@decocms/apps-wake 8.1.0-next.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.
Files changed (54) hide show
  1. package/package.json +7 -30
  2. package/src/index.ts +1 -61
  3. package/src/utils/gql.ts +1 -2
  4. package/src/__tests__/wakeClient.test.ts +0 -136
  5. package/src/actions/cart/addCoupon.ts +0 -43
  6. package/src/actions/cart/addItem.ts +0 -10
  7. package/src/actions/cart/addItems.ts +0 -50
  8. package/src/actions/cart/addKit.ts +0 -53
  9. package/src/actions/cart/partnerAssociate.ts +0 -48
  10. package/src/actions/cart/partnerDisassociate.ts +0 -43
  11. package/src/actions/cart/removeCoupon.ts +0 -39
  12. package/src/actions/cart/removeKit.ts +0 -56
  13. package/src/actions/cart/updateItemQuantity.ts +0 -69
  14. package/src/actions/newsletter/register.ts +0 -32
  15. package/src/actions/notifyme.ts +0 -28
  16. package/src/actions/review/create.ts +0 -30
  17. package/src/actions/shippingSimulation.ts +0 -60
  18. package/src/actions/submmitForm.ts +0 -25
  19. package/src/actions/wishlist/addProduct.ts +0 -43
  20. package/src/actions/wishlist/removeProduct.ts +0 -45
  21. package/src/client.ts +0 -123
  22. package/src/commerceLoaders.ts +0 -137
  23. package/src/handlers/sitemap.ts +0 -61
  24. package/src/loaders/cart.ts +0 -46
  25. package/src/loaders/partners.ts +0 -58
  26. package/src/loaders/productDetailsPage.ts +0 -174
  27. package/src/loaders/productList.ts +0 -262
  28. package/src/loaders/productListingPage.ts +0 -333
  29. package/src/loaders/proxy.ts +0 -79
  30. package/src/loaders/recommendations.ts +0 -84
  31. package/src/loaders/shop.ts +0 -37
  32. package/src/loaders/suggestion.ts +0 -67
  33. package/src/loaders/user.ts +0 -48
  34. package/src/loaders/wishlist.ts +0 -40
  35. package/src/manifest.gen.ts +0 -69
  36. package/src/mod.ts +0 -88
  37. package/src/registry.ts +0 -9
  38. package/src/utils/authError.ts +0 -107
  39. package/src/utils/authenticate.ts +0 -42
  40. package/src/utils/capitalize.ts +0 -9
  41. package/src/utils/cart.ts +0 -33
  42. package/src/utils/cookies.ts +0 -82
  43. package/src/utils/getVariations.ts +0 -47
  44. package/src/utils/graphql.ts +0 -72
  45. package/src/utils/httpError.ts +0 -15
  46. package/src/utils/instrumentedFetch.ts +0 -46
  47. package/src/utils/operationRouter.ts +0 -51
  48. package/src/utils/parseHeaders.ts +0 -19
  49. package/src/utils/partner.ts +0 -34
  50. package/src/utils/requestCtx.ts +0 -41
  51. package/src/utils/transform.ts +0 -460
  52. package/src/utils/types.ts +0 -6
  53. package/src/utils/user.ts +0 -9
  54. package/tsconfig.json +0 -7
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@decocms/apps-wake",
3
- "version": "8.1.0-next.0",
3
+ "version": "8.1.0-next.1",
4
4
  "type": "module",
5
- "description": "Deco commerce app: Wake Commerce integration",
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,47 +10,24 @@
10
10
  },
11
11
  "files": [
12
12
  "src",
13
- "tsconfig.json"
13
+ "!src/**/*.test.ts",
14
+ "!src/**/__tests__"
14
15
  ],
15
16
  "main": "./src/index.ts",
