@parallel-protocol/mpp 0.2.1 → 0.2.2

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/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { MppChargeCredential } from '@parallel-protocol/mpp-types';
2
2
  export { MppChargeCredential, MppReceipt, decodeBase64Url, encodeBase64Url } from '@parallel-protocol/mpp-types';
3
- import { a as MppRouteConfig, b as MppFacilitatorConfig, c as MppSettleResult, M as MppMiddlewareConfig, H as HTTPAdapter, P as PaymentGateResult, d as MiddlewareResult, e as PassResult } from './types-CCE-FI8i.js';
4
- export { f as MppSettleFailure, g as MppSettleSuccess, R as RunHandlerResult } from './types-CCE-FI8i.js';
3
+ import { a as MppRouteConfig, b as MppFacilitatorConfig, c as MppSettleResult, M as MppMiddlewareConfig, H as HTTPAdapter, P as PaymentGateResult, d as MiddlewareResult, e as PassResult } from './types-BSzM92sD.js';
4
+ export { f as MppSettleFailure, g as MppSettleSuccess, R as RunHandlerResult } from './types-BSzM92sD.js';
5
5
  import 'viem';
6
6
 
7
7
  /** The challenge echoed back inside a credential (derived — mpp-types has no standalone export). */
@@ -39,6 +39,8 @@ declare const MPP_ERROR_CODES: {
39
39
  readonly FACILITATOR_UNAVAILABLE: "FACILITATOR_UNAVAILABLE";
40
40
  readonly FACILITATOR_INVALID_RESPONSE: "FACILITATOR_INVALID_RESPONSE";
41
41
  readonly INVALID_CREDENTIAL: "INVALID_CREDENTIAL";
42
+ /** A path with `.` or `..` segments on a paid route, refused with 400. */
43
+ readonly INVALID_PATH: "INVALID_PATH";
42
44
  readonly METHOD_MISMATCH: "METHOD_MISMATCH";
43
45
  };
44
46
  type MppErrorCode = (typeof MPP_ERROR_CODES)[keyof typeof MPP_ERROR_CODES];
@@ -50,13 +52,14 @@ declare class MppRuntimeError extends Error {
50
52
  constructor(code: string);
51
53
  }
52
54
 
53
- declare function createMppPaymentGate(config: MppMiddlewareConfig): (adapter: Pick<HTTPAdapter, "getHeader" | "getPath" | "getUrl" | "getMethod">) => Promise<PaymentGateResult>;
55
+ declare function createMppPaymentGate(config: MppMiddlewareConfig): (adapter: Pick<HTTPAdapter, "getHeader" | "getPath" | "getFullPath" | "getUrl" | "getMethod">) => Promise<PaymentGateResult>;
54
56
  declare function createMppPaymentMiddleware(config: MppMiddlewareConfig): (adapter: HTTPAdapter) => Promise<MiddlewareResult | PassResult>;
55
57
 
56
58
  /** Parse a human price ("0.01") or pass a bigint through. Default 6 decimals (stablecoins). */
57
59
  declare function parsePrice(price: string | bigint, decimals?: number): bigint;
58
60
  /** Resolve an EVM chain id from a chain slug via the static catalogue. */
59
61
  declare function chainIdFromSlug(network: string): number | undefined;
62
+ /** The route a request path falls under, see `findRoute`. */
60
63
  declare function matchRoute<T>(path: string, routes: Record<string, T>): T | undefined;
61
64
 
62
65
  export { HTTPAdapter, MPP_ERROR_CODES, MiddlewareResult, type MppChallenge, MppConfigError, type MppErrorCode, MppFacilitatorClient, MppFacilitatorConfig, MppMiddlewareConfig, MppRouteConfig, MppRuntimeError, MppSettleResult, PassResult, PaymentGateResult, buildChallenge, chainIdFromSlug, createMppPaymentGate, createMppPaymentMiddleware, matchRoute, parseAuthorizationHeader, parsePrice, serializeChallenge };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { MPP_ERROR_CODES, MppConfigError, MppFacilitatorClient, MppRuntimeError, buildChallenge, chainIdFromSlug, createMppPaymentGate, createMppPaymentMiddleware, matchRoute, parseAuthorizationHeader, parsePrice, serializeChallenge } from './chunk-CQ62EEHN.js';
