@decocms/apps-vtex 8.0.0 → 8.1.0-next.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 (133) hide show
  1. package/package.json +7 -52
  2. package/src/index.ts +12 -15
  3. package/src/utils/constants.ts +2 -56
  4. package/src/utils/cookieSanitizer.ts +59 -59
  5. package/src/utils/operationRouter.ts +76 -72
  6. package/src/utils/types.ts +709 -1557
  7. package/src/vtexClient.ts +444 -0
  8. package/src/README.md +0 -6
  9. package/src/__tests__/client-segment-cookie.test.ts +0 -255
  10. package/src/__tests__/client-set-cookie-forward.test.ts +0 -257
  11. package/src/__tests__/schemas.test.ts +0 -71
  12. package/src/actions/address.ts +0 -250
  13. package/src/actions/analytics/sendEvent.ts +0 -86
  14. package/src/actions/auth.ts +0 -333
  15. package/src/actions/checkout.ts +0 -659
  16. package/src/actions/index.ts +0 -11
  17. package/src/actions/masterData.ts +0 -168
  18. package/src/actions/misc.ts +0 -188
  19. package/src/actions/newsletter.ts +0 -105
  20. package/src/actions/orders.ts +0 -34
  21. package/src/actions/profile.ts +0 -201
  22. package/src/actions/session.ts +0 -85
  23. package/src/actions/trigger.ts +0 -43
  24. package/src/actions/wishlist.ts +0 -114
  25. package/src/client.ts +0 -667
  26. package/src/commerceLoaders.ts +0 -267
  27. package/src/hooks/__tests__/createCart.render.test.ts +0 -114
  28. package/src/hooks/__tests__/createCart.test.ts +0 -92
  29. package/src/hooks/__tests__/createUseCart.test.ts +0 -184
  30. package/src/hooks/__tests__/createUseUser.test.ts +0 -48
  31. package/src/hooks/__tests__/createUseWishlist.test.ts +0 -87
  32. package/src/hooks/cartQuery.ts +0 -204
  33. package/src/hooks/createCart.ts +0 -427
  34. package/src/hooks/createUseCart.ts +0 -360
  35. package/src/hooks/createUseUser.ts +0 -153
  36. package/src/hooks/createUseWishlist.ts +0 -242
  37. package/src/hooks/index.ts +0 -25
  38. package/src/hooks/useAutocomplete.ts +0 -83
  39. package/src/hooks/useCart.ts +0 -243
  40. package/src/hooks/useUser.ts +0 -78
  41. package/src/hooks/useWishlist.ts +0 -119
  42. package/src/invoke.ts +0 -235
  43. package/src/loaders/ProductDetailsPage.ts +0 -1
  44. package/src/loaders/ProductList.ts +0 -1
  45. package/src/loaders/ProductListingPage.ts +0 -1
  46. package/src/loaders/address.ts +0 -115
  47. package/src/loaders/autocomplete.ts +0 -58
  48. package/src/loaders/brands.ts +0 -44
  49. package/src/loaders/cart/attachments.ts +0 -53
  50. package/src/loaders/cart/full.ts +0 -67
  51. package/src/loaders/cart/gifts.ts +0 -43
  52. package/src/loaders/cart/orderFormId.ts +0 -31
  53. package/src/loaders/cart/shipping.test.ts +0 -125
  54. package/src/loaders/cart/shipping.ts +0 -136
  55. package/src/loaders/cart/summary.ts +0 -36
  56. package/src/loaders/cart.ts +0 -52
  57. package/src/loaders/catalog.ts +0 -163
  58. package/src/loaders/collections.ts +0 -55
  59. package/src/loaders/index.ts +0 -20
  60. package/src/loaders/intelligentSearch/__tests__/productListingPage.test.ts +0 -51
  61. package/src/loaders/intelligentSearch/productDetailsPage.ts +0 -113
  62. package/src/loaders/intelligentSearch/productList.ts +0 -154
  63. package/src/loaders/intelligentSearch/productListingPage.ts +0 -526
  64. package/src/loaders/intelligentSearch/suggestions.ts +0 -46
  65. package/src/loaders/legacy/productDetailsPage.ts +0 -1
  66. package/src/loaders/legacy/productList.ts +0 -1
  67. package/src/loaders/legacy/relatedProductsLoader.ts +0 -81
  68. package/src/loaders/legacy.ts +0 -635
  69. package/src/loaders/logistics.ts +0 -111
  70. package/src/loaders/minicart.ts +0 -78
  71. package/src/loaders/navbar.ts +0 -26
  72. package/src/loaders/orders.ts +0 -92
  73. package/src/loaders/pageType.ts +0 -68
  74. package/src/loaders/paths/PDPDefaultPath.ts +0 -51
  75. package/src/loaders/payment.ts +0 -97
  76. package/src/loaders/productListFull.ts +0 -159
  77. package/src/loaders/profile.ts +0 -138
  78. package/src/loaders/promotion.ts +0 -30
  79. package/src/loaders/search.ts +0 -124
  80. package/src/loaders/session.ts +0 -83
  81. package/src/loaders/user.ts +0 -87
  82. package/src/loaders/wishlist.ts +0 -89
  83. package/src/loaders/wishlistProducts.ts +0 -69
  84. package/src/loaders/workflow/products.ts +0 -64
  85. package/src/loaders/workflow.ts +0 -316
  86. package/src/logo.png +0 -0
  87. package/src/manifest.gen.ts +0 -89
  88. package/src/middleware.ts +0 -240
  89. package/src/mod.ts +0 -157
  90. package/src/registry.ts +0 -9
  91. package/src/schemas.gen.ts +0 -3191
  92. package/src/schemas.ts +0 -30
  93. package/src/types.ts +0 -248
  94. package/src/utils/__tests__/cartProjection.test.ts +0 -118
  95. package/src/utils/__tests__/cookieSanitizer.test.ts +0 -162
  96. package/src/utils/__tests__/fetch.test.ts +0 -80
  97. package/src/utils/__tests__/fetchCache.test.ts +0 -155
  98. package/src/utils/__tests__/instrumentedFetch.test.ts +0 -158
  99. package/src/utils/__tests__/intelligentSearch.test.ts +0 -88
  100. package/src/utils/__tests__/minicart.test.ts +0 -184
  101. package/src/utils/__tests__/operationRouter.test.ts +0 -227
  102. package/src/utils/__tests__/resilience.test.ts +0 -205
  103. package/src/utils/__tests__/resourceRange.test.ts +0 -32
  104. package/src/utils/__tests__/simulationCache.test.ts +0 -40
  105. package/src/utils/__tests__/sitemap.test.ts +0 -185
  106. package/src/utils/__tests__/slugify.test.ts +0 -31
  107. package/src/utils/__tests__/transform.test.ts +0 -769
  108. package/src/utils/accountLoaders.ts +0 -203
  109. package/src/utils/authHelpers.ts +0 -85
  110. package/src/utils/batch.ts +0 -18
  111. package/src/utils/cartProjection.ts +0 -96
  112. package/src/utils/cookies.ts +0 -167
  113. package/src/utils/enrichment.ts +0 -560
  114. package/src/utils/fetch.ts +0 -107
  115. package/src/utils/fetchCache.ts +0 -199
  116. package/src/utils/index.ts +0 -19
  117. package/src/utils/instrumentedFetch.ts +0 -97
  118. package/src/utils/intelligentSearch.ts +0 -96
  119. package/src/utils/legacy.ts +0 -139
  120. package/src/utils/minicart.ts +0 -139
  121. package/src/utils/pickAndOmit.ts +0 -25
  122. package/src/utils/proxy.ts +0 -435
  123. package/src/utils/resilience.ts +0 -352
  124. package/src/utils/resourceRange.ts +0 -10
  125. package/src/utils/segment.ts +0 -152
  126. package/src/utils/similars.ts +0 -37
  127. package/src/utils/simulationCache.ts +0 -73
  128. package/src/utils/sitemap.ts +0 -282
  129. package/src/utils/slugCache.ts +0 -28
  130. package/src/utils/slugify.ts +0 -13
  131. package/src/utils/transform.ts +0 -1522
  132. package/src/utils/vtexId.ts +0 -138
  133. package/tsconfig.json +0 -7
