@deltablab/express 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 +21 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/package.json +50 -0
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.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { RequestHandler } from 'express';
|
|
2
|
+
import { PaygatePipelineConnectOptions } from '@deltablab/publisher-core';
|
|
3
|
+
export { GatewayPipelineOptions, PaygatePipelineConnectOptions } from '@deltablab/publisher-core';
|
|
4
|
+
|
|
5
|
+
interface PaygateExpressCloudOptions {
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
apiKey: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Connection options used by `createPaygateExpress`.
|
|
11
|
+
* Declared as interface (not type alias) to preserve declaration-merging compatibility.
|
|
12
|
+
*/
|
|
13
|
+
interface CreatePaygateExpressOptions extends PaygateExpressCloudOptions, PaygatePipelineConnectOptions {
|
|
14
|
+
}
|
|
15
|
+
/** Route-local options used by `createPaygateExpress(...)(route)`. */
|
|
16
|
+
interface PaygateExpressRouteOptions {
|
|
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 PaygateExpressOptions extends CreatePaygateExpressOptions, PaygateExpressRouteOptions {
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Express `RequestHandler` for the PayGate paywall.
|
|
27
|
+
* It does not read or mutate `req.body`, so downstream business handlers can
|
|
28
|
+
* consume the request payload normally.
|
|
29
|
+
*/
|
|
30
|
+
declare function paygateExpress(options: PaygateExpressOptions): RequestHandler;
|
|
31
|
+
declare function createPaygateExpress(options: CreatePaygateExpressOptions): (route: PaygateExpressRouteOptions) => RequestHandler;
|
|
32
|
+
|
|
33
|
+
export { type CreatePaygateExpressOptions, type PaygateExpressCloudOptions, type PaygateExpressOptions, type PaygateExpressRouteOptions, createPaygateExpress, paygateExpress };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { createGatewayPipelineForPaidRoute, incomingFromExpress } from "@deltablab/publisher-core";
|
|
3
|
+
import { PublisherCloudClient } from "@deltablab/publisher-cloud";
|
|
4
|
+
function createRequestHandler(options) {
|
|
5
|
+
const publisherCloud = new PublisherCloudClient({
|
|
6
|
+
baseUrl: options.baseUrl,
|
|
7
|
+
apiKey: options.apiKey
|
|
8
|
+
});
|
|
9
|
+
const pipeline = createGatewayPipelineForPaidRoute(options, options.endpointId, publisherCloud);
|
|
10
|
+
return async (req, res, next) => {
|
|
11
|
+
try {
|
|
12
|
+
const result = await pipeline.handle(incomingFromExpress(req));
|
|
13
|
+
if (result.kind === "next") {
|
|
14
|
+
return next();
|
|
15
|
+
}
|
|
16
|
+
res.status(result.status ?? 500);
|
|
17
|
+
if (result.headers) {
|
|
18
|
+
for (const [k, v] of Object.entries(result.headers)) {
|
|
19
|
+
res.setHeader(k, v);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
res.json(result.body);
|
|
23
|
+
} catch (err) {
|
|
24
|
+
next(err);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function paygateExpress(options) {
|
|
29
|
+
return createRequestHandler(options);
|
|
30
|
+
}
|
|
31
|
+
function createPaygateExpress(options) {
|
|
32
|
+
return ({ endpointId }) => createRequestHandler({ ...options, endpointId });
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
createPaygateExpress,
|
|
36
|
+
paygateExpress
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Request, Response, NextFunction, RequestHandler } from \"express\";\nimport type {\n GatewayPipelineOptions,\n PaygatePipelineConnectOptions,\n} from \"@deltablab/publisher-core\";\nimport { createGatewayPipelineForPaidRoute, incomingFromExpress } from \"@deltablab/publisher-core\";\nimport { PublisherCloudClient } from \"@deltablab/publisher-cloud\";\n\nexport interface PaygateExpressCloudOptions {\n baseUrl: string;\n apiKey: string;\n}\n\n/**\n * Connection options used by `createPaygateExpress`.\n * Declared as interface (not type alias) to preserve declaration-merging compatibility.\n */\nexport interface CreatePaygateExpressOptions\n extends PaygateExpressCloudOptions,\n PaygatePipelineConnectOptions {}\n\n/** Route-local options used by `createPaygateExpress(...)(route)`. */\nexport interface PaygateExpressRouteOptions {\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 PaygateExpressOptions\n extends CreatePaygateExpressOptions,\n PaygateExpressRouteOptions {}\n\nfunction createRequestHandler(options: PaygateExpressOptions): RequestHandler {\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 (req: Request, res: Response, next: NextFunction) => {\n try {\n const result = await pipeline.handle(incomingFromExpress(req));\n\n if (result.kind === \"next\") {\n return next();\n }\n\n res.status(result.status ?? 500);\n if (result.headers) {\n for (const [k, v] of Object.entries(result.headers)) {\n res.setHeader(k, v);\n }\n }\n res.json(result.body);\n } catch (err) {\n next(err);\n }\n };\n}\n\n/**\n * Express `RequestHandler` for the PayGate paywall.\n * It does not read or mutate `req.body`, so downstream business handlers can\n * consume the request payload normally.\n */\nexport function paygateExpress(options: PaygateExpressOptions): RequestHandler {\n return createRequestHandler(options);\n}\n\nexport function createPaygateExpress(\n options: CreatePaygateExpressOptions,\n): (route: PaygateExpressRouteOptions) => RequestHandler {\n return ({ endpointId }: PaygateExpressRouteOptions) =>\n createRequestHandler({ ...options, endpointId });\n}\n\nexport type { GatewayPipelineOptions, PaygatePipelineConnectOptions };\n"],"mappings":";AAKA,SAAS,mCAAmC,2BAA2B;AACvE,SAAS,4BAA4B;AA4BrC,SAAS,qBAAqB,SAAgD;AAC5E,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,KAAc,KAAe,SAAuB;AAChE,QAAI;AACF,YAAM,SAAS,MAAM,SAAS,OAAO,oBAAoB,GAAG,CAAC;AAE7D,UAAI,OAAO,SAAS,QAAQ;AAC1B,eAAO,KAAK;AAAA,MACd;AAEA,UAAI,OAAO,OAAO,UAAU,GAAG;AAC/B,UAAI,OAAO,SAAS;AAClB,mBAAW,CAAC,GAAG,CAAC,KAAK,OAAO,QAAQ,OAAO,OAAO,GAAG;AACnD,cAAI,UAAU,GAAG,CAAC;AAAA,QACpB;AAAA,MACF;AACA,UAAI,KAAK,OAAO,IAAI;AAAA,IACtB,SAAS,KAAK;AACZ,WAAK,GAAG;AAAA,IACV;AAAA,EACF;AACF;AAOO,SAAS,eAAe,SAAgD;AAC7E,SAAO,qBAAqB,OAAO;AACrC;AAEO,SAAS,qBACd,SACuD;AACvD,SAAO,CAAC,EAAE,WAAW,MACnB,qBAAqB,EAAE,GAAG,SAAS,WAAW,CAAC;AACnD;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@deltablab/express",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Express 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
|
+
"express",
|
|
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/publisher-cloud": "0.1.0",
|
|
33
|
+
"@deltablab/publisher-core": "0.1.0",
|
|
34
|
+
"@deltablab/protocol": "0.1.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"express": "^4.18.0 || ^5.0.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/express": "^5.0.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
|
+
}
|