@doswiftly/storefront-sdk 4.0.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -9
- package/dist/core/bot-protection/abstract-manager.d.ts +57 -0
- package/dist/core/bot-protection/abstract-manager.d.ts.map +1 -0
- package/dist/core/bot-protection/abstract-manager.js +144 -0
- package/dist/core/bot-protection/create-manager.d.ts +15 -0
- package/dist/core/bot-protection/create-manager.d.ts.map +1 -0
- package/dist/core/bot-protection/create-manager.js +33 -0
- package/dist/core/bot-protection/eucaptcha-manager.d.ts +15 -0
- package/dist/core/bot-protection/eucaptcha-manager.d.ts.map +1 -0
- package/dist/core/bot-protection/eucaptcha-manager.js +76 -0
- package/dist/core/bot-protection/fallback-manager.d.ts +18 -0
- package/dist/core/bot-protection/fallback-manager.d.ts.map +1 -0
- package/dist/core/bot-protection/fallback-manager.js +42 -0
- package/dist/core/bot-protection/turnstile-manager.d.ts +15 -0
- package/dist/core/bot-protection/turnstile-manager.d.ts.map +1 -0
- package/dist/core/bot-protection/turnstile-manager.js +78 -0
- package/dist/core/cart/cookie-config.d.ts +14 -0
- package/dist/core/cart/cookie-config.d.ts.map +1 -0
- package/dist/core/cart/cookie-config.js +13 -0
- package/dist/core/currency/cookie-config.d.ts +14 -0
- package/dist/core/currency/cookie-config.d.ts.map +1 -0
- package/dist/core/currency/cookie-config.js +13 -0
- package/dist/core/image.d.ts +55 -0
- package/dist/core/image.d.ts.map +1 -0
- package/dist/core/image.js +48 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +13 -0
- package/dist/core/language/cookie-config.d.ts +14 -0
- package/dist/core/language/cookie-config.d.ts.map +1 -0
- package/dist/core/language/cookie-config.js +13 -0
- package/dist/core/middleware/bot-protection.d.ts +71 -0
- package/dist/core/middleware/bot-protection.d.ts.map +1 -0
- package/dist/core/middleware/bot-protection.js +63 -0
- package/dist/core/middleware/currency.d.ts.map +1 -1
- package/dist/core/middleware/currency.js +2 -1
- package/dist/core/middleware/language.d.ts +18 -0
- package/dist/core/middleware/language.d.ts.map +1 -0
- package/dist/core/middleware/language.js +25 -0
- package/dist/react/bot-protection/bot-protection-context.d.ts +12 -0
- package/dist/react/bot-protection/bot-protection-context.d.ts.map +1 -0
- package/dist/react/bot-protection/bot-protection-context.js +9 -0
- package/dist/react/bot-protection/bot-protection-widget.d.ts +13 -0
- package/dist/react/bot-protection/bot-protection-widget.d.ts.map +1 -0
- package/dist/react/bot-protection/bot-protection-widget.js +34 -0
- package/dist/react/cookies.d.ts +17 -0
- package/dist/react/cookies.d.ts.map +1 -1
- package/dist/react/cookies.js +36 -3
- package/dist/react/hooks/use-bot-protection.d.ts +16 -0
- package/dist/react/hooks/use-bot-protection.d.ts.map +1 -0
- package/dist/react/hooks/use-bot-protection.js +24 -0
- package/dist/react/index.d.ts +10 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +9 -1
- package/dist/react/providers/language-provider.d.ts +18 -0
- package/dist/react/providers/language-provider.d.ts.map +1 -0
- package/dist/react/providers/language-provider.js +24 -0
- package/dist/react/providers/storefront-client-provider.d.ts +7 -2
- package/dist/react/providers/storefront-client-provider.d.ts.map +1 -1
- package/dist/react/providers/storefront-client-provider.js +14 -3
- package/dist/react/providers/storefront-provider.d.ts +7 -1
- package/dist/react/providers/storefront-provider.d.ts.map +1 -1
- package/dist/react/providers/storefront-provider.js +11 -4
- package/dist/react/stores/cart.context.d.ts +12 -0
- package/dist/react/stores/cart.context.d.ts.map +1 -0
- package/dist/react/stores/cart.context.js +3 -0
- package/dist/react/stores/cart.store.d.ts +71 -0
- package/dist/react/stores/cart.store.d.ts.map +1 -0
- package/dist/react/stores/cart.store.js +166 -0
- package/dist/react/stores/currency.store.d.ts +6 -9
- package/dist/react/stores/currency.store.d.ts.map +1 -1
- package/dist/react/stores/currency.store.js +5 -22
- package/dist/react/stores/language.store.d.ts +33 -0
- package/dist/react/stores/language.store.d.ts.map +1 -0
- package/dist/react/stores/language.store.js +67 -0
- package/dist/react/stores/store-context.d.ts +5 -0
- package/dist/react/stores/store-context.d.ts.map +1 -1
- package/dist/react/stores/store-context.js +14 -0
- package/dist/react/types/shop-config.d.ts +19 -0
- package/dist/react/types/shop-config.d.ts.map +1 -0
- package/dist/react/types/shop-config.js +7 -0
- package/package.json +1 -1
- package/src/__tests__/unit/bot-protection.test.ts +461 -0
- package/src/__tests__/unit/cart-store.test.ts +349 -0
- package/src/core/bot-protection/abstract-manager.ts +185 -0
- package/src/core/bot-protection/create-manager.ts +37 -0
- package/src/core/bot-protection/eucaptcha-manager.ts +88 -0
- package/src/core/bot-protection/fallback-manager.ts +43 -0
- package/src/core/bot-protection/turnstile-manager.ts +92 -0
- package/src/core/bot-protection/types/eucaptcha.d.ts +28 -0
- package/src/core/bot-protection/types/turnstile.d.ts +33 -0
- package/src/core/cart/cookie-config.ts +13 -0
- package/src/core/currency/cookie-config.ts +13 -0
- package/src/core/image.ts +75 -0
- package/src/core/index.ts +30 -0
- package/src/core/language/cookie-config.ts +13 -0
- package/src/core/middleware/bot-protection.ts +140 -0
- package/src/core/middleware/currency.ts +2 -1
- package/src/core/middleware/language.ts +30 -0
- package/src/react/bot-protection/bot-protection-context.ts +17 -0
- package/src/react/bot-protection/bot-protection-widget.tsx +46 -0
- package/src/react/cookies.ts +39 -4
- package/src/react/hooks/use-bot-protection.ts +31 -0
- package/src/react/index.ts +27 -1
- package/src/react/providers/language-provider.tsx +34 -0
- package/src/react/providers/storefront-client-provider.tsx +20 -3
- package/src/react/providers/storefront-provider.tsx +34 -6
- package/src/react/stores/cart.context.ts +10 -0
- package/src/react/stores/cart.store.ts +254 -0
- package/src/react/stores/currency.store.ts +12 -32
- package/src/react/stores/language.store.ts +90 -0
- package/src/react/stores/store-context.tsx +21 -0
- package/src/react/types/shop-config.ts +22 -0
|
@@ -5,20 +5,17 @@
|
|
|
5
5
|
* Instance is created in StorefrontProvider via useRef and provided
|
|
6
6
|
* through React Context — eliminates module duplication in Turbopack.
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
currency: string;
|
|
14
|
-
}>;
|
|
15
|
-
}
|
|
8
|
+
import type { ShopConfig } from '../types/shop-config';
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Use ShopConfig instead. Kept for backward compatibility of type exports.
|
|
11
|
+
*/
|
|
12
|
+
export type ShopCurrencyData = ShopConfig;
|
|
16
13
|
export interface CurrencyStore {
|
|
17
14
|
baseCurrency: string | null;
|
|
18
15
|
supportedCurrencies: string[];
|
|
19
16
|
currency: string | null;
|
|
20
17
|
isLoaded: boolean;
|
|
21
|
-
initialize: (shopData:
|
|
18
|
+
initialize: (shopData: ShopConfig) => void;
|
|
22
19
|
setCurrency: (currency: string) => void;
|
|
23
20
|
}
|
|
24
21
|
export declare const createCurrencyStore: () => import("zustand").StoreApi<CurrencyStore>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.store.d.ts","sourceRoot":"","sources":["../../../src/react/stores/currency.store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"currency.store.d.ts","sourceRoot":"","sources":["../../../src/react/stores/currency.store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIvD;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC;AAE1C,MAAM,WAAW,aAAa;IAE5B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,OAAO,CAAC;IAGlB,UAAU,EAAE,CAAC,QAAQ,EAAE,UAAU,KAAK,IAAI,CAAC;IAC3C,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CACzC;AAED,eAAO,MAAM,mBAAmB,iDAqD3B,CAAC;AAMN,eAAO,MAAM,cAAc,GAAI,OAAO,aAAa,kBAAmB,CAAC;AACvE,eAAO,MAAM,kBAAkB,GAAI,OAAO,aAAa,kBAAuB,CAAC;AAC/E,eAAO,MAAM,yBAAyB,GAAI,OAAO,aAAa,aAA8B,CAAC;AAC7F,eAAO,MAAM,cAAc,GAAI,OAAO,aAAa,YAAmB,CAAC"}
|
|
@@ -6,25 +6,8 @@
|
|
|
6
6
|
* through React Context — eliminates module duplication in Turbopack.
|
|
7
7
|
*/
|
|
8
8
|
import { createStore } from 'zustand/vanilla';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*/
|
|
12
|
-
function getCurrencyFromCookie() {
|
|
13
|
-
if (typeof document === 'undefined')
|
|
14
|
-
return null;
|
|
15
|
-
const match = document.cookie.match(/(?:^|;\s*)preferred-currency=([^;]*)/);
|
|
16
|
-
return match ? decodeURIComponent(match[1]) : null;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Set currency in cookie (client-side).
|
|
20
|
-
*/
|
|
21
|
-
function setCurrencyCookie(currency) {
|
|
22
|
-
if (typeof document === 'undefined')
|
|
23
|
-
return;
|
|
24
|
-
const maxAge = 365 * 24 * 60 * 60; // 1 year
|
|
25
|
-
const secure = typeof location !== 'undefined' && location.protocol === 'https:' ? ';secure' : '';
|
|
26
|
-
document.cookie = `preferred-currency=${encodeURIComponent(currency)};max-age=${maxAge};path=/;samesite=lax${secure}`;
|
|
27
|
-
}
|
|
9
|
+
import { CURRENCY_COOKIE_NAME, CURRENCY_COOKIE_MAX_AGE } from '../../core/currency/cookie-config';
|
|
10
|
+
import { getCookie, setCookie } from '../cookies';
|
|
28
11
|
export const createCurrencyStore = () => createStore()((set, get) => ({
|
|
29
12
|
baseCurrency: null,
|
|
30
13
|
supportedCurrencies: [],
|
|
@@ -32,7 +15,7 @@ export const createCurrencyStore = () => createStore()((set, get) => ({
|
|
|
32
15
|
isLoaded: false,
|
|
33
16
|
initialize: (shopData) => {
|
|
34
17
|
// 1. Try saved currency from cookie (SSR-safe)
|
|
35
|
-
const saved =
|
|
18
|
+
const saved = getCookie(CURRENCY_COOKIE_NAME);
|
|
36
19
|
// 2. Try to detect from browser locale
|
|
37
20
|
let detected;
|
|
38
21
|
if (shopData.localeToCurrencyMap && typeof navigator !== 'undefined') {
|
|
@@ -54,7 +37,7 @@ export const createCurrencyStore = () => createStore()((set, get) => ({
|
|
|
54
37
|
});
|
|
55
38
|
// Ensure cookie is set if we determined a currency
|
|
56
39
|
if (finalCurrency && !saved) {
|
|
57
|
-
|
|
40
|
+
setCookie(CURRENCY_COOKIE_NAME, finalCurrency, { maxAge: CURRENCY_COOKIE_MAX_AGE });
|
|
58
41
|
}
|
|
59
42
|
},
|
|
60
43
|
setCurrency: (currency) => {
|
|
@@ -64,7 +47,7 @@ export const createCurrencyStore = () => createStore()((set, get) => ({
|
|
|
64
47
|
return;
|
|
65
48
|
}
|
|
66
49
|
set({ currency });
|
|
67
|
-
|
|
50
|
+
setCookie(CURRENCY_COOKIE_NAME, currency, { maxAge: CURRENCY_COOKIE_MAX_AGE });
|
|
68
51
|
},
|
|
69
52
|
}));
|
|
70
53
|
// ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Language store factory — tracks active language for SDK middleware.
|
|
3
|
+
*
|
|
4
|
+
* Creates a vanilla Zustand store (not a React hook singleton).
|
|
5
|
+
* Instance is created in StorefrontProvider via useRef and provided
|
|
6
|
+
* through React Context — eliminates module duplication in Turbopack.
|
|
7
|
+
*
|
|
8
|
+
* KEY PRINCIPLE: URL is the single source of truth for language.
|
|
9
|
+
* - next-intl middleware uses `preferred-language` cookie (custom name via localeCookie.name)
|
|
10
|
+
* - This store tracks the active language for SDK X-Lang header
|
|
11
|
+
* - setLanguage() persists to `preferred-language` cookie
|
|
12
|
+
* - initialize() sets defaultLanguage and supportedLanguages from Shop query
|
|
13
|
+
* - setLanguage() is called by LanguageSyncProvider when URL locale changes
|
|
14
|
+
*
|
|
15
|
+
* Single `preferred-language` cookie serves both:
|
|
16
|
+
* - next-intl middleware (locale detection/routing, via localeCookie.name override)
|
|
17
|
+
* - SDK language store (X-Lang header, framework-agnostic)
|
|
18
|
+
*/
|
|
19
|
+
import type { ShopConfig } from '../types/shop-config';
|
|
20
|
+
export interface LanguageStore {
|
|
21
|
+
defaultLanguage: string | null;
|
|
22
|
+
supportedLanguages: string[];
|
|
23
|
+
language: string | null;
|
|
24
|
+
isLoaded: boolean;
|
|
25
|
+
initialize: (shopData: ShopConfig) => void;
|
|
26
|
+
setLanguage: (language: string) => void;
|
|
27
|
+
}
|
|
28
|
+
export declare const createLanguageStore: (initialLanguage?: string | null) => import("zustand").StoreApi<LanguageStore>;
|
|
29
|
+
export declare const selectLanguage: (state: LanguageStore) => string | null;
|
|
30
|
+
export declare const selectDefaultLanguage: (state: LanguageStore) => string | null;
|
|
31
|
+
export declare const selectSupportedLanguages: (state: LanguageStore) => string[];
|
|
32
|
+
export declare const selectLanguageIsLoaded: (state: LanguageStore) => boolean;
|
|
33
|
+
//# sourceMappingURL=language.store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language.store.d.ts","sourceRoot":"","sources":["../../../src/react/stores/language.store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIvD,MAAM,WAAW,aAAa;IAE5B,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,OAAO,CAAC;IAGlB,UAAU,EAAE,CAAC,QAAQ,EAAE,UAAU,KAAK,IAAI,CAAC;IAC3C,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CACzC;AAED,eAAO,MAAM,mBAAmB,GAAI,kBAAkB,MAAM,GAAG,IAAI,8CA4C9D,CAAC;AAMN,eAAO,MAAM,cAAc,GAAI,OAAO,aAAa,kBAAmB,CAAC;AACvE,eAAO,MAAM,qBAAqB,GAAI,OAAO,aAAa,kBAA0B,CAAC;AACrF,eAAO,MAAM,wBAAwB,GAAI,OAAO,aAAa,aAA6B,CAAC;AAC3F,eAAO,MAAM,sBAAsB,GAAI,OAAO,aAAa,YAAmB,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Language store factory — tracks active language for SDK middleware.
|
|
3
|
+
*
|
|
4
|
+
* Creates a vanilla Zustand store (not a React hook singleton).
|
|
5
|
+
* Instance is created in StorefrontProvider via useRef and provided
|
|
6
|
+
* through React Context — eliminates module duplication in Turbopack.
|
|
7
|
+
*
|
|
8
|
+
* KEY PRINCIPLE: URL is the single source of truth for language.
|
|
9
|
+
* - next-intl middleware uses `preferred-language` cookie (custom name via localeCookie.name)
|
|
10
|
+
* - This store tracks the active language for SDK X-Lang header
|
|
11
|
+
* - setLanguage() persists to `preferred-language` cookie
|
|
12
|
+
* - initialize() sets defaultLanguage and supportedLanguages from Shop query
|
|
13
|
+
* - setLanguage() is called by LanguageSyncProvider when URL locale changes
|
|
14
|
+
*
|
|
15
|
+
* Single `preferred-language` cookie serves both:
|
|
16
|
+
* - next-intl middleware (locale detection/routing, via localeCookie.name override)
|
|
17
|
+
* - SDK language store (X-Lang header, framework-agnostic)
|
|
18
|
+
*/
|
|
19
|
+
import { createStore } from 'zustand/vanilla';
|
|
20
|
+
import { LANGUAGE_COOKIE_NAME, LANGUAGE_COOKIE_MAX_AGE } from '../../core/language/cookie-config';
|
|
21
|
+
import { getCookie, setCookie } from '../cookies';
|
|
22
|
+
export const createLanguageStore = (initialLanguage) => createStore()((set, get) => ({
|
|
23
|
+
defaultLanguage: null,
|
|
24
|
+
supportedLanguages: [],
|
|
25
|
+
language: initialLanguage ?? null,
|
|
26
|
+
isLoaded: false,
|
|
27
|
+
initialize: (shopData) => {
|
|
28
|
+
const supported = shopData.supportedLanguages ?? [];
|
|
29
|
+
const current = get().language;
|
|
30
|
+
const saved = getCookie(LANGUAGE_COOKIE_NAME);
|
|
31
|
+
// Priority: current (from initialLanguage/URL) > cookie (validated) > default
|
|
32
|
+
const finalLanguage = current && (supported.length === 0 || supported.includes(current))
|
|
33
|
+
? current
|
|
34
|
+
: saved && (supported.length === 0 || supported.includes(saved))
|
|
35
|
+
? saved
|
|
36
|
+
: shopData.defaultLanguage ?? null;
|
|
37
|
+
set({
|
|
38
|
+
defaultLanguage: shopData.defaultLanguage ?? null,
|
|
39
|
+
supportedLanguages: supported,
|
|
40
|
+
language: finalLanguage,
|
|
41
|
+
isLoaded: true,
|
|
42
|
+
});
|
|
43
|
+
// Persist cookie if determined from fallback (not already saved)
|
|
44
|
+
if (finalLanguage && finalLanguage !== saved) {
|
|
45
|
+
setCookie(LANGUAGE_COOKIE_NAME, finalLanguage, { maxAge: LANGUAGE_COOKIE_MAX_AGE });
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
setLanguage: (language) => {
|
|
49
|
+
const { supportedLanguages } = get();
|
|
50
|
+
// Validate vs supported (bypass if empty — LanguageSyncProvider may call before initialize)
|
|
51
|
+
if (supportedLanguages.length > 0 && !supportedLanguages.includes(language)) {
|
|
52
|
+
console.warn(`[LanguageStore] Language ${language} not supported`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (get().language === language)
|
|
56
|
+
return;
|
|
57
|
+
setCookie(LANGUAGE_COOKIE_NAME, language, { maxAge: LANGUAGE_COOKIE_MAX_AGE });
|
|
58
|
+
set({ language });
|
|
59
|
+
},
|
|
60
|
+
}));
|
|
61
|
+
// ---------------------------------------------------------------------------
|
|
62
|
+
// Selectors (for use with useLanguageStore(selector))
|
|
63
|
+
// ---------------------------------------------------------------------------
|
|
64
|
+
export const selectLanguage = (state) => state.language;
|
|
65
|
+
export const selectDefaultLanguage = (state) => state.defaultLanguage;
|
|
66
|
+
export const selectSupportedLanguages = (state) => state.supportedLanguages;
|
|
67
|
+
export const selectLanguageIsLoaded = (state) => state.isLoaded;
|
|
@@ -11,8 +11,10 @@
|
|
|
11
11
|
import { type StoreApi } from 'zustand';
|
|
12
12
|
import type { AuthStore } from './auth.store';
|
|
13
13
|
import type { CurrencyStore } from './currency.store';
|
|
14
|
+
import type { LanguageStore } from './language.store';
|
|
14
15
|
export declare const AuthStoreContext: import("react").Context<StoreApi<AuthStore> | null>;
|
|
15
16
|
export declare const CurrencyStoreContext: import("react").Context<StoreApi<CurrencyStore> | null>;
|
|
17
|
+
export declare const LanguageStoreContext: import("react").Context<StoreApi<LanguageStore> | null>;
|
|
16
18
|
export declare function useAuthStore(): AuthStore;
|
|
17
19
|
export declare function useAuthStore<T>(selector: (s: AuthStore) => T): T;
|
|
18
20
|
export declare function useAuthStoreApi(): StoreApi<AuthStore>;
|
|
@@ -24,4 +26,7 @@ export declare function useAuthHydrated(): boolean;
|
|
|
24
26
|
export declare function useCurrencyStore(): CurrencyStore;
|
|
25
27
|
export declare function useCurrencyStore<T>(selector: (s: CurrencyStore) => T): T;
|
|
26
28
|
export declare function useCurrencyStoreApi(): StoreApi<CurrencyStore>;
|
|
29
|
+
export declare function useLanguageStore(): LanguageStore;
|
|
30
|
+
export declare function useLanguageStore<T>(selector: (s: LanguageStore) => T): T;
|
|
31
|
+
export declare function useLanguageStoreApi(): StoreApi<LanguageStore>;
|
|
27
32
|
//# sourceMappingURL=store-context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store-context.d.ts","sourceRoot":"","sources":["../../../src/react/stores/store-context.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAMtD,eAAO,MAAM,gBAAgB,qDAAkD,CAAC;AAChF,eAAO,MAAM,oBAAoB,yDAAsD,CAAC;AAMxF,wBAAgB,YAAY,IAAI,SAAS,CAAC;AAC1C,wBAAgB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,SAAS,KAAK,CAAC,GAAG,CAAC,CAAC;AAQlE,wBAAgB,eAAe,IAAI,QAAQ,CAAC,SAAS,CAAC,CAIrD;AAED;;;GAGG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAczC;AAMD,wBAAgB,gBAAgB,IAAI,aAAa,CAAC;AAClD,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,CAAC,GAAG,CAAC,CAAC;AAQ1E,wBAAgB,mBAAmB,IAAI,QAAQ,CAAC,aAAa,CAAC,CAI7D"}
|
|
1
|
+
{"version":3,"file":"store-context.d.ts","sourceRoot":"","sources":["../../../src/react/stores/store-context.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAMtD,eAAO,MAAM,gBAAgB,qDAAkD,CAAC;AAChF,eAAO,MAAM,oBAAoB,yDAAsD,CAAC;AACxF,eAAO,MAAM,oBAAoB,yDAAsD,CAAC;AAMxF,wBAAgB,YAAY,IAAI,SAAS,CAAC;AAC1C,wBAAgB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,SAAS,KAAK,CAAC,GAAG,CAAC,CAAC;AAQlE,wBAAgB,eAAe,IAAI,QAAQ,CAAC,SAAS,CAAC,CAIrD;AAED;;;GAGG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAczC;AAMD,wBAAgB,gBAAgB,IAAI,aAAa,CAAC;AAClD,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,CAAC,GAAG,CAAC,CAAC;AAQ1E,wBAAgB,mBAAmB,IAAI,QAAQ,CAAC,aAAa,CAAC,CAI7D;AAMD,wBAAgB,gBAAgB,IAAI,aAAa,CAAC;AAClD,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,CAAC,GAAG,CAAC,CAAC;AAQ1E,wBAAgB,mBAAmB,IAAI,QAAQ,CAAC,aAAa,CAAC,CAI7D"}
|
|
@@ -16,6 +16,7 @@ import { useStore } from 'zustand';
|
|
|
16
16
|
// ---------------------------------------------------------------------------
|
|
17
17
|
export const AuthStoreContext = createContext(null);
|
|
18
18
|
export const CurrencyStoreContext = createContext(null);
|
|
19
|
+
export const LanguageStoreContext = createContext(null);
|
|
19
20
|
export function useAuthStore(selector) {
|
|
20
21
|
const store = useContext(AuthStoreContext);
|
|
21
22
|
if (!store)
|
|
@@ -60,3 +61,16 @@ export function useCurrencyStoreApi() {
|
|
|
60
61
|
throw new Error('useCurrencyStoreApi must be used within StorefrontProvider');
|
|
61
62
|
return store;
|
|
62
63
|
}
|
|
64
|
+
export function useLanguageStore(selector) {
|
|
65
|
+
const store = useContext(LanguageStoreContext);
|
|
66
|
+
if (!store)
|
|
67
|
+
throw new Error('useLanguageStore must be used within StorefrontProvider');
|
|
68
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
69
|
+
return selector ? useStore(store, selector) : useStore(store);
|
|
70
|
+
}
|
|
71
|
+
export function useLanguageStoreApi() {
|
|
72
|
+
const store = useContext(LanguageStoreContext);
|
|
73
|
+
if (!store)
|
|
74
|
+
throw new Error('useLanguageStoreApi must be used within StorefrontProvider');
|
|
75
|
+
return store;
|
|
76
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ShopConfig — full shop configuration from backend shop query.
|
|
3
|
+
*
|
|
4
|
+
* Flat interface — new features added here directly.
|
|
5
|
+
* Each concern is consumed by its own provider internally.
|
|
6
|
+
*/
|
|
7
|
+
import type { BotProtectionConfig } from '../../core/middleware/bot-protection';
|
|
8
|
+
export interface ShopConfig {
|
|
9
|
+
currencyCode: string;
|
|
10
|
+
supportedCurrencies: string[];
|
|
11
|
+
localeToCurrencyMap?: Array<{
|
|
12
|
+
locale: string;
|
|
13
|
+
currency: string;
|
|
14
|
+
}>;
|
|
15
|
+
defaultLanguage?: string | null;
|
|
16
|
+
supportedLanguages?: string[] | null;
|
|
17
|
+
botProtection?: BotProtectionConfig | null;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=shop-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shop-config.d.ts","sourceRoot":"","sources":["../../../src/react/types/shop-config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAEhF,MAAM,WAAW,UAAU;IAEzB,YAAY,EAAE,MAAM,CAAC;IACrB,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,mBAAmB,CAAC,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAGlE,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,kBAAkB,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAGrC,aAAa,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAC;CAC5C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@doswiftly/storefront-sdk",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Storefront runtime SDK for DoSwiftly Commerce — layered transport, middleware pipeline, React providers, Zustand stores, cache strategies. 0 runtime dependencies in core.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "dist/core/index.d.ts",
|