@vasrefil/api-toolkit 1.9.0 → 1.10.0
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/app-middlewares/airbrake.d.ts +3 -2
- package/dist/app-middlewares/airbrake.js +56 -13
- package/dist/env.d.ts +3 -3
- package/dist/env.js +5 -2
- package/dist/index.js +2 -5
- package/dist/models/_config.js +5 -5
- package/dist/routes/index.route.js +2 -2
- package/dist/utilities/email.util.d.ts +2 -1
- package/dist/utilities/email.util.js +8 -6
- package/dist/utilities/log.util.js +11 -11
- package/package.json +2 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ServiceRespI } from '../interfaces/interface';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import * as Airbrake from '@airbrake/node';
|
|
3
|
+
import * as airbrakeExpress from '@airbrake/node/dist/instrumentation/express';
|
|
4
|
+
declare let airbrake: Airbrake.Notifier | null;
|
|
4
5
|
declare const airbrake_request_logger: (dto: {
|
|
5
6
|
serviceResponse: ServiceRespI;
|
|
6
7
|
}) => void;
|
|
@@ -1,26 +1,67 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
39
|
exports.airtbrake_error_logger = exports.airbrake_request_logger = exports.airbrakeExpress = exports.airbrake = void 0;
|
|
7
40
|
const env_1 = __importDefault(require("../env"));
|
|
8
|
-
const Airbrake = require(
|
|
9
|
-
const airbrakeExpress = require(
|
|
41
|
+
const Airbrake = __importStar(require("@airbrake/node"));
|
|
42
|
+
const airbrakeExpress = __importStar(require("@airbrake/node/dist/instrumentation/express"));
|
|
10
43
|
exports.airbrakeExpress = airbrakeExpress;
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
44
|
+
const json_stringify_safe_1 = __importDefault(require("json-stringify-safe"));
|
|
45
|
+
let airbrake;
|
|
46
|
+
if (env_1.default.AIRBRAKE.PROJECT_ID && env_1.default.AIRBRAKE.PROJECT_KEY) {
|
|
47
|
+
exports.airbrake = airbrake = new Airbrake.Notifier({
|
|
48
|
+
projectId: env_1.default.AIRBRAKE.PROJECT_ID,
|
|
49
|
+
projectKey: env_1.default.AIRBRAKE.PROJECT_KEY,
|
|
50
|
+
environment: `${env_1.default.NODE_ENV}`
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
console.log('AIRBRAKE environment variables (PROJECT_ID, PROJECT_KEY) are required.');
|
|
55
|
+
exports.airbrake = airbrake = null;
|
|
56
|
+
}
|
|
18
57
|
const airbrake_request_logger = (dto) => {
|
|
58
|
+
if (!airbrake)
|
|
59
|
+
return;
|
|
19
60
|
try {
|
|
20
61
|
const { request, error, data, message, actionType } = dto.serviceResponse;
|
|
21
|
-
const dataErr = data ?
|
|
22
|
-
const errorErr = error ?
|
|
23
|
-
const messageErr = message ?
|
|
62
|
+
const dataErr = data ? (0, json_stringify_safe_1.default)(data) : null;
|
|
63
|
+
const errorErr = error ? (0, json_stringify_safe_1.default)(error, null) : null;
|
|
64
|
+
const messageErr = message ? (0, json_stringify_safe_1.default)(message) : null;
|
|
24
65
|
const error_ = messageErr || errorErr || dataErr;
|
|
25
66
|
const actionType_ = actionType || 'App Error';
|
|
26
67
|
const body = request && request.body ? request.body : 'no body';
|
|
@@ -37,9 +78,11 @@ const airbrake_request_logger = (dto) => {
|
|
|
37
78
|
};
|
|
38
79
|
exports.airbrake_request_logger = airbrake_request_logger;
|
|
39
80
|
const airtbrake_error_logger = (dto) => {
|
|
81
|
+
if (!airbrake)
|
|
82
|
+
return;
|
|
40
83
|
try {
|
|
41
84
|
airbrake.notify({
|
|
42
|
-
error:
|
|
85
|
+
error: (0, json_stringify_safe_1.default)(dto.error, null),
|
|
43
86
|
params: dto.params,
|
|
44
87
|
route: dto.route
|
|
45
88
|
});
|
package/dist/env.d.ts
CHANGED
|
@@ -29,11 +29,11 @@ declare const env: {
|
|
|
29
29
|
API_KEY: string | undefined;
|
|
30
30
|
};
|
|
31
31
|
AIRBRAKE: {
|
|
32
|
-
PROJECT_ID:
|
|
33
|
-
PROJECT_KEY: string
|
|
32
|
+
PROJECT_ID: number;
|
|
33
|
+
PROJECT_KEY: string;
|
|
34
34
|
};
|
|
35
35
|
GO_MAILER: {
|
|
36
|
-
API_KEY: string
|
|
36
|
+
API_KEY: string;
|
|
37
37
|
};
|
|
38
38
|
};
|
|
39
39
|
export default env;
|
package/dist/env.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
|
|
6
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
7
|
+
dotenv_1.default.config();
|
|
5
8
|
var NODE_ENVS;
|
|
6
9
|
(function (NODE_ENVS) {
|
|
7
10
|
NODE_ENVS["DEV"] = "dev";
|
package/dist/index.js
CHANGED
|
@@ -7,11 +7,10 @@ const express_1 = __importDefault(require("express"));
|
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const cors_1 = __importDefault(require("cors"));
|
|
9
9
|
const helmet_1 = __importDefault(require("helmet"));
|
|
10
|
-
const
|
|
10
|
+
const errorhandler_1 = __importDefault(require("errorhandler"));
|
|
11
11
|
const _config_1 = require("./models/_config");
|
|
12
12
|
const index_route_1 = require("./routes/index.route");
|
|
13
13
|
const logger_util_1 = require("./utilities/logger.util");
|
|
14
|
-
// import { airbrake, airbrakeExpress } from './app-middlewares/airbrake';
|
|
15
14
|
const port = process.env.PORT || 8012;
|
|
16
15
|
const app = (0, express_1.default)();
|
|
17
16
|
app.set('trust proxy', true);
|
|
@@ -32,11 +31,9 @@ app.use(function (err, req, res, next) {
|
|
|
32
31
|
next(err);
|
|
33
32
|
});
|
|
34
33
|
//error handling
|
|
35
|
-
app.use(
|
|
34
|
+
app.use((0, errorhandler_1.default)());
|
|
36
35
|
(0, _config_1.dbConfig)();
|
|
37
|
-
// app.use(airbrakeExpress.makeMiddleware(airbrake));
|
|
38
36
|
(0, index_route_1.routes)(app);
|
|
39
|
-
// app.use(airbrakeExpress.makeErrorHandler(airbrake));
|
|
40
37
|
app.listen(port, () => {
|
|
41
38
|
console.log(`Server is running on port ${port}`);
|
|
42
39
|
});
|
package/dist/models/_config.js
CHANGED
|
@@ -4,20 +4,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.dbConfig = void 0;
|
|
7
|
-
const
|
|
7
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
8
|
const env_1 = __importDefault(require("../env"));
|
|
9
|
-
const
|
|
10
|
-
|
|
9
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
+
mongoose_1.default.set('strictQuery', false);
|
|
11
11
|
const dbConfig = () => {
|
|
12
12
|
// Connect to MongoDB
|
|
13
13
|
if (env_1.default.MONGODB_URI) {
|
|
14
|
-
|
|
14
|
+
mongoose_1.default.connect(env_1.default.MONGODB_URI)
|
|
15
15
|
.then(() => {
|
|
16
16
|
console.log('✌🏾 Successfully connected to MongoDB');
|
|
17
17
|
})
|
|
18
18
|
.catch(err => {
|
|
19
19
|
console.log(err);
|
|
20
|
-
console.log(
|
|
20
|
+
console.log(chalk_1.default.red.bgBlack.bold('An error occured while conencting to MongoDB'));
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.routes = void 0;
|
|
7
7
|
const express_1 = require("express");
|
|
8
|
-
const
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
9
|
const env_1 = __importDefault(require("../env"));
|
|
10
10
|
const sample_route_1 = __importDefault(require("./sample.route"));
|
|
11
11
|
/**
|
|
@@ -18,7 +18,7 @@ const sample_route_1 = __importDefault(require("./sample.route"));
|
|
|
18
18
|
const routes = (app) => {
|
|
19
19
|
let router;
|
|
20
20
|
router = (0, express_1.Router)();
|
|
21
|
-
console.log(
|
|
21
|
+
console.log(chalk_1.default.yellow.bgBlack.bold("Loading sample routes"));
|
|
22
22
|
sample_route_1.default.loadRoutes('/samples', router);
|
|
23
23
|
router.get('/', (req, res) => {
|
|
24
24
|
res.send(`Welcome to API-Toolkit - ${env_1.default.NODE_ENV}`);
|
|
@@ -7,9 +7,10 @@ export interface SendEmailPayloadI {
|
|
|
7
7
|
html: string;
|
|
8
8
|
metadata?: object;
|
|
9
9
|
template_code?: string;
|
|
10
|
+
job_options?: BulkJobOptions;
|
|
10
11
|
}
|
|
11
12
|
declare class EmailUtil_ {
|
|
12
|
-
send_email: (payload: SendEmailPayloadI[]
|
|
13
|
+
send_email: (payload: SendEmailPayloadI[]) => Promise<void>;
|
|
13
14
|
}
|
|
14
15
|
export declare const EmailUtil: EmailUtil_;
|
|
15
16
|
export {};
|
|
@@ -5,13 +5,15 @@ const queue_1 = require("./../background-jobs/queue");
|
|
|
5
5
|
const helpers_1 = require("../helpers");
|
|
6
6
|
class EmailUtil_ {
|
|
7
7
|
constructor() {
|
|
8
|
-
this.send_email = async (payload
|
|
8
|
+
this.send_email = async (payload) => {
|
|
9
9
|
try {
|
|
10
|
-
const jobs = payload.map(p =>
|
|
11
|
-
name: p.action_type,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
const jobs = payload.map(p => {
|
|
11
|
+
const data = { name: p.action_type, data: p };
|
|
12
|
+
if (p.job_options) {
|
|
13
|
+
data['opts'] = p.job_options;
|
|
14
|
+
}
|
|
15
|
+
return data;
|
|
16
|
+
});
|
|
15
17
|
(0, queue_1.EmailQueue)().addBulk(jobs);
|
|
16
18
|
}
|
|
17
19
|
catch (error) {
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.LogUtil = void 0;
|
|
7
7
|
const airbrake_1 = require("../app-middlewares/airbrake");
|
|
8
8
|
const api_request_util_1 = require("./api-request.util");
|
|
9
|
-
const
|
|
9
|
+
const json_stringify_safe_1 = __importDefault(require("json-stringify-safe"));
|
|
10
10
|
const env_1 = __importDefault(require("../env"));
|
|
11
11
|
const ip_util_1 = require("./ip.util");
|
|
12
12
|
class LogUtil_ {
|
|
@@ -20,8 +20,8 @@ class LogUtil_ {
|
|
|
20
20
|
const response = this.get_user_event_response(dto.serviceResponse);
|
|
21
21
|
const payload = {
|
|
22
22
|
distinct_id: user.distinct_id,
|
|
23
|
-
request:
|
|
24
|
-
response:
|
|
23
|
+
request: (0, json_stringify_safe_1.default)(request, null),
|
|
24
|
+
response: (0, json_stringify_safe_1.default)(response, null),
|
|
25
25
|
request_url: request?.url,
|
|
26
26
|
event: actionType,
|
|
27
27
|
type: 'USER_EVENT',
|
|
@@ -31,8 +31,8 @@ class LogUtil_ {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
catch (error) {
|
|
34
|
-
airbrake_1.airbrake
|
|
35
|
-
error:
|
|
34
|
+
airbrake_1.airbrake?.notify({
|
|
35
|
+
error: (0, json_stringify_safe_1.default)(error, null),
|
|
36
36
|
context: { component: 'USER_EVENT', service_name: env_1.default.SERVICE_NAME },
|
|
37
37
|
params: { actionType, status, request },
|
|
38
38
|
});
|
|
@@ -43,16 +43,16 @@ class LogUtil_ {
|
|
|
43
43
|
const payload = {
|
|
44
44
|
...dto,
|
|
45
45
|
distinct_id: dto.distinct_id || 'admin',
|
|
46
|
-
response:
|
|
47
|
-
request:
|
|
46
|
+
response: (0, json_stringify_safe_1.default)(dto.response, null),
|
|
47
|
+
request: (0, json_stringify_safe_1.default)(this.get_app_log_request(dto.request), null),
|
|
48
48
|
type: 'APP_LOG'
|
|
49
49
|
};
|
|
50
50
|
await this.create_activity_log(payload);
|
|
51
51
|
}
|
|
52
52
|
catch (error) {
|
|
53
53
|
console.log(error);
|
|
54
|
-
airbrake_1.airbrake
|
|
55
|
-
error:
|
|
54
|
+
airbrake_1.airbrake?.notify({
|
|
55
|
+
error: (0, json_stringify_safe_1.default)(error, null),
|
|
56
56
|
context: { component: 'APP_LOG', service_name: env_1.default.SERVICE_NAME },
|
|
57
57
|
});
|
|
58
58
|
}
|
|
@@ -85,8 +85,8 @@ class LogUtil_ {
|
|
|
85
85
|
if (error) {
|
|
86
86
|
delete error.req;
|
|
87
87
|
}
|
|
88
|
-
const data_ = data ?
|
|
89
|
-
const error_ = error ?
|
|
88
|
+
const data_ = data ? (0, json_stringify_safe_1.default)(data) : null;
|
|
89
|
+
const error_ = error ? (0, json_stringify_safe_1.default)(error, null) : null;
|
|
90
90
|
const message_ = message ? message : null;
|
|
91
91
|
response = {
|
|
92
92
|
message: message_, error: error_
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vasrefil/api-toolkit",
|
|
3
3
|
"description": "This is Vasrefil API toolkit",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.10.0",
|
|
5
5
|
"author": "Sodiq Alabi",
|
|
6
6
|
"main": "dist/public-api.js",
|
|
7
7
|
"types": "dist/public-api.d.ts",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"@types/body-parser": "1.19.0",
|
|
41
41
|
"@types/cors": "^2.8.17",
|
|
42
42
|
"@types/errorhandler": "1.5.0",
|
|
43
|
+
"@types/json-stringify-safe": "^5.0.3",
|
|
43
44
|
"@types/morgan": "^1.9.3",
|
|
44
45
|
"@types/node": "^14.14.7",
|
|
45
46
|
"cross-env": "^7.0.2",
|