@decocms/apps 0.23.3 → 0.25.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.
Files changed (111) hide show
  1. package/LICENSE +21 -0
  2. package/commerce/components/Image.tsx +129 -143
  3. package/commerce/components/JsonLd.tsx +192 -201
  4. package/commerce/components/Picture.tsx +65 -75
  5. package/commerce/sdk/analytics.ts +15 -15
  6. package/commerce/sdk/formatPrice.ts +13 -16
  7. package/commerce/sdk/url.ts +7 -7
  8. package/commerce/sdk/useOffer.ts +46 -57
  9. package/commerce/sdk/useVariantPossibilities.ts +25 -25
  10. package/commerce/types/commerce.ts +868 -875
  11. package/commerce/utils/canonical.ts +5 -8
  12. package/commerce/utils/constants.ts +5 -6
  13. package/commerce/utils/filters.ts +4 -4
  14. package/commerce/utils/productToAnalyticsItem.ts +52 -56
  15. package/commerce/utils/stateByZip.ts +42 -42
  16. package/package.json +24 -4
  17. package/shopify/actions/cart/addItems.ts +24 -25
  18. package/shopify/actions/cart/updateCoupons.ts +19 -20
  19. package/shopify/actions/cart/updateItems.ts +19 -20
  20. package/shopify/actions/user/signIn.ts +25 -30
  21. package/shopify/actions/user/signUp.ts +19 -24
  22. package/shopify/client.ts +24 -24
  23. package/shopify/index.ts +20 -18
  24. package/shopify/init.ts +18 -21
  25. package/shopify/loaders/ProductDetailsPage.ts +16 -20
  26. package/shopify/loaders/ProductList.ts +66 -69
  27. package/shopify/loaders/ProductListingPage.ts +150 -158
  28. package/shopify/loaders/RelatedProducts.ts +24 -27
  29. package/shopify/loaders/cart.ts +53 -52
  30. package/shopify/loaders/shop.ts +22 -27
  31. package/shopify/loaders/user.ts +27 -32
  32. package/shopify/utils/admin/admin.ts +33 -34
  33. package/shopify/utils/admin/queries.ts +2 -2
  34. package/shopify/utils/cart.ts +18 -14
  35. package/shopify/utils/cookies.ts +62 -65
  36. package/shopify/utils/enums.ts +424 -424
  37. package/shopify/utils/graphql.ts +44 -55
  38. package/shopify/utils/storefront/queries.ts +24 -29
  39. package/shopify/utils/storefront/storefront.graphql.gen.ts +55 -55
  40. package/shopify/utils/transform.ts +370 -376
  41. package/shopify/utils/types.ts +118 -118
  42. package/shopify/utils/user.ts +11 -11
  43. package/shopify/utils/utils.ts +135 -140
  44. package/vtex/actions/address.ts +86 -86
  45. package/vtex/actions/auth.ts +14 -27
  46. package/vtex/actions/checkout.ts +36 -49
  47. package/vtex/actions/masterData.ts +10 -27
  48. package/vtex/actions/misc.ts +101 -111
  49. package/vtex/actions/newsletter.ts +48 -52
  50. package/vtex/actions/orders.ts +13 -16
  51. package/vtex/actions/profile.ts +55 -55
  52. package/vtex/actions/session.ts +36 -35
  53. package/vtex/actions/trigger.ts +25 -25
  54. package/vtex/actions/wishlist.ts +51 -53
  55. package/vtex/client.ts +14 -42
  56. package/vtex/hooks/index.ts +4 -4
  57. package/vtex/hooks/useAutocomplete.ts +42 -48
  58. package/vtex/hooks/useCart.ts +153 -165
  59. package/vtex/hooks/useUser.ts +40 -40
  60. package/vtex/hooks/useWishlist.ts +70 -70
  61. package/vtex/inline-loaders/productDetailsPage.ts +1 -3
  62. package/vtex/inline-loaders/productList.ts +121 -127
  63. package/vtex/inline-loaders/productListShelf.ts +159 -0
  64. package/vtex/inline-loaders/productListingPage.ts +10 -34
  65. package/vtex/inline-loaders/relatedProducts.ts +1 -3
  66. package/vtex/inline-loaders/suggestions.ts +36 -39
  67. package/vtex/inline-loaders/workflowProducts.ts +45 -49
  68. package/vtex/invoke.ts +159 -194
  69. package/vtex/loaders/address.ts +49 -54
  70. package/vtex/loaders/brands.ts +19 -26
  71. package/vtex/loaders/cart.ts +24 -21
  72. package/vtex/loaders/catalog.ts +51 -53
  73. package/vtex/loaders/collections.ts +25 -27
  74. package/vtex/loaders/legacy.ts +487 -534
  75. package/vtex/loaders/logistics.ts +33 -37
  76. package/vtex/loaders/navbar.ts +5 -8
  77. package/vtex/loaders/orders.ts +28 -39
  78. package/vtex/loaders/pageType.ts +41 -35
  79. package/vtex/loaders/payment.ts +27 -37
  80. package/vtex/loaders/profile.ts +38 -38
  81. package/vtex/loaders/promotion.ts +5 -8
  82. package/vtex/loaders/search.ts +56 -59
  83. package/vtex/loaders/session.ts +22 -30
  84. package/vtex/loaders/user.ts +39 -41
  85. package/vtex/loaders/wishlist.ts +35 -35
  86. package/vtex/loaders/wishlistProducts.ts +3 -15
  87. package/vtex/loaders/workflow.ts +220 -227
  88. package/vtex/middleware.ts +116 -119
  89. package/vtex/types.ts +201 -201
  90. package/vtex/utils/batch.ts +13 -16
  91. package/vtex/utils/cookies.ts +76 -80
  92. package/vtex/utils/enrichment.ts +62 -42
  93. package/vtex/utils/fetchCache.ts +1 -4
  94. package/vtex/utils/index.ts +6 -6
  95. package/vtex/utils/intelligentSearch.ts +48 -57
  96. package/vtex/utils/legacy.ts +108 -124
  97. package/vtex/utils/pickAndOmit.ts +15 -20
  98. package/vtex/utils/proxy.ts +136 -146
  99. package/vtex/utils/resourceRange.ts +3 -3
  100. package/vtex/utils/segment.ts +100 -111
  101. package/vtex/utils/similars.ts +1 -2
  102. package/vtex/utils/sitemap.ts +91 -91
  103. package/vtex/utils/slugCache.ts +2 -6
  104. package/vtex/utils/slugify.ts +9 -9
  105. package/vtex/utils/transform.ts +1178 -1105
  106. package/vtex/utils/types.ts +1381 -1381
  107. package/vtex/utils/vtexId.ts +44 -47
  108. package/.github/workflows/release.yml +0 -34
  109. package/.releaserc.json +0 -28
  110. package/knip.json +0 -19
  111. package/tsconfig.json +0 -11
