@puga-labs/x402-mantle-sdk 0.3.1 → 0.3.3

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.
Files changed (71) hide show
  1. package/dist/{chunk-HTZ3QFY4.js → chunk-23QNUJIB.js} +4 -3
  2. package/dist/chunk-CXRILT3C.js +68 -0
  3. package/dist/{chunk-CTI5CRDY.js → chunk-E46A7I6B.js} +1 -1
  4. package/dist/{chunk-XAQGMFSR.js → chunk-HEZZ74SI.js} +6 -0
  5. package/dist/chunk-NQWSCY44.js +70 -0
  6. package/dist/chunk-PCJEJYP6.js +68 -0
  7. package/dist/chunk-PPVS3X5Z.js +99 -0
  8. package/dist/chunk-QWQUSRLY.js +99 -0
  9. package/dist/chunk-U73CZU3X.js +237 -0
  10. package/dist/chunk-WO2MYZXT.js +0 -0
  11. package/dist/chunk-ZLCKBFVJ.js +237 -0
  12. package/dist/chunk-ZROK2XOB.js +70 -0
  13. package/dist/client.d.cts +4 -4
  14. package/dist/client.d.ts +4 -4
  15. package/dist/client.js +2 -2
  16. package/dist/{constants-CVFF0ray.d.ts → constants-0ncqvV_O.d.ts} +1 -1
  17. package/dist/{constants-DzCGK0Q3.d.cts → constants-CsIL25uQ.d.cts} +1 -1
  18. package/dist/{createMantleClient-NN0Nitp9.d.cts → createMantleClient-CO0uWPb-.d.cts} +1 -1
  19. package/dist/{createMantleClient-DVFkbBfS.d.ts → createMantleClient-CuiPsTa6.d.ts} +1 -1
  20. package/dist/express-D8EwEcOL.d.ts +66 -0
  21. package/dist/express-eQOPxfnI.d.cts +66 -0
  22. package/dist/index.cjs +186 -109
  23. package/dist/index.d.cts +6 -4
  24. package/dist/index.d.ts +6 -4
  25. package/dist/index.js +6 -4
  26. package/dist/nextjs-Duecps0q.d.cts +45 -0
  27. package/dist/nextjs-TFhFiQuL.d.ts +45 -0
  28. package/dist/react.cjs +3 -2
  29. package/dist/react.d.cts +7 -4
  30. package/dist/react.d.ts +7 -4
  31. package/dist/react.js +3 -3
  32. package/dist/server-express.cjs +368 -0
  33. package/dist/server-express.d.cts +5 -0
  34. package/dist/server-express.d.ts +5 -0
  35. package/dist/server-express.js +13 -0
  36. package/dist/server-nextjs.cjs +339 -0
  37. package/dist/server-nextjs.d.cts +5 -0
  38. package/dist/server-nextjs.d.ts +5 -0
  39. package/dist/server-nextjs.js +11 -0
  40. package/dist/server-web.cjs +339 -0
  41. package/dist/server-web.d.cts +4 -0
  42. package/dist/server-web.d.ts +4 -0
  43. package/dist/server-web.js +11 -0
  44. package/dist/server.cjs +316 -111
  45. package/dist/server.d.cts +67 -104
  46. package/dist/server.d.ts +67 -104
  47. package/dist/server.js +29 -5
  48. package/dist/{types-2zqbJvcz.d.cts → types-BFUqKBBO.d.cts} +1 -1
  49. package/dist/{types-2zqbJvcz.d.ts → types-BFUqKBBO.d.ts} +1 -1
  50. package/dist/types-CoOdbZSp.d.cts +97 -0
  51. package/dist/types-CqQ6OgRi.d.ts +85 -0
  52. package/dist/types-CrOsOHcX.d.cts +85 -0
  53. package/dist/types-DTzov_EE.d.ts +97 -0
  54. package/dist/web-standards-BNQyWzBC.d.cts +77 -0
  55. package/dist/web-standards-D8j1kZxd.d.ts +77 -0
  56. package/package.json +49 -2
  57. package/dist/chunk-DA6ZBXNO.js +0 -275
  58. package/dist/chunk-FD4HG7KR.js +0 -135
  59. package/dist/chunk-GWVWPS3R.js +0 -277
  60. package/dist/chunk-MQALBRGV.js +0 -135
  61. package/dist/chunk-PYIYE3HI.js +0 -135
  62. package/dist/chunk-Q6SPMEIW.js +0 -235
  63. package/dist/chunk-RNKXSBT7.js +0 -135
  64. package/dist/chunk-SPCXFN7C.js +0 -284
  65. package/dist/chunk-T5DRYLNB.js +0 -135
  66. package/dist/chunk-TSEE5NSJ.js +0 -297
  67. package/dist/chunk-WELDWRDX.js +0 -307
  68. package/dist/constants-C7aY8u5b.d.cts +0 -77
  69. package/dist/constants-C7aY8u5b.d.ts +0 -77
  70. package/dist/createMantleClient-DS1Ghqrz.d.cts +0 -51
  71. package/dist/createMantleClient-DS1Ghqrz.d.ts +0 -51
