@ajayjbtickets/common 1.0.14 → 1.0.16
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/dist/index.cjs +14 -14
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +14 -14
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -209,18 +209,13 @@ var import_config = require("dotenv/config");
|
|
|
209
209
|
var getConfig = () => {
|
|
210
210
|
return {
|
|
211
211
|
ENVIRONMENT: process.env.ENVIRONMENT,
|
|
212
|
-
LOG_DIR: process.env.LOG_DIR,
|
|
213
|
-
LOG_LEVEL: process.env.LOG_LEVEL,
|
|
212
|
+
LOG_DIR: process.env.LOG_DIR || "logs",
|
|
213
|
+
LOG_LEVEL: process.env.LOG_LEVEL || "info",
|
|
214
214
|
SALT_ROUNDS: parseInt(process.env.SALT_ROUNDS),
|
|
215
215
|
JWT_KEY: process.env.JWT_KEY
|
|
216
216
|
};
|
|
217
217
|
};
|
|
218
218
|
var getSanitizedConfig = (config2) => {
|
|
219
|
-
for (const [key, value] of Object.entries(config2)) {
|
|
220
|
-
if (!value) {
|
|
221
|
-
throw new Error(`Missing key ${key} in config.env`);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
219
|
return config2;
|
|
225
220
|
};
|
|
226
221
|
var config = getConfig();
|
|
@@ -276,6 +271,9 @@ var ApiError = class extends Error {
|
|
|
276
271
|
break;
|
|
277
272
|
default:
|
|
278
273
|
let messsage = err.message;
|
|
274
|
+
if (!sanitizedConfig.ENVIRONMENT) {
|
|
275
|
+
throw new Error("Missing required environment variable: ENVIRONMENT");
|
|
276
|
+
}
|
|
279
277
|
messsage = sanitizedConfig.ENVIRONMENT !== ENVIRONMENTS.production ? messsage : "Something went wrong!";
|
|
280
278
|
new InternalErrorResponse(messsage, err.errors).send(res);
|
|
281
279
|
break;
|
|
@@ -337,12 +335,8 @@ var ForbiddenError = class extends ApiError {
|
|
|
337
335
|
// src/core/Logger.ts
|
|
338
336
|
var import_winston = __toESM(require("winston"), 1);
|
|
339
337
|
var import_fs = __toESM(require("fs"), 1);
|
|
340
|
-
var import_path = __toESM(require("path"), 1);
|
|
341
338
|
var import_winston_daily_rotate_file = __toESM(require("winston-daily-rotate-file"), 1);
|
|
342
339
|
var dir = sanitizedConfig.LOG_DIR;
|
|
343
|
-
if (!dir) {
|
|
344
|
-
dir = import_path.default.resolve("logs");
|
|
345
|
-
}
|
|
346
340
|
if (!import_fs.default.existsSync(dir)) {
|
|
347
341
|
import_fs.default.mkdirSync(dir);
|
|
348
342
|
}
|
|
@@ -405,6 +399,9 @@ var import_jsonwebtoken2 = __toESM(require("jsonwebtoken"), 1);
|
|
|
405
399
|
var import_jsonwebtoken = __toESM(require("jsonwebtoken"), 1);
|
|
406
400
|
var JwtService = class {
|
|
407
401
|
static sign(payload, signOptions = {}) {
|
|
402
|
+
if (!sanitizedConfig.JWT_KEY) {
|
|
403
|
+
throw new Error("Missing required environment variable: JWT_KEY");
|
|
404
|
+
}
|
|
408
405
|
const token = import_jsonwebtoken.default.sign(
|
|
409
406
|
payload,
|
|
410
407
|
sanitizedConfig.JWT_KEY,
|
|
@@ -420,10 +417,10 @@ var JwtService = class {
|
|
|
420
417
|
);
|
|
421
418
|
return decoded;
|
|
422
419
|
}
|
|
423
|
-
static generatePayload(
|
|
420
|
+
static generatePayload(payload) {
|
|
424
421
|
return {
|
|
425
|
-
|
|
426
|
-
email:
|
|
422
|
+
id: payload.id,
|
|
423
|
+
email: payload.email
|
|
427
424
|
};
|
|
428
425
|
}
|
|
429
426
|
};
|
|
@@ -454,6 +451,9 @@ var import_bcrypt = __toESM(require("bcrypt"), 1);
|
|
|
454
451
|
var Password = class {
|
|
455
452
|
static hashPassword(password) {
|
|
456
453
|
return new Promise((resolve, reject) => {
|
|
454
|
+
if (!sanitizedConfig.SALT_ROUNDS) {
|
|
455
|
+
reject("Missing required environment variable: SALT_ROUNDS");
|
|
456
|
+
}
|
|
457
457
|
import_bcrypt.default.hash(password, sanitizedConfig.SALT_ROUNDS, function(err, hash) {
|
|
458
458
|
if (err) {
|
|
459
459
|
reject(err.message);
|
package/dist/index.d.cts
CHANGED
|
@@ -159,13 +159,13 @@ declare const schemaValidator: (type: ValidationSource, schema: ZodSchema) => (r
|
|
|
159
159
|
declare const verifyToken: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
160
160
|
|
|
161
161
|
interface JwtPayload {
|
|
162
|
-
|
|
162
|
+
id: string;
|
|
163
163
|
email: string;
|
|
164
164
|
}
|
|
165
165
|
declare class JwtService {
|
|
166
166
|
static sign(payload: string | Buffer | object, signOptions?: SignOptions): string;
|
|
167
167
|
static verify(token: string, verifyOptions?: VerifyOptions): string | jsonwebtoken.Jwt | jsonwebtoken.JwtPayload;
|
|
168
|
-
static generatePayload<T extends JwtPayload>(
|
|
168
|
+
static generatePayload<T extends JwtPayload>(payload: T): T;
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
declare class Password {
|
package/dist/index.d.ts
CHANGED
|
@@ -159,13 +159,13 @@ declare const schemaValidator: (type: ValidationSource, schema: ZodSchema) => (r
|
|
|
159
159
|
declare const verifyToken: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
160
160
|
|
|
161
161
|
interface JwtPayload {
|
|
162
|
-
|
|
162
|
+
id: string;
|
|
163
163
|
email: string;
|
|
164
164
|
}
|
|
165
165
|
declare class JwtService {
|
|
166
166
|
static sign(payload: string | Buffer | object, signOptions?: SignOptions): string;
|
|
167
167
|
static verify(token: string, verifyOptions?: VerifyOptions): string | jsonwebtoken.Jwt | jsonwebtoken.JwtPayload;
|
|
168
|
-
static generatePayload<T extends JwtPayload>(
|
|
168
|
+
static generatePayload<T extends JwtPayload>(payload: T): T;
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
declare class Password {
|
package/dist/index.js
CHANGED
|
@@ -143,18 +143,13 @@ import "dotenv/config";
|
|
|
143
143
|
var getConfig = () => {
|
|
144
144
|
return {
|
|
145
145
|
ENVIRONMENT: process.env.ENVIRONMENT,
|
|
146
|
-
LOG_DIR: process.env.LOG_DIR,
|
|
147
|
-
LOG_LEVEL: process.env.LOG_LEVEL,
|
|
146
|
+
LOG_DIR: process.env.LOG_DIR || "logs",
|
|
147
|
+
LOG_LEVEL: process.env.LOG_LEVEL || "info",
|
|
148
148
|
SALT_ROUNDS: parseInt(process.env.SALT_ROUNDS),
|
|
149
149
|
JWT_KEY: process.env.JWT_KEY
|
|
150
150
|
};
|
|
151
151
|
};
|
|
152
152
|
var getSanitizedConfig = (config2) => {
|
|
153
|
-
for (const [key, value] of Object.entries(config2)) {
|
|
154
|
-
if (!value) {
|
|
155
|
-
throw new Error(`Missing key ${key} in config.env`);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
153
|
return config2;
|
|
159
154
|
};
|
|
160
155
|
var config = getConfig();
|
|
@@ -210,6 +205,9 @@ var ApiError = class extends Error {
|
|
|
210
205
|
break;
|
|
211
206
|
default:
|
|
212
207
|
let messsage = err.message;
|
|
208
|
+
if (!sanitizedConfig.ENVIRONMENT) {
|
|
209
|
+
throw new Error("Missing required environment variable: ENVIRONMENT");
|
|
210
|
+
}
|
|
213
211
|
messsage = sanitizedConfig.ENVIRONMENT !== ENVIRONMENTS.production ? messsage : "Something went wrong!";
|
|
214
212
|
new InternalErrorResponse(messsage, err.errors).send(res);
|
|
215
213
|
break;
|
|
@@ -271,12 +269,8 @@ var ForbiddenError = class extends ApiError {
|
|
|
271
269
|
// src/core/Logger.ts
|
|
272
270
|
import winston, { format } from "winston";
|
|
273
271
|
import fs from "fs";
|
|
274
|
-
import path from "path";
|
|
275
272
|
import DailyRotateFile from "winston-daily-rotate-file";
|
|
276
273
|
var dir = sanitizedConfig.LOG_DIR;
|
|
277
|
-
if (!dir) {
|
|
278
|
-
dir = path.resolve("logs");
|
|
279
|
-
}
|
|
280
274
|
if (!fs.existsSync(dir)) {
|
|
281
275
|
fs.mkdirSync(dir);
|
|
282
276
|
}
|
|
@@ -339,6 +333,9 @@ import jsonwebtoken2 from "jsonwebtoken";
|
|
|
339
333
|
import jsonwebtoken from "jsonwebtoken";
|
|
340
334
|
var JwtService = class {
|
|
341
335
|
static sign(payload, signOptions = {}) {
|
|
336
|
+
if (!sanitizedConfig.JWT_KEY) {
|
|
337
|
+
throw new Error("Missing required environment variable: JWT_KEY");
|
|
338
|
+
}
|
|
342
339
|
const token = jsonwebtoken.sign(
|
|
343
340
|
payload,
|
|
344
341
|
sanitizedConfig.JWT_KEY,
|
|
@@ -354,10 +351,10 @@ var JwtService = class {
|
|
|
354
351
|
);
|
|
355
352
|
return decoded;
|
|
356
353
|
}
|
|
357
|
-
static generatePayload(
|
|
354
|
+
static generatePayload(payload) {
|
|
358
355
|
return {
|
|
359
|
-
|
|
360
|
-
email:
|
|
356
|
+
id: payload.id,
|
|
357
|
+
email: payload.email
|
|
361
358
|
};
|
|
362
359
|
}
|
|
363
360
|
};
|
|
@@ -388,6 +385,9 @@ import bcrypt from "bcrypt";
|
|
|
388
385
|
var Password = class {
|
|
389
386
|
static hashPassword(password) {
|
|
390
387
|
return new Promise((resolve, reject) => {
|
|
388
|
+
if (!sanitizedConfig.SALT_ROUNDS) {
|
|
389
|
+
reject("Missing required environment variable: SALT_ROUNDS");
|
|
390
|
+
}
|
|
391
391
|
bcrypt.hash(password, sanitizedConfig.SALT_ROUNDS, function(err, hash) {
|
|
392
392
|
if (err) {
|
|
393
393
|
reject(err.message);
|