@readyfor/api-client-base 1.22.0 → 1.22.1-pr1285.b385439

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 (57) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +23 -0
  2. package/dist/apiClientConfigStore-CNRWwVM3.mjs +86 -0
  3. package/dist/apiClientConfigStore.d.ts +11 -10
  4. package/dist/apiClientConfigStore.js +10 -37
  5. package/dist/apiError.d.ts +24 -25
  6. package/dist/apiError.js +68 -95
  7. package/dist/fetcher.d.ts +8 -7
  8. package/dist/fetcher.js +57 -125
  9. package/dist/index.d.ts +10 -10
  10. package/dist/index.js +31 -38
  11. package/dist/index.mjs +146 -62
  12. package/dist/react/ApiClientConfigProvider.d.ts +10 -9
  13. package/dist/react/ApiClientConfigProvider.js +24 -41
  14. package/dist/react/index.d.ts +4 -7
  15. package/dist/react/index.js +10 -26
  16. package/dist/react/index.mjs +61 -23
  17. package/dist/react/swr.d.ts +10 -9
  18. package/dist/react/swr.js +24 -37
  19. package/dist/react/useApiClientConfig.d.ts +5 -5
  20. package/dist/react/useApiClientConfig.js +18 -50
  21. package/dist/requestUrl.d.ts +3 -2
  22. package/dist/requestUrl.js +14 -49
  23. package/dist/store.d.ts +6 -5
  24. package/dist/store.js +20 -43
  25. package/dist/types.d.ts +5 -11
  26. package/dist/types.js +0 -16
  27. package/dist/utils/headersInit.d.ts +3 -2
  28. package/dist/utils/headersInit.js +45 -49
  29. package/dist/utils/requestInit.d.ts +10 -3
  30. package/dist/utils/requestInit.js +14 -31
  31. package/dist/zod.d.ts +4 -3
  32. package/dist/zod.js +6 -30
  33. package/package.json +2 -19
  34. package/dist/apiClientConfigStore.mjs +0 -13
  35. package/dist/apiError.mjs +0 -19
  36. package/dist/chunk-3SEO7S3Q.mjs +0 -23
  37. package/dist/chunk-5JS6U5IM.mjs +0 -37
  38. package/dist/chunk-DH33ZDBG.mjs +0 -19
  39. package/dist/chunk-FNLUAQWC.mjs +0 -80
  40. package/dist/chunk-GD4RTKUU.mjs +0 -22
  41. package/dist/chunk-JCZWXJBU.mjs +0 -10
  42. package/dist/chunk-NOC6G3HZ.mjs +0 -21
  43. package/dist/chunk-NYICHGY2.mjs +0 -30
  44. package/dist/chunk-OVR3ZT2S.mjs +0 -118
  45. package/dist/chunk-QXFPBYPL.mjs +0 -25
  46. package/dist/chunk-TZUKIYFN.mjs +0 -14
  47. package/dist/chunk-WBQAMGXK.mjs +0 -0
  48. package/dist/fetcher.mjs +0 -20
  49. package/dist/react/ApiClientConfigProvider.mjs +0 -13
  50. package/dist/react/swr.mjs +0 -6
  51. package/dist/react/useApiClientConfig.mjs +0 -16
  52. package/dist/requestUrl.mjs +0 -10
  53. package/dist/store.mjs +0 -6
  54. package/dist/types.mjs +0 -1
  55. package/dist/utils/headersInit.mjs +0 -8
  56. package/dist/utils/requestInit.mjs +0 -7
  57. package/dist/zod.mjs +0 -8
