@miso.ai/doggoganger 0.9.1-beta.3 → 0.9.1-beta.4

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/fetch.js +28 -26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miso.ai/doggoganger",
3
- "version": "0.9.1-beta.3",
3
+ "version": "0.9.1-beta.4",
4
4
  "description": "A dummy miso endpoint for demo and testing",
5
5
  "type": "module",
6
6
  "bin": {
package/src/fetch.js CHANGED
@@ -1,32 +1,34 @@
1
1
  import { wrapResponse } from './route/utils.js';
2
2
 
3
- export default function buildFetch(api) {
4
- return async function fetch(url, { method = 'GET', body } = {}) {
5
- method = method.toUpperCase();
6
- if (typeof body === 'string') {
7
- body = JSON.parse(body);
8
- }
9
- url = new URL(url);
10
- const segments = url.pathname.substring(1).split('/');
11
- if (segments[0] === 'v1') {
12
- segments.splice(0, 1);
13
- }
14
- const group = segments[0];
15
- let name = segments[1];
16
- let type = 'query';
3
+ export default async function fetch(api, url, { method = 'GET', body } = {}) {
4
+ method = method.toUpperCase();
5
+ if (typeof body === 'string') {
6
+ body = JSON.parse(body);
7
+ }
8
+ url = new URL(url);
9
+ const segments = url.pathname.substring(1).split('/');
10
+ if (segments[0] === 'v1') {
11
+ segments.splice(0, 1);
12
+ }
13
+ const group = segments[0];
14
+ let name = segments[1];
15
+ let type = 'query';
17
16
 
18
- if (group === 'interactions' && segments.length === 1) {
19
- name = 'upload';
20
- type = 'data';
21
- } else if (group === 'ask' && segments.length === 4 && segments[2] === 'questions' && segments[3] === 'answer') {
22
- name = 'answer';
23
- body = segments[3];
24
- }
17
+ if (group === 'interactions' && segments.length === 1) {
18
+ name = 'upload';
19
+ type = 'data';
20
+ } else if (group === 'ask' && segments.length === 4 && segments[2] === 'questions' && segments[3] === 'answer') {
21
+ name = 'answer';
22
+ body = segments[3];
23
+ }
25
24
 
26
- if (!api[group][name]) {
27
- throw new Error(`Unknown path: ${url.pathname}`);
28
- }
25
+ if (!api[group][name]) {
26
+ throw new Error(`Unknown path: ${url.pathname}`);
27
+ }
29
28
 
30
- return await wrapResponse(api[group][name], type)(body);
31
- };
29
+ const resBody = await wrapResponse(api[group][name], type)(body);
30
+
31
+ return new Response(JSON.stringify(resBody), {
32
+ status: 200,
33
+ });
32
34
  }