@decocms/apps-vtex 8.1.0-next.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 (139) hide show
  1. package/package.json +7 -52
  2. package/src/index.ts +10 -28
  3. package/src/utils/constants.ts +2 -56
  4. package/src/utils/cookieSanitizer.ts +59 -59
  5. package/src/utils/operationRouter.ts +75 -65
  6. package/src/utils/types.ts +709 -1557
  7. package/src/vtexClient.ts +354 -343
  8. package/src/README.md +0 -6
  9. package/src/__conformance__/upstream.test.ts +0 -158
  10. package/src/__tests__/client-segment-cookie.test.ts +0 -255
  11. package/src/__tests__/client-set-cookie-forward.test.ts +0 -257
  12. package/src/__tests__/schemas.test.ts +0 -71
  13. package/src/actions/address.ts +0 -250
  14. package/src/actions/analytics/sendEvent.ts +0 -86
  15. package/src/actions/auth.ts +0 -333
  16. package/src/actions/checkout.ts +0 -659
  17. package/src/actions/index.ts +0 -11
  18. package/src/actions/masterData.ts +0 -168
  19. package/src/actions/misc.ts +0 -188
  20. package/src/actions/newsletter.ts +0 -105
  21. package/src/actions/orders.ts +0 -34
  22. package/src/actions/profile.ts +0 -201
  23. package/src/actions/session.ts +0 -85
  24. package/src/actions/trigger.ts +0 -43
  25. package/src/actions/wishlist.ts +0 -114
  26. package/src/client.ts +0 -724
  27. package/src/commerceLoaders.ts +0 -267
  28. package/src/hooks/__tests__/createCart.render.test.ts +0 -114
  29. package/src/hooks/__tests__/createCart.test.ts +0 -92
  30. package/src/hooks/__tests__/createUseCart.test.ts +0 -184
  31. package/src/hooks/__tests__/createUseUser.test.ts +0 -48
  32. package/src/hooks/__tests__/createUseWishlist.test.ts +0 -87
  33. package/src/hooks/cartQuery.ts +0 -204
  34. package/src/hooks/createCart.ts +0 -427
  35. package/src/hooks/createUseCart.ts +0 -360
  36. package/src/hooks/createUseUser.ts +0 -153
  37. package/src/hooks/createUseWishlist.ts +0 -242
  38. package/src/hooks/index.ts +0 -25
  39. package/src/hooks/useAutocomplete.ts +0 -83
  40. package/src/hooks/useCart.ts +0 -243
  41. package/src/hooks/useUser.ts +0 -78
  42. package/src/hooks/useWishlist.ts +0 -119
  43. package/src/invoke.ts +0 -235
  44. package/src/loaders/ProductDetailsPage.ts +0 -1
  45. package/src/loaders/ProductList.ts +0 -1
  46. package/src/loaders/ProductListingPage.ts +0 -1
  47. package/src/loaders/__tests__/legacyProductList.test.ts +0 -157
  48. package/src/loaders/address.ts +0 -115
  49. package/src/loaders/autocomplete.ts +0 -56
  50. package/src/loaders/brands.ts +0 -44
  51. package/src/loaders/cart/attachments.ts +0 -53
  52. package/src/loaders/cart/full.ts +0 -67
  53. package/src/loaders/cart/gifts.ts +0 -43
  54. package/src/loaders/cart/orderFormId.ts +0 -31
  55. package/src/loaders/cart/shipping.test.ts +0 -125
  56. package/src/loaders/cart/shipping.ts +0 -136
  57. package/src/loaders/cart/summary.ts +0 -36
  58. package/src/loaders/cart.ts +0 -52
  59. package/src/loaders/catalog.ts +0 -163
  60. package/src/loaders/collections.ts +0 -55
  61. package/src/loaders/index.ts +0 -20
  62. package/src/loaders/intelligentSearch/__tests__/productListingPage.test.ts +0 -51
  63. package/src/loaders/intelligentSearch/productDetailsPage.ts +0 -111
  64. package/src/loaders/intelligentSearch/productList.ts +0 -170
  65. package/src/loaders/intelligentSearch/productListingPage.ts +0 -525
  66. package/src/loaders/intelligentSearch/suggestions.ts +0 -44
  67. package/src/loaders/legacy/productDetailsPage.ts +0 -1
  68. package/src/loaders/legacy/productList.ts +0 -1
  69. package/src/loaders/legacy/relatedProductsLoader.ts +0 -79
  70. package/src/loaders/legacy.ts +0 -710
  71. package/src/loaders/logistics.ts +0 -111
  72. package/src/loaders/minicart.ts +0 -78
  73. package/src/loaders/navbar.ts +0 -26
  74. package/src/loaders/orders.ts +0 -92
  75. package/src/loaders/pageType.ts +0 -68
  76. package/src/loaders/paths/PDPDefaultPath.ts +0 -51
  77. package/src/loaders/payment.ts +0 -97
  78. package/src/loaders/productListFull.ts +0 -157
  79. package/src/loaders/profile.ts +0 -138
  80. package/src/loaders/promotion.ts +0 -30
  81. package/src/loaders/search.ts +0 -124
  82. package/src/loaders/session.ts +0 -83
  83. package/src/loaders/user.ts +0 -87
  84. package/src/loaders/wishlist.ts +0 -89
  85. package/src/loaders/wishlistProducts.ts +0 -69
  86. package/src/loaders/workflow/products.ts +0 -62
  87. package/src/loaders/workflow.ts +0 -316
  88. package/src/logo.png +0 -0
  89. package/src/manifest.gen.ts +0 -89
  90. package/src/middleware.cacheHeaders.test.ts +0 -44
  91. package/src/middleware.ts +0 -240
  92. package/src/mod.ts +0 -173
  93. package/src/registry.ts +0 -9
  94. package/src/schemas.gen.ts +0 -3191
  95. package/src/schemas.ts +0 -30
  96. package/src/types.ts +0 -248
  97. package/src/utils/__tests__/cartProjection.test.ts +0 -118
  98. package/src/utils/__tests__/cookieSanitizer.test.ts +0 -162
  99. package/src/utils/__tests__/fetch.test.ts +0 -80
  100. package/src/utils/__tests__/fetchCache.test.ts +0 -155
  101. package/src/utils/__tests__/instrumentedFetch.test.ts +0 -158
  102. package/src/utils/__tests__/intelligentSearch.test.ts +0 -88
  103. package/src/utils/__tests__/minicart.test.ts +0 -184
  104. package/src/utils/__tests__/operationRouter.test.ts +0 -227
  105. package/src/utils/__tests__/resilience.test.ts +0 -205
  106. package/src/utils/__tests__/resourceRange.test.ts +0 -32
  107. package/src/utils/__tests__/simulationCache.test.ts +0 -40
  108. package/src/utils/__tests__/sitemap.test.ts +0 -185
  109. package/src/utils/__tests__/slugify.test.ts +0 -31
  110. package/src/utils/__tests__/storefrontBaseUrl.test.ts +0 -61
  111. package/src/utils/__tests__/transform.test.ts +0 -1111
  112. package/src/utils/accountLoaders.ts +0 -203
  113. package/src/utils/authHelpers.ts +0 -85
  114. package/src/utils/batch.ts +0 -18
  115. package/src/utils/buildOfferShelf.test.ts +0 -59
  116. package/src/utils/cartProjection.ts +0 -96
  117. package/src/utils/cookies.ts +0 -167
  118. package/src/utils/enrichment.ts +0 -556
  119. package/src/utils/fetch.ts +0 -111
  120. package/src/utils/fetchCache.ts +0 -55
  121. package/src/utils/index.ts +0 -19
  122. package/src/utils/instrumentedFetch.ts +0 -98
  123. package/src/utils/intelligentSearch.ts +0 -96
  124. package/src/utils/legacy.ts +0 -139
  125. package/src/utils/minicart.ts +0 -139
  126. package/src/utils/pickAndOmit.ts +0 -25
  127. package/src/utils/proxy.ts +0 -495
  128. package/src/utils/resilience.ts +0 -352
  129. package/src/utils/resourceRange.ts +0 -10
  130. package/src/utils/segment.ts +0 -152
  131. package/src/utils/similars.ts +0 -35
  132. package/src/utils/simulationCache.ts +0 -73
  133. package/src/utils/sitemap.ts +0 -283
  134. package/src/utils/slugCache.ts +0 -28
  135. package/src/utils/slugify.ts +0 -13
  136. package/src/utils/transform.ts +0 -1691
  137. package/src/utils/vtexId.ts +0 -151
  138. package/src/vtexClient.test.ts +0 -204
  139. package/tsconfig.json +0 -7
