mockaton 2.2.0 → 2.3.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.
Binary file
package/README.md CHANGED
@@ -125,7 +125,7 @@ Comments are anything within parentheses, including them.
125
125
  They are ignored for URL purposes, so they have no effect
126
126
  on the URL mask. For example, these two are for `/api/foo`
127
127
  <pre>
128
- api/foo<b>(my comment)</b>.GET.200.json<b>(foo)</b>
128
+ api/foo<b>(my comment)</b>.GET.200.json<b>(bar)</b>
129
129
  api/foo.GET.200.json
130
130
  </pre>
131
131
 
@@ -143,10 +143,10 @@ but since that’s part of the query string, it’s ignored anyway.
143
143
 
144
144
 
145
145
 
146
- ### Default (index-like) file
147
- For the default route of a directory, omit the name (just use
148
- the extension). For example, the following files will be routed
149
- to `api/foo` because comments and the query string are ignored.
146
+ ### Default (index-like) route
147
+ For the default route of a directory, omit the mock filename name
148
+ (<b>just use the extension</b>). For example, the following files will be
149
+ routed to `api/foo` because comments and the query string are ignored.
150
150
  ```text
151
151
  api/foo/.GET.200.json
152
152
  api/foo/?bar=[bar].GET.200.json
@@ -160,7 +160,7 @@ The selected cookie is sent in every response in the `Set-Cookie` header.
160
160
  import { jwtCookie } from 'mockaton'
161
161
 
162
162
  Config.cookies = {
163
- 'My Admin User': 'my-cookie=1;Path=/;SameSite=strict',
163
+ 'My Admin User': 'my-cookie=1;Path=/;SameSite=strict',
164
164
  'My Normal User': 'my-cookie=0;Path=/;SameSite=strict',
165
165
  'My JWT': jwtCookie('my-cookie', {
166
166
  email: 'john.doe@example.com',
@@ -175,15 +175,14 @@ words, it’s useful if you only care about its payload.
175
175
 
176
176
 
177
177
  ## `Config.extraHeaders`
178
- They are applied last, right before ending the response. In
179
- other words, they can overwrite the `Content-Type`. They are
180
- not tuples, the header name goes in even-numbered indices.
178
+ They are applied last, right before ending the response. In other words, they
179
+ can overwrite the `Content-Type`. The header name goes in even indices.
181
180
 
182
181
  ```js
183
182
  Config.extraHeaders = [
184
183
  'Server', 'Mockaton',
185
- 'Set-Cookie', 'another-cookie=FOO;Path=/;SameSite=strict',
186
- 'Set-Cookie', 'another-cookie=BAR;Path=/;SameSite=strict'
184
+ 'Set-Cookie', 'foo=FOO;Path=/;SameSite=strict',
185
+ 'Set-Cookie', 'bar=BAR;Path=/;SameSite=strict'
187
186
  ]
188
187
  ```
189
188
 
@@ -223,7 +222,7 @@ fetch(addr + '/mockaton/bulk-select-by-comment', {
223
222
  ### Reset
224
223
  Re-Initialize the collection and its states (selected mocks and cookies, delays, etc.).
225
224
  ```js
