@ajayjbtickets/common 1.0.15 → 1.0.17
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 +11 -11
- package/dist/index.js +11 -11
- package/package.json +2 -2
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,
|
|
@@ -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.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,
|
|
@@ -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);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ajayjbtickets/common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dev": "tsx ./src/index.ts",
|
|
26
26
|
"clean": "del ./dist/*",
|
|
27
27
|
"build": "npm run clean && tsup",
|
|
28
|
-
"
|
|
28
|
+
"publish": "git add . && git commit -m \"updates\" && npm version patch && npm run build && npm publish"
|
|
29
29
|
},
|
|
30
30
|
"keywords": [],
|
|
31
31
|
"author": "",
|