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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 SolvaPay Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -5,6 +5,7 @@ Universal server SDK for Node.js and edge runtimes. Includes API client, paywall
5
5
  **Works in**: Node.js, Vercel Edge Functions, Cloudflare Workers, Deno, Supabase Edge Functions, and more.
6
6
 
7
7
  ## Install
8
+
8
9
  ```bash
9
10
  pnpm add @solvapay/server
10
11
  ```
@@ -16,39 +17,39 @@ pnpm add @solvapay/server
16
17
  The same imports work in **Node.js and edge runtimes**. The correct implementation is automatically selected:
17
18
 
18
19
  ```ts
19
- import { createSolvaPayClient, verifyWebhook } from '@solvapay/server';
20
+ import { createSolvaPayClient, verifyWebhook } from '@solvapay/server'
20
21
 
21
22
  // Works in Node.js, Edge Functions, Cloudflare Workers, Deno, etc.
22
- const apiClient = createSolvaPayClient({
23
- apiKey: process.env.SOLVAPAY_SECRET_KEY!
24
- });
23
+ const apiClient = createSolvaPayClient({
24
+ apiKey: process.env.SOLVAPAY_SECRET_KEY!,
25
+ })
25
26
 
26
27
  // Auto-selects Node crypto or Web Crypto based on runtime
27
- const event = await verifyWebhook({
28
- body,
29
- signature,
30
- secret: process.env.SOLVAPAY_WEBHOOK_SECRET!
31
- });
28
+ const event = await verifyWebhook({
29
+ body,
30
+ signature,
31
+ secret: process.env.SOLVAPAY_WEBHOOK_SECRET!,
32
+ })
32
33
  ```
33
34
 
34
35
  **Edge Runtime Examples:**
35
36
 
36
37
  ```ts
37
38
  // Supabase Edge Function
38
- import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
39
- import { createSolvaPayClient, verifyWebhook } from 'https://esm.sh/@solvapay/server@latest';
39
+ import { serve } from 'https://deno.land/std@0.168.0/http/server.ts'
40
+ import { createSolvaPayClient, verifyWebhook } from 'https://esm.sh/@solvapay/server@latest'
40
41
 
41
42
  const solvapay = createSolvaPayClient({
42
43
  apiKey: Deno.env.get('SOLVAPAY_SECRET_KEY')!,
43
- });
44
+ })
44
45
 
45
46
  // Vercel Edge Function
46
- import { createSolvaPayClient } from '@solvapay/server';
47
+ import { createSolvaPayClient } from '@solvapay/server'
47
48
 
48
- export const runtime = 'edge';
49
+ export const runtime = 'edge'
49
50
  const solvapay = createSolvaPayClient({
50
51
  apiKey: process.env.SOLVAPAY_SECRET_KEY!,
51
- });
52
+ })
52
53
  ```
53
54
 
54
55
  ### Paywall Protection
@@ -59,8 +60,8 @@ Use the unified payable API to protect your endpoints and functions with usage l
59
60
  import { createSolvaPay } from '@solvapay/server';
60
61
 
61
62
  // Create SolvaPay instance with your API key
