@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 @@
|
|
|
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"]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure/web-pubsub-express",
|
|
3
|
-
"version": "1.0.6
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Azure Web PubSub CloudEvents handlers",
|
|
5
5
|
"sdk-type": "client",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"build": "npm run clean && dev-tool run build-package && dev-tool run
|
|
7
|
+
"build": "npm run clean && dev-tool run build-package && dev-tool run extract-api",
|
|
8
8
|
"build:browser": "echo \"Browser is not supported.\" && exit 0",
|
|
9
9
|
"build:node": "dev-tool run build-package",
|
|
10
10
|
"build:samples": "echo Obsolete.",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node",
|
|
26
26
|
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
|
|
27
27
|
"unit-test:browser": "echo \"Browser is not supported.\" && exit 0",
|
|
28
|
-
"unit-test:node": "dev-tool run test:vitest
|
|
29
|
-
"update-snippets": "
|
|
28
|
+
"unit-test:node": "dev-tool run test:vitest",
|
|
29
|
+
"update-snippets": "dev-tool run update-snippets"
|
|
30
30
|
},
|
|
31
31
|
"files": [
|
|
32
32
|
"dist/",
|
|
@@ -49,23 +49,25 @@
|
|
|
49
49
|
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/web-pubsub/web-pubsub-express/README.md",
|
|
50
50
|
"sideEffects": false,
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@azure/logger": "^1.1.
|
|
53
|
-
"tslib": "^2.
|
|
52
|
+
"@azure/logger": "^1.1.4",
|
|
53
|
+
"tslib": "^2.8.1"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@azure/
|
|
57
|
-
"@azure/
|
|
58
|
-
"@
|
|
59
|
-
"@types/express
|
|
56
|
+
"@azure-tools/test-utils-vitest": "^1.0.0",
|
|
57
|
+
"@azure/dev-tool": "^1.0.0",
|
|
58
|
+
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
|
|
59
|
+
"@types/express": "^4.17.21",
|
|
60
|
+
"@types/express-serve-static-core": "^4.19.5",
|
|
60
61
|
"@types/jsonwebtoken": "^9.0.0",
|
|
61
62
|
"@types/node": "^18.0.0",
|
|
62
|
-
"@vitest/browser": "^3.0.
|
|
63
|
-
"@vitest/coverage-istanbul": "^3.0.
|
|
63
|
+
"@vitest/browser": "^3.0.6",
|
|
64
|
+
"@vitest/coverage-istanbul": "^3.0.6",
|
|
64
65
|
"dotenv": "^16.0.0",
|
|
65
66
|
"eslint": "^9.9.0",
|
|
66
|
-
"express": "^4.
|
|
67
|
+
"express": "^4.21.2",
|
|
68
|
+
"playwright": "^1.50.1",
|
|
67
69
|
"typescript": "~5.7.2",
|
|
68
|
-
"vitest": "^3.0.
|
|
70
|
+
"vitest": "^3.0.6"
|
|
69
71
|
},
|
|
70
72
|
"//sampleConfiguration": {
|
|
71
73
|
"productName": "Azure Web PubSub CloudEvents Handlers for Express",
|
|
@@ -74,6 +76,7 @@
|
|
|
74
76
|
]
|
|
75
77
|
},
|
|
76
78
|
"tshy": {
|
|
79
|
+
"project": "./tsconfig.src.json",
|
|
77
80
|
"exports": {
|
|
78
81
|
"./package.json": "./package.json",
|
|
79
82
|
".": "./src/index.ts"
|
|
@@ -82,12 +85,23 @@
|
|
|
82
85
|
"esm",
|
|
83
86
|
"commonjs"
|
|
84
87
|
],
|
|
85
|
-
"
|
|
86
|
-
|
|
88
|
+
"esmDialects": [
|
|
89
|
+
"browser",
|
|
90
|
+
"react-native"
|
|
91
|
+
],
|
|
92
|
+
"selfLink": false
|
|
87
93
|
},
|
|
88
94
|
"exports": {
|
|
89
95
|
"./package.json": "./package.json",
|
|
90
96
|
".": {
|
|
97
|
+
"browser": {
|
|
98
|
+
"types": "./dist/browser/index.d.ts",
|
|
99
|
+
"default": "./dist/browser/index.js"
|
|
100
|
+
},
|
|
101
|
+
"react-native": {
|
|
102
|
+
"types": "./dist/react-native/index.d.ts",
|
|
103
|
+
"default": "./dist/react-native/index.js"
|
|
104
|
+
},
|
|
91
105
|
"import": {
|
|
92
106
|
"types": "./dist/esm/index.d.ts",
|
|
93
107
|
"default": "./dist/esm/index.js"
|
|
@@ -101,5 +115,7 @@
|
|
|
101
115
|
"main": "./dist/commonjs/index.js",
|
|
102
116
|
"types": "./dist/commonjs/index.d.ts",
|
|
103
117
|
"type": "module",
|
|
104
|
-
"module": "./dist/esm/index.js"
|
|
118
|
+
"module": "./dist/esm/index.js",
|
|
119
|
+
"browser": "./dist/browser/index.js",
|
|
120
|
+
"react-native": "./dist/react-native/index.js"
|
|
105
121
|
}
|