entity-server-client 0.2.5 → 0.3.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.
Files changed (50) hide show
  1. package/README.md +32 -1
  2. package/build.mjs +11 -1
  3. package/docs/api/alimtalk.md +62 -0
  4. package/docs/api/auth.md +256 -0
  5. package/docs/api/email.md +37 -0
  6. package/docs/api/entity.md +273 -0
  7. package/docs/api/file.md +80 -0
  8. package/docs/api/health.md +41 -0
  9. package/docs/api/identity.md +32 -0
  10. package/docs/api/import.md +34 -0
  11. package/docs/api/packet.md +25 -0
  12. package/docs/api/pg.md +90 -0
  13. package/docs/api/push.md +107 -0
  14. package/docs/api/react.md +141 -0
  15. package/docs/api/setup.md +43 -0
  16. package/docs/api/sms.md +45 -0
  17. package/docs/api/smtp.md +33 -0
  18. package/docs/api/transaction.md +50 -0
  19. package/docs/api/utils.md +52 -0
  20. package/docs/apis.md +22 -787
  21. package/docs/react.md +64 -7
  22. package/package.json +7 -1
  23. package/src/EntityServerClient.ts +28 -546
  24. package/src/client/base.ts +305 -0
  25. package/src/client/packet.ts +16 -52
  26. package/src/client/request.ts +46 -9
  27. package/src/client/utils.ts +17 -2
  28. package/src/hooks/useEntityServer.ts +3 -4
  29. package/src/mixins/auth.ts +143 -0
  30. package/src/mixins/entity.ts +205 -0
  31. package/src/mixins/file.ts +99 -0
  32. package/src/mixins/push.ts +109 -0
  33. package/src/mixins/smtp.ts +20 -0
  34. package/src/mixins/utils.ts +106 -0
  35. package/src/packet.ts +84 -0
  36. package/src/types.ts +93 -1
  37. package/tests/packet.test.mjs +50 -0
  38. package/dist/EntityServerClient.d.ts +0 -203
  39. package/dist/client/hmac.d.ts +0 -8
  40. package/dist/client/packet.d.ts +0 -22
  41. package/dist/client/request.d.ts +0 -16
  42. package/dist/client/utils.d.ts +0 -4
  43. package/dist/hooks/useEntityServer.d.ts +0 -63
  44. package/dist/index.d.ts +0 -4
  45. package/dist/index.js +0 -2
  46. package/dist/index.js.map +0 -7
  47. package/dist/react.d.ts +0 -1
  48. package/dist/react.js +0 -2
  49. package/dist/react.js.map +0 -7
  50. package/dist/types.d.ts +0 -165
