@viu/emporix-sdk 2.30.0 → 2.31.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 CHANGED
@@ -1,5 +1,63 @@
1
1
  # @viu/emporix-sdk
2
2
 
3
+ ## 2.31.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#216](https://github.com/viuteam/emporix-sdk/pull/216) [`ca45e50`](https://github.com/viuteam/emporix-sdk/commit/ca45e50bf79ab7d72c51c0687f383bffeecfcf6d) Thanks [@amnael1](https://github.com/amnael1)! - `@viu/emporix-sdk-next` no longer depends on `@viu/emporix-sdk-react`. The peer
8
+ dependency is gone, and the built package contains zero imports of it.
9
+
10
+ A server-first Next app therefore installs **three** packages instead of four,
11
+ and with them no React and no `@tanstack/react-query` — both are peers of the
12
+ React bindings, and neither has anything to do with a mode where the browser makes
13
+ no Emporix calls at all.
14
+
15
+ What moved to `@viu/emporix-sdk` (`core/session-storage.ts`), completing the step
16
+ that started with `STORAGE_KEYS`:
17
+
18
+ | Export | Was |
19
+ | ------------------------------------------------------------- | ------------------------------------------------------- |
20
+ | `EmporixStorage`, `TokenStorage`, `PersistedAnonymousSession` | the session-persistence contract |
21
+ | `parseAnonymousSession` | parses a stored anonymous session |
22
+ | `createCookieBackedStorage`, `CookieIo` | the whole key-to-accessor mapping |
23
+ | `createServerStorage`, `ServerCookieJar` | an `EmporixStorage` over any cookie jar |
24
+ | `serverAuth` | customer context when a token is stored, else anonymous |
25
+
26
+ None of it imports React — `createServerStorage` fits Next, Remix, SvelteKit,
27
+ Nitro or a plain Node handler, and it was only ever in the React package because
28
+ that is where the browser backends live. Those stay: `createMemoryStorage`,
29
+ `createLocalStorage`, `createSessionStorage`, `createCookieStorage` and the
30
+ `subscribeAll` listener set are genuinely browser concerns.
31
+
32
+ **Nothing to change in your code.** `@viu/emporix-sdk-react` re-exports every
33
+ moved name from `./storage` and `/ssr`, with one definition only. One type is now
34
+ derived rather than re-declared: `PersistedAnonymousSession` is
35
+ `Pick<StoredAnonymousSession, "refreshToken" | "sessionId">`, which is what it
36
+ always was in practice — the browser adapters deliberately persist only those two
37
+ fields, while a server store may also keep the access token.
38
+
39
+ - [#215](https://github.com/viuteam/emporix-sdk/pull/215) [`e9d019d`](https://github.com/viuteam/emporix-sdk/commit/e9d019d4a5bf3238311dab11e5fb856ce5689004) Thanks [@amnael1](https://github.com/amnael1)! - Move the eight session keys into the core SDK: `STORAGE_KEYS` and
40
+ `EmporixStorageKey` are now exported from `@viu/emporix-sdk`.
41
+
42
+ They were never a React concern. The same eight strings are cookie names in a
43
+ Next `proxy.ts`, Web Storage keys in a browser adapter, and record fields in a
44
+ server-side session store — but they lived in `@viu/emporix-sdk-react`, which is
45
+ why `@viu/emporix-sdk-next` depended on the React bindings to name a cookie. Six
46
+ of the seven files in that package imported nothing else from it.
47
+
48
+ Nothing to change in your code. `@viu/emporix-sdk-react` re-exports both from
49
+ `./storage` and `/ssr`, and `@viu/emporix-sdk-next` still re-exports
50
+ `STORAGE_KEYS` from `/session`. There is exactly one definition, and a test
51
+ asserts object identity across all three paths — a copy would be the one drift
52
+ that silently breaks a session by writing a cookie under one name and reading it
53
+ under another.
54
+
55
+ Measured on the built output: `@viu/emporix-sdk-next` reached for
56
+ `@viu/emporix-sdk-react` in seven places before, and now does so in one —
57
+ `server-session.ts`, for `createServerStorage`, `serverAuth` and the
58
+ `EmporixStorage` type. Removing that last one (and the peer dependency with it) is
59
+ a follow-up, because it touches a public signature.
60
+
3
61
  ## 2.30.0
4
62
 
5
63
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -595,6 +595,78 @@ var DefaultTokenProvider = class {
595
595
  }
596
596
  };
597
597
 
