@contrast/agent 4.16.2 → 4.18.0
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/esm.mjs +21 -11
- package/lib/assess/policy/propagators.json +4 -0
- package/lib/assess/policy/signatures.json +5 -0
- package/lib/assess/propagators/fastify-static/allowed-path.js +85 -0
- package/lib/assess/sources/index.js +26 -5
- package/lib/cli-rewriter/index.js +1 -1
- package/lib/contrast.js +1 -1
- package/lib/core/config/options.js +14 -1
- package/lib/core/config/util.js +39 -11
- package/lib/core/rewrite/index.js +2 -2
- package/lib/protect/service.js +2 -0
- package/lib/util/trace-util.js +5 -4
- package/node_modules/@colors/colors/LICENSE +26 -0
- package/node_modules/@colors/colors/README.md +219 -0
- package/node_modules/@colors/colors/examples/normal-usage.js +83 -0
- package/node_modules/@colors/colors/examples/safe-string.js +80 -0
- package/node_modules/@colors/colors/index.d.ts +136 -0
- package/node_modules/@colors/colors/lib/colors.js +211 -0
- package/node_modules/@colors/colors/lib/custom/trap.js +46 -0
- package/node_modules/@colors/colors/lib/custom/zalgo.js +110 -0
- package/node_modules/@colors/colors/lib/extendStringPrototype.js +110 -0
- package/node_modules/@colors/colors/lib/index.js +13 -0
- package/node_modules/@colors/colors/lib/maps/america.js +10 -0
- package/node_modules/@colors/colors/lib/maps/rainbow.js +12 -0
- package/node_modules/@colors/colors/lib/maps/random.js +11 -0
- package/node_modules/@colors/colors/lib/maps/zebra.js +5 -0
- package/node_modules/@colors/colors/lib/styles.js +95 -0
- package/node_modules/@colors/colors/lib/system/has-flag.js +35 -0
- package/node_modules/@colors/colors/lib/system/supports-colors.js +151 -0
- package/node_modules/@colors/colors/package.json +49 -0
- package/node_modules/@colors/colors/safe.d.ts +48 -0
- package/node_modules/@colors/colors/safe.js +10 -0
- package/node_modules/@colors/colors/themes/generic-logging.js +12 -0
- package/node_modules/@dabh/diagnostics/README.md +16 -16
- package/node_modules/@dabh/diagnostics/package.json +9 -9
- package/node_modules/color/README.md +9 -0
- package/node_modules/color/index.js +4 -1
- package/node_modules/color/package.json +8 -8
- package/node_modules/color-string/README.md +6 -2
- package/node_modules/color-string/index.js +21 -13
- package/node_modules/color-string/package.json +4 -4
- package/node_modules/colorspace/package.json +5 -5
- package/node_modules/fecha/dist/fecha.min.js +1 -1
- package/node_modules/fecha/dist/fecha.min.js.map +1 -0
- package/node_modules/fecha/lib/fecha.d.ts +2 -2
- package/node_modules/fecha/lib/fecha.js +35 -18
- package/node_modules/fecha/lib/fecha.js.map +1 -0
- package/node_modules/fecha/lib/fecha.umd.js +35 -18
- package/node_modules/fecha/lib/fecha.umd.js.map +1 -0
- package/node_modules/fecha/package.json +9 -10
- package/node_modules/fecha/src/fecha.ts +524 -0
- package/node_modules/logform/.eslintrc +1 -1
- package/node_modules/logform/CHANGELOG.md +24 -0
- package/node_modules/logform/README.md +15 -17
- package/node_modules/logform/browser.js +3 -1
- package/node_modules/logform/cli.js +1 -1
- package/node_modules/logform/colorize.js +2 -2
- package/node_modules/logform/dist/browser.js +8 -2
- package/node_modules/logform/dist/cli.js +2 -2
- package/node_modules/logform/dist/colorize.js +5 -5
- package/node_modules/logform/dist/errors.js +1 -1
- package/node_modules/logform/dist/format.js +9 -5
- package/node_modules/logform/dist/index.js +53 -20
- package/node_modules/logform/dist/json.js +7 -6
- package/node_modules/logform/dist/logstash.js +1 -1
- package/node_modules/logform/dist/pad-levels.js +4 -4
- package/node_modules/logform/dist/printf.js +1 -1
- package/node_modules/logform/dist/simple.js +1 -1
- package/node_modules/logform/dist/splat.js +2 -2
- package/node_modules/logform/dist/uncolorize.js +1 -1
- package/node_modules/logform/errors.js +1 -1
- package/node_modules/logform/index.d.ts +36 -0
- package/node_modules/logform/index.js +19 -20
- package/node_modules/logform/json.js +7 -7
- package/node_modules/logform/logstash.js +1 -1
- package/node_modules/logform/package.json +10 -9
- package/node_modules/logform/simple.js +1 -1
- package/node_modules/logform/uncolorize.js +1 -1
- package/node_modules/safe-stable-stringify/CHANGELOG.md +75 -0
- package/node_modules/safe-stable-stringify/LICENSE +21 -0
- package/node_modules/safe-stable-stringify/esm/package.json +4 -0
- package/node_modules/safe-stable-stringify/esm/wrapper.js +6 -0
- package/node_modules/safe-stable-stringify/index.d.ts +18 -0
- package/node_modules/safe-stable-stringify/index.js +618 -0
- package/node_modules/safe-stable-stringify/package.json +69 -0
- package/node_modules/safe-stable-stringify/readme.md +170 -0
- package/node_modules/safe-stable-stringify/tsconfig.json +22 -0
- package/node_modules/winston/LICENSE +18 -18
- package/node_modules/winston/README.md +1231 -1230
- package/node_modules/winston/dist/winston/common.js +10 -10
- package/node_modules/winston/dist/winston/config/index.js +17 -17
- package/node_modules/winston/dist/winston/container.js +46 -46
- package/node_modules/winston/dist/winston/create-logger.js +28 -24
- package/node_modules/winston/dist/winston/exception-handler.js +49 -49
- package/node_modules/winston/dist/winston/exception-stream.js +27 -27
- package/node_modules/winston/dist/winston/logger.js +152 -138
- package/node_modules/winston/dist/winston/profiler.js +22 -22
- package/node_modules/winston/dist/winston/rejection-handler.js +54 -54
- package/node_modules/winston/dist/winston/tail-file.js +14 -14
- package/node_modules/winston/dist/winston/transports/console.js +31 -31
- package/node_modules/winston/dist/winston/transports/file.js +101 -101
- package/node_modules/winston/dist/winston/transports/http.js +119 -41
- package/node_modules/winston/dist/winston/transports/index.js +17 -17
- package/node_modules/winston/dist/winston/transports/stream.js +24 -24
- package/node_modules/winston/dist/winston.js +91 -97
- package/node_modules/winston/index.d.ts +213 -193
- package/node_modules/winston/lib/winston/common.js +61 -61
- package/node_modules/winston/lib/winston/config/index.d.ts +99 -98
- package/node_modules/winston/lib/winston/config/index.js +35 -35
- package/node_modules/winston/lib/winston/container.js +114 -114
- package/node_modules/winston/lib/winston/create-logger.js +104 -104
- package/node_modules/winston/lib/winston/exception-handler.js +245 -245
- package/node_modules/winston/lib/winston/exception-stream.js +54 -54
- package/node_modules/winston/lib/winston/logger.js +676 -667
- package/node_modules/winston/lib/winston/profiler.js +51 -51
- package/node_modules/winston/lib/winston/rejection-handler.js +251 -251
- package/node_modules/winston/lib/winston/tail-file.js +124 -124
- package/node_modules/winston/lib/winston/transports/console.js +117 -117
- package/node_modules/winston/lib/winston/transports/file.js +695 -695
- package/node_modules/winston/lib/winston/transports/http.js +267 -202
- package/node_modules/winston/lib/winston/transports/index.d.ts +103 -100
- package/node_modules/winston/lib/winston/transports/index.js +56 -56
- package/node_modules/winston/lib/winston/transports/stream.js +63 -63
- package/node_modules/winston/lib/winston.js +176 -182
- package/node_modules/winston/node_modules/winston-transport/.babelrc +3 -0
- package/node_modules/winston/node_modules/winston-transport/.eslintrc +7 -0
- package/node_modules/winston/node_modules/winston-transport/.gitattributes +1 -0
- package/node_modules/winston/node_modules/winston-transport/.nyc_output/c3d7ddb9-cc26-466b-a4f6-993ad69e86f6.json +1 -0
- package/node_modules/winston/node_modules/winston-transport/.nyc_output/processinfo/c3d7ddb9-cc26-466b-a4f6-993ad69e86f6.json +1 -0
- package/node_modules/winston/node_modules/winston-transport/.nyc_output/processinfo/index.json +1 -0
- package/node_modules/winston/node_modules/winston-transport/CHANGELOG.md +126 -0
- package/node_modules/winston/node_modules/winston-transport/LICENSE +22 -0
- package/node_modules/winston/node_modules/winston-transport/README.md +50 -0
- package/node_modules/winston/node_modules/winston-transport/dist/index.js +215 -0
- package/node_modules/winston/node_modules/winston-transport/dist/legacy.js +116 -0
- package/node_modules/winston/node_modules/winston-transport/index.d.ts +39 -0
- package/node_modules/winston/node_modules/winston-transport/index.js +215 -0
- package/node_modules/winston/node_modules/winston-transport/legacy.js +119 -0
- package/node_modules/winston/node_modules/winston-transport/package.json +56 -0
- package/node_modules/winston/package.json +76 -75
- package/package.json +9 -6
- package/node_modules/@dabh/diagnostics/example.png +0 -0
- package/node_modules/color-string/CHANGELOG.md +0 -18
- package/node_modules/colorspace/test.js +0 -14
- package/node_modules/fecha/CHANGELOG.md +0 -67
- package/node_modules/logform/.travis.yml +0 -17
- package/node_modules/winston/CHANGELOG.md +0 -560
|
@@ -1,202 +1,267 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* http.js: Transport for outputting to a json-rpcserver.
|
|
3
|
-
*
|
|
4
|
-
* (C) 2010 Charlie Robbins
|
|
5
|
-
* MIT LICENCE
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
const http = require('http');
|
|
11
|
-
const https = require('https');
|
|
12
|
-
const { Stream } = require('readable-stream');
|
|
13
|
-
const TransportStream = require('winston-transport');
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
* @
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
this.
|
|
32
|
-
this.
|
|
33
|
-
this.
|
|
34
|
-
this.
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
37
|
-
this.
|
|
38
|
-
this.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
1
|
+
/**
|
|
2
|
+
* http.js: Transport for outputting to a json-rpcserver.
|
|
3
|
+
*
|
|
4
|
+
* (C) 2010 Charlie Robbins
|
|
5
|
+
* MIT LICENCE
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
const http = require('http');
|
|
11
|
+
const https = require('https');
|
|
12
|
+
const { Stream } = require('readable-stream');
|
|
13
|
+
const TransportStream = require('winston-transport');
|
|
14
|
+
const jsonStringify = require('safe-stable-stringify');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Transport for outputting to a json-rpc server.
|
|
18
|
+
* @type {Stream}
|
|
19
|
+
* @extends {TransportStream}
|
|
20
|
+
*/
|
|
21
|
+
module.exports = class Http extends TransportStream {
|
|
22
|
+
/**
|
|
23
|
+
* Constructor function for the Http transport object responsible for
|
|
24
|
+
* persisting log messages and metadata to a terminal or TTY.
|
|
25
|
+
* @param {!Object} [options={}] - Options for this instance.
|
|
26
|
+
*/
|
|
27
|
+
// eslint-disable-next-line max-statements
|
|
28
|
+
constructor(options = {}) {
|
|
29
|
+
super(options);
|
|
30
|
+
|
|
31
|
+
this.options = options;
|
|
32
|
+
this.name = options.name || 'http';
|
|
33
|
+
this.ssl = !!options.ssl;
|
|
34
|
+
this.host = options.host || 'localhost';
|
|
35
|
+
this.port = options.port;
|
|
36
|
+
this.auth = options.auth;
|
|
37
|
+
this.path = options.path || '';
|
|
38
|
+
this.agent = options.agent;
|
|
39
|
+
this.headers = options.headers || {};
|
|
40
|
+
this.headers['content-type'] = 'application/json';
|
|
41
|
+
this.batch = options.batch || false;
|
|
42
|
+
this.batchInterval = options.batchInterval || 5000;
|
|
43
|
+
this.batchCount = options.batchCount || 10;
|
|
44
|
+
this.batchOptions = [];
|
|
45
|
+
this.batchTimeoutID = -1;
|
|
46
|
+
this.batchCallback = {};
|
|
47
|
+
|
|
48
|
+
if (!this.port) {
|
|
49
|
+
this.port = this.ssl ? 443 : 80;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Core logging method exposed to Winston.
|
|
55
|
+
* @param {Object} info - TODO: add param description.
|
|
56
|
+
* @param {function} callback - TODO: add param description.
|
|
57
|
+
* @returns {undefined}
|
|
58
|
+
*/
|
|
59
|
+
log(info, callback) {
|
|
60
|
+
this._request(info, (err, res) => {
|
|
61
|
+
if (res && res.statusCode !== 200) {
|
|
62
|
+
err = new Error(`Invalid HTTP Status Code: ${res.statusCode}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (err) {
|
|
66
|
+
this.emit('warn', err);
|
|
67
|
+
} else {
|
|
68
|
+
this.emit('logged', info);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Remark: (jcrugzz) Fire and forget here so requests dont cause buffering
|
|
73
|
+
// and block more requests from happening?
|
|
74
|
+
if (callback) {
|
|
75
|
+
setImmediate(callback);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Query the transport. Options object is optional.
|
|
81
|
+
* @param {Object} options - Loggly-like query options for this instance.
|
|
82
|
+
* @param {function} callback - Continuation to respond to when complete.
|
|
83
|
+
* @returns {undefined}
|
|
84
|
+
*/
|
|
85
|
+
query(options, callback) {
|
|
86
|
+
if (typeof options === 'function') {
|
|
87
|
+
callback = options;
|
|
88
|
+
options = {};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
options = {
|
|
92
|
+
method: 'query',
|
|
93
|
+
params: this.normalizeQuery(options)
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
if (options.params.path) {
|
|
97
|
+
options.path = options.params.path;
|
|
98
|
+
delete options.params.path;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (options.params.auth) {
|
|
102
|
+
options.auth = options.params.auth;
|
|
103
|
+
delete options.params.auth;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
this._request(options, (err, res, body) => {
|
|
107
|
+
if (res && res.statusCode !== 200) {
|
|
108
|
+
err = new Error(`Invalid HTTP Status Code: ${res.statusCode}`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (err) {
|
|
112
|
+
return callback(err);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (typeof body === 'string') {
|
|
116
|
+
try {
|
|
117
|
+
body = JSON.parse(body);
|
|
118
|
+
} catch (e) {
|
|
119
|
+
return callback(e);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
callback(null, body);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Returns a log stream for this transport. Options object is optional.
|
|
129
|
+
* @param {Object} options - Stream options for this instance.
|
|
130
|
+
* @returns {Stream} - TODO: add return description
|
|
131
|
+
*/
|
|
132
|
+
stream(options = {}) {
|
|
133
|
+
const stream = new Stream();
|
|
134
|
+
options = {
|
|
135
|
+
method: 'stream',
|
|
136
|
+
params: options
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
if (options.params.path) {
|
|
140
|
+
options.path = options.params.path;
|
|
141
|
+
delete options.params.path;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (options.params.auth) {
|
|
145
|
+
options.auth = options.params.auth;
|
|
146
|
+
delete options.params.auth;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
let buff = '';
|
|
150
|
+
const req = this._request(options);
|
|
151
|
+
|
|
152
|
+
stream.destroy = () => req.destroy();
|
|
153
|
+
req.on('data', data => {
|
|
154
|
+
data = (buff + data).split(/\n+/);
|
|
155
|
+
const l = data.length - 1;
|
|
156
|
+
|
|
157
|
+
let i = 0;
|
|
158
|
+
for (; i < l; i++) {
|
|
159
|
+
try {
|
|
160
|
+
stream.emit('log', JSON.parse(data[i]));
|
|
161
|
+
} catch (e) {
|
|
162
|
+
stream.emit('error', e);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
buff = data[l];
|
|
167
|
+
});
|
|
168
|
+
req.on('error', err => stream.emit('error', err));
|
|
169
|
+
|
|
170
|
+
return stream;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Make a request to a winstond server or any http server which can
|
|
175
|
+
* handle json-rpc.
|
|
176
|
+
* @param {function} options - Options to sent the request.
|
|
177
|
+
* @param {function} callback - Continuation to respond to when complete.
|
|
178
|
+
*/
|
|
179
|
+
_request(options, callback) {
|
|
180
|
+
options = options || {};
|
|
181
|
+
|
|
182
|
+
const auth = options.auth || this.auth;
|
|
183
|
+
const path = options.path || this.path || '';
|
|
184
|
+
|
|
185
|
+
delete options.auth;
|
|
186
|
+
delete options.path;
|
|
187
|
+
|
|
188
|
+
if (this.batch) {
|
|
189
|
+
this._doBatch(options, callback, auth, path);
|
|
190
|
+
} else {
|
|
191
|
+
this._doRequest(options, callback, auth, path);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Send or memorize the options according to batch configuration
|
|
197
|
+
* @param {function} options - Options to sent the request.
|
|
198
|
+
* @param {function} callback - Continuation to respond to when complete.
|
|
199
|
+
* @param {Object?} auth - authentication options
|
|
200
|
+
* @param {string} path - request path
|
|
201
|
+
*/
|
|
202
|
+
_doBatch(options, callback, auth, path) {
|
|
203
|
+
this.batchOptions.push(options);
|
|
204
|
+
if (this.batchOptions.length === 1) {
|
|
205
|
+
// First message stored, it's time to start the timeout!
|
|
206
|
+
const me = this;
|
|
207
|
+
this.batchCallback = callback;
|
|
208
|
+
this.batchTimeoutID = setTimeout(function () {
|
|
209
|
+
// timeout is reached, send all messages to endpoint
|
|
210
|
+
me.batchTimeoutID = -1;
|
|
211
|
+
me._doBatchRequest(me.batchCallback, auth, path);
|
|
212
|
+
}, this.batchInterval);
|
|
213
|
+
}
|
|
214
|
+
if (this.batchOptions.length === this.batchCount) {
|
|
215
|
+
// max batch count is reached, send all messages to endpoint
|
|
216
|
+
this._doBatchRequest(this.batchCallback, auth, path);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Initiate a request with the memorized batch options, stop the batch timeout
|
|
222
|
+
* @param {function} callback - Continuation to respond to when complete.
|
|
223
|
+
* @param {Object?} auth - authentication options
|
|
224
|
+
* @param {string} path - request path
|
|
225
|
+
*/
|
|
226
|
+
_doBatchRequest(callback, auth, path) {
|
|
227
|
+
if (this.batchTimeoutID > 0) {
|
|
228
|
+
clearTimeout(this.batchTimeoutID);
|
|
229
|
+
this.batchTimeoutID = -1;
|
|
230
|
+
}
|
|
231
|
+
const batchOptionsCopy = this.batchOptions.slice();
|
|
232
|
+
this.batchOptions = [];
|
|
233
|
+
this._doRequest(batchOptionsCopy, callback, auth, path);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Make a request to a winstond server or any http server which can
|
|
238
|
+
* handle json-rpc.
|
|
239
|
+
* @param {function} options - Options to sent the request.
|
|
240
|
+
* @param {function} callback - Continuation to respond to when complete.
|
|
241
|
+
* @param {Object?} auth - authentication options
|
|
242
|
+
* @param {string} path - request path
|
|
243
|
+
*/
|
|
244
|
+
_doRequest(options, callback, auth, path) {
|
|
245
|
+
// Prepare options for outgoing HTTP request
|
|
246
|
+
const headers = Object.assign({}, this.headers);
|
|
247
|
+
if (auth && auth.bearer) {
|
|
248
|
+
headers.Authorization = `Bearer ${auth.bearer}`;
|
|
249
|
+
}
|
|
250
|
+
const req = (this.ssl ? https : http).request({
|
|
251
|
+
...this.options,
|
|
252
|
+
method: 'POST',
|
|
253
|
+
host: this.host,
|
|
254
|
+
port: this.port,
|
|
255
|
+
path: `/${path.replace(/^\//, '')}`,
|
|
256
|
+
headers: headers,
|
|
257
|
+
auth: (auth && auth.username && auth.password) ? (`${auth.username}:${auth.password}`) : '',
|
|
258
|
+
agent: this.agent
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
req.on('error', callback);
|
|
262
|
+
req.on('response', res => (
|
|
263
|
+
res.on('end', () => callback(null, res)).resume()
|
|
264
|
+
));
|
|
265
|
+
req.end(Buffer.from(jsonStringify(options), 'utf8'));
|
|
266
|
+
}
|
|
267
|
+
};
|