@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.
- package/README.md +53 -46
- package/dist/browser/cloudEventsDispatcher.d.ts +15 -0
- package/dist/browser/cloudEventsDispatcher.d.ts.map +1 -0
- package/dist/browser/cloudEventsDispatcher.js +411 -0
- package/dist/browser/cloudEventsDispatcher.js.map +1 -0
- package/dist/browser/cloudEventsProtocols.d.ts +411 -0
- package/dist/browser/cloudEventsProtocols.d.ts.map +1 -0
- package/dist/browser/cloudEventsProtocols.js +4 -0
- package/dist/browser/cloudEventsProtocols.js.map +1 -0
- package/dist/browser/enum/MqttErrorCodes/mqttDisconnectReasonCode.d.ts +180 -0
- package/dist/browser/enum/MqttErrorCodes/mqttDisconnectReasonCode.d.ts.map +1 -0
- package/dist/browser/enum/MqttErrorCodes/mqttDisconnectReasonCode.js +183 -0
- package/dist/browser/enum/MqttErrorCodes/mqttDisconnectReasonCode.js.map +1 -0
- package/dist/browser/enum/MqttErrorCodes/mqttV311ConnectReturnCode.d.ts +31 -0
- package/dist/browser/enum/MqttErrorCodes/mqttV311ConnectReturnCode.d.ts.map +1 -0
- package/dist/browser/enum/MqttErrorCodes/mqttV311ConnectReturnCode.js +34 -0
- package/dist/browser/enum/MqttErrorCodes/mqttV311ConnectReturnCode.js.map +1 -0
- package/dist/browser/enum/MqttErrorCodes/mqttV500ConnectReasonCode.d.ts +112 -0
- package/dist/browser/enum/MqttErrorCodes/mqttV500ConnectReasonCode.d.ts.map +1 -0
- package/dist/browser/enum/MqttErrorCodes/mqttV500ConnectReasonCode.js +115 -0
- package/dist/browser/enum/MqttErrorCodes/mqttV500ConnectReasonCode.js.map +1 -0
- package/dist/browser/index.d.ts +6 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +8 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/logger.d.ts +7 -0
- package/dist/browser/logger.d.ts.map +1 -0
- package/dist/browser/logger.js +10 -0
- package/dist/browser/logger.js.map +1 -0
- package/dist/browser/package.json +3 -0
- package/dist/browser/utils.d.ts +6 -0
- package/dist/browser/utils.d.ts.map +1 -0
- package/dist/browser/utils.js +53 -0
- package/dist/browser/utils.js.map +1 -0
- package/dist/browser/webPubSubEventHandler.d.ts +46 -0
- package/dist/browser/webPubSubEventHandler.d.ts.map +1 -0
- package/dist/browser/webPubSubEventHandler.js +73 -0
- package/dist/browser/webPubSubEventHandler.js.map +1 -0
- package/dist/commonjs/index.js +14 -880
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/webPubSubEventHandler.d.ts +7 -8
- package/dist/commonjs/webPubSubEventHandler.d.ts.map +1 -1
- package/dist/commonjs/webPubSubEventHandler.js +7 -8
- package/dist/commonjs/webPubSubEventHandler.js.map +1 -1
- package/dist/esm/webPubSubEventHandler.d.ts +7 -8
- package/dist/esm/webPubSubEventHandler.d.ts.map +1 -1
- package/dist/esm/webPubSubEventHandler.js +7 -8
- package/dist/esm/webPubSubEventHandler.js.map +1 -1
- package/dist/react-native/cloudEventsDispatcher.d.ts +15 -0
- package/dist/react-native/cloudEventsDispatcher.d.ts.map +1 -0
- package/dist/react-native/cloudEventsDispatcher.js +411 -0
- package/dist/react-native/cloudEventsDispatcher.js.map +1 -0
- package/dist/react-native/cloudEventsProtocols.d.ts +411 -0
- package/dist/react-native/cloudEventsProtocols.d.ts.map +1 -0
- package/dist/react-native/cloudEventsProtocols.js +4 -0
- package/dist/react-native/cloudEventsProtocols.js.map +1 -0
- package/dist/react-native/enum/MqttErrorCodes/mqttDisconnectReasonCode.d.ts +180 -0
- package/dist/react-native/enum/MqttErrorCodes/mqttDisconnectReasonCode.d.ts.map +1 -0
- package/dist/react-native/enum/MqttErrorCodes/mqttDisconnectReasonCode.js +183 -0
- package/dist/react-native/enum/MqttErrorCodes/mqttDisconnectReasonCode.js.map +1 -0
- package/dist/react-native/enum/MqttErrorCodes/mqttV311ConnectReturnCode.d.ts +31 -0
- package/dist/react-native/enum/MqttErrorCodes/mqttV311ConnectReturnCode.d.ts.map +1 -0
- package/dist/react-native/enum/MqttErrorCodes/mqttV311ConnectReturnCode.js +34 -0
- package/dist/react-native/enum/MqttErrorCodes/mqttV311ConnectReturnCode.js.map +1 -0
- package/dist/react-native/enum/MqttErrorCodes/mqttV500ConnectReasonCode.d.ts +112 -0
- package/dist/react-native/enum/MqttErrorCodes/mqttV500ConnectReasonCode.d.ts.map +1 -0
- package/dist/react-native/enum/MqttErrorCodes/mqttV500ConnectReasonCode.js +115 -0
- package/dist/react-native/enum/MqttErrorCodes/mqttV500ConnectReasonCode.js.map +1 -0
- package/dist/react-native/index.d.ts +6 -0
- package/dist/react-native/index.d.ts.map +1 -0
- package/dist/react-native/index.js +8 -0
- package/dist/react-native/index.js.map +1 -0
- package/dist/react-native/logger.d.ts +7 -0
- package/dist/react-native/logger.d.ts.map +1 -0
- package/dist/react-native/logger.js +10 -0
- package/dist/react-native/logger.js.map +1 -0
- package/dist/react-native/package.json +3 -0
- package/dist/react-native/utils.d.ts +6 -0
- package/dist/react-native/utils.d.ts.map +1 -0
- package/dist/react-native/utils.js +53 -0
- package/dist/react-native/utils.js.map +1 -0
- package/dist/react-native/webPubSubEventHandler.d.ts +46 -0
- package/dist/react-native/webPubSubEventHandler.d.ts.map +1 -0
- package/dist/react-native/webPubSubEventHandler.js +73 -0
- package/dist/react-native/webPubSubEventHandler.js.map +1 -0
- package/package.json +33 -17
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
/**
|
|
4
|
+
* MQTT Connect Reason Codes
|
|
5
|
+
* These codes represent the reasons for the outcome of an MQTT CONNECT packet as per MQTT 5.0 specification.
|
|
6
|
+
*/
|
|
7
|
+
export var MqttV500ConnectReasonCode;
|
|
8
|
+
(function (MqttV500ConnectReasonCode) {
|
|
9
|
+
/**
|
|
10
|
+
* 0x80 - Unspecified error
|
|
11
|
+
* Description: The Server does not wish to reveal the reason for the failure, or none of the other Reason Codes apply.
|
|
12
|
+
*/
|
|
13
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["UnspecifiedError"] = 128] = "UnspecifiedError";
|
|
14
|
+
/**
|
|
15
|
+
* 0x81 - Malformed Packet
|
|
16
|
+
* Description: Data within the CONNECT packet could not be correctly parsed.
|
|
17
|
+
*/
|
|
18
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["MalformedPacket"] = 129] = "MalformedPacket";
|
|
19
|
+
/**
|
|
20
|
+
* 0x82 - Protocol Error
|
|
21
|
+
* Description: Data in the CONNECT packet does not conform to this specification.
|
|
22
|
+
*/
|
|
23
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["ProtocolError"] = 130] = "ProtocolError";
|
|
24
|
+
/**
|
|
25
|
+
* 0x83 - Implementation specific error
|
|
26
|
+
* Description: The CONNECT is valid but is not accepted by this Server.
|
|
27
|
+
*/
|
|
28
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["ImplementationSpecificError"] = 131] = "ImplementationSpecificError";
|
|
29
|
+
/**
|
|
30
|
+
* 0x84 - Unsupported Protocol Version
|
|
31
|
+
* Description: The Server does not support the version of the MQTT protocol requested by the Client.
|
|
32
|
+
*/
|
|
33
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["UnsupportedProtocolVersion"] = 132] = "UnsupportedProtocolVersion";
|
|
34
|
+
/**
|
|
35
|
+
* 0x85 - Client Identifier not valid
|
|
36
|
+
* Description: The Client Identifier is a valid string but is not allowed by the Server.
|
|
37
|
+
*/
|
|
38
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["ClientIdentifierNotValid"] = 133] = "ClientIdentifierNotValid";
|
|
39
|
+
/**
|
|
40
|
+
* 0x86 - Bad User Name or Password
|
|
41
|
+
* Description: The Server does not accept the User Name or Password specified by the Client.
|
|
42
|
+
*/
|
|
43
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["BadUserNameOrPassword"] = 134] = "BadUserNameOrPassword";
|
|
44
|
+
/**
|
|
45
|
+
* 0x87 - Not authorized
|
|
46
|
+
* Description: The Client is not authorized to connect.
|
|
47
|
+
*/
|
|
48
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["NotAuthorized"] = 135] = "NotAuthorized";
|
|
49
|
+
/**
|
|
50
|
+
* 0x88 - Server unavailable
|
|
51
|
+
* Description: The MQTT Server is not available.
|
|
52
|
+
*/
|
|
53
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["ServerUnavailable"] = 136] = "ServerUnavailable";
|
|
54
|
+
/**
|
|
55
|
+
* 0x89 - Server busy
|
|
56
|
+
* Description: The Server is busy. Try again later.
|
|
57
|
+
*/
|
|
58
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["ServerBusy"] = 137] = "ServerBusy";
|
|
59
|
+
/**
|
|
60
|
+
* 0x8A - Banned
|
|
61
|
+
* Description: This Client has been banned by administrative action. Contact the server administrator.
|
|
62
|
+
*/
|
|
63
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["Banned"] = 138] = "Banned";
|
|
64
|
+
/**
|
|
65
|
+
* 0x8C - Bad authentication method
|
|
66
|
+
* Description: The authentication method is not supported or does not match the authentication method currently in use.
|
|
67
|
+
*/
|
|
68
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["BadAuthenticationMethod"] = 140] = "BadAuthenticationMethod";
|
|
69
|
+
/**
|
|
70
|
+
* 0x90 - Topic Name invalid
|
|
71
|
+
* Description: The Will Topic Name is not malformed, but is not accepted by this Server.
|
|
72
|
+
*/
|
|
73
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["TopicNameInvalid"] = 144] = "TopicNameInvalid";
|
|
74
|
+
/**
|
|
75
|
+
* 0x95 - Packet too large
|
|
76
|
+
* Description: The CONNECT packet exceeded the maximum permissible size.
|
|
77
|
+
*/
|
|
78
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["PacketTooLarge"] = 149] = "PacketTooLarge";
|
|
79
|
+
/**
|
|
80
|
+
* 0x97 - Quota exceeded
|
|
81
|
+
* Description: An implementation or administrative imposed limit has been exceeded.
|
|
82
|
+
*/
|
|
83
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["QuotaExceeded"] = 151] = "QuotaExceeded";
|
|
84
|
+
/**
|
|
85
|
+
* 0x99 - Payload format invalid
|
|
86
|
+
* Description: The Will Payload does not match the specified Payload Format Indicator.
|
|
87
|
+
*/
|
|
88
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["PayloadFormatInvalid"] = 153] = "PayloadFormatInvalid";
|
|
89
|
+
/**
|
|
90
|
+
* 0x9A - Retain not supported
|
|
91
|
+
* Description: The Server does not support retained messages, and Will Retain was set to 1.
|
|
92
|
+
*/
|
|
93
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["RetainNotSupported"] = 154] = "RetainNotSupported";
|
|
94
|
+
/**
|
|
95
|
+
* 0x9B - QoS not supported
|
|
96
|
+
* Description: The Server does not support the QoS set in Will QoS.
|
|
97
|
+
*/
|
|
98
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["QosNotSupported"] = 155] = "QosNotSupported";
|
|
99
|
+
/**
|
|
100
|
+
* 0x9C - Use another server
|
|
101
|
+
* Description: The Client should temporarily use another server.
|
|
102
|
+
*/
|
|
103
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["UseAnotherServer"] = 156] = "UseAnotherServer";
|
|
104
|
+
/**
|
|
105
|
+
* 0x9D - Server moved
|
|
106
|
+
* Description: The Client should permanently use another server.
|
|
107
|
+
*/
|
|
108
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["ServerMoved"] = 157] = "ServerMoved";
|
|
109
|
+
/**
|
|
110
|
+
* 0x9F - Connection rate exceeded
|
|
111
|
+
* Description: The connection rate limit has been exceeded.
|
|
112
|
+
*/
|
|
113
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["ConnectionRateExceeded"] = 159] = "ConnectionRateExceeded";
|
|
114
|
+
})(MqttV500ConnectReasonCode || (MqttV500ConnectReasonCode = {}));
|
|
115
|
+
//# sourceMappingURL=mqttV500ConnectReasonCode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mqttV500ConnectReasonCode.js","sourceRoot":"","sources":["../../../../src/enum/MqttErrorCodes/mqttV500ConnectReasonCode.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;GAGG;AACH,MAAM,CAAN,IAAY,yBA8HX;AA9HD,WAAY,yBAAyB;IACnC;;;OAGG;IACH,mGAAuB,CAAA;IAEvB;;;OAGG;IACH,iGAAsB,CAAA;IAEtB;;;OAGG;IACH,6FAAoB,CAAA;IAEpB;;;OAGG;IACH,yHAAkC,CAAA;IAElC;;;OAGG;IACH,uHAAiC,CAAA;IAEjC;;;OAGG;IACH,mHAA+B,CAAA;IAE/B;;;OAGG;IACH,6GAA4B,CAAA;IAE5B;;;OAGG;IACH,6FAAoB,CAAA;IAEpB;;;OAGG;IACH,qGAAwB,CAAA;IAExB;;;OAGG;IACH,uFAAiB,CAAA;IAEjB;;;OAGG;IACH,+EAAa,CAAA;IAEb;;;OAGG;IACH,iHAA8B,CAAA;IAE9B;;;OAGG;IACH,mGAAuB,CAAA;IAEvB;;;OAGG;IACH,+FAAqB,CAAA;IAErB;;;OAGG;IACH,6FAAoB,CAAA;IAEpB;;;OAGG;IACH,2GAA2B,CAAA;IAE3B;;;OAGG;IACH,uGAAyB,CAAA;IAEzB;;;OAGG;IACH,iGAAsB,CAAA;IAEtB;;;OAGG;IACH,mGAAuB,CAAA;IAEvB;;;OAGG;IACH,yFAAkB,CAAA;IAElB;;;OAGG;IACH,+GAA6B,CAAA;AAC/B,CAAC,EA9HW,yBAAyB,KAAzB,yBAAyB,QA8HpC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * MQTT Connect Reason Codes\n * These codes represent the reasons for the outcome of an MQTT CONNECT packet as per MQTT 5.0 specification.\n */\nexport enum MqttV500ConnectReasonCode {\n /**\n * 0x80 - Unspecified error\n * Description: The Server does not wish to reveal the reason for the failure, or none of the other Reason Codes apply.\n */\n UnspecifiedError = 0x80,\n\n /**\n * 0x81 - Malformed Packet\n * Description: Data within the CONNECT packet could not be correctly parsed.\n */\n MalformedPacket = 0x81,\n\n /**\n * 0x82 - Protocol Error\n * Description: Data in the CONNECT packet does not conform to this specification.\n */\n ProtocolError = 0x82,\n\n /**\n * 0x83 - Implementation specific error\n * Description: The CONNECT is valid but is not accepted by this Server.\n */\n ImplementationSpecificError = 0x83,\n\n /**\n * 0x84 - Unsupported Protocol Version\n * Description: The Server does not support the version of the MQTT protocol requested by the Client.\n */\n UnsupportedProtocolVersion = 0x84,\n\n /**\n * 0x85 - Client Identifier not valid\n * Description: The Client Identifier is a valid string but is not allowed by the Server.\n */\n ClientIdentifierNotValid = 0x85,\n\n /**\n * 0x86 - Bad User Name or Password\n * Description: The Server does not accept the User Name or Password specified by the Client.\n */\n BadUserNameOrPassword = 0x86,\n\n /**\n * 0x87 - Not authorized\n * Description: The Client is not authorized to connect.\n */\n NotAuthorized = 0x87,\n\n /**\n * 0x88 - Server unavailable\n * Description: The MQTT Server is not available.\n */\n ServerUnavailable = 0x88,\n\n /**\n * 0x89 - Server busy\n * Description: The Server is busy. Try again later.\n */\n ServerBusy = 0x89,\n\n /**\n * 0x8A - Banned\n * Description: This Client has been banned by administrative action. Contact the server administrator.\n */\n Banned = 0x8a,\n\n /**\n * 0x8C - Bad authentication method\n * Description: The authentication method is not supported or does not match the authentication method currently in use.\n */\n BadAuthenticationMethod = 0x8c,\n\n /**\n * 0x90 - Topic Name invalid\n * Description: The Will Topic Name is not malformed, but is not accepted by this Server.\n */\n TopicNameInvalid = 0x90,\n\n /**\n * 0x95 - Packet too large\n * Description: The CONNECT packet exceeded the maximum permissible size.\n */\n PacketTooLarge = 0x95,\n\n /**\n * 0x97 - Quota exceeded\n * Description: An implementation or administrative imposed limit has been exceeded.\n */\n QuotaExceeded = 0x97,\n\n /**\n * 0x99 - Payload format invalid\n * Description: The Will Payload does not match the specified Payload Format Indicator.\n */\n PayloadFormatInvalid = 0x99,\n\n /**\n * 0x9A - Retain not supported\n * Description: The Server does not support retained messages, and Will Retain was set to 1.\n */\n RetainNotSupported = 0x9a,\n\n /**\n * 0x9B - QoS not supported\n * Description: The Server does not support the QoS set in Will QoS.\n */\n QosNotSupported = 0x9b,\n\n /**\n * 0x9C - Use another server\n * Description: The Client should temporarily use another server.\n */\n UseAnotherServer = 0x9c,\n\n /**\n * 0x9D - Server moved\n * Description: The Client should permanently use another server.\n */\n ServerMoved = 0x9d,\n\n /**\n * 0x9F - Connection rate exceeded\n * Description: The connection rate limit has been exceeded.\n */\n ConnectionRateExceeded = 0x9f,\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { WebPubSubEventHandler } from "./webPubSubEventHandler.js";
|
|
2
|
+
export * from "./cloudEventsProtocols.js";
|
|
3
|
+
export { MqttV311ConnectReturnCode } from "./enum/MqttErrorCodes/mqttV311ConnectReturnCode.js";
|
|
4
|
+
export { MqttV500ConnectReasonCode } from "./enum/MqttErrorCodes/mqttV500ConnectReasonCode.js";
|
|
5
|
+
export { MqttDisconnectReasonCode } from "./enum/MqttErrorCodes/mqttDisconnectReasonCode.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,cAAc,2BAA2B,CAAC;AAE1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,oDAAoD,CAAC;AAC/F,OAAO,EAAE,yBAAyB,EAAE,MAAM,oDAAoD,CAAC;AAC/F,OAAO,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
export { WebPubSubEventHandler } from "./webPubSubEventHandler.js";
|
|
4
|
+
export * from "./cloudEventsProtocols.js";
|
|
5
|
+
export { MqttV311ConnectReturnCode } from "./enum/MqttErrorCodes/mqttV311ConnectReturnCode.js";
|
|
6
|
+
export { MqttV500ConnectReasonCode } from "./enum/MqttErrorCodes/mqttV500ConnectReasonCode.js";
|
|
7
|
+
export { MqttDisconnectReasonCode } from "./enum/MqttErrorCodes/mqttDisconnectReasonCode.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,cAAc,2BAA2B,CAAC;AAE1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,oDAAoD,CAAC;AAC/F,OAAO,EAAE,yBAAyB,EAAE,MAAM,oDAAoD,CAAC;AAC/F,OAAO,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nexport { WebPubSubEventHandler } from \"./webPubSubEventHandler.js\";\n\nexport * from \"./cloudEventsProtocols.js\";\n\nexport { MqttV311ConnectReturnCode } from \"./enum/MqttErrorCodes/mqttV311ConnectReturnCode.js\";\nexport { MqttV500ConnectReasonCode } from \"./enum/MqttErrorCodes/mqttV500ConnectReasonCode.js\";\nexport { MqttDisconnectReasonCode } from \"./enum/MqttErrorCodes/mqttDisconnectReasonCode.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,eAAO,MAAM,MAAM,qCAA2C,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { createClientLogger } from "@azure/logger";
|
|
4
|
+
/**
|
|
5
|
+
* The \@azure/logger configuration for this package.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export const logger = createClientLogger("web-pubsub-express");
|
|
10
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,kBAAkB,CAAC,oBAAoB,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { createClientLogger } from \"@azure/logger\";\n\n/**\n * The \\@azure/logger configuration for this package.\n *\n * @internal\n */\nexport const logger = createClientLogger(\"web-pubsub-express\");\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { IncomingMessage } from "node:http";
|
|
2
|
+
export declare function toBase64JsonString(obj: Record<string, any>): string;
|
|
3
|
+
export declare function fromBase64JsonString(base64String: string | undefined): Record<string, any>;
|
|
4
|
+
export declare function getHttpHeader(req: IncomingMessage, key: string): string | undefined;
|
|
5
|
+
export declare function readRequestBody(req: IncomingMessage): Promise<Buffer>;
|
|
6
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAMjD,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAEnE;AAED,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAa1F;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAcnF;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAgBrE"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
function isJsonObject(obj) {
|
|
4
|
+
return obj && typeof obj === "object" && !Array.isArray(obj);
|
|
5
|
+
}
|
|
6
|
+
export function toBase64JsonString(obj) {
|
|
7
|
+
return Buffer.from(JSON.stringify(obj)).toString("base64");
|
|
8
|
+
}
|
|
9
|
+
export function fromBase64JsonString(base64String) {
|
|
10
|
+
if (base64String === undefined) {
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
const buf = Buffer.from(base64String, "base64").toString();
|
|
15
|
+
const parsed = JSON.parse(buf);
|
|
16
|
+
return isJsonObject(parsed) ? parsed : {};
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
console.warn("Unexpected state format:" + e);
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function getHttpHeader(req, key) {
|
|
24
|
+
if (!key)
|
|
25
|
+
return undefined;
|
|
26
|
+
// According to https://nodejs.org/api/http.html#http_class_http_incomingmessage, header names are always lower-cased
|
|
27
|
+
const value = req.headers[key.toLowerCase()];
|
|
28
|
+
if (value === undefined) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
if (typeof value === "string") {
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
return value[0];
|
|
35
|
+
}
|
|
36
|
+
export function readRequestBody(req) {
|
|
37
|
+
return new Promise(function (resolve, reject) {
|
|
38
|
+
const chunks = [];
|
|
39
|
+
req.on("data", function (chunk) {
|
|
40
|
+
chunks.push(chunk);
|
|
41
|
+
});
|
|
42
|
+
req.on("end", function () {
|
|
43
|
+
const buffer = Buffer.concat(chunks);
|
|
44
|
+
resolve(buffer);
|
|
45
|
+
});
|
|
46
|
+
// reject on request error
|
|
47
|
+
req.on("error", function (err) {
|
|
48
|
+
// This is not a "Second reject", just a different sort of failure
|
|
49
|
+
reject(err);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,SAAS,YAAY,CAAC,GAAQ;IAC5B,OAAO,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,GAAwB;IACzD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,YAAgC;IACnE,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC3D,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC/B,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5C,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,OAAO,CAAC,IAAI,CAAC,0BAA0B,GAAG,CAAC,CAAC,CAAC;QAC7C,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,GAAoB,EAAE,GAAW;IAC7D,IAAI,CAAC,GAAG;QAAE,OAAO,SAAS,CAAC;IAE3B,qHAAqH;IACrH,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;IAE7C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAoB;IAClD,OAAO,IAAI,OAAO,CAAC,UAAU,OAAO,EAAE,MAAM;QAC1C,MAAM,MAAM,GAAQ,EAAE,CAAC;QACvB,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK;YAC5B,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC,CAAC,CAAC;QACH,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE;YACZ,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACrC,OAAO,CAAC,MAAM,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;QACH,0BAA0B;QAC1B,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,GAAG;YAC3B,kEAAkE;YAClE,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { IncomingMessage } from \"node:http\";\n\nfunction isJsonObject(obj: any): boolean {\n return obj && typeof obj === \"object\" && !Array.isArray(obj);\n}\n\nexport function toBase64JsonString(obj: Record<string, any>): string {\n return Buffer.from(JSON.stringify(obj)).toString(\"base64\");\n}\n\nexport function fromBase64JsonString(base64String: string | undefined): Record<string, any> {\n if (base64String === undefined) {\n return {};\n }\n\n try {\n const buf = Buffer.from(base64String, \"base64\").toString();\n const parsed = JSON.parse(buf);\n return isJsonObject(parsed) ? parsed : {};\n } catch (e: any) {\n console.warn(\"Unexpected state format:\" + e);\n return {};\n }\n}\n\nexport function getHttpHeader(req: IncomingMessage, key: string): string | undefined {\n if (!key) return undefined;\n\n // According to https://nodejs.org/api/http.html#http_class_http_incomingmessage, header names are always lower-cased\n const value = req.headers[key.toLowerCase()];\n\n if (value === undefined) {\n return undefined;\n }\n if (typeof value === \"string\") {\n return value;\n }\n\n return value[0];\n}\n\nexport function readRequestBody(req: IncomingMessage): Promise<Buffer> {\n return new Promise(function (resolve, reject) {\n const chunks: any = [];\n req.on(\"data\", function (chunk) {\n chunks.push(chunk);\n });\n req.on(\"end\", function () {\n const buffer = Buffer.concat(chunks);\n resolve(buffer);\n });\n // reject on request error\n req.on(\"error\", function (err) {\n // This is not a \"Second reject\", just a different sort of failure\n reject(err);\n });\n });\n}\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type express from "express-serve-static-core";
|
|
2
|
+
import type { WebPubSubEventHandlerOptions } from "./cloudEventsProtocols.js";
|
|
3
|
+
/**
|
|
4
|
+
* The handler to handle incoming CloudEvents messages
|
|
5
|
+
*/
|
|
6
|
+
export declare class WebPubSubEventHandler {
|
|
7
|
+
private hub;
|
|
8
|
+
/**
|
|
9
|
+
* The path this CloudEvents handler listens to
|
|
10
|
+
*/
|
|
11
|
+
readonly path: string;
|
|
12
|
+
private _cloudEventsHandler;
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of a WebPubSubEventHandler for handling incoming CloudEvents messages.
|
|
15
|
+
*
|
|
16
|
+
* Example usage:
|
|
17
|
+
* ```ts snippet:WebPubSubEventHandlerHandleMessages
|
|
18
|
+
* import { WebPubSubEventHandler } from "@azure/web-pubsub-express";
|
|
19
|
+
*
|
|
20
|
+
* const endpoint = "https://xxxx.webpubsubdev.azure.com";
|
|
21
|
+
* const handler = new WebPubSubEventHandler("chat", {
|
|
22
|
+
* handleConnect: (req, res) => {
|
|
23
|
+
* console.log(JSON.stringify(req));
|
|
24
|
+
* return {};
|
|
25
|
+
* },
|
|
26
|
+
* onConnected: (req) => {
|
|
27
|
+
* console.log(JSON.stringify(req));
|
|
28
|
+
* },
|
|
29
|
+
* handleUserEvent: (req, res) => {
|
|
30
|
+
* console.log(JSON.stringify(req));
|
|
31
|
+
* res.success("Hey " + req.data, req.dataType);
|
|
32
|
+
* },
|
|
33
|
+
* allowedEndpoints: [endpoint],
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @param hub - The name of the hub to listen to
|
|
38
|
+
* @param options - Options to configure the event handler
|
|
39
|
+
*/
|
|
40
|
+
constructor(hub: string, options?: WebPubSubEventHandlerOptions);
|
|
41
|
+
/**
|
|
42
|
+
* Get the middleware to process the CloudEvents requests
|
|
43
|
+
*/
|
|
44
|
+
getMiddleware(): express.RequestHandler;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=webPubSubEventHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webPubSubEventHandler.d.ts","sourceRoot":"","sources":["../../src/webPubSubEventHandler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,OAAO,MAAM,2BAA2B,CAAC;AAGrD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AAE9E;;GAEG;AACH,qBAAa,qBAAqB;IAoC9B,OAAO,CAAC,GAAG;IAnCb;;OAEG;IACH,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B,OAAO,CAAC,mBAAmB,CAAwB;IAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;gBAEO,GAAG,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,4BAA4B;IAOxC;;OAEG;IACI,aAAa,IAAI,OAAO,CAAC,cAAc;CA+B/C"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { CloudEventsDispatcher } from "./cloudEventsDispatcher.js";
|
|
4
|
+
/**
|
|
5
|
+
* The handler to handle incoming CloudEvents messages
|
|
6
|
+
*/
|
|
7
|
+
export class WebPubSubEventHandler {
|
|
8
|
+
/**
|
|
9
|
+
* Creates an instance of a WebPubSubEventHandler for handling incoming CloudEvents messages.
|
|
10
|
+
*
|
|
11
|
+
* Example usage:
|
|
12
|
+
* ```ts snippet:WebPubSubEventHandlerHandleMessages
|
|
13
|
+
* import { WebPubSubEventHandler } from "@azure/web-pubsub-express";
|
|
14
|
+
*
|
|
15
|
+
* const endpoint = "https://xxxx.webpubsubdev.azure.com";
|
|
16
|
+
* const handler = new WebPubSubEventHandler("chat", {
|
|
17
|
+
* handleConnect: (req, res) => {
|
|
18
|
+
* console.log(JSON.stringify(req));
|
|
19
|
+
* return {};
|
|
20
|
+
* },
|
|
21
|
+
* onConnected: (req) => {
|
|
22
|
+
* console.log(JSON.stringify(req));
|
|
23
|
+
* },
|
|
24
|
+
* handleUserEvent: (req, res) => {
|
|
25
|
+
* console.log(JSON.stringify(req));
|
|
26
|
+
* res.success("Hey " + req.data, req.dataType);
|
|
27
|
+
* },
|
|
28
|
+
* allowedEndpoints: [endpoint],
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @param hub - The name of the hub to listen to
|
|
33
|
+
* @param options - Options to configure the event handler
|
|
34
|
+
*/
|
|
35
|
+
constructor(hub, options) {
|
|
36
|
+
var _a;
|
|
37
|
+
this.hub = hub;
|
|
38
|
+
const path = ((_a = options === null || options === void 0 ? void 0 : options.path) !== null && _a !== void 0 ? _a : `/api/webpubsub/hubs/${hub}/`).toLowerCase();
|
|
39
|
+
this.path = path.endsWith("/") ? path : path + "/";
|
|
40
|
+
this._cloudEventsHandler = new CloudEventsDispatcher(this.hub, options);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get the middleware to process the CloudEvents requests
|
|
44
|
+
*/
|
|
45
|
+
getMiddleware() {
|
|
46
|
+
return async (req, res, next) => {
|
|
47
|
+
// Request originalUrl can contain query while baseUrl + path not
|
|
48
|
+
let requestUrl = (req.baseUrl + req.path).toLowerCase();
|
|
49
|
+
// normalize the Url
|
|
50
|
+
requestUrl = requestUrl.endsWith("/") ? requestUrl : requestUrl + "/";
|
|
51
|
+
if (requestUrl.startsWith(this.path)) {
|
|
52
|
+
if (req.method === "OPTIONS") {
|
|
53
|
+
if (this._cloudEventsHandler.handlePreflight(req, res)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else if (req.method === "POST") {
|
|
58
|
+
try {
|
|
59
|
+
if (await this._cloudEventsHandler.handleRequest(req, res)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
next(err);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
next();
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=webPubSubEventHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webPubSubEventHandler.js","sourceRoot":"","sources":["../../src/webPubSubEventHandler.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAGnE;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAQhC;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,YACU,GAAW,EACnB,OAAsC;;QAD9B,QAAG,GAAH,GAAG,CAAQ;QAGnB,MAAM,IAAI,GAAG,CAAC,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,mCAAI,uBAAuB,GAAG,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;QAC5E,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC;QACnD,IAAI,CAAC,mBAAmB,GAAG,IAAI,qBAAqB,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC1E,CAAC;IAED;;OAEG;IACI,aAAa;QAClB,OAAO,KAAK,EACV,GAAoB,EACpB,GAAqB,EACrB,IAA0B,EACX,EAAE;YACjB,iEAAiE;YACjE,IAAI,UAAU,GAAG,CAAC,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;YAExD,oBAAoB;YACpB,UAAU,GAAG,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,GAAG,GAAG,CAAC;YACtE,IAAI,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrC,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;oBAC7B,IAAI,IAAI,CAAC,mBAAmB,CAAC,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;wBACvD,OAAO;oBACT,CAAC;gBACH,CAAC;qBAAM,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;oBACjC,IAAI,CAAC;wBACH,IAAI,MAAM,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;4BAC3D,OAAO;wBACT,CAAC;oBACH,CAAC;oBAAC,OAAO,GAAQ,EAAE,CAAC;wBAClB,IAAI,CAAC,GAAG,CAAC,CAAC;wBACV,OAAO;oBACT,CAAC;gBACH,CAAC;YACH,CAAC;YAED,IAAI,EAAE,CAAC;QACT,CAAC,CAAC;IACJ,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type express from \"express-serve-static-core\";\n\nimport { CloudEventsDispatcher } from \"./cloudEventsDispatcher.js\";\nimport type { WebPubSubEventHandlerOptions } from \"./cloudEventsProtocols.js\";\n\n/**\n * The handler to handle incoming CloudEvents messages\n */\nexport class WebPubSubEventHandler {\n /**\n * The path this CloudEvents handler listens to\n */\n public readonly path: string;\n\n private _cloudEventsHandler: CloudEventsDispatcher;\n\n /**\n * Creates an instance of a WebPubSubEventHandler for handling incoming CloudEvents messages.\n *\n * Example usage:\n * ```ts snippet:WebPubSubEventHandlerHandleMessages\n * import { WebPubSubEventHandler } from \"@azure/web-pubsub-express\";\n *\n * const endpoint = \"https://xxxx.webpubsubdev.azure.com\";\n * const handler = new WebPubSubEventHandler(\"chat\", {\n * handleConnect: (req, res) => {\n * console.log(JSON.stringify(req));\n * return {};\n * },\n * onConnected: (req) => {\n * console.log(JSON.stringify(req));\n * },\n * handleUserEvent: (req, res) => {\n * console.log(JSON.stringify(req));\n * res.success(\"Hey \" + req.data, req.dataType);\n * },\n * allowedEndpoints: [endpoint],\n * });\n * ```\n *\n * @param hub - The name of the hub to listen to\n * @param options - Options to configure the event handler\n */\n constructor(\n private hub: string,\n options?: WebPubSubEventHandlerOptions,\n ) {\n const path = (options?.path ?? `/api/webpubsub/hubs/${hub}/`).toLowerCase();\n this.path = path.endsWith(\"/\") ? path : path + \"/\";\n this._cloudEventsHandler = new CloudEventsDispatcher(this.hub, options);\n }\n\n /**\n * Get the middleware to process the CloudEvents requests\n */\n public getMiddleware(): express.RequestHandler {\n return async (\n req: express.Request,\n res: express.Response,\n next: express.NextFunction,\n ): Promise<void> => {\n // Request originalUrl can contain query while baseUrl + path not\n let requestUrl = (req.baseUrl + req.path).toLowerCase();\n\n // normalize the Url\n requestUrl = requestUrl.endsWith(\"/\") ? requestUrl : requestUrl + \"/\";\n if (requestUrl.startsWith(this.path)) {\n if (req.method === \"OPTIONS\") {\n if (this._cloudEventsHandler.handlePreflight(req, res)) {\n return;\n }\n } else if (req.method === \"POST\") {\n try {\n if (await this._cloudEventsHandler.handleRequest(req, res)) {\n return;\n }\n } catch (err: any) {\n next(err);\n return;\n }\n }\n }\n\n next();\n };\n }\n}\n"]}
|