@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.
Files changed (110) 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 +23 -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/productListingPage.ts +10 -34
  64. package/vtex/inline-loaders/relatedProducts.ts +1 -3
  65. package/vtex/inline-loaders/suggestions.ts +36 -39
  66. package/vtex/inline-loaders/workflowProducts.ts +45 -49
  67. package/vtex/invoke.ts +159 -194
  68. package/vtex/loaders/address.ts +49 -54
  69. package/vtex/loaders/brands.ts +19 -26
  70. package/vtex/loaders/cart.ts +24 -21
  71. package/vtex/loaders/catalog.ts +51 -53
  72. package/vtex/loaders/collections.ts +25 -27
  73. package/vtex/loaders/legacy.ts +487 -534
  74. package/vtex/loaders/logistics.ts +33 -37
  75. package/vtex/loaders/navbar.ts +5 -8
  76. package/vtex/loaders/orders.ts +28 -39
  77. package/vtex/loaders/pageType.ts +41 -35
  78. package/vtex/loaders/payment.ts +27 -37
  79. package/vtex/loaders/profile.ts +38 -38
  80. package/vtex/loaders/promotion.ts +5 -8
  81. package/vtex/loaders/search.ts +56 -59
  82. package/vtex/loaders/session.ts +22 -30
  83. package/vtex/loaders/user.ts +39 -41
  84. package/vtex/loaders/wishlist.ts +35 -35
  85. package/vtex/loaders/wishlistProducts.ts +3 -15
  86. package/vtex/loaders/workflow.ts +220 -227
  87. package/vtex/middleware.ts +116 -119
  88. package/vtex/types.ts +201 -201
  89. package/vtex/utils/batch.ts +13 -16
  90. package/vtex/utils/cookies.ts +76 -80
  91. package/vtex/utils/enrichment.ts +62 -42
  92. package/vtex/utils/fetchCache.ts +1 -4
  93. package/vtex/utils/index.ts +6 -6
  94. package/vtex/utils/intelligentSearch.ts +48 -57
  95. package/vtex/utils/legacy.ts +108 -124
  96. package/vtex/utils/pickAndOmit.ts +15 -20
  97. package/vtex/utils/proxy.ts +136 -146
  98. package/vtex/utils/resourceRange.ts +3 -3
  99. package/vtex/utils/segment.ts +100 -111
  100. package/vtex/utils/similars.ts +1 -2
  101. package/vtex/utils/sitemap.ts +91 -91
  102. package/vtex/utils/slugCache.ts +2 -6
  103. package/vtex/utils/slugify.ts +9 -9
  104. package/vtex/utils/transform.ts +1012 -1105
  105. package/vtex/utils/types.ts +1381 -1381
  106. package/vtex/utils/vtexId.ts +44 -47
  107. package/.github/workflows/release.yml +0 -34
  108. package/.releaserc.json +0 -28
  109. package/knip.json +0 -19
  110. package/tsconfig.json +0 -11
@@ -7,13 +7,13 @@
7
7
  */
8
8
 
9
9
  export interface VtexAuthInfo {
10
- isLoggedIn: boolean;
11
- email?: string;
12
- account?: string;
13
- /** Unix timestamp (seconds) when the token expires. */
14
- exp?: number;
15
- /** Whether the token is expired. */
16
- isExpired: boolean;
10
+ isLoggedIn: boolean;
11
+ email?: string;
12
+ account?: string;
13
+ /** Unix timestamp (seconds) when the token expires. */
14
+ exp?: number;
15
+ /** Whether the token is expired. */
16
+ isExpired: boolean;
17
17
  }
18
18
 
19
19
  const VTEX_AUTH_COOKIE = "VtexIdclientAutCookie";
@@ -22,10 +22,8 @@ const VTEX_AUTH_COOKIE = "VtexIdclientAutCookie";
22
22
  * Extract the VtexIdclientAutCookie value from a cookie string.
23
23
  */
24
24
  export function extractVtexAuthCookie(cookieHeader: string): string | null {
25
- const match = cookieHeader.match(
26
- new RegExp(`(?:^|;\\s*)${VTEX_AUTH_COOKIE}=([^;]+)`),
27
- );
28
- return match?.[1] ?? null;
25
+ const match = cookieHeader.match(new RegExp(`(?:^|;\\s*)${VTEX_AUTH_COOKIE}=([^;]+)`));
26
+ return match?.[1] ?? null;
29
27
  }
30
28
 
31
29
  /**
@@ -33,55 +31,54 @@ export function extractVtexAuthCookie(cookieHeader: string): string | null {
33
31
  * Only reads the middle segment (claims).
34
32
  */
35
33
  function decodeJwtPayload(token: string): Record<string, unknown> | null {
36
- try {
37
- const parts = token.split(".");
38
- if (parts.length !== 3) return null;
39
- const payload = parts[1];
40
- const decoded = atob(payload.replace(/-/g, "+").replace(/_/g, "/"));
41
- return JSON.parse(decoded);
42
- } catch {
43
- return null;
44
- }
34
+ try {
35
+ const parts = token.split(".");
36
+ if (parts.length !== 3) return null;
37
+ const payload = parts[1];
38
+ const decoded = atob(payload.replace(/-/g, "+").replace(/_/g, "/"));
39
+ return JSON.parse(decoded);
40
+ } catch {
41
+ return null;
42
+ }
45
43
  }
46
44
 
47
45
  /**
48
46
  * Parse a VTEX auth cookie token into structured auth info.
49
47
  */
