@azure/web-pubsub-express 1.0.6-alpha.20250619.1 → 1.0.6-alpha.20250730.1

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.
@@ -1 +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"]}
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;IAoCtB;IAnCV;;OAEG;IACa,IAAI,CAAS;IAErB,mBAAmB,CAAwB;IAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,YACU,GAAW,EACnB,OAAsC;QAD9B,QAAG,GAAH,GAAG,CAAQ;QAGnB,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE,IAAI,IAAI,uBAAuB,GAAG,GAAG,CAAC,CAAC,WAAW,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ourcesContent":["// 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,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure/web-pubsub-express",
3
- "version": "1.0.6-alpha.20250619.1",
3
+ "version": "1.0.6-alpha.20250730.1",
4
4
  "description": "Azure Web PubSub CloudEvents handlers",
5
5
  "sdk-type": "client",
6
6
  "scripts": {
@@ -68,7 +68,7 @@
68
68
  ]
69
69
  },
70
70
  "tshy": {
71
- "project": "./tsconfig.src.json",
71
+ "project": "../../../tsconfig.src.build.json",
72
72
  "exports": {
73
73
  "./package.json": "./package.json",
74
74
  ".": "./src/index.ts"