@viu/emporix-sdk 2.14.0 → 2.16.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 (129) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/availability.cjs +1 -0
  3. package/dist/availability.cjs.map +1 -1
  4. package/dist/availability.d.cts +1 -0
  5. package/dist/availability.d.ts +1 -0
  6. package/dist/availability.js +1 -1
  7. package/dist/cart.cjs +1 -0
  8. package/dist/cart.cjs.map +1 -1
  9. package/dist/cart.d.cts +1 -0
  10. package/dist/cart.d.ts +1 -0
  11. package/dist/cart.js +1 -1
  12. package/dist/category.cjs +1 -0
  13. package/dist/category.cjs.map +1 -1
  14. package/dist/category.d.cts +1 -0
  15. package/dist/category.d.ts +1 -0
  16. package/dist/category.js +1 -1
  17. package/dist/checkout.cjs +1 -0
  18. package/dist/checkout.cjs.map +1 -1
  19. package/dist/checkout.d.cts +1 -0
  20. package/dist/checkout.d.ts +1 -0
  21. package/dist/checkout.js +1 -1
  22. package/dist/{chunk-LGOC5XOI.js → chunk-3BTPX7IJ.js} +3 -2
  23. package/dist/chunk-3BTPX7IJ.js.map +1 -0
  24. package/dist/{chunk-MIUVJEGR.js → chunk-5VTBLBXJ.js} +3 -2
  25. package/dist/chunk-5VTBLBXJ.js.map +1 -0
  26. package/dist/{chunk-WW3H7VJ5.js → chunk-62PCCHZ2.js} +4 -2
  27. package/dist/chunk-62PCCHZ2.js.map +1 -0
  28. package/dist/{chunk-BDFOD7W3.js → chunk-A3LYJUD4.js} +3 -2
  29. package/dist/chunk-A3LYJUD4.js.map +1 -0
  30. package/dist/{chunk-MM6JF3Z7.js → chunk-BNX3JULF.js} +3 -2
  31. package/dist/chunk-BNX3JULF.js.map +1 -0
  32. package/dist/{chunk-LGLFJL3S.js → chunk-DUVIIWFG.js} +3 -2
  33. package/dist/chunk-DUVIIWFG.js.map +1 -0
  34. package/dist/{chunk-HAEVK6IS.js → chunk-EAWGUZHS.js} +3 -2
  35. package/dist/chunk-EAWGUZHS.js.map +1 -0
  36. package/dist/{chunk-WWCCB22A.js → chunk-GIZS4BY3.js} +3 -2
  37. package/dist/chunk-GIZS4BY3.js.map +1 -0
  38. package/dist/{chunk-BPVMQFO4.js → chunk-K3VQLW3P.js} +3 -2
  39. package/dist/chunk-K3VQLW3P.js.map +1 -0
  40. package/dist/{chunk-CR2JRH7T.js → chunk-NE7MIZPR.js} +4 -2
  41. package/dist/chunk-NE7MIZPR.js.map +1 -0
  42. package/dist/{chunk-UOBOFCFU.js → chunk-NEXUWPHW.js} +3 -2
  43. package/dist/chunk-NEXUWPHW.js.map +1 -0
  44. package/dist/{chunk-FU5WQALW.js → chunk-OTG2S2L4.js} +3 -2
  45. package/dist/chunk-OTG2S2L4.js.map +1 -0
  46. package/dist/{chunk-P3UHYMDH.js → chunk-PAT4CS36.js} +3 -2
  47. package/dist/chunk-PAT4CS36.js.map +1 -0
  48. package/dist/chunk-PYLWZZC4.js +280 -0
  49. package/dist/chunk-PYLWZZC4.js.map +1 -0
  50. package/dist/{chunk-XG2TKFY5.js → chunk-RYQVMR26.js} +3 -2
  51. package/dist/chunk-RYQVMR26.js.map +1 -0
  52. package/dist/companies.cjs +1 -0
  53. package/dist/companies.cjs.map +1 -1
  54. package/dist/companies.d.cts +1 -0
  55. package/dist/companies.d.ts +1 -0
  56. package/dist/companies.js +1 -1
  57. package/dist/contacts.cjs +1 -0
  58. package/dist/contacts.cjs.map +1 -1
  59. package/dist/contacts.d.cts +1 -0
  60. package/dist/contacts.d.ts +1 -0
  61. package/dist/contacts.js +1 -1
  62. package/dist/customer-groups.cjs +1 -0
  63. package/dist/customer-groups.cjs.map +1 -1
  64. package/dist/customer-groups.d.cts +1 -0
  65. package/dist/customer-groups.d.ts +1 -0
  66. package/dist/customer-groups.js +1 -1
  67. package/dist/customer.cjs +1 -0
  68. package/dist/customer.cjs.map +1 -1
  69. package/dist/customer.d.cts +1 -0
  70. package/dist/customer.d.ts +1 -0
  71. package/dist/customer.js +1 -1
  72. package/dist/index.cjs +219 -119
  73. package/dist/index.cjs.map +1 -1
  74. package/dist/index.d.cts +76 -4
  75. package/dist/index.d.ts +76 -4
  76. package/dist/index.js +210 -377
  77. package/dist/index.js.map +1 -1
  78. package/dist/locations.cjs +1 -0
  79. package/dist/locations.cjs.map +1 -1
  80. package/dist/locations.d.cts +1 -0
  81. package/dist/locations.d.ts +1 -0
  82. package/dist/locations.js +1 -1
  83. package/dist/media.cjs +1 -0
  84. package/dist/media.cjs.map +1 -1
  85. package/dist/media.d.cts +1 -0
  86. package/dist/media.d.ts +1 -0
  87. package/dist/media.js +1 -1
  88. package/dist/orders.cjs +2 -0
  89. package/dist/orders.cjs.map +1 -1
  90. package/dist/orders.d.cts +2 -0
  91. package/dist/orders.d.ts +2 -0
  92. package/dist/orders.js +1 -1
  93. package/dist/payment.cjs +25 -7
  94. package/dist/payment.cjs.map +1 -1
  95. package/dist/payment.d.cts +8 -3
  96. package/dist/payment.d.ts +8 -3
  97. package/dist/payment.js +1 -1
  98. package/dist/price.cjs +1 -0
  99. package/dist/price.cjs.map +1 -1
  100. package/dist/price.d.cts +1 -0
  101. package/dist/price.d.ts +1 -0
  102. package/dist/price.js +1 -1
  103. package/dist/product.cjs +1 -0
  104. package/dist/product.cjs.map +1 -1
  105. package/dist/product.d.cts +1 -0
  106. package/dist/product.d.ts +1 -0
  107. package/dist/product.js +1 -1
  108. package/dist/segment.cjs +2 -0
  109. package/dist/segment.cjs.map +1 -1
  110. package/dist/segment.d.cts +2 -0
  111. package/dist/segment.d.ts +2 -0
  112. package/dist/segment.js +1 -1
  113. package/package.json +2 -1
  114. package/dist/chunk-BDFOD7W3.js.map +0 -1
  115. package/dist/chunk-BPVMQFO4.js.map +0 -1
  116. package/dist/chunk-CR2JRH7T.js.map +0 -1
  117. package/dist/chunk-EINAVCV2.js +0 -30
  118. package/dist/chunk-EINAVCV2.js.map +0 -1
  119. package/dist/chunk-FU5WQALW.js.map +0 -1
  120. package/dist/chunk-HAEVK6IS.js.map +0 -1
  121. package/dist/chunk-LGLFJL3S.js.map +0 -1
  122. package/dist/chunk-LGOC5XOI.js.map +0 -1
  123. package/dist/chunk-MIUVJEGR.js.map +0 -1
  124. package/dist/chunk-MM6JF3Z7.js.map +0 -1
  125. package/dist/chunk-P3UHYMDH.js.map +0 -1
  126. package/dist/chunk-UOBOFCFU.js.map +0 -1
  127. package/dist/chunk-WW3H7VJ5.js.map +0 -1
  128. package/dist/chunk-WWCCB22A.js.map +0 -1
  129. package/dist/chunk-XG2TKFY5.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -782,6 +782,75 @@ var HttpClient = class {
782
782
  }
