@viu/emporix-sdk 2.13.1 → 2.15.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 (136) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +1 -1
  3. package/dist/availability.cjs +4 -1
  4. package/dist/availability.cjs.map +1 -1
  5. package/dist/availability.d.cts +2 -1
  6. package/dist/availability.d.ts +2 -1
  7. package/dist/availability.js +2 -2
  8. package/dist/cart.cjs +1 -0
  9. package/dist/cart.cjs.map +1 -1
  10. package/dist/cart.d.cts +2 -1
  11. package/dist/cart.d.ts +2 -1
  12. package/dist/cart.js +2 -2
  13. package/dist/category.cjs +4 -1
  14. package/dist/category.cjs.map +1 -1
  15. package/dist/category.d.cts +2 -1
  16. package/dist/category.d.ts +2 -1
  17. package/dist/category.js +1 -1
  18. package/dist/checkout.cjs +1 -0
  19. package/dist/checkout.cjs.map +1 -1
  20. package/dist/checkout.d.cts +2 -1
  21. package/dist/checkout.d.ts +2 -1
  22. package/dist/checkout.js +2 -2
  23. package/dist/{chunk-BFQ732VZ.js → chunk-3BDDYX3V.js} +3 -3
  24. package/dist/{chunk-BFQ732VZ.js.map → chunk-3BDDYX3V.js.map} +1 -1
  25. package/dist/{chunk-LGOC5XOI.js → chunk-3BTPX7IJ.js} +3 -2
  26. package/dist/chunk-3BTPX7IJ.js.map +1 -0
  27. package/dist/{chunk-B4UOYJKW.js → chunk-5VTBLBXJ.js} +9 -4
  28. package/dist/chunk-5VTBLBXJ.js.map +1 -0
  29. package/dist/{chunk-WW3H7VJ5.js → chunk-62PCCHZ2.js} +4 -2
  30. package/dist/chunk-62PCCHZ2.js.map +1 -0
  31. package/dist/{chunk-BK25FDTH.js → chunk-A3LYJUD4.js} +10 -5
  32. package/dist/chunk-A3LYJUD4.js.map +1 -0
  33. package/dist/{chunk-MM6JF3Z7.js → chunk-BNX3JULF.js} +3 -2
  34. package/dist/chunk-BNX3JULF.js.map +1 -0
  35. package/dist/{chunk-LGLFJL3S.js → chunk-DUVIIWFG.js} +3 -2
  36. package/dist/chunk-DUVIIWFG.js.map +1 -0
  37. package/dist/{chunk-HAEVK6IS.js → chunk-EAWGUZHS.js} +3 -2
  38. package/dist/chunk-EAWGUZHS.js.map +1 -0
  39. package/dist/{chunk-AUVJ5V47.js → chunk-GIZS4BY3.js} +6 -3
  40. package/dist/chunk-GIZS4BY3.js.map +1 -0
  41. package/dist/{chunk-XMEP74BU.js → chunk-K3VQLW3P.js} +7 -4
  42. package/dist/chunk-K3VQLW3P.js.map +1 -0
  43. package/dist/{chunk-Z6PNI5VT.js → chunk-NE7MIZPR.js} +5 -3
  44. package/dist/chunk-NE7MIZPR.js.map +1 -0
  45. package/dist/{chunk-TLH6SLAF.js → chunk-NEXUWPHW.js} +28 -34
  46. package/dist/chunk-NEXUWPHW.js.map +1 -0
  47. package/dist/{chunk-WSXRUYBE.js → chunk-OTG2S2L4.js} +4 -3
  48. package/dist/chunk-OTG2S2L4.js.map +1 -0
  49. package/dist/{chunk-I3YYGSN2.js → chunk-PAT4CS36.js} +4 -3
  50. package/dist/chunk-PAT4CS36.js.map +1 -0
  51. package/dist/{chunk-OMYVOOSX.js → chunk-RYQVMR26.js} +4 -3
  52. package/dist/chunk-RYQVMR26.js.map +1 -0
  53. package/dist/{chunk-KTODT6DV.js → chunk-UWGGF4MC.js} +7 -3
  54. package/dist/chunk-UWGGF4MC.js.map +1 -0
  55. package/dist/{chunk-HKPZI7Y5.js → chunk-XEJPH6UN.js} +4 -3
  56. package/dist/chunk-XEJPH6UN.js.map +1 -0
  57. package/dist/companies.cjs +1 -0
  58. package/dist/companies.cjs.map +1 -1
  59. package/dist/companies.d.cts +2 -1
  60. package/dist/companies.d.ts +2 -1
  61. package/dist/companies.js +1 -1
  62. package/dist/contacts.cjs +1 -0
  63. package/dist/contacts.cjs.map +1 -1
  64. package/dist/contacts.d.cts +2 -1
  65. package/dist/contacts.d.ts +2 -1
  66. package/dist/contacts.js +1 -1
  67. package/dist/{context-CD7F_LHT.d.cts → context-DhoFgoKf.d.cts} +13 -0
  68. package/dist/{context-CD7F_LHT.d.ts → context-DhoFgoKf.d.ts} +13 -0
  69. package/dist/customer-groups.cjs +1 -0
  70. package/dist/customer-groups.cjs.map +1 -1
  71. package/dist/customer-groups.d.cts +2 -1
  72. package/dist/customer-groups.d.ts +2 -1
  73. package/dist/customer-groups.js +1 -1
  74. package/dist/customer.cjs +24 -31
  75. package/dist/customer.cjs.map +1 -1
  76. package/dist/customer.d.cts +2 -1
  77. package/dist/customer.d.ts +2 -1
  78. package/dist/customer.js +3 -3
  79. package/dist/index.cjs +310 -151
  80. package/dist/index.cjs.map +1 -1
  81. package/dist/index.d.cts +84 -6
  82. package/dist/index.d.ts +84 -6
  83. package/dist/index.js +278 -148
  84. package/dist/index.js.map +1 -1
  85. package/dist/locations.cjs +1 -0
  86. package/dist/locations.cjs.map +1 -1
  87. package/dist/locations.d.cts +2 -1
  88. package/dist/locations.d.ts +2 -1
  89. package/dist/locations.js +1 -1
  90. package/dist/media.cjs +1 -0
  91. package/dist/media.cjs.map +1 -1
  92. package/dist/media.d.cts +2 -1
  93. package/dist/media.d.ts +2 -1
  94. package/dist/media.js +2 -2
  95. package/dist/orders.cjs +2 -0
  96. package/dist/orders.cjs.map +1 -1
  97. package/dist/orders.d.cts +3 -1
  98. package/dist/orders.d.ts +3 -1
  99. package/dist/orders.js +1 -1
  100. package/dist/payment.cjs +1 -0
  101. package/dist/payment.cjs.map +1 -1
  102. package/dist/payment.d.cts +2 -1
  103. package/dist/payment.d.ts +2 -1
  104. package/dist/payment.js +3 -3
  105. package/dist/price.cjs +7 -2
  106. package/dist/price.cjs.map +1 -1
  107. package/dist/price.d.cts +2 -1
  108. package/dist/price.d.ts +2 -1
  109. package/dist/price.js +2 -2
  110. package/dist/product.cjs +7 -2
  111. package/dist/product.cjs.map +1 -1
  112. package/dist/product.d.cts +2 -1
  113. package/dist/product.d.ts +2 -1
  114. package/dist/product.js +1 -1
  115. package/dist/segment.cjs +2 -0
  116. package/dist/segment.cjs.map +1 -1
  117. package/dist/segment.d.cts +3 -1
  118. package/dist/segment.d.ts +3 -1
  119. package/dist/segment.js +3 -3
  120. package/package.json +2 -1
  121. package/dist/chunk-AUVJ5V47.js.map +0 -1
  122. package/dist/chunk-B4UOYJKW.js.map +0 -1
  123. package/dist/chunk-BK25FDTH.js.map +0 -1
  124. package/dist/chunk-HAEVK6IS.js.map +0 -1
  125. package/dist/chunk-HKPZI7Y5.js.map +0 -1
  126. package/dist/chunk-I3YYGSN2.js.map +0 -1
  127. package/dist/chunk-KTODT6DV.js.map +0 -1
  128. package/dist/chunk-LGLFJL3S.js.map +0 -1
  129. package/dist/chunk-LGOC5XOI.js.map +0 -1
  130. package/dist/chunk-MM6JF3Z7.js.map +0 -1
  131. package/dist/chunk-OMYVOOSX.js.map +0 -1
  132. package/dist/chunk-TLH6SLAF.js.map +0 -1
  133. package/dist/chunk-WSXRUYBE.js.map +0 -1
  134. package/dist/chunk-WW3H7VJ5.js.map +0 -1
  135. package/dist/chunk-XMEP74BU.js.map +0 -1
  136. package/dist/chunk-Z6PNI5VT.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,37 +1,37 @@
