@reactionary/hcl 0.9.11 → 0.9.12
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/order-search.capability.js +79 -0
- package/capabilities/order.capability.js +62 -0
- package/capabilities/profile.capability.js +215 -0
- package/core/initialize.js +59 -2
- package/factories/index.js +3 -0
- package/factories/order/order.factory.js +124 -0
- package/factories/order-search/order-search.factory.js +59 -0
- package/factories/profile/profile.factory.js +49 -0
- package/index.js +3 -0
- package/package.json +2 -2
- package/schema/capabilities.schema.js +8 -2
- package/src/capabilities/order-search.capability.d.ts +13 -0
- package/src/capabilities/order.capability.d.ts +13 -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 +3 -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/profile/profile.factory.d.ts +9 -0
- package/src/index.d.ts +3 -0
- package/src/schema/capabilities.schema.d.ts +19 -1
- package/src/schema/hcl.schema.d.ts +63 -0
- package/src/test/test-utils.d.ts +4 -1
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
OrderSearchCapability,
|
|
14
|
+
OrderSearchQueryByTermSchema,
|
|
15
|
+
OrderSearchResultSchema,
|
|
16
|
+
Reactionary,
|
|
17
|
+
success
|
|
18
|
+
} from "@reactionary/core";
|
|
19
|
+
import createDebug from "debug";
|
|
20
|
+
const debug = createDebug("reactionary:hcl:order-search");
|
|
21
|
+
const ALL_HISTORY_STATUSES = "C,S,X,R,D,M,G,F";
|
|
22
|
+
function coreStatusToWcs(status) {
|
|
23
|
+
switch (status) {
|
|
24
|
+
case "Shipped":
|
|
25
|
+
return "S";
|
|
26
|
+
case "Cancelled":
|
|
27
|
+
return "X,R,D";
|
|
28
|
+
case "ReleasedToFulfillment":
|
|
29
|
+
return "M,G,F";
|
|
30
|
+
case "AwaitingPayment":
|
|
31
|
+
return "C";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
class HclOrderSearchCapability extends OrderSearchCapability {
|
|
35
|
+
config;
|
|
36
|
+
client;
|
|
37
|
+
factory;
|
|
38
|
+
constructor(cache, context, config, client, factory) {
|
|
39
|
+
super(cache, context);
|
|
40
|
+
this.config = config;
|
|
41
|
+
this.client = client;
|
|
42
|
+
this.factory = factory;
|
|
43
|
+
}
|
|
44
|
+
async queryByTerm(payload) {
|
|
45
|
+
const { pageSize, pageNumber } = payload.search.paginationOptions;
|
|
46
|
+
const wcsStatuses = payload.search.orderStatus?.length ? payload.search.orderStatus.map(coreStatusToWcs).join(",") : ALL_HISTORY_STATUSES;
|
|
47
|
+
debug(
|
|
48
|
+
"queryByTerm statuses=%s page=%d/%d",
|
|
49
|
+
wcsStatuses,
|
|
50
|
+
pageNumber,
|
|
51
|
+
pageSize
|
|
52
|
+
);
|
|
53
|
+
const data = await this.client.callGet(
|
|
54
|
+
this.orderByStatusUrl(wcsStatuses),
|
|
55
|
+
this.orderByStatusParams(pageSize, (pageNumber - 1) * pageSize)
|
|
56
|
+
);
|
|
57
|
+
return success(
|
|
58
|
+
this.factory.parseOrderSearchResult(this.context, data, payload)
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
orderByStatusUrl(statuses) {
|
|
62
|
+
return `${this.client.transactionBaseUrl}/order/byStatus/${encodeURIComponent(statuses)}`;
|
|
63
|
+
}
|
|
64
|
+
orderByStatusParams(maxResults, startIndex) {
|
|
65
|
+
return new URLSearchParams({
|
|
66
|
+
maxResults: String(maxResults),
|
|
67
|
+
startIndex: String(startIndex)
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
__decorateClass([
|
|
72
|
+
Reactionary({
|
|
73
|
+
inputSchema: OrderSearchQueryByTermSchema,
|
|
74
|
+
outputSchema: OrderSearchResultSchema
|
|
75
|
+
})
|
|
76
|
+
], HclOrderSearchCapability.prototype, "queryByTerm", 1);
|
|
77
|
+
export {
|
|
78
|
+
HclOrderSearchCapability
|
|
79
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
OrderCapability,
|
|
14
|
+
OrderQueryByIdSchema,
|
|
15
|
+
OrderSchema,
|
|
16
|
+
Reactionary,
|
|
17
|
+
error,
|
|
18
|
+
success
|
|
19
|
+
} from "@reactionary/core";
|
|
20
|
+
import createDebug from "debug";
|
|
21
|
+
const debug = createDebug("reactionary:hcl:order");
|
|
22
|
+
class HclOrderCapability extends OrderCapability {
|
|
23
|
+
config;
|
|
24
|
+
client;
|
|
25
|
+
factory;
|
|
26
|
+
constructor(cache, context, config, client, factory) {
|
|
27
|
+
super(cache, context);
|
|
28
|
+
this.config = config;
|
|
29
|
+
this.client = client;
|
|
30
|
+
this.factory = factory;
|
|
31
|
+
}
|
|
32
|
+
async getById(payload) {
|
|
33
|
+
debug("getById %s", payload.order.key);
|
|
34
|
+
const data = await this.client.callGet(
|
|
35
|
+
this.orderUrl(payload.order.key),
|
|
36
|
+
this.orderParams(),
|
|
37
|
+
{ allowUndefined: true }
|
|
38
|
+
);
|
|
39
|
+
if (!data) {
|
|
40
|
+
return error({
|
|
41
|
+
type: "NotFound",
|
|
42
|
+
identifier: payload.order
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return success(this.factory.parseOrder(this.context, data));
|
|
46
|
+
}
|
|
47
|
+
orderUrl(orderId) {
|
|
48
|
+
return `${this.client.transactionBaseUrl}/order/${encodeURIComponent(orderId)}`;
|
|
49
|
+
}
|
|
50
|
+
orderParams() {
|
|
51
|
+
return new URLSearchParams({ profileName: "IBM_getOrderDetailsByOrderId" });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
__decorateClass([
|
|
55
|
+
Reactionary({
|
|
56
|
+
inputSchema: OrderQueryByIdSchema,
|
|
57
|
+
outputSchema: OrderSchema
|
|
58
|
+
})
|
|
59
|
+
], HclOrderCapability.prototype, "getById", 1);
|
|
60
|
+
export {
|
|
61
|
+
HclOrderCapability
|
|
62
|
+
};
|
|
@@ -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,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CategoryPaginatedResultSchema,
|
|
3
3
|
IdentitySchema,
|
|
4
|
-
|
|
4
|
+
OrderSchema,
|
|
5
|
+
OrderSearchResultSchema,
|
|
6
|
+
ProductSchema,
|
|
7
|
+
ProfileSchema
|
|
5
8
|
} from "@reactionary/core";
|
|
6
9
|
import { HclCategorySchema } from "../schema/category.schema.js";
|
|
7
10
|
import {
|
|
@@ -20,9 +23,12 @@ import {
|
|
|
20
23
|
HclCheckoutFactory,
|
|
21
24
|
HclIdentityFactory,
|
|
22
25
|
HclInventoryFactory,
|
|
26
|
+
HclOrderFactory,
|
|
27
|
+
HclOrderSearchFactory,
|
|
23
28
|
HclPriceFactory,
|
|
24
29
|
HclProductFactory,
|
|
25
|
-
HclProductSearchFactory
|
|
30
|
+
HclProductSearchFactory,
|
|
31
|
+
HclProfileFactory
|
|
26
32
|
} from "../factories/index.js";
|
|
27
33
|
import { HclCartCapability } from "../capabilities/cart.capability.js";
|
|
28
34
|
import { HclCheckoutCapability } from "../capabilities/checkout.capability.js";
|
|
@@ -32,6 +38,9 @@ import { HclProductSearchCapability } from "../capabilities/product-search.capab
|
|
|
32
38
|
import { HclPriceCapability } from "../capabilities/price.capability.js";
|
|
33
39
|
import { HclInventoryCapability } from "../capabilities/inventory.capability.js";
|
|
34
40
|
import { HclIdentityCapability } from "../capabilities/identity.capability.js";
|
|
41
|
+
import { HclProfileCapability } from "../capabilities/profile.capability.js";
|
|
42
|
+
import { HclOrderCapability } from "../capabilities/order.capability.js";
|
|
43
|
+
import { HclOrderSearchCapability } from "../capabilities/order-search.capability.js";
|
|
35
44
|
import {
|
|
36
45
|
CartIdentifierSchema,
|
|
37
46
|
CartPaginatedSearchResultSchema,
|
|
@@ -195,6 +204,54 @@ function withHclCapabilities(configuration, capabilities) {
|
|
|
195
204
|
buildCapabilityArgs
|
|
196
205
|
);
|
|
197
206
|
}
|
|
207
|
+
if (caps.profile?.enabled) {
|
|
208
|
+
client.profile = resolveCapabilityWithFactory(
|
|
209
|
+
capabilities.profile,
|
|
210
|
+
{
|
|
211
|
+
factory: new HclProfileFactory(ProfileSchema),
|
|
212
|
+
capability: (args) => new HclProfileCapability(
|
|
213
|
+
args.cache,
|
|
214
|
+
args.context,
|
|
215
|
+
args.config,
|
|
216
|
+
args.hclClient,
|
|
217
|
+
args.factory
|
|
218
|
+
)
|
|
219
|
+
},
|
|
220
|
+
buildCapabilityArgs
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
if (caps.order?.enabled) {
|
|
224
|
+
client.order = resolveCapabilityWithFactory(
|
|
225
|
+
capabilities.order,
|
|
226
|
+
{
|
|
227
|
+
factory: new HclOrderFactory(OrderSchema),
|
|
228
|
+
capability: (args) => new HclOrderCapability(
|
|
229
|
+
args.cache,
|
|
230
|
+
args.context,
|
|
231
|
+
args.config,
|
|
232
|
+
args.hclClient,
|
|
233
|
+
args.factory
|
|
234
|
+
)
|
|
235
|
+
},
|
|
236
|
+
buildCapabilityArgs
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
if (caps.orderSearch?.enabled) {
|
|
240
|
+
client.orderSearch = resolveCapabilityWithFactory(
|
|
241
|
+
capabilities.orderSearch,
|
|
242
|
+
{
|
|
243
|
+
factory: new HclOrderSearchFactory(OrderSearchResultSchema),
|
|
244
|
+
capability: (args) => new HclOrderSearchCapability(
|
|
245
|
+
args.cache,
|
|
246
|
+
args.context,
|
|
247
|
+
args.config,
|
|
248
|
+
args.hclClient,
|
|
249
|
+
args.factory
|
|
250
|
+
)
|
|
251
|
+
},
|
|
252
|
+
buildCapabilityArgs
|
|
253
|
+
);
|
|
254
|
+
}
|
|
198
255
|
return client;
|
|
199
256
|
};
|
|
200
257
|
}
|
package/factories/index.js
CHANGED
|
@@ -6,3 +6,6 @@ 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";
|
|
@@ -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,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,6 @@ 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";
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/hcl",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@reactionary/core": "0.9.
|
|
8
|
+
"@reactionary/core": "0.9.12",
|
|
9
9
|
"debug": "^4.4.3",
|
|
10
10
|
"zod": "4.1.9"
|
|
11
11
|
},
|
|
@@ -13,7 +13,10 @@ const HclCapabilitiesSchema = CapabilitiesSchema.pick({
|
|
|
13
13
|
price: true,
|
|
14
14
|
inventory: true,
|
|
15
15
|
identity: true,
|
|
16
|
-
productSearch: true
|
|
16
|
+
productSearch: true,
|
|
17
|
+
profile: true,
|
|
18
|
+
order: true,
|
|
19
|
+
orderSearch: true
|
|
17
20
|
}).extend({
|
|
18
21
|
cart: OverridableCapabilitySchema.optional(),
|
|
19
22
|
checkout: OverridableCapabilitySchema.optional(),
|
|
@@ -22,7 +25,10 @@ const HclCapabilitiesSchema = CapabilitiesSchema.pick({
|
|
|
22
25
|
price: OverridableCapabilitySchema.optional(),
|
|
23
26
|
inventory: OverridableCapabilitySchema.optional(),
|
|
24
27
|
identity: OverridableCapabilitySchema.optional(),
|
|
25
|
-
productSearch: OverridableCapabilitySchema.optional()
|
|
28
|
+
productSearch: OverridableCapabilitySchema.optional(),
|
|
29
|
+
profile: OverridableCapabilitySchema.optional(),
|
|
30
|
+
order: OverridableCapabilitySchema.optional(),
|
|
31
|
+
orderSearch: OverridableCapabilitySchema.optional()
|
|
26
32
|
}).partial();
|
|
27
33
|
export {
|
|
28
34
|
HclCapabilitiesSchema
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Cache, OrderSearchCapability, type OrderSearchFactory, type OrderSearchFactoryOutput, type OrderSearchFactoryWithOutput, type OrderSearchQueryByTerm, type RequestContext, type Result } from '@reactionary/core';
|
|
2
|
+
import type { HclConfiguration } from '../schema/configuration.schema.js';
|
|
3
|
+
import type { HclClient } from '../core/client.js';
|
|
4
|
+
import type { HclOrderSearchFactory } from '../factories/order-search/order-search.factory.js';
|
|
5
|
+
export declare class HclOrderSearchCapability<TFactory extends OrderSearchFactory = HclOrderSearchFactory> extends OrderSearchCapability<OrderSearchFactoryOutput<TFactory>> {
|
|
6
|
+
protected config: HclConfiguration;
|
|
7
|
+
protected client: HclClient;
|
|
8
|
+
protected factory: OrderSearchFactoryWithOutput<TFactory>;
|
|
9
|
+
constructor(cache: Cache, context: RequestContext, config: HclConfiguration, client: HclClient, factory: OrderSearchFactoryWithOutput<TFactory>);
|
|
10
|
+
queryByTerm(payload: OrderSearchQueryByTerm): Promise<Result<OrderSearchFactoryOutput<TFactory>>>;
|
|
11
|
+
protected orderByStatusUrl(statuses: string): string;
|
|
12
|
+
protected orderByStatusParams(maxResults: number, startIndex: number): URLSearchParams;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Cache, type NotFoundError, OrderCapability, type OrderFactory, type OrderFactoryOutput, type OrderFactoryWithOutput, type OrderQueryById, type RequestContext, type Result } from '@reactionary/core';
|
|
2
|
+
import type { HclConfiguration } from '../schema/configuration.schema.js';
|
|
3
|
+
import type { HclClient } from '../core/client.js';
|
|
4
|
+
import type { HclOrderFactory } from '../factories/order/order.factory.js';
|
|
5
|
+
export declare class HclOrderCapability<TFactory extends OrderFactory = HclOrderFactory> extends OrderCapability<OrderFactoryOutput<TFactory>> {
|
|
6
|
+
protected config: HclConfiguration;
|
|
7
|
+
protected client: HclClient;
|
|
8
|
+
protected factory: OrderFactoryWithOutput<TFactory>;
|
|
9
|
+
constructor(cache: Cache, context: RequestContext, config: HclConfiguration, client: HclClient, factory: OrderFactoryWithOutput<TFactory>);
|
|
10
|
+
getById(payload: OrderQueryById): Promise<Result<OrderFactoryOutput<TFactory>, NotFoundError>>;
|
|
11
|
+
protected orderUrl(orderId: string): string;
|
|
12
|
+
protected orderParams(): URLSearchParams;
|
|
13
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Address, type Cache, type NotFoundError, ProfileCapability, type ProfileFactory, type ProfileFactoryOutput, type ProfileFactoryWithOutput, type ProfileMutationAddShippingAddress, type ProfileMutationMakeShippingAddressDefault, type ProfileMutationRemoveShippingAddress, type ProfileMutationSetBillingAddress, type ProfileMutationUpdate, type ProfileMutationUpdateShippingAddress, type ProfileQuerySelf, type RequestContext, type Result } from '@reactionary/core';
|
|
2
|
+
import type { HclConfiguration } from '../schema/configuration.schema.js';
|
|
3
|
+
import type { HclClient } from '../core/client.js';
|
|
4
|
+
import type { HclProfileFactory } from '../factories/profile/profile.factory.js';
|
|
5
|
+
import type { HclPersonResponse, HclWcsPersonContact } from '../schema/hcl.schema.js';
|
|
6
|
+
export declare class HclProfileCapability<TFactory extends ProfileFactory = HclProfileFactory> extends ProfileCapability<ProfileFactoryOutput<TFactory>> {
|
|
7
|
+
protected config: HclConfiguration;
|
|
8
|
+
protected client: HclClient;
|
|
9
|
+
protected factory: ProfileFactoryWithOutput<TFactory>;
|
|
10
|
+
constructor(cache: Cache, context: RequestContext, config: HclConfiguration, client: HclClient, factory: ProfileFactoryWithOutput<TFactory>);
|
|
11
|
+
protected fetchPerson(): Promise<HclPersonResponse>;
|
|
12
|
+
protected fetchProfile(): Promise<ProfileFactoryOutput<TFactory>>;
|
|
13
|
+
protected toWcsContact(address: Address): Partial<HclWcsPersonContact>;
|
|
14
|
+
protected personSelfUrl(): string;
|
|
15
|
+
protected updatePersonPayload(email?: string, phone?: string): {
|
|
16
|
+
email1?: string;
|
|
17
|
+
phone1?: string;
|
|
18
|
+
};
|
|
19
|
+
protected personContactListUrl(): string;
|
|
20
|
+
protected contactUrl(nickName: string): string;
|
|
21
|
+
protected makeShippingAddressDefaultPayload(): {
|
|
22
|
+
primary: string;
|
|
23
|
+
};
|
|
24
|
+
getById(_payload: ProfileQuerySelf): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>>;
|
|
25
|
+
update(payload: ProfileMutationUpdate): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>>;
|
|
26
|
+
addShippingAddress(payload: ProfileMutationAddShippingAddress): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>>;
|
|
27
|
+
updateShippingAddress(payload: ProfileMutationUpdateShippingAddress): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>>;
|
|
28
|
+
removeShippingAddress(payload: ProfileMutationRemoveShippingAddress): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>>;
|
|
29
|
+
makeShippingAddressDefault(payload: ProfileMutationMakeShippingAddressDefault): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>>;
|
|
30
|
+
setBillingAddress(payload: ProfileMutationSetBillingAddress): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>>;
|
|
31
|
+
}
|
|
@@ -8,7 +8,10 @@ import type { HclProductSearchCapability } from '../capabilities/product-search.
|
|
|
8
8
|
import type { HclPriceCapability } from '../capabilities/price.capability.js';
|
|
9
9
|
import type { HclInventoryCapability } from '../capabilities/inventory.capability.js';
|
|
10
10
|
import type { HclIdentityCapability } from '../capabilities/identity.capability.js';
|
|
11
|
-
type
|
|
11
|
+
import type { HclProfileCapability } from '../capabilities/profile.capability.js';
|
|
12
|
+
import type { HclOrderCapability } from '../capabilities/order.capability.js';
|
|
13
|
+
import type { HclOrderSearchCapability } from '../capabilities/order-search.capability.js';
|
|
14
|
+
type OverridableCapabilityKey = 'product' | 'productSearch' | 'cart' | 'checkout' | 'category' | 'price' | 'inventory' | 'identity' | 'profile' | 'order' | 'orderSearch';
|
|
12
15
|
type EnabledCapability<TCapability> = TCapability extends {
|
|
13
16
|
enabled: true;
|
|
14
17
|
} ? true : false;
|
|
@@ -28,6 +31,9 @@ type DefaultCapabilityMap = {
|
|
|
28
31
|
price: HclPriceCapability;
|
|
29
32
|
inventory: HclInventoryCapability;
|
|
30
33
|
identity: HclIdentityCapability;
|
|
34
|
+
profile: HclProfileCapability;
|
|
35
|
+
order: HclOrderCapability;
|
|
36
|
+
orderSearch: HclOrderSearchCapability;
|
|
31
37
|
};
|
|
32
38
|
type CapabilityImplementationMap<T extends HclCapabilities> = {
|
|
33
39
|
[K in OverridableCapabilityKey]: ExtractCapabilityImplementation<T[K], DefaultCapabilityMap[K]>;
|
package/src/factories/index.d.ts
CHANGED
|
@@ -6,3 +6,6 @@ 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';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AnyOrderSchema, CostBreakDown, Currency, OrderFactory, OrderItem, OrderSchema, PaymentInstruction, RequestContext } from '@reactionary/core';
|
|
2
|
+
import type * as z from 'zod';
|
|
3
|
+
import type { HclWcsOrderDetailResponse, HclWcsOrderItem, HclWcsPaymentInstruction } from '../../schema/hcl.schema.js';
|
|
4
|
+
export declare class HclOrderFactory<TOrderSchema extends AnyOrderSchema = typeof OrderSchema> implements OrderFactory<TOrderSchema> {
|
|
5
|
+
readonly orderSchema: TOrderSchema;
|
|
6
|
+
constructor(orderSchema: TOrderSchema);
|
|
7
|
+
parseOrder(context: RequestContext, data: HclWcsOrderDetailResponse): z.output<TOrderSchema>;
|
|
8
|
+
protected parseOrderItem(_context: RequestContext, item: HclWcsOrderItem, defaultCurrency: Currency): OrderItem;
|
|
9
|
+
protected parseCostBreakdown(_context: RequestContext, data: HclWcsOrderDetailResponse, currency: Currency): CostBreakDown;
|
|
10
|
+
protected parsePaymentInstruction(_context: RequestContext, pi: HclWcsPaymentInstruction, defaultCurrency: Currency): PaymentInstruction;
|
|
11
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AnyOrderSearchResultSchema, OrderSearchFactory, OrderSearchQueryByTerm, OrderSearchResultItem, OrderSearchResultSchema, RequestContext } from '@reactionary/core';
|
|
2
|
+
import type * as z from 'zod';
|
|
3
|
+
import type { HclWcsCartResponse, HclWcsOrderListResponse } from '../../schema/hcl.schema.js';
|
|
4
|
+
export declare class HclOrderSearchFactory<TOrderSearchResultSchema extends AnyOrderSearchResultSchema = typeof OrderSearchResultSchema> implements OrderSearchFactory<TOrderSearchResultSchema> {
|
|
5
|
+
readonly orderSearchResultSchema: TOrderSearchResultSchema;
|
|
6
|
+
constructor(orderSearchResultSchema: TOrderSearchResultSchema);
|
|
7
|
+
parseOrderSearchResult(context: RequestContext, data: HclWcsOrderListResponse, query: OrderSearchQueryByTerm): z.output<TOrderSearchResultSchema>;
|
|
8
|
+
protected parseOrderSearchResultItem(_context: RequestContext, item: HclWcsCartResponse): OrderSearchResultItem;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Address, AnyProfileSchema, ProfileFactory, ProfileSchema, RequestContext } from '@reactionary/core';
|
|
2
|
+
import type * as z from 'zod';
|
|
3
|
+
import type { HclPersonResponse, HclWcsPersonContact } from '../../schema/hcl.schema.js';
|
|
4
|
+
export declare class HclProfileFactory<TProfileSchema extends AnyProfileSchema = typeof ProfileSchema> implements ProfileFactory<TProfileSchema> {
|
|
5
|
+
readonly profileSchema: TProfileSchema;
|
|
6
|
+
constructor(profileSchema: TProfileSchema);
|
|
7
|
+
parseProfile(context: RequestContext, data: HclPersonResponse): z.output<TProfileSchema>;
|
|
8
|
+
protected parseAddress(_context: RequestContext, contact: HclWcsPersonContact): Address;
|
|
9
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -14,3 +14,6 @@ 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';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Cache, RequestContext, CartFactory, CartFactoryWithOutput, CartCapability, CategoryFactory, CategoryFactoryWithOutput, CategoryCapability, CheckoutFactory, CheckoutFactoryWithOutput, CheckoutCapability, IdentityFactory, IdentityFactoryWithOutput, IdentityCapability, InventoryFactory, InventoryFactoryWithOutput, InventoryCapability, PriceFactory, PriceFactoryWithOutput, PriceCapability, ProductFactory, ProductFactoryWithOutput, ProductCapability, ProductSearchFactory, ProductSearchFactoryWithOutput, ProductSearchCapability } from '@reactionary/core';
|
|
1
|
+
import type { Cache, RequestContext, CartFactory, CartFactoryWithOutput, CartCapability, CategoryFactory, CategoryFactoryWithOutput, CategoryCapability, CheckoutFactory, CheckoutFactoryWithOutput, CheckoutCapability, IdentityFactory, IdentityFactoryWithOutput, IdentityCapability, InventoryFactory, InventoryFactoryWithOutput, InventoryCapability, OrderFactory, OrderFactoryWithOutput, OrderCapability, OrderSearchFactory, OrderSearchFactoryWithOutput, OrderSearchCapability, PriceFactory, PriceFactoryWithOutput, PriceCapability, ProductFactory, ProductFactoryWithOutput, ProductCapability, ProductSearchFactory, ProductSearchFactoryWithOutput, ProductSearchCapability, ProfileFactory, ProfileFactoryWithOutput, ProfileCapability } from '@reactionary/core';
|
|
2
2
|
import type { HclConfiguration } from './configuration.schema.js';
|
|
3
3
|
import type { HclClient } from '../core/client.js';
|
|
4
4
|
import * as z from 'zod';
|
|
@@ -43,6 +43,21 @@ export declare const HclCapabilitiesSchema: z.ZodObject<{
|
|
|
43
43
|
factory: z.ZodOptional<z.ZodUnknown>;
|
|
44
44
|
capability: z.ZodOptional<z.ZodUnknown>;
|
|
45
45
|
}, z.core.$loose>>>;
|
|
46
|
+
profile: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
47
|
+
enabled: z.ZodBoolean;
|
|
48
|
+
factory: z.ZodOptional<z.ZodUnknown>;
|
|
49
|
+
capability: z.ZodOptional<z.ZodUnknown>;
|
|
50
|
+
}, z.core.$loose>>>;
|
|
51
|
+
order: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
52
|
+
enabled: z.ZodBoolean;
|
|
53
|
+
factory: z.ZodOptional<z.ZodUnknown>;
|
|
54
|
+
capability: z.ZodOptional<z.ZodUnknown>;
|
|
55
|
+
}, z.core.$loose>>>;
|
|
56
|
+
orderSearch: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
57
|
+
enabled: z.ZodBoolean;
|
|
58
|
+
factory: z.ZodOptional<z.ZodUnknown>;
|
|
59
|
+
capability: z.ZodOptional<z.ZodUnknown>;
|
|
60
|
+
}, z.core.$loose>>>;
|
|
46
61
|
}, z.core.$loose>;
|
|
47
62
|
export type HclCapabilities = z.infer<typeof HclCapabilitiesSchema>;
|
|
48
63
|
export interface HclCapabilityFactoryArgs {
|
|
@@ -67,3 +82,6 @@ export type HclPriceCapabilityConfig = HclCapabilityConfig<PriceFactoryWithOutpu
|
|
|
67
82
|
export type HclProductCapabilityConfig = HclCapabilityConfig<ProductFactoryWithOutput<ProductFactory>, ProductCapability>;
|
|
68
83
|
export type HclProductSearchCapabilityConfig = HclCapabilityConfig<ProductSearchFactoryWithOutput<ProductSearchFactory>, ProductSearchCapability>;
|
|
69
84
|
export type HclIdentityCapabilityConfig = HclCapabilityConfig<IdentityFactoryWithOutput<IdentityFactory>, IdentityCapability>;
|
|
85
|
+
export type HclProfileCapabilityConfig = HclCapabilityConfig<ProfileFactoryWithOutput<ProfileFactory>, ProfileCapability>;
|
|
86
|
+
export type HclOrderCapabilityConfig = HclCapabilityConfig<OrderFactoryWithOutput<OrderFactory>, OrderCapability>;
|
|
87
|
+
export type HclOrderSearchCapabilityConfig = HclCapabilityConfig<OrderSearchFactoryWithOutput<OrderSearchFactory>, OrderSearchCapability>;
|
|
@@ -427,6 +427,31 @@ export interface HclWcsIdentityResponse {
|
|
|
427
427
|
personalizationID?: string;
|
|
428
428
|
resourceName?: string;
|
|
429
429
|
}
|
|
430
|
+
/**
|
|
431
|
+
* A single entry in a WCS person address book (contact list).
|
|
432
|
+
* Returned as part of the GET /person/@self response (contact[] field)
|
|
433
|
+
* and used for POST/PUT /person/@self/contact operations.
|
|
434
|
+
*/
|
|
435
|
+
export interface HclWcsPersonContact {
|
|
436
|
+
/** Unique identifier / display name for this address (e.g. 'Home', 'Work', 'Billing'). */
|
|
437
|
+
nickName: string;
|
|
438
|
+
firstName?: string;
|
|
439
|
+
lastName?: string;
|
|
440
|
+
/** Street address lines. Index 0 = street, index 1 = apartment / second line. */
|
|
441
|
+
addressLine?: string[];
|
|
442
|
+
/** Alternative single-field address (some WCS endpoint variants). */
|
|
443
|
+
address1?: string;
|
|
444
|
+
city?: string;
|
|
445
|
+
stateOrProvinceName?: string;
|
|
446
|
+
zipCode?: string;
|
|
447
|
+
/** ISO country code, e.g. 'US'. */
|
|
448
|
+
country?: string;
|
|
449
|
+
phone1?: string;
|
|
450
|
+
email1?: string;
|
|
451
|
+
/** '1' marks this as the default / primary shipping address. */
|
|
452
|
+
primary?: string;
|
|
453
|
+
addressType?: string;
|
|
454
|
+
}
|
|
430
455
|
/**
|
|
431
456
|
* Response from GET /wcs/resources/store/{storeId}/person/@self.
|
|
432
457
|
* Only the fields we use are typed; the full WCS schema has many more.
|
|
@@ -439,9 +464,12 @@ export interface HclPersonResponse {
|
|
|
439
464
|
email1?: string;
|
|
440
465
|
firstName?: string;
|
|
441
466
|
lastName?: string;
|
|
467
|
+
phone1?: string;
|
|
442
468
|
resourceName?: string;
|
|
443
469
|
/** Organization ID. `-2000` indicates the default anonymous org. */
|
|
444
470
|
orgizationId?: string;
|
|
471
|
+
/** Address book entries embedded in the person/@self response. */
|
|
472
|
+
contact?: HclWcsPersonContact[];
|
|
445
473
|
}
|
|
446
474
|
/** A single order item embedded in a WCS cart/@self response. */
|
|
447
475
|
export interface HclWcsOrderItem {
|
|
@@ -631,3 +659,38 @@ export interface HclWcsCreateOrderResponse {
|
|
|
631
659
|
redirecturl?: string;
|
|
632
660
|
viewTaskName?: string;
|
|
633
661
|
}
|
|
662
|
+
/**
|
|
663
|
+
* A full order as returned by GET /wcs/resources/store/{storeId}/order/{orderId}.
|
|
664
|
+
* Extends the cart response shape with the `placedDate` field that is only
|
|
665
|
+
* present on placed (non-active) orders.
|
|
666
|
+
*/
|
|
667
|
+
export interface HclWcsOrderDetailResponse extends HclWcsCartResponse {
|
|
668
|
+
/** Date/time when the order was placed, e.g. '2024-01-15T10:30:00.000Z'. */
|
|
669
|
+
placedDate?: string;
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* A single summary entry in a GET /wcs/resources/store/{storeId}/order/@history response.
|
|
673
|
+
* Contains only the fields available in the history list; use getById for full detail.
|
|
674
|
+
*/
|
|
675
|
+
export interface HclWcsOrderHistoryItem {
|
|
676
|
+
orderId: string;
|
|
677
|
+
/** WCS order status code, e.g. 'P', 'M', 'S', 'X'. */
|
|
678
|
+
status: string;
|
|
679
|
+
placedDate?: string;
|
|
680
|
+
grandTotal?: string;
|
|
681
|
+
grandTotalCurrency?: string;
|
|
682
|
+
totalProductPrice?: string;
|
|
683
|
+
orderDescription?: string;
|
|
684
|
+
buyerDistinguishedName?: string;
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* Top-level response from GET /wcs/resources/store/{storeId}/order/@history.
|
|
688
|
+
* Returns a paginated list of the buyer's past orders.
|
|
689
|
+
*/
|
|
690
|
+
export interface HclWcsOrderHistoryResponse {
|
|
691
|
+
Order?: HclWcsOrderHistoryItem[];
|
|
692
|
+
recordSetTotal?: string;
|
|
693
|
+
recordSetCount?: string;
|
|
694
|
+
recordSetStartNumber?: string;
|
|
695
|
+
recordSetComplete?: string;
|
|
696
|
+
}
|
package/src/test/test-utils.d.ts
CHANGED
|
@@ -5,12 +5,15 @@ export declare function createHclClient(contextOverrides?: Partial<RequestContex
|
|
|
5
5
|
product?: true | undefined;
|
|
6
6
|
productSearch?: true | undefined;
|
|
7
7
|
price?: false | undefined;
|
|
8
|
+
order?: false | undefined;
|
|
8
9
|
cart?: false | undefined;
|
|
9
10
|
checkout?: false | undefined;
|
|
10
11
|
identity?: false | undefined;
|
|
12
|
+
profile?: false | undefined;
|
|
11
13
|
inventory?: false | undefined;
|
|
12
14
|
category?: true | undefined;
|
|
13
|
-
|
|
15
|
+
orderSearch?: false | undefined;
|
|
16
|
+
}>, "product" | "productSearch" | "price" | "order" | "cart" | "checkout" | "identity" | "profile" | "inventory" | "category" | "orderSearch"> & {
|
|
14
17
|
product: import("../index.js").HclProductCapability<import("../index.js").HclProductFactory<import("zod").ZodObject<{
|
|
15
18
|
identifier: import("zod").ZodObject<{
|
|
16
19
|
key: import("zod").ZodString;
|