@@ -0,0 +1,305 @@
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
+ anonymousPacketToken: string;
13
+ apiKey: string;
14
+ hmacSecret: string;
15
+ encryptRequests: boolean;
16
+ activeTxId: string | null = null;
17
+
18
+ // 세션 유지 관련
19
+ keepSession: boolean;
20
+ refreshBuffer: number;
21
+ onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
22
+ onSessionExpired?: (error: Error) => void;
23
+ _sessionRefreshToken: string | null = null;
24
+ _refreshTimer: ReturnType<typeof setTimeout> | null = null;
25
+
26
+ // ─── 초기화 & 설정 ────────────────────────────────────────────────────────
27
+
28
+ /**
29
+ * EntityServerClient 인스턴스를 생성합니다.
30
+ *
31
+ * 기본값:
32
+ * - `baseUrl`: `VITE_ENTITY_SERVER_URL` 또는 상대 경로(`""`)
33
+ */
34
+ constructor(options: EntityServerClientOptions = {}) {
35
+ const envBaseUrl = readEnv("VITE_ENTITY_SERVER_URL");
36
+
37
+ this.baseUrl = (options.baseUrl ?? envBaseUrl ?? "").replace(/\/$/, "");
38
+ this.token = options.token ?? "";
39
+ this.anonymousPacketToken = options.anonymousPacketToken ?? "";
40
+ this.apiKey = options.apiKey ?? "";
41
+ this.hmacSecret = options.hmacSecret ?? "";
42
+ this.encryptRequests = options.encryptRequests ?? false;
43
+ this.keepSession = options.keepSession ?? false;
44
+ this.refreshBuffer = options.refreshBuffer ?? 60;
45
+ this.onTokenRefreshed = options.onTokenRefreshed;
46
+ this.onSessionExpired = options.onSessionExpired;
47
+ }
48
+
49
+ /** baseUrl, token, encryptRequests 값을 런타임에 갱신합니다. */
50
+ configure(options: Partial<EntityServerClientOptions>): void {
51
+ if (typeof options.baseUrl === "string") {
52
+ this.baseUrl = options.baseUrl.replace(/\/$/, "");
53
+ }
54
+ if (typeof options.token === "string") this.token = options.token;
55
+ if (typeof options.anonymousPacketToken === "string") {
56
+ this.anonymousPacketToken = options.anonymousPacketToken;
57
+ }
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
+ /** 익명 패킷 암호화용 토큰을 설정합니다. */
79
+ setAnonymousPacketToken(token: string): void {
80
+ this.anonymousPacketToken = token;
81
+ }
82
+
83
+ /** HMAC 인증용 API Key를 설정합니다. */
84
+ setApiKey(apiKey: string): void {
85
+ this.apiKey = apiKey;
86
+ }
87
+
88
+ /** HMAC 인증용 시크릿을 설정합니다. */
89
+ setHmacSecret(secret: string): void {
90
+ this.hmacSecret = secret;
91
+ }
92
+
93
+ /** 암호화 요청 활성화 여부를 설정합니다. */
94
+ setEncryptRequests(value: boolean): void {
95
+ this.encryptRequests = value;
96
+ }
97
+
98
+ // ─── 세션 유지 ────────────────────────────────────────────────────────────
99
+
100
+ /** @internal 자동 토큰 갱신 타이머를 시작합니다. */
101
+ _scheduleKeepSession(
102
+ refreshToken: string,
103
+ expiresIn: number,
104
+ refreshFn: (
105
+ rt: string,
106
+ ) => Promise<{ access_token: string; expires_in: number }>,
107
+ ): void {
108
+ this._clearRefreshTimer();
109
+ this._sessionRefreshToken = refreshToken;
110
+ const delayMs = Math.max((expiresIn - this.refreshBuffer) * 1000, 0);
111
+ this._refreshTimer = setTimeout(async () => {
112
+ if (!this._sessionRefreshToken) return;
113
+ try {
114
+ const result = await refreshFn(this._sessionRefreshToken);
115
+ this.onTokenRefreshed?.(result.access_token, result.expires_in);
116
+ this._scheduleKeepSession(
117
+ this._sessionRefreshToken,
118
+ result.expires_in,
119
+ refreshFn,
120
+ );
121
+ } catch (err) {
122
+ this._clearRefreshTimer();
123
+ this.onSessionExpired?.(
124
+ err instanceof Error ? err : new Error(String(err)),
125
+ );
126
+ }
127
+ }, delayMs);
128
+ }
129
+
130
+ /** @internal 자동 갱신 타이머를 정리합니다. */
131
+ _clearRefreshTimer(): void {
132
+ if (this._refreshTimer !== null) {
133
+ clearTimeout(this._refreshTimer);
134
+ this._refreshTimer = null;
135
+ }
136
+ }
137
+
138
+ /**
139
+ * 세션 유지 타이머를 중지합니다.
140
+ * `logout()` 호출 시 자동으로 중지되며, 직접 호출이 필요한 경우는 드뭅니다.
141
+ */
142
+ stopKeepSession(): void {
143
+ this._clearRefreshTimer();
144
+ this._sessionRefreshToken = null;
145
+ }
146
+
147
+ // ─── 요청 본문 파싱 ───────────────────────────────────────────────────────
148
+
149
+ /**
150
+ * 요청 바디를 파싱합니다.
151
+ * `application/octet-stream`이면 XChaCha20-Poly1305 복호화, 그 외는 JSON 파싱합니다.
152
+ *
153
+ * @param requireEncrypted `true`이면 암호화된 요청만 허용합니다.
154
+ */
155
+ readRequestBody<T = Record<string, unknown>>(
156
+ body: ArrayBuffer | Uint8Array | string | T | null | undefined,
157
+ contentType = "application/json",
158
+ requireEncrypted = false,
159
+ ): T {
160
+ const key = derivePacketKey(
161
+ this.hmacSecret,
162
+ this.token || this.anonymousPacketToken,
163
+ );
164
+ return parseRequestBody<T>(body, contentType, requireEncrypted, key);
165
+ }
166
+
167
+ // ─── 내부 헬퍼 ───────────────────────────────────────────────────────────
168
+
169
+ get _reqOpts(): RequestOptions {
170
+ return {
171
+ baseUrl: this.baseUrl,
172
+ token: this.token,
173
+ anonymousPacketToken: this.anonymousPacketToken,
174
+ apiKey: this.apiKey,
175
+ hmacSecret: this.hmacSecret,
176
+ encryptRequests: this.encryptRequests,
177
+ };
178
+ }
179
+
180
+ requestJson<T>(
181
+ method: string,
182
+ path: string,
183
+ body?: unknown,
184
+ withAuth = true,
185
+ extraHeaders?: Record<string, string>,
186
+ ): Promise<T> {
187
+ return entityRequest<T>(
188
+ this._reqOpts,
189
+ method,
190
+ path,
191
+ body,
192
+ withAuth,
193
+ extraHeaders,
194
+ false,
195
+ );
196
+ }
197
+
198
+ _request<T>(
199
+ method: string,
200
+ path: string,
201
+ body?: unknown,
202
+ withAuth = true,
203
+ extraHeaders?: Record<string, string>,
204
+ ): Promise<T> {
205
+ return entityRequest<T>(
206
+ this._reqOpts,
207
+ method,
208
+ path,
209
+ body,
210
+ withAuth,
211
+ extraHeaders,
212
+ true,
213
+ );
214
+ }
215
+
216
+ /** PNG/바이너리 응답을 ArrayBuffer로 반환합니다. (QR, 바코드 등) */
217
+ async _requestBinary(
218
+ method: string,
219
+ path: string,
220
+ body?: unknown,
221
+ withAuth = true,
222
+ ): Promise<ArrayBuffer> {
223
+ const headers: Record<string, string> = {
224
+ "Content-Type": "application/json",
225
+ };
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 != null ? { body: JSON.stringify(body) } : {}),
234
+ credentials: "include",
235
+ });
236
+
237
+ if (!res.ok) {
238
+ const text = await res.text();
239
+ const err = new Error(`HTTP ${res.status}: ${text}`);
240
+ (err as { status?: number }).status = res.status;
241
+ throw err;
242
+ }
243
+
244
+ return res.arrayBuffer();
245
+ }
246
+
247
+ /** multipart/form-data 요청을 보냅니다. (파일 업로드 등) */
248
+ async _requestForm<T>(
249
+ method: string,
250
+ path: string,
251
+ form: FormData,
252
+ withAuth = true,
253
+ ): Promise<T> {
254
+ const headers: Record<string, string> = {};
255
+ if (withAuth && this.token)
256
+ headers["Authorization"] = `Bearer ${this.token}`;
257
+ if (this.apiKey) headers["X-API-Key"] = this.apiKey;
258
+
259
+ const res = await fetch(this.baseUrl + path, {
260
+ method,
261
+ headers,
262
+ body: form,
263
+ credentials: "include",
264
+ });
265
+
266
+ const data = await res.json();
267
+ if (!data.ok) {
268
+ const err = new Error(
269
+ data.message ?? `EntityServer error (HTTP ${res.status})`,
270
+ );
271
+ (err as { status?: number }).status = res.status;
272
+ throw err;
273
+ }
274
+ return data as T;
275
+ }
276
+
277
+ /** multipart/form-data 요청을 보내고 바이너리(ArrayBuffer)를 반환합니다. */
278
+ async _requestFormBinary(
279
+ method: string,
280
+ path: string,
281
+ form: FormData,
282
+ withAuth = true,
283
+ ): Promise<ArrayBuffer> {
284
+ const headers: Record<string, string> = {};
285
+ if (withAuth && this.token)
286
+ headers["Authorization"] = `Bearer ${this.token}`;
287
+ if (this.apiKey) headers["X-API-Key"] = this.apiKey;
288
+
289
+ const res = await fetch(this.baseUrl + path, {
290
+ method,
291
+ headers,
292
+ body: form,
293
+ credentials: "include",
294
+ });
295
+
296
+ if (!res.ok) {
297
+ const text = await res.text();
298
+ const err = new Error(`HTTP ${res.status}: ${text}`);
299
+ (err as { status?: number }).status = res.status;
300
+ throw err;
301
+ }
302
+
303
+ return res.arrayBuffer();
304
+ }
305
+ }
@@ -1,71 +1,37 @@
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";
1
+ import {
2
+ derivePacketKey as derivePacketKeyCore,
3
+ encryptPacket as encryptPacketCore,
4
+ decryptPacket as decryptPacketCore,
5
+ } from "../packet";
7
6
 