1
- import { LocationsService } from './chunk-LGLFJL3S.js';
2
- export { LocationsService } from './chunk-LGLFJL3S.js';
3
- import { MediaService } from './chunk-WSXRUYBE.js';
4
- export { MediaService } from './chunk-WSXRUYBE.js';
5
- import { OrdersService, SalesOrdersService } from './chunk-WW3H7VJ5.js';
6
- export { OrdersService, SalesOrdersService } from './chunk-WW3H7VJ5.js';
7
- import { PaymentGatewayService } from './chunk-HKPZI7Y5.js';
8
- export { PaymentGatewayService } from './chunk-HKPZI7Y5.js';
9
- import { PriceService } from './chunk-BK25FDTH.js';
10
- export { PriceService } from './chunk-BK25FDTH.js';
11
- import { ProductService } from './chunk-B4UOYJKW.js';
12
- export { ProductService } from './chunk-B4UOYJKW.js';
13
- import { SegmentService } from './chunk-Z6PNI5VT.js';
14
- export { SegmentService } from './chunk-Z6PNI5VT.js';
15
- import { AvailabilityService } from './chunk-XMEP74BU.js';
16
- export { AvailabilityService } from './chunk-XMEP74BU.js';
17
- import { CartService } from './chunk-I3YYGSN2.js';
18
- export { CartService } from './chunk-I3YYGSN2.js';
19
- import { CategoryService } from './chunk-AUVJ5V47.js';
20
- export { CategoryService } from './chunk-AUVJ5V47.js';
1
+ import { LocationsService } from './chunk-DUVIIWFG.js';
2
+ export { LocationsService } from './chunk-DUVIIWFG.js';
3
+ import { MediaService } from './chunk-OTG2S2L4.js';
4
+ export { MediaService } from './chunk-OTG2S2L4.js';
5
+ import { OrdersService, SalesOrdersService } from './chunk-62PCCHZ2.js';
6
+ export { OrdersService, SalesOrdersService } from './chunk-62PCCHZ2.js';
7
+ import { PaymentGatewayService } from './chunk-XEJPH6UN.js';
8
+ export { PaymentGatewayService } from './chunk-XEJPH6UN.js';
9
+ import { PriceService } from './chunk-A3LYJUD4.js';
10
+ export { PriceService } from './chunk-A3LYJUD4.js';
11
+ import { ProductService } from './chunk-5VTBLBXJ.js';
12
+ export { ProductService } from './chunk-5VTBLBXJ.js';
13
+ import { SegmentService } from './chunk-NE7MIZPR.js';
14
+ export { SegmentService } from './chunk-NE7MIZPR.js';
15
+ import { AvailabilityService } from './chunk-K3VQLW3P.js';
16
+ export { AvailabilityService } from './chunk-K3VQLW3P.js';
17
+ import { CartService } from './chunk-PAT4CS36.js';
18
+ export { CartService } from './chunk-PAT4CS36.js';
19
+ import { CategoryService } from './chunk-GIZS4BY3.js';
20
+ export { CategoryService } from './chunk-GIZS4BY3.js';
21
21
  export { iterateAll } from './chunk-GWJ2U2CP.js';
22
- import { CheckoutService } from './chunk-OMYVOOSX.js';
23
- export { CheckoutService } from './chunk-OMYVOOSX.js';
24
- import { CompaniesService } from './chunk-MM6JF3Z7.js';
25
- export { CompaniesService } from './chunk-MM6JF3Z7.js';
26
- import { ContactsService } from './chunk-HAEVK6IS.js';
27
- export { ContactsService } from './chunk-HAEVK6IS.js';
28
- import { CustomerGroupsService } from './chunk-LGOC5XOI.js';
29
- export { CustomerGroupsService } from './chunk-LGOC5XOI.js';
30
- import { CustomerService } from './chunk-TLH6SLAF.js';
31
- export { CustomerService } from './chunk-TLH6SLAF.js';
32
- import './chunk-BFQ732VZ.js';
33
- import { EmporixAuthError, errorFromResponse, EmporixNotFoundError } from './chunk-KTODT6DV.js';
34
- export { EmporixAuthError, EmporixError, EmporixForbiddenError, EmporixInsufficientScopeError, EmporixNotFoundError, EmporixServerError, EmporixValidationError, errorFromResponse } from './chunk-KTODT6DV.js';
22
+ import { CheckoutService } from './chunk-RYQVMR26.js';
23
+ export { CheckoutService } from './chunk-RYQVMR26.js';
24
+ import { CompaniesService } from './chunk-BNX3JULF.js';
25
+ export { CompaniesService } from './chunk-BNX3JULF.js';
26
+ import { ContactsService } from './chunk-EAWGUZHS.js';
27
+ export { ContactsService } from './chunk-EAWGUZHS.js';
28
+ import { CustomerGroupsService } from './chunk-3BTPX7IJ.js';
29
+ export { CustomerGroupsService } from './chunk-3BTPX7IJ.js';
30
+ import { CustomerService } from './chunk-NEXUWPHW.js';
31
+ export { CustomerService } from './chunk-NEXUWPHW.js';
32
+ import './chunk-3BDDYX3V.js';
33
+ import { EmporixAuthError, EmporixTimeoutError, EmporixNetworkError, errorFromResponse, EmporixNotFoundError, EmporixError } from './chunk-UWGGF4MC.js';
34
+ export { EmporixAuthError, EmporixError, EmporixForbiddenError, EmporixInsufficientScopeError, EmporixNetworkError, EmporixNotFoundError, EmporixServerError, EmporixTimeoutError, EmporixValidationError, errorFromResponse } from './chunk-UWGGF4MC.js';
35
35
 
36
36
  // src/core/config.ts
37
37
  var DEFAULT_HOST = "https://api.emporix.io";
@@ -407,6 +407,26 @@ var DefaultTokenProvider = class {
407
407
  this.serviceLocks.set(set, p);
408
408
  return p;
409
409
  }
