@apextelemed/partner-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +64 -0
- package/README.md +363 -0
- package/dist/api/index.d.ts +12 -0
- package/dist/api/index.js +8 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/index.jsx +127 -0
- package/dist/cart-CBH8Em8f.d.ts +189 -0
- package/dist/cart-D4mVX_zx.d.ts +66 -0
- package/dist/chunk/2OXI5TKO.jsx +249 -0
- package/dist/chunk/3A3MF7R2.jsx +1 -0
- package/dist/chunk/3VEOP7TZ.jsx +16679 -0
- package/dist/chunk/5XGPFYIJ.js +26 -0
- package/dist/chunk/5XGPFYIJ.js.map +1 -0
- package/dist/chunk/67KHO66G.js +26 -0
- package/dist/chunk/67KHO66G.js.map +1 -0
- package/dist/chunk/6TFBQECC.jsx +135 -0
- package/dist/chunk/AN3WPMEP.js +3 -0
- package/dist/chunk/AN3WPMEP.js.map +1 -0
- package/dist/chunk/DHII7L5Y.js +686 -0
- package/dist/chunk/DHII7L5Y.js.map +1 -0
- package/dist/chunk/DS4E7FAI.js +132 -0
- package/dist/chunk/DS4E7FAI.js.map +1 -0
- package/dist/chunk/DY5BJ6UG.js +1195 -0
- package/dist/chunk/DY5BJ6UG.js.map +1 -0
- package/dist/chunk/E7722UPF.js +378 -0
- package/dist/chunk/E7722UPF.js.map +1 -0
- package/dist/chunk/HLXKWRRW.js +16774 -0
- package/dist/chunk/HLXKWRRW.js.map +1 -0
- package/dist/chunk/I46Y2J5W.jsx +144 -0
- package/dist/chunk/J63XPQP4.jsx +21 -0
- package/dist/chunk/J6KNY37T.js +122 -0
- package/dist/chunk/J6KNY37T.js.map +1 -0
- package/dist/chunk/KNTZTYXE.jsx +3315 -0
- package/dist/chunk/KZZSQ7LP.jsx +409 -0
- package/dist/chunk/L46OKCKG.jsx +733 -0
- package/dist/chunk/LDZIUFDM.jsx +31 -0
- package/dist/chunk/LZWA44KD.js +3 -0
- package/dist/chunk/LZWA44KD.js.map +1 -0
- package/dist/chunk/NVRAOAVV.js +3 -0
- package/dist/chunk/NVRAOAVV.js.map +1 -0
- package/dist/chunk/O3QK7YZR.jsx +1 -0
- package/dist/chunk/UZCST66N.jsx +21 -0
- package/dist/chunk/V42CGY2S.jsx +1229 -0
- package/dist/chunk/YJEHCCLY.js +467 -0
- package/dist/chunk/YJEHCCLY.js.map +1 -0
- package/dist/chunk/ZMOG2IIC.js +3194 -0
- package/dist/chunk/ZMOG2IIC.js.map +1 -0
- package/dist/client-BzSg2DEK.d.ts +1539 -0
- package/dist/config/index.d.ts +55 -0
- package/dist/config/index.js +3 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/index.jsx +11 -0
- package/dist/flows/index.d.ts +1322 -0
- package/dist/flows/index.js +9 -0
- package/dist/flows/index.js.map +1 -0
- package/dist/flows/index.jsx +124 -0
- package/dist/index/index.d.ts +71 -0
- package/dist/index/index.js +15 -0
- package/dist/index/index.js.map +1 -0
- package/dist/index/index.jsx +311 -0
- package/dist/pages/index.d.ts +617 -0
- package/dist/pages/index.js +10 -0
- package/dist/pages/index.js.map +1 -0
- package/dist/pages/index.jsx +50 -0
- package/dist/primitives/default/index.d.ts +6 -0
- package/dist/primitives/default/index.js +3 -0
- package/dist/primitives/default/index.js.map +1 -0
- package/dist/primitives/default/index.jsx +7 -0
- package/dist/primitives/index.d.ts +122 -0
- package/dist/primitives/index.js +3 -0
- package/dist/primitives/index.js.map +1 -0
- package/dist/primitives/index.jsx +9 -0
- package/dist/stores/index.d.ts +48 -0
- package/dist/stores/index.js +6 -0
- package/dist/stores/index.js.map +1 -0
- package/dist/stores/index.jsx +16 -0
- package/dist/surveyV2-BgQHK0GE.d.ts +48 -0
- package/dist/testing/adapter.d.ts +104 -0
- package/dist/testing/adapter.d.ts.map +1 -0
- package/dist/testing/adapter.js +14 -0
- package/dist/testing/adapter.js.map +1 -0
- package/dist/testing/env.d.ts +29 -0
- package/dist/testing/env.d.ts.map +1 -0
- package/dist/testing/env.js +42 -0
- package/dist/testing/env.js.map +1 -0
- package/dist/testing/fixtures.d.ts +70 -0
- package/dist/testing/fixtures.d.ts.map +1 -0
- package/dist/testing/fixtures.js +74 -0
- package/dist/testing/fixtures.js.map +1 -0
- package/dist/testing/index.d.ts +15 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +14 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/mocks.d.ts +53 -0
- package/dist/testing/mocks.d.ts.map +1 -0
- package/dist/testing/mocks.js +90 -0
- package/dist/testing/mocks.js.map +1 -0
- package/dist/testing/seam-suite.d.ts +39 -0
- package/dist/testing/seam-suite.d.ts.map +1 -0
- package/dist/testing/seam-suite.js +196 -0
- package/dist/testing/seam-suite.js.map +1 -0
- package/dist/testing/storage.d.ts +40 -0
- package/dist/testing/storage.d.ts.map +1 -0
- package/dist/testing/storage.js +71 -0
- package/dist/testing/storage.js.map +1 -0
- package/dist/theme/admin.css +579 -0
- package/dist/theme/affiliate.css +191 -0
- package/dist/theme/flow.css +497 -0
- package/dist/theme/index.d.ts +84 -0
- package/dist/theme/index.js +94 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/theme/index.jsx +97 -0
- package/dist/theme/member-portal.css +1762 -0
- package/package.json +199 -0
|
@@ -0,0 +1,733 @@
|
|
|
1
|
+
import {
|
|
2
|
+
adoptCartId,
|
|
3
|
+
fetchCartConfig,
|
|
4
|
+
fetchResumedCart,
|
|
5
|
+
postCartSnapshot,
|
|
6
|
+
readCartToken,
|
|
7
|
+
resetCartId,
|
|
8
|
+
stripCartToken
|
|
9
|
+
} from "./6TFBQECC.jsx";
|
|
10
|
+
import {
|
|
11
|
+
firstAddressError,
|
|
12
|
+
formatCardNumber,
|
|
13
|
+
formatCvv,
|
|
14
|
+
formatExpiry,
|
|
15
|
+
isLive,
|
|
16
|
+
useAddressPair,
|
|
17
|
+
useCardTokenizer,
|
|
18
|
+
validateAddress
|
|
19
|
+
} from "./KNTZTYXE.jsx";
|
|
20
|
+
import {
|
|
21
|
+
auth_default,
|
|
22
|
+
cart_default,
|
|
23
|
+
medication_default
|
|
24
|
+
} from "./KZZSQ7LP.jsx";
|
|
25
|
+
import {
|
|
26
|
+
ApiError,
|
|
27
|
+
newIdempotencyKey,
|
|
28
|
+
productsApi,
|
|
29
|
+
promoCodesApi,
|
|
30
|
+
subscriptionsApi,
|
|
31
|
+
usersApi
|
|
32
|
+
} from "./V42CGY2S.jsx";
|
|
33
|
+
import {
|
|
34
|
+
getConfig
|
|
35
|
+
} from "./LDZIUFDM.jsx";
|
|
36
|
+
|
|
37
|
+
// src/flows/products.ts
|
|
38
|
+
import { createMemo, createResource, createSignal } from "solid-js";
|
|
39
|
+
function priceForDosage(product, dosage) {
|
|
40
|
+
const overlay = (product.dosage_prices ?? []).find((d) => d.dosage === dosage);
|
|
41
|
+
if (overlay && overlay.price != null) return overlay.price;
|
|
42
|
+
return product.price;
|
|
43
|
+
}
|
|
44
|
+
function lowestPrice(product) {
|
|
45
|
+
const available = product.available_dosages ?? [];
|
|
46
|
+
if (available.length === 0) return product.price;
|
|
47
|
+
let min = null;
|
|
48
|
+
for (const dose of available) {
|
|
49
|
+
const p = priceForDosage(product, dose);
|
|
50
|
+
if (p != null && (min == null || p < min)) min = p;
|
|
51
|
+
}
|
|
52
|
+
return min ?? product.price;
|
|
53
|
+
}
|
|
54
|
+
function lowestSalePrice(product, basePrice) {
|
|
55
|
+
if (basePrice == null || !product.activeSale) return null;
|
|
56
|
+
const sale = product.activeSale;
|
|
57
|
+
const baseCents = Math.round(basePrice * 100);
|
|
58
|
+
if (sale.discountCents <= 0) return null;
|
|
59
|
+
if (product.salePriceCents != null && product.price != null && Math.abs(product.price - basePrice) < 1e-3) {
|
|
60
|
+
return product.salePriceCents / 100;
|
|
61
|
+
}
|
|
62
|
+
if (product.price != null && product.salePriceCents != null && product.price > 0) {
|
|
63
|
+
const ratio = product.salePriceCents / Math.round(product.price * 100);
|
|
64
|
+
return Math.max(0, basePrice * ratio);
|
|
65
|
+
}
|
|
66
|
+
return Math.max(0, (baseCents - sale.discountCents) / 100);
|
|
67
|
+
}
|
|
68
|
+
function useCatalog() {
|
|
69
|
+
const [products] = createResource(async () => {
|
|
70
|
+
try {
|
|
71
|
+
const res = await productsApi.list();
|
|
72
|
+
return res.products;
|
|
73
|
+
} catch {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
const weightLoss = () => (products() ?? []).filter((p) => (p.categories ?? []).includes("weight-loss"));
|
|
78
|
+
const peptides = () => (products() ?? []).filter((p) => !(p.categories ?? []).includes("weight-loss"));
|
|
79
|
+
const filterByCategory = (slug) => (products() ?? []).filter((p) => (p.categories ?? []).includes(slug));
|
|
80
|
+
return { products, weightLoss, peptides, filterByCategory };
|
|
81
|
+
}
|
|
82
|
+
function useProductDetail(productId) {
|
|
83
|
+
const [product] = createResource(productId, async (id) => {
|
|
84
|
+
if (!id) return null;
|
|
85
|
+
try {
|
|
86
|
+
const res = await productsApi.list();
|
|
87
|
+
return res.products.find((p) => p.id === id) ?? null;
|
|
88
|
+
} catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
const pricingMode = createMemo(
|
|
93
|
+
() => product()?.pricing_mode ?? "per_dose"
|
|
94
|
+
);
|
|
95
|
+
const dosageOptions = createMemo(() => {
|
|
96
|
+
const p = product();
|
|
97
|
+
if (!p) return [];
|
|
98
|
+
const all = (p.available_dosages ?? []).map((dosage) => {
|
|
99
|
+
const overlay = (p.dosage_prices ?? []).find((d) => d.dosage === dosage);
|
|
100
|
+
const price = overlay && overlay.price != null ? overlay.price : p.price;
|
|
101
|
+
return { dosage, price, savingsPrice: overlay?.savingsPrice ?? null };
|
|
102
|
+
}).filter((o) => o.price != null);
|
|
103
|
+
if (pricingMode() !== "flat_fee" || all.length === 0) return all;
|
|
104
|
+
const override = p.dosage_override;
|
|
105
|
+
const chosen = override && all.find((d) => d.dosage === override) || all[0];
|
|
106
|
+
return [chosen];
|
|
107
|
+
});
|
|
108
|
+
const [selectedDosage, setSelectedDosage] = createSignal("");
|
|
109
|
+
createMemo(() => {
|
|
110
|
+
const opts = dosageOptions();
|
|
111
|
+
if (opts.length > 0 && !selectedDosage()) setSelectedDosage(opts[0].dosage);
|
|
112
|
+
});
|
|
113
|
+
const selectedPrice = createMemo(() => {
|
|
114
|
+
const opts = dosageOptions();
|
|
115
|
+
const chosen = opts.find((d) => d.dosage === selectedDosage());
|
|
116
|
+
if (chosen) return chosen.price;
|
|
117
|
+
return product()?.price ?? null;
|
|
118
|
+
});
|
|
119
|
+
const selectedSalePrice = createMemo(() => {
|
|
120
|
+
const p = product();
|
|
121
|
+
const base = selectedPrice();
|
|
122
|
+
if (!p || base == null || !p.activeSale) return null;
|
|
123
|
+
if (p.salePriceCents != null && p.price != null && p.price > 0) {
|
|
124
|
+
const ratio = p.salePriceCents / Math.round(p.price * 100);
|
|
125
|
+
return Math.max(0, base * ratio);
|
|
126
|
+
}
|
|
127
|
+
return Math.max(0, base - p.activeSale.discountCents / 100);
|
|
128
|
+
});
|
|
129
|
+
const inCart = createMemo(() => {
|
|
130
|
+
const p = product();
|
|
131
|
+
if (!p) return false;
|
|
132
|
+
const dosage = selectedDosage() || (dosageOptions()[0]?.dosage ?? "");
|
|
133
|
+
const key = cart_default.itemKey(p.id, dosage);
|
|
134
|
+
return cart_default.items().some((i) => cart_default.itemKey(i.productId, i.dosage) === key);
|
|
135
|
+
});
|
|
136
|
+
function addToCart() {
|
|
137
|
+
const p = product();
|
|
138
|
+
if (!p) return;
|
|
139
|
+
const dosage = selectedDosage() || (dosageOptions()[0]?.dosage ?? "");
|
|
140
|
+
const effective = selectedSalePrice() ?? selectedPrice() ?? 0;
|
|
141
|
+
const priceCents = Math.round(effective * 100);
|
|
142
|
+
cart_default.add({
|
|
143
|
+
productId: p.id,
|
|
144
|
+
productName: p.name,
|
|
145
|
+
dosage,
|
|
146
|
+
quantity: 1,
|
|
147
|
+
priceCents,
|
|
148
|
+
drugId: p.id,
|
|
149
|
+
apexDrugId: p.apex_drug_id ?? null,
|
|
150
|
+
categories: p.categories ?? [],
|
|
151
|
+
thumbnailUrl: p.thumbnail_url ?? void 0,
|
|
152
|
+
hideDoseLabel: pricingMode() === "flat_fee" ? true : void 0,
|
|
153
|
+
isSubscription: p.is_subscription ? true : void 0
|
|
154
|
+
});
|
|
155
|
+
cart_default.open();
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
product,
|
|
159
|
+
dosageOptions,
|
|
160
|
+
selectedDosage,
|
|
161
|
+
setSelectedDosage,
|
|
162
|
+
selectedPrice,
|
|
163
|
+
selectedSalePrice,
|
|
164
|
+
pricingMode,
|
|
165
|
+
inCart,
|
|
166
|
+
addToCart
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function useMedicationSelect(options = {}) {
|
|
170
|
+
const catalog = useCatalog();
|
|
171
|
+
function selectMedication(product) {
|
|
172
|
+
medication_default.select({ drugId: product.id, drugName: product.name });
|
|
173
|
+
options.onSelected?.();
|
|
174
|
+
}
|
|
175
|
+
function selectGeneralConsultation() {
|
|
176
|
+
medication_default.select({
|
|
177
|
+
drugId: null,
|
|
178
|
+
drugName: options.generalConsultationLabel ?? "General Consultation"
|
|
179
|
+
});
|
|
180
|
+
options.onSelected?.();
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
products: catalog.products,
|
|
184
|
+
weightLoss: catalog.weightLoss,
|
|
185
|
+
peptides: catalog.peptides,
|
|
186
|
+
selectMedication,
|
|
187
|
+
selectGeneralConsultation
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// src/flows/categoryVisual.ts
|
|
192
|
+
function hashId(id) {
|
|
193
|
+
let h = 5381;
|
|
194
|
+
for (let i = 0; i < id.length; i++) h = (h << 5) + h + id.charCodeAt(i) | 0;
|
|
195
|
+
return Math.abs(h);
|
|
196
|
+
}
|
|
197
|
+
var DEFAULT_COLOR_PALETTE = [
|
|
198
|
+
"#4f46e5",
|
|
199
|
+
// indigo
|
|
200
|
+
"#0891b2",
|
|
201
|
+
// cyan
|
|
202
|
+
"#0d9488",
|
|
203
|
+
// teal
|
|
204
|
+
"#f59e0b",
|
|
205
|
+
// amber
|
|
206
|
+
"#e11d48",
|
|
207
|
+
// rose
|
|
208
|
+
"#10b981",
|
|
209
|
+
// emerald
|
|
210
|
+
"#8b5cf6",
|
|
211
|
+
// violet
|
|
212
|
+
"#f97316"
|
|
213
|
+
// orange
|
|
214
|
+
];
|
|
215
|
+
function categoryColor(id, opts = {}) {
|
|
216
|
+
const palette = opts.palette ?? DEFAULT_COLOR_PALETTE;
|
|
217
|
+
if (palette.length === 0) return "currentColor";
|
|
218
|
+
return palette[hashId(id) % palette.length];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// src/flows/subscriptionIntake.ts
|
|
222
|
+
import { createEffect, createSignal as createSignal2, onMount } from "solid-js";
|
|
223
|
+
var DRAFT_TTL_MS = 7 * 24 * 3600 * 1e3;
|
|
224
|
+
var MAX_RESTORABLE_STEP = 1;
|
|
225
|
+
function draftKey() {
|
|
226
|
+
return `${getConfig().storagePrefix}-subscription-intake-draft`;
|
|
227
|
+
}
|
|
228
|
+
function loadDraft() {
|
|
229
|
+
try {
|
|
230
|
+
const raw = localStorage.getItem(draftKey());
|
|
231
|
+
if (!raw) return {};
|
|
232
|
+
const parsed = JSON.parse(raw);
|
|
233
|
+
if (parsed.savedAt && Date.now() - parsed.savedAt > DRAFT_TTL_MS) {
|
|
234
|
+
localStorage.removeItem(draftKey());
|
|
235
|
+
return {};
|
|
236
|
+
}
|
|
237
|
+
return parsed ?? {};
|
|
238
|
+
} catch {
|
|
239
|
+
return {};
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function saveDraft(draft) {
|
|
243
|
+
try {
|
|
244
|
+
localStorage.setItem(draftKey(), JSON.stringify({ ...draft, savedAt: Date.now() }));
|
|
245
|
+
} catch {
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function clearDraft() {
|
|
249
|
+
try {
|
|
250
|
+
localStorage.removeItem(draftKey());
|
|
251
|
+
} catch {
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
function useSubscriptionIntakeFlow(options) {
|
|
255
|
+
const accept = useCardTokenizer();
|
|
256
|
+
let restored = {};
|
|
257
|
+
if (typeof window !== "undefined") restored = loadDraft();
|
|
258
|
+
const [step, setStep] = createSignal2(Math.min(restored.step ?? 0, MAX_RESTORABLE_STEP));
|
|
259
|
+
const [error, setError] = createSignal2(null);
|
|
260
|
+
const [tokenizing, setTokenizing] = createSignal2(false);
|
|
261
|
+
const [submitting, setSubmitting] = createSignal2(false);
|
|
262
|
+
const [outcome, setOutcome] = createSignal2({ kind: "in_progress" });
|
|
263
|
+
const [firstName, setFirstName] = createSignal2(restored.firstName ?? "");
|
|
264
|
+
const [lastName, setLastName] = createSignal2(restored.lastName ?? "");
|
|
265
|
+
const [email, setEmail] = createSignal2(restored.email ?? "");
|
|
266
|
+
const [password, setPassword] = createSignal2("");
|
|
267
|
+
const [dateOfBirth, setDateOfBirth] = createSignal2(restored.dateOfBirth ?? "");
|
|
268
|
+
const [phone, setPhone] = createSignal2(restored.phone ?? "");
|
|
269
|
+
const addr = useAddressPair({
|
|
270
|
+
initialShipping: {
|
|
271
|
+
street: restored.street ?? "",
|
|
272
|
+
city: restored.city ?? "",
|
|
273
|
+
state: restored.state ?? "",
|
|
274
|
+
zip: restored.zip ?? ""
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
const street = () => addr.shipping().street;
|
|
278
|
+
const city = () => addr.shipping().city;
|
|
279
|
+
const state = () => addr.shipping().state;
|
|
280
|
+
const zip = () => addr.shipping().zip;
|
|
281
|
+
const effectiveBillingAddress = () => {
|
|
282
|
+
const b = addr.effectiveBilling();
|
|
283
|
+
return { street: b.street.trim(), city: b.city.trim(), state: b.state, zip: b.zip.trim() };
|
|
284
|
+
};
|
|
285
|
+
const [cardNumberRaw, setCardNumberRaw] = createSignal2("", { equals: false });
|
|
286
|
+
const [expiryRaw, setExpiryRaw] = createSignal2("", { equals: false });
|
|
287
|
+
const [cvvRaw, setCvvRaw] = createSignal2("", { equals: false });
|
|
288
|
+
const [promoCode, setPromoCode] = createSignal2("");
|
|
289
|
+
const [promoValidating, setPromoValidating] = createSignal2(false);
|
|
290
|
+
const [promoError, setPromoError] = createSignal2(null);
|
|
291
|
+
const [promoApplied, setPromoApplied] = createSignal2(null);
|
|
292
|
+
const [idemKey, setIdemKey] = createSignal2(restored.idempotencyKey ?? "");
|
|
293
|
+
onMount(() => {
|
|
294
|
+
createEffect(() => {
|
|
295
|
+
saveDraft({
|
|
296
|
+
step: step(),
|
|
297
|
+
firstName: firstName(),
|
|
298
|
+
lastName: lastName(),
|
|
299
|
+
dateOfBirth: dateOfBirth(),
|
|
300
|
+
email: email(),
|
|
301
|
+
phone: phone(),
|
|
302
|
+
street: street(),
|
|
303
|
+
city: city(),
|
|
304
|
+
state: state(),
|
|
305
|
+
zip: zip(),
|
|
306
|
+
idempotencyKey: idemKey() || void 0
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
onMount(async () => {
|
|
311
|
+
if (!auth_default.isAuthenticated()) return;
|
|
312
|
+
try {
|
|
313
|
+
const res = await subscriptionsApi.list();
|
|
314
|
+
const existing = res?.subscriptions?.find(
|
|
315
|
+
(s) => isLive(s.status) && (options.singleSubscription || s.productId === options.pricing.productId)
|
|
316
|
+
);
|
|
317
|
+
if (existing) {
|
|
318
|
+
clearDraft();
|
|
319
|
+
setOutcome(
|
|
320
|
+
existing.productId === options.pricing.productId ? { kind: "completed" } : { kind: "already_subscribed", productId: existing.productId }
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
} catch {
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
const savingsBaseCents = () => {
|
|
327
|
+
const list = options.pricing.priceCents;
|
|
328
|
+
const savings = options.pricing.savingsPriceCents;
|
|
329
|
+
return options.isSavingsMember?.() && savings != null ? savings : list;
|
|
330
|
+
};
|
|
331
|
+
const pricing = () => {
|
|
332
|
+
const baseCents = savingsBaseCents();
|
|
333
|
+
const promo = promoApplied();
|
|
334
|
+
if (!promo?.valid || !promo.discountCents) {
|
|
335
|
+
return { baseCents, discountCents: 0, finalCents: baseCents };
|
|
336
|
+
}
|
|
337
|
+
const discountCents = Math.min(baseCents, promo.discountCents);
|
|
338
|
+
return {
|
|
339
|
+
baseCents,
|
|
340
|
+
discountCents,
|
|
341
|
+
finalCents: promo.finalCents ?? Math.max(0, baseCents - discountCents),
|
|
342
|
+
promoCode: promo.promoCode?.code
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
async function applyPromo() {
|
|
346
|
+
const code = promoCode().trim();
|
|
347
|
+
if (!code) {
|
|
348
|
+
setPromoError("Enter a promo code.");
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
setPromoError(null);
|
|
352
|
+
setPromoValidating(true);
|
|
353
|
+
try {
|
|
354
|
+
const res = await promoCodesApi.validate(code, {
|
|
355
|
+
productIds: [options.pricing.productId],
|
|
356
|
+
subtotalCents: options.pricing.priceCents
|
|
357
|
+
});
|
|
358
|
+
if (!res.valid) {
|
|
359
|
+
setPromoError(res.error ?? "Invalid promo code.");
|
|
360
|
+
setPromoApplied(null);
|
|
361
|
+
} else {
|
|
362
|
+
setPromoApplied(res);
|
|
363
|
+
setPromoError(null);
|
|
364
|
+
}
|
|
365
|
+
} catch {
|
|
366
|
+
setPromoError("Could not validate promo code. Please try again.");
|
|
367
|
+
setPromoApplied(null);
|
|
368
|
+
} finally {
|
|
369
|
+
setPromoValidating(false);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
function clearPromo() {
|
|
373
|
+
setPromoCode("");
|
|
374
|
+
setPromoApplied(null);
|
|
375
|
+
setPromoError(null);
|
|
376
|
+
}
|
|
377
|
+
function validateStep(s) {
|
|
378
|
+
if (s === 0) {
|
|
379
|
+
if (!firstName().trim()) return "First name is required.";
|
|
380
|
+
if (!lastName().trim()) return "Last name is required.";
|
|
381
|
+
if (!auth_default.isAuthenticated()) {
|
|
382
|
+
if (!email().trim()) return "Email is required.";
|
|
383
|
+
if (!password().trim()) return "Password is required.";
|
|
384
|
+
if (password().length < 8) return "Password must be at least 8 characters.";
|
|
385
|
+
}
|
|
386
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(dateOfBirth())) return "Enter a valid date of birth.";
|
|
387
|
+
const dob = /* @__PURE__ */ new Date(dateOfBirth() + "T00:00:00");
|
|
388
|
+
if (Number.isNaN(dob.getTime())) return "Enter a valid date of birth.";
|
|
389
|
+
const age = (Date.now() - dob.getTime()) / (365.25 * 24 * 3600 * 1e3);
|
|
390
|
+
if (age < 18) return "You must be at least 18 to register.";
|
|
391
|
+
if (age > 120) return "Enter a valid date of birth.";
|
|
392
|
+
} else if (s === 1) {
|
|
393
|
+
return firstAddressError(validateAddress(addr.shipping(), "", { enforceAvailability: true }));
|
|
394
|
+
} else if (s === 2) {
|
|
395
|
+
if (!cardNumberRaw().trim()) return "Card number is required.";
|
|
396
|
+
if (!expiryRaw().trim()) return "Expiration date is required.";
|
|
397
|
+
if (!cvvRaw().trim()) return "CVV is required.";
|
|
398
|
+
}
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
async function next() {
|
|
402
|
+
const err = validateStep(step());
|
|
403
|
+
if (err) {
|
|
404
|
+
setError(err);
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
setError(null);
|
|
408
|
+
setStep((s) => s + 1);
|
|
409
|
+
}
|
|
410
|
+
function back() {
|
|
411
|
+
setError(null);
|
|
412
|
+
if (step() > 0) setStep((s) => s - 1);
|
|
413
|
+
}
|
|
414
|
+
async function submit() {
|
|
415
|
+
const finalPricing = pricing();
|
|
416
|
+
const isFree = finalPricing.finalCents === 0;
|
|
417
|
+
if (!isFree) {
|
|
418
|
+
const cardErr = validateStep(2);
|
|
419
|
+
if (cardErr) {
|
|
420
|
+
setError(cardErr);
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
if (addr.billingIsOverride()) {
|
|
424
|
+
const bErr = firstAddressError(validateAddress(addr.billing(), "Billing"));
|
|
425
|
+
if (bErr) {
|
|
426
|
+
setError(bErr);
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
setError(null);
|
|
432
|
+
let opaque;
|
|
433
|
+
if (!isFree) {
|
|
434
|
+
setTokenizing(true);
|
|
435
|
+
setOutcome({ kind: "tokenizing" });
|
|
436
|
+
try {
|
|
437
|
+
opaque = await accept.tokenize({
|
|
438
|
+
cardNumber: cardNumberRaw(),
|
|
439
|
+
expiry: expiryRaw(),
|
|
440
|
+
cvv: cvvRaw()
|
|
441
|
+
});
|
|
442
|
+
} catch (e) {
|
|
443
|
+
setError(e instanceof Error ? e.message : "Card tokenization failed.");
|
|
444
|
+
setTokenizing(false);
|
|
445
|
+
setOutcome({ kind: "in_progress" });
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
setTokenizing(false);
|
|
449
|
+
}
|
|
450
|
+
setSubmitting(true);
|
|
451
|
+
setOutcome({ kind: "submitting" });
|
|
452
|
+
let idempotencyKey = idemKey();
|
|
453
|
+
if (!idempotencyKey) {
|
|
454
|
+
idempotencyKey = newIdempotencyKey();
|
|
455
|
+
setIdemKey(idempotencyKey);
|
|
456
|
+
}
|
|
457
|
+
try {
|
|
458
|
+
const promo = promoApplied();
|
|
459
|
+
if (auth_default.isAuthenticated()) {
|
|
460
|
+
await usersApi.updateProfile({
|
|
461
|
+
firstName: firstName().trim(),
|
|
462
|
+
lastName: lastName().trim(),
|
|
463
|
+
dateOfBirth: dateOfBirth(),
|
|
464
|
+
phone: phone().trim() || void 0,
|
|
465
|
+
address1: street().trim(),
|
|
466
|
+
city: city().trim(),
|
|
467
|
+
state: state(),
|
|
468
|
+
zip: zip().trim()
|
|
469
|
+
});
|
|
470
|
+
const res = await subscriptionsApi.create({
|
|
471
|
+
opaqueData: opaque,
|
|
472
|
+
amountCents: finalPricing.baseCents,
|
|
473
|
+
intervalDays: options.intervalDays ?? 30,
|
|
474
|
+
billingAddress: effectiveBillingAddress(),
|
|
475
|
+
products: [{
|
|
476
|
+
productId: options.pricing.productId,
|
|
477
|
+
productName: options.pricing.productName,
|
|
478
|
+
quantity: 1,
|
|
479
|
+
dosage: options.surveyResult.dosage
|
|
480
|
+
}],
|
|
481
|
+
productId: options.pricing.productId,
|
|
482
|
+
promoCode: promo?.valid ? promo.promoCode?.code : void 0,
|
|
483
|
+
metadata: {
|
|
484
|
+
drugId: options.surveyResult.drugId,
|
|
485
|
+
selectedDosage: options.surveyResult.dosage,
|
|
486
|
+
caseNotes: options.surveyResult.caseNotes,
|
|
487
|
+
v2SurveyResponseId: options.surveyResult.v2SurveyResponseId
|
|
488
|
+
}
|
|
489
|
+
}, { idempotencyKey });
|
|
490
|
+
if (res.error) {
|
|
491
|
+
throw new Error(res.error || "Subscription failed. Please try again.");
|
|
492
|
+
}
|
|
493
|
+
} else {
|
|
494
|
+
await auth_default.signupAndSubscribe({
|
|
495
|
+
email: email().trim(),
|
|
496
|
+
password: password(),
|
|
497
|
+
member: {
|
|
498
|
+
firstName: firstName().trim(),
|
|
499
|
+
lastName: lastName().trim(),
|
|
500
|
+
dateOfBirth: dateOfBirth(),
|
|
501
|
+
phone: phone().trim() || void 0,
|
|
502
|
+
address1: street().trim(),
|
|
503
|
+
city: city().trim(),
|
|
504
|
+
state: state(),
|
|
505
|
+
zip: zip().trim()
|
|
506
|
+
},
|
|
507
|
+
opaqueData: opaque,
|
|
508
|
+
amountCents: finalPricing.baseCents,
|
|
509
|
+
intervalDays: options.intervalDays ?? 30,
|
|
510
|
+
medication: options.surveyResult.drugId,
|
|
511
|
+
products: [{
|
|
512
|
+
productId: options.pricing.productId,
|
|
513
|
+
productName: options.pricing.productName,
|
|
514
|
+
quantity: 1,
|
|
515
|
+
dosage: options.surveyResult.dosage
|
|
516
|
+
}],
|
|
517
|
+
billingAddress: effectiveBillingAddress(),
|
|
518
|
+
surveyResponseId: options.surveyResult.surveyResponseId,
|
|
519
|
+
v2SurveyResponseId: options.surveyResult.v2SurveyResponseId,
|
|
520
|
+
caseNotes: options.surveyResult.caseNotes,
|
|
521
|
+
promoCode: promo?.valid ? promo.promoCode?.code : void 0
|
|
522
|
+
}, { idempotencyKey });
|
|
523
|
+
}
|
|
524
|
+
clearDraft();
|
|
525
|
+
setOutcome({ kind: "completed" });
|
|
526
|
+
} catch (err) {
|
|
527
|
+
if (err instanceof ApiError && err.code === "SUBSCRIPTION_EXISTS") {
|
|
528
|
+
clearDraft();
|
|
529
|
+
setOutcome({ kind: "already_subscribed" });
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
const maybeCommitted = err instanceof ApiError && err.ambiguous;
|
|
533
|
+
if (!maybeCommitted) setIdemKey(newIdempotencyKey());
|
|
534
|
+
setError(err instanceof Error ? err.message : "Registration failed. Please try again.");
|
|
535
|
+
setOutcome({ kind: "in_progress" });
|
|
536
|
+
} finally {
|
|
537
|
+
setSubmitting(false);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
return {
|
|
541
|
+
step,
|
|
542
|
+
stepCount: 3,
|
|
543
|
+
next,
|
|
544
|
+
back,
|
|
545
|
+
outcome,
|
|
546
|
+
error,
|
|
547
|
+
submitting,
|
|
548
|
+
tokenizing,
|
|
549
|
+
tokenizerReady: accept.ready,
|
|
550
|
+
acceptJsReady: accept.ready,
|
|
551
|
+
tokenizerError: accept.error,
|
|
552
|
+
acceptJsError: accept.error,
|
|
553
|
+
firstName,
|
|
554
|
+
setFirstName,
|
|
555
|
+
lastName,
|
|
556
|
+
setLastName,
|
|
557
|
+
email,
|
|
558
|
+
setEmail,
|
|
559
|
+
password,
|
|
560
|
+
setPassword,
|
|
561
|
+
dateOfBirth,
|
|
562
|
+
setDateOfBirth,
|
|
563
|
+
phone,
|
|
564
|
+
setPhone,
|
|
565
|
+
address: addr,
|
|
566
|
+
cardNumber: cardNumberRaw,
|
|
567
|
+
setCardNumber: (v) => setCardNumberRaw(formatCardNumber(v)),
|
|
568
|
+
expiry: expiryRaw,
|
|
569
|
+
setExpiry: (v) => setExpiryRaw(formatExpiry(v)),
|
|
570
|
+
cvv: cvvRaw,
|
|
571
|
+
setCvv: (v) => setCvvRaw(formatCvv(v)),
|
|
572
|
+
promoCode,
|
|
573
|
+
setPromoCode,
|
|
574
|
+
promoValidating,
|
|
575
|
+
promoError,
|
|
576
|
+
promoApplied,
|
|
577
|
+
applyPromo,
|
|
578
|
+
clearPromo,
|
|
579
|
+
pricing,
|
|
580
|
+
surveyResult: options.surveyResult,
|
|
581
|
+
medication: options.pricing,
|
|
582
|
+
submit
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// src/flows/cartCapture.ts
|
|
587
|
+
import { createEffect as createEffect2, createRoot, on } from "solid-js";
|
|
588
|
+
function toSnapshotLines(items) {
|
|
589
|
+
return items.map((i) => ({
|
|
590
|
+
productId: i.productId,
|
|
591
|
+
...i.dosage ? { dosage: i.dosage } : {},
|
|
592
|
+
quantity: i.quantity || 1
|
|
593
|
+
}));
|
|
594
|
+
}
|
|
595
|
+
function applyResumedCart(resumed) {
|
|
596
|
+
cart_default.clear();
|
|
597
|
+
for (const line of resumed.items) {
|
|
598
|
+
cart_default.add({
|
|
599
|
+
productId: line.productId,
|
|
600
|
+
productName: line.name,
|
|
601
|
+
dosage: line.dosage ?? "",
|
|
602
|
+
quantity: 1,
|
|
603
|
+
// The sale price when one is running — same figure the catalog shows.
|
|
604
|
+
priceCents: line.salePriceCents ?? line.priceCents,
|
|
605
|
+
drugId: line.productId,
|
|
606
|
+
apexDrugId: line.apexDrugId,
|
|
607
|
+
categories: line.categories,
|
|
608
|
+
thumbnailUrl: line.thumbnailUrl ?? void 0,
|
|
609
|
+
hideDoseLabel: line.hideDoseLabel || void 0,
|
|
610
|
+
isSubscription: line.isSubscription || void 0
|
|
611
|
+
});
|
|
612
|
+
if (line.quantity > 1) {
|
|
613
|
+
cart_default.setQuantity(cart_default.itemKey(line.productId, line.dosage ?? ""), line.quantity);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
async function restorePromo(resumed) {
|
|
618
|
+
if (!resumed.promoCode) return;
|
|
619
|
+
try {
|
|
620
|
+
const res = await promoCodesApi.validate(resumed.promoCode, {
|
|
621
|
+
productIds: resumed.items.map((i) => i.productId),
|
|
622
|
+
subtotalCents: resumed.subtotalCents
|
|
623
|
+
});
|
|
624
|
+
if (!res.valid || !res.promoCode) return;
|
|
625
|
+
cart_default.setPromo({
|
|
626
|
+
code: res.promoCode.code,
|
|
627
|
+
discountType: res.promoCode.discountType,
|
|
628
|
+
discountValueCents: res.promoCode.discountValueCents,
|
|
629
|
+
discountCents: res.discountCents ?? 0
|
|
630
|
+
});
|
|
631
|
+
} catch {
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
var restoreInFlight = null;
|
|
635
|
+
function restoreCartFromLink() {
|
|
636
|
+
if (!restoreInFlight) {
|
|
637
|
+
restoreInFlight = runRestore().finally(() => {
|
|
638
|
+
restoreInFlight = null;
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
return restoreInFlight;
|
|
642
|
+
}
|
|
643
|
+
async function runRestore() {
|
|
644
|
+
const token = readCartToken();
|
|
645
|
+
if (!token) return null;
|
|
646
|
+
const resumed = await fetchResumedCart(token);
|
|
647
|
+
stripCartToken();
|
|
648
|
+
if (!resumed) return null;
|
|
649
|
+
adoptCartId(resumed.cartId);
|
|
650
|
+
applyResumedCart(resumed);
|
|
651
|
+
void restorePromo(resumed);
|
|
652
|
+
return resumed;
|
|
653
|
+
}
|
|
654
|
+
var running = false;
|
|
655
|
+
function startCartCapture(opts = {}) {
|
|
656
|
+
if (running) return () => {
|
|
657
|
+
};
|
|
658
|
+
running = true;
|
|
659
|
+
const debounceMs = opts.debounceMs ?? 2e3;
|
|
660
|
+
let enabled = null;
|
|
661
|
+
let pending = null;
|
|
662
|
+
let timer;
|
|
663
|
+
let lastSentEmpty = true;
|
|
664
|
+
function flush() {
|
|
665
|
+
if (timer) clearTimeout(timer);
|
|
666
|
+
timer = void 0;
|
|
667
|
+
const items = pending;
|
|
668
|
+
pending = null;
|
|
669
|
+
if (!items || enabled !== true) return;
|
|
670
|
+
if (items.length === 0) {
|
|
671
|
+
if (lastSentEmpty) return;
|
|
672
|
+
postCartSnapshot({ items: [], promoCode: null });
|
|
673
|
+
resetCartId();
|
|
674
|
+
lastSentEmpty = true;
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
postCartSnapshot({
|
|
678
|
+
items: toSnapshotLines(items),
|
|
679
|
+
promoCode: cart_default.appliedPromo()?.code ?? null,
|
|
680
|
+
email: opts.email?.() ?? null
|
|
681
|
+
});
|
|
682
|
+
lastSentEmpty = false;
|
|
683
|
+
}
|
|
684
|
+
function schedule(ms) {
|
|
685
|
+
if (timer) clearTimeout(timer);
|
|
686
|
+
timer = setTimeout(flush, ms);
|
|
687
|
+
}
|
|
688
|
+
const dispose = createRoot((disposeRoot) => {
|
|
689
|
+
createEffect2(
|
|
690
|
+
on(
|
|
691
|
+
cart_default.items,
|
|
692
|
+
(items) => {
|
|
693
|
+
pending = items;
|
|
694
|
+
if (enabled === true) schedule(debounceMs);
|
|
695
|
+
},
|
|
696
|
+
{ defer: true }
|
|
697
|
+
)
|
|
698
|
+
);
|
|
699
|
+
return disposeRoot;
|
|
700
|
+
});
|
|
701
|
+
void fetchCartConfig().then((cfg) => {
|
|
702
|
+
enabled = cfg.snapshot;
|
|
703
|
+
if (!enabled) return;
|
|
704
|
+
void restoreCartFromLink();
|
|
705
|
+
if (pending) schedule(0);
|
|
706
|
+
});
|
|
707
|
+
const onPageHide = () => flush();
|
|
708
|
+
if (typeof window !== "undefined" && typeof window.addEventListener === "function") {
|
|
709
|
+
window.addEventListener("pagehide", onPageHide);
|
|
710
|
+
}
|
|
711
|
+
return () => {
|
|
712
|
+
if (timer) clearTimeout(timer);
|
|
713
|
+
if (typeof window !== "undefined" && typeof window.removeEventListener === "function") {
|
|
714
|
+
window.removeEventListener("pagehide", onPageHide);
|
|
715
|
+
}
|
|
716
|
+
dispose();
|
|
717
|
+
running = false;
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
export {
|
|
722
|
+
lowestPrice,
|
|
723
|
+
lowestSalePrice,
|
|
724
|
+
useCatalog,
|
|
725
|
+
useProductDetail,
|
|
726
|
+
useMedicationSelect,
|
|
727
|
+
DEFAULT_COLOR_PALETTE,
|
|
728
|
+
categoryColor,
|
|
729
|
+
useSubscriptionIntakeFlow,
|
|
730
|
+
restoreCartFromLink,
|
|
731
|
+
startCartCapture
|
|
732
|
+
};
|
|
733
|
+
//# sourceMappingURL=L46OKCKG.jsx.map
|