forked from vuestorefront/vue-storefront
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
619072c
commit a5a0cea
Showing
20 changed files
with
209 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface RequestOptions { | ||
dryRun?: boolean | ||
forceClientState?: boolean | ||
payload?: any | ||
silent?: boolean | ||
callbackEvent?: boolean | string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {Action, ActionTree} from "vuex"; | ||
|
||
export interface ApiCartActions<S, R> extends ActionTree<S, R> { | ||
apiFetchCartProducts: Action<S, R>, | ||
[key: string]: Action<S, R>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { VueStorefrontModule, VueStorefrontModuleConfig } from '@vue-storefront/core/lib/module' | ||
import { module } from './store' | ||
|
||
const KEY = 'api-other-backend'; | ||
|
||
const moduleConfig: VueStorefrontModuleConfig = { | ||
store: { modules: [{ key: KEY, module }] }, | ||
key: KEY | ||
}; | ||
|
||
export const ApiOtherBackend = new VueStorefrontModule(moduleConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ActionTree } from 'vuex' | ||
import RootState from '@vue-storefront/core/types/RootState' | ||
import ClaimsState from '../types/ApiState' | ||
import cart from './api/cart'; | ||
|
||
const actions: ActionTree<ClaimsState, RootState> = { | ||
...cart | ||
}; | ||
|
||
export default actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ActionContext } from 'vuex'; | ||
import { TaskQueue } from '@vue-storefront/core/lib/sync'; | ||
import config from 'config' | ||
import Task from '@vue-storefront/core/lib/sync/types/Task'; | ||
import RootState from '@vue-storefront/core/types/RootState' | ||
import ApiState from "../../types/ApiState"; | ||
import { ApiCartActions } from '@vue-storefront/core/modules/cart/types/ApiCartActions'; | ||
import { RequestOptions } from '@vue-storefront/core/modules/api/types/Request'; | ||
|
||
|
||
const cart: ApiCartActions<ApiState, RootState> = { | ||
apiFetchCartProducts: { | ||
root: true, | ||
handler(context: ActionContext<ApiState, RootState>, {forceClientState = false, dryRun = false, callbackEvent = false}: RequestOptions): Promise<Task> { | ||
return TaskQueue.execute({ | ||
url: `${config.backendUrl}/cart`, // sync the cart | ||
payload: { | ||
method: 'GET', | ||
headers: {'Content-Type': 'application/json'}, | ||
mode: 'cors' | ||
}, | ||
silent: true, | ||
force_client_state: forceClientState, | ||
dry_run: dryRun, | ||
callback_event: callbackEvent | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
export default cart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Module } from 'vuex' | ||
import actions from './actions' | ||
import RootState from '@vue-storefront/core/types/RootState' | ||
import ApiState from '../types/ApiState' | ||
|
||
export const module: Module<ApiState, RootState> = { | ||
namespaced: true, | ||
actions | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default interface ApiState { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { VueStorefrontModule, VueStorefrontModuleConfig } from '@vue-storefront/core/lib/module' | ||
import { module } from './store' | ||
|
||
const KEY = 'api-vue-storefront-extended'; | ||
|
||
const moduleConfig: VueStorefrontModuleConfig = { | ||
store: { modules: [{ key: KEY, module }] }, | ||
key: KEY | ||
}; | ||
|
||
export const ApiVueStorefrontExtended = new VueStorefrontModule(moduleConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ActionTree } from 'vuex' | ||
import RootState from '@vue-storefront/core/types/RootState' | ||
import ClaimsState from '../types/ApiState' | ||
import cart from './api/cart'; | ||
|
||
const actions: ActionTree<ClaimsState, RootState> = { | ||
...cart | ||
}; | ||
|
||
export default actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import RootState from '@vue-storefront/core/types/RootState' | ||
import ApiState from "../../types/ApiState"; | ||
import { ApiCartActions } from '@vue-storefront/core/modules/cart/types/ApiCartActions'; | ||
import baseCartActions from '../../../api-vue-storefront/store/api/cart'; | ||
|
||
|
||
const cart: ApiCartActions<ApiState, RootState> = { | ||
...baseCartActions // import all base cart actions | ||
// replace override base ones with whatever you want or add your own | ||
}; | ||
|
||
export default cart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Module } from 'vuex' | ||
import actions from './actions' | ||
import RootState from '@vue-storefront/core/types/RootState' | ||
import ApiState from '../types/ApiState' | ||
|
||
export const module: Module<ApiState, RootState> = { | ||
namespaced: true, | ||
actions | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import BaseApiState from '../../api-vue-storefront/types/ApiState'; | ||
|
||
export default interface ApiState extends BaseApiState { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { VueStorefrontModule, VueStorefrontModuleConfig } from '@vue-storefront/core/lib/module' | ||
import { module } from './store' | ||
|
||
const KEY = 'api-vue-storefront'; | ||
|
||
const moduleConfig: VueStorefrontModuleConfig = { | ||
store: { modules: [{ key: KEY, module }] }, | ||
key: KEY | ||
}; | ||
|
||
export const ApiVueStorefront = new VueStorefrontModule(moduleConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ActionTree } from 'vuex' | ||
import RootState from '@vue-storefront/core/types/RootState' | ||
import ClaimsState from '../types/ApiState' | ||
import cart from './api/cart'; | ||
|
||
const actions: ActionTree<ClaimsState, RootState> = { | ||
...cart | ||
}; | ||
|
||
export default actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ActionContext } from 'vuex'; | ||
import { TaskQueue } from '@vue-storefront/core/lib/sync'; | ||
import config from 'config' | ||
import Task from '@vue-storefront/core/lib/sync/types/Task'; | ||
import RootState from '@vue-storefront/core/types/RootState' | ||
import ApiState from "../../types/ApiState"; | ||
import { ApiCartActions } from '@vue-storefront/core/modules/cart/types/ApiCartActions'; | ||
import { RequestOptions } from '@vue-storefront/core/modules/api/types/Request'; | ||
|
||
|
||
const cart: ApiCartActions<ApiState, RootState> = { | ||
apiFetchCartProducts: { | ||
root: true, | ||
handler(context: ActionContext<ApiState, RootState>, {forceClientState = false, dryRun = false, callbackEvent = false}: RequestOptions): Promise<Task> { | ||
return TaskQueue.execute({ | ||
url: config.cart.pull_endpoint, // sync the cart | ||
payload: { | ||
method: 'GET', | ||
headers: {'Content-Type': 'application/json'}, | ||
mode: 'cors' | ||
}, | ||
silent: true, | ||
force_client_state: forceClientState, | ||
dry_run: dryRun, | ||
callback_event: callbackEvent | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
export default cart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Module } from 'vuex' | ||
import actions from './actions' | ||
import RootState from '@vue-storefront/core/types/RootState' | ||
import ApiState from '../types/ApiState' | ||
|
||
export const module: Module<ApiState, RootState> = { | ||
namespaced: true, | ||
actions | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default interface ApiState { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters