@readyfor/api-client-base 0.0.1-pr889.422eb87
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/LICENSE.md +1 -0
- package/dist/apiClientConfigStore.d.mts +17 -0
- package/dist/apiClientConfigStore.d.ts +17 -0
- package/dist/apiClientConfigStore.js +56 -0
- package/dist/apiClientConfigStore.mjs +9 -0
- package/dist/apiError.d.mts +30 -0
- package/dist/apiError.d.ts +30 -0
- package/dist/apiError.js +94 -0
- package/dist/apiError.mjs +13 -0
- package/dist/chunk-3SEO7S3Q.mjs +23 -0
- package/dist/chunk-472P3XVV.mjs +13 -0
- package/dist/chunk-C5P5R2CL.mjs +79 -0
- package/dist/chunk-DHYJM4DQ.mjs +19 -0
- package/dist/chunk-H3C7VSOJ.mjs +25 -0
- package/dist/chunk-JCZWXJBU.mjs +10 -0
- package/dist/chunk-PY35XWDS.mjs +66 -0
- package/dist/chunk-RGDL3AEX.mjs +22 -0
- package/dist/chunk-VVRQ7D57.mjs +25 -0
- package/dist/chunk-WBQAMGXK.mjs +0 -0
- package/dist/fetcher.d.mts +12 -0
- package/dist/fetcher.d.ts +12 -0
- package/dist/fetcher.js +170 -0
- package/dist/fetcher.mjs +16 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +232 -0
- package/dist/index.mjs +43 -0
- package/dist/react/ApiClientConfigProvider.d.mts +17 -0
- package/dist/react/ApiClientConfigProvider.d.ts +17 -0
- package/dist/react/ApiClientConfigProvider.js +87 -0
- package/dist/react/ApiClientConfigProvider.mjs +11 -0
- package/dist/react/index.d.mts +8 -0
- package/dist/react/index.d.ts +8 -0
- package/dist/react/index.js +112 -0
- package/dist/react/index.mjs +20 -0
- package/dist/react/swr.d.mts +13 -0
- package/dist/react/swr.d.ts +13 -0
- package/dist/react/swr.js +43 -0
- package/dist/react/swr.mjs +6 -0
- package/dist/react/useApiClientConfig.d.mts +8 -0
- package/dist/react/useApiClientConfig.d.ts +8 -0
- package/dist/react/useApiClientConfig.js +86 -0
- package/dist/react/useApiClientConfig.mjs +12 -0
- package/dist/requestUrl.d.mts +6 -0
- package/dist/requestUrl.d.ts +6 -0
- package/dist/requestUrl.js +78 -0
- package/dist/requestUrl.mjs +8 -0
- package/dist/requestUrl.test.d.mts +2 -0
- package/dist/requestUrl.test.d.ts +2 -0
- package/dist/requestUrl.test.js +171 -0
- package/dist/requestUrl.test.mjs +114 -0
- package/dist/store.d.mts +13 -0
- package/dist/store.d.ts +13 -0
- package/dist/store.js +47 -0
- package/dist/store.mjs +6 -0
- package/dist/types.d.mts +12 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.js +18 -0
- package/dist/types.mjs +1 -0
- package/dist/zod.d.mts +6 -0
- package/dist/zod.d.ts +6 -0
- package/dist/zod.js +35 -0
- package/dist/zod.mjs +8 -0
- package/package.json +66 -0
package/dist/fetcher.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/fetcher.ts
|
|
21
|
+
var fetcher_exports = {};
|
|
22
|
+
__export(fetcher_exports, {
|
|
23
|
+
createBlobFetcher: () => createBlobFetcher,
|
|
24
|
+
createJsonFetcher: () => createJsonFetcher,
|
|
25
|
+
createTextFetcher: () => createTextFetcher,
|
|
26
|
+
createVoidFetcher: () => createVoidFetcher
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(fetcher_exports);
|
|
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/apiClientConfigStore.ts
|
|
97
|
+
var defaultConfig = {};
|
|
98
|
+
var store = createStore(defaultConfig);
|
|
99
|
+
|
|
100
|
+
// src/fetcher.ts
|
|
101
|
+
var defaultRequestInit = {
|
|
102
|
+
credentials: "include"
|
|
103
|
+
};
|
|
104
|
+
var createJsonFetcher = (schema, customRequestInit = {}) => (input, requestInit = {}) => createTextFetcher(customRequestInit)(input, requestInit).then((text) => {
|
|
105
|
+
const parsedResponse = JSON.parse(text);
|
|
106
|
+
const result = schema.safeParse(parsedResponse);
|
|
107
|
+
const config = store.getState();
|
|
108
|
+
if (result.success) {
|
|
109
|
+
return result.data;
|
|
110
|
+
}
|
|
111
|
+
if (config.showsSchemaParseError) {
|
|
112
|
+
console.error(result.error);
|
|
113
|
+
}
|
|
114
|
+
if (config.forceDeserializeResponse) {
|
|
115
|
+
config.onFailedDeserializeResponse(input, result.error);
|
|
116
|
+
return parsedResponse;
|
|
117
|
+
}
|
|
118
|
+
throw result.error;
|
|
119
|
+
});
|
|
120
|
+
var createTextFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, {
|
|
121
|
+
...defaultRequestInit,
|
|
122
|
+
...customRequestInit,
|
|
123
|
+
...requestInit,
|
|
124
|
+
headers: {
|
|
125
|
+
...defaultRequestInit.headers,
|
|
126
|
+
...customRequestInit.headers,
|
|
127
|
+
...requestInit.headers
|
|
128
|
+
}
|
|
129
|
+
}).then(async (res) => {
|
|
130
|
+
const body = await res.text();
|
|
131
|
+
if (res.ok) return body;
|
|
132
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
133
|
+
throw new HTTPError(code, body);
|
|
134
|
+
});
|
|
135
|
+
var createBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, {
|
|
136
|
+
...defaultRequestInit,
|
|
137
|
+
...customRequestInit,
|
|
138
|
+
...requestInit,
|
|
139
|
+
headers: {
|
|
140
|
+
...defaultRequestInit.headers,
|
|
141
|
+
...customRequestInit.headers,
|
|
142
|
+
...requestInit.headers
|
|
143
|
+
}
|
|
144
|
+
}).then(async (res) => {
|
|
145
|
+
const body = await res.blob();
|
|
146
|
+
if (res.ok) return { body, headers: res.headers };
|
|
147
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
148
|
+
throw new HTTPError(code, body);
|
|
149
|
+
});
|
|
150
|
+
var createVoidFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, {
|
|
151
|
+
...defaultRequestInit,
|
|
152
|
+
...customRequestInit,
|
|
153
|
+
...requestInit,
|
|
154
|
+
headers: {
|
|
155
|
+
...defaultRequestInit.headers,
|
|
156
|
+
...customRequestInit.headers,
|
|
157
|
+
...requestInit.headers
|
|
158
|
+
}
|
|
159
|
+
}).then(async (res) => {
|
|
160
|
+
if (res.ok) return;
|
|
161
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
162
|
+
throw new HTTPError(code);
|
|
163
|
+
});
|
|
164
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
165
|
+
0 && (module.exports = {
|
|
166
|
+
createBlobFetcher,
|
|
167
|
+
createJsonFetcher,
|
|
168
|
+
createTextFetcher,
|
|
169
|
+
createVoidFetcher
|
|
170
|
+
});
|
package/dist/fetcher.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createBlobFetcher,
|
|
3
|
+
createJsonFetcher,
|
|
4
|
+
createTextFetcher,
|
|
5
|
+
createVoidFetcher
|
|
6
|
+
} from "./chunk-C5P5R2CL.mjs";
|
|
7
|
+
import "./chunk-PY35XWDS.mjs";
|
|
8
|
+
import "./chunk-JCZWXJBU.mjs";
|
|
9
|
+
import "./chunk-472P3XVV.mjs";
|
|
10
|
+
import "./chunk-3SEO7S3Q.mjs";
|
|
11
|
+
export {
|
|
12
|
+
createBlobFetcher,
|
|
13
|
+
createJsonFetcher,
|
|
14
|
+
createTextFetcher,
|
|
15
|
+
createVoidFetcher
|
|
16
|
+
};
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { Config, setApiClientConfig, store } from './apiClientConfigStore.mjs';
|
|
2
|
+
export { ErrorStatusCode, HTTPError, errorStatusCode, errorTitle, getErrorStatus } from './apiError.mjs';
|
|
3
|
+
export { BlobFetcherResponse, createBlobFetcher, createJsonFetcher, createTextFetcher, createVoidFetcher } from './fetcher.mjs';
|
|
4
|
+
export { UrlConfig, __internal__requestUrl } from './requestUrl.mjs';
|
|
5
|
+
export { Store, createStore } from './store.mjs';
|
|
6
|
+
export { ForceDig, QueryPropsFor } from './types.mjs';
|
|
7
|
+
export { isZodError, schemaForType } from './zod.mjs';
|
|
8
|
+
import 'zod';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { Config, 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 { UrlConfig, __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
|
+
import 'zod';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
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
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
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
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
HTTPError: () => HTTPError,
|
|
34
|
+
__internal__requestUrl: () => __internal__requestUrl,
|
|
35
|
+
createBlobFetcher: () => createBlobFetcher,
|
|
36
|
+
createJsonFetcher: () => createJsonFetcher,
|
|
37
|
+
createStore: () => createStore,
|
|
38
|
+
createTextFetcher: () => createTextFetcher,
|
|
39
|
+
createVoidFetcher: () => createVoidFetcher,
|
|
40
|
+
errorStatusCode: () => errorStatusCode,
|
|
41
|
+
errorTitle: () => errorTitle,
|
|
42
|
+
getErrorStatus: () => getErrorStatus,
|
|
43
|
+
isZodError: () => isZodError,
|
|
44
|
+
schemaForType: () => schemaForType,
|
|
45
|
+
setApiClientConfig: () => setApiClientConfig,
|
|
46
|
+
store: () => store
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(src_exports);
|
|
49
|
+
|
|
50
|
+
// src/store.ts
|
|
51
|
+
var createStore = (initialState) => {
|
|
52
|
+
let state = initialState;
|
|
53
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
54
|
+
const getState = () => state;
|
|
55
|
+
const setState = (fn) => {
|
|
56
|
+
state = fn(state);
|
|
57
|
+
listeners.forEach((listener) => listener());
|
|
58
|
+
};
|
|
59
|
+
const subscribe = (listener) => {
|
|
60
|
+
listeners.add(listener);
|
|
61
|
+
return () => listeners.delete(listener);
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
getState,
|
|
65
|
+
setState,
|
|
66
|
+
subscribe
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// src/apiClientConfigStore.ts
|
|
71
|
+
var defaultConfig = {};
|
|
72
|
+
var store = createStore(defaultConfig);
|
|
73
|
+
var setApiClientConfig = (config) => store.setState(() => config);
|
|
74
|
+
|
|
75
|
+
// src/zod.ts
|
|
76
|
+
var schemaForType = () => (arg) => {
|
|
77
|
+
return arg;
|
|
78
|
+
};
|
|
79
|
+
var isZodError = (obj) => obj !== null && typeof obj === "object" && obj.constructor.name === "ZodError";
|
|
80
|
+
|
|
81
|
+
// src/apiError.ts
|
|
82
|
+
var errorStatusCode = {
|
|
83
|
+
MOVED_PERMANENTLY: 301,
|
|
84
|
+
FOUND: 302,
|
|
85
|
+
BAD_REQUEST: 400,
|
|
86
|
+
UNAUTHORIZED: 401,
|
|
87
|
+
FORBIDDEN: 403,
|
|
88
|
+
NOT_FOUND: 404,
|
|
89
|
+
PAYLOAD_TOO_LARGE: 413,
|
|
90
|
+
NETWORK_ERROR: 418,
|
|
91
|
+
UNPROCESSABLE_ENTITY: 422,
|
|
92
|
+
INTERNAL_SERVER_ERROR: 500,
|
|
93
|
+
BAD_GATEWAY: 502,
|
|
94
|
+
SERVER_UNAVAILABLE: 503,
|
|
95
|
+
GATEWAY_TIMEOUT: 504,
|
|
96
|
+
ZOD_ERROR: 901,
|
|
97
|
+
UNHANDLED_ERROR: 999
|
|
98
|
+
};
|
|
99
|
+
var errorTitle = {
|
|
100
|
+
301: "\u30DA\u30FC\u30B8\u304C\u79FB\u52D5\u3055\u308C\u3066\u3044\u307E\u3059",
|
|
101
|
+
302: "\u30DA\u30FC\u30B8\u304C\u4E00\u6642\u7684\u306B\u79FB\u52D5\u3055\u308C\u3066\u3044\u307E\u3059",
|
|
102
|
+
400: "\u30EA\u30AF\u30A8\u30B9\u30C8\u304C\u4E0D\u6B63\u3067\u3059",
|
|
103
|
+
401: "\u30ED\u30B0\u30A4\u30F3\u3057\u3066\u304F\u3060\u3055\u3044",
|
|
104
|
+
403: "\u4E0D\u6B63\u306A\u30C8\u30FC\u30AF\u30F3\u3067\u3059",
|
|
105
|
+
404: "\u30DA\u30FC\u30B8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3067\u3057\u305F",
|
|
106
|
+
413: "\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
|
|
107
|
+
418: "\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
|
|
108
|
+
422: "\u30C7\u30FC\u30BF\u304C\u4E0D\u6B63\u3067\u3059",
|
|
109
|
+
500: "\u30B5\u30FC\u30D0\u30FC\u3067\u30A8\u30E9\u30FC\u304C\u8D77\u304D\u307E\u3057\u305F",
|
|
110
|
+
502: "\u30B5\u30FC\u30D0\u30FC\u3067\u30A8\u30E9\u30FC\u304C\u8D77\u304D\u307E\u3057\u305F",
|
|
111
|
+
503: "\u30E1\u30F3\u30C6\u30CA\u30F3\u30B9\u4E2D\u3067\u3059",
|
|
112
|
+
504: "\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
|
|
113
|
+
901: "\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F",
|
|
114
|
+
999: "\u30B5\u30FC\u30D0\u30FC\u3067\u30A8\u30E9\u30FC\u304C\u8D77\u304D\u307E\u3057\u305F"
|
|
115
|
+
};
|
|
116
|
+
var HTTPError = class extends Error {
|
|
117
|
+
status;
|
|
118
|
+
body;
|
|
119
|
+
constructor(status, body) {
|
|
120
|
+
super(errorTitle[status]);
|
|
121
|
+
this.name = "HTTPError";
|
|
122
|
+
this.status = status;
|
|
123
|
+
this.body = body;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
var getErrorStatus = (response) => {
|
|
127
|
+
if (response instanceof Object && "status" in response && typeof response["status"] === "number") {
|
|
128
|
+
const status = Number(response["status"]);
|
|
129
|
+
return Object.values(errorStatusCode).includes(status) ? status : 999;
|
|
130
|
+
}
|
|
131
|
+
if (isZodError(response)) {
|
|
132
|
+
return errorStatusCode.ZOD_ERROR;
|
|
133
|
+
}
|
|
134
|
+
return void 0;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// src/fetcher.ts
|
|
138
|
+
var defaultRequestInit = {
|
|
139
|
+
credentials: "include"
|
|
140
|
+
};
|
|
141
|
+
var createJsonFetcher = (schema, customRequestInit = {}) => (input, requestInit = {}) => createTextFetcher(customRequestInit)(input, requestInit).then((text) => {
|
|
142
|
+
const parsedResponse = JSON.parse(text);
|
|
143
|
+
const result = schema.safeParse(parsedResponse);
|
|
144
|
+
const config = store.getState();
|
|
145
|
+
if (result.success) {
|
|
146
|
+
return result.data;
|
|
147
|
+
}
|
|
148
|
+
if (config.showsSchemaParseError) {
|
|
149
|
+
console.error(result.error);
|
|
150
|
+
}
|
|
151
|
+
if (config.forceDeserializeResponse) {
|
|
152
|
+
config.onFailedDeserializeResponse(input, result.error);
|
|
153
|
+
return parsedResponse;
|
|
154
|
+
}
|
|
155
|
+
throw result.error;
|
|
156
|
+
});
|
|
157
|
+
var createTextFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, {
|
|
158
|
+
...defaultRequestInit,
|
|
159
|
+
...customRequestInit,
|
|
160
|
+
...requestInit,
|
|
161
|
+
headers: {
|
|
162
|
+
...defaultRequestInit.headers,
|
|
163
|
+
...customRequestInit.headers,
|
|
164
|
+
...requestInit.headers
|
|
165
|
+
}
|
|
166
|
+
}).then(async (res) => {
|
|
167
|
+
const body = await res.text();
|
|
168
|
+
if (res.ok) return body;
|
|
169
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
170
|
+
throw new HTTPError(code, body);
|
|
171
|
+
});
|
|
172
|
+
var createBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, {
|
|
173
|
+
...defaultRequestInit,
|
|
174
|
+
...customRequestInit,
|
|
175
|
+
...requestInit,
|
|
176
|
+
headers: {
|
|
177
|
+
...defaultRequestInit.headers,
|
|
178
|
+
...customRequestInit.headers,
|
|
179
|
+
...requestInit.headers
|
|
180
|
+
}
|
|
181
|
+
}).then(async (res) => {
|
|
182
|
+
const body = await res.blob();
|
|
183
|
+
if (res.ok) return { body, headers: res.headers };
|
|
184
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
185
|
+
throw new HTTPError(code, body);
|
|
186
|
+
});
|
|
187
|
+
var createVoidFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, {
|
|
188
|
+
...defaultRequestInit,
|
|
189
|
+
...customRequestInit,
|
|
190
|
+
...requestInit,
|
|
191
|
+
headers: {
|
|
192
|
+
...defaultRequestInit.headers,
|
|
193
|
+
...customRequestInit.headers,
|
|
194
|
+
...requestInit.headers
|
|
195
|
+
}
|
|
196
|
+
}).then(async (res) => {
|
|
197
|
+
if (res.ok) return;
|
|
198
|
+
const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
|
|
199
|
+
throw new HTTPError(code);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// src/requestUrl.ts
|
|
203
|
+
var import_qs = __toESM(require("qs"));
|
|
204
|
+
function __internal__requestUrl(...args) {
|
|
205
|
+
const config = store.getState();
|
|
206
|
+
const rawPath = args[0];
|
|
207
|
+
const params = args[1] || {};
|
|
208
|
+
const query = args[2];
|
|
209
|
+
const hostName = config.hostName ? typeof config.hostName === "string" ? config.hostName : config.hostName(rawPath) : "";
|
|
210
|
+
const path = hostName + Object.entries(params).reduce(
|
|
211
|
+
(path2, [key, value]) => path2.replace(`{${key}}`, String(value)),
|
|
212
|
+
rawPath
|
|
213
|
+
);
|
|
214
|
+
return query ? `${path}?${import_qs.default.stringify(query)}` : path;
|
|
215
|
+
}
|
|
216
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
217
|
+
0 && (module.exports = {
|
|
218
|
+
HTTPError,
|
|
219
|
+
__internal__requestUrl,
|
|
220
|
+
createBlobFetcher,
|
|
221
|
+
createJsonFetcher,
|
|
222
|
+
createStore,
|
|
223
|
+
createTextFetcher,
|
|
224
|
+
createVoidFetcher,
|
|
225
|
+
errorStatusCode,
|
|
226
|
+
errorTitle,
|
|
227
|
+
getErrorStatus,
|
|
228
|
+
isZodError,
|
|
229
|
+
schemaForType,
|
|
230
|
+
setApiClientConfig,
|
|
231
|
+
store
|
|
232
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createBlobFetcher,
|
|
3
|
+
createJsonFetcher,
|
|
4
|
+
createTextFetcher,
|
|
5
|
+
createVoidFetcher
|
|
6
|
+
} from "./chunk-C5P5R2CL.mjs";
|
|
7
|
+
import {
|
|
8
|
+
HTTPError,
|
|
9
|
+
errorStatusCode,
|
|
10
|
+
errorTitle,
|
|
11
|
+
getErrorStatus
|
|
12
|
+
} from "./chunk-PY35XWDS.mjs";
|
|
13
|
+
import {
|
|
14
|
+
isZodError,
|
|
15
|
+
schemaForType
|
|
16
|
+
} from "./chunk-JCZWXJBU.mjs";
|
|
17
|
+
import {
|
|
18
|
+
__internal__requestUrl
|
|
19
|
+
} from "./chunk-RGDL3AEX.mjs";
|
|
20
|
+
import {
|
|
21
|
+
setApiClientConfig,
|
|
22
|
+
store
|
|
23
|
+
} from "./chunk-472P3XVV.mjs";
|
|
24
|
+
import {
|
|
25
|
+
createStore
|
|
26
|
+
} from "./chunk-3SEO7S3Q.mjs";
|
|
27
|
+
import "./chunk-WBQAMGXK.mjs";
|
|
28
|
+
export {
|
|
29
|
+
HTTPError,
|
|
30
|
+
__internal__requestUrl,
|
|
31
|
+
createBlobFetcher,
|
|
32
|
+
createJsonFetcher,
|
|
33
|
+
createStore,
|
|
34
|
+
createTextFetcher,
|
|
35
|
+
createVoidFetcher,
|
|
36
|
+
errorStatusCode,
|
|
37
|
+
errorTitle,
|
|
38
|
+
getErrorStatus,
|
|
39
|
+
isZodError,
|
|
40
|
+
schemaForType,
|
|
41
|
+
setApiClientConfig,
|
|
42
|
+
store
|
|
43
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FC, ReactNode } from 'react';
|
|
2
|
+
import { Config } from '../apiClientConfigStore.mjs';
|
|
3
|
+
import { Store } from '../store.mjs';
|
|
4
|
+
import { SWRConfiguration } from 'swr';
|
|
5
|
+
import '../requestUrl.mjs';
|
|
6
|
+
|
|
7
|
+
type Configuration = Config & {
|
|
8
|
+
swr?: SWRConfiguration;
|
|
9
|
+
};
|
|
10
|
+
type Props = {
|
|
11
|
+
config: Configuration;
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
};
|
|
14
|
+
declare const ApiClientConfigProvider: FC<Props>;
|
|
15
|
+
declare const useApiClientConfigContext: () => Store<Config>;
|
|
16
|
+
|
|
17
|
+
export { ApiClientConfigProvider, useApiClientConfigContext };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FC, ReactNode } from 'react';
|
|
2
|
+
import { Config } from '../apiClientConfigStore.js';
|
|
3
|
+
import { Store } from '../store.js';
|
|
4
|
+
import { SWRConfiguration } from 'swr';
|
|
5
|
+
import '../requestUrl.js';
|
|
6
|
+
|
|
7
|
+
type Configuration = Config & {
|
|
8
|
+
swr?: SWRConfiguration;
|
|
9
|
+
};
|
|
10
|
+
type Props = {
|
|
11
|
+
config: Configuration;
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
};
|
|
14
|
+
declare const ApiClientConfigProvider: FC<Props>;
|
|
15
|
+
declare const useApiClientConfigContext: () => Store<Config>;
|
|
16
|
+
|
|
17
|
+
export { ApiClientConfigProvider, useApiClientConfigContext };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/react/ApiClientConfigProvider.tsx
|
|
21
|
+
var ApiClientConfigProvider_exports = {};
|
|
22
|
+
__export(ApiClientConfigProvider_exports, {
|
|
23
|
+
ApiClientConfigProvider: () => ApiClientConfigProvider,
|
|
24
|
+
useApiClientConfigContext: () => useApiClientConfigContext
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(ApiClientConfigProvider_exports);
|
|
27
|
+
var import_react2 = require("react");
|
|
28
|
+
|
|
29
|
+
// src/store.ts
|
|
30
|
+
var createStore = (initialState) => {
|
|
31
|
+
let state = initialState;
|
|
32
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
33
|
+
const getState = () => state;
|
|
34
|
+
const setState = (fn) => {
|
|
35
|
+
state = fn(state);
|
|
36
|
+
listeners.forEach((listener) => listener());
|
|
37
|
+
};
|
|
38
|
+
const subscribe = (listener) => {
|
|
39
|
+
listeners.add(listener);
|
|
40
|
+
return () => listeners.delete(listener);
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
getState,
|
|
44
|
+
setState,
|
|
45
|
+
subscribe
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// src/apiClientConfigStore.ts
|
|
50
|
+
var defaultConfig = {};
|
|
51
|
+
var store = createStore(defaultConfig);
|
|
52
|
+
|
|
53
|
+
// src/react/ApiClientConfigProvider.tsx
|
|
54
|
+
var import_swr = require("swr");
|
|
55
|
+
|
|
56
|
+
// src/react/swr.ts
|
|
57
|
+
var import_react = require("react");
|
|
58
|
+
var abortMiddleware = (useSWRNext) => (key, fetcher, config) => {
|
|
59
|
+
const ctrlRef = (0, import_react.useRef)();
|
|
60
|
+
const extendedFetcher = fetcher ? (key2) => {
|
|
61
|
+
ctrlRef.current?.abort();
|
|
62
|
+
ctrlRef.current = new AbortController();
|
|
63
|
+
return fetcher(key2, { signal: ctrlRef.current.signal });
|
|
64
|
+
} : fetcher;
|
|
65
|
+
return useSWRNext(key, extendedFetcher, config);
|
|
66
|
+
};
|
|
67
|
+
var createSwrConfig = (config) => ({
|
|
68
|
+
...config,
|
|
69
|
+
use: [...config?.use ?? [], abortMiddleware]
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// src/react/ApiClientConfigProvider.tsx
|
|
73
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
74
|
+
var ApiClientConfigContext = (0, import_react2.createContext)(store);
|
|
75
|
+
var ApiClientConfigProvider = (props) => {
|
|
76
|
+
const { swr, ...config } = props.config;
|
|
77
|
+
(0, import_react2.useEffect)(() => {
|
|
78
|
+
store.setState(() => config);
|
|
79
|
+
}, [config]);
|
|
80
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ApiClientConfigContext.Provider, { value: store, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_swr.SWRConfig, { value: createSwrConfig(swr), children: props.children }) });
|
|
81
|
+
};
|
|
82
|
+
var useApiClientConfigContext = () => (0, import_react2.useContext)(ApiClientConfigContext) || store;
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
ApiClientConfigProvider,
|
|
86
|
+
useApiClientConfigContext
|
|
87
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ApiClientConfigProvider,
|
|
3
|
+
useApiClientConfigContext
|
|
4
|
+
} from "../chunk-VVRQ7D57.mjs";
|
|
5
|
+
import "../chunk-DHYJM4DQ.mjs";
|
|
6
|
+
import "../chunk-472P3XVV.mjs";
|
|
7
|
+
import "../chunk-3SEO7S3Q.mjs";
|
|
8
|
+
export {
|
|
9
|
+
ApiClientConfigProvider,
|
|
10
|
+
useApiClientConfigContext
|
|
11
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { ApiClientConfigProvider, useApiClientConfigContext } from './ApiClientConfigProvider.mjs';
|
|
2
|
+
export { Configuration, createSwrConfig } from './swr.mjs';
|
|
3
|
+
export { useApiClientConfig, useApiClientConfigWithSelector } from './useApiClientConfig.mjs';
|
|
4
|
+
import 'react';
|
|
5
|
+
import '../apiClientConfigStore.mjs';
|
|
6
|
+
import '../store.mjs';
|
|
7
|
+
import '../requestUrl.mjs';
|
|
8
|
+
import 'swr';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { ApiClientConfigProvider, useApiClientConfigContext } from './ApiClientConfigProvider.js';
|
|
2
|
+
export { Configuration, createSwrConfig } from './swr.js';
|
|
3
|
+
export { useApiClientConfig, useApiClientConfigWithSelector } from './useApiClientConfig.js';
|
|
4
|
+
import 'react';
|
|
5
|
+
import '../apiClientConfigStore.js';
|
|
6
|
+
import '../store.js';
|
|
7
|
+
import '../requestUrl.js';
|
|
8
|
+
import 'swr';
|