@parallel-protocol/x402 0.10.0 → 0.10.1

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/next.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkMYCUOJ3H_cjs = require('./chunk-MYCUOJ3H.cjs');
4
- require('./chunk-KZZY5LS6.cjs');
3
+ var chunkAYMDIX7A_cjs = require('./chunk-AYMDIX7A.cjs');
4
+ require('./chunk-4CEMNRCZ.cjs');
5
5
  var server = require('next/server');
6
6
 
7
7
  // src/next/adapter.ts
@@ -25,7 +25,7 @@ var NextAdapter = class {
25
25
  // Read from a clone: a request body is a stream that can be consumed once,
26
26
  // and the handler still needs the original.
27
27
  async getBody() {
28
- if (!chunkMYCUOJ3H_cjs.isJsonContentType(this.req.headers.get("content-type") ?? void 0))
28
+ if (!chunkAYMDIX7A_cjs.isJsonContentType(this.req.headers.get("content-type") ?? void 0))
29
29
  return void 0;
30
30
  try {
31
31
  return await this.req.clone().json();
@@ -43,20 +43,21 @@ function fromResult(result) {
43
43
  });
44
44
  }
45
45
  function withPayment(config, handler) {
46
- const gate = chunkMYCUOJ3H_cjs.createPaymentGate(config);
46
+ const gate = chunkAYMDIX7A_cjs.createPaymentGate(config);
47
47
  return async (req) => {
48
48
  const gateResult = await gate(new NextAdapter(req));
49
49
  if (gateResult.type === "pass") {
50
- return handler(req);
50
+ if (!gateResult.preflight) return handler(req);
51
+ return new server.NextResponse(null, { status: 204 });
51
52
  }
52
53
  if (gateResult.type === "error") return fromResult(gateResult.result);
53
54
  let response;
54
55
  try {
55
- const outcome = await chunkMYCUOJ3H_cjs.raceTimeout(
56
+ const outcome = await chunkAYMDIX7A_cjs.raceTimeout(
56
57
  handler(req),
57
58
  gateResult.handlerTimeoutMs
58
59
  );
59
- if (outcome === chunkMYCUOJ3H_cjs.HANDLER_TIMEOUT) {
60
+ if (outcome === chunkAYMDIX7A_cjs.HANDLER_TIMEOUT) {
60
61
  return new server.NextResponse(null, { status: 504 });
61
62
  }
62
63
  response = outcome;
@@ -65,10 +66,10 @@ function withPayment(config, handler) {
65
66
  }
66
67
  let raw;
67
68
  if (gateResult.scheme === "upto") {
68
- raw = response.headers.get(chunkMYCUOJ3H_cjs.SETTLE_AMOUNT_HEADER) ?? void 0;
69
+ raw = response.headers.get(chunkAYMDIX7A_cjs.SETTLE_AMOUNT_HEADER) ?? void 0;
69
70
  if (raw !== void 0) {
70
71
  const headers = new Headers(response.headers);
71
- headers.delete(chunkMYCUOJ3H_cjs.SETTLE_AMOUNT_HEADER);
72
+ headers.delete(chunkAYMDIX7A_cjs.SETTLE_AMOUNT_HEADER);
72
73
  response = new server.NextResponse(response.body, {
73
74
  status: response.status,
74
75
  headers
@@ -79,24 +80,24 @@ function withPayment(config, handler) {
79
80
  let settleOptions;
80
81
  if (gateResult.scheme === "upto") {
81
82
  const handled = response;
82
- const resolved = await chunkMYCUOJ3H_cjs.resolveCharge(gateResult, raw, {
83
+ const resolved = await chunkAYMDIX7A_cjs.resolveCharge(gateResult, raw, {
83
84
  status: handled.status,
84
85
  header: (name) => handled.headers.get(name) ?? void 0,
85
86
  // Read from a clone: the body streams once, to the client.
86
- body: () => chunkMYCUOJ3H_cjs.jsonFromResponse(handled)
87
+ body: () => chunkAYMDIX7A_cjs.jsonFromResponse(handled)
87
88
  });
88
89
  if (resolved.kind === "invalid") {
89
90
  handled.body?.cancel().catch(() => {
90
91
  });
91
- return fromResult(chunkMYCUOJ3H_cjs.invalidSettleAmountResponse(resolved.reason));
92
+ return fromResult(chunkAYMDIX7A_cjs.invalidSettleAmountResponse(resolved.reason));
92
93
  }
93
94
  if (resolved.kind === "skip") return response;
94
95
  settleOptions = { amount: resolved.amount };
95
96
  }
96
- const outcome = await chunkMYCUOJ3H_cjs.settleVerified(gateResult, settleOptions);
97
+ const outcome = await chunkAYMDIX7A_cjs.settleVerified(gateResult, settleOptions);
97
98
  if (outcome.settled) {
98
99
  const headers = new Headers(response.headers);
99
- headers.set("payment-response", chunkMYCUOJ3H_cjs.encodeBase64(outcome.confirmation));
100
+ headers.set("payment-response", chunkAYMDIX7A_cjs.encodeBase64(outcome.confirmation));
100
101
  headers.set("access-control-expose-headers", "payment-response");
101
102
  return new server.NextResponse(response.body, {
102
103
  status: response.status,
@@ -105,7 +106,7 @@ function withPayment(config, handler) {
105
106
  }
106
107
  response.body?.cancel().catch(() => {
107
108
  });
108
- return fromResult(chunkMYCUOJ3H_cjs.settlementFailureResponse(outcome));
109
+ return fromResult(chunkAYMDIX7A_cjs.settlementFailureResponse(outcome));
109
110
  }
110
111
  return response;
111
112
  };
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-BWL9h1eY.cjs';
2
+ import { H as HTTPAdapter, P as PaymentMiddlewareConfig } from './types-CRBMTQaq.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-BWL9h1eY.js';
2
+ import { H as HTTPAdapter, P as PaymentMiddlewareConfig } from './types-CRBMTQaq.js';
3
3
  import 'viem';
4
4
 
5
5
  declare class NextAdapter implements HTTPAdapter {
package/dist/next.js CHANGED
@@ -1,5 +1,5 @@
1
- import { isJsonContentType, createPaymentGate, raceTimeout, HANDLER_TIMEOUT, SETTLE_AMOUNT_HEADER, resolveCharge, jsonFromResponse, invalidSettleAmountResponse, settleVerified, encodeBase64, settlementFailureResponse } from './chunk-VSNDEQGS.js';
2
- import './chunk-QAECRSWF.js';
1
+ import { isJsonContentType, createPaymentGate, raceTimeout, HANDLER_TIMEOUT, SETTLE_AMOUNT_HEADER, resolveCharge, jsonFromResponse, invalidSettleAmountResponse, settleVerified, encodeBase64, settlementFailureResponse } from './chunk-CNASNROQ.js';
2
+ import './chunk-MZCHBBUN.js';
3
3
  import { NextResponse } from 'next/server';
4
4
 
5
5
  // src/next/adapter.ts
@@ -45,7 +45,8 @@ function withPayment(config, handler) {
45
45
  return async (req) => {
46
46
  const gateResult = await gate(new NextAdapter(req));
47
47
  if (gateResult.type === "pass") {
48
- return handler(req);
48
+ if (!gateResult.preflight) return handler(req);
49
+ return new NextResponse(null, { status: 204 });
49
50
  }
50
51
  if (gateResult.type === "error") return fromResult(gateResult.result);
51
52
  let response;
@@ -10,7 +10,14 @@ interface FacilitatorConfig {
10
10
  */
11
11
  interface PriceContext {
12
12
  method: string;
13
+ /** As the framework gives it, not normalized: compare `routePath` instead. */
13
14
  path: string;
15
+ /**
16
+ * The path the route matched, in the form routes are matched on: under an
17
+ * Express mount, the full path when the key is written with it. Set by the
18
+ * middleware.
19
+ */
20
+ routePath?: string;
14
21
  url: string;
15
22
  header(name: string): string | undefined;
16
23
  body: unknown;
@@ -95,6 +102,8 @@ interface HTTPAdapter {
95
102
  getHeader(name: string): string | undefined;
96
103
  getMethod(): string;
97
104
  getPath(): string;
105
+ /** The path with the prefix a mount stripped from `getPath()`. */
106
+ getFullPath?(): string;
98
107
  getUrl(): string;
99
108
  /** The parsed request body, for routes priced per request. */
100
109
  getBody?(): Promise<unknown>;
@@ -201,6 +210,8 @@ interface MiddlewareResult {
201
210
  interface PassResult {
202
211
  pass: true;
203
212
  handlerRan?: true;
213
+ /** An OPTIONS on a paid route: send only the handler's status and CORS headers. */
214
+ preflight?: true;
204
215
  }
205
216
  type VerifiedPayment = {
206
217
  type: "verified";
@@ -217,6 +228,7 @@ type VerifiedPayment = {
217
228
  };
218
229
  type PaymentGateResult = {
219
230
  type: "pass";
231
+ preflight?: true;
220
232
  } | {
221
233
  type: "error";
222
234
  result: MiddlewareResult;
@@ -10,7 +10,14 @@ interface FacilitatorConfig {
10
10
  */
11
11
  interface PriceContext {
12
12
  method: string;
13
+ /** As the framework gives it, not normalized: compare `routePath` instead. */
13
14
  path: string;
15
+ /**
16
+ * The path the route matched, in the form routes are matched on: under an
17
+ * Express mount, the full path when the key is written with it. Set by the
18
+ * middleware.
19
+ */
20
+ routePath?: string;
14
21
  url: string;
15
22
  header(name: string): string | undefined;
16
23
  body: unknown;
@@ -95,6 +102,8 @@ interface HTTPAdapter {
95
102
  getHeader(name: string): string | undefined;
96
103
  getMethod(): string;
97
104
  getPath(): string;
105
+ /** The path with the prefix a mount stripped from `getPath()`. */
106
+ getFullPath?(): string;
98
107
  getUrl(): string;
99
108
  /** The parsed request body, for routes priced per request. */
100
109
  getBody?(): Promise<unknown>;
@@ -201,6 +210,8 @@ interface MiddlewareResult {
201
210
  interface PassResult {
202
211
  pass: true;
203
212
  handlerRan?: true;
213
+ /** An OPTIONS on a paid route: send only the handler's status and CORS headers. */
214
+ preflight?: true;
204
215
  }
205
216
  type VerifiedPayment = {
206
217
  type: "verified";
@@ -217,6 +228,7 @@ type VerifiedPayment = {
217
228
  };
218
229
  type PaymentGateResult = {
219
230
  type: "pass";
231
+ preflight?: true;
220
232
  } | {
221
233
  type: "error";
222
234
  result: MiddlewareResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parallel-protocol/x402",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "Parallel Protocol x402 payment middleware — Express, Next.js, Fastify, Hono",
5
5
  "author": "Parallel Protocol <contact@parallel.best>",
6
6
  "repository": {
@@ -124,6 +124,7 @@
124
124
  "devDependencies": {
125
125
  "@types/express": "^5.0.1",
126
126
  "@types/node": "^22.0.0",
127
+ "express": "^5.3.0",
127
128
  "fastify": "^5.12.7",
128
129
  "hono": "^4.0.0",
129
130
  "next": "^15.0.0",