@solvapay/react 1.0.9 → 1.0.11-preview-e89911bc8c4dd3759eab37b440559220b691fd23

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.
@@ -30,7 +30,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/mcp/index.ts
31
31
  var mcp_exports = {};
32
32
  __export(mcp_exports, {
33
+ AppHeader: () => AppHeader,
33
34
  BackLink: () => BackLink,
35
+ HOSTS_WITH_MERCHANT_CHROME: () => HOSTS_WITH_MERCHANT_CHROME,
34
36
  MCP_TOOL_NAMES: () => import_mcp_core4.MCP_TOOL_NAMES,
35
37
  McpAccountView: () => McpAccountView,
36
38
  McpApp: () => McpApp,
@@ -38,11 +40,9 @@ __export(mcp_exports, {
38
40
  McpBridgeProvider: () => McpBridgeProvider,
39
41
  McpCheckoutView: () => McpCheckoutView,
40
42
  McpCustomerDetailsCard: () => McpCustomerDetailsCard,
41
- McpNudgeView: () => McpNudgeView,
42
- McpPaywallView: () => McpPaywallView,
43
+ McpHostInfoProvider: () => McpHostInfoProvider,
43
44
  McpSellerDetailsCard: () => McpSellerDetailsCard,
44
45
  McpTopupView: () => McpTopupView,
45
- McpUpsellStrip: () => McpUpsellStrip,
46
46
  McpViewRouter: () => McpViewRouter,
47
47
  SOLVAPAY_TRANSPORT_TOOL_NAMES: () => SOLVAPAY_TRANSPORT_TOOL_NAMES,
48
48
  classifyHostEntry: () => classifyHostEntry,
@@ -57,6 +57,7 @@ __export(mcp_exports, {
57
57
  resolvePlanShape: () => resolvePlanShape,
58
58
  seedMcpCaches: () => seedMcpCaches,
59
59
  useHostLocale: () => useHostLocale,
60
+ useHostName: () => useHostName,
60
61
  useMcpBridge: () => useMcpBridge,
61
62
  useMcpToolResult: () => useMcpToolResult,
62
63
  useStripeProbe: () => useStripeProbe,
@@ -343,20 +344,6 @@ function defaultSuccessCopy(evt, locale) {
343
344
 
344
345
  // src/mcp/bootstrap.ts
345
346
  var import_mcp_core2 = require("@solvapay/mcp-core");
346
-
347
- // ../server/src/index.ts
348
- var import_node_crypto = __toESM(require("crypto"), 1);
349
-
350
- // ../server/src/types/paywall.ts
351
- function isPaywallStructuredContent(value) {
352
- if (typeof value !== "object" || value === null || !("kind" in value)) {
353
- return false;
354
- }
355
- const kind = value.kind;
356
- return kind === "payment_required" || kind === "activation_required";
357
- }
358
-
359
- // src/mcp/bootstrap.ts
360
347
  var SOLVAPAY_TRANSPORT_TOOL_NAMES = new Set(
361
348
  Object.values(import_mcp_core2.MCP_TOOL_NAMES).filter(
362
349
  (name) => !(name in import_mcp_core2.VIEW_FOR_TOOL)
@@ -376,8 +363,7 @@ function classifyHostEntry(app) {
376
363
  view
377
364
  };
378
365
  }
379
- if (isTransportToolName(toolName)) return { kind: "other", toolName };
380
- return { kind: "data", toolName };
366
+ return { kind: "other", toolName };
381
367
  }
382
368
  function inferViewFromHost(app) {
383
369
  const classification = classifyHostEntry(app);
@@ -411,11 +397,7 @@ function parseBootstrapFromToolResult(result, toolName, fallbackView) {
411
397
  }
412
398
  const key = structured?.stripePublishableKey ?? null;
413
399
  const requestedView = structured?.view ?? fallbackView;
414
- const paywall = requestedView === "paywall" && isPaywallStructuredContent(structured?.paywall) ? structured.paywall : void 0;
415
400
  const resolvedView = requestedView;
416
- const nudgeSpec = structured?.nudge;
417
- const nudge = requestedView === "nudge" && isNudgeSpec(nudgeSpec) ? nudgeSpec : void 0;
418
- const data = requestedView === "nudge" ? structured?.data : void 0;
419
401
  return {
420
402
  view: resolvedView,
421
403
  productRef: ref,
@@ -424,19 +406,11 @@ function parseBootstrapFromToolResult(result, toolName, fallbackView) {
424
406
  merchant: structured?.merchant ?? {},
425
407
  product: structured?.product ?? { reference: ref },
426
408
  plans: Array.isArray(structured?.plans) ? structured.plans : [],
427
- customer: structured?.customer ?? null,
428
- ...paywall ? { paywall } : {},
429
- ...nudge ? { nudge } : {},
430
- ...data !== void 0 ? { data } : {}
409
+ customer: structured?.customer ?? null
431
410
  };
432
411
  }
433
- function isNudgeSpec(value) {
434
- if (typeof value !== "object" || value === null) return false;
435
- const kind = value.kind;
436
- return typeof kind === "string" && (kind === "low-balance" || kind === "cycle-ending" || kind === "approaching-limit");
437
- }
438
412
  function waitForInitialToolResult(app, options = {}) {
439
- const { timeoutMs = 2e3, signal, fallbackView = "paywall" } = options;
413
+ const { timeoutMs = 2e3, signal, fallbackView = "checkout" } = options;
440
414
  return new Promise((resolve, reject) => {
441
415
  let settled = false;
442
416
  let cleanup;
@@ -1999,11 +1973,11 @@ function seedMcpCaches(initial, config) {
1999
1973
  }
2000
1974
 
2001
1975
  // src/mcp/McpApp.tsx
2002
- var import_react50 = require("react");
1976
+ var import_react49 = require("react");
2003
1977
  var import_mcp_core3 = require("@solvapay/mcp-core");
2004
1978
 
2005
1979
  // src/mcp/McpAppShell.tsx
2006
- var import_react49 = require("react");
1980
+ var import_react46 = require("react");
2007
1981
 
2008
1982
  // src/hooks/usePurchase.ts
2009
1983
  function usePurchase() {
@@ -3198,7 +3172,11 @@ var DEFAULT_MCP_CLASS_NAMES = {
3198
3172
  amountOption: "solvapay-mcp-amount-option",
3199
3173
  amountCustom: "solvapay-mcp-amount-custom",
3200
3174
  topupForm: "solvapay-mcp-topup-form",
3201
- activationFlow: "solvapay-mcp-activation-flow"
3175
+ activationFlow: "solvapay-mcp-activation-flow",
3176
+ appHeader: "solvapay-mcp-app-header",
3177
+ appHeaderIcon: "solvapay-mcp-app-header-icon",
3178
+ appHeaderInitials: "solvapay-mcp-app-header-initials",
3179
+ appHeaderName: "solvapay-mcp-app-header-name"
3202
3180
  };
3203
3181
  function resolveMcpClassNames(overrides) {
3204
3182
  if (!overrides) return DEFAULT_MCP_CLASS_NAMES;
@@ -4184,8 +4162,6 @@ var AmountStep = (0, import_react29.memo)(function AmountStep2({
4184
4162
  plan,
4185
4163
  onBack,
4186
4164
  onContinue,
4187
- isActivating,
4188
- activationError,
4189
4165
  cx
4190
4166
  }) {
4191
4167
  const currency = (plan.currency ?? "USD").toUpperCase();
@@ -4209,16 +4185,13 @@ var AmountStep = (0, import_react29.memo)(function AmountStep2({
4209
4185
  AmountPicker.Confirm,
4210
4186
  {
4211
4187
  className: cx.button,
4212
- onConfirm: (amountMinor) => {
4213
- void onContinue(amountMinor);
4214
- },
4215
- children: isActivating ? "Activating\u2026" : stagedAmountMinor ? `Continue \u2014 ${formatPrice(stagedAmountMinor, currency, { locale })}` : "Continue"
4188
+ onConfirm: (amountMinor) => onContinue(amountMinor),
4189
+ children: stagedAmountMinor ? `Continue \u2014 ${formatPrice(stagedAmountMinor, currency, { locale })}` : "Continue"
4216
4190
  }
4217
4191
  )
4218
4192
  ]
4219
4193
  }
4220
- ),
4221
- activationError ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("p", { className: cx.error, role: "alert", children: activationError }) : null
4194
+ )
4222
4195
  ] });
4223
4196
  });
4224
4197
  function PresetAmountRow({ cx }) {
@@ -4250,6 +4223,20 @@ var import_react32 = require("react");
4250
4223
  var import_react31 = require("react");
4251
4224
  var import_react_stripe_js = require("@stripe/react-stripe-js");
4252
4225
 
4226
+ // src/primitives/paymentElementDefaults.ts
4227
+ var DEFAULT_PAYMENT_ELEMENT_OPTIONS = {
4228
+ wallets: { link: "never" }
4229
+ };
4230
+ function withPaymentElementDefaults(options) {
4231
+ return {
4232
+ ...options,
4233
+ wallets: {
4234
+ ...DEFAULT_PAYMENT_ELEMENT_OPTIONS.wallets,
4235
+ ...options?.wallets
4236
+ }
4237
+ };
4238
+ }
4239
+
4253
4240
  // src/hooks/useTopup.ts
4254
4241
  var import_react30 = require("react");
4255
4242
  var import_stripe_js2 = require("@stripe/stripe-js");
@@ -4576,7 +4563,7 @@ var PaymentElementSlot = ({ options }) => {
4576
4563
  return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { "data-solvapay-topup-form-payment-element": "", children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
4577
4564
  import_react_stripe_js.PaymentElement,
4578
4565
  {
4579
- options,
4566
+ options: withPaymentElementDefaults(options),
4580
4567
  onChange: (e) => setPaymentInputComplete(e.complete)
4581
4568
  },
4582
4569
  locale || "default"
@@ -4654,18 +4641,15 @@ var PaygPaymentStep = (0, import_react32.memo)(function PaygPaymentStep2({
4654
4641
  }) {
4655
4642
  const currency = (plan.currency ?? "USD").toUpperCase();
4656
4643
  const locale = useHostLocale();
4657
- const creditsPerUnit = plan.creditsPerUnit ?? 1;
4658
- const creditsAdded = Math.round(amountMinor * creditsPerUnit);
4644
+ const { creditsPerMinorUnit, displayExchangeRate } = useBalance();
4645
+ const creditsAdded = creditsPerMinorUnit != null && creditsPerMinorUnit > 0 ? Math.floor(amountMinor / (displayExchangeRate ?? 1) * creditsPerMinorUnit) : null;
4659
4646
  return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(import_jsx_runtime23.Fragment, { children: [
4660
4647
  /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(BackLink, { label: "Change amount", onClick: onBack }),
4661
4648
  /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("h2", { className: cx.heading, children: "Payment" }),
4662
4649
  /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "solvapay-mcp-checkout-order-summary", "data-variant": "payg", children: [
4663
4650
  /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "solvapay-mcp-checkout-order-summary-row", children: [
4664
- /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("span", { className: cx.muted, children: [
4665
- creditsAdded.toLocaleString(locale),
4666
- " credits"
4667
- ] }),
4668
- /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { children: formatPrice(amountMinor, currency, { locale }) })
4651
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: cx.muted, children: creditsAdded != null ? `${creditsAdded.toLocaleString(locale)} credits` : formatPrice(amountMinor, currency, { locale }) }),
4652
+ creditsAdded != null ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { children: formatPrice(amountMinor, currency, { locale }) }) : null
4669
4653
  ] }),
4670
4654
  /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "solvapay-mcp-checkout-order-summary-row", children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: cx.muted, children: "One-time" }) })
4671
4655
  ] }),
@@ -5853,7 +5837,7 @@ var PaymentElementSlot2 = ({ options }) => {
5853
5837
  return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { "data-solvapay-payment-form-payment-element": "", children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
5854
5838
  import_react_stripe_js2.PaymentElement,
5855
5839
  {
5856
- options,
5840
+ options: withPaymentElementDefaults(options),
5857
5841
  onChange: (e) => setPaymentInputComplete(e.complete)
5858
5842
  },
5859
5843
  locale || "default"
@@ -6189,58 +6173,52 @@ function CheckoutStateMachine(props) {
6189
6173
  const transport = useTransport();
6190
6174
  const locale = useHostLocale();
6191
6175
  const { notifyModelContext, notifySuccess } = useMcpBridge();
6176
+ const { creditsPerMinorUnit, displayExchangeRate } = useBalance();
6192
6177
  const selectedPlanShape = selectedPlan;
6193
6178
  const branch = selectedPlanShape ? isPayg(selectedPlanShape) ? "payg" : "recurring" : null;
6194
- const onPlanContinue = (0, import_react42.useCallback)(() => {
6179
+ const onPlanContinue = (0, import_react42.useCallback)(async () => {
6195
6180
  if (!selectedPlanShape || !selectedPlanRef) return;
6196
6181
  setActivationError(null);
6197
6182
  void notifyModelContext({
6198
6183
  text: `User selected ${selectedPlanShape.name ?? "a plan"}.`
6199
6184
  });
6200
6185
  if (branch === "payg") {
6201
- setStep("amount");
6186
+ setIsActivating(true);
6187
+ try {
6188
+ await transport.activatePlan({ productRef, planRef: selectedPlanRef });
6189
+ setStep("amount");
6190
+ } catch (err) {
6191
+ const msg = err instanceof Error ? err.message : "Activation failed";
6192
+ setActivationError(msg);
6193
+ } finally {
6194
+ setIsActivating(false);
6195
+ }
6202
6196
  return;
6203
6197
  }
6204
6198
  setStep("payment");
6205
6199
  }, [
6206
6200
  branch,
6207
6201
  notifyModelContext,
6202
+ productRef,
6208
6203
  selectedPlanRef,
6209
6204
  selectedPlanShape,
6210
6205
  setActivationError,
6211
- setStep
6206
+ setIsActivating,
6207
+ setStep,
6208
+ transport
6212
6209
  ]);
6213
6210
  const onAmountContinue = (0, import_react42.useCallback)(
6214
- async (amountMinor) => {
6211
+ (amountMinor) => {
6215
6212
  if (!selectedPlanRef) return;
6216
6213
  setSelectedAmountMinor(amountMinor);
6217
- setActivationError(null);
6218
- setIsActivating(true);
6219
- try {
6220
- await transport.activatePlan({ productRef, planRef: selectedPlanRef });
6221
- setStep("payment");
6222
- } catch (err) {
6223
- const msg = err instanceof Error ? err.message : "Activation failed";
6224
- setActivationError(msg);
6225
- } finally {
6226
- setIsActivating(false);
6227
- }
6214
+ setStep("payment");
6228
6215
  },
6229
- [
6230
- productRef,
6231
- selectedPlanRef,
6232
- setActivationError,
6233
- setIsActivating,
6234
- setSelectedAmountMinor,
6235
- setStep,
6236
- transport
6237
- ]
6216
+ [selectedPlanRef, setSelectedAmountMinor, setStep]
6238
6217
  );
6239
6218
  const onPaygPaymentSuccess = (0, import_react42.useCallback)(() => {
6240
6219
  if (!selectedPlanShape || selectedAmountMinor == null) return;
6241
6220
  const currency = (selectedPlanShape.currency ?? "USD").toUpperCase();
6242
- const creditsPerUnit = selectedPlanShape.creditsPerUnit ?? 1;
6243
- const creditsAdded = Math.round(selectedAmountMinor * creditsPerUnit);
6221
+ const creditsAdded = creditsPerMinorUnit != null && creditsPerMinorUnit > 0 ? Math.floor(selectedAmountMinor / (displayExchangeRate ?? 1) * creditsPerMinorUnit) : 0;
6244
6222
  setSuccessMeta({
6245
6223
  branch: "payg",
6246
6224
  amountMinor: selectedAmountMinor,
@@ -6260,6 +6238,8 @@ function CheckoutStateMachine(props) {
6260
6238
  void notifySuccess({ kind: "topup", amountMinor: selectedAmountMinor, currency });
6261
6239
  onPurchaseSuccess?.();
6262
6240
  }, [
6241
+ creditsPerMinorUnit,
6242
+ displayExchangeRate,
6263
6243
  locale,
6264
6244
  notifyModelContext,
6265
6245
  notifySuccess,
@@ -6349,8 +6329,6 @@ function CheckoutStateMachine(props) {
6349
6329
  plan: selectedPlanShape,
6350
6330
  onBack: onBackFromAmount,
6351
6331
  onContinue: onAmountContinue,
6352
- isActivating,
6353
- activationError,
6354
6332
  cx
6355
6333
  }
6356
6334
  );
@@ -6414,6 +6392,8 @@ function EmbeddedCheckout({
6414
6392
  onRefreshBootstrap,
6415
6393
  onClose,
6416
6394
  cx,
6395
+ // `classNames` is accepted on the interface for API stability but
6396
+ // not consumed inside this surface — see the JSDoc on the prop.
6417
6397
  children
6418
6398
  }) {
6419
6399
  const { loading, isRefetching, activePurchase } = usePurchase();
@@ -6518,6 +6498,7 @@ function McpCheckoutView({
6518
6498
  onRefreshBootstrap,
6519
6499
  onClose,
6520
6500
  cx,
6501
+ classNames,
6521
6502
  children
6522
6503
  }
6523
6504
  );
@@ -6820,420 +6801,9 @@ function HostedCheckout({
6820
6801
  ] });
6821
6802
  }
6822
6803
 
6823
- // src/primitives/PaywallNotice.tsx
6824
- var import_react46 = require("react");
6825
-
6826
- // src/hooks/usePaywallResolver.ts
6804
+ // src/mcp/views/McpTopupView.tsx
6827
6805
  var import_react45 = require("react");
6828
- function usePaywallResolver(content) {
6829
- const { activePurchase, hasPaidPurchase, refetch: refetchPurchase } = usePurchase();
6830
- const { credits, refetch: refetchBalance } = useBalance();
6831
- const resolved = (0, import_react45.useMemo)(() => {
6832
- if (!content) return false;
6833
- const productMatches = !content.product || activePurchase?.productRef === content.product || activePurchase?.productName === content.product;
6834
- if (content.kind === "payment_required") {
6835
- return Boolean(hasPaidPurchase && productMatches);
6836
- }
6837
- const balance = content.balance;
6838
- if (balance && typeof balance.remainingUnits === "number" && balance.remainingUnits > 0) {
6839
- return true;
6840
- }
6841
- if (balance && credits != null && balance.creditsPerUnit && credits >= balance.creditsPerUnit) {
6842
- return true;
6843
- }
6844
- return Boolean(productMatches && activePurchase?.status === "active");
6845
- }, [content, hasPaidPurchase, activePurchase, credits]);
6846
- const refetch = (0, import_react45.useCallback)(async () => {
6847
- await Promise.all([
6848
- refetchPurchase().catch(() => void 0),
6849
- refetchBalance().catch(() => void 0)
6850
- ]);
6851
- }, [refetchPurchase, refetchBalance]);
6852
- return { resolved, refetch };
6853
- }
6854
-
6855
- // src/primitives/PaywallNotice.tsx
6856
6806
  var import_jsx_runtime34 = require("react/jsx-runtime");
6857
- var PaywallNoticeContext = (0, import_react46.createContext)(null);
6858
- function usePaywallNoticeCtx(part) {
6859
- const ctx = (0, import_react46.useContext)(PaywallNoticeContext);
6860
- if (!ctx) {
6861
- throw new Error(`PaywallNotice.${part} must be rendered inside <PaywallNotice.Root>.`);
6862
- }
6863
- return ctx;
6864
- }
6865
- var Root8 = (0, import_react46.forwardRef)(function PaywallNoticeRoot({ content, onResolved, classNames, asChild, children, ...rest }, forwardedRef) {
6866
- const { resolved, refetch } = usePaywallResolver(content);
6867
- const classNamesResolved = (0, import_react46.useMemo)(() => classNames ?? {}, [classNames]);
6868
- (0, import_react46.useEffect)(() => {
6869
- if (resolved) onResolved?.();
6870
- }, [resolved, onResolved]);
6871
- const ctx = (0, import_react46.useMemo)(
6872
- () => ({
6873
- content,
6874
- resolved,
6875
- refetch,
6876
- onResolved,
6877
- classNames: classNamesResolved
6878
- }),
6879
- [content, resolved, refetch, onResolved, classNamesResolved]
6880
- );
6881
- const Comp = asChild ? Slot : "div";
6882
- return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PaywallNoticeContext.Provider, { value: ctx, children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
6883
- Comp,
6884
- {
6885
- ref: forwardedRef,
6886
- "data-solvapay-paywall-notice": "",
6887
- "data-kind": content.kind,
6888
- "data-state": resolved ? "resolved" : "pending",
6889
- className: classNamesResolved.root,
6890
- ...rest,
6891
- children
6892
- }
6893
- ) });
6894
- });
6895
- var Heading3 = (0, import_react46.forwardRef)(function PaywallNoticeHeading({ asChild, children, className, ...rest }, forwardedRef) {
6896
- const ctx = usePaywallNoticeCtx("Heading");
6897
- const copy = useCopy();
6898
- const defaultText = ctx.resolved ? copy.paywall.resolvedHeading : ctx.content.kind === "payment_required" ? copy.paywall.paymentRequiredHeading : copy.paywall.activationRequiredHeading;
6899
- const Comp = asChild ? Slot : "h2";
6900
- return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
6901
- Comp,
6902
- {
6903
- ref: forwardedRef,
6904
- "data-solvapay-paywall-heading": "",
6905
- className: className ?? ctx.classNames.heading,
6906
- ...rest,
6907
- children: children ?? defaultText
6908
- }
6909
- );
6910
- });
6911
- var Message = (0, import_react46.forwardRef)(function PaywallNoticeMessage({ asChild, children, className, ...rest }, forwardedRef) {
6912
- const ctx = usePaywallNoticeCtx("Message");
6913
- const copy = useCopy();
6914
- const Comp = asChild ? Slot : "p";
6915
- const defaultText = resolvePaywallMessage(ctx.content, copy.paywall);
6916
- return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
6917
- Comp,
6918
- {
6919
- ref: forwardedRef,
6920
- "data-solvapay-paywall-message": "",
6921
- className: className ?? ctx.classNames.message,
6922
- ...rest,
6923
- children: children ?? defaultText
6924
- }
6925
- );
6926
- });
6927
- function resolvePaywallMessage(content, paywallCopy) {
6928
- if (content.kind !== "payment_required") {
6929
- return content.message;
6930
- }
6931
- const balance = content.balance;
6932
- if (!balance) return content.message;
6933
- const productName = content.productDetails?.name;
6934
- const forProduct = productName ? interpolate(paywallCopy.paymentRequiredProductSuffix, { product: productName }) : "";
6935
- const remaining = balance.remainingUnits ?? 0;
6936
- if (remaining <= 0) {
6937
- return interpolate(paywallCopy.paymentRequiredMessage, { forProduct });
6938
- }
6939
- return interpolate(paywallCopy.paymentRequiredMessageRemaining, {
6940
- remaining: String(remaining),
6941
- pluralSuffix: remaining === 1 ? "" : "s",
6942
- forProduct
6943
- });
6944
- }
6945
- var ProductContext = (0, import_react46.forwardRef)(function PaywallNoticeProductContext({ asChild, children, className, ...rest }, forwardedRef) {
6946
- const ctx = usePaywallNoticeCtx("ProductContext");
6947
- const copy = useCopy();
6948
- const product = ctx.content.kind === "activation_required" ? ctx.content.productDetails : void 0;
6949
- if (!product?.name) return null;
6950
- const label = interpolate(copy.paywall.productContext, { product: product.name });
6951
- const Comp = asChild ? Slot : "div";
6952
- return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
6953
- Comp,
6954
- {
6955
- ref: forwardedRef,
6956
- "data-solvapay-paywall-product-context": "",
6957
- className: className ?? ctx.classNames.productContext,
6958
- ...rest,
6959
- children: children ?? label
6960
- }
6961
- );
6962
- });
6963
- var Balance = (0, import_react46.forwardRef)(function PaywallNoticeBalance({ asChild, children, className, ...rest }, forwardedRef) {
6964
- const ctx = usePaywallNoticeCtx("Balance");
6965
- const copy = useCopy();
6966
- const balance = ctx.content.balance;
6967
- if (ctx.content.kind !== "activation_required" || !balance) return null;
6968
- const label = interpolate(copy.paywall.balanceLine, {
6969
- available: String(balance.remainingUnits ?? 0),
6970
- required: String(balance.creditsPerUnit ?? 1)
6971
- });
6972
- const Comp = asChild ? Slot : "div";
6973
- return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
6974
- Comp,
6975
- {
6976
- ref: forwardedRef,
6977
- "data-solvapay-paywall-balance": "",
6978
- className: className ?? ctx.classNames.balance,
6979
- ...rest,
6980
- children: children ?? label
6981
- }
6982
- );
6983
- });
6984
- function Plans({ className, children }) {
6985
- const ctx = usePaywallNoticeCtx("Plans");
6986
- if (ctx.content.kind !== "activation_required") return null;
6987
- if (!ctx.content.product) return null;
6988
- const defaultClass = className ?? ctx.classNames.plans ?? "solvapay-paywall-plans";
6989
- return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { "data-solvapay-paywall-plans": "", className: defaultClass, children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PlanSelector.Root, { productRef: ctx.content.product, filter: hidesFreePlan, children: children ?? /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(import_jsx_runtime34.Fragment, { children: [
6990
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PlanSelector.Grid, { children: /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(PlanSelector.Card, { children: [
6991
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PlanSelector.CardBadge, {}),
6992
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PlanSelector.CardName, {}),
6993
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PlanSelector.CardPrice, {}),
6994
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PlanSelector.CardInterval, {})
6995
- ] }) }),
6996
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PlanSelector.Loading, {}),
6997
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PlanSelector.Error, {})
6998
- ] }) }) });
6999
- }
7000
- function hidesFreePlan(plan) {
7001
- return plan.requiresPayment !== false;
7002
- }
7003
- var HostedCheckoutLink = (0, import_react46.forwardRef)(function PaywallNoticeHostedCheckoutLink({ asChild, children, className, ...rest }, forwardedRef) {
7004
- const ctx = usePaywallNoticeCtx("HostedCheckoutLink");
7005
- const copy = useCopy();
7006
- const href = ctx.content.checkoutUrl;
7007
- if (!href) return null;
7008
- const Comp = asChild ? Slot : "a";
7009
- return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
7010
- Comp,
7011
- {
7012
- ref: forwardedRef,
7013
- href,
7014
- target: "_blank",
7015
- rel: "noopener noreferrer",
7016
- "data-solvapay-paywall-hosted-link": "",
7017
- className: className ?? ctx.classNames.hostedLink,
7018
- ...rest,
7019
- children: children ?? copy.paywall.hostedCheckoutButton
7020
- }
7021
- );
7022
- });
7023
- function EmbeddedCheckout2({
7024
- returnUrl,
7025
- className,
7026
- children
7027
- }) {
7028
- const ctx = usePaywallNoticeCtx("EmbeddedCheckout");
7029
- if (!ctx.content.product) return null;
7030
- const defaultClass = className ?? ctx.classNames.embeddedCheckout ?? "solvapay-paywall-embedded-checkout";
7031
- return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { "data-solvapay-paywall-embedded-checkout": "", className: defaultClass, children: /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(PlanSelector.Root, { productRef: ctx.content.product, filter: hidesFreePlan, children: [
7032
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PlanSelector.Grid, { children: /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(PlanSelector.Card, { children: [
7033
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PlanSelector.CardBadge, {}),
7034
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PlanSelector.CardName, {}),
7035
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PlanSelector.CardPrice, {}),
7036
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PlanSelector.CardInterval, {})
7037
- ] }) }),
7038
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PlanSelector.Loading, {}),
7039
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PlanSelector.Error, {}),
7040
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PaywallSelectedPlanGate, { productRef: ctx.content.product, returnUrl, children })
7041
- ] }) });
7042
- }
7043
- function PaywallSelectedPlanGate({
7044
- productRef,
7045
- returnUrl,
7046
- children
7047
- }) {
7048
- const { selectedPlan, selectedPlanRef } = usePlanSelector();
7049
- if (!selectedPlanRef || !selectedPlan) return null;
7050
- if (isPaygPlan(selectedPlan)) {
7051
- return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
7052
- PaywallPaygGate,
7053
- {
7054
- plan: selectedPlan,
7055
- returnUrl
7056
- },
7057
- selectedPlanRef
7058
- );
7059
- }
7060
- return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PaywallPaymentFormGate, { productRef, returnUrl, children: children ?? /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(import_jsx_runtime34.Fragment, { children: [
7061
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PaymentForm.Summary, {}),
7062
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PaymentForm.Loading, {}),
7063
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PaymentForm.PaymentElement, {}),
7064
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PaymentForm.Error, {}),
7065
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PaymentForm.MandateText, {}),
7066
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PaymentForm.SubmitButton, {})
7067
- ] }) });
7068
- }
7069
- function PaywallPaygGate({
7070
- plan,
7071
- returnUrl
7072
- }) {
7073
- const ctx = usePaywallNoticeCtx("EmbeddedCheckout");
7074
- const currency = (plan.currency ?? "USD").toUpperCase();
7075
- const [amountMinor, setAmountMinor] = (0, import_react46.useState)(null);
7076
- if (amountMinor == null) {
7077
- return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { "data-solvapay-paywall-payg-amount": "", children: /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(AmountPicker.Root, { currency, emit: "minor", children: [
7078
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(AmountPicker.Custom, {}),
7079
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(AmountPicker.Confirm, { onConfirm: (minor) => setAmountMinor(minor), children: "Continue" })
7080
- ] }) });
7081
- }
7082
- return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { "data-solvapay-paywall-payg-topup": "", children: [
7083
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
7084
- "button",
7085
- {
7086
- type: "button",
7087
- "data-solvapay-paywall-payg-change-amount": "",
7088
- onClick: () => setAmountMinor(null),
7089
- children: "Change amount"
7090
- }
7091
- ),
7092
- /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(
7093
- TopupForm.Root,
7094
- {
7095
- amount: amountMinor,
7096
- currency,
7097
- returnUrl,
7098
- onSuccess: () => {
7099
- void ctx.refetch();
7100
- },
7101
- children: [
7102
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(TopupForm.Loading, {}),
7103
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(TopupForm.PaymentElement, {}),
7104
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(TopupForm.Error, {}),
7105
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(TopupForm.SubmitButton, {})
7106
- ]
7107
- }
7108
- )
7109
- ] });
7110
- }
7111
- function PaywallPaymentFormGate({
7112
- productRef,
7113
- returnUrl,
7114
- children
7115
- }) {
7116
- const { selectedPlanRef } = usePlanSelector();
7117
- const ctx = usePaywallNoticeCtx("EmbeddedCheckout");
7118
- if (!selectedPlanRef) return null;
7119
- return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
7120
- PaymentForm.Root,
7121
- {
7122
- planRef: selectedPlanRef,
7123
- productRef,
7124
- returnUrl,
7125
- requireTermsAcceptance: false,
7126
- onSuccess: () => {
7127
- void ctx.refetch();
7128
- },
7129
- children
7130
- },
7131
- selectedPlanRef
7132
- );
7133
- }
7134
- var Retry = (0, import_react46.forwardRef)(
7135
- function PaywallNoticeRetry({ asChild, children, className, onClick, ...rest }, forwardedRef) {
7136
- const ctx = usePaywallNoticeCtx("Retry");
7137
- const copy = useCopy();
7138
- const Comp = asChild ? Slot : "button";
7139
- return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
7140
- Comp,
7141
- {
7142
- ref: forwardedRef,
7143
- type: "button",
7144
- disabled: !ctx.resolved,
7145
- "data-solvapay-paywall-retry": "",
7146
- "data-state": ctx.resolved ? "ready" : "waiting",
7147
- className: className ?? ctx.classNames.retryButton,
7148
- onClick: (e) => {
7149
- onClick?.(e);
7150
- if (!e.defaultPrevented && ctx.resolved) ctx.onResolved?.();
7151
- },
7152
- ...rest,
7153
- children: children ?? copy.paywall.retryButton
7154
- }
7155
- );
7156
- }
7157
- );
7158
- var PaywallNotice = Object.assign(Root8, {
7159
- Root: Root8,
7160
- Heading: Heading3,
7161
- Message,
7162
- ProductContext,
7163
- Plans,
7164
- Balance,
7165
- HostedCheckoutLink,
7166
- EmbeddedCheckout: EmbeddedCheckout2,
7167
- Retry
7168
- });
7169
-
7170
- // src/mcp/views/McpPaywallView.tsx
7171
- var import_jsx_runtime35 = require("react/jsx-runtime");
7172
- function McpPaywallView({
7173
- content,
7174
- publishableKey = null,
7175
- returnUrl,
7176
- classNames,
7177
- onResolved,
7178
- plans,
7179
- upgradeCta
7180
- }) {
7181
- const cx = resolveMcpClassNames(classNames);
7182
- const copy = useCopy();
7183
- const probe = useStripeProbe(publishableKey);
7184
- const productRef = content.product;
7185
- const embeddedReady = probe === "ready" && Boolean(productRef);
7186
- const isLoading = probe === "loading";
7187
- return /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(
7188
- PaywallNotice.Root,
7189
- {
7190
- content,
7191
- onResolved,
7192
- classNames: {
7193
- // Flat flex-column stack — no outer card. `EmbeddedCheckout`
7194
- // provides the single card below.
7195
- root: cx.stack,
7196
- heading: cx.heading,
7197
- message: cx.muted,
7198
- balance: cx.notice,
7199
- hostedLink: cx.button
7200
- },
7201
- children: [
7202
- /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(PaywallNotice.Heading, {}),
7203
- /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(PaywallNotice.Message, {}),
7204
- /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(PaywallNotice.Balance, {}),
7205
- isLoading ? /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className: cx.muted, children: copy.paywall.hostedCheckoutLoading }) : embeddedReady ? /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
7206
- EmbeddedCheckout,
7207
- {
7208
- productRef,
7209
- returnUrl,
7210
- fromPaywall: true,
7211
- paywallKind: content.kind,
7212
- hideUpgradeBanner: true,
7213
- plans,
7214
- onRefreshBootstrap: onResolved,
7215
- onClose: onResolved,
7216
- cx
7217
- }
7218
- ) : /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(PaywallNotice.HostedCheckoutLink, {}),
7219
- upgradeCta ? /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
7220
- "button",
7221
- {
7222
- type: "button",
7223
- className: `${cx.button} solvapay-mcp-paywall-upgrade-cta`.trim(),
7224
- "data-variant": "secondary",
7225
- onClick: upgradeCta.onClick,
7226
- children: upgradeCta.label
7227
- }
7228
- ) : null
7229
- ]
7230
- }
7231
- );
7232
- }
7233
-
7234
- // src/mcp/views/McpTopupView.tsx
7235
- var import_react47 = require("react");
7236
- var import_jsx_runtime36 = require("react/jsx-runtime");
7237
6807
  var FALLBACK_TOPUP_CURRENCY = "USD";
