@reactionary/hcl 0.9.11 → 0.9.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/capabilities/analytics.capability.js +98 -0
- package/capabilities/order-search.capability.js +79 -0
- package/capabilities/order.capability.js +62 -0
- package/capabilities/personalization-profile.capability.js +85 -0
- package/capabilities/product-associations.capability.js +117 -0
- package/capabilities/product-recommendations.capability.js +143 -0
- package/capabilities/profile.capability.js +215 -0
- package/core/initialize.js +136 -2
- package/factories/index.js +6 -0
- package/factories/order/order.factory.js +124 -0
- package/factories/order-search/order-search.factory.js +59 -0
- package/factories/personalization-profile/personalization-profile.factory.js +16 -0
- package/factories/product-associations/product-associations.factory.js +16 -0
- package/factories/product-recommendations/product-recommendations.factory.js +17 -0
- package/factories/profile/profile.factory.js +49 -0
- package/index.js +7 -0
- package/package.json +2 -2
- package/schema/capabilities.schema.js +16 -2
- package/schema/configuration.schema.js +37 -1
- package/src/capabilities/analytics.capability.d.ts +17 -0
- package/src/capabilities/order-search.capability.d.ts +13 -0
- package/src/capabilities/order.capability.d.ts +13 -0
- package/src/capabilities/personalization-profile.capability.d.ts +19 -0
- package/src/capabilities/product-associations.capability.d.ts +22 -0
- package/src/capabilities/product-recommendations.capability.d.ts +29 -0
- package/src/capabilities/profile.capability.d.ts +31 -0
- package/src/core/initialize.types.d.ts +7 -1
- package/src/factories/index.d.ts +6 -0
- package/src/factories/order/order.factory.d.ts +11 -0
- package/src/factories/order-search/order-search.factory.d.ts +9 -0
- package/src/factories/personalization-profile/personalization-profile.factory.d.ts +11 -0
- package/src/factories/product-associations/product-associations.factory.d.ts +8 -0
- package/src/factories/product-recommendations/product-recommendations.factory.d.ts +12 -0
- package/src/factories/profile/profile.factory.d.ts +9 -0
- package/src/index.d.ts +7 -0
- package/src/schema/capabilities.schema.d.ts +45 -1
- package/src/schema/configuration.schema.d.ts +24 -0
- package/src/schema/hcl.schema.d.ts +122 -1
- package/src/test/test-utils.d.ts +4 -1
|
@@ -0,0 +1,215 @@
|
|
|
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
|
+
ProfileCapability,
|
|
14
|
+
ProfileMutationAddShippingAddressSchema,
|
|
15
|
+
ProfileMutationMakeShippingAddressDefaultSchema,
|
|
16
|
+
ProfileMutationRemoveShippingAddressSchema,
|
|
17
|
+
ProfileMutationSetBillingAddressSchema,
|
|
18
|
+
ProfileMutationUpdateSchema,
|
|
19
|
+
ProfileMutationUpdateShippingAddressSchema,
|
|
20
|
+
ProfileQueryByIdSchema,
|
|
21
|
+
ProfileSchema,
|
|
22
|
+
Reactionary,
|
|
23
|
+
error,
|
|
24
|
+
success
|
|
25
|
+
} from "@reactionary/core";
|
|
26
|
+
import createDebug from "debug";
|
|
27
|
+
const debug = createDebug("reactionary:hcl:profile");
|
|
28
|
+
const BILLING_NICK_NAME = "Billing";
|
|
29
|
+
class HclProfileCapability extends ProfileCapability {
|
|
30
|
+
config;
|
|
31
|
+
client;
|
|
32
|
+
factory;
|
|
33
|
+
constructor(cache, context, config, client, factory) {
|
|
34
|
+
super(cache, context);
|
|
35
|
+
this.config = config;
|
|
36
|
+
this.client = client;
|
|
37
|
+
this.factory = factory;
|
|
38
|
+
}
|
|
39
|
+
async fetchPerson() {
|
|
40
|
+
return this.client.callGet(this.personSelfUrl());
|
|
41
|
+
}
|
|
42
|
+
async fetchProfile() {
|
|
43
|
+
const person = await this.fetchPerson();
|
|
44
|
+
return this.factory.parseProfile(this.context, person);
|
|
45
|
+
}
|
|
46
|
+
toWcsContact(address) {
|
|
47
|
+
const lines = [address.streetAddress, address.streetNumber].filter(Boolean);
|
|
48
|
+
return {
|
|
49
|
+
nickName: address.identifier.nickName,
|
|
50
|
+
firstName: address.firstName,
|
|
51
|
+
lastName: address.lastName,
|
|
52
|
+
addressLine: lines.length ? lines : void 0,
|
|
53
|
+
city: address.city,
|
|
54
|
+
stateOrProvinceName: address.region,
|
|
55
|
+
zipCode: address.postalCode,
|
|
56
|
+
country: address.countryCode
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
personSelfUrl() {
|
|
60
|
+
return `${this.client.transactionBaseUrl}/person/@self`;
|
|
61
|
+
}
|
|
62
|
+
updatePersonPayload(email, phone) {
|
|
63
|
+
return { email1: email, phone1: phone };
|
|
64
|
+
}
|
|
65
|
+
personContactListUrl() {
|
|
66
|
+
return `${this.client.transactionBaseUrl}/person/@self/contact`;
|
|
67
|
+
}
|
|
68
|
+
contactUrl(nickName) {
|
|
69
|
+
return `${this.client.transactionBaseUrl}/person/@self/contact/${encodeURIComponent(nickName)}`;
|
|
70
|
+
}
|
|
71
|
+
makeShippingAddressDefaultPayload() {
|
|
72
|
+
return { primary: "1" };
|
|
73
|
+
}
|
|
74
|
+
async getById(_payload) {
|
|
75
|
+
debug("getById");
|
|
76
|
+
return success(await this.fetchProfile());
|
|
77
|
+
}
|
|
78
|
+
async update(payload) {
|
|
79
|
+
debug("update %o", payload.identifier);
|
|
80
|
+
await this.client.callPut(
|
|
81
|
+
this.personSelfUrl(),
|
|
82
|
+
this.updatePersonPayload(payload.email, payload.phone)
|
|
83
|
+
);
|
|
84
|
+
return success(await this.fetchProfile());
|
|
85
|
+
}
|
|
86
|
+
async addShippingAddress(payload) {
|
|
87
|
+
debug("addShippingAddress %s", payload.address.identifier.nickName);
|
|
88
|
+
await this.client.callPost(
|
|
89
|
+
this.personContactListUrl(),
|
|
90
|
+
this.toWcsContact(payload.address)
|
|
91
|
+
);
|
|
92
|
+
return success(await this.fetchProfile());
|
|
93
|
+
}
|
|
94
|
+
async updateShippingAddress(payload) {
|
|
95
|
+
debug("updateShippingAddress %s", payload.address.identifier.nickName);
|
|
96
|
+
try {
|
|
97
|
+
await this.client.callPut(
|
|
98
|
+
this.contactUrl(payload.address.identifier.nickName),
|
|
99
|
+
this.toWcsContact(payload.address)
|
|
100
|
+
);
|
|
101
|
+
} catch (err) {
|
|
102
|
+
if (err instanceof Error && err.message.includes("404")) {
|
|
103
|
+
return error({
|
|
104
|
+
type: "NotFound",
|
|
105
|
+
identifier: payload.address.identifier
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
throw err;
|
|
109
|
+
}
|
|
110
|
+
return success(await this.fetchProfile());
|
|
111
|
+
}
|
|
112
|
+
async removeShippingAddress(payload) {
|
|
113
|
+
debug("removeShippingAddress %s", payload.addressIdentifier.nickName);
|
|
114
|
+
try {
|
|
115
|
+
await this.client.callDelete(
|
|
116
|
+
this.contactUrl(payload.addressIdentifier.nickName)
|
|
117
|
+
);
|
|
118
|
+
} catch (err) {
|
|
119
|
+
if (err instanceof Error && err.message.includes("404")) {
|
|
120
|
+
return error({
|
|
121
|
+
type: "NotFound",
|
|
122
|
+
identifier: payload.addressIdentifier
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
throw err;
|
|
126
|
+
}
|
|
127
|
+
return success(await this.fetchProfile());
|
|
128
|
+
}
|
|
129
|
+
async makeShippingAddressDefault(payload) {
|
|
130
|
+
debug("makeShippingAddressDefault %s", payload.addressIdentifier.nickName);
|
|
131
|
+
try {
|
|
132
|
+
await this.client.callPut(
|
|
133
|
+
this.contactUrl(payload.addressIdentifier.nickName),
|
|
134
|
+
this.makeShippingAddressDefaultPayload()
|
|
135
|
+
);
|
|
136
|
+
} catch (err) {
|
|
137
|
+
if (err instanceof Error && err.message.includes("404")) {
|
|
138
|
+
return error({
|
|
139
|
+
type: "NotFound",
|
|
140
|
+
identifier: payload.addressIdentifier
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
throw err;
|
|
144
|
+
}
|
|
145
|
+
return success(await this.fetchProfile());
|
|
146
|
+
}
|
|
147
|
+
async setBillingAddress(payload) {
|
|
148
|
+
debug("setBillingAddress");
|
|
149
|
+
const person = await this.fetchPerson();
|
|
150
|
+
const billingContact = (person.contact ?? []).find(
|
|
151
|
+
(c) => c.nickName === BILLING_NICK_NAME
|
|
152
|
+
);
|
|
153
|
+
const contactData = {
|
|
154
|
+
...this.toWcsContact(payload.address),
|
|
155
|
+
nickName: BILLING_NICK_NAME
|
|
156
|
+
};
|
|
157
|
+
if (billingContact) {
|
|
158
|
+
await this.client.callPut(
|
|
159
|
+
this.contactUrl(BILLING_NICK_NAME),
|
|
160
|
+
contactData
|
|
161
|
+
);
|
|
162
|
+
} else {
|
|
163
|
+
await this.client.callPost(
|
|
164
|
+
this.personContactListUrl(),
|
|
165
|
+
contactData
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
return success(await this.fetchProfile());
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
__decorateClass([
|
|
172
|
+
Reactionary({
|
|
173
|
+
inputSchema: ProfileQueryByIdSchema,
|
|
174
|
+
outputSchema: ProfileSchema
|
|
175
|
+
})
|
|
176
|
+
], HclProfileCapability.prototype, "getById", 1);
|
|
177
|
+
__decorateClass([
|
|
178
|
+
Reactionary({
|
|
179
|
+
inputSchema: ProfileMutationUpdateSchema,
|
|
180
|
+
outputSchema: ProfileSchema
|
|
181
|
+
})
|
|
182
|
+
], HclProfileCapability.prototype, "update", 1);
|
|
183
|
+
__decorateClass([
|
|
184
|
+
Reactionary({
|
|
185
|
+
inputSchema: ProfileMutationAddShippingAddressSchema,
|
|
186
|
+
outputSchema: ProfileSchema
|
|
187
|
+
})
|
|
188
|
+
], HclProfileCapability.prototype, "addShippingAddress", 1);
|
|
189
|
+
__decorateClass([
|
|
190
|
+
Reactionary({
|
|
191
|
+
inputSchema: ProfileMutationUpdateShippingAddressSchema,
|
|
192
|
+
outputSchema: ProfileSchema
|
|
193
|
+
})
|
|
194
|
+
], HclProfileCapability.prototype, "updateShippingAddress", 1);
|
|
195
|
+
__decorateClass([
|
|
196
|
+
Reactionary({
|
|
197
|
+
inputSchema: ProfileMutationRemoveShippingAddressSchema,
|
|
198
|
+
outputSchema: ProfileSchema
|
|
199
|
+
})
|
|
200
|
+
], HclProfileCapability.prototype, "removeShippingAddress", 1);
|
|
201
|
+
__decorateClass([
|
|
202
|
+
Reactionary({
|
|
203
|
+
inputSchema: ProfileMutationMakeShippingAddressDefaultSchema,
|
|
204
|
+
outputSchema: ProfileSchema
|
|
205
|
+
})
|
|
206
|
+
], HclProfileCapability.prototype, "makeShippingAddressDefault", 1);
|
|
207
|
+
__decorateClass([
|
|
208
|
+
Reactionary({
|
|
209
|
+
inputSchema: ProfileMutationSetBillingAddressSchema,
|
|
210
|
+
outputSchema: ProfileSchema
|
|
211
|
+
})
|
|
212
|
+
], HclProfileCapability.prototype, "setBillingAddress", 1);
|
|
213
|
+
export {
|
|
214
|
+
HclProfileCapability
|
|
215
|
+
};
|
package/core/initialize.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CategoryPaginatedResultSchema,
|
|
3
3
|
IdentitySchema,
|
|
4
|
-
|
|
4
|
+
OrderSchema,
|
|
5
|
+
OrderSearchResultSchema,
|
|
6
|
+
PersonalizationProfileSchema,
|
|
7
|
+
ProductAssociationSchema,
|
|
8
|
+
ProductRecommendationSchema,
|
|
9
|
+
ProductSchema,
|
|
10
|
+
ProfileSchema
|
|
5
11
|
} from "@reactionary/core";
|
|
6
12
|
import { HclCategorySchema } from "../schema/category.schema.js";
|
|
7
13
|
import {
|
|
@@ -20,9 +26,15 @@ import {
|
|
|
20
26
|
HclCheckoutFactory,
|
|
21
27
|
HclIdentityFactory,
|
|
22
28
|
HclInventoryFactory,
|
|
29
|
+
HclOrderFactory,
|
|
30
|
+
HclOrderSearchFactory,
|
|
31
|
+
HclPersonalizationProfileFactory,
|
|
23
32
|
HclPriceFactory,
|
|
33
|
+
HclProductAssociationsFactory,
|
|
24
34
|
HclProductFactory,
|
|
25
|
-
|
|
35
|
+
HclProductRecommendationsFactory,
|
|
36
|
+
HclProductSearchFactory,
|
|
37
|
+
HclProfileFactory
|
|
26
38
|
} from "../factories/index.js";
|
|
27
39
|
import { HclCartCapability } from "../capabilities/cart.capability.js";
|
|
28
40
|
import { HclCheckoutCapability } from "../capabilities/checkout.capability.js";
|
|
@@ -32,6 +44,13 @@ import { HclProductSearchCapability } from "../capabilities/product-search.capab
|
|
|
32
44
|
import { HclPriceCapability } from "../capabilities/price.capability.js";
|
|
33
45
|
import { HclInventoryCapability } from "../capabilities/inventory.capability.js";
|
|
34
46
|
import { HclIdentityCapability } from "../capabilities/identity.capability.js";
|
|
47
|
+
import { HclProfileCapability } from "../capabilities/profile.capability.js";
|
|
48
|
+
import { HclOrderCapability } from "../capabilities/order.capability.js";
|
|
49
|
+
import { HclOrderSearchCapability } from "../capabilities/order-search.capability.js";
|
|
50
|
+
import { HclAnalyticsCapability } from "../capabilities/analytics.capability.js";
|
|
51
|
+
import { HclProductAssociationsCapability } from "../capabilities/product-associations.capability.js";
|
|
52
|
+
import { HclProductRecommendationsCapability } from "../capabilities/product-recommendations.capability.js";
|
|
53
|
+
import { HclPersonalizationProfileCapability } from "../capabilities/personalization-profile.capability.js";
|
|
35
54
|
import {
|
|
36
55
|
CartIdentifierSchema,
|
|
37
56
|
CartPaginatedSearchResultSchema,
|
|
@@ -195,6 +214,121 @@ function withHclCapabilities(configuration, capabilities) {
|
|
|
195
214
|
buildCapabilityArgs
|
|
196
215
|
);
|
|
197
216
|
}
|
|
217
|
+
if (caps.profile?.enabled) {
|
|
218
|
+
client.profile = resolveCapabilityWithFactory(
|
|
219
|
+
capabilities.profile,
|
|
220
|
+
{
|
|
221
|
+
factory: new HclProfileFactory(ProfileSchema),
|
|
222
|
+
capability: (args) => new HclProfileCapability(
|
|
223
|
+
args.cache,
|
|
224
|
+
args.context,
|
|
225
|
+
args.config,
|
|
226
|
+
args.hclClient,
|
|
227
|
+
args.factory
|
|
228
|
+
)
|
|
229
|
+
},
|
|
230
|
+
buildCapabilityArgs
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
if (caps.order?.enabled) {
|
|
234
|
+
client.order = resolveCapabilityWithFactory(
|
|
235
|
+
capabilities.order,
|
|
236
|
+
{
|
|
237
|
+
factory: new HclOrderFactory(OrderSchema),
|
|
238
|
+
capability: (args) => new HclOrderCapability(
|
|
239
|
+
args.cache,
|
|
240
|
+
args.context,
|
|
241
|
+
args.config,
|
|
242
|
+
args.hclClient,
|
|
243
|
+
args.factory
|
|
244
|
+
)
|
|
245
|
+
},
|
|
246
|
+
buildCapabilityArgs
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
if (caps.orderSearch?.enabled) {
|
|
250
|
+
client.orderSearch = resolveCapabilityWithFactory(
|
|
251
|
+
capabilities.orderSearch,
|
|
252
|
+
{
|
|
253
|
+
factory: new HclOrderSearchFactory(OrderSearchResultSchema),
|
|
254
|
+
capability: (args) => new HclOrderSearchCapability(
|
|
255
|
+
args.cache,
|
|
256
|
+
args.context,
|
|
257
|
+
args.config,
|
|
258
|
+
args.hclClient,
|
|
259
|
+
args.factory
|
|
260
|
+
)
|
|
261
|
+
},
|
|
262
|
+
buildCapabilityArgs
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
if (caps.analytics?.enabled) {
|
|
266
|
+
const analyticsCap = capabilities.analytics;
|
|
267
|
+
if (analyticsCap?.capability) {
|
|
268
|
+
client.analytics = analyticsCap.capability(
|
|
269
|
+
buildCapabilityArgs(void 0)
|
|
270
|
+
);
|
|
271
|
+
} else {
|
|
272
|
+
client.analytics = new HclAnalyticsCapability(
|
|
273
|
+
cache,
|
|
274
|
+
context,
|
|
275
|
+
config,
|
|
276
|
+
hclClient
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (caps.productAssociations?.enabled) {
|
|
281
|
+
client.productAssociations = resolveCapabilityWithFactory(
|
|
282
|
+
capabilities.productAssociations,
|
|
283
|
+
{
|
|
284
|
+
factory: new HclProductAssociationsFactory(ProductAssociationSchema),
|
|
285
|
+
capability: (args) => new HclProductAssociationsCapability(
|
|
286
|
+
args.cache,
|
|
287
|
+
args.context,
|
|
288
|
+
args.config,
|
|
289
|
+
args.hclClient,
|
|
290
|
+
args.factory
|
|
291
|
+
)
|
|
292
|
+
},
|
|
293
|
+
buildCapabilityArgs
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
if (caps.productRecommendations?.enabled) {
|
|
297
|
+
client.productRecommendations = resolveCapabilityWithFactory(
|
|
298
|
+
capabilities.productRecommendations,
|
|
299
|
+
{
|
|
300
|
+
factory: new HclProductRecommendationsFactory(
|
|
301
|
+
ProductRecommendationSchema
|
|
302
|
+
),
|
|
303
|
+
capability: (args) => new HclProductRecommendationsCapability(
|
|
304
|
+
args.cache,
|
|
305
|
+
args.context,
|
|
306
|
+
args.config,
|
|
307
|
+
args.hclClient,
|
|
308
|
+
args.factory
|
|
309
|
+
)
|
|
310
|
+
},
|
|
311
|
+
buildCapabilityArgs
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
if (caps.personalizationProfile?.enabled) {
|
|
315
|
+
client.personalizationProfile = resolveCapabilityWithFactory(
|
|
316
|
+
capabilities.personalizationProfile,
|
|
317
|
+
{
|
|
318
|
+
factory: new HclPersonalizationProfileFactory(
|
|
319
|
+
PersonalizationProfileSchema
|
|
320
|
+
),
|
|
321
|
+
capability: (args) => new HclPersonalizationProfileCapability(
|
|
322
|
+
args.cache,
|
|
323
|
+
args.context,
|
|
324
|
+
args.config,
|
|
325
|
+
args.hclClient,
|
|
326
|
+
args.factory
|
|
327
|
+
)
|
|
328
|
+
},
|
|
329
|
+
buildCapabilityArgs
|
|
330
|
+
);
|
|
331
|
+
}
|
|
198
332
|
return client;
|
|
199
333
|
};
|
|
200
334
|
}
|
package/factories/index.js
CHANGED
|
@@ -6,3 +6,9 @@ export * from "./product-search/product-search.factory.js";
|
|
|
6
6
|
export * from "./price/price.factory.js";
|
|
7
7
|
export * from "./inventory/inventory.factory.js";
|
|
8
8
|
export * from "./identity/identity.factory.js";
|
|
9
|
+
export * from "./profile/profile.factory.js";
|
|
10
|
+
export * from "./order/order.factory.js";
|
|
11
|
+
export * from "./order-search/order-search.factory.js";
|
|
12
|
+
export * from "./product-associations/product-associations.factory.js";
|
|
13
|
+
export * from "./product-recommendations/product-recommendations.factory.js";
|
|
14
|
+
export * from "./personalization-profile/personalization-profile.factory.js";
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
function mapWcsOrderStatus(status) {
|
|
2
|
+
switch (status) {
|
|
3
|
+
case "S":
|
|
4
|
+
return "Shipped";
|
|
5
|
+
case "X":
|
|
6
|
+
case "R":
|
|
7
|
+
case "D":
|
|
8
|
+
return "Cancelled";
|
|
9
|
+
case "M":
|
|
10
|
+
case "G":
|
|
11
|
+
case "F":
|
|
12
|
+
return "ReleasedToFulfillment";
|
|
13
|
+
default:
|
|
14
|
+
return "AwaitingPayment";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
class HclOrderFactory {
|
|
18
|
+
orderSchema;
|
|
19
|
+
constructor(orderSchema) {
|
|
20
|
+
this.orderSchema = orderSchema;
|
|
21
|
+
}
|
|
22
|
+
parseOrder(context, data) {
|
|
23
|
+
const currency = data.grandTotalCurrency ?? data.totalProductPriceCurrency ?? "USD";
|
|
24
|
+
const orderStatus = mapWcsOrderStatus(data.orderStatus ?? "");
|
|
25
|
+
const inventoryStatus = orderStatus === "Shipped" ? "Allocated" : "NotAllocated";
|
|
26
|
+
const userId = { userId: data.buyerId ?? "" };
|
|
27
|
+
const result = {
|
|
28
|
+
identifier: { key: data.orderId },
|
|
29
|
+
userId,
|
|
30
|
+
items: (data.orderItem ?? []).map(
|
|
31
|
+
(item) => this.parseOrderItem(context, item, currency)
|
|
32
|
+
),
|
|
33
|
+
price: this.parseCostBreakdown(context, data, currency),
|
|
34
|
+
orderStatus,
|
|
35
|
+
inventoryStatus,
|
|
36
|
+
paymentInstructions: (data.paymentInstruction ?? []).map(
|
|
37
|
+
(pi) => this.parsePaymentInstruction(context, pi, currency)
|
|
38
|
+
),
|
|
39
|
+
shippingAddress: data.x_shippingAddress ? {
|
|
40
|
+
identifier: {
|
|
41
|
+
nickName: data.x_shippingAddress.nickName ?? ""
|
|
42
|
+
},
|
|
43
|
+
firstName: data.x_shippingAddress.firstName ?? "",
|
|
44
|
+
lastName: data.x_shippingAddress.lastName ?? "",
|
|
45
|
+
streetAddress: data.x_shippingAddress.addressLine?.[0] ?? data.x_shippingAddress.address1 ?? "",
|
|
46
|
+
streetNumber: data.x_shippingAddress.addressLine?.[1] ?? "",
|
|
47
|
+
city: data.x_shippingAddress.city ?? "",
|
|
48
|
+
region: data.x_shippingAddress.state ?? "",
|
|
49
|
+
postalCode: data.x_shippingAddress.zipCode ?? "",
|
|
50
|
+
countryCode: data.x_shippingAddress.country ?? ""
|
|
51
|
+
} : void 0,
|
|
52
|
+
billingAddress: data.x_billingAddress ? {
|
|
53
|
+
identifier: {
|
|
54
|
+
nickName: data.x_billingAddress.nickName ?? ""
|
|
55
|
+
},
|
|
56
|
+
firstName: data.x_billingAddress.firstName ?? "",
|
|
57
|
+
lastName: data.x_billingAddress.lastName ?? "",
|
|
58
|
+
streetAddress: data.x_billingAddress.addressLine?.[0] ?? data.x_billingAddress.address1 ?? "",
|
|
59
|
+
streetNumber: data.x_billingAddress.addressLine?.[1] ?? "",
|
|
60
|
+
city: data.x_billingAddress.city ?? "",
|
|
61
|
+
region: data.x_billingAddress.state ?? "",
|
|
62
|
+
postalCode: data.x_billingAddress.zipCode ?? "",
|
|
63
|
+
countryCode: data.x_billingAddress.country ?? ""
|
|
64
|
+
} : void 0
|
|
65
|
+
};
|
|
66
|
+
return this.orderSchema.parse(result);
|
|
67
|
+
}
|
|
68
|
+
parseOrderItem(_context, item, defaultCurrency) {
|
|
69
|
+
const currency = item.currency ?? defaultCurrency;
|
|
70
|
+
const price = {
|
|
71
|
+
unitPrice: { value: Number(item.unitPrice), currency },
|
|
72
|
+
totalPrice: { value: Number(item.orderItemPrice), currency },
|
|
73
|
+
unitDiscount: { value: 0, currency },
|
|
74
|
+
totalDiscount: { value: 0, currency }
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
identifier: { key: item.orderItemId },
|
|
78
|
+
variant: { sku: item.partNumber },
|
|
79
|
+
quantity: Number(item.quantity),
|
|
80
|
+
price,
|
|
81
|
+
inventoryStatus: "Allocated"
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
parseCostBreakdown(_context, data, currency) {
|
|
85
|
+
return {
|
|
86
|
+
grandTotal: { value: Number(data.grandTotal ?? "0"), currency },
|
|
87
|
+
totalProductPrice: {
|
|
88
|
+
value: Number(data.totalProductPrice ?? "0"),
|
|
89
|
+
currency
|
|
90
|
+
},
|
|
91
|
+
totalShipping: {
|
|
92
|
+
value: Number(data.totalShippingCharge ?? "0"),
|
|
93
|
+
currency
|
|
94
|
+
},
|
|
95
|
+
totalTax: { value: Number(data.totalSalesTax ?? "0"), currency },
|
|
96
|
+
totalDiscount: {
|
|
97
|
+
value: Math.abs(Number(data.totalAdjustment ?? "0")),
|
|
98
|
+
currency
|
|
99
|
+
},
|
|
100
|
+
totalSurcharge: { value: 0, currency }
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
parsePaymentInstruction(_context, pi, defaultCurrency) {
|
|
104
|
+
const currency = pi.currency ?? defaultCurrency;
|
|
105
|
+
const paymentMethod = {
|
|
106
|
+
method: pi.payMethodId,
|
|
107
|
+
name: pi.piDescription ?? pi.payMethodId,
|
|
108
|
+
paymentProcessor: pi.payMethodId
|
|
109
|
+
};
|
|
110
|
+
return {
|
|
111
|
+
identifier: { key: pi.piId },
|
|
112
|
+
amount: { value: Number(pi.piAmount ?? "0"), currency },
|
|
113
|
+
paymentMethod,
|
|
114
|
+
protocolData: (pi.protocolData ?? []).map((pd) => ({
|
|
115
|
+
key: pd.name,
|
|
116
|
+
value: pd.value
|
|
117
|
+
})),
|
|
118
|
+
status: "pending"
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
export {
|
|
123
|
+
HclOrderFactory
|
|
124
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
function mapWcsOrderStatus(status) {
|
|
2
|
+
switch (status) {
|
|
3
|
+
case "S":
|
|
4
|
+
return "Shipped";
|
|
5
|
+
case "X":
|
|
6
|
+
case "R":
|
|
7
|
+
case "D":
|
|
8
|
+
return "Cancelled";
|
|
9
|
+
case "M":
|
|
10
|
+
case "G":
|
|
11
|
+
case "F":
|
|
12
|
+
return "ReleasedToFulfillment";
|
|
13
|
+
default:
|
|
14
|
+
return "AwaitingPayment";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
class HclOrderSearchFactory {
|
|
18
|
+
orderSearchResultSchema;
|
|
19
|
+
constructor(orderSearchResultSchema) {
|
|
20
|
+
this.orderSearchResultSchema = orderSearchResultSchema;
|
|
21
|
+
}
|
|
22
|
+
parseOrderSearchResult(context, data, query) {
|
|
23
|
+
const items = (data.Order ?? []).map(
|
|
24
|
+
(o) => this.parseOrderSearchResultItem(context, o)
|
|
25
|
+
);
|
|
26
|
+
const totalCount = Number(data.recordSetTotal ?? items.length);
|
|
27
|
+
const { pageSize, pageNumber } = query.search.paginationOptions;
|
|
28
|
+
const result = {
|
|
29
|
+
identifier: { ...query.search },
|
|
30
|
+
items,
|
|
31
|
+
totalCount,
|
|
32
|
+
pageSize,
|
|
33
|
+
pageNumber,
|
|
34
|
+
totalPages: Math.ceil(totalCount / Math.max(1, pageSize))
|
|
35
|
+
};
|
|
36
|
+
return this.orderSearchResultSchema.parse(result);
|
|
37
|
+
}
|
|
38
|
+
parseOrderSearchResultItem(_context, item) {
|
|
39
|
+
const orderStatus = mapWcsOrderStatus(item.orderStatus ?? "");
|
|
40
|
+
const inventoryStatus = orderStatus === "Shipped" ? "Allocated" : "NotAllocated";
|
|
41
|
+
const userId = { userId: item.buyerId ?? "" };
|
|
42
|
+
const totalAmount = {
|
|
43
|
+
value: Number(item.grandTotal ?? "0"),
|
|
44
|
+
currency: item.grandTotalCurrency ?? "USD"
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
identifier: { key: item.orderId },
|
|
48
|
+
userId,
|
|
49
|
+
customerName: "",
|
|
50
|
+
orderDate: item.lastUpdateDate ?? "",
|
|
51
|
+
orderStatus,
|
|
52
|
+
inventoryStatus,
|
|
53
|
+
totalAmount
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
HclOrderSearchFactory
|
|
59
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class HclPersonalizationProfileFactory {
|
|
2
|
+
personalizationProfileSchema;
|
|
3
|
+
constructor(personalizationProfileSchema) {
|
|
4
|
+
this.personalizationProfileSchema = personalizationProfileSchema;
|
|
5
|
+
}
|
|
6
|
+
parsePersonalizationProfile(_context, data) {
|
|
7
|
+
return this.personalizationProfileSchema.parse({
|
|
8
|
+
identifier: { key: data.personalizationId },
|
|
9
|
+
segments: data.segments,
|
|
10
|
+
blurb: ""
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
HclPersonalizationProfileFactory
|
|
16
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class HclProductAssociationsFactory {
|
|
2
|
+
productAssociationSchema;
|
|
3
|
+
constructor(productAssociationSchema) {
|
|
4
|
+
this.productAssociationSchema = productAssociationSchema;
|
|
5
|
+
}
|
|
6
|
+
parseAssociation(_context, data) {
|
|
7
|
+
return this.productAssociationSchema.parse({
|
|
8
|
+
associationIdentifier: { key: data.partNumber },
|
|
9
|
+
associationReturnType: "idOnly",
|
|
10
|
+
product: { key: data.partNumber }
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
HclProductAssociationsFactory
|
|
16
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class HclProductRecommendationsFactory {
|
|
2
|
+
productRecommendationSchema;
|
|
3
|
+
constructor(productRecommendationSchema) {
|
|
4
|
+
this.productRecommendationSchema = productRecommendationSchema;
|
|
5
|
+
}
|
|
6
|
+
parseRecommendation(_context, data) {
|
|
7
|
+
const key = data.activityData.partNumber ?? data.activityData.contentId ?? "";
|
|
8
|
+
return this.productRecommendationSchema.parse({
|
|
9
|
+
recommendationIdentifier: { key, algorithm: data.algorithm },
|
|
10
|
+
recommendationReturnType: "idOnly",
|
|
11
|
+
product: { key }
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
HclProductRecommendationsFactory
|
|
17
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const BILLING_NICK_NAME = "Billing";
|
|
2
|
+
class HclProfileFactory {
|
|
3
|
+
profileSchema;
|
|
4
|
+
constructor(profileSchema) {
|
|
5
|
+
this.profileSchema = profileSchema;
|
|
6
|
+
}
|
|
7
|
+
parseProfile(context, data) {
|
|
8
|
+
const contacts = data.contact ?? [];
|
|
9
|
+
const billingContact = contacts.find(
|
|
10
|
+
(c) => c.nickName === BILLING_NICK_NAME
|
|
11
|
+
);
|
|
12
|
+
const shippingContacts = contacts.filter(
|
|
13
|
+
(c) => c.nickName !== BILLING_NICK_NAME
|
|
14
|
+
);
|
|
15
|
+
const defaultShipping = shippingContacts.find((c) => c.primary === "1") ?? shippingContacts[0];
|
|
16
|
+
const alternates = shippingContacts.filter((c) => c !== defaultShipping);
|
|
17
|
+
const result = {
|
|
18
|
+
identifier: { userId: data.userId },
|
|
19
|
+
email: data.email1 ?? data.logonId ?? "",
|
|
20
|
+
phone: data.phone1 ?? "",
|
|
21
|
+
emailVerified: false,
|
|
22
|
+
phoneVerified: false,
|
|
23
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
24
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
25
|
+
billingAddress: billingContact ? this.parseAddress(context, billingContact) : void 0,
|
|
26
|
+
shippingAddress: defaultShipping ? this.parseAddress(context, defaultShipping) : void 0,
|
|
27
|
+
alternateShippingAddresses: alternates.map(
|
|
28
|
+
(c) => this.parseAddress(context, c)
|
|
29
|
+
)
|
|
30
|
+
};
|
|
31
|
+
return this.profileSchema.parse(result);
|
|
32
|
+
}
|
|
33
|
+
parseAddress(_context, contact) {
|
|
34
|
+
return {
|
|
35
|
+
identifier: { nickName: contact.nickName },
|
|
36
|
+
firstName: contact.firstName ?? "",
|
|
37
|
+
lastName: contact.lastName ?? "",
|
|
38
|
+
streetAddress: contact.addressLine?.[0] ?? contact.address1 ?? "",
|
|
39
|
+
streetNumber: contact.addressLine?.[1] ?? "",
|
|
40
|
+
city: contact.city ?? "",
|
|
41
|
+
region: contact.stateOrProvinceName ?? "",
|
|
42
|
+
postalCode: contact.zipCode ?? "",
|
|
43
|
+
countryCode: contact.country ?? ""
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
HclProfileFactory
|
|
49
|
+
};
|
package/index.js
CHANGED
|
@@ -14,3 +14,10 @@ export * from "./capabilities/product-search.capability.js";
|
|
|
14
14
|
export * from "./capabilities/price.capability.js";
|
|
15
15
|
export * from "./capabilities/inventory.capability.js";
|
|
16
16
|
export * from "./capabilities/identity.capability.js";
|
|
17
|
+
export * from "./capabilities/profile.capability.js";
|
|
18
|
+
export * from "./capabilities/order.capability.js";
|
|
19
|
+
export * from "./capabilities/order-search.capability.js";
|
|
20
|
+
export * from "./capabilities/analytics.capability.js";
|
|
21
|
+
export * from "./capabilities/product-associations.capability.js";
|
|
22
|
+
export * from "./capabilities/product-recommendations.capability.js";
|
|
23
|
+
export * from "./capabilities/personalization-profile.capability.js";
|