@reactionary/medusa 0.6.4 → 0.6.6
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/capabilities/cart.capability.js +7 -99
- package/capabilities/category.capability.js +29 -47
- package/capabilities/checkout.capability.js +19 -209
- package/capabilities/inventory.capability.js +10 -54
- package/capabilities/order-search.capability.js +2 -76
- package/capabilities/order.capability.js +2 -130
- package/capabilities/price.capability.js +3 -38
- package/capabilities/product-associations.capability.js +19 -54
- package/capabilities/product-search.capability.js +15 -67
- package/capabilities/product.capability.js +18 -131
- package/capabilities/profile.capability.js +14 -63
- package/factories/cart/cart.factory.js +91 -2
- package/factories/category/category.factory.js +33 -3
- package/factories/checkout/checkout.factory.js +187 -4
- package/factories/inventory/inventory.factory.js +19 -1
- package/factories/order/order.factory.js +128 -2
- package/factories/order-search/order-search.factory.js +75 -2
- package/factories/price/price.factory.js +31 -2
- package/factories/product/product.factory.js +155 -2
- package/factories/product-associations/product-associations.factory.js +38 -2
- package/factories/product-search/product-search.factory.js +51 -2
- package/factories/profile/profile.factory.js +54 -2
- package/package.json +2 -2
- package/src/capabilities/cart.capability.d.ts +2 -28
- package/src/capabilities/category.capability.d.ts +5 -7
- package/src/capabilities/checkout.capability.d.ts +3 -35
- package/src/capabilities/inventory.capability.d.ts +2 -12
- package/src/capabilities/order-search.capability.d.ts +2 -42
- package/src/capabilities/order.capability.d.ts +2 -39
- package/src/capabilities/price.capability.d.ts +1 -4
- package/src/capabilities/product-associations.capability.d.ts +3 -7
- package/src/capabilities/product-search.capability.d.ts +4 -34
- package/src/capabilities/product.capability.d.ts +1 -6
- package/src/capabilities/profile.capability.d.ts +3 -5
- package/src/factories/cart/cart.factory.d.ts +23 -2
- package/src/factories/category/category.factory.d.ts +4 -3
- package/src/factories/checkout/checkout.factory.d.ts +31 -4
- package/src/factories/inventory/inventory.factory.d.ts +7 -1
- package/src/factories/order/order.factory.d.ts +38 -2
- package/src/factories/order-search/order-search.factory.d.ts +20 -2
- package/src/factories/price/price.factory.d.ts +6 -1
- package/src/factories/product/product.factory.d.ts +6 -2
- package/src/factories/product-associations/product-associations.factory.d.ts +8 -2
- package/src/factories/product-search/product-search.factory.d.ts +5 -2
- package/src/factories/profile/profile.factory.d.ts +4 -2
|
@@ -11,13 +11,14 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
11
11
|
};
|
|
12
12
|
import {
|
|
13
13
|
InventoryCapability,
|
|
14
|
-
InventorySchema,
|
|
15
14
|
InventoryQueryBySKUSchema,
|
|
15
|
+
InventorySchema,
|
|
16
16
|
Reactionary,
|
|
17
|
-
success
|
|
17
|
+
success,
|
|
18
|
+
error
|
|
18
19
|
} from "@reactionary/core";
|
|
19
|
-
import { MedusaAdminAPI } from "../core/client.js";
|
|
20
20
|
import createDebug from "debug";
|
|
21
|
+
import { MedusaAdminAPI } from "../core/client.js";
|
|
21
22
|
const debug = createDebug("reactionary:medusa:inventory");
|
|
22
23
|
class MedusaInventoryCapability extends InventoryCapability {
|
|
23
24
|
constructor(config, cache, context, medusaApi, factory) {
|
|
@@ -45,7 +46,7 @@ class MedusaInventoryCapability extends InventoryCapability {
|
|
|
45
46
|
if (debug.enabled) {
|
|
46
47
|
debug(`No inventory items found for SKU: ${sku}`);
|
|
47
48
|
}
|
|
48
|
-
return
|
|
49
|
+
return error({ type: "NotFound", identifier: payload.variant });
|
|
49
50
|
}
|
|
50
51
|
const inventoryItem = inventoryResponse.inventory_items[0];
|
|
51
52
|
const locationsResponse = await adminClient.admin.stockLocation.list({
|
|
@@ -70,66 +71,21 @@ class MedusaInventoryCapability extends InventoryCapability {
|
|
|
70
71
|
if (debug.enabled) {
|
|
71
72
|
debug(`No stock location found with name: ${fulfillmentCenterKey}`);
|
|
72
73
|
}
|
|
73
|
-
return
|
|
74
|
+
return error({ type: "NotFound", identifier: payload.fulfilmentCenter });
|
|
74
75
|
}
|
|
75
|
-
return success(this.
|
|
76
|
+
return success(this.factory.parseInventory(this.context, {
|
|
76
77
|
sku: payload.variant.sku,
|
|
77
78
|
fulfillmentCenterKey,
|
|
78
79
|
quantity,
|
|
79
80
|
inventoryItemId: inventoryItem.id
|
|
80
81
|
}));
|
|
81
|
-
} catch (
|
|
82
|
+
} catch (err) {
|
|
82
83
|
if (debug.enabled) {
|
|
83
|
-
debug(`Error fetching inventory for SKU: ${sku}`,
|
|
84
|
+
debug(`Error fetching inventory for SKU: ${sku}`, err);
|
|
84
85
|
}
|
|
85
|
-
return
|
|
86
|
+
return error({ type: "NotFound", identifier: payload.variant });
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
|
-
parseSingle(_body) {
|
|
89
|
-
const { sku, fulfillmentCenterKey, quantity } = _body;
|
|
90
|
-
const identifier = {
|
|
91
|
-
variant: {
|
|
92
|
-
sku
|
|
93
|
-
},
|
|
94
|
-
fulfillmentCenter: {
|
|
95
|
-
key: fulfillmentCenterKey
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
let status = "outOfStock";
|
|
99
|
-
if (quantity > 0) {
|
|
100
|
-
status = "inStock";
|
|
101
|
-
}
|
|
102
|
-
const result = {
|
|
103
|
-
identifier,
|
|
104
|
-
quantity,
|
|
105
|
-
status
|
|
106
|
-
};
|
|
107
|
-
return this.factory.parseInventory(this.context, result);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Utility function to create an empty inventory result.
|
|
111
|
-
* This is used when no inventory is found for a given SKU + fulfillment center combination.
|
|
112
|
-
* @param sku
|
|
113
|
-
* @param fulfillmentCenterKey
|
|
114
|
-
* @returns
|
|
115
|
-
*/
|
|
116
|
-
createEmptyInventoryResult(sku, fulfillmentCenterKey) {
|
|
117
|
-
const identifier = {
|
|
118
|
-
variant: { sku },
|
|
119
|
-
fulfillmentCenter: { key: fulfillmentCenterKey }
|
|
120
|
-
};
|
|
121
|
-
const quantity = 0;
|
|
122
|
-
const status = "outOfStock";
|
|
123
|
-
const result = {
|
|
124
|
-
identifier,
|
|
125
|
-
quantity,
|
|
126
|
-
status
|
|
127
|
-
};
|
|
128
|
-
return this.factory.parseInventory(this.context, result);
|
|
129
|
-
}
|
|
130
|
-
getResourceName() {
|
|
131
|
-
return "inventory";
|
|
132
|
-
}
|
|
133
89
|
}
|
|
134
90
|
__decorateClass([
|
|
135
91
|
Reactionary({
|
|
@@ -10,7 +10,6 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
10
10
|
return result;
|
|
11
11
|
};
|
|
12
12
|
import {
|
|
13
|
-
AddressIdentifierSchema,
|
|
14
13
|
OrderSearchCapability,
|
|
15
14
|
OrderSearchQueryByTermSchema,
|
|
16
15
|
OrderSearchResultSchema,
|
|
@@ -68,86 +67,13 @@ class MedusaOrderSearchCapability extends OrderSearchCapability {
|
|
|
68
67
|
debug("queryByTerm", payload);
|
|
69
68
|
const medusa = await this.medusaApi.getClient();
|
|
70
69
|
const response = await medusa.store.order.list(this.queryByTermPayload(payload));
|
|
71
|
-
const result = this.
|
|
70
|
+
const result = this.factory.parseOrderSearchResult(this.context, response, payload);
|
|
72
71
|
if (debug.enabled) {
|
|
73
72
|
debug(
|
|
74
73
|
`Search for term "${payload.search.term}" returned ${response.orders.length} orders (page ${payload.search.paginationOptions.pageNumber} of ${result.totalPages})`
|
|
75
74
|
);
|
|
76
75
|
}
|
|
77
|
-
return success(
|
|
78
|
-
}
|
|
79
|
-
composeAddressFromStoreAddress(storeAddress) {
|
|
80
|
-
return {
|
|
81
|
-
identifier: AddressIdentifierSchema.parse({
|
|
82
|
-
nickName: storeAddress.id
|
|
83
|
-
}),
|
|
84
|
-
firstName: storeAddress.first_name || "",
|
|
85
|
-
lastName: storeAddress.last_name || "",
|
|
86
|
-
streetAddress: storeAddress.address_1 || "",
|
|
87
|
-
streetNumber: storeAddress.address_2 || "",
|
|
88
|
-
city: storeAddress.city || "",
|
|
89
|
-
postalCode: storeAddress.postal_code || "",
|
|
90
|
-
countryCode: storeAddress.country_code || "",
|
|
91
|
-
region: ""
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
parseSingle(body) {
|
|
95
|
-
const identifier = { key: body.id };
|
|
96
|
-
const userId = {
|
|
97
|
-
userId: body.customer_id || ""
|
|
98
|
-
};
|
|
99
|
-
const customerName = `${body.billing_address?.first_name} ${body.billing_address?.last_name}`;
|
|
100
|
-
const shippingAddress = this.composeAddressFromStoreAddress(body.shipping_address);
|
|
101
|
-
const orderDate = new Date(body.created_at).toISOString();
|
|
102
|
-
let orderStatus = "AwaitingPayment";
|
|
103
|
-
if (body.status === "draft") {
|
|
104
|
-
orderStatus = "AwaitingPayment";
|
|
105
|
-
}
|
|
106
|
-
if (body.status === "pending") {
|
|
107
|
-
orderStatus = "ReleasedToFulfillment";
|
|
108
|
-
}
|
|
109
|
-
if (body.status === "completed") {
|
|
110
|
-
orderStatus = "Shipped";
|
|
111
|
-
}
|
|
112
|
-
if (body.status === "canceled") {
|
|
113
|
-
orderStatus = "Cancelled";
|
|
114
|
-
}
|
|
115
|
-
let inventoryStatus = "NotAllocated";
|
|
116
|
-
if (body.fulfillment_status === "fulfilled") {
|
|
117
|
-
inventoryStatus = "Allocated";
|
|
118
|
-
}
|
|
119
|
-
const totalAmount = {
|
|
120
|
-
currency: body.currency_code.toUpperCase(),
|
|
121
|
-
value: body.total ? body.total : 0
|
|
122
|
-
};
|
|
123
|
-
const order = {
|
|
124
|
-
identifier,
|
|
125
|
-
userId,
|
|
126
|
-
customerName,
|
|
127
|
-
shippingAddress,
|
|
128
|
-
orderDate,
|
|
129
|
-
orderStatus,
|
|
130
|
-
inventoryStatus,
|
|
131
|
-
totalAmount
|
|
132
|
-
};
|
|
133
|
-
return order;
|
|
134
|
-
}
|
|
135
|
-
parsePaginatedResult(body, query) {
|
|
136
|
-
const identifier = {
|
|
137
|
-
...query.search
|
|
138
|
-
};
|
|
139
|
-
const orders = body.orders.map((o) => {
|
|
140
|
-
return this.parseSingle(o);
|
|
141
|
-
});
|
|
142
|
-
const result = {
|
|
143
|
-
identifier,
|
|
144
|
-
pageNumber: (Math.ceil(body.offset / body.limit) || 0) + 1,
|
|
145
|
-
pageSize: body.limit,
|
|
146
|
-
totalCount: body.count,
|
|
147
|
-
totalPages: Math.ceil(body.count / body.limit || 0) + 1,
|
|
148
|
-
items: orders
|
|
149
|
-
};
|
|
150
|
-
return result;
|
|
76
|
+
return success(result);
|
|
151
77
|
}
|
|
152
78
|
}
|
|
153
79
|
__decorateClass([
|
|
@@ -14,13 +14,10 @@ import {
|
|
|
14
14
|
OrderQueryByIdSchema,
|
|
15
15
|
OrderSchema,
|
|
16
16
|
Reactionary,
|
|
17
|
-
success
|
|
18
|
-
error,
|
|
19
|
-
ProductVariantIdentifierSchema
|
|
17
|
+
success
|
|
20
18
|
} from "@reactionary/core";
|
|
21
19
|
import createDebug from "debug";
|
|
22
20
|
import { handleProviderError } from "../utils/medusa-helpers.js";
|
|
23
|
-
import { parseMedusaItemPrice, parseMedusaCostBreakdown } from "../utils/medusa-helpers.js";
|
|
24
21
|
const debug = createDebug("reactionary:medusa:order");
|
|
25
22
|
class MedusaOrderCapability extends OrderCapability {
|
|
26
23
|
constructor(config, cache, context, medusaApi, factory) {
|
|
@@ -36,137 +33,12 @@ class MedusaOrderCapability extends OrderCapability {
|
|
|
36
33
|
const medusa = await this.medusaApi.getClient();
|
|
37
34
|
try {
|
|
38
35
|
const response = await medusa.store.order.retrieve(payload.order.key);
|
|
39
|
-
const order = this.
|
|
36
|
+
const order = this.factory.parseOrder(this.context, response.order);
|
|
40
37
|
return success(order);
|
|
41
38
|
} catch (err) {
|
|
42
39
|
return handleProviderError("order", err);
|
|
43
40
|
}
|
|
44
41
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Extension point to control the parsing of a single cart item price
|
|
47
|
-
* @param remoteItem
|
|
48
|
-
* @param currency
|
|
49
|
-
* @returns
|
|
50
|
-
*/
|
|
51
|
-
parseItemPrice(remoteItem, currency) {
|
|
52
|
-
return parseMedusaItemPrice(remoteItem, currency);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Extension point to control the parsing of the cost breakdown of a cart
|
|
56
|
-
* @param remote
|
|
57
|
-
* @returns
|
|
58
|
-
*/
|
|
59
|
-
parseCostBreakdown(remote) {
|
|
60
|
-
return parseMedusaCostBreakdown(remote);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Extension point to control the parsing of a single cart item
|
|
64
|
-
* @param remoteItem
|
|
65
|
-
* @param currency
|
|
66
|
-
* @returns
|
|
67
|
-
*/
|
|
68
|
-
parseOrderItem(remoteItem, currency) {
|
|
69
|
-
const item = {
|
|
70
|
-
identifier: {
|
|
71
|
-
key: remoteItem.id
|
|
72
|
-
},
|
|
73
|
-
variant: ProductVariantIdentifierSchema.parse({
|
|
74
|
-
sku: remoteItem.variant_sku || ""
|
|
75
|
-
}),
|
|
76
|
-
quantity: remoteItem.quantity || 1,
|
|
77
|
-
price: this.parseItemPrice(remoteItem, currency),
|
|
78
|
-
inventoryStatus: "Allocated"
|
|
79
|
-
};
|
|
80
|
-
return item;
|
|
81
|
-
}
|
|
82
|
-
parsePaymentInstruction(remotePayment, order) {
|
|
83
|
-
const paymentMethodIdentifier = {
|
|
84
|
-
method: remotePayment.payment_providers?.[0]?.id || "unknown",
|
|
85
|
-
name: remotePayment.payment_providers?.[0]?.id || "unknown",
|
|
86
|
-
paymentProcessor: remotePayment.payment_providers?.[0]?.id || "unknown"
|
|
87
|
-
};
|
|
88
|
-
let status = "pending";
|
|
89
|
-
switch (remotePayment.status) {
|
|
90
|
-
case "not_paid":
|
|
91
|
-
status = "pending";
|
|
92
|
-
break;
|
|
93
|
-
case "awaiting":
|
|
94
|
-
status = "pending";
|
|
95
|
-
break;
|
|
96
|
-
case "authorized":
|
|
97
|
-
status = "authorized";
|
|
98
|
-
break;
|
|
99
|
-
case "partially_authorized":
|
|
100
|
-
status = "pending";
|
|
101
|
-
break;
|
|
102
|
-
case "canceled":
|
|
103
|
-
status = "canceled";
|
|
104
|
-
break;
|
|
105
|
-
case "failed":
|
|
106
|
-
status = "canceled";
|
|
107
|
-
break;
|
|
108
|
-
case "completed":
|
|
109
|
-
status = "capture";
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
const paymentData = remotePayment.payments?.[0].data || {};
|
|
113
|
-
const pi = {
|
|
114
|
-
identifier: {
|
|
115
|
-
key: remotePayment.id
|
|
116
|
-
},
|
|
117
|
-
amount: {
|
|
118
|
-
value: remotePayment.amount,
|
|
119
|
-
currency: remotePayment.currency_code?.toUpperCase()
|
|
120
|
-
},
|
|
121
|
-
paymentMethod: paymentMethodIdentifier,
|
|
122
|
-
protocolData: paymentData ? Object.entries(paymentData).map(([key, value]) => ({
|
|
123
|
-
key,
|
|
124
|
-
value: String(value)
|
|
125
|
-
})) : [],
|
|
126
|
-
status
|
|
127
|
-
};
|
|
128
|
-
return pi;
|
|
129
|
-
}
|
|
130
|
-
parseSingle(body) {
|
|
131
|
-
const identifier = { key: body.id };
|
|
132
|
-
const userId = {
|
|
133
|
-
userId: body.customer_id || ""
|
|
134
|
-
};
|
|
135
|
-
const items = (body.items || []).map((item) => {
|
|
136
|
-
return this.parseOrderItem(item, body.currency_code.toUpperCase());
|
|
137
|
-
});
|
|
138
|
-
const price = this.parseCostBreakdown(body);
|
|
139
|
-
let orderStatus = "AwaitingPayment";
|
|
140
|
-
if (body.status === "draft") {
|
|
141
|
-
orderStatus = "AwaitingPayment";
|
|
142
|
-
}
|
|
143
|
-
if (body.status === "pending") {
|
|
144
|
-
orderStatus = "ReleasedToFulfillment";
|
|
145
|
-
}
|
|
146
|
-
if (body.status === "completed") {
|
|
147
|
-
orderStatus = "Shipped";
|
|
148
|
-
}
|
|
149
|
-
if (body.status === "canceled") {
|
|
150
|
-
orderStatus = "Cancelled";
|
|
151
|
-
}
|
|
152
|
-
let inventoryStatus = "NotAllocated";
|
|
153
|
-
if (body.fulfillment_status === "fulfilled") {
|
|
154
|
-
inventoryStatus = "Allocated";
|
|
155
|
-
}
|
|
156
|
-
const paymentInstructions = body.payment_collections?.map((pc) => {
|
|
157
|
-
return this.parsePaymentInstruction(pc, body);
|
|
158
|
-
}) || [];
|
|
159
|
-
const result = {
|
|
160
|
-
identifier,
|
|
161
|
-
userId,
|
|
162
|
-
items,
|
|
163
|
-
price,
|
|
164
|
-
orderStatus,
|
|
165
|
-
inventoryStatus,
|
|
166
|
-
paymentInstructions
|
|
167
|
-
};
|
|
168
|
-
return this.factory.parseOrder(this.context, result);
|
|
169
|
-
}
|
|
170
42
|
}
|
|
171
43
|
__decorateClass([
|
|
172
44
|
Reactionary({
|
|
@@ -10,10 +10,10 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
10
10
|
return result;
|
|
11
11
|
};
|
|
12
12
|
import {
|
|
13
|
-
PriceCapability,
|
|
14
|
-
PriceSchema,
|
|
15
13
|
CustomerPriceQuerySchema,
|
|
16
14
|
ListPriceQuerySchema,
|
|
15
|
+
PriceCapability,
|
|
16
|
+
PriceSchema,
|
|
17
17
|
Reactionary,
|
|
18
18
|
success
|
|
19
19
|
} from "@reactionary/core";
|
|
@@ -57,7 +57,7 @@ class MedusaPriceCapability extends PriceCapability {
|
|
|
57
57
|
}
|
|
58
58
|
return this.createEmptyPriceResult(sku);
|
|
59
59
|
}
|
|
60
|
-
return this.
|
|
60
|
+
return this.factory.parsePrice(this.context, { variant, mode });
|
|
61
61
|
} catch (error) {
|
|
62
62
|
if (debug.enabled) {
|
|
63
63
|
debug(
|
|
@@ -67,41 +67,6 @@ class MedusaPriceCapability extends PriceCapability {
|
|
|
67
67
|
return this.createEmptyPriceResult(sku);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
parseSingle(variant, mode) {
|
|
71
|
-
const identifier = {
|
|
72
|
-
variant: {
|
|
73
|
-
sku: variant.sku || ""
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
const calculatedPrice = variant.calculated_price;
|
|
77
|
-
let unitPrice;
|
|
78
|
-
let isOnSale = false;
|
|
79
|
-
if (calculatedPrice) {
|
|
80
|
-
const priceToUse = mode === "customer" ? calculatedPrice.calculated_amount : calculatedPrice.original_amount;
|
|
81
|
-
if (mode === "customer") {
|
|
82
|
-
isOnSale = calculatedPrice.calculated_price?.price_list_type === "sale";
|
|
83
|
-
}
|
|
84
|
-
unitPrice = {
|
|
85
|
-
value: priceToUse || 0,
|
|
86
|
-
currency: calculatedPrice.currency_code?.toUpperCase() || this.context.languageContext.currencyCode
|
|
87
|
-
};
|
|
88
|
-
} else {
|
|
89
|
-
unitPrice = {
|
|
90
|
-
value: -1,
|
|
91
|
-
currency: this.context.languageContext.currencyCode
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
const result = {
|
|
95
|
-
identifier,
|
|
96
|
-
tieredPrices: [],
|
|
97
|
-
unitPrice,
|
|
98
|
-
onSale: isOnSale
|
|
99
|
-
};
|
|
100
|
-
return this.factory.parsePrice(this.context, result);
|
|
101
|
-
}
|
|
102
|
-
getResourceName() {
|
|
103
|
-
return "price";
|
|
104
|
-
}
|
|
105
70
|
}
|
|
106
71
|
__decorateClass([
|
|
107
72
|
Reactionary({
|
|
@@ -12,9 +12,6 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
12
12
|
import {
|
|
13
13
|
ProductAssociationsCapability,
|
|
14
14
|
Reactionary,
|
|
15
|
-
ImageSchema,
|
|
16
|
-
ProductSearchResultItemVariantSchema,
|
|
17
|
-
ProductVariantIdentifierSchema,
|
|
18
15
|
success
|
|
19
16
|
} from "@reactionary/core";
|
|
20
17
|
class MedusaProductAssociationsCapability extends ProductAssociationsCapability {
|
|
@@ -54,69 +51,37 @@ class MedusaProductAssociationsCapability extends ProductAssociationsCapability
|
|
|
54
51
|
offset: 0,
|
|
55
52
|
limit: maxNumberOfAssociations
|
|
56
53
|
});
|
|
57
|
-
return associatedProductsResponse.products
|
|
54
|
+
return associatedProductsResponse.products || [];
|
|
58
55
|
}
|
|
59
56
|
async getAccessories(query) {
|
|
60
57
|
const associatedProducts = await this.fetchAssociatedProductsFor(query.forProduct, query.numberOfAccessories || 4, "reactionaryaccessories");
|
|
61
|
-
const result = associatedProducts.map((product) => ({
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
product
|
|
58
|
+
const result = associatedProducts.map((product) => this.factory.parseAssociation(this.context, {
|
|
59
|
+
product,
|
|
60
|
+
identifier: {
|
|
61
|
+
key: `${query.forProduct.key}-accessory-${product.external_id}`
|
|
62
|
+
}
|
|
67
63
|
}));
|
|
68
|
-
return success(result
|
|
64
|
+
return success(result);
|
|
69
65
|
}
|
|
70
66
|
async getSpareparts(query) {
|
|
71
67
|
const associatedProducts = await this.fetchAssociatedProductsFor(query.forProduct, query.numberOfSpareparts || 4, "reactionaryspareparts");
|
|
72
|
-
const result = associatedProducts.map((product) => ({
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
product
|
|
68
|
+
const result = associatedProducts.map((product) => this.factory.parseAssociation(this.context, {
|
|
69
|
+
product,
|
|
70
|
+
identifier: {
|
|
71
|
+
key: `${query.forProduct.key}-sparepart-${product.external_id}`
|
|
72
|
+
}
|
|
78
73
|
}));
|
|
79
|
-
return success(result
|
|
74
|
+
return success(result);
|
|
80
75
|
}
|
|
81
76
|
async getReplacements(query) {
|
|
82
77
|
const associatedProducts = await this.fetchAssociatedProductsFor(query.forProduct, query.numberOfReplacements || 4, "reactionaryreplacements");
|
|
83
|
-
const result = associatedProducts.map((product) => ({
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
product
|
|
78
|
+
const result = associatedProducts.map((product) => this.factory.parseAssociation(this.context, {
|
|
79
|
+
product,
|
|
80
|
+
identifier: {
|
|
81
|
+
key: `${query.forProduct.key}-replacement-${product.external_id}`
|
|
82
|
+
}
|
|
89
83
|
}));
|
|
90
|
-
return success(result
|
|
91
|
-
}
|
|
92
|
-
parseSingle(_body) {
|
|
93
|
-
const heroVariant = _body.variants?.[0];
|
|
94
|
-
const identifier = { key: _body.external_id || _body.id };
|
|
95
|
-
const slug = _body.handle;
|
|
96
|
-
const name = heroVariant?.title || _body.title;
|
|
97
|
-
const variants = [];
|
|
98
|
-
if (heroVariant) {
|
|
99
|
-
variants.push(this.parseVariant(heroVariant, _body));
|
|
100
|
-
}
|
|
101
|
-
const result = {
|
|
102
|
-
identifier,
|
|
103
|
-
name,
|
|
104
|
-
slug,
|
|
105
|
-
variants
|
|
106
|
-
};
|
|
107
|
-
return result;
|
|
108
|
-
}
|
|
109
|
-
parseVariant(variant, product) {
|
|
110
|
-
const img = ImageSchema.parse({
|
|
111
|
-
sourceUrl: product.images?.[0].url ?? "",
|
|
112
|
-
altText: product.title || void 0
|
|
113
|
-
});
|
|
114
|
-
return ProductSearchResultItemVariantSchema.parse({
|
|
115
|
-
variant: ProductVariantIdentifierSchema.parse({
|
|
116
|
-
sku: variant.sku || ""
|
|
117
|
-
}),
|
|
118
|
-
image: img
|
|
119
|
-
});
|
|
84
|
+
return success(result);
|
|
120
85
|
}
|
|
121
86
|
}
|
|
122
87
|
__decorateClass([
|
|
@@ -10,17 +10,12 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
10
10
|
return result;
|
|
11
11
|
};
|
|
12
12
|
import {
|
|
13
|
+
FacetIdentifierSchema,
|
|
14
|
+
FacetValueIdentifierSchema,
|
|
13
15
|
ProductSearchCapability,
|
|
14
16
|
ProductSearchQueryByTermSchema,
|
|
15
|
-
ImageSchema,
|
|
16
|
-
ProductVariantIdentifierSchema,
|
|
17
|
-
ProductVariantOptionSchema,
|
|
18
|
-
ProductOptionIdentifierSchema,
|
|
19
|
-
ProductSearchResultItemVariantSchema,
|
|
20
|
-
Reactionary,
|
|
21
17
|
ProductSearchResultSchema,
|
|
22
|
-
|
|
23
|
-
FacetIdentifierSchema,
|
|
18
|
+
Reactionary,
|
|
24
19
|
success
|
|
25
20
|
} from "@reactionary/core";
|
|
26
21
|
import createDebug from "debug";
|
|
@@ -74,6 +69,16 @@ class MedusaProductSearchCapability extends ProductSearchCapability {
|
|
|
74
69
|
offset: (payload.search.paginationOptions.pageNumber - 1) * payload.search.paginationOptions.pageSize
|
|
75
70
|
};
|
|
76
71
|
}
|
|
72
|
+
async createCategoryNavigationFilter(payload) {
|
|
73
|
+
const facetIdentifier = FacetIdentifierSchema.parse({
|
|
74
|
+
key: "categories"
|
|
75
|
+
});
|
|
76
|
+
const facetValueIdentifier = FacetValueIdentifierSchema.parse({
|
|
77
|
+
facet: facetIdentifier,
|
|
78
|
+
key: payload.categoryPath[payload.categoryPath.length - 1].identifier.key
|
|
79
|
+
});
|
|
80
|
+
return success(facetValueIdentifier);
|
|
81
|
+
}
|
|
77
82
|
async queryByTerm(payload) {
|
|
78
83
|
const client = await this.medusaApi.getClient();
|
|
79
84
|
let categoryIdToFind = null;
|
|
@@ -96,70 +101,13 @@ class MedusaProductSearchCapability extends ProductSearchCapability {
|
|
|
96
101
|
}
|
|
97
102
|
}
|
|
98
103
|
const response = await client.store.product.list(this.queryByTermPayload(payload, categoryIdToFind));
|
|
99
|
-
const result = this.
|
|
104
|
+
const result = this.factory.parseSearchResult(this.context, response, payload);
|
|
100
105
|
if (debug.enabled) {
|
|
101
106
|
debug(
|
|
102
107
|
`Search for term "${payload.search.term}" returned ${response.products.length} products (page ${payload.search.paginationOptions.pageNumber} of ${result.totalPages})`
|
|
103
108
|
);
|
|
104
109
|
}
|
|
105
|
-
return success(
|
|
106
|
-
}
|
|
107
|
-
parsePaginatedResult(remote, query) {
|
|
108
|
-
const products = remote.products.map(
|
|
109
|
-
(p) => this.parseSingle(p)
|
|
110
|
-
);
|
|
111
|
-
const result = {
|
|
112
|
-
identifier: {
|
|
113
|
-
...query.search
|
|
114
|
-
},
|
|
115
|
-
pageNumber: (Math.ceil(remote.offset / remote.limit) || 0) + 1,
|
|
116
|
-
pageSize: remote.limit,
|
|
117
|
-
totalCount: remote.count,
|
|
118
|
-
totalPages: Math.ceil(remote.count / remote.limit || 0) + 1,
|
|
119
|
-
items: products,
|
|
120
|
-
facets: []
|
|
121
|
-
};
|
|
122
|
-
result.facets = [];
|
|
123
|
-
return result;
|
|
124
|
-
}
|
|
125
|
-
parseSingle(_body) {
|
|
126
|
-
const heroVariant = _body.variants?.[0];
|
|
127
|
-
const identifier = { key: _body.external_id || _body.id };
|
|
128
|
-
const slug = _body.handle;
|
|
129
|
-
const name = heroVariant?.title || _body.title;
|
|
130
|
-
const variants = [];
|
|
131
|
-
if (heroVariant) {
|
|
132
|
-
variants.push(this.parseVariant(heroVariant, _body));
|
|
133
|
-
}
|
|
134
|
-
const result = {
|
|
135
|
-
identifier,
|
|
136
|
-
name,
|
|
137
|
-
slug,
|
|
138
|
-
variants
|
|
139
|
-
};
|
|
140
|
-
return result;
|
|
141
|
-
}
|
|
142
|
-
parseVariant(variant, product) {
|
|
143
|
-
const img = ImageSchema.parse({
|
|
144
|
-
sourceUrl: product.images?.[0].url ?? "",
|
|
145
|
-
altText: product.title || void 0
|
|
146
|
-
});
|
|
147
|
-
return ProductSearchResultItemVariantSchema.parse({
|
|
148
|
-
variant: ProductVariantIdentifierSchema.parse({
|
|
149
|
-
sku: variant.sku || ""
|
|
150
|
-
}),
|
|
151
|
-
image: img
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
async createCategoryNavigationFilter(payload) {
|
|
155
|
-
const facetIdentifier = FacetIdentifierSchema.parse({
|
|
156
|
-
key: "categories"
|
|
157
|
-
});
|
|
158
|
-
const facetValueIdentifier = FacetValueIdentifierSchema.parse({
|
|
159
|
-
facet: facetIdentifier,
|
|
160
|
-
key: payload.categoryPath[payload.categoryPath.length - 1].identifier.key
|
|
161
|
-
});
|
|
162
|
-
return success(facetValueIdentifier);
|
|
110
|
+
return success(result);
|
|
163
111
|
}
|
|
164
112
|
}
|
|
165
113
|
__decorateClass([
|