7238
6808
  function McpTopupView({
7239
6809
  publishableKey = null,
@@ -7246,11 +6816,12 @@ function McpTopupView({
7246
6816
  const probe = useStripeProbe(publishableKey);
7247
6817
  const { merchant, loading: merchantLoading } = useMerchant();
7248
6818
  if (probe === "loading" || merchantLoading) {
7249
- return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: cx.card, children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("p", { children: "Loading top-up\u2026" }) });
6819
+ return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: cx.card, children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("p", { children: "Loading top-up\u2026" }) });
7250
6820
  }
7251
- if (probe === "blocked") return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(HostedTopupFallback, { cx, onBack });
6821
+ if (probe === "blocked")
6822
+ return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(HostedTopupFallback, { cx, onBack });
7252
6823
  const currency = merchant?.defaultCurrency?.toUpperCase() ?? FALLBACK_TOPUP_CURRENCY;
7253
- return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
6824
+ return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
7254
6825
  EmbeddedTopup,
7255
6826
  {
7256
6827
  returnUrl,
@@ -7268,24 +6839,24 @@ function EmbeddedTopup({
7268
6839
  onBack,
7269
6840
  cx
7270
6841
  }) {
7271
- const [committedAmountMinor, setCommittedAmountMinor] = (0, import_react47.useState)(null);
7272
- const [justPaidMinor, setJustPaidMinor] = (0, import_react47.useState)(null);
6842
+ const [committedAmountMinor, setCommittedAmountMinor] = (0, import_react45.useState)(null);
6843
+ const [justPaidMinor, setJustPaidMinor] = (0, import_react45.useState)(null);
7273
6844
  const { adjustBalance, creditsPerMinorUnit } = useBalance();
7274
6845
  const locale = useHostLocale();
7275
6846
  const { notifyModelContext, notifySuccess } = useMcpBridge();
7276
6847
  if (justPaidMinor != null) {
7277
6848
  const displayAmount = formatPrice(justPaidMinor, currency, { locale, free: "" });
7278
- return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: cx.card, children: [
7279
- onBack ? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(BackLink, { label: "Back to my account", onClick: onBack }) : null,
7280
- /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: cx.balanceRow, children: [
7281
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("h2", { className: cx.heading, children: "Credits added" }),
7282
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(BalanceBadge, {})
6849
+ return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: cx.card, children: [
6850
+ onBack ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(BackLink, { label: "Back to my account", onClick: onBack }) : null,
6851
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: cx.balanceRow, children: [
6852
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("h2", { className: cx.heading, children: "Credits added" }),
6853
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(BalanceBadge, {})
7283
6854
  ] }),
7284
- /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("p", { className: cx.muted, children: [
6855
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("p", { className: cx.muted, children: [
7285
6856
  displayAmount,
7286
6857
  " landed in your balance."
7287
6858
  ] }),
7288
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
6859
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
7289
6860
  "button",
7290
6861
  {
7291
6862
  type: "button",
@@ -7294,7 +6865,7 @@ function EmbeddedTopup({
7294
6865
  children: "Add more credits"
7295
6866
  }
7296
6867
  ),
7297
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
6868
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
7298
6869
  LaunchCustomerPortalButton,
7299
6870
  {
7300
6871
  className: cx.button,
@@ -7307,18 +6878,18 @@ function EmbeddedTopup({
7307
6878
  }
7308
6879
  if (committedAmountMinor != null && committedAmountMinor > 0) {
7309
6880
  const displayAmount = formatPrice(committedAmountMinor, currency, { locale, free: "" });
7310
- return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: cx.card, children: [
7311
- onBack ? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(BackLink, { label: "Back to my account", onClick: onBack }) : null,
7312
- /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: cx.balanceRow, children: [
7313
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("h2", { className: cx.heading, children: "Pay with card" }),
7314
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(BalanceBadge, {})
6881
+ return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: cx.card, children: [
6882
+ onBack ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(BackLink, { label: "Back to my account", onClick: onBack }) : null,
6883
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: cx.balanceRow, children: [
6884
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("h2", { className: cx.heading, children: "Pay with card" }),
6885
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(BalanceBadge, {})
7315
6886
  ] }),
7316
- /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("p", { className: cx.muted, children: [
6887
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("p", { className: cx.muted, children: [
7317
6888
  "Adding ",
7318
6889
  displayAmount,
7319
6890
  " in credits."
7320
6891
  ] }),
7321
- /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
6892
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(
7322
6893
  TopupForm.Root,
7323
6894
  {
7324
6895
  amount: committedAmountMinor,
@@ -7343,14 +6914,14 @@ function EmbeddedTopup({
7343
6914
  setCommittedAmountMinor(null);
7344
6915
  },
7345
6916
  children: [
7346
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(TopupForm.Loading, {}),
7347
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(TopupForm.PaymentElement, {}),
7348
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(TopupForm.Error, { className: cx.error }),
7349
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(TopupForm.SubmitButton, { className: cx.button })
6917
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(TopupForm.Loading, {}),
6918
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(TopupForm.PaymentElement, {}),
6919
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(TopupForm.Error, { className: cx.error }),
6920
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(TopupForm.SubmitButton, { className: cx.button })
7350
6921
  ]
7351
6922
  }
7352
6923
  ),
7353
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
6924
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
7354
6925
  BackLink,
7355
6926
  {
7356
6927
  label: "Change amount",
@@ -7359,16 +6930,16 @@ function EmbeddedTopup({
7359
6930
  )
7360
6931
  ] });
7361
6932
  }
7362
- return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: cx.card, children: [
7363
- onBack ? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(BackLink, { label: "Back to my account", onClick: onBack }) : null,
7364
- /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: cx.balanceRow, children: [
7365
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("h2", { className: cx.heading, children: "Add credits" }),
7366
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(BalanceBadge, {})
6933
+ return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: cx.card, children: [
6934
+ onBack ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(BackLink, { label: "Back to my account", onClick: onBack }) : null,
6935
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: cx.balanceRow, children: [
6936
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("h2", { className: cx.heading, children: "Add credits" }),
6937
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(BalanceBadge, {})
7367
6938
  ] }),
7368
- /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(AmountPicker.Root, { currency, emit: "minor", className: cx.amountPicker, children: [
7369
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(QuickAmountOptions, { className: cx.amountOptions, optionClassName: cx.amountOption }),
7370
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(AmountPicker.Custom, { className: cx.amountCustom }),
7371
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
6939
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(AmountPicker.Root, { currency, emit: "minor", className: cx.amountPicker, children: [
6940
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(QuickAmountOptions, { className: cx.amountOptions, optionClassName: cx.amountOption }),
6941
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(AmountPicker.Custom, { className: cx.amountCustom }),
6942
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
7372
6943
  AmountPicker.Confirm,
7373
6944
  {
7374
6945
  className: cx.button,
@@ -7392,14 +6963,17 @@ function QuickAmountOptions({
7392
6963
  optionClassName
7393
6964
  }) {
7394
6965
  const { quickAmounts } = useAmountPicker();
7395
- return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className, children: quickAmounts.map((amount) => /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(AmountPicker.Option, { amount, className: optionClassName }, amount)) });
7396
- }
7397
- function HostedTopupFallback({ cx, onBack }) {
7398
- return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: cx.card, children: [
7399
- onBack ? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(BackLink, { label: "Back to my account", onClick: onBack }) : null,
7400
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("h2", { className: cx.heading, children: "Add credits" }),
7401
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("p", { className: cx.muted, children: "This host doesn't allow embedded payments. Open the SolvaPay portal in a new tab to complete your top-up there." }),
7402
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
6966
+ return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className, children: quickAmounts.map((amount) => /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(AmountPicker.Option, { amount, className: optionClassName }, amount)) });
6967
+ }
6968
+ function HostedTopupFallback({
6969
+ cx,
6970
+ onBack
6971
+ }) {
6972
+ return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: cx.card, children: [
6973
+ onBack ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(BackLink, { label: "Back to my account", onClick: onBack }) : null,
6974
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("h2", { className: cx.heading, children: "Add credits" }),
6975
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("p", { className: cx.muted, children: "This host doesn't allow embedded payments. Open the SolvaPay portal in a new tab to complete your top-up there." }),
6976
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
7403
6977
  LaunchCustomerPortalButton,
7404
6978
  {
7405
6979
  className: cx.button,
@@ -7411,76 +6985,8 @@ function HostedTopupFallback({ cx, onBack }) {
7411
6985
  ] });
7412
6986
  }
7413
6987
 
7414
- // src/mcp/components/McpUpsellStrip.tsx
7415
- var import_react48 = require("react");
7416
- var import_jsx_runtime37 = require("react/jsx-runtime");
7417
- var NUDGE_DEFAULTS = {
7418
- "low-balance": { label: "Upgrade" },
7419
- "cycle-ending": { label: "Renew" },
7420
- "approaching-limit": { label: "Upgrade" }
7421
- };
7422
- function McpUpsellStrip({
7423
- nudge,
7424
- onCta,
7425
- onDismiss,
7426
- hideDismiss = false,
7427
- ctaLabel,
7428
- className
7429
- }) {
7430
- const [dismissed, setDismissed] = (0, import_react48.useState)(false);
7431
- if (dismissed) return null;
7432
- const label = ctaLabel ?? NUDGE_DEFAULTS[nudge.kind].label;
7433
- const handleDismiss = () => {
7434
- setDismissed(true);
7435
- onDismiss?.();
7436
- };
7437
- const rootClass = [
7438
- "solvapay-mcp-upsell-strip",
7439
- `solvapay-mcp-upsell-strip--${nudge.kind}`,
7440
- className
7441
- ].filter(Boolean).join(" ");
7442
- return /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)("aside", { className: rootClass, role: "status", "aria-live": "polite", "data-testid": "mcp-upsell-strip", children: [
7443
- /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("span", { className: "solvapay-mcp-upsell-strip-message", children: nudge.message }),
7444
- /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)("div", { className: "solvapay-mcp-upsell-strip-actions", children: [
7445
- onCta ? /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
7446
- "button",
7447
- {
7448
- type: "button",
7449
- onClick: onCta,
7450
- className: "solvapay-mcp-upsell-strip-cta",
7451
- children: label
7452
- }
7453
- ) : null,
7454
- hideDismiss ? null : /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
7455
- "button",
7456
- {
7457
- type: "button",
7458
- onClick: handleDismiss,
7459
- className: "solvapay-mcp-upsell-strip-dismiss",
7460
- "aria-label": "Dismiss",
7461
- children: "\xD7"
7462
- }
7463
- )
7464
- ] })
7465
- ] });
7466
- }
7467
-
7468
- // src/mcp/views/McpNudgeView.tsx
7469
- var import_jsx_runtime38 = require("react/jsx-runtime");
7470
- function McpNudgeView({ bootstrap, onCta, onDismiss, classNames }) {
7471
- const cx = resolveMcpClassNames(classNames);
7472
- const { nudge, data } = bootstrap;
7473
- return /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("section", { className: "solvapay-mcp-nudge-view", children: [
7474
- nudge ? /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(McpUpsellStrip, { nudge, onCta, onDismiss }) : null,
7475
- data !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: cx.card, children: [
7476
- /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("h2", { className: cx.heading, children: "Tool result" }),
7477
- /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("pre", { className: "solvapay-mcp-nudge-data", children: JSON.stringify(data, null, 2) })
7478
- ] }) : null
7479
- ] });
7480
- }
7481
-
7482
6988
  // src/mcp/McpAppShell.tsx
7483
- var import_jsx_runtime39 = require("react/jsx-runtime");
6989
+ var import_jsx_runtime35 = require("react/jsx-runtime");
7484
6990
  function resolveSurface(bootstrapView) {
7485
6991
  switch (bootstrapView) {
7486
6992
  case "checkout":
@@ -7490,10 +6996,6 @@ function resolveSurface(bootstrapView) {
7490
6996
  return "checkout";
7491
6997
  case "topup":
7492
6998
  return "topup";
7493
- case "paywall":
7494
- return "paywall";
7495
- case "nudge":
7496
- return "nudge";
7497
6999
  case "usage":
7498
7000
  // Usage folds into the account surface.
7499
7001
  case "account":
@@ -7510,53 +7012,22 @@ function McpAppShell({
7510
7012
  onClose
7511
7013
  }) {
7512
7014
  const { merchant } = useMerchant();
7513
- const [paywallDismissed, setPaywallDismissed] = (0, import_react49.useState)(false);
7514
- const [overrideView, setOverrideView] = (0, import_react49.useState)(null);
7515
- const [cameFromPaywall, setCameFromPaywall] = (0, import_react49.useState)(false);
7516
- const initialFromPaywall = bootstrap.view === "paywall";
7015
+ const [overrideView, setOverrideView] = (0, import_react46.useState)(null);
7517
7016
  const resolvedView = resolveSurface(bootstrap.view);
7518
- const isPaywall = resolvedView === "paywall" && !paywallDismissed;
7519
- const effectiveView = overrideView ?? (isPaywall ? "paywall" : resolvedView);
7520
- const showShellHeader = effectiveView !== "nudge";
7521
- const isChrome = showShellHeader && effectiveView !== "paywall";
7522
- const fromPaywall = cameFromPaywall || initialFromPaywall;
7523
- const refreshedRef = (0, import_react49.useRef)(false);
7524
- (0, import_react49.useEffect)(() => {
7017
+ const effectiveView = overrideView ?? resolvedView;
7018
+ const refreshedRef = (0, import_react46.useRef)(false);
7019
+ (0, import_react46.useEffect)(() => {
7525
7020
  if (!onRefreshBootstrap) return;
7526
7021
  if (refreshedRef.current) return;
7527
- if (bootstrap.view === "paywall" || bootstrap.view === "nudge") return;
7528
7022
  refreshedRef.current = true;
7529
7023
  void Promise.resolve(onRefreshBootstrap()).catch(() => {
7530
7024
  });
7531
7025
  }, [onRefreshBootstrap, bootstrap.view]);
7532
7026
  const showFooter = footer ?? Boolean(merchant?.termsUrl || merchant?.privacyUrl);
7533
- const isShellSidebarEligible = isChrome && bootstrap.customer !== null;
7534
- const productName = bootstrap.product?.name ?? null;
7535
- const productDescription = bootstrap.product?.description ?? null;
7536
- const handlePaywallUpgrade = () => {
7537
- setPaywallDismissed(true);
7538
- setCameFromPaywall(true);
7539
- setOverrideView("checkout");
7540
- };
7541
- const handleNudgeCta = () => {
7542
- setOverrideView("checkout");
7543
- };
7544
- const handleChangePlan = () => {
7545
- setCameFromPaywall(false);
7546
- setOverrideView("checkout");
7547
- };
7548
- return /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: "solvapay-mcp-shell", "data-paywall": isPaywall ? "true" : void 0, children: [
7549
- showShellHeader ? /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
7550
- ShellHeader,
7551
- {
7552
- merchant,
7553
- productName,
7554
- productDescription,
7555
- classNames
7556
- }
7557
- ) : null,
7558
- /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: "solvapay-mcp-shell-layout", children: [
7559
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: "solvapay-mcp-shell-body", children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
7027
+ const isShellSidebarEligible = bootstrap.customer !== null;
7028
+ return /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("div", { className: "solvapay-mcp-shell", children: [
7029
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("div", { className: "solvapay-mcp-shell-layout", children: [
7030
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className: "solvapay-mcp-shell-body", children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
7560
7031
  McpViewRouter,
7561
7032
  {
7562
7033
  view: effectiveView,
@@ -7564,18 +7035,14 @@ function McpAppShell({
7564
7035
  views,
7565
7036
  classNames,
7566
7037
  suppressDetailCards: isShellSidebarEligible,
7567
- fromPaywall,
7568
7038
  onSurfaceChange: setOverrideView,
7569
- onPaywallUpgrade: handlePaywallUpgrade,
7570
- onNudgeCta: handleNudgeCta,
7571
- onChangePlan: handleChangePlan,
7572
7039
  onRefreshBootstrap,
7573
7040
  onClose
7574
7041
  }
7575
7042
  ) }),
7576
- isShellSidebarEligible ? /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("aside", { className: "solvapay-mcp-shell-sidebar", "aria-label": "Your account context", children: [
7577
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(McpSellerDetailsCard, { classNames }),
7578
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
7043
+ isShellSidebarEligible ? /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("aside", { className: "solvapay-mcp-shell-sidebar", "aria-label": "Your account context", children: [
7044
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(McpSellerDetailsCard, { classNames }),
7045
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
7579
7046
  McpCustomerDetailsCard,
7580
7047
  {
7581
7048
  classNames,
@@ -7584,35 +7051,7 @@ function McpAppShell({
7584
7051
  )
7585
7052
  ] }) : null
7586
7053
  ] }),
7587
- isChrome && showFooter ? /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(ShellFooter, { classNames, merchant }) : null
7588
- ] });
7589
- }
7590
- function ShellHeader({
7591
- merchant,
7592
- productName,
7593
- productDescription,
7594
- classNames
7595
- }) {
7596
- const cx = resolveMcpClassNames(classNames);
7597
- const displayName = merchant?.displayName ?? null;
7598
- const logoUrl = merchant?.logoUrl ?? null;
7599
- const initials = displayName ? displayName.split(/\s+/).filter(Boolean).slice(0, 2).map((part) => part[0].toUpperCase()).join("") : "SP";
7600
- const headingText = productName ?? displayName ?? "My account";
7601
- const tagline = productName && productDescription ? productDescription.trim() : null;
7602
- return /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("header", { className: "solvapay-mcp-shell-header", children: [
7603
- /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: "solvapay-mcp-shell-brand", children: [
7604
- logoUrl ? /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
7605
- "img",
7606
- {
7607
- className: "solvapay-mcp-shell-logo",
7608
- src: logoUrl,
7609
- alt: displayName ?? "Merchant logo"
7610
- }
7611
- ) : /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("span", { className: "solvapay-mcp-shell-logo-initials", "aria-hidden": "true", children: initials }),
7612
- displayName ? /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("span", { className: "solvapay-mcp-shell-brand-name", children: displayName }) : null
7613
- ] }),
7614
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("h1", { className: `${cx.heading} solvapay-mcp-shell-title`.trim(), children: headingText }),
7615
- tagline ? /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("p", { className: "solvapay-mcp-shell-tagline", children: tagline }) : null
7054
+ showFooter ? /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(ShellFooter, { classNames, merchant }) : null
7616
7055
  ] });
7617
7056
  }
7618
7057
  function ShellFooter({
@@ -7623,10 +7062,10 @@ function ShellFooter({
7623
7062
  const termsUrl = merchant?.termsUrl;
7624
7063
  const privacyUrl = merchant?.privacyUrl;
7625
7064
  if (!termsUrl && !privacyUrl) {
7626
- return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("footer", { className: `solvapay-mcp-shell-footer ${cx.muted}`.trim(), children: "Provided by SolvaPay" });
7065
+ return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("footer", { className: `solvapay-mcp-shell-footer ${cx.muted}`.trim(), children: "Provided by SolvaPay" });
7627
7066
  }
7628
- return /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("footer", { className: `solvapay-mcp-shell-footer ${cx.muted}`.trim(), children: [
7629
- termsUrl ? /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(
7067
+ return /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("footer", { className: `solvapay-mcp-shell-footer ${cx.muted}`.trim(), children: [
7068
+ termsUrl ? /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(
7630
7069
  "a",
7631
7070
  {
7632
7071
  className: "solvapay-mcp-shell-footer-link",
@@ -7636,12 +7075,12 @@ function ShellFooter({
7636
7075
  "aria-label": "Terms (opens in a new tab)",
7637
7076
  children: [
7638
7077
  "Terms",
7639
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(ExternalLinkGlyph, {})
7078
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(ExternalLinkGlyph, {})
7640
7079
  ]
7641
7080
  }
7642
7081
  ) : null,
7643
- termsUrl && privacyUrl ? /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("span", { "aria-hidden": "true", children: " \xB7 " }) : null,
7644
- privacyUrl ? /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(
7082
+ termsUrl && privacyUrl ? /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("span", { "aria-hidden": "true", children: " \xB7 " }) : null,
7083
+ privacyUrl ? /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(
7645
7084
  "a",
7646
7085
  {
7647
7086
  className: "solvapay-mcp-shell-footer-link",
@@ -7651,12 +7090,12 @@ function ShellFooter({
7651
7090
  "aria-label": "Privacy (opens in a new tab)",
7652
7091
  children: [
7653
7092
  "Privacy",
7654
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(ExternalLinkGlyph, {})
7093
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(ExternalLinkGlyph, {})
7655
7094
  ]
7656
7095
  }
7657
7096
  ) : null,
7658
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("span", { "aria-hidden": "true", children: " \xB7 " }),
7659
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("span", { children: "Provided by SolvaPay" })
7097
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("span", { "aria-hidden": "true", children: " \xB7 " }),
7098
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("span", { children: "Provided by SolvaPay" })
7660
7099
  ] });
7661
7100
  }
7662
7101
  function McpViewRouter({
@@ -7665,38 +7104,26 @@ function McpViewRouter({
7665
7104
  views,
7666
7105
  classNames,
7667
7106
  suppressDetailCards,
7668
- fromPaywall,
7669
7107
  onSurfaceChange,
7670
- onPaywallUpgrade,
7671
- onNudgeCta,
7672
- onChangePlan,
7673
7108
  onRefreshBootstrap,
7674
7109
  onClose
7675
7110
  }) {
7676
- const { productRef, stripePublishableKey, returnUrl, paywall } = bootstrap;
7677
- const locale = useHostLocale();
7111
+ const { productRef, stripePublishableKey, returnUrl } = bootstrap;
7678
7112
  const CheckoutView = views?.checkout ?? McpCheckoutView;
7679
7113
  const AccountView = views?.account ?? McpAccountView;
7680
7114
  const TopupView = views?.topup ?? McpTopupView;
7681
- const PaywallView = views?.paywall ?? McpPaywallView;
7682
- const NudgeView = views?.nudge ?? McpNudgeView;
7683
7115
  const goCheckout = onSurfaceChange ? () => onSurfaceChange("checkout") : void 0;
7684
7116
  const goTopup = onSurfaceChange ? () => onSurfaceChange("topup") : void 0;
7685
7117
  const goAccount = onSurfaceChange ? () => onSurfaceChange("account") : void 0;
7686
- const changePlan = onChangePlan ?? goCheckout;
7687
- const nudgeCta = onNudgeCta ?? goCheckout;
7688
- const paywallUpgrade = onPaywallUpgrade ?? goCheckout;
7689
7118
  switch (view) {
7690
7119
  case "checkout":
7691
- return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
7120
+ return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
7692
7121
  CheckoutView,
7693
7122
  {
7694
7123
  productRef,
7695
7124
  publishableKey: stripePublishableKey,
7696
7125
  returnUrl,
7697
7126
  classNames,
7698
- fromPaywall,
7699
- paywallKind: paywall?.kind,
7700
7127
  plans: bootstrap.plans,
7701
7128
  onRequestTopup: goTopup,
7702
7129
  onRefreshBootstrap,
@@ -7704,17 +7131,17 @@ function McpViewRouter({
7704
7131
  }
7705
7132
  );
7706
7133
  case "account":
7707
- return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
7134
+ return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
7708
7135
  AccountView,
7709
7136
  {
7710
7137
  classNames,
7711
7138
  onTopup: goTopup,
7712
- onChangePlan: changePlan,
7139
+ onChangePlan: goCheckout,
7713
7140
  hideDetailCards: suppressDetailCards
7714
7141
  }
7715
7142
  );
7716
7143
  case "topup":
7717
- return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
7144
+ return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
7718
7145
  TopupView,
7719
7146
  {
7720
7147
  publishableKey: stripePublishableKey,
@@ -7723,70 +7150,100 @@ function McpViewRouter({
7723
7150
  onBack: goAccount
7724
7151
  }
7725
7152
  );
7726
- case "paywall": {
7727
- if (!paywall) return null;
7728
- const upgradeCandidate = findRecurringPlan(bootstrap.plans);
7729
- const upgradeCta = upgradeCandidate && paywallUpgrade ? { label: formatUpgradeLabel(upgradeCandidate, locale), onClick: paywallUpgrade } : void 0;
7730
- return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
7731
- PaywallView,
7732
- {
7733
- content: paywall,
7734
- publishableKey: stripePublishableKey,
7735
- returnUrl,
7736
- classNames,
7737
- plans: bootstrap.plans,
7738
- upgradeCta
7739
- }
7740
- );
7741
- }
7742
- case "nudge":
7743
- return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
7744
- NudgeView,
7745
- {
7746
- bootstrap,
7747
- onCta: nudgeCta,
7748
- classNames
7749
- }
7750
- );
7751
7153
  default:
7752
7154
  return null;
7753
7155
  }
7754
7156
  }
7755
- function findRecurringPlan(plans) {
7756
- const list = plans;
7757
- if (!list || list.length === 0) return null;
7758
- const match = list.find((p) => {
7759
- if (p.planType !== "recurring") return false;
7760
- return !p.meterRef;
7761
- });
7762
- return match ?? null;
7763
- }
7764
- var BILLING_CYCLE_SUFFIX = {
7765
- daily: "d",
7766
- weekly: "wk",
7767
- monthly: "mo",
7768
- quarterly: "qtr",
7769
- yearly: "yr",
7770
- annual: "yr",
7771
- annually: "yr"
7772
- };
7773
- function abbreviateBillingCycle(cycle) {
7774
- const key = cycle.toLowerCase();
7775
- if (BILLING_CYCLE_SUFFIX[key]) return BILLING_CYCLE_SUFFIX[key];
7776
- return key.slice(0, 2);
7157
+
7158
+ // src/mcp/views/AppHeader.tsx
7159
+ var import_react48 = require("react");
7160
+
7161
+ // src/mcp/hooks/useHostInfo.tsx
7162
+ var import_react47 = require("react");
7163
+ var import_jsx_runtime36 = require("react/jsx-runtime");
7164
+ var McpHostInfoContext = (0, import_react47.createContext)(null);
7165
+ function McpHostInfoProvider({ hostName, children }) {
7166
+ return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(McpHostInfoContext.Provider, { value: hostName, children });
7167
+ }
7168
+ function useHostName() {
7169
+ return (0, import_react47.useContext)(McpHostInfoContext);
7777
7170
  }
7778
- function formatUpgradeLabel(plan, locale) {
7779
- const name = plan.name ?? "Unlimited";
7780
- if (typeof plan.price === "number" && plan.price > 0 && plan.currency) {
7781
- const amount = formatPrice(plan.price, plan.currency, { locale });
7782
- const cycle = plan.billingCycle ? `/${abbreviateBillingCycle(plan.billingCycle)}` : "";
7783
- return `Upgrade to ${name} \u2014 ${amount}${cycle}`;
7171
+
7172
+ // src/mcp/views/AppHeader.tsx
7173
+ var import_jsx_runtime37 = require("react/jsx-runtime");
7174
+ var HOSTS_WITH_MERCHANT_CHROME = /chatgpt|openai|claude/i;
7175
+ function useMerchantSafe() {
7176
+ const ctx = (0, import_react48.useContext)(SolvaPayContext);
7177
+ if (!ctx?._config) return null;
7178
+ const key = createTransportCacheKey(
7179
+ ctx._config,
7180
+ ctx._config.api?.getMerchant ?? "/api/merchant"
7181
+ );
7182
+ return merchantCache.get(key)?.merchant ?? null;
7183
+ }
7184
+ function getInitials(name) {
7185
+ const trimmed = name.trim();
7186
+ if (!trimmed) return "SP";
7187
+ const parts = trimmed.split(/\s+/).filter(Boolean);
7188
+ if (parts.length >= 2) {
7189
+ return parts.slice(0, 2).map((part) => part[0]?.toUpperCase() ?? "").join("");
7190
+ }
7191
+ const word = parts[0] ?? "";
7192
+ const firstChar = word[0]?.toUpperCase() ?? "";
7193
+ const innerUpper = word.slice(1).match(/[A-Z]/);
7194
+ if (innerUpper) return firstChar + innerUpper[0];
7195
+ return (word.slice(0, 2) || "SP").toUpperCase();
7196
+ }
7197
+ function AppHeader({
7198
+ mode = "auto",
7199
+ className,
7200
+ classNames,
7201
+ merchant: merchantProp,
7202
+ children
7203
+ }) {
7204
+ const cx = resolveMcpClassNames(classNames);
7205
+ const cachedMerchant = useMerchantSafe();
7206
+ const merchant = merchantProp !== void 0 ? merchantProp : cachedMerchant;
7207
+ const hostName = useHostName();
7208
+ const name = merchant?.displayName ?? "SolvaPay";
7209
+ const iconUrl = merchant?.iconUrl ?? merchant?.logoUrl ?? null;
7210
+ const [imgFailed, setImgFailed] = (0, import_react48.useState)(false);
7211
+ const [imgLoaded, setImgLoaded] = (0, import_react48.useState)(false);
7212
+ const imgRef = (0, import_react48.useRef)(null);
7213
+ (0, import_react48.useLayoutEffect)(() => {
7214
+ const el = imgRef.current;
7215
+ const cached = el ? el.complete && el.naturalHeight > 0 : false;
7216
+ setImgFailed(false);
7217
+ setImgLoaded(cached);
7218
+ }, [iconUrl]);
7219
+ if (mode === "never") return null;
7220
+ if (mode === "auto" && hostName && HOSTS_WITH_MERCHANT_CHROME.test(hostName)) {
7221
+ return null;
7784
7222
  }
7785
- return `Upgrade to ${name}`;
7223
+ const rootClass = [cx.appHeader, className].filter(Boolean).join(" ");
7224
+ const hasIconUrl = iconUrl !== null && !imgFailed;
7225
+ const showInitials = !hasIconUrl || !imgLoaded;
7226
+ return /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)("header", { className: rootClass, children: [
7227
+ hasIconUrl ? /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
7228
+ "img",
7229
+ {
7230
+ ref: imgRef,
7231
+ className: cx.appHeaderIcon,
7232
+ src: iconUrl,
7233
+ alt: "",
7234
+ style: imgLoaded ? void 0 : { display: "none" },
7235
+ onLoad: () => setImgLoaded(true),
7236
+ onError: () => setImgFailed(true)
7237
+ }
7238
+ ) : null,
7239
+ showInitials ? /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("span", { className: cx.appHeaderInitials, "aria-hidden": "true", children: getInitials(name) }) : null,
7240
+ /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("span", { className: cx.appHeaderName, children: name }),
7241
+ children ? /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("span", { className: "solvapay-mcp-app-header-slot", children }) : null
7242
+ ] });
7786
7243
  }
7787
7244
 
7788
7245
  // src/mcp/McpApp.tsx
7789
- var import_jsx_runtime40 = require("react/jsx-runtime");
7246
+ var import_jsx_runtime38 = require("react/jsx-runtime");
7790
7247
  function bootstrapToInitial(bs) {
7791
7248
  return {
7792
7249
  customerRef: bs.customer?.ref ?? null,
@@ -7811,50 +7268,44 @@ function McpApp({
7811
7268
  messageOnSuccess
7812
7269
  }) {
7813
7270
  const cx = resolveMcpClassNames(classNames);
7814
- const [bootstrap, setBootstrap] = (0, import_react50.useState)(null);
7815
- const [initError, setInitError] = (0, import_react50.useState)(null);
7816
- const pendingBootstrapFetchRef = (0, import_react50.useRef)(0);
7817
- const applyContextRef = (0, import_react50.useRef)(applyContext);
7818
- const onInitErrorRef = (0, import_react50.useRef)(onInitError);
7819
- (0, import_react50.useEffect)(() => {
7271
+ const [bootstrap, setBootstrap] = (0, import_react49.useState)(null);
7272
+ const [initError, setInitError] = (0, import_react49.useState)(null);
7273
+ const [hostName, setHostName] = (0, import_react49.useState)(null);
7274
+ const pendingBootstrapFetchRef = (0, import_react49.useRef)(0);
7275
+ const applyContextRef = (0, import_react49.useRef)(applyContext);
7276
+ const onInitErrorRef = (0, import_react49.useRef)(onInitError);
7277
+ (0, import_react49.useEffect)(() => {
7820
7278
  applyContextRef.current = applyContext;
7821
7279
  }, [applyContext]);
7822
- (0, import_react50.useEffect)(() => {
7280
+ (0, import_react49.useEffect)(() => {
7823
7281
  onInitErrorRef.current = onInitError;
7824
7282
  }, [onInitError]);
7825
- (0, import_react50.useEffect)(() => {
7283
+ (0, import_react49.useEffect)(() => {
7826
7284
  let cancelled = false;
7827
7285
  setInitError(null);
7828
7286
  setBootstrap(null);
7287
+ setHostName(null);
7829
7288
  app.onhostcontextchanged = (ctx) => {
7830
7289
  applyContextRef.current?.(ctx);
7831
7290
  };
7832
7291
  app.onteardown = async () => ({});
7833
- let resolveFirstNotification;
7834
- const firstNotificationApplied = new Promise((r) => {
7835
- resolveFirstNotification = r;
7836
- });
7837
7292
  const onToolResult = (params) => {
7838
7293
  if (cancelled) return;
7839
7294
  const toolName = app.getHostContext?.()?.toolInfo?.tool?.name ?? null;
7840
7295
  if (toolName && isTransportToolName(toolName)) return;
7841
- if (pendingBootstrapFetchRef.current) {
7842
- resolveFirstNotification?.();
7843
- return;
7844
- }
7296
+ if (pendingBootstrapFetchRef.current) return;
7845
7297
  try {
7846
7298
  const intentView = toolName ? import_mcp_core3.VIEW_FOR_TOOL[toolName] : void 0;
7847
- const fallbackView = intentView ?? "paywall";
7299
+ const fallbackView = intentView ?? "checkout";
7848
7300
  const fresh = parseBootstrapFromToolResult(
7849
7301
  params,
7850
7302
  toolName ?? "(unknown tool)",
7851
7303
  fallbackView
7852
7304
  );
7853
7305
  setBootstrap(fresh);
7854
- resolveFirstNotification?.();
7855
7306
  } catch (err) {
7856
7307
  if (typeof console !== "undefined") {
7857
- console.warn("[solvapay] ignoring malformed tool-result notification:", err);
7308
+ console.debug("[solvapay] non-bootstrap tool-result notification:", err);
7858
7309
  }
7859
7310
  }
7860
7311
  };
@@ -7877,21 +7328,7 @@ function McpApp({
7877
7328
  await app.connect();
7878
7329
  if (cancelled) return;
7879
7330
  applyContextRef.current?.(app.getHostContext());
7880
- const classification = classifyHostEntry(app);
7881
- if (classification.kind === "data") {
7882
- const timeoutMs = 2e3;
7883
- const timedOut = await Promise.race([
7884
- firstNotificationApplied.then(() => false),
7885
- new Promise((r) => setTimeout(() => r(true), timeoutMs))
7886
- ]);
7887
- if (cancelled) return;
7888
- if (timedOut) {
7889
- void Promise.resolve(app.requestTeardown?.()).catch(() => {
7890
- });
7891
- return;
7892
- }
7893
- return;
7894
- }
7331
+ setHostName(app.getHostVersion?.()?.name ?? null);
7895
7332
  pendingBootstrapFetchRef.current += 1;
7896
7333
  try {
7897
7334
  const result = await fetchMcpBootstrap(app);
@@ -7914,13 +7351,13 @@ function McpApp({
7914
7351
  unsubscribe?.();
7915
7352
  };
7916
7353
  }, [app]);
7917
- const transport = (0, import_react50.useMemo)(() => createMcpAppAdapter(app), [app]);
7918
- const initial = (0, import_react50.useMemo)(
7354
+ const transport = (0, import_react49.useMemo)(() => createMcpAppAdapter(app), [app]);
7355
+ const initial = (0, import_react49.useMemo)(
7919
7356
  () => bootstrap ? bootstrapToInitial(bootstrap) : void 0,
7920
7357
  [bootstrap]
7921
7358
  );
7922
7359
  const iconUrl = bootstrap?.merchant ? bootstrap.merchant.iconUrl ?? bootstrap.merchant.logoUrl ?? null : null;
7923
- (0, import_react50.useEffect)(() => {
7360
+ (0, import_react49.useEffect)(() => {
7924
7361
  if (typeof document === "undefined") return;
7925
7362
  if (!iconUrl) return;
7926
7363
  const MANAGED_ATTR = "data-solvapay-favicon";
@@ -7932,10 +7369,20 @@ function McpApp({
7932
7369
  link.rel = "icon";
7933
7370
  link.href = iconUrl;
7934
7371
  if (!existing) document.head.appendChild(link);
7372
+ const PRELOAD_ATTR = "data-solvapay-icon-preload";
7373
+ const existingPreload = document.head.querySelector(
7374
+ `link[${PRELOAD_ATTR}]`
7375
+ );
7376
+ const preload = existingPreload ?? document.createElement("link");
7377
+ preload.setAttribute(PRELOAD_ATTR, "");
7378
+ preload.rel = "preload";
7379
+ preload.as = "image";
7380
+ preload.href = iconUrl;
7381
+ if (!existingPreload) document.head.appendChild(preload);
7935
7382
  return () => {
7936
7383
  };
7937
7384
  }, [iconUrl]);
7938
- const providerConfig = (0, import_react50.useMemo)(
7385
+ const providerConfig = (0, import_react49.useMemo)(
7939
7386
  () => {
7940
7387
  const resolved = {
7941
7388
  // `SolvaPayProvider` short-circuits its fetch pipeline when there's
@@ -7964,12 +7411,12 @@ function McpApp({
7964
7411
  },
7965
7412
  [transport, initial, app]
7966
7413
  );
7967
- const seededInitialRef = (0, import_react50.useRef)(null);
7414
+ const seededInitialRef = (0, import_react49.useRef)(null);
7968
7415
  if (initial && seededInitialRef.current !== initial) {
7969
7416
  seedMcpCaches(initial, providerConfig);
7970
7417
  seededInitialRef.current = initial;
7971
7418
  }
7972
- const refreshBootstrap = (0, import_react50.useMemo)(
7419
+ const refreshBootstrap = (0, import_react49.useMemo)(
7973
7420
  () => async () => {
7974
7421
  pendingBootstrapFetchRef.current += 1;
7975
7422
  try {
@@ -7983,7 +7430,7 @@ function McpApp({
7983
7430
  },
7984
7431
  [app, providerConfig]
7985
7432
  );
7986
- const defaultOnClose = (0, import_react50.useMemo)(
7433
+ const defaultOnClose = (0, import_react49.useMemo)(
7987
7434
  () => () => {
7988
7435
  void Promise.resolve(app.requestTeardown?.()).catch(() => {
7989
7436
  });
@@ -7991,27 +7438,37 @@ function McpApp({
7991
7438
  [app]
7992
7439
  );
7993
7440
  const effectiveOnClose = onClose ?? defaultOnClose;
7994
- if (initError) {
7995
- return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("main", { className: "solvapay-mcp-main", children: /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: `${cx.card} ${cx.error}`.trim(), children: [
7996
- /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("h2", { className: cx.heading, children: "Unable to load SolvaPay" }),
7997
- /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("p", { children: initError })
7998
- ] }) });
7999
- }
8000
- if (!bootstrap) {
8001
- return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("main", { className: "solvapay-mcp-main", children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: cx.card, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("p", { children: "Loading\u2026" }) }) });
8002
- }
8003
- const effectiveBootstrap = productRefOverride ? { ...bootstrap, productRef: productRefOverride } : bootstrap;
8004
- return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(SolvaPayProvider, { config: providerConfig, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(McpBridgeProvider, { app, messageOnSuccess, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("main", { className: "solvapay-mcp-main", children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
8005
- McpAppShell,
8006
- {
8007
- bootstrap: effectiveBootstrap,
8008
- views,
8009
- classNames,
8010
- ...footer !== void 0 ? { footer } : {},
8011
- onRefreshBootstrap: refreshBootstrap,
8012
- onClose: effectiveOnClose
8013
- }
8014
- ) }) }) });
7441
+ const effectiveBootstrap = bootstrap && productRefOverride ? { ...bootstrap, productRef: productRefOverride } : bootstrap;
7442
+ return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(McpHostInfoProvider, { hostName, children: /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("main", { className: "solvapay-mcp-main", children: [
7443
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
7444
+ AppHeader,
7445
+ {
7446
+ classNames,
7447
+ merchant: effectiveBootstrap?.merchant ?? null
7448
+ }
7449
+ ),
7450
+ initError ? /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: `${cx.card} ${cx.error}`.trim(), children: [
7451
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("h2", { className: cx.heading, children: "Unable to load SolvaPay" }),
7452
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("p", { children: initError })
7453
+ ] }) : !effectiveBootstrap ? (
7454
+ // Intent-tool / fallback entries show a loading card while the
7455
+ // in-flight `fetchMcpBootstrap` call resolves. Data-tool iframe
7456
+ // entries no longer exist (payable merchant tools don't advertise
7457
+ // `_meta.ui.resourceUri`) so this is always legitimate user
7458
+ // feedback for an in-flight tool call.
7459
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("div", { className: cx.card, children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("p", { children: "Loading\u2026" }) })
7460
+ ) : /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(SolvaPayProvider, { config: providerConfig, children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(McpBridgeProvider, { app, messageOnSuccess, children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
7461
+ McpAppShell,
7462
+ {
7463
+ bootstrap: effectiveBootstrap,
7464
+ views,
7465
+ classNames,
7466
+ ...footer !== void 0 ? { footer } : {},
7467
+ onRefreshBootstrap: refreshBootstrap,
7468
+ onClose: effectiveOnClose
7469
+ }
7470
+ ) }) })
7471
+ ] }) });
8015
7472
  }
8016
7473
 
8017
7474
  // src/mcp/plan-actions.ts
@@ -8062,7 +7519,9 @@ function resolveActivityStrip(purchase) {
8062
7519
  }
8063
7520
  // Annotate the CommonJS export names for ESM import in node:
8064
7521
  0 && (module.exports = {
7522
+ AppHeader,
8065
7523
  BackLink,
7524
+ HOSTS_WITH_MERCHANT_CHROME,
8066
7525
  MCP_TOOL_NAMES,
8067
7526
  McpAccountView,
8068
7527
  McpApp,
@@ -8070,11 +7529,9 @@ function resolveActivityStrip(purchase) {
8070
7529
  McpBridgeProvider,
8071
7530
  McpCheckoutView,
8072
7531
  McpCustomerDetailsCard,
8073
- McpNudgeView,
8074
- McpPaywallView,
7532
+ McpHostInfoProvider,
8075
7533
  McpSellerDetailsCard,
8076
7534
  McpTopupView,
8077
- McpUpsellStrip,
8078
7535
  McpViewRouter,
8079
7536
  SOLVAPAY_TRANSPORT_TOOL_NAMES,
8080
7537
  classifyHostEntry,
@@ -8089,6 +7546,7 @@ function resolveActivityStrip(purchase) {
8089
7546
  resolvePlanShape,
8090
7547
  seedMcpCaches,
8091
7548
  useHostLocale,
7549
+ useHostName,
8092
7550
  useMcpBridge,
8093
7551
  useMcpToolResult,
8094
7552
  useStripeProbe,