@apextelemed/partner-core 0.3.1 → 0.4.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/README.md +47 -0
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api/index.jsx +1 -1
- package/dist/chunk/{UNAI6NBV.js → 2XJBOTK5.js} +50 -7
- package/dist/chunk/2XJBOTK5.js.map +1 -0
- package/dist/chunk/{D6GCJFQD.js → EIXZJX6R.js} +5 -5
- package/dist/chunk/{D6GCJFQD.js.map → EIXZJX6R.js.map} +1 -1
- package/dist/chunk/{AC7FFU4J.jsx → HM27UGZM.jsx} +2738 -1481
- package/dist/chunk/{J4G52ET6.js → ID67FV6R.js} +4284 -1806
- package/dist/chunk/ID67FV6R.js.map +1 -0
- package/dist/chunk/{DUVW24DM.jsx → MEF3FUQB.jsx} +49 -6
- package/dist/chunk/{M6DZVPYZ.jsx → NYLIUR7O.jsx} +688 -36
- package/dist/chunk/{5RQ4ZIYB.js → OJSQZEB3.js} +678 -38
- package/dist/chunk/OJSQZEB3.js.map +1 -0
- package/dist/chunk/{KMHMT6YP.jsx → STEVQZ6U.jsx} +19 -15
- package/dist/chunk/{2EVGOW2Z.jsx → T6IKS76T.jsx} +4 -4
- package/dist/chunk/{FWUBNK42.js → YHWX4NMV.js} +19 -15
- package/dist/chunk/YHWX4NMV.js.map +1 -0
- package/dist/{client-CWYoMmla.d.ts → client-DUrhrzOG.d.ts} +318 -9
- package/dist/flows/index.d.ts +99 -2
- package/dist/flows/index.js +4 -4
- package/dist/flows/index.jsx +24 -4
- package/dist/index/index.d.ts +2 -2
- package/dist/index/index.js +5 -5
- package/dist/index/index.jsx +25 -5
- package/dist/pages/index.d.ts +35 -2
- package/dist/pages/index.js +4 -4
- package/dist/pages/index.jsx +4 -4
- package/dist/stores/index.d.ts +1 -1
- package/dist/stores/index.js +2 -2
- package/dist/stores/index.jsx +2 -2
- package/dist/theme/admin.css +434 -0
- package/package.json +1 -1
- package/dist/chunk/5RQ4ZIYB.js.map +0 -1
- package/dist/chunk/FWUBNK42.js.map +0 -1
- package/dist/chunk/J4G52ET6.js.map +0 -1
- package/dist/chunk/UNAI6NBV.js.map +0 -1
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
auth_default,
|
|
13
13
|
cart_default,
|
|
14
14
|
medication_default
|
|
15
|
-
} from "./
|
|
15
|
+
} from "./STEVQZ6U.jsx";
|
|
16
16
|
import {
|
|
17
17
|
ApiError,
|
|
18
18
|
addressesApi,
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
subscriptionsApi,
|
|
28
28
|
supportApi,
|
|
29
29
|
usersApi
|
|
30
|
-
} from "./
|
|
30
|
+
} from "./MEF3FUQB.jsx";
|
|
31
31
|
import {
|
|
32
32
|
getConfig
|
|
33
33
|
} from "./LDZIUFDM.jsx";
|
|
@@ -69,8 +69,8 @@ function flattenSurveyToSteps(data) {
|
|
|
69
69
|
const sortedSections = [...data.sections || []].sort((a, b) => a.order - b.order);
|
|
70
70
|
sortedSections.forEach((section, sectionIndex) => {
|
|
71
71
|
const sortedSteps = [...section.steps || []].sort((a, b) => a.order - b.order);
|
|
72
|
-
sortedSteps.forEach((
|
|
73
|
-
const sortedQuestions = [...
|
|
72
|
+
sortedSteps.forEach((step2, stepIndex) => {
|
|
73
|
+
const sortedQuestions = [...step2.questions || []].sort((a, b) => a.order - b.order);
|
|
74
74
|
const questions = sortedQuestions.map((q) => ({
|
|
75
75
|
id: q.questionId,
|
|
76
76
|
type: q.type,
|
|
@@ -89,8 +89,8 @@ function flattenSurveyToSteps(data) {
|
|
|
89
89
|
sectionIndex,
|
|
90
90
|
stepIndex,
|
|
91
91
|
sectionTitle: section.title,
|
|
92
|
-
stepTitle:
|
|
93
|
-
stepDescription:
|
|
92
|
+
stepTitle: step2.title,
|
|
93
|
+
stepDescription: step2.description,
|
|
94
94
|
questions
|
|
95
95
|
});
|
|
96
96
|
}
|
|
@@ -145,9 +145,9 @@ function useSurveyFlow(options = {}) {
|
|
|
145
145
|
const [hydrated, setHydrated] = createSignal(false);
|
|
146
146
|
const totalSteps = () => steps().length;
|
|
147
147
|
const isLastStep = () => currentStep() >= totalSteps() - 1;
|
|
148
|
-
const
|
|
148
|
+
const step2 = () => steps()[currentStep()] ?? null;
|
|
149
149
|
const visibleQuestions = () => {
|
|
150
|
-
const s =
|
|
150
|
+
const s = step2();
|
|
151
151
|
if (!s) return [];
|
|
152
152
|
return s.questions.filter((q) => isQuestionVisible(q, answers()));
|
|
153
153
|
};
|
|
@@ -486,7 +486,7 @@ function useSurveyFlow(options = {}) {
|
|
|
486
486
|
surveyTitle,
|
|
487
487
|
totalSteps,
|
|
488
488
|
currentStep,
|
|
489
|
-
step,
|
|
489
|
+
step: step2,
|
|
490
490
|
visibleQuestions,
|
|
491
491
|
answers,
|
|
492
492
|
setAnswer,
|
|
@@ -606,10 +606,10 @@ var ZIP_RE = /^\d{5}(-\d{4})?$/;
|
|
|
606
606
|
var EMPTY = { street: "", street2: "", city: "", state: "", zip: "" };
|
|
607
607
|
var VERIFY_TIMEOUT_MS = 3500;
|
|
608
608
|
var UNCHECKED_RESULT = { status: "unchecked", corrected: false, messages: [] };
|
|
609
|
-
function withTimeout(p,
|
|
609
|
+
function withTimeout(p, ms2, fallback) {
|
|
610
610
|
let timer;
|
|
611
611
|
const timeout = new Promise((resolve) => {
|
|
612
|
-
timer = setTimeout(() => resolve(fallback),
|
|
612
|
+
timer = setTimeout(() => resolve(fallback), ms2);
|
|
613
613
|
});
|
|
614
614
|
return Promise.race([p, timeout]).finally(() => clearTimeout(timer));
|
|
615
615
|
}
|
|
@@ -919,8 +919,8 @@ function useCheckoutFlow(options = {}) {
|
|
|
919
919
|
const baseMedicationCents = (() => {
|
|
920
920
|
const cents = rx?.priceCents;
|
|
921
921
|
if (typeof cents === "number") return cents;
|
|
922
|
-
const
|
|
923
|
-
return typeof
|
|
922
|
+
const dollars2 = rx?.price;
|
|
923
|
+
return typeof dollars2 === "number" ? Math.round(dollars2 * 100) : 0;
|
|
924
924
|
})();
|
|
925
925
|
const promoDiscountCents = (() => {
|
|
926
926
|
const locked = rx?.discountCents;
|
|
@@ -1404,7 +1404,7 @@ function useSignupFlow(options) {
|
|
|
1404
1404
|
const accept = useCardTokenizer();
|
|
1405
1405
|
let restored = {};
|
|
1406
1406
|
if (typeof window !== "undefined") restored = loadDraft();
|
|
1407
|
-
const [
|
|
1407
|
+
const [step2, setStep] = createSignal6(Math.min(restored.step ?? 0, MAX_RESTORABLE_STEP));
|
|
1408
1408
|
const [error, setError] = createSignal6(null);
|
|
1409
1409
|
const [tokenizing, setTokenizing] = createSignal6(false);
|
|
1410
1410
|
const [submitting, setSubmitting] = createSignal6(false);
|
|
@@ -1428,7 +1428,7 @@ function useSignupFlow(options) {
|
|
|
1428
1428
|
onMount5(() => {
|
|
1429
1429
|
createEffect4(() => {
|
|
1430
1430
|
saveDraft({
|
|
1431
|
-
step:
|
|
1431
|
+
step: step2(),
|
|
1432
1432
|
firstName: firstName(),
|
|
1433
1433
|
lastName: lastName(),
|
|
1434
1434
|
dateOfBirth: dateOfBirth(),
|
|
@@ -1480,7 +1480,7 @@ function useSignupFlow(options) {
|
|
|
1480
1480
|
}
|
|
1481
1481
|
}
|
|
1482
1482
|
async function advance() {
|
|
1483
|
-
const startStep =
|
|
1483
|
+
const startStep = step2();
|
|
1484
1484
|
const err = validateStep(startStep);
|
|
1485
1485
|
if (err) {
|
|
1486
1486
|
setError(err);
|
|
@@ -1519,7 +1519,7 @@ function useSignupFlow(options) {
|
|
|
1519
1519
|
}
|
|
1520
1520
|
function back() {
|
|
1521
1521
|
setError(null);
|
|
1522
|
-
if (
|
|
1522
|
+
if (step2() === 3) setTokenizedData(null);
|
|
1523
1523
|
setStep((s) => Math.max(0, s - 1));
|
|
1524
1524
|
}
|
|
1525
1525
|
function finishIfAuthenticated() {
|
|
@@ -1607,8 +1607,8 @@ function useSignupFlow(options) {
|
|
|
1607
1607
|
return finishIfAuthenticated();
|
|
1608
1608
|
}
|
|
1609
1609
|
return {
|
|
1610
|
-
step,
|
|
1611
|
-
isConfirmStep: () =>
|
|
1610
|
+
step: step2,
|
|
1611
|
+
isConfirmStep: () => step2() === 3,
|
|
1612
1612
|
next,
|
|
1613
1613
|
back,
|
|
1614
1614
|
error,
|
|
@@ -1687,7 +1687,7 @@ function clearDraft2() {
|
|
|
1687
1687
|
function useRegisterFlow() {
|
|
1688
1688
|
let restored = {};
|
|
1689
1689
|
if (typeof window !== "undefined") restored = loadDraft2();
|
|
1690
|
-
const [
|
|
1690
|
+
const [step2, setStep] = createSignal7(Math.min(restored.step ?? 0, MAX_RESTORABLE_STEP2));
|
|
1691
1691
|
const [error, setError] = createSignal7(null);
|
|
1692
1692
|
const [submitting, setSubmitting] = createSignal7(false);
|
|
1693
1693
|
const [outcome, setOutcome] = createSignal7({ kind: "in_progress" });
|
|
@@ -1708,7 +1708,7 @@ function useRegisterFlow() {
|
|
|
1708
1708
|
}
|
|
1709
1709
|
createEffect5(() => {
|
|
1710
1710
|
saveDraft2({
|
|
1711
|
-
step:
|
|
1711
|
+
step: step2(),
|
|
1712
1712
|
firstName: firstName(),
|
|
1713
1713
|
lastName: lastName(),
|
|
1714
1714
|
dateOfBirth: dateOfBirth(),
|
|
@@ -1756,7 +1756,7 @@ function useRegisterFlow() {
|
|
|
1756
1756
|
}
|
|
1757
1757
|
}
|
|
1758
1758
|
async function advance() {
|
|
1759
|
-
const startStep =
|
|
1759
|
+
const startStep = step2();
|
|
1760
1760
|
if (startStep >= 2) return;
|
|
1761
1761
|
const err = validateStep(startStep);
|
|
1762
1762
|
if (err) {
|
|
@@ -1845,8 +1845,8 @@ function useRegisterFlow() {
|
|
|
1845
1845
|
return finishIfAuthenticated();
|
|
1846
1846
|
}
|
|
1847
1847
|
return {
|
|
1848
|
-
step,
|
|
1849
|
-
isConfirmStep: () =>
|
|
1848
|
+
step: step2,
|
|
1849
|
+
isConfirmStep: () => step2() === 2,
|
|
1850
1850
|
next,
|
|
1851
1851
|
back,
|
|
1852
1852
|
error,
|
|
@@ -2333,8 +2333,8 @@ function buildTrackerView(rx) {
|
|
|
2333
2333
|
return { stages: stages2, activeIndex: 2, shipment: null, branch: "denied" };
|
|
2334
2334
|
}
|
|
2335
2335
|
const activeIndex = resolveActiveIndex(rx);
|
|
2336
|
-
const stages = PIPELINE.map((
|
|
2337
|
-
const base = { key:
|
|
2336
|
+
const stages = PIPELINE.map((step2, i) => {
|
|
2337
|
+
const base = { key: step2.key, label: step2.label };
|
|
2338
2338
|
if (i < activeIndex) {
|
|
2339
2339
|
return {
|
|
2340
2340
|
...base,
|
|
@@ -2345,8 +2345,8 @@ function buildTrackerView(rx) {
|
|
|
2345
2345
|
if (i === activeIndex) {
|
|
2346
2346
|
return {
|
|
2347
2347
|
...base,
|
|
2348
|
-
heroWord:
|
|
2349
|
-
subCaption:
|
|
2348
|
+
heroWord: step2.heroWord,
|
|
2349
|
+
subCaption: step2.subCaption,
|
|
2350
2350
|
state: "active",
|
|
2351
2351
|
timestamp: i === PIPE.submitted ? rx.createdAt : rx.updatedAt
|
|
2352
2352
|
};
|
|
@@ -2412,6 +2412,646 @@ function formatEventDate(date) {
|
|
|
2412
2412
|
return date.toLocaleDateString("en-US", { month: "short", day: "numeric" });
|
|
2413
2413
|
}
|
|
2414
2414
|
|
|
2415
|
+
// src/flows/customer360.ts
|
|
2416
|
+
var LIFECYCLE_LABEL = {
|
|
2417
|
+
active: "Active",
|
|
2418
|
+
past_due: "Past due",
|
|
2419
|
+
paused: "Paused",
|
|
2420
|
+
incomplete: "Incomplete signup",
|
|
2421
|
+
cancelled: "Cancelled",
|
|
2422
|
+
card_declined: "Card declined",
|
|
2423
|
+
awaiting_prescriber: "Awaiting prescriber",
|
|
2424
|
+
never_subscribed: "Never subscribed"
|
|
2425
|
+
};
|
|
2426
|
+
var LIFECYCLE_TONE = {
|
|
2427
|
+
active: "success",
|
|
2428
|
+
past_due: "warning",
|
|
2429
|
+
paused: "neutral",
|
|
2430
|
+
incomplete: "warning",
|
|
2431
|
+
cancelled: "neutral",
|
|
2432
|
+
card_declined: "danger",
|
|
2433
|
+
awaiting_prescriber: "info",
|
|
2434
|
+
never_subscribed: "neutral"
|
|
2435
|
+
};
|
|
2436
|
+
var LIFECYCLE_BUCKETS = [
|
|
2437
|
+
"never_subscribed",
|
|
2438
|
+
"card_declined",
|
|
2439
|
+
"awaiting_prescriber",
|
|
2440
|
+
"incomplete",
|
|
2441
|
+
"active",
|
|
2442
|
+
"past_due",
|
|
2443
|
+
"paused",
|
|
2444
|
+
"cancelled"
|
|
2445
|
+
];
|
|
2446
|
+
var ACCOUNT_SOURCE_LABEL = {
|
|
2447
|
+
savings: "Savings program registration",
|
|
2448
|
+
register_and_subscribe: "Signed up and subscribed in one step",
|
|
2449
|
+
register: "Created an account first",
|
|
2450
|
+
unknown: "Unknown"
|
|
2451
|
+
};
|
|
2452
|
+
var DAY_MS2 = 864e5;
|
|
2453
|
+
var LIVE = /* @__PURE__ */ new Set(["active", "paused", "past_due"]);
|
|
2454
|
+
function ms(iso) {
|
|
2455
|
+
if (!iso) return null;
|
|
2456
|
+
const t = Date.parse(iso);
|
|
2457
|
+
return Number.isNaN(t) ? null : t;
|
|
2458
|
+
}
|
|
2459
|
+
function fmtDay(iso) {
|
|
2460
|
+
const t = ms(iso);
|
|
2461
|
+
if (t === null) return "an unknown date";
|
|
2462
|
+
return new Date(t).toLocaleDateString("en-US", {
|
|
2463
|
+
month: "short",
|
|
2464
|
+
day: "numeric",
|
|
2465
|
+
year: "numeric",
|
|
2466
|
+
timeZone: "UTC"
|
|
2467
|
+
});
|
|
2468
|
+
}
|
|
2469
|
+
function sentence(text) {
|
|
2470
|
+
const t = text.trim();
|
|
2471
|
+
return /[.!?]$/.test(t) ? t : `${t}.`;
|
|
2472
|
+
}
|
|
2473
|
+
function dollars(cents) {
|
|
2474
|
+
if (cents == null) return "$0.00";
|
|
2475
|
+
return `$${(cents / 100).toFixed(2)}`;
|
|
2476
|
+
}
|
|
2477
|
+
function newestFirst(items, at2) {
|
|
2478
|
+
return [...items].sort((a, b) => (ms(at2(b)) ?? 0) - (ms(at2(a)) ?? 0));
|
|
2479
|
+
}
|
|
2480
|
+
function latestSubscription(subs) {
|
|
2481
|
+
return newestFirst(subs, (s) => s.createdAt)[0] ?? null;
|
|
2482
|
+
}
|
|
2483
|
+
function primarySubscription(subs) {
|
|
2484
|
+
const live = newestFirst(
|
|
2485
|
+
subs.filter((s) => LIVE.has(s.status)),
|
|
2486
|
+
(s) => s.createdAt
|
|
2487
|
+
);
|
|
2488
|
+
return live[0] ?? latestSubscription(subs);
|
|
2489
|
+
}
|
|
2490
|
+
function latestRequest(reqs) {
|
|
2491
|
+
return newestFirst(reqs, (r) => r.createdAt)[0] ?? null;
|
|
2492
|
+
}
|
|
2493
|
+
function latestFailedPayment(payments) {
|
|
2494
|
+
return newestFirst(
|
|
2495
|
+
payments.filter((p) => p.status === "failed"),
|
|
2496
|
+
(p) => p.createdAt
|
|
2497
|
+
)[0] ?? null;
|
|
2498
|
+
}
|
|
2499
|
+
function hasTracking(r) {
|
|
2500
|
+
return !!(r.tracking?.trackingNumber || r.delivery?.trackingNumber);
|
|
2501
|
+
}
|
|
2502
|
+
function accountSource(o) {
|
|
2503
|
+
if (o.customer.savingsMemberId) return "savings";
|
|
2504
|
+
const created = ms(o.customer.createdAt);
|
|
2505
|
+
if (created === null) return "unknown";
|
|
2506
|
+
const oldest = [...o.subscriptions].sort(
|
|
2507
|
+
(a, b) => (ms(a.createdAt) ?? 0) - (ms(b.createdAt) ?? 0)
|
|
2508
|
+
)[0];
|
|
2509
|
+
if (oldest) {
|
|
2510
|
+
const subAt = ms(oldest.createdAt);
|
|
2511
|
+
if (subAt !== null && Math.abs(subAt - created) < 2 * 6e4) return "register_and_subscribe";
|
|
2512
|
+
}
|
|
2513
|
+
return "register";
|
|
2514
|
+
}
|
|
2515
|
+
function lifecycleReason(o) {
|
|
2516
|
+
const { bucket } = o.lifecycle;
|
|
2517
|
+
const facts = o.lifecycle.facts;
|
|
2518
|
+
const sub = primarySubscription(o.subscriptions);
|
|
2519
|
+
const source = accountSource(o);
|
|
2520
|
+
const joined = fmtDay(o.customer.createdAt);
|
|
2521
|
+
const captures = newestFirst(o.funnel.captures, (c) => c.capturedAt);
|
|
2522
|
+
const capture = captures[0] ?? null;
|
|
2523
|
+
switch (bucket) {
|
|
2524
|
+
case "never_subscribed": {
|
|
2525
|
+
const opener = source === "savings" ? `Joined through the savings program on ${joined}.` : `Created an account on ${joined}.`;
|
|
2526
|
+
if (capture) {
|
|
2527
|
+
if (!capture.qualified) {
|
|
2528
|
+
return `${opener} Completed the intake survey on ${fmtDay(capture.capturedAt)} but did not qualify.`;
|
|
2529
|
+
}
|
|
2530
|
+
return `${opener} Completed the intake survey on ${fmtDay(capture.capturedAt)} but never checked out.`;
|
|
2531
|
+
}
|
|
2532
|
+
if (facts?.hasFunnelCapture) {
|
|
2533
|
+
return `${opener} Completed the intake survey but never checked out.`;
|
|
2534
|
+
}
|
|
2535
|
+
if (facts?.hasOpenCart) {
|
|
2536
|
+
return `${opener} Never completed the intake survey; has an abandoned cart.`;
|
|
2537
|
+
}
|
|
2538
|
+
return `${opener} Never completed the intake survey.`;
|
|
2539
|
+
}
|
|
2540
|
+
case "card_declined": {
|
|
2541
|
+
const failed = latestFailedPayment(o.payments);
|
|
2542
|
+
const when = failed ? fmtDay(failed.createdAt) : fmtDay(facts?.lastPaymentAt);
|
|
2543
|
+
const why = failed?.failureReason ? `: ${failed.failureReason}` : "";
|
|
2544
|
+
return `Card declined at checkout on ${when}${why}. No subscription was created.`;
|
|
2545
|
+
}
|
|
2546
|
+
case "awaiting_prescriber": {
|
|
2547
|
+
const req = latestRequest(o.requests.items);
|
|
2548
|
+
const when = req ? fmtDay(req.createdAt) : fmtDay(facts?.latestRequestApexStatus ? null : null);
|
|
2549
|
+
return req ? `Prescription request submitted ${when}; awaiting prescriber review.` : "A prescription request is awaiting prescriber review.";
|
|
2550
|
+
}
|
|
2551
|
+
case "incomplete":
|
|
2552
|
+
return "Checkout payment outcome is unknown; the subscription is on hold until the charge is verified.";
|
|
2553
|
+
case "active": {
|
|
2554
|
+
if (!sub) return "Active subscription.";
|
|
2555
|
+
const next = sub.nextChargeAt ? ` Next charge ${fmtDay(sub.nextChargeAt)}.` : "";
|
|
2556
|
+
return `Subscribed ${fmtDay(sub.createdAt)}.${next}`;
|
|
2557
|
+
}
|
|
2558
|
+
case "past_due": {
|
|
2559
|
+
const s = o.subscriptions.find((x) => x.status === "past_due") ?? sub;
|
|
2560
|
+
const attempt = s ? newestFirst(s.billingAttempts ?? [], (a) => a.createdAt).find((a) => a.status === "failed") : null;
|
|
2561
|
+
const n = s?.retryCount ? ` (retry ${s.retryCount})` : "";
|
|
2562
|
+
const why = attempt?.errorMessage ? `: ${sentence(attempt.errorMessage)}` : ".";
|
|
2563
|
+
const retry = s?.nextChargeAt ? ` Next retry ${fmtDay(s.nextChargeAt)}.` : "";
|
|
2564
|
+
return `Renewal charge failed${n}${why}${retry}`;
|
|
2565
|
+
}
|
|
2566
|
+
case "paused": {
|
|
2567
|
+
const s = o.subscriptions.find((x) => x.status === "paused") ?? sub;
|
|
2568
|
+
return s?.pausedAt ? `Paused on ${fmtDay(s.pausedAt)}.` : "Subscription paused.";
|
|
2569
|
+
}
|
|
2570
|
+
case "cancelled": {
|
|
2571
|
+
const s = newestFirst(
|
|
2572
|
+
o.subscriptions.filter((x) => x.status === "cancelled"),
|
|
2573
|
+
(x) => x.cancelledAt
|
|
2574
|
+
)[0] ?? sub;
|
|
2575
|
+
if (!s) return "Subscription cancelled.";
|
|
2576
|
+
const started = ms(s.createdAt);
|
|
2577
|
+
const ended = ms(s.cancelledAt);
|
|
2578
|
+
const months = started !== null && ended !== null ? Math.max(0, Math.round((ended - started) / (30 * DAY_MS2))) : null;
|
|
2579
|
+
const tenure = months !== null && months > 0 ? ` after ${months} month${months === 1 ? "" : "s"}` : "";
|
|
2580
|
+
return `Cancelled on ${fmtDay(s.cancelledAt)}${tenure}.`;
|
|
2581
|
+
}
|
|
2582
|
+
default:
|
|
2583
|
+
return o.lifecycle.label || "";
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
var SEVERITY_RANK = { danger: 0, warning: 1, info: 2 };
|
|
2587
|
+
var STALE_REVIEW_DAYS = 3;
|
|
2588
|
+
function deriveAttention(o, now = /* @__PURE__ */ new Date()) {
|
|
2589
|
+
const items = [];
|
|
2590
|
+
const nowMs = now.getTime();
|
|
2591
|
+
const liveSubs = o.subscriptions.filter((s) => LIVE.has(s.status));
|
|
2592
|
+
for (const p of o.payments) {
|
|
2593
|
+
if (p.status === "refund_pending") {
|
|
2594
|
+
items.push({
|
|
2595
|
+
id: `refund-pending-${p.id}`,
|
|
2596
|
+
severity: "danger",
|
|
2597
|
+
title: `Refund of ${dollars(p.amountCents)} did not complete at the gateway`,
|
|
2598
|
+
detail: p.failureReason ?? "Finish the refund manually in the gateway, then resolve here.",
|
|
2599
|
+
action: { kind: "open_payment", label: "View payment", paymentId: p.id }
|
|
2600
|
+
});
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
for (const s of o.subscriptions) {
|
|
2604
|
+
for (const a of s.billingAttempts ?? []) {
|
|
2605
|
+
if (a.status === "indeterminate") {
|
|
2606
|
+
items.push({
|
|
2607
|
+
id: `attempt-indeterminate-${a.id}`,
|
|
2608
|
+
severity: "danger",
|
|
2609
|
+
title: "A charge outcome is unknown; billing is blocked until it is resolved",
|
|
2610
|
+
detail: `${dollars(a.amountCents)} for period ${(a.billingPeriod ?? 0) + 1}${a.errorMessage ? ` \u2014 ${a.errorMessage}` : ""}`,
|
|
2611
|
+
action: { kind: "resolve_attempt", label: "Resolve", subscriptionId: s.id, attemptId: a.id }
|
|
2612
|
+
});
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
if (s.status === "past_due") {
|
|
2616
|
+
const failed = newestFirst(s.billingAttempts ?? [], (a) => a.createdAt).find((a) => a.status === "failed");
|
|
2617
|
+
items.push({
|
|
2618
|
+
id: `past-due-${s.id}`,
|
|
2619
|
+
severity: "warning",
|
|
2620
|
+
title: `Renewal charge failed${s.retryCount ? ` (retry ${s.retryCount})` : ""}`,
|
|
2621
|
+
detail: [
|
|
2622
|
+
failed?.errorMessage ? sentence(failed.errorMessage) : failed?.errorCode ? `Code ${failed.errorCode}.` : null,
|
|
2623
|
+
s.nextChargeAt ? `Next retry ${fmtDay(s.nextChargeAt)}.` : "No retry scheduled."
|
|
2624
|
+
].filter(Boolean).join(" "),
|
|
2625
|
+
action: { kind: "edit_schedule", label: "Edit schedule", subscriptionId: s.id }
|
|
2626
|
+
});
|
|
2627
|
+
}
|
|
2628
|
+
if (s.status === "incomplete") {
|
|
2629
|
+
items.push({
|
|
2630
|
+
id: `incomplete-${s.id}`,
|
|
2631
|
+
severity: "warning",
|
|
2632
|
+
title: "Checkout payment is unverified",
|
|
2633
|
+
detail: "The gateway did not confirm the first charge. The subscription is held and will not bill until resolved.",
|
|
2634
|
+
action: { kind: "open_subscription", label: "View subscription", subscriptionId: s.id }
|
|
2635
|
+
});
|
|
2636
|
+
}
|
|
2637
|
+
}
|
|
2638
|
+
if (liveSubs.length === 0) {
|
|
2639
|
+
const declined = latestFailedPayment(o.payments.filter((p) => p.detached));
|
|
2640
|
+
if (declined) {
|
|
2641
|
+
items.push({
|
|
2642
|
+
id: `declined-${declined.id}`,
|
|
2643
|
+
severity: "warning",
|
|
2644
|
+
title: `Card declined at checkout on ${fmtDay(declined.createdAt)}`,
|
|
2645
|
+
detail: declined.failureReason ?? void 0,
|
|
2646
|
+
action: { kind: "open_payment", label: "View payment", paymentId: declined.id }
|
|
2647
|
+
});
|
|
2648
|
+
}
|
|
2649
|
+
}
|
|
2650
|
+
if (o.subscriptions.length === 0 && o.payments.every((p) => p.status !== "failed")) {
|
|
2651
|
+
const captured = o.funnel.captures.length > 0 || o.lifecycle.facts?.hasFunnelCapture;
|
|
2652
|
+
if (o.customer.savingsMemberId && !captured) {
|
|
2653
|
+
items.push({
|
|
2654
|
+
id: "savings-no-intake",
|
|
2655
|
+
severity: "info",
|
|
2656
|
+
title: "Registered through the savings program but never started the intake survey",
|
|
2657
|
+
detail: o.tenant.requirePaidSubscription ? "This site requires a paid subscription before a prescription request can be created." : void 0
|
|
2658
|
+
});
|
|
2659
|
+
} else if (captured) {
|
|
2660
|
+
const c = newestFirst(o.funnel.captures, (x) => x.capturedAt)[0];
|
|
2661
|
+
items.push({
|
|
2662
|
+
id: "intake-no-checkout",
|
|
2663
|
+
severity: "info",
|
|
2664
|
+
title: c ? `Completed the intake survey on ${fmtDay(c.capturedAt)} but never checked out` : "Completed the intake survey but never checked out",
|
|
2665
|
+
detail: c && !c.qualified ? "Did not qualify." : void 0
|
|
2666
|
+
});
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
for (const r of o.requests.items) {
|
|
2670
|
+
if (r.status === "call_requested") {
|
|
2671
|
+
items.push({
|
|
2672
|
+
id: `consult-${r.requestId}`,
|
|
2673
|
+
severity: "info",
|
|
2674
|
+
title: `Prescriber requested a consultation${r.drugName ? ` for ${r.drugName}` : ""}`,
|
|
2675
|
+
action: { kind: "open_request", label: "View request", requestId: r.requestId }
|
|
2676
|
+
});
|
|
2677
|
+
}
|
|
2678
|
+
if (r.status === "pending") {
|
|
2679
|
+
const created = ms(r.createdAt);
|
|
2680
|
+
const days = created !== null ? Math.floor((nowMs - created) / DAY_MS2) : null;
|
|
2681
|
+
if (days !== null && days >= STALE_REVIEW_DAYS) {
|
|
2682
|
+
items.push({
|
|
2683
|
+
id: `stale-review-${r.requestId}`,
|
|
2684
|
+
severity: "info",
|
|
2685
|
+
title: `Awaiting prescriber review for ${days} days${r.drugName ? ` (${r.drugName})` : ""}`,
|
|
2686
|
+
action: { kind: "open_request", label: "View request", requestId: r.requestId }
|
|
2687
|
+
});
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
if (r.renewal?.needsReviewAt) {
|
|
2691
|
+
items.push({
|
|
2692
|
+
id: `renewal-review-${r.renewal.id}`,
|
|
2693
|
+
severity: "warning",
|
|
2694
|
+
title: "Renewal needs review",
|
|
2695
|
+
detail: r.renewal.reviewReason ?? void 0,
|
|
2696
|
+
action: { kind: "open_request", label: "View request", requestId: r.requestId }
|
|
2697
|
+
});
|
|
2698
|
+
}
|
|
2699
|
+
}
|
|
2700
|
+
const pending = o.requests.items.filter((r) => r.status === "pending");
|
|
2701
|
+
if (liveSubs.length === 0 && o.subscriptions.some((s) => s.status === "cancelled") && pending.length > 0) {
|
|
2702
|
+
items.push({
|
|
2703
|
+
id: "cancelled-with-pending",
|
|
2704
|
+
severity: "warning",
|
|
2705
|
+
title: `${pending.length} unapproved prescription request${pending.length === 1 ? " is" : "s are"} still in the prescriber queue after cancellation`,
|
|
2706
|
+
detail: "A cancelled customer should not be prescribed. Cancel the pending requests.",
|
|
2707
|
+
action: { kind: "cancel_unapproved", label: "Cancel unapproved requests" }
|
|
2708
|
+
});
|
|
2709
|
+
}
|
|
2710
|
+
for (const t of o.support.threads) {
|
|
2711
|
+
if (t.adminUnread && t.status !== "closed") {
|
|
2712
|
+
items.push({
|
|
2713
|
+
id: `support-${t.id}`,
|
|
2714
|
+
severity: "info",
|
|
2715
|
+
title: `Support message awaiting reply${t.subject ? `: ${t.subject}` : ""}`,
|
|
2716
|
+
detail: t.lastMessageAt ? `Last message ${fmtDay(t.lastMessageAt)}` : void 0,
|
|
2717
|
+
action: { kind: "open_thread", label: "Open thread", threadId: t.id }
|
|
2718
|
+
});
|
|
2719
|
+
}
|
|
2720
|
+
}
|
|
2721
|
+
return items.sort((a, b) => SEVERITY_RANK[a.severity] - SEVERITY_RANK[b.severity]);
|
|
2722
|
+
}
|
|
2723
|
+
var JOURNEY_LABEL = {
|
|
2724
|
+
account: "Account",
|
|
2725
|
+
intake: "Intake",
|
|
2726
|
+
checkout: "Checkout",
|
|
2727
|
+
prescriber: "Prescriber",
|
|
2728
|
+
pharmacy: "Pharmacy",
|
|
2729
|
+
shipped: "Shipped",
|
|
2730
|
+
renewing: "Renewing"
|
|
2731
|
+
};
|
|
2732
|
+
function step(key, state, date = null, detail = null) {
|
|
2733
|
+
return { key, label: JOURNEY_LABEL[key], state, date, detail };
|
|
2734
|
+
}
|
|
2735
|
+
function deriveJourney(o) {
|
|
2736
|
+
const steps = [];
|
|
2737
|
+
const source = accountSource(o);
|
|
2738
|
+
const subs = o.subscriptions;
|
|
2739
|
+
const liveSub = primarySubscription(subs.filter((s) => LIVE.has(s.status)));
|
|
2740
|
+
const anySub = subs.length > 0;
|
|
2741
|
+
const req = latestRequest(o.requests.items);
|
|
2742
|
+
const capture = newestFirst(o.funnel.captures, (c) => c.capturedAt)[0] ?? null;
|
|
2743
|
+
const session = newestFirst(o.funnel.sessions, (s) => s.lastSeenAt)[0] ?? null;
|
|
2744
|
+
const declined = latestFailedPayment(o.payments);
|
|
2745
|
+
const paid = newestFirst(
|
|
2746
|
+
o.payments.filter((p) => p.status === "succeeded" || p.status === "refunded"),
|
|
2747
|
+
(p) => p.createdAt
|
|
2748
|
+
)[0];
|
|
2749
|
+
steps.push(step("account", "done", o.customer.createdAt, ACCOUNT_SOURCE_LABEL[source]));
|
|
2750
|
+
const intakeDone = !!capture || o.lifecycle.facts?.hasFunnelCapture || anySub || o.requests.items.length > 0;
|
|
2751
|
+
if (intakeDone) {
|
|
2752
|
+
steps.push(
|
|
2753
|
+
step(
|
|
2754
|
+
"intake",
|
|
2755
|
+
"done",
|
|
2756
|
+
capture?.capturedAt ?? null,
|
|
2757
|
+
capture ? capture.qualified ? "Completed and qualified" : "Completed, did not qualify" : "Completed"
|
|
2758
|
+
)
|
|
2759
|
+
);
|
|
2760
|
+
} else if (session) {
|
|
2761
|
+
steps.push(
|
|
2762
|
+
step(
|
|
2763
|
+
"intake",
|
|
2764
|
+
"active",
|
|
2765
|
+
session.lastSeenAt,
|
|
2766
|
+
session.lastStep != null && session.stepCount ? `Stopped at step ${session.lastStep} of ${session.stepCount}` : "Started, not completed"
|
|
2767
|
+
)
|
|
2768
|
+
);
|
|
2769
|
+
} else {
|
|
2770
|
+
steps.push(
|
|
2771
|
+
step(
|
|
2772
|
+
"intake",
|
|
2773
|
+
"active",
|
|
2774
|
+
null,
|
|
2775
|
+
o.funnel.telemetryEnabled ? "Not started" : "Not completed (step data not collected on this site)"
|
|
2776
|
+
)
|
|
2777
|
+
);
|
|
2778
|
+
}
|
|
2779
|
+
if (anySub || paid) {
|
|
2780
|
+
const first = [...subs].sort((a, b) => (ms(a.createdAt) ?? 0) - (ms(b.createdAt) ?? 0))[0];
|
|
2781
|
+
steps.push(step("checkout", "done", first?.createdAt ?? paid?.createdAt ?? null, first ? `${dollars(first.amountCents)} subscription` : "One-time purchase"));
|
|
2782
|
+
} else if (subs.some((s) => s.status === "incomplete")) {
|
|
2783
|
+
steps.push(step("checkout", "blocked", null, "Payment outcome unverified"));
|
|
2784
|
+
} else if (declined) {
|
|
2785
|
+
steps.push(step("checkout", "blocked", declined.createdAt, declined.failureReason ? `Declined: ${declined.failureReason}` : "Card declined"));
|
|
2786
|
+
} else if (intakeDone) {
|
|
2787
|
+
steps.push(step("checkout", "active", null, "Not started"));
|
|
2788
|
+
} else {
|
|
2789
|
+
steps.push(step("checkout", "upcoming"));
|
|
2790
|
+
}
|
|
2791
|
+
const checkoutDone = anySub || !!paid;
|
|
2792
|
+
if (req) {
|
|
2793
|
+
switch (req.status) {
|
|
2794
|
+
case "pending":
|
|
2795
|
+
steps.push(step("prescriber", "active", req.createdAt, "Awaiting review"));
|
|
2796
|
+
break;
|
|
2797
|
+
case "call_requested":
|
|
2798
|
+
steps.push(step("prescriber", "blocked", req.updatedAt ?? req.createdAt, "Consultation requested"));
|
|
2799
|
+
break;
|
|
2800
|
+
case "denied":
|
|
2801
|
+
steps.push(step("prescriber", "blocked", req.updatedAt ?? req.createdAt, "Not approved"));
|
|
2802
|
+
break;
|
|
2803
|
+
default:
|
|
2804
|
+
steps.push(step("prescriber", "done", req.updatedAt ?? req.createdAt, "Approved"));
|
|
2805
|
+
}
|
|
2806
|
+
} else if (liveSub) {
|
|
2807
|
+
steps.push(step("prescriber", "blocked", null, "No prescription request on file"));
|
|
2808
|
+
} else if (checkoutDone) {
|
|
2809
|
+
steps.push(step("prescriber", "upcoming", null, "No prescription request"));
|
|
2810
|
+
} else {
|
|
2811
|
+
steps.push(step("prescriber", "upcoming"));
|
|
2812
|
+
}
|
|
2813
|
+
const approvedStatuses = /* @__PURE__ */ new Set(["approved", "pharmacy", "processing", "completed", "shipped"]);
|
|
2814
|
+
if (req && (req.status === "pharmacy" || req.status === "processing" || req.status === "completed" || req.status === "shipped" || hasTracking(req))) {
|
|
2815
|
+
steps.push(step("pharmacy", "done", req.updatedAt ?? null, req.pharmacySent ? "Sent to pharmacy" : "At the pharmacy"));
|
|
2816
|
+
} else if (req && req.status === "approved") {
|
|
2817
|
+
steps.push(
|
|
2818
|
+
step(
|
|
2819
|
+
"pharmacy",
|
|
2820
|
+
"active",
|
|
2821
|
+
null,
|
|
2822
|
+
o.tenant.fulfillmentMode === "deferred" && !req.paymentConfirmed ? "Approved; waiting on payment confirmation" : "Approved; waiting for pharmacy hand-off"
|
|
2823
|
+
)
|
|
2824
|
+
);
|
|
2825
|
+
} else if (req && approvedStatuses.has(req.status)) {
|
|
2826
|
+
steps.push(step("pharmacy", "active"));
|
|
2827
|
+
} else {
|
|
2828
|
+
steps.push(step("pharmacy", "upcoming"));
|
|
2829
|
+
}
|
|
2830
|
+
if (req && hasTracking(req)) {
|
|
2831
|
+
const carrier = req.tracking?.shipCarrier ?? req.delivery?.shipCarrier ?? null;
|
|
2832
|
+
const number = req.tracking?.trackingNumber ?? req.delivery?.trackingNumber ?? null;
|
|
2833
|
+
const delivered = (req.tracking?.deliveryStatus ?? req.delivery?.status ?? "").toLowerCase() === "delivered";
|
|
2834
|
+
steps.push(
|
|
2835
|
+
step(
|
|
2836
|
+
"shipped",
|
|
2837
|
+
"done",
|
|
2838
|
+
req.tracking?.shippedAt ?? null,
|
|
2839
|
+
delivered ? "Delivered" : [carrier, number].filter(Boolean).join(" ") || "Shipped"
|
|
2840
|
+
)
|
|
2841
|
+
);
|
|
2842
|
+
} else if (req && (req.status === "pharmacy" || req.status === "processing" || req.status === "completed")) {
|
|
2843
|
+
steps.push(step("shipped", "active", null, "Awaiting shipment"));
|
|
2844
|
+
} else {
|
|
2845
|
+
steps.push(step("shipped", "upcoming"));
|
|
2846
|
+
}
|
|
2847
|
+
if (liveSub) {
|
|
2848
|
+
if (liveSub.status === "past_due") {
|
|
2849
|
+
steps.push(step("renewing", "blocked", liveSub.nextChargeAt, `Renewal charge failed${liveSub.retryCount ? `, retry ${liveSub.retryCount}` : ""}`));
|
|
2850
|
+
} else if (liveSub.status === "paused") {
|
|
2851
|
+
steps.push(step("renewing", "blocked", liveSub.pausedAt, "Paused"));
|
|
2852
|
+
} else {
|
|
2853
|
+
const checkIn = req?.renewal?.status ?? null;
|
|
2854
|
+
steps.push(
|
|
2855
|
+
step(
|
|
2856
|
+
"renewing",
|
|
2857
|
+
"done",
|
|
2858
|
+
liveSub.nextChargeAt,
|
|
2859
|
+
liveSub.nextChargeAt ? `Next charge ${fmtDay(liveSub.nextChargeAt)}${checkIn ? ` \xB7 check-in ${checkIn.replace(/_/g, " ")}` : ""}` : "No next charge scheduled"
|
|
2860
|
+
)
|
|
2861
|
+
);
|
|
2862
|
+
}
|
|
2863
|
+
} else if (subs.some((s) => s.status === "cancelled")) {
|
|
2864
|
+
const c = newestFirst(subs.filter((s) => s.status === "cancelled"), (s) => s.cancelledAt)[0];
|
|
2865
|
+
steps.push(step("renewing", "blocked", c?.cancelledAt ?? null, "Cancelled"));
|
|
2866
|
+
} else {
|
|
2867
|
+
steps.push(step("renewing", "upcoming"));
|
|
2868
|
+
}
|
|
2869
|
+
let seenActive = false;
|
|
2870
|
+
for (const s of steps) {
|
|
2871
|
+
if (s.state === "active" || s.state === "blocked") {
|
|
2872
|
+
if (seenActive && s.state === "active") s.state = "upcoming";
|
|
2873
|
+
seenActive = true;
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2876
|
+
return steps;
|
|
2877
|
+
}
|
|
2878
|
+
var TRACKER_STATUS = {
|
|
2879
|
+
pending: "pending",
|
|
2880
|
+
approved: "approved",
|
|
2881
|
+
denied: "denied",
|
|
2882
|
+
call_requested: "call_requested",
|
|
2883
|
+
pharmacy: "pharmacy",
|
|
2884
|
+
processing: "pharmacy",
|
|
2885
|
+
completed: "pharmacy",
|
|
2886
|
+
shipped: "shipped"
|
|
2887
|
+
};
|
|
2888
|
+
function toTrackerRequest(r) {
|
|
2889
|
+
const delivery = r.delivery ?? (r.tracking?.trackingNumber ? {
|
|
2890
|
+
status: r.tracking.deliveryStatus,
|
|
2891
|
+
trackingNumber: r.tracking.trackingNumber,
|
|
2892
|
+
shipCarrier: r.tracking.shipCarrier ?? "",
|
|
2893
|
+
trackingUrl: null
|
|
2894
|
+
} : null);
|
|
2895
|
+
const status = delivery?.trackingNumber ? "shipped" : TRACKER_STATUS[r.status] ?? "pending";
|
|
2896
|
+
return {
|
|
2897
|
+
status,
|
|
2898
|
+
createdAt: r.createdAt,
|
|
2899
|
+
updatedAt: r.updatedAt,
|
|
2900
|
+
dosage: r.dosage ?? void 0,
|
|
2901
|
+
delivery
|
|
2902
|
+
};
|
|
2903
|
+
}
|
|
2904
|
+
var at = (iso) => iso ?? "";
|
|
2905
|
+
function attemptTone(a) {
|
|
2906
|
+
if (a.status === "failed") return "danger";
|
|
2907
|
+
if (a.status === "indeterminate") return "warning";
|
|
2908
|
+
if (a.status === "succeeded") return "success";
|
|
2909
|
+
return "neutral";
|
|
2910
|
+
}
|
|
2911
|
+
function buildTimeline(o, limit = 200) {
|
|
2912
|
+
const ev = [];
|
|
2913
|
+
ev.push({
|
|
2914
|
+
id: "account",
|
|
2915
|
+
at: o.customer.createdAt,
|
|
2916
|
+
kind: "account",
|
|
2917
|
+
title: "Account created",
|
|
2918
|
+
detail: ACCOUNT_SOURCE_LABEL[accountSource(o)],
|
|
2919
|
+
tone: "neutral"
|
|
2920
|
+
});
|
|
2921
|
+
for (const c of o.funnel.captures) {
|
|
2922
|
+
ev.push({
|
|
2923
|
+
id: `capture-${c.responseId}`,
|
|
2924
|
+
at: at(c.capturedAt),
|
|
2925
|
+
kind: "intake",
|
|
2926
|
+
title: c.qualified ? "Completed intake survey (qualified)" : "Completed intake survey (did not qualify)",
|
|
2927
|
+
detail: c.remindersSent ? `${c.remindersSent} recovery reminder${c.remindersSent === 1 ? "" : "s"} sent` : null,
|
|
2928
|
+
tone: c.qualified ? "success" : "neutral"
|
|
2929
|
+
});
|
|
2930
|
+
}
|
|
2931
|
+
for (const s of o.funnel.sessions) {
|
|
2932
|
+
ev.push({
|
|
2933
|
+
id: `session-${s.sessionId}`,
|
|
2934
|
+
at: at(s.startedAt),
|
|
2935
|
+
kind: "intake",
|
|
2936
|
+
title: "Started intake survey",
|
|
2937
|
+
detail: s.lastStep != null && s.stepCount ? `Reached step ${s.lastStep} of ${s.stepCount}` : null,
|
|
2938
|
+
tone: "neutral"
|
|
2939
|
+
});
|
|
2940
|
+
}
|
|
2941
|
+
for (const c of o.funnel.carts) {
|
|
2942
|
+
ev.push({
|
|
2943
|
+
id: `cart-${c.cartId}`,
|
|
2944
|
+
at: at(c.updatedAt),
|
|
2945
|
+
kind: "cart",
|
|
2946
|
+
title: c.convertedAt ? "Cart checked out" : "Cart left open",
|
|
2947
|
+
detail: `${c.itemCount} item${c.itemCount === 1 ? "" : "s"} \xB7 ${dollars(c.subtotalCents)}`,
|
|
2948
|
+
tone: "neutral"
|
|
2949
|
+
});
|
|
2950
|
+
}
|
|
2951
|
+
for (const s of o.subscriptions) {
|
|
2952
|
+
ev.push({
|
|
2953
|
+
id: `sub-created-${s.id}`,
|
|
2954
|
+
at: at(s.createdAt),
|
|
2955
|
+
kind: "subscription",
|
|
2956
|
+
title: `Subscribed${s.medication ? ` to ${s.medication}` : ""}`,
|
|
2957
|
+
detail: `${dollars(s.amountCents)} every ${s.intervalDays} days`,
|
|
2958
|
+
tone: "success"
|
|
2959
|
+
});
|
|
2960
|
+
if (s.pausedAt && s.status === "paused") {
|
|
2961
|
+
ev.push({ id: `sub-paused-${s.id}`, at: s.pausedAt, kind: "subscription", title: "Subscription paused", tone: "neutral" });
|
|
2962
|
+
}
|
|
2963
|
+
if (s.cancelledAt) {
|
|
2964
|
+
ev.push({ id: `sub-cancelled-${s.id}`, at: s.cancelledAt, kind: "subscription", title: "Subscription cancelled", tone: "danger" });
|
|
2965
|
+
}
|
|
2966
|
+
for (const a of s.billingAttempts ?? []) {
|
|
2967
|
+
if (a.status === "succeeded") continue;
|
|
2968
|
+
ev.push({
|
|
2969
|
+
id: `attempt-${a.id}`,
|
|
2970
|
+
at: at(a.createdAt),
|
|
2971
|
+
kind: "attempt",
|
|
2972
|
+
title: a.status === "failed" ? `Renewal charge failed (${dollars(a.amountCents)})` : a.status === "indeterminate" ? `Renewal charge outcome unknown (${dollars(a.amountCents)})` : `Renewal charge pending (${dollars(a.amountCents)})`,
|
|
2973
|
+
detail: a.errorMessage ?? a.errorCode ?? null,
|
|
2974
|
+
tone: attemptTone(a)
|
|
2975
|
+
});
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
for (const p of o.payments) {
|
|
2979
|
+
const detached = p.detached ? " at checkout (no subscription created)" : "";
|
|
2980
|
+
const title = p.status === "succeeded" ? `Paid ${dollars(p.amountCents)}` : p.status === "failed" ? `Payment of ${dollars(p.amountCents)} declined${detached}` : p.status === "refunded" ? `Refunded ${dollars(p.refundedAmountCents || p.amountCents)}` : p.status === "refund_pending" ? `Refund of ${dollars(p.amountCents)} pending` : p.status === "voided" ? `Payment of ${dollars(p.amountCents)} voided` : `Payment ${p.status} (${dollars(p.amountCents)})`;
|
|
2981
|
+
ev.push({
|
|
2982
|
+
id: `payment-${p.id}`,
|
|
2983
|
+
at: at(p.createdAt),
|
|
2984
|
+
kind: "payment",
|
|
2985
|
+
title,
|
|
2986
|
+
detail: p.failureReason ?? (p.type ? p.type.replace(/_/g, " ") : null),
|
|
2987
|
+
tone: p.status === "succeeded" ? "success" : p.status === "failed" || p.status === "refund_pending" ? "danger" : p.status === "refunded" || p.status === "voided" ? "warning" : "neutral"
|
|
2988
|
+
});
|
|
2989
|
+
if (p.refundedAt && p.refundedAmountCents > 0 && p.status === "succeeded") {
|
|
2990
|
+
ev.push({
|
|
2991
|
+
id: `payment-partial-${p.id}`,
|
|
2992
|
+
at: at(p.refundedAt),
|
|
2993
|
+
kind: "payment",
|
|
2994
|
+
title: `Partially refunded ${dollars(p.refundedAmountCents)} of ${dollars(p.amountCents)}`,
|
|
2995
|
+
tone: "warning"
|
|
2996
|
+
});
|
|
2997
|
+
}
|
|
2998
|
+
}
|
|
2999
|
+
for (const r of o.requests.items) {
|
|
3000
|
+
if (r.createdAt) {
|
|
3001
|
+
ev.push({
|
|
3002
|
+
id: `request-${r.requestId}`,
|
|
3003
|
+
at: r.createdAt,
|
|
3004
|
+
kind: "request",
|
|
3005
|
+
title: `Prescription request submitted${r.drugName ? ` for ${r.drugName}` : ""}`,
|
|
3006
|
+
detail: r.dosage ?? null,
|
|
3007
|
+
tone: "neutral"
|
|
3008
|
+
});
|
|
3009
|
+
}
|
|
3010
|
+
if (r.updatedAt && r.updatedAt !== r.createdAt && r.status !== "pending") {
|
|
3011
|
+
ev.push({
|
|
3012
|
+
id: `request-status-${r.requestId}`,
|
|
3013
|
+
at: r.updatedAt,
|
|
3014
|
+
kind: "request",
|
|
3015
|
+
title: `Request ${r.status.replace(/_/g, " ")}${r.drugName ? ` (${r.drugName})` : ""}`,
|
|
3016
|
+
tone: r.status === "denied" ? "danger" : r.status === "call_requested" ? "warning" : "success"
|
|
3017
|
+
});
|
|
3018
|
+
}
|
|
3019
|
+
if (r.tracking?.shippedAt) {
|
|
3020
|
+
ev.push({
|
|
3021
|
+
id: `shipped-${r.requestId}`,
|
|
3022
|
+
at: r.tracking.shippedAt,
|
|
3023
|
+
kind: "shipment",
|
|
3024
|
+
title: `Shipped${r.drugName ? ` ${r.drugName}` : ""}`,
|
|
3025
|
+
detail: [r.tracking.shipCarrier, r.tracking.trackingNumber].filter(Boolean).join(" ") || null,
|
|
3026
|
+
tone: "success"
|
|
3027
|
+
});
|
|
3028
|
+
}
|
|
3029
|
+
if (r.renewal?.triggerAt) {
|
|
3030
|
+
ev.push({
|
|
3031
|
+
id: `renewal-${r.renewal.id}`,
|
|
3032
|
+
at: r.renewal.triggerAt,
|
|
3033
|
+
kind: "renewal",
|
|
3034
|
+
title: `Refill check-in ${r.renewal.status.replace(/_/g, " ")}`,
|
|
3035
|
+
detail: r.renewal.pharmacyFillDate ? `Fill date ${r.renewal.pharmacyFillDate}` : null,
|
|
3036
|
+
tone: r.renewal.status === "request_failed" ? "danger" : "neutral"
|
|
3037
|
+
});
|
|
3038
|
+
}
|
|
3039
|
+
}
|
|
3040
|
+
for (const t of o.support.threads) {
|
|
3041
|
+
if (t.lastMessageAt) {
|
|
3042
|
+
ev.push({
|
|
3043
|
+
id: `support-${t.id}`,
|
|
3044
|
+
at: t.lastMessageAt,
|
|
3045
|
+
kind: "support",
|
|
3046
|
+
title: t.adminUnread ? "Support message awaiting reply" : `Support thread ${t.status}`,
|
|
3047
|
+
detail: t.subject,
|
|
3048
|
+
tone: t.adminUnread ? "info" : "neutral"
|
|
3049
|
+
});
|
|
3050
|
+
}
|
|
3051
|
+
}
|
|
3052
|
+
return ev.filter((e) => ms(e.at) !== null).sort((a, b) => (ms(b.at) ?? 0) - (ms(a.at) ?? 0)).slice(0, limit);
|
|
3053
|
+
}
|
|
3054
|
+
|
|
2415
3055
|
// src/flows/memberPortal.ts
|
|
2416
3056
|
import { createResource as createResource2 } from "solid-js";
|
|
2417
3057
|
async function fetchPendingSurveys2() {
|
|
@@ -2460,7 +3100,7 @@ function useMemberPortalData() {
|
|
|
2460
3100
|
const [pendingSurveys] = createResource2(fetchPendingSurveys2);
|
|
2461
3101
|
const member = () => me.error ? null : me()?.member ?? null;
|
|
2462
3102
|
const subscriptions = () => me.error ? [] : me()?.subscriptions ?? [];
|
|
2463
|
-
const
|
|
3103
|
+
const primarySubscription2 = () => pickPrimarySub(subscriptions());
|
|
2464
3104
|
const hasBilling = () => subscriptions().length > 0;
|
|
2465
3105
|
const rxRequests = () => rxRes.error ? [] : rxRes() ?? [];
|
|
2466
3106
|
const primaryRx = () => {
|
|
@@ -2474,7 +3114,7 @@ function useMemberPortalData() {
|
|
|
2474
3114
|
const firstName = () => readFirstName(member());
|
|
2475
3115
|
const loading = () => me.loading || rxRes.loading;
|
|
2476
3116
|
const error = () => rxRes.error || me.error ? "We couldn\u2019t load your portal. Please try again." : null;
|
|
2477
|
-
const
|
|
3117
|
+
const toTrackerRequest2 = (rx) => ({
|
|
2478
3118
|
status: rx.status,
|
|
2479
3119
|
createdAt: rx.createdAt,
|
|
2480
3120
|
updatedAt: rx.updatedAt,
|
|
@@ -2482,7 +3122,7 @@ function useMemberPortalData() {
|
|
|
2482
3122
|
delivery: rx.delivery
|
|
2483
3123
|
});
|
|
2484
3124
|
const trackerSubscription = () => {
|
|
2485
|
-
const s =
|
|
3125
|
+
const s = primarySubscription2();
|
|
2486
3126
|
if (!s) return null;
|
|
2487
3127
|
return {
|
|
2488
3128
|
status: s.status,
|
|
@@ -2498,7 +3138,7 @@ function useMemberPortalData() {
|
|
|
2498
3138
|
return {
|
|
2499
3139
|
member,
|
|
2500
3140
|
subscriptions,
|
|
2501
|
-
primarySubscription,
|
|
3141
|
+
primarySubscription: primarySubscription2,
|
|
2502
3142
|
hasBilling,
|
|
2503
3143
|
rxRequests,
|
|
2504
3144
|
primaryRx,
|
|
@@ -2511,7 +3151,7 @@ function useMemberPortalData() {
|
|
|
2511
3151
|
void refetchMe();
|
|
2512
3152
|
void refetchRx();
|
|
2513
3153
|
},
|
|
2514
|
-
toTrackerRequest,
|
|
3154
|
+
toTrackerRequest: toTrackerRequest2,
|
|
2515
3155
|
trackerSubscription
|
|
2516
3156
|
};
|
|
2517
3157
|
}
|
|
@@ -3200,9 +3840,9 @@ function createFunnelDraftStore(opts) {
|
|
|
3200
3840
|
draftId = saved;
|
|
3201
3841
|
if (isNew) postFunnelEvent("draft:saved", { draftId: saved });
|
|
3202
3842
|
}
|
|
3203
|
-
function scheduleFlush(
|
|
3843
|
+
function scheduleFlush(ms2) {
|
|
3204
3844
|
if (timer) clearTimeout(timer);
|
|
3205
|
-
timer = setTimeout(() => void flush(),
|
|
3845
|
+
timer = setTimeout(() => void flush(), ms2);
|
|
3206
3846
|
}
|
|
3207
3847
|
if (typeof window !== "undefined" && typeof window.addEventListener === "function") {
|
|
3208
3848
|
window.addEventListener("pagehide", () => void flush());
|
|
@@ -3354,6 +3994,18 @@ export {
|
|
|
3354
3994
|
buildRefillView,
|
|
3355
3995
|
formatStageDate,
|
|
3356
3996
|
formatEventDate,
|
|
3997
|
+
LIFECYCLE_LABEL,
|
|
3998
|
+
LIFECYCLE_TONE,
|
|
3999
|
+
LIFECYCLE_BUCKETS,
|
|
4000
|
+
ACCOUNT_SOURCE_LABEL,
|
|
4001
|
+
fmtDay,
|
|
4002
|
+
primarySubscription,
|
|
4003
|
+
accountSource,
|
|
4004
|
+
lifecycleReason,
|
|
4005
|
+
deriveAttention,
|
|
4006
|
+
deriveJourney,
|
|
4007
|
+
toTrackerRequest,
|
|
4008
|
+
buildTimeline,
|
|
3357
4009
|
useMemberPortalData,
|
|
3358
4010
|
useUpdatePaymentMethodFlow,
|
|
3359
4011
|
isImageAttachment,
|
|
@@ -3374,4 +4026,4 @@ export {
|
|
|
3374
4026
|
useSurveyV2Flow,
|
|
3375
4027
|
uploadPrescriptionPhoto
|
|
3376
4028
|
};
|
|
3377
|
-
//# sourceMappingURL=
|
|
4029
|
+
//# sourceMappingURL=NYLIUR7O.jsx.map
|