@viu/emporix-sdk 2.30.0 → 2.31.1

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,71 @@
1
1
  # @viu/emporix-sdk
2
2
 
3
+ ## 2.31.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#227](https://github.com/viuteam/emporix-sdk/pull/227) [`208f45a`](https://github.com/viuteam/emporix-sdk/commit/208f45a7b36519979d80f74b075c64bafb245919) Thanks [@viu-release-bot](https://github.com/apps/viu-release-bot)! - chore(sdk): sync generated types with upstream Emporix API specs
8
+
9
+ Updated services: import-service
10
+
11
+ ## 2.31.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [#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
16
+ dependency is gone, and the built package contains zero imports of it.
17
+
18
+ A server-first Next app therefore installs **three** packages instead of four,
19
+ and with them no React and no `@tanstack/react-query` — both are peers of the
20
+ React bindings, and neither has anything to do with a mode where the browser makes
21
+ no Emporix calls at all.
22
+
23
+ What moved to `@viu/emporix-sdk` (`core/session-storage.ts`), completing the step
24
+ that started with `STORAGE_KEYS`:
25
+
26
+ | Export | Was |
27
+ | ------------------------------------------------------------- | ------------------------------------------------------- |
28
+ | `EmporixStorage`, `TokenStorage`, `PersistedAnonymousSession` | the session-persistence contract |
29
+ | `parseAnonymousSession` | parses a stored anonymous session |
30
+ | `createCookieBackedStorage`, `CookieIo` | the whole key-to-accessor mapping |
31
+ | `createServerStorage`, `ServerCookieJar` | an `EmporixStorage` over any cookie jar |
32
+ | `serverAuth` | customer context when a token is stored, else anonymous |
33
+
34
+ None of it imports React — `createServerStorage` fits Next, Remix, SvelteKit,
35
+ Nitro or a plain Node handler, and it was only ever in the React package because
36
+ that is where the browser backends live. Those stay: `createMemoryStorage`,
37
+ `createLocalStorage`, `createSessionStorage`, `createCookieStorage` and the
38
+ `subscribeAll` listener set are genuinely browser concerns.
39
+
40
+ **Nothing to change in your code.** `@viu/emporix-sdk-react` re-exports every
41
+ moved name from `./storage` and `/ssr`, with one definition only. One type is now
42
+ derived rather than re-declared: `PersistedAnonymousSession` is
43
+ `Pick<StoredAnonymousSession, "refreshToken" | "sessionId">`, which is what it
44
+ always was in practice — the browser adapters deliberately persist only those two
45
+ fields, while a server store may also keep the access token.
46
+
47
+ - [#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
48
+ `EmporixStorageKey` are now exported from `@viu/emporix-sdk`.
49
+
50
+ They were never a React concern. The same eight strings are cookie names in a
51
+ Next `proxy.ts`, Web Storage keys in a browser adapter, and record fields in a
52
+ server-side session store — but they lived in `@viu/emporix-sdk-react`, which is
53
+ why `@viu/emporix-sdk-next` depended on the React bindings to name a cookie. Six
54
+ of the seven files in that package imported nothing else from it.
55
+
56
+ Nothing to change in your code. `@viu/emporix-sdk-react` re-exports both from
57
+ `./storage` and `/ssr`, and `@viu/emporix-sdk-next` still re-exports
58
+ `STORAGE_KEYS` from `/session`. There is exactly one definition, and a test
59
+ asserts object identity across all three paths — a copy would be the one drift
60
+ that silently breaks a session by writing a cookie under one name and reading it
61
+ under another.
62
+
63
+ Measured on the built output: `@viu/emporix-sdk-next` reached for
64
+ `@viu/emporix-sdk-react` in seven places before, and now does so in one —
65
+ `server-session.ts`, for `createServerStorage`, `serverAuth` and the
66
+ `EmporixStorage` type. Removing that last one (and the peer dependency with it) is
67
+ a follow-up, because it touches a public signature.
68
+
3
69
  ## 2.30.0
4
70
 
5
71
  ### 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.1";
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