Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x | import ApolloClient from 'apollo-client'; import { InMemoryCache } from 'apollo-cache-inmemory'; import SdkAuth, { TokenProvider } from '@commercetools/sdk-auth'; import { createCommerceToolsConnection, isAnonymousSession, isUserSession } from './helpers/comemrcetoolsLink'; import getProduct from './api/getProduct'; import getCategory from './api/getCategory'; import createCart from './api/createCart'; import updateCart from './api/updateCart'; import getCart from './api/getCart'; import addToCart from './api/addToCart'; import removeFromCart from './api/removeFromCart'; import updateCartQuantity from './api/updateCartQuantity'; import getMe from './api/getMe'; import createMyOrderFromCart from './api/createMyOrderFromCart'; import getShippingMethods from './api/getShippingMethods'; import updateShippingDetails from './api/updateShippingDetails'; import customerSignMeUp from './api/customerSignMeUp'; import customerSignMeIn from './api/customerSignMeIn'; import getOrders from './api/getMyOrders'; import applyCartCoupon from './api/applyCartCoupon'; import removeCartCoupon from './api/removeCartCoupon'; import customerChangeMyPassword from './api/customerChangeMyPassword'; import customerUpdateMe from './api/customerUpdateMe'; import { apiClientFactory } from '@vue-storefront/core'; import { Config } from './types/setup'; const defaultSettings = { locale: 'en', acceptLanguage: ['en'], auth: { onTokenChange: () => {}, onTokenRead: () => '', onTokenRemove: () => {} }, cookies: { currencyCookieName: 'vsf-currency', countryCookieName: 'vsf-country', localeCookieName: 'vsf-locale' } }; interface ClientInstance extends ApolloClient<any> { sdkAuth?: SdkAuth; tokenProvider?: TokenProvider; } const isGuest = (context) => { const { client, config } = context; const { handleIsGuest } = config; if (handleIsGuest) { return handleIsGuest(context); } if (client.tokenProvider) { const token = config.auth.onTokenRead(); return !isAnonymousSession(token) && !isUserSession(token); } return false; }; const customerSignOut = async ({ config, client }) => { if (config.auth.onTokenRemove) { config.auth.onTokenRemove(); } if (client.tokenProvider) { client.tokenProvider.invalidateTokenInfo(); } }; const onSetup = (settings: Config): { config: Config; client: ClientInstance } => { const languageMap = settings.languageMap || {}; const acceptLanguage = settings.acceptLanguage || defaultSettings.acceptLanguage; const locale = settings.locale || defaultSettings.locale; const config = { ...defaultSettings, ...settings, languageMap, acceptLanguage: languageMap[locale] || acceptLanguage, auth: settings.auth || defaultSettings.auth } as any as Config; Iif (settings.client) { return { client: settings.client, config }; } Iif (settings.customOptions && settings.customOptions.link) { return { client: new ApolloClient({ cache: new InMemoryCache(), ...settings.customOptions }), config }; } const { apolloLink, sdkAuth, tokenProvider } = createCommerceToolsConnection(config); const client = new ApolloClient({ link: apolloLink, cache: new InMemoryCache(), ...settings.customOptions }); (client as ClientInstance).sdkAuth = sdkAuth; (client as ClientInstance).tokenProvider = tokenProvider; return { config, client }; }; const { createApiClient } = apiClientFactory<Config, any>({ tag: 'ct', onSetup, api: { getProduct, getCategory, getOrders, createCart, updateCart, getCart, addToCart, removeFromCart, getMe, updateCartQuantity, createMyOrderFromCart, getShippingMethods, updateShippingDetails, customerSignMeUp, customerSignMeIn, customerSignOut, applyCartCoupon, removeCartCoupon, customerChangeMyPassword, customerUpdateMe, isGuest } }); export { createApiClient }; export * from './fragments'; export * from './types/Api'; export * from './types/GraphQL'; export * from './types/setup'; export * from './helpers/queries'; export * as cartActions from './helpers/cart/actions'; |