@apextelemed/partner-core 0.6.4 → 0.7.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 (54) hide show
  1. package/README.md +2 -2
  2. package/dist/api/index.d.ts +1 -1
  3. package/dist/api/index.js +3 -3
  4. package/dist/api/index.jsx +3 -3
  5. package/dist/{cart-D4mVX_zx.d.ts → cart-o6DpAu5y.d.ts} +1 -0
  6. package/dist/chunk/{WLEIDQ5M.jsx → 4S4MTN2K.jsx} +6 -2
  7. package/dist/chunk/{NBB2VTQK.jsx → 4SFB2SS2.jsx} +2 -2
  8. package/dist/chunk/{BVLA7ATM.js → 64RJJFEH.js} +3 -3
  9. package/dist/chunk/{BVLA7ATM.js.map → 64RJJFEH.js.map} +1 -1
  10. package/dist/chunk/{EVCGDF5D.jsx → 7AFUT5S3.jsx} +9 -1
  11. package/dist/chunk/{ZDBW3JDO.jsx → 7AMVRNYX.jsx} +3286 -1423
  12. package/dist/chunk/{4ZSZHZQV.jsx → CBOGAYTL.jsx} +2 -2
  13. package/dist/chunk/{YJEHCCLY.js → EXXI5Y7I.js} +4 -3
  14. package/dist/chunk/EXXI5Y7I.js.map +1 -0
  15. package/dist/chunk/{MTCQREMZ.js → F34QLV7Z.js} +4063 -2058
  16. package/dist/chunk/F34QLV7Z.js.map +1 -0
  17. package/dist/chunk/{MLXPHJLR.js → GODF2NJN.js} +7 -3
  18. package/dist/chunk/GODF2NJN.js.map +1 -0
  19. package/dist/chunk/{WUE4VQBA.js → J3IRPONP.js} +392 -21
  20. package/dist/chunk/J3IRPONP.js.map +1 -0
  21. package/dist/chunk/{QTGJY3YQ.js → J3OK2PQA.js} +3 -3
  22. package/dist/chunk/{QTGJY3YQ.js.map → J3OK2PQA.js.map} +1 -1
  23. package/dist/chunk/{NSRQXBHK.js → KXO4U2C6.js} +8 -189
  24. package/dist/chunk/KXO4U2C6.js.map +1 -0
  25. package/dist/chunk/{HXMLRDIJ.jsx → PA66KUAU.jsx} +418 -26
  26. package/dist/chunk/{2OXI5TKO.jsx → RSMUKR4J.jsx} +3 -2
  27. package/dist/chunk/{5HNZ7SEM.jsx → SHXH72AC.jsx} +26 -219
  28. package/dist/chunk/{BEDW4XUM.js → UPZPR5TU.js} +10 -2
  29. package/dist/chunk/UPZPR5TU.js.map +1 -0
  30. package/dist/{client-B6Kt7LWo.d.ts → client-CiHb-dIf.d.ts} +64 -8
  31. package/dist/flows/index.d.ts +157 -13
  32. package/dist/flows/index.js +6 -6
  33. package/dist/flows/index.jsx +25 -13
  34. package/dist/index/index.d.ts +4 -4
  35. package/dist/index/index.js +8 -8
  36. package/dist/index/index.jsx +40 -16
  37. package/dist/pages/index.d.ts +41 -6
  38. package/dist/pages/index.js +5 -5
  39. package/dist/pages/index.jsx +19 -7
  40. package/dist/primitives/default/index.js +1 -1
  41. package/dist/primitives/default/index.jsx +1 -1
  42. package/dist/stores/index.d.ts +2 -2
  43. package/dist/stores/index.js +2 -2
  44. package/dist/stores/index.jsx +2 -2
  45. package/dist/testing/seam-suite.js +1 -1
  46. package/dist/theme/admin.css +406 -1
  47. package/dist/theme/member-portal.css +5 -5
  48. package/package.json +1 -1
  49. package/dist/chunk/BEDW4XUM.js.map +0 -1
  50. package/dist/chunk/MLXPHJLR.js.map +0 -1
  51. package/dist/chunk/MTCQREMZ.js.map +0 -1
  52. package/dist/chunk/NSRQXBHK.js.map +0 -1
  53. package/dist/chunk/WUE4VQBA.js.map +0 -1
  54. package/dist/chunk/YJEHCCLY.js.map +0 -1
@@ -6,13 +6,13 @@ import {
6
6
  readResumeToken,
7
7
  saveFunnelDraft,
8
8
  stripResumeToken
9
- } from "./NBB2VTQK.jsx";
9
+ } from "./4SFB2SS2.jsx";
10
10
  import {
11
11
  affiliateAuth_default,
12
12
  auth_default,
13
13
  cart_default,
14
14
  medication_default
15
- } from "./WLEIDQ5M.jsx";
15
+ } from "./4S4MTN2K.jsx";
16
16
  import {
17
17
  ApiError,
18
18
  addressesApi,
@@ -24,10 +24,11 @@ import {
24
24
  newIdempotencyKey,
25
25
  ordersApi,
26
26
  paymentsApi,
27
+ productsApi,
27
28
  subscriptionsApi,
28
29
  supportApi,
29
30
  usersApi
30
- } from "./EVCGDF5D.jsx";
31
+ } from "./7AFUT5S3.jsx";
31
32
  import {
32
33
  getConfig
33
34
  } from "./LDZIUFDM.jsx";
