@apextelemed/partner-core 0.10.0-dev.22 → 0.10.0-dev.24
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/README.md +21 -2
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.js +3 -3
- package/dist/api/index.jsx +5 -3
- package/dist/chunk/{NSEWFPUP.js → 7MCMXXYQ.js} +50 -3
- package/dist/chunk/7MCMXXYQ.js.map +1 -0
- package/dist/chunk/{TYXWVNC3.js → BNH4UOGN.js} +55 -12
- package/dist/chunk/BNH4UOGN.js.map +1 -0
- package/dist/chunk/{ET3GPUTR.jsx → CLNLTAG7.jsx} +59 -12
- package/dist/chunk/{BALHOD46.jsx → EZG74SQL.jsx} +49 -1
- package/dist/chunk/{DHVOZQQ2.js → FA4D2S5A.js} +3 -3
- package/dist/chunk/{DHVOZQQ2.js.map → FA4D2S5A.js.map} +1 -1
- package/dist/chunk/{OA3A3PUC.jsx → FM3JH2ZD.jsx} +1638 -860
- package/dist/chunk/{L2ZMGXWR.js → JKUWPGEW.js} +31 -6
- package/dist/chunk/JKUWPGEW.js.map +1 -0
- package/dist/chunk/{JL7B6RHG.js → M2LV5JQD.js} +3 -3
- package/dist/chunk/{JL7B6RHG.js.map → M2LV5JQD.js.map} +1 -1
- package/dist/chunk/{CYGHTTCA.js → NHNMRJL6.js} +1715 -905
- package/dist/chunk/NHNMRJL6.js.map +1 -0
- package/dist/chunk/{DBW2RWHV.jsx → RRKAKQ77.jsx} +2 -2
- package/dist/chunk/{QIBVNW2V.jsx → VF7FTWCG.jsx} +2 -2
- package/dist/chunk/{75F4YFYC.jsx → VG35MW6B.jsx} +33 -4
- package/dist/chunk/{ZW2HBOS5.jsx → XW4PEQPI.jsx} +2 -2
- package/dist/chunk/{4CTTOSOW.js → XZXPLS3K.js} +3 -3
- package/dist/chunk/{4CTTOSOW.js.map → XZXPLS3K.js.map} +1 -1
- package/dist/{client-CDpCqI4d.d.ts → client-DsIvVM5a.d.ts} +143 -1
- package/dist/flows/index.d.ts +213 -141
- package/dist/flows/index.js +6 -6
- package/dist/flows/index.jsx +16 -6
- package/dist/index/index.d.ts +2 -2
- package/dist/index/index.js +7 -7
- package/dist/index/index.jsx +19 -7
- package/dist/pages/index.d.ts +2 -2
- package/dist/pages/index.js +5 -5
- package/dist/pages/index.jsx +5 -5
- package/dist/stores/index.d.ts +1 -1
- package/dist/stores/index.js +2 -2
- package/dist/stores/index.jsx +2 -2
- package/package.json +1 -1
- package/dist/chunk/CYGHTTCA.js.map +0 -1
- package/dist/chunk/L2ZMGXWR.js.map +0 -1
- package/dist/chunk/NSEWFPUP.js.map +0 -1
- package/dist/chunk/TYXWVNC3.js.map +0 -1
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
setAffiliateTokens,
|
|
13
13
|
setTokens,
|
|
14
14
|
usersApi
|
|
15
|
-
} from "./
|
|
15
|
+
} from "./EZG74SQL.jsx";
|
|
16
16
|
import {
|
|
17
17
|
getConfig,
|
|
18
18
|
onConfigured
|
|
@@ -414,4 +414,4 @@ export {
|
|
|
414
414
|
affiliateAuth_default,
|
|
415
415
|
medication_default
|
|
416
416
|
};
|
|
417
|
-
//# sourceMappingURL=
|
|
417
|
+
//# sourceMappingURL=RRKAKQ77.jsx.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
captureAuthHeader,
|
|
3
3
|
peekFunnelSessionId
|
|
4
|
-
} from "./
|
|
4
|
+
} from "./XW4PEQPI.jsx";
|
|
5
5
|
import {
|
|
6
6
|
getConfig
|
|
7
7
|
} from "./LDZIUFDM.jsx";
|
|
@@ -174,4 +174,4 @@ export {
|
|
|
174
174
|
readCartToken,
|
|
175
175
|
stripCartToken
|
|
176
176
|
};
|
|
177
|
-
//# sourceMappingURL=
|
|
177
|
+
//# sourceMappingURL=VF7FTWCG.jsx.map
|
|
@@ -6,13 +6,13 @@ import {
|
|
|
6
6
|
readResumeToken,
|
|
7
7
|
saveFunnelDraft,
|
|
8
8
|
stripResumeToken
|
|
9
|
-
} from "./
|
|
9
|
+
} from "./XW4PEQPI.jsx";
|
|
10
10
|
import {
|
|
11
11
|
affiliateAuth_default,
|
|
12
12
|
auth_default,
|
|
13
13
|
cart_default,
|
|
14
14
|
medication_default
|
|
15
|
-
} from "./
|
|
15
|
+
} from "./RRKAKQ77.jsx";
|
|
16
16
|
import {
|
|
17
17
|
ApiError,
|
|
18
18
|
addressesApi,
|
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
subscriptionsApi,
|
|
32
32
|
supportApi,
|
|
33
33
|
usersApi
|
|
34
|
-
} from "./
|
|
34
|
+
} from "./EZG74SQL.jsx";
|
|
35
35
|
import {
|
|
36
36
|
getConfig
|
|
37
37
|
} from "./LDZIUFDM.jsx";
|
|
@@ -4555,6 +4555,31 @@ async function uploadPrescriptionPhoto(file) {
|
|
|
4555
4555
|
return { photoId: parsed.photoId };
|
|
4556
4556
|
}
|
|
4557
4557
|
|
|
4558
|
+
// src/flows/offers.ts
|
|
4559
|
+
function bestOfferDiscount(offers, cart) {
|
|
4560
|
+
if (!offers || cart.baseCents <= 0) return null;
|
|
4561
|
+
let best = null;
|
|
4562
|
+
for (const offer of offers) {
|
|
4563
|
+
const scoped = offer.productIds ?? [];
|
|
4564
|
+
if (scoped.length > 0 && !scoped.some((id) => cart.productIds.includes(id))) continue;
|
|
4565
|
+
const raw = offer.discountType === "percent" ? Math.round(cart.baseCents * offer.discountValueCents / 100) : offer.discountValueCents;
|
|
4566
|
+
const discountCents = Math.min(cart.baseCents, raw);
|
|
4567
|
+
if (discountCents > 0 && (!best || discountCents > best.discountCents)) best = { offer, discountCents };
|
|
4568
|
+
}
|
|
4569
|
+
return best;
|
|
4570
|
+
}
|
|
4571
|
+
function offerBeatsPromo(offerDiscountCents, promoDiscountCents) {
|
|
4572
|
+
return offerDiscountCents > promoDiscountCents;
|
|
4573
|
+
}
|
|
4574
|
+
function offerDurationText(o) {
|
|
4575
|
+
if (o.recurringIndefinite) return "every month";
|
|
4576
|
+
const further = o.recurringCharges ?? 0;
|
|
4577
|
+
return further > 0 ? `your first ${further + 1} charges` : "your first charge";
|
|
4578
|
+
}
|
|
4579
|
+
function offerSummaryText(o) {
|
|
4580
|
+
return `${o.amountText} off ${offerDurationText(o)}`;
|
|
4581
|
+
}
|
|
4582
|
+
|
|
4558
4583
|
// src/flows/productCatalog.ts
|
|
4559
4584
|
import { createEffect as createEffect9, createMemo as createMemo2, createSignal as createSignal13, on as on3 } from "solid-js";
|
|
4560
4585
|
var messageOf = (err, fallback) => err instanceof Error && err.message ? err.message : fallback;
|
|
@@ -5337,6 +5362,10 @@ export {
|
|
|
5337
5362
|
resolveSurveyV2DrugIntent,
|
|
5338
5363
|
useSurveyV2Flow,
|
|
5339
5364
|
uploadPrescriptionPhoto,
|
|
5365
|
+
bestOfferDiscount,
|
|
5366
|
+
offerBeatsPromo,
|
|
5367
|
+
offerDurationText,
|
|
5368
|
+
offerSummaryText,
|
|
5340
5369
|
classifyCatalogError,
|
|
5341
5370
|
findStoredDosePrice,
|
|
5342
5371
|
buildStrengthRows,
|
|
@@ -5360,4 +5389,4 @@ export {
|
|
|
5360
5389
|
addCatalogItemAsProduct,
|
|
5361
5390
|
createCatalogProduct
|
|
5362
5391
|
};
|
|
5363
|
-
//# sourceMappingURL=
|
|
5392
|
+
//# sourceMappingURL=VG35MW6B.jsx.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getTokens
|
|
3
|
-
} from "./
|
|
3
|
+
} from "./EZG74SQL.jsx";
|
|
4
4
|
import {
|
|
5
5
|
getConfig
|
|
6
6
|
} from "./LDZIUFDM.jsx";
|
|
@@ -154,4 +154,4 @@ export {
|
|
|
154
154
|
readResumeToken,
|
|
155
155
|
stripResumeToken
|
|
156
156
|
};
|
|
157
|
-
//# sourceMappingURL=
|
|
157
|
+
//# sourceMappingURL=XW4PEQPI.jsx.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { peekFunnelSessionId, captureAuthHeader } from './
|
|
1
|
+
import { peekFunnelSessionId, captureAuthHeader } from './M2LV5JQD.js';
|
|
2
2
|
import { getConfig } from './5XGPFYIJ.js';
|
|
3
3
|
|
|
4
4
|
// src/api/promoRef.ts
|
|
@@ -156,5 +156,5 @@ function stripCartToken() {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
export { adoptCartId, capturePromoCode, cartId, clearPromoCode, fetchCartConfig, fetchResumedCart, postCartSnapshot, readCartToken, readPromoCode, resetCartConfigCache, resetCartId, stripCartToken };
|
|
159
|
-
//# sourceMappingURL=
|
|
160
|
-
//# sourceMappingURL=
|
|
159
|
+
//# sourceMappingURL=XZXPLS3K.js.map
|
|
160
|
+
//# sourceMappingURL=XZXPLS3K.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/api/promoRef.ts","../../src/api/cart.ts"],"names":[],"mappings":";;;;AAiBA,IAAM,MAAA,GAAS,EAAA,GAAK,EAAA,GAAK,EAAA,GAAK,EAAA,GAAK,GAAA;AAEnC,IAAM,UAAA,GAAa,MAAM,CAAA,EAAG,SAAA,GAAY,aAAa,CAAA,WAAA,CAAA;AAQ9C,SAAS,iBAAiB,IAAA,EAAoB;AACnD,EAAA,IAAI,OAAO,iBAAiB,WAAA,EAAa;AACzC,EAAA,MAAM,OAAA,GAAU,KAAK,IAAA,EAAK;AAC1B,EAAA,IAAI,CAAC,OAAA,EAAS;AACd,EAAA,IAAI;AACF,IAAA,MAAM,QAAqB,EAAE,IAAA,EAAM,SAAS,EAAA,EAAI,IAAA,CAAK,KAAI,EAAE;AAC3D,IAAA,YAAA,CAAa,QAAQ,UAAA,EAAW,EAAG,IAAA,CAAK,SAAA,CAAU,KAAK,CAAC,CAAA;AAAA,EAC1D,CAAA,CAAA,MAAQ;AAAA,EAER;AACF;AASO,SAAS,aAAA,GAA+B;AAC7C,EAAA,IAAI,OAAO,YAAA,KAAiB,WA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AA,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":"4CTTOSOW.js","sourcesContent":["// ── First-party promo-code capture from a `?promo=` landing ──────────\n//\n// A campaign link can carry its own code (`/?promo=TRUE10`) so the member does\n// not have to type it. Stashed in the storefront's own localStorage and read\n// back when the intake reaches the promo field.\n//\n// Mirrors `affiliateRef` deliberately — same storage shape, same 30-day window —\n// but is a SEPARATE concern: an affiliate ref attributes a sale to a partner and\n// is validated server-side at checkout, while this only pre-fills an input the\n// member still has to submit.\n\nimport { getConfig } from '../config';\n\n// Matches the affiliate-ref window. A stash that outlives the promo it carries\n// is not a correctness problem — the code is re-validated before it is used,\n// and silently dropped if it has expired — but there is no reason to keep one\n// around longer than a campaign plausibly runs.\nconst TTL_MS = 30 * 24 * 60 * 60 * 1000;\n\nconst storageKey = () => `${getConfig().storagePrefix}-promo-code`;\n\ninterface StoredPromo {\n code: string;\n ts: number;\n}\n\n/** Persist a promo code from a `?promo=` landing. No-op for empty input. */\nexport function capturePromoCode(code: string): void {\n if (typeof localStorage === 'undefined') return;\n const trimmed = code.trim();\n if (!trimmed) return;\n try {\n const entry: StoredPromo = { code: trimmed, ts: Date.now() };\n localStorage.setItem(storageKey(), JSON.stringify(entry));\n } catch {\n // storage unavailable (private mode / quota) — non-fatal\n }\n}\n\n/**\n * Read the stored promo code, or null if absent or past the storage window.\n *\n * Being within the window says nothing about whether the CODE is still valid —\n * a campaign can end while the stash is fresh. The caller re-validates against\n * the server before showing it to anyone.\n */\nexport function readPromoCode(): string | null {\n if (typeof localStorage === 'undefined') return null;\n try {\n const raw = localStorage.getItem(storageKey());\n if (!raw) return null;\n const parsed = JSON.parse(raw) as Partial<StoredPromo>;\n if (!parsed.code || typeof parsed.ts !== 'number') return null;\n if (Date.now() - parsed.ts > TTL_MS) {\n localStorage.removeItem(storageKey());\n return null;\n }\n return parsed.code;\n } catch {\n return null;\n }\n}\n\n/** Drop the stored promo code. */\nexport function clearPromoCode(): void {\n if (typeof localStorage === 'undefined') return;\n try {\n localStorage.removeItem(storageKey());\n } catch {\n // non-fatal\n }\n}\n","import { getConfig } from '../config';\nimport { captureAuthHeader, 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 *\n * The bearer token, when there is one, is how a signed-in shopper's cart gets\n * their user id: the endpoint takes identity from the token and never from the\n * body (`optionalAuth`), so omitting it left every logged-in cart anonymous —\n * joinable only by whatever email happened to be attached.\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 ...captureAuthHeader(),\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"]}
|
|
1
|
+
{"version":3,"sources":["../../src/api/promoRef.ts","../../src/api/cart.ts"],"names":[],"mappings":";;;;AAiBA,IAAM,MAAA,GAAS,EAAA,GAAK,EAAA,GAAK,EAAA,GAAK,EAAA,GAAK,GAAA;AAEnC,IAAM,UAAA,GAAa,MAAM,CAAA,EAAG,SAAA,GAAY,aAAa,CAAA,WAAA,CAAA;AAQ9C,SAAS,iBAAiB,IAAA,EAAoB;AACnD,EAAA,IAAI,OAAO,iBAAiB,WAAA,EAAa;AACzC,EAAA,MAAM,OAAA,GAAU,KAAK,IAAA,EAAK;AAC1B,EAAA,IAAI,CAAC,OAAA,EAAS;AACd,EAAA,IAAI;AACF,IAAA,MAAM,QAAqB,EAAE,IAAA,EAAM,SAAS,EAAA,EAAI,IAAA,CAAK,KAAI,EAAE;AAC3D,IAAA,YAAA,CAAa,QAAQ,UAAA,EAAW,EAAG,IAAA,CAAK,SAAA,CAAU,KAAK,CAAC,CAAA;AAAA,EAC1D,CAAA,CAAA,MAAQ;AAAA,EAER;AACF;AASO,SAAS,aAAA,GAA+B;AAC7C,EAAA,IAAI,OAAO,YAAA,KAAiB,WAAA,EAAa,OAAO,IAAA;AAChD,EAAA,IAAI;AACF,IAAA,MAAM,GAAA,GAAM,YAAA,CAAa,OAAA,CAAQ,UAAA,EAAY,CAAA;AAC7C,IAAA,IAAI,CAAC,KAAK,OAAO,IAAA;AACjB,IAAA,MAAM,MAAA,GAAS,IAAA,CAA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Content":["// ── First-party promo-code capture from a `?promo=` landing ──────────\n//\n// A campaign link can carry its own code (`/?promo=TRUE10`) so the member does\n// not have to type it. Stashed in the storefront's own localStorage and read\n// back when the intake reaches the promo field.\n//\n// Mirrors `affiliateRef` deliberately — same storage shape, same 30-day window —\n// but is a SEPARATE concern: an affiliate ref attributes a sale to a partner and\n// is validated server-side at checkout, while this only pre-fills an input the\n// member still has to submit.\n\nimport { getConfig } from '../config';\n\n// Matches the affiliate-ref window. A stash that outlives the promo it carries\n// is not a correctness problem — the code is re-validated before it is used,\n// and silently dropped if it has expired — but there is no reason to keep one\n// around longer than a campaign plausibly runs.\nconst TTL_MS = 30 * 24 * 60 * 60 * 1000;\n\nconst storageKey = () => `${getConfig().storagePrefix}-promo-code`;\n\ninterface StoredPromo {\n code: string;\n ts: number;\n}\n\n/** Persist a promo code from a `?promo=` landing. No-op for empty input. */\nexport function capturePromoCode(code: string): void {\n if (typeof localStorage === 'undefined') return;\n const trimmed = code.trim();\n if (!trimmed) return;\n try {\n const entry: StoredPromo = { code: trimmed, ts: Date.now() };\n localStorage.setItem(storageKey(), JSON.stringify(entry));\n } catch {\n // storage unavailable (private mode / quota) — non-fatal\n }\n}\n\n/**\n * Read the stored promo code, or null if absent or past the storage window.\n *\n * Being within the window says nothing about whether the CODE is still valid —\n * a campaign can end while the stash is fresh. The caller re-validates against\n * the server before showing it to anyone.\n */\nexport function readPromoCode(): string | null {\n if (typeof localStorage === 'undefined') return null;\n try {\n const raw = localStorage.getItem(storageKey());\n if (!raw) return null;\n const parsed = JSON.parse(raw) as Partial<StoredPromo>;\n if (!parsed.code || typeof parsed.ts !== 'number') return null;\n if (Date.now() - parsed.ts > TTL_MS) {\n localStorage.removeItem(storageKey());\n return null;\n }\n return parsed.code;\n } catch {\n return null;\n }\n}\n\n/** Drop the stored promo code. */\nexport function clearPromoCode(): void {\n if (typeof localStorage === 'undefined') return;\n try {\n localStorage.removeItem(storageKey());\n } catch {\n // non-fatal\n }\n}\n","import { getConfig } from '../config';\nimport { captureAuthHeader, 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 *\n * The bearer token, when there is one, is how a signed-in shopper's cart gets\n * their user id: the endpoint takes identity from the token and never from the\n * body (`optionalAuth`), so omitting it left every logged-in cart anonymous —\n * joinable only by whatever email happened to be attached.\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 ...captureAuthHeader(),\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"]}
|
|
@@ -390,6 +390,13 @@ interface SubscriptionPreview {
|
|
|
390
390
|
discountCents: number;
|
|
391
391
|
totalCents: number;
|
|
392
392
|
promoApplied: boolean;
|
|
393
|
+
/** The buyer's own offer, when it is what priced this cart (an offer and a
|
|
394
|
+
* promo code compete for one slot). Absent on backends that predate offers. */
|
|
395
|
+
offerApplied?: {
|
|
396
|
+
label: string;
|
|
397
|
+
amountText: string;
|
|
398
|
+
recurringIndefinite: boolean;
|
|
399
|
+
} | null;
|
|
393
400
|
savingsApplied: boolean;
|
|
394
401
|
/** The member already holds this subscription, so the charge would return
|
|
395
402
|
* it unchanged and charge nothing (lines empty, totals 0). Absent on
|
|
@@ -959,6 +966,44 @@ declare const promoCodesApi: {
|
|
|
959
966
|
subtotalCents?: number;
|
|
960
967
|
}): Promise<PromoValidationResponse>;
|
|
961
968
|
};
|
|
969
|
+
/**
|
|
970
|
+
* An offer the signed-in member holds and has not claimed yet: a discount that
|
|
971
|
+
* is theirs if they subscribe by its deadline. Display only — checkout looks
|
|
972
|
+
* the buyer's offers up server-side and never takes one from the client.
|
|
973
|
+
*/
|
|
974
|
+
interface MemberOffer {
|
|
975
|
+
id: string;
|
|
976
|
+
label: string;
|
|
977
|
+
discountType: 'percent' | 'fixed';
|
|
978
|
+
/** percent: 1–100. fixed: cents. */
|
|
979
|
+
discountValueCents: number;
|
|
980
|
+
/** "$10" / "15%". */
|
|
981
|
+
amountText: string;
|
|
982
|
+
recurringIndefinite: boolean;
|
|
983
|
+
/** Rebills after the first charge that carry the discount; ignored when indefinite. */
|
|
984
|
+
recurringCharges: number;
|
|
985
|
+
/** Empty = any product. */
|
|
986
|
+
productIds: string[];
|
|
987
|
+
expiresAt: string;
|
|
988
|
+
/** The last full day to claim it, as the member was told ("November 11, 2026").
|
|
989
|
+
* Print this; do not format `expiresAt`, which is hours into the next day. */
|
|
990
|
+
deadlineText: string;
|
|
991
|
+
}
|
|
992
|
+
declare const offersApi: {
|
|
993
|
+
/** The signed-in member's unclaimed offers (member JWT). */
|
|
994
|
+
mine(): Promise<{
|
|
995
|
+
offers: MemberOffer[];
|
|
996
|
+
}>;
|
|
997
|
+
/**
|
|
998
|
+
* The offers waiting for someone with no account yet, by the address they
|
|
999
|
+
* are registering with — so a guest is shown the price they will be charged.
|
|
1000
|
+
* Empty for an address that already has an account. POST: the address never
|
|
1001
|
+
* goes in a URL.
|
|
1002
|
+
*/
|
|
1003
|
+
forEmail(email: string): Promise<{
|
|
1004
|
+
offers: MemberOffer[];
|
|
1005
|
+
}>;
|
|
1006
|
+
};
|
|
962
1007
|
declare const ordersApi: {
|
|
963
1008
|
create(payload: CreateOrderPayload): Promise<{
|
|
964
1009
|
order: Order;
|
|
@@ -1858,6 +1903,41 @@ declare const adminApi: {
|
|
|
1858
1903
|
promoCode: AdminPromoCode;
|
|
1859
1904
|
}>;
|
|
1860
1905
|
deletePromoCode(id: string): Promise<unknown>;
|
|
1906
|
+
getOffers(): Promise<{
|
|
1907
|
+
offers: AdminOffer[];
|
|
1908
|
+
}>;
|
|
1909
|
+
createOffer(payload: AdminOfferInput): Promise<{
|
|
1910
|
+
offer: AdminOfferBase;
|
|
1911
|
+
}>;
|
|
1912
|
+
/** Whole object. Grants already issued keep the terms they were issued with. */
|
|
1913
|
+
updateOffer(id: string, payload: AdminOfferInput): Promise<{
|
|
1914
|
+
offer: AdminOfferBase;
|
|
1915
|
+
}>;
|
|
1916
|
+
/** Archive. 409 (the message names the sequence) while a sequence hands it out. */
|
|
1917
|
+
archiveOffer(id: string): Promise<unknown>;
|
|
1918
|
+
getOfferGrants(offerId: string, params?: {
|
|
1919
|
+
limit?: number;
|
|
1920
|
+
offset?: number;
|
|
1921
|
+
}): Promise<{
|
|
1922
|
+
grants: AdminOfferGrant[];
|
|
1923
|
+
}>;
|
|
1924
|
+
/**
|
|
1925
|
+
* Give the offer to one person. Idempotent: a person holds an offer once, so
|
|
1926
|
+
* `created: false` returns the grant they already have, original deadline
|
|
1927
|
+
* included.
|
|
1928
|
+
*/
|
|
1929
|
+
issueOfferGrant(offerId: string, payload: {
|
|
1930
|
+
email: string;
|
|
1931
|
+
userId?: string;
|
|
1932
|
+
validDays: number;
|
|
1933
|
+
}): Promise<{
|
|
1934
|
+
grant: AdminOfferGrantBase;
|
|
1935
|
+
created: boolean;
|
|
1936
|
+
}>;
|
|
1937
|
+
/** Take back an unclaimed grant. 409 once it has been claimed. */
|
|
1938
|
+
revokeOfferGrant(grantId: string): Promise<{
|
|
1939
|
+
grant: AdminOfferGrantBase;
|
|
1940
|
+
}>;
|
|
1861
1941
|
getCategories(): Promise<{
|
|
1862
1942
|
categories: AdminCategory[];
|
|
1863
1943
|
}>;
|
|
@@ -2005,6 +2085,68 @@ interface AdminPromoCodeInput {
|
|
|
2005
2085
|
recurringIndefinite?: boolean;
|
|
2006
2086
|
affiliateId?: string | null;
|
|
2007
2087
|
}
|
|
2088
|
+
/** An offer as create/update return it; the list adds counts (`AdminOffer`). */
|
|
2089
|
+
interface AdminOfferBase {
|
|
2090
|
+
id: string;
|
|
2091
|
+
tenantId: string;
|
|
2092
|
+
name: string;
|
|
2093
|
+
discountType: DiscountType;
|
|
2094
|
+
/** percent: 1–100. fixed: cents. */
|
|
2095
|
+
discountValueCents: number;
|
|
2096
|
+
/** Rebills after the first charge that carry the discount; ignored when indefinite. */
|
|
2097
|
+
recurringCharges: number;
|
|
2098
|
+
recurringIndefinite: boolean;
|
|
2099
|
+
/** Empty = any product. */
|
|
2100
|
+
productIds: string[];
|
|
2101
|
+
isActive: boolean;
|
|
2102
|
+
createdAt: string;
|
|
2103
|
+
updatedAt: string;
|
|
2104
|
+
archivedAt?: string | null;
|
|
2105
|
+
}
|
|
2106
|
+
type OfferGrantState = 'open' | 'claimed' | 'expired' | 'revoked';
|
|
2107
|
+
interface AdminOffer extends AdminOfferBase {
|
|
2108
|
+
grants: Record<OfferGrantState, number>;
|
|
2109
|
+
/** Sequences that hand this offer out. */
|
|
2110
|
+
usedBy: Array<{
|
|
2111
|
+
sequenceId: string;
|
|
2112
|
+
sequenceName: string;
|
|
2113
|
+
}>;
|
|
2114
|
+
}
|
|
2115
|
+
interface AdminOfferInput {
|
|
2116
|
+
name: string;
|
|
2117
|
+
discountType: DiscountType;
|
|
2118
|
+
discountValueCents: number;
|
|
2119
|
+
recurringIndefinite: boolean;
|
|
2120
|
+
recurringCharges: number;
|
|
2121
|
+
productIds: string[];
|
|
2122
|
+
isActive: boolean;
|
|
2123
|
+
}
|
|
2124
|
+
/** One person holding one offer. The terms are a copy, frozen when it was issued. */
|
|
2125
|
+
interface AdminOfferGrantBase {
|
|
2126
|
+
id: string;
|
|
2127
|
+
offerId: string;
|
|
2128
|
+
email: string;
|
|
2129
|
+
userId: string | null;
|
|
2130
|
+
/** The offer's name when the grant was issued. */
|
|
2131
|
+
label: string;
|
|
2132
|
+
discountType: DiscountType;
|
|
2133
|
+
discountValueCents: number;
|
|
2134
|
+
recurringCharges: number;
|
|
2135
|
+
recurringIndefinite: boolean;
|
|
2136
|
+
productIds: string[];
|
|
2137
|
+
issuedAt: string;
|
|
2138
|
+
/** `admin:<uid>` or `sequence:<id>`. */
|
|
2139
|
+
issuedBy: string;
|
|
2140
|
+
sequenceId: string | null;
|
|
2141
|
+
/** The deadline to claim it, not the end of the discount. */
|
|
2142
|
+
expiresAt: string;
|
|
2143
|
+
redeemedAt: string | null;
|
|
2144
|
+
revokedAt: string | null;
|
|
2145
|
+
}
|
|
2146
|
+
/** A grant as the list returns it; issue and revoke return it without `state`. */
|
|
2147
|
+
interface AdminOfferGrant extends AdminOfferGrantBase {
|
|
2148
|
+
state: OfferGrantState;
|
|
2149
|
+
}
|
|
2008
2150
|
type AffiliateStatus = 'pending' | 'active' | 'suspended' | 'rejected';
|
|
2009
2151
|
type CommissionStatus = 'pending' | 'approved' | 'paid' | 'cancelled';
|
|
2010
2152
|
type AttributionMethod = 'link' | 'promo_code' | 'both';
|
|
@@ -2312,4 +2454,4 @@ declare const affiliatePortalApi: {
|
|
|
2312
2454
|
track(refCode: string, landingPage?: string): Promise<AffiliateTrackResponse>;
|
|
2313
2455
|
};
|
|
2314
2456
|
|
|
2315
|
-
export { type
|
|
2457
|
+
export { type AffiliateDashboardStats as $, type AddressVerifyResult as A, type AdminOrphanReason as B, type AdminOrphanedDosePrice as C, type AdminPayment as D, type AdminPaymentDetail as E, type AdminProduct as F, type AdminProductOverlayField as G, type AdminProductStrength as H, type AdminPromoCode as I, type AdminPromoCodeInput as J, type AdminRefundResult as K, type AdminSale as L, type AdminSaleInput as M, type AdminSubscription as N, type AdminSubscriptionDetail as O, type AdminSubscriptionPatch as P, type AdminSubscriptionWriteResult as Q, type AdminSupportCustomer as R, type AdminSupportStats as S, type AdminSupportThread as T, type AdminWebhookEvent as U, type Affiliate as V, type AffiliateAuthTokens as W, type AffiliateClickRecord as X, type AffiliateConversion as Y, type AffiliateDashboardLinks as Z, type AffiliateDashboardProfile as _, type AdminApexDrug as a, type OrderItemInput as a$, type AffiliateDownlineMember as a0, type AffiliateEarningsBreakdown as a1, type AffiliatePaymentMethod as a2, type AffiliateProgram as a3, type AffiliateRegisterInput as a4, type AffiliateRegisterResponse as a5, type AffiliateSession as a6, type AffiliateStatsResponse as a7, type AffiliateStatus as a8, type AffiliateTrackResponse as a9, type CheckoutResult as aA, type CommissionConfig as aB, type CommissionStatus as aC, type CompleteSurveyPayload as aD, type CreateAffiliatePayload as aE, type CreateAffiliateProgramPayload as aF, type CreateOrderPayload as aG, type CreateRequestPayload as aH, type CreateSubscriptionPayload as aI, type CustomTemplate as aJ, type CustomTemplateInput as aK, type CustomerDiscountConfig as aL, type DeliveryInfo as aM, type DiscountType as aN, type EmailNotificationSettings as aO, type EmailTemplatesMap as aP, type LoginPayload as aQ, type MemberOffer as aR, type MemberPrescriptionRequest as aS, type MemberSurveyMode as aT, type MemberSurveyResponseSummary as aU, type MemberSurveyTranscript as aV, type MemberSurveyTranscriptItem as aW, type MemberSurveyTranscriptSection as aX, type MembersMeResponse as aY, type OfferGrantState as aZ, type Order as a_, ApiError as aa, type ApiResponse as ab, type AttributionMethod as ac, type AuthTokens as ad, type BillingReminderSettings as ae, type CatalogAvailabilityItem as af, type CatalogAvailabilityReason as ag, type CatalogAvailabilityResult as ah, type CatalogClassification as ai, type CatalogDose as aj, type CatalogDoseInput as ak, type CatalogDoseModel as al, type CatalogDoseSuggestion as am, type CatalogDoseSuggestions as an, type CatalogEquivalentSuggestions as ao, type CatalogFulfillment as ap, type CatalogFulfillmentInput as aq, type CatalogItem as ar, type CatalogItemInput as as, type CatalogMappableDrug as at, type CatalogMatrixCell as au, type CatalogProduct as av, type CatalogReadiness as aw, type CategoryMetadata as ax, type CheckoutAddress as ay, type CheckoutPayload as az, type AdminApexItemStatus as b, setTokens as b$, type PaginationParams as b0, type PaymentCallbackPayload as b1, type PaymentInitiatePayload as b2, type PaymentType as b3, type PendingRenewalSurvey as b4, type Placeholder as b5, type PlaceholderKind as b6, type ProductSaleSummary as b7, type PromoValidationResponse as b8, type PublicCategory as b9, type UpdateProfilePayload as bA, type User as bB, addressesApi as bC, adminAffiliatesApi as bD, adminApi as bE, adminCatalogApi as bF, affiliateAuthStorageKey as bG, affiliatePortalApi as bH, apexApi as bI, apiFetch as bJ, authApi as bK, authStorageKey as bL, catalogApi as bM, clearAffiliateTokens as bN, clearTokens as bO, getAffiliateTokens as bP, getTokens as bQ, membersApi as bR, messagesApi as bS, newIdempotencyKey as bT, offersApi as bU, onTokensCleared as bV, ordersApi as bW, paymentsApi as bX, productsApi as bY, promoCodesApi as bZ, setAffiliateTokens as b_, type RegisterAndSubscribePayload as ba, type RegisterPayload as bb, type RenewalStatus as bc, SUPPORT_ATTACHMENT_MAX_BYTES as bd, SUPPORT_ATTACHMENT_MIME_TYPES as be, type SelectDrugPayload as bf, type SendMessagePayload as bg, type SendToPharmacyPayload as bh, type SubscriptionPreview as bi, type SubscriptionPreviewLine as bj, type SubscriptionPreviewPayload as bk, type SupportAttachment as bl, type SupportMessage as bm, type SupportRealtimeToken as bn, type SupportThread as bo, type SupportThreadCategory as bp, type SupportThreadStatus as bq, type SurveySubmitPayload as br, type TemplatePlaceholdersMap as bs, type TemplateText as bt, type TenantFeature as bu, type TenantFeatureAccess as bv, type TokenTrackName as bw, type UpdateAffiliatePayload as bx, type UpdateAffiliateProgramPayload as by, type UpdatePaymentMethodPayload as bz, type AdminBillingAttempt as c, subscriptionsApi as c0, supportApi as c1, usersApi as c2, type AdminCategory as d, type AdminCategoryInput as e, type AdminCategoryUpdate as f, type AdminCustomer as g, type AdminCustomerFacts as h, type AdminCustomerFunnel as i, type AdminCustomerListParams as j, type AdminCustomerOverview as k, type AdminCustomerProfile as l, type AdminCustomerRequest as m, type AdminCustomerRow as n, type AdminCustomerSupport as o, type AdminCustomerSupportThread as p, type AdminDashboardStats as q, type AdminLifecycle as r, type AdminLifecycleBucket as s, type AdminListParams as t, type AdminOffer as u, type AdminOfferBase as v, type AdminOfferGrant as w, type AdminOfferGrantBase as x, type AdminOfferInput as y, type AdminOrderSummary as z };
|