8
7
  /**
9
8
  * 패킷 암호화 키를 유도합니다.
10
9
  * - HMAC 모드 (`hmacSecret` 유효 시): HKDF-SHA256(hmac_secret, "entity-server:packet-encryption")
11
- * - JWT 모드: SHA-256(jwt_token)
10
+ * - JWT 모드: HKDF-SHA256(jwt_token, "entity-server:packet-encryption")
12
11
  */
13
12
  export function derivePacketKey(hmacSecret: string, token: string): Uint8Array {
14
- if (hmacSecret) {
15
- const salt = new TextEncoder().encode("entity-server:hkdf:v1");
16
- const info = new TextEncoder().encode(
17
- "entity-server:packet-encryption",
18
- );
19
- return hkdf(
20
- sha256,
21
- new TextEncoder().encode(hmacSecret),
22
- salt,
23
- info,
24
- 32,
25
- );
26
- }
27
- return sha256(new TextEncoder().encode(token));
13
+ return derivePacketKeyCore(hmacSecret || token);
28
14
  }
29
15
 
30
16
  /**
31
17
  * 평문 바이트를 XChaCha20-Poly1305로 암호화합니다.
32
- * 포맷: [random_magic:magicLen][random_nonce:24][ciphertext+tag]
18
+ * 포맷: [random_magic:K][random_nonce:24][ciphertext+tag]
19
+ * K = 2 + key[31] % 14 (패킷 키에서 자동 파생)
33
20
  */
