@furystack/rest-client-fetch 5.0.0 → 5.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/esm/create-client.js +48 -0
- package/esm/create-client.js.map +1 -0
- package/esm/index.d.ts +3 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +3 -0
- package/esm/index.js.map +1 -0
- package/esm/response-error.js +7 -0
- package/esm/response-error.js.map +1 -0
- package/package.json +4 -13
- package/src/create-client.ts +1 -1
- package/src/index.ts +2 -2
- package/types/index.d.ts +0 -3
- package/types/index.d.ts.map +0 -1
- /package/{types → esm}/create-client.d.ts +0 -0
- /package/{types → esm}/create-client.d.ts.map +0 -0
- /package/{types → esm}/response-error.d.ts +0 -0
- /package/{types → esm}/response-error.d.ts.map +0 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { serializeToQueryString } from '@furystack/rest';
|
|
2
|
+
import { ResponseError } from './response-error.js';
|
|
3
|
+
import { compile } from 'path-to-regexp';
|
|
4
|
+
export const createClient = (clientOptions) => {
|
|
5
|
+
const fetchMethod = clientOptions.fetch || fetch;
|
|
6
|
+
return async (options) => {
|
|
7
|
+
const { url, query, body, headers } = options;
|
|
8
|
+
const urlToSend = (url ? compile(options.action)(url) : options.action) +
|
|
9
|
+
(query
|
|
10
|
+
? clientOptions.serializeQueryParams
|
|
11
|
+
? clientOptions.serializeQueryParams(query)
|
|
12
|
+
: `?${serializeToQueryString(query)}`
|
|
13
|
+
: '');
|
|
14
|
+
const response = await fetchMethod((clientOptions.endpointUrl + urlToSend), {
|
|
15
|
+
...clientOptions.requestInit,
|
|
16
|
+
method: options.method.toString(),
|
|
17
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
18
|
+
...(headers
|
|
19
|
+
? {
|
|
20
|
+
headers: {
|
|
21
|
+
...clientOptions.requestInit?.headers,
|
|
22
|
+
...headers,
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
: {}),
|
|
26
|
+
});
|
|
27
|
+
if (!response.ok) {
|
|
28
|
+
throw new ResponseError(response.statusText, response);
|
|
29
|
+
}
|
|
30
|
+
const contentType = response.headers?.get?.('Content-Type');
|
|
31
|
+
if (contentType?.startsWith('text/')) {
|
|
32
|
+
const result = (await response.text());
|
|
33
|
+
return { response, result };
|
|
34
|
+
}
|
|
35
|
+
if (contentType === 'form/multipart') {
|
|
36
|
+
const result = (await response.formData());
|
|
37
|
+
return { response, result };
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const result = (await response.json());
|
|
41
|
+
return { response, result };
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return { response, result: null };
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=create-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-client.js","sourceRoot":"","sources":["../src/create-client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAoBxC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAoB,aAA4B,EAAE,EAAE;IAC9E,MAAM,WAAW,GAAG,aAAa,CAAC,KAAK,IAAI,KAAK,CAAA;IAEhD,OAAO,KAAK,EASV,OAMU,EACyC,EAAE;QACrD,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAc,CAAA;QAEpD,MAAM,SAAS,GACb,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAgB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,OAAO,CAAC,MAAiB,CAAC;YAC3E,CAAC,KAAK;gBACJ,CAAC,CAAC,aAAa,CAAC,oBAAoB;oBAClC,CAAC,CAA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Aa,CAAA;YAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;SAC5B;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAgB,EAAE,CAAA;SAC9C;IACH,CAAC,CAAA;AACH,CAAC,CAAA"}
|
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA"}
|
package/esm/index.js
ADDED
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-error.js","sourceRoot":"","sources":["../src/response-error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,YAAY,OAAe,EAAS,QAAkB;QACpD,KAAK,CAAC,OAAO,CAAC,CAAA;QADoB,aAAQ,GAAR,QAAQ,CAAU;IAEtD,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@furystack/rest-client-fetch",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.2",
|
|
4
4
|
"description": "Native browser fetch based REST API implementation for FuryStack",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -8,20 +8,11 @@
|
|
|
8
8
|
},
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"import": "./esm/index.js"
|
|
12
|
-
"types": "./types/index.d.ts"
|
|
13
|
-
},
|
|
14
|
-
"./package.json": "./package.json"
|
|
15
|
-
},
|
|
16
|
-
"typesVersions": {
|
|
17
|
-
"*": {
|
|
18
|
-
"*": [
|
|
19
|
-
"types/*"
|
|
20
|
-
]
|
|
11
|
+
"import": "./esm/index.js"
|
|
21
12
|
}
|
|
22
13
|
},
|
|
23
14
|
"files": [
|
|
24
|
-
"
|
|
15
|
+
"esm",
|
|
25
16
|
"types",
|
|
26
17
|
"src"
|
|
27
18
|
],
|
|
@@ -46,7 +37,7 @@
|
|
|
46
37
|
},
|
|
47
38
|
"homepage": "https://github.com/furystack/furystack",
|
|
48
39
|
"dependencies": {
|
|
49
|
-
"@furystack/rest": "^5.0.
|
|
40
|
+
"@furystack/rest": "^5.0.2",
|
|
50
41
|
"path-to-regexp": "^6.2.1"
|
|
51
42
|
},
|
|
52
43
|
"devDependencies": {
|
package/src/create-client.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RestApi } from '@furystack/rest'
|
|
2
2
|
import { serializeToQueryString } from '@furystack/rest'
|
|
3
|
-
import { ResponseError } from './response-error'
|
|
3
|
+
import { ResponseError } from './response-error.js'
|
|
4
4
|
import { compile } from 'path-to-regexp'
|
|
5
5
|
export type BodyParameter<T> = T extends { result: unknown; body: infer U } ? { body: U } : unknown
|
|
6
6
|
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './create-client'
|
|
2
|
-
export * from './response-error'
|
|
1
|
+
export * from './create-client.js'
|
|
2
|
+
export * from './response-error.js'
|
package/types/index.d.ts
DELETED
package/types/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|