@4mica/sdk-hono 1.3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 4mica Network
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ var server = require('@4mica/sdk/server');
4
+
5
+ // src/index.ts
6
+ function paywall(verifier, config) {
7
+ const pw = server.createPaywall(verifier, config);
8
+ return async (c, next) => {
9
+ const result = await pw.handle(c.req.raw);
10
+ if (result instanceof Response) {
11
+ return result;
12
+ }
13
+ c.set("paymentGuarantee", result.guarantee);
14
+ await next();
15
+ result.headers.forEach((value, key) => {
16
+ c.res.headers.set(key, value);
17
+ });
18
+ };
19
+ }
20
+
21
+ exports.paywall = paywall;
22
+ //# sourceMappingURL=index.cjs.map
23
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["createPaywall"],"mappings":";;;;;AA4BO,SAAS,OAAA,CACd,UACA,MAAA,EACmB;AACnB,EAAA,MAAM,EAAA,GAAKA,oBAAA,CAAc,QAAA,EAAU,MAAM,CAAA;AACzC,EAAA,OAAO,OAAO,GAAG,IAAA,KAAS;AACxB,IAAA,MAAM,SAAS,MAAM,EAAA,CAAG,MAAA,CAAO,CAAA,CAAE,IAAI,GAAG,CAAA;AACxC,IAAA,IAAI,kBAAkB,QAAA,EAAU;AAC9B,MAAA,OAAO,MAAA;AAAA,IACT;AACA,IAAA,CAAA,CAAE,GAAA,CAAI,kBAAA,EAAoB,MAAA,CAAO,SAAS,CAAA;AAC1C,IAAA,MAAM,IAAA,EAAK;AACX,IAAA,MAAA,CAAO,OAAA,CAAQ,OAAA,CAAQ,CAAC,KAAA,EAAO,GAAA,KAAQ;AACrC,MAAA,CAAA,CAAE,GAAA,CAAI,OAAA,CAAQ,GAAA,CAAI,GAAA,EAAK,KAAK,CAAA;AAAA,IAC9B,CAAC,CAAA;AAAA,EACH,CAAA;AACF","file":"index.cjs","sourcesContent":["import type {\n PaywallConfig,\n PaywallGuarantee,\n PaywallVerifier,\n} from \"@4mica/sdk/server\";\nimport { createPaywall } from \"@4mica/sdk/server\";\nimport type { MiddlewareHandler } from \"hono\";\n\nexport type { PaywallConfig, PaywallGuarantee, PaywallVerifier };\n\ndeclare module \"hono\" {\n interface ContextVariableMap {\n /** The verified 4Mica payment guarantee, set by the {@link paywall} middleware. */\n paymentGuarantee: PaywallGuarantee;\n }\n}\n\n/**\n * Hono middleware that gates a route behind a 4Mica x402 payment.\n *\n * Returns a `402` response with the x402 payment requirements when no valid\n * `X-PAYMENT` header is present; otherwise verifies the payment, exposes the\n * guarantee via `c.get(\"paymentGuarantee\")`, runs the handler, and merges the\n * `X-PAYMENT-RESPONSE` header onto the response.\n *\n * @param verifier - `client`, `client.rpc`, or any guarantee verifier.\n * @param config - Advertised payment requirements for the protected resource.\n */\nexport function paywall(\n verifier: PaywallVerifier,\n config: PaywallConfig,\n): MiddlewareHandler {\n const pw = createPaywall(verifier, config);\n return async (c, next) => {\n const result = await pw.handle(c.req.raw);\n if (result instanceof Response) {\n return result;\n }\n c.set(\"paymentGuarantee\", result.guarantee);\n await next();\n result.headers.forEach((value, key) => {\n c.res.headers.set(key, value);\n });\n };\n}\n"]}
@@ -0,0 +1,24 @@
1
+ import { PaywallGuarantee, PaywallVerifier, PaywallConfig } from '@4mica/sdk/server';
2
+ export { PaywallConfig, PaywallGuarantee, PaywallVerifier } from '@4mica/sdk/server';
3
+ import { MiddlewareHandler } from 'hono';
4
+
5
+ declare module "hono" {
6
+ interface ContextVariableMap {
7
+ /** The verified 4Mica payment guarantee, set by the {@link paywall} middleware. */
8
+ paymentGuarantee: PaywallGuarantee;
9
+ }
10
+ }
11
+ /**
12
+ * Hono middleware that gates a route behind a 4Mica x402 payment.
13
+ *
14
+ * Returns a `402` response with the x402 payment requirements when no valid
15
+ * `X-PAYMENT` header is present; otherwise verifies the payment, exposes the
16
+ * guarantee via `c.get("paymentGuarantee")`, runs the handler, and merges the
17
+ * `X-PAYMENT-RESPONSE` header onto the response.
18
+ *
19
+ * @param verifier - `client`, `client.rpc`, or any guarantee verifier.
20
+ * @param config - Advertised payment requirements for the protected resource.
21
+ */
22
+ declare function paywall(verifier: PaywallVerifier, config: PaywallConfig): MiddlewareHandler;
23
+
24
+ export { paywall };
@@ -0,0 +1,24 @@
1
+ import { PaywallGuarantee, PaywallVerifier, PaywallConfig } from '@4mica/sdk/server';
2
+ export { PaywallConfig, PaywallGuarantee, PaywallVerifier } from '@4mica/sdk/server';
3
+ import { MiddlewareHandler } from 'hono';
4
+
5
+ declare module "hono" {
6
+ interface ContextVariableMap {
7
+ /** The verified 4Mica payment guarantee, set by the {@link paywall} middleware. */
8
+ paymentGuarantee: PaywallGuarantee;
9
+ }
10
+ }
11
+ /**
12
+ * Hono middleware that gates a route behind a 4Mica x402 payment.
13
+ *
14
+ * Returns a `402` response with the x402 payment requirements when no valid
15
+ * `X-PAYMENT` header is present; otherwise verifies the payment, exposes the
16
+ * guarantee via `c.get("paymentGuarantee")`, runs the handler, and merges the
17
+ * `X-PAYMENT-RESPONSE` header onto the response.
18
+ *
19
+ * @param verifier - `client`, `client.rpc`, or any guarantee verifier.
20
+ * @param config - Advertised payment requirements for the protected resource.
21
+ */
22
+ declare function paywall(verifier: PaywallVerifier, config: PaywallConfig): MiddlewareHandler;
23
+
24
+ export { paywall };
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ import { createPaywall } from '@4mica/sdk/server';
2
+
3
+ // src/index.ts
4
+ function paywall(verifier, config) {
5
+ const pw = createPaywall(verifier, config);
6
+ return async (c, next) => {
7
+ const result = await pw.handle(c.req.raw);
8
+ if (result instanceof Response) {
9
+ return result;
10
+ }
11
+ c.set("paymentGuarantee", result.guarantee);
12
+ await next();
13
+ result.headers.forEach((value, key) => {
14
+ c.res.headers.set(key, value);
15
+ });
16
+ };
17
+ }
18
+
19
+ export { paywall };
20
+ //# sourceMappingURL=index.js.map
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AA4BO,SAAS,OAAA,CACd,UACA,MAAA,EACmB;AACnB,EAAA,MAAM,EAAA,GAAK,aAAA,CAAc,QAAA,EAAU,MAAM,CAAA;AACzC,EAAA,OAAO,OAAO,GAAG,IAAA,KAAS;AACxB,IAAA,MAAM,SAAS,MAAM,EAAA,CAAG,MAAA,CAAO,CAAA,CAAE,IAAI,GAAG,CAAA;AACxC,IAAA,IAAI,kBAAkB,QAAA,EAAU;AAC9B,MAAA,OAAO,MAAA;AAAA,IACT;AACA,IAAA,CAAA,CAAE,GAAA,CAAI,kBAAA,EAAoB,MAAA,CAAO,SAAS,CAAA;AAC1C,IAAA,MAAM,IAAA,EAAK;AACX,IAAA,MAAA,CAAO,OAAA,CAAQ,OAAA,CAAQ,CAAC,KAAA,EAAO,GAAA,KAAQ;AACrC,MAAA,CAAA,CAAE,GAAA,CAAI,OAAA,CAAQ,GAAA,CAAI,GAAA,EAAK,KAAK,CAAA;AAAA,IAC9B,CAAC,CAAA;AAAA,EACH,CAAA;AACF","file":"index.js","sourcesContent":["import type {\n PaywallConfig,\n PaywallGuarantee,\n PaywallVerifier,\n} from \"@4mica/sdk/server\";\nimport { createPaywall } from \"@4mica/sdk/server\";\nimport type { MiddlewareHandler } from \"hono\";\n\nexport type { PaywallConfig, PaywallGuarantee, PaywallVerifier };\n\ndeclare module \"hono\" {\n interface ContextVariableMap {\n /** The verified 4Mica payment guarantee, set by the {@link paywall} middleware. */\n paymentGuarantee: PaywallGuarantee;\n }\n}\n\n/**\n * Hono middleware that gates a route behind a 4Mica x402 payment.\n *\n * Returns a `402` response with the x402 payment requirements when no valid\n * `X-PAYMENT` header is present; otherwise verifies the payment, exposes the\n * guarantee via `c.get(\"paymentGuarantee\")`, runs the handler, and merges the\n * `X-PAYMENT-RESPONSE` header onto the response.\n *\n * @param verifier - `client`, `client.rpc`, or any guarantee verifier.\n * @param config - Advertised payment requirements for the protected resource.\n */\nexport function paywall(\n verifier: PaywallVerifier,\n config: PaywallConfig,\n): MiddlewareHandler {\n const pw = createPaywall(verifier, config);\n return async (c, next) => {\n const result = await pw.handle(c.req.raw);\n if (result instanceof Response) {\n return result;\n }\n c.set(\"paymentGuarantee\", result.guarantee);\n await next();\n result.headers.forEach((value, key) => {\n c.res.headers.set(key, value);\n });\n };\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@4mica/sdk-hono",
3
+ "version": "1.3.1",
4
+ "description": "Hono middleware for gating routes behind a 4Mica x402 payment",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/4mica-Network/homepage.git",
10
+ "directory": "packages/sdk-hono"
11
+ },
12
+ "sideEffects": false,
13
+ "main": "./dist/index.cjs",
14
+ "module": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "import": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
21
+ },
22
+ "require": {
23
+ "types": "./dist/index.d.cts",
24
+ "default": "./dist/index.cjs"
25
+ }
26
+ },
27
+ "./package.json": "./package.json"
28
+ },
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "engines": {
33
+ "node": ">=18"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "keywords": [
39
+ "4mica",
40
+ "sdk",
41
+ "hono",
42
+ "x402",
43
+ "middleware",
44
+ "payments"
45
+ ],
46
+ "dependencies": {
47
+ "@4mica/sdk": "1.3.1"
48
+ },
49
+ "peerDependencies": {
50
+ "hono": ">=4"
51
+ },
52
+ "devDependencies": {
53
+ "@arethetypeswrong/cli": "^0.18.2",
54
+ "@types/node": "^24.10.1",
55
+ "hono": "^4.6.0",
56
+ "publint": "^0.3.14",
57
+ "tsup": "^8.5.1",
58
+ "typescript": "^5.9.0",
59
+ "vitest": "^4.1.8",
60
+ "@4mica/tsconfig": "0.0.0"
61
+ },
62
+ "scripts": {
63
+ "build": "tsup",
64
+ "dev": "tsup --watch",
65
+ "clean": "rm -rf dist",
66
+ "typecheck": "tsc --noEmit",
67
+ "test": "vitest run --passWithNoTests",
68
+ "check:exports": "attw --pack . --profile node16 && publint --strict"
69
+ }
70
+ }