entity-server-client 0.3.1 → 1.0.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 (69) hide show
  1. package/dist/EntityServerClient.d.ts +432 -0
  2. package/dist/client/base.d.ts +84 -0
  3. package/dist/client/hmac.d.ts +8 -0
  4. package/dist/client/packet.d.ts +24 -0
  5. package/dist/client/request.d.ts +16 -0
  6. package/dist/client/utils.d.ts +8 -0
  7. package/dist/hooks/useEntityServer.d.ts +63 -0
  8. package/{src/index.ts → dist/index.d.ts} +1 -3
  9. package/dist/index.js +2 -0
  10. package/dist/index.js.map +7 -0
  11. package/dist/mixins/alimtalk.d.ts +56 -0
  12. package/dist/mixins/auth.d.ts +100 -0
  13. package/dist/mixins/email.d.ts +51 -0
  14. package/dist/mixins/entity.d.ts +126 -0
  15. package/dist/mixins/file.d.ts +85 -0
  16. package/dist/mixins/identity.d.ts +52 -0
  17. package/dist/mixins/llm.d.ts +94 -0
  18. package/dist/mixins/pg.d.ts +63 -0
  19. package/dist/mixins/push.d.ts +101 -0
  20. package/dist/mixins/sms.d.ts +55 -0
  21. package/dist/mixins/smtp.d.ts +51 -0
  22. package/dist/mixins/utils.d.ts +88 -0
  23. package/dist/packet.d.ts +11 -0
  24. package/dist/packet.js +2 -0
  25. package/dist/packet.js.map +7 -0
  26. package/dist/react.js +2 -0
  27. package/dist/react.js.map +7 -0
  28. package/{src/types.ts → dist/types.d.ts} +2 -42
  29. package/package.json +9 -36
  30. package/LICENSE +0 -21
  31. package/README.md +0 -128
  32. package/build.mjs +0 -36
  33. package/docs/api/alimtalk.md +0 -62
  34. package/docs/api/auth.md +0 -256
  35. package/docs/api/email.md +0 -37
  36. package/docs/api/entity.md +0 -273
  37. package/docs/api/file.md +0 -80
  38. package/docs/api/health.md +0 -47
  39. package/docs/api/identity.md +0 -32
  40. package/docs/api/import.md +0 -45
  41. package/docs/api/packet.md +0 -90
  42. package/docs/api/pg.md +0 -90
  43. package/docs/api/push.md +0 -107
  44. package/docs/api/react.md +0 -141
  45. package/docs/api/request.md +0 -118
  46. package/docs/api/setup.md +0 -43
  47. package/docs/api/sms.md +0 -45
  48. package/docs/api/smtp.md +0 -33
  49. package/docs/api/transaction.md +0 -50
  50. package/docs/api/utils.md +0 -52
  51. package/docs/apis.md +0 -26
  52. package/docs/react.md +0 -137
  53. package/src/EntityServerClient.ts +0 -28
  54. package/src/client/base.ts +0 -348
  55. package/src/client/hmac.ts +0 -41
  56. package/src/client/packet.ts +0 -77
  57. package/src/client/request.ts +0 -139
  58. package/src/client/utils.ts +0 -33
  59. package/src/hooks/useEntityServer.ts +0 -154
  60. package/src/mixins/auth.ts +0 -143
  61. package/src/mixins/entity.ts +0 -205
  62. package/src/mixins/file.ts +0 -99
  63. package/src/mixins/push.ts +0 -109
  64. package/src/mixins/smtp.ts +0 -20
  65. package/src/mixins/utils.ts +0 -106
  66. package/src/packet.ts +0 -84
  67. package/tests/packet.test.mjs +0 -50
  68. package/tsconfig.json +0 -14
  69. /package/{src/react.ts → dist/react.d.ts} +0 -0