783
783
  };
784
784
 
785
+ // package.json
786
+ var version = "2.16.0";
787
+
788
+ // src/version.ts
789
+ var SDK_VERSION = version;
790
+
791
+ // src/core/create-core.ts
792
+ function createCore(config) {
793
+ const cfg = validateConfig(config);
794
+ let loggerObj = {};
795
+ let baseLogger;
796
+ if (cfg.logger === false) {
797
+ baseLogger = createNoopLogger();
798
+ } else if (cfg.logger && typeof cfg.logger.child === "function") {
799
+ baseLogger = cfg.logger;
800
+ } else if (cfg.logger) {
801
+ loggerObj = cfg.logger;
802
+ }
803
+ const resolver = new LevelResolver(loggerObj);
804
+ const root = baseLogger ?? createConsoleLogger(resolver, {
805
+ sdk: "emporix",
806
+ sdkVersion: SDK_VERSION,
807
+ tenant: cfg.tenant
808
+ });
809
+ const tokenProvider = cfg.tokenProvider ?? new DefaultTokenProvider(cfg);
810
+ const customerRefresh = new CustomerRefreshRegistry();
811
+ const requestContext = {
812
+ language: cfg.credentials.storefront?.context?.language
813
+ };
814
+ const mk = (service) => ({
815
+ tenant: cfg.tenant,
816
+ tokenProvider,
817
+ logger: root.child({ service }),
818
+ http: new HttpClient({
819
+ host: cfg.host,
820
+ provider: tokenProvider,
821
+ logger: root.child({ service: "http" }),
822
+ retry: cfg.retry,
823
+ timeouts: cfg.timeouts,
824
+ customerRefresh,
825
+ requestContext
826
+ })
827
+ });
828
+ return {
829
+ tenant: cfg.tenant,
830
+ config: cfg,
831
+ tokenProvider,
832
+ mk,
833
+ setStorefrontContext(ctx) {
834
+ if (ctx.language !== void 0) {
835
+ requestContext.language = ctx.language || void 0;
836
+ }
837
+ const { language: _language, ...priceContext } = ctx;
838
+ if (Object.keys(priceContext).length > 0) {
839
+ tokenProvider.setAnonymousContext?.(priceContext);
840
+ }
841
+ },
842
+ setLogLevel(level, opts = {}) {
843
+ resolver.set(level, opts.service, opts.force ?? false);
844
+ },
845
+ getLogLevel(service) {
846
+ return resolver.get(service);
847
+ },
848
+ setCustomerTokenRefresher(refresher) {
849
+ customerRefresh.set(refresher);
850
+ }
851
+ };
852
+ }
853
+
785
854
  // src/core/require-customer.ts
