@vasrefil/api-toolkit 1.0.26 → 1.0.28

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
@@ -16,6 +16,10 @@ declare const env: {
16
16
  BASEURL: string;
17
17
  API_KEY: string | undefined;
18
18
  };
19
+ EDUCATION: {
20
+ BASEURL: string;
21
+ API_KEY: string | undefined;
22
+ };
19
23
  LOG: {
20
24
  BASEURL: string;
21
25
  API_KEY: string | undefined;
package/dist/env.js CHANGED
@@ -22,6 +22,10 @@ const env = {
22
22
  BASEURL: process.env.NODE_ENV === NODE_ENVS.PROD ? 'https://voucher-api.vasrefil.com' : 'https://voucher-api-dev.vasrefil.com',
23
23
  API_KEY: process.env.VAS_VOUCHER_API_KEY
24
24
  },
25
+ EDUCATION: {
26
+ BASEURL: process.env.NODE_ENV === NODE_ENVS.PROD ? 'https://education-api.vasrefil.com' : 'https://education-api-dev.vasrefil.com',
27
+ API_KEY: process.env.VASREFIL_EDUCATION_API_KEY
28
+ },
25
29
  LOG: {
26
30
  BASEURL: process.env.NODE_ENV === NODE_ENVS.PROD ? 'https://log-api.vasrefil.com' : 'https://log-api-dev.vasrefil.com',
27
31
  API_KEY: process.env.VASREFIL_LOG_API_KEY
@@ -1,3 +1,4 @@
1
1
  export * from './currency-formatter.helper';
2
2
  export * from './query.helper';
3
3
  export * from './request.helper';
4
+ export * from './unique-id.helper';
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./currency-formatter.helper"), exports);
18
18
  __exportStar(require("./query.helper"), exports);
19
19
  __exportStar(require("./request.helper"), exports);
20
+ __exportStar(require("./unique-id.helper"), exports);
@@ -0,0 +1 @@
1
+ export declare const UniqueIdHelper: () => string;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UniqueIdHelper = void 0;
4
+ const UniqueIdHelper = () => {
5
+ const head = Date.now();
6
+ const tail = (Math.random() * 5) * (Math.random() * 5);
7
+ return `${head}${Math.floor(tail)}`;
8
+ };
9
+ exports.UniqueIdHelper = UniqueIdHelper;
@@ -1,9 +1,10 @@
1
1
  import { Response, NextFunction } from 'express';
2
2
  import { RootService } from '../services/_root.service';
3
- import { AdminRequestI } from 'src/interfaces/admin.interface';
3
+ import { AdminRequestI } from '../interfaces/admin.interface';
4
4
  declare class AdminAuthMidWare_ extends RootService {
5
5
  auth: (req: AdminRequestI, res: Response, next: NextFunction) => Promise<any>;
6
6
  voucher_auth: (req: AdminRequestI, res: Response, next: NextFunction) => Promise<any>;
7
+ edu_auth: (req: AdminRequestI, res: Response, next: NextFunction) => Promise<any>;
7
8
  private get_admin;
8
9
  }
9
10
  declare const AdminAuthMidWare: AdminAuthMidWare_;
@@ -13,7 +13,7 @@ class AdminAuthMidWare_ extends _root_service_1.RootService {
13
13
  constructor() {
14
14
  super(...arguments);
15
15
  this.auth = async (req, res, next) => {
16
- const actionType = 'AUTH_MIDWARE';
16
+ const actionType = 'ADMIN_AUTH_MIDWARE';
17
17
  try {
18
18
  const apiKey = req.headers['api-key'];
19
19
  if (apiKey) {
@@ -32,7 +32,7 @@ class AdminAuthMidWare_ extends _root_service_1.RootService {
32
32
  }
33
33
  };
34
34
  this.voucher_auth = async (req, res, next) => {
35
- const actionType = 'AUTH_MIDWARE';
35
+ const actionType = 'VOUCHER_ADMIN_AUTH_MIDWARE';
36
36
  try {
37
37
  const apiKey = req.headers['api-key'];
38
38
  if (apiKey) {
@@ -50,6 +50,25 @@ class AdminAuthMidWare_ extends _root_service_1.RootService {
50
50
  return this.sendResponse({ req, res, status, actionType, message, data, error });
51
51
  }
52
52
  };
53
+ this.edu_auth = async (req, res, next) => {
54
+ const actionType = 'EDU_ADMIN_AUTH_MIDWARE';
55
+ try {
56
+ const apiKey = req.headers['api-key'];
57
+ if (apiKey) {
58
+ if (apiKey !== env_1.default.EDUCATION.API_KEY)
59
+ throw user_response_1.UserApiResp.NOT_AUTHORIZED;
60
+ }
61
+ else {
62
+ const { admin_user } = await this.get_admin(req);
63
+ req.admin = admin_user;
64
+ }
65
+ next();
66
+ }
67
+ catch (error) {
68
+ const { status, message, data } = this.get_error(error);
69
+ return this.sendResponse({ req, res, status, actionType, message, data, error });
70
+ }
71
+ };
53
72
  this.get_admin = async (req) => {
54
73
  try {
55
74
  const baseurl = env_1.default.VASREFIL.BASEURL;
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.26",
4
+ "version": "1.0.28",
5
5
  "author": "Sodiq Alabi",
6
6
  "main": "dist/public-api.js",
7
7
  "types": "dist/public-api.d.ts",