@doswiftly/storefront-sdk 4.0.0 → 4.1.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 +33 -6
- 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/index.d.ts +7 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +11 -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/index.ts +23 -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
package/dist/core/index.d.ts
CHANGED
|
@@ -37,9 +37,13 @@ export { createStorefrontClient } from './client/create-client';
|
|
|
37
37
|
export type { StorefrontClient, StorefrontClientConfig, Middleware, ExecuteFn, GraphQLRequest, GraphQLResponse, GraphQLErrorInfo, UserError, CacheStrategy, CacheOptions, TypedDocumentString, } from './client/types';
|
|
38
38
|
export { authMiddleware } from './middleware/auth';
|
|
39
39
|
export { currencyMiddleware } from './middleware/currency';
|
|
40
|
+
export { languageMiddleware } from './middleware/language';
|
|
41
|
+
export { botProtectionMiddleware, BOT_PROTECTION_HEADER, type BotProtectionTokenProvider, type BotProtectionConfig, type BotProtectionProviderConfig, type BotProtectionMiddlewareOptions, type FailStrategy, } from './middleware/bot-protection';
|
|
40
42
|
export { retryMiddleware, type RetryOptions } from './middleware/retry';
|
|
41
43
|
export { timeoutMiddleware, type TimeoutOptions } from './middleware/timeout';
|
|
42
44
|
export { errorMiddleware } from './middleware/errors';
|
|
45
|
+
export { createBotProtectionManager } from './bot-protection/create-manager';
|
|
46
|
+
export { FallbackBotProtectionManager } from './bot-protection/fallback-manager';
|
|
43
47
|
export { StorefrontError, ErrorCodes, type StorefrontErrorOptions } from './errors';
|
|
44
48
|
export { cacheNone, cacheShort, cacheLong, cachePrivate, cacheCustom, generateCacheControlHeader, type CacheOverrides, } from './cache';
|
|
45
49
|
export { CartClient } from './cart/cart-client';
|
|
@@ -51,6 +55,9 @@ export { sanitizeHtml } from './helpers/sanitize-html';
|
|
|
51
55
|
export { normalizeConnection, type Connection, type ConnectionEdge, type ConnectionPageInfo, type NormalizedConnection, } from './helpers/normalize-connection';
|
|
52
56
|
export { formatPrice, formatPriceRange, formatAmount, formatDate, formatDateTime, formatNumber, formatPercentage, getCurrencySymbol, CURRENCY_SYMBOLS, CURRENCY_LOCALES, type PriceMoney, } from './format';
|
|
53
57
|
export { AUTH_COOKIE_NAME, AUTH_COOKIE_DEFAULTS, type AuthCookieConfig, } from './auth/cookie-config';
|
|
58
|
+
export { LANGUAGE_COOKIE_NAME, LANGUAGE_COOKIE_MAX_AGE, LANGUAGE_HEADER_NAME } from './language/cookie-config';
|
|
59
|
+
export { CURRENCY_COOKIE_NAME, CURRENCY_COOKIE_MAX_AGE, CURRENCY_HEADER_NAME } from './currency/cookie-config';
|
|
60
|
+
export { CART_COOKIE_NAME, CART_COOKIE_MAX_AGE } from './cart/cookie-config';
|
|
54
61
|
export { matchesRoute, type RouteProtectionConfig } from './auth/routes';
|
|
55
62
|
export { createSetTokenHandler, createClearTokenHandler } from './auth/handlers';
|
|
56
63
|
export { createAuthTokenClient, type AuthTokenClient } from './auth/token-client';
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAGH,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAGhE,YAAY,EACV,gBAAgB,EAChB,sBAAsB,EACtB,UAAU,EACV,SAAS,EACT,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,YAAY,EACZ,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,KAAK,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAGpF,OAAO,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,YAAY,EACZ,WAAW,EACX,0BAA0B,EAC1B,KAAK,cAAc,GACpB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,YAAY,EACV,IAAI,EACJ,QAAQ,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gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/core/index.js
CHANGED
|
@@ -38,9 +38,14 @@ export { createStorefrontClient } from './client/create-client';
|
|
|
38
38
|
// Middleware
|
|
39
39
|
export { authMiddleware } from './middleware/auth';
|
|
40
40
|
export { currencyMiddleware } from './middleware/currency';
|
|
41
|
+
export { languageMiddleware } from './middleware/language';
|
|
42
|
+
export { botProtectionMiddleware, BOT_PROTECTION_HEADER, } from './middleware/bot-protection';
|
|
41
43
|
export { retryMiddleware } from './middleware/retry';
|
|
42
44
|
export { timeoutMiddleware } from './middleware/timeout';
|
|
43
45
|
export { errorMiddleware } from './middleware/errors';
|
|
46
|
+
// Bot protection managers (framework-agnostic, DOM APIs)
|
|
47
|
+
export { createBotProtectionManager } from './bot-protection/create-manager';
|
|
48
|
+
export { FallbackBotProtectionManager } from './bot-protection/fallback-manager';
|
|
44
49
|
// Errors
|
|
45
50
|
export { StorefrontError, ErrorCodes } from './errors';
|
|
46
51
|
// Cache strategies
|
|
@@ -57,6 +62,12 @@ export { normalizeConnection, } from './helpers/normalize-connection';
|
|
|
57
62
|
export { formatPrice, formatPriceRange, formatAmount, formatDate, formatDateTime, formatNumber, formatPercentage, getCurrencySymbol, CURRENCY_SYMBOLS, CURRENCY_LOCALES, } from './format';
|
|
58
63
|
// Auth cookie config (platform contract)
|
|
59
64
|
export { AUTH_COOKIE_NAME, AUTH_COOKIE_DEFAULTS, } from './auth/cookie-config';
|
|
65
|
+
// Language config
|
|
66
|
+
export { LANGUAGE_COOKIE_NAME, LANGUAGE_COOKIE_MAX_AGE, LANGUAGE_HEADER_NAME } from './language/cookie-config';
|
|
67
|
+
// Currency config
|
|
68
|
+
export { CURRENCY_COOKIE_NAME, CURRENCY_COOKIE_MAX_AGE, CURRENCY_HEADER_NAME } from './currency/cookie-config';
|
|
69
|
+
// Cart cookie config
|
|
70
|
+
export { CART_COOKIE_NAME, CART_COOKIE_MAX_AGE } from './cart/cookie-config';
|
|
60
71
|
// Auth route matching
|
|
61
72
|
export { matchesRoute } from './auth/routes';
|
|
62
73
|
// Auth cookie handlers (API route factories)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Language configuration constants — platform contract.
|
|
3
|
+
*
|
|
4
|
+
* Used by:
|
|
5
|
+
* - SDK language store (client-side cookie read/write)
|
|
6
|
+
* - SDK language middleware (X-Lang header)
|
|
7
|
+
* - next-intl middleware `localeCookie.name` (server-side locale detection)
|
|
8
|
+
*
|
|
9
|
+
* Single cookie replaces both next-intl's NEXT_LOCALE and SDK's preferred-language.
|
|
10
|
+
*/
|
|
11
|
+
export declare const LANGUAGE_COOKIE_NAME = "preferred-language";
|
|
12
|
+
export declare const LANGUAGE_COOKIE_MAX_AGE: number;
|
|
13
|
+
export declare const LANGUAGE_HEADER_NAME = "X-Lang";
|
|
14
|
+
//# sourceMappingURL=cookie-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookie-config.d.ts","sourceRoot":"","sources":["../../../src/core/language/cookie-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,uBAAuB,CAAC;AACzD,eAAO,MAAM,uBAAuB,QAAqB,CAAC;AAC1D,eAAO,MAAM,oBAAoB,WAAW,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Language configuration constants — platform contract.
|
|
3
|
+
*
|
|
4
|
+
* Used by:
|
|
5
|
+
* - SDK language store (client-side cookie read/write)
|
|
6
|
+
* - SDK language middleware (X-Lang header)
|
|
7
|
+
* - next-intl middleware `localeCookie.name` (server-side locale detection)
|
|
8
|
+
*
|
|
9
|
+
* Single cookie replaces both next-intl's NEXT_LOCALE and SDK's preferred-language.
|
|
10
|
+
*/
|
|
11
|
+
export const LANGUAGE_COOKIE_NAME = 'preferred-language';
|
|
12
|
+
export const LANGUAGE_COOKIE_MAX_AGE = 365 * 24 * 60 * 60; // 1 year
|
|
13
|
+
export const LANGUAGE_HEADER_NAME = 'X-Lang';
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bot protection middleware — vendor-agnostic token injection.
|
|
3
|
+
*
|
|
4
|
+
* Intercepts protected mutations and adds a bot verification token
|
|
5
|
+
* via the X-Bot-Protection-Token header. Token acquisition is delegated
|
|
6
|
+
* to a BotProtectionTokenProvider (EU CAPTCHA, Turnstile, etc.).
|
|
7
|
+
*
|
|
8
|
+
* Fail strategy is per-operation: 'open' = continue without token,
|
|
9
|
+
* 'closed' = throw if token unavailable.
|
|
10
|
+
*/
|
|
11
|
+
import type { Middleware } from '../client/types';
|
|
12
|
+
/** Vendor-agnostic token provider interface */
|
|
13
|
+
export interface BotProtectionTokenProvider {
|
|
14
|
+
/**
|
|
15
|
+
* Get a fresh bot protection token.
|
|
16
|
+
* Handles: in-flight deduplication, timeout, singleton script loading.
|
|
17
|
+
*
|
|
18
|
+
* @param options.action - Operation name (e.g. 'CustomerCreate') for action validation
|
|
19
|
+
* @param options.timeoutMs - Timeout in ms (default: 10000)
|
|
20
|
+
* @returns Token string or null if unavailable (adblock, timeout, error)
|
|
21
|
+
*/
|
|
22
|
+
execute(options?: {
|
|
23
|
+
action?: string;
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
}): Promise<string | null>;
|
|
26
|
+
/** Cleanup widget and script resources */
|
|
27
|
+
destroy(): void;
|
|
28
|
+
}
|
|
29
|
+
/** Single provider config (from shop query) */
|
|
30
|
+
export interface BotProtectionProviderConfig {
|
|
31
|
+
/** Provider identifier: 'eucaptcha' | 'turnstile' | 'recaptcha' | extensible */
|
|
32
|
+
provider: string;
|
|
33
|
+
/** Site key for the bot protection widget */
|
|
34
|
+
siteKey: string;
|
|
35
|
+
/** Script URL — configurable for region-specific / enterprise overrides */
|
|
36
|
+
scriptUrl: string;
|
|
37
|
+
}
|
|
38
|
+
/** Bot protection configuration from shop query */
|
|
39
|
+
export interface BotProtectionConfig {
|
|
40
|
+
/** Primary provider */
|
|
41
|
+
primary: BotProtectionProviderConfig;
|
|
42
|
+
/** Fallback provider (runtime: if primary fails -> fallback -> fail-open) */
|
|
43
|
+
fallback?: BotProtectionProviderConfig | null;
|
|
44
|
+
/** GraphQL operation names requiring verification */
|
|
45
|
+
protectedOperations: string[];
|
|
46
|
+
}
|
|
47
|
+
/** Fail strategy per request */
|
|
48
|
+
export type FailStrategy = 'open' | 'closed';
|
|
49
|
+
export interface BotProtectionMiddlewareOptions {
|
|
50
|
+
/** Token provider instance (manager or fallback chain) */
|
|
51
|
+
tokenProvider: BotProtectionTokenProvider;
|
|
52
|
+
/** GraphQL operation names that require bot protection */
|
|
53
|
+
protectedOperations: string[];
|
|
54
|
+
/** Default fail strategy when token acquisition fails (default: 'open') */
|
|
55
|
+
defaultFailStrategy?: FailStrategy;
|
|
56
|
+
/** Override fail strategy per operation (e.g. CheckoutComplete = closed) */
|
|
57
|
+
failStrategyOverrides?: Record<string, FailStrategy>;
|
|
58
|
+
}
|
|
59
|
+
/** Header name for bot protection token */
|
|
60
|
+
export declare const BOT_PROTECTION_HEADER = "X-Bot-Protection-Token";
|
|
61
|
+
/**
|
|
62
|
+
* Creates bot protection middleware for the SDK pipeline.
|
|
63
|
+
*
|
|
64
|
+
* Only intercepts mutations whose operationName is in protectedOperations.
|
|
65
|
+
* Token is fetched fresh on every call (single-use tokens, retry-safe).
|
|
66
|
+
*
|
|
67
|
+
* Pipeline position: AFTER auth/currency, BEFORE retry/timeout/errors.
|
|
68
|
+
* Retry middleware re-executes the full chain, so each attempt gets a fresh token.
|
|
69
|
+
*/
|
|
70
|
+
export declare function botProtectionMiddleware(options: BotProtectionMiddlewareOptions): Middleware;
|
|
71
|
+
//# sourceMappingURL=bot-protection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bot-protection.d.ts","sourceRoot":"","sources":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,uBAAuB,CAAC,OAAO,EAAE,8BAA8B,GAAG,UAAU,CA2C3F"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bot protection middleware — vendor-agnostic token injection.
|
|
3
|
+
*
|
|
4
|
+
* Intercepts protected mutations and adds a bot verification token
|
|
5
|
+
* via the X-Bot-Protection-Token header. Token acquisition is delegated
|
|
6
|
+
* to a BotProtectionTokenProvider (EU CAPTCHA, Turnstile, etc.).
|
|
7
|
+
*
|
|
8
|
+
* Fail strategy is per-operation: 'open' = continue without token,
|
|
9
|
+
* 'closed' = throw if token unavailable.
|
|
10
|
+
*/
|
|
11
|
+
import { StorefrontError } from '../errors';
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// Constants
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
/** Header name for bot protection token */
|
|
16
|
+
export const BOT_PROTECTION_HEADER = 'X-Bot-Protection-Token';
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// Middleware factory
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
/**
|
|
21
|
+
* Creates bot protection middleware for the SDK pipeline.
|
|
22
|
+
*
|
|
23
|
+
* Only intercepts mutations whose operationName is in protectedOperations.
|
|
24
|
+
* Token is fetched fresh on every call (single-use tokens, retry-safe).
|
|
25
|
+
*
|
|
26
|
+
* Pipeline position: AFTER auth/currency, BEFORE retry/timeout/errors.
|
|
27
|
+
* Retry middleware re-executes the full chain, so each attempt gets a fresh token.
|
|
28
|
+
*/
|
|
29
|
+
export function botProtectionMiddleware(options) {
|
|
30
|
+
const { tokenProvider, protectedOperations, defaultFailStrategy = 'open', failStrategyOverrides = {}, } = options;
|
|
31
|
+
const protectedSet = new Set(protectedOperations);
|
|
32
|
+
return async (request, next) => {
|
|
33
|
+
// Only intercept mutations
|
|
34
|
+
if (!request.isMutation)
|
|
35
|
+
return next(request);
|
|
36
|
+
// Only intercept protected operations
|
|
37
|
+
const opName = request.operationName;
|
|
38
|
+
if (!opName || !protectedSet.has(opName)) {
|
|
39
|
+
return next(request);
|
|
40
|
+
}
|
|
41
|
+
// Fetch fresh token — action param enables backend action validation
|
|
42
|
+
const token = await tokenProvider.execute({
|
|
43
|
+
action: opName,
|
|
44
|
+
timeoutMs: 10000,
|
|
45
|
+
});
|
|
46
|
+
if (token) {
|
|
47
|
+
request.headers[BOT_PROTECTION_HEADER] = token;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
// Fail strategy: open = continue without token, closed = throw
|
|
51
|
+
const strategy = failStrategyOverrides[opName] ?? defaultFailStrategy;
|
|
52
|
+
if (strategy === 'closed') {
|
|
53
|
+
throw new StorefrontError({
|
|
54
|
+
code: 'BOT_PROTECTION_REQUIRED',
|
|
55
|
+
message: 'Bot protection verification failed. Please try again.',
|
|
56
|
+
status: 0,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
// fail-open: continue without token — backend guard may still reject
|
|
60
|
+
}
|
|
61
|
+
return next(request);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../../src/core/middleware/currency.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../../src/core/middleware/currency.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,GAC3C,UAAU,CAQZ"}
|
|
@@ -10,11 +10,12 @@
|
|
|
10
10
|
* client.use(currencyMiddleware(() => currencyStore.getState().currency));
|
|
11
11
|
* ```
|
|
12
12
|
*/
|
|
13
|
+
import { CURRENCY_HEADER_NAME } from '../currency/cookie-config';
|
|
13
14
|
export function currencyMiddleware(getCurrency) {
|
|
14
15
|
return (request, next) => {
|
|
15
16
|
const currency = getCurrency();
|
|
16
17
|
if (currency) {
|
|
17
|
-
request.headers[
|
|
18
|
+
request.headers[CURRENCY_HEADER_NAME] = currency;
|
|
18
19
|
}
|
|
19
20
|
return next(request);
|
|
20
21
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Language middleware — adds X-Lang header.
|
|
3
|
+
*
|
|
4
|
+
* Language is resolved lazily so language switches are reflected immediately.
|
|
5
|
+
* CRITICAL: does NOT send header when language=null (store not yet initialized)
|
|
6
|
+
* — without this, backend returns default language, React Query caches it,
|
|
7
|
+
* and after setLanguage() the cache is stale.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { languageMiddleware } from '@doswiftly/storefront-sdk';
|
|
12
|
+
*
|
|
13
|
+
* client.use(languageMiddleware(() => languageStore.getState().language));
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
import type { Middleware } from '../client/types';
|
|
17
|
+
export declare function languageMiddleware(getLanguage: () => string | null | undefined): Middleware;
|
|
18
|
+
//# sourceMappingURL=language.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language.d.ts","sourceRoot":"","sources":["../../../src/core/middleware/language.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,GAC3C,UAAU,CAQZ"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Language middleware — adds X-Lang header.
|
|
3
|
+
*
|
|
4
|
+
* Language is resolved lazily so language switches are reflected immediately.
|
|
5
|
+
* CRITICAL: does NOT send header when language=null (store not yet initialized)
|
|
6
|
+
* — without this, backend returns default language, React Query caches it,
|
|
7
|
+
* and after setLanguage() the cache is stale.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { languageMiddleware } from '@doswiftly/storefront-sdk';
|
|
12
|
+
*
|
|
13
|
+
* client.use(languageMiddleware(() => languageStore.getState().language));
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
import { LANGUAGE_HEADER_NAME } from '../language/cookie-config';
|
|
17
|
+
export function languageMiddleware(getLanguage) {
|
|
18
|
+
return (request, next) => {
|
|
19
|
+
const language = getLanguage();
|
|
20
|
+
if (language) {
|
|
21
|
+
request.headers[LANGUAGE_HEADER_NAME] = language;
|
|
22
|
+
}
|
|
23
|
+
return next(request);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bot protection React context.
|
|
3
|
+
*
|
|
4
|
+
* Provides access to the BotProtectionTokenProvider manager
|
|
5
|
+
* for the useBotProtection() escape hatch hook.
|
|
6
|
+
*/
|
|
7
|
+
import type { BotProtectionTokenProvider } from '../../core/middleware/bot-protection';
|
|
8
|
+
export interface BotProtectionContextValue {
|
|
9
|
+
manager: BotProtectionTokenProvider | null;
|
|
10
|
+
}
|
|
11
|
+
export declare const BotProtectionContext: import("react").Context<BotProtectionContextValue | null>;
|
|
12
|
+
//# sourceMappingURL=bot-protection-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bot-protection-context.d.ts","sourceRoot":"","sources":["../../../src/react/bot-protection/bot-protection-context.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAEvF,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,0BAA0B,GAAG,IAAI,CAAC;CAC5C;AAED,eAAO,MAAM,oBAAoB,2DAAwD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bot protection React context.
|
|
3
|
+
*
|
|
4
|
+
* Provides access to the BotProtectionTokenProvider manager
|
|
5
|
+
* for the useBotProtection() escape hatch hook.
|
|
6
|
+
*/
|
|
7
|
+
'use client';
|
|
8
|
+
import { createContext } from 'react';
|
|
9
|
+
export const BotProtectionContext = createContext(null);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BotProtectionWidget — invisible React wrapper that mounts the bot protection manager.
|
|
3
|
+
*
|
|
4
|
+
* Renders a hidden div and mounts/unmounts the manager lifecycle.
|
|
5
|
+
* Triggers lazy script preload on mount.
|
|
6
|
+
*/
|
|
7
|
+
import type { BotProtectionTokenProvider } from '../../core/middleware/bot-protection';
|
|
8
|
+
interface BotProtectionWidgetProps {
|
|
9
|
+
manager: BotProtectionTokenProvider | null;
|
|
10
|
+
}
|
|
11
|
+
export declare function BotProtectionWidget({ manager }: BotProtectionWidgetProps): import("react/jsx-runtime").JSX.Element | null;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=bot-protection-widget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bot-protection-widget.d.ts","sourceRoot":"","sources":["../../../src/react/bot-protection/bot-protection-widget.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAGvF,UAAU,wBAAwB;IAChC,OAAO,EAAE,0BAA0B,GAAG,IAAI,CAAC;CAC5C;AAED,wBAAgB,mBAAmB,CAAC,EAAE,OAAO,EAAE,EAAE,wBAAwB,kDA4BxE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BotProtectionWidget — invisible React wrapper that mounts the bot protection manager.
|
|
3
|
+
*
|
|
4
|
+
* Renders a hidden div and mounts/unmounts the manager lifecycle.
|
|
5
|
+
* Triggers lazy script preload on mount.
|
|
6
|
+
*/
|
|
7
|
+
'use client';
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
import { useEffect, useRef } from 'react';
|
|
10
|
+
export function BotProtectionWidget({ manager }) {
|
|
11
|
+
const containerRef = useRef(null);
|
|
12
|
+
const mountedRef = useRef(false);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (!manager || !containerRef.current || mountedRef.current)
|
|
15
|
+
return;
|
|
16
|
+
mountedRef.current = true;
|
|
17
|
+
// Trigger lazy script preload + mount container
|
|
18
|
+
const mgr = manager;
|
|
19
|
+
if (typeof mgr.loadScript === 'function') {
|
|
20
|
+
mgr.loadScript().catch(() => {
|
|
21
|
+
// Script load failure is handled gracefully in execute()
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (typeof mgr.mount === 'function') {
|
|
25
|
+
mgr.mount(containerRef.current);
|
|
26
|
+
}
|
|
27
|
+
return () => {
|
|
28
|
+
mountedRef.current = false;
|
|
29
|
+
};
|
|
30
|
+
}, [manager]);
|
|
31
|
+
if (!manager)
|
|
32
|
+
return null;
|
|
33
|
+
return _jsx("div", { ref: containerRef, style: { display: 'none' }, "aria-hidden": "true" });
|
|
34
|
+
}
|
package/dist/react/cookies.d.ts
CHANGED
|
@@ -10,11 +10,14 @@
|
|
|
10
10
|
export declare function getCookie(name: string): string | null;
|
|
11
11
|
/**
|
|
12
12
|
* Set cookie (client-side only).
|
|
13
|
+
*
|
|
14
|
+
* `secure` defaults to auto-detect from `location.protocol` (true on HTTPS).
|
|
13
15
|
*/
|
|
14
16
|
export declare function setCookie(name: string, value: string, options?: {
|
|
15
17
|
maxAge?: number;
|
|
16
18
|
path?: string;
|
|
17
19
|
sameSite?: string;
|
|
20
|
+
secure?: boolean;
|
|
18
21
|
}): void;
|
|
19
22
|
/**
|
|
20
23
|
* Delete cookie (client-side only).
|
|
@@ -25,4 +28,18 @@ export declare function deleteCookie(name: string, path?: string): void;
|
|
|
25
28
|
* Falls back to document.cookie on client.
|
|
26
29
|
*/
|
|
27
30
|
export declare function getCurrencyFromCookieAsync(): Promise<string | null>;
|
|
31
|
+
/**
|
|
32
|
+
* Get cart ID from cookie (async — works with Next.js cookies()).
|
|
33
|
+
* Falls back to document.cookie on client.
|
|
34
|
+
*
|
|
35
|
+
* Use in Server Components for SSR cart badge:
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const cartId = await getCartIdFromCookieAsync();
|
|
38
|
+
* if (cartId) {
|
|
39
|
+
* const cart = await fetchCart(cartId);
|
|
40
|
+
* // Render cart badge with real totalQuantity — no skeleton needed
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function getCartIdFromCookieAsync(): Promise<string | null>;
|
|
28
45
|
//# sourceMappingURL=cookies.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../../src/react/cookies.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAIrD;AAED
|
|
1
|
+
{"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../../src/react/cookies.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAIrD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GACpF,IAAI,CAON;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,SAAM,GAAG,IAAI,CAG3D;AAKD;;;GAGG;AACH,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAYzE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAYvE"}
|
package/dist/react/cookies.js
CHANGED
|
@@ -15,12 +15,17 @@ export function getCookie(name) {
|
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Set cookie (client-side only).
|
|
18
|
+
*
|
|
19
|
+
* `secure` defaults to auto-detect from `location.protocol` (true on HTTPS).
|
|
18
20
|
*/
|
|
19
21
|
export function setCookie(name, value, options = {}) {
|
|
20
22
|
if (typeof document === 'undefined')
|
|
21
23
|
return;
|
|
22
24
|
const { maxAge = 365 * 24 * 60 * 60, path = '/', sameSite = 'lax' } = options;
|
|
23
|
-
|
|
25
|
+
const secure = options.secure ??
|
|
26
|
+
(typeof location !== 'undefined' && location.protocol === 'https:');
|
|
27
|
+
const securePart = secure ? ';secure' : '';
|
|
28
|
+
document.cookie = `${name}=${encodeURIComponent(value)};max-age=${maxAge};path=${path};samesite=${sameSite}${securePart}`;
|
|
24
29
|
}
|
|
25
30
|
/**
|
|
26
31
|
* Delete cookie (client-side only).
|
|
@@ -30,6 +35,8 @@ export function deleteCookie(name, path = '/') {
|
|
|
30
35
|
return;
|
|
31
36
|
document.cookie = `${name}=;max-age=0;path=${path}`;
|
|
32
37
|
}
|
|
38
|
+
import { CURRENCY_COOKIE_NAME } from '../core/currency/cookie-config';
|
|
39
|
+
import { CART_COOKIE_NAME } from '../core/cart/cookie-config';
|
|
33
40
|
/**
|
|
34
41
|
* Get preferred currency from cookie (async — works with Next.js cookies()).
|
|
35
42
|
* Falls back to document.cookie on client.
|
|
@@ -39,11 +46,37 @@ export async function getCurrencyFromCookieAsync() {
|
|
|
39
46
|
try {
|
|
40
47
|
const { cookies } = await import('next/headers');
|
|
41
48
|
const cookieStore = await cookies();
|
|
42
|
-
return cookieStore.get(
|
|
49
|
+
return cookieStore.get(CURRENCY_COOKIE_NAME)?.value ?? null;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// Not in a server context or next not available
|
|
53
|
+
}
|
|
54
|
+
// Client-side fallback
|
|
55
|
+
return getCookie(CURRENCY_COOKIE_NAME);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get cart ID from cookie (async — works with Next.js cookies()).
|
|
59
|
+
* Falls back to document.cookie on client.
|
|
60
|
+
*
|
|
61
|
+
* Use in Server Components for SSR cart badge:
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const cartId = await getCartIdFromCookieAsync();
|
|
64
|
+
* if (cartId) {
|
|
65
|
+
* const cart = await fetchCart(cartId);
|
|
66
|
+
* // Render cart badge with real totalQuantity — no skeleton needed
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export async function getCartIdFromCookieAsync() {
|
|
71
|
+
// Server-side: try Next.js cookies()
|
|
72
|
+
try {
|
|
73
|
+
const { cookies } = await import('next/headers');
|
|
74
|
+
const cookieStore = await cookies();
|
|
75
|
+
return cookieStore.get(CART_COOKIE_NAME)?.value ?? null;
|
|
43
76
|
}
|
|
44
77
|
catch {
|
|
45
78
|
// Not in a server context or next not available
|
|
46
79
|
}
|
|
47
80
|
// Client-side fallback
|
|
48
|
-
return getCookie(
|
|
81
|
+
return getCookie(CART_COOKIE_NAME);
|
|
49
82
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useBotProtection — escape hatch hook for custom bot protection use cases.
|
|
3
|
+
*
|
|
4
|
+
* Normally the middleware handles token injection automatically.
|
|
5
|
+
* Use this hook only when you need manual control (e.g. custom forms).
|
|
6
|
+
*/
|
|
7
|
+
export declare function useBotProtection(): {
|
|
8
|
+
/** Execute a bot protection challenge and get a token */
|
|
9
|
+
execute: (options?: {
|
|
10
|
+
action?: string;
|
|
11
|
+
timeoutMs?: number;
|
|
12
|
+
}) => Promise<string | null>;
|
|
13
|
+
/** Whether bot protection is configured and available */
|
|
14
|
+
isAvailable: boolean;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=use-bot-protection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-bot-protection.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-bot-protection.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,wBAAgB,gBAAgB;IAa5B,yDAAyD;wBAR9C;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE;IAUlD,yDAAyD;;EAG5D"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useBotProtection — escape hatch hook for custom bot protection use cases.
|
|
3
|
+
*
|
|
4
|
+
* Normally the middleware handles token injection automatically.
|
|
5
|
+
* Use this hook only when you need manual control (e.g. custom forms).
|
|
6
|
+
*/
|
|
7
|
+
'use client';
|
|
8
|
+
import { useContext, useCallback } from 'react';
|
|
9
|
+
import { BotProtectionContext } from '../bot-protection/bot-protection-context';
|
|
10
|
+
export function useBotProtection() {
|
|
11
|
+
const ctx = useContext(BotProtectionContext);
|
|
12
|
+
const manager = ctx?.manager ?? null;
|
|
13
|
+
const execute = useCallback((options) => {
|
|
14
|
+
if (!manager)
|
|
15
|
+
return Promise.resolve(null);
|
|
16
|
+
return manager.execute(options);
|
|
17
|
+
}, [manager]);
|
|
18
|
+
return {
|
|
19
|
+
/** Execute a bot protection challenge and get a token */
|
|
20
|
+
execute,
|
|
21
|
+
/** Whether bot protection is configured and available */
|
|
22
|
+
isAvailable: !!manager,
|
|
23
|
+
};
|
|
24
|
+
}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -14,17 +14,26 @@
|
|
|
14
14
|
export { StorefrontProvider, type StorefrontProviderProps } from './providers/storefront-provider';
|
|
15
15
|
export { StorefrontClientProvider, type StorefrontClientProviderProps } from './providers/storefront-client-provider';
|
|
16
16
|
export { CurrencyProvider, type CurrencyProviderProps } from './providers/currency-provider';
|
|
17
|
+
export { LanguageProvider, type LanguageProviderProps } from './providers/language-provider';
|
|
17
18
|
export { useAuth, type UseAuthOptions, type LoginResult, type LogoutResult, type TokenRenewResult } from './hooks/use-auth';
|
|
18
19
|
export { useCartManager } from './hooks/use-cart-manager';
|
|
19
20
|
export { useStorefrontClient } from './hooks/use-storefront-client';
|
|
20
21
|
export { useCurrency } from './hooks/use-currency';
|
|
21
22
|
export { useAuthStore, useAuthStoreApi, useAuthHydrated } from './stores/store-context';
|
|
22
23
|
export { useCurrencyStore, useCurrencyStoreApi } from './stores/store-context';
|
|
24
|
+
export { useLanguageStore, useLanguageStoreApi } from './stores/store-context';
|
|
23
25
|
export type { AuthStore, CustomerInfo } from './stores/auth.store';
|
|
24
26
|
export type { CurrencyStore, ShopCurrencyData } from './stores/currency.store';
|
|
27
|
+
export type { LanguageStore } from './stores/language.store';
|
|
28
|
+
export type { ShopConfig } from './types/shop-config';
|
|
25
29
|
export { selectCurrency, selectBaseCurrency, selectSupportedCurrencies, selectIsLoaded } from './stores/currency.store';
|
|
26
|
-
export {
|
|
30
|
+
export { selectLanguage, selectDefaultLanguage, selectSupportedLanguages, selectLanguageIsLoaded } from './stores/language.store';
|
|
31
|
+
export { getCookie, setCookie, deleteCookie, getCurrencyFromCookieAsync, getCartIdFromCookieAsync } from './cookies';
|
|
32
|
+
export { useBotProtection } from './hooks/use-bot-protection';
|
|
27
33
|
export { useHydrated } from './hooks/use-hydrated';
|
|
28
34
|
export { useDebouncedValue } from './hooks/use-debounced-value';
|
|
35
|
+
export { createCartStore, selectCartId, selectIsCartOpen, selectCartIsLoading, } from './stores/cart.store';
|
|
36
|
+
export type { CartState, CartStoreConfig, CartActions, CartData, CartMutationAction, CartLineInput, CartLineUpdateInput, } from './stores/cart.store';
|
|
37
|
+
export { CartProvider, useCartStore, useCartStoreApi } from './stores/cart.context';
|
|
29
38
|
export { createStoreContext } from './helpers/create-store-context';
|
|
30
39
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,kBAAkB,EAAE,KAAK,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AACnG,OAAO,EAAE,wBAAwB,EAAE,KAAK,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AACtH,OAAO,EAAE,gBAAgB,EAAE,KAAK,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAG7F,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC5H,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACxF,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAG/E,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnE,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,kBAAkB,EAAE,KAAK,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AACnG,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AGrH,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAG9D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAGhE,OAAO,EACL,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,SAAS,EACT,eAAe,EACf,WAAW,EACX,QAAQ,EACR,kBAAkB,EAClB,aAAa,EACb,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC"}
|
package/dist/react/index.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
export { StorefrontProvider } from './providers/storefront-provider';
|
|
16
16
|
export { StorefrontClientProvider } from './providers/storefront-client-provider';
|
|
17
17
|
export { CurrencyProvider } from './providers/currency-provider';
|
|
18
|
+
export { LanguageProvider } from './providers/language-provider';
|
|
18
19
|
// Hooks
|
|
19
20
|
export { useAuth } from './hooks/use-auth';
|
|
20
21
|
export { useCartManager } from './hooks/use-cart-manager';
|
|
@@ -23,12 +24,19 @@ export { useCurrency } from './hooks/use-currency';
|
|
|
23
24
|
// Store hooks (Context-based)
|
|
24
25
|
export { useAuthStore, useAuthStoreApi, useAuthHydrated } from './stores/store-context';
|
|
25
26
|
export { useCurrencyStore, useCurrencyStoreApi } from './stores/store-context';
|
|
27
|
+
export { useLanguageStore, useLanguageStoreApi } from './stores/store-context';
|
|
26
28
|
// Selectors
|
|
27
29
|
export { selectCurrency, selectBaseCurrency, selectSupportedCurrencies, selectIsLoaded } from './stores/currency.store';
|
|
30
|
+
export { selectLanguage, selectDefaultLanguage, selectSupportedLanguages, selectLanguageIsLoaded } from './stores/language.store';
|
|
28
31
|
// Cookie utilities
|
|
29
|
-
export { getCookie, setCookie, deleteCookie, getCurrencyFromCookieAsync } from './cookies';
|
|
32
|
+
export { getCookie, setCookie, deleteCookie, getCurrencyFromCookieAsync, getCartIdFromCookieAsync } from './cookies';
|
|
33
|
+
// Bot protection
|
|
34
|
+
export { useBotProtection } from './hooks/use-bot-protection';
|
|
30
35
|
// Generic hooks
|
|
31
36
|
export { useHydrated } from './hooks/use-hydrated';
|
|
32
37
|
export { useDebouncedValue } from './hooks/use-debounced-value';
|
|
38
|
+
// Cart store (DI-based)
|
|
39
|
+
export { createCartStore, selectCartId, selectIsCartOpen, selectCartIsLoading, } from './stores/cart.store';
|
|
40
|
+
export { CartProvider, useCartStore, useCartStoreApi } from './stores/cart.context';
|
|
33
41
|
// Store context helper
|
|
34
42
|
export { createStoreContext } from './helpers/create-store-context';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LanguageProvider — initializes language store from Shop data.
|
|
3
|
+
*
|
|
4
|
+
* Thin wrapper that calls useLanguageStore.initialize() on mount
|
|
5
|
+
* with the shop's language configuration from the server.
|
|
6
|
+
*
|
|
7
|
+
* NOTE: This only sets defaultLanguage and supportedLanguages.
|
|
8
|
+
* The active `language` is set by the template's LanguageSyncProvider
|
|
9
|
+
* which reads locale from the URL (via next-intl) and calls setLanguage().
|
|
10
|
+
*/
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import type { ShopConfig } from '../types/shop-config';
|
|
13
|
+
export interface LanguageProviderProps {
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
shopData: ShopConfig;
|
|
16
|
+
}
|
|
17
|
+
export declare function LanguageProvider({ children, shopData }: LanguageProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
//# sourceMappingURL=language-provider.d.ts.map
|