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