package/dist/server.d.ts CHANGED
@@ -1,116 +1,79 @@
1
- import { Request, Response, NextFunction } from 'express';
2
- import { N as NetworkId, P as PaymentRequirements } from './types-2zqbJvcz.js';
3
- export { A as AssetConfig, a as Authorization, E as EIP1193Provider, d as PaymentHeaderBase64, c as PaymentHeaderObject, b as PaymentHeaderPayload } from './types-2zqbJvcz.js';
4
- export { M as MANTLE_DEFAULTS } from './constants-CVFF0ray.js';
1
+ import { c as PaymentCheckInput, d as PaymentCheckResult } from './types-CqQ6OgRi.js';
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
+ import { c as PaymentHeaderObject } from './types-BFUqKBBO.js';
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-TFhFiQuL.js';
6
+ export { w as web } from './web-standards-D8j1kZxd.js';
7
+ import { P as PaymentLogEntry, T as TelemetryConfig, c as TelemetryEvent } from './types-DTzov_EE.js';
8
+ import 'express';
9
+ import 'next/server';
5
10
 
6
- /** Unique key for a protected route, e.g. "GET /api/protected". */
7
- type RouteKey = string;
8
- /** Pricing config for a single route. */
9
- interface RoutePricingConfig {
10
- /** Price in USD cents, e.g. 1 => $0.01. */
11
- priceUsdCents: number;
12
- /** Network identifier (e.g. "mantle-mainnet"). */
13
- network: NetworkId;
14
- }
15
- /** Map of route keys to pricing config. */
16
- type RoutesConfig = Record<RouteKey, RoutePricingConfig>;
17
- /** Log entry for a successfully settled payment. */
18
- interface PaymentLogEntry {
19
- id: string;
20
- from: string;
21
- to: string;
22
- valueAtomic: string;
23
- network: NetworkId;
24
- asset: string;
25
- route?: RouteKey;
26
- txHash?: string;
27
- timestamp: number;
28
- facilitatorUrl?: string;
29
- paymentRequirements?: PaymentRequirements;
30
- }
31
- /** Config for optional telemetry (billing/analytics). */
32
- interface TelemetryConfig {
33
- /** Project key from nosubs.ai dashboard. */
34
- projectKey: string;
35
- /**
36
- * Telemetry endpoint URL.
37
- * If not specified, uses DEFAULT_TELEMETRY_ENDPOINT (see server/constants.ts).
38
- * If both are undefined, telemetry is not sent.
39
- */
40
- endpoint?: string;
41
- }
42
- /** Telemetry event payload for payment_verified. */
43
- interface TelemetryEvent {
44
- event: "payment_verified";
45
- ts: number;
46
- projectKey: string;
47
- network: string;
48
- buyer: string;
49
- payTo: string;
50
- amountAtomic: string;
51
- asset: string;
52
- decimals: number;
53
- nonce: string;
54
- route: string;
55
- facilitatorType: "hosted" | "self-hosted";
56
- facilitatorUrl?: string;
57
- facilitatorAddress?: string;
58
- txHash?: string;
59
- priceUsd?: string;
60
- }
61
- /** Config for createPaymentMiddleware. */
62
- interface PaymentMiddlewareConfig {
63
- /** Base URL of facilitator, e.g. https://facilitator.nosubs.ai */
64
- facilitatorUrl: string;
65
- /** Recipient address (developer). */
66
- receiverAddress: `0x${string}`;
67
- /** Map of protected routes and their pricing. */
68
- routes: RoutesConfig;
69
- /**
70
- * Optional hook called whenever a payment is successfully settled.
71
- * You can use this to push logs into your DB / analytics pipeline.
72
- */
73
- onPaymentSettled?: (entry: PaymentLogEntry) => void;
74
- /** Optional: Send usage telemetry for billing/analytics. */
75
- telemetry?: TelemetryConfig;
76
- }
77
11
  /**
78
- * Minimal config for mantlePaywall() - simplified API for single-route protection.
79
- * This is the "sweet path" for Mantle mainnet + USDC with sensible defaults.
12
+ * Validate Ethereum address format.
13
+ * Throws descriptive error if invalid.
14
+ *
15
+ * @param address - Address to validate
16
+ * @param paramName - Parameter name for error messages (default: "address")
17
+ * @throws Error if address is invalid
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * validateAddress("0x1234567890123456789012345678901234567890", "payTo");
22
+ * // Valid - no error thrown
23
+ *
24
+ * validateAddress("invalid", "payTo");
25
+ * // Throws: "payTo must start with \"0x\"..."
26
+ * ```
80
27
  */
