@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/CHANGELOG.md +6 -0
- package/dist/availability.d.cts +1 -1
- package/dist/availability.d.ts +1 -1
- package/dist/cart.d.cts +1 -1
- package/dist/cart.d.ts +1 -1
- package/dist/category.d.cts +1 -1
- package/dist/category.d.ts +1 -1
- package/dist/checkout.d.cts +1 -1
- package/dist/checkout.d.ts +1 -1
- package/dist/companies.d.cts +1 -1
- package/dist/companies.d.ts +1 -1
- package/dist/contacts.d.cts +1 -1
- package/dist/contacts.d.ts +1 -1
- package/dist/{context-CmShWI_R.d.cts → context-CD7F_LHT.d.cts} +10 -0
- package/dist/{context-CmShWI_R.d.ts → context-CD7F_LHT.d.ts} +10 -0
- package/dist/customer-groups.d.cts +1 -1
- package/dist/customer-groups.d.ts +1 -1
- package/dist/customer.d.cts +1 -1
- package/dist/customer.d.ts +1 -1
- package/dist/index.cjs +28 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +28 -15
- package/dist/index.js.map +1 -1
- package/dist/locations.d.cts +1 -1
- package/dist/locations.d.ts +1 -1
- package/dist/media.d.cts +1 -1
- package/dist/media.d.ts +1 -1
- package/dist/orders.d.cts +1 -1
- package/dist/orders.d.ts +1 -1
- package/dist/payment.d.cts +1 -1
- package/dist/payment.d.ts +1 -1
- package/dist/price.d.cts +1 -1
- package/dist/price.d.ts +1 -1
- package/dist/product.d.cts +1 -1
- package/dist/product.d.ts +1 -1
- package/dist/segment.d.cts +1 -1
- package/dist/segment.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @viu/emporix-sdk
|
|
2
2
|
|
|
3
|
+
## 2.12.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#116](https://github.com/viuteam/emporix-sdk/pull/116) [`5411502`](https://github.com/viuteam/emporix-sdk/commit/5411502fdde0737ad457812e28a86c505f938282) Thanks [@amnael1](https://github.com/amnael1)! - Add a runtime language switch. `client.setStorefrontContext({ language })` now sets an `Accept-Language` header on every read. React's `useSiteContext()` exposes `language` + `setLanguage(lang)` (modeled on `setCurrency`), persists the choice via `EmporixStorage` (`emporix.language`), mirrors it into the server session context, and keys localized reads (products, categories, segments, cart, shopping lists, orders) by language so the cache never serves stale-language text. A new `initialLanguage` provider prop seeds the active language.
|
|
8
|
+
|
|
3
9
|
## 2.11.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/dist/availability.d.cts
CHANGED
package/dist/availability.d.ts
CHANGED
package/dist/cart.d.cts
CHANGED
package/dist/cart.d.ts
CHANGED
package/dist/category.d.cts
CHANGED
package/dist/category.d.ts
CHANGED
package/dist/checkout.d.cts
CHANGED
package/dist/checkout.d.ts
CHANGED
package/dist/companies.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ClientContext, b as AuthContext } from './context-
|
|
1
|
+
import { C as ClientContext, b as AuthContext } from './context-CD7F_LHT.cjs';
|
|
2
2
|
import { L as LegalEntity, e as LegalEntityCreate, f as LegalEntityUpdate } from './types.gen-C_wOXYZB.cjs';
|
|
3
3
|
export { A as AccountLimit, d as CustomerGroup, g as LegalInfo } from './types.gen-C_wOXYZB.cjs';
|
|
4
4
|
|
package/dist/companies.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ClientContext, b as AuthContext } from './context-
|
|
1
|
+
import { C as ClientContext, b as AuthContext } from './context-CD7F_LHT.js';
|
|
2
2
|
import { L as LegalEntity, e as LegalEntityCreate, f as LegalEntityUpdate } from './types.gen-C_wOXYZB.js';
|
|
3
3
|
export { A as AccountLimit, d as CustomerGroup, g as LegalInfo } from './types.gen-C_wOXYZB.js';
|
|
4
4
|
|
package/dist/contacts.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ClientContext, b as AuthContext } from './context-
|
|
1
|
+
import { C as ClientContext, b as AuthContext } from './context-CD7F_LHT.cjs';
|
|
2
2
|
import { C as ContactAssignment, a as ContactAssignmentCreate, b as ContactAssignmentUpdate } from './types.gen-C_wOXYZB.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
package/dist/contacts.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ClientContext, b as AuthContext } from './context-
|
|
1
|
+
import { C as ClientContext, b as AuthContext } from './context-CD7F_LHT.js';
|
|
2
2
|
import { C as ContactAssignment, a as ContactAssignmentCreate, b as ContactAssignmentUpdate } from './types.gen-C_wOXYZB.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -93,6 +93,7 @@ interface StorefrontCredentials {
|
|
|
93
93
|
currency?: string;
|
|
94
94
|
siteCode?: string;
|
|
95
95
|
targetLocation?: string;
|
|
96
|
+
language?: string;
|
|
96
97
|
};
|
|
97
98
|
}
|
|
98
99
|
/** User-supplied SDK configuration. */
|
|
@@ -335,12 +336,21 @@ interface HttpClientOptions {
|
|
|
335
336
|
sleep?: (ms: number) => Promise<void>;
|
|
336
337
|
/** Opt-in customer-token refresher registry (off unless a refresher is set). */
|
|
337
338
|
customerRefresh?: CustomerRefreshRegistry;
|
|
339
|
+
/**
|
|
340
|
+
* Shared storefront request context. When `language` is set, every request
|
|
341
|
+
* carries `Accept-Language: <language>`. Mutated at runtime via
|
|
342
|
+
* `EmporixClient.setStorefrontContext({ language })`.
|
|
343
|
+
*/
|
|
344
|
+
requestContext?: {
|
|
345
|
+
language?: string | undefined;
|
|
346
|
+
};
|
|
338
347
|
}
|
|
339
348
|
/** Fetch wrapper: auth resolution, JSON parsing, typed error mapping, logging. */
|
|
340
349
|
declare class HttpClient {
|
|
341
350
|
private readonly opts;
|
|
342
351
|
private readonly sleep;
|
|
343
352
|
constructor(opts: HttpClientOptions);
|
|
353
|
+
private buildHeaders;
|
|
344
354
|
request<T = unknown>(o: RequestOptions): Promise<T>;
|
|
345
355
|
/**
|
|
346
356
|
* Single-shot fetch that returns the raw {@link Response} unparsed. Used by
|
|
@@ -93,6 +93,7 @@ interface StorefrontCredentials {
|
|
|
93
93
|
currency?: string;
|
|
94
94
|
siteCode?: string;
|
|
95
95
|
targetLocation?: string;
|
|
96
|
+
language?: string;
|
|
96
97
|
};
|
|
97
98
|
}
|
|
98
99
|
/** User-supplied SDK configuration. */
|
|
@@ -335,12 +336,21 @@ interface HttpClientOptions {
|
|
|
335
336
|
sleep?: (ms: number) => Promise<void>;
|
|
336
337
|
/** Opt-in customer-token refresher registry (off unless a refresher is set). */
|
|
337
338
|
customerRefresh?: CustomerRefreshRegistry;
|
|
339
|
+
/**
|
|
340
|
+
* Shared storefront request context. When `language` is set, every request
|
|
341
|
+
* carries `Accept-Language: <language>`. Mutated at runtime via
|
|
342
|
+
* `EmporixClient.setStorefrontContext({ language })`.
|
|
343
|
+
*/
|
|
344
|
+
requestContext?: {
|
|
345
|
+
language?: string | undefined;
|
|
346
|
+
};
|
|
338
347
|
}
|
|
339
348
|
/** Fetch wrapper: auth resolution, JSON parsing, typed error mapping, logging. */
|
|
340
349
|
declare class HttpClient {
|
|
341
350
|
private readonly opts;
|
|
342
351
|
private readonly sleep;
|
|
343
352
|
constructor(opts: HttpClientOptions);
|
|
353
|
+
private buildHeaders;
|
|
344
354
|
request<T = unknown>(o: RequestOptions): Promise<T>;
|
|
345
355
|
/**
|
|
346
356
|
* Single-shot fetch that returns the raw {@link Response} unparsed. Used by
|
package/dist/customer.d.cts
CHANGED
package/dist/customer.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -583,6 +583,16 @@ var HttpClient = class {
|
|
|
583
583
|
}
|
|
584
584
|
opts;
|
|
585
585
|
sleep;
|
|
586
|
+
buildHeaders(o, token, isFormData) {
|
|
587
|
+
return {
|
|
588
|
+
...this.opts.requestContext?.language ? { "Accept-Language": this.opts.requestContext.language } : {},
|
|
589
|
+
...o.headers ?? {},
|
|
590
|
+
Authorization: `Bearer ${token}`,
|
|
591
|
+
// JSON bodies: set Content-Type. FormData bodies: let `fetch`
|
|
592
|
+
// emit `multipart/form-data; boundary=...` itself.
|
|
593
|
+
...o.body !== void 0 && !isFormData ? { "Content-Type": "application/json" } : {}
|
|
594
|
+
};
|
|
595
|
+
}
|
|
586
596
|
async request(o) {
|
|
587
597
|
const requestId = `req-${++requestSeq}`;
|
|
588
598
|
const log = this.opts.logger.child({ requestId });
|
|
@@ -611,13 +621,7 @@ var HttpClient = class {
|
|
|
611
621
|
const isFormData = typeof FormData !== "undefined" && o.body instanceof FormData;
|
|
612
622
|
const init = {
|
|
613
623
|
method: o.method,
|
|
614
|
-
headers:
|
|
615
|
-
...o.headers ?? {},
|
|
616
|
-
Authorization: `Bearer ${token}`,
|
|
617
|
-
// JSON bodies: set Content-Type. FormData bodies: let `fetch`
|
|
618
|
-
// emit `multipart/form-data; boundary=...` itself.
|
|
619
|
-
...o.body !== void 0 && !isFormData ? { "Content-Type": "application/json" } : {}
|
|
620
|
-
},
|
|
624
|
+
headers: this.buildHeaders(o, token, isFormData),
|
|
621
625
|
signal: controller.signal
|
|
622
626
|
};
|
|
623
627
|
if (o.body !== void 0) {
|
|
@@ -705,11 +709,7 @@ var HttpClient = class {
|
|
|
705
709
|
const isFormData = typeof FormData !== "undefined" && o.body instanceof FormData;
|
|
706
710
|
const init = {
|
|
707
711
|
method: o.method,
|
|
708
|
-
headers:
|
|
709
|
-
...o.headers ?? {},
|
|
710
|
-
Authorization: `Bearer ${token}`,
|
|
711
|
-
...o.body !== void 0 && !isFormData ? { "Content-Type": "application/json" } : {}
|
|
712
|
-
},
|
|
712
|
+
headers: this.buildHeaders(o, token, isFormData),
|
|
713
713
|
signal: controller.signal,
|
|
714
714
|
...extra?.redirect ? { redirect: extra.redirect } : {}
|
|
715
715
|
};
|
|
@@ -5096,7 +5096,7 @@ var ApprovalService = class {
|
|
|
5096
5096
|
};
|
|
5097
5097
|
|
|
5098
5098
|
// package.json
|
|
5099
|
-
var version = "2.
|
|
5099
|
+
var version = "2.12.0";
|
|
5100
5100
|
|
|
5101
5101
|
// src/version.ts
|
|
5102
5102
|
var SDK_VERSION = version;
|
|
@@ -5165,6 +5165,7 @@ var EmporixClient = class {
|
|
|
5165
5165
|
config;
|
|
5166
5166
|
resolver;
|
|
5167
5167
|
customerRefresh;
|
|
5168
|
+
requestContext;
|
|
5168
5169
|
constructor(config) {
|
|
5169
5170
|
const cfg = validateConfig(config);
|
|
5170
5171
|
this.tenant = cfg.tenant;
|
|
@@ -5188,6 +5189,8 @@ var EmporixClient = class {
|
|
|
5188
5189
|
this.tokenProvider = tokenProvider;
|
|
5189
5190
|
const customerRefresh = new CustomerRefreshRegistry();
|
|
5190
5191
|
this.customerRefresh = customerRefresh;
|
|
5192
|
+
this.requestContext = { language: cfg.credentials.storefront?.context?.language };
|
|
5193
|
+
const requestContext = this.requestContext;
|
|
5191
5194
|
const mk = (service) => ({
|
|
5192
5195
|
tenant: cfg.tenant,
|
|
5193
5196
|
tokenProvider,
|
|
@@ -5198,7 +5201,8 @@ var EmporixClient = class {
|
|
|
5198
5201
|
logger: root.child({ service: "http" }),
|
|
5199
5202
|
retry: cfg.retry,
|
|
5200
5203
|
timeouts: cfg.timeouts,
|
|
5201
|
-
customerRefresh
|
|
5204
|
+
customerRefresh,
|
|
5205
|
+
requestContext
|
|
5202
5206
|
})
|
|
5203
5207
|
});
|
|
5204
5208
|
this.customers = new CustomerService(mk("customer"));
|
|
@@ -5256,9 +5260,18 @@ var EmporixClient = class {
|
|
|
5256
5260
|
* next request re-mints a token bound to the new context. Use this to switch
|
|
5257
5261
|
* currency at runtime. Carts are currency-bound — clear the cart after a
|
|
5258
5262
|
* currency change (the React `setCurrency` does this for you).
|
|
5263
|
+
*
|
|
5264
|
+
* Also sets the storefront `language` (an `Accept-Language` header on every
|
|
5265
|
+
* read); a language-only change does NOT re-mint the token.
|
|
5259
5266
|
*/
|
|
5260
5267
|
setStorefrontContext(ctx) {
|
|
5261
|
-
|
|
5268
|
+
if (ctx.language !== void 0) {
|
|
5269
|
+
this.requestContext.language = ctx.language || void 0;
|
|
5270
|
+
}
|
|
5271
|
+
const { language: _language, ...priceContext } = ctx;
|
|
5272
|
+
if (Object.keys(priceContext).length > 0) {
|
|
5273
|
+
this.tokenProvider.setAnonymousContext?.(priceContext);
|
|
5274
|
+
}
|
|
5262
5275
|
}
|
|
5263
5276
|
/** Sets the runtime log level globally or for one service. */
|
|
5264
5277
|
setLogLevel(level, opts = {}) {
|