@reactionary/hcl 0.9.8 → 0.9.11

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.
Files changed (43) hide show
  1. package/capabilities/cart.capability.js +411 -0
  2. package/capabilities/category.capability.js +111 -35
  3. package/capabilities/checkout.capability.js +337 -0
  4. package/capabilities/identity.capability.js +214 -0
  5. package/capabilities/inventory.capability.js +75 -0
  6. package/capabilities/price.capability.js +122 -0
  7. package/capabilities/product-search.capability.js +64 -13
  8. package/capabilities/product.capability.js +114 -28
  9. package/core/client.js +81 -90
  10. package/core/initialize.js +111 -5
  11. package/core/session-keys.js +14 -0
  12. package/factories/cart/cart.factory.js +135 -0
  13. package/factories/checkout/checkout.factory.js +131 -0
  14. package/factories/identity/identity.factory.js +12 -0
  15. package/factories/index.js +5 -0
  16. package/factories/inventory/inventory.factory.js +38 -0
  17. package/factories/price/price.factory.js +39 -0
  18. package/index.js +5 -0
  19. package/package.json +8 -5
  20. package/schema/capabilities.schema.js +2 -0
  21. package/schema/configuration.schema.js +9 -1
  22. package/src/capabilities/cart.capability.d.ts +69 -0
  23. package/src/capabilities/category.capability.d.ts +20 -1
  24. package/src/capabilities/checkout.capability.d.ts +41 -0
  25. package/src/capabilities/identity.capability.d.ts +29 -0
  26. package/src/capabilities/inventory.capability.d.ts +13 -0
  27. package/src/capabilities/price.capability.d.ts +16 -0
  28. package/src/capabilities/product-search.capability.d.ts +7 -2
  29. package/src/capabilities/product.capability.d.ts +14 -2
  30. package/src/core/client.d.ts +41 -14
  31. package/src/core/initialize.types.d.ts +11 -5
  32. package/src/core/session-keys.d.ts +14 -0
  33. package/src/factories/cart/cart.factory.d.ts +11 -0
  34. package/src/factories/checkout/checkout.factory.d.ts +11 -0
  35. package/src/factories/identity/identity.factory.d.ts +7 -0
  36. package/src/factories/index.d.ts +5 -0
  37. package/src/factories/inventory/inventory.factory.d.ts +29 -0
  38. package/src/factories/price/price.factory.d.ts +26 -0
  39. package/src/index.d.ts +5 -0
  40. package/src/schema/capabilities.schema.d.ts +7 -1
  41. package/src/schema/configuration.schema.d.ts +6 -0
  42. package/src/schema/hcl.schema.d.ts +321 -0
  43. package/src/test/test-utils.d.ts +2 -1