81
- interface MinimalPaywallOptions {
82
- /** Price in USD (e.g. 0.01 for 1 cent). */
83
- priceUsd: number;
84
- /** Recipient address (developer wallet). */
85
- payTo: `0x${string}`;
86
- /** Optional facilitator URL (defaults to localhost:8080 or NEXT_PUBLIC_FACILITATOR_URL). */
87
- facilitatorUrl?: string;
88
- /** Optional telemetry config. */
89
- telemetry?: TelemetryConfig;
90
- /** Optional payment settled hook. */
91
- onPaymentSettled?: (entry: PaymentLogEntry) => void;
92
- }
28
+ declare function validateAddress(address: string, paramName?: string): void;
93
29
  /**
94
- * Express middleware function type for Mantle paywall.
95
- * Async function that returns Promise<void>.
30
+ * Decode base64 payment header into JSON object.
31
+ * Works in both Node.js and browser environments.
96
32
  */
97
- type MantleMiddleware = (req: Request, res: Response, next: NextFunction) => Promise<void>;
33
+ declare function decodePaymentHeader(paymentHeaderBase64: string): PaymentHeaderObject;
34
+ /**
35
+ * Build a route key from HTTP method and path.
36
+ * @param method - HTTP method (GET, POST, etc.)
37
+ * @param path - URL path (e.g. "/api/protected")
38
+ * @returns Route key string (e.g. "POST /api/protected")
39
+ */
40
+ declare function buildRouteKey(method: string, path: string): string;
98
41
 
99
- declare function createPaymentMiddleware(config: PaymentMiddlewareConfig): (req: Request, res: Response, next: NextFunction) => Promise<void>;
42
+ /**
43
+ * Check payment header and verify with facilitator.
44
+ * This function is framework-agnostic and can be used with any HTTP framework.
45
+ *
46
+ * @param input - Payment check configuration
47
+ * @returns Result indicating whether to allow access or return error response
48
+ */
49
+ declare function checkPayment(input: PaymentCheckInput): Promise<PaymentCheckResult>;
100
50
 
101
51
  /**
102
- * Simplified wrapper for protecting a single route with x402 payments.
103
- * Uses Mantle mainnet defaults (USDC, exact scheme, etc.).
52
+ * Default telemetry endpoint URL.
104
53
  *
105
- * Usage:
106
- * ```typescript
107
- * const pay = mantlePaywall({ priceUsd: 0.01, payTo: "0x..." });
108
- * export const POST = pay(async (req) => { ... });
109
- * ```
54
+ * Set to a valid URL when the official analytics backend is ready.
55
+ * If undefined, telemetry will only be sent if explicitly configured
56
+ * via TelemetryConfig.endpoint.
57
+ */
58
+ declare const DEFAULT_TELEMETRY_ENDPOINT: string | undefined;
59
+
60
+ /**
61
+ * Converts PaymentLogEntry to TelemetryEvent.
62
+ *
63
+ * This function transforms the internal PaymentLogEntry format
64
+ * to the telemetry event format expected by the analytics backend.
65
+ */
66
+ declare function createTelemetryEvent(entry: PaymentLogEntry, config: TelemetryConfig): TelemetryEvent;
67
+ /**
68
+ * Sends telemetry event to endpoint (fire-and-forget).
69
+ *
70
+ * This function sends the telemetry event asynchronously and never throws.
71
+ * Errors are logged but never propagate to the caller, ensuring that
72
+ * telemetry failures never break the payment flow.
110
73
  *
111
- * @param opts - Minimal configuration (price, payTo, optional facilitator/telemetry).
112
- * @returns Express middleware function for single-route protection.
74
+ * @param event - The telemetry event to send
75
+ * @param endpoint - The telemetry endpoint URL (optional, falls back to DEFAULT_TELEMETRY_ENDPOINT)
113
76
  */