@@ -1,19 +0,0 @@
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
- };
@@ -1,80 +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
- CONFLICT: 409,
14
- PAYLOAD_TOO_LARGE: 413,
15
- NETWORK_ERROR: 418,
16
- UNPROCESSABLE_ENTITY: 422,
17
- INTERNAL_SERVER_ERROR: 500,
18
- BAD_GATEWAY: 502,
19
- SERVER_UNAVAILABLE: 503,
20
- GATEWAY_TIMEOUT: 504,
21
- ZOD_ERROR: 901,
22
- UNHANDLED_ERROR: 999
23
- };
24
- var errorTitle = {
25
- 301: "\u30DA\u30FC\u30B8\u304C\u79FB\u52D5\u3055\u308C\u3066\u3044\u307E\u3059",
26
- 302: "\u30DA\u30FC\u30B8\u304C\u4E00\u6642\u7684\u306B\u79FB\u52D5\u3055\u308C\u3066\u3044\u307E\u3059",
27
- 400: "\u30EA\u30AF\u30A8\u30B9\u30C8\u304C\u4E0D\u6B63\u3067\u3059",
28
- 401: "\u30ED\u30B0\u30A4\u30F3\u3057\u3066\u304F\u3060\u3055\u3044",
29
- 403: "\u4E0D\u6B63\u306A\u30C8\u30FC\u30AF\u30F3\u3067\u3059",
30
- 404: "\u30DA\u30FC\u30B8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3067\u3057\u305F",
31
- 409: "\u7DE8\u96C6\u5185\u5BB9\u304C\u7AF6\u5408\u3057\u3066\u3044\u307E\u3059",
32
- 413: "\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
33
- 418: "\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
34
- 422: "\u30C7\u30FC\u30BF\u304C\u4E0D\u6B63\u3067\u3059",
35
- 500: "\u30B5\u30FC\u30D0\u30FC\u3067\u30A8\u30E9\u30FC\u304C\u8D77\u304D\u307E\u3057\u305F",
36
- 502: "\u30B5\u30FC\u30D0\u30FC\u3067\u30A8\u30E9\u30FC\u304C\u8D77\u304D\u307E\u3057\u305F",
37
- 503: "\u30E1\u30F3\u30C6\u30CA\u30F3\u30B9\u4E2D\u3067\u3059",
38
- 504: "\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
39
- 901: "\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F",
40
- 999: "\u30B5\u30FC\u30D0\u30FC\u3067\u30A8\u30E9\u30FC\u304C\u8D77\u304D\u307E\u3057\u305F"
41
- };
42
- var HTTPError = class extends Error {
43
- status;
44
- body;
45
- constructor(status, body) {
46
- super(errorTitle[status]);
47
- this.name = "HTTPError";
48
- this.status = status;
49
- this.body = body;
50
- }
51
- };
52
- var isHttpErrorWithStatus = (error, status) => error instanceof Error && "status" in error && error.status === status;
53
- var getHttpErrorBody = (error) => error instanceof Error && "body" in error ? error.body : void 0;
54
- var getHttpErrorBodyReason = (body) => {
55
- if (body !== null && typeof body === "object" && "reason" in body) {
56
- const reason = body.reason;
57
- return typeof reason === "string" ? reason : void 0;
58
- }
59
- return void 0;
60
- };
61
- var getErrorStatus = (response) => {
62
- if (response instanceof Object && "status" in response && typeof response["status"] === "number") {
63
- const status = Number(response["status"]);
64
- return Object.values(errorStatusCode).includes(status) ? status : 999;
65
- }
66
- if (isZodError(response)) {
67
- return errorStatusCode.ZOD_ERROR;
68
- }
69
- return void 0;
70
- };
71
-
72
- export {
73
- errorStatusCode,
74
- errorTitle,
75
- HTTPError,
76
- isHttpErrorWithStatus,
77
- getHttpErrorBody,
78
- getHttpErrorBodyReason,
79
- getErrorStatus
80
- };
@@ -1,22 +0,0 @@
1
- import {
2
- store
3
- } from "./chunk-NOC6G3HZ.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
- };
@@ -1,10 +0,0 @@
1
- // src/zod.ts
2
- var schemaForType = () => (arg) => {
3
- return arg;
4
- };
5
- var isZodError = (obj) => obj !== null && typeof obj === "object" && obj.constructor.name === "ZodError";
6
-
7
- export {
8
- schemaForType,
9
- isZodError
10
- };
@@ -1,21 +0,0 @@
1
- import {
2
- mergeRequestInit
3
- } from "./chunk-TZUKIYFN.mjs";
4
- import {
5
- createStore
6
- } from "./chunk-3SEO7S3Q.mjs";
7
-
8
- // src/apiClientConfigStore.ts
9
- var defaultConfig = {};
10
- var store = globalThis[Symbol.for("@readyfor/api-client-base/config")] ??= 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
- };
@@ -1,30 +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
- 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
- };
@@ -1,118 +0,0 @@
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
- };
@@ -1,25 +0,0 @@
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
- };
@@ -1,14 +0,0 @@
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.mjs DELETED
@@ -1,20 +0,0 @@
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
- };
@@ -1,13 +0,0 @@
1
- import {
2
- ApiClientConfigProvider,
3
- useApiClientConfigContext
4
- } from "../chunk-QXFPBYPL.mjs";
5
- import "../chunk-DH33ZDBG.mjs";
6
- import "../chunk-NOC6G3HZ.mjs";
7
- import "../chunk-TZUKIYFN.mjs";
8
- import "../chunk-NYICHGY2.mjs";
9
- import "../chunk-3SEO7S3Q.mjs";
10
- export {
11
- ApiClientConfigProvider,
12
- useApiClientConfigContext
13
- };
@@ -1,6 +0,0 @@
1
- import {
2
- createSwrConfig
3
- } from "../chunk-DH33ZDBG.mjs";
4
- export {
5
- createSwrConfig
6
- };
@@ -1,16 +0,0 @@
1
- import {
2
- useApiClientConfig,
3
- useApiClientConfigWithSelector,
4
- useRequestInit
5
- } from "../chunk-5JS6U5IM.mjs";
6
- import "../chunk-QXFPBYPL.mjs";
7
- import "../chunk-DH33ZDBG.mjs";
8
- import "../chunk-NOC6G3HZ.mjs";
9
- import "../chunk-TZUKIYFN.mjs";
10
- import "../chunk-NYICHGY2.mjs";
11
- import "../chunk-3SEO7S3Q.mjs";
12
- export {
13
- useApiClientConfig,
14
- useApiClientConfigWithSelector,
15
- useRequestInit
16
- };
@@ -1,10 +0,0 @@
1
- import {
2
- __internal__requestUrl
3
- } from "./chunk-GD4RTKUU.mjs";
4
- import "./chunk-NOC6G3HZ.mjs";
5
- import "./chunk-TZUKIYFN.mjs";
6
- import "./chunk-NYICHGY2.mjs";
7
- import "./chunk-3SEO7S3Q.mjs";
8
- export {
9
- __internal__requestUrl
10
- };
package/dist/store.mjs DELETED
@@ -1,6 +0,0 @@
1
- import {
2
- createStore
3
- } from "./chunk-3SEO7S3Q.mjs";
4
- export {
5
- createStore
6
- };
package/dist/types.mjs DELETED
@@ -1 +0,0 @@
1
- import "./chunk-WBQAMGXK.mjs";
@@ -1,8 +0,0 @@
1
- import {
2
- mergeHeadersInit,
3
- toHeadersInit
4
- } from "../chunk-NYICHGY2.mjs";
5
- export {
6
- mergeHeadersInit,
7
- toHeadersInit
8
- };
@@ -1,7 +0,0 @@
1
- import {
2
- mergeRequestInit
3
- } from "../chunk-TZUKIYFN.mjs";
4
- import "../chunk-NYICHGY2.mjs";
5
- export {
6
- mergeRequestInit
7
- };
package/dist/zod.mjs DELETED
@@ -1,8 +0,0 @@
1
- import {
2
- isZodError,
3
- schemaForType
4
- } from "./chunk-JCZWXJBU.mjs";
5
- export {
6
- isZodError,
7
- schemaForType
8
- };