@solvapay/server 1.0.8-preview.8 → 1.0.8
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 +80 -2
- package/dist/edge.d.ts +495 -61
- package/dist/edge.js +648 -187
- package/dist/fetch/index.cjs +3071 -0
- package/dist/fetch/index.d.cts +112 -0
- package/dist/fetch/index.d.ts +112 -0
- package/dist/fetch/index.js +3017 -0
- package/dist/index.cjs +603 -5013
- package/dist/index.d.cts +490 -156
- package/dist/index.d.ts +490 -156
- package/dist/index.js +571 -695
- package/package.json +15 -12
- package/dist/chunk-MLKGABMK.js +0 -9
- package/dist/chunk-R5U7XKVJ.js +0 -16
- package/dist/dist-EPVKJAIP.js +0 -94
- package/dist/dist-JBJ4HMP7.js +0 -94
- package/dist/esm-5GYCIXIY.js +0 -3475
- package/dist/esm-UW7WCMEK.js +0 -3475
- package/dist/src/adapters/base.d.ts +0 -57
- package/dist/src/adapters/base.d.ts.map +0 -1
- package/dist/src/adapters/base.js +0 -73
- package/dist/src/adapters/base.js.map +0 -1
- package/dist/src/adapters/http.d.ts +0 -25
- package/dist/src/adapters/http.d.ts.map +0 -1
- package/dist/src/adapters/http.js +0 -99
- package/dist/src/adapters/http.js.map +0 -1
- package/dist/src/adapters/index.d.ts +0 -11
- package/dist/src/adapters/index.d.ts.map +0 -1
- package/dist/src/adapters/index.js +0 -10
- package/dist/src/adapters/index.js.map +0 -1
- package/dist/src/adapters/mcp.d.ts +0 -24
- package/dist/src/adapters/mcp.d.ts.map +0 -1
- package/dist/src/adapters/mcp.js +0 -75
- package/dist/src/adapters/mcp.js.map +0 -1
- package/dist/src/adapters/next.d.ts +0 -24
- package/dist/src/adapters/next.d.ts.map +0 -1
- package/dist/src/adapters/next.js +0 -109
- package/dist/src/adapters/next.js.map +0 -1
- package/dist/src/client.d.ts +0 -58
- package/dist/src/client.d.ts.map +0 -1
- package/dist/src/client.js +0 -495
- package/dist/src/client.js.map +0 -1
- package/dist/src/edge.d.ts +0 -22
- package/dist/src/edge.d.ts.map +0 -1
- package/dist/src/edge.js +0 -91
- package/dist/src/edge.js.map +0 -1
- package/dist/src/factory.d.ts +0 -605
- package/dist/src/factory.d.ts.map +0 -1
- package/dist/src/factory.js +0 -215
- package/dist/src/factory.js.map +0 -1
- package/dist/src/helpers/auth.d.ts +0 -47
- package/dist/src/helpers/auth.d.ts.map +0 -1
- package/dist/src/helpers/auth.js +0 -73
- package/dist/src/helpers/auth.js.map +0 -1
- package/dist/src/helpers/checkout.d.ts +0 -45
- package/dist/src/helpers/checkout.d.ts.map +0 -1
- package/dist/src/helpers/checkout.js +0 -89
- package/dist/src/helpers/checkout.js.map +0 -1
- package/dist/src/helpers/customer.d.ts +0 -51
- package/dist/src/helpers/customer.d.ts.map +0 -1
- package/dist/src/helpers/customer.js +0 -77
- package/dist/src/helpers/customer.js.map +0 -1
- package/dist/src/helpers/error.d.ts +0 -15
- package/dist/src/helpers/error.d.ts.map +0 -1
- package/dist/src/helpers/error.js +0 -35
- package/dist/src/helpers/error.js.map +0 -1
- package/dist/src/helpers/index.d.ts +0 -17
- package/dist/src/helpers/index.d.ts.map +0 -1
- package/dist/src/helpers/index.js +0 -23
- package/dist/src/helpers/index.js.map +0 -1
- package/dist/src/helpers/payment.d.ts +0 -107
- package/dist/src/helpers/payment.d.ts.map +0 -1
- package/dist/src/helpers/payment.js +0 -150
- package/dist/src/helpers/payment.js.map +0 -1
- package/dist/src/helpers/plans.d.ts +0 -19
- package/dist/src/helpers/plans.d.ts.map +0 -1
- package/dist/src/helpers/plans.js +0 -53
- package/dist/src/helpers/plans.js.map +0 -1
- package/dist/src/helpers/renewal.d.ts +0 -23
- package/dist/src/helpers/renewal.d.ts.map +0 -1
- package/dist/src/helpers/renewal.js +0 -90
- package/dist/src/helpers/renewal.js.map +0 -1
- package/dist/src/helpers/subscription.d.ts +0 -23
- package/dist/src/helpers/subscription.d.ts.map +0 -1
- package/dist/src/helpers/subscription.js +0 -101
- package/dist/src/helpers/subscription.js.map +0 -1
- package/dist/src/helpers/types.d.ts +0 -22
- package/dist/src/helpers/types.d.ts.map +0 -1
- package/dist/src/helpers/types.js +0 -7
- package/dist/src/helpers/types.js.map +0 -1
- package/dist/src/index.d.ts +0 -73
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -106
- package/dist/src/index.js.map +0 -1
- package/dist/src/mcp/auth-bridge.d.ts +0 -9
- package/dist/src/mcp/auth-bridge.d.ts.map +0 -1
- package/dist/src/mcp/auth-bridge.js +0 -46
- package/dist/src/mcp/auth-bridge.js.map +0 -1
- package/dist/src/mcp/oauth-bridge.d.ts +0 -48
- package/dist/src/mcp/oauth-bridge.d.ts.map +0 -1
- package/dist/src/mcp/oauth-bridge.js +0 -110
- package/dist/src/mcp/oauth-bridge.js.map +0 -1
- package/dist/src/mcp-auth.d.ts +0 -17
- package/dist/src/mcp-auth.d.ts.map +0 -1
- package/dist/src/mcp-auth.js +0 -57
- package/dist/src/mcp-auth.js.map +0 -1
- package/dist/src/paywall.d.ts +0 -119
- package/dist/src/paywall.d.ts.map +0 -1
- package/dist/src/paywall.js +0 -700
- package/dist/src/paywall.js.map +0 -1
- package/dist/src/register-virtual-tools-mcp.d.ts +0 -23
- package/dist/src/register-virtual-tools-mcp.d.ts.map +0 -1
- package/dist/src/register-virtual-tools-mcp.js +0 -86
- package/dist/src/register-virtual-tools-mcp.js.map +0 -1
- package/dist/src/types/client.d.ts +0 -216
- package/dist/src/types/client.d.ts.map +0 -1
- package/dist/src/types/client.js +0 -7
- package/dist/src/types/client.js.map +0 -1
- package/dist/src/types/generated.d.ts +0 -2834
- package/dist/src/types/generated.d.ts.map +0 -1
- package/dist/src/types/generated.js +0 -6
- package/dist/src/types/generated.js.map +0 -1
- package/dist/src/types/index.d.ts +0 -13
- package/dist/src/types/index.d.ts.map +0 -1
- package/dist/src/types/index.js +0 -8
- package/dist/src/types/index.js.map +0 -1
- package/dist/src/types/options.d.ts +0 -126
- package/dist/src/types/options.d.ts.map +0 -1
- package/dist/src/types/options.js +0 -8
- package/dist/src/types/options.js.map +0 -1
- package/dist/src/types/paywall.d.ts +0 -64
- package/dist/src/types/paywall.d.ts.map +0 -1
- package/dist/src/types/paywall.js +0 -7
- package/dist/src/types/paywall.js.map +0 -1
- package/dist/src/types/webhook.d.ts +0 -50
- package/dist/src/types/webhook.d.ts.map +0 -1
- package/dist/src/types/webhook.js +0 -2
- package/dist/src/types/webhook.js.map +0 -1
- package/dist/src/utils.d.ts +0 -110
- package/dist/src/utils.d.ts.map +0 -1
- package/dist/src/utils.js +0 -217
- package/dist/src/utils.js.map +0 -1
- package/dist/src/virtual-tools.d.ts +0 -44
- package/dist/src/virtual-tools.d.ts.map +0 -1
- package/dist/src/virtual-tools.js +0 -140
- package/dist/src/virtual-tools.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/webapi-K5XBCEO6.js +0 -3775
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base Adapter Interface
|
|
3
|
-
*
|
|
4
|
-
* Defines the contract for all framework adapters.
|
|
5
|
-
* Each adapter handles extraction, transformation, and formatting for its specific context.
|
|
6
|
-
*/
|
|
7
|
-
import type { SolvaPayPaywall } from '../paywall';
|
|
8
|
-
import type { PaywallMetadata } from '../types';
|
|
9
|
-
/**
|
|
10
|
-
* Base adapter interface that all framework adapters implement
|
|
11
|
-
*/
|
|
12
|
-
export interface Adapter<TContext = any, TResult = any> {
|
|
13
|
-
/**
|
|
14
|
-
* Extract plain arguments from the framework-specific context
|
|
15
|
-
*/
|
|
16
|
-
extractArgs(context: TContext): Promise<Record<string, unknown>> | Record<string, unknown>;
|
|
17
|
-
/**
|
|
18
|
-
* Extract customer reference from the context
|
|
19
|
-
*/
|
|
20
|
-
getCustomerRef(context: TContext, extra?: unknown): Promise<string> | string;
|
|
21
|
-
/**
|
|
22
|
-
* Format the business logic result for the framework
|
|
23
|
-
*/
|
|
24
|
-
formatResponse(result: unknown, context: TContext): TResult;
|
|
25
|
-
/**
|
|
26
|
-
* Format errors for the framework
|
|
27
|
-
*/
|
|
28
|
-
formatError(error: Error, context: TContext): TResult;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Shared utilities for adapters
|
|
32
|
-
*/
|
|
33
|
-
export declare class AdapterUtils {
|
|
34
|
-
/**
|
|
35
|
-
* Ensure customer reference is properly formatted
|
|
36
|
-
*/
|
|
37
|
-
static ensureCustomerRef(customerRef: string): string;
|
|
38
|
-
/**
|
|
39
|
-
* Extract customer ref from JWT token
|
|
40
|
-
*/
|
|
41
|
-
static extractFromJWT(token: string, options?: {
|
|
42
|
-
secret?: string;
|
|
43
|
-
issuer?: string;
|
|
44
|
-
audience?: string;
|
|
45
|
-
}): Promise<string | null>;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Create a protected handler using an adapter.
|
|
49
|
-
*
|
|
50
|
-
* The returned closure caches:
|
|
51
|
-
* - `backendRefCache`: resolved customer ref (input → cus_xxx) so ensureCustomer
|
|
52
|
-
* is only called once per distinct customer identity.
|
|
53
|
-
* - `protectedHandler`: the closure returned by paywall.protect() is created once
|
|
54
|
-
* and reused across invocations.
|
|
55
|
-
*/
|
|
56
|
-
export declare function createAdapterHandler<TContext, TResult>(adapter: Adapter<TContext, TResult>, paywall: SolvaPayPaywall, metadata: PaywallMetadata, businessLogic: (args: any) => Promise<any>): Promise<(context: TContext, extra?: unknown) => Promise<TResult>>;
|
|
57
|
-
//# sourceMappingURL=base.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/adapters/base.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,KAAK,EAAe,eAAe,EAAE,MAAM,UAAU,CAAA;AAE5D;;GAEG;AAEH,MAAM,WAAW,OAAO,CAAC,QAA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73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base Adapter Interface
|
|
3
|
-
*
|
|
4
|
-
* Defines the contract for all framework adapters.
|
|
5
|
-
* Each adapter handles extraction, transformation, and formatting for its specific context.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Shared utilities for adapters
|
|
9
|
-
*/
|
|
10
|
-
export class AdapterUtils {
|
|
11
|
-
/**
|
|
12
|
-
* Ensure customer reference is properly formatted
|
|
13
|
-
*/
|
|
14
|
-
static ensureCustomerRef(customerRef) {
|
|
15
|
-
if (!customerRef || customerRef === 'anonymous') {
|
|
16
|
-
return 'anonymous';
|
|
17
|
-
}
|
|
18
|
-
// Return customer ref as-is (preserve UUIDs with hyphens, etc.)
|
|
19
|
-
return customerRef;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Extract customer ref from JWT token
|
|
23
|
-
*/
|
|
24
|
-
static async extractFromJWT(token, options) {
|
|
25
|
-
try {
|
|
26
|
-
const { jwtVerify } = await import('jose');
|
|
27
|
-
const jwtSecret = new TextEncoder().encode(options?.secret || process.env.OAUTH_JWKS_SECRET || 'test-jwt-secret');
|
|
28
|
-
const { payload } = await jwtVerify(token, jwtSecret, {
|
|
29
|
-
issuer: options?.issuer || process.env.OAUTH_ISSUER || 'http://localhost:3000',
|
|
30
|
-
audience: options?.audience || process.env.OAUTH_CLIENT_ID || 'test-client-id',
|
|
31
|
-
});
|
|
32
|
-
return payload.sub || null;
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
// JWT verification failed, return null
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Create a protected handler using an adapter.
|
|
42
|
-
*
|
|
43
|
-
* The returned closure caches:
|
|
44
|
-
* - `backendRefCache`: resolved customer ref (input → cus_xxx) so ensureCustomer
|
|
45
|
-
* is only called once per distinct customer identity.
|
|
46
|
-
* - `protectedHandler`: the closure returned by paywall.protect() is created once
|
|
47
|
-
* and reused across invocations.
|
|
48
|
-
*/
|
|
49
|
-
export async function createAdapterHandler(adapter, paywall, metadata,
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
-
businessLogic) {
|
|
52
|
-
const backendRefCache = new Map();
|
|
53
|
-
const getCustomerRef = (args) => args.auth?.customer_ref || 'anonymous';
|
|
54
|
-
const protectedHandler = await paywall.protect(businessLogic, metadata, getCustomerRef);
|
|
55
|
-
return async (context, extra) => {
|
|
56
|
-
try {
|
|
57
|
-
const args = await adapter.extractArgs(context);
|
|
58
|
-
const customerRef = await adapter.getCustomerRef(context, extra);
|
|
59
|
-
let backendRef = backendRefCache.get(customerRef);
|
|
60
|
-
if (!backendRef) {
|
|
61
|
-
backendRef = await paywall.ensureCustomer(customerRef, customerRef);
|
|
62
|
-
backendRefCache.set(customerRef, backendRef);
|
|
63
|
-
}
|
|
64
|
-
args.auth = { customer_ref: backendRef };
|
|
65
|
-
const result = await protectedHandler(args);
|
|
66
|
-
return adapter.formatResponse(result, context);
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
return adapter.formatError(error, context);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
//# sourceMappingURL=base.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/adapters/base.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA+BH;;GAEG;AACH,MAAM,OAAO,YAAY;IACvB;;OAEG;IACH,MAAM,CAAC,iBAAiB,CAAC,WAAmB;QAC1C,IAAI,CAAC,WAAW,IAAI,WAAW,KAAK,WAAW,EAAE,CAAC;YAChD,OAAO,WAAW,CAAA;QACpB,CAAC;QAED,gEAAgE;QAChE,OAAO,WAAW,CAAA;IACpB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,cAAc,CACzB,KAAa,EACb,OAIC;Q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AAO,EAAE,KAAK,CAAC,CAAA;YAEhE,IAAI,UAAU,GAAG,eAAe,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;YACjD,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,UAAU,GAAG,MAAM,OAAO,CAAC,cAAc,CAAC,WAAW,EAAE,WAAW,CAAC,CAAA;gBACnE,eAAe,CAAC,GAAG,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;YAC9C,CAAC;YAED,IAAI,CAAC,IAAI,GAAG,EAAE,YAAY,EAAE,UAAU,EAAE,CAAA;YAExC,MAAM,MAAM,GAAG,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAA;YAC3C,OAAO,OAAO,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAChD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,OAAO,CAAC,WAAW,CAAC,KAAc,EAAE,OAAO,CAAC,CAAA;QACrD,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTTP Adapter for Express and Fastify
|
|
3
|
-
*
|
|
4
|
-
* Handles Express and Fastify HTTP frameworks with automatic detection
|
|
5
|
-
* of request/response patterns.
|
|
6
|
-
*/
|
|
7
|
-
import type { Adapter } from './base';
|
|
8
|
-
import type { HttpAdapterOptions } from '../types';
|
|
9
|
-
/**
|
|
10
|
-
* HTTP context (Express or Fastify)
|
|
11
|
-
*/
|
|
12
|
-
type HttpContext = [req: any, reply: any];
|
|
13
|
-
/**
|
|
14
|
-
* HTTP Adapter implementation
|
|
15
|
-
*/
|
|
16
|
-
export declare class HttpAdapter implements Adapter<HttpContext, unknown> {
|
|
17
|
-
private options;
|
|
18
|
-
constructor(options?: HttpAdapterOptions);
|
|
19
|
-
extractArgs([req, _reply]: HttpContext): Record<string, unknown>;
|
|
20
|
-
getCustomerRef([req, _reply]: HttpContext): Promise<string>;
|
|
21
|
-
formatResponse(result: unknown, [_req, reply]: HttpContext): unknown;
|
|
22
|
-
formatError(error: Error, [_req, reply]: HttpContext): unknown;
|
|
23
|
-
}
|
|
24
|
-
export {};
|
|
25
|
-
//# sourceMappingURL=http.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/adapters/http.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAErC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAGlD;;GAEG;AAEH,KAAK,WAAW,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,CAAA;AAEzC;;GAEG;AACH,qBAAa,WAAY,YAAW,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC;IACnD,OAAO,CAAC,OAAO;gBAAP,OAAO,GAAE,kBAAuB;IAEpD,WAAW,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAa1D,cAAc,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IA0BjE,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,OAAO;IAepE,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,OAAO;CAyC/D"}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTTP Adapter for Express and Fastify
|
|
3
|
-
*
|
|
4
|
-
* Handles Express and Fastify HTTP frameworks with automatic detection
|
|
5
|
-
* of request/response patterns.
|
|
6
|
-
*/
|
|
7
|
-
import { AdapterUtils } from './base';
|
|
8
|
-
import { PaywallError } from '../paywall';
|
|
9
|
-
/**
|
|
10
|
-
* HTTP Adapter implementation
|
|
11
|
-
*/
|
|
12
|
-
export class HttpAdapter {
|
|
13
|
-
options;
|
|
14
|
-
constructor(options = {}) {
|
|
15
|
-
this.options = options;
|
|
16
|
-
}
|
|
17
|
-
extractArgs([req, _reply]) {
|
|
18
|
-
if (this.options.extractArgs) {
|
|
19
|
-
return this.options.extractArgs(req);
|
|
20
|
-
}
|
|
21
|
-
// Default extraction from req.body, req.params, req.query
|
|
22
|
-
return {
|
|
23
|
-
...(req.body || {}),
|
|
24
|
-
...(req.params || {}),
|
|
25
|
-
...(req.query || {}),
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
async getCustomerRef([req, _reply]) {
|
|
29
|
-
if (this.options.getCustomerRef) {
|
|
30
|
-
const ref = await this.options.getCustomerRef(req);
|
|
31
|
-
return AdapterUtils.ensureCustomerRef(ref);
|
|
32
|
-
}
|
|
33
|
-
// Try x-customer-ref header first
|
|
34
|
-
const headerRef = req.headers?.['x-customer-ref'];
|
|
35
|
-
if (headerRef) {
|
|
36
|
-
return AdapterUtils.ensureCustomerRef(headerRef);
|
|
37
|
-
}
|
|
38
|
-
// Try JWT token if available
|
|
39
|
-
const authHeader = req.headers?.['authorization'];
|
|
40
|
-
if (authHeader && authHeader.startsWith('Bearer ')) {
|
|
41
|
-
const token = authHeader.substring(7);
|
|
42
|
-
const jwtSub = await AdapterUtils.extractFromJWT(token);
|
|
43
|
-
if (jwtSub) {
|
|
44
|
-
return AdapterUtils.ensureCustomerRef(jwtSub);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
// Fallback to anonymous
|
|
48
|
-
return 'anonymous';
|
|
49
|
-
}
|
|
50
|
-
formatResponse(result, [_req, reply]) {
|
|
51
|
-
if (this.options.transformResponse) {
|
|
52
|
-
return this.options.transformResponse(result, reply);
|
|
53
|
-
}
|
|
54
|
-
// Express: has reply.status method
|
|
55
|
-
if (reply && reply.status && typeof reply.json === 'function') {
|
|
56
|
-
reply.json(result);
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
// Fastify: return value for auto-serialization
|
|
60
|
-
return result;
|
|
61
|
-
}
|
|
62
|
-
formatError(error, [_req, reply]) {
|
|
63
|
-
if (error instanceof PaywallError) {
|
|
64
|
-
const errorResponse = {
|
|
65
|
-
success: false,
|
|
66
|
-
error: 'Payment required',
|
|
67
|
-
product: error.structuredContent.product,
|
|
68
|
-
checkoutUrl: error.structuredContent.checkoutUrl,
|
|
69
|
-
message: error.structuredContent.message,
|
|
70
|
-
};
|
|
71
|
-
// Express: has reply.status method
|
|
72
|
-
if (reply && reply.status && typeof reply.json === 'function') {
|
|
73
|
-
reply.status(402).json(errorResponse);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
// Fastify: use reply.code
|
|
77
|
-
if (reply && reply.code) {
|
|
78
|
-
reply.code(402);
|
|
79
|
-
}
|
|
80
|
-
return errorResponse;
|
|
81
|
-
}
|
|
82
|
-
// Generic error
|
|
83
|
-
const errorResponse = {
|
|
84
|
-
success: false,
|
|
85
|
-
error: error instanceof Error ? error.message : 'Internal server error',
|
|
86
|
-
};
|
|
87
|
-
// Express: has reply.status method
|
|
88
|
-
if (reply && reply.status && typeof reply.json === 'function') {
|
|
89
|
-
reply.status(500).json(errorResponse);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
// Fastify: use reply.code
|
|
93
|
-
if (reply && reply.code) {
|
|
94
|
-
reply.code(500);
|
|
95
|
-
}
|
|
96
|
-
return errorResponse;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
//# sourceMappingURL=http.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/adapters/http.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAErC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,C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K,CAAC,IAAI,EAAE,CAAC;gBACxB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YACjB,CAAC;YACD,OAAO,aAAa,CAAA;QACtB,CAAC;QAED,gBAAgB;QAChB,MAAM,aAAa,GAAG;YACpB,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,uBAAuB;SACxE,CAAA;QAED,mCAAmC;QACnC,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAC9D,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;YACrC,OAAM;QACR,CAAC;QAED,0BAA0B;QAC1B,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;YACxB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACjB,CAAC;QACD,OAAO,aAAa,CAAA;IACtB,CAAC;CACF"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adapters Export
|
|
3
|
-
*
|
|
4
|
-
* Exports all framework adapters and utilities
|
|
5
|
-
*/
|
|
6
|
-
export type { Adapter } from './base';
|
|
7
|
-
export { AdapterUtils, createAdapterHandler } from './base';
|
|
8
|
-
export { HttpAdapter } from './http';
|
|
9
|
-
export { NextAdapter } from './next';
|
|
10
|
-
export { McpAdapter } from './mcp';
|
|
11
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adapters Export
|
|
3
|
-
*
|
|
4
|
-
* Exports all framework adapters and utilities
|
|
5
|
-
*/
|
|
6
|
-
export { AdapterUtils, createAdapterHandler } from './base';
|
|
7
|
-
export { HttpAdapter } from './http';
|
|
8
|
-
export { NextAdapter } from './next';
|
|
9
|
-
export { McpAdapter } from './mcp';
|
|
10
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP Adapter for Model Context Protocol servers
|
|
3
|
-
*
|
|
4
|
-
* Handles MCP tool format with content wrapping
|
|
5
|
-
*/
|
|
6
|
-
import type { Adapter } from './base';
|
|
7
|
-
import type { McpAdapterOptions, McpToolExtra, PaywallToolResult } from '../types';
|
|
8
|
-
/**
|
|
9
|
-
* MCP context (plain args object)
|
|
10
|
-
*/
|
|
11
|
-
type McpContext = Record<string, unknown>;
|
|
12
|
-
/**
|
|
13
|
-
* MCP Adapter implementation
|
|
14
|
-
*/
|
|
15
|
-
export declare class McpAdapter implements Adapter<McpContext, PaywallToolResult> {
|
|
16
|
-
private options;
|
|
17
|
-
constructor(options?: McpAdapterOptions);
|
|
18
|
-
extractArgs(args: McpContext): Record<string, unknown>;
|
|
19
|
-
getCustomerRef(args: McpContext, extra?: McpToolExtra): Promise<string>;
|
|
20
|
-
formatResponse(result: unknown, _context: McpContext): PaywallToolResult;
|
|
21
|
-
formatError(error: Error, _context: McpContext): PaywallToolResult;
|
|
22
|
-
}
|
|
23
|
-
export {};
|
|
24
|
-
//# sourceMappingURL=mcp.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../../src/adapters/mcp.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAErC,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAGlF;;GAEG;AACH,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEzC;;GAEG;AACH,qBAAa,UAAW,YAAW,OAAO,CAAC,UAAU,EAAE,iBAAiB,CAAC;IAC3D,OAAO,CAAC,OAAO;gBAAP,OAAO,GAAE,iBAAsB;IAEnD,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAKhD,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;IAc7E,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,GAAG,iBAAiB;IAqBxE,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,GAAG,iBAAiB;CA+BnE"}
|
package/dist/src/adapters/mcp.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP Adapter for Model Context Protocol servers
|
|
3
|
-
*
|
|
4
|
-
* Handles MCP tool format with content wrapping
|
|
5
|
-
*/
|
|
6
|
-
import { AdapterUtils } from './base';
|
|
7
|
-
import { PaywallError, paywallErrorToClientPayload } from '../paywall';
|
|
8
|
-
/**
|
|
9
|
-
* MCP Adapter implementation
|
|
10
|
-
*/
|
|
11
|
-
export class McpAdapter {
|
|
12
|
-
options;
|
|
13
|
-
constructor(options = {}) {
|
|
14
|
-
this.options = options;
|
|
15
|
-
}
|
|
16
|
-
extractArgs(args) {
|
|
17
|
-
// MCP args are already plain objects, pass through
|
|
18
|
-
return args;
|
|
19
|
-
}
|
|
20
|
-
async getCustomerRef(args, extra) {
|
|
21
|
-
if (this.options.getCustomerRef) {
|
|
22
|
-
const ref = await this.options.getCustomerRef(args, extra);
|
|
23
|
-
return AdapterUtils.ensureCustomerRef(ref);
|
|
24
|
-
}
|
|
25
|
-
const customerRefFromExtra = extra?.authInfo?.extra?.customer_ref;
|
|
26
|
-
const customerRef = typeof customerRefFromExtra === 'string' && customerRefFromExtra.trim()
|
|
27
|
-
? customerRefFromExtra.trim()
|
|
28
|
-
: 'anonymous';
|
|
29
|
-
return AdapterUtils.ensureCustomerRef(customerRef);
|
|
30
|
-
}
|
|
31
|
-
formatResponse(result, _context) {
|
|
32
|
-
const transformed = this.options.transformResponse
|
|
33
|
-
? this.options.transformResponse(result)
|
|
34
|
-
: result;
|
|
35
|
-
const response = {
|
|
36
|
-
content: [
|
|
37
|
-
{
|
|
38
|
-
type: 'text',
|
|
39
|
-
text: JSON.stringify(transformed, null, 2),
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
};
|
|
43
|
-
if (transformed && typeof transformed === 'object' && !Array.isArray(transformed)) {
|
|
44
|
-
response.structuredContent = transformed;
|
|
45
|
-
}
|
|
46
|
-
return response;
|
|
47
|
-
}
|
|
48
|
-
formatError(error, _context) {
|
|
49
|
-
if (error instanceof PaywallError) {
|
|
50
|
-
return {
|
|
51
|
-
content: [
|
|
52
|
-
{
|
|
53
|
-
type: 'text',
|
|
54
|
-
text: JSON.stringify(paywallErrorToClientPayload(error), null, 2),
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
isError: true,
|
|
58
|
-
structuredContent: error.structuredContent,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
content: [
|
|
63
|
-
{
|
|
64
|
-
type: 'text',
|
|
65
|
-
text: JSON.stringify({
|
|
66
|
-
success: false,
|
|
67
|
-
error: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
68
|
-
}, null, 2),
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
isError: true,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
//# sourceMappingURL=mcp.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../../src/adapters/mcp.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAErC,OAAO,EAAE,YAAY,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAOtE;;GAEG;AACH,MAAM,OAAO,UAAU;IACD;IAApB,YAAoB,UAA6B,EAAE;QAA/B,YAAO,GAAP,OAAO,CAAwB;IAAG,CAAC;IAEvD,WAAW,CAAC,IAAgB;QAC1B,mDAAmD;QACnD,OAAO,IAAI,CAAA;IACb,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,IAAgB,EAAE,KAAoB;QACzD,IAAI,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;YAChC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;YAC1D,OAAO,YAAY,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAA;QAC5C,CAAC;QAED,MAAM,oBAAoB,GAAG,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,CAAA;QACjE,MAAM,WAAW,GACf,OAAO,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KAAK;wBACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,wBAAwB;qBACzE,EACD,IAAI,EACJ,CAAC,CACF;iBACF;aACF;YACD,OAAO,EAAE,IAAI;SACd,CAAA;IACH,CAAC;CACF"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Next.js Adapter for App Router
|
|
3
|
-
*
|
|
4
|
-
* Handles Next.js App Router with Web Request/Response API
|
|
5
|
-
*/
|
|
6
|
-
import type { Adapter } from './base';
|
|
7
|
-
import type { NextAdapterOptions } from '../types';
|
|
8
|
-
/**
|
|
9
|
-
* Next.js context (Web Request + optional route context)
|
|
10
|
-
*/
|
|
11
|
-
type NextContext = [request: Request, context?: any];
|
|
12
|
-
/**
|
|
13
|
-
* Next.js Adapter implementation
|
|
14
|
-
*/
|
|
15
|
-
export declare class NextAdapter implements Adapter<NextContext, Response> {
|
|
16
|
-
private options;
|
|
17
|
-
constructor(options?: NextAdapterOptions);
|
|
18
|
-
extractArgs([request, context]: NextContext): Promise<Record<string, unknown>>;
|
|
19
|
-
getCustomerRef([request]: NextContext): Promise<string>;
|
|
20
|
-
formatResponse(result: unknown, _context: NextContext): Response;
|
|
21
|
-
formatError(error: Error, _context: NextContext): Response;
|
|
22
|
-
}
|
|
23
|
-
export {};
|
|
24
|
-
//# sourceMappingURL=next.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../../../src/adapters/next.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAErC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAGlD;;GAEG;AAEH,KAAK,WAAW,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,CAAA;AAEpD;;GAEG;AACH,qBAAa,WAAY,YAAW,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC;IACpD,OAAO,CAAC,OAAO;gBAAP,OAAO,GAAE,kBAAuB;IAE9C,WAAW,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAwC9E,cAAc,CAAC,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IAgC7D,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,GAAG,QAAQ;IAWhE,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,GAAG,QAAQ;CA4B3D"}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Next.js Adapter for App Router
|
|
3
|
-
*
|
|
4
|
-
* Handles Next.js App Router with Web Request/Response API
|
|
5
|
-
*/
|
|
6
|
-
import { AdapterUtils } from './base';
|
|
7
|
-
import { PaywallError } from '../paywall';
|
|
8
|
-
/**
|
|
9
|
-
* Next.js Adapter implementation
|
|
10
|
-
*/
|
|
11
|
-
export class NextAdapter {
|
|
12
|
-
options;
|
|
13
|
-
constructor(options = {}) {
|
|
14
|
-
this.options = options;
|
|
15
|
-
}
|
|
16
|
-
async extractArgs([request, context]) {
|
|
17
|
-
if (this.options.extractArgs) {
|
|
18
|
-
return await this.options.extractArgs(request, context);
|
|
19
|
-
}
|
|
20
|
-
// Default extraction from URL, body, and route params
|
|
21
|
-
const url = new URL(request.url);
|
|
22
|
-
const query = Object.fromEntries(url.searchParams.entries());
|
|
23
|
-
// Parse request body if present
|
|
24
|
-
let body = {};
|
|
25
|
-
try {
|
|
26
|
-
if (request.method !== 'GET' &&
|
|
27
|
-
request.headers.get('content-type')?.includes('application/json')) {
|
|
28
|
-
body = await request.json();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
// If parsing fails, continue with empty body
|
|
33
|
-
}
|
|
34
|
-
// Handle route parameters if provided
|
|
35
|
-
let routeParams = {};
|
|
36
|
-
if (context?.params) {
|
|
37
|
-
if (typeof context.params === 'object' && 'then' in context.params) {
|
|
38
|
-
// Handle Promise<params> case (Next.js 15+ app router)
|
|
39
|
-
routeParams = await context.params;
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
routeParams = context.params;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return {
|
|
46
|
-
...body,
|
|
47
|
-
...query,
|
|
48
|
-
...routeParams,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
async getCustomerRef([request]) {
|
|
52
|
-
if (this.options.getCustomerRef) {
|
|
53
|
-
const ref = await this.options.getCustomerRef(request);
|
|
54
|
-
return AdapterUtils.ensureCustomerRef(ref);
|
|
55
|
-
}
|
|
56
|
-
// Try to get from JWT token first
|
|
57
|
-
const authHeader = request.headers.get('authorization');
|
|
58
|
-
if (authHeader && authHeader.startsWith('Bearer ')) {
|
|
59
|
-
const token = authHeader.substring(7);
|
|
60
|
-
const jwtSub = await AdapterUtils.extractFromJWT(token);
|
|
61
|
-
if (jwtSub) {
|
|
62
|
-
return AdapterUtils.ensureCustomerRef(jwtSub);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
// Try x-user-id header (set by middleware, e.g., Supabase auth)
|
|
66
|
-
const userId = request.headers.get('x-user-id');
|
|
67
|
-
if (userId) {
|
|
68
|
-
return AdapterUtils.ensureCustomerRef(userId);
|
|
69
|
-
}
|
|
70
|
-
// Fallback to x-customer-ref header
|
|
71
|
-
const headerRef = request.headers.get('x-customer-ref');
|
|
72
|
-
if (headerRef) {
|
|
73
|
-
return AdapterUtils.ensureCustomerRef(headerRef);
|
|
74
|
-
}
|
|
75
|
-
// Default to demo_user for Next.js (common in examples)
|
|
76
|
-
return 'demo_user';
|
|
77
|
-
}
|
|
78
|
-
formatResponse(result, _context) {
|
|
79
|
-
const transformed = this.options.transformResponse
|
|
80
|
-
? this.options.transformResponse(result)
|
|
81
|
-
: result;
|
|
82
|
-
return new Response(JSON.stringify(transformed), {
|
|
83
|
-
status: 200,
|
|
84
|
-
headers: { 'Content-Type': 'application/json' },
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
formatError(error, _context) {
|
|
88
|
-
if (error instanceof PaywallError) {
|
|
89
|
-
return new Response(JSON.stringify({
|
|
90
|
-
success: false,
|
|
91
|
-
error: 'Payment required',
|
|
92
|
-
product: error.structuredContent.product,
|
|
93
|
-
checkoutUrl: error.structuredContent.checkoutUrl,
|
|
94
|
-
message: error.structuredContent.message,
|
|
95
|
-
}), {
|
|
96
|
-
status: 402,
|
|
97
|
-
headers: { 'Content-Type': 'application/json' },
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
return new Response(JSON.stringify({
|
|
101
|
-
success: false,
|
|
102
|
-
error: error instanceof Error ? error.message : 'Internal server error',
|
|
103
|
-
}), {
|
|
104
|
-
status: 500,
|
|
105
|
-
headers: { 'Content-Type': 'application/json' },
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
//# sourceMappingURL=next.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"next.js","sourceRoot":"","sources":["../../../src/adapters/next.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAErC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAQzC;;GAEG;AACH,MAAM,OAAO,WAAW;IACF;IAApB,YAAoB,UAA8B,EAAE;QAAhC,YAAO,GAAP,OAAO,CAAyB;IAAG,CAAC;IAExD,KAAK,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,OAAO,CAAc;QAC/C,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;YAC7B,OAAO,MAAM,I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CAAC,CAAA;IACJ,CAAC;IAED,WAAW,CAAC,KAAY,EAAE,QAAqB;QAC7C,IAAI,KAAK,YAAY,YAAY,EAAE,CAAC;YAClC,OAAO,IAAI,QAAQ,CACjB,IAAI,CAAC,SAAS,CAAC;gBACb,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,kBAAkB;gBACzB,OAAO,EAAE,KAAK,CAAC,iBAAiB,CAAC,OAAO;gBACxC,WAAW,EAAE,KAAK,CAAC,iBAAiB,CAAC,WAAW;gBAChD,OAAO,EAAE,KAAK,CAAC,iBAAiB,CAAC,OAAO;aACzC,CAAC,EACF;gBACE,MAAM,EAAE,GAAG;gBACX,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;aAChD,CACF,CAAA;QACH,CAAC;QAED,OAAO,IAAI,QAAQ,CACjB,IAAI,CAAC,SAAS,CAAC;YACb,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,uBAAuB;SACxE,CAAC,EACF;YACE,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;SAChD,CACF,CAAA;IACH,CAAC;CACF"}
|
package/dist/src/client.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SolvaPay Server SDK - API Client
|
|
3
|
-
*
|
|
4
|
-
* This module provides the API client implementation for communicating with
|
|
5
|
-
* the SolvaPay backend. The client handles all HTTP requests for paywall
|
|
6
|
-
* protection, usage tracking, and resource management.
|
|
7
|
-
*/
|
|
8
|
-
import type { SolvaPayClient } from './types';
|
|
9
|
-
/**
|
|
10
|
-
* Configuration options for creating a SolvaPay API client
|
|
11
|
-
*/
|
|
12
|
-
export type ServerClientOptions = {
|
|
13
|
-
/**
|
|
14
|
-
* Your SolvaPay API key (required)
|
|
15
|
-
*/
|
|
16
|
-
apiKey: string;
|
|
17
|
-
/**
|
|
18
|
-
* Base URL for the SolvaPay API (optional)
|
|
19
|
-
* Defaults to https://api.solvapay.com
|
|
20
|
-
*/
|
|
21
|
-
apiBaseUrl?: string;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Creates a SolvaPay API client that implements the full SolvaPayClient interface.
|
|
25
|
-
*
|
|
26
|
-
* This function creates a low-level API client for direct communication with the
|
|
27
|
-
* SolvaPay backend. For most use cases, use `createSolvaPay()` instead, which
|
|
28
|
-
* provides a higher-level API with paywall protection.
|
|
29
|
-
*
|
|
30
|
-
* Use this function when you need:
|
|
31
|
-
* - Direct API access for custom operations
|
|
32
|
-
* - Testing with custom client implementations
|
|
33
|
-
* - Advanced use cases not covered by the main API
|
|
34
|
-
*
|
|
35
|
-
* @param opts - Configuration options
|
|
36
|
-
* @param opts.apiKey - Your SolvaPay API key (required)
|
|
37
|
-
* @param opts.apiBaseUrl - Optional API base URL override
|
|
38
|
-
* @returns A fully configured SolvaPayClient instance
|
|
39
|
-
* @throws {SolvaPayError} If API key is missing
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```typescript
|
|
43
|
-
* // Create API client directly
|
|
44
|
-
* const client = createSolvaPayClient({
|
|
45
|
-
* apiKey: process.env.SOLVAPAY_SECRET_KEY!,
|
|
46
|
-
* apiBaseUrl: 'https://api.solvapay.com' // optional
|
|
47
|
-
* });
|
|
48
|
-
*
|
|
49
|
-
* // Use client for custom operations
|
|
50
|
-
* const products = await client.listProducts();
|
|
51
|
-
* ```
|
|
52
|
-
*
|
|
53
|
-
* @see {@link createSolvaPay} for the recommended high-level API
|
|
54
|
-
* @see {@link ServerClientOptions} for configuration options
|
|
55
|
-
* @since 1.0.0
|
|
56
|
-
*/
|
|
57
|
-
export declare function createSolvaPayClient(opts: ServerClientOptions): SolvaPayClient;
|
|
58
|
-
//# sourceMappingURL=client.d.ts.map
|
package/dist/src/client.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,mBAAmB,GAAG,cAAc,CA0iB9E"}
|