114
- declare function mantlePaywall(opts: MinimalPaywallOptions): MantleMiddleware;
77
+ declare function sendTelemetry(event: TelemetryEvent, endpoint?: string): Promise<void>;
115
78
 
116
- export { type MantleMiddleware, type MinimalPaywallOptions, NetworkId, type PaymentLogEntry, type PaymentMiddlewareConfig, PaymentRequirements, type RouteKey, type RoutePricingConfig, type RoutesConfig, type TelemetryConfig, type TelemetryEvent, createPaymentMiddleware, mantlePaywall };
79
+ export { DEFAULT_TELEMETRY_ENDPOINT, PaymentCheckInput, PaymentCheckResult, buildRouteKey, checkPayment, createTelemetryEvent, decodePaymentHeader, sendTelemetry, validateAddress };
package/dist/server.js CHANGED
@@ -1,12 +1,36 @@
1
+ import "./chunk-WO2MYZXT.js";
1
2
  import {
2
3
  createPaymentMiddleware,
4
+ express_exports,
3
5
  mantlePaywall
4
- } from "./chunk-Q6SPMEIW.js";
6
+ } from "./chunk-QWQUSRLY.js";
5
7
  import {
6
- MANTLE_DEFAULTS
7
- } from "./chunk-XAQGMFSR.js";
8
+ nextjs_exports
9
+ } from "./chunk-CXRILT3C.js";
10
+ import {
11
+ web_standards_exports
12
+ } from "./chunk-ZROK2XOB.js";
13
+ import {
14
+ DEFAULT_TELEMETRY_ENDPOINT,
15
+ buildRouteKey,
16
+ checkPayment,
17
+ createTelemetryEvent,
18
+ decodePaymentHeader,
19
+ sendTelemetry,
20
+ validateAddress
21
+ } from "./chunk-ZLCKBFVJ.js";
22
+ import "./chunk-HEZZ74SI.js";
8
23
  export {
9
- MANTLE_DEFAULTS,
24
+ DEFAULT_TELEMETRY_ENDPOINT,
25
+ buildRouteKey,
26
+ checkPayment,
10
27
  createPaymentMiddleware,
11
- mantlePaywall
28
+ createTelemetryEvent,
29
+ decodePaymentHeader,
30
+ express_exports as express,
31
+ mantlePaywall,
32
+ nextjs_exports as nextjs,
33
+ sendTelemetry,
34
+ validateAddress,
35
+ web_standards_exports as web
12
36
  };
@@ -12,7 +12,7 @@ interface PaymentRequirements {
12
12
  network: NetworkId;
13
13
  asset: string;
14
14
  maxAmountRequired: string;
15
- payTo: `0x${string}`;
15
+ payTo: string;
16
16
  price?: string;
17
17
  currency?: string;
18
18
  }
@@ -12,7 +12,7 @@ interface PaymentRequirements {
12
12
  network: NetworkId;
13
13
  asset: string;
14
14
  maxAmountRequired: string;
15
- payTo: `0x${string}`;
15
+ payTo: string;
16
16
  price?: string;
17
17
  currency?: string;
18
18
  }
