@viu/emporix-sdk 2.9.0 → 2.10.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 +18 -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-DJDTlhLW.d.cts → context-BBKOwNW6.d.cts} +16 -0
- package/dist/{context-DJDTlhLW.d.ts → context-BBKOwNW6.d.ts} +16 -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 +18 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +18 -2
- 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,23 @@
|
|
|
1
1
|
# @viu/emporix-sdk
|
|
2
2
|
|
|
3
|
+
## 2.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#112](https://github.com/viuteam/emporix-sdk/pull/112) [`1f87a9b`](https://github.com/viuteam/emporix-sdk/commit/1f87a9b54ddde591716eba7427e04573113b17f9) Thanks [@amnael1](https://github.com/amnael1)! - feat: runtime currency switching
|
|
8
|
+
|
|
9
|
+
Adds `EmporixClient.setStorefrontContext({ currency, siteCode, targetLocation })`
|
|
10
|
+
to re-bind the anonymous price context at runtime (invalidating the anon session
|
|
11
|
+
so the next login re-mints with the new currency — covers the pre-cart guest
|
|
12
|
+
case `sessionContext.patch` cannot). Adds `useSiteContext().setCurrency(code)`,
|
|
13
|
+
which re-binds the context, clears the currency-bound guest cart, and PATCHes an
|
|
14
|
+
existing server session context. The storefront-demo gains a currency dropdown
|
|
15
|
+
populated from the active site's `availableCurrencies`.
|
|
16
|
+
|
|
17
|
+
On reload, the site-context `currency` now seeds from the client's configured
|
|
18
|
+
`context.currency` (instead of always deriving from the site default), so a
|
|
19
|
+
persisted currency choice is respected.
|
|
20
|
+
|
|
3
21
|
## 2.9.0
|
|
4
22
|
|
|
5
23
|
### 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-BBKOwNW6.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-BBKOwNW6.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-BBKOwNW6.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-BBKOwNW6.js';
|
|
2
2
|
import { C as ContactAssignment, a as ContactAssignmentCreate, b as ContactAssignmentUpdate } from './types.gen-C_wOXYZB.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -222,6 +222,16 @@ interface TokenProvider {
|
|
|
222
222
|
* replaces the previous adapter.
|
|
223
223
|
*/
|
|
224
224
|
attachAnonymousStore?(store: AnonymousSessionStore): void;
|
|
225
|
+
/**
|
|
226
|
+
* Override the storefront context (currency/site/country) used for the next
|
|
227
|
+
* anonymous login, then invalidate the current anonymous session so it
|
|
228
|
+
* re-mints with the new context. No-op for providers without anon support.
|
|
229
|
+
*/
|
|
230
|
+
setAnonymousContext?(ctx: {
|
|
231
|
+
currency?: string;
|
|
232
|
+
siteCode?: string;
|
|
233
|
+
targetLocation?: string;
|
|
234
|
+
}): void;
|
|
225
235
|
/**
|
|
226
236
|
* Subscribe to token-refresh events. Optional — implementations may no-op.
|
|
227
237
|
* Returns an unsubscribe function. `DefaultTokenProvider` emits for the
|
|
@@ -267,6 +277,7 @@ declare class DefaultTokenProvider implements TokenProvider {
|
|
|
267
277
|
private anon;
|
|
268
278
|
private anonLock;
|
|
269
279
|
private anonStore?;
|
|
280
|
+
private contextOverride;
|
|
270
281
|
private readonly refreshListeners;
|
|
271
282
|
constructor(cfg: ResolvedConfig);
|
|
272
283
|
onRefresh(listener: (event: {
|
|
@@ -285,6 +296,11 @@ declare class DefaultTokenProvider implements TokenProvider {
|
|
|
285
296
|
/** Refreshes the anonymous session, preserving its sessionId. */
|
|
286
297
|
refreshAnonymous(): Promise<AnonymousSession>;
|
|
287
298
|
invalidateAnonymous(): void;
|
|
299
|
+
setAnonymousContext(ctx: {
|
|
300
|
+
currency?: string;
|
|
301
|
+
siteCode?: string;
|
|
302
|
+
targetLocation?: string;
|
|
303
|
+
}): void;
|
|
288
304
|
/** Force a stale access token while keeping the refresh token + sessionId. */
|
|
289
305
|
expireAnonymous(): void;
|
|
290
306
|
private stripExpiry;
|
|
@@ -222,6 +222,16 @@ interface TokenProvider {
|
|
|
222
222
|
* replaces the previous adapter.
|
|
223
223
|
*/
|
|
224
224
|
attachAnonymousStore?(store: AnonymousSessionStore): void;
|
|
225
|
+
/**
|
|
226
|
+
* Override the storefront context (currency/site/country) used for the next
|
|
227
|
+
* anonymous login, then invalidate the current anonymous session so it
|
|
228
|
+
* re-mints with the new context. No-op for providers without anon support.
|
|
229
|
+
*/
|
|
230
|
+
setAnonymousContext?(ctx: {
|
|
231
|
+
currency?: string;
|
|
232
|
+
siteCode?: string;
|
|
233
|
+
targetLocation?: string;
|
|
234
|
+
}): void;
|
|
225
235
|
/**
|
|
226
236
|
* Subscribe to token-refresh events. Optional — implementations may no-op.
|
|
227
237
|
* Returns an unsubscribe function. `DefaultTokenProvider` emits for the
|
|
@@ -267,6 +277,7 @@ declare class DefaultTokenProvider implements TokenProvider {
|
|
|
267
277
|
private anon;
|
|
268
278
|
private anonLock;
|
|
269
279
|
private anonStore?;
|
|
280
|
+
private contextOverride;
|
|
270
281
|
private readonly refreshListeners;
|
|
271
282
|
constructor(cfg: ResolvedConfig);
|
|
272
283
|
onRefresh(listener: (event: {
|
|
@@ -285,6 +296,11 @@ declare class DefaultTokenProvider implements TokenProvider {
|
|
|
285
296
|
/** Refreshes the anonymous session, preserving its sessionId. */
|
|
286
297
|
refreshAnonymous(): Promise<AnonymousSession>;
|
|
287
298
|
invalidateAnonymous(): void;
|
|
299
|
+
setAnonymousContext(ctx: {
|
|
300
|
+
currency?: string;
|
|
301
|
+
siteCode?: string;
|
|
302
|
+
targetLocation?: string;
|
|
303
|
+
}): void;
|
|
288
304
|
/** Force a stale access token while keeping the refresh token + sessionId. */
|
|
289
305
|
expireAnonymous(): void;
|
|
290
306
|
private stripExpiry;
|
package/dist/customer.d.cts
CHANGED
package/dist/customer.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -396,6 +396,7 @@ var DefaultTokenProvider = class {
|
|
|
396
396
|
anon;
|
|
397
397
|
anonLock;
|
|
398
398
|
anonStore;
|
|
399
|
+
contextOverride;
|
|
399
400
|
refreshListeners = /* @__PURE__ */ new Set();
|
|
400
401
|
onRefresh(listener) {
|
|
401
402
|
this.refreshListeners.add(listener);
|
|
@@ -508,6 +509,11 @@ var DefaultTokenProvider = class {
|
|
|
508
509
|
this.anon = void 0;
|
|
509
510
|
this.anonStore?.write(null);
|
|
510
511
|
}
|
|
512
|
+
setAnonymousContext(ctx) {
|
|
513
|
+
const base = this.contextOverride ?? this.cfg.credentials.storefront?.context ?? {};
|
|
514
|
+
this.contextOverride = { ...base, ...ctx };
|
|
515
|
+
this.invalidateAnonymous();
|
|
516
|
+
}
|
|
511
517
|
/** Force a stale access token while keeping the refresh token + sessionId. */
|
|
512
518
|
expireAnonymous() {
|
|
513
519
|
if (this.anon) this.anon = { ...this.anon, expiresAt: 0 };
|
|
@@ -524,7 +530,7 @@ var DefaultTokenProvider = class {
|
|
|
524
530
|
const url = new URL(`${this.cfg.host}/customerlogin/auth/anonymous/${mode}`);
|
|
525
531
|
url.searchParams.set("tenant", this.cfg.tenant);
|
|
526
532
|
url.searchParams.set("client_id", sf.clientId);
|
|
527
|
-
const c = sf.context;
|
|
533
|
+
const c = this.contextOverride ?? sf.context;
|
|
528
534
|
if (c?.currency) url.searchParams.set("currency", c.currency);
|
|
529
535
|
if (c?.siteCode) url.searchParams.set("siteCode", c.siteCode);
|
|
530
536
|
if (c?.targetLocation) url.searchParams.set("targetLocation", c.targetLocation);
|
|
@@ -5068,7 +5074,7 @@ var ApprovalService = class {
|
|
|
5068
5074
|
};
|
|
5069
5075
|
|
|
5070
5076
|
// package.json
|
|
5071
|
-
var version = "2.
|
|
5077
|
+
var version = "2.10.0";
|
|
5072
5078
|
|
|
5073
5079
|
// src/version.ts
|
|
5074
5080
|
var SDK_VERSION = version;
|
|
@@ -5220,6 +5226,16 @@ var EmporixClient = class {
|
|
|
5220
5226
|
this.customerAdmin = new CustomerAdminService(mk("customer-admin"));
|
|
5221
5227
|
this.approvals = new ApprovalService(mk("approval"));
|
|
5222
5228
|
}
|
|
5229
|
+
/**
|
|
5230
|
+
* Re-binds the storefront price context (currency / siteCode / targetLocation)
|
|
5231
|
+
* for anonymous pricing and invalidates the current anonymous session, so the
|
|
5232
|
+
* next request re-mints a token bound to the new context. Use this to switch
|
|
5233
|
+
* currency at runtime. Carts are currency-bound — clear the cart after a
|
|
5234
|
+
* currency change (the React `setCurrency` does this for you).
|
|
5235
|
+
*/
|
|
5236
|
+
setStorefrontContext(ctx) {
|
|
5237
|
+
this.tokenProvider.setAnonymousContext?.(ctx);
|
|
5238
|
+
}
|
|
5223
5239
|
/** Sets the runtime log level globally or for one service. */
|
|
5224
5240
|
setLogLevel(level, opts = {}) {
|
|
5225
5241
|
this.resolver.set(level, opts.service, opts.force ?? false);
|