@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.
- 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 +24 -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/productListShelf.ts +159 -0
- 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 +1178 -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/vtex/utils/vtexId.ts
CHANGED
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
export interface VtexAuthInfo {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
26
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
const payload = decodeJwtPayload(token);
|
|
50
|
+
if (!payload) {
|
|
51
|
+
return { isLoggedIn: false, isExpired: true };
|
|
52
|
+
}
|
|
55
53
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
66
|
-
typeof payload.account === "string" ? payload.account : undefined;
|
|
63
|
+
const account = typeof payload.account === "string" ? payload.account : undefined;
|
|
67
64
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
100
|
-
|
|
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
|
-
}
|