@apextelemed/partner-core 0.15.0 → 0.16.0-dev.44

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 (42) hide show
  1. package/dist/api/index.d.ts +1 -1
  2. package/dist/api/index.js +3 -3
  3. package/dist/api/index.jsx +5 -3
  4. package/dist/chunk/{JOPX73FC.jsx → 2RWPQQ4A.jsx} +5 -5
  5. package/dist/chunk/{WDB3G3X3.js → 46MIDHRD.js} +3 -3
  6. package/dist/chunk/{WDB3G3X3.js.map → 46MIDHRD.js.map} +1 -1
  7. package/dist/chunk/{DLP3Q3AT.js → AM5HSKWG.js} +6 -6
  8. package/dist/chunk/{DLP3Q3AT.js.map → AM5HSKWG.js.map} +1 -1
  9. package/dist/chunk/{OLSTMCLZ.jsx → AO3N6VTS.jsx} +24 -1
  10. package/dist/chunk/{YYWHDAAF.js → CXMAV5SC.js} +3 -3
  11. package/dist/chunk/{YYWHDAAF.js.map → CXMAV5SC.js.map} +1 -1
  12. package/dist/chunk/{CWPXPAUD.js → E6KLEFN3.js} +586 -6
  13. package/dist/chunk/E6KLEFN3.js.map +1 -0
  14. package/dist/chunk/{5ZJ7NC4S.jsx → HYN2BVTH.jsx} +2225 -1352
  15. package/dist/chunk/{CCRVBJ6A.jsx → KK36ZETG.jsx} +2 -2
  16. package/dist/chunk/{NCK4UJHA.jsx → MMPKHKIU.jsx} +2 -2
  17. package/dist/chunk/{NSWRAFQE.js → MPW4IVPB.js} +2533 -1132
  18. package/dist/chunk/MPW4IVPB.js.map +1 -0
  19. package/dist/chunk/{ZYHXLSJA.js → NEV5KNPS.js} +25 -3
  20. package/dist/chunk/NEV5KNPS.js.map +1 -0
  21. package/dist/chunk/{VECSCRAK.jsx → ONYGQYUN.jsx} +608 -5
  22. package/dist/chunk/{2LWM2YSR.jsx → RF6RWN3P.jsx} +2 -2
  23. package/dist/chunk/{IBGYHU26.js → RGFD2T3K.js} +3 -3
  24. package/dist/chunk/{IBGYHU26.js.map → RGFD2T3K.js.map} +1 -1
  25. package/dist/{client-B07yeMS8.d.ts → client-oZcZn-HB.d.ts} +178 -1
  26. package/dist/flows/index.d.ts +300 -2
  27. package/dist/flows/index.js +6 -6
  28. package/dist/flows/index.jsx +44 -6
  29. package/dist/index/index.d.ts +2 -2
  30. package/dist/index/index.js +7 -7
  31. package/dist/index/index.jsx +47 -7
  32. package/dist/pages/index.d.ts +1 -1
  33. package/dist/pages/index.js +5 -5
  34. package/dist/pages/index.jsx +5 -5
  35. package/dist/stores/index.d.ts +1 -1
  36. package/dist/stores/index.js +2 -2
  37. package/dist/stores/index.jsx +2 -2
  38. package/dist/theme/admin.css +95 -0
  39. package/package.json +1 -1
  40. package/dist/chunk/CWPXPAUD.js.map +0 -1
  41. package/dist/chunk/NSWRAFQE.js.map +0 -1
  42. package/dist/chunk/ZYHXLSJA.js.map +0 -1
@@ -6,18 +6,19 @@ import {
6
6
  readResumeToken,
7
7
  saveFunnelDraft,
8
8
  stripResumeToken
9
- } from "./NCK4UJHA.jsx";
9
+ } from "./MMPKHKIU.jsx";
10
10
  import {
11
11
  affiliateAuth_default,
12
12
  auth_default,
13
13
  cart_default,
14
14
  medication_default
15
- } from "./CCRVBJ6A.jsx";
15
+ } from "./KK36ZETG.jsx";
16
16
  import {
17
17
  ApiError,
18
18
  addressesApi,
19
19
  adminApi,
20
20
  adminCatalogApi,
21
+ adminCatalogConversionApi,
21
22
  affiliatePortalApi,
22
23
  apexApi,
23
24
  authApi,
@@ -31,7 +32,7 @@ import {
31
32
  subscriptionsApi,
32
33
  supportApi,
33
34
  usersApi
34
- } from "./OLSTMCLZ.jsx";
35
+ } from "./AO3N6VTS.jsx";
35
36
  import {
36
37
  getConfig
37
38
  } from "./QVZ7BRNO.jsx";
