@decocms/apps 0.27.0 → 0.28.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/commerce/app-types.ts +62 -0
- package/commerce/manifest-utils.ts +38 -0
- package/commerce/resolve.ts +114 -0
- package/commerce/sdk/formatPrice.ts +1 -4
- package/package.json +11 -4
- package/resend/manifest.gen.ts +15 -0
- package/resend/mod.ts +33 -19
- package/shopify/index.ts +3 -0
- package/shopify/manifest.gen.ts +39 -0
- package/shopify/mod.ts +67 -0
- package/vtex/actions/auth.ts +77 -68
- package/vtex/actions/checkout.ts +224 -205
- package/vtex/actions/masterData.ts +32 -18
- package/vtex/actions/session.ts +20 -23
- package/vtex/client.ts +50 -76
- package/vtex/index.ts +2 -1
- package/vtex/manifest.gen.ts +75 -0
- package/vtex/mod.ts +83 -0
- package/vtex/invoke.ts +0 -196
package/vtex/actions/checkout.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* VTEX Checkout API actions.
|
|
3
|
-
*
|
|
3
|
+
* Each function receives a single props object — matching the invoke handler
|
|
4
|
+
* pattern from deco-cx/apps where `setupApps()` registers handlers directly.
|
|
4
5
|
*
|
|
5
6
|
* Ported from deco-cx/apps vtex/actions/cart/*.ts
|
|
6
7
|
* @see https://developers.vtex.com/docs/api-reference/checkout-api
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
|
-
import type { VtexFetchResult } from "../client";
|
|
10
10
|
import { getVtexConfig, vtexFetch, vtexFetchWithCookies } from "../client";
|
|
11
11
|
import type { OrderForm } from "../types";
|
|
12
12
|
|
|
@@ -54,21 +54,19 @@ function forceHttpsOnAssets(orderForm: OrderForm): OrderForm {
|
|
|
54
54
|
// Cart (OrderForm) — core CRUD
|
|
55
55
|
// ---------------------------------------------------------------------------
|
|
56
56
|
|
|
57
|
-
export
|
|
58
|
-
orderFormId?: string
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
export interface GetOrCreateCartProps {
|
|
58
|
+
orderFormId?: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function getOrCreateCart(props: GetOrCreateCartProps): Promise<OrderForm> {
|
|
62
|
+
const { orderFormId } = props;
|
|
61
63
|
const sc = scParam();
|
|
62
|
-
const headers: Record<string, string> = {};
|
|
63
|
-
if (cookieHeader) headers.cookie = cookieHeader;
|
|
64
64
|
|
|
65
65
|
if (orderFormId) {
|
|
66
66
|
const result = await vtexFetchWithCookies<OrderForm>(
|
|
67
67
|
`/api/checkout/pub/orderForm/${orderFormId}${sc ? `?${sc}` : ""}`,
|
|
68
|
-
{ headers },
|
|
69
68
|
);
|
|
70
|
-
|
|
71
|
-
return result;
|
|
69
|
+
return forceHttpsOnAssets(result);
|
|
72
70
|
}
|
|
73
71
|
const result = await vtexFetchWithCookies<OrderForm>(
|
|
74
72
|
`/api/checkout/pub/orderForm${sc ? `?${sc}` : ""}`,
|
|
@@ -77,96 +75,87 @@ export async function getOrCreateCart(
|
|
|
77
75
|
body: JSON.stringify({
|
|
78
76
|
expectedOrderFormSections: DEFAULT_EXPECTED_SECTIONS,
|
|
79
77
|
}),
|
|
80
|
-
headers,
|
|
81
78
|
},
|
|
82
79
|
);
|
|
83
|
-
|
|
84
|
-
return result;
|
|
80
|
+
return forceHttpsOnAssets(result);
|
|
85
81
|
}
|
|
86
82
|
|
|
87
|
-
export
|
|
88
|
-
orderFormId: string
|
|
83
|
+
export interface AddItemsToCartProps {
|
|
84
|
+
orderFormId: string;
|
|
89
85
|
orderItems: Array<{
|
|
90
86
|
id: string;
|
|
91
87
|
seller: string;
|
|
92
88
|
quantity: number;
|
|
93
89
|
index?: number;
|
|
94
90
|
price?: number;
|
|
95
|
-
}
|
|
96
|
-
allowedOutdatedData
|
|
97
|
-
|
|
98
|
-
|
|
91
|
+
}>;
|
|
92
|
+
allowedOutdatedData?: string[];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function addItemsToCart(props: AddItemsToCartProps): Promise<OrderForm> {
|
|
96
|
+
const { orderFormId, orderItems, allowedOutdatedData = ["paymentData"] } = props;
|
|
99
97
|
const params = appendSc(new URLSearchParams());
|
|
100
98
|
for (const d of allowedOutdatedData) params.append("allowedOutdatedData", d);
|
|
101
|
-
const headers: Record<string, string> = {};
|
|
102
|
-
if (cookieHeader) headers.cookie = cookieHeader;
|
|
103
99
|
const result = await vtexFetchWithCookies<OrderForm>(
|
|
104
100
|
`/api/checkout/pub/orderForm/${orderFormId}/items?${params}`,
|
|
105
|
-
{ method: "POST", body: JSON.stringify({ orderItems })
|
|
101
|
+
{ method: "POST", body: JSON.stringify({ orderItems }) },
|
|
106
102
|
);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
): Promise<VtexFetchResult<OrderForm>> {
|
|
103
|
+
return forceHttpsOnAssets(result);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface UpdateCartItemsProps {
|
|
107
|
+
orderFormId: string;
|
|
108
|
+
orderItems: Array<{ index: number; quantity: number }>;
|
|
109
|
+
allowedOutdatedData?: string[];
|
|
110
|
+
noSplitItem?: boolean;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function updateCartItems(props: UpdateCartItemsProps): Promise<OrderForm> {
|
|
114
|
+
const { orderFormId, orderItems, allowedOutdatedData = ["paymentData"], noSplitItem } = props;
|
|
120
115
|
const params = appendSc(new URLSearchParams());
|
|
121
|
-
for (const d of
|
|
116
|
+
for (const d of allowedOutdatedData) {
|
|
122
117
|
params.append("allowedOutdatedData", d);
|
|
123
118
|
}
|
|
124
|
-
const headers: Record<string, string> = {};
|
|
125
|
-
if (opts?.cookieHeader) headers.cookie = opts.cookieHeader;
|
|
126
119
|
const result = await vtexFetchWithCookies<OrderForm>(
|
|
127
120
|
`/api/checkout/pub/orderForm/${orderFormId}/items/update?${params}`,
|
|
128
121
|
{
|
|
129
122
|
method: "POST",
|
|
130
123
|
body: JSON.stringify({
|
|
131
124
|
orderItems,
|
|
132
|
-
noSplitItem: Boolean(
|
|
125
|
+
noSplitItem: Boolean(noSplitItem),
|
|
133
126
|
}),
|
|
134
|
-
headers,
|
|
135
127
|
},
|
|
136
128
|
);
|
|
137
|
-
|
|
138
|
-
|
|
129
|
+
return forceHttpsOnAssets(result);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface RemoveAllItemsProps {
|
|
133
|
+
orderFormId: string;
|
|
139
134
|
}
|
|
140
135
|
|
|
141
|
-
export async function removeAllItems(
|
|
142
|
-
orderFormId
|
|
143
|
-
cookieHeader?: string,
|
|
144
|
-
): Promise<VtexFetchResult<OrderForm>> {
|
|
136
|
+
export async function removeAllItems(props: RemoveAllItemsProps): Promise<OrderForm> {
|
|
137
|
+
const { orderFormId } = props;
|
|
145
138
|
const sc = scParam();
|
|
146
|
-
const headers: Record<string, string> = {};
|
|
147
|
-
if (cookieHeader) headers.cookie = cookieHeader;
|
|
148
139
|
const result = await vtexFetchWithCookies<OrderForm>(
|
|
149
140
|
`/api/checkout/pub/orderForm/${orderFormId}/items/removeAll${sc ? `?${sc}` : ""}`,
|
|
150
|
-
{ method: "POST", body: JSON.stringify({})
|
|
141
|
+
{ method: "POST", body: JSON.stringify({}) },
|
|
151
142
|
);
|
|
152
|
-
|
|
153
|
-
return result;
|
|
143
|
+
return forceHttpsOnAssets(result);
|
|
154
144
|
}
|
|
155
145
|
|
|
156
|
-
export
|
|
157
|
-
orderFormId: string
|
|
158
|
-
text: string
|
|
159
|
-
|
|
160
|
-
|
|
146
|
+
export interface AddCouponToCartProps {
|
|
147
|
+
orderFormId: string;
|
|
148
|
+
text: string;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export async function addCouponToCart(props: AddCouponToCartProps): Promise<OrderForm> {
|
|
152
|
+
const { orderFormId, text } = props;
|
|
161
153
|
const sc = scParam();
|
|
162
|
-
const headers: Record<string, string> = {};
|
|
163
|
-
if (cookieHeader) headers.cookie = cookieHeader;
|
|
164
154
|
const result = await vtexFetchWithCookies<OrderForm>(
|
|
165
155
|
`/api/checkout/pub/orderForm/${orderFormId}/coupons${sc ? `?${sc}` : ""}`,
|
|
166
|
-
{ method: "POST", body: JSON.stringify({ text })
|
|
156
|
+
{ method: "POST", body: JSON.stringify({ text }) },
|
|
167
157
|
);
|
|
168
|
-
|
|
169
|
-
return result;
|
|
158
|
+
return forceHttpsOnAssets(result);
|
|
170
159
|
}
|
|
171
160
|
|
|
172
161
|
// ---------------------------------------------------------------------------
|
|
@@ -179,17 +168,17 @@ export interface SimulationItem {
|
|
|
179
168
|
seller: string;
|
|
180
169
|
}
|
|
181
170
|
|
|
182
|
-
export
|
|
183
|
-
items: SimulationItem[]
|
|
184
|
-
postalCode: string
|
|
185
|
-
country?: string
|
|
186
|
-
RnbBehavior
|
|
187
|
-
|
|
188
|
-
|
|
171
|
+
export interface SimulateCartProps {
|
|
172
|
+
items: SimulationItem[];
|
|
173
|
+
postalCode: string;
|
|
174
|
+
country?: string;
|
|
175
|
+
RnbBehavior?: 0 | 1;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export async function simulateCart(props: SimulateCartProps) {
|
|
179
|
+
const { items, postalCode, country, RnbBehavior = 1 } = props;
|
|
189
180
|
const config = getVtexConfig();
|
|
190
181
|
const params = appendSc(new URLSearchParams({ RnbBehavior: String(RnbBehavior) }));
|
|
191
|
-
const headers: Record<string, string> = {};
|
|
192
|
-
if (cookieHeader) headers.cookie = cookieHeader;
|
|
193
182
|
return vtexFetch<any>(`/api/checkout/pub/orderForms/simulation?${params}`, {
|
|
194
183
|
method: "POST",
|
|
195
184
|
body: JSON.stringify({
|
|
@@ -197,7 +186,6 @@ export async function simulateCart(
|
|
|
197
186
|
postalCode,
|
|
198
187
|
country: country ?? config.country ?? "BRA",
|
|
199
188
|
}),
|
|
200
|
-
headers,
|
|
201
189
|
});
|
|
202
190
|
}
|
|
203
191
|
|
|
@@ -205,15 +193,20 @@ export async function simulateCart(
|
|
|
205
193
|
// Cart — offerings (services attached to items)
|
|
206
194
|
// ---------------------------------------------------------------------------
|
|
207
195
|
|
|
208
|
-
export
|
|
209
|
-
orderFormId: string
|
|
210
|
-
itemIndex: number
|
|
211
|
-
offeringId: string | number
|
|
212
|
-
expectedOrderFormSections
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
196
|
+
export interface AddOfferingProps {
|
|
197
|
+
orderFormId: string;
|
|
198
|
+
itemIndex: number;
|
|
199
|
+
offeringId: string | number;
|
|
200
|
+
expectedOrderFormSections?: string[];
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export async function addOffering(props: AddOfferingProps): Promise<OrderForm> {
|
|
204
|
+
const {
|
|
205
|
+
orderFormId,
|
|
206
|
+
itemIndex,
|
|
207
|
+
offeringId,
|
|
208
|
+
expectedOrderFormSections = DEFAULT_EXPECTED_SECTIONS,
|
|
209
|
+
} = props;
|
|
217
210
|
const result = await vtexFetchWithCookies<OrderForm>(
|
|
218
211
|
`/api/checkout/pub/orderForm/${orderFormId}/items/${itemIndex}/offerings`,
|
|
219
212
|
{
|
|
@@ -223,129 +216,142 @@ export async function addOffering(
|
|
|
223
216
|
id: offeringId,
|
|
224
217
|
info: null,
|
|
225
218
|
}),
|
|
226
|
-
headers,
|
|
227
219
|
},
|
|
228
220
|
);
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
): Promise<
|
|
240
|
-
const
|
|
241
|
-
|
|
221
|
+
return forceHttpsOnAssets(result);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export interface RemoveOfferingProps {
|
|
225
|
+
orderFormId: string;
|
|
226
|
+
itemIndex: number;
|
|
227
|
+
offeringId: string | number;
|
|
228
|
+
expectedOrderFormSections?: string[];
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export async function removeOffering(props: RemoveOfferingProps): Promise<OrderForm> {
|
|
232
|
+
const {
|
|
233
|
+
orderFormId,
|
|
234
|
+
itemIndex,
|
|
235
|
+
offeringId,
|
|
236
|
+
expectedOrderFormSections = DEFAULT_EXPECTED_SECTIONS,
|
|
237
|
+
} = props;
|
|
242
238
|
const result = await vtexFetchWithCookies<OrderForm>(
|
|
243
239
|
`/api/checkout/pub/orderForm/${orderFormId}/items/${itemIndex}/offerings/${offeringId}/remove`,
|
|
244
240
|
{
|
|
245
241
|
method: "POST",
|
|
246
242
|
body: JSON.stringify({ expectedOrderFormSections }),
|
|
247
|
-
headers,
|
|
248
243
|
},
|
|
249
244
|
);
|
|
250
|
-
|
|
251
|
-
return result;
|
|
245
|
+
return forceHttpsOnAssets(result);
|
|
252
246
|
}
|
|
253
247
|
|
|
254
248
|
// ---------------------------------------------------------------------------
|
|
255
249
|
// Cart — attachments
|
|
256
250
|
// ---------------------------------------------------------------------------
|
|
257
251
|
|
|
252
|
+
export interface UpdateOrderFormAttachmentProps {
|
|
253
|
+
orderFormId: string;
|
|
254
|
+
attachment: string;
|
|
255
|
+
body: Record<string, unknown>;
|
|
256
|
+
expectedOrderFormSections?: string[];
|
|
257
|
+
}
|
|
258
|
+
|
|
258
259
|
export async function updateOrderFormAttachment(
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
260
|
+
props: UpdateOrderFormAttachmentProps,
|
|
261
|
+
): Promise<OrderForm> {
|
|
262
|
+
const {
|
|
263
|
+
orderFormId,
|
|
264
|
+
attachment,
|
|
265
|
+
body,
|
|
266
|
+
expectedOrderFormSections = DEFAULT_EXPECTED_SECTIONS,
|
|
267
|
+
} = props;
|
|
265
268
|
if (!orderFormId) throw new Error("Order form ID is required");
|
|
266
|
-
const headers: Record<string, string> = {};
|
|
267
|
-
if (cookieHeader) headers.cookie = cookieHeader;
|
|
268
269
|
const result = await vtexFetchWithCookies<OrderForm>(
|
|
269
270
|
`/api/checkout/pub/orderForm/${orderFormId}/attachments/${attachment}`,
|
|
270
271
|
{
|
|
271
272
|
method: "POST",
|
|
272
273
|
body: JSON.stringify({ expectedOrderFormSections, ...body }),
|
|
273
|
-
headers,
|
|
274
274
|
},
|
|
275
275
|
);
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
276
|
+
return forceHttpsOnAssets(result);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export interface UpdateItemAttachmentProps {
|
|
280
|
+
orderFormId: string;
|
|
281
|
+
itemIndex: number;
|
|
282
|
+
attachment: string;
|
|
283
|
+
content: Record<string, unknown>;
|
|
284
|
+
noSplitItem?: boolean;
|
|
285
|
+
expectedOrderFormSections?: string[];
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export async function updateItemAttachment(props: UpdateItemAttachmentProps): Promise<OrderForm> {
|
|
289
|
+
const {
|
|
290
|
+
orderFormId,
|
|
291
|
+
itemIndex,
|
|
292
|
+
attachment,
|
|
293
|
+
content,
|
|
294
|
+
noSplitItem = true,
|
|
295
|
+
expectedOrderFormSections = DEFAULT_EXPECTED_SECTIONS,
|
|
296
|
+
} = props;
|
|
294
297
|
const result = await vtexFetchWithCookies<OrderForm>(
|
|
295
298
|
`/api/checkout/pub/orderForm/${orderFormId}/items/${itemIndex}/attachments/${attachment}`,
|
|
296
299
|
{
|
|
297
300
|
method: "POST",
|
|
298
301
|
body: JSON.stringify({
|
|
299
302
|
content,
|
|
300
|
-
noSplitItem
|
|
301
|
-
expectedOrderFormSections
|
|
303
|
+
noSplitItem,
|
|
304
|
+
expectedOrderFormSections,
|
|
302
305
|
}),
|
|
303
|
-
headers,
|
|
304
306
|
},
|
|
305
307
|
);
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
308
|
+
return forceHttpsOnAssets(result);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export interface RemoveItemAttachmentProps {
|
|
312
|
+
orderFormId: string;
|
|
313
|
+
itemIndex: number;
|
|
314
|
+
attachment: string;
|
|
315
|
+
content: Record<string, unknown>;
|
|
316
|
+
noSplitItem?: boolean;
|
|
317
|
+
expectedOrderFormSections?: string[];
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export async function removeItemAttachment(props: RemoveItemAttachmentProps): Promise<OrderForm> {
|
|
321
|
+
const {
|
|
322
|
+
orderFormId,
|
|
323
|
+
itemIndex,
|
|
324
|
+
attachment,
|
|
325
|
+
content,
|
|
326
|
+
noSplitItem = true,
|
|
327
|
+
expectedOrderFormSections = DEFAULT_EXPECTED_SECTIONS,
|
|
328
|
+
} = props;
|
|
324
329
|
const result = await vtexFetchWithCookies<OrderForm>(
|
|
325
330
|
`/api/checkout/pub/orderForm/${orderFormId}/items/${itemIndex}/attachments/${attachment}`,
|
|
326
331
|
{
|
|
327
332
|
method: "DELETE",
|
|
328
333
|
body: JSON.stringify({
|
|
329
334
|
content,
|
|
330
|
-
noSplitItem
|
|
331
|
-
expectedOrderFormSections
|
|
335
|
+
noSplitItem,
|
|
336
|
+
expectedOrderFormSections,
|
|
332
337
|
}),
|
|
333
|
-
headers,
|
|
334
338
|
},
|
|
335
339
|
);
|
|
336
|
-
|
|
337
|
-
return result;
|
|
340
|
+
return forceHttpsOnAssets(result);
|
|
338
341
|
}
|
|
339
342
|
|
|
340
343
|
// ---------------------------------------------------------------------------
|
|
341
344
|
// Cart — price override
|
|
342
345
|
// ---------------------------------------------------------------------------
|
|
343
346
|
|
|
344
|
-
export
|
|
345
|
-
orderFormId: string
|
|
346
|
-
itemIndex: number
|
|
347
|
-
price: number
|
|
348
|
-
|
|
347
|
+
export interface UpdateItemPriceProps {
|
|
348
|
+
orderFormId: string;
|
|
349
|
+
itemIndex: number;
|
|
350
|
+
price: number;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export async function updateItemPrice(props: UpdateItemPriceProps): Promise<OrderForm> {
|
|
354
|
+
const { orderFormId, itemIndex, price } = props;
|
|
349
355
|
return vtexFetch<OrderForm>(
|
|
350
356
|
`/api/checkout/pub/orderForm/${orderFormId}/items/${itemIndex}/price`,
|
|
351
357
|
{ method: "PUT", body: JSON.stringify({ price }) },
|
|
@@ -356,15 +362,20 @@ export async function updateItemPrice(
|
|
|
356
362
|
// Cart — selectable gifts
|
|
357
363
|
// ---------------------------------------------------------------------------
|
|
358
364
|
|
|
359
|
-
export
|
|
360
|
-
orderFormId: string
|
|
361
|
-
giftId: string
|
|
362
|
-
selectedGifts: Array<{ id: string; seller: string; quantity: number }
|
|
363
|
-
expectedOrderFormSections
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
365
|
+
export interface UpdateSelectableGiftsProps {
|
|
366
|
+
orderFormId: string;
|
|
367
|
+
giftId: string;
|
|
368
|
+
selectedGifts: Array<{ id: string; seller: string; quantity: number }>;
|
|
369
|
+
expectedOrderFormSections?: string[];
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export async function updateSelectableGifts(props: UpdateSelectableGiftsProps): Promise<OrderForm> {
|
|
373
|
+
const {
|
|
374
|
+
orderFormId,
|
|
375
|
+
giftId,
|
|
376
|
+
selectedGifts,
|
|
377
|
+
expectedOrderFormSections = DEFAULT_EXPECTED_SECTIONS,
|
|
378
|
+
} = props;
|
|
368
379
|
const result = await vtexFetchWithCookies<OrderForm>(
|
|
369
380
|
`/api/checkout/pub/orderForm/${orderFormId}/selectable-gifts/${giftId}`,
|
|
370
381
|
{
|
|
@@ -374,65 +385,69 @@ export async function updateSelectableGifts(
|
|
|
374
385
|
selectedGifts,
|
|
375
386
|
id: giftId,
|
|
376
387
|
}),
|
|
377
|
-
headers,
|
|
378
388
|
},
|
|
379
389
|
);
|
|
380
|
-
|
|
381
|
-
return result;
|
|
390
|
+
return forceHttpsOnAssets(result);
|
|
382
391
|
}
|
|
383
392
|
|
|
384
393
|
// ---------------------------------------------------------------------------
|
|
385
394
|
// Cart — installments
|
|
386
395
|
// ---------------------------------------------------------------------------
|
|
387
396
|
|
|
388
|
-
export
|
|
389
|
-
orderFormId: string
|
|
390
|
-
paymentSystem: number
|
|
391
|
-
|
|
392
|
-
|
|
397
|
+
export interface GetInstallmentsProps {
|
|
398
|
+
orderFormId: string;
|
|
399
|
+
paymentSystem: number;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export async function getInstallments(props: GetInstallmentsProps) {
|
|
403
|
+
const { orderFormId, paymentSystem } = props;
|
|
393
404
|
const params = new URLSearchParams({ paymentSystem: String(paymentSystem) });
|
|
394
405
|
appendSc(params);
|
|
395
|
-
|
|
396
|
-
if (cookieHeader) headers.cookie = cookieHeader;
|
|
397
|
-
return vtexFetch<any>(`/api/checkout/pub/orderForm/${orderFormId}/installments?${params}`, {
|
|
398
|
-
headers,
|
|
399
|
-
});
|
|
406
|
+
return vtexFetch<any>(`/api/checkout/pub/orderForm/${orderFormId}/installments?${params}`);
|
|
400
407
|
}
|
|
401
408
|
|
|
402
409
|
// ---------------------------------------------------------------------------
|
|
403
410
|
// Cart — profile & messages
|
|
404
411
|
// ---------------------------------------------------------------------------
|
|
405
412
|
|
|
413
|
+
export interface UpdateOrderFormProfileProps {
|
|
414
|
+
orderFormId: string;
|
|
415
|
+
fields: Record<string, unknown>;
|
|
416
|
+
ignoreProfileData?: boolean;
|
|
417
|
+
}
|
|
418
|
+
|
|
406
419
|
export async function updateOrderFormProfile(
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
const body = opts?.ignoreProfileData ? { ...fields, ignoreProfileData: true } : fields;
|
|
412
|
-
const headers: Record<string, string> = {};
|
|
413
|
-
if (opts?.cookieHeader) headers.cookie = opts.cookieHeader;
|
|
420
|
+
props: UpdateOrderFormProfileProps,
|
|
421
|
+
): Promise<OrderForm> {
|
|
422
|
+
const { orderFormId, fields, ignoreProfileData } = props;
|
|
423
|
+
const body = ignoreProfileData ? { ...fields, ignoreProfileData: true } : fields;
|
|
414
424
|
const result = await vtexFetchWithCookies<OrderForm>(
|
|
415
425
|
`/api/checkout/pub/orderForm/${orderFormId}/profile`,
|
|
416
|
-
{ method: "PATCH", body: JSON.stringify(body)
|
|
426
|
+
{ method: "PATCH", body: JSON.stringify(body) },
|
|
417
427
|
);
|
|
418
|
-
|
|
419
|
-
|
|
428
|
+
return forceHttpsOnAssets(result);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
export interface ChangeToAnonymousUserProps {
|
|
432
|
+
orderFormId: string;
|
|
420
433
|
}
|
|
421
434
|
|
|
422
|
-
export async function changeToAnonymousUser(
|
|
435
|
+
export async function changeToAnonymousUser(props: ChangeToAnonymousUserProps): Promise<OrderForm> {
|
|
436
|
+
const { orderFormId } = props;
|
|
423
437
|
return vtexFetch<OrderForm>(`/api/checkout/changeToAnonymousUser/${orderFormId}`);
|
|
424
438
|
}
|
|
425
439
|
|
|
440
|
+
export interface ClearOrderFormMessagesProps {
|
|
441
|
+
orderFormId: string;
|
|
442
|
+
}
|
|
443
|
+
|
|
426
444
|
export async function clearOrderFormMessages(
|
|
427
|
-
|
|
428
|
-
cookieHeader?: string,
|
|
445
|
+
props: ClearOrderFormMessagesProps,
|
|
429
446
|
): Promise<OrderForm> {
|
|
430
|
-
const
|
|
431
|
-
if (cookieHeader) headers.cookie = cookieHeader;
|
|
447
|
+
const { orderFormId } = props;
|
|
432
448
|
return vtexFetch<OrderForm>(`/api/checkout/pub/orderForm/${orderFormId}/messages/clear`, {
|
|
433
449
|
method: "POST",
|
|
434
450
|
body: JSON.stringify({}),
|
|
435
|
-
headers,
|
|
436
451
|
});
|
|
437
452
|
}
|
|
438
453
|
|
|
@@ -450,10 +465,15 @@ export interface RegionResult {
|
|
|
450
465
|
sellers: Seller[];
|
|
451
466
|
}
|
|
452
467
|
|
|
468
|
+
export interface GetSellersByRegionProps {
|
|
469
|
+
postalCode: string;
|
|
470
|
+
salesChannel?: string;
|
|
471
|
+
}
|
|
472
|
+
|
|
453
473
|
export async function getSellersByRegion(
|
|
454
|
-
|
|
455
|
-
salesChannel?: string,
|
|
474
|
+
props: GetSellersByRegionProps,
|
|
456
475
|
): Promise<RegionResult | null> {
|
|
476
|
+
const { postalCode, salesChannel } = props;
|
|
457
477
|
const params = new URLSearchParams({ country: "BRA", postalCode });
|
|
458
478
|
const sc = salesChannel ?? getVtexConfig().salesChannel;
|
|
459
479
|
if (sc) params.set("sc", sc);
|
|
@@ -461,21 +481,20 @@ export async function getSellersByRegion(
|
|
|
461
481
|
return resp[0]?.sellers?.length > 0 ? resp[0] : null;
|
|
462
482
|
}
|
|
463
483
|
|
|
464
|
-
export
|
|
465
|
-
orderFormId: string
|
|
466
|
-
postalCode: string
|
|
467
|
-
country
|
|
468
|
-
|
|
469
|
-
|
|
484
|
+
export interface SetShippingPostalCodeProps {
|
|
485
|
+
orderFormId: string;
|
|
486
|
+
postalCode: string;
|
|
487
|
+
country?: string;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
export async function setShippingPostalCode(props: SetShippingPostalCodeProps): Promise<boolean> {
|
|
491
|
+
const { orderFormId, postalCode, country = "BRA" } = props;
|
|
470
492
|
try {
|
|
471
|
-
const headers: Record<string, string> = {};
|
|
472
|
-
if (cookieHeader) headers.cookie = cookieHeader;
|
|
473
493
|
await vtexFetch<any>(`/api/checkout/pub/orderForm/${orderFormId}/attachments/shippingData`, {
|
|
474
494
|
method: "POST",
|
|
475
495
|
body: JSON.stringify({
|
|
476
496
|
selectedAddresses: [{ postalCode, country }],
|
|
477
497
|
}),
|
|
478
|
-
headers,
|
|
479
498
|
});
|
|
480
499
|
return true;
|
|
481
500
|
} catch {
|