@cored3v/web-core 1.0.2 → 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 CHANGED
@@ -1,9 +1,107 @@
1
1
  # @cored3v/web-core
2
2
 
3
- A reusable, production-ready **Express.js application core** that provides
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
- This package is designed to protect source code by teams and consultants against unauthorised use.
5
+ It supports **Express.js**, **Next.js**, **Nuxt (H3)**, and generic Node.js environments.
8
6
 
9
- The package supports both ESModule and CommonJS imports.
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.
@@ -1,2 +1,11 @@
1
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
+ };
2
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((0, helmet_1.default)());
11
- app.use((0, cors_1.default)());
15
+ app.use(exports.securityConfig.helmet);
16
+ app.use(exports.securityConfig.cors);
12
17
  }
@@ -1,4 +1,7 @@
1
+ import jwt from "jsonwebtoken";
1
2
  import { Config } from "../types.js";
3
+ export declare function verifyToken(token: string, secret: string): string | jwt.JwtPayload;
2
4
  export declare function initJwtAuth(config: Config): {
5
+ verify(token: string): string | jwt.JwtPayload;
3
6
  middleware(): (req: any, _res: any, next: any) => any;
4
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 = jsonwebtoken_1.default.verify(token, secret);
27
+ req.user = verifyToken(token, secret);
21
28
  }
22
29
  catch { }
23
30
  next();
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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);
@@ -1,2 +1,4 @@
1
1
  export { createApp } from "./app/createApp";
2
+ export { createNextApp } from "./frameworks/next";
3
+ export { createH3App } from "./frameworks/h3";
2
4
  export * from "./types";
@@ -1,2 +1,4 @@
1
1
  export { createApp } from "./app/createApp.js";
2
+ export { createNextApp } from "./frameworks/next.js";
3
+ export { createH3App } from "./frameworks/h3.js";
2
4
  export * from "./types.js";
@@ -1,3 +1,5 @@
1
1
  "use strict";
2
2
  export { createApp } from "./app/createApp.js";
3
+ export { createNextApp } from "./frameworks/next.js";
4
+ export { createH3App } from "./frameworks/h3.js";
3
5
  export * from "./types.js";
@@ -1,2 +1,11 @@
1
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
+ };
2
11
  export declare function applySecurity(app: Express): void;
@@ -1,6 +1,10 @@
1
1
  import helmet from "helmet";
2
2
  import cors from "cors";
3
+ export const securityConfig = {
4
+ helmet: helmet(),
5
+ cors: cors()
6
+ };
3
7
  export function applySecurity(app) {
4
- app.use(helmet());
5
- app.use(cors());
8
+ app.use(securityConfig.helmet);
9
+ app.use(securityConfig.cors);
6
10
  }
@@ -1,4 +1,7 @@
1
+ import jwt from "jsonwebtoken";
1
2
  import { Config } from "../types.js";
3
+ export declare function verifyToken(token: string, secret: string): string | jwt.JwtPayload;
2
4
  export declare function initJwtAuth(config: Config): {
5
+ verify(token: string): string | jwt.JwtPayload;
3
6
  middleware(): (req: any, _res: any, next: any) => any;
4
7
  };
@@ -1,9 +1,15 @@
1
1
  import jwt from "jsonwebtoken";
2
+ export function verifyToken(token, secret) {
3
+ return jwt.verify(token, secret);
4
+ }
2
5
  export function initJwtAuth(config) {
3
6
  const secret = config.get("JWT_SECRET");
4
7
  if (!secret)
5
8
  throw new Error("JWT_SECRET missing");
6
9
  return {
10
+ verify(token) {
11
+ return verifyToken(token, secret);
12
+ },
7
13
  middleware() {
8
14
  return (req, _res, next) => {
9
15
  const h = req.headers.authorization;
@@ -11,7 +17,7 @@ export function initJwtAuth(config) {
11
17
  return next();
12
18
  try {
13
19
  const token = h.replace("Bearer ", "");
14
- req.user = jwt.verify(token, secret);
20
+ req.user = verifyToken(token, secret);
15
21
  }
16
22
  catch { }
17
23
  next();
@@ -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 {};
@@ -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);
@@ -1,2 +1,4 @@
1
1
  export { createApp } from "./app/createApp";
2
+ export { createNextApp } from "./frameworks/next";
3
+ export { createH3App } from "./frameworks/h3";
2
4
  export * from "./types";
@@ -1,2 +1,4 @@
1
1
  export { createApp } from "./app/createApp.js";
2
+ export { createNextApp } from "./frameworks/next.js";
3
+ export { createH3App } from "./frameworks/h3.js";
2
4
  export * from "./types.js";
@@ -1,2 +1,4 @@
1
1
  export { createApp } from "./app/createApp.js";
2
+ export { createNextApp } from "./frameworks/next.js";
3
+ export { createH3App } from "./frameworks/h3.js";
2
4
  export * from "./types.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cored3v/web-core",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Reusable licensed Express core for web applications",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.cjs",
@@ -39,4 +39,4 @@
39
39
  "typescript": "^5.4.0",
40
40
  "undici-types": "^7.18.2"
41
41
  }
42
- }
42
+ }