mockaton 8.16.6 → 8.17.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/README.md CHANGED
@@ -70,12 +70,15 @@ lets you download all the HTTP responses following the filename convention.
70
70
 
71
71
  ### Option 2: Fallback to Your Backend
72
72
  This option could be a bit elaborate if your backend uses third-party auth,
73
- because in that case you’d have to inject the cookies manually.
73
+ because you’d have to inject the cookies or tokens in `sessionStorage` manually.
74
74
 
75
- At any rate, you can forward requests to your backend for routes you don’t have
76
- mocks for, or routes that have the ☁️ **Cloud Checkbox** checked. By checking
77
- ✅ **Save Mocks**, you can collect the responses that hit your backend. They
78
- will be saved in your `config.mocksDir` following the filename convention.
75
+ On the other hand, if you backend handles the session cookie, or if you can
76
+ develop without auth, proxying to your backend is straightforward to set up.
77
+
78
+ In a nutshell, you can forward requests to your backend for routes you don’t have
79
+ mocks for, or routes that have the ☁️ **Cloud Checkbox** checked. In addition, by
80
+ checking ✅ **Save Mocks**, you can collect the responses that hit your backend.
81
+ They will be saved in your `config.mocksDir` following the filename convention.
79
82
 
80
83
 
81
84
  <br/>
@@ -161,6 +164,7 @@ you want. For example, by adding `(demo-part1)`, `(demo-part2)` to the filenames
161
164
 
162
165
  Similarly, you can deploy a **Standalone Demo Server** by compiling the frontend app and
163
166
  putting its built assets in `config.staticDir`. And simulate the flow by Bulk Selecting mocks.