786
855
  function requireCustomer(auth2) {
787
856
  if (auth2 && (auth2.kind === "customer" || auth2.kind === "raw")) return auth2;
@@ -809,6 +878,7 @@ var CustomerService = class {
809
878
  this.ctx = ctx;
810
879
  }
811
880
  ctx;
881
+ static channel = "customer";
812
882
  /** Obtains an anonymous storefront session (accessToken + sessionId + refreshToken). */
813
883
  async anonymous() {
814
884
  return this.ctx.tokenProvider.getAnonymousToken();
@@ -1008,6 +1078,7 @@ var ProductService = class {
1008
1078
  this.ctx = ctx;
1009
1079
  }
1010
1080
  ctx;
1081
+ static channel = "product";
1011
1082
  /** Fetches one product by id. */
1012
1083
  async get(productId, _opts, auth2 = ANON) {
1013
1084
  return this.ctx.http.request({
@@ -1169,6 +1240,7 @@ var CategoryService = class {
1169
1240
  this.ctx = ctx;
1170
1241
  }
1171
1242
  ctx;
1243
+ static channel = "category";
1172
1244
  /** Fetches one category by id. */
1173
1245
  async get(categoryId, auth2 = ANON2) {
1174
1246
  return this.ctx.http.request({
@@ -1302,6 +1374,7 @@ var CartService = class {
1302
1374
  this.ctx = ctx;
1303
1375
  }
1304
1376
  ctx;
1377
+ static channel = "cart";
1305
1378
  base() {
1306
1379
  return `/cart/${this.ctx.tenant}/carts`;
1307
1380
  }
@@ -1474,6 +1547,7 @@ var CheckoutService = class {
1474
1547
  this.ctx = ctx;
1475
1548
  }
1476
1549
  ctx;
1550
+ static channel = "checkout";
1477
1551
  headers(opts, guest) {
1478
1552
  if (guest || !opts.saasToken) return void 0;
1479
1553
  return { "saas-token": opts.saasToken };
@@ -1511,25 +1585,31 @@ var CheckoutService = class {
1511
1585
  };
1512
1586
 
1513
1587
  // src/services/payment.ts
1588
+ var ANON3 = auth.anonymous();
1514
1589
  var PaymentGatewayService = class {
1515
1590
  constructor(ctx) {
1516
1591
  this.ctx = ctx;
1517
1592
  }
1518
1593
  ctx;
1519
- /** Lists configured frontend payment modes. */
1520
- async listPaymentModes(auth2) {
1594
+ static channel = "payment";
1595
+ /**
1596
+ * Lists configured frontend payment modes. The endpoint requires a bearer
1597
+ * token but no customer scope ("No scope required"), so it defaults to an
1598
+ * anonymous context and works for guests and logged-in customers alike.
1599
+ */
1600
+ async listPaymentModes(authCtx = ANON3) {
1521
1601
  return this.ctx.http.request({
1522
1602
  method: "GET",
1523
1603
  path: `/payment-gateway/${this.ctx.tenant}/paymentmodes/frontend`,
1524
- auth: requireCustomer(auth2)
1604
+ auth: authCtx
1525
1605
  });
1526
1606
  }
1527
1607
  /** Authorizes a post-checkout (deferred) payment for an existing order. */
1528
- async authorize(input, auth2) {
1608
+ async authorize(input, authCtx) {
1529
1609
  return this.ctx.http.request({
1530
1610
  method: "POST",
1531
1611
  path: `/payment-gateway/${this.ctx.tenant}/payment/frontend/authorize`,
1532
- auth: requireCustomer(auth2),
1612
+ auth: requireCustomer(authCtx),
1533
1613
  body: input
1534
1614
  });
1535
1615
  }
@@ -1546,10 +1626,10 @@ function normalizeMatch(raw) {
1546
1626
  };
1547
1627
  return { ...base, itemId, itemRef };
1548
1628
  }
1549
- var ANON3 = { kind: "anonymous" };
1629
+ var ANON4 = { kind: "anonymous" };
1550
1630
  var SERVICE = { kind: "service" };
1551
1631
  function requireContextAuth(auth2) {
1552
- const a = auth2 ?? ANON3;
1632
+ const a = auth2 ?? ANON4;
1553
1633
  if (a.kind === "anonymous" || a.kind === "customer" || a.kind === "raw") return a;
1554
1634
  throw new EmporixAuthError(
1555
1635
  "match-prices-by-context requires an anonymous, customer, or raw AuthContext"
@@ -1560,6 +1640,7 @@ var PriceService = class {
1560
1640
  this.ctx = ctx;
1561
1641
  }
1562
1642
  ctx;
1643
+ static channel = "price";
1563
1644
  /**
1564
1645
  * Resolves prices using the session context bound to the bearer token
1565
1646
  * (currency/site/country were set at anonymous-login time). Default auth:
@@ -1647,6 +1728,7 @@ var MediaService = class {
1647
1728
  this.ctx = ctx;
1648
1729
  }
1649
1730
  ctx;
1731
+ static channel = "media";
1650
1732
  base() {
1651
1733
  return `/media/${this.ctx.tenant}/assets`;
1652
1734
  }
@@ -1892,6 +1974,8 @@ var SegmentService = class {
1892
1974
  }
1893
1975
  ctx;
1894
1976
  deps;
1977
+ static channel = "segment";
1978
+ static deps = ["products", "categories"];
1895
1979
  base() {
1896
1980
  return `/customer-segment/${this.ctx.tenant}/segments`;
1897
1981
  }
@@ -2017,14 +2101,15 @@ var SegmentService = class {
2017
2101
  };
2018
2102
 
2019
2103
  // src/services/site.ts
2020
- var ANON4 = auth.anonymous();
2104
+ var ANON5 = auth.anonymous();
2021
2105
  var SiteService = class {
2022
2106
  constructor(ctx) {
2023
2107
  this.ctx = ctx;
2024
2108
  }
2025
2109
  ctx;
2110
+ static channel = "site";
2026
2111
  /** Lists active sites. */
2027
- async list(authCtx = ANON4) {
2112
+ async list(authCtx = ANON5) {
2028
2113
  return this.ctx.http.request({
2029
2114
  method: "GET",
2030
2115
  path: `/site/${this.ctx.tenant}/sites`,
@@ -2032,7 +2117,7 @@ var SiteService = class {
2032
2117
  });
2033
2118
  }
2034
2119
  /** Retrieves one site by code. */
2035
- async get(code, authCtx = ANON4) {
2120
+ async get(code, authCtx = ANON5) {
2036
2121
  return this.ctx.http.request({
2037
2122
  method: "GET",
2038
2123
  path: `/site/${this.ctx.tenant}/sites/${code}`,
@@ -2043,7 +2128,7 @@ var SiteService = class {
2043
2128
  * Returns the tenant's default site (the one with `default: true`).
2044
2129
  * Throws if no default is configured — a tenant should always have one.
2045
2130
  */
2046
- async current(authCtx = ANON4) {
2131
+ async current(authCtx = ANON5) {
2047
2132
  const sites = await this.list(authCtx);
2048
2133
  const def = sites.find((s) => s.default);
2049
2134
  if (!def) {
@@ -2056,18 +2141,19 @@ var SiteService = class {
2056
2141
  };
2057
2142
 
2058
2143
  // src/services/session-context.ts
2059
- var ANON5 = auth.anonymous();
2144
+ var ANON6 = auth.anonymous();
2060
2145
  var SessionContextService = class {
2061
2146
  constructor(ctx) {
2062
2147
  this.ctx = ctx;
2063
2148
  }
2064
2149
  ctx;
2150
+ static channel = "session-context";
2065
2151
  /**
2066
2152
  * Retrieves the current session context, or `null` when the server returns
2067
2153
  * 404 (no session exists yet — the session-context is created server-side
2068
2154
  * only after the user creates a cart).
2069
2155
  */
2070
- async get(authCtx = ANON5) {
2156
+ async get(authCtx = ANON6) {
2071
2157
  try {
2072
2158
  return await this.ctx.http.request({
2073
2159
  method: "GET",
@@ -2085,7 +2171,7 @@ var SessionContextService = class {
2085
2171
  * server returned 404 on the version-lookup GET, so there is nothing to
2086
2172
  * update). Non-404 errors propagate.
2087
2173
  */
2088
- async patch(input, authCtx = ANON5) {
2174
+ async patch(input, authCtx = ANON6) {
2089
2175
  let version2 = input.version;
2090
2176
  if (version2 === void 0) {
2091
2177
  const current = await this.get(authCtx);
@@ -2124,6 +2210,7 @@ var CompaniesService = class {
2124
2210
  this.ctx = ctx;
2125
2211
  }
2126
2212
  ctx;
2213
+ static channel = "customer-management";
2127
2214
  base() {
2128
2215
  return `/customer-management/${this.ctx.tenant}/legal-entities`;
2129
2216
  }
@@ -2180,6 +2267,7 @@ var ContactsService = class {
2180
2267
  this.ctx = ctx;
2181
2268
  }
2182
2269
  ctx;
2270
+ static channel = "customer-management";
2183
2271
  base() {
2184
2272
  return `/customer-management/${this.ctx.tenant}/contact-assignments`;
2185
2273
  }
@@ -2229,6 +2317,7 @@ var LocationsService = class {
2229
2317
  this.ctx = ctx;
2230
2318
  }
2231
2319
  ctx;
2320
+ static channel = "customer-management";
2232
2321
  base() {
2233
2322
  return `/customer-management/${this.ctx.tenant}/locations`;
2234
2323
  }
@@ -2286,6 +2375,7 @@ var CustomerGroupsService = class {
2286
2375
  this.ctx = ctx;
2287
2376
  }
2288
2377
  ctx;
2378
+ static channel = "iam";
2289
2379
  base() {
2290
2380
  return `/iam/${this.ctx.tenant}/groups`;
2291
2381
  }
@@ -2328,6 +2418,7 @@ var OrdersService = class {
2328
2418
  this.ctx = ctx;
2329
2419
  }
2330
2420
  ctx;
2421
+ static channel = "orders";
2331
2422
  base() {
2332
2423
  return `/order-v2/${this.ctx.tenant}/orders`;
2333
2424
  }
@@ -2388,6 +2479,7 @@ var SalesOrdersService = class {
2388
2479
  this.ctx = ctx;
2389
2480
  }
2390
2481
  ctx;
2482
+ static channel = "sales-orders";
2391
2483
  base() {
2392
2484
  return `/order-v2/${this.ctx.tenant}/salesorders`;
2393
2485
  }
@@ -2414,17 +2506,18 @@ var SalesOrdersService = class {
2414
2506
  };
2415
2507
 
2416
2508
  // src/services/availability.ts
2417
- var ANON6 = { kind: "anonymous" };
2509
+ var ANON7 = { kind: "anonymous" };
2418
2510
  var AvailabilityService = class {
2419
2511
  constructor(ctx) {
2420
2512
  this.ctx = ctx;
2421
2513
  }
2422
2514
  ctx;
2515
+ static channel = "availability";
2423
2516
  /**
2424
2517
  * Single product. Resolves the availability record, or — when
2425
2518
  * `opts.defaultAvailableOnNotFound` is set — a default available record on 404.
2426
2519
  */
2427
- async get(productId, siteCode, auth2 = ANON6, opts = {}) {
2520
+ async get(productId, siteCode, auth2 = ANON7, opts = {}) {
2428
2521
  try {
2429
2522
  return await this.ctx.http.request({
2430
2523
  method: "GET",
@@ -2447,7 +2540,7 @@ var AvailabilityService = class {
2447
2540
  * `opts.defaultAvailableOnNotFound` is set). The result preserves input order
2448
2541
  * and length. An empty `productIds` resolves to `[]` without a request.
2449
2542
  */
2450
- async getMany(productIds, siteCode, auth2 = ANON6, opts = {}) {
2543
+ async getMany(productIds, siteCode, auth2 = ANON7, opts = {}) {
2451
2544
  if (productIds.length === 0) return [];
2452
2545
  const found = await this.ctx.http.request({
2453
2546
  method: "POST",
@@ -2477,6 +2570,7 @@ var TenantConfigService = class {
2477
2570
  this.ctx = ctx;
2478
2571
  }
2479
2572
  ctx;
2573
+ static channel = "configuration";
2480
2574
  base() {
2481
2575
  return `/configuration/${this.ctx.tenant}/configurations`;
2482
2576
  }
@@ -2533,6 +2627,7 @@ var ClientConfigService = class {
2533
2627
  this.ctx = ctx;
2534
2628
  }
2535
2629
  ctx;
2630
+ static channel = "configuration";
2536
2631
  base(client) {
2537
2632
  return `/configuration/${this.ctx.tenant}/clients/${encodeURIComponent(client)}/configurations`;
2538
2633
  }
@@ -2590,6 +2685,7 @@ var ShoppingListService = class {
2590
2685
  this.ctx = ctx;
2591
2686
  }
2592
2687
  ctx;
2688
+ static channel = "shopping-list";
2593
2689
  base() {
2594
2690
  return `/shoppinglist/${this.ctx.tenant}/shopping-lists`;
2595
2691
  }
@@ -2686,6 +2782,7 @@ var RagIndexerService = class {
2686
2782
  this.ctx = ctx;
2687
2783
  }
2688
2784
  ctx;
2785
+ static channel = "ai-rag-indexer";
2689
2786
  base(type) {
2690
2787
  return `/ai-rag-indexer/${this.ctx.tenant}/${encodeURIComponent(type)}`;
2691
2788
  }
@@ -2726,6 +2823,7 @@ var SequentialIdService = class {
2726
2823
  this.ctx = ctx;
2727
2824
  }
2728
2825
  ctx;
2826
+ static channel = "sequential-id";
2729
2827
  base() {
2730
2828
  return `/sequential-id/${this.ctx.tenant}/schemas`;
2731
2829
  }
@@ -2815,6 +2913,7 @@ var FeeService = class {
2815
2913
  this.ctx = ctx;
2816
2914
  }
2817
2915
  ctx;
2916
+ static channel = "fee";
2818
2917
  feesBase() {
2819
2918
  return `/fee/${this.ctx.tenant}/fees`;
2820
2919
  }
@@ -2974,6 +3073,7 @@ var CloudFunctionsService = class {
2974
3073
  this.ctx = ctx;
2975
3074
  }
2976
3075
  ctx;
3076
+ static channel = "cloud-functions";
2977
3077
  base() {
2978
3078
  return `/cloud-functions/${this.ctx.tenant}/functions`;
2979
3079
  }
@@ -2997,6 +3097,7 @@ var WebhookService = class {
2997
3097
  this.ctx = ctx;
2998
3098
  }
2999
3099
  ctx;
3100
+ static channel = "webhook";
3000
3101
  base() {
3001
3102
  return `/webhook/${this.ctx.tenant}`;
3002
3103
  }
@@ -3109,6 +3210,7 @@ var SchemaService = class {
3109
3210
  this.ctx = ctx;
3110
3211
  }
3111
3212
  ctx;
3213
+ static channel = "schema";
3112
3214
  schemasBase() {
3113
3215
  return `/schema/${this.ctx.tenant}/schemas`;
3114
3216
  }
@@ -3336,6 +3438,7 @@ var AiService = class {
3336
3438
  this.ctx = ctx;
3337
3439
  }
3338
3440
  ctx;
3441
+ static channel = "ai";
3339
3442
  base() {
3340
3443
  return `/ai-service/${this.ctx.tenant}`;
3341
3444
  }
@@ -3449,6 +3552,7 @@ var TaxService = class {
3449
3552
  this.ctx = ctx;
3450
3553
  }
3451
3554
  ctx;
3555
+ static channel = "tax";
3452
3556
  base() {
3453
3557
  return `/tax/${this.ctx.tenant}`;
3454
3558
  }
@@ -3518,6 +3622,7 @@ var CouponService = class {
3518
3622
  this.ctx = ctx;
3519
3623
  }
3520
3624
  ctx;
3625
+ static channel = "coupon";
3521
3626
  base() {
3522
3627
  return `/coupon/${this.ctx.tenant}`;
3523
3628
  }
@@ -3644,6 +3749,7 @@ var RewardPointsService = class {
3644
3749
  this.ctx = ctx;
3645
3750
  }
3646
3751
  ctx;
3752
+ static channel = "reward-points";
3647
3753
  /** Base without tenant (customer / public / batch endpoints). */
3648
3754
  base() {
3649
3755
  return `/reward-points`;
@@ -3798,6 +3904,7 @@ var BrandService = class {
3798
3904
  this.ctx = ctx;
3799
3905
  }
3800
3906
  ctx;
3907
+ static channel = "brand";
3801
3908
  base() {
3802
3909
  return `/brand/brands`;
3803
3910
  }
@@ -3862,6 +3969,7 @@ var LabelService = class {
3862
3969
  this.ctx = ctx;
3863
3970
  }
3864
3971
  ctx;
3972
+ static channel = "label";
3865
3973
  base() {
3866
3974
  return `/label/labels`;
3867
3975
  }
@@ -3926,6 +4034,7 @@ var CountryService = class {
3926
4034
  this.ctx = ctx;
3927
4035
  }
3928
4036
  ctx;
4037
+ static channel = "country";
3929
4038
  base() {
3930
4039
  return `/country/${this.ctx.tenant}`;
3931
4040
  }
@@ -3981,6 +4090,7 @@ var CurrencyService = class {
3981
4090
  this.ctx = ctx;
3982
4091
  }
3983
4092
  ctx;
4093
+ static channel = "currency";
3984
4094
  base() {
3985
4095
  return `/currency/${this.ctx.tenant}`;
3986
4096
  }
@@ -4081,6 +4191,7 @@ var ShippingService = class {
4081
4191
  this.ctx = ctx;
4082
4192
  }
4083
4193
  ctx;
4194
+ static channel = "shipping";
4084
4195
  base() {
4085
4196
  return `/shipping/${this.ctx.tenant}`;
4086
4197
  }
@@ -4495,6 +4606,7 @@ var ReturnsService = class {
4495
4606
  this.ctx = ctx;
4496
4607
  }
4497
4608
  ctx;
4609
+ static channel = "returns";
4498
4610
  base() {
4499
4611
  return `/return/${this.ctx.tenant}/returns`;
4500
4612
  }
@@ -4559,6 +4671,7 @@ var SepaExportService = class {
4559
4671
  this.ctx = ctx;
4560
4672
  }
4561
4673
  ctx;
4674
+ static channel = "sepa-export";
4562
4675
  base() {
4563
4676
  return `/sepa-export/${this.ctx.tenant}`;
4564
4677
  }
@@ -4599,6 +4712,7 @@ var IndexingService = class {
4599
4712
  this.ctx = ctx;
4600
4713
  }
4601
4714
  ctx;
4715
+ static channel = "indexing";
4602
4716
  base() {
4603
4717
  return `/indexing/${this.ctx.tenant}`;
4604
4718
  }
@@ -4665,6 +4779,7 @@ var UnitHandlingService = class {
4665
4779
  this.ctx = ctx;
4666
4780
  }
4667
4781
  ctx;
4782
+ static channel = "unit-handling";
4668
4783
  base() {
4669
4784
  return `/unit-handling/${this.ctx.tenant}`;
4670
4785
  }
@@ -4746,6 +4861,7 @@ var CatalogService = class {
4746
4861
  this.ctx = ctx;
4747
4862
  }
4748
4863
  ctx;
4864
+ static channel = "catalog";
4749
4865
  base() {
4750
4866
  return `/catalog/${this.ctx.tenant}/catalogs`;
4751
4867
  }
@@ -4813,6 +4929,7 @@ var VendorService = class {
4813
4929
  this.ctx = ctx;
4814
4930
  }
4815
4931
  ctx;
4932
+ static channel = "vendor";
4816
4933
  base() {
4817
4934
  return `/vendor/${this.ctx.tenant}`;
4818
4935
  }
@@ -4912,6 +5029,7 @@ var PickPackService = class {
4912
5029
  this.ctx = ctx;
4913
5030
  }
4914
5031
  ctx;
5032
+ static channel = "pick-pack";
4915
5033
  base() {
4916
5034
  return `/pick-pack/${this.ctx.tenant}`;
4917
5035
  }
@@ -5003,6 +5121,7 @@ var CustomerAdminService = class {
5003
5121
  this.ctx = ctx;
5004
5122
  }
5005
5123
  ctx;
5124
+ static channel = "customer-admin";
5006
5125
  base() {
5007
5126
  return `/customer/${this.ctx.tenant}/customers`;
5008
5127
  }
@@ -5107,6 +5226,7 @@ var ApprovalService = class {
5107
5226
  this.ctx = ctx;
5108
5227
  }
5109
5228
  ctx;
5229
+ static channel = "approval";
5110
5230
  base() {
5111
5231
  return `/approval/${this.ctx.tenant}`;
5112
5232
  }
@@ -5173,12 +5293,6 @@ var ApprovalService = class {
5173
5293
  }
5174
5294
  };
5175
5295
 
5176
- // package.json
5177
- var version = "2.14.0";
5178
-
5179
- // src/version.ts
5180
- var SDK_VERSION = version;
5181
-
5182
5296
  // src/client.ts
5183
5297
  var EmporixClient = class {
5184
5298
  customers;
@@ -5241,96 +5355,62 @@ var EmporixClient = class {
5241
5355
  * Provider tree. Treat as read-only.
5242
5356
  */
5243
5357
  config;
5244
- resolver;
5245
- customerRefresh;
5246
- requestContext;
5358
+ core;
5247
5359
  constructor(config) {
5248
- const cfg = validateConfig(config);
5249
- this.tenant = cfg.tenant;
5250
- this.config = cfg;
5251
- let loggerObj = {};
5252
- let baseLogger;
5253
- if (cfg.logger === false) {
5254
- baseLogger = createNoopLogger();
5255
- } else if (cfg.logger && typeof cfg.logger.child === "function") {
5256
- baseLogger = cfg.logger;
5257
- } else if (cfg.logger) {
5258
- loggerObj = cfg.logger;
5259
- }
5260
- this.resolver = new LevelResolver(loggerObj);
5261
- const root = baseLogger ?? createConsoleLogger(this.resolver, {
5262
- sdk: "emporix",
5263
- sdkVersion: SDK_VERSION,
5264
- tenant: cfg.tenant
5265
- });
5266
- const tokenProvider = cfg.tokenProvider ?? new DefaultTokenProvider(cfg);
5267
- this.tokenProvider = tokenProvider;
5268
- const customerRefresh = new CustomerRefreshRegistry();
5269
- this.customerRefresh = customerRefresh;
5270
- this.requestContext = { language: cfg.credentials.storefront?.context?.language };
5271
- const requestContext = this.requestContext;
5272
- const mk = (service) => ({
5273
- tenant: cfg.tenant,
5274
- tokenProvider,
5275
- logger: root.child({ service }),
5276
- http: new HttpClient({
5277
- host: cfg.host,
5278
- provider: tokenProvider,
5279
- logger: root.child({ service: "http" }),
5280
- retry: cfg.retry,
5281
- timeouts: cfg.timeouts,
5282
- customerRefresh,
5283
- requestContext
5284
- })
5285
- });
5286
- this.customers = new CustomerService(mk("customer"));
5287
- this.products = new ProductService(mk("product"));
5288
- this.categories = new CategoryService(mk("category"));
5289
- this.carts = new CartService(mk("cart"));
5290
- this.checkout = new CheckoutService(mk("checkout"));
5291
- this.payments = new PaymentGatewayService(mk("payment"));
5292
- this.prices = new PriceService(mk("price"));
5293
- this.media = new MediaService(mk("media"));
5294
- this.segments = new SegmentService(mk("segment"), {
5360
+ const core = createCore(config);
5361
+ this.core = core;
5362
+ this.tenant = core.tenant;
5363
+ this.config = core.config;
5364
+ this.tokenProvider = core.tokenProvider;
5365
+ const mk = core.mk;
5366
+ this.customers = new CustomerService(mk(CustomerService.channel));
5367
+ this.products = new ProductService(mk(ProductService.channel));
5368
+ this.categories = new CategoryService(mk(CategoryService.channel));
5369
+ this.carts = new CartService(mk(CartService.channel));
5370
+ this.checkout = new CheckoutService(mk(CheckoutService.channel));
5371
+ this.payments = new PaymentGatewayService(mk(PaymentGatewayService.channel));
5372
+ this.prices = new PriceService(mk(PriceService.channel));
5373
+ this.media = new MediaService(mk(MediaService.channel));
5374
+ this.segments = new SegmentService(mk(SegmentService.channel), {
5295
5375
  products: this.products,
5296
5376
  categories: this.categories
5297
5377
  });
5298
- this.sites = new SiteService(mk("site"));
5299
- this.sessionContext = new SessionContextService(mk("session-context"));
5300
- this.companies = new CompaniesService(mk("customer-management"));
5301
- this.contacts = new ContactsService(mk("customer-management"));
5302
- this.locations = new LocationsService(mk("customer-management"));
5303
- this.customerGroups = new CustomerGroupsService(mk("iam"));
5304
- this.orders = new OrdersService(mk("orders"));
5305
- this.salesOrders = new SalesOrdersService(mk("sales-orders"));
5306
- this.availability = new AvailabilityService(mk("availability"));
5307
- this.tenantConfig = new TenantConfigService(mk("configuration"));
5308
- this.clientConfig = new ClientConfigService(mk("configuration"));
5309
- this.shoppingLists = new ShoppingListService(mk("shopping-list"));
5310
- this.ragIndexer = new RagIndexerService(mk("ai-rag-indexer"));
5311
- this.sequentialIds = new SequentialIdService(mk("sequential-id"));
5312
- this.fees = new FeeService(mk("fee"));
5313
- this.cloudFunctions = new CloudFunctionsService(mk("cloud-functions"));
5314
- this.webhooks = new WebhookService(mk("webhook"));
5315
- this.schemas = new SchemaService(mk("schema"));
5316
- this.ai = new AiService(mk("ai"));
5317
- this.taxes = new TaxService(mk("tax"));
5318
- this.coupons = new CouponService(mk("coupon"));
5319
- this.rewardPoints = new RewardPointsService(mk("reward-points"));
5320
- this.brands = new BrandService(mk("brand"));
5321
- this.labels = new LabelService(mk("label"));
5322
- this.countries = new CountryService(mk("country"));
5323
- this.currencies = new CurrencyService(mk("currency"));
5324
- this.shipping = new ShippingService(mk("shipping"));
5325
- this.returns = new ReturnsService(mk("returns"));
5326
- this.sepaExport = new SepaExportService(mk("sepa-export"));
5327
- this.indexing = new IndexingService(mk("indexing"));
5328
- this.units = new UnitHandlingService(mk("unit-handling"));
5329
- this.catalogs = new CatalogService(mk("catalog"));
5330
- this.vendors = new VendorService(mk("vendor"));
5331
- this.pickPack = new PickPackService(mk("pick-pack"));
5332
- this.customerAdmin = new CustomerAdminService(mk("customer-admin"));
5333
- this.approvals = new ApprovalService(mk("approval"));
5378
+ this.sites = new SiteService(mk(SiteService.channel));
5379
+ this.sessionContext = new SessionContextService(mk(SessionContextService.channel));
5380
+ this.companies = new CompaniesService(mk(CompaniesService.channel));
5381
+ this.contacts = new ContactsService(mk(ContactsService.channel));
5382
+ this.locations = new LocationsService(mk(LocationsService.channel));
5383
+ this.customerGroups = new CustomerGroupsService(mk(CustomerGroupsService.channel));
5384
+ this.orders = new OrdersService(mk(OrdersService.channel));
5385
+ this.salesOrders = new SalesOrdersService(mk(SalesOrdersService.channel));
5386
+ this.availability = new AvailabilityService(mk(AvailabilityService.channel));
5387
+ this.tenantConfig = new TenantConfigService(mk(TenantConfigService.channel));
5388
+ this.clientConfig = new ClientConfigService(mk(ClientConfigService.channel));
5389
+ this.shoppingLists = new ShoppingListService(mk(ShoppingListService.channel));
5390
+ this.ragIndexer = new RagIndexerService(mk(RagIndexerService.channel));
5391
+ this.sequentialIds = new SequentialIdService(mk(SequentialIdService.channel));
5392
+ this.fees = new FeeService(mk(FeeService.channel));
5393
+ this.cloudFunctions = new CloudFunctionsService(mk(CloudFunctionsService.channel));
5394
+ this.webhooks = new WebhookService(mk(WebhookService.channel));
5395
+ this.schemas = new SchemaService(mk(SchemaService.channel));
5396
+ this.ai = new AiService(mk(AiService.channel));
5397
+ this.taxes = new TaxService(mk(TaxService.channel));
5398
+ this.coupons = new CouponService(mk(CouponService.channel));
5399
+ this.rewardPoints = new RewardPointsService(mk(RewardPointsService.channel));
5400
+ this.brands = new BrandService(mk(BrandService.channel));
5401
+ this.labels = new LabelService(mk(LabelService.channel));
5402
+ this.countries = new CountryService(mk(CountryService.channel));
5403
+ this.currencies = new CurrencyService(mk(CurrencyService.channel));
5404
+ this.shipping = new ShippingService(mk(ShippingService.channel));
5405
+ this.returns = new ReturnsService(mk(ReturnsService.channel));
5406
+ this.sepaExport = new SepaExportService(mk(SepaExportService.channel));
5407
+ this.indexing = new IndexingService(mk(IndexingService.channel));
5408
+ this.units = new UnitHandlingService(mk(UnitHandlingService.channel));
5409
+ this.catalogs = new CatalogService(mk(CatalogService.channel));
5410
+ this.vendors = new VendorService(mk(VendorService.channel));
5411
+ this.pickPack = new PickPackService(mk(PickPackService.channel));
5412
+ this.customerAdmin = new CustomerAdminService(mk(CustomerAdminService.channel));
5413
+ this.approvals = new ApprovalService(mk(ApprovalService.channel));
5334
5414
  }
5335
5415
  /**
5336
5416
  * Re-binds the storefront price context (currency / siteCode / targetLocation)
@@ -5343,21 +5423,15 @@ var EmporixClient = class {
5343
5423
  * read); a language-only change does NOT re-mint the token.
5344
5424
  */
5345
5425
  setStorefrontContext(ctx) {
5346
- if (ctx.language !== void 0) {
5347
- this.requestContext.language = ctx.language || void 0;
5348
- }
5349
- const { language: _language, ...priceContext } = ctx;
5350
- if (Object.keys(priceContext).length > 0) {
5351
- this.tokenProvider.setAnonymousContext?.(priceContext);
5352
- }
5426
+ this.core.setStorefrontContext(ctx);
5353
5427
  }
5354
5428
  /** Sets the runtime log level globally or for one service. */
5355
5429
  setLogLevel(level, opts = {}) {
5356
- this.resolver.set(level, opts.service, opts.force ?? false);
5430
+ this.core.setLogLevel(level, opts);
5357
5431
  }
5358
5432
  /** Returns the effective log level for a service. */
5359
5433
  getLogLevel(service) {
5360
- return this.resolver.get(service);
5434
+ return this.core.getLogLevel(service);
5361
5435
  }
5362
5436
  /**
5363
5437
  * Registers (or clears with `null`) a customer-token refresher. When set, a
@@ -5366,10 +5440,34 @@ var EmporixClient = class {
5366
5440
  * automatically via `autoRefreshCustomerToken`.
5367
5441
  */
5368
5442
  setCustomerTokenRefresher(refresher) {
5369
- this.customerRefresh.set(refresher);
5443
+ this.core.setCustomerTokenRefresher(refresher);
5370
5444
  }
5371
5445
  };
5372
5446
 
5447
+ // src/create-emporix-client.ts
5448
+ function createEmporixClient(config, services) {
5449
+ const { mk, ...core } = createCore(config);
5450
+ const built = {};
5451
+ const entries = Object.entries(services);
5452
+ for (const [key, Svc] of entries) {
5453
+ if (!Svc.deps?.length) built[key] = new Svc(mk(Svc.channel));
5454
+ }
5455
+ for (const [key, Svc] of entries) {
5456
+ if (!Svc.deps?.length) continue;
5457
+ const deps = {};
5458
+ for (const dep of Svc.deps) {
5459
+ if (!(dep in built)) {
5460
+ throw new EmporixError(
5461
+ `createEmporixClient: "${key}" requires "${dep}" in the services map`
5462
+ );
5463
+ }
5464
+ deps[dep] = built[dep];
5465
+ }
5466
+ built[key] = new Svc(mk(Svc.channel), deps);
5467
+ }
5468
+ return { ...core, ...built };
5469
+ }
5470
+
5373
5471
  // src/core/yrn.ts
5374
5472
  function productIdFromYrn(yrn) {
5375
5473
  if (!yrn) return "";
@@ -5440,6 +5538,8 @@ exports.VendorService = VendorService;
5440
5538
  exports.WebhookService = WebhookService;
5441
5539
  exports.auth = auth;
5442
5540
  exports.createConsoleLogger = createConsoleLogger;
5541
+ exports.createCore = createCore;
5542
+ exports.createEmporixClient = createEmporixClient;
5443
5543
  exports.createNoopLogger = createNoopLogger;
5444
5544
  exports.errorFromResponse = errorFromResponse;
5445
5545
  exports.iterateAll = iterateAll;