@viu/emporix-sdk 2.23.0 → 2.26.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +16 -6
  3. package/dist/availability.d.cts +1 -1
  4. package/dist/availability.d.ts +1 -1
  5. package/dist/cart.d.cts +1 -1
  6. package/dist/cart.d.ts +1 -1
  7. package/dist/category.d.cts +1 -1
  8. package/dist/category.d.ts +1 -1
  9. package/dist/checkout.d.cts +1 -1
  10. package/dist/checkout.d.ts +1 -1
  11. package/dist/companies.d.cts +1 -1
  12. package/dist/companies.d.ts +1 -1
  13. package/dist/contacts.d.cts +1 -1
  14. package/dist/contacts.d.ts +1 -1
  15. package/dist/{context-CfXJcYKP.d.cts → context-DC5gSgKK.d.cts} +18 -0
  16. package/dist/{context-CfXJcYKP.d.ts → context-DC5gSgKK.d.ts} +18 -0
  17. package/dist/{customer-groups-BxSNFHq1.d.cts → customer-groups-BqYsPCA6.d.cts} +1 -1
  18. package/dist/{customer-groups-GlzWhDsi.d.ts → customer-groups-CLm6Gu9U.d.ts} +1 -1
  19. package/dist/customer-groups.d.cts +2 -2
  20. package/dist/customer-groups.d.ts +2 -2
  21. package/dist/customer.d.cts +1 -1
  22. package/dist/customer.d.ts +1 -1
  23. package/dist/index.cjs +12 -5
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +5 -5
  26. package/dist/index.d.ts +5 -5
  27. package/dist/index.js +12 -5
  28. package/dist/index.js.map +1 -1
  29. package/dist/locations.d.cts +1 -1
  30. package/dist/locations.d.ts +1 -1
  31. package/dist/media.d.cts +1 -1
  32. package/dist/media.d.ts +1 -1
  33. package/dist/orders.d.cts +1 -1
  34. package/dist/orders.d.ts +1 -1
  35. package/dist/payment.d.cts +1 -1
  36. package/dist/payment.d.ts +1 -1
  37. package/dist/price.d.cts +1 -1
  38. package/dist/price.d.ts +1 -1
  39. package/dist/product.d.cts +1 -1
  40. package/dist/product.d.ts +1 -1
  41. package/dist/segment.d.cts +1 -1
  42. package/dist/segment.d.ts +1 -1
  43. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # @viu/emporix-sdk
2
2
 
