@reactionary/commercetools 0.6.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/README.md +11 -0
- package/capabilities/cart.capability.js +324 -0
- package/capabilities/category.capability.js +198 -0
- package/capabilities/checkout.capability.js +374 -0
- package/capabilities/identity.capability.js +95 -0
- package/capabilities/index.js +15 -0
- package/capabilities/inventory.capability.js +63 -0
- package/capabilities/order-search.capability.js +106 -0
- package/capabilities/order.capability.js +48 -0
- package/capabilities/price.capability.js +114 -0
- package/capabilities/product-associations.capability.js +120 -0
- package/capabilities/product-list.capability.js +393 -0
- package/capabilities/product-reviews.capability.js +193 -0
- package/capabilities/product-search.capability.js +297 -0
- package/capabilities/product.capability.js +103 -0
- package/capabilities/profile.capability.js +337 -0
- package/capabilities/store.capability.js +51 -0
- package/core/capability-descriptors.js +274 -0
- package/core/client.js +318 -0
- package/core/initialize.js +47 -0
- package/core/initialize.types.js +8 -0
- package/core/token-cache.js +36 -0
- package/factories/cart/cart.factory.js +110 -0
- package/factories/category/category.factory.js +40 -0
- package/factories/checkout/checkout-initializer-overrides.example.js +67 -0
- package/factories/checkout/checkout.factory.js +235 -0
- package/factories/identity/identity.factory.js +14 -0
- package/factories/inventory/inventory.factory.js +30 -0
- package/factories/order/order.factory.js +114 -0
- package/factories/order-search/order-search.factory.js +68 -0
- package/factories/price/price.factory.js +52 -0
- package/factories/product/product-capability-custom-method-only.example.js +38 -0
- package/factories/product/product-capability-schema-signature-extension.example.js +46 -0
- package/factories/product/product-factory-baseline.example.js +10 -0
- package/factories/product/product-factory-schema-and-parse-extension.example.js +25 -0
- package/factories/product/product-factory-schema-extension.example.js +18 -0
- package/factories/product/product-initializer-factory-extension.example.js +33 -0
- package/factories/product/product.factory.js +151 -0
- package/factories/product/utils.example.js +8 -0
- package/factories/product-associations/product-associations.factory.js +63 -0
- package/factories/product-list/product-list.factory.js +65 -0
- package/factories/product-reviews/product-reviews.factory.js +42 -0
- package/factories/product-search/product-search.factory.js +114 -0
- package/factories/profile/profile.factory.js +62 -0
- package/factories/store/store.factory.js +29 -0
- package/index.js +28 -0
- package/package.json +17 -0
- package/schema/capabilities.schema.js +46 -0
- package/schema/commercetools.schema.js +30 -0
- package/schema/configuration.schema.js +19 -0
- package/schema/session.schema.js +9 -0
- package/src/capabilities/cart.capability.d.ts +34 -0
- package/src/capabilities/category.capability.d.ts +47 -0
- package/src/capabilities/checkout.capability.d.ts +39 -0
- package/src/capabilities/identity.capability.d.ts +14 -0
- package/src/capabilities/index.d.ts +15 -0
- package/src/capabilities/inventory.capability.d.ts +13 -0
- package/src/capabilities/order-search.capability.d.ts +13 -0
- package/src/capabilities/order.capability.d.ts +13 -0
- package/src/capabilities/price.capability.d.ts +18 -0
- package/src/capabilities/product-associations.capability.d.ts +17 -0
- package/src/capabilities/product-list.capability.d.ts +29 -0
- package/src/capabilities/product-reviews.capability.d.ts +18 -0
- package/src/capabilities/product-search.capability.d.ts +82 -0
- package/src/capabilities/product.capability.d.ts +17 -0
- package/src/capabilities/profile.capability.d.ts +30 -0
- package/src/capabilities/store.capability.d.ts +13 -0
- package/src/core/capability-descriptors.d.ts +16 -0
- package/src/core/client.d.ts +55 -0
- package/src/core/initialize.d.ts +5 -0
- package/src/core/initialize.types.d.ts +118 -0
- package/src/core/token-cache.d.ts +9 -0
- package/src/factories/cart/cart.factory.d.ts +14 -0
- package/src/factories/category/category.factory.d.ts +11 -0
- package/src/factories/checkout/checkout-initializer-overrides.example.d.ts +1 -0
- package/src/factories/checkout/checkout.factory.d.ts +18 -0
- package/src/factories/identity/identity.factory.d.ts +8 -0
- package/src/factories/inventory/inventory.factory.d.ts +9 -0
- package/src/factories/order/order.factory.d.ts +9 -0
- package/src/factories/order-search/order-search.factory.d.ts +11 -0
- package/src/factories/price/price.factory.d.ts +11 -0
- package/src/factories/product/product-capability-custom-method-only.example.d.ts +1 -0
- package/src/factories/product/product-capability-schema-signature-extension.example.d.ts +1 -0
- package/src/factories/product/product-factory-baseline.example.d.ts +1 -0
- package/src/factories/product/product-factory-schema-and-parse-extension.example.d.ts +1 -0
- package/src/factories/product/product-factory-schema-extension.example.d.ts +1 -0
- package/src/factories/product/product-initializer-factory-extension.example.d.ts +1 -0
- package/src/factories/product/product.factory.d.ts +18 -0
- package/src/factories/product/utils.example.d.ts +4 -0
- package/src/factories/product-associations/product-associations.factory.d.ts +15 -0
- package/src/factories/product-list/product-list.factory.d.ts +17 -0
- package/src/factories/product-reviews/product-reviews.factory.d.ts +14 -0
- package/src/factories/product-search/product-search.factory.d.ts +13 -0
- package/src/factories/profile/profile.factory.d.ts +11 -0
- package/src/factories/store/store.factory.d.ts +9 -0
- package/src/index.d.ts +28 -0
- package/src/schema/capabilities.schema.d.ts +104 -0
- package/src/schema/commercetools.schema.d.ts +30 -0
- package/src/schema/configuration.schema.d.ts +30 -0
- package/src/schema/session.schema.d.ts +7 -0
- package/src/test/client-builder-merge-extensions.example.d.ts +1 -0
- package/src/test/test-utils.d.ts +27 -0
- package/test/client-builder-merge-extensions.example.js +94 -0
- package/test/test-utils.js +27 -0
|
@@ -0,0 +1,337 @@
|
|
|
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
|
+
ProfileMutationUpdateSchema,
|
|
14
|
+
ProfileCapability,
|
|
15
|
+
ProfileSchema,
|
|
16
|
+
Reactionary,
|
|
17
|
+
success,
|
|
18
|
+
error,
|
|
19
|
+
ProfileMutationSetBillingAddressSchema,
|
|
20
|
+
ProfileMutationRemoveShippingAddressSchema,
|
|
21
|
+
ProfileMutationAddShippingAddressSchema
|
|
22
|
+
} from "@reactionary/core";
|
|
23
|
+
class CommercetoolsProfileCapability extends ProfileCapability {
|
|
24
|
+
config;
|
|
25
|
+
commercetools;
|
|
26
|
+
factory;
|
|
27
|
+
constructor(config, cache, context, commercetools, factory) {
|
|
28
|
+
super(cache, context);
|
|
29
|
+
this.config = config;
|
|
30
|
+
this.commercetools = commercetools;
|
|
31
|
+
this.factory = factory;
|
|
32
|
+
}
|
|
33
|
+
async getClient() {
|
|
34
|
+
const client = await this.commercetools.getClient();
|
|
35
|
+
return client.withProjectKey({ projectKey: this.config.projectKey });
|
|
36
|
+
}
|
|
37
|
+
async getById(payload) {
|
|
38
|
+
const client = await this.getClient();
|
|
39
|
+
const remote = await client.me().get().execute();
|
|
40
|
+
if (remote.body.id !== payload.identifier.userId) {
|
|
41
|
+
return error({
|
|
42
|
+
type: "NotFound",
|
|
43
|
+
identifier: payload.identifier
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const model = this.factory.parseProfile(this.context, remote.body);
|
|
47
|
+
return success(model);
|
|
48
|
+
}
|
|
49
|
+
async addShippingAddress(payload) {
|
|
50
|
+
const client = await this.getClient();
|
|
51
|
+
const remote = await client.me().get().execute();
|
|
52
|
+
let customer = remote.body;
|
|
53
|
+
if (customer.id !== payload.identifier.userId) {
|
|
54
|
+
return error({
|
|
55
|
+
type: "NotFound",
|
|
56
|
+
identifier: payload.identifier
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const updateResponse = await client.me().post({
|
|
60
|
+
body: {
|
|
61
|
+
version: customer.version,
|
|
62
|
+
actions: [
|
|
63
|
+
{
|
|
64
|
+
action: "addAddress",
|
|
65
|
+
address: this.createCTAddressDraft(payload.address)
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
}).execute();
|
|
70
|
+
customer = updateResponse.body;
|
|
71
|
+
const model = this.factory.parseProfile(this.context, customer);
|
|
72
|
+
return success(model);
|
|
73
|
+
}
|
|
74
|
+
async updateShippingAddress(payload) {
|
|
75
|
+
const client = await this.getClient();
|
|
76
|
+
const remote = await client.me().get().execute();
|
|
77
|
+
let customer = remote.body;
|
|
78
|
+
if (customer.id !== payload.identifier.userId) {
|
|
79
|
+
return error({
|
|
80
|
+
type: "NotFound",
|
|
81
|
+
identifier: payload.identifier
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
const targetAddress = customer.addresses.find((addr) => addr.key === payload.address.identifier.nickName);
|
|
85
|
+
if (!targetAddress) {
|
|
86
|
+
return error({
|
|
87
|
+
type: "NotFound",
|
|
88
|
+
identifier: payload.identifier
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
const updateResponse = await client.me().post({
|
|
92
|
+
body: {
|
|
93
|
+
version: customer.version,
|
|
94
|
+
actions: [
|
|
95
|
+
{
|
|
96
|
+
action: "changeAddress",
|
|
97
|
+
addressId: targetAddress.id,
|
|
98
|
+
address: this.createCTAddressDraft(payload.address)
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
}).execute();
|
|
103
|
+
customer = updateResponse.body;
|
|
104
|
+
const model = this.factory.parseProfile(this.context, customer);
|
|
105
|
+
return success(model);
|
|
106
|
+
}
|
|
107
|
+
async removeShippingAddress(payload) {
|
|
108
|
+
const client = await this.getClient();
|
|
109
|
+
const remote = await client.me().get().execute();
|
|
110
|
+
let customer = remote.body;
|
|
111
|
+
if (customer.id !== payload.identifier.userId) {
|
|
112
|
+
return error({
|
|
113
|
+
type: "NotFound",
|
|
114
|
+
identifier: payload.identifier
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
const updateActions = [];
|
|
118
|
+
const addressToRemove = customer.addresses.find((addr) => addr.key === payload.addressIdentifier.nickName);
|
|
119
|
+
if (addressToRemove) {
|
|
120
|
+
updateActions.push({
|
|
121
|
+
action: "removeAddress",
|
|
122
|
+
addressId: addressToRemove.id
|
|
123
|
+
});
|
|
124
|
+
} else {
|
|
125
|
+
return error({
|
|
126
|
+
type: "NotFound",
|
|
127
|
+
identifier: payload.identifier
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
const needsNewDefaultShippingAddress = addressToRemove && customer.defaultShippingAddressId === addressToRemove.id;
|
|
131
|
+
if (needsNewDefaultShippingAddress) {
|
|
132
|
+
const newDefaultAddress = customer.addresses.find((addr) => addr.id !== addressToRemove.id && addr.id !== customer.defaultBillingAddressId);
|
|
133
|
+
if (newDefaultAddress) {
|
|
134
|
+
updateActions.push({
|
|
135
|
+
action: "setDefaultShippingAddress",
|
|
136
|
+
addressKey: newDefaultAddress.key
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const updateResponse = await client.me().post({
|
|
141
|
+
body: {
|
|
142
|
+
version: customer.version,
|
|
143
|
+
actions: updateActions
|
|
144
|
+
}
|
|
145
|
+
}).execute();
|
|
146
|
+
customer = updateResponse.body;
|
|
147
|
+
const model = this.factory.parseProfile(this.context, customer);
|
|
148
|
+
return success(model);
|
|
149
|
+
}
|
|
150
|
+
async makeShippingAddressDefault(payload) {
|
|
151
|
+
const client = await this.getClient();
|
|
152
|
+
const remote = await client.me().get().execute();
|
|
153
|
+
let customer = remote.body;
|
|
154
|
+
if (customer.id !== payload.identifier.userId) {
|
|
155
|
+
return error({
|
|
156
|
+
type: "NotFound",
|
|
157
|
+
identifier: payload.identifier
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
const addressToMakeDefault = customer.addresses.find((addr) => addr.key === payload.addressIdentifier.nickName);
|
|
161
|
+
if (!addressToMakeDefault) {
|
|
162
|
+
return error({
|
|
163
|
+
type: "NotFound",
|
|
164
|
+
identifier: payload.identifier
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
if (addressToMakeDefault.id === customer.defaultBillingAddressId) {
|
|
168
|
+
return error({
|
|
169
|
+
type: "InvalidInput",
|
|
170
|
+
error: "Cannot set shipping address as default billing address"
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
const updateResponse = await client.me().post({
|
|
174
|
+
body: {
|
|
175
|
+
version: customer.version,
|
|
176
|
+
actions: [
|
|
177
|
+
{
|
|
178
|
+
action: "setDefaultShippingAddress",
|
|
179
|
+
addressKey: addressToMakeDefault.key
|
|
180
|
+
}
|
|
181
|
+
]
|
|
182
|
+
}
|
|
183
|
+
}).execute();
|
|
184
|
+
customer = updateResponse.body;
|
|
185
|
+
const model = this.factory.parseProfile(this.context, customer);
|
|
186
|
+
return success(model);
|
|
187
|
+
}
|
|
188
|
+
async setBillingAddress(payload) {
|
|
189
|
+
const client = await this.getClient();
|
|
190
|
+
const remote = await client.me().get().execute();
|
|
191
|
+
let customer = remote.body;
|
|
192
|
+
if (customer.id !== payload.identifier.userId) {
|
|
193
|
+
return error({
|
|
194
|
+
type: "NotFound",
|
|
195
|
+
identifier: payload.identifier
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
const updateActions = [];
|
|
199
|
+
const mainAddress = customer.defaultBillingAddressId ? customer.addresses.find((addr) => addr.id === customer.defaultBillingAddressId) : null;
|
|
200
|
+
if (!mainAddress) {
|
|
201
|
+
const newAddress = this.createCTAddressDraft(payload.address);
|
|
202
|
+
updateActions.push({
|
|
203
|
+
action: "addAddress",
|
|
204
|
+
address: newAddress
|
|
205
|
+
});
|
|
206
|
+
updateActions.push({
|
|
207
|
+
action: "setDefaultBillingAddress",
|
|
208
|
+
addressKey: newAddress.key
|
|
209
|
+
});
|
|
210
|
+
} else {
|
|
211
|
+
updateActions.push({
|
|
212
|
+
action: "changeAddress",
|
|
213
|
+
addressId: mainAddress.id,
|
|
214
|
+
address: this.createCTAddressDraft(payload.address)
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
if (updateActions.length > 0) {
|
|
218
|
+
const updateResponse = await client.me().post({
|
|
219
|
+
body: {
|
|
220
|
+
version: customer.version,
|
|
221
|
+
actions: updateActions
|
|
222
|
+
}
|
|
223
|
+
}).execute();
|
|
224
|
+
customer = updateResponse.body;
|
|
225
|
+
}
|
|
226
|
+
const model = this.factory.parseProfile(this.context, customer);
|
|
227
|
+
return success(model);
|
|
228
|
+
}
|
|
229
|
+
async update(payload) {
|
|
230
|
+
const client = await this.getClient();
|
|
231
|
+
const remote = await client.me().get().execute();
|
|
232
|
+
let customer = remote.body;
|
|
233
|
+
if (customer.id !== payload.identifier.userId) {
|
|
234
|
+
return error({
|
|
235
|
+
type: "NotFound",
|
|
236
|
+
identifier: payload.identifier
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
const updateActions = [];
|
|
240
|
+
if (payload.email !== void 0) {
|
|
241
|
+
updateActions.push({
|
|
242
|
+
action: "changeEmail",
|
|
243
|
+
email: payload.email
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
const mainAddress = customer.defaultBillingAddressId ? customer.addresses.find((addr) => addr.id === customer.defaultBillingAddressId) : null;
|
|
247
|
+
if (!mainAddress) {
|
|
248
|
+
updateActions.push({
|
|
249
|
+
action: "addAddress",
|
|
250
|
+
address: {
|
|
251
|
+
key: `billing-address-${customer.id}`,
|
|
252
|
+
email: payload.email || customer.email,
|
|
253
|
+
phone: payload.phone,
|
|
254
|
+
country: this.context.taxJurisdiction.countryCode
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
updateActions.push({
|
|
258
|
+
action: "setDefaultBillingAddress",
|
|
259
|
+
addressKey: `billing-address-${customer.id}`
|
|
260
|
+
});
|
|
261
|
+
} else {
|
|
262
|
+
updateActions.push({
|
|
263
|
+
action: "changeAddress",
|
|
264
|
+
addressId: mainAddress.id,
|
|
265
|
+
address: {
|
|
266
|
+
...mainAddress,
|
|
267
|
+
email: payload.email || customer.email,
|
|
268
|
+
phone: payload.phone
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
if (updateActions.length > 0) {
|
|
273
|
+
const updateResponse = await client.me().post({
|
|
274
|
+
body: {
|
|
275
|
+
version: customer.version,
|
|
276
|
+
actions: updateActions
|
|
277
|
+
}
|
|
278
|
+
}).execute();
|
|
279
|
+
customer = updateResponse.body;
|
|
280
|
+
}
|
|
281
|
+
const model = this.factory.parseProfile(this.context, customer);
|
|
282
|
+
return success(model);
|
|
283
|
+
}
|
|
284
|
+
createCTAddressDraft(address) {
|
|
285
|
+
return {
|
|
286
|
+
key: address.identifier.nickName,
|
|
287
|
+
firstName: address.firstName,
|
|
288
|
+
lastName: address.lastName,
|
|
289
|
+
streetName: address.streetAddress,
|
|
290
|
+
streetNumber: address.streetNumber,
|
|
291
|
+
postalCode: address.postalCode,
|
|
292
|
+
city: address.city,
|
|
293
|
+
region: address.region,
|
|
294
|
+
country: address.countryCode || this.context.taxJurisdiction.countryCode
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Checks if an address only contains phone information and lacks essential address fields.
|
|
299
|
+
* An address is considered incomplete if it exists but has no firstName, lastName, streetName,
|
|
300
|
+
* streetNumber, or city.
|
|
301
|
+
* @param address - The address to check, or undefined
|
|
302
|
+
* @returns true if the address exists but lacks essential fields, false otherwise (including when address is undefined)
|
|
303
|
+
*/
|
|
304
|
+
isIncompleteAddress(address) {
|
|
305
|
+
if (!address) {
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
return !address.firstName && !address.lastName && !address.streetName && !address.streetNumber && !address.city;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
__decorateClass([
|
|
312
|
+
Reactionary({
|
|
313
|
+
inputSchema: ProfileMutationAddShippingAddressSchema,
|
|
314
|
+
outputSchema: ProfileSchema
|
|
315
|
+
})
|
|
316
|
+
], CommercetoolsProfileCapability.prototype, "addShippingAddress", 1);
|
|
317
|
+
__decorateClass([
|
|
318
|
+
Reactionary({
|
|
319
|
+
inputSchema: ProfileMutationRemoveShippingAddressSchema,
|
|
320
|
+
outputSchema: ProfileSchema
|
|
321
|
+
})
|
|
322
|
+
], CommercetoolsProfileCapability.prototype, "removeShippingAddress", 1);
|
|
323
|
+
__decorateClass([
|
|
324
|
+
Reactionary({
|
|
325
|
+
inputSchema: ProfileMutationSetBillingAddressSchema,
|
|
326
|
+
outputSchema: ProfileSchema
|
|
327
|
+
})
|
|
328
|
+
], CommercetoolsProfileCapability.prototype, "setBillingAddress", 1);
|
|
329
|
+
__decorateClass([
|
|
330
|
+
Reactionary({
|
|
331
|
+
inputSchema: ProfileMutationUpdateSchema,
|
|
332
|
+
outputSchema: ProfileSchema
|
|
333
|
+
})
|
|
334
|
+
], CommercetoolsProfileCapability.prototype, "update", 1);
|
|
335
|
+
export {
|
|
336
|
+
CommercetoolsProfileCapability
|
|
337
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
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 { Reactionary, StoreCapability, StoreQueryByProximitySchema, StoreSchema, success, error } from "@reactionary/core";
|
|
13
|
+
import * as z from "zod";
|
|
14
|
+
class CommercetoolsStoreCapability extends StoreCapability {
|
|
15
|
+
config;
|
|
16
|
+
commercetools;
|
|
17
|
+
factory;
|
|
18
|
+
constructor(config, cache, context, commercetools, factory) {
|
|
19
|
+
super(cache, context);
|
|
20
|
+
this.config = config;
|
|
21
|
+
this.commercetools = commercetools;
|
|
22
|
+
this.factory = factory;
|
|
23
|
+
}
|
|
24
|
+
async getClient() {
|
|
25
|
+
const client = await this.commercetools.getClient();
|
|
26
|
+
return client.withProjectKey({ projectKey: this.config.projectKey });
|
|
27
|
+
}
|
|
28
|
+
async queryByProximity(payload) {
|
|
29
|
+
const client = await this.getClient();
|
|
30
|
+
const remote = await client.channels().get({
|
|
31
|
+
queryArgs: {
|
|
32
|
+
limit: payload.limit,
|
|
33
|
+
where: `geoLocation within circle(${payload.longitude}, ${payload.latitude}, ${payload.distance * 1e3}) AND roles contains any ("InventorySupply")`
|
|
34
|
+
}
|
|
35
|
+
}).execute();
|
|
36
|
+
const results = [];
|
|
37
|
+
for (const r of remote.body.results) {
|
|
38
|
+
results.push(this.factory.parseStore(this.context, r));
|
|
39
|
+
}
|
|
40
|
+
return success(results);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
__decorateClass([
|
|
44
|
+
Reactionary({
|
|
45
|
+
inputSchema: StoreQueryByProximitySchema,
|
|
46
|
+
outputSchema: z.array(StoreSchema)
|
|
47
|
+
})
|
|
48
|
+
], CommercetoolsStoreCapability.prototype, "queryByProximity", 1);
|
|
49
|
+
export {
|
|
50
|
+
CommercetoolsStoreCapability
|
|
51
|
+
};
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CartIdentifierSchema,
|
|
3
|
+
CartSchema,
|
|
4
|
+
CategoryPaginatedResultSchema,
|
|
5
|
+
CategorySchema,
|
|
6
|
+
CheckoutSchema,
|
|
7
|
+
IdentitySchema,
|
|
8
|
+
InventorySchema,
|
|
9
|
+
OrderSearchResultSchema,
|
|
10
|
+
OrderSchema,
|
|
11
|
+
PaymentMethodSchema,
|
|
12
|
+
ProductAssociationSchema,
|
|
13
|
+
ProductListItemPaginatedResultsSchema,
|
|
14
|
+
ProductListItemSchema,
|
|
15
|
+
ProductListPaginatedResultsSchema,
|
|
16
|
+
ProductListSchema,
|
|
17
|
+
ProductRatingSummarySchema,
|
|
18
|
+
ProductReviewPaginatedResultSchema,
|
|
19
|
+
ProductReviewSchema,
|
|
20
|
+
ProductSchema,
|
|
21
|
+
ProductSearchResultSchema,
|
|
22
|
+
ProfileSchema,
|
|
23
|
+
PriceSchema,
|
|
24
|
+
ShippingMethodSchema,
|
|
25
|
+
StoreSchema
|
|
26
|
+
} from "@reactionary/core";
|
|
27
|
+
import {
|
|
28
|
+
} from "../schema/capabilities.schema.js";
|
|
29
|
+
import { CommercetoolsCartFactory } from "../factories/cart/cart.factory.js";
|
|
30
|
+
import { CommercetoolsCategoryFactory } from "../factories/category/category.factory.js";
|
|
31
|
+
import { CommercetoolsCheckoutFactory } from "../factories/checkout/checkout.factory.js";
|
|
32
|
+
import { CommercetoolsIdentityFactory } from "../factories/identity/identity.factory.js";
|
|
33
|
+
import { CommercetoolsInventoryFactory } from "../factories/inventory/inventory.factory.js";
|
|
34
|
+
import { CommercetoolsOrderFactory } from "../factories/order/order.factory.js";
|
|
35
|
+
import { CommercetoolsOrderSearchFactory } from "../factories/order-search/order-search.factory.js";
|
|
36
|
+
import { CommercetoolsPriceFactory } from "../factories/price/price.factory.js";
|
|
37
|
+
import { CommercetoolsProductAssociationsFactory } from "../factories/product-associations/product-associations.factory.js";
|
|
38
|
+
import { CommercetoolsProductListFactory } from "../factories/product-list/product-list.factory.js";
|
|
39
|
+
import { CommercetoolsProductFactory } from "../factories/product/product.factory.js";
|
|
40
|
+
import { CommercetoolsProductReviewsFactory } from "../factories/product-reviews/product-reviews.factory.js";
|
|
41
|
+
import { CommercetoolsProductSearchFactory } from "../factories/product-search/product-search.factory.js";
|
|
42
|
+
import { CommercetoolsProfileFactory } from "../factories/profile/profile.factory.js";
|
|
43
|
+
import { CommercetoolsStoreFactory } from "../factories/store/store.factory.js";
|
|
44
|
+
import { CommercetoolsCartCapability } from "../capabilities/cart.capability.js";
|
|
45
|
+
import { CommercetoolsCategoryCapability } from "../capabilities/category.capability.js";
|
|
46
|
+
import { CommercetoolsCheckoutCapability } from "../capabilities/checkout.capability.js";
|
|
47
|
+
import { CommercetoolsIdentityCapability } from "../capabilities/identity.capability.js";
|
|
48
|
+
import { CommercetoolsInventoryCapability } from "../capabilities/inventory.capability.js";
|
|
49
|
+
import { CommercetoolsOrderCapability } from "../capabilities/order.capability.js";
|
|
50
|
+
import { CommercetoolsOrderSearchCapability } from "../capabilities/order-search.capability.js";
|
|
51
|
+
import { CommercetoolsPriceCapability } from "../capabilities/price.capability.js";
|
|
52
|
+
import { CommercetoolsProductAssociationsCapability } from "../capabilities/product-associations.capability.js";
|
|
53
|
+
import { CommercetoolsProductListCapability } from "../capabilities/product-list.capability.js";
|
|
54
|
+
import { CommercetoolsProductCapability } from "../capabilities/product.capability.js";
|
|
55
|
+
import { CommercetoolsProductReviewsCapability } from "../capabilities/product-reviews.capability.js";
|
|
56
|
+
import { CommercetoolsProductSearchCapability } from "../capabilities/product-search.capability.js";
|
|
57
|
+
import { CommercetoolsProfileCapability } from "../capabilities/profile.capability.js";
|
|
58
|
+
import { CommercetoolsStoreCapability } from "../capabilities/store.capability.js";
|
|
59
|
+
const capabilityKeys = [
|
|
60
|
+
"product",
|
|
61
|
+
"profile",
|
|
62
|
+
"productSearch",
|
|
63
|
+
"productAssociations",
|
|
64
|
+
"productList",
|
|
65
|
+
"productReviews",
|
|
66
|
+
"identity",
|
|
67
|
+
"cart",
|
|
68
|
+
"inventory",
|
|
69
|
+
"price",
|
|
70
|
+
"category",
|
|
71
|
+
"checkout",
|
|
72
|
+
"store",
|
|
73
|
+
"order",
|
|
74
|
+
"orderSearch"
|
|
75
|
+
];
|
|
76
|
+
const capabilityDescriptors = {
|
|
77
|
+
product: {
|
|
78
|
+
isEnabled: (caps) => caps.product?.enabled,
|
|
79
|
+
getOverride: (caps) => caps.product,
|
|
80
|
+
createDefaultFactory: () => new CommercetoolsProductFactory(ProductSchema),
|
|
81
|
+
createDefaultCapability: (args) => new CommercetoolsProductCapability(
|
|
82
|
+
args.cache,
|
|
83
|
+
args.context,
|
|
84
|
+
args.config,
|
|
85
|
+
args.commercetoolsApi,
|
|
86
|
+
args.factory
|
|
87
|
+
)
|
|
88
|
+
},
|
|
89
|
+
profile: {
|
|
90
|
+
isEnabled: (caps) => caps.profile?.enabled,
|
|
91
|
+
getOverride: (caps) => caps.profile,
|
|
92
|
+
createDefaultFactory: () => new CommercetoolsProfileFactory(ProfileSchema),
|
|
93
|
+
createDefaultCapability: (args) => new CommercetoolsProfileCapability(
|
|
94
|
+
args.config,
|
|
95
|
+
args.cache,
|
|
96
|
+
args.context,
|
|
97
|
+
args.commercetoolsApi,
|
|
98
|
+
args.factory
|
|
99
|
+
)
|
|
100
|
+
},
|
|
101
|
+
productSearch: {
|
|
102
|
+
isEnabled: (caps) => caps.productSearch?.enabled,
|
|
103
|
+
getOverride: (caps) => caps.productSearch,
|
|
104
|
+
createDefaultFactory: () => new CommercetoolsProductSearchFactory(ProductSearchResultSchema),
|
|
105
|
+
createDefaultCapability: (args) => new CommercetoolsProductSearchCapability(
|
|
106
|
+
args.config,
|
|
107
|
+
args.cache,
|
|
108
|
+
args.context,
|
|
109
|
+
args.commercetoolsApi,
|
|
110
|
+
args.factory
|
|
111
|
+
)
|
|
112
|
+
},
|
|
113
|
+
productAssociations: {
|
|
114
|
+
isEnabled: (caps) => caps.productAssociations?.enabled,
|
|
115
|
+
getOverride: (caps) => caps.productAssociations,
|
|
116
|
+
createDefaultFactory: () => new CommercetoolsProductAssociationsFactory(ProductAssociationSchema),
|
|
117
|
+
createDefaultCapability: (args) => new CommercetoolsProductAssociationsCapability(
|
|
118
|
+
args.config,
|
|
119
|
+
args.cache,
|
|
120
|
+
args.context,
|
|
121
|
+
args.commercetoolsApi,
|
|
122
|
+
args.factory
|
|
123
|
+
)
|
|
124
|
+
},
|
|
125
|
+
productList: {
|
|
126
|
+
isEnabled: (caps) => caps.productList?.enabled,
|
|
127
|
+
getOverride: (caps) => caps.productList,
|
|
128
|
+
createDefaultFactory: () => new CommercetoolsProductListFactory(
|
|
129
|
+
ProductListSchema,
|
|
130
|
+
ProductListItemSchema,
|
|
131
|
+
ProductListPaginatedResultsSchema,
|
|
132
|
+
ProductListItemPaginatedResultsSchema
|
|
133
|
+
),
|
|
134
|
+
createDefaultCapability: (args) => new CommercetoolsProductListCapability(
|
|
135
|
+
args.config,
|
|
136
|
+
args.cache,
|
|
137
|
+
args.context,
|
|
138
|
+
args.commercetoolsApi,
|
|
139
|
+
args.factory
|
|
140
|
+
)
|
|
141
|
+
},
|
|
142
|
+
productReviews: {
|
|
143
|
+
isEnabled: (caps) => caps.productReviews?.enabled,
|
|
144
|
+
getOverride: (caps) => caps.productReviews,
|
|
145
|
+
createDefaultFactory: () => new CommercetoolsProductReviewsFactory(
|
|
146
|
+
ProductRatingSummarySchema,
|
|
147
|
+
ProductReviewSchema,
|
|
148
|
+
ProductReviewPaginatedResultSchema
|
|
149
|
+
),
|
|
150
|
+
createDefaultCapability: (args) => new CommercetoolsProductReviewsCapability(
|
|
151
|
+
args.config,
|
|
152
|
+
args.cache,
|
|
153
|
+
args.context,
|
|
154
|
+
args.commercetoolsApi,
|
|
155
|
+
args.factory
|
|
156
|
+
)
|
|
157
|
+
},
|
|
158
|
+
identity: {
|
|
159
|
+
isEnabled: (caps) => caps.identity?.enabled,
|
|
160
|
+
getOverride: (caps) => caps.identity,
|
|
161
|
+
createDefaultFactory: () => new CommercetoolsIdentityFactory(IdentitySchema),
|
|
162
|
+
createDefaultCapability: (args) => new CommercetoolsIdentityCapability(
|
|
163
|
+
args.config,
|
|
164
|
+
args.cache,
|
|
165
|
+
args.context,
|
|
166
|
+
args.commercetoolsApi,
|
|
167
|
+
args.factory
|
|
168
|
+
)
|
|
169
|
+
},
|
|
170
|
+
cart: {
|
|
171
|
+
isEnabled: (caps) => caps.cart?.enabled,
|
|
172
|
+
getOverride: (caps) => caps.cart,
|
|
173
|
+
createDefaultFactory: () => new CommercetoolsCartFactory(CartSchema, CartIdentifierSchema),
|
|
174
|
+
createDefaultCapability: (args) => new CommercetoolsCartCapability(
|
|
175
|
+
args.config,
|
|
176
|
+
args.cache,
|
|
177
|
+
args.context,
|
|
178
|
+
args.commercetoolsApi,
|
|
179
|
+
args.factory
|
|
180
|
+
)
|
|
181
|
+
},
|
|
182
|
+
inventory: {
|
|
183
|
+
isEnabled: (caps) => caps.inventory?.enabled,
|
|
184
|
+
getOverride: (caps) => caps.inventory,
|
|
185
|
+
createDefaultFactory: () => new CommercetoolsInventoryFactory(InventorySchema),
|
|
186
|
+
createDefaultCapability: (args) => new CommercetoolsInventoryCapability(
|
|
187
|
+
args.config,
|
|
188
|
+
args.cache,
|
|
189
|
+
args.context,
|
|
190
|
+
args.commercetoolsApi,
|
|
191
|
+
args.factory
|
|
192
|
+
)
|
|
193
|
+
},
|
|
194
|
+
price: {
|
|
195
|
+
isEnabled: (caps) => caps.price?.enabled,
|
|
196
|
+
getOverride: (caps) => caps.price,
|
|
197
|
+
createDefaultFactory: () => new CommercetoolsPriceFactory(PriceSchema),
|
|
198
|
+
createDefaultCapability: (args) => new CommercetoolsPriceCapability(
|
|
199
|
+
args.config,
|
|
200
|
+
args.cache,
|
|
201
|
+
args.context,
|
|
202
|
+
args.commercetoolsApi,
|
|
203
|
+
args.factory
|
|
204
|
+
)
|
|
205
|
+
},
|
|
206
|
+
category: {
|
|
207
|
+
isEnabled: (caps) => caps.category?.enabled,
|
|
208
|
+
getOverride: (caps) => caps.category,
|
|
209
|
+
createDefaultFactory: () => new CommercetoolsCategoryFactory(CategorySchema, CategoryPaginatedResultSchema),
|
|
210
|
+
createDefaultCapability: (args) => new CommercetoolsCategoryCapability(
|
|
211
|
+
args.config,
|
|
212
|
+
args.cache,
|
|
213
|
+
args.context,
|
|
214
|
+
args.commercetoolsApi,
|
|
215
|
+
args.factory
|
|
216
|
+
)
|
|
217
|
+
},
|
|
218
|
+
checkout: {
|
|
219
|
+
isEnabled: (caps) => caps.checkout?.enabled,
|
|
220
|
+
getOverride: (caps) => caps.checkout,
|
|
221
|
+
createDefaultFactory: () => new CommercetoolsCheckoutFactory(
|
|
222
|
+
CheckoutSchema,
|
|
223
|
+
ShippingMethodSchema,
|
|
224
|
+
PaymentMethodSchema
|
|
225
|
+
),
|
|
226
|
+
createDefaultCapability: (args) => new CommercetoolsCheckoutCapability(
|
|
227
|
+
args.config,
|
|
228
|
+
args.cache,
|
|
229
|
+
args.context,
|
|
230
|
+
args.commercetoolsApi,
|
|
231
|
+
args.factory
|
|
232
|
+
)
|
|
233
|
+
},
|
|
234
|
+
store: {
|
|
235
|
+
isEnabled: (caps) => caps.store?.enabled,
|
|
236
|
+
getOverride: (caps) => caps.store,
|
|
237
|
+
createDefaultFactory: () => new CommercetoolsStoreFactory(StoreSchema),
|
|
238
|
+
createDefaultCapability: (args) => new CommercetoolsStoreCapability(
|
|
239
|
+
args.config,
|
|
240
|
+
args.cache,
|
|
241
|
+
args.context,
|
|
242
|
+
args.commercetoolsApi,
|
|
243
|
+
args.factory
|
|
244
|
+
)
|
|
245
|
+
},
|
|
246
|
+
order: {
|
|
247
|
+
isEnabled: (caps) => caps.order?.enabled,
|
|
248
|
+
getOverride: (caps) => caps.order,
|
|
249
|
+
createDefaultFactory: () => new CommercetoolsOrderFactory(OrderSchema),
|
|
250
|
+
createDefaultCapability: (args) => new CommercetoolsOrderCapability(
|
|
251
|
+
args.config,
|
|
252
|
+
args.cache,
|
|
253
|
+
args.context,
|
|
254
|
+
args.commercetoolsApi,
|
|
255
|
+
args.factory
|
|
256
|
+
)
|
|
257
|
+
},
|
|
258
|
+
orderSearch: {
|
|
259
|
+
isEnabled: (caps) => caps.orderSearch?.enabled,
|
|
260
|
+
getOverride: (caps) => caps.orderSearch,
|
|
261
|
+
createDefaultFactory: () => new CommercetoolsOrderSearchFactory(OrderSearchResultSchema),
|
|
262
|
+
createDefaultCapability: (args) => new CommercetoolsOrderSearchCapability(
|
|
263
|
+
args.config,
|
|
264
|
+
args.cache,
|
|
265
|
+
args.context,
|
|
266
|
+
args.commercetoolsApi,
|
|
267
|
+
args.factory
|
|
268
|
+
)
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
export {
|
|
272
|
+
capabilityDescriptors,
|
|
273
|
+
capabilityKeys
|
|
274
|
+
};
|