@reactionary/hcl 0.9.13 → 0.9.14
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/company.capability.js +307 -0
- package/capabilities/product-list.capability.js +665 -0
- package/capabilities/store.capability.js +72 -0
- package/core/initialize.js +71 -2
- package/factories/company/company.factory.js +77 -0
- package/factories/index.js +3 -0
- package/factories/product-list/product-list.factory.js +158 -0
- package/factories/store/store.factory.js +18 -0
- package/index.js +3 -0
- package/package.json +2 -2
- package/schema/capabilities.schema.js +8 -2
- package/src/capabilities/company.capability.d.ts +26 -0
- package/src/capabilities/product-list.capability.d.ts +42 -0
- package/src/capabilities/store.capability.d.ts +13 -0
- package/src/core/initialize.types.d.ts +7 -1
- package/src/factories/company/company.factory.d.ts +11 -0
- package/src/factories/index.d.ts +3 -0
- package/src/factories/product-list/product-list.factory.d.ts +40 -0
- package/src/factories/store/store.factory.d.ts +8 -0
- package/src/index.d.ts +3 -0
- package/src/schema/capabilities.schema.d.ts +19 -1
- package/src/schema/hcl.schema.d.ts +218 -0
- package/src/test/test-utils.d.ts +4 -1
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
Reactionary,
|
|
14
|
+
StoreCapability,
|
|
15
|
+
StoreQueryByProximitySchema,
|
|
16
|
+
StoreSchema,
|
|
17
|
+
success
|
|
18
|
+
} from "@reactionary/core";
|
|
19
|
+
import * as z from "zod";
|
|
20
|
+
import createDebug from "debug";
|
|
21
|
+
const debug = createDebug("reactionary:hcl:store");
|
|
22
|
+
class HclStoreCapability extends StoreCapability {
|
|
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 queryByProximity(payload) {
|
|
33
|
+
debug(
|
|
34
|
+
"queryByProximity lat=%d lon=%d dist=%d",
|
|
35
|
+
payload.latitude,
|
|
36
|
+
payload.longitude,
|
|
37
|
+
payload.distance
|
|
38
|
+
);
|
|
39
|
+
const response = await this.client.callGet(
|
|
40
|
+
this.getStoreLocatorUrl(payload),
|
|
41
|
+
this.getStoreLocatorParams(payload),
|
|
42
|
+
{ allowUndefined: true }
|
|
43
|
+
);
|
|
44
|
+
const stores = (response?.PhysicalStore ?? []).map(
|
|
45
|
+
(store) => this.factory.parseStore(this.context, store)
|
|
46
|
+
);
|
|
47
|
+
return success(stores);
|
|
48
|
+
}
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
// Extension points
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
getStoreLocatorUrl(payload) {
|
|
53
|
+
return `${this.client.transactionBaseUrl}/storelocator/latitude/${payload.latitude}/longitude/${payload.longitude}`;
|
|
54
|
+
}
|
|
55
|
+
getStoreLocatorParams(payload) {
|
|
56
|
+
const params = new URLSearchParams();
|
|
57
|
+
params.set("maxItems", String(payload.limit));
|
|
58
|
+
params.set("radius", String(payload.distance));
|
|
59
|
+
params.set("radiusUOM", "km");
|
|
60
|
+
params.set("siteLevelStoreSearch", "false");
|
|
61
|
+
return params;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
__decorateClass([
|
|
65
|
+
Reactionary({
|
|
66
|
+
inputSchema: StoreQueryByProximitySchema,
|
|
67
|
+
outputSchema: z.array(StoreSchema)
|
|
68
|
+
})
|
|
69
|
+
], HclStoreCapability.prototype, "queryByProximity", 1);
|
|
70
|
+
export {
|
|
71
|
+
HclStoreCapability
|
|
72
|
+
};
|
package/core/initialize.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CategoryPaginatedResultSchema,
|
|
3
|
+
CompanyPaginatedListSchema,
|
|
4
|
+
CompanySchema,
|
|
3
5
|
IdentitySchema,
|
|
4
6
|
OrderSchema,
|
|
5
7
|
OrderSearchResultSchema,
|
|
6
8
|
PersonalizationProfileSchema,
|
|
7
9
|
ProductAssociationSchema,
|
|
10
|
+
ProductListItemPaginatedResultsSchema,
|
|
11
|
+
ProductListItemSchema,
|
|
12
|
+
ProductListPaginatedResultsSchema,
|
|
13
|
+
ProductListSchema,
|
|
8
14
|
ProductRecommendationSchema,
|
|
9
15
|
ProductSchema,
|
|
10
|
-
ProfileSchema
|
|
16
|
+
ProfileSchema,
|
|
17
|
+
StoreSchema
|
|
11
18
|
} from "@reactionary/core";
|
|
12
19
|
import { HclCategorySchema } from "../schema/category.schema.js";
|
|
13
20
|
import {
|
|
@@ -24,6 +31,7 @@ import {
|
|
|
24
31
|
HclCartFactory,
|
|
25
32
|
HclCategoryFactory,
|
|
26
33
|
HclCheckoutFactory,
|
|
34
|
+
HclCompanyFactory,
|
|
27
35
|
HclIdentityFactory,
|
|
28
36
|
HclInventoryFactory,
|
|
29
37
|
HclOrderFactory,
|
|
@@ -32,9 +40,11 @@ import {
|
|
|
32
40
|
HclPriceFactory,
|
|
33
41
|
HclProductAssociationsFactory,
|
|
34
42
|
HclProductFactory,
|
|
43
|
+
HclProductListFactory,
|
|
35
44
|
HclProductRecommendationsFactory,
|
|
36
45
|
HclProductSearchFactory,
|
|
37
|
-
HclProfileFactory
|
|
46
|
+
HclProfileFactory,
|
|
47
|
+
HclStoreFactory
|
|
38
48
|
} from "../factories/index.js";
|
|
39
49
|
import { HclCartCapability } from "../capabilities/cart.capability.js";
|
|
40
50
|
import { HclCheckoutCapability } from "../capabilities/checkout.capability.js";
|
|
@@ -51,6 +61,9 @@ import { HclAnalyticsCapability } from "../capabilities/analytics.capability.js"
|
|
|
51
61
|
import { HclProductAssociationsCapability } from "../capabilities/product-associations.capability.js";
|
|
52
62
|
import { HclProductRecommendationsCapability } from "../capabilities/product-recommendations.capability.js";
|
|
53
63
|
import { HclPersonalizationProfileCapability } from "../capabilities/personalization-profile.capability.js";
|
|
64
|
+
import { HclCompanyCapability } from "../capabilities/company.capability.js";
|
|
65
|
+
import { HclStoreCapability } from "../capabilities/store.capability.js";
|
|
66
|
+
import { HclProductListCapability } from "../capabilities/product-list.capability.js";
|
|
54
67
|
import {
|
|
55
68
|
CartIdentifierSchema,
|
|
56
69
|
CartPaginatedSearchResultSchema,
|
|
@@ -329,6 +342,62 @@ function withHclCapabilities(configuration, capabilities) {
|
|
|
329
342
|
buildCapabilityArgs
|
|
330
343
|
);
|
|
331
344
|
}
|
|
345
|
+
if (caps.company?.enabled) {
|
|
346
|
+
client.company = resolveCapabilityWithFactory(
|
|
347
|
+
capabilities.company,
|
|
348
|
+
{
|
|
349
|
+
factory: new HclCompanyFactory(
|
|
350
|
+
CompanySchema,
|
|
351
|
+
CompanyPaginatedListSchema
|
|
352
|
+
),
|
|
353
|
+
capability: (args) => new HclCompanyCapability(
|
|
354
|
+
args.cache,
|
|
355
|
+
args.context,
|
|
356
|
+
args.config,
|
|
357
|
+
args.hclClient,
|
|
358
|
+
args.factory
|
|
359
|
+
)
|
|
360
|
+
},
|
|
361
|
+
buildCapabilityArgs
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
if (caps.store?.enabled) {
|
|
365
|
+
client.store = resolveCapabilityWithFactory(
|
|
366
|
+
capabilities.store,
|
|
367
|
+
{
|
|
368
|
+
factory: new HclStoreFactory(StoreSchema),
|
|
369
|
+
capability: (args) => new HclStoreCapability(
|
|
370
|
+
args.cache,
|
|
371
|
+
args.context,
|
|
372
|
+
args.config,
|
|
373
|
+
args.hclClient,
|
|
374
|
+
args.factory
|
|
375
|
+
)
|
|
376
|
+
},
|
|
377
|
+
buildCapabilityArgs
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
if (caps.productList?.enabled) {
|
|
381
|
+
client.productList = resolveCapabilityWithFactory(
|
|
382
|
+
capabilities.productList,
|
|
383
|
+
{
|
|
384
|
+
factory: new HclProductListFactory(
|
|
385
|
+
ProductListSchema,
|
|
386
|
+
ProductListItemSchema,
|
|
387
|
+
ProductListPaginatedResultsSchema,
|
|
388
|
+
ProductListItemPaginatedResultsSchema
|
|
389
|
+
),
|
|
390
|
+
capability: (args) => new HclProductListCapability(
|
|
391
|
+
args.cache,
|
|
392
|
+
args.context,
|
|
393
|
+
args.config,
|
|
394
|
+
args.hclClient,
|
|
395
|
+
args.factory
|
|
396
|
+
)
|
|
397
|
+
},
|
|
398
|
+
buildCapabilityArgs
|
|
399
|
+
);
|
|
400
|
+
}
|
|
332
401
|
return client;
|
|
333
402
|
};
|
|
334
403
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
class HclCompanyFactory {
|
|
2
|
+
companySchema;
|
|
3
|
+
companyPaginatedListSchema;
|
|
4
|
+
constructor(companySchema, companyPaginatedListSchema) {
|
|
5
|
+
this.companySchema = companySchema;
|
|
6
|
+
this.companyPaginatedListSchema = companyPaginatedListSchema;
|
|
7
|
+
}
|
|
8
|
+
parseCompany(_context, data) {
|
|
9
|
+
const result = {
|
|
10
|
+
identifier: {
|
|
11
|
+
taxIdentifier: data.taxPayerId ?? data.organizationId ?? data.orgEntityId ?? ""
|
|
12
|
+
},
|
|
13
|
+
name: data.organizationName ?? data.displayName ?? "",
|
|
14
|
+
dunsIdentifier: void 0,
|
|
15
|
+
tinIdentifier: data.legalId,
|
|
16
|
+
logo: void 0,
|
|
17
|
+
// state '0' = locked/blocked; any other value (or absent) = active
|
|
18
|
+
status: data.state === "0" ? "blocked" : "active",
|
|
19
|
+
pointOfContact: {
|
|
20
|
+
email: data.contactInfo?.email1 ?? "",
|
|
21
|
+
phone: data.contactInfo?.phone1
|
|
22
|
+
},
|
|
23
|
+
billingAddress: data.contactInfo ? this.parseOrgContact(data.contactInfo, "default") : this.parseOrgContact(
|
|
24
|
+
{
|
|
25
|
+
nickName: "default",
|
|
26
|
+
firstName: "",
|
|
27
|
+
lastName: "",
|
|
28
|
+
addressLine: [],
|
|
29
|
+
city: "",
|
|
30
|
+
stateOrProvinceName: "",
|
|
31
|
+
zipCode: "",
|
|
32
|
+
country: ""
|
|
33
|
+
},
|
|
34
|
+
"default"
|
|
35
|
+
),
|
|
36
|
+
alternateShippingAddresses: (data.addressBook ?? []).map(
|
|
37
|
+
(c, i) => this.parseOrgContact(c, c.nickName ?? `address-${i}`)
|
|
38
|
+
),
|
|
39
|
+
isCustomAddressesAllowed: false,
|
|
40
|
+
isSelfManagementOfShippingAddressesAllowed: false
|
|
41
|
+
};
|
|
42
|
+
return this.companySchema.parse(result);
|
|
43
|
+
}
|
|
44
|
+
parseCompanyPaginatedList(context, data, _query) {
|
|
45
|
+
const items = (data.organizationDataBeans ?? []).map(
|
|
46
|
+
(org) => this.parseCompany(context, org)
|
|
47
|
+
);
|
|
48
|
+
const pageSize = Math.max(1, items.length);
|
|
49
|
+
const result = {
|
|
50
|
+
identifier: {
|
|
51
|
+
paginationOptions: { pageNumber: 1, pageSize }
|
|
52
|
+
},
|
|
53
|
+
items,
|
|
54
|
+
totalCount: Number(data.recordSetTotal ?? items.length),
|
|
55
|
+
pageSize,
|
|
56
|
+
pageNumber: 1,
|
|
57
|
+
totalPages: 1
|
|
58
|
+
};
|
|
59
|
+
return this.companyPaginatedListSchema.parse(result);
|
|
60
|
+
}
|
|
61
|
+
parseOrgContact(contact, defaultNickName) {
|
|
62
|
+
return {
|
|
63
|
+
identifier: { nickName: contact.nickName ?? defaultNickName },
|
|
64
|
+
firstName: contact.firstName ?? "",
|
|
65
|
+
lastName: contact.lastName ?? "",
|
|
66
|
+
streetAddress: contact.addressLine?.[0] ?? "",
|
|
67
|
+
streetNumber: contact.addressLine?.[1] ?? "",
|
|
68
|
+
city: contact.city ?? "",
|
|
69
|
+
region: contact.stateOrProvinceName ?? "",
|
|
70
|
+
postalCode: contact.zipCode ?? "",
|
|
71
|
+
countryCode: contact.country ?? ""
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export {
|
|
76
|
+
HclCompanyFactory
|
|
77
|
+
};
|
package/factories/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./cart/cart.factory.js";
|
|
2
2
|
export * from "./checkout/checkout.factory.js";
|
|
3
|
+
export * from "./company/company.factory.js";
|
|
3
4
|
export * from "./product/product.factory.js";
|
|
4
5
|
export * from "./category/category.factory.js";
|
|
5
6
|
export * from "./product-search/product-search.factory.js";
|
|
@@ -10,5 +11,7 @@ export * from "./profile/profile.factory.js";
|
|
|
10
11
|
export * from "./order/order.factory.js";
|
|
11
12
|
export * from "./order-search/order-search.factory.js";
|
|
12
13
|
export * from "./product-associations/product-associations.factory.js";
|
|
14
|
+
export * from "./product-list/product-list.factory.js";
|
|
13
15
|
export * from "./product-recommendations/product-recommendations.factory.js";
|
|
14
16
|
export * from "./personalization-profile/personalization-profile.factory.js";
|
|
17
|
+
export * from "./store/store.factory.js";
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
const WISHLIST_TYPES = /* @__PURE__ */ new Set(["favorite", "wish", "shopping"]);
|
|
2
|
+
function encodeWishlistType(type, description) {
|
|
3
|
+
return `${type}:${description ?? ""}`;
|
|
4
|
+
}
|
|
5
|
+
function decodeWishlistType(raw) {
|
|
6
|
+
if (raw) {
|
|
7
|
+
const colonIdx = raw.indexOf(":");
|
|
8
|
+
if (colonIdx > 0) {
|
|
9
|
+
const prefix = raw.slice(0, colonIdx);
|
|
10
|
+
if (WISHLIST_TYPES.has(prefix)) {
|
|
11
|
+
const desc = raw.slice(colonIdx + 1);
|
|
12
|
+
return {
|
|
13
|
+
type: prefix,
|
|
14
|
+
description: desc || void 0
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return { type: "wish", description: raw || void 0 };
|
|
20
|
+
}
|
|
21
|
+
class HclProductListFactory {
|
|
22
|
+
productListSchema;
|
|
23
|
+
productListItemSchema;
|
|
24
|
+
productListPaginatedSchema;
|
|
25
|
+
productListItemPaginatedSchema;
|
|
26
|
+
constructor(productListSchema, productListItemSchema, productListPaginatedSchema, productListItemPaginatedSchema) {
|
|
27
|
+
this.productListSchema = productListSchema;
|
|
28
|
+
this.productListItemSchema = productListItemSchema;
|
|
29
|
+
this.productListPaginatedSchema = productListPaginatedSchema;
|
|
30
|
+
this.productListItemPaginatedSchema = productListItemPaginatedSchema;
|
|
31
|
+
}
|
|
32
|
+
parseProductList(_context, data) {
|
|
33
|
+
const key = data.uniqueID ?? data.externalIdentifier ?? "";
|
|
34
|
+
const { type, description } = decodeWishlistType(data.description);
|
|
35
|
+
const result = {
|
|
36
|
+
identifier: { key, listType: type },
|
|
37
|
+
type,
|
|
38
|
+
name: data.descriptionName ?? "",
|
|
39
|
+
description,
|
|
40
|
+
published: true
|
|
41
|
+
};
|
|
42
|
+
return this.productListSchema.parse(result);
|
|
43
|
+
}
|
|
44
|
+
parseProductListItem(_context, data) {
|
|
45
|
+
const result = {
|
|
46
|
+
identifier: { key: data.item.giftListItemID ?? "", list: data.list },
|
|
47
|
+
variant: { sku: data.item.productId ?? data.item.partNumber ?? "" },
|
|
48
|
+
quantity: Math.max(1, Number(data.item.quantityRequested ?? 1)),
|
|
49
|
+
order: 1
|
|
50
|
+
};
|
|
51
|
+
return this.productListItemSchema.parse(result);
|
|
52
|
+
}
|
|
53
|
+
parseProductListPaginatedResult(context, data, query) {
|
|
54
|
+
const items = (data.GiftList ?? []).map((w) => this.parseProductList(context, w)).filter(
|
|
55
|
+
(item) => item.identifier.listType === query.search.listType
|
|
56
|
+
);
|
|
57
|
+
const result = {
|
|
58
|
+
identifier: {
|
|
59
|
+
listType: query.search.listType,
|
|
60
|
+
paginationOptions: query.search.paginationOptions
|
|
61
|
+
},
|
|
62
|
+
items,
|
|
63
|
+
totalCount: items.length,
|
|
64
|
+
pageSize: Math.max(1, items.length),
|
|
65
|
+
pageNumber: 1,
|
|
66
|
+
totalPages: 1
|
|
67
|
+
};
|
|
68
|
+
return this.productListPaginatedSchema.parse(result);
|
|
69
|
+
}
|
|
70
|
+
parseProductListItemPaginatedResult(context, data, query) {
|
|
71
|
+
const rawItems = data.GiftList?.[0]?.item ?? [];
|
|
72
|
+
const items = rawItems.map(
|
|
73
|
+
(i) => this.parseProductListItem(context, { item: i, list: query.search.list })
|
|
74
|
+
);
|
|
75
|
+
const result = {
|
|
76
|
+
identifier: {
|
|
77
|
+
list: query.search.list,
|
|
78
|
+
paginationOptions: query.search.paginationOptions
|
|
79
|
+
},
|
|
80
|
+
items,
|
|
81
|
+
totalCount: Number(data.recordSetTotal ?? items.length),
|
|
82
|
+
pageSize: items.length,
|
|
83
|
+
pageNumber: 1,
|
|
84
|
+
totalPages: 1
|
|
85
|
+
};
|
|
86
|
+
return this.productListItemPaginatedSchema.parse(result);
|
|
87
|
+
}
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
// Requisition list parsers
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
parseRequisitionList(_context, data) {
|
|
92
|
+
const result = {
|
|
93
|
+
identifier: {
|
|
94
|
+
key: data.requisitionListId ?? "",
|
|
95
|
+
listType: "requisition"
|
|
96
|
+
},
|
|
97
|
+
type: "requisition",
|
|
98
|
+
name: data.name ?? "",
|
|
99
|
+
description: data.description,
|
|
100
|
+
published: true
|
|
101
|
+
};
|
|
102
|
+
return this.productListSchema.parse(result);
|
|
103
|
+
}
|
|
104
|
+
parseRequisitionListItem(_context, data) {
|
|
105
|
+
const result = {
|
|
106
|
+
identifier: {
|
|
107
|
+
key: data.item.requisitionListItemId ?? "",
|
|
108
|
+
list: data.list
|
|
109
|
+
},
|
|
110
|
+
variant: { sku: data.item.productId ?? data.item.partNumber ?? "" },
|
|
111
|
+
quantity: Math.max(1, Number(data.item.quantity ?? 1)),
|
|
112
|
+
order: 1
|
|
113
|
+
};
|
|
114
|
+
return this.productListItemSchema.parse(result);
|
|
115
|
+
}
|
|
116
|
+
parseRequisitionListPaginatedResult(context, data, query) {
|
|
117
|
+
const items = (data.resultList ?? []).map(
|
|
118
|
+
(r) => this.parseRequisitionList(context, r)
|
|
119
|
+
);
|
|
120
|
+
const result = {
|
|
121
|
+
identifier: {
|
|
122
|
+
listType: query.search.listType,
|
|
123
|
+
paginationOptions: query.search.paginationOptions
|
|
124
|
+
},
|
|
125
|
+
items,
|
|
126
|
+
totalCount: Number(data.recordSetTotal ?? items.length),
|
|
127
|
+
pageSize: Math.max(1, items.length),
|
|
128
|
+
pageNumber: 1,
|
|
129
|
+
totalPages: 1
|
|
130
|
+
};
|
|
131
|
+
return this.productListPaginatedSchema.parse(result);
|
|
132
|
+
}
|
|
133
|
+
parseRequisitionListItemPaginatedResult(context, data, query) {
|
|
134
|
+
const rawItems = data.resultList?.[0]?.item ?? [];
|
|
135
|
+
const items = rawItems.map(
|
|
136
|
+
(i) => this.parseRequisitionListItem(context, {
|
|
137
|
+
item: i,
|
|
138
|
+
list: query.search.list
|
|
139
|
+
})
|
|
140
|
+
);
|
|
141
|
+
const result = {
|
|
142
|
+
identifier: {
|
|
143
|
+
list: query.search.list,
|
|
144
|
+
paginationOptions: query.search.paginationOptions
|
|
145
|
+
},
|
|
146
|
+
items,
|
|
147
|
+
totalCount: Number(data.recordSetTotal ?? items.length),
|
|
148
|
+
pageSize: Math.max(1, items.length),
|
|
149
|
+
pageNumber: 1,
|
|
150
|
+
totalPages: 1
|
|
151
|
+
};
|
|
152
|
+
return this.productListItemPaginatedSchema.parse(result);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
export {
|
|
156
|
+
HclProductListFactory,
|
|
157
|
+
encodeWishlistType
|
|
158
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class HclStoreFactory {
|
|
2
|
+
storeSchema;
|
|
3
|
+
constructor(storeSchema) {
|
|
4
|
+
this.storeSchema = storeSchema;
|
|
5
|
+
}
|
|
6
|
+
parseStore(_context, data) {
|
|
7
|
+
const name = data.Description?.[0]?.displayStoreName ?? data.storeName ?? data.uniqueID;
|
|
8
|
+
const result = {
|
|
9
|
+
identifier: { key: data.uniqueID },
|
|
10
|
+
name,
|
|
11
|
+
fulfillmentCenter: { key: data.uniqueID }
|
|
12
|
+
};
|
|
13
|
+
return this.storeSchema.parse(result);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
HclStoreFactory
|
|
18
|
+
};
|
package/index.js
CHANGED
|
@@ -21,3 +21,6 @@ export * from "./capabilities/analytics.capability.js";
|
|
|
21
21
|
export * from "./capabilities/product-associations.capability.js";
|
|
22
22
|
export * from "./capabilities/product-recommendations.capability.js";
|
|
23
23
|
export * from "./capabilities/personalization-profile.capability.js";
|
|
24
|
+
export * from "./capabilities/company.capability.js";
|
|
25
|
+
export * from "./capabilities/store.capability.js";
|
|
26
|
+
export * from "./capabilities/product-list.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.14",
|
|
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.14",
|
|
9
9
|
"debug": "^4.4.3",
|
|
10
10
|
"zod": "4.1.9"
|
|
11
11
|
},
|
|
@@ -9,34 +9,40 @@ const HclCapabilitiesSchema = CapabilitiesSchema.pick({
|
|
|
9
9
|
cart: true,
|
|
10
10
|
checkout: true,
|
|
11
11
|
category: true,
|
|
12
|
+
company: true,
|
|
12
13
|
product: true,
|
|
13
14
|
price: true,
|
|
14
15
|
inventory: true,
|
|
15
16
|
identity: true,
|
|
16
17
|
productSearch: true,
|
|
18
|
+
productList: true,
|
|
17
19
|
profile: true,
|
|
18
20
|
order: true,
|
|
19
21
|
orderSearch: true,
|
|
20
22
|
analytics: true,
|
|
21
23
|
productAssociations: true,
|
|
22
24
|
productRecommendations: true,
|
|
23
|
-
personalizationProfile: true
|
|
25
|
+
personalizationProfile: true,
|
|
26
|
+
store: true
|
|
24
27
|
}).extend({
|
|
25
28
|
cart: OverridableCapabilitySchema.optional(),
|
|
26
29
|
checkout: OverridableCapabilitySchema.optional(),
|
|
27
30
|
category: OverridableCapabilitySchema.optional(),
|
|
31
|
+
company: OverridableCapabilitySchema.optional(),
|
|
28
32
|
product: OverridableCapabilitySchema.optional(),
|
|
29
33
|
price: OverridableCapabilitySchema.optional(),
|
|
30
34
|
inventory: OverridableCapabilitySchema.optional(),
|
|
31
35
|
identity: OverridableCapabilitySchema.optional(),
|
|
32
36
|
productSearch: OverridableCapabilitySchema.optional(),
|
|
37
|
+
productList: OverridableCapabilitySchema.optional(),
|
|
33
38
|
profile: OverridableCapabilitySchema.optional(),
|
|
34
39
|
order: OverridableCapabilitySchema.optional(),
|
|
35
40
|
orderSearch: OverridableCapabilitySchema.optional(),
|
|
36
41
|
analytics: OverridableCapabilitySchema.optional(),
|
|
37
42
|
productAssociations: OverridableCapabilitySchema.optional(),
|
|
38
43
|
productRecommendations: OverridableCapabilitySchema.optional(),
|
|
39
|
-
personalizationProfile: OverridableCapabilitySchema.optional()
|
|
44
|
+
personalizationProfile: OverridableCapabilitySchema.optional(),
|
|
45
|
+
store: OverridableCapabilitySchema.optional()
|
|
40
46
|
}).partial();
|
|
41
47
|
export {
|
|
42
48
|
HclCapabilitiesSchema
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Address, type Cache, CompanyCapability, type CompanyFactory, type CompanyFactoryOutput, type CompanyFactoryWithOutput, type CompanyMutationAddShippingAddress, type CompanyMutationMakeShippingAddressDefault, type CompanyMutationRemoveShippingAddress, type CompanyMutationUpdateShippingAddress, type CompanyPaginatedList, type CompanyQueryById, type CompanyQueryList, type NotFoundError, 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 { HclCompanyFactory } from '../factories/company/company.factory.js';
|
|
5
|
+
import type { HclOrganizationItem, HclWcsOrgContact } from '../schema/hcl.schema.js';
|
|
6
|
+
export declare class HclCompanyCapability<TFactory extends CompanyFactory = HclCompanyFactory> extends CompanyCapability {
|
|
7
|
+
protected readonly config: HclConfiguration;
|
|
8
|
+
protected readonly client: HclClient;
|
|
9
|
+
protected readonly factory: CompanyFactoryWithOutput<TFactory>;
|
|
10
|
+
constructor(cache: Cache, context: RequestContext, config: HclConfiguration, client: HclClient, factory: CompanyFactoryWithOutput<TFactory>);
|
|
11
|
+
getById(payload: CompanyQueryById): Promise<Result<CompanyFactoryOutput<TFactory>>>;
|
|
12
|
+
listCompanies(payload: CompanyQueryList): Promise<Result<CompanyPaginatedList>>;
|
|
13
|
+
addShippingAddress(payload: CompanyMutationAddShippingAddress): Promise<Result<CompanyFactoryOutput<TFactory>, NotFoundError>>;
|
|
14
|
+
updateShippingAddress(payload: CompanyMutationUpdateShippingAddress): Promise<Result<CompanyFactoryOutput<TFactory>, NotFoundError>>;
|
|
15
|
+
removeShippingAddress(payload: CompanyMutationRemoveShippingAddress): Promise<Result<CompanyFactoryOutput<TFactory>, NotFoundError>>;
|
|
16
|
+
makeShippingAddressDefault(payload: CompanyMutationMakeShippingAddressDefault): Promise<Result<CompanyFactoryOutput<TFactory>, NotFoundError>>;
|
|
17
|
+
protected getOrganizationUrl(orgId: string): string;
|
|
18
|
+
protected getOrganizationDetailsParams(): URLSearchParams;
|
|
19
|
+
protected getOrganizationListUrl(): string;
|
|
20
|
+
protected getOrganizationListParams(query: CompanyQueryList): URLSearchParams;
|
|
21
|
+
protected getUpdateOrganizationUrl(orgId: string): string;
|
|
22
|
+
protected getUpdateOrganizationBody(org: HclOrganizationItem, addressBook: HclWcsOrgContact[]): Record<string, unknown>;
|
|
23
|
+
protected fetchOrganization(orgId: string): Promise<HclOrganizationItem | undefined>;
|
|
24
|
+
protected fetchOrganizationOrThrow(orgId: string): Promise<HclOrganizationItem>;
|
|
25
|
+
protected toOrgContact(address: Address): HclWcsOrgContact;
|
|
26
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type Cache, ProductListCapability, type ProductListFactory, type ProductListFactoryItemOutput, type ProductListFactoryItemPaginatedOutput, type ProductListFactoryListOutput, type ProductListFactoryListPaginatedOutput, type ProductListFactoryWithOutput, type ProductListItemMutationCreate, type ProductListItemMutationDelete, type ProductListItemMutationUpdate, type ProductListItemsQuery, type ProductListMutationCreate, type ProductListMutationDelete, type ProductListMutationUpdate, type ProductListQuery, type ProductListQueryById, 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 { HclProductListFactory, HclRequisitionListFactoryExtension } from '../factories/product-list/product-list.factory.js';
|
|
5
|
+
export declare class HclProductListCapability<TFactory extends ProductListFactory = HclProductListFactory> extends ProductListCapability<ProductListFactoryListOutput<TFactory>, ProductListFactoryItemOutput<TFactory>, ProductListFactoryListPaginatedOutput<TFactory>, ProductListFactoryItemPaginatedOutput<TFactory>> {
|
|
6
|
+
protected readonly config: HclConfiguration;
|
|
7
|
+
protected readonly client: HclClient;
|
|
8
|
+
protected readonly factory: ProductListFactoryWithOutput<TFactory>;
|
|
9
|
+
constructor(cache: Cache, context: RequestContext, config: HclConfiguration, client: HclClient, factory: ProductListFactoryWithOutput<TFactory>);
|
|
10
|
+
/**
|
|
11
|
+
* Returns the factory cast to include the HCL-specific requisition list parse methods.
|
|
12
|
+
* Subclasses can override this if they provide a custom factory.
|
|
13
|
+
*/
|
|
14
|
+
protected get requisitionFactory(): ProductListFactoryWithOutput<TFactory> & HclRequisitionListFactoryExtension;
|
|
15
|
+
getById(payload: ProductListQueryById): Promise<Result<ProductListFactoryListOutput<TFactory>>>;
|
|
16
|
+
queryLists(query: ProductListQuery): Promise<Result<ProductListFactoryListPaginatedOutput<TFactory>>>;
|
|
17
|
+
addList(mutation: ProductListMutationCreate): Promise<Result<ProductListFactoryListOutput<TFactory>>>;
|
|
18
|
+
updateList(mutation: ProductListMutationUpdate): Promise<Result<ProductListFactoryListOutput<TFactory>>>;
|
|
19
|
+
deleteList(mutation: ProductListMutationDelete): Promise<Result<void>>;
|
|
20
|
+
queryListItems(query: ProductListItemsQuery): Promise<Result<ProductListFactoryItemPaginatedOutput<TFactory>>>;
|
|
21
|
+
addItem(mutation: ProductListItemMutationCreate): Promise<Result<ProductListFactoryItemOutput<TFactory>>>;
|
|
22
|
+
updateItem(mutation: ProductListItemMutationUpdate): Promise<Result<ProductListFactoryItemOutput<TFactory>>>;
|
|
23
|
+
deleteItem(mutation: ProductListItemMutationDelete): Promise<Result<void>>;
|
|
24
|
+
protected getWishlistsUrl(): string;
|
|
25
|
+
protected getWishlistUrl(listId: string): string;
|
|
26
|
+
protected getWishlistItemsUrl(listId: string): string;
|
|
27
|
+
protected getWishlistItemUrl(listId: string, itemId: string): string;
|
|
28
|
+
protected getWishlistItemsParams(query: ProductListItemsQuery): URLSearchParams;
|
|
29
|
+
protected getCreateWishlistBody(mutation: ProductListMutationCreate): Record<string, unknown>;
|
|
30
|
+
protected getUpdateWishlistBody(mutation: ProductListMutationUpdate): Record<string, unknown>;
|
|
31
|
+
protected getAddItemParams(): URLSearchParams;
|
|
32
|
+
protected getAddItemBody(mutation: ProductListItemMutationCreate): Record<string, unknown>;
|
|
33
|
+
protected getRequisitionListsUrl(): string;
|
|
34
|
+
protected getRequisitionListUrl(listId: string): string;
|
|
35
|
+
protected getRequisitionListItemsUrl(listId: string): string;
|
|
36
|
+
protected getRequisitionListItemUrl(listId: string, itemId: string): string;
|
|
37
|
+
protected getRequisitionListItemsParams(query: ProductListItemsQuery): URLSearchParams;
|
|
38
|
+
protected getCreateRequisitionListBody(mutation: ProductListMutationCreate): Record<string, unknown>;
|
|
39
|
+
protected getUpdateRequisitionListBody(mutation: ProductListMutationUpdate): Record<string, unknown>;
|
|
40
|
+
protected getRequisitionAddItemParams(): URLSearchParams;
|
|
41
|
+
protected getRequisitionAddItemBody(mutation: ProductListItemMutationCreate): Record<string, unknown>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Cache, type RequestContext, type Result, StoreCapability, type StoreFactory, type StoreFactoryOutput, type StoreFactoryWithOutput, type StoreQueryByProximity } from '@reactionary/core';
|
|
2
|
+
import type { HclConfiguration } from '../schema/configuration.schema.js';
|
|
3
|
+
import type { HclClient } from '../core/client.js';
|
|
4
|
+
import type { HclStoreFactory } from '../factories/store/store.factory.js';
|
|
5
|
+
export declare class HclStoreCapability<TFactory extends StoreFactory = HclStoreFactory> extends StoreCapability<StoreFactoryOutput<TFactory>> {
|
|
6
|
+
protected readonly config: HclConfiguration;
|
|
7
|
+
protected readonly client: HclClient;
|
|
8
|
+
protected readonly factory: StoreFactoryWithOutput<TFactory>;
|
|
9
|
+
constructor(cache: Cache, context: RequestContext, config: HclConfiguration, client: HclClient, factory: StoreFactoryWithOutput<TFactory>);
|
|
10
|
+
queryByProximity(payload: StoreQueryByProximity): Promise<Result<StoreFactoryOutput<TFactory>[]>>;
|
|
11
|
+
protected getStoreLocatorUrl(payload: StoreQueryByProximity): string;
|
|
12
|
+
protected getStoreLocatorParams(payload: StoreQueryByProximity): URLSearchParams;
|
|
13
|
+
}
|
|
@@ -2,16 +2,19 @@ import type { ClientFromCapabilities } from '@reactionary/core';
|
|
|
2
2
|
import type { HclCapabilities } from '../schema/capabilities.schema.js';
|
|
3
3
|
import type { HclCartCapability } from '../capabilities/cart.capability.js';
|
|
4
4
|
import type { HclCheckoutCapability } from '../capabilities/checkout.capability.js';
|
|
5
|
+
import type { HclCompanyCapability } from '../capabilities/company.capability.js';
|
|
5
6
|
import type { HclProductCapability } from '../capabilities/product.capability.js';
|
|
6
7
|
import type { HclCategoryCapability } from '../capabilities/category.capability.js';
|
|
7
8
|
import type { HclProductSearchCapability } from '../capabilities/product-search.capability.js';
|
|
8
9
|
import type { HclPriceCapability } from '../capabilities/price.capability.js';
|
|
9
10
|
import type { HclInventoryCapability } from '../capabilities/inventory.capability.js';
|
|
10
11
|
import type { HclIdentityCapability } from '../capabilities/identity.capability.js';
|
|
12
|
+
import type { HclProductListCapability } from '../capabilities/product-list.capability.js';
|
|
11
13
|
import type { HclProfileCapability } from '../capabilities/profile.capability.js';
|
|
12
14
|
import type { HclOrderCapability } from '../capabilities/order.capability.js';
|
|
13
15
|
import type { HclOrderSearchCapability } from '../capabilities/order-search.capability.js';
|
|
14
|
-
type
|
|
16
|
+
import type { HclStoreCapability } from '../capabilities/store.capability.js';
|
|
17
|
+
type OverridableCapabilityKey = 'product' | 'productSearch' | 'cart' | 'checkout' | 'category' | 'company' | 'price' | 'inventory' | 'identity' | 'productList' | 'profile' | 'order' | 'orderSearch' | 'store';
|
|
15
18
|
type EnabledCapability<TCapability> = TCapability extends {
|
|
16
19
|
enabled: true;
|
|
17
20
|
} ? true : false;
|
|
@@ -28,12 +31,15 @@ type DefaultCapabilityMap = {
|
|
|
28
31
|
cart: HclCartCapability;
|
|
29
32
|
checkout: HclCheckoutCapability;
|
|
30
33
|
category: HclCategoryCapability;
|
|
34
|
+
company: HclCompanyCapability;
|
|
31
35
|
price: HclPriceCapability;
|
|
32
36
|
inventory: HclInventoryCapability;
|
|
33
37
|
identity: HclIdentityCapability;
|
|
38
|
+
productList: HclProductListCapability;
|
|
34
39
|
profile: HclProfileCapability;
|
|
35
40
|
order: HclOrderCapability;
|
|
36
41
|
orderSearch: HclOrderSearchCapability;
|
|
42
|
+
store: HclStoreCapability;
|
|
37
43
|
};
|
|
38
44
|
type CapabilityImplementationMap<T extends HclCapabilities> = {
|
|
39
45
|
[K in OverridableCapabilityKey]: ExtractCapabilityImplementation<T[K], DefaultCapabilityMap[K]>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type * as z from 'zod';
|
|
2
|
+
import type { Address, AnyCompanyPaginatedListSchema, AnyCompanySchema, CompanyFactory, CompanyQueryList, CompanySchema, CompanyPaginatedListSchema, RequestContext } from '@reactionary/core';
|
|
3
|
+
import type { HclOrganizationItem, HclOrganizationListResponse, HclWcsOrgContact } from '../../schema/hcl.schema.js';
|
|
4
|
+
export declare class HclCompanyFactory<TCompanySchema extends AnyCompanySchema = typeof CompanySchema, TCompanyPaginatedListSchema extends AnyCompanyPaginatedListSchema = typeof CompanyPaginatedListSchema> implements CompanyFactory<TCompanySchema, TCompanyPaginatedListSchema> {
|
|
5
|
+
readonly companySchema: TCompanySchema;
|
|
6
|
+
readonly companyPaginatedListSchema: TCompanyPaginatedListSchema;
|
|
7
|
+
constructor(companySchema: TCompanySchema, companyPaginatedListSchema: TCompanyPaginatedListSchema);
|
|
8
|
+
parseCompany(_context: RequestContext, data: HclOrganizationItem): z.output<TCompanySchema>;
|
|
9
|
+
parseCompanyPaginatedList(context: RequestContext, data: HclOrganizationListResponse, _query: CompanyQueryList): z.output<TCompanyPaginatedListSchema>;
|
|
10
|
+
protected parseOrgContact(contact: HclWcsOrgContact, defaultNickName: string): Address;
|
|
11
|
+
}
|