playov2-js-utilities 0.3.19 → 0.3.22

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/index.js CHANGED
@@ -10,5 +10,6 @@ module.exports = {
10
10
  NotificationConfig: require('./notification.config'),
11
11
  httpRequest: require('./request'),
12
12
  Cron: require('./cron'),
13
- MessagePublisher: require('./message_publisher')
13
+ MessagePublisher: require('./message_publisher'),
14
+ middleware: require('./middleware')
14
15
  };
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,39 @@
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
+ const requestDetails = {
10
+ method: req.method,
11
+ params: req.params,
12
+ query: req.query,
13
+ url: req.url,
14
+ originalUrl: req.originalUrl,
15
+ service
16
+ };
17
+ if (req.body.length < 1000) {
18
+ requestDetails['body'] = req.body || {};
19
+ }
20
+
21
+ Logger.prepareInfoLog(id, requestDetails, "Incoming request");
22
+
23
+ res.on('finish', function () {
24
+ const duration = Date.now() - start;
25
+ const status = res.statusCode;
26
+ Logger.prepareInfoLog(id, { res, status, duration, service }, "Outgoing request - finish event");
27
+ });
28
+
29
+ res.on('close', function () {
30
+ const duration = Date.now() - start;
31
+ const status = res.statusCode;
32
+ Logger.prepareInfoLog(id, { res, status, duration, service }, "Outgoing request - close event");
33
+ });
34
+ next();
35
+ };
36
+
37
+ module.exports = {
38
+ playoServiceRequestInterceptor
39
+ }
@@ -100,7 +100,7 @@ const config = {
100
100
  target: "group",
101
101
  path: "manage",
102
102
  title: "Group Invitation",
103
- type: ["push"],
103
+ type: ["push", "drawer"],
104
104
  buttons: [],
105
105
  android_channel_id: notificationChannels.groups_manage_requests
106
106
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playov2-js-utilities",
3
- "version": "0.3.19",
3
+ "version": "0.3.22",
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.18",
25
+ "@playo/logger": "^0.9.24",
26
26
  "axios": "^0.24.0",
27
27
  "cron": "^1.8.2",
28
28
  "handlebars": "^4.7.7",