62
- const solvaPay = createSolvaPay({
63
- apiKey: process.env.SOLVAPAY_SECRET_KEY!
63
+ const solvaPay = createSolvaPay({
64
+ apiKey: process.env.SOLVAPAY_SECRET_KEY!
64
65
  });
65
66
 
66
67
  // Create a payable with your agent configuration
@@ -88,8 +89,8 @@ const protectedHandler = await payable.function(async (args) => {
88
89
  return { result: 'success' };
89
90
  });
90
91
 
91
- const result = await protectedHandler({
92
- auth: { customer_ref: 'customer_123' }
92
+ const result = await protectedHandler({
93
+ auth: { customer_ref: 'customer_123' }
93
94
  });
94
95
  ```
95
96
 
@@ -98,27 +99,27 @@ const result = await protectedHandler({
98
99
  You can integrate authentication adapters from `@solvapay/auth` with the `getCustomerRef` option:
99
100
 
100
101
  ```ts
101
- import { createSolvaPay } from '@solvapay/server';
102
- import { SupabaseAuthAdapter } from '@solvapay/auth/supabase';
102
+ import { createSolvaPay } from '@solvapay/server'
103
+ import { SupabaseAuthAdapter } from '@solvapay/auth/supabase'
103
104
 
104
105
  const auth = new SupabaseAuthAdapter({
105
- jwtSecret: process.env.SUPABASE_JWT_SECRET!
106
- });
106
+ jwtSecret: process.env.SUPABASE_JWT_SECRET!,
107
+ })
107
108
 
108
- const solvaPay = createSolvaPay({ apiKey: process.env.SOLVAPAY_SECRET_KEY! });
109
+ const solvaPay = createSolvaPay({ apiKey: process.env.SOLVAPAY_SECRET_KEY! })
109
110
 
110
111
  // Use with Next.js adapter
111
112
  export const POST = solvaPay.payable({ agent: 'my-api' }).next(
112
- async (args) => {
113
- return { result: 'success' };
113
+ async args => {
114
+ return { result: 'success' }
114
115
  },
115
116
  {
116
- getCustomerRef: async (req) => {
117
- const userId = await auth.getUserIdFromRequest(req);
118
- return userId ?? 'anonymous';
119
- }
120
- }
121
- );
117
+ getCustomerRef: async req => {
118
+ const userId = await auth.getUserIdFromRequest(req)
119
+ return userId ?? 'anonymous'
120
+ },
121
+ },
122
+ )
122
123
  ```
123
124
 
124
125
  This automatically extracts the user ID from authentication tokens and uses it as the customer reference for paywall checks.
@@ -175,15 +176,17 @@ This will fetch the OpenAPI spec from `http://localhost:3001/v1/openapi.json` an
175
176
  ### Using Generated Types
176
177
 
177
178
  ```typescript
178
- import type { paths, components } from './types/generated';
179
+ import type { paths, components } from './types/generated'
179
180
 
180
181
  // Use path operation types
181
- type CheckLimitsRequest = paths['/v1/sdk/limits']['post']['requestBody']['content']['application/json'];
182
- type CheckLimitsResponse = paths['/v1/sdk/limits']['post']['responses']['200']['content']['application/json'];
182
+ type CheckLimitsRequest =
183
+ paths['/v1/sdk/limits']['post']['requestBody']['content']['application/json']
184
+ type CheckLimitsResponse =
185
+ paths['/v1/sdk/limits']['post']['responses']['200']['content']['application/json']
183
186
 
184
187
  // Use component schemas
185
- type Agent = components['schemas']['Agent'];
186
- type Plan = components['schemas']['Plan'];
188
+ type Agent = components['schemas']['Agent']
189
+ type Plan = components['schemas']['Plan']
187
190
  ```
188
191
 
189
192
  **Note:** The generated types complement the existing hand-written types in `src/types.ts`. Run `pnpm generate:types` whenever the backend API changes to keep types in sync.
@@ -214,6 +217,7 @@ pnpm test:watch
214
217
  ### Unit Tests
215
218
 
216
219
  Unit tests (`__tests__/paywall.test.ts`) use a mock API client and test:
220
+
217
221
  - Paywall protection logic
218
222
  - Handler creation (HTTP, Next.js, MCP)
219
223
  - Error handling
@@ -225,6 +229,7 @@ Unit tests (`__tests__/paywall.test.ts`) use a mock API client and test:
225
229
  ### Integration Tests
226
230
 
227
231
  Integration tests (`__tests__/backend.integration.test.ts`) connect to a real SolvaPay backend and test:
232
+
228
233
  - SDK API methods with real responses
229
234
  - Actual limit enforcement
230
235
  - Real usage tracking
@@ -251,6 +256,7 @@ USE_REAL_BACKEND=true SOLVAPAY_SECRET_KEY=your_key pnpm test:integration
251
256
  ### Payment Integration Tests (Stripe)
252
257
 
253
258
  Payment tests (`__tests__/payment-stripe.integration.test.ts`) verify the complete payment flow with Stripe:
259
+
254
260
  - Creating payment intents
255
261
  - Confirming payments with test cards
256
262
  - Webhook processing (optional)
@@ -270,24 +276,27 @@ export SOLVAPAY_API_BASE_URL=http://localhost:3001
270
276
  The E2E webhook test is skipped by default because it requires Stripe webhooks to be forwarded to your local backend. To enable webhook testing:
271
277
 
272
278
  1. **Install Stripe CLI:**
279
+
273
280
  ```bash
274
281
  # macOS
275
282
  brew install stripe/stripe-cli/stripe
276
-
283
+
277
284
  # Linux / Windows - see https://stripe.com/docs/stripe-cli
278
285
  ```
279
286
 
280
287
  2. **Login to Stripe:**
288
+
281
289
  ```bash
282
290
  stripe login
283
291
  ```
284
292
 
285
293
  3. **Forward webhooks to your local backend:**
294
+
286
295
  ```bash
287
296
  # Terminal 1: Start your backend
288
297
  cd path/to/solvapay-backend
289
298
  pnpm dev
290
-
299
+
291
300
  # Terminal 2: Forward Stripe webhooks
292
301
  stripe listen --forward-to localhost:3001/webhooks/stripe
293
302
  ```
@@ -354,4 +363,4 @@ By default, both are **disabled** to keep test output clean and readable. Enable
354
363
  run: pnpm test:integration
355
364
  ```
356
365
 
357
- More: docs/architecture.md
366
+ More: [docs/guides/architecture.md](../../docs/guides/architecture.md)
@@ -0,0 +1,9 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ export {
8
+ __export
9
+ };