16
17
  "exports": {
17
18
  ".": "./src/index.ts",
18
- "./mod": "./src/mod.ts",
19
- "./client": "./src/client.ts",
20
19
  "./storefront": "./src/storefront.ts",
21
- "./storefront/types": "./src/storefrontTypes.ts",
22
- "./commerceLoaders": "./src/commerceLoaders.ts",
23
- "./loaders/*": "./src/loaders/*.ts",
24
- "./actions/*": "./src/actions/*.ts",
25
- "./actions/cart/*": "./src/actions/cart/*.ts",
26
- "./actions/newsletter/*": "./src/actions/newsletter/*.ts",
27
- "./actions/review/*": "./src/actions/review/*.ts",
28
- "./actions/wishlist/*": "./src/actions/wishlist/*.ts",
29
- "./handlers/*": "./src/handlers/*.ts",
30
- "./hooks": "./src/hooks/index.ts",
31
- "./hooks/*": "./src/hooks/*.ts",
32
- "./utils/*": "./src/utils/*.ts",
33
- "./registry": "./src/registry.ts"
20
+ "./storefront/types": "./src/storefrontTypes.ts"
34
21
  },
35
22
  "scripts": {
36
23
  "build": "tsc",
37
24
  "test": "vitest run --root ../.. packages/apps-wake/",
38
- "typecheck": "tsc --noEmit",
39
- "lint:unused": "knip"
25
+ "typecheck": "tsc --noEmit"
40
26
  },
41
27
  "dependencies": {
42
- "@decocms/blocks": "8.1.0-next.0",
43
- "@decocms/apps-commerce": "8.1.0-next.0",
44
- "@decocms/tanstack": "8.1.0-next.0"
45
- },
46
- "peerDependencies": {
47
- "react": "^19.0.0",
48
- "react-dom": "^19.0.0"
28
+ "@decocms/blocks": "8.1.0-next.1"
49
29
  },
50
30
  "devDependencies": {
51
- "@types/react": "^19.0.0",
52
- "@types/react-dom": "^19.0.0",
53
- "knip": "^5.86.0",
54
31
  "typescript": "^5.9.0"
55
32
  },
