@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.
Files changed (113) hide show
  1. package/.github/workflows/release.yml +34 -0
  2. package/.releaserc.json +25 -0
  3. package/commerce/components/Image.tsx +209 -0
  4. package/commerce/components/JsonLd.tsx +285 -0
  5. package/commerce/sdk/analytics.ts +24 -0
  6. package/commerce/sdk/formatPrice.ts +23 -0
  7. package/commerce/sdk/url.ts +9 -0
  8. package/commerce/sdk/useOffer.ts +75 -0
  9. package/commerce/sdk/useVariantPossibilities.ts +43 -0
  10. package/commerce/types/commerce.ts +1105 -0
  11. package/commerce/utils/canonical.ts +11 -0
  12. package/commerce/utils/constants.ts +9 -0
  13. package/commerce/utils/filters.ts +10 -0
  14. package/commerce/utils/productToAnalyticsItem.ts +67 -0
  15. package/commerce/utils/stateByZip.ts +50 -0
  16. package/knip.json +19 -0
  17. package/package.json +77 -0
  18. package/shopify/actions/cart/addItems.ts +37 -0
  19. package/shopify/actions/cart/updateCoupons.ts +32 -0
  20. package/shopify/actions/cart/updateItems.ts +32 -0
  21. package/shopify/actions/user/signIn.ts +45 -0
  22. package/shopify/actions/user/signUp.ts +36 -0
  23. package/shopify/client.ts +58 -0
  24. package/shopify/index.ts +32 -0
  25. package/shopify/init.ts +40 -0
  26. package/shopify/loaders/ProductDetailsPage.ts +35 -0
  27. package/shopify/loaders/ProductList.ts +101 -0
  28. package/shopify/loaders/ProductListingPage.ts +180 -0
  29. package/shopify/loaders/RelatedProducts.ts +45 -0
  30. package/shopify/loaders/cart.ts +73 -0
  31. package/shopify/loaders/shop.ts +40 -0
  32. package/shopify/loaders/user.ts +44 -0
  33. package/shopify/utils/admin/admin.ts +57 -0
  34. package/shopify/utils/admin/queries.ts +29 -0
  35. package/shopify/utils/cart.ts +28 -0
  36. package/shopify/utils/cookies.ts +85 -0
  37. package/shopify/utils/enums.ts +438 -0
  38. package/shopify/utils/graphql.ts +69 -0
  39. package/shopify/utils/storefront/queries.ts +530 -0
  40. package/shopify/utils/storefront/storefront.graphql.gen.ts +113 -0
  41. package/shopify/utils/transform.ts +436 -0
  42. package/shopify/utils/types.ts +191 -0
  43. package/shopify/utils/user.ts +23 -0
  44. package/shopify/utils/utils.ts +164 -0
  45. package/tsconfig.json +11 -0
  46. package/vtex/README.md +6 -0
  47. package/vtex/actions/address.ts +211 -0
  48. package/vtex/actions/auth.ts +337 -0
  49. package/vtex/actions/checkout.ts +497 -0
  50. package/vtex/actions/index.ts +11 -0
  51. package/vtex/actions/masterData.ts +170 -0
  52. package/vtex/actions/misc.ts +196 -0
  53. package/vtex/actions/newsletter.ts +108 -0
  54. package/vtex/actions/orders.ts +37 -0
  55. package/vtex/actions/profile.ts +119 -0
  56. package/vtex/actions/session.ts +87 -0
  57. package/vtex/actions/trigger.ts +43 -0
  58. package/vtex/actions/wishlist.ts +116 -0
  59. package/vtex/client.ts +423 -0
  60. package/vtex/hooks/index.ts +4 -0
  61. package/vtex/hooks/useAutocomplete.ts +89 -0
  62. package/vtex/hooks/useCart.ts +219 -0
  63. package/vtex/hooks/useUser.ts +78 -0
  64. package/vtex/hooks/useWishlist.ts +119 -0
  65. package/vtex/index.ts +14 -0
  66. package/vtex/inline-loaders/productDetailsPage.ts +75 -0
  67. package/vtex/inline-loaders/productList.ts +163 -0
  68. package/vtex/inline-loaders/productListingPage.ts +447 -0
  69. package/vtex/inline-loaders/relatedProducts.ts +83 -0
  70. package/vtex/inline-loaders/suggestions.ts +49 -0
  71. package/vtex/inline-loaders/workflowProducts.ts +68 -0
  72. package/vtex/invoke.ts +202 -0
  73. package/vtex/loaders/address.ts +120 -0
  74. package/vtex/loaders/brands.ts +51 -0
  75. package/vtex/loaders/cart.ts +49 -0
  76. package/vtex/loaders/catalog.ts +165 -0
  77. package/vtex/loaders/collections.ts +57 -0
  78. package/vtex/loaders/index.ts +19 -0
  79. package/vtex/loaders/legacy.ts +671 -0
  80. package/vtex/loaders/logistics.ts +115 -0
  81. package/vtex/loaders/navbar.ts +29 -0
  82. package/vtex/loaders/orders.ts +103 -0
  83. package/vtex/loaders/pageType.ts +62 -0
  84. package/vtex/loaders/payment.ts +107 -0
  85. package/vtex/loaders/profile.ts +138 -0
  86. package/vtex/loaders/promotion.ts +33 -0
  87. package/vtex/loaders/search.ts +127 -0
  88. package/vtex/loaders/session.ts +91 -0
  89. package/vtex/loaders/user.ts +89 -0
  90. package/vtex/loaders/wishlist.ts +89 -0
  91. package/vtex/loaders/wishlistProducts.ts +81 -0
  92. package/vtex/loaders/workflow.ts +323 -0
  93. package/vtex/logo.png +0 -0
  94. package/vtex/middleware.ts +229 -0
  95. package/vtex/types.ts +248 -0
  96. package/vtex/utils/batch.ts +21 -0
  97. package/vtex/utils/cookies.ts +76 -0
  98. package/vtex/utils/enrichment.ts +540 -0
  99. package/vtex/utils/fetchCache.ts +150 -0
  100. package/vtex/utils/index.ts +17 -0
  101. package/vtex/utils/intelligentSearch.ts +84 -0
  102. package/vtex/utils/legacy.ts +155 -0
  103. package/vtex/utils/pickAndOmit.ts +30 -0
  104. package/vtex/utils/proxy.ts +196 -0
  105. package/vtex/utils/resourceRange.ts +10 -0
  106. package/vtex/utils/segment.ts +163 -0
  107. package/vtex/utils/similars.ts +38 -0
  108. package/vtex/utils/sitemap.ts +133 -0
  109. package/vtex/utils/slugCache.ts +32 -0
  110. package/vtex/utils/slugify.ts +13 -0
  111. package/vtex/utils/transform.ts +1331 -0
  112. package/vtex/utils/types.ts +1884 -0
  113. 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 };