@readyfor/api-client-base 1.22.0-pr1284.8c3c6e8 → 1.22.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/dist/apiClientConfigStore.d.ts +10 -11
- package/dist/apiClientConfigStore.js +37 -10
- package/dist/apiClientConfigStore.mjs +12 -9
- package/dist/apiError.d.ts +25 -24
- package/dist/apiError.js +95 -68
- package/dist/apiError.mjs +18 -70
- package/dist/chunk-3SEO7S3Q.mjs +23 -0
- package/dist/chunk-5JS6U5IM.mjs +37 -0
- package/dist/chunk-DH33ZDBG.mjs +19 -0
- package/dist/chunk-FNLUAQWC.mjs +80 -0
- package/dist/chunk-GD4RTKUU.mjs +22 -0
- package/dist/chunk-JCZWXJBU.mjs +10 -0
- package/dist/chunk-NOC6G3HZ.mjs +21 -0
- package/dist/chunk-NYICHGY2.mjs +30 -0
- package/dist/chunk-OVR3ZT2S.mjs +118 -0
- package/dist/chunk-QXFPBYPL.mjs +25 -0
- package/dist/chunk-TZUKIYFN.mjs +14 -0
- package/dist/chunk-WBQAMGXK.mjs +0 -0
- package/dist/fetcher.d.ts +7 -8
- package/dist/fetcher.js +125 -57
- package/dist/fetcher.mjs +20 -63
- package/dist/index.d.ts +10 -10
- package/dist/index.js +38 -31
- package/dist/index.mjs +63 -10
- package/dist/react/ApiClientConfigProvider.d.ts +9 -10
- package/dist/react/ApiClientConfigProvider.js +41 -24
- package/dist/react/ApiClientConfigProvider.mjs +12 -22
- package/dist/react/index.d.ts +7 -4
- package/dist/react/index.js +26 -10
- package/dist/react/index.mjs +24 -4
- package/dist/react/swr.d.ts +9 -10
- package/dist/react/swr.js +37 -24
- package/dist/react/swr.mjs +5 -25
- package/dist/react/useApiClientConfig.d.ts +5 -5
- package/dist/react/useApiClientConfig.js +50 -18
- package/dist/react/useApiClientConfig.mjs +15 -19
- package/dist/requestUrl.d.ts +2 -3
- package/dist/requestUrl.js +49 -14
- package/dist/requestUrl.mjs +10 -13
- package/dist/store.d.ts +5 -6
- package/dist/store.js +43 -20
- package/dist/store.mjs +5 -20
- package/dist/types.d.ts +11 -5
- package/dist/types.js +16 -0
- package/dist/types.mjs +1 -1
- package/dist/utils/headersInit.d.ts +2 -3
- package/dist/utils/headersInit.js +49 -45
- package/dist/utils/headersInit.mjs +7 -46
- package/dist/utils/requestInit.d.ts +3 -10
- package/dist/utils/requestInit.js +31 -14
- package/dist/utils/requestInit.mjs +7 -15
- package/dist/zod.d.ts +3 -4
- package/dist/zod.js +30 -6
- package/dist/zod.mjs +7 -6
- package/package.json +18 -3
- package/dist/_virtual/_rolldown/runtime.js +0 -23
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/utils/headersInit.ts
|
|
2
|
+
var mergeHeadersInit = (baseHeadersInit, overrideHeadersInit) => {
|
|
3
|
+
const base = new Headers(baseHeadersInit);
|
|
4
|
+
const override = new Headers(overrideHeadersInit);
|
|
5
|
+
const setCookies = base.getSetCookie().concat(override.getSetCookie());
|
|
6
|
+
base.delete("set-cookie");
|
|
7
|
+
override.delete("set-cookie");
|
|
8
|
+
const mergedHeaders = new Headers({
|
|
9
|
+
...Object.fromEntries(base),
|
|
10
|
+
...Object.fromEntries(override)
|
|
11
|
+
});
|
|
12
|
+
setCookies.forEach((cookie) => {
|
|
13
|
+
mergedHeaders.append("set-cookie", cookie);
|
|
14
|
+
});
|
|
15
|
+
return mergedHeaders;
|
|
16
|
+
};
|
|
17
|
+
var toHeadersInit = (headers) => {
|
|
18
|
+
const result = {};
|
|
19
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
20
|
+
if (value !== void 0) {
|
|
21
|
+
result[key] = String(value);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
mergeHeadersInit,
|
|
29
|
+
toHeadersInit
|
|
30
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HTTPError,
|
|
3
|
+
errorStatusCode
|
|
4
|
+
} from "./chunk-FNLUAQWC.mjs";
|
|
5
|
+
import {
|
|
6
|
+
store
|
|
7
|
+
} from "./chunk-NOC6G3HZ.mjs";
|
|
8
|
+
import {
|
|
9
|
+
mergeRequestInit
|
|
10
|
+
} from "./chunk-TZUKIYFN.mjs";
|
|
11
|
+
|
|
12
|
+
// src/fetcher.ts
|
|
13
|
+
var defaultRequestInit = {
|
|
14
|
+
credentials: "include"
|
|
15
|
+
};
|
|
16
|
+
var createJsonFetcher = (schema, customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
17
|
+
input,
|
|
18
|
+
mergeRequestInit(
|
|
19
|
+
defaultRequestInit,
|
|
20
|
+
mergeRequestInit(customRequestInit, requestInit)
|
|
21
|
+
)
|
|
22
|
+
).then(async (res) => {
|
|
23
|
+
const text = await res.text();
|
|
24
|
+
const body = text ? JSON.parse(text) : {};
|
|
25
|
+
if (res.ok) return body;
|
|
26
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
27
|
+
const error = new HTTPError(code, body);
|
|
28
|
+
throw error;
|
|
29
|
+
}).catch((error) => {
|
|
30
|
+
store.getState().onError?.(error);
|
|
31
|
+
throw error;
|
|
32
|
+
}).then((parsedResponse) => {
|
|
33
|
+
const result = schema.safeParse(parsedResponse);
|
|
34
|
+
const config = store.getState();
|
|
35
|
+
if (result.success) {
|
|
36
|
+
return result.data;
|
|
37
|
+
}
|
|
38
|
+
if (config.showsSchemaParseError) {
|
|
39
|
+
console.error(result.error);
|
|
40
|
+
}
|
|
41
|
+
if (config.forceDeserializeResponse) {
|
|
42
|
+
config.onFailedDeserializeResponse(input, result.error);
|
|
43
|
+
return parsedResponse;
|
|
44
|
+
}
|
|
45
|
+
throw result.error;
|
|
46
|
+
});
|
|
47
|
+
var createTextFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
48
|
+
input,
|
|
49
|
+
mergeRequestInit(
|
|
50
|
+
defaultRequestInit,
|
|
51
|
+
mergeRequestInit(customRequestInit, requestInit)
|
|
52
|
+
)
|
|
53
|
+
).then(async (res) => {
|
|
54
|
+
const body = await res.text();
|
|
55
|
+
if (res.ok) return body;
|
|
56
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
57
|
+
const error = new HTTPError(code, body);
|
|
58
|
+
throw error;
|
|
59
|
+
}).catch((error) => {
|
|
60
|
+
store.getState().onError?.(error);
|
|
61
|
+
throw error;
|
|
62
|
+
});
|
|
63
|
+
var createBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
64
|
+
input,
|
|
65
|
+
mergeRequestInit(
|
|
66
|
+
defaultRequestInit,
|
|
67
|
+
mergeRequestInit(customRequestInit, requestInit)
|
|
68
|
+
)
|
|
69
|
+
).then(async (res) => {
|
|
70
|
+
const body = await res.blob();
|
|
71
|
+
if (res.ok) return { body, headers: res.headers };
|
|
72
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
73
|
+
const error = new HTTPError(code, body);
|
|
74
|
+
throw error;
|
|
75
|
+
}).catch((error) => {
|
|
76
|
+
store.getState().onError?.(error);
|
|
77
|
+
throw error;
|
|
78
|
+
});
|
|
79
|
+
var createFileOrBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
80
|
+
input,
|
|
81
|
+
mergeRequestInit(
|
|
82
|
+
defaultRequestInit,
|
|
83
|
+
mergeRequestInit(customRequestInit, requestInit)
|
|
84
|
+
)
|
|
85
|
+
).then(async (res) => {
|
|
86
|
+
const body = await res.blob();
|
|
87
|
+
if (res.ok) return { body, headers: res.headers };
|
|
88
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
89
|
+
const error = new HTTPError(code, body);
|
|
90
|
+
throw error;
|
|
91
|
+
}).catch((error) => {
|
|
92
|
+
store.getState().onError?.(error);
|
|
93
|
+
throw error;
|
|
94
|
+
});
|
|
95
|
+
var createVoidFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
96
|
+
input,
|
|
97
|
+
mergeRequestInit(
|
|
98
|
+
defaultRequestInit,
|
|
99
|
+
mergeRequestInit(customRequestInit, requestInit)
|
|
100
|
+
)
|
|
101
|
+
).then(async (res) => {
|
|
102
|
+
if (res.ok) return;
|
|
103
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
104
|
+
const body = await res.text();
|
|
105
|
+
const error = new HTTPError(code, body);
|
|
106
|
+
throw error;
|
|
107
|
+
}).catch((error) => {
|
|
108
|
+
store.getState().onError?.(error);
|
|
109
|
+
throw error;
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
export {
|
|
113
|
+
createJsonFetcher,
|
|
114
|
+
createTextFetcher,
|
|
115
|
+
createBlobFetcher,
|
|
116
|
+
createFileOrBlobFetcher,
|
|
117
|
+
createVoidFetcher
|
|
118
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSwrConfig
|
|
3
|
+
} from "./chunk-DH33ZDBG.mjs";
|
|
4
|
+
import {
|
|
5
|
+
store
|
|
6
|
+
} from "./chunk-NOC6G3HZ.mjs";
|
|
7
|
+
|
|
8
|
+
// src/react/ApiClientConfigProvider.tsx
|
|
9
|
+
import { createContext, useContext, useEffect } from "react";
|
|
10
|
+
import { SWRConfig } from "swr";
|
|
11
|
+
import { jsx } from "react/jsx-runtime";
|
|
12
|
+
var ApiClientConfigContext = createContext(store);
|
|
13
|
+
var ApiClientConfigProvider = (props) => {
|
|
14
|
+
const { swr, ...config } = props.config;
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
store.setState(() => config);
|
|
17
|
+
}, [config]);
|
|
18
|
+
return /* @__PURE__ */ jsx(ApiClientConfigContext.Provider, { value: store, children: /* @__PURE__ */ jsx(SWRConfig, { value: createSwrConfig(swr), children: props.children }) });
|
|
19
|
+
};
|
|
20
|
+
var useApiClientConfigContext = () => useContext(ApiClientConfigContext) || store;
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
ApiClientConfigProvider,
|
|
24
|
+
useApiClientConfigContext
|
|
25
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mergeHeadersInit
|
|
3
|
+
} from "./chunk-NYICHGY2.mjs";
|
|
4
|
+
|
|
5
|
+
// src/utils/requestInit.ts
|
|
6
|
+
var mergeRequestInit = ({ headers: baseHeaders, ...base }, { headers: overrideHeaders, ...override }) => ({
|
|
7
|
+
...base,
|
|
8
|
+
...override,
|
|
9
|
+
headers: baseHeaders === void 0 ? overrideHeaders : overrideHeaders === void 0 ? baseHeaders : mergeHeadersInit(baseHeaders, overrideHeaders)
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
mergeRequestInit
|
|
14
|
+
};
|
|
File without changes
|
package/dist/fetcher.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
-
//#region src/fetcher.d.ts
|
|
4
3
|
declare const createJsonFetcher: <T = never>(schema: z.ZodType<T>, customRequestInit?: RequestInit) => (input: RequestInfo, requestInit?: RequestInit) => Promise<T>;
|
|
5
4
|
declare const createTextFetcher: (customRequestInit?: RequestInit) => (input: RequestInfo, requestInit?: RequestInit) => Promise<string>;
|
|
6
5
|
type BlobFetcherResponse = {
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
body: Blob;
|
|
7
|
+
headers: Headers;
|
|
9
8
|
};
|
|
10
9
|
declare const createBlobFetcher: (customRequestInit?: RequestInit) => (input: RequestInfo, requestInit?: RequestInit) => Promise<BlobFetcherResponse>;
|
|
11
10
|
type FileOrBlobFetcherResponse = {
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
body: File | Blob;
|
|
12
|
+
headers: Headers;
|
|
14
13
|
};
|
|
15
14
|
declare const createFileOrBlobFetcher: (customRequestInit?: RequestInit) => (input: RequestInfo, requestInit?: RequestInit) => Promise<FileOrBlobFetcherResponse>;
|
|
16
15
|
declare const createVoidFetcher: (customRequestInit?: RequestInit) => (input: RequestInfo, requestInit?: RequestInit) => Promise<void>;
|
|
17
|
-
|
|
18
|
-
export { BlobFetcherResponse, FileOrBlobFetcherResponse, createBlobFetcher, createFileOrBlobFetcher, createJsonFetcher, createTextFetcher, createVoidFetcher };
|
|
16
|
+
|
|
17
|
+
export { type BlobFetcherResponse, type FileOrBlobFetcherResponse, createBlobFetcher, createFileOrBlobFetcher, createJsonFetcher, createTextFetcher, createVoidFetcher };
|
package/dist/fetcher.js
CHANGED
|
@@ -1,68 +1,136 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var fetcher_exports = {};
|
|
20
|
+
__export(fetcher_exports, {
|
|
21
|
+
createBlobFetcher: () => createBlobFetcher,
|
|
22
|
+
createFileOrBlobFetcher: () => createFileOrBlobFetcher,
|
|
23
|
+
createJsonFetcher: () => createJsonFetcher,
|
|
24
|
+
createTextFetcher: () => createTextFetcher,
|
|
25
|
+
createVoidFetcher: () => createVoidFetcher
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(fetcher_exports);
|
|
28
|
+
var import_apiError = require("./apiError");
|
|
29
|
+
var import_apiClientConfigStore = require("./apiClientConfigStore");
|
|
30
|
+
var import_requestInit = require("./utils/requestInit");
|
|
31
|
+
const defaultRequestInit = {
|
|
32
|
+
credentials: "include"
|
|
33
|
+
};
|
|
34
|
+
const createJsonFetcher = (schema, customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
35
|
+
input,
|
|
36
|
+
(0, import_requestInit.mergeRequestInit)(
|
|
37
|
+
defaultRequestInit,
|
|
38
|
+
(0, import_requestInit.mergeRequestInit)(customRequestInit, requestInit)
|
|
39
|
+
)
|
|
40
|
+
).then(async (res) => {
|
|
41
|
+
const text = await res.text();
|
|
42
|
+
const body = text ? JSON.parse(text) : {};
|
|
43
|
+
if (res.ok) return body;
|
|
44
|
+
const code = Object.values(import_apiError.errorStatusCode).includes(res.status) ? res.status : 999;
|
|
45
|
+
const error = new import_apiError.HTTPError(code, body);
|
|
46
|
+
throw error;
|
|
12
47
|
}).catch((error) => {
|
|
13
|
-
|
|
14
|
-
|
|
48
|
+
import_apiClientConfigStore.store.getState().onError?.(error);
|
|
49
|
+
throw error;
|
|
15
50
|
}).then((parsedResponse) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
51
|
+
const result = schema.safeParse(parsedResponse);
|
|
52
|
+
const config = import_apiClientConfigStore.store.getState();
|
|
53
|
+
if (result.success) {
|
|
54
|
+
return result.data;
|
|
55
|
+
}
|
|
56
|
+
if (config.showsSchemaParseError) {
|
|
57
|
+
console.error(result.error);
|
|
58
|
+
}
|
|
59
|
+
if (config.forceDeserializeResponse) {
|
|
60
|
+
config.onFailedDeserializeResponse(input, result.error);
|
|
61
|
+
return parsedResponse;
|
|
62
|
+
}
|
|
63
|
+
throw result.error;
|
|
25
64
|
});
|
|
26
|
-
const createTextFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
65
|
+
const createTextFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
66
|
+
input,
|
|
67
|
+
(0, import_requestInit.mergeRequestInit)(
|
|
68
|
+
defaultRequestInit,
|
|
69
|
+
(0, import_requestInit.mergeRequestInit)(customRequestInit, requestInit)
|
|
70
|
+
)
|
|
71
|
+
).then(async (res) => {
|
|
72
|
+
const body = await res.text();
|
|
73
|
+
if (res.ok) return body;
|
|
74
|
+
const code = Object.values(import_apiError.errorStatusCode).includes(res.status) ? res.status : 999;
|
|
75
|
+
const error = new import_apiError.HTTPError(code, body);
|
|
76
|
+
throw error;
|
|
30
77
|
}).catch((error) => {
|
|
31
|
-
|
|
32
|
-
|
|
78
|
+
import_apiClientConfigStore.store.getState().onError?.(error);
|
|
79
|
+
throw error;
|
|
33
80
|
});
|
|
34
|
-
const createBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
81
|
+
const createBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
82
|
+
input,
|
|
83
|
+
(0, import_requestInit.mergeRequestInit)(
|
|
84
|
+
defaultRequestInit,
|
|
85
|
+
(0, import_requestInit.mergeRequestInit)(customRequestInit, requestInit)
|
|
86
|
+
)
|
|
87
|
+
).then(async (res) => {
|
|
88
|
+
const body = await res.blob();
|
|
89
|
+
if (res.ok) return { body, headers: res.headers };
|
|
90
|
+
const code = Object.values(import_apiError.errorStatusCode).includes(res.status) ? res.status : 999;
|
|
91
|
+
const error = new import_apiError.HTTPError(code, body);
|
|
92
|
+
throw error;
|
|
41
93
|
}).catch((error) => {
|
|
42
|
-
|
|
43
|
-
|
|
94
|
+
import_apiClientConfigStore.store.getState().onError?.(error);
|
|
95
|
+
throw error;
|
|
44
96
|
});
|
|
45
|
-
const createFileOrBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
97
|
+
const createFileOrBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
98
|
+
input,
|
|
99
|
+
(0, import_requestInit.mergeRequestInit)(
|
|
100
|
+
defaultRequestInit,
|
|
101
|
+
(0, import_requestInit.mergeRequestInit)(customRequestInit, requestInit)
|
|
102
|
+
)
|
|
103
|
+
).then(async (res) => {
|
|
104
|
+
const body = await res.blob();
|
|
105
|
+
if (res.ok) return { body, headers: res.headers };
|
|
106
|
+
const code = Object.values(import_apiError.errorStatusCode).includes(res.status) ? res.status : 999;
|
|
107
|
+
const error = new import_apiError.HTTPError(code, body);
|
|
108
|
+
throw error;
|
|
52
109
|
}).catch((error) => {
|
|
53
|
-
|
|
54
|
-
|
|
110
|
+
import_apiClientConfigStore.store.getState().onError?.(error);
|
|
111
|
+
throw error;
|
|
55
112
|
});
|
|
56
|
-
const createVoidFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
57
|
-
|
|
58
|
-
|
|
113
|
+
const createVoidFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
114
|
+
input,
|
|
115
|
+
(0, import_requestInit.mergeRequestInit)(
|
|
116
|
+
defaultRequestInit,
|
|
117
|
+
(0, import_requestInit.mergeRequestInit)(customRequestInit, requestInit)
|
|
118
|
+
)
|
|
119
|
+
).then(async (res) => {
|
|
120
|
+
if (res.ok) return;
|
|
121
|
+
const code = Object.values(import_apiError.errorStatusCode).includes(res.status) ? res.status : 999;
|
|
122
|
+
const body = await res.text();
|
|
123
|
+
const error = new import_apiError.HTTPError(code, body);
|
|
124
|
+
throw error;
|
|
59
125
|
}).catch((error) => {
|
|
60
|
-
|
|
61
|
-
|
|
126
|
+
import_apiClientConfigStore.store.getState().onError?.(error);
|
|
127
|
+
throw error;
|
|
128
|
+
});
|
|
129
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
130
|
+
0 && (module.exports = {
|
|
131
|
+
createBlobFetcher,
|
|
132
|
+
createFileOrBlobFetcher,
|
|
133
|
+
createJsonFetcher,
|
|
134
|
+
createTextFetcher,
|
|
135
|
+
createVoidFetcher
|
|
62
136
|
});
|
|
63
|
-
//#endregion
|
|
64
|
-
exports.createBlobFetcher = createBlobFetcher;
|
|
65
|
-
exports.createFileOrBlobFetcher = createFileOrBlobFetcher;
|
|
66
|
-
exports.createJsonFetcher = createJsonFetcher;
|
|
67
|
-
exports.createTextFetcher = createTextFetcher;
|
|
68
|
-
exports.createVoidFetcher = createVoidFetcher;
|
package/dist/fetcher.mjs
CHANGED
|
@@ -1,63 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return parsedResponse;
|
|
22
|
-
}
|
|
23
|
-
throw result.error;
|
|
24
|
-
});
|
|
25
|
-
const createTextFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
|
|
26
|
-
const body = await res.text();
|
|
27
|
-
if (res.ok) return body;
|
|
28
|
-
throw new HTTPError(Object.values(errorStatusCode).includes(res.status) ? res.status : 999, body);
|
|
29
|
-
}).catch((error) => {
|
|
30
|
-
store.getState().onError?.(error);
|
|
31
|
-
throw error;
|
|
32
|
-
});
|
|
33
|
-
const createBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
|
|
34
|
-
const body = await res.blob();
|
|
35
|
-
if (res.ok) return {
|
|
36
|
-
body,
|
|
37
|
-
headers: res.headers
|
|
38
|
-
};
|
|
39
|
-
throw new HTTPError(Object.values(errorStatusCode).includes(res.status) ? res.status : 999, body);
|
|
40
|
-
}).catch((error) => {
|
|
41
|
-
store.getState().onError?.(error);
|
|
42
|
-
throw error;
|
|
43
|
-
});
|
|
44
|
-
const createFileOrBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
|
|
45
|
-
const body = await res.blob();
|
|
46
|
-
if (res.ok) return {
|
|
47
|
-
body,
|
|
48
|
-
headers: res.headers
|
|
49
|
-
};
|
|
50
|
-
throw new HTTPError(Object.values(errorStatusCode).includes(res.status) ? res.status : 999, body);
|
|
51
|
-
}).catch((error) => {
|
|
52
|
-
store.getState().onError?.(error);
|
|
53
|
-
throw error;
|
|
54
|
-
});
|
|
55
|
-
const createVoidFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
|
|
56
|
-
if (res.ok) return;
|
|
57
|
-
throw new HTTPError(Object.values(errorStatusCode).includes(res.status) ? res.status : 999, await res.text());
|
|
58
|
-
}).catch((error) => {
|
|
59
|
-
store.getState().onError?.(error);
|
|
60
|
-
throw error;
|
|
61
|
-
});
|
|
62
|
-
//#endregion
|
|
63
|
-
export { createBlobFetcher, createFileOrBlobFetcher, createJsonFetcher, createTextFetcher, createVoidFetcher };
|
|
1
|
+
import {
|
|
2
|
+
createBlobFetcher,
|
|
3
|
+
createFileOrBlobFetcher,
|
|
4
|
+
createJsonFetcher,
|
|
5
|
+
createTextFetcher,
|
|
6
|
+
createVoidFetcher
|
|
7
|
+
} from "./chunk-OVR3ZT2S.mjs";
|
|
8
|
+
import "./chunk-FNLUAQWC.mjs";
|
|
9
|
+
import "./chunk-NOC6G3HZ.mjs";
|
|
10
|
+
import "./chunk-TZUKIYFN.mjs";
|
|
11
|
+
import "./chunk-NYICHGY2.mjs";
|
|
12
|
+
import "./chunk-3SEO7S3Q.mjs";
|
|
13
|
+
import "./chunk-JCZWXJBU.mjs";
|
|
14
|
+
export {
|
|
15
|
+
createBlobFetcher,
|
|
16
|
+
createFileOrBlobFetcher,
|
|
17
|
+
createJsonFetcher,
|
|
18
|
+
createTextFetcher,
|
|
19
|
+
createVoidFetcher
|
|
20
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
export { Config, RequestConfig, buildRequestInitWithDefaultConfig, setApiClientConfig, store } from './apiClientConfigStore.js';
|
|
2
|
+
export { ErrorStatusCode, HTTPError, errorStatusCode, errorTitle, getErrorStatus, getHttpErrorBody, getHttpErrorBodyReason, isHttpErrorWithStatus } from './apiError.js';
|
|
3
|
+
export { BlobFetcherResponse, FileOrBlobFetcherResponse, createBlobFetcher, createFileOrBlobFetcher, createJsonFetcher, createTextFetcher, createVoidFetcher } from './fetcher.js';
|
|
4
|
+
export { __internal__requestUrl } from './requestUrl.js';
|
|
5
|
+
export { Store, createStore } from './store.js';
|
|
6
|
+
export { ForceDig, QueryPropsFor } from './types.js';
|
|
7
|
+
export { isZodError, schemaForType } from './zod.js';
|
|
8
|
+
export { mergeRequestInit } from './utils/requestInit.js';
|
|
9
|
+
export { mergeHeadersInit, toHeadersInit } from './utils/headersInit.js';
|
|
10
|
+
import 'zod';
|
package/dist/index.js
CHANGED
|
@@ -1,31 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
exports
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
exports
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var index_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(index_exports);
|
|
18
|
+
__reExport(index_exports, require("./apiClientConfigStore"), module.exports);
|
|
19
|
+
__reExport(index_exports, require("./apiError"), module.exports);
|
|
20
|
+
__reExport(index_exports, require("./fetcher"), module.exports);
|
|
21
|
+
__reExport(index_exports, require("./requestUrl"), module.exports);
|
|
22
|
+
__reExport(index_exports, require("./store"), module.exports);
|
|
23
|
+
__reExport(index_exports, require("./types"), module.exports);
|
|
24
|
+
__reExport(index_exports, require("./zod"), module.exports);
|
|
25
|
+
__reExport(index_exports, require("./utils/requestInit"), module.exports);
|
|
26
|
+
__reExport(index_exports, require("./utils/headersInit"), module.exports);
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
...require("./apiClientConfigStore"),
|
|
30
|
+
...require("./apiError"),
|
|
31
|
+
...require("./fetcher"),
|
|
32
|
+
...require("./requestUrl"),
|
|
33
|
+
...require("./store"),
|
|
34
|
+
...require("./types"),
|
|
35
|
+
...require("./zod"),
|
|
36
|
+
...require("./utils/requestInit"),
|
|
37
|
+
...require("./utils/headersInit")
|
|
38
|
+
});
|