@viu/emporix-sdk 2.14.0 → 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 (128) hide show
  1. package/CHANGELOG.md +6 -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-XG2TKFY5.js → chunk-RYQVMR26.js} +3 -2
  49. package/dist/chunk-RYQVMR26.js.map +1 -0
  50. package/dist/{chunk-EINAVCV2.js → chunk-XEJPH6UN.js} +3 -2
  51. package/dist/chunk-XEJPH6UN.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 +197 -102
  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 -134
  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 +1 -0
  94. package/dist/payment.cjs.map +1 -1
  95. package/dist/payment.d.cts +1 -0
  96. package/dist/payment.d.ts +1 -0
  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.map +0 -1
  118. package/dist/chunk-FU5WQALW.js.map +0 -1
  119. package/dist/chunk-HAEVK6IS.js.map +0 -1
  120. package/dist/chunk-LGLFJL3S.js.map +0 -1
  121. package/dist/chunk-LGOC5XOI.js.map +0 -1
  122. package/dist/chunk-MIUVJEGR.js.map +0 -1
  123. package/dist/chunk-MM6JF3Z7.js.map +0 -1
  124. package/dist/chunk-P3UHYMDH.js.map +0 -1
  125. package/dist/chunk-UOBOFCFU.js.map +0 -1
  126. package/dist/chunk-WW3H7VJ5.js.map +0 -1
  127. package/dist/chunk-WWCCB22A.js.map +0 -1
  128. 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.15.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 };
@@ -1516,6 +1590,7 @@ var PaymentGatewayService = class {
1516
1590
  this.ctx = ctx;
1517
1591
  }
1518
1592
  ctx;
1593
+ static channel = "payment";
1519
1594
  /** Lists configured frontend payment modes. */
