@solvapay/server 1.0.0-preview.1

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.
@@ -0,0 +1,825 @@
1
+ interface components {
2
+ schemas: {
3
+ CreateSecretKey: Record<string, never>;
4
+ CheckName: Record<string, never>;
5
+ CreateAdminAgent: Record<string, never>;
6
+ UpdateAdminAgent: Record<string, never>;
7
+ Signup: Record<string, never>;
8
+ AuthResponse: Record<string, never>;
9
+ Login: Record<string, never>;
10
+ ForgotPassword: Record<string, never>;
11
+ ResetPassword: Record<string, never>;
12
+ VerifyEmail: Record<string, never>;
13
+ CreateUser: Record<string, never>;
14
+ UpdateUser: Record<string, never>;
15
+ UpdateProfile: Record<string, never>;
16
+ UpdatePreferences: Record<string, never>;
17
+ ChangePassword: Record<string, never>;
18
+ RequestEmailChange: Record<string, never>;
19
+ CreateConnectedAccount: Record<string, never>;
20
+ UpdateConnectedAccount: Record<string, never>;
21
+ CreatePlanRequest: Record<string, never>;
22
+ UpdatePlanRequest: Record<string, never>;
23
+ ExecuteAnalyticsQuery: Record<string, never>;
24
+ ExecuteMultipleQueries: Record<string, never>;
25
+ CheckLimitRequest: {
26
+ /**
27
+ * @description Customer reference identifier
28
+ * @example cus_3c4d5e6f7g8h
29
+ */
30
+ customerRef: string;
31
+ /**
32
+ * @description Agent reference identifier
33
+ * @example agt_1a2b3c4d5e6f
34
+ */
35
+ agentRef: string;
36
+ };
37
+ LimitResponse: {
38
+ /**
39
+ * @description Whether the customer is within their usage limits
40
+ * @example true
41
+ */
42
+ withinLimits: boolean;
43
+ /**
44
+ * @description Remaining usage units before hitting the limit
45
+ * @example 997
46
+ */
47
+ remaining: number;
48
+ /**
49
+ * @description Optional checkout URL if payment is required
50
+ * @example https://checkout.solvapay.com/pay_1a2b3c4d
51
+ */
52
+ checkoutUrl?: string;
53
+ };
54
+ UsageEvent: {
55
+ /**
56
+ * @description Customer reference identifier
57
+ * @example cus_3c4d5e6f7g8h
58
+ */
59
+ customerRef: string;
60
+ /**
61
+ * @description Agent reference identifier
62
+ * @example agt_1a2b3c4d5e6f
63
+ */
64
+ agentRef: string;
65
+ /**
66
+ * @description Outcome of the action
67
+ * @example success
68
+ * @enum {string}
69
+ */
70
+ outcome: "success" | "paywall" | "fail";
71
+ /**
72
+ * @description Optional action identifier
73
+ * @example generate_text
74
+ */
75
+ action?: string;
76
+ /**
77
+ * @description Unique request identifier matching the limits check
78
+ * @example req_1a2b3c4d5e6f
79
+ */
80
+ requestId: string;
81
+ /**
82
+ * @description Duration of the action in milliseconds
83
+ * @example 1250
84
+ */
85
+ actionDuration: number;
86
+ /**
87
+ * @description ISO 8601 timestamp of when the action occurred
88
+ * @example 2025-10-21T10:30:00.000Z
89
+ */
90
+ timestamp: string;
91
+ };
92
+ CreateCustomerRequest: {
93
+ /**
94
+ * @description Customer email address (required)
95
+ * @example customer@example.com
96
+ */
97
+ email: string;
98
+ /**
99
+ * @description Customer full name (optional)
100
+ * @example John Doe
101
+ */
102
+ name?: string;
103
+ };
104
+ SubscriptionInfo: {
105
+ /**
106
+ * @description Subscription reference
107
+ * @example sub_abc123
108
+ */
109
+ reference: string;
110
+ /**
111
+ * @description Plan name
112
+ * @example Pro Plan
113
+ */
114
+ planName: string;
115
+ /**
116
+ * @description Agent name
117
+ * @example AI Assistant
118
+ */
119
+ agentName: string;
120
+ /**
121
+ * @description Subscription status
122
+ * @example active
123
+ */
124
+ status: string;
125
+ /**
126
+ * @description Start date
127
+ * @example 2025-10-27T10:00:00Z
128
+ */
129
+ startDate: string;
130
+ };
131
+ CustomerResponse: {
132
+ /**
133
+ * @description Customer reference identifier
134
+ * @example cus_3c4d5e6f7g8h
135
+ */
136
+ reference: string;
137
+ /**
138
+ * @description Customer full name
139
+ * @example John Doe
140
+ */
141
+ name: string;
142
+ /**
143
+ * @description Customer email address
144
+ * @example customer@example.com
145
+ */
146
+ email: string;
147
+ /** @description Active subscriptions */
148
+ subscriptions?: components["schemas"]["SubscriptionInfo"][];
149
+ };
150
+ Agent: Record<string, never>;
151
+ CreateAgentRequest: Record<string, never>;
152
+ UpdateAgentRequest: Record<string, never>;
153
+ BasePlan: Record<string, never>;
154
+ SubscriptionResponse: {
155
+ /**
156
+ * @description Subscription reference identifier
157
+ * @example sub_1a2b3c4d5e6f
158
+ */
159
+ reference: string;
160
+ /**
161
+ * @description Customer reference identifier
162
+ * @example cus_3c4d5e6f7g8h
163
+ */
164
+ customerRef: string;
165
+ /**
166
+ * @description Customer email
167
+ * @example customer@example.com
168
+ */
169
+ customerEmail: string;
170
+ /**
171
+ * @description Customer name
172
+ * @example John Doe
173
+ */
174
+ customerName?: string;
175
+ /**
176
+ * @description Agent reference identifier
177
+ * @example agt_1a2b3c4d5e6f
178
+ */
179
+ agentRef: string;
180
+ /**
181
+ * @description Agent name
182
+ * @example My AI Agent
183
+ */
184
+ agentName: string;
185
+ /**
186
+ * @description Plan reference identifier
187
+ * @example pln_1a2b3c4d5e6f
188
+ */
189
+ planRef: string;
190
+ /**
191
+ * @description Plan name
192
+ * @example Premium Plan
193
+ */
194
+ planName: string;
195
+ /**
196
+ * @description Plan type
197
+ * @example recurring
198
+ * @enum {string}
199
+ */
200
+ planType: "recurring" | "usage-based" | "one-time" | "hybrid";
201
+ /**
202
+ * @description Subscription status
203
+ * @example active
204
+ * @enum {string}
205
+ */
206
+ status: "pending" | "active" | "expired" | "cancelled" | "suspended" | "refunded";
207
+ /**
208
+ * @description Amount paid in original currency (in cents)
209
+ * @example 9900
210
+ */
211
+ amount: number;
212
+ /**
213
+ * @description Currency code
214
+ * @example USD
215
+ */
216
+ currency: string;
217
+ /**
218
+ * @description Start date of subscription
219
+ * @example 2025-01-01T00:00:00.000Z
220
+ */
221
+ startDate: string;
222
+ /**
223
+ * @description End date of subscription (if applicable)
224
+ * @example 2025-02-01T00:00:00.000Z
225
+ */
226
+ endDate?: string;
227
+ /**
228
+ * @description When payment was confirmed
229
+ * @example 2025-01-01T00:00:00.000Z
230
+ */
231
+ paidAt?: string;
232
+ /** @description Usage quota information (for usage-based plans) */
233
+ usageQuota?: Record<string, never>;
234
+ /**
235
+ * @description Whether this is a recurring subscription
236
+ * @example true
237
+ */
238
+ isRecurring: boolean;
239
+ /**
240
+ * @description Next billing date (for recurring subscriptions)
241
+ * @example 2025-02-01T00:00:00.000Z
242
+ */
243
+ nextBillingDate?: string;
244
+ /**
245
+ * @description When subscription was cancelled (if applicable)
246
+ * @example 2025-01-15T00:00:00.000Z
247
+ */
248
+ cancelledAt?: string;
249
+ /**
250
+ * @description Reason for cancellation (if applicable)
251
+ * @example Customer request
252
+ */
253
+ cancellationReason?: string;
254
+ /**
255
+ * @description When subscription was created
256
+ * @example 2025-01-01T00:00:00.000Z
257
+ */
258
+ createdAt: string;
259
+ };
260
+ CancelSubscriptionRequest: {
261
+ /**
262
+ * @description Reason for cancellation
263
+ * @example Customer request
264
+ */
265
+ reason?: string;
266
+ };
267
+ CreatePageSettings: {
268
+ /** @description Page identifier */
269
+ id: string;
270
+ /** @description Page display name */
271
+ name: string;
272
+ /** @description Logo URL */
273
+ logo?: string;
274
+ /**
275
+ * @description Text color in hex format
276
+ * @example #2d3748
277
+ */
278
+ textColor: string;
279
+ /**
280
+ * @description Button color in hex format
281
+ * @example #3182ce
282
+ */
283
+ buttonColor: string;
284
+ /**
285
+ * @description Left background color in hex format
286
+ * @example #f7fafc
287
+ */
288
+ leftBackgroundColor: string;
289
+ /**
290
+ * @description Right background color in hex format
291
+ * @example #ffffff
292
+ */
293
+ rightBackgroundColor: string;
294
+ /**
295
+ * @description Font family
296
+ * @example Inter
297
+ */
298
+ fontFamily: string;
299
+ /**
300
+ * @description Font size
301
+ * @example 16px
302
+ */
303
+ fontSize: string;
304
+ };
305
+ };
306
+ responses: never;
307
+ parameters: never;
308
+ requestBodies: never;
309
+ headers: never;
310
+ pathItems: never;
311
+ }
312
+
313
+ /**
314
+ * SolvaPay API Client Type Definitions
315
+ *
316
+ * Types related to the SolvaPay API client and backend communication.
317
+ */
318
+
319
+ /**
320
+ * Extended LimitResponse with plan field
321
+ */
322
+ type LimitResponseWithPlan = components['schemas']['LimitResponse'] & {
323
+ plan: string;
324
+ };
325
+ /**
326
+ * Extended CustomerResponse with proper field mapping
327
+ */
328
+ type CustomerResponseMapped = {
329
+ customerRef: string;
330
+ email?: string;
331
+ name?: string;
332
+ plan?: string;
333
+ };
334
+ /**
335
+ * SolvaPay API Client Interface
336
+ *
337
+ * This interface defines the contract for communicating with the SolvaPay backend.
338
+ * Uses auto-generated types from the OpenAPI specification.
339
+ * You can provide your own implementation or use the default createSolvaPayClient().
340
+ */
341
+ interface SolvaPayClient {
342
+ checkLimits(params: components['schemas']['CheckLimitRequest']): Promise<LimitResponseWithPlan>;
343
+ trackUsage(params: components['schemas']['UsageEvent'] & {
344
+ planRef: string;
345
+ }): Promise<void>;
346
+ createCustomer?(params: components['schemas']['CreateCustomerRequest']): Promise<{
347
+ customerRef: string;
348
+ }>;
349
+ getCustomer?(params: {
350
+ customerRef: string;
351
+ }): Promise<CustomerResponseMapped>;
352
+ listAgents?(): Promise<Array<{
353
+ reference: string;
354
+ name: string;
355
+ description?: string;
356
+ }>>;
357
+ createAgent?(params: components['schemas']['CreateAgentRequest']): Promise<{
358
+ reference: string;
359
+ name: string;
360
+ }>;
361
+ deleteAgent?(agentRef: string): Promise<void>;
362
+ listPlans?(agentRef: string): Promise<Array<{
363
+ reference: string;
364
+ name: string;
365
+ isFreeTier?: boolean;
366
+ freeUnits?: number;
367
+ description?: string;
368
+ }>>;
369
+ createPlan?(params: components['schemas']['CreatePlanRequest'] & {
370
+ agentRef: string;
371
+ }): Promise<{
372
+ reference: string;
373
+ name: string;
374
+ }>;
375
+ deletePlan?(agentRef: string, planRef: string): Promise<void>;
376
+ createPaymentIntent?(params: {
377
+ agentRef: string;
378
+ planRef: string;
379
+ customerRef: string;
380
+ idempotencyKey?: string;
381
+ }): Promise<{
382
+ id: string;
383
+ clientSecret: string;
384
+ publishableKey: string;
385
+ accountId?: string;
386
+ }>;
387
+ }
388
+
389
+ /**
390
+ * Paywall Type Definitions
391
+ *
392
+ * Types related to paywall protection, limits, and gating functionality.
393
+ */
394
+ /**
395
+ * Arguments passed to protected handlers
396
+ */
397
+ interface PaywallArgs {
398
+ [key: string]: any;
399
+ auth?: {
400
+ customer_ref?: string;
401
+ };
402
+ }
403
+ /**
404
+ * Metadata for configuring paywall protection
405
+ */
406
+ interface PaywallMetadata {
407
+ agent?: string;
408
+ plan?: string;
409
+ }
410
+ /**
411
+ * Structured content for paywall errors
412
+ */
413
+ interface PaywallStructuredContent {
414
+ kind: 'payment_required';
415
+ agent: string;
416
+ checkoutUrl: string;
417
+ message: string;
418
+ }
419
+ /**
420
+ * MCP tool result with optional paywall information
421
+ */
422
+ interface PaywallToolResult {
423
+ content?: Array<{
424
+ type: 'text' | 'image' | 'resource';
425
+ text?: string;
426
+ data?: string;
427
+ mimeType?: string;
428
+ }>;
429
+ isError?: boolean;
430
+ structuredContent?: PaywallStructuredContent;
431
+ }
432
+
433
+ /**
434
+ * Configuration Options Type Definitions
435
+ *
436
+ * Types for configuring various aspects of the SDK including retry behavior,
437
+ * payable protection, and framework adapters.
438
+ */
439
+ /**
440
+ * Retry configuration options
441
+ */
442
+ interface RetryOptions$1 {
443
+ /**
444
+ * Maximum number of retry attempts (default: 2)
445
+ */
446
+ maxRetries?: number;
447
+ /**
448
+ * Initial delay between retries in milliseconds (default: 500)
449
+ */
450
+ initialDelay?: number;
451
+ /**
452
+ * Backoff strategy for calculating delay between retries (default: 'fixed')
453
+ * - 'fixed': Same delay between all retries
454
+ * - 'linear': Delay increases linearly (initialDelay * attempt)
455
+ * - 'exponential': Delay doubles each attempt (initialDelay * 2^(attempt-1))
456
+ */
457
+ backoffStrategy?: 'fixed' | 'linear' | 'exponential';
458
+ /**
459
+ * Optional function to determine if a retry should be attempted based on the error
460
+ * @param error The error that was thrown
461
+ * @param attempt The current attempt number (0-indexed)
462
+ * @returns true if a retry should be attempted, false otherwise
463
+ */
464
+ shouldRetry?: (error: Error, attempt: number) => boolean;
465
+ /**
466
+ * Optional callback invoked before each retry attempt
467
+ * @param error The error that triggered the retry
468
+ * @param attempt The current attempt number (0-indexed)
469
+ */
470
+ onRetry?: (error: Error, attempt: number) => void;
471
+ }
472
+ /**
473
+ * Options for configuring payable protection
474
+ */
475
+ interface PayableOptions {
476
+ /**
477
+ * Agent identifier (auto-detected from package.json if not provided)
478
+ */
479
+ agent?: string;
480
+ /**
481
+ * Agent reference (alias for agent, preferred for consistency with backend API)
482
+ */
483
+ agentRef?: string;
484
+ /**
485
+ * Plan identifier (defaults to agent name if not provided)
486
+ */
487
+ plan?: string;
488
+ /**
489
+ * Plan reference (alias for plan, preferred for consistency with backend API)
490
+ */
491
+ planRef?: string;
492
+ /**
493
+ * Optional function to extract customer reference from context
494
+ */
495
+ getCustomerRef?: (context: any) => string | Promise<string>;
496
+ }
497
+ /**
498
+ * HTTP adapter options for Express/Fastify
499
+ */
500
+ interface HttpAdapterOptions {
501
+ /**
502
+ * Extract arguments from HTTP request
503
+ */
504
+ extractArgs?: (req: any) => any;
505
+ /**
506
+ * Extract customer reference from HTTP request
507
+ */
508
+ getCustomerRef?: (req: any) => string | Promise<string>;
509
+ /**
510
+ * Transform the response before sending
511
+ */
512
+ transformResponse?: (result: any, reply: any) => any;
513
+ }
514
+ /**
515
+ * Next.js adapter options for App Router
516
+ */
517
+ interface NextAdapterOptions {
518
+ /**
519
+ * Extract arguments from Web Request
520
+ */
521
+ extractArgs?: (request: Request, context?: any) => any | Promise<any>;
522
+ /**
523
+ * Extract customer reference from Web Request
524
+ */
525
+ getCustomerRef?: (request: Request) => string | Promise<string>;
526
+ /**
527
+ * Transform the response before returning
528
+ */
529
+ transformResponse?: (result: any) => any;
530
+ }
531
+ /**
532
+ * MCP adapter options for MCP servers
533
+ */
534
+ interface McpAdapterOptions {
535
+ /**
536
+ * Extract customer reference from MCP args
537
+ */
538
+ getCustomerRef?: (args: any) => string | Promise<string>;
539
+ /**
540
+ * Transform the response before wrapping in MCP format
541
+ */
542
+ transformResponse?: (result: any) => any;
543
+ }
544
+
545
+ /**
546
+ * SolvaPay Factory
547
+ *
548
+ * Main entry point for creating SolvaPay instances with the unified payable API
549
+ */
550
+
551
+ /**
552
+ * Configuration for creating a SolvaPay instance
553
+ */
554
+ interface CreateSolvaPayConfig {
555
+ /**
556
+ * API key for production use (creates client automatically)
557
+ */
558
+ apiKey?: string;
559
+ /**
560
+ * API client for testing or custom implementations
561
+ */
562
+ apiClient?: SolvaPayClient;
563
+ /**
564
+ * Optional API base URL (only used with apiKey)
565
+ */
566
+ apiBaseUrl?: string;
567
+ }
568
+ /**
569
+ * Payable function that provides explicit adapters
570
+ */
571
+ interface PayableFunction {
572
+ /**
573
+ * HTTP adapter for Express/Fastify
574
+ */
575
+ http<T = any>(businessLogic: (args: any) => Promise<T>, options?: HttpAdapterOptions): (req: any, reply: any) => Promise<any>;
576
+ /**
577
+ * Next.js adapter for App Router
578
+ */
579
+ next<T = any>(businessLogic: (args: any) => Promise<T>, options?: NextAdapterOptions): (request: Request, context?: any) => Promise<Response>;
580
+ /**
581
+ * MCP adapter for Model Context Protocol servers
582
+ */
583
+ mcp<T = any>(businessLogic: (args: any) => Promise<T>, options?: McpAdapterOptions): (args: any) => Promise<any>;
584
+ /**
585
+ * Pure function adapter for direct function protection
586
+ * Use this for testing, background jobs, or non-framework contexts
587
+ */
588
+ function<T = any>(businessLogic: (args: any) => Promise<T>): Promise<(args: any) => Promise<T>>;
589
+ }
590
+ /**
591
+ * SolvaPay instance with payable method and common API methods
592
+ */
593
+ interface SolvaPay {
594
+ /**
595
+ * Create a payable handler with explicit adapters
596
+ */
597
+ payable(options?: PayableOptions): PayableFunction;
598
+ /**
599
+ * Ensure customer exists (for testing/setup)
600
+ * Only attempts creation once per customer (idempotent).
601
+ */
602
+ ensureCustomer(customerRef: string): Promise<string>;
603
+ /**
604
+ * Create a payment intent for a customer to subscribe to a plan
605
+ */
606
+ createPaymentIntent(params: {
607
+ agentRef: string;
608
+ planRef: string;
609
+ customerRef: string;
610
+ idempotencyKey?: string;
611
+ }): Promise<{
612
+ id: string;
613
+ clientSecret: string;
614
+ publishableKey: string;
615
+ accountId?: string;
616
+ }>;
617
+ /**
618
+ * Check if customer is within usage limits
619
+ */
620
+ checkLimits(params: {
621
+ customerRef: string;
622
+ agentRef: string;
623
+ }): Promise<{
624
+ withinLimits: boolean;
625
+ remaining: number;
626
+ plan: string;
627
+ checkoutUrl?: string;
628
+ }>;
629
+ /**
630
+ * Track usage for a customer action
631
+ */
632
+ trackUsage(params: {
633
+ customerRef: string;
634
+ agentRef: string;
635
+ planRef: string;
636
+ outcome: 'success' | 'paywall' | 'fail';
637
+ action?: string;
638
+ requestId: string;
639
+ actionDuration: number;
640
+ timestamp: string;
641
+ }): Promise<void>;
642
+ /**
643
+ * Create a new customer
644
+ */
645
+ createCustomer(params: {
646
+ email: string;
647
+ name?: string;
648
+ }): Promise<{
649
+ customerRef: string;
650
+ }>;
651
+ /**
652
+ * Get customer details
653
+ */
654
+ getCustomer(params: {
655
+ customerRef: string;
656
+ }): Promise<{
657
+ customerRef: string;
658
+ email?: string;
659
+ name?: string;
660
+ plan?: string;
661
+ }>;
662
+ /**
663
+ * Direct access to the API client for advanced operations
664
+ * (agent/plan management, etc.)
665
+ */
666
+ apiClient: SolvaPayClient;
667
+ }
668
+ /**
669
+ * Create a SolvaPay instance
670
+ *
671
+ * @param config - Configuration with either apiKey or apiClient
672
+ * @returns SolvaPay instance with payable() method
673
+ *
674
+ * @example
675
+ * ```typescript
676
+ * // Production: Pass API key
677
+ * const solvaPay = createSolvaPay({
678
+ * apiKey: process.env.SOLVAPAY_SECRET_KEY
679
+ * });
680
+ *
681
+ * // Testing: Pass mock client
682
+ * const solvaPay = createSolvaPay({
683
+ * apiClient: mockClient
684
+ * });
685
+ *
686
+ * // Create payable handlers
687
+ * const payable = solvaPay.payable({ agent: 'my-api' });
688
+ * app.post('/tasks', payable.http(createTask));
689
+ * export const POST = payable.next(createTask);
690
+ * ```
691
+ */
692
+ declare function createSolvaPay(config: CreateSolvaPayConfig): SolvaPay;
693
+
694
+ /**
695
+ * SolvaPay Server SDK - API Client
696
+ *
697
+ * This module provides the API client implementation for communicating with
698
+ * the SolvaPay backend. The client handles all HTTP requests for paywall
699
+ * protection, usage tracking, and resource management.
700
+ */
701
+
702
+ /**
703
+ * Configuration options for creating a SolvaPay API client
704
+ */
705
+ type ServerClientOptions = {
706
+ /**
707
+ * Your SolvaPay API key (required)
708
+ */
709
+ apiKey: string;
710
+ /**
711
+ * Base URL for the SolvaPay API (optional)
712
+ * Defaults to https://api-dev.solvapay.com
713
+ */
714
+ apiBaseUrl?: string;
715
+ };
716
+ /**
717
+ * Creates a SolvaPay API client that implements the full SolvaPayClient
718
+ * for server-side paywall and usage tracking operations.
719
+ *
720
+ * @param opts - Configuration options including API key and optional base URL
721
+ * @returns A fully configured SolvaPayClient instance
722
+ * @throws {SolvaPayError} If API key is missing
723
+ *
724
+ * @example
725
+ * ```typescript
726
+ * const client = createSolvaPayClient({
727
+ * apiKey: process.env.SOLVAPAY_SECRET_KEY!,
728
+ * apiBaseUrl: 'https://api.solvapay.com' // optional
729
+ * });
730
+ * ```
731
+ */
732
+ declare function createSolvaPayClient(opts: ServerClientOptions): SolvaPayClient;
733
+
734
+ /**
735
+ * SolvaPay SDK - Universal Paywall Protection
736
+ *
737
+ * One API that works everywhere:
738
+ * - HTTP frameworks (Fastify, Express)
739
+ * - MCP servers
740
+ * - Class-based and functional programming
741
+ */
742
+
743
+ declare class PaywallError extends Error {
744
+ structuredContent: PaywallStructuredContent;
745
+ constructor(message: string, structuredContent: PaywallStructuredContent);
746
+ }
747
+
748
+ /**
749
+ * Utility functions for the SolvaPay Server SDK
750
+ */
751
+ /**
752
+ * Retry configuration options
753
+ */
754
+ interface RetryOptions {
755
+ /**
756
+ * Maximum number of retry attempts (default: 2)
757
+ */
758
+ maxRetries?: number;
759
+ /**
760
+ * Initial delay between retries in milliseconds (default: 500)
761
+ */
762
+ initialDelay?: number;
763
+ /**
764
+ * Backoff strategy for calculating delay between retries (default: 'fixed')
765
+ * - 'fixed': Same delay between all retries
766
+ * - 'linear': Delay increases linearly (initialDelay * attempt)
767
+ * - 'exponential': Delay doubles each attempt (initialDelay * 2^(attempt-1))
768
+ */
769
+ backoffStrategy?: 'fixed' | 'linear' | 'exponential';
770
+ /**
771
+ * Optional function to determine if a retry should be attempted based on the error
772
+ * @param error The error that was thrown
773
+ * @param attempt The current attempt number (0-indexed)
774
+ * @returns true if a retry should be attempted, false otherwise
775
+ */
776
+ shouldRetry?: (error: Error, attempt: number) => boolean;
777
+ /**
778
+ * Optional callback invoked before each retry attempt
779
+ * @param error The error that triggered the retry
780
+ * @param attempt The current attempt number (0-indexed)
781
+ */
782
+ onRetry?: (error: Error, attempt: number) => void;
783
+ }
784
+ /**
785
+ * Executes an async function with automatic retry logic
786
+ *
787
+ * @template T The return type of the async function
788
+ * @param fn The async function to execute
789
+ * @param options Retry configuration options
790
+ * @returns A promise that resolves with the function result or rejects with the last error
791
+ *
792
+ * @example
793
+ * ```typescript
794
+ * // Simple retry with defaults
795
+ * const result = await withRetry(() => apiCall());
796
+ *
797
+ * // Custom retry with conditional logic
798
+ * const result = await withRetry(
799
+ * () => apiCall(),
800
+ * {
801
+ * maxRetries: 3,
802
+ * initialDelay: 1000,
803
+ * backoffStrategy: 'exponential',
804
+ * shouldRetry: (error) => error.message.includes('timeout'),
805
+ * onRetry: (error, attempt) => console.log(`Retry ${attempt + 1}`)
806
+ * }
807
+ * );
808
+ * ```
809
+ */
810
+ declare function withRetry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
811
+
812
+ /**
813
+ * SolvaPay Server SDK
814
+ *
815
+ * Main entry point for the SolvaPay server-side SDK.
816
+ * Provides unified payable API with explicit adapters for all frameworks.
817
+ */
818
+
819
+ declare function verifyWebhook({ body, signature, secret }: {
820
+ body: string;
821
+ signature: string;
822
+ secret: string;
823
+ }): any;
824
+
825
+ export { type CreateSolvaPayConfig, type HttpAdapterOptions, type McpAdapterOptions, type NextAdapterOptions, type PayableFunction, type PayableOptions, type PaywallArgs, PaywallError, type PaywallMetadata, type PaywallStructuredContent, type PaywallToolResult, type RetryOptions$1 as RetryOptions, type ServerClientOptions, type SolvaPay, type SolvaPayClient, createSolvaPay, createSolvaPayClient, verifyWebhook, withRetry };