@readyfor/api-client-base 0.246.0 → 0.247.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.mjs +8 -9
- package/dist/apiError.mjs +7 -55
- package/dist/chunk-2ORFVC4H.mjs +14 -0
- package/dist/chunk-3SEO7S3Q.mjs +23 -0
- package/dist/chunk-DH33ZDBG.mjs +19 -0
- package/dist/chunk-E3EKMNYV.mjs +100 -0
- package/dist/chunk-EYKOWAWU.mjs +22 -0
- package/dist/chunk-GIFAQKW5.mjs +20 -0
- package/dist/chunk-JCZWXJBU.mjs +10 -0
- package/dist/chunk-PY35XWDS.mjs +66 -0
- package/dist/chunk-T2LQ4KT5.mjs +25 -0
- package/dist/chunk-WBQAMGXK.mjs +0 -0
- package/dist/chunk-X4CTIU5H.mjs +37 -0
- package/dist/chunk-Z2IX5DM2.mjs +21 -0
- package/dist/fetcher.mjs +12 -84
- package/dist/index.mjs +50 -8
- package/dist/react/ApiClientConfigProvider.mjs +9 -14
- package/dist/react/index.mjs +24 -3
- package/dist/react/swr.mjs +3 -14
- package/dist/react/useApiClientConfig.mjs +11 -25
- package/dist/requestUrl.mjs +7 -14
- package/dist/store.mjs +3 -18
- package/dist/types.mjs +1 -0
- package/dist/utils/headersInit.mjs +3 -15
- package/dist/utils/requestInit.mjs +4 -6
- package/dist/zod.mjs +4 -4
- package/package.json +2 -2
- package/dist/apiClientConfigStore.d.mts +0 -22
- package/dist/apiError.d.mts +0 -30
- package/dist/fetcher.d.mts +0 -12
- package/dist/index.d.mts +0 -9
- package/dist/react/ApiClientConfigProvider.d.mts +0 -16
- package/dist/react/index.d.mts +0 -7
- package/dist/react/swr.d.mts +0 -13
- package/dist/react/useApiClientConfig.d.mts +0 -8
- package/dist/requestUrl.d.mts +0 -3
- package/dist/store.d.mts +0 -13
- package/dist/types.d.mts +0 -12
- package/dist/utils/headersInit.d.mts +0 -17
- package/dist/utils/requestInit.d.mts +0 -9
- package/dist/zod.d.mts +0 -6
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
buildRequestInitWithDefaultConfig,
|
|
3
|
+
setApiClientConfig,
|
|
4
|
+
store
|
|
5
|
+
} from "./chunk-Z2IX5DM2.mjs";
|
|
6
|
+
import "./chunk-2ORFVC4H.mjs";
|
|
7
|
+
import "./chunk-GIFAQKW5.mjs";
|
|
8
|
+
import "./chunk-3SEO7S3Q.mjs";
|
|
10
9
|
export {
|
|
11
10
|
buildRequestInitWithDefaultConfig,
|
|
12
11
|
setApiClientConfig,
|
package/dist/apiError.mjs
CHANGED
|
@@ -1,58 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
NOT_FOUND: 404,
|
|
9
|
-
PAYLOAD_TOO_LARGE: 413,
|
|
10
|
-
NETWORK_ERROR: 418,
|
|
11
|
-
UNPROCESSABLE_ENTITY: 422,
|
|
12
|
-
INTERNAL_SERVER_ERROR: 500,
|
|
13
|
-
BAD_GATEWAY: 502,
|
|
14
|
-
SERVER_UNAVAILABLE: 503,
|
|
15
|
-
GATEWAY_TIMEOUT: 504,
|
|
16
|
-
ZOD_ERROR: 901,
|
|
17
|
-
UNHANDLED_ERROR: 999
|
|
18
|
-
};
|
|
19
|
-
const errorTitle = {
|
|
20
|
-
301: "\u30DA\u30FC\u30B8\u304C\u79FB\u52D5\u3055\u308C\u3066\u3044\u307E\u3059",
|
|
21
|
-
302: "\u30DA\u30FC\u30B8\u304C\u4E00\u6642\u7684\u306B\u79FB\u52D5\u3055\u308C\u3066\u3044\u307E\u3059",
|
|
22
|
-
400: "\u30EA\u30AF\u30A8\u30B9\u30C8\u304C\u4E0D\u6B63\u3067\u3059",
|
|
23
|
-
401: "\u30ED\u30B0\u30A4\u30F3\u3057\u3066\u304F\u3060\u3055\u3044",
|
|
24
|
-
403: "\u4E0D\u6B63\u306A\u30C8\u30FC\u30AF\u30F3\u3067\u3059",
|
|
25
|
-
404: "\u30DA\u30FC\u30B8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3067\u3057\u305F",
|
|
26
|
-
413: "\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
|
|
27
|
-
418: "\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
|
|
28
|
-
422: "\u30C7\u30FC\u30BF\u304C\u4E0D\u6B63\u3067\u3059",
|
|
29
|
-
500: "\u30B5\u30FC\u30D0\u30FC\u3067\u30A8\u30E9\u30FC\u304C\u8D77\u304D\u307E\u3057\u305F",
|
|
30
|
-
502: "\u30B5\u30FC\u30D0\u30FC\u3067\u30A8\u30E9\u30FC\u304C\u8D77\u304D\u307E\u3057\u305F",
|
|
31
|
-
503: "\u30E1\u30F3\u30C6\u30CA\u30F3\u30B9\u4E2D\u3067\u3059",
|
|
32
|
-
504: "\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
|
|
33
|
-
901: "\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F",
|
|
34
|
-
999: "\u30B5\u30FC\u30D0\u30FC\u3067\u30A8\u30E9\u30FC\u304C\u8D77\u304D\u307E\u3057\u305F"
|
|
35
|
-
};
|
|
36
|
-
class HTTPError extends Error {
|
|
37
|
-
status;
|
|
38
|
-
body;
|
|
39
|
-
constructor(status, body) {
|
|
40
|
-
super(errorTitle[status]);
|
|
41
|
-
this.name = "HTTPError";
|
|
42
|
-
this.status = status;
|
|
43
|
-
this.body = body;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const getErrorStatus = (response) => {
|
|
47
|
-
if (response instanceof Object && "status" in response && typeof response["status"] === "number") {
|
|
48
|
-
const status = Number(response["status"]);
|
|
49
|
-
return Object.values(errorStatusCode).includes(status) ? status : 999;
|
|
50
|
-
}
|
|
51
|
-
if (isZodError(response)) {
|
|
52
|
-
return errorStatusCode.ZOD_ERROR;
|
|
53
|
-
}
|
|
54
|
-
return void 0;
|
|
55
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
HTTPError,
|
|
3
|
+
errorStatusCode,
|
|
4
|
+
errorTitle,
|
|
5
|
+
getErrorStatus
|
|
6
|
+
} from "./chunk-PY35XWDS.mjs";
|
|
7
|
+
import "./chunk-JCZWXJBU.mjs";
|
|
56
8
|
export {
|
|
57
9
|
HTTPError,
|
|
58
10
|
errorStatusCode,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mergeHeadersInit
|
|
3
|
+
} from "./chunk-GIFAQKW5.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
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/store.ts
|
|
2
|
+
var createStore = (initialState) => {
|
|
3
|
+
let state = initialState;
|
|
4
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
5
|
+
const getState = () => state;
|
|
6
|
+
const setState = (fn) => {
|
|
7
|
+
state = fn(state);
|
|
8
|
+
listeners.forEach((listener) => listener());
|
|
9
|
+
};
|
|
10
|
+
const subscribe = (listener) => {
|
|
11
|
+
listeners.add(listener);
|
|
12
|
+
return () => listeners.delete(listener);
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
getState,
|
|
16
|
+
setState,
|
|
17
|
+
subscribe
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
createStore
|
|
23
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/react/swr.ts
|
|
2
|
+
import { useRef } from "react";
|
|
3
|
+
var abortMiddleware = (useSWRNext) => (key, fetcher, config) => {
|
|
4
|
+
const ctrlRef = useRef(void 0);
|
|
5
|
+
const extendedFetcher = fetcher ? (key2, params) => {
|
|
6
|
+
ctrlRef.current?.abort();
|
|
7
|
+
ctrlRef.current = new AbortController();
|
|
8
|
+
return fetcher(key2, { ...params, signal: ctrlRef.current.signal });
|
|
9
|
+
} : fetcher;
|
|
10
|
+
return useSWRNext(key, extendedFetcher, config);
|
|
11
|
+
};
|
|
12
|
+
var createSwrConfig = (config) => ({
|
|
13
|
+
...config,
|
|
14
|
+
use: [...config?.use ?? [], abortMiddleware]
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
createSwrConfig
|
|
19
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HTTPError,
|
|
3
|
+
errorStatusCode
|
|
4
|
+
} from "./chunk-PY35XWDS.mjs";
|
|
5
|
+
import {
|
|
6
|
+
store
|
|
7
|
+
} from "./chunk-Z2IX5DM2.mjs";
|
|
8
|
+
import {
|
|
9
|
+
mergeRequestInit
|
|
10
|
+
} from "./chunk-2ORFVC4H.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 body = await res.json();
|
|
24
|
+
if (res.ok) return body;
|
|
25
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
26
|
+
const error = new HTTPError(code, body);
|
|
27
|
+
throw error;
|
|
28
|
+
}).catch((error) => {
|
|
29
|
+
store.getState().onError?.(error);
|
|
30
|
+
throw error;
|
|
31
|
+
}).then((parsedResponse) => {
|
|
32
|
+
const result = schema.safeParse(parsedResponse);
|
|
33
|
+
const config = store.getState();
|
|
34
|
+
if (result.success) {
|
|
35
|
+
return result.data;
|
|
36
|
+
}
|
|
37
|
+
if (config.showsSchemaParseError) {
|
|
38
|
+
console.error(result.error);
|
|
39
|
+
}
|
|
40
|
+
if (config.forceDeserializeResponse) {
|
|
41
|
+
config.onFailedDeserializeResponse(input, result.error);
|
|
42
|
+
return parsedResponse;
|
|
43
|
+
}
|
|
44
|
+
throw result.error;
|
|
45
|
+
});
|
|
46
|
+
var createTextFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
47
|
+
input,
|
|
48
|
+
mergeRequestInit(
|
|
49
|
+
defaultRequestInit,
|
|
50
|
+
mergeRequestInit(customRequestInit, requestInit)
|
|
51
|
+
)
|
|
52
|
+
).then(async (res) => {
|
|
53
|
+
const body = await res.text();
|
|
54
|
+
if (res.ok) return body;
|
|
55
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
56
|
+
const error = new HTTPError(code, body);
|
|
57
|
+
throw error;
|
|
58
|
+
}).catch((error) => {
|
|
59
|
+
store.getState().onError?.(error);
|
|
60
|
+
throw error;
|
|
61
|
+
});
|
|
62
|
+
var createBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
63
|
+
input,
|
|
64
|
+
mergeRequestInit(
|
|
65
|
+
defaultRequestInit,
|
|
66
|
+
mergeRequestInit(customRequestInit, requestInit)
|
|
67
|
+
)
|
|
68
|
+
).then(async (res) => {
|
|
69
|
+
const body = await res.blob();
|
|
70
|
+
if (res.ok) return { body, headers: res.headers };
|
|
71
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
72
|
+
const error = new HTTPError(code, body);
|
|
73
|
+
throw error;
|
|
74
|
+
}).catch((error) => {
|
|
75
|
+
store.getState().onError?.(error);
|
|
76
|
+
throw error;
|
|
77
|
+
});
|
|
78
|
+
var createVoidFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
79
|
+
input,
|
|
80
|
+
mergeRequestInit(
|
|
81
|
+
defaultRequestInit,
|
|
82
|
+
mergeRequestInit(customRequestInit, requestInit)
|
|
83
|
+
)
|
|
84
|
+
).then(async (res) => {
|
|
85
|
+
if (res.ok) return;
|
|
86
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
87
|
+
const body = await res.text();
|
|
88
|
+
const error = new HTTPError(code, body);
|
|
89
|
+
throw error;
|
|
90
|
+
}).catch((error) => {
|
|
91
|
+
store.getState().onError?.(error);
|
|
92
|
+
throw error;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
export {
|
|
96
|
+
createJsonFetcher,
|
|
97
|
+
createTextFetcher,
|
|
98
|
+
createBlobFetcher,
|
|
99
|
+
createVoidFetcher
|
|
100
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
store
|
|
3
|
+
} from "./chunk-Z2IX5DM2.mjs";
|
|
4
|
+
|
|
5
|
+
// src/requestUrl.ts
|
|
6
|
+
import qs from "qs";
|
|
7
|
+
function __internal__requestUrl(...args) {
|
|
8
|
+
const config = store.getState();
|
|
9
|
+
const rawPath = args[0];
|
|
10
|
+
const params = args[1] || {};
|
|
11
|
+
const query = args[2];
|
|
12
|
+
const hostName = config.hostName ? typeof config.hostName === "string" ? config.hostName : config.hostName(rawPath) : "";
|
|
13
|
+
const path = hostName + Object.entries(params).reduce(
|
|
14
|
+
(path2, [key, value]) => path2.replace(`{${key}}`, String(value)),
|
|
15
|
+
rawPath
|
|
16
|
+
);
|
|
17
|
+
return query ? `${path}?${qs.stringify(query)}` : path;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
__internal__requestUrl
|
|
22
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
|
|
18
|
+
export {
|
|
19
|
+
mergeHeadersInit
|
|
20
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isZodError
|
|
3
|
+
} from "./chunk-JCZWXJBU.mjs";
|
|
4
|
+
|
|
5
|
+
// src/apiError.ts
|
|
6
|
+
var errorStatusCode = {
|
|
7
|
+
MOVED_PERMANENTLY: 301,
|
|
8
|
+
FOUND: 302,
|
|
9
|
+
BAD_REQUEST: 400,
|
|
10
|
+
UNAUTHORIZED: 401,
|
|
11
|
+
FORBIDDEN: 403,
|
|
12
|
+
NOT_FOUND: 404,
|
|
13
|
+
PAYLOAD_TOO_LARGE: 413,
|
|
14
|
+
NETWORK_ERROR: 418,
|
|
15
|
+
UNPROCESSABLE_ENTITY: 422,
|
|
16
|
+
INTERNAL_SERVER_ERROR: 500,
|
|
17
|
+
BAD_GATEWAY: 502,
|
|
18
|
+
SERVER_UNAVAILABLE: 503,
|
|
19
|
+
GATEWAY_TIMEOUT: 504,
|
|
20
|
+
ZOD_ERROR: 901,
|
|
21
|
+
UNHANDLED_ERROR: 999
|
|
22
|
+
};
|
|
23
|
+
var errorTitle = {
|
|
24
|
+
301: "\u30DA\u30FC\u30B8\u304C\u79FB\u52D5\u3055\u308C\u3066\u3044\u307E\u3059",
|
|
25
|
+
302: "\u30DA\u30FC\u30B8\u304C\u4E00\u6642\u7684\u306B\u79FB\u52D5\u3055\u308C\u3066\u3044\u307E\u3059",
|
|
26
|
+
400: "\u30EA\u30AF\u30A8\u30B9\u30C8\u304C\u4E0D\u6B63\u3067\u3059",
|
|
27
|
+
401: "\u30ED\u30B0\u30A4\u30F3\u3057\u3066\u304F\u3060\u3055\u3044",
|
|
28
|
+
403: "\u4E0D\u6B63\u306A\u30C8\u30FC\u30AF\u30F3\u3067\u3059",
|
|
29
|
+
404: "\u30DA\u30FC\u30B8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3067\u3057\u305F",
|
|
30
|
+
413: "\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
|
|
31
|
+
418: "\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
|
|
32
|
+
422: "\u30C7\u30FC\u30BF\u304C\u4E0D\u6B63\u3067\u3059",
|
|
33
|
+
500: "\u30B5\u30FC\u30D0\u30FC\u3067\u30A8\u30E9\u30FC\u304C\u8D77\u304D\u307E\u3057\u305F",
|
|
34
|
+
502: "\u30B5\u30FC\u30D0\u30FC\u3067\u30A8\u30E9\u30FC\u304C\u8D77\u304D\u307E\u3057\u305F",
|
|
35
|
+
503: "\u30E1\u30F3\u30C6\u30CA\u30F3\u30B9\u4E2D\u3067\u3059",
|
|
36
|
+
504: "\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
|
|
37
|
+
901: "\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F",
|
|
38
|
+
999: "\u30B5\u30FC\u30D0\u30FC\u3067\u30A8\u30E9\u30FC\u304C\u8D77\u304D\u307E\u3057\u305F"
|
|
39
|
+
};
|
|
40
|
+
var HTTPError = class extends Error {
|
|
41
|
+
status;
|
|
42
|
+
body;
|
|
43
|
+
constructor(status, body) {
|
|
44
|
+
super(errorTitle[status]);
|
|
45
|
+
this.name = "HTTPError";
|
|
46
|
+
this.status = status;
|
|
47
|
+
this.body = body;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var getErrorStatus = (response) => {
|
|
51
|
+
if (response instanceof Object && "status" in response && typeof response["status"] === "number") {
|
|
52
|
+
const status = Number(response["status"]);
|
|
53
|
+
return Object.values(errorStatusCode).includes(status) ? status : 999;
|
|
54
|
+
}
|
|
55
|
+
if (isZodError(response)) {
|
|
56
|
+
return errorStatusCode.ZOD_ERROR;
|
|
57
|
+
}
|
|
58
|
+
return void 0;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export {
|
|
62
|
+
errorStatusCode,
|
|
63
|
+
errorTitle,
|
|
64
|
+
HTTPError,
|
|
65
|
+
getErrorStatus
|
|
66
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSwrConfig
|
|
3
|
+
} from "./chunk-DH33ZDBG.mjs";
|
|
4
|
+
import {
|
|
5
|
+
store
|
|
6
|
+
} from "./chunk-Z2IX5DM2.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
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useApiClientConfigContext
|
|
3
|
+
} from "./chunk-T2LQ4KT5.mjs";
|
|
4
|
+
import {
|
|
5
|
+
mergeRequestInit
|
|
6
|
+
} from "./chunk-2ORFVC4H.mjs";
|
|
7
|
+
|
|
8
|
+
// src/react/useApiClientConfig.ts
|
|
9
|
+
import { useMemo } from "react";
|
|
10
|
+
import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
|
|
11
|
+
import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector.js";
|
|
12
|
+
var useApiClientConfig = () => {
|
|
13
|
+
const store = useApiClientConfigContext();
|
|
14
|
+
return useSyncExternalStore(store.subscribe, store.getState);
|
|
15
|
+
};
|
|
16
|
+
var useApiClientConfigWithSelector = (selector) => {
|
|
17
|
+
const store = useApiClientConfigContext();
|
|
18
|
+
return useSyncExternalStoreWithSelector(
|
|
19
|
+
store.subscribe,
|
|
20
|
+
store.getState,
|
|
21
|
+
null,
|
|
22
|
+
selector
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
var useRequestInit = (customRequestInit = {}) => {
|
|
26
|
+
const { defaultRequestInit = {} } = useApiClientConfig();
|
|
27
|
+
return useMemo(
|
|
28
|
+
() => mergeRequestInit(defaultRequestInit, customRequestInit),
|
|
29
|
+
[defaultRequestInit, customRequestInit]
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export {
|
|
34
|
+
useApiClientConfig,
|
|
35
|
+
useApiClientConfigWithSelector,
|
|
36
|
+
useRequestInit
|
|
37
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mergeRequestInit
|
|
3
|
+
} from "./chunk-2ORFVC4H.mjs";
|
|
4
|
+
import {
|
|
5
|
+
createStore
|
|
6
|
+
} from "./chunk-3SEO7S3Q.mjs";
|
|
7
|
+
|
|
8
|
+
// src/apiClientConfigStore.ts
|
|
9
|
+
var defaultConfig = {};
|
|
10
|
+
var store = createStore(defaultConfig);
|
|
11
|
+
var setApiClientConfig = (config) => store.setState(() => config);
|
|
12
|
+
var buildRequestInitWithDefaultConfig = (customRequestInit = {}) => {
|
|
13
|
+
const { defaultRequestInit = {} } = store.getState();
|
|
14
|
+
return mergeRequestInit(defaultRequestInit, customRequestInit);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
store,
|
|
19
|
+
setApiClientConfig,
|
|
20
|
+
buildRequestInitWithDefaultConfig
|
|
21
|
+
};
|
package/dist/fetcher.mjs
CHANGED
|
@@ -1,87 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
).then(async (res) => {
|
|
14
|
-
const body = await res.json();
|
|
15
|
-
if (res.ok) return body;
|
|
16
|
-
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
17
|
-
const error = new HTTPError(code, body);
|
|
18
|
-
throw error;
|
|
19
|
-
}).catch((error) => {
|
|
20
|
-
store.getState().onError?.(error);
|
|
21
|
-
throw error;
|
|
22
|
-
}).then((parsedResponse) => {
|
|
23
|
-
const result = schema.safeParse(parsedResponse);
|
|
24
|
-
const config = store.getState();
|
|
25
|
-
if (result.success) {
|
|
26
|
-
return result.data;
|
|
27
|
-
}
|
|
28
|
-
if (config.showsSchemaParseError) {
|
|
29
|
-
console.error(result.error);
|
|
30
|
-
}
|
|
31
|
-
if (config.forceDeserializeResponse) {
|
|
32
|
-
config.onFailedDeserializeResponse(input, result.error);
|
|
33
|
-
return parsedResponse;
|
|
34
|
-
}
|
|
35
|
-
throw result.error;
|
|
36
|
-
});
|
|
37
|
-
const createTextFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
38
|
-
input,
|
|
39
|
-
mergeRequestInit(
|
|
40
|
-
defaultRequestInit,
|
|
41
|
-
mergeRequestInit(customRequestInit, requestInit)
|
|
42
|
-
)
|
|
43
|
-
).then(async (res) => {
|
|
44
|
-
const body = await res.text();
|
|
45
|
-
if (res.ok) return body;
|
|
46
|
-
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
47
|
-
const error = new HTTPError(code, body);
|
|
48
|
-
throw error;
|
|
49
|
-
}).catch((error) => {
|
|
50
|
-
store.getState().onError?.(error);
|
|
51
|
-
throw error;
|
|
52
|
-
});
|
|
53
|
-
const createBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
54
|
-
input,
|
|
55
|
-
mergeRequestInit(
|
|
56
|
-
defaultRequestInit,
|
|
57
|
-
mergeRequestInit(customRequestInit, requestInit)
|
|
58
|
-
)
|
|
59
|
-
).then(async (res) => {
|
|
60
|
-
const body = await res.blob();
|
|
61
|
-
if (res.ok) return { body, headers: res.headers };
|
|
62
|
-
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
63
|
-
const error = new HTTPError(code, body);
|
|
64
|
-
throw error;
|
|
65
|
-
}).catch((error) => {
|
|
66
|
-
store.getState().onError?.(error);
|
|
67
|
-
throw error;
|
|
68
|
-
});
|
|
69
|
-
const createVoidFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
70
|
-
input,
|
|
71
|
-
mergeRequestInit(
|
|
72
|
-
defaultRequestInit,
|
|
73
|
-
mergeRequestInit(customRequestInit, requestInit)
|
|
74
|
-
)
|
|
75
|
-
).then(async (res) => {
|
|
76
|
-
if (res.ok) return;
|
|
77
|
-
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
78
|
-
const body = await res.text();
|
|
79
|
-
const error = new HTTPError(code, body);
|
|
80
|
-
throw error;
|
|
81
|
-
}).catch((error) => {
|
|
82
|
-
store.getState().onError?.(error);
|
|
83
|
-
throw error;
|
|
84
|
-
});
|
|
1
|
+
import {
|
|
2
|
+
createBlobFetcher,
|
|
3
|
+
createJsonFetcher,
|
|
4
|
+
createTextFetcher,
|
|
5
|
+
createVoidFetcher
|
|
6
|
+
} from "./chunk-E3EKMNYV.mjs";
|
|
7
|
+
import "./chunk-PY35XWDS.mjs";
|
|
8
|
+
import "./chunk-Z2IX5DM2.mjs";
|
|
9
|
+
import "./chunk-2ORFVC4H.mjs";
|
|
10
|
+
import "./chunk-GIFAQKW5.mjs";
|
|
11
|
+
import "./chunk-3SEO7S3Q.mjs";
|
|
12
|
+
import "./chunk-JCZWXJBU.mjs";
|
|
85
13
|
export {
|
|
86
14
|
createBlobFetcher,
|
|
87
15
|
createJsonFetcher,
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import {
|
|
2
|
+
createBlobFetcher,
|
|
3
|
+
createJsonFetcher,
|
|
4
|
+
createTextFetcher,
|
|
5
|
+
createVoidFetcher
|
|
6
|
+
} from "./chunk-E3EKMNYV.mjs";
|
|
7
|
+
import {
|
|
8
|
+
HTTPError,
|
|
9
|
+
errorStatusCode,
|
|
10
|
+
errorTitle,
|
|
11
|
+
getErrorStatus
|
|
12
|
+
} from "./chunk-PY35XWDS.mjs";
|
|
13
|
+
import {
|
|
14
|
+
__internal__requestUrl
|
|
15
|
+
} from "./chunk-EYKOWAWU.mjs";
|
|
16
|
+
import {
|
|
17
|
+
buildRequestInitWithDefaultConfig,
|
|
18
|
+
setApiClientConfig,
|
|
19
|
+
store
|
|
20
|
+
} from "./chunk-Z2IX5DM2.mjs";
|
|
21
|
+
import {
|
|
22
|
+
mergeRequestInit
|
|
23
|
+
} from "./chunk-2ORFVC4H.mjs";
|
|
24
|
+
import "./chunk-GIFAQKW5.mjs";
|
|
25
|
+
import {
|
|
26
|
+
createStore
|
|
27
|
+
} from "./chunk-3SEO7S3Q.mjs";
|
|
28
|
+
import "./chunk-WBQAMGXK.mjs";
|
|
29
|
+
import {
|
|
30
|
+
isZodError,
|
|
31
|
+
schemaForType
|
|
32
|
+
} from "./chunk-JCZWXJBU.mjs";
|
|
33
|
+
export {
|
|
34
|
+
HTTPError,
|
|
35
|
+
__internal__requestUrl,
|
|
36
|
+
buildRequestInitWithDefaultConfig,
|
|
37
|
+
createBlobFetcher,
|
|
38
|
+
createJsonFetcher,
|
|
39
|
+
createStore,
|
|
40
|
+
createTextFetcher,
|
|
41
|
+
createVoidFetcher,
|
|
42
|
+
errorStatusCode,
|
|
43
|
+
errorTitle,
|
|
44
|
+
getErrorStatus,
|
|
45
|
+
isZodError,
|
|
46
|
+
mergeRequestInit,
|
|
47
|
+
schemaForType,
|
|
48
|
+
setApiClientConfig,
|
|
49
|
+
store
|
|
50
|
+
};
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
store.setState(() => config);
|
|
11
|
-
}, [config]);
|
|
12
|
-
return /* @__PURE__ */ jsx(ApiClientConfigContext.Provider, { value: store, children: /* @__PURE__ */ jsx(SWRConfig, { value: createSwrConfig(swr), children: props.children }) });
|
|
13
|
-
};
|
|
14
|
-
const useApiClientConfigContext = () => useContext(ApiClientConfigContext) || store;
|
|
1
|
+
import {
|
|
2
|
+
ApiClientConfigProvider,
|
|
3
|
+
useApiClientConfigContext
|
|
4
|
+
} from "../chunk-T2LQ4KT5.mjs";
|
|
5
|
+
import "../chunk-DH33ZDBG.mjs";
|
|
6
|
+
import "../chunk-Z2IX5DM2.mjs";
|
|
7
|
+
import "../chunk-2ORFVC4H.mjs";
|
|
8
|
+
import "../chunk-GIFAQKW5.mjs";
|
|
9
|
+
import "../chunk-3SEO7S3Q.mjs";
|
|
15
10
|
export {
|
|
16
11
|
ApiClientConfigProvider,
|
|
17
12
|
useApiClientConfigContext
|
package/dist/react/index.mjs
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
useApiClientConfig,
|
|
3
|
+
useApiClientConfigWithSelector,
|
|
4
|
+
useRequestInit
|
|
5
|
+
} from "../chunk-X4CTIU5H.mjs";
|
|
6
|
+
import {
|
|
7
|
+
ApiClientConfigProvider,
|
|
8
|
+
useApiClientConfigContext
|
|
9
|
+
} from "../chunk-T2LQ4KT5.mjs";
|
|
10
|
+
import {
|
|
11
|
+
createSwrConfig
|
|
12
|
+
} from "../chunk-DH33ZDBG.mjs";
|
|
13
|
+
import "../chunk-Z2IX5DM2.mjs";
|
|
14
|
+
import "../chunk-2ORFVC4H.mjs";
|
|
15
|
+
import "../chunk-GIFAQKW5.mjs";
|
|
16
|
+
import "../chunk-3SEO7S3Q.mjs";
|
|
17
|
+
export {
|
|
18
|
+
ApiClientConfigProvider,
|
|
19
|
+
createSwrConfig,
|
|
20
|
+
useApiClientConfig,
|
|
21
|
+
useApiClientConfigContext,
|
|
22
|
+
useApiClientConfigWithSelector,
|
|
23
|
+
useRequestInit
|
|
24
|
+
};
|
package/dist/react/swr.mjs
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const extendedFetcher = fetcher ? (key2, params) => {
|
|
5
|
-
ctrlRef.current?.abort();
|
|
6
|
-
ctrlRef.current = new AbortController();
|
|
7
|
-
return fetcher(key2, { ...params, signal: ctrlRef.current.signal });
|
|
8
|
-
} : fetcher;
|
|
9
|
-
return useSWRNext(key, extendedFetcher, config);
|
|
10
|
-
};
|
|
11
|
-
const createSwrConfig = (config) => ({
|
|
12
|
-
...config,
|
|
13
|
-
use: [...config?.use ?? [], abortMiddleware]
|
|
14
|
-
});
|
|
1
|
+
import {
|
|
2
|
+
createSwrConfig
|
|
3
|
+
} from "../chunk-DH33ZDBG.mjs";
|
|
15
4
|
export {
|
|
16
5
|
createSwrConfig
|
|
17
6
|
};
|
|
@@ -1,28 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return useSyncExternalStoreWithSelector(
|
|
13
|
-
store.subscribe,
|
|
14
|
-
store.getState,
|
|
15
|
-
null,
|
|
16
|
-
selector
|
|
17
|
-
);
|
|
18
|
-
};
|
|
19
|
-
const useRequestInit = (customRequestInit = {}) => {
|
|
20
|
-
const { defaultRequestInit = {} } = useApiClientConfig();
|
|
21
|
-
return useMemo(
|
|
22
|
-
() => mergeRequestInit(defaultRequestInit, customRequestInit),
|
|
23
|
-
[defaultRequestInit, customRequestInit]
|
|
24
|
-
);
|
|
25
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
useApiClientConfig,
|
|
3
|
+
useApiClientConfigWithSelector,
|
|
4
|
+
useRequestInit
|
|
5
|
+
} from "../chunk-X4CTIU5H.mjs";
|
|
6
|
+
import "../chunk-T2LQ4KT5.mjs";
|
|
7
|
+
import "../chunk-DH33ZDBG.mjs";
|
|
8
|
+
import "../chunk-Z2IX5DM2.mjs";
|
|
9
|
+
import "../chunk-2ORFVC4H.mjs";
|
|
10
|
+
import "../chunk-GIFAQKW5.mjs";
|
|
11
|
+
import "../chunk-3SEO7S3Q.mjs";
|
|
26
12
|
export {
|
|
27
13
|
useApiClientConfig,
|
|
28
14
|
useApiClientConfigWithSelector,
|
package/dist/requestUrl.mjs
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const hostName = config.hostName ? typeof config.hostName === "string" ? config.hostName : config.hostName(rawPath) : "";
|
|
9
|
-
const path = hostName + Object.entries(params).reduce(
|
|
10
|
-
(path2, [key, value]) => path2.replace(`{${key}}`, String(value)),
|
|
11
|
-
rawPath
|
|
12
|
-
);
|
|
13
|
-
return query ? `${path}?${qs.stringify(query)}` : path;
|
|
14
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
__internal__requestUrl
|
|
3
|
+
} from "./chunk-EYKOWAWU.mjs";
|
|
4
|
+
import "./chunk-Z2IX5DM2.mjs";
|
|
5
|
+
import "./chunk-2ORFVC4H.mjs";
|
|
6
|
+
import "./chunk-GIFAQKW5.mjs";
|
|
7
|
+
import "./chunk-3SEO7S3Q.mjs";
|
|
15
8
|
export {
|
|
16
9
|
__internal__requestUrl
|
|
17
10
|
};
|
package/dist/store.mjs
CHANGED
|
@@ -1,21 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const getState = () => state;
|
|
5
|
-
const setState = (fn) => {
|
|
6
|
-
state = fn(state);
|
|
7
|
-
listeners.forEach((listener) => listener());
|
|
8
|
-
};
|
|
9
|
-
const subscribe = (listener) => {
|
|
10
|
-
listeners.add(listener);
|
|
11
|
-
return () => listeners.delete(listener);
|
|
12
|
-
};
|
|
13
|
-
return {
|
|
14
|
-
getState,
|
|
15
|
-
setState,
|
|
16
|
-
subscribe
|
|
17
|
-
};
|
|
18
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
createStore
|
|
3
|
+
} from "./chunk-3SEO7S3Q.mjs";
|
|
19
4
|
export {
|
|
20
5
|
createStore
|
|
21
6
|
};
|
package/dist/types.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./chunk-WBQAMGXK.mjs";
|
|
@@ -1,18 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const setCookies = base.getSetCookie().concat(override.getSetCookie());
|
|
5
|
-
base.delete("set-cookie");
|
|
6
|
-
override.delete("set-cookie");
|
|
7
|
-
const mergedHeaders = new Headers({
|
|
8
|
-
...Object.fromEntries(base),
|
|
9
|
-
...Object.fromEntries(override)
|
|
10
|
-
});
|
|
11
|
-
setCookies.forEach((cookie) => {
|
|
12
|
-
mergedHeaders.append("set-cookie", cookie);
|
|
13
|
-
});
|
|
14
|
-
return mergedHeaders;
|
|
15
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
mergeHeadersInit
|
|
3
|
+
} from "../chunk-GIFAQKW5.mjs";
|
|
16
4
|
export {
|
|
17
5
|
mergeHeadersInit
|
|
18
6
|
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
headers: baseHeaders === void 0 ? overrideHeaders : overrideHeaders === void 0 ? baseHeaders : mergeHeadersInit(baseHeaders, overrideHeaders)
|
|
6
|
-
});
|
|
1
|
+
import {
|
|
2
|
+
mergeRequestInit
|
|
3
|
+
} from "../chunk-2ORFVC4H.mjs";
|
|
4
|
+
import "../chunk-GIFAQKW5.mjs";
|
|
7
5
|
export {
|
|
8
6
|
mergeRequestInit
|
|
9
7
|
};
|
package/dist/zod.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
isZodError,
|
|
3
|
+
schemaForType
|
|
4
|
+
} from "./chunk-JCZWXJBU.mjs";
|
|
5
5
|
export {
|
|
6
6
|
isZodError,
|
|
7
7
|
schemaForType
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@readyfor/api-client-base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.247.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"!src/**/*.test.tsx"
|
|
76
76
|
]
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "389d508e37e0001ab445dabae2e17eb220addf61"
|
|
79
79
|
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Store } from './store.js';
|
|
2
|
-
|
|
3
|
-
type DeserializeResponseConfig = {
|
|
4
|
-
forceDeserializeResponse?: false;
|
|
5
|
-
} | {
|
|
6
|
-
forceDeserializeResponse: true;
|
|
7
|
-
onFailedDeserializeResponse: (input: RequestInfo, error: Error) => void;
|
|
8
|
-
};
|
|
9
|
-
type LoggingConfig = {
|
|
10
|
-
showsSchemaParseError?: boolean;
|
|
11
|
-
};
|
|
12
|
-
type RequestConfig = {
|
|
13
|
-
hostName?: string | ((path: string) => string);
|
|
14
|
-
defaultRequestInit?: RequestInit;
|
|
15
|
-
onError?: (error: unknown) => void;
|
|
16
|
-
};
|
|
17
|
-
type Config = RequestConfig & DeserializeResponseConfig & LoggingConfig;
|
|
18
|
-
declare const store: Store<Config>;
|
|
19
|
-
declare const setApiClientConfig: (config: Config) => void;
|
|
20
|
-
declare const buildRequestInitWithDefaultConfig: (customRequestInit?: RequestInit) => RequestInit;
|
|
21
|
-
|
|
22
|
-
export { type Config, type RequestConfig, buildRequestInitWithDefaultConfig, setApiClientConfig, store };
|
package/dist/apiError.d.mts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
type ErrorStatusCode = 301 | 302 | 400 | 401 | 403 | 404 | 413 | 418 | 422 | 500 | 502 | 503 | 504 | 901 | 999;
|
|
2
|
-
declare const errorStatusCode: {
|
|
3
|
-
readonly MOVED_PERMANENTLY: 301;
|
|
4
|
-
readonly FOUND: 302;
|
|
5
|
-
readonly BAD_REQUEST: 400;
|
|
6
|
-
readonly UNAUTHORIZED: 401;
|
|
7
|
-
readonly FORBIDDEN: 403;
|
|
8
|
-
readonly NOT_FOUND: 404;
|
|
9
|
-
readonly PAYLOAD_TOO_LARGE: 413;
|
|
10
|
-
readonly NETWORK_ERROR: 418;
|
|
11
|
-
readonly UNPROCESSABLE_ENTITY: 422;
|
|
12
|
-
readonly INTERNAL_SERVER_ERROR: 500;
|
|
13
|
-
readonly BAD_GATEWAY: 502;
|
|
14
|
-
readonly SERVER_UNAVAILABLE: 503;
|
|
15
|
-
readonly GATEWAY_TIMEOUT: 504;
|
|
16
|
-
readonly ZOD_ERROR: 901;
|
|
17
|
-
readonly UNHANDLED_ERROR: 999;
|
|
18
|
-
};
|
|
19
|
-
declare const errorTitle: {
|
|
20
|
-
[key in ErrorStatusCode]: string;
|
|
21
|
-
};
|
|
22
|
-
declare class HTTPError extends Error {
|
|
23
|
-
status: ErrorStatusCode;
|
|
24
|
-
body?: unknown;
|
|
25
|
-
constructor(status: ErrorStatusCode);
|
|
26
|
-
constructor(status: ErrorStatusCode, body: unknown);
|
|
27
|
-
}
|
|
28
|
-
declare const getErrorStatus: (response: unknown) => ErrorStatusCode | undefined;
|
|
29
|
-
|
|
30
|
-
export { type ErrorStatusCode, HTTPError, errorStatusCode, errorTitle, getErrorStatus };
|
package/dist/fetcher.d.mts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
declare const createJsonFetcher: <T = never>(schema: z.ZodType<T, any, any>, customRequestInit?: RequestInit) => (input: RequestInfo, requestInit?: RequestInit) => Promise<T>;
|
|
4
|
-
declare const createTextFetcher: (customRequestInit?: RequestInit) => (input: RequestInfo, requestInit?: RequestInit) => Promise<string>;
|
|
5
|
-
type BlobFetcherResponse = {
|
|
6
|
-
body: Blob;
|
|
7
|
-
headers: Headers;
|
|
8
|
-
};
|
|
9
|
-
declare const createBlobFetcher: (customRequestInit?: RequestInit) => (input: RequestInfo, requestInit?: RequestInit) => Promise<BlobFetcherResponse>;
|
|
10
|
-
declare const createVoidFetcher: (customRequestInit?: RequestInit) => (input: RequestInfo, requestInit?: RequestInit) => Promise<void>;
|
|
11
|
-
|
|
12
|
-
export { type BlobFetcherResponse, createBlobFetcher, createJsonFetcher, createTextFetcher, createVoidFetcher };
|
package/dist/index.d.mts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { Config, RequestConfig, buildRequestInitWithDefaultConfig, setApiClientConfig, store } from './apiClientConfigStore.js';
|
|
2
|
-
export { ErrorStatusCode, HTTPError, errorStatusCode, errorTitle, getErrorStatus } from './apiError.js';
|
|
3
|
-
export { BlobFetcherResponse, createBlobFetcher, 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
|
-
import 'zod';
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { FC, ReactNode } from 'react';
|
|
2
|
-
import { Config } from '../apiClientConfigStore.js';
|
|
3
|
-
import { Store } from '../store.js';
|
|
4
|
-
import { SWRConfiguration } from 'swr';
|
|
5
|
-
|
|
6
|
-
type Configuration = Config & {
|
|
7
|
-
swr?: SWRConfiguration;
|
|
8
|
-
};
|
|
9
|
-
type Props = {
|
|
10
|
-
config: Configuration;
|
|
11
|
-
children: ReactNode;
|
|
12
|
-
};
|
|
13
|
-
declare const ApiClientConfigProvider: FC<Props>;
|
|
14
|
-
declare const useApiClientConfigContext: () => Store<Config>;
|
|
15
|
-
|
|
16
|
-
export { ApiClientConfigProvider, useApiClientConfigContext };
|
package/dist/react/index.d.mts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { ApiClientConfigProvider, useApiClientConfigContext } from './ApiClientConfigProvider.js';
|
|
2
|
-
export { Configuration, createSwrConfig } from './swr.js';
|
|
3
|
-
export { useApiClientConfig, useApiClientConfigWithSelector, useRequestInit } from './useApiClientConfig.js';
|
|
4
|
-
import 'react';
|
|
5
|
-
import '../apiClientConfigStore.js';
|
|
6
|
-
import '../store.js';
|
|
7
|
-
import 'swr';
|
package/dist/react/swr.d.mts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { SWRConfiguration } from 'swr';
|
|
2
|
-
|
|
3
|
-
type Configuration<T> = SWRConfiguration<T> & {
|
|
4
|
-
/**
|
|
5
|
-
* fetchを止めるかどうかのオプション
|
|
6
|
-
* trueの場合: useSWRの第一引数にnullが渡されます
|
|
7
|
-
* false,または未指定の場合: useSWRの第一引数にURLが渡されます
|
|
8
|
-
*/
|
|
9
|
-
shouldNotFetch?: boolean;
|
|
10
|
-
};
|
|
11
|
-
declare const createSwrConfig: (config?: SWRConfiguration) => SWRConfiguration;
|
|
12
|
-
|
|
13
|
-
export { type Configuration, createSwrConfig };
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Config } from '../apiClientConfigStore.js';
|
|
2
|
-
import '../store.js';
|
|
3
|
-
|
|
4
|
-
declare const useApiClientConfig: () => Config;
|
|
5
|
-
declare const useApiClientConfigWithSelector: <T>(selector: (state: Config) => T) => T;
|
|
6
|
-
declare const useRequestInit: (customRequestInit?: RequestInit) => RequestInit;
|
|
7
|
-
|
|
8
|
-
export { useApiClientConfig, useApiClientConfigWithSelector, useRequestInit };
|
package/dist/requestUrl.d.mts
DELETED
package/dist/store.d.mts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
type Listener = () => void;
|
|
2
|
-
type GetState<T> = () => T;
|
|
3
|
-
type SetState<T> = (fn: (state: T) => T) => void;
|
|
4
|
-
type Subscribe = (listener: Listener) => Unsubscribe;
|
|
5
|
-
type Unsubscribe = () => void;
|
|
6
|
-
type Store<T> = {
|
|
7
|
-
getState: GetState<T>;
|
|
8
|
-
setState: SetState<T>;
|
|
9
|
-
subscribe: Subscribe;
|
|
10
|
-
};
|
|
11
|
-
declare const createStore: <T>(initialState: T) => Store<T>;
|
|
12
|
-
|
|
13
|
-
export { type Store, createStore };
|
package/dist/types.d.mts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
type ForceDig<T, K extends string[]> = K extends [
|
|
2
|
-
infer P extends string,
|
|
3
|
-
...infer Rest extends string[]
|
|
4
|
-
] ? T extends {
|
|
5
|
-
[key in P]?: infer S;
|
|
6
|
-
} ? ForceDig<Exclude<S, undefined>, Rest> : Record<string, never> : T;
|
|
7
|
-
type RemoveBracket<T> = T extends `${infer S}[]` ? S : T;
|
|
8
|
-
type QueryPropsFor<T extends Record<string, unknown>> = {
|
|
9
|
-
[K in keyof T as RemoveBracket<K>]: K extends `${string}[]` ? Exclude<T[K], undefined>[] : T[K];
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export type { ForceDig, QueryPropsFor };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 二つのHeadersInitの情報を元に、新たなHeadersInitを作成する
|
|
3
|
-
*
|
|
4
|
-
* Set-Cookieヘッダーは両方のHeadersInitから取得し、マージ後のHeadersに追加される。
|
|
5
|
-
* それ以外のヘッダーは、後勝ちの形式で新たなHeadersInitにマージされる。
|
|
6
|
-
*
|
|
7
|
-
* ヘッダーを削除する仕組みなどは非対応。
|
|
8
|
-
*
|
|
9
|
-
* Set-Cookieを特別扱いするのは、Fetch APIの仕様に基づいている。
|
|
10
|
-
* https://fetch.spec.whatwg.org/#terminology-headers
|
|
11
|
-
*
|
|
12
|
-
* @param baseHeadersInit 元となるHeadersInit
|
|
13
|
-
* @param overrideHeadersInit 上書きしたいヘッダーを含むHeadersInit。
|
|
14
|
-
*/
|
|
15
|
-
declare const mergeHeadersInit: (baseHeadersInit: HeadersInit, overrideHeadersInit: HeadersInit) => HeadersInit;
|
|
16
|
-
|
|
17
|
-
export { mergeHeadersInit };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 第一引数と第二引数のequestInitをマージした新たなRequestInitを返す。
|
|
3
|
-
* 同じフィールドが存在する場合、第二引数の値で上書きされる。
|
|
4
|
-
* ただし、`headers`フィールドに関しては、`base`と`override`両方に有効なHeadersInitがある場合に限り、
|
|
5
|
-
* `mergeHeadersInit`を使用してヘッダーの内容をマージする
|
|
6
|
-
*/
|
|
7
|
-
declare const mergeRequestInit: ({ headers: baseHeaders, ...base }: RequestInit, { headers: overrideHeaders, ...override }: RequestInit) => RequestInit;
|
|
8
|
-
|
|
9
|
-
export { mergeRequestInit };
|