@readyfor/api-client-base 0.245.0 → 0.245.1-pr989.733ad69
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.mts +1 -1
- package/dist/apiClientConfigStore.js +7 -53
- package/dist/apiClientConfigStore.mjs +9 -8
- package/dist/apiError.js +7 -13
- package/dist/apiError.mjs +55 -7
- package/dist/fetcher.js +29 -124
- package/dist/fetcher.mjs +84 -12
- package/dist/index.d.mts +8 -8
- package/dist/index.js +17 -263
- package/dist/index.mjs +8 -50
- package/dist/react/ApiClientConfigProvider.d.mts +2 -2
- package/dist/react/ApiClientConfigProvider.js +10 -54
- package/dist/react/ApiClientConfigProvider.mjs +14 -9
- package/dist/react/index.d.mts +5 -5
- package/dist/react/index.js +7 -127
- package/dist/react/index.mjs +3 -24
- package/dist/react/swr.js +2 -4
- package/dist/react/swr.mjs +14 -3
- package/dist/react/useApiClientConfig.d.mts +2 -2
- package/dist/react/useApiClientConfig.js +12 -76
- package/dist/react/useApiClientConfig.mjs +25 -11
- package/dist/requestUrl.js +2 -29
- package/dist/requestUrl.mjs +14 -7
- package/dist/store.js +1 -3
- package/dist/store.mjs +18 -3
- package/dist/types.js +0 -2
- package/dist/types.mjs +0 -1
- package/dist/utils/headersInit.js +1 -3
- package/dist/utils/headersInit.mjs +15 -3
- package/dist/utils/requestInit.js +3 -23
- package/dist/utils/requestInit.mjs +6 -4
- package/dist/zod.js +2 -4
- package/dist/zod.mjs +4 -4
- package/package.json +10 -9
- package/dist/chunk-2ORFVC4H.mjs +0 -14
- package/dist/chunk-3SEO7S3Q.mjs +0 -23
- package/dist/chunk-DH33ZDBG.mjs +0 -19
- package/dist/chunk-E3EKMNYV.mjs +0 -100
- package/dist/chunk-EYKOWAWU.mjs +0 -22
- package/dist/chunk-GIFAQKW5.mjs +0 -20
- package/dist/chunk-JCZWXJBU.mjs +0 -10
- package/dist/chunk-PY35XWDS.mjs +0 -66
- package/dist/chunk-T2LQ4KT5.mjs +0 -25
- package/dist/chunk-WBQAMGXK.mjs +0 -0
- package/dist/chunk-X4CTIU5H.mjs +0 -37
- package/dist/chunk-Z2IX5DM2.mjs +0 -21
package/dist/chunk-E3EKMNYV.mjs
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/chunk-EYKOWAWU.mjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/chunk-GIFAQKW5.mjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/chunk-JCZWXJBU.mjs
DELETED
package/dist/chunk-PY35XWDS.mjs
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/chunk-T2LQ4KT5.mjs
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/chunk-WBQAMGXK.mjs
DELETED
|
File without changes
|
package/dist/chunk-X4CTIU5H.mjs
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/chunk-Z2IX5DM2.mjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
};
|