playov2-js-utilities 0.3.23 → 0.3.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/lib/logger.js +2 -2
- package/lib/middleware.js +14 -6
- package/lib/notification.config.js +8 -5
- package/package.json +2 -1
package/lib/logger.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const PLAYO_LOGGER = require("@playo/logger")
|
|
2
2
|
|
|
3
|
-
const LOGGER = new PLAYO_LOGGER("playov2-
|
|
3
|
+
const LOGGER = new PLAYO_LOGGER("playov2-js-utilities")
|
|
4
4
|
|
|
5
5
|
const ENV = process.env.NODE_ENV || 'staging';
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ if (ENV === 'staging' || ENV === 'test') {
|
|
|
10
10
|
|
|
11
11
|
if (ENV === "production") {
|
|
12
12
|
LOGGER.setMailer({
|
|
13
|
-
'receiverEmail': ["saurabh@playo.co", "
|
|
13
|
+
'receiverEmail': ["saurabh@playo.co", "avish@playo.co"], // array of recievers, mandatory
|
|
14
14
|
'senderEmail': "logger@playo.co",// address of sender, mandatory
|
|
15
15
|
'senderName': 'Mail Logger - prod - Utitlies module', // default: Mail Logger, optional
|
|
16
16
|
'replyEmail': 'no-reply@mail.com', // default: no-reply@playo.co, optional
|
package/lib/middleware.js
CHANGED
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
|
|
2
|
-
const { v4: uuidv4
|
|
2
|
+
const { v4: uuidv4 } = require('uuid');
|
|
3
3
|
const Logger = require('./logger')
|
|
4
4
|
|
|
5
5
|
const playoServiceRequestInterceptor = (req, res, next, service = 'microservice-name') => {
|
|
6
6
|
const id = req.headers["x-request-id"] || uuidv4();
|
|
7
7
|
const start = Date.now();
|
|
8
|
-
|
|
8
|
+
let userId = 'internal-request';
|
|
9
|
+
if (req.headers.userinfo) {
|
|
10
|
+
try {
|
|
11
|
+
userId = JSON.parse(req.headers.userinfo).userId
|
|
12
|
+
} catch (error) {
|
|
13
|
+
Logger.prepareInfoLog(id, { userinfo: req.headers.userinfo }, "Malformed userInfo in headers detected");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const url = req.url;
|
|
9
17
|
const requestDetails = {
|
|
10
18
|
method: req.method,
|
|
11
19
|
params: req.params,
|
|
12
20
|
query: req.query,
|
|
13
|
-
url
|
|
21
|
+
url,
|
|
14
22
|
originalUrl: req.originalUrl,
|
|
15
23
|
service
|
|
16
24
|
};
|
|
17
|
-
if (req.body.length <
|
|
25
|
+
if (req.body && JSON.stringify(req.body).length < 10000) { // 0.1 mb
|
|
18
26
|
requestDetails['body'] = req.body || {};
|
|
19
27
|
}
|
|
20
28
|
|
|
@@ -23,13 +31,13 @@ const playoServiceRequestInterceptor = (req, res, next, service = 'microservice-
|
|
|
23
31
|
res.on('finish', function () {
|
|
24
32
|
const duration = Date.now() - start;
|
|
25
33
|
const status = res.statusCode;
|
|
26
|
-
Logger.prepareInfoLog(id, { status, duration, service }, "Outgoing request - finish event");
|
|
34
|
+
Logger.prepareInfoLog(id, { status, duration, service, url, userId }, "Outgoing request - finish event");
|
|
27
35
|
});
|
|
28
36
|
|
|
29
37
|
res.on('close', function () {
|
|
30
38
|
const duration = Date.now() - start;
|
|
31
39
|
const status = res.statusCode;
|
|
32
|
-
Logger.prepareInfoLog(id, { status, duration, service }, "Outgoing request - close event");
|
|
40
|
+
Logger.prepareInfoLog(id, { status, duration, service, url, userId }, "Outgoing request - close event");
|
|
33
41
|
});
|
|
34
42
|
next();
|
|
35
43
|
};
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
//\-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_- Private -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\//
|
|
3
|
+
// These categories correspond to notification preferences of the user
|
|
3
4
|
const notificationCategories = {
|
|
4
|
-
GROUP: 'group',
|
|
5
|
-
ACTIVITY: 'activity',
|
|
5
|
+
GROUP: 'group', // group updates
|
|
6
|
+
ACTIVITY: 'activity', // activity updates
|
|
6
7
|
KARMA: 'karma',
|
|
7
|
-
SPLIT_PAYMENTS: 'split_payments'
|
|
8
|
+
SPLIT_PAYMENTS: 'split_payments',
|
|
9
|
+
OFFERS: 'offers',
|
|
10
|
+
PLAYPAL_ACTIVITY: 'playpal-activity' // activity_suggestion_from_playpals
|
|
8
11
|
};
|
|
9
12
|
|
|
10
13
|
// Android notification channels will be bound to categories
|
|
@@ -49,7 +52,7 @@ const notificationIds = {
|
|
|
49
52
|
NEW_COMMENT: 'new-comment',
|
|
50
53
|
ACTIVITY_INVITATION: 'activity-invitation',
|
|
51
54
|
ACTIVITY_INVITATION_RESPONSE: 'activity-invitation-response',
|
|
52
|
-
ACTIVITY_REQUEST: 'activity-request',
|
|
55
|
+
ACTIVITY_REQUEST: 'activity-request', // deprecated - use ACTIVITY_REQUEST_MANAGE
|
|
53
56
|
ACTIVITY_REQUEST_RESPONSE: 'activity-request-response',
|
|
54
57
|
HOST_RETIRED: 'host-retired',
|
|
55
58
|
JOINEE_RETIRED: 'joinee-retired',
|
|
@@ -291,7 +294,7 @@ const config = {
|
|
|
291
294
|
android_channel_id: notificationChannels.activity_updates
|
|
292
295
|
},
|
|
293
296
|
[notificationIds.ACTIVITY_HOSTED]: {
|
|
294
|
-
category:
|
|
297
|
+
category: notificationCategories.PLAYPAL_ACTIVITY,
|
|
295
298
|
target: "match",
|
|
296
299
|
title: "Activity Update",
|
|
297
300
|
type: ["push", "drawer"],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "playov2-js-utilities",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.26",
|
|
4
4
|
"description": "Private package for JS utility functions",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"license": "ISC",
|
|
18
18
|
"homepage": "https://bitbucket.org/techmash/playov2-js-utilities#readme",
|
|
19
19
|
"devDependencies": {
|
|
20
|
+
"@types/uuid": "^8.3.4",
|
|
20
21
|
"faker": "^5.5.3",
|
|
21
22
|
"jest": "^27.1.0"
|
|
22
23
|
},
|