56
33
  "publishConfig": {
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- // v8: the thin Wake client (see /next/upstream-clients). Operations are in
1
+ // The thin Wake client (see /next/upstream-clients). Operations are in
2
2
  // `@decocms/apps-wake/storefront`, their types in `.../storefront/types`.
3
3
 
4
4
  export type { UserAuthenticate } from "./utils/client";
@@ -9,63 +9,3 @@ export {
9
9
  type WakeClientOptions,
10
10
  WakeError,
11
11
  } from "./wakeClient";
12
-
13
- // v7 (kept for v7 consumers until the v7 modules are dropped)
14
- // App contract
15
-
16
- // Cart actions
17
- export { default as addItem } from "./actions/cart/addItem";
18
- export { type CartItem, default as addItems } from "./actions/cart/addItems";
19
- export { default as updateItemQuantity } from "./actions/cart/updateItemQuantity";
20
- // Client & Config
21
- export type { WakeConfig } from "./client";
22
- export {
23
- configureWake,
24
- getBaseUrl,
25
- getCheckoutUrl,
26
- getWakeClient,
27
- getWakeConfig,
28
- initWakeFromBlocks,
29
- setWakeFetch,
30
- } from "./client";
31
- // Commerce loaders factory (cached, CMS-registerable map)
32
- export {
33
- type CommerceLoaderFn,
34
- createWakeCommerceLoaders,
35
- type WakeCommerceLoadersOptions,
36
- } from "./commerceLoaders";
37
- // Cart / user / wishlist
38
- export { default as cartLoader } from "./loaders/cart";
39
- // Shop / partners
40
- export { default as partnersLoader } from "./loaders/partners";
41
- // Product loaders
42
- export { default as productDetailsPageLoader } from "./loaders/productDetailsPage";
43
- export { default as productListLoader } from "./loaders/productList";
44
- export { default as productListingPageLoader } from "./loaders/productListingPage";
45
- export type { WakeProxyRoute } from "./loaders/proxy";
46
- export { default as proxyLoader } from "./loaders/proxy";
47
- export { default as recommendationsLoader } from "./loaders/recommendations";
48
- export { default as shopLoader } from "./loaders/shop";
49
- export { default as suggestionLoader } from "./loaders/suggestion";
50
- export { default as userLoader } from "./loaders/user";
51
- export { default as wishlistLoader } from "./loaders/wishlist";
52
- export { configure, type Props, type WakeState } from "./mod";
53
- // Registry
54
- export { WAKE_REGISTRY_ENTRY } from "./registry";
55
-
56
- // Cookie utils
57
- export { getCartCookie, setCartCookie, setClientCookie } from "./utils/cart";
58
- export { getCookies, setCookie } from "./utils/cookies";
59
- // GraphQL client + fetch instrumentation
60
- export { extractGraphqlOperationName } from "./utils/graphqlOperationName";
61
- export { type CreateWakeFetchOptions, createWakeFetch } from "./utils/instrumentedFetch";
62
- export { wakeOperationRouter } from "./utils/operationRouter";
63
- export { getPartnerCookie } from "./utils/partner";
64
- // Transform helpers
65
- export {
66
- parseSlug,
67
- toBreadcrumbList,
68
- toFilters,
69
- toProduct,
70
- } from "./utils/transform";
71
- export { getUserCookie } from "./utils/user";
package/src/utils/gql.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  /**
2
- * GraphQL document helpers shared by the v8 client (`../wakeClient.ts`) and
3
- * the v7 GraphQL client (`./graphql.ts`). Pure: no I/O, no framework imports.
2
+ * GraphQL document helpers used by the client (`../wakeClient.ts`). Pure: no I/O, no framework imports.
4
3
  */
5
4
 
6
5
  /**
@@ -1,136 +0,0 @@
1
- // @vitest-environment node
2
- /**
3
- * The v8 Wake client (/next/upstream-clients): every request goes through the
4
- * instrumented fetch as provider "wake", named by its operation, and errors
5
- * never carry bodies or tokens.
6
- */
7
- import { beforeEach, describe, expect, it, vi } from "vitest";
8
-
9
- const instrumented = vi.hoisted(() => ({
10
- providers: [] as string[],
11
- operations: [] as (string | undefined)[],
12
- }));
13
-
14
- vi.mock("@decocms/blocks/fetch", async (importOriginal) => {
15
- const real = await importOriginal<typeof import("@decocms/blocks/fetch")>();
16
- return {
17
- createInstrumentedFetch: (options: Parameters<typeof real.createInstrumentedFetch>[0]) => {
18
- instrumented.providers.push(options.provider);
19
- const request = real.createInstrumentedFetch(options);
20
- return (input: string | URL | Request, init?: RequestInit & { operation?: string }) => {
21
- instrumented.operations.push(init?.operation);
22
- return request(input, init);
23
- };
24
- },
25
- };
26
- });
27
-
28
- import { GetProduct } from "../storefront";
29
- import { createWakeClient, WakeError } from "../wakeClient";
30
-
31
- /** The error a call rejects with (fails the test if it resolves). */
32
- const failure = (call: Promise<unknown>): Promise<Error> =>
33
- call.then(
34
- () => {
35
- throw new Error("expected the call to fail");
36
- },
37
- (error: Error) => error,
38
- );
39
-
40
- function upstream(body: unknown, status = 200) {
41
- return vi.fn(
42
- async (_input: string | URL | Request, _init?: RequestInit) =>
43
- new Response(JSON.stringify(body), { status }),
44
- );
45
- }
46
-
47
- beforeEach(() => {
48
- instrumented.providers.length = 0;
49
- instrumented.operations.length = 0;
50
- });
51
-
52
- describe("createWakeClient", () => {
53
- it("runs a storefront operation through the instrumented fetch, labeled by its name", async () => {
54
- const fetch = upstream({ data: { product: { productId: 1 } } });
55
- const wake = createWakeClient({ storefrontToken: "tok" }, { fetch });
56
-
57
- const data = await wake.graphql<{ product: { productId: number } }>(
58
- GetProduct,
59
- { productId: 1 },
60
- {
61
- headers: {
62
- "x-forwarded-for": "203.0.113.7",
63
- "TCS-Access-Token": "spoofed",
64
- "Content-Type": "text/plain",
65
- },
66
- },
67
- );
68
-
69
- expect(data).toEqual({ product: { productId: 1 } });
70
- expect(instrumented.providers).toEqual(["wake"]);
71
- expect(instrumented.operations).toEqual(["GetProduct"]);
72
- const [url, init] = fetch.mock.calls[0]!;
73
- expect(String(url)).toBe("https://storefront-api.fbits.net/graphql");
74
- const headers = new Headers(init?.headers);
75
- // Per-call headers can't override the token or the content type, whatever their case.
76
- expect(headers.get("tcs-access-token")).toBe("tok");
77
- expect(headers.get("content-type")).toBe("application/json");
78
- expect(headers.get("x-forwarded-for")).toBe("203.0.113.7");
79
- const body = JSON.parse(String(init?.body));
80
- expect(body.variables).toEqual({ productId: 1 });
81
- expect(body.query).toContain("fragment"); // fragments are sent with the document
82
- });
83
-
84
- it("throws a WakeError without the body on HTTP and GraphQL failures", async () => {
85
- const failing = createWakeClient(
86
- { storefrontToken: "tok" },
87
- { fetch: upstream({ secret: "x" }, 502) },
88
- );
89
- const httpError = await failure(failing.graphql("query Shop { shop { name } }"));
90
- expect(httpError).toBeInstanceOf(WakeError);
91
- expect(httpError.message).toBe("wake Shop failed with HTTP 502");
92
-
93
- const erroring = createWakeClient(
94
- { storefrontToken: "tok" },
95
- { fetch: upstream({ errors: [{ message: "customer jane@example.com not found" }] }) },
96
- );
97
- const gqlError = await failure(erroring.graphql("query Shop { shop { name } }"));
98
- expect(gqlError.message).toBe("wake Shop returned 1 GraphQL error(s)");
99
- expect(gqlError.message).not.toContain("jane");
100
- expect(gqlError.message).not.toContain("tok");
101
- });
102
-
103
- it("reads the signed-in shopper from the checkout, or null when signed out", async () => {
104
- const fetch = upstream({ CustomerAccessToken: "cat", Email: "a@example.com" });
105
- const wake = createWakeClient(
106
- { storefrontToken: "tok", checkoutUrl: "https://checkout.example.com" },
107
- { fetch },
108
- );
109
- expect(await wake.getLogin("fbits-login=abc")).toMatchObject({ CustomerAccessToken: "cat" });
110
- const [url, init] = fetch.mock.calls[0]!;
111
- expect(String(url)).toBe("https://checkout.example.com/api/Login/Get");
112
- expect(new Headers(init?.headers).get("cookie")).toBe("fbits-login=abc");
113
- expect(instrumented.operations).toEqual(["getLogin"]);
114
-
115
- const signedOut = createWakeClient(
116
- { storefrontToken: "tok", checkoutUrl: "https://checkout.example.com" },
117
- { fetch: upstream({}, 401) },
118
- );
119
- expect(await signedOut.getLogin("")).toBeNull();
120
- });
121
-
122
- it("throws on a rate limit instead of reporting the shopper as signed out", async () => {
123
- const limited = createWakeClient(
124
- { storefrontToken: "tok", checkoutUrl: "https://checkout.example.com" },
125
- { fetch: upstream({}, 429) },
126
- );
127
- const error = await failure(limited.getLogin("fbits-login=abc"));
128
- expect(error).toBeInstanceOf(WakeError);
129
- expect(error.message).toBe("wake getLogin failed with HTTP 429");
130
- });
131
-
132
- it("requires checkoutUrl for getLogin", async () => {
133
- const wake = createWakeClient({ storefrontToken: "tok" }, { fetch: upstream({}) });
134
- await expect(wake.getLogin("")).rejects.toThrow(/set checkoutUrl/);
135
- });
136
- });
@@ -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;