@viu/emporix-sdk 2.33.5 → 2.34.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # @viu/emporix-sdk
2
2
 
3
+ ## 2.34.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#269](https://github.com/viuteam/emporix-sdk/pull/269) [`1cc5094`](https://github.com/viuteam/emporix-sdk/commit/1cc5094f092529494c166fbf8e5a315adac127b2) Thanks [@amnael1](https://github.com/amnael1)! - Fix the JSON-Patch `op` enum for the Approval service. The upstream spec ships
8
+ `ADD`/`REMOVE`/`REPLACE`, which the live API rejects with 400; `ApprovalPatch['op']`
9
+ is now `'add' | 'remove' | 'replace'`. Callers that worked around the wrong type
10
+ with a cast can drop it. Measured against tenant `viu` on 2026-08-18.
11
+
12
+ - [#269](https://github.com/viuteam/emporix-sdk/pull/269) [`c2e9993`](https://github.com/viuteam/emporix-sdk/commit/c2e999351b0ca99ae96b8615957cb2d168c2ee34) Thanks [@amnael1](https://github.com/amnael1)! - Add `approvalStatusPatch(status, approverComment?)`, which builds the JSON-Patch for
13
+ an approval decision. It encodes two measured quirks: the op is lowercase, and the
14
+ approver comment needs `add` rather than `replace` — `replace` on the absent
15
+ `approverComment` field answers APPROVAL-400010 and, because PATCH is atomic, drops
16
+ the status change with it.
17
+
18
+ - [#269](https://github.com/viuteam/emporix-sdk/pull/269) [`071cb9c`](https://github.com/viuteam/emporix-sdk/commit/071cb9c6022c3dc4cd1f99f114c208fc057344f1) Thanks [@amnael1](https://github.com/amnael1)! - Add `productYrn(tenant, productId)`, the inverse of `productIdFromYrn` and the form
19
+ `carts.addItem` requires. Also notes in `productIdFromYrn` that approval resource
20
+ items carry a bare product id rather than a YRN, so callers need the `itemId` fallback.
21
+
22
+ ### Patch Changes
23
+
24
+ - [#269](https://github.com/viuteam/emporix-sdk/pull/269) [`ab8c607`](https://github.com/viuteam/emporix-sdk/commit/ab8c6078349738867877c3600f3ef52880c82439) Thanks [@amnael1](https://github.com/amnael1)! - Document measured Approval-service behaviour: `createApproval` consumes the cart
25
+ (404 from the Cart API, not restored by decline or withdrawal), `checkPermitted`
26
+ answers `true` for the approver as well as the requester, and the approver comment
27
+ needs `add`. Also corrects the `useCreateApproval` example, which showed the payload
28
+ nested under `resource` and omitted the mandatory `action`, `approver` and `details`.
29
+
30
+ - [#269](https://github.com/viuteam/emporix-sdk/pull/269) [`75bf3ef`](https://github.com/viuteam/emporix-sdk/commit/75bf3efae89dbcd19283dc9ac8f6cc609e72ee7b) Thanks [@amnael1](https://github.com/amnael1)! - Warn when `context` is passed at the top level of `EmporixConfig` instead of inside
31
+ `credentials.storefront`. It was silently dropped, after which `matchByContext`
32
+ returns an empty list with no error because the anonymous token carries no site,
33
+ currency or country. `logger: false` is honoured as a request for silence.
34
+
3
35
  ## 2.33.5
4
36
 
5
37
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -90,6 +90,17 @@ function errorFromResponse(status, message, body) {
90
90
  // src/core/config.ts
91
91
  var DEFAULT_HOST = "https://api.emporix.io";
92
92
  var TENANT_RE = /^[a-z][a-z0-9]{2,15}$/;
93
+ function warnOnMisplacedContext(input) {
94
+ if (!("context" in input)) return;
95
+ const logger = input.logger;
96
+ if (logger === false) return;
97
+ const message = "EmporixConfig has no top-level `context` \u2014 it is being ignored. Move it into `credentials.storefront.context`, otherwise the anonymous token carries no site/currency/country and price matching returns an empty list without erroring.";
98
+ if (logger && typeof logger.warn === "function") {
99
+ logger.warn(message);
100
+ return;
101
+ }
102
+ console.warn(`[emporix] ${message}`);
103
+ }
93
104
  function validateConfig(input) {
94
105
  if (!TENANT_RE.test(input.tenant)) {
95
106
  throw new Error(
@@ -99,6 +110,7 @@ function validateConfig(input) {
99
110
  if (!input.credentials) {
100
111
  throw new Error("credentials is required (provide at least one of backend/storefront/custom)");
101
112
  }
113
+ warnOnMisplacedContext(input);
102
114
  return {
103
115
  tenant: input.tenant,
104
116
  host: input.host ?? DEFAULT_HOST,
@@ -983,7 +995,7 @@ var HttpClient = class {
983
995
  };
984
996
 
985
997
  // package.json
986
- var version = "2.33.5";
998
+ var version = "2.34.0";
987
999
 
988
1000
  // src/version.ts
989
1001
  var SDK_VERSION = version;
@@ -8543,6 +8555,15 @@ var ApprovalService = class {
8543
8555
  });
8544
8556
  }
8545
8557
  };
8558
+ function approvalStatusPatch(status, approverComment) {
8559
+ const comment = approverComment?.trim() ?? "";
8560
+ return [
8561
+ { op: "replace", path: "/status", value: status },
8562
+ // `as const` on both fields: the generated type narrows `path` to an enum too, so
8563
+ // a widened `string` from the spread would not be assignable.
8564
+ ...comment !== "" ? [{ op: "add", path: "/approverComment", value: comment }] : []
8565
+ ];
8566
+ }
8546
8567
 
8547
8568
  // src/client.ts
8548
8569
  var EmporixClient = class {
@@ -8733,6 +8754,9 @@ function productIdFromYrn(yrn) {
8733
8754
  const semi = yrn.lastIndexOf(";");
8734
8755
  return semi >= 0 ? yrn.slice(semi + 1) : "";
8735
8756
  }
8757
+ function productYrn(tenant, productId) {
8758
+ return `urn:yaas:hybris:product:product:${tenant};${productId}`;
8759
+ }
8736
8760
 
8737
8761
  exports.AiService = AiService;
8738
8762
  exports.ApprovalService = ApprovalService;
@@ -8800,6 +8824,7 @@ exports.TenantConfigService = TenantConfigService;
8800
8824
  exports.UnitHandlingService = UnitHandlingService;
8801
8825
  exports.VendorService = VendorService;
8802
8826
  exports.WebhookService = WebhookService;
8827
+ exports.approvalStatusPatch = approvalStatusPatch;
8803
8828
  exports.auth = auth;
8804
8829
  exports.createConsoleLogger = createConsoleLogger;
8805
8830
  exports.createCookieBackedStorage = createCookieBackedStorage;
@@ -8812,6 +8837,7 @@ exports.iterateAll = iterateAll;
8812
8837
  exports.parseAnonymousSession = parseAnonymousSession;
8813
8838
  exports.pickFee = pickFee;
8814
8839
  exports.productIdFromYrn = productIdFromYrn;
8840
+ exports.productYrn = productYrn;
8815
8841
  exports.redact = redact;
8816
8842
  exports.resolveQuery = resolveQuery;
8817
8843
  exports.resolveToken = resolveToken;