@vasrefil/api-toolkit 1.6.0 → 1.7.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.
@@ -0,0 +1,5 @@
1
+ export declare const connection: any;
2
+ export declare enum JOB {
3
+ EMAIL = "EMAIL",
4
+ IN_APP_NOTIFICATION = "IN_APP_NOTIFICATION"
5
+ }
@@ -0,0 +1,14 @@
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.JOB = exports.connection = void 0;
7
+ const IORedis = require('ioredis');
8
+ const env_1 = __importDefault(require("../env"));
9
+ exports.connection = new IORedis(env_1.default.BULLMQ_REDIS_URL, { maxRetriesPerRequest: null });
10
+ var JOB;
11
+ (function (JOB) {
12
+ JOB["EMAIL"] = "EMAIL";
13
+ JOB["IN_APP_NOTIFICATION"] = "IN_APP_NOTIFICATION";
14
+ })(JOB || (exports.JOB = JOB = {}));
@@ -0,0 +1,3 @@
1
+ import { Queue } from 'bullmq';
2
+ export declare const EmailQueue: Queue<any, any, string, any, any, string>;
3
+ export declare const InAppNotificationQueue: Queue<any, any, string, any, any, string>;
@@ -0,0 +1,35 @@
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.InAppNotificationQueue = exports.EmailQueue = void 0;
7
+ const bullmq_1 = require("bullmq");
8
+ const common_1 = require("./common");
9
+ const common_2 = require("./common");
10
+ const env_1 = __importDefault(require("../env"));
11
+ const attempts = env_1.default.NODE_ENV === env_1.default.NODE_ENVS.PROD ? 10 : 1;
12
+ const removeOnComplete = {
13
+ age: (3600 * 24) * 3, // 3 days
14
+ };
15
+ const backoff = {
16
+ type: 'exponential',
17
+ delay: 10000,
18
+ };
19
+ exports.EmailQueue = new bullmq_1.Queue(common_2.JOB.EMAIL, {
20
+ connection: common_1.connection,
21
+ defaultJobOptions: {
22
+ attempts,
23
+ backoff,
24
+ removeOnComplete
25
+ },
26
+ });
27
+ exports.InAppNotificationQueue = new bullmq_1.Queue(common_2.JOB.IN_APP_NOTIFICATION, {
28
+ connection: common_1.connection,
29
+ defaultJobOptions: {
30
+ attempts: 1,
31
+ backoff,
32
+ removeOnComplete,
33
+ removeOnFail: removeOnComplete
34
+ },
35
+ });
package/dist/env.d.ts CHANGED
@@ -5,10 +5,12 @@ declare enum NODE_ENVS {
5
5
  }
6
6
  declare const env: {
7
7
  NODE_ENV: NODE_ENVS;
8
+ NODE_ENVS: typeof NODE_ENVS;
8
9
  MONGODB_URI: string | undefined;
9
10
  API_KEY: string | undefined;
10
11
  SERVICE_NAME: string | undefined;
11
12
  REDIS_URL: string;
13
+ BULLMQ_REDIS_URL: string;
12
14
  ERROR_MESSAGE: string;
13
15
  VASREFIL: {
14
16
  BASEURL: string;
package/dist/env.js CHANGED
@@ -11,10 +11,12 @@ var NODE_ENVS;
11
11
  let NODE_ENV = process.env.NODE_ENV;
12
12
  const env = {
13
13
  NODE_ENV,
14
+ NODE_ENVS,
14
15
  MONGODB_URI: process.env.MONGODB_URI,
15
16
  API_KEY: process.env.API_KEY,
16
17
  SERVICE_NAME: process.env.SERVICE_NAME,
17
18
  REDIS_URL: process.env.REDIS_URL,
19
+ BULLMQ_REDIS_URL: process.env.BULLMQ_REDIS_URL,
18
20
  ERROR_MESSAGE: 'Sorry an error occured, please try again later',
19
21
  VASREFIL: {
20
22
  BASEURL: NODE_ENV === NODE_ENVS.PROD ? 'https://api.vasrefil.com' : 'https://api-v2-test.vasrefil.com',
@@ -22,7 +22,7 @@ declare class GoMailerUtil_ {
22
22
  }) => Promise<void>;
23
23
  trigger_event: (payload: GoMailerEventPayload) => Promise<any>;
24
24
  send_transactional_email: (payload: GoMailerEmailPayload) => Promise<any>;
25
- sync_contact: (payload: any) => Promise<any>;
25
+ sync_contact: (payload: any, throw_new_error?: boolean) => Promise<any>;
26
26
  }
27
27
  declare const GoMailerUtil: GoMailerUtil_;
28
28
  export { GoMailerUtil };
@@ -13,6 +13,8 @@ class GoMailerUtil_ {
13
13
  constructor() {
14
14
  this.send_event = async (dto) => {
15
15
  try {
16
+ if (env_1.default.NODE_ENV !== env_1.default.NODE_ENVS.PROD)
17
+ return;
16
18
  const { req, actionType } = dto.serviceResponse;
17
19
  const user = req.user;
18
20
  const transaction = req.transaction;
@@ -84,7 +86,7 @@ class GoMailerUtil_ {
84
86
  throw err;
85
87
  }
86
88
  };
87
- this.sync_contact = async (payload) => {
89
+ this.sync_contact = async (payload, throw_new_error = false) => {
88
90
  try {
89
91
  const headers = { Authorization: `Bearer ${env_1.default.GO_MAILER.API_KEY}` };
90
92
  const url = 'https://api.go-mailer.com/v1/contacts';
@@ -92,7 +94,8 @@ class GoMailerUtil_ {
92
94
  return data;
93
95
  }
94
96
  catch (error) {
95
- throw helpers_1.RequestHelper.get_error(error);
97
+ const err = helpers_1.RequestHelper.get_error(error);
98
+ throw throw_new_error ? new Error(err) : err;
96
99
  }
97
100
  };
98
101
  }
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.6.0",
4
+ "version": "1.7.0",
5
5
  "author": "Sodiq Alabi",
6
6
  "main": "dist/public-api.js",
7
7
  "types": "dist/public-api.d.ts",
@@ -21,6 +21,7 @@
21
21
  "@airbrake/node": "^2.1.8",
22
22
  "@types/jsonwebtoken": "^8.5.0",
23
23
  "axios": "^1.7.8",
24
+ "bullmq": "^5.64.1",
24
25
  "chalk": "^4.1.0",
25
26
  "cors": "^2.8.5",
26
27
  "date-fns": "^2.29.3",