@reactionary/provider-medusa 0.3.17 → 0.6.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.
- package/package.json +2 -2
- package/providers/cart.provider.js +115 -53
- package/providers/category.provider.js +25 -16
- package/providers/checkout.provider.js +56 -33
- package/providers/order-search.provider.js +9 -5
- package/providers/product-recommendations.provider.js +8 -5
- package/providers/product-search.provider.js +11 -8
- package/providers/product.provider.js +18 -12
- package/providers/profile.provider.js +28 -12
- package/src/providers/cart.provider.d.ts +44 -5
- package/src/providers/category.provider.d.ts +17 -0
- package/src/providers/checkout.provider.d.ts +11 -1
- package/src/providers/order-search.provider.d.ts +1 -0
- package/src/providers/product-recommendations.provider.d.ts +6 -1
- package/src/providers/product-search.provider.d.ts +1 -0
- package/src/providers/product.provider.d.ts +12 -0
- package/src/providers/profile.provider.d.ts +7 -0
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/provider-medusa",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@medusajs/js-sdk": "^2.13.0",
|
|
9
|
-
"@reactionary/core": "0.
|
|
9
|
+
"@reactionary/core": "0.6.1",
|
|
10
10
|
"debug": "^4.4.3",
|
|
11
11
|
"@medusajs/types": "^2.11.0",
|
|
12
12
|
"zod": "4.1.9"
|
|
@@ -21,10 +21,10 @@ import {
|
|
|
21
21
|
CartProvider,
|
|
22
22
|
CartQueryByIdSchema,
|
|
23
23
|
CartSchema,
|
|
24
|
+
error,
|
|
24
25
|
ProductVariantIdentifierSchema,
|
|
25
26
|
Reactionary,
|
|
26
|
-
success
|
|
27
|
-
error
|
|
27
|
+
success
|
|
28
28
|
} from "@reactionary/core";
|
|
29
29
|
import createDebug from "debug";
|
|
30
30
|
import { MedusaCartIdentifierSchema } from "../schema/medusa.schema.js";
|
|
@@ -54,7 +54,7 @@ class MedusaCartProvider extends CartProvider {
|
|
|
54
54
|
if (debug.enabled) {
|
|
55
55
|
debug("Fetching cart by ID:", medusaId.key);
|
|
56
56
|
}
|
|
57
|
-
const cartResponse = await client.store.cart.retrieve(medusaId.key);
|
|
57
|
+
const cartResponse = await client.store.cart.retrieve(medusaId.key, { fields: this.includedFields });
|
|
58
58
|
if (debug.enabled) {
|
|
59
59
|
debug("Received cart response:", cartResponse);
|
|
60
60
|
}
|
|
@@ -73,6 +73,19 @@ class MedusaCartProvider extends CartProvider {
|
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Extension point for the `add` operation to control the payload sent to Medusa when adding an item to the cart. By default, it only includes the variant ID and quantity, but you can override it to include more fields as needed.
|
|
78
|
+
*
|
|
79
|
+
* @param payload
|
|
80
|
+
* @param variantId
|
|
81
|
+
* @returns
|
|
82
|
+
*/
|
|
83
|
+
addPayload(payload, variantId) {
|
|
84
|
+
return {
|
|
85
|
+
variant_id: variantId,
|
|
86
|
+
quantity: payload.quantity
|
|
87
|
+
};
|
|
88
|
+
}
|
|
76
89
|
async add(payload) {
|
|
77
90
|
try {
|
|
78
91
|
const client = await this.getClient();
|
|
@@ -94,10 +107,7 @@ class MedusaCartProvider extends CartProvider {
|
|
|
94
107
|
const variantId = await this.medusaApi.resolveVariantId(payload.variant.sku);
|
|
95
108
|
const response = await client.store.cart.createLineItem(
|
|
96
109
|
medusaId.key,
|
|
97
|
-
|
|
98
|
-
variant_id: variantId,
|
|
99
|
-
quantity: payload.quantity
|
|
100
|
-
},
|
|
110
|
+
this.addPayload(payload, variantId),
|
|
101
111
|
{
|
|
102
112
|
fields: this.includedFields
|
|
103
113
|
}
|
|
@@ -132,6 +142,16 @@ class MedusaCartProvider extends CartProvider {
|
|
|
132
142
|
handleProviderError("remove item from cart", error2);
|
|
133
143
|
}
|
|
134
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Extension point for the `changeQuantity` operation to control the payload sent to Medusa when changing the quantity of an item in the cart. By default, it only includes the new quantity, but you can override it to include more fields as needed.
|
|
147
|
+
* @param payload
|
|
148
|
+
* @returns
|
|
149
|
+
*/
|
|
150
|
+
changeQuantityPayload(payload) {
|
|
151
|
+
return {
|
|
152
|
+
quantity: payload.quantity
|
|
153
|
+
};
|
|
154
|
+
}
|
|
135
155
|
async changeQuantity(payload) {
|
|
136
156
|
if (payload.quantity < 1) {
|
|
137
157
|
throw new Error(
|
|
@@ -144,9 +164,7 @@ class MedusaCartProvider extends CartProvider {
|
|
|
144
164
|
const response = await client.store.cart.updateLineItem(
|
|
145
165
|
medusaId.key,
|
|
146
166
|
payload.item.key,
|
|
147
|
-
|
|
148
|
-
quantity: payload.quantity
|
|
149
|
-
},
|
|
167
|
+
this.changeQuantityPayload(payload),
|
|
150
168
|
{
|
|
151
169
|
fields: this.includedFields
|
|
152
170
|
}
|
|
@@ -181,7 +199,7 @@ class MedusaCartProvider extends CartProvider {
|
|
|
181
199
|
identifier: void 0
|
|
182
200
|
});
|
|
183
201
|
} catch (err) {
|
|
184
|
-
debug("Failed to get active cart ID:",
|
|
202
|
+
debug("Failed to get active cart ID:", err);
|
|
185
203
|
return error({
|
|
186
204
|
type: "NotFound",
|
|
187
205
|
identifier: void 0
|
|
@@ -213,17 +231,28 @@ class MedusaCartProvider extends CartProvider {
|
|
|
213
231
|
return success(void 0);
|
|
214
232
|
}
|
|
215
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Extension point to apply a coupon code to the cart. By default, it only includes the coupon code, but you can override it to include more fields as needed.
|
|
236
|
+
* @param payload
|
|
237
|
+
* @returns
|
|
238
|
+
*/
|
|
239
|
+
applyCouponCodePayload(payload) {
|
|
240
|
+
return {
|
|
241
|
+
promo_codes: [payload.couponCode]
|
|
242
|
+
};
|
|
243
|
+
}
|
|
216
244
|
async applyCouponCode(payload) {
|
|
217
245
|
try {
|
|
218
246
|
const client = await this.getClient();
|
|
219
247
|
const medusaId = payload.cart;
|
|
220
|
-
const response = await client.
|
|
221
|
-
medusaId.key
|
|
248
|
+
const response = await client.client.fetch(
|
|
249
|
+
`/store/carts/${medusaId.key}/promotions`,
|
|
222
250
|
{
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
251
|
+
method: "POST",
|
|
252
|
+
body: this.applyCouponCodePayload(payload),
|
|
253
|
+
query: {
|
|
254
|
+
fields: this.includedFields
|
|
255
|
+
}
|
|
227
256
|
}
|
|
228
257
|
);
|
|
229
258
|
if (response.cart) {
|
|
@@ -234,73 +263,86 @@ class MedusaCartProvider extends CartProvider {
|
|
|
234
263
|
handleProviderError("apply coupon code", error2);
|
|
235
264
|
}
|
|
236
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* Extension point to remove a coupon code from the cart. By default, it only includes the coupon code to be removed, but you can override it to include more fields as needed.
|
|
268
|
+
* @param payload
|
|
269
|
+
* @returns
|
|
270
|
+
*/
|
|
271
|
+
removeCouponCodePayload(payload) {
|
|
272
|
+
return {
|
|
273
|
+
promo_codes: [payload.couponCode]
|
|
274
|
+
};
|
|
275
|
+
}
|
|
237
276
|
async removeCouponCode(payload) {
|
|
238
277
|
try {
|
|
239
278
|
const client = await this.getClient();
|
|
240
279
|
const medusaId = payload.cart;
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
const response = await client.store.cart.update(
|
|
248
|
-
medusaId.key,
|
|
249
|
-
{
|
|
250
|
-
promo_codes: remainingCodes || []
|
|
251
|
-
},
|
|
252
|
-
{
|
|
280
|
+
const response = await client.client.fetch(
|
|
281
|
+
`/store/carts/${medusaId.key}/promotions`,
|
|
282
|
+
{
|
|
283
|
+
method: "DELETE",
|
|
284
|
+
body: this.removeCouponCodePayload(payload),
|
|
285
|
+
query: {
|
|
253
286
|
fields: this.includedFields
|
|
254
287
|
}
|
|
255
|
-
);
|
|
256
|
-
if (response.cart) {
|
|
257
|
-
return success(this.parseSingle(response.cart));
|
|
258
288
|
}
|
|
289
|
+
);
|
|
290
|
+
if (response.cart) {
|
|
291
|
+
return success(this.parseSingle(response.cart));
|
|
259
292
|
}
|
|
260
293
|
throw new Error("Failed to remove coupon code");
|
|
261
294
|
} catch (error2) {
|
|
262
295
|
handleProviderError("remove coupon code", error2);
|
|
263
296
|
}
|
|
264
297
|
}
|
|
298
|
+
/**
|
|
299
|
+
* Extension point to control the payload sent to Medusa when changing the currency of the cart. By default, it only includes the new region ID, but you can override it to include more fields as needed.
|
|
300
|
+
* @param payload
|
|
301
|
+
* @param newRegionId
|
|
302
|
+
* @returns
|
|
303
|
+
*/
|
|
304
|
+
changeCurrencyPayload(payload, newRegionId) {
|
|
305
|
+
return {
|
|
306
|
+
region_id: newRegionId
|
|
307
|
+
};
|
|
308
|
+
}
|
|
265
309
|
async changeCurrency(payload) {
|
|
266
310
|
try {
|
|
267
311
|
const client = await this.getClient();
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
);
|
|
271
|
-
client.store.cart.update(
|
|
312
|
+
const newRegionId = (await this.medusaApi.getActiveRegion()).id;
|
|
313
|
+
const updatedCartResponse = await client.store.cart.update(
|
|
272
314
|
payload.cart.key,
|
|
273
|
-
|
|
274
|
-
region_id: (await this.medusaApi.getActiveRegion()).id
|
|
275
|
-
},
|
|
315
|
+
this.changeCurrencyPayload(payload, newRegionId),
|
|
276
316
|
{
|
|
277
317
|
fields: this.includedFields
|
|
278
318
|
}
|
|
279
319
|
);
|
|
280
|
-
if (
|
|
281
|
-
throw new Error("Cart not found");
|
|
282
|
-
}
|
|
283
|
-
const newCartResponse = await client.store.cart.retrieve(
|
|
284
|
-
payload.cart.key
|
|
285
|
-
);
|
|
286
|
-
if (newCartResponse.cart) {
|
|
320
|
+
if (updatedCartResponse.cart) {
|
|
287
321
|
this.medusaApi.setSessionData({
|
|
288
|
-
activeCartId:
|
|
322
|
+
activeCartId: updatedCartResponse.cart.id
|
|
289
323
|
});
|
|
290
|
-
return success(this.parseSingle(
|
|
324
|
+
return success(this.parseSingle(updatedCartResponse.cart));
|
|
291
325
|
}
|
|
292
326
|
throw new Error("Failed to change currency");
|
|
293
327
|
} catch (error2) {
|
|
294
328
|
handleProviderError("change currency", error2);
|
|
295
329
|
}
|
|
296
330
|
}
|
|
331
|
+
/**
|
|
332
|
+
* Extension point to control the payload sent to Medusa when creating a cart. By default, it only includes the currency code, but you can override it to include more fields as needed.
|
|
333
|
+
* @param currency
|
|
334
|
+
* @returns
|
|
335
|
+
*/
|
|
336
|
+
createCartPayload(currency) {
|
|
337
|
+
return {
|
|
338
|
+
currency_code: (currency || this.context.languageContext.currencyCode || "").toLowerCase()
|
|
339
|
+
};
|
|
340
|
+
}
|
|
297
341
|
async createCart(currency) {
|
|
298
342
|
try {
|
|
299
343
|
const client = await this.getClient();
|
|
300
344
|
const response = await client.store.cart.create(
|
|
301
|
-
|
|
302
|
-
currency_code: (currency || this.context.languageContext.currencyCode || "").toLowerCase()
|
|
303
|
-
},
|
|
345
|
+
this.createCartPayload(currency),
|
|
304
346
|
{
|
|
305
347
|
fields: this.includedFields
|
|
306
348
|
}
|
|
@@ -383,12 +425,32 @@ class MedusaCartProvider extends CartProvider {
|
|
|
383
425
|
for (const remoteItem of allItems) {
|
|
384
426
|
items.push(this.parseCartItem(remoteItem, price.grandTotal.currency));
|
|
385
427
|
}
|
|
428
|
+
const appliedPromotions = [];
|
|
429
|
+
if (remote.promotions) {
|
|
430
|
+
for (const promo of remote.promotions) {
|
|
431
|
+
const promotionName = promo.code;
|
|
432
|
+
let promoDescription = "";
|
|
433
|
+
if (promo.application_method?.type === "percentage") {
|
|
434
|
+
promoDescription = `-${promo.application_method.value}%`;
|
|
435
|
+
}
|
|
436
|
+
if (promo.application_method?.type === "fixed") {
|
|
437
|
+
promoDescription = `-${promo.application_method.value} ${price.grandTotal.currency}`;
|
|
438
|
+
}
|
|
439
|
+
appliedPromotions.push({
|
|
440
|
+
code: promo.code || "",
|
|
441
|
+
isCouponCode: promo.is_automatic ? false : true,
|
|
442
|
+
name: promotionName || promoDescription,
|
|
443
|
+
description: promoDescription
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
}
|
|
386
447
|
const result = {
|
|
387
448
|
identifier,
|
|
388
449
|
name,
|
|
389
450
|
description,
|
|
390
451
|
price,
|
|
391
452
|
items,
|
|
453
|
+
appliedPromotions,
|
|
392
454
|
userId: {
|
|
393
455
|
userId: "???"
|
|
394
456
|
}
|
|
@@ -427,8 +489,8 @@ __decorateClass([
|
|
|
427
489
|
], MedusaCartProvider.prototype, "getActiveCartId", 1);
|
|
428
490
|
__decorateClass([
|
|
429
491
|
Reactionary({
|
|
430
|
-
|
|
431
|
-
|
|
492
|
+
cache: false,
|
|
493
|
+
inputSchema: CartMutationDeleteCartSchema
|
|
432
494
|
})
|
|
433
495
|
], MedusaCartProvider.prototype, "deleteCart", 1);
|
|
434
496
|
__decorateClass([
|
|
@@ -71,13 +71,16 @@ class MedusaCategoryProvider extends CategoryProvider {
|
|
|
71
71
|
}
|
|
72
72
|
return success(this.parseSingle(candidate));
|
|
73
73
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const categoryResult = await sdk.store.category.list({
|
|
74
|
+
getBySlugPayload(payload) {
|
|
75
|
+
return {
|
|
77
76
|
handle: payload.slug,
|
|
78
77
|
limit: 1,
|
|
79
78
|
offset: 0
|
|
80
|
-
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
async getBySlug(payload) {
|
|
82
|
+
const sdk = await this.medusaApi.getClient();
|
|
83
|
+
const categoryResult = await sdk.store.category.list(this.getBySlugPayload(payload));
|
|
81
84
|
if (categoryResult.count === 0) {
|
|
82
85
|
return error({
|
|
83
86
|
type: "NotFound",
|
|
@@ -107,31 +110,37 @@ class MedusaCategoryProvider extends CategoryProvider {
|
|
|
107
110
|
results = results.reverse();
|
|
108
111
|
return success(results);
|
|
109
112
|
}
|
|
113
|
+
findChildCategoriesPayload(payload, actualParent) {
|
|
114
|
+
return {
|
|
115
|
+
fields: "+metadata,+parent_category.metadata",
|
|
116
|
+
parent_category_id: actualParent.id,
|
|
117
|
+
limit: payload.paginationOptions.pageSize,
|
|
118
|
+
offset: (payload.paginationOptions.pageNumber - 1) * payload.paginationOptions.pageSize
|
|
119
|
+
};
|
|
120
|
+
}
|
|
110
121
|
async findChildCategories(payload) {
|
|
111
122
|
const sdk = await this.medusaApi.getClient();
|
|
112
|
-
const
|
|
123
|
+
const actualParent = await this.resolveCategoryIdByExternalId(
|
|
113
124
|
payload.parentId.key
|
|
114
125
|
);
|
|
115
|
-
if (!
|
|
126
|
+
if (!actualParent) {
|
|
116
127
|
throw new Error("Parent category not found " + payload.parentId.key);
|
|
117
128
|
}
|
|
118
|
-
const response = await sdk.store.category.list(
|
|
119
|
-
fields: "+metadata,+parent_category.metadata",
|
|
120
|
-
parent_category_id: actualParentId.id,
|
|
121
|
-
limit: payload.paginationOptions.pageSize,
|
|
122
|
-
offset: (payload.paginationOptions.pageNumber - 1) * payload.paginationOptions.pageSize
|
|
123
|
-
});
|
|
129
|
+
const response = await sdk.store.category.list(this.findChildCategoriesPayload(payload, actualParent));
|
|
124
130
|
const result = this.parsePaginatedResult(response);
|
|
125
131
|
return success(result);
|
|
126
132
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const response = await sdk.store.category.list({
|
|
133
|
+
findTopCategoriesPayload(payload) {
|
|
134
|
+
return {
|
|
130
135
|
fields: "+metadata",
|
|
131
136
|
parent_category_id: "null",
|
|
132
137
|
limit: payload.paginationOptions.pageSize,
|
|
133
138
|
offset: (payload.paginationOptions.pageNumber - 1) * payload.paginationOptions.pageSize
|
|
134
|
-
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
async findTopCategories(payload) {
|
|
142
|
+
const sdk = await this.medusaApi.getClient();
|
|
143
|
+
const response = await sdk.store.category.list(this.findTopCategoriesPayload(payload));
|
|
135
144
|
const result = this.parsePaginatedResult(response);
|
|
136
145
|
return success(result);
|
|
137
146
|
}
|
|
@@ -58,6 +58,16 @@ class MedusaCheckoutProvider extends CheckoutProvider {
|
|
|
58
58
|
this.includedFields = ["+items.*"].join(",");
|
|
59
59
|
this.config = config;
|
|
60
60
|
}
|
|
61
|
+
initiateCheckoutForCartPayload(payload) {
|
|
62
|
+
return {
|
|
63
|
+
billing_address: payload.billingAddress ? this.mapAddressToStoreAddress(payload.billingAddress) : void 0,
|
|
64
|
+
shipping_address: payload.billingAddress ? this.mapAddressToStoreAddress(payload.billingAddress) : void 0,
|
|
65
|
+
email: payload.notificationEmail,
|
|
66
|
+
metadata: {
|
|
67
|
+
sms_notification: payload.notificationPhone
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
61
71
|
async initiateCheckoutForCart(payload) {
|
|
62
72
|
const client = await this.medusaApi.getClient();
|
|
63
73
|
if (debug.enabled) {
|
|
@@ -67,14 +77,7 @@ class MedusaCheckoutProvider extends CheckoutProvider {
|
|
|
67
77
|
}
|
|
68
78
|
const response = await client.store.cart.update(
|
|
69
79
|
payload.cart.identifier.key,
|
|
70
|
-
|
|
71
|
-
billing_address: payload.billingAddress ? this.mapAddressToStoreAddress(payload.billingAddress) : void 0,
|
|
72
|
-
shipping_address: payload.billingAddress ? this.mapAddressToStoreAddress(payload.billingAddress) : void 0,
|
|
73
|
-
email: payload.notificationEmail,
|
|
74
|
-
metadata: {
|
|
75
|
-
sms_notification: payload.notificationPhone
|
|
76
|
-
}
|
|
77
|
-
},
|
|
80
|
+
this.initiateCheckoutForCartPayload(payload),
|
|
78
81
|
{
|
|
79
82
|
fields: this.includedFields
|
|
80
83
|
}
|
|
@@ -88,21 +91,27 @@ class MedusaCheckoutProvider extends CheckoutProvider {
|
|
|
88
91
|
});
|
|
89
92
|
return success(this.parseSingle(response.cart));
|
|
90
93
|
}
|
|
94
|
+
setShippingAddressPayload(payload) {
|
|
95
|
+
return {
|
|
96
|
+
shipping_address: this.mapAddressToStoreAddress(payload.shippingAddress)
|
|
97
|
+
};
|
|
98
|
+
}
|
|
91
99
|
async setShippingAddress(payload) {
|
|
92
100
|
const client = await this.medusaApi.getClient();
|
|
93
101
|
const response = await client.store.cart.update(
|
|
94
102
|
payload.checkout.key,
|
|
95
|
-
|
|
96
|
-
shipping_address: this.mapAddressToStoreAddress(
|
|
97
|
-
payload.shippingAddress
|
|
98
|
-
)
|
|
99
|
-
},
|
|
103
|
+
this.setShippingAddressPayload(payload),
|
|
100
104
|
{
|
|
101
105
|
fields: this.includedFields
|
|
102
106
|
}
|
|
103
107
|
);
|
|
104
108
|
return success(this.parseSingle(response.cart));
|
|
105
109
|
}
|
|
110
|
+
getAvailableShippingMethodsPayload(payload) {
|
|
111
|
+
return {
|
|
112
|
+
cart_id: payload.checkout.key
|
|
113
|
+
};
|
|
114
|
+
}
|
|
106
115
|
async getAvailableShippingMethods(payload) {
|
|
107
116
|
const client = await this.medusaApi.getClient();
|
|
108
117
|
if (debug.enabled) {
|
|
@@ -110,9 +119,9 @@ class MedusaCheckoutProvider extends CheckoutProvider {
|
|
|
110
119
|
`Fetching available shipping methods for checkout with key: ${payload.checkout.key}`
|
|
111
120
|
);
|
|
112
121
|
}
|
|
113
|
-
const shippingMethodResponse = await client.store.fulfillment.listCartOptions(
|
|
114
|
-
|
|
115
|
-
|
|
122
|
+
const shippingMethodResponse = await client.store.fulfillment.listCartOptions(
|
|
123
|
+
this.getAvailableShippingMethodsPayload(payload)
|
|
124
|
+
);
|
|
116
125
|
const shippingMethods = [];
|
|
117
126
|
for (const sm of shippingMethodResponse.shipping_options) {
|
|
118
127
|
shippingMethods.push(
|
|
@@ -136,6 +145,11 @@ class MedusaCheckoutProvider extends CheckoutProvider {
|
|
|
136
145
|
}
|
|
137
146
|
return success(shippingMethods);
|
|
138
147
|
}
|
|
148
|
+
getAvailablePaymentMethodsPayload(payload, regionId) {
|
|
149
|
+
return {
|
|
150
|
+
region_id: regionId
|
|
151
|
+
};
|
|
152
|
+
}
|
|
139
153
|
async getAvailablePaymentMethods(payload) {
|
|
140
154
|
const client = await this.medusaApi.getClient();
|
|
141
155
|
if (debug.enabled) {
|
|
@@ -144,9 +158,12 @@ class MedusaCheckoutProvider extends CheckoutProvider {
|
|
|
144
158
|
);
|
|
145
159
|
}
|
|
146
160
|
const checkout = await client.store.cart.retrieve(payload.checkout.key);
|
|
147
|
-
const paymentMethodResponse = await client.store.payment.listPaymentProviders(
|
|
148
|
-
|
|
149
|
-
|
|
161
|
+
const paymentMethodResponse = await client.store.payment.listPaymentProviders(
|
|
162
|
+
this.getAvailablePaymentMethodsPayload(
|
|
163
|
+
payload,
|
|
164
|
+
checkout.cart.region_id || (await this.medusaApi.getActiveRegion()).id
|
|
165
|
+
)
|
|
166
|
+
);
|
|
150
167
|
const paymentMethods = [];
|
|
151
168
|
for (const pm of paymentMethodResponse.payment_providers) {
|
|
152
169
|
paymentMethods.push(
|
|
@@ -170,6 +187,15 @@ class MedusaCheckoutProvider extends CheckoutProvider {
|
|
|
170
187
|
}
|
|
171
188
|
return success(paymentMethods);
|
|
172
189
|
}
|
|
190
|
+
addPaymentInstructionPayload(payload) {
|
|
191
|
+
return {
|
|
192
|
+
provider_id: payload.paymentInstruction.paymentMethod.method,
|
|
193
|
+
data: payload.paymentInstruction.protocolData.reduce((acc, curr) => {
|
|
194
|
+
acc[curr.key] = curr.value;
|
|
195
|
+
return acc;
|
|
196
|
+
}, {})
|
|
197
|
+
};
|
|
198
|
+
}
|
|
173
199
|
async addPaymentInstruction(payload) {
|
|
174
200
|
const client = await this.medusaApi.getClient();
|
|
175
201
|
if (debug.enabled) {
|
|
@@ -181,13 +207,7 @@ class MedusaCheckoutProvider extends CheckoutProvider {
|
|
|
181
207
|
const cartResponse = await client.store.cart.retrieve(
|
|
182
208
|
payload.checkout.key
|
|
183
209
|
);
|
|
184
|
-
const paymentSessionResponse = await client.store.payment.initiatePaymentSession(cartResponse.cart,
|
|
185
|
-
provider_id: payload.paymentInstruction.paymentMethod.method,
|
|
186
|
-
data: payload.paymentInstruction.protocolData.reduce((acc, curr) => {
|
|
187
|
-
acc[curr.key] = curr.value;
|
|
188
|
-
return acc;
|
|
189
|
-
}, {})
|
|
190
|
-
});
|
|
210
|
+
const paymentSessionResponse = await client.store.payment.initiatePaymentSession(cartResponse.cart, this.addPaymentInstructionPayload(payload));
|
|
191
211
|
const updatedCartResponse = await client.store.cart.retrieve(
|
|
192
212
|
payload.checkout.key,
|
|
193
213
|
{
|
|
@@ -205,18 +225,21 @@ class MedusaCheckoutProvider extends CheckoutProvider {
|
|
|
205
225
|
removePaymentInstruction(payload) {
|
|
206
226
|
throw new Error("Method not implemented.");
|
|
207
227
|
}
|
|
228
|
+
setShippingInstructionPayload(payload) {
|
|
229
|
+
return {
|
|
230
|
+
option_id: payload.shippingInstruction.shippingMethod.key,
|
|
231
|
+
data: {
|
|
232
|
+
consent_for_unattended_delivery: payload.shippingInstruction.consentForUnattendedDelivery + "",
|
|
233
|
+
instructions: payload.shippingInstruction.instructions || ""
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
}
|
|
208
237
|
async setShippingInstruction(payload) {
|
|
209
238
|
const client = await this.medusaApi.getClient();
|
|
210
239
|
const medusaId = payload.checkout;
|
|
211
240
|
try {
|
|
212
241
|
if (payload.shippingInstruction.shippingMethod) {
|
|
213
|
-
await client.store.cart.addShippingMethod(medusaId.key,
|
|
214
|
-
option_id: payload.shippingInstruction.shippingMethod.key,
|
|
215
|
-
data: {
|
|
216
|
-
consent_for_unattended_delivery: payload.shippingInstruction.consentForUnattendedDelivery + "",
|
|
217
|
-
instructions: payload.shippingInstruction.instructions || ""
|
|
218
|
-
}
|
|
219
|
-
});
|
|
242
|
+
await client.store.cart.addShippingMethod(medusaId.key, this.setShippingInstructionPayload(payload));
|
|
220
243
|
}
|
|
221
244
|
await client.store.cart.update(medusaId.key, {
|
|
222
245
|
metadata: {
|
|
@@ -25,9 +25,8 @@ class MedusaOrderSearchProvider extends OrderSearchProvider {
|
|
|
25
25
|
this.medusaApi = medusaApi;
|
|
26
26
|
this.config = config;
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const medusa = await this.medusaApi.getClient();
|
|
28
|
+
queryByTermPayload(payload) {
|
|
29
|
+
const filters = {};
|
|
31
30
|
if (payload.search.term) {
|
|
32
31
|
debug("Searching orders by term is not supported in Medusa");
|
|
33
32
|
}
|
|
@@ -56,11 +55,16 @@ class MedusaOrderSearchProvider extends OrderSearchProvider {
|
|
|
56
55
|
}
|
|
57
56
|
return retStatus;
|
|
58
57
|
});
|
|
59
|
-
|
|
58
|
+
return {
|
|
60
59
|
status: statusFilter,
|
|
61
60
|
limit: payload.search.paginationOptions.pageSize,
|
|
62
61
|
offset: (payload.search.paginationOptions.pageNumber - 1) * payload.search.paginationOptions.pageSize
|
|
63
|
-
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
async queryByTerm(payload) {
|
|
65
|
+
debug("queryByTerm", payload);
|
|
66
|
+
const medusa = await this.medusaApi.getClient();
|
|
67
|
+
const response = await medusa.store.order.list(this.queryByTermPayload(payload));
|
|
64
68
|
const result = this.parsePaginatedResult(response, payload);
|
|
65
69
|
if (debug.enabled) {
|
|
66
70
|
debug(
|
|
@@ -14,6 +14,13 @@ class MedusaProductRecommendationsProvider extends ProductRecommendationsProvide
|
|
|
14
14
|
this.config = config;
|
|
15
15
|
this.medusaApi = medusaApi;
|
|
16
16
|
}
|
|
17
|
+
getCollectionPayload(query, collection) {
|
|
18
|
+
return {
|
|
19
|
+
collection_id: [collection.id],
|
|
20
|
+
limit: query.numberOfRecommendations,
|
|
21
|
+
fields: "+variants.id,+variants.sku,+external_id"
|
|
22
|
+
};
|
|
23
|
+
}
|
|
17
24
|
/**
|
|
18
25
|
* Get product recommendations from a Medusa collection
|
|
19
26
|
*
|
|
@@ -44,11 +51,7 @@ class MedusaProductRecommendationsProvider extends ProductRecommendationsProvide
|
|
|
44
51
|
if (debug.enabled) {
|
|
45
52
|
debug(`Found collection: ${collection.title} (${collection.id})`);
|
|
46
53
|
}
|
|
47
|
-
const productsResponse = await client.store.product.list(
|
|
48
|
-
collection_id: [collection.id],
|
|
49
|
-
limit: query.numberOfRecommendations,
|
|
50
|
-
fields: "+variants.id,+variants.sku,+external_id"
|
|
51
|
-
});
|
|
54
|
+
const productsResponse = await client.store.product.list(this.getCollectionPayload(query, collection));
|
|
52
55
|
if (debug.enabled) {
|
|
53
56
|
debug(`Found ${productsResponse.products.length} products in collection`);
|
|
54
57
|
}
|
|
@@ -61,6 +61,16 @@ class MedusaSearchProvider extends ProductSearchProvider {
|
|
|
61
61
|
}
|
|
62
62
|
return candidate || null;
|
|
63
63
|
}
|
|
64
|
+
queryByTermPayload(payload, categoryIdToFind) {
|
|
65
|
+
const finalSearch = (payload.search.term || "").trim().replace("*", "");
|
|
66
|
+
return {
|
|
67
|
+
q: finalSearch,
|
|
68
|
+
...categoryIdToFind ? { category_id: categoryIdToFind } : {},
|
|
69
|
+
limit: payload.search.paginationOptions.pageSize,
|
|
70
|
+
fields: "+metadata.*,+external_id",
|
|
71
|
+
offset: (payload.search.paginationOptions.pageNumber - 1) * payload.search.paginationOptions.pageSize
|
|
72
|
+
};
|
|
73
|
+
}
|
|
64
74
|
async queryByTerm(payload) {
|
|
65
75
|
const client = await this.medusaApi.getClient();
|
|
66
76
|
let categoryIdToFind = null;
|
|
@@ -82,14 +92,7 @@ class MedusaSearchProvider extends ProductSearchProvider {
|
|
|
82
92
|
);
|
|
83
93
|
}
|
|
84
94
|
}
|
|
85
|
-
const
|
|
86
|
-
const response = await client.store.product.list({
|
|
87
|
-
q: finalSearch,
|
|
88
|
-
...categoryIdToFind ? { category_id: categoryIdToFind } : {},
|
|
89
|
-
limit: payload.search.paginationOptions.pageSize,
|
|
90
|
-
fields: "+metadata.*,+external_id",
|
|
91
|
-
offset: (payload.search.paginationOptions.pageNumber - 1) * payload.search.paginationOptions.pageSize
|
|
92
|
-
});
|
|
95
|
+
const response = await client.store.product.list(this.queryByTermPayload(payload, categoryIdToFind));
|
|
93
96
|
const result = this.parsePaginatedResult(response);
|
|
94
97
|
if (debug.enabled) {
|
|
95
98
|
debug(
|
|
@@ -30,18 +30,21 @@ class MedusaProductProvider extends ProductProvider {
|
|
|
30
30
|
this.alwaysIncludedFields = ["+metadata.*", "+categories.metadata.*", "+external_id"];
|
|
31
31
|
this.config = config;
|
|
32
32
|
}
|
|
33
|
+
getByIdPayload(payload) {
|
|
34
|
+
return {
|
|
35
|
+
external_id: payload.identifier.key,
|
|
36
|
+
limit: 1,
|
|
37
|
+
offset: 0,
|
|
38
|
+
fields: this.alwaysIncludedFields.join(",")
|
|
39
|
+
};
|
|
40
|
+
}
|
|
33
41
|
async getById(payload) {
|
|
34
42
|
const client = await this.medusaApi.getClient();
|
|
35
43
|
if (debug.enabled) {
|
|
36
44
|
debug(`Fetching product by ID: ${payload.identifier.key}`);
|
|
37
45
|
}
|
|
38
46
|
const response = await client.store.product.list(
|
|
39
|
-
|
|
40
|
-
external_id: payload.identifier.key,
|
|
41
|
-
limit: 1,
|
|
42
|
-
offset: 0,
|
|
43
|
-
fields: this.alwaysIncludedFields.join(",")
|
|
44
|
-
}
|
|
47
|
+
this.getByIdPayload(payload)
|
|
45
48
|
);
|
|
46
49
|
if (response.count === 0) {
|
|
47
50
|
return error({
|
|
@@ -51,17 +54,20 @@ class MedusaProductProvider extends ProductProvider {
|
|
|
51
54
|
}
|
|
52
55
|
return success(this.parseSingle(response.products[0]));
|
|
53
56
|
}
|
|
57
|
+
getBySlugPayload(payload) {
|
|
58
|
+
return {
|
|
59
|
+
handle: payload.slug,
|
|
60
|
+
limit: 1,
|
|
61
|
+
offset: 0,
|
|
62
|
+
fields: this.alwaysIncludedFields.join(",")
|
|
63
|
+
};
|
|
64
|
+
}
|
|
54
65
|
async getBySlug(payload) {
|
|
55
66
|
const client = await this.medusaApi.getClient();
|
|
56
67
|
if (debug.enabled) {
|
|
57
68
|
debug(`Fetching product by slug: ${payload.slug}`);
|
|
58
69
|
}
|
|
59
|
-
const response = await client.store.product.list(
|
|
60
|
-
handle: payload.slug,
|
|
61
|
-
limit: 1,
|
|
62
|
-
offset: 0,
|
|
63
|
-
fields: this.alwaysIncludedFields.join(",")
|
|
64
|
-
});
|
|
70
|
+
const response = await client.store.product.list(this.getBySlugPayload(payload));
|
|
65
71
|
if (debug.enabled) {
|
|
66
72
|
debug(`Found ${response.count} products for slug: ${payload.slug}`);
|
|
67
73
|
}
|
|
@@ -45,6 +45,13 @@ class MedusaProfileProvider extends ProfileProvider {
|
|
|
45
45
|
const model = this.parseSingle(customerResponse.customer);
|
|
46
46
|
return success(model);
|
|
47
47
|
}
|
|
48
|
+
updatePayload(payload) {
|
|
49
|
+
const updateData = {};
|
|
50
|
+
if (payload.phone !== void 0) {
|
|
51
|
+
updateData.phone = payload.phone;
|
|
52
|
+
}
|
|
53
|
+
return updateData;
|
|
54
|
+
}
|
|
48
55
|
async update(payload) {
|
|
49
56
|
debug("update", payload);
|
|
50
57
|
const client = await this.medusaApi.getClient();
|
|
@@ -56,16 +63,16 @@ class MedusaProfileProvider extends ProfileProvider {
|
|
|
56
63
|
});
|
|
57
64
|
}
|
|
58
65
|
const customer = customerResponse.customer;
|
|
59
|
-
const updatedResponse = await client.store.customer.update({
|
|
60
|
-
phone: payload.phone ?? customer.phone
|
|
61
|
-
}, { fields: this.includedFields.join(",") });
|
|
66
|
+
const updatedResponse = await client.store.customer.update(this.updatePayload(payload), { fields: this.includedFields.join(",") });
|
|
62
67
|
const model = this.parseSingle(updatedResponse.customer);
|
|
63
68
|
return success(model);
|
|
64
69
|
}
|
|
70
|
+
addShippingAddressPayload(payload) {
|
|
71
|
+
return this.createMedusaAddress(payload.address);
|
|
72
|
+
}
|
|
65
73
|
async addShippingAddress(payload) {
|
|
66
74
|
debug("addShippingAddress", payload);
|
|
67
75
|
const client = await this.medusaApi.getClient();
|
|
68
|
-
const medusaAddress = this.createMedusaAddress(payload.address);
|
|
69
76
|
const customer = await client.store.customer.retrieve({ fields: this.includedFields.join(",") });
|
|
70
77
|
if (!customer.customer) {
|
|
71
78
|
return error({
|
|
@@ -80,7 +87,7 @@ class MedusaProfileProvider extends ProfileProvider {
|
|
|
80
87
|
error: "Address with the same nickname already exists"
|
|
81
88
|
});
|
|
82
89
|
}
|
|
83
|
-
const response = await client.store.customer.createAddress(
|
|
90
|
+
const response = await client.store.customer.createAddress(this.addShippingAddressPayload(payload), { fields: this.includedFields.join(",") });
|
|
84
91
|
if (!response.customer) {
|
|
85
92
|
return error({
|
|
86
93
|
type: "InvalidInput",
|
|
@@ -90,6 +97,9 @@ class MedusaProfileProvider extends ProfileProvider {
|
|
|
90
97
|
const model = this.parseSingle(response.customer);
|
|
91
98
|
return success(model);
|
|
92
99
|
}
|
|
100
|
+
updateShippingAddressPayload(payload) {
|
|
101
|
+
return this.createMedusaAddress(payload.address);
|
|
102
|
+
}
|
|
93
103
|
async updateShippingAddress(payload) {
|
|
94
104
|
debug("updateShippingAddress", payload);
|
|
95
105
|
const client = await this.medusaApi.getClient();
|
|
@@ -100,7 +110,6 @@ class MedusaProfileProvider extends ProfileProvider {
|
|
|
100
110
|
identifier: payload.identifier
|
|
101
111
|
});
|
|
102
112
|
}
|
|
103
|
-
const medusaAddress = this.createMedusaAddress(payload.address);
|
|
104
113
|
const existingAddress = customer.customer.addresses.find((addr) => addr.address_name === payload.address.identifier.nickName);
|
|
105
114
|
if (!existingAddress) {
|
|
106
115
|
return error({
|
|
@@ -108,7 +117,7 @@ class MedusaProfileProvider extends ProfileProvider {
|
|
|
108
117
|
identifier: payload.address.identifier
|
|
109
118
|
});
|
|
110
119
|
}
|
|
111
|
-
const response = await client.store.customer.updateAddress(existingAddress.id,
|
|
120
|
+
const response = await client.store.customer.updateAddress(existingAddress.id, this.updateShippingAddressPayload(payload), { fields: this.includedFields.join(",") });
|
|
112
121
|
if (!response.customer) {
|
|
113
122
|
return error({
|
|
114
123
|
type: "InvalidInput",
|
|
@@ -146,6 +155,11 @@ class MedusaProfileProvider extends ProfileProvider {
|
|
|
146
155
|
const model = this.parseSingle(customerAfterDelete.customer);
|
|
147
156
|
return success(model);
|
|
148
157
|
}
|
|
158
|
+
makeShippingAddressDefaultPayload(payload) {
|
|
159
|
+
return {
|
|
160
|
+
is_default_shipping: true
|
|
161
|
+
};
|
|
162
|
+
}
|
|
149
163
|
async makeShippingAddressDefault(payload) {
|
|
150
164
|
debug("makeShippingAddressDefault", payload);
|
|
151
165
|
const client = await this.medusaApi.getClient();
|
|
@@ -165,14 +179,17 @@ class MedusaProfileProvider extends ProfileProvider {
|
|
|
165
179
|
}
|
|
166
180
|
const response = await client.store.customer.updateAddress(
|
|
167
181
|
existingAddress.id,
|
|
168
|
-
|
|
169
|
-
is_default_shipping: true
|
|
170
|
-
},
|
|
182
|
+
this.makeShippingAddressDefaultPayload(payload),
|
|
171
183
|
{ fields: this.includedFields.join(",") }
|
|
172
184
|
);
|
|
173
185
|
const model = this.parseSingle(response.customer);
|
|
174
186
|
return success(model);
|
|
175
187
|
}
|
|
188
|
+
setBillingAddressPayload(payload) {
|
|
189
|
+
const newAddr = this.createMedusaAddress(payload.address);
|
|
190
|
+
newAddr.is_default_billing = true;
|
|
191
|
+
return newAddr;
|
|
192
|
+
}
|
|
176
193
|
async setBillingAddress(payload) {
|
|
177
194
|
debug("setBillingAddress", payload);
|
|
178
195
|
const client = await this.medusaApi.getClient();
|
|
@@ -191,8 +208,7 @@ class MedusaProfileProvider extends ProfileProvider {
|
|
|
191
208
|
error: "Another address with the same nickname already exists"
|
|
192
209
|
});
|
|
193
210
|
}
|
|
194
|
-
const newAddr = this.
|
|
195
|
-
newAddr.is_default_billing = true;
|
|
211
|
+
const newAddr = this.setBillingAddressPayload(payload);
|
|
196
212
|
const existingBillingAddress = customer.addresses.find((addr) => addr.is_default_billing);
|
|
197
213
|
if (existingBillingAddress) {
|
|
198
214
|
const updateAddressResponse = await client.store.customer.updateAddress(existingBillingAddress.id, newAddr, { fields: this.includedFields.join(",") });
|
|
@@ -2,7 +2,7 @@ import type { Cache, Cart, CartIdentifier, CartItem, CartMutationApplyCoupon, Ca
|
|
|
2
2
|
import { CartProvider } from '@reactionary/core';
|
|
3
3
|
import type { MedusaAPI } from '../core/client.js';
|
|
4
4
|
import type { MedusaConfiguration } from '../schema/configuration.schema.js';
|
|
5
|
-
import type
|
|
5
|
+
import type { StoreAddCartLineItem, StoreCart, StoreCartAddPromotion, StoreCartLineItem, StoreCartRemovePromotion, StoreCreateCart, StoreUpdateCart, StoreUpdateCartLineItem } from '@medusajs/types';
|
|
6
6
|
export declare class MedusaCartProvider extends CartProvider {
|
|
7
7
|
medusaApi: MedusaAPI;
|
|
8
8
|
protected config: MedusaConfiguration;
|
|
@@ -15,14 +15,53 @@ export declare class MedusaCartProvider extends CartProvider {
|
|
|
15
15
|
protected includedFields: string;
|
|
16
16
|
constructor(config: MedusaConfiguration, cache: Cache, context: RequestContext, medusaApi: MedusaAPI);
|
|
17
17
|
getById(payload: CartQueryById): Promise<Result<Cart, NotFoundError>>;
|
|
18
|
+
/**
|
|
19
|
+
* Extension point for the `add` operation to control the payload sent to Medusa when adding an item to the cart. By default, it only includes the variant ID and quantity, but you can override it to include more fields as needed.
|
|
20
|
+
*
|
|
21
|
+
* @param payload
|
|
22
|
+
* @param variantId
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
protected addPayload(payload: CartMutationItemAdd, variantId: string): StoreAddCartLineItem;
|
|
18
26
|
add(payload: CartMutationItemAdd): Promise<Result<Cart>>;
|
|
19
27
|
remove(payload: CartMutationItemRemove): Promise<Result<Cart>>;
|
|
28
|
+
/**
|
|
29
|
+
* Extension point for the `changeQuantity` operation to control the payload sent to Medusa when changing the quantity of an item in the cart. By default, it only includes the new quantity, but you can override it to include more fields as needed.
|
|
30
|
+
* @param payload
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
protected changeQuantityPayload(payload: CartMutationItemQuantityChange): StoreUpdateCartLineItem;
|
|
20
34
|
changeQuantity(payload: CartMutationItemQuantityChange): Promise<Result<Cart>>;
|
|
21
35
|
getActiveCartId(): Promise<Result<CartIdentifier, NotFoundError>>;
|
|
22
36
|
deleteCart(payload: CartMutationDeleteCart): Promise<Result<void>>;
|
|
37
|
+
/**
|
|
38
|
+
* Extension point to apply a coupon code to the cart. By default, it only includes the coupon code, but you can override it to include more fields as needed.
|
|
39
|
+
* @param payload
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
protected applyCouponCodePayload(payload: CartMutationApplyCoupon): StoreCartAddPromotion;
|
|
23
43
|
applyCouponCode(payload: CartMutationApplyCoupon): Promise<Result<Cart>>;
|
|
44
|
+
/**
|
|
45
|
+
* Extension point to remove a coupon code from the cart. By default, it only includes the coupon code to be removed, but you can override it to include more fields as needed.
|
|
46
|
+
* @param payload
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
protected removeCouponCodePayload(payload: CartMutationRemoveCoupon): StoreCartRemovePromotion;
|
|
24
50
|
removeCouponCode(payload: CartMutationRemoveCoupon): Promise<Result<Cart>>;
|
|
51
|
+
/**
|
|
52
|
+
* Extension point to control the payload sent to Medusa when changing the currency of the cart. By default, it only includes the new region ID, but you can override it to include more fields as needed.
|
|
53
|
+
* @param payload
|
|
54
|
+
* @param newRegionId
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
protected changeCurrencyPayload(payload: CartMutationChangeCurrency, newRegionId: string): StoreUpdateCart;
|
|
25
58
|
changeCurrency(payload: CartMutationChangeCurrency): Promise<Result<Cart>>;
|
|
59
|
+
/**
|
|
60
|
+
* Extension point to control the payload sent to Medusa when creating a cart. By default, it only includes the currency code, but you can override it to include more fields as needed.
|
|
61
|
+
* @param currency
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
protected createCartPayload(currency?: string): StoreCreateCart;
|
|
26
65
|
protected createCart(currency?: string): Promise<CartIdentifier>;
|
|
27
66
|
protected getClient(): Promise<{
|
|
28
67
|
client: import("@medusajs/js-sdk").Client;
|
|
@@ -36,24 +75,24 @@ export declare class MedusaCartProvider extends CartProvider {
|
|
|
36
75
|
* @param currency
|
|
37
76
|
* @returns
|
|
38
77
|
*/
|
|
39
|
-
protected parseItemPrice(remoteItem:
|
|
78
|
+
protected parseItemPrice(remoteItem: StoreCartLineItem, currency: Currency): ItemCostBreakdown;
|
|
40
79
|
/**
|
|
41
80
|
* Extension point to control the parsing of the cost breakdown of a cart
|
|
42
81
|
* @param remote
|
|
43
82
|
* @returns
|
|
44
83
|
*/
|
|
45
|
-
protected parseCostBreakdown(remote:
|
|
84
|
+
protected parseCostBreakdown(remote: StoreCart): CostBreakDown;
|
|
46
85
|
/**
|
|
47
86
|
* Extension point to control the parsing of a single cart item
|
|
48
87
|
* @param remoteItem
|
|
49
88
|
* @param currency
|
|
50
89
|
* @returns
|
|
51
90
|
*/
|
|
52
|
-
protected parseCartItem(remoteItem:
|
|
91
|
+
protected parseCartItem(remoteItem: StoreCartLineItem, currency: Currency): CartItem;
|
|
53
92
|
/**
|
|
54
93
|
* Extension point to control the parsing of a single cart
|
|
55
94
|
* @param remote
|
|
56
95
|
* @returns
|
|
57
96
|
*/
|
|
58
|
-
protected parseSingle(remote:
|
|
97
|
+
protected parseSingle(remote: StoreCart): Cart;
|
|
59
98
|
}
|
|
@@ -8,8 +8,19 @@ export declare class MedusaCategoryProvider extends CategoryProvider {
|
|
|
8
8
|
constructor(config: MedusaConfiguration, cache: Cache, context: RequestContext, medusaApi: MedusaAPI);
|
|
9
9
|
protected resolveCategoryIdByExternalId(externalId: string): Promise<StoreProductCategory | null>;
|
|
10
10
|
getById(payload: CategoryQueryById): Promise<Result<Category, NotFoundError>>;
|
|
11
|
+
protected getBySlugPayload(payload: CategoryQueryBySlug): {
|
|
12
|
+
handle: string;
|
|
13
|
+
limit: number;
|
|
14
|
+
offset: number;
|
|
15
|
+
};
|
|
11
16
|
getBySlug(payload: CategoryQueryBySlug): Promise<Result<Category, NotFoundError>>;
|
|
12
17
|
getBreadcrumbPathToCategory(payload: CategoryQueryForBreadcrumb): Promise<Result<Category[]>>;
|
|
18
|
+
protected findChildCategoriesPayload(payload: CategoryQueryForChildCategories, actualParent: StoreProductCategory): {
|
|
19
|
+
fields: string;
|
|
20
|
+
parent_category_id: string;
|
|
21
|
+
limit: number;
|
|
22
|
+
offset: number;
|
|
23
|
+
};
|
|
13
24
|
findChildCategories(payload: CategoryQueryForChildCategories): Promise<import("@reactionary/core").Ok<{
|
|
14
25
|
pageNumber: number;
|
|
15
26
|
pageSize: number;
|
|
@@ -17,6 +28,12 @@ export declare class MedusaCategoryProvider extends CategoryProvider {
|
|
|
17
28
|
totalPages: number;
|
|
18
29
|
items: Category[];
|
|
19
30
|
}>>;
|
|
31
|
+
protected findTopCategoriesPayload(payload: CategoryQueryForTopCategories): {
|
|
32
|
+
fields: string;
|
|
33
|
+
parent_category_id: string;
|
|
34
|
+
limit: number;
|
|
35
|
+
offset: number;
|
|
36
|
+
};
|
|
20
37
|
findTopCategories(payload: CategoryQueryForTopCategories): Promise<import("@reactionary/core").Ok<{
|
|
21
38
|
pageNumber: number;
|
|
22
39
|
pageSize: number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { StoreCart, StoreCartAddress, StoreCartLineItem } from '@medusajs/types';
|
|
1
|
+
import type { StoreAddCartShippingMethods, StoreCart, StoreCartAddress, StoreCartLineItem, StoreInitializePaymentSession, StoreUpdateCart } from '@medusajs/types';
|
|
2
2
|
import type { Address, Cache, Checkout, CheckoutIdentifier, CheckoutItem, CheckoutMutationAddPaymentInstruction, CheckoutMutationFinalizeCheckout, CheckoutMutationInitiateCheckout, CheckoutMutationRemovePaymentInstruction, CheckoutMutationSetShippingAddress, CheckoutMutationSetShippingInstruction, CheckoutQueryById, CheckoutQueryForAvailablePaymentMethods, CheckoutQueryForAvailableShippingMethods, CostBreakDown, Currency, ItemCostBreakdown, PaymentMethod, RequestContext, ShippingMethod, Result, NotFoundError } from '@reactionary/core';
|
|
3
3
|
import { CheckoutProvider } from '@reactionary/core';
|
|
4
4
|
import type { MedusaAPI } from '../core/client.js';
|
|
@@ -18,13 +18,23 @@ export declare class MedusaCheckoutProvider extends CheckoutProvider {
|
|
|
18
18
|
*/
|
|
19
19
|
protected includedFields: string;
|
|
20
20
|
constructor(config: MedusaConfiguration, cache: Cache, context: RequestContext, medusaApi: MedusaAPI);
|
|
21
|
+
protected initiateCheckoutForCartPayload(payload: CheckoutMutationInitiateCheckout): StoreUpdateCart;
|
|
21
22
|
initiateCheckoutForCart(payload: CheckoutMutationInitiateCheckout): Promise<Result<Checkout>>;
|
|
22
23
|
getById(payload: CheckoutQueryById): Promise<Result<Checkout, NotFoundError>>;
|
|
24
|
+
protected setShippingAddressPayload(payload: CheckoutMutationSetShippingAddress): StoreUpdateCart;
|
|
23
25
|
setShippingAddress(payload: CheckoutMutationSetShippingAddress): Promise<Result<Checkout>>;
|
|
26
|
+
protected getAvailableShippingMethodsPayload(payload: CheckoutQueryForAvailableShippingMethods): {
|
|
27
|
+
cart_id: string;
|
|
28
|
+
};
|
|
24
29
|
getAvailableShippingMethods(payload: CheckoutQueryForAvailableShippingMethods): Promise<Result<ShippingMethod[]>>;
|
|
30
|
+
protected getAvailablePaymentMethodsPayload(payload: CheckoutQueryForAvailablePaymentMethods, regionId: string): {
|
|
31
|
+
region_id: string;
|
|
32
|
+
};
|
|
25
33
|
getAvailablePaymentMethods(payload: CheckoutQueryForAvailablePaymentMethods): Promise<Result<PaymentMethod[]>>;
|
|
34
|
+
protected addPaymentInstructionPayload(payload: CheckoutMutationAddPaymentInstruction): StoreInitializePaymentSession;
|
|
26
35
|
addPaymentInstruction(payload: CheckoutMutationAddPaymentInstruction): Promise<Result<Checkout>>;
|
|
27
36
|
removePaymentInstruction(payload: CheckoutMutationRemovePaymentInstruction): Promise<Result<Checkout>>;
|
|
37
|
+
protected setShippingInstructionPayload(payload: CheckoutMutationSetShippingInstruction): StoreAddCartShippingMethods;
|
|
28
38
|
setShippingInstruction(payload: CheckoutMutationSetShippingInstruction): Promise<Result<Checkout>>;
|
|
29
39
|
finalizeCheckout(payload: CheckoutMutationFinalizeCheckout): Promise<Result<Checkout>>;
|
|
30
40
|
/**
|
|
@@ -7,6 +7,7 @@ export declare class MedusaOrderSearchProvider extends OrderSearchProvider {
|
|
|
7
7
|
medusaApi: MedusaAPI;
|
|
8
8
|
protected config: MedusaConfiguration;
|
|
9
9
|
constructor(config: MedusaConfiguration, cache: Cache, context: RequestContext, medusaApi: MedusaAPI);
|
|
10
|
+
protected queryByTermPayload(payload: OrderSearchQueryByTerm): any;
|
|
10
11
|
queryByTerm(payload: OrderSearchQueryByTerm): Promise<Result<OrderSearchResult>>;
|
|
11
12
|
protected composeAddressFromStoreAddress(storeAddress: StoreOrderAddress): Address;
|
|
12
13
|
protected parseSingle(body: StoreOrder): {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { StoreProduct, StoreProductVariant } from '@medusajs/types';
|
|
1
|
+
import type { StoreCollection, StoreProduct, StoreProductVariant } from '@medusajs/types';
|
|
2
2
|
import { ProductRecommendationsProvider, type Cache, type ProductRecommendation, type ProductRecommendationsByCollectionQuery, type ProductSearchResultItemVariant, type RequestContext, type Result } from '@reactionary/core';
|
|
3
3
|
import type { MedusaAPI } from '../core/client.js';
|
|
4
4
|
import type { MedusaConfiguration } from '../schema/configuration.schema.js';
|
|
@@ -16,6 +16,11 @@ export declare class MedusaProductRecommendationsProvider extends ProductRecomme
|
|
|
16
16
|
protected config: MedusaConfiguration;
|
|
17
17
|
protected medusaApi: MedusaAPI;
|
|
18
18
|
constructor(config: MedusaConfiguration, cache: Cache, context: RequestContext, medusaApi: MedusaAPI);
|
|
19
|
+
protected getCollectionPayload(query: ProductRecommendationsByCollectionQuery, collection: StoreCollection): {
|
|
20
|
+
collection_id: string[];
|
|
21
|
+
limit: number;
|
|
22
|
+
fields: string;
|
|
23
|
+
};
|
|
19
24
|
/**
|
|
20
25
|
* Get product recommendations from a Medusa collection
|
|
21
26
|
*
|
|
@@ -7,6 +7,7 @@ export declare class MedusaSearchProvider extends ProductSearchProvider {
|
|
|
7
7
|
protected config: MedusaConfiguration;
|
|
8
8
|
constructor(config: MedusaConfiguration, cache: Cache, context: RequestContext, medusaApi: MedusaAPI);
|
|
9
9
|
protected resolveCategoryIdByExternalId(externalId: string): Promise<StoreProductCategory | null>;
|
|
10
|
+
protected queryByTermPayload(payload: ProductSearchQueryByTerm, categoryIdToFind: string | null): any;
|
|
10
11
|
queryByTerm(payload: ProductSearchQueryByTerm): Promise<Result<ProductSearchResult>>;
|
|
11
12
|
protected parsePaginatedResult(remote: StoreProductListResponse): {
|
|
12
13
|
identifier: {
|
|
@@ -8,7 +8,19 @@ export declare class MedusaProductProvider extends ProductProvider {
|
|
|
8
8
|
protected config: MedusaConfiguration;
|
|
9
9
|
protected alwaysIncludedFields: string[];
|
|
10
10
|
constructor(config: MedusaConfiguration, cache: Cache, context: RequestContext, medusaApi: MedusaAPI);
|
|
11
|
+
protected getByIdPayload(payload: ProductQueryById): {
|
|
12
|
+
external_id: string;
|
|
13
|
+
limit: number;
|
|
14
|
+
offset: number;
|
|
15
|
+
fields: string;
|
|
16
|
+
};
|
|
11
17
|
getById(payload: ProductQueryById): Promise<Result<Product>>;
|
|
18
|
+
protected getBySlugPayload(payload: ProductQueryBySlug): {
|
|
19
|
+
handle: string;
|
|
20
|
+
limit: number;
|
|
21
|
+
offset: number;
|
|
22
|
+
fields: string;
|
|
23
|
+
};
|
|
12
24
|
getBySlug(payload: ProductQueryBySlug): Promise<Result<Product, NotFoundError>>;
|
|
13
25
|
getBySKU(payload: ProductQueryBySKU): Promise<Result<Product>>;
|
|
14
26
|
protected parseSingle(_body: StoreProduct): Product;
|
|
@@ -18,11 +18,18 @@ export declare class MedusaProfileProvider extends ProfileProvider {
|
|
|
18
18
|
protected includedFields: string[];
|
|
19
19
|
constructor(config: MedusaConfiguration, cache: Cache, context: RequestContext, medusaApi: MedusaAPI);
|
|
20
20
|
getById(payload: ProfileQueryById): Promise<Result<Profile, NotFoundError>>;
|
|
21
|
+
protected updatePayload(payload: ProfileMutationUpdate): any;
|
|
21
22
|
update(payload: ProfileMutationUpdate): Promise<Result<Profile, NotFoundError>>;
|
|
23
|
+
protected addShippingAddressPayload(payload: ProfileMutationAddShippingAddress): StoreCreateCustomerAddress;
|
|
22
24
|
addShippingAddress(payload: ProfileMutationAddShippingAddress): Promise<Result<Profile, NotFoundError>>;
|
|
25
|
+
protected updateShippingAddressPayload(payload: ProfileMutationUpdateShippingAddress): StoreCreateCustomerAddress;
|
|
23
26
|
updateShippingAddress(payload: ProfileMutationUpdateShippingAddress): Promise<Result<Profile, NotFoundError>>;
|
|
24
27
|
removeShippingAddress(payload: ProfileMutationRemoveShippingAddress): Promise<Result<Profile, NotFoundError>>;
|
|
28
|
+
protected makeShippingAddressDefaultPayload(payload: ProfileMutationMakeShippingAddressDefault): {
|
|
29
|
+
is_default_shipping: boolean;
|
|
30
|
+
};
|
|
25
31
|
makeShippingAddressDefault(payload: ProfileMutationMakeShippingAddressDefault): Promise<Result<Profile, NotFoundError>>;
|
|
32
|
+
protected setBillingAddressPayload(payload: ProfileMutationSetBillingAddress): StoreCreateCustomerAddress;
|
|
26
33
|
setBillingAddress(payload: ProfileMutationSetBillingAddress): Promise<Result<Profile, NotFoundError>>;
|
|
27
34
|
protected createMedusaAddress(address: Address): StoreCreateCustomerAddress;
|
|
28
35
|
protected parseAddress(address: StoreCustomerAddress): Address;
|