@@ -144,13 +145,23 @@ function useSurveyFlow(options = {}) {
144
145
  const [createRequestKey, setCreateRequestKey] = createSignal(newIdempotencyKey());
145
146
  const [hydrated, setHydrated] = createSignal(false);
146
147
  const totalSteps = () => steps().length;
147
- const isLastStep = () => currentStep() >= totalSteps() - 1;
148
148
  const step2 = () => steps()[currentStep()] ?? null;
149
149
  const visibleQuestions = () => {
150
150
  const s = step2();
151
151
  if (!s) return [];
152
152
  return s.questions.filter((q) => isQuestionVisible(q, answers()));
153
153
  };
154
+ const stepHasVisibleQuestions = (i) => {
155
+ const s = steps()[i];
156
+ return !!s && s.questions.some((q) => isQuestionVisible(q, answers()));
157
+ };
158
+ const nearestVisibleStep = (from, dir) => {
159
+ for (let i = from + dir; i >= 0 && i < steps().length; i += dir) {
160
+ if (stepHasVisibleQuestions(i)) return i;
161
+ }
162
+ return -1;
163
+ };
164
+ const isLastStep = () => nearestVisibleStep(currentStep(), 1) === -1;
154
165
  onMount(async () => {
155
166
  const cartItems = cart_default.items();
156
167
  const hasCart = cartItems.length > 0;
@@ -212,7 +223,12 @@ function useSurveyFlow(options = {}) {
212
223
  const draft = loadSurveyDraft();
213
224
  if (draft.surveyId === sid) {
214
225
  if (draft.answers) setAnswers(draft.answers);
215
- setCurrentStep(Math.min(Math.max(draft.currentStep ?? 0, 0), Math.max(flat.length - 1, 0)));
226
+ const restoredStep = Math.min(Math.max(draft.currentStep ?? 0, 0), Math.max(flat.length - 1, 0));
227
+ setCurrentStep(restoredStep);
228
+ if (!stepHasVisibleQuestions(restoredStep)) {
229
+ const fwd = nearestVisibleStep(restoredStep, 1);
230
+ setCurrentStep(fwd !== -1 ? fwd : Math.max(nearestVisibleStep(restoredStep, -1), 0));
231
+ }
216
232
  if (draft.responseId) setResponseId(draft.responseId);
217
233
  if (draft.submitSurveyKey) setSubmitSurveyKey(draft.submitSurveyKey);
218
234
  if (draft.createRequestKey) setCreateRequestKey(draft.createRequestKey);
@@ -447,11 +463,13 @@ function useSurveyFlow(options = {}) {
447
463
  } finally {
448
464
  setSubmitting(false);
449
465
  }
450
- setCurrentStep((s) => s + 1);
466
+ const nextStep = nearestVisibleStep(currentStep(), 1);
467
+ if (nextStep !== -1) setCurrentStep(nextStep);
451
468
  }
452
469
  function back() {
453
470
  setValidationError(null);
454
- if (currentStep() > 0) setCurrentStep((s) => s - 1);
471
+ const prev = nearestVisibleStep(currentStep(), -1);
472
+ if (prev !== -1) setCurrentStep(prev);
455
473
  }
456
474
  async function confirmDrugSelection() {
457
475
  if (!selectedDrugId()) {
@@ -1425,6 +1443,10 @@ function useSignupFlow(options) {
1425
1443
  const [tokenizedData, setTokenizedData] = createSignal6(null);
1426
1444
  const [promoCode, setPromoCode] = createSignal6("");
1427
1445
  const [idempotencyKey, setIdempotencyKey] = createSignal6(newIdempotencyKey());
1446
+ const cartIsEmpty = () => cart_default.items().length === 0;
1447
+ onMount5(() => {
1448
+ if (options.requireCart && cartIsEmpty()) setOutcome({ kind: "needs_cart" });
1449
+ });
1428
1450
  onMount5(() => {
1429
1451
  createEffect4(() => {
1430
1452
  saveDraft({
@@ -1530,6 +1552,10 @@ function useSignupFlow(options) {
1530
1552
  }
1531
1553
  async function submit() {
1532
1554
  if (submitting()) return;
1555
+ if (options.requireCart && cartIsEmpty()) {
1556
+ setOutcome({ kind: "needs_cart" });
1557
+ return;
1558
+ }
1533
1559
  const opaque = tokenizedData();
1534
1560
  if (!opaque) {
1535
1561
  setError("Card not tokenized. Please go back and re-enter your card details.");
@@ -1901,7 +1927,7 @@ function isLive(status) {
1901
1927
  }
1902
1928
 
1903
1929
  // src/flows/subscribe.ts
1904
- import { createSignal as createSignal8, onMount as onMount7 } from "solid-js";
1930
+ import { createEffect as createEffect6, createSignal as createSignal8, on, onMount as onMount7 } from "solid-js";
1905
1931
  async function hasActiveSubscription() {
1906
1932
  const subsRes = await subscriptionsApi.list();
1907
1933
  return (subsRes?.subscriptions ?? []).some((s) => s.status === "active");
@@ -1915,6 +1941,8 @@ function useSubscribeFlow(options) {
1915
1941
  const [outcome, setOutcome] = createSignal8({ kind: "loading" });
1916
1942
  const [error, setError] = createSignal8(null);
1917
1943
  const [submitting, setSubmitting] = createSignal8(false);
1944
+ const [quote, setQuote] = createSignal8(null);
1945
+ const [quoteError, setQuoteError] = createSignal8(null);
1918
1946
  const [street, setStreet] = createSignal8("");
1919
1947
  const [city, setCity] = createSignal8("");
1920
1948
  const [state, setState] = createSignal8("");
@@ -1952,6 +1980,83 @@ function useSubscribeFlow(options) {
1952
1980
  }
1953
1981
  setOutcome({ kind: "in_progress" });
1954
1982
  });
1983
+ const cartProducts = () => cart_default.items().map((i) => ({
1984
+ productId: i.productId,
1985
+ productName: i.productName,
1986
+ quantity: i.quantity,
1987
+ dosage: i.dosage
1988
+ }));
1989
+ function estimateFromCart() {
1990
+ const lines = cart_default.items().map((i) => ({
1991
+ productId: i.productId,
1992
+ productName: i.productName,
1993
+ dosage: i.dosage || null,
1994
+ quantity: i.quantity || 1,
1995
+ amountCents: i.priceCents * (i.quantity || 1)
1996
+ }));
1997
+ let subtotalCents = lines.reduce((s, l) => s + l.amountCents, 0);
1998
+ if (subtotalCents === 0 && lines.length === 0) subtotalCents = options.membershipAmountCents;
1999
+ const discountCents = Math.min(subtotalCents, cart_default.appliedPromo()?.discountCents ?? 0);
2000
+ return {
2001
+ source: "estimate",
2002
+ model: "per_product",
2003
+ intervalDays: options.membershipIntervalDays ?? 30,
2004
+ lines,
2005
+ subtotalCents,
2006
+ discountCents,
2007
+ totalCents: subtotalCents - discountCents
2008
+ };
2009
+ }
2010
+ let quoteSeq = 0;
2011
+ async function refreshQuote() {
2012
+ const seq = ++quoteSeq;
2013
+ setQuoteError(null);
2014
+ try {
2015
+ const p = await subscriptionsApi.preview({
2016
+ products: cartProducts(),
2017
+ productId: cartProducts()[0]?.productId,
2018
+ promoCode: cart_default.appliedPromo()?.code,
2019
+ intervalDays: options.membershipIntervalDays
2020
+ });
2021
+ if (seq !== quoteSeq) return;
2022
+ if (p.alreadySubscribed) {
2023
+ setOutcome({ kind: "already_subscribed" });
2024
+ return;
2025
+ }
2026
+ setQuote({
2027
+ source: "server",
2028
+ model: p.model,
2029
+ intervalDays: p.intervalDays,
2030
+ lines: (p.lines ?? []).map((l) => ({
2031
+ productId: l.productId,
2032
+ productName: l.productName,
2033
+ dosage: l.dosage ?? null,
2034
+ quantity: l.quantity,
2035
+ amountCents: l.amountCents
2036
+ })),
2037
+ subtotalCents: p.subtotalCents,
2038
+ discountCents: p.discountCents,
2039
+ totalCents: p.totalCents
2040
+ });
2041
+ } catch (e) {
2042
+ if (seq !== quoteSeq) return;
2043
+ const status = e instanceof ApiError ? e.status : void 0;
2044
+ if (status && status >= 400 && status < 500 && status !== 404 && status !== 405) {
2045
+ setQuote(null);
2046
+ setQuoteError(e instanceof Error ? e.message : "This order cannot be priced right now.");
2047
+ return;
2048
+ }
2049
+ setQuote(estimateFromCart());
2050
+ }
2051
+ }
2052
+ createEffect6(
2053
+ on(
2054
+ () => [outcome().kind, cart_default.items(), cart_default.appliedPromo()],
2055
+ ([kind]) => {
2056
+ if (kind === "in_progress") void refreshQuote();
2057
+ }
2058
+ )
2059
+ );
1955
2060
  function validate() {
1956
2061
  const a = validateAddress(
1957
2062
  { street: street(), city: city(), state: state(), zip: zip() },
@@ -1975,6 +2080,10 @@ function useSubscribeFlow(options) {
1975
2080
  setOutcome({ kind: "needs_cart" });
1976
2081
  return;
1977
2082
  }
2083
+ if (quoteError()) {
2084
+ setError(quoteError());
2085
+ return;
2086
+ }
1978
2087
  const err = validate();
1979
2088
  if (err) {
1980
2089
  setError(err);
@@ -1998,7 +2107,9 @@ function useSubscribeFlow(options) {
1998
2107
  const res = await subscriptionsApi.create(
1999
2108
  {
2000
2109
  opaqueData: opaque,
2001
- amountCents: options.membershipAmountCents,
2110
+ // Informational only — the backend prices the cart itself. Send what
2111
+ // the customer was shown so the two are auditable together.
2112
+ amountCents: quote()?.totalCents ?? options.membershipAmountCents,
2002
2113
  intervalDays: options.membershipIntervalDays ?? 30,
2003
2114
  billingAddress: {
2004
2115
  street: street().trim(),
@@ -2046,6 +2157,8 @@ function useSubscribeFlow(options) {
2046
2157
  acceptJsError: accept.error,
2047
2158
  error,
2048
2159
  submitting,
2160
+ quote,
2161
+ quoteError,
2049
2162
  street,
2050
2163
  setStreet,
2051
2164
  city,
@@ -2426,7 +2539,7 @@ var LIFECYCLE_LABEL = {
2426
2539
  past_due: "Past due",
2427
2540
  paused: "Paused",
2428
2541
  incomplete: "Incomplete signup",
2429
- cancelled: "Cancelled",
2542
+ cancelled: "Canceled",
2430
2543
  card_declined: "Card declined",
2431
2544
  awaiting_prescriber: "Awaiting prescriber",
2432
2545
  never_subscribed: "Never subscribed"
@@ -2580,12 +2693,12 @@ function lifecycleReason(o) {
2580
2693
  o.subscriptions.filter((x) => x.status === "cancelled"),
2581
2694
  (x) => x.cancelledAt
2582
2695
  )[0] ?? sub;
2583
- if (!s) return "Subscription cancelled.";
2696
+ if (!s) return "Subscription canceled.";
2584
2697
  const started = ms(s.createdAt);
2585
2698
  const ended = ms(s.cancelledAt);
2586
2699
  const months = started !== null && ended !== null ? Math.max(0, Math.round((ended - started) / (30 * DAY_MS2))) : null;
2587
2700
  const tenure = months !== null && months > 0 ? ` after ${months} month${months === 1 ? "" : "s"}` : "";
2588
- return `Cancelled on ${fmtDay(s.cancelledAt)}${tenure}.`;
2701
+ return `Canceled on ${fmtDay(s.cancelledAt)}${tenure}.`;
2589
2702
  }
2590
2703
  default:
2591
2704
  return o.lifecycle.label || "";
@@ -2711,7 +2824,7 @@ function deriveAttention(o, now = /* @__PURE__ */ new Date()) {
2711
2824
  id: "cancelled-with-pending",
2712
2825
  severity: "warning",
2713
2826
  title: `${pending.length} unapproved prescription request${pending.length === 1 ? " is" : "s are"} still in the prescriber queue after cancellation`,
2714
- detail: "A cancelled customer should not be prescribed. Cancel the pending requests.",
2827
+ detail: "A canceled customer should not be prescribed. Cancel the pending requests.",
2715
2828
  action: { kind: "cancel_unapproved", label: "Cancel unapproved requests" }
2716
2829
  });
2717
2830
  }
@@ -2737,8 +2850,8 @@ var JOURNEY_LABEL = {
2737
2850
  shipped: "Shipped",
2738
2851
  renewing: "Renewing"
2739
2852
  };
2740
- function step(key, state, date = null, detail = null) {
2741
- return { key, label: JOURNEY_LABEL[key], state, date, detail };
2853
+ function step(key, state, date = null, detail = null, label = JOURNEY_LABEL[key]) {
2854
+ return { key, label, state, date, detail };
2742
2855
  }
2743
2856
  function deriveJourney(o) {
2744
2857
  const steps = [];
@@ -2870,7 +2983,7 @@ function deriveJourney(o) {
2870
2983
  }
2871
2984
  } else if (subs.some((s) => s.status === "cancelled")) {
2872
2985
  const c = newestFirst(subs.filter((s) => s.status === "cancelled"), (s) => s.cancelledAt)[0];
2873
- steps.push(step("renewing", "blocked", c?.cancelledAt ?? null, "Cancelled"));
2986
+ steps.push(step("renewing", "blocked", c?.cancelledAt ?? null, "Subscription ended", "Canceled"));
2874
2987
  } else {
2875
2988
  steps.push(step("renewing", "upcoming"));
2876
2989
  }
@@ -2970,7 +3083,7 @@ function buildTimeline(o, limit = 200) {
2970
3083
  ev.push({ id: `sub-paused-${s.id}`, at: s.pausedAt, kind: "subscription", title: "Subscription paused", tone: "neutral" });
2971
3084
  }
2972
3085
  if (s.cancelledAt) {
2973
- ev.push({ id: `sub-cancelled-${s.id}`, at: s.cancelledAt, kind: "subscription", title: "Subscription cancelled", tone: "danger" });
3086
+ ev.push({ id: `sub-cancelled-${s.id}`, at: s.cancelledAt, kind: "subscription", title: "Subscription canceled", tone: "danger" });
2974
3087
  }
2975
3088
  for (const a of s.billingAttempts ?? []) {
2976
3089
  if (a.status === "succeeded") continue;
@@ -3170,7 +3283,7 @@ function useMemberPortalData() {
3170
3283
  }
3171
3284
 
3172
3285
  // src/flows/updatePaymentMethod.ts
3173
- import { createEffect as createEffect6, createSignal as createSignal9 } from "solid-js";
3286
+ import { createEffect as createEffect7, createSignal as createSignal9 } from "solid-js";
3174
3287
  function useUpdatePaymentMethodFlow(subscriptionId) {
3175
3288
  const accept = useCardTokenizer();
3176
3289
  const [cardNumber, setCardNumberRaw] = createSignal9("");
@@ -3180,7 +3293,7 @@ function useUpdatePaymentMethodFlow(subscriptionId) {
3180
3293
  const [error, setError] = createSignal9(null);
3181
3294
  const billing = useAddressPair();
3182
3295
  const [billingLoaded, setBillingLoaded] = createSignal9(false);
3183
- createEffect6(() => {
3296
+ createEffect7(() => {
3184
3297
  const id = subscriptionId();
3185
3298
  if (!id || billingLoaded()) return;
3186
3299
  void (async () => {
@@ -3264,10 +3377,12 @@ async function subscribeToSupportTopic(topic, onPing) {
3264
3377
  try {
3265
3378
  const config = await supportApi.getRealtimeToken();
3266
3379
  if (!config?.token || !config.url || !config.anonKey) return null;
3380
+ const topicName = typeof topic === "string" ? topic : config.topics ? topic(config.topics) : void 0;
3381
+ if (!topicName) return null;
3267
3382
  const { createClient } = await import("@supabase/supabase-js");
3268
3383
  const client = createClient(config.url, config.anonKey);
3269
3384
  await client.realtime.setAuth(config.token);
3270
- const channel = client.channel(topic, {
3385
+ const channel = client.channel(topicName, {
3271
3386
  config: { private: true }
3272
3387
  });
3273
3388
  channel.on("broadcast", { event: "thread_updated" }, (message) => {
@@ -3763,10 +3878,234 @@ function useMessagesThread(options = {}) {
3763
3878
  };
3764
3879
  }
3765
3880
 
3881
+ // src/flows/products.ts
3882
+ import { createMemo, createResource as createResource3, createSignal as createSignal11 } from "solid-js";
3883
+ function priceForDosage(product, dosage) {
3884
+ const overlay = (product.dosage_prices ?? []).find((d) => d.dosage === dosage);
3885
+ if (overlay && overlay.price != null) return overlay.price;
3886
+ return product.price;
3887
+ }
3888
+ function lowestPrice(product) {
3889
+ const available = product.available_dosages ?? [];
3890
+ if (available.length === 0) return product.price;
3891
+ let min = null;
3892
+ for (const dose of available) {
3893
+ const p = priceForDosage(product, dose);
3894
+ if (p != null && (min == null || p < min)) min = p;
3895
+ }
3896
+ return min ?? product.price;
3897
+ }
3898
+ function salePriceForBase(product, basePrice) {
3899
+ if (basePrice == null || !product.activeSale) return null;
3900
+ const sale = product.activeSale;
3901
+ const baseCents = Math.round(basePrice * 100);
3902
+ if (sale.discountCents <= 0) return null;
3903
+ if (product.salePriceCents != null && product.price != null && Math.abs(product.price - basePrice) < 1e-3) {
3904
+ return product.salePriceCents / 100;
3905
+ }
3906
+ if (product.price != null && product.salePriceCents != null && product.price > 0) {
3907
+ const ratio = product.salePriceCents / Math.round(product.price * 100);
3908
+ return Math.max(0, basePrice * ratio);
3909
+ }
3910
+ return Math.max(0, (baseCents - sale.discountCents) / 100);
3911
+ }
3912
+ function lowestSalePrice(product, basePrice) {
3913
+ return salePriceForBase(product, basePrice);
3914
+ }
3915
+ function useCatalog() {
3916
+ const [products] = createResource3(async () => {
3917
+ try {
3918
+ const res = await productsApi.list();
3919
+ return res.products;
3920
+ } catch {
3921
+ return [];
3922
+ }
3923
+ });
3924
+ const weightLoss = () => (products() ?? []).filter((p) => (p.categories ?? []).includes("weight-loss"));
3925
+ const peptides = () => (products() ?? []).filter((p) => !(p.categories ?? []).includes("weight-loss"));
3926
+ const filterByCategory = (slug) => (products() ?? []).filter((p) => (p.categories ?? []).includes(slug));
3927
+ return { products, weightLoss, peptides, filterByCategory };
3928
+ }
3929
+ function useProductDetail(productId) {
3930
+ const [product] = createResource3(productId, async (id) => {
3931
+ if (!id) return null;
3932
+ try {
3933
+ const res = await productsApi.list();
3934
+ return res.products.find((p) => p.id === id) ?? null;
3935
+ } catch {
3936
+ return null;
3937
+ }
3938
+ });
3939
+ const pricingMode = createMemo(
3940
+ () => product()?.pricing_mode ?? "per_dose"
3941
+ );
3942
+ const dosageOptions = createMemo(() => {
3943
+ const p = product();
3944
+ if (!p) return [];
3945
+ const all = (p.available_dosages ?? []).map((dosage) => {
3946
+ const overlay = (p.dosage_prices ?? []).find((d) => d.dosage === dosage);
3947
+ const price = overlay && overlay.price != null ? overlay.price : p.price;
3948
+ return { dosage, price, savingsPrice: overlay?.savingsPrice ?? null };
3949
+ }).filter((o) => o.price != null);
3950
+ if (pricingMode() !== "flat_fee" || all.length === 0) return all;
3951
+ const override = p.dosage_override;
3952
+ const chosen = override && all.find((d) => d.dosage === override) || all[0];
3953
+ return [chosen];
3954
+ });
3955
+ const [selectedDosage, setSelectedDosage] = createSignal11("");
3956
+ createMemo(() => {
3957
+ const opts = dosageOptions();
3958
+ if (opts.length > 0 && !selectedDosage()) setSelectedDosage(opts[0].dosage);
3959
+ });
3960
+ const selectedPrice = createMemo(() => {
3961
+ const opts = dosageOptions();
3962
+ const chosen = opts.find((d) => d.dosage === selectedDosage());
3963
+ if (chosen) return chosen.price;
3964
+ return product()?.price ?? null;
3965
+ });
3966
+ const selectedSalePrice = createMemo(() => {
3967
+ const p = product();
3968
+ const base = selectedPrice();
3969
+ if (!p || base == null || !p.activeSale) return null;
3970
+ if (p.salePriceCents != null && p.price != null && p.price > 0) {
3971
+ const ratio = p.salePriceCents / Math.round(p.price * 100);
3972
+ return Math.max(0, base * ratio);
3973
+ }
3974
+ return Math.max(0, base - p.activeSale.discountCents / 100);
3975
+ });
3976
+ const inCart = createMemo(() => {
3977
+ const p = product();
3978
+ if (!p) return false;
3979
+ const dosage = selectedDosage() || (dosageOptions()[0]?.dosage ?? "");
3980
+ const key = cart_default.itemKey(p.id, dosage);
3981
+ return cart_default.items().some((i) => cart_default.itemKey(i.productId, i.dosage) === key);
3982
+ });
3983
+ function addToCart() {
3984
+ const p = product();
3985
+ if (!p) return;
3986
+ const dosage = selectedDosage() || (dosageOptions()[0]?.dosage ?? "");
3987
+ const effective = selectedSalePrice() ?? selectedPrice() ?? 0;
3988
+ const priceCents = Math.round(effective * 100);
3989
+ cart_default.add({
3990
+ productId: p.id,
3991
+ productName: p.name,
3992
+ dosage,
3993
+ quantity: 1,
3994
+ priceCents,
3995
+ drugId: p.id,
3996
+ apexDrugId: p.apex_drug_id ?? null,
3997
+ categories: p.categories ?? [],
3998
+ thumbnailUrl: p.thumbnail_url ?? void 0,
3999
+ hideDoseLabel: pricingMode() === "flat_fee" ? true : void 0,
4000
+ isSubscription: p.is_subscription ? true : void 0
4001
+ });
4002
+ cart_default.open();
4003
+ }
4004
+ return {
4005
+ product,
4006
+ dosageOptions,
4007
+ selectedDosage,
4008
+ setSelectedDosage,
4009
+ selectedPrice,
4010
+ selectedSalePrice,
4011
+ pricingMode,
4012
+ inCart,
4013
+ addToCart
4014
+ };
4015
+ }
4016
+ function useMedicationSelect(options = {}) {
4017
+ const catalog = useCatalog();
4018
+ function selectMedication(product) {
4019
+ medication_default.select({ drugId: product.id, drugName: product.name });
4020
+ options.onSelected?.();
4021
+ }
4022
+ function selectGeneralConsultation() {
4023
+ medication_default.select({
4024
+ drugId: null,
4025
+ drugName: options.generalConsultationLabel ?? "General Consultation"
4026
+ });
4027
+ options.onSelected?.();
4028
+ }
4029
+ return {
4030
+ products: catalog.products,
4031
+ weightLoss: catalog.weightLoss,
4032
+ peptides: catalog.peptides,
4033
+ selectMedication,
4034
+ selectGeneralConsultation
4035
+ };
4036
+ }
4037
+
4038
+ // src/flows/cartReconcile.ts
4039
+ import { createResource as createResource4 } from "solid-js";
4040
+ function snapshotChanged(before, after) {
4041
+ return before.productName !== after.productName || before.priceCents !== after.priceCents || (before.apexDrugId ?? null) !== (after.apexDrugId ?? null) || !!before.isSubscription !== !!after.isSubscription || !!before.hideDoseLabel !== !!after.hideDoseLabel;
4042
+ }
4043
+ function reconcileCartLines(items, products, opts = {}) {
4044
+ const byId = new Map(products.map((p) => [p.id, p]));
4045
+ const kept = [];
4046
+ const dropped = [];
4047
+ const refreshed = [];
4048
+ for (const item of items) {
4049
+ const product = byId.get(item.productId);
4050
+ if (!product) {
4051
+ dropped.push({ item, reason: "unavailable" });
4052
+ continue;
4053
+ }
4054
+ if (opts.requireApexDrug && !product.apex_drug_id) {
4055
+ dropped.push({ item, reason: "not_prescribable" });
4056
+ continue;
4057
+ }
4058
+ const base = priceForDosage(product, item.dosage);
4059
+ if (base == null) {
4060
+ dropped.push({ item, reason: "unpriced" });
4061
+ continue;
4062
+ }
4063
+ const effective = salePriceForBase(product, base) ?? base;
4064
+ const next = {
4065
+ ...item,
4066
+ productName: product.name,
4067
+ priceCents: Math.round(effective * 100),
4068
+ apexDrugId: product.apex_drug_id ?? null,
4069
+ categories: product.categories ?? [],
4070
+ thumbnailUrl: product.thumbnail_url ?? void 0,
4071
+ hideDoseLabel: product.pricing_mode === "flat_fee" ? true : void 0,
4072
+ isSubscription: product.is_subscription ? true : void 0
4073
+ };
4074
+ if (snapshotChanged(item, next)) refreshed.push(next);
4075
+ kept.push(next);
4076
+ }
4077
+ return { items: kept, dropped, refreshed, checked: true };
4078
+ }
4079
+ var UNCHECKED = { items: [], dropped: [], refreshed: [], checked: false };
4080
+ async function reconcileCartAgainstCatalog(opts = {}) {
4081
+ const items = cart_default.items();
4082
+ if (items.length === 0) return { ...UNCHECKED, checked: true };
4083
+ let products;
4084
+ try {
4085
+ products = (await productsApi.list()).products ?? [];
4086
+ } catch {
4087
+ return UNCHECKED;
4088
+ }
4089
+ if (products.length === 0) return UNCHECKED;
4090
+ const result = reconcileCartLines(items, products, opts);
4091
+ if (result.dropped.length > 0 || result.refreshed.length > 0) {
4092
+ cart_default.replace(result.items);
4093
+ }
4094
+ return result;
4095
+ }
4096
+ function useCartReconcile(opts = {}) {
4097
+ const [result] = createResource4(() => reconcileCartAgainstCatalog(opts));
4098
+ return {
4099
+ dropped: () => result()?.dropped ?? [],
4100
+ refreshed: () => result()?.refreshed ?? [],
4101
+ pending: () => result.loading
4102
+ };
4103
+ }
4104
+
3766
4105
  // src/flows/affiliate.ts
3767
- import { createResource as createResource3 } from "solid-js";
4106
+ import { createResource as createResource5 } from "solid-js";
3768
4107
  function useAffiliateStats() {
3769
- const [stats, { refetch }] = createResource3(
4108
+ const [stats, { refetch }] = createResource5(
3770
4109
  () => affiliateAuth_default.isAuthenticated(),
3771
4110
  async (authed) => {
3772
4111
  if (!authed) return null;
@@ -3781,7 +4120,7 @@ function useAffiliateStats() {
3781
4120
  return { stats, refetch: () => refetch() };
3782
4121
  }
3783
4122
  function useAffiliateConversions(opts) {
3784
- const [conversions, { refetch }] = createResource3(
4123
+ const [conversions, { refetch }] = createResource5(
3785
4124
  () => affiliateAuth_default.isAuthenticated(),
3786
4125
  async (authed, _info) => {
3787
4126
  if (!authed) return [];
@@ -3796,7 +4135,7 @@ function useAffiliateConversions(opts) {
3796
4135
  return { conversions, refetch: () => refetch() };
3797
4136
  }
3798
4137
  function useAffiliateDownline() {
3799
- const [downline, { refetch }] = createResource3(
4138
+ const [downline, { refetch }] = createResource5(
3800
4139
  () => affiliateAuth_default.isAuthenticated(),
3801
4140
  async (authed) => {
3802
4141
  if (!authed) return [];
@@ -3811,7 +4150,7 @@ function useAffiliateDownline() {
3811
4150
  return { downline, refetch: () => refetch() };
3812
4151
  }
3813
4152
  function useAffiliateLinks() {
3814
- const [links, { refetch }] = createResource3(
4153
+ const [links, { refetch }] = createResource5(
3815
4154
  () => affiliateAuth_default.isAuthenticated(),
3816
4155
  async (authed) => {
3817
4156
  if (!authed) return null;
@@ -3825,6 +4164,45 @@ function useAffiliateLinks() {
3825
4164
  return { links, refetch: () => refetch() };
3826
4165
  }
3827
4166
 
4167
+ // src/flows/categoryVisual.ts
4168
+ function hashId(id) {
4169
+ let h = 5381;
4170
+ for (let i = 0; i < id.length; i++) h = (h << 5) + h + id.charCodeAt(i) | 0;
4171
+ return Math.abs(h);
4172
+ }
4173
+ var DEFAULT_COLOR_PALETTE = [
4174
+ "#4f46e5",
4175
+ // indigo
4176
+ "#0891b2",
4177
+ // cyan
4178
+ "#0d9488",
4179
+ // teal
4180
+ "#f59e0b",
4181
+ // amber
4182
+ "#e11d48",
4183
+ // rose
4184
+ "#10b981",
4185
+ // emerald
4186
+ "#8b5cf6",
4187
+ // violet
4188
+ "#f97316"
4189
+ // orange
4190
+ ];
4191
+ function categoryColor(id, opts = {}) {
4192
+ const palette = opts.palette ?? DEFAULT_COLOR_PALETTE;
4193
+ if (palette.length === 0) return "currentColor";
4194
+ return palette[hashId(id) % palette.length];
4195
+ }
4196
+ function isCssColorValue(value) {
4197
+ return /^(#[0-9a-f]{3,8}|(rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)\([^;{}()]*\)|var\(--[\w-]+\))$/i.test(
4198
+ value.trim()
4199
+ );
4200
+ }
4201
+ function resolveCategoryColor(category, opts = {}) {
4202
+ const set = category.color?.trim();
4203
+ return set && isCssColorValue(set) ? set : categoryColor(category.id, opts);
4204
+ }
4205
+
3828
4206
  // src/flows/funnel.ts
3829
4207
  var FORWARDED = /* @__PURE__ */ new Set([
3830
4208
  "survey:loaded",
@@ -4087,16 +4465,30 @@ export {
4087
4465
  buildTimeline,
4088
4466
  useMemberPortalData,
4089
4467
  useUpdatePaymentMethodFlow,
4468
+ subscribeToSupportTopic,
4090
4469
  SUPPORT_CATEGORIES,
4091
4470
  categoryLabel,
4092
4471
  isImageAttachment,
4093
4472
  formatConversationTime,
4094
4473
  formatMessageTime,
4095
4474
  useMessagesThread,
4475
+ lowestPrice,
4476
+ salePriceForBase,
4477
+ lowestSalePrice,
4478
+ useCatalog,
4479
+ useProductDetail,
4480
+ useMedicationSelect,
4481
+ reconcileCartLines,
4482
+ reconcileCartAgainstCatalog,
4483
+ useCartReconcile,
4096
4484
  useAffiliateStats,
4097
4485
  useAffiliateConversions,
4098
4486
  useAffiliateDownline,
4099
4487
  useAffiliateLinks,
4488
+ DEFAULT_COLOR_PALETTE,
4489
+ categoryColor,
4490
+ isCssColorValue,
4491
+ resolveCategoryColor,
4100
4492
  createFunnelTelemetry,
4101
4493
  captureFunnelEmail,
4102
4494
  emailGateAnswered,
@@ -4107,4 +4499,4 @@ export {
4107
4499
  useSurveyV2Flow,
4108
4500
  uploadPrescriptionPhoto
4109
4501
  };
4110
- //# sourceMappingURL=HXMLRDIJ.jsx.map
4502
+ //# sourceMappingURL=PA66KUAU.jsx.map
@@ -180,7 +180,8 @@ function Banner(props) {
180
180
  return <div class={`flow-banner flow-banner--${props.variant}`}>{props.children}</div>;
181
181
  }
182
182
  function StatusPill(props) {
183
- const label = () => props.label ?? props.status.charAt(0).toUpperCase() + props.status.slice(1);
183
+ const text = () => props.status === "cancelled" ? "canceled" : props.status;
184
+ const label = () => props.label ?? text().charAt(0).toUpperCase() + text().slice(1);
184
185
  return <span class={`flow-pill flow-pill--${props.status}`}>{label()}</span>;
185
186
  }
186
187
  function Spinner(props) {
@@ -246,4 +247,4 @@ var defaultPrimitives = {
246
247
  export {
247
248
  defaultPrimitives
248
249
  };
249
- //# sourceMappingURL=2OXI5TKO.jsx.map
250
+ //# sourceMappingURL=RSMUKR4J.jsx.map