@solvapay/server 1.2.0 → 1.2.1-preview-e89fa52f99b6d0c7bf9834fcf2d1403141051fa0

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/index.d.ts CHANGED
@@ -29,6 +29,15 @@ interface components {
29
29
  * @example usd
30
30
  */
31
31
  defaultCurrency?: string;
32
+ /**
33
+ * Full set of currencies a customer may pay credit topups in, including the default currency. Omitted/single-entry means single-currency behavior.
34
+ * @example [
35
+ * "USD",
36
+ * "EUR",
37
+ * "GBP"
38
+ * ]
39
+ */
40
+ supportedTopupCurrencies?: string[];
32
41
  /**
33
42
  * Descriptor appearing on the customer card statement
34
43
  * @example ACME INC
@@ -246,6 +255,33 @@ interface components {
246
255
  */
247
256
  checkoutUrl: string;
248
257
  };
258
+ PlanPricingOptionDto: {
259
+ /**
260
+ * ISO 4217 currency code
261
+ * @example USD
262
+ */
263
+ currency: string;
264
+ /**
265
+ * Price in smallest currency unit (e.g. cents)
266
+ * @example 2999
267
+ */
268
+ price: number;
269
+ /**
270
+ * Base price in smallest currency unit (hybrid plans)
271
+ * @example 1999
272
+ */
273
+ basePrice?: number;
274
+ /**
275
+ * One-time setup fee in smallest currency unit
276
+ * @example 500
277
+ */
278
+ setupFee?: number;
279
+ /**
280
+ * Whether this is the default currency option for the plan
281
+ * @example true
282
+ */
283
+ default?: boolean;
284
+ };
249
285
  Plan: {
250
286
  /**
251
287
  * Plan type exposed in SDK
@@ -283,6 +319,8 @@ interface components {
283
319
  * @example USD
284
320
  */
285
321
  currency: string;
322
+ /** @description Per-currency price options for this plan */
323
+ pricingOptions?: components["schemas"]["PlanPricingOptionDto"][];
286
324
  /**
287
325
  * Currency symbol (derived from currency)
288
326
  * @example $
@@ -376,6 +414,13 @@ interface components {
376
414
  price?: number;
377
415
  creditsPerUnit?: number;
378
416
  currency?: string;
417
+ pricingOptions?: {
418
+ currency: string;
419
+ price: number;
420
+ basePrice?: number;
421
+ setupFee?: number;
422
+ default?: boolean;
423
+ }[];
379
424
  /** @enum {string} */
380
425
  billingModel?: "pre-paid" | "post-paid";
381
426
  freeUnits?: number;
@@ -414,6 +459,13 @@ interface components {
414
459
  price?: number;
415
460
  creditsPerUnit?: number;
416
461
  currency?: string;
462
+ pricingOptions?: {
463
+ currency: string;
464
+ price: number;
465
+ basePrice?: number;
466
+ setupFee?: number;
467
+ default?: boolean;
468
+ }[];
417
469
  /** @enum {string} */
418
470
  billingModel?: "pre-paid" | "post-paid";
419
471
  freeUnits?: number;
@@ -658,6 +710,13 @@ interface components {
658
710
  name: string;
659
711
  price: number;
660
712
  currency: string;
713
+ pricingOptions?: {
714
+ currency: string;
715
+ price: number;
716
+ basePrice?: number;
717
+ setupFee?: number;
718
+ default?: boolean;
719
+ }[];
661
720
  /** @enum {string} */
662
721
  billingCycle?: "weekly" | "monthly" | "quarterly" | "yearly" | "custom";
663
722
  /** @enum {string} */
@@ -726,6 +785,13 @@ interface components {
726
785
  name: string;
727
786
  price: number;
728
787
  currency: string;
788
+ pricingOptions?: {
789
+ currency: string;
790
+ price: number;
791
+ basePrice?: number;
792
+ setupFee?: number;
793
+ default?: boolean;
794
+ }[];
729
795
  /** @enum {string} */
730
796
  billingCycle?: "weekly" | "monthly" | "quarterly" | "yearly" | "custom";
731
797
  /** @enum {string} */
@@ -759,6 +825,52 @@ interface components {
759
825
  CloneProductDto: {
760
826
  name?: string;
761
827
  };
828
+ CreditDebitSuccessResponse: {
829
+ /** @enum {number} */
830
+ debited: true;
831
+ /**
832
+ * Credits debited for this usage event
833
+ * @example 10
834
+ */
835
+ amount: number;
836
+ /**
837
+ * Estimated remaining units after debit
838
+ * @example 99
839
+ */
840
+ unitsRemaining: number;
841
+ };
842
+ CreditDebitSkippedResponse: {
843
+ /** @enum {number} */
844
+ debited: false;
845
+ /**
846
+ * Reason no credit debit was recorded
847
+ * @example duplicate
848
+ * @enum {string}
849
+ */
850
+ reason: "duplicate" | "no_product_ref" | "customer_not_found" | "no_active_purchase" | "plan_not_credit_based";
851
+ };
852
+ UsageRecordResponse: {
853
+ /** @example true */
854
+ success: boolean;
855
+ /** @example usage_A1B2C3D4 */
856
+ reference: string;
857
+ creditDebit?: components["schemas"]["CreditDebitSuccessResponse"] | components["schemas"]["CreditDebitSkippedResponse"];
858
+ };
859
+ BulkUsageResultResponse: {
860
+ /** @example usage_A1B2C3D4 */
861
+ reference: string;
862
+ creditDebit?: components["schemas"]["CreditDebitSuccessResponse"] | components["schemas"]["CreditDebitSkippedResponse"];
863
+ };
864
+ BulkUsageResponse: {
865
+ /** @example true */
866
+ success: boolean;
867
+ /**
868
+ * Number of usage events inserted
869
+ * @example 2
870
+ */
871
+ inserted: number;
872
+ results: components["schemas"]["BulkUsageResultResponse"][];
873
+ };
762
874
  CreateUsageRequest: {
763
875
  customerRef: string;
764
876
  /**
@@ -1028,6 +1140,8 @@ interface components {
1028
1140
  creditsPerUnit?: number;
1029
1141
  billingModel?: string;
1030
1142
  billingCycle?: string;
1143
+ /** @description Per-currency price options for this plan */
1144
+ pricingOptions?: components["schemas"]["PlanPricingOptionDto"][];
1031
1145
  };
1032
1146
  LimitBalanceDto: {
1033
1147
  /** @description Credit balance in mils */
@@ -1111,6 +1225,22 @@ interface components {
1111
1225
  };
1112
1226
  externalRef?: string;
1113
1227
  };
1228
+ GrantCustomerCreditsRequest: {
1229
+ credits: number;
1230
+ reason?: string;
1231
+ };
1232
+ GrantCustomerCreditsResponse: {
1233
+ /** @description Whether the grant was recorded */
1234
+ success: boolean;
1235
+ /** @description Customer reference identifier */
1236
+ customerRef: string;
1237
+ /** @description Granted credit amount */
1238
+ credits: number;
1239
+ /** @description Customer credit balance after the grant */
1240
+ balance: number;
1241
+ /** @description Machine-readable grant reason */
1242
+ reason?: string;
1243
+ };
1114
1244
  CreateCustomerSessionRequest: {
1115
1245
  customerRef: string;
1116
1246
  productRef?: string;
@@ -2014,12 +2144,7 @@ interface operations {
2014
2144
  [name: string]: unknown;
2015
2145
  };
2016
2146
  content: {
2017
- "application/json": {
2018
- /** @example true */
2019
- success?: boolean;
2020
- /** @example usage_A1B2C3D4 */
2021
- reference?: string;
2022
- };
2147
+ "application/json": components["schemas"]["UsageRecordResponse"];
2023
2148
  };
2024
2149
  };
2025
2150
  /** @description Validation failed */
@@ -2049,7 +2174,9 @@ interface operations {
2049
2174
  headers: {
2050
2175
  [name: string]: unknown;
2051
2176
  };
2052
- content?: never;
2177
+ content: {
2178
+ "application/json": components["schemas"]["BulkUsageResponse"];
2179
+ };
2053
2180
  };
2054
2181
  /** @description Validation failed */
2055
2182
  400: {
@@ -2581,6 +2708,43 @@ interface operations {
2581
2708
  };
2582
2709
  };
2583
2710
  };
2711
+ CustomerSdkController_grantCredits: {
2712
+ parameters: {
2713
+ query?: never;
2714
+ header?: {
2715
+ /** @description Provider-scoped idempotency key for safe grant retries */
2716
+ "Idempotency-Key"?: string;
2717
+ };
2718
+ path: {
2719
+ /** @description Customer reference identifier */
2720
+ reference: string;
2721
+ };
2722
+ cookie?: never;
2723
+ };
2724
+ requestBody: {
2725
+ content: {
2726
+ "application/json": components["schemas"]["GrantCustomerCreditsRequest"];
2727
+ };
2728
+ };
2729
+ responses: {
2730
+ /** @description Credits granted successfully */
2731
+ 200: {
2732
+ headers: {
2733
+ [name: string]: unknown;
2734
+ };
2735
+ content: {
2736
+ "application/json": components["schemas"]["GrantCustomerCreditsResponse"];
2737
+ };
2738
+ };
2739
+ /** @description Customer not found */
2740
+ 404: {
2741
+ headers: {
2742
+ [name: string]: unknown;
2743
+ };
2744
+ content?: never;
2745
+ };
2746
+ };
2747
+ };
2584
2748
  CustomerSdkController_createCustomerSession: {
2585
2749
  parameters: {
2586
2750
  query?: never;
@@ -2974,6 +3138,22 @@ type SdkMerchantResponse = components['schemas']['SdkMerchantResponseDto'];
2974
3138
  type SdkPlatformConfigResponse = components['schemas']['SdkPlatformConfigResponseDto'];
2975
3139
  /** SDK-facing product projection. Sourced from the existing OpenAPI spec. */
2976
3140
  type SdkProductResponse = components['schemas']['SdkProductResponse'];
3141
+ type CreditDebitSkipReason = components['schemas']['CreditDebitSkippedResponse']['reason'];
3142
+ type CreditDebitResult = components['schemas']['CreditDebitSuccessResponse'] | components['schemas']['CreditDebitSkippedResponse'];
3143
+ type TrackUsageRequest = Omit<Partial<components['schemas']['CreateUsageRequest']>, 'customerRef' | 'metadata'> & {
3144
+ customerRef: string;
3145
+ metadata?: Record<string, unknown>;
3146
+ };
3147
+ type TrackUsageResponse = components['schemas']['UsageRecordResponse'];
3148
+ interface TrackUsageBulkRequest {
3149
+ events: TrackUsageRequest[];
3150
+ }
3151
+ type TrackUsageBulkResponse = components['schemas']['BulkUsageResponse'];
3152
+ type AssignCreditsRequest = components['schemas']['GrantCustomerCreditsRequest'] & {
3153
+ customerRef: string;
3154
+ idempotencyKey?: string;
3155
+ };
3156
+ type AssignCreditsResponse = components['schemas']['GrantCustomerCreditsResponse'];
2977
3157
  type McpBootstrapPlanInput = NonNullable<components['schemas']['McpBootstrapDto']['plans']>[number];
2978
3158
  type ToolPlanMappingInput = NonNullable<components['schemas']['McpBootstrapDto']['tools']>[number];
2979
3159
  type McpBootstrapRequest = components['schemas']['McpBootstrapDto'];
@@ -3021,19 +3201,8 @@ interface ConfigureMcpPlansResponse {
3021
3201
  */
3022
3202
  interface SolvaPayClient {
3023
3203
  checkLimits(params: CheckLimitsRequest): Promise<LimitResponseWithPlan>;
3024
- trackUsage(params: {
3025
- customerRef: string;
3026
- actionType?: 'transaction' | 'api_call' | 'hour' | 'email' | 'storage' | 'custom';
3027
- units?: number;
3028
- outcome?: 'success' | 'paywall' | 'fail';
3029
- productRef?: string;
3030
- purchaseRef?: string;
3031
- description?: string;
3032
- metadata?: Record<string, unknown>;
3033
- duration?: number;
3034
- timestamp?: string;
3035
- idempotencyKey?: string;
3036
- }): Promise<void>;
3204
+ trackUsage(params: TrackUsageRequest): Promise<TrackUsageResponse>;
3205
+ trackUsageBulk?(params: TrackUsageBulkRequest): Promise<TrackUsageBulkResponse>;
3037
3206
  createCustomer?(params: components['schemas']['CreateCustomerRequest']): Promise<{
3038
3207
  customerRef: string;
3039
3208
  }>;
@@ -3057,6 +3226,7 @@ interface SolvaPayClient {
3057
3226
  externalRef?: string;
3058
3227
  email?: string;
3059
3228
  }): Promise<CustomerResponseMapped>;
3229
+ assignCredits?(params: AssignCreditsRequest): Promise<AssignCreditsResponse>;
3060
3230
  /**
3061
3231
  * SDK-facing merchant identity (GET /v1/sdk/merchant).
3062
3232
  * Returns the subset of provider fields safe for browser consumption —
@@ -3102,6 +3272,7 @@ interface SolvaPayClient {
3102
3272
  productRef: string;
3103
3273
  planRef: string;
3104
3274
  customerRef: string;
3275
+ currency?: string;
3105
3276
  idempotencyKey?: string;
3106
3277
  }): Promise<{
3107
3278
  processorPaymentId: string;
@@ -3729,12 +3900,12 @@ interface PayableFunction {
3729
3900
  * const solvaPay = createSolvaPay();
3730
3901
  *
3731
3902
  * // Create payable handlers
3732
- * const payable = solvaPay.payable({ product: 'prd_myapi' });
3733
- *
3734
- * // Manage customers
3735
- * const customerRef = await solvaPay.ensureCustomer('user_123', 'user_123', {
3736
- * email: 'user@example.com'
3737
- * });
3903
+ * const payable = solvaPay.payable({ product: 'prd_myapi' });
3904
+ *
3905
+ * // Manage customers
3906
+ * const customerRef = await solvaPay.ensureCustomer('user_123', 'user_123', {
3907
+ * email: 'user@example.com'
3908
+ * });
3738
3909
  * ```
3739
3910
  */
3740
3911
  interface SolvaPay {
@@ -3814,6 +3985,7 @@ interface SolvaPay {
3814
3985
  productRef: string;
3815
3986
  planRef: string;
3816
3987
  customerRef: string;
3988
+ currency?: string;
3817
3989
  idempotencyKey?: string;
3818
3990
  }): Promise<{
3819
3991
  processorPaymentId: string;
@@ -3941,19 +4113,11 @@ interface SolvaPay {
3941
4113
  * });
3942
4114
  * ```
3943
4115
  */
3944
- trackUsage(params: {
3945
- customerRef: string;
3946
- actionType?: 'transaction' | 'api_call' | 'hour' | 'email' | 'storage' | 'custom';
3947
- units?: number;
3948
- outcome?: 'success' | 'paywall' | 'fail';
3949
- productRef?: string;
3950
- purchaseRef?: string;
3951
- description?: string;
3952
- metadata?: Record<string, unknown>;
3953
- duration?: number;
3954
- timestamp?: string;
3955
- idempotencyKey?: string;
3956
- }): Promise<void>;
4116
+ trackUsage(params: TrackUsageRequest): Promise<TrackUsageResponse>;
4117
+ /**
4118
+ * Track usage events in bulk.
4119
+ */
4120
+ trackUsageBulk(params: TrackUsageBulkRequest): Promise<TrackUsageBulkResponse>;
3957
4121
  /**
3958
4122
  * Create a new customer in SolvaPay backend.
3959
4123
  *
@@ -4008,6 +4172,10 @@ interface SolvaPay {
4008
4172
  customerRef?: string;
4009
4173
  externalRef?: string;
4010
4174
  }): Promise<CustomerResponseMapped>;
4175
+ /**
4176
+ * Assign credits to a customer balance.
4177
+ */
4178
+ assignCredits(params: AssignCreditsRequest): Promise<AssignCreditsResponse>;
4011
4179
  /**
4012
4180
  * Get credits for a customer.
4013
4181
  *
@@ -4182,7 +4350,7 @@ interface SolvaPay {
4182
4350
  *
4183
4351
  * This factory function creates a SolvaPay instance that can be used to
4184
4352
  * protect API endpoints, functions, and MCP tools with usage limits and
4185
- * purchase checks.
4353
+ * purchase checks.
4186
4354
  *
4187
4355
  * @param config - Optional configuration object
4188
4356
  * @param config.apiKey - API key for production use (defaults to `SOLVAPAY_SECRET_KEY` env var)
@@ -4582,7 +4750,7 @@ declare function handleRouteError(error: unknown, operationName: string, default
4582
4750
  * the standard Web API Request (Express, Fastify, Next.js, Edge Functions, etc.).
4583
4751
  *
4584
4752
  * Resolution order:
4585
- * 1. `x-user-id` header — set by Next.js-style middleware (unchanged).
4753
+ * 1. `SOLVAPAY_USER_ID_HEADER` header — set by Next.js-style middleware (unchanged).
4586
4754
  * 2. `Authorization: Bearer <jwt>` — verified via HS256 when a secret is
4587
4755
  * configured (`SOLVAPAY_JWT_SECRET` or `SUPABASE_JWT_SECRET`), or
4588
4756
  * unverified-decoded when no secret is configured. The unverified path
@@ -4734,6 +4902,7 @@ declare function getCustomerBalanceCore(request: Request, options?: {
4734
4902
  declare function createPaymentIntentCore(request: Request, body: {
4735
4903
  planRef: string;
4736
4904
  productRef: string;
4905
+ currency?: string;
4737
4906
  }, options?: {
4738
4907
  solvaPay?: SolvaPay;
4739
4908
  includeEmail?: boolean;
@@ -5142,11 +5311,10 @@ declare function trackUsageCore(request: Request, body: {
5142
5311
  productRef?: string;
5143
5312
  description?: string;
5144
5313
  metadata?: Record<string, unknown>;
5314
+ idempotencyKey?: string;
5145
5315
  }, options?: {
5146
5316
  solvaPay?: SolvaPay;
5147
- }): Promise<{
5148
- success: true;
5149
- } | ErrorResult>;
5317
+ }): Promise<TrackUsageResponse | ErrorResult>;
5150
5318
 
5151
5319
  /**
5152
5320
  * SolvaPay Server SDK
@@ -5203,4 +5371,4 @@ declare function verifyWebhook({ body, signature, secret, }: {
5203
5371
  secret: string;
5204
5372
  }): WebhookEvent;
5205
5373
 
5206
- 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 McpServerLike, 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, type ProcessPaymentResult, type ProtectHandlerContext, type PurchaseCheckResult, type RegisterVirtualToolsMcpOptions, type RetryOptions, type SdkMerchantResponse, type SdkProductResponse, type ServerClientOptions, type SolvaPay, type SolvaPayClient, type ToolPlanMappingInput, type TopupProcessResult, VIRTUAL_TOOL_DEFINITIONS, type VirtualToolDefinition, type VirtualToolsOptions, type WebhookEvent, type WebhookEventForType, type WebhookEventObjectMap, type WebhookEventType, type WebhookProduct, activatePlanCore, buildGateMessage, buildNudgeMessage, buildPaywallGate, cancelPurchaseCore, checkLimitsCore, checkPurchaseCore, classifyPaywallState, type components, createCheckoutSessionCore, createCustomerSessionCore, createPaymentIntentCore, createSolvaPay, createSolvaPayClient, createTopupPaymentIntentCore, createVirtualTools, getAuthenticatedUserCore, getCustomerBalanceCore, getMerchantCore, getPaymentMethodCore, getProductCore, getUsageCore, handleRouteError, isErrorResult, isPaywallStructuredContent, jsonSchemaToZodRawShape, listPlansCore, paywallErrorToClientPayload, processPaymentIntentCore, processTopupPaymentIntentCore, reactivatePurchaseCore, registerVirtualToolsMcpImpl, syncCustomerCore, trackUsageCore, verifyWebhook, withRetry };
5374
+ export { type ActivatePlanResult, type AssignCreditsRequest, type AssignCreditsResponse, type AuthenticatedUser, type ConfigureMcpPlansRequest, type ConfigureMcpPlansResponse, type CreateSolvaPayConfig, type CreditDebitResult, type CreditDebitSkipReason, 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 McpServerLike, 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, type ProcessPaymentResult, type ProtectHandlerContext, type PurchaseCheckResult, type RegisterVirtualToolsMcpOptions, type RetryOptions, type SdkMerchantResponse, type SdkProductResponse, type ServerClientOptions, type SolvaPay, type SolvaPayClient, type ToolPlanMappingInput, type TopupProcessResult, type TrackUsageBulkRequest, type TrackUsageBulkResponse, type TrackUsageRequest, type TrackUsageResponse, VIRTUAL_TOOL_DEFINITIONS, type VirtualToolDefinition, type VirtualToolsOptions, type WebhookEvent, type WebhookEventForType, type WebhookEventObjectMap, type WebhookEventType, type WebhookProduct, activatePlanCore, buildGateMessage, buildNudgeMessage, buildPaywallGate, cancelPurchaseCore, checkLimitsCore, checkPurchaseCore, classifyPaywallState, type components, createCheckoutSessionCore, createCustomerSessionCore, createPaymentIntentCore, createSolvaPay, createSolvaPayClient, createTopupPaymentIntentCore, createVirtualTools, getAuthenticatedUserCore, getCustomerBalanceCore, getMerchantCore, getPaymentMethodCore, getProductCore, getUsageCore, handleRouteError, isErrorResult, isPaywallStructuredContent, jsonSchemaToZodRawShape, listPlansCore, paywallErrorToClientPayload, processPaymentIntentCore, processTopupPaymentIntentCore, reactivatePurchaseCore, registerVirtualToolsMcpImpl, syncCustomerCore, trackUsageCore, verifyWebhook, withRetry };