@solvapay/server 1.0.0-preview.17 → 1.0.0-preview.19

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
@@ -1,9 +1,13 @@
1
1
  interface components {
2
2
  schemas: {
3
+ UpdateProviderProfileDto: Record<string, never>;
3
4
  CreateSecretKey: Record<string, never>;
4
5
  CheckName: Record<string, never>;
5
6
  CreateAdminAgent: Record<string, never>;
6
7
  UpdateAdminAgent: Record<string, never>;
8
+ SdkAgentResponse: Record<string, never>;
9
+ CreateAgentRequest: Record<string, never>;
10
+ UpdateAgentRequest: Record<string, never>;
7
11
  Signup: Record<string, never>;
8
12
  AuthResponse: Record<string, never>;
9
13
  Login: Record<string, never>;
@@ -16,261 +20,333 @@ interface components {
16
20
  UpdatePreferences: Record<string, never>;
17
21
  ChangePassword: Record<string, never>;
18
22
  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
- CreateCustomerSessionRequest: {
24
- /**
25
- * @description Customer reference identifier
26
- * @example cus_3c4d5e6f7g8h
27
- */
28
- customerRef: string;
29
- };
30
- CustomerSessionResponse: {
31
- /**
32
- * @description Customer session ID
33
- * @example 507f1f77bcf86cd799439011
34
- */
35
- id: string;
36
- /**
37
- * @description Public session ID used in customer URL
38
- * @example e3f1c2d4b6a89f001122334455667788
39
- */
40
- sessionId: string;
41
- /**
42
- * @description Session status
43
- * @example active
44
- */
45
- status: string;
46
- /**
47
- * @description Customer URL to open the customer page
48
- * @example https://solvapay.com/customer/manage?id=e3f1c2d4b6a89f001122334455667788
49
- */
50
- customerUrl: string;
51
- };
52
- ExecuteAnalyticsQuery: Record<string, never>;
53
- ExecuteMultipleQueries: Record<string, never>;
54
23
  CreateCheckoutSessionRequest: {
55
24
  /**
56
- * @description Customer reference identifier
25
+ * Customer reference identifier
57
26
  * @example cus_3c4d5e6f7g8h
58
27
  */
59
28
  customerRef: string;
60
29
  /**
61
- * @description Agent reference identifier
30
+ * Agent reference identifier
62
31
  * @example agt_1a2b3c4d5e6f
63
32
  */
64
33
  agentRef: string;
65
34
  /**
66
- * @description Plan reference identifier (optional)
35
+ * Plan reference identifier (optional)
67
36
  * @example pln_2b3c4d5e6f7g
68
37
  */
69
38
  planRef?: string;
70
39
  /**
71
- * @description URL to redirect to after successful payment (optional)
40
+ * URL to redirect to after successful payment (optional)
72
41
  * @example https://example.com/payment-success
73
42
  */
74
43
  returnUrl?: string;
75
44
  };
76
45
  CheckoutSessionResponse: {
77
46
  /**
78
- * @description Checkout session ID
47
+ * Checkout session ID
79
48
  * @example 507f1f77bcf86cd799439011
80
49
  */
81
50
  id: string;
82
51
  /**
83
- * @description Public session ID used in checkout URL
52
+ * Public session ID used in checkout URL
84
53
  * @example a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6
85
54
  */
86
55
  sessionId: string;
87
56
  /**
88
- * @description Amount in cents
57
+ * Amount in cents
89
58
  * @example 2999
90
59
  */
91
60
  amount: number;
92
61
  /**
93
- * @description Currency code
62
+ * Currency code
94
63
  * @example USD
95
64
  */
96
65
  currency: string;
97
66
  /**
98
- * @description Session status
67
+ * Session status
99
68
  * @example active
100
69
  */
101
70
  status: string;
102
71
  /**
103
- * @description Checkout URL to open the checkout page
72
+ * Checkout URL to open the checkout page
104
73
  * @example https://solvapay.com/customer/checkout?id=a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6
105
74
  */
106
75
  checkoutUrl: string;
107
76
  };
108
77
  CancelSubscriptionRequest: {
109
78
  /**
110
- * @description Reason for cancellation
79
+ * Reason for cancellation
111
80
  * @example Customer request
112
81
  */
113
82
  reason?: string;
114
83
  };
115
- CheckLimitRequest: {
84
+ CreateConnectedAccount: Record<string, never>;
85
+ UpdateConnectedAccount: Record<string, never>;
86
+ CreateCheckoutSessionResponse: {
116
87
  /**
117
- * @description Customer reference identifier
118
- * @example cus_3c4d5e6f7g8h
88
+ * Checkout session ID/token
89
+ * @example e3f1c2d4b6a89f001122334455667788
119
90
  */
120
- customerRef: string;
91
+ sessionId: string;
121
92
  /**
122
- * @description Agent reference identifier
123
- * @example agt_1a2b3c4d5e6f
93
+ * Full checkout URL based on backend configuration (ready to redirect customer)
94
+ * @example https://solvapay.com/customer/checkout?id=e3f1c2d4b6a89f001122334455667788
124
95
  */
125
- agentRef: string;
96
+ checkoutUrl: string;
126
97
  };
127
- LimitResponse: {
98
+ CreatePlanRequest: {
128
99
  /**
129
- * @description Whether the customer is within their usage limits
130
- * @example true
100
+ * Plan name
101
+ * @example Basic Plan
131
102
  */
132
- withinLimits: boolean;
103
+ name: string;
133
104
  /**
134
- * @description Remaining usage units before hitting the limit
135
- * @example 997
105
+ * Plan description
106
+ * @example Basic recurring plan with monthly billing
136
107
  */
137
- remaining: number;
108
+ description?: string;
138
109
  /**
139
- * @description Optional checkout session ID/token if payment is required
140
- * @example e3f1c2d4b6a89f001122334455667788
110
+ * Plan type
111
+ * @example recurring
112
+ * @enum {string}
141
113
  */
142
- checkoutSessionId?: string;
114
+ type?: "recurring" | "usage-based" | "hybrid" | "one-time";
143
115
  /**
144
- * @description Optional full checkout URL if payment is required (based on backend configuration)
145
- * @example https://app.solvapay.com/customer/checkout?id=e3f1c2d4b6a89f001122334455667788
116
+ * Billing cycle
117
+ * @example monthly
118
+ * @enum {string}
146
119
  */
147
- checkoutUrl?: string;
148
- };
149
- UsageEvent: {
120
+ billingCycle?: "weekly" | "monthly" | "quarterly" | "yearly" | "custom";
150
121
  /**
151
- * @description Customer reference identifier
152
- * @example cus_3c4d5e6f7g8h
122
+ * Plan price
123
+ * @example 29.99
153
124
  */
154
- customerRef: string;
125
+ price?: number;
155
126
  /**
156
- * @description Agent reference identifier
157
- * @example agt_1a2b3c4d5e6f
127
+ * Currency code (ISO 4217)
128
+ * @example USD
129
+ * @enum {string}
158
130
  */
159
- agentRef: string;
131
+ currency?: "USD" | "EUR" | "GBP" | "SEK" | "NOK" | "DKK" | "CAD" | "AUD" | "JPY" | "CHF" | "PLN" | "CZK" | "HUF" | "RON" | "BGN" | "HRK" | "RSD" | "MKD" | "BAM" | "ALL" | "ISK" | "TRY" | "RUB" | "UAH" | "BYN" | "MDL" | "GEL" | "AMD" | "AZN" | "KZT" | "KGS" | "TJS" | "TMT" | "UZS" | "MNT" | "CNY" | "KRW" | "THB" | "VND" | "IDR" | "MYR" | "SGD" | "PHP" | "INR" | "PKR" | "BDT" | "LKR" | "NPR" | "AFN" | "IRR" | "IQD" | "JOD" | "KWD" | "LBP" | "OMR" | "QAR" | "SAR" | "SYP" | "AED" | "YER" | "ILS" | "EGP" | "MAD" | "TND" | "DZD" | "LYD" | "SDG" | "ETB" | "KES" | "TZS" | "UGX" | "RWF" | "BIF" | "DJF" | "SOS" | "ERN" | "SLL" | "GMD" | "GNF" | "CVE" | "STN" | "AOA" | "ZAR" | "BWP" | "SZL" | "LSL" | "NAD" | "ZMW" | "ZWL" | "MZN" | "MWK" | "MGA" | "MUR" | "SCR" | "KMF" | "MVR";
160
132
  /**
161
- * @description Outcome of the action
162
- * @example success
133
+ * Setup fee
134
+ * @example 0
135
+ */
136
+ setupFee?: number;
137
+ /**
138
+ * Trial days
139
+ * @example 7
140
+ */
141
+ trialDays?: number;
142
+ /**
143
+ * Number of free units included
144
+ * @example 100
145
+ */
146
+ freeUnits?: number;
147
+ /** @description Optional agent ID to associate plan with (not stored on plan, only used for initial association) */
148
+ agentId?: string;
149
+ /**
150
+ * Billing model for usage-based plans
151
+ * @example pre-paid
163
152
  * @enum {string}
164
153
  */
165
- outcome: "success" | "paywall" | "fail";
154
+ billingModel?: "pre-paid" | "post-paid";
166
155
  /**
167
- * @description Optional action identifier
168
- * @example generate_text
156
+ * Price per unit for usage-based plans
157
+ * @example 0.01
169
158
  */
170
- action?: string;
159
+ pricePerUnit?: number;
171
160
  /**
172
- * @description Unique request identifier matching the limits check
173
- * @example req_1a2b3c4d5e6f
161
+ * Unit name for usage-based plans
162
+ * @example request
174
163
  */
175
- requestId: string;
164
+ unit?: string;
176
165
  /**
177
- * @description Duration of the action in milliseconds
178
- * @example 1250
166
+ * Usage quota for usage-based plans
167
+ * @example 10000
179
168
  */
180
- actionDuration: number;
169
+ quota?: number;
181
170
  /**
182
- * @description ISO 8601 timestamp of when the action occurred
183
- * @example 2025-10-21T10:30:00.000Z
171
+ * Whether to rollover unused units
172
+ * @example false
184
173
  */
185
- timestamp: string;
174
+ rolloverUnusedUnits?: boolean;
175
+ /**
176
+ * Base price for hybrid plans
177
+ * @example 29.99
178
+ */
179
+ basePrice?: number;
180
+ /**
181
+ * Usage limits
182
+ * @example {
183
+ * "maxTransactions": 1000,
184
+ * "maxCalls": 500,
185
+ * "maxHours": 24
186
+ * }
187
+ */
188
+ limits?: Record<string, never>;
189
+ /**
190
+ * Plan features (can be array of strings or object with boolean flags)
191
+ * @example {
192
+ * "apiAccess": true,
193
+ * "prioritySupport": false
194
+ * }
195
+ */
196
+ features?: Record<string, never>;
197
+ /**
198
+ * Whether this is a free tier plan
199
+ * @example false
200
+ */
201
+ isFreeTier?: boolean;
202
+ /**
203
+ * Whether payment is required
204
+ * @example true
205
+ */
206
+ requiresPayment?: boolean;
207
+ /**
208
+ * Whether the plan is active
209
+ * @example true
210
+ */
211
+ isActive?: boolean;
212
+ /**
213
+ * Maximum number of active users
214
+ * @example 10
215
+ */
216
+ maxActiveUsers?: number;
217
+ /**
218
+ * Access expiry in days
219
+ * @example 30
220
+ */
221
+ accessExpiryDays?: number;
222
+ /** @description Additional metadata */
223
+ metadata?: Record<string, never>;
224
+ /** @description Usage tracking (internal use, not validated) */
225
+ customerUsage?: Record<string, never>;
226
+ /**
227
+ * Whether this is the default plan
228
+ * @example false
229
+ */
230
+ default?: boolean;
231
+ };
232
+ UpdatePlanRequest: Record<string, never>;
233
+ BasePlan: Record<string, never>;
234
+ CreateCustomerSessionRequest: {
235
+ /**
236
+ * Customer reference identifier
237
+ * @example cus_3c4d5e6f7g8h
238
+ */
239
+ customerRef: string;
240
+ };
241
+ CustomerSessionResponse: {
242
+ /**
243
+ * Customer session ID
244
+ * @example 507f1f77bcf86cd799439011
245
+ */
246
+ id: string;
247
+ /**
248
+ * Public session ID used in customer URL
249
+ * @example e3f1c2d4b6a89f001122334455667788
250
+ */
251
+ sessionId: string;
252
+ /**
253
+ * Session status
254
+ * @example active
255
+ */
256
+ status: string;
257
+ /**
258
+ * Customer URL to open the customer page
259
+ * @example https://solvapay.com/customer/manage?id=e3f1c2d4b6a89f001122334455667788
260
+ */
261
+ customerUrl: string;
186
262
  };
187
263
  CreateCustomerRequest: {
188
264
  /**
189
- * @description Customer email address (required)
265
+ * Customer email address (required)
190
266
  * @example customer@example.com
191
267
  */
192
268
  email: string;
193
269
  /**
194
- * @description Customer full name (optional)
270
+ * Customer full name (optional)
195
271
  * @example John Doe
196
272
  */
197
273
  name?: string;
198
274
  /**
199
- * @description External reference ID from your auth system to map this customer to an auth user (optional)
275
+ * External reference ID from your auth system to map this customer to an auth user (optional)
200
276
  * @example auth_user_12345
201
277
  */
202
278
  externalRef?: string;
203
279
  };
204
280
  SubscriptionInfo: {
205
281
  /**
206
- * @description Subscription reference
282
+ * Subscription reference
207
283
  * @example sub_abc123
208
284
  */
209
285
  reference: string;
210
286
  /**
211
- * @description Plan name
287
+ * Plan name
212
288
  * @example Pro Plan
213
289
  */
214
290
  planName: string;
215
291
  /**
216
- * @description Agent name
292
+ * Agent name
217
293
  * @example AI Assistant
218
294
  */
219
295
  agentName: string;
220
296
  /**
221
- * @description Subscription status
297
+ * Subscription status
222
298
  * @example active
223
299
  */
224
300
  status: string;
225
301
  /**
226
- * @description Start date
302
+ * Start date
227
303
  * @example 2025-10-27T10:00:00Z
228
304
  */
229
305
  startDate: string;
230
306
  /**
231
- * @description Amount paid in original currency (in cents)
307
+ * Amount paid in original currency (in cents)
232
308
  * @example 9900
233
309
  */
234
310
  amount: number;
235
311
  /**
236
- * @description Currency code
312
+ * Currency code
237
313
  * @example USD
238
314
  */
239
315
  currency: string;
240
316
  /**
241
- * @description End date of subscription
317
+ * End date of subscription
242
318
  * @example 2025-11-27T10:00:00Z
243
319
  */
244
320
  endDate?: string;
245
321
  /**
246
- * @description When subscription was cancelled
322
+ * When subscription was cancelled
247
323
  * @example 2025-10-28T10:00:00Z
248
324
  */
249
325
  cancelledAt?: string;
250
326
  /**
251
- * @description Reason for cancellation
327
+ * Reason for cancellation
252
328
  * @example Customer request
253
329
  */
254
330
  cancellationReason?: string;
255
331
  };
256
332
  CustomerResponse: {
257
333
  /**
258
- * @description Customer reference identifier
334
+ * Customer reference identifier
259
335
  * @example cus_3c4d5e6f7g8h
260
336
  */
261
337
  reference: string;
262
338
  /**
263
- * @description Customer full name
339
+ * Customer full name
264
340
  * @example John Doe
265
341
  */
266
342
  name: string;
267
343
  /**
268
- * @description Customer email address
344
+ * Customer email address
269
345
  * @example customer@example.com
270
346
  */
271
347
  email: string;
272
348
  /**
273
- * @description External reference ID from your auth system (if set during creation or update)
349
+ * External reference ID from your auth system (if set during creation or update)
274
350
  * @example auth_user_12345
275
351
  */
276
352
  externalRef?: string;
@@ -279,172 +355,256 @@ interface components {
279
355
  };
280
356
  CreateCustomerSessionResponse: {
281
357
  /**
282
- * @description Customer session ID/token
358
+ * Customer session ID/token
283
359
  * @example e3f1c2d4b6a89f001122334455667788
284
360
  */
285
361
  sessionId: string;
286
362
  /**
287
- * @description Full customer URL based on backend configuration (ready to redirect customer)
363
+ * Full customer URL based on backend configuration (ready to redirect customer)
288
364
  * @example https://solvapay.com/customer/manage?id=e3f1c2d4b6a89f001122334455667788
289
365
  */
290
366
  customerUrl: string;
291
367
  };
292
368
  GetCustomerSessionResponse: {
293
369
  /**
294
- * @description Customer session ID/token
370
+ * Customer session ID/token
295
371
  * @example e3f1c2d4b6a89f001122334455667788
296
372
  */
297
373
  sessionId: string;
298
374
  /**
299
- * @description Session status
375
+ * Session status
300
376
  * @example active
301
377
  * @enum {string}
302
378
  */
303
379
  status: "active" | "expired" | "used";
304
380
  /**
305
- * @description Full customer URL based on backend configuration (ready to redirect customer)
381
+ * Full customer URL based on backend configuration (ready to redirect customer)
306
382
  * @example https://solvapay.com/customer/manage?id=e3f1c2d4b6a89f001122334455667788
307
383
  */
308
384
  customerUrl: string;
309
385
  /**
310
- * @description Session expiration date
386
+ * Session expiration date
311
387
  * @example 2025-01-01T12:00:00.000Z
312
388
  */
313
389
  expiresAt: string;
314
390
  /** @description Customer object from session data */
315
391
  customer: components["schemas"]["CustomerResponse"];
316
392
  /**
317
- * @description Session creation date
393
+ * Session creation date
318
394
  * @example 2025-01-01T11:45:00.000Z
319
395
  */
320
396
  createdAt: string;
321
397
  /**
322
- * @description Session last update date
398
+ * Session last update date
323
399
  * @example 2025-01-01T11:45:00.000Z
324
400
  */
325
401
  updatedAt: string;
326
402
  };
327
- Agent: Record<string, never>;
328
- CreateAgentRequest: Record<string, never>;
329
- UpdateAgentRequest: Record<string, never>;
330
- BasePlan: Record<string, never>;
403
+ CreateOAuthClientDto: Record<string, never>;
404
+ UpdateOAuthClientDto: Record<string, never>;
405
+ GoogleLoginDto: {
406
+ /** @description The authorization code returned by Google */
407
+ code: string;
408
+ /** @description The redirect URI used in the initial authorization request */
409
+ redirect_uri: string;
410
+ /** @description The state parameter returned by Google (contains client_id) */
411
+ state: string;
412
+ };
413
+ GithubLoginDto: {
414
+ /** @description The authorization code returned by GitHub */
415
+ code: string;
416
+ /** @description The redirect URI used in the initial authorization request */
417
+ redirect_uri: string;
418
+ /** @description The state parameter returned by GitHub (contains client_id) */
419
+ state: string;
420
+ };
421
+ ExecuteAnalyticsQuery: Record<string, never>;
422
+ ExecuteMultipleQueries: Record<string, never>;
331
423
  SubscriptionResponse: {
332
424
  /**
333
- * @description Subscription reference identifier
425
+ * Subscription reference identifier
334
426
  * @example sub_1a2b3c4d5e6f
335
427
  */
336
428
  reference: string;
337
429
  /**
338
- * @description Customer reference identifier
430
+ * Customer reference identifier
339
431
  * @example cus_3c4d5e6f7g8h
340
432
  */
341
433
  customerRef: string;
342
434
  /**
343
- * @description Customer email
435
+ * Customer email
344
436
  * @example customer@example.com
345
437
  */
346
438
  customerEmail: string;
347
439
  /**
348
- * @description Customer name
440
+ * Customer name
349
441
  * @example John Doe
350
442
  */
351
443
  customerName?: string;
352
444
  /**
353
- * @description Agent reference identifier
445
+ * Agent reference identifier
354
446
  * @example agt_1a2b3c4d5e6f
355
447
  */
356
448
  agentRef: string;
357
449
  /**
358
- * @description Agent name
450
+ * Agent name
359
451
  * @example My AI Agent
360
452
  */
361
453
  agentName: string;
362
454
  /**
363
- * @description Plan reference identifier
455
+ * Plan reference identifier
364
456
  * @example pln_1a2b3c4d5e6f
365
457
  */
366
458
  planRef: string;
367
459
  /**
368
- * @description Plan name
460
+ * Plan name
369
461
  * @example Premium Plan
370
462
  */
371
463
  planName: string;
372
464
  /**
373
- * @description Plan type
465
+ * Plan type
374
466
  * @example recurring
375
467
  * @enum {string}
376
468
  */
377
469
  planType: "recurring" | "usage-based" | "one-time" | "hybrid";
378
470
  /**
379
- * @description Subscription status
471
+ * Subscription status
380
472
  * @example active
381
473
  * @enum {string}
382
474
  */
383
475
  status: "pending" | "active" | "expired" | "cancelled" | "suspended" | "refunded";
384
476
  /**
385
- * @description Amount paid in original currency (in cents)
477
+ * Amount paid in original currency (in cents)
386
478
  * @example 9900
387
479
  */
388
480
  amount: number;
389
481
  /**
390
- * @description Currency code
482
+ * Currency code
391
483
  * @example USD
392
484
  */
393
485
  currency: string;
394
486
  /**
395
- * @description Start date of subscription
487
+ * Start date of subscription
396
488
  * @example 2025-01-01T00:00:00.000Z
397
489
  */
398
490
  startDate: string;
399
491
  /**
400
- * @description End date of subscription (if applicable)
492
+ * End date of subscription (if applicable)
401
493
  * @example 2025-02-01T00:00:00.000Z
402
494
  */
403
495
  endDate?: string;
404
496
  /**
405
- * @description When payment was confirmed
497
+ * When payment was confirmed
406
498
  * @example 2025-01-01T00:00:00.000Z
407
499
  */
408
500
  paidAt?: string;
409
501
  /** @description Usage quota information (for usage-based plans) */
410
502
  usageQuota?: Record<string, never>;
411
503
  /**
412
- * @description Whether this is a recurring subscription
504
+ * Whether this is a recurring subscription
413
505
  * @example true
414
506
  */
415
507
  isRecurring: boolean;
416
508
  /**
417
- * @description Next billing date (for recurring subscriptions)
509
+ * Next billing date (for recurring subscriptions)
418
510
  * @example 2025-02-01T00:00:00.000Z
419
511
  */
420
512
  nextBillingDate?: string;
421
513
  /**
422
- * @description When subscription was cancelled (if applicable)
514
+ * When subscription was cancelled (if applicable)
423
515
  * @example 2025-01-15T00:00:00.000Z
424
516
  */
425
517
  cancelledAt?: string;
426
518
  /**
427
- * @description Reason for cancellation (if applicable)
519
+ * Reason for cancellation (if applicable)
428
520
  * @example Customer request
429
521
  */
430
522
  cancellationReason?: string;
431
523
  /**
432
- * @description When subscription was created
524
+ * When subscription was created
433
525
  * @example 2025-01-01T00:00:00.000Z
434
526
  */
435
527
  createdAt: string;
436
528
  };
437
- CreateCheckoutSessionResponse: {
529
+ CheckLimitRequest: {
530
+ /**
531
+ * Customer reference identifier
532
+ * @example cus_3c4d5e6f7g8h
533
+ */
534
+ customerRef: string;
535
+ /**
536
+ * Agent reference identifier
537
+ * @example agt_1a2b3c4d5e6f
538
+ */
539
+ agentRef: string;
540
+ };
541
+ LimitResponse: {
438
542
  /**
439
- * @description Checkout session ID/token
543
+ * Whether the customer is within their usage limits
544
+ * @example true
545
+ */
546
+ withinLimits: boolean;
547
+ /**
548
+ * Remaining usage units before hitting the limit
549
+ * @example 997
550
+ */
551
+ remaining: number;
552
+ /**
553
+ * Optional checkout session ID/token if payment is required
440
554
  * @example e3f1c2d4b6a89f001122334455667788
441
555
  */
442
- sessionId: string;
556
+ checkoutSessionId?: string;
443
557
  /**
444
- * @description Full checkout URL based on backend configuration (ready to redirect customer)
445
- * @example https://solvapay.com/customer/checkout?id=e3f1c2d4b6a89f001122334455667788
558
+ * Optional full checkout URL if payment is required (based on backend configuration)
559
+ * @example https://app.solvapay.com/customer/checkout?id=e3f1c2d4b6a89f001122334455667788
446
560
  */
447
- checkoutUrl: string;
561
+ checkoutUrl?: string;
562
+ };
563
+ UsageEvent: {
564
+ /**
565
+ * Customer reference identifier
566
+ * @example cus_3c4d5e6f7g8h
567
+ */
568
+ customerRef: string;
569
+ /**
570
+ * Agent reference identifier
571
+ * @example agt_1a2b3c4d5e6f
572
+ */
573
+ agentRef: string;
574
+ /**
575
+ * Outcome of the action
576
+ * @example success
577
+ * @enum {string}
578
+ */
579
+ outcome: "success" | "paywall" | "fail";
580
+ /**
581
+ * Optional action identifier
582
+ * @example generate_text
583
+ */
584
+ action?: string;
585
+ /**
586
+ * Unique request identifier matching the limits check
587
+ * @example req_1a2b3c4d5e6f
588
+ */
589
+ requestId: string;
590
+ /**
591
+ * Duration of the action in milliseconds
592
+ * @example 1250
593
+ */
594
+ actionDuration: number;
595
+ /**
596
+ * ISO 8601 timestamp of when the action occurred
597
+ * @example 2025-10-21T10:30:00.000Z
598
+ */
599
+ timestamp: string;
600
+ };
601
+ UpdateThemePreferenceDto: {
602
+ /**
603
+ * Selected UI theme mode
604
+ * @example dark
605
+ * @enum {string}
606
+ */
607
+ mode: "light" | "dark";
448
608
  };
449
609
  CreatePageSettings: {
450
610
  /** @description Page identifier */
@@ -454,36 +614,38 @@ interface components {
454
614
  /** @description Logo URL */
455
615
  logo?: string;
456
616
  /**
457
- * @description Text color in hex format
617
+ * Text color in hex format
458
618
  * @example #2d3748
459
619
  */
460
620
  textColor: string;
461
621
  /**
462
- * @description Button color in hex format
622
+ * Button color in hex format
463
623
  * @example #3182ce
464
624
  */
465
625
  buttonColor: string;
466
626
  /**
467
- * @description Left background color in hex format
627
+ * Left background color in hex format
468
628
  * @example #f7fafc
469
629
  */
470
630
  leftBackgroundColor: string;
471
631
  /**
472
- * @description Right background color in hex format
632
+ * Right background color in hex format
473
633
  * @example #ffffff
474
634
  */
475
635
  rightBackgroundColor: string;
476
636
  /**
477
- * @description Font family
637
+ * Font family
478
638
  * @example Inter
479
639
  */
480
640
  fontFamily: string;
481
641
  /**
482
- * @description Font size
642
+ * Font size
483
643
  * @example 16px
484
644
  */
485
645
  fontSize: string;
486
646
  };
647
+ CreateWebhookEndpointDto: Record<string, never>;
648
+ UpdateWebhookEndpointDto: Record<string, never>;
487
649
  };
488
650
  responses: never;
489
651
  parameters: never;
@@ -554,11 +716,9 @@ interface SolvaPayClient {
554
716
  createCustomer?(params: components['schemas']['CreateCustomerRequest']): Promise<{
555
717
  customerRef: string;
556
718
  }>;
557
- getCustomer?(params: {
558
- customerRef: string;
559
- }): Promise<CustomerResponseMapped>;
560
- getCustomerByExternalRef?(params: {
561
- externalRef: string;
719
+ getCustomer(params: {
720
+ customerRef?: string;
721
+ externalRef?: string;
562
722
  }): Promise<CustomerResponseMapped>;
563
723
  listAgents?(): Promise<Array<{
564
724
  reference: string;
@@ -771,68 +931,242 @@ interface McpAdapterOptions {
771
931
  }
772
932
 
773
933
  /**
774
- * Configuration for creating a SolvaPay instance
934
+ * Configuration for creating a SolvaPay instance.
935
+ *
936
+ * You can provide either an `apiKey` (for production) or an `apiClient` (for testing).
937
+ * If neither is provided, the SDK will attempt to read `SOLVAPAY_SECRET_KEY` from
938
+ * environment variables. If no API key is found, the SDK runs in stub mode.
939
+ *
940
+ * @example
941
+ * ```typescript
942
+ * // Production: Use API key
943
+ * const config: CreateSolvaPayConfig = {
944
+ * apiKey: process.env.SOLVAPAY_SECRET_KEY
945
+ * };
946
+ *
947
+ * // Testing: Use mock client
948
+ * const config: CreateSolvaPayConfig = {
949
+ * apiClient: mockClient
950
+ * };
951
+ * ```
775
952
  */
776
953
  interface CreateSolvaPayConfig {
777
954
  /**
778
- * API key for production use (creates client automatically)
955
+ * API key for production use (creates client automatically).
956
+ * Defaults to `SOLVAPAY_SECRET_KEY` environment variable if not provided.
779
957
  */
780
958
  apiKey?: string;
781
959
  /**
782
- * API client for testing or custom implementations
960
+ * API client for testing or custom implementations.
961
+ * Use this for stub mode, testing, or custom client implementations.
783
962
  */
784
963
  apiClient?: SolvaPayClient;
785
964
  /**
786
- * Optional API base URL (only used with apiKey)
965
+ * Optional API base URL override (only used with apiKey).
966
+ * Defaults to production API URL if not provided.
787
967
  */
788
968
  apiBaseUrl?: string;
789
969
  }
790
970
  /**
791
- * Payable function that provides explicit adapters
971
+ * Payable function that provides explicit adapters for different frameworks.
972
+ *
973
+ * Use the appropriate adapter method for your framework:
974
+ * - `http()` - Express.js, Fastify, and other HTTP frameworks
975
+ * - `next()` - Next.js App Router API routes
976
+ * - `mcp()` - Model Context Protocol servers
977
+ * - `function()` - Pure functions, background jobs, or testing
978
+ *
979
+ * @example
980
+ * ```typescript
981
+ * const payable = solvaPay.payable({ agent: 'agt_myapi', plan: 'pln_premium' });
982
+ *
983
+ * // Express.js
984
+ * app.post('/tasks', payable.http(createTask));
985
+ *
986
+ * // Next.js
987
+ * export const POST = payable.next(createTask);
988
+ *
989
+ * // MCP Server
990
+ * const handler = payable.mcp(createTask);
991
+ *
992
+ * // Pure function
993
+ * const protectedFn = await payable.function(createTask);
994
+ * ```
792
995
  */
793
996
  interface PayableFunction {
794
997
  /**
795
- * HTTP adapter for Express/Fastify
998
+ * HTTP adapter for Express.js, Fastify, and other HTTP frameworks.
999
+ *
1000
+ * @param businessLogic - Your business logic function
1001
+ * @param options - Optional adapter configuration
1002
+ * @returns HTTP route handler function
1003
+ *
1004
+ * @example
1005
+ * ```typescript
1006
+ * app.post('/tasks', payable.http(async (req) => {
1007
+ * const { title } = req.body;
1008
+ * return { success: true, task: { title } };
1009
+ * }));
1010
+ * ```
796
1011
  */
797
1012
  http<T = any>(businessLogic: (args: any) => Promise<T>, options?: HttpAdapterOptions): (req: any, reply: any) => Promise<any>;
798
1013
  /**
799
- * Next.js adapter for App Router
1014
+ * Next.js adapter for App Router API routes.
1015
+ *
1016
+ * @param businessLogic - Your business logic function
1017
+ * @param options - Optional adapter configuration
1018
+ * @returns Next.js route handler function
1019
+ *
1020
+ * @example
1021
+ * ```typescript
1022
+ * // app/api/tasks/route.ts
1023
+ * export const POST = payable.next(async (request) => {
1024
+ * const body = await request.json();
1025
+ * return Response.json({ success: true });
1026
+ * });
1027
+ * ```
800
1028
  */
801
1029
  next<T = any>(businessLogic: (args: any) => Promise<T>, options?: NextAdapterOptions): (request: Request, context?: any) => Promise<Response>;
802
1030
  /**
803
- * MCP adapter for Model Context Protocol servers
1031
+ * MCP adapter for Model Context Protocol servers.
1032
+ *
1033
+ * @param businessLogic - Your tool implementation function
1034
+ * @param options - Optional adapter configuration
1035
+ * @returns MCP tool handler function
1036
+ *
1037
+ * @example
1038
+ * ```typescript
1039
+ * const handler = payable.mcp(async (args) => {
1040
+ * return { success: true, result: 'tool output' };
1041
+ * });
1042
+ * ```
804
1043
  */
805
1044
  mcp<T = any>(businessLogic: (args: any) => Promise<T>, options?: McpAdapterOptions): (args: any) => Promise<any>;
806
1045
  /**
807
- * Pure function adapter for direct function protection
808
- * Use this for testing, background jobs, or non-framework contexts
1046
+ * Pure function adapter for direct function protection.
1047
+ *
1048
+ * Use this for testing, background jobs, or non-framework contexts.
1049
+ *
1050
+ * @param businessLogic - Your business logic function
1051
+ * @returns Protected function that requires customer reference in args
1052
+ *
1053
+ * @example
1054
+ * ```typescript
1055
+ * const protectedFn = await payable.function(async (args) => {
1056
+ * return { result: 'processed' };
1057
+ * });
1058
+ *
1059
+ * // Call with customer reference
1060
+ * const result = await protectedFn({
1061
+ * auth: { customer_ref: 'user_123' },
1062
+ * // ... other args
1063
+ * });
1064
+ * ```
809
1065
  */
810
1066
  function<T = any>(businessLogic: (args: any) => Promise<T>): Promise<(args: any) => Promise<T>>;
811
1067
  }
812
1068
  /**
813
- * SolvaPay instance with payable method and common API methods
1069
+ * SolvaPay instance with payable method and common API methods.
1070
+ *
1071
+ * This interface provides the main API for interacting with SolvaPay.
1072
+ * Use `createSolvaPay()` to create an instance.
1073
+ *
1074
+ * @example
1075
+ * ```typescript
1076
+ * const solvaPay = createSolvaPay();
1077
+ *
1078
+ * // Create payable handlers
1079
+ * const payable = solvaPay.payable({ agent: 'agt_myapi', plan: 'pln_premium' });
1080
+ *
1081
+ * // Manage customers
1082
+ * const customerRef = await solvaPay.ensureCustomer('user_123', 'user_123', {
1083
+ * email: 'user@example.com'
1084
+ * });
1085
+ *
1086
+ * // Create payment intents
1087
+ * const intent = await solvaPay.createPaymentIntent({
1088
+ * agentRef: 'agt_myapi',
1089
+ * planRef: 'pln_premium',
1090
+ * customerRef: 'user_123'
1091
+ * });
1092
+ * ```
814
1093
  */
815
1094
  interface SolvaPay {
816
1095
  /**
817
- * Create a payable handler with explicit adapters
1096
+ * Create a payable handler with explicit adapters for different frameworks.
1097
+ *
1098
+ * @param options - Payable options including agent and plan references
1099
+ * @returns PayableFunction with framework-specific adapters
1100
+ *
1101
+ * @example
1102
+ * ```typescript
1103
+ * const payable = solvaPay.payable({
1104
+ * agent: 'agt_myapi',
1105
+ * plan: 'pln_premium'
1106
+ * });
1107
+ *
1108
+ * app.post('/tasks', payable.http(createTask));
1109
+ * ```
818
1110
  */
819
1111
  payable(options?: PayableOptions): PayableFunction;
820
1112
  /**
821
- * Ensure customer exists (for testing/setup)
822
- * Only attempts creation once per customer (idempotent).
1113
+ * Ensure customer exists in SolvaPay backend (idempotent).
1114
+ *
1115
+ * Creates a customer if they don't exist, or returns existing customer reference.
1116
+ * This is automatically called by the paywall system, but you can call it
1117
+ * explicitly for setup or testing.
823
1118
  *
824
1119
  * @param customerRef - The customer reference used as a cache key (e.g., Supabase user ID)
825
- * @param externalRef - Optional external reference for backend lookup (e.g., Supabase user ID)
1120
+ * @param externalRef - Optional external reference for backend lookup (e.g., Supabase user ID).
826
1121
  * If provided, will lookup existing customer by externalRef before creating new one.
827
1122
  * The externalRef is stored on the SolvaPay backend for customer lookup.
828
- * @param options - Optional customer details (email, name) for customer creation
1123
+ * @param options - Optional customer details for customer creation
1124
+ * @param options.email - Customer email address
1125
+ * @param options.name - Customer name
1126
+ * @returns Customer reference (backend customer ID)
1127
+ *
1128
+ * @example
1129
+ * ```typescript
1130
+ * // Ensure customer exists before processing payment
1131
+ * const customerRef = await solvaPay.ensureCustomer(
1132
+ * 'user_123', // customerRef (your user ID)
1133
+ * 'user_123', // externalRef (same or different)
1134
+ * {
1135
+ * email: 'user@example.com',
1136
+ * name: 'John Doe'
1137
+ * }
1138
+ * );
1139
+ * ```
829
1140
  */
830
1141
  ensureCustomer(customerRef: string, externalRef?: string, options?: {
831
1142
  email?: string;
832
1143
  name?: string;
833
1144
  }): Promise<string>;
834
1145
  /**
835
- * Create a payment intent for a customer to subscribe to a plan
1146
+ * Create a Stripe payment intent for a customer to subscribe to a plan.
1147
+ *
1148
+ * This creates a payment intent that can be confirmed on the client side
1149
+ * using Stripe.js. After confirmation, call `processPayment()` to complete
1150
+ * the subscription.
1151
+ *
1152
+ * @param params - Payment intent parameters
1153
+ * @param params.agentRef - Agent reference
1154
+ * @param params.planRef - Plan reference to subscribe to
1155
+ * @param params.customerRef - Customer reference
1156
+ * @param params.idempotencyKey - Optional idempotency key for retry safety
1157
+ * @returns Payment intent with client secret and publishable key
1158
+ *
1159
+ * @example
1160
+ * ```typescript
1161
+ * const intent = await solvaPay.createPaymentIntent({
1162
+ * agentRef: 'agt_myapi',
1163
+ * planRef: 'pln_premium',
1164
+ * customerRef: 'user_123',
1165
+ * idempotencyKey: 'unique-key-123'
1166
+ * });
1167
+ *
1168
+ * // Use intent.clientSecret with Stripe.js on client
1169
+ * ```
836
1170
  */
837
1171
  createPaymentIntent(params: {
838
1172
  agentRef: string;
@@ -846,8 +1180,32 @@ interface SolvaPay {
846
1180
  accountId?: string;
847
1181
  }>;
848
1182
  /**
849
- * Process a payment intent after client-side confirmation
850
- * Creates subscription or purchase immediately, eliminating webhook delay
1183
+ * Process a payment intent after client-side Stripe confirmation.
1184
+ *
1185
+ * Creates subscription or purchase immediately, eliminating webhook delay.
1186
+ * Call this after the client has confirmed the payment intent with Stripe.js.
1187
+ *
1188
+ * @param params - Payment processing parameters
1189
+ * @param params.paymentIntentId - Stripe payment intent ID from client confirmation
1190
+ * @param params.agentRef - Agent reference
1191
+ * @param params.customerRef - Customer reference
1192
+ * @param params.planRef - Optional plan reference (if not in payment intent)
1193
+ * @returns Payment processing result with subscription details
1194
+ *
1195
+ * @example
1196
+ * ```typescript
1197
+ * // After client confirms payment with Stripe.js
1198
+ * const result = await solvaPay.processPayment({
1199
+ * paymentIntentId: 'pi_1234567890',
1200
+ * agentRef: 'agt_myapi',
1201
+ * customerRef: 'user_123',
1202
+ * planRef: 'pln_premium'
1203
+ * });
1204
+ *
1205
+ * if (result.success) {
1206
+ * console.log('Subscription created:', result.subscriptionRef);
1207
+ * }
1208
+ * ```
851
1209
  */
852
1210
  processPayment(params: {
853
1211
  paymentIntentId: string;
@@ -856,7 +1214,28 @@ interface SolvaPay {
856
1214
  planRef?: string;
857
1215
  }): Promise<ProcessPaymentResult>;
858
1216
  /**
859
- * Check if customer is within usage limits
1217
+ * Check if customer is within usage limits for an agent.
1218
+ *
1219
+ * This method checks subscription status and usage limits without
1220
+ * executing business logic. Use `payable()` for automatic protection.
1221
+ *
1222
+ * @param params - Limit check parameters
1223
+ * @param params.customerRef - Customer reference
1224
+ * @param params.agentRef - Agent reference
1225
+ * @returns Limit check result with remaining usage and checkout URL if needed
1226
+ *
1227
+ * @example
1228
+ * ```typescript
1229
+ * const limits = await solvaPay.checkLimits({
1230
+ * customerRef: 'user_123',
1231
+ * agentRef: 'agt_myapi'
1232
+ * });
1233
+ *
1234
+ * if (!limits.withinLimits) {
1235
+ * // Redirect to checkout
1236
+ * window.location.href = limits.checkoutUrl;
1237
+ * }
1238
+ * ```
860
1239
  */
861
1240
  checkLimits(params: {
862
1241
  customerRef: string;
@@ -868,7 +1247,34 @@ interface SolvaPay {
868
1247
  checkoutUrl?: string;
869
1248
  }>;
870
1249
  /**
871
- * Track usage for a customer action
1250
+ * Track usage for a customer action.
1251
+ *
1252
+ * This is automatically called by the paywall system. You typically
1253
+ * don't need to call this manually unless implementing custom tracking.
1254
+ *
1255
+ * @param params - Usage tracking parameters
1256
+ * @param params.customerRef - Customer reference
1257
+ * @param params.agentRef - Agent reference
1258
+ * @param params.planRef - Plan reference
1259
+ * @param params.outcome - Action outcome ('success', 'paywall', or 'fail')
1260
+ * @param params.action - Optional action name for analytics
1261
+ * @param params.requestId - Unique request ID
1262
+ * @param params.actionDuration - Action duration in milliseconds
1263
+ * @param params.timestamp - ISO timestamp of the action
1264
+ *
1265
+ * @example
1266
+ * ```typescript
1267
+ * await solvaPay.trackUsage({
1268
+ * customerRef: 'user_123',
1269
+ * agentRef: 'agt_myapi',
1270
+ * planRef: 'pln_premium',
1271
+ * outcome: 'success',
1272
+ * action: 'api_call',
1273
+ * requestId: 'req_123',
1274
+ * actionDuration: 150,
1275
+ * timestamp: new Date().toISOString()
1276
+ * });
1277
+ * ```
872
1278
  */
873
1279
  trackUsage(params: {
874
1280
  customerRef: string;
@@ -881,7 +1287,23 @@ interface SolvaPay {
881
1287
  timestamp: string;
882
1288
  }): Promise<void>;
883
1289
  /**
884
- * Create a new customer
1290
+ * Create a new customer in SolvaPay backend.
1291
+ *
1292
+ * Note: `ensureCustomer()` is usually preferred as it's idempotent.
1293
+ * Use this only if you need explicit control over customer creation.
1294
+ *
1295
+ * @param params - Customer creation parameters
1296
+ * @param params.email - Customer email address (required)
1297
+ * @param params.name - Optional customer name
1298
+ * @returns Created customer reference
1299
+ *
1300
+ * @example
1301
+ * ```typescript
1302
+ * const { customerRef } = await solvaPay.createCustomer({
1303
+ * email: 'user@example.com',
1304
+ * name: 'John Doe'
1305
+ * });
1306
+ * ```
885
1307
  */
886
1308
  createCustomer(params: {
887
1309
  email: string;
@@ -890,25 +1312,87 @@ interface SolvaPay {
890
1312
  customerRef: string;
891
1313
  }>;
892
1314
  /**
893
- * Get customer details
894
- * Uses the generated CustomerResponseMapped type which includes all subscription fields from the API
1315
+ * Get customer details including subscriptions and usage.
1316
+ *
1317
+ * Returns full customer information from the SolvaPay backend, including
1318
+ * all active subscriptions, usage history, and customer metadata.
1319
+ *
1320
+ * @param params - Customer lookup parameters
1321
+ * @param params.customerRef - Optional customer reference (SolvaPay ID)
1322
+ * @param params.externalRef - Optional external reference (e.g., Supabase ID)
1323
+ * @returns Customer details with subscriptions and metadata
1324
+ *
1325
+ * @example
1326
+ * ```typescript
1327
+ * // Lookup by SolvaPay customer ID
1328
+ * const customer = await solvaPay.getCustomer({
1329
+ * customerRef: 'cust_123'
1330
+ * });
1331
+ *
1332
+ * // Lookup by external ID (e.g. Supabase user ID)
1333
+ * const customer = await solvaPay.getCustomer({
1334
+ * externalRef: 'user_123'
1335
+ * });
1336
+ * ```
895
1337
  */
896
1338
  getCustomer(params: {
897
- customerRef: string;
1339
+ customerRef?: string;
1340
+ externalRef?: string;
898
1341
  }): Promise<CustomerResponseMapped>;
899
1342
  /**
900
- * Create a checkout session for a customer
1343
+ * Create a hosted checkout session for a customer.
1344
+ *
1345
+ * This creates a Stripe Checkout session that redirects the customer
1346
+ * to a hosted payment page. After payment, customer is redirected back.
1347
+ *
1348
+ * @param params - Checkout session parameters
1349
+ * @param params.agentRef - Agent reference
1350
+ * @param params.customerRef - Customer reference
1351
+ * @param params.planRef - Optional plan reference (if not specified, shows plan selector)
1352
+ * @param params.returnUrl - URL to redirect to after successful payment
1353
+ * @returns Checkout session with redirect URL
1354
+ *
1355
+ * @example
1356
+ * ```typescript
1357
+ * const session = await solvaPay.createCheckoutSession({
1358
+ * agentRef: 'agt_myapi',
1359
+ * customerRef: 'user_123',
1360
+ * planRef: 'pln_premium',
1361
+ * returnUrl: 'https://myapp.com/success'
1362
+ * });
1363
+ *
1364
+ * // Redirect customer to checkout
1365
+ * window.location.href = session.checkoutUrl;
1366
+ * ```
901
1367
  */
902
1368
  createCheckoutSession(params: {
903
1369
  agentRef: string;
904
1370
  customerRef: string;
905
1371
  planRef?: string;
1372
+ returnUrl?: string;
906
1373
  }): Promise<{
907
1374
  sessionId: string;
908
1375
  checkoutUrl: string;
909
1376
  }>;
910
1377
  /**
911
- * Create a customer session for accessing customer-specific functionality
1378
+ * Create a customer portal session for managing subscriptions.
1379
+ *
1380
+ * This creates a Stripe Customer Portal session that allows customers
1381
+ * to manage their subscriptions, update payment methods, and view invoices.
1382
+ *
1383
+ * @param params - Customer session parameters
1384
+ * @param params.customerRef - Customer reference
1385
+ * @returns Customer portal session with redirect URL
1386
+ *
1387
+ * @example
1388
+ * ```typescript
1389
+ * const session = await solvaPay.createCustomerSession({
1390
+ * customerRef: 'user_123'
1391
+ * });
1392
+ *
1393
+ * // Redirect customer to portal
1394
+ * window.location.href = session.customerUrl;
1395
+ * ```
912
1396
  */
913
1397
  createCustomerSession(params: {
914
1398
  customerRef: string;
@@ -917,20 +1401,35 @@ interface SolvaPay {
917
1401
  customerUrl: string;
918
1402
  }>;
919
1403
  /**
920
- * Direct access to the API client for advanced operations
921
- * (agent/plan management, etc.)
1404
+ * Direct access to the API client for advanced operations.
1405
+ *
1406
+ * Use this for operations not exposed by the SolvaPay interface,
1407
+ * such as agent/plan management or custom API calls.
1408
+ *
1409
+ * @example
1410
+ * ```typescript
1411
+ * // Access API client directly for custom operations
1412
+ * const agents = await solvaPay.apiClient.listAgents();
1413
+ * ```
922
1414
  */
923
1415
  apiClient: SolvaPayClient;
924
1416
  }
925
1417
  /**
926
- * Create a SolvaPay instance
1418
+ * Create a SolvaPay instance with paywall protection capabilities.
1419
+ *
1420
+ * This factory function creates a SolvaPay instance that can be used to
1421
+ * protect API endpoints, functions, and MCP tools with usage limits and
1422
+ * subscription checks.
927
1423
  *
928
- * @param config - Optional configuration with either apiKey or apiClient. If not provided, reads from environment variables.
929
- * @returns SolvaPay instance with payable() method
1424
+ * @param config - Optional configuration object
1425
+ * @param config.apiKey - API key for production use (defaults to `SOLVAPAY_SECRET_KEY` env var)
1426
+ * @param config.apiClient - Custom API client for testing or advanced use cases
1427
+ * @param config.apiBaseUrl - Optional API base URL override
1428
+ * @returns SolvaPay instance with payable() method and API client access
930
1429
  *
931
1430
  * @example
932
1431
  * ```typescript
933
- * // Production: Read from environment variables (recommended)
1432
+ * // Production: Use environment variable (recommended)
934
1433
  * const solvaPay = createSolvaPay();
935
1434
  *
936
1435
  * // Production: Pass API key explicitly
@@ -938,16 +1437,26 @@ interface SolvaPay {
938
1437
  * apiKey: process.env.SOLVAPAY_SECRET_KEY
939
1438
  * });
940
1439
  *
941
- * // Testing: Pass mock client
1440
+ * // Testing: Use mock client
942
1441
  * const solvaPay = createSolvaPay({
943
1442
  * apiClient: mockClient
944
1443
  * });
945
1444
  *
946
- * // Create payable handlers
947
- * const payable = solvaPay.payable({ agent: 'my-api' });
948
- * app.post('/tasks', payable.http(createTask));
949
- * export const POST = payable.next(createTask);
1445
+ * // Create payable handlers for your agent
1446
+ * const payable = solvaPay.payable({
1447
+ * agent: 'agt_myapi',
1448
+ * plan: 'pln_premium'
1449
+ * });
1450
+ *
1451
+ * // Protect endpoints with framework-specific adapters
1452
+ * app.post('/tasks', payable.http(createTask)); // Express/Fastify
1453
+ * export const POST = payable.next(createTask); // Next.js App Router
1454
+ * const handler = payable.mcp(createTask); // MCP servers
950
1455
  * ```
1456
+ *
1457
+ * @see {@link SolvaPay} for the returned instance interface
1458
+ * @see {@link CreateSolvaPayConfig} for configuration options
1459
+ * @since 1.0.0
951
1460
  */
952
1461
  declare function createSolvaPay(config?: CreateSolvaPayConfig): SolvaPay;
953
1462
 
@@ -969,25 +1478,43 @@ type ServerClientOptions = {
969
1478
  apiKey: string;
970
1479
  /**
971
1480
  * Base URL for the SolvaPay API (optional)
972
- * Defaults to https://api-dev.solvapay.com
1481
+ * Defaults to https://api.solvapay.com
973
1482
  */
974
1483
  apiBaseUrl?: string;
975
1484
  };
976
1485
  /**
977
- * Creates a SolvaPay API client that implements the full SolvaPayClient
978
- * for server-side paywall and usage tracking operations.
1486
+ * Creates a SolvaPay API client that implements the full SolvaPayClient interface.
979
1487
  *
980
- * @param opts - Configuration options including API key and optional base URL
1488
+ * This function creates a low-level API client for direct communication with the
1489
+ * SolvaPay backend. For most use cases, use `createSolvaPay()` instead, which
1490
+ * provides a higher-level API with paywall protection.
1491
+ *
1492
+ * Use this function when you need:
1493
+ * - Direct API access for custom operations
1494
+ * - Testing with custom client implementations
1495
+ * - Advanced use cases not covered by the main API
1496
+ *
1497
+ * @param opts - Configuration options
1498
+ * @param opts.apiKey - Your SolvaPay API key (required)
1499
+ * @param opts.apiBaseUrl - Optional API base URL override
981
1500
  * @returns A fully configured SolvaPayClient instance
982
1501
  * @throws {SolvaPayError} If API key is missing
983
1502
  *
984
1503
  * @example
985
1504
  * ```typescript
1505
+ * // Create API client directly
986
1506
  * const client = createSolvaPayClient({
987
1507
  * apiKey: process.env.SOLVAPAY_SECRET_KEY!,
988
1508
  * apiBaseUrl: 'https://api.solvapay.com' // optional
989
1509
  * });
1510
+ *
1511
+ * // Use client for custom operations
1512
+ * const agents = await client.listAgents();
990
1513
  * ```
1514
+ *
1515
+ * @see {@link createSolvaPay} for the recommended high-level API
1516
+ * @see {@link ServerClientOptions} for configuration options
1517
+ * @since 1.0.0
991
1518
  */
992
1519
  declare function createSolvaPayClient(opts: ServerClientOptions): SolvaPayClient;
993
1520
 
@@ -1000,8 +1527,48 @@ declare function createSolvaPayClient(opts: ServerClientOptions): SolvaPayClient
1000
1527
  * - Class-based and functional programming
1001
1528
  */
1002
1529
 
1530
+ /**
1531
+ * Error thrown when a paywall is triggered (subscription required or usage limit exceeded).
1532
+ *
1533
+ * This error is automatically thrown by the paywall protection system when:
1534
+ * - Customer doesn't have required subscription
1535
+ * - Customer has exceeded usage limits
1536
+ * - Customer needs to upgrade their plan
1537
+ *
1538
+ * The error includes structured content with checkout URLs and metadata for
1539
+ * building custom paywall UIs.
1540
+ *
1541
+ * @example
1542
+ * ```typescript
1543
+ * import { PaywallError } from '@solvapay/server';
1544
+ *
1545
+ * try {
1546
+ * const result = await payable.http(createTask)(req, res);
1547
+ * return result;
1548
+ * } catch (error) {
1549
+ * if (error instanceof PaywallError) {
1550
+ * // Custom paywall handling
1551
+ * return res.status(402).json({
1552
+ * error: error.message,
1553
+ * checkoutUrl: error.structuredContent.checkoutUrl,
1554
+ * // Additional metadata available in error.structuredContent
1555
+ * });
1556
+ * }
1557
+ * throw error;
1558
+ * }
1559
+ * ```
1560
+ *
1561
+ * @see {@link PaywallStructuredContent} for the structured content format
1562
+ * @since 1.0.0
1563
+ */
1003
1564
  declare class PaywallError extends Error {
1004
1565
  structuredContent: PaywallStructuredContent;
1566
+ /**
1567
+ * Creates a new PaywallError instance.
1568
+ *
1569
+ * @param message - Error message
1570
+ * @param structuredContent - Structured content with checkout URLs and metadata
1571
+ */
1005
1572
  constructor(message: string, structuredContent: PaywallStructuredContent);
1006
1573
  }
1007
1574
 
@@ -1010,19 +1577,28 @@ declare class PaywallError extends Error {
1010
1577
  */
1011
1578
 
1012
1579
  /**
1013
- * Executes an async function with automatic retry logic
1580
+ * Execute an async function with automatic retry logic.
1581
+ *
1582
+ * This utility function provides configurable retry logic with exponential backoff,
1583
+ * conditional retry logic, and retry callbacks. Useful for handling transient
1584
+ * network errors or rate limiting.
1014
1585
  *
1015
1586
  * @template T The return type of the async function
1016
1587
  * @param fn The async function to execute
1017
1588
  * @param options Retry configuration options
1589
+ * @param options.maxRetries - Maximum number of retry attempts (default: 2)
1590
+ * @param options.initialDelay - Initial delay in milliseconds before first retry (default: 500)
1591
+ * @param options.backoffStrategy - Backoff strategy: 'fixed', 'linear', or 'exponential' (default: 'fixed')
1592
+ * @param options.shouldRetry - Optional function to determine if error should be retried
1593
+ * @param options.onRetry - Optional callback called before each retry attempt
1018
1594
  * @returns A promise that resolves with the function result or rejects with the last error
1019
1595
  *
1020
1596
  * @example
1021
1597
  * ```typescript
1022
- * // Simple retry with defaults
1598
+ * // Simple retry with defaults (2 retries, 500ms delay)
1023
1599
  * const result = await withRetry(() => apiCall());
1024
1600
  *
1025
- * // Custom retry with conditional logic
1601
+ * // Custom retry with exponential backoff
1026
1602
  * const result = await withRetry(
1027
1603
  * () => apiCall(),
1028
1604
  * {
@@ -1034,6 +1610,8 @@ declare class PaywallError extends Error {
1034
1610
  * }
1035
1611
  * );
1036
1612
  * ```
1613
+ *
1614
+ * @since 1.0.0
1037
1615
  */
1038
1616
  declare function withRetry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
1039
1617
 
@@ -1082,14 +1660,39 @@ declare function handleRouteError(error: unknown, operationName: string, default
1082
1660
  */
1083
1661
 
1084
1662
  /**
1085
- * Extract authenticated user information from request
1663
+ * Extract authenticated user information from a standard Web API Request.
1086
1664
  *
1087
- * This is a generic implementation that uses dynamic imports to avoid
1088
- * requiring @solvapay/auth package at build time.
1665
+ * This is a generic, framework-agnostic helper that extracts user ID, email,
1666
+ * and name from authenticated requests. Works with any framework that uses
1667
+ * the standard Web API Request (Express, Fastify, Next.js, Edge Functions, etc.).
1089
1668
  *
1090
- * @param request - Standard Web API Request
1669
+ * Uses dynamic imports to avoid requiring @solvapay/auth at build time,
1670
+ * making it suitable for edge runtime environments.
1671
+ *
1672
+ * @param request - Standard Web API Request object
1091
1673
  * @param options - Configuration options
1674
+ * @param options.includeEmail - Whether to extract email from JWT token (default: true)
1675
+ * @param options.includeName - Whether to extract name from JWT token (default: true)
1092
1676
  * @returns Authenticated user info or error result
1677
+ *
1678
+ * @example
1679
+ * ```typescript
1680
+ * // In an API route handler
1681
+ * export async function GET(request: Request) {
1682
+ * const userResult = await getAuthenticatedUserCore(request);
1683
+ *
1684
+ * if (isErrorResult(userResult)) {
1685
+ * return Response.json(userResult, { status: userResult.status });
1686
+ * }
1687
+ *
1688
+ * const { userId, email, name } = userResult;
1689
+ * // Use user info...
1690
+ * }
1691
+ * ```
1692
+ *
1693
+ * @see {@link AuthenticatedUser} for the return type
1694
+ * @see {@link ErrorResult} for error handling
1695
+ * @since 1.0.0
1093
1696
  */
1094
1697
  declare function getAuthenticatedUserCore(request: Request, options?: {
1095
1698
  includeEmail?: boolean;
@@ -1104,13 +1707,41 @@ declare function getAuthenticatedUserCore(request: Request, options?: {
1104
1707
  */
1105
1708
 
1106
1709
  /**
1107
- * Sync customer - ensure customer exists in SolvaPay backend
1710
+ * Sync customer with SolvaPay backend (ensure customer exists).
1108
1711
  *
1109
- * Uses externalRef for consistent lookup and prevents duplicate customers.
1712
+ * This helper ensures a customer exists in the SolvaPay backend by:
1713
+ * 1. Extracting authenticated user information from the request
1714
+ * 2. Creating or retrieving the customer using the user ID as external reference
1715
+ * 3. Syncing customer data (email, name) if provided
1110
1716
  *
1111
- * @param request - Standard Web API Request
1717
+ * Uses `externalRef` for consistent lookup and prevents duplicate customers.
1718
+ * The returned customer reference is the SolvaPay backend customer ID.
1719
+ *
1720
+ * @param request - Standard Web API Request object
1112
1721
  * @param options - Configuration options
1113
- * @returns Customer reference or error result
1722
+ * @param options.solvaPay - Optional SolvaPay instance (creates new one if not provided)
1723
+ * @param options.includeEmail - Whether to include email in customer data (default: true)
1724
+ * @param options.includeName - Whether to include name in customer data (default: true)
1725
+ * @returns Customer reference (backend customer ID) or error result
1726
+ *
1727
+ * @example
1728
+ * ```typescript
1729
+ * // In an API route handler
1730
+ * export async function POST(request: Request) {
1731
+ * const customerResult = await syncCustomerCore(request);
1732
+ *
1733
+ * if (isErrorResult(customerResult)) {
1734
+ * return Response.json(customerResult, { status: customerResult.status });
1735
+ * }
1736
+ *
1737
+ * const customerRef = customerResult;
1738
+ * // Use customer reference...
1739
+ * }
1740
+ * ```
1741
+ *
1742
+ * @see {@link getAuthenticatedUserCore} for user extraction
1743
+ * @see {@link ErrorResult} for error handling
1744
+ * @since 1.0.0
1114
1745
  */
1115
1746
  declare function syncCustomerCore(request: Request, options?: {
1116
1747
  solvaPay?: SolvaPay;
@@ -1119,12 +1750,44 @@ declare function syncCustomerCore(request: Request, options?: {
1119
1750
  }): Promise<string | ErrorResult>;
1120
1751
 
1121
1752
  /**
1122
- * Create payment intent - core implementation
1753
+ * Create a Stripe payment intent for a customer to subscribe to a plan.
1123
1754
  *
1124
- * @param request - Standard Web API Request
1755
+ * This is a framework-agnostic helper that:
1756
+ * 1. Extracts authenticated user from the request
1757
+ * 2. Syncs customer with SolvaPay backend
1758
+ * 3. Creates a payment intent for the specified plan
1759
+ *
1760
+ * The payment intent can then be confirmed on the client side using Stripe.js.
1761
+ * After confirmation, use `processPaymentCore()` to complete the subscription.
1762
+ *
1763
+ * @param request - Standard Web API Request object
1125
1764
  * @param body - Payment intent parameters
1765
+ * @param body.planRef - Plan reference to subscribe to (required)
1766
+ * @param body.agentRef - Agent reference (required)
1126
1767
  * @param options - Configuration options
1127
- * @returns Payment intent response or error result
1768
+ * @param options.solvaPay - Optional SolvaPay instance (creates new one if not provided)
1769
+ * @param options.includeEmail - Whether to include email in customer data (default: true)
1770
+ * @param options.includeName - Whether to include name in customer data (default: true)
1771
+ * @returns Payment intent response with client secret and customer reference, or error result
1772
+ *
1773
+ * @example
1774
+ * ```typescript
1775
+ * // In an API route handler
1776
+ * export async function POST(request: Request) {
1777
+ * const body = await request.json();
1778
+ * const result = await createPaymentIntentCore(request, body);
1779
+ *
1780
+ * if (isErrorResult(result)) {
1781
+ * return Response.json(result, { status: result.status });
1782
+ * }
1783
+ *
1784
+ * return Response.json(result);
1785
+ * }
1786
+ * ```
1787
+ *
1788
+ * @see {@link processPaymentCore} for processing confirmed payments
1789
+ * @see {@link ErrorResult} for error handling
1790
+ * @since 1.0.0
1128
1791
  */
1129
1792
  declare function createPaymentIntentCore(request: Request, body: {
1130
1793
  planRef: string;
@@ -1141,12 +1804,45 @@ declare function createPaymentIntentCore(request: Request, body: {
1141
1804
  customerRef: string;
1142
1805
  } | ErrorResult>;
1143
1806
  /**
1144
- * Process payment - core implementation
1807
+ * Process a payment intent after client-side Stripe confirmation.
1145
1808
  *
1146
- * @param request - Standard Web API Request
1809
+ * This helper processes a payment intent that has been confirmed on the client
1810
+ * side using Stripe.js. It creates the subscription or purchase immediately,
1811
+ * eliminating webhook delay.
1812
+ *
1813
+ * Call this after the client has confirmed the payment intent with Stripe.js.
1814
+ *
1815
+ * @param request - Standard Web API Request object
1147
1816
  * @param body - Payment processing parameters
1817
+ * @param body.paymentIntentId - Stripe payment intent ID from client confirmation (required)
1818
+ * @param body.agentRef - Agent reference (required)
1819
+ * @param body.planRef - Optional plan reference (if not in payment intent)
1148
1820
  * @param options - Configuration options
1149
- * @returns Process payment result or error result
1821
+ * @param options.solvaPay - Optional SolvaPay instance (creates new one if not provided)
1822
+ * @returns Process payment result with subscription details, or error result
1823
+ *
1824
+ * @example
1825
+ * ```typescript
1826
+ * // In an API route handler
1827
+ * export async function POST(request: Request) {
1828
+ * const body = await request.json();
1829
+ * const result = await processPaymentCore(request, body);
1830
+ *
1831
+ * if (isErrorResult(result)) {
1832
+ * return Response.json(result, { status: result.status });
1833
+ * }
1834
+ *
1835
+ * if (result.success) {
1836
+ * console.log('Subscription created:', result.subscriptionRef);
1837
+ * }
1838
+ *
1839
+ * return Response.json(result);
1840
+ * }
1841
+ * ```
1842
+ *
1843
+ * @see {@link createPaymentIntentCore} for creating payment intents
1844
+ * @see {@link ErrorResult} for error handling
1845
+ * @since 1.0.0
1150
1846
  */
1151
1847
  declare function processPaymentCore(request: Request, body: {
1152
1848
  paymentIntentId: string;
@@ -1174,10 +1870,12 @@ declare function processPaymentCore(request: Request, body: {
1174
1870
  declare function createCheckoutSessionCore(request: Request, body: {
1175
1871
  agentRef: string;
1176
1872
  planRef?: string;
1873
+ returnUrl?: string;
1177
1874
  }, options?: {
1178
1875
  solvaPay?: SolvaPay;
1179
1876
  includeEmail?: boolean;
1180
1877
  includeName?: boolean;
1878
+ returnUrl?: string;
1181
1879
  }): Promise<{
1182
1880
  sessionId: string;
1183
1881
  checkoutUrl: string;
@@ -1246,7 +1944,50 @@ declare function listPlansCore(request: Request): Promise<{
1246
1944
  * Provides unified payable API with explicit adapters for all frameworks.
1247
1945
  */
1248
1946
 
1249
- declare function verifyWebhook({ body, signature, secret }: {
1947
+ /**
1948
+ * Verify webhook signature from SolvaPay backend.
1949
+ *
1950
+ * This function verifies that a webhook request is authentic by comparing
1951
+ * the provided signature with a computed HMAC-SHA256 signature of the request body.
1952
+ * Uses timing-safe comparison to prevent timing attacks.
1953
+ *
1954
+ * @param params - Webhook verification parameters
1955
+ * @param params.body - Raw request body as string (must be exactly as received)
1956
+ * @param params.signature - Signature from `x-solvapay-signature` header
1957
+ * @param params.secret - Webhook secret from SolvaPay dashboard
1958
+ * @returns Parsed webhook payload as object
1959
+ * @throws {SolvaPayError} If signature is invalid
1960
+ *
1961
+ * @example
1962
+ * ```typescript
1963
+ * import { verifyWebhook } from '@solvapay/server';
1964
+ *
1965
+ * // In Express.js
1966
+ * app.post('/webhooks/solvapay', express.raw({ type: 'application/json' }), (req, res) => {
1967
+ * try {
1968
+ * const signature = req.headers['x-solvapay-signature'] as string;
1969
+ * const payload = verifyWebhook({
1970
+ * body: req.body.toString(),
1971
+ * signature,
1972
+ * secret: process.env.SOLVAPAY_WEBHOOK_SECRET!
1973
+ * });
1974
+ *
1975
+ * // Handle webhook event
1976
+ * if (payload.type === 'subscription.created') {
1977
+ * // Process subscription creation
1978
+ * }
1979
+ *
1980
+ * res.json({ received: true });
1981
+ * } catch (error) {
1982
+ * res.status(401).json({ error: 'Invalid signature' });
1983
+ * }
1984
+ * });
1985
+ * ```
1986
+ *
1987
+ * @see [Webhook Guide](../../../docs/guides/webhooks.md) for complete webhook handling examples
1988
+ * @since 1.0.0
1989
+ */
1990
+ declare function verifyWebhook({ body, signature, secret, }: {
1250
1991
  body: string;
1251
1992
  signature: string;
1252
1993
  secret: string;