@puga-labs/x402-mantle-sdk 0.3.3 → 0.3.5
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/dist/chunk-IT6VV6YL.js +73 -0
- package/dist/nextjs-BgyAWzT3.d.ts +82 -0
- package/dist/nextjs-CGOVHJXl.d.cts +89 -0
- package/dist/nextjs-CY13JXkV.d.cts +82 -0
- package/dist/nextjs-w61gRvpz.d.ts +89 -0
- package/dist/server-nextjs.cjs +5 -0
- package/dist/server-nextjs.d.cts +1 -1
- package/dist/server-nextjs.d.ts +1 -1
- package/dist/server-nextjs.js +3 -1
- package/dist/server.cjs +4 -0
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildRouteKey,
|
|
3
|
+
checkPayment,
|
|
4
|
+
validateAddress
|
|
5
|
+
} from "./chunk-ZLCKBFVJ.js";
|
|
6
|
+
import {
|
|
7
|
+
MANTLE_DEFAULTS,
|
|
8
|
+
__export,
|
|
9
|
+
getDefaultAssetForNetwork,
|
|
10
|
+
usdCentsToAtomic
|
|
11
|
+
} from "./chunk-HEZZ74SI.js";
|
|
12
|
+
|
|
13
|
+
// src/server/adapters/nextjs.ts
|
|
14
|
+
var nextjs_exports = {};
|
|
15
|
+
__export(nextjs_exports, {
|
|
16
|
+
isPaywallErrorResponse: () => isPaywallErrorResponse,
|
|
17
|
+
mantlePaywall: () => mantlePaywall
|
|
18
|
+
});
|
|
19
|
+
import { NextResponse } from "next/server";
|
|
20
|
+
function mantlePaywall(opts) {
|
|
21
|
+
const { priceUsd, payTo, facilitatorUrl, telemetry, onPaymentSettled } = opts;
|
|
22
|
+
validateAddress(payTo, "payTo");
|
|
23
|
+
const priceUsdCents = Math.round(priceUsd * 100);
|
|
24
|
+
return function(handler) {
|
|
25
|
+
return async (req) => {
|
|
26
|
+
const url = new URL(req.url);
|
|
27
|
+
const method = req.method;
|
|
28
|
+
const path = url.pathname;
|
|
29
|
+
const routeKey = buildRouteKey(method, path);
|
|
30
|
+
const network = MANTLE_DEFAULTS.NETWORK;
|
|
31
|
+
const assetConfig = getDefaultAssetForNetwork(network);
|
|
32
|
+
const maxAmountRequiredBigInt = usdCentsToAtomic(
|
|
33
|
+
priceUsdCents,
|
|
34
|
+
assetConfig.decimals
|
|
35
|
+
);
|
|
36
|
+
const paymentRequirements = {
|
|
37
|
+
scheme: "exact",
|
|
38
|
+
network,
|
|
39
|
+
asset: assetConfig.address,
|
|
40
|
+
maxAmountRequired: maxAmountRequiredBigInt.toString(),
|
|
41
|
+
payTo,
|
|
42
|
+
price: `$${(priceUsdCents / 100).toFixed(2)}`,
|
|
43
|
+
currency: "USD"
|
|
44
|
+
};
|
|
45
|
+
const paymentHeader = req.headers.get("X-PAYMENT") || req.headers.get("x-payment") || null;
|
|
46
|
+
const result = await checkPayment({
|
|
47
|
+
paymentHeader,
|
|
48
|
+
paymentRequirements,
|
|
49
|
+
facilitatorUrl: facilitatorUrl || MANTLE_DEFAULTS.FACILITATOR_URL,
|
|
50
|
+
routeKey,
|
|
51
|
+
network,
|
|
52
|
+
asset: assetConfig.address,
|
|
53
|
+
telemetry,
|
|
54
|
+
onPaymentSettled
|
|
55
|
+
});
|
|
56
|
+
if (!result.isValid) {
|
|
57
|
+
return NextResponse.json(result.responseBody, {
|
|
58
|
+
status: result.statusCode
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return handler(req);
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function isPaywallErrorResponse(response) {
|
|
66
|
+
return typeof response === "object" && response !== null && "error" in response && typeof response.error === "string";
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export {
|
|
70
|
+
mantlePaywall,
|
|
71
|
+
isPaywallErrorResponse,
|
|
72
|
+
nextjs_exports
|
|
73
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { M as MinimalPaywallOptions } from './types-CqQ6OgRi.js';
|
|
3
|
+
import { P as PaymentRequirements } from './types-BFUqKBBO.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Error response returned when payment verification fails.
|
|
7
|
+
* This can be due to missing payment, invalid payment, or verification errors.
|
|
8
|
+
*/
|
|
9
|
+
interface PaywallErrorResponse {
|
|
10
|
+
error: string;
|
|
11
|
+
paymentRequirements?: PaymentRequirements;
|
|
12
|
+
paymentHeader?: null;
|
|
13
|
+
invalidReason?: string | null;
|
|
14
|
+
details?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Next.js App Router route handler type.
|
|
18
|
+
*/
|
|
19
|
+
type NextJSHandler<T = any> = (req: NextRequest) => Promise<NextResponse<T>>;
|
|
20
|
+
/**
|
|
21
|
+
* Wrapper function that adds x402 payment verification to Next.js route handler.
|
|
22
|
+
* Returns a handler that may return either the original handler's response type (T)
|
|
23
|
+
* or a PaywallErrorResponse if payment verification fails.
|
|
24
|
+
*/
|
|
25
|
+
type NextJSPaywallWrapper = <T>(handler: NextJSHandler<T>) => NextJSHandler<T | PaywallErrorResponse>;
|
|
26
|
+
/**
|
|
27
|
+
* Create Next.js App Router middleware for x402 payment verification.
|
|
28
|
+
* Uses Mantle mainnet defaults (USDC, exact scheme, etc.).
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* // app/api/generate-image/route.ts
|
|
33
|
+
* import { mantlePaywall } from '@puga-labs/x402-mantle-sdk/server/nextjs'
|
|
34
|
+
*
|
|
35
|
+
* const pay = mantlePaywall({
|
|
36
|
+
* priceUsd: 0.01,
|
|
37
|
+
* payTo: process.env.PAY_TO!,
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // No 'as any' needed! TypeScript correctly infers the union type
|
|
41
|
+
* export const POST = pay(async (req: NextRequest) => {
|
|
42
|
+
* const { prompt } = await req.json();
|
|
43
|
+
* // Your handler code here
|
|
44
|
+
* return NextResponse.json({ success: true, imageUrl: "..." });
|
|
45
|
+
* });
|
|
46
|
+
* // TypeScript knows POST returns: NextResponse<{ success: boolean; imageUrl: string } | PaywallErrorResponse>
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @param opts - Minimal configuration (price, payTo, optional facilitator/telemetry).
|
|
50
|
+
* @returns Function that wraps Next.js route handlers with payment verification.
|
|
51
|
+
*/
|
|
52
|
+
declare function mantlePaywall(opts: MinimalPaywallOptions): NextJSPaywallWrapper;
|
|
53
|
+
/**
|
|
54
|
+
* Type guard to check if a response is a paywall error response.
|
|
55
|
+
* Useful for handling the union type returned by the paywall wrapper.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const response = await fetch('/api/protected');
|
|
60
|
+
* const data = await response.json();
|
|
61
|
+
*
|
|
62
|
+
* if (isPaywallErrorResponse(data)) {
|
|
63
|
+
* // Handle error: data.error, data.paymentRequirements, etc.
|
|
64
|
+
* console.error('Payment required:', data.paymentRequirements);
|
|
65
|
+
* } else {
|
|
66
|
+
* // Handle success: data has type T
|
|
67
|
+
* console.log('Success:', data);
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
declare function isPaywallErrorResponse(response: unknown): response is PaywallErrorResponse;
|
|
72
|
+
|
|
73
|
+
type nextjs_NextJSHandler<T = any> = NextJSHandler<T>;
|
|
74
|
+
type nextjs_NextJSPaywallWrapper = NextJSPaywallWrapper;
|
|
75
|
+
type nextjs_PaywallErrorResponse = PaywallErrorResponse;
|
|
76
|
+
declare const nextjs_isPaywallErrorResponse: typeof isPaywallErrorResponse;
|
|
77
|
+
declare const nextjs_mantlePaywall: typeof mantlePaywall;
|
|
78
|
+
declare namespace nextjs {
|
|
79
|
+
export { type nextjs_NextJSHandler as NextJSHandler, type nextjs_NextJSPaywallWrapper as NextJSPaywallWrapper, type nextjs_PaywallErrorResponse as PaywallErrorResponse, nextjs_isPaywallErrorResponse as isPaywallErrorResponse, nextjs_mantlePaywall as mantlePaywall };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { type NextJSHandler as N, type PaywallErrorResponse as P, type NextJSPaywallWrapper as a, isPaywallErrorResponse as i, mantlePaywall as m, nextjs as n };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { NextRequest } from 'next/server';
|
|
2
|
+
import { M as MinimalPaywallOptions } from './types-CrOsOHcX.cjs';
|
|
3
|
+
import { P as PaymentRequirements } from './types-BFUqKBBO.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Error response returned when payment verification fails.
|
|
7
|
+
* This can be due to missing payment, invalid payment, or verification errors.
|
|
8
|
+
*/
|
|
9
|
+
interface PaywallErrorResponse {
|
|
10
|
+
error: string;
|
|
11
|
+
paymentRequirements?: PaymentRequirements;
|
|
12
|
+
paymentHeader?: null;
|
|
13
|
+
invalidReason?: string | null;
|
|
14
|
+
details?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Simple promise-or-value helper.
|
|
18
|
+
*/
|
|
19
|
+
type Awaitable<T> = T | Promise<T>;
|
|
20
|
+
/**
|
|
21
|
+
* Next.js App Router route handler type.
|
|
22
|
+
*
|
|
23
|
+
* Accepts anything that is a valid `Response` to avoid forcing users
|
|
24
|
+
* to annotate union bodies on every handler.
|
|
25
|
+
*/
|
|
26
|
+
type NextJSHandler = (req: NextRequest) => Awaitable<Response>;
|
|
27
|
+
/**
|
|
28
|
+
* Wrapper function that adds x402 payment verification to Next.js route handler.
|
|
29
|
+
* Returns a handler that may return either the original handler's response
|
|
30
|
+
* or a PaywallErrorResponse if payment verification fails.
|
|
31
|
+
*/
|
|
32
|
+
type NextJSPaywallWrapper = (handler: NextJSHandler) => NextJSHandler;
|
|
33
|
+
/**
|
|
34
|
+
* Create Next.js App Router middleware for x402 payment verification.
|
|
35
|
+
* Uses Mantle mainnet defaults (USDC, exact scheme, etc.).
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* // app/api/generate-image/route.ts
|
|
40
|
+
* import { mantlePaywall } from '@puga-labs/x402-mantle-sdk/server/nextjs'
|
|
41
|
+
*
|
|
42
|
+
* const pay = mantlePaywall({
|
|
43
|
+
* priceUsd: 0.01,
|
|
44
|
+
* payTo: process.env.PAY_TO!,
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* // No 'as any' needed! TypeScript correctly infers the union type
|
|
48
|
+
* export const POST = pay(async (req: NextRequest) => {
|
|
49
|
+
* const { prompt } = await req.json();
|
|
50
|
+
* // Your handler code here
|
|
51
|
+
* return NextResponse.json({ success: true, imageUrl: "..." });
|
|
52
|
+
* });
|
|
53
|
+
* // TypeScript knows POST returns: NextResponse<{ success: boolean; imageUrl: string } | PaywallErrorResponse>
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @param opts - Minimal configuration (price, payTo, optional facilitator/telemetry).
|
|
57
|
+
* @returns Function that wraps Next.js route handlers with payment verification.
|
|
58
|
+
*/
|
|
59
|
+
declare function mantlePaywall(opts: MinimalPaywallOptions): NextJSPaywallWrapper;
|
|
60
|
+
/**
|
|
61
|
+
* Type guard to check if a response is a paywall error response.
|
|
62
|
+
* Useful for handling the union type returned by the paywall wrapper.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const response = await fetch('/api/protected');
|
|
67
|
+
* const data = await response.json();
|
|
68
|
+
*
|
|
69
|
+
* if (isPaywallErrorResponse(data)) {
|
|
70
|
+
* // Handle error: data.error, data.paymentRequirements, etc.
|
|
71
|
+
* console.error('Payment required:', data.paymentRequirements);
|
|
72
|
+
* } else {
|
|
73
|
+
* // Handle success: data has type T
|
|
74
|
+
* console.log('Success:', data);
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
declare function isPaywallErrorResponse(response: unknown): response is PaywallErrorResponse;
|
|
79
|
+
|
|
80
|
+
type nextjs_NextJSHandler = NextJSHandler;
|
|
81
|
+
type nextjs_NextJSPaywallWrapper = NextJSPaywallWrapper;
|
|
82
|
+
type nextjs_PaywallErrorResponse = PaywallErrorResponse;
|
|
83
|
+
declare const nextjs_isPaywallErrorResponse: typeof isPaywallErrorResponse;
|
|
84
|
+
declare const nextjs_mantlePaywall: typeof mantlePaywall;
|
|
85
|
+
declare namespace nextjs {
|
|
86
|
+
export { type nextjs_NextJSHandler as NextJSHandler, type nextjs_NextJSPaywallWrapper as NextJSPaywallWrapper, type nextjs_PaywallErrorResponse as PaywallErrorResponse, nextjs_isPaywallErrorResponse as isPaywallErrorResponse, nextjs_mantlePaywall as mantlePaywall };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { type NextJSHandler as N, type PaywallErrorResponse as P, type NextJSPaywallWrapper as a, isPaywallErrorResponse as i, mantlePaywall as m, nextjs as n };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { M as MinimalPaywallOptions } from './types-CrOsOHcX.cjs';
|
|
3
|
+
import { P as PaymentRequirements } from './types-BFUqKBBO.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Error response returned when payment verification fails.
|
|
7
|
+
* This can be due to missing payment, invalid payment, or verification errors.
|
|
8
|
+
*/
|
|
9
|
+
interface PaywallErrorResponse {
|
|
10
|
+
error: string;
|
|
11
|
+
paymentRequirements?: PaymentRequirements;
|
|
12
|
+
paymentHeader?: null;
|
|
13
|
+
invalidReason?: string | null;
|
|
14
|
+
details?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Next.js App Router route handler type.
|
|
18
|
+
*/
|
|
19
|
+
type NextJSHandler<T = any> = (req: NextRequest) => Promise<NextResponse<T>>;
|
|
20
|
+
/**
|
|
21
|
+
* Wrapper function that adds x402 payment verification to Next.js route handler.
|
|
22
|
+
* Returns a handler that may return either the original handler's response type (T)
|
|
23
|
+
* or a PaywallErrorResponse if payment verification fails.
|
|
24
|
+
*/
|
|
25
|
+
type NextJSPaywallWrapper = <T>(handler: NextJSHandler<T>) => NextJSHandler<T | PaywallErrorResponse>;
|
|
26
|
+
/**
|
|
27
|
+
* Create Next.js App Router middleware for x402 payment verification.
|
|
28
|
+
* Uses Mantle mainnet defaults (USDC, exact scheme, etc.).
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* // app/api/generate-image/route.ts
|
|
33
|
+
* import { mantlePaywall } from '@puga-labs/x402-mantle-sdk/server/nextjs'
|
|
34
|
+
*
|
|
35
|
+
* const pay = mantlePaywall({
|
|
36
|
+
* priceUsd: 0.01,
|
|
37
|
+
* payTo: process.env.PAY_TO!,
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // No 'as any' needed! TypeScript correctly infers the union type
|
|
41
|
+
* export const POST = pay(async (req: NextRequest) => {
|
|
42
|
+
* const { prompt } = await req.json();
|
|
43
|
+
* // Your handler code here
|
|
44
|
+
* return NextResponse.json({ success: true, imageUrl: "..." });
|
|
45
|
+
* });
|
|
46
|
+
* // TypeScript knows POST returns: NextResponse<{ success: boolean; imageUrl: string } | PaywallErrorResponse>
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @param opts - Minimal configuration (price, payTo, optional facilitator/telemetry).
|
|
50
|
+
* @returns Function that wraps Next.js route handlers with payment verification.
|
|
51
|
+
*/
|
|
52
|
+
declare function mantlePaywall(opts: MinimalPaywallOptions): NextJSPaywallWrapper;
|
|
53
|
+
/**
|
|
54
|
+
* Type guard to check if a response is a paywall error response.
|
|
55
|
+
* Useful for handling the union type returned by the paywall wrapper.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const response = await fetch('/api/protected');
|
|
60
|
+
* const data = await response.json();
|
|
61
|
+
*
|
|
62
|
+
* if (isPaywallErrorResponse(data)) {
|
|
63
|
+
* // Handle error: data.error, data.paymentRequirements, etc.
|
|
64
|
+
* console.error('Payment required:', data.paymentRequirements);
|
|
65
|
+
* } else {
|
|
66
|
+
* // Handle success: data has type T
|
|
67
|
+
* console.log('Success:', data);
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
declare function isPaywallErrorResponse(response: unknown): response is PaywallErrorResponse;
|
|
72
|
+
|
|
73
|
+
type nextjs_NextJSHandler<T = any> = NextJSHandler<T>;
|
|
74
|
+
type nextjs_NextJSPaywallWrapper = NextJSPaywallWrapper;
|
|
75
|
+
type nextjs_PaywallErrorResponse = PaywallErrorResponse;
|
|
76
|
+
declare const nextjs_isPaywallErrorResponse: typeof isPaywallErrorResponse;
|
|
77
|
+
declare const nextjs_mantlePaywall: typeof mantlePaywall;
|
|
78
|
+
declare namespace nextjs {
|
|
79
|
+
export { type nextjs_NextJSHandler as NextJSHandler, type nextjs_NextJSPaywallWrapper as NextJSPaywallWrapper, type nextjs_PaywallErrorResponse as PaywallErrorResponse, nextjs_isPaywallErrorResponse as isPaywallErrorResponse, nextjs_mantlePaywall as mantlePaywall };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { type NextJSHandler as N, type PaywallErrorResponse as P, type NextJSPaywallWrapper as a, isPaywallErrorResponse as i, mantlePaywall as m, nextjs as n };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { NextRequest } from 'next/server';
|
|
2
|
+
import { M as MinimalPaywallOptions } from './types-CqQ6OgRi.js';
|
|
3
|
+
import { P as PaymentRequirements } from './types-BFUqKBBO.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Error response returned when payment verification fails.
|
|
7
|
+
* This can be due to missing payment, invalid payment, or verification errors.
|
|
8
|
+
*/
|
|
9
|
+
interface PaywallErrorResponse {
|
|
10
|
+
error: string;
|
|
11
|
+
paymentRequirements?: PaymentRequirements;
|
|
12
|
+
paymentHeader?: null;
|
|
13
|
+
invalidReason?: string | null;
|
|
14
|
+
details?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Simple promise-or-value helper.
|
|
18
|
+
*/
|
|
19
|
+
type Awaitable<T> = T | Promise<T>;
|
|
20
|
+
/**
|
|
21
|
+
* Next.js App Router route handler type.
|
|
22
|
+
*
|
|
23
|
+
* Accepts anything that is a valid `Response` to avoid forcing users
|
|
24
|
+
* to annotate union bodies on every handler.
|
|
25
|
+
*/
|
|
26
|
+
type NextJSHandler = (req: NextRequest) => Awaitable<Response>;
|
|
27
|
+
/**
|
|
28
|
+
* Wrapper function that adds x402 payment verification to Next.js route handler.
|
|
29
|
+
* Returns a handler that may return either the original handler's response
|
|
30
|
+
* or a PaywallErrorResponse if payment verification fails.
|
|
31
|
+
*/
|
|
32
|
+
type NextJSPaywallWrapper = (handler: NextJSHandler) => NextJSHandler;
|
|
33
|
+
/**
|
|
34
|
+
* Create Next.js App Router middleware for x402 payment verification.
|
|
35
|
+
* Uses Mantle mainnet defaults (USDC, exact scheme, etc.).
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* // app/api/generate-image/route.ts
|
|
40
|
+
* import { mantlePaywall } from '@puga-labs/x402-mantle-sdk/server/nextjs'
|
|
41
|
+
*
|
|
42
|
+
* const pay = mantlePaywall({
|
|
43
|
+
* priceUsd: 0.01,
|
|
44
|
+
* payTo: process.env.PAY_TO!,
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* // No 'as any' needed! TypeScript correctly infers the union type
|
|
48
|
+
* export const POST = pay(async (req: NextRequest) => {
|
|
49
|
+
* const { prompt } = await req.json();
|
|
50
|
+
* // Your handler code here
|
|
51
|
+
* return NextResponse.json({ success: true, imageUrl: "..." });
|
|
52
|
+
* });
|
|
53
|
+
* // TypeScript knows POST returns: NextResponse<{ success: boolean; imageUrl: string } | PaywallErrorResponse>
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @param opts - Minimal configuration (price, payTo, optional facilitator/telemetry).
|
|
57
|
+
* @returns Function that wraps Next.js route handlers with payment verification.
|
|
58
|
+
*/
|
|
59
|
+
declare function mantlePaywall(opts: MinimalPaywallOptions): NextJSPaywallWrapper;
|
|
60
|
+
/**
|
|
61
|
+
* Type guard to check if a response is a paywall error response.
|
|
62
|
+
* Useful for handling the union type returned by the paywall wrapper.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const response = await fetch('/api/protected');
|
|
67
|
+
* const data = await response.json();
|
|
68
|
+
*
|
|
69
|
+
* if (isPaywallErrorResponse(data)) {
|
|
70
|
+
* // Handle error: data.error, data.paymentRequirements, etc.
|
|
71
|
+
* console.error('Payment required:', data.paymentRequirements);
|
|
72
|
+
* } else {
|
|
73
|
+
* // Handle success: data has type T
|
|
74
|
+
* console.log('Success:', data);
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
declare function isPaywallErrorResponse(response: unknown): response is PaywallErrorResponse;
|
|
79
|
+
|
|
80
|
+
type nextjs_NextJSHandler = NextJSHandler;
|
|
81
|
+
type nextjs_NextJSPaywallWrapper = NextJSPaywallWrapper;
|
|
82
|
+
type nextjs_PaywallErrorResponse = PaywallErrorResponse;
|
|
83
|
+
declare const nextjs_isPaywallErrorResponse: typeof isPaywallErrorResponse;
|
|
84
|
+
declare const nextjs_mantlePaywall: typeof mantlePaywall;
|
|
85
|
+
declare namespace nextjs {
|
|
86
|
+
export { type nextjs_NextJSHandler as NextJSHandler, type nextjs_NextJSPaywallWrapper as NextJSPaywallWrapper, type nextjs_PaywallErrorResponse as PaywallErrorResponse, nextjs_isPaywallErrorResponse as isPaywallErrorResponse, nextjs_mantlePaywall as mantlePaywall };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { type NextJSHandler as N, type PaywallErrorResponse as P, type NextJSPaywallWrapper as a, isPaywallErrorResponse as i, mantlePaywall as m, nextjs as n };
|
package/dist/server-nextjs.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var server_nextjs_exports = {};
|
|
22
22
|
__export(server_nextjs_exports, {
|
|
23
23
|
MANTLE_DEFAULTS: () => MANTLE_DEFAULTS,
|
|
24
|
+
isPaywallErrorResponse: () => isPaywallErrorResponse,
|
|
24
25
|
mantlePaywall: () => mantlePaywall
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(server_nextjs_exports);
|
|
@@ -332,8 +333,12 @@ function mantlePaywall(opts) {
|
|
|
332
333
|
};
|
|
333
334
|
};
|
|
334
335
|
}
|
|
336
|
+
function isPaywallErrorResponse(response) {
|
|
337
|
+
return typeof response === "object" && response !== null && "error" in response && typeof response.error === "string";
|
|
338
|
+
}
|
|
335
339
|
// Annotate the CommonJS export names for ESM import in node:
|
|
336
340
|
0 && (module.exports = {
|
|
337
341
|
MANTLE_DEFAULTS,
|
|
342
|
+
isPaywallErrorResponse,
|
|
338
343
|
mantlePaywall
|
|
339
344
|
});
|
package/dist/server-nextjs.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { N as NextJSHandler, a as NextJSPaywallWrapper, m as mantlePaywall } from './nextjs-
|
|
1
|
+
export { N as NextJSHandler, a as NextJSPaywallWrapper, P as PaywallErrorResponse, i as isPaywallErrorResponse, m as mantlePaywall } from './nextjs-CGOVHJXl.cjs';
|
|
2
2
|
export { M as MinimalPaywallOptions, c as PaymentCheckInput, d as PaymentCheckResult, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-CrOsOHcX.cjs';
|
|
3
3
|
export { A as AssetConfig, a as Authorization, E as EIP1193Provider, N as NetworkId, d as PaymentHeaderBase64, c as PaymentHeaderObject, b as PaymentHeaderPayload, P as PaymentRequirements } from './types-BFUqKBBO.cjs';
|
|
4
4
|
export { M as MANTLE_DEFAULTS } from './constants-CsIL25uQ.cjs';
|
package/dist/server-nextjs.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { N as NextJSHandler, a as NextJSPaywallWrapper, m as mantlePaywall } from './nextjs-
|
|
1
|
+
export { N as NextJSHandler, a as NextJSPaywallWrapper, P as PaywallErrorResponse, i as isPaywallErrorResponse, m as mantlePaywall } from './nextjs-w61gRvpz.js';
|
|
2
2
|
export { M as MinimalPaywallOptions, c as PaymentCheckInput, d as PaymentCheckResult, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-CqQ6OgRi.js';
|
|
3
3
|
export { A as AssetConfig, a as Authorization, E as EIP1193Provider, N as NetworkId, d as PaymentHeaderBase64, c as PaymentHeaderObject, b as PaymentHeaderPayload, P as PaymentRequirements } from './types-BFUqKBBO.js';
|
|
4
4
|
export { M as MANTLE_DEFAULTS } from './constants-0ncqvV_O.js';
|
package/dist/server-nextjs.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
+
isPaywallErrorResponse,
|
|
2
3
|
mantlePaywall
|
|
3
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-IT6VV6YL.js";
|
|
4
5
|
import "./chunk-ZLCKBFVJ.js";
|
|
5
6
|
import {
|
|
6
7
|
MANTLE_DEFAULTS
|
|
7
8
|
} from "./chunk-HEZZ74SI.js";
|
|
8
9
|
export {
|
|
9
10
|
MANTLE_DEFAULTS,
|
|
11
|
+
isPaywallErrorResponse,
|
|
10
12
|
mantlePaywall
|
|
11
13
|
};
|
package/dist/server.cjs
CHANGED
|
@@ -378,6 +378,7 @@ function mantlePaywall(opts) {
|
|
|
378
378
|
// src/server/adapters/nextjs.ts
|
|
379
379
|
var nextjs_exports = {};
|
|
380
380
|
__export(nextjs_exports, {
|
|
381
|
+
isPaywallErrorResponse: () => isPaywallErrorResponse,
|
|
381
382
|
mantlePaywall: () => mantlePaywall2
|
|
382
383
|
});
|
|
383
384
|
var import_server = require("next/server");
|
|
@@ -426,6 +427,9 @@ function mantlePaywall2(opts) {
|
|
|
426
427
|
};
|
|
427
428
|
};
|
|
428
429
|
}
|
|
430
|
+
function isPaywallErrorResponse(response) {
|
|
431
|
+
return typeof response === "object" && response !== null && "error" in response && typeof response.error === "string";
|
|
432
|
+
}
|
|
429
433
|
|
|
430
434
|
// src/server/adapters/web-standards.ts
|
|
431
435
|
var web_standards_exports = {};
|
package/dist/server.d.cts
CHANGED
|
@@ -2,7 +2,7 @@ import { c as PaymentCheckInput, d as PaymentCheckResult } from './types-CrOsOHc
|
|
|
2
2
|
export { M as MinimalPaywallOptions, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-CrOsOHcX.cjs';
|
|
3
3
|
import { c as PaymentHeaderObject } from './types-BFUqKBBO.cjs';
|
|
4
4
|
export { M as MantleMiddleware, c as createPaymentMiddleware, e as express, m as mantlePaywall } from './express-eQOPxfnI.cjs';
|
|
5
|
-
export { n as nextjs } from './nextjs-
|
|
5
|
+
export { n as nextjs } from './nextjs-CGOVHJXl.cjs';
|
|
6
6
|
export { w as web } from './web-standards-BNQyWzBC.cjs';
|
|
7
7
|
import { P as PaymentLogEntry, T as TelemetryConfig, c as TelemetryEvent } from './types-CoOdbZSp.cjs';
|
|
8
8
|
import 'express';
|
package/dist/server.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { c as PaymentCheckInput, d as PaymentCheckResult } from './types-CqQ6OgR
|
|
|
2
2
|
export { M as MinimalPaywallOptions, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-CqQ6OgRi.js';
|
|
3
3
|
import { c as PaymentHeaderObject } from './types-BFUqKBBO.js';
|
|
4
4
|
export { M as MantleMiddleware, c as createPaymentMiddleware, e as express, m as mantlePaywall } from './express-D8EwEcOL.js';
|
|
5
|
-
export { n as nextjs } from './nextjs-
|
|
5
|
+
export { n as nextjs } from './nextjs-w61gRvpz.js';
|
|
6
6
|
export { w as web } from './web-standards-D8j1kZxd.js';
|
|
7
7
|
import { P as PaymentLogEntry, T as TelemetryConfig, c as TelemetryEvent } from './types-DTzov_EE.js';
|
|
8
8
|
import 'express';
|
package/dist/server.js
CHANGED
package/package.json
CHANGED