@puga-labs/x402-mantle-sdk 0.3.2 → 0.3.4
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-GHUWTX7J.js → chunk-CXRILT3C.js} +4 -2
- package/dist/chunk-IT6VV6YL.js +73 -0
- package/dist/{chunk-6GLR5EBK.js → chunk-QWQUSRLY.js} +5 -2
- package/dist/{chunk-BRGW36P7.js → chunk-ZLCKBFVJ.js} +27 -1
- package/dist/{chunk-WFUDGBKK.js → chunk-ZROK2XOB.js} +4 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/nextjs-BgyAWzT3.d.ts +82 -0
- package/dist/nextjs-CY13JXkV.d.cts +82 -0
- package/dist/server-express.cjs +1 -1
- package/dist/server-express.js +2 -2
- package/dist/server-nextjs.cjs +6 -1
- package/dist/server-nextjs.d.cts +1 -1
- package/dist/server-nextjs.d.ts +1 -1
- package/dist/server-nextjs.js +4 -2
- package/dist/server-web.cjs +1 -1
- package/dist/server-web.js +2 -2
- package/dist/server.cjs +5 -1
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +4 -4
- package/package.json +2 -2
- package/dist/chunk-CTI5CRDY.js +0 -274
- package/dist/chunk-DA6ZBXNO.js +0 -275
- package/dist/chunk-FD4HG7KR.js +0 -135
- package/dist/chunk-FHU6CFHF.js +0 -0
- package/dist/chunk-GWVWPS3R.js +0 -277
- package/dist/chunk-HTZ3QFY4.js +0 -135
- package/dist/chunk-MQALBRGV.js +0 -135
- package/dist/chunk-PYIYE3HI.js +0 -135
- package/dist/chunk-Q6SPMEIW.js +0 -235
- package/dist/chunk-RNKXSBT7.js +0 -135
- package/dist/chunk-SPCXFN7C.js +0 -284
- package/dist/chunk-T5DRYLNB.js +0 -135
- package/dist/chunk-TSEE5NSJ.js +0 -297
- package/dist/chunk-WAKJRVUP.js +0 -135
- package/dist/chunk-WELDWRDX.js +0 -307
- package/dist/chunk-XAQGMFSR.js +0 -56
- package/dist/constants-C7aY8u5b.d.cts +0 -77
- package/dist/constants-C7aY8u5b.d.ts +0 -77
- package/dist/constants-CVFF0ray.d.ts +0 -17
- package/dist/constants-DzCGK0Q3.d.cts +0 -17
- package/dist/createMantleClient-DS1Ghqrz.d.cts +0 -51
- package/dist/createMantleClient-DS1Ghqrz.d.ts +0 -51
- package/dist/createMantleClient-DVFkbBfS.d.ts +0 -87
- package/dist/createMantleClient-NN0Nitp9.d.cts +0 -87
- package/dist/express-Ck7eryef.d.cts +0 -66
- package/dist/express-CmEg5hR3.d.ts +0 -66
- package/dist/nextjs-Bp8DxYDN.d.ts +0 -45
- package/dist/nextjs-CliiaTPe.d.cts +0 -45
- package/dist/nextjs-D7t-BC4N.d.ts +0 -45
- package/dist/nextjs-ZO2J9mdo.d.cts +0 -45
- package/dist/types-2zqbJvcz.d.cts +0 -63
- package/dist/types-2zqbJvcz.d.ts +0 -63
- package/dist/types-C7EPJ6Hd.d.ts +0 -85
- package/dist/types-CEttmr1U.d.cts +0 -97
- package/dist/types-D20K36pc.d.ts +0 -97
- package/dist/types-xkNm0uzE.d.cts +0 -85
- package/dist/web-standards-C3D2vdTg.d.ts +0 -77
- package/dist/web-standards-DOYp0UDT.d.cts +0 -77
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildRouteKey,
|
|
3
|
-
checkPayment
|
|
4
|
-
|
|
3
|
+
checkPayment,
|
|
4
|
+
validateAddress
|
|
5
|
+
} from "./chunk-ZLCKBFVJ.js";
|
|
5
6
|
import {
|
|
6
7
|
MANTLE_DEFAULTS,
|
|
7
8
|
__export,
|
|
@@ -17,6 +18,7 @@ __export(nextjs_exports, {
|
|
|
17
18
|
import { NextResponse } from "next/server";
|
|
18
19
|
function mantlePaywall(opts) {
|
|
19
20
|
const { priceUsd, payTo, facilitatorUrl, telemetry, onPaymentSettled } = opts;
|
|
21
|
+
validateAddress(payTo, "payTo");
|
|
20
22
|
const priceUsdCents = Math.round(priceUsd * 100);
|
|
21
23
|
return function(handler) {
|
|
22
24
|
return async (req) => {
|
|
@@ -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
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildRouteKey,
|
|
3
|
-
checkPayment
|
|
4
|
-
|
|
3
|
+
checkPayment,
|
|
4
|
+
validateAddress
|
|
5
|
+
} from "./chunk-ZLCKBFVJ.js";
|
|
5
6
|
import {
|
|
6
7
|
MANTLE_DEFAULTS,
|
|
7
8
|
__export,
|
|
@@ -23,6 +24,7 @@ function createPaymentMiddleware(config) {
|
|
|
23
24
|
if (!receiverAddress) {
|
|
24
25
|
throw new Error("receiverAddress is required");
|
|
25
26
|
}
|
|
27
|
+
validateAddress(receiverAddress, "receiverAddress");
|
|
26
28
|
if (!routes || Object.keys(routes).length === 0) {
|
|
27
29
|
throw new Error("routes config must not be empty");
|
|
28
30
|
}
|
|
@@ -68,6 +70,7 @@ function createPaymentMiddleware(config) {
|
|
|
68
70
|
}
|
|
69
71
|
function mantlePaywall(opts) {
|
|
70
72
|
const { priceUsd, payTo, facilitatorUrl, telemetry, onPaymentSettled } = opts;
|
|
73
|
+
validateAddress(payTo, "payTo");
|
|
71
74
|
const priceUsdCents = Math.round(priceUsd * 100);
|
|
72
75
|
return async (req, res, next) => {
|
|
73
76
|
const method = (req.method || "GET").toUpperCase();
|
|
@@ -3,6 +3,31 @@ import {
|
|
|
3
3
|
} from "./chunk-HEZZ74SI.js";
|
|
4
4
|
|
|
5
5
|
// src/server/core/utils.ts
|
|
6
|
+
function validateAddress(address, paramName = "address") {
|
|
7
|
+
if (!address) {
|
|
8
|
+
throw new Error(`${paramName} is required`);
|
|
9
|
+
}
|
|
10
|
+
if (typeof address !== "string") {
|
|
11
|
+
throw new Error(`${paramName} must be a string, got ${typeof address}`);
|
|
12
|
+
}
|
|
13
|
+
if (!address.startsWith("0x")) {
|
|
14
|
+
const preview = address.length > 10 ? `${address.substring(0, 10)}...` : address;
|
|
15
|
+
throw new Error(
|
|
16
|
+
`${paramName} must start with "0x", got: ${preview}`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
if (address.length !== 42) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`${paramName} must be 42 characters (0x + 40 hex), got ${address.length} characters`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
const hexPart = address.slice(2);
|
|
25
|
+
if (!/^[0-9a-fA-F]{40}$/.test(hexPart)) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`${paramName} must contain only hexadecimal characters (0-9, a-f, A-F) after "0x"`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
6
31
|
function decodePaymentHeader(paymentHeaderBase64) {
|
|
7
32
|
try {
|
|
8
33
|
if (typeof Buffer !== "undefined") {
|
|
@@ -90,7 +115,7 @@ async function checkPayment(input) {
|
|
|
90
115
|
telemetry,
|
|
91
116
|
onPaymentSettled
|
|
92
117
|
} = input;
|
|
93
|
-
if (!paymentHeader) {
|
|
118
|
+
if (!paymentHeader || paymentHeader.trim() === "") {
|
|
94
119
|
return {
|
|
95
120
|
status: "require_payment",
|
|
96
121
|
statusCode: 402,
|
|
@@ -202,6 +227,7 @@ async function checkPayment(input) {
|
|
|
202
227
|
}
|
|
203
228
|
|
|
204
229
|
export {
|
|
230
|
+
validateAddress,
|
|
205
231
|
decodePaymentHeader,
|
|
206
232
|
buildRouteKey,
|
|
207
233
|
DEFAULT_TELEMETRY_ENDPOINT,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildRouteKey,
|
|
3
|
-
checkPayment
|
|
4
|
-
|
|
3
|
+
checkPayment,
|
|
4
|
+
validateAddress
|
|
5
|
+
} from "./chunk-ZLCKBFVJ.js";
|
|
5
6
|
import {
|
|
6
7
|
MANTLE_DEFAULTS,
|
|
7
8
|
__export,
|
|
@@ -16,6 +17,7 @@ __export(web_standards_exports, {
|
|
|
16
17
|
});
|
|
17
18
|
function mantlePaywall(opts) {
|
|
18
19
|
const { priceUsd, payTo, facilitatorUrl, telemetry, onPaymentSettled } = opts;
|
|
20
|
+
validateAddress(payTo, "payTo");
|
|
19
21
|
const priceUsdCents = Math.round(priceUsd * 100);
|
|
20
22
|
return function(handler) {
|
|
21
23
|
return async (request) => {
|
package/dist/index.cjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -10,8 +10,8 @@ import "./chunk-WO2MYZXT.js";
|
|
|
10
10
|
import {
|
|
11
11
|
createPaymentMiddleware,
|
|
12
12
|
mantlePaywall
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
13
|
+
} from "./chunk-QWQUSRLY.js";
|
|
14
|
+
import "./chunk-ZLCKBFVJ.js";
|
|
15
15
|
import {
|
|
16
16
|
MANTLE_DEFAULTS
|
|
17
17
|
} from "./chunk-HEZZ74SI.js";
|
|
@@ -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,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 };
|
package/dist/server-express.cjs
CHANGED
package/dist/server-express.js
CHANGED
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);
|
|
@@ -175,7 +176,7 @@ async function checkPayment(input) {
|
|
|
175
176
|
telemetry,
|
|
176
177
|
onPaymentSettled
|
|
177
178
|
} = input;
|
|
178
|
-
if (!paymentHeader) {
|
|
179
|
+
if (!paymentHeader || paymentHeader.trim() === "") {
|
|
179
180
|
return {
|
|
180
181
|
status: "require_payment",
|
|
181
182
|
statusCode: 402,
|
|
@@ -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-CY13JXkV.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-BgyAWzT3.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
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-IT6VV6YL.js";
|
|
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-web.cjs
CHANGED
package/dist/server-web.js
CHANGED
package/dist/server.cjs
CHANGED
|
@@ -182,7 +182,7 @@ async function checkPayment(input) {
|
|
|
182
182
|
telemetry,
|
|
183
183
|
onPaymentSettled
|
|
184
184
|
} = input;
|
|
185
|
-
if (!paymentHeader) {
|
|
185
|
+
if (!paymentHeader || paymentHeader.trim() === "") {
|
|
186
186
|
return {
|
|
187
187
|
status: "require_payment",
|
|
188
188
|
statusCode: 402,
|
|
@@ -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-CY13JXkV.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-BgyAWzT3.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
|
@@ -3,13 +3,13 @@ import {
|
|
|
3
3
|
createPaymentMiddleware,
|
|
4
4
|
express_exports,
|
|
5
5
|
mantlePaywall
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-QWQUSRLY.js";
|
|
7
7
|
import {
|
|
8
8
|
nextjs_exports
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-IT6VV6YL.js";
|
|
10
10
|
import {
|
|
11
11
|
web_standards_exports
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-ZROK2XOB.js";
|
|
13
13
|
import {
|
|
14
14
|
DEFAULT_TELEMETRY_ENDPOINT,
|
|
15
15
|
buildRouteKey,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
decodePaymentHeader,
|
|
19
19
|
sendTelemetry,
|
|
20
20
|
validateAddress
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-ZLCKBFVJ.js";
|
|
22
22
|
import "./chunk-HEZZ74SI.js";
|
|
23
23
|
export {
|
|
24
24
|
DEFAULT_TELEMETRY_ENDPOINT,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@puga-labs/x402-mantle-sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "x402 payments SDK for Mantle (USDC, gasless, facilitator-based)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Evgenii Pugachev <cyprus.pugamuga@gmail.com>",
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
"peerDependencies": {
|
|
109
109
|
"ethers": "^6.0.0",
|
|
110
110
|
"express": "^4.0.0 || ^5.0.0",
|
|
111
|
-
"next": "^14.0.0 || ^15.0.0",
|
|
111
|
+
"next": "^14.0.0 || ^15.0.0 || ^16.0.0",
|
|
112
112
|
"react": "^18.0.0 || ^19.0.0"
|
|
113
113
|
},
|
|
114
114
|
"peerDependenciesMeta": {
|