34
21
  export function encryptPacket(
35
22
  plaintext: Uint8Array,
36
23
  key: Uint8Array,
37
- magicLen: number,
38
24
  ): Uint8Array {
39
- const magic = new Uint8Array(magicLen);
40
- const nonce = new Uint8Array(24);
41
- crypto.getRandomValues(magic);
42
- crypto.getRandomValues(nonce);
43
- const cipher = xchacha20poly1305(key, nonce);
44
- const ciphertext = cipher.encrypt(plaintext);
45
- const result = new Uint8Array(magicLen + 24 + ciphertext.length);
46
- result.set(magic, 0);
47
- result.set(nonce, magicLen);
48
- result.set(ciphertext, magicLen + 24);
49
- return result;
25
+ return encryptPacketCore(plaintext, key);
50
26
  }
51
27
 
52
28
  /**
53
29
  * XChaCha20-Poly1305 패킷을 복호화해 JSON 객체로 변환합니다.
54
- * 포맷: [magic:magicLen][nonce:24][ciphertext+tag]
30
+ * 포맷: [magic:K][nonce:24][ciphertext+tag]
31
+ * K = 2 + key[31] % 14 (패킷 키에서 자동 파생)
55
32
  */
56
- export function decryptPacket<T>(
57
- buffer: ArrayBuffer,
58
- key: Uint8Array,
59
- magicLen: number,
60
- ): T {
61
- const data = new Uint8Array(buffer);
62
- if (data.length < magicLen + 24 + 16) {
63
- throw new Error("Encrypted packet too short");
64
- }
65
- const nonce = data.slice(magicLen, magicLen + 24);
66
- const ciphertext = data.slice(magicLen + 24);
67
- const cipher = xchacha20poly1305(key, nonce);
68
- const plaintext = cipher.decrypt(ciphertext);
33
+ export function decryptPacket<T>(buffer: ArrayBuffer, key: Uint8Array): T {
34
+ const plaintext = decryptPacketCore(buffer, key);
69
35
  return JSON.parse(new TextDecoder().decode(plaintext)) as T;
70
36
  }
71
37
 
@@ -79,7 +45,6 @@ export function parseRequestBody<T>(
79
45
  contentType: string,
80
46
  requireEncrypted: boolean,
81
47
  key: Uint8Array,
82
- magicLen: number,
83
48
  ): T {
84
49
  const isEncrypted = contentType
85
50
  .toLowerCase()
@@ -93,14 +58,13 @@ export function parseRequestBody<T>(
93
58
 
94
59
  if (isEncrypted) {
95
60
  if (body == null) throw new Error("Encrypted request body is empty");
96
- if (body instanceof ArrayBuffer)
97
- return decryptPacket<T>(body, key, magicLen);
61
+ if (body instanceof ArrayBuffer) return decryptPacket<T>(body, key);
98
62
  if (body instanceof Uint8Array) {
99
63
  const sliced = body.buffer.slice(
100
64
  body.byteOffset,
101
65
  body.byteOffset + body.byteLength,
102
66
  );
103
- return decryptPacket<T>(sliced as ArrayBuffer, key, magicLen);
67
+ return decryptPacket<T>(sliced as ArrayBuffer, key);
104
68
  }
105
69
  throw new Error(
106
70
  "Encrypted request body must be ArrayBuffer or Uint8Array",
@@ -4,12 +4,31 @@ import { buildHmacHeaders } from "./hmac";
4
4
  export interface RequestOptions {
5
5
  baseUrl: string;
6
6
  token: string;
7
+ anonymousPacketToken: string;
7
8
  apiKey: string;
8
9
  hmacSecret: string;
9
- packetMagicLen: number;
10
10
  encryptRequests: boolean;
11
11
  }
12
12
 
13
+ function resolvePacketSource(opts: RequestOptions): string {
14
+ return opts.hmacSecret || opts.token || opts.anonymousPacketToken;
15
+ }
16
+
17
+ async function readErrorMessage(res: Response): Promise<string> {
18
+ const contentType = res.headers.get("Content-Type") ?? "";
19
+ if (contentType.includes("application/json")) {
20
+ const data = (await res.json().catch(() => null)) as {
21
+ error?: string;
22
+ message?: string;
23
+ } | null;
24
+ if (data?.error) return data.error;
25
+ if (data?.message) return data.message;
26
+ }
27
+
28
+ const text = await res.text().catch(() => "");
29
+ return text || `HTTP ${res.status}`;
30
+ }
31
+
13
32
  /**
14
33
  * Entity Server에 HTTP 요청을 보냅니다.
15
34
  *
@@ -24,16 +43,18 @@ export async function entityRequest<T>(
24
43
  body?: unknown,
25
44
  withAuth = true,
26
45
  extraHeaders: Record<string, string> = {},
46
+ requireOkShape = true,
27
47
  ): Promise<T> {
28
48
  const {
29
49
  baseUrl,
30
50
  token,
31
51
  apiKey,
32
52
  hmacSecret,
33
- packetMagicLen,
34
53
  encryptRequests,
54
+ anonymousPacketToken,
35
55
  } = opts;
36
56
  const isHmacMode = withAuth && !!(apiKey && hmacSecret);
57
+ const packetSource = resolvePacketSource(opts);
37
58
 
38
59
  const headers: Record<string, string> = {
39
60
  "Content-Type": "application/json",
@@ -47,19 +68,23 @@ export async function entityRequest<T>(
47
68
  if (body != null) {
48
69
  const shouldEncrypt =
49
70
  encryptRequests &&
50
- withAuth &&
51
- (token || isHmacMode) &&
71
+ !!packetSource &&
52
72
  method !== "GET" &&
53
73
  method !== "HEAD";
54
74
 
55
75
  if (shouldEncrypt) {
56
- const key = derivePacketKey(hmacSecret, token);
76
+ const key = derivePacketKey(
77
+ hmacSecret,
78
+ token || anonymousPacketToken,
79
+ );
57
80
  fetchBody = encryptPacket(
58
81
  new TextEncoder().encode(JSON.stringify(body)),
59
82
  key,
60
- packetMagicLen,
61
83
  );
62
84
  headers["Content-Type"] = "application/octet-stream";
85
+ if (!token && !isHmacMode && anonymousPacketToken) {
86
+ headers["X-Packet-Token"] = anonymousPacketToken;
87
+ }
63
88
  } else {
64
89
  fetchBody = JSON.stringify(body);
65
90
  }
@@ -82,21 +107,33 @@ export async function entityRequest<T>(
82
107
  method,
83
108
  headers,
84
109
  ...(fetchBody != null ? { body: fetchBody as BodyInit } : {}),
110
+ credentials: "include",
85
111
  });
86
112
 
113
+ if (!res.ok) {
114
+ const err = new Error(await readErrorMessage(res));
115
+ (err as { status?: number }).status = res.status;
116
+ throw err;
117
+ }
118
+
87
119
  const contentType = res.headers.get("Content-Type") ?? "";
88
120
  if (contentType.includes("application/octet-stream")) {
89
- const key = derivePacketKey(hmacSecret, token);
90
- return decryptPacket<T>(await res.arrayBuffer(), key, packetMagicLen);
121
+ const key = derivePacketKey(hmacSecret, token || anonymousPacketToken);
122
+ return decryptPacket<T>(await res.arrayBuffer(), key);
123
+ }
124
+
125
+ if (!contentType.includes("application/json")) {
126
+ return (await res.text()) as T;
91
127
  }
92
128
 
93
129
  const data = await res.json();
94
- if (!data.ok) {
130
+ if (requireOkShape && !data.ok) {
95
131
  const err = new Error(
96
132
  data.message ?? `EntityServer error (HTTP ${res.status})`,
97
133
  );
98
134
  (err as { status?: number }).status = res.status;
99
135
  throw err;
100
136
  }
137
+
101
138
  return data as T;
102
139
  }
@@ -1,9 +1,24 @@
1
- /** Vite 환경변수(`import.meta.env`)에서 값을 읽습니다. */
1
+ /**
2
+ * 환경변수를 읽습니다.
3
+ * - 브라우저/Vite: `import.meta.env`
4
+ * - Node.js: `process.env`
5
+ */
2
6
  export function readEnv(name: string): string | undefined {
7
+ // Vite / 기타 번들러 (import.meta.env)
3
8
  const meta = import.meta as unknown as {
4
9
  env?: Record<string, string | undefined>;
5
10
  };
6
- return meta?.env?.[name];
11
+ if (meta?.env?.[name] != null) return meta.env[name];
12
+
13
+ // Node.js (process.env)
14
+ const _proc = (
15
+ globalThis as { process?: { env?: Record<string, string | undefined> } }
16
+ ).process;
17
+ if (_proc?.env?.[name] != null) {
18
+ return _proc.env[name];
19
+ }
20
+
21
+ return undefined;
7
22
  }
8
23
 
9
24
  /** 쿼리 파라미터 객체를 URL 쿼리 문자열로 변환합니다. `orderBy` 키는 `order_by`로 변환됩니다. */
@@ -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) {