@deltablab/hono 0.1.0

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) 2026 PayGate contributors
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.
@@ -0,0 +1,32 @@
1
+ import { MiddlewareHandler } from 'hono';
2
+ import { PaygatePipelineConnectOptions } from '@deltablab/publisher-core';
3
+ export { GatewayPipelineOptions, PaygatePipelineConnectOptions } from '@deltablab/publisher-core';
4
+
5
+ interface PaygateHonoCloudOptions {
6
+ baseUrl: string;
7
+ apiKey: string;
8
+ }
9
+ /**
10
+ * Connection options used by `createPaygateHono`.
11
+ * Declared as interface (not type alias) to preserve declaration-merging compatibility.
12
+ */
13
+ interface CreatePaygateHonoOptions extends PaygateHonoCloudOptions, PaygatePipelineConnectOptions {
14
+ }
15
+ /** Route-local options used by `createPaygateHono(...)(route)`. */
16
+ interface PaygateHonoRouteOptions {
17
+ endpointId: string;
18
+ }
19
+ /**
20
+ * Options for one paid route.
21
+ * Declared as interface (not type alias) to preserve declaration-merging compatibility.
22
+ */
23
+ interface PaygateHonoOptions extends CreatePaygateHonoOptions, PaygateHonoRouteOptions {
24
+ }
25
+ /**
26
+ * Hono middleware for the PayGate paywall. Uses `c.req.raw` so JSON bodies stay
27
+ * available to later handlers (`c.req.json()`).
28
+ */
29
+ declare function paygateHono(options: PaygateHonoOptions): MiddlewareHandler;
30
+ declare function createPaygateHono(options: CreatePaygateHonoOptions): (route: PaygateHonoRouteOptions) => MiddlewareHandler;
31
+
32
+ export { type CreatePaygateHonoOptions, type PaygateHonoCloudOptions, type PaygateHonoOptions, type PaygateHonoRouteOptions, createPaygateHono, paygateHono };
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ // src/index.ts
2
+ import {
3
+ createGatewayPipelineForPaidRoute,
4
+ incomingFromWebRequest,
5
+ paygateResultToWebResponse
6
+ } from "@deltablab/publisher-core";
7
+ import { PublisherCloudClient } from "@deltablab/publisher-cloud";
8
+ function createMiddleware(options) {
9
+ const publisherCloud = new PublisherCloudClient({
10
+ baseUrl: options.baseUrl,
11
+ apiKey: options.apiKey
12
+ });
13
+ const pipeline = createGatewayPipelineForPaidRoute(options, options.endpointId, publisherCloud);
14
+ return async (c, next) => {
15
+ const result = await pipeline.handle(incomingFromWebRequest(c.req.raw));
16
+ if (result.kind === "next") {
17
+ return next();
18
+ }
19
+ return paygateResultToWebResponse(result);
20
+ };
21
+ }
22
+ function paygateHono(options) {
23
+ return createMiddleware(options);
24
+ }
25
+ function createPaygateHono(options) {
26
+ return ({ endpointId }) => createMiddleware({ ...options, endpointId });
27
+ }
28
+ export {
29
+ createPaygateHono,
30
+ paygateHono
31
+ };
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { MiddlewareHandler } from \"hono\";\nimport type {\n GatewayPipelineOptions,\n PaygatePipelineConnectOptions,\n} from \"@deltablab/publisher-core\";\nimport {\n createGatewayPipelineForPaidRoute,\n incomingFromWebRequest,\n paygateResultToWebResponse,\n} from \"@deltablab/publisher-core\";\nimport { PublisherCloudClient } from \"@deltablab/publisher-cloud\";\n\nexport interface PaygateHonoCloudOptions {\n baseUrl: string;\n apiKey: string;\n}\n\n/**\n * Connection options used by `createPaygateHono`.\n * Declared as interface (not type alias) to preserve declaration-merging compatibility.\n */\nexport interface CreatePaygateHonoOptions\n extends PaygateHonoCloudOptions,\n PaygatePipelineConnectOptions {}\n\n/** Route-local options used by `createPaygateHono(...)(route)`. */\nexport interface PaygateHonoRouteOptions {\n endpointId: string;\n}\n\n/**\n * Options for one paid route.\n * Declared as interface (not type alias) to preserve declaration-merging compatibility.\n */\nexport interface PaygateHonoOptions\n extends CreatePaygateHonoOptions,\n PaygateHonoRouteOptions {}\n\nfunction createMiddleware(options: PaygateHonoOptions): MiddlewareHandler {\n const publisherCloud = new PublisherCloudClient({\n baseUrl: options.baseUrl,\n apiKey: options.apiKey,\n });\n\n const pipeline = createGatewayPipelineForPaidRoute(options, options.endpointId, publisherCloud);\n\n return async (c, next) => {\n const result = await pipeline.handle(incomingFromWebRequest(c.req.raw));\n\n if (result.kind === \"next\") {\n return next();\n }\n\n return paygateResultToWebResponse(result);\n };\n}\n\n/**\n * Hono middleware for the PayGate paywall. Uses `c.req.raw` so JSON bodies stay\n * available to later handlers (`c.req.json()`).\n */\nexport function paygateHono(options: PaygateHonoOptions): MiddlewareHandler {\n return createMiddleware(options);\n}\n\nexport function createPaygateHono(\n options: CreatePaygateHonoOptions,\n): (route: PaygateHonoRouteOptions) => MiddlewareHandler {\n return ({ endpointId }: PaygateHonoRouteOptions) =>\n createMiddleware({ ...options, endpointId });\n}\n\nexport type { GatewayPipelineOptions, PaygatePipelineConnectOptions };\n"],"mappings":";AAKA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,4BAA4B;AA4BrC,SAAS,iBAAiB,SAAgD;AACxE,QAAM,iBAAiB,IAAI,qBAAqB;AAAA,IAC9C,SAAS,QAAQ;AAAA,IACjB,QAAQ,QAAQ;AAAA,EAClB,CAAC;AAED,QAAM,WAAW,kCAAkC,SAAS,QAAQ,YAAY,cAAc;AAE9F,SAAO,OAAO,GAAG,SAAS;AACxB,UAAM,SAAS,MAAM,SAAS,OAAO,uBAAuB,EAAE,IAAI,GAAG,CAAC;AAEtE,QAAI,OAAO,SAAS,QAAQ;AAC1B,aAAO,KAAK;AAAA,IACd;AAEA,WAAO,2BAA2B,MAAM;AAAA,EAC1C;AACF;AAMO,SAAS,YAAY,SAAgD;AAC1E,SAAO,iBAAiB,OAAO;AACjC;AAEO,SAAS,kBACd,SACuD;AACvD,SAAO,CAAC,EAAE,WAAW,MACnB,iBAAiB,EAAE,GAAG,SAAS,WAAW,CAAC;AAC/C;","names":[]}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@deltablab/hono",
3
+ "version": "0.1.0",
4
+ "description": "Hono middleware wiring PayGate GatewayPipeline to your routes.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "engines": {
8
+ "node": ">=20"
9
+ },
10
+ "keywords": [
11
+ "paygate",
12
+ "x402",
13
+ "hono",
14
+ "middleware"
15
+ ],
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "import": "./dist/index.js",
26
+ "default": "./dist/index.js"
27
+ }
28
+ },
29
+ "main": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
31
+ "dependencies": {
32
+ "@deltablab/protocol": "0.1.0",
33
+ "@deltablab/publisher-core": "0.1.0",
34
+ "@deltablab/publisher-cloud": "0.1.0"
35
+ },
36
+ "peerDependencies": {
37
+ "hono": "^4.0.0"
38
+ },
39
+ "devDependencies": {
40
+ "hono": "^4.7.0",
41
+ "tsup": "^8.4.0",
42
+ "typescript": "^5.7.0",
43
+ "vitest": "^3.1.0"
44
+ },
45
+ "scripts": {
46
+ "build": "tsup",
47
+ "test": "vitest run",
48
+ "test:watch": "vitest"
49
+ }
50
+ }