3
+ ## 2.26.0
4
+
5
+ ### Patch Changes
6
+
7
+ - [#184](https://github.com/viuteam/emporix-sdk/pull/184) [`3f81681`](https://github.com/viuteam/emporix-sdk/commit/3f816818d444d9b874044f1fae7b9e82d48679b1) Thanks [@viu-release-bot](https://github.com/apps/viu-release-bot)! - chore(sdk): sync generated types with upstream Emporix API specs
8
+
9
+ Updated services: ai-service,indexing-service
10
+
11
+ ## 2.25.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [#185](https://github.com/viuteam/emporix-sdk/pull/185) [`893d8b1`](https://github.com/viuteam/emporix-sdk/commit/893d8b191f186d7c439b609b295e190aa3ba2ee5) Thanks [@amnael1](https://github.com/amnael1)! - `EmporixConfig.fetch` — replace the global `fetch` used for API requests.
16
+
17
+ ```ts
18
+ const sdk = new EmporixClient({ tenant, credentials, fetch: myFetch });
19
+ ```
20
+
21
+ Useful for tracing, test doubles, custom retry policies, and framework-level
22
+ caching (`@viu/emporix-sdk-next` uses it to attach Next cache tags).
23
+
24
+ Client-level rather than per-request: the 596 `http.request` call sites in
25
+ `services/` each build their own `RequestOptions` literal, so a per-request
26
+ `fetchOptions` field would reach none of them.
27
+
28
+ Token requests and SSE deliberately keep using the global `fetch`: a cached
29
+ token response would be a security defect, and caching an event stream is
30
+ meaningless. Both are therefore structurally uncacheable, not merely uncached by
31
+ convention.
32
+
3
33
  ## 2.23.0
4
34
 
5
35
  ### Minor Changes
package/README.md CHANGED
@@ -34,8 +34,18 @@ const products = await sdk.products.list();
34
34
  const { customerToken } = await sdk.customers.login({ email, password });
35
35
  const ctx = auth.customer(customerToken);
36
36
  const me = await sdk.customers.me(ctx);
37
+
38
+ // create() returns CartCreated → cart.cartId (getCurrent() returns a Cart → .id)
37
39
  const cart = await sdk.carts.create({ currency: "EUR" }, ctx);
38
- await sdk.carts.addItem(cart.id, { productId: "p_1", quantity: 2 }, ctx);
40
+ await sdk.carts.addItem(
41
+ cart.cartId,
42
+ {
43
+ itemYrn: `urn:yaas:hybris:product:product:${sdk.tenant};p_1`,
44
+ quantity: 2,
45
+ price: { priceId: "pr_1", originalAmount: 10, effectiveAmount: 10, currency: "EUR" },
46
+ },
47
+ ctx,
48
+ );
39
49
 
40
50
  // Service account with a custom credential set
41
51
  await sdk.products.list(undefined, auth.service("partner"));
@@ -53,17 +63,17 @@ property on the `EmporixClient` instance:
53
63
  | --- | --- |
54
64
  | Catalog | `products`, `categories`, `prices`, `brands`, `labels`, `catalogs` |
55
65
  | Cart & checkout | `carts`, `checkout`, `payments`, `coupons`, `taxes`, `shipping`, `fees` |
56
- | Orders & fulfilment | `orders`, `salesOrders`, `returns`, `pickPack`, `availability`, `indexing` |
57
- | Customers & B2B | `customers`, `customerAdmin`, `companies`, `contacts`, `locations`, `customerGroups`, `approvals`, `rewardPoints`, `segments` |
58
- | Platform & config | `sites`, `sessionContext`, `tenantConfig`, `clientConfig`, `media`, `schemas`, `webhooks`, `sequentialIds`, `units`, `countries`, `currencies`, `vendors`, `shoppingLists`, `sepaExport`, `ai`, `ragIndexer` |
66
+ | Orders & fulfilment | `orders`, `salesOrders`, `quotes`, `invoices`, `returns`, `pickPack`, `availability`, `indexing` |
67
+ | Customers & B2B | `customers`, `customerAdmin`, `companies`, `contacts`, `locations`, `customerGroups`, `approvals`, `rewardPoints`, `segments`, `iam` |
68
+ | Platform & config | `sites`, `sessionContext`, `tenantConfig`, `clientConfig`, `media`, `schemas`, `webhooks`, `sequentialIds`, `units`, `countries`, `currencies`, `vendors`, `shoppingLists`, `sepaExport`, `cloudFunctions`, `ai`, `ragIndexer` |
59
69
 
60
70
  The sections below highlight the most-used services; per-service guides live in
61
71
  [`../../docs/`](../../docs).
62
72
 
63
73
  ## Searching by mixin (custom) fields
64
74
 
65
- `products.search`, `categories.search`, `orders.listMine({ q })`,
66
- `customerAdmin.searchCustomers({ q })` and `vendor.searchVendors({ q })` accept a
75
+ `products.search`, `categories.search`, `orders.listMine(auth, { q })`,
76
+ `customerAdmin.searchCustomers({ q })` and `vendors.searchVendors({ q })` accept a
67
77
  raw Emporix `q` string **or** a type-safe filter built with `mixinQuery` from
68
78
  [`@viu/emporix-mixins`](../mixins). The filter is entity-gated (a filter built for
69
79
  one entity is a compile error on another) and an `or()` filter is rejected on
@@ -1,4 +1,4 @@
1
- import { C as ClientContext, b as AuthContext, P as PaginatedItems } from './context-CfXJcYKP.cjs';
1
+ import { C as ClientContext, b as AuthContext, P as PaginatedItems } from './context-DC5gSgKK.cjs';
2
2
 
3
3
  type AvailabilityDto = {
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { C as ClientContext, b as AuthContext, P as PaginatedItems } from './context-CfXJcYKP.js';
1
+ import { C as ClientContext, b as AuthContext, P as PaginatedItems } from './context-DC5gSgKK.js';
2
2
 
3
3
  type AvailabilityDto = {
4
4
  /**
package/dist/cart.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as ClientContext, b as AuthContext } from './context-CfXJcYKP.cjs';
1
+ import { C as ClientContext, b as AuthContext } from './context-DC5gSgKK.cjs';
2
2
 
3
3
  /**
4
4
  * Access control identifier that determines who can view or manage the cart.
package/dist/cart.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as ClientContext, b as AuthContext } from './context-CfXJcYKP.js';
1
+ import { C as ClientContext, b as AuthContext } from './context-DC5gSgKK.js';
2
2
 
3
3
  /**
4
4
  * Access control identifier that determines who can view or manage the cart.
@@ -1,4 +1,4 @@
1
- import { C as ClientContext, b as AuthContext, P as PaginatedItems } from './context-CfXJcYKP.cjs';
1
+ import { C as ClientContext, b as AuthContext, P as PaginatedItems } from './context-DC5gSgKK.cjs';
2
2
  import { a as QueryFor } from './query-mLQs2WFr.cjs';
3
3
  import { Product } from './product.cjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { C as ClientContext, b as AuthContext, P as PaginatedItems } from './context-CfXJcYKP.js';
1
+ import { C as ClientContext, b as AuthContext, P as PaginatedItems } from './context-DC5gSgKK.js';
2
2
  import { a as QueryFor } from './query-mLQs2WFr.js';
3
3
  import { Product } from './product.js';
4
4
 
@@ -1,4 +1,4 @@
1
- import { C as ClientContext, b as AuthContext } from './context-CfXJcYKP.cjs';
1
+ import { C as ClientContext, b as AuthContext } from './context-DC5gSgKK.cjs';
2
2
 
3
3
  /**
4
4
  * Information about the customer's address.
@@ -1,4 +1,4 @@
1
- import { C as ClientContext, b as AuthContext } from './context-CfXJcYKP.js';
1
+ import { C as ClientContext, b as AuthContext } from './context-DC5gSgKK.js';
2
2
 
3
3
  /**
4
4
  * Information about the customer's address.
@@ -1,4 +1,4 @@
1
- import { C as ClientContext, b as AuthContext } from './context-CfXJcYKP.cjs';
1
+ import { C as ClientContext, b as AuthContext } from './context-DC5gSgKK.cjs';
2
2
  import { L as LegalEntity, e as LegalEntityCreate, f as LegalEntityUpdate } from './types.gen-C_wOXYZB.cjs';
3
3
  export { A as AccountLimit, d as CustomerGroup, g as LegalInfo } from './types.gen-C_wOXYZB.cjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { C as ClientContext, b as AuthContext } from './context-CfXJcYKP.js';
1
+ import { C as ClientContext, b as AuthContext } from './context-DC5gSgKK.js';
2
2
  import { L as LegalEntity, e as LegalEntityCreate, f as LegalEntityUpdate } from './types.gen-C_wOXYZB.js';
3
3
  export { A as AccountLimit, d as CustomerGroup, g as LegalInfo } from './types.gen-C_wOXYZB.js';
4
4
 
@@ -1,4 +1,4 @@
1
- import { C as ClientContext, b as AuthContext } from './context-CfXJcYKP.cjs';
1
+ import { C as ClientContext, b as AuthContext } from './context-DC5gSgKK.cjs';
2
2
  import { C as ContactAssignment, a as ContactAssignmentCreate, b as ContactAssignmentUpdate } from './types.gen-C_wOXYZB.cjs';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { C as ClientContext, b as AuthContext } from './context-CfXJcYKP.js';
1
+ import { C as ClientContext, b as AuthContext } from './context-DC5gSgKK.js';
2
2
  import { C as ContactAssignment, a as ContactAssignmentCreate, b as ContactAssignmentUpdate } from './types.gen-C_wOXYZB.js';
3
3
 
4
4
  /**
@@ -124,6 +124,16 @@ interface EmporixConfig {
124
124
  maxLifetimeSeconds?: number;
125
125
  };
126
126
  logger?: LoggerConfig;
127
+ /**
128
+ * Replaces the global `fetch` for API requests. Receives the same arguments.
129
+ *
130
+ * Deliberately NOT used for token requests (`core/auth.ts`) or SSE
131
+ * (`HttpClient.stream`): a cached token response would be a security defect,
132
+ * and caching an event stream is meaningless. Those keep the global `fetch`,
133
+ * which makes them structurally uncacheable rather than uncached by
134
+ * convention.
135
+ */
136
+ fetch?: typeof globalThis.fetch;
127
137
  }
128
138
  /** Fully-resolved configuration with defaults applied. */
129
139
  interface ResolvedConfig {
@@ -143,6 +153,7 @@ interface ResolvedConfig {
143
153
  maxLifetimeSeconds: number;
144
154
  };
145
155
  logger: LoggerConfig | undefined;
156
+ fetch: typeof globalThis.fetch | undefined;
146
157
  }
147
158
  /** Validates user config and applies defaults. Throws on invalid tenant/credentials. */
148
159
  declare function validateConfig(input: EmporixConfig): ResolvedConfig;
@@ -364,11 +375,18 @@ interface HttpClientOptions {
364
375
  requestContext?: {
365
376
  language?: string | undefined;
366
377
  };
378
+ /**
379
+ * Replaces the global `fetch` for API requests. Not used by token requests
380
+ * (`core/auth.ts`) or by {@link HttpClient.stream} — see `EmporixConfig.fetch`.
381
+ */
382
+ fetch?: typeof globalThis.fetch;
367
383
  }
368
384
  /** Fetch wrapper: auth resolution, JSON parsing, typed error mapping, logging. */
369
385
  declare class HttpClient {
370
386
  private readonly opts;
371
387
  private readonly sleep;
388
+ /** Resolved request fetch. The arrow keeps `globalThis.fetch` correctly bound. */
389
+ private readonly doFetch;
372
390
  constructor(opts: HttpClientOptions);
373
391
  private buildHeaders;
374
392
  request<T = unknown>(o: RequestOptions): Promise<T>;
@@ -124,6 +124,16 @@ interface EmporixConfig {
124
124
  maxLifetimeSeconds?: number;
125
125
  };
126
126
  logger?: LoggerConfig;
127
+ /**
128
+ * Replaces the global `fetch` for API requests. Receives the same arguments.
129
+ *
130
+ * Deliberately NOT used for token requests (`core/auth.ts`) or SSE
131
+ * (`HttpClient.stream`): a cached token response would be a security defect,
132
+ * and caching an event stream is meaningless. Those keep the global `fetch`,
133
+ * which makes them structurally uncacheable rather than uncached by
134
+ * convention.
135
+ */
136
+ fetch?: typeof globalThis.fetch;
127
137
  }
128
138
  /** Fully-resolved configuration with defaults applied. */
129
139
  interface ResolvedConfig {
@@ -143,6 +153,7 @@ interface ResolvedConfig {
143
153
  maxLifetimeSeconds: number;
144
154
  };
145
155
  logger: LoggerConfig | undefined;
156
+ fetch: typeof globalThis.fetch | undefined;
146
157
  }
147
158
  /** Validates user config and applies defaults. Throws on invalid tenant/credentials. */
148
159
  declare function validateConfig(input: EmporixConfig): ResolvedConfig;
@@ -364,11 +375,18 @@ interface HttpClientOptions {
364
375
  requestContext?: {
365
376
  language?: string | undefined;
366
377
  };
378
+ /**
379
+ * Replaces the global `fetch` for API requests. Not used by token requests
380
+ * (`core/auth.ts`) or by {@link HttpClient.stream} — see `EmporixConfig.fetch`.
381
+ */
382
+ fetch?: typeof globalThis.fetch;
367
383
  }
368
384
  /** Fetch wrapper: auth resolution, JSON parsing, typed error mapping, logging. */
369
385
  declare class HttpClient {
370
386
  private readonly opts;
371
387
  private readonly sleep;
388
+ /** Resolved request fetch. The arrow keeps `globalThis.fetch` correctly bound. */
389
+ private readonly doFetch;
372
390
  constructor(opts: HttpClientOptions);
373
391
  private buildHeaders;
374
392
  request<T = unknown>(o: RequestOptions): Promise<T>;
@@ -1,4 +1,4 @@
1
- import { C as ClientContext, b as AuthContext } from './context-CfXJcYKP.cjs';
1
+ import { C as ClientContext, b as AuthContext } from './context-DC5gSgKK.cjs';
2
2
 
3
3
  /**
4
4
  * Access control metadata.
@@ -1,4 +1,4 @@
1
- import { C as ClientContext, b as AuthContext } from './context-CfXJcYKP.js';
1
+ import { C as ClientContext, b as AuthContext } from './context-DC5gSgKK.js';
2
2
 
3
3
  /**
4
4
  * Access control metadata.
@@ -1,2 +1,2 @@
1
- export { g as CustomerGroupsService, j as IamGroup, c as IamGroupMemberAssignment } from './customer-groups-BxSNFHq1.cjs';
2
- import './context-CfXJcYKP.cjs';
1
+ export { g as CustomerGroupsService, j as IamGroup, c as IamGroupMemberAssignment } from './customer-groups-BqYsPCA6.cjs';
2
+ import './context-DC5gSgKK.cjs';
@@ -1,2 +1,2 @@
1
- export { g as CustomerGroupsService, j as IamGroup, c as IamGroupMemberAssignment } from './customer-groups-GlzWhDsi.js';
2
- import './context-CfXJcYKP.js';
1
+ export { g as CustomerGroupsService, j as IamGroup, c as IamGroupMemberAssignment } from './customer-groups-CLm6Gu9U.js';
2
+ import './context-DC5gSgKK.js';
@@ -1,4 +1,4 @@
1
- import { C as ClientContext, A as AnonymousSession, b as AuthContext } from './context-CfXJcYKP.cjs';
1
+ import { C as ClientContext, A as AnonymousSession, b as AuthContext } from './context-DC5gSgKK.cjs';
2
2
 
3
3
  type AccountId = {
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { C as ClientContext, A as AnonymousSession, b as AuthContext } from './context-CfXJcYKP.js';
1
+ import { C as ClientContext, A as AnonymousSession, b as AuthContext } from './context-DC5gSgKK.js';
2
2
 
3
3
  type AccountId = {
4
4
  /**
package/dist/index.cjs CHANGED
@@ -113,7 +113,8 @@ function validateConfig(input) {
113
113
  expirationBufferSeconds: input.cache?.expirationBufferSeconds ?? 60,
114
114
  maxLifetimeSeconds: input.cache?.maxLifetimeSeconds ?? 3600
115
115
  },
116
- logger: input.logger
116
+ logger: input.logger,
117
+ fetch: input.fetch
117
118
  };
118
119
  }
119
120
 
@@ -645,9 +646,12 @@ var HttpClient = class {
645
646
  constructor(opts) {
646
647
  this.opts = opts;
647
648
  this.sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
649
+ this.doFetch = opts.fetch ?? ((...args) => globalThis.fetch(...args));
648
650
  }
649
651
  opts;
650
652
  sleep;
653
+ /** Resolved request fetch. The arrow keeps `globalThis.fetch` correctly bound. */
654
+ doFetch;
651
655
  buildHeaders(o, token, isFormData) {
652
656
  return {
653
657
  ...this.opts.requestContext?.language ? { "Accept-Language": this.opts.requestContext.language } : {},
@@ -703,7 +707,7 @@ var HttpClient = class {
703
707
  let res;
704
708
  let text;
705
709
  try {
706
- res = await Promise.race([fetch(url, init), overallBudget]);
710
+ res = await Promise.race([this.doFetch(url, init), overallBudget]);
707
711
  clearTimeout(connectTimer);
708
712
  connectTimer = void 0;
709
713
  const body = res.text();
@@ -807,7 +811,7 @@ var HttpClient = class {
807
811
  init.body = isFormData ? o.body : JSON.stringify(o.body);
808
812
  }
809
813
  try {
810
- return await fetch(url, init);
814
+ return await this.doFetch(url, init);
811
815
  } catch (err) {
812
816
  if (err.name === "AbortError") {
813
817
  throw new EmporixTimeoutError(
@@ -886,7 +890,7 @@ var HttpClient = class {
886
890
  };
887
891
 
888
892
  // package.json
889
- var version = "2.23.0";
893
+ var version = "2.26.0";
890
894
 
891
895
  // src/version.ts
892
896
  var SDK_VERSION = version;
@@ -925,7 +929,10 @@ function createCore(config) {
925
929
  retry: cfg.retry,
926
930
  timeouts: cfg.timeouts,
927
931
  customerRefresh,
928
- requestContext
932
+ requestContext,
933
+ // exactOptionalPropertyTypes: `{ fetch: undefined }` is a type error
934
+ // against `fetch?: typeof globalThis.fetch`, so spread conditionally.
935
+ ...cfg.fetch !== void 0 ? { fetch: cfg.fetch } : {}
929
936
  })
930
937
  });
931
938
  return {