@vasrefil/api-toolkit 1.0.24 → 1.0.26

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
@@ -7,10 +7,15 @@ declare const env: {
7
7
  NODE_ENV: NODE_ENVS;
8
8
  MONGODB_URI: string;
9
9
  API_KEY: string | undefined;
10
+ SERVICE_NAME: string | undefined;
10
11
  VASREFIL: {
11
12
  BASEURL: string;
12
13
  API_KEY: string | undefined;
13
14
  };
15
+ VAS_VOUCHER: {
16
+ BASEURL: string;
17
+ API_KEY: string | undefined;
18
+ };
14
19
  LOG: {
15
20
  BASEURL: string;
16
21
  API_KEY: string | undefined;
package/dist/env.js CHANGED
@@ -13,10 +13,15 @@ const env = {
13
13
  NODE_ENV,
14
14
  MONGODB_URI: '',
15
15
  API_KEY: process.env.API_KEY,
16
+ SERVICE_NAME: process.env.SERVICE_NAME,
16
17
  VASREFIL: {
17
18
  BASEURL: NODE_ENV === NODE_ENVS.PROD ? 'https://api.vasrefil.com' : 'https://api-v2-test.vasrefil.com',
18
19
  API_KEY: process.env.VASREFIL_API_KEY
19
20
  },
21
+ VAS_VOUCHER: {
22
+ BASEURL: process.env.NODE_ENV === NODE_ENVS.PROD ? 'https://voucher-api.vasrefil.com' : 'https://voucher-api-dev.vasrefil.com',
23
+ API_KEY: process.env.VAS_VOUCHER_API_KEY
24
+ },
20
25
  LOG: {
21
26
  BASEURL: process.env.NODE_ENV === NODE_ENVS.PROD ? 'https://log-api.vasrefil.com' : 'https://log-api-dev.vasrefil.com',
22
27
  API_KEY: process.env.VASREFIL_LOG_API_KEY
@@ -3,6 +3,7 @@ import { RootService } from '../services/_root.service';
3
3
  import { AdminRequestI } from 'src/interfaces/admin.interface';
4
4
  declare class AdminAuthMidWare_ extends RootService {
5
5
  auth: (req: AdminRequestI, res: Response, next: NextFunction) => Promise<any>;
6
+ voucher_auth: (req: AdminRequestI, res: Response, next: NextFunction) => Promise<any>;
6
7
  private get_admin;
7
8
  }
8
9
  declare const AdminAuthMidWare: AdminAuthMidWare_;
@@ -31,6 +31,25 @@ class AdminAuthMidWare_ extends _root_service_1.RootService {
31
31
  return this.sendResponse({ req, res, status, actionType, message, data, error });
32
32
  }
33
33
  };
34
+ this.voucher_auth = async (req, res, next) => {
35
+ const actionType = 'AUTH_MIDWARE';
36
+ try {
37
+ const apiKey = req.headers['api-key'];
38
+ if (apiKey) {
39
+ if (apiKey !== env_1.default.VAS_VOUCHER.API_KEY)
40
+ throw user_response_1.UserApiResp.NOT_AUTHORIZED;
41
+ }
42
+ else {
43
+ const { admin_user } = await this.get_admin(req);
44
+ req.admin = admin_user;
45
+ }
46
+ next();
47
+ }
48
+ catch (error) {
49
+ const { status, message, data } = this.get_error(error);
50
+ return this.sendResponse({ req, res, status, actionType, message, data, error });
51
+ }
52
+ };
34
53
  this.get_admin = async (req) => {
35
54
  try {
36
55
  const baseurl = env_1.default.VASREFIL.BASEURL;
@@ -1,9 +1,13 @@
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
6
  exports.LogUtil = void 0;
4
7
  const airbrake_1 = require("../app-middlewares/airbrake");
5
8
  const api_request_util_1 = require("./api-request.util");
6
9
  const json_stringify_safe = require('json-stringify-safe');
10
+ const env_1 = __importDefault(require("../env"));
7
11
  class LogUtil_ {
8
12
  constructor() {
9
13
  this.user_event = async (dto) => {
@@ -15,6 +19,7 @@ class LogUtil_ {
15
19
  const response = this.get_user_event_response(dto.serviceResponse);
16
20
  const payload = {
17
21
  distinct_id: user.distinct_id,
22
+ service_name: env_1.default.SERVICE_NAME,
18
23
  request: JSON.stringify(request),
19
24
  response: JSON.stringify(response),
20
25
  request_url: request?.url,
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.24",
4
+ "version": "1.0.26",
5
5
  "author": "Sodiq Alabi",
6
6
  "main": "dist/public-api.js",
7
7
  "types": "dist/public-api.d.ts",