@azure/web-pubsub-express 1.0.6-alpha.20250224.1 → 1.0.6

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 (86) hide show
  1. package/README.md +53 -46
  2. package/dist/browser/cloudEventsDispatcher.d.ts +15 -0
  3. package/dist/browser/cloudEventsDispatcher.d.ts.map +1 -0
  4. package/dist/browser/cloudEventsDispatcher.js +411 -0
  5. package/dist/browser/cloudEventsDispatcher.js.map +1 -0
  6. package/dist/browser/cloudEventsProtocols.d.ts +411 -0
  7. package/dist/browser/cloudEventsProtocols.d.ts.map +1 -0
  8. package/dist/browser/cloudEventsProtocols.js +4 -0
  9. package/dist/browser/cloudEventsProtocols.js.map +1 -0
  10. package/dist/browser/enum/MqttErrorCodes/mqttDisconnectReasonCode.d.ts +180 -0
  11. package/dist/browser/enum/MqttErrorCodes/mqttDisconnectReasonCode.d.ts.map +1 -0
  12. package/dist/browser/enum/MqttErrorCodes/mqttDisconnectReasonCode.js +183 -0
  13. package/dist/browser/enum/MqttErrorCodes/mqttDisconnectReasonCode.js.map +1 -0
  14. package/dist/browser/enum/MqttErrorCodes/mqttV311ConnectReturnCode.d.ts +31 -0
  15. package/dist/browser/enum/MqttErrorCodes/mqttV311ConnectReturnCode.d.ts.map +1 -0
  16. package/dist/browser/enum/MqttErrorCodes/mqttV311ConnectReturnCode.js +34 -0
  17. package/dist/browser/enum/MqttErrorCodes/mqttV311ConnectReturnCode.js.map +1 -0
  18. package/dist/browser/enum/MqttErrorCodes/mqttV500ConnectReasonCode.d.ts +112 -0
  19. package/dist/browser/enum/MqttErrorCodes/mqttV500ConnectReasonCode.d.ts.map +1 -0
  20. package/dist/browser/enum/MqttErrorCodes/mqttV500ConnectReasonCode.js +115 -0
  21. package/dist/browser/enum/MqttErrorCodes/mqttV500ConnectReasonCode.js.map +1 -0
  22. package/dist/browser/index.d.ts +6 -0
  23. package/dist/browser/index.d.ts.map +1 -0
  24. package/dist/browser/index.js +8 -0
  25. package/dist/browser/index.js.map +1 -0
  26. package/dist/browser/logger.d.ts +7 -0
  27. package/dist/browser/logger.d.ts.map +1 -0
  28. package/dist/browser/logger.js +10 -0
  29. package/dist/browser/logger.js.map +1 -0
  30. package/dist/browser/package.json +3 -0
  31. package/dist/browser/utils.d.ts +6 -0
  32. package/dist/browser/utils.d.ts.map +1 -0
  33. package/dist/browser/utils.js +53 -0
  34. package/dist/browser/utils.js.map +1 -0
  35. package/dist/browser/webPubSubEventHandler.d.ts +46 -0
  36. package/dist/browser/webPubSubEventHandler.d.ts.map +1 -0
  37. package/dist/browser/webPubSubEventHandler.js +73 -0
  38. package/dist/browser/webPubSubEventHandler.js.map +1 -0
  39. package/dist/commonjs/index.js +14 -880
  40. package/dist/commonjs/index.js.map +1 -1
  41. package/dist/commonjs/webPubSubEventHandler.d.ts +7 -8
  42. package/dist/commonjs/webPubSubEventHandler.d.ts.map +1 -1
  43. package/dist/commonjs/webPubSubEventHandler.js +7 -8
  44. package/dist/commonjs/webPubSubEventHandler.js.map +1 -1
  45. package/dist/esm/webPubSubEventHandler.d.ts +7 -8
  46. package/dist/esm/webPubSubEventHandler.d.ts.map +1 -1
  47. package/dist/esm/webPubSubEventHandler.js +7 -8
  48. package/dist/esm/webPubSubEventHandler.js.map +1 -1
  49. package/dist/react-native/cloudEventsDispatcher.d.ts +15 -0
  50. package/dist/react-native/cloudEventsDispatcher.d.ts.map +1 -0
  51. package/dist/react-native/cloudEventsDispatcher.js +411 -0
  52. package/dist/react-native/cloudEventsDispatcher.js.map +1 -0
  53. package/dist/react-native/cloudEventsProtocols.d.ts +411 -0
  54. package/dist/react-native/cloudEventsProtocols.d.ts.map +1 -0
  55. package/dist/react-native/cloudEventsProtocols.js +4 -0
  56. package/dist/react-native/cloudEventsProtocols.js.map +1 -0
  57. package/dist/react-native/enum/MqttErrorCodes/mqttDisconnectReasonCode.d.ts +180 -0
  58. package/dist/react-native/enum/MqttErrorCodes/mqttDisconnectReasonCode.d.ts.map +1 -0
  59. package/dist/react-native/enum/MqttErrorCodes/mqttDisconnectReasonCode.js +183 -0
  60. package/dist/react-native/enum/MqttErrorCodes/mqttDisconnectReasonCode.js.map +1 -0
  61. package/dist/react-native/enum/MqttErrorCodes/mqttV311ConnectReturnCode.d.ts +31 -0
  62. package/dist/react-native/enum/MqttErrorCodes/mqttV311ConnectReturnCode.d.ts.map +1 -0
  63. package/dist/react-native/enum/MqttErrorCodes/mqttV311ConnectReturnCode.js +34 -0
  64. package/dist/react-native/enum/MqttErrorCodes/mqttV311ConnectReturnCode.js.map +1 -0
  65. package/dist/react-native/enum/MqttErrorCodes/mqttV500ConnectReasonCode.d.ts +112 -0
  66. package/dist/react-native/enum/MqttErrorCodes/mqttV500ConnectReasonCode.d.ts.map +1 -0
  67. package/dist/react-native/enum/MqttErrorCodes/mqttV500ConnectReasonCode.js +115 -0
  68. package/dist/react-native/enum/MqttErrorCodes/mqttV500ConnectReasonCode.js.map +1 -0
  69. package/dist/react-native/index.d.ts +6 -0
  70. package/dist/react-native/index.d.ts.map +1 -0
  71. package/dist/react-native/index.js +8 -0
  72. package/dist/react-native/index.js.map +1 -0
  73. package/dist/react-native/logger.d.ts +7 -0
  74. package/dist/react-native/logger.d.ts.map +1 -0
  75. package/dist/react-native/logger.js +10 -0
  76. package/dist/react-native/logger.js.map +1 -0
  77. package/dist/react-native/package.json +3 -0
  78. package/dist/react-native/utils.d.ts +6 -0
  79. package/dist/react-native/utils.d.ts.map +1 -0
  80. package/dist/react-native/utils.js +53 -0
  81. package/dist/react-native/utils.js.map +1 -0
  82. package/dist/react-native/webPubSubEventHandler.d.ts +46 -0
  83. package/dist/react-native/webPubSubEventHandler.d.ts.map +1 -0
  84. package/dist/react-native/webPubSubEventHandler.js +73 -0
  85. package/dist/react-native/webPubSubEventHandler.js.map +1 -0
  86. package/package.json +33 -17
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudEventsDispatcher.js","sourceRoot":"","sources":["../../src/cloudEventsDispat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AAgB,CAChC,WAAW,EACX,2BAA2B,CAAC,WAAW,EAAE,QAAQ,CAAC,CACnD,CAAC;gBACF,OAAO,IAAI,CAAC;YACd,CAAC;YACD;gBACE,MAAM,CAAC,OAAO,CAAC,qBAAqB,SAAS,EAAE,CAAC,CAAC;gBACjD,OAAO,KAAK,CAAC;QACjB,CAAC;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport * as utils from \"./utils.js\";\nimport type { IncomingMessage, ServerResponse } from \"node:http\";\nimport { URL } from \"node:url\";\nimport { logger } from \"./logger.js\";\n\nimport type {\n ConnectRequest,\n ConnectResponse,\n ConnectedRequest,\n ConnectionContext,\n ConnectResponseHandler,\n DisconnectedRequest,\n UserEventRequest,\n UserEventResponseHandler,\n WebPubSubEventHandlerOptions,\n MqttConnectRequest,\n MqttConnectErrorResponse,\n MqttConnectionContextProperties,\n ConnectErrorResponse,\n MqttDisconnectedRequest,\n} from \"./cloudEventsProtocols.js\";\nimport { MqttV311ConnectReturnCode } from \"./enum/MqttErrorCodes/mqttV311ConnectReturnCode.js\";\nimport { MqttV500ConnectReasonCode } from \"./enum/MqttErrorCodes/mqttV500ConnectReasonCode.js\";\n\nenum EventType {\n Connect,\n Connected,\n Disconnected,\n UserEvent,\n}\n\nfunction getConnectResponseHandler(\n connectRequest: ConnectRequest,\n response: ServerResponse,\n): ConnectResponseHandler {\n const states: Record<string, any> = connectRequest.context.states;\n let modified = false;\n const handler = {\n setState(name: string, value: unknown): void {\n states[name] = value;\n modified = true;\n },\n success(res?: ConnectResponse): void {\n if (modified) {\n response.setHeader(\"ce-connectionState\", utils.toBase64JsonString(states));\n }\n if (res === undefined) {\n response.statusCode = 204;\n response.end();\n } else {\n response.statusCode = 200;\n response.setHeader(\"Content-Type\", \"application/json; charset=utf-8\");\n response.end(JSON.stringify(res));\n }\n },\n fail(code: 400 | 401 | 500, detail?: string): void {\n handleConnectErrorResponse(connectRequest, response, code, detail);\n },\n failWith(res: ConnectErrorResponse | MqttConnectErrorResponse) {\n if (\"mqtt\" in res) {\n response.statusCode = getStatusCodeFromMqttConnectCode(res.mqtt.code);\n response.setHeader(\"Content-Type\", \"application/json; charset=utf-8\");\n response.end(JSON.stringify(res));\n } else {\n handleConnectErrorResponse(connectRequest, response, res.code, res.detail);\n }\n },\n };\n\n return handler;\n}\n\nfunction getUserEventResponseHandler(\n userRequest: UserEventRequest,\n response: ServerResponse,\n): UserEventResponseHandler {\n const states: Record<string, any> = userRequest.context.states;\n let modified = false;\n const handler = {\n setState(name: string, value: unknown): void {\n modified = true;\n states[name] = value;\n },\n success(data?: string | ArrayBuffer, dataType?: \"binary\" | \"text\" | \"json\"): void {\n response.statusCode = 200;\n if (modified) {\n response.setHeader(\"ce-connectionState\", utils.toBase64JsonString(states));\n }\n\n switch (dataType) {\n case \"json\":\n response.setHeader(\"Content-Type\", \"application/json; charset=utf-8\");\n break;\n case \"text\":\n response.setHeader(\"Content-Type\", \"text/plain; charset=utf-8\");\n break;\n default:\n response.setHeader(\"Content-Type\", \"application/octet-stream\");\n break;\n }\n response.end(data ?? \"\");\n },\n fail(code: 400 | 401 | 500, detail?: string): void {\n response.statusCode = code;\n response.end(detail ?? \"\");\n },\n };\n return handler;\n}\n\nfunction getContext(request: IncomingMessage, origin: string): ConnectionContext {\n const baseContext: ConnectionContext = {\n signature: utils.getHttpHeader(request, \"ce-signature\")!,\n userId: utils.getHttpHeader(request, \"ce-userid\"),\n hub: utils.getHttpHeader(request, \"ce-hub\")!,\n connectionId: utils.getHttpHeader(request, \"ce-connectionid\")!,\n eventName: utils.getHttpHeader(request, \"ce-eventname\")!,\n origin: origin,\n states: utils.fromBase64JsonString(utils.getHttpHeader(request, \"ce-connectionstate\")),\n clientProtocol: \"default\",\n };\n\n if (isMqttRequest(request)) {\n const mqttProperties: MqttConnectionContextProperties = {\n physicalConnectionId: utils.getHttpHeader(request, \"ce-physicalConnectionId\")!,\n sessionId: utils.getHttpHeader(request, \"ce-sessionId\"),\n };\n return {\n ...baseContext,\n clientProtocol: \"mqtt\",\n mqtt: mqttProperties,\n };\n } else {\n return baseContext;\n }\n}\n\nfunction tryGetWebPubSubEvent(req: IncomingMessage): EventType | undefined {\n // check ce-type to see if it is a valid WebPubSub CloudEvent request\n const prefix = \"azure.webpubsub.\";\n const connect = \"azure.webpubsub.sys.connect\";\n const connected = \"azure.webpubsub.sys.connected\";\n const disconnectd = \"azure.webpubsub.sys.disconnected\";\n const userPrefix = \"azure.webpubsub.user.\";\n const type = utils.getHttpHeader(req, \"ce-type\");\n if (!type?.startsWith(prefix)) {\n return undefined;\n }\n if (type.startsWith(userPrefix)) {\n return EventType.UserEvent;\n }\n switch (type) {\n case connect:\n return EventType.Connect;\n case connected:\n return EventType.Connected;\n case disconnectd:\n return EventType.Disconnected;\n default:\n return undefined;\n }\n}\n\nfunction getStatusCodeFromMqttConnectCode(\n mqttConnectCode: MqttV311ConnectReturnCode | MqttV500ConnectReasonCode,\n): number {\n if (mqttConnectCode < 0x80) {\n switch (mqttConnectCode) {\n case MqttV311ConnectReturnCode.UnacceptableProtocolVersion:\n case MqttV311ConnectReturnCode.IdentifierRejected:\n return 400; // BadRequest\n case MqttV311ConnectReturnCode.ServerUnavailable:\n return 503; // ServiceUnavailable\n case MqttV311ConnectReturnCode.BadUsernameOrPassword:\n case MqttV311ConnectReturnCode.NotAuthorized:\n return 401; // Unauthorized\n default:\n logger.warning(`Invalid MQTT connect return code: ${mqttConnectCode}.`);\n return 500; // InternalServerError\n }\n } else {\n switch (mqttConnectCode) {\n case MqttV500ConnectReasonCode.NotAuthorized:\n case MqttV500ConnectReasonCode.BadUserNameOrPassword:\n return 401; // Unauthorized\n case MqttV500ConnectReasonCode.ClientIdentifierNotValid:\n case MqttV500ConnectReasonCode.MalformedPacket:\n case MqttV500ConnectReasonCode.UnsupportedProtocolVersion:\n case MqttV500ConnectReasonCode.BadAuthenticationMethod:\n case MqttV500ConnectReasonCode.TopicNameInvalid:\n case MqttV500ConnectReasonCode.PayloadFormatInvalid:\n case MqttV500ConnectReasonCode.ImplementationSpecificError:\n case MqttV500ConnectReasonCode.PacketTooLarge:\n case MqttV500ConnectReasonCode.RetainNotSupported:\n case MqttV500ConnectReasonCode.QosNotSupported:\n return 400; // BadRequest\n case MqttV500ConnectReasonCode.QuotaExceeded:\n case MqttV500ConnectReasonCode.ConnectionRateExceeded:\n return 429; // TooManyRequests\n case MqttV500ConnectReasonCode.Banned:\n return 403; // Forbidden\n case MqttV500ConnectReasonCode.UseAnotherServer:\n case MqttV500ConnectReasonCode.ServerMoved:\n case MqttV500ConnectReasonCode.ServerUnavailable:\n case MqttV500ConnectReasonCode.ServerBusy:\n case MqttV500ConnectReasonCode.UnspecifiedError:\n return 500; // InternalServerError\n default:\n logger.warning(`Invalid MQTT connect return code: ${mqttConnectCode}.`);\n return 500; // InternalServerError\n }\n }\n}\n\nfunction getMqttConnectCodeFromStatusCode(\n statusCode: 400 | 401 | 500,\n protocolVersion: number,\n): MqttV311ConnectReturnCode | MqttV500ConnectReasonCode {\n if (protocolVersion === 4) {\n switch (statusCode) {\n case 400:\n return MqttV311ConnectReturnCode.BadUsernameOrPassword;\n case 401:\n return MqttV311ConnectReturnCode.NotAuthorized;\n case 500:\n return MqttV311ConnectReturnCode.ServerUnavailable;\n default:\n logger.warning(`Unsupported HTTP Status Code: ${statusCode}.`);\n return MqttV311ConnectReturnCode.ServerUnavailable;\n }\n } else if (protocolVersion === 5) {\n switch (statusCode) {\n case 400:\n return MqttV500ConnectReasonCode.BadUserNameOrPassword;\n case 401:\n return MqttV500ConnectReasonCode.NotAuthorized;\n case 500:\n return MqttV500ConnectReasonCode.UnspecifiedError;\n default:\n logger.warning(`Unsupported HTTP Status Code: ${statusCode}.`);\n return MqttV500ConnectReasonCode.UnspecifiedError;\n }\n } else {\n logger.warning(`Invalid MQTT protocol version: ${protocolVersion}.`);\n return MqttV311ConnectReturnCode.UnacceptableProtocolVersion;\n }\n}\n\nfunction handleConnectErrorResponse(\n connectRequest: ConnectRequest,\n response: ServerResponse,\n code: 400 | 401 | 500,\n detail?: string,\n): void {\n const isMqttReq = connectRequest.context.clientProtocol === \"mqtt\";\n if (isMqttReq) {\n const protocolVersion = (connectRequest as MqttConnectRequest).mqtt.protocolVersion;\n const mqttErrorResponse: MqttConnectErrorResponse = {\n mqtt: {\n code: getMqttConnectCodeFromStatusCode(code, protocolVersion),\n reason: detail,\n },\n };\n response.statusCode = code;\n response.setHeader(\"Content-Type\", \"application/json; charset=utf-8\");\n response.end(JSON.stringify(mqttErrorResponse));\n } else {\n response.statusCode = code;\n response.end(detail ?? \"\");\n }\n}\n\nfunction isWebPubSubRequest(req: IncomingMessage): boolean {\n return utils.getHttpHeader(req, \"ce-awpsversion\") !== undefined;\n}\n\nfunction isMqttRequest(req: IncomingMessage): boolean {\n const subprotocol = utils.getHttpHeader(req, \"ce-subprotocol\");\n const physicalConnectionId = utils.getHttpHeader(req, \"ce-physicalConnectionId\");\n return (\n subprotocol !== undefined &&\n subprotocol.toLowerCase().includes(\"mqtt\") &&\n physicalConnectionId !== undefined\n );\n}\n\nasync function readUserEventRequest(\n request: IncomingMessage,\n origin: string,\n): Promise<UserEventRequest | undefined> {\n const contentTypeheader = utils.getHttpHeader(request, \"content-type\");\n if (contentTypeheader === undefined) {\n return undefined;\n }\n\n const contentType = contentTypeheader.split(\";\")[0].trim();\n\n switch (contentType) {\n case \"application/octet-stream\":\n return {\n context: getContext(request, origin),\n data: await utils.readRequestBody(request),\n dataType: \"binary\",\n };\n case \"application/json\":\n return {\n context: getContext(request, origin),\n data: JSON.parse((await utils.readRequestBody(request)).toString()),\n dataType: \"json\",\n };\n case \"text/plain\":\n return {\n context: getContext(request, origin),\n data: (await utils.readRequestBody(request)).toString(),\n dataType: \"text\",\n };\n default:\n return undefined;\n }\n}\n\nasync function readSystemEventRequest<T extends { context: ConnectionContext }>(\n request: IncomingMessage,\n origin: string,\n): Promise<T> {\n const body = (await utils.readRequestBody(request)).toString();\n const parsedRequest = JSON.parse(body) as T;\n parsedRequest.context = getContext(request, origin);\n return parsedRequest;\n}\n\n/**\n * @internal\n */\nexport class CloudEventsDispatcher {\n private readonly _allowAll: boolean = true;\n private readonly _allowedOrigins: Array<string> = [];\n constructor(\n private hub: string,\n private eventHandler?: WebPubSubEventHandlerOptions,\n ) {\n if (Array.isArray(eventHandler)) {\n throw new Error(\"Unexpected WebPubSubEventHandlerOptions\");\n }\n if (eventHandler?.allowedEndpoints !== undefined) {\n this._allowedOrigins = eventHandler.allowedEndpoints.map((endpoint) =>\n new URL(endpoint).host.toLowerCase(),\n );\n this._allowAll = false;\n }\n }\n\n public handlePreflight(req: IncomingMessage, res: ServerResponse): boolean {\n if (!isWebPubSubRequest(req)) {\n return false;\n }\n const origin = utils.getHttpHeader(req, \"webhook-request-origin\");\n\n if (origin === undefined) {\n logger.warning(\"Expecting webhook-request-origin header.\");\n res.statusCode = 400;\n } else if (this._allowAll) {\n res.setHeader(\"WebHook-Allowed-Origin\", \"*\");\n } else {\n // service to do the check\n res.setHeader(\"WebHook-Allowed-Origin\", this._allowedOrigins);\n }\n\n res.end();\n return true;\n }\n\n public async handleRequest(request: IncomingMessage, response: ServerResponse): Promise<boolean> {\n if (!isWebPubSubRequest(request)) {\n return false;\n }\n\n // check if it is a valid WebPubSub cloud events\n const origin = utils.getHttpHeader(request, \"webhook-request-origin\");\n if (origin === undefined) {\n return false;\n }\n\n const eventType = tryGetWebPubSubEvent(request);\n if (eventType === undefined) {\n return false;\n }\n\n // check if hub matches\n const hub = utils.getHttpHeader(request, \"ce-hub\");\n if (hub?.toUpperCase() !== this.hub.toUpperCase()) {\n return false;\n }\n\n const isMqtt = isMqttRequest(request);\n // No need to read body if handler is not specified\n switch (eventType) {\n case EventType.Connect:\n if (!this.eventHandler?.handleConnect) {\n if (isMqtt) response.statusCode = 204;\n response.end();\n return true;\n }\n break;\n case EventType.Connected:\n if (!this.eventHandler?.onConnected) {\n response.end();\n return true;\n }\n break;\n case EventType.Disconnected:\n if (!this.eventHandler?.onDisconnected) {\n response.end();\n return true;\n }\n break;\n case EventType.UserEvent:\n if (!this.eventHandler?.handleUserEvent) {\n response.end();\n return true;\n }\n break;\n default:\n logger.warning(`Unknown EventType ${eventType}`);\n return false;\n }\n\n switch (eventType) {\n case EventType.Connect: {\n const connectRequest = isMqtt\n ? await readSystemEventRequest<MqttConnectRequest>(request, origin)\n : await readSystemEventRequest<ConnectRequest>(request, origin);\n // service passes out query property, assign it to queries\n connectRequest.queries = connectRequest.query;\n logger.verbose(connectRequest);\n this.eventHandler.handleConnect!(\n connectRequest,\n getConnectResponseHandler(connectRequest, response),\n );\n return true;\n }\n case EventType.Connected: {\n // for unblocking events, we responds to the service as early as possible\n response.end();\n const connectedRequest = await readSystemEventRequest<ConnectedRequest>(request, origin);\n logger.verbose(connectedRequest);\n this.eventHandler.onConnected!(connectedRequest);\n return true;\n }\n case EventType.Disconnected: {\n // for unblocking events, we responds to the service as early as possible\n response.end();\n const disconnectedRequest = isMqtt\n ? await readSystemEventRequest<MqttDisconnectedRequest>(request, origin)\n : await readSystemEventRequest<DisconnectedRequest>(request, origin);\n logger.verbose(disconnectedRequest);\n this.eventHandler.onDisconnected!(disconnectedRequest);\n return true;\n }\n case EventType.UserEvent: {\n const userRequest = await readUserEventRequest(request, origin);\n if (userRequest === undefined) {\n logger.warning(\n `Unsupported content type ${utils.getHttpHeader(request, \"content-type\")}`,\n );\n return false;\n }\n logger.verbose(userRequest);\n this.eventHandler.handleUserEvent!(\n userRequest,\n getUserEventResponseHandler(userRequest, response),\n );\n return true;\n }\n default:\n logger.warning(`Unknown EventType ${eventType}`);\n return false;\n }\n }\n}\n"]}
@@ -0,0 +1,411 @@
1
+ import type { MqttDisconnectReasonCode } from "./enum/MqttErrorCodes/mqttDisconnectReasonCode.js";
2
+ import type { MqttV311ConnectReturnCode } from "./enum/MqttErrorCodes/mqttV311ConnectReturnCode.js";
3
+ import type { MqttV500ConnectReasonCode } from "./enum/MqttErrorCodes/mqttV500ConnectReasonCode.js";
4
+ /**
5
+ * Response of the connect event.
6
+ */
7
+ export interface ConnectResponse {
8
+ /**
9
+ * Set the groups the connection would like to join.
10
+ */
11
+ groups?: string[];
12
+ /**
13
+ * Set the roles the connection belongs to.
14
+ */
15
+ roles?: string[];
16
+ /**
17
+ * Set the userId for the connection.
18
+ */
19
+ userId?: string;
20
+ /**
21
+ * Set the subprotocol for the connection to complete WebSocket handshake.
22
+ */
23
+ subprotocol?: string;
24
+ }
25
+ /**
26
+ * Success respones of the connect event.
27
+ */
28
+ export interface MqttConnectResponse extends ConnectResponse {
29
+ /**
30
+ * The MQTT specific properties in a successful MQTT connection event response.
31
+ */
32
+ mqtt?: MqttConnectResponseProperties;
33
+ }
34
+ /**
35
+ * Response of a failed connect event.
36
+ */
37
+ export interface ConnectErrorResponse {
38
+ /**
39
+ * The error code.
40
+ */
41
+ code: 400 | 401 | 500;
42
+ /**
43
+ * The error detail.
44
+ */
45
+ detail?: string;
46
+ }
47
+ /**
48
+ * Response of an MQTT connection failure.
49
+ */
50
+ export interface MqttConnectErrorResponse {
51
+ /**
52
+ * The properties of the MQTT connection failure response.
53
+ */
54
+ mqtt: MqttConnectErrorResponseProperties;
55
+ }
56
+ /**
57
+ * The properties of an MQTT connection failure response.
58
+ */
59
+ export interface MqttConnectErrorResponseProperties {
60
+ /**
61
+ * The MQTT connect return code.
62
+ */
63
+ code: MqttV311ConnectReturnCode | MqttV500ConnectReasonCode;
64
+ /**
65
+ * The reason string for the connection failure.
66
+ */
67
+ reason?: string;
68
+ /**
69
+ * The user properties in the response.
70
+ */
71
+ userProperties?: MqttUserProperty[];
72
+ }
73
+ /**
74
+ * The protocol of Web PubSub Client.
75
+ */
76
+ export type WebPubSubClientProtocol = "default" | "mqtt";
77
+ /**
78
+ * The connection context representing the client WebSocket connection.
79
+ */
80
+ export interface ConnectionContext {
81
+ /**
82
+ * The unique identifier generated by the service of the network connection.
83
+ */
84
+ signature: string;
85
+ /**
86
+ * The hub the connection belongs to.
87
+ */
88
+ hub: string;
89
+ /**
90
+ * The Id of the connection.
91
+ */
92
+ connectionId: string;
93
+ /**
94
+ * The event name of this CloudEvents request.
95
+ */
96
+ eventName: string;
97
+ /**
98
+ * The origin this CloudEvents request comes from.
99
+ */
100
+ origin: string;
101
+ /**
102
+ * The user id of the connection.
103
+ */
104
+ userId?: string;
105
+ /**
106
+ * The subprotocol of this connection.
107
+ */
108
+ subprotocol?: string;
109
+ /**
110
+ * Get the additional states for the connection, such states are perserved throughout the lifetime of the connection.
111
+ */
112
+ states: Record<string, any>;
113
+ /**
114
+ * The type of client protocol.
115
+ */
116
+ clientProtocol: WebPubSubClientProtocol;
117
+ /**
118
+ * The MQTT properties that the client WebSocket connection has when it connects (For MQTT connection only).
119
+ */
120
+ mqtt?: MqttConnectionContextProperties;
121
+ }
122
+ /**
123
+ * The connection context properties representing the MQTT client WebSocket connection.
124
+ */
125
+ export interface MqttConnectionContextProperties {
126
+ /**
127
+ * The unique identifier generated by the service of the network connection.
128
+ */
129
+ physicalConnectionId: string;
130
+ /**
131
+ * The unique identifier generated by the service of the MQTT session.
132
+ */
133
+ sessionId?: string;
134
+ }
135
+ /**
136
+ * Request for the connect event.
137
+ */
138
+ export interface ConnectRequest {
139
+ /**
140
+ * The context of current CloudEvents request.
141
+ */
142
+ context: ConnectionContext;
143
+ /**
144
+ * The claims that the client WebSocket connection has when it connects.
145
+ */
146
+ claims?: Record<string, string[]>;
147
+ /**
148
+ * The query that the client WebSocket connection has when it connects.
149
+ * @deprecated Please use queries instead.
150
+ */
151
+ query?: Record<string, string[]>;
152
+ /**
153
+ * The queries that the client WebSocket connection has when it connects.
154
+ */
155
+ queries?: Record<string, string[]>;
156
+ /**
157
+ * The headers that the client WebSocket connection has when it connects.
158
+ */
159
+ headers?: Record<string, string[]>;
160
+ /**
161
+ * The subprotocols that the client WebSocket connection uses to do handshake.
162
+ */
163
+ subprotocols?: string[];
164
+ /**
165
+ * The client certificate info that the client WebSocket connection uses to connect.
166
+ */
167
+ clientCertificates?: Certificate[];
168
+ }
169
+ /**
170
+ * Request for the MQTT connect event.
171
+ */
172
+ export interface MqttConnectRequest extends ConnectRequest {
173
+ /**
174
+ * The MQTT specific properties in the MQTT connect event request.
175
+ */
176
+ mqtt: MqttConnectProperties;
177
+ }
178
+ /**
179
+ * The properties of the MQTT CONNECT packet.
180
+ */
181
+ export interface MqttConnectProperties {
182
+ /**
183
+ * MQTT protocol version.
184
+ */
185
+ protocolVersion: number;
186
+ /**
187
+ * The username field in the MQTT CONNECT packet.
188
+ */
189
+ username?: string;
190
+ /**
191
+ * The password field in the MQTT CONNECT packet.
192
+ */
193
+ password?: string;
194
+ /**
195
+ * The user properties in the MQTT CONNECT packet.
196
+ */
197
+ userProperties?: MqttUserProperty[];
198
+ }
199
+ /**
200
+ * The properties of a successful MQTT connection event response
201
+ */
202
+ export interface MqttConnectResponseProperties {
203
+ /**
204
+ * Additional diagnostic or other information provided by upstream server
205
+ * Now only MQTT 5.0 supports user properties
206
+ */
207
+ userProperties?: MqttUserProperty[];
208
+ }
209
+ /**
210
+ * The properties of a user in MQTT.
211
+ */
212
+ export interface MqttUserProperty {
213
+ /**
214
+ * The name of the property.
215
+ */
216
+ name: string;
217
+ /**
218
+ * The value of the property.
219
+ */
220
+ value: string;
221
+ }
222
+ /**
223
+ * The client certificate.
224
+ */
225
+ export interface Certificate {
226
+ /**
227
+ * The thumbprint of the certificate.
228
+ */
229
+ thumbprint: string;
230
+ }
231
+ /**
232
+ * Request for the connected event.
233
+ */
234
+ export interface ConnectedRequest {
235
+ /**
236
+ * The context of current CloudEvents request.
237
+ */
238
+ context: ConnectionContext;
239
+ }
240
+ /**
241
+ * Request for the user event.
242
+ */
243
+ export type UserEventRequest = {
244
+ /**
245
+ * The context of current CloudEvents request.
246
+ */
247
+ context: ConnectionContext;
248
+ /**
249
+ * The content data.
250
+ */
251
+ data: string;
252
+ /**
253
+ * The type of the data.
254
+ */
255
+ dataType: "text";
256
+ } | {
257
+ /**
258
+ * The context of current CloudEvents request.
259
+ */
260
+ context: ConnectionContext;
261
+ /**
262
+ * 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
263
+ */
264
+ data: unknown;
265
+ /**
266
+ * The type of the data.
267
+ */
268
+ dataType: "json";
269
+ } | {
270
+ /**
271
+ * The context of current CloudEvents request.
272
+ */
273
+ context: ConnectionContext;
274
+ /**
275
+ * The content data.
276
+ */
277
+ data: ArrayBuffer;
278
+ /**
279
+ * The type of the data.
280
+ */
281
+ dataType: "binary";
282
+ };
283
+ /**
284
+ * Request for the disconnected event.
285
+ */
286
+ export interface DisconnectedRequest {
287
+ /**
288
+ * The context of current CloudEvents request.
289
+ */
290
+ context: ConnectionContext;
291
+ /**
292
+ * The reason that the connection disconnects.
293
+ */
294
+ reason?: string;
295
+ }
296
+ /**
297
+ * Request for the disconnected event.
298
+ */
299
+ export interface MqttDisconnectedRequest extends DisconnectedRequest {
300
+ /**
301
+ * The MQTT specific properties in the MQTT disconnected event request.
302
+ */
303
+ mqtt: MqttDisconnectedProperties;
304
+ }
305
+ /**
306
+ * The properties of an MQTT disconnected event.
307
+ */
308
+ export interface MqttDisconnectedProperties {
309
+ /**
310
+ * The MQTT disconnect packet.
311
+ */
312
+ disconnectPacket: MqttDisconnectPacket;
313
+ /**
314
+ * Whether the disconnection is initiated by the client.
315
+ */
316
+ initiatedByClient: boolean;
317
+ }
318
+ /**
319
+ * The properties of the MQTT DISCONNECT packet.
320
+ */
321
+ export interface MqttDisconnectPacket {
322
+ /**
323
+ * The MQTT disconnect return code.
324
+ */
325
+ code: MqttDisconnectReasonCode;
326
+ /**
327
+ * The user properties in the MQTT disconnect packet.
328
+ */
329
+ userProperties?: MqttUserProperty[];
330
+ }
331
+ /**
332
+ * The handler to set connect event response
333
+ */
334
+ export interface ConnectResponseHandler {
335
+ /**
336
+ * Set the state of the connection
337
+ * @param name - The name of the state
338
+ * @param value - The value of the state
339
+ */
340
+ setState(name: string, value: unknown): void;
341
+ /**
342
+ * Return success response to the service.
343
+ * @param response - The response for the connect event.
344
+ */
345
+ success(response?: ConnectResponse | MqttConnectResponse): void;
346
+ /**
347
+ * Return failed response and the service will reject the client WebSocket connection.
348
+ * @param code - Code can be 400 user error, 401 unauthorized and 500 server error.
349
+ * @param detail - The detail of the error.
350
+ */
351
+ fail(code: 400 | 401 | 500, detail?: string): void;
352
+ /**
353
+ * Return failed response with MQTT response properties and the service will reject the client WebSocket connection.
354
+ * @param response - The response for the connect event which contains either default WebPubSub or MQTT response properties.
355
+ */
356
+ failWith(response: ConnectErrorResponse | MqttConnectErrorResponse): void;
357
+ }
358
+ /**
359
+ * The handler to set user event response
360
+ */
361
+ export interface UserEventResponseHandler {
362
+ /**
363
+ * Set the state of the connection
364
+ * @param name - The name of the state
365
+ * @param value - The value of the state
366
+ */
367
+ setState(name: string, value: unknown): void;
368
+ /**
369
+ * Return success response with data to be delivered to the client WebSocket connection.
370
+ * @param data - The payload data to be returned to the client. Stringify the message if it is a JSON object.
371
+ * @param dataType - The type of the payload data.
372
+ */
373
+ success(data?: string | ArrayBuffer, dataType?: "binary" | "text" | "json"): void;
374
+ /**
375
+ * Return failed response and the service will close the client WebSocket connection.
376
+ * @param code - Code can be 400 user error, 401 unauthorized and 500 server error.
377
+ * @param detail - The detail of the error.
378
+ */
379
+ fail(code: 400 | 401 | 500, detail?: string): void;
380
+ }
381
+ /**
382
+ * The options for the CloudEvents handler.
383
+ */
384
+ export interface WebPubSubEventHandlerOptions {
385
+ /**
386
+ * Custom serving path for the path of the CloudEvents handler.
387
+ */
388
+ path?: string;
389
+ /**
390
+ * Handle 'connect' event, the service waits for the response to proceed.
391
+ */
392
+ handleConnect?: (connectRequest: ConnectRequest, connectResponse: ConnectResponseHandler) => void;
393
+ /**
394
+ * Handle user events, the service waits for the response to proceed.
395
+ */
396
+ handleUserEvent?: (userEventRequest: UserEventRequest, userEventResponse: UserEventResponseHandler) => void;
397
+ /**
398
+ * Event trigger for "connected" unblocking event. This is an unblocking event and the service does not wait for the response.
399
+ */
400
+ onConnected?: (connectedRequest: ConnectedRequest) => void;
401
+ /**
402
+ *
403
+ * Event triggers for "disconnected" unblocking event. This is an unblocking event and the service does not wait for the response.
404
+ */
405
+ onDisconnected?: (disconnectedRequest: DisconnectedRequest) => void;
406
+ /**
407
+ * If not specified, by default allow all the endpoints, otherwise only allow specified endpoints
408
+ */
409
+ allowedEndpoints?: string[];
410
+ }
411
+ //# sourceMappingURL=cloudEventsProtocols.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudEventsProtocols.d.ts","sourceRoot":"","sources":["../../src/cloudEventsProtocols.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAC;AAClG,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,oDAAoD,CAAC;AACpG,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,oDAAoD,CAAC;AAEpG;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D;;OAEG;IACH,IAAI,CAAC,EAAE,6BAA6B,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,IAAI,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;IACtB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,IAAI,EAAE,kCAAkC,CAAC;CAC1C;AAED;;GAEG;AACH,MAAM,WAAW,kCA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AAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7C;;;;OAIG;IACH,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,WAAW,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAClF;;;;OAIG;IACH,IAAI,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACpD;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,sBAAsB,KAAK,IAAI,CAAC;IAElG;;OAEG;IACH,eAAe,CAAC,EAAE,CAChB,gBAAgB,EAAE,gBAAgB,EAClC,iBAAiB,EAAE,wBAAwB,KACxC,IAAI,CAAC;IAEV;;OAEG;IACH,WAAW,CAAC,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAE3D;;;OAGG;IACH,cAAc,CAAC,EAAE,CAAC,mBAAmB,EAAE,mBAAmB,KAAK,IAAI,CAAC;IAEpE;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B"}
@@ -0,0 +1,4 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ export {};
4
+ //# sourceMappingURL=cloudEventsProtocols.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudEventsProtocols.js","sourceRoot":"","sources":["../../src/cloudEventsProtocols.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { MqttDisconnectReasonCode } from \"./enum/MqttErrorCodes/mqttDisconnectReasonCode.js\";\nimport type { MqttV311ConnectReturnCode } from \"./enum/MqttErrorCodes/mqttV311ConnectReturnCode.js\";\nimport type { MqttV500ConnectReasonCode } from \"./enum/MqttErrorCodes/mqttV500ConnectReasonCode.js\";\n\n/**\n * Response of the connect event.\n */\nexport interface ConnectResponse {\n /**\n * Set the groups the connection would like to join.\n */\n groups?: string[];\n /**\n * Set the roles the connection belongs to.\n */\n roles?: string[];\n /**\n * Set the userId for the connection.\n */\n userId?: string;\n /**\n * Set the subprotocol for the connection to complete WebSocket handshake.\n */\n subprotocol?: string;\n}\n\n/**\n * Success respones of the connect event.\n */\nexport interface MqttConnectResponse extends ConnectResponse {\n /**\n * The MQTT specific properties in a successful MQTT connection event response.\n */\n mqtt?: MqttConnectResponseProperties;\n}\n\n/**\n * Response of a failed connect event.\n */\nexport interface ConnectErrorResponse {\n /**\n * The error code.\n */\n code: 400 | 401 | 500;\n /**\n * The error detail.\n */\n detail?: string;\n}\n\n/**\n * Response of an MQTT connection failure.\n */\nexport interface MqttConnectErrorResponse {\n /**\n * The properties of the MQTT connection failure response.\n */\n mqtt: MqttConnectErrorResponseProperties;\n}\n\n/**\n * The properties of an MQTT connection failure response.\n */\nexport interface MqttConnectErrorResponseProperties {\n /**\n * The MQTT connect return code.\n */\n code: MqttV311ConnectReturnCode | MqttV500ConnectReasonCode;\n /**\n * The reason string for the connection failure.\n */\n reason?: string;\n /**\n * The user properties in the response.\n */\n userProperties?: MqttUserProperty[];\n}\n\n/**\n * The protocol of Web PubSub Client.\n */\nexport type WebPubSubClientProtocol = \"default\" | \"mqtt\";\n\n/**\n * The connection context representing the client WebSocket connection.\n */\nexport interface ConnectionContext {\n /**\n * The unique identifier generated by the service of the network connection.\n */\n signature: string;\n /**\n * The hub the connection belongs to.\n */\n hub: string;\n /**\n * The Id of the connection.\n */\n connectionId: string;\n /**\n * The event name of this CloudEvents request.\n */\n eventName: string;\n /**\n * The origin this CloudEvents request comes from.\n */\n origin: string;\n /**\n * The user id of the connection.\n */\n userId?: string;\n /**\n * The subprotocol of this connection.\n */\n subprotocol?: string;\n /**\n * Get the additional states for the connection, such states are perserved throughout the lifetime of the connection.\n */\n states: Record<string, any>;\n /**\n * The type of client protocol.\n */\n clientProtocol: WebPubSubClientProtocol;\n /**\n * The MQTT properties that the client WebSocket connection has when it connects (For MQTT connection only).\n */\n mqtt?: MqttConnectionContextProperties;\n}\n\n/**\n * The connection context properties representing the MQTT client WebSocket connection.\n */\nexport interface MqttConnectionContextProperties {\n /**\n * The unique identifier generated by the service of the network connection.\n */\n physicalConnectionId: string;\n /**\n * The unique identifier generated by the service of the MQTT session.\n */\n sessionId?: string;\n}\n\n/**\n * Request for the connect event.\n */\nexport interface ConnectRequest {\n /**\n * The context of current CloudEvents request.\n */\n context: ConnectionContext;\n /**\n * The claims that the client WebSocket connection has when it connects.\n */\n claims?: Record<string, string[]>;\n /**\n * The query that the client WebSocket connection has when it connects.\n * @deprecated Please use queries instead.\n */\n query?: Record<string, string[]>;\n /**\n * The queries that the client WebSocket connection has when it connects.\n */\n queries?: Record<string, string[]>;\n /**\n * The headers that the client WebSocket connection has when it connects.\n */\n headers?: Record<string, string[]>;\n /**\n * The subprotocols that the client WebSocket connection uses to do handshake.\n */\n subprotocols?: string[];\n /**\n * The client certificate info that the client WebSocket connection uses to connect.\n */\n clientCertificates?: Certificate[];\n}\n\n/**\n * Request for the MQTT connect event.\n */\nexport interface MqttConnectRequest extends ConnectRequest {\n /**\n * The MQTT specific properties in the MQTT connect event request.\n */\n mqtt: MqttConnectProperties;\n}\n\n/**\n * The properties of the MQTT CONNECT packet.\n */\nexport interface MqttConnectProperties {\n /**\n * MQTT protocol version.\n */\n protocolVersion: number;\n /**\n * The username field in the MQTT CONNECT packet.\n */\n username?: string;\n /**\n * The password field in the MQTT CONNECT packet.\n */\n password?: string;\n /**\n * The user properties in the MQTT CONNECT packet.\n */\n userProperties?: MqttUserProperty[];\n}\n\n/**\n * The properties of a successful MQTT connection event response\n */\nexport interface MqttConnectResponseProperties {\n /**\n * Additional diagnostic or other information provided by upstream server\n * Now only MQTT 5.0 supports user properties\n */\n userProperties?: MqttUserProperty[];\n}\n\n/**\n * The properties of a user in MQTT.\n */\nexport interface MqttUserProperty {\n /**\n * The name of the property.\n */\n name: string;\n /**\n * The value of the property.\n */\n value: string;\n}\n\n/**\n * The client certificate.\n */\nexport interface Certificate {\n /**\n * The thumbprint of the certificate.\n */\n thumbprint: string;\n}\n\n/**\n * Request for the connected event.\n */\nexport interface ConnectedRequest {\n /**\n * The context of current CloudEvents request.\n */\n context: ConnectionContext;\n}\n\n/**\n * Request for the user event.\n */\nexport type UserEventRequest =\n | {\n /**\n * The context of current CloudEvents request.\n */\n context: ConnectionContext;\n\n /**\n * The content data.\n */\n data: string;\n /**\n * The type of the data.\n */\n dataType: \"text\";\n }\n | {\n /**\n * The context of current CloudEvents request.\n */\n context: ConnectionContext;\n\n /**\n * 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\n */\n data: unknown;\n\n /**\n * The type of the data.\n */\n dataType: \"json\";\n }\n | {\n /**\n * The context of current CloudEvents request.\n */\n context: ConnectionContext;\n\n /**\n * The content data.\n */\n data: ArrayBuffer;\n /**\n * The type of the data.\n */\n dataType: \"binary\";\n };\n\n/**\n * Request for the disconnected event.\n */\nexport interface DisconnectedRequest {\n /**\n * The context of current CloudEvents request.\n */\n context: ConnectionContext;\n /**\n * The reason that the connection disconnects.\n */\n reason?: string;\n}\n\n/**\n * Request for the disconnected event.\n */\nexport interface MqttDisconnectedRequest extends DisconnectedRequest {\n /**\n * The MQTT specific properties in the MQTT disconnected event request.\n */\n mqtt: MqttDisconnectedProperties;\n}\n\n/**\n * The properties of an MQTT disconnected event.\n */\nexport interface MqttDisconnectedProperties {\n /**\n * The MQTT disconnect packet.\n */\n disconnectPacket: MqttDisconnectPacket;\n /**\n * Whether the disconnection is initiated by the client.\n */\n initiatedByClient: boolean;\n}\n\n/**\n * The properties of the MQTT DISCONNECT packet.\n */\nexport interface MqttDisconnectPacket {\n /**\n * The MQTT disconnect return code.\n */\n code: MqttDisconnectReasonCode;\n /**\n * The user properties in the MQTT disconnect packet.\n */\n userProperties?: MqttUserProperty[];\n}\n\n/**\n * The handler to set connect event response\n */\nexport interface ConnectResponseHandler {\n /**\n * Set the state of the connection\n * @param name - The name of the state\n * @param value - The value of the state\n */\n setState(name: string, value: unknown): void;\n /**\n * Return success response to the service.\n * @param response - The response for the connect event.\n */\n success(response?: ConnectResponse | MqttConnectResponse): void;\n /**\n * Return failed response and the service will reject the client WebSocket connection.\n * @param code - Code can be 400 user error, 401 unauthorized and 500 server error.\n * @param detail - The detail of the error.\n */\n fail(code: 400 | 401 | 500, detail?: string): void;\n /**\n * Return failed response with MQTT response properties and the service will reject the client WebSocket connection.\n * @param response - The response for the connect event which contains either default WebPubSub or MQTT response properties.\n */\n failWith(response: ConnectErrorResponse | MqttConnectErrorResponse): void;\n}\n\n/**\n * The handler to set user event response\n */\nexport interface UserEventResponseHandler {\n /**\n * Set the state of the connection\n * @param name - The name of the state\n * @param value - The value of the state\n */\n setState(name: string, value: unknown): void;\n /**\n * Return success response with data to be delivered to the client WebSocket connection.\n * @param data - The payload data to be returned to the client. Stringify the message if it is a JSON object.\n * @param dataType - The type of the payload data.\n */\n success(data?: string | ArrayBuffer, dataType?: \"binary\" | \"text\" | \"json\"): void;\n /**\n * Return failed response and the service will close the client WebSocket connection.\n * @param code - Code can be 400 user error, 401 unauthorized and 500 server error.\n * @param detail - The detail of the error.\n */\n fail(code: 400 | 401 | 500, detail?: string): void;\n}\n\n/**\n * The options for the CloudEvents handler.\n */\nexport interface WebPubSubEventHandlerOptions {\n /**\n * Custom serving path for the path of the CloudEvents handler.\n */\n path?: string;\n\n /**\n * Handle 'connect' event, the service waits for the response to proceed.\n */\n handleConnect?: (connectRequest: ConnectRequest, connectResponse: ConnectResponseHandler) => void;\n\n /**\n * Handle user events, the service waits for the response to proceed.\n */\n handleUserEvent?: (\n userEventRequest: UserEventRequest,\n userEventResponse: UserEventResponseHandler,\n ) => void;\n\n /**\n * Event trigger for \"connected\" unblocking event. This is an unblocking event and the service does not wait for the response.\n */\n onConnected?: (connectedRequest: ConnectedRequest) => void;\n\n /**\n *\n * Event triggers for \"disconnected\" unblocking event. This is an unblocking event and the service does not wait for the response.\n */\n onDisconnected?: (disconnectedRequest: DisconnectedRequest) => void;\n\n /**\n * If not specified, by default allow all the endpoints, otherwise only allow specified endpoints\n */\n allowedEndpoints?: string[];\n}\n"]}