scharff 1.0.0 → 1.0.4

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.
Files changed (3) hide show
  1. package/README.md +33 -6
  2. package/index.js +43 -3
  3. package/package.json +18 -3
package/README.md CHANGED
@@ -1,19 +1,46 @@
1
1
  # Scharff Logger
2
- This project was created by Michael Scharff for logging purposes.
3
- The project is using the fetch-intercept NPM package.
2
+ Scharff is a lightweight and versatile Node.js package designed to enhance your application's logging capabilities by seamlessly integrating a powerful outgoing request logger. With Scharff, you can effortlessly gain insights into the interactions your application has with external services, APIs, and resources.
4
3
 
5
4
  ## Installation
6
5
  1) run `npm install scharff`.
7
6
  2) fork the git repository `https://github.com/Minka1902/scharff.git`, and place it next to your project.
8
7
 
9
8
  ## Usage
10
- 1) in your entry point, import unregister from the package: `const { unregister } = require('../../scharff/index');`
11
- 2) to stop the logger just run the unregister function: `unregister()`
9
+ 1) in your entry point, import unregister from the package: `const { unregister } = require('scharff');`
10
+ 2) to stop the logger just run the unregister function: `unregister()`, or `npm uninstall scharff`.
12
11
 
13
12
  ## What to expect
14
- The package will create a outgoingRequest.log file and start logging the requests to the file.
13
+ 1) The package will create a outgoingRequest.log file and start logging the requests to the file.
14
+ 2) In there you can see the fetch requests you sent.
15
+ 3) The request will be in the format below:</br>
16
+ {</br>
17
+ &nbsp;&nbsp;&nbsp;&nbsp;"url":"http://666.777.888.999:3000/update/www.exampe.com",</br>
18
+ &nbsp;&nbsp;&nbsp;&nbsp;"ip":"130.130.130.130",</br>
19
+ &nbsp;&nbsp;&nbsp;&nbsp;"date":{</br>
20
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;date:"20/20/2020",</br>
21
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;time:"20:20:20 PM"</br>
22
+ &nbsp;&nbsp;&nbsp;&nbsp;},</br>
23
+ &nbsp;&nbsp;&nbsp;&nbsp;"originUrl":"/update/www.example.com",</br>
24
+ &nbsp;&nbsp;&nbsp;&nbsp;"method":"PUT",</br>
25
+ &nbsp;&nbsp;&nbsp;&nbsp;"headers":{</br>
26
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Content-Type":"application/json",</br>
27
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Access-Control-Allow-Origin":"*"</br>
28
+ &nbsp;&nbsp;&nbsp;&nbsp;},</br>
29
+ &nbsp;&nbsp;&nbsp;&nbsp;"body":{</br>
30
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"isActive":true,</br>
31
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"status":200,</br>
32
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"lastChecked":"2020-20-20T20:20:20.200Z"</br>
33
+ &nbsp;&nbsp;&nbsp;&nbsp;}</br>
34
+ }
35
+
36
+ ## New in this release
37
+ 1) New date log.
38
+
39
+
40
+ ## Requirements
41
+ 1) nodejs version >= v18.0.0
15
42
 
16
43
  ## Future additions
17
44
  1) We will add a request error logger.
18
45
  2) We will add a response logger.
19
- 3) We will add a response error logger.
46
+ 3) We will add a response error logger.
package/index.js CHANGED
@@ -1,12 +1,24 @@
1
+ const { removeBaseUrl } = require('./constants/functions');
1
2
  const fetchIntercept = require('fetch-intercept');
2
3
  const fs = require('fs');
3
- const { removeBaseUrl } = require('./constants/functions');
4
+ const os = require('os');
4
5
 
5
6
  module.exports.unregister = fetchIntercept.register({
6
7
  request: function (url, config) {
8
+ const interfaces = os.networkInterfaces();
9
+ let addresses = [];
7
10
  let tempUrl = url;
11
+ for (let i in interfaces) {
12
+ for (var i2 in interfaces[i]) {
13
+ var address = interfaces[i][i2];
14
+ if (address.family === 'IPv4' && !address.internal) {
15
+ addresses.push(address.address);
16
+ }
17
+ }
18
+ }
19
+ let tempReq = { type: 'Outgoing_Request', url, ip: addresses[0] };
20
+ tempReq.date = { date: new Date().toLocaleDateString(), time: new Date().toLocaleTimeString() };
8
21
  tempUrl = removeBaseUrl(tempUrl);
9
- let tempReq = { url };
10
22
  if (tempUrl !== url) {
11
23
  tempReq.originUrl = tempUrl;
12
24
  }
@@ -42,7 +54,35 @@ module.exports.unregister = fetchIntercept.register({
42
54
  // },
43
55
 
44
56
  // response: function (response) {
45
- // // Modify the response object
57
+ // let tempRes = { incomingTime: new Date() };
58
+ // if (response) {
59
+ // if (response.status) {
60
+ // tempRes.status = { status: response.status, statusText: response.statusText };
61
+ // }
62
+ // if (response.request) {
63
+ // tempRes.request = { method: response.request.method, originalUrl: response.request.url, mode: response.request.mode };
64
+ // }
65
+ // if (response.type) {
66
+ // tempRes.type = response.type;
67
+ // }
68
+ // if (response.redirected) {
69
+ // tempRes.redirected = response.redirected;
70
+ // }
71
+ // if (response.url) {
72
+ // tempRes.url = response.url;
73
+ // }
74
+ // if (response.ok === true) {
75
+ // tempRes.isActive = true;
76
+ // } else {
77
+ // tempRes.isActive = false;
78
+ // }
79
+ // }
80
+ // fs.open('./incomingResponse.log', 'a', function (e, id) {
81
+ // fs.write(id, JSON.stringify(tempRes) + "\n", null, 'utf8', function () {
82
+ // fs.close(id, function () {
83
+ // });
84
+ // });
85
+ // });
46
86
  // return response;
47
87
  // },
48
88
 
package/package.json CHANGED
@@ -1,18 +1,33 @@
1
1
  {
2
2
  "name": "scharff",
3
- "version": "1.0.0",
3
+ "version": "1.0.4",
4
4
  "description": "Logger for outgoing requests",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
8
8
  },
9
+ "keywords": [
10
+ "logger",
11
+ "outgoing",
12
+ "request",
13
+ "response",
14
+ "error",
15
+ "fetch",
16
+ "fetch-inspector",
17
+ "inspector",
18
+ "scharff",
19
+ "npm"
20
+ ],
9
21
  "repository": {
10
22
  "type": "git",
11
23
  "url": "https://github.com/Minka1902/scharff.git"
12
24
  },
13
- "author": "Michael Scharff",
25
+ "author": {
26
+ "name": "Michael Scharff",
27
+ "email": "minka.scharff@gmail.com"
28
+ },
14
29
  "license": "ISC",
15
30
  "dependencies": {
16
31
  "fetch-intercept": "^2.4.0"
17
32
  }
18
- }
33
+ }