@vasrefil/api-toolkit 1.0.58 → 1.0.60

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/env.d.ts CHANGED
@@ -30,5 +30,8 @@ declare const env: {
30
30
  PROJECT_ID: string | undefined;
31
31
  PROJECT_KEY: string | undefined;
32
32
  };
33
+ GO_MAILER: {
34
+ API_KEY: string | undefined;
35
+ };
33
36
  };
34
37
  export default env;
package/dist/env.js CHANGED
@@ -36,5 +36,8 @@ const env = {
36
36
  PROJECT_ID: process.env.AIRBRAKE_PROJECT_ID,
37
37
  PROJECT_KEY: process.env.AIRBRAKE_PROJECT_KEY
38
38
  },
39
+ GO_MAILER: {
40
+ API_KEY: process.env.GO_MAILER_API_KEY
41
+ }
39
42
  };
40
43
  exports.default = env;
@@ -0,0 +1,40 @@
1
+ import { UserI } from "./user.interface";
2
+ export declare enum AppLogPriorityI {
3
+ info = "info",
4
+ warning = "warning",
5
+ critical = "critical",
6
+ emergency = "emergency"
7
+ }
8
+ export declare enum AppLogStatusI {
9
+ unresolved = "unresolved",
10
+ resolved = "resolved"
11
+ }
12
+ export declare enum AppLogTypeI {
13
+ info = "info",
14
+ error = "error"
15
+ }
16
+ export interface AppLogPayloadI {
17
+ distinct_id?: string;
18
+ log_type?: AppLogTypeI;
19
+ category: string;
20
+ subcategory?: string;
21
+ priority?: AppLogPriorityI;
22
+ function_name?: string;
23
+ webhook?: string;
24
+ response?: object;
25
+ request?: {
26
+ body: object;
27
+ headers?: object;
28
+ };
29
+ log_status?: AppLogStatusI;
30
+ }
31
+ export interface LogI {
32
+ message: string;
33
+ type: AppLogTypeI;
34
+ request: {
35
+ body: object;
36
+ headers?: object;
37
+ };
38
+ response: object;
39
+ user?: UserI;
40
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppLogTypeI = exports.AppLogStatusI = exports.AppLogPriorityI = void 0;
4
+ var AppLogPriorityI;
5
+ (function (AppLogPriorityI) {
6
+ AppLogPriorityI["info"] = "info";
7
+ AppLogPriorityI["warning"] = "warning";
8
+ AppLogPriorityI["critical"] = "critical";
9
+ AppLogPriorityI["emergency"] = "emergency";
10
+ })(AppLogPriorityI || (exports.AppLogPriorityI = AppLogPriorityI = {}));
11
+ var AppLogStatusI;
12
+ (function (AppLogStatusI) {
13
+ AppLogStatusI["unresolved"] = "unresolved";
14
+ AppLogStatusI["resolved"] = "resolved";
15
+ })(AppLogStatusI || (exports.AppLogStatusI = AppLogStatusI = {}));
16
+ var AppLogTypeI;
17
+ (function (AppLogTypeI) {
18
+ AppLogTypeI["info"] = "info";
19
+ AppLogTypeI["error"] = "error";
20
+ })(AppLogTypeI || (exports.AppLogTypeI = AppLogTypeI = {}));
@@ -43,6 +43,7 @@ const airbrake_1 = require("../app-middlewares/airbrake");
43
43
  const log_util_1 = require("../utilities/log.util");
44
44
  const env_1 = __importDefault(require("../env"));
45
45
  const mongoose = __importStar(require("mongoose"));
46
+ const go_mailer_util_1 = require("src/utilities/go-mailer.util");
46
47
  class RootService {
47
48
  constructor() {
48
49
  this.SUCCESS = status_interface_1.Status.SUCCESS;
@@ -58,6 +59,7 @@ class RootService {
58
59
  logger_util_1.winston.error(error);
59
60
  }
60
61
  log_util_1.LogUtil.user_event({ serviceResponse: log_service_resp });
62
+ go_mailer_util_1.GoMailerUtil.send_event({ serviceResponse });
61
63
  }
62
64
  catch (error) {
63
65
  logger_util_1.winston.error(error);
@@ -0,0 +1,8 @@
1
+ import { ServiceRespI } from '../interfaces';
2
+ declare class GoMailerUtil_ {
3
+ send_event: (dto: {
4
+ serviceResponse: ServiceRespI;
5
+ }) => Promise<void>;
6
+ }
7
+ declare const GoMailerUtil: GoMailerUtil_;
8
+ export { GoMailerUtil };
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.GoMailerUtil = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const env_1 = __importDefault(require("../env"));
9
+ const log_util_1 = require("./log.util");
10
+ const helpers_1 = require("..//helpers");
11
+ class GoMailerUtil_ {
12
+ constructor() {
13
+ this.send_event = async (dto) => {
14
+ try {
15
+ const { req, actionType } = dto.serviceResponse;
16
+ const url = 'https://automata.go-mailer.com/api/v1/events/trigger';
17
+ const user = req.user;
18
+ const body = {
19
+ event_code: actionType,
20
+ contact_email: user.email,
21
+ context: {
22
+ firstname: user.first_name,
23
+ lastname: user.last_name,
24
+ }
25
+ };
26
+ const headers = { Authorization: `Bearer ${env_1.default.GO_MAILER.API_KEY}` };
27
+ const { data } = await axios_1.default.post(url, body, { headers });
28
+ console.log('data', data);
29
+ }
30
+ catch (error) {
31
+ const err = helpers_1.RequestHelper.get_error(error);
32
+ log_util_1.LogUtil.app_log({
33
+ distinct_id: 'admin',
34
+ response: err,
35
+ request: { body: {} },
36
+ function_name: "GoMailerUtil_->send_event",
37
+ category: "SEND_EVENT",
38
+ subcategory: "GO_MAILER_SEND_EVENT",
39
+ });
40
+ console.log('GoMailerUtil_:error', error);
41
+ }
42
+ };
43
+ }
44
+ }
45
+ const GoMailerUtil = new GoMailerUtil_;
46
+ exports.GoMailerUtil = GoMailerUtil;
@@ -1,9 +1,11 @@
1
1
  import { ServiceRespI } from '../interfaces/interface';
2
2
  import { UserRequestI } from '../interfaces/user.interface';
3
+ import { AppLogPayloadI } from '../interfaces/log.interface';
3
4
  declare class LogUtil_ {
4
5
  user_event: (dto: {
5
6
  serviceResponse: ServiceRespI;
6
7
  }) => Promise<void>;
8
+ app_log: (dto: AppLogPayloadI) => Promise<void>;
7
9
  get_request: (req: UserRequestI) => {
8
10
  params: import("express-serve-static-core").ParamsDictionary;
9
11
  query: import("qs").ParsedQs;
@@ -80,6 +82,7 @@ declare class LogUtil_ {
80
82
  private get_user_event_response;
81
83
  private get_user;
82
84
  private create_activity_log;
85
+ private get_app_log_request;
83
86
  }
84
87
  declare const LogUtil: LogUtil_;
85
88
  export { LogUtil };
@@ -38,6 +38,25 @@ class LogUtil_ {
38
38
  });
39
39
  }
40
40
  };
41
+ this.app_log = async (dto) => {
42
+ try {
43
+ const payload = {
44
+ ...dto,
45
+ distinct_id: dto.distinct_id || 'admin',
46
+ response: json_stringify_safe(dto.response, null),
47
+ request: json_stringify_safe(this.get_app_log_request(dto.request), null),
48
+ type: 'APP_LOG'
49
+ };
50
+ await this.create_activity_log(payload);
51
+ }
52
+ catch (error) {
53
+ console.log(error);
54
+ airbrake_1.airbrake.notify({
55
+ error: JSON.stringify(error),
56
+ context: { component: 'APP_LOG' },
57
+ });
58
+ }
59
+ };
41
60
  this.get_request = (req) => {
42
61
  const { authorization, pin_token, ...headers_ } = req.headers;
43
62
  const { password, pin, old_pin, new_pin, bvn, nin, file, ...body_ } = req.body;
@@ -92,6 +111,12 @@ class LogUtil_ {
92
111
  throw error;
93
112
  }
94
113
  };
114
+ this.get_app_log_request = (request) => {
115
+ const { bvn, nin, ...body_ } = request.body;
116
+ return {
117
+ body: body_
118
+ };
119
+ };
95
120
  }
96
121
  }
97
122
  const LogUtil = new LogUtil_;
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.0.58",
4
+ "version": "1.0.60",
5
5
  "author": "Sodiq Alabi",
6
6
  "main": "dist/public-api.js",
7
7
  "types": "dist/public-api.d.ts",
@@ -19,6 +19,7 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@airbrake/node": "^2.1.8",
22
+ "@go-mailer/go-mailer": "^3.0.0",
22
23
  "@types/jsonwebtoken": "^8.5.0",
23
24
  "axios": "^1.7.8",
24
25
  "chalk": "^4.1.0",