@faremeter/middleware 0.16.0 → 0.17.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/src/cache.d.ts +12 -0
- package/dist/src/cache.d.ts.map +1 -1
- package/dist/src/cache.js +6 -0
- package/dist/src/common.d.ts +174 -13
- package/dist/src/common.d.ts.map +1 -1
- package/dist/src/common.js +345 -37
- package/dist/src/common.test.d.ts +3 -0
- package/dist/src/common.test.d.ts.map +1 -0
- package/dist/src/common.test.js +50 -0
- package/dist/src/express.d.ts +10 -0
- package/dist/src/express.d.ts.map +1 -1
- package/dist/src/express.js +29 -3
- package/dist/src/hono.d.ts +14 -0
- package/dist/src/hono.d.ts.map +1 -1
- package/dist/src/hono.js +27 -4
- package/dist/src/index.d.ts +26 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +26 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -3
package/dist/src/hono.js
CHANGED
|
@@ -1,15 +1,38 @@
|
|
|
1
|
-
import { handleMiddlewareRequest, createPaymentRequiredResponseCache, } from "./common.js";
|
|
1
|
+
import { handleMiddlewareRequest, createPaymentRequiredResponseCache, resolveSupportedVersions, } from "./common.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates Hono middleware that gates routes behind x402 payment.
|
|
4
|
+
*
|
|
5
|
+
* The middleware intercepts requests, checks for payment headers, communicates
|
|
6
|
+
* with the facilitator to validate and settle payments, and only allows the
|
|
7
|
+
* request to proceed if payment is successful.
|
|
8
|
+
*
|
|
9
|
+
* @param args - Configuration including facilitator URL and accepted payment types
|
|
10
|
+
* @returns A Hono middleware handler
|
|
11
|
+
*/
|
|
2
12
|
export async function createMiddleware(args) {
|
|
3
|
-
|
|
13
|
+
// Validate configuration at creation time
|
|
14
|
+
const supportedVersions = resolveSupportedVersions(args.supportedVersions);
|
|
15
|
+
const { getPaymentRequiredResponse, getPaymentRequiredResponseV2 } = createPaymentRequiredResponseCache(args.cacheConfig);
|
|
4
16
|
return async (c, next) => {
|
|
5
17
|
return await handleMiddlewareRequest({
|
|
6
18
|
...args,
|
|
19
|
+
supportedVersions,
|
|
7
20
|
resource: c.req.url,
|
|
8
21
|
getHeader: (key) => c.req.header(key),
|
|
22
|
+
setResponseHeader: (key, value) => c.header(key, value),
|
|
9
23
|
getPaymentRequiredResponse,
|
|
10
|
-
|
|
24
|
+
getPaymentRequiredResponseV2,
|
|
25
|
+
sendJSONResponse: (status, body, headers) => {
|
|
11
26
|
c.status(status);
|
|
12
|
-
|
|
27
|
+
if (headers) {
|
|
28
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
29
|
+
c.header(key, value);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (body) {
|
|
33
|
+
return c.json(body);
|
|
34
|
+
}
|
|
35
|
+
return c.body(null);
|
|
13
36
|
},
|
|
14
37
|
body: async ({ verify, settle }) => {
|
|
15
38
|
if (args.verifyBeforeSettle) {
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title Middleware Package
|
|
3
|
+
* @sidebarTitle Middleware
|
|
4
|
+
* @description Server middleware for gating routes behind x402 payments
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @title Express Middleware
|
|
9
|
+
* @sidebarTitle Middleware / Express
|
|
10
|
+
* @description x402 payment middleware for Express.js
|
|
11
|
+
*/
|
|
1
12
|
export * as express from "./express.js";
|
|
13
|
+
/**
|
|
14
|
+
* @title Hono Middleware
|
|
15
|
+
* @sidebarTitle Middleware / Hono
|
|
16
|
+
* @description x402 payment middleware for Hono web framework
|
|
17
|
+
*/
|
|
2
18
|
export * as hono from "./hono.js";
|
|
19
|
+
/**
|
|
20
|
+
* @title Common Middleware
|
|
21
|
+
* @sidebarTitle Middleware / Common
|
|
22
|
+
* @description Framework-agnostic middleware utilities and types
|
|
23
|
+
*/
|
|
3
24
|
export * as common from "./common.js";
|
|
25
|
+
/**
|
|
26
|
+
* @title Middleware Cache
|
|
27
|
+
* @sidebarTitle Middleware / Cache
|
|
28
|
+
* @description LRU cache with time-based expiration for payment requirements
|
|
29
|
+
*/
|
|
4
30
|
export * as cache from "./cache.js";
|
|
5
31
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH;;;;GAIG;AACH,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC;;;;GAIG;AACH,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B;;;;GAIG;AACH,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC;;;;GAIG;AACH,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title Middleware Package
|
|
3
|
+
* @sidebarTitle Middleware
|
|
4
|
+
* @description Server middleware for gating routes behind x402 payments
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @title Express Middleware
|
|
9
|
+
* @sidebarTitle Middleware / Express
|
|
10
|
+
* @description x402 payment middleware for Express.js
|
|
11
|
+
*/
|
|
1
12
|
export * as express from "./express.js";
|
|
13
|
+
/**
|
|
14
|
+
* @title Hono Middleware
|
|
15
|
+
* @sidebarTitle Middleware / Hono
|
|
16
|
+
* @description x402 payment middleware for Hono web framework
|
|
17
|
+
*/
|
|
2
18
|
export * as hono from "./hono.js";
|
|
19
|
+
/**
|
|
20
|
+
* @title Common Middleware
|
|
21
|
+
* @sidebarTitle Middleware / Common
|
|
22
|
+
* @description Framework-agnostic middleware utilities and types
|
|
23
|
+
*/
|
|
3
24
|
export * as common from "./common.js";
|
|
25
|
+
/**
|
|
26
|
+
* @title Middleware Cache
|
|
27
|
+
* @sidebarTitle Middleware / Cache
|
|
28
|
+
* @description LRU cache with time-based expiration for payment requirements
|
|
29
|
+
*/
|
|
4
30
|
export * as cache from "./cache.js";
|