@@ -1,138 +0,0 @@
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(new RegExp(`(?:^|;\\s*)${VTEX_AUTH_COOKIE}=([^;]+)`));
26
- return match?.[1] ?? null;
27
- }
28
-
29
- /**
30
- * Decode a JWT payload without verification.
31
- * Only reads the middle segment (claims).
32
- */
33
- function decodeJwtPayload(token: string): Record<string, unknown> | null {
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
- }
43
- }
44
-
45
- /**
46
- * Parse a VTEX auth cookie token into structured auth info.
47
- */
48
- export function parseVtexAuthToken(token: string): VtexAuthInfo {
49
- const payload = decodeJwtPayload(token);
50
- if (!payload) {
51
- return { isLoggedIn: false, isExpired: true };
52
- }
53
-
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;
62
-
63
- const account = typeof payload.account === "string" ? payload.account : undefined;
64
-
65
- return {
66
- isLoggedIn: !isExpired,
67
- email,
68
- account,
69
- exp,
70
- isExpired,
71
- };
72
- }
73
-
74
- /**
75
- * Check if a request has a valid (non-expired) VTEX auth cookie.
76
- */
77
- export function isVtexLoggedIn(request: Request): boolean {
78
- const cookies = request.headers.get("cookie") ?? "";
79
- const token = extractVtexAuthCookie(cookies);
80
- if (!token) return false;
81
- return parseVtexAuthToken(token).isLoggedIn;
82
- }
83
-
84
- /**
85
- * Build a complete auth cookie header string from either a raw token
86
- * or an already-formatted cookie string.
87
- *
88
- * VTEX requires both `VtexIdclientAutCookie` and the account-suffixed
89
- * variant `VtexIdclientAutCookie_{account}` for authenticated GraphQL
90
- * calls to myvtex.com.
91
- *
92
- * If `authCookie` already contains `=` (i.e. it's a full cookie string),
93
- * it's returned as-is. Otherwise the token is wrapped in both cookie names.
94
- */
95
- export function buildAuthCookieHeader(authCookie: string, account: string): string {
96
- if (authCookie.includes("=")) return authCookie;
97
- return `${VTEX_AUTH_COOKIE}=${authCookie}; ${VTEX_AUTH_COOKIE}_${account}=${authCookie}`;
98
- }
99
-
100
- export interface CookiePayload {
101
- sub?: string;
102
- account?: string;
103
- audience?: string;
104
- sess?: string;
105
- exp?: number;
106
- userId?: string;
107
- }
108
-
109
- /**
110
- * Parse VTEX auth cookies from request headers.
111
- *
112
- * Returns the serialized cookie string (for forwarding) and the decoded
113
- * JWT payload. Compatible with the legacy deco-cx/apps parseCookie API.
114
- */
115
- export function parseCookie(
116
- headers: Headers,
117
- account: string,
118
- ): { cookie: string; payload: CookiePayload | undefined } {
119
- const cookieHeader = headers.get("cookie") ?? "";
120
-
121
- const base = extractVtexAuthCookie(cookieHeader);
122
- const suffixedRe = new RegExp(`(?:^|;\\s*)${VTEX_AUTH_COOKIE}_${account}=([^;]+)`);
123
- const suffixedMatch = cookieHeader.match(suffixedRe);
124
- const suffixed = suffixedMatch?.[1] ?? null;
125
-
126
- const token = base ?? suffixed;
127
- const payload = token
128
- ? ((decodeJwtPayload(token) as CookiePayload | null) ?? undefined)
129
- : undefined;
130
-
131
- const parts: string[] = [];
132
- if (base) parts.push(`${VTEX_AUTH_COOKIE}=${base}`);
133
- if (suffixed) parts.push(`${VTEX_AUTH_COOKIE}_${account}=${suffixed}`);
134
-
135
- return { cookie: parts.join("; "), payload };
136
- }
137
-
138
- export { VTEX_AUTH_COOKIE };
package/tsconfig.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "outDir": "dist"
5
- },
6
- "include": ["src/**/*"]
7
- }