@cored3v/web-core 1.0.1 → 1.0.3
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 +104 -4
- package/dist/{app → cjs/app}/createApp.d.ts +1 -1
- package/dist/{app → cjs/app}/createApp.js +10 -10
- package/dist/cjs/app/security.d.ts +11 -0
- package/dist/{app → cjs/app}/security.js +7 -2
- package/dist/cjs/auth/jwt.d.ts +7 -0
- package/dist/{auth → cjs/auth}/jwt.js +8 -1
- package/dist/{config → cjs/config}/index.d.ts +1 -1
- package/dist/{config → cjs/config}/index.js +1 -1
- package/dist/{db → cjs/db}/index.js +2 -2
- package/dist/cjs/frameworks/h3.d.ts +21 -0
- package/dist/cjs/frameworks/h3.js +38 -0
- package/dist/cjs/frameworks/next.d.ts +21 -0
- package/dist/cjs/frameworks/next.js +34 -0
- package/dist/cjs/frameworks/types.d.ts +24 -0
- package/dist/{index.js → cjs/index.cjs} +5 -1
- package/dist/cjs/index.d.cts +4 -0
- package/dist/cjs/index.d.mts +4 -0
- package/dist/cjs/index.mjs +5 -0
- package/dist/{license → cjs/license}/verify.js +2 -2
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types.js +2 -0
- package/dist/esm/app/createApp.d.ts +6 -0
- package/dist/esm/app/createApp.js +52 -0
- package/dist/esm/app/security.d.ts +11 -0
- package/dist/esm/app/security.js +10 -0
- package/dist/esm/auth/jwt.d.ts +7 -0
- package/dist/esm/auth/jwt.js +27 -0
- package/dist/esm/config/index.d.ts +2 -0
- package/dist/esm/config/index.js +10 -0
- package/dist/esm/db/index.d.ts +15 -0
- package/dist/esm/db/index.js +11 -0
- package/dist/esm/db/postgres.d.ts +12 -0
- package/dist/esm/db/postgres.js +9 -0
- package/dist/esm/frameworks/h3.d.ts +21 -0
- package/dist/esm/frameworks/h3.js +35 -0
- package/dist/esm/frameworks/next.d.ts +21 -0
- package/dist/esm/frameworks/next.js +31 -0
- package/dist/esm/frameworks/types.d.ts +24 -0
- package/dist/esm/frameworks/types.js +1 -0
- package/dist/esm/index.cjs +24 -0
- package/dist/esm/index.d.cts +4 -0
- package/dist/esm/index.d.mts +4 -0
- package/dist/esm/index.mjs +4 -0
- package/dist/esm/license/crypto.d.ts +1 -0
- package/dist/esm/license/crypto.js +18 -0
- package/dist/esm/license/types.d.ts +7 -0
- package/dist/esm/license/types.js +1 -0
- package/dist/esm/license/verify.d.ts +4 -0
- package/dist/esm/license/verify.js +18 -0
- package/dist/esm/types.d.ts +28 -0
- package/dist/esm/types.js +1 -0
- package/package.json +18 -5
- package/dist/app/security.d.ts +0 -2
- package/dist/auth/jwt.d.ts +0 -4
- package/dist/index.d.ts +0 -2
- /package/dist/{db → cjs/db}/index.d.ts +0 -0
- /package/dist/{db → cjs/db}/postgres.d.ts +0 -0
- /package/dist/{db → cjs/db}/postgres.js +0 -0
- /package/dist/{license → cjs/frameworks}/types.js +0 -0
- /package/dist/{license → cjs/license}/crypto.d.ts +0 -0
- /package/dist/{license → cjs/license}/crypto.js +0 -0
- /package/dist/{license → cjs/license}/types.d.ts +0 -0
- /package/dist/{types.js → cjs/license/types.js} +0 -0
- /package/dist/{license → cjs/license}/verify.d.ts +0 -0
- /package/dist/{types.d.ts → cjs/types.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,7 +1,107 @@
|
|
|
1
1
|
# @cored3v/web-core
|
|
2
2
|
|
|
3
|
-
A
|
|
4
|
-
bootstrapping, configuration, authentication, database lifecycle management,
|
|
5
|
-
and **license-based execution enforcement**.
|
|
3
|
+
A generic, production-ready application core for Node.js, designed to provide reusable **bootstrapping, configuration, authentication, and license-based execution enforcement** across multiple frameworks.
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
It supports **Express.js**, **Next.js**, **Nuxt (H3)**, and generic Node.js environments.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **License Enforcement**: Protect your source code by enforcing valid license keys.
|
|
10
|
+
- **JWT Authentication**: Built-in JWT verification helper and middleware.
|
|
11
|
+
- **Database Management**: Automatic Postgres connection pooling and lifecycle management.
|
|
12
|
+
- **Security Defaults**: Pre-configured Helmet and CORS for Express.
|
|
13
|
+
- **Multi-Framework**: First-class adapters for Express, Next.js, and H3.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @cored3v/web-core
|
|
19
|
+
# or
|
|
20
|
+
yarn add @cored3v/web-core
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### Next.js (App Router & Middleware)
|
|
26
|
+
|
|
27
|
+
Use `createNextApp` to integrate core services.
|
|
28
|
+
|
|
29
|
+
**`src/lib/core.ts`**
|
|
30
|
+
```typescript
|
|
31
|
+
import { createNextApp } from "@cored3v/web-core";
|
|
32
|
+
|
|
33
|
+
// Initialize once (singleton pattern recommended)
|
|
34
|
+
export const core = await createNextApp({
|
|
35
|
+
appId: "my-next-app"
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**`src/app/api/hello/route.ts`**
|
|
40
|
+
```typescript
|
|
41
|
+
import { core } from "@/lib/core";
|
|
42
|
+
import { NextResponse } from "next/server";
|
|
43
|
+
|
|
44
|
+
export async function GET(request: Request) {
|
|
45
|
+
// Verify Session
|
|
46
|
+
const user = await core.verifySession(request);
|
|
47
|
+
if (!user) {
|
|
48
|
+
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return NextResponse.json({ message: "Hello World", user });
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Express.js
|
|
56
|
+
|
|
57
|
+
Use `createApp` to bootstrap a full Express server.
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { createApp } from "@cored3v/web-core";
|
|
61
|
+
|
|
62
|
+
await createApp({
|
|
63
|
+
appId: "my-express-app",
|
|
64
|
+
http: { port: 3000 },
|
|
65
|
+
routes: ({ app, router, auth, db }) => {
|
|
66
|
+
|
|
67
|
+
// Protected Route
|
|
68
|
+
router.get("/secure", auth.middleware(), (req, res) => {
|
|
69
|
+
res.json({ message: "Secure Data", user: req.user });
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
}).then(({ start }) => start());
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Nuxt / H3 / Nitro
|
|
77
|
+
|
|
78
|
+
Use `createH3App` for H3-based servers.
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { createH3App } from "@cored3v/web-core";
|
|
82
|
+
|
|
83
|
+
const core = await createH3App({ appId: "my-nuxt-app" });
|
|
84
|
+
|
|
85
|
+
export default eventHandler(async (event) => {
|
|
86
|
+
const user = await core.verifySession(event);
|
|
87
|
+
if (!user) {
|
|
88
|
+
throw createError({ statusCode: 401, statusMessage: "Unauthorized" });
|
|
89
|
+
}
|
|
90
|
+
return { message: "Success", user };
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Configuration
|
|
95
|
+
|
|
96
|
+
The library uses `dotenv` to load configuration. Ensure you have a `.env` file or environment variables set.
|
|
97
|
+
|
|
98
|
+
| Variable | Description | Required | Default |
|
|
99
|
+
|----------|-------------|----------|---------|
|
|
100
|
+
| `LICENSE_PATH` | Path to the `license.json` file | No | `./license.json` |
|
|
101
|
+
| `JWT_SECRET` | Secret key for JWT verification | **Yes** | - |
|
|
102
|
+
| `DATABASE_URL` | Postgres Connection String | No | - |
|
|
103
|
+
| `PORT` | Http Port (Express only) | No | `3000` |
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
Private / Proprietary.
|
|
@@ -39,16 +39,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.createApp = createApp;
|
|
40
40
|
const express_1 = __importStar(require("express"));
|
|
41
41
|
const http_1 = __importDefault(require("http"));
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
const
|
|
42
|
+
const index_js_1 = require("../config/index.js");
|
|
43
|
+
const verify_js_1 = require("../license/verify.js");
|
|
44
|
+
const security_js_1 = require("./security.js");
|
|
45
|
+
const index_js_2 = require("../db/index.js");
|
|
46
|
+
const jwt_js_1 = require("../auth/jwt.js");
|
|
47
47
|
async function createApp(opts) {
|
|
48
48
|
// 1) CONFIG
|
|
49
|
-
const config = (0,
|
|
49
|
+
const config = (0, index_js_1.loadConfig)();
|
|
50
50
|
// 2) LICENSE GATE
|
|
51
|
-
await (0,
|
|
51
|
+
await (0, verify_js_1.verifyLicense)({
|
|
52
52
|
appId: opts.appId,
|
|
53
53
|
licensePath: config.get("LICENSE_PATH", "./license.json"),
|
|
54
54
|
});
|
|
@@ -59,13 +59,13 @@ async function createApp(opts) {
|
|
|
59
59
|
if (opts.http?.trustProxy)
|
|
60
60
|
app.set("trust proxy", true);
|
|
61
61
|
// 4) CORE MIDDLEWARE
|
|
62
|
-
(0,
|
|
62
|
+
(0, security_js_1.applySecurity)(app);
|
|
63
63
|
app.use(express_1.default.json());
|
|
64
64
|
app.use(express_1.default.urlencoded({ extended: false }));
|
|
65
65
|
// 5) DB (non-optional if declared)
|
|
66
|
-
const db = await (0,
|
|
66
|
+
const db = await (0, index_js_2.initDb)(opts.db);
|
|
67
67
|
// 6) AUTH
|
|
68
|
-
const auth = (0,
|
|
68
|
+
const auth = (0, jwt_js_1.initJwtAuth)(config);
|
|
69
69
|
// 7) ROUTES
|
|
70
70
|
if (opts.routes) {
|
|
71
71
|
opts.routes({ app, router, db, auth, config });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Express } from "express";
|
|
2
|
+
import cors from "cors";
|
|
3
|
+
export declare const securityConfig: {
|
|
4
|
+
helmet: (req: import("http").IncomingMessage, res: import("http").ServerResponse, next: (err?: unknown) => void) => void;
|
|
5
|
+
cors: (req: cors.CorsRequest, res: {
|
|
6
|
+
statusCode?: number | undefined;
|
|
7
|
+
setHeader(key: string, value: string): any;
|
|
8
|
+
end(): any;
|
|
9
|
+
}, next: (err?: any) => any) => void;
|
|
10
|
+
};
|
|
11
|
+
export declare function applySecurity(app: Express): void;
|
|
@@ -3,10 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.securityConfig = void 0;
|
|
6
7
|
exports.applySecurity = applySecurity;
|
|
7
8
|
const helmet_1 = __importDefault(require("helmet"));
|
|
8
9
|
const cors_1 = __importDefault(require("cors"));
|
|
10
|
+
exports.securityConfig = {
|
|
11
|
+
helmet: (0, helmet_1.default)(),
|
|
12
|
+
cors: (0, cors_1.default)()
|
|
13
|
+
};
|
|
9
14
|
function applySecurity(app) {
|
|
10
|
-
app.use(
|
|
11
|
-
app.use(
|
|
15
|
+
app.use(exports.securityConfig.helmet);
|
|
16
|
+
app.use(exports.securityConfig.cors);
|
|
12
17
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import jwt from "jsonwebtoken";
|
|
2
|
+
import { Config } from "../types.js";
|
|
3
|
+
export declare function verifyToken(token: string, secret: string): string | jwt.JwtPayload;
|
|
4
|
+
export declare function initJwtAuth(config: Config): {
|
|
5
|
+
verify(token: string): string | jwt.JwtPayload;
|
|
6
|
+
middleware(): (req: any, _res: any, next: any) => any;
|
|
7
|
+
};
|
|
@@ -3,13 +3,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.verifyToken = verifyToken;
|
|
6
7
|
exports.initJwtAuth = initJwtAuth;
|
|
7
8
|
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
9
|
+
function verifyToken(token, secret) {
|
|
10
|
+
return jsonwebtoken_1.default.verify(token, secret);
|
|
11
|
+
}
|
|
8
12
|
function initJwtAuth(config) {
|
|
9
13
|
const secret = config.get("JWT_SECRET");
|
|
10
14
|
if (!secret)
|
|
11
15
|
throw new Error("JWT_SECRET missing");
|
|
12
16
|
return {
|
|
17
|
+
verify(token) {
|
|
18
|
+
return verifyToken(token, secret);
|
|
19
|
+
},
|
|
13
20
|
middleware() {
|
|
14
21
|
return (req, _res, next) => {
|
|
15
22
|
const h = req.headers.authorization;
|
|
@@ -17,7 +24,7 @@ function initJwtAuth(config) {
|
|
|
17
24
|
return next();
|
|
18
25
|
try {
|
|
19
26
|
const token = h.replace("Bearer ", "");
|
|
20
|
-
req.user =
|
|
27
|
+
req.user = verifyToken(token, secret);
|
|
21
28
|
}
|
|
22
29
|
catch { }
|
|
23
30
|
next();
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Config } from "../types";
|
|
1
|
+
import { Config } from "../types.js";
|
|
2
2
|
export declare function loadConfig(): Config;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.initDb = initDb;
|
|
4
|
-
const
|
|
4
|
+
const postgres_js_1 = require("./postgres.js");
|
|
5
5
|
async function initDb(opts) {
|
|
6
6
|
if (!opts)
|
|
7
7
|
return null;
|
|
8
8
|
if (opts.type === "postgres") {
|
|
9
9
|
if (!opts.uri)
|
|
10
10
|
throw new Error("Postgres URI required");
|
|
11
|
-
return (0,
|
|
11
|
+
return (0, postgres_js_1.initPostgres)(opts.uri);
|
|
12
12
|
}
|
|
13
13
|
throw new Error("Unsupported DB");
|
|
14
14
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CreateFrameworkAppOptions } from "./types.js";
|
|
2
|
+
export declare function createH3App(opts: CreateFrameworkAppOptions): Promise<{
|
|
3
|
+
db: {
|
|
4
|
+
query: {
|
|
5
|
+
<T extends import("pg").Submittable>(queryStream: T): T;
|
|
6
|
+
<R extends any[] = any[], I = any[]>(queryConfig: import("pg").QueryArrayConfig<I>, values?: import("pg").QueryConfigValues<I>): Promise<import("pg").QueryArrayResult<R>>;
|
|
7
|
+
<R extends import("pg").QueryResultRow = any, I = any>(queryConfig: import("pg").QueryConfig<I>): Promise<import("pg").QueryResult<R>>;
|
|
8
|
+
<R extends import("pg").QueryResultRow = any, I = any[]>(queryTextOrConfig: string | import("pg").QueryConfig<I>, values?: import("pg").QueryConfigValues<I>): Promise<import("pg").QueryResult<R>>;
|
|
9
|
+
<R extends any[] = any[], I = any[]>(queryConfig: import("pg").QueryArrayConfig<I>, callback: (err: Error, result: import("pg").QueryArrayResult<R>) => void): void;
|
|
10
|
+
<R extends import("pg").QueryResultRow = any, I = any[]>(queryTextOrConfig: string | import("pg").QueryConfig<I>, callback: (err: Error, result: import("pg").QueryResult<R>) => void): void;
|
|
11
|
+
<R extends import("pg").QueryResultRow = any, I = any[]>(queryText: string, values: import("pg").QueryConfigValues<I>, callback: (err: Error, result: import("pg").QueryResult<R>) => void): void;
|
|
12
|
+
};
|
|
13
|
+
close: () => Promise<void>;
|
|
14
|
+
} | null;
|
|
15
|
+
auth: {
|
|
16
|
+
verify(token: string): string | import("jsonwebtoken").JwtPayload;
|
|
17
|
+
middleware(): (req: any, _res: any, next: any) => any;
|
|
18
|
+
};
|
|
19
|
+
config: import("../types.js").Config;
|
|
20
|
+
verifySession: (event: any) => Promise<string | import("jsonwebtoken").JwtPayload | null>;
|
|
21
|
+
}>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createH3App = createH3App;
|
|
4
|
+
const index_js_1 = require("../config/index.js");
|
|
5
|
+
const verify_js_1 = require("../license/verify.js");
|
|
6
|
+
const jwt_js_1 = require("../auth/jwt.js");
|
|
7
|
+
const index_js_2 = require("../db/index.js");
|
|
8
|
+
// H3 is often used in Nuxt or Nitro. We don't import h3 directly to avoid hard dependency,
|
|
9
|
+
// but we assume the user passes the event or app instance if needed.
|
|
10
|
+
// For now, we return a setup object similar to Next.js
|
|
11
|
+
async function createH3App(opts) {
|
|
12
|
+
const config = (0, index_js_1.loadConfig)();
|
|
13
|
+
// License Check
|
|
14
|
+
await (0, verify_js_1.verifyLicense)({
|
|
15
|
+
appId: opts.appId,
|
|
16
|
+
licensePath: config.get("LICENSE_PATH", "./license.json"),
|
|
17
|
+
});
|
|
18
|
+
const db = await (0, index_js_2.initDb)({ type: "postgres" });
|
|
19
|
+
const auth = (0, jwt_js_1.initJwtAuth)(config);
|
|
20
|
+
return {
|
|
21
|
+
db,
|
|
22
|
+
auth,
|
|
23
|
+
config,
|
|
24
|
+
verifySession: async (event) => {
|
|
25
|
+
// H3 event structure abstraction
|
|
26
|
+
const h = event.node?.req?.headers?.authorization || event.headers?.get("authorization");
|
|
27
|
+
if (!h)
|
|
28
|
+
return null;
|
|
29
|
+
try {
|
|
30
|
+
const token = h.replace("Bearer ", "");
|
|
31
|
+
return auth.verify(token);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CreateFrameworkAppOptions } from "./types.js";
|
|
2
|
+
export declare function createNextApp(opts: CreateFrameworkAppOptions): Promise<{
|
|
3
|
+
db: {
|
|
4
|
+
query: {
|
|
5
|
+
<T extends import("pg").Submittable>(queryStream: T): T;
|
|
6
|
+
<R extends any[] = any[], I = any[]>(queryConfig: import("pg").QueryArrayConfig<I>, values?: import("pg").QueryConfigValues<I>): Promise<import("pg").QueryArrayResult<R>>;
|
|
7
|
+
<R extends import("pg").QueryResultRow = any, I = any>(queryConfig: import("pg").QueryConfig<I>): Promise<import("pg").QueryResult<R>>;
|
|
8
|
+
<R extends import("pg").QueryResultRow = any, I = any[]>(queryTextOrConfig: string | import("pg").QueryConfig<I>, values?: import("pg").QueryConfigValues<I>): Promise<import("pg").QueryResult<R>>;
|
|
9
|
+
<R extends any[] = any[], I = any[]>(queryConfig: import("pg").QueryArrayConfig<I>, callback: (err: Error, result: import("pg").QueryArrayResult<R>) => void): void;
|
|
10
|
+
<R extends import("pg").QueryResultRow = any, I = any[]>(queryTextOrConfig: string | import("pg").QueryConfig<I>, callback: (err: Error, result: import("pg").QueryResult<R>) => void): void;
|
|
11
|
+
<R extends import("pg").QueryResultRow = any, I = any[]>(queryText: string, values: import("pg").QueryConfigValues<I>, callback: (err: Error, result: import("pg").QueryResult<R>) => void): void;
|
|
12
|
+
};
|
|
13
|
+
close: () => Promise<void>;
|
|
14
|
+
} | null;
|
|
15
|
+
auth: {
|
|
16
|
+
verify(token: string): string | import("jsonwebtoken").JwtPayload;
|
|
17
|
+
middleware(): (req: any, _res: any, next: any) => any;
|
|
18
|
+
};
|
|
19
|
+
config: import("../types.js").Config;
|
|
20
|
+
verifySession: (req: Request) => Promise<string | import("jsonwebtoken").JwtPayload | null>;
|
|
21
|
+
}>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createNextApp = createNextApp;
|
|
4
|
+
const index_js_1 = require("../config/index.js");
|
|
5
|
+
const verify_js_1 = require("../license/verify.js");
|
|
6
|
+
const jwt_js_1 = require("../auth/jwt.js");
|
|
7
|
+
const index_js_2 = require("../db/index.js");
|
|
8
|
+
async function createNextApp(opts) {
|
|
9
|
+
const config = (0, index_js_1.loadConfig)();
|
|
10
|
+
// License Check
|
|
11
|
+
await (0, verify_js_1.verifyLicense)({
|
|
12
|
+
appId: opts.appId,
|
|
13
|
+
licensePath: config.get("LICENSE_PATH", "./license.json"),
|
|
14
|
+
});
|
|
15
|
+
const db = await (0, index_js_2.initDb)({ type: "postgres" }); // Defaulting to existing DB logic
|
|
16
|
+
const auth = (0, jwt_js_1.initJwtAuth)(config);
|
|
17
|
+
return {
|
|
18
|
+
db,
|
|
19
|
+
auth,
|
|
20
|
+
config,
|
|
21
|
+
verifySession: async (req) => {
|
|
22
|
+
const h = req.headers.get("authorization");
|
|
23
|
+
if (!h)
|
|
24
|
+
return null;
|
|
25
|
+
try {
|
|
26
|
+
const token = h.replace("Bearer ", "");
|
|
27
|
+
return auth.verify(token);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Config } from "../types.js";
|
|
2
|
+
export interface WebCoreRequest {
|
|
3
|
+
headers: Record<string, string | string[] | undefined>;
|
|
4
|
+
url?: string;
|
|
5
|
+
method?: string;
|
|
6
|
+
body?: any;
|
|
7
|
+
}
|
|
8
|
+
export interface WebCoreResponse {
|
|
9
|
+
status(code: number): WebCoreResponse;
|
|
10
|
+
json(body: any): WebCoreResponse;
|
|
11
|
+
send(body: any): WebCoreResponse;
|
|
12
|
+
setHeader(key: string, value: string): WebCoreResponse;
|
|
13
|
+
}
|
|
14
|
+
export interface WebCoreContext {
|
|
15
|
+
config: Config;
|
|
16
|
+
auth: {
|
|
17
|
+
verify(token: string): any;
|
|
18
|
+
};
|
|
19
|
+
db?: any;
|
|
20
|
+
}
|
|
21
|
+
export interface CreateFrameworkAppOptions {
|
|
22
|
+
appId: string;
|
|
23
|
+
config?: Record<string, any>;
|
|
24
|
+
}
|
|
@@ -14,7 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.createApp = void 0;
|
|
17
|
+
exports.createH3App = exports.createNextApp = exports.createApp = void 0;
|
|
18
18
|
var createApp_1 = require("./app/createApp");
|
|
19
19
|
Object.defineProperty(exports, "createApp", { enumerable: true, get: function () { return createApp_1.createApp; } });
|
|
20
|
+
var next_1 = require("./frameworks/next");
|
|
21
|
+
Object.defineProperty(exports, "createNextApp", { enumerable: true, get: function () { return next_1.createNextApp; } });
|
|
22
|
+
var h3_1 = require("./frameworks/h3");
|
|
23
|
+
Object.defineProperty(exports, "createH3App", { enumerable: true, get: function () { return h3_1.createH3App; } });
|
|
20
24
|
__exportStar(require("./types"), exports);
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.verifyLicense = verifyLicense;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const
|
|
8
|
+
const crypto_js_1 = require("./crypto.js");
|
|
9
9
|
async function verifyLicense(opts) {
|
|
10
10
|
if (!fs_1.default.existsSync(opts.licensePath)) {
|
|
11
11
|
throw new Error("License file not found");
|
|
@@ -18,7 +18,7 @@ async function verifyLicense(opts) {
|
|
|
18
18
|
if (new Date(raw.expiresAt) < new Date()) {
|
|
19
19
|
throw new Error("License expired");
|
|
20
20
|
}
|
|
21
|
-
if (!(0,
|
|
21
|
+
if (!(0, crypto_js_1.verifySignature)(payload, signature)) {
|
|
22
22
|
throw new Error("Invalid license signature");
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "commonjs"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import express, { Router } from "express";
|
|
2
|
+
import http from "http";
|
|
3
|
+
import { loadConfig } from "../config/index.js";
|
|
4
|
+
import { verifyLicense } from "../license/verify.js";
|
|
5
|
+
import { applySecurity } from "./security.js";
|
|
6
|
+
import { initDb } from "../db/index.js";
|
|
7
|
+
import { initJwtAuth } from "../auth/jwt.js";
|
|
8
|
+
export async function createApp(opts) {
|
|
9
|
+
// 1) CONFIG
|
|
10
|
+
const config = loadConfig();
|
|
11
|
+
// 2) LICENSE GATE
|
|
12
|
+
await verifyLicense({
|
|
13
|
+
appId: opts.appId,
|
|
14
|
+
licensePath: config.get("LICENSE_PATH", "./license.json"),
|
|
15
|
+
});
|
|
16
|
+
// 3) EXPRESS INIT
|
|
17
|
+
const app = express();
|
|
18
|
+
const server = http.createServer(app);
|
|
19
|
+
const router = Router();
|
|
20
|
+
if (opts.http?.trustProxy)
|
|
21
|
+
app.set("trust proxy", true);
|
|
22
|
+
// 4) CORE MIDDLEWARE
|
|
23
|
+
applySecurity(app);
|
|
24
|
+
app.use(express.json());
|
|
25
|
+
app.use(express.urlencoded({ extended: false }));
|
|
26
|
+
// 5) DB (non-optional if declared)
|
|
27
|
+
const db = await initDb(opts.db);
|
|
28
|
+
// 6) AUTH
|
|
29
|
+
const auth = initJwtAuth(config);
|
|
30
|
+
// 7) ROUTES
|
|
31
|
+
if (opts.routes) {
|
|
32
|
+
opts.routes({ app, router, db, auth, config });
|
|
33
|
+
}
|
|
34
|
+
app.use(router);
|
|
35
|
+
// 8) ERROR HANDLER
|
|
36
|
+
app.use((err, _req, res, _next) => {
|
|
37
|
+
console.error(err);
|
|
38
|
+
res.status(500).json({ error: "Internal Server Error from web-core" });
|
|
39
|
+
});
|
|
40
|
+
// 9) LIFE CYCLE
|
|
41
|
+
async function start() {
|
|
42
|
+
const port = opts.http?.port ?? config.get("PORT", 3000);
|
|
43
|
+
await new Promise((resolve) => server.listen(port, resolve));
|
|
44
|
+
console.log(`[web-core] listening on ${port}`);
|
|
45
|
+
}
|
|
46
|
+
async function shutdown() {
|
|
47
|
+
if (db?.close)
|
|
48
|
+
await db.close();
|
|
49
|
+
server.close();
|
|
50
|
+
}
|
|
51
|
+
return { app, start, shutdown };
|
|
52
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Express } from "express";
|
|
2
|
+
import cors from "cors";
|
|
3
|
+
export declare const securityConfig: {
|
|
4
|
+
helmet: (req: import("http").IncomingMessage, res: import("http").ServerResponse, next: (err?: unknown) => void) => void;
|
|
5
|
+
cors: (req: cors.CorsRequest, res: {
|
|
6
|
+
statusCode?: number | undefined;
|
|
7
|
+
setHeader(key: string, value: string): any;
|
|
8
|
+
end(): any;
|
|
9
|
+
}, next: (err?: any) => any) => void;
|
|
10
|
+
};
|
|
11
|
+
export declare function applySecurity(app: Express): void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import jwt from "jsonwebtoken";
|
|
2
|
+
import { Config } from "../types.js";
|
|
3
|
+
export declare function verifyToken(token: string, secret: string): string | jwt.JwtPayload;
|
|
4
|
+
export declare function initJwtAuth(config: Config): {
|
|
5
|
+
verify(token: string): string | jwt.JwtPayload;
|
|
6
|
+
middleware(): (req: any, _res: any, next: any) => any;
|
|
7
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import jwt from "jsonwebtoken";
|
|
2
|
+
export function verifyToken(token, secret) {
|
|
3
|
+
return jwt.verify(token, secret);
|
|
4
|
+
}
|
|
5
|
+
export function initJwtAuth(config) {
|
|
6
|
+
const secret = config.get("JWT_SECRET");
|
|
7
|
+
if (!secret)
|
|
8
|
+
throw new Error("JWT_SECRET missing");
|
|
9
|
+
return {
|
|
10
|
+
verify(token) {
|
|
11
|
+
return verifyToken(token, secret);
|
|
12
|
+
},
|
|
13
|
+
middleware() {
|
|
14
|
+
return (req, _res, next) => {
|
|
15
|
+
const h = req.headers.authorization;
|
|
16
|
+
if (!h)
|
|
17
|
+
return next();
|
|
18
|
+
try {
|
|
19
|
+
const token = h.replace("Bearer ", "");
|
|
20
|
+
req.user = verifyToken(token, secret);
|
|
21
|
+
}
|
|
22
|
+
catch { }
|
|
23
|
+
next();
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare function initDb(opts?: {
|
|
2
|
+
type: "postgres";
|
|
3
|
+
uri?: string;
|
|
4
|
+
}): Promise<{
|
|
5
|
+
query: {
|
|
6
|
+
<T extends import("pg").Submittable>(queryStream: T): T;
|
|
7
|
+
<R extends any[] = any[], I = any[]>(queryConfig: import("pg").QueryArrayConfig<I>, values?: import("pg").QueryConfigValues<I>): Promise<import("pg").QueryArrayResult<R>>;
|
|
8
|
+
<R extends import("pg").QueryResultRow = any, I = any>(queryConfig: import("pg").QueryConfig<I>): Promise<import("pg").QueryResult<R>>;
|
|
9
|
+
<R extends import("pg").QueryResultRow = any, I = any[]>(queryTextOrConfig: string | import("pg").QueryConfig<I>, values?: import("pg").QueryConfigValues<I>): Promise<import("pg").QueryResult<R>>;
|
|
10
|
+
<R extends any[] = any[], I = any[]>(queryConfig: import("pg").QueryArrayConfig<I>, callback: (err: Error, result: import("pg").QueryArrayResult<R>) => void): void;
|
|
11
|
+
<R extends import("pg").QueryResultRow = any, I = any[]>(queryTextOrConfig: string | import("pg").QueryConfig<I>, callback: (err: Error, result: import("pg").QueryResult<R>) => void): void;
|
|
12
|
+
<R extends import("pg").QueryResultRow = any, I = any[]>(queryText: string, values: import("pg").QueryConfigValues<I>, callback: (err: Error, result: import("pg").QueryResult<R>) => void): void;
|
|
13
|
+
};
|
|
14
|
+
close: () => Promise<void>;
|
|
15
|
+
} | null>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { initPostgres } from "./postgres.js";
|
|
2
|
+
export async function initDb(opts) {
|
|
3
|
+
if (!opts)
|
|
4
|
+
return null;
|
|
5
|
+
if (opts.type === "postgres") {
|
|
6
|
+
if (!opts.uri)
|
|
7
|
+
throw new Error("Postgres URI required");
|
|
8
|
+
return initPostgres(opts.uri);
|
|
9
|
+
}
|
|
10
|
+
throw new Error("Unsupported DB");
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function initPostgres(uri: string): Promise<{
|
|
2
|
+
query: {
|
|
3
|
+
<T extends import("pg").Submittable>(queryStream: T): T;
|
|
4
|
+
<R extends any[] = any[], I = any[]>(queryConfig: import("pg").QueryArrayConfig<I>, values?: import("pg").QueryConfigValues<I>): Promise<import("pg").QueryArrayResult<R>>;
|
|
5
|
+
<R extends import("pg").QueryResultRow = any, I = any>(queryConfig: import("pg").QueryConfig<I>): Promise<import("pg").QueryResult<R>>;
|
|
6
|
+
<R extends import("pg").QueryResultRow = any, I = any[]>(queryTextOrConfig: string | import("pg").QueryConfig<I>, values?: import("pg").QueryConfigValues<I>): Promise<import("pg").QueryResult<R>>;
|
|
7
|
+
<R extends any[] = any[], I = any[]>(queryConfig: import("pg").QueryArrayConfig<I>, callback: (err: Error, result: import("pg").QueryArrayResult<R>) => void): void;
|
|
8
|
+
<R extends import("pg").QueryResultRow = any, I = any[]>(queryTextOrConfig: string | import("pg").QueryConfig<I>, callback: (err: Error, result: import("pg").QueryResult<R>) => void): void;
|
|
9
|
+
<R extends import("pg").QueryResultRow = any, I = any[]>(queryText: string, values: import("pg").QueryConfigValues<I>, callback: (err: Error, result: import("pg").QueryResult<R>) => void): void;
|
|
10
|
+
};
|
|
11
|
+
close: () => Promise<void>;
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CreateFrameworkAppOptions } from "./types.js";
|
|
2
|
+
export declare function createH3App(opts: CreateFrameworkAppOptions): Promise<{
|
|
3
|
+
db: {
|
|
4
|
+
query: {
|
|
5
|
+
<T extends import("pg").Submittable>(queryStream: T): T;
|
|
6
|
+
<R extends any[] = any[], I = any[]>(queryConfig: import("pg").QueryArrayConfig<I>, values?: import("pg").QueryConfigValues<I>): Promise<import("pg").QueryArrayResult<R>>;
|
|
7
|
+
<R extends import("pg").QueryResultRow = any, I = any>(queryConfig: import("pg").QueryConfig<I>): Promise<import("pg").QueryResult<R>>;
|
|
8
|
+
<R extends import("pg").QueryResultRow = any, I = any[]>(queryTextOrConfig: string | import("pg").QueryConfig<I>, values?: import("pg").QueryConfigValues<I>): Promise<import("pg").QueryResult<R>>;
|
|
9
|
+
<R extends any[] = any[], I = any[]>(queryConfig: import("pg").QueryArrayConfig<I>, callback: (err: Error, result: import("pg").QueryArrayResult<R>) => void): void;
|
|
10
|
+
<R extends import("pg").QueryResultRow = any, I = any[]>(queryTextOrConfig: string | import("pg").QueryConfig<I>, callback: (err: Error, result: import("pg").QueryResult<R>) => void): void;
|
|
11
|
+
<R extends import("pg").QueryResultRow = any, I = any[]>(queryText: string, values: import("pg").QueryConfigValues<I>, callback: (err: Error, result: import("pg").QueryResult<R>) => void): void;
|
|
12
|
+
};
|
|
13
|
+
close: () => Promise<void>;
|
|
14
|
+
} | null;
|
|
15
|
+
auth: {
|
|
16
|
+
verify(token: string): string | import("jsonwebtoken").JwtPayload;
|
|
17
|
+
middleware(): (req: any, _res: any, next: any) => any;
|
|
18
|
+
};
|
|
19
|
+
config: import("../types.js").Config;
|
|
20
|
+
verifySession: (event: any) => Promise<string | import("jsonwebtoken").JwtPayload | null>;
|
|
21
|
+
}>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { loadConfig } from "../config/index.js";
|
|
2
|
+
import { verifyLicense } from "../license/verify.js";
|
|
3
|
+
import { initJwtAuth } from "../auth/jwt.js";
|
|
4
|
+
import { initDb } from "../db/index.js";
|
|
5
|
+
// H3 is often used in Nuxt or Nitro. We don't import h3 directly to avoid hard dependency,
|
|
6
|
+
// but we assume the user passes the event or app instance if needed.
|
|
7
|
+
// For now, we return a setup object similar to Next.js
|
|
8
|
+
export async function createH3App(opts) {
|
|
9
|
+
const config = loadConfig();
|
|
10
|
+
// License Check
|
|
11
|
+
await verifyLicense({
|
|
12
|
+
appId: opts.appId,
|
|
13
|
+
licensePath: config.get("LICENSE_PATH", "./license.json"),
|
|
14
|
+
});
|
|
15
|
+
const db = await initDb({ type: "postgres" });
|
|
16
|
+
const auth = initJwtAuth(config);
|
|
17
|
+
return {
|
|
18
|
+
db,
|
|
19
|
+
auth,
|
|
20
|
+
config,
|
|
21
|
+
verifySession: async (event) => {
|
|
22
|
+
// H3 event structure abstraction
|
|
23
|
+
const h = event.node?.req?.headers?.authorization || event.headers?.get("authorization");
|
|
24
|
+
if (!h)
|
|
25
|
+
return null;
|
|
26
|
+
try {
|
|
27
|
+
const token = h.replace("Bearer ", "");
|
|
28
|
+
return auth.verify(token);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CreateFrameworkAppOptions } from "./types.js";
|
|
2
|
+
export declare function createNextApp(opts: CreateFrameworkAppOptions): Promise<{
|
|
3
|
+
db: {
|
|
4
|
+
query: {
|
|
5
|
+
<T extends import("pg").Submittable>(queryStream: T): T;
|
|
6
|
+
<R extends any[] = any[], I = any[]>(queryConfig: import("pg").QueryArrayConfig<I>, values?: import("pg").QueryConfigValues<I>): Promise<import("pg").QueryArrayResult<R>>;
|
|
7
|
+
<R extends import("pg").QueryResultRow = any, I = any>(queryConfig: import("pg").QueryConfig<I>): Promise<import("pg").QueryResult<R>>;
|
|
8
|
+
<R extends import("pg").QueryResultRow = any, I = any[]>(queryTextOrConfig: string | import("pg").QueryConfig<I>, values?: import("pg").QueryConfigValues<I>): Promise<import("pg").QueryResult<R>>;
|
|
9
|
+
<R extends any[] = any[], I = any[]>(queryConfig: import("pg").QueryArrayConfig<I>, callback: (err: Error, result: import("pg").QueryArrayResult<R>) => void): void;
|
|
10
|
+
<R extends import("pg").QueryResultRow = any, I = any[]>(queryTextOrConfig: string | import("pg").QueryConfig<I>, callback: (err: Error, result: import("pg").QueryResult<R>) => void): void;
|
|
11
|
+
<R extends import("pg").QueryResultRow = any, I = any[]>(queryText: string, values: import("pg").QueryConfigValues<I>, callback: (err: Error, result: import("pg").QueryResult<R>) => void): void;
|
|
12
|
+
};
|
|
13
|
+
close: () => Promise<void>;
|
|
14
|
+
} | null;
|
|
15
|
+
auth: {
|
|
16
|
+
verify(token: string): string | import("jsonwebtoken").JwtPayload;
|
|
17
|
+
middleware(): (req: any, _res: any, next: any) => any;
|
|
18
|
+
};
|
|
19
|
+
config: import("../types.js").Config;
|
|
20
|
+
verifySession: (req: Request) => Promise<string | import("jsonwebtoken").JwtPayload | null>;
|
|
21
|
+
}>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { loadConfig } from "../config/index.js";
|
|
2
|
+
import { verifyLicense } from "../license/verify.js";
|
|
3
|
+
import { initJwtAuth } from "../auth/jwt.js";
|
|
4
|
+
import { initDb } from "../db/index.js";
|
|
5
|
+
export async function createNextApp(opts) {
|
|
6
|
+
const config = loadConfig();
|
|
7
|
+
// License Check
|
|
8
|
+
await verifyLicense({
|
|
9
|
+
appId: opts.appId,
|
|
10
|
+
licensePath: config.get("LICENSE_PATH", "./license.json"),
|
|
11
|
+
});
|
|
12
|
+
const db = await initDb({ type: "postgres" }); // Defaulting to existing DB logic
|
|
13
|
+
const auth = initJwtAuth(config);
|
|
14
|
+
return {
|
|
15
|
+
db,
|
|
16
|
+
auth,
|
|
17
|
+
config,
|
|
18
|
+
verifySession: async (req) => {
|
|
19
|
+
const h = req.headers.get("authorization");
|
|
20
|
+
if (!h)
|
|
21
|
+
return null;
|
|
22
|
+
try {
|
|
23
|
+
const token = h.replace("Bearer ", "");
|
|
24
|
+
return auth.verify(token);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Config } from "../types.js";
|
|
2
|
+
export interface WebCoreRequest {
|
|
3
|
+
headers: Record<string, string | string[] | undefined>;
|
|
4
|
+
url?: string;
|
|
5
|
+
method?: string;
|
|
6
|
+
body?: any;
|
|
7
|
+
}
|
|
8
|
+
export interface WebCoreResponse {
|
|
9
|
+
status(code: number): WebCoreResponse;
|
|
10
|
+
json(body: any): WebCoreResponse;
|
|
11
|
+
send(body: any): WebCoreResponse;
|
|
12
|
+
setHeader(key: string, value: string): WebCoreResponse;
|
|
13
|
+
}
|
|
14
|
+
export interface WebCoreContext {
|
|
15
|
+
config: Config;
|
|
16
|
+
auth: {
|
|
17
|
+
verify(token: string): any;
|
|
18
|
+
};
|
|
19
|
+
db?: any;
|
|
20
|
+
}
|
|
21
|
+
export interface CreateFrameworkAppOptions {
|
|
22
|
+
appId: string;
|
|
23
|
+
config?: Record<string, any>;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.createH3App = exports.createNextApp = exports.createApp = void 0;
|
|
18
|
+
var createApp_1 = require("./app/createApp");
|
|
19
|
+
Object.defineProperty(exports, "createApp", { enumerable: true, get: function () { return createApp_1.createApp; } });
|
|
20
|
+
var next_1 = require("./frameworks/next");
|
|
21
|
+
Object.defineProperty(exports, "createNextApp", { enumerable: true, get: function () { return next_1.createNextApp; } });
|
|
22
|
+
var h3_1 = require("./frameworks/h3");
|
|
23
|
+
Object.defineProperty(exports, "createH3App", { enumerable: true, get: function () { return h3_1.createH3App; } });
|
|
24
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function verifySignature(payload: object, signature: string): boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
const PUBLIC_KEY = `
|
|
3
|
+
-----BEGIN PUBLIC KEY-----
|
|
4
|
+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsU0BSgfcYaHOuWuNRQEw
|
|
5
|
+
t3HyMf+UY+RAVGf0bDmdXIyp5fPol5K86jol45lIaxdbkMpPqODmr/lU0dDBOIwy
|
|
6
|
+
wlhbAQb0nLsIMQf3M6lNw6OtI0EnlZd2xhfisfu1XH9UBbn7Q6W2+i22rZhKC3yY
|
|
7
|
+
8E7Dntgl7IkItjEFFpnbA4tCY6yTGhGfAx/4O977Vw2ET6m5SVcFVlKs0OxekRc0
|
|
8
|
+
7rcgCTwSjHPkMumVc7zv+rfZPkhULN76ju26gcuR19xd+gNq3qLGgJ9hcDITmuwP
|
|
9
|
+
FE212I94elpNRNbrX7MUqVX3o7trE5CqxH42NuGP20edSWcKqpvqLFPSnlsSvhUp
|
|
10
|
+
MQIDAQAB
|
|
11
|
+
-----END PUBLIC KEY-----
|
|
12
|
+
`;
|
|
13
|
+
export function verifySignature(payload, signature) {
|
|
14
|
+
const verify = crypto.createVerify("RSA-SHA256");
|
|
15
|
+
verify.update(JSON.stringify(payload));
|
|
16
|
+
verify.end();
|
|
17
|
+
return verify.verify(PUBLIC_KEY, Buffer.from(signature, "base64"));
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { verifySignature } from "./crypto.js";
|
|
3
|
+
export async function verifyLicense(opts) {
|
|
4
|
+
if (!fs.existsSync(opts.licensePath)) {
|
|
5
|
+
throw new Error("License file not found");
|
|
6
|
+
}
|
|
7
|
+
const raw = JSON.parse(fs.readFileSync(opts.licensePath, "utf8"));
|
|
8
|
+
const { signature, ...payload } = raw;
|
|
9
|
+
if (raw.appId !== opts.appId) {
|
|
10
|
+
throw new Error("License appId mismatch");
|
|
11
|
+
}
|
|
12
|
+
if (new Date(raw.expiresAt) < new Date()) {
|
|
13
|
+
throw new Error("License expired");
|
|
14
|
+
}
|
|
15
|
+
if (!verifySignature(payload, signature)) {
|
|
16
|
+
throw new Error("Invalid license signature");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Express, Router } from "express";
|
|
2
|
+
export interface CreateAppOptions {
|
|
3
|
+
appId: string;
|
|
4
|
+
http?: {
|
|
5
|
+
port?: number;
|
|
6
|
+
trustProxy?: boolean;
|
|
7
|
+
};
|
|
8
|
+
db?: {
|
|
9
|
+
type: "postgres";
|
|
10
|
+
uri?: string;
|
|
11
|
+
};
|
|
12
|
+
auth?: {
|
|
13
|
+
provider: "jwt";
|
|
14
|
+
};
|
|
15
|
+
routes?: (ctx: AppContext) => void;
|
|
16
|
+
}
|
|
17
|
+
export interface AppContext {
|
|
18
|
+
app: Express;
|
|
19
|
+
router: Router;
|
|
20
|
+
db: any;
|
|
21
|
+
auth: {
|
|
22
|
+
middleware(): any;
|
|
23
|
+
};
|
|
24
|
+
config: Config;
|
|
25
|
+
}
|
|
26
|
+
export interface Config {
|
|
27
|
+
get<T = any>(key: string, fallback?: T): T;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cored3v/web-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Reusable licensed Express core for web applications",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/cjs/index.cjs",
|
|
7
|
+
"module": "./dist/esm/index.mjs",
|
|
8
|
+
"types": "./dist/esm/index.esm.d.ts",
|
|
7
9
|
"files": [
|
|
8
10
|
"dist"
|
|
9
11
|
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/esm/index.mjs",
|
|
15
|
+
"require": "./dist/cjs/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
10
18
|
"scripts": {
|
|
11
|
-
"build": "tsc",
|
|
19
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
20
|
+
"build:cjs": "tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json",
|
|
21
|
+
"build": "npm run build:esm && npm run build:cjs",
|
|
12
22
|
"prepublishOnly": "npm run build"
|
|
13
23
|
},
|
|
14
24
|
"dependencies": {
|
|
@@ -24,6 +34,9 @@
|
|
|
24
34
|
"@types/jsonwebtoken": "^9.0.6",
|
|
25
35
|
"@types/node": "^20.11.0",
|
|
26
36
|
"@types/pg": "^8.16.0",
|
|
27
|
-
"
|
|
37
|
+
"pg-protocol": "^1.10.3",
|
|
38
|
+
"pg-types": "^4.1.0",
|
|
39
|
+
"typescript": "^5.4.0",
|
|
40
|
+
"undici-types": "^7.18.2"
|
|
28
41
|
}
|
|
29
42
|
}
|
package/dist/app/security.d.ts
DELETED
package/dist/auth/jwt.d.ts
DELETED
package/dist/index.d.ts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|