@azure/web-pubsub-express 1.0.0-beta.1 → 1.0.1-alpha.20211215.2

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.
@@ -48,6 +48,10 @@ export declare interface ConnectionContext {
48
48
  * The subprotocol of this connection.
49
49
  */
50
50
  subprotocol?: string;
51
+ /**
52
+ * Get the additional states for the connection, such states are perserved throughout the lifetime of the connection.
53
+ */
54
+ states: Record<string, any>;
51
55
  }
52
56
 
53
57
  /**
@@ -66,6 +70,10 @@ export declare interface ConnectRequest {
66
70
  * The queries that the client WebSocket connection has when it connects.
67
71
  */
68
72
  queries?: Record<string, string[]>;
73
+ /**
74
+ * The headers that the client WebSocket connection has when it connects.
75
+ */
76
+ headers?: Record<string, string[]>;
69
77
  /**
70
78
  * The subprotocols that the client WebSocket connection uses to do handshake.
71
79
  */
@@ -102,15 +110,21 @@ export declare interface ConnectResponse {
102
110
  * The handler to set connect event response
103
111
  */
104
112
  export declare interface ConnectResponseHandler {
113
+ /**
114
+ * Set the state of the connection
115
+ * @param name - The name of the state
116
+ * @param value - The value of the state
117
+ */
118
+ setState(name: string, value: unknown): void;
105
119
  /**
106
120
  * Return success response to the service.
107
- * @param response The response for the connect event.
121
+ * @param response - The response for the connect event.
108
122
  */
109
123
  success(response?: ConnectResponse): void;
110
124
  /**
111
125
  * Return failed response and the service will reject the client WebSocket connection.
112
- * @param code Code can be 400 user error, 401 unauthorized and 500 server error.
113
- * @param detail The detail of the error.
126
+ * @param code - Code can be 400 user error, 401 unauthorized and 500 server error.
127
+ * @param detail - The detail of the error.
114
128
  */
115
129
  fail(code: 400 | 401 | 500, detail?: string): void;
116
130
  }
@@ -164,16 +178,22 @@ export declare type UserEventRequest = {
164
178
  * The handler to set user event response
165
179
  */
166
180
  export declare interface UserEventResponseHandler {
181
+ /**
182
+ * Set the state of the connection
183
+ * @param name - The name of the state
184
+ * @param value - The value of the state
185
+ */
186
+ setState(name: string, value: unknown): void;
167
187
  /**
168
188
  * Return success response with data to be delivered to the client WebSocket connection.
169
- * @param data The payload data to be returned to the client.
170
- * @param dataType The type of the payload data.
189
+ * @param data - The payload data to be returned to the client.
190
+ * @param dataType - The type of the payload data.
171
191
  */
172
192
  success(data?: string | ArrayBuffer, dataType?: "binary" | "text" | "json"): void;
173
193
  /**
174
194
  * Return failed response and the service will close the client WebSocket connection.
175
- * @param code Code can be 400 user error, 401 unauthorized and 500 server error.
176
- * @param detail The detail of the error.
195
+ * @param code - Code can be 400 user error, 401 unauthorized and 500 server error.
196
+ * @param detail - The detail of the error.
177
197
  */
178
198
  fail(code: 400 | 401 | 500, detail?: string): void;
179
199
  }
@@ -196,7 +216,7 @@ export declare class WebPubSubEventHandler {
196
216
  * import express from "express";
197
217
  * import { WebPubSubEventHandler } from "@azure/web-pubsub-express";
198
218
  * const endpoint = "https://xxxx.webpubsubdev.azure.com"
199
- * const handler = new WebPubSubEventHandler('chat', [ endpoint ] {
219
+ * const handler = new WebPubSubEventHandler('chat', {
200
220
  * handleConnect: (req, res) => {
201
221
  * console.log(JSON.stringify(req));
202
222
  * return {};
@@ -208,15 +228,15 @@ export declare class WebPubSubEventHandler {
208
228
  * console.log(JSON.stringify(req));
209
229
  * res.success("Hey " + req.data, req.dataType);
210
230
  * };
231
+ * allowedEndpoints: [ endpoint ]
211
232
  * },
212
233
  * });
213
234
  * ```
214
235
  *
215
- * @param hub The name of the hub to listen to
216
- * @param allowedEndpoints The allowed endpoints for the incoming CloudEvents request
217
- * @param options Options to configure the event handler
236
+ * @param hub - The name of the hub to listen to
237
+ * @param options - Options to configure the event handler
218
238
  */
219
- constructor(hub: string, allowedEndpoints: string[], options?: WebPubSubEventHandlerOptions);
239
+ constructor(hub: string, options?: WebPubSubEventHandlerOptions);
220
240
  /**
221
241
  * Get the middleware to process the CloudEvents requests
222
242
  */
@@ -231,10 +251,6 @@ export declare interface WebPubSubEventHandlerOptions {
231
251
  * Custom serving path for the path of the CloudEvents handler.
232
252
  */
233
253
  path?: string;
234
- /**
235
- * Configures if you'd like to dump the incoming HTTP request.
236
- */
237
- dumpRequest?: boolean;
238
254
  /**
239
255
  * Handle 'connect' event, the service waits for the response to proceed.
240
256
  */
@@ -252,6 +268,10 @@ export declare interface WebPubSubEventHandlerOptions {
252
268
  * Event triggers for "disconnected" unblocking event. This is an unblocking event and the service does not wait for the response.
253
269
  */
254
270
  onDisconnected?: (disconnectedRequest: DisconnectedRequest) => void;
271
+ /**
272
+ * If not specified, by default allow all the endpoints, otherwise only allow specified endpoints
273
+ */
274
+ allowedEndpoints?: string[];
255
275
  }
256
276
 
257
277
  export { }