@reactionary/hcl 0.9.12 → 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/analytics.capability.js +98 -0
- package/capabilities/company.capability.js +307 -0
- package/capabilities/personalization-profile.capability.js +85 -0
- package/capabilities/product-associations.capability.js +117 -0
- package/capabilities/product-list.capability.js +665 -0
- package/capabilities/product-recommendations.capability.js +143 -0
- package/capabilities/store.capability.js +72 -0
- package/core/initialize.js +148 -2
- package/factories/company/company.factory.js +77 -0
- package/factories/index.js +6 -0
- package/factories/personalization-profile/personalization-profile.factory.js +16 -0
- package/factories/product-associations/product-associations.factory.js +16 -0
- package/factories/product-list/product-list.factory.js +158 -0
- package/factories/product-recommendations/product-recommendations.factory.js +17 -0
- package/factories/store/store.factory.js +18 -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/company.capability.d.ts +26 -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-list.capability.d.ts +42 -0
- package/src/capabilities/product-recommendations.capability.d.ts +29 -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 +6 -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-list/product-list.factory.d.ts +40 -0
- package/src/factories/product-recommendations/product-recommendations.factory.d.ts +12 -0
- package/src/factories/store/store.factory.d.ts +8 -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 +277 -1
- package/src/test/test-utils.d.ts +4 -1
|
@@ -0,0 +1,665 @@
|
|
|
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
|
+
ProductListCapability,
|
|
14
|
+
ProductListItemMutationCreateSchema,
|
|
15
|
+
ProductListItemMutationDeleteSchema,
|
|
16
|
+
ProductListItemMutationUpdateSchema,
|
|
17
|
+
ProductListItemPaginatedResultsSchema,
|
|
18
|
+
ProductListItemQuerySchema,
|
|
19
|
+
ProductListItemSchema,
|
|
20
|
+
ProductListMutationCreateSchema,
|
|
21
|
+
ProductListMutationDeleteSchema,
|
|
22
|
+
ProductListMutationUpdateSchema,
|
|
23
|
+
ProductListPaginatedResultsSchema,
|
|
24
|
+
ProductListQueryByIdSchema,
|
|
25
|
+
ProductListQuerySchema,
|
|
26
|
+
ProductListSchema,
|
|
27
|
+
Reactionary,
|
|
28
|
+
error,
|
|
29
|
+
success
|
|
30
|
+
} from "@reactionary/core";
|
|
31
|
+
import createDebug from "debug";
|
|
32
|
+
import { encodeWishlistType } from "../factories/product-list/product-list.factory.js";
|
|
33
|
+
const debug = createDebug("reactionary:hcl:product-list");
|
|
34
|
+
function isRequisitionList(listType) {
|
|
35
|
+
return listType === "requisition";
|
|
36
|
+
}
|
|
37
|
+
class HclProductListCapability extends ProductListCapability {
|
|
38
|
+
config;
|
|
39
|
+
client;
|
|
40
|
+
factory;
|
|
41
|
+
constructor(cache, context, config, client, factory) {
|
|
42
|
+
super(cache, context);
|
|
43
|
+
this.config = config;
|
|
44
|
+
this.client = client;
|
|
45
|
+
this.factory = factory;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Returns the factory cast to include the HCL-specific requisition list parse methods.
|
|
49
|
+
* Subclasses can override this if they provide a custom factory.
|
|
50
|
+
*/
|
|
51
|
+
get requisitionFactory() {
|
|
52
|
+
return this.factory;
|
|
53
|
+
}
|
|
54
|
+
async getById(payload) {
|
|
55
|
+
debug(
|
|
56
|
+
"getById %s (type=%s)",
|
|
57
|
+
payload.identifier.key,
|
|
58
|
+
payload.identifier.listType
|
|
59
|
+
);
|
|
60
|
+
const itemsQuery = {
|
|
61
|
+
search: {
|
|
62
|
+
list: payload.identifier,
|
|
63
|
+
paginationOptions: { pageSize: 100, pageNumber: 1 }
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
let wishlist;
|
|
67
|
+
if (isRequisitionList(payload.identifier.listType)) {
|
|
68
|
+
const response = await this.client.callGet(
|
|
69
|
+
this.getRequisitionListItemsUrl(payload.identifier.key),
|
|
70
|
+
this.getRequisitionListItemsParams(itemsQuery),
|
|
71
|
+
{ allowUndefined: true }
|
|
72
|
+
);
|
|
73
|
+
const raw = response?.resultList?.[0];
|
|
74
|
+
if (!raw)
|
|
75
|
+
return error({
|
|
76
|
+
type: "NotFound",
|
|
77
|
+
identifier: payload.identifier
|
|
78
|
+
});
|
|
79
|
+
return success(
|
|
80
|
+
this.requisitionFactory.parseRequisitionList(
|
|
81
|
+
this.context,
|
|
82
|
+
raw
|
|
83
|
+
)
|
|
84
|
+
);
|
|
85
|
+
} else {
|
|
86
|
+
const response = await this.client.callGet(
|
|
87
|
+
this.getWishlistItemsUrl(payload.identifier.key),
|
|
88
|
+
this.getWishlistItemsParams(itemsQuery),
|
|
89
|
+
{ allowUndefined: true }
|
|
90
|
+
);
|
|
91
|
+
wishlist = response?.GiftList?.[0];
|
|
92
|
+
}
|
|
93
|
+
if (!wishlist) {
|
|
94
|
+
return error({
|
|
95
|
+
type: "NotFound",
|
|
96
|
+
identifier: payload.identifier
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return success(this.factory.parseProductList(this.context, wishlist));
|
|
100
|
+
}
|
|
101
|
+
async queryLists(query) {
|
|
102
|
+
debug("queryLists listType=%s", query.search.listType);
|
|
103
|
+
if (isRequisitionList(query.search.listType)) {
|
|
104
|
+
const response2 = await this.client.callGet(
|
|
105
|
+
this.getRequisitionListsUrl(),
|
|
106
|
+
void 0,
|
|
107
|
+
{ allowUndefined: true }
|
|
108
|
+
);
|
|
109
|
+
return success(
|
|
110
|
+
this.requisitionFactory.parseRequisitionListPaginatedResult(
|
|
111
|
+
this.context,
|
|
112
|
+
response2 ?? {},
|
|
113
|
+
query
|
|
114
|
+
)
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
const response = await this.client.callGet(
|
|
118
|
+
this.getWishlistsUrl(),
|
|
119
|
+
void 0,
|
|
120
|
+
{ allowUndefined: true }
|
|
121
|
+
);
|
|
122
|
+
const data = {
|
|
123
|
+
GiftList: response?.GiftList ?? [],
|
|
124
|
+
recordSetTotal: response?.recordSetTotal ?? "0"
|
|
125
|
+
};
|
|
126
|
+
return success(
|
|
127
|
+
this.factory.parseProductListPaginatedResult(this.context, data, query)
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
async addList(mutation) {
|
|
131
|
+
debug("addList name=%s type=%s", mutation.list.name, mutation.list.type);
|
|
132
|
+
let listId;
|
|
133
|
+
if (isRequisitionList(mutation.list.type)) {
|
|
134
|
+
const response = await this.client.callPost(
|
|
135
|
+
this.getRequisitionListsUrl(),
|
|
136
|
+
this.getCreateRequisitionListBody(mutation)
|
|
137
|
+
);
|
|
138
|
+
listId = response.requisitionListId ?? "";
|
|
139
|
+
const fetchedResponse = await this.client.callGet(
|
|
140
|
+
this.getRequisitionListItemsUrl(listId),
|
|
141
|
+
this.getRequisitionListItemsParams({
|
|
142
|
+
search: {
|
|
143
|
+
list: { key: listId, listType: mutation.list.type },
|
|
144
|
+
paginationOptions: { pageSize: 1, pageNumber: 1 }
|
|
145
|
+
}
|
|
146
|
+
}),
|
|
147
|
+
{ allowUndefined: true }
|
|
148
|
+
);
|
|
149
|
+
const raw = fetchedResponse?.resultList?.[0] ?? {
|
|
150
|
+
requisitionListId: listId,
|
|
151
|
+
name: mutation.list.name,
|
|
152
|
+
description: mutation.list.description
|
|
153
|
+
};
|
|
154
|
+
return success(
|
|
155
|
+
this.requisitionFactory.parseRequisitionList(
|
|
156
|
+
this.context,
|
|
157
|
+
raw
|
|
158
|
+
)
|
|
159
|
+
);
|
|
160
|
+
} else {
|
|
161
|
+
const response = await this.client.callPost(
|
|
162
|
+
this.getWishlistsUrl(),
|
|
163
|
+
this.getCreateWishlistBody(mutation)
|
|
164
|
+
);
|
|
165
|
+
listId = response.uniqueID ?? response.externalIdentifier ?? "";
|
|
166
|
+
const fetchedResponse = await this.client.callGet(
|
|
167
|
+
this.getWishlistItemsUrl(listId),
|
|
168
|
+
this.getWishlistItemsParams({
|
|
169
|
+
search: {
|
|
170
|
+
list: { key: listId, listType: mutation.list.type },
|
|
171
|
+
paginationOptions: { pageSize: 1, pageNumber: 1 }
|
|
172
|
+
}
|
|
173
|
+
}),
|
|
174
|
+
{ allowUndefined: true }
|
|
175
|
+
);
|
|
176
|
+
const wishlist = fetchedResponse?.GiftList?.[0] ?? {
|
|
177
|
+
uniqueID: listId,
|
|
178
|
+
externalIdentifier: response.externalIdentifier,
|
|
179
|
+
descriptionName: mutation.list.name,
|
|
180
|
+
description: encodeWishlistType(
|
|
181
|
+
mutation.list.type,
|
|
182
|
+
mutation.list.description
|
|
183
|
+
)
|
|
184
|
+
};
|
|
185
|
+
return success(this.factory.parseProductList(this.context, wishlist));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
async updateList(mutation) {
|
|
189
|
+
debug("updateList %s (type=%s)", mutation.list.key, mutation.list.listType);
|
|
190
|
+
const itemsQuery = {
|
|
191
|
+
search: {
|
|
192
|
+
list: mutation.list,
|
|
193
|
+
paginationOptions: { pageSize: 1, pageNumber: 1 }
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
if (isRequisitionList(mutation.list.listType)) {
|
|
197
|
+
await this.client.callPut(
|
|
198
|
+
this.getRequisitionListUrl(mutation.list.key),
|
|
199
|
+
this.getUpdateRequisitionListBody(mutation)
|
|
200
|
+
);
|
|
201
|
+
const response = await this.client.callGet(
|
|
202
|
+
this.getRequisitionListItemsUrl(mutation.list.key),
|
|
203
|
+
this.getRequisitionListItemsParams(itemsQuery),
|
|
204
|
+
{ allowUndefined: true }
|
|
205
|
+
);
|
|
206
|
+
const raw = response?.resultList?.[0];
|
|
207
|
+
if (!raw)
|
|
208
|
+
return error({
|
|
209
|
+
type: "NotFound",
|
|
210
|
+
identifier: mutation.list
|
|
211
|
+
});
|
|
212
|
+
return success(
|
|
213
|
+
this.requisitionFactory.parseRequisitionList(
|
|
214
|
+
this.context,
|
|
215
|
+
raw
|
|
216
|
+
)
|
|
217
|
+
);
|
|
218
|
+
} else {
|
|
219
|
+
await this.client.callPut(
|
|
220
|
+
this.getWishlistUrl(mutation.list.key),
|
|
221
|
+
this.getUpdateWishlistBody(mutation)
|
|
222
|
+
);
|
|
223
|
+
const response = await this.client.callGet(
|
|
224
|
+
this.getWishlistItemsUrl(mutation.list.key),
|
|
225
|
+
this.getWishlistItemsParams(itemsQuery),
|
|
226
|
+
{ allowUndefined: true }
|
|
227
|
+
);
|
|
228
|
+
if (!response?.GiftList?.[0])
|
|
229
|
+
return error({
|
|
230
|
+
type: "NotFound",
|
|
231
|
+
identifier: mutation.list
|
|
232
|
+
});
|
|
233
|
+
return success(
|
|
234
|
+
this.factory.parseProductList(this.context, response.GiftList[0])
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
async deleteList(mutation) {
|
|
239
|
+
debug("deleteList %s (type=%s)", mutation.list.key, mutation.list.listType);
|
|
240
|
+
if (isRequisitionList(mutation.list.listType)) {
|
|
241
|
+
await this.client.callDelete(
|
|
242
|
+
this.getRequisitionListUrl(mutation.list.key),
|
|
243
|
+
{ ignore404: false }
|
|
244
|
+
);
|
|
245
|
+
} else {
|
|
246
|
+
await this.client.callDelete(this.getWishlistUrl(mutation.list.key), {
|
|
247
|
+
ignore404: false
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
return success(void 0);
|
|
251
|
+
}
|
|
252
|
+
async queryListItems(query) {
|
|
253
|
+
debug(
|
|
254
|
+
"queryListItems list=%s (type=%s)",
|
|
255
|
+
query.search.list.key,
|
|
256
|
+
query.search.list.listType
|
|
257
|
+
);
|
|
258
|
+
if (isRequisitionList(query.search.list.listType)) {
|
|
259
|
+
const response = await this.client.callGet(
|
|
260
|
+
this.getRequisitionListItemsUrl(query.search.list.key),
|
|
261
|
+
this.getRequisitionListItemsParams(query),
|
|
262
|
+
{ allowUndefined: true }
|
|
263
|
+
);
|
|
264
|
+
return success(
|
|
265
|
+
this.requisitionFactory.parseRequisitionListItemPaginatedResult(
|
|
266
|
+
this.context,
|
|
267
|
+
response ?? {},
|
|
268
|
+
query
|
|
269
|
+
)
|
|
270
|
+
);
|
|
271
|
+
} else {
|
|
272
|
+
const response = await this.client.callGet(
|
|
273
|
+
this.getWishlistItemsUrl(query.search.list.key),
|
|
274
|
+
this.getWishlistItemsParams(query),
|
|
275
|
+
{ allowUndefined: true }
|
|
276
|
+
);
|
|
277
|
+
const data = response ?? {
|
|
278
|
+
GiftList: [],
|
|
279
|
+
recordSetTotal: "0"
|
|
280
|
+
};
|
|
281
|
+
return success(
|
|
282
|
+
this.factory.parseProductListItemPaginatedResult(
|
|
283
|
+
this.context,
|
|
284
|
+
data,
|
|
285
|
+
query
|
|
286
|
+
)
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
async addItem(mutation) {
|
|
291
|
+
debug(
|
|
292
|
+
"addItem list=%s sku=%s",
|
|
293
|
+
mutation.list.key,
|
|
294
|
+
mutation.listItem.variant.sku
|
|
295
|
+
);
|
|
296
|
+
if (isRequisitionList(mutation.list.listType)) {
|
|
297
|
+
const params = this.getRequisitionAddItemParams();
|
|
298
|
+
const url = `${this.getRequisitionListUrl(mutation.list.key)}?${params.toString()}`;
|
|
299
|
+
await this.client.callPut(
|
|
300
|
+
url,
|
|
301
|
+
this.getRequisitionAddItemBody(mutation)
|
|
302
|
+
);
|
|
303
|
+
const response = await this.client.callGet(
|
|
304
|
+
this.getRequisitionListItemsUrl(mutation.list.key),
|
|
305
|
+
this.getRequisitionListItemsParams({
|
|
306
|
+
search: {
|
|
307
|
+
list: mutation.list,
|
|
308
|
+
paginationOptions: { pageSize: 100, pageNumber: 1 }
|
|
309
|
+
}
|
|
310
|
+
}),
|
|
311
|
+
{ allowUndefined: true }
|
|
312
|
+
);
|
|
313
|
+
const sku = mutation.listItem.variant.sku;
|
|
314
|
+
const raw = response?.resultList?.[0]?.item?.find(
|
|
315
|
+
(i) => i.productId === sku || i.partNumber === sku
|
|
316
|
+
);
|
|
317
|
+
if (!raw)
|
|
318
|
+
return error({
|
|
319
|
+
type: "NotFound",
|
|
320
|
+
identifier: { key: sku, list: mutation.list }
|
|
321
|
+
});
|
|
322
|
+
const input = {
|
|
323
|
+
item: raw,
|
|
324
|
+
list: mutation.list
|
|
325
|
+
};
|
|
326
|
+
return success(
|
|
327
|
+
this.requisitionFactory.parseRequisitionListItem(
|
|
328
|
+
this.context,
|
|
329
|
+
input
|
|
330
|
+
)
|
|
331
|
+
);
|
|
332
|
+
} else {
|
|
333
|
+
const params = this.getAddItemParams();
|
|
334
|
+
const url = `${this.getWishlistUrl(mutation.list.key)}?${params.toString()}`;
|
|
335
|
+
await this.client.callPut(
|
|
336
|
+
url,
|
|
337
|
+
this.getAddItemBody(mutation)
|
|
338
|
+
);
|
|
339
|
+
const listResponse = await this.client.callGet(
|
|
340
|
+
this.getWishlistItemsUrl(mutation.list.key),
|
|
341
|
+
this.getWishlistItemsParams({
|
|
342
|
+
search: {
|
|
343
|
+
list: mutation.list,
|
|
344
|
+
paginationOptions: { pageSize: 100, pageNumber: 1 }
|
|
345
|
+
}
|
|
346
|
+
}),
|
|
347
|
+
{ allowUndefined: true }
|
|
348
|
+
);
|
|
349
|
+
const sku = mutation.listItem.variant.sku;
|
|
350
|
+
const item = listResponse?.GiftList?.[0]?.item?.find(
|
|
351
|
+
(i) => i.productId === sku || i.partNumber === sku
|
|
352
|
+
);
|
|
353
|
+
if (!item)
|
|
354
|
+
return error({
|
|
355
|
+
type: "NotFound",
|
|
356
|
+
identifier: { key: sku, list: mutation.list }
|
|
357
|
+
});
|
|
358
|
+
const input = { item, list: mutation.list };
|
|
359
|
+
return success(this.factory.parseProductListItem(this.context, input));
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
async updateItem(mutation) {
|
|
363
|
+
debug(
|
|
364
|
+
"updateItem list=%s item=%s",
|
|
365
|
+
mutation.listItem.list.key,
|
|
366
|
+
mutation.listItem.key
|
|
367
|
+
);
|
|
368
|
+
const listType = mutation.listItem.list.listType;
|
|
369
|
+
const listId = mutation.listItem.list.key;
|
|
370
|
+
const fetchQuery = {
|
|
371
|
+
search: {
|
|
372
|
+
list: mutation.listItem.list,
|
|
373
|
+
paginationOptions: { pageSize: 100, pageNumber: 1 }
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
if (isRequisitionList(listType)) {
|
|
377
|
+
const response = await this.client.callGet(
|
|
378
|
+
this.getRequisitionListItemsUrl(listId),
|
|
379
|
+
this.getRequisitionListItemsParams(fetchQuery),
|
|
380
|
+
{ allowUndefined: true }
|
|
381
|
+
);
|
|
382
|
+
const existing = response?.resultList?.[0]?.item?.find(
|
|
383
|
+
(i) => i.requisitionListItemId === mutation.listItem.key
|
|
384
|
+
);
|
|
385
|
+
if (!existing)
|
|
386
|
+
return error({
|
|
387
|
+
type: "NotFound",
|
|
388
|
+
identifier: mutation.listItem
|
|
389
|
+
});
|
|
390
|
+
const params = this.getRequisitionAddItemParams();
|
|
391
|
+
const url = `${this.getRequisitionListUrl(listId)}?${params.toString()}`;
|
|
392
|
+
await this.client.callPut(url, {
|
|
393
|
+
item: [
|
|
394
|
+
{
|
|
395
|
+
location: "online",
|
|
396
|
+
productId: existing.productId ?? existing.partNumber,
|
|
397
|
+
quantity: String(
|
|
398
|
+
mutation.quantity ?? Number(existing.quantity ?? 1)
|
|
399
|
+
)
|
|
400
|
+
}
|
|
401
|
+
]
|
|
402
|
+
});
|
|
403
|
+
const updated = await this.client.callGet(
|
|
404
|
+
this.getRequisitionListItemsUrl(listId),
|
|
405
|
+
this.getRequisitionListItemsParams(fetchQuery),
|
|
406
|
+
{ allowUndefined: true }
|
|
407
|
+
);
|
|
408
|
+
const updatedRaw = updated?.resultList?.[0]?.item?.find(
|
|
409
|
+
(i) => i.requisitionListItemId === mutation.listItem.key
|
|
410
|
+
);
|
|
411
|
+
if (!updatedRaw)
|
|
412
|
+
return error({
|
|
413
|
+
type: "NotFound",
|
|
414
|
+
identifier: mutation.listItem
|
|
415
|
+
});
|
|
416
|
+
const input = {
|
|
417
|
+
item: updatedRaw,
|
|
418
|
+
list: mutation.listItem.list
|
|
419
|
+
};
|
|
420
|
+
return success(
|
|
421
|
+
this.requisitionFactory.parseRequisitionListItem(
|
|
422
|
+
this.context,
|
|
423
|
+
input
|
|
424
|
+
)
|
|
425
|
+
);
|
|
426
|
+
} else {
|
|
427
|
+
const listResponse = await this.client.callGet(
|
|
428
|
+
this.getWishlistItemsUrl(listId),
|
|
429
|
+
this.getWishlistItemsParams(fetchQuery),
|
|
430
|
+
{ allowUndefined: true }
|
|
431
|
+
);
|
|
432
|
+
const existing = listResponse?.GiftList?.[0]?.item?.find(
|
|
433
|
+
(i) => i.giftListItemID === mutation.listItem.key
|
|
434
|
+
);
|
|
435
|
+
if (!existing)
|
|
436
|
+
return error({
|
|
437
|
+
type: "NotFound",
|
|
438
|
+
identifier: mutation.listItem
|
|
439
|
+
});
|
|
440
|
+
const params = this.getAddItemParams();
|
|
441
|
+
const url = `${this.getWishlistUrl(listId)}?${params.toString()}`;
|
|
442
|
+
await this.client.callPut(url, {
|
|
443
|
+
item: [
|
|
444
|
+
{
|
|
445
|
+
location: "online",
|
|
446
|
+
productId: existing.productId ?? existing.partNumber,
|
|
447
|
+
quantityRequested: String(
|
|
448
|
+
mutation.quantity ?? Number(existing.quantityRequested ?? 1)
|
|
449
|
+
)
|
|
450
|
+
}
|
|
451
|
+
]
|
|
452
|
+
});
|
|
453
|
+
const updated = await this.client.callGet(
|
|
454
|
+
this.getWishlistItemsUrl(listId),
|
|
455
|
+
this.getWishlistItemsParams(fetchQuery),
|
|
456
|
+
{ allowUndefined: true }
|
|
457
|
+
);
|
|
458
|
+
const updatedItem = updated?.GiftList?.[0]?.item?.find(
|
|
459
|
+
(i) => i.giftListItemID === mutation.listItem.key
|
|
460
|
+
);
|
|
461
|
+
if (!updatedItem)
|
|
462
|
+
return error({
|
|
463
|
+
type: "NotFound",
|
|
464
|
+
identifier: mutation.listItem
|
|
465
|
+
});
|
|
466
|
+
const input = {
|
|
467
|
+
item: updatedItem,
|
|
468
|
+
list: mutation.listItem.list
|
|
469
|
+
};
|
|
470
|
+
return success(this.factory.parseProductListItem(this.context, input));
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
async deleteItem(mutation) {
|
|
474
|
+
debug(
|
|
475
|
+
"deleteItem list=%s item=%s",
|
|
476
|
+
mutation.listItem.list.key,
|
|
477
|
+
mutation.listItem.key
|
|
478
|
+
);
|
|
479
|
+
if (isRequisitionList(mutation.listItem.list.listType)) {
|
|
480
|
+
await this.client.callDelete(
|
|
481
|
+
this.getRequisitionListItemUrl(
|
|
482
|
+
mutation.listItem.list.key,
|
|
483
|
+
mutation.listItem.key
|
|
484
|
+
),
|
|
485
|
+
{ ignore404: true }
|
|
486
|
+
);
|
|
487
|
+
} else {
|
|
488
|
+
await this.client.callDelete(
|
|
489
|
+
this.getWishlistItemUrl(
|
|
490
|
+
mutation.listItem.list.key,
|
|
491
|
+
mutation.listItem.key
|
|
492
|
+
),
|
|
493
|
+
{ ignore404: true }
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
return success(void 0);
|
|
497
|
+
}
|
|
498
|
+
// ---------------------------------------------------------------------------
|
|
499
|
+
// Extension points — wishlist (non-requisition)
|
|
500
|
+
// ---------------------------------------------------------------------------
|
|
501
|
+
getWishlistsUrl() {
|
|
502
|
+
return `${this.client.transactionBaseUrl}/wishlist`;
|
|
503
|
+
}
|
|
504
|
+
getWishlistUrl(listId) {
|
|
505
|
+
return `${this.client.transactionBaseUrl}/wishlist/${encodeURIComponent(listId)}`;
|
|
506
|
+
}
|
|
507
|
+
getWishlistItemsUrl(listId) {
|
|
508
|
+
return `${this.client.transactionBaseUrl}/wishlist/${encodeURIComponent(listId)}/item`;
|
|
509
|
+
}
|
|
510
|
+
getWishlistItemUrl(listId, itemId) {
|
|
511
|
+
return `${this.client.transactionBaseUrl}/wishlist/${encodeURIComponent(listId)}/item/${encodeURIComponent(itemId)}`;
|
|
512
|
+
}
|
|
513
|
+
getWishlistItemsParams(query) {
|
|
514
|
+
const params = new URLSearchParams();
|
|
515
|
+
params.set("pageNumber", String(query.search.paginationOptions.pageNumber));
|
|
516
|
+
params.set("pageSize", String(query.search.paginationOptions.pageSize));
|
|
517
|
+
return params;
|
|
518
|
+
}
|
|
519
|
+
getCreateWishlistBody(mutation) {
|
|
520
|
+
return {
|
|
521
|
+
descriptionName: mutation.list.name,
|
|
522
|
+
// Encode the listType into description so it can be read back on query.
|
|
523
|
+
description: encodeWishlistType(
|
|
524
|
+
mutation.list.type,
|
|
525
|
+
mutation.list.description
|
|
526
|
+
),
|
|
527
|
+
giftCardAccepted: "false",
|
|
528
|
+
accessSpecifier: "Private"
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
getUpdateWishlistBody(mutation) {
|
|
532
|
+
const body = {};
|
|
533
|
+
if (mutation.name !== void 0)
|
|
534
|
+
body["descriptionName"] = mutation.name;
|
|
535
|
+
if (mutation.description !== void 0) {
|
|
536
|
+
body["description"] = encodeWishlistType(
|
|
537
|
+
mutation.list.listType,
|
|
538
|
+
mutation.description
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
return body;
|
|
542
|
+
}
|
|
543
|
+
getAddItemParams() {
|
|
544
|
+
const params = new URLSearchParams();
|
|
545
|
+
params.set("addItem", "true");
|
|
546
|
+
return params;
|
|
547
|
+
}
|
|
548
|
+
getAddItemBody(mutation) {
|
|
549
|
+
return {
|
|
550
|
+
item: [
|
|
551
|
+
{
|
|
552
|
+
location: "online",
|
|
553
|
+
productId: mutation.listItem.variant.sku,
|
|
554
|
+
quantityRequested: String(mutation.listItem.quantity ?? 1)
|
|
555
|
+
}
|
|
556
|
+
]
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
// ---------------------------------------------------------------------------
|
|
560
|
+
// Extension points — requisition list
|
|
561
|
+
// ---------------------------------------------------------------------------
|
|
562
|
+
getRequisitionListsUrl() {
|
|
563
|
+
return `${this.client.transactionBaseUrl}/requisitionList`;
|
|
564
|
+
}
|
|
565
|
+
getRequisitionListUrl(listId) {
|
|
566
|
+
return `${this.client.transactionBaseUrl}/requisitionList/${encodeURIComponent(listId)}`;
|
|
567
|
+
}
|
|
568
|
+
getRequisitionListItemsUrl(listId) {
|
|
569
|
+
return `${this.client.transactionBaseUrl}/requisitionList/${encodeURIComponent(listId)}`;
|
|
570
|
+
}
|
|
571
|
+
getRequisitionListItemUrl(listId, itemId) {
|
|
572
|
+
return `${this.client.transactionBaseUrl}/requisitionList/${encodeURIComponent(listId)}/requisitionListItem/${encodeURIComponent(itemId)}`;
|
|
573
|
+
}
|
|
574
|
+
getRequisitionListItemsParams(query) {
|
|
575
|
+
const params = new URLSearchParams();
|
|
576
|
+
params.set("pageNumber", String(query.search.paginationOptions.pageNumber));
|
|
577
|
+
params.set("pageSize", String(query.search.paginationOptions.pageSize));
|
|
578
|
+
return params;
|
|
579
|
+
}
|
|
580
|
+
getCreateRequisitionListBody(mutation) {
|
|
581
|
+
return {
|
|
582
|
+
name: mutation.list.name,
|
|
583
|
+
description: mutation.list.description ?? ""
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
getUpdateRequisitionListBody(mutation) {
|
|
587
|
+
const body = {};
|
|
588
|
+
if (mutation.name !== void 0)
|
|
589
|
+
body["name"] = mutation.name;
|
|
590
|
+
if (mutation.description !== void 0)
|
|
591
|
+
body["description"] = mutation.description;
|
|
592
|
+
return body;
|
|
593
|
+
}
|
|
594
|
+
getRequisitionAddItemParams() {
|
|
595
|
+
const params = new URLSearchParams();
|
|
596
|
+
params.set("addItem", "true");
|
|
597
|
+
return params;
|
|
598
|
+
}
|
|
599
|
+
getRequisitionAddItemBody(mutation) {
|
|
600
|
+
return {
|
|
601
|
+
item: [
|
|
602
|
+
{
|
|
603
|
+
location: "online",
|
|
604
|
+
productId: mutation.listItem.variant.sku,
|
|
605
|
+
quantity: String(mutation.listItem.quantity ?? 1)
|
|
606
|
+
}
|
|
607
|
+
]
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
__decorateClass([
|
|
612
|
+
Reactionary({
|
|
613
|
+
inputSchema: ProductListQueryByIdSchema,
|
|
614
|
+
outputSchema: ProductListSchema
|
|
615
|
+
})
|
|
616
|
+
], HclProductListCapability.prototype, "getById", 1);
|
|
617
|
+
__decorateClass([
|
|
618
|
+
Reactionary({
|
|
619
|
+
inputSchema: ProductListQuerySchema,
|
|
620
|
+
outputSchema: ProductListPaginatedResultsSchema
|
|
621
|
+
})
|
|
622
|
+
], HclProductListCapability.prototype, "queryLists", 1);
|
|
623
|
+
__decorateClass([
|
|
624
|
+
Reactionary({
|
|
625
|
+
inputSchema: ProductListMutationCreateSchema,
|
|
626
|
+
outputSchema: ProductListSchema
|
|
627
|
+
})
|
|
628
|
+
], HclProductListCapability.prototype, "addList", 1);
|
|
629
|
+
__decorateClass([
|
|
630
|
+
Reactionary({
|
|
631
|
+
inputSchema: ProductListMutationUpdateSchema,
|
|
632
|
+
outputSchema: ProductListSchema
|
|
633
|
+
})
|
|
634
|
+
], HclProductListCapability.prototype, "updateList", 1);
|
|
635
|
+
__decorateClass([
|
|
636
|
+
Reactionary({
|
|
637
|
+
inputSchema: ProductListMutationDeleteSchema
|
|
638
|
+
})
|
|
639
|
+
], HclProductListCapability.prototype, "deleteList", 1);
|
|
640
|
+
__decorateClass([
|
|
641
|
+
Reactionary({
|
|
642
|
+
inputSchema: ProductListItemQuerySchema,
|
|
643
|
+
outputSchema: ProductListItemPaginatedResultsSchema
|
|
644
|
+
})
|
|
645
|
+
], HclProductListCapability.prototype, "queryListItems", 1);
|
|
646
|
+
__decorateClass([
|
|
647
|
+
Reactionary({
|
|
648
|
+
inputSchema: ProductListItemMutationCreateSchema,
|
|
649
|
+
outputSchema: ProductListItemSchema
|
|
650
|
+
})
|
|
651
|
+
], HclProductListCapability.prototype, "addItem", 1);
|
|
652
|
+
__decorateClass([
|
|
653
|
+
Reactionary({
|
|
654
|
+
inputSchema: ProductListItemMutationUpdateSchema,
|
|
655
|
+
outputSchema: ProductListItemSchema
|
|
656
|
+
})
|
|
657
|
+
], HclProductListCapability.prototype, "updateItem", 1);
|
|
658
|
+
__decorateClass([
|
|
659
|
+
Reactionary({
|
|
660
|
+
inputSchema: ProductListItemMutationDeleteSchema
|
|
661
|
+
})
|
|
662
|
+
], HclProductListCapability.prototype, "deleteItem", 1);
|
|
663
|
+
export {
|
|
664
|
+
HclProductListCapability
|
|
665
|
+
};
|