varsnap 1.11.2 → 1.11.3

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/dist/browser.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! Varsnap.js v1.11.2 */
1
+ /*! Varsnap.js v1.11.3 */
2
2
  (function webpackUniversalModuleDefinition(root, factory) {
3
3
  if(typeof exports === 'object' && typeof module === 'object')
4
4
  module.exports = factory();
@@ -13,536 +13,108 @@ return /******/ (() => { // webpackBootstrap
13
13
  /******/ "use strict";
14
14
  /******/ var __webpack_modules__ = ({
15
15
 
16
- /***/ "./varsnap/core.ts":
17
- /*!*************************!*\
18
- !*** ./varsnap/core.ts ***!
19
- \*************************/
20
- /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
16
+ /***/ "./node_modules/axios/lib/adapters/adapters.js":
17
+ /*!*****************************************************!*\
18
+ !*** ./node_modules/axios/lib/adapters/adapters.js ***!
19
+ \*****************************************************/
20
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
21
21
 
22
22
  __webpack_require__.r(__webpack_exports__);
23
23
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
24
- /* harmony export */ Consumer: () => (/* binding */ Consumer),
25
- /* harmony export */ Producer: () => (/* binding */ Producer),
26
- /* harmony export */ Util: () => (/* binding */ Util),
27
- /* harmony export */ clientName: () => (/* binding */ clientName),
28
- /* harmony export */ runTests: () => (/* binding */ runTests),
29
- /* harmony export */ varsnap: () => (/* binding */ varsnap),
30
- /* harmony export */ version: () => (/* binding */ version)
24
+ /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
31
25
  /* harmony export */ });
32
- /* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! axios */ "./node_modules/axios/lib/axios.js");
26
+ /* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../utils.js */ "./node_modules/axios/lib/utils.js");
27
+ /* harmony import */ var _http_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./http.js */ "./node_modules/axios/lib/helpers/null.js");
28
+ /* harmony import */ var _xhr_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./xhr.js */ "./node_modules/axios/lib/adapters/xhr.js");
29
+ /* harmony import */ var _fetch_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./fetch.js */ "./node_modules/axios/lib/adapters/fetch.js");
30
+ /* harmony import */ var _core_AxiosError_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../core/AxiosError.js */ "./node_modules/axios/lib/core/AxiosError.js");
33
31
 