@@ -0,0 +1,97 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ import { N as NetworkId, P as PaymentRequirements } from './types-BFUqKBBO.cjs';
3
+
4
+ /** Unique key for a protected route, e.g. "GET /api/protected". */
5
+ type RouteKey = string;
6
+ /** Pricing config for a single route. */
7
+ interface RoutePricingConfig {
8
+ /** Price in USD cents, e.g. 1 => $0.01. */
9
+ priceUsdCents: number;
10
+ /** Network identifier (e.g. "mantle-mainnet"). */
11
+ network: NetworkId;
12
+ }
13
+ /** Map of route keys to pricing config. */
14
+ type RoutesConfig = Record<RouteKey, RoutePricingConfig>;
15
+ /** Log entry for a successfully settled payment. */
16
+ interface PaymentLogEntry {
17
+ id: string;
18
+ from: string;
19
+ to: string;
20
+ valueAtomic: string;
21
+ network: NetworkId;
22
+ asset: string;
23
+ route?: RouteKey;
24
+ txHash?: string;
25
+ timestamp: number;
26
+ facilitatorUrl?: string;
27
+ paymentRequirements?: PaymentRequirements;
28
+ }
29
+ /** Config for optional telemetry (billing/analytics). */
30
+ interface TelemetryConfig {
31
+ /** Project key from nosubs.ai dashboard. */
32
+ projectKey: string;
33
+ /**
34
+ * Telemetry endpoint URL.
35
+ * If not specified, uses DEFAULT_TELEMETRY_ENDPOINT (see server/constants.ts).
36
+ * If both are undefined, telemetry is not sent.
37
+ */
38
+ endpoint?: string;
39
+ }
40
+ /** Telemetry event payload for payment_verified. */
41
+ interface TelemetryEvent {
42
+ event: "payment_verified";
43
+ ts: number;
44
+ projectKey: string;
45
+ network: string;
46
+ buyer: string;
47
+ payTo: string;
48
+ amountAtomic: string;
49
+ asset: string;
50
+ decimals: number;
51
+ nonce: string;
52
+ route: string;
53
+ facilitatorType: "hosted" | "self-hosted";
54
+ facilitatorUrl?: string;
55
+ facilitatorAddress?: string;
56
+ txHash?: string;
57
+ priceUsd?: string;
58
+ }
59
+ /** Config for createPaymentMiddleware. */
60
+ interface PaymentMiddlewareConfig {
61
+ /** Base URL of facilitator, e.g. https://facilitator.nosubs.ai */
62
+ facilitatorUrl: string;
63
+ /** Recipient address (developer). Validated at runtime. */
64
+ receiverAddress: string;
65
+ /** Map of protected routes and their pricing. */
66
+ routes: RoutesConfig;
67
+ /**
68
+ * Optional hook called whenever a payment is successfully settled.
69
+ * You can use this to push logs into your DB / analytics pipeline.
70
+ */
71
+ onPaymentSettled?: (entry: PaymentLogEntry) => void;
72
+ /** Optional: Send usage telemetry for billing/analytics. */
73
+ telemetry?: TelemetryConfig;
74
+ }
75
+ /**
76
+ * Minimal config for mantlePaywall() - simplified API for single-route protection.
77
+ * This is the "sweet path" for Mantle mainnet + USDC with sensible defaults.
78
+ */
79
+ interface MinimalPaywallOptions {
80
+ /** Price in USD (e.g. 0.01 for 1 cent). */
81
+ priceUsd: number;
82
+ /** Recipient address (developer wallet). Validated at runtime. */
83
+ payTo: string;
84
+ /** Optional facilitator URL (defaults to localhost:8080 or NEXT_PUBLIC_FACILITATOR_URL). */
85
+ facilitatorUrl?: string;
86
+ /** Optional telemetry config. */
87
+ telemetry?: TelemetryConfig;
88
+ /** Optional payment settled hook. */
89
+ onPaymentSettled?: (entry: PaymentLogEntry) => void;
90
+ }
91
+ /**
92
+ * Express middleware function type for Mantle paywall.
93
+ * Async function that returns Promise<void>.
94
+ */
95
+ type MantleMiddleware = (req: Request, res: Response, next: NextFunction) => Promise<void>;
96
+
97
+ export type { MantleMiddleware as M, PaymentLogEntry as P, RouteKey as R, TelemetryConfig as T, RoutePricingConfig as a, RoutesConfig as b, TelemetryEvent as c, PaymentMiddlewareConfig as d, MinimalPaywallOptions as e };
@@ -0,0 +1,85 @@
1
+ import { N as NetworkId, P as PaymentRequirements } from './types-BFUqKBBO.js';
2
+
3
+ /** Unique key for a protected route, e.g. "GET /api/protected". */
4
+ type RouteKey = string;
5
+ /** Pricing config for a single route. */
6
+ interface RoutePricingConfig {
7
+ /** Price in USD cents, e.g. 1 => $0.01. */
8
+ priceUsdCents: number;
9
+ /** Network identifier (e.g. "mantle-mainnet"). */
10
+ network: NetworkId;
11
+ }
12
+ /** Map of route keys to pricing config. */
13
+ type RoutesConfig = Record<RouteKey, RoutePricingConfig>;
14
+ /** Log entry for a successfully settled payment. */
15
+ interface PaymentLogEntry {
16
+ id: string;
17
+ from: string;
18
+ to: string;
19
+ valueAtomic: string;
20
+ network: NetworkId;
21
+ asset: string;
22
+ route?: RouteKey;
23
+ txHash?: string;
24
+ timestamp: number;
25
+ facilitatorUrl?: string;
26
+ paymentRequirements?: PaymentRequirements;
27
+ }
28
+ /** Config for optional telemetry (billing/analytics). */
29
+ interface TelemetryConfig {
30
+ /** Project key from nosubs.ai dashboard. */
31
+ projectKey: string;
32
+ /**
33
+ * Telemetry endpoint URL.
34
+ * If not specified, uses DEFAULT_TELEMETRY_ENDPOINT (see server/constants.ts).
35
+ */
36
+ endpoint?: string;
37
+ }
38
+ /**
39
+ * Minimal config for mantlePaywall() - simplified API for single-route protection.
40
+ * This is the "sweet path" for Mantle mainnet + USDC with sensible defaults.
41
+ */
42
+ interface MinimalPaywallOptions {
43
+ /** Price in USD (e.g. 0.01 for 1 cent). */
44
+ priceUsd: number;
45
+ /** Recipient address (developer wallet). Validated at runtime. */
46
+ payTo: string;
47
+ /** Optional facilitator URL (defaults to localhost:8080 or NEXT_PUBLIC_FACILITATOR_URL). */
48
+ facilitatorUrl?: string;
49
+ /** Optional telemetry config. */
50
+ telemetry?: TelemetryConfig;
51
+ /** Optional payment settled hook. */
52
+ onPaymentSettled?: (entry: PaymentLogEntry) => void;
53
+ }
54
+ /** Input for checkPayment function. */
55
+ interface PaymentCheckInput {
56
+ /** X-PAYMENT header value (base64 encoded), or null if not present. */
57
+ paymentHeader: string | null;
58
+ /** Payment requirements for this route. */
59
+ paymentRequirements: PaymentRequirements;
60
+ /** Facilitator URL for verification. */
61
+ facilitatorUrl: string;
62
+ /** Route key for logging, e.g. "POST /api/generate-image". */
63
+ routeKey?: RouteKey;
64
+ /** Network ID for this payment. */
65
+ network: NetworkId;
66
+ /** Asset address (ERC-20 token). */
67
+ asset: string;
68
+ /** Telemetry config (optional). */
69
+ telemetry?: TelemetryConfig;
70
+ /** Payment settled callback (optional). */
71
+ onPaymentSettled?: (entry: PaymentLogEntry) => void;
72
+ }
73
+ /** Result from checkPayment function. */
74
+ interface PaymentCheckResult {
75
+ /** Status of the payment check. */
76
+ status: "require_payment" | "verification_error" | "invalid_payment" | "verified";
77
+ /** HTTP status code to return. */
78
+ statusCode: 402 | 500 | 200;
79
+ /** Response body to return (null if verified). */
80
+ responseBody: any | null;
81
+ /** Whether payment is valid (only true if status is "verified"). */
82
+ isValid: boolean;
83
+ }
84
+
85
+ export type { MinimalPaywallOptions as M, PaymentLogEntry as P, RouteKey as R, TelemetryConfig as T, RoutePricingConfig as a, RoutesConfig as b, PaymentCheckInput as c, PaymentCheckResult as d };
@@ -0,0 +1,85 @@
1
+ import { N as NetworkId, P as PaymentRequirements } from './types-BFUqKBBO.cjs';
2
+
3
+ /** Unique key for a protected route, e.g. "GET /api/protected". */
4
+ type RouteKey = string;
5
+ /** Pricing config for a single route. */
6
+ interface RoutePricingConfig {
7
+ /** Price in USD cents, e.g. 1 => $0.01. */
8
+ priceUsdCents: number;
9
+ /** Network identifier (e.g. "mantle-mainnet"). */
10
+ network: NetworkId;
11
+ }
12
+ /** Map of route keys to pricing config. */
13
+ type RoutesConfig = Record<RouteKey, RoutePricingConfig>;
14
+ /** Log entry for a successfully settled payment. */
15
+ interface PaymentLogEntry {
16
+ id: string;
17
+ from: string;
18
+ to: string;
19
+ valueAtomic: string;
20
+ network: NetworkId;
21
+ asset: string;
22
+ route?: RouteKey;
23
+ txHash?: string;
24
+ timestamp: number;
25
+ facilitatorUrl?: string;
26
+ paymentRequirements?: PaymentRequirements;
27
+ }
28
+ /** Config for optional telemetry (billing/analytics). */
29
+ interface TelemetryConfig {
30
+ /** Project key from nosubs.ai dashboard. */
31
+ projectKey: string;
32
+ /**
33
+ * Telemetry endpoint URL.
34
+ * If not specified, uses DEFAULT_TELEMETRY_ENDPOINT (see server/constants.ts).
35
+ */
36
+ endpoint?: string;
37
+ }
38
+ /**
39
+ * Minimal config for mantlePaywall() - simplified API for single-route protection.
40
+ * This is the "sweet path" for Mantle mainnet + USDC with sensible defaults.
41
+ */
42
+ interface MinimalPaywallOptions {
43
+ /** Price in USD (e.g. 0.01 for 1 cent). */
44
+ priceUsd: number;
45
+ /** Recipient address (developer wallet). Validated at runtime. */
46
+ payTo: string;
47
+ /** Optional facilitator URL (defaults to localhost:8080 or NEXT_PUBLIC_FACILITATOR_URL). */
48
+ facilitatorUrl?: string;
49
+ /** Optional telemetry config. */
50
+ telemetry?: TelemetryConfig;
51
+ /** Optional payment settled hook. */
52
+ onPaymentSettled?: (entry: PaymentLogEntry) => void;
53
+ }
54
+ /** Input for checkPayment function. */
55
+ interface PaymentCheckInput {
56
+ /** X-PAYMENT header value (base64 encoded), or null if not present. */
57
+ paymentHeader: string | null;
58
+ /** Payment requirements for this route. */
59
+ paymentRequirements: PaymentRequirements;
60
+ /** Facilitator URL for verification. */
61
+ facilitatorUrl: string;
62
+ /** Route key for logging, e.g. "POST /api/generate-image". */
63
+ routeKey?: RouteKey;
64
+ /** Network ID for this payment. */
65
+ network: NetworkId;
66
+ /** Asset address (ERC-20 token). */
67
+ asset: string;
68
+ /** Telemetry config (optional). */
69
+ telemetry?: TelemetryConfig;
70
+ /** Payment settled callback (optional). */
71
+ onPaymentSettled?: (entry: PaymentLogEntry) => void;
72
+ }
73
+ /** Result from checkPayment function. */
74
+ interface PaymentCheckResult {
75
+ /** Status of the payment check. */
76
+ status: "require_payment" | "verification_error" | "invalid_payment" | "verified";
77
+ /** HTTP status code to return. */
78
+ statusCode: 402 | 500 | 200;
79
+ /** Response body to return (null if verified). */
80
+ responseBody: any | null;
81
+ /** Whether payment is valid (only true if status is "verified"). */
82
+ isValid: boolean;
83
+ }
84
+
85
+ export type { MinimalPaywallOptions as M, PaymentLogEntry as P, RouteKey as R, TelemetryConfig as T, RoutePricingConfig as a, RoutesConfig as b, PaymentCheckInput as c, PaymentCheckResult as d };
@@ -0,0 +1,97 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ import { N as NetworkId, P as PaymentRequirements } from './types-BFUqKBBO.js';
3
+
4
+ /** Unique key for a protected route, e.g. "GET /api/protected". */
5
+ type RouteKey = string;
6
+ /** Pricing config for a single route. */
7
+ interface RoutePricingConfig {
8
+ /** Price in USD cents, e.g. 1 => $0.01. */
9
+ priceUsdCents: number;
10
+ /** Network identifier (e.g. "mantle-mainnet"). */
11
+ network: NetworkId;
12
+ }
13
+ /** Map of route keys to pricing config. */
14
+ type RoutesConfig = Record<RouteKey, RoutePricingConfig>;
15
+ /** Log entry for a successfully settled payment. */
16
+ interface PaymentLogEntry {
17
+ id: string;
18
+ from: string;
19
+ to: string;
20
+ valueAtomic: string;
21
+ network: NetworkId;
22
+ asset: string;
23
+ route?: RouteKey;
24
+ txHash?: string;
25
+ timestamp: number;
26
+ facilitatorUrl?: string;
27
+ paymentRequirements?: PaymentRequirements;
28
+ }
29
+ /** Config for optional telemetry (billing/analytics). */
30
+ interface TelemetryConfig {
31
+ /** Project key from nosubs.ai dashboard. */
32
+ projectKey: string;
33
+ /**
34
+ * Telemetry endpoint URL.
35
+ * If not specified, uses DEFAULT_TELEMETRY_ENDPOINT (see server/constants.ts).
36
+ * If both are undefined, telemetry is not sent.
37
+ */
38
+ endpoint?: string;
39
+ }
40
+ /** Telemetry event payload for payment_verified. */
41
+ interface TelemetryEvent {
42
+ event: "payment_verified";
43
+ ts: number;
44
+ projectKey: string;
45
+ network: string;
46
+ buyer: string;
47
+ payTo: string;
48
+ amountAtomic: string;
49
+ asset: string;
50
+ decimals: number;
51
+ nonce: string;
52
+ route: string;
53
+ facilitatorType: "hosted" | "self-hosted";
54
+ facilitatorUrl?: string;
55
+ facilitatorAddress?: string;
56
+ txHash?: string;
57
+ priceUsd?: string;
58
+ }
59
+ /** Config for createPaymentMiddleware. */
60
+ interface PaymentMiddlewareConfig {
61
+ /** Base URL of facilitator, e.g. https://facilitator.nosubs.ai */
62
+ facilitatorUrl: string;
63
+ /** Recipient address (developer). Validated at runtime. */
64
+ receiverAddress: string;
65
+ /** Map of protected routes and their pricing. */
66
+ routes: RoutesConfig;
67
+ /**
68
+ * Optional hook called whenever a payment is successfully settled.
69
+ * You can use this to push logs into your DB / analytics pipeline.
70
+ */
71
+ onPaymentSettled?: (entry: PaymentLogEntry) => void;
72
+ /** Optional: Send usage telemetry for billing/analytics. */
73
+ telemetry?: TelemetryConfig;
74
+ }
75
+ /**
76
+ * Minimal config for mantlePaywall() - simplified API for single-route protection.
77
+ * This is the "sweet path" for Mantle mainnet + USDC with sensible defaults.
78
+ */
79
+ interface MinimalPaywallOptions {
80
+ /** Price in USD (e.g. 0.01 for 1 cent). */
81
+ priceUsd: number;
82
+ /** Recipient address (developer wallet). Validated at runtime. */
83
+ payTo: string;
84
+ /** Optional facilitator URL (defaults to localhost:8080 or NEXT_PUBLIC_FACILITATOR_URL). */
85
+ facilitatorUrl?: string;
86
+ /** Optional telemetry config. */
87
+ telemetry?: TelemetryConfig;
88
+ /** Optional payment settled hook. */
89
+ onPaymentSettled?: (entry: PaymentLogEntry) => void;
90
+ }
91
+ /**
92
+ * Express middleware function type for Mantle paywall.
93
+ * Async function that returns Promise<void>.
94
+ */
95
+ type MantleMiddleware = (req: Request, res: Response, next: NextFunction) => Promise<void>;
96
+
97
+ export type { MantleMiddleware as M, PaymentLogEntry as P, RouteKey as R, TelemetryConfig as T, RoutePricingConfig as a, RoutesConfig as b, TelemetryEvent as c, PaymentMiddlewareConfig as d, MinimalPaywallOptions as e };