nexus-backend 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 CHANGED
@@ -21,13 +21,14 @@ A lightweight backend utility library for [Express.js](https://expressjs.com/) p
21
21
  ## Installation
22
22
 
23
23
  ```bash
24
- npm install nexus-backend
24
+
25
+ npm install express mongoose cors helmet morgan cookie-parser
25
26
  ```
26
27
 
27
- Express is a peer dependency — make sure it is installed in your project:
28
+ Express, mongoose, cors, helmet, morgan, and cookie-parser are peer dependencies — make sure they are installed in your project:
28
29
 
29
30
  ```bash
30
- npm install express
31
+ npm install nexus-backend
31
32
  ```
32
33
 
33
34
  ---
@@ -35,39 +36,97 @@ npm install express
35
36
  ## Quick Start
36
37
 
37
38
  ```ts
38
- import express from "express";
39
+ // src/config/mongoConfig.ts
40
+ import { type MongoConfig } from "nexus-backend";
41
+
42
+ const dbConfig: MongoConfig = {
43
+ subDomain: requiredEnv(process.env.DB_HOST, "DB_HOST"),
44
+ userName: requiredEnv(process.env.DB_USERNAME, "DB_USERNAME"),
45
+ password: requiredEnv(process.env.DB_PASSWORD, "DB_PASSWORD"),
46
+ cluster: requiredEnv(process.env.DB_CLUSTER, "DB_CLUSTER"),
47
+ dbName: requiredEnv(process.env.DB_NAME, "DB_NAME"),
48
+ };
49
+ export default dbConfig;
50
+ ```
51
+
52
+ ```ts
53
+ // src/server.ts
54
+ import express, { type Application, Request, Response } from "express";
55
+ import http from "http";
39
56
  import {
40
57
  successResponse,
41
58
  errorMiddleware,
42
59
  NotFoundError,
43
60
  ValidationError,
44
61
  } from "nexus-backend";
62
+ import cors from "cors";
63
+ import helmet from "helmet";
64
+ import morgan from "morgan";
65
+ import cookieParser from "cookie-parser";
66
+ import { Server } from "socket.io";
45
67
 
46
- const app = express();
47
- app.use(express.json());
68
+ const app: Application = express();
48
69
 
49
- // Example route
50
- app.get("/users/:id", async (req, res, next) => {
51
- try {
52
- const user = await getUserById(req.params.id);
70
+ if (process.env.NODE_ENV !== "production") {
71
+ app.use(morgan("dev"));
72
+ }
73
+ app.set("trust proxy", 1);
74
+ app.use(helmet());
75
+ app.use(
76
+ cors({
77
+ origin: process.env.FRONTEND_URL,
78
+ credentials: true,
79
+ }),
80
+ );
53
81
 
54
- if (!user) {
55
- throw new NotFoundError("User not found");
56
- }
82
+ app.use(express.json({ limit: "500mb" })); // Adjust the limit as needed
83
+ app.use(express.urlencoded({ extended: true, limit: "500mb" })); // For parsing application/x-www-form-urlencoded
84
+ app.use(cookieParser());
57
85
 
58
- res.json(successResponse(user, "User fetched successfully"));
59
- } catch (err) {
60
- next(err);
86
+ // Example route
87
+ app.get("/users/:id", async (req: Request, res: Response) => {
88
+ const user = await getUserById(req.params.id);
89
+
90
+ if (!user) {
91
+ throw new NotFoundError("User not found");
61
92
  }
93
+
94
+ res.json(successResponse(user, "User fetched successfully"));
62
95
  });
63
96
 
64
97
  // Register error middleware last
65
98
  app.use(errorMiddleware);
99
+ const server = http.createServer(app);
100
+ export const io = new Server(server, {
101
+ cors: {
102
+ origin: process.env.FRONTEND_URL,
103
+ credentials: true,
104
+ },
105
+ });
66
106
 
67
- app.listen(3000);
107
+ export default server;
68
108
  ```
69
109
 
70
- ---
110
+ ```ts
111
+ // src/index.ts
112
+ import "dotenv/config";
113
+ import { connectMongoDb } from "nexus-backend";
114
+ import dns from "dns";
115
+ import dbConfig from "./config/mongoConfig";
116
+ import server from "./server";
117
+ const PORT = process.env.PORT || 5000;
118
+ async () => {
119
+ dns.setServers(["1.1.1.1", "1.0.0.1"]);
120
+ const dbConnected = await connectMongoDb(dbConfig);
121
+ if (!dbConnected) {
122
+ console.error("Database connection failed. Exiting...");
123
+ process.exit(1);
124
+ }
125
+ server.listen(PORT, () => {
126
+ console.log(`Server running on ${PORT}`);
127
+ });
128
+ };
129
+ ```
71
130
 
72
131
  ## API Reference
73
132
 
@@ -84,9 +143,9 @@ successResponse<T>(data: T, message?: string): SuccessResponse<T>
84
143
  **Example**
85
144
 
86
145
  ```ts
87
- res.status(200).json(
88
- successResponse({ id: 1, name: "Alice" }, "User fetched successfully")
89
- );
146
+ res
147
+ .status(200)
148
+ .json(successResponse({ id: 1, name: "Alice" }, "User fetched successfully"));
90
149
  ```
91
150
 
92
151
  ```json
@@ -110,9 +169,11 @@ errorResponse(message: string, errors?: any, stack?: string): ErrorResponse
110
169
  **Example**
111
170
 
112
171
  ```ts
113
- res.status(400).json(
114
- errorResponse("Validation failed", { field: "email", issue: "Required" })
115
- );
172
+ res
173
+ .status(400)
174
+ .json(
175
+ errorResponse("Validation failed", { field: "email", issue: "Required" }),
176
+ );
116
177
  ```
117
178
 
118
179
  ```json
@@ -137,12 +198,12 @@ The base error class. Use this when none of the specific subclasses fit your use
137
198
  new ApiError(message: string, statusCode?: number, errors?: any, isOperational?: boolean)
138
199
  ```
139
200
 
140
- | Parameter | Type | Default | Description |
141
- |---|---|---|---|
142
- | `message` | `string` | — | Human-readable error message |
143
- | `statusCode` | `number` | `500` | HTTP status code |
144
- | `errors` | `any` | `undefined` | Additional error details or field errors |
145
- | `isOperational` | `boolean` | `true` | Marks the error as an expected operational error |
201
+ | Parameter | Type | Default | Description |
202
+ | --------------- | --------- | ----------- | ------------------------------------------------ |
203
+ | `message` | `string` | — | Human-readable error message |
204
+ | `statusCode` | `number` | `500` | HTTP status code |
205
+ | `errors` | `any` | `undefined` | Additional error details or field errors |
206
+ | `isOperational` | `boolean` | `true` | Marks the error as an expected operational error |
146
207
 
147
208
  ---
148
209
 
@@ -285,4 +346,4 @@ type ApiResult<T> = SuccessResponse<T> | ErrorResponse;
285
346
 
286
347
  ## License
287
348
 
288
- MIT
349
+ MIT
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Request, Response, NextFunction } from 'express';
2
+ import NodeCache from 'node-cache';
2
3
 
3
4
  interface SuccessResponse<T = any> {
4
5
  success: true;
@@ -16,6 +17,18 @@ declare const successResponse: <T>(data: T, message?: string) => SuccessResponse
16
17
 
17
18
  declare const errorResponse: (message: string, errors?: any, stack?: string) => ErrorResponse;
18
19
 
20
+ declare const requiredEnv: (value: string | undefined, key: string) => string;
21
+
22
+ interface MongoConfig {
23
+ subDomain: string;
24
+ userName: string;
25
+ password: string;
26
+ cluster: string;
27
+ dbName: string;
28
+ }
29
+
30
+ declare const connectMongoDb: (config: MongoConfig) => Promise<boolean>;
31
+
19
32
  declare class ApiError extends Error {
20
33
  statusCode: number;
21
34
  isOperational: boolean;
@@ -48,4 +61,25 @@ declare const errorHandler: [
48
61
  (err: any, req: Request, res: Response, next: NextFunction) => void
49
62
  ];
50
63
 
51
- export { ApiError, BadRequestError, type ErrorResponse, ForbiddenError, NotFoundError, type SuccessResponse, UnauthorizedError, ValidationError, errorHandler as errorMiddleware, errorResponse, successResponse };
64
+ type CacheValue = unknown;
65
+ type ComputeFn<T> = () => Promise<T> | T;
66
+ declare class Cache extends NodeCache {
67
+ private namespaces;
68
+ private tagMap;
69
+ constructor(options?: NodeCache.Options);
70
+ private getKey;
71
+ private removeKeyFromTags;
72
+ setItem(key: string, value: CacheValue, ttl?: number, namespace?: string, tags?: string[]): void;
73
+ getItem<T = unknown>(key: string, namespace?: string): T | undefined;
74
+ getOrSetItem<T>(key: string, computeFn: ComputeFn<T>, ttl?: number, namespace?: string, tags?: string[]): Promise<T>;
75
+ deleteItem(key: string, namespace?: string): number;
76
+ clearNamespace(namespace?: string): void;
77
+ /**
78
+ * Delete all keys associated with a tag
79
+ */
80
+ clearTag(tag: string): void;
81
+ }
82
+
83
+ declare const cacheMemory: Cache;
84
+
85
+ export { ApiError, BadRequestError, Cache, type ErrorResponse, ForbiddenError, type MongoConfig, NotFoundError, type SuccessResponse, UnauthorizedError, ValidationError, cacheMemory, connectMongoDb, errorHandler as errorMiddleware, errorResponse, requiredEnv, successResponse };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Request, Response, NextFunction } from 'express';
2
+ import NodeCache from 'node-cache';
2
3
 
3
4
  interface SuccessResponse<T = any> {
4
5
  success: true;
@@ -16,6 +17,18 @@ declare const successResponse: <T>(data: T, message?: string) => SuccessResponse
16
17
 
17
18
  declare const errorResponse: (message: string, errors?: any, stack?: string) => ErrorResponse;
18
19
 
20
+ declare const requiredEnv: (value: string | undefined, key: string) => string;
21
+
22
+ interface MongoConfig {
23
+ subDomain: string;
24
+ userName: string;
25
+ password: string;
26
+ cluster: string;
27
+ dbName: string;
28
+ }
29
+
30
+ declare const connectMongoDb: (config: MongoConfig) => Promise<boolean>;
31
+
19
32
  declare class ApiError extends Error {
20
33
  statusCode: number;
21
34
  isOperational: boolean;
@@ -48,4 +61,25 @@ declare const errorHandler: [
48
61
  (err: any, req: Request, res: Response, next: NextFunction) => void
49
62
  ];
50
63
 
51
- export { ApiError, BadRequestError, type ErrorResponse, ForbiddenError, NotFoundError, type SuccessResponse, UnauthorizedError, ValidationError, errorHandler as errorMiddleware, errorResponse, successResponse };
64
+ type CacheValue = unknown;
65
+ type ComputeFn<T> = () => Promise<T> | T;
66
+ declare class Cache extends NodeCache {
67
+ private namespaces;
68
+ private tagMap;
69
+ constructor(options?: NodeCache.Options);
70
+ private getKey;
71
+ private removeKeyFromTags;
72
+ setItem(key: string, value: CacheValue, ttl?: number, namespace?: string, tags?: string[]): void;
73
+ getItem<T = unknown>(key: string, namespace?: string): T | undefined;
74
+ getOrSetItem<T>(key: string, computeFn: ComputeFn<T>, ttl?: number, namespace?: string, tags?: string[]): Promise<T>;
75
+ deleteItem(key: string, namespace?: string): number;
76
+ clearNamespace(namespace?: string): void;
77
+ /**
78
+ * Delete all keys associated with a tag
79
+ */
80
+ clearTag(tag: string): void;
81
+ }
82
+
83
+ declare const cacheMemory: Cache;
84
+
85
+ export { ApiError, BadRequestError, Cache, type ErrorResponse, ForbiddenError, type MongoConfig, NotFoundError, type SuccessResponse, UnauthorizedError, ValidationError, cacheMemory, connectMongoDb, errorHandler as errorMiddleware, errorResponse, requiredEnv, successResponse };
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
@@ -22,12 +32,16 @@ var index_exports = {};
22
32
  __export(index_exports, {
23
33
  ApiError: () => ApiError,
24
34
  BadRequestError: () => BadRequestError,
35
+ Cache: () => Cache,
25
36
  ForbiddenError: () => ForbiddenError,
26
37
  NotFoundError: () => NotFoundError,
27
38
  UnauthorizedError: () => UnauthorizedError,
28
39
  ValidationError: () => ValidationError,
40
+ cacheMemory: () => cacheMemory_default,
41
+ connectMongoDb: () => connectMongoDb,
29
42
  errorMiddleware: () => errorHandler_default,
30
43
  errorResponse: () => errorResponse,
44
+ requiredEnv: () => requiredEnv,
31
45
  successResponse: () => successResponse
32
46
  });
33
47
  module.exports = __toCommonJS(index_exports);
@@ -47,6 +61,39 @@ var errorResponse = (message, errors, stack) => ({
47
61
  stack
48
62
  });
49
63
 
64
+ // src/utils/envManager.ts
65
+ var requiredEnv = (value, key) => {
66
+ if (!value) {
67
+ throw new Error(`Missing required environment variable: ${key}`);
68
+ }
69
+ return value;
70
+ };
71
+
72
+ // src/config/mongoConfig.ts
73
+ var import_mongoose = __toESM(require("mongoose"));
74
+ var connectMongoDb = async (config) => {
75
+ const { subDomain, userName, password, cluster, dbName } = config;
76
+ const srvURL = `mongodb+srv://${userName}:${password}@${cluster.toLowerCase()}.${subDomain}.mongodb.net/${dbName}?retryWrites=true&w=majority&appName=${cluster.toLowerCase()}`;
77
+ const fallbackURL = `mongodb://${userName}:${password}@ac-hkntio7-shard-00-00.${subDomain}.mongodb.net:27017,ac-hkntio7-shard-00-01.${subDomain}.mongodb.net:27017,ac-hkntio7-shard-00-02.${subDomain}.mongodb.net:27017/${dbName}?ssl=true&replicaSet=atlas-cji6jk-shard-0&authSource=admin&appName=${cluster}`;
78
+ try {
79
+ console.log("Trying primary +srv connection...");
80
+ await import_mongoose.default.connect(srvURL);
81
+ console.log("Connected to MongoDB Atlas via +srv URL");
82
+ return true;
83
+ } catch (err) {
84
+ console.warn("+srv connection failed:", err.message);
85
+ console.log("Trying fallback standard connection...");
86
+ try {
87
+ await import_mongoose.default.connect(fallbackURL);
88
+ console.log("Connected to MongoDB Atlas via fallback URL");
89
+ return true;
90
+ } catch (fallbackErr) {
91
+ console.error("Fallback connection failed:", fallbackErr.message);
92
+ return false;
93
+ }
94
+ }
95
+ };
96
+
50
97
  // src/errors/ApiError.ts