1520
1595
  async listPaymentModes(auth2) {
1521
1596
  return this.ctx.http.request({
@@ -1560,6 +1635,7 @@ var PriceService = class {
1560
1635
  this.ctx = ctx;
1561
1636
  }
1562
1637
  ctx;
1638
+ static channel = "price";
1563
1639
  /**
1564
1640
  * Resolves prices using the session context bound to the bearer token
1565
1641
  * (currency/site/country were set at anonymous-login time). Default auth:
@@ -1647,6 +1723,7 @@ var MediaService = class {
1647
1723
  this.ctx = ctx;
1648
1724
  }
1649
1725
  ctx;
1726
+ static channel = "media";
1650
1727
  base() {
1651
1728
  return `/media/${this.ctx.tenant}/assets`;
1652
1729
  }
@@ -1892,6 +1969,8 @@ var SegmentService = class {
1892
1969
  }
1893
1970
  ctx;
1894
1971
  deps;
1972
+ static channel = "segment";
1973
+ static deps = ["products", "categories"];
1895
1974
  base() {
1896
1975
  return `/customer-segment/${this.ctx.tenant}/segments`;
1897
1976
  }
@@ -2023,6 +2102,7 @@ var SiteService = class {
2023
2102
  this.ctx = ctx;
2024
2103
  }
2025
2104
  ctx;
2105
+ static channel = "site";
2026
2106
  /** Lists active sites. */
2027
2107
  async list(authCtx = ANON4) {
2028
2108
  return this.ctx.http.request({
@@ -2062,6 +2142,7 @@ var SessionContextService = class {
2062
2142
  this.ctx = ctx;
2063
2143
  }
2064
2144
  ctx;
2145
+ static channel = "session-context";
2065
2146
  /**
2066
2147
  * Retrieves the current session context, or `null` when the server returns
2067
2148
  * 404 (no session exists yet — the session-context is created server-side
@@ -2124,6 +2205,7 @@ var CompaniesService = class {
2124
2205
  this.ctx = ctx;
2125
2206
  }
2126
2207
  ctx;
2208
+ static channel = "customer-management";
2127
2209
  base() {
2128
2210
  return `/customer-management/${this.ctx.tenant}/legal-entities`;
2129
2211
  }
@@ -2180,6 +2262,7 @@ var ContactsService = class {
2180
2262
  this.ctx = ctx;
2181
2263
  }
2182
2264
  ctx;
2265
+ static channel = "customer-management";
2183
2266
  base() {
2184
2267
  return `/customer-management/${this.ctx.tenant}/contact-assignments`;
2185
2268
  }
@@ -2229,6 +2312,7 @@ var LocationsService = class {
2229
2312
  this.ctx = ctx;
2230
2313
  }
2231
2314
  ctx;
2315
+ static channel = "customer-management";
2232
2316
  base() {
2233
2317
  return `/customer-management/${this.ctx.tenant}/locations`;
2234
2318
  }
@@ -2286,6 +2370,7 @@ var CustomerGroupsService = class {
2286
2370
  this.ctx = ctx;
2287
2371
  }
2288
2372
  ctx;
2373
+ static channel = "iam";
2289
2374
  base() {
2290
2375
  return `/iam/${this.ctx.tenant}/groups`;
2291
2376
  }
@@ -2328,6 +2413,7 @@ var OrdersService = class {
2328
2413
  this.ctx = ctx;
2329
2414
  }
2330
2415
  ctx;
2416
+ static channel = "orders";
2331
2417
  base() {
2332
2418
  return `/order-v2/${this.ctx.tenant}/orders`;
2333
2419
  }
@@ -2388,6 +2474,7 @@ var SalesOrdersService = class {
2388
2474
  this.ctx = ctx;
2389
2475
  }
2390
2476
  ctx;
2477
+ static channel = "sales-orders";
2391
2478
  base() {
2392
2479
  return `/order-v2/${this.ctx.tenant}/salesorders`;
2393
2480
  }
@@ -2420,6 +2507,7 @@ var AvailabilityService = class {
2420
2507
  this.ctx = ctx;
2421
2508
  }
2422
2509
  ctx;
2510
+ static channel = "availability";
2423
2511
  /**
2424
2512
  * Single product. Resolves the availability record, or — when
2425
2513
  * `opts.defaultAvailableOnNotFound` is set — a default available record on 404.
@@ -2477,6 +2565,7 @@ var TenantConfigService = class {
2477
2565
  this.ctx = ctx;
2478
2566
  }
2479
2567
  ctx;
2568
+ static channel = "configuration";
2480
2569
  base() {
2481
2570
  return `/configuration/${this.ctx.tenant}/configurations`;
2482
2571
  }
@@ -2533,6 +2622,7 @@ var ClientConfigService = class {
2533
2622
  this.ctx = ctx;
2534
2623
  }
2535
2624
  ctx;
2625
+ static channel = "configuration";
2536
2626
  base(client) {
2537
2627
  return `/configuration/${this.ctx.tenant}/clients/${encodeURIComponent(client)}/configurations`;
2538
2628
  }
@@ -2590,6 +2680,7 @@ var ShoppingListService = class {
2590
2680
  this.ctx = ctx;
2591
2681
  }
2592
2682
  ctx;
2683
+ static channel = "shopping-list";
2593
2684
  base() {
2594
2685
  return `/shoppinglist/${this.ctx.tenant}/shopping-lists`;
2595
2686
  }
@@ -2686,6 +2777,7 @@ var RagIndexerService = class {
2686
2777
  this.ctx = ctx;
2687
2778
  }
2688
2779
  ctx;
2780
+ static channel = "ai-rag-indexer";
2689
2781
  base(type) {
2690
2782
  return `/ai-rag-indexer/${this.ctx.tenant}/${encodeURIComponent(type)}`;
2691
2783
  }
@@ -2726,6 +2818,7 @@ var SequentialIdService = class {
2726
2818
  this.ctx = ctx;
2727
2819
  }
2728
2820
  ctx;
2821
+ static channel = "sequential-id";
2729
2822
  base() {
2730
2823
  return `/sequential-id/${this.ctx.tenant}/schemas`;
2731
2824
  }
@@ -2815,6 +2908,7 @@ var FeeService = class {
2815
2908
  this.ctx = ctx;
2816
2909
  }
2817
2910
  ctx;
2911
+ static channel = "fee";
2818
2912
  feesBase() {
2819
2913
  return `/fee/${this.ctx.tenant}/fees`;
2820
2914
  }
@@ -2974,6 +3068,7 @@ var CloudFunctionsService = class {
2974
3068
  this.ctx = ctx;
2975
3069
  }
2976
3070
  ctx;
3071
+ static channel = "cloud-functions";
2977
3072
  base() {
2978
3073
  return `/cloud-functions/${this.ctx.tenant}/functions`;
2979
3074
  }
@@ -2997,6 +3092,7 @@ var WebhookService = class {
2997
3092
  this.ctx = ctx;
2998
3093
  }
2999
3094
  ctx;
3095
+ static channel = "webhook";
3000
3096
  base() {
3001
3097
  return `/webhook/${this.ctx.tenant}`;
3002
3098
  }
@@ -3109,6 +3205,7 @@ var SchemaService = class {
3109
3205
  this.ctx = ctx;
3110
3206
  }
3111
3207
  ctx;
3208
+ static channel = "schema";
3112
3209
  schemasBase() {
3113
3210
  return `/schema/${this.ctx.tenant}/schemas`;
3114
3211
  }
@@ -3336,6 +3433,7 @@ var AiService = class {
3336
3433
  this.ctx = ctx;
3337
3434
  }
3338
3435
  ctx;
3436
+ static channel = "ai";
3339
3437
  base() {
3340
3438
  return `/ai-service/${this.ctx.tenant}`;
3341
3439
  }
@@ -3449,6 +3547,7 @@ var TaxService = class {
3449
3547
  this.ctx = ctx;
3450
3548
  }
3451
3549
  ctx;
3550
+ static channel = "tax";
3452
3551
  base() {
3453
3552
  return `/tax/${this.ctx.tenant}`;
3454
3553
  }
@@ -3518,6 +3617,7 @@ var CouponService = class {
3518
3617
  this.ctx = ctx;
3519
3618
  }
3520
3619
  ctx;
3620
+ static channel = "coupon";
3521
3621
  base() {
3522
3622
  return `/coupon/${this.ctx.tenant}`;
3523
3623
  }
@@ -3644,6 +3744,7 @@ var RewardPointsService = class {
3644
3744
  this.ctx = ctx;
3645
3745
  }
3646
3746
  ctx;
3747
+ static channel = "reward-points";
3647
3748
  /** Base without tenant (customer / public / batch endpoints). */
3648
3749
  base() {
3649
3750
  return `/reward-points`;
@@ -3798,6 +3899,7 @@ var BrandService = class {
3798
3899
  this.ctx = ctx;
3799
3900
  }
3800
3901
  ctx;
3902
+ static channel = "brand";
3801
3903
  base() {
3802
3904
  return `/brand/brands`;
3803
3905
  }
@@ -3862,6 +3964,7 @@ var LabelService = class {
3862
3964
  this.ctx = ctx;
3863
3965
  }
3864
3966
  ctx;
3967
+ static channel = "label";
3865
3968
  base() {
3866
3969
  return `/label/labels`;
3867
3970
  }
@@ -3926,6 +4029,7 @@ var CountryService = class {
3926
4029
  this.ctx = ctx;
3927
4030
  }
3928
4031
  ctx;
4032
+ static channel = "country";
3929
4033
  base() {
3930
4034
  return `/country/${this.ctx.tenant}`;
3931
4035
  }
@@ -3981,6 +4085,7 @@ var CurrencyService = class {
3981
4085
  this.ctx = ctx;
3982
4086
  }
3983
4087
  ctx;
4088
+ static channel = "currency";
3984
4089
  base() {
3985
4090
  return `/currency/${this.ctx.tenant}`;
3986
4091
  }
@@ -4081,6 +4186,7 @@ var ShippingService = class {
4081
4186
  this.ctx = ctx;
4082
4187
  }
4083
4188
  ctx;
4189
+ static channel = "shipping";
4084
4190
  base() {
4085
4191
  return `/shipping/${this.ctx.tenant}`;
4086
4192
  }
@@ -4495,6 +4601,7 @@ var ReturnsService = class {
4495
4601
  this.ctx = ctx;
4496
4602
  }
4497
4603
  ctx;
4604
+ static channel = "returns";
4498
4605
  base() {
4499
4606
  return `/return/${this.ctx.tenant}/returns`;
4500
4607
  }
@@ -4559,6 +4666,7 @@ var SepaExportService = class {
4559
4666
  this.ctx = ctx;
4560
4667
  }
4561
4668
  ctx;
4669
+ static channel = "sepa-export";
4562
4670
  base() {
4563
4671
  return `/sepa-export/${this.ctx.tenant}`;
4564
4672
  }
@@ -4599,6 +4707,7 @@ var IndexingService = class {
4599
4707
  this.ctx = ctx;
4600
4708
  }
4601
4709
  ctx;
4710
+ static channel = "indexing";
4602
4711
  base() {
4603
4712
  return `/indexing/${this.ctx.tenant}`;
4604
4713
  }
@@ -4665,6 +4774,7 @@ var UnitHandlingService = class {
4665
4774
  this.ctx = ctx;
4666
4775
  }
4667
4776
  ctx;
4777
+ static channel = "unit-handling";
4668
4778
  base() {
4669
4779
  return `/unit-handling/${this.ctx.tenant}`;
4670
4780
  }
@@ -4746,6 +4856,7 @@ var CatalogService = class {
4746
4856
  this.ctx = ctx;
4747
4857
  }
4748
4858
  ctx;
4859
+ static channel = "catalog";
4749
4860
  base() {
4750
4861
  return `/catalog/${this.ctx.tenant}/catalogs`;
4751
4862
  }
@@ -4813,6 +4924,7 @@ var VendorService = class {
4813
4924
  this.ctx = ctx;
4814
4925
  }
4815
4926
  ctx;
4927
+ static channel = "vendor";
4816
4928
  base() {
4817
4929
  return `/vendor/${this.ctx.tenant}`;
4818
4930
  }
@@ -4912,6 +5024,7 @@ var PickPackService = class {
4912
5024
  this.ctx = ctx;
4913
5025
  }
4914
5026
  ctx;
5027
+ static channel = "pick-pack";
4915
5028
  base() {
4916
5029
  return `/pick-pack/${this.ctx.tenant}`;
4917
5030
  }
@@ -5003,6 +5116,7 @@ var CustomerAdminService = class {
5003
5116
  this.ctx = ctx;
5004
5117
  }
5005
5118
  ctx;
5119
+ static channel = "customer-admin";
5006
5120
  base() {
5007
5121
  return `/customer/${this.ctx.tenant}/customers`;
5008
5122
  }
@@ -5107,6 +5221,7 @@ var ApprovalService = class {
5107
5221
  this.ctx = ctx;
5108
5222
  }
5109
5223
  ctx;
5224
+ static channel = "approval";
5110
5225
  base() {
5111
5226
  return `/approval/${this.ctx.tenant}`;
5112
5227
  }
@@ -5173,12 +5288,6 @@ var ApprovalService = class {
5173
5288
  }
5174
5289
  };
5175
5290
 
5176
- // package.json
5177
- var version = "2.14.0";
5178
-
5179
- // src/version.ts
5180
- var SDK_VERSION = version;
5181
-
5182
5291
  // src/client.ts
5183
5292
  var EmporixClient = class {
5184
5293
  customers;
@@ -5241,96 +5350,62 @@ var EmporixClient = class {
5241
5350
  * Provider tree. Treat as read-only.
5242
5351
  */
5243
5352
  config;
5244
- resolver;
5245
- customerRefresh;
5246
- requestContext;
5353
+ core;
5247
5354
  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"), {
5355
+ const core = createCore(config);
5356
+ this.core = core;
5357
+ this.tenant = core.tenant;
5358
+ this.config = core.config;
5359
+ this.tokenProvider = core.tokenProvider;
5360
+ const mk = core.mk;
5361
+ this.customers = new CustomerService(mk(CustomerService.channel));
5362
+ this.products = new ProductService(mk(ProductService.channel));
5363
+ this.categories = new CategoryService(mk(CategoryService.channel));
5364
+ this.carts = new CartService(mk(CartService.channel));
5365
+ this.checkout = new CheckoutService(mk(CheckoutService.channel));
5366
+ this.payments = new PaymentGatewayService(mk(PaymentGatewayService.channel));
5367
+ this.prices = new PriceService(mk(PriceService.channel));
5368
+ this.media = new MediaService(mk(MediaService.channel));
5369
+ this.segments = new SegmentService(mk(SegmentService.channel), {
5295
5370
  products: this.products,
5296
5371
  categories: this.categories
5297
5372
  });
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"));
5373
+ this.sites = new SiteService(mk(SiteService.channel));
5374
+ this.sessionContext = new SessionContextService(mk(SessionContextService.channel));
5375
+ this.companies = new CompaniesService(mk(CompaniesService.channel));
5376
+ this.contacts = new ContactsService(mk(ContactsService.channel));
5377
+ this.locations = new LocationsService(mk(LocationsService.channel));
5378
+ this.customerGroups = new CustomerGroupsService(mk(CustomerGroupsService.channel));
5379
+ this.orders = new OrdersService(mk(OrdersService.channel));
5380
+ this.salesOrders = new SalesOrdersService(mk(SalesOrdersService.channel));
5381
+ this.availability = new AvailabilityService(mk(AvailabilityService.channel));
5382
+ this.tenantConfig = new TenantConfigService(mk(TenantConfigService.channel));
5383
+ this.clientConfig = new ClientConfigService(mk(ClientConfigService.channel));
5384
+ this.shoppingLists = new ShoppingListService(mk(ShoppingListService.channel));
5385
+ this.ragIndexer = new RagIndexerService(mk(RagIndexerService.channel));
5386
+ this.sequentialIds = new SequentialIdService(mk(SequentialIdService.channel));
5387
+ this.fees = new FeeService(mk(FeeService.channel));
5388
+ this.cloudFunctions = new CloudFunctionsService(mk(CloudFunctionsService.channel));
5389
+ this.webhooks = new WebhookService(mk(WebhookService.channel));
5390
+ this.schemas = new SchemaService(mk(SchemaService.channel));
5391
+ this.ai = new AiService(mk(AiService.channel));
5392
+ this.taxes = new TaxService(mk(TaxService.channel));
5393
+ this.coupons = new CouponService(mk(CouponService.channel));
5394
+ this.rewardPoints = new RewardPointsService(mk(RewardPointsService.channel));
5395
+ this.brands = new BrandService(mk(BrandService.channel));
5396
+ this.labels = new LabelService(mk(LabelService.channel));
5397
+ this.countries = new CountryService(mk(CountryService.channel));
5398
+ this.currencies = new CurrencyService(mk(CurrencyService.channel));
5399
+ this.shipping = new ShippingService(mk(ShippingService.channel));
5400
+ this.returns = new ReturnsService(mk(ReturnsService.channel));
5401
+ this.sepaExport = new SepaExportService(mk(SepaExportService.channel));
5402
+ this.indexing = new IndexingService(mk(IndexingService.channel));
5403
+ this.units = new UnitHandlingService(mk(UnitHandlingService.channel));
5404
+ this.catalogs = new CatalogService(mk(CatalogService.channel));
5405
+ this.vendors = new VendorService(mk(VendorService.channel));
5406
+ this.pickPack = new PickPackService(mk(PickPackService.channel));
5407
+ this.customerAdmin = new CustomerAdminService(mk(CustomerAdminService.channel));
5408
+ this.approvals = new ApprovalService(mk(ApprovalService.channel));
5334
5409
  }
5335
5410
  /**
5336
5411
  * Re-binds the storefront price context (currency / siteCode / targetLocation)
@@ -5343,21 +5418,15 @@ var EmporixClient = class {
5343
5418
  * read); a language-only change does NOT re-mint the token.
5344
5419
  */
5345
5420
  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
- }
5421
+ this.core.setStorefrontContext(ctx);
5353
5422
  }
5354
5423
  /** Sets the runtime log level globally or for one service. */
5355
5424
  setLogLevel(level, opts = {}) {
5356
- this.resolver.set(level, opts.service, opts.force ?? false);
5425
+ this.core.setLogLevel(level, opts);
5357
5426
  }
5358
5427
  /** Returns the effective log level for a service. */
5359
5428
  getLogLevel(service) {
5360
- return this.resolver.get(service);
5429
+ return this.core.getLogLevel(service);
5361
5430
  }
5362
5431
  /**
5363
5432
  * Registers (or clears with `null`) a customer-token refresher. When set, a
@@ -5366,10 +5435,34 @@ var EmporixClient = class {
5366
5435
  * automatically via `autoRefreshCustomerToken`.
5367
5436
  */
5368
5437
  setCustomerTokenRefresher(refresher) {
5369
- this.customerRefresh.set(refresher);
5438
+ this.core.setCustomerTokenRefresher(refresher);
5370
5439
  }
5371
5440
  };
5372
5441
 
5442
+ // src/create-emporix-client.ts
5443
+ function createEmporixClient(config, services) {
5444
+ const { mk, ...core } = createCore(config);
5445
+ const built = {};
5446
+ const entries = Object.entries(services);
5447
+ for (const [key, Svc] of entries) {
5448
+ if (!Svc.deps?.length) built[key] = new Svc(mk(Svc.channel));
5449
+ }
5450
+ for (const [key, Svc] of entries) {
5451
+ if (!Svc.deps?.length) continue;
5452
+ const deps = {};
5453
+ for (const dep of Svc.deps) {
5454
+ if (!(dep in built)) {
5455
+ throw new EmporixError(
5456
+ `createEmporixClient: "${key}" requires "${dep}" in the services map`
5457
+ );
5458
+ }
5459
+ deps[dep] = built[dep];
5460
+ }
5461
+ built[key] = new Svc(mk(Svc.channel), deps);
5462
+ }
5463
+ return { ...core, ...built };
5464
+ }
5465
+
5373
5466
  // src/core/yrn.ts
5374
5467
  function productIdFromYrn(yrn) {
5375
5468
  if (!yrn) return "";
@@ -5440,6 +5533,8 @@ exports.VendorService = VendorService;
5440
5533
  exports.WebhookService = WebhookService;
5441
5534
  exports.auth = auth;
5442
5535
  exports.createConsoleLogger = createConsoleLogger;
5536
+ exports.createCore = createCore;
5537
+ exports.createEmporixClient = createEmporixClient;
5443
5538
  exports.createNoopLogger = createNoopLogger;
5444
5539
  exports.errorFromResponse = errorFromResponse;
5445
5540
  exports.iterateAll = iterateAll;