34
- const produceURL = 'https://www.varsnap.com/api/snap/produce/';
35
- const consumeURL = 'https://www.varsnap.com/api/snap/consume/';
36
- const produceTrialURL = 'https://www.varsnap.com/api/trial/produce/';
37
- const trialGroupURL = 'https://www.varsnap.com/api/trial_group/';
38
- const version = '1.11.2';
39
- const clientName = 'javascript.' + version;
40
- const defaultConfig = {
41
- varsnap: true,
42
- env: 'development',
43
- branch: '',
44
- producerToken: '',
45
- consumerToken: '',
46
- logger: console,
47
- };
48
- let Producers = [];
49
- let Consumers = [];
50
- class Util {
51
- static getConfig(config, configKey) {
52
- if (!config) {
53
- return '';
54
- }
55
- let val = config[configKey];
56
- if (!val) {
57
- return '';
58
- }
59
- val = val.toString().toLowerCase();
60
- return val;
61
- }
62
- static setConfig(config, configKey, configValue) {
63
- if (configKey === 'varsnap') {
64
- if (typeof configValue === 'string') {
65
- configValue = configValue === 'true';
66
- }
67
- config[configKey] = configValue;
68
- }
69
- if (configKey === 'env' || configKey === 'producerToken' || configKey === 'consumerToken' || configKey === 'branch') {
70
- config[configKey] = configValue;
71
- }
72
- if (configKey === 'logger') {
73
- config[configKey] = configValue;
74
- }
75
- return config;
76
- }
77
- static getSignature(targetFunc, funcName) {
78
- let signature = '';
79
- if (funcName !== '' && funcName !== undefined) {
80
- signature = funcName;
81
- }
82
- else {
83
- // Remove any implementation code from signature
84
- signature = targetFunc.toString().split('{')[0];
85
- // Trim preceding and trailing whitespace
86
- signature = signature.replace(/^\s+|\s+$/g, '');
87
- // Trim whitespace between comma separated arguments
88
- signature = signature.replace(/,\s+/g, ',');
89
- }
90
- return 'javascript.' + version + '.' + signature;
91
- }
92
- static ajax(url, requestData) {
93
- const requestParams = new URLSearchParams(requestData);
94
- const data = requestParams.toString();
95
- const options = {
96
- method: 'POST',
97
- url: url,
98
- headers: {
99
- 'Content-Type': 'application/x-www-form-urlencoded',
100
- },
101
- data: data,
102
- responseType: 'json',
103
- };
104
- if (Util.isNode() && options.headers) {
105
- options.headers['User-Agent'] = 'varsnap.js';
106
- }
107
- const ajaxPromise = (0,axios__WEBPACK_IMPORTED_MODULE_0__["default"])(options).then((response) => {
108
- return response.data;
109
- }).catch((error) => {
110
- return error;
111
- });
112
- return ajaxPromise;
113
- }
114
- static debug(config, data) {
115
- if (config.logger) {
116
- config.logger.debug(data);
117
- }
118
- }
119
- static log(config, data) {
120
- if (config.logger) {
121
- config.logger.log(data);
122
- }
123
- }
124
- static error(config, data) {
125
- if (config.logger) {
126
- config.logger.error(data);
127
- }
128
- }
129
- static resetProducers() {
130
- Producers = [];
131
- }
132
- static resetConsumers() {
133
- Consumers = [];
134
- }
135
- static getProducers() {
136
- return Producers;
137
- }
138
- static getConsumers() {
139
- return Consumers;
140
- }
141
- static limitString(x) {
142
- const limitedString = String(x);
143
- const limit = 30;
144
- const ellipsis = '...';
145
- if (limitedString.length <= limit) {
146
- return limitedString;
147
- }
148
- return limitedString.substring(0, 30 - ellipsis.length) + ellipsis;
149
- }
150
- static isNode() {
151
- if (typeof process !== 'object') {
152
- return false;
153
- }
154
- if (typeof window !== 'undefined') {
155
- return false;
156
- }
157
- return true;
158
- }
32
+
33
+
34
+
35
+
36
+
37
+ const knownAdapters = {
38
+ http: _http_js__WEBPACK_IMPORTED_MODULE_0__["default"],
39
+ xhr: _xhr_js__WEBPACK_IMPORTED_MODULE_1__["default"],
40
+ fetch: _fetch_js__WEBPACK_IMPORTED_MODULE_2__["default"]
159
41
  }
160
- class Producer {
161
- constructor(targetFunc, signature, config) {
162
- this.targetFunc = targetFunc;
163
- this.signature = signature;
164
- this.config = config;
42
+
43
+ _utils_js__WEBPACK_IMPORTED_MODULE_3__["default"].forEach(knownAdapters, (fn, value) => {
44
+ if (fn) {
45
+ try {
46
+ Object.defineProperty(fn, 'name', {value});
47
+ } catch (e) {
48
+ // eslint-disable-next-line no-empty
165
49
  }
166
- isEnabled() {
167
- if (!this.config.varsnap) {
168
- return false;
169
- }
170
- if (Util.getConfig(this.config, 'env') !== 'production') {
171
- return false;
172
- }
173
- if (!Util.getConfig(this.config, 'producerToken')) {
174
- return false;
50
+ Object.defineProperty(fn, 'adapterName', {value});
51
+ }
52
+ });
53
+
54
+ const renderReason = (reason) => `- ${reason}`;
55
+
56
+ const isResolvedHandle = (adapter) => _utils_js__WEBPACK_IMPORTED_MODULE_3__["default"].isFunction(adapter) || adapter === null || adapter === false;
57
+
58
+ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
59
+ getAdapter: (adapters) => {
60
+ adapters = _utils_js__WEBPACK_IMPORTED_MODULE_3__["default"].isArray(adapters) ? adapters : [adapters];
61
+
62
+ const {length} = adapters;
63
+ let nameOrAdapter;
64
+ let adapter;
65
+
66
+ const rejectedReasons = {};
67
+
68
+ for (let i = 0; i < length; i++) {
69
+ nameOrAdapter = adapters[i];
70
+ let id;
71
+
72
+ adapter = nameOrAdapter;
73
+
74
+ if (!isResolvedHandle(nameOrAdapter)) {
75
+ adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
76
+
77
+ if (adapter === undefined) {
78
+ throw new _core_AxiosError_js__WEBPACK_IMPORTED_MODULE_4__["default"](`Unknown adapter '${id}'`);
175
79
  }
176
- return true;
177
- }
178
- static serialize(data) {
179
- return JSON.stringify(data);
80
+ }
81
+
82
+ if (adapter) {
83
+ break;
84
+ }
85
+
86
+ rejectedReasons[id || '#' + i] = adapter;
180
87
  }
181
- static serialize_formatted(data) {
182
- return JSON.stringify(data, null, 2);
88
+
89
+ if (!adapter) {
90
+
91
+ const reasons = Object.entries(rejectedReasons)
92
+ .map(([id, state]) => `adapter ${id} ` +
93
+ (state === false ? 'is not supported by the environment' : 'is not available in the build')
94
+ );
95
+
96
+ let s = length ?
97
+ (reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
98
+ 'as no adapter specified';
99
+
100
+ throw new _core_AxiosError_js__WEBPACK_IMPORTED_MODULE_4__["default"](
101
+ `There is no suitable adapter to dispatch the request ` + s,
102
+ 'ERR_NOT_SUPPORT'
103
+ );
183
104
  }
184
- produce(args, output) {
185
- if (!this.isEnabled()) {
186
- const errorPromise = new Promise((resolve) => {
187
- return resolve(false);
188
- });
189
- return errorPromise;
190
- }
191
- Util.debug(this.config, 'Sending call to Varsnap');
192
- return Promise.resolve(output).then((outputValue) => {
193
- const data = {
194
- 'producer_token': Util.getConfig(this.config, 'producerToken'),
195
- 'signature': this.signature,
196
- 'inputs': Producer.serialize(args),
197
- 'prod_outputs': Producer.serialize(outputValue),
198
- };
199
- return Util.ajax(produceURL, data).then(() => {
200
- return true;
201
- }).catch((err) => {
202
- if (err.response) {
203
- if (err.response.status === 429) {
204
- Util.error(this.config, 'Cannot produce to Varsnap; Signature at rate limit');
205
- return true;
206
- }
207
- if (err.response.status === 404) {
208
- Util.error(this.config, 'Cannot produce to Varsnap; check your producer token');
209
- }
210
- else {
211
- Util.error(this.config, err.response.statusText);
212
- }
213
- }
214
- return false;
215
- });
216
- });
217
- }
218
- }
219
- class Consumer {
220
- constructor(targetFunc, signature, config) {
221
- this.targetFunc = targetFunc;
222
- this.signature = signature;
223
- this.config = config;
224
- }
225
- isEnabled() {
226
- if (!this.config.varsnap) {
227
- return false;
228
- }
229
- if (Util.getConfig(this.config, 'env') !== 'development') {
230
- return false;
231
- }
232
- if (!Util.getConfig(this.config, 'consumerToken')) {
233
- return false;
234
- }
235
- return true;
236
- }
237
- static deserialize(data) {
238
- if (data === '') {
239
- return undefined;
240
- }
241
- return JSON.parse(data);
242
- }
243
- consume(trialGroup) {
244
- if (!this.isEnabled()) {
245
- const errorPromise = new Promise((resolve) => {
246
- Util.error(this.config, 'Varsnap not enabled for testing');
247
- return resolve(false);
248
- });
249
- return errorPromise;
250
- }
251
- const data = {
252
- 'consumer_token': Util.getConfig(this.config, 'consumerToken'),
253
- 'signature': this.signature,
254
- };
255
- const ajax = Util.ajax(consumeURL, data);
256
- const consume = ajax.then((rawResponse) => {
257
- const response = rawResponse;
258
- if (!response || response.status !== 'ok') {
259
- const errorPromise = new Promise((resolve) => {
260
- Util.error(this.config, 'Received error from Varsnap: ' + response.status);
261
- return resolve(false);
262
- });
263
- return [errorPromise];
264
- }
265
- if (response.results.length === 0) {
266
- Util.log(this.config, 'No snaps found for signature: ' + data.signature);
267
- }
268
- const trialPromises = [];
269
- for (const snap of response.results) {
270
- const inputs = Consumer.deserialize(snap['inputs']);
271
- const prodOutputs = Consumer.deserialize(snap['prod_outputs']);
272
- let localOutputs;
273
- try {
274
- localOutputs = this.targetFunc(...inputs);
275
- }
276
- catch (err) {
277
- localOutputs = err;
278
- }
279
- const trialPromise = Promise.resolve(localOutputs).then((localOutputValue) => {
280
- const prodOutputsSerialized = Producer.serialize(prodOutputs);
281
- const localOutputsSerialized = Producer.serialize(localOutputValue);
282
- const matches = prodOutputsSerialized === localOutputsSerialized;
283
- this.reportCentral(trialGroup, snap, prodOutputs, localOutputValue, matches).then((trialURL) => {
284
- this.reportLog(snap['id'], inputs, prodOutputs, localOutputValue, matches, trialURL);
285
- });
286
- return matches;
287
- });
288
- trialPromises.push(trialPromise);
289
- }
290
- return trialPromises;
291
- }).then((trialPromises) => {
292
- return Promise.all(trialPromises).then((results) => {
293
- const allMatches = results.every((result) => result);
294
- return allMatches;
295
- });
296
- }).catch((error) => {
297
- Util.error(this.config, 'Cannot contact Varsnap: ' + error);
298
- return false;
299
- });
300
- return consume;
301
- }
302
- reportCentral(trialGroup, snap, prodOutputs, localOutputs, matches) {
303
- const data = {
304
- 'trial_group_id': trialGroup.trial_group_id,
305
- 'consumer_token': Util.getConfig(this.config, 'consumerToken'),
306
- 'snap_id': snap.id,
307
- 'test_outputs': Producer.serialize(localOutputs),
308
- 'matches': matches.toString(),
309
- 'snap_outputs_formatted': Producer.serialize_formatted(prodOutputs),
310
- 'test_outputs_formatted': Producer.serialize_formatted(localOutputs),
311
- };
312
- const ajax = Util.ajax(produceTrialURL, data);
313
- const report = ajax.then((rawResponse) => {
314
- const response = rawResponse;
315
- if (!response || response.status !== 'ok') {
316
- return false;
317
- }
318
- const trialURL = response['trial_url'];
319
- return trialURL;
320
- }).catch((error) => {
321
- Util.error(this.config, 'Cannot upload test results to Varsnap: ' + error);
322
- return false;
323
- });
324
- return report;
325
- }
326
- reportLog(snapID, inputs, prodOutputs, localOutputs, matches, trialURL) {
327
- if (matches) {
328
- return;
329
- }
330
- Util.log(this.config, '');
331
- Util.log(this.config, 'Testing with Varsnap uuid: ' + snapID);
332
- Util.log(this.config, 'Signature: ' + this.signature);
333
- Util.log(this.config, 'Function input args: ' + Util.limitString(inputs));
334
- Util.log(this.config, 'Production function outputs: ' + Util.limitString(prodOutputs));
335
- Util.log(this.config, 'Your function outputs: ' + Util.limitString(localOutputs));
336
- Util.log(this.config, 'Matching outputs: ' + matches);
337
- let trialURLView = 'Cannot upload trial';
338
- if (trialURL) {
339
- trialURLView = String(trialURL);
340
- }
341
- Util.log(this.config, 'Trial URL: ' + trialURLView);
342
- }
343
- reportTrialGroup(trialGroup) {
344
- Util.log(this.config, 'Trial Group: ' + trialGroup.trial_group_url);
345
- }
346
- }
347
- function varsnap(func, funcName) {
348
- if (funcName === undefined) {
349
- funcName = '';
350
- }
351
- const signature = Util.getSignature(func, funcName);
352
- const producer = new Producer(func, signature, varsnap._config);
353
- const consumer = new Consumer(func, signature, varsnap._config);
354
- const wrapped = function (...args) {
355
- let result;
356
- try {
357
- result = func(...args);
358
- }
359
- catch (err) {
360
- producer.produce(args, err);
361
- throw (err);
362
- }
363
- producer.produce(args, result);
364
- return result;
365
- };
366
- wrapped.producer = producer;
367
- wrapped.consumer = consumer;
368
- wrapped.signature = signature;
369
- Producers.push(producer);
370
- Consumers.push(consumer);
371
- return wrapped;
372
- }
373
- varsnap._config = defaultConfig;
374
- varsnap.updateConfig = function updateConfig(newConfig) {
375
- let config = varsnap._config;
376
- for (const key of Object.keys(varsnap._config)) {
377
- if (Object.prototype.hasOwnProperty.call(newConfig, key)) {
378
- config = Util.setConfig(config, key, newConfig[key]);
379
- }
380
- }
381
- varsnap._config = config;
382
- };
383
- varsnap.reset = function reset() {
384
- Util.resetConsumers();
385
- Util.resetProducers();
386
- };
387
- varsnap.version = version;
388
- function getTrialGroup(consumerConfig) {
389
- const data = {
390
- 'branch': Util.getConfig(consumerConfig, 'branch'),
391
- 'consumer_token': Util.getConfig(consumerConfig, 'consumerToken'),
392
- 'client': clientName,
393
- };
394
- const raw = data;
395
- const ajax = Util.ajax(trialGroupURL, raw);
396
- const trialGroup = ajax.then((rawResponse) => {
397
- const response = rawResponse;
398
- return response;
399
- }).catch((error) => {
400
- let errorMessage = '';
401
- if (error && error.response && error.response.data) {
402
- const response = error.response.data;
403
- errorMessage = response.error;
404
- }
405
- else {
406
- errorMessage = error.toString();
407
- }
408
- Util.error(consumerConfig, 'Cannot generate a new Trial Group: ' + errorMessage);
409
- return {
410
- status: 'not ok',
411
- project_id: '',
412
- trial_group_id: '',
413
- trial_group_url: '',
414
- };
415
- });
416
- return trialGroup;
417
- }
418
- function runTests() {
419
- const consumers = Util.getConsumers();
420
- if (consumers.length === 0) {
421
- return Promise.resolve(true);
422
- }
423
- const consumerConfig = consumers[0].config;
424
- return getTrialGroup(consumerConfig).then((trialGroup) => {
425
- const testPromises = [];
426
- for (const consumer of consumers) {
427
- const testPromise = consumer.consume(trialGroup);
428
- testPromises.push(testPromise);
429
- }
430
- if (consumers.length > 0) {
431
- consumers[0].reportTrialGroup(trialGroup);
432
- }
433
- return Promise.all(testPromises);
434
- }).then((results) => {
435
- const allPass = results.every((result) => result);
436
- return allPass;
437
- });
438
- }
439
- varsnap.runTests = runTests;
105
+
106
+ return adapter;
107
+ },
108
+ adapters: knownAdapters
109
+ });
440
110
 
441
111
 
442
112
  /***/ }),
443
113
 
444
- /***/ "./node_modules/axios/lib/adapters/adapters.js":
445
- /*!*****************************************************!*\
446
- !*** ./node_modules/axios/lib/adapters/adapters.js ***!
447
- \*****************************************************/
448
- /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
449
-
450
- __webpack_require__.r(__webpack_exports__);
451
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
452
- /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
453
- /* harmony export */ });
454
- /* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../utils.js */ "./node_modules/axios/lib/utils.js");
455
- /* harmony import */ var _http_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./http.js */ "./node_modules/axios/lib/helpers/null.js");
456
- /* harmony import */ var _xhr_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./xhr.js */ "./node_modules/axios/lib/adapters/xhr.js");
457
- /* harmony import */ var _fetch_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./fetch.js */ "./node_modules/axios/lib/adapters/fetch.js");
458
- /* harmony import */ var _core_AxiosError_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../core/AxiosError.js */ "./node_modules/axios/lib/core/AxiosError.js");
459
-
460
-
461
-
462
-
463
-
464
-
465
- const knownAdapters = {
466
- http: _http_js__WEBPACK_IMPORTED_MODULE_0__["default"],
467
- xhr: _xhr_js__WEBPACK_IMPORTED_MODULE_1__["default"],
468
- fetch: _fetch_js__WEBPACK_IMPORTED_MODULE_2__["default"]
469
- }
470
-
471
- _utils_js__WEBPACK_IMPORTED_MODULE_3__["default"].forEach(knownAdapters, (fn, value) => {
472
- if (fn) {
473
- try {
474
- Object.defineProperty(fn, 'name', {value});
475
- } catch (e) {
476
- // eslint-disable-next-line no-empty
477
- }
478
- Object.defineProperty(fn, 'adapterName', {value});
479
- }
480
- });
481
-
482
- const renderReason = (reason) => `- ${reason}`;
483
-
484
- const isResolvedHandle = (adapter) => _utils_js__WEBPACK_IMPORTED_MODULE_3__["default"].isFunction(adapter) || adapter === null || adapter === false;
485
-
486
- /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
487
- getAdapter: (adapters) => {
488
- adapters = _utils_js__WEBPACK_IMPORTED_MODULE_3__["default"].isArray(adapters) ? adapters : [adapters];
489
-
490
- const {length} = adapters;
491
- let nameOrAdapter;
492
- let adapter;
493
-
494
- const rejectedReasons = {};
495
-
496
- for (let i = 0; i < length; i++) {
497
- nameOrAdapter = adapters[i];
498
- let id;
499
-
500
- adapter = nameOrAdapter;
501
-
502
- if (!isResolvedHandle(nameOrAdapter)) {
503
- adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
504
-
505
- if (adapter === undefined) {
506
- throw new _core_AxiosError_js__WEBPACK_IMPORTED_MODULE_4__["default"](`Unknown adapter '${id}'`);
507
- }
508
- }
509
-
510
- if (adapter) {
511
- break;
512
- }
513
-
514
- rejectedReasons[id || '#' + i] = adapter;
515
- }
516
-
517
- if (!adapter) {
518
-
519
- const reasons = Object.entries(rejectedReasons)
520
- .map(([id, state]) => `adapter ${id} ` +
521
- (state === false ? 'is not supported by the environment' : 'is not available in the build')
522
- );
523
-
524
- let s = length ?
525
- (reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
526
- 'as no adapter specified';
527
-
528
- throw new _core_AxiosError_js__WEBPACK_IMPORTED_MODULE_4__["default"](
529
- `There is no suitable adapter to dispatch the request ` + s,
530
- 'ERR_NOT_SUPPORT'
531
- );
532
- }
533
-
534
- return adapter;
535
- },
536
- adapters: knownAdapters
537
- });
538
-
539
-
540
- /***/ }),
541
-
542
- /***/ "./node_modules/axios/lib/adapters/fetch.js":
543
- /*!**************************************************!*\
544
- !*** ./node_modules/axios/lib/adapters/fetch.js ***!
545
- \**************************************************/
114
+ /***/ "./node_modules/axios/lib/adapters/fetch.js":
115
+ /*!**************************************************!*\
116
+ !*** ./node_modules/axios/lib/adapters/fetch.js ***!
117
+ \**************************************************/
546
118
  /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