@@ -1,333 +0,0 @@
1
- /**
2
- * VTEX Authentication Actions
3
- *
4
- * Ported from deco-cx/apps vtex/actions/authentication/*.ts
5
- * Cookie forwarding happens automatically via RequestContext.responseHeaders.
6
- * @see https://github.com/deco-cx/apps/tree/main/vtex/actions/authentication
7
- */
8
-
9
- import { getVtexConfig, vtexFetchWithCookies } from "../client";
10
- import { VTEX_AUTH_COOKIE } from "../utils/vtexId";
11
-
12
- // ---------------------------------------------------------------------------
13
- // Types
14
- // ---------------------------------------------------------------------------
15
-
16
- export interface AuthProvider {
17
- providerName: string;
18
- className: string;
19
- expectedContext: unknown[];
20
- }
21
-
22
- export interface StartAuthentication {
23
- authenticationToken: string | null;
24
- oauthProviders: AuthProvider[];
25
- showClassicAuthentication: boolean;
26
- showAccessKeyAuthentication: boolean;
27
- showPasskeyAuthentication: boolean;
28
- authCookie: string | null;
29
- isAuthenticated: boolean;
30
- selectedProvider: string | null;
31
- samlProviders: unknown[];
32
- }
33
-
34
- export interface AuthResponse {
35
- authStatus: string | "WrongCredentials" | "BlockedUser" | "Success";
36
- promptMFA: boolean;
37
- clientToken: string | null;
38
- authCookie: { Name: string; Value: string } | null;
39
- accountAuthCookie: { Name: string; Value: string } | null;
40
- expiresIn: number;
41
- userId: string | null;
42
- phoneNumber: string | null;
43
- scope: string | null;
44
- }
45
-
46
- export interface RefreshTokenResponse {
47
- status: string;
48
- userId: string;
49
- refreshAfter: string;
50
- }
51
-
52
- /**
53
- * Cookies to set after a successful login.
54
- * Caller (server function) should use these to set cookies on the response.
55
- */
56
- export interface LoginCookies {
57
- authCookieName: string;
58
- authCookieValue: string;
59
- accountAuthCookieName?: string;
60
- accountAuthCookieValue?: string;
61
- expiresInSeconds: number;
62
- }
63
-
64
- // ---------------------------------------------------------------------------
65
- // Helpers
66
- // ---------------------------------------------------------------------------
67
-
68
- const FORM_HEADERS = {
69
- "Content-Type": "application/x-www-form-urlencoded",
70
- Accept: "application/json",
71
- };
72
-
73
- /**
74
- * Extract login cookies from an AuthResponse.
75
- * Returns null if auth failed.
76
- */
77
- export function extractLoginCookies(response: AuthResponse): LoginCookies | null {
78
- if (response.authStatus !== "Success" || !response.authCookie) {
79
- return null;
80
- }
81
- return {
82
- authCookieName: response.authCookie.Name,
83
- authCookieValue: response.authCookie.Value,
84
- accountAuthCookieName: response.accountAuthCookie?.Name,
85
- accountAuthCookieValue: response.accountAuthCookie?.Value,
86
- expiresInSeconds: response.expiresIn,
87
- };
88
- }
89
-
90
- // ---------------------------------------------------------------------------
91
- // Actions
92
- // ---------------------------------------------------------------------------
93
-
94
- export interface StartAuthenticationProps {
95
- callbackUrl?: string;
96
- returnUrl?: string;
97
- locale?: string;
98
- appStart?: boolean;
99
- }
100
-
101
- export async function startAuthentication(
102
- props?: StartAuthenticationProps,
103
- ): Promise<StartAuthentication> {
104
- const config = getVtexConfig();
105
- const {
106
- callbackUrl = "/",
107
- returnUrl = "/",
108
- locale = config.locale ?? "pt-BR",
109
- appStart = true,
110
- } = props ?? {};
111
-
112
- const params = new URLSearchParams({
113
- locale,
114
- scope: config.account,
115
- appStart: String(appStart),
116
- callbackUrl,
117
- returnUrl,
118
- });
119
-
120
- return vtexFetchWithCookies<StartAuthentication>(
121
- `/api/vtexid/pub/authentication/start?${params}`,
122
- );
123
- }
124
-
125
- export interface ClassicSignInProps {
126
- email: string;
127
- password: string;
128
- authenticationToken?: string;
129
- }
130
-
131
- /**
132
- * Classic email + password sign-in.
133
- * Calls startAuthentication internally if no authenticationToken provided.
134
- * Set-Cookie headers from both calls are forwarded via RequestContext.responseHeaders.
135
- */
136
- export async function classicSignIn(props: ClassicSignInProps): Promise<AuthResponse> {
137
- const { email, password } = props;
138
- let token = props.authenticationToken;
139
- if (!token) {
140
- const startResult = await startAuthentication();
141
- token = startResult.authenticationToken ?? undefined;
142
- if (!token) throw new Error("Failed to obtain authentication token from startAuthentication");
143
- }
144
-
145
- const body = new URLSearchParams({
146
- email,
147
- password,
148
- authenticationToken: token,
149
- });
150
- return vtexFetchWithCookies<AuthResponse>("/api/vtexid/pub/authentication/classic/validate", {
151
- method: "POST",
152
- body,
153
- headers: FORM_HEADERS,
154
- });
155
- }
156
-
157
- export interface AccessKeySignInProps {
158
- email: string;
159
- accessKey: string;
160
- authenticationToken: string;
161
- }
162
-
163
- /**
164
- * Passwordless sign-in via email access key.
165
- */
166
- export async function accessKeySignIn(props: AccessKeySignInProps): Promise<AuthResponse> {
167
- const { email, accessKey, authenticationToken } = props;
168
- const body = new URLSearchParams({
169
- login: email,
170
- accessKey,
171
- authenticationToken,
172
- });
173
-
174
- return vtexFetchWithCookies<AuthResponse>("/api/vtexid/pub/authentication/accesskey/validate", {
175
- method: "POST",
176
- body,
177
- headers: FORM_HEADERS,
178
- });
179
- }
180
-
181
- /**
182
- * Logout — returns list of cookie names that must be cleared (Max-Age=0).
183
- */
184
- export function logout(): { cookiesToClear: string[] } {
185
- const { account } = getVtexConfig();
186
- return {
187
- cookiesToClear: [
188
- VTEX_AUTH_COOKIE,
189
- `${VTEX_AUTH_COOKIE}_${account}`,
190
- "vid_rt",
191
- `vid_rt_${account}`,
192
- ],
193
- };
194
- }
195
-
196
- export interface RefreshTokenProps {
197
- fingerprint?: string;
198
- }
199
-
200
- /**
201
- * Refreshes the VTEX auth token using existing session cookies.
202
- * Cookies are read automatically from RequestContext.
203
- */
204
- export async function refreshToken(props?: RefreshTokenProps): Promise<RefreshTokenResponse> {
205
- return vtexFetchWithCookies<RefreshTokenResponse>("/api/vtexid/refreshtoken/webstore", {
206
- method: "POST",
207
- body: JSON.stringify({ fingerprint: props?.fingerprint }),
208
- });
209
- }
210
-
211
- export interface RecoveryPasswordProps {
212
- email: string;
213
- newPassword: string;
214
- accessKey: string;
215
- authenticationToken: string;
216
- locale?: string;
217
- }
218
-
219
- /**
220
- * Sets a new password using an email access key (password-recovery flow).
221
- */
222
- export async function recoveryPassword(props: RecoveryPasswordProps): Promise<AuthResponse> {
223
- const { email, newPassword, accessKey, authenticationToken, locale } = props;
224
- const config = getVtexConfig();
225
-
226
- const params = new URLSearchParams({
227
- scope: config.account,
228
- locale: locale ?? config.locale ?? "pt-BR",
229
- });
230
-
231
- const body = new URLSearchParams({
232
- login: email,
233
- accessKey,
234
- newPassword,
235
- authenticationToken,
236
- });
237
-
238
- return vtexFetchWithCookies<AuthResponse>(
239
- `/api/vtexid/pub/authentication/classic/setpassword?${params}`,
240
- { method: "POST", body, headers: FORM_HEADERS },
241
- );
242
- }
243
-
244
- export interface ResetPasswordProps {
245
- email: string;
246
- currentPassword: string;
247
- newPassword: string;
248
- authenticationToken?: string;
249
- locale?: string;
250
- }
251
-
252
- /**
253
- * Resets password for an already-authenticated user.
254
- * Calls startAuthentication internally if no authenticationToken provided.
255
- * Set-Cookie headers from both calls are forwarded via RequestContext.responseHeaders.
256
- */
257
- export async function resetPassword(props: ResetPasswordProps): Promise<AuthResponse> {
258
- const { email, currentPassword, newPassword, locale } = props;
259
- const config = getVtexConfig();
260
-
261
- let token = props.authenticationToken;
262
- if (!token) {
263
- const startResult = await startAuthentication({ locale });
264
- token = startResult.authenticationToken ?? undefined;
265
- if (!token) throw new Error("Failed to obtain authentication token from startAuthentication");
266
- }
267
-
268
- const params = new URLSearchParams({
269
- scope: config.account,
270
- locale: locale ?? config.locale ?? "pt-BR",
271
- });
272
-
273
- const body = new URLSearchParams({
274
- login: email,
275
- currentPassword,
276
- newPassword,
277
- authenticationToken: token,
278
- });
279
-
280
- return vtexFetchWithCookies<AuthResponse>(
281
- `/api/vtexid/pub/authentication/classic/setpassword?${params}`,
282
- { method: "POST", body, headers: FORM_HEADERS },
283
- );
284
- }
285
-
286
- export interface SendEmailVerificationProps {
287
- email: string;
288
- authenticationToken?: string;
289
- locale?: string;
290
- parentAppId?: string;
291
- }
292
-
293
- /**
294
- * Sends an access-key verification email.
295
- * Calls startAuthentication internally if no authenticationToken provided.
296
- * Returns { success, authenticationToken }.
297
- */
298
- export async function sendEmailVerification(props: SendEmailVerificationProps): Promise<{
299
- success: boolean;
300
- authenticationToken: string | null;
301
- }> {
302
- const { email, locale, parentAppId } = props;
303
- try {
304
- let token = props.authenticationToken;
305
-
306
- if (!token) {
307
- const startResult = await startAuthentication({ locale });
308
- token = startResult.authenticationToken ?? undefined;
309
- if (!token) throw new Error("Failed to obtain authentication token");
310
- }
311
-
312
- const body = new URLSearchParams({ authenticationToken: token, email });
313
- if (locale) body.append("locale", locale);
314
- if (parentAppId) body.append("parentAppId", parentAppId);
315
-
316
- const result = await vtexFetchWithCookies<Record<string, string>>(
317
- "/api/vtexid/pub/authentication/accesskey/send?deliveryMethod=email",
318
- { method: "POST", body, headers: FORM_HEADERS },
319
- );
320
-
321
- if (result?.authStatus === "InvalidToken") {
322
- throw new Error("Authentication token is invalid");
323
- }
324
-
325
- return {
326
- success: true,
327
- authenticationToken: token,
328
- };
329
- } catch (error) {
330
- console.error("[sendEmailVerification]", error);
331
- return { success: false, authenticationToken: null };
332
- }
333
- }