226
- fetch(add + '/mockaton/reset', {
225
+ fetch(addr + '/mockaton/reset', {
227
226
  method: 'PATCH'
228
227
  })
229
228
  ```
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": "2.2.0",
5
+ "version": "2.3.0",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "license": "MIT",
@@ -3,6 +3,7 @@
3
3
 
4
4
  export default function (req, response) {
5
5
  return JSON.stringify([
6
- { id: 0 }
6
+ 'http://example.com/foo',
7
+ 'http://example.com/bar',
7
8
  ])
8
9
  }
package/src/Dashboard.css CHANGED
@@ -14,23 +14,13 @@ body {
14
14
  padding: 16px;
15
15
  }
16
16
  * {
17
+ padding: 0;
17
18
  border: 0;
18
19
  margin: 0;
19
20
  font-family: system-ui, sans-serif;
20
21
  font-size: 100%;
21
22
  }
22
23
 
23
- h1 {
24
- padding: 12px 0;
25
- margin: 0;
26
- font-size: 2rem;
27
- }
28
-
29
-
30
- select {
31
- padding: 3px 0;
32
- border: 1px solid #444;
33
- }
34
24
 
35
25
  fieldset {
36
26
  width: 120px;
@@ -47,15 +37,6 @@ fieldset {
47
37
  }
48
38
  }
49
39
 
50
- .CookieSelector {
51
- display: flex;
52
- align-items: center;
53
- margin-left: 20px;
54
-
55
- select {
56
- margin-left: 5px;
57
- }
58
- }
59
40
 
60
41
  main {
61
42
  display: flex;
@@ -72,14 +53,39 @@ main {
72
53
  }
73
54
  }
74
55
 
75
- .TitleWrap {
56
+ menu {
76
57
  display: flex;
77
- align-items: center;
58
+ margin-bottom: 12px;
59
+ gap: 14px;
60
+ align-items: flex-end;
61
+
62
+ h1 {
63
+ margin: 0;
64
+ margin-right: 14px;
65
+ font-size: 2rem;
66
+ }
67
+
68
+ label {
69
+ span {
70
+ display: block;
71
+ color: #555;
72
+ font-size: .85rem;
73
+ }
74
+
75
+ select {
76
+ width: 143px;
77
+ padding: 3px 0;
78
+ border: 1px solid #bbb;
79
+ margin-top: 1px;
80
+ cursor: pointer;
81
+ border-radius: 4px;
82
+ font-size: 0.9rem;
83
+ }
84
+ }
78
85
 
79
86
  button {
80
- padding: 3px 12px;
87
+ padding: 4px 12px;
81
88
  border: 1px solid var(--colorRed);
82
- margin-left: 20px;
83
89
  background: transparent;
84
90
  color: var(--colorRed);
85
91
  border-radius: 50px;
@@ -132,18 +138,11 @@ main {
132
138
  }
133
139
  }
134
140
 
135
- .BulkSelectSection {
136
- margin: 20px 0;
137
- }
138
-
139
- .BulkSelectSection select {
140
- margin-top: 5px;
141
- }
142
-
143
141
  .MockSelector {
144
142
  width: 300px;
145
143
  padding: 8px 1px;
146
144
  border: 0;
145
+ border-radius: 4px;
147
146
  background: #eee;
148
147
  text-align: right;
149
148
  direction: rtl;
package/src/Dashboard.js CHANGED
@@ -16,14 +16,11 @@ const Strings = {
16
16
  }
17
17
 
18
18
  const CSS = {
19
- BulkSelectSection: 'BulkSelectSection',
20
- CookieSelector: 'CookieSelector',
21
19
  DelayCheckbox: 'DelayCheckbox',
22
20
  Documentation: 'Documentation',
23
21
  MockSelector: 'MockSelector',
24
22
  PayloadViewer: 'PayloadViewer',
25
23
  PreviewLink: 'PreviewLink',
26
- TitleWrap: 'TitleWrap',
27
24
 
28
25
  bold: 'bold',
29
26
  chosen: 'chosen',
@@ -57,13 +54,11 @@ function DevPanel(brokersByMethod, cookies, comments) {
57
54
  document.title = Strings.title
58
55
  return (
59
56
  r('div', null,
60
- r('div', { className: CSS.TitleWrap },
57
+ r('menu', null,
61
58
  r('h1', null, Strings.title),
62
- r(ResetButton),
63
- r(CookieSelector, { list: cookies })),
64
- r('div', { className: CSS.BulkSelectSection },
65
- r('h2', null, Strings.bulk_select_by_comment),
66
- r(BulkSelector, { comments })),
59
+ r(CookieSelector, { list: cookies }),
60
+ r(BulkSelector, { comments }),
61
+ r(ResetButton)),
67
62
  r('main', null,
68
63
  r('table', null, Object.entries(brokersByMethod).map(([method, brokers]) =>
69
64
  r(SectionByMethod, { method, brokers }))),
@@ -88,8 +83,8 @@ function ResetButton() {
88
83
 
89
84
  function CookieSelector({ list }) {
90
85
  return (
91
- r('label', { className: CSS.CookieSelector },
92
- Strings.cookie,
86
+ r('label', null,
87
+ r('span', null, Strings.cookie),
93
88
  r('select', {
94
89
  autocomplete: 'off',
95
90
  disabled: list.length <= 1,
@@ -111,21 +106,23 @@ function CookieSelector({ list }) {
111
106
 
112
107
  function BulkSelector({ comments }) {
113
108
  return (
114
- r('select', {
115
- autocomplete: 'off',
116
- disabled: comments.length <= 1,
117
- onChange() {
118
- fetch(API.bulkSelect, {
119
- method: 'PATCH',
120
- body: JSON.stringify(this.value)
121
- })
122
- .then(init)
123
- .catch(console.error)
124
- }
125
- }, [Strings.select_one].concat(comments).map(item =>
126
- r('option', {
127
- value: item
128
- }, item))))
109
+ r('label', null,
110
+ r('span', null, Strings.bulk_select_by_comment),
111
+ r('select', {
112
+ autocomplete: 'off',
113
+ disabled: comments.length <= 1,
114
+ onChange() {
115
+ fetch(API.bulkSelect, {
116
+ method: 'PATCH',
117
+ body: JSON.stringify(this.value)
118
+ })
119
+ .then(init)
120
+ .catch(console.error)
121
+ }
122
+ }, [Strings.select_one].concat(comments).map(item =>
123
+ r('option', {
124
+ value: item
125
+ }, item)))))
129
126
  }
130
127
 
131
128
 
@@ -36,8 +36,8 @@ export async function dispatchMock(req, response) {
36
36
  response.setHeader('content-type', mimeFor('.json'))
37
37
  const jsExport = await importDefault(file)
38
38
  mockText = typeof jsExport === 'function'
39
- ? jsExport(req, response)
40
- : JSON.stringify(jsExport)
39
+ ? await jsExport(req, response)
40
+ : JSON.stringify(jsExport, null, 2)
41
41
  }
42
42
  else {
43
43
  response.setHeader('content-type', mimeFor(file))