@decocms/apps 0.20.1
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/.github/workflows/release.yml +34 -0
- package/.releaserc.json +25 -0
- package/commerce/components/Image.tsx +209 -0
- package/commerce/components/JsonLd.tsx +285 -0
- package/commerce/sdk/analytics.ts +24 -0
- package/commerce/sdk/formatPrice.ts +23 -0
- package/commerce/sdk/url.ts +9 -0
- package/commerce/sdk/useOffer.ts +75 -0
- package/commerce/sdk/useVariantPossibilities.ts +43 -0
- package/commerce/types/commerce.ts +1105 -0
- package/commerce/utils/canonical.ts +11 -0
- package/commerce/utils/constants.ts +9 -0
- package/commerce/utils/filters.ts +10 -0
- package/commerce/utils/productToAnalyticsItem.ts +67 -0
- package/commerce/utils/stateByZip.ts +50 -0
- package/knip.json +19 -0
- package/package.json +77 -0
- package/shopify/actions/cart/addItems.ts +37 -0
- package/shopify/actions/cart/updateCoupons.ts +32 -0
- package/shopify/actions/cart/updateItems.ts +32 -0
- package/shopify/actions/user/signIn.ts +45 -0
- package/shopify/actions/user/signUp.ts +36 -0
- package/shopify/client.ts +58 -0
- package/shopify/index.ts +32 -0
- package/shopify/init.ts +40 -0
- package/shopify/loaders/ProductDetailsPage.ts +35 -0
- package/shopify/loaders/ProductList.ts +101 -0
- package/shopify/loaders/ProductListingPage.ts +180 -0
- package/shopify/loaders/RelatedProducts.ts +45 -0
- package/shopify/loaders/cart.ts +73 -0
- package/shopify/loaders/shop.ts +40 -0
- package/shopify/loaders/user.ts +44 -0
- package/shopify/utils/admin/admin.ts +57 -0
- package/shopify/utils/admin/queries.ts +29 -0
- package/shopify/utils/cart.ts +28 -0
- package/shopify/utils/cookies.ts +85 -0
- package/shopify/utils/enums.ts +438 -0
- package/shopify/utils/graphql.ts +69 -0
- package/shopify/utils/storefront/queries.ts +530 -0
- package/shopify/utils/storefront/storefront.graphql.gen.ts +113 -0
- package/shopify/utils/transform.ts +436 -0
- package/shopify/utils/types.ts +191 -0
- package/shopify/utils/user.ts +23 -0
- package/shopify/utils/utils.ts +164 -0
- package/tsconfig.json +11 -0
- package/vtex/README.md +6 -0
- package/vtex/actions/address.ts +211 -0
- package/vtex/actions/auth.ts +337 -0
- package/vtex/actions/checkout.ts +497 -0
- package/vtex/actions/index.ts +11 -0
- package/vtex/actions/masterData.ts +170 -0
- package/vtex/actions/misc.ts +196 -0
- package/vtex/actions/newsletter.ts +108 -0
- package/vtex/actions/orders.ts +37 -0
- package/vtex/actions/profile.ts +119 -0
- package/vtex/actions/session.ts +87 -0
- package/vtex/actions/trigger.ts +43 -0
- package/vtex/actions/wishlist.ts +116 -0
- package/vtex/client.ts +423 -0
- package/vtex/hooks/index.ts +4 -0
- package/vtex/hooks/useAutocomplete.ts +89 -0
- package/vtex/hooks/useCart.ts +219 -0
- package/vtex/hooks/useUser.ts +78 -0
- package/vtex/hooks/useWishlist.ts +119 -0
- package/vtex/index.ts +14 -0
- package/vtex/inline-loaders/productDetailsPage.ts +75 -0
- package/vtex/inline-loaders/productList.ts +163 -0
- package/vtex/inline-loaders/productListingPage.ts +447 -0
- package/vtex/inline-loaders/relatedProducts.ts +83 -0
- package/vtex/inline-loaders/suggestions.ts +49 -0
- package/vtex/inline-loaders/workflowProducts.ts +68 -0
- package/vtex/invoke.ts +202 -0
- package/vtex/loaders/address.ts +120 -0
- package/vtex/loaders/brands.ts +51 -0
- package/vtex/loaders/cart.ts +49 -0
- package/vtex/loaders/catalog.ts +165 -0
- package/vtex/loaders/collections.ts +57 -0
- package/vtex/loaders/index.ts +19 -0
- package/vtex/loaders/legacy.ts +671 -0
- package/vtex/loaders/logistics.ts +115 -0
- package/vtex/loaders/navbar.ts +29 -0
- package/vtex/loaders/orders.ts +103 -0
- package/vtex/loaders/pageType.ts +62 -0
- package/vtex/loaders/payment.ts +107 -0
- package/vtex/loaders/profile.ts +138 -0
- package/vtex/loaders/promotion.ts +33 -0
- package/vtex/loaders/search.ts +127 -0
- package/vtex/loaders/session.ts +91 -0
- package/vtex/loaders/user.ts +89 -0
- package/vtex/loaders/wishlist.ts +89 -0
- package/vtex/loaders/wishlistProducts.ts +81 -0
- package/vtex/loaders/workflow.ts +323 -0
- package/vtex/logo.png +0 -0
- package/vtex/middleware.ts +229 -0
- package/vtex/types.ts +248 -0
- package/vtex/utils/batch.ts +21 -0
- package/vtex/utils/cookies.ts +76 -0
- package/vtex/utils/enrichment.ts +540 -0
- package/vtex/utils/fetchCache.ts +150 -0
- package/vtex/utils/index.ts +17 -0
- package/vtex/utils/intelligentSearch.ts +84 -0
- package/vtex/utils/legacy.ts +155 -0
- package/vtex/utils/pickAndOmit.ts +30 -0
- package/vtex/utils/proxy.ts +196 -0
- package/vtex/utils/resourceRange.ts +10 -0
- package/vtex/utils/segment.ts +163 -0
- package/vtex/utils/similars.ts +38 -0
- package/vtex/utils/sitemap.ts +133 -0
- package/vtex/utils/slugCache.ts +32 -0
- package/vtex/utils/slugify.ts +13 -0
- package/vtex/utils/transform.ts +1331 -0
- package/vtex/utils/types.ts +1884 -0
- package/vtex/utils/vtexId.ts +103 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VTEX authentication cookie parser.
|
|
3
|
+
*
|
|
4
|
+
* Parses the VtexIdclientAutCookie JWT to detect login state
|
|
5
|
+
* without making API calls. Only decodes the payload (no signature
|
|
6
|
+
* verification -- we only need presence and expiry, not auth).
|
|
7
|
+
*/
|
|
8
|
+
|
|
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;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const VTEX_AUTH_COOKIE = "VtexIdclientAutCookie";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Extract the VtexIdclientAutCookie value from a cookie string.
|
|
23
|
+
*/
|
|
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;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Decode a JWT payload without verification.
|
|
33
|
+
* Only reads the middle segment (claims).
|
|
34
|
+
*/
|
|
35
|
+
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
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Parse a VTEX auth cookie token into structured auth info.
|
|
49
|
+
*/
|
|
50
|
+
export function parseVtexAuthToken(token: string): VtexAuthInfo {
|
|
51
|
+
const payload = decodeJwtPayload(token);
|
|
52
|
+
if (!payload) {
|
|
53
|
+
return { isLoggedIn: false, isExpired: true };
|
|
54
|
+
}
|
|
55
|
+
|
|
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;
|
|
64
|
+
|
|
65
|
+
const account =
|
|
66
|
+
typeof payload.account === "string" ? payload.account : undefined;
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
isLoggedIn: !isExpired,
|
|
70
|
+
email,
|
|
71
|
+
account,
|
|
72
|
+
exp,
|
|
73
|
+
isExpired,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Check if a request has a valid (non-expired) VTEX auth cookie.
|
|
79
|
+
*/
|
|
80
|
+
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;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Build a complete auth cookie header string from either a raw token
|
|
89
|
+
* or an already-formatted cookie string.
|
|
90
|
+
*
|
|
91
|
+
* VTEX requires both `VtexIdclientAutCookie` and the account-suffixed
|
|
92
|
+
* variant `VtexIdclientAutCookie_{account}` for authenticated GraphQL
|
|
93
|
+
* calls to myvtex.com.
|
|
94
|
+
*
|
|
95
|
+
* If `authCookie` already contains `=` (i.e. it's a full cookie string),
|
|
96
|
+
* it's returned as-is. Otherwise the token is wrapped in both cookie names.
|
|
97
|
+
*/
|
|
98
|
+
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}`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { VTEX_AUTH_COOKIE };
|