playov2-js-utilities 0.3.17 → 0.3.20
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/lib/logger.js +115 -0
- package/lib/middleware.js +27 -0
- package/lib/notification.config.js +12 -11
- package/package.json +2 -2
package/lib/logger.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
const PLAYO_LOGGER = require("@playo/logger")
|
|
2
|
+
|
|
3
|
+
const LOGGER = new PLAYO_LOGGER("playov2-activity")
|
|
4
|
+
|
|
5
|
+
const ENV = process.env.NODE_ENV || 'staging';
|
|
6
|
+
|
|
7
|
+
if (ENV === 'staging' || ENV === 'test') {
|
|
8
|
+
LOGGER.setSlack('# test');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (ENV === "production") {
|
|
12
|
+
LOGGER.setMailer({
|
|
13
|
+
'receiverEmail': ["saurabh@playo.co", "umashankar@playo.co", "avish@playo.co"], // array of recievers, mandatory
|
|
14
|
+
'senderEmail': "logger@playo.co",// address of sender, mandatory
|
|
15
|
+
'senderName': 'Mail Logger - prod - Utitlies module', // default: Mail Logger, optional
|
|
16
|
+
'replyEmail': 'no-reply@mail.com', // default: no-reply@playo.co, optional
|
|
17
|
+
'region': "us-east-1", // default: 'us-east-1', optional
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
LOGGER.setSlack('# server_alerts');
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Info log - use where some stack trace needs to be stored for later debug purpose
|
|
25
|
+
* @param {String} id
|
|
26
|
+
* @param {Object} data
|
|
27
|
+
* @param {String} message
|
|
28
|
+
*/
|
|
29
|
+
const prepareInfoLog = (
|
|
30
|
+
id = "info-log",
|
|
31
|
+
data = {},
|
|
32
|
+
message = "info-message"
|
|
33
|
+
) => {
|
|
34
|
+
LOGGER.info(id, data, message);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Error log - used to monitor error throughout the system
|
|
39
|
+
* @param {String} id
|
|
40
|
+
* @param {Object} data
|
|
41
|
+
* @param {String} message
|
|
42
|
+
*/
|
|
43
|
+
const prepareErrorLog = (
|
|
44
|
+
id = "error-log",
|
|
45
|
+
data = {},
|
|
46
|
+
message = "error-message"
|
|
47
|
+
) => {
|
|
48
|
+
if (data.stack) {
|
|
49
|
+
data = data.stack;
|
|
50
|
+
}
|
|
51
|
+
LOGGER.error(id, data, message);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Alert log - Sends alert on slack and email to notify to concerned people
|
|
56
|
+
* @param {String} id
|
|
57
|
+
* @param {Object} data
|
|
58
|
+
* @param {String} message
|
|
59
|
+
* @param {Boolean} sendEmail
|
|
60
|
+
*/
|
|
61
|
+
const prepareAlertLog = (
|
|
62
|
+
id = "alert-log",
|
|
63
|
+
data = {},
|
|
64
|
+
message = "alert-message",
|
|
65
|
+
sendEmail = false
|
|
66
|
+
) => {
|
|
67
|
+
LOGGER.alert(id, data, message, sendEmail);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Use this to debug , ideally only on staging env
|
|
72
|
+
* @param {String} id
|
|
73
|
+
* @param {Object} data
|
|
74
|
+
* @param {String} message
|
|
75
|
+
*/
|
|
76
|
+
const prepareDebugLog = (
|
|
77
|
+
id = "alert log",
|
|
78
|
+
data = {},
|
|
79
|
+
message = "debug-log"
|
|
80
|
+
) => {
|
|
81
|
+
LOGGER.debug(id, data, message);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Use this to print error or failure that do not need to fixed on an urgent basis but need to later analyzed later
|
|
86
|
+
* @param {String} id
|
|
87
|
+
* @param {Object} data
|
|
88
|
+
* @param {String} message
|
|
89
|
+
*/
|
|
90
|
+
const prepareWarnLog = (
|
|
91
|
+
id = "warn log",
|
|
92
|
+
data = {},
|
|
93
|
+
message = "warn-log",
|
|
94
|
+
topic = 'warn-topic'
|
|
95
|
+
) => {
|
|
96
|
+
LOGGER.warn(id, data, message, topic);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Set module name for your module to be observed in logs
|
|
101
|
+
* @param {String} moduleName
|
|
102
|
+
* @returns
|
|
103
|
+
*/
|
|
104
|
+
const setModule = (moduleName) => {
|
|
105
|
+
return LOGGER.setModule(moduleName);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
module.exports = {
|
|
109
|
+
prepareInfoLog,
|
|
110
|
+
prepareErrorLog,
|
|
111
|
+
prepareAlertLog,
|
|
112
|
+
prepareDebugLog,
|
|
113
|
+
prepareWarnLog,
|
|
114
|
+
setModule,
|
|
115
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
const { v4: uuidv4, v4 } = require('uuid');
|
|
3
|
+
const Logger = require('./logger')
|
|
4
|
+
|
|
5
|
+
const playoServiceRequestInterceptor = (req, res, next, service = 'microservice-name') => {
|
|
6
|
+
const id = req.headers["x-request-id"] || uuidv4();
|
|
7
|
+
const start = Date.now();
|
|
8
|
+
|
|
9
|
+
Logger.prepareInfoLog(id, { body: req.body, path: req.params, query: req.query, url: req.originalUrl, service }, "Incoming request");
|
|
10
|
+
|
|
11
|
+
res.on('finish', function() {
|
|
12
|
+
const duration = Date.now() - start;
|
|
13
|
+
const status = res.status;
|
|
14
|
+
Logger.prepareInfoLog(id, { res, status, duration, service }, "Outgoing request - finish event");
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
res.on('close', function() {
|
|
18
|
+
const duration = Date.now() - start;
|
|
19
|
+
const status = res.status;
|
|
20
|
+
Logger.prepareInfoLog(id, { res, status, duration, service }, "Outgoing request - close event");
|
|
21
|
+
});
|
|
22
|
+
next();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
module.exports = {
|
|
26
|
+
playoServiceRequestInterceptor
|
|
27
|
+
}
|
|
@@ -52,6 +52,7 @@ const notificationIds = {
|
|
|
52
52
|
ACTIVITY_REQUEST: 'activity-request',
|
|
53
53
|
ACTIVITY_REQUEST_RESPONSE: 'activity-request-response',
|
|
54
54
|
HOST_RETIRED: 'host-retired',
|
|
55
|
+
JOINEE_RETIRED: 'joinee-retired',
|
|
55
56
|
EDIT_ACTIVITY: 'edit-activity',
|
|
56
57
|
ACTIVITY_FULL: 'activity-full',
|
|
57
58
|
VENUE_TAGGED: 'venue-tagged',
|
|
@@ -61,7 +62,6 @@ const notificationIds = {
|
|
|
61
62
|
COHOST_DELETED: 'cohost-deleted',
|
|
62
63
|
ACTIVITY_QUERY: 'activity-query',
|
|
63
64
|
ACTIVITY_CANCEL: 'activity-cancel',
|
|
64
|
-
ACTIVITY_REMINDER: 'activity-reminder',
|
|
65
65
|
ACTIVITY_HOSTED: 'activity-hosted',
|
|
66
66
|
ACTIVITY_REQUEST_MANAGE: 'activity-request-manage',
|
|
67
67
|
ACTIVITY_JOINED: 'activity-joined',
|
|
@@ -201,6 +201,15 @@ const config = {
|
|
|
201
201
|
android_channel_id: notificationChannels.activity_player_in_out
|
|
202
202
|
},
|
|
203
203
|
[notificationIds.HOST_RETIRED]: {
|
|
204
|
+
category: notificationCategories.ACTIVITY,
|
|
205
|
+
target: "match",
|
|
206
|
+
path: "manage",
|
|
207
|
+
title: "Activity Update",
|
|
208
|
+
type: ["push", "drawer"],
|
|
209
|
+
buttons: [],
|
|
210
|
+
android_channel_id: notificationChannels.activity_player_in_out
|
|
211
|
+
},
|
|
212
|
+
[notificationIds.JOINEE_RETIRED]: {
|
|
204
213
|
category: notificationCategories.ACTIVITY,
|
|
205
214
|
target: "match",
|
|
206
215
|
title: "Activity Update",
|
|
@@ -281,14 +290,6 @@ const config = {
|
|
|
281
290
|
buttons: [],
|
|
282
291
|
android_channel_id: notificationChannels.activity_updates
|
|
283
292
|
},
|
|
284
|
-
[notificationIds.ACTIVITY_REMINDER]: {
|
|
285
|
-
category: notificationCategories.ACTIVITY,
|
|
286
|
-
target: "match",
|
|
287
|
-
title: "Activity Reminder",
|
|
288
|
-
type: ["push"],
|
|
289
|
-
buttons: [],
|
|
290
|
-
android_channel_id: notificationChannels.activity_player_in_out
|
|
291
|
-
},
|
|
292
293
|
[notificationIds.ACTIVITY_HOSTED]: {
|
|
293
294
|
category: "playpal-activity",
|
|
294
295
|
target: "match",
|
|
@@ -413,7 +414,7 @@ const config = {
|
|
|
413
414
|
},
|
|
414
415
|
[notificationIds.HOST_ACTIVITY_PAYOUT]: {
|
|
415
416
|
category: notificationCategories.ACTIVITY,
|
|
416
|
-
target: "
|
|
417
|
+
target: "passbook/0",
|
|
417
418
|
title: "Activity Update",
|
|
418
419
|
type: ["push", "drawer"],
|
|
419
420
|
buttons: [],
|
|
@@ -421,7 +422,7 @@ const config = {
|
|
|
421
422
|
},
|
|
422
423
|
[notificationIds.KARMA_CASHBACK]: {
|
|
423
424
|
category: notificationCategories.ACTIVITY,
|
|
424
|
-
target: "passbook",
|
|
425
|
+
target: "passbook/1",
|
|
425
426
|
title: "Karma Update",
|
|
426
427
|
type: ["push", "drawer"],
|
|
427
428
|
android_channel_id: notificationChannels.karma,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "playov2-js-utilities",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.20",
|
|
4
4
|
"description": "Private package for JS utility functions",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@google-cloud/tasks": "^2.5.0",
|
|
25
|
-
"@playo/logger": "^0.9.
|
|
25
|
+
"@playo/logger": "^0.9.24",
|
|
26
26
|
"axios": "^0.24.0",
|
|
27
27
|
"cron": "^1.8.2",
|
|
28
28
|
"handlebars": "^4.7.7",
|