547
119
 
548
120
  __webpack_require__.r(__webpack_exports__);
@@ -773,7 +345,7 @@ const resolveBodyLength = async (headers, body) => {
773
345
  } catch (err) {
774
346
  unsubscribe && unsubscribe();
775
347
 
776
- if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
348
+ if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
777
349
  throw Object.assign(
778
350
  new _core_AxiosError_js__WEBPACK_IMPORTED_MODULE_2__["default"]('Network Error', _core_AxiosError_js__WEBPACK_IMPORTED_MODULE_2__["default"].ERR_NETWORK, config, request),
779
351
  {
@@ -1382,7 +954,7 @@ const validators = _helpers_validator_js__WEBPACK_IMPORTED_MODULE_0__["default"]
1382
954
  */
1383
955
  class Axios {
1384
956
  constructor(instanceConfig) {
1385
- this.defaults = instanceConfig;
957
+ this.defaults = instanceConfig || {};
1386
958
  this.interceptors = {
1387
959
  request: new _InterceptorManager_js__WEBPACK_IMPORTED_MODULE_1__["default"](),
1388
960
  response: new _InterceptorManager_js__WEBPACK_IMPORTED_MODULE_1__["default"]()
@@ -1459,6 +1031,15 @@ class Axios {
1459
1031
  }
1460
1032
  }
1461
1033
 
1034
+ // Set config.allowAbsoluteUrls
1035
+ if (config.allowAbsoluteUrls !== undefined) {
1036
+ // do nothing
1037
+ } else if (this.defaults.allowAbsoluteUrls !== undefined) {
1038
+ config.allowAbsoluteUrls = this.defaults.allowAbsoluteUrls;
1039
+ } else {
1040
+ config.allowAbsoluteUrls = true;
1041
+ }
1042
+
1462
1043
  _helpers_validator_js__WEBPACK_IMPORTED_MODULE_0__["default"].assertOptions(config, {
1463
1044
  baseUrl: validators.spelling('baseURL'),
1464
1045
  withXsrfToken: validators.spelling('withXSRFToken')
@@ -1554,7 +1135,7 @@ class Axios {
1554
1135
 
1555
1136
  getUri(config) {
1556
1137
  config = (0,_mergeConfig_js__WEBPACK_IMPORTED_MODULE_2__["default"])(this.defaults, config);
1557
- const fullPath = (0,_buildFullPath_js__WEBPACK_IMPORTED_MODULE_6__["default"])(config.baseURL, config.url);
1138
+ const fullPath = (0,_buildFullPath_js__WEBPACK_IMPORTED_MODULE_6__["default"])(config.baseURL, config.url, config.allowAbsoluteUrls);
1558
1139
  return (0,_helpers_buildURL_js__WEBPACK_IMPORTED_MODULE_7__["default"])(fullPath, config.params, config.paramsSerializer);
1559
1140
  }
1560
1141
  }
@@ -1829,10 +1410,18 @@ class AxiosHeaders {
1829
1410
  setHeaders(header, valueOrRewrite)
1830
1411
  } else if(_utils_js__WEBPACK_IMPORTED_MODULE_0__["default"].isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
1831
1412
  setHeaders((0,_helpers_parseHeaders_js__WEBPACK_IMPORTED_MODULE_1__["default"])(header), valueOrRewrite);
1832
- } else if (_utils_js__WEBPACK_IMPORTED_MODULE_0__["default"].isHeaders(header)) {
1833
- for (const [key, value] of header.entries()) {
1834
- setHeader(value, key, rewrite);
1413
+ } else if (_utils_js__WEBPACK_IMPORTED_MODULE_0__["default"].isObject(header) && _utils_js__WEBPACK_IMPORTED_MODULE_0__["default"].isIterable(header)) {
1414
+ let obj = {}, dest, key;
1415
+ for (const entry of header) {
1416
+ if (!_utils_js__WEBPACK_IMPORTED_MODULE_0__["default"].isArray(entry)) {
1417
+ throw TypeError('Object iterator must return a key-value pair');
1418
+ }
1419
+
1420
+ obj[key = entry[0]] = (dest = obj[key]) ?
1421
+ (_utils_js__WEBPACK_IMPORTED_MODULE_0__["default"].isArray(dest) ? [...dest, entry[1]] : [dest, entry[1]]) : entry[1];
1835
1422
  }
1423
+
1424
+ setHeaders(obj, valueOrRewrite)
1836
1425
  } else {
1837
1426
  header != null && setHeader(valueOrRewrite, header, rewrite);
1838
1427
  }
@@ -1974,6 +1563,10 @@ class AxiosHeaders {
1974
1563
  return Object.entries(this.toJSON()).map(([header, value]) => header + ': ' + value).join('\n');
1975
1564
  }
1976
1565
 
1566
+ getSetCookie() {
1567
+ return this.get("set-cookie") || [];
1568
+ }
1569
+
1977
1570
  get [Symbol.toStringTag]() {
1978
1571
  return 'AxiosHeaders';
1979
1572
  }
@@ -2146,8 +1739,9 @@ __webpack_require__.r(__webpack_exports__);
2146
1739
  *
2147
1740
  * @returns {string} The combined full path
2148
1741
  */
2149
- function buildFullPath(baseURL, requestedURL) {
2150
- if (baseURL && !(0,_helpers_isAbsoluteURL_js__WEBPACK_IMPORTED_MODULE_0__["default"])(requestedURL)) {
1742
+ function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
1743
+ let isRelativeUrl = !(0,_helpers_isAbsoluteURL_js__WEBPACK_IMPORTED_MODULE_0__["default"])(requestedURL);
1744
+ if (baseURL && (isRelativeUrl || allowAbsoluteUrls == false)) {
2151
1745
  return (0,_helpers_combineURLs_js__WEBPACK_IMPORTED_MODULE_1__["default"])(baseURL, requestedURL);
2152
1746
  }
2153
1747
  return requestedURL;
@@ -2679,7 +2273,7 @@ __webpack_require__.r(__webpack_exports__);
2679
2273
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2680
2274
  /* harmony export */ VERSION: () => (/* binding */ VERSION)
2681
2275
  /* harmony export */ });
2682
- const VERSION = "1.7.9";
2276
+ const VERSION = "1.9.0";
2683
2277
 
2684
2278
  /***/ }),
2685
2279
 
@@ -3499,7 +3093,7 @@ __webpack_require__.r(__webpack_exports__);
3499
3093
 
3500
3094
  newConfig.headers = headers = _core_AxiosHeaders_js__WEBPACK_IMPORTED_MODULE_1__["default"].from(headers);
3501
3095
 
3502
- newConfig.url = (0,_buildURL_js__WEBPACK_IMPORTED_MODULE_2__["default"])((0,_core_buildFullPath_js__WEBPACK_IMPORTED_MODULE_3__["default"])(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
3096
+ newConfig.url = (0,_buildURL_js__WEBPACK_IMPORTED_MODULE_2__["default"])((0,_core_buildFullPath_js__WEBPACK_IMPORTED_MODULE_3__["default"])(newConfig.baseURL, newConfig.url, newConfig.allowAbsoluteUrls), config.params, config.paramsSerializer);
3503
3097
 
3504
3098
  // HTTP basic authentication
3505
3099
  if (auth) {
@@ -4390,6 +3984,7 @@ __webpack_require__.r(__webpack_exports__);
4390
3984
 
4391
3985
  const {toString} = Object.prototype;
4392
3986
  const {getPrototypeOf} = Object;
3987
+ const {iterator, toStringTag} = Symbol;
4393
3988
 
4394
3989
  const kindOf = (cache => thing => {
4395
3990
  const str = toString.call(thing);
@@ -4516,7 +4111,7 @@ const isPlainObject = (val) => {
4516
4111
  }
4517
4112
 
4518
4113
  const prototype = getPrototypeOf(val);
4519
- return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in val) && !(Symbol.iterator in val);
4114
+ return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(toStringTag in val) && !(iterator in val);
4520
4115
  }
4521
4116
 
4522
4117
  /**
@@ -4867,13 +4462,13 @@ const isTypedArray = (TypedArray => {
4867
4462
  * @returns {void}
4868
4463
  */
4869
4464
  const forEachEntry = (obj, fn) => {
4870
- const generator = obj && obj[Symbol.iterator];
4465
+ const generator = obj && obj[iterator];
4871
4466
 
4872
- const iterator = generator.call(obj);
4467
+ const _iterator = generator.call(obj);
4873
4468
 
4874
4469
  let result;
4875
4470
 
4876
- while ((result = iterator.next()) && !result.done) {
4471
+ while ((result = _iterator.next()) && !result.done) {
4877
4472
  const pair = result.value;
4878
4473
  fn.call(obj, pair[0], pair[1]);
4879
4474
  }
@@ -4986,26 +4581,6 @@ const toFiniteNumber = (value, defaultValue) => {
4986
4581
  return value != null && Number.isFinite(value = +value) ? value : defaultValue;
4987
4582
  }
4988
4583
 
4989
- const ALPHA = 'abcdefghijklmnopqrstuvwxyz'
4990
-
4991
- const DIGIT = '0123456789';
4992
-
4993
- const ALPHABET = {
4994
- DIGIT,
4995
- ALPHA,
4996
- ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
4997
- }
4998
-
4999
- const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
5000
- let str = '';
5001
- const {length} = alphabet;
5002
- while (size--) {
5003
- str += alphabet[Math.random() * length|0]
5004
- }
5005
-
5006
- return str;
5007
- }
5008
-
5009
4584
  /**
5010
4585
  * If the thing is a FormData object, return true, otherwise return false.
5011
4586
  *
@@ -5014,7 +4589,7 @@ const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
5014
4589
  * @returns {boolean}
5015
4590
  */
5016
4591
  function isSpecCompliantForm(thing) {
5017
- return !!(thing && isFunction(thing.append) && thing[Symbol.toStringTag] === 'FormData' && thing[Symbol.iterator]);
4592
+ return !!(thing && isFunction(thing.append) && thing[toStringTag] === 'FormData' && thing[iterator]);
5018
4593
  }
5019
4594
 
5020
4595
  const toJSONObject = (obj) => {
@@ -5083,6 +4658,10 @@ const asap = typeof queueMicrotask !== 'undefined' ?
5083
4658
 
5084
4659
  // *********************
5085
4660
 
4661
+
4662
+ const isIterable = (thing) => thing != null && isFunction(thing[iterator]);
4663
+
4664
+
5086
4665
  /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
5087
4666
  isArray,
5088
4667
  isArrayBuffer,
@@ -5133,17 +4712,444 @@ const asap = typeof queueMicrotask !== 'undefined' ?
5133
4712
  findKey,
5134
4713
  global: _global,
5135
4714
  isContextDefined,
5136
- ALPHABET,
5137
- generateString,
5138
4715
  isSpecCompliantForm,
5139
4716
  toJSONObject,
5140
4717
  isAsyncFn,
5141
4718
  isThenable,
5142
4719
  setImmediate: _setImmediate,
5143
- asap
4720
+ asap,
4721
+ isIterable
5144
4722
  });
5145
4723
 
5146
4724
 
4725
+ /***/ }),
4726
+
4727
+ /***/ "./varsnap/core.ts":
4728
+ /*!*************************!*\
4729
+ !*** ./varsnap/core.ts ***!
4730
+ \*************************/
4731
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
4732
+
4733
+ __webpack_require__.r(__webpack_exports__);
4734
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
4735
+ /* harmony export */ Consumer: () => (/* binding */ Consumer),
4736
+ /* harmony export */ Producer: () => (/* binding */ Producer),
4737
+ /* harmony export */ Util: () => (/* binding */ Util),
4738
+ /* harmony export */ clientName: () => (/* binding */ clientName),
4739
+ /* harmony export */ runTests: () => (/* binding */ runTests),
4740
+ /* harmony export */ varsnap: () => (/* binding */ varsnap),
4741
+ /* harmony export */ version: () => (/* binding */ version)
4742
+ /* harmony export */ });
4743
+ /* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! axios */ "./node_modules/axios/lib/axios.js");
4744
+
4745
+ const produceURL = 'https://www.varsnap.com/api/snap/produce/';
4746
+ const consumeURL = 'https://www.varsnap.com/api/snap/consume/';
4747
+ const produceTrialURL = 'https://www.varsnap.com/api/trial/produce/';
4748
+ const trialGroupURL = 'https://www.varsnap.com/api/trial_group/';
4749
+ const version = '1.11.3';
4750
+ const clientName = 'javascript.' + version;
4751
+ const defaultConfig = {
4752
+ varsnap: true,
4753
+ env: 'development',
4754
+ branch: '',
4755
+ producerToken: '',
4756
+ consumerToken: '',
4757
+ logger: console,
4758
+ };
4759
+ let Producers = [];
4760
+ let Consumers = [];
4761
+ class Util {
4762
+ static getConfig(config, configKey) {
4763
+ if (!config) {
4764
+ return '';
4765
+ }
4766
+ let val = config[configKey];
4767
+ if (!val) {
4768
+ return '';
4769
+ }
4770
+ val = val.toString().toLowerCase();
4771
+ return val;
4772
+ }
4773
+ static setConfig(config, configKey, configValue) {
4774
+ if (configKey === 'varsnap') {
4775
+ if (typeof configValue === 'string') {
4776
+ configValue = configValue === 'true';
4777
+ }
4778
+ config[configKey] = configValue;
4779
+ }
4780
+ if (configKey === 'env' || configKey === 'producerToken' || configKey === 'consumerToken' || configKey === 'branch') {
4781
+ config[configKey] = configValue;
4782
+ }
4783
+ if (configKey === 'logger') {
4784
+ config[configKey] = configValue;
4785
+ }
4786
+ return config;
4787
+ }
4788
+ static getSignature(targetFunc, funcName) {
4789
+ let signature = '';
4790
+ if (funcName !== '' && funcName !== undefined) {
4791
+ signature = funcName;
4792
+ }
4793
+ else {
4794
+ // Remove any implementation code from signature
4795
+ signature = targetFunc.toString().split('{')[0];
4796
+ // Trim preceding and trailing whitespace
4797
+ signature = signature.replace(/^\s+|\s+$/g, '');
4798
+ // Trim whitespace between comma separated arguments
4799
+ signature = signature.replace(/,\s+/g, ',');
4800
+ }
4801
+ return 'javascript.' + version + '.' + signature;
4802
+ }
4803
+ static ajax(url, requestData) {
4804
+ const requestParams = new URLSearchParams(requestData);
4805
+ const data = requestParams.toString();
4806
+ const options = {
4807
+ method: 'POST',
4808
+ url: url,
4809
+ headers: {
4810
+ 'Content-Type': 'application/x-www-form-urlencoded',
4811
+ },
4812
+ data: data,
4813
+ responseType: 'json',
4814
+ };
4815
+ if (Util.isNode() && options.headers) {
4816
+ options.headers['User-Agent'] = 'varsnap.js';
4817
+ }
4818
+ const ajaxPromise = (0,axios__WEBPACK_IMPORTED_MODULE_0__["default"])(options).then((response) => {
4819
+ return response.data;
4820
+ }).catch((error) => {
4821
+ return error;
4822
+ });
4823
+ return ajaxPromise;
4824
+ }
4825
+ static debug(config, data) {
4826
+ if (config.logger) {
4827
+ config.logger.debug(data);
4828
+ }
4829
+ }
4830
+ static log(config, data) {
4831
+ if (config.logger) {
4832
+ config.logger.log(data);
4833
+ }
4834
+ }
4835
+ static error(config, data) {
4836
+ if (config.logger) {
4837
+ config.logger.error(data);
4838
+ }
4839
+ }
4840
+ static resetProducers() {
4841
+ Producers = [];
4842
+ }
4843
+ static resetConsumers() {
4844
+ Consumers = [];
4845
+ }
4846
+ static getProducers() {
4847
+ return Producers;
4848
+ }
4849
+ static getConsumers() {
4850
+ return Consumers;
4851
+ }
4852
+ static limitString(x) {
4853
+ const limitedString = String(x);
4854
+ const limit = 30;
4855
+ const ellipsis = '...';
4856
+ if (limitedString.length <= limit) {
4857
+ return limitedString;
4858
+ }
4859
+ return limitedString.substring(0, 30 - ellipsis.length) + ellipsis;
4860
+ }
4861
+ static isNode() {
4862
+ if (typeof process !== 'object') {
4863
+ return false;
4864
+ }
4865
+ if (typeof window !== 'undefined') {
4866
+ return false;
4867
+ }
4868
+ return true;
4869
+ }
4870
+ }
4871
+ class Producer {
4872
+ constructor(targetFunc, signature, config) {
4873
+ this.targetFunc = targetFunc;
4874
+ this.signature = signature;
4875
+ this.config = config;
4876
+ }
4877
+ isEnabled() {
4878
+ if (!this.config.varsnap) {
4879
+ return false;
4880
+ }
4881
+ if (Util.getConfig(this.config, 'env') !== 'production') {
4882
+ return false;
4883
+ }
4884
+ if (!Util.getConfig(this.config, 'producerToken')) {
4885
+ return false;
4886
+ }
4887
+ return true;
4888
+ }
4889
+ static serialize(data) {
4890
+ return JSON.stringify(data);
4891
+ }
4892
+ static serialize_formatted(data) {
4893
+ return JSON.stringify(data, null, 2);
4894
+ }
4895
+ produce(args, output) {
4896
+ if (!this.isEnabled()) {
4897
+ const errorPromise = new Promise((resolve) => {
4898
+ return resolve(false);
4899
+ });
4900
+ return errorPromise;
4901
+ }
4902
+ Util.debug(this.config, 'Sending call to Varsnap');
4903
+ return Promise.resolve(output).then((outputValue) => {
4904
+ const data = {
4905
+ 'producer_token': Util.getConfig(this.config, 'producerToken'),
4906
+ 'signature': this.signature,
4907
+ 'inputs': Producer.serialize(args),
4908
+ 'prod_outputs': Producer.serialize(outputValue),
4909
+ };
4910
+ return Util.ajax(produceURL, data).then(() => {
4911
+ return true;
4912
+ }).catch((err) => {
4913
+ if (err.response) {
4914
+ if (err.response.status === 429) {
4915
+ Util.error(this.config, 'Cannot produce to Varsnap; Signature at rate limit');
4916
+ return true;
4917
+ }
4918
+ if (err.response.status === 404) {
4919
+ Util.error(this.config, 'Cannot produce to Varsnap; check your producer token');
4920
+ }
4921
+ else {
4922
+ Util.error(this.config, err.response.statusText);
4923
+ }
4924
+ }
4925
+ return false;
4926
+ });
4927
+ });
4928
+ }
4929
+ }
4930
+ class Consumer {
4931
+ constructor(targetFunc, signature, config) {
4932
+ this.targetFunc = targetFunc;
4933
+ this.signature = signature;
4934
+ this.config = config;
4935
+ }
4936
+ isEnabled() {
4937
+ if (!this.config.varsnap) {
4938
+ return false;
4939
+ }
4940
+ if (Util.getConfig(this.config, 'env') !== 'development') {
4941
+ return false;
4942
+ }
4943
+ if (!Util.getConfig(this.config, 'consumerToken')) {
4944
+ return false;
4945
+ }
4946
+ return true;
4947
+ }
4948
+ static deserialize(data) {
4949
+ if (data === '') {
4950
+ return undefined;
4951
+ }
4952
+ return JSON.parse(data);
4953
+ }
4954
+ consume(trialGroup) {
4955
+ if (!this.isEnabled()) {
4956
+ const errorPromise = new Promise((resolve) => {
4957
+ Util.error(this.config, 'Varsnap not enabled for testing');
4958
+ return resolve(false);
4959
+ });
4960
+ return errorPromise;
4961
+ }
4962
+ const data = {
4963
+ 'consumer_token': Util.getConfig(this.config, 'consumerToken'),
4964
+ 'signature': this.signature,
4965
+ };
4966
+ const ajax = Util.ajax(consumeURL, data);
4967
+ const consume = ajax.then((rawResponse) => {
4968
+ const response = rawResponse;
4969
+ if (!response || response.status !== 'ok') {
4970
+ const errorPromise = new Promise((resolve) => {
4971
+ Util.error(this.config, 'Received error from Varsnap: ' + response.status);
4972
+ return resolve(false);
4973
+ });
4974
+ return [errorPromise];
4975
+ }
4976
+ if (response.results.length === 0) {
4977
+ Util.log(this.config, 'No snaps found for signature: ' + data.signature);
4978
+ }
4979
+ const trialPromises = [];
4980
+ for (const snap of response.results) {
4981
+ const inputs = Consumer.deserialize(snap['inputs']);
4982
+ const prodOutputs = Consumer.deserialize(snap['prod_outputs']);
4983
+ let localOutputs;
4984
+ try {
4985
+ localOutputs = this.targetFunc(...inputs);
4986
+ }
4987
+ catch (err) {
4988
+ localOutputs = err;
4989
+ }
4990
+ const trialPromise = Promise.resolve(localOutputs).then((localOutputValue) => {
4991
+ const prodOutputsSerialized = Producer.serialize(prodOutputs);
4992
+ const localOutputsSerialized = Producer.serialize(localOutputValue);
4993
+ const matches = prodOutputsSerialized === localOutputsSerialized;
4994
+ this.reportCentral(trialGroup, snap, prodOutputs, localOutputValue, matches).then((trialURL) => {
4995
+ this.reportLog(snap['id'], inputs, prodOutputs, localOutputValue, matches, trialURL);
4996
+ });
4997
+ return matches;
4998
+ });
4999
+ trialPromises.push(trialPromise);
5000
+ }
5001
+ return trialPromises;
5002
+ }).then((trialPromises) => {
5003
+ return Promise.all(trialPromises).then((results) => {
5004
+ const allMatches = results.every((result) => result);
5005
+ return allMatches;
5006
+ });
5007
+ }).catch((error) => {
5008
+ Util.error(this.config, 'Cannot contact Varsnap: ' + error);
5009
+ return false;
5010
+ });
5011
+ return consume;
5012
+ }
5013
+ reportCentral(trialGroup, snap, prodOutputs, localOutputs, matches) {
5014
+ const data = {
5015
+ 'trial_group_id': trialGroup.trial_group_id,
5016
+ 'consumer_token': Util.getConfig(this.config, 'consumerToken'),
5017
+ 'snap_id': snap.id,
5018
+ 'test_outputs': Producer.serialize(localOutputs),
5019
+ 'matches': matches.toString(),
5020
+ 'snap_outputs_formatted': Producer.serialize_formatted(prodOutputs),
5021
+ 'test_outputs_formatted': Producer.serialize_formatted(localOutputs),
5022
+ };
5023
+ const ajax = Util.ajax(produceTrialURL, data);
5024
+ const report = ajax.then((rawResponse) => {
5025
+ const response = rawResponse;
5026
+ if (!response || response.status !== 'ok') {
5027
+ return false;
5028
+ }
5029
+ const trialURL = response['trial_url'];
5030
+ return trialURL;
5031
+ }).catch((error) => {
5032
+ Util.error(this.config, 'Cannot upload test results to Varsnap: ' + error);
5033
+ return false;
5034
+ });
5035
+ return report;
5036
+ }
5037
+ reportLog(snapID, inputs, prodOutputs, localOutputs, matches, trialURL) {
5038
+ if (matches) {
5039
+ return;
5040
+ }
5041
+ Util.log(this.config, '');
5042
+ Util.log(this.config, 'Testing with Varsnap uuid: ' + snapID);
5043
+ Util.log(this.config, 'Signature: ' + this.signature);
5044
+ Util.log(this.config, 'Function input args: ' + Util.limitString(inputs));
5045
+ Util.log(this.config, 'Production function outputs: ' + Util.limitString(prodOutputs));
5046
+ Util.log(this.config, 'Your function outputs: ' + Util.limitString(localOutputs));
5047
+ Util.log(this.config, 'Matching outputs: ' + matches);
5048
+ let trialURLView = 'Cannot upload trial';
5049
+ if (trialURL) {
5050
+ trialURLView = String(trialURL);
5051
+ }
5052
+ Util.log(this.config, 'Trial URL: ' + trialURLView);
5053
+ }
5054
+ reportTrialGroup(trialGroup) {
5055
+ Util.log(this.config, 'Trial Group: ' + trialGroup.trial_group_url);
5056
+ }
5057
+ }
5058
+ function varsnap(func, funcName) {
5059
+ if (funcName === undefined) {
5060
+ funcName = '';
5061
+ }
5062
+ const signature = Util.getSignature(func, funcName);
5063
+ const producer = new Producer(func, signature, varsnap._config);
5064
+ const consumer = new Consumer(func, signature, varsnap._config);
5065
+ const wrapped = function (...args) {
5066
+ let result;
5067
+ try {
5068
+ result = func(...args);
5069
+ }
5070
+ catch (err) {
5071
+ producer.produce(args, err);
5072
+ throw (err);
5073
+ }
5074
+ producer.produce(args, result);
5075
+ return result;
5076
+ };
5077
+ wrapped.producer = producer;
5078
+ wrapped.consumer = consumer;
5079
+ wrapped.signature = signature;
5080
+ Producers.push(producer);
5081
+ Consumers.push(consumer);
5082
+ return wrapped;
5083
+ }
5084
+ varsnap._config = defaultConfig;
5085
+ varsnap.updateConfig = function updateConfig(newConfig) {
5086
+ let config = varsnap._config;
5087
+ for (const key of Object.keys(varsnap._config)) {
5088
+ if (Object.prototype.hasOwnProperty.call(newConfig, key)) {
5089
+ config = Util.setConfig(config, key, newConfig[key]);
5090
+ }
5091
+ }
5092
+ varsnap._config = config;
5093
+ };
5094
+ varsnap.reset = function reset() {
5095
+ Util.resetConsumers();
5096
+ Util.resetProducers();
5097
+ };
5098
+ varsnap.version = version;
5099
+ function getTrialGroup(consumerConfig) {
5100
+ const data = {
5101
+ 'branch': Util.getConfig(consumerConfig, 'branch'),
5102
+ 'consumer_token': Util.getConfig(consumerConfig, 'consumerToken'),
5103
+ 'client': clientName,
5104
+ };
5105
+ const raw = data;
5106
+ const ajax = Util.ajax(trialGroupURL, raw);
5107
+ const trialGroup = ajax.then((rawResponse) => {
5108
+ const response = rawResponse;
5109
+ return response;
5110
+ }).catch((error) => {
5111
+ let errorMessage = '';
5112
+ if (error && error.response && error.response.data) {
5113
+ const response = error.response.data;
5114
+ errorMessage = response.error;
5115
+ }
5116
+ else {
5117
+ errorMessage = error.toString();
5118
+ }
5119
+ Util.error(consumerConfig, 'Cannot generate a new Trial Group: ' + errorMessage);
5120
+ return {
5121
+ status: 'not ok',
5122
+ project_id: '',
5123
+ trial_group_id: '',
5124
+ trial_group_url: '',
5125
+ };
5126
+ });
5127
+ return trialGroup;
5128
+ }
5129
+ function runTests() {
5130
+ const consumers = Util.getConsumers();
5131
+ if (consumers.length === 0) {
5132
+ return Promise.resolve(true);
5133
+ }
5134
+ const consumerConfig = consumers[0].config;
5135
+ return getTrialGroup(consumerConfig).then((trialGroup) => {
5136
+ const testPromises = [];
5137
+ for (const consumer of consumers) {
5138
+ const testPromise = consumer.consume(trialGroup);
5139
+ testPromises.push(testPromise);
5140
+ }
5141
+ if (consumers.length > 0) {
5142
+ consumers[0].reportTrialGroup(trialGroup);
5143
+ }
5144
+ return Promise.all(testPromises);
5145
+ }).then((results) => {
5146
+ const allPass = results.every((result) => result);
5147
+ return allPass;
5148
+ });
5149
+ }
5150
+ varsnap.runTests = runTests;
5151
+
5152
+
5147
5153
  /***/ })
5148
5154
 
5149
5155
  /******/ });