@viu/emporix-sdk 2.11.0 → 2.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as ClientContext, b as AuthContext, P as PaginatedItems, T as TokenProvider, n as ResolvedConfig, E as EmporixConfig, j as LogLevel, o as ServiceName, e as CustomerTokenRefresher } from './context-CmShWI_R.cjs';
2
- export { A as AnonymousSession, a as AnonymousSessionStore, c as AuthKind, d as CustomerRefreshRegistry, D as DEFAULT_HOST, f as DefaultTokenProvider, H as HttpClient, g as HttpClientOptions, L as LEVEL, h as LevelResolver, i as LogFields, k as Logger, l as LoggerConfig, m as LoggerObjectConfig, R as RequestOptions, S as ServiceCredentials, p as StorefrontCredentials, q as auth, r as createConsoleLogger, s as createNoopLogger, t as iterateAll, u as redact, v as resolveToken, w as validateConfig } from './context-CmShWI_R.cjs';
1
+ import { C as ClientContext, b as AuthContext, P as PaginatedItems, T as TokenProvider, n as ResolvedConfig, E as EmporixConfig, j as LogLevel, o as ServiceName, e as CustomerTokenRefresher } from './context-CD7F_LHT.cjs';
2
+ export { A as AnonymousSession, a as AnonymousSessionStore, c as AuthKind, d as CustomerRefreshRegistry, D as DEFAULT_HOST, f as DefaultTokenProvider, H as HttpClient, g as HttpClientOptions, L as LEVEL, h as LevelResolver, i as LogFields, k as Logger, l as LoggerConfig, m as LoggerObjectConfig, R as RequestOptions, S as ServiceCredentials, p as StorefrontCredentials, q as auth, r as createConsoleLogger, s as createNoopLogger, t as iterateAll, u as redact, v as resolveToken, w as validateConfig } from './context-CD7F_LHT.cjs';
3
3
  import { CustomerService } from './customer.cjs';
4
4
  export { Address, AddressCreateInput, AddressUpdateInput, Customer, CustomerSession, CustomerSignupInput, CustomerUpdateInput, PasswordChangeInput, PasswordResetConfirmInput, PasswordResetRequestInput } from './customer.cjs';
5
5
  import { ProductService } from './product.cjs';
