@solvapay/server 1.0.0-preview.20 → 1.0.0-preview.21

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 CHANGED
@@ -64,8 +64,8 @@ const solvaPay = createSolvaPay({
64
64
  apiKey: process.env.SOLVAPAY_SECRET_KEY!
65
65
  });
66
66
 
67
- // Create a payable with your agent configuration
68
- const payable = solvaPay.payable({ agent: 'my-agent' });
67
+ // Create a payable with your product configuration
68
+ const payable = solvaPay.payable({ product: 'my-product' });
69
69
 
70
70
  // Use the appropriate adapter for your context:
71
71
 
@@ -109,7 +109,7 @@ const auth = new SupabaseAuthAdapter({
109
109
  const solvaPay = createSolvaPay({ apiKey: process.env.SOLVAPAY_SECRET_KEY! })
110
110
 
111
111
  // Use with Next.js adapter
112
- export const POST = solvaPay.payable({ agent: 'my-api' }).next(
112
+ export const POST = solvaPay.payable({ product: 'my-api' }).next(
113
113
  async args => {
114
114
  return { result: 'success' }
115
115
  },
@@ -124,6 +124,32 @@ export const POST = solvaPay.payable({ agent: 'my-api' }).next(
124
124
 
125
125
  This automatically extracts the user ID from authentication tokens and uses it as the customer reference for paywall checks.
126
126
 
127
+ For MCP bearer-token flows, the SDK also exports helper utilities:
128
+
129
+ ```ts
130
+ import {
131
+ getCustomerRefFromBearerAuthHeader,
132
+ McpBearerAuthError,
133
+ } from '@solvapay/server'
134
+
135
+ const handler = solvaPay.payable({ product: 'my-api' }).mcp(
136
+ async args => ({ ok: true }),
137
+ {
138
+ getCustomerRef: args => {
139
+ try {
140
+ return getCustomerRefFromBearerAuthHeader(args._authHeader as string | undefined)
141
+ } catch (error) {
142
+ if (error instanceof McpBearerAuthError) return 'anonymous'
143
+ throw error
144
+ }
145
+ },
146
+ },
147
+ )
148
+ ```
149
+
150
+ `payable({ getCustomerRef })` is now supported as a default extractor across adapters. Adapter-level
151
+ `getCustomerRef` still takes precedence when both are provided.
152
+
127
153
  ### When to Use Each Adapter
128
154
 
129
155
  Choose the adapter based on your context:
@@ -189,7 +215,7 @@ type Agent = components['schemas']['Agent']
189
215
  type Plan = components['schemas']['Plan']
190
216
  ```
191
217
 
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.
218
+ **Note:** The generated types complement the existing hand-written types in `src/types/client.ts`. Run `pnpm generate:types` whenever the backend API changes to keep types in sync.
193
219
 
194
220
  ## Testing
195
221
 
@@ -216,13 +242,13 @@ pnpm test:watch
216
242
 
217
243
  ### Unit Tests
218
244
 
219
- Unit tests (`__tests__/paywall.test.ts`) use a mock API client and test:
245
+ Unit tests (`__tests__/paywall.unit.test.ts`, `__tests__/mcp-auth.unit.test.ts`) use a mock API client and test:
220
246
 
221
247
  - Paywall protection logic
222
248
  - Handler creation (HTTP, Next.js, MCP)
223
249
  - Error handling
224
250
  - Authentication flows
225
- - Agent resolution
251
+ - Product resolution
226
252
 
227
253
  **No backend required** - runs fast and deterministically.
228
254