entity-server-client 0.2.4 → 0.2.6

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 (48) hide show
  1. package/README.md +0 -1
  2. package/build.mjs +4 -1
  3. package/dist/EntityServerClient.d.ts +709 -0
  4. package/dist/client/base.d.ts +59 -0
  5. package/dist/client/hmac.d.ts +8 -0
  6. package/dist/client/packet.d.ts +24 -0
  7. package/dist/client/request.d.ts +15 -0
  8. package/dist/client/utils.d.ts +8 -0
  9. package/dist/index.d.ts +3 -393
  10. package/dist/index.js +1 -1
  11. package/dist/index.js.map +4 -4
  12. package/dist/mixins/alimtalk.d.ts +56 -0
  13. package/dist/mixins/auth.d.ts +167 -0
  14. package/dist/mixins/email.d.ts +51 -0
  15. package/dist/mixins/entity.d.ts +119 -0
  16. package/dist/mixins/file.d.ts +78 -0
  17. package/dist/mixins/identity.d.ts +52 -0
  18. package/dist/mixins/pg.d.ts +63 -0
  19. package/dist/mixins/push.d.ts +110 -0
  20. package/dist/mixins/sms.d.ts +55 -0
  21. package/dist/mixins/smtp.d.ts +44 -0
  22. package/dist/mixins/utils.d.ts +70 -0
  23. package/dist/react.js +1 -1
  24. package/dist/react.js.map +4 -4
  25. package/dist/types.d.ts +329 -0
  26. package/docs/apis.md +5 -12
  27. package/docs/react.md +6 -7
  28. package/package.json +2 -1
  29. package/src/EntityServerClient.ts +54 -0
  30. package/src/client/base.ts +246 -0
  31. package/src/client/hmac.ts +41 -0
  32. package/src/client/packet.ts +100 -0
  33. package/src/client/request.ts +93 -0
  34. package/src/client/utils.ts +34 -0
  35. package/src/hooks/useEntityServer.ts +3 -4
  36. package/src/index.ts +3 -917
  37. package/src/mixins/alimtalk.ts +35 -0
  38. package/src/mixins/auth.ts +287 -0
  39. package/src/mixins/email.ts +46 -0
  40. package/src/mixins/entity.ts +205 -0
  41. package/src/mixins/file.ts +99 -0
  42. package/src/mixins/identity.ts +35 -0
  43. package/src/mixins/pg.ts +58 -0
  44. package/src/mixins/push.ts +132 -0
  45. package/src/mixins/sms.ts +46 -0
  46. package/src/mixins/smtp.ts +20 -0
  47. package/src/mixins/utils.ts +75 -0
  48. package/src/types.ts +388 -0
