@decocms/apps 0.23.3 → 0.24.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/LICENSE +21 -0
- package/commerce/components/Image.tsx +129 -143
- package/commerce/components/JsonLd.tsx +192 -201
- package/commerce/components/Picture.tsx +65 -75
- package/commerce/sdk/analytics.ts +15 -15
- package/commerce/sdk/formatPrice.ts +13 -16
- package/commerce/sdk/url.ts +7 -7
- package/commerce/sdk/useOffer.ts +46 -57
- package/commerce/sdk/useVariantPossibilities.ts +25 -25
- package/commerce/types/commerce.ts +868 -875
- package/commerce/utils/canonical.ts +5 -8
- package/commerce/utils/constants.ts +5 -6
- package/commerce/utils/filters.ts +4 -4
- package/commerce/utils/productToAnalyticsItem.ts +52 -56
- package/commerce/utils/stateByZip.ts +42 -42
- package/package.json +23 -4
- package/shopify/actions/cart/addItems.ts +24 -25
- package/shopify/actions/cart/updateCoupons.ts +19 -20
- package/shopify/actions/cart/updateItems.ts +19 -20
- package/shopify/actions/user/signIn.ts +25 -30
- package/shopify/actions/user/signUp.ts +19 -24
- package/shopify/client.ts +24 -24
- package/shopify/index.ts +20 -18
- package/shopify/init.ts +18 -21
- package/shopify/loaders/ProductDetailsPage.ts +16 -20
- package/shopify/loaders/ProductList.ts +66 -69
- package/shopify/loaders/ProductListingPage.ts +150 -158
- package/shopify/loaders/RelatedProducts.ts +24 -27
- package/shopify/loaders/cart.ts +53 -52
- package/shopify/loaders/shop.ts +22 -27
- package/shopify/loaders/user.ts +27 -32
- package/shopify/utils/admin/admin.ts +33 -34
- package/shopify/utils/admin/queries.ts +2 -2
- package/shopify/utils/cart.ts +18 -14
- package/shopify/utils/cookies.ts +62 -65
- package/shopify/utils/enums.ts +424 -424
- package/shopify/utils/graphql.ts +44 -55
- package/shopify/utils/storefront/queries.ts +24 -29
- package/shopify/utils/storefront/storefront.graphql.gen.ts +55 -55
- package/shopify/utils/transform.ts +370 -376
- package/shopify/utils/types.ts +118 -118
- package/shopify/utils/user.ts +11 -11
- package/shopify/utils/utils.ts +135 -140
- package/vtex/actions/address.ts +86 -86
- package/vtex/actions/auth.ts +14 -27
- package/vtex/actions/checkout.ts +36 -49
- package/vtex/actions/masterData.ts +10 -27
- package/vtex/actions/misc.ts +101 -111
- package/vtex/actions/newsletter.ts +48 -52
- package/vtex/actions/orders.ts +13 -16
- package/vtex/actions/profile.ts +55 -55
- package/vtex/actions/session.ts +36 -35
- package/vtex/actions/trigger.ts +25 -25
- package/vtex/actions/wishlist.ts +51 -53
- package/vtex/client.ts +14 -42
- package/vtex/hooks/index.ts +4 -4
- package/vtex/hooks/useAutocomplete.ts +42 -48
- package/vtex/hooks/useCart.ts +153 -165
- package/vtex/hooks/useUser.ts +40 -40
- package/vtex/hooks/useWishlist.ts +70 -70
- package/vtex/inline-loaders/productDetailsPage.ts +1 -3
- package/vtex/inline-loaders/productList.ts +121 -127
- package/vtex/inline-loaders/productListingPage.ts +10 -34
- package/vtex/inline-loaders/relatedProducts.ts +1 -3
- package/vtex/inline-loaders/suggestions.ts +36 -39
- package/vtex/inline-loaders/workflowProducts.ts +45 -49
- package/vtex/invoke.ts +159 -194
- package/vtex/loaders/address.ts +49 -54
- package/vtex/loaders/brands.ts +19 -26
- package/vtex/loaders/cart.ts +24 -21
- package/vtex/loaders/catalog.ts +51 -53
- package/vtex/loaders/collections.ts +25 -27
- package/vtex/loaders/legacy.ts +487 -534
- package/vtex/loaders/logistics.ts +33 -37
- package/vtex/loaders/navbar.ts +5 -8
- package/vtex/loaders/orders.ts +28 -39
- package/vtex/loaders/pageType.ts +41 -35
- package/vtex/loaders/payment.ts +27 -37
- package/vtex/loaders/profile.ts +38 -38
- package/vtex/loaders/promotion.ts +5 -8
- package/vtex/loaders/search.ts +56 -59
- package/vtex/loaders/session.ts +22 -30
- package/vtex/loaders/user.ts +39 -41
- package/vtex/loaders/wishlist.ts +35 -35
- package/vtex/loaders/wishlistProducts.ts +3 -15
- package/vtex/loaders/workflow.ts +220 -227
- package/vtex/middleware.ts +116 -119
- package/vtex/types.ts +201 -201
- package/vtex/utils/batch.ts +13 -16
- package/vtex/utils/cookies.ts +76 -80
- package/vtex/utils/enrichment.ts +62 -42
- package/vtex/utils/fetchCache.ts +1 -4
- package/vtex/utils/index.ts +6 -6
- package/vtex/utils/intelligentSearch.ts +48 -57
- package/vtex/utils/legacy.ts +108 -124
- package/vtex/utils/pickAndOmit.ts +15 -20
- package/vtex/utils/proxy.ts +136 -146
- package/vtex/utils/resourceRange.ts +3 -3
- package/vtex/utils/segment.ts +100 -111
- package/vtex/utils/similars.ts +1 -2
- package/vtex/utils/sitemap.ts +91 -91
- package/vtex/utils/slugCache.ts +2 -6
- package/vtex/utils/slugify.ts +9 -9
- package/vtex/utils/transform.ts +1012 -1105
- package/vtex/utils/types.ts +1381 -1381
- package/vtex/utils/vtexId.ts +44 -47
- package/.github/workflows/release.yml +0 -34
- package/.releaserc.json +0 -28
- package/knip.json +0 -19
- package/tsconfig.json +0 -11
package/shopify/utils/graphql.ts
CHANGED
|
@@ -1,69 +1,58 @@
|
|
|
1
|
-
export function gql(
|
|
2
|
-
|
|
3
|
-
...values: unknown[]
|
|
4
|
-
): string {
|
|
5
|
-
return strings.reduce(
|
|
6
|
-
(acc, str, i) => acc + str + (values[i] ?? ""),
|
|
7
|
-
""
|
|
8
|
-
);
|
|
1
|
+
export function gql(strings: TemplateStringsArray, ...values: unknown[]): string {
|
|
2
|
+
return strings.reduce((acc, str, i) => acc + str + (values[i] ?? ""), "");
|
|
9
3
|
}
|
|
10
4
|
|
|
11
5
|
export interface QueryDefinition {
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
fragments?: string[];
|
|
7
|
+
query: string;
|
|
14
8
|
}
|
|
15
9
|
|
|
16
10
|
export function buildQuery(def: QueryDefinition): string {
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
const fragments = def.fragments?.join("\n") ?? "";
|
|
12
|
+
return fragments ? `${fragments}\n${def.query}` : def.query;
|
|
19
13
|
}
|
|
20
14
|
|
|
21
15
|
export interface GraphQLClient {
|
|
22
|
-
|
|
23
|
-
query: string | QueryDefinition,
|
|
24
|
-
variables?: Record<string, unknown>
|
|
25
|
-
): Promise<T>;
|
|
16
|
+
query<T>(query: string | QueryDefinition, variables?: Record<string, unknown>): Promise<T>;
|
|
26
17
|
}
|
|
27
18
|
|
|
28
19
|
export function createGraphqlClient(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
endpoint: string,
|
|
21
|
+
headers: Record<string, string>,
|
|
22
|
+
fetchFn?: typeof fetch,
|
|
32
23
|
): GraphQLClient {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
},
|
|
68
|
-
};
|
|
24
|
+
const _fetch = fetchFn ?? globalThis.fetch;
|
|
25
|
+
return {
|
|
26
|
+
async query<T>(
|
|
27
|
+
queryOrDef: string | QueryDefinition,
|
|
28
|
+
variables?: Record<string, unknown>,
|
|
29
|
+
): Promise<T> {
|
|
30
|
+
const query = typeof queryOrDef === "string" ? queryOrDef : buildQuery(queryOrDef);
|
|
31
|
+
|
|
32
|
+
const response = await _fetch(endpoint, {
|
|
33
|
+
method: "POST",
|
|
34
|
+
headers: {
|
|
35
|
+
"Content-Type": "application/json",
|
|
36
|
+
...headers,
|
|
37
|
+
},
|
|
38
|
+
body: JSON.stringify({ query, variables }),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
throw new Error(`Shopify GraphQL error: ${response.status} ${response.statusText}`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const json = (await response.json()) as { data?: T; errors?: Array<{ message: string }> };
|
|
46
|
+
|
|
47
|
+
if (json.errors?.length) {
|
|
48
|
+
throw new Error(`Shopify GraphQL errors: ${json.errors.map((e) => e.message).join(", ")}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (json.data === undefined) {
|
|
52
|
+
throw new Error("Shopify GraphQL response missing data");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return json.data;
|
|
56
|
+
},
|
|
57
|
+
};
|
|
69
58
|
}
|
|
@@ -266,7 +266,7 @@ const Customer = gql`
|
|
|
266
266
|
`;
|
|
267
267
|
|
|
268
268
|
export const CreateCart = {
|
|
269
|
-
|
|
269
|
+
query: gql`mutation CreateCart {
|
|
270
270
|
payload: cartCreate {
|
|
271
271
|
cart { id }
|
|
272
272
|
}
|
|
@@ -274,22 +274,20 @@ export const CreateCart = {
|
|
|
274
274
|
};
|
|
275
275
|
|
|
276
276
|
export const GetCart = {
|
|
277
|
-
|
|
278
|
-
|
|
277
|
+
fragments: [Cart],
|
|
278
|
+
query: gql`query GetCart($id: ID!) { cart(id: $id) { ...Cart } }`,
|
|
279
279
|
};
|
|
280
280
|
|
|
281
281
|
export const GetProduct = {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
gql`query GetProduct($handle: String, $identifiers: [HasMetafieldsIdentifier!]!) {
|
|
282
|
+
fragments: [Product, ProductVariant, Collection],
|
|
283
|
+
query: gql`query GetProduct($handle: String, $identifiers: [HasMetafieldsIdentifier!]!) {
|
|
285
284
|
product(handle: $handle) { ...Product }
|
|
286
285
|
}`,
|
|
287
286
|
};
|
|
288
287
|
|
|
289
288
|
export const ListProducts = {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
gql`query ListProducts($first: Int, $after: String, $query: String, $identifiers: [HasMetafieldsIdentifier!]!) {
|
|
289
|
+
fragments: [Product, ProductVariant, Collection],
|
|
290
|
+
query: gql`query ListProducts($first: Int, $after: String, $query: String, $identifiers: [HasMetafieldsIdentifier!]!) {
|
|
293
291
|
products(first: $first, after: $after, query: $query) {
|
|
294
292
|
nodes {
|
|
295
293
|
...Product
|
|
@@ -299,8 +297,8 @@ export const ListProducts = {
|
|
|
299
297
|
};
|
|
300
298
|
|
|
301
299
|
export const SearchProducts = {
|
|
302
|
-
|
|
303
|
-
|
|
300
|
+
fragments: [Product, ProductVariant, Filter, Collection],
|
|
301
|
+
query: gql`query searchWithFilters(
|
|
304
302
|
$first: Int,
|
|
305
303
|
$last: Int,
|
|
306
304
|
$after: String,
|
|
@@ -340,8 +338,8 @@ export const SearchProducts = {
|
|
|
340
338
|
};
|
|
341
339
|
|
|
342
340
|
export const ProductsByCollection = {
|
|
343
|
-
|
|
344
|
-
|
|
341
|
+
fragments: [Product, ProductVariant, Collection, Filter],
|
|
342
|
+
query: gql`query AllProducts(
|
|
345
343
|
$first: Int,
|
|
346
344
|
$last: Int,
|
|
347
345
|
$after: String,
|
|
@@ -383,9 +381,8 @@ export const ProductsByCollection = {
|
|
|
383
381
|
};
|
|
384
382
|
|
|
385
383
|
export const ProductRecommendations = {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
gql`query productRecommendations($productId: ID!, $identifiers: [HasMetafieldsIdentifier!]!) {
|
|
384
|
+
fragments: [Product, ProductVariant, Collection],
|
|
385
|
+
query: gql`query productRecommendations($productId: ID!, $identifiers: [HasMetafieldsIdentifier!]!) {
|
|
389
386
|
productRecommendations(productId: $productId) {
|
|
390
387
|
...Product
|
|
391
388
|
}
|
|
@@ -393,7 +390,7 @@ export const ProductRecommendations = {
|
|
|
393
390
|
};
|
|
394
391
|
|
|
395
392
|
export const GetShopInfo = {
|
|
396
|
-
|
|
393
|
+
query: gql`query GetShopInfo($identifiers: [HasMetafieldsIdentifier!]!) {
|
|
397
394
|
shop {
|
|
398
395
|
name
|
|
399
396
|
description
|
|
@@ -447,8 +444,8 @@ export const GetShopInfo = {
|
|
|
447
444
|
};
|
|
448
445
|
|
|
449
446
|
export const FetchCustomerInfo = {
|
|
450
|
-
|
|
451
|
-
|
|
447
|
+
fragments: [Customer],
|
|
448
|
+
query: gql`query FetchCustomerInfo($customerAccessToken: String!) {
|
|
452
449
|
customer(customerAccessToken: $customerAccessToken) {
|
|
453
450
|
...Customer
|
|
454
451
|
}
|
|
@@ -456,8 +453,8 @@ export const FetchCustomerInfo = {
|
|
|
456
453
|
};
|
|
457
454
|
|
|
458
455
|
export const AddItemToCart = {
|
|
459
|
-
|
|
460
|
-
|
|
456
|
+
fragments: [Cart],
|
|
457
|
+
query: gql`mutation AddItemToCart($cartId: ID!, $lines: [CartLineInput!]!) {
|
|
461
458
|
payload: cartLinesAdd(cartId: $cartId, lines: $lines) {
|
|
462
459
|
cart { ...Cart }
|
|
463
460
|
}
|
|
@@ -465,7 +462,7 @@ export const AddItemToCart = {
|
|
|
465
462
|
};
|
|
466
463
|
|
|
467
464
|
export const RegisterAccount = {
|
|
468
|
-
|
|
465
|
+
query: gql`mutation RegisterAccount(
|
|
469
466
|
$email: String!,
|
|
470
467
|
$password: String!,
|
|
471
468
|
$firstName: String,
|
|
@@ -491,8 +488,8 @@ export const RegisterAccount = {
|
|
|
491
488
|
};
|
|
492
489
|
|
|
493
490
|
export const AddCoupon = {
|
|
494
|
-
|
|
495
|
-
|
|
491
|
+
fragments: [Cart],
|
|
492
|
+
query: gql`mutation AddCoupon($cartId: ID!, $discountCodes: [String!]!) {
|
|
496
493
|
payload: cartDiscountCodesUpdate(cartId: $cartId, discountCodes: $discountCodes) {
|
|
497
494
|
cart { ...Cart }
|
|
498
495
|
userErrors {
|
|
@@ -504,9 +501,8 @@ export const AddCoupon = {
|
|
|
504
501
|
};
|
|
505
502
|
|
|
506
503
|
export const UpdateItems = {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
gql`mutation UpdateItems($cartId: ID!, $lines: [CartLineUpdateInput!]!) {
|
|
504
|
+
fragments: [Cart],
|
|
505
|
+
query: gql`mutation UpdateItems($cartId: ID!, $lines: [CartLineUpdateInput!]!) {
|
|
510
506
|
payload: cartLinesUpdate(cartId: $cartId, lines: $lines) {
|
|
511
507
|
cart { ...Cart }
|
|
512
508
|
}
|
|
@@ -514,8 +510,7 @@ export const UpdateItems = {
|
|
|
514
510
|
};
|
|
515
511
|
|
|
516
512
|
export const SignInWithEmailAndPassword = {
|
|
517
|
-
|
|
518
|
-
gql`mutation SignInWithEmailAndPassword($email: String!, $password: String!) {
|
|
513
|
+
query: gql`mutation SignInWithEmailAndPassword($email: String!, $password: String!) {
|
|
519
514
|
customerAccessTokenCreate(input: { email: $email, password: $password }) {
|
|
520
515
|
customerAccessToken {
|
|
521
516
|
accessToken
|
|
@@ -6,33 +6,33 @@
|
|
|
6
6
|
|
|
7
7
|
// Cart types
|
|
8
8
|
export type CartFragment = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
9
|
+
id: string;
|
|
10
|
+
checkoutUrl: string;
|
|
11
|
+
totalQuantity: number;
|
|
12
|
+
lines: {
|
|
13
|
+
nodes: Array<{
|
|
14
|
+
id: string;
|
|
15
|
+
quantity: number;
|
|
16
|
+
merchandise: {
|
|
17
|
+
__typename?: string;
|
|
18
|
+
id: string;
|
|
19
|
+
title: string;
|
|
20
|
+
image?: { url: string; altText?: string | null } | null;
|
|
21
|
+
product: { title: string; handle: string; onlineStoreUrl?: string | null };
|
|
22
|
+
price: { amount: string; currencyCode: string };
|
|
23
|
+
compareAtPrice?: { amount: string; currencyCode: string } | null;
|
|
24
|
+
};
|
|
25
|
+
discountAllocations?: Array<{
|
|
26
|
+
__typename?: string;
|
|
27
|
+
code?: string;
|
|
28
|
+
}>;
|
|
29
|
+
}>;
|
|
30
|
+
};
|
|
31
|
+
cost: {
|
|
32
|
+
totalAmount: { amount: string; currencyCode: string };
|
|
33
|
+
subtotalAmount: { amount: string; currencyCode: string };
|
|
34
|
+
};
|
|
35
|
+
discountCodes?: Array<{ applicable: boolean; code: string }>;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
// Mutation types
|
|
@@ -59,53 +59,53 @@ export type ProductFilter = any;
|
|
|
59
59
|
|
|
60
60
|
// Customer types
|
|
61
61
|
export type Customer = {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
id: string;
|
|
63
|
+
firstName?: string | null;
|
|
64
|
+
lastName?: string | null;
|
|
65
|
+
email?: string | null;
|
|
66
|
+
phone?: string | null;
|
|
67
|
+
acceptsMarketing?: boolean;
|
|
68
|
+
defaultAddress?: any;
|
|
69
|
+
addresses?: { nodes: any[] };
|
|
70
|
+
orders?: { nodes: any[] };
|
|
71
71
|
};
|
|
72
72
|
|
|
73
73
|
export type CustomerAccessTokenCreateInput = {
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
email: string;
|
|
75
|
+
password: string;
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
export type CustomerAccessTokenCreateWithMultipassPayload = {
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
customerAccessToken?: { accessToken: string; expiresAt: string } | null;
|
|
80
|
+
customerUserErrors?: Array<{ message: string; code?: string }>;
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
export type CustomerCreateInput = {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
email: string;
|
|
85
|
+
password: string;
|
|
86
|
+
firstName?: string;
|
|
87
|
+
lastName?: string;
|
|
88
|
+
acceptsMarketing?: boolean;
|
|
89
89
|
};
|
|
90
90
|
|
|
91
91
|
export type CustomerCreatePayload = {
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
customer?: Customer | null;
|
|
93
|
+
customerUserErrors?: Array<{ message: string; code?: string }>;
|
|
94
94
|
};
|
|
95
95
|
|
|
96
96
|
// Shop types
|
|
97
97
|
export type Shop = {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
98
|
+
name: string;
|
|
99
|
+
description?: string;
|
|
100
|
+
shipsToCountries?: string[];
|
|
101
|
+
refundPolicy?: { body: string; title: string; url: string };
|
|
102
|
+
privacyPolicy?: { body: string; title: string; url: string };
|
|
103
|
+
termsOfService?: { body: string; title: string; url: string };
|
|
104
|
+
metafields?: Array<{ key: string; value: string; namespace: string } | null>;
|
|
105
105
|
};
|
|
106
106
|
|
|
107
107
|
export type ShopMetafieldsArgs = {
|
|
108
|
-
|
|
108
|
+
identifiers: Array<{ namespace: string; key: string }>;
|
|
109
109
|
};
|
|
110
110
|
|
|
111
111
|
// Order/Admin types
|