@stuntman/shared 0.1.0 → 0.1.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.
- package/README.md +3 -0
- package/dist/config.js +3 -2
- package/dist/index.d.ts +10 -0
- package/dist/rawHeaders.d.ts +1 -0
- package/dist/rawHeaders.js +13 -0
- package/package.json +5 -1
- package/src/config.ts +3 -2
- package/src/index.ts +13 -1
- package/src/rawHeaders.ts +14 -0
package/README.md
ADDED
package/dist/config.js
CHANGED
|
@@ -23,7 +23,7 @@ const defaultConfig = {
|
|
|
23
23
|
traffic: {
|
|
24
24
|
limitCount: _1.DEFAULT_CACHE_MAX_ENTRIES,
|
|
25
25
|
limitSize: _1.DEFAULT_CACHE_MAX_SIZE,
|
|
26
|
-
ttl: _1.DEFAULT_CACHE_TTL
|
|
26
|
+
ttl: _1.DEFAULT_CACHE_TTL,
|
|
27
27
|
},
|
|
28
28
|
},
|
|
29
29
|
webgui: {
|
|
@@ -35,6 +35,7 @@ try {
|
|
|
35
35
|
configFromFile = config_1.default.get('stuntman');
|
|
36
36
|
}
|
|
37
37
|
catch (error) {
|
|
38
|
-
|
|
38
|
+
// eslint-disable-next-line no-console
|
|
39
|
+
console.warn('unable to find correct config - starting with defaults');
|
|
39
40
|
}
|
|
40
41
|
exports.serverConfig = (0, defaults_1.default)(configFromFile, defaultConfig);
|
package/dist/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export type RuleMatchResult = boolean | {
|
|
|
28
28
|
result: boolean;
|
|
29
29
|
enableRuleIds?: string[];
|
|
30
30
|
disableRuleIds?: string[];
|
|
31
|
+
description?: string;
|
|
31
32
|
};
|
|
32
33
|
export type RemotableFunction<T extends Function> = {
|
|
33
34
|
localFn: T;
|
|
@@ -151,3 +152,12 @@ export type ServerConfig = {
|
|
|
151
152
|
traffic: StorageConfig;
|
|
152
153
|
};
|
|
153
154
|
};
|
|
155
|
+
export interface RuleExecutorInterface {
|
|
156
|
+
addRule: (rule: Rule, overwrite?: boolean) => Promise<LiveRule>;
|
|
157
|
+
removeRule: (id: string) => Promise<void>;
|
|
158
|
+
enableRule: (id: string) => void;
|
|
159
|
+
disableRule: (id: string) => void;
|
|
160
|
+
findMatchingRule: (request: Request) => Promise<LiveRule | null>;
|
|
161
|
+
getRules: () => Promise<readonly LiveRule[]>;
|
|
162
|
+
getRule: (id: string) => Promise<LiveRule | undefined>;
|
|
163
|
+
}
|
package/dist/rawHeaders.d.ts
CHANGED
|
@@ -7,5 +7,6 @@ export declare class RawHeaders extends Array<string> implements Stuntman.RawHea
|
|
|
7
7
|
remove(name: string): void;
|
|
8
8
|
toHeaderPairs(): readonly [string, string][];
|
|
9
9
|
static fromHeaderPairs(headerPairs: [string, string][]): RawHeaders;
|
|
10
|
+
static fromHeadersRecord(headersRecord: Record<string, string | string[] | undefined>): RawHeaders;
|
|
10
11
|
static toHeaderPairs(rawHeaders: string[]): readonly [string, string][];
|
|
11
12
|
}
|
package/dist/rawHeaders.js
CHANGED
|
@@ -59,6 +59,19 @@ class RawHeaders extends Array {
|
|
|
59
59
|
static fromHeaderPairs(headerPairs) {
|
|
60
60
|
return new RawHeaders(...headerPairs.flatMap((x) => x));
|
|
61
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
|
+
}
|
|
62
75
|
static toHeaderPairs(rawHeaders) {
|
|
63
76
|
const headers = new Array();
|
|
64
77
|
for (let headerIndex = 0; headerIndex < rawHeaders.length; headerIndex += 2) {
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stuntman/shared",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Stuntman - HTTP proxy / mock shared types and utils",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/andrzej-woof/stuntman.git"
|
|
9
9
|
},
|
|
10
|
+
"homepage": "https://github.com/andrzej-woof/stuntman#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/andrzej-woof/stuntman/issues"
|
|
13
|
+
},
|
|
10
14
|
"keywords": [
|
|
11
15
|
"proxy",
|
|
12
16
|
"mock",
|
package/src/config.ts
CHANGED
|
@@ -30,7 +30,7 @@ const defaultConfig: ServerConfig = {
|
|
|
30
30
|
traffic: {
|
|
31
31
|
limitCount: DEFAULT_CACHE_MAX_ENTRIES,
|
|
32
32
|
limitSize: DEFAULT_CACHE_MAX_SIZE,
|
|
33
|
-
ttl: DEFAULT_CACHE_TTL
|
|
33
|
+
ttl: DEFAULT_CACHE_TTL,
|
|
34
34
|
},
|
|
35
35
|
},
|
|
36
36
|
webgui: {
|
|
@@ -42,7 +42,8 @@ let configFromFile: RecursivePartial<ServerConfig> = {};
|
|
|
42
42
|
try {
|
|
43
43
|
configFromFile = config.get<RecursivePartial<ServerConfig>>('stuntman');
|
|
44
44
|
} catch (error) {
|
|
45
|
-
|
|
45
|
+
// eslint-disable-next-line no-console
|
|
46
|
+
console.warn('unable to find correct config - starting with defaults');
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
export const serverConfig = defaults(configFromFile, defaultConfig) as ServerConfig;
|
package/src/index.ts
CHANGED
|
@@ -42,7 +42,9 @@ export enum HttpCode {
|
|
|
42
42
|
|
|
43
43
|
export type LocalVariables = Record<string, SerializableTypes>;
|
|
44
44
|
|
|
45
|
-
export type RuleMatchResult =
|
|
45
|
+
export type RuleMatchResult =
|
|
46
|
+
| boolean
|
|
47
|
+
| { result: boolean; enableRuleIds?: string[]; disableRuleIds?: string[]; description?: string };
|
|
46
48
|
|
|
47
49
|
export type RemotableFunction<T extends Function> = {
|
|
48
50
|
localFn: T;
|
|
@@ -197,3 +199,13 @@ export type ServerConfig = {
|
|
|
197
199
|
traffic: StorageConfig;
|
|
198
200
|
};
|
|
199
201
|
};
|
|
202
|
+
|
|
203
|
+
export interface RuleExecutorInterface {
|
|
204
|
+
addRule: (rule: Rule, overwrite?: boolean) => Promise<LiveRule>;
|
|
205
|
+
removeRule: (id: string) => Promise<void>;
|
|
206
|
+
enableRule: (id: string) => void;
|
|
207
|
+
disableRule: (id: string) => void;
|
|
208
|
+
findMatchingRule: (request: Request) => Promise<LiveRule | null>;
|
|
209
|
+
getRules: () => Promise<readonly LiveRule[]>;
|
|
210
|
+
getRule: (id: string) => Promise<LiveRule | undefined>;
|
|
211
|
+
}
|
package/src/rawHeaders.ts
CHANGED
|
@@ -65,6 +65,20 @@ export class RawHeaders extends Array<string> implements Stuntman.RawHeadersInte
|
|
|
65
65
|
return new RawHeaders(...headerPairs.flatMap((x) => x));
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
static fromHeadersRecord(headersRecord: Record<string, string | string[] | undefined>): RawHeaders {
|
|
69
|
+
const output = new RawHeaders();
|
|
70
|
+
for (const [key, value] of Object.entries(headersRecord)) {
|
|
71
|
+
if (typeof value === 'string' || value === undefined) {
|
|
72
|
+
output.add(key, value ?? '');
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
for (const subValue of value) {
|
|
76
|
+
output.add(key, subValue);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return output;
|
|
80
|
+
}
|
|
81
|
+
|
|
68
82
|
static toHeaderPairs(rawHeaders: string[]): readonly [string, string][] {
|
|
69
83
|
const headers = new Array<[string, string]>();
|
|
70
84
|
for (let headerIndex = 0; headerIndex < rawHeaders.length; headerIndex += 2) {
|