@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,85 +0,0 @@
1
- /**
2
- * VTEX Sessions API actions.
3
- * Cookie forwarding happens automatically via RequestContext.responseHeaders.
4
- */
5
-
6
- import { getVtexConfig, vtexFetchWithCookies, vtexIOGraphQL } from "../client";
7
- import { buildAuthCookieHeader } from "../utils/vtexId";
8
-
9
- // ---------------------------------------------------------------------------
10
- // createSession
11
- // ---------------------------------------------------------------------------
12
-
13
- export interface SessionData {
14
- id: string;
15
- namespaces: Record<string, Record<string, { value: string }>>;
16
- }
17
-
18
- export interface CreateSessionProps {
19
- data: Record<string, any>;
20
- }
21
-
22
- export async function createSession(props: CreateSessionProps): Promise<SessionData> {
23
- const { data } = props;
24
- return vtexFetchWithCookies<SessionData>("/api/sessions", {
25
- method: "POST",
26
- body: JSON.stringify(data),
27
- });
28
- }
29
-
30
- // ---------------------------------------------------------------------------
31
- // editSession
32
- // ---------------------------------------------------------------------------
33
-
34
- export interface EditSessionResponse {
35
- id: string;
36
- namespaces: Record<string, Record<string, { value: string }>>;
37
- }
38
-
39
- export interface EditSessionProps {
40
- public: Record<string, { value: string }>;
41
- }
42
-
43
- /**
44
- * Edit the current VTEX session (public properties).
45
- */
46
- export async function editSession(props: EditSessionProps): Promise<EditSessionResponse> {
47
- return vtexFetchWithCookies<EditSessionResponse>("/api/sessions", {
48
- method: "PATCH",
49
- body: JSON.stringify({ public: { ...props.public } }),
50
- });
51
- }
52
-
53
- // ---------------------------------------------------------------------------
54
- // deleteSession
55
- // ---------------------------------------------------------------------------
56
-
57
- export interface DeleteSessionResponse {
58
- logOutFromSession: string;
59
- }
60
-
61
- const DELETE_SESSION_MUTATION = `mutation LogOutFromSession($sessionId: ID) {
62
- logOutFromSession(sessionId: $sessionId) @context(provider: "vtex.store-graphql@2.x")
63
- }`;
64
-
65
- export interface DeleteSessionProps {
66
- sessionId: string;
67
- authCookie: string;
68
- }
69
-
70
- /**
71
- * Log out / delete a VTEX session via the store-graphql mutation.
72
- * Requires a valid auth cookie.
73
- */
74
- export async function deleteSession(props: DeleteSessionProps): Promise<DeleteSessionResponse> {
75
- const { sessionId, authCookie } = props;
76
- if (!authCookie) throw new Error("Auth cookie is required to delete session");
77
- const { account } = getVtexConfig();
78
- return vtexIOGraphQL<DeleteSessionResponse>(
79
- {
80
- query: DELETE_SESSION_MUTATION,
81
- variables: { sessionId },
82
- },
83
- { cookie: buildAuthCookieHeader(authCookie, account) },
84
- );
85
- }
@@ -1,43 +0,0 @@
1
- /**
2
- * VTEX SKU change notification (trigger/webhook) types.
3
- *
4
- * Ported from `vtex/_to-port/actions/trigger.ts`.
5
- * The original Deco action forwarded the payload to a Durable Object workflow.
6
- * Actual webhook handling is framework-specific, so we only export the
7
- * canonical payload interface and a handler signature type here.
8
- */
9
-
10
- /** Payload sent by VTEX when a SKU changes in the catalog. */
11
- export interface VTEXNotificationPayload {
12
- /** SKU ID in VTEX. */
13
- IdSku: string;
14
- /** Seller's account name in VTEX (visible in the store's Admin URL). */
15
- An: string;
16
- /** Affiliate ID generated automatically in the configuration. */
17
- IdAffiliate: string;
18
- /** Product ID in VTEX. */
19
- ProductId: number;
20
- /** Date when the item was updated. */
21
- DateModified: string;
22
- /**
23
- * Whether the product is active. `false` means the product was
24
- * deactivated and should be blocked / zeroed in the marketplace.
25
- */
26
- IsActive: boolean;
27
- /** Inventory level has changed -- run a Fulfillment Simulation to refresh. */
28
- StockModified: boolean;
29
- /** Price has changed -- run a Fulfillment Simulation to refresh. */
30
- PriceModified: boolean;
31
- /** Product/SKU registration data changed (name, description, weight, etc.). */
32
- HasStockKeepingUnitModified: boolean;
33
- /** Product is no longer associated with the trade policy. */
34
- HasStockKeepingUnitRemovedFromAffiliate: boolean;
35
- }
36
-
37
- /**
38
- * Generic handler signature for the VTEX trigger webhook.
39
- * Implement this in your framework layer (e.g. TanStack Start API route).
40
- */
41
- export type VTEXTriggerHandler = (
42
- payload: VTEXNotificationPayload,
43
- ) => Promise<{ id: string } | undefined>;
@@ -1,114 +0,0 @@
1
- /**
2
- * VTEX Wishlist actions (wish-list graphql app).
3
- * Ported from deco-cx/apps:
4
- * - vtex/actions/wishlist/addItem.ts
5
- * - vtex/actions/wishlist/removeItem.ts
6
- * @see https://developers.vtex.com/docs/apps/vtex.wish-list
7
- */
8
- import { getVtexConfig, vtexIOGraphQL } from "../client";
9
- import { buildAuthCookieHeader } from "../utils/vtexId";
10
-
11
- /** Maximum wishlist items to fetch in a single query. */
12
- const WISHLIST_MAX_ITEMS = 500;
13
-
14
- // ---------------------------------------------------------------------------
15
- // Types
16
- // ---------------------------------------------------------------------------
17
-
18
- export interface WishlistItem {
19
- id?: string;
20
- productId: string;
21
- sku: string;
22
- title?: string;
23
- }
24
-
25
- // ---------------------------------------------------------------------------
26
- // GraphQL helper (myvtex.com private graphql)
27
- // ---------------------------------------------------------------------------
28
-
29
- function buildCookieHeader(authCookie: string): string {
30
- return buildAuthCookieHeader(authCookie, getVtexConfig().account);
31
- }
32
-
33
- // ---------------------------------------------------------------------------
34
- // Queries & Mutations
35
- // ---------------------------------------------------------------------------
36
-
37
- const ADD_TO_WISHLIST = `mutation AddToWishlist($listItem: ListItemInputType!, $shopperId: String!, $name: String!, $public: Boolean) {
38
- addToList(listItem: $listItem, shopperId: $shopperId, name: $name, public: $public) @context(provider: "vtex.wish-list@1.x")
39
- }`;
40
-
41
- const REMOVE_FROM_WISHLIST = `mutation RemoveFromList($id: ID!, $shopperId: String!, $name: String) {
42
- removeFromList(id: $id, shopperId: $shopperId, name: $name) @context(provider: "vtex.wish-list@1.x")
43
- }`;
44
-
45
- const VIEW_WISHLIST = `query ViewList($shopperId: String!, $name: String!, $from: Int!, $to: Int!) {
46
- viewList(shopperId: $shopperId, name: $name, from: $from, to: $to) @context(provider: "vtex.wish-list@1.x") {
47
- data { id productId sku title }
48
- }
49
- }`;
50
-
51
- // ---------------------------------------------------------------------------
52
- // Actions
53
- // ---------------------------------------------------------------------------
54
-
55
- async function fetchWishlist(shopperId: string, authCookie: string): Promise<WishlistItem[]> {
56
- const data = await vtexIOGraphQL<{
57
- viewList: { data: WishlistItem[] | null };
58
- }>(
59
- {
60
- query: VIEW_WISHLIST,
61
- variables: { shopperId, name: "Wishlist", from: 0, to: WISHLIST_MAX_ITEMS },
62
- },
63
- { Cookie: buildCookieHeader(authCookie) },
64
- );
65
- return data.viewList?.data ?? [];
66
- }
67
-
68
- /**
69
- * Add an item to the user's wishlist.
70
- * Returns the updated full wishlist.
71
- */
72
- export async function addItem(
73
- item: { productId: string; sku: string; title?: string },
74
- shopperId: string,
75
- authCookie: string,
76
- ): Promise<WishlistItem[]> {
77
- if (!authCookie) throw new Error("User must be logged in to add to wishlist");
78
- await vtexIOGraphQL<unknown>(
79
- {
80
- query: ADD_TO_WISHLIST,
81
- variables: {
82
- name: "Wishlist",
83
- shopperId,
84
- listItem: item,
85
- },
86
- },
87
- { Cookie: buildCookieHeader(authCookie) },
88
- );
89
- return fetchWishlist(shopperId, authCookie);
90
- }
91
-
92
- /**
93
- * Remove an item from the user's wishlist by its list-entry ID.
94
- * Returns the updated full wishlist.
95
- */
96
- export async function removeItem(
97
- id: string,
98
- shopperId: string,
99
- authCookie: string,
100
- ): Promise<WishlistItem[]> {
101
- if (!authCookie) throw new Error("User must be logged in to remove from wishlist");
102
- await vtexIOGraphQL<unknown>(
103
- {
104
- query: REMOVE_FROM_WISHLIST,
105
- variables: {
106
- id,
107
- name: "Wishlist",
108
- shopperId,
109
- },
110
- },
111
- { Cookie: buildCookieHeader(authCookie) },
112
- );
113
- return fetchWishlist(shopperId, authCookie);
114
- }