@@ -1,69 +1,58 @@
1
- export function gql(
2
- strings: TemplateStringsArray,
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
- fragments?: string[];
13
- query: string;
6
+ fragments?: string[];
7
+ query: string;
14
8
  }
15
9
 
16
10
  export function buildQuery(def: QueryDefinition): string {
17
- const fragments = def.fragments?.join("\n") ?? "";
18
- return fragments ? `${fragments}\n${def.query}` : def.query;
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
- query<T>(
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
- endpoint: string,
30
- headers: Record<string, string>,
31
- fetchFn?: typeof fetch,
20
+ endpoint: string,
21
+ headers: Record<string, string>,
22
+ fetchFn?: typeof fetch,
32
23
  ): GraphQLClient {
33
- const _fetch = fetchFn ?? globalThis.fetch;
34
- return {
35
- async query<T>(
36
- queryOrDef: string | QueryDefinition,
37
- variables?: Record<string, unknown>
38
- ): Promise<T> {
39
- const query = typeof queryOrDef === "string"
40
- ? queryOrDef
41
- : buildQuery(queryOrDef);
42
-
43
- const response = await _fetch(endpoint, {
44
- method: "POST",
45
- headers: {
46
- "Content-Type": "application/json",
47
- ...headers,
48
- },
49
- body: JSON.stringify({ query, variables }),
50
- });
51
-
52
- if (!response.ok) {
53
- throw new Error(
54
- `Shopify GraphQL error: ${response.status} ${response.statusText}`
55
- );
56
- }
57
-
58
- const json = await response.json() as { data?: T; errors?: Array<{ message: string }> };
59
-
60
- if (json.errors?.length) {
61
- throw new Error(
62
- `Shopify GraphQL errors: ${json.errors.map((e) => e.message).join(", ")}`
63
- );
64
- }
65
-
66
- return json.data as T;
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
- query: gql`mutation CreateCart {
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
- fragments: [Cart],
278
- query: gql`query GetCart($id: ID!) { cart(id: $id) { ...Cart } }`,
277
+ fragments: [Cart],
278
+ query: gql`query GetCart($id: ID!) { cart(id: $id) { ...Cart } }`,
279
279
  };
280
280
 
281
281
  export const GetProduct = {
282
- fragments: [Product, ProductVariant, Collection],
283
- query:
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
- fragments: [Product, ProductVariant, Collection],
291
- query:
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
- fragments: [Product, ProductVariant, Filter, Collection],
303
- query: gql`query searchWithFilters(
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
- fragments: [Product, ProductVariant, Collection, Filter],
344
- query: gql`query AllProducts(
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
- fragments: [Product, ProductVariant, Collection],
387
- query:
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
- query: gql`query GetShopInfo($identifiers: [HasMetafieldsIdentifier!]!) {
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
- fragments: [Customer],
451
- query: gql`query FetchCustomerInfo($customerAccessToken: String!) {
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
- fragments: [Cart],
460
- query: gql`mutation AddItemToCart($cartId: ID!, $lines: [CartLineInput!]!) {
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
- query: gql`mutation RegisterAccount(
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
- fragments: [Cart],
495
- query: gql`mutation AddCoupon($cartId: ID!, $discountCodes: [String!]!) {
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
- fragments: [Cart],
508
- query:
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
- query:
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
- 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 }>;
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
- 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[] };
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
- email: string;
75
- password: string;
74
+ email: string;
75
+ password: string;
76
76
  };
77
77
 
78
78
  export type CustomerAccessTokenCreateWithMultipassPayload = {
79
- customerAccessToken?: { accessToken: string; expiresAt: string } | null;
80
- customerUserErrors?: Array<{ message: string; code?: string }>;
79
+ customerAccessToken?: { accessToken: string; expiresAt: string } | null;
80
+ customerUserErrors?: Array<{ message: string; code?: string }>;
81
81
  };
82
82
 
83
83
  export type CustomerCreateInput = {
84
- email: string;
85
- password: string;
86
- firstName?: string;
87
- lastName?: string;
88
- acceptsMarketing?: boolean;
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
- customer?: Customer | null;
93
- customerUserErrors?: Array<{ message: string; code?: string }>;
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
- 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>;
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
- identifiers: Array<{ namespace: string; key: string }>;
108
+ identifiers: Array<{ namespace: string; key: string }>;
109
109
  };
110
110
 
111
111
  // Order/Admin types