@readyfor/api-client-base 0.245.0-pr988.a84fa3b → 0.245.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.js +53 -7
- package/dist/apiClientConfigStore.mjs +8 -9
- package/dist/apiError.js +13 -7
- 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.js +124 -29
- package/dist/fetcher.mjs +12 -84
- package/dist/index.js +263 -17
- package/dist/index.mjs +50 -8
- package/dist/react/ApiClientConfigProvider.js +54 -10
- package/dist/react/ApiClientConfigProvider.mjs +9 -14
- package/dist/react/index.js +127 -7
- package/dist/react/index.mjs +24 -3
- package/dist/react/swr.js +4 -2
- package/dist/react/swr.mjs +3 -14
- package/dist/react/useApiClientConfig.js +76 -12
- package/dist/react/useApiClientConfig.mjs +11 -25
- package/dist/requestUrl.js +29 -2
- package/dist/requestUrl.mjs +7 -14
- package/dist/store.js +3 -1
- package/dist/store.mjs +3 -18
- package/dist/types.js +2 -0
- package/dist/types.mjs +1 -0
- package/dist/utils/headersInit.js +3 -1
- package/dist/utils/headersInit.mjs +3 -15
- package/dist/utils/requestInit.js +23 -3
- package/dist/utils/requestInit.mjs +4 -6
- package/dist/zod.js +4 -2
- package/dist/zod.mjs +4 -4
- package/package.json +9 -9
package/dist/fetcher.js
CHANGED
|
@@ -16,6 +16,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/fetcher.ts
|
|
19
21
|
var fetcher_exports = {};
|
|
20
22
|
__export(fetcher_exports, {
|
|
21
23
|
createBlobFetcher: () => createBlobFetcher,
|
|
@@ -24,30 +26,123 @@ __export(fetcher_exports, {
|
|
|
24
26
|
createVoidFetcher: () => createVoidFetcher
|
|
25
27
|
});
|
|
26
28
|
module.exports = __toCommonJS(fetcher_exports);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var
|
|
30
|
-
|
|
29
|
+
|
|
30
|
+
// src/apiError.ts
|
|
31
|
+
var errorStatusCode = {
|
|
32
|
+
MOVED_PERMANENTLY: 301,
|
|
33
|
+
FOUND: 302,
|
|
34
|
+
BAD_REQUEST: 400,
|
|
35
|
+
UNAUTHORIZED: 401,
|
|
36
|
+
FORBIDDEN: 403,
|
|
37
|
+
NOT_FOUND: 404,
|
|
38
|
+
PAYLOAD_TOO_LARGE: 413,
|
|
39
|
+
NETWORK_ERROR: 418,
|
|
40
|
+
UNPROCESSABLE_ENTITY: 422,
|
|
41
|
+
INTERNAL_SERVER_ERROR: 500,
|
|
42
|
+
BAD_GATEWAY: 502,
|
|
43
|
+
SERVER_UNAVAILABLE: 503,
|
|
44
|
+
GATEWAY_TIMEOUT: 504,
|
|
45
|
+
ZOD_ERROR: 901,
|
|
46
|
+
UNHANDLED_ERROR: 999
|
|
47
|
+
};
|
|
48
|
+
var errorTitle = {
|
|
49
|
+
301: "\u30DA\u30FC\u30B8\u304C\u79FB\u52D5\u3055\u308C\u3066\u3044\u307E\u3059",
|
|
50
|
+
302: "\u30DA\u30FC\u30B8\u304C\u4E00\u6642\u7684\u306B\u79FB\u52D5\u3055\u308C\u3066\u3044\u307E\u3059",
|
|
51
|
+
400: "\u30EA\u30AF\u30A8\u30B9\u30C8\u304C\u4E0D\u6B63\u3067\u3059",
|
|
52
|
+
401: "\u30ED\u30B0\u30A4\u30F3\u3057\u3066\u304F\u3060\u3055\u3044",
|
|
53
|
+
403: "\u4E0D\u6B63\u306A\u30C8\u30FC\u30AF\u30F3\u3067\u3059",
|
|
54
|
+
404: "\u30DA\u30FC\u30B8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3067\u3057\u305F",
|
|
55
|
+
413: "\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
|
|
56
|
+
418: "\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
|
|
57
|
+
422: "\u30C7\u30FC\u30BF\u304C\u4E0D\u6B63\u3067\u3059",
|
|
58
|
+
500: "\u30B5\u30FC\u30D0\u30FC\u3067\u30A8\u30E9\u30FC\u304C\u8D77\u304D\u307E\u3057\u305F",
|
|
59
|
+
502: "\u30B5\u30FC\u30D0\u30FC\u3067\u30A8\u30E9\u30FC\u304C\u8D77\u304D\u307E\u3057\u305F",
|
|
60
|
+
503: "\u30E1\u30F3\u30C6\u30CA\u30F3\u30B9\u4E2D\u3067\u3059",
|
|
61
|
+
504: "\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
|
|
62
|
+
901: "\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F",
|
|
63
|
+
999: "\u30B5\u30FC\u30D0\u30FC\u3067\u30A8\u30E9\u30FC\u304C\u8D77\u304D\u307E\u3057\u305F"
|
|
64
|
+
};
|
|
65
|
+
var HTTPError = class extends Error {
|
|
66
|
+
status;
|
|
67
|
+
body;
|
|
68
|
+
constructor(status, body) {
|
|
69
|
+
super(errorTitle[status]);
|
|
70
|
+
this.name = "HTTPError";
|
|
71
|
+
this.status = status;
|
|
72
|
+
this.body = body;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/store.ts
|
|
77
|
+
var createStore = (initialState) => {
|
|
78
|
+
let state = initialState;
|
|
79
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
80
|
+
const getState = () => state;
|
|
81
|
+
const setState = (fn) => {
|
|
82
|
+
state = fn(state);
|
|
83
|
+
listeners.forEach((listener) => listener());
|
|
84
|
+
};
|
|
85
|
+
const subscribe = (listener) => {
|
|
86
|
+
listeners.add(listener);
|
|
87
|
+
return () => listeners.delete(listener);
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
getState,
|
|
91
|
+
setState,
|
|
92
|
+
subscribe
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// src/utils/headersInit.ts
|
|
97
|
+
var mergeHeadersInit = (baseHeadersInit, overrideHeadersInit) => {
|
|
98
|
+
const base = new Headers(baseHeadersInit);
|
|
99
|
+
const override = new Headers(overrideHeadersInit);
|
|
100
|
+
const setCookies = base.getSetCookie().concat(override.getSetCookie());
|
|
101
|
+
base.delete("set-cookie");
|
|
102
|
+
override.delete("set-cookie");
|
|
103
|
+
const mergedHeaders = new Headers({
|
|
104
|
+
...Object.fromEntries(base),
|
|
105
|
+
...Object.fromEntries(override)
|
|
106
|
+
});
|
|
107
|
+
setCookies.forEach((cookie) => {
|
|
108
|
+
mergedHeaders.append("set-cookie", cookie);
|
|
109
|
+
});
|
|
110
|
+
return mergedHeaders;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// src/utils/requestInit.ts
|
|
114
|
+
var mergeRequestInit = ({ headers: baseHeaders, ...base }, { headers: overrideHeaders, ...override }) => ({
|
|
115
|
+
...base,
|
|
116
|
+
...override,
|
|
117
|
+
headers: baseHeaders === void 0 ? overrideHeaders : overrideHeaders === void 0 ? baseHeaders : mergeHeadersInit(baseHeaders, overrideHeaders)
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// src/apiClientConfigStore.ts
|
|
121
|
+
var defaultConfig = {};
|
|
122
|
+
var store = createStore(defaultConfig);
|
|
123
|
+
|
|
124
|
+
// src/fetcher.ts
|
|
125
|
+
var defaultRequestInit = {
|
|
31
126
|
credentials: "include"
|
|
32
127
|
};
|
|
33
|
-
|
|
128
|
+
var createJsonFetcher = (schema, customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
34
129
|
input,
|
|
35
|
-
|
|
130
|
+
mergeRequestInit(
|
|
36
131
|
defaultRequestInit,
|
|
37
|
-
|
|
132
|
+
mergeRequestInit(customRequestInit, requestInit)
|
|
38
133
|
)
|
|
39
134
|
).then(async (res) => {
|
|
40
135
|
const body = await res.json();
|
|
41
136
|
if (res.ok) return body;
|
|
42
|
-
const code = Object.values(
|
|
43
|
-
const error = new
|
|
137
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
138
|
+
const error = new HTTPError(code, body);
|
|
44
139
|
throw error;
|
|
45
140
|
}).catch((error) => {
|
|
46
|
-
|
|
141
|
+
store.getState().onError?.(error);
|
|
47
142
|
throw error;
|
|
48
143
|
}).then((parsedResponse) => {
|
|
49
144
|
const result = schema.safeParse(parsedResponse);
|
|
50
|
-
const config =
|
|
145
|
+
const config = store.getState();
|
|
51
146
|
if (result.success) {
|
|
52
147
|
return result.data;
|
|
53
148
|
}
|
|
@@ -60,52 +155,52 @@ const createJsonFetcher = (schema, customRequestInit = {}) => (input, requestIni
|
|
|
60
155
|
}
|
|
61
156
|
throw result.error;
|
|
62
157
|
});
|
|
63
|
-
|
|
158
|
+
var createTextFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
64
159
|
input,
|
|
65
|
-
|
|
160
|
+
mergeRequestInit(
|
|
66
161
|
defaultRequestInit,
|
|
67
|
-
|
|
162
|
+
mergeRequestInit(customRequestInit, requestInit)
|
|
68
163
|
)
|
|
69
164
|
).then(async (res) => {
|
|
70
165
|
const body = await res.text();
|
|
71
166
|
if (res.ok) return body;
|
|
72
|
-
const code = Object.values(
|
|
73
|
-
const error = new
|
|
167
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
168
|
+
const error = new HTTPError(code, body);
|
|
74
169
|
throw error;
|
|
75
170
|
}).catch((error) => {
|
|
76
|
-
|
|
171
|
+
store.getState().onError?.(error);
|
|
77
172
|
throw error;
|
|
78
173
|
});
|
|
79
|
-
|
|
174
|
+
var createBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
80
175
|
input,
|
|
81
|
-
|
|
176
|
+
mergeRequestInit(
|
|
82
177
|
defaultRequestInit,
|
|
83
|
-
|
|
178
|
+
mergeRequestInit(customRequestInit, requestInit)
|
|
84
179
|
)
|
|
85
180
|
).then(async (res) => {
|
|
86
181
|
const body = await res.blob();
|
|
87
182
|
if (res.ok) return { body, headers: res.headers };
|
|
88
|
-
const code = Object.values(
|
|
89
|
-
const error = new
|
|
183
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
184
|
+
const error = new HTTPError(code, body);
|
|
90
185
|
throw error;
|
|
91
186
|
}).catch((error) => {
|
|
92
|
-
|
|
187
|
+
store.getState().onError?.(error);
|
|
93
188
|
throw error;
|
|
94
189
|
});
|
|
95
|
-
|
|
190
|
+
var createVoidFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
96
191
|
input,
|
|
97
|
-
|
|
192
|
+
mergeRequestInit(
|
|
98
193
|
defaultRequestInit,
|
|
99
|
-
|
|
194
|
+
mergeRequestInit(customRequestInit, requestInit)
|
|
100
195
|
)
|
|
101
196
|
).then(async (res) => {
|
|
102
197
|
if (res.ok) return;
|
|
103
|
-
const code = Object.values(
|
|
198
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
104
199
|
const body = await res.text();
|
|
105
|
-
const error = new
|
|
200
|
+
const error = new HTTPError(code, body);
|
|
106
201
|
throw error;
|
|
107
202
|
}).catch((error) => {
|
|
108
|
-
|
|
203
|
+
store.getState().onError?.(error);
|
|
109
204
|
throw error;
|
|
110
205
|
});
|
|
111
206
|
// Annotate the CommonJS export names for ESM import in node:
|
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.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
6
12
|
var __copyProps = (to, from, except, desc) => {
|
|
7
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
14
|
for (let key of __getOwnPropNames(from))
|
|
@@ -11,26 +17,266 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
11
17
|
}
|
|
12
18
|
return to;
|
|
13
19
|
};
|
|
14
|
-
var
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
15
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
16
31
|
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
HTTPError: () => HTTPError,
|
|
34
|
+
__internal__requestUrl: () => __internal__requestUrl,
|
|
35
|
+
buildRequestInitWithDefaultConfig: () => buildRequestInitWithDefaultConfig,
|
|
36
|
+
createBlobFetcher: () => createBlobFetcher,
|
|
37
|
+
createJsonFetcher: () => createJsonFetcher,
|
|
38
|
+
createStore: () => createStore,
|
|
39
|
+
createTextFetcher: () => createTextFetcher,
|
|
40
|
+
createVoidFetcher: () => createVoidFetcher,
|
|
41
|
+
errorStatusCode: () => errorStatusCode,
|
|
42
|
+
errorTitle: () => errorTitle,
|
|
43
|
+
getErrorStatus: () => getErrorStatus,
|
|
44
|
+
isZodError: () => isZodError,
|
|
45
|
+
mergeRequestInit: () => mergeRequestInit,
|
|
46
|
+
schemaForType: () => schemaForType,
|
|
47
|
+
setApiClientConfig: () => setApiClientConfig,
|
|
48
|
+
store: () => store
|
|
49
|
+
});
|
|
17
50
|
module.exports = __toCommonJS(index_exports);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
51
|
+
|
|
52
|
+
// src/store.ts
|
|
53
|
+
var createStore = (initialState) => {
|
|
54
|
+
let state = initialState;
|
|
55
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
56
|
+
const getState = () => state;
|
|
57
|
+
const setState = (fn) => {
|
|
58
|
+
state = fn(state);
|
|
59
|
+
listeners.forEach((listener) => listener());
|
|
60
|
+
};
|
|
61
|
+
const subscribe = (listener) => {
|
|
62
|
+
listeners.add(listener);
|
|
63
|
+
return () => listeners.delete(listener);
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
getState,
|
|
67
|
+
setState,
|
|
68
|
+
subscribe
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// src/utils/headersInit.ts
|
|
73
|
+
var mergeHeadersInit = (baseHeadersInit, overrideHeadersInit) => {
|
|
74
|
+
const base = new Headers(baseHeadersInit);
|
|
75
|
+
const override = new Headers(overrideHeadersInit);
|
|
76
|
+
const setCookies = base.getSetCookie().concat(override.getSetCookie());
|
|
77
|
+
base.delete("set-cookie");
|
|
78
|
+
override.delete("set-cookie");
|
|
79
|
+
const mergedHeaders = new Headers({
|
|
80
|
+
...Object.fromEntries(base),
|
|
81
|
+
...Object.fromEntries(override)
|
|
82
|
+
});
|
|
83
|
+
setCookies.forEach((cookie) => {
|
|
84
|
+
mergedHeaders.append("set-cookie", cookie);
|
|
85
|
+
});
|
|
86
|
+
return mergedHeaders;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// src/utils/requestInit.ts
|
|
90
|
+
var mergeRequestInit = ({ headers: baseHeaders, ...base }, { headers: overrideHeaders, ...override }) => ({
|
|
91
|
+
...base,
|
|
92
|
+
...override,
|
|
93
|
+
headers: baseHeaders === void 0 ? overrideHeaders : overrideHeaders === void 0 ? baseHeaders : mergeHeadersInit(baseHeaders, overrideHeaders)
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// src/apiClientConfigStore.ts
|
|
97
|
+
var defaultConfig = {};
|
|
98
|
+
var store = createStore(defaultConfig);
|
|
99
|
+
var setApiClientConfig = (config) => store.setState(() => config);
|
|
100
|
+
var buildRequestInitWithDefaultConfig = (customRequestInit = {}) => {
|
|
101
|
+
const { defaultRequestInit: defaultRequestInit2 = {} } = store.getState();
|
|
102
|
+
return mergeRequestInit(defaultRequestInit2, customRequestInit);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// src/zod.ts
|
|
106
|
+
var schemaForType = () => (arg) => {
|
|
107
|
+
return arg;
|
|
108
|
+
};
|
|
109
|
+
var isZodError = (obj) => obj !== null && typeof obj === "object" && obj.constructor.name === "ZodError";
|
|
110
|
+
|
|
111
|
+
// src/apiError.ts
|
|
112
|
+
var errorStatusCode = {
|
|
113
|
+
MOVED_PERMANENTLY: 301,
|
|
114
|
+
FOUND: 302,
|
|
115
|
+
BAD_REQUEST: 400,
|
|
116
|
+
UNAUTHORIZED: 401,
|
|
117
|
+
FORBIDDEN: 403,
|
|
118
|
+
NOT_FOUND: 404,
|
|
119
|
+
PAYLOAD_TOO_LARGE: 413,
|
|
120
|
+
NETWORK_ERROR: 418,
|
|
121
|
+
UNPROCESSABLE_ENTITY: 422,
|
|
122
|
+
INTERNAL_SERVER_ERROR: 500,
|
|
123
|
+
BAD_GATEWAY: 502,
|
|
124
|
+
SERVER_UNAVAILABLE: 503,
|
|
125
|
+
GATEWAY_TIMEOUT: 504,
|
|
126
|
+
ZOD_ERROR: 901,
|
|
127
|
+
UNHANDLED_ERROR: 999
|
|
128
|
+
};
|
|
129
|
+
var errorTitle = {
|
|
130
|
+
301: "\u30DA\u30FC\u30B8\u304C\u79FB\u52D5\u3055\u308C\u3066\u3044\u307E\u3059",
|
|
131
|
+
302: "\u30DA\u30FC\u30B8\u304C\u4E00\u6642\u7684\u306B\u79FB\u52D5\u3055\u308C\u3066\u3044\u307E\u3059",
|
|
132
|
+
400: "\u30EA\u30AF\u30A8\u30B9\u30C8\u304C\u4E0D\u6B63\u3067\u3059",
|
|
133
|
+
401: "\u30ED\u30B0\u30A4\u30F3\u3057\u3066\u304F\u3060\u3055\u3044",
|
|
134
|
+
403: "\u4E0D\u6B63\u306A\u30C8\u30FC\u30AF\u30F3\u3067\u3059",
|
|
135
|
+
404: "\u30DA\u30FC\u30B8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3067\u3057\u305F",
|
|
136
|
+
413: "\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
|
|
137
|
+
418: "\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
|
|
138
|
+
422: "\u30C7\u30FC\u30BF\u304C\u4E0D\u6B63\u3067\u3059",
|
|
139
|
+
500: "\u30B5\u30FC\u30D0\u30FC\u3067\u30A8\u30E9\u30FC\u304C\u8D77\u304D\u307E\u3057\u305F",
|
|
140
|
+
502: "\u30B5\u30FC\u30D0\u30FC\u3067\u30A8\u30E9\u30FC\u304C\u8D77\u304D\u307E\u3057\u305F",
|
|
141
|
+
503: "\u30E1\u30F3\u30C6\u30CA\u30F3\u30B9\u4E2D\u3067\u3059",
|
|
142
|
+
504: "\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
|
|
143
|
+
901: "\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F",
|
|
144
|
+
999: "\u30B5\u30FC\u30D0\u30FC\u3067\u30A8\u30E9\u30FC\u304C\u8D77\u304D\u307E\u3057\u305F"
|
|
145
|
+
};
|
|
146
|
+
var HTTPError = class extends Error {
|
|
147
|
+
status;
|
|
148
|
+
body;
|
|
149
|
+
constructor(status, body) {
|
|
150
|
+
super(errorTitle[status]);
|
|
151
|
+
this.name = "HTTPError";
|
|
152
|
+
this.status = status;
|
|
153
|
+
this.body = body;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
var getErrorStatus = (response) => {
|
|
157
|
+
if (response instanceof Object && "status" in response && typeof response["status"] === "number") {
|
|
158
|
+
const status = Number(response["status"]);
|
|
159
|
+
return Object.values(errorStatusCode).includes(status) ? status : 999;
|
|
160
|
+
}
|
|
161
|
+
if (isZodError(response)) {
|
|
162
|
+
return errorStatusCode.ZOD_ERROR;
|
|
163
|
+
}
|
|
164
|
+
return void 0;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// src/fetcher.ts
|
|
168
|
+
var defaultRequestInit = {
|
|
169
|
+
credentials: "include"
|
|
170
|
+
};
|
|
171
|
+
var createJsonFetcher = (schema, customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
172
|
+
input,
|
|
173
|
+
mergeRequestInit(
|
|
174
|
+
defaultRequestInit,
|
|
175
|
+
mergeRequestInit(customRequestInit, requestInit)
|
|
176
|
+
)
|
|
177
|
+
).then(async (res) => {
|
|
178
|
+
const body = await res.json();
|
|
179
|
+
if (res.ok) return body;
|
|
180
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
181
|
+
const error = new HTTPError(code, body);
|
|
182
|
+
throw error;
|
|
183
|
+
}).catch((error) => {
|
|
184
|
+
store.getState().onError?.(error);
|
|
185
|
+
throw error;
|
|
186
|
+
}).then((parsedResponse) => {
|
|
187
|
+
const result = schema.safeParse(parsedResponse);
|
|
188
|
+
const config = store.getState();
|
|
189
|
+
if (result.success) {
|
|
190
|
+
return result.data;
|
|
191
|
+
}
|
|
192
|
+
if (config.showsSchemaParseError) {
|
|
193
|
+
console.error(result.error);
|
|
194
|
+
}
|
|
195
|
+
if (config.forceDeserializeResponse) {
|
|
196
|
+
config.onFailedDeserializeResponse(input, result.error);
|
|
197
|
+
return parsedResponse;
|
|
198
|
+
}
|
|
199
|
+
throw result.error;
|
|
200
|
+
});
|
|
201
|
+
var createTextFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
202
|
+
input,
|
|
203
|
+
mergeRequestInit(
|
|
204
|
+
defaultRequestInit,
|
|
205
|
+
mergeRequestInit(customRequestInit, requestInit)
|
|
206
|
+
)
|
|
207
|
+
).then(async (res) => {
|
|
208
|
+
const body = await res.text();
|
|
209
|
+
if (res.ok) return body;
|
|
210
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
211
|
+
const error = new HTTPError(code, body);
|
|
212
|
+
throw error;
|
|
213
|
+
}).catch((error) => {
|
|
214
|
+
store.getState().onError?.(error);
|
|
215
|
+
throw error;
|
|
216
|
+
});
|
|
217
|
+
var createBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
218
|
+
input,
|
|
219
|
+
mergeRequestInit(
|
|
220
|
+
defaultRequestInit,
|
|
221
|
+
mergeRequestInit(customRequestInit, requestInit)
|
|
222
|
+
)
|
|
223
|
+
).then(async (res) => {
|
|
224
|
+
const body = await res.blob();
|
|
225
|
+
if (res.ok) return { body, headers: res.headers };
|
|
226
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
227
|
+
const error = new HTTPError(code, body);
|
|
228
|
+
throw error;
|
|
229
|
+
}).catch((error) => {
|
|
230
|
+
store.getState().onError?.(error);
|
|
231
|
+
throw error;
|
|
232
|
+
});
|
|
233
|
+
var createVoidFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
|
|
234
|
+
input,
|
|
235
|
+
mergeRequestInit(
|
|
236
|
+
defaultRequestInit,
|
|
237
|
+
mergeRequestInit(customRequestInit, requestInit)
|
|
238
|
+
)
|
|
239
|
+
).then(async (res) => {
|
|
240
|
+
if (res.ok) return;
|
|
241
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
242
|
+
const body = await res.text();
|
|
243
|
+
const error = new HTTPError(code, body);
|
|
244
|
+
throw error;
|
|
245
|
+
}).catch((error) => {
|
|
246
|
+
store.getState().onError?.(error);
|
|
247
|
+
throw error;
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
// src/requestUrl.ts
|
|
251
|
+
var import_qs = __toESM(require("qs"));
|
|
252
|
+
function __internal__requestUrl(...args) {
|
|
253
|
+
const config = store.getState();
|
|
254
|
+
const rawPath = args[0];
|
|
255
|
+
const params = args[1] || {};
|
|
256
|
+
const query = args[2];
|
|
257
|
+
const hostName = config.hostName ? typeof config.hostName === "string" ? config.hostName : config.hostName(rawPath) : "";
|
|
258
|
+
const path = hostName + Object.entries(params).reduce(
|
|
259
|
+
(path2, [key, value]) => path2.replace(`{${key}}`, String(value)),
|
|
260
|
+
rawPath
|
|
261
|
+
);
|
|
262
|
+
return query ? `${path}?${import_qs.default.stringify(query)}` : path;
|
|
263
|
+
}
|
|
26
264
|
// Annotate the CommonJS export names for ESM import in node:
|
|
27
265
|
0 && (module.exports = {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
266
|
+
HTTPError,
|
|
267
|
+
__internal__requestUrl,
|
|
268
|
+
buildRequestInitWithDefaultConfig,
|
|
269
|
+
createBlobFetcher,
|
|
270
|
+
createJsonFetcher,
|
|
271
|
+
createStore,
|
|
272
|
+
createTextFetcher,
|
|
273
|
+
createVoidFetcher,
|
|
274
|
+
errorStatusCode,
|
|
275
|
+
errorTitle,
|
|
276
|
+
getErrorStatus,
|
|
277
|
+
isZodError,
|
|
278
|
+
mergeRequestInit,
|
|
279
|
+
schemaForType,
|
|
280
|
+
setApiClientConfig,
|
|
281
|
+
store
|
|
36
282
|
});
|
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
|
+
};
|