entity-client 1.0.23 → 1.0.25
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/EntityAppServerApi.d.ts +49 -0
- package/dist/EntityServerApi.d.ts +24 -0
- package/dist/client/base.d.ts +13 -0
- package/dist/client/base.js +1 -1
- package/dist/client/base.js.map +3 -3
- package/dist/client/request.d.ts +5 -0
- package/dist/client/request.js +1 -1
- package/dist/client/request.js.map +3 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +3 -3
- package/dist/mixins/app/plugins/alimtalk.d.ts +3 -0
- package/dist/mixins/app/plugins/friendtalk.d.ts +3 -0
- package/dist/mixins/app/plugins/holidays.d.ts +3 -0
- package/dist/mixins/app/plugins/identity.d.ts +3 -0
- package/dist/mixins/app/plugins/llm.d.ts +3 -0
- package/dist/mixins/app/plugins/ocr.d.ts +3 -0
- package/dist/mixins/app/plugins/pg.d.ts +3 -0
- package/dist/mixins/app/plugins/push.d.ts +3 -0
- package/dist/mixins/app/plugins/sms.d.ts +3 -0
- package/dist/mixins/app/plugins/taxinvoice.d.ts +3 -0
- package/dist/mixins/app/routes/account.d.ts +3 -0
- package/dist/mixins/app/routes/board.d.ts +4 -0
- package/dist/mixins/app/routes/board.js +1 -1
- package/dist/mixins/app/routes/board.js.map +2 -2
- package/dist/mixins/app/routes/email-verify.d.ts +3 -0
- package/dist/mixins/app/routes/oauth.d.ts +3 -0
- package/dist/mixins/app/routes/password-reset.d.ts +3 -0
- package/dist/mixins/app/routes/two-factor.d.ts +3 -0
- package/dist/mixins/server/admin.d.ts +3 -0
- package/dist/mixins/server/auth.d.ts +3 -0
- package/dist/mixins/server/auth.js +1 -1
- package/dist/mixins/server/auth.js.map +3 -3
- package/dist/mixins/server/entity.d.ts +3 -0
- package/dist/mixins/server/file.d.ts +3 -0
- package/dist/mixins/server/push.d.ts +3 -0
- package/dist/mixins/server/smtp.d.ts +3 -0
- package/dist/mixins/server/transaction.d.ts +3 -0
- package/dist/mixins/server/utils.d.ts +3 -0
- package/dist/react.js +1 -1
- package/dist/react.js.map +3 -3
- package/package.json +1 -1
|
@@ -17,6 +17,7 @@ declare const EntityAppServerApi_base: {
|
|
|
17
17
|
csrfRefresher: (() => Promise<void>) | null;
|
|
18
18
|
requestAbortControllers: Map<string, AbortController>;
|
|
19
19
|
activeTxId: string | null;
|
|
20
|
+
initialHealthFired: boolean;
|
|
20
21
|
keepSession: boolean;
|
|
21
22
|
refreshBuffer: number;
|
|
22
23
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -39,8 +40,10 @@ declare const EntityAppServerApi_base: {
|
|
|
39
40
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
40
41
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
41
42
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
43
|
+
fireInitialHealth(): void;
|
|
42
44
|
setToken(token: string): void;
|
|
43
45
|
setAccessTokenFromResponse(token: string): void;
|
|
46
|
+
syncRealtimeWithToken(): void;
|
|
44
47
|
setAnonymousPacketToken(token: string): void;
|
|
45
48
|
setApiKey(apiKey: string): void;
|
|
46
49
|
setHmacSecret(secret: string): void;
|
|
@@ -102,6 +105,7 @@ declare const EntityAppServerApi_base: {
|
|
|
102
105
|
csrfRefresher: (() => Promise<void>) | null;
|
|
103
106
|
requestAbortControllers: Map<string, AbortController>;
|
|
104
107
|
activeTxId: string | null;
|
|
108
|
+
initialHealthFired: boolean;
|
|
105
109
|
keepSession: boolean;
|
|
106
110
|
refreshBuffer: number;
|
|
107
111
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -124,8 +128,10 @@ declare const EntityAppServerApi_base: {
|
|
|
124
128
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
125
129
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
126
130
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
131
|
+
fireInitialHealth(): void;
|
|
127
132
|
setToken(token: string): void;
|
|
128
133
|
setAccessTokenFromResponse(token: string): void;
|
|
134
|
+
syncRealtimeWithToken(): void;
|
|
129
135
|
setAnonymousPacketToken(token: string): void;
|
|
130
136
|
setApiKey(apiKey: string): void;
|
|
131
137
|
setHmacSecret(secret: string): void;
|
|
@@ -190,6 +196,7 @@ declare const EntityAppServerApi_base: {
|
|
|
190
196
|
csrfRefresher: (() => Promise<void>) | null;
|
|
191
197
|
requestAbortControllers: Map<string, AbortController>;
|
|
192
198
|
activeTxId: string | null;
|
|
199
|
+
initialHealthFired: boolean;
|
|
193
200
|
keepSession: boolean;
|
|
194
201
|
refreshBuffer: number;
|
|
195
202
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -212,8 +219,10 @@ declare const EntityAppServerApi_base: {
|
|
|
212
219
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
213
220
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
214
221
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
222
|
+
fireInitialHealth(): void;
|
|
215
223
|
setToken(token: string): void;
|
|
216
224
|
setAccessTokenFromResponse(token: string): void;
|
|
225
|
+
syncRealtimeWithToken(): void;
|
|
217
226
|
setAnonymousPacketToken(token: string): void;
|
|
218
227
|
setApiKey(apiKey: string): void;
|
|
219
228
|
setHmacSecret(secret: string): void;
|
|
@@ -279,6 +288,7 @@ declare const EntityAppServerApi_base: {
|
|
|
279
288
|
csrfRefresher: (() => Promise<void>) | null;
|
|
280
289
|
requestAbortControllers: Map<string, AbortController>;
|
|
281
290
|
activeTxId: string | null;
|
|
291
|
+
initialHealthFired: boolean;
|
|
282
292
|
keepSession: boolean;
|
|
283
293
|
refreshBuffer: number;
|
|
284
294
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -301,8 +311,10 @@ declare const EntityAppServerApi_base: {
|
|
|
301
311
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
302
312
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
303
313
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
314
|
+
fireInitialHealth(): void;
|
|
304
315
|
setToken(token: string): void;
|
|
305
316
|
setAccessTokenFromResponse(token: string): void;
|
|
317
|
+
syncRealtimeWithToken(): void;
|
|
306
318
|
setAnonymousPacketToken(token: string): void;
|
|
307
319
|
setApiKey(apiKey: string): void;
|
|
308
320
|
setHmacSecret(secret: string): void;
|
|
@@ -370,6 +382,7 @@ declare const EntityAppServerApi_base: {
|
|
|
370
382
|
csrfRefresher: (() => Promise<void>) | null;
|
|
371
383
|
requestAbortControllers: Map<string, AbortController>;
|
|
372
384
|
activeTxId: string | null;
|
|
385
|
+
initialHealthFired: boolean;
|
|
373
386
|
keepSession: boolean;
|
|
374
387
|
refreshBuffer: number;
|
|
375
388
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -392,8 +405,10 @@ declare const EntityAppServerApi_base: {
|
|
|
392
405
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
393
406
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
394
407
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
408
|
+
fireInitialHealth(): void;
|
|
395
409
|
setToken(token: string): void;
|
|
396
410
|
setAccessTokenFromResponse(token: string): void;
|
|
411
|
+
syncRealtimeWithToken(): void;
|
|
397
412
|
setAnonymousPacketToken(token: string): void;
|
|
398
413
|
setApiKey(apiKey: string): void;
|
|
399
414
|
setHmacSecret(secret: string): void;
|
|
@@ -460,6 +475,7 @@ declare const EntityAppServerApi_base: {
|
|
|
460
475
|
csrfRefresher: (() => Promise<void>) | null;
|
|
461
476
|
requestAbortControllers: Map<string, AbortController>;
|
|
462
477
|
activeTxId: string | null;
|
|
478
|
+
initialHealthFired: boolean;
|
|
463
479
|
keepSession: boolean;
|
|
464
480
|
refreshBuffer: number;
|
|
465
481
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -482,8 +498,10 @@ declare const EntityAppServerApi_base: {
|
|
|
482
498
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
483
499
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
484
500
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
501
|
+
fireInitialHealth(): void;
|
|
485
502
|
setToken(token: string): void;
|
|
486
503
|
setAccessTokenFromResponse(token: string): void;
|
|
504
|
+
syncRealtimeWithToken(): void;
|
|
487
505
|
setAnonymousPacketToken(token: string): void;
|
|
488
506
|
setApiKey(apiKey: string): void;
|
|
489
507
|
setHmacSecret(secret: string): void;
|
|
@@ -552,6 +570,7 @@ declare const EntityAppServerApi_base: {
|
|
|
552
570
|
csrfRefresher: (() => Promise<void>) | null;
|
|
553
571
|
requestAbortControllers: Map<string, AbortController>;
|
|
554
572
|
activeTxId: string | null;
|
|
573
|
+
initialHealthFired: boolean;
|
|
555
574
|
keepSession: boolean;
|
|
556
575
|
refreshBuffer: number;
|
|
557
576
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -574,8 +593,10 @@ declare const EntityAppServerApi_base: {
|
|
|
574
593
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
575
594
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
576
595
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
596
|
+
fireInitialHealth(): void;
|
|
577
597
|
setToken(token: string): void;
|
|
578
598
|
setAccessTokenFromResponse(token: string): void;
|
|
599
|
+
syncRealtimeWithToken(): void;
|
|
579
600
|
setAnonymousPacketToken(token: string): void;
|
|
580
601
|
setApiKey(apiKey: string): void;
|
|
581
602
|
setHmacSecret(secret: string): void;
|
|
@@ -671,6 +692,7 @@ declare const EntityAppServerApi_base: {
|
|
|
671
692
|
csrfRefresher: (() => Promise<void>) | null;
|
|
672
693
|
requestAbortControllers: Map<string, AbortController>;
|
|
673
694
|
activeTxId: string | null;
|
|
695
|
+
initialHealthFired: boolean;
|
|
674
696
|
keepSession: boolean;
|
|
675
697
|
refreshBuffer: number;
|
|
676
698
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -693,8 +715,10 @@ declare const EntityAppServerApi_base: {
|
|
|
693
715
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
694
716
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
695
717
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
718
|
+
fireInitialHealth(): void;
|
|
696
719
|
setToken(token: string): void;
|
|
697
720
|
setAccessTokenFromResponse(token: string): void;
|
|
721
|
+
syncRealtimeWithToken(): void;
|
|
698
722
|
setAnonymousPacketToken(token: string): void;
|
|
699
723
|
setApiKey(apiKey: string): void;
|
|
700
724
|
setHmacSecret(secret: string): void;
|
|
@@ -759,6 +783,7 @@ declare const EntityAppServerApi_base: {
|
|
|
759
783
|
csrfRefresher: (() => Promise<void>) | null;
|
|
760
784
|
requestAbortControllers: Map<string, AbortController>;
|
|
761
785
|
activeTxId: string | null;
|
|
786
|
+
initialHealthFired: boolean;
|
|
762
787
|
keepSession: boolean;
|
|
763
788
|
refreshBuffer: number;
|
|
764
789
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -781,8 +806,10 @@ declare const EntityAppServerApi_base: {
|
|
|
781
806
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
782
807
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
783
808
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
809
|
+
fireInitialHealth(): void;
|
|
784
810
|
setToken(token: string): void;
|
|
785
811
|
setAccessTokenFromResponse(token: string): void;
|
|
812
|
+
syncRealtimeWithToken(): void;
|
|
786
813
|
setAnonymousPacketToken(token: string): void;
|
|
787
814
|
setApiKey(apiKey: string): void;
|
|
788
815
|
setHmacSecret(secret: string): void;
|
|
@@ -850,6 +877,7 @@ declare const EntityAppServerApi_base: {
|
|
|
850
877
|
csrfRefresher: (() => Promise<void>) | null;
|
|
851
878
|
requestAbortControllers: Map<string, AbortController>;
|
|
852
879
|
activeTxId: string | null;
|
|
880
|
+
initialHealthFired: boolean;
|
|
853
881
|
keepSession: boolean;
|
|
854
882
|
refreshBuffer: number;
|
|
855
883
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -872,8 +900,10 @@ declare const EntityAppServerApi_base: {
|
|
|
872
900
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
873
901
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
874
902
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
903
|
+
fireInitialHealth(): void;
|
|
875
904
|
setToken(token: string): void;
|
|
876
905
|
setAccessTokenFromResponse(token: string): void;
|
|
906
|
+
syncRealtimeWithToken(): void;
|
|
877
907
|
setAnonymousPacketToken(token: string): void;
|
|
878
908
|
setApiKey(apiKey: string): void;
|
|
879
909
|
setHmacSecret(secret: string): void;
|
|
@@ -940,6 +970,7 @@ declare const EntityAppServerApi_base: {
|
|
|
940
970
|
csrfRefresher: (() => Promise<void>) | null;
|
|
941
971
|
requestAbortControllers: Map<string, AbortController>;
|
|
942
972
|
activeTxId: string | null;
|
|
973
|
+
initialHealthFired: boolean;
|
|
943
974
|
keepSession: boolean;
|
|
944
975
|
refreshBuffer: number;
|
|
945
976
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -962,8 +993,10 @@ declare const EntityAppServerApi_base: {
|
|
|
962
993
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
963
994
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
964
995
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
996
|
+
fireInitialHealth(): void;
|
|
965
997
|
setToken(token: string): void;
|
|
966
998
|
setAccessTokenFromResponse(token: string): void;
|
|
999
|
+
syncRealtimeWithToken(): void;
|
|
967
1000
|
setAnonymousPacketToken(token: string): void;
|
|
968
1001
|
setApiKey(apiKey: string): void;
|
|
969
1002
|
setHmacSecret(secret: string): void;
|
|
@@ -1031,6 +1064,7 @@ declare const EntityAppServerApi_base: {
|
|
|
1031
1064
|
csrfRefresher: (() => Promise<void>) | null;
|
|
1032
1065
|
requestAbortControllers: Map<string, AbortController>;
|
|
1033
1066
|
activeTxId: string | null;
|
|
1067
|
+
initialHealthFired: boolean;
|
|
1034
1068
|
keepSession: boolean;
|
|
1035
1069
|
refreshBuffer: number;
|
|
1036
1070
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -1053,8 +1087,10 @@ declare const EntityAppServerApi_base: {
|
|
|
1053
1087
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
1054
1088
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
1055
1089
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
1090
|
+
fireInitialHealth(): void;
|
|
1056
1091
|
setToken(token: string): void;
|
|
1057
1092
|
setAccessTokenFromResponse(token: string): void;
|
|
1093
|
+
syncRealtimeWithToken(): void;
|
|
1058
1094
|
setAnonymousPacketToken(token: string): void;
|
|
1059
1095
|
setApiKey(apiKey: string): void;
|
|
1060
1096
|
setHmacSecret(secret: string): void;
|
|
@@ -1120,6 +1156,7 @@ declare const EntityAppServerApi_base: {
|
|
|
1120
1156
|
csrfRefresher: (() => Promise<void>) | null;
|
|
1121
1157
|
requestAbortControllers: Map<string, AbortController>;
|
|
1122
1158
|
activeTxId: string | null;
|
|
1159
|
+
initialHealthFired: boolean;
|
|
1123
1160
|
keepSession: boolean;
|
|
1124
1161
|
refreshBuffer: number;
|
|
1125
1162
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -1142,8 +1179,10 @@ declare const EntityAppServerApi_base: {
|
|
|
1142
1179
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
1143
1180
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
1144
1181
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
1182
|
+
fireInitialHealth(): void;
|
|
1145
1183
|
setToken(token: string): void;
|
|
1146
1184
|
setAccessTokenFromResponse(token: string): void;
|
|
1185
|
+
syncRealtimeWithToken(): void;
|
|
1147
1186
|
setAnonymousPacketToken(token: string): void;
|
|
1148
1187
|
setApiKey(apiKey: string): void;
|
|
1149
1188
|
setHmacSecret(secret: string): void;
|
|
@@ -1209,6 +1248,7 @@ declare const EntityAppServerApi_base: {
|
|
|
1209
1248
|
csrfRefresher: (() => Promise<void>) | null;
|
|
1210
1249
|
requestAbortControllers: Map<string, AbortController>;
|
|
1211
1250
|
activeTxId: string | null;
|
|
1251
|
+
initialHealthFired: boolean;
|
|
1212
1252
|
keepSession: boolean;
|
|
1213
1253
|
refreshBuffer: number;
|
|
1214
1254
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -1231,8 +1271,10 @@ declare const EntityAppServerApi_base: {
|
|
|
1231
1271
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
1232
1272
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
1233
1273
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
1274
|
+
fireInitialHealth(): void;
|
|
1234
1275
|
setToken(token: string): void;
|
|
1235
1276
|
setAccessTokenFromResponse(token: string): void;
|
|
1277
|
+
syncRealtimeWithToken(): void;
|
|
1236
1278
|
setAnonymousPacketToken(token: string): void;
|
|
1237
1279
|
setApiKey(apiKey: string): void;
|
|
1238
1280
|
setHmacSecret(secret: string): void;
|
|
@@ -1290,6 +1332,7 @@ declare const EntityAppServerApi_base: {
|
|
|
1290
1332
|
getBoardPost<T = unknown>(seq: number): Promise<T>;
|
|
1291
1333
|
createBoardPost<T = unknown>(category: string, body: Record<string, unknown>): Promise<T>;
|
|
1292
1334
|
updateBoardPost<T = unknown>(seq: number, body: Record<string, unknown>): Promise<T>;
|
|
1335
|
+
expireBoardPost<T = unknown>(seq: number): Promise<T>;
|
|
1293
1336
|
deleteBoardPost<T = unknown>(seq: number): Promise<T>;
|
|
1294
1337
|
listBoardComments<T = unknown>(postSeq: number, query?: Record<string, unknown>): Promise<T>;
|
|
1295
1338
|
createBoardComment<T = unknown>(postSeq: number, body: Record<string, unknown>): Promise<T>;
|
|
@@ -1326,6 +1369,7 @@ declare const EntityAppServerApi_base: {
|
|
|
1326
1369
|
csrfRefresher: (() => Promise<void>) | null;
|
|
1327
1370
|
requestAbortControllers: Map<string, AbortController>;
|
|
1328
1371
|
activeTxId: string | null;
|
|
1372
|
+
initialHealthFired: boolean;
|
|
1329
1373
|
keepSession: boolean;
|
|
1330
1374
|
refreshBuffer: number;
|
|
1331
1375
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -1348,8 +1392,10 @@ declare const EntityAppServerApi_base: {
|
|
|
1348
1392
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
1349
1393
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
1350
1394
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
1395
|
+
fireInitialHealth(): void;
|
|
1351
1396
|
setToken(token: string): void;
|
|
1352
1397
|
setAccessTokenFromResponse(token: string): void;
|
|
1398
|
+
syncRealtimeWithToken(): void;
|
|
1353
1399
|
setAnonymousPacketToken(token: string): void;
|
|
1354
1400
|
setApiKey(apiKey: string): void;
|
|
1355
1401
|
setHmacSecret(secret: string): void;
|
|
@@ -1420,6 +1466,7 @@ declare const EntityAppServerApi_base: {
|
|
|
1420
1466
|
csrfRefresher: (() => Promise<void>) | null;
|
|
1421
1467
|
requestAbortControllers: Map<string, AbortController>;
|
|
1422
1468
|
activeTxId: string | null;
|
|
1469
|
+
initialHealthFired: boolean;
|
|
1423
1470
|
keepSession: boolean;
|
|
1424
1471
|
refreshBuffer: number;
|
|
1425
1472
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -1442,8 +1489,10 @@ declare const EntityAppServerApi_base: {
|
|
|
1442
1489
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
1443
1490
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
1444
1491
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
1492
|
+
fireInitialHealth(): void;
|
|
1445
1493
|
setToken(token: string): void;
|
|
1446
1494
|
setAccessTokenFromResponse(token: string): void;
|
|
1495
|
+
syncRealtimeWithToken(): void;
|
|
1447
1496
|
setAnonymousPacketToken(token: string): void;
|
|
1448
1497
|
setApiKey(apiKey: string): void;
|
|
1449
1498
|
setHmacSecret(secret: string): void;
|
|
@@ -48,6 +48,7 @@ declare const EntityServerApi_base: {
|
|
|
48
48
|
csrfRefresher: (() => Promise<void>) | null;
|
|
49
49
|
requestAbortControllers: Map<string, AbortController>;
|
|
50
50
|
activeTxId: string | null;
|
|
51
|
+
initialHealthFired: boolean;
|
|
51
52
|
keepSession: boolean;
|
|
52
53
|
refreshBuffer: number;
|
|
53
54
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -70,8 +71,10 @@ declare const EntityServerApi_base: {
|
|
|
70
71
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
71
72
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
72
73
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
74
|
+
fireInitialHealth(): void;
|
|
73
75
|
setToken(token: string): void;
|
|
74
76
|
setAccessTokenFromResponse(token: string): void;
|
|
77
|
+
syncRealtimeWithToken(): void;
|
|
75
78
|
setAnonymousPacketToken(token: string): void;
|
|
76
79
|
setApiKey(apiKey: string): void;
|
|
77
80
|
setHmacSecret(secret: string): void;
|
|
@@ -135,6 +138,7 @@ declare const EntityServerApi_base: {
|
|
|
135
138
|
csrfRefresher: (() => Promise<void>) | null;
|
|
136
139
|
requestAbortControllers: Map<string, AbortController>;
|
|
137
140
|
activeTxId: string | null;
|
|
141
|
+
initialHealthFired: boolean;
|
|
138
142
|
keepSession: boolean;
|
|
139
143
|
refreshBuffer: number;
|
|
140
144
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -157,8 +161,10 @@ declare const EntityServerApi_base: {
|
|
|
157
161
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
158
162
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
159
163
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
164
|
+
fireInitialHealth(): void;
|
|
160
165
|
setToken(token: string): void;
|
|
161
166
|
setAccessTokenFromResponse(token: string): void;
|
|
167
|
+
syncRealtimeWithToken(): void;
|
|
162
168
|
setAnonymousPacketToken(token: string): void;
|
|
163
169
|
setApiKey(apiKey: string): void;
|
|
164
170
|
setHmacSecret(secret: string): void;
|
|
@@ -284,6 +290,7 @@ declare const EntityServerApi_base: {
|
|
|
284
290
|
csrfRefresher: (() => Promise<void>) | null;
|
|
285
291
|
requestAbortControllers: Map<string, AbortController>;
|
|
286
292
|
activeTxId: string | null;
|
|
293
|
+
initialHealthFired: boolean;
|
|
287
294
|
keepSession: boolean;
|
|
288
295
|
refreshBuffer: number;
|
|
289
296
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -306,8 +313,10 @@ declare const EntityServerApi_base: {
|
|
|
306
313
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
307
314
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
308
315
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
316
|
+
fireInitialHealth(): void;
|
|
309
317
|
setToken(token: string): void;
|
|
310
318
|
setAccessTokenFromResponse(token: string): void;
|
|
319
|
+
syncRealtimeWithToken(): void;
|
|
311
320
|
setAnonymousPacketToken(token: string): void;
|
|
312
321
|
setApiKey(apiKey: string): void;
|
|
313
322
|
setHmacSecret(secret: string): void;
|
|
@@ -377,6 +386,7 @@ declare const EntityServerApi_base: {
|
|
|
377
386
|
csrfRefresher: (() => Promise<void>) | null;
|
|
378
387
|
requestAbortControllers: Map<string, AbortController>;
|
|
379
388
|
activeTxId: string | null;
|
|
389
|
+
initialHealthFired: boolean;
|
|
380
390
|
keepSession: boolean;
|
|
381
391
|
refreshBuffer: number;
|
|
382
392
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -399,8 +409,10 @@ declare const EntityServerApi_base: {
|
|
|
399
409
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
400
410
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
401
411
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
412
|
+
fireInitialHealth(): void;
|
|
402
413
|
setToken(token: string): void;
|
|
403
414
|
setAccessTokenFromResponse(token: string): void;
|
|
415
|
+
syncRealtimeWithToken(): void;
|
|
404
416
|
setAnonymousPacketToken(token: string): void;
|
|
405
417
|
setApiKey(apiKey: string): void;
|
|
406
418
|
setHmacSecret(secret: string): void;
|
|
@@ -488,6 +500,7 @@ declare const EntityServerApi_base: {
|
|
|
488
500
|
csrfRefresher: (() => Promise<void>) | null;
|
|
489
501
|
requestAbortControllers: Map<string, AbortController>;
|
|
490
502
|
activeTxId: string | null;
|
|
503
|
+
initialHealthFired: boolean;
|
|
491
504
|
keepSession: boolean;
|
|
492
505
|
refreshBuffer: number;
|
|
493
506
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -510,8 +523,10 @@ declare const EntityServerApi_base: {
|
|
|
510
523
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
511
524
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
512
525
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
526
|
+
fireInitialHealth(): void;
|
|
513
527
|
setToken(token: string): void;
|
|
514
528
|
setAccessTokenFromResponse(token: string): void;
|
|
529
|
+
syncRealtimeWithToken(): void;
|
|
515
530
|
setAnonymousPacketToken(token: string): void;
|
|
516
531
|
setApiKey(apiKey: string): void;
|
|
517
532
|
setHmacSecret(secret: string): void;
|
|
@@ -634,6 +649,7 @@ declare const EntityServerApi_base: {
|
|
|
634
649
|
csrfRefresher: (() => Promise<void>) | null;
|
|
635
650
|
requestAbortControllers: Map<string, AbortController>;
|
|
636
651
|
activeTxId: string | null;
|
|
652
|
+
initialHealthFired: boolean;
|
|
637
653
|
keepSession: boolean;
|
|
638
654
|
refreshBuffer: number;
|
|
639
655
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -656,8 +672,10 @@ declare const EntityServerApi_base: {
|
|
|
656
672
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
657
673
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
658
674
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
675
|
+
fireInitialHealth(): void;
|
|
659
676
|
setToken(token: string): void;
|
|
660
677
|
setAccessTokenFromResponse(token: string): void;
|
|
678
|
+
syncRealtimeWithToken(): void;
|
|
661
679
|
setAnonymousPacketToken(token: string): void;
|
|
662
680
|
setApiKey(apiKey: string): void;
|
|
663
681
|
setHmacSecret(secret: string): void;
|
|
@@ -784,6 +802,7 @@ declare const EntityServerApi_base: {
|
|
|
784
802
|
csrfRefresher: (() => Promise<void>) | null;
|
|
785
803
|
requestAbortControllers: Map<string, AbortController>;
|
|
786
804
|
activeTxId: string | null;
|
|
805
|
+
initialHealthFired: boolean;
|
|
787
806
|
keepSession: boolean;
|
|
788
807
|
refreshBuffer: number;
|
|
789
808
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -806,8 +825,10 @@ declare const EntityServerApi_base: {
|
|
|
806
825
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
807
826
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
808
827
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
828
|
+
fireInitialHealth(): void;
|
|
809
829
|
setToken(token: string): void;
|
|
810
830
|
setAccessTokenFromResponse(token: string): void;
|
|
831
|
+
syncRealtimeWithToken(): void;
|
|
811
832
|
setAnonymousPacketToken(token: string): void;
|
|
812
833
|
setApiKey(apiKey: string): void;
|
|
813
834
|
setHmacSecret(secret: string): void;
|
|
@@ -902,6 +923,7 @@ declare const EntityServerApi_base: {
|
|
|
902
923
|
csrfCookieName: string;
|
|
903
924
|
requestAbortControllers: Map<string, AbortController>;
|
|
904
925
|
activeTxId: string | null;
|
|
926
|
+
initialHealthFired: boolean;
|
|
905
927
|
keepSession: boolean;
|
|
906
928
|
refreshBuffer: number;
|
|
907
929
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -924,7 +946,9 @@ declare const EntityServerApi_base: {
|
|
|
924
946
|
realtimeStatusListeners: Set<import("./types.js").RealtimeStatusListener>;
|
|
925
947
|
realtimeEventListeners: Map<string, Set<import("./types.js").RealtimeMessageListener>>;
|
|
926
948
|
configure(options: Partial<import("./types.js").EntityServerClientOptions>): void;
|
|
949
|
+
fireInitialHealth(): void;
|
|
927
950
|
setToken(token: string): void;
|
|
951
|
+
syncRealtimeWithToken(): void;
|
|
928
952
|
setAnonymousPacketToken(token: string): void;
|
|
929
953
|
setApiKey(apiKey: string): void;
|
|
930
954
|
setHmacSecret(secret: string): void;
|
package/dist/client/base.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export declare class EntityServerClientBase {
|
|
|
15
15
|
csrfRefresher: (() => Promise<void>) | null;
|
|
16
16
|
requestAbortControllers: Map<string, AbortController>;
|
|
17
17
|
activeTxId: string | null;
|
|
18
|
+
/** @internal 브라우저에서 첫 구성 시 health 1회 자동 호출했는지 여부 */
|
|
19
|
+
initialHealthFired: boolean;
|
|
18
20
|
keepSession: boolean;
|
|
19
21
|
refreshBuffer: number;
|
|
20
22
|
onTokenRefreshed?: (accessToken: string, expiresIn: number) => void;
|
|
@@ -45,10 +47,21 @@ export declare class EntityServerClientBase {
|
|
|
45
47
|
constructor(options?: EntityServerClientOptions);
|
|
46
48
|
/** baseUrl, token, encryptRequests 값을 런타임에 갱신합니다. */
|
|
47
49
|
configure(options: Partial<EntityServerClientOptions>): void;
|
|
50
|
+
/**
|
|
51
|
+
* 브라우저에서 클라이언트가 처음 구성될 때 `/v1/health` 를 1회 자동 호출한다.
|
|
52
|
+
*
|
|
53
|
+
* CSRF·anon 쿠키 발급과 패킷 암호화 협상(`X-Packet-Encryption`)을 앱 진입 즉시 선반영해,
|
|
54
|
+
* 프런트 라우트(`/login` 등)와 무관하게 항상 health 가 최소 1회 돌도록 보장한다.
|
|
55
|
+
*
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
fireInitialHealth(): void;
|
|
48
59
|
/** 인증 요청에 사용할 JWT Access Token을 설정합니다. */
|
|
49
60
|
setToken(token: string): void;
|
|
50
61
|
/** 응답 헤더로 받은 access token 갱신을 반영한다. */
|
|
51
62
|
setAccessTokenFromResponse(token: string): void;
|
|
63
|
+
/** 토큰 변경 후 realtime 연결 상태를 동기화한다. */
|
|
64
|
+
syncRealtimeWithToken(): void;
|
|
52
65
|
/** 익명 패킷 암호화용 토큰을 설정합니다. */
|
|
53
66
|
setAnonymousPacketToken(token: string): void;
|
|
54
67
|
/** HMAC 인증용 API Key를 설정합니다. */
|
package/dist/client/base.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{readEnv as m}from"./utils.js";import{derivePacketKey as u,parseRequestBody as f}from"./packet.js";import{entityRequest as l}from"./request.js";const c="/v1/realtime";class y{baseUrl;token;anonymousPacketToken;apiKey;hmacSecret;encryptRequests;csrfEnabled;csrfHeaderName;csrfCookieName;csrfRefresher=null;requestAbortControllers=new Map;activeTxId=null;keepSession;refreshBuffer;onTokenRefreshed;onSessionExpired;onHealthChange;sessionRefreshToken=null;refreshTimer=null;healthTickTimer=null;healthTickPromise=null;realtimeEnabled;realtimePath;realtimeAutoReconnect;realtimeReconnectDelayMs;realtimeStatus;realtimeSocket=null;realtimeConnectPromise=null;realtimeReconnectTimer=null;realtimeShouldReconnect=!1;realtimeMessageListeners=new Set;realtimeStatusListeners=new Set;realtimeEventListeners=new Map;constructor(e={}){const t=m("VITE_ENTITY_SERVER_URL");this.baseUrl=(e.baseUrl??t??"").replace(/\/$/,""),this.token=e.token??"",this.anonymousPacketToken=e.anonymousPacketToken??"",this.apiKey=e.apiKey??"",this.hmacSecret=e.hmacSecret??"",this.encryptRequests=e.encryptRequests??!1,this.csrfEnabled=e.csrfEnabled??!1,this.csrfHeaderName=e.csrfHeaderName??"x-csrf-token",this.csrfCookieName=e.csrfCookieName??"_csrf",this.keepSession=e.keepSession??!1,this.refreshBuffer=e.refreshBuffer??60,this.onTokenRefreshed=e.onTokenRefreshed,this.onSessionExpired=e.onSessionExpired,this.onHealthChange=e.onHealthChange,this.realtimeEnabled=!1,this.realtimePath=c,this.realtimeAutoReconnect=!0,this.realtimeReconnectDelayMs=3e3,this.realtimeStatus="idle",this.applyRealtimeOptions(e.realtime),typeof e.healthTickInterval=="number"&&e.healthTickInterval>0&&Promise.resolve().then(()=>this.startHealthTick(e.healthTickInterval,!1))}configure(e){typeof e.baseUrl=="string"&&(this.baseUrl=e.baseUrl.replace(/\/$/,"")),typeof e.token=="string"&&(this.token=e.token),typeof e.anonymousPacketToken=="string"&&(this.anonymousPacketToken=e.anonymousPacketToken),typeof e.encryptRequests=="boolean"&&(this.encryptRequests=e.encryptRequests),typeof e.csrfEnabled=="boolean"&&(this.csrfEnabled=e.csrfEnabled),typeof e.csrfHeaderName=="string"&&(this.csrfHeaderName=e.csrfHeaderName),typeof e.csrfCookieName=="string"&&(this.csrfCookieName=e.csrfCookieName),typeof e.apiKey=="string"&&(this.apiKey=e.apiKey),typeof e.hmacSecret=="string"&&(this.hmacSecret=e.hmacSecret),typeof e.keepSession=="boolean"&&(this.keepSession=e.keepSession),typeof e.refreshBuffer=="number"&&(this.refreshBuffer=e.refreshBuffer),e.onTokenRefreshed&&(this.onTokenRefreshed=e.onTokenRefreshed),e.onSessionExpired&&(this.onSessionExpired=e.onSessionExpired),e.onHealthChange&&(this.onHealthChange=e.onHealthChange),typeof e.realtime<"u"&&this.applyRealtimeOptions(e.realtime),typeof e.healthTickInterval=="number"&&e.healthTickInterval>0&&Promise.resolve().then(()=>this.startHealthTick(e.healthTickInterval,!1))}setToken(e){this.token=e,e||this.disconnectRealtime("token_cleared")}setAccessTokenFromResponse(e){this.token=e,e||this.disconnectRealtime("token_cleared")}setAnonymousPacketToken(e){this.anonymousPacketToken=e}setApiKey(e){this.apiKey=e}setHmacSecret(e){this.hmacSecret=e}setEncryptRequests(e){this.encryptRequests=e}setCsrfEnabled(e){this.csrfEnabled=e}addRealtimeListener(e){this.realtimeMessageListeners.add(e)}removeRealtimeListener(e){this.realtimeMessageListeners.delete(e)}addRealtimeStatusListener(e){this.realtimeStatusListeners.add(e)}removeRealtimeStatusListener(e){this.realtimeStatusListeners.delete(e)}addRealtimeEventListener(e,t){const i=String(e).trim();i&&(this.realtimeEventListeners.has(i)||this.realtimeEventListeners.set(i,new Set),this.realtimeEventListeners.get(i).add(t))}removeRealtimeEventListener(e,t){const i=String(e).trim();if(!i)return;const s=this.realtimeEventListeners.get(i);s&&(s.delete(t),s.size===0&&this.realtimeEventListeners.delete(i))}async connectRealtime(){if(!this.realtimeEnabled){this.setRealtimeStatus("disabled","realtime_disabled");return}if(!this.token)throw new Error("Cannot open realtime connection without access token.");if(typeof WebSocket>"u")throw new Error("WebSocket is not available in this environment.");if(this.realtimeSocket&&this.realtimeSocket.readyState===WebSocket.OPEN)return;if(this.realtimeSocket&&this.realtimeSocket.readyState===WebSocket.CONNECTING&&this.realtimeConnectPromise)return this.realtimeConnectPromise;this.clearRealtimeReconnectTimer(),this.realtimeShouldReconnect=this.realtimeAutoReconnect,this.setRealtimeStatus("connecting","connect_requested");const e=new WebSocket(this.buildRealtimeUrl());return this.realtimeSocket=e,this.realtimeConnectPromise=new Promise((t,i)=>{let s=!1;const r=()=>{s||(s=!0,this.realtimeConnectPromise=null,t())},n=a=>{s||(s=!0,this.realtimeConnectPromise=null,i(a))};e.addEventListener("open",()=>{this.setRealtimeStatus("open","socket_open"),r()}),e.addEventListener("message",a=>{this.handleRealtimeMessage(a.data)}),e.addEventListener("error",()=>{this.setRealtimeStatus("closed","socket_error",new Error("Realtime socket error."))}),e.addEventListener("close",a=>{this.realtimeSocket===e&&(this.realtimeSocket=null);const o=a.reason||"socket_closed",h=new Error(`Realtime socket closed (${a.code}${a.reason?`: ${a.reason}`:""}).`);this.setRealtimeStatus("closed",o,h),s||n(h),this.realtimeShouldReconnect&&this.realtimeEnabled&&this.realtimeAutoReconnect&&this.token&&this.scheduleRealtimeReconnect(o)})}),this.realtimeConnectPromise}disconnectRealtime(e="client_disconnect"){if(this.realtimeShouldReconnect=!1,this.clearRealtimeReconnectTimer(),this.realtimeSocket){const t=this.realtimeSocket;this.realtimeSocket=null;try{(t.readyState===WebSocket.OPEN||t.readyState===WebSocket.CONNECTING)&&t.close(1e3,e)}catch{}}this.realtimeConnectPromise=null,this.setRealtimeStatus(this.realtimeEnabled?"idle":"disabled",e)}sendRealtime(e){return!this.realtimeSocket||this.realtimeSocket.readyState!==WebSocket.OPEN?!1:(this.realtimeSocket.send(JSON.stringify(e)),!0)}subscribeRealtime(e){return this.sendRealtime({type:"subscribe",channel:"session",event:"session.subscribe",data:{subscriptions:e}})}unsubscribeRealtime(e){return this.sendRealtime({type:"unsubscribe",channel:"session",event:"session.unsubscribe",data:{subscriptions:e}})}startHealthTick(e=300*1e3,t=!0){this.stopHealthTick();const i=()=>{this.healthTickPromise||(this.healthTickPromise=(this.csrfRefresher?this.csrfRefresher():Promise.resolve()).then(()=>{this.onHealthChange?.(!0)}).catch(()=>{this.onHealthChange?.(!1)}).finally(()=>{this.healthTickPromise=null}))};t&&i(),this.healthTickTimer=setInterval(i,e)}stopHealthTick(){this.healthTickTimer!==null&&(clearInterval(this.healthTickTimer),this.healthTickTimer=null),this.healthTickPromise=null}scheduleKeepSession(e,t,i){this.clearRefreshTimer(),this.sessionRefreshToken=e;const s=Math.max((t-this.refreshBuffer)*1e3,0);this.refreshTimer=setTimeout(async()=>{if(this.sessionRefreshToken)try{const r=await i(this.sessionRefreshToken);this.onTokenRefreshed?.(r.access_token,r.expires_in),this.scheduleKeepSession(this.sessionRefreshToken,r.expires_in,i)}catch(r){this.clearRefreshTimer(),this.onSessionExpired?.(r instanceof Error?r:new Error(String(r)))}},s)}clearRefreshTimer(){this.refreshTimer!==null&&(clearTimeout(this.refreshTimer),this.refreshTimer=null)}stopKeepSession(){this.clearRefreshTimer(),this.sessionRefreshToken=null}applyRealtimeOptions(e){const t=typeof e=="boolean"?{enabled:e}:e??{};if(this.realtimeEnabled=t.enabled??!1,this.realtimePath=String(t.path??c).trim()||c,this.realtimeAutoReconnect=t.autoReconnect??!0,this.realtimeReconnectDelayMs=Math.max(250,t.reconnectDelayMs??3e3),!this.realtimeEnabled){this.disconnectRealtime("realtime_disabled");return}this.setRealtimeStatus("idle","realtime_enabled")}buildRealtimeUrl(){const e=this.baseUrl||m("VITE_ENTITY_SERVER_URL")||"",t=typeof window<"u"?window.location.origin:"",i=e||t;if(!i)throw new Error("Realtime connection requires baseUrl.");const s=new URL(i,t||void 0),r=s.pathname==="/"?"":s.pathname.replace(/\/+$/,""),n=`/${this.realtimePath.replace(/^\/+/,"")}`;return s.pathname=`${r}${n}`||n,s.search="",s.hash="",s.protocol=s.protocol==="https:"?"wss:":"ws:",s.searchParams.set("access_token",this.token),s.toString()}handleRealtimeMessage(e){if(typeof e!="string")return;let t;try{t=JSON.parse(e)}catch{return}for(const s of this.realtimeMessageListeners)s(t);const i=this.realtimeEventListeners.get(t.event);if(i)for(const s of i)s(t)}scheduleRealtimeReconnect(e){this.clearRealtimeReconnectTimer(),this.realtimeReconnectTimer=setTimeout(()=>{this.realtimeReconnectTimer=null,!(!this.realtimeEnabled||!this.token)&&(this.setRealtimeStatus("connecting",`${e}:reconnect`),this.connectRealtime().catch(()=>{}))},this.realtimeReconnectDelayMs)}clearRealtimeReconnectTimer(){this.realtimeReconnectTimer!==null&&(clearTimeout(this.realtimeReconnectTimer),this.realtimeReconnectTimer=null)}setRealtimeStatus(e,t,i){const s=this.realtimeStatus;if(!(s===e&&typeof t>"u"&&typeof i>"u")){this.realtimeStatus=e;for(const r of this.realtimeStatusListeners)r({status:e,previousStatus:s,...t?{reason:t}:{},...i?{error:i}:{}})}}applyCsrfHealth(){if(!(typeof document>"u")){for(const e of document.cookie.split(";")){const t=e.indexOf("=");if(!(t<0)&&e.substring(0,t).trim()===this.csrfCookieName){this.csrfEnabled=!!e.substring(t+1).trim();return}}this.csrfEnabled=!1}}readRequestBody(e,t="application/json",i=!1){const s=u(this.hmacSecret,this.token||this.anonymousPacketToken);return f(e,t,i,s)}get reqOpts(){return{baseUrl:this.baseUrl,token:this.token,anonymousPacketToken:this.anonymousPacketToken,apiKey:this.apiKey,hmacSecret:this.hmacSecret,encryptRequests:this.encryptRequests,csrfEnabled:this.csrfEnabled,csrfHeaderName:this.csrfHeaderName,csrfCookieName:this.csrfCookieName,refreshCsrfCookie:this.csrfEnabled?this.csrfRefresher:null,requestAbortControllers:this.requestAbortControllers,onAccessToken:e=>{this.setAccessTokenFromResponse(e)}}}prepareRequest(e){return Promise.resolve()}get http(){const e=this;return{get(t,i=!0,s,r){return e.prepareRequest(i).then(()=>l(e.reqOpts,"GET",t,void 0,i,s,r??!0))},post(t,i,s=!0,r,n){return e.prepareRequest(s).then(()=>l(e.reqOpts,"POST",t,i,s,r,n??!0))},put(t,i,s=!0,r,n){return e.prepareRequest(s).then(()=>l(e.reqOpts,"PUT",t,i,s,r,n??!0))},patch(t,i,s=!0,r,n){return e.prepareRequest(s).then(()=>l(e.reqOpts,"PATCH",t,i,s,r,n??!0))},delete(t,i,s=!0,r,n){return e.prepareRequest(s).then(()=>l(e.reqOpts,"DELETE",t,i,s,r,n??!0))}}}request(e,t,i,s=!0,r,n){return this.prepareRequest(s).then(()=>l(this.reqOpts,e,t,i,s,r,n??!0))}async requestBinary(e,t,i,s=!0){await this.prepareRequest(s);const r={"Content-Type":"application/json"};s&&this.token&&(r.Authorization=`Bearer ${this.token}`),this.apiKey&&(r["X-API-Key"]=this.apiKey);const n=await fetch(this.baseUrl+t,{method:e,headers:r,...i!=null?{body:JSON.stringify(i)}:{},credentials:"include"});if(!n.ok){const a=await n.text(),o=new Error(`HTTP ${n.status}: ${a}`);throw o.status=n.status,o}return n.arrayBuffer()}async requestForm(e,t,i,s=!0){const r={};s&&this.token&&(r.Authorization=`Bearer ${this.token}`),this.apiKey&&(r["X-API-Key"]=this.apiKey);const n=await fetch(this.baseUrl+t,{method:e,headers:r,body:i,credentials:"include"}),a=await n.json();if(!a.ok){const o=new Error(a.message??`EntityServer error (HTTP ${n.status})`);throw o.status=n.status,o}return a}async requestFormBinary(e,t,i,s=!0){const r={};s&&this.token&&(r.Authorization=`Bearer ${this.token}`),this.apiKey&&(r["X-API-Key"]=this.apiKey);const n=await fetch(this.baseUrl+t,{method:e,headers:r,body:i,credentials:"include"});if(!n.ok){const a=await n.text(),o=new Error(`HTTP ${n.status}: ${a}`);throw o.status=n.status,o}return n.arrayBuffer()}}export{y as EntityServerClientBase};
|
|
1
|
+
import{readEnv as m}from"./utils.js";import{derivePacketKey as u,parseRequestBody as f}from"./packet.js";import{entityRequest as l}from"./request.js";const c="/v1/realtime";class y{baseUrl;token;anonymousPacketToken;apiKey;hmacSecret;encryptRequests;csrfEnabled;csrfHeaderName;csrfCookieName;csrfRefresher=null;requestAbortControllers=new Map;activeTxId=null;initialHealthFired=!1;keepSession;refreshBuffer;onTokenRefreshed;onSessionExpired;onHealthChange;sessionRefreshToken=null;refreshTimer=null;healthTickTimer=null;healthTickPromise=null;realtimeEnabled;realtimePath;realtimeAutoReconnect;realtimeReconnectDelayMs;realtimeStatus;realtimeSocket=null;realtimeConnectPromise=null;realtimeReconnectTimer=null;realtimeShouldReconnect=!1;realtimeMessageListeners=new Set;realtimeStatusListeners=new Set;realtimeEventListeners=new Map;constructor(e={}){const t=m("VITE_ENTITY_SERVER_URL");this.baseUrl=(e.baseUrl??t??"").replace(/\/$/,""),this.token=e.token??"",this.anonymousPacketToken=e.anonymousPacketToken??"",this.apiKey=e.apiKey??"",this.hmacSecret=e.hmacSecret??"",this.encryptRequests=e.encryptRequests??!1,this.csrfEnabled=e.csrfEnabled??!1,this.csrfHeaderName=e.csrfHeaderName??"x-csrf-token",this.csrfCookieName=e.csrfCookieName??"_csrf",this.keepSession=e.keepSession??!1,this.refreshBuffer=e.refreshBuffer??60,this.onTokenRefreshed=e.onTokenRefreshed,this.onSessionExpired=e.onSessionExpired,this.onHealthChange=e.onHealthChange,this.realtimeEnabled=!1,this.realtimePath=c,this.realtimeAutoReconnect=!0,this.realtimeReconnectDelayMs=3e3,this.realtimeStatus="idle",this.applyRealtimeOptions(e.realtime),typeof e.healthTickInterval=="number"&&e.healthTickInterval>0&&Promise.resolve().then(()=>this.startHealthTick(e.healthTickInterval,!1)),this.fireInitialHealth()}configure(e){typeof e.baseUrl=="string"&&(this.baseUrl=e.baseUrl.replace(/\/$/,"")),typeof e.token=="string"&&(this.token=e.token),typeof e.anonymousPacketToken=="string"&&(this.anonymousPacketToken=e.anonymousPacketToken),typeof e.encryptRequests=="boolean"&&(this.encryptRequests=e.encryptRequests),typeof e.csrfEnabled=="boolean"&&(this.csrfEnabled=e.csrfEnabled),typeof e.csrfHeaderName=="string"&&(this.csrfHeaderName=e.csrfHeaderName),typeof e.csrfCookieName=="string"&&(this.csrfCookieName=e.csrfCookieName),typeof e.apiKey=="string"&&(this.apiKey=e.apiKey),typeof e.hmacSecret=="string"&&(this.hmacSecret=e.hmacSecret),typeof e.keepSession=="boolean"&&(this.keepSession=e.keepSession),typeof e.refreshBuffer=="number"&&(this.refreshBuffer=e.refreshBuffer),e.onTokenRefreshed&&(this.onTokenRefreshed=e.onTokenRefreshed),e.onSessionExpired&&(this.onSessionExpired=e.onSessionExpired),e.onHealthChange&&(this.onHealthChange=e.onHealthChange),typeof e.realtime<"u"&&this.applyRealtimeOptions(e.realtime),typeof e.healthTickInterval=="number"&&e.healthTickInterval>0&&Promise.resolve().then(()=>this.startHealthTick(e.healthTickInterval,!1)),this.fireInitialHealth()}fireInitialHealth(){if(this.initialHealthFired||typeof document>"u"||!this.baseUrl)return;this.initialHealthFired=!0;const e=this;typeof e.checkHealth=="function"&&Promise.resolve().then(()=>e.checkHealth(!1).catch(()=>{}))}setToken(e){this.token=e,this.syncRealtimeWithToken()}setAccessTokenFromResponse(e){this.token=e,this.syncRealtimeWithToken()}syncRealtimeWithToken(){if(!this.token){this.disconnectRealtime("token_cleared");return}!this.realtimeEnabled||typeof WebSocket>"u"||this.connectRealtime().catch(()=>{})}setAnonymousPacketToken(e){this.anonymousPacketToken=e}setApiKey(e){this.apiKey=e}setHmacSecret(e){this.hmacSecret=e}setEncryptRequests(e){this.encryptRequests=e}setCsrfEnabled(e){this.csrfEnabled=e}addRealtimeListener(e){this.realtimeMessageListeners.add(e)}removeRealtimeListener(e){this.realtimeMessageListeners.delete(e)}addRealtimeStatusListener(e){this.realtimeStatusListeners.add(e)}removeRealtimeStatusListener(e){this.realtimeStatusListeners.delete(e)}addRealtimeEventListener(e,t){const i=String(e).trim();i&&(this.realtimeEventListeners.has(i)||this.realtimeEventListeners.set(i,new Set),this.realtimeEventListeners.get(i).add(t))}removeRealtimeEventListener(e,t){const i=String(e).trim();if(!i)return;const s=this.realtimeEventListeners.get(i);s&&(s.delete(t),s.size===0&&this.realtimeEventListeners.delete(i))}async connectRealtime(){if(!this.realtimeEnabled){this.setRealtimeStatus("disabled","realtime_disabled");return}if(!this.token)throw new Error("Cannot open realtime connection without access token.");if(typeof WebSocket>"u")throw new Error("WebSocket is not available in this environment.");if(this.realtimeSocket&&this.realtimeSocket.readyState===WebSocket.OPEN)return;if(this.realtimeSocket&&this.realtimeSocket.readyState===WebSocket.CONNECTING&&this.realtimeConnectPromise)return this.realtimeConnectPromise;this.clearRealtimeReconnectTimer(),this.realtimeShouldReconnect=this.realtimeAutoReconnect,this.setRealtimeStatus("connecting","connect_requested");const e=new WebSocket(this.buildRealtimeUrl());return this.realtimeSocket=e,this.realtimeConnectPromise=new Promise((t,i)=>{let s=!1;const r=()=>{s||(s=!0,this.realtimeConnectPromise=null,t())},n=a=>{s||(s=!0,this.realtimeConnectPromise=null,i(a))};e.addEventListener("open",()=>{this.setRealtimeStatus("open","socket_open"),r()}),e.addEventListener("message",a=>{this.handleRealtimeMessage(a.data)}),e.addEventListener("error",()=>{this.setRealtimeStatus("closed","socket_error",new Error("Realtime socket error."))}),e.addEventListener("close",a=>{this.realtimeSocket===e&&(this.realtimeSocket=null);const o=a.reason||"socket_closed",h=new Error(`Realtime socket closed (${a.code}${a.reason?`: ${a.reason}`:""}).`);this.setRealtimeStatus("closed",o,h),s||n(h),this.realtimeShouldReconnect&&this.realtimeEnabled&&this.realtimeAutoReconnect&&this.token&&this.scheduleRealtimeReconnect(o)})}),this.realtimeConnectPromise}disconnectRealtime(e="client_disconnect"){if(this.realtimeShouldReconnect=!1,this.clearRealtimeReconnectTimer(),this.realtimeSocket){const t=this.realtimeSocket;this.realtimeSocket=null;try{(t.readyState===WebSocket.OPEN||t.readyState===WebSocket.CONNECTING)&&t.close(1e3,e)}catch{}}this.realtimeConnectPromise=null,this.setRealtimeStatus(this.realtimeEnabled?"idle":"disabled",e)}sendRealtime(e){return!this.realtimeSocket||this.realtimeSocket.readyState!==WebSocket.OPEN?!1:(this.realtimeSocket.send(JSON.stringify(e)),!0)}subscribeRealtime(e){return this.sendRealtime({type:"subscribe",channel:"session",event:"session.subscribe",data:{subscriptions:e}})}unsubscribeRealtime(e){return this.sendRealtime({type:"unsubscribe",channel:"session",event:"session.unsubscribe",data:{subscriptions:e}})}startHealthTick(e=300*1e3,t=!0){this.stopHealthTick();const i=()=>{this.healthTickPromise||(this.healthTickPromise=(this.csrfRefresher?this.csrfRefresher():Promise.resolve()).then(()=>{this.onHealthChange?.(!0)}).catch(()=>{this.onHealthChange?.(!1)}).finally(()=>{this.healthTickPromise=null}))};t&&i(),this.healthTickTimer=setInterval(i,e)}stopHealthTick(){this.healthTickTimer!==null&&(clearInterval(this.healthTickTimer),this.healthTickTimer=null),this.healthTickPromise=null}scheduleKeepSession(e,t,i){this.clearRefreshTimer(),this.sessionRefreshToken=e;const s=Math.max((t-this.refreshBuffer)*1e3,0);this.refreshTimer=setTimeout(async()=>{if(this.sessionRefreshToken)try{const r=await i(this.sessionRefreshToken);this.onTokenRefreshed?.(r.access_token,r.expires_in),this.scheduleKeepSession(this.sessionRefreshToken,r.expires_in,i)}catch(r){this.clearRefreshTimer(),this.onSessionExpired?.(r instanceof Error?r:new Error(String(r)))}},s)}clearRefreshTimer(){this.refreshTimer!==null&&(clearTimeout(this.refreshTimer),this.refreshTimer=null)}stopKeepSession(){this.clearRefreshTimer(),this.sessionRefreshToken=null}applyRealtimeOptions(e){const t=typeof e=="boolean"?{enabled:e}:e??{};if(this.realtimeEnabled=t.enabled??!1,this.realtimePath=String(t.path??c).trim()||c,this.realtimeAutoReconnect=t.autoReconnect??!0,this.realtimeReconnectDelayMs=Math.max(250,t.reconnectDelayMs??3e3),!this.realtimeEnabled){this.disconnectRealtime("realtime_disabled");return}this.setRealtimeStatus("idle","realtime_enabled")}buildRealtimeUrl(){const e=this.baseUrl||m("VITE_ENTITY_SERVER_URL")||"",t=typeof window<"u"?window.location.origin:"",i=e||t;if(!i)throw new Error("Realtime connection requires baseUrl.");const s=new URL(i,t||void 0),r=s.pathname==="/"?"":s.pathname.replace(/\/+$/,""),n=`/${this.realtimePath.replace(/^\/+/,"")}`;return s.pathname=`${r}${n}`||n,s.search="",s.hash="",s.protocol=s.protocol==="https:"?"wss:":"ws:",s.searchParams.set("access_token",this.token),s.toString()}handleRealtimeMessage(e){if(typeof e!="string")return;let t;try{t=JSON.parse(e)}catch{return}for(const s of this.realtimeMessageListeners)s(t);const i=this.realtimeEventListeners.get(t.event);if(i)for(const s of i)s(t)}scheduleRealtimeReconnect(e){this.clearRealtimeReconnectTimer(),this.realtimeReconnectTimer=setTimeout(()=>{this.realtimeReconnectTimer=null,!(!this.realtimeEnabled||!this.token)&&(this.setRealtimeStatus("connecting",`${e}:reconnect`),this.connectRealtime().catch(()=>{}))},this.realtimeReconnectDelayMs)}clearRealtimeReconnectTimer(){this.realtimeReconnectTimer!==null&&(clearTimeout(this.realtimeReconnectTimer),this.realtimeReconnectTimer=null)}setRealtimeStatus(e,t,i){const s=this.realtimeStatus;if(!(s===e&&typeof t>"u"&&typeof i>"u")){this.realtimeStatus=e;for(const r of this.realtimeStatusListeners)r({status:e,previousStatus:s,...t?{reason:t}:{},...i?{error:i}:{}})}}applyCsrfHealth(){if(!(typeof document>"u")){for(const e of document.cookie.split(";")){const t=e.indexOf("=");if(!(t<0)&&e.substring(0,t).trim()===this.csrfCookieName){this.csrfEnabled=!!e.substring(t+1).trim();return}}this.csrfEnabled=!1}}readRequestBody(e,t="application/json",i=!1){const s=u(this.hmacSecret,this.token||this.anonymousPacketToken);return f(e,t,i,s)}get reqOpts(){return{baseUrl:this.baseUrl,token:this.token,anonymousPacketToken:this.anonymousPacketToken,apiKey:this.apiKey,hmacSecret:this.hmacSecret,encryptRequests:this.encryptRequests,csrfEnabled:this.csrfEnabled,csrfHeaderName:this.csrfHeaderName,csrfCookieName:this.csrfCookieName,refreshCsrfCookie:this.csrfEnabled?this.csrfRefresher:null,requestAbortControllers:this.requestAbortControllers,onAccessToken:e=>{this.setAccessTokenFromResponse(e)}}}prepareRequest(e){return Promise.resolve()}get http(){const e=this;return{get(t,i=!0,s,r){return e.prepareRequest(i).then(()=>l(e.reqOpts,"GET",t,void 0,i,s,r??!0))},post(t,i,s=!0,r,n){return e.prepareRequest(s).then(()=>l(e.reqOpts,"POST",t,i,s,r,n??!0))},put(t,i,s=!0,r,n){return e.prepareRequest(s).then(()=>l(e.reqOpts,"PUT",t,i,s,r,n??!0))},patch(t,i,s=!0,r,n){return e.prepareRequest(s).then(()=>l(e.reqOpts,"PATCH",t,i,s,r,n??!0))},delete(t,i,s=!0,r,n){return e.prepareRequest(s).then(()=>l(e.reqOpts,"DELETE",t,i,s,r,n??!0))}}}request(e,t,i,s=!0,r,n){return this.prepareRequest(s).then(()=>l(this.reqOpts,e,t,i,s,r,n??!0))}async requestBinary(e,t,i,s=!0){await this.prepareRequest(s);const r={"Content-Type":"application/json"};s&&this.token&&(r.Authorization=`Bearer ${this.token}`),this.apiKey&&(r["X-API-Key"]=this.apiKey);const n=await fetch(this.baseUrl+t,{method:e,headers:r,...i!=null?{body:JSON.stringify(i)}:{},credentials:"include"});if(!n.ok){const a=await n.text(),o=new Error(`HTTP ${n.status}: ${a}`);throw o.status=n.status,o}return n.arrayBuffer()}async requestForm(e,t,i,s=!0){const r={};s&&this.token&&(r.Authorization=`Bearer ${this.token}`),this.apiKey&&(r["X-API-Key"]=this.apiKey);const n=await fetch(this.baseUrl+t,{method:e,headers:r,body:i,credentials:"include"}),a=await n.json();if(!a.ok){const o=new Error(a.message??`EntityServer error (HTTP ${n.status})`);throw o.status=n.status,o}return a}async requestFormBinary(e,t,i,s=!0){const r={};s&&this.token&&(r.Authorization=`Bearer ${this.token}`),this.apiKey&&(r["X-API-Key"]=this.apiKey);const n=await fetch(this.baseUrl+t,{method:e,headers:r,body:i,credentials:"include"});if(!n.ok){const a=await n.text(),o=new Error(`HTTP ${n.status}: ${a}`);throw o.status=n.status,o}return n.arrayBuffer()}}export{y as EntityServerClientBase};
|
|
2
2
|
//# sourceMappingURL=base.js.map
|