@@ -0,0 +1,411 @@
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
+ CartCapability,
14
+ CartIdentifierSchema,
15
+ CartMutationApplyCouponSchema,
16
+ CartMutationChangeCurrencySchema,
17
+ CartMutationCreateCartSchema,
18
+ CartMutationDeleteCartSchema,
19
+ CartMutationItemAddSchema,
20
+ CartMutationItemQuantityChangeSchema,
21
+ CartMutationItemRemoveSchema,
22
+ CartMutationRemoveCouponSchema,
23
+ CartMutationRenameCartSchema,
24
+ CartPaginatedSearchResultSchema,
25
+ CartQueryByIdSchema,
26
+ CartQueryListSchema,
27
+ CartSchema,
28
+ Reactionary,
29
+ error,
30
+ success
31
+ } from "@reactionary/core";
32
+ import createDebug from "debug";
33
+ import { HclCartNotFoundError } from "../core/client.js";
34
+ const debug = createDebug("reactionary:hcl:cart");
35
+ class HclCartCapability extends CartCapability {
36
+ config;
37
+ client;
38
+ factory;
39
+ constructor(cache, context, config, client, factory) {
40
+ super(cache, context);
41
+ this.config = config;
42
+ this.client = client;
43
+ this.factory = factory;
44
+ }
45
+ setPendingOrderUrl(orderId) {
46
+ return `${this.client.transactionBaseUrl}/cart/${encodeURIComponent(orderId)}/set_pending_order`;
47
+ }
48
+ setPendingOrderPayload(orderId) {
49
+ return { orderId };
50
+ }
51
+ /**
52
+ * Set the specified order as the current pending (@self) order.
53
+ * After this call, @self endpoints will operate on that orderId.
54
+ */
55
+ async fetchSetPendingOrder(orderId) {
56
+ await this.client.callPost(
57
+ this.setPendingOrderUrl(orderId),
58
+ this.setPendingOrderPayload(orderId)
59
+ );
60
+ }
61
+ wcsOrderUrl(orderId) {
62
+ return `${this.client.transactionBaseUrl}/order/${encodeURIComponent(orderId)}`;
63
+ }
64
+ /**
65
+ * Fetch a specific order by ID directly from the Order API.
66
+ * Does NOT call set_pending_order — safe to use for read-only access.
67
+ * Throws HclCartNotFoundError on 404.
68
+ */
69
+ async fetchWcsOrder(orderId) {
70
+ const data = await this.client.callGet(
71
+ this.wcsOrderUrl(orderId),
72
+ void 0,
73
+ { allowUndefined: true }
74
+ );
75
+ if (!data)
76
+ throw new HclCartNotFoundError();
77
+ return data;
78
+ }
79
+ cartUrl() {
80
+ return `${this.client.transactionBaseUrl}/cart/@self`;
81
+ }
82
+ /**
83
+ * Fetch the raw WCS cart response.
84
+ * If orderId is provided, uses GET /order/{orderId} directly (no side effects).
85
+ * Without orderId, falls back to GET /cart/@self (current pending order).
86
+ * Throws HclCartNotFoundError on 404.
87
+ */
88
+ async fetchWcsCart(orderId) {
89
+ if (orderId) {
90
+ return this.fetchWcsOrder(orderId);
91
+ }
92
+ const data = await this.client.callGet(
93
+ this.cartUrl(),
94
+ void 0,
95
+ { allowUndefined: true }
96
+ );
97
+ if (!data)
98
+ throw new HclCartNotFoundError();
99
+ return data;
100
+ }
101
+ /** Fetch and parse the current cart via the factory. */
102
+ async fetchCart(orderId) {
103
+ const data = await this.fetchWcsCart(orderId);
104
+ return this.factory.parseCart(this.context, data);
105
+ }
106
+ addOrderItemUrl(currency) {
107
+ const qs = currency ? `?currency=${encodeURIComponent(currency)}` : "";
108
+ return `${this.client.transactionBaseUrl}/cart${qs}`;
109
+ }
110
+ addOrderItemPayload(partNumber, quantity) {
111
+ return {
112
+ orderItem: [{ partNumber, quantity: String(quantity) }],
113
+ x_calculateOrder: "1",
114
+ x_calculationUsage: "-1,-2,-3,-4,-5,-6,-7"
115
+ };
116
+ }
117
+ updateOrderItemUrl() {
118
+ return `${this.client.transactionBaseUrl}/cart/@self/update_order_item`;
119
+ }
120
+ updateOrderItemPayload(orderItemId, quantity) {
121
+ return {
122
+ orderItem: [{ orderItemId, quantity: String(quantity) }],
123
+ x_calculateOrder: "1",
124
+ x_calculationUsage: "-1,-2,-3,-4,-5,-6,-7"
125
+ };
126
+ }
127
+ deleteOrderItemUrl() {
128
+ return `${this.client.transactionBaseUrl}/cart/@self/delete_order_item`;
129
+ }
130
+ deleteOrderItemPayload(orderItemId) {
131
+ return {
132
+ orderItemId,
133
+ x_calculateOrder: "1",
134
+ x_calculationUsage: "-1,-2,-3,-4,-5,-6,-7"
135
+ };
136
+ }
137
+ deleteCartUrl(orderId) {
138
+ return orderId ? `${this.client.transactionBaseUrl}/cart/${encodeURIComponent(orderId)}/cancel_order` : `${this.client.transactionBaseUrl}/cart/@self`;
139
+ }
140
+ orderListUrl() {
141
+ return `${this.client.transactionBaseUrl}/order/byStatus/P`;
142
+ }
143
+ createOrderUrl() {
144
+ return `${this.client.transactionBaseUrl}/cart/create_order`;
145
+ }
146
+ createOrderParams(description, currency) {
147
+ const params = new URLSearchParams();
148
+ params.set("description", description ?? "");
149
+ if (currency)
150
+ params.set("currency", currency);
151
+ return params;
152
+ }
153
+ updateOrderDescriptionUrl() {
154
+ return `${this.client.transactionBaseUrl}/cart/@self/update_order_item`;
155
+ }
156
+ updateOrderDescriptionPayload(description, orderItem) {
157
+ return {
158
+ orderDescription: description,
159
+ orderItem,
160
+ x_calculateOrder: "1",
161
+ x_calculationUsage: "-1,-2,-3,-4,-5,-6,-7"
162
+ };
163
+ }
164
+ addPromotionCodeUrl() {
165
+ return `${this.client.transactionBaseUrl}/cart/@self/assigned_promotion_code`;
166
+ }
167
+ addPromotionCodePayload(code) {
168
+ return { promoCode: code };
169
+ }
170
+ removePromotionCodeUrl(code) {
171
+ return `${this.client.transactionBaseUrl}/cart/@self/assigned_promotion_code/${encodeURIComponent(code)}`;
172
+ }
173
+ async getById(payload) {
174
+ debug("getById %s", payload.cart.key);
175
+ try {
176
+ const cart = await this.fetchCart(payload.cart.key || void 0);
177
+ return success(cart);
178
+ } catch (err) {
179
+ if (err instanceof HclCartNotFoundError) {
180
+ return error({ type: "NotFound", identifier: "" });
181
+ }
182
+ throw err;
183
+ }
184
+ }
185
+ async getActiveCartId() {
186
+ debug("getActiveCartId");
187
+ try {
188
+ const data = await this.fetchWcsCart();
189
+ return success(this.factory.parseCartIdentifier(this.context, data));
190
+ } catch (err) {
191
+ if (err instanceof HclCartNotFoundError) {
192
+ return error({ type: "NotFound", identifier: "" });
193
+ }
194
+ throw err;
195
+ }
196
+ }
197
+ async add(payload) {
198
+ debug(
199
+ "add %s x%d cart=%s",
200
+ payload.variant.sku,
201
+ payload.quantity,
202
+ payload.cart.key
203
+ );
204
+ if (payload.cart.key) {
205
+ await this.fetchSetPendingOrder(payload.cart.key);
206
+ }
207
+ await this.client.callPost(
208
+ this.addOrderItemUrl(),
209
+ this.addOrderItemPayload(payload.variant.sku, payload.quantity)
210
+ );
211
+ return success(await this.fetchCart(payload.cart.key || void 0));
212
+ }
213
+ async remove(payload) {
214
+ debug("remove orderItemId=%s cart=%s", payload.item.key, payload.cart.key);
215
+ if (payload.cart.key) {
216
+ await this.fetchSetPendingOrder(payload.cart.key);
217
+ }
218
+ await this.client.callPut(
219
+ this.deleteOrderItemUrl(),
220
+ this.deleteOrderItemPayload(payload.item.key)
221
+ );
222
+ return success(await this.fetchCart(payload.cart.key || void 0));
223
+ }
224
+ async changeQuantity(payload) {
225
+ debug(
226
+ "changeQuantity orderItemId=%s qty=%d cart=%s",
227
+ payload.item.key,
228
+ payload.quantity,
229
+ payload.cart.key
230
+ );
231
+ if (payload.cart.key) {
232
+ await this.fetchSetPendingOrder(payload.cart.key);
233
+ }
234
+ await this.client.callPut(
235
+ this.updateOrderItemUrl(),
236
+ this.updateOrderItemPayload(payload.item.key, payload.quantity)
237
+ );
238
+ return success(await this.fetchCart(payload.cart.key || void 0));
239
+ }
240
+ async listCarts(payload) {
241
+ debug("listCarts");
242
+ const data = await this.client.callGet(
243
+ this.orderListUrl(),
244
+ void 0,
245
+ { allowUndefined: true }
246
+ );
247
+ const orderList = data ?? { Order: [] };
248
+ return success(
249
+ this.factory.parseCartPaginatedSearchResult(
250
+ this.context,
251
+ orderList,
252
+ payload
253
+ )
254
+ );
255
+ }
256
+ async createCart(payload) {
257
+ debug("createCart name=%s", payload.name);
258
+ const result = await this.client.callPost(
259
+ `${this.createOrderUrl()}?${this.createOrderParams(payload.name || void 0).toString()}`,
260
+ {}
261
+ );
262
+ if (payload.name) {
263
+ this.context.session["hcl.cartName"] = payload.name;
264
+ }
265
+ return success(await this.fetchCart(result.outOrderId));
266
+ }
267
+ async deleteCart(payload) {
268
+ debug("deleteCart %s", payload.cart.key);
269
+ await this.client.callDelete(
270
+ this.deleteCartUrl(payload.cart.key || void 0),
271
+ {
272
+ ignore404: true
273
+ }
274
+ );
275
+ return success(void 0);
276
+ }
277
+ async renameCart(payload) {
278
+ debug("renameCart %s -> %s", payload.cart.key, payload.newName);
279
+ if (payload.cart.key) {
280
+ await this.fetchSetPendingOrder(payload.cart.key);
281
+ }
282
+ const wcsCart = await this.fetchWcsCart();
283
+ const orderItem = (wcsCart.orderItem ?? []).map((item) => ({
284
+ orderItemId: item.orderItemId,
285
+ quantity: item.quantity
286
+ }));
287
+ await this.client.callPut(
288
+ this.updateOrderDescriptionUrl(),
289
+ this.updateOrderDescriptionPayload(payload.newName, orderItem)
290
+ );
291
+ this.context.session["hcl.cartName"] = payload.newName;
292
+ return success(await this.fetchCart(payload.cart.key || void 0));
293
+ }
294
+ async applyCouponCode(payload) {
295
+ debug("applyCouponCode %s cart=%s", payload.couponCode, payload.cart.key);
296
+ if (payload.cart.key) {
297
+ await this.fetchSetPendingOrder(payload.cart.key);
298
+ }
299
+ await this.client.callPost(
300
+ this.addPromotionCodeUrl(),
301
+ this.addPromotionCodePayload(payload.couponCode)
302
+ );
303
+ return success(await this.fetchCart(payload.cart.key || void 0));
304
+ }
305
+ async removeCouponCode(payload) {
306
+ debug("removeCouponCode %s cart=%s", payload.couponCode, payload.cart.key);
307
+ if (payload.cart.key) {
308
+ await this.fetchSetPendingOrder(payload.cart.key);
309
+ }
310
+ await this.client.callDelete(
311
+ this.removePromotionCodeUrl(payload.couponCode),
312
+ {
313
+ ignore404: true
314
+ }
315
+ );
316
+ return success(await this.fetchCart(payload.cart.key || void 0));
317
+ }
318
+ async changeCurrency(payload) {
319
+ debug("changeCurrency %s cart=%s", payload.newCurrency, payload.cart.key);
320
+ const oldCart = await this.fetchWcsCart(payload.cart.key || void 0);
321
+ const oldOrderId = oldCart.orderId;
322
+ const newOrder = await this.client.callPost(
323
+ `${this.createOrderUrl()}?${this.createOrderParams(oldCart.orderDescription, payload.newCurrency).toString()}`,
324
+ {}
325
+ );
326
+ await this.fetchSetPendingOrder(newOrder.outOrderId);
327
+ for (const item of oldCart.orderItem ?? []) {
328
+ await this.client.callPost(
329
+ this.addOrderItemUrl(payload.newCurrency),
330
+ this.addOrderItemPayload(item.partNumber, Number(item.quantity))
331
+ );
332
+ }
333
+ await this.client.callDelete(this.deleteCartUrl(oldOrderId), {
334
+ ignore404: true
335
+ });
336
+ return success(await this.fetchCart(newOrder.outOrderId));
337
+ }
338
+ }
339
+ __decorateClass([
340
+ Reactionary({
341
+ inputSchema: CartQueryByIdSchema,
342
+ outputSchema: CartSchema
343
+ })
344
+ ], HclCartCapability.prototype, "getById", 1);
345
+ __decorateClass([
346
+ Reactionary({
347
+ outputSchema: CartIdentifierSchema
348
+ })
349
+ ], HclCartCapability.prototype, "getActiveCartId", 1);
350
+ __decorateClass([
351
+ Reactionary({
352
+ inputSchema: CartMutationItemAddSchema,
353
+ outputSchema: CartSchema
354
+ })
355
+ ], HclCartCapability.prototype, "add", 1);
356
+ __decorateClass([
357
+ Reactionary({
358
+ inputSchema: CartMutationItemRemoveSchema,
359
+ outputSchema: CartSchema
360
+ })
361
+ ], HclCartCapability.prototype, "remove", 1);
362
+ __decorateClass([
363
+ Reactionary({
364
+ inputSchema: CartMutationItemQuantityChangeSchema,
365
+ outputSchema: CartSchema
366
+ })
367
+ ], HclCartCapability.prototype, "changeQuantity", 1);
368
+ __decorateClass([
369
+ Reactionary({
370
+ inputSchema: CartQueryListSchema,
371
+ outputSchema: CartPaginatedSearchResultSchema
372
+ })
373
+ ], HclCartCapability.prototype, "listCarts", 1);
374
+ __decorateClass([
375
+ Reactionary({
376
+ inputSchema: CartMutationCreateCartSchema,
377
+ outputSchema: CartSchema
378
+ })
379
+ ], HclCartCapability.prototype, "createCart", 1);
380
+ __decorateClass([
381
+ Reactionary({
382
+ inputSchema: CartMutationDeleteCartSchema
383
+ })
384
+ ], HclCartCapability.prototype, "deleteCart", 1);
385
+ __decorateClass([
386
+ Reactionary({
387
+ inputSchema: CartMutationRenameCartSchema,
388
+ outputSchema: CartSchema
389
+ })
390
+ ], HclCartCapability.prototype, "renameCart", 1);
391
+ __decorateClass([
392
+ Reactionary({
393
+ inputSchema: CartMutationApplyCouponSchema,
394
+ outputSchema: CartSchema
395
+ })
396
+ ], HclCartCapability.prototype, "applyCouponCode", 1);
397
+ __decorateClass([
398
+ Reactionary({
399
+ inputSchema: CartMutationRemoveCouponSchema,
400
+ outputSchema: CartSchema
401
+ })
402
+ ], HclCartCapability.prototype, "removeCouponCode", 1);
403
+ __decorateClass([
404
+ Reactionary({
405
+ inputSchema: CartMutationChangeCurrencySchema,
406
+ outputSchema: CartSchema
407
+ })
408
+ ], HclCartCapability.prototype, "changeCurrency", 1);
409
+ export {
410
+ HclCartCapability
411
+ };
@@ -23,7 +23,6 @@ import {
23
23
  success
24
24
  } from "@reactionary/core";