1
+ export { MPP_ERROR_CODES, MppConfigError, MppFacilitatorClient, MppRuntimeError, buildChallenge, chainIdFromSlug, createMppPaymentGate, createMppPaymentMiddleware, matchRoute, parseAuthorizationHeader, parsePrice, serializeChallenge } from './chunk-BYNIZG5S.js';
2
2
  export { decodeBase64Url, encodeBase64Url } from '@parallel-protocol/mpp-types';
package/dist/next.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkRNM3RDKR_cjs = require('./chunk-RNM3RDKR.cjs');
4
- var chunkMEDPOLT4_cjs = require('./chunk-MEDPOLT4.cjs');
4
+ var chunk76KPBYGA_cjs = require('./chunk-76KPBYGA.cjs');
5
5
  var mppTypes = require('@parallel-protocol/mpp-types');
6
6
  var server = require('next/server');
7
7
 
@@ -27,11 +27,12 @@ var NextAdapter = class {
27
27
 
28
28
  // src/next/index.ts
29
29
  function withPayment(config, handler) {
30
- const gate = chunkMEDPOLT4_cjs.createMppPaymentGate(config);
30
+ const gate = chunk76KPBYGA_cjs.createMppPaymentGate(config);
31
31
  return async (req) => {
32
32
  const gateResult = await gate(new NextAdapter(req));
33
33
  if (gateResult.type === "pass") {
34
- return handler(req);
34
+ if (!gateResult.preflight) return handler(req);
35
+ return new server.NextResponse(null, { status: 204 });
35
36
  }
36
37
  if (gateResult.type === "error") {
37
38
  return new server.NextResponse(JSON.stringify(gateResult.result.body), {
@@ -52,7 +53,7 @@ function withPayment(config, handler) {
52
53
  } catch {
53
54
  return new server.NextResponse(null, { status: 504 });
54
55
  }
55
- if (chunkMEDPOLT4_cjs.isSuccessStatus(response.status)) {
56
+ if (chunk76KPBYGA_cjs.isSuccessStatus(response.status)) {
56
57
  try {
57
58
  const settleResponse = await gateResult.settle();
58
59
  if (settleResponse.success) {
@@ -69,7 +70,9 @@ function withPayment(config, handler) {
69
70
  }
70
71
  } catch {
71
72
  }
72
- return server.NextResponse.json(chunkMEDPOLT4_cjs.SETTLE_FAILURE_BODY, { status: 402 });
73
+ response.body?.cancel().catch(() => {
74
+ });
75
+ return server.NextResponse.json(chunk76KPBYGA_cjs.SETTLE_FAILURE_BODY, { status: 402 });
73
76
  }
74
77
  return response;
75
78
  };
package/dist/next.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
- import { H as HTTPAdapter, M as MppMiddlewareConfig } from './types-CCE-FI8i.cjs';
2
+ import { H as HTTPAdapter, M as MppMiddlewareConfig } from './types-BSzM92sD.cjs';
3
3
  import '@parallel-protocol/mpp-types';
4
4
  import 'viem';
5
5
 
package/dist/next.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
- import { H as HTTPAdapter, M as MppMiddlewareConfig } from './types-CCE-FI8i.js';
2
+ import { H as HTTPAdapter, M as MppMiddlewareConfig } from './types-BSzM92sD.js';
3
3
  import '@parallel-protocol/mpp-types';
4
4
  import 'viem';
5
5
 
package/dist/next.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { raceTimeout, HANDLER_TIMEOUT } from './chunk-DXHOWEAQ.js';
2
- import { createMppPaymentGate, isSuccessStatus, SETTLE_FAILURE_BODY } from './chunk-CQ62EEHN.js';
2
+ import { createMppPaymentGate, isSuccessStatus, SETTLE_FAILURE_BODY } from './chunk-BYNIZG5S.js';
3
3
  import { encodeBase64Url } from '@parallel-protocol/mpp-types';
4
4
  import { NextResponse } from 'next/server';
5
5
 
@@ -29,7 +29,8 @@ function withPayment(config, handler) {
29
29
  return async (req) => {
30
30
  const gateResult = await gate(new NextAdapter(req));
31
31
  if (gateResult.type === "pass") {
32
- return handler(req);
32
+ if (!gateResult.preflight) return handler(req);
33
+ return new NextResponse(null, { status: 204 });
33
34
  }
34
35
  if (gateResult.type === "error") {
35
36
  return new NextResponse(JSON.stringify(gateResult.result.body), {
@@ -67,6 +68,8 @@ function withPayment(config, handler) {
67
68
  }
68
69
  } catch {
69
70
  }
71
+ response.body?.cancel().catch(() => {
72
+ });
70
73
  return NextResponse.json(SETTLE_FAILURE_BODY, { status: 402 });
71
74
  }
72
75
  return response;
@@ -44,6 +44,8 @@ interface HTTPAdapter {
44
44
  getHeader(name: string): string | undefined;
45
45
  getMethod(): string;
46
46
  getPath(): string;
47
+ /** The path with the prefix a mount stripped from `getPath()`. */
48
+ getFullPath?(): string;
47
49
  getUrl(): string;
48
50
  runHandler?(): Promise<RunHandlerResult>;
49
51
  }
@@ -67,9 +69,12 @@ interface MiddlewareResult {
67
69
  interface PassResult {
68
70
  pass: true;
69
71
  handlerRan?: true;
72
+ /** An OPTIONS on a paid route: send only the handler's status and CORS headers. */
73
+ preflight?: true;
70
74
  }
71
75
  type PaymentGateResult = {
72
76
  type: "pass";
77
+ preflight?: true;
73
78
  } | {
74
79
  type: "error";
75
80
  result: MiddlewareResult;
@@ -44,6 +44,8 @@ interface HTTPAdapter {
44
44
  getHeader(name: string): string | undefined;
45
45
  getMethod(): string;
46
46
  getPath(): string;
47
+ /** The path with the prefix a mount stripped from `getPath()`. */
48
+ getFullPath?(): string;
47
49
  getUrl(): string;
48
50
  runHandler?(): Promise<RunHandlerResult>;
49
51
  }
@@ -67,9 +69,12 @@ interface MiddlewareResult {
67
69
  interface PassResult {
68
70
  pass: true;
69
71
  handlerRan?: true;
72
+ /** An OPTIONS on a paid route: send only the handler's status and CORS headers. */
73
+ preflight?: true;
70
74
  }
71
75
  type PaymentGateResult = {
72
76
  type: "pass";
77
+ preflight?: true;
73
78
  } | {
74
79
  type: "error";
75
80
  result: MiddlewareResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parallel-protocol/mpp",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Parallel Protocol MPP (Machine Payments Protocol) merchant middleware — the Payment HTTP auth-scheme dance (402 challenge → credential → receipt) over the facilitator's /mpp endpoints",
5
5
  "author": "Parallel Protocol <contact@parallel.best>",
6
6
  "repository": "github:parallel-protocol/sdk-merchant",
@@ -109,6 +109,7 @@
109
109
  "devDependencies": {
110
110
  "@types/express": "^5.0.1",
111
111
  "@types/node": "^22.0.0",
112
+ "express": "^5.3.0",
112
113
  "fastify": "^5.12.7",
113
114
  "hono": "^4.0.0",
114
115
  "next": "^15.0.0",