@@ -0,0 +1,432 @@
1
+ /**
2
+ * @file EntityServerClient.ts
3
+ * Mixin 패턴으로 구성된 EntityServerClient.
4
+ *
5
+ * 절(section)별 구현:
6
+ * src/client/base.ts — 상태·생성자·공통 헬퍼
7
+ * src/mixins/auth.ts — 인증 (로그인/로그아웃/me/트랜잭션 등)
8
+ * src/mixins/entity.ts — 트랜잭션 & 엔티티 CRUD
9
+ * src/mixins/push.ts — 푸시 디바이스 관리
10
+ * src/mixins/smtp.ts — SMTP 메일 발송
11
+ * src/mixins/file.ts — 파일 스토리지
12
+ * src/mixins/utils.ts — QR코드/바코드/PDF변환
13
+ */
14
+ import { EntityServerClientBase } from "./client/base";
15
+ declare const EntityServerClient_base: {
16
+ new (...args: any[]): {
17
+ qrcode(content: string, opts?: import("./types").QRCodeOptions): Promise<ArrayBuffer>;
18
+ qrcodeBase64(content: string, opts?: import("./types").QRCodeOptions): Promise<{
19
+ ok: boolean;
20
+ data: string;
21
+ data_uri: string;
22
+ }>;
23
+ qrcodeText(content: string, opts?: import("./types").QRCodeOptions): Promise<{
24
+ ok: boolean;
25
+ text: string;
26
+ }>;
27
+ barcode(content: string, opts?: import("./types").BarcodeOptions): Promise<ArrayBuffer>;
28
+ pdf2png(pdfData: ArrayBuffer | Uint8Array<ArrayBuffer>, opts?: import("./types").Pdf2PngOptions): Promise<ArrayBuffer>;
29
+ baseUrl: string;
30
+ token: string;
31
+ anonymousPacketToken: string;
32
+ apiKey: string;
33
+ hmacSecret: string;
34
+ encryptRequests: boolean;
35
+ activeTxId: string | null;
36
+ keepSession: boolean;
37
+ refreshBuffer: number;
38
+ onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
39
+ onSessionExpired?: (error: Error) => void;
40
+ _sessionRefreshToken: string | null;
41
+ _refreshTimer: ReturnType<typeof setTimeout> | null;
42
+ configure(options: Partial<import("./types").EntityServerClientOptions>): void;
43
+ setToken(token: string): void;
44
+ setAnonymousPacketToken(token: string): void;
45
+ setApiKey(apiKey: string): void;
46
+ setHmacSecret(secret: string): void;
47
+ setEncryptRequests(value: boolean): void;
48
+ _scheduleKeepSession(refreshToken: string, expiresIn: number, refreshFn: (rt: string) => Promise<{
49
+ access_token: string;
50
+ expires_in: number;
51
+ }>): void;
52
+ _clearRefreshTimer(): void;
53
+ stopKeepSession(): void;
54
+ readRequestBody<T = Record<string, unknown>>(body: ArrayBuffer | Uint8Array | string | T | null | undefined, contentType?: string, requireEncrypted?: boolean): T;
55
+ get _reqOpts(): import("./client/request").RequestOptions;
56
+ requestJson<T>(method: string, path: string, body?: unknown, withAuth?: boolean, extraHeaders?: Record<string, string>): Promise<T>;
57
+ requestBinary(method: string, path: string, body?: unknown, withAuth?: boolean): Promise<ArrayBuffer>;
58
+ requestForm<T>(method: string, path: string, form: FormData, withAuth?: boolean): Promise<T>;
59
+ requestFormBinary(method: string, path: string, form: FormData, withAuth?: boolean): Promise<ArrayBuffer>;
60
+ _request<T>(method: string, path: string, body?: unknown, withAuth?: boolean, extraHeaders?: Record<string, string>): Promise<T>;
61
+ _requestBinary(method: string, path: string, body?: unknown, withAuth?: boolean): Promise<ArrayBuffer>;
62
+ _requestForm<T>(method: string, path: string, form: FormData, withAuth?: boolean): Promise<T>;
63
+ _requestFormBinary(method: string, path: string, form: FormData, withAuth?: boolean): Promise<ArrayBuffer>;
64
+ };
65
+ } & {
66
+ new (...args: any[]): {
67
+ fileUpload(entity: string, file: File | Blob, opts?: import("./types").FileUploadOptions): Promise<{
68
+ ok: boolean;
69
+ uuid: string;
70
+ data: import("./types").FileMeta;
71
+ }>;
72
+ fileDownload(entity: string, uuid: string): Promise<ArrayBuffer>;
73
+ fileDelete(entity: string, uuid: string): Promise<{
74
+ ok: boolean;
75
+ uuid: string;
76
+ deleted: boolean;
77
+ }>;
78
+ fileList(entity: string, opts?: {
79
+ refSeq?: number;
80
+ }): Promise<{
81
+ ok: boolean;
82
+ data: {
83
+ items: import("./types").FileMeta[];
84
+ total: number;
85
+ };
86
+ }>;
87
+ fileMeta(entity: string, uuid: string): Promise<{
88
+ ok: boolean;
89
+ data: import("./types").FileMeta;
90
+ }>;
91
+ fileToken(uuid: string): Promise<{
92
+ ok: boolean;
93
+ token: string;
94
+ }>;
95
+ fileUrl(uuid: string): string;
96
+ baseUrl: string;
97
+ token: string;
98
+ anonymousPacketToken: string;
99
+ apiKey: string;
100
+ hmacSecret: string;
101
+ encryptRequests: boolean;
102
+ activeTxId: string | null;
103
+ keepSession: boolean;
104
+ refreshBuffer: number;
105
+ onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
106
+ onSessionExpired?: (error: Error) => void;
107
+ _sessionRefreshToken: string | null;
108
+ _refreshTimer: ReturnType<typeof setTimeout> | null;
109
+ configure(options: Partial<import("./types").EntityServerClientOptions>): void;
110
+ setToken(token: string): void;
111
+ setAnonymousPacketToken(token: string): void;
112
+ setApiKey(apiKey: string): void;
113
+ setHmacSecret(secret: string): void;
114
+ setEncryptRequests(value: boolean): void;
115
+ _scheduleKeepSession(refreshToken: string, expiresIn: number, refreshFn: (rt: string) => Promise<{
116
+ access_token: string;
117
+ expires_in: number;
118
+ }>): void;
119
+ _clearRefreshTimer(): void;
120
+ stopKeepSession(): void;
121
+ readRequestBody<T = Record<string, unknown>>(body: ArrayBuffer | Uint8Array | string | T | null | undefined, contentType?: string, requireEncrypted?: boolean): T;
122
+ get _reqOpts(): import("./client/request").RequestOptions;
123
+ requestJson<T>(method: string, path: string, body?: unknown, withAuth?: boolean, extraHeaders?: Record<string, string>): Promise<T>;
124
+ requestBinary(method: string, path: string, body?: unknown, withAuth?: boolean): Promise<ArrayBuffer>;
125
+ requestForm<T>(method: string, path: string, form: FormData, withAuth?: boolean): Promise<T>;
126
+ requestFormBinary(method: string, path: string, form: FormData, withAuth?: boolean): Promise<ArrayBuffer>;
127
+ _request<T>(method: string, path: string, body?: unknown, withAuth?: boolean, extraHeaders?: Record<string, string>): Promise<T>;
128
+ _requestBinary(method: string, path: string, body?: unknown, withAuth?: boolean): Promise<ArrayBuffer>;
129
+ _requestForm<T>(method: string, path: string, form: FormData, withAuth?: boolean): Promise<T>;
130
+ _requestFormBinary(method: string, path: string, form: FormData, withAuth?: boolean): Promise<ArrayBuffer>;
131
+ };
132
+ } & {
133
+ new (...args: any[]): {
134
+ smtpSend(req: import("./types").SmtpSendRequest): Promise<{
135
+ ok: boolean;
136
+ seq: number;
137
+ }>;
138
+ smtpStatus(seq: number): Promise<{
139
+ ok: boolean;
140
+ status: string;
141
+ }>;
142
+ baseUrl: string;
143
+ token: string;
144
+ anonymousPacketToken: string;
145
+ apiKey: string;
146
+ hmacSecret: string;
147
+ encryptRequests: boolean;
148
+ activeTxId: string | null;
149
+ keepSession: boolean;
150
+ refreshBuffer: number;
151
+ onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
152
+ onSessionExpired?: (error: Error) => void;
153
+ _sessionRefreshToken: string | null;
154
+ _refreshTimer: ReturnType<typeof setTimeout> | null;
155
+ configure(options: Partial<import("./types").EntityServerClientOptions>): void;
156
+ setToken(token: string): void;
157
+ setAnonymousPacketToken(token: string): void;
158
+ setApiKey(apiKey: string): void;
159
+ setHmacSecret(secret: string): void;
160
+ setEncryptRequests(value: boolean): void;
161
+ _scheduleKeepSession(refreshToken: string, expiresIn: number, refreshFn: (rt: string) => Promise<{
162
+ access_token: string;
163
+ expires_in: number;
164
+ }>): void;
165
+ _clearRefreshTimer(): void;
166
+ stopKeepSession(): void;
167
+ readRequestBody<T = Record<string, unknown>>(body: ArrayBuffer | Uint8Array | string | T | null | undefined, contentType?: string, requireEncrypted?: boolean): T;
168
+ get _reqOpts(): import("./client/request").RequestOptions;
169
+ requestJson<T>(method: string, path: string, body?: unknown, withAuth?: boolean, extraHeaders?: Record<string, string>): Promise<T>;
170
+ requestBinary(method: string, path: string, body?: unknown, withAuth?: boolean): Promise<ArrayBuffer>;
171
+ requestForm<T>(method: string, path: string, form: FormData, withAuth?: boolean): Promise<T>;
172
+ requestFormBinary(method: string, path: string, form: FormData, withAuth?: boolean): Promise<ArrayBuffer>;
173
+ _request<T>(method: string, path: string, body?: unknown, withAuth?: boolean, extraHeaders?: Record<string, string>): Promise<T>;
174
+ _requestBinary(method: string, path: string, body?: unknown, withAuth?: boolean): Promise<ArrayBuffer>;
175
+ _requestForm<T>(method: string, path: string, form: FormData, withAuth?: boolean): Promise<T>;
176
+ _requestFormBinary(method: string, path: string, form: FormData, withAuth?: boolean): Promise<ArrayBuffer>;
177
+ };
178
+ } & {
179
+ new (...args: any[]): {
180
+ push(pushEntity: string, payload: Record<string, unknown>, opts?: {
181
+ transactionId?: string;
182
+ }): Promise<{
183
+ ok: boolean;
184
+ seq: number;
185
+ }>;
186
+ pushLogList<T = unknown>(params?: import("./types").EntityListParams): Promise<{
187
+ ok: boolean;
188
+ data: import("./types").EntityListResult<T>;
189
+ }>;
190
+ registerPushDevice(accountSeq: number, deviceId: string, pushToken: string, opts?: import("./types").RegisterPushDeviceOptions): Promise<{
191
+ ok: boolean;
192
+ seq: number;
193
+ }>;
194
+ updatePushDeviceToken(deviceSeq: number, pushToken: string, opts?: {
195
+ pushEnabled?: boolean;
196
+ transactionId?: string;
197
+ }): Promise<{
198
+ ok: boolean;
199
+ seq: number;
200
+ }>;
201
+ disablePushDevice(deviceSeq: number, opts?: {
202
+ transactionId?: string;
203
+ }): Promise<{
204
+ ok: boolean;
205
+ seq: number;
206
+ }>;
207
+ baseUrl: string;
208
+ token: string;
209
+ anonymousPacketToken: string;
210
+ apiKey: string;
211
+ hmacSecret: string;
212
+ encryptRequests: boolean;
213
+ activeTxId: string | null;
214
+ keepSession: boolean;
215
+ refreshBuffer: number;
216
+ onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
217
+ onSessionExpired?: (error: Error) => void;
218
+ _sessionRefreshToken: string | null;
219
+ _refreshTimer: ReturnType<typeof setTimeout> | null;
220
+ configure(options: Partial<import("./types").EntityServerClientOptions>): void;
221
+ setToken(token: string): void;
222
+ setAnonymousPacketToken(token: string): void;
223
+ setApiKey(apiKey: string): void;
224
+ setHmacSecret(secret: string): void;
225
+ setEncryptRequests(value: boolean): void;
226
+ _scheduleKeepSession(refreshToken: string, expiresIn: number, refreshFn: (rt: string) => Promise<{
227
+ access_token: string;
228
+ expires_in: number;
229
+ }>): void;
230
+ _clearRefreshTimer(): void;
231
+ stopKeepSession(): void;
232
+ readRequestBody<T = Record<string, unknown>>(body: ArrayBuffer | Uint8Array | string | T | null | undefined, contentType?: string, requireEncrypted?: boolean): T;
233
+ get _reqOpts(): import("./client/request").RequestOptions;
234
+ requestJson<T>(method: string, path: string, body?: unknown, withAuth?: boolean, extraHeaders?: Record<string, string>): Promise<T>;
235
+ requestBinary(method: string, path: string, body?: unknown, withAuth?: boolean): Promise<ArrayBuffer>;
236
+ requestForm<T>(method: string, path: string, form: FormData, withAuth?: boolean): Promise<T>;
237
+ requestFormBinary(method: string, path: string, form: FormData, withAuth?: boolean): Promise<ArrayBuffer>;
238
+ _request<T>(method: string, path: string, body?: unknown, withAuth?: boolean, extraHeaders?: Record<string, string>): Promise<T>;
239
+ _requestBinary(method: string, path: string, body?: unknown, withAuth?: boolean): Promise<ArrayBuffer>;
240
+ _requestForm<T>(method: string, path: string, form: FormData, withAuth?: boolean): Promise<T>;
241
+ _requestFormBinary(method: string, path: string, form: FormData, withAuth?: boolean): Promise<ArrayBuffer>;
242
+ submit(entity: string, data: Record<string, unknown>, opts?: {
243
+ transactionId?: string;
244
+ skipHooks?: boolean;
245
+ }): Promise<{
246
+ ok: boolean;
247
+ seq: number;
248
+ }>;
249
+ list<T = unknown>(entity: string, params?: import("./types").EntityListParams): Promise<{
250
+ ok: boolean;
251
+ data: import("./types").EntityListResult<T>;
252
+ }>;
253
+ };
254
+ } & {
255
+ new (...args: any[]): {
256
+ transStart(): Promise<string>;
257
+ transRollback(transactionId?: string): Promise<{
258
+ ok: boolean;
259
+ }>;
260
+ transCommit(transactionId?: string): Promise<{
261
+ ok: boolean;
262
+ results: {
263
+ entity: string;
264
+ action: string;
265
+ seq: number;
266
+ }[];
267
+ }>;
268
+ get<T = unknown>(entity: string, seq: number, opts?: {
269
+ skipHooks?: boolean;
270
+ }): Promise<{
271
+ ok: boolean;
272
+ data: T;
273
+ }>;
274
+ find<T = unknown>(entity: string, conditions?: Record<string, unknown>, opts?: {
275
+ skipHooks?: boolean;
276
+ }): Promise<{
277
+ ok: boolean;
278
+ data: T;
279
+ }>;
280
+ list<T = unknown>(entity: string, params?: import("./types").EntityListParams): Promise<{
281
+ ok: boolean;
282
+ data: import("./types").EntityListResult<T>;
283
+ }>;
284
+ count(entity: string, conditions?: Record<string, unknown>): Promise<{
285
+ ok: boolean;
286
+ count: number;
287
+ }>;
288
+ query<T = unknown>(entity: string, req: import("./types").EntityQueryRequest): Promise<{
289
+ ok: boolean;
290
+ data: {
291
+ items: T[];
292
+ count: number;
293
+ };
294
+ }>;
295
+ submit(entity: string, data: Record<string, unknown>, opts?: {
296
+ transactionId?: string;
297
+ skipHooks?: boolean;
298
+ }): Promise<{
299
+ ok: boolean;
300
+ seq: number;
301
+ }>;
302
+ delete(entity: string, seq: number, opts?: {
303
+ transactionId?: string;
304
+ hard?: boolean;
305
+ skipHooks?: boolean;
306
+ }): Promise<{
307
+ ok: boolean;
308
+ deleted: number;
309
+ }>;
310
+ history<T = unknown>(entity: string, seq: number, params?: Pick<import("./types").EntityListParams, "page" | "limit">): Promise<{
311
+ ok: boolean;
312
+ data: import("./types").EntityListResult<import("./types").EntityHistoryRecord<T>>;
313
+ }>;
314
+ rollback(entity: string, historySeq: number): Promise<{
315
+ ok: boolean;
316
+ }>;
317
+ baseUrl: string;
318
+ token: string;
319
+ anonymousPacketToken: string;
320
+ apiKey: string;
321
+ hmacSecret: string;
322
+ encryptRequests: boolean;
323
+ activeTxId: string | null;
324
+ keepSession: boolean;
325
+ refreshBuffer: number;
326
+ onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
327
+ onSessionExpired?: (error: Error) => void;
328
+ _sessionRefreshToken: string | null;
329
+ _refreshTimer: ReturnType<typeof setTimeout> | null;
330
+ configure(options: Partial<import("./types").EntityServerClientOptions>): void;
331
+ setToken(token: string): void;
332
+ setAnonymousPacketToken(token: string): void;
333
+ setApiKey(apiKey: string): void;
334
+ setHmacSecret(secret: string): void;
335
+ setEncryptRequests(value: boolean): void;
336
+ _scheduleKeepSession(refreshToken: string, expiresIn: number, refreshFn: (rt: string) => Promise<{
337
+ access_token: string;
338
+ expires_in: number;
339
+ }>): void;
340
+ _clearRefreshTimer(): void;
341
+ stopKeepSession(): void;
342
+ readRequestBody<T = Record<string, unknown>>(body: ArrayBuffer | Uint8Array | string | T | null | undefined, contentType?: string, requireEncrypted?: boolean): T;
343
+ get _reqOpts(): import("./client/request").RequestOptions;
344
+ requestJson<T>(method: string, path: string, body?: unknown, withAuth?: boolean, extraHeaders?: Record<string, string>): Promise<T>;
345
+ requestBinary(method: string, path: string, body?: unknown, withAuth?: boolean): Promise<ArrayBuffer>;
346
+ requestForm<T>(method: string, path: string, form: FormData, withAuth?: boolean): Promise<T>;
347
+ requestFormBinary(method: string, path: string, form: FormData, withAuth?: boolean): Promise<ArrayBuffer>;
348
+ _request<T>(method: string, path: string, body?: unknown, withAuth?: boolean, extraHeaders?: Record<string, string>): Promise<T>;
349
+ _requestBinary(method: string, path: string, body?: unknown, withAuth?: boolean): Promise<ArrayBuffer>;
350
+ _requestForm<T>(method: string, path: string, form: FormData, withAuth?: boolean): Promise<T>;
351
+ _requestFormBinary(method: string, path: string, form: FormData, withAuth?: boolean): Promise<ArrayBuffer>;
352
+ };
353
+ } & {
354
+ new (...args: any[]): {
355
+ checkHealth(): Promise<{
356
+ ok: boolean;
357
+ packet_encryption?: boolean;
358
+ packet_mode?: string;
359
+ packet_token?: string;
360
+ }>;
361
+ login(email: string, password: string): Promise<{
362
+ access_token: string;
363
+ refresh_token: string;
364
+ expires_in: number;
365
+ force_password_change?: boolean;
366
+ password_expired?: boolean;
367
+ password_expires_in_days?: number;
368
+ }>;
369
+ refreshToken(refreshToken: string): Promise<{
370
+ access_token: string;
371
+ expires_in: number;
372
+ }>;
373
+ logout(refreshToken: string): Promise<{
374
+ ok: boolean;
375
+ }>;
376
+ me<T = Record<string, unknown>>(): Promise<{
377
+ ok: boolean;
378
+ data: T;
379
+ }>;
380
+ withdraw(passwd?: string): Promise<{
381
+ ok: boolean;
382
+ }>;
383
+ reactivate(params: {
384
+ email: string;
385
+ passwd?: string;
386
+ provider?: string;
387
+ code?: string;
388
+ }): Promise<{
389
+ access_token: string;
390
+ refresh_token: string;
391
+ expires_in: number;
392
+ }>;
393
+ baseUrl: string;
394
+ token: string;
395
+ anonymousPacketToken: string;
396
+ apiKey: string;
397
+ hmacSecret: string;
398
+ encryptRequests: boolean;
399
+ activeTxId: string | null;
400
+ keepSession: boolean;
401
+ refreshBuffer: number;
402
+ onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
403
+ onSessionExpired?: (error: Error) => void;
404
+ _sessionRefreshToken: string | null;
405
+ _refreshTimer: ReturnType<typeof setTimeout> | null;
406
+ configure(options: Partial<import("./types").EntityServerClientOptions>): void;
407
+ setToken(token: string): void;
408
+ setAnonymousPacketToken(token: string): void;
409
+ setApiKey(apiKey: string): void;
410
+ setHmacSecret(secret: string): void;
411
+ setEncryptRequests(value: boolean): void;
412
+ _scheduleKeepSession(refreshToken: string, expiresIn: number, refreshFn: (rt: string) => Promise<{
413
+ access_token: string;
414
+ expires_in: number;
415
+ }>): void;
416
+ _clearRefreshTimer(): void;
417
+ stopKeepSession(): void;
418
+ readRequestBody<T = Record<string, unknown>>(body: ArrayBuffer | Uint8Array | string | T | null | undefined, contentType?: string, requireEncrypted?: boolean): T;
419
+ get _reqOpts(): import("./client/request").RequestOptions;
420
+ requestJson<T>(method: string, path: string, body?: unknown, withAuth?: boolean, extraHeaders?: Record<string, string>): Promise<T>;
421
+ requestBinary(method: string, path: string, body?: unknown, withAuth?: boolean): Promise<ArrayBuffer>;
422
+ requestForm<T>(method: string, path: string, form: FormData, withAuth?: boolean): Promise<T>;
423
+ requestFormBinary(method: string, path: string, form: FormData, withAuth?: boolean): Promise<ArrayBuffer>;
424
+ _request<T>(method: string, path: string, body?: unknown, withAuth?: boolean, extraHeaders?: Record<string, string>): Promise<T>;
425
+ _requestBinary(method: string, path: string, body?: unknown, withAuth?: boolean): Promise<ArrayBuffer>;
426
+ _requestForm<T>(method: string, path: string, form: FormData, withAuth?: boolean): Promise<T>;
427
+ _requestFormBinary(method: string, path: string, form: FormData, withAuth?: boolean): Promise<ArrayBuffer>;
428
+ };
429
+ } & typeof EntityServerClientBase;
430
+ export declare class EntityServerClient extends EntityServerClient_base {
431
+ }
432
+ export {};
@@ -0,0 +1,84 @@
1
+ import type { EntityServerClientOptions } from "../types";
2
+ import { type RequestOptions } from "./request";
3
+ export type GConstructor<T = object> = new (...args: any[]) => T;
4
+ export declare class EntityServerClientBase {
5
+ baseUrl: string;
6
+ token: string;
7
+ anonymousPacketToken: string;
8
+ apiKey: string;
9
+ hmacSecret: string;
10
+ encryptRequests: boolean;
11
+ activeTxId: string | null;
12
+ keepSession: boolean;
13
+ refreshBuffer: number;
14
+ onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
15
+ onSessionExpired?: (error: Error) => void;
16
+ _sessionRefreshToken: string | null;
17
+ _refreshTimer: ReturnType<typeof setTimeout> | null;
18
+ /**
19
+ * EntityServerClient 인스턴스를 생성합니다.
20
+ *
21
+ * 기본값:
22
+ * - `baseUrl`: `VITE_ENTITY_SERVER_URL` 또는 상대 경로(`""`)
23
+ */
24
+ constructor(options?: EntityServerClientOptions);
25
+ /** baseUrl, token, encryptRequests 값을 런타임에 갱신합니다. */
26
+ configure(options: Partial<EntityServerClientOptions>): void;
27
+ /** 인증 요청에 사용할 JWT Access Token을 설정합니다. */
28
+ setToken(token: string): void;
29
+ /** 익명 패킷 암호화용 토큰을 설정합니다. */
30
+ setAnonymousPacketToken(token: string): void;
31
+ /** HMAC 인증용 API Key를 설정합니다. */
32
+ setApiKey(apiKey: string): void;
33
+ /** HMAC 인증용 시크릿을 설정합니다. */
34
+ setHmacSecret(secret: string): void;
35
+ /** 암호화 요청 활성화 여부를 설정합니다. */
36
+ setEncryptRequests(value: boolean): void;
37
+ /** @internal 자동 토큰 갱신 타이머를 시작합니다. */
38
+ _scheduleKeepSession(refreshToken: string, expiresIn: number, refreshFn: (rt: string) => Promise<{
39
+ access_token: string;
40
+ expires_in: number;
41
+ }>): void;
42
+ /** @internal 자동 갱신 타이머를 정리합니다. */
43
+ _clearRefreshTimer(): void;
44
+ /**
45
+ * 세션 유지 타이머를 중지합니다.
46
+ * `logout()` 호출 시 자동으로 중지되며, 직접 호출이 필요한 경우는 드뭅니다.
47
+ */
48
+ stopKeepSession(): void;
49
+ /**
50
+ * 요청 바디를 파싱합니다.
51
+ * `application/octet-stream`이면 XChaCha20-Poly1305 복호화, 그 외는 JSON 파싱합니다.
52
+ *
53
+ * @param requireEncrypted `true`이면 암호화된 요청만 허용합니다.
54
+ */
55
+ readRequestBody<T = Record<string, unknown>>(body: ArrayBuffer | Uint8Array | string | T | null | undefined, contentType?: string, requireEncrypted?: boolean): T;
56
+ get _reqOpts(): RequestOptions;
57
+ /**
58
+ * 임의 경로에 JSON 요청을 보냅니다. 응답이 JSON이면 파싱, octet-stream이면 자동 복호화합니다.
59
+ * `ok` 필드를 강제하지 않아 go서버/앱서버 신규 라우트 등 자유 응답 포맷에 사용합니다.
60
+ * `encryptRequests: true`이면 요청 바디도 자동 암호화됩니다.
61
+ */
62
+ requestJson<T>(method: string, path: string, body?: unknown, withAuth?: boolean, extraHeaders?: Record<string, string>): Promise<T>;
63
+ /**
64
+ * 임의 경로에 요청을 보내고 바이너리(ArrayBuffer)를 반환합니다.
65
+ * 이미지, PDF, 압축 파일 등 바이너리 응답이 오는 엔드포인트에 사용합니다.
66
+ */
67
+ requestBinary(method: string, path: string, body?: unknown, withAuth?: boolean): Promise<ArrayBuffer>;
68
+ /**
69
+ * multipart/form-data 요청을 보냅니다. 파일 업로드 등에 사용합니다.
70
+ * 응답은 JSON으로 파싱하여 반환합니다.
71
+ */
72
+ requestForm<T>(method: string, path: string, form: FormData, withAuth?: boolean): Promise<T>;
73
+ /**
74
+ * multipart/form-data 요청을 보내고 바이너리(ArrayBuffer)를 반환합니다.
75
+ */
76
+ requestFormBinary(method: string, path: string, form: FormData, withAuth?: boolean): Promise<ArrayBuffer>;
77
+ _request<T>(method: string, path: string, body?: unknown, withAuth?: boolean, extraHeaders?: Record<string, string>): Promise<T>;
78
+ /** PNG/바이너리 응답을 ArrayBuffer로 반환합니다. (QR, 바코드 등) */
79
+ _requestBinary(method: string, path: string, body?: unknown, withAuth?: boolean): Promise<ArrayBuffer>;
80
+ /** multipart/form-data 요청을 보냅니다. (파일 업로드 등) */
81
+ _requestForm<T>(method: string, path: string, form: FormData, withAuth?: boolean): Promise<T>;
82
+ /** multipart/form-data 요청을 보내고 바이너리(ArrayBuffer)를 반환합니다. */
83
+ _requestFormBinary(method: string, path: string, form: FormData, withAuth?: boolean): Promise<ArrayBuffer>;
84
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * HMAC-SHA256 서명 헤더를 생성합니다.
3
+ *
4
+ * 서명 대상: `METHOD|PATH|TIMESTAMP|NONCE|BODY`
5
+ *
6
+ * @returns `X-API-Key`, `X-Timestamp`, `X-Nonce`, `X-Signature` 헤더 객체
7
+ */
8
+ export declare function buildHmacHeaders(method: string, path: string, bodyBytes: Uint8Array, apiKey: string, hmacSecret: string): Record<string, string>;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * 패킷 암호화 키를 유도합니다.
3
+ * - HMAC 모드 (`hmacSecret` 유효 시): HKDF-SHA256(hmac_secret, "entity-server:packet-encryption")
4
+ * - JWT 모드: HKDF-SHA256(jwt_token, "entity-server:packet-encryption")
5
+ */
6
+ export declare function derivePacketKey(hmacSecret: string, token: string): Uint8Array;
7
+ /**
8
+ * 평문 바이트를 XChaCha20-Poly1305로 암호화합니다.
9
+ * 포맷: [random_magic:K][random_nonce:24][ciphertext+tag]
10
+ * K = 2 + key[31] % 14 (패킷 키에서 자동 파생)
11
+ */
12
+ export declare function encryptPacket(plaintext: Uint8Array, key: Uint8Array): Uint8Array;
13
+ /**
14
+ * XChaCha20-Poly1305 패킷을 복호화해 JSON 객체로 변환합니다.
15
+ * 포맷: [magic:K][nonce:24][ciphertext+tag]
16
+ * K = 2 + key[31] % 14 (패킷 키에서 자동 파생)
17
+ */
18
+ export declare function decryptPacket<T>(buffer: ArrayBuffer, key: Uint8Array): T;
19
+ /**
20
+ * 요청 바디를 파싱합니다. `application/octet-stream`이면 복호화, 그 외는 JSON 파싱합니다.
21
+ *
22
+ * @param requireEncrypted `true`이면 암호화된 요청만 허용합니다.
23
+ */
24
+ export declare function parseRequestBody<T>(body: ArrayBuffer | Uint8Array | string | T | null | undefined, contentType: string, requireEncrypted: boolean, key: Uint8Array): T;
@@ -0,0 +1,16 @@
1
+ export interface RequestOptions {
2
+ baseUrl: string;
3
+ token: string;
4
+ anonymousPacketToken: string;
5
+ apiKey: string;
6
+ hmacSecret: string;
7
+ encryptRequests: boolean;
8
+ }
9
+ /**
10
+ * Entity Server에 HTTP 요청을 보냅니다.
11
+ *
12
+ * - `encryptRequests` 활성화 시 인증된 POST 바디를 자동 암호화합니다.
13
+ * - 응답이 `application/octet-stream`이면 자동 복호화합니다.
14
+ * - JSON 응답의 `ok`가 false이면 에러를 던집니다.
15
+ */
16
+ export declare function entityRequest<T>(opts: RequestOptions, method: string, path: string, body?: unknown, withAuth?: boolean, extraHeaders?: Record<string, string>, requireOkShape?: boolean): Promise<T>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 환경변수를 읽습니다.
3
+ * - 브라우저/Vite: `import.meta.env`
4
+ * - Node.js: `process.env`
5
+ */
6
+ export declare function readEnv(name: string): string | undefined;
7
+ /** 쿼리 파라미터 객체를 URL 쿼리 문자열로 변환합니다. `orderBy` 키는 `order_by`로 변환됩니다. */
8
+ export declare function buildQuery(params: Record<string, unknown>): string;
@@ -0,0 +1,63 @@
1
+ import { EntityServerClient, type EntityQueryRequest, type EntityServerClientOptions } from "../index";
2
+ export interface UseEntityServerOptions extends EntityServerClientOptions {
3
+ singleton?: boolean;
4
+ tokenResolver?: () => string | undefined | null;
5
+ /**
6
+ * 페이지 새로고침 후 로그인 상태를 복원할 때 사용합니다.
7
+ * 이 값이 있으면 마운트 시 `client.refreshToken()`을 호출해 새 access_token을 발급받습니다.
8
+ * `keepSession: true`와 함께 사용하면 세션 유지 타이머도 재시작됩니다.
9
+ * 갱신 성공 시 `onTokenRefreshed` 콜백이 호출됩니다.
10
+ */
11
+ resumeSession?: string;
12
+ }
13
+ export interface UseEntityServerResult {
14
+ /** EntityServerClient 인스턴스 (read 전용 메서드 직접 호출 시 사용) */
15
+ client: EntityServerClient;
16
+ /** submit 또는 delete 진행 중 여부 */
17
+ isPending: boolean;
18
+ /** 마지막 mutation 에러 (없으면 null) */
19
+ error: Error | null;
20
+ /** 에러·결과 상태 초기화 */
21
+ reset: () => void;
22
+ /** entity 데이터 생성/수정 (seq 없으면 INSERT, 있으면 UPDATE) */
23
+ submit: (entity: string, data: Record<string, unknown>, opts?: {
24
+ transactionId?: string;
25
+ skipHooks?: boolean;
26
+ }) => Promise<{
27
+ ok: boolean;
28
+ seq: number;
29
+ }>;
30
+ /** entity 데이터 삭제 */
31
+ del: (entity: string, seq: number, opts?: {
32
+ transactionId?: string;
33
+ hard?: boolean;
34
+ skipHooks?: boolean;
35
+ }) => Promise<{
36
+ ok: boolean;
37
+ deleted: number;
38
+ }>;
39
+ /** 커스텀 SQL 조회 */
40
+ query: <T = unknown>(entity: string, req: EntityQueryRequest) => Promise<{
41
+ ok: boolean;
42
+ data: {
43
+ items: T[];
44
+ count: number;
45
+ };
46
+ }>;
47
+ }
48
+ /**
49
+ * React 환경에서 EntityServerClient 인스턴스와 mutation 상태를 반환합니다.
50
+ *
51
+ * - `singleton=true`(기본): 패키지 전역 `entityServer` 인스턴스를 사용합니다.
52
+ * - `singleton=false`: 컴포넌트 스코프의 새 인스턴스를 생성합니다.
53
+ *
54
+ * @example
55
+ * ```tsx
56
+ * const { submit, del, isPending, error, reset } = useEntityServer();
57
+ *
58
+ * const handleSave = async () => {
59
+ * await submit("account", { name: "홍길동" });
60
+ * };
61
+ * ```
62
+ */
63
+ export declare function useEntityServer(options?: UseEntityServerOptions): UseEntityServerResult;
@@ -1,6 +1,4 @@
1
1
  export * from "./types";
2
2
  export * from "./EntityServerClient";
3
-
4
3
  import { EntityServerClient } from "./EntityServerClient";
5
-
6
- export const entityServer = new EntityServerClient();
4
+ export declare const entityServer: EntityServerClient;