598
+ // src/core/session-keys.ts
599
+ var STORAGE_KEYS = {
600
+ customerToken: "emporix.customerToken",
601
+ cartId: "emporix.cartId",
602
+ anonymousSession: "emporix.anonymousSession",
603
+ siteCode: "emporix.siteCode",
604
+ language: "emporix.language",
605
+ activeLegalEntityId: "emporix.activeLegalEntityId",
606
+ refreshToken: "emporix.refreshToken",
607
+ saasToken: "emporix.saasToken"
608
+ };
609
+
610
+ // src/core/session-storage.ts
611
+ function parseAnonymousSession(raw) {
612
+ if (raw === null) return null;
613
+ try {
614
+ const parsed = JSON.parse(raw);
615
+ return typeof parsed.refreshToken === "string" && typeof parsed.sessionId === "string" ? { refreshToken: parsed.refreshToken, sessionId: parsed.sessionId } : null;
616
+ } catch {
617
+ return null;
618
+ }
619
+ }
620
+ function createCookieBackedStorage(io, opts = {}) {
621
+ const tokenName = opts.tokenName ?? STORAGE_KEYS.customerToken;
622
+ const notify = opts.notify;
623
+ const warned = /* @__PURE__ */ new Set();
624
+ const write = (name, value, key) => {
625
+ if (io.set === void 0) {
626
+ if (!warned.has(key)) {
627
+ warned.add(key);
628
+ console.warn(
629
+ `[emporix] storage is read-only; ignoring write to "${key}". Provide a \`set\` accessor to enable writes (e.g. from a Server Action).`
630
+ );
631
+ }
632
+ return;
633
+ }
634
+ io.set(name, value);
635
+ notify?.(key);
636
+ };
637
+ return {
638
+ getCustomerToken: () => io.get(tokenName),
639
+ setCustomerToken: (t) => write(tokenName, t, "customerToken"),
640
+ getCartId: () => io.get(STORAGE_KEYS.cartId),
641
+ setCartId: (id) => write(STORAGE_KEYS.cartId, id, "cartId"),
642
+ getAnonymousSession: () => parseAnonymousSession(io.get(STORAGE_KEYS.anonymousSession)),
643
+ setAnonymousSession: (s) => write(
644
+ STORAGE_KEYS.anonymousSession,
645
+ s === null ? null : JSON.stringify({ refreshToken: s.refreshToken, sessionId: s.sessionId }),
646
+ "anonymousSession"
647
+ ),
648
+ getSiteCode: () => io.get(STORAGE_KEYS.siteCode),
649
+ setSiteCode: (code) => write(STORAGE_KEYS.siteCode, code, "siteCode"),
650
+ getLanguage: () => io.get(STORAGE_KEYS.language),
651
+ setLanguage: (l) => write(STORAGE_KEYS.language, l, "language"),
652
+ getActiveLegalEntityId: () => io.get(STORAGE_KEYS.activeLegalEntityId),
653
+ setActiveLegalEntityId: (id) => write(STORAGE_KEYS.activeLegalEntityId, id, "activeLegalEntityId"),
654
+ getRefreshToken: () => io.get(STORAGE_KEYS.refreshToken),
655
+ setRefreshToken: (t) => write(STORAGE_KEYS.refreshToken, t, "refreshToken"),
656
+ getSaasToken: () => io.get(STORAGE_KEYS.saasToken),
657
+ setSaasToken: (t) => write(STORAGE_KEYS.saasToken, t, "saasToken")
658
+ };
659
+ }
660
+ function createServerStorage(jar) {
661
+ return createCookieBackedStorage(
662
+ jar.set !== void 0 ? { get: jar.get, set: jar.set } : { get: jar.get }
663
+ );
664
+ }
665
+ function serverAuth(storage) {
666
+ const token = storage.getCustomerToken();
667
+ return token !== null ? auth.customer(token) : auth.anonymous();
668
+ }
669
+
598
670
  // src/core/sse.ts
599
671
  function parseFrame(frame) {
600
672
  const ev = { data: "" };
@@ -893,7 +965,7 @@ var HttpClient = class {
893
965
  };
894
966
 
895
967
  // package.json
896
- var version = "2.30.0";
968
+ var version = "2.31.0";
897
969
 
898
970
  // src/version.ts
899
971
  var SDK_VERSION = version;
@@ -8516,6 +8588,7 @@ exports.QuoteService = QuoteService;
8516
8588
  exports.RagIndexerService = RagIndexerService;
8517
8589
  exports.ReturnsService = ReturnsService;
8518
8590
  exports.RewardPointsService = RewardPointsService;
8591
+ exports.STORAGE_KEYS = STORAGE_KEYS;
8519
8592
  exports.SalesOrdersService = SalesOrdersService;
8520
8593
  exports.SchemaService = SchemaService;
8521
8594
  exports.SegmentService = SegmentService;
@@ -8532,17 +8605,21 @@ exports.VendorService = VendorService;
8532
8605
  exports.WebhookService = WebhookService;
8533
8606
  exports.auth = auth;
8534
8607
  exports.createConsoleLogger = createConsoleLogger;
8608
+ exports.createCookieBackedStorage = createCookieBackedStorage;
8535
8609
  exports.createCore = createCore;
8536
8610
  exports.createEmporixClient = createEmporixClient;
8537
8611
  exports.createNoopLogger = createNoopLogger;
8612
+ exports.createServerStorage = createServerStorage;
8538
8613
  exports.errorFromResponse = errorFromResponse;
8539
8614
  exports.iterateAll = iterateAll;
8615
+ exports.parseAnonymousSession = parseAnonymousSession;
8540
8616
  exports.pickFee = pickFee;
8541
8617
  exports.productIdFromYrn = productIdFromYrn;
8542
8618
  exports.redact = redact;
8543
8619
  exports.resolveQuery = resolveQuery;
8544
8620
  exports.resolveToken = resolveToken;
8545
8621
  exports.resolveZone = resolveZone;
8622
+ exports.serverAuth = serverAuth;
8546
8623
  exports.validateConfig = validateConfig;
8547
8624
  //# sourceMappingURL=index.cjs.map
8548
8625
  //# sourceMappingURL=index.cjs.map