25
25
  import * as z from "zod";
26
- import { getLocaleParams } from "../core/locale-params.js";
27
26
  class HclCategoryCapability extends CategoryCapability {
28
27
  constructor(cache, context, config, client, factory) {
29
28
  super(cache, context);
@@ -32,11 +31,10 @@ class HclCategoryCapability extends CategoryCapability {
32
31
  this.factory = factory;
33
32
  }
34
33
  async getById(payload) {
35
- const { langId } = getLocaleParams(this.config, this.context);
36
- const response = await this.client.findCategories({
37
- identifier: [payload.id.key],
38
- langId
39
- });
34
+ const response = await this.client.callGet(
35
+ this.getByIdUrl(payload),
36
+ this.getByIdPayload(payload)
37
+ );
40
38
  const data = response.contents?.[0];
41
39
  if (!data) {
42
40
  return error({ type: "NotFound", identifier: payload.id });
@@ -44,20 +42,22 @@ class HclCategoryCapability extends CategoryCapability {
44
42
  return success(this.factory.parseCategory(this.context, data));
45
43
  }
46
44
  async getBySlug(payload) {
47
- const { langId } = getLocaleParams(this.config, this.context);
48
- const token = await this.client.resolveSlug(payload.slug, langId);
45
+ const urlResponse = await this.client.callGet(
46
+ this.urlsUrl(),
47
+ this.urlsParams(payload.slug),
48
+ { allowUndefined: true }
49
+ );
50
+ const token = urlResponse?.contents?.[0];
49
51
  if (!token || token.tokenName !== "CategoryToken" || !token.tokenExternalValue) {
50
52
  return error({
51
53
  type: "NotFound",
52
54
  identifier: payload.slug
53
55
  });
54
56
  }
55
- const response = await this.client.findCategories({
56
- // tokenExternalValue is the external identifier (e.g. "LivingRoom").
57
- // Use identifier= param so the key returned by the factory is consistent.
58
- identifier: [token.tokenExternalValue],
59
- langId
60
- });
57
+ const response = await this.client.callGet(
58
+ this.getBySlugUrl(token),
59
+ this.getBySlugPayload(token)
60
+ );
61
61
  const data = response.contents?.[0];
62
62
  if (!data) {
63
63
  return error({
@@ -68,11 +68,10 @@ class HclCategoryCapability extends CategoryCapability {
68
68
  return success(this.factory.parseCategory(this.context, data));
69
69
  }
70
70
  async getBreadcrumbPathToCategory(payload) {
71
- const { langId } = getLocaleParams(this.config, this.context);
72
- const leafResponse = await this.client.findCategories({
73
- identifier: [payload.id.key],
74
- langId
75
- });
71
+ const leafResponse = await this.client.callGet(
72
+ this.getBreadcrumbLeafUrl(payload),
73
+ this.getBreadcrumbLeafPayload(payload)
74
+ );
76
75
  const leafData = leafResponse.contents?.[0];
77
76
  if (!leafData) {
78
77
  return success([]);
@@ -80,7 +79,10 @@ class HclCategoryCapability extends CategoryCapability {
80
79
  const parentId = leafData.parentCatalogGroupID;
81
80
  const pathSegments = (typeof parentId === "string" ? parentId : parentId?.[0] ?? "").split("/").filter(Boolean);
82
81
  const ancestorIds = pathSegments.slice(0, -1);
83
- const ancestorsResp = ancestorIds.length > 0 ? await this.client.findCategories({ id: ancestorIds, langId }) : { contents: [] };
82
+ const ancestorsResp = ancestorIds.length > 0 ? await this.client.callGet(
83
+ this.getBreadcrumbAncestorsUrl(ancestorIds),
84
+ this.getBreadcrumbAncestorsPayload(ancestorIds)
85
+ ) : { contents: [] };
84
86
  const byUniqueId = new Map(
85
87
  (ancestorsResp.contents ?? []).map((c) => [c.uniqueID, c])
86
88
  );
@@ -95,11 +97,10 @@ class HclCategoryCapability extends CategoryCapability {
95
97
  return success(path);
96
98
  }
97
99
  async findChildCategories(payload) {
98
- const { langId } = getLocaleParams(this.config, this.context);
99
- const parentResp = await this.client.findCategories({
100
- identifier: [payload.parentId.key],
101
- langId
102
- });
100
+ const parentResp = await this.client.callGet(
101
+ this.findChildCategoriesParentUrl(payload),
102
+ this.findChildCategoriesParentPayload(payload)
103
+ );
103
104
  const parentUniqueId = parentResp.contents?.[0]?.uniqueID;
104
105
  if (!parentUniqueId) {
105
106
  return error({
@@ -107,11 +108,10 @@ class HclCategoryCapability extends CategoryCapability {
107
108
  identifier: payload.parentId
108
109
  });
109
110
  }
110
- const response = await this.client.findCategories({
111
- parentCategoryId: parentUniqueId,
112
- depthAndLimit: "1,0",
113
- langId
114
- });
111
+ const response = await this.client.callGet(
112
+ this.findChildCategoriesUrl(parentUniqueId),
113
+ this.findChildCategoriesPayload(parentUniqueId)
114
+ );
115
115
  const items = response.contents ?? [];
116
116
  const paginated = this.factory.parseCategoryPaginatedResult(
117
117
  this.context,
@@ -121,11 +121,10 @@ class HclCategoryCapability extends CategoryCapability {
121
121
  return success(paginated);
122
122
  }
123
123
  async findTopCategories(payload) {
124
- const { langId } = getLocaleParams(this.config, this.context);
125
- const response = await this.client.findCategories({
126
- depthAndLimit: "1,0",
127
- langId
128
- });
124
+ const response = await this.client.callGet(
125
+ this.findTopCategoriesUrl(payload),
126
+ this.findTopCategoriesPayload()
127
+ );
129
128
  const items = response.contents ?? [];
130
129
  const paginated = this.factory.parseCategoryPaginatedResult(
131
130
  this.context,
@@ -134,6 +133,83 @@ class HclCategoryCapability extends CategoryCapability {
134
133
  );
135
134
  return success(paginated);
136
135
  }
136
+ getByIdUrl(_payload) {
137
+ return this.categoriesUrl();
138
+ }
139
+ getBySlugUrl(_token) {
140
+ return this.categoriesUrl();
141
+ }
142
+ getBreadcrumbLeafUrl(_payload) {
143
+ return this.categoriesUrl();
144
+ }
145
+ getBreadcrumbAncestorsUrl(_ancestorIds) {
146
+ return this.categoriesUrl();
147
+ }
148
+ findChildCategoriesParentUrl(_payload) {
149
+ return this.categoriesUrl();
150
+ }
151
+ findChildCategoriesUrl(_parentUniqueId) {
152
+ return this.categoriesUrl();
153
+ }
154
+ findTopCategoriesUrl(_payload) {
155
+ return this.categoriesUrl();
156
+ }
157
+ getByIdPayload(payload) {
158
+ return this.categoriesParams({ identifier: [payload.id.key] });
159
+ }
160
+ // tokenValue is the numeric uniqueID; tokenExternalValue is the string identifier
161
+ // which the categories API rejects with 400 when used as an id= parameter.
162
+ getBySlugPayload(token) {
163
+ return this.categoriesParams({ id: [token.tokenValue] });
164
+ }
165
+ getBreadcrumbLeafPayload(payload) {
166
+ return this.categoriesParams({ identifier: [payload.id.key] });
167
+ }
168
+ getBreadcrumbAncestorsPayload(ancestorIds) {
169
+ return this.categoriesParams({ id: ancestorIds });
170
+ }
171
+ findChildCategoriesParentPayload(payload) {
172
+ return this.categoriesParams({ identifier: [payload.parentId.key] });
173
+ }
174
+ findChildCategoriesPayload(parentUniqueId) {
175
+ return this.categoriesParams({
176
+ parentCategoryId: parentUniqueId,
177
+ depthAndLimit: "1,0"
178
+ });
179
+ }
180
+ findTopCategoriesPayload() {
181
+ return this.categoriesParams({ depthAndLimit: "1,0" });
182
+ }
183
+ categoriesUrl() {
184
+ return `${this.client.catalogBaseUrl}/api/v2/categories`;
185
+ }
186
+ categoriesParams(query) {
187
+ const params = new URLSearchParams();
188
+ params.set("storeId", query.storeId ?? this.config.storeId);
189
+ const catalogId = query.catalogId ?? this.config.catalogId;
190
+ if (catalogId)
191
+ params.set("catalogId", catalogId);
192
+ if (query.parentCategoryId)
193
+ params.set("parentCategoryId", query.parentCategoryId);
194
+ if (query.depthAndLimit)
195
+ params.set("depthAndLimit", query.depthAndLimit);
196
+ if (query.profileName)
197
+ params.set("profileName", query.profileName);
198
+ for (const id of query.id ?? [])
199
+ params.append("id", id);
200
+ for (const identifier of query.identifier ?? [])
201
+ params.append("identifier", identifier);
202
+ return params;
203
+ }
204
+ urlsUrl() {
205
+ return `${this.client.catalogBaseUrl}/api/v2/urls`;
206
+ }
207
+ urlsParams(slug) {
208
+ const params = new URLSearchParams();
209
+ params.set("storeId", this.config.storeId);
210
+ params.append("identifier", slug);
211
+ return params;
212
+ }
137
213
  }
138
214
  __decorateClass([
139
215
  Reactionary({