@apextelemed/partner-core 0.1.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.
Files changed (114) hide show
  1. package/LICENSE +64 -0
  2. package/README.md +363 -0
  3. package/dist/api/index.d.ts +12 -0
  4. package/dist/api/index.js +8 -0
  5. package/dist/api/index.js.map +1 -0
  6. package/dist/api/index.jsx +127 -0
  7. package/dist/cart-CBH8Em8f.d.ts +189 -0
  8. package/dist/cart-D4mVX_zx.d.ts +66 -0
  9. package/dist/chunk/2OXI5TKO.jsx +249 -0
  10. package/dist/chunk/3A3MF7R2.jsx +1 -0
  11. package/dist/chunk/3VEOP7TZ.jsx +16679 -0
  12. package/dist/chunk/5XGPFYIJ.js +26 -0
  13. package/dist/chunk/5XGPFYIJ.js.map +1 -0
  14. package/dist/chunk/67KHO66G.js +26 -0
  15. package/dist/chunk/67KHO66G.js.map +1 -0
  16. package/dist/chunk/6TFBQECC.jsx +135 -0
  17. package/dist/chunk/AN3WPMEP.js +3 -0
  18. package/dist/chunk/AN3WPMEP.js.map +1 -0
  19. package/dist/chunk/DHII7L5Y.js +686 -0
  20. package/dist/chunk/DHII7L5Y.js.map +1 -0
  21. package/dist/chunk/DS4E7FAI.js +132 -0
  22. package/dist/chunk/DS4E7FAI.js.map +1 -0
  23. package/dist/chunk/DY5BJ6UG.js +1195 -0
  24. package/dist/chunk/DY5BJ6UG.js.map +1 -0
  25. package/dist/chunk/E7722UPF.js +378 -0
  26. package/dist/chunk/E7722UPF.js.map +1 -0
  27. package/dist/chunk/HLXKWRRW.js +16774 -0
  28. package/dist/chunk/HLXKWRRW.js.map +1 -0
  29. package/dist/chunk/I46Y2J5W.jsx +144 -0
  30. package/dist/chunk/J63XPQP4.jsx +21 -0
  31. package/dist/chunk/J6KNY37T.js +122 -0
  32. package/dist/chunk/J6KNY37T.js.map +1 -0
  33. package/dist/chunk/KNTZTYXE.jsx +3315 -0
  34. package/dist/chunk/KZZSQ7LP.jsx +409 -0
  35. package/dist/chunk/L46OKCKG.jsx +733 -0
  36. package/dist/chunk/LDZIUFDM.jsx +31 -0
  37. package/dist/chunk/LZWA44KD.js +3 -0
  38. package/dist/chunk/LZWA44KD.js.map +1 -0
  39. package/dist/chunk/NVRAOAVV.js +3 -0
  40. package/dist/chunk/NVRAOAVV.js.map +1 -0
  41. package/dist/chunk/O3QK7YZR.jsx +1 -0
  42. package/dist/chunk/UZCST66N.jsx +21 -0
  43. package/dist/chunk/V42CGY2S.jsx +1229 -0
  44. package/dist/chunk/YJEHCCLY.js +467 -0
  45. package/dist/chunk/YJEHCCLY.js.map +1 -0
  46. package/dist/chunk/ZMOG2IIC.js +3194 -0
  47. package/dist/chunk/ZMOG2IIC.js.map +1 -0
  48. package/dist/client-BzSg2DEK.d.ts +1539 -0
  49. package/dist/config/index.d.ts +55 -0
  50. package/dist/config/index.js +3 -0
  51. package/dist/config/index.js.map +1 -0
  52. package/dist/config/index.jsx +11 -0
  53. package/dist/flows/index.d.ts +1322 -0
  54. package/dist/flows/index.js +9 -0
  55. package/dist/flows/index.js.map +1 -0
  56. package/dist/flows/index.jsx +124 -0
  57. package/dist/index/index.d.ts +71 -0
  58. package/dist/index/index.js +15 -0
  59. package/dist/index/index.js.map +1 -0
  60. package/dist/index/index.jsx +311 -0
  61. package/dist/pages/index.d.ts +617 -0
  62. package/dist/pages/index.js +10 -0
  63. package/dist/pages/index.js.map +1 -0
  64. package/dist/pages/index.jsx +50 -0
  65. package/dist/primitives/default/index.d.ts +6 -0
  66. package/dist/primitives/default/index.js +3 -0
  67. package/dist/primitives/default/index.js.map +1 -0
  68. package/dist/primitives/default/index.jsx +7 -0
  69. package/dist/primitives/index.d.ts +122 -0
  70. package/dist/primitives/index.js +3 -0
  71. package/dist/primitives/index.js.map +1 -0
  72. package/dist/primitives/index.jsx +9 -0
  73. package/dist/stores/index.d.ts +48 -0
  74. package/dist/stores/index.js +6 -0
  75. package/dist/stores/index.js.map +1 -0
  76. package/dist/stores/index.jsx +16 -0
  77. package/dist/surveyV2-BgQHK0GE.d.ts +48 -0
  78. package/dist/testing/adapter.d.ts +104 -0
  79. package/dist/testing/adapter.d.ts.map +1 -0
  80. package/dist/testing/adapter.js +14 -0
  81. package/dist/testing/adapter.js.map +1 -0
  82. package/dist/testing/env.d.ts +29 -0
  83. package/dist/testing/env.d.ts.map +1 -0
  84. package/dist/testing/env.js +42 -0
  85. package/dist/testing/env.js.map +1 -0
  86. package/dist/testing/fixtures.d.ts +70 -0
  87. package/dist/testing/fixtures.d.ts.map +1 -0
  88. package/dist/testing/fixtures.js +74 -0
  89. package/dist/testing/fixtures.js.map +1 -0
  90. package/dist/testing/index.d.ts +15 -0
  91. package/dist/testing/index.d.ts.map +1 -0
  92. package/dist/testing/index.js +14 -0
  93. package/dist/testing/index.js.map +1 -0
  94. package/dist/testing/mocks.d.ts +53 -0
  95. package/dist/testing/mocks.d.ts.map +1 -0
  96. package/dist/testing/mocks.js +90 -0
  97. package/dist/testing/mocks.js.map +1 -0
  98. package/dist/testing/seam-suite.d.ts +39 -0
  99. package/dist/testing/seam-suite.d.ts.map +1 -0
  100. package/dist/testing/seam-suite.js +196 -0
  101. package/dist/testing/seam-suite.js.map +1 -0
  102. package/dist/testing/storage.d.ts +40 -0
  103. package/dist/testing/storage.d.ts.map +1 -0
  104. package/dist/testing/storage.js +71 -0
  105. package/dist/testing/storage.js.map +1 -0
  106. package/dist/theme/admin.css +579 -0
  107. package/dist/theme/affiliate.css +191 -0
  108. package/dist/theme/flow.css +497 -0
  109. package/dist/theme/index.d.ts +84 -0
  110. package/dist/theme/index.js +94 -0
  111. package/dist/theme/index.js.map +1 -0
  112. package/dist/theme/index.jsx +97 -0
  113. package/dist/theme/member-portal.css +1762 -0
  114. package/package.json +199 -0
