@solvapay/server 2.4.1 → 2.5.0-preview-4dcf60c628500a6210ba69edbf7ae56ee47fbb3a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/edge.d.ts CHANGED
@@ -817,6 +817,12 @@ interface components {
817
817
  /** @description Whether the grant was recorded */
818
818
  success: boolean;
819
819
  };
820
+ LimitAutoRechargeDto: {
821
+ /** @description Whether auto-recharge is enabled for this provider */
822
+ enabled: boolean;
823
+ /** @description Stored auto-recharge status when a config exists */
824
+ status?: string;
825
+ };
820
826
  LimitBalanceDto: {
821
827
  /** @description Credit balance in credits (100 credits = 1 minor currency unit) */
822
828
  creditBalance: number;
@@ -829,6 +835,8 @@ interface components {
829
835
  LimitPlanItemDto: {
830
836
  /** @description Derived billing cycle */
831
837
  billingCycle?: string;
838
+ /** @description Deep link that opens hosted checkout with this plan preselected. Present only when a checkout session was minted for this response. */
839
+ checkoutUrl?: string;
832
840
  /**
833
841
  * @deprecated
834
842
  * @description Deprecated alias of perUnitChargeMinor. Same minor-units value — not credits. Prefer perUnitChargeMinor.
@@ -858,6 +866,8 @@ interface components {
858
866
  LimitResponse: {
859
867
  /** @description True when the customer must activate a priced default plan before usage is allowed */
860
868
  activationRequired?: boolean;
869
+ /** @description Per-provider auto-recharge snapshot read off the customer document. Omitted when no config exists. */
870
+ autoRecharge?: components['schemas']['LimitAutoRechargeDto'];
861
871
  /** @description Prepaid usage balance context when the default plan is usage-based */
862
872
  balance?: components['schemas']['LimitBalanceDto'];
863
873
  /**
@@ -878,9 +888,7 @@ interface components {
878
888
  creditsPerUnit?: number;
879
889
  /** @description ISO 4217 currency code for credit fields */
880
890
  currency?: string;
881
- /**
882
- * The effective finite cap for this meter. Present only when the backend measured a finite cap.
883
- */
891
+ /** @description The effective finite cap for this meter. Present only when the backend measured a finite cap. */
884
892
  limit?: number;
885
893
  /**
886
894
  * The meter name to use when tracking usage events
@@ -893,10 +901,21 @@ interface components {
893
901
  needsUpgrade?: boolean;
894
902
  /** @description Access is granted and usage beyond the included cap accrues an overage charge — `onExceed: charge`. */
895
903
  overage?: boolean;
904
+ /**
905
+ * Authoritative paywall classification shared with Managed MCP. Present on denial responses only.
906
+ * @enum {string}
907
+ */
908
+ paywallReason?: 'activation_required' | 'topup_required' | 'payment_required';
909
+ /** @description Display name of the active or default plan */
910
+ planName?: string;
911
+ /** @description Active plan reference when the customer already holds a purchase */
912
+ planRef?: string;
896
913
  /** @description Active plans on the product available for activation or checkout */
897
914
  plans?: components['schemas']['LimitPlanItemDto'][];
898
915
  /** @description Product the limit check applies to */
899
916
  product?: components['schemas']['LimitProductBriefDto'];
917
+ /** @description Active purchase reference when the customer already holds a purchase */
918
+ purchaseRef?: string;
900
919
  /**
901
920
  * Remaining usage units before hitting the limit. `-1` means unlimited (no finite cap).
902
921
  * @example 997
@@ -906,9 +925,7 @@ interface components {
906
925
  throttled?: boolean;
907
926
  /** @description The customer was auto-upgraded to the target pricing to restore access — `onExceed: auto_upgrade` succeeded. */
908
927
  upgraded?: boolean;
909
- /**
910
- * Consumed usage units this period. Present only when the backend measured a finite cap.
911
- */
928
+ /** @description Consumed usage units this period. Present only when the backend measured a finite cap. */
912
929
  used?: number;
913
930
  /**
914
931
  * Whether the customer is within their usage limits
@@ -3899,7 +3916,7 @@ type AttachBusinessDetailsParams = {
3899
3916
  type AttachBusinessDetailsResult = components['schemas']['AttachBusinessDetailsResponse'];
3900
3917
  type CheckLimitsRequest = components['schemas']['CheckLimitRequest'];
3901
3918
  /**
3902
- * Extended LimitResponse with SDK-added plan field.
3919
+ * `LimitResponse` plus a deprecated SDK-only `plan` alias.
3903
3920
  *
3904
3921
  * The backend `LimitResponse` now natively carries the `onExceed` outcome flags
3905
3922
  * (`throttled` / `overage` / `needsTopUp` / `needsUpgrade` / `upgraded`, resolved
@@ -3907,9 +3924,13 @@ type CheckLimitsRequest = components['schemas']['CheckLimitRequest'];
3907
3924
  * `overage` ride the allow path (`withinLimits: true`) so a protected handler
3908
3925
  * can read them from `decision.limits` and degrade service or note overage; the
3909
3926
  * others accompany a gate outcome.
3927
+ *
3928
+ * Read `planRef` for the active plan. `plan` is never populated by the
3929
+ * backend — it remains optional so older fixtures and callers still type-check.
3910
3930
  */
3911
3931
  type LimitResponseWithPlan = components['schemas']['LimitResponse'] & {
3912
- plan: string;
3932
+ /** @deprecated Never populated by the backend. Read `planRef` instead. */
3933
+ plan?: string;
3913
3934
  };
3914
3935
  /**
3915
3936
  * Extended CustomerResponse with proper field mapping
@@ -4182,6 +4203,16 @@ interface SolvaPayClient {
4182
4203
  type LimitPlanSummary = components['schemas']['LimitPlanItemDto'];
4183
4204
  type LimitActivationBalance = components['schemas']['LimitBalanceDto'];
4184
4205
  type LimitActivationProduct = components['schemas']['LimitProductBriefDto'];
4206
+ type LimitAutoRechargeDto = components['schemas']['LimitAutoRechargeDto'];
4207
+ /**
4208
+ * All paywall reasons the SDK recognises: every backend `paywallReason`
4209
+ * plus the three SDK-only classifier kinds. Derived from a shared tuple
4210
+ * so the Zod mirror in `paywall-schema.ts` cannot drift.
4211
+ */
4212
+ declare const PAYWALL_REASONS: readonly ["activation_required", "topup_required", "payment_required", "upgrade_required", "limit_reached", "reactivation_required"];
4213
+ type PaywallReason = (typeof PAYWALL_REASONS)[number];
4214
+ declare const PAYWALL_NEXT_ACTIONS: readonly ["topup", "checkout", "activate", "account"];
4215
+ type PaywallNextAction = (typeof PAYWALL_NEXT_ACTIONS)[number];
4185
4216
  /**
4186
4217
  * Arguments passed to protected handlers
4187
4218
  */
@@ -4218,8 +4249,10 @@ interface PaywallMetadata {
4218
4249
  * when the backend did not send it — never defaulted.
4219
4250
  */
4220
4251
  type PaywallGateRecoveryFields = {
4221
- /** Active plan reference from `limits.plan`. */
4252
+ /** Active plan reference from `limits.planRef` (falls back to deprecated `plan`). */
4222
4253
  planRef?: string;
4254
+ /** Display name of the active or default plan. */
4255
+ planName?: string;
4223
4256
  /** Product plans from `checkLimits` (activation already had this). */
4224
4257
  plans?: LimitPlanSummary[];
4225
4258
  /** Meter the gated call was charged against. */
@@ -4239,6 +4272,37 @@ type PaywallGateRecoveryFields = {
4239
4272
  };
4240
4273
  /** Prepaid credit balance, coalesced from nested or top-level fields. */
4241
4274
  creditBalance?: number;
4275
+ /**
4276
+ * `PaywallState.kind` — same vocabulary as the classifier, not a third enum.
4277
+ * `upgrade_required` / `limit_reached` / `reactivation_required` are
4278
+ * SDK-only; the backend's `paywallReason` is a smaller set
4279
+ * (`activation_required` / `topup_required` / `payment_required`).
4280
+ */
4281
+ reason?: PaywallReason;
4282
+ /** Single primary recovery the agent should take. */
4283
+ nextAction?: PaywallNextAction;
4284
+ /**
4285
+ * Credits deducted per call. Named `creditsPerCall` on purpose:
4286
+ * `balance.creditsPerUnit` is credits, but `plans[].creditsPerUnit`
4287
+ * is a deprecated alias for `perUnitChargeMinor` (minor currency units).
4288
+ */
4289
+ creditsPerCall?: number;
4290
+ /** `max(0, creditsPerCall - creditBalance)` when both are known. */
4291
+ shortfallCredits?: number;
4292
+ /** How many calls the current allowance or wallet still covers. */
4293
+ remainingCalls?: number;
4294
+ /** Active purchase reference when the customer already holds a purchase. */
4295
+ purchaseRef?: string;
4296
+ /** Purchase/plan status when the backend sent one. */
4297
+ planStatus?: string;
4298
+ /** Per-provider auto-recharge snapshot. Omitted when unknown. */
4299
+ autoRecharge?: LimitAutoRechargeDto;
4300
+ /** Global destinations. Per-plan URLs stay on `plans[].checkoutUrl`. */
4301
+ links?: {
4302
+ topup?: string;
4303
+ checkout?: string;
4304
+ manage?: string;
4305
+ };
4242
4306
  };
4243
4307
  type PaywallStructuredContent = ({
4244
4308
  kind: 'payment_required';
@@ -5431,6 +5495,7 @@ declare function paywallErrorToClientPayload(error: PaywallError): Record<string
5431
5495
 
5432
5496
  declare const PaywallStructuredContentSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
5433
5497
  planRef: z.ZodOptional<z.ZodString>;
5498
+ planName: z.ZodOptional<z.ZodString>;
5434
5499
  plans: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
5435
5500
  meterName: z.ZodOptional<z.ZodString>;
5436
5501
  unitPriceMinor: z.ZodOptional<z.ZodNumber>;
@@ -5443,12 +5508,41 @@ declare const PaywallStructuredContentSchema: z.ZodDiscriminatedUnion<[z.ZodObje
5443
5508
  creditBalance: z.ZodOptional<z.ZodNumber>;
5444
5509
  balance: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
5445
5510
  productDetails: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
5511
+ reason: z.ZodOptional<z.ZodEnum<{
5512
+ topup_required: "topup_required";
5513
+ payment_required: "payment_required";
5514
+ activation_required: "activation_required";
5515
+ upgrade_required: "upgrade_required";
5516
+ limit_reached: "limit_reached";
5517
+ reactivation_required: "reactivation_required";
5518
+ }>>;
5519
+ nextAction: z.ZodOptional<z.ZodEnum<{
5520
+ topup: "topup";
5521
+ checkout: "checkout";
5522
+ activate: "activate";
5523
+ account: "account";
5524
+ }>>;
5525
+ creditsPerCall: z.ZodOptional<z.ZodNumber>;
5526
+ shortfallCredits: z.ZodOptional<z.ZodNumber>;
5527
+ remainingCalls: z.ZodOptional<z.ZodNumber>;
5528
+ purchaseRef: z.ZodOptional<z.ZodString>;
5529
+ planStatus: z.ZodOptional<z.ZodString>;
5530
+ autoRecharge: z.ZodOptional<z.ZodObject<{
5531
+ enabled: z.ZodBoolean;
5532
+ status: z.ZodOptional<z.ZodString>;
5533
+ }, z.core.$strip>>;
5534
+ links: z.ZodOptional<z.ZodObject<{
5535
+ topup: z.ZodOptional<z.ZodString>;
5536
+ checkout: z.ZodOptional<z.ZodString>;
5537
+ manage: z.ZodOptional<z.ZodString>;
5538
+ }, z.core.$strip>>;
5446
5539
  kind: z.ZodLiteral<"payment_required">;
5447
5540
  product: z.ZodString;
5448
5541
  checkoutUrl: z.ZodString;
5449
5542
  message: z.ZodString;
5450
5543
  }, z.core.$strip>, z.ZodObject<{
5451
5544
  planRef: z.ZodOptional<z.ZodString>;
5545
+ planName: z.ZodOptional<z.ZodString>;
5452
5546
  plans: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
5453
5547
  meterName: z.ZodOptional<z.ZodString>;
5454
5548
  unitPriceMinor: z.ZodOptional<z.ZodNumber>;
@@ -5461,6 +5555,34 @@ declare const PaywallStructuredContentSchema: z.ZodDiscriminatedUnion<[z.ZodObje
5461
5555
  creditBalance: z.ZodOptional<z.ZodNumber>;
5462
5556
  balance: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
5463
5557
  productDetails: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
5558
+ reason: z.ZodOptional<z.ZodEnum<{
5559
+ topup_required: "topup_required";
5560
+ payment_required: "payment_required";
5561
+ activation_required: "activation_required";
5562
+ upgrade_required: "upgrade_required";
5563
+ limit_reached: "limit_reached";
5564
+ reactivation_required: "reactivation_required";
5565
+ }>>;
5566
+ nextAction: z.ZodOptional<z.ZodEnum<{
5567
+ topup: "topup";
5568
+ checkout: "checkout";
5569
+ activate: "activate";
5570
+ account: "account";
5571
+ }>>;
5572
+ creditsPerCall: z.ZodOptional<z.ZodNumber>;
5573
+ shortfallCredits: z.ZodOptional<z.ZodNumber>;
5574
+ remainingCalls: z.ZodOptional<z.ZodNumber>;
5575
+ purchaseRef: z.ZodOptional<z.ZodString>;
5576
+ planStatus: z.ZodOptional<z.ZodString>;
5577
+ autoRecharge: z.ZodOptional<z.ZodObject<{
5578
+ enabled: z.ZodBoolean;
5579
+ status: z.ZodOptional<z.ZodString>;
5580
+ }, z.core.$strip>>;
5581
+ links: z.ZodOptional<z.ZodObject<{
5582
+ topup: z.ZodOptional<z.ZodString>;
5583
+ checkout: z.ZodOptional<z.ZodString>;
5584
+ manage: z.ZodOptional<z.ZodString>;
5585
+ }, z.core.$strip>>;
5464
5586
  kind: z.ZodLiteral<"activation_required">;
5465
5587
  product: z.ZodString;
5466
5588
  checkoutUrl: z.ZodString;
@@ -5498,38 +5620,41 @@ type PaywallState = {
5498
5620
  } | {
5499
5621
  kind: 'reactivation_required';
5500
5622
  };
5623
+ type CreditSignals = {
5624
+ creditBalance?: number;
5625
+ creditsPerCall?: number;
5626
+ shortfallCredits?: number;
5627
+ remainingCalls?: number;
5628
+ isCreditBased: boolean;
5629
+ };
5630
+ /**
5631
+ * Coalesce the two credit-balance channels and derive shortfall /
5632
+ * remaining-call counts. Nested `balance` wins when present.
5633
+ */
5634
+ declare function creditSignals(limits: LimitResponseWithPlan | null): CreditSignals;
5635
+ declare function nextActionFor(state: PaywallState): PaywallNextAction;
5501
5636
  /**
5502
5637
  * Classify a `LimitResponseWithPlan` (or `null` on degraded paths) into
5503
5638
  * a `PaywallState`. Pure — safe to call multiple times per request.
5504
5639
  *
5505
5640
  * Precedence:
5506
- * 1. `activationRequired === true` — trumps everything else; the
5507
- * backend explicitly flagged that no plan is live yet.
5508
- * 2. Authoritative `needsTopUp` / `needsUpgrade` flags from
5509
- * `decideLimit`, when the backend sent them. Prefer these over
5510
- * the credit-balance heuristic so a top-up deny and an
5511
- * auto-upgrade deny are not re-derived from plan type.
5512
- * 3. Usage-based plan out of credits — the customer has a plan but
5513
- * ran out, so a topup is the right action. "Out of credits" is
5514
- * determined from (in order): the nested
5515
- * `balance.creditBalance === 0` block, the top-level
5516
- * `creditBalance === 0` field, or `remaining === 0` as a
5517
- * fallback for older backend responses that omit both credit
5518
- * fields on usage-based plans.
5519
- * 4. Active plan at included cap (`plan` is a non-empty ref and
5520
- * `remaining <= 0`) → `limit_reached`. This is the "on Free, used
5521
- * 3 of 3" case — not "no plan".
5522
- * 5. Everything else → `upgrade_required`, including:
5523
- * - `limits === null` (defensive),
5524
- * - no active plan on the product.
5641
+ * 1. `activationRequired` / `paywallReason === 'activation_required'`.
5642
+ * 2. `paywallReason === 'topup_required'` — backend stays authoritative
5643
+ * for credit-based denials (same rule as Managed MCP).
5644
+ * 3. Authoritative `needsTopUp` / `needsUpgrade` flags from `decideLimit`.
5645
+ * 4. Credit-field presence + a real shortfall (`balance < cost`).
5646
+ * 5. Active purchase / plan at included cap → `limit_reached`.
5647
+ * 6. Floor: never `upgrade_required` when credit fields or a purchase
5648
+ * are present. Everything else → `upgrade_required`.
5525
5649
  *
5526
5650
  * `reactivation_required` is deferred — it needs a distinct backend
5527
- * signal (future `LimitResponse.inactivePurchaseRef`) which isn't
5528
- * emitted yet. Kept in the type so downstream code compiles against
5529
- * the full discriminated union; `classifyPaywallState` will never
5530
- * return it under current backend behaviour.
5651
+ * signal which isn't emitted yet. Kept in the type so downstream code
5652
+ * compiles against the full discriminated union.
5531
5653
  */
5532
5654
  declare function classifyPaywallState(limits: LimitResponseWithPlan | null): PaywallState;
5655
+ /** Escape markdown link-label delimiters — plan names are provider-authored. */
5656
+ declare function linkLabel(name: string): string;
5657
+ declare function planLadder(gate: PaywallStructuredContent): string | null;
5533
5658
  /**
5534
5659
  * Produce the terminal-friendly gate message. Names the `account`
5535
5660
  * viewer (with a `view` hint when the landing screen matters) or
@@ -5574,13 +5699,10 @@ declare function buildNudgeMessage(state: PaywallState, limits: LimitResponseWit
5574
5699
  */
5575
5700
 
5576
5701
  /**
5577
- * Subset of `LimitResponseWithPlan` the helper actually reads. Keeps the
5578
- * signature flexible — callers can pass the raw `apiClient.checkLimits`
5579
- * result without first asserting the `plan` field.
5702
+ * `LimitResponseWithPlan` as returned by `apiClient.checkLimits`.
5703
+ * `plan` is optional and deprecated — the backend never sends it.
5580
5704
  */
5581
- type LimitsLike = Omit<LimitResponseWithPlan, 'plan'> & {
5582
- plan?: LimitResponseWithPlan['plan'];
5583
- };
5705
+ type LimitsLike = LimitResponseWithPlan;
5584
5706
  declare function buildPaywallGate(productRef: string, limits: LimitsLike): PaywallStructuredContent;
5585
5707
 
5586
5708
  /**
@@ -6309,4 +6431,4 @@ declare function verifyWebhook({ body, signature, secret, }: {
6309
6431
  secret: string;
6310
6432
  }): Promise<WebhookEvent>;
6311
6433
 
6312
- export { type ActivatePlanResult, type AuthenticatedUser, type ConfigureMcpPlansRequest, type ConfigureMcpPlansResponse, type CreateSolvaPayConfig, type CustomerBalanceResult, type CustomerResponseMapped, type CustomerWebhookObject, type ErrorResult, type GetUsageResult, type HttpAdapterOptions, type LimitActivationBalance, type LimitActivationProduct, type LimitPlanSummary, type LimitResponseWithPlan, type McpBootstrapPlanInput, type McpBootstrapRequest, type McpBootstrapResponse, type McpToolPlanMappingInput, type NextAdapterOptions, type OneTimePurchaseInfo, type PayableAllowResult, type PayableFunction, type PayableGateOptions, type PayableGateResult, type PayableOptions, type PayablePaywallResult, type PaymentMethodInfo, type PaywallArgs, type PaywallDecision, PaywallError, type PaywallMetadata, type PaywallState, type PaywallStructuredContent, PaywallStructuredContentSchema, type ProcessPaymentResult, type ProductConfigurationStatus, type PurchaseCheckResult, type RetryOptions, type SdkMerchantResponse, type SdkProductResponse, type ServerClientOptions, type SolvaPay, type SolvaPayClient, type ToolPlanMappingInput, type TopupProcessResult, type VerifyProductConfigurationOptions, type WebhookEvent, type WebhookEventForType, type WebhookEventObjectMap, type WebhookEventType, type WebhookProduct, activatePlanCore, attachBusinessDetailsCore, buildGateMessage, buildNudgeMessage, buildPaywallGate, cancelPurchaseCore, checkLimitsCore, checkPurchaseCore, classifyPaywallState, type components, createCheckoutSessionCore, createCustomerSessionCore, createPaymentIntentCore, createSolvaPay, createSolvaPayClient, createTopupPaymentIntentCore, deriveUsageSnapshot, disableAutoRechargeCore, getAuthenticatedUserCore, getAutoRechargeCore, getCustomerBalanceCore, getHistoryCore, getMerchantCore, getPaymentMethodCore, getProductCore, getUsageCore, handleRouteError, isErrorResult, isPaywallStructuredContent, listPlansCore, paywallErrorToClientPayload, processPaymentIntentCore, processTopupPaymentIntentCore, reactivatePurchaseCore, saveAutoRechargeCore, syncCustomerCore, trackUsageCore, verifyProductConfiguration, verifyWebhook, withRetry };
6434
+ export { type ActivatePlanResult, type AuthenticatedUser, type ConfigureMcpPlansRequest, type ConfigureMcpPlansResponse, type CreateSolvaPayConfig, type CreditSignals, type CustomerBalanceResult, type CustomerResponseMapped, type CustomerWebhookObject, type ErrorResult, type GetUsageResult, type HttpAdapterOptions, type LimitActivationBalance, type LimitActivationProduct, type LimitPlanSummary, type LimitResponseWithPlan, type McpBootstrapPlanInput, type McpBootstrapRequest, type McpBootstrapResponse, type McpToolPlanMappingInput, type NextAdapterOptions, type OneTimePurchaseInfo, type PayableAllowResult, type PayableFunction, type PayableGateOptions, type PayableGateResult, type PayableOptions, type PayablePaywallResult, type PaymentMethodInfo, type PaywallArgs, type PaywallDecision, PaywallError, type PaywallMetadata, type PaywallState, type PaywallStructuredContent, PaywallStructuredContentSchema, type ProcessPaymentResult, type ProductConfigurationStatus, type PurchaseCheckResult, type RetryOptions, type SdkMerchantResponse, type SdkProductResponse, type ServerClientOptions, type SolvaPay, type SolvaPayClient, type ToolPlanMappingInput, type TopupProcessResult, type VerifyProductConfigurationOptions, type WebhookEvent, type WebhookEventForType, type WebhookEventObjectMap, type WebhookEventType, type WebhookProduct, activatePlanCore, attachBusinessDetailsCore, buildGateMessage, buildNudgeMessage, buildPaywallGate, cancelPurchaseCore, checkLimitsCore, checkPurchaseCore, classifyPaywallState, type components, createCheckoutSessionCore, createCustomerSessionCore, createPaymentIntentCore, createSolvaPay, createSolvaPayClient, createTopupPaymentIntentCore, creditSignals, deriveUsageSnapshot, disableAutoRechargeCore, getAuthenticatedUserCore, getAutoRechargeCore, getCustomerBalanceCore, getHistoryCore, getMerchantCore, getPaymentMethodCore, getProductCore, getUsageCore, handleRouteError, isErrorResult, isPaywallStructuredContent, linkLabel, listPlansCore, nextActionFor, paywallErrorToClientPayload, planLadder, processPaymentIntentCore, processTopupPaymentIntentCore, reactivatePurchaseCore, saveAutoRechargeCore, syncCustomerCore, trackUsageCore, verifyProductConfiguration, verifyWebhook, withRetry };