ng-talkback 21.0.14 → 21.0.17
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/browser/package.json +1 -1
- package/browser-prod/package.json +1 -1
- package/browser-prod.re-export.json +1 -0
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/package.json +1 -1
- package/lib-prod/build-info._auto-generated_.js +14 -30
- package/lib-prod/env/env.angular-node-app.js +130 -71
- package/lib-prod/env/env.docs-webapp.js +130 -71
- package/lib-prod/env/env.electron-app.js +130 -71
- package/lib-prod/env/env.mobile-app.js +130 -71
- package/lib-prod/env/env.npm-lib-and-cli-tool.js +130 -71
- package/lib-prod/env/env.vscode-plugin.js +130 -71
- package/lib-prod/env/index.js +6 -23
- package/lib-prod/es6.backend.js +5 -5
- package/lib-prod/features/error-rate.backend.js +23 -24
- package/lib-prod/features/latency.backend.js +26 -29
- package/lib-prod/index._auto-generated_.js +0 -6
- package/lib-prod/index.js +15 -31
- package/lib-prod/logger.backend.js +20 -21
- package/lib-prod/migrations/index.js +1 -19
- package/lib-prod/migrations/migrations_index._auto-generated_.js +0 -4
- package/lib-prod/options.backend.js +86 -82
- package/lib-prod/package.json +1 -1
- package/lib-prod/request-handler.backend.js +124 -138
- package/lib-prod/server.backend.js +78 -84
- package/lib-prod/summary.backend.js +20 -21
- package/lib-prod/talkback-factory.backend.js +17 -18
- package/lib-prod/tape-matcher.backend.js +87 -89
- package/lib-prod/tape-renderer.backend.js +88 -94
- package/lib-prod/tape-store.backend.js +86 -91
- package/lib-prod/tape.backend.js +69 -74
- package/lib-prod/types.backend.js +0 -3
- package/lib-prod/utils/content-encoding.backend.js +34 -35
- package/lib-prod/utils/headers.backend.js +13 -15
- package/lib-prod/utils/media-type.backend.js +45 -46
- package/lib-prod.re-export.json +1 -0
- package/package.json +3 -2
- package/websql/package.json +1 -1
- package/websql-prod/package.json +1 -1
- package/websql-prod.re-export.json +1 -0
- package/lib-prod/build-info._auto-generated_.d.ts +0 -24
- package/lib-prod/build-info._auto-generated_.js.map +0 -1
- package/lib-prod/env/env.angular-node-app.d.ts +0 -64
- package/lib-prod/env/env.angular-node-app.js.map +0 -1
- package/lib-prod/env/env.docs-webapp.d.ts +0 -64
- package/lib-prod/env/env.docs-webapp.js.map +0 -1
- package/lib-prod/env/env.electron-app.d.ts +0 -64
- package/lib-prod/env/env.electron-app.js.map +0 -1
- package/lib-prod/env/env.mobile-app.d.ts +0 -64
- package/lib-prod/env/env.mobile-app.js.map +0 -1
- package/lib-prod/env/env.npm-lib-and-cli-tool.d.ts +0 -64
- package/lib-prod/env/env.npm-lib-and-cli-tool.js.map +0 -1
- package/lib-prod/env/env.vscode-plugin.d.ts +0 -64
- package/lib-prod/env/env.vscode-plugin.js.map +0 -1
- package/lib-prod/env/index.d.ts +0 -6
- package/lib-prod/env/index.js.map +0 -1
- package/lib-prod/es6.backend.d.ts +0 -2
- package/lib-prod/es6.backend.js.map +0 -1
- package/lib-prod/features/error-rate.backend.d.ts +0 -9
- package/lib-prod/features/error-rate.backend.js.map +0 -1
- package/lib-prod/features/latency.backend.d.ts +0 -8
- package/lib-prod/features/latency.backend.js.map +0 -1
- package/lib-prod/index._auto-generated_.d.ts +0 -0
- package/lib-prod/index._auto-generated_.js.map +0 -1
- package/lib-prod/index.d.ts +0 -41
- package/lib-prod/index.js.map +0 -1
- package/lib-prod/logger.backend.d.ts +0 -7
- package/lib-prod/logger.backend.js.map +0 -1
- package/lib-prod/migrations/index.d.ts +0 -1
- package/lib-prod/migrations/index.js.map +0 -1
- package/lib-prod/migrations/migrations_index._auto-generated_.d.ts +0 -0
- package/lib-prod/migrations/migrations_index._auto-generated_.js.map +0 -1
- package/lib-prod/options.backend.d.ts +0 -52
- package/lib-prod/options.backend.js.map +0 -1
- package/lib-prod/request-handler.backend.d.ts +0 -13
- package/lib-prod/request-handler.backend.js.map +0 -1
- package/lib-prod/server.backend.d.ts +0 -17
- package/lib-prod/server.backend.js.map +0 -1
- package/lib-prod/summary.backend.d.ts +0 -8
- package/lib-prod/summary.backend.js.map +0 -1
- package/lib-prod/talkback-factory.backend.d.ts +0 -7
- package/lib-prod/talkback-factory.backend.js.map +0 -1
- package/lib-prod/tape-matcher.backend.d.ts +0 -12
- package/lib-prod/tape-matcher.backend.js.map +0 -1
- package/lib-prod/tape-renderer.backend.d.ts +0 -24
- package/lib-prod/tape-renderer.backend.js.map +0 -1
- package/lib-prod/tape-store.backend.d.ts +0 -16
- package/lib-prod/tape-store.backend.js.map +0 -1
- package/lib-prod/tape.backend.d.ts +0 -19
- package/lib-prod/tape.backend.js.map +0 -1
- package/lib-prod/types.backend.d.ts +0 -43
- package/lib-prod/types.backend.js.map +0 -1
- package/lib-prod/utils/content-encoding.backend.d.ts +0 -10
- package/lib-prod/utils/content-encoding.backend.js.map +0 -1
- package/lib-prod/utils/headers.backend.d.ts +0 -4
- package/lib-prod/utils/headers.backend.js.map +0 -1
- package/lib-prod/utils/media-type.backend.d.ts +0 -10
- package/lib-prod/utils/media-type.backend.js.map +0 -1
package/lib-prod/index.js
CHANGED
|
@@ -1,37 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.talkback = void 0;
|
|
18
1
|
let a = 2;
|
|
19
2
|
a++;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const options_backend_1 = require("./options.backend");
|
|
3
|
+
export * from "./options.backend";
|
|
4
|
+
export * from "./tape.backend";
|
|
5
|
+
import TalkbackFactory from "./talkback-factory.backend";
|
|
6
|
+
import { DefaultOptions, FallbackMode, RecordMode } from "./options.backend";
|
|
25
7
|
const talkbackFn = (options) => {
|
|
26
|
-
|
|
8
|
+
return TalkbackFactory.server(options);
|
|
27
9
|
};
|
|
28
10
|
talkbackFn.Options = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
11
|
+
Default: DefaultOptions,
|
|
12
|
+
FallbackMode,
|
|
13
|
+
RecordMode
|
|
14
|
+
};
|
|
15
|
+
talkbackFn.requestHandler = (options) => TalkbackFactory.requestHandler(options);
|
|
16
|
+
const talkback = talkbackFn;
|
|
17
|
+
var index_default = talkbackFn;
|
|
18
|
+
export {
|
|
19
|
+
index_default as default,
|
|
20
|
+
talkback
|
|
32
21
|
};
|
|
33
|
-
talkbackFn.requestHandler = (options) => talkback_factory_backend_1.default.requestHandler(options);
|
|
34
|
-
exports.talkback = talkbackFn;
|
|
35
|
-
exports.default = talkbackFn;
|
|
36
|
-
//#endregion
|
|
37
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,26 +1,25 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
class Logger {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
2
|
+
options;
|
|
3
|
+
constructor(options) {
|
|
4
|
+
this.options = options;
|
|
5
|
+
if (this.options.debug) {
|
|
6
|
+
console.debug("DEBUG mode active");
|
|
10
7
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
}
|
|
9
|
+
log(message) {
|
|
10
|
+
if (!this.options.silent || this.options.debug) {
|
|
11
|
+
console.log(message);
|
|
15
12
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
error(message) {
|
|
22
|
-
console.error(message);
|
|
13
|
+
}
|
|
14
|
+
debug(message) {
|
|
15
|
+
if (this.options.debug) {
|
|
16
|
+
console.debug(message);
|
|
23
17
|
}
|
|
18
|
+
}
|
|
19
|
+
error(message) {
|
|
20
|
+
console.error(message);
|
|
21
|
+
}
|
|
24
22
|
}
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
export {
|
|
24
|
+
Logger as default
|
|
25
|
+
};
|
|
@@ -1,19 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
//@ts-nocheck
|
|
18
|
-
__exportStar(require("./migrations_index._auto-generated_"), exports);
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from "./migrations_index._auto-generated_";
|
|
@@ -1,91 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import Logger from "./logger.backend";
|
|
2
|
+
const RecordMode = {
|
|
3
|
+
NEW: "NEW",
|
|
4
|
+
// If no tape matches the request, proxy it and save the response to a tape
|
|
5
|
+
OVERWRITE: "OVERWRITE",
|
|
6
|
+
// Always proxy the request and save the response to a tape, overwriting any existing one
|
|
7
|
+
DISABLED: "DISABLED",
|
|
8
|
+
// If a matching tape exists, return it. Otherwise, don't proxy the request and use `fallbackMode` for the response
|
|
9
|
+
ALL: []
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
RecordMode.ALL = [RecordMode.NEW, RecordMode.OVERWRITE, RecordMode.DISABLED];
|
|
12
|
+
const FallbackMode = {
|
|
13
|
+
NOT_FOUND: "NOT_FOUND",
|
|
14
|
+
PROXY: "PROXY",
|
|
15
|
+
ALL: []
|
|
16
16
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
17
|
+
FallbackMode.ALL = [FallbackMode.NOT_FOUND, FallbackMode.PROXY];
|
|
18
|
+
const DefaultOptions = {
|
|
19
|
+
host: "",
|
|
20
|
+
port: 8080,
|
|
21
|
+
path: "./tapes/",
|
|
22
|
+
record: RecordMode.NEW,
|
|
23
|
+
fallbackMode: FallbackMode.NOT_FOUND,
|
|
24
|
+
name: "unnamed",
|
|
25
|
+
tapeNameGenerator: void 0,
|
|
26
|
+
https: {
|
|
27
|
+
enabled: false,
|
|
28
|
+
keyPath: void 0,
|
|
29
|
+
certPath: void 0
|
|
30
|
+
},
|
|
31
|
+
ignoreHeaders: ["content-length", "host"],
|
|
32
|
+
ignoreQueryParams: [],
|
|
33
|
+
ignoreBody: false,
|
|
34
|
+
bodyMatcher: void 0,
|
|
35
|
+
urlMatcher: void 0,
|
|
36
|
+
requestDecorator: void 0,
|
|
37
|
+
responseDecorator: void 0,
|
|
38
|
+
tapeDecorator: void 0,
|
|
39
|
+
latency: 0,
|
|
40
|
+
errorRate: 0,
|
|
41
|
+
silent: false,
|
|
42
|
+
summary: true,
|
|
43
|
+
debug: false,
|
|
44
|
+
logger: new Logger({})
|
|
45
45
|
};
|
|
46
46
|
class OptionsFactory {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
47
|
+
static logger;
|
|
48
|
+
static prepare(usrOpts = {}) {
|
|
49
|
+
const opts = {
|
|
50
|
+
...DefaultOptions,
|
|
51
|
+
name: usrOpts.host,
|
|
52
|
+
...usrOpts,
|
|
53
|
+
ignoreHeaders: [
|
|
54
|
+
...DefaultOptions.ignoreHeaders,
|
|
55
|
+
...usrOpts.ignoreHeaders || []
|
|
56
|
+
]
|
|
57
|
+
};
|
|
58
|
+
this.logger = new Logger(opts);
|
|
59
|
+
opts.logger = this.logger;
|
|
60
|
+
this.validateOptions(opts);
|
|
61
|
+
return opts;
|
|
62
|
+
}
|
|
63
|
+
static validateOptions(opts) {
|
|
64
|
+
this.validateRecord(opts.record);
|
|
65
|
+
this.validateFallbackMode(opts.fallbackMode);
|
|
66
|
+
this.validateLatency(opts.latency);
|
|
67
|
+
this.validateErrorRate(opts.errorRate);
|
|
68
|
+
}
|
|
69
|
+
static validateRecord(record) {
|
|
70
|
+
if (typeof record === "string" && !RecordMode.ALL.includes(record)) {
|
|
71
|
+
throw `INVALID OPTION: record has an invalid value of '${record}'`;
|
|
62
72
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
this.validateErrorRate(opts.errorRate);
|
|
73
|
+
}
|
|
74
|
+
static validateFallbackMode(fallbackMode) {
|
|
75
|
+
if (typeof fallbackMode === "string" && !FallbackMode.ALL.includes(fallbackMode)) {
|
|
76
|
+
throw `INVALID OPTION: fallbackMode has an invalid value of '${fallbackMode}'`;
|
|
68
77
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
}
|
|
79
|
+
static validateLatency(latency) {
|
|
80
|
+
if (Array.isArray(latency) && latency.length !== 2) {
|
|
81
|
+
throw `Invalid LATENCY option. If using a range, the array should only have 2 values [min, max]. Current=[${latency}]`;
|
|
73
82
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
static validateLatency(latency) {
|
|
80
|
-
if (Array.isArray(latency) && latency.length !== 2) {
|
|
81
|
-
throw `Invalid LATENCY option. If using a range, the array should only have 2 values [min, max]. Current=[${latency}]`;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
static validateErrorRate(errorRate) {
|
|
85
|
-
if (typeof (errorRate) !== "function" && (errorRate < 0 || errorRate > 100)) {
|
|
86
|
-
throw `Invalid ERRORRATE option. Value should be between 0 and 100. Current=[${errorRate}]`;
|
|
87
|
-
}
|
|
83
|
+
}
|
|
84
|
+
static validateErrorRate(errorRate) {
|
|
85
|
+
if (typeof errorRate !== "function" && (errorRate < 0 || errorRate > 100)) {
|
|
86
|
+
throw `Invalid ERRORRATE option. Value should be between 0 and 100. Current=[${errorRate}]`;
|
|
88
87
|
}
|
|
88
|
+
}
|
|
89
89
|
}
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
export {
|
|
91
|
+
DefaultOptions,
|
|
92
|
+
FallbackMode,
|
|
93
|
+
RecordMode,
|
|
94
|
+
OptionsFactory as default
|
|
95
|
+
};
|
package/lib-prod/package.json
CHANGED
|
@@ -1,145 +1,131 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const error_rate_backend_1 = require("./features/error-rate.backend");
|
|
8
|
-
const latency_backend_1 = require("./features/latency.backend");
|
|
1
|
+
import { v4 as uuidv4 } from "uuid";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import Tape from "./tape.backend";
|
|
4
|
+
import OptionsFactory, { RecordMode, FallbackMode } from "./options.backend";
|
|
5
|
+
import ErrorRate from "./features/error-rate.backend";
|
|
6
|
+
import Latency from "./features/latency.backend";
|
|
9
7
|
class RequestHandler {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
tapeStore;
|
|
9
|
+
options;
|
|
10
|
+
errorRate;
|
|
11
|
+
latency;
|
|
12
|
+
constructor(tapeStore, options) {
|
|
13
|
+
this.tapeStore = tapeStore;
|
|
14
|
+
this.options = options;
|
|
15
|
+
this.errorRate = new ErrorRate(this.options);
|
|
16
|
+
this.latency = new Latency(this.options);
|
|
17
|
+
}
|
|
18
|
+
async handle(req) {
|
|
19
|
+
const matchingContext = {
|
|
20
|
+
id: uuidv4()
|
|
21
|
+
};
|
|
22
|
+
const recordMode = typeof this.options.record === "string" ? this.options.record : this.options.record(req);
|
|
23
|
+
OptionsFactory.validateRecord(recordMode);
|
|
24
|
+
if (this.options.requestDecorator) {
|
|
25
|
+
req = this.options.requestDecorator(req, matchingContext);
|
|
26
|
+
if (!req) {
|
|
27
|
+
throw new Error("requestDecorator didn't return a req object");
|
|
28
|
+
}
|
|
19
29
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
let newTape = new Tape(req, this.options);
|
|
31
|
+
let matchingTape = this.tapeStore.find(newTape);
|
|
32
|
+
let resObj, responseTape;
|
|
33
|
+
if (recordMode !== RecordMode.OVERWRITE && matchingTape) {
|
|
34
|
+
responseTape = matchingTape;
|
|
35
|
+
if (this.errorRate.shouldSimulate(req, matchingTape)) {
|
|
36
|
+
return this.errorRate.simulate(req);
|
|
37
|
+
}
|
|
38
|
+
await this.latency.simulate(req, matchingTape);
|
|
39
|
+
} else {
|
|
40
|
+
if (matchingTape) {
|
|
41
|
+
responseTape = matchingTape;
|
|
42
|
+
} else {
|
|
43
|
+
responseTape = newTape;
|
|
44
|
+
}
|
|
45
|
+
if (recordMode === RecordMode.NEW || recordMode === RecordMode.OVERWRITE) {
|
|
46
|
+
resObj = await this.makeRealRequest(req);
|
|
47
|
+
responseTape.res = { ...resObj };
|
|
48
|
+
if (this.options.tapeDecorator) {
|
|
49
|
+
responseTape = this.options.tapeDecorator(responseTape, matchingContext);
|
|
50
|
+
if (!responseTape) {
|
|
51
|
+
throw new Error("tapeDecorator didn't return a tape object");
|
|
52
|
+
}
|
|
31
53
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (this.errorRate.shouldSimulate(req, matchingTape)) {
|
|
38
|
-
return this.errorRate.simulate(req);
|
|
39
|
-
}
|
|
40
|
-
await this.latency.simulate(req, matchingTape);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
if (matchingTape) {
|
|
44
|
-
responseTape = matchingTape;
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
responseTape = newTape;
|
|
48
|
-
}
|
|
49
|
-
if (recordMode === options_backend_1.RecordMode.NEW || recordMode === options_backend_1.RecordMode.OVERWRITE) {
|
|
50
|
-
resObj = await this.makeRealRequest(req);
|
|
51
|
-
responseTape.res = { ...resObj };
|
|
52
|
-
if (this.options.tapeDecorator) {
|
|
53
|
-
responseTape = this.options.tapeDecorator(responseTape, matchingContext);
|
|
54
|
-
if (!responseTape) {
|
|
55
|
-
throw new Error("tapeDecorator didn't return a tape object");
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
await this.tapeStore.save(responseTape);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
resObj = await this.onNoRecord(req);
|
|
62
|
-
responseTape.res = { ...resObj };
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
resObj = responseTape.res;
|
|
66
|
-
if (this.options.responseDecorator) {
|
|
67
|
-
const clonedTape = await responseTape.clone();
|
|
68
|
-
const resTape = this.options.responseDecorator(clonedTape, req, matchingContext);
|
|
69
|
-
if (!resTape) {
|
|
70
|
-
throw new Error("responseDecorator didn't return a tape object");
|
|
71
|
-
}
|
|
72
|
-
if (resTape.res.headers["content-length"]) {
|
|
73
|
-
resTape.res.headers["content-length"] = resTape.res.body.length;
|
|
74
|
-
}
|
|
75
|
-
resObj = resTape.res;
|
|
76
|
-
}
|
|
77
|
-
return resObj;
|
|
54
|
+
await this.tapeStore.save(responseTape);
|
|
55
|
+
} else {
|
|
56
|
+
resObj = await this.onNoRecord(req);
|
|
57
|
+
responseTape.res = { ...resObj };
|
|
58
|
+
}
|
|
78
59
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
await this.latency.simulate(req, undefined);
|
|
92
|
-
return await this.makeRealRequest(req);
|
|
93
|
-
}
|
|
94
|
-
return {
|
|
95
|
-
status: 404,
|
|
96
|
-
headers: { "content-type": ["text/plain"] },
|
|
97
|
-
body: Buffer.from("talkback - tape not found")
|
|
98
|
-
};
|
|
60
|
+
resObj = responseTape.res;
|
|
61
|
+
if (this.options.responseDecorator) {
|
|
62
|
+
const clonedTape = await responseTape.clone();
|
|
63
|
+
const resTape = this.options.responseDecorator(clonedTape, req, matchingContext);
|
|
64
|
+
if (!resTape) {
|
|
65
|
+
throw new Error("responseDecorator didn't return a tape object");
|
|
66
|
+
}
|
|
67
|
+
if (resTape.res.headers["content-length"]) {
|
|
68
|
+
resTape.res.headers["content-length"] = resTape.res.body.length;
|
|
69
|
+
}
|
|
70
|
+
resObj = resTape.res;
|
|
99
71
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
72
|
+
return resObj;
|
|
73
|
+
}
|
|
74
|
+
async onNoRecord(req) {
|
|
75
|
+
const fallbackMode = typeof this.options.fallbackMode === "string" ? this.options.fallbackMode : this.options.fallbackMode(req);
|
|
76
|
+
OptionsFactory.validateFallbackMode(fallbackMode);
|
|
77
|
+
this.options.logger.log(`Tape for ${req.url} not found and recording is disabled (fallbackMode: ${fallbackMode})`);
|
|
78
|
+
this.options.logger.log({
|
|
79
|
+
url: req.url,
|
|
80
|
+
headers: req.headers
|
|
81
|
+
});
|
|
82
|
+
if (fallbackMode === FallbackMode.PROXY) {
|
|
83
|
+
if (this.errorRate.shouldSimulate(req, void 0)) {
|
|
84
|
+
return this.errorRate.simulate(req);
|
|
85
|
+
}
|
|
86
|
+
await this.latency.simulate(req, void 0);
|
|
87
|
+
return await this.makeRealRequest(req);
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
status: 404,
|
|
91
|
+
headers: { "content-type": ["text/plain"] },
|
|
92
|
+
body: Buffer.from("talkback - tape not found")
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
async makeRealRequest(req) {
|
|
96
|
+
let { method, url, body } = req;
|
|
97
|
+
const headers = { ...req.headers };
|
|
98
|
+
delete headers.host;
|
|
99
|
+
const host = this.options.host;
|
|
100
|
+
let urlToGetData = `${host}${url}`;
|
|
101
|
+
var fRes = {
|
|
102
|
+
status: 400,
|
|
103
|
+
headers: {},
|
|
104
|
+
body: new Buffer("")
|
|
105
|
+
};
|
|
106
|
+
try {
|
|
107
|
+
const r = await axios({
|
|
108
|
+
url: urlToGetData,
|
|
109
|
+
method,
|
|
110
|
+
headers,
|
|
111
|
+
data: body,
|
|
112
|
+
responseType: "arraybuffer"
|
|
113
|
+
});
|
|
114
|
+
fRes = {
|
|
115
|
+
status: r.status,
|
|
116
|
+
headers: r.headers,
|
|
117
|
+
body: r.data
|
|
118
|
+
};
|
|
119
|
+
} catch (err) {
|
|
120
|
+
fRes = {
|
|
121
|
+
status: err?.response?.status,
|
|
122
|
+
headers: err?.response?.headers,
|
|
123
|
+
body: err?.response?.data
|
|
124
|
+
};
|
|
142
125
|
}
|
|
126
|
+
return fRes;
|
|
127
|
+
}
|
|
143
128
|
}
|
|
144
|
-
|
|
145
|
-
|
|
129
|
+
export {
|
|
130
|
+
RequestHandler as default
|
|
131
|
+
};
|