@@ -0,0 +1,144 @@
1
+ import {
2
+ getConfig
3
+ } from "./LDZIUFDM.jsx";
4
+
5
+ // src/api/funnel.ts
6
+ var DISABLED = { telemetry: false, emailGate: false, emailGateRequired: false };
7
+ var configPromise = null;
8
+ function fetchFunnelConfig() {
9
+ if (!configPromise) {
10
+ configPromise = (async () => {
11
+ try {
12
+ const cfg = getConfig();
13
+ const res = await fetch(`${cfg.apiBase}/config/funnel`, {
14
+ headers: { "X-Tenant-Key": cfg.tenantKey }
15
+ });
16
+ if (!res.ok) return DISABLED;
17
+ const body = await res.json();
18
+ return {
19
+ telemetry: body.telemetry === true,
20
+ emailGate: body.emailGate === true,
21
+ emailGateRequired: body.emailGateRequired === true
22
+ };
23
+ } catch {
24
+ return DISABLED;
25
+ }
26
+ })();
27
+ }
28
+ return configPromise;
29
+ }
30
+ function adoptFunnelSessionId(id) {
31
+ if (!id) return;
32
+ try {
33
+ sessionStorage.setItem(sessionIdKey(), id);
34
+ } catch {
35
+ }
36
+ }
37
+ function resetFunnelConfigCache() {
38
+ configPromise = null;
39
+ }
40
+ var sessionIdKey = () => `${getConfig().storagePrefix}-funnel-session`;
41
+ function funnelSessionId() {
42
+ let id = null;
43
+ try {
44
+ id = sessionStorage.getItem(sessionIdKey());
45
+ } catch {
46
+ }
47
+ if (!id) {
48
+ id = typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2)}`;
49
+ try {
50
+ sessionStorage.setItem(sessionIdKey(), id);
51
+ } catch {
52
+ }
53
+ }
54
+ return id;
55
+ }
56
+ function peekFunnelSessionId() {
57
+ try {
58
+ return sessionStorage.getItem(sessionIdKey());
59
+ } catch {
60
+ return null;
61
+ }
62
+ }
63
+ function postFunnelEvent(type, data) {
64
+ try {
65
+ const cfg = getConfig();
66
+ void fetch(`${cfg.apiBase}/funnel/events`, {
67
+ method: "POST",
68
+ keepalive: true,
69
+ headers: {
70
+ "Content-Type": "application/json",
71
+ "X-Tenant-Key": cfg.tenantKey
72
+ },
73
+ body: JSON.stringify({ sessionId: funnelSessionId(), type, data })
74
+ }).catch(() => {
75
+ });
76
+ } catch {
77
+ }
78
+ }
79
+ async function saveFunnelDraft(draft) {
80
+ try {
81
+ const cfg = getConfig();
82
+ if (!cfg.apexEmbedApiBase) return null;
83
+ const res = await fetch(`${cfg.apexEmbedApiBase}/v2/embed/surveys/drafts`, {
84
+ method: "PUT",
85
+ headers: { "Content-Type": "application/json", "X-Tenant-Key": cfg.tenantKey },
86
+ body: JSON.stringify(draft)
87
+ });
88
+ if (!res.ok) return null;
89
+ const body = await res.json();
90
+ return body.draftId ?? null;
91
+ } catch {
92
+ return null;
93
+ }
94
+ }
95
+ async function fetchResumedDraft(token) {
96
+ try {
97
+ const cfg = getConfig();
98
+ const res = await fetch(`${cfg.apiBase}/funnel/resume?token=${encodeURIComponent(token)}`, {
99
+ headers: { "X-Tenant-Key": cfg.tenantKey }
100
+ });
101
+ if (!res.ok) return null;
102
+ const body = await res.json();
103
+ if (!body.draftId || !Array.isArray(body.answers)) return null;
104
+ return {
105
+ sessionId: String(body.sessionId ?? ""),
106
+ draftId: body.draftId,
107
+ answers: body.answers,
108
+ stepIndex: typeof body.stepIndex === "number" ? body.stepIndex : 0
109
+ };
110
+ } catch {
111
+ return null;
112
+ }
113
+ }
114
+ function readResumeToken() {
115
+ try {
116
+ const token = new URLSearchParams(window.location.search).get("resume");
117
+ return token && token.length > 0 ? token : null;
118
+ } catch {
119
+ return null;
120
+ }
121
+ }
122
+ function stripResumeToken() {
123
+ try {
124
+ const url = new URL(window.location.href);
125
+ if (!url.searchParams.has("resume")) return;
126
+ url.searchParams.delete("resume");
127
+ window.history.replaceState({}, "", url.toString());
128
+ } catch {
129
+ }
130
+ }
131
+
132
+ export {
133
+ fetchFunnelConfig,
134
+ adoptFunnelSessionId,
135
+ resetFunnelConfigCache,
136
+ funnelSessionId,
137
+ peekFunnelSessionId,
138
+ postFunnelEvent,
139
+ saveFunnelDraft,
140
+ fetchResumedDraft,
141
+ readResumeToken,
142
+ stripResumeToken
143
+ };
144
+ //# sourceMappingURL=I46Y2J5W.jsx.map
@@ -0,0 +1,21 @@
1
+ // src/primitives.tsx
2
+ import { createContext, useContext } from "solid-js";
3
+ var PrimitivesContext = createContext();
4
+ function PrimitivesProvider(props) {
5
+ return <PrimitivesContext.Provider value={props.value}>{props.children}</PrimitivesContext.Provider>;
6
+ }
7
+ function usePrimitives() {
8
+ const ctx = useContext(PrimitivesContext);
9
+ if (!ctx) {
10
+ throw new Error(
11
+ "usePrimitives() called outside <PrimitivesProvider>. Wrap your app at the root."
12
+ );
13
+ }
14
+ return ctx;
15
+ }
16
+
17
+ export {
18
+ PrimitivesProvider,
19
+ usePrimitives
20
+ };
21
+ //# sourceMappingURL=J63XPQP4.jsx.map
@@ -0,0 +1,122 @@
1
+ import { peekFunnelSessionId } from './DS4E7FAI.js';
2
+ import { getConfig } from './5XGPFYIJ.js';
3
+
4
+ // src/api/cart.ts
5
+ var DISABLED = { snapshot: false };
6
+ var configPromise = null;
7
+ function fetchCartConfig() {
8
+ if (!configPromise) {
9
+ configPromise = (async () => {
10
+ try {
11
+ const cfg = getConfig();
12
+ const res = await fetch(`${cfg.apiBase}/config/cart`, {
13
+ headers: { "X-Tenant-Key": cfg.tenantKey }
14
+ });
15
+ if (!res.ok) return DISABLED;
16
+ const body = await res.json();
17
+ return { snapshot: body.snapshot === true };
18
+ } catch {
19
+ return DISABLED;
20
+ }
21
+ })();
22
+ }
23
+ return configPromise;
24
+ }
25
+ function resetCartConfigCache() {
26
+ configPromise = null;
27
+ }
28
+ var cartIdKey = () => `${getConfig().storagePrefix}-cart-id`;
29
+ function cartId() {
30
+ let id = null;
31
+ try {
32
+ id = localStorage.getItem(cartIdKey());
33
+ } catch {
34
+ }
35
+ if (!id) {
36
+ id = typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2)}`;
37
+ try {
38
+ localStorage.setItem(cartIdKey(), id);
39
+ } catch {
40
+ }
41
+ }
42
+ return id;
43
+ }
44
+ function adoptCartId(id) {
45
+ if (!id) return;
46
+ try {
47
+ localStorage.setItem(cartIdKey(), id);
48
+ } catch {
49
+ }
50
+ }
51
+ function resetCartId() {
52
+ try {
53
+ localStorage.removeItem(cartIdKey());
54
+ } catch {
55
+ }
56
+ }
57
+ function postCartSnapshot(params) {
58
+ try {
59
+ const cfg = getConfig();
60
+ void fetch(`${cfg.apiBase}/cart/snapshot`, {
61
+ method: "POST",
62
+ keepalive: true,
63
+ headers: {
64
+ "Content-Type": "application/json",
65
+ "X-Tenant-Key": cfg.tenantKey
66
+ },
67
+ body: JSON.stringify({
68
+ cartId: cartId(),
69
+ items: params.items,
70
+ promoCode: params.promoCode ?? null,
71
+ ...params.email ? { email: params.email } : {},
72
+ // Only when a survey session already exists: it lets the backend reuse
73
+ // the address the pre-survey email gate collected, which is often the
74
+ // only handle we have on an anonymous shopper.
75
+ ...peekFunnelSessionId() ? { sessionId: peekFunnelSessionId() } : {}
76
+ })
77
+ }).catch(() => {
78
+ });
79
+ } catch {
80
+ }
81
+ }
82
+ async function fetchResumedCart(token) {
83
+ try {
84
+ const cfg = getConfig();
85
+ const res = await fetch(`${cfg.apiBase}/cart/resume?token=${encodeURIComponent(token)}`, {
86
+ headers: { "X-Tenant-Key": cfg.tenantKey }
87
+ });
88
+ if (!res.ok) return null;
89
+ const body = await res.json();
90
+ if (!body.cartId || !Array.isArray(body.items) || body.items.length === 0) return null;
91
+ return {
92
+ cartId: body.cartId,
93
+ items: body.items,
94
+ unavailable: Array.isArray(body.unavailable) ? body.unavailable : [],
95
+ promoCode: body.promoCode ?? null,
96
+ subtotalCents: typeof body.subtotalCents === "number" ? body.subtotalCents : 0
97
+ };
98
+ } catch {
99
+ return null;
100
+ }
101
+ }
102
+ function readCartToken() {
103
+ try {
104
+ const token = new URLSearchParams(window.location.search).get("cart");
105
+ return token && token.length > 0 ? token : null;
106
+ } catch {
107
+ return null;
108
+ }
109
+ }
110
+ function stripCartToken() {
111
+ try {
112
+ const url = new URL(window.location.href);
113
+ if (!url.searchParams.has("cart")) return;
114
+ url.searchParams.delete("cart");
115
+ window.history.replaceState({}, "", url.toString());
116
+ } catch {
117
+ }
118
+ }
119
+
120
+ export { adoptCartId, cartId, fetchCartConfig, fetchResumedCart, postCartSnapshot, readCartToken, resetCartConfigCache, resetCartId, stripCartToken };
121
+ //# sourceMappingURL=J6KNY37T.js.map
122
+ //# sourceMappingURL=J6KNY37T.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/api/cart.ts"],"names":[],"mappings":";;;;AAmBA,IAAM,QAAA,GAA8B,EAAE,QAAA,EAAU,KAAA,EAAM;AAEtD,IAAI,aAAA,GAAmD,IAAA;AAMhD,SAAS,eAAA,GAA8C;AAC5D,EAAA,IAAI,CAAC,aAAA,EAAe;AAClB,IAAA,aAAA,GAAA,CAAiB,YAAY;AAC3B,MAAA,IAAI;AACF,QAAA,MAAM,MAAM,SAAA,EAAU;AACtB,QAAA,MAAM,MAAM,MAAM,KAAA,CAAM,CAAA,EAAG,GAAA,CAAI,OAAO,CAAA,YAAA,CAAA,EAAgB;AAAA,UACpD,OAAA,EAAS,EAAE,cAAA,EAAgB,GAAA,CAAI,SAAA;AAAU,SAC1C,CAAA;AACD,QAAA,IAAI,CAAC,GAAA,CAAI,EAAA,EAAI,OAAO,QAAA;AACpB,QAAA,MAAM,IAAA,GAAQ,MAAM,GAAA,CAAI,IAAA,EAAK;AAC7B,QAAA,OAAO,EAAE,QAAA,EAAU,IAAA,CAAK,QAAA,KAAa,IAAA,EAAK;AAAA,MAC5C,CAAA,CAAA,MAAQ;AACN,QAAA,OAAO,QAAA;AAAA,MACT;AAAA,IACF,CAAA,GAAG;AAAA,EACL;AACA,EAAA,OAAO,aAAA;AACT;AAGO,SAAS,oBAAA,GAA6B;AAC3C,EAAA,aAAA,GAAgB,IAAA;AAClB;AAEA,IAAM,SAAA,GAAY,MAAM,CAAA,EAAG,SAAA,GAAY,aAAa,CAAA,QAAA,CAAA;AAY7C,SAAS,MAAA,GAAiB;AAC/B,EAAA,IAAI,EAAA,GAAoB,IAAA;AACxB,EAAA,I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,IAAa,IAAA;AAAA,MAC7B,eAAe,OAAO,IAAA,CAAK,aAAA,KAAkB,QAAA,GAAW,KAAK,aAAA,GAAgB;AAAA,KAC/E;AAAA,EACF,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT;AACF;AAGO,SAAS,aAAA,GAA+B;AAC7C,EAAA,IAAI;AACF,IAAA,MAAM,KAAA,GAAQ,IAAI,eAAA,CAAgB,MAAA,CAAO,SAAS,MAAM,CAAA,CAAE,IAAI,MAAM,CAAA;AACpE,IAAA,OAAO,KAAA,IAAS,KAAA,CAAM,MAAA,GAAS,CAAA,GAAI,KAAA,GAAQ,IAAA;AAAA,EAC7C,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT;AACF;AAOO,SAAS,cAAA,GAAuB;AACrC,EAAA,IAAI;AACF,IAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,MAAA,CAAO,SAAS,IAAI,CAAA;AACxC,IAAA,IAAI,CAAC,GAAA,CAAI,YAAA,CAAa,GAAA,CAAI,MAAM,CAAA,EAAG;AACnC,IAAA,GAAA,CAAI,YAAA,CAAa,OAAO,MAAM,CAAA;AAC9B,IAAA,MAAA,CAAO,QAAQ,YAAA,CAAa,IAAI,EAAA,EAAI,GAAA,CAAI,UAAU,CAAA;AAAA,EACpD,CAAA,CAAA,MAAQ;AAAA,EAER;AACF","file":"J6KNY37T.js","sourcesContent":["import { getConfig } from '../config';\nimport { peekFunnelSessionId } from './funnel';\n\n// ── Abandoned-cart transport ────────────────────────────────────────────────\n//\n// Thin client for the-backend's cart-capture endpoints:\n// GET /config/cart → whether this tenant mirrors carts at all\n// POST /cart/snapshot → server-side mirror of the browser's cart\n// GET /cart/resume → trade an emailed token for the saved cart\n//\n// Sibling of ./funnel, and the same posture: fire-and-forget, fail-silent.\n// Cart capture is marketing instrumentation and must never break, block or\n// slow down shopping.\n\nexport interface CartCaptureConfig {\n /** Tenant opted in (features.cartRecovery); false = never send anything. */\n snapshot: boolean;\n}\n\nconst DISABLED: CartCaptureConfig = { snapshot: false };\n\nlet configPromise: Promise<CartCaptureConfig> | null = null;\n\n/**\n * The tenant's cart-capture posture, fetched once per page load and cached.\n * Fails closed: any error reads as \"off\".\n */\nexport function fetchCartConfig(): Promise<CartCaptureConfig> {\n if (!configPromise) {\n configPromise = (async () => {\n try {\n const cfg = getConfig();\n const res = await fetch(`${cfg.apiBase}/config/cart`, {\n headers: { 'X-Tenant-Key': cfg.tenantKey },\n });\n if (!res.ok) return DISABLED;\n const body = (await res.json()) as Partial<CartCaptureConfig>;\n return { snapshot: body.snapshot === true };\n } catch {\n return DISABLED;\n }\n })();\n }\n return configPromise;\n}\n\n/** Test seam: forget the cached config so the next fetch re-resolves. */\nexport function resetCartConfigCache(): void {\n configPromise = null;\n}\n\nconst cartIdKey = () => `${getConfig().storagePrefix}-cart-id`;\n\n/**\n * Stable id for this shopper's cart, minted on first use and kept in\n * localStorage — NOT sessionStorage like the survey session.\n *\n * A cart outlives the tab it was filled in: someone adds items, closes the\n * browser, comes back tomorrow and finds the cart still there (the cart store\n * itself persists the same way). The id has to survive with it, or every visit\n * would look like a brand-new abandoned cart and one shopper would accumulate\n * a row — and a reminder track — per session.\n */\nexport function cartId(): string {\n let id: string | null = null;\n try {\n id = localStorage.getItem(cartIdKey());\n } catch {\n /* storage unavailable (private mode) — fall through to an ephemeral id */\n }\n if (!id) {\n id =\n typeof crypto !== 'undefined' && 'randomUUID' in crypto\n ? crypto.randomUUID()\n : `${Date.now()}-${Math.random().toString(36).slice(2)}`;\n try {\n localStorage.setItem(cartIdKey(), id);\n } catch {\n /* ephemeral it is */\n }\n }\n return id;\n}\n\n/**\n * Continue the cart a recovery email points at, instead of the one this browser\n * happens to hold. Adopting the emailed id keeps the reminder history, the\n * email address and the eventual conversion on ONE row.\n */\nexport function adoptCartId(id: string): void {\n if (!id) return;\n try {\n localStorage.setItem(cartIdKey(), id);\n } catch {\n /* storage unavailable — the adoption is ephemeral */\n }\n}\n\n/**\n * Start a fresh cart id. Called after a purchase: the old id is stamped\n * converted server-side and must never be written to again, or a new cart\n * would inherit a bought cart's row (and its silence — converted rows are\n * never nudged).\n */\nexport function resetCartId(): void {\n try {\n localStorage.removeItem(cartIdKey());\n } catch {\n /* nothing to clear */\n }\n}\n\nexport interface CartSnapshotLine {\n productId: string;\n dosage?: string;\n quantity: number;\n}\n\n/**\n * Mirror the cart server-side. Identity only — the backend re-prices from the\n * catalog and ignores anything else we send, so there is no point shipping\n * names or prices.\n *\n * `keepalive` lets the request survive the page unload that so often IS the\n * abandonment.\n */\nexport function postCartSnapshot(params: {\n items: CartSnapshotLine[];\n promoCode?: string | null;\n email?: string | null;\n}): void {\n try {\n const cfg = getConfig();\n void fetch(`${cfg.apiBase}/cart/snapshot`, {\n method: 'POST',\n keepalive: true,\n headers: {\n 'Content-Type': 'application/json',\n 'X-Tenant-Key': cfg.tenantKey,\n },\n body: JSON.stringify({\n cartId: cartId(),\n items: params.items,\n promoCode: params.promoCode ?? null,\n ...(params.email ? { email: params.email } : {}),\n // Only when a survey session already exists: it lets the backend reuse\n // the address the pre-survey email gate collected, which is often the\n // only handle we have on an anonymous shopper.\n ...(peekFunnelSessionId() ? { sessionId: peekFunnelSessionId() } : {}),\n }),\n }).catch(() => {});\n } catch {\n /* not configured yet — drop */\n }\n}\n\n/** A resumed cart line, already re-priced against today's catalog. */\nexport interface ResumedCartLine {\n productId: string;\n dosage?: string;\n quantity: number;\n name: string;\n priceCents: number;\n salePriceCents: number | null;\n thumbnailUrl: string | null;\n isSubscription: boolean;\n apexDrugId: string | null;\n categories: string[];\n hideDoseLabel: boolean;\n}\n\nexport interface ResumedCart {\n cartId: string;\n items: ResumedCartLine[];\n /** Lines whose product has since been discontinued or deactivated. */\n unavailable: Array<{ productId: string; dosage?: string; quantity: number }>;\n promoCode: string | null;\n subtotalCents: number;\n}\n\n/**\n * Exchange an emailed recovery token for the saved cart.\n *\n * The token is the ONLY thing authorizing this read — the-backend verifies its\n * HMAC before returning anything. A 404 (expired, already bought, tampered, or\n * every product gone) resolves to null so the caller simply keeps whatever cart\n * this browser already had.\n */\nexport async function fetchResumedCart(token: string): Promise<ResumedCart | null> {\n try {\n const cfg = getConfig();\n const res = await fetch(`${cfg.apiBase}/cart/resume?token=${encodeURIComponent(token)}`, {\n headers: { 'X-Tenant-Key': cfg.tenantKey },\n });\n if (!res.ok) return null;\n const body = (await res.json()) as Partial<ResumedCart>;\n if (!body.cartId || !Array.isArray(body.items) || body.items.length === 0) return null;\n return {\n cartId: body.cartId,\n items: body.items,\n unavailable: Array.isArray(body.unavailable) ? body.unavailable : [],\n promoCode: body.promoCode ?? null,\n subtotalCents: typeof body.subtotalCents === 'number' ? body.subtotalCents : 0,\n };\n } catch {\n return null;\n }\n}\n\n/** Read the `?cart=` token from the current URL. */\nexport function readCartToken(): string | null {\n try {\n const token = new URLSearchParams(window.location.search).get('cart');\n return token && token.length > 0 ? token : null;\n } catch {\n return null;\n }\n}\n\n/**\n * Drop `?cart=` from the address bar once it's been redeemed, so a refresh (or\n * a shared URL) doesn't re-run the restore over a cart the shopper has since\n * edited. History is replaced, not pushed — the token was never a page.\n */\nexport function stripCartToken(): void {\n try {\n const url = new URL(window.location.href);\n if (!url.searchParams.has('cart')) return;\n url.searchParams.delete('cart');\n window.history.replaceState({}, '', url.toString());\n } catch {\n /* no history API — leaving the param is harmless */\n }\n}\n"]}