@solvapay/server 1.0.0-preview.18 → 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/LICENSE.md +21 -0
- package/README.md +49 -40
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/edge.d.ts +910 -215
- package/dist/edge.js +238 -174
- package/dist/{esm-5GYCIXIY.js → esm-UW7WCMEK.js} +1 -1
- package/dist/index.cjs +241 -171
- package/dist/index.d.cts +953 -215
- package/dist/index.d.ts +953 -215
- package/dist/index.js +243 -175
- package/package.json +7 -7
- package/dist/chunk-R5U7XKVJ.js +0 -16
package/dist/edge.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
|
-
*
|
|
25
|
+
* Customer reference identifier
|
|
57
26
|
* @example cus_3c4d5e6f7g8h
|
|
58
27
|
*/
|
|
59
28
|
customerRef: string;
|
|
60
29
|
/**
|
|
61
|
-
*
|
|
30
|
+
* Agent reference identifier
|
|
62
31
|
* @example agt_1a2b3c4d5e6f
|
|
63
32
|
*/
|
|
64
33
|
agentRef: string;
|
|
65
34
|
/**
|
|
66
|
-
*
|
|
35
|
+
* Plan reference identifier (optional)
|
|
67
36
|
* @example pln_2b3c4d5e6f7g
|
|
68
37
|
*/
|
|
69
38
|
planRef?: string;
|
|
70
39
|
/**
|
|
71
|
-
*
|
|
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
|
-
*
|
|
47
|
+
* Checkout session ID
|
|
79
48
|
* @example 507f1f77bcf86cd799439011
|
|
80
49
|
*/
|
|
81
50
|
id: string;
|
|
82
51
|
/**
|
|
83
|
-
*
|
|
52
|
+
* Public session ID used in checkout URL
|
|
84
53
|
* @example a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6
|
|
85
54
|
*/
|
|
86
55
|
sessionId: string;
|
|
87
56
|
/**
|
|
88
|
-
*
|
|
57
|
+
* Amount in cents
|
|
89
58
|
* @example 2999
|
|
90
59
|
*/
|
|
91
60
|
amount: number;
|
|
92
61
|
/**
|
|
93
|
-
*
|
|
62
|
+
* Currency code
|
|
94
63
|
* @example USD
|
|
95
64
|
*/
|
|
96
65
|
currency: string;
|
|
97
66
|
/**
|
|
98
|
-
*
|
|
67
|
+
* Session status
|
|
99
68
|
* @example active
|
|
100
69
|
*/
|
|
101
70
|
status: string;
|
|
102
71
|
/**
|
|
103
|
-
*
|
|
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
|
-
*
|
|
79
|
+
* Reason for cancellation
|
|
111
80
|
* @example Customer request
|
|
112
81
|
*/
|
|
113
82
|
reason?: string;
|
|
114
83
|
};
|
|
115
|
-
|
|
84
|
+
CreateConnectedAccount: Record<string, never>;
|
|
85
|
+
UpdateConnectedAccount: Record<string, never>;
|
|
86
|
+
CreateCheckoutSessionResponse: {
|
|
116
87
|
/**
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
88
|
+
* Checkout session ID/token
|
|
89
|
+
* @example e3f1c2d4b6a89f001122334455667788
|
|
119
90
|
*/
|
|
120
|
-
|
|
91
|
+
sessionId: string;
|
|
121
92
|
/**
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
93
|
+
* Full checkout URL based on backend configuration (ready to redirect customer)
|
|
94
|
+
* @example https://solvapay.com/customer/checkout?id=e3f1c2d4b6a89f001122334455667788
|
|
124
95
|
*/
|
|
125
|
-
|
|
96
|
+
checkoutUrl: string;
|
|
126
97
|
};
|
|
127
|
-
|
|
98
|
+
CreatePlanRequest: {
|
|
128
99
|
/**
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
100
|
+
* Plan name
|
|
101
|
+
* @example Basic Plan
|
|
131
102
|
*/
|
|
132
|
-
|
|
103
|
+
name: string;
|
|
133
104
|
/**
|
|
134
|
-
*
|
|
135
|
-
* @example
|
|
105
|
+
* Plan description
|
|
106
|
+
* @example Basic recurring plan with monthly billing
|
|
136
107
|
*/
|
|
137
|
-
|
|
108
|
+
description?: string;
|
|
138
109
|
/**
|
|
139
|
-
*
|
|
140
|
-
* @example
|
|
110
|
+
* Plan type
|
|
111
|
+
* @example recurring
|
|
112
|
+
* @enum {string}
|
|
141
113
|
*/
|
|
142
|
-
|
|
114
|
+
type?: "recurring" | "usage-based" | "hybrid" | "one-time";
|
|
143
115
|
/**
|
|
144
|
-
*
|
|
145
|
-
* @example
|
|
116
|
+
* Billing cycle
|
|
117
|
+
* @example monthly
|
|
118
|
+
* @enum {string}
|
|
146
119
|
*/
|
|
147
|
-
|
|
148
|
-
};
|
|
149
|
-
UsageEvent: {
|
|
120
|
+
billingCycle?: "weekly" | "monthly" | "quarterly" | "yearly" | "custom";
|
|
150
121
|
/**
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
122
|
+
* Plan price
|
|
123
|
+
* @example 29.99
|
|
153
124
|
*/
|
|
154
|
-
|
|
125
|
+
price?: number;
|
|
155
126
|
/**
|
|
156
|
-
*
|
|
157
|
-
* @example
|
|
127
|
+
* Currency code (ISO 4217)
|
|
128
|
+
* @example USD
|
|
129
|
+
* @enum {string}
|
|
158
130
|
*/
|
|
159
|
-
|
|
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
|
-
*
|
|
162
|
-
* @example
|
|
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
|
-
|
|
154
|
+
billingModel?: "pre-paid" | "post-paid";
|
|
166
155
|
/**
|
|
167
|
-
*
|
|
168
|
-
* @example
|
|
156
|
+
* Price per unit for usage-based plans
|
|
157
|
+
* @example 0.01
|
|
169
158
|
*/
|
|
170
|
-
|
|
159
|
+
pricePerUnit?: number;
|
|
171
160
|
/**
|
|
172
|
-
*
|
|
173
|
-
* @example
|
|
161
|
+
* Unit name for usage-based plans
|
|
162
|
+
* @example request
|
|
174
163
|
*/
|
|
175
|
-
|
|
164
|
+
unit?: string;
|
|
176
165
|
/**
|
|
177
|
-
*
|
|
178
|
-
* @example
|
|
166
|
+
* Usage quota for usage-based plans
|
|
167
|
+
* @example 10000
|
|
179
168
|
*/
|
|
180
|
-
|
|
169
|
+
quota?: number;
|
|
181
170
|
/**
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
171
|
+
* Whether to rollover unused units
|
|
172
|
+
* @example false
|
|
184
173
|
*/
|
|
185
|
-
|
|
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
|
-
*
|
|
265
|
+
* Customer email address (required)
|
|
190
266
|
* @example customer@example.com
|
|
191
267
|
*/
|
|
192
268
|
email: string;
|
|
193
269
|
/**
|
|
194
|
-
*
|
|
270
|
+
* Customer full name (optional)
|
|
195
271
|
* @example John Doe
|
|
196
272
|
*/
|
|
197
273
|
name?: string;
|
|
198
274
|
/**
|
|
199
|
-
*
|
|
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
|
-
*
|
|
282
|
+
* Subscription reference
|
|
207
283
|
* @example sub_abc123
|
|
208
284
|
*/
|
|
209
285
|
reference: string;
|
|
210
286
|
/**
|
|
211
|
-
*
|
|
287
|
+
* Plan name
|
|
212
288
|
* @example Pro Plan
|
|
213
289
|
*/
|
|
214
290
|
planName: string;
|
|
215
291
|
/**
|
|
216
|
-
*
|
|
292
|
+
* Agent name
|
|
217
293
|
* @example AI Assistant
|
|
218
294
|
*/
|
|
219
295
|
agentName: string;
|
|
220
296
|
/**
|
|
221
|
-
*
|
|
297
|
+
* Subscription status
|
|
222
298
|
* @example active
|
|
223
299
|
*/
|
|
224
300
|
status: string;
|
|
225
301
|
/**
|
|
226
|
-
*
|
|
302
|
+
* Start date
|
|
227
303
|
* @example 2025-10-27T10:00:00Z
|
|
228
304
|
*/
|
|
229
305
|
startDate: string;
|
|
230
306
|
/**
|
|
231
|
-
*
|
|
307
|
+
* Amount paid in original currency (in cents)
|
|
232
308
|
* @example 9900
|
|
233
309
|
*/
|
|
234
310
|
amount: number;
|
|
235
311
|
/**
|
|
236
|
-
*
|
|
312
|
+
* Currency code
|
|
237
313
|
* @example USD
|
|
238
314
|
*/
|
|
239
315
|
currency: string;
|
|
240
316
|
/**
|
|
241
|
-
*
|
|
317
|
+
* End date of subscription
|
|
242
318
|
* @example 2025-11-27T10:00:00Z
|
|
243
319
|
*/
|
|
244
320
|
endDate?: string;
|
|
245
321
|
/**
|
|
246
|
-
*
|
|
322
|
+
* When subscription was cancelled
|
|
247
323
|
* @example 2025-10-28T10:00:00Z
|
|
248
324
|
*/
|
|
249
325
|
cancelledAt?: string;
|
|
250
326
|
/**
|
|
251
|
-
*
|
|
327
|
+
* Reason for cancellation
|
|
252
328
|
* @example Customer request
|
|
253
329
|
*/
|
|
254
330
|
cancellationReason?: string;
|
|
255
331
|
};
|
|
256
332
|
CustomerResponse: {
|
|
257
333
|
/**
|
|
258
|
-
*
|
|
334
|
+
* Customer reference identifier
|
|
259
335
|
* @example cus_3c4d5e6f7g8h
|
|
260
336
|
*/
|
|
261
337
|
reference: string;
|
|
262
338
|
/**
|
|
263
|
-
*
|
|
339
|
+
* Customer full name
|
|
264
340
|
* @example John Doe
|
|
265
341
|
*/
|
|
266
342
|
name: string;
|
|
267
343
|
/**
|
|
268
|
-
*
|
|
344
|
+
* Customer email address
|
|
269
345
|
* @example customer@example.com
|
|
270
346
|
*/
|
|
271
347
|
email: string;
|
|
272
348
|
/**
|
|
273
|
-
*
|
|
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
|
-
*
|
|
358
|
+
* Customer session ID/token
|
|
283
359
|
* @example e3f1c2d4b6a89f001122334455667788
|
|
284
360
|
*/
|
|
285
361
|
sessionId: string;
|
|
286
362
|
/**
|
|
287
|
-
*
|
|
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
|
-
*
|
|
370
|
+
* Customer session ID/token
|
|
295
371
|
* @example e3f1c2d4b6a89f001122334455667788
|
|
296
372
|
*/
|
|
297
373
|
sessionId: string;
|
|
298
374
|
/**
|
|
299
|
-
*
|
|
375
|
+
* Session status
|
|
300
376
|
* @example active
|
|
301
377
|
* @enum {string}
|
|
302
378
|
*/
|
|
303
379
|
status: "active" | "expired" | "used";
|
|
304
380
|
/**
|
|
305
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
393
|
+
* Session creation date
|
|
318
394
|
* @example 2025-01-01T11:45:00.000Z
|
|
319
395
|
*/
|
|
320
396
|
createdAt: string;
|
|
321
397
|
/**
|
|
322
|
-
*
|
|
398
|
+
* Session last update date
|
|
323
399
|
* @example 2025-01-01T11:45:00.000Z
|
|
324
400
|
*/
|
|
325
401
|
updatedAt: string;
|
|
326
402
|
};
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
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
|
-
*
|
|
425
|
+
* Subscription reference identifier
|
|
334
426
|
* @example sub_1a2b3c4d5e6f
|
|
335
427
|
*/
|
|
336
428
|
reference: string;
|
|
337
429
|
/**
|
|
338
|
-
*
|
|
430
|
+
* Customer reference identifier
|
|
339
431
|
* @example cus_3c4d5e6f7g8h
|
|
340
432
|
*/
|
|
341
433
|
customerRef: string;
|
|
342
434
|
/**
|
|
343
|
-
*
|
|
435
|
+
* Customer email
|
|
344
436
|
* @example customer@example.com
|
|
345
437
|
*/
|
|
346
438
|
customerEmail: string;
|
|
347
439
|
/**
|
|
348
|
-
*
|
|
440
|
+
* Customer name
|
|
349
441
|
* @example John Doe
|
|
350
442
|
*/
|
|
351
443
|
customerName?: string;
|
|
352
444
|
/**
|
|
353
|
-
*
|
|
445
|
+
* Agent reference identifier
|
|
354
446
|
* @example agt_1a2b3c4d5e6f
|
|
355
447
|
*/
|
|
356
448
|
agentRef: string;
|
|
357
449
|
/**
|
|
358
|
-
*
|
|
450
|
+
* Agent name
|
|
359
451
|
* @example My AI Agent
|
|
360
452
|
*/
|
|
361
453
|
agentName: string;
|
|
362
454
|
/**
|
|
363
|
-
*
|
|
455
|
+
* Plan reference identifier
|
|
364
456
|
* @example pln_1a2b3c4d5e6f
|
|
365
457
|
*/
|
|
366
458
|
planRef: string;
|
|
367
459
|
/**
|
|
368
|
-
*
|
|
460
|
+
* Plan name
|
|
369
461
|
* @example Premium Plan
|
|
370
462
|
*/
|
|
371
463
|
planName: string;
|
|
372
464
|
/**
|
|
373
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
477
|
+
* Amount paid in original currency (in cents)
|
|
386
478
|
* @example 9900
|
|
387
479
|
*/
|
|
388
480
|
amount: number;
|
|
389
481
|
/**
|
|
390
|
-
*
|
|
482
|
+
* Currency code
|
|
391
483
|
* @example USD
|
|
392
484
|
*/
|
|
393
485
|
currency: string;
|
|
394
486
|
/**
|
|
395
|
-
*
|
|
487
|
+
* Start date of subscription
|
|
396
488
|
* @example 2025-01-01T00:00:00.000Z
|
|
397
489
|
*/
|
|
398
490
|
startDate: string;
|
|
399
491
|
/**
|
|
400
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
504
|
+
* Whether this is a recurring subscription
|
|
413
505
|
* @example true
|
|
414
506
|
*/
|
|
415
507
|
isRecurring: boolean;
|
|
416
508
|
/**
|
|
417
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
519
|
+
* Reason for cancellation (if applicable)
|
|
428
520
|
* @example Customer request
|
|
429
521
|
*/
|
|
430
522
|
cancellationReason?: string;
|
|
431
523
|
/**
|
|
432
|
-
*
|
|
524
|
+
* When subscription was created
|
|
433
525
|
* @example 2025-01-01T00:00:00.000Z
|
|
434
526
|
*/
|
|
435
527
|
createdAt: string;
|
|
436
528
|
};
|
|
437
|
-
|
|
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: {
|
|
542
|
+
/**
|
|
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;
|
|
438
552
|
/**
|
|
439
|
-
*
|
|
553
|
+
* Optional checkout session ID/token if payment is required
|
|
440
554
|
* @example e3f1c2d4b6a89f001122334455667788
|
|
441
555
|
*/
|
|
442
|
-
|
|
556
|
+
checkoutSessionId?: string;
|
|
443
557
|
/**
|
|
444
|
-
*
|
|
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
|
|
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
|
-
*
|
|
617
|
+
* Text color in hex format
|
|
458
618
|
* @example #2d3748
|
|
459
619
|
*/
|
|
460
620
|
textColor: string;
|
|
461
621
|
/**
|
|
462
|
-
*
|
|
622
|
+
* Button color in hex format
|
|
463
623
|
* @example #3182ce
|
|
464
624
|
*/
|
|
465
625
|
buttonColor: string;
|
|
466
626
|
/**
|
|
467
|
-
*
|
|
627
|
+
* Left background color in hex format
|
|
468
628
|
* @example #f7fafc
|
|
469
629
|
*/
|
|
470
630
|
leftBackgroundColor: string;
|
|
471
631
|
/**
|
|
472
|
-
*
|
|
632
|
+
* Right background color in hex format
|
|
473
633
|
* @example #ffffff
|
|
474
634
|
*/
|
|
475
635
|
rightBackgroundColor: string;
|
|
476
636
|
/**
|
|
477
|
-
*
|
|
637
|
+
* Font family
|
|
478
638
|
* @example Inter
|
|
479
639
|
*/
|
|
480
640
|
fontFamily: string;
|
|
481
641
|
/**
|
|
482
|
-
*
|
|
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
|
|
558
|
-
customerRef
|
|
559
|
-
|
|
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;
|
|
@@ -788,91 +948,283 @@ type ServerClientOptions = {
|
|
|
788
948
|
apiKey: string;
|
|
789
949
|
/**
|
|
790
950
|
* Base URL for the SolvaPay API (optional)
|
|
791
|
-
* Defaults to https://api
|
|
951
|
+
* Defaults to https://api.solvapay.com
|
|
792
952
|
*/
|
|
793
953
|
apiBaseUrl?: string;
|
|
794
954
|
};
|
|
795
955
|
/**
|
|
796
|
-
* Creates a SolvaPay API client that implements the full SolvaPayClient
|
|
797
|
-
*
|
|
956
|
+
* Creates a SolvaPay API client that implements the full SolvaPayClient interface.
|
|
957
|
+
*
|
|
958
|
+
* This function creates a low-level API client for direct communication with the
|
|
959
|
+
* SolvaPay backend. For most use cases, use `createSolvaPay()` instead, which
|
|
960
|
+
* provides a higher-level API with paywall protection.
|
|
961
|
+
*
|
|
962
|
+
* Use this function when you need:
|
|
963
|
+
* - Direct API access for custom operations
|
|
964
|
+
* - Testing with custom client implementations
|
|
965
|
+
* - Advanced use cases not covered by the main API
|
|
798
966
|
*
|
|
799
|
-
* @param opts - Configuration options
|
|
967
|
+
* @param opts - Configuration options
|
|
968
|
+
* @param opts.apiKey - Your SolvaPay API key (required)
|
|
969
|
+
* @param opts.apiBaseUrl - Optional API base URL override
|
|
800
970
|
* @returns A fully configured SolvaPayClient instance
|
|
801
971
|
* @throws {SolvaPayError} If API key is missing
|
|
802
972
|
*
|
|
803
973
|
* @example
|
|
804
974
|
* ```typescript
|
|
975
|
+
* // Create API client directly
|
|
805
976
|
* const client = createSolvaPayClient({
|
|
806
977
|
* apiKey: process.env.SOLVAPAY_SECRET_KEY!,
|
|
807
978
|
* apiBaseUrl: 'https://api.solvapay.com' // optional
|
|
808
979
|
* });
|
|
980
|
+
*
|
|
981
|
+
* // Use client for custom operations
|
|
982
|
+
* const agents = await client.listAgents();
|
|
809
983
|
* ```
|
|
984
|
+
*
|
|
985
|
+
* @see {@link createSolvaPay} for the recommended high-level API
|
|
986
|
+
* @see {@link ServerClientOptions} for configuration options
|
|
987
|
+
* @since 1.0.0
|
|
810
988
|
*/
|
|
811
989
|
declare function createSolvaPayClient(opts: ServerClientOptions): SolvaPayClient;
|
|
812
990
|
|
|
813
991
|
/**
|
|
814
|
-
* Configuration for creating a SolvaPay instance
|
|
992
|
+
* Configuration for creating a SolvaPay instance.
|
|
993
|
+
*
|
|
994
|
+
* You can provide either an `apiKey` (for production) or an `apiClient` (for testing).
|
|
995
|
+
* If neither is provided, the SDK will attempt to read `SOLVAPAY_SECRET_KEY` from
|
|
996
|
+
* environment variables. If no API key is found, the SDK runs in stub mode.
|
|
997
|
+
*
|
|
998
|
+
* @example
|
|
999
|
+
* ```typescript
|
|
1000
|
+
* // Production: Use API key
|
|
1001
|
+
* const config: CreateSolvaPayConfig = {
|
|
1002
|
+
* apiKey: process.env.SOLVAPAY_SECRET_KEY
|
|
1003
|
+
* };
|
|
1004
|
+
*
|
|
1005
|
+
* // Testing: Use mock client
|
|
1006
|
+
* const config: CreateSolvaPayConfig = {
|
|
1007
|
+
* apiClient: mockClient
|
|
1008
|
+
* };
|
|
1009
|
+
* ```
|
|
815
1010
|
*/
|
|
816
1011
|
interface CreateSolvaPayConfig {
|
|
817
1012
|
/**
|
|
818
|
-
* API key for production use (creates client automatically)
|
|
1013
|
+
* API key for production use (creates client automatically).
|
|
1014
|
+
* Defaults to `SOLVAPAY_SECRET_KEY` environment variable if not provided.
|
|
819
1015
|
*/
|
|
820
1016
|
apiKey?: string;
|
|
821
1017
|
/**
|
|
822
|
-
* API client for testing or custom implementations
|
|
1018
|
+
* API client for testing or custom implementations.
|
|
1019
|
+
* Use this for stub mode, testing, or custom client implementations.
|
|
823
1020
|
*/
|
|
824
1021
|
apiClient?: SolvaPayClient;
|
|
825
1022
|
/**
|
|
826
|
-
* Optional API base URL (only used with apiKey)
|
|
1023
|
+
* Optional API base URL override (only used with apiKey).
|
|
1024
|
+
* Defaults to production API URL if not provided.
|
|
827
1025
|
*/
|
|
828
1026
|
apiBaseUrl?: string;
|
|
829
1027
|
}
|
|
830
1028
|
/**
|
|
831
|
-
* Payable function that provides explicit adapters
|
|
1029
|
+
* Payable function that provides explicit adapters for different frameworks.
|
|
1030
|
+
*
|
|
1031
|
+
* Use the appropriate adapter method for your framework:
|
|
1032
|
+
* - `http()` - Express.js, Fastify, and other HTTP frameworks
|
|
1033
|
+
* - `next()` - Next.js App Router API routes
|
|
1034
|
+
* - `mcp()` - Model Context Protocol servers
|
|
1035
|
+
* - `function()` - Pure functions, background jobs, or testing
|
|
1036
|
+
*
|
|
1037
|
+
* @example
|
|
1038
|
+
* ```typescript
|
|
1039
|
+
* const payable = solvaPay.payable({ agent: 'agt_myapi', plan: 'pln_premium' });
|
|
1040
|
+
*
|
|
1041
|
+
* // Express.js
|
|
1042
|
+
* app.post('/tasks', payable.http(createTask));
|
|
1043
|
+
*
|
|
1044
|
+
* // Next.js
|
|
1045
|
+
* export const POST = payable.next(createTask);
|
|
1046
|
+
*
|
|
1047
|
+
* // MCP Server
|
|
1048
|
+
* const handler = payable.mcp(createTask);
|
|
1049
|
+
*
|
|
1050
|
+
* // Pure function
|
|
1051
|
+
* const protectedFn = await payable.function(createTask);
|
|
1052
|
+
* ```
|
|
832
1053
|
*/
|
|
833
1054
|
interface PayableFunction {
|
|
834
1055
|
/**
|
|
835
|
-
* HTTP adapter for Express
|
|
1056
|
+
* HTTP adapter for Express.js, Fastify, and other HTTP frameworks.
|
|
1057
|
+
*
|
|
1058
|
+
* @param businessLogic - Your business logic function
|
|
1059
|
+
* @param options - Optional adapter configuration
|
|
1060
|
+
* @returns HTTP route handler function
|
|
1061
|
+
*
|
|
1062
|
+
* @example
|
|
1063
|
+
* ```typescript
|
|
1064
|
+
* app.post('/tasks', payable.http(async (req) => {
|
|
1065
|
+
* const { title } = req.body;
|
|
1066
|
+
* return { success: true, task: { title } };
|
|
1067
|
+
* }));
|
|
1068
|
+
* ```
|
|
836
1069
|
*/
|
|
837
1070
|
http<T = any>(businessLogic: (args: any) => Promise<T>, options?: HttpAdapterOptions): (req: any, reply: any) => Promise<any>;
|
|
838
1071
|
/**
|
|
839
|
-
* Next.js adapter for App Router
|
|
1072
|
+
* Next.js adapter for App Router API routes.
|
|
1073
|
+
*
|
|
1074
|
+
* @param businessLogic - Your business logic function
|
|
1075
|
+
* @param options - Optional adapter configuration
|
|
1076
|
+
* @returns Next.js route handler function
|
|
1077
|
+
*
|
|
1078
|
+
* @example
|
|
1079
|
+
* ```typescript
|
|
1080
|
+
* // app/api/tasks/route.ts
|
|
1081
|
+
* export const POST = payable.next(async (request) => {
|
|
1082
|
+
* const body = await request.json();
|
|
1083
|
+
* return Response.json({ success: true });
|
|
1084
|
+
* });
|
|
1085
|
+
* ```
|
|
840
1086
|
*/
|
|
841
1087
|
next<T = any>(businessLogic: (args: any) => Promise<T>, options?: NextAdapterOptions): (request: Request, context?: any) => Promise<Response>;
|
|
842
1088
|
/**
|
|
843
|
-
* MCP adapter for Model Context Protocol servers
|
|
1089
|
+
* MCP adapter for Model Context Protocol servers.
|
|
1090
|
+
*
|
|
1091
|
+
* @param businessLogic - Your tool implementation function
|
|
1092
|
+
* @param options - Optional adapter configuration
|
|
1093
|
+
* @returns MCP tool handler function
|
|
1094
|
+
*
|
|
1095
|
+
* @example
|
|
1096
|
+
* ```typescript
|
|
1097
|
+
* const handler = payable.mcp(async (args) => {
|
|
1098
|
+
* return { success: true, result: 'tool output' };
|
|
1099
|
+
* });
|
|
1100
|
+
* ```
|
|
844
1101
|
*/
|
|
845
1102
|
mcp<T = any>(businessLogic: (args: any) => Promise<T>, options?: McpAdapterOptions): (args: any) => Promise<any>;
|
|
846
1103
|
/**
|
|
847
|
-
* Pure function adapter for direct function protection
|
|
848
|
-
*
|
|
1104
|
+
* Pure function adapter for direct function protection.
|
|
1105
|
+
*
|
|
1106
|
+
* Use this for testing, background jobs, or non-framework contexts.
|
|
1107
|
+
*
|
|
1108
|
+
* @param businessLogic - Your business logic function
|
|
1109
|
+
* @returns Protected function that requires customer reference in args
|
|
1110
|
+
*
|
|
1111
|
+
* @example
|
|
1112
|
+
* ```typescript
|
|
1113
|
+
* const protectedFn = await payable.function(async (args) => {
|
|
1114
|
+
* return { result: 'processed' };
|
|
1115
|
+
* });
|
|
1116
|
+
*
|
|
1117
|
+
* // Call with customer reference
|
|
1118
|
+
* const result = await protectedFn({
|
|
1119
|
+
* auth: { customer_ref: 'user_123' },
|
|
1120
|
+
* // ... other args
|
|
1121
|
+
* });
|
|
1122
|
+
* ```
|
|
849
1123
|
*/
|
|
850
1124
|
function<T = any>(businessLogic: (args: any) => Promise<T>): Promise<(args: any) => Promise<T>>;
|
|
851
1125
|
}
|
|
852
1126
|
/**
|
|
853
|
-
* SolvaPay instance with payable method and common API methods
|
|
1127
|
+
* SolvaPay instance with payable method and common API methods.
|
|
1128
|
+
*
|
|
1129
|
+
* This interface provides the main API for interacting with SolvaPay.
|
|
1130
|
+
* Use `createSolvaPay()` to create an instance.
|
|
1131
|
+
*
|
|
1132
|
+
* @example
|
|
1133
|
+
* ```typescript
|
|
1134
|
+
* const solvaPay = createSolvaPay();
|
|
1135
|
+
*
|
|
1136
|
+
* // Create payable handlers
|
|
1137
|
+
* const payable = solvaPay.payable({ agent: 'agt_myapi', plan: 'pln_premium' });
|
|
1138
|
+
*
|
|
1139
|
+
* // Manage customers
|
|
1140
|
+
* const customerRef = await solvaPay.ensureCustomer('user_123', 'user_123', {
|
|
1141
|
+
* email: 'user@example.com'
|
|
1142
|
+
* });
|
|
1143
|
+
*
|
|
1144
|
+
* // Create payment intents
|
|
1145
|
+
* const intent = await solvaPay.createPaymentIntent({
|
|
1146
|
+
* agentRef: 'agt_myapi',
|
|
1147
|
+
* planRef: 'pln_premium',
|
|
1148
|
+
* customerRef: 'user_123'
|
|
1149
|
+
* });
|
|
1150
|
+
* ```
|
|
854
1151
|
*/
|
|
855
1152
|
interface SolvaPay {
|
|
856
1153
|
/**
|
|
857
|
-
* Create a payable handler with explicit adapters
|
|
1154
|
+
* Create a payable handler with explicit adapters for different frameworks.
|
|
1155
|
+
*
|
|
1156
|
+
* @param options - Payable options including agent and plan references
|
|
1157
|
+
* @returns PayableFunction with framework-specific adapters
|
|
1158
|
+
*
|
|
1159
|
+
* @example
|
|
1160
|
+
* ```typescript
|
|
1161
|
+
* const payable = solvaPay.payable({
|
|
1162
|
+
* agent: 'agt_myapi',
|
|
1163
|
+
* plan: 'pln_premium'
|
|
1164
|
+
* });
|
|
1165
|
+
*
|
|
1166
|
+
* app.post('/tasks', payable.http(createTask));
|
|
1167
|
+
* ```
|
|
858
1168
|
*/
|
|
859
1169
|
payable(options?: PayableOptions): PayableFunction;
|
|
860
1170
|
/**
|
|
861
|
-
* Ensure customer exists (
|
|
862
|
-
*
|
|
1171
|
+
* Ensure customer exists in SolvaPay backend (idempotent).
|
|
1172
|
+
*
|
|
1173
|
+
* Creates a customer if they don't exist, or returns existing customer reference.
|
|
1174
|
+
* This is automatically called by the paywall system, but you can call it
|
|
1175
|
+
* explicitly for setup or testing.
|
|
863
1176
|
*
|
|
864
1177
|
* @param customerRef - The customer reference used as a cache key (e.g., Supabase user ID)
|
|
865
|
-
* @param externalRef - Optional external reference for backend lookup (e.g., Supabase user ID)
|
|
1178
|
+
* @param externalRef - Optional external reference for backend lookup (e.g., Supabase user ID).
|
|
866
1179
|
* If provided, will lookup existing customer by externalRef before creating new one.
|
|
867
1180
|
* The externalRef is stored on the SolvaPay backend for customer lookup.
|
|
868
|
-
* @param options - Optional customer details
|
|
1181
|
+
* @param options - Optional customer details for customer creation
|
|
1182
|
+
* @param options.email - Customer email address
|
|
1183
|
+
* @param options.name - Customer name
|
|
1184
|
+
* @returns Customer reference (backend customer ID)
|
|
1185
|
+
*
|
|
1186
|
+
* @example
|
|
1187
|
+
* ```typescript
|
|
1188
|
+
* // Ensure customer exists before processing payment
|
|
1189
|
+
* const customerRef = await solvaPay.ensureCustomer(
|
|
1190
|
+
* 'user_123', // customerRef (your user ID)
|
|
1191
|
+
* 'user_123', // externalRef (same or different)
|
|
1192
|
+
* {
|
|
1193
|
+
* email: 'user@example.com',
|
|
1194
|
+
* name: 'John Doe'
|
|
1195
|
+
* }
|
|
1196
|
+
* );
|
|
1197
|
+
* ```
|
|
869
1198
|
*/
|
|
870
1199
|
ensureCustomer(customerRef: string, externalRef?: string, options?: {
|
|
871
1200
|
email?: string;
|
|
872
1201
|
name?: string;
|
|
873
1202
|
}): Promise<string>;
|
|
874
1203
|
/**
|
|
875
|
-
* Create a payment intent for a customer to subscribe to a plan
|
|
1204
|
+
* Create a Stripe payment intent for a customer to subscribe to a plan.
|
|
1205
|
+
*
|
|
1206
|
+
* This creates a payment intent that can be confirmed on the client side
|
|
1207
|
+
* using Stripe.js. After confirmation, call `processPayment()` to complete
|
|
1208
|
+
* the subscription.
|
|
1209
|
+
*
|
|
1210
|
+
* @param params - Payment intent parameters
|
|
1211
|
+
* @param params.agentRef - Agent reference
|
|
1212
|
+
* @param params.planRef - Plan reference to subscribe to
|
|
1213
|
+
* @param params.customerRef - Customer reference
|
|
1214
|
+
* @param params.idempotencyKey - Optional idempotency key for retry safety
|
|
1215
|
+
* @returns Payment intent with client secret and publishable key
|
|
1216
|
+
*
|
|
1217
|
+
* @example
|
|
1218
|
+
* ```typescript
|
|
1219
|
+
* const intent = await solvaPay.createPaymentIntent({
|
|
1220
|
+
* agentRef: 'agt_myapi',
|
|
1221
|
+
* planRef: 'pln_premium',
|
|
1222
|
+
* customerRef: 'user_123',
|
|
1223
|
+
* idempotencyKey: 'unique-key-123'
|
|
1224
|
+
* });
|
|
1225
|
+
*
|
|
1226
|
+
* // Use intent.clientSecret with Stripe.js on client
|
|
1227
|
+
* ```
|
|
876
1228
|
*/
|
|
877
1229
|
createPaymentIntent(params: {
|
|
878
1230
|
agentRef: string;
|
|
@@ -886,8 +1238,32 @@ interface SolvaPay {
|
|
|
886
1238
|
accountId?: string;
|
|
887
1239
|
}>;
|
|
888
1240
|
/**
|
|
889
|
-
* Process a payment intent after client-side confirmation
|
|
890
|
-
*
|
|
1241
|
+
* Process a payment intent after client-side Stripe confirmation.
|
|
1242
|
+
*
|
|
1243
|
+
* Creates subscription or purchase immediately, eliminating webhook delay.
|
|
1244
|
+
* Call this after the client has confirmed the payment intent with Stripe.js.
|
|
1245
|
+
*
|
|
1246
|
+
* @param params - Payment processing parameters
|
|
1247
|
+
* @param params.paymentIntentId - Stripe payment intent ID from client confirmation
|
|
1248
|
+
* @param params.agentRef - Agent reference
|
|
1249
|
+
* @param params.customerRef - Customer reference
|
|
1250
|
+
* @param params.planRef - Optional plan reference (if not in payment intent)
|
|
1251
|
+
* @returns Payment processing result with subscription details
|
|
1252
|
+
*
|
|
1253
|
+
* @example
|
|
1254
|
+
* ```typescript
|
|
1255
|
+
* // After client confirms payment with Stripe.js
|
|
1256
|
+
* const result = await solvaPay.processPayment({
|
|
1257
|
+
* paymentIntentId: 'pi_1234567890',
|
|
1258
|
+
* agentRef: 'agt_myapi',
|
|
1259
|
+
* customerRef: 'user_123',
|
|
1260
|
+
* planRef: 'pln_premium'
|
|
1261
|
+
* });
|
|
1262
|
+
*
|
|
1263
|
+
* if (result.success) {
|
|
1264
|
+
* console.log('Subscription created:', result.subscriptionRef);
|
|
1265
|
+
* }
|
|
1266
|
+
* ```
|
|
891
1267
|
*/
|
|
892
1268
|
processPayment(params: {
|
|
893
1269
|
paymentIntentId: string;
|
|
@@ -896,7 +1272,28 @@ interface SolvaPay {
|
|
|
896
1272
|
planRef?: string;
|
|
897
1273
|
}): Promise<ProcessPaymentResult>;
|
|
898
1274
|
/**
|
|
899
|
-
* Check if customer is within usage limits
|
|
1275
|
+
* Check if customer is within usage limits for an agent.
|
|
1276
|
+
*
|
|
1277
|
+
* This method checks subscription status and usage limits without
|
|
1278
|
+
* executing business logic. Use `payable()` for automatic protection.
|
|
1279
|
+
*
|
|
1280
|
+
* @param params - Limit check parameters
|
|
1281
|
+
* @param params.customerRef - Customer reference
|
|
1282
|
+
* @param params.agentRef - Agent reference
|
|
1283
|
+
* @returns Limit check result with remaining usage and checkout URL if needed
|
|
1284
|
+
*
|
|
1285
|
+
* @example
|
|
1286
|
+
* ```typescript
|
|
1287
|
+
* const limits = await solvaPay.checkLimits({
|
|
1288
|
+
* customerRef: 'user_123',
|
|
1289
|
+
* agentRef: 'agt_myapi'
|
|
1290
|
+
* });
|
|
1291
|
+
*
|
|
1292
|
+
* if (!limits.withinLimits) {
|
|
1293
|
+
* // Redirect to checkout
|
|
1294
|
+
* window.location.href = limits.checkoutUrl;
|
|
1295
|
+
* }
|
|
1296
|
+
* ```
|
|
900
1297
|
*/
|
|
901
1298
|
checkLimits(params: {
|
|
902
1299
|
customerRef: string;
|
|
@@ -908,7 +1305,34 @@ interface SolvaPay {
|
|
|
908
1305
|
checkoutUrl?: string;
|
|
909
1306
|
}>;
|
|
910
1307
|
/**
|
|
911
|
-
* Track usage for a customer action
|
|
1308
|
+
* Track usage for a customer action.
|
|
1309
|
+
*
|
|
1310
|
+
* This is automatically called by the paywall system. You typically
|
|
1311
|
+
* don't need to call this manually unless implementing custom tracking.
|
|
1312
|
+
*
|
|
1313
|
+
* @param params - Usage tracking parameters
|
|
1314
|
+
* @param params.customerRef - Customer reference
|
|
1315
|
+
* @param params.agentRef - Agent reference
|
|
1316
|
+
* @param params.planRef - Plan reference
|
|
1317
|
+
* @param params.outcome - Action outcome ('success', 'paywall', or 'fail')
|
|
1318
|
+
* @param params.action - Optional action name for analytics
|
|
1319
|
+
* @param params.requestId - Unique request ID
|
|
1320
|
+
* @param params.actionDuration - Action duration in milliseconds
|
|
1321
|
+
* @param params.timestamp - ISO timestamp of the action
|
|
1322
|
+
*
|
|
1323
|
+
* @example
|
|
1324
|
+
* ```typescript
|
|
1325
|
+
* await solvaPay.trackUsage({
|
|
1326
|
+
* customerRef: 'user_123',
|
|
1327
|
+
* agentRef: 'agt_myapi',
|
|
1328
|
+
* planRef: 'pln_premium',
|
|
1329
|
+
* outcome: 'success',
|
|
1330
|
+
* action: 'api_call',
|
|
1331
|
+
* requestId: 'req_123',
|
|
1332
|
+
* actionDuration: 150,
|
|
1333
|
+
* timestamp: new Date().toISOString()
|
|
1334
|
+
* });
|
|
1335
|
+
* ```
|
|
912
1336
|
*/
|
|
913
1337
|
trackUsage(params: {
|
|
914
1338
|
customerRef: string;
|
|
@@ -921,7 +1345,23 @@ interface SolvaPay {
|
|
|
921
1345
|
timestamp: string;
|
|
922
1346
|
}): Promise<void>;
|
|
923
1347
|
/**
|
|
924
|
-
* Create a new customer
|
|
1348
|
+
* Create a new customer in SolvaPay backend.
|
|
1349
|
+
*
|
|
1350
|
+
* Note: `ensureCustomer()` is usually preferred as it's idempotent.
|
|
1351
|
+
* Use this only if you need explicit control over customer creation.
|
|
1352
|
+
*
|
|
1353
|
+
* @param params - Customer creation parameters
|
|
1354
|
+
* @param params.email - Customer email address (required)
|
|
1355
|
+
* @param params.name - Optional customer name
|
|
1356
|
+
* @returns Created customer reference
|
|
1357
|
+
*
|
|
1358
|
+
* @example
|
|
1359
|
+
* ```typescript
|
|
1360
|
+
* const { customerRef } = await solvaPay.createCustomer({
|
|
1361
|
+
* email: 'user@example.com',
|
|
1362
|
+
* name: 'John Doe'
|
|
1363
|
+
* });
|
|
1364
|
+
* ```
|
|
925
1365
|
*/
|
|
926
1366
|
createCustomer(params: {
|
|
927
1367
|
email: string;
|
|
@@ -930,14 +1370,58 @@ interface SolvaPay {
|
|
|
930
1370
|
customerRef: string;
|
|
931
1371
|
}>;
|
|
932
1372
|
/**
|
|
933
|
-
* Get customer details
|
|
934
|
-
*
|
|
1373
|
+
* Get customer details including subscriptions and usage.
|
|
1374
|
+
*
|
|
1375
|
+
* Returns full customer information from the SolvaPay backend, including
|
|
1376
|
+
* all active subscriptions, usage history, and customer metadata.
|
|
1377
|
+
*
|
|
1378
|
+
* @param params - Customer lookup parameters
|
|
1379
|
+
* @param params.customerRef - Optional customer reference (SolvaPay ID)
|
|
1380
|
+
* @param params.externalRef - Optional external reference (e.g., Supabase ID)
|
|
1381
|
+
* @returns Customer details with subscriptions and metadata
|
|
1382
|
+
*
|
|
1383
|
+
* @example
|
|
1384
|
+
* ```typescript
|
|
1385
|
+
* // Lookup by SolvaPay customer ID
|
|
1386
|
+
* const customer = await solvaPay.getCustomer({
|
|
1387
|
+
* customerRef: 'cust_123'
|
|
1388
|
+
* });
|
|
1389
|
+
*
|
|
1390
|
+
* // Lookup by external ID (e.g. Supabase user ID)
|
|
1391
|
+
* const customer = await solvaPay.getCustomer({
|
|
1392
|
+
* externalRef: 'user_123'
|
|
1393
|
+
* });
|
|
1394
|
+
* ```
|
|
935
1395
|
*/
|
|
936
1396
|
getCustomer(params: {
|
|
937
|
-
customerRef
|
|
1397
|
+
customerRef?: string;
|
|
1398
|
+
externalRef?: string;
|
|
938
1399
|
}): Promise<CustomerResponseMapped>;
|
|
939
1400
|
/**
|
|
940
|
-
* Create a checkout session for a customer
|
|
1401
|
+
* Create a hosted checkout session for a customer.
|
|
1402
|
+
*
|
|
1403
|
+
* This creates a Stripe Checkout session that redirects the customer
|
|
1404
|
+
* to a hosted payment page. After payment, customer is redirected back.
|
|
1405
|
+
*
|
|
1406
|
+
* @param params - Checkout session parameters
|
|
1407
|
+
* @param params.agentRef - Agent reference
|
|
1408
|
+
* @param params.customerRef - Customer reference
|
|
1409
|
+
* @param params.planRef - Optional plan reference (if not specified, shows plan selector)
|
|
1410
|
+
* @param params.returnUrl - URL to redirect to after successful payment
|
|
1411
|
+
* @returns Checkout session with redirect URL
|
|
1412
|
+
*
|
|
1413
|
+
* @example
|
|
1414
|
+
* ```typescript
|
|
1415
|
+
* const session = await solvaPay.createCheckoutSession({
|
|
1416
|
+
* agentRef: 'agt_myapi',
|
|
1417
|
+
* customerRef: 'user_123',
|
|
1418
|
+
* planRef: 'pln_premium',
|
|
1419
|
+
* returnUrl: 'https://myapp.com/success'
|
|
1420
|
+
* });
|
|
1421
|
+
*
|
|
1422
|
+
* // Redirect customer to checkout
|
|
1423
|
+
* window.location.href = session.checkoutUrl;
|
|
1424
|
+
* ```
|
|
941
1425
|
*/
|
|
942
1426
|
createCheckoutSession(params: {
|
|
943
1427
|
agentRef: string;
|
|
@@ -949,7 +1433,24 @@ interface SolvaPay {
|
|
|
949
1433
|
checkoutUrl: string;
|
|
950
1434
|
}>;
|
|
951
1435
|
/**
|
|
952
|
-
* Create a customer session for
|
|
1436
|
+
* Create a customer portal session for managing subscriptions.
|
|
1437
|
+
*
|
|
1438
|
+
* This creates a Stripe Customer Portal session that allows customers
|
|
1439
|
+
* to manage their subscriptions, update payment methods, and view invoices.
|
|
1440
|
+
*
|
|
1441
|
+
* @param params - Customer session parameters
|
|
1442
|
+
* @param params.customerRef - Customer reference
|
|
1443
|
+
* @returns Customer portal session with redirect URL
|
|
1444
|
+
*
|
|
1445
|
+
* @example
|
|
1446
|
+
* ```typescript
|
|
1447
|
+
* const session = await solvaPay.createCustomerSession({
|
|
1448
|
+
* customerRef: 'user_123'
|
|
1449
|
+
* });
|
|
1450
|
+
*
|
|
1451
|
+
* // Redirect customer to portal
|
|
1452
|
+
* window.location.href = session.customerUrl;
|
|
1453
|
+
* ```
|
|
953
1454
|
*/
|
|
954
1455
|
createCustomerSession(params: {
|
|
955
1456
|
customerRef: string;
|
|
@@ -958,20 +1459,35 @@ interface SolvaPay {
|
|
|
958
1459
|
customerUrl: string;
|
|
959
1460
|
}>;
|
|
960
1461
|
/**
|
|
961
|
-
* Direct access to the API client for advanced operations
|
|
962
|
-
*
|
|
1462
|
+
* Direct access to the API client for advanced operations.
|
|
1463
|
+
*
|
|
1464
|
+
* Use this for operations not exposed by the SolvaPay interface,
|
|
1465
|
+
* such as agent/plan management or custom API calls.
|
|
1466
|
+
*
|
|
1467
|
+
* @example
|
|
1468
|
+
* ```typescript
|
|
1469
|
+
* // Access API client directly for custom operations
|
|
1470
|
+
* const agents = await solvaPay.apiClient.listAgents();
|
|
1471
|
+
* ```
|
|
963
1472
|
*/
|
|
964
1473
|
apiClient: SolvaPayClient;
|
|
965
1474
|
}
|
|
966
1475
|
/**
|
|
967
|
-
* Create a SolvaPay instance
|
|
1476
|
+
* Create a SolvaPay instance with paywall protection capabilities.
|
|
1477
|
+
*
|
|
1478
|
+
* This factory function creates a SolvaPay instance that can be used to
|
|
1479
|
+
* protect API endpoints, functions, and MCP tools with usage limits and
|
|
1480
|
+
* subscription checks.
|
|
968
1481
|
*
|
|
969
|
-
* @param config - Optional configuration
|
|
970
|
-
* @
|
|
1482
|
+
* @param config - Optional configuration object
|
|
1483
|
+
* @param config.apiKey - API key for production use (defaults to `SOLVAPAY_SECRET_KEY` env var)
|
|
1484
|
+
* @param config.apiClient - Custom API client for testing or advanced use cases
|
|
1485
|
+
* @param config.apiBaseUrl - Optional API base URL override
|
|
1486
|
+
* @returns SolvaPay instance with payable() method and API client access
|
|
971
1487
|
*
|
|
972
1488
|
* @example
|
|
973
1489
|
* ```typescript
|
|
974
|
-
* // Production:
|
|
1490
|
+
* // Production: Use environment variable (recommended)
|
|
975
1491
|
* const solvaPay = createSolvaPay();
|
|
976
1492
|
*
|
|
977
1493
|
* // Production: Pass API key explicitly
|
|
@@ -979,16 +1495,26 @@ interface SolvaPay {
|
|
|
979
1495
|
* apiKey: process.env.SOLVAPAY_SECRET_KEY
|
|
980
1496
|
* });
|
|
981
1497
|
*
|
|
982
|
-
* // Testing:
|
|
1498
|
+
* // Testing: Use mock client
|
|
983
1499
|
* const solvaPay = createSolvaPay({
|
|
984
1500
|
* apiClient: mockClient
|
|
985
1501
|
* });
|
|
986
1502
|
*
|
|
987
|
-
* // Create payable handlers
|
|
988
|
-
* const payable = solvaPay.payable({
|
|
989
|
-
*
|
|
990
|
-
*
|
|
1503
|
+
* // Create payable handlers for your agent
|
|
1504
|
+
* const payable = solvaPay.payable({
|
|
1505
|
+
* agent: 'agt_myapi',
|
|
1506
|
+
* plan: 'pln_premium'
|
|
1507
|
+
* });
|
|
1508
|
+
*
|
|
1509
|
+
* // Protect endpoints with framework-specific adapters
|
|
1510
|
+
* app.post('/tasks', payable.http(createTask)); // Express/Fastify
|
|
1511
|
+
* export const POST = payable.next(createTask); // Next.js App Router
|
|
1512
|
+
* const handler = payable.mcp(createTask); // MCP servers
|
|
991
1513
|
* ```
|
|
1514
|
+
*
|
|
1515
|
+
* @see {@link SolvaPay} for the returned instance interface
|
|
1516
|
+
* @see {@link CreateSolvaPayConfig} for configuration options
|
|
1517
|
+
* @since 1.0.0
|
|
992
1518
|
*/
|
|
993
1519
|
declare function createSolvaPay(config?: CreateSolvaPayConfig): SolvaPay;
|
|
994
1520
|
|
|
@@ -1001,8 +1527,48 @@ declare function createSolvaPay(config?: CreateSolvaPayConfig): SolvaPay;
|
|
|
1001
1527
|
* - Class-based and functional programming
|
|
1002
1528
|
*/
|
|
1003
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
|
+
*/
|
|
1004
1564
|
declare class PaywallError extends Error {
|
|
1005
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
|
+
*/
|
|
1006
1572
|
constructor(message: string, structuredContent: PaywallStructuredContent);
|
|
1007
1573
|
}
|
|
1008
1574
|
|
|
@@ -1011,19 +1577,28 @@ declare class PaywallError extends Error {
|
|
|
1011
1577
|
*/
|
|
1012
1578
|
|
|
1013
1579
|
/**
|
|
1014
|
-
*
|
|
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.
|
|
1015
1585
|
*
|
|
1016
1586
|
* @template T The return type of the async function
|
|
1017
1587
|
* @param fn The async function to execute
|
|
1018
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
|
|
1019
1594
|
* @returns A promise that resolves with the function result or rejects with the last error
|
|
1020
1595
|
*
|
|
1021
1596
|
* @example
|
|
1022
1597
|
* ```typescript
|
|
1023
|
-
* // Simple retry with defaults
|
|
1598
|
+
* // Simple retry with defaults (2 retries, 500ms delay)
|
|
1024
1599
|
* const result = await withRetry(() => apiCall());
|
|
1025
1600
|
*
|
|
1026
|
-
* // Custom retry with
|
|
1601
|
+
* // Custom retry with exponential backoff
|
|
1027
1602
|
* const result = await withRetry(
|
|
1028
1603
|
* () => apiCall(),
|
|
1029
1604
|
* {
|
|
@@ -1035,6 +1610,8 @@ declare class PaywallError extends Error {
|
|
|
1035
1610
|
* }
|
|
1036
1611
|
* );
|
|
1037
1612
|
* ```
|
|
1613
|
+
*
|
|
1614
|
+
* @since 1.0.0
|
|
1038
1615
|
*/
|
|
1039
1616
|
declare function withRetry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
|
|
1040
1617
|
|
|
@@ -1083,14 +1660,39 @@ declare function handleRouteError(error: unknown, operationName: string, default
|
|
|
1083
1660
|
*/
|
|
1084
1661
|
|
|
1085
1662
|
/**
|
|
1086
|
-
* Extract authenticated user information from
|
|
1663
|
+
* Extract authenticated user information from a standard Web API Request.
|
|
1087
1664
|
*
|
|
1088
|
-
* This is a generic
|
|
1089
|
-
*
|
|
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.).
|
|
1090
1668
|
*
|
|
1091
|
-
*
|
|
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
|
|
1092
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)
|
|
1093
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
|
|
1094
1696
|
*/
|
|
1095
1697
|
declare function getAuthenticatedUserCore(request: Request, options?: {
|
|
1096
1698
|
includeEmail?: boolean;
|
|
@@ -1105,13 +1707,41 @@ declare function getAuthenticatedUserCore(request: Request, options?: {
|
|
|
1105
1707
|
*/
|
|
1106
1708
|
|
|
1107
1709
|
/**
|
|
1108
|
-
* Sync customer
|
|
1710
|
+
* Sync customer with SolvaPay backend (ensure customer exists).
|
|
1109
1711
|
*
|
|
1110
|
-
*
|
|
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
|
|
1111
1716
|
*
|
|
1112
|
-
*
|
|
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
|
|
1113
1721
|
* @param options - Configuration options
|
|
1114
|
-
* @
|
|
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
|
|
1115
1745
|
*/
|
|
1116
1746
|
declare function syncCustomerCore(request: Request, options?: {
|
|
1117
1747
|
solvaPay?: SolvaPay;
|
|
@@ -1120,12 +1750,44 @@ declare function syncCustomerCore(request: Request, options?: {
|
|
|
1120
1750
|
}): Promise<string | ErrorResult>;
|
|
1121
1751
|
|
|
1122
1752
|
/**
|
|
1123
|
-
* Create payment intent
|
|
1753
|
+
* Create a Stripe payment intent for a customer to subscribe to a plan.
|
|
1124
1754
|
*
|
|
1125
|
-
*
|
|
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
|
|
1126
1764
|
* @param body - Payment intent parameters
|
|
1765
|
+
* @param body.planRef - Plan reference to subscribe to (required)
|
|
1766
|
+
* @param body.agentRef - Agent reference (required)
|
|
1127
1767
|
* @param options - Configuration options
|
|
1128
|
-
* @
|
|
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
|
|
1129
1791
|
*/
|
|
1130
1792
|
declare function createPaymentIntentCore(request: Request, body: {
|
|
1131
1793
|
planRef: string;
|
|
@@ -1142,12 +1804,45 @@ declare function createPaymentIntentCore(request: Request, body: {
|
|
|
1142
1804
|
customerRef: string;
|
|
1143
1805
|
} | ErrorResult>;
|
|
1144
1806
|
/**
|
|
1145
|
-
* Process payment -
|
|
1807
|
+
* Process a payment intent after client-side Stripe confirmation.
|
|
1146
1808
|
*
|
|
1147
|
-
*
|
|
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
|
|
1148
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)
|
|
1149
1820
|
* @param options - Configuration options
|
|
1150
|
-
* @
|
|
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
|
|
1151
1846
|
*/
|
|
1152
1847
|
declare function processPaymentCore(request: Request, body: {
|
|
1153
1848
|
paymentIntentId: string;
|
|
@@ -1269,7 +1964,7 @@ declare function listPlansCore(request: Request): Promise<{
|
|
|
1269
1964
|
* const event = await verifyWebhook({ body, signature, secret });
|
|
1270
1965
|
* ```
|
|
1271
1966
|
*/
|
|
1272
|
-
declare function verifyWebhook({ body, signature, secret }: {
|
|
1967
|
+
declare function verifyWebhook({ body, signature, secret, }: {
|
|
1273
1968
|
body: string;
|
|
1274
1969
|
signature: string;
|
|
1275
1970
|
secret: string;
|