@@ -5305,6 +5306,589 @@ async function createCatalogProduct(input) {
5305
5306
  };
5306
5307
  }
5307
5308
 
5309
+ // src/flows/catalogConversion.ts
5310
+ import { createEffect as createEffect10, createMemo as createMemo3, createSignal as createSignal14, on as on4, onCleanup as onCleanup4 } from "solid-js";
5311
+ function canOfferConversion(product) {
5312
+ const id = product.apexDrugId;
5313
+ return typeof id === "string" && id.length > 0 && !isCatalogItemId(id) && !product.catalogOverlay;
5314
+ }
5315
+ var messageOf2 = (err, fallback) => err instanceof Error && err.message ? err.message : fallback;
5316
+ function classifyConversionError(err) {
5317
+ const e = err ?? {};
5318
+ const status = typeof e.status === "number" ? e.status : void 0;
5319
+ const code = typeof e.code === "string" ? e.code : void 0;
5320
+ const message = messageOf2(err, "Something went wrong talking to the server.");
5321
+ if (status === 409 && code === "plan_changed") return { kind: "plan_changed", message };
5322
+ if (status === 409 && code === "conversion_in_progress") return { kind: "in_progress", message };
5323
+ if (e.ambiguous === true || status === void 0 || status >= 500) {
5324
+ return { kind: "ambiguous", message, serverFinished: code !== void 0, ...code ? { code } : {} };
5325
+ }
5326
+ return { kind: "refused", message, status, ...code ? { code } : {} };
5327
+ }
5328
+ var FINDING_TITLES = {
5329
+ // Blockers — each says what to do.
5330
+ renewal_in_flight: "A refill is being processed for this product \u2014 try again in a few minutes.",
5331
+ drug_list_mode_not_mixed: "Your prescribing platform doesn't support moving one product at a time yet.",
5332
+ product_not_prescribed: "This product isn't prescribed through your prescribing platform, so there is nothing to convert.",
5333
+ already_on_catalog: "This product is already on a catalog item, so there is nothing to convert.",
5334
+ apex_not_configured: "This site isn't linked to your prescribing platform yet.",
5335
+ could_not_read: "We couldn't read everything needed to check this product. Try again in a moment.",
5336
+ products_share_pointer: "Another product uses the same prescribing-platform drug. Give each product its own before converting.",
5337
+ duplicate_dose_price_entries: "Two of this product\u2019s prices have the same strength and link. Remove the duplicate, then try again.",
5338
+ ambiguous_target_item: "More than one catalog item already uses this drug. Leave it on exactly one, then try again.",
5339
+ conversion_item_incomplete: "A catalog item created for this product earlier is missing its pharmacy drug.",
5340
+ target_item_not_listed: "The catalog item isn't showing up on your prescribing platform yet.",
5341
+ target_item_unfillable: "No pharmacy is switched on for the catalog item, so orders for it would be refused.",
5342
+ renewal_line_without_product: "Some refills of this product can\u2019t be matched back to it.",
5343
+ subscription_product_id_not_a_product: "Some subscriptions point at a drug id instead of this product.",
5344
+ // Warnings.
5345
+ dose_price_orphaned: "Some prices won't carry over (they stay on file but are never sold).",
5346
+ strength_needs_price: "Some new strengths will have no price until you set one.",
5347
+ strength_priced_from_base: "Some new strengths will sell at the product's base price.",
5348
+ subscriber_dose_unmapped: "Some subscribers will be flagged for review at their next renewal.",
5349
+ price_entries_share_strength: "More than one price is matched to the same strength.",
5350
+ open_request_at_cutover: "Some prescription requests are still open.",
5351
+ legacy_drug_already_hidden: "This product's strengths are already hidden in your store.",
5352
+ clinical_item_needs_manual_matches: "This item uses clinical doses, so nothing is suggested \u2014 choose each match yourself.",
5353
+ continuity_fulfillment_disabled: "The pharmacy this product's patients use is switched off on the new item.",
5354
+ apex_readiness_warning: "Your prescribing platform reports setup warnings for the new item.",
5355
+ conversion_incomplete_strengths_hidden: "A conversion didn't finish, so this product's strengths are hidden.",
5356
+ converted_item_not_listed: "This product's catalog item isn't listed, so it can't be sold."
5357
+ };
5358
+ var MATCH_DEPENDENT_WARNINGS = [
5359
+ "dose_price_orphaned",
5360
+ "strength_needs_price",
5361
+ "strength_priced_from_base",
5362
+ "subscriber_dose_unmapped",
5363
+ "price_entries_share_strength"
5364
+ ];
5365
+ function explainFinding(finding) {
5366
+ return { title: FINDING_TITLES[finding.code] ?? null, message: finding.message };
5367
+ }
5368
+ var sourceKey = (source) => JSON.stringify([source.dosage ?? null, source.apexSkuId ?? null]);
5369
+ function sourceLabel(source) {
5370
+ if (source.dosage) return source.dosage;
5371
+ if (source.field === "apex_sku_id") return "Single-dose product";
5372
+ return "Unlabelled strength";
5373
+ }
5374
+ var SOURCE_FIELD_NOTE = {
5375
+ dosage_prices: null,
5376
+ apex_sku_id: "This product\u2019s single linked strength",
5377
+ subscriber_dose: "No price \u2014 only subscribers hold this strength"
5378
+ };
5379
+ var MATCH_HOW_LABEL = {
5380
+ source_sku: "Matched by the pharmacy pack it replaces",
5381
+ exact_label: "Matched by identical name",
5382
+ already_bound: "Already linked to this strength"
5383
+ };
5384
+ var liveDoses = (preview) => preview.doses.filter((d) => d.live);
5385
+ function canLeaveUnmatched(match, doses) {
5386
+ const { source } = match;
5387
+ if (source.field === "apex_sku_id" || source.alsoKeysApexSkuId) return false;
5388
+ if (!source.apexSkuId && source.dosage && doses.some((d) => d.live && d.label === source.dosage)) return false;
5389
+ return true;
5390
+ }
5391
+ function initialMatches(preview) {
5392
+ const out = {};
5393
+ for (const m of preview.doseMatches) if (m.suggestedDoseId) out[sourceKey(m.source)] = m.suggestedDoseId;
5394
+ return out;
5395
+ }
5396
+ function matchProblem(match, choice, doses) {
5397
+ if (choice === void 0) return "undecided";
5398
+ if (choice === null) return canLeaveUnmatched(match, doses) ? null : "cannot_be_left";
5399
+ return doses.some((d) => d.live && d.id === choice) ? null : "not_offered";
5400
+ }
5401
+ var matchesComplete = (preview, matches) => preview.doseMatches.every((m) => matchProblem(m, matches[sourceKey(m.source)], preview.doses) === null);
5402
+ function toChoices(preview, matches) {
5403
+ if (!matchesComplete(preview, matches)) return null;
5404
+ return preview.doseMatches.map((m) => ({
5405
+ source: { dosage: m.source.dosage, apexSkuId: m.source.apexSkuId },
5406
+ doseId: matches[sourceKey(m.source)] ?? null
5407
+ }));
5408
+ }
5409
+ function flaggedSubscribers(preview, matches) {
5410
+ return preview.doseMatches.filter((m) => m.source.subscriberCount > 0 && matches[sourceKey(m.source)] === null).map((m) => ({ source: m.source, subscribers: m.source.subscriberCount }));
5411
+ }
5412
+ function describeConversion(preview, matches, basePrice) {
5413
+ const doses = liveDoses(preview);
5414
+ const labelOfDose = (id) => doses.find((d) => d.id === id)?.label ?? id;
5415
+ const carried = [];
5416
+ const left = [];
5417
+ for (const m of preview.doseMatches) {
5418
+ const choice = matches[sourceKey(m.source)];
5419
+ const label = sourceLabel(m.source);
5420
+ if (typeof choice === "string") {
5421
+ carried.push({ label, price: m.source.price, doseLabel: labelOfDose(choice), subscribers: m.source.subscriberCount });
5422
+ } else if (choice === null) {
5423
+ left.push({ label, price: m.source.price, subscribers: m.source.subscriberCount });
5424
+ }
5425
+ }
5426
+ const flat = preview.product.pricingMode === "flat_fee";
5427
+ const strengthsAfter = doses.map((d) => {
5428
+ const own = flat ? null : preview.doseMatches.find(
5429
+ (m) => m.source.field === "dosage_prices" && m.source.price != null && matches[sourceKey(m.source)] === d.id
5430
+ )?.source.price ?? null;
5431
+ const price = own ?? basePrice;
5432
+ return { label: d.label, doseId: d.id, price, fromBase: own === null && basePrice !== null, needsPrice: price === null };
5433
+ });
5434
+ return {
5435
+ itemId: preview.target?.kind === "existing" ? preview.target.itemId : null,
5436
+ itemName: preview.target?.kind === "existing" ? preview.target.itemName : null,
5437
+ carried,
5438
+ left,
5439
+ flaggedSubscribers: flaggedSubscribers(preview, matches).reduce((n, f) => n + f.subscribers, 0),
5440
+ strengthsAfter
5441
+ };
5442
+ }
5443
+ var ACTIVATION_BLOCKERS = ["drug_list_mode_not_mixed", "could_not_read", "apex_not_configured"];
5444
+ var hasBlockers = (p) => p.blockers.length > 0;
5445
+ var hasConversion = (p) => !!p?.conversion;
5446
+ var DEFAULT_POLL_MS = 5e3;
5447
+ var DEFAULT_WATCH_MS = 12e4;
5448
+ var REVIEW_STAGES = ["ready_to_commit", "active_not_committed"];
5449
+ function useCatalogConversion(opts) {
5450
+ const [preview, setPreview] = createSignal14(null);
5451
+ const [phase, setPhase] = createSignal14({ kind: "rest" });
5452
+ const [notice, setNotice] = createSignal14(null);
5453
+ const [matches, setMatches] = createSignal14({});
5454
+ const [matchesPlan, setMatchesPlan] = createSignal14(void 0);
5455
+ const [confirming, setConfirming] = createSignal14(false);
5456
+ const [convertedOrigin, setConvertedOrigin] = createSignal14("existing");
5457
+ const [lastCommit, setLastCommit] = createSignal14(null);
5458
+ let generation = 0;
5459
+ let timer;
5460
+ let announcedConverted = false;
5461
+ let announcedUndone = false;
5462
+ const enabled = () => opts.enabled ? opts.enabled() : true;
5463
+ const productId = () => opts.product().id;
5464
+ const pollMs = () => opts.pollIntervalMs ?? DEFAULT_POLL_MS;
5465
+ const windowMs = () => opts.watchWindowMs ?? DEFAULT_WATCH_MS;
5466
+ const stopTimer = () => {
5467
+ if (timer !== void 0) clearTimeout(timer);
5468
+ timer = void 0;
5469
+ };
5470
+ onCleanup4(() => {
5471
+ generation += 1;
5472
+ stopTimer();
5473
+ });
5474
+ const state = createMemo3(() => {
5475
+ const ph = phase();
5476
+ if (ph.kind === "watching") return { kind: "watching", reason: ph.reason };
5477
+ if (ph.kind !== "rest") return ph;
5478
+ const p = preview();
5479
+ if (!p) return enabled() ? { kind: "loading", reason: "initial" } : { kind: "idle" };
5480
+ switch (p.stage) {
5481
+ case "converted":
5482
+ return { kind: "converted", origin: convertedOrigin() };
5483
+ case "committed_not_active":
5484
+ return p.blockers.some((b) => ACTIVATION_BLOCKERS.includes(b.code)) ? { kind: "blocked" } : { kind: "finish_activation" };
5485
+ case "not_started":
5486
+ return hasBlockers(p) || !p.eligible ? { kind: "blocked" } : { kind: "ready" };
5487
+ case "ready_to_commit":
5488
+ case "active_not_committed":
5489
+ return hasBlockers(p) || !p.eligible ? { kind: "blocked" } : { kind: "reviewing", unfinished: p.stage === "active_not_committed", confirming: confirming() };
5490
+ default:
5491
+ return { kind: "blocked" };
5492
+ }
5493
+ });
5494
+ const busy = () => {
5495
+ const k = phase().kind;
5496
+ return k === "loading" || k === "preparing" || k === "committing" || k === "undoing" || k === "watching";
5497
+ };
5498
+ const adopt = (p) => {
5499
+ setPreview(p);
5500
+ if (p.planHash !== matchesPlan()) {
5501
+ setMatches(initialMatches(p));
5502
+ setMatchesPlan(p.planHash);
5503
+ setConfirming(false);
5504
+ }
5505
+ };
5506
+ const readPreview = () => adminCatalogConversionApi.preview(productId());
5507
+ const load = async (reason) => {
5508
+ const gen = ++generation;
5509
+ stopTimer();
5510
+ setPhase({ kind: "loading", reason });
5511
+ try {
5512
+ const p = await readPreview();
5513
+ if (gen !== generation) return false;
5514
+ adopt(p);
5515
+ setPhase({ kind: "rest" });
5516
+ return true;
5517
+ } catch (err) {
5518
+ if (gen !== generation) return false;
5519
+ const failure = classifyConversionError(err);
5520
+ const status = err?.status;
5521
+ setPhase({
5522
+ kind: "unreadable",
5523
+ afterWrite: false,
5524
+ message: status === 404 && !err.code ? "This site's backend doesn't support converting products yet." : failure.message
5525
+ });
5526
+ return false;
5527
+ }
5528
+ };
5529
+ const reload = async () => {
5530
+ if (!enabled()) return;
5531
+ await load(preview() ? "refresh" : "initial");
5532
+ };
5533
+ const identity = createMemo3(() => `${opts.product().id}|${enabled()}`);
5534
+ createEffect10(
5535
+ on4(identity, () => {
5536
+ generation += 1;
5537
+ stopTimer();
5538
+ setPreview(null);
5539
+ setMatches({});
5540
+ setMatchesPlan(void 0);
5541
+ setConfirming(false);
5542
+ setNotice(null);
5543
+ setLastCommit(null);
5544
+ setConvertedOrigin("existing");
5545
+ announcedConverted = false;
5546
+ announcedUndone = false;
5547
+ setPhase(enabled() ? { kind: "loading", reason: "initial" } : { kind: "rest" });
5548
+ if (enabled()) void load("initial");
5549
+ })
5550
+ );
5551
+ const doses = createMemo3(() => {
5552
+ const p = preview();
5553
+ return p ? liveDoses(p) : [];
5554
+ });
5555
+ const rows = createMemo3(() => {
5556
+ const p = preview();
5557
+ if (!p) return [];
5558
+ const chosen = matches();
5559
+ return p.doseMatches.map((m) => {
5560
+ const key = sourceKey(m.source);
5561
+ const choice = chosen[key];
5562
+ return {
5563
+ key,
5564
+ match: m,
5565
+ source: m.source,
5566
+ label: sourceLabel(m.source),
5567
+ choice,
5568
+ changed: choice !== void 0 && choice !== m.suggestedDoseId,
5569
+ canLeaveUnmatched: canLeaveUnmatched(m, p.doses),
5570
+ flagged: m.source.subscriberCount > 0 && choice === null,
5571
+ problem: matchProblem(m, choice, p.doses)
5572
+ };
5573
+ });
5574
+ });
5575
+ const undecidedCount = createMemo3(() => rows().filter((r) => r.choice === void 0).length);
5576
+ const complete = createMemo3(() => {
5577
+ const p = preview();
5578
+ return !!p && matchesComplete(p, matches());
5579
+ });
5580
+ const flagged = createMemo3(() => {
5581
+ const p = preview();
5582
+ return p ? flaggedSubscribers(p, matches()) : [];
5583
+ });
5584
+ const summary = createMemo3(() => {
5585
+ const p = preview();
5586
+ if (!p || p.target?.kind !== "existing") return null;
5587
+ return describeConversion(p, matches(), opts.product().price ?? null);
5588
+ });
5589
+ const reviewing = () => state().kind === "reviewing";
5590
+ const setMatch = (key, choice) => {
5591
+ if (!reviewing() || busy()) return;
5592
+ if (!rows().some((r) => r.key === key)) return;
5593
+ setMatches((prev) => ({ ...prev, [key]: choice }));
5594
+ setConfirming(false);
5595
+ };
5596
+ const leaveUndecidedUnmatched = () => {
5597
+ if (!reviewing() || busy()) return;
5598
+ setMatches((prev) => {
5599
+ const next = { ...prev };
5600
+ for (const r of rows()) if (r.choice === void 0 && r.canLeaveUnmatched) next[r.key] = null;
5601
+ return next;
5602
+ });
5603
+ setConfirming(false);
5604
+ };
5605
+ const resetToSuggestions = () => {
5606
+ const p = preview();
5607
+ if (!p || !reviewing() || busy()) return;
5608
+ setMatches(initialMatches(p));
5609
+ setConfirming(false);
5610
+ };
5611
+ const confirmReview = () => {
5612
+ if (!reviewing() || busy() || !complete()) return false;
5613
+ setConfirming(true);
5614
+ return true;
5615
+ };
5616
+ const backToReview = () => setConfirming(false);
5617
+ const announceConverted = (origin, warnings) => {
5618
+ setConvertedOrigin(origin);
5619
+ if (announcedConverted) return;
5620
+ announcedConverted = true;
5621
+ opts.onConverted?.({ productId: productId(), origin, warnings });
5622
+ };
5623
+ const announceUndone = (result) => {
5624
+ if (announcedUndone) return;
5625
+ announcedUndone = true;
5626
+ opts.onUndone?.({ productId: productId(), result });
5627
+ };
5628
+ const startWatching = (reason, gen) => {
5629
+ setPhase({ kind: "watching", reason, since: Date.now() });
5630
+ stopTimer();
5631
+ timer = setTimeout(() => void poll(gen), pollMs());
5632
+ };
5633
+ const poll = async (gen) => {
5634
+ stopTimer();
5635
+ const w = phase();
5636
+ if (gen !== generation || w.kind !== "watching") return;
5637
+ let read = false;
5638
+ try {
5639
+ const p2 = await readPreview();
5640
+ if (gen !== generation) return;
5641
+ adopt(p2);
5642
+ read = true;
5643
+ } catch {
5644
+ if (gen !== generation) return;
5645
+ }
5646
+ const p = preview();
5647
+ if (read && p?.stage === "converted") {
5648
+ setPhase({ kind: "rest" });
5649
+ setNotice({
5650
+ tone: "success",
5651
+ message: "The conversion finished. The connection dropped while it was running, but it went through."
5652
+ });
5653
+ announceConverted("recovered", []);
5654
+ return;
5655
+ }
5656
+ if (read && p && !REVIEW_STAGES.includes(p.stage)) {
5657
+ setPhase({ kind: "rest" });
5658
+ return;
5659
+ }
5660
+ if (Date.now() - w.since >= windowMs()) {
5661
+ if (!p) {
5662
+ setPhase({
5663
+ kind: "unreadable",
5664
+ afterWrite: true,
5665
+ message: "We couldn't confirm whether the conversion finished. Check again before doing anything else \u2014 nothing will be sent twice."
5666
+ });
5667
+ return;
5668
+ }
5669
+ setPhase({ kind: "rest" });
5670
+ setNotice({
5671
+ tone: "warn",
5672
+ message: p.stage === "active_not_committed" ? "The conversion hasn't finished. Its catalog item is switched on but the product has not been moved, so its strengths are hidden in your store until it completes. Review the strengths and convert again to finish it." : "The conversion hasn't started, and nothing was changed. You can review the strengths and try again."
5673
+ });
5674
+ return;
5675
+ }
5676
+ timer = setTimeout(() => void poll(gen), pollMs());
5677
+ };
5678
+ const checkNow = async () => {
5679
+ const w = phase();
5680
+ if (w.kind !== "watching") return;
5681
+ await poll(generation);
5682
+ };
5683
+ const prepare = async () => {
5684
+ const p = preview();
5685
+ if (state().kind !== "ready" || busy() || !p?.planHash) return;
5686
+ const gen = ++generation;
5687
+ setNotice(null);
5688
+ setPhase({ kind: "preparing" });
5689
+ try {
5690
+ const res = await adminCatalogConversionApi.prepare(productId(), p.planHash);
5691
+ if (gen !== generation) return;
5692
+ adopt(res.preview);
5693
+ setPhase({ kind: "rest" });
5694
+ setNotice({
5695
+ tone: "success",
5696
+ message: res.status === "already_prepared" ? "The catalog item already existed. Nothing was created." : "The catalog item was created and is switched off: nothing is sold from it yet and your product is unchanged."
5697
+ });
5698
+ } catch (err) {
5699
+ if (gen !== generation) return;
5700
+ await afterFailedWrite("prepare", err, gen);
5701
+ }
5702
+ };
5703
+ const runCommit = async (resume, choices, planHash) => {
5704
+ const gen = ++generation;
5705
+ setNotice(null);
5706
+ setConfirming(false);
5707
+ setPhase({ kind: "committing", resume });
5708
+ try {
5709
+ const res = await adminCatalogConversionApi.commit(productId(), { planHash, doseMatches: choices });
5710
+ if (gen !== generation) return;
5711
+ setLastCommit(res);
5712
+ adopt(res.preview);
5713
+ if (res.preview.stage !== "converted") {
5714
+ setPhase({ kind: "rest" });
5715
+ setNotice({
5716
+ tone: "warn",
5717
+ message: "The server reported the conversion done, but the product does not read as converted yet. Check again in a moment."
5718
+ });
5719
+ return;
5720
+ }
5721
+ setPhase({ kind: "rest" });
5722
+ announceConverted("committed", res.warnings ?? []);
5723
+ } catch (err) {
5724
+ if (gen !== generation) return;
5725
+ await afterFailedWrite("commit", err, gen);
5726
+ }
5727
+ };
5728
+ const commit = async () => {
5729
+ const p = preview();
5730
+ const k = state();
5731
+ if (!p?.planHash || k.kind !== "reviewing" || !k.confirming || busy()) return;
5732
+ if (matchesPlan() !== p.planHash) return;
5733
+ const choices = toChoices(p, matches());
5734
+ if (!choices) return;
5735
+ await runCommit("convert", choices, p.planHash);
5736
+ };
5737
+ const finishActivation = async () => {
5738
+ const p = preview();
5739
+ if (!p?.planHash || state().kind !== "finish_activation" || busy()) return;
5740
+ await runCommit("activation", [], p.planHash);
5741
+ };
5742
+ const canUndo = createMemo3(() => hasConversion(preview()) && !busy() && phase().kind === "rest");
5743
+ const undo = async (options = {}) => {
5744
+ if (!canUndo()) return;
5745
+ const gen = ++generation;
5746
+ setNotice(null);
5747
+ setPhase({ kind: "undoing" });
5748
+ try {
5749
+ const res = await adminCatalogConversionApi.undo(productId(), {
5750
+ ...options.deactivateItem ? { deactivateItem: true } : {},
5751
+ ...options.force ? { force: true } : {}
5752
+ });
5753
+ if (gen !== generation) return;
5754
+ setPhase({ kind: "undone", result: res });
5755
+ announceUndone(res);
5756
+ void readPreview().then((p) => {
5757
+ if (gen === generation) adopt(p);
5758
+ }).catch(() => {
5759
+ });
5760
+ } catch (err) {
5761
+ if (gen !== generation) return;
5762
+ await afterFailedWrite("undo", err, gen);
5763
+ }
5764
+ };
5765
+ async function afterFailedWrite(step2, err, gen) {
5766
+ const failure = classifyConversionError(err);
5767
+ const read = await reread(gen);
5768
+ if (gen !== generation) return;
5769
+ if (!read) {
5770
+ setPhase({
5771
+ kind: "unreadable",
5772
+ afterWrite: true,
5773
+ message: `We couldn't confirm what happened: ${failure.message} Check again before doing anything else \u2014 nothing will be sent twice.`
5774
+ });
5775
+ return;
5776
+ }
5777
+ const p = preview();
5778
+ if (failure.kind === "in_progress") {
5779
+ if (step2 === "commit" && p.stage === "converted") {
5780
+ setNotice({ tone: "success", message: "The conversion finished." });
5781
+ announceConverted("recovered", []);
5782
+ return;
5783
+ }
5784
+ if (step2 === "commit") {
5785
+ setNotice({ tone: "info", code: "conversion_in_progress", message: failure.message });
5786
+ startWatching("in_progress", gen);
5787
+ return;
5788
+ }
5789
+ setNotice({ tone: "warn", code: "conversion_in_progress", message: failure.message });
5790
+ return;
5791
+ }
5792
+ if (step2 === "undo") {
5793
+ if (failure.kind === "ambiguous" && !hasConversion(p)) {
5794
+ setPhase({ kind: "undone", result: null });
5795
+ announceUndone(null);
5796
+ setNotice({
5797
+ tone: "warn",
5798
+ message: "The undo went through, but the connection dropped before we got its report, so we can't list what it did not undo. Check the catalog item in the catalog editor: if it is still switched on, this product shows no strengths in your store until it is switched off."
5799
+ });
5800
+ return;
5801
+ }
5802
+ setNotice(
5803
+ failure.kind === "ambiguous" ? {
5804
+ tone: "warn",
5805
+ message: `We couldn't confirm the undo (${failure.message}) and the product still shows as converted, so nothing has changed that we can see. Check again, then try once more.`
5806
+ } : { tone: "danger", ...failure.kind === "refused" && failure.code ? { code: failure.code } : {}, message: failure.message }
5807
+ );
5808
+ return;
5809
+ }
5810
+ if (step2 === "commit" && p.stage === "converted") {
5811
+ setNotice({
5812
+ tone: "success",
5813
+ message: "The conversion went through. The connection dropped before we heard back, but the product is converted."
5814
+ });
5815
+ announceConverted("recovered", []);
5816
+ return;
5817
+ }
5818
+ if (failure.kind === "plan_changed") {
5819
+ setConfirming(false);
5820
+ setNotice({
5821
+ tone: "warn",
5822
+ code: "plan_changed",
5823
+ message: "Something changed while you were reviewing \u2014 the product, its subscribers or the catalog item. Nothing was changed. Review the updated strengths and confirm again."
5824
+ });
5825
+ return;
5826
+ }
5827
+ if (failure.kind === "ambiguous" && !failure.serverFinished && step2 === "commit" && REVIEW_STAGES.includes(p.stage)) {
5828
+ setNotice({
5829
+ tone: "warn",
5830
+ message: "We lost the connection while converting. The server may still be finishing, so we're checking before offering anything else."
5831
+ });
5832
+ startWatching("dropped", gen);
5833
+ return;
5834
+ }
5835
+ setConfirming(false);
5836
+ if (step2 === "prepare" && failure.kind === "ambiguous" && p.target?.kind === "existing") {
5837
+ setNotice({
5838
+ tone: "success",
5839
+ message: "The catalog item was created (the connection dropped before we heard back). It is switched off."
5840
+ });
5841
+ return;
5842
+ }
5843
+ const code = failure.kind === "refused" || failure.kind === "ambiguous" ? failure.code : void 0;
5844
+ setNotice({
5845
+ tone: failure.kind === "ambiguous" ? "warn" : "danger",
5846
+ ...code ? { code } : {},
5847
+ message: code === "blocked" ? "Something now stops this product being converted. Nothing was changed \u2014 see what's in the way below." : failure.kind === "ambiguous" && !failure.serverFinished ? `That didn't go through, and nothing was ${step2 === "prepare" ? "created" : "changed"}. ${failure.message}` : failure.message
5848
+ });
5849
+ }
5850
+ async function reread(gen) {
5851
+ setPhase({ kind: "loading", reason: "reconcile" });
5852
+ try {
5853
+ const p = await readPreview();
5854
+ if (gen !== generation) return false;
5855
+ adopt(p);
5856
+ setPhase({ kind: "rest" });
5857
+ return true;
5858
+ } catch (err) {
5859
+ if (gen !== generation) return false;
5860
+ setPhase({ kind: "unreadable", afterWrite: true, message: messageOf2(err, "We couldn't read the product's state.") });
5861
+ return false;
5862
+ }
5863
+ }
5864
+ return {
5865
+ state,
5866
+ preview,
5867
+ notice,
5868
+ dismissNotice: () => setNotice(null),
5869
+ busy,
5870
+ reload,
5871
+ rows,
5872
+ doses,
5873
+ setMatch,
5874
+ leaveUndecidedUnmatched,
5875
+ resetToSuggestions,
5876
+ undecidedCount,
5877
+ complete,
5878
+ flagged,
5879
+ summary,
5880
+ confirmReview,
5881
+ backToReview,
5882
+ prepare,
5883
+ commit,
5884
+ finishActivation,
5885
+ canUndo,
5886
+ undo,
5887
+ checkNow,
5888
+ lastCommit
5889
+ };
5890
+ }
5891
+
5308
5892
  export {
5309
5893
  isQuestionVisible,
5310
5894
  useSurveyFlow,
@@ -5416,6 +6000,25 @@ export {
5416
6000
  groupDrugsByPharmacy,
5417
6001
  useProductCatalogEditor,
5418
6002
  addCatalogItemAsProduct,
5419
- createCatalogProduct
6003
+ createCatalogProduct,
6004
+ canOfferConversion,
6005
+ classifyConversionError,
6006
+ MATCH_DEPENDENT_WARNINGS,
6007
+ explainFinding,
6008
+ sourceKey,
6009
+ sourceLabel,
6010
+ SOURCE_FIELD_NOTE,
6011
+ MATCH_HOW_LABEL,
6012
+ liveDoses,
6013
+ canLeaveUnmatched,
6014
+ initialMatches,
6015
+ matchProblem,
6016
+ matchesComplete,
6017
+ toChoices,
6018
+ flaggedSubscribers,
6019
+ describeConversion,
6020
+ hasBlockers,
6021
+ hasConversion,
6022
+ useCatalogConversion
5420
6023
  };
5421
- //# sourceMappingURL=VECSCRAK.jsx.map
6024
+ //# sourceMappingURL=ONYGQYUN.jsx.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  captureAuthHeader,
3
3
  peekFunnelSessionId
4
- } from "./NCK4UJHA.jsx";
4
+ } from "./MMPKHKIU.jsx";
5
5
  import {
6
6
  getConfig
7
7
  } from "./QVZ7BRNO.jsx";
@@ -174,4 +174,4 @@ export {
174
174
  readCartToken,
175
175
  stripCartToken
176
176
  };
177
- //# sourceMappingURL=2LWM2YSR.jsx.map
177
+ //# sourceMappingURL=RF6RWN3P.jsx.map
@@ -1,4 +1,4 @@
1
- import { peekFunnelSessionId, captureAuthHeader } from './YYWHDAAF.js';
1
+ import { peekFunnelSessionId, captureAuthHeader } from './CXMAV5SC.js';
2
2
  import { getConfig } from './2IFPDU4D.js';
3
3
 
4
4
  // src/api/promoRef.ts
@@ -156,5 +156,5 @@ function stripCartToken() {
156
156
  }
157
157
 
158
158
  export { adoptCartId, capturePromoCode, cartId, clearPromoCode, fetchCartConfig, fetchResumedCart, postCartSnapshot, readCartToken, readPromoCode, resetCartConfigCache, resetCartId, stripCartToken };
159
- //# sourceMappingURL=IBGYHU26.js.map
160
- //# sourceMappingURL=IBGYHU26.js.map
159
+ //# sourceMappingURL=RGFD2T3K.js.map
160
+ //# sourceMappingURL=RGFD2T3K.js.map