@vasrefil/api-toolkit 1.2.5 → 1.2.7

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.
@@ -126,6 +126,15 @@ class RootService {
126
126
  if (error?.codeName) {
127
127
  response.message = env_1.default.ERROR_MESSAGE;
128
128
  }
129
+ if (['invalid signature', 'jwt expired'].includes(response.message)) {
130
+ response.message = 'Authentication failed. Please log in again.';
131
+ }
132
+ if (message.includes('authorization header')) {
133
+ response.message = 'Authorization failed.';
134
+ }
135
+ if (message.includes('ETIMEDOUT')) {
136
+ response.message = env_1.default.ERROR_MESSAGE;
137
+ }
129
138
  response.data = data ? data : response.data;
130
139
  return response;
131
140
  }
@@ -76,7 +76,12 @@ declare class LogUtil_ {
76
76
  };
77
77
  method: string;
78
78
  url: string;
79
+ host: string;
80
+ hostname: string;
79
81
  statusCode: number | undefined;
82
+ originalUrl: string;
83
+ baseUrl: string;
84
+ ip: string | undefined;
80
85
  body: any;
81
86
  };
82
87
  private get_user_event_response;
@@ -19,7 +19,6 @@ class LogUtil_ {
19
19
  const response = this.get_user_event_response(dto.serviceResponse);
20
20
  const payload = {
21
21
  distinct_id: user.distinct_id,
22
- service_name: env_1.default.SERVICE_NAME,
23
22
  request: json_stringify_safe(request, null),
24
23
  response: json_stringify_safe(response, null),
25
24
  request_url: request?.url,
@@ -33,7 +32,7 @@ class LogUtil_ {
33
32
  catch (error) {
34
33
  airbrake_1.airbrake.notify({
35
34
  error: json_stringify_safe(error, null),
36
- context: { component: 'USER_EVENT' },
35
+ context: { component: 'USER_EVENT', service_name: env_1.default.SERVICE_NAME },
37
36
  params: { actionType, status, request },
38
37
  });
39
38
  }
@@ -53,17 +52,28 @@ class LogUtil_ {
53
52
  console.log(error);
54
53
  airbrake_1.airbrake.notify({
55
54
  error: json_stringify_safe(error, null),
56
- context: { component: 'APP_LOG' },
55
+ context: { component: 'APP_LOG', service_name: env_1.default.SERVICE_NAME },
57
56
  });
58
57
  }
59
58
  };
60
59
  this.get_request = (req) => {
61
60
  const { authorization, pin_token, ...headers_ } = req.headers;
62
61
  const { password, pin, old_pin, new_pin, bvn, nin, file, ...body_ } = req.body;
63
- const { params, query, method, url, statusCode } = req;
62
+ const { params, query, method, url, statusCode, host, hostname, originalUrl, baseUrl } = req;
64
63
  delete headers_['pin-token'];
64
+ const ip = req.headers["x-forwarded-for"]?.split(",")[0]?.trim() || req.socket.remoteAddress;
65
65
  const request = {
66
- params, query, headers: headers_, method, url, statusCode,
66
+ params,
67
+ query,
68
+ headers: headers_,
69
+ method,
70
+ url,
71
+ host,
72
+ hostname,
73
+ statusCode,
74
+ originalUrl,
75
+ baseUrl,
76
+ ip,
67
77
  body: body_,
68
78
  };
69
79
  return request;
@@ -103,7 +113,10 @@ class LogUtil_ {
103
113
  const resp = await (0, api_request_util_1.LogApiRequest)({
104
114
  method: 'POST',
105
115
  endpoint: 'activities',
106
- body
116
+ body: {
117
+ ...body,
118
+ service_name: env_1.default.SERVICE_NAME,
119
+ }
107
120
  });
108
121
  return resp;
109
122
  }
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.2.5",
4
+ "version": "1.2.7",
5
5
  "author": "Sodiq Alabi",
6
6
  "main": "dist/public-api.js",
7
7
  "types": "dist/public-api.d.ts",
@@ -20,7 +20,6 @@
20
20
  "dependencies": {
21
21
  "@airbrake/node": "^2.1.8",
22
22
  "@types/jsonwebtoken": "^8.5.0",
23
- "@vasrefil/api-toolkit": "^1.2.4",
24
23
  "axios": "^1.7.8",
25
24
  "chalk": "^4.1.0",
26
25
  "cors": "^2.8.5",