mockaton 13.0.0 → 13.0.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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "mockaton",
3
3
  "description": "HTTP Mock Server",
4
4
  "type": "module",
5
- "version": "13.0.0",
5
+ "version": "13.0.2",
6
6
  "exports": {
7
7
  ".": {
8
8
  "import": "./index.js",
@@ -40,7 +40,7 @@ export class Commander {
40
40
 
41
41
 
42
42
  /** @returns {JsonPromise<ClientMockBroker>} */
43
- toggleStatus = (status, method, urlMask) => this.#patch(API.toggleStatus, [status, method, urlMask])
43
+ toggleStatus = (method, urlMask, status) => this.#patch(API.toggleStatus, [method, urlMask, status])
44
44
 
45
45
  // TODO change Status or Toggle404?
46
46
 
@@ -99,7 +99,11 @@ async function updatePayloadViewer(proxied, file, response) {
99
99
  ? PayloadViewerTitleWhenProxied(response)
100
100
  : PayloadViewerTitle(file, response.statusText))
101
101
 
102
- // All branches naively assume GET 200
102
+ if (!response.ok || response.status === 204) {
103
+ codeRef.elem.textContent = await bodyAsText()
104
+ return
105
+ }
106
+
103
107
  if (mime.startsWith('image/'))
104
108
  codeRef.elem.replaceChildren(r('img', {
105
109
  src: URL.createObjectURL(await response.blob())
@@ -138,8 +142,8 @@ async function updatePayloadViewer(proxied, file, response) {
138
142
  }, t`Download`))
139
143
 
140
144
 
141
- function bodyAsText() {
142
- return response.text() || t`/* Empty Response Body */`
145
+ async function bodyAsText() {
146
+ return (await response.text()) || t`/* Empty Response Body */`
143
147
  }
144
148
  }
145
149
 
@@ -161,8 +161,8 @@ export const store = {
161
161
  })
162
162
  },
163
163
 
164
- toggleStatus(status, method, urlMask) {
165
- store._request(() => api.toggleStatus(status, method, urlMask), async response => {
164
+ toggleStatus(method, urlMask, status) {
165
+ store._request(() => api.toggleStatus(method, urlMask, status), async response => {
166
166
  store.setBroker(await response.json())
167
167
  store.setChosenLink(method, urlMask)
168
168
  store.renderRow(method, urlMask)
package/src/client/app.js CHANGED
@@ -131,7 +131,7 @@ function Row(row, i) {
131
131
  disabled: row.opts.length === 1 && (row.isStatic ? row.status === 404 : row.status === 500),
132
132
  checked: !row.proxied && (row.isStatic ? row.status === 404 : row.status === 500),
133
133
  commit() {
134
- store.toggleStatus(row.isStatic ? 404 : 500, method, urlMask)
134
+ store.toggleStatus(method, urlMask, row.isStatic ? 404 : 500)
135
135
  }
136
136
  }),
137
137
 
package/src/server/Api.js CHANGED
@@ -200,7 +200,7 @@ async function selectMock(req, response) {
200
200
 
201
201
 
202
202
  async function toggleRouteStatus(req, response) {
203
- const [status, method, urlMask] = await req.json()
203
+ const [method, urlMask, status] = await req.json()
204
204
 
205
205
  const broker = mockBrokersCollection.brokerByRoute(method, urlMask)
206
206
  if (!broker)
@@ -498,7 +498,7 @@ describe('Proxy Fallback', () => {
498
498
  await fx.sync()
499
499
  await api.setProxyFallback('https://example.test')
500
500
 
501
- const r0 = await api.toggleStatus(500, fx.method, fx.urlMask)
501
+ const r0 = await api.toggleStatus(fx.method, fx.urlMask, 500)
502
502
  const b0 = await r0.json()
503
503
  equal(b0.proxied, false)
504
504
  equal(b0.autoStatus, 500)
@@ -706,13 +706,13 @@ describe('Auto Status', () => {
706
706
  await fx.sync()
707
707
  equal((await fx.request()).status, fx.status)
708
708
 
709
- const bp0 = await api.toggleStatus(500, fx.method, fx.urlMask)
709
+ const bp0 = await api.toggleStatus(fx.method, fx.urlMask, 500)
710
710
  const b0 = await bp0.json()
711
711
  equal(b0.autoStatus, 500)
712
712
  equal(b0.status, 500)
713
713
  equal((await fx.request()).status, 500)
714
714
 
715
- const r1 = await api.toggleStatus(500, fx.method, fx.urlMask)
715
+ const r1 = await api.toggleStatus(fx.method, fx.urlMask, 500)
716
716
  equal((await r1.json()).autoStatus, 0)
717
717
  equal((await fx.request()).status, fx.status)
718
718
  })
@@ -724,13 +724,13 @@ describe('Auto Status', () => {
724
724
  await fx500.write()
725
725
  await api.reset()
726
726
 
727
- const bp0 = await api.toggleStatus(500, fx200.method, fx200.urlMask)
727
+ const bp0 = await api.toggleStatus(fx200.method, fx200.urlMask, 500)
728
728
  const b0 = await bp0.json()
729
729
  equal(b0.autoStatus, 0)
730
730
  equal(b0.status, 500)
731
731
  equal(await (await fx200.request()).text(), fx500.body)
732
732
 
733
- const bp1 = await api.toggleStatus(500, fx200.method, fx200.urlMask)
733
+ const bp1 = await api.toggleStatus(fx200.method, fx200.urlMask, 500)
734
734
  const b1 = await bp1.json()
735
735
  equal(b0.autoStatus, 0)
736
736
  equal(b1.status, 200)
@@ -745,7 +745,7 @@ describe('Auto Status', () => {
745
745
  await fx.sync()
746
746
  await api.setProxyFallback('https://example.test')
747
747
  await api.setRouteIsProxied(fx.method, fx.urlMask, true)
748
- await api.toggleStatus(500, fx.method, fx.urlMask)
748
+ await api.toggleStatus(fx.method, fx.urlMask, 500)
749
749
  equal((await fx.fetchBroker()).proxied, false)
750
750
  await fx.unlink()
751
751
  await api.setProxyFallback('')
@@ -756,13 +756,13 @@ describe('Auto Status', () => {
756
756
  await fx.sync()
757
757
  equal((await fx.request()).status, 200)
758
758
 
759
- const bp0 = await api.toggleStatus(404, fx.method, fx.urlMask)
759
+ const bp0 = await api.toggleStatus(fx.method, fx.urlMask, 404)
760
760
  const b0 = await bp0.json()
761
761
  equal(b0.autoStatus, 404)
762
762
  equal(b0.status, 404)
763
763
  equal((await fx.request()).status, 404)
764
764
 
765
- const r1 = await api.toggleStatus(404, fx.method, fx.urlMask)
765
+ const r1 = await api.toggleStatus(fx.method, fx.urlMask, 404)
766
766
  equal((await r1.json()).autoStatus, 0)
767
767
  equal((await fx.request()).status, 200)
768
768
 
@@ -1064,7 +1064,7 @@ describe('Registering Mocks', () => {
1064
1064
  const fx200 = new Fixture('reg-error.GET.200.txt')
1065
1065
  const fx500 = new Fixture('reg-error.GET.500.txt')
1066
1066
  await fx200.register()
1067
- await api.toggleStatus(500, fx200.method, fx200.urlMask)
1067
+ await api.toggleStatus(fx200.method, fx200.urlMask, 500)
1068
1068
  const b0 = await fx200.fetchBroker()
1069
1069
  equal(b0.autoStatus, 500)
1070
1070
  await fx500.register()
package/src/server/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { resolve } from 'node:path'
3
+ import { resolve, join } from 'node:path'
4
4
  import { parseArgs } from 'node:util'
5
5
 
6
6
  import { isFile } from './utils/fs.js'
@@ -24,7 +24,8 @@ try {
24
24
  'no-open': { short: 'n', type: 'boolean' },
25
25
 
26
26
  help: { short: 'h', type: 'boolean' },
27
- version: { short: 'v', type: 'boolean' }
27
+ version: { short: 'v', type: 'boolean' },
28
+ skills: { type: 'boolean' },
28
29
  },
29
30
  allowPositionals: true
30
31
  })
@@ -43,6 +44,9 @@ process.on('SIGUSR2', () => process.exit(0))
43
44
  if (args.version)
44
45
  console.log(pkgJSON.version)
45
46
 
47
+ else if (args.skills)
48
+ console.log(join(import.meta.dirname, 'skills'))
49
+
46
50
  else if (args.help)
47
51
  console.log(`
48
52
  Usage: mockaton [mocks-dir] [options]
@@ -58,6 +62,7 @@ Options:
58
62
 
59
63
  -h, --help Show this help
60
64
  -v, --version Show version
65
+ --skills Show AI agent skills path
61
66
 
62
67
  Notes:
63
68
  * mockaton.config.js supports more options, see: https://mockaton.com/config