@parallel-protocol/x402 0.5.3 → 0.6.0
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 +51 -4
- package/dist/{chunk-KQPIZ6SZ.cjs → chunk-K6QETMQA.cjs} +124 -15
- package/dist/{chunk-75GLDK7L.js → chunk-TLCEPWQI.js} +120 -16
- package/dist/express.cjs +14 -6
- package/dist/express.d.cts +2 -2
- package/dist/express.d.ts +2 -2
- package/dist/express.js +12 -4
- package/dist/fastify.cjs +62 -13
- package/dist/fastify.d.cts +1 -1
- package/dist/fastify.d.ts +1 -1
- package/dist/fastify.js +60 -11
- package/dist/hono.cjs +10 -6
- package/dist/hono.d.cts +2 -2
- package/dist/hono.d.ts +2 -2
- package/dist/hono.js +8 -4
- package/dist/index.cjs +21 -13
- package/dist/index.d.cts +29 -4
- package/dist/index.d.ts +29 -4
- package/dist/index.js +1 -1
- package/dist/next.cjs +36 -7
- package/dist/next.d.cts +1 -1
- package/dist/next.d.ts +1 -1
- package/dist/next.js +33 -4
- package/dist/types-CBzm5CtM.d.cts +131 -0
- package/dist/types-CBzm5CtM.d.ts +131 -0
- package/package.json +2 -2
- package/dist/chunk-2UEAVMCH.js +0 -17
- package/dist/chunk-XUNNMCO5.cjs +0 -20
- package/dist/types-CUi55YSx.d.cts +0 -95
- package/dist/types-CUi55YSx.d.ts +0 -95
package/dist/next.cjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var chunkKQPIZ6SZ_cjs = require('./chunk-KQPIZ6SZ.cjs');
|
|
3
|
+
var chunkK6QETMQA_cjs = require('./chunk-K6QETMQA.cjs');
|
|
5
4
|
var server = require('next/server');
|
|
6
5
|
|
|
7
6
|
// src/next/adapter.ts
|
|
@@ -26,7 +25,7 @@ var NextAdapter = class {
|
|
|
26
25
|
|
|
27
26
|
// src/next/index.ts
|
|
28
27
|
function withPayment(config, handler) {
|
|
29
|
-
const gate =
|
|
28
|
+
const gate = chunkK6QETMQA_cjs.createPaymentGate(config);
|
|
30
29
|
return async (req) => {
|
|
31
30
|
const gateResult = await gate(new NextAdapter(req));
|
|
32
31
|
if (gateResult.type === "pass") {
|
|
@@ -43,20 +42,50 @@ function withPayment(config, handler) {
|
|
|
43
42
|
}
|
|
44
43
|
let response;
|
|
45
44
|
try {
|
|
46
|
-
const outcome = await
|
|
47
|
-
|
|
45
|
+
const outcome = await chunkK6QETMQA_cjs.raceTimeout(
|
|
46
|
+
handler(req),
|
|
47
|
+
gateResult.handlerTimeoutMs
|
|
48
|
+
);
|
|
49
|
+
if (outcome === chunkK6QETMQA_cjs.HANDLER_TIMEOUT) {
|
|
48
50
|
return new server.NextResponse(null, { status: 504 });
|
|
49
51
|
}
|
|
50
52
|
response = outcome;
|
|
51
53
|
} catch {
|
|
52
54
|
return new server.NextResponse(null, { status: 504 });
|
|
53
55
|
}
|
|
56
|
+
let raw;
|
|
57
|
+
if (gateResult.scheme === "upto") {
|
|
58
|
+
raw = response.headers.get(chunkK6QETMQA_cjs.SETTLE_AMOUNT_HEADER) ?? void 0;
|
|
59
|
+
if (raw !== void 0) {
|
|
60
|
+
const headers = new Headers(response.headers);
|
|
61
|
+
headers.delete(chunkK6QETMQA_cjs.SETTLE_AMOUNT_HEADER);
|
|
62
|
+
response = new server.NextResponse(response.body, {
|
|
63
|
+
status: response.status,
|
|
64
|
+
headers
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
54
68
|
if (response.status >= 200 && response.status < 300) {
|
|
69
|
+
let settleOptions;
|
|
70
|
+
if (gateResult.scheme === "upto") {
|
|
71
|
+
const resolved = chunkK6QETMQA_cjs.resolveSettleAmount(
|
|
72
|
+
raw,
|
|
73
|
+
gateResult.maxAmount,
|
|
74
|
+
gateResult.decimals
|
|
75
|
+
);
|
|
76
|
+
if (resolved.kind === "invalid") {
|
|
77
|
+
return server.NextResponse.json(chunkK6QETMQA_cjs.INVALID_SETTLE_AMOUNT_RESPONSE, {
|
|
78
|
+
status: 402
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
if (resolved.kind === "skip") return response;
|
|
82
|
+
settleOptions = { amount: resolved.amount };
|
|
83
|
+
}
|
|
55
84
|
try {
|
|
56
|
-
const settleResponse = await gateResult.settle();
|
|
85
|
+
const settleResponse = settleOptions ? await gateResult.settle(settleOptions) : await gateResult.settle();
|
|
57
86
|
if (settleResponse.success) {
|
|
58
87
|
const headers = new Headers(response.headers);
|
|
59
|
-
headers.set("payment-response",
|
|
88
|
+
headers.set("payment-response", chunkK6QETMQA_cjs.encodeBase64(settleResponse));
|
|
60
89
|
headers.set("access-control-expose-headers", "payment-response");
|
|
61
90
|
return new server.NextResponse(response.body, {
|
|
62
91
|
status: response.status,
|
package/dist/next.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import { H as HTTPAdapter, P as PaymentMiddlewareConfig } from './types-
|
|
2
|
+
import { H as HTTPAdapter, P as PaymentMiddlewareConfig } from './types-CBzm5CtM.cjs';
|
|
3
3
|
import 'viem';
|
|
4
4
|
|
|
5
5
|
declare class NextAdapter implements HTTPAdapter {
|
package/dist/next.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import { H as HTTPAdapter, P as PaymentMiddlewareConfig } from './types-
|
|
2
|
+
import { H as HTTPAdapter, P as PaymentMiddlewareConfig } from './types-CBzm5CtM.js';
|
|
3
3
|
import 'viem';
|
|
4
4
|
|
|
5
5
|
declare class NextAdapter implements HTTPAdapter {
|
package/dist/next.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { raceTimeout, HANDLER_TIMEOUT } from './chunk-
|
|
2
|
-
import { createPaymentGate, encodeBase64 } from './chunk-75GLDK7L.js';
|
|
1
|
+
import { createPaymentGate, raceTimeout, HANDLER_TIMEOUT, SETTLE_AMOUNT_HEADER, resolveSettleAmount, INVALID_SETTLE_AMOUNT_RESPONSE, encodeBase64 } from './chunk-TLCEPWQI.js';
|
|
3
2
|
import { NextResponse } from 'next/server';
|
|
4
3
|
|
|
5
4
|
// src/next/adapter.ts
|
|
@@ -41,7 +40,10 @@ function withPayment(config, handler) {
|
|
|
41
40
|
}
|
|
42
41
|
let response;
|
|
43
42
|
try {
|
|
44
|
-
const outcome = await raceTimeout(
|
|
43
|
+
const outcome = await raceTimeout(
|
|
44
|
+
handler(req),
|
|
45
|
+
gateResult.handlerTimeoutMs
|
|
46
|
+
);
|
|
45
47
|
if (outcome === HANDLER_TIMEOUT) {
|
|
46
48
|
return new NextResponse(null, { status: 504 });
|
|
47
49
|
}
|
|
@@ -49,9 +51,36 @@ function withPayment(config, handler) {
|
|
|
49
51
|
} catch {
|
|
50
52
|
return new NextResponse(null, { status: 504 });
|
|
51
53
|
}
|
|
54
|
+
let raw;
|
|
55
|
+
if (gateResult.scheme === "upto") {
|
|
56
|
+
raw = response.headers.get(SETTLE_AMOUNT_HEADER) ?? void 0;
|
|
57
|
+
if (raw !== void 0) {
|
|
58
|
+
const headers = new Headers(response.headers);
|
|
59
|
+
headers.delete(SETTLE_AMOUNT_HEADER);
|
|
60
|
+
response = new NextResponse(response.body, {
|
|
61
|
+
status: response.status,
|
|
62
|
+
headers
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
52
66
|
if (response.status >= 200 && response.status < 300) {
|
|
67
|
+
let settleOptions;
|
|
68
|
+
if (gateResult.scheme === "upto") {
|
|
69
|
+
const resolved = resolveSettleAmount(
|
|
70
|
+
raw,
|
|
71
|
+
gateResult.maxAmount,
|
|
72
|
+
gateResult.decimals
|
|
73
|
+
);
|
|
74
|
+
if (resolved.kind === "invalid") {
|
|
75
|
+
return NextResponse.json(INVALID_SETTLE_AMOUNT_RESPONSE, {
|
|
76
|
+
status: 402
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
if (resolved.kind === "skip") return response;
|
|
80
|
+
settleOptions = { amount: resolved.amount };
|
|
81
|
+
}
|
|
53
82
|
try {
|
|
54
|
-
const settleResponse = await gateResult.settle();
|
|
83
|
+
const settleResponse = settleOptions ? await gateResult.settle(settleOptions) : await gateResult.settle();
|
|
55
84
|
if (settleResponse.success) {
|
|
56
85
|
const headers = new Headers(response.headers);
|
|
57
86
|
headers.set("payment-response", encodeBase64(settleResponse));
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { Address } from 'viem';
|
|
2
|
+
|
|
3
|
+
interface FacilitatorConfig {
|
|
4
|
+
url: string;
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
}
|
|
7
|
+
interface RouteConfig {
|
|
8
|
+
price: string | bigint;
|
|
9
|
+
decimals?: number;
|
|
10
|
+
network: string;
|
|
11
|
+
payTo: Address;
|
|
12
|
+
acceptedTokens?: Address[];
|
|
13
|
+
description?: string;
|
|
14
|
+
/**
|
|
15
|
+
* `exact` (default) charges `price` as invoiced. `upto` invoices `price` as a
|
|
16
|
+
* cap: the handler decides the actual amount through the
|
|
17
|
+
* `payment-settle-amount` response header and the remainder is refunded.
|
|
18
|
+
*/
|
|
19
|
+
scheme?: "exact" | "upto";
|
|
20
|
+
/**
|
|
21
|
+
* Settlement window the payer signs for, in seconds (default 300). Metered
|
|
22
|
+
* routes announce how long their handler may take; the facilitator caps it
|
|
23
|
+
* at 3600. The handler must finish comfortably before it expires.
|
|
24
|
+
*/
|
|
25
|
+
maxTimeoutSeconds?: number;
|
|
26
|
+
}
|
|
27
|
+
interface PaymentMiddlewareConfig {
|
|
28
|
+
facilitator: FacilitatorConfig;
|
|
29
|
+
routes: Record<string, RouteConfig>;
|
|
30
|
+
}
|
|
31
|
+
interface RunHandlerOptions {
|
|
32
|
+
/** Handler timeout for this request; defaults to the adapter's 30 s. */
|
|
33
|
+
timeoutMs?: number;
|
|
34
|
+
}
|
|
35
|
+
interface RunHandlerResult {
|
|
36
|
+
status: number;
|
|
37
|
+
setResponseHeader(name: string, value: string): void;
|
|
38
|
+
/** Reads a header the handler set on its response (metered routes). */
|
|
39
|
+
getResponseHeader?(name: string): string | undefined;
|
|
40
|
+
/** Strips a header before the response leaves (metered routes). */
|
|
41
|
+
removeResponseHeader?(name: string): void;
|
|
42
|
+
sendResponse(): void;
|
|
43
|
+
discardResponse(): void;
|
|
44
|
+
}
|
|
45
|
+
interface HTTPAdapter {
|
|
46
|
+
getHeader(name: string): string | undefined;
|
|
47
|
+
getMethod(): string;
|
|
48
|
+
getPath(): string;
|
|
49
|
+
getUrl(): string;
|
|
50
|
+
runHandler?(options?: RunHandlerOptions): Promise<RunHandlerResult>;
|
|
51
|
+
}
|
|
52
|
+
interface ResourceInfo {
|
|
53
|
+
url: string;
|
|
54
|
+
description?: string;
|
|
55
|
+
mimeType?: string;
|
|
56
|
+
}
|
|
57
|
+
interface PaymentRequirements {
|
|
58
|
+
scheme: string;
|
|
59
|
+
network: string;
|
|
60
|
+
asset: string;
|
|
61
|
+
amount: string;
|
|
62
|
+
payTo: string;
|
|
63
|
+
maxTimeoutSeconds: number;
|
|
64
|
+
extra: Record<string, unknown>;
|
|
65
|
+
}
|
|
66
|
+
interface PaymentRequired {
|
|
67
|
+
x402Version: number;
|
|
68
|
+
error?: string;
|
|
69
|
+
resource: ResourceInfo;
|
|
70
|
+
accepts: PaymentRequirements[];
|
|
71
|
+
extensions?: Record<string, unknown>;
|
|
72
|
+
}
|
|
73
|
+
interface FacilitatorPaymentRequirements {
|
|
74
|
+
maxAmountRequired: string;
|
|
75
|
+
asset: string;
|
|
76
|
+
payTo: string;
|
|
77
|
+
network: string;
|
|
78
|
+
scheme?: "exact" | "upto";
|
|
79
|
+
maxTimeoutSeconds?: number;
|
|
80
|
+
}
|
|
81
|
+
/** Settle-time options — only metered (`upto`) routes use them. */
|
|
82
|
+
interface SettleOptions {
|
|
83
|
+
/** Amount actually charged, in the asset's smallest unit. */
|
|
84
|
+
amount?: string;
|
|
85
|
+
}
|
|
86
|
+
interface PaymentConfirmation {
|
|
87
|
+
success: true;
|
|
88
|
+
txHash: Address;
|
|
89
|
+
route: string;
|
|
90
|
+
chain: string;
|
|
91
|
+
gasSponsored: boolean;
|
|
92
|
+
networkId: string;
|
|
93
|
+
/** Amount actually charged (smallest unit) — metered routes only. */
|
|
94
|
+
amountSettled?: string;
|
|
95
|
+
}
|
|
96
|
+
interface PaymentFailure {
|
|
97
|
+
success: false;
|
|
98
|
+
error: {
|
|
99
|
+
code: string;
|
|
100
|
+
message: string;
|
|
101
|
+
hint?: string;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
type FacilitatorResponse = PaymentConfirmation | PaymentFailure;
|
|
105
|
+
interface MiddlewareResult {
|
|
106
|
+
status: number;
|
|
107
|
+
headers: Record<string, string>;
|
|
108
|
+
body: unknown;
|
|
109
|
+
}
|
|
110
|
+
interface PassResult {
|
|
111
|
+
pass: true;
|
|
112
|
+
handlerRan?: true;
|
|
113
|
+
}
|
|
114
|
+
type VerifiedPayment = {
|
|
115
|
+
type: "verified";
|
|
116
|
+
scheme: "exact" | "upto";
|
|
117
|
+
/** The verified amount (smallest unit): the price, or the cap for `upto`. */
|
|
118
|
+
maxAmount: bigint;
|
|
119
|
+
decimals: number;
|
|
120
|
+
/** How long the handler may run before the middleware gives up on it. */
|
|
121
|
+
handlerTimeoutMs: number;
|
|
122
|
+
settle(options?: SettleOptions): Promise<FacilitatorResponse>;
|
|
123
|
+
};
|
|
124
|
+
type PaymentGateResult = {
|
|
125
|
+
type: "pass";
|
|
126
|
+
} | {
|
|
127
|
+
type: "error";
|
|
128
|
+
result: MiddlewareResult;
|
|
129
|
+
} | VerifiedPayment;
|
|
130
|
+
|
|
131
|
+
export type { FacilitatorConfig as F, HTTPAdapter as H, MiddlewareResult as M, PaymentMiddlewareConfig as P, RunHandlerOptions as R, SettleOptions as S, VerifiedPayment as V, RunHandlerResult as a, FacilitatorPaymentRequirements as b, FacilitatorResponse as c, PaymentGateResult as d, PassResult as e, PaymentConfirmation as f, PaymentFailure as g, PaymentRequired as h, PaymentRequirements as i, ResourceInfo as j, RouteConfig as k };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { Address } from 'viem';
|
|
2
|
+
|
|
3
|
+
interface FacilitatorConfig {
|
|
4
|
+
url: string;
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
}
|
|
7
|
+
interface RouteConfig {
|
|
8
|
+
price: string | bigint;
|
|
9
|
+
decimals?: number;
|
|
10
|
+
network: string;
|
|
11
|
+
payTo: Address;
|
|
12
|
+
acceptedTokens?: Address[];
|
|
13
|
+
description?: string;
|
|
14
|
+
/**
|
|
15
|
+
* `exact` (default) charges `price` as invoiced. `upto` invoices `price` as a
|
|
16
|
+
* cap: the handler decides the actual amount through the
|
|
17
|
+
* `payment-settle-amount` response header and the remainder is refunded.
|
|
18
|
+
*/
|
|
19
|
+
scheme?: "exact" | "upto";
|
|
20
|
+
/**
|
|
21
|
+
* Settlement window the payer signs for, in seconds (default 300). Metered
|
|
22
|
+
* routes announce how long their handler may take; the facilitator caps it
|
|
23
|
+
* at 3600. The handler must finish comfortably before it expires.
|
|
24
|
+
*/
|
|
25
|
+
maxTimeoutSeconds?: number;
|
|
26
|
+
}
|
|
27
|
+
interface PaymentMiddlewareConfig {
|
|
28
|
+
facilitator: FacilitatorConfig;
|
|
29
|
+
routes: Record<string, RouteConfig>;
|
|
30
|
+
}
|
|
31
|
+
interface RunHandlerOptions {
|
|
32
|
+
/** Handler timeout for this request; defaults to the adapter's 30 s. */
|
|
33
|
+
timeoutMs?: number;
|
|
34
|
+
}
|
|
35
|
+
interface RunHandlerResult {
|
|
36
|
+
status: number;
|
|
37
|
+
setResponseHeader(name: string, value: string): void;
|
|
38
|
+
/** Reads a header the handler set on its response (metered routes). */
|
|
39
|
+
getResponseHeader?(name: string): string | undefined;
|
|
40
|
+
/** Strips a header before the response leaves (metered routes). */
|
|
41
|
+
removeResponseHeader?(name: string): void;
|
|
42
|
+
sendResponse(): void;
|
|
43
|
+
discardResponse(): void;
|
|
44
|
+
}
|
|
45
|
+
interface HTTPAdapter {
|
|
46
|
+
getHeader(name: string): string | undefined;
|
|
47
|
+
getMethod(): string;
|
|
48
|
+
getPath(): string;
|
|
49
|
+
getUrl(): string;
|
|
50
|
+
runHandler?(options?: RunHandlerOptions): Promise<RunHandlerResult>;
|
|
51
|
+
}
|
|
52
|
+
interface ResourceInfo {
|
|
53
|
+
url: string;
|
|
54
|
+
description?: string;
|
|
55
|
+
mimeType?: string;
|
|
56
|
+
}
|
|
57
|
+
interface PaymentRequirements {
|
|
58
|
+
scheme: string;
|
|
59
|
+
network: string;
|
|
60
|
+
asset: string;
|
|
61
|
+
amount: string;
|
|
62
|
+
payTo: string;
|
|
63
|
+
maxTimeoutSeconds: number;
|
|
64
|
+
extra: Record<string, unknown>;
|
|
65
|
+
}
|
|
66
|
+
interface PaymentRequired {
|
|
67
|
+
x402Version: number;
|
|
68
|
+
error?: string;
|
|
69
|
+
resource: ResourceInfo;
|
|
70
|
+
accepts: PaymentRequirements[];
|
|
71
|
+
extensions?: Record<string, unknown>;
|
|
72
|
+
}
|
|
73
|
+
interface FacilitatorPaymentRequirements {
|
|
74
|
+
maxAmountRequired: string;
|
|
75
|
+
asset: string;
|
|
76
|
+
payTo: string;
|
|
77
|
+
network: string;
|
|
78
|
+
scheme?: "exact" | "upto";
|
|
79
|
+
maxTimeoutSeconds?: number;
|
|
80
|
+
}
|
|
81
|
+
/** Settle-time options — only metered (`upto`) routes use them. */
|
|
82
|
+
interface SettleOptions {
|
|
83
|
+
/** Amount actually charged, in the asset's smallest unit. */
|
|
84
|
+
amount?: string;
|
|
85
|
+
}
|
|
86
|
+
interface PaymentConfirmation {
|
|
87
|
+
success: true;
|
|
88
|
+
txHash: Address;
|
|
89
|
+
route: string;
|
|
90
|
+
chain: string;
|
|
91
|
+
gasSponsored: boolean;
|
|
92
|
+
networkId: string;
|
|
93
|
+
/** Amount actually charged (smallest unit) — metered routes only. */
|
|
94
|
+
amountSettled?: string;
|
|
95
|
+
}
|
|
96
|
+
interface PaymentFailure {
|
|
97
|
+
success: false;
|
|
98
|
+
error: {
|
|
99
|
+
code: string;
|
|
100
|
+
message: string;
|
|
101
|
+
hint?: string;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
type FacilitatorResponse = PaymentConfirmation | PaymentFailure;
|
|
105
|
+
interface MiddlewareResult {
|
|
106
|
+
status: number;
|
|
107
|
+
headers: Record<string, string>;
|
|
108
|
+
body: unknown;
|
|
109
|
+
}
|
|
110
|
+
interface PassResult {
|
|
111
|
+
pass: true;
|
|
112
|
+
handlerRan?: true;
|
|
113
|
+
}
|
|
114
|
+
type VerifiedPayment = {
|
|
115
|
+
type: "verified";
|
|
116
|
+
scheme: "exact" | "upto";
|
|
117
|
+
/** The verified amount (smallest unit): the price, or the cap for `upto`. */
|
|
118
|
+
maxAmount: bigint;
|
|
119
|
+
decimals: number;
|
|
120
|
+
/** How long the handler may run before the middleware gives up on it. */
|
|
121
|
+
handlerTimeoutMs: number;
|
|
122
|
+
settle(options?: SettleOptions): Promise<FacilitatorResponse>;
|
|
123
|
+
};
|
|
124
|
+
type PaymentGateResult = {
|
|
125
|
+
type: "pass";
|
|
126
|
+
} | {
|
|
127
|
+
type: "error";
|
|
128
|
+
result: MiddlewareResult;
|
|
129
|
+
} | VerifiedPayment;
|
|
130
|
+
|
|
131
|
+
export type { FacilitatorConfig as F, HTTPAdapter as H, MiddlewareResult as M, PaymentMiddlewareConfig as P, RunHandlerOptions as R, SettleOptions as S, VerifiedPayment as V, RunHandlerResult as a, FacilitatorPaymentRequirements as b, FacilitatorResponse as c, PaymentGateResult as d, PassResult as e, PaymentConfirmation as f, PaymentFailure as g, PaymentRequired as h, PaymentRequirements as i, ResourceInfo as j, RouteConfig as k };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parallel-protocol/x402",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Parallel Protocol x402 payment middleware — Express, Next.js, Fastify, Hono",
|
|
5
5
|
"author": "Parallel Protocol <contact@parallel.best>",
|
|
6
6
|
"repository": {
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"vitest": "^4.0.14"
|
|
124
124
|
},
|
|
125
125
|
"dependencies": {
|
|
126
|
-
"@parallel-protocol/chains": "^0.
|
|
126
|
+
"@parallel-protocol/chains": "^0.4.0",
|
|
127
127
|
"fastify-plugin": "^6.0.0",
|
|
128
128
|
"zod": "^4.4.3"
|
|
129
129
|
},
|
package/dist/chunk-2UEAVMCH.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// src/timeout.ts
|
|
2
|
-
var HANDLER_TIMEOUT_MS = 3e4;
|
|
3
|
-
var HANDLER_TIMEOUT = /* @__PURE__ */ Symbol("x402:handler-timeout");
|
|
4
|
-
async function raceTimeout(promise, ms = HANDLER_TIMEOUT_MS) {
|
|
5
|
-
let timer;
|
|
6
|
-
const timeout = new Promise((resolve) => {
|
|
7
|
-
timer = setTimeout(() => resolve(HANDLER_TIMEOUT), ms);
|
|
8
|
-
timer.unref?.();
|
|
9
|
-
});
|
|
10
|
-
try {
|
|
11
|
-
return await Promise.race([promise, timeout]);
|
|
12
|
-
} finally {
|
|
13
|
-
clearTimeout(timer);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export { HANDLER_TIMEOUT, raceTimeout };
|
package/dist/chunk-XUNNMCO5.cjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// src/timeout.ts
|
|
4
|
-
var HANDLER_TIMEOUT_MS = 3e4;
|
|
5
|
-
var HANDLER_TIMEOUT = /* @__PURE__ */ Symbol("x402:handler-timeout");
|
|
6
|
-
async function raceTimeout(promise, ms = HANDLER_TIMEOUT_MS) {
|
|
7
|
-
let timer;
|
|
8
|
-
const timeout = new Promise((resolve) => {
|
|
9
|
-
timer = setTimeout(() => resolve(HANDLER_TIMEOUT), ms);
|
|
10
|
-
timer.unref?.();
|
|
11
|
-
});
|
|
12
|
-
try {
|
|
13
|
-
return await Promise.race([promise, timeout]);
|
|
14
|
-
} finally {
|
|
15
|
-
clearTimeout(timer);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
exports.HANDLER_TIMEOUT = HANDLER_TIMEOUT;
|
|
20
|
-
exports.raceTimeout = raceTimeout;
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { Address } from 'viem';
|
|
2
|
-
|
|
3
|
-
interface FacilitatorConfig {
|
|
4
|
-
url: string;
|
|
5
|
-
apiKey?: string;
|
|
6
|
-
}
|
|
7
|
-
interface RouteConfig {
|
|
8
|
-
price: string | bigint;
|
|
9
|
-
decimals?: number;
|
|
10
|
-
network: string;
|
|
11
|
-
payTo: Address;
|
|
12
|
-
acceptedTokens?: Address[];
|
|
13
|
-
description?: string;
|
|
14
|
-
}
|
|
15
|
-
interface PaymentMiddlewareConfig {
|
|
16
|
-
facilitator: FacilitatorConfig;
|
|
17
|
-
routes: Record<string, RouteConfig>;
|
|
18
|
-
}
|
|
19
|
-
interface RunHandlerResult {
|
|
20
|
-
status: number;
|
|
21
|
-
setResponseHeader(name: string, value: string): void;
|
|
22
|
-
sendResponse(): void;
|
|
23
|
-
discardResponse(): void;
|
|
24
|
-
}
|
|
25
|
-
interface HTTPAdapter {
|
|
26
|
-
getHeader(name: string): string | undefined;
|
|
27
|
-
getMethod(): string;
|
|
28
|
-
getPath(): string;
|
|
29
|
-
getUrl(): string;
|
|
30
|
-
runHandler?(): Promise<RunHandlerResult>;
|
|
31
|
-
}
|
|
32
|
-
interface ResourceInfo {
|
|
33
|
-
url: string;
|
|
34
|
-
description?: string;
|
|
35
|
-
mimeType?: string;
|
|
36
|
-
}
|
|
37
|
-
interface PaymentRequirements {
|
|
38
|
-
scheme: string;
|
|
39
|
-
network: string;
|
|
40
|
-
asset: string;
|
|
41
|
-
amount: string;
|
|
42
|
-
payTo: string;
|
|
43
|
-
maxTimeoutSeconds: number;
|
|
44
|
-
extra: Record<string, unknown>;
|
|
45
|
-
}
|
|
46
|
-
interface PaymentRequired {
|
|
47
|
-
x402Version: number;
|
|
48
|
-
error?: string;
|
|
49
|
-
resource: ResourceInfo;
|
|
50
|
-
accepts: PaymentRequirements[];
|
|
51
|
-
extensions?: Record<string, unknown>;
|
|
52
|
-
}
|
|
53
|
-
interface FacilitatorPaymentRequirements {
|
|
54
|
-
maxAmountRequired: string;
|
|
55
|
-
asset: string;
|
|
56
|
-
payTo: string;
|
|
57
|
-
network: string;
|
|
58
|
-
}
|
|
59
|
-
interface PaymentConfirmation {
|
|
60
|
-
success: true;
|
|
61
|
-
txHash: Address;
|
|
62
|
-
route: string;
|
|
63
|
-
chain: string;
|
|
64
|
-
gasSponsored: boolean;
|
|
65
|
-
networkId: string;
|
|
66
|
-
}
|
|
67
|
-
interface PaymentFailure {
|
|
68
|
-
success: false;
|
|
69
|
-
error: {
|
|
70
|
-
code: string;
|
|
71
|
-
message: string;
|
|
72
|
-
hint?: string;
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
type FacilitatorResponse = PaymentConfirmation | PaymentFailure;
|
|
76
|
-
interface MiddlewareResult {
|
|
77
|
-
status: number;
|
|
78
|
-
headers: Record<string, string>;
|
|
79
|
-
body: unknown;
|
|
80
|
-
}
|
|
81
|
-
interface PassResult {
|
|
82
|
-
pass: true;
|
|
83
|
-
handlerRan?: true;
|
|
84
|
-
}
|
|
85
|
-
type PaymentGateResult = {
|
|
86
|
-
type: "pass";
|
|
87
|
-
} | {
|
|
88
|
-
type: "error";
|
|
89
|
-
result: MiddlewareResult;
|
|
90
|
-
} | {
|
|
91
|
-
type: "verified";
|
|
92
|
-
settle(): Promise<FacilitatorResponse>;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
export type { FacilitatorConfig as F, HTTPAdapter as H, MiddlewareResult as M, PaymentMiddlewareConfig as P, RunHandlerResult as R, FacilitatorPaymentRequirements as a, FacilitatorResponse as b, PaymentGateResult as c, PassResult as d, PaymentConfirmation as e, PaymentFailure as f, PaymentRequired as g, PaymentRequirements as h, ResourceInfo as i, RouteConfig as j };
|
package/dist/types-CUi55YSx.d.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { Address } from 'viem';
|
|
2
|
-
|
|
3
|
-
interface FacilitatorConfig {
|
|
4
|
-
url: string;
|
|
5
|
-
apiKey?: string;
|
|
6
|
-
}
|
|
7
|
-
interface RouteConfig {
|
|
8
|
-
price: string | bigint;
|
|
9
|
-
decimals?: number;
|
|
10
|
-
network: string;
|
|
11
|
-
payTo: Address;
|
|
12
|
-
acceptedTokens?: Address[];
|
|
13
|
-
description?: string;
|
|
14
|
-
}
|
|
15
|
-
interface PaymentMiddlewareConfig {
|
|
16
|
-
facilitator: FacilitatorConfig;
|
|
17
|
-
routes: Record<string, RouteConfig>;
|
|
18
|
-
}
|
|
19
|
-
interface RunHandlerResult {
|
|
20
|
-
status: number;
|
|
21
|
-
setResponseHeader(name: string, value: string): void;
|
|
22
|
-
sendResponse(): void;
|
|
23
|
-
discardResponse(): void;
|
|
24
|
-
}
|
|
25
|
-
interface HTTPAdapter {
|
|
26
|
-
getHeader(name: string): string | undefined;
|
|
27
|
-
getMethod(): string;
|
|
28
|
-
getPath(): string;
|
|
29
|
-
getUrl(): string;
|
|
30
|
-
runHandler?(): Promise<RunHandlerResult>;
|
|
31
|
-
}
|
|
32
|
-
interface ResourceInfo {
|
|
33
|
-
url: string;
|
|
34
|
-
description?: string;
|
|
35
|
-
mimeType?: string;
|
|
36
|
-
}
|
|
37
|
-
interface PaymentRequirements {
|
|
38
|
-
scheme: string;
|
|
39
|
-
network: string;
|
|
40
|
-
asset: string;
|
|
41
|
-
amount: string;
|
|
42
|
-
payTo: string;
|
|
43
|
-
maxTimeoutSeconds: number;
|
|
44
|
-
extra: Record<string, unknown>;
|
|
45
|
-
}
|
|
46
|
-
interface PaymentRequired {
|
|
47
|
-
x402Version: number;
|
|
48
|
-
error?: string;
|
|
49
|
-
resource: ResourceInfo;
|
|
50
|
-
accepts: PaymentRequirements[];
|
|
51
|
-
extensions?: Record<string, unknown>;
|
|
52
|
-
}
|
|
53
|
-
interface FacilitatorPaymentRequirements {
|
|
54
|
-
maxAmountRequired: string;
|
|
55
|
-
asset: string;
|
|
56
|
-
payTo: string;
|
|
57
|
-
network: string;
|
|
58
|
-
}
|
|
59
|
-
interface PaymentConfirmation {
|
|
60
|
-
success: true;
|
|
61
|
-
txHash: Address;
|
|
62
|
-
route: string;
|
|
63
|
-
chain: string;
|
|
64
|
-
gasSponsored: boolean;
|
|
65
|
-
networkId: string;
|
|
66
|
-
}
|
|
67
|
-
interface PaymentFailure {
|
|
68
|
-
success: false;
|
|
69
|
-
error: {
|
|
70
|
-
code: string;
|
|
71
|
-
message: string;
|
|
72
|
-
hint?: string;
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
type FacilitatorResponse = PaymentConfirmation | PaymentFailure;
|
|
76
|
-
interface MiddlewareResult {
|
|
77
|
-
status: number;
|
|
78
|
-
headers: Record<string, string>;
|
|
79
|
-
body: unknown;
|
|
80
|
-
}
|
|
81
|
-
interface PassResult {
|
|
82
|
-
pass: true;
|
|
83
|
-
handlerRan?: true;
|
|
84
|
-
}
|
|
85
|
-
type PaymentGateResult = {
|
|
86
|
-
type: "pass";
|
|
87
|
-
} | {
|
|
88
|
-
type: "error";
|
|
89
|
-
result: MiddlewareResult;
|
|
90
|
-
} | {
|
|
91
|
-
type: "verified";
|
|
92
|
-
settle(): Promise<FacilitatorResponse>;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
export type { FacilitatorConfig as F, HTTPAdapter as H, MiddlewareResult as M, PaymentMiddlewareConfig as P, RunHandlerResult as R, FacilitatorPaymentRequirements as a, FacilitatorResponse as b, PaymentGateResult as c, PassResult as d, PaymentConfirmation as e, PaymentFailure as f, PaymentRequired as g, PaymentRequirements as h, ResourceInfo as i, RouteConfig as j };
|