@@ -0,0 +1,246 @@
1
+ import type { EntityServerClientOptions } from "../types";
2
+ import { readEnv } from "./utils";
3
+ import { derivePacketKey, parseRequestBody } from "./packet";
4
+ import { entityRequest, type RequestOptions } from "./request";
5
+
6
+ // mixin 헬퍼 타입
7
+ export type GConstructor<T = object> = new (...args: any[]) => T;
8
+
9
+ export class EntityServerClientBase {
10
+ baseUrl: string;
11
+ token: string;
12
+ apiKey: string;
13
+ hmacSecret: string;
14
+ encryptRequests: boolean;
15
+ activeTxId: string | null = null;
16
+
17
+ // 세션 유지 관련
18
+ keepSession: boolean;
19
+ refreshBuffer: number;
20
+ onTokenRefreshed?: (
21
+ accessToken: string,
22
+ expiresIn: number,
23
+ ) => void;
24
+ onSessionExpired?: (error: Error) => void;
25
+ _sessionRefreshToken: string | null = null;
26
+ _refreshTimer: ReturnType<typeof setTimeout> | null = null;
27
+
28
+ // ─── 초기화 & 설정 ────────────────────────────────────────────────────────
29
+
30
+ /**
31
+ * EntityServerClient 인스턴스를 생성합니다.
32
+ *
33
+ * 기본값:
34
+ * - `baseUrl`: `VITE_ENTITY_SERVER_URL` 또는 `http://localhost:47200`
35
+ */
36
+ constructor(options: EntityServerClientOptions = {}) {
37
+ const envBaseUrl = readEnv("VITE_ENTITY_SERVER_URL");
38
+
39
+ this.baseUrl = (
40
+ options.baseUrl ??
41
+ envBaseUrl ??
42
+ "http://localhost:47200"
43
+ ).replace(/\/$/, "");
44
+ this.token = options.token ?? "";
45
+ this.apiKey = options.apiKey ?? "";
46
+ this.hmacSecret = options.hmacSecret ?? "";
47
+ this.encryptRequests = options.encryptRequests ?? false;
48
+ this.keepSession = options.keepSession ?? false;
49
+ this.refreshBuffer = options.refreshBuffer ?? 60;
50
+ this.onTokenRefreshed = options.onTokenRefreshed;
51
+ this.onSessionExpired = options.onSessionExpired;
52
+ }
53
+
54
+ /** baseUrl, token, encryptRequests 값을 런타임에 갱신합니다. */
55
+ configure(options: Partial<EntityServerClientOptions>): void {
56
+ if (options.baseUrl) this.baseUrl = options.baseUrl.replace(/\/$/, "");
57
+ if (typeof options.token === "string") this.token = options.token;
58
+ if (typeof options.encryptRequests === "boolean")
59
+ this.encryptRequests = options.encryptRequests;
60
+ if (typeof options.apiKey === "string") this.apiKey = options.apiKey;
61
+ if (typeof options.hmacSecret === "string")
62
+ this.hmacSecret = options.hmacSecret;
63
+ if (typeof options.keepSession === "boolean")
64
+ this.keepSession = options.keepSession;
65
+ if (typeof options.refreshBuffer === "number")
66
+ this.refreshBuffer = options.refreshBuffer;
67
+ if (options.onTokenRefreshed)
68
+ this.onTokenRefreshed = options.onTokenRefreshed;
69
+ if (options.onSessionExpired)
70
+ this.onSessionExpired = options.onSessionExpired;
71
+ }
72
+
73
+ /** 인증 요청에 사용할 JWT Access Token을 설정합니다. */
74
+ setToken(token: string): void {
75
+ this.token = token;
76
+ }
77
+
78
+ /** HMAC 인증용 API Key를 설정합니다. */
79
+ setApiKey(apiKey: string): void {
80
+ this.apiKey = apiKey;
81
+ }
82
+
83
+ /** HMAC 인증용 시크릿을 설정합니다. */
84
+ setHmacSecret(secret: string): void {
85
+ this.hmacSecret = secret;
86
+ }
87
+
88
+ /** 암호화 요청 활성화 여부를 설정합니다. */
89
+ setEncryptRequests(value: boolean): void {
90
+ this.encryptRequests = value;
91
+ }
92
+
93
+ // ─── 세션 유지 ────────────────────────────────────────────────────────────
94
+
95
+ /** @internal 자동 토큰 갱신 타이머를 시작합니다. */
96
+ _scheduleKeepSession(
97
+ refreshToken: string,
98
+ expiresIn: number,
99
+ refreshFn: (
100
+ rt: string,
101
+ ) => Promise<{ access_token: string; expires_in: number }>,
102
+ ): void {
103
+ this._clearRefreshTimer();
104
+ this._sessionRefreshToken = refreshToken;
105
+ const delayMs = Math.max((expiresIn - this.refreshBuffer) * 1000, 0);
106
+ this._refreshTimer = setTimeout(async () => {
107
+ if (!this._sessionRefreshToken) return;
108
+ try {
109
+ const result = await refreshFn(this._sessionRefreshToken);
110
+ this.onTokenRefreshed?.(result.access_token, result.expires_in);
111
+ this._scheduleKeepSession(
112
+ this._sessionRefreshToken,
113
+ result.expires_in,
114
+ refreshFn,
115
+ );
116
+ } catch (err) {
117
+ this._clearRefreshTimer();
118
+ this.onSessionExpired?.(
119
+ err instanceof Error ? err : new Error(String(err)),
120
+ );
121
+ }
122
+ }, delayMs);
123
+ }
124
+
125
+ /** @internal 자동 갱신 타이머를 정리합니다. */
126
+ _clearRefreshTimer(): void {
127
+ if (this._refreshTimer !== null) {
128
+ clearTimeout(this._refreshTimer);
129
+ this._refreshTimer = null;
130
+ }
131
+ }
132
+
133
+ /**
134
+ * 세션 유지 타이머를 중지합니다.
135
+ * `logout()` 호출 시 자동으로 중지되며, 직접 호출이 필요한 경우는 드뭅니다.
136
+ */
137
+ stopKeepSession(): void {
138
+ this._clearRefreshTimer();
139
+ this._sessionRefreshToken = null;
140
+ }
141
+
142
+ // ─── 요청 본문 파싱 ───────────────────────────────────────────────────────
143
+
144
+ /**
145
+ * 요청 바디를 파싱합니다.
146
+ * `application/octet-stream`이면 XChaCha20-Poly1305 복호화, 그 외는 JSON 파싱합니다.
147
+ *
148
+ * @param requireEncrypted `true`이면 암호화된 요청만 허용합니다.
149
+ */
150
+ readRequestBody<T = Record<string, unknown>>(
151
+ body: ArrayBuffer | Uint8Array | string | T | null | undefined,
152
+ contentType = "application/json",
153
+ requireEncrypted = false,
154
+ ): T {
155
+ const key = derivePacketKey(this.hmacSecret, this.token);
156
+ return parseRequestBody<T>(body, contentType, requireEncrypted, key);
157
+ }
158
+
159
+ // ─── 내부 헬퍼 ───────────────────────────────────────────────────────────
160
+
161
+ get _reqOpts(): RequestOptions {
162
+ return {
163
+ baseUrl: this.baseUrl,
164
+ token: this.token,
165
+ apiKey: this.apiKey,
166
+ hmacSecret: this.hmacSecret,
167
+ encryptRequests: this.encryptRequests,
168
+ };
169
+ }
170
+
171
+ _request<T>(
172
+ method: string,
173
+ path: string,
174
+ body?: unknown,
175
+ withAuth = true,
176
+ extraHeaders?: Record<string, string>,
177
+ ): Promise<T> {
178
+ return entityRequest<T>(
179
+ this._reqOpts,
180
+ method,
181
+ path,
182
+ body,
183
+ withAuth,
184
+ extraHeaders,
185
+ );
186
+ }
187
+
188
+ /** PNG/바이너리 응답을 ArrayBuffer로 반환합니다. (QR, 바코드 등) */
189
+ async _requestBinary(
190
+ method: string,
191
+ path: string,
192
+ body?: unknown,
193
+ withAuth = true,
194
+ ): Promise<ArrayBuffer> {
195
+ const headers: Record<string, string> = {
196
+ "Content-Type": "application/json",
197
+ };
198
+ if (withAuth && this.token)
199
+ headers["Authorization"] = `Bearer ${this.token}`;
200
+ if (this.apiKey) headers["X-API-Key"] = this.apiKey;
201
+
202
+ const res = await fetch(this.baseUrl + path, {
203
+ method,
204
+ headers,
205
+ ...(body != null ? { body: JSON.stringify(body) } : {}),
206
+ });
207
+
208
+ if (!res.ok) {
209
+ const text = await res.text();
210
+ const err = new Error(`HTTP ${res.status}: ${text}`);
211
+ (err as { status?: number }).status = res.status;
212
+ throw err;
213
+ }
214
+
215
+ return res.arrayBuffer();
216
+ }
217
+
218
+ /** multipart/form-data 요청을 보냅니다. (파일 업로드 등) */
219
+ async _requestForm<T>(
220
+ method: string,
221
+ path: string,
222
+ form: FormData,
223
+ withAuth = true,
224
+ ): Promise<T> {
225
+ const headers: Record<string, string> = {};
226
+ if (withAuth && this.token)
227
+ headers["Authorization"] = `Bearer ${this.token}`;
228
+ if (this.apiKey) headers["X-API-Key"] = this.apiKey;
229
+
230
+ const res = await fetch(this.baseUrl + path, {
231
+ method,
232
+ headers,
233
+ body: form,
234
+ });
235
+
236
+ const data = await res.json();
237
+ if (!data.ok) {
238
+ const err = new Error(
239
+ data.message ?? `EntityServer error (HTTP ${res.status})`,
240
+ );
241
+ (err as { status?: number }).status = res.status;
242
+ throw err;
243
+ }
244
+ return data as T;
245
+ }
246
+ }
@@ -0,0 +1,41 @@
1
+ // @ts-ignore
2
+ import { sha256 } from "@noble/hashes/sha2";
3
+ // @ts-ignore
4
+ import { hmac } from "@noble/hashes/hmac";
5
+
6
+ /**
7
+ * HMAC-SHA256 서명 헤더를 생성합니다.
8
+ *
9
+ * 서명 대상: `METHOD|PATH|TIMESTAMP|NONCE|BODY`
10
+ *
11
+ * @returns `X-API-Key`, `X-Timestamp`, `X-Nonce`, `X-Signature` 헤더 객체
12
+ */
13
+ export function buildHmacHeaders(
14
+ method: string,
15
+ path: string,
16
+ bodyBytes: Uint8Array,
17
+ apiKey: string,
18
+ hmacSecret: string,
19
+ ): Record<string, string> {
20
+ const timestamp = String(Math.floor(Date.now() / 1000));
21
+ const nonce = crypto.randomUUID();
22
+
23
+ const prefix = new TextEncoder().encode(
24
+ `${method}|${path}|${timestamp}|${nonce}|`,
25
+ );
26
+ const payload = new Uint8Array(prefix.length + bodyBytes.length);
27
+ payload.set(prefix, 0);
28
+ payload.set(bodyBytes, prefix.length);
29
+
30
+ const sig = hmac(sha256, new TextEncoder().encode(hmacSecret), payload);
31
+ const signature = [...sig]
32
+ .map((b) => b.toString(16).padStart(2, "0"))
33
+ .join("");
34
+
35
+ return {
36
+ "X-API-Key": apiKey,
37
+ "X-Timestamp": timestamp,
38
+ "X-Nonce": nonce,
39
+ "X-Signature": signature,
40
+ };
41
+ }
@@ -0,0 +1,100 @@
1
+ // @ts-ignore
2
+ import { xchacha20poly1305 } from "@noble/ciphers/chacha";
3
+ // @ts-ignore
4
+ import { sha256 } from "@noble/hashes/sha2";
5
+ // @ts-ignore
6
+ import { hkdf } from "@noble/hashes/hkdf";
7
+
8
+ /**
9
+ * 패킷 암호화 키를 유도합니다.
10
+ * - HMAC 모드 (`hmacSecret` 유효 시): HKDF-SHA256(hmac_secret, "entity-server:packet-encryption")
11
+ * - JWT 모드: HKDF-SHA256(jwt_token, "entity-server:packet-encryption")
12
+ */
13
+ export function derivePacketKey(hmacSecret: string, token: string): Uint8Array {
14
+ const ikm = hmacSecret || token;
15
+ const salt = new TextEncoder().encode("entity-server:hkdf:v1");
16
+ const info = new TextEncoder().encode("entity-server:packet-encryption");
17
+ return hkdf(sha256, new TextEncoder().encode(ikm), salt, info, 32);
18
+ }
19
+
20
+ /**
21
+ * 평문 바이트를 XChaCha20-Poly1305로 암호화합니다.
22
+ * 포맷: [random_magic:K][random_nonce:24][ciphertext+tag]
23
+ * K = 2 + key[31] % 14 (패킷 키에서 자동 파생)
24
+ */
25
+ export function encryptPacket(
26
+ plaintext: Uint8Array,
27
+ key: Uint8Array,
28
+ ): Uint8Array {
29
+ const magicLen = 2 + (key[31] % 14);
30
+ const magic = new Uint8Array(magicLen);
31
+ const nonce = new Uint8Array(24);
32
+ crypto.getRandomValues(magic);
33
+ crypto.getRandomValues(nonce);
34
+ const cipher = xchacha20poly1305(key, nonce);
35
+ const ciphertext = cipher.encrypt(plaintext);
36
+ const result = new Uint8Array(magicLen + 24 + ciphertext.length);
37
+ result.set(magic, 0);
38
+ result.set(nonce, magicLen);
39
+ result.set(ciphertext, magicLen + 24);
40
+ return result;
41
+ }
42
+
43
+ /**
44
+ * XChaCha20-Poly1305 패킷을 복호화해 JSON 객체로 변환합니다.
45
+ * 포맷: [magic:K][nonce:24][ciphertext+tag]
46
+ * K = 2 + key[31] % 14 (패킷 키에서 자동 파생)
47
+ */
48
+ export function decryptPacket<T>(buffer: ArrayBuffer, key: Uint8Array): T {
49
+ const magicLen = 2 + (key[31] % 14);
50
+ const data = new Uint8Array(buffer);
51
+ if (data.length < magicLen + 24 + 16) {
52
+ throw new Error("Encrypted packet too short");
53
+ }
54
+ const nonce = data.slice(magicLen, magicLen + 24);
55
+ const ciphertext = data.slice(magicLen + 24);
56
+ const cipher = xchacha20poly1305(key, nonce);
57
+ const plaintext = cipher.decrypt(ciphertext);
58
+ return JSON.parse(new TextDecoder().decode(plaintext)) as T;
59
+ }
60
+
61
+ /**
62
+ * 요청 바디를 파싱합니다. `application/octet-stream`이면 복호화, 그 외는 JSON 파싱합니다.
63
+ *
64
+ * @param requireEncrypted `true`이면 암호화된 요청만 허용합니다.
65
+ */
66
+ export function parseRequestBody<T>(
67
+ body: ArrayBuffer | Uint8Array | string | T | null | undefined,
68
+ contentType: string,
69
+ requireEncrypted: boolean,
70
+ key: Uint8Array,
71
+ ): T {
72
+ const isEncrypted = contentType
73
+ .toLowerCase()
74
+ .includes("application/octet-stream");
75
+
76
+ if (requireEncrypted && !isEncrypted) {
77
+ throw new Error(
78
+ "Encrypted request required: Content-Type must be application/octet-stream",
79
+ );
80
+ }
81
+
82
+ if (isEncrypted) {
83
+ if (body == null) throw new Error("Encrypted request body is empty");
84
+ if (body instanceof ArrayBuffer) return decryptPacket<T>(body, key);
85
+ if (body instanceof Uint8Array) {
86
+ const sliced = body.buffer.slice(
87
+ body.byteOffset,
88
+ body.byteOffset + body.byteLength,
89
+ );
90
+ return decryptPacket<T>(sliced as ArrayBuffer, key);
91
+ }
92
+ throw new Error(
93
+ "Encrypted request body must be ArrayBuffer or Uint8Array",
94
+ );
95
+ }
96
+
97
+ if (body == null || body === "") return {} as T;
98
+ if (typeof body === "string") return JSON.parse(body) as T;
99
+ return body as T;
100
+ }
@@ -0,0 +1,93 @@
1
+ import { derivePacketKey, encryptPacket, decryptPacket } from "./packet";
2
+ import { buildHmacHeaders } from "./hmac";
3
+
4
+ export interface RequestOptions {
5
+ baseUrl: string;
6
+ token: string;
7
+ apiKey: string;
8
+ hmacSecret: string;
9
+ encryptRequests: boolean;
10
+ }
11
+
12
+ /**
13
+ * Entity Server에 HTTP 요청을 보냅니다.
14
+ *
15
+ * - `encryptRequests` 활성화 시 인증된 POST 바디를 자동 암호화합니다.
16
+ * - 응답이 `application/octet-stream`이면 자동 복호화합니다.
17
+ * - JSON 응답의 `ok`가 false이면 에러를 던집니다.
18
+ */
19
+ export async function entityRequest<T>(
20
+ opts: RequestOptions,
21
+ method: string,
22
+ path: string,
23
+ body?: unknown,
24
+ withAuth = true,
25
+ extraHeaders: Record<string, string> = {},
26
+ ): Promise<T> {
27
+ const { baseUrl, token, apiKey, hmacSecret, encryptRequests } = opts;
28
+ const isHmacMode = withAuth && !!(apiKey && hmacSecret);
29
+
30
+ const headers: Record<string, string> = {
31
+ "Content-Type": "application/json",
32
+ ...extraHeaders,
33
+ };
34
+ if (!isHmacMode && withAuth && token) {
35
+ headers.Authorization = `Bearer ${token}`;
36
+ }
37
+
38
+ let fetchBody: string | Uint8Array | null = null;
39
+ if (body != null) {
40
+ const shouldEncrypt =
41
+ encryptRequests &&
42
+ withAuth &&
43
+ (token || isHmacMode) &&
44
+ method !== "GET" &&
45
+ method !== "HEAD";
46
+
47
+ if (shouldEncrypt) {
48
+ const key = derivePacketKey(hmacSecret, token);
49
+ fetchBody = encryptPacket(
50
+ new TextEncoder().encode(JSON.stringify(body)),
51
+ key,
52
+ );
53
+ headers["Content-Type"] = "application/octet-stream";
54
+ } else {
55
+ fetchBody = JSON.stringify(body);
56
+ }
57
+ }
58
+
59
+ if (isHmacMode) {
60
+ const bodyBytes =
61
+ fetchBody instanceof Uint8Array
62
+ ? fetchBody
63
+ : typeof fetchBody === "string"
64
+ ? new TextEncoder().encode(fetchBody)
65
+ : new Uint8Array(0);
66
+ Object.assign(
67
+ headers,
68
+ buildHmacHeaders(method, path, bodyBytes, apiKey, hmacSecret),
69
+ );
70
+ }
71
+
72
+ const res = await fetch(baseUrl + path, {
73
+ method,
74
+ headers,
75
+ ...(fetchBody != null ? { body: fetchBody as BodyInit } : {}),
76
+ });
77
+
78
+ const contentType = res.headers.get("Content-Type") ?? "";
79
+ if (contentType.includes("application/octet-stream")) {
80
+ const key = derivePacketKey(hmacSecret, token);
81
+ return decryptPacket<T>(await res.arrayBuffer(), key);
82
+ }
83
+
84
+ const data = await res.json();
85
+ if (!data.ok) {
86
+ const err = new Error(
87
+ data.message ?? `EntityServer error (HTTP ${res.status})`,
88
+ );
89
+ (err as { status?: number }).status = res.status;
90
+ throw err;
91
+ }
92
+ return data as T;
93
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * 환경변수를 읽습니다.
3
+ * - 브라우저/Vite: `import.meta.env`
4
+ * - Node.js: `process.env`
5
+ */
6
+ export function readEnv(name: string): string | undefined {
7
+ // Vite / 기타 번들러 (import.meta.env)
8
+ const meta = import.meta as unknown as {
9
+ env?: Record<string, string | undefined>;
10
+ };
11
+ if (meta?.env?.[name] != null) return meta.env[name];
12
+
13
+ // Node.js (process.env)
14
+ if (
15
+ typeof process !== "undefined" &&
16
+ process.env &&
17
+ process.env[name] != null
18
+ ) {
19
+ return process.env[name];
20
+ }
21
+
22
+ return undefined;
23
+ }
24
+
25
+ /** 쿼리 파라미터 객체를 URL 쿼리 문자열로 변환합니다. `orderBy` 키는 `order_by`로 변환됩니다. */
26
+ export function buildQuery(params: Record<string, unknown>): string {
27
+ return Object.entries(params)
28
+ .filter(([, value]) => value != null)
29
+ .map(
30
+ ([key, value]) =>
31
+ `${encodeURIComponent(key === "orderBy" ? "order_by" : key)}=${encodeURIComponent(String(value))}`,
32
+ )
33
+ .join("&");
34
+ }
@@ -69,7 +69,6 @@ export function useEntityServer(
69
69
  singleton = true,
70
70
  tokenResolver,
71
71
  baseUrl,
72
- packetMagicLen,
73
72
  token,
74
73
  resumeSession,
75
74
  } = options;
@@ -100,10 +99,10 @@ export function useEntityServer(
100
99
  const client = useMemo(() => {
101
100
  const c = singleton
102
101
  ? entityServer
103
- : new EntityServerClient({ baseUrl, packetMagicLen, token });
102
+ : new EntityServerClient({ baseUrl, token });
104
103
 
105
104
  if (singleton) {
106
- c.configure({ baseUrl, packetMagicLen, token });
105
+ c.configure({ baseUrl, token });
107
106
  }
108
107
 
109
108
  const resolvedToken = tokenResolver?.();
@@ -112,7 +111,7 @@ export function useEntityServer(
112
111
  }
113
112
 
114
113
  return c;
115
- }, [singleton, tokenResolver, baseUrl, packetMagicLen, token]);
114
+ }, [singleton, tokenResolver, baseUrl, token]);
116
115
 
117
116
  const run = useCallback(async <T>(fn: () => Promise<T>): Promise<T> => {
118
117
  if (mountedRef.current) {