@doswiftly/storefront-sdk 4.0.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 +430 -0
- package/dist/__tests__/unit/test-helpers.d.ts +46 -0
- package/dist/__tests__/unit/test-helpers.d.ts.map +1 -0
- package/dist/__tests__/unit/test-helpers.js +72 -0
- package/dist/core/auth/auth-client.d.ts +46 -0
- package/dist/core/auth/auth-client.d.ts.map +1 -0
- package/dist/core/auth/auth-client.js +82 -0
- package/dist/core/auth/cookie-config.d.ts +18 -0
- package/dist/core/auth/cookie-config.d.ts.map +1 -0
- package/dist/core/auth/cookie-config.js +18 -0
- package/dist/core/auth/handlers.d.ts +32 -0
- package/dist/core/auth/handlers.d.ts.map +1 -0
- package/dist/core/auth/handlers.js +127 -0
- package/dist/core/auth/routes.d.ts +21 -0
- package/dist/core/auth/routes.d.ts.map +1 -0
- package/dist/core/auth/routes.js +14 -0
- package/dist/core/auth/token-client.d.ts +26 -0
- package/dist/core/auth/token-client.d.ts.map +1 -0
- package/dist/core/auth/token-client.js +42 -0
- package/dist/core/auth/types.d.ts +53 -0
- package/dist/core/auth/types.d.ts.map +1 -0
- package/dist/core/auth/types.js +4 -0
- package/dist/core/cache.d.ts +54 -0
- package/dist/core/cache.d.ts.map +1 -0
- package/dist/core/cache.js +82 -0
- package/dist/core/cart/cart-client.d.ts +57 -0
- package/dist/core/cart/cart-client.d.ts.map +1 -0
- package/dist/core/cart/cart-client.js +89 -0
- package/dist/core/cart/types.d.ts +110 -0
- package/dist/core/cart/types.d.ts.map +1 -0
- package/dist/core/cart/types.js +6 -0
- package/dist/core/client/compose.d.ts +9 -0
- package/dist/core/client/compose.d.ts.map +1 -0
- package/dist/core/client/compose.js +9 -0
- package/dist/core/client/create-client.d.ts +15 -0
- package/dist/core/client/create-client.d.ts.map +1 -0
- package/dist/core/client/create-client.js +85 -0
- package/dist/core/client/dedupe.d.ts +7 -0
- package/dist/core/client/dedupe.d.ts.map +1 -0
- package/dist/core/client/dedupe.js +16 -0
- package/dist/core/client/execute.d.ts +20 -0
- package/dist/core/client/execute.d.ts.map +1 -0
- package/dist/core/client/execute.js +48 -0
- package/dist/core/client/hash.d.ts +7 -0
- package/dist/core/client/hash.d.ts.map +1 -0
- package/dist/core/client/hash.js +21 -0
- package/dist/core/client/operation-name.d.ts +7 -0
- package/dist/core/client/operation-name.d.ts.map +1 -0
- package/dist/core/client/operation-name.js +10 -0
- package/dist/core/client/types.d.ts +126 -0
- package/dist/core/client/types.d.ts.map +1 -0
- package/dist/core/client/types.js +26 -0
- package/dist/core/errors.d.ts +43 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +43 -0
- package/dist/core/format.d.ts +92 -0
- package/dist/core/format.d.ts.map +1 -0
- package/dist/core/format.js +216 -0
- package/dist/core/helpers/assert-no-user-errors.d.ts +10 -0
- package/dist/core/helpers/assert-no-user-errors.d.ts.map +1 -0
- package/dist/core/helpers/assert-no-user-errors.js +16 -0
- package/dist/core/helpers/normalize-connection.d.ts +36 -0
- package/dist/core/helpers/normalize-connection.d.ts.map +1 -0
- package/dist/core/helpers/normalize-connection.js +21 -0
- package/dist/core/helpers/sanitize-html.d.ts +8 -0
- package/dist/core/helpers/sanitize-html.d.ts.map +1 -0
- package/dist/core/helpers/sanitize-html.js +35 -0
- package/dist/core/index.d.ts +59 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +68 -0
- package/dist/core/middleware/auth.d.ts +16 -0
- package/dist/core/middleware/auth.d.ts.map +1 -0
- package/dist/core/middleware/auth.js +22 -0
- package/dist/core/middleware/currency.d.ts +15 -0
- package/dist/core/middleware/currency.d.ts.map +1 -0
- package/dist/core/middleware/currency.js +21 -0
- package/dist/core/middleware/errors.d.ts +24 -0
- package/dist/core/middleware/errors.d.ts.map +1 -0
- package/dist/core/middleware/errors.js +77 -0
- package/dist/core/middleware/retry.d.ts +22 -0
- package/dist/core/middleware/retry.d.ts.map +1 -0
- package/dist/core/middleware/retry.js +58 -0
- package/dist/core/middleware/timeout.d.ts +19 -0
- package/dist/core/middleware/timeout.d.ts.map +1 -0
- package/dist/core/middleware/timeout.js +51 -0
- package/dist/core/operations/auth.d.ts +11 -0
- package/dist/core/operations/auth.d.ts.map +1 -0
- package/dist/core/operations/auth.js +112 -0
- package/dist/core/operations/cart.d.ts +15 -0
- package/dist/core/operations/cart.d.ts.map +1 -0
- package/dist/core/operations/cart.js +169 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/react/cookies.d.ts +28 -0
- package/dist/react/cookies.d.ts.map +1 -0
- package/dist/react/cookies.js +49 -0
- package/dist/react/helpers/create-store-context.d.ts +37 -0
- package/dist/react/helpers/create-store-context.d.ts.map +1 -0
- package/dist/react/helpers/create-store-context.js +47 -0
- package/dist/react/hooks/use-auth.d.ts +65 -0
- package/dist/react/hooks/use-auth.d.ts.map +1 -0
- package/dist/react/hooks/use-auth.js +168 -0
- package/dist/react/hooks/use-cart-manager.d.ts +30 -0
- package/dist/react/hooks/use-cart-manager.d.ts.map +1 -0
- package/dist/react/hooks/use-cart-manager.js +223 -0
- package/dist/react/hooks/use-currency.d.ts +11 -0
- package/dist/react/hooks/use-currency.d.ts.map +1 -0
- package/dist/react/hooks/use-currency.js +19 -0
- package/dist/react/hooks/use-debounced-value.d.ts +15 -0
- package/dist/react/hooks/use-debounced-value.d.ts.map +1 -0
- package/dist/react/hooks/use-debounced-value.js +25 -0
- package/dist/react/hooks/use-hydrated.d.ts +9 -0
- package/dist/react/hooks/use-hydrated.d.ts.map +1 -0
- package/dist/react/hooks/use-hydrated.js +14 -0
- package/dist/react/hooks/use-storefront-client.d.ts +6 -0
- package/dist/react/hooks/use-storefront-client.d.ts.map +1 -0
- package/dist/react/hooks/use-storefront-client.js +8 -0
- package/dist/react/index.d.ts +30 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +34 -0
- package/dist/react/providers/currency-provider.d.ts +14 -0
- package/dist/react/providers/currency-provider.d.ts.map +1 -0
- package/dist/react/providers/currency-provider.js +20 -0
- package/dist/react/providers/storefront-client-provider.d.ts +33 -0
- package/dist/react/providers/storefront-client-provider.d.ts.map +1 -0
- package/dist/react/providers/storefront-client-provider.js +57 -0
- package/dist/react/providers/storefront-provider.d.ts +42 -0
- package/dist/react/providers/storefront-provider.d.ts.map +1 -0
- package/dist/react/providers/storefront-provider.js +40 -0
- package/dist/react/server/get-storefront-client.d.ts +42 -0
- package/dist/react/server/get-storefront-client.d.ts.map +1 -0
- package/dist/react/server/get-storefront-client.js +44 -0
- package/dist/react/server/index.d.ts +2 -0
- package/dist/react/server/index.d.ts.map +1 -0
- package/dist/react/server/index.js +1 -0
- package/dist/react/stores/auth.store.d.ts +48 -0
- package/dist/react/stores/auth.store.d.ts.map +1 -0
- package/dist/react/stores/auth.store.js +67 -0
- package/dist/react/stores/currency.store.d.ts +29 -0
- package/dist/react/stores/currency.store.d.ts.map +1 -0
- package/dist/react/stores/currency.store.js +76 -0
- package/dist/react/stores/index.d.ts +8 -0
- package/dist/react/stores/index.d.ts.map +1 -0
- package/dist/react/stores/index.js +10 -0
- package/dist/react/stores/store-context.d.ts +27 -0
- package/dist/react/stores/store-context.d.ts.map +1 -0
- package/dist/react/stores/store-context.js +62 -0
- package/package.json +71 -0
- package/src/__tests__/contract/storefront-api.contract.test.ts +450 -0
- package/src/__tests__/unit/auth-client.test.ts +210 -0
- package/src/__tests__/unit/cart-client.test.ts +233 -0
- package/src/__tests__/unit/create-client.test.ts +356 -0
- package/src/__tests__/unit/helpers.test.ts +377 -0
- package/src/__tests__/unit/middleware.test.ts +374 -0
- package/src/__tests__/unit/test-helpers.ts +103 -0
- package/src/core/auth/auth-client.ts +123 -0
- package/src/core/auth/cookie-config.ts +23 -0
- package/src/core/auth/handlers.ts +168 -0
- package/src/core/auth/routes.ts +26 -0
- package/src/core/auth/token-client.ts +51 -0
- package/src/core/auth/types.ts +54 -0
- package/src/core/cache.ts +102 -0
- package/src/core/cart/cart-client.ts +150 -0
- package/src/core/cart/types.ts +104 -0
- package/src/core/client/compose.ts +15 -0
- package/src/core/client/create-client.ts +129 -0
- package/src/core/client/dedupe.ts +19 -0
- package/src/core/client/execute.ts +70 -0
- package/src/core/client/hash.ts +21 -0
- package/src/core/client/operation-name.ts +12 -0
- package/src/core/client/types.ts +171 -0
- package/src/core/errors.ts +67 -0
- package/src/core/format.ts +254 -0
- package/src/core/helpers/assert-no-user-errors.ts +21 -0
- package/src/core/helpers/normalize-connection.ts +48 -0
- package/src/core/helpers/sanitize-html.ts +42 -0
- package/src/core/index.ts +148 -0
- package/src/core/middleware/auth.ts +27 -0
- package/src/core/middleware/currency.ts +26 -0
- package/src/core/middleware/errors.ts +86 -0
- package/src/core/middleware/retry.ts +75 -0
- package/src/core/middleware/timeout.ts +61 -0
- package/src/core/operations/auth.ts +123 -0
- package/src/core/operations/cart.ts +185 -0
- package/src/index.ts +25 -0
- package/src/react/cookies.ts +54 -0
- package/src/react/helpers/create-store-context.ts +56 -0
- package/src/react/hooks/use-auth.ts +218 -0
- package/src/react/hooks/use-cart-manager.ts +236 -0
- package/src/react/hooks/use-currency.ts +23 -0
- package/src/react/hooks/use-debounced-value.ts +30 -0
- package/src/react/hooks/use-hydrated.ts +20 -0
- package/src/react/hooks/use-storefront-client.ts +12 -0
- package/src/react/index.ts +45 -0
- package/src/react/providers/currency-provider.tsx +30 -0
- package/src/react/providers/storefront-client-provider.tsx +90 -0
- package/src/react/providers/storefront-provider.tsx +71 -0
- package/src/react/server/get-storefront-client.ts +60 -0
- package/src/react/server/index.ts +1 -0
- package/src/react/stores/auth.store.ts +112 -0
- package/src/react/stores/currency.store.ts +113 -0
- package/src/react/stores/index.ts +17 -0
- package/src/react/stores/store-context.tsx +82 -0
- package/tsconfig.json +20 -0
- package/vitest.config.ts +14 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth Cookie Configuration — platform contract.
|
|
3
|
+
*
|
|
4
|
+
* Backend validates cookie by name `customerAccessToken`.
|
|
5
|
+
* Every storefront MUST use the same name. Security options
|
|
6
|
+
* (httpOnly, secure, sameSite) are the platform standard.
|
|
7
|
+
*/
|
|
8
|
+
export declare const AUTH_COOKIE_NAME = "customerAccessToken";
|
|
9
|
+
export declare const AUTH_COOKIE_DEFAULTS: {
|
|
10
|
+
readonly name: "customerAccessToken";
|
|
11
|
+
readonly path: "/";
|
|
12
|
+
readonly sameSite: "lax";
|
|
13
|
+
readonly httpOnly: true;
|
|
14
|
+
readonly secure: boolean;
|
|
15
|
+
readonly maxAge: number;
|
|
16
|
+
};
|
|
17
|
+
export type AuthCookieConfig = typeof AUTH_COOKIE_DEFAULTS;
|
|
18
|
+
//# sourceMappingURL=cookie-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookie-config.d.ts","sourceRoot":"","sources":["../../../src/core/auth/cookie-config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,eAAO,MAAM,gBAAgB,wBAAwB,CAAC;AAEtD,eAAO,MAAM,oBAAoB;;;;;;;CAUvB,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,OAAO,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth Cookie Configuration — platform contract.
|
|
3
|
+
*
|
|
4
|
+
* Backend validates cookie by name `customerAccessToken`.
|
|
5
|
+
* Every storefront MUST use the same name. Security options
|
|
6
|
+
* (httpOnly, secure, sameSite) are the platform standard.
|
|
7
|
+
*/
|
|
8
|
+
export const AUTH_COOKIE_NAME = 'customerAccessToken';
|
|
9
|
+
export const AUTH_COOKIE_DEFAULTS = {
|
|
10
|
+
name: AUTH_COOKIE_NAME,
|
|
11
|
+
path: '/',
|
|
12
|
+
sameSite: 'lax',
|
|
13
|
+
httpOnly: true,
|
|
14
|
+
secure: typeof window !== 'undefined'
|
|
15
|
+
? window.location.protocol === 'https:'
|
|
16
|
+
: process.env.NODE_ENV === 'production',
|
|
17
|
+
maxAge: 60 * 60 * 24 * 30, // 30 days
|
|
18
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth cookie handlers — factory functions for API routes.
|
|
3
|
+
*
|
|
4
|
+
* 0 deps, pure Web API (Request/Response). Framework-agnostic.
|
|
5
|
+
* Creates set-token and clear-token handlers that any storefront
|
|
6
|
+
* can use as 2-line API routes.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* // app/api/auth/set-token/route.ts
|
|
11
|
+
* import { createSetTokenHandler } from '@doswiftly/storefront-sdk';
|
|
12
|
+
* export const POST = createSetTokenHandler();
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
interface SetTokenHandlerOptions {
|
|
16
|
+
maxAge?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Create a POST handler that sets the auth token in an httpOnly cookie.
|
|
20
|
+
*
|
|
21
|
+
* Security: origin validation, Content-Type check, CSRF (SameSite=Lax),
|
|
22
|
+
* httpOnly (XSS protection), Secure in production.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createSetTokenHandler(overrides?: SetTokenHandlerOptions): (request: Request) => Promise<Response>;
|
|
25
|
+
/**
|
|
26
|
+
* Create a POST handler that clears the auth token cookie.
|
|
27
|
+
*
|
|
28
|
+
* Security: origin validation, immediate expiration (maxAge=0).
|
|
29
|
+
*/
|
|
30
|
+
export declare function createClearTokenHandler(): (request: Request) => Promise<Response>;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../../src/core/auth/handlers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,UAAU,sBAAsB;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAmCD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,CAAC,EAAE,sBAAsB,GACjC,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAgEzC;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAkCjF"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth cookie handlers — factory functions for API routes.
|
|
3
|
+
*
|
|
4
|
+
* 0 deps, pure Web API (Request/Response). Framework-agnostic.
|
|
5
|
+
* Creates set-token and clear-token handlers that any storefront
|
|
6
|
+
* can use as 2-line API routes.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* // app/api/auth/set-token/route.ts
|
|
11
|
+
* import { createSetTokenHandler } from '@doswiftly/storefront-sdk';
|
|
12
|
+
* export const POST = createSetTokenHandler();
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
import { AUTH_COOKIE_NAME, AUTH_COOKIE_DEFAULTS } from './cookie-config';
|
|
16
|
+
function serializeCookie(name, value, options) {
|
|
17
|
+
const parts = [`${name}=${value}`];
|
|
18
|
+
if (options.maxAge != null)
|
|
19
|
+
parts.push(`Max-Age=${options.maxAge}`);
|
|
20
|
+
if (options.path)
|
|
21
|
+
parts.push(`Path=${options.path}`);
|
|
22
|
+
if (options.sameSite)
|
|
23
|
+
parts.push(`SameSite=${options.sameSite}`);
|
|
24
|
+
if (options.secure)
|
|
25
|
+
parts.push('Secure');
|
|
26
|
+
if (options.httpOnly)
|
|
27
|
+
parts.push('HttpOnly');
|
|
28
|
+
return parts.join('; ');
|
|
29
|
+
}
|
|
30
|
+
function validateOrigin(request) {
|
|
31
|
+
const origin = request.headers.get('origin');
|
|
32
|
+
const host = request.headers.get('host');
|
|
33
|
+
if (origin && !origin.includes(host || '')) {
|
|
34
|
+
return new Response(JSON.stringify({ error: 'Invalid origin' }), {
|
|
35
|
+
status: 403,
|
|
36
|
+
headers: { 'Content-Type': 'application/json' },
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create a POST handler that sets the auth token in an httpOnly cookie.
|
|
43
|
+
*
|
|
44
|
+
* Security: origin validation, Content-Type check, CSRF (SameSite=Lax),
|
|
45
|
+
* httpOnly (XSS protection), Secure in production.
|
|
46
|
+
*/
|
|
47
|
+
export function createSetTokenHandler(overrides) {
|
|
48
|
+
const maxAge = overrides?.maxAge ?? AUTH_COOKIE_DEFAULTS.maxAge;
|
|
49
|
+
return async (request) => {
|
|
50
|
+
try {
|
|
51
|
+
// 1. CSRF: validate origin
|
|
52
|
+
const originError = validateOrigin(request);
|
|
53
|
+
if (originError)
|
|
54
|
+
return originError;
|
|
55
|
+
// 2. Validate Content-Type
|
|
56
|
+
const contentType = request.headers.get('content-type');
|
|
57
|
+
if (!contentType?.includes('application/json')) {
|
|
58
|
+
return new Response(JSON.stringify({ error: 'Content-Type must be application/json' }), { status: 400, headers: { 'Content-Type': 'application/json' } });
|
|
59
|
+
}
|
|
60
|
+
// 3. Parse body
|
|
61
|
+
let body;
|
|
62
|
+
try {
|
|
63
|
+
body = await request.json();
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return new Response(JSON.stringify({ error: 'Invalid JSON body' }), { status: 400, headers: { 'Content-Type': 'application/json' } });
|
|
67
|
+
}
|
|
68
|
+
const { token } = body;
|
|
69
|
+
if (!token || typeof token !== 'string' || token.trim() === '') {
|
|
70
|
+
return new Response(JSON.stringify({ error: 'Token is required and must be a non-empty string' }), { status: 400, headers: { 'Content-Type': 'application/json' } });
|
|
71
|
+
}
|
|
72
|
+
// 4. Set httpOnly cookie
|
|
73
|
+
const cookie = serializeCookie(AUTH_COOKIE_NAME, token, {
|
|
74
|
+
maxAge,
|
|
75
|
+
path: AUTH_COOKIE_DEFAULTS.path,
|
|
76
|
+
sameSite: AUTH_COOKIE_DEFAULTS.sameSite,
|
|
77
|
+
secure: AUTH_COOKIE_DEFAULTS.secure,
|
|
78
|
+
httpOnly: AUTH_COOKIE_DEFAULTS.httpOnly,
|
|
79
|
+
});
|
|
80
|
+
return new Response(JSON.stringify({ success: true, message: 'Token set successfully' }), {
|
|
81
|
+
status: 200,
|
|
82
|
+
headers: {
|
|
83
|
+
'Content-Type': 'application/json',
|
|
84
|
+
'Set-Cookie': cookie,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
console.error('Error setting auth token:', error);
|
|
90
|
+
return new Response(JSON.stringify({ error: 'Internal server error' }), { status: 500, headers: { 'Content-Type': 'application/json' } });
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Create a POST handler that clears the auth token cookie.
|
|
96
|
+
*
|
|
97
|
+
* Security: origin validation, immediate expiration (maxAge=0).
|
|
98
|
+
*/
|
|
99
|
+
export function createClearTokenHandler() {
|
|
100
|
+
return async (request) => {
|
|
101
|
+
try {
|
|
102
|
+
// 1. CSRF: validate origin
|
|
103
|
+
const originError = validateOrigin(request);
|
|
104
|
+
if (originError)
|
|
105
|
+
return originError;
|
|
106
|
+
// 2. Clear cookie (maxAge=0)
|
|
107
|
+
const cookie = serializeCookie(AUTH_COOKIE_NAME, '', {
|
|
108
|
+
maxAge: 0,
|
|
109
|
+
path: AUTH_COOKIE_DEFAULTS.path,
|
|
110
|
+
sameSite: AUTH_COOKIE_DEFAULTS.sameSite,
|
|
111
|
+
secure: AUTH_COOKIE_DEFAULTS.secure,
|
|
112
|
+
httpOnly: AUTH_COOKIE_DEFAULTS.httpOnly,
|
|
113
|
+
});
|
|
114
|
+
return new Response(JSON.stringify({ success: true, message: 'Token cleared successfully' }), {
|
|
115
|
+
status: 200,
|
|
116
|
+
headers: {
|
|
117
|
+
'Content-Type': 'application/json',
|
|
118
|
+
'Set-Cookie': cookie,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
console.error('Error clearing auth token:', error);
|
|
124
|
+
return new Response(JSON.stringify({ error: 'Internal server error' }), { status: 500, headers: { 'Content-Type': 'application/json' } });
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route matching utility for auth redirects.
|
|
3
|
+
*
|
|
4
|
+
* Pure function — route lists stay in the template (SSOT config),
|
|
5
|
+
* but matching logic lives in the SDK (reusable across templates).
|
|
6
|
+
*/
|
|
7
|
+
export interface RouteProtectionConfig {
|
|
8
|
+
protectedRoutes: string[];
|
|
9
|
+
guestOnlyRoutes: string[];
|
|
10
|
+
redirects: {
|
|
11
|
+
unauthenticated: string;
|
|
12
|
+
authenticated: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Check if a pathname matches any route in the list.
|
|
17
|
+
* Supports both exact matches and prefix matches
|
|
18
|
+
* (e.g., "/account" matches "/account/orders").
|
|
19
|
+
*/
|
|
20
|
+
export declare function matchesRoute(pathname: string, routes: string[]): boolean;
|
|
21
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../src/core/auth/routes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,qBAAqB;IACpC,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,SAAS,EAAE;QACT,eAAe,EAAE,MAAM,CAAC;QACxB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;CACH;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAIxE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route matching utility for auth redirects.
|
|
3
|
+
*
|
|
4
|
+
* Pure function — route lists stay in the template (SSOT config),
|
|
5
|
+
* but matching logic lives in the SDK (reusable across templates).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Check if a pathname matches any route in the list.
|
|
9
|
+
* Supports both exact matches and prefix matches
|
|
10
|
+
* (e.g., "/account" matches "/account/orders").
|
|
11
|
+
*/
|
|
12
|
+
export function matchesRoute(pathname, routes) {
|
|
13
|
+
return routes.some((route) => pathname === route || pathname.startsWith(`${route}/`));
|
|
14
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side auth token helpers — fetch-based, 0 deps.
|
|
3
|
+
*
|
|
4
|
+
* Calls API routes to set/clear the httpOnly auth cookie.
|
|
5
|
+
* Used by template hooks (use-auth.ts, use-auth-sync.ts, register-form.tsx).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createAuthTokenClient } from '@doswiftly/storefront-sdk';
|
|
10
|
+
* const { setToken, clearToken } = createAuthTokenClient();
|
|
11
|
+
*
|
|
12
|
+
* await setToken(accessToken);
|
|
13
|
+
* await clearToken();
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export interface AuthTokenClient {
|
|
17
|
+
setToken: (token: string) => Promise<void>;
|
|
18
|
+
clearToken: () => Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create a client for managing auth tokens via API routes.
|
|
22
|
+
*
|
|
23
|
+
* @param basePath - Base path for API routes (default: "/api/auth")
|
|
24
|
+
*/
|
|
25
|
+
export declare function createAuthTokenClient(basePath?: string): AuthTokenClient;
|
|
26
|
+
//# sourceMappingURL=token-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-client.d.ts","sourceRoot":"","sources":["../../../src/core/auth/token-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,SAAc,GAAG,eAAe,CAwB7E"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side auth token helpers — fetch-based, 0 deps.
|
|
3
|
+
*
|
|
4
|
+
* Calls API routes to set/clear the httpOnly auth cookie.
|
|
5
|
+
* Used by template hooks (use-auth.ts, use-auth-sync.ts, register-form.tsx).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createAuthTokenClient } from '@doswiftly/storefront-sdk';
|
|
10
|
+
* const { setToken, clearToken } = createAuthTokenClient();
|
|
11
|
+
*
|
|
12
|
+
* await setToken(accessToken);
|
|
13
|
+
* await clearToken();
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Create a client for managing auth tokens via API routes.
|
|
18
|
+
*
|
|
19
|
+
* @param basePath - Base path for API routes (default: "/api/auth")
|
|
20
|
+
*/
|
|
21
|
+
export function createAuthTokenClient(basePath = '/api/auth') {
|
|
22
|
+
return {
|
|
23
|
+
async setToken(token) {
|
|
24
|
+
const response = await fetch(`${basePath}/set-token`, {
|
|
25
|
+
method: 'POST',
|
|
26
|
+
headers: { 'Content-Type': 'application/json' },
|
|
27
|
+
body: JSON.stringify({ token }),
|
|
28
|
+
});
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
throw new Error('Failed to set authentication token');
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
async clearToken() {
|
|
34
|
+
const response = await fetch(`${basePath}/clear-token`, {
|
|
35
|
+
method: 'POST',
|
|
36
|
+
});
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
throw new Error('Failed to clear authentication token');
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth types — manual (no codegen).
|
|
3
|
+
*/
|
|
4
|
+
export interface CustomerAccessToken {
|
|
5
|
+
accessToken: string;
|
|
6
|
+
expiresAt: string;
|
|
7
|
+
}
|
|
8
|
+
export interface Customer {
|
|
9
|
+
id: string;
|
|
10
|
+
email: string;
|
|
11
|
+
firstName: string | null;
|
|
12
|
+
lastName: string | null;
|
|
13
|
+
displayName: string | null;
|
|
14
|
+
phone: string | null;
|
|
15
|
+
emailVerified: boolean;
|
|
16
|
+
emailMarketingState: string | null;
|
|
17
|
+
defaultAddress: MailingAddress | null;
|
|
18
|
+
ordersCount: number;
|
|
19
|
+
totalSpent: {
|
|
20
|
+
amount: string;
|
|
21
|
+
currencyCode: string;
|
|
22
|
+
} | null;
|
|
23
|
+
createdAt: string;
|
|
24
|
+
updatedAt: string;
|
|
25
|
+
}
|
|
26
|
+
export interface MailingAddress {
|
|
27
|
+
id: string;
|
|
28
|
+
address1: string | null;
|
|
29
|
+
address2: string | null;
|
|
30
|
+
city: string | null;
|
|
31
|
+
company: string | null;
|
|
32
|
+
country: string | null;
|
|
33
|
+
countryCode: string | null;
|
|
34
|
+
firstName: string | null;
|
|
35
|
+
lastName: string | null;
|
|
36
|
+
phone: string | null;
|
|
37
|
+
province: string | null;
|
|
38
|
+
provinceCode: string | null;
|
|
39
|
+
zip: string | null;
|
|
40
|
+
isDefault: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface AuthResult {
|
|
43
|
+
accessToken: string;
|
|
44
|
+
expiresAt: string;
|
|
45
|
+
customer?: Customer;
|
|
46
|
+
}
|
|
47
|
+
export interface CustomerCreateInput {
|
|
48
|
+
email: string;
|
|
49
|
+
password: string;
|
|
50
|
+
firstName?: string;
|
|
51
|
+
lastName?: string;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/auth/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,aAAa,EAAE,OAAO,CAAC;IACvB,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,cAAc,EAAE,cAAc,GAAG,IAAI,CAAC;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC5D,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache strategies — functions (not constants) with override support.
|
|
3
|
+
*
|
|
4
|
+
* Inspired by Shopify Hydrogen's caching strategies.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { cacheLong, cacheShort } from '@doswiftly/storefront-sdk';
|
|
9
|
+
*
|
|
10
|
+
* // Default
|
|
11
|
+
* const data = await client.query(ShopQuery, {}, cacheLong());
|
|
12
|
+
*
|
|
13
|
+
* // Override with tags (Next.js revalidateTag)
|
|
14
|
+
* const data = await client.query(ProductQuery, { slug }, cacheLong({ tags: ['product', slug] }));
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
import type { CacheStrategy, CacheOptions } from './client/types';
|
|
18
|
+
export interface CacheOverrides {
|
|
19
|
+
/** Override max-age (seconds) */
|
|
20
|
+
maxAge?: number;
|
|
21
|
+
/** Override stale-while-revalidate (seconds) */
|
|
22
|
+
staleWhileRevalidate?: number;
|
|
23
|
+
/** Cache tags (for Next.js revalidateTag) */
|
|
24
|
+
tags?: string[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* No caching — every request hits the server.
|
|
28
|
+
* Use for: Cart, Customer data, real-time inventory.
|
|
29
|
+
*/
|
|
30
|
+
export declare function cacheNone(overrides?: CacheOverrides): CacheStrategy;
|
|
31
|
+
/**
|
|
32
|
+
* Short cache — 1s max-age, 9s stale-while-revalidate (10s total).
|
|
33
|
+
* Use for: Product listings, collections, search results.
|
|
34
|
+
*/
|
|
35
|
+
export declare function cacheShort(overrides?: CacheOverrides): CacheStrategy;
|
|
36
|
+
/**
|
|
37
|
+
* Long cache — 1h max-age, 23h stale-while-revalidate (24h total).
|
|
38
|
+
* Use for: Static content, shop info, rarely changing data.
|
|
39
|
+
*/
|
|
40
|
+
export declare function cacheLong(overrides?: CacheOverrides): CacheStrategy;
|
|
41
|
+
/**
|
|
42
|
+
* Private cache — 1s max-age, no sharing between users.
|
|
43
|
+
* Use for: Personalized content, customer-specific data.
|
|
44
|
+
*/
|
|
45
|
+
export declare function cachePrivate(overrides?: CacheOverrides): CacheStrategy;
|
|
46
|
+
/**
|
|
47
|
+
* Custom cache — full control over all options.
|
|
48
|
+
*/
|
|
49
|
+
export declare function cacheCustom(options: CacheOptions): CacheStrategy;
|
|
50
|
+
/**
|
|
51
|
+
* Generate Cache-Control header string from cache strategy.
|
|
52
|
+
*/
|
|
53
|
+
export declare function generateCacheControlHeader(cache: CacheStrategy): string;
|
|
54
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/core/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAElE,MAAM,WAAW,cAAc;IAC7B,iCAAiC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,6CAA6C;IAC7C,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,SAAS,CAAC,EAAE,cAAc,GAAG,aAAa,CAMnE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,SAAS,CAAC,EAAE,cAAc,GAAG,aAAa,CAOpE;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,SAAS,CAAC,EAAE,cAAc,GAAG,aAAa,CAOnE;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,SAAS,CAAC,EAAE,cAAc,GAAG,aAAa,CAOtE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,aAAa,CAEhE;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,CAYvE"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache strategies — functions (not constants) with override support.
|
|
3
|
+
*
|
|
4
|
+
* Inspired by Shopify Hydrogen's caching strategies.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { cacheLong, cacheShort } from '@doswiftly/storefront-sdk';
|
|
9
|
+
*
|
|
10
|
+
* // Default
|
|
11
|
+
* const data = await client.query(ShopQuery, {}, cacheLong());
|
|
12
|
+
*
|
|
13
|
+
* // Override with tags (Next.js revalidateTag)
|
|
14
|
+
* const data = await client.query(ProductQuery, { slug }, cacheLong({ tags: ['product', slug] }));
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* No caching — every request hits the server.
|
|
19
|
+
* Use for: Cart, Customer data, real-time inventory.
|
|
20
|
+
*/
|
|
21
|
+
export function cacheNone(overrides) {
|
|
22
|
+
return {
|
|
23
|
+
maxAge: 0,
|
|
24
|
+
mode: 'no-store',
|
|
25
|
+
tags: overrides?.tags,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Short cache — 1s max-age, 9s stale-while-revalidate (10s total).
|
|
30
|
+
* Use for: Product listings, collections, search results.
|
|
31
|
+
*/
|
|
32
|
+
export function cacheShort(overrides) {
|
|
33
|
+
return {
|
|
34
|
+
maxAge: overrides?.maxAge ?? 1,
|
|
35
|
+
staleWhileRevalidate: overrides?.staleWhileRevalidate ?? 9,
|
|
36
|
+
mode: 'public',
|
|
37
|
+
tags: overrides?.tags,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Long cache — 1h max-age, 23h stale-while-revalidate (24h total).
|
|
42
|
+
* Use for: Static content, shop info, rarely changing data.
|
|
43
|
+
*/
|
|
44
|
+
export function cacheLong(overrides) {
|
|
45
|
+
return {
|
|
46
|
+
maxAge: overrides?.maxAge ?? 3600,
|
|
47
|
+
staleWhileRevalidate: overrides?.staleWhileRevalidate ?? 82800,
|
|
48
|
+
mode: 'public',
|
|
49
|
+
tags: overrides?.tags,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Private cache — 1s max-age, no sharing between users.
|
|
54
|
+
* Use for: Personalized content, customer-specific data.
|
|
55
|
+
*/
|
|
56
|
+
export function cachePrivate(overrides) {
|
|
57
|
+
return {
|
|
58
|
+
maxAge: overrides?.maxAge ?? 1,
|
|
59
|
+
staleWhileRevalidate: overrides?.staleWhileRevalidate ?? 9,
|
|
60
|
+
mode: 'private',
|
|
61
|
+
tags: overrides?.tags,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Custom cache — full control over all options.
|
|
66
|
+
*/
|
|
67
|
+
export function cacheCustom(options) {
|
|
68
|
+
return { ...options };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Generate Cache-Control header string from cache strategy.
|
|
72
|
+
*/
|
|
73
|
+
export function generateCacheControlHeader(cache) {
|
|
74
|
+
if (cache.mode === 'no-store') {
|
|
75
|
+
return 'no-store, no-cache, must-revalidate';
|
|
76
|
+
}
|
|
77
|
+
const parts = [cache.mode, `max-age=${cache.maxAge}`];
|
|
78
|
+
if (cache.staleWhileRevalidate !== undefined) {
|
|
79
|
+
parts.push(`stale-while-revalidate=${cache.staleWhileRevalidate}`);
|
|
80
|
+
}
|
|
81
|
+
return parts.join(', ');
|
|
82
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CartClient — plain async API for cart operations (no React, no React Query).
|
|
3
|
+
*
|
|
4
|
+
* Wraps StorefrontClient.mutate/query with typed operations.
|
|
5
|
+
* Auto-throws on userErrors via assertNoUserErrors.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const cartClient = new CartClient(storefrontClient);
|
|
10
|
+
*
|
|
11
|
+
* const cart = await cartClient.create();
|
|
12
|
+
* const updated = await cartClient.addItem(cart.id, [
|
|
13
|
+
* { merchandiseId: 'variant-123', quantity: 1 }
|
|
14
|
+
* ]);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
import type { StorefrontClient } from '../client/types';
|
|
18
|
+
import type { Cart, CartCreateInput, CartLineInput, CartLineUpdateInput, CartBuyerIdentityInput } from './types';
|
|
19
|
+
export declare class CartClient {
|
|
20
|
+
private readonly client;
|
|
21
|
+
constructor(client: StorefrontClient);
|
|
22
|
+
/**
|
|
23
|
+
* Fetch existing cart by ID.
|
|
24
|
+
* Returns null if cart doesn't exist or has expired.
|
|
25
|
+
*/
|
|
26
|
+
get(cartId: string): Promise<Cart | null>;
|
|
27
|
+
/**
|
|
28
|
+
* Create a new cart, optionally with initial lines.
|
|
29
|
+
*/
|
|
30
|
+
create(input?: CartCreateInput): Promise<Cart>;
|
|
31
|
+
/**
|
|
32
|
+
* Add line items to an existing cart.
|
|
33
|
+
*/
|
|
34
|
+
addItems(cartId: string, lines: CartLineInput[]): Promise<Cart>;
|
|
35
|
+
/**
|
|
36
|
+
* Update line items (quantity, attributes).
|
|
37
|
+
*/
|
|
38
|
+
updateItems(cartId: string, lines: CartLineUpdateInput[]): Promise<Cart>;
|
|
39
|
+
/**
|
|
40
|
+
* Remove line items by their line IDs.
|
|
41
|
+
*/
|
|
42
|
+
removeItems(cartId: string, lineIds: string[]): Promise<Cart>;
|
|
43
|
+
/**
|
|
44
|
+
* Update discount codes (replaces all existing codes).
|
|
45
|
+
* Pass empty array to clear discounts.
|
|
46
|
+
*/
|
|
47
|
+
updateDiscountCodes(cartId: string, discountCodes: string[]): Promise<Cart>;
|
|
48
|
+
/**
|
|
49
|
+
* Update cart note / gift message.
|
|
50
|
+
*/
|
|
51
|
+
updateNote(cartId: string, note: string): Promise<Cart>;
|
|
52
|
+
/**
|
|
53
|
+
* Update buyer identity (email, phone, country, customer link).
|
|
54
|
+
*/
|
|
55
|
+
updateBuyerIdentity(cartId: string, buyerIdentity: CartBuyerIdentityInput): Promise<Cart>;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=cart-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cart-client.d.ts","sourceRoot":"","sources":["../../../src/core/cart/cart-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,EACV,IAAI,EACJ,eAAe,EACf,aAAa,EACb,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,SAAS,CAAC;AA0BjB,qBAAa,UAAU;IACT,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,gBAAgB;IAErD;;;OAGG;IACG,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAQ/C;;OAEG;IACG,MAAM,CAAC,KAAK,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IASpD;;OAEG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IASrE;;OAEG;IACG,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAS9E;;OAEG;IACG,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IASnE;;;OAGG;IACG,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IASjF;;OAEG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS7D;;OAEG;IACG,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;CAQhG"}
|