@reactionary/provider-medusa 0.1.13 → 0.2.2
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/client.js +2 -23
- package/core/initialize.js +4 -0
- package/index.js +1 -0
- package/package.json +2 -2
- package/providers/cart.provider.js +68 -58
- package/providers/category.provider.js +19 -53
- package/providers/checkout.provider.js +18 -40
- package/providers/identity.provider.js +9 -25
- package/providers/inventory.provider.js +7 -22
- package/providers/price.provider.js +8 -13
- package/providers/product-search.provider.js +31 -35
- package/providers/product.provider.js +13 -13
- package/providers/profile.provider.js +323 -0
- package/schema/capabilities.schema.js +2 -1
- package/src/core/client.d.ts +0 -35
- package/src/index.d.ts +1 -0
- package/src/providers/cart.provider.d.ts +10 -10
- package/src/providers/category.provider.d.ts +8 -50
- package/src/providers/checkout.provider.d.ts +10 -10
- package/src/providers/identity.provider.d.ts +5 -5
- package/src/providers/inventory.provider.d.ts +2 -2
- package/src/providers/price.provider.d.ts +3 -3
- package/src/providers/product-search.provider.d.ts +3 -17
- package/src/providers/product.provider.d.ts +4 -4
- package/src/providers/profile.provider.d.ts +30 -0
- package/src/schema/capabilities.schema.d.ts +3 -2
- package/test/cart.provider.spec.js +69 -49
- package/test/category.provider.spec.js +125 -63
- package/test/checkout.spec.js +80 -49
- package/test/identity.provider.spec.js +22 -7
- package/test/inventory.provider.spec.js +35 -24
- package/test/large-cart.provider.spec.js +57 -31
- package/test/price.provider.spec.js +57 -36
- package/test/product.provider.spec.js +78 -49
- package/test/search.provider.spec.js +47 -20
|
@@ -0,0 +1,323 @@
|
|
|
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
|
+
ProfileProvider,
|
|
14
|
+
Reactionary,
|
|
15
|
+
ProfileSchema,
|
|
16
|
+
ProfileMutationUpdateSchema,
|
|
17
|
+
ProfileMutationAddShippingAddressSchema,
|
|
18
|
+
ProfileMutationUpdateShippingAddressSchema,
|
|
19
|
+
ProfileMutationRemoveShippingAddressSchema,
|
|
20
|
+
ProfileMutationMakeShippingAddressDefaultSchema,
|
|
21
|
+
ProfileMutationSetBillingAddressSchema,
|
|
22
|
+
success,
|
|
23
|
+
ProfileQueryByIdSchema,
|
|
24
|
+
error
|
|
25
|
+
} from "@reactionary/core";
|
|
26
|
+
import createDebug from "debug";
|
|
27
|
+
const debug = createDebug("reactionary:medusa:profile");
|
|
28
|
+
class MedusaProfileProvider extends ProfileProvider {
|
|
29
|
+
constructor(config, cache, context, client) {
|
|
30
|
+
super(cache, context);
|
|
31
|
+
this.includedFields = ["+metadata.*"];
|
|
32
|
+
this.config = config;
|
|
33
|
+
this.client = client;
|
|
34
|
+
}
|
|
35
|
+
async getById(payload) {
|
|
36
|
+
debug("getById", payload);
|
|
37
|
+
const client = await this.client.getClient();
|
|
38
|
+
const customerResponse = await client.store.customer.retrieve({ fields: this.includedFields.join(",") });
|
|
39
|
+
if (!customerResponse.customer) {
|
|
40
|
+
return error({
|
|
41
|
+
identifier: payload.identifier,
|
|
42
|
+
type: "NotFound"
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const model = this.parseSingle(customerResponse.customer);
|
|
46
|
+
return success(model);
|
|
47
|
+
}
|
|
48
|
+
async update(payload) {
|
|
49
|
+
debug("update", payload);
|
|
50
|
+
const client = await this.client.getClient();
|
|
51
|
+
const customerResponse = await client.store.customer.retrieve({ fields: this.includedFields.join(",") });
|
|
52
|
+
if (!customerResponse.customer) {
|
|
53
|
+
return error({
|
|
54
|
+
type: "NotFound",
|
|
55
|
+
identifier: payload.identifier
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const customer = customerResponse.customer;
|
|
59
|
+
const updatedResponse = await client.store.customer.update({
|
|
60
|
+
phone: payload.phone ?? customer.phone
|
|
61
|
+
}, { fields: this.includedFields.join(",") });
|
|
62
|
+
const model = this.parseSingle(updatedResponse.customer);
|
|
63
|
+
return success(model);
|
|
64
|
+
}
|
|
65
|
+
async addShippingAddress(payload) {
|
|
66
|
+
debug("addShippingAddress", payload);
|
|
67
|
+
const client = await this.client.getClient();
|
|
68
|
+
const medusaAddress = this.createMedusaAddress(payload.address);
|
|
69
|
+
const customer = await client.store.customer.retrieve({ fields: this.includedFields.join(",") });
|
|
70
|
+
if (!customer.customer) {
|
|
71
|
+
return error({
|
|
72
|
+
type: "NotFound",
|
|
73
|
+
identifier: payload.identifier
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
const existingAddress = customer.customer.addresses.find((addr) => addr.address_name === payload.address.identifier.nickName);
|
|
77
|
+
if (existingAddress) {
|
|
78
|
+
return error({
|
|
79
|
+
type: "InvalidInput",
|
|
80
|
+
error: {
|
|
81
|
+
message: "Address with the same nickname already exists"
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const response = await client.store.customer.createAddress(medusaAddress, { fields: this.includedFields.join(",") });
|
|
86
|
+
if (!response.customer) {
|
|
87
|
+
return error({
|
|
88
|
+
type: "InvalidInput",
|
|
89
|
+
error: {
|
|
90
|
+
message: "Failed to add shipping address"
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
const model = this.parseSingle(response.customer);
|
|
95
|
+
return success(model);
|
|
96
|
+
}
|
|
97
|
+
async updateShippingAddress(payload) {
|
|
98
|
+
debug("updateShippingAddress", payload);
|
|
99
|
+
const client = await this.client.getClient();
|
|
100
|
+
const customer = await client.store.customer.retrieve({ fields: this.includedFields.join(",") });
|
|
101
|
+
if (!customer.customer) {
|
|
102
|
+
return error({
|
|
103
|
+
type: "NotFound",
|
|
104
|
+
identifier: payload.identifier
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
const medusaAddress = this.createMedusaAddress(payload.address);
|
|
108
|
+
const existingAddress = customer.customer.addresses.find((addr) => addr.address_name === payload.address.identifier.nickName);
|
|
109
|
+
if (!existingAddress) {
|
|
110
|
+
return error({
|
|
111
|
+
type: "NotFound",
|
|
112
|
+
identifier: payload.address.identifier
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
const response = await client.store.customer.updateAddress(existingAddress.id, medusaAddress, { fields: this.includedFields.join(",") });
|
|
116
|
+
if (!response.customer) {
|
|
117
|
+
return error({
|
|
118
|
+
type: "InvalidInput",
|
|
119
|
+
error: {
|
|
120
|
+
message: "Failed to add shipping address"
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
const model = this.parseSingle(response.customer);
|
|
125
|
+
return success(model);
|
|
126
|
+
}
|
|
127
|
+
async removeShippingAddress(payload) {
|
|
128
|
+
debug("removeShippingAddress", payload);
|
|
129
|
+
const client = await this.client.getClient();
|
|
130
|
+
const customer = await client.store.customer.retrieve({ fields: this.includedFields.join(",") });
|
|
131
|
+
if (!customer.customer) {
|
|
132
|
+
return error({
|
|
133
|
+
type: "NotFound",
|
|
134
|
+
identifier: payload.identifier
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
const existingAddress = customer.customer.addresses.find((addr) => addr.address_name === payload.addressIdentifier.nickName);
|
|
138
|
+
if (!existingAddress) {
|
|
139
|
+
return error({
|
|
140
|
+
type: "NotFound",
|
|
141
|
+
identifier: payload.addressIdentifier
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
const response = await client.store.customer.deleteAddress(existingAddress.id, { fields: this.includedFields.join(",") });
|
|
145
|
+
if (!response.deleted) {
|
|
146
|
+
return error({
|
|
147
|
+
type: "InvalidInput",
|
|
148
|
+
error: {
|
|
149
|
+
message: "Failed to delete shipping address"
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
const customerAfterDelete = await client.store.customer.retrieve({ fields: this.includedFields.join(",") });
|
|
154
|
+
const model = this.parseSingle(customerAfterDelete.customer);
|
|
155
|
+
return success(model);
|
|
156
|
+
}
|
|
157
|
+
async makeShippingAddressDefault(payload) {
|
|
158
|
+
debug("makeShippingAddressDefault", payload);
|
|
159
|
+
const client = await this.client.getClient();
|
|
160
|
+
const customer = await client.store.customer.retrieve({ fields: this.includedFields.join(",") });
|
|
161
|
+
if (!customer.customer) {
|
|
162
|
+
return error({
|
|
163
|
+
type: "NotFound",
|
|
164
|
+
identifier: payload.identifier
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
const existingAddress = customer.customer.addresses.find((addr) => addr.address_name === payload.addressIdentifier.nickName);
|
|
168
|
+
if (!existingAddress) {
|
|
169
|
+
return error({
|
|
170
|
+
type: "NotFound",
|
|
171
|
+
identifier: payload.addressIdentifier
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
const response = await client.store.customer.updateAddress(
|
|
175
|
+
existingAddress.id,
|
|
176
|
+
{
|
|
177
|
+
is_default_shipping: true
|
|
178
|
+
},
|
|
179
|
+
{ fields: this.includedFields.join(",") }
|
|
180
|
+
);
|
|
181
|
+
const model = this.parseSingle(response.customer);
|
|
182
|
+
return success(model);
|
|
183
|
+
}
|
|
184
|
+
async setBillingAddress(payload) {
|
|
185
|
+
debug("setBillingAddress", payload);
|
|
186
|
+
const client = await this.client.getClient();
|
|
187
|
+
const customerResponse = await client.store.customer.retrieve({ fields: this.includedFields.join(",") });
|
|
188
|
+
if (!customerResponse.customer) {
|
|
189
|
+
return error({
|
|
190
|
+
type: "NotFound",
|
|
191
|
+
identifier: payload.identifier
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
let customer = customerResponse.customer;
|
|
195
|
+
const existingAddressWithNickname = customer.addresses.find((addr) => addr.address_name === payload.address.identifier.nickName);
|
|
196
|
+
if (existingAddressWithNickname && !existingAddressWithNickname.is_default_billing) {
|
|
197
|
+
return error({
|
|
198
|
+
type: "InvalidInput",
|
|
199
|
+
error: {
|
|
200
|
+
message: "Another address with the same nickname already exists"
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
const newAddr = this.createMedusaAddress(payload.address);
|
|
205
|
+
newAddr.is_default_billing = true;
|
|
206
|
+
const existingBillingAddress = customer.addresses.find((addr) => addr.is_default_billing);
|
|
207
|
+
if (existingBillingAddress) {
|
|
208
|
+
const updateAddressResponse = await client.store.customer.updateAddress(existingBillingAddress.id, newAddr, { fields: this.includedFields.join(",") });
|
|
209
|
+
customer = updateAddressResponse.customer;
|
|
210
|
+
} else {
|
|
211
|
+
const createAddressResponse = await client.store.customer.createAddress(newAddr, { fields: this.includedFields.join(",") });
|
|
212
|
+
customer = createAddressResponse.customer;
|
|
213
|
+
}
|
|
214
|
+
const model = this.parseSingle(customer);
|
|
215
|
+
return success(model);
|
|
216
|
+
}
|
|
217
|
+
createMedusaAddress(address) {
|
|
218
|
+
return {
|
|
219
|
+
address_name: address.identifier.nickName,
|
|
220
|
+
first_name: address.firstName,
|
|
221
|
+
last_name: address.lastName,
|
|
222
|
+
address_1: address.streetAddress,
|
|
223
|
+
address_2: address.streetNumber,
|
|
224
|
+
city: address.city,
|
|
225
|
+
province: address.region,
|
|
226
|
+
postal_code: address.postalCode,
|
|
227
|
+
country_code: address.countryCode
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
parseAddress(address) {
|
|
231
|
+
return {
|
|
232
|
+
identifier: {
|
|
233
|
+
nickName: address.address_name || ""
|
|
234
|
+
},
|
|
235
|
+
firstName: address.first_name || "",
|
|
236
|
+
lastName: address.last_name || "",
|
|
237
|
+
streetAddress: address.address_1 || "",
|
|
238
|
+
streetNumber: address.address_2 || "",
|
|
239
|
+
city: address.city || "",
|
|
240
|
+
region: address.province || "",
|
|
241
|
+
postalCode: address.postal_code || "",
|
|
242
|
+
countryCode: address.country_code || ""
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
parseSingle(customer) {
|
|
246
|
+
const email = customer.email;
|
|
247
|
+
const emailVerified = customer.metadata?.["email_verified"] === "true";
|
|
248
|
+
const phone = customer.phone || "";
|
|
249
|
+
const phoneVerified = customer.metadata?.["phone_verified"] === "true";
|
|
250
|
+
const addresses = customer.addresses || [];
|
|
251
|
+
let billingAddress = void 0;
|
|
252
|
+
let shippingAddress = void 0;
|
|
253
|
+
const existingBillingAddress = customer.addresses.find((addr) => addr.is_default_billing);
|
|
254
|
+
if (existingBillingAddress) {
|
|
255
|
+
billingAddress = this.parseAddress(existingBillingAddress);
|
|
256
|
+
}
|
|
257
|
+
const existingShippingAddress = customer.addresses.find((addr) => addr.is_default_shipping);
|
|
258
|
+
if (existingShippingAddress) {
|
|
259
|
+
shippingAddress = this.parseAddress(existingShippingAddress);
|
|
260
|
+
}
|
|
261
|
+
const alternateShippingAddresses = [];
|
|
262
|
+
alternateShippingAddresses.push(...addresses.filter((x) => !(x.is_default_billing || x.is_default_shipping)).map((addr) => this.parseAddress(addr)));
|
|
263
|
+
return {
|
|
264
|
+
identifier: {
|
|
265
|
+
userId: customer.id
|
|
266
|
+
},
|
|
267
|
+
email,
|
|
268
|
+
emailVerified,
|
|
269
|
+
phone,
|
|
270
|
+
phoneVerified,
|
|
271
|
+
billingAddress,
|
|
272
|
+
shippingAddress,
|
|
273
|
+
alternateShippingAddresses,
|
|
274
|
+
createdAt: new Date(customer.created_at || "").toISOString(),
|
|
275
|
+
updatedAt: new Date(customer.updated_at || "").toISOString()
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
__decorateClass([
|
|
280
|
+
Reactionary({
|
|
281
|
+
inputSchema: ProfileQueryByIdSchema,
|
|
282
|
+
outputSchema: ProfileSchema
|
|
283
|
+
})
|
|
284
|
+
], MedusaProfileProvider.prototype, "getById", 1);
|
|
285
|
+
__decorateClass([
|
|
286
|
+
Reactionary({
|
|
287
|
+
inputSchema: ProfileMutationUpdateSchema,
|
|
288
|
+
outputSchema: ProfileSchema
|
|
289
|
+
})
|
|
290
|
+
], MedusaProfileProvider.prototype, "update", 1);
|
|
291
|
+
__decorateClass([
|
|
292
|
+
Reactionary({
|
|
293
|
+
inputSchema: ProfileMutationAddShippingAddressSchema,
|
|
294
|
+
outputSchema: ProfileSchema
|
|
295
|
+
})
|
|
296
|
+
], MedusaProfileProvider.prototype, "addShippingAddress", 1);
|
|
297
|
+
__decorateClass([
|
|
298
|
+
Reactionary({
|
|
299
|
+
inputSchema: ProfileMutationUpdateShippingAddressSchema,
|
|
300
|
+
outputSchema: ProfileSchema
|
|
301
|
+
})
|
|
302
|
+
], MedusaProfileProvider.prototype, "updateShippingAddress", 1);
|
|
303
|
+
__decorateClass([
|
|
304
|
+
Reactionary({
|
|
305
|
+
inputSchema: ProfileMutationRemoveShippingAddressSchema,
|
|
306
|
+
outputSchema: ProfileSchema
|
|
307
|
+
})
|
|
308
|
+
], MedusaProfileProvider.prototype, "removeShippingAddress", 1);
|
|
309
|
+
__decorateClass([
|
|
310
|
+
Reactionary({
|
|
311
|
+
inputSchema: ProfileMutationMakeShippingAddressDefaultSchema,
|
|
312
|
+
outputSchema: ProfileSchema
|
|
313
|
+
})
|
|
314
|
+
], MedusaProfileProvider.prototype, "makeShippingAddressDefault", 1);
|
|
315
|
+
__decorateClass([
|
|
316
|
+
Reactionary({
|
|
317
|
+
inputSchema: ProfileMutationSetBillingAddressSchema,
|
|
318
|
+
outputSchema: ProfileSchema
|
|
319
|
+
})
|
|
320
|
+
], MedusaProfileProvider.prototype, "setBillingAddress", 1);
|
|
321
|
+
export {
|
|
322
|
+
MedusaProfileProvider
|
|
323
|
+
};
|
package/src/core/client.d.ts
CHANGED
|
@@ -62,21 +62,7 @@ export declare class MedusaClient {
|
|
|
62
62
|
userId: string;
|
|
63
63
|
};
|
|
64
64
|
type: "Registered";
|
|
65
|
-
meta: {
|
|
66
|
-
cache: {
|
|
67
|
-
hit: false;
|
|
68
|
-
key: string;
|
|
69
|
-
};
|
|
70
|
-
placeholder: false;
|
|
71
|
-
};
|
|
72
65
|
} | {
|
|
73
|
-
meta: {
|
|
74
|
-
cache: {
|
|
75
|
-
hit: false;
|
|
76
|
-
key: string;
|
|
77
|
-
};
|
|
78
|
-
placeholder: false;
|
|
79
|
-
};
|
|
80
66
|
type: "Anonymous";
|
|
81
67
|
}>;
|
|
82
68
|
login(email: string, password: string, reqCtx: RequestContext): Promise<{
|
|
@@ -84,32 +70,11 @@ export declare class MedusaClient {
|
|
|
84
70
|
userId: string;
|
|
85
71
|
};
|
|
86
72
|
type: "Registered";
|
|
87
|
-
meta: {
|
|
88
|
-
cache: {
|
|
89
|
-
hit: false;
|
|
90
|
-
key: string;
|
|
91
|
-
};
|
|
92
|
-
placeholder: false;
|
|
93
|
-
};
|
|
94
73
|
} | {
|
|
95
|
-
meta: {
|
|
96
|
-
cache: {
|
|
97
|
-
hit: false;
|
|
98
|
-
key: string;
|
|
99
|
-
};
|
|
100
|
-
placeholder: false;
|
|
101
|
-
};
|
|
102
74
|
type: "Anonymous";
|
|
103
75
|
}>;
|
|
104
76
|
logout(reqCtx: RequestContext): Promise<{
|
|
105
77
|
type: "Anonymous";
|
|
106
|
-
meta: {
|
|
107
|
-
cache: {
|
|
108
|
-
hit: false;
|
|
109
|
-
key: string;
|
|
110
|
-
};
|
|
111
|
-
placeholder: false;
|
|
112
|
-
};
|
|
113
78
|
}>;
|
|
114
79
|
protected createAuthenticatedClient(reqCtx: RequestContext): Promise<Medusa>;
|
|
115
80
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Cache, Cart, CartIdentifier, CartItem, CartMutationApplyCoupon, CartMutationChangeCurrency, CartMutationDeleteCart, CartMutationItemAdd, CartMutationItemQuantityChange, CartMutationItemRemove, CartMutationRemoveCoupon, CartQueryById, CostBreakDown, Currency, ItemCostBreakdown, RequestContext } from '@reactionary/core';
|
|
1
|
+
import type { Cache, Cart, CartIdentifier, CartItem, CartMutationApplyCoupon, CartMutationChangeCurrency, CartMutationDeleteCart, CartMutationItemAdd, CartMutationItemQuantityChange, CartMutationItemRemove, CartMutationRemoveCoupon, CartQueryById, CostBreakDown, Currency, ItemCostBreakdown, NotFoundError, RequestContext, Result } from '@reactionary/core';
|
|
2
2
|
import { CartProvider } from '@reactionary/core';
|
|
3
3
|
import type { MedusaClient } from '../core/client.js';
|
|
4
4
|
import type { MedusaConfiguration } from '../schema/configuration.schema.js';
|
|
@@ -14,15 +14,15 @@ export declare class MedusaCartProvider extends CartProvider {
|
|
|
14
14
|
*/
|
|
15
15
|
protected includedFields: string;
|
|
16
16
|
constructor(config: MedusaConfiguration, cache: Cache, context: RequestContext, client: MedusaClient);
|
|
17
|
-
getById(payload: CartQueryById): Promise<Cart
|
|
18
|
-
add(payload: CartMutationItemAdd): Promise<Cart
|
|
19
|
-
remove(payload: CartMutationItemRemove): Promise<Cart
|
|
20
|
-
changeQuantity(payload: CartMutationItemQuantityChange): Promise<Cart
|
|
21
|
-
getActiveCartId(): Promise<CartIdentifier
|
|
22
|
-
deleteCart(payload: CartMutationDeleteCart): Promise<
|
|
23
|
-
applyCouponCode(payload: CartMutationApplyCoupon): Promise<Cart
|
|
24
|
-
removeCouponCode(payload: CartMutationRemoveCoupon): Promise<Cart
|
|
25
|
-
changeCurrency(payload: CartMutationChangeCurrency): Promise<Cart
|
|
17
|
+
getById(payload: CartQueryById): Promise<Result<Cart, NotFoundError>>;
|
|
18
|
+
add(payload: CartMutationItemAdd): Promise<Result<Cart>>;
|
|
19
|
+
remove(payload: CartMutationItemRemove): Promise<Result<Cart>>;
|
|
20
|
+
changeQuantity(payload: CartMutationItemQuantityChange): Promise<Result<Cart>>;
|
|
21
|
+
getActiveCartId(): Promise<Result<CartIdentifier, NotFoundError>>;
|
|
22
|
+
deleteCart(payload: CartMutationDeleteCart): Promise<Result<void>>;
|
|
23
|
+
applyCouponCode(payload: CartMutationApplyCoupon): Promise<Result<Cart>>;
|
|
24
|
+
removeCouponCode(payload: CartMutationRemoveCoupon): Promise<Result<Cart>>;
|
|
25
|
+
changeCurrency(payload: CartMutationChangeCurrency): Promise<Result<Cart>>;
|
|
26
26
|
protected createCart(currency?: string): Promise<CartIdentifier>;
|
|
27
27
|
protected getClient(): Promise<{
|
|
28
28
|
client: import("@medusajs/js-sdk").Client;
|
|
@@ -1,28 +1,21 @@
|
|
|
1
1
|
import type { StoreProductCategory, StoreProductCategoryListResponse } from '@medusajs/types';
|
|
2
2
|
import type { Category, Cache } from '@reactionary/core';
|
|
3
|
-
import { CategoryProvider, type CategoryQueryById, type CategoryQueryBySlug, type CategoryQueryForBreadcrumb, type CategoryQueryForChildCategories, type CategoryQueryForTopCategories, type RequestContext } from '@reactionary/core';
|
|
3
|
+
import { CategoryProvider, type Result, type NotFoundError, type CategoryQueryById, type CategoryQueryBySlug, type CategoryQueryForBreadcrumb, type CategoryQueryForChildCategories, type CategoryQueryForTopCategories, type RequestContext } from '@reactionary/core';
|
|
4
4
|
import type { MedusaClient, MedusaConfiguration } from '../index.js';
|
|
5
5
|
export declare class MedusaCategoryProvider extends CategoryProvider {
|
|
6
6
|
client: MedusaClient;
|
|
7
7
|
protected config: MedusaConfiguration;
|
|
8
8
|
constructor(config: MedusaConfiguration, cache: Cache, context: RequestContext, client: MedusaClient);
|
|
9
9
|
protected resolveCategoryIdByExternalId(externalId: string): Promise<StoreProductCategory | null>;
|
|
10
|
-
getById(payload: CategoryQueryById): Promise<Category
|
|
11
|
-
getBySlug(payload: CategoryQueryBySlug): Promise<Category
|
|
12
|
-
getBreadcrumbPathToCategory(payload: CategoryQueryForBreadcrumb): Promise<Category[]
|
|
13
|
-
findChildCategories(payload: CategoryQueryForChildCategories): Promise<{
|
|
10
|
+
getById(payload: CategoryQueryById): Promise<Result<Category, NotFoundError>>;
|
|
11
|
+
getBySlug(payload: CategoryQueryBySlug): Promise<Result<Category, NotFoundError>>;
|
|
12
|
+
getBreadcrumbPathToCategory(payload: CategoryQueryForBreadcrumb): Promise<Result<Category[]>>;
|
|
13
|
+
findChildCategories(payload: CategoryQueryForChildCategories): Promise<import("@reactionary/core").Ok<{
|
|
14
14
|
pageNumber: number;
|
|
15
15
|
pageSize: number;
|
|
16
16
|
totalCount: number;
|
|
17
17
|
totalPages: number;
|
|
18
18
|
items: {
|
|
19
|
-
meta: {
|
|
20
|
-
cache: {
|
|
21
|
-
hit: boolean;
|
|
22
|
-
key: string;
|
|
23
|
-
};
|
|
24
|
-
placeholder: boolean;
|
|
25
|
-
};
|
|
26
19
|
identifier: {
|
|
27
20
|
key: string;
|
|
28
21
|
};
|
|
@@ -39,27 +32,13 @@ export declare class MedusaCategoryProvider extends CategoryProvider {
|
|
|
39
32
|
key: string;
|
|
40
33
|
} | undefined;
|
|
41
34
|
}[];
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
hit: false;
|
|
45
|
-
key: string;
|
|
46
|
-
};
|
|
47
|
-
placeholder: false;
|
|
48
|
-
};
|
|
49
|
-
}>;
|
|
50
|
-
findTopCategories(payload: CategoryQueryForTopCategories): Promise<{
|
|
35
|
+
}>>;
|
|
36
|
+
findTopCategories(payload: CategoryQueryForTopCategories): Promise<import("@reactionary/core").Ok<{
|
|
51
37
|
pageNumber: number;
|
|
52
38
|
pageSize: number;
|
|
53
39
|
totalCount: number;
|
|
54
40
|
totalPages: number;
|
|
55
41
|
items: {
|
|
56
|
-
meta: {
|
|
57
|
-
cache: {
|
|
58
|
-
hit: boolean;
|
|
59
|
-
key: string;
|
|
60
|
-
};
|
|
61
|
-
placeholder: boolean;
|
|
62
|
-
};
|
|
63
42
|
identifier: {
|
|
64
43
|
key: string;
|
|
65
44
|
};
|
|
@@ -76,14 +55,7 @@ export declare class MedusaCategoryProvider extends CategoryProvider {
|
|
|
76
55
|
key: string;
|
|
77
56
|
} | undefined;
|
|
78
57
|
}[];
|
|
79
|
-
|
|
80
|
-
cache: {
|
|
81
|
-
hit: false;
|
|
82
|
-
key: string;
|
|
83
|
-
};
|
|
84
|
-
placeholder: false;
|
|
85
|
-
};
|
|
86
|
-
}>;
|
|
58
|
+
}>>;
|
|
87
59
|
protected parseSingle(_body: StoreProductCategory): Category;
|
|
88
60
|
protected parsePaginatedResult(body: StoreProductCategoryListResponse): {
|
|
89
61
|
pageNumber: number;
|
|
@@ -91,13 +63,6 @@ export declare class MedusaCategoryProvider extends CategoryProvider {
|
|
|
91
63
|
totalCount: number;
|
|
92
64
|
totalPages: number;
|
|
93
65
|
items: {
|
|
94
|
-
meta: {
|
|
95
|
-
cache: {
|
|
96
|
-
hit: boolean;
|
|
97
|
-
key: string;
|
|
98
|
-
};
|
|
99
|
-
placeholder: boolean;
|
|
100
|
-
};
|
|
101
66
|
identifier: {
|
|
102
67
|
key: string;
|
|
103
68
|
};
|
|
@@ -114,12 +79,5 @@ export declare class MedusaCategoryProvider extends CategoryProvider {
|
|
|
114
79
|
key: string;
|
|
115
80
|
} | undefined;
|
|
116
81
|
}[];
|
|
117
|
-
meta: {
|
|
118
|
-
cache: {
|
|
119
|
-
hit: false;
|
|
120
|
-
key: string;
|
|
121
|
-
};
|
|
122
|
-
placeholder: false;
|
|
123
|
-
};
|
|
124
82
|
};
|
|
125
83
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { StoreCart, StoreCartAddress, StoreCartLineItem } from '@medusajs/types';
|
|
2
|
-
import type { Address, Cache, Checkout, CheckoutIdentifier, CheckoutItem, CheckoutMutationAddPaymentInstruction, CheckoutMutationFinalizeCheckout, CheckoutMutationInitiateCheckout, CheckoutMutationRemovePaymentInstruction, CheckoutMutationSetShippingAddress, CheckoutMutationSetShippingInstruction, CheckoutQueryById, CheckoutQueryForAvailablePaymentMethods, CheckoutQueryForAvailableShippingMethods, CostBreakDown, Currency, ItemCostBreakdown, PaymentMethod, RequestContext, ShippingMethod } from '@reactionary/core';
|
|
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 { MedusaClient } from '../core/client.js';
|
|
5
5
|
import type { MedusaConfiguration } from '../schema/configuration.schema.js';
|
|
@@ -18,15 +18,15 @@ export declare class MedusaCheckoutProvider extends CheckoutProvider {
|
|
|
18
18
|
*/
|
|
19
19
|
protected includedFields: string;
|
|
20
20
|
constructor(config: MedusaConfiguration, cache: Cache, context: RequestContext, client: MedusaClient);
|
|
21
|
-
initiateCheckoutForCart(payload: CheckoutMutationInitiateCheckout): Promise<Checkout
|
|
22
|
-
getById(payload: CheckoutQueryById): Promise<Checkout
|
|
23
|
-
setShippingAddress(payload: CheckoutMutationSetShippingAddress): Promise<Checkout
|
|
24
|
-
getAvailableShippingMethods(payload: CheckoutQueryForAvailableShippingMethods): Promise<ShippingMethod[]
|
|
25
|
-
getAvailablePaymentMethods(payload: CheckoutQueryForAvailablePaymentMethods): Promise<PaymentMethod[]
|
|
26
|
-
addPaymentInstruction(payload: CheckoutMutationAddPaymentInstruction): Promise<Checkout
|
|
27
|
-
removePaymentInstruction(payload: CheckoutMutationRemovePaymentInstruction): Promise<Checkout
|
|
28
|
-
setShippingInstruction(payload: CheckoutMutationSetShippingInstruction): Promise<Checkout
|
|
29
|
-
finalizeCheckout(payload: CheckoutMutationFinalizeCheckout): Promise<Checkout
|
|
21
|
+
initiateCheckoutForCart(payload: CheckoutMutationInitiateCheckout): Promise<Result<Checkout>>;
|
|
22
|
+
getById(payload: CheckoutQueryById): Promise<Result<Checkout, NotFoundError>>;
|
|
23
|
+
setShippingAddress(payload: CheckoutMutationSetShippingAddress): Promise<Result<Checkout>>;
|
|
24
|
+
getAvailableShippingMethods(payload: CheckoutQueryForAvailableShippingMethods): Promise<Result<ShippingMethod[]>>;
|
|
25
|
+
getAvailablePaymentMethods(payload: CheckoutQueryForAvailablePaymentMethods): Promise<Result<PaymentMethod[]>>;
|
|
26
|
+
addPaymentInstruction(payload: CheckoutMutationAddPaymentInstruction): Promise<Result<Checkout>>;
|
|
27
|
+
removePaymentInstruction(payload: CheckoutMutationRemovePaymentInstruction): Promise<Result<Checkout>>;
|
|
28
|
+
setShippingInstruction(payload: CheckoutMutationSetShippingInstruction): Promise<Result<Checkout>>;
|
|
29
|
+
finalizeCheckout(payload: CheckoutMutationFinalizeCheckout): Promise<Result<Checkout>>;
|
|
30
30
|
/**
|
|
31
31
|
* Extension point to map an Address to a Store Address
|
|
32
32
|
* @param address
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Identity, type IdentityMutationLogin, type IdentityMutationLogout, type IdentityMutationRegister, type IdentityQuerySelf, type RequestContext, type Cache, IdentityProvider, type AnonymousIdentity } from '@reactionary/core';
|
|
1
|
+
import { type Identity, type IdentityMutationLogin, type IdentityMutationLogout, type IdentityMutationRegister, type IdentityQuerySelf, type RequestContext, type Cache, IdentityProvider, type AnonymousIdentity, type Result } from '@reactionary/core';
|
|
2
2
|
import type { MedusaConfiguration } from '../schema/configuration.schema.js';
|
|
3
3
|
import type { MedusaClient } from '../core/client.js';
|
|
4
4
|
export declare class MedusaIdentityProvider extends IdentityProvider {
|
|
@@ -6,8 +6,8 @@ export declare class MedusaIdentityProvider extends IdentityProvider {
|
|
|
6
6
|
protected client: MedusaClient;
|
|
7
7
|
constructor(config: MedusaConfiguration, cache: Cache, context: RequestContext, client: MedusaClient);
|
|
8
8
|
protected createAnonymousIdentity(): AnonymousIdentity;
|
|
9
|
-
getSelf(_payload: IdentityQuerySelf): Promise<Identity
|
|
10
|
-
login(payload: IdentityMutationLogin): Promise<Identity
|
|
11
|
-
logout(_payload: IdentityMutationLogout): Promise<Identity
|
|
12
|
-
register(payload: IdentityMutationRegister): Promise<Identity
|
|
9
|
+
getSelf(_payload: IdentityQuerySelf): Promise<Result<Identity>>;
|
|
10
|
+
login(payload: IdentityMutationLogin): Promise<Result<Identity>>;
|
|
11
|
+
logout(_payload: IdentityMutationLogout): Promise<Result<Identity>>;
|
|
12
|
+
register(payload: IdentityMutationRegister): Promise<Result<Identity>>;
|
|
13
13
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type Inventory, type InventoryQueryBySKU, type RequestContext, type Cache, InventoryProvider } from '@reactionary/core';
|
|
1
|
+
import { type Inventory, type InventoryQueryBySKU, type RequestContext, type Cache, InventoryProvider, type NotFoundError, type Result } from '@reactionary/core';
|
|
2
2
|
import type { MedusaConfiguration } from '../schema/configuration.schema.js';
|
|
3
3
|
import { type MedusaClient } from '../core/client.js';
|
|
4
4
|
export declare class MedusaInventoryProvider extends InventoryProvider {
|
|
5
5
|
client: MedusaClient;
|
|
6
6
|
protected config: MedusaConfiguration;
|
|
7
7
|
constructor(config: MedusaConfiguration, cache: Cache, context: RequestContext, client: MedusaClient);
|
|
8
|
-
getBySKU(payload: InventoryQueryBySKU): Promise<Inventory
|
|
8
|
+
getBySKU(payload: InventoryQueryBySKU): Promise<Result<Inventory, NotFoundError>>;
|
|
9
9
|
protected parseSingle(_body: unknown): Inventory;
|
|
10
10
|
/**
|
|
11
11
|
* Utility function to create an empty inventory result.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { StoreProductVariant } from '@medusajs/types';
|
|
2
|
-
import { PriceProvider, type Cache, type CustomerPriceQuery, type ListPriceQuery, type Price, type RequestContext } from '@reactionary/core';
|
|
2
|
+
import { PriceProvider, type Cache, type CustomerPriceQuery, type ListPriceQuery, type Price, type RequestContext, type Result } from '@reactionary/core';
|
|
3
3
|
import type { MedusaClient } from '../core/client.js';
|
|
4
4
|
import type { MedusaConfiguration } from '../schema/configuration.schema.js';
|
|
5
5
|
export declare class MedusaPriceProvider extends PriceProvider {
|
|
6
6
|
client: MedusaClient;
|
|
7
7
|
protected config: MedusaConfiguration;
|
|
8
8
|
constructor(config: MedusaConfiguration, cache: Cache, context: RequestContext, client: MedusaClient);
|
|
9
|
-
getListPrice(payload: ListPriceQuery): Promise<Price
|
|
10
|
-
getCustomerPrice(payload: CustomerPriceQuery): Promise<Price
|
|
9
|
+
getListPrice(payload: ListPriceQuery): Promise<Result<Price>>;
|
|
10
|
+
getCustomerPrice(payload: CustomerPriceQuery): Promise<Result<Price>>;
|
|
11
11
|
protected getBySKU(payload: ListPriceQuery | CustomerPriceQuery): Promise<Price>;
|
|
12
12
|
protected parseSingle(variant: StoreProductVariant): Price;
|
|
13
13
|
protected getResourceName(): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProductSearchProvider, type Cache, type RequestContext, type ProductSearchQueryByTerm, type ProductSearchResult, type ProductSearchResultItem, type ProductSearchResultItemVariant, type FacetIdentifier, type FacetValueIdentifier, type ProductSearchResultFacet, type ProductSearchResultFacetValue, type ProductSearchQueryCreateNavigationFilter } from '@reactionary/core';
|
|
1
|
+
import { ProductSearchProvider, type Cache, type RequestContext, type ProductSearchQueryByTerm, type ProductSearchResult, type ProductSearchResultItem, type ProductSearchResultItemVariant, type FacetIdentifier, type FacetValueIdentifier, type ProductSearchResultFacet, type ProductSearchResultFacetValue, type ProductSearchQueryCreateNavigationFilter, type Result } from '@reactionary/core';
|
|
2
2
|
import type { MedusaConfiguration } from '../schema/configuration.schema.js';
|
|
3
3
|
import type { MedusaClient } from '../core/client.js';
|
|
4
4
|
import type { StoreProduct, StoreProductCategory, StoreProductListResponse, StoreProductVariant } from '@medusajs/types';
|
|
@@ -7,7 +7,7 @@ export declare class MedusaSearchProvider extends ProductSearchProvider {
|
|
|
7
7
|
protected config: MedusaConfiguration;
|
|
8
8
|
constructor(config: MedusaConfiguration, cache: Cache, context: RequestContext, client: MedusaClient);
|
|
9
9
|
protected resolveCategoryIdByExternalId(externalId: string): Promise<StoreProductCategory | null>;
|
|
10
|
-
queryByTerm(payload: ProductSearchQueryByTerm): Promise<ProductSearchResult
|
|
10
|
+
queryByTerm(payload: ProductSearchQueryByTerm): Promise<Result<ProductSearchResult>>;
|
|
11
11
|
protected parsePaginatedResult(remote: StoreProductListResponse): {
|
|
12
12
|
identifier: {
|
|
13
13
|
facets: never[];
|
|
@@ -18,25 +18,11 @@ export declare class MedusaSearchProvider extends ProductSearchProvider {
|
|
|
18
18
|
};
|
|
19
19
|
term: string;
|
|
20
20
|
};
|
|
21
|
-
meta: {
|
|
22
|
-
cache: {
|
|
23
|
-
hit: false;
|
|
24
|
-
key: string;
|
|
25
|
-
};
|
|
26
|
-
placeholder: false;
|
|
27
|
-
};
|
|
28
21
|
pageNumber: number;
|
|
29
22
|
pageSize: number;
|
|
30
23
|
totalCount: number;
|
|
31
24
|
totalPages: number;
|
|
32
25
|
items: {
|
|
33
|
-
meta: {
|
|
34
|
-
cache: {
|
|
35
|
-
hit: boolean;
|
|
36
|
-
key: string;
|
|
37
|
-
};
|
|
38
|
-
placeholder: boolean;
|
|
39
|
-
};
|
|
40
26
|
identifier: {
|
|
41
27
|
key: string;
|
|
42
28
|
};
|
|
@@ -73,7 +59,7 @@ export declare class MedusaSearchProvider extends ProductSearchProvider {
|
|
|
73
59
|
};
|
|
74
60
|
protected parseSingle(_body: StoreProduct): ProductSearchResultItem;
|
|
75
61
|
protected parseVariant(variant: StoreProductVariant, product: StoreProduct): ProductSearchResultItemVariant;
|
|
76
|
-
createCategoryNavigationFilter(payload: ProductSearchQueryCreateNavigationFilter): Promise<FacetValueIdentifier
|
|
62
|
+
createCategoryNavigationFilter(payload: ProductSearchQueryCreateNavigationFilter): Promise<Result<FacetValueIdentifier>>;
|
|
77
63
|
protected parseFacetValue(facetValueIdentifier: FacetValueIdentifier, label: string, count: number): ProductSearchResultFacetValue;
|
|
78
64
|
protected parseFacet(facetIdentifier: FacetIdentifier, facetValue: unknown): ProductSearchResultFacet;
|
|
79
65
|
}
|