@stuntman/shared 0.1.4 → 0.1.6

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.
@@ -0,0 +1,14 @@
1
+ import type * as Stuntman from '.';
2
+ export interface AppErrorInterface {
3
+ name?: string;
4
+ httpCode: Stuntman.HttpCode;
5
+ message: string;
6
+ isOperational?: boolean;
7
+ }
8
+ export declare class AppError extends Error {
9
+ readonly name: string;
10
+ readonly httpCode: Stuntman.HttpCode;
11
+ readonly uuid?: string;
12
+ readonly isOperational: boolean;
13
+ constructor(args: AppErrorInterface);
14
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppError = void 0;
4
+ class AppError extends Error {
5
+ constructor(args) {
6
+ super(args.message);
7
+ this.isOperational = true;
8
+ Object.setPrototypeOf(this, new.target.prototype);
9
+ this.name = args.name || 'Error';
10
+ this.httpCode = args.httpCode;
11
+ if (args.isOperational !== undefined) {
12
+ this.isOperational = args.isOperational;
13
+ }
14
+ Error.captureStackTrace(this);
15
+ }
16
+ }
17
+ exports.AppError = AppError;
@@ -0,0 +1,2 @@
1
+ import { ServerConfig } from '.';
2
+ export declare const serverConfig: ServerConfig;
package/dist/config.js ADDED
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.serverConfig = void 0;
7
+ const _1 = require(".");
8
+ const config_1 = __importDefault(require("config"));
9
+ const path_1 = __importDefault(require("path"));
10
+ // TODO safeguards & defaults
11
+ const defaultConfig = {
12
+ api: {
13
+ disabled: false,
14
+ port: _1.DEFAULT_API_PORT,
15
+ apiKeyReadOnly: null,
16
+ apiKeyReadWrite: null,
17
+ },
18
+ mock: {
19
+ domain: _1.DEFAULT_MOCK_DOMAIN,
20
+ externalDns: _1.EXTERNAL_DNS,
21
+ port: _1.DEFAULT_MOCK_PORT,
22
+ timeout: _1.DEFAULT_PROXY_TIMEOUT,
23
+ rulesPath: path_1.default.join(process.cwd(), 'rules'),
24
+ },
25
+ storage: {
26
+ traffic: {
27
+ limitCount: _1.DEFAULT_CACHE_MAX_ENTRIES,
28
+ limitSize: _1.DEFAULT_CACHE_MAX_SIZE,
29
+ ttl: _1.DEFAULT_CACHE_TTL,
30
+ },
31
+ },
32
+ webgui: {
33
+ disabled: false,
34
+ },
35
+ };
36
+ config_1.default.util.setModuleDefaults('stuntman', defaultConfig);
37
+ let configFromFile = {};
38
+ try {
39
+ configFromFile = config_1.default.get('stuntman');
40
+ }
41
+ catch (error) {
42
+ // eslint-disable-next-line no-console
43
+ console.warn('unable to find correct config - starting with defaults');
44
+ }
45
+ exports.serverConfig = configFromFile;
@@ -0,0 +1,14 @@
1
+ export declare const DEFAULT_PROXY_TIMEOUT = 60000;
2
+ export declare const DEFAULT_RULE_PRIORITY = 100;
3
+ export declare const DEFAULT_MOCK_PORT = 2015;
4
+ export declare const DEFAULT_API_PORT = 1985;
5
+ export declare const DEFAULT_CACHE_MAX_ENTRIES = 500;
6
+ export declare const DEFAULT_CACHE_MAX_SIZE: number;
7
+ export declare const DEFAULT_CACHE_TTL: number;
8
+ export declare const DEFAULT_MOCK_DOMAIN = "stuntman";
9
+ export declare const DEFAULT_RULE_TTL_SECONDS: number;
10
+ export declare const MIN_RULE_TTL_SECONDS = 10;
11
+ export declare const MAX_RULE_TTL_SECONDS: number;
12
+ export declare const CATCH_ALL_RULE_PRIORITY: number;
13
+ export declare const CATCH_RULE_NAME = "internal/catch-all";
14
+ export declare const EXTERNAL_DNS: string[];
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EXTERNAL_DNS = exports.CATCH_RULE_NAME = exports.CATCH_ALL_RULE_PRIORITY = exports.MAX_RULE_TTL_SECONDS = exports.MIN_RULE_TTL_SECONDS = exports.DEFAULT_RULE_TTL_SECONDS = exports.DEFAULT_MOCK_DOMAIN = exports.DEFAULT_CACHE_TTL = exports.DEFAULT_CACHE_MAX_SIZE = exports.DEFAULT_CACHE_MAX_ENTRIES = exports.DEFAULT_API_PORT = exports.DEFAULT_MOCK_PORT = exports.DEFAULT_RULE_PRIORITY = exports.DEFAULT_PROXY_TIMEOUT = void 0;
4
+ exports.DEFAULT_PROXY_TIMEOUT = 60000;
5
+ exports.DEFAULT_RULE_PRIORITY = 100;
6
+ exports.DEFAULT_MOCK_PORT = 2015;
7
+ exports.DEFAULT_API_PORT = 1985;
8
+ exports.DEFAULT_CACHE_MAX_ENTRIES = 500;
9
+ exports.DEFAULT_CACHE_MAX_SIZE = 500 * 1024 * 1024;
10
+ exports.DEFAULT_CACHE_TTL = 1000 * 60 * 60;
11
+ exports.DEFAULT_MOCK_DOMAIN = 'stuntman';
12
+ exports.DEFAULT_RULE_TTL_SECONDS = 60 * 10;
13
+ exports.MIN_RULE_TTL_SECONDS = 10;
14
+ exports.MAX_RULE_TTL_SECONDS = 60 * 60;
15
+ exports.CATCH_ALL_RULE_PRIORITY = Infinity;
16
+ exports.CATCH_RULE_NAME = 'internal/catch-all';
17
+ exports.EXTERNAL_DNS = ['8.8.8.8', '1.1.1.1'];
@@ -0,0 +1,179 @@
1
+ export * from './constants';
2
+ export * from './appError';
3
+ export * from './logger';
4
+ export * from './stringify';
5
+ export * from './rawHeaders';
6
+ export * from './config';
7
+ export declare const INDEX_DTS: string;
8
+ type NonObject = string | number | boolean | symbol | undefined | null | any[];
9
+ interface SerializableTypesRecord<T> {
10
+ [k: string | number]: T;
11
+ }
12
+ export type RecursivePartial<T> = {
13
+ [P in keyof T]?: T[P] extends (infer U)[] ? RecursivePartial<U>[] : T[P] extends object ? RecursivePartial<T[P]> : T[P];
14
+ };
15
+ type SerializableTypes = string | number | boolean | undefined | null | RegExp | SerializableTypes[] | SerializableTypesRecord<SerializableTypes>;
16
+ export declare enum HttpCode {
17
+ OK = 200,
18
+ NO_CONTENT = 204,
19
+ BAD_REQUEST = 400,
20
+ UNAUTHORIZED = 401,
21
+ NOT_FOUND = 404,
22
+ CONFLICT = 409,
23
+ UNPROCESSABLE_ENTITY = 422,
24
+ INTERNAL_SERVER_ERROR = 500
25
+ }
26
+ export type LocalVariables = Record<string, SerializableTypes>;
27
+ export type RuleMatchResult = boolean | {
28
+ result: boolean;
29
+ enableRuleIds?: string[];
30
+ disableRuleIds?: string[];
31
+ description?: string;
32
+ };
33
+ export type RemotableFunction<T extends Function> = {
34
+ localFn: T;
35
+ localVariables?: LocalVariables;
36
+ };
37
+ export type SerializedRemotableFunction = {
38
+ localFn: string;
39
+ localVariables?: string;
40
+ remoteFn: string;
41
+ };
42
+ type WithRemotableFunctions<Type> = {
43
+ [PropertyKey in keyof Type]: Extract<Type[PropertyKey], Function> extends never ? Exclude<Type[PropertyKey], NonObject> extends never ? Type[PropertyKey] : WithRemotableFunctions<Exclude<Type[PropertyKey], NonObject>> : Exclude<Type[PropertyKey], Function> | RemotableFunction<Extract<Type[PropertyKey], Function>>;
44
+ };
45
+ export type WithSerializedFunctions<Type> = {
46
+ [PropertyKey in keyof Type]: Extract<Type[PropertyKey], RemotableFunction<Function>> extends never ? Exclude<Type[PropertyKey], NonObject> extends never ? Type[PropertyKey] : WithSerializedFunctions<Exclude<Type[PropertyKey], NonObject>> : Exclude<Type[PropertyKey], RemotableFunction<Function>> | SerializedRemotableFunction;
47
+ };
48
+ export interface RawHeadersInterface extends Array<string> {
49
+ get: (name: string) => string | undefined;
50
+ set: (name: string, value: string) => void;
51
+ has: (name: string, value?: string) => boolean;
52
+ add: (name: string, value: string) => void;
53
+ remove: (name: string) => void;
54
+ toHeaderPairs: () => readonly [string, string][];
55
+ }
56
+ export type BaseRequest = {
57
+ rawHeaders: RawHeadersInterface;
58
+ url: string;
59
+ body?: any;
60
+ method: string;
61
+ };
62
+ export type Request = BaseRequest & {
63
+ id: string;
64
+ timestamp: number;
65
+ gqlBody?: GQLRequestBody;
66
+ };
67
+ export type Response = {
68
+ rawHeaders?: RawHeadersInterface;
69
+ status?: number;
70
+ body?: any;
71
+ timestamp?: number;
72
+ };
73
+ export type LogEntry = {
74
+ originalRequest: Request;
75
+ labels?: string[];
76
+ mockRuleId?: string;
77
+ originalResponse?: Response;
78
+ modifiedRequest?: Request;
79
+ modifiedResponse?: Response;
80
+ };
81
+ export type RuleMatchFunction = (request: Request) => RuleMatchResult;
82
+ export type RequestManipulationFn = (request: Request) => Request;
83
+ export type ResponseManipulationFn = (request: Request, response: Response) => Response;
84
+ export type ResponseGenerationFn = (request: Request) => Response;
85
+ export type Actions = {
86
+ proxyPass: true;
87
+ mockResponse?: undefined;
88
+ modifyRequest?: undefined;
89
+ modifyResponse?: undefined;
90
+ } | {
91
+ mockResponse: Response | ResponseGenerationFn;
92
+ proxyPass?: undefined;
93
+ modifyRequest?: undefined;
94
+ modifyResponse?: undefined;
95
+ } | {
96
+ modifyRequest: RequestManipulationFn;
97
+ modifyResponse?: ResponseManipulationFn;
98
+ proxyPass?: true | undefined;
99
+ mockResponse?: undefined;
100
+ } | {
101
+ modifyRequest?: RequestManipulationFn;
102
+ modifyResponse: ResponseManipulationFn;
103
+ proxyPass?: true | undefined;
104
+ mockResponse?: undefined;
105
+ };
106
+ export type Rule = {
107
+ id: string;
108
+ priority?: number;
109
+ matches: RuleMatchFunction;
110
+ labels?: string[];
111
+ actions: Actions;
112
+ disableAfterUse?: boolean | number;
113
+ removeAfterUse?: boolean | number;
114
+ ttlSeconds: number;
115
+ storeTraffic?: boolean;
116
+ isEnabled?: boolean;
117
+ };
118
+ export type DeployedRule = Omit<Rule, 'disableAfterUse' | 'removeAfterUse' | 'ttlSeconds'>;
119
+ export type SerializableRule = WithRemotableFunctions<Rule>;
120
+ export type SerializedRule = WithSerializedFunctions<SerializableRule>;
121
+ export type LiveRule = Rule & {
122
+ counter: number;
123
+ createdTimestamp: number;
124
+ };
125
+ export type GQLRequestBody = {
126
+ operationName: string;
127
+ variables?: any;
128
+ query: string;
129
+ type: 'query' | 'mutation';
130
+ methodName?: string;
131
+ };
132
+ export type WebGuiConfig = {
133
+ disabled: boolean;
134
+ };
135
+ export type ApiConfig = {
136
+ port: number;
137
+ disabled: boolean;
138
+ apiKeyReadWrite: string | null;
139
+ apiKeyReadOnly: string | null;
140
+ };
141
+ export type ClientConfig = {
142
+ protocol?: 'http' | 'https';
143
+ host?: string;
144
+ port?: number;
145
+ timeout?: number;
146
+ };
147
+ export type MockConfig = {
148
+ domain: string;
149
+ port: number;
150
+ httpsPort?: number;
151
+ httpsKey?: string;
152
+ httpsCert?: string;
153
+ timeout: number;
154
+ externalDns: string[];
155
+ rulesPath: string;
156
+ disableProxy?: boolean;
157
+ };
158
+ export type StorageConfig = {
159
+ limitCount: number;
160
+ limitSize: number;
161
+ ttl: number;
162
+ };
163
+ export type ServerConfig = {
164
+ webgui: WebGuiConfig;
165
+ api: ApiConfig;
166
+ mock: MockConfig;
167
+ storage: {
168
+ traffic: StorageConfig;
169
+ };
170
+ };
171
+ export interface RuleExecutorInterface {
172
+ addRule: (rule: Rule, overwrite?: boolean) => Promise<LiveRule>;
173
+ removeRule: (id: string) => Promise<void>;
174
+ enableRule: (id: string) => void;
175
+ disableRule: (id: string) => void;
176
+ findMatchingRule: (request: Request) => Promise<LiveRule | null>;
177
+ getRules: () => Promise<readonly LiveRule[]>;
178
+ getRule: (id: string) => Promise<LiveRule | undefined>;
179
+ }
package/dist/index.js ADDED
@@ -0,0 +1,40 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.HttpCode = exports.INDEX_DTS = void 0;
21
+ /* eslint-disable @typescript-eslint/ban-types */
22
+ __exportStar(require("./constants"), exports);
23
+ __exportStar(require("./appError"), exports);
24
+ __exportStar(require("./logger"), exports);
25
+ __exportStar(require("./stringify"), exports);
26
+ __exportStar(require("./rawHeaders"), exports);
27
+ __exportStar(require("./config"), exports);
28
+ const fs_1 = __importDefault(require("fs"));
29
+ exports.INDEX_DTS = fs_1.default.readFileSync(`${__dirname}/index.d.ts`, 'utf-8');
30
+ var HttpCode;
31
+ (function (HttpCode) {
32
+ HttpCode[HttpCode["OK"] = 200] = "OK";
33
+ HttpCode[HttpCode["NO_CONTENT"] = 204] = "NO_CONTENT";
34
+ HttpCode[HttpCode["BAD_REQUEST"] = 400] = "BAD_REQUEST";
35
+ HttpCode[HttpCode["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
36
+ HttpCode[HttpCode["NOT_FOUND"] = 404] = "NOT_FOUND";
37
+ HttpCode[HttpCode["CONFLICT"] = 409] = "CONFLICT";
38
+ HttpCode[HttpCode["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
39
+ HttpCode[HttpCode["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
40
+ })(HttpCode = exports.HttpCode || (exports.HttpCode = {}));
@@ -0,0 +1,9 @@
1
+ export declare const logger: import("pino").Logger<{
2
+ level: string;
3
+ messageKey: string;
4
+ formatters: {
5
+ level(label: string): {
6
+ level: string;
7
+ };
8
+ };
9
+ }>;
package/dist/logger.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ var _a;
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.logger = void 0;
8
+ const pino_1 = __importDefault(require("pino"));
9
+ exports.logger = (0, pino_1.default)({
10
+ level: (_a = process.env.LOG_LEVEL) !== null && _a !== void 0 ? _a : 'info',
11
+ messageKey: 'message',
12
+ formatters: {
13
+ level(label) {
14
+ return { level: label };
15
+ },
16
+ },
17
+ });
@@ -0,0 +1,12 @@
1
+ import type * as Stuntman from '.';
2
+ export declare class RawHeaders extends Array<string> implements Stuntman.RawHeadersInterface {
3
+ get(name: string): string | undefined;
4
+ has(name: string, value?: string): boolean;
5
+ set(name: string, value: string): void;
6
+ add(name: string, value: string): void;
7
+ remove(name: string): void;
8
+ toHeaderPairs(): readonly [string, string][];
9
+ static fromHeaderPairs(headerPairs: [string, string][]): RawHeaders;
10
+ static fromHeadersRecord(headersRecord: Record<string, string | string[] | undefined>): RawHeaders;
11
+ static toHeaderPairs(rawHeaders: string[]): readonly [string, string][];
12
+ }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RawHeaders = void 0;
4
+ class RawHeaders extends Array {
5
+ get(name) {
6
+ const headers = this.toHeaderPairs();
7
+ const matchingHeaders = headers.filter((h) => h[0].toLowerCase() === name.toLowerCase());
8
+ if (matchingHeaders.length === 0) {
9
+ return;
10
+ }
11
+ if (matchingHeaders.length === 1) {
12
+ return matchingHeaders[0][1];
13
+ }
14
+ throw new Error('Multiple headers with same name. Manipulate rawHeaders instead');
15
+ }
16
+ has(name, value) {
17
+ const foundValue = this.get(name);
18
+ if (value === undefined) {
19
+ return foundValue !== undefined;
20
+ }
21
+ return foundValue === value;
22
+ }
23
+ set(name, value) {
24
+ let foundHeaders = 0;
25
+ for (let headerIndex = 0; headerIndex < this.length; headerIndex += 2) {
26
+ if (this[headerIndex].toLowerCase() === name.toLowerCase()) {
27
+ this[headerIndex + 1] = value;
28
+ ++foundHeaders;
29
+ }
30
+ }
31
+ if (foundHeaders === 0) {
32
+ return this.add(name, value);
33
+ }
34
+ if (foundHeaders > 1) {
35
+ throw new Error('Multiple headers with same name. Manipulate rawHeaders instead');
36
+ }
37
+ }
38
+ add(name, value) {
39
+ this.push(name);
40
+ this.push(value);
41
+ }
42
+ remove(name) {
43
+ const headersCopy = [...this];
44
+ let foundHeaders = 0;
45
+ for (let headerIndex = 0; headerIndex < headersCopy.length; headerIndex += 2) {
46
+ if (this[headerIndex - foundHeaders * 2].toLowerCase() === name.toLowerCase()) {
47
+ delete this[headerIndex];
48
+ delete this[headerIndex];
49
+ ++foundHeaders;
50
+ }
51
+ }
52
+ if (foundHeaders > 1) {
53
+ throw new Error('Multiple headers with same name. Manipulate rawHeaders instead');
54
+ }
55
+ }
56
+ toHeaderPairs() {
57
+ return RawHeaders.toHeaderPairs(this);
58
+ }
59
+ static fromHeaderPairs(headerPairs) {
60
+ return new RawHeaders(...headerPairs.flatMap((x) => x));
61
+ }
62
+ static fromHeadersRecord(headersRecord) {
63
+ const output = new RawHeaders();
64
+ for (const [key, value] of Object.entries(headersRecord)) {
65
+ if (typeof value === 'string' || value === undefined) {
66
+ output.add(key, value !== null && value !== void 0 ? value : '');
67
+ continue;
68
+ }
69
+ for (const subValue of value) {
70
+ output.add(key, subValue);
71
+ }
72
+ }
73
+ return output;
74
+ }
75
+ static toHeaderPairs(rawHeaders) {
76
+ const headers = new Array();
77
+ for (let headerIndex = 0; headerIndex < rawHeaders.length; headerIndex += 2) {
78
+ headers.push([rawHeaders[headerIndex], rawHeaders[headerIndex + 1]]);
79
+ }
80
+ return headers;
81
+ }
82
+ }
83
+ exports.RawHeaders = RawHeaders;
@@ -0,0 +1 @@
1
+ export declare const stringify: (obj: any) => string;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stringify = void 0;
4
+ const stringify = (obj) => JSON.stringify(obj, (key, value) => {
5
+ if (typeof value === 'function' || value instanceof RegExp) {
6
+ return value.toString();
7
+ }
8
+ return value;
9
+ });
10
+ exports.stringify = stringify;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stuntman/shared",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Stuntman - HTTP proxy / mock shared types and utils",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -36,10 +36,20 @@
36
36
  "pino": "8.10.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@types/config": "3.3.0"
39
+ "@jest/globals": "29.4.3",
40
+ "@types/config": "3.3.0",
41
+ "jest": "29.4.3",
42
+ "typescript": "4.9.5"
40
43
  },
44
+ "files": [
45
+ "src/**",
46
+ "dist/**",
47
+ "README.md",
48
+ "LICENSE",
49
+ "CHANGELOG.md"
50
+ ],
41
51
  "scripts": {
42
- "test": "echo \"Error: no test specified\" && exit 1",
52
+ "test": "SUPPRESS_NO_CONFIG_WARNING=1 jest",
43
53
  "clean": "rm -fr dist",
44
54
  "build": "tsc",
45
55
  "lint": "prettier --check . && eslint . --ext ts",
package/src/index.ts CHANGED
@@ -53,7 +53,7 @@ export type RemotableFunction<T extends Function> = {
53
53
 
54
54
  export type SerializedRemotableFunction = {
55
55
  localFn: string;
56
- variable?: string;
56
+ localVariables?: string;
57
57
  remoteFn: string;
58
58
  };
59
59
 
@@ -117,15 +117,29 @@ export type ResponseManipulationFn = (request: Request, response: Response) => R
117
117
  export type ResponseGenerationFn = (request: Request) => Response;
118
118
 
119
119
  export type Actions =
120
+ | {
121
+ proxyPass: true;
122
+ mockResponse?: undefined;
123
+ modifyRequest?: undefined;
124
+ modifyResponse?: undefined;
125
+ }
120
126
  | {
121
127
  mockResponse: Response | ResponseGenerationFn;
128
+ proxyPass?: undefined;
122
129
  modifyRequest?: undefined;
123
130
  modifyResponse?: undefined;
124
131
  }
125
132
  | {
133
+ modifyRequest: RequestManipulationFn;
134
+ modifyResponse?: ResponseManipulationFn;
135
+ proxyPass?: true | undefined;
126
136
  mockResponse?: undefined;
137
+ }
138
+ | {
127
139
  modifyRequest?: RequestManipulationFn;
128
- modifyResponse?: ResponseManipulationFn;
140
+ modifyResponse: ResponseManipulationFn;
141
+ proxyPass?: true | undefined;
142
+ mockResponse?: undefined;
129
143
  };
130
144
 
131
145
  export type Rule = {
@@ -133,7 +147,7 @@ export type Rule = {
133
147
  priority?: number;
134
148
  matches: RuleMatchFunction; // function for picking request to process
135
149
  labels?: string[]; // groupping req/res pairs for searching later e.g. ['exoclick', 'testId123']
136
- actions?: Actions;
150
+ actions: Actions;
137
151
  disableAfterUse?: boolean | number; // disable after rule is triggered n-times
138
152
  removeAfterUse?: boolean | number; // disable after rule is triggered n-times
139
153
  ttlSeconds: number;
@@ -186,6 +200,7 @@ export type MockConfig = {
186
200
  timeout: number;
187
201
  externalDns: string[];
188
202
  rulesPath: string;
203
+ disableProxy?: boolean;
189
204
  };
190
205
 
191
206
  export type StorageConfig = {
@@ -1 +0,0 @@
1
- // TODO
package/tsconfig.json DELETED
@@ -1,22 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2018",
4
- "module": "commonjs",
5
- "rootDir": "src",
6
- "declaration": true,
7
- "outDir": "dist",
8
- "esModuleInterop": true,
9
- "forceConsistentCasingInFileNames": true,
10
- "strict": true,
11
- "skipLibCheck": true,
12
- "typeRoots": ["node_modules/@types"],
13
- "allowJs": true,
14
- "moduleResolution": "node16",
15
- "types": ["node", "jest"]
16
- },
17
- "exclude": [
18
- "jest.config.js",
19
- "./dist/**",
20
- "./test/**"
21
- ]
22
- }