@readyfor/api-client-base 1.22.0-pr1284.8c3c6e8 → 1.22.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.d.ts +10 -11
- package/dist/apiClientConfigStore.js +37 -10
- package/dist/apiClientConfigStore.mjs +12 -9
- package/dist/apiError.d.ts +25 -24
- package/dist/apiError.js +95 -68
- package/dist/apiError.mjs +18 -70
- package/dist/chunk-3SEO7S3Q.mjs +23 -0
- package/dist/chunk-5JS6U5IM.mjs +37 -0
- package/dist/chunk-DH33ZDBG.mjs +19 -0
- package/dist/chunk-FNLUAQWC.mjs +80 -0
- package/dist/chunk-GD4RTKUU.mjs +22 -0
- package/dist/chunk-JCZWXJBU.mjs +10 -0
- package/dist/chunk-NOC6G3HZ.mjs +21 -0
- package/dist/chunk-NYICHGY2.mjs +30 -0
- package/dist/chunk-OVR3ZT2S.mjs +118 -0
- package/dist/chunk-QXFPBYPL.mjs +25 -0
- package/dist/chunk-TZUKIYFN.mjs +14 -0
- package/dist/chunk-WBQAMGXK.mjs +0 -0
- package/dist/fetcher.d.ts +7 -8
- package/dist/fetcher.js +125 -57
- package/dist/fetcher.mjs +20 -63
- package/dist/index.d.ts +10 -10
- package/dist/index.js +38 -31
- package/dist/index.mjs +63 -10
- package/dist/react/ApiClientConfigProvider.d.ts +9 -10
- package/dist/react/ApiClientConfigProvider.js +41 -24
- package/dist/react/ApiClientConfigProvider.mjs +12 -22
- package/dist/react/index.d.ts +7 -4
- package/dist/react/index.js +26 -10
- package/dist/react/index.mjs +24 -4
- package/dist/react/swr.d.ts +9 -10
- package/dist/react/swr.js +37 -24
- package/dist/react/swr.mjs +5 -25
- package/dist/react/useApiClientConfig.d.ts +5 -5
- package/dist/react/useApiClientConfig.js +50 -18
- package/dist/react/useApiClientConfig.mjs +15 -19
- package/dist/requestUrl.d.ts +2 -3
- package/dist/requestUrl.js +49 -14
- package/dist/requestUrl.mjs +10 -13
- package/dist/store.d.ts +5 -6
- package/dist/store.js +43 -20
- package/dist/store.mjs +5 -20
- package/dist/types.d.ts +11 -5
- package/dist/types.js +16 -0
- package/dist/types.mjs +1 -1
- package/dist/utils/headersInit.d.ts +2 -3
- package/dist/utils/headersInit.js +49 -45
- package/dist/utils/headersInit.mjs +7 -46
- package/dist/utils/requestInit.d.ts +3 -10
- package/dist/utils/requestInit.js +31 -14
- package/dist/utils/requestInit.mjs +7 -15
- package/dist/zod.d.ts +3 -4
- package/dist/zod.js +30 -6
- package/dist/zod.mjs +7 -6
- package/package.json +18 -3
- package/dist/_virtual/_rolldown/runtime.js +0 -23
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import { Store } from
|
|
1
|
+
import { Store } from './store.js';
|
|
2
2
|
|
|
3
|
-
//#region src/apiClientConfigStore.d.ts
|
|
4
3
|
type DeserializeResponseConfig = {
|
|
5
|
-
|
|
4
|
+
forceDeserializeResponse?: false;
|
|
6
5
|
} | {
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
forceDeserializeResponse: true;
|
|
7
|
+
onFailedDeserializeResponse: (input: RequestInfo, error: Error) => void;
|
|
9
8
|
};
|
|
10
9
|
type LoggingConfig = {
|
|
11
|
-
|
|
10
|
+
showsSchemaParseError?: boolean;
|
|
12
11
|
};
|
|
13
12
|
type RequestConfig = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
hostName?: string | ((path: string) => string);
|
|
14
|
+
defaultRequestInit?: RequestInit;
|
|
15
|
+
onError?: (error: unknown) => void;
|
|
17
16
|
};
|
|
18
17
|
type Config = RequestConfig & DeserializeResponseConfig & LoggingConfig;
|
|
19
18
|
declare const store: Store<Config>;
|
|
20
19
|
declare const setApiClientConfig: (config: Config) => void;
|
|
21
20
|
declare const buildRequestInitWithDefaultConfig: (customRequestInit?: RequestInit) => RequestInit;
|
|
22
|
-
|
|
23
|
-
export { Config, RequestConfig, buildRequestInitWithDefaultConfig, setApiClientConfig, store };
|
|
21
|
+
|
|
22
|
+
export { type Config, type RequestConfig, buildRequestInitWithDefaultConfig, setApiClientConfig, store };
|
|
@@ -1,13 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
+
var apiClientConfigStore_exports = {};
|
|
20
|
+
__export(apiClientConfigStore_exports, {
|
|
21
|
+
buildRequestInitWithDefaultConfig: () => buildRequestInitWithDefaultConfig,
|
|
22
|
+
setApiClientConfig: () => setApiClientConfig,
|
|
23
|
+
store: () => store
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(apiClientConfigStore_exports);
|
|
26
|
+
var import_store = require("./store");
|
|
27
|
+
var import_requestInit = require("./utils/requestInit");
|
|
28
|
+
const defaultConfig = {};
|
|
29
|
+
const store = globalThis[Symbol.for("@readyfor/api-client-base/config")] ??= (0, import_store.createStore)(defaultConfig);
|
|
5
30
|
const setApiClientConfig = (config) => store.setState(() => config);
|
|
6
31
|
const buildRequestInitWithDefaultConfig = (customRequestInit = {}) => {
|
|
7
|
-
|
|
8
|
-
|
|
32
|
+
const { defaultRequestInit = {} } = store.getState();
|
|
33
|
+
return (0, import_requestInit.mergeRequestInit)(defaultRequestInit, customRequestInit);
|
|
9
34
|
};
|
|
10
|
-
|
|
11
|
-
exports
|
|
12
|
-
|
|
13
|
-
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
buildRequestInitWithDefaultConfig,
|
|
38
|
+
setApiClientConfig,
|
|
39
|
+
store
|
|
40
|
+
});
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import {
|
|
2
|
+
buildRequestInitWithDefaultConfig,
|
|
3
|
+
setApiClientConfig,
|
|
4
|
+
store
|
|
5
|
+
} from "./chunk-NOC6G3HZ.mjs";
|
|
6
|
+
import "./chunk-TZUKIYFN.mjs";
|
|
7
|
+
import "./chunk-NYICHGY2.mjs";
|
|
8
|
+
import "./chunk-3SEO7S3Q.mjs";
|
|
9
|
+
export {
|
|
10
|
+
buildRequestInitWithDefaultConfig,
|
|
11
|
+
setApiClientConfig,
|
|
12
|
+
store
|
|
8
13
|
};
|
|
9
|
-
//#endregion
|
|
10
|
-
export { buildRequestInitWithDefaultConfig, setApiClientConfig, store };
|
package/dist/apiError.d.ts
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
//#region src/apiError.d.ts
|
|
2
1
|
type ErrorStatusCode = 301 | 302 | 400 | 401 | 403 | 404 | 409 | 413 | 418 | 422 | 500 | 502 | 503 | 504 | 901 | 999;
|
|
3
2
|
declare const errorStatusCode: {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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 CONFLICT: 409;
|
|
10
|
+
readonly PAYLOAD_TOO_LARGE: 413;
|
|
11
|
+
readonly NETWORK_ERROR: 418;
|
|
12
|
+
readonly UNPROCESSABLE_ENTITY: 422;
|
|
13
|
+
readonly INTERNAL_SERVER_ERROR: 500;
|
|
14
|
+
readonly BAD_GATEWAY: 502;
|
|
15
|
+
readonly SERVER_UNAVAILABLE: 503;
|
|
16
|
+
readonly GATEWAY_TIMEOUT: 504;
|
|
17
|
+
readonly ZOD_ERROR: 901;
|
|
18
|
+
readonly UNHANDLED_ERROR: 999;
|
|
19
|
+
};
|
|
20
|
+
declare const errorTitle: {
|
|
21
|
+
[key in ErrorStatusCode]: string;
|
|
20
22
|
};
|
|
21
|
-
declare const errorTitle: { [key in ErrorStatusCode]: string };
|
|
22
23
|
declare class HTTPError extends Error {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
status: ErrorStatusCode;
|
|
25
|
+
body?: unknown;
|
|
26
|
+
constructor(status: ErrorStatusCode);
|
|
27
|
+
constructor(status: ErrorStatusCode, body: unknown);
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
29
30
|
* duck typing で HTTPError の status を判定する。
|
|
@@ -35,5 +36,5 @@ declare const isHttpErrorWithStatus: (error: unknown, status: number) => boolean
|
|
|
35
36
|
declare const getHttpErrorBody: (error: unknown) => unknown;
|
|
36
37
|
declare const getHttpErrorBodyReason: (body: unknown) => string | undefined;
|
|
37
38
|
declare const getErrorStatus: (response: unknown) => ErrorStatusCode | undefined;
|
|
38
|
-
|
|
39
|
-
export { ErrorStatusCode, HTTPError, errorStatusCode, errorTitle, getErrorStatus, getHttpErrorBody, getHttpErrorBodyReason, isHttpErrorWithStatus };
|
|
39
|
+
|
|
40
|
+
export { type ErrorStatusCode, HTTPError, errorStatusCode, errorTitle, getErrorStatus, getHttpErrorBody, getHttpErrorBodyReason, isHttpErrorWithStatus };
|
package/dist/apiError.js
CHANGED
|
@@ -1,78 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
var apiError_exports = {};
|
|
20
|
+
__export(apiError_exports, {
|
|
21
|
+
HTTPError: () => HTTPError,
|
|
22
|
+
errorStatusCode: () => errorStatusCode,
|
|
23
|
+
errorTitle: () => errorTitle,
|
|
24
|
+
getErrorStatus: () => getErrorStatus,
|
|
25
|
+
getHttpErrorBody: () => getHttpErrorBody,
|
|
26
|
+
getHttpErrorBodyReason: () => getHttpErrorBodyReason,
|
|
27
|
+
isHttpErrorWithStatus: () => isHttpErrorWithStatus
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(apiError_exports);
|
|
30
|
+
var import_zod = require("./zod");
|
|
4
31
|
const errorStatusCode = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
32
|
+
MOVED_PERMANENTLY: 301,
|
|
33
|
+
FOUND: 302,
|
|
34
|
+
BAD_REQUEST: 400,
|
|
35
|
+
UNAUTHORIZED: 401,
|
|
36
|
+
FORBIDDEN: 403,
|
|
37
|
+
NOT_FOUND: 404,
|
|
38
|
+
CONFLICT: 409,
|
|
39
|
+
PAYLOAD_TOO_LARGE: 413,
|
|
40
|
+
NETWORK_ERROR: 418,
|
|
41
|
+
UNPROCESSABLE_ENTITY: 422,
|
|
42
|
+
INTERNAL_SERVER_ERROR: 500,
|
|
43
|
+
BAD_GATEWAY: 502,
|
|
44
|
+
SERVER_UNAVAILABLE: 503,
|
|
45
|
+
GATEWAY_TIMEOUT: 504,
|
|
46
|
+
ZOD_ERROR: 901,
|
|
47
|
+
UNHANDLED_ERROR: 999
|
|
21
48
|
};
|
|
22
49
|
const errorTitle = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
}
|
|
50
|
+
301: "\u30DA\u30FC\u30B8\u304C\u79FB\u52D5\u3055\u308C\u3066\u3044\u307E\u3059",
|
|
51
|
+
302: "\u30DA\u30FC\u30B8\u304C\u4E00\u6642\u7684\u306B\u79FB\u52D5\u3055\u308C\u3066\u3044\u307E\u3059",
|
|
52
|
+
400: "\u30EA\u30AF\u30A8\u30B9\u30C8\u304C\u4E0D\u6B63\u3067\u3059",
|
|
53
|
+
401: "\u30ED\u30B0\u30A4\u30F3\u3057\u3066\u304F\u3060\u3055\u3044",
|
|
54
|
+
403: "\u4E0D\u6B63\u306A\u30C8\u30FC\u30AF\u30F3\u3067\u3059",
|
|
55
|
+
404: "\u30DA\u30FC\u30B8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3067\u3057\u305F",
|
|
56
|
+
409: "\u7DE8\u96C6\u5185\u5BB9\u304C\u7AF6\u5408\u3057\u3066\u3044\u307E\u3059",
|
|
57
|
+
413: "\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
|
|
58
|
+
418: "\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
|
|
59
|
+
422: "\u30C7\u30FC\u30BF\u304C\u4E0D\u6B63\u3067\u3059",
|
|
60
|
+
500: "\u30B5\u30FC\u30D0\u30FC\u3067\u30A8\u30E9\u30FC\u304C\u8D77\u304D\u307E\u3057\u305F",
|
|
61
|
+
502: "\u30B5\u30FC\u30D0\u30FC\u3067\u30A8\u30E9\u30FC\u304C\u8D77\u304D\u307E\u3057\u305F",
|
|
62
|
+
503: "\u30E1\u30F3\u30C6\u30CA\u30F3\u30B9\u4E2D\u3067\u3059",
|
|
63
|
+
504: "\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
|
|
64
|
+
901: "\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F",
|
|
65
|
+
999: "\u30B5\u30FC\u30D0\u30FC\u3067\u30A8\u30E9\u30FC\u304C\u8D77\u304D\u307E\u3057\u305F"
|
|
49
66
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
67
|
+
class HTTPError extends Error {
|
|
68
|
+
status;
|
|
69
|
+
body;
|
|
70
|
+
constructor(status, body) {
|
|
71
|
+
super(errorTitle[status]);
|
|
72
|
+
this.name = "HTTPError";
|
|
73
|
+
this.status = status;
|
|
74
|
+
this.body = body;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
56
77
|
const isHttpErrorWithStatus = (error, status) => error instanceof Error && "status" in error && error.status === status;
|
|
57
78
|
const getHttpErrorBody = (error) => error instanceof Error && "body" in error ? error.body : void 0;
|
|
58
79
|
const getHttpErrorBodyReason = (body) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
80
|
+
if (body !== null && typeof body === "object" && "reason" in body) {
|
|
81
|
+
const reason = body.reason;
|
|
82
|
+
return typeof reason === "string" ? reason : void 0;
|
|
83
|
+
}
|
|
84
|
+
return void 0;
|
|
63
85
|
};
|
|
64
86
|
const getErrorStatus = (response) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
87
|
+
if (response instanceof Object && "status" in response && typeof response["status"] === "number") {
|
|
88
|
+
const status = Number(response["status"]);
|
|
89
|
+
return Object.values(errorStatusCode).includes(status) ? status : 999;
|
|
90
|
+
}
|
|
91
|
+
if ((0, import_zod.isZodError)(response)) {
|
|
92
|
+
return errorStatusCode.ZOD_ERROR;
|
|
93
|
+
}
|
|
94
|
+
return void 0;
|
|
70
95
|
};
|
|
71
|
-
|
|
72
|
-
exports
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
96
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
97
|
+
0 && (module.exports = {
|
|
98
|
+
HTTPError,
|
|
99
|
+
errorStatusCode,
|
|
100
|
+
errorTitle,
|
|
101
|
+
getErrorStatus,
|
|
102
|
+
getHttpErrorBody,
|
|
103
|
+
getHttpErrorBodyReason,
|
|
104
|
+
isHttpErrorWithStatus
|
|
105
|
+
});
|
package/dist/apiError.mjs
CHANGED
|
@@ -1,71 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
UNHANDLED_ERROR: 999
|
|
1
|
+
import {
|
|
2
|
+
HTTPError,
|
|
3
|
+
errorStatusCode,
|
|
4
|
+
errorTitle,
|
|
5
|
+
getErrorStatus,
|
|
6
|
+
getHttpErrorBody,
|
|
7
|
+
getHttpErrorBodyReason,
|
|
8
|
+
isHttpErrorWithStatus
|
|
9
|
+
} from "./chunk-FNLUAQWC.mjs";
|
|
10
|
+
import "./chunk-JCZWXJBU.mjs";
|
|
11
|
+
export {
|
|
12
|
+
HTTPError,
|
|
13
|
+
errorStatusCode,
|
|
14
|
+
errorTitle,
|
|
15
|
+
getErrorStatus,
|
|
16
|
+
getHttpErrorBody,
|
|
17
|
+
getHttpErrorBodyReason,
|
|
18
|
+
isHttpErrorWithStatus
|
|
20
19
|
};
|
|
21
|
-
const errorTitle = {
|
|
22
|
-
301: "ページが移動されています",
|
|
23
|
-
302: "ページが一時的に移動されています",
|
|
24
|
-
400: "リクエストが不正です",
|
|
25
|
-
401: "ログインしてください",
|
|
26
|
-
403: "不正なトークンです",
|
|
27
|
-
404: "ページが見つかりませんでした",
|
|
28
|
-
409: "編集内容が競合しています",
|
|
29
|
-
413: "通信に失敗しました",
|
|
30
|
-
418: "通信に失敗しました",
|
|
31
|
-
422: "データが不正です",
|
|
32
|
-
500: "サーバーでエラーが起きました",
|
|
33
|
-
502: "サーバーでエラーが起きました",
|
|
34
|
-
503: "メンテナンス中です",
|
|
35
|
-
504: "通信に失敗しました",
|
|
36
|
-
901: "問題が発生しました",
|
|
37
|
-
999: "サーバーでエラーが起きました"
|
|
38
|
-
};
|
|
39
|
-
var HTTPError = class extends Error {
|
|
40
|
-
status;
|
|
41
|
-
body;
|
|
42
|
-
constructor(status, body) {
|
|
43
|
-
super(errorTitle[status]);
|
|
44
|
-
this.name = "HTTPError";
|
|
45
|
-
this.status = status;
|
|
46
|
-
this.body = body;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* duck typing で HTTPError の status を判定する。
|
|
51
|
-
* pnpm の strict isolation により instanceof HTTPError が
|
|
52
|
-
* 別バージョンのクラスと一致しないケースがあるため、
|
|
53
|
-
* プロパティベースで判定する。
|
|
54
|
-
*/
|
|
55
|
-
const isHttpErrorWithStatus = (error, status) => error instanceof Error && "status" in error && error.status === status;
|
|
56
|
-
const getHttpErrorBody = (error) => error instanceof Error && "body" in error ? error.body : void 0;
|
|
57
|
-
const getHttpErrorBodyReason = (body) => {
|
|
58
|
-
if (body !== null && typeof body === "object" && "reason" in body) {
|
|
59
|
-
const reason = body.reason;
|
|
60
|
-
return typeof reason === "string" ? reason : void 0;
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
const getErrorStatus = (response) => {
|
|
64
|
-
if (response instanceof Object && "status" in response && typeof response["status"] === "number") {
|
|
65
|
-
const status = Number(response["status"]);
|
|
66
|
-
return Object.values(errorStatusCode).includes(status) ? status : 999;
|
|
67
|
-
}
|
|
68
|
-
if (isZodError(response)) return errorStatusCode.ZOD_ERROR;
|
|
69
|
-
};
|
|
70
|
-
//#endregion
|
|
71
|
-
export { HTTPError, errorStatusCode, errorTitle, getErrorStatus, getHttpErrorBody, getHttpErrorBodyReason, isHttpErrorWithStatus };
|
|
@@ -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,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useApiClientConfigContext
|
|
3
|
+
} from "./chunk-QXFPBYPL.mjs";
|
|
4
|
+
import {
|
|
5
|
+
mergeRequestInit
|
|
6
|
+
} from "./chunk-TZUKIYFN.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, store.getState);
|
|
15
|
+
};
|
|
16
|
+
var useApiClientConfigWithSelector = (selector) => {
|
|
17
|
+
const store = useApiClientConfigContext();
|
|
18
|
+
return useSyncExternalStoreWithSelector(
|
|
19
|
+
store.subscribe,
|
|
20
|
+
store.getState,
|
|
21
|
+
store.getState,
|
|
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,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,80 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
};
|