hookdesk 0.1.0 → 0.2.0
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/CHANGELOG.md +53 -0
- package/README.md +225 -43
- package/config/app.json +198 -0
- package/config/default.json +9 -0
- package/config/limits.json +40 -0
- package/config/messages.json +193 -0
- package/package.json +6 -5
- package/src/cli.js +24 -0
- package/src/loader/fixed.js +18 -0
- package/src/loader/settings.js +94 -0
- package/src/mocks/rules.js +95 -0
- package/src/server.js +161 -97
- package/src/store/events.js +34 -0
- package/src/ui/index.html +83 -0
- package/src/{ui.css → ui/ui.css} +32 -2
- package/src/ui/ui.js +419 -0
- package/src/config.js +0 -71
- package/src/ui.html +0 -66
- package/src/ui.js +0 -323
- package/src/wordmark.svg +0 -13
- /package/src/{logo.svg → ui/logo.svg} +0 -0
package/config/app.json
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "HookDesk Mini",
|
|
3
|
+
"headers": {
|
|
4
|
+
"contentType": "content-type",
|
|
5
|
+
"replay": "x-hookdesk-replay",
|
|
6
|
+
"eventId": "x-hookdesk-event-id"
|
|
7
|
+
},
|
|
8
|
+
"contentTypes": {
|
|
9
|
+
"json": "application/json; charset=utf-8",
|
|
10
|
+
"text": "text/plain; charset=utf-8"
|
|
11
|
+
},
|
|
12
|
+
"responseHeaders": {
|
|
13
|
+
"defaults": {
|
|
14
|
+
"cache-control": "no-store"
|
|
15
|
+
},
|
|
16
|
+
"always": {
|
|
17
|
+
"x-content-type-options": "nosniff"
|
|
18
|
+
},
|
|
19
|
+
"onPayloadTooLarge": {
|
|
20
|
+
"connection": "close"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"methods": {
|
|
24
|
+
"get": "GET",
|
|
25
|
+
"head": "HEAD",
|
|
26
|
+
"post": "POST",
|
|
27
|
+
"delete": "DELETE"
|
|
28
|
+
},
|
|
29
|
+
"methodsWithoutBody": [
|
|
30
|
+
"GET",
|
|
31
|
+
"HEAD"
|
|
32
|
+
],
|
|
33
|
+
"status": {
|
|
34
|
+
"ok": 200,
|
|
35
|
+
"created": 201,
|
|
36
|
+
"badRequest": 400,
|
|
37
|
+
"forbidden": 403,
|
|
38
|
+
"notFound": 404,
|
|
39
|
+
"timeout": 408,
|
|
40
|
+
"conflict": 409,
|
|
41
|
+
"payloadTooLarge": 413,
|
|
42
|
+
"unsupportedMediaType": 415,
|
|
43
|
+
"serverError": 500,
|
|
44
|
+
"badGateway": 502
|
|
45
|
+
},
|
|
46
|
+
"routes": {
|
|
47
|
+
"config": "/api/config",
|
|
48
|
+
"events": "/api/events",
|
|
49
|
+
"wait": "/api/events/wait",
|
|
50
|
+
"export": "/api/events/export",
|
|
51
|
+
"event": "/api/events/{id}",
|
|
52
|
+
"replay": "/api/events/{id}/replay",
|
|
53
|
+
"mocks": "/api/mocks",
|
|
54
|
+
"mock": "/api/mocks/{id}"
|
|
55
|
+
},
|
|
56
|
+
"query": {
|
|
57
|
+
"method": "method",
|
|
58
|
+
"path": "path",
|
|
59
|
+
"since": "since",
|
|
60
|
+
"timeout": "timeout"
|
|
61
|
+
},
|
|
62
|
+
"uiDirectory": "ui",
|
|
63
|
+
"packageFile": "../package.json",
|
|
64
|
+
"security": {
|
|
65
|
+
"dashboardHeaders": {
|
|
66
|
+
"x-frame-options": "DENY",
|
|
67
|
+
"content-security-policy": "default-src 'self'; script-src 'self'; style-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'none'"
|
|
68
|
+
},
|
|
69
|
+
"mockHeaders": {
|
|
70
|
+
"content-security-policy": "sandbox"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"staticFiles": {
|
|
74
|
+
"page": {
|
|
75
|
+
"path": "/",
|
|
76
|
+
"file": "index.html",
|
|
77
|
+
"type": "text/html; charset=utf-8",
|
|
78
|
+
"dashboard": true,
|
|
79
|
+
"template": true
|
|
80
|
+
},
|
|
81
|
+
"script": {
|
|
82
|
+
"path": "/ui.js",
|
|
83
|
+
"file": "ui.js",
|
|
84
|
+
"type": "text/javascript; charset=utf-8"
|
|
85
|
+
},
|
|
86
|
+
"styles": {
|
|
87
|
+
"path": "/ui.css",
|
|
88
|
+
"file": "ui.css",
|
|
89
|
+
"type": "text/css; charset=utf-8"
|
|
90
|
+
},
|
|
91
|
+
"logo": {
|
|
92
|
+
"path": "/logo.svg",
|
|
93
|
+
"file": "logo.svg",
|
|
94
|
+
"type": "image/svg+xml"
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"defaultResponse": {
|
|
98
|
+
"status": 200,
|
|
99
|
+
"body": {
|
|
100
|
+
"received": true
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
"mocks": {
|
|
104
|
+
"anyMethod": "*",
|
|
105
|
+
"prefixSuffix": "/*",
|
|
106
|
+
"ruleDefaults": {
|
|
107
|
+
"status": 200,
|
|
108
|
+
"delayMs": 0
|
|
109
|
+
},
|
|
110
|
+
"configRuleIdPrefix": "config-",
|
|
111
|
+
"generatedIdLength": 8
|
|
112
|
+
},
|
|
113
|
+
"export": {
|
|
114
|
+
"tool": "hookdesk",
|
|
115
|
+
"fileName": "hookdesk-export-{time}.json",
|
|
116
|
+
"headers": {
|
|
117
|
+
"content-disposition": "attachment; filename=\"{fileName}\""
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
"cli": {
|
|
121
|
+
"examplePath": "/demo",
|
|
122
|
+
"exampleContentType": "application/json",
|
|
123
|
+
"exampleBody": "{\"event\":\"hello\"}"
|
|
124
|
+
},
|
|
125
|
+
"ui": {
|
|
126
|
+
"methods": [
|
|
127
|
+
"GET",
|
|
128
|
+
"POST",
|
|
129
|
+
"PUT",
|
|
130
|
+
"PATCH",
|
|
131
|
+
"DELETE"
|
|
132
|
+
],
|
|
133
|
+
"mockMethods": [
|
|
134
|
+
"*",
|
|
135
|
+
"GET",
|
|
136
|
+
"POST",
|
|
137
|
+
"PUT",
|
|
138
|
+
"PATCH",
|
|
139
|
+
"DELETE",
|
|
140
|
+
"HEAD",
|
|
141
|
+
"OPTIONS"
|
|
142
|
+
],
|
|
143
|
+
"themeStorageKey": "hookdesk-theme",
|
|
144
|
+
"retryMs": 3000,
|
|
145
|
+
"toastMs": 2200,
|
|
146
|
+
"flashMs": 1400,
|
|
147
|
+
"rateWindowMs": 60000,
|
|
148
|
+
"errorStatusFrom": 400,
|
|
149
|
+
"shortIdLength": 8,
|
|
150
|
+
"ageTickMs": 1000,
|
|
151
|
+
"keys": {
|
|
152
|
+
"next": [
|
|
153
|
+
"j",
|
|
154
|
+
"ArrowDown"
|
|
155
|
+
],
|
|
156
|
+
"previous": [
|
|
157
|
+
"k",
|
|
158
|
+
"ArrowUp"
|
|
159
|
+
],
|
|
160
|
+
"replay": [
|
|
161
|
+
"r"
|
|
162
|
+
],
|
|
163
|
+
"copyCurl": [
|
|
164
|
+
"c"
|
|
165
|
+
]
|
|
166
|
+
},
|
|
167
|
+
"timeline": {
|
|
168
|
+
"gridDash": [
|
|
169
|
+
2,
|
|
170
|
+
4
|
|
171
|
+
],
|
|
172
|
+
"gridRows": 3,
|
|
173
|
+
"selectionDash": [
|
|
174
|
+
3,
|
|
175
|
+
3
|
|
176
|
+
],
|
|
177
|
+
"selectionAlpha": 0.35,
|
|
178
|
+
"idleAlpha": 0.7,
|
|
179
|
+
"lineWidth": 1,
|
|
180
|
+
"spikeWidthPx": 1,
|
|
181
|
+
"selectedSpikeWidthPx": 2,
|
|
182
|
+
"pulseLineWidth": 1.5,
|
|
183
|
+
"labelTopPx": 2,
|
|
184
|
+
"divisions": 5,
|
|
185
|
+
"redrawMs": 250,
|
|
186
|
+
"hoverRadiusPx": 8,
|
|
187
|
+
"minSpikePx": 8,
|
|
188
|
+
"topPaddingPx": 22,
|
|
189
|
+
"dotRadiusPx": 2.5,
|
|
190
|
+
"selectedDotRadiusPx": 3.5,
|
|
191
|
+
"pulseGrowPx": 18,
|
|
192
|
+
"labelHeightPx": 22,
|
|
193
|
+
"labelPaddingPx": 8,
|
|
194
|
+
"labelFontPx": 11
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
"scheme": "http"
|
|
198
|
+
}
|
package/config/default.json
CHANGED
|
@@ -39,6 +39,15 @@
|
|
|
39
39
|
"x-auth-token"
|
|
40
40
|
]
|
|
41
41
|
},
|
|
42
|
+
"mocks": {
|
|
43
|
+
"maxDelayMs": 30000,
|
|
44
|
+
"maxRules": 100,
|
|
45
|
+
"rules": []
|
|
46
|
+
},
|
|
47
|
+
"wait": {
|
|
48
|
+
"defaultTimeoutMs": 10000,
|
|
49
|
+
"maxTimeoutMs": 60000
|
|
50
|
+
},
|
|
42
51
|
"ui": {
|
|
43
52
|
"pollIntervalMs": 1500,
|
|
44
53
|
"timelineWindowMs": 300000,
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"server": {
|
|
3
|
+
"loopbackHosts": ["127.0.0.1", "localhost", "::1"],
|
|
4
|
+
"loopbackHostnames": ["127.0.0.1", "localhost", "[::1]"],
|
|
5
|
+
"port": { "min": 0, "max": 65535 },
|
|
6
|
+
"hostHeaderPattern": "^[A-Za-z0-9.:\\[\\]-]+$"
|
|
7
|
+
},
|
|
8
|
+
"capture": {
|
|
9
|
+
"pathPrefixPattern": "^/[A-Za-z0-9._~-]+(/[A-Za-z0-9._~-]+)*$",
|
|
10
|
+
"reservedPathPattern": "^/(api|ui\\.)",
|
|
11
|
+
"maxBodyBytes": { "min": 1, "max": 104857600 },
|
|
12
|
+
"maxEvents": { "min": 1, "max": 100000 }
|
|
13
|
+
},
|
|
14
|
+
"replay": {
|
|
15
|
+
"timeoutMs": { "min": 100, "max": 60000 }
|
|
16
|
+
},
|
|
17
|
+
"mocks": {
|
|
18
|
+
"maxDelayMs": { "min": 0, "max": 600000 },
|
|
19
|
+
"maxRules": { "min": 1, "max": 10000 },
|
|
20
|
+
"status": { "min": 200, "max": 599 },
|
|
21
|
+
"statusWithoutBody": [204, 304],
|
|
22
|
+
"ruleKeys": ["id", "method", "path", "status", "headers", "body", "delayMs"],
|
|
23
|
+
"apiContentTypePattern":"^application/json(\\s*;|$)",
|
|
24
|
+
"methodPattern":"^(\\*|[A-Z]+)$",
|
|
25
|
+
"idPattern":"^[A-Za-z0-9._-]{1,64}$",
|
|
26
|
+
"pathPattern": "^/[^\\s?#*]*$",
|
|
27
|
+
"headerValueForbiddenPattern": "[\\r\\n]",
|
|
28
|
+
"headerNamePattern":"^[!#$%&'*+.^_`|~0-9A-Za-z-]+$",
|
|
29
|
+
"reservedHeaders": ["content-length", "transfer-encoding", "connection", "keep-alive", "upgrade", "trailer"]
|
|
30
|
+
},
|
|
31
|
+
"wait": {
|
|
32
|
+
"maxTimeoutMs": { "min": 1000, "max": 600000 },
|
|
33
|
+
"defaultTimeoutMs": { "min": 0, "max": 600000 }
|
|
34
|
+
},
|
|
35
|
+
"ui": {
|
|
36
|
+
"pollIntervalMs": { "min": 250, "max": 60000 },
|
|
37
|
+
"timelineWindowMs": { "min": 10000, "max": 86400000 },
|
|
38
|
+
"themes": ["auto", "light", "dark"]
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cli": {
|
|
3
|
+
"running": "{name} is running",
|
|
4
|
+
"dashboard": "Dashboard: {url}",
|
|
5
|
+
"webhook": "Webhook: {url}",
|
|
6
|
+
"mocksOne": "Mocks: {count} rule from config",
|
|
7
|
+
"mocksMany": "Mocks: {count} rules from config",
|
|
8
|
+
"mocksNone": "Mocks: none, every request gets {status} {body}",
|
|
9
|
+
"example": "Example: {command}",
|
|
10
|
+
"exampleCommand": "curl -X POST {url} -H 'Content-Type: {contentType}' -d '{body}'",
|
|
11
|
+
"cannotStart": "Cannot start {name}: {reason}"
|
|
12
|
+
},
|
|
13
|
+
"api": {
|
|
14
|
+
"onlyLocalhost": "Only localhost is allowed",
|
|
15
|
+
"crossOrigin": "Cross-origin requests are blocked",
|
|
16
|
+
"invalidOrigin": "Invalid origin",
|
|
17
|
+
"notFound": "Not found",
|
|
18
|
+
"eventNotFound": "Event not found",
|
|
19
|
+
"ruleNotFound": "Rule not found",
|
|
20
|
+
"internalError": "Internal server error",
|
|
21
|
+
"payloadTooLarge": "Payload exceeds {limit} bytes",
|
|
22
|
+
"pathMustStartWithSlash": "path must start with \"/\"",
|
|
23
|
+
"sinceInvalid": "since must be an ISO 8601 timestamp",
|
|
24
|
+
"timeoutInvalid": "timeout must be an integer {range} (wait.maxTimeoutMs)",
|
|
25
|
+
"waitTimedOut": "No matching request within {timeout} ms",
|
|
26
|
+
"contentTypeJson": "Content-Type must be application/json",
|
|
27
|
+
"bodyInvalidJson": "Body must be valid JSON",
|
|
28
|
+
"replayBlocked": "{method} requests cannot be replayed",
|
|
29
|
+
"replayFailed": "Replay failed: {reason}",
|
|
30
|
+
"ruleLimit": "Rule limit reached (mocks.maxRules = {max})",
|
|
31
|
+
"ruleDuplicate": "A rule with id \"{id}\" already exists"
|
|
32
|
+
},
|
|
33
|
+
"config": {
|
|
34
|
+
"cannotRead": "Cannot read config file {path}: {reason}",
|
|
35
|
+
"unknownSection": "Unknown config section \"{section}\"",
|
|
36
|
+
"sectionNotObject": "Config section \"{section}\" must be an object",
|
|
37
|
+
"unknownKey": "Unknown config key \"{section}.{key}\"",
|
|
38
|
+
"invalid": "Invalid configuration:\n - {errors}",
|
|
39
|
+
"errorSeparator": "\n - ",
|
|
40
|
+
"range": "{key} must be an integer {range}",
|
|
41
|
+
"loopbackHost": "server.host must be a loopback address ({hosts})",
|
|
42
|
+
"allowedHostnames": "server.allowedHostnames must be a non-empty list of {hosts}",
|
|
43
|
+
"allowedHostnamesIncludeHost": "server.allowedHostnames must include server.host",
|
|
44
|
+
"pathPrefix": "capture.pathPrefix must look like \"/hook\" (no trailing slash, not under /api)",
|
|
45
|
+
"stringList": "{key} must be a list of names",
|
|
46
|
+
"placeholder": "redaction.placeholder must be a non-empty string",
|
|
47
|
+
"rulesList": "mocks.rules must be a list of rules",
|
|
48
|
+
"rulesOverLimit": "mocks.rules has more rules than mocks.maxRules",
|
|
49
|
+
"ruleIdsUnique": "mocks.rules ids must be unique",
|
|
50
|
+
"waitDefaultOverMax": "wait.defaultTimeoutMs must not exceed wait.maxTimeoutMs",
|
|
51
|
+
"theme": "ui.defaultTheme must be one of {themes}",
|
|
52
|
+
"listSeparator": ", "
|
|
53
|
+
},
|
|
54
|
+
"rules": {
|
|
55
|
+
"defaultLabel": "rule",
|
|
56
|
+
"configLabel": "mocks.rules[{index}]",
|
|
57
|
+
"notObject": "{label} must be an object",
|
|
58
|
+
"unknownKey": "{label}: unknown key \"{key}\"",
|
|
59
|
+
"id": "{label}.id must match {pattern}",
|
|
60
|
+
"method": "{label}.method must be \"{any}\" or an HTTP method name",
|
|
61
|
+
"path": "{label}.path must be {prefix} or a path under it, optionally ending in \"{suffix}\" (no query string)",
|
|
62
|
+
"status": "{label}.status must be an integer {range}",
|
|
63
|
+
"delay": "{label}.delayMs must be an integer {range} (mocks.maxDelayMs)",
|
|
64
|
+
"headersObject": "{label}.headers must be an object of header names to string values",
|
|
65
|
+
"headerName": "{label}.headers: invalid header name \"{name}\"",
|
|
66
|
+
"headerReserved": "{label}.headers: \"{name}\" is set by the server and cannot be mocked",
|
|
67
|
+
"headerValue": "{label}.headers[\"{name}\"] must be a single-line string",
|
|
68
|
+
"statusWithoutBody": "{label}: status {status} cannot have a body",
|
|
69
|
+
"separator": "\n"
|
|
70
|
+
},
|
|
71
|
+
"ui": {
|
|
72
|
+
"live": "Live",
|
|
73
|
+
"offline": "Offline",
|
|
74
|
+
"reconnected": "Reconnected to local server",
|
|
75
|
+
"unreachable": "Cannot reach local server",
|
|
76
|
+
"clipboardUnavailable": "Clipboard unavailable",
|
|
77
|
+
"httpStatus": "HTTP {status}",
|
|
78
|
+
"byte": "byte",
|
|
79
|
+
"bytes": "bytes",
|
|
80
|
+
"kilobytes": "KB",
|
|
81
|
+
"megabytes": "MB",
|
|
82
|
+
"exactBytes": "{count} bytes",
|
|
83
|
+
"seconds": "{value}s",
|
|
84
|
+
"minutes": "{value}m",
|
|
85
|
+
"hours": "{value}h",
|
|
86
|
+
"ago": "ago",
|
|
87
|
+
"none": "none",
|
|
88
|
+
"now": "now",
|
|
89
|
+
"noRequests": "No requests yet.",
|
|
90
|
+
"replayMark": "replay",
|
|
91
|
+
"mockMark": "mock",
|
|
92
|
+
"waitingTitle": "Waiting for the first request",
|
|
93
|
+
"waitingText": "Send any HTTP method to {endpoint}/anything. It shows up here and on the timeline the moment it lands.",
|
|
94
|
+
"copyCurl": "Copy curl",
|
|
95
|
+
"curlCopied": "curl copied",
|
|
96
|
+
"curlCopiedWarning": "curl copied. Check for secrets before sharing.",
|
|
97
|
+
"endpointCopied": "Endpoint copied",
|
|
98
|
+
"selectRequest": "Select a request.",
|
|
99
|
+
"replayOf": "replay of {id}",
|
|
100
|
+
"replayLocally": "Replay locally",
|
|
101
|
+
"copyAsCurl": "Copy as curl",
|
|
102
|
+
"tabBody": "Body",
|
|
103
|
+
"tabHeaders": "Headers",
|
|
104
|
+
"tabResponse": "Response",
|
|
105
|
+
"tabCurl": "cURL",
|
|
106
|
+
"emptyBody": "Empty body.",
|
|
107
|
+
"noContentType": "no content-type",
|
|
108
|
+
"formatted": " / formatted",
|
|
109
|
+
"redactedNote": "Sensitive header values are redacted.",
|
|
110
|
+
"responseStatus": "status",
|
|
111
|
+
"responseAnsweredBy": "answered by",
|
|
112
|
+
"responseDelay": "delay",
|
|
113
|
+
"answeredByRule": "mock rule {id} ({path})",
|
|
114
|
+
"answeredByDefault": "default response",
|
|
115
|
+
"milliseconds": "{value} ms",
|
|
116
|
+
"responseNote": "What the sender received for this request.",
|
|
117
|
+
"curlNote": "Redacted headers are left out. The body may still contain secrets.",
|
|
118
|
+
"cannotLoadRequest": "Cannot load request: {reason}",
|
|
119
|
+
"replayed": "Replayed locally / HTTP {status}",
|
|
120
|
+
"replayFailed": "Replay failed: {reason}",
|
|
121
|
+
"rulesOne": "{count} rule",
|
|
122
|
+
"rulesMany": "{count} rules",
|
|
123
|
+
"noRules": "No rules. Every request gets the default response.",
|
|
124
|
+
"remove": "Remove",
|
|
125
|
+
"cannotRemoveRule": "Cannot remove rule: {reason}",
|
|
126
|
+
"headersNotJson": "Headers must be a JSON object",
|
|
127
|
+
"ruleAdded": "Mock rule added",
|
|
128
|
+
"cannotAddRule": "Cannot add rule: {reason}",
|
|
129
|
+
"confirmClear": "Clear all captured requests?",
|
|
130
|
+
"clearFailed": "Clear failed: {reason}",
|
|
131
|
+
"confirmRemoveRules": "Remove all mock rules?",
|
|
132
|
+
"cannotRemoveRules": "Cannot remove rules: {reason}",
|
|
133
|
+
"hoverLabel": "{method} {path} {status} {size} {age} ago",
|
|
134
|
+
"themes": { "auto": "Auto", "light": "Light", "dark": "Dark" },
|
|
135
|
+
"otherMethods": "other"
|
|
136
|
+
},
|
|
137
|
+
"html": {
|
|
138
|
+
"brandName": "hookdesk",
|
|
139
|
+
"brandTag": "mini",
|
|
140
|
+
"version": "version",
|
|
141
|
+
"host": "host",
|
|
142
|
+
"buffer": "buffer",
|
|
143
|
+
"requestsShort": "req",
|
|
144
|
+
"storage": "storage",
|
|
145
|
+
"memory": "memory",
|
|
146
|
+
"liveTitle": "Whether the dashboard can reach the local server",
|
|
147
|
+
"themeGroup": "Color theme",
|
|
148
|
+
"captured": "Captured",
|
|
149
|
+
"capturedNote": "requests held in memory",
|
|
150
|
+
"last": "Last",
|
|
151
|
+
"rateNote": "requests in that time",
|
|
152
|
+
"lastHit": "Last hit",
|
|
153
|
+
"lastHitNote": "since the newest request",
|
|
154
|
+
"inMemory": "In memory",
|
|
155
|
+
"inMemoryNote": "total size of all bodies",
|
|
156
|
+
"activity": "Activity, last",
|
|
157
|
+
"activityHelp": "Each spike is one request. Taller means a bigger body. Hover to preview, click to open.",
|
|
158
|
+
"timelineLabel": "Request activity timeline",
|
|
159
|
+
"sendTest": "Send a test",
|
|
160
|
+
"commandTitle": "Run this in a terminal to send a test webhook",
|
|
161
|
+
"copyEndpoint": "Copy endpoint",
|
|
162
|
+
"copyEndpointTitle": "Copy the base URL to paste into your webhook provider or app",
|
|
163
|
+
"copyCurl": "Copy curl",
|
|
164
|
+
"copyCurlTitle": "Copy the test command on the left",
|
|
165
|
+
"export": "Export",
|
|
166
|
+
"exportTitle": "Download all captured requests and their responses as JSON",
|
|
167
|
+
"refresh": "Refresh",
|
|
168
|
+
"refreshTitle": "Reload the request list now",
|
|
169
|
+
"clear": "Clear",
|
|
170
|
+
"clearTitle": "Delete all captured requests",
|
|
171
|
+
"mockResponses": "Mock responses",
|
|
172
|
+
"mocksHint": "Rules decide what the sender gets back. The first matching rule answers; newest rules come first.",
|
|
173
|
+
"formMethod": "Method",
|
|
174
|
+
"formPath": "Path, or a prefix ending in",
|
|
175
|
+
"formStatus": "Status",
|
|
176
|
+
"formDelay": "Delay ms",
|
|
177
|
+
"formHeaders": "Headers (JSON object, optional)",
|
|
178
|
+
"formBody": "Body (optional)",
|
|
179
|
+
"addRule": "Add rule",
|
|
180
|
+
"removeAllRules": "Remove all rules",
|
|
181
|
+
"requests": "Requests",
|
|
182
|
+
"newestFirst": "newest first",
|
|
183
|
+
"navigate": "navigate",
|
|
184
|
+
"columnMethod": "Method",
|
|
185
|
+
"columnPath": "Path",
|
|
186
|
+
"columnStatus": "Status",
|
|
187
|
+
"columnSize": "Size",
|
|
188
|
+
"columnAge": "Age",
|
|
189
|
+
"footer": "Local only. Bodies are shown as received and may contain secrets.",
|
|
190
|
+
"replay": "replay",
|
|
191
|
+
"copyCurlKey": "copy curl"
|
|
192
|
+
}
|
|
193
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hookdesk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Local-only webhook inspector: capture, inspect, and replay HTTP requests in a live browser dashboard",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webhook",
|
|
@@ -25,21 +25,22 @@
|
|
|
25
25
|
},
|
|
26
26
|
"type": "module",
|
|
27
27
|
"bin": {
|
|
28
|
-
"hookdesk": "./src/
|
|
28
|
+
"hookdesk": "./src/cli.js"
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
31
31
|
"src",
|
|
32
32
|
"config",
|
|
33
33
|
"README.md",
|
|
34
|
+
"CHANGELOG.md",
|
|
34
35
|
"LICENSE"
|
|
35
36
|
],
|
|
36
37
|
"scripts": {
|
|
37
|
-
"start": "node src/
|
|
38
|
-
"dev": "node --watch src/
|
|
38
|
+
"start": "node src/cli.js",
|
|
39
|
+
"dev": "node --watch src/cli.js",
|
|
39
40
|
"test": "node --test"
|
|
40
41
|
},
|
|
41
42
|
"engines": {
|
|
42
|
-
"node": ">=
|
|
43
|
+
"node": ">=26"
|
|
43
44
|
},
|
|
44
45
|
"license": "MIT"
|
|
45
46
|
}
|
package/src/cli.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { app, messages, format, urlHost } from './loader/fixed.js';
|
|
3
|
+
import { loadConfig } from './loader/settings.js';
|
|
4
|
+
import { createApp } from './server.js';
|
|
5
|
+
|
|
6
|
+
const M = messages.cli;
|
|
7
|
+
const argValue = name => process.argv.find(x => x.startsWith(`--${name}=`))?.slice(name.length + 3);
|
|
8
|
+
|
|
9
|
+
const port = argValue('port') ?? process.env.PORT;
|
|
10
|
+
let config;
|
|
11
|
+
try { config = loadConfig({ file: argValue('config'), overrides: port === undefined ? undefined : { server: { port: Number(port) } } }); }
|
|
12
|
+
catch (error) { console.error(error.message); process.exit(1); }
|
|
13
|
+
|
|
14
|
+
const { server } = createApp({ config });
|
|
15
|
+
server.on('error', error => { console.error(format(M.cannotStart, { name: app.name, reason: error.message })); process.exit(1); });
|
|
16
|
+
server.listen(config.server.port, config.server.host, () => {
|
|
17
|
+
const base = `${app.scheme}://${urlHost(config.server.host)}:${server.address().port}`;
|
|
18
|
+
const webhook = `${base}${config.capture.pathPrefix}`;
|
|
19
|
+
const count = config.mocks.rules.length;
|
|
20
|
+
const mocks = count ? format(count === 1 ? M.mocksOne : M.mocksMany, { count }) : format(M.mocksNone, { status: app.defaultResponse.status, body: JSON.stringify(app.defaultResponse.body) });
|
|
21
|
+
const command = format(M.exampleCommand, { url: `${webhook}${app.cli.examplePath}`, contentType: app.cli.exampleContentType, body: app.cli.exampleBody });
|
|
22
|
+
const lines = [format(M.running, { name: app.name }), format(M.dashboard, { url: base }), format(M.webhook, { url: webhook }), mocks, format(M.example, { command })];
|
|
23
|
+
console.log(`\n${lines.map(line => ` ${line}`).join('\n')}\n`);
|
|
24
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
|
|
3
|
+
// Fixed values live in JSON, not in code: config/limits.json holds validation bounds,
|
|
4
|
+
// config/app.json holds names, routes, status codes, headers, and UI constants,
|
|
5
|
+
// config/messages.json holds every text the CLI, API, and dashboard show.
|
|
6
|
+
const readJson = name => JSON.parse(readFileSync(new URL(`../../config/${name}`, import.meta.url), 'utf8'));
|
|
7
|
+
export const limits = readJson('limits.json');
|
|
8
|
+
export const app = readJson('app.json');
|
|
9
|
+
export const messages = readJson('messages.json');
|
|
10
|
+
|
|
11
|
+
export const inRange = (value, { min, max }) => Number.isInteger(value) && value >= min && value <= max;
|
|
12
|
+
export const rangeText = ({ min, max }) => `${min}..${max}`;
|
|
13
|
+
// IPv6 addresses need brackets inside a URL or Host header.
|
|
14
|
+
export const urlHost = host => host.includes(':') ? `[${host}]` : host;
|
|
15
|
+
// Fills {name} placeholders in a message or route template.
|
|
16
|
+
export const format = (template, values = {}) => template.replace(/\{(\w+)\}/g, (match, key) => key in values ? String(values[key]) : match);
|
|
17
|
+
// Error carrying an HTTP status from config/app.json.
|
|
18
|
+
export const httpError = (status, message) => Object.assign(new Error(message), { status });
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { parseRule } from '../mocks/rules.js';
|
|
4
|
+
import { app, limits, messages, format, inRange, rangeText, urlHost } from './fixed.js';
|
|
5
|
+
|
|
6
|
+
const M = messages.config;
|
|
7
|
+
export const defaultConfigPath = fileURLToPath(new URL('../../config/default.json', import.meta.url));
|
|
8
|
+
|
|
9
|
+
function readConfigFile(path) {
|
|
10
|
+
try { return JSON.parse(readFileSync(path, 'utf8')); }
|
|
11
|
+
catch (error) { throw new Error(format(M.cannotRead, { path, reason: error.message })); }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Merges one level deep: each section is merged key by key, arrays are replaced whole.
|
|
15
|
+
// Unknown sections and keys are rejected so typos never pass silently.
|
|
16
|
+
export function mergeConfig(base, override = {}) {
|
|
17
|
+
const merged = {};
|
|
18
|
+
for (const [section, values] of Object.entries(override)) {
|
|
19
|
+
if (!(section in base)) throw new Error(format(M.unknownSection, { section }));
|
|
20
|
+
if (typeof values !== 'object' || values === null || Array.isArray(values)) throw new Error(format(M.sectionNotObject, { section }));
|
|
21
|
+
for (const key of Object.keys(values)) if (!(key in base[section])) throw new Error(format(M.unknownKey, { section, key }));
|
|
22
|
+
}
|
|
23
|
+
for (const section of Object.keys(base)) merged[section] = { ...base[section], ...(override[section] || {}) };
|
|
24
|
+
return merged;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const isStringList = value => Array.isArray(value) && value.every(x => typeof x === 'string' && x.length > 0);
|
|
28
|
+
|
|
29
|
+
function validateConfig(config) {
|
|
30
|
+
const { server, capture, replay, redaction, mocks, wait, ui } = config;
|
|
31
|
+
const L = limits;
|
|
32
|
+
const join = list => list.join(M.listSeparator);
|
|
33
|
+
const errors = [];
|
|
34
|
+
const check = (ok, message) => { if (!ok) errors.push(message); };
|
|
35
|
+
const range = (section, key) => check(inRange(config[section][key], L[section][key]), format(M.range, { key: `${section}.${key}`, range: rangeText(L[section][key]) }));
|
|
36
|
+
const stringList = (section, key) => check(isStringList(config[section][key]), format(M.stringList, { key: `${section}.${key}` }));
|
|
37
|
+
|
|
38
|
+
check(L.server.loopbackHosts.includes(server.host), format(M.loopbackHost, { hosts: join(L.server.loopbackHosts) }));
|
|
39
|
+
range('server', 'port');
|
|
40
|
+
check(isStringList(server.allowedHostnames) && server.allowedHostnames.length > 0 && server.allowedHostnames.every(x => L.server.loopbackHostnames.includes(x)), format(M.allowedHostnames, { hosts: join(L.server.loopbackHostnames) }));
|
|
41
|
+
check(isStringList(server.allowedHostnames) && server.allowedHostnames.includes(urlHost(server.host)), M.allowedHostnamesIncludeHost);
|
|
42
|
+
check(typeof capture.pathPrefix === 'string' && new RegExp(L.capture.pathPrefixPattern).test(capture.pathPrefix) && !new RegExp(L.capture.reservedPathPattern).test(capture.pathPrefix), M.pathPrefix);
|
|
43
|
+
range('capture', 'maxBodyBytes');
|
|
44
|
+
range('capture', 'maxEvents');
|
|
45
|
+
range('replay', 'timeoutMs');
|
|
46
|
+
stringList('replay', 'blockedMethods');
|
|
47
|
+
stringList('replay', 'excludedHeaders');
|
|
48
|
+
check(typeof redaction.placeholder === 'string' && redaction.placeholder.length > 0, M.placeholder);
|
|
49
|
+
stringList('redaction', 'sensitiveHeaders');
|
|
50
|
+
range('mocks', 'maxDelayMs');
|
|
51
|
+
range('mocks', 'maxRules');
|
|
52
|
+
if (!Array.isArray(mocks.rules)) errors.push(M.rulesList);
|
|
53
|
+
else {
|
|
54
|
+
check(mocks.rules.length <= mocks.maxRules, M.rulesOverLimit);
|
|
55
|
+
const ids = mocks.rules.map(rule => rule?.id).filter(id => id !== undefined);
|
|
56
|
+
check(new Set(ids).size === ids.length, M.ruleIdsUnique);
|
|
57
|
+
mocks.rules.forEach((rule, index) => {
|
|
58
|
+
try { parseRule(rule, { pathPrefix: capture.pathPrefix, maxDelayMs: mocks.maxDelayMs }, format(messages.rules.configLabel, { index })); }
|
|
59
|
+
catch (error) { errors.push(...error.errors); }
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
range('wait', 'maxTimeoutMs');
|
|
63
|
+
range('wait', 'defaultTimeoutMs');
|
|
64
|
+
check(wait.defaultTimeoutMs <= wait.maxTimeoutMs, M.waitDefaultOverMax);
|
|
65
|
+
range('ui', 'pollIntervalMs');
|
|
66
|
+
range('ui', 'timelineWindowMs');
|
|
67
|
+
check(L.ui.themes.includes(ui.defaultTheme), format(M.theme, { themes: join(L.ui.themes) }));
|
|
68
|
+
stringList('ui', 'curlExcludedHeaders');
|
|
69
|
+
if (errors.length) throw new Error(format(M.invalid, { errors: errors.join(M.errorSeparator) }));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function normalize(config) {
|
|
73
|
+
const lower = list => list.map(x => x.toLowerCase());
|
|
74
|
+
const ruleLimits = { pathPrefix: config.capture.pathPrefix, maxDelayMs: config.mocks.maxDelayMs };
|
|
75
|
+
return {
|
|
76
|
+
...config,
|
|
77
|
+
replay: { ...config.replay, blockedMethods: config.replay.blockedMethods.map(x => x.toUpperCase()), excludedHeaders: lower(config.replay.excludedHeaders) },
|
|
78
|
+
redaction: { ...config.redaction, sensitiveHeaders: lower(config.redaction.sensitiveHeaders) },
|
|
79
|
+
// Config rules without an id get one from their position, so they can be removed through the API.
|
|
80
|
+
mocks: { ...config.mocks, rules: config.mocks.rules.map((rule, i) => ({ ...parseRule(rule, ruleLimits), id: rule.id ?? `${app.mocks.configRuleIdPrefix}${i + 1}` })) },
|
|
81
|
+
ui: { ...config.ui, curlExcludedHeaders: lower(config.ui.curlExcludedHeaders) },
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const deepFreeze = value => { if (value && typeof value === 'object') { Object.values(value).forEach(deepFreeze); Object.freeze(value); } return value; };
|
|
86
|
+
|
|
87
|
+
// Precedence: config/default.json < file (--config) < overrides (PORT, --port, tests).
|
|
88
|
+
export function loadConfig({ file, overrides } = {}) {
|
|
89
|
+
let config = readConfigFile(defaultConfigPath);
|
|
90
|
+
if (file) config = mergeConfig(config, readConfigFile(file));
|
|
91
|
+
if (overrides) config = mergeConfig(config, overrides);
|
|
92
|
+
validateConfig(config);
|
|
93
|
+
return deepFreeze(normalize(config));
|
|
94
|
+
}
|