mockaton 8.11.0 → 8.11.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 CHANGED
@@ -226,7 +226,7 @@ want a `Content-Type` header in the response.
226
226
 
227
227
  <details>
228
228
  <summary>Supported Methods</summary>
229
- <p>From Node.js <code>http.METHODS</code></p>
229
+ <p>From <code>require('node:http').METHODS</code></p>
230
230
  <p>
231
231
  ACL, BIND, CHECKOUT,
232
232
  CONNECT, COPY, DELETE,
@@ -473,7 +473,7 @@ function capitalizePlugin(filePath) {
473
473
  Defaults to `true`. When `true`, these are the default options:
474
474
  ```js
475
475
  config.corsOrigins = ['*']
476
- config.corsMethods = ['GET', 'PUT', 'DELETE', 'POST', 'PATCH', 'HEAD', 'OPTIONS', 'TRACE', 'CONNECT']
476
+ config.corsMethods = require('node:http').METHODS
477
477
  config.corsHeaders = ['content-type']
478
478
  config.corsCredentials = true
479
479
  config.corsMaxAge = 0 // seconds to cache the preflight req
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "mockaton",
3
3
  "description": "A deterministic server-side for developing and testing frontend clients",
4
4
  "type": "module",
5
- "version": "8.11.0",
5
+ "version": "8.11.2",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "license": "MIT",
package/src/Dashboard.css CHANGED
@@ -12,7 +12,7 @@
12
12
  --colorBackground: #fff;
13
13
  --colorComboBoxHeaderBackground: #fff;
14
14
  --colorComboBoxBackground: #f7f7f7;
15
- --colorHeaderBackground: #f3f3f3;
15
+ --colorHeaderBackground: #eee;
16
16
  --colorSecondaryButtonBackground: #f3f3f3;
17
17
  --colorSecondaryAction: #555;
18
18
  --colorDisabledMockSelector: #444;
@@ -31,8 +31,8 @@
31
31
  --colorBackground: #161616;
32
32
  --colorHeaderBackground: #090909;
33
33
  --colorComboBoxBackground: #252525;
34
- --colorSecondaryButtonBackground: #202020;
35
- --colorSecondaryAction: #bbb;
34
+ --colorSecondaryButtonBackground: #282828;
35
+ --colorSecondaryAction: #999;
36
36
  --colorComboBoxHeaderBackground: #222;
37
37
  --colorDisabledMockSelector: #b9b9b9;
38
38
  --colorHover: #023661;
@@ -68,7 +68,10 @@ select, a, input, button, summary {
68
68
  }
69
69
  }
70
70
 
71
- a, button, input[type=checkbox] {
71
+ a,
72
+ button,
73
+ input[type=checkbox],
74
+ input[type=checkbox] ~ svg {
72
75
  cursor: pointer;
73
76
 
74
77
  &:active {
@@ -117,7 +120,7 @@ select {
117
120
  img {
118
121
  width: 130px;
119
122
  align-self: center;
120
- margin-right: 20px;
123
+ margin-right: 22px;
121
124
  }
122
125
 
123
126
  .Field {
@@ -133,8 +136,10 @@ select {
133
136
  svg {
134
137
  width: 14px;
135
138
  height: 14px;
136
- fill: var(--colorLabel);
137
- opacity: 0.6;
139
+ stroke: var(--colorLabel);
140
+ stroke-width: 1.5px;
141
+ fill: none;
142
+ opacity: .7;
138
143
  }
139
144
  }
140
145
 
@@ -158,16 +163,18 @@ select {
158
163
  }
159
164
 
160
165
  &.GlobalDelayField {
161
- width: 82px;
166
+ width: 84px;
162
167
 
163
168
  input[type=number] {
164
169
  padding-right: 0;
165
170
  }
166
171
 
167
172
  svg {
173
+ width: 12px;
174
+ height: 12px;
168
175
  border: 1px solid var(--colorLabel);
176
+ stroke-width: 3px;
169
177
  border-radius: 50%;
170
- transform: scale(.85);
171
178
  }
172
179
  }
173
180
 
@@ -276,7 +283,7 @@ select {
276
283
  position: relative;
277
284
  left: -6px;
278
285
  display: inline-block;
279
- width: 278px;
286
+ width: 272px;
280
287
  padding: 8px 6px;
281
288
  border-radius: var(--radius);
282
289
  color: var(--colorAccent);
@@ -295,6 +302,7 @@ select {
295
302
  width: 260px;
296
303
  height: 30px;
297
304
  padding-right: 5px;
305
+ padding-left: 16px;
298
306
  border: 0;
299
307
  text-align: right;
300
308
  direction: rtl;
@@ -323,7 +331,6 @@ select {
323
331
  .ProxyToggler {
324
332
  display: flex;
325
333
  margin-left: 8px;
326
- cursor: pointer;
327
334
 
328
335
  > input {
329
336
  appearance: none;
@@ -334,48 +341,90 @@ select {
334
341
  outline: 2px solid var(--colorAccent)
335
342
  }
336
343
  }
344
+ }
337
345
 
338
- &:enabled:hover:not(:checked) ~ svg {
339
- background: var(--colorHover);
340
- fill: var(--colorText);
341
- }
346
+ > svg {
347
+ vertical-align: bottom;
348
+ fill: none;
349
+ stroke: var(--colorSecondaryAction);
350
+ }
351
+ }
342
352
 
353
+ .DelayToggler {
354
+ > input {
343
355
  &:checked ~ svg {
344
- border-color: transparent;
356
+ border: 1px solid var(--colorBackground);
357
+ fill: var(--colorAccent);
345
358
  background: var(--colorAccent);
346
- fill: white;
347
- box-shadow: var(--boxShadow1);
359
+ stroke: var(--colorBackground);
348
360
  }
349
361
 
350
- &:disabled ~ svg {
351
- fill-opacity: 0.4;
352
- cursor: not-allowed;
353
- box-shadow: none;
362
+ &:enabled:hover:not(:checked) ~ svg {
363
+ border-color: var(--colorText);
364
+ background: var(--colorHover);
365
+ stroke: var(--colorText);
354
366
  }
355
367
  }
356
368
 
357
369
  > svg {
358
370
  width: 18px;
359
371
  height: 18px;
360
- vertical-align: bottom;
361
- fill: var(--colorSecondaryAction);
372
+ stroke-width: 2.5px;
362
373
  border-radius: 50%;
363
374
  background: var(--colorSecondaryButtonBackground);
364
375
  }
365
376
  }
366
377
 
367
378
  .ProxyToggler {
379
+ padding: 1px 3px;
380
+ background: var(--colorSecondaryButtonBackground);
381
+ border-radius: var(--radiusSmall);
382
+
383
+ &:has(input:checked),
384
+ &:has(input:disabled) {
385
+ background: transparent;
386
+ }
387
+
388
+ > input {
389
+ &:checked ~ svg {
390
+ fill: var(--colorAccent);
391
+ stroke: var(--colorAccent);
392
+
393
+ path:last-of-type { /* inner cloud curve */
394
+ stroke: var(--colorBackground);
395
+ }
396
+ transform: scale(1.2);
397
+ }
398
+
399
+ &:enabled:hover:not(:checked) ~ svg {
400
+ fill: var(--colorHover);
401
+ stroke: var(--colorText);
402
+ }
403
+
404
+ &:disabled ~ svg {
405
+ stroke-opacity: 0.5;
406
+ cursor: not-allowed;
407
+ box-shadow: none;
408
+ fill: transparent;
409
+
410
+ path:last-of-type {
411
+ stroke-opacity: 0;
412
+ stroke: transparent;
413
+ }
414
+ }
415
+ }
416
+
368
417
  > svg {
369
- width: 20px;
370
- padding: 3px;
371
- border-color: transparent;
418
+ width: 16px;
419
+ height: 16px;
420
+ stroke-width: 2px;
372
421
  border-radius: var(--radiusSmall);
373
422
  }
374
423
  }
375
424
 
376
425
  .InternalServerErrorToggler {
377
426
  display: flex;
378
- margin-left: 8px;
427
+ margin-left: 6px;
379
428
  cursor: pointer;
380
429
 
381
430
  > input {
@@ -391,19 +440,18 @@ select {
391
440
  &:checked ~ span {
392
441
  color: white;
393
442
  background: var(--colorRed);
394
- box-shadow: var(--boxShadow1);
395
443
  }
396
444
  }
397
445
 
398
446
  > span {
399
- padding: 5px 4px;
447
+ padding: 4px;
400
448
  font-size: 10px;
449
+ font-weight: bold;
401
450
  color: var(--colorSecondaryAction);
402
451
  border-radius: var(--radiusSmall);
403
452
  background: var(--colorSecondaryButtonBackground);
404
453
 
405
454
  &:hover {
406
- box-shadow: var(--boxShadow1);
407
455
  background: var(--colorLightRed);
408
456
  color: var(--colorRed);
409
457
  }
@@ -530,7 +578,7 @@ select {
530
578
  color: #9b71e8
531
579
  }
532
580
  .token.attr-name, .token.builtin, .token.char, .token.inserted, .token.selector, .token.string {
533
- color: #459900
581
+ color: #3e8300
534
582
  }
535
583
  .language-css .token.string, .style .token.string, .token.entity, .token.operator, .token.url {
536
584
  color: #9a6e3a;
package/src/Dashboard.js CHANGED
@@ -520,13 +520,15 @@ function onError(error) {
520
520
  function TimerIcon() {
521
521
  return (
522
522
  r('svg', { viewBox: '0 0 24 24' },
523
- r('path', { d: 'M12 7H11v6l5 3.2.75-1.23-4.5-3z' })))
523
+ r('path', { d: 'm11 5.6 0.14 7.2 6 3.7' })))
524
524
  }
525
525
 
526
526
  function CloudIcon() {
527
527
  return (
528
528
  r('svg', { viewBox: '0 0 24 24' },
529
- r('path', { d: 'M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.61 5.64 5.36 8.04 2.35 8.36 0 10.9 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96M19 18H6c-2.21 0-4-1.79-4-4s1.79-4 4-4 4 1.79 4 4h2c0-2.76-1.86-5.08-4.4-5.78C8.61 6.88 10.2 6 12 6c3.03 0 5.5 2.47 5.5 5.5v.5H19c1.65 0 3 1.35 3 3s-1.35 3-3 3' })))
529
+ r('path', { d: 'm6.1 8.9c0.98-2.3 3.3-3.9 6-3.9 3.3-2e-7 6 2.5 6.4 5.7 0.018 0.15 0.024 0.18 0.026 0.23 0.0016 0.037 8.2e-4 0.084 0.098 0.14 0.097 0.054 0.29 0.05 0.48 0.05 2.2 0 4 1.8 4 4s-1.8 4-4 4c-4-0.038-9-0.038-13-0.018-2.8 0-5-2.2-5-5-2.2e-7 -2.8 2.2-5 5-5 2.8 2e-7 5 2.2 5 5' }),
530
+ r('path', { d: 'm6.1 9.1c2.8 0 5 2.3 5 5' })
531
+ ))
530
532
  }
531
533
 
532
534
 
package/src/Filename.js CHANGED
@@ -1,4 +1,4 @@
1
- const httpMethods = [ // node:http.METHODS
1
+ const httpMethods = [ // @KeepSync with node:http.METHODS
2
2
  'ACL', 'BIND', 'CHECKOUT',
3
3
  'CONNECT', 'COPY', 'DELETE',
4
4
  'GET', 'HEAD', 'LINK',
@@ -61,6 +61,7 @@ function removeTrailingSlash(url = '') {
61
61
  .replace('/#', '#')
62
62
  }
63
63
 
64
+ // TODO ThinkAbout allowing custom status codes
64
65
  function responseStatusIsValid(status) {
65
66
  return Number.isInteger(status)
66
67
  && status >= 100
@@ -14,7 +14,7 @@ export async function dispatchMock(req, response) {
14
14
  const broker = mockBrokerCollection.getBrokerForUrl(req.method, req.url)
15
15
  if (!broker || broker.proxied) {
16
16
  if (config.proxyFallback)
17
- await proxy(req, response, Number(Boolean(broker?.delayed)) * config.delay)
17
+ await proxy(req, response, config.delay * Boolean(broker?.delayed))
18
18
  else
19
19
  sendNotFound(response)
20
20
  return
package/src/config.js CHANGED
@@ -2,7 +2,7 @@ import { realpathSync } from 'node:fs'
2
2
  import { isDirectory } from './utils/fs.js'
3
3
  import { openInBrowser } from './utils/openInBrowser.js'
4
4
  import { jsToJsonPlugin } from './MockDispatcherPlugins.js'
5
- import { StandardMethods } from './utils/http-request.js'
5
+ import { SUPPORTED_METHODS } from './utils/http-request.js'
6
6
  import { validateCorsAllowedMethods, validateCorsAllowedOrigins } from './utils/http-cors.js'
7
7
 
8
8
 
@@ -28,7 +28,7 @@ export const config = Object.seal({
28
28
 
29
29
  corsAllowed: true,
30
30
  corsOrigins: ['*'],
31
- corsMethods: StandardMethods,
31
+ corsMethods: SUPPORTED_METHODS,
32
32
  corsHeaders: ['content-type'],
33
33
  corsExposedHeaders: [],
34
34
  corsCredentials: true,
@@ -2,7 +2,7 @@
2
2
  <svg version="1.1" viewBox="0 0 570 100" xmlns="http://www.w3.org/2000/svg">
3
3
  <style>
4
4
  :root { --color: #000000; }
5
- @media (prefers-color-scheme: light) { :root { --color: #444 } }
5
+ @media (prefers-color-scheme: light) { :root { --color: #111 } }
6
6
  @media (prefers-color-scheme: dark) { :root { --color: #eee } }
7
7
  path { fill: var(--color) }
8
8
  </style>
@@ -1,9 +1,7 @@
1
- import { StandardMethods } from './http-request.js'
2
-
1
+ import { methodIsSupported } from './http-request.js'
3
2
 
4
3
  /* https://www.w3.org/TR/2020/SPSD-cors-20200602/#resource-processing-model */
5
4
 
6
-
7
5
  export function validateCorsAllowedOrigins(arr) {
8
6
  if (!Array.isArray(arr))
9
7
  return false
@@ -13,8 +11,7 @@ export function validateCorsAllowedOrigins(arr) {
13
11
  }
14
12
 
15
13
  export function validateCorsAllowedMethods(arr) {
16
- return Array.isArray(arr)
17
- && arr.every(m => StandardMethods.includes(m))
14
+ return Array.isArray(arr) && arr.every(methodIsSupported)
18
15
  }
19
16
 
20
17
 
@@ -38,7 +35,7 @@ const CH = CorsHeader
38
35
  export function isPreflight(req) {
39
36
  return req.method === 'OPTIONS'
40
37
  && URL.canParse(req.headers[CH.Origin])
41
- && StandardMethods.includes(req.headers[CH.AccessControlRequestMethod])
38
+ && methodIsSupported(req.headers[CH.AccessControlRequestMethod])
42
39
  }
43
40
 
44
41
 
@@ -1,7 +1,8 @@
1
- export const StandardMethods = [
2
- 'GET', 'PUT', 'DELETE', 'POST', 'PATCH',
3
- 'HEAD', 'OPTIONS', 'TRACE', 'CONNECT'
4
- ]
1
+ import { METHODS } from 'node:http'
2
+
3
+
4
+ export const SUPPORTED_METHODS = METHODS
5
+ export const methodIsSupported = method => SUPPORTED_METHODS.includes(method)
5
6
 
6
7
  export class BodyReaderError extends Error {name = 'BodyReaderError'}
7
8