@@ -7135,6 +7135,7 @@ declare class EmporixClient {
7135
7135
  readonly config: ResolvedConfig;
7136
7136
  private readonly resolver;
7137
7137
  private readonly customerRefresh;
7138
+ private readonly requestContext;
7138
7139
  constructor(config: EmporixConfig);
7139
7140
  /**
7140
7141
  * Re-binds the storefront price context (currency / siteCode / targetLocation)
@@ -7142,11 +7143,15 @@ declare class EmporixClient {
7142
7143
  * next request re-mints a token bound to the new context. Use this to switch
7143
7144
  * currency at runtime. Carts are currency-bound — clear the cart after a
7144
7145
  * currency change (the React `setCurrency` does this for you).
7146
+ *
7147
+ * Also sets the storefront `language` (an `Accept-Language` header on every
7148
+ * read); a language-only change does NOT re-mint the token.
7145
7149
  */
7146
7150
  setStorefrontContext(ctx: {
7147
7151
  currency?: string;
7148
7152
  siteCode?: string;
7149
7153
  targetLocation?: string;
7154
+ language?: string;
7150
7155
  }): void;
7151
7156
  /** Sets the runtime log level globally or for one service. */
7152
7157
  setLogLevel(level: LogLevel, opts?: {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as ClientContext, b as AuthContext, P as PaginatedItems, T as TokenProvider, n as ResolvedConfig, E as EmporixConfig, j as LogLevel, o as ServiceName, e as CustomerTokenRefresher } from './context-CmShWI_R.js';
2
- export { A as AnonymousSession, a as AnonymousSessionStore, c as AuthKind, d as CustomerRefreshRegistry, D as DEFAULT_HOST, f as DefaultTokenProvider, H as HttpClient, g as HttpClientOptions, L as LEVEL, h as LevelResolver, i as LogFields, k as Logger, l as LoggerConfig, m as LoggerObjectConfig, R as RequestOptions, S as ServiceCredentials, p as StorefrontCredentials, q as auth, r as createConsoleLogger, s as createNoopLogger, t as iterateAll, u as redact, v as resolveToken, w as validateConfig } from './context-CmShWI_R.js';
1
+ import { C as ClientContext, b as AuthContext, P as PaginatedItems, T as TokenProvider, n as ResolvedConfig, E as EmporixConfig, j as LogLevel, o as ServiceName, e as CustomerTokenRefresher } from './context-CD7F_LHT.js';
2
+ export { A as AnonymousSession, a as AnonymousSessionStore, c as AuthKind, d as CustomerRefreshRegistry, D as DEFAULT_HOST, f as DefaultTokenProvider, H as HttpClient, g as HttpClientOptions, L as LEVEL, h as LevelResolver, i as LogFields, k as Logger, l as LoggerConfig, m as LoggerObjectConfig, R as RequestOptions, S as ServiceCredentials, p as StorefrontCredentials, q as auth, r as createConsoleLogger, s as createNoopLogger, t as iterateAll, u as redact, v as resolveToken, w as validateConfig } from './context-CD7F_LHT.js';
3
3
  import { CustomerService } from './customer.js';
4
4
  export { Address, AddressCreateInput, AddressUpdateInput, Customer, CustomerSession, CustomerSignupInput, CustomerUpdateInput, PasswordChangeInput, PasswordResetConfirmInput, PasswordResetRequestInput } from './customer.js';
5
5
  import { ProductService } from './product.js';
@@ -7135,6 +7135,7 @@ declare class EmporixClient {
7135
7135
  readonly config: ResolvedConfig;
7136
7136
  private readonly resolver;
7137
7137
  private readonly customerRefresh;
7138
+ private readonly requestContext;
7138
7139
  constructor(config: EmporixConfig);
7139
7140
  /**
7140
7141
  * Re-binds the storefront price context (currency / siteCode / targetLocation)
@@ -7142,11 +7143,15 @@ declare class EmporixClient {
7142
7143
  * next request re-mints a token bound to the new context. Use this to switch
7143
7144
  * currency at runtime. Carts are currency-bound — clear the cart after a
7144
7145
  * currency change (the React `setCurrency` does this for you).
7146
+ *
7147
+ * Also sets the storefront `language` (an `Accept-Language` header on every
7148
+ * read); a language-only change does NOT re-mint the token.
7145
7149
  */
7146
7150
  setStorefrontContext(ctx: {
7147
7151
  currency?: string;
7148
7152
  siteCode?: string;
7149
7153
  targetLocation?: string;
7154
+ language?: string;
7150
7155
  }): void;
7151
7156
  /** Sets the runtime log level globally or for one service. */
7152
7157
  setLogLevel(level: LogLevel, opts?: {
package/dist/index.js CHANGED
@@ -533,6 +533,16 @@ var HttpClient = class {
533
533
  }
534
534
  opts;
535
535
  sleep;
536
+ buildHeaders(o, token, isFormData) {
537
+ return {
538
+ ...this.opts.requestContext?.language ? { "Accept-Language": this.opts.requestContext.language } : {},
539
+ ...o.headers ?? {},
540
+ Authorization: `Bearer ${token}`,
541
+ // JSON bodies: set Content-Type. FormData bodies: let `fetch`
542
+ // emit `multipart/form-data; boundary=...` itself.
543
+ ...o.body !== void 0 && !isFormData ? { "Content-Type": "application/json" } : {}
544
+ };
545
+ }
536
546
  async request(o) {
537
547
  const requestId = `req-${++requestSeq}`;
538
548
  const log = this.opts.logger.child({ requestId });
@@ -561,13 +571,7 @@ var HttpClient = class {
561
571
  const isFormData = typeof FormData !== "undefined" && o.body instanceof FormData;
562
572
  const init = {
563
573
  method: o.method,
564
- headers: {
565
- ...o.headers ?? {},
566
- Authorization: `Bearer ${token}`,
567
- // JSON bodies: set Content-Type. FormData bodies: let `fetch`
568
- // emit `multipart/form-data; boundary=...` itself.
569
- ...o.body !== void 0 && !isFormData ? { "Content-Type": "application/json" } : {}
570
- },
574
+ headers: this.buildHeaders(o, token, isFormData),
571
575
  signal: controller.signal
572
576
  };
573
577
  if (o.body !== void 0) {
@@ -655,11 +659,7 @@ var HttpClient = class {
655
659
  const isFormData = typeof FormData !== "undefined" && o.body instanceof FormData;
656
660
  const init = {
657
661
  method: o.method,
658
- headers: {
659
- ...o.headers ?? {},
660
- Authorization: `Bearer ${token}`,
661
- ...o.body !== void 0 && !isFormData ? { "Content-Type": "application/json" } : {}
662
- },
662
+ headers: this.buildHeaders(o, token, isFormData),
663
663
  signal: controller.signal,
664
664
  ...extra?.redirect ? { redirect: extra.redirect } : {}
665
665
  };
@@ -3468,7 +3468,7 @@ var ApprovalService = class {
3468
3468
  };
3469
3469
 
3470
3470
  // package.json
3471
- var version = "2.11.0";
3471
+ var version = "2.12.0";
3472
3472
 
3473
3473
  // src/version.ts
3474
3474
  var SDK_VERSION = version;
@@ -3537,6 +3537,7 @@ var EmporixClient = class {
3537
3537
  config;
3538
3538
  resolver;
3539
3539
  customerRefresh;
3540
+ requestContext;
3540
3541
  constructor(config) {
3541
3542
  const cfg = validateConfig(config);
3542
3543
  this.tenant = cfg.tenant;
@@ -3560,6 +3561,8 @@ var EmporixClient = class {
3560
3561
  this.tokenProvider = tokenProvider;
3561
3562
  const customerRefresh = new CustomerRefreshRegistry();
3562
3563
  this.customerRefresh = customerRefresh;
3564
+ this.requestContext = { language: cfg.credentials.storefront?.context?.language };
3565
+ const requestContext = this.requestContext;
3563
3566
  const mk = (service) => ({
3564
3567
  tenant: cfg.tenant,
3565
3568
  tokenProvider,
@@ -3570,7 +3573,8 @@ var EmporixClient = class {
3570
3573
  logger: root.child({ service: "http" }),
3571
3574
  retry: cfg.retry,
3572
3575
  timeouts: cfg.timeouts,
3573
- customerRefresh
3576
+ customerRefresh,
3577
+ requestContext
3574
3578
  })
3575
3579
  });
3576
3580
  this.customers = new CustomerService(mk("customer"));
@@ -3628,9 +3632,18 @@ var EmporixClient = class {
3628
3632
  * next request re-mints a token bound to the new context. Use this to switch
3629
3633
  * currency at runtime. Carts are currency-bound — clear the cart after a
3630
3634
  * currency change (the React `setCurrency` does this for you).
3635
+ *
3636
+ * Also sets the storefront `language` (an `Accept-Language` header on every
3637
+ * read); a language-only change does NOT re-mint the token.
3631
3638
  */
3632
3639
  setStorefrontContext(ctx) {
3633
- this.tokenProvider.setAnonymousContext?.(ctx);
3640
+ if (ctx.language !== void 0) {
3641
+ this.requestContext.language = ctx.language || void 0;
3642
+ }
3643
+ const { language: _language, ...priceContext } = ctx;
3644
+ if (Object.keys(priceContext).length > 0) {
3645
+ this.tokenProvider.setAnonymousContext?.(priceContext);
3646
+ }
3634
3647
  }
3635
3648
  /** Sets the runtime log level globally or for one service. */
3636
3649
  setLogLevel(level, opts = {}) {