@decocms/apps-wake 7.66.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/package.json +58 -0
- package/src/actions/cart/addCoupon.ts +43 -0
- package/src/actions/cart/addItem.ts +10 -0
- package/src/actions/cart/addItems.ts +50 -0
- package/src/actions/cart/addKit.ts +53 -0
- package/src/actions/cart/partnerAssociate.ts +48 -0
- package/src/actions/cart/partnerDisassociate.ts +43 -0
- package/src/actions/cart/removeCoupon.ts +39 -0
- package/src/actions/cart/removeKit.ts +56 -0
- package/src/actions/cart/updateItemQuantity.ts +69 -0
- package/src/actions/newsletter/register.ts +32 -0
- package/src/actions/notifyme.ts +28 -0
- package/src/actions/review/create.ts +30 -0
- package/src/actions/shippingSimulation.ts +60 -0
- package/src/actions/submmitForm.ts +25 -0
- package/src/actions/wishlist/addProduct.ts +43 -0
- package/src/actions/wishlist/removeProduct.ts +45 -0
- package/src/client.ts +123 -0
- package/src/commerceLoaders.ts +137 -0
- package/src/handlers/sitemap.ts +61 -0
- package/src/index.ts +58 -0
- package/src/loaders/cart.ts +46 -0
- package/src/loaders/partners.ts +58 -0
- package/src/loaders/productDetailsPage.ts +174 -0
- package/src/loaders/productList.ts +262 -0
- package/src/loaders/productListingPage.ts +333 -0
- package/src/loaders/proxy.ts +79 -0
- package/src/loaders/recommendations.ts +84 -0
- package/src/loaders/shop.ts +37 -0
- package/src/loaders/suggestion.ts +67 -0
- package/src/loaders/user.ts +48 -0
- package/src/loaders/wishlist.ts +40 -0
- package/src/manifest.gen.ts +69 -0
- package/src/mod.ts +88 -0
- package/src/registry.ts +9 -0
- package/src/utils/authError.ts +107 -0
- package/src/utils/authenticate.ts +42 -0
- package/src/utils/capitalize.ts +9 -0
- package/src/utils/cart.ts +33 -0
- package/src/utils/client.ts +11 -0
- package/src/utils/cookies.ts +82 -0
- package/src/utils/getVariations.ts +47 -0
- package/src/utils/graphql/queries.ts +1363 -0
- package/src/utils/graphql/storefront.graphql.gen.ts +10233 -0
- package/src/utils/graphql.ts +88 -0
- package/src/utils/graphqlOperationName.ts +67 -0
- package/src/utils/httpError.ts +15 -0
- package/src/utils/instrumentedFetch.ts +46 -0
- package/src/utils/operationRouter.ts +51 -0
- package/src/utils/parseHeaders.ts +19 -0
- package/src/utils/partner.ts +34 -0
- package/src/utils/requestCtx.ts +41 -0
- package/src/utils/transform.ts +460 -0
- package/src/utils/types.ts +6 -0
- package/src/utils/user.ts +9 -0
- package/tsconfig.json +7 -0
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@decocms/apps-wake",
|
|
3
|
+
"version": "7.66.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Deco commerce app: Wake Commerce integration",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/decocms/blocks.git",
|
|
9
|
+
"directory": "packages/apps-wake"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"src",
|
|
13
|
+
"tsconfig.json"
|
|
14
|
+
],
|
|
15
|
+
"main": "./src/index.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./src/index.ts",
|
|
18
|
+
"./mod": "./src/mod.ts",
|
|
19
|
+
"./client": "./src/client.ts",
|
|
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"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc",
|
|
35
|
+
"test": "vitest run --root ../.. packages/apps-wake/",
|
|
36
|
+
"typecheck": "tsc --noEmit",
|
|
37
|
+
"lint:unused": "knip"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@decocms/blocks": "7.66.0",
|
|
41
|
+
"@decocms/apps-commerce": "7.66.0",
|
|
42
|
+
"@decocms/tanstack": "7.66.0"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"react": "^19.0.0",
|
|
46
|
+
"react-dom": "^19.0.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/react": "^19.0.0",
|
|
50
|
+
"@types/react-dom": "^19.0.0",
|
|
51
|
+
"knip": "^5.86.0",
|
|
52
|
+
"typescript": "^5.9.0"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"registry": "https://registry.npmjs.org",
|
|
56
|
+
"access": "public"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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;
|
|
@@ -0,0 +1,10 @@
|
|
|
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;
|
|
@@ -0,0 +1,50 @@
|
|
|
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;
|
|
@@ -0,0 +1,53 @@
|
|
|
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;
|
|
@@ -0,0 +1,48 @@
|
|
|
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;
|
|
@@ -0,0 +1,43 @@
|
|
|
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;
|
|
@@ -0,0 +1,39 @@
|
|
|
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;
|
|
@@ -0,0 +1,56 @@
|
|
|
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;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { getWakeClient } from "../../client";
|
|
2
|
+
import cartLoader from "../../loaders/cart";
|
|
3
|
+
import { getCartCookie, setCartCookie } from "../../utils/cart";
|
|
4
|
+
import { RemoveItemFromCart } from "../../utils/graphql/queries";
|
|
5
|
+
import type {
|
|
6
|
+
CheckoutFragment,
|
|
7
|
+
RemoveItemFromCartMutation,
|
|
8
|
+
} from "../../utils/graphql/storefront.graphql.gen";
|
|
9
|
+
import { HttpError } from "../../utils/httpError";
|
|
10
|
+
import {
|
|
11
|
+
currentRequestHeaders,
|
|
12
|
+
currentResponseHeaders,
|
|
13
|
+
forwardedHeaders,
|
|
14
|
+
} from "../../utils/requestCtx";
|
|
15
|
+
import addItem from "./addItem";
|
|
16
|
+
|
|
17
|
+
export interface Props {
|
|
18
|
+
productVariantId: number;
|
|
19
|
+
quantity: number;
|
|
20
|
+
customization?: { customizationId: number; value: string }[];
|
|
21
|
+
subscription?: { subscriptionGroupId: number; recurringTypeId: number };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const removeFromCart = (props: Props, cartId: string, headers: Record<string, string>) =>
|
|
25
|
+
getWakeClient().query<RemoveItemFromCartMutation>(
|
|
26
|
+
RemoveItemFromCart,
|
|
27
|
+
{ input: { id: cartId, products: [props] } },
|
|
28
|
+
headers,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const action = async (props: Props): Promise<Partial<CheckoutFragment>> => {
|
|
32
|
+
const cartId = getCartCookie(currentRequestHeaders());
|
|
33
|
+
const headers = forwardedHeaders();
|
|
34
|
+
|
|
35
|
+
if (!cartId) {
|
|
36
|
+
throw new HttpError(400, "Missing cart cookie");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/*
|
|
40
|
+
* get cart
|
|
41
|
+
* find the current product on cart
|
|
42
|
+
* the current amount
|
|
43
|
+
* calculate the difference between the current item amount and requested new amount
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
const cart = await cartLoader();
|
|
47
|
+
const item = cart.products?.find((item) => item?.productVariantId === props.productVariantId);
|
|
48
|
+
const quantityItem = item?.quantity ?? 0;
|
|
49
|
+
const quantity = props.quantity - quantityItem;
|
|
50
|
+
|
|
51
|
+
let checkout: Partial<CheckoutFragment> | undefined;
|
|
52
|
+
|
|
53
|
+
if (props.quantity > 0 && quantity > 0) {
|
|
54
|
+
checkout = await addItem({ ...props, quantity });
|
|
55
|
+
} else {
|
|
56
|
+
const data = await removeFromCart({ ...props, quantity: -quantity }, cartId, headers);
|
|
57
|
+
checkout = data.checkout ?? undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const checkoutId = checkout?.checkoutId;
|
|
61
|
+
|
|
62
|
+
if (checkoutId && cartId !== checkoutId) {
|
|
63
|
+
setCartCookie(currentResponseHeaders(), checkoutId);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return checkout ?? {};
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export default action;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { getWakeClient } from "../../client";
|
|
2
|
+
import { CreateNewsletterRegister } from "../../utils/graphql/queries";
|
|
3
|
+
import type {
|
|
4
|
+
CreateNewsletterRegisterMutation,
|
|
5
|
+
NewsletterNode,
|
|
6
|
+
} from "../../utils/graphql/storefront.graphql.gen";
|
|
7
|
+
import { HttpError } from "../../utils/httpError";
|
|
8
|
+
import { forwardedHeaders } from "../../utils/requestCtx";
|
|
9
|
+
|
|
10
|
+
export interface Props {
|
|
11
|
+
email: string;
|
|
12
|
+
name: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const action = async (props: Props): Promise<NewsletterNode> => {
|
|
16
|
+
const storefront = getWakeClient();
|
|
17
|
+
const headers = forwardedHeaders();
|
|
18
|
+
|
|
19
|
+
const data = await storefront.query<CreateNewsletterRegisterMutation>(
|
|
20
|
+
CreateNewsletterRegister,
|
|
21
|
+
{ input: { ...props } },
|
|
22
|
+
headers,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
if (!data.createNewsletterRegister) {
|
|
26
|
+
throw new HttpError(400, "Error on Register");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return data.createNewsletterRegister;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default action;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { getWakeClient } from "../client";
|
|
2
|
+
import { ProductRestockAlert } from "../utils/graphql/queries";
|
|
3
|
+
import type {
|
|
4
|
+
ProductRestockAlertMutation,
|
|
5
|
+
RestockAlertNode,
|
|
6
|
+
} from "../utils/graphql/storefront.graphql.gen";
|
|
7
|
+
import { forwardedHeaders } from "../utils/requestCtx";
|
|
8
|
+
|
|
9
|
+
export interface Props {
|
|
10
|
+
email: string;
|
|
11
|
+
name: string;
|
|
12
|
+
productVariantId: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const action = async (props: Props): Promise<RestockAlertNode | null> => {
|
|
16
|
+
const storefront = getWakeClient();
|
|
17
|
+
const headers = forwardedHeaders();
|
|
18
|
+
|
|
19
|
+
const data = await storefront.query<ProductRestockAlertMutation>(
|
|
20
|
+
ProductRestockAlert,
|
|
21
|
+
{ input: props },
|
|
22
|
+
headers,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
return data.productRestockAlert ?? null;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default action;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getWakeClient } from "../../client";
|
|
2
|
+
import { CreateProductReview } from "../../utils/graphql/queries";
|
|
3
|
+
import type {
|
|
4
|
+
CreateProductReviewMutation,
|
|
5
|
+
Review,
|
|
6
|
+
} from "../../utils/graphql/storefront.graphql.gen";
|
|
7
|
+
import { forwardedHeaders } from "../../utils/requestCtx";
|
|
8
|
+
|
|
9
|
+
export interface Props {
|
|
10
|
+
email: string;
|
|
11
|
+
name: string;
|
|
12
|
+
productVariantId: number;
|
|
13
|
+
rating: number;
|
|
14
|
+
review: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const action = async (props: Props): Promise<Review | null> => {
|
|
18
|
+
const storefront = getWakeClient();
|
|
19
|
+
const headers = forwardedHeaders();
|
|
20
|
+
|
|
21
|
+
const data = await storefront.query<CreateProductReviewMutation>(
|
|
22
|
+
CreateProductReview,
|
|
23
|
+
props as unknown as Record<string, unknown>,
|
|
24
|
+
headers,
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
return data.createProductReview ?? null;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default action;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { getWakeClient } from "../client";
|
|
2
|
+
import { getCartCookie } from "../utils/cart";
|
|
3
|
+
import { ShippingQuotes } from "../utils/graphql/queries";
|
|
4
|
+
import type {
|
|
5
|
+
ShippingQuotesQuery,
|
|
6
|
+
ShippingQuotesQueryVariables,
|
|
7
|
+
} from "../utils/graphql/storefront.graphql.gen";
|
|
8
|
+
import { HttpError } from "../utils/httpError";
|
|
9
|
+
import { currentRequestHeaders, forwardedHeaders } from "../utils/requestCtx";
|
|
10
|
+
|
|
11
|
+
export interface Props {
|
|
12
|
+
cep?: string;
|
|
13
|
+
simulateCartItems?: boolean;
|
|
14
|
+
productVariantId?: number;
|
|
15
|
+
quantity?: number;
|
|
16
|
+
useSelectedAddress?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const buildSimulationParams = (props: Props, checkoutId?: string): ShippingQuotesQueryVariables => {
|
|
20
|
+
const { cep, simulateCartItems, productVariantId, quantity, useSelectedAddress } = props;
|
|
21
|
+
|
|
22
|
+
const defaultQueryParams = {
|
|
23
|
+
cep,
|
|
24
|
+
useSelectedAddress,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
if (simulateCartItems) {
|
|
28
|
+
if (!checkoutId) throw new HttpError(400, "Missing cart cookie");
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
...defaultQueryParams,
|
|
32
|
+
checkoutId,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
...defaultQueryParams,
|
|
38
|
+
productVariantId,
|
|
39
|
+
quantity,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const action = async (props: Props): Promise<ShippingQuotesQuery["shippingQuotes"]> => {
|
|
44
|
+
const storefront = getWakeClient();
|
|
45
|
+
const headers = forwardedHeaders();
|
|
46
|
+
|
|
47
|
+
const cartId = getCartCookie(currentRequestHeaders());
|
|
48
|
+
|
|
49
|
+
const simulationParams = buildSimulationParams(props, cartId);
|
|
50
|
+
|
|
51
|
+
const data = await storefront.query<ShippingQuotesQuery>(
|
|
52
|
+
ShippingQuotes,
|
|
53
|
+
{ ...simulationParams },
|
|
54
|
+
headers,
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
return data.shippingQuotes ?? [];
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export default action;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getWakeClient } from "../client";
|
|
2
|
+
import { SendGenericForm } from "../utils/graphql/queries";
|
|
3
|
+
import type { SendGenericFormMutation } from "../utils/graphql/storefront.graphql.gen";
|
|
4
|
+
import { forwardedHeaders } from "../utils/requestCtx";
|
|
5
|
+
|
|
6
|
+
export interface Props {
|
|
7
|
+
body: unknown;
|
|
8
|
+
// file: Upload,
|
|
9
|
+
recaptchaToken: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const action = async (props: Props): Promise<SendGenericFormMutation["sendGenericForm"]> => {
|
|
13
|
+
const storefront = getWakeClient();
|
|
14
|
+
const headers = forwardedHeaders();
|
|
15
|
+
|
|
16
|
+
const data = await storefront.query<SendGenericFormMutation>(
|
|
17
|
+
SendGenericForm,
|
|
18
|
+
props as unknown as Record<string, unknown>,
|
|
19
|
+
headers,
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
return data.sendGenericForm!;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default action;
|