@decocms/apps 0.23.3 → 0.25.0
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/LICENSE +21 -0
- package/commerce/components/Image.tsx +129 -143
- package/commerce/components/JsonLd.tsx +192 -201
- package/commerce/components/Picture.tsx +65 -75
- package/commerce/sdk/analytics.ts +15 -15
- package/commerce/sdk/formatPrice.ts +13 -16
- package/commerce/sdk/url.ts +7 -7
- package/commerce/sdk/useOffer.ts +46 -57
- package/commerce/sdk/useVariantPossibilities.ts +25 -25
- package/commerce/types/commerce.ts +868 -875
- package/commerce/utils/canonical.ts +5 -8
- package/commerce/utils/constants.ts +5 -6
- package/commerce/utils/filters.ts +4 -4
- package/commerce/utils/productToAnalyticsItem.ts +52 -56
- package/commerce/utils/stateByZip.ts +42 -42
- package/package.json +24 -4
- package/shopify/actions/cart/addItems.ts +24 -25
- package/shopify/actions/cart/updateCoupons.ts +19 -20
- package/shopify/actions/cart/updateItems.ts +19 -20
- package/shopify/actions/user/signIn.ts +25 -30
- package/shopify/actions/user/signUp.ts +19 -24
- package/shopify/client.ts +24 -24
- package/shopify/index.ts +20 -18
- package/shopify/init.ts +18 -21
- package/shopify/loaders/ProductDetailsPage.ts +16 -20
- package/shopify/loaders/ProductList.ts +66 -69
- package/shopify/loaders/ProductListingPage.ts +150 -158
- package/shopify/loaders/RelatedProducts.ts +24 -27
- package/shopify/loaders/cart.ts +53 -52
- package/shopify/loaders/shop.ts +22 -27
- package/shopify/loaders/user.ts +27 -32
- package/shopify/utils/admin/admin.ts +33 -34
- package/shopify/utils/admin/queries.ts +2 -2
- package/shopify/utils/cart.ts +18 -14
- package/shopify/utils/cookies.ts +62 -65
- package/shopify/utils/enums.ts +424 -424
- package/shopify/utils/graphql.ts +44 -55
- package/shopify/utils/storefront/queries.ts +24 -29
- package/shopify/utils/storefront/storefront.graphql.gen.ts +55 -55
- package/shopify/utils/transform.ts +370 -376
- package/shopify/utils/types.ts +118 -118
- package/shopify/utils/user.ts +11 -11
- package/shopify/utils/utils.ts +135 -140
- package/vtex/actions/address.ts +86 -86
- package/vtex/actions/auth.ts +14 -27
- package/vtex/actions/checkout.ts +36 -49
- package/vtex/actions/masterData.ts +10 -27
- package/vtex/actions/misc.ts +101 -111
- package/vtex/actions/newsletter.ts +48 -52
- package/vtex/actions/orders.ts +13 -16
- package/vtex/actions/profile.ts +55 -55
- package/vtex/actions/session.ts +36 -35
- package/vtex/actions/trigger.ts +25 -25
- package/vtex/actions/wishlist.ts +51 -53
- package/vtex/client.ts +14 -42
- package/vtex/hooks/index.ts +4 -4
- package/vtex/hooks/useAutocomplete.ts +42 -48
- package/vtex/hooks/useCart.ts +153 -165
- package/vtex/hooks/useUser.ts +40 -40
- package/vtex/hooks/useWishlist.ts +70 -70
- package/vtex/inline-loaders/productDetailsPage.ts +1 -3
- package/vtex/inline-loaders/productList.ts +121 -127
- package/vtex/inline-loaders/productListShelf.ts +159 -0
- package/vtex/inline-loaders/productListingPage.ts +10 -34
- package/vtex/inline-loaders/relatedProducts.ts +1 -3
- package/vtex/inline-loaders/suggestions.ts +36 -39
- package/vtex/inline-loaders/workflowProducts.ts +45 -49
- package/vtex/invoke.ts +159 -194
- package/vtex/loaders/address.ts +49 -54
- package/vtex/loaders/brands.ts +19 -26
- package/vtex/loaders/cart.ts +24 -21
- package/vtex/loaders/catalog.ts +51 -53
- package/vtex/loaders/collections.ts +25 -27
- package/vtex/loaders/legacy.ts +487 -534
- package/vtex/loaders/logistics.ts +33 -37
- package/vtex/loaders/navbar.ts +5 -8
- package/vtex/loaders/orders.ts +28 -39
- package/vtex/loaders/pageType.ts +41 -35
- package/vtex/loaders/payment.ts +27 -37
- package/vtex/loaders/profile.ts +38 -38
- package/vtex/loaders/promotion.ts +5 -8
- package/vtex/loaders/search.ts +56 -59
- package/vtex/loaders/session.ts +22 -30
- package/vtex/loaders/user.ts +39 -41
- package/vtex/loaders/wishlist.ts +35 -35
- package/vtex/loaders/wishlistProducts.ts +3 -15
- package/vtex/loaders/workflow.ts +220 -227
- package/vtex/middleware.ts +116 -119
- package/vtex/types.ts +201 -201
- package/vtex/utils/batch.ts +13 -16
- package/vtex/utils/cookies.ts +76 -80
- package/vtex/utils/enrichment.ts +62 -42
- package/vtex/utils/fetchCache.ts +1 -4
- package/vtex/utils/index.ts +6 -6
- package/vtex/utils/intelligentSearch.ts +48 -57
- package/vtex/utils/legacy.ts +108 -124
- package/vtex/utils/pickAndOmit.ts +15 -20
- package/vtex/utils/proxy.ts +136 -146
- package/vtex/utils/resourceRange.ts +3 -3
- package/vtex/utils/segment.ts +100 -111
- package/vtex/utils/similars.ts +1 -2
- package/vtex/utils/sitemap.ts +91 -91
- package/vtex/utils/slugCache.ts +2 -6
- package/vtex/utils/slugify.ts +9 -9
- package/vtex/utils/transform.ts +1178 -1105
- package/vtex/utils/types.ts +1381 -1381
- package/vtex/utils/vtexId.ts +44 -47
- package/.github/workflows/release.yml +0 -34
- package/.releaserc.json +0 -28
- package/knip.json +0 -19
- package/tsconfig.json +0 -11
|
@@ -2,67 +2,63 @@
|
|
|
2
2
|
* Workflow/collection products loader using Intelligent Search + shared transform.
|
|
3
3
|
* Maps IS response to schema.org Product[] following deco-cx/apps pattern.
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
import { toProduct, pickSku } from "../utils/transform";
|
|
7
|
-
import type { Product as ProductVTEX } from "../utils/types";
|
|
5
|
+
|
|
8
6
|
import type { Product } from "../../commerce/types/commerce";
|
|
7
|
+
import { getVtexConfig, intelligentSearch, toFacetPath } from "../client";
|
|
8
|
+
import { pickSku, toProduct } from "../utils/transform";
|
|
9
|
+
import type { Product as ProductVTEX } from "../utils/types";
|
|
9
10
|
|
|
10
11
|
export interface WorkflowProductsProps {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
props?: {
|
|
13
|
+
query?: string;
|
|
14
|
+
count?: number;
|
|
15
|
+
sort?: string;
|
|
16
|
+
collection?: string;
|
|
17
|
+
};
|
|
18
|
+
page?: number;
|
|
19
|
+
pagesize?: number;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export default async function vtexWorkflowProducts(
|
|
22
|
-
|
|
23
|
+
props: WorkflowProductsProps,
|
|
23
24
|
): Promise<Product[] | null> {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
const inner = props.props ?? props;
|
|
26
|
+
const collection = (inner as any).collection;
|
|
27
|
+
const query = (inner as any).query ?? "";
|
|
28
|
+
const count = (inner as any).count ?? props.pagesize ?? 12;
|
|
29
|
+
const sort = (inner as any).sort ?? "";
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
try {
|
|
32
|
+
const config = getVtexConfig();
|
|
33
|
+
const locale = config.locale ?? "pt-BR";
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
const params: Record<string, string> = {
|
|
36
|
+
count: String(count),
|
|
37
|
+
locale,
|
|
38
|
+
page: String((props.page ?? 0) + 1),
|
|
39
|
+
};
|
|
40
|
+
if (query) params.query = query;
|
|
41
|
+
if (sort) params.sort = sort;
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
const facetPath = collection
|
|
44
|
+
? toFacetPath([{ key: "productClusterIds", value: collection }])
|
|
45
|
+
: "";
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
? `/product_search/${facetPath}`
|
|
48
|
-
: "/product_search/";
|
|
47
|
+
const endpoint = facetPath ? `/product_search/${facetPath}` : "/product_search/";
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
endpoint,
|
|
52
|
-
params,
|
|
53
|
-
);
|
|
49
|
+
const data = await intelligentSearch<{ products: ProductVTEX[] }>(endpoint, params);
|
|
54
50
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
const products = data.products ?? [];
|
|
52
|
+
const baseUrl = config.publicUrl
|
|
53
|
+
? `https://${config.publicUrl}`
|
|
54
|
+
: `https://${config.account}.vtexcommercestable.${config.domain ?? "com.br"}`;
|
|
59
55
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
56
|
+
return products.map((p) => {
|
|
57
|
+
const sku = pickSku(p);
|
|
58
|
+
return toProduct(p, sku, 0, { baseUrl, priceCurrency: "BRL" });
|
|
59
|
+
});
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.error("[VTEX] Workflow products error:", error);
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
68
64
|
}
|
package/vtex/invoke.ts
CHANGED
|
@@ -22,210 +22,175 @@
|
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
import { createInvokeFn } from "@decocms/start/sdk/createInvoke";
|
|
25
|
+
import type { RegionResult } from "./actions/checkout";
|
|
25
26
|
import {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
addCouponToCart,
|
|
28
|
+
addItemsToCart,
|
|
29
|
+
getOrCreateCart,
|
|
30
|
+
getSellersByRegion,
|
|
31
|
+
type SimulationItem,
|
|
32
|
+
setShippingPostalCode,
|
|
33
|
+
simulateCart,
|
|
34
|
+
updateCartItems,
|
|
35
|
+
updateOrderFormAttachment,
|
|
35
36
|
} from "./actions/checkout";
|
|
36
37
|
import {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
type CreateDocumentResult,
|
|
39
|
+
createDocument,
|
|
40
|
+
getDocument,
|
|
41
|
+
patchDocument,
|
|
42
|
+
searchDocuments,
|
|
43
|
+
type UploadAttachmentOpts,
|
|
44
|
+
uploadAttachment,
|
|
44
45
|
} from "./actions/masterData";
|
|
46
|
+
import { type NotifyMeProps, notifyMe } from "./actions/misc";
|
|
47
|
+
import { type SubscribeProps, subscribe } from "./actions/newsletter";
|
|
45
48
|
import { createSession, editSession, type SessionData } from "./actions/session";
|
|
46
|
-
import { subscribe, type SubscribeProps } from "./actions/newsletter";
|
|
47
|
-
import { notifyMe, type NotifyMeProps } from "./actions/misc";
|
|
48
49
|
import type { OrderForm } from "./types";
|
|
49
|
-
import type { RegionResult } from "./actions/checkout";
|
|
50
50
|
|
|
51
51
|
// ---------------------------------------------------------------------------
|
|
52
52
|
// invoke.vtex.actions — typed server functions callable from client
|
|
53
53
|
// ---------------------------------------------------------------------------
|
|
54
54
|
|
|
55
55
|
export const invoke = {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
documentId: string;
|
|
197
|
-
data: Record<string, any>;
|
|
198
|
-
}) => patchDocument(input.entity, input.documentId, input.data),
|
|
199
|
-
) as (ctx: {
|
|
200
|
-
data: {
|
|
201
|
-
entity: string;
|
|
202
|
-
documentId: string;
|
|
203
|
-
data: Record<string, any>;
|
|
204
|
-
};
|
|
205
|
-
}) => Promise<void>,
|
|
206
|
-
|
|
207
|
-
searchDocuments: createInvokeFn(
|
|
208
|
-
(input: { entity: string; filter: string }) =>
|
|
209
|
-
searchDocuments(input.entity, input.filter),
|
|
210
|
-
),
|
|
211
|
-
|
|
212
|
-
uploadAttachment: createInvokeFn(
|
|
213
|
-
(input: UploadAttachmentOpts) => uploadAttachment(input),
|
|
214
|
-
) as (ctx: {
|
|
215
|
-
data: UploadAttachmentOpts;
|
|
216
|
-
}) => Promise<{ ok: true }>,
|
|
217
|
-
|
|
218
|
-
// -- Newsletter -------------------------------------------------------
|
|
219
|
-
|
|
220
|
-
subscribe: createInvokeFn(
|
|
221
|
-
(input: SubscribeProps) => subscribe(input),
|
|
222
|
-
) as (ctx: { data: SubscribeProps }) => Promise<void>,
|
|
223
|
-
|
|
224
|
-
// -- Misc -------------------------------------------------------------
|
|
225
|
-
|
|
226
|
-
notifyMe: createInvokeFn(
|
|
227
|
-
(input: NotifyMeProps) => notifyMe(input),
|
|
228
|
-
) as (ctx: { data: NotifyMeProps }) => Promise<void>,
|
|
229
|
-
},
|
|
230
|
-
},
|
|
56
|
+
vtex: {
|
|
57
|
+
actions: {
|
|
58
|
+
// -- Cart (unwrap VtexFetchResult -> OrderForm) -----------------------
|
|
59
|
+
|
|
60
|
+
getOrCreateCart: createInvokeFn(
|
|
61
|
+
(input: { orderFormId?: string }) => getOrCreateCart(input.orderFormId),
|
|
62
|
+
{ unwrap: true },
|
|
63
|
+
) as unknown as (ctx: { data: { orderFormId?: string } }) => Promise<OrderForm>,
|
|
64
|
+
|
|
65
|
+
addItemsToCart: createInvokeFn(
|
|
66
|
+
(input: {
|
|
67
|
+
orderFormId: string;
|
|
68
|
+
orderItems: Array<{
|
|
69
|
+
id: string;
|
|
70
|
+
seller: string;
|
|
71
|
+
quantity: number;
|
|
72
|
+
}>;
|
|
73
|
+
}) => addItemsToCart(input.orderFormId, input.orderItems),
|
|
74
|
+
{ unwrap: true },
|
|
75
|
+
) as unknown as (ctx: {
|
|
76
|
+
data: {
|
|
77
|
+
orderFormId: string;
|
|
78
|
+
orderItems: Array<{
|
|
79
|
+
id: string;
|
|
80
|
+
seller: string;
|
|
81
|
+
quantity: number;
|
|
82
|
+
}>;
|
|
83
|
+
};
|
|
84
|
+
}) => Promise<OrderForm>,
|
|
85
|
+
|
|
86
|
+
updateCartItems: createInvokeFn(
|
|
87
|
+
(input: { orderFormId: string; orderItems: Array<{ index: number; quantity: number }> }) =>
|
|
88
|
+
updateCartItems(input.orderFormId, input.orderItems),
|
|
89
|
+
{ unwrap: true },
|
|
90
|
+
) as unknown as (ctx: {
|
|
91
|
+
data: {
|
|
92
|
+
orderFormId: string;
|
|
93
|
+
orderItems: Array<{ index: number; quantity: number }>;
|
|
94
|
+
};
|
|
95
|
+
}) => Promise<OrderForm>,
|
|
96
|
+
|
|
97
|
+
addCouponToCart: createInvokeFn(
|
|
98
|
+
(input: { orderFormId: string; text: string }) =>
|
|
99
|
+
addCouponToCart(input.orderFormId, input.text),
|
|
100
|
+
{ unwrap: true },
|
|
101
|
+
) as unknown as (ctx: { data: { orderFormId: string; text: string } }) => Promise<OrderForm>,
|
|
102
|
+
|
|
103
|
+
simulateCart: createInvokeFn(
|
|
104
|
+
(input: { items: SimulationItem[]; postalCode: string; country?: string }) =>
|
|
105
|
+
simulateCart(input.items, input.postalCode, input.country),
|
|
106
|
+
),
|
|
107
|
+
|
|
108
|
+
// -- Shipping / Region ------------------------------------------------
|
|
109
|
+
|
|
110
|
+
getSellersByRegion: createInvokeFn((input: { postalCode: string; salesChannel?: string }) =>
|
|
111
|
+
getSellersByRegion(input.postalCode, input.salesChannel),
|
|
112
|
+
) as (ctx: {
|
|
113
|
+
data: { postalCode: string; salesChannel?: string };
|
|
114
|
+
}) => Promise<RegionResult | null>,
|
|
115
|
+
|
|
116
|
+
setShippingPostalCode: createInvokeFn(
|
|
117
|
+
(input: { orderFormId: string; postalCode: string; country?: string }) =>
|
|
118
|
+
setShippingPostalCode(input.orderFormId, input.postalCode, input.country),
|
|
119
|
+
) as (ctx: {
|
|
120
|
+
data: {
|
|
121
|
+
orderFormId: string;
|
|
122
|
+
postalCode: string;
|
|
123
|
+
country?: string;
|
|
124
|
+
};
|
|
125
|
+
}) => Promise<boolean>,
|
|
126
|
+
|
|
127
|
+
updateOrderFormAttachment: createInvokeFn(
|
|
128
|
+
(input: { orderFormId: string; attachment: string; body: Record<string, unknown> }) =>
|
|
129
|
+
updateOrderFormAttachment(input.orderFormId, input.attachment, input.body),
|
|
130
|
+
{ unwrap: true },
|
|
131
|
+
) as unknown as (ctx: {
|
|
132
|
+
data: {
|
|
133
|
+
orderFormId: string;
|
|
134
|
+
attachment: string;
|
|
135
|
+
body: Record<string, unknown>;
|
|
136
|
+
};
|
|
137
|
+
}) => Promise<OrderForm>,
|
|
138
|
+
|
|
139
|
+
// -- Session ----------------------------------------------------------
|
|
140
|
+
|
|
141
|
+
createSession: createInvokeFn((input: Record<string, any>) => createSession(input), {
|
|
142
|
+
unwrap: true,
|
|
143
|
+
}),
|
|
144
|
+
|
|
145
|
+
editSession: createInvokeFn(
|
|
146
|
+
(input: { public: Record<string, { value: string }> }) => editSession(input.public),
|
|
147
|
+
{ unwrap: true },
|
|
148
|
+
) as unknown as (ctx: {
|
|
149
|
+
data: { public: Record<string, { value: string }> };
|
|
150
|
+
}) => Promise<SessionData>,
|
|
151
|
+
|
|
152
|
+
// -- MasterData -------------------------------------------------------
|
|
153
|
+
|
|
154
|
+
createDocument: createInvokeFn((input: { entity: string; data: Record<string, any> }) =>
|
|
155
|
+
createDocument(input.entity, input.data),
|
|
156
|
+
) as (ctx: {
|
|
157
|
+
data: { entity: string; data: Record<string, any> };
|
|
158
|
+
}) => Promise<CreateDocumentResult>,
|
|
159
|
+
|
|
160
|
+
getDocument: createInvokeFn((input: { entity: string; documentId: string }) =>
|
|
161
|
+
getDocument(input.entity, input.documentId),
|
|
162
|
+
),
|
|
163
|
+
|
|
164
|
+
patchDocument: createInvokeFn(
|
|
165
|
+
(input: { entity: string; documentId: string; data: Record<string, any> }) =>
|
|
166
|
+
patchDocument(input.entity, input.documentId, input.data),
|
|
167
|
+
) as (ctx: {
|
|
168
|
+
data: {
|
|
169
|
+
entity: string;
|
|
170
|
+
documentId: string;
|
|
171
|
+
data: Record<string, any>;
|
|
172
|
+
};
|
|
173
|
+
}) => Promise<void>,
|
|
174
|
+
|
|
175
|
+
searchDocuments: createInvokeFn((input: { entity: string; filter: string }) =>
|
|
176
|
+
searchDocuments(input.entity, input.filter),
|
|
177
|
+
),
|
|
178
|
+
|
|
179
|
+
uploadAttachment: createInvokeFn((input: UploadAttachmentOpts) =>
|
|
180
|
+
uploadAttachment(input),
|
|
181
|
+
) as (ctx: { data: UploadAttachmentOpts }) => Promise<{ ok: true }>,
|
|
182
|
+
|
|
183
|
+
// -- Newsletter -------------------------------------------------------
|
|
184
|
+
|
|
185
|
+
subscribe: createInvokeFn((input: SubscribeProps) => subscribe(input)) as (ctx: {
|
|
186
|
+
data: SubscribeProps;
|
|
187
|
+
}) => Promise<void>,
|
|
188
|
+
|
|
189
|
+
// -- Misc -------------------------------------------------------------
|
|
190
|
+
|
|
191
|
+
notifyMe: createInvokeFn((input: NotifyMeProps) => notifyMe(input)) as (ctx: {
|
|
192
|
+
data: NotifyMeProps;
|
|
193
|
+
}) => Promise<void>,
|
|
194
|
+
},
|
|
195
|
+
},
|
|
231
196
|
} as const;
|
package/vtex/loaders/address.ts
CHANGED
|
@@ -15,34 +15,34 @@ import { vtexFetch, vtexIOGraphQL } from "../client";
|
|
|
15
15
|
// ---------------------------------------------------------------------------
|
|
16
16
|
|
|
17
17
|
export interface PostalAddress {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
"@type": "PostalAddress";
|
|
19
|
+
postalCode?: string;
|
|
20
|
+
addressLocality?: string;
|
|
21
|
+
addressRegion?: string;
|
|
22
|
+
addressCountry?: string;
|
|
23
|
+
streetAddress?: string;
|
|
24
|
+
identifier?: string;
|
|
25
|
+
areaServed?: string;
|
|
26
|
+
description?: string;
|
|
27
|
+
disambiguatingDescription?: string;
|
|
28
|
+
latitude?: number;
|
|
29
|
+
longitude?: number;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export interface VtexAddress {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
addressId: string;
|
|
34
|
+
addressType: string;
|
|
35
|
+
addressName: string;
|
|
36
|
+
city: string;
|
|
37
|
+
complement: string;
|
|
38
|
+
country: string;
|
|
39
|
+
neighborhood: string;
|
|
40
|
+
number: string;
|
|
41
|
+
postalCode: string;
|
|
42
|
+
geoCoordinates: number[];
|
|
43
|
+
receiverName: string;
|
|
44
|
+
state: string;
|
|
45
|
+
street: string;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
// ---------------------------------------------------------------------------
|
|
@@ -54,27 +54,27 @@ export interface VtexAddress {
|
|
|
54
54
|
* @see https://developers.vtex.com/docs/api-reference/checkout-api#get-/api/checkout/pub/postal-code/-countryCode-/-postalCode-
|
|
55
55
|
*/
|
|
56
56
|
export async function getAddressByPostalCode(
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
countryCode: string,
|
|
58
|
+
postalCode: string,
|
|
59
59
|
): Promise<PostalAddress> {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
const data = await vtexFetch<Record<string, any>>(
|
|
61
|
+
`/api/checkout/pub/postal-code/${countryCode}/${postalCode}`,
|
|
62
|
+
);
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
64
|
+
return {
|
|
65
|
+
"@type": "PostalAddress",
|
|
66
|
+
postalCode: data.postalCode,
|
|
67
|
+
addressLocality: data.city,
|
|
68
|
+
addressRegion: data.state,
|
|
69
|
+
addressCountry: data.country,
|
|
70
|
+
streetAddress: data.street || undefined,
|
|
71
|
+
identifier: data.number || undefined,
|
|
72
|
+
areaServed: data.neighborhood || undefined,
|
|
73
|
+
description: data.complement || undefined,
|
|
74
|
+
disambiguatingDescription: data.reference || undefined,
|
|
75
|
+
latitude: data.geoCoordinates?.[0] ?? undefined,
|
|
76
|
+
longitude: data.geoCoordinates?.[1] ?? undefined,
|
|
77
|
+
};
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
// ---------------------------------------------------------------------------
|
|
@@ -106,15 +106,10 @@ const USER_ADDRESSES_QUERY = `query Addresses @context(scope: "private") {
|
|
|
106
106
|
* Fetch addresses for the currently authenticated user.
|
|
107
107
|
* Requires a valid VTEX auth cookie.
|
|
108
108
|
*/
|
|
109
|
-
export async function getUserAddresses(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
profile: { addresses: VtexAddress[] };
|
|
114
|
-
}>(
|
|
115
|
-
{ query: USER_ADDRESSES_QUERY },
|
|
116
|
-
{ cookie: authCookie },
|
|
117
|
-
);
|
|
109
|
+
export async function getUserAddresses(authCookie: string): Promise<VtexAddress[]> {
|
|
110
|
+
const { profile } = await vtexIOGraphQL<{
|
|
111
|
+
profile: { addresses: VtexAddress[] };
|
|
112
|
+
}>({ query: USER_ADDRESSES_QUERY }, { cookie: authCookie });
|
|
118
113
|
|
|
119
|
-
|
|
114
|
+
return profile?.addresses ?? [];
|
|
120
115
|
}
|