410
+ /**
411
+ * fetch with the configured read timeout. Token endpoints sit in front of
412
+ * single-flight locks — one hung call would otherwise block every request
413
+ * on this credential set forever.
414
+ */
415
+ async boundedFetch(url, init = {}) {
416
+ const ms = this.cfg.timeouts?.readMs ?? 6e4;
417
+ const controller = new AbortController();
418
+ const timer = setTimeout(() => controller.abort(), ms);
419
+ try {
420
+ return await fetch(url, { ...init, signal: controller.signal });
421
+ } catch (err) {
422
+ if (err.name === "AbortError") {
423
+ throw new EmporixTimeoutError(`token request timed out after ${ms}ms`);
424
+ }
425
+ throw new EmporixNetworkError(`token request network failure: ${err.message}`);
426
+ } finally {
427
+ clearTimeout(timer);
428
+ }
429
+ }
410
430
  async requestServiceToken(set) {
411
431
  const c = this.creds(set);
412
432
  const body = new URLSearchParams({
@@ -415,7 +435,7 @@ var DefaultTokenProvider = class {
415
435
  client_secret: c.secret
416
436
  });
417
437
  if (c.scope) body.set("scope", c.scope);
418
- const res = await fetch(`${this.cfg.host}/oauth/token`, {
438
+ const res = await this.boundedFetch(`${this.cfg.host}/oauth/token`, {
419
439
  method: "POST",
420
440
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
421
441
  body
@@ -488,7 +508,7 @@ var DefaultTokenProvider = class {
488
508
  url.searchParams.set("refresh_token", this.anon.refreshToken);
489
509
  }
490
510
  try {
491
- const res = await fetch(url, { method: "GET" });
511
+ const res = await this.boundedFetch(url, { method: "GET" });
492
512
  const json = await res.json().catch(() => ({}));
493
513
  if (!res.ok) {
494
514
  this.notifyRefresh("anonymous", false);
@@ -564,10 +584,18 @@ var HttpClient = class {
564
584
  attempt
565
585
  });
566
586
  const controller = new AbortController();
567
- const timer = setTimeout(
568
- () => controller.abort(),
569
- o.timeoutMs ?? this.opts.timeouts.readMs
570
- );
587
+ const overallMs = o.timeoutMs ?? this.opts.timeouts.readMs;
588
+ const connectMs = Math.min(this.opts.timeouts.connectMs, overallMs);
589
+ const timeoutMsg = `${o.method} ${o.path} timed out after ${overallMs}ms (connect budget ${connectMs}ms)`;
590
+ let connectTimer;
591
+ let overallTimer;
592
+ const overallBudget = new Promise((_, reject) => {
593
+ overallTimer = setTimeout(() => {
594
+ controller.abort();
595
+ reject(new EmporixTimeoutError(timeoutMsg));
596
+ }, overallMs);
597
+ });
598
+ connectTimer = setTimeout(() => controller.abort(), connectMs);
571
599
  const isFormData = typeof FormData !== "undefined" && o.body instanceof FormData;
572
600
  const init = {
573
601
  method: o.method,
@@ -578,12 +606,27 @@ var HttpClient = class {
578
606
  init.body = isFormData ? o.body : JSON.stringify(o.body);
579
607
  }
580
608
  let res;
609
+ let text;
581
610
  try {
582
- res = await fetch(url, init);
611
+ res = await Promise.race([fetch(url, init), overallBudget]);
612
+ clearTimeout(connectTimer);
613
+ connectTimer = void 0;
614
+ const body = res.text();
615
+ body.catch(() => {
616
+ });
617
+ text = await Promise.race([body, overallBudget]);
618
+ } catch (err) {
619
+ if (err instanceof EmporixTimeoutError) throw err;
620
+ if (err.name === "AbortError") {
621
+ throw new EmporixTimeoutError(timeoutMsg);
622
+ }
623
+ throw new EmporixNetworkError(
624
+ `${o.method} ${o.path} network failure: ${err.message}`
625
+ );
583
626
  } finally {
584
- clearTimeout(timer);
627
+ if (connectTimer !== void 0) clearTimeout(connectTimer);
628
+ if (overallTimer !== void 0) clearTimeout(overallTimer);
585
629
  }
586
- const text = await res.text();
587
630
  const parsed = text ? safeJson(text) : void 0;
588
631
  if (res.ok) {
589
632
  log.debug("http ok", { status: res.status });
@@ -613,10 +656,12 @@ var HttpClient = class {
613
656
  }
614
657
  throw errorFromResponse(res.status, `${o.method} ${o.path} \u2192 401`, parsed);
615
658
  }
616
- const retryable = res.status >= 500 || res.status === 429;
659
+ const idempotent = o.method === "GET" || o.method === "PUT" || o.method === "DELETE" || o.idempotent === true;
660
+ const retryable = idempotent && (res.status >= 500 || res.status === 429);
617
661
  if (retryable && attempt < maxAttempts) {
618
- const retryAfter = Number(res.headers.get("Retry-After"));
619
- const backoff = Number.isFinite(retryAfter) && retryAfter >= 0 ? retryAfter * 1e3 : Math.min(1e3 * 2 ** (attempt - 1), 8e3) + Math.random() * 100;
662
+ const retryAfterHeader = res.headers.get("Retry-After");
663
+ const retryAfter = retryAfterHeader ? Number(retryAfterHeader) : Number.NaN;
664
+ const backoff = Number.isFinite(retryAfter) && retryAfter >= 0 ? Math.min(retryAfter * 1e3, 8e3) : Math.min(1e3 * 2 ** (attempt - 1), 8e3) + Math.random() * 100;
620
665
  log.warn("retryable failure", { status: res.status, attempt, backoffMs: backoff });
621
666
  await this.sleep(backoff);
622
667
  continue;
@@ -668,12 +713,90 @@ var HttpClient = class {
668
713
  }
669
714
  try {
670
715
  return await fetch(url, init);
716
+ } catch (err) {
717
+ if (err.name === "AbortError") {
718
+ throw new EmporixTimeoutError(
719
+ `${o.method} ${o.path} timed out after ${o.timeoutMs ?? this.opts.timeouts.readMs}ms`
720
+ );
721
+ }
722
+ throw new EmporixNetworkError(
723
+ `${o.method} ${o.path} network failure: ${err.message}`
724
+ );
671
725
  } finally {
672
726
  clearTimeout(timer);
673
727
  }
674
728
  }
675
729
  };
676
730
 
731
+ // package.json
732
+ var version = "2.15.0";
733
+
734
+ // src/version.ts
735
+ var SDK_VERSION = version;
736
+
737
+ // src/core/create-core.ts
738
+ function createCore(config) {
739
+ const cfg = validateConfig(config);
740
+ let loggerObj = {};
741
+ let baseLogger;
742
+ if (cfg.logger === false) {
743
+ baseLogger = createNoopLogger();
744
+ } else if (cfg.logger && typeof cfg.logger.child === "function") {
745
+ baseLogger = cfg.logger;
746
+ } else if (cfg.logger) {
747
+ loggerObj = cfg.logger;
748
+ }
749
+ const resolver = new LevelResolver(loggerObj);
750
+ const root = baseLogger ?? createConsoleLogger(resolver, {
751
+ sdk: "emporix",
752
+ sdkVersion: SDK_VERSION,
753
+ tenant: cfg.tenant
754
+ });
755
+ const tokenProvider = cfg.tokenProvider ?? new DefaultTokenProvider(cfg);
756
+ const customerRefresh = new CustomerRefreshRegistry();
757
+ const requestContext = {
758
+ language: cfg.credentials.storefront?.context?.language
759
+ };
760
+ const mk = (service) => ({
761
+ tenant: cfg.tenant,
762
+ tokenProvider,
763
+ logger: root.child({ service }),
764
+ http: new HttpClient({
765
+ host: cfg.host,
766
+ provider: tokenProvider,
767
+ logger: root.child({ service: "http" }),
768
+ retry: cfg.retry,
769
+ timeouts: cfg.timeouts,
770
+ customerRefresh,
771
+ requestContext
772
+ })
773
+ });
774
+ return {
775
+ tenant: cfg.tenant,
776
+ config: cfg,
777
+ tokenProvider,
778
+ mk,
779
+ setStorefrontContext(ctx) {
780
+ if (ctx.language !== void 0) {
781
+ requestContext.language = ctx.language || void 0;
782
+ }
783
+ const { language: _language, ...priceContext } = ctx;
784
+ if (Object.keys(priceContext).length > 0) {
785
+ tokenProvider.setAnonymousContext?.(priceContext);
786
+ }
787
+ },
788
+ setLogLevel(level, opts = {}) {
789
+ resolver.set(level, opts.service, opts.force ?? false);
790
+ },
791
+ getLogLevel(service) {
792
+ return resolver.get(service);
793
+ },
794
+ setCustomerTokenRefresher(refresher) {
795
+ customerRefresh.set(refresher);
796
+ }
797
+ };
798
+ }
799
+
677
800
  // src/services/site.ts
678
801
  var ANON = auth.anonymous();
679
802
  var SiteService = class {
@@ -681,6 +804,7 @@ var SiteService = class {
681
804
  this.ctx = ctx;
682
805
  }
683
806
  ctx;
807
+ static channel = "site";
684
808
  /** Lists active sites. */
685
809
  async list(authCtx = ANON) {
686
810
  return this.ctx.http.request({
@@ -720,6 +844,7 @@ var SessionContextService = class {
720
844
  this.ctx = ctx;
721
845
  }
722
846
  ctx;
847
+ static channel = "session-context";
723
848
  /**
724
849
  * Retrieves the current session context, or `null` when the server returns
725
850
  * 404 (no session exists yet — the session-context is created server-side
@@ -783,6 +908,7 @@ var TenantConfigService = class {
783
908
  this.ctx = ctx;
784
909
  }
785
910
  ctx;
911
+ static channel = "configuration";
786
912
  base() {
787
913
  return `/configuration/${this.ctx.tenant}/configurations`;
788
914
  }
@@ -839,6 +965,7 @@ var ClientConfigService = class {
839
965
  this.ctx = ctx;
840
966
  }
841
967
  ctx;
968
+ static channel = "configuration";
842
969
  base(client) {
843
970
  return `/configuration/${this.ctx.tenant}/clients/${encodeURIComponent(client)}/configurations`;
844
971
  }
@@ -896,6 +1023,7 @@ var ShoppingListService = class {
896
1023
  this.ctx = ctx;
897
1024
  }
898
1025
  ctx;
1026
+ static channel = "shopping-list";
899
1027
  base() {
900
1028
  return `/shoppinglist/${this.ctx.tenant}/shopping-lists`;
901
1029
  }
@@ -992,6 +1120,7 @@ var RagIndexerService = class {
992
1120
  this.ctx = ctx;
993
1121
  }
994
1122
  ctx;
1123
+ static channel = "ai-rag-indexer";
995
1124
  base(type) {
996
1125
  return `/ai-rag-indexer/${this.ctx.tenant}/${encodeURIComponent(type)}`;
997
1126
  }
@@ -1032,6 +1161,7 @@ var SequentialIdService = class {
1032
1161
  this.ctx = ctx;
1033
1162
  }
1034
1163
  ctx;
1164
+ static channel = "sequential-id";
1035
1165
  base() {
1036
1166
  return `/sequential-id/${this.ctx.tenant}/schemas`;
1037
1167
  }
@@ -1121,6 +1251,7 @@ var FeeService = class {
1121
1251
  this.ctx = ctx;
1122
1252
  }
1123
1253
  ctx;
1254
+ static channel = "fee";
1124
1255
  feesBase() {
1125
1256
  return `/fee/${this.ctx.tenant}/fees`;
1126
1257
  }
@@ -1280,6 +1411,7 @@ var CloudFunctionsService = class {
1280
1411
  this.ctx = ctx;
1281
1412
  }
1282
1413
  ctx;
1414
+ static channel = "cloud-functions";
1283
1415
  base() {
1284
1416
  return `/cloud-functions/${this.ctx.tenant}/functions`;
1285
1417
  }
@@ -1303,6 +1435,7 @@ var WebhookService = class {
1303
1435
  this.ctx = ctx;
1304
1436
  }
1305
1437
  ctx;
1438
+ static channel = "webhook";
1306
1439
  base() {
1307
1440
  return `/webhook/${this.ctx.tenant}`;
1308
1441
  }
@@ -1415,6 +1548,7 @@ var SchemaService = class {
1415
1548
  this.ctx = ctx;
1416
1549
  }
1417
1550
  ctx;
1551
+ static channel = "schema";
1418
1552
  schemasBase() {
1419
1553
  return `/schema/${this.ctx.tenant}/schemas`;
1420
1554
  }
@@ -1642,6 +1776,7 @@ var AiService = class {
1642
1776
  this.ctx = ctx;
1643
1777
  }
1644
1778
  ctx;
1779
+ static channel = "ai";
1645
1780
  base() {
1646
1781
  return `/ai-service/${this.ctx.tenant}`;
1647
1782
  }
@@ -1755,6 +1890,7 @@ var TaxService = class {
1755
1890
  this.ctx = ctx;
1756
1891
  }
1757
1892
  ctx;
1893
+ static channel = "tax";
1758
1894
  base() {
1759
1895
  return `/tax/${this.ctx.tenant}`;
1760
1896
  }
@@ -1824,6 +1960,7 @@ var CouponService = class {
1824
1960
  this.ctx = ctx;
1825
1961
  }
1826
1962
  ctx;
1963
+ static channel = "coupon";
1827
1964
  base() {
1828
1965
  return `/coupon/${this.ctx.tenant}`;
1829
1966
  }
@@ -1950,6 +2087,7 @@ var RewardPointsService = class {
1950
2087
  this.ctx = ctx;
1951
2088
  }
1952
2089
  ctx;
2090
+ static channel = "reward-points";
1953
2091
  /** Base without tenant (customer / public / batch endpoints). */
1954
2092
  base() {
1955
2093
  return `/reward-points`;
@@ -2104,6 +2242,7 @@ var BrandService = class {
2104
2242
  this.ctx = ctx;
2105
2243
  }
2106
2244
  ctx;
2245
+ static channel = "brand";
2107
2246
  base() {
2108
2247
  return `/brand/brands`;
2109
2248
  }
@@ -2168,6 +2307,7 @@ var LabelService = class {
2168
2307
  this.ctx = ctx;
2169
2308
  }
2170
2309
  ctx;
2310
+ static channel = "label";
2171
2311
  base() {
2172
2312
  return `/label/labels`;
2173
2313
  }
@@ -2232,6 +2372,7 @@ var CountryService = class {
2232
2372
  this.ctx = ctx;
2233
2373
  }
2234
2374
  ctx;
2375
+ static channel = "country";
2235
2376
  base() {
2236
2377
  return `/country/${this.ctx.tenant}`;
2237
2378
  }
@@ -2287,6 +2428,7 @@ var CurrencyService = class {
2287
2428
  this.ctx = ctx;
2288
2429
  }
2289
2430
  ctx;
2431
+ static channel = "currency";
2290
2432
  base() {
2291
2433
  return `/currency/${this.ctx.tenant}`;
2292
2434
  }
@@ -2387,6 +2529,7 @@ var ShippingService = class {
2387
2529
  this.ctx = ctx;
2388
2530
  }
2389
2531
  ctx;
2532
+ static channel = "shipping";
2390
2533
  base() {
2391
2534
  return `/shipping/${this.ctx.tenant}`;
2392
2535
  }
@@ -2801,6 +2944,7 @@ var ReturnsService = class {
2801
2944
  this.ctx = ctx;
2802
2945
  }
2803
2946
  ctx;
2947
+ static channel = "returns";
2804
2948
  base() {
2805
2949
  return `/return/${this.ctx.tenant}/returns`;
2806
2950
  }
@@ -2865,6 +3009,7 @@ var SepaExportService = class {
2865
3009
  this.ctx = ctx;
2866
3010
  }
2867
3011
  ctx;
3012
+ static channel = "sepa-export";
2868
3013
  base() {
2869
3014
  return `/sepa-export/${this.ctx.tenant}`;
2870
3015
  }
@@ -2905,6 +3050,7 @@ var IndexingService = class {
2905
3050
  this.ctx = ctx;
2906
3051
  }
2907
3052
  ctx;
3053
+ static channel = "indexing";
2908
3054
  base() {
2909
3055
  return `/indexing/${this.ctx.tenant}`;
2910
3056
  }
@@ -2971,6 +3117,7 @@ var UnitHandlingService = class {
2971
3117
  this.ctx = ctx;
2972
3118
  }
2973
3119
  ctx;
3120
+ static channel = "unit-handling";
2974
3121
  base() {
2975
3122
  return `/unit-handling/${this.ctx.tenant}`;
2976
3123
  }
@@ -3052,6 +3199,7 @@ var CatalogService = class {
3052
3199
  this.ctx = ctx;
3053
3200
  }
3054
3201
  ctx;
3202
+ static channel = "catalog";
3055
3203
  base() {
3056
3204
  return `/catalog/${this.ctx.tenant}/catalogs`;
3057
3205
  }
@@ -3119,6 +3267,7 @@ var VendorService = class {
3119
3267
  this.ctx = ctx;
3120
3268
  }
3121
3269
  ctx;
3270
+ static channel = "vendor";
3122
3271
  base() {
3123
3272
  return `/vendor/${this.ctx.tenant}`;
3124
3273
  }
@@ -3218,6 +3367,7 @@ var PickPackService = class {
3218
3367
  this.ctx = ctx;
3219
3368
  }
3220
3369
  ctx;
3370
+ static channel = "pick-pack";
3221
3371
  base() {
3222
3372
  return `/pick-pack/${this.ctx.tenant}`;
3223
3373
  }
@@ -3309,6 +3459,7 @@ var CustomerAdminService = class {
3309
3459
  this.ctx = ctx;
3310
3460
  }
3311
3461
  ctx;
3462
+ static channel = "customer-admin";
3312
3463
  base() {
3313
3464
  return `/customer/${this.ctx.tenant}/customers`;
3314
3465
  }
@@ -3413,6 +3564,7 @@ var ApprovalService = class {
3413
3564
  this.ctx = ctx;
3414
3565
  }
3415
3566
  ctx;
3567
+ static channel = "approval";
3416
3568
  base() {
3417
3569
  return `/approval/${this.ctx.tenant}`;
3418
3570
  }
@@ -3479,12 +3631,6 @@ var ApprovalService = class {
3479
3631
  }
3480
3632
  };
3481
3633
 
3482
- // package.json
3483
- var version = "2.13.1";
3484
-
3485
- // src/version.ts
3486
- var SDK_VERSION = version;
3487
-
3488
3634
  // src/client.ts
3489
3635
  var EmporixClient = class {
3490
3636
  customers;
@@ -3547,96 +3693,62 @@ var EmporixClient = class {
3547
3693
  * Provider tree. Treat as read-only.
3548
3694
  */
3549
3695
  config;
3550
- resolver;
3551
- customerRefresh;
3552
- requestContext;
3696
+ core;
3553
3697
  constructor(config) {
3554
- const cfg = validateConfig(config);
3555
- this.tenant = cfg.tenant;
3556
- this.config = cfg;
3557
- let loggerObj = {};
3558
- let baseLogger;
3559
- if (cfg.logger === false) {
3560
- baseLogger = createNoopLogger();
3561
- } else if (cfg.logger && typeof cfg.logger.child === "function") {
3562
- baseLogger = cfg.logger;
3563
- } else if (cfg.logger) {
3564
- loggerObj = cfg.logger;
3565
- }
3566
- this.resolver = new LevelResolver(loggerObj);
3567
- const root = baseLogger ?? createConsoleLogger(this.resolver, {
3568
- sdk: "emporix",
3569
- sdkVersion: SDK_VERSION,
3570
- tenant: cfg.tenant
3571
- });
3572
- const tokenProvider = cfg.tokenProvider ?? new DefaultTokenProvider(cfg);
3573
- this.tokenProvider = tokenProvider;
3574
- const customerRefresh = new CustomerRefreshRegistry();
3575
- this.customerRefresh = customerRefresh;
3576
- this.requestContext = { language: cfg.credentials.storefront?.context?.language };
3577
- const requestContext = this.requestContext;
3578
- const mk = (service) => ({
3579
- tenant: cfg.tenant,
3580
- tokenProvider,
3581
- logger: root.child({ service }),
3582
- http: new HttpClient({
3583
- host: cfg.host,
3584
- provider: tokenProvider,
3585
- logger: root.child({ service: "http" }),
3586
- retry: cfg.retry,
3587
- timeouts: cfg.timeouts,
3588
- customerRefresh,
3589
- requestContext
3590
- })
3591
- });
3592
- this.customers = new CustomerService(mk("customer"));
3593
- this.products = new ProductService(mk("product"));
3594
- this.categories = new CategoryService(mk("category"));
3595
- this.carts = new CartService(mk("cart"));
3596
- this.checkout = new CheckoutService(mk("checkout"));
3597
- this.payments = new PaymentGatewayService(mk("payment"));
3598
- this.prices = new PriceService(mk("price"));
3599
- this.media = new MediaService(mk("media"));
3600
- this.segments = new SegmentService(mk("segment"), {
3698
+ const core = createCore(config);
3699
+ this.core = core;
3700
+ this.tenant = core.tenant;
3701
+ this.config = core.config;
3702
+ this.tokenProvider = core.tokenProvider;
3703
+ const mk = core.mk;
3704
+ this.customers = new CustomerService(mk(CustomerService.channel));
3705
+ this.products = new ProductService(mk(ProductService.channel));
3706
+ this.categories = new CategoryService(mk(CategoryService.channel));
3707
+ this.carts = new CartService(mk(CartService.channel));
3708
+ this.checkout = new CheckoutService(mk(CheckoutService.channel));
3709
+ this.payments = new PaymentGatewayService(mk(PaymentGatewayService.channel));
3710
+ this.prices = new PriceService(mk(PriceService.channel));
3711
+ this.media = new MediaService(mk(MediaService.channel));
3712
+ this.segments = new SegmentService(mk(SegmentService.channel), {
3601
3713
  products: this.products,
3602
3714
  categories: this.categories
3603
3715
  });
3604
- this.sites = new SiteService(mk("site"));
3605
- this.sessionContext = new SessionContextService(mk("session-context"));
3606
- this.companies = new CompaniesService(mk("customer-management"));
3607
- this.contacts = new ContactsService(mk("customer-management"));
3608
- this.locations = new LocationsService(mk("customer-management"));
3609
- this.customerGroups = new CustomerGroupsService(mk("iam"));
3610
- this.orders = new OrdersService(mk("orders"));
3611
- this.salesOrders = new SalesOrdersService(mk("sales-orders"));
3612
- this.availability = new AvailabilityService(mk("availability"));
3613
- this.tenantConfig = new TenantConfigService(mk("configuration"));
3614
- this.clientConfig = new ClientConfigService(mk("configuration"));
3615
- this.shoppingLists = new ShoppingListService(mk("shopping-list"));
3616
- this.ragIndexer = new RagIndexerService(mk("ai-rag-indexer"));
3617
- this.sequentialIds = new SequentialIdService(mk("sequential-id"));
3618
- this.fees = new FeeService(mk("fee"));
3619
- this.cloudFunctions = new CloudFunctionsService(mk("cloud-functions"));
3620
- this.webhooks = new WebhookService(mk("webhook"));
3621
- this.schemas = new SchemaService(mk("schema"));
3622
- this.ai = new AiService(mk("ai"));
3623
- this.taxes = new TaxService(mk("tax"));
3624
- this.coupons = new CouponService(mk("coupon"));
3625
- this.rewardPoints = new RewardPointsService(mk("reward-points"));
3626
- this.brands = new BrandService(mk("brand"));
3627
- this.labels = new LabelService(mk("label"));
3628
- this.countries = new CountryService(mk("country"));
3629
- this.currencies = new CurrencyService(mk("currency"));
3630
- this.shipping = new ShippingService(mk("shipping"));
3631
- this.returns = new ReturnsService(mk("returns"));
3632
- this.sepaExport = new SepaExportService(mk("sepa-export"));
3633
- this.indexing = new IndexingService(mk("indexing"));
3634
- this.units = new UnitHandlingService(mk("unit-handling"));
3635
- this.catalogs = new CatalogService(mk("catalog"));
3636
- this.vendors = new VendorService(mk("vendor"));
3637
- this.pickPack = new PickPackService(mk("pick-pack"));
3638
- this.customerAdmin = new CustomerAdminService(mk("customer-admin"));
3639
- this.approvals = new ApprovalService(mk("approval"));
3716
+ this.sites = new SiteService(mk(SiteService.channel));
3717
+ this.sessionContext = new SessionContextService(mk(SessionContextService.channel));
3718
+ this.companies = new CompaniesService(mk(CompaniesService.channel));
3719
+ this.contacts = new ContactsService(mk(ContactsService.channel));
3720
+ this.locations = new LocationsService(mk(LocationsService.channel));
3721
+ this.customerGroups = new CustomerGroupsService(mk(CustomerGroupsService.channel));
3722
+ this.orders = new OrdersService(mk(OrdersService.channel));
3723
+ this.salesOrders = new SalesOrdersService(mk(SalesOrdersService.channel));
3724
+ this.availability = new AvailabilityService(mk(AvailabilityService.channel));
3725
+ this.tenantConfig = new TenantConfigService(mk(TenantConfigService.channel));
3726
+ this.clientConfig = new ClientConfigService(mk(ClientConfigService.channel));
3727
+ this.shoppingLists = new ShoppingListService(mk(ShoppingListService.channel));
3728
+ this.ragIndexer = new RagIndexerService(mk(RagIndexerService.channel));
3729
+ this.sequentialIds = new SequentialIdService(mk(SequentialIdService.channel));
3730
+ this.fees = new FeeService(mk(FeeService.channel));
3731
+ this.cloudFunctions = new CloudFunctionsService(mk(CloudFunctionsService.channel));
3732
+ this.webhooks = new WebhookService(mk(WebhookService.channel));
3733
+ this.schemas = new SchemaService(mk(SchemaService.channel));
3734
+ this.ai = new AiService(mk(AiService.channel));
3735
+ this.taxes = new TaxService(mk(TaxService.channel));
3736
+ this.coupons = new CouponService(mk(CouponService.channel));
3737
+ this.rewardPoints = new RewardPointsService(mk(RewardPointsService.channel));
3738
+ this.brands = new BrandService(mk(BrandService.channel));
3739
+ this.labels = new LabelService(mk(LabelService.channel));
3740
+ this.countries = new CountryService(mk(CountryService.channel));
3741
+ this.currencies = new CurrencyService(mk(CurrencyService.channel));
3742
+ this.shipping = new ShippingService(mk(ShippingService.channel));
3743
+ this.returns = new ReturnsService(mk(ReturnsService.channel));
3744
+ this.sepaExport = new SepaExportService(mk(SepaExportService.channel));
3745
+ this.indexing = new IndexingService(mk(IndexingService.channel));
3746
+ this.units = new UnitHandlingService(mk(UnitHandlingService.channel));
3747
+ this.catalogs = new CatalogService(mk(CatalogService.channel));
3748
+ this.vendors = new VendorService(mk(VendorService.channel));
3749
+ this.pickPack = new PickPackService(mk(PickPackService.channel));
3750
+ this.customerAdmin = new CustomerAdminService(mk(CustomerAdminService.channel));
3751
+ this.approvals = new ApprovalService(mk(ApprovalService.channel));
3640
3752
  }
3641
3753
  /**
3642
3754
  * Re-binds the storefront price context (currency / siteCode / targetLocation)
@@ -3649,21 +3761,15 @@ var EmporixClient = class {
3649
3761
  * read); a language-only change does NOT re-mint the token.
3650
3762
  */
3651
3763
  setStorefrontContext(ctx) {
3652
- if (ctx.language !== void 0) {
3653
- this.requestContext.language = ctx.language || void 0;
3654
- }
3655
- const { language: _language, ...priceContext } = ctx;
3656
- if (Object.keys(priceContext).length > 0) {
3657
- this.tokenProvider.setAnonymousContext?.(priceContext);
3658
- }
3764
+ this.core.setStorefrontContext(ctx);
3659
3765
  }
3660
3766
  /** Sets the runtime log level globally or for one service. */
3661
3767
  setLogLevel(level, opts = {}) {
3662
- this.resolver.set(level, opts.service, opts.force ?? false);
3768
+ this.core.setLogLevel(level, opts);
3663
3769
  }
3664
3770
  /** Returns the effective log level for a service. */
3665
3771
  getLogLevel(service) {
3666
- return this.resolver.get(service);
3772
+ return this.core.getLogLevel(service);
3667
3773
  }
3668
3774
  /**
3669
3775
  * Registers (or clears with `null`) a customer-token refresher. When set, a
@@ -3672,10 +3778,34 @@ var EmporixClient = class {
3672
3778
  * automatically via `autoRefreshCustomerToken`.
3673
3779
  */
3674
3780
  setCustomerTokenRefresher(refresher) {
3675
- this.customerRefresh.set(refresher);
3781
+ this.core.setCustomerTokenRefresher(refresher);
3676
3782
  }
3677
3783
  };
3678
3784
 
3785
+ // src/create-emporix-client.ts
3786
+ function createEmporixClient(config, services) {
3787
+ const { mk, ...core } = createCore(config);
3788
+ const built = {};
3789
+ const entries = Object.entries(services);
3790
+ for (const [key, Svc] of entries) {
3791
+ if (!Svc.deps?.length) built[key] = new Svc(mk(Svc.channel));
3792
+ }
3793
+ for (const [key, Svc] of entries) {
3794
+ if (!Svc.deps?.length) continue;
3795
+ const deps = {};
3796
+ for (const dep of Svc.deps) {
3797
+ if (!(dep in built)) {
3798
+ throw new EmporixError(
3799
+ `createEmporixClient: "${key}" requires "${dep}" in the services map`
3800
+ );
3801
+ }
3802
+ deps[dep] = built[dep];
3803
+ }
3804
+ built[key] = new Svc(mk(Svc.channel), deps);
3805
+ }
3806
+ return { ...core, ...built };
3807
+ }
3808
+
3679
3809
  // src/core/yrn.ts
3680
3810
  function productIdFromYrn(yrn) {
3681
3811
  if (!yrn) return "";
@@ -3683,6 +3813,6 @@ function productIdFromYrn(yrn) {
3683
3813
  return semi >= 0 ? yrn.slice(semi + 1) : "";
3684
3814
  }
3685
3815
 
3686
- export { AiService, ApprovalService, BrandService, CatalogService, ClientConfigService, CloudFunctionsService, CountryService, CouponService, CurrencyService, CustomerAdminService, CustomerRefreshRegistry, DEFAULT_HOST, DefaultTokenProvider, EmporixClient, FeeService, HttpClient, IndexingService, LEVEL, LabelService, LevelResolver, PickPackService, RagIndexerService, ReturnsService, RewardPointsService, SchemaService, SepaExportService, SequentialIdService, SessionContextService, ShippingService, ShoppingListService, SiteService, TaxService, TenantConfigService, UnitHandlingService, VendorService, WebhookService, auth, createConsoleLogger, createNoopLogger, productIdFromYrn, redact, resolveToken, validateConfig };
3816
+ export { AiService, ApprovalService, BrandService, CatalogService, ClientConfigService, CloudFunctionsService, CountryService, CouponService, CurrencyService, CustomerAdminService, CustomerRefreshRegistry, DEFAULT_HOST, DefaultTokenProvider, EmporixClient, FeeService, HttpClient, IndexingService, LEVEL, LabelService, LevelResolver, PickPackService, RagIndexerService, ReturnsService, RewardPointsService, SchemaService, SepaExportService, SequentialIdService, SessionContextService, ShippingService, ShoppingListService, SiteService, TaxService, TenantConfigService, UnitHandlingService, VendorService, WebhookService, auth, createConsoleLogger, createCore, createEmporixClient, createNoopLogger, productIdFromYrn, redact, resolveToken, validateConfig };
3687
3817
  //# sourceMappingURL=index.js.map
3688
3818
  //# sourceMappingURL=index.js.map