@inditextech/weave-store-azure-web-pubsub 3.0.0-SNAPSHOT.56.1 → 3.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 (2) hide show
  1. package/dist/server.d.ts +1084 -0
  2. package/package.json +3 -3
@@ -0,0 +1,1084 @@
1
+ import { WebPubSubServiceClient } from "@azure/web-pubsub";
2
+ import { TokenCredential } from "@azure/identity";
3
+ import * as Y from "yjs";
4
+ import { Doc } from "yjs";
5
+ import { WebSocket } from "ws";
6
+ import koa from "koa";
7
+ import Emittery from "emittery";
8
+ import ReconnectingWebSocket from "reconnecting-websocket";
9
+ import * as awarenessProtocol$1 from "y-protocols/awareness";
10
+ import * as awarenessProtocol from "y-protocols/awareness";
11
+ import { WeaveStore } from "@inditextech/weave-sdk";
12
+ import { DeepPartial, WeaveStoreOptions } from "@inditextech/weave-types";
13
+ import { Encoder } from "lib0/encoding";
14
+ import { Decoder } from "lib0/decoding";
15
+ import express from "express-serve-static-core";
16
+ import { RequestHandler } from "express";
17
+
18
+ //#region src/constants.d.ts
19
+ declare const WEAVE_STORE_AZURE_WEB_PUBSUB = "store-azure-web-pubsub";
20
+ declare const WEAVE_STORE_AZURE_WEB_PUBSUB_CONNECTION_STATUS: {
21
+ "CONNECTING": string;
22
+ "CONNECTED": string;
23
+ "DISCONNECTED": string;
24
+ "ERROR": string;
25
+ };
26
+ declare const WEAVE_STORE_HORIZONTAL_SYNC_HANDLER_CLIENT_TYPE: {
27
+ "PUB": string;
28
+ "SUB": string;
29
+ };
30
+
31
+ //#endregion
32
+ //#region src/store-azure-web-pubsub.d.ts
33
+ declare class WeaveStoreAzureWebPubsub extends WeaveStore {
34
+ private azureWebPubsubOptions;
35
+ private roomId;
36
+ private started;
37
+ private initialRoomData;
38
+ protected provider: WeaveStoreAzureWebPubSubSyncClient;
39
+ protected name: string;
40
+ protected supportsUndoManager: boolean;
41
+ protected awarenessCallback: (changes: any) => void;
42
+ constructor(initialRoomData: Uint8Array | FetchInitialState | undefined, storeOptions: WeaveStoreOptions, azureWebPubsubOptions: Pick<WeaveStoreAzureWebPubsubOptions, "roomId" | "url"> & Partial<Omit<WeaveStoreAzureWebPubsubOptions, "roomId" | "url">>);
43
+ setup(): void;
44
+ private loadRoomInitialData;
45
+ private init;
46
+ emitEvent<T>(name: string, payload?: T): void;
47
+ getClientId(): string | null;
48
+ connect(extraParams?: Record<string, string>): Promise<void>;
49
+ disconnect(): void;
50
+ simulateWebsocketError(): void;
51
+ destroy(): void;
52
+ handleAwarenessChange(emit?: boolean): void;
53
+ setAwarenessInfo<T>(field: string, value: T): void;
54
+ }
55
+
56
+ //#endregion
57
+ //#region src/client.d.ts
58
+ declare class WeaveStoreAzureWebPubSubSyncClient extends Emittery {
59
+ doc: Doc;
60
+ topic: string;
61
+ private instance;
62
+ private _ws;
63
+ private _url;
64
+ private _fetchClient;
65
+ private _status;
66
+ private _wsConnected;
67
+ private _synced;
68
+ private _lastReceivedSyncResponse;
69
+ private _connectionRetries;
70
+ private _uuid;
71
+ private _awareness;
72
+ private _initialized;
73
+ private _chunkedMessages;
74
+ private _updateHandler;
75
+ private _awarenessUpdateHandler;
76
+ /**
77
+ * @param {string} url
78
+ * @param {string} topic
79
+ * @param {Doc} doc
80
+ * @param {number} [options.resyncInterval] Request server state every `resyncInterval` milliseconds.
81
+ * @param {number} [options.tokenProvider] token generator for negotiation.
82
+ */
83
+ constructor(instance: WeaveStoreAzureWebPubsub, url: string, topic: string, doc: Doc);
84
+ get awareness(): awarenessProtocol$1.Awareness;
85
+ get synced(): boolean;
86
+ set synced(state: boolean);
87
+ get ws(): ReconnectingWebSocket | null;
88
+ get id(): string;
89
+ getClientId(): string;
90
+ saveLastSyncResponse(): void;
91
+ simulateWebsocketError(): void;
92
+ disconnect(): void;
93
+ setFetchClient(fetchClient?: FetchClient): void;
94
+ fetchConnectionUrl(connectionUrlExtraParams?: Record<string, string>): Promise<string>;
95
+ createWebSocket(connectionUrlExtraParams?: Record<string, string>): Promise<ReconnectingWebSocket>;
96
+ setAndEmitStatusInfo(status: WeaveStoreAzureWebPubSubSyncClientConnectionStatus): void;
97
+ connect(connectionUrlExtraParams?: Record<string, string>): Promise<void>;
98
+ }
99
+
100
+ //#endregion
101
+ //#region src/types.d.ts
102
+ type WeaveStoreAzureWebPubsubConfig = {
103
+ endpoint: string;
104
+ persistIntervalMs?: number;
105
+ hubName: string;
106
+ auth?: {
107
+ key?: string;
108
+ custom?: TokenCredential;
109
+ };
110
+ connectionHandlers?: DeepPartial<WeaveAzureWebPubsubSyncHandlerOptions>;
111
+ };
112
+ type WeaveAzureWebPubsubSyncHandlerOptions = {
113
+ onConnect?: (connectionId: string, queries: Record<string, string[]> | undefined) => Promise<void>;
114
+ onConnected?: (connectionId: string) => Promise<void>;
115
+ removeConnection?: (connectionId: string) => Promise<void>;
116
+ getConnectionRoom?: (connectionId: string) => Promise<string | null>;
117
+ getRoomConnections?: (roomId: string) => Promise<string[]>;
118
+ persistIntervalMs?: number;
119
+ };
120
+ type WeaveStoreAzureWebPubsubOptions = {
121
+ roomId: string;
122
+ url: string;
123
+ fetchClient?: FetchClient;
124
+ };
125
+ type WeaveStoreAzureWebPubsubOnStoreFetchConnectionUrlEvent = {
126
+ loading: boolean;
127
+ error: Error | null;
128
+ };
129
+ type FetchClient = (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
130
+ type FetchInitialState = (doc: Doc) => void;
131
+ type PersistRoom = (roomId: string, actualState: Uint8Array<ArrayBufferLike>) => Promise<void>;
132
+ type FetchRoom = (roomId: string) => Promise<Uint8Array | null>;
133
+ type WeaveStoreAzureWebPubsubEvents = {
134
+ onConnect: WeaveStoreAzureWebPubsubOnConnectEvent;
135
+ onConnected: WeaveStoreAzureWebPubsubOnConnectedEvent;
136
+ onDisconnected: WeaveStoreAzureWebPubsubOnDisconnectedEvent;
137
+ };
138
+ type WeaveStoreAzureWebPubsubOnConnectEvent = {
139
+ context: ConnectionContext;
140
+ queries: Record<string, string[]> | undefined;
141
+ };
142
+ type WeaveStoreAzureWebPubsubOnConnectedEvent = {
143
+ context: ConnectionContext;
144
+ queries?: Record<string, string[]>;
145
+ };
146
+ type WeaveStoreAzureWebPubsubOnDisconnectedEvent = {
147
+ context: ConnectionContext;
148
+ queries?: Record<string, string[]>;
149
+ };
150
+ type WeaveStoreAzureWebPubsubOnWebsocketOpenEvent = {
151
+ group: string;
152
+ event: WebSocket.Event;
153
+ };
154
+ type WeaveStoreAzureWebPubsubOnWebsocketJoinGroupEvent = {
155
+ group: string;
156
+ };
157
+ type WeaveStoreAzureWebPubsubOnWebsocketMessageEvent = {
158
+ group: string;
159
+ event: WebSocket.MessageEvent;
160
+ };
161
+ type WeaveStoreAzureWebPubsubOnWebsocketCloseEvent = {
162
+ group: string;
163
+ event: CloseEvent;
164
+ };
165
+ type WeaveStoreAzureWebPubsubOnWebsocketErrorEvent = {
166
+ group: string;
167
+ error: ErrorEvent;
168
+ };
169
+ type WeaveStoreAzureWebPubsubOnWebsocketOnTokenRefreshEvent = {
170
+ group: string;
171
+ };
172
+ type WeaveStoreAzureWebPubSubSyncHostClientConnectOptions = {
173
+ expirationTimeInMinutes?: number;
174
+ };
175
+ type WeaveStoreAzureWebPubSubSyncClientConnectionStatusKeys = keyof typeof WEAVE_STORE_AZURE_WEB_PUBSUB_CONNECTION_STATUS;
176
+ type WeaveStoreAzureWebPubSubSyncClientConnectionStatus = (typeof WEAVE_STORE_AZURE_WEB_PUBSUB_CONNECTION_STATUS)[WeaveStoreAzureWebPubSubSyncClientConnectionStatusKeys];
177
+ declare enum MessageType {
178
+ System = "system",
179
+ JoinGroup = "joinGroup",
180
+ SendToGroup = "sendToGroup",
181
+ }
182
+ declare enum MessageDataType {
183
+ Init = "init",
184
+ Sync = "sync",
185
+ Awareness = "awareness",
186
+ }
187
+ interface MessageData {
188
+ payloadId?: string;
189
+ index?: number;
190
+ type?: "chunk" | "end";
191
+ totalChunks?: number;
192
+ group: string;
193
+ t: string;
194
+ f: string;
195
+ c: string;
196
+ }
197
+ interface Message {
198
+ type: string;
199
+ fromUserId: string;
200
+ from: string;
201
+ group: string;
202
+ data: MessageData;
203
+ }
204
+ type MessageHandler = (encoder: Encoder, decoder: Decoder, client: WeaveStoreAzureWebPubSubSyncClient, clientId: string, emitSynced: boolean, messageType: number) => void;
205
+
206
+ //#endregion
207
+ //#region src/server/event-handler/enum/mqtt-error-codes/mqtt-disconnect-reason-code.d.ts
208
+ /**
209
+ * MQTT 5.0 Disconnect Reason Codes.
210
+ */
211
+ declare enum MqttDisconnectReasonCode {
212
+ /**
213
+ * 0x00 - Normal disconnection
214
+ * Sent by: Client or Server
215
+ * Description: Close the connection normally. Do not send the Will Message.
216
+ */
217
+ NormalDisconnection = 0,
218
+ /**
219
+ * 0x04 - Disconnect with Will Message
220
+ * Sent by: Client
221
+ * Description: The Client wishes to disconnect but requires that the Server also publishes its Will Message.
222
+ */
223
+ DisconnectWithWillMessage = 4,
224
+ /**
225
+ * 0x80 - Unspecified error
226
+ * Sent by: Client or Server
227
+ * Description: The Connection is closed but the sender either does not wish to reveal the reason, or none of the other Reason Codes apply.
228
+ */
229
+ UnspecifiedError = 128,
230
+ /**
231
+ * 0x81 - Malformed Packet
232
+ * Sent by: Client or Server
233
+ * Description: The received packet does not conform to this specification.
234
+ */
235
+ MalformedPacket = 129,
236
+ /**
237
+ * 0x82 - Protocol Error
238
+ * Sent by: Client or Server
239
+ * Description: An unexpected or out of order packet was received.
240
+ */
241
+ ProtocolError = 130,
242
+ /**
243
+ * 0x83 - Implementation specific error
244
+ * Sent by: Client or Server
245
+ * Description: The packet received is valid but cannot be processed by this implementation.
246
+ */
247
+ ImplementationSpecificError = 131,
248
+ /**
249
+ * 0x87 - Not authorized
250
+ * Sent by: Server
251
+ * Description: The request is not authorized.
252
+ */
253
+ NotAuthorized = 135,
254
+ /**
255
+ * 0x89 - Server busy
256
+ * Sent by: Server
257
+ * Description: The Server is busy and cannot continue processing requests from this Client.
258
+ */
259
+ ServerBusy = 137,
260
+ /**
261
+ * 0x8B - Server shutting down
262
+ * Sent by: Server
263
+ * Description: The Server is shutting down.
264
+ */
265
+ ServerShuttingDown = 139,
266
+ /**
267
+ * 0x8D - Keep Alive timeout
268
+ * Sent by: Server
269
+ * Description: The Connection is closed because no packet has been received for 1.5 times the Keepalive time.
270
+ */
271
+ KeepAliveTimeout = 141,
272
+ /**
273
+ * 0x8E - Session taken over
274
+ * Sent by: Server
275
+ * Description: Another Connection using the same ClientID has connected causing this Connection to be closed.
276
+ */
277
+ SessionTakenOver = 142,
278
+ /**
279
+ * 0x8F - Topic Filter invalid
280
+ * Sent by: Server
281
+ * Description: The Topic Filter is correctly formed, but is not accepted by this Server.
282
+ */
283
+ TopicFilterInvalid = 143,
284
+ /**
285
+ * 0x90 - Topic Name invalid
286
+ * Sent by: Client or Server
287
+ * Description: The Topic Name is correctly formed, but is not accepted by this Client or Server.
288
+ */
289
+ TopicNameInvalid = 144,
290
+ /**
291
+ * 0x93 - Receive Maximum exceeded
292
+ * Sent by: Client or Server
293
+ * Description: The Client or Server has received more than Receive Maximum publication for which it has not sent PUBACK or PUBCOMP.
294
+ */
295
+ ReceiveMaximumExceeded = 147,
296
+ /**
297
+ * 0x94 - Topic Alias invalid
298
+ * Sent by: Client or Server
299
+ * Description: The Client or Server has received a PUBLISH packet containing a Topic Alias which is greater than the Maximum Topic Alias it sent in the CONNECT or CONNACK packet.
300
+ */
301
+ TopicAliasInvalid = 148,
302
+ /**
303
+ * 0x95 - Packet too large
304
+ * Sent by: Client or Server
305
+ * Description: The packet size is greater than Maximum Packet Size for this Client or Server.
306
+ */
307
+ PacketTooLarge = 149,
308
+ /**
309
+ * 0x96 - Message rate too high
310
+ * Sent by: Client or Server
311
+ * Description: The received data rate is too high.
312
+ */
313
+ MessageRateTooHigh = 150,
314
+ /**
315
+ * 0x97 - Quota exceeded
316
+ * Sent by: Client or Server
317
+ * Description: An implementation or administrative imposed limit has been exceeded.
318
+ */
319
+ QuotaExceeded = 151,
320
+ /**
321
+ * 0x98 - Administrative action
322
+ * Sent by: Client or Server
323
+ * Description: The Connection is closed due to an administrative action.
324
+ */
325
+ AdministrativeAction = 152,
326
+ /**
327
+ * 0x99 - Payload format invalid
328
+ * Sent by: Client or Server
329
+ * Description: The payload format does not match the one specified by the Payload Format Indicator.
330
+ */
331
+ PayloadFormatInvalid = 153,
332
+ /**
333
+ * 0x9A - Retain not supported
334
+ * Sent by: Server
335
+ * Description: The Server does not support retained messages.
336
+ */
337
+ RetainNotSupported = 154,
338
+ /**
339
+ * 0x9B - QoS not supported
340
+ * Sent by: Server
341
+ * Description: The Client specified a QoS greater than the QoS specified in a Maximum QoS in the CONNACK.
342
+ */
343
+ QosNotSupported = 155,
344
+ /**
345
+ * 0x9C - Use another server
346
+ * Sent by: Server
347
+ * Description: The Client should temporarily change its Server.
348
+ */
349
+ UseAnotherServer = 156,
350
+ /**
351
+ * 0x9D - Server moved
352
+ * Sent by: Server
353
+ * Description: The Server is moved and the Client should permanently change its server location.
354
+ */
355
+ ServerMoved = 157,
356
+ /**
357
+ * 0x9E - Shared Subscriptions not supported
358
+ * Sent by: Server
359
+ * Description: The Server does not support Shared Subscriptions.
360
+ */
361
+ SharedSubscriptionsNotSupported = 158,
362
+ /**
363
+ * 0x9F - Connection rate exceeded
364
+ * Sent by: Server
365
+ * Description: This connection is closed because the connection rate is too high.
366
+ */
367
+ ConnectionRateExceeded = 159,
368
+ /**
369
+ * 0xA0 - Maximum connect time
370
+ * Sent by: Server
371
+ * Description: The maximum connection time authorized for this connection has been exceeded.
372
+ */
373
+ MaximumConnectTime = 160,
374
+ /**
375
+ * 0xA1 - Subscription Identifiers not supported
376
+ * Sent by: Server
377
+ * Description: The Server does not support Subscription Identifiers; the subscription is not accepted.
378
+ */
379
+ SubscriptionIdentifiersNotSupported = 161,
380
+ /**
381
+ * 0xA2 - Wildcard Subscriptions not supported
382
+ * Sent by: Server
383
+ * Description: The Server does not support Wildcard Subscriptions; the subscription is not accepted.
384
+ */
385
+ WildcardSubscriptionsNotSupported = 162,
386
+ } //#endregion
387
+ //#region src/server/event-handler/enum/mqtt-error-codes/mqtt-v311-connect-return-code.d.ts
388
+ /**
389
+ * MQTT 3.1.1 Connect Return Codes.
390
+ */
391
+ declare enum MqttV311ConnectReturnCode {
392
+ /**
393
+ * 0x01: Connection refused, unacceptable protocol version
394
+ * The Server does not support the level of the MQTT protocol requested by the Client.
395
+ */
396
+ UnacceptableProtocolVersion = 1,
397
+ /**
398
+ * 0x02: Connection refused, identifier rejected
399
+ * The Client identifier is correct UTF-8 but not allowed by the Server.
400
+ */
401
+ IdentifierRejected = 2,
402
+ /**
403
+ * 0x03: Connection refused, server unavailable
404
+ * The Network Connection has been made but the MQTT service is unavailable.
405
+ */
406
+ ServerUnavailable = 3,
407
+ /**
408
+ * 0x04: Connection refused, bad user name or password
409
+ * The data in the user name or password is malformed.
410
+ */
411
+ BadUsernameOrPassword = 4,
412
+ /**
413
+ * 0x05: Connection refused, not authorized
414
+ * The Client is not authorized to connect.
415
+ */
416
+ NotAuthorized = 5,
417
+ }
418
+
419
+ //#endregion
420
+ //#region src/server/event-handler/enum/mqtt-error-codes/mqtt-v500-connect-reason-code.d.ts
421
+ /**
422
+ * MQTT Connect Reason Codes
423
+ * These codes represent the reasons for the outcome of an MQTT CONNECT packet as per MQTT 5.0 specification.
424
+ */
425
+ declare enum MqttV500ConnectReasonCode {
426
+ /**
427
+ * 0x80 - Unspecified error
428
+ * Description: The Server does not wish to reveal the reason for the failure, or none of the other Reason Codes apply.
429
+ */
430
+ UnspecifiedError = 128,
431
+ /**
432
+ * 0x81 - Malformed Packet
433
+ * Description: Data within the CONNECT packet could not be correctly parsed.
434
+ */
435
+ MalformedPacket = 129,
436
+ /**
437
+ * 0x82 - Protocol Error
438
+ * Description: Data in the CONNECT packet does not conform to this specification.
439
+ */
440
+ ProtocolError = 130,
441
+ /**
442
+ * 0x83 - Implementation specific error
443
+ * Description: The CONNECT is valid but is not accepted by this Server.
444
+ */
445
+ ImplementationSpecificError = 131,
446
+ /**
447
+ * 0x84 - Unsupported Protocol Version
448
+ * Description: The Server does not support the version of the MQTT protocol requested by the Client.
449
+ */
450
+ UnsupportedProtocolVersion = 132,
451
+ /**
452
+ * 0x85 - Client Identifier not valid
453
+ * Description: The Client Identifier is a valid string but is not allowed by the Server.
454
+ */
455
+ ClientIdentifierNotValid = 133,
456
+ /**
457
+ * 0x86 - Bad User Name or Password
458
+ * Description: The Server does not accept the User Name or Password specified by the Client.
459
+ */
460
+ BadUserNameOrPassword = 134,
461
+ /**
462
+ * 0x87 - Not authorized
463
+ * Description: The Client is not authorized to connect.
464
+ */
465
+ NotAuthorized = 135,
466
+ /**
467
+ * 0x88 - Server unavailable
468
+ * Description: The MQTT Server is not available.
469
+ */
470
+ ServerUnavailable = 136,
471
+ /**
472
+ * 0x89 - Server busy
473
+ * Description: The Server is busy. Try again later.
474
+ */
475
+ ServerBusy = 137,
476
+ /**
477
+ * 0x8A - Banned
478
+ * Description: This Client has been banned by administrative action. Contact the server administrator.
479
+ */
480
+ Banned = 138,
481
+ /**
482
+ * 0x8C - Bad authentication method
483
+ * Description: The authentication method is not supported or does not match the authentication method currently in use.
484
+ */
485
+ BadAuthenticationMethod = 140,
486
+ /**
487
+ * 0x90 - Topic Name invalid
488
+ * Description: The Will Topic Name is not malformed, but is not accepted by this Server.
489
+ */
490
+ TopicNameInvalid = 144,
491
+ /**
492
+ * 0x95 - Packet too large
493
+ * Description: The CONNECT packet exceeded the maximum permissible size.
494
+ */
495
+ PacketTooLarge = 149,
496
+ /**
497
+ * 0x97 - Quota exceeded
498
+ * Description: An implementation or administrative imposed limit has been exceeded.
499
+ */
500
+ QuotaExceeded = 151,
501
+ /**
502
+ * 0x99 - Payload format invalid
503
+ * Description: The Will Payload does not match the specified Payload Format Indicator.
504
+ */
505
+ PayloadFormatInvalid = 153,
506
+ /**
507
+ * 0x9A - Retain not supported
508
+ * Description: The Server does not support retained messages, and Will Retain was set to 1.
509
+ */
510
+ RetainNotSupported = 154,
511
+ /**
512
+ * 0x9B - QoS not supported
513
+ * Description: The Server does not support the QoS set in Will QoS.
514
+ */
515
+ QosNotSupported = 155,
516
+ /**
517
+ * 0x9C - Use another server
518
+ * Description: The Client should temporarily use another server.
519
+ */
520
+ UseAnotherServer = 156,
521
+ /**
522
+ * 0x9D - Server moved
523
+ * Description: The Client should permanently use another server.
524
+ */
525
+ ServerMoved = 157,
526
+ /**
527
+ * 0x9F - Connection rate exceeded
528
+ * Description: The connection rate limit has been exceeded.
529
+ */
530
+ ConnectionRateExceeded = 159,
531
+ }
532
+
533
+ //#endregion
534
+ //#region src/server/event-handler/cloud-events-protocols.d.ts
535
+ /**
536
+ * Response of the connect event.
537
+ */
538
+ interface ConnectResponse {
539
+ /**
540
+ * Set the groups the connection would like to join.
541
+ */
542
+ groups?: string[];
543
+ /**
544
+ * Set the roles the connection belongs to.
545
+ */
546
+ roles?: string[];
547
+ /**
548
+ * Set the userId for the connection.
549
+ */
550
+ userId?: string;
551
+ /**
552
+ * Set the subprotocol for the connection to complete WebSocket handshake.
553
+ */
554
+ subprotocol?: string;
555
+ }
556
+ /**
557
+ * Success respones of the connect event.
558
+ */
559
+ interface MqttConnectResponse extends ConnectResponse {
560
+ /**
561
+ * The MQTT specific properties in a successful MQTT connection event response.
562
+ */
563
+ mqtt?: MqttConnectResponseProperties;
564
+ }
565
+ /**
566
+ * Response of a failed connect event.
567
+ */
568
+ interface ConnectErrorResponse {
569
+ /**
570
+ * The error code.
571
+ */
572
+ code: 400 | 401 | 500;
573
+ /**
574
+ * The error detail.
575
+ */
576
+ detail?: string;
577
+ }
578
+ /**
579
+ * Response of an MQTT connection failure.
580
+ */
581
+ interface MqttConnectErrorResponse {
582
+ /**
583
+ * The properties of the MQTT connection failure response.
584
+ */
585
+ mqtt: MqttConnectErrorResponseProperties;
586
+ }
587
+ /**
588
+ * The properties of an MQTT connection failure response.
589
+ */
590
+ interface MqttConnectErrorResponseProperties {
591
+ /**
592
+ * The MQTT connect return code.
593
+ */
594
+ code: MqttV311ConnectReturnCode | MqttV500ConnectReasonCode;
595
+ /**
596
+ * The reason string for the connection failure.
597
+ */
598
+ reason?: string;
599
+ /**
600
+ * The user properties in the response.
601
+ */
602
+ userProperties?: MqttUserProperty[];
603
+ }
604
+ /**
605
+ * The protocol of Web PubSub Client.
606
+ */
607
+ type WebPubSubClientProtocol = "default" | "mqtt";
608
+ /**
609
+ * The connection context representing the client WebSocket connection.
610
+ */
611
+ interface ConnectionContext {
612
+ /**
613
+ * The unique identifier generated by the service of the network connection.
614
+ */
615
+ signature: string;
616
+ /**
617
+ * The hub the connection belongs to.
618
+ */
619
+ hub: string;
620
+ /**
621
+ * The Id of the connection.
622
+ */
623
+ connectionId: string;
624
+ /**
625
+ * The event name of this CloudEvents request.
626
+ */
627
+ eventName: string;
628
+ /**
629
+ * The origin this CloudEvents request comes from.
630
+ */
631
+ origin: string;
632
+ /**
633
+ * The user id of the connection.
634
+ */
635
+ userId?: string;
636
+ /**
637
+ * The subprotocol of this connection.
638
+ */
639
+ subprotocol?: string;
640
+ /**
641
+ * Get the additional states for the connection, such states are perserved throughout the lifetime of the connection.
642
+ */
643
+ states: Record<string, any>;
644
+ /**
645
+ * The type of client protocol.
646
+ */
647
+ clientProtocol: WebPubSubClientProtocol;
648
+ /**
649
+ * The MQTT properties that the client WebSocket connection has when it connects (For MQTT connection only).
650
+ */
651
+ mqtt?: MqttConnectionContextProperties;
652
+ }
653
+ /**
654
+ * The connection context properties representing the MQTT client WebSocket connection.
655
+ */
656
+ interface MqttConnectionContextProperties {
657
+ /**
658
+ * The unique identifier generated by the service of the network connection.
659
+ */
660
+ physicalConnectionId: string;
661
+ /**
662
+ * The unique identifier generated by the service of the MQTT session.
663
+ */
664
+ sessionId?: string;
665
+ }
666
+ /**
667
+ * Request for the connect event.
668
+ */
669
+ interface ConnectRequest {
670
+ /**
671
+ * The context of current CloudEvents request.
672
+ */
673
+ context: ConnectionContext;
674
+ /**
675
+ * The claims that the client WebSocket connection has when it connects.
676
+ */
677
+ claims?: Record<string, string[]>;
678
+ /**
679
+ * The query that the client WebSocket connection has when it connects.
680
+ * @deprecated Please use queries instead.
681
+ */
682
+ query?: Record<string, string[]>;
683
+ /**
684
+ * The queries that the client WebSocket connection has when it connects.
685
+ */
686
+ queries?: Record<string, string[]>;
687
+ /**
688
+ * The headers that the client WebSocket connection has when it connects.
689
+ */
690
+ headers?: Record<string, string[]>;
691
+ /**
692
+ * The subprotocols that the client WebSocket connection uses to do handshake.
693
+ */
694
+ subprotocols?: string[];
695
+ /**
696
+ * The client certificate info that the client WebSocket connection uses to connect.
697
+ */
698
+ clientCertificates?: Certificate[];
699
+ }
700
+ /**
701
+ * Request for the MQTT connect event.
702
+ */
703
+ interface MqttConnectRequest extends ConnectRequest {
704
+ /**
705
+ * The MQTT specific properties in the MQTT connect event request.
706
+ */
707
+ mqtt: MqttConnectProperties;
708
+ }
709
+ /**
710
+ * The properties of the MQTT CONNECT packet.
711
+ */
712
+ interface MqttConnectProperties {
713
+ /**
714
+ * MQTT protocol version.
715
+ */
716
+ protocolVersion: number;
717
+ /**
718
+ * The username field in the MQTT CONNECT packet.
719
+ */
720
+ username?: string;
721
+ /**
722
+ * The password field in the MQTT CONNECT packet.
723
+ */
724
+ password?: string;
725
+ /**
726
+ * The user properties in the MQTT CONNECT packet.
727
+ */
728
+ userProperties?: MqttUserProperty[];
729
+ }
730
+ /**
731
+ * The properties of a successful MQTT connection event response
732
+ */
733
+ interface MqttConnectResponseProperties {
734
+ /**
735
+ * Additional diagnostic or other information provided by upstream server
736
+ * Now only MQTT 5.0 supports user properties
737
+ */
738
+ userProperties?: MqttUserProperty[];
739
+ }
740
+ /**
741
+ * The properties of a user in MQTT.
742
+ */
743
+ interface MqttUserProperty {
744
+ /**
745
+ * The name of the property.
746
+ */
747
+ name: string;
748
+ /**
749
+ * The value of the property.
750
+ */
751
+ value: string;
752
+ }
753
+ /**
754
+ * The client certificate.
755
+ */
756
+ interface Certificate {
757
+ /**
758
+ * The thumbprint of the certificate.
759
+ */
760
+ thumbprint: string;
761
+ }
762
+ /**
763
+ * Request for the connected event.
764
+ */
765
+ interface ConnectedRequest {
766
+ /**
767
+ * The context of current CloudEvents request.
768
+ */
769
+ context: ConnectionContext;
770
+ }
771
+ /**
772
+ * Request for the user event.
773
+ */
774
+ type UserEventRequest = {
775
+ /**
776
+ * The context of current CloudEvents request.
777
+ */
778
+ context: ConnectionContext;
779
+ /**
780
+ * The content data.
781
+ */
782
+ data: string;
783
+ /**
784
+ * The type of the data.
785
+ */
786
+ dataType: "text";
787
+ } | {
788
+ /**
789
+ * The context of current CloudEvents request.
790
+ */
791
+ context: ConnectionContext;
792
+ /**
793
+ * The content data, when data type is `json`, the data is the result of JSON.parse, so the type of the data depends on user scenarios
794
+ */
795
+ data: unknown;
796
+ /**
797
+ * The type of the data.
798
+ */
799
+ dataType: "json";
800
+ } | {
801
+ /**
802
+ * The context of current CloudEvents request.
803
+ */
804
+ context: ConnectionContext;
805
+ /**
806
+ * The content data.
807
+ */
808
+ data: ArrayBuffer;
809
+ /**
810
+ * The type of the data.
811
+ */
812
+ dataType: "binary";
813
+ };
814
+ /**
815
+ * Request for the disconnected event.
816
+ */
817
+ interface DisconnectedRequest {
818
+ /**
819
+ * The context of current CloudEvents request.
820
+ */
821
+ context: ConnectionContext;
822
+ /**
823
+ * The reason that the connection disconnects.
824
+ */
825
+ reason?: string;
826
+ }
827
+ /**
828
+ * Request for the disconnected event.
829
+ */
830
+ interface MqttDisconnectedRequest extends DisconnectedRequest {
831
+ /**
832
+ * The MQTT specific properties in the MQTT disconnected event request.
833
+ */
834
+ mqtt: MqttDisconnectedProperties;
835
+ }
836
+ /**
837
+ * The properties of an MQTT disconnected event.
838
+ */
839
+ interface MqttDisconnectedProperties {
840
+ /**
841
+ * The MQTT disconnect packet.
842
+ */
843
+ disconnectPacket: MqttDisconnectPacket;
844
+ /**
845
+ * Whether the disconnection is initiated by the client.
846
+ */
847
+ initiatedByClient: boolean;
848
+ }
849
+ /**
850
+ * The properties of the MQTT DISCONNECT packet.
851
+ */
852
+ interface MqttDisconnectPacket {
853
+ /**
854
+ * The MQTT disconnect return code.
855
+ */
856
+ code: MqttDisconnectReasonCode;
857
+ /**
858
+ * The user properties in the MQTT disconnect packet.
859
+ */
860
+ userProperties?: MqttUserProperty[];
861
+ }
862
+ /**
863
+ * The handler to set connect event response
864
+ */
865
+ interface ConnectResponseHandler {
866
+ /**
867
+ * Set the state of the connection
868
+ * @param name - The name of the state
869
+ * @param value - The value of the state
870
+ */
871
+ setState(name: string, value: unknown): void;
872
+ /**
873
+ * Return success response to the service.
874
+ * @param response - The response for the connect event.
875
+ */
876
+ success(response?: ConnectResponse | MqttConnectResponse): void;
877
+ /**
878
+ * Return failed response and the service will reject the client WebSocket connection.
879
+ * @param code - Code can be 400 user error, 401 unauthorized and 500 server error.
880
+ * @param detail - The detail of the error.
881
+ */
882
+ fail(code: 400 | 401 | 500, detail?: string): void;
883
+ /**
884
+ * Return failed response with MQTT response properties and the service will reject the client WebSocket connection.
885
+ * @param response - The response for the connect event which contains either default WebPubSub or MQTT response properties.
886
+ */
887
+ failWith(response: ConnectErrorResponse | MqttConnectErrorResponse): void;
888
+ }
889
+ /**
890
+ * The handler to set user event response
891
+ */
892
+ interface UserEventResponseHandler {
893
+ /**
894
+ * Set the state of the connection
895
+ * @param name - The name of the state
896
+ * @param value - The value of the state
897
+ */
898
+ setState(name: string, value: unknown): void;
899
+ /**
900
+ * Return success response with data to be delivered to the client WebSocket connection.
901
+ * @param data - The payload data to be returned to the client. Stringify the message if it is a JSON object.
902
+ * @param dataType - The type of the payload data.
903
+ */
904
+ success(data?: string | ArrayBuffer, dataType?: "binary" | "text" | "json"): void;
905
+ /**
906
+ * Return failed response and the service will close the client WebSocket connection.
907
+ * @param code - Code can be 400 user error, 401 unauthorized and 500 server error.
908
+ * @param detail - The detail of the error.
909
+ */
910
+ fail(code: 400 | 401 | 500, detail?: string): void;
911
+ }
912
+ /**
913
+ * The options for the CloudEvents handler.
914
+ */
915
+ interface WebPubSubEventHandlerOptions {
916
+ /**
917
+ * Custom serving path for the path of the CloudEvents handler.
918
+ */
919
+ path?: string;
920
+ /**
921
+ * Handle 'connect' event, the service waits for the response to proceed.
922
+ */
923
+ handleConnect?: (connectRequest: ConnectRequest, connectResponse: ConnectResponseHandler) => void;
924
+ /**
925
+ * Handle user events, the service waits for the response to proceed.
926
+ */
927
+ handleUserEvent?: (userEventRequest: UserEventRequest, userEventResponse: UserEventResponseHandler) => void;
928
+ /**
929
+ * Event trigger for "connected" unblocking event. This is an unblocking event and the service does not wait for the response.
930
+ */
931
+ onConnected?: (connectedRequest: ConnectedRequest) => void;
932
+ /**
933
+ *
934
+ * Event triggers for "disconnected" unblocking event. This is an unblocking event and the service does not wait for the response.
935
+ */
936
+ onDisconnected?: (disconnectedRequest: DisconnectedRequest) => void;
937
+ /**
938
+ * If not specified, by default allow all the endpoints, otherwise only allow specified endpoints
939
+ */
940
+ allowedEndpoints?: string[];
941
+ } //#endregion
942
+ //#region src/server/event-handler/web-pubsub-event-handler.d.ts
943
+ /**
944
+ * The handler to handle incoming CloudEvents messages
945
+ */
946
+ declare class WebPubSubEventHandler {
947
+ private hub;
948
+ /**
949
+ * The path this CloudEvents handler listens to
950
+ */
951
+ readonly path: string;
952
+ private _cloudEventsHandler;
953
+ /**
954
+ * Creates an instance of a WebPubSubEventHandler for handling incoming CloudEvents messages.
955
+ *
956
+ * Example usage:
957
+ * ```ts snippet:WebPubSubEventHandlerHandleMessages
958
+ * import { WebPubSubEventHandler } from "@azure/web-pubsub-express";
959
+ *
960
+ * const endpoint = "https://xxxx.webpubsubdev.azure.com";
961
+ * const handler = new WebPubSubEventHandler("chat", {
962
+ * handleConnect: (req, res) => {
963
+ * console.log(JSON.stringify(req));
964
+ * return {};
965
+ * },
966
+ * onConnected: (req) => {
967
+ * console.log(JSON.stringify(req));
968
+ * },
969
+ * handleUserEvent: (req, res) => {
970
+ * console.log(JSON.stringify(req));
971
+ * res.success("Hey " + req.data, req.dataType);
972
+ * },
973
+ * allowedEndpoints: [endpoint],
974
+ * });
975
+ * ```
976
+ *
977
+ * @param hub - The name of the hub to listen to
978
+ * @param options - Options to configure the event handler
979
+ */
980
+ constructor(hub: string, options?: WebPubSubEventHandlerOptions);
981
+ /**
982
+ * Get the middleware to process the CloudEvents requests for Koa.js
983
+ */
984
+ getKoaMiddleware(): (ctx: koa.Context, next: koa.Next) => Promise<void>;
985
+ /**
986
+ * Get the middleware to process the CloudEvents requests for Express.js
987
+ */
988
+ getExpressJsMiddleware(): express.RequestHandler;
989
+ }
990
+
991
+ //#endregion
992
+ //#region src/server/azure-web-pubsub-host.d.ts
993
+ declare class WeaveStoreAzureWebPubSubSyncHost {
994
+ private readonly server;
995
+ private readonly syncHandler;
996
+ doc: Y.Doc;
997
+ topic: string;
998
+ topicAwarenessChannel: string;
999
+ private _client;
1000
+ private _conn;
1001
+ private _reconnectAttempts;
1002
+ private _forceClose;
1003
+ private _awareness;
1004
+ private _chunkedMessages;
1005
+ private _updateHandler;
1006
+ private _awarenessUpdateHandler;
1007
+ constructor(server: WeaveAzureWebPubsubServer, syncHandler: WeaveAzureWebPubsubSyncHandler, client: WebPubSubServiceClient, topic: string, doc: Y.Doc);
1008
+ get awareness(): awarenessProtocol.Awareness;
1009
+ sendInitAwarenessInfo(origin: string): void;
1010
+ createWebSocket(): Promise<void>;
1011
+ start(): Promise<void>;
1012
+ stop(): Promise<void>;
1013
+ simulateWebsocketError(): void;
1014
+ private safeSend;
1015
+ private chunkString;
1016
+ private chunkedBroadcast;
1017
+ private broadcast;
1018
+ private chunkedSend;
1019
+ private send;
1020
+ private onClientInit;
1021
+ private onClientSync;
1022
+ private onAwareness;
1023
+ private negotiate;
1024
+ }
1025
+
1026
+ //#endregion
1027
+ //#region src/server/azure-web-pubsub-sync-handler.d.ts
1028
+ declare class WeaveAzureWebPubsubSyncHandler extends WebPubSubEventHandler {
1029
+ private _client;
1030
+ private readonly _rooms;
1031
+ private readonly _roomsSyncHost;
1032
+ private _store_persistence;
1033
+ private readonly syncOptions?;
1034
+ private initialState;
1035
+ private readonly server;
1036
+ private readonly roomsLastState;
1037
+ constructor(hub: string, server: WeaveAzureWebPubsubServer, client: WebPubSubServiceClient, initialState: FetchInitialState, syncHandlerOptions?: WeaveAzureWebPubsubSyncHandlerOptions, eventHandlerOptions?: WebPubSubEventHandlerOptions);
1038
+ private getNewYDoc;
1039
+ private setupRoomInstance;
1040
+ isPersistingOnInterval(): boolean;
1041
+ private setupRoomInstancePersistence;
1042
+ persistRoomTask(roomId: string): Promise<void>;
1043
+ private handleConnectionDisconnection;
1044
+ destroyRoomInstance(roomId: string): Promise<void>;
1045
+ private getHostConnection;
1046
+ getRoomsLoaded(): string[];
1047
+ getRoomSyncHost(roomId: string): WeaveStoreAzureWebPubSubSyncHost | undefined;
1048
+ getRoomDocument(roomId: string): Promise<Y.Doc>;
1049
+ clientConnect(roomId: string, connectionOptions?: WeaveStoreAzureWebPubSubSyncHostClientConnectOptions): Promise<string>;
1050
+ }
1051
+
1052
+ //#endregion
1053
+ //#region src/server/azure-web-pubsub-server.d.ts
1054
+ type WeaveAzureWebPubsubServerParams = {
1055
+ initialState?: FetchInitialState;
1056
+ pubSubConfig: WeaveStoreAzureWebPubsubConfig;
1057
+ eventsHandlerConfig?: WebPubSubEventHandlerOptions;
1058
+ persistRoom?: PersistRoom;
1059
+ fetchRoom?: FetchRoom;
1060
+ };
1061
+ declare class WeaveAzureWebPubsubServer extends Emittery {
1062
+ private syncClient;
1063
+ private syncHandler;
1064
+ persistRoom: PersistRoom | undefined;
1065
+ fetchRoom: FetchRoom | undefined;
1066
+ constructor({
1067
+ pubSubConfig,
1068
+ eventsHandlerConfig,
1069
+ initialState,
1070
+ persistRoom,
1071
+ fetchRoom
1072
+ }: WeaveAzureWebPubsubServerParams);
1073
+ getKoaMiddleware(): koa.Middleware;
1074
+ getExpressJsMiddleware(): RequestHandler;
1075
+ getSyncHandler(): WeaveAzureWebPubsubSyncHandler;
1076
+ emitEvent<T>(event: string, payload?: T): void;
1077
+ addEventListener<T>(event: string, callback: (payload: T) => void): void;
1078
+ removeEventListener<T>(event: string, callback: (payload: T) => void): void;
1079
+ getRoomDocument(roomId: string): Promise<Y.Doc>;
1080
+ clientConnect(roomId: string, connectionOptions?: WeaveStoreAzureWebPubSubSyncHostClientConnectOptions): Promise<string | null>;
1081
+ }
1082
+
1083
+ //#endregion
1084
+ export { Certificate, ConnectErrorResponse, ConnectRequest, ConnectResponse, ConnectResponseHandler, ConnectedRequest, ConnectionContext, DisconnectedRequest, FetchClient, FetchInitialState, FetchRoom, Message, MessageData, MessageDataType, MessageHandler, MessageType, MqttConnectErrorResponse, MqttConnectErrorResponseProperties, MqttConnectProperties, MqttConnectRequest, MqttConnectResponse, MqttConnectResponseProperties, MqttConnectionContextProperties, MqttDisconnectPacket, MqttDisconnectReasonCode, MqttDisconnectedProperties, MqttDisconnectedRequest, MqttUserProperty, MqttV311ConnectReturnCode, MqttV500ConnectReasonCode, PersistRoom, UserEventRequest, UserEventResponseHandler, WEAVE_STORE_AZURE_WEB_PUBSUB, WEAVE_STORE_AZURE_WEB_PUBSUB_CONNECTION_STATUS, WEAVE_STORE_HORIZONTAL_SYNC_HANDLER_CLIENT_TYPE, WeaveAzureWebPubsubServer, WeaveAzureWebPubsubSyncHandlerOptions, WeaveStoreAzureWebPubSubSyncClientConnectionStatus, WeaveStoreAzureWebPubSubSyncClientConnectionStatusKeys, WeaveStoreAzureWebPubSubSyncHost, WeaveStoreAzureWebPubSubSyncHostClientConnectOptions, WeaveStoreAzureWebPubsubConfig, WeaveStoreAzureWebPubsubEvents, WeaveStoreAzureWebPubsubOnConnectEvent, WeaveStoreAzureWebPubsubOnConnectedEvent, WeaveStoreAzureWebPubsubOnDisconnectedEvent, WeaveStoreAzureWebPubsubOnStoreFetchConnectionUrlEvent, WeaveStoreAzureWebPubsubOnWebsocketCloseEvent, WeaveStoreAzureWebPubsubOnWebsocketErrorEvent, WeaveStoreAzureWebPubsubOnWebsocketJoinGroupEvent, WeaveStoreAzureWebPubsubOnWebsocketMessageEvent, WeaveStoreAzureWebPubsubOnWebsocketOnTokenRefreshEvent, WeaveStoreAzureWebPubsubOnWebsocketOpenEvent, WeaveStoreAzureWebPubsubOptions, WebPubSubClientProtocol, WebPubSubEventHandler, WebPubSubEventHandlerOptions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inditextech/weave-store-azure-web-pubsub",
3
- "version": "3.0.0-SNAPSHOT.56.1",
3
+ "version": "3.0.0",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Jesus Manuel Piñeiro Cid <jesusmpc@inditex.com>",
@@ -57,8 +57,8 @@
57
57
  "dependencies": {
58
58
  "@azure/identity": "4.10.2",
59
59
  "@azure/web-pubsub": "1.2.0",
60
- "@inditextech/weave-types": "3.0.0-SNAPSHOT.56.1",
61
- "@inditextech/weave-sdk": "3.0.0-SNAPSHOT.56.1",
60
+ "@inditextech/weave-types": "3.0.0",
61
+ "@inditextech/weave-sdk": "3.0.0",
62
62
  "@syncedstore/core": "0.6.0",
63
63
  "buffer": "6.0.3",
64
64
  "reconnecting-websocket": "4.4.0",