@reactionary/provider-medusa 0.2.2 → 0.2.3
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/core/initialize.js +13 -5
- package/index.js +2 -0
- package/package.json +2 -2
- package/providers/order-search.provider.js +157 -0
- package/providers/order.provider.js +175 -0
- package/schema/capabilities.schema.js +2 -0
- package/src/index.d.ts +2 -0
- package/src/providers/order-search.provider.d.ts +91 -0
- package/src/providers/order.provider.d.ts +51 -0
- package/src/schema/capabilities.schema.d.ts +2 -0
- package/src/utils/medusa-helpers.d.ts +2 -2
package/core/initialize.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { MedusaCartProvider } from "../providers/cart.provider.js";
|
|
2
|
+
import { MedusaCategoryProvider } from "../providers/category.provider.js";
|
|
3
|
+
import { MedusaCheckoutProvider } from "../providers/checkout.provider.js";
|
|
2
4
|
import { MedusaIdentityProvider } from "../providers/identity.provider.js";
|
|
3
5
|
import { MedusaInventoryProvider } from "../providers/inventory.provider.js";
|
|
6
|
+
import { MedusaOrderSearchProvider } from "../providers/order-search.provider.js";
|
|
7
|
+
import { MedusaOrderProvider } from "../providers/order.provider.js";
|
|
4
8
|
import { MedusaPriceProvider } from "../providers/price.provider.js";
|
|
5
|
-
import { MedusaCapabilitiesSchema } from "../schema/capabilities.schema.js";
|
|
6
|
-
import { MedusaConfigurationSchema } from "../schema/configuration.schema.js";
|
|
7
9
|
import { MedusaSearchProvider } from "../providers/product-search.provider.js";
|
|
8
10
|
import { MedusaProductProvider } from "../providers/product.provider.js";
|
|
9
|
-
import { MedusaClient } from "./client.js";
|
|
10
|
-
import { MedusaCategoryProvider } from "../providers/category.provider.js";
|
|
11
|
-
import { MedusaCheckoutProvider } from "../providers/checkout.provider.js";
|
|
12
11
|
import { MedusaProfileProvider } from "../providers/profile.provider.js";
|
|
12
|
+
import { MedusaCapabilitiesSchema } from "../schema/capabilities.schema.js";
|
|
13
|
+
import { MedusaConfigurationSchema } from "../schema/configuration.schema.js";
|
|
14
|
+
import { MedusaClient } from "./client.js";
|
|
13
15
|
function withMedusaCapabilities(configuration, capabilities) {
|
|
14
16
|
return (cache, context) => {
|
|
15
17
|
const client = {};
|
|
@@ -43,6 +45,12 @@ function withMedusaCapabilities(configuration, capabilities) {
|
|
|
43
45
|
if (caps.profile) {
|
|
44
46
|
client.profile = new MedusaProfileProvider(configuration, cache, context, medusaClient);
|
|
45
47
|
}
|
|
48
|
+
if (caps.order) {
|
|
49
|
+
client.order = new MedusaOrderProvider(configuration, cache, context, medusaClient);
|
|
50
|
+
}
|
|
51
|
+
if (caps.orderSearch) {
|
|
52
|
+
client.orderSearch = new MedusaOrderSearchProvider(configuration, cache, context, medusaClient);
|
|
53
|
+
}
|
|
46
54
|
return client;
|
|
47
55
|
};
|
|
48
56
|
}
|
package/index.js
CHANGED
|
@@ -6,6 +6,8 @@ export * from "./core/client.js";
|
|
|
6
6
|
export * from "./providers/cart.provider.js";
|
|
7
7
|
export * from "./providers/identity.provider.js";
|
|
8
8
|
export * from "./providers/inventory.provider.js";
|
|
9
|
+
export * from "./providers/order.provider.js";
|
|
10
|
+
export * from "./providers/order-search.provider.js";
|
|
9
11
|
export * from "./providers/price.provider.js";
|
|
10
12
|
export * from "./providers/product-search.provider.js";
|
|
11
13
|
export * from "./providers/profile.provider.js";
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/provider-medusa",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"zod": "4.1.9",
|
|
9
|
-
"@reactionary/core": "0.2.
|
|
9
|
+
"@reactionary/core": "0.2.3",
|
|
10
10
|
"@medusajs/js-sdk": "^2.0.0",
|
|
11
11
|
"debug": "^4.3.4",
|
|
12
12
|
"@medusajs/types": "^2.11.0",
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
import {
|
|
13
|
+
AddressIdentifierSchema,
|
|
14
|
+
OrderSearchProvider,
|
|
15
|
+
OrderSearchQueryByTermSchema,
|
|
16
|
+
OrderSearchResultSchema,
|
|
17
|
+
Reactionary,
|
|
18
|
+
success
|
|
19
|
+
} from "@reactionary/core";
|
|
20
|
+
import createDebug from "debug";
|
|
21
|
+
const debug = createDebug("reactionary:medusa:order-search");
|
|
22
|
+
class MedusaOrderSearchProvider extends OrderSearchProvider {
|
|
23
|
+
constructor(config, cache, context, client) {
|
|
24
|
+
super(cache, context);
|
|
25
|
+
this.config = config;
|
|
26
|
+
this.client = client;
|
|
27
|
+
}
|
|
28
|
+
async queryByTerm(payload) {
|
|
29
|
+
debug("queryByTerm", payload);
|
|
30
|
+
const medusa = await this.client.getClient();
|
|
31
|
+
if (payload.search.term) {
|
|
32
|
+
debug("Searching orders by term is not supported in Medusa");
|
|
33
|
+
}
|
|
34
|
+
if (payload.search.partNumber) {
|
|
35
|
+
debug("Searching orders by part number is not supported in Medusa");
|
|
36
|
+
}
|
|
37
|
+
if (payload.search.startDate) {
|
|
38
|
+
debug("Searching orders by start date is not supported in Medusa");
|
|
39
|
+
}
|
|
40
|
+
if (payload.search.endDate) {
|
|
41
|
+
debug("Searching orders by end date is not supported in Medusa");
|
|
42
|
+
}
|
|
43
|
+
if (payload.search.userId) {
|
|
44
|
+
debug("Searching orders by customer ID is not supported in Medusa");
|
|
45
|
+
}
|
|
46
|
+
const statusFilter = (payload.search.orderStatus ?? []).map((status) => {
|
|
47
|
+
let retStatus = "draft";
|
|
48
|
+
if (status === "AwaitingPayment") {
|
|
49
|
+
retStatus = "draft";
|
|
50
|
+
}
|
|
51
|
+
if (status === "ReleasedToFulfillment") {
|
|
52
|
+
retStatus = "pending";
|
|
53
|
+
}
|
|
54
|
+
if (status === "Shipped") {
|
|
55
|
+
retStatus = "completed";
|
|
56
|
+
}
|
|
57
|
+
if (status === "Cancelled") {
|
|
58
|
+
retStatus = "canceled";
|
|
59
|
+
}
|
|
60
|
+
return retStatus;
|
|
61
|
+
});
|
|
62
|
+
const response = await medusa.store.order.list({
|
|
63
|
+
status: statusFilter,
|
|
64
|
+
limit: payload.search.paginationOptions.pageSize,
|
|
65
|
+
offset: (payload.search.paginationOptions.pageNumber - 1) * payload.search.paginationOptions.pageSize
|
|
66
|
+
});
|
|
67
|
+
const result = this.parsePaginatedResult(response, payload);
|
|
68
|
+
if (debug.enabled) {
|
|
69
|
+
debug(
|
|
70
|
+
`Search for term "${payload.search.term}" returned ${response.orders.length} orders (page ${payload.search.paginationOptions.pageNumber} of ${result.totalPages})`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
return success(result);
|
|
74
|
+
}
|
|
75
|
+
composeAddressFromStoreAddress(storeAddress) {
|
|
76
|
+
return {
|
|
77
|
+
identifier: AddressIdentifierSchema.parse({
|
|
78
|
+
nickName: storeAddress.id
|
|
79
|
+
}),
|
|
80
|
+
firstName: storeAddress.first_name || "",
|
|
81
|
+
lastName: storeAddress.last_name || "",
|
|
82
|
+
streetAddress: storeAddress.address_1 || "",
|
|
83
|
+
streetNumber: storeAddress.address_2 || "",
|
|
84
|
+
city: storeAddress.city || "",
|
|
85
|
+
postalCode: storeAddress.postal_code || "",
|
|
86
|
+
countryCode: storeAddress.country_code || "",
|
|
87
|
+
region: ""
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
parseSingle(body) {
|
|
91
|
+
const identifier = { key: body.id };
|
|
92
|
+
const userId = {
|
|
93
|
+
userId: body.customer_id || ""
|
|
94
|
+
};
|
|
95
|
+
const customerName = `${body.billing_address?.first_name} ${body.billing_address?.last_name}`;
|
|
96
|
+
const shippingAddress = this.composeAddressFromStoreAddress(body.shipping_address);
|
|
97
|
+
const orderDate = new Date(body.created_at).toISOString();
|
|
98
|
+
let orderStatus = "AwaitingPayment";
|
|
99
|
+
if (body.status === "draft") {
|
|
100
|
+
orderStatus = "AwaitingPayment";
|
|
101
|
+
}
|
|
102
|
+
if (body.status === "pending") {
|
|
103
|
+
orderStatus = "ReleasedToFulfillment";
|
|
104
|
+
}
|
|
105
|
+
if (body.status === "completed") {
|
|
106
|
+
orderStatus = "Shipped";
|
|
107
|
+
}
|
|
108
|
+
if (body.status === "canceled") {
|
|
109
|
+
orderStatus = "Cancelled";
|
|
110
|
+
}
|
|
111
|
+
let inventoryStatus = "NotAllocated";
|
|
112
|
+
if (body.fulfillment_status === "fulfilled") {
|
|
113
|
+
inventoryStatus = "Allocated";
|
|
114
|
+
}
|
|
115
|
+
const totalAmount = {
|
|
116
|
+
currency: body.currency_code.toUpperCase(),
|
|
117
|
+
value: body.total ? body.total : 0
|
|
118
|
+
};
|
|
119
|
+
const order = {
|
|
120
|
+
identifier,
|
|
121
|
+
userId,
|
|
122
|
+
customerName,
|
|
123
|
+
shippingAddress,
|
|
124
|
+
orderDate,
|
|
125
|
+
orderStatus,
|
|
126
|
+
inventoryStatus,
|
|
127
|
+
totalAmount
|
|
128
|
+
};
|
|
129
|
+
return order;
|
|
130
|
+
}
|
|
131
|
+
parsePaginatedResult(body, query) {
|
|
132
|
+
const identifier = {
|
|
133
|
+
...query.search
|
|
134
|
+
};
|
|
135
|
+
const orders = body.orders.map((o) => {
|
|
136
|
+
return this.parseSingle(o);
|
|
137
|
+
});
|
|
138
|
+
const result = {
|
|
139
|
+
identifier,
|
|
140
|
+
pageNumber: (Math.ceil(body.offset / body.limit) || 0) + 1,
|
|
141
|
+
pageSize: body.limit,
|
|
142
|
+
totalCount: body.count,
|
|
143
|
+
totalPages: Math.ceil(body.count / body.limit || 0) + 1,
|
|
144
|
+
items: orders
|
|
145
|
+
};
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
__decorateClass([
|
|
150
|
+
Reactionary({
|
|
151
|
+
inputSchema: OrderSearchQueryByTermSchema,
|
|
152
|
+
outputSchema: OrderSearchResultSchema
|
|
153
|
+
})
|
|
154
|
+
], MedusaOrderSearchProvider.prototype, "queryByTerm", 1);
|
|
155
|
+
export {
|
|
156
|
+
MedusaOrderSearchProvider
|
|
157
|
+
};
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
import {
|
|
13
|
+
OrderProvider,
|
|
14
|
+
OrderQueryByIdSchema,
|
|
15
|
+
OrderSchema,
|
|
16
|
+
Reactionary,
|
|
17
|
+
success,
|
|
18
|
+
error,
|
|
19
|
+
ProductVariantIdentifierSchema
|
|
20
|
+
} from "@reactionary/core";
|
|
21
|
+
import createDebug from "debug";
|
|
22
|
+
import { handleProviderError } from "../utils/medusa-helpers.js";
|
|
23
|
+
import { parseMedusaItemPrice, parseMedusaCostBreakdown } from "../utils/medusa-helpers.js";
|
|
24
|
+
const debug = createDebug("reactionary:medusa:order");
|
|
25
|
+
class MedusaOrderProvider extends OrderProvider {
|
|
26
|
+
constructor(config, cache, context, client) {
|
|
27
|
+
super(cache, context);
|
|
28
|
+
this.config = config;
|
|
29
|
+
this.client = client;
|
|
30
|
+
}
|
|
31
|
+
async getById(payload) {
|
|
32
|
+
debug("getById", payload);
|
|
33
|
+
const medusa = await this.client.getClient();
|
|
34
|
+
try {
|
|
35
|
+
const response = await medusa.store.order.retrieve(payload.order.key);
|
|
36
|
+
const order = this.parseSingle(response.order);
|
|
37
|
+
return success(order);
|
|
38
|
+
} catch (err) {
|
|
39
|
+
return handleProviderError("order", err);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Extension point to control the parsing of a single cart item price
|
|
44
|
+
* @param remoteItem
|
|
45
|
+
* @param currency
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
parseItemPrice(remoteItem, currency) {
|
|
49
|
+
return parseMedusaItemPrice(remoteItem, currency);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Extension point to control the parsing of the cost breakdown of a cart
|
|
53
|
+
* @param remote
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
parseCostBreakdown(remote) {
|
|
57
|
+
return parseMedusaCostBreakdown(remote);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Extension point to control the parsing of a single cart item
|
|
61
|
+
* @param remoteItem
|
|
62
|
+
* @param currency
|
|
63
|
+
* @returns
|
|
64
|
+
*/
|
|
65
|
+
parseOrderItem(remoteItem, currency) {
|
|
66
|
+
const item = {
|
|
67
|
+
identifier: {
|
|
68
|
+
key: remoteItem.id
|
|
69
|
+
},
|
|
70
|
+
variant: ProductVariantIdentifierSchema.parse({
|
|
71
|
+
sku: remoteItem.variant_sku || ""
|
|
72
|
+
}),
|
|
73
|
+
quantity: remoteItem.quantity || 1,
|
|
74
|
+
price: this.parseItemPrice(remoteItem, currency),
|
|
75
|
+
inventoryStatus: "Allocated"
|
|
76
|
+
};
|
|
77
|
+
return item;
|
|
78
|
+
}
|
|
79
|
+
parsePaymentInstruction(remotePayment, order) {
|
|
80
|
+
const paymentMethodIdentifier = {
|
|
81
|
+
method: remotePayment.payment_providers?.[0]?.id || "unknown",
|
|
82
|
+
name: remotePayment.payment_providers?.[0]?.id || "unknown",
|
|
83
|
+
paymentProcessor: remotePayment.payment_providers?.[0]?.id || "unknown"
|
|
84
|
+
};
|
|
85
|
+
let status = "pending";
|
|
86
|
+
switch (remotePayment.status) {
|
|
87
|
+
case "not_paid":
|
|
88
|
+
status = "pending";
|
|
89
|
+
break;
|
|
90
|
+
case "awaiting":
|
|
91
|
+
status = "pending";
|
|
92
|
+
break;
|
|
93
|
+
case "authorized":
|
|
94
|
+
status = "authorized";
|
|
95
|
+
break;
|
|
96
|
+
case "partially_authorized":
|
|
97
|
+
status = "pending";
|
|
98
|
+
break;
|
|
99
|
+
case "canceled":
|
|
100
|
+
status = "canceled";
|
|
101
|
+
break;
|
|
102
|
+
case "failed":
|
|
103
|
+
status = "canceled";
|
|
104
|
+
break;
|
|
105
|
+
case "completed":
|
|
106
|
+
status = "capture";
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
const paymentData = remotePayment.payments?.[0].data || {};
|
|
110
|
+
const pi = {
|
|
111
|
+
identifier: {
|
|
112
|
+
key: remotePayment.id
|
|
113
|
+
},
|
|
114
|
+
amount: {
|
|
115
|
+
value: remotePayment.amount,
|
|
116
|
+
currency: remotePayment.currency_code?.toUpperCase()
|
|
117
|
+
},
|
|
118
|
+
paymentMethod: paymentMethodIdentifier,
|
|
119
|
+
protocolData: paymentData ? Object.entries(paymentData).map(([key, value]) => ({
|
|
120
|
+
key,
|
|
121
|
+
value: String(value)
|
|
122
|
+
})) : [],
|
|
123
|
+
status
|
|
124
|
+
};
|
|
125
|
+
return pi;
|
|
126
|
+
}
|
|
127
|
+
parseSingle(body) {
|
|
128
|
+
const identifier = { key: body.id };
|
|
129
|
+
const userId = {
|
|
130
|
+
userId: body.customer_id || ""
|
|
131
|
+
};
|
|
132
|
+
const items = (body.items || []).map((item) => {
|
|
133
|
+
return this.parseOrderItem(item, body.currency_code.toUpperCase());
|
|
134
|
+
});
|
|
135
|
+
const price = this.parseCostBreakdown(body);
|
|
136
|
+
let orderStatus = "AwaitingPayment";
|
|
137
|
+
if (body.status === "draft") {
|
|
138
|
+
orderStatus = "AwaitingPayment";
|
|
139
|
+
}
|
|
140
|
+
if (body.status === "pending") {
|
|
141
|
+
orderStatus = "ReleasedToFulfillment";
|
|
142
|
+
}
|
|
143
|
+
if (body.status === "completed") {
|
|
144
|
+
orderStatus = "Shipped";
|
|
145
|
+
}
|
|
146
|
+
if (body.status === "canceled") {
|
|
147
|
+
orderStatus = "Cancelled";
|
|
148
|
+
}
|
|
149
|
+
let inventoryStatus = "NotAllocated";
|
|
150
|
+
if (body.fulfillment_status === "fulfilled") {
|
|
151
|
+
inventoryStatus = "Allocated";
|
|
152
|
+
}
|
|
153
|
+
const paymentInstructions = body.payment_collections?.map((pc) => {
|
|
154
|
+
return this.parsePaymentInstruction(pc, body);
|
|
155
|
+
}) || [];
|
|
156
|
+
return {
|
|
157
|
+
identifier,
|
|
158
|
+
userId,
|
|
159
|
+
items,
|
|
160
|
+
price,
|
|
161
|
+
orderStatus,
|
|
162
|
+
inventoryStatus,
|
|
163
|
+
paymentInstructions
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
__decorateClass([
|
|
168
|
+
Reactionary({
|
|
169
|
+
inputSchema: OrderQueryByIdSchema,
|
|
170
|
+
outputSchema: OrderSchema
|
|
171
|
+
})
|
|
172
|
+
], MedusaOrderProvider.prototype, "getById", 1);
|
|
173
|
+
export {
|
|
174
|
+
MedusaOrderProvider
|
|
175
|
+
};
|
package/src/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export * from './core/client.js';
|
|
|
6
6
|
export * from './providers/cart.provider.js';
|
|
7
7
|
export * from './providers/identity.provider.js';
|
|
8
8
|
export * from './providers/inventory.provider.js';
|
|
9
|
+
export * from './providers/order.provider.js';
|
|
10
|
+
export * from './providers/order-search.provider.js';
|
|
9
11
|
export * from './providers/price.provider.js';
|
|
10
12
|
export * from './providers/product-search.provider.js';
|
|
11
13
|
export * from './providers/profile.provider.js';
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { RequestContext, Cache, OrderSearchQueryByTerm, OrderSearchResult, Result, OrderStatus, Address } from '@reactionary/core';
|
|
2
|
+
import { OrderSearchProvider } from '@reactionary/core';
|
|
3
|
+
import type { MedusaConfiguration } from '../schema/configuration.schema.js';
|
|
4
|
+
import type { MedusaClient } from '../core/client.js';
|
|
5
|
+
import type { StoreOrder, StoreOrderAddress, StoreOrderListResponse } from '@medusajs/types';
|
|
6
|
+
export declare class MedusaOrderSearchProvider extends OrderSearchProvider {
|
|
7
|
+
protected config: MedusaConfiguration;
|
|
8
|
+
protected client: MedusaClient;
|
|
9
|
+
constructor(config: MedusaConfiguration, cache: Cache, context: RequestContext, client: MedusaClient);
|
|
10
|
+
queryByTerm(payload: OrderSearchQueryByTerm): Promise<Result<OrderSearchResult>>;
|
|
11
|
+
protected composeAddressFromStoreAddress(storeAddress: StoreOrderAddress): Address;
|
|
12
|
+
protected parseSingle(body: StoreOrder): {
|
|
13
|
+
identifier: {
|
|
14
|
+
key: string;
|
|
15
|
+
};
|
|
16
|
+
userId: {
|
|
17
|
+
userId: string;
|
|
18
|
+
};
|
|
19
|
+
customerName: string;
|
|
20
|
+
shippingAddress: {
|
|
21
|
+
identifier: {
|
|
22
|
+
nickName: string;
|
|
23
|
+
};
|
|
24
|
+
firstName: string;
|
|
25
|
+
lastName: string;
|
|
26
|
+
streetAddress: string;
|
|
27
|
+
streetNumber: string;
|
|
28
|
+
city: string;
|
|
29
|
+
region: string;
|
|
30
|
+
postalCode: string;
|
|
31
|
+
countryCode: string;
|
|
32
|
+
};
|
|
33
|
+
orderDate: string;
|
|
34
|
+
orderStatus: OrderStatus;
|
|
35
|
+
inventoryStatus: "NotAllocated" | "Allocated";
|
|
36
|
+
totalAmount: {
|
|
37
|
+
value: number;
|
|
38
|
+
currency: "AED" | "AFN" | "ALL" | "AMD" | "ANG" | "AOA" | "ARS" | "AUD" | "AWG" | "AZN" | "BAM" | "BBD" | "BDT" | "BGN" | "BHD" | "BIF" | "BMD" | "BND" | "BOB" | "BOV" | "BRL" | "BSD" | "BTN" | "BWP" | "BYN" | "BZD" | "CAD" | "CDF" | "CHE" | "CHF" | "CHW" | "CLF" | "CLP" | "CNY" | "COP" | "COU" | "CRC" | "CUC" | "CUP" | "CVE" | "CZK" | "DJF" | "DKK" | "DOP" | "DZD" | "EGP" | "ERN" | "ETB" | "EUR" | "FJD" | "FKP" | "GBP" | "GEL" | "GHS" | "GIP" | "GMD" | "GNF" | "GTQ" | "GYD" | "HKD" | "HNL" | "HRK" | "HTG" | "HUF" | "IDR" | "ILS" | "INR" | "IQD" | "IRR" | "ISK" | "JMD" | "JOD" | "JPY" | "KES" | "KGS" | "KHR" | "KMF" | "KPW" | "KRW" | "KWD" | "KYD" | "KZT" | "LAK" | "LBP" | "LKR" | "LRD" | "LSL" | "LYD" | "MAD" | "MDL" | "MGA" | "MKD" | "MMK" | "MNT" | "MOP" | "MRU" | "MUR" | "MVR" | "MWK" | "MXN" | "MXV" | "MYR" | "MZN" | "NAD" | "NGN" | "NIO" | "NOK" | "NPR" | "NZD" | "OMR" | "PAB" | "PEN" | "PGK" | "PHP" | "PKR" | "PLN" | "PYG" | "QAR" | "RON" | "RSD" | "RUB" | "RWF" | "SAR" | "SBD" | "SCR" | "SDG" | "SEK" | "SGD" | "SHP" | "SLE" | "SLL" | "SOS" | "SRD" | "SSP" | "STN" | "SYP" | "SZL" | "THB" | "TJS" | "TMT" | "TND" | "TOP" | "TRY" | "TTD" | "TVD" | "TWD" | "TZS" | "UAH" | "UGX" | "USD" | "USN" | "UYI" | "UYU" | "UYW" | "UZS" | "VED" | "VES" | "VND" | "VUV" | "WST" | "XAF" | "XAG" | "XAU" | "XBA" | "XBB" | "XBC" | "XBD" | "XCD" | "XDR" | "XOF" | "XPD" | "XPF" | "XPT" | "XSU" | "XTS" | "XUA" | "XXX" | "YER" | "ZAR" | "ZMW" | "ZWL";
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
protected parsePaginatedResult(body: StoreOrderListResponse, query: OrderSearchQueryByTerm): {
|
|
42
|
+
identifier: {
|
|
43
|
+
term: string;
|
|
44
|
+
filters: string[];
|
|
45
|
+
paginationOptions: {
|
|
46
|
+
pageNumber: number;
|
|
47
|
+
pageSize: number;
|
|
48
|
+
};
|
|
49
|
+
partNumber?: string[] | undefined;
|
|
50
|
+
orderStatus?: ("AwaitingPayment" | "ReleasedToFulfillment" | "Shipped" | "Cancelled")[] | undefined;
|
|
51
|
+
userId?: {
|
|
52
|
+
userId: string;
|
|
53
|
+
} | undefined;
|
|
54
|
+
startDate?: string | undefined;
|
|
55
|
+
endDate?: string | undefined;
|
|
56
|
+
};
|
|
57
|
+
pageNumber: number;
|
|
58
|
+
pageSize: number;
|
|
59
|
+
totalCount: number;
|
|
60
|
+
totalPages: number;
|
|
61
|
+
items: {
|
|
62
|
+
identifier: {
|
|
63
|
+
key: string;
|
|
64
|
+
};
|
|
65
|
+
userId: {
|
|
66
|
+
userId: string;
|
|
67
|
+
};
|
|
68
|
+
customerName: string;
|
|
69
|
+
orderDate: string;
|
|
70
|
+
orderStatus: "AwaitingPayment" | "ReleasedToFulfillment" | "Shipped" | "Cancelled";
|
|
71
|
+
inventoryStatus: "NotAllocated" | "Allocated" | "Backordered" | "Preordered";
|
|
72
|
+
totalAmount: {
|
|
73
|
+
value: number;
|
|
74
|
+
currency: "AED" | "AFN" | "ALL" | "AMD" | "ANG" | "AOA" | "ARS" | "AUD" | "AWG" | "AZN" | "BAM" | "BBD" | "BDT" | "BGN" | "BHD" | "BIF" | "BMD" | "BND" | "BOB" | "BOV" | "BRL" | "BSD" | "BTN" | "BWP" | "BYN" | "BZD" | "CAD" | "CDF" | "CHE" | "CHF" | "CHW" | "CLF" | "CLP" | "CNY" | "COP" | "COU" | "CRC" | "CUC" | "CUP" | "CVE" | "CZK" | "DJF" | "DKK" | "DOP" | "DZD" | "EGP" | "ERN" | "ETB" | "EUR" | "FJD" | "FKP" | "GBP" | "GEL" | "GHS" | "GIP" | "GMD" | "GNF" | "GTQ" | "GYD" | "HKD" | "HNL" | "HRK" | "HTG" | "HUF" | "IDR" | "ILS" | "INR" | "IQD" | "IRR" | "ISK" | "JMD" | "JOD" | "JPY" | "KES" | "KGS" | "KHR" | "KMF" | "KPW" | "KRW" | "KWD" | "KYD" | "KZT" | "LAK" | "LBP" | "LKR" | "LRD" | "LSL" | "LYD" | "MAD" | "MDL" | "MGA" | "MKD" | "MMK" | "MNT" | "MOP" | "MRU" | "MUR" | "MVR" | "MWK" | "MXN" | "MXV" | "MYR" | "MZN" | "NAD" | "NGN" | "NIO" | "NOK" | "NPR" | "NZD" | "OMR" | "PAB" | "PEN" | "PGK" | "PHP" | "PKR" | "PLN" | "PYG" | "QAR" | "RON" | "RSD" | "RUB" | "RWF" | "SAR" | "SBD" | "SCR" | "SDG" | "SEK" | "SGD" | "SHP" | "SLE" | "SLL" | "SOS" | "SRD" | "SSP" | "STN" | "SYP" | "SZL" | "THB" | "TJS" | "TMT" | "TND" | "TOP" | "TRY" | "TTD" | "TVD" | "TWD" | "TZS" | "UAH" | "UGX" | "USD" | "USN" | "UYI" | "UYU" | "UYW" | "UZS" | "VED" | "VES" | "VND" | "VUV" | "WST" | "XAF" | "XAG" | "XAU" | "XBA" | "XBB" | "XBC" | "XBD" | "XCD" | "XDR" | "XOF" | "XPD" | "XPF" | "XPT" | "XSU" | "XTS" | "XUA" | "XXX" | "YER" | "ZAR" | "ZMW" | "ZWL";
|
|
75
|
+
};
|
|
76
|
+
shippingAddress?: {
|
|
77
|
+
identifier: {
|
|
78
|
+
nickName: string;
|
|
79
|
+
};
|
|
80
|
+
firstName: string;
|
|
81
|
+
lastName: string;
|
|
82
|
+
streetAddress: string;
|
|
83
|
+
streetNumber: string;
|
|
84
|
+
city: string;
|
|
85
|
+
region: string;
|
|
86
|
+
postalCode: string;
|
|
87
|
+
countryCode: string;
|
|
88
|
+
} | undefined;
|
|
89
|
+
}[];
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Cache, Order, OrderQueryById, RequestContext, Result, NotFoundError, CostBreakDown, Currency, OrderItem, ItemCostBreakdown } from '@reactionary/core';
|
|
2
|
+
import { OrderProvider } from '@reactionary/core';
|
|
3
|
+
import type { MedusaClient } from '../core/client.js';
|
|
4
|
+
import type { MedusaConfiguration } from '../schema/configuration.schema.js';
|
|
5
|
+
import type { StoreOrder, StoreOrderLineItem, StorePaymentCollection } from '@medusajs/types';
|
|
6
|
+
export declare class MedusaOrderProvider extends OrderProvider {
|
|
7
|
+
protected config: MedusaConfiguration;
|
|
8
|
+
protected client: MedusaClient;
|
|
9
|
+
constructor(config: MedusaConfiguration, cache: Cache, context: RequestContext, client: MedusaClient);
|
|
10
|
+
getById(payload: OrderQueryById): Promise<Result<Order, NotFoundError>>;
|
|
11
|
+
/**
|
|
12
|
+
* Extension point to control the parsing of a single cart item price
|
|
13
|
+
* @param remoteItem
|
|
14
|
+
* @param currency
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
protected parseItemPrice(remoteItem: StoreOrderLineItem, currency: Currency): ItemCostBreakdown;
|
|
18
|
+
/**
|
|
19
|
+
* Extension point to control the parsing of the cost breakdown of a cart
|
|
20
|
+
* @param remote
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
protected parseCostBreakdown(remote: StoreOrder): CostBreakDown;
|
|
24
|
+
/**
|
|
25
|
+
* Extension point to control the parsing of a single cart item
|
|
26
|
+
* @param remoteItem
|
|
27
|
+
* @param currency
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
protected parseOrderItem(remoteItem: StoreOrderLineItem, currency: Currency): OrderItem;
|
|
31
|
+
protected parsePaymentInstruction(remotePayment: StorePaymentCollection, order: StoreOrder): {
|
|
32
|
+
identifier: {
|
|
33
|
+
key: string;
|
|
34
|
+
};
|
|
35
|
+
amount: {
|
|
36
|
+
value: number;
|
|
37
|
+
currency: Currency;
|
|
38
|
+
};
|
|
39
|
+
paymentMethod: {
|
|
40
|
+
method: string;
|
|
41
|
+
name: string;
|
|
42
|
+
paymentProcessor: string;
|
|
43
|
+
};
|
|
44
|
+
protocolData: {
|
|
45
|
+
key: string;
|
|
46
|
+
value: string;
|
|
47
|
+
}[];
|
|
48
|
+
status: "pending" | "authorized" | "canceled" | "capture";
|
|
49
|
+
};
|
|
50
|
+
protected parseSingle(body: StoreOrder): Order;
|
|
51
|
+
}
|
|
@@ -4,10 +4,12 @@ export declare const MedusaCapabilitiesSchema: z.ZodObject<{
|
|
|
4
4
|
product: z.ZodOptional<z.ZodBoolean>;
|
|
5
5
|
cart: z.ZodOptional<z.ZodBoolean>;
|
|
6
6
|
checkout: z.ZodOptional<z.ZodBoolean>;
|
|
7
|
+
order: z.ZodOptional<z.ZodBoolean>;
|
|
7
8
|
identity: z.ZodOptional<z.ZodBoolean>;
|
|
8
9
|
inventory: z.ZodOptional<z.ZodBoolean>;
|
|
9
10
|
category: z.ZodOptional<z.ZodBoolean>;
|
|
10
11
|
profile: z.ZodOptional<z.ZodBoolean>;
|
|
11
12
|
productSearch: z.ZodOptional<z.ZodBoolean>;
|
|
13
|
+
orderSearch: z.ZodOptional<z.ZodBoolean>;
|
|
12
14
|
}, z.core.$loose>;
|
|
13
15
|
export type MedusaCapabilities = z.infer<typeof MedusaCapabilitiesSchema>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { StoreCart } from '@medusajs/types';
|
|
1
|
+
import type { StoreCart, StoreOrder } from '@medusajs/types';
|
|
2
2
|
import type { CostBreakDown, Currency } from '@reactionary/core';
|
|
3
3
|
/**
|
|
4
4
|
* Parses cost breakdown from Medusa StoreCart
|
|
5
5
|
*/
|
|
6
|
-
export declare function parseMedusaCostBreakdown(remote: StoreCart): CostBreakDown;
|
|
6
|
+
export declare function parseMedusaCostBreakdown(remote: StoreCart | StoreOrder): CostBreakDown;
|
|
7
7
|
/**
|
|
8
8
|
* Parses item price structure from Medusa line item
|
|
9
9
|
*/
|