167
+ The [aot-fetch-demo repo](https://github.com/ericfortis/aot-fetch-demo) has a working example.
164
168
 
165
169
 
166
170
  <br/>
@@ -232,9 +236,11 @@ export default function listColors() {
232
236
  ```
233
237
  </details>
234
238
 
239
+ <br/>
240
+
235
241
  **What if I need to serve a static .js or .ts?**
236
242
 
237
- **Option A:** Put it in your `config.staticDir` without the filename extension convention (i.e., no `.GET.200.js`)
243
+ **Option A:** Put it in your `config.staticDir` without the `.GET.200.js` extension.
238
244
 
239
245
  **Option B:** Read it and return it. For example:
240
246
  ```js
@@ -346,20 +352,19 @@ api/foo/bar.GET.200.json
346
352
  This is the only required field. The directory must exist.
347
353
 
348
354
  ### `staticDir?: string`
349
- Files under `config.staticDir` don’t use the filename convention, and
350
- they take precedence over corresponding `GET` mocks in `config.mocksDir`.
351
- For example, if you have two files for `GET /foo/bar.jpg`
352
-
355
+ **This option is not needed** besides serving partial content (e.g., videos). But
356
+ it’s convenient for serving 200 GET requests without having to add the filename
357
+ extension convention. For example, for using Mockaton as a standalone demo server,
358
+ as explained above in the _Use Cases_ section.
359
+
360
+ Files under `config.staticDir` don’t use the filename convention, and they take
361
+ precedence over corresponding `GET` mocks in `config.mocksDir` (regardless
362
+ of status code). For example, if you have two files for `GET /foo/bar.jpg`:
353
363
  <pre>
354
- my-static-dir<b>/foo/bar.jpg</b>
355
- my-mocks-dir<b>/foo/bar.jpg</b>.GET.200.jpg // Unreachable
364
+ my-static-dir<b>/foo/bar.jpg</b> <span style="color:green"> // Wins</span>
365
+ my-mocks-dir<b>/foo/bar.jpg</b>.GET.200.jpg <span style="color:red"> // Unreachable</span>
356
366
  </pre>
357
367
 
358
- This `config.staticDir` is not actually needed besides serving partial content
359
- (e.g., videos). At any rate, it’s convenient for serving 200 GET requests without
360
- having to add the filename extension convention (i.e., no `.GET.200.ext`).
361
- For example, for using Mockaton as a standalone demo server. For that, you
362
- can build your frontend bundle and put its built assets in this folder.
363
368
 
364
369
  <br/>
365
370
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "mockaton",
3
3
  "description": "HTTP Mock Server",
4
4
  "type": "module",
5
- "version": "8.16.6",
5
+ "version": "8.17.0",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "license": "MIT",
package/src/Dashboard.css CHANGED
@@ -272,7 +272,7 @@ table {
272
272
 
273
273
  th {
274
274
  padding-bottom: 2px;
275
- padding-left: 110px;
275
+ padding-left: 4px;
276
276
  text-align: left;
277
277
  }
278
278
 
@@ -359,7 +359,6 @@ table {
359
359
  }
360
360
 
361
361
  .DelayToggler {
362
- margin-left: 8px;
363
362
  > input {
364
363
  &:checked ~ svg {
365
364
  border-color: var(--colorAccent);
@@ -387,6 +386,7 @@ table {
387
386
  .ProxyToggler {
388
387
  padding: 1px 3px;
389
388
  border: 1px solid var(--colorSecondaryActionBorder);
389
+ margin-right: 8px;
390
390
  border-radius: var(--radius);
391
391
 
392
392
  &:has(input:checked),
@@ -539,30 +539,31 @@ table {
539
539
 
540
540
  .ErrorToast {
541
541
  position: fixed;
542
+ z-index: 9999;
542
543
  bottom: 12px;
543
544
  left: 12px;
544
- z-index: 9999;
545
+ padding: 12px 16px;
545
546
  cursor: pointer;
546
547
  background: var(--colorRed);
547
548
  color: white;
548
- padding: 12px 16px;
549
549
  border-radius: var(--radius);
550
550
  box-shadow: var(--boxShadow1);
551
551
  opacity: 0;
552
552
  transform: translateY(20px);
553
553
  animation: _kfToastIn 240ms forwards;
554
554
 
555
- &:hover {
556
- &::after {
557
- top: 0;
558
- left: calc(100% - 6px);
559
- position: absolute;
560
- content: '×';
561
- vertical-align: middle;
562
- padding: 12px;
563
- border-radius: var(--radius);
564
- background: black;
565
- }
555
+ &:hover::after {
556
+ position: absolute;
557
+ top: 0;
558
+ left: 0;
559
+ width: 100%;
560
+ height: 100%;
561
+ text-align: center;
562
+ content: '×';
563
+ font-size: 28px;
564
+ line-height: 34px;
565
+ border-radius: var(--radius);
566
+ background: rgba(0, 0, 0, 0.5);
566
567
  }
567
568
  }
568
569
 
package/src/Dashboard.js CHANGED
@@ -92,12 +92,13 @@ function init() {
92
92
 
93
93
  function App([brokersByMethod, cookies, comments, delay, collectProxied, fallbackAddress, staticBrokers]) {
94
94
  globalDelay = delay
95
+ const canProxy = Boolean(fallbackAddress)
95
96
  return [
96
97
  r(Header, { cookies, comments, delay, fallbackAddress, collectProxied }),
97
98
  r('main', null,
98
99
  r('div', { className: CSS.MainLeftSide },
99
- r(MockList, { brokersByMethod, canProxy: Boolean(fallbackAddress) }),
100
- r(StaticFilesList, { brokers: staticBrokers })),
100
+ r(MockList, { brokersByMethod, canProxy }),
101
+ r(StaticFilesList, { brokers: staticBrokers, canProxy })),
101
102
  r('div', { className: CSS.MainRightSide },
102
103
  r(PayloadViewer)))]
103
104
  }
@@ -270,10 +271,12 @@ function SectionByMethod({ method, brokers, canProxy }) {
270
271
  const urlMasksDittoed = dittoSplitPaths(urlMasks)
271
272
  return (
272
273
  r('tbody', null,
273
- r('th', { colspan: 4 }, method),
274
+ r('tr', null,
275
+ r('th', { colspan: 2 + Number(canProxy) }),
276
+ r('th', null, method)),
274
277
  brokersSorted.map(([urlMask, broker], i) =>
275
278
  r('tr', { 'data-method': method, 'data-urlMask': urlMask },
276
- r('td', null, r(ProxyToggler, { broker, disabled: !canProxy })),
279
+ canProxy && r('td', null, r(ProxyToggler, { broker })),
277
280
  r('td', null, r(DelayRouteToggler, { broker })),
278
281
  r('td', null, r(InternalServerErrorToggler, { broker })),
279
282
  r('td', null, r(PreviewLink, { method, urlMask, urlMaskDittoed: urlMasksDittoed[i] })),
@@ -387,7 +390,7 @@ function InternalServerErrorToggler({ broker }) {
387
390
  }
388
391
 
389
392
  /** @param {{ broker: MockBroker, disabled: boolean }} props */
390
- function ProxyToggler({ broker, disabled }) {
393
+ function ProxyToggler({ broker }) {
391
394
  function onChange() {
392
395
  const { urlMask, method } = parseFilename(broker.mocks[0])
393
396
  mockaton.setRouteIsProxied(method, urlMask, this.checked)
@@ -402,7 +405,6 @@ function ProxyToggler({ broker, disabled }) {
402
405
  },
403
406
  r('input', {
404
407
  type: 'checkbox',
405
- disabled,
406
408
  checked: !broker.currentMock.file,
407
409
  onChange
408
410
  }),
@@ -414,7 +416,7 @@ function ProxyToggler({ broker, disabled }) {
414
416
  * # StaticFilesList
415
417
  * @param {{ brokers: StaticBroker[] }} props
416
418
  */
417
- function StaticFilesList({ brokers }) {
419
+ function StaticFilesList({ brokers, canProxy }) {
418
420
  if (!Object.keys(brokers).length)
419
421
  return null
420
422
  const dp = dittoSplitPaths(Object.keys(brokers)).map(([ditto, tail]) => ditto
@@ -422,11 +424,14 @@ function StaticFilesList({ brokers }) {
422
424
  : tail)
423
425
  return (
424
426
  r('table', { className: CSS.StaticFilesList },
427
+ r('thead', null,
428
+ r('tr', null,
429
+ r('th', { colspan: 2 + Number(canProxy) }),
430
+ r('th', null, Strings.static_get))),
425
431
  r('tbody', null,
426
- r('th', { colspan: 4 }, Strings.static_get),
427
432
  Object.values(brokers).map((broker, i) =>
428
433
  r('tr', null,
429
- r('td', null, r(ProxyStaticToggler, {})),
434
+ canProxy && r('td', null, r(ProxyStaticToggler, {})),
430
435
  r('td', null, r(DelayStaticRouteToggler, { broker })),
431
436
  r('td', null, r(NotFoundToggler, { broker })),
432
437
  r('td', null, r('a', { href: broker.route, target: '_blank' }, dp[i]))
@@ -604,9 +609,7 @@ function showErrorToast(msg) {
604
609
  className: CSS.ErrorToast,
605
610
  onClick() {
606
611
  const toast = this
607
- document.startViewTransition(() => {
608
- toast.remove()
609
- })
612
+ document.startViewTransition(() => toast.remove())
610
613
  }
611
614
  }, msg))
612
615
  }