50
48
  export function parseVtexAuthToken(token: string): VtexAuthInfo {
51
- const payload = decodeJwtPayload(token);
52
- if (!payload) {
53
- return { isLoggedIn: false, isExpired: true };
54
- }
49
+ const payload = decodeJwtPayload(token);
50
+ if (!payload) {
51
+ return { isLoggedIn: false, isExpired: true };
52
+ }
55
53
 
56
- const exp = typeof payload.exp === "number" ? payload.exp : undefined;
57
- const isExpired = exp != null ? exp * 1000 < Date.now() : false;
58
- const email =
59
- typeof payload.sub === "string"
60
- ? payload.sub
61
- : typeof payload.userId === "string"
62
- ? payload.userId
63
- : undefined;
54
+ const exp = typeof payload.exp === "number" ? payload.exp : undefined;
55
+ const isExpired = exp != null ? exp * 1000 < Date.now() : false;
56
+ const email =
57
+ typeof payload.sub === "string"
58
+ ? payload.sub
59
+ : typeof payload.userId === "string"
60
+ ? payload.userId
61
+ : undefined;
64
62
 
65
- const account =
66
- typeof payload.account === "string" ? payload.account : undefined;
63
+ const account = typeof payload.account === "string" ? payload.account : undefined;
67
64
 
68
- return {
69
- isLoggedIn: !isExpired,
70
- email,
71
- account,
72
- exp,
73
- isExpired,
74
- };
65
+ return {
66
+ isLoggedIn: !isExpired,
67
+ email,
68
+ account,
69
+ exp,
70
+ isExpired,
71
+ };
75
72
  }
76
73
 
77
74
  /**
78
75
  * Check if a request has a valid (non-expired) VTEX auth cookie.
79
76
  */
80
77
  export function isVtexLoggedIn(request: Request): boolean {
81
- const cookies = request.headers.get("cookie") ?? "";
82
- const token = extractVtexAuthCookie(cookies);
83
- if (!token) return false;
84
- return parseVtexAuthToken(token).isLoggedIn;
78
+ const cookies = request.headers.get("cookie") ?? "";
79
+ const token = extractVtexAuthCookie(cookies);
80
+ if (!token) return false;
81
+ return parseVtexAuthToken(token).isLoggedIn;
85
82
  }
86
83
 
87
84
  /**
@@ -96,8 +93,8 @@ export function isVtexLoggedIn(request: Request): boolean {
96
93
  * it's returned as-is. Otherwise the token is wrapped in both cookie names.
97
94
  */
98
95
  export function buildAuthCookieHeader(authCookie: string, account: string): string {
99
- if (authCookie.includes("=")) return authCookie;
100
- return `${VTEX_AUTH_COOKIE}=${authCookie}; ${VTEX_AUTH_COOKIE}_${account}=${authCookie}`;
96
+ if (authCookie.includes("=")) return authCookie;
97
+ return `${VTEX_AUTH_COOKIE}=${authCookie}; ${VTEX_AUTH_COOKIE}_${account}=${authCookie}`;
101
98
  }
102
99
 
103
100
  export { VTEX_AUTH_COOKIE };
@@ -1,34 +0,0 @@
1
- name: Release
2
-
3
- on:
4
- push:
5
- branches: [main]
6
- workflow_dispatch:
7
-
8
- permissions:
9
- contents: write
10
- id-token: write
11
- issues: write
12
- pull-requests: write
13
-
14
- jobs:
15
- release:
16
- runs-on: ubuntu-latest
17
- steps:
18
- - uses: actions/checkout@v4
19
- with:
20
- fetch-depth: 0
21
-
22
- - uses: actions/setup-node@v4
23
- with:
24
- node-version: 22
25
- registry-url: https://registry.npmjs.org
26
-
27
- - run: npm install -g npm@latest
28
-
29
- - run: npm install
30
-
31
- - name: Release
32
- run: npx semantic-release
33
- env:
34
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
package/.releaserc.json DELETED
@@ -1,28 +0,0 @@
1
- {
2
- "branches": ["main"],
3
- "plugins": [
4
- ["@semantic-release/commit-analyzer", {
5
- "preset": "angular",
6
- "releaseRules": [
7
- { "type": "feat", "release": "minor" },
8
- { "type": "fix", "release": "patch" },
9
- { "type": "perf", "release": "patch" },
10
- { "type": "refactor", "release": "patch" },
11
- { "type": "docs", "release": false },
12
- { "type": "chore", "release": false },
13
- { "type": "style", "release": false },
14
- { "type": "test", "release": false }
15
- ]
16
- }],
17
- "@semantic-release/release-notes-generator",
18
- ["@semantic-release/exec", {
19
- "prepareCmd": "npm version ${nextRelease.version} --no-git-tag-version",
20
- "publishCmd": "npm publish --access public"
21
- }],
22
- "@semantic-release/github",
23
- ["@semantic-release/git", {
24
- "assets": ["package.json"],
25
- "message": "chore(release): ${nextRelease.version} [skip ci]"
26
- }]
27
- ]
28
- }
package/knip.json DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "$schema": "https://unpkg.com/knip@latest/schema.json",
3
- "entry": [
4
- "vtex/*.ts",
5
- "vtex/inline-loaders/*.ts",
6
- "commerce/components/*.tsx",
7
- "commerce/sdk/*.ts"
8
- ],
9
- "project": [
10
- "**/*.ts",
11
- "**/*.tsx"
12
- ],
13
- "ignoreBinaries": [
14
- "semantic-release"
15
- ],
16
- "ignoreDependencies": [
17
- "@decocms/start"
18
- ]
19
- }
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "jsx": "react-jsx",
4
- "moduleResolution": "bundler",
5
- "module": "ESNext",
6
- "target": "ES2022",
7
- "skipLibCheck": true,
8
- "strictNullChecks": true
9
- },
10
- "include": ["**/*.ts", "**/*.tsx"]
11
- }