51
98
  var ApiError = class extends Error {
52
99
  constructor(message, statusCode = 500, errors, isOperational = true) {
@@ -115,16 +162,118 @@ var globalErrorHandler = (err, req, res, next) => {
115
162
  };
116
163
  var errorHandler = [routeNotFoundHandler, globalErrorHandler];
117
164
  var errorHandler_default = errorHandler;
165
+
166
+ // src/utils/cache.ts
167
+ var import_node_cache = __toESM(require("node-cache"));
168
+ var Cache = class extends import_node_cache.default {
169
+ constructor(options = {}) {
170
+ const defaults = {
171
+ stdTTL: 60,
172
+ checkperiod: 120
173
+ };
174
+ super({ ...defaults, ...options });
175
+ this.namespaces = /* @__PURE__ */ new Set();
176
+ this.tagMap = /* @__PURE__ */ new Map();
177
+ this.on("expired", (key, value) => {
178
+ console.log(`[Cache] Key expired: ${key} ->`, value);
179
+ this.removeKeyFromTags(key);
180
+ });
181
+ }
182
+ getKey(key, namespace) {
183
+ return namespace ? `${namespace}:${key}` : key;
184
+ }
185
+ removeKeyFromTags(key) {
186
+ for (const [tag, keys] of this.tagMap.entries()) {
187
+ if (keys.has(key)) {
188
+ keys.delete(key);
189
+ if (keys.size === 0) {
190
+ this.tagMap.delete(tag);
191
+ }
192
+ }
193
+ }
194
+ }
195
+ setItem(key, value, ttl = 60, namespace, tags = []) {
196
+ const fullKey = this.getKey(key, namespace);
197
+ if (namespace) {
198
+ this.namespaces.add(namespace);
199
+ }
200
+ const storedValue = typeof value === "string" ? value : JSON.stringify(value);
201
+ this.set(fullKey, storedValue, ttl);
202
+ for (const tag of tags) {
203
+ if (!this.tagMap.has(tag)) {
204
+ this.tagMap.set(tag, /* @__PURE__ */ new Set());
205
+ }
206
+ this.tagMap.get(tag).add(fullKey);
207
+ }
208
+ }
209
+ getItem(key, namespace) {
210
+ const fullKey = this.getKey(key, namespace);
211
+ const value = this.get(fullKey);
212
+ if (value === void 0) return void 0;
213
+ try {
214
+ return JSON.parse(value);
215
+ } catch {
216
+ return value;
217
+ }
218
+ }
219
+ async getOrSetItem(key, computeFn, ttl, namespace, tags = []) {
220
+ let value = this.getItem(key, namespace);
221
+ if (value === void 0) {
222
+ value = await computeFn();
223
+ this.setItem(key, value, ttl, namespace, tags);
224
+ }
225
+ return value;
226
+ }
227
+ deleteItem(key, namespace) {
228
+ const fullKey = this.getKey(key, namespace);
229
+ this.removeKeyFromTags(fullKey);
230
+ return this.del(fullKey);
231
+ }
232
+ clearNamespace(namespace) {
233
+ if (!namespace) {
234
+ this.flushAll();
235
+ this.tagMap.clear();
236
+ console.log("[Cache] All keys cleared");
237
+ return;
238
+ }
239
+ for (const key of this.keys()) {
240
+ if (key.startsWith(`${namespace}:`)) {
241
+ this.deleteItem(key);
242
+ }
243
+ }
244
+ console.log(`[Cache] Namespace "${namespace}" cleared`);
245
+ }
246
+ /**
247
+ * Delete all keys associated with a tag
248
+ */
249
+ clearTag(tag) {
250
+ const keys = this.tagMap.get(tag);
251
+ if (!keys) return;
252
+ for (const key of keys) {
253
+ this.del(key);
254
+ }
255
+ this.tagMap.delete(tag);
256
+ console.log(`[Cache] All keys with tag "${tag}" cleared`);
257
+ }
258
+ };
259
+
260
+ // src/utils/cacheMemory.ts
261
+ var cacheMemory = new Cache();
262
+ var cacheMemory_default = cacheMemory;
118
263
  // Annotate the CommonJS export names for ESM import in node:
119
264
  0 && (module.exports = {
120
265
  ApiError,
121
266
  BadRequestError,
267
+ Cache,
122
268
  ForbiddenError,
123
269
  NotFoundError,
124
270
  UnauthorizedError,
125
271
  ValidationError,
272
+ cacheMemory,
273
+ connectMongoDb,
126
274
  errorMiddleware,
127
275
  errorResponse,
276
+ requiredEnv,
128
277
  successResponse
129
278
  });
130
279
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/responses/successResponse.ts","../src/responses/errorResponse.ts","../src/errors/ApiError.ts","../src/errors/BadRequestError.ts","../src/errors/UnauthorisedError.ts","../src/errors/ForbiddenError.ts","../src/errors/NotFoundError.ts","../src/errors/ValidationError.ts","../src/handlers/errorHandler.ts"],"sourcesContent":["export { successResponse } from \"./responses/successResponse\";\nexport { errorResponse } from \"./responses/errorResponse\";\n\nexport { default as ApiError } from \"./errors/ApiError\";\nexport { default as BadRequestError } from \"./errors/BadRequestError\";\nexport { default as UnauthorizedError } from \"./errors/UnauthorisedError\";\nexport { default as ForbiddenError } from \"./errors/ForbiddenError\";\nexport { default as NotFoundError } from \"./errors/NotFoundError\";\nexport { default as ValidationError } from \"./errors/ValidationError\";\n\nexport { default as errorMiddleware } from \"./handlers/errorHandler\";\n\nexport type {\n SuccessResponse,\n ErrorResponse,\n} from \"./types/response.types\";","import { SuccessResponse } from \"../types/response.types\";\n\nexport const successResponse = <T>(\n data: T,\n message?: string\n): SuccessResponse<T> => ({\n success: true,\n data,\n message,\n});","import { ErrorResponse } from \"../types/response.types\";\n\nexport const errorResponse = (\n message: string,\n errors?: any,\n stack?: string\n): ErrorResponse => ({\n success: false,\n message,\n errors,\n stack,\n});","export default class ApiError extends Error {\n statusCode: number;\n isOperational: boolean;\n errors?: any;\n\n constructor(\n message: string,\n statusCode = 500,\n errors?: any,\n isOperational = true\n ) {\n super(message);\n\n this.statusCode = statusCode;\n this.errors = errors;\n this.isOperational = isOperational;\n\n Error.captureStackTrace(this, this.constructor);\n }\n}","import ApiError from \"./ApiError\";\n\nexport default class BadRequestError extends ApiError {\n constructor(message = \"Bad Request\", errors?: any) {\n super(message, 400, errors);\n }\n}","import ApiError from \"./ApiError\";\n\nexport default class UnauthorizedError extends ApiError {\n constructor(message = \"Unauthorized\", errors?: any) {\n super(message, 401, errors);\n }\n}","import ApiError from \"./ApiError\";\n\nexport default class ForbiddenError extends ApiError {\n constructor(message = \"Forbidden\", errors?: any) {\n super(message, 403, errors);\n }\n}","import ApiError from \"./ApiError\";\n\nexport default class NotFoundError extends ApiError {\n constructor(message = \"Resource Not Found\", errors?: any) {\n super(message, 404, errors);\n }\n}","import ApiError from \"./ApiError\";\n\nexport default class ValidationError extends ApiError {\n constructor(message = \"Validation Failed\", errors?: any) {\n super(message, 422, errors);\n }\n}","// errorHandler.ts\nimport { Request, Response, NextFunction } from \"express\";\nimport ApiError from \"../errors/ApiError\";\nimport { errorResponse } from \"../responses/errorResponse\";\n\nconst routeNotFoundHandler = (req: Request, _: Response, next: NextFunction) => {\n next(new ApiError(`Route ${req.originalUrl} not found`, 404));\n};\n\nconst globalErrorHandler = (err: any, req: Request, res: Response, next: NextFunction) => {\n console.error(\"Error:\", err);\n let statusCode = 500;\n let message = \"Internal Server Error\";\n let errors = undefined;\n let stack = undefined;\n\n if (err instanceof ApiError) {\n statusCode = err.statusCode;\n message = err.message;\n errors = err.errors;\n }\n\n if (process.env.NODE_ENV === \"development\") {\n stack = err.stack;\n }\n\n return res.status(statusCode).json(errorResponse(message, errors, stack));\n};\n\n// Export as a tuple with explicit types so spread works correctly\nconst errorHandler: [\n (req: Request, res: Response, next: NextFunction) => void,\n (err: any, req: Request, res: Response, next: NextFunction) => void\n] = [routeNotFoundHandler, globalErrorHandler];\n\nexport default errorHandler;"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,kBAAkB,CAC7B,MACA,aACwB;AAAA,EACxB,SAAS;AAAA,EACT;AAAA,EACA;AACF;;;ACPO,IAAM,gBAAgB,CAC3B,SACA,QACA,WACmB;AAAA,EACnB,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AACF;;;ACXA,IAAqB,WAArB,cAAsC,MAAM;AAAA,EAK1C,YACE,SACA,aAAa,KACb,QACA,gBAAgB,MAChB;AACA,UAAM,OAAO;AAEb,SAAK,aAAa;AAClB,SAAK,SAAS;AACd,SAAK,gBAAgB;AAErB,UAAM,kBAAkB,MAAM,KAAK,WAAW;AAAA,EAChD;AACF;;;ACjBA,IAAqB,kBAArB,cAA6C,SAAS;AAAA,EACpD,YAAY,UAAU,eAAe,QAAc;AACjD,UAAM,SAAS,KAAK,MAAM;AAAA,EAC5B;AACF;;;ACJA,IAAqB,oBAArB,cAA+C,SAAS;AAAA,EACtD,YAAY,UAAU,gBAAgB,QAAc;AAClD,UAAM,SAAS,KAAK,MAAM;AAAA,EAC5B;AACF;;;ACJA,IAAqB,iBAArB,cAA4C,SAAS;AAAA,EACnD,YAAY,UAAU,aAAa,QAAc;AAC/C,UAAM,SAAS,KAAK,MAAM;AAAA,EAC5B;AACF;;;ACJA,IAAqB,gBAArB,cAA2C,SAAS;AAAA,EAClD,YAAY,UAAU,sBAAsB,QAAc;AACxD,UAAM,SAAS,KAAK,MAAM;AAAA,EAC5B;AACF;;;ACJA,IAAqB,kBAArB,cAA6C,SAAS;AAAA,EACpD,YAAY,UAAU,qBAAqB,QAAc;AACvD,UAAM,SAAS,KAAK,MAAM;AAAA,EAC5B;AACF;;;ACDA,IAAM,uBAAuB,CAAC,KAAc,GAAa,SAAuB;AAC9E,OAAK,IAAI,SAAS,SAAS,IAAI,WAAW,cAAc,GAAG,CAAC;AAC9D;AAEA,IAAM,qBAAqB,CAAC,KAAU,KAAc,KAAe,SAAuB;AACxF,UAAQ,MAAM,UAAU,GAAG;AAC3B,MAAI,aAAa;AACjB,MAAI,UAAU;AACd,MAAI,SAAS;AACb,MAAI,QAAQ;AAEZ,MAAI,eAAe,UAAU;AAC3B,iBAAa,IAAI;AACjB,cAAU,IAAI;AACd,aAAS,IAAI;AAAA,EACf;AAEA,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,YAAQ,IAAI;AAAA,EACd;AAEA,SAAO,IAAI,OAAO,UAAU,EAAE,KAAK,cAAc,SAAS,QAAQ,KAAK,CAAC;AAC1E;AAGA,IAAM,eAGF,CAAC,sBAAsB,kBAAkB;AAE7C,IAAO,uBAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/responses/successResponse.ts","../src/responses/errorResponse.ts","../src/utils/envManager.ts","../src/config/mongoConfig.ts","../src/errors/ApiError.ts","../src/errors/BadRequestError.ts","../src/errors/UnauthorisedError.ts","../src/errors/ForbiddenError.ts","../src/errors/NotFoundError.ts","../src/errors/ValidationError.ts","../src/handlers/errorHandler.ts","../src/utils/cache.ts","../src/utils/cacheMemory.ts"],"sourcesContent":["export { successResponse } from \"./responses/successResponse\";\nexport { errorResponse } from \"./responses/errorResponse\";\nexport { requiredEnv } from \"./utils/envManager\";\nexport { connectMongoDb } from \"./config/mongoConfig\";\nexport { default as ApiError } from \"./errors/ApiError\";\nexport { default as BadRequestError } from \"./errors/BadRequestError\";\nexport { default as UnauthorizedError } from \"./errors/UnauthorisedError\";\nexport { default as ForbiddenError } from \"./errors/ForbiddenError\";\nexport { default as NotFoundError } from \"./errors/NotFoundError\";\nexport { default as ValidationError } from \"./errors/ValidationError\";\nexport { default as errorMiddleware } from \"./handlers/errorHandler\";\nexport { Cache } from \"./utils/cache\";\nexport { default as cacheMemory } from \"./utils/cacheMemory\";\nexport type { SuccessResponse, ErrorResponse } from \"./types/response.types\";\nexport { type MongoConfig } from \"./types/mongoConfig.types\";\n","import { SuccessResponse } from \"../types/response.types\";\n\nexport const successResponse = <T>(\n data: T,\n message?: string\n): SuccessResponse<T> => ({\n success: true,\n data,\n message,\n});","import { ErrorResponse } from \"../types/response.types\";\n\nexport const errorResponse = (\n message: string,\n errors?: any,\n stack?: string\n): ErrorResponse => ({\n success: false,\n message,\n errors,\n stack,\n});","export const requiredEnv = (value: string | undefined, key: string): string => {\n if (!value) {\n throw new Error(`Missing required environment variable: ${key}`);\n }\n return value;\n};","import mongoose from \"mongoose\";\n\nimport type { MongoConfig } from \"../types/mongoConfig.types\";\n\nexport const connectMongoDb = async (config: MongoConfig) => {\n const { subDomain, userName, password, cluster, dbName } = config;\n // Primary +srv URL\n const srvURL = `mongodb+srv://${userName}:${password}@${cluster.toLowerCase()}.${subDomain}.mongodb.net/${dbName}?retryWrites=true&w=majority&appName=${cluster.toLowerCase()}`;\n // Fallback standard mongodb:// URL (you need to adjust hostnames from Atlas)\n const fallbackURL = `mongodb://${userName}:${password}@ac-hkntio7-shard-00-00.${subDomain}.mongodb.net:27017,ac-hkntio7-shard-00-01.${subDomain}.mongodb.net:27017,ac-hkntio7-shard-00-02.${subDomain}.mongodb.net:27017/${dbName}?ssl=true&replicaSet=atlas-cji6jk-shard-0&authSource=admin&appName=${cluster}`;\n try {\n console.log(\"Trying primary +srv connection...\");\n await mongoose.connect(srvURL);\n console.log(\"Connected to MongoDB Atlas via +srv URL\");\n return true;\n } catch (err: any) {\n console.warn(\"+srv connection failed:\", err.message);\n console.log(\"Trying fallback standard connection...\");\n try {\n await mongoose.connect(fallbackURL);\n console.log(\"Connected to MongoDB Atlas via fallback URL\");\n return true;\n } catch (fallbackErr: any) {\n console.error(\"Fallback connection failed:\", fallbackErr.message);\n return false;\n }\n }\n};","export default class ApiError extends Error {\n statusCode: number;\n isOperational: boolean;\n errors?: any;\n\n constructor(\n message: string,\n statusCode = 500,\n errors?: any,\n isOperational = true\n ) {\n super(message);\n\n this.statusCode = statusCode;\n this.errors = errors;\n this.isOperational = isOperational;\n\n Error.captureStackTrace(this, this.constructor);\n }\n}","import ApiError from \"./ApiError\";\n\nexport default class BadRequestError extends ApiError {\n constructor(message = \"Bad Request\", errors?: any) {\n super(message, 400, errors);\n }\n}","import ApiError from \"./ApiError\";\n\nexport default class UnauthorizedError extends ApiError {\n constructor(message = \"Unauthorized\", errors?: any) {\n super(message, 401, errors);\n }\n}","import ApiError from \"./ApiError\";\n\nexport default class ForbiddenError extends ApiError {\n constructor(message = \"Forbidden\", errors?: any) {\n super(message, 403, errors);\n }\n}","import ApiError from \"./ApiError\";\n\nexport default class NotFoundError extends ApiError {\n constructor(message = \"Resource Not Found\", errors?: any) {\n super(message, 404, errors);\n }\n}","import ApiError from \"./ApiError\";\n\nexport default class ValidationError extends ApiError {\n constructor(message = \"Validation Failed\", errors?: any) {\n super(message, 422, errors);\n }\n}","// errorHandler.ts\nimport { Request, Response, NextFunction } from \"express\";\nimport ApiError from \"../errors/ApiError\";\nimport { errorResponse } from \"../responses/errorResponse\";\n\nconst routeNotFoundHandler = (req: Request, _: Response, next: NextFunction) => {\n next(new ApiError(`Route ${req.originalUrl} not found`, 404));\n};\n\nconst globalErrorHandler = (err: any, req: Request, res: Response, next: NextFunction) => {\n console.error(\"Error:\", err);\n let statusCode = 500;\n let message = \"Internal Server Error\";\n let errors = undefined;\n let stack = undefined;\n\n if (err instanceof ApiError) {\n statusCode = err.statusCode;\n message = err.message;\n errors = err.errors;\n }\n\n if (process.env.NODE_ENV === \"development\") {\n stack = err.stack;\n }\n\n return res.status(statusCode).json(errorResponse(message, errors, stack));\n};\n\n// Export as a tuple with explicit types so spread works correctly\nconst errorHandler: [\n (req: Request, res: Response, next: NextFunction) => void,\n (err: any, req: Request, res: Response, next: NextFunction) => void\n] = [routeNotFoundHandler, globalErrorHandler];\n\nexport default errorHandler;","import NodeCache from \"node-cache\";\n\ntype CacheValue = unknown;\ntype ComputeFn<T> = () => Promise<T> | T;\n\nexport class Cache extends NodeCache {\n private namespaces: Set<string>;\n private tagMap: Map<string, Set<string>>;\n\n constructor(options: NodeCache.Options = {}) {\n const defaults: NodeCache.Options = {\n stdTTL: 60,\n checkperiod: 120,\n };\n\n super({ ...defaults, ...options });\n\n this.namespaces = new Set<string>();\n this.tagMap = new Map<string, Set<string>>();\n\n this.on(\"expired\", (key: string, value: unknown) => {\n console.log(`[Cache] Key expired: ${key} ->`, value);\n this.removeKeyFromTags(key);\n });\n }\n\n private getKey(key: string, namespace?: string): string {\n return namespace ? `${namespace}:${key}` : key;\n }\n\n private removeKeyFromTags(key: string): void {\n for (const [tag, keys] of this.tagMap.entries()) {\n if (keys.has(key)) {\n keys.delete(key);\n if (keys.size === 0) {\n this.tagMap.delete(tag);\n }\n }\n }\n }\n\n setItem(\n key: string,\n value: CacheValue,\n ttl: number =60,\n namespace?: string,\n tags: string[] = []\n ): void {\n const fullKey = this.getKey(key, namespace);\n\n if (namespace) {\n this.namespaces.add(namespace);\n }\n\n const storedValue =\n typeof value === \"string\" ? value : JSON.stringify(value);\n\n this.set(fullKey, storedValue, ttl);\n\n for (const tag of tags) {\n if (!this.tagMap.has(tag)) {\n this.tagMap.set(tag, new Set<string>());\n }\n this.tagMap.get(tag)!.add(fullKey);\n }\n }\n\n getItem<T = unknown>(key: string, namespace?: string): T | undefined {\n const fullKey = this.getKey(key, namespace);\n const value = this.get(fullKey);\n\n if (value === undefined) return undefined;\n\n try {\n return JSON.parse(value as string) as T;\n } catch {\n return value as T;\n }\n }\n\n async getOrSetItem<T>(\n key: string,\n computeFn: ComputeFn<T>,\n ttl?: number,\n namespace?: string,\n tags: string[] = []\n ): Promise<T> {\n let value = this.getItem<T>(key, namespace);\n\n if (value === undefined) {\n value = await computeFn();\n this.setItem(key, value, ttl, namespace, tags);\n }\n\n return value;\n }\n\n deleteItem(key: string, namespace?: string): number {\n const fullKey = this.getKey(key, namespace);\n this.removeKeyFromTags(fullKey);\n return this.del(fullKey);\n }\n\n clearNamespace(namespace?: string): void {\n if (!namespace) {\n this.flushAll();\n this.tagMap.clear();\n console.log(\"[Cache] All keys cleared\");\n return;\n }\n\n for (const key of this.keys()) {\n if (key.startsWith(`${namespace}:`)) {\n this.deleteItem(key);\n }\n }\n\n console.log(`[Cache] Namespace \"${namespace}\" cleared`);\n }\n\n /**\n * Delete all keys associated with a tag\n */\n clearTag(tag: string): void {\n const keys = this.tagMap.get(tag);\n if (!keys) return;\n\n for (const key of keys) {\n this.del(key);\n }\n\n this.tagMap.delete(tag);\n console.log(`[Cache] All keys with tag \"${tag}\" cleared`);\n }\n}\n","import { Cache } from \"./cache\";\n\nconst cacheMemory = new Cache();\n\nexport default cacheMemory;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,kBAAkB,CAC7B,MACA,aACwB;AAAA,EACxB,SAAS;AAAA,EACT;AAAA,EACA;AACF;;;ACPO,IAAM,gBAAgB,CAC3B,SACA,QACA,WACmB;AAAA,EACnB,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AACF;;;ACXO,IAAM,cAAc,CAAC,OAA2B,QAAwB;AAC7E,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,0CAA0C,GAAG,EAAE;AAAA,EACjE;AACA,SAAO;AACT;;;ACLA,sBAAqB;AAId,IAAM,iBAAiB,OAAO,WAAwB;AAC3D,QAAM,EAAE,W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ACvB,cAAQ,MAAM,UAAU;AACxB,WAAK,QAAQ,KAAK,OAAO,KAAK,WAAW,IAAI;AAAA,IAC/C;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,WAAW,KAAa,WAA4B;AAClD,UAAM,UAAU,KAAK,OAAO,KAAK,SAAS;AAC1C,SAAK,kBAAkB,OAAO;AAC9B,WAAO,KAAK,IAAI,OAAO;AAAA,EACzB;AAAA,EAEA,eAAe,WAA0B;AACvC,QAAI,CAAC,WAAW;AACd,WAAK,SAAS;AACd,WAAK,OAAO,MAAM;AAClB,cAAQ,IAAI,0BAA0B;AACtC;AAAA,IACF;AAEA,eAAW,OAAO,KAAK,KAAK,GAAG;AAC7B,UAAI,IAAI,WAAW,GAAG,SAAS,GAAG,GAAG;AACnC,aAAK,WAAW,GAAG;AAAA,MACrB;AAAA,IACF;AAEA,YAAQ,IAAI,sBAAsB,SAAS,WAAW;AAAA,EACxD;AAAA;AAAA;AAAA;AAAA,EAKA,SAAS,KAAmB;AAC1B,UAAM,OAAO,KAAK,OAAO,IAAI,GAAG;AAChC,QAAI,CAAC,KAAM;AAEX,eAAW,OAAO,MAAM;AACtB,WAAK,IAAI,GAAG;AAAA,IACd;AAEA,SAAK,OAAO,OAAO,GAAG;AACtB,YAAQ,IAAI,8BAA8B,GAAG,WAAW;AAAA,EAC1D;AACF;;;ACpIA,IAAM,cAAc,IAAI,MAAM;AAE9B,IAAO,sBAAQ;","names":["mongoose","NodeCache"]}
package/dist/index.mjs CHANGED
@@ -13,6 +13,39 @@ var errorResponse = (message, errors, stack) => ({
13
13
  stack
14
14
  });
15
15
 
16
+ // src/utils/envManager.ts
17
+ var requiredEnv = (value, key) => {
18
+ if (!value) {
19
+ throw new Error(`Missing required environment variable: ${key}`);
20
+ }
21
+ return value;
22
+ };
23
+
24
+ // src/config/mongoConfig.ts
25
+ import mongoose from "mongoose";
26
+ var connectMongoDb = async (config) => {
27
+ const { subDomain, userName, password, cluster, dbName } = config;
28
+ const srvURL = `mongodb+srv://${userName}:${password}@${cluster.toLowerCase()}.${subDomain}.mongodb.net/${dbName}?retryWrites=true&w=majority&appName=${cluster.toLowerCase()}`;
29
+ const fallbackURL = `mongodb://${userName}:${password}@ac-hkntio7-shard-00-00.${subDomain}.mongodb.net:27017,ac-hkntio7-shard-00-01.${subDomain}.mongodb.net:27017,ac-hkntio7-shard-00-02.${subDomain}.mongodb.net:27017/${dbName}?ssl=true&replicaSet=atlas-cji6jk-shard-0&authSource=admin&appName=${cluster}`;
30
+ try {
31
+ console.log("Trying primary +srv connection...");
32
+ await mongoose.connect(srvURL);
33
+ console.log("Connected to MongoDB Atlas via +srv URL");
34
+ return true;
35
+ } catch (err) {
36
+ console.warn("+srv connection failed:", err.message);
37
+ console.log("Trying fallback standard connection...");
38
+ try {
39
+ await mongoose.connect(fallbackURL);
40
+ console.log("Connected to MongoDB Atlas via fallback URL");
41
+ return true;
42
+ } catch (fallbackErr) {
43
+ console.error("Fallback connection failed:", fallbackErr.message);
44
+ return false;
45
+ }
46
+ }
47
+ };
48
+
16
49
  // src/errors/ApiError.ts
17
50
  var ApiError = class extends Error {
18
51
  constructor(message, statusCode = 500, errors, isOperational = true) {
@@ -81,15 +114,117 @@ var globalErrorHandler = (err, req, res, next) => {
81
114
  };
82
115
  var errorHandler = [routeNotFoundHandler, globalErrorHandler];
83
116
  var errorHandler_default = errorHandler;
117
+
118
+ // src/utils/cache.ts
119
+ import NodeCache from "node-cache";
120
+ var Cache = class extends NodeCache {
121
+ constructor(options = {}) {
122
+ const defaults = {
123
+ stdTTL: 60,
124
+ checkperiod: 120
125
+ };
126
+ super({ ...defaults, ...options });
127
+ this.namespaces = /* @__PURE__ */ new Set();
128
+ this.tagMap = /* @__PURE__ */ new Map();
129
+ this.on("expired", (key, value) => {
130
+ console.log(`[Cache] Key expired: ${key} ->`, value);
131
+ this.removeKeyFromTags(key);
132
+ });
133
+ }
134
+ getKey(key, namespace) {
135
+ return namespace ? `${namespace}:${key}` : key;
136
+ }
137
+ removeKeyFromTags(key) {
138
+ for (const [tag, keys] of this.tagMap.entries()) {
139
+ if (keys.has(key)) {
140
+ keys.delete(key);
141
+ if (keys.size === 0) {
142
+ this.tagMap.delete(tag);
143
+ }
144
+ }
145
+ }
146
+ }
147
+ setItem(key, value, ttl = 60, namespace, tags = []) {
148
+ const fullKey = this.getKey(key, namespace);
149
+ if (namespace) {
150
+ this.namespaces.add(namespace);
151
+ }
152
+ const storedValue = typeof value === "string" ? value : JSON.stringify(value);
153
+ this.set(fullKey, storedValue, ttl);
154
+ for (const tag of tags) {
155
+ if (!this.tagMap.has(tag)) {
156
+ this.tagMap.set(tag, /* @__PURE__ */ new Set());
157
+ }
158
+ this.tagMap.get(tag).add(fullKey);
159
+ }
160
+ }
161
+ getItem(key, namespace) {
162
+ const fullKey = this.getKey(key, namespace);
163
+ const value = this.get(fullKey);
164
+ if (value === void 0) return void 0;
165
+ try {
166
+ return JSON.parse(value);
167
+ } catch {
168
+ return value;
169
+ }
170
+ }
171
+ async getOrSetItem(key, computeFn, ttl, namespace, tags = []) {
172
+ let value = this.getItem(key, namespace);
173
+ if (value === void 0) {
174
+ value = await computeFn();
175
+ this.setItem(key, value, ttl, namespace, tags);
176
+ }
177
+ return value;
178
+ }
179
+ deleteItem(key, namespace) {
180
+ const fullKey = this.getKey(key, namespace);
181
+ this.removeKeyFromTags(fullKey);
182
+ return this.del(fullKey);
183
+ }
184
+ clearNamespace(namespace) {
185
+ if (!namespace) {
186
+ this.flushAll();
187
+ this.tagMap.clear();
188
+ console.log("[Cache] All keys cleared");
189
+ return;
190
+ }
191
+ for (const key of this.keys()) {
192
+ if (key.startsWith(`${namespace}:`)) {
193
+ this.deleteItem(key);
194
+ }
195
+ }
196
+ console.log(`[Cache] Namespace "${namespace}" cleared`);
197
+ }
198
+ /**
199
+ * Delete all keys associated with a tag
200
+ */
201
+ clearTag(tag) {
202
+ const keys = this.tagMap.get(tag);
203
+ if (!keys) return;
204
+ for (const key of keys) {
205
+ this.del(key);
206
+ }
207
+ this.tagMap.delete(tag);
208
+ console.log(`[Cache] All keys with tag "${tag}" cleared`);
209
+ }
210
+ };
211
+
212
+ // src/utils/cacheMemory.ts
213
+ var cacheMemory = new Cache();
214
+ var cacheMemory_default = cacheMemory;
84
215
  export {
85
216
  ApiError,
86
217
  BadRequestError,
218
+ Cache,
87
219
  ForbiddenError,
88
220
  NotFoundError,
89
221
  UnauthorizedError,
90
222
  ValidationError,
223
+ cacheMemory_default as cacheMemory,
224
+ connectMongoDb,
91
225
  errorHandler_default as errorMiddleware,
92
226
  errorResponse,
227
+ requiredEnv,
93
228
  successResponse
94
229
  };
95
230
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/responses/successResponse.ts","../src/responses/errorResponse.ts","../src/errors/ApiError.ts","../src/errors/BadRequestError.ts","../src/errors/UnauthorisedError.ts","../src/errors/ForbiddenError.ts","../src/errors/NotFoundError.ts","../src/errors/ValidationError.ts","../src/handlers/errorHandler.ts"],"sourcesContent":["import { SuccessResponse } from \"../types/response.types\";\n\nexport const successResponse = <T>(\n data: T,\n message?: string\n): SuccessResponse<T> => ({\n success: true,\n data,\n message,\n});","import { ErrorResponse } from \"../types/response.types\";\n\nexport const errorResponse = (\n message: string,\n errors?: any,\n stack?: string\n): ErrorResponse => ({\n success: false,\n message,\n errors,\n stack,\n});","export default class ApiError extends Error {\n statusCode: number;\n isOperational: boolean;\n errors?: any;\n\n constructor(\n message: string,\n statusCode = 500,\n errors?: any,\n isOperational = true\n ) {\n super(message);\n\n this.statusCode = statusCode;\n this.errors = errors;\n this.isOperational = isOperational;\n\n Error.captureStackTrace(this, this.constructor);\n }\n}","import ApiError from \"./ApiError\";\n\nexport default class BadRequestError extends ApiError {\n constructor(message = \"Bad Request\", errors?: any) {\n super(message, 400, errors);\n }\n}","import ApiError from \"./ApiError\";\n\nexport default class UnauthorizedError extends ApiError {\n constructor(message = \"Unauthorized\", errors?: any) {\n super(message, 401, errors);\n }\n}","import ApiError from \"./ApiError\";\n\nexport default class ForbiddenError extends ApiError {\n constructor(message = \"Forbidden\", errors?: any) {\n super(message, 403, errors);\n }\n}","import ApiError from \"./ApiError\";\n\nexport default class NotFoundError extends ApiError {\n constructor(message = \"Resource Not Found\", errors?: any) {\n super(message, 404, errors);\n }\n}","import ApiError from \"./ApiError\";\n\nexport default class ValidationError extends ApiError {\n constructor(message = \"Validation Failed\", errors?: any) {\n super(message, 422, errors);\n }\n}","// errorHandler.ts\nimport { Request, Response, NextFunction } from \"express\";\nimport ApiError from \"../errors/ApiError\";\nimport { errorResponse } from \"../responses/errorResponse\";\n\nconst routeNotFoundHandler = (req: Request, _: Response, next: NextFunction) => {\n next(new ApiError(`Route ${req.originalUrl} not found`, 404));\n};\n\nconst globalErrorHandler = (err: any, req: Request, res: Response, next: NextFunction) => {\n console.error(\"Error:\", err);\n let statusCode = 500;\n let message = \"Internal Server Error\";\n let errors = undefined;\n let stack = undefined;\n\n if (err instanceof ApiError) {\n statusCode = err.statusCode;\n message = err.message;\n errors = err.errors;\n }\n\n if (process.env.NODE_ENV === \"development\") {\n stack = err.stack;\n }\n\n return res.status(statusCode).json(errorResponse(message, errors, stack));\n};\n\n// Export as a tuple with explicit types so spread works correctly\nconst errorHandler: [\n (req: Request, res: Response, next: NextFunction) => void,\n (err: any, req: Request, res: Response, next: NextFunction) => void\n] = [routeNotFoundHandler, globalErrorHandler];\n\nexport default errorHandler;"],"mappings":";AAEO,IAAM,kBAAkB,CAC7B,MACA,aACwB;AAAA,EACxB,SAAS;AAAA,EACT;AAAA,EACA;AACF;;;ACPO,IAAM,gBAAgB,CAC3B,SACA,QACA,WACmB;AAAA,EACnB,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AACF;;;ACXA,IAAqB,WAArB,cAAsC,MAAM;AAAA,EAK1C,YACE,SACA,aAAa,KACb,QACA,gBAAgB,MAChB;AACA,UAAM,OAAO;AAEb,SAAK,aAAa;AAClB,SAAK,SAAS;AACd,SAAK,gBA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IAAO,uBAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/responses/successResponse.ts","../src/responses/errorResponse.ts","../src/utils/envManager.ts","../src/config/mongoConfig.ts","../src/errors/ApiError.ts","../src/errors/BadRequestError.ts","../src/errors/UnauthorisedError.ts","../src/errors/ForbiddenError.ts","../src/errors/NotFoundError.ts","../src/errors/ValidationError.ts","../src/handlers/errorHandler.ts","../src/utils/cache.ts","../src/utils/cacheMemory.ts"],"sourcesContent":["import { SuccessResponse } from \"../types/response.types\";\n\nexport const successResponse = <T>(\n data: T,\n message?: string\n): SuccessResponse<T> => ({\n success: true,\n data,\n message,\n});","import { ErrorResponse } from \"../types/response.types\";\n\nexport const errorResponse = (\n message: string,\n errors?: any,\n stack?: string\n): ErrorResponse => ({\n success: false,\n message,\n errors,\n stack,\n});","export const requiredEnv = (value: string | undefined, key: string): string => {\n if (!value) {\n throw new Error(`Missing required environment variable: ${key}`);\n }\n return value;\n};","import mongoose from \"mongoose\";\n\nimport type { MongoConfig } from \"../types/mongoConfig.types\";\n\nexport const connectMongoDb = async (config: MongoConfig) => {\n const { subDomain, userName, password, cluster, dbName } = config;\n // Primary +srv URL\n const srvURL = `mongodb+srv://${userName}:${password}@${cluster.toLowerCase()}.${subDomain}.mongodb.net/${dbName}?retryWrites=true&w=majority&appName=${cluster.toLowerCase()}`;\n // Fallback standard mongodb:// URL (you need to adjust hostnames from Atlas)\n const fallbackURL = `mongodb://${userName}:${password}@ac-hkntio7-shard-00-00.${subDomain}.mongodb.net:27017,ac-hkntio7-shard-00-01.${subDomain}.mongodb.net:27017,ac-hkntio7-shard-00-02.${subDomain}.mongodb.net:27017/${dbName}?ssl=true&replicaSet=atlas-cji6jk-shard-0&authSource=admin&appName=${cluster}`;\n try {\n console.log(\"Trying primary +srv connection...\");\n await mongoose.connect(srvURL);\n console.log(\"Connected to MongoDB Atlas via +srv URL\");\n return true;\n } catch (err: any) {\n console.warn(\"+srv connection failed:\", err.message);\n console.log(\"Trying fallback standard connection...\");\n try {\n await mongoose.connect(fallbackURL);\n console.log(\"Connected to MongoDB Atlas via fallback URL\");\n return true;\n } catch (fallbackErr: any) {\n console.error(\"Fallback connection failed:\", fallbackErr.message);\n return false;\n }\n }\n};","export default class ApiError extends Error {\n statusCode: number;\n isOperational: boolean;\n errors?: any;\n\n constructor(\n message: string,\n statusCode = 500,\n errors?: any,\n isOperational = true\n ) {\n super(message);\n\n this.statusCode = statusCode;\n this.errors = errors;\n this.isOperational = isOperational;\n\n Error.captureStackTrace(this, this.constructor);\n }\n}","import ApiError from \"./ApiError\";\n\nexport default class BadRequestError extends ApiError {\n constructor(message = \"Bad Request\", errors?: any) {\n super(message, 400, errors);\n }\n}","import ApiError from \"./ApiError\";\n\nexport default class UnauthorizedError extends ApiError {\n constructor(message = \"Unauthorized\", errors?: any) {\n super(message, 401, errors);\n }\n}","import ApiError from \"./ApiError\";\n\nexport default class ForbiddenError extends ApiError {\n constructor(message = \"Forbidden\", errors?: any) {\n super(message, 403, errors);\n }\n}","import ApiError from \"./ApiError\";\n\nexport default class NotFoundError extends ApiError {\n constructor(message = \"Resource Not Found\", errors?: any) {\n super(message, 404, errors);\n }\n}","import ApiError from \"./ApiError\";\n\nexport default class ValidationError extends ApiError {\n constructor(message = \"Validation Failed\", errors?: any) {\n super(message, 422, errors);\n }\n}","// errorHandler.ts\nimport { Request, Response, NextFunction } from \"express\";\nimport ApiError from \"../errors/ApiError\";\nimport { errorResponse } from \"../responses/errorResponse\";\n\nconst routeNotFoundHandler = (req: Request, _: Response, next: NextFunction) => {\n next(new ApiError(`Route ${req.originalUrl} not found`, 404));\n};\n\nconst globalErrorHandler = (err: any, req: Request, res: Response, next: NextFunction) => {\n console.error(\"Error:\", err);\n let statusCode = 500;\n let message = \"Internal Server Error\";\n let errors = undefined;\n let stack = undefined;\n\n if (err instanceof ApiError) {\n statusCode = err.statusCode;\n message = err.message;\n errors = err.errors;\n }\n\n if (process.env.NODE_ENV === \"development\") {\n stack = err.stack;\n }\n\n return res.status(statusCode).json(errorResponse(message, errors, stack));\n};\n\n// Export as a tuple with explicit types so spread works correctly\nconst errorHandler: [\n (req: Request, res: Response, next: NextFunction) => void,\n (err: any, req: Request, res: Response, next: NextFunction) => void\n] = [routeNotFoundHandler, globalErrorHandler];\n\nexport default errorHandler;","import NodeCache from \"node-cache\";\n\ntype CacheValue = unknown;\ntype ComputeFn<T> = () => Promise<T> | T;\n\nexport class Cache extends NodeCache {\n private namespaces: Set<string>;\n private tagMap: Map<string, Set<string>>;\n\n constructor(options: NodeCache.Options = {}) {\n const defaults: NodeCache.Options = {\n stdTTL: 60,\n checkperiod: 120,\n };\n\n super({ ...defaults, ...options });\n\n this.namespaces = new Set<string>();\n this.tagMap = new Map<string, Set<string>>();\n\n this.on(\"expired\", (key: string, value: unknown) => {\n console.log(`[Cache] Key expired: ${key} ->`, value);\n this.removeKeyFromTags(key);\n });\n }\n\n private getKey(key: string, namespace?: string): string {\n return namespace ? `${namespace}:${key}` : key;\n }\n\n private removeKeyFromTags(key: string): void {\n for (const [tag, keys] of this.tagMap.entries()) {\n if (keys.has(key)) {\n keys.delete(key);\n if (keys.size === 0) {\n this.tagMap.delete(tag);\n }\n }\n }\n }\n\n setItem(\n key: string,\n value: CacheValue,\n ttl: number =60,\n namespace?: string,\n tags: string[] = []\n ): void {\n const fullKey = this.getKey(key, namespace);\n\n if (namespace) {\n this.namespaces.add(namespace);\n }\n\n const storedValue =\n typeof value === \"string\" ? value : JSON.stringify(value);\n\n this.set(fullKey, storedValue, ttl);\n\n for (const tag of tags) {\n if (!this.tagMap.has(tag)) {\n this.tagMap.set(tag, new Set<string>());\n }\n this.tagMap.get(tag)!.add(fullKey);\n }\n }\n\n getItem<T = unknown>(key: string, namespace?: string): T | undefined {\n const fullKey = this.getKey(key, namespace);\n const value = this.get(fullKey);\n\n if (value === undefined) return undefined;\n\n try {\n return JSON.parse(value as string) as T;\n } catch {\n return value as T;\n }\n }\n\n async getOrSetItem<T>(\n key: string,\n computeFn: ComputeFn<T>,\n ttl?: number,\n namespace?: string,\n tags: string[] = []\n ): Promise<T> {\n let value = this.getItem<T>(key, namespace);\n\n if (value === undefined) {\n value = await computeFn();\n this.setItem(key, value, ttl, namespace, tags);\n }\n\n return value;\n }\n\n deleteItem(key: string, namespace?: string): number {\n const fullKey = this.getKey(key, namespace);\n this.removeKeyFromTags(fullKey);\n return this.del(fullKey);\n }\n\n clearNamespace(namespace?: string): void {\n if (!namespace) {\n this.flushAll();\n this.tagMap.clear();\n console.log(\"[Cache] All keys cleared\");\n return;\n }\n\n for (const key of this.keys()) {\n if (key.startsWith(`${namespace}:`)) {\n this.deleteItem(key);\n }\n }\n\n console.log(`[Cache] Namespace \"${namespace}\" cleared`);\n }\n\n /**\n * Delete all keys associated with a tag\n */\n clearTag(tag: string): void {\n const keys = this.tagMap.get(tag);\n if (!keys) return;\n\n for (const key of keys) {\n this.del(key);\n }\n\n this.tagMap.delete(tag);\n console.log(`[Cache] All keys with tag \"${tag}\" cleared`);\n }\n}\n","import { Cache } from \"./cache\";\n\nconst cacheMemory = new Cache();\n\nexport default cacheMemory;\n"],"mappings":";AAEO,IAAM,kBAAkB,CAC7B,MACA,aACwB;AAAA,EACxB,SAAS;AAAA,EACT;AAAA,EACA;AACF;;;ACPO,IAAM,gBAAgB,CAC3B,SACA,QACA,WACmB;AAAA,EACnB,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AACF;;;ACXO,IAAM,cAAc,CAAC,OAA2B,QAAwB;AAC7E,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,0CAA0C,GAAG,EAAE;AAAA,EACjE;AACA,SAAO;AACT;;;ACLA,OAAO,cAAc;AAId,IAAM,iBAAiB,OAAO,WAAwB;AAC3D,QAAM,EAAE,WAAW,UAAU,UAAU,SAAS,OAAO,IAAI;AAE3D,QAAM,SAAS,iBAAiB,QAAQ,IAAI,QAAQ,IAAI,QAAQ,YAAY,CAAC,IAAI,SAAS,gBAAgB,MAAM,wCAAwC,QAAQ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,KAAK,SAAS;AAC1C,SAAK,kBAAkB,OAAO;AAC9B,WAAO,KAAK,IAAI,OAAO;AAAA,EACzB;AAAA,EAEA,eAAe,WAA0B;AACvC,QAAI,CAAC,WAAW;AACd,WAAK,SAAS;AACd,WAAK,OAAO,MAAM;AAClB,cAAQ,IAAI,0BAA0B;AACtC;AAAA,IACF;AAEA,eAAW,OAAO,KAAK,KAAK,GAAG;AAC7B,UAAI,IAAI,WAAW,GAAG,SAAS,GAAG,GAAG;AACnC,aAAK,WAAW,GAAG;AAAA,MACrB;AAAA,IACF;AAEA,YAAQ,IAAI,sBAAsB,SAAS,WAAW;AAAA,EACxD;AAAA;AAAA;AAAA;AAAA,EAKA,SAAS,KAAmB;AAC1B,UAAM,OAAO,KAAK,OAAO,IAAI,GAAG;AAChC,QAAI,CAAC,KAAM;AAEX,eAAW,OAAO,MAAM;AACtB,WAAK,IAAI,GAAG;AAAA,IACd;AAEA,SAAK,OAAO,OAAO,GAAG;AACtB,YAAQ,IAAI,8BAA8B,GAAG,WAAW;AAAA,EAC1D;AACF;;;ACpIA,IAAM,cAAc,IAAI,MAAM;AAE9B,IAAO,sBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexus-backend",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Backend utility library for Express.js",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -12,11 +12,21 @@
12
12
  "build": "tsup"
13
13
  },
14
14
  "peerDependencies": {
15
- "express": "^5.0.6"
15
+ "cookie-parser": "^1.4.7",
16
+ "cors": "^2.8.6",
17
+ "dotenv": "^17.4.2",
18
+ "express": "^5.0.6",
19
+ "helmet": "^8.1.0",
20
+ "mongoose": "^9.6.2",
21
+ "morgan": "^1.10.1",
22
+ "socket.io": "^4.8.3",
23
+ "node-cache": "5.1.2"
16
24
  },
17
25
  "devDependencies": {
26
+ "@types/cookie-parser": "^1.4.10",
27
+ "@types/cors": "^2.8.19",
18
28
  "@types/express": "^5.0.6",
19
29
  "tsup": "^8.5.1",
20
30
  "typescript": "^5.8.3"
21
31
  }
22
- }
32
+ }