@decocms/apps-wake 7.72.0 → 8.1.0-next.1
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/package.json +8 -29
- package/src/index.ts +9 -56
- package/src/storefront.ts +13 -0
- package/src/storefrontTypes.ts +6 -0
- package/src/utils/gql.ts +23 -0
- package/src/utils/graphql/queries.ts +1 -1
- package/src/wakeClient.ts +104 -0
- package/src/actions/cart/addCoupon.ts +0 -43
- package/src/actions/cart/addItem.ts +0 -10
- package/src/actions/cart/addItems.ts +0 -50
- package/src/actions/cart/addKit.ts +0 -53
- package/src/actions/cart/partnerAssociate.ts +0 -48
- package/src/actions/cart/partnerDisassociate.ts +0 -43
- package/src/actions/cart/removeCoupon.ts +0 -39
- package/src/actions/cart/removeKit.ts +0 -56
- package/src/actions/cart/updateItemQuantity.ts +0 -69
- package/src/actions/newsletter/register.ts +0 -32
- package/src/actions/notifyme.ts +0 -28
- package/src/actions/review/create.ts +0 -30
- package/src/actions/shippingSimulation.ts +0 -60
- package/src/actions/submmitForm.ts +0 -25
- package/src/actions/wishlist/addProduct.ts +0 -43
- package/src/actions/wishlist/removeProduct.ts +0 -45
- package/src/client.ts +0 -123
- package/src/commerceLoaders.ts +0 -137
- package/src/handlers/sitemap.ts +0 -61
- package/src/loaders/cart.ts +0 -46
- package/src/loaders/partners.ts +0 -58
- package/src/loaders/productDetailsPage.ts +0 -174
- package/src/loaders/productList.ts +0 -262
- package/src/loaders/productListingPage.ts +0 -333
- package/src/loaders/proxy.ts +0 -79
- package/src/loaders/recommendations.ts +0 -84
- package/src/loaders/shop.ts +0 -37
- package/src/loaders/suggestion.ts +0 -67
- package/src/loaders/user.ts +0 -48
- package/src/loaders/wishlist.ts +0 -40
- package/src/manifest.gen.ts +0 -69
- package/src/mod.ts +0 -88
- package/src/registry.ts +0 -9
- package/src/utils/authError.ts +0 -107
- package/src/utils/authenticate.ts +0 -42
- package/src/utils/capitalize.ts +0 -9
- package/src/utils/cart.ts +0 -33
- package/src/utils/cookies.ts +0 -82
- package/src/utils/getVariations.ts +0 -47
- package/src/utils/graphql.ts +0 -88
- package/src/utils/httpError.ts +0 -15
- package/src/utils/instrumentedFetch.ts +0 -46
- package/src/utils/operationRouter.ts +0 -51
- package/src/utils/parseHeaders.ts +0 -19
- package/src/utils/partner.ts +0 -34
- package/src/utils/requestCtx.ts +0 -41
- package/src/utils/transform.ts +0 -460
- package/src/utils/types.ts +0 -6
- package/src/utils/user.ts +0 -9
- package/tsconfig.json +0 -7
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/apps-wake",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.1.0-next.1",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "Thin Wake Commerce Storefront API client for Deco sites",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/decocms/blocks.git",
|
|
@@ -10,45 +10,24 @@
|
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"src",
|
|
13
|
-
"
|
|
13
|
+
"!src/**/*.test.ts",
|
|
14
|
+
"!src/**/__tests__"
|
|
14
15
|
],
|
|
15
16
|
"main": "./src/index.ts",
|
|
16
17
|
"exports": {
|
|
17
18
|
".": "./src/index.ts",
|
|
18
|
-
"./
|
|
19
|
-
"./
|
|
20
|
-
"./commerceLoaders": "./src/commerceLoaders.ts",
|
|
21
|
-
"./loaders/*": "./src/loaders/*.ts",
|
|
22
|
-
"./actions/*": "./src/actions/*.ts",
|
|
23
|
-
"./actions/cart/*": "./src/actions/cart/*.ts",
|
|
24
|
-
"./actions/newsletter/*": "./src/actions/newsletter/*.ts",
|
|
25
|
-
"./actions/review/*": "./src/actions/review/*.ts",
|
|
26
|
-
"./actions/wishlist/*": "./src/actions/wishlist/*.ts",
|
|
27
|
-
"./handlers/*": "./src/handlers/*.ts",
|
|
28
|
-
"./hooks": "./src/hooks/index.ts",
|
|
29
|
-
"./hooks/*": "./src/hooks/*.ts",
|
|
30
|
-
"./utils/*": "./src/utils/*.ts",
|
|
31
|
-
"./registry": "./src/registry.ts"
|
|
19
|
+
"./storefront": "./src/storefront.ts",
|
|
20
|
+
"./storefront/types": "./src/storefrontTypes.ts"
|
|
32
21
|
},
|
|
33
22
|
"scripts": {
|
|
34
23
|
"build": "tsc",
|
|
35
24
|
"test": "vitest run --root ../.. packages/apps-wake/",
|
|
36
|
-
"typecheck": "tsc --noEmit"
|
|
37
|
-
"lint:unused": "knip"
|
|
25
|
+
"typecheck": "tsc --noEmit"
|
|
38
26
|
},
|
|
39
27
|
"dependencies": {
|
|
40
|
-
"@decocms/blocks": "
|
|
41
|
-
"@decocms/apps-commerce": "7.72.0",
|
|
42
|
-
"@decocms/tanstack": "7.72.0"
|
|
43
|
-
},
|
|
44
|
-
"peerDependencies": {
|
|
45
|
-
"react": "^19.0.0",
|
|
46
|
-
"react-dom": "^19.0.0"
|
|
28
|
+
"@decocms/blocks": "8.1.0-next.1"
|
|
47
29
|
},
|
|
48
30
|
"devDependencies": {
|
|
49
|
-
"@types/react": "^19.0.0",
|
|
50
|
-
"@types/react-dom": "^19.0.0",
|
|
51
|
-
"knip": "^5.86.0",
|
|
52
31
|
"typescript": "^5.9.0"
|
|
53
32
|
},
|
|
54
33
|
"publishConfig": {
|
package/src/index.ts
CHANGED
|
@@ -1,58 +1,11 @@
|
|
|
1
|
-
//
|
|
1
|
+
// The thin Wake client (see /next/upstream-clients). Operations are in
|
|
2
|
+
// `@decocms/apps-wake/storefront`, their types in `.../storefront/types`.
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
export { default as addItem } from "./actions/cart/addItem";
|
|
5
|
-
export { type CartItem, default as addItems } from "./actions/cart/addItems";
|
|
6
|
-
export { default as updateItemQuantity } from "./actions/cart/updateItemQuantity";
|
|
7
|
-
// Client & Config
|
|
8
|
-
export type { WakeConfig } from "./client";
|
|
4
|
+
export type { UserAuthenticate } from "./utils/client";
|
|
9
5
|
export {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
setWakeFetch,
|
|
17
|
-
} from "./client";
|
|
18
|
-
// Commerce loaders factory (cached, CMS-registerable map)
|
|
19
|
-
export {
|
|
20
|
-
type CommerceLoaderFn,
|
|
21
|
-
createWakeCommerceLoaders,
|
|
22
|
-
type WakeCommerceLoadersOptions,
|
|
23
|
-
} from "./commerceLoaders";
|
|
24
|
-
// Cart / user / wishlist
|
|
25
|
-
export { default as cartLoader } from "./loaders/cart";
|
|
26
|
-
// Shop / partners
|
|
27
|
-
export { default as partnersLoader } from "./loaders/partners";
|
|
28
|
-
// Product loaders
|
|
29
|
-
export { default as productDetailsPageLoader } from "./loaders/productDetailsPage";
|
|
30
|
-
export { default as productListLoader } from "./loaders/productList";
|
|
31
|
-
export { default as productListingPageLoader } from "./loaders/productListingPage";
|
|
32
|
-
export type { WakeProxyRoute } from "./loaders/proxy";
|
|
33
|
-
export { default as proxyLoader } from "./loaders/proxy";
|
|
34
|
-
export { default as recommendationsLoader } from "./loaders/recommendations";
|
|
35
|
-
export { default as shopLoader } from "./loaders/shop";
|
|
36
|
-
export { default as suggestionLoader } from "./loaders/suggestion";
|
|
37
|
-
export { default as userLoader } from "./loaders/user";
|
|
38
|
-
export { default as wishlistLoader } from "./loaders/wishlist";
|
|
39
|
-
export { configure, type Props, type WakeState } from "./mod";
|
|
40
|
-
// Registry
|
|
41
|
-
export { WAKE_REGISTRY_ENTRY } from "./registry";
|
|
42
|
-
|
|
43
|
-
// Cookie utils
|
|
44
|
-
export { getCartCookie, setCartCookie, setClientCookie } from "./utils/cart";
|
|
45
|
-
export { getCookies, setCookie } from "./utils/cookies";
|
|
46
|
-
// GraphQL client + fetch instrumentation
|
|
47
|
-
export { extractGraphqlOperationName } from "./utils/graphqlOperationName";
|
|
48
|
-
export { type CreateWakeFetchOptions, createWakeFetch } from "./utils/instrumentedFetch";
|
|
49
|
-
export { wakeOperationRouter } from "./utils/operationRouter";
|
|
50
|
-
export { getPartnerCookie } from "./utils/partner";
|
|
51
|
-
// Transform helpers
|
|
52
|
-
export {
|
|
53
|
-
parseSlug,
|
|
54
|
-
toBreadcrumbList,
|
|
55
|
-
toFilters,
|
|
56
|
-
toProduct,
|
|
57
|
-
} from "./utils/transform";
|
|
58
|
-
export { getUserCookie } from "./utils/user";
|
|
6
|
+
createWakeClient,
|
|
7
|
+
type WakeClient,
|
|
8
|
+
type WakeClientConfig,
|
|
9
|
+
type WakeClientOptions,
|
|
10
|
+
WakeError,
|
|
11
|
+
} from "./wakeClient";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@decocms/apps-wake/storefront`: Wake's Storefront GraphQL operations, to
|
|
3
|
+
* pass to `createWakeClient`'s `graphql`. Their generated request and response
|
|
4
|
+
* types are in `@decocms/apps-wake/storefront/types`:
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { GetProduct } from "@decocms/apps-wake/storefront";
|
|
8
|
+
* import type { GetProductQuery, GetProductQueryVariables } from "@decocms/apps-wake/storefront/types";
|
|
9
|
+
*
|
|
10
|
+
* const data = await wake.graphql<GetProductQuery, GetProductQueryVariables>(GetProduct, { productId: 1 });
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export * from "./utils/graphql/queries";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@decocms/apps-wake/storefront/types`: types generated from Wake's
|
|
3
|
+
* Storefront GraphQL schema, one `<Operation>Query`/`<Operation>Mutation` and
|
|
4
|
+
* `...Variables` pair per operation in `@decocms/apps-wake/storefront`.
|
|
5
|
+
*/
|
|
6
|
+
export type * from "./utils/graphql/storefront.graphql.gen";
|
package/src/utils/gql.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GraphQL document helpers used by the client (`../wakeClient.ts`). Pure: no I/O, no framework imports.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Tagged-template helper that composes a GraphQL document string.
|
|
7
|
+
* Kept identical to the Deno `gql` so `graphql/queries.ts` (which defines
|
|
8
|
+
* `{ fragments, query }` objects) works verbatim.
|
|
9
|
+
*/
|
|
10
|
+
export function gql(strings: TemplateStringsArray, ...values: unknown[]): string {
|
|
11
|
+
return strings.reduce((acc, str, i) => acc + str + (values[i] ?? ""), "");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** A Wake storefront operation: its document plus the fragments it spreads. */
|
|
15
|
+
export interface QueryDefinition {
|
|
16
|
+
fragments?: string[];
|
|
17
|
+
query: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function buildQuery(def: QueryDefinition): string {
|
|
21
|
+
const fragments = def.fragments?.join("\n") ?? "";
|
|
22
|
+
return fragments ? `${fragments}\n${def.query}` : def.query;
|
|
23
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Wake client: a thin, typed client for Wake's Storefront GraphQL API and
|
|
3
|
+
* the one checkout REST call a storefront needs, over the framework's
|
|
4
|
+
* instrumented fetch (provider "wake"). See /next/upstream-clients.
|
|
5
|
+
*
|
|
6
|
+
* Configuration comes in as arguments; the site reads its environment where
|
|
7
|
+
* it creates the client. Converters, hooks, cart/session flows, caching and
|
|
8
|
+
* proxying belong to the site (platform templates), not here.
|
|
9
|
+
*/
|
|
10
|
+
import { createInstrumentedFetch } from "@decocms/blocks/fetch";
|
|
11
|
+
import type { UserAuthenticate } from "./utils/client";
|
|
12
|
+
import { buildQuery, type QueryDefinition } from "./utils/gql";
|
|
13
|
+
import { extractGraphqlOperationName } from "./utils/graphqlOperationName";
|
|
14
|
+
|
|
15
|
+
const WAKE_STOREFRONT_ENDPOINT = "https://storefront-api.fbits.net/graphql";
|
|
16
|
+
|
|
17
|
+
export interface WakeClientConfig {
|
|
18
|
+
/** Wake Storefront API token, sent as `TCS-Access-Token`. */
|
|
19
|
+
storefrontToken: string;
|
|
20
|
+
/** Storefront GraphQL endpoint; defaults to Wake's multi-tenant endpoint. */
|
|
21
|
+
storefrontEndpoint?: string;
|
|
22
|
+
/** Checkout origin, e.g. `https://checkout.example.com`. Required by `getLogin`. */
|
|
23
|
+
checkoutUrl?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface WakeClientOptions {
|
|
27
|
+
/** The fetch underneath, e.g. a fake in tests. Defaults to `globalThis.fetch`. */
|
|
28
|
+
fetch?: Parameters<typeof createInstrumentedFetch>[0]["fetch"];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Thrown on a non-2xx response or a GraphQL `errors` payload. Never carries bodies or tokens. */
|
|
32
|
+
export class WakeError extends Error {
|
|
33
|
+
constructor(
|
|
34
|
+
readonly operation: string,
|
|
35
|
+
readonly status: number,
|
|
36
|
+
/** How many GraphQL errors the response carried (0 for an HTTP failure). */
|
|
37
|
+
readonly graphqlErrors = 0,
|
|
38
|
+
) {
|
|
39
|
+
super(
|
|
40
|
+
graphqlErrors > 0
|
|
41
|
+
? `wake ${operation} returned ${graphqlErrors} GraphQL error(s)`
|
|
42
|
+
: `wake ${operation} failed with HTTP ${status}`,
|
|
43
|
+
);
|
|
44
|
+
this.name = "WakeError";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type WakeClient = ReturnType<typeof createWakeClient>;
|
|
49
|
+
|
|
50
|
+
export function createWakeClient(config: WakeClientConfig, options: WakeClientOptions = {}) {
|
|
51
|
+
const request = createInstrumentedFetch({ provider: "wake", fetch: options.fetch });
|
|
52
|
+
const endpoint = config.storefrontEndpoint || WAKE_STOREFRONT_ENDPOINT;
|
|
53
|
+
const checkoutUrl = config.checkoutUrl;
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
/**
|
|
57
|
+
* Run a Storefront GraphQL operation (see `@decocms/apps-wake/storefront`).
|
|
58
|
+
* The operation label is the document's operation name. `headers` adds
|
|
59
|
+
* per-call headers, such as `X-Forwarded-For` or a customer access token;
|
|
60
|
+
* they never override the token or the content type.
|
|
61
|
+
*/
|
|
62
|
+
async graphql<TData, TVariables = Record<string, unknown>>(
|
|
63
|
+
document: string | QueryDefinition,
|
|
64
|
+
variables?: TVariables,
|
|
65
|
+
init: { headers?: Record<string, string> } = {},
|
|
66
|
+
): Promise<TData> {
|
|
67
|
+
const query = typeof document === "string" ? document : buildQuery(document);
|
|
68
|
+
const operation = extractGraphqlOperationName(query) ?? "graphql";
|
|
69
|
+
const headers = new Headers(init.headers);
|
|
70
|
+
headers.set("content-type", "application/json");
|
|
71
|
+
headers.set("tcs-access-token", config.storefrontToken);
|
|
72
|
+
const response = await request(endpoint, {
|
|
73
|
+
operation,
|
|
74
|
+
method: "POST",
|
|
75
|
+
headers,
|
|
76
|
+
body: JSON.stringify({ query, variables }),
|
|
77
|
+
});
|
|
78
|
+
if (!response.ok) throw new WakeError(operation, response.status);
|
|
79
|
+
const body = (await response.json()) as { data?: TData; errors?: unknown[] };
|
|
80
|
+
if (body.errors?.length) throw new WakeError(operation, response.status, body.errors.length);
|
|
81
|
+
if (body.data === undefined) throw new WakeError(operation, response.status);
|
|
82
|
+
return body.data;
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* `GET /api/Login/Get` on the checkout: exchanges the shopper's checkout
|
|
87
|
+
* cookies (the `fbits-login` cookie) for their account, or `null` when
|
|
88
|
+
* they aren't signed in (401, 403 or 404). Any other failure, such as
|
|
89
|
+
* a 429, throws a `WakeError`.
|
|
90
|
+
*/
|
|
91
|
+
async getLogin(cookie: string): Promise<UserAuthenticate | null> {
|
|
92
|
+
if (!checkoutUrl) throw new Error("wake getLogin: set checkoutUrl");
|
|
93
|
+
const response = await request(new URL("/api/Login/Get", checkoutUrl), {
|
|
94
|
+
operation: "getLogin",
|
|
95
|
+
headers: { cookie },
|
|
96
|
+
});
|
|
97
|
+
if (response.status === 401 || response.status === 403 || response.status === 404) {
|
|
98
|
+
return null; // not signed in
|
|
99
|
+
}
|
|
100
|
+
if (!response.ok) throw new WakeError("getLogin", response.status);
|
|
101
|
+
return (await response.json()) as UserAuthenticate | null;
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { getWakeClient } from "../../client";
|
|
2
|
-
import { getCartCookie, setCartCookie } from "../../utils/cart";
|
|
3
|
-
import { AddCoupon } from "../../utils/graphql/queries";
|
|
4
|
-
import type {
|
|
5
|
-
AddCouponMutation,
|
|
6
|
-
CheckoutFragment,
|
|
7
|
-
} from "../../utils/graphql/storefront.graphql.gen";
|
|
8
|
-
import { HttpError } from "../../utils/httpError";
|
|
9
|
-
import {
|
|
10
|
-
currentRequestHeaders,
|
|
11
|
-
currentResponseHeaders,
|
|
12
|
-
forwardedHeaders,
|
|
13
|
-
} from "../../utils/requestCtx";
|
|
14
|
-
|
|
15
|
-
export interface Props {
|
|
16
|
-
coupon: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const action = async (props: Props): Promise<Partial<CheckoutFragment>> => {
|
|
20
|
-
const storefront = getWakeClient();
|
|
21
|
-
const cartId = getCartCookie(currentRequestHeaders());
|
|
22
|
-
const headers = forwardedHeaders();
|
|
23
|
-
|
|
24
|
-
if (!cartId) {
|
|
25
|
-
throw new HttpError(400, "Missing cart cookie");
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const data = await storefront.query<AddCouponMutation>(
|
|
29
|
-
AddCoupon,
|
|
30
|
-
{ checkoutId: cartId, ...props },
|
|
31
|
-
headers,
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
const checkoutId = data.checkout?.checkoutId;
|
|
35
|
-
|
|
36
|
-
if (checkoutId && cartId !== checkoutId) {
|
|
37
|
-
setCartCookie(currentResponseHeaders(), checkoutId);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return data.checkout ?? {};
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export default action;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { CheckoutFragment } from "../../utils/graphql/storefront.graphql.gen";
|
|
2
|
-
import addItems, { type CartItem as Props } from "./addItems";
|
|
3
|
-
|
|
4
|
-
export type { CartItem as Props } from "./addItems";
|
|
5
|
-
|
|
6
|
-
const action = async (props: Props): Promise<Partial<CheckoutFragment>> => {
|
|
7
|
-
return await addItems({ products: [props] });
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export default action;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { getWakeClient } from "../../client";
|
|
2
|
-
import { getCartCookie, setCartCookie } from "../../utils/cart";
|
|
3
|
-
import { AddItemToCart } from "../../utils/graphql/queries";
|
|
4
|
-
import type {
|
|
5
|
-
AddItemToCartMutation,
|
|
6
|
-
CheckoutFragment,
|
|
7
|
-
} from "../../utils/graphql/storefront.graphql.gen";
|
|
8
|
-
import { HttpError } from "../../utils/httpError";
|
|
9
|
-
import {
|
|
10
|
-
currentRequestHeaders,
|
|
11
|
-
currentResponseHeaders,
|
|
12
|
-
forwardedHeaders,
|
|
13
|
-
} from "../../utils/requestCtx";
|
|
14
|
-
|
|
15
|
-
export interface CartItem {
|
|
16
|
-
productVariantId: number;
|
|
17
|
-
quantity: number;
|
|
18
|
-
customization?: { customizationId: number; value: string }[];
|
|
19
|
-
subscription?: { subscriptionGroupId: number; recurringTypeId: number };
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface Props {
|
|
23
|
-
products: CartItem[];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const action = async (props: Props): Promise<Partial<CheckoutFragment>> => {
|
|
27
|
-
const storefront = getWakeClient();
|
|
28
|
-
const cartId = getCartCookie(currentRequestHeaders());
|
|
29
|
-
const headers = forwardedHeaders();
|
|
30
|
-
|
|
31
|
-
if (!cartId) {
|
|
32
|
-
throw new HttpError(400, "Missing cart cookie");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const data = await storefront.query<AddItemToCartMutation>(
|
|
36
|
-
AddItemToCart,
|
|
37
|
-
{ input: { id: cartId, products: props.products } },
|
|
38
|
-
headers,
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
const checkoutId = data.checkout?.checkoutId;
|
|
42
|
-
|
|
43
|
-
if (checkoutId && cartId !== checkoutId) {
|
|
44
|
-
setCartCookie(currentResponseHeaders(), checkoutId);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return data.checkout ?? {};
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export default action;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { getWakeClient } from "../../client";
|
|
2
|
-
import { getCartCookie, setCartCookie } from "../../utils/cart";
|
|
3
|
-
import { AddKit } from "../../utils/graphql/queries";
|
|
4
|
-
import type { AddKitMutation, CheckoutFragment } from "../../utils/graphql/storefront.graphql.gen";
|
|
5
|
-
import { HttpError } from "../../utils/httpError";
|
|
6
|
-
import {
|
|
7
|
-
currentRequestHeaders,
|
|
8
|
-
currentResponseHeaders,
|
|
9
|
-
forwardedHeaders,
|
|
10
|
-
} from "../../utils/requestCtx";
|
|
11
|
-
|
|
12
|
-
export interface KitItemVariant {
|
|
13
|
-
productVariantId: number;
|
|
14
|
-
quantity: number;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface KitItem {
|
|
18
|
-
productId: number;
|
|
19
|
-
variants: KitItemVariant[];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface Props {
|
|
23
|
-
products: KitItem[];
|
|
24
|
-
quantity: number;
|
|
25
|
-
kitId: number;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const action = async (props: Props): Promise<Partial<CheckoutFragment>> => {
|
|
29
|
-
const storefront = getWakeClient();
|
|
30
|
-
const cartId = getCartCookie(currentRequestHeaders());
|
|
31
|
-
const headers = forwardedHeaders();
|
|
32
|
-
const { quantity, kitId, products } = props;
|
|
33
|
-
|
|
34
|
-
if (!cartId) {
|
|
35
|
-
throw new HttpError(400, "Missing cart cookie");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const data = await storefront.query<AddKitMutation>(
|
|
39
|
-
AddKit,
|
|
40
|
-
{ input: { id: cartId, quantity, kitId, products } },
|
|
41
|
-
headers,
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
const checkoutId = data.checkout?.checkoutId;
|
|
45
|
-
|
|
46
|
-
if (checkoutId && cartId !== checkoutId) {
|
|
47
|
-
setCartCookie(currentResponseHeaders(), checkoutId);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return data.checkout ?? {};
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export default action;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { getWakeClient } from "../../client";
|
|
2
|
-
import { getCartCookie, setCartCookie } from "../../utils/cart";
|
|
3
|
-
import { CheckoutPartnerAssociate } from "../../utils/graphql/queries";
|
|
4
|
-
import type {
|
|
5
|
-
CheckoutFragment,
|
|
6
|
-
CheckoutPartnerAssociateMutation,
|
|
7
|
-
} from "../../utils/graphql/storefront.graphql.gen";
|
|
8
|
-
import { HttpError } from "../../utils/httpError";
|
|
9
|
-
import { setPartnerCookie } from "../../utils/partner";
|
|
10
|
-
import {
|
|
11
|
-
currentRequestHeaders,
|
|
12
|
-
currentResponseHeaders,
|
|
13
|
-
forwardedHeaders,
|
|
14
|
-
} from "../../utils/requestCtx";
|
|
15
|
-
|
|
16
|
-
export interface Props {
|
|
17
|
-
partnerAccessToken: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const action = async (props: Props): Promise<Partial<CheckoutFragment>> => {
|
|
21
|
-
const storefront = getWakeClient();
|
|
22
|
-
const cartId = getCartCookie(currentRequestHeaders());
|
|
23
|
-
const headers = forwardedHeaders();
|
|
24
|
-
const { partnerAccessToken } = props;
|
|
25
|
-
|
|
26
|
-
if (!cartId) {
|
|
27
|
-
throw new HttpError(400, "Missing cart cookie");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const data = await storefront.query<CheckoutPartnerAssociateMutation>(
|
|
31
|
-
CheckoutPartnerAssociate,
|
|
32
|
-
{ checkoutId: cartId, partnerAccessToken },
|
|
33
|
-
headers,
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
const checkoutId = data.checkout?.checkoutId;
|
|
37
|
-
const responseHeaders = currentResponseHeaders();
|
|
38
|
-
|
|
39
|
-
if (checkoutId && cartId !== checkoutId) {
|
|
40
|
-
setCartCookie(responseHeaders, checkoutId);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
setPartnerCookie(responseHeaders, partnerAccessToken);
|
|
44
|
-
|
|
45
|
-
return data.checkout ?? {};
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export default action;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { getWakeClient } from "../../client";
|
|
2
|
-
import { getCartCookie, setCartCookie } from "../../utils/cart";
|
|
3
|
-
import { CheckoutPartnerDisassociate } from "../../utils/graphql/queries";
|
|
4
|
-
import type {
|
|
5
|
-
CheckoutFragment,
|
|
6
|
-
CheckoutPartnerDisassociateMutation,
|
|
7
|
-
} from "../../utils/graphql/storefront.graphql.gen";
|
|
8
|
-
import { HttpError } from "../../utils/httpError";
|
|
9
|
-
import { deletePartnerCookie } from "../../utils/partner";
|
|
10
|
-
import {
|
|
11
|
-
currentRequestHeaders,
|
|
12
|
-
currentResponseHeaders,
|
|
13
|
-
forwardedHeaders,
|
|
14
|
-
} from "../../utils/requestCtx";
|
|
15
|
-
|
|
16
|
-
const action = async (): Promise<Partial<CheckoutFragment>> => {
|
|
17
|
-
const storefront = getWakeClient();
|
|
18
|
-
const cartId = getCartCookie(currentRequestHeaders());
|
|
19
|
-
const headers = forwardedHeaders();
|
|
20
|
-
|
|
21
|
-
if (!cartId) {
|
|
22
|
-
throw new HttpError(400, "Missing cart cookie");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const data = await storefront.query<CheckoutPartnerDisassociateMutation>(
|
|
26
|
-
CheckoutPartnerDisassociate,
|
|
27
|
-
{ checkoutId: cartId },
|
|
28
|
-
headers,
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
const checkoutId = data.checkout?.checkoutId;
|
|
32
|
-
const responseHeaders = currentResponseHeaders();
|
|
33
|
-
|
|
34
|
-
if (checkoutId && cartId !== checkoutId) {
|
|
35
|
-
setCartCookie(responseHeaders, checkoutId);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
deletePartnerCookie(responseHeaders);
|
|
39
|
-
|
|
40
|
-
return data.checkout ?? {};
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export default action;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { getWakeClient } from "../../client";
|
|
2
|
-
import { getCartCookie, setCartCookie } from "../../utils/cart";
|
|
3
|
-
import { RemoveCoupon } from "../../utils/graphql/queries";
|
|
4
|
-
import type {
|
|
5
|
-
CheckoutFragment,
|
|
6
|
-
RemoveCouponMutation,
|
|
7
|
-
} from "../../utils/graphql/storefront.graphql.gen";
|
|
8
|
-
import { HttpError } from "../../utils/httpError";
|
|
9
|
-
import {
|
|
10
|
-
currentRequestHeaders,
|
|
11
|
-
currentResponseHeaders,
|
|
12
|
-
forwardedHeaders,
|
|
13
|
-
} from "../../utils/requestCtx";
|
|
14
|
-
|
|
15
|
-
const action = async (): Promise<Partial<CheckoutFragment>> => {
|
|
16
|
-
const storefront = getWakeClient();
|
|
17
|
-
const cartId = getCartCookie(currentRequestHeaders());
|
|
18
|
-
const headers = forwardedHeaders();
|
|
19
|
-
|
|
20
|
-
if (!cartId) {
|
|
21
|
-
throw new HttpError(400, "Missing cart cookie");
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const data = await storefront.query<RemoveCouponMutation>(
|
|
25
|
-
RemoveCoupon,
|
|
26
|
-
{ checkoutId: cartId },
|
|
27
|
-
headers,
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
const checkoutId = data.checkout?.checkoutId;
|
|
31
|
-
|
|
32
|
-
if (checkoutId && cartId !== checkoutId) {
|
|
33
|
-
setCartCookie(currentResponseHeaders(), checkoutId);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return data.checkout ?? {};
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export default action;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { getWakeClient } from "../../client";
|
|
2
|
-
import { getCartCookie, setCartCookie } from "../../utils/cart";
|
|
3
|
-
import { RemoveKit } from "../../utils/graphql/queries";
|
|
4
|
-
import type {
|
|
5
|
-
CheckoutFragment,
|
|
6
|
-
RemoveKitMutation,
|
|
7
|
-
} from "../../utils/graphql/storefront.graphql.gen";
|
|
8
|
-
import { HttpError } from "../../utils/httpError";
|
|
9
|
-
import {
|
|
10
|
-
currentRequestHeaders,
|
|
11
|
-
currentResponseHeaders,
|
|
12
|
-
forwardedHeaders,
|
|
13
|
-
} from "../../utils/requestCtx";
|
|
14
|
-
|
|
15
|
-
export interface KitItemVariant {
|
|
16
|
-
productVariantId: number;
|
|
17
|
-
quantity: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface KitItem {
|
|
21
|
-
productId: number;
|
|
22
|
-
variants: KitItemVariant[];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface Props {
|
|
26
|
-
products: KitItem[];
|
|
27
|
-
quantity: number;
|
|
28
|
-
kitId: number;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const action = async (props: Props): Promise<Partial<CheckoutFragment>> => {
|
|
32
|
-
const storefront = getWakeClient();
|
|
33
|
-
const cartId = getCartCookie(currentRequestHeaders());
|
|
34
|
-
const headers = forwardedHeaders();
|
|
35
|
-
const { quantity, kitId, products } = props;
|
|
36
|
-
|
|
37
|
-
if (!cartId) {
|
|
38
|
-
throw new HttpError(400, "Missing cart cookie");
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const data = await storefront.query<RemoveKitMutation>(
|
|
42
|
-
RemoveKit,
|
|
43
|
-
{ input: { id: cartId, quantity, kitId, products } },
|
|
44
|
-
headers,
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
const checkoutId = data.checkout?.checkoutId;
|
|
48
|
-
|
|
49
|
-
if (checkoutId && cartId !== checkoutId) {
|
|
50
|
-
setCartCookie(currentResponseHeaders(), checkoutId);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return data.checkout ?? {};
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export default action;
|