x402-express-mantle 1.0.3 → 1.0.5
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 +14 -6
- package/lib/cjs/index.d.ts +81 -119
- package/lib/cjs/index.js +3 -3
- package/lib/esm/index.d.mts +5 -5
- package/lib/esm/index.mjs +3 -3
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -14,16 +14,16 @@ Complete x402 Express middleware SDK with built-in Mantle testnet support and US
|
|
|
14
14
|
## Installation
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
|
-
npm install x402-express-mantle@1.0.
|
|
17
|
+
npm install x402-express-mantle@1.0.4
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
## Quick Start
|
|
21
21
|
|
|
22
22
|
```javascript
|
|
23
23
|
import express from "express";
|
|
24
|
-
import {
|
|
25
|
-
import { ExactEvmScheme } from "x402-
|
|
26
|
-
import { HTTPFacilitatorClient } from "x402-
|
|
24
|
+
import { paymentMiddleware, x402ResourceServer } from "x402-express-mantle";
|
|
25
|
+
import { ExactEvmScheme } from "x402-evm-mantle";
|
|
26
|
+
import { HTTPFacilitatorClient } from "x402-core-mantle/http";
|
|
27
27
|
|
|
28
28
|
const app = express();
|
|
29
29
|
|
|
@@ -56,7 +56,15 @@ const schemes = [
|
|
|
56
56
|
];
|
|
57
57
|
|
|
58
58
|
// Add payment middleware
|
|
59
|
-
app.use(
|
|
59
|
+
app.use(
|
|
60
|
+
paymentMiddleware(
|
|
61
|
+
routes,
|
|
62
|
+
new x402ResourceServer(facilitatorClient).register(
|
|
63
|
+
"eip155:5003",
|
|
64
|
+
new ExactEvmScheme()
|
|
65
|
+
)
|
|
66
|
+
)
|
|
67
|
+
);
|
|
60
68
|
|
|
61
69
|
// Your protected route
|
|
62
70
|
app.get("/premium-data", (req, res) => {
|
|
@@ -136,7 +144,7 @@ This SDK includes custom Mantle configurations:
|
|
|
136
144
|
### Vercel
|
|
137
145
|
|
|
138
146
|
````bash
|
|
139
|
-
npm install x402-express-mantle@1.0.
|
|
147
|
+
npm install x402-express-mantle@1.0.4
|
|
140
148
|
|
|
141
149
|
## Quick Example
|
|
142
150
|
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,111 +1,91 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
PaywallProvider,
|
|
7
|
-
FacilitatorClient,
|
|
8
|
-
} from "x402-core-mantle/server";
|
|
9
|
-
export {
|
|
10
|
-
PaywallConfig,
|
|
11
|
-
PaywallProvider,
|
|
12
|
-
RouteConfigurationError,
|
|
13
|
-
RouteValidationError,
|
|
14
|
-
x402HTTPResourceServer,
|
|
15
|
-
x402ResourceServer,
|
|
16
|
-
} from "x402-core-mantle/server";
|
|
17
|
-
import { Network, SchemeNetworkServer } from "x402-core-mantle/types";
|
|
18
|
-
export {
|
|
19
|
-
Network,
|
|
20
|
-
PaymentPayload,
|
|
21
|
-
PaymentRequired,
|
|
22
|
-
PaymentRequirements,
|
|
23
|
-
SchemeNetworkServer,
|
|
24
|
-
} from "x402-core-mantle/types";
|
|
25
|
-
import { Request, Response, NextFunction } from "express";
|
|
1
|
+
import { HTTPAdapter, RoutesConfig, x402ResourceServer, PaywallConfig, PaywallProvider, FacilitatorClient } from '@x402/core/server';
|
|
2
|
+
export { PaywallConfig, PaywallProvider, RouteConfigurationError, RouteValidationError, x402HTTPResourceServer, x402ResourceServer } from '@x402/core/server';
|
|
3
|
+
import { Network, SchemeNetworkServer } from '@x402/core/types';
|
|
4
|
+
export { Network, PaymentPayload, PaymentRequired, PaymentRequirements, SchemeNetworkServer } from '@x402/core/types';
|
|
5
|
+
import { Request, Response, NextFunction } from 'express';
|
|
26
6
|
|
|
27
7
|
/**
|
|
28
8
|
* Express adapter implementation
|
|
29
9
|
*/
|
|
30
10
|
declare class ExpressAdapter implements HTTPAdapter {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
11
|
+
private req;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new ExpressAdapter instance.
|
|
14
|
+
*
|
|
15
|
+
* @param req - The Express request object
|
|
16
|
+
*/
|
|
17
|
+
constructor(req: Request);
|
|
18
|
+
/**
|
|
19
|
+
* Gets a header value from the request.
|
|
20
|
+
*
|
|
21
|
+
* @param name - The header name
|
|
22
|
+
* @returns The header value or undefined
|
|
23
|
+
*/
|
|
24
|
+
getHeader(name: string): string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Gets the HTTP method of the request.
|
|
27
|
+
*
|
|
28
|
+
* @returns The HTTP method
|
|
29
|
+
*/
|
|
30
|
+
getMethod(): string;
|
|
31
|
+
/**
|
|
32
|
+
* Gets the path of the request.
|
|
33
|
+
*
|
|
34
|
+
* @returns The request path
|
|
35
|
+
*/
|
|
36
|
+
getPath(): string;
|
|
37
|
+
/**
|
|
38
|
+
* Gets the full URL of the request.
|
|
39
|
+
*
|
|
40
|
+
* @returns The full request URL
|
|
41
|
+
*/
|
|
42
|
+
getUrl(): string;
|
|
43
|
+
/**
|
|
44
|
+
* Gets the Accept header from the request.
|
|
45
|
+
*
|
|
46
|
+
* @returns The Accept header value or empty string
|
|
47
|
+
*/
|
|
48
|
+
getAcceptHeader(): string;
|
|
49
|
+
/**
|
|
50
|
+
* Gets the User-Agent header from the request.
|
|
51
|
+
*
|
|
52
|
+
* @returns The User-Agent header value or empty string
|
|
53
|
+
*/
|
|
54
|
+
getUserAgent(): string;
|
|
55
|
+
/**
|
|
56
|
+
* Gets all query parameters from the request URL.
|
|
57
|
+
*
|
|
58
|
+
* @returns Record of query parameter key-value pairs
|
|
59
|
+
*/
|
|
60
|
+
getQueryParams(): Record<string, string | string[]>;
|
|
61
|
+
/**
|
|
62
|
+
* Gets a specific query parameter by name.
|
|
63
|
+
*
|
|
64
|
+
* @param name - The query parameter name
|
|
65
|
+
* @returns The query parameter value(s) or undefined
|
|
66
|
+
*/
|
|
67
|
+
getQueryParam(name: string): string | string[] | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Gets the parsed request body.
|
|
70
|
+
* Requires express.json() or express.urlencoded() middleware.
|
|
71
|
+
*
|
|
72
|
+
* @returns The parsed request body
|
|
73
|
+
*/
|
|
74
|
+
getBody(): unknown;
|
|
95
75
|
}
|
|
96
76
|
|
|
97
77
|
/**
|
|
98
78
|
* Configuration for registering a payment scheme with a specific network
|
|
99
79
|
*/
|
|
100
80
|
interface SchemeRegistration {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
81
|
+
/**
|
|
82
|
+
* The network identifier (e.g., 'eip155:84532', 'solana:mainnet')
|
|
83
|
+
*/
|
|
84
|
+
network: Network;
|
|
85
|
+
/**
|
|
86
|
+
* The scheme server implementation for this network
|
|
87
|
+
*/
|
|
88
|
+
server: SchemeNetworkServer;
|
|
109
89
|
}
|
|
110
90
|
/**
|
|
111
91
|
* Express payment middleware for x402 protocol (direct server instance).
|
|
@@ -124,7 +104,7 @@ interface SchemeRegistration {
|
|
|
124
104
|
* @example
|
|
125
105
|
* ```typescript
|
|
126
106
|
* import { paymentMiddleware } from "@x402/express";
|
|
127
|
-
* import { x402ResourceServer } from "x402
|
|
107
|
+
* import { x402ResourceServer } from "@x402/core/server";
|
|
128
108
|
* import { registerExactEvmScheme } from "@x402/evm/exact/server";
|
|
129
109
|
*
|
|
130
110
|
* const server = new x402ResourceServer(myFacilitatorClient);
|
|
@@ -133,13 +113,7 @@ interface SchemeRegistration {
|
|
|
133
113
|
* app.use(paymentMiddleware(routes, server, paywallConfig));
|
|
134
114
|
* ```
|
|
135
115
|
*/
|
|
136
|
-
declare function paymentMiddleware(
|
|
137
|
-
routes: RoutesConfig,
|
|
138
|
-
server: x402ResourceServer,
|
|
139
|
-
paywallConfig?: PaywallConfig,
|
|
140
|
-
paywall?: PaywallProvider,
|
|
141
|
-
syncFacilitatorOnStart?: boolean
|
|
142
|
-
): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
116
|
+
declare function paymentMiddleware(routes: RoutesConfig, server: x402ResourceServer, paywallConfig?: PaywallConfig, paywall?: PaywallProvider, syncFacilitatorOnStart?: boolean): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
143
117
|
/**
|
|
144
118
|
* Express payment middleware for x402 protocol (configuration-based).
|
|
145
119
|
*
|
|
@@ -166,18 +140,6 @@ declare function paymentMiddleware(
|
|
|
166
140
|
* ));
|
|
167
141
|
* ```
|
|
168
142
|
*/
|
|
169
|
-
declare function paymentMiddlewareFromConfig(
|
|
170
|
-
routes: RoutesConfig,
|
|
171
|
-
facilitatorClients?: FacilitatorClient | FacilitatorClient[],
|
|
172
|
-
schemes?: SchemeRegistration[],
|
|
173
|
-
paywallConfig?: PaywallConfig,
|
|
174
|
-
paywall?: PaywallProvider,
|
|
175
|
-
syncFacilitatorOnStart?: boolean
|
|
176
|
-
): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
143
|
+
declare function paymentMiddlewareFromConfig(routes: RoutesConfig, facilitatorClients?: FacilitatorClient | FacilitatorClient[], schemes?: SchemeRegistration[], paywallConfig?: PaywallConfig, paywall?: PaywallProvider, syncFacilitatorOnStart?: boolean): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
177
144
|
|
|
178
|
-
export {
|
|
179
|
-
ExpressAdapter,
|
|
180
|
-
type SchemeRegistration,
|
|
181
|
-
paymentMiddleware,
|
|
182
|
-
paymentMiddlewareFromConfig,
|
|
183
|
-
};
|
|
145
|
+
export { ExpressAdapter, type SchemeRegistration, paymentMiddleware, paymentMiddlewareFromConfig };
|
package/lib/cjs/index.js
CHANGED
|
@@ -38,7 +38,7 @@ __export(src_exports, {
|
|
|
38
38
|
x402ResourceServer: () => import_server2.x402ResourceServer
|
|
39
39
|
});
|
|
40
40
|
module.exports = __toCommonJS(src_exports);
|
|
41
|
-
var import_server = require("x402
|
|
41
|
+
var import_server = require("@x402/core/server");
|
|
42
42
|
|
|
43
43
|
// src/adapter.ts
|
|
44
44
|
var ExpressAdapter = class {
|
|
@@ -130,8 +130,8 @@ var ExpressAdapter = class {
|
|
|
130
130
|
};
|
|
131
131
|
|
|
132
132
|
// src/index.ts
|
|
133
|
-
var import_server2 = require("x402
|
|
134
|
-
var import_server3 = require("x402
|
|
133
|
+
var import_server2 = require("@x402/core/server");
|
|
134
|
+
var import_server3 = require("@x402/core/server");
|
|
135
135
|
function checkIfBazaarNeeded(routes) {
|
|
136
136
|
if ("accepts" in routes) {
|
|
137
137
|
return !!(routes.extensions && "bazaar" in routes.extensions);
|
package/lib/esm/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { HTTPAdapter, RoutesConfig, x402ResourceServer, PaywallConfig, PaywallProvider, FacilitatorClient } from 'x402
|
|
2
|
-
export { PaywallConfig, PaywallProvider, RouteConfigurationError, RouteValidationError, x402HTTPResourceServer, x402ResourceServer } from 'x402
|
|
3
|
-
import { Network, SchemeNetworkServer } from 'x402
|
|
4
|
-
export { Network, PaymentPayload, PaymentRequired, PaymentRequirements, SchemeNetworkServer } from 'x402
|
|
1
|
+
import { HTTPAdapter, RoutesConfig, x402ResourceServer, PaywallConfig, PaywallProvider, FacilitatorClient } from '@x402/core/server';
|
|
2
|
+
export { PaywallConfig, PaywallProvider, RouteConfigurationError, RouteValidationError, x402HTTPResourceServer, x402ResourceServer } from '@x402/core/server';
|
|
3
|
+
import { Network, SchemeNetworkServer } from '@x402/core/types';
|
|
4
|
+
export { Network, PaymentPayload, PaymentRequired, PaymentRequirements, SchemeNetworkServer } from '@x402/core/types';
|
|
5
5
|
import { Request, Response, NextFunction } from 'express';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -104,7 +104,7 @@ interface SchemeRegistration {
|
|
|
104
104
|
* @example
|
|
105
105
|
* ```typescript
|
|
106
106
|
* import { paymentMiddleware } from "@x402/express";
|
|
107
|
-
* import { x402ResourceServer } from "x402
|
|
107
|
+
* import { x402ResourceServer } from "@x402/core/server";
|
|
108
108
|
* import { registerExactEvmScheme } from "@x402/evm/exact/server";
|
|
109
109
|
*
|
|
110
110
|
* const server = new x402ResourceServer(myFacilitatorClient);
|
package/lib/esm/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {
|
|
3
3
|
x402HTTPResourceServer,
|
|
4
4
|
x402ResourceServer
|
|
5
|
-
} from "x402
|
|
5
|
+
} from "@x402/core/server";
|
|
6
6
|
|
|
7
7
|
// src/adapter.ts
|
|
8
8
|
var ExpressAdapter = class {
|
|
@@ -94,8 +94,8 @@ var ExpressAdapter = class {
|
|
|
94
94
|
};
|
|
95
95
|
|
|
96
96
|
// src/index.ts
|
|
97
|
-
import { x402ResourceServer as x402ResourceServer2, x402HTTPResourceServer as x402HTTPResourceServer2 } from "x402
|
|
98
|
-
import { RouteConfigurationError } from "x402
|
|
97
|
+
import { x402ResourceServer as x402ResourceServer2, x402HTTPResourceServer as x402HTTPResourceServer2 } from "@x402/core/server";
|
|
98
|
+
import { RouteConfigurationError } from "@x402/core/server";
|
|
99
99
|
function checkIfBazaarNeeded(routes) {
|
|
100
100
|
if ("accepts" in routes) {
|
|
101
101
|
return !!(routes.extensions && "bazaar" in routes.extensions);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "x402-express-mantle",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"main": "./lib/cjs/index.js",
|
|
5
5
|
"module": "./lib/esm/index.mjs",
|
|
6
6
|
"types": "./lib/cjs/index.d.ts",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"author": "Mantle x402 Team",
|
|
23
23
|
"description": "x402 Express middleware SDK with built-in Mantle testnet support and USDC Token configurations",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"x402-core-mantle": "2.1.
|
|
26
|
-
"x402-evm-mantle": "2.1.
|
|
27
|
-
"x402-svm-mantle": "2.1.
|
|
25
|
+
"x402-core-mantle": "2.1.2-mantle",
|
|
26
|
+
"x402-evm-mantle": "2.1.2-mantle",
|
|
27
|
+
"x402-svm-mantle": "2.1.2-mantle",
|
|
28
28
|
"@solana/kit": "^2.1.1",
|
|
29
29
|
"viem": "^2.39.3",
|
|
30
30
|
"zod": "^3.24.2"
|