@azure/web-pubsub-express 1.0.6-alpha.20231214.1 → 1.0.6-alpha.20240112.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.
package/dist/index.js CHANGED
@@ -99,7 +99,7 @@ function getConnectResponseHandler(connectRequest, response) {
99
99
  },
100
100
  fail(code, detail) {
101
101
  response.statusCode = code;
102
- response.end(detail !== null && detail !== void 0 ? detail : "");
102
+ response.end(detail ?? "");
103
103
  },
104
104
  };
105
105
  return handler;
@@ -128,11 +128,11 @@ function getUserEventResponseHandler(userRequest, response) {
128
128
  response.setHeader("Content-Type", "application/octet-stream");
129
129
  break;
130
130
  }
131
- response.end(data !== null && data !== void 0 ? data : "");
131
+ response.end(data ?? "");
132
132
  },
133
133
  fail(code, detail) {
134
134
  response.statusCode = code;
135
- response.end(detail !== null && detail !== void 0 ? detail : "");
135
+ response.end(detail ?? "");
136
136
  },
137
137
  };
138
138
  return handler;
@@ -158,7 +158,7 @@ function tryGetWebPubSubEvent(req) {
158
158
  const disconnectd = "azure.webpubsub.sys.disconnected";
159
159
  const userPrefix = "azure.webpubsub.user.";
160
160
  const type = getHttpHeader(req, "ce-type");
161
- if (!(type === null || type === void 0 ? void 0 : type.startsWith(prefix))) {
161
+ if (!type?.startsWith(prefix)) {
162
162
  return undefined;
163
163
  }
164
164
  if (type.startsWith(userPrefix)) {
@@ -225,7 +225,7 @@ class CloudEventsDispatcher {
225
225
  if (Array.isArray(eventHandler)) {
226
226
  throw new Error("Unexpected WebPubSubEventHandlerOptions");
227
227
  }
228
- if ((eventHandler === null || eventHandler === void 0 ? void 0 : eventHandler.allowedEndpoints) !== undefined) {
228
+ if (eventHandler?.allowedEndpoints !== undefined) {
229
229
  this._allowedOrigins = eventHandler.allowedEndpoints.map((endpoint) => new url.URL(endpoint).host.toLowerCase());
230
230
  this._allowAll = false;
231
231
  }
@@ -250,7 +250,6 @@ class CloudEventsDispatcher {
250
250
  return true;
251
251
  }
252
252
  async handleRequest(request, response) {
253
- var _a, _b, _c, _d;
254
253
  if (!isWebPubSubRequest(request)) {
255
254
  return false;
256
255
  }
@@ -265,31 +264,31 @@ class CloudEventsDispatcher {
265
264
  }
266
265
  // check if hub matches
267
266
  const hub = getHttpHeader(request, "ce-hub");
268
- if ((hub === null || hub === void 0 ? void 0 : hub.toUpperCase()) !== this.hub.toUpperCase()) {
267
+ if (hub?.toUpperCase() !== this.hub.toUpperCase()) {
269
268
  return false;
270
269
  }
271
270
  // No need to read body if handler is not specified
272
271
  switch (eventType) {
273
272
  case EventType.Connect:
274
- if (!((_a = this.eventHandler) === null || _a === void 0 ? void 0 : _a.handleConnect)) {
273
+ if (!this.eventHandler?.handleConnect) {
275
274
  response.end();
276
275
  return true;
277
276
  }
278
277
  break;
279
278
  case EventType.Connected:
280
- if (!((_b = this.eventHandler) === null || _b === void 0 ? void 0 : _b.onConnected)) {
279
+ if (!this.eventHandler?.onConnected) {
281
280
  response.end();
282
281
  return true;
283
282
  }
284
283
  break;
285
284
  case EventType.Disconnected:
286
- if (!((_c = this.eventHandler) === null || _c === void 0 ? void 0 : _c.onDisconnected)) {
285
+ if (!this.eventHandler?.onDisconnected) {
287
286
  response.end();
288
287
  return true;
289
288
  }
290
289
  break;
291
290
  case EventType.UserEvent:
292
- if (!((_d = this.eventHandler) === null || _d === void 0 ? void 0 : _d.handleUserEvent)) {
291
+ if (!this.eventHandler?.handleUserEvent) {
293
292
  response.end();
294
293
  return true;
295
294
  }
@@ -375,9 +374,8 @@ class WebPubSubEventHandler {
375
374
  * @param options - Options to configure the event handler
376
375
  */
377
376
  constructor(hub, options) {
378
- var _a;
379
377
  this.hub = hub;
380
- const path = ((_a = options === null || options === void 0 ? void 0 : options.path) !== null && _a !== void 0 ? _a : `/api/webpubsub/hubs/${hub}/`).toLowerCase();
378
+ const path = (options?.path ?? `/api/webpubsub/hubs/${hub}/`).toLowerCase();
381
379
  this.path = path.endsWith("/") ? path : path + "/";
382
380
  this._cloudEventsHandler = new CloudEventsDispatcher(this.hub, options);
383
381
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/utils.ts","../src/logger.ts","../src/cloudEventsDispatcher.ts","../src/webPubSubEventHandler.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { IncomingMessage } from \"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","// 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","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as utils from \"./utils\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport { URL } from \"url\";\nimport { logger } from \"./logger\";\n\nimport {\n ConnectRequest,\n ConnectResponse,\n ConnectedRequest,\n ConnectionContext,\n ConnectResponseHandler,\n DisconnectedRequest,\n UserEventRequest,\n UserEventResponseHandler,\n WebPubSubEventHandlerOptions,\n} from \"./cloudEventsProtocols\";\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 response.statusCode = 200;\n if (modified) {\n response.setHeader(\"ce-connectionState\", utils.toBase64JsonString(states));\n }\n if (res === undefined) {\n response.end();\n } else {\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 response.statusCode = code;\n response.end(detail ?? \"\");\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 context = {\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 };\n\n // TODO: validation\n return context;\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 isWebPubSubRequest(req: IncomingMessage): boolean {\n return utils.getHttpHeader(req, \"ce-awpsversion\") !== undefined;\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(private hub: string, private eventHandler?: WebPubSubEventHandlerOptions) {\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 // No need to read body if handler is not specified\n switch (eventType) {\n case EventType.Connect:\n if (!this.eventHandler?.handleConnect) {\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 = 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\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 = await readSystemEventRequest<DisconnectedRequest>(\n request,\n origin\n );\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","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport express from \"express-serve-static-core\";\n\nimport { CloudEventsDispatcher } from \"./cloudEventsDispatcher\";\nimport { WebPubSubEventHandlerOptions } from \"./cloudEventsProtocols\";\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\n * import express from \"express\";\n * import { WebPubSubEventHandler } from \"@azure/web-pubsub-express\";\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 *\n * @param hub - The name of the hub to listen to\n * @param options - Options to configure the event handler\n */\n constructor(private hub: string, options?: WebPubSubEventHandlerOptions) {\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"],"names":["createClientLogger","utils.toBase64JsonString","utils.getHttp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B,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;KACzE;AAED;;AAEG;IACI,aAAa,GAAA;QAClB,OAAO,OACL,GAAoB,EACpB,GAAqB,EACrB,IAA0B,KACT;;AAEjB,YAAA,IAAI,UAAU,GAAG,CAAC,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,WAAW,EAAE,CAAC;;AAGxD,YAAA,UAAU,GAAG,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,UAAU,GAAG,UAAU,GAAG,GAAG,CAAC;YACtE,IAAI,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AACpC,gBAAA,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS,EAAE;oBAC5B,IAAI,IAAI,CAAC,mBAAmB,CAAC,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE;wBACtD,OAAO;AACR,qBAAA;AACF,iBAAA;AAAM,qBAAA,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,EAAE;oBAChC,IAAI;wBACF,IAAI,MAAM,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE;4BAC1D,OAAO;AACR,yBAAA;AACF,qBAAA;AAAC,oBAAA,OAAO,GAAQ,EAAE;wBACjB,IAAI,CAAC,GAAG,CAAC,CAAC;wBACV,OAAO;AACR,qBAAA;AACF,iBAAA;AACF,aAAA;AAED,YAAA,IAAI,EAAE,CAAC;AACT,SAAC,CAAC;KACH;AACF;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/utils.ts","../src/logger.ts","../src/cloudEventsDispatcher.ts","../src/webPubSubEventHandler.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { IncomingMessage } from \"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","// 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","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as utils from \"./utils\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport { URL } from \"url\";\nimport { logger } from \"./logger\";\n\nimport {\n ConnectRequest,\n ConnectResponse,\n ConnectedRequest,\n ConnectionContext,\n ConnectResponseHandler,\n DisconnectedRequest,\n UserEventRequest,\n UserEventResponseHandler,\n WebPubSubEventHandlerOptions,\n} from \"./cloudEventsProtocols\";\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 response.statusCode = 200;\n if (modified) {\n response.setHeader(\"ce-connectionState\", utils.toBase64JsonString(states));\n }\n if (res === undefined) {\n response.end();\n } else {\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 response.statusCode = code;\n response.end(detail ?? \"\");\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 context = {\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 };\n\n // TODO: validation\n return context;\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 isWebPubSubRequest(req: IncomingMessage): boolean {\n return utils.getHttpHeader(req, \"ce-awpsversion\") !== undefined;\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 // No need to read body if handler is not specified\n switch (eventType) {\n case EventType.Connect:\n if (!this.eventHandler?.handleConnect) {\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 = 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\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 = await readSystemEventRequest<DisconnectedRequest>(\n request,\n origin,\n );\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","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport express from \"express-serve-static-core\";\n\nimport { CloudEventsDispatcher } from \"./cloudEventsDispatcher\";\nimport { WebPubSubEventHandlerOptions } from \"./cloudEventsProtocols\";\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\n * import express from \"express\";\n * import { WebPubSubEventHandler } from \"@azure/web-pubsub-express\";\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 *\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"],"names":["createClientLogger","utils.toBase64JsonString","utils.getHttpHeader","utils.fromBase64JsonString","utils.readRequestBody","URL"],"mappings":";;;;;;;AAAA;AACA;AAIA,SAAS,YAAY,CAAC,GAAQ,EAAA;AAC5B,IAAA,OAAO,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAC/D,CAAC;AAEK,SAAU,kBAAkB,CAAC,GAAwB,EAAA;AACzD,IAAA,OAAO,MAAM,CAAC,IAAI,CAAC,IAA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AAM,OAAO,GAAG,IAAI,qBAAqB,CAAC,MAAM,EAAE;IAChD,aAAa,CAAC,GAAG,EAAE,GAAG;QACpB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjB,+FAA+F;QAC/F,GAAG,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;QAC9B,GAAG,CAAC,OAAO,EAAE,CAAC;QACd,UAAU;QACV,iBAAiB;IACnB,CAAC;IACD,WAAW,CAAC,gBAAgB;QAC1B,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAChC,CAAC;IACD,eAAe,CAAC,GAAG,EAAE,GAAG;QACtB,IAAI,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QACjD,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACxB,kCAAkC;QAClC,GAAG,CAAC,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;QACvC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC/B,CAAC;IACD,gBAAgB,EAAE,CAAC,iCAAiC,CAAC;CACtD,CAAC,CAAC;AAEH,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;AAEtB,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;AAEjC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,CACpB,OAAO,CAAC,GAAG,CAAC,0DAA0D,OAAO,CAAC,IAAI,EAAE,CAAC,CACtF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * @summary Demonstrates handling Web PubSub CloudEvents with Express\n */\n\nimport { WebPubSubEventHandler } from \"@azure/web-pubsub-express\";\nimport express from \"express\";\n\nconst handler = new WebPubSubEventHandler(\"chat\", {\n handleConnect(req, res) {\n console.log(req);\n // You can set the state for the connection, it lasts throughout the lifetime of the connection\n res.setState(\"calledTime\", 1);\n res.success();\n // or fail\n // res.fail(401);\n },\n onConnected(connectedRequest) {\n console.log(connectedRequest);\n },\n handleUserEvent(req, res) {\n var calledTime = req.context.states.calledTime++;\n console.log(calledTime);\n // You can also set the state here\n res.setState(\"calledTime\", calledTime);\n res.success(\"Hello\", \"text\");\n },\n allowedEndpoints: [\"https://xxx.webpubsub.azure.com\"],\n});\n\nconst app = express();\n\napp.use(handler.getMiddleware());\n\napp.listen(3000, () =>\n console.log(`Azure WebPubSub Upstream ready at http://localhost:3000${handler.path}`)\n);\n"]}
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../samples-dev/server.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;GAEG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,MAAM,OAAO,GAAG,IAAI,qBAAqB,CAAC,MAAM,EAAE;IAChD,aAAa,CAAC,GAAG,EAAE,GAAG;QACpB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjB,+FAA+F;QAC/F,GAAG,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;QAC9B,GAAG,CAAC,OAAO,EAAE,CAAC;QACd,UAAU;QACV,iBAAiB;IACnB,CAAC;IACD,WAAW,CAAC,gBAAgB;QAC1B,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAChC,CAAC;IACD,eAAe,CAAC,GAAG,EAAE,GAAG;QACtB,IAAI,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QACjD,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACxB,kCAAkC;QAClC,GAAG,CAAC,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;QACvC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC/B,CAAC;IACD,gBAAgB,EAAE,CAAC,iCAAiC,CAAC;CACtD,CAAC,CAAC;AAEH,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;AAEtB,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;AAEjC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,CACpB,OAAO,CAAC,GAAG,CAAC,0DAA0D,OAAO,CAAC,IAAI,EAAE,CAAC,CACtF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * @summary Demonstrates handling Web PubSub CloudEvents with Express\n */\n\nimport { WebPubSubEventHandler } from \"@azure/web-pubsub-express\";\nimport express from \"express\";\n\nconst handler = new WebPubSubEventHandler(\"chat\", {\n handleConnect(req, res) {\n console.log(req);\n // You can set the state for the connection, it lasts throughout the lifetime of the connection\n res.setState(\"calledTime\", 1);\n res.success();\n // or fail\n // res.fail(401);\n },\n onConnected(connectedRequest) {\n console.log(connectedRequest);\n },\n handleUserEvent(req, res) {\n var calledTime = req.context.states.calledTime++;\n console.log(calledTime);\n // You can also set the state here\n res.setState(\"calledTime\", calledTime);\n res.success(\"Hello\", \"text\");\n },\n allowedEndpoints: [\"https://xxx.webpubsub.azure.com\"],\n});\n\nconst app = express();\n\napp.use(handler.getMiddleware());\n\napp.listen(3000, () =>\n console.log(`Azure WebPubSub Upstream ready at http://localhost:3000${handler.path}`),\n);\n"]}
@@ -33,7 +33,7 @@ function getConnectResponseHandler(connectRequest, response) {
33
33
  },
34
34
  fail(code, detail) {
35
35
  response.statusCode = code;
36
- response.end(detail !== null && detail !== void 0 ? detail : "");
36
+ response.end(detail ?? "");
37
37
  },
38
38
  };
39
39
  return handler;
@@ -62,11 +62,11 @@ function getUserEventResponseHandler(userRequest, response) {
62
62
  response.setHeader("Content-Type", "application/octet-stream");
63
63
  break;
64
64
  }
65
- response.end(data !== null && data !== void 0 ? data : "");
65
+ response.end(data ?? "");
66
66
  },
67
67
  fail(code, detail) {
68
68
  response.statusCode = code;
69
- response.end(detail !== null && detail !== void 0 ? detail : "");
69
+ response.end(detail ?? "");
70
70
  },
71
71
  };
72
72
  return handler;
@@ -92,7 +92,7 @@ function tryGetWebPubSubEvent(req) {
92
92
  const disconnectd = "azure.webpubsub.sys.disconnected";
93
93
  const userPrefix = "azure.webpubsub.user.";
94
94
  const type = utils.getHttpHeader(req, "ce-type");
95
- if (!(type === null || type === void 0 ? void 0 : type.startsWith(prefix))) {
95
+ if (!type?.startsWith(prefix)) {
96
96
  return undefined;
97
97
  }
98
98
  if (type.startsWith(userPrefix)) {
@@ -159,7 +159,7 @@ export class CloudEventsDispatcher {
159
159
  if (Array.isArray(eventHandler)) {
160
160
  throw new Error("Unexpected WebPubSubEventHandlerOptions");
161
161
  }
162
- if ((eventHandler === null || eventHandler === void 0 ? void 0 : eventHandler.allowedEndpoints) !== undefined) {
162
+ if (eventHandler?.allowedEndpoints !== undefined) {
163
163
  this._allowedOrigins = eventHandler.allowedEndpoints.map((endpoint) => new URL(endpoint).host.toLowerCase());
164
164
  this._allowAll = false;
165
165
  }
@@ -184,7 +184,6 @@ export class CloudEventsDispatcher {
184
184
  return true;
185
185
  }
186
186
  async handleRequest(request, response) {
187
- var _a, _b, _c, _d;
188
187
  if (!isWebPubSubRequest(request)) {
189
188
  return false;
190
189
  }
@@ -199,31 +198,31 @@ export class CloudEventsDispatcher {
199
198
  }
200
199
  // check if hub matches
201
200
  const hub = utils.getHttpHeader(request, "ce-hub");
202
- if ((hub === null || hub === void 0 ? void 0 : hub.toUpperCase()) !== this.hub.toUpperCase()) {
201
+ if (hub?.toUpperCase() !== this.hub.toUpperCase()) {
203
202
  return false;
204
203
  }
205
204
  // No need to read body if handler is not specified
206
205
  switch (eventType) {
207
206
  case EventType.Connect:
208
- if (!((_a = this.eventHandler) === null || _a === void 0 ? void 0 : _a.handleConnect)) {
207
+ if (!this.eventHandler?.handleConnect) {
209
208
  response.end();
210
209
  return true;
211
210
  }
212
211
  break;
213
212
  case EventType.Connected:
214
- if (!((_b = this.eventHandler) === null || _b === void 0 ? void 0 : _b.onConnected)) {
213
+ if (!this.eventHandler?.onConnected) {
215
214
  response.end();
216
215
  return true;
217
216
  }
218
217
  break;
219
218
  case EventType.Disconnected:
220
- if (!((_c = this.eventHandler) === null || _c === void 0 ? void 0 : _c.onDisconnected)) {
219
+ if (!this.eventHandler?.onDisconnected) {
221
220
  response.end();
222
221
  return true;
223
222
  }
224
223
  break;
225
224
  case EventType.UserEvent:
226
- if (!((_d = this.eventHandler) === null || _d === void 0 ? void 0 : _d.handleUserEvent)) {
225
+ if (!this.eventHandler?.handleUserEvent) {
227
226
  response.end();
228
227
  return true;
229
228
  }
@@ -1 +1 @@
1
- {"version":3,"file":"cloudEventsDispatcher.js","sourceRoot":"","sources":["../../src/cloudEventsDispatcher.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAclC,IAAK,SAKJ;AALD,WAAK,SAAS;IACZ,+CAAO,CAAA;IACP,mDAAS,CAAA;IACT,yDAAY,CAAA;IACZ,mDAAS,CAAA;AACX,CAAC,EALI,SAAS,KAAT,SAAS,QAKb;AAED,SAAS,yBAAyB,CAChC,cAA8B,EAC9B,QAAwB;IAExB,MAAM,MAAM,GAAwB,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC;IAClE,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,MAAM,OAAO,GAAG;QACd,QAAQ,CAAC,IAAY,EAAE,KAAc;YACnC,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;YACrB,QAAQ,GAAG,IAAI,CAAC;QAClB,CAAC;QACD,OAAO,CAAC,GAAqB;YAC3B,QAAQ,CAAC,UAA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K,CAAC,aAAa,CAAC,OAAO,EAAE,cAAc,CAAC,EAAE,CAC3E,CAAC;oBACF,OAAO,KAAK,CAAC;iBACd;gBACD,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;gBAC5B,IAAI,CAAC,YAAY,CAAC,eAAgB,CAChC,WAAW,EACX,2BAA2B,CAAC,WAAW,EAAE,QAAQ,CAAC,CACnD,CAAC;gBACF,OAAO,IAAI,CAAC;aACb;YACD;gBACE,MAAM,CAAC,OAAO,CAAC,qBAAqB,SAAS,EAAE,CAAC,CAAC;gBACjD,OAAO,KAAK,CAAC;SAChB;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as utils from \"./utils\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport { URL } from \"url\";\nimport { logger } from \"./logger\";\n\nimport {\n ConnectRequest,\n ConnectResponse,\n ConnectedRequest,\n ConnectionContext,\n ConnectResponseHandler,\n DisconnectedRequest,\n UserEventRequest,\n UserEventResponseHandler,\n WebPubSubEventHandlerOptions,\n} from \"./cloudEventsProtocols\";\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 response.statusCode = 200;\n if (modified) {\n response.setHeader(\"ce-connectionState\", utils.toBase64JsonString(states));\n }\n if (res === undefined) {\n response.end();\n } else {\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 response.statusCode = code;\n response.end(detail ?? \"\");\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 context = {\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 };\n\n // TODO: validation\n return context;\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 isWebPubSubRequest(req: IncomingMessage): boolean {\n return utils.getHttpHeader(req, \"ce-awpsversion\") !== undefined;\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(private hub: string, private eventHandler?: WebPubSubEventHandlerOptions) {\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 // No need to read body if handler is not specified\n switch (eventType) {\n case EventType.Connect:\n if (!this.eventHandler?.handleConnect) {\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 = 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\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 = await readSystemEventRequest<DisconnectedRequest>(\n request,\n origin\n );\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"]}
1
+ {"version":3,"file":"cloudEventsDispatcher.js","sourceRoot":"","sources":["../../src/cloudEventsDispatcher.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAclC,IAAK,SAKJ;AALD,WAAK,SAAS;IACZ,+CAAO,CAAA;IACP,mDAAS,CAAA;IACT,yDAAY,CAAA;IACZ,mDAAS,CAAA;AACX,CAAC,EALI,SAAS,KAAT,SAAS,QAKb;AAED,SAAS,yBAAyB,CAChC,cAA8B,EAC9B,QAAwB;IAExB,MAAM,MAAM,GAAwB,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC;IAClE,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,MAAM,OAAO,GAAG;QACd,QAAQ,CAAC,IAAY,EAAE,KAAc;YACnC,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;YACrB,QAAQ,GAAG,IAAI,CAAC;QAClB,CAAC;QACD,OAAO,CAAC,GAAqB;YAC3B,QAAQ,CAAC,UAAU,GAAG,GAAG,CAAC;YAC1B,IAAI,QAAQ,EAAE;gBACZ,QAAQ,CAAC,SAAS,CAAC,oBAAoB,EAAE,KAAK,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC;aAC5E;YACD,IAAI,GAAG,KAAK,SAAS,EAAE;gBACrB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\"./utils\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport { URL } from \"url\";\nimport { logger } from \"./logger\";\n\nimport {\n ConnectRequest,\n ConnectResponse,\n ConnectedRequest,\n ConnectionContext,\n ConnectResponseHandler,\n DisconnectedRequest,\n UserEventRequest,\n UserEventResponseHandler,\n WebPubSubEventHandlerOptions,\n} from \"./cloudEventsProtocols\";\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 response.statusCode = 200;\n if (modified) {\n response.setHeader(\"ce-connectionState\", utils.toBase64JsonString(states));\n }\n if (res === undefined) {\n response.end();\n } else {\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 response.statusCode = code;\n response.end(detail ?? \"\");\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 context = {\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 };\n\n // TODO: validation\n return context;\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 isWebPubSubRequest(req: IncomingMessage): boolean {\n return utils.getHttpHeader(req, \"ce-awpsversion\") !== undefined;\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 // No need to read body if handler is not specified\n switch (eventType) {\n case EventType.Connect:\n if (!this.eventHandler?.handleConnect) {\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 = 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\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 = await readSystemEventRequest<DisconnectedRequest>(\n request,\n origin,\n );\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"]}
@@ -1 +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\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 * The connection context representing the client WebSocket connection.\n */\nexport interface ConnectionContext {\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\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 * 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 * 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): 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\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"]}
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\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 * The connection context representing the client WebSocket connection.\n */\nexport interface ConnectionContext {\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\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 * 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 * 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): 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\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"]}
@@ -34,9 +34,8 @@ export class WebPubSubEventHandler {
34
34
  * @param options - Options to configure the event handler
35
35
  */
36
36
  constructor(hub, options) {
37
- var _a;
38
37
  this.hub = hub;
39
- const path = ((_a = options === null || options === void 0 ? void 0 : options.path) !== null && _a !== void 0 ? _a : `/api/webpubsub/hubs/${hub}/`).toLowerCase();
38
+ const path = (options?.path ?? `/api/webpubsub/hubs/${hub}/`).toLowerCase();
40
39
  this.path = path.endsWith("/") ? path : path + "/";
41
40
  this._cloudEventsHandler = new CloudEventsDispatcher(this.hub, options);
42
41
  }
@@ -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,yBAAyB,CAAC;AAGhE;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAQhC;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,YAAoB,GAAW,EAAE,OAAsC;;QAAnD,QAAG,GAAH,GAAG,CAAQ;QAC7B,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;gBACpC,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS,EAAE;oBAC5B,IAAI,IAAI,CAAC,mBAAmB,CAAC,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE;wBACtD,OAAO;qBACR;iBACF;qBAAM,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,EAAE;oBAChC,IAAI;wBACF,IAAI,MAAM,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE;4BAC1D,OAAO;yBACR;qBACF;oBAAC,OAAO,GAAQ,EAAE;wBACjB,IAAI,CAAC,GAAG,CAAC,CAAC;wBACV,OAAO;qBACR;iBACF;aACF;YAED,IAAI,EAAE,CAAC;QACT,CAAC,CAAC;IACJ,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport express from \"express-serve-static-core\";\n\nimport { CloudEventsDispatcher } from \"./cloudEventsDispatcher\";\nimport { WebPubSubEventHandlerOptions } from \"./cloudEventsProtocols\";\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\n * import express from \"express\";\n * import { WebPubSubEventHandler } from \"@azure/web-pubsub-express\";\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 *\n * @param hub - The name of the hub to listen to\n * @param options - Options to configure the event handler\n */\n constructor(private hub: string, options?: WebPubSubEventHandlerOptions) {\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,yBAAyB,CAAC;AAGhE;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAQhC;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;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,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;gBACpC,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS,EAAE;oBAC5B,IAAI,IAAI,CAAC,mBAAmB,CAAC,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE;wBACtD,OAAO;qBACR;iBACF;qBAAM,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,EAAE;oBAChC,IAAI;wBACF,IAAI,MAAM,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE;4BAC1D,OAAO;yBACR;qBACF;oBAAC,OAAO,GAAQ,EAAE;wBACjB,IAAI,CAAC,GAAG,CAAC,CAAC;wBACV,OAAO;qBACR;iBACF;aACF;YAED,IAAI,EAAE,CAAC;QACT,CAAC,CAAC;IACJ,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport express from \"express-serve-static-core\";\n\nimport { CloudEventsDispatcher } from \"./cloudEventsDispatcher\";\nimport { WebPubSubEventHandlerOptions } from \"./cloudEventsProtocols\";\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\n * import express from \"express\";\n * import { WebPubSubEventHandler } from \"@azure/web-pubsub-express\";\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 *\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;\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yright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { CloudEventsDispatcher } from \"../src/cloudEventsDispatcher\";\nimport { assert } from \"chai\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport { Socket } from \"net\";\nimport * as sinon from \"sinon\";\nimport { toBase64JsonString } from \"../src/utils\";\n\nfunction buildRequest(\n req: IncomingMessage,\n hub: string,\n connectionId: string,\n userId?: string,\n states?: string\n): void {\n req.headers[\"webhook-request-origin\"] = \"xxx.webpubsub.azure.com\";\n req.headers[\"content-type\"] = \"application/json; charset=utf-8\";\n req.headers[\"ce-awpsversion\"] = \"1.0\";\n req.headers[\"ce-specversion\"] = \"1.0\";\n req.headers[\"ce-type\"] = \"azure.webpubsub.sys.connect\";\n req.headers[\"ce-source\"] = `/hubs/${hub}/client/${connectionId}`;\n req.headers[\"ce-id\"] = \"1\";\n req.headers[\"ce-time\"] = new Date().toUTCString();\n if (userId !== undefined) {\n req.headers[\"ce-userId\"] = userId;\n }\n req.headers[\"ce-connectionId\"] = connectionId;\n req.headers[\"ce-hub\"] = hub;\n req.headers[\"ce-event\"] = \"connect\";\n req.headers[\"ce-connectionstate\"] = states;\n}\n\nfunction mockBody(req: IncomingMessage, body: string): void {\n req.emit(\"data\", Buffer.from(body, \"utf-8\"));\n req.emit(\"end\");\n}\n\ndescribe(\"Can handle connect event\", function () {\n let req: IncomingMessage;\n let res: ServerResponse;\n\n beforeEach(function () {\n req = new IncomingMessage(new Socket());\n res = new ServerResponse(req);\n });\n\n it(\"Should not handle the request if request is not cloud events\", async function () {\n const endSpy = sinon.spy(res.end);\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should not handle the request if hub does not match\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should response with 200 when option is not specified\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response with 200 when handler is not specified\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {});\n const result = await dispatcher.handleRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response with error when handler returns error\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleConnect: async (_, response) => {\n response.fail(400);\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(400, res.statusCode, \"should be error\");\n });\n\n it(\"Should response with success when handler returns success\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleConnect: async (_, response) => {\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n });\n\n it(\"Should response with success when handler returns success value\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleConnect: async (_, response) => {\n response.success({ userId: \"vic\" });\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n });\n\n it(\"Should be able to set connection state\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleConnect: async (_, response) => {\n response.setState(\"key1\", \"val1\");\n response.setState(\"key2\", \"val2\");\n response.setState(\"key1\", [\"val3\"]);\n response.setState(\"key3\", \"\");\n response.success({ userId: \"vic\" });\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(\n toBase64JsonString({\n key1: [\"val3\"],\n key2: \"val2\",\n key3: \"\",\n }),\n res.getHeader(\"ce-connectionState\"),\n \"should contain multiple state headers\"\n );\n });\n\n it(\"Should be able to get the connection states if it exists in the header\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n const states = toBase64JsonString({\n key1: [\"val3\"],\n key2: \"val2\",\n key3: \"\",\n });\n buildRequest(req, \"hub1\", \"conn1\", undefined, states);\n const dispatcher = new CloudEventsDispatcher(\"hub1\", {\n handleConnect: (request, response) => {\n assert.equal(\"val3\", request.context.states[\"key1\"][0]);\n assert.equal(\"val2\", request.context.states[\"key2\"]);\n assert.equal(\"\", request.context.states[\"key3\"]);\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n });\n\n it(\"Invalid state header gets ignored\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub1\", \"conn1\", undefined, \"\");\n const dispatcher = new CloudEventsDispatcher(\"hub1\", {\n handleConnect: (request, response) => {\n assert.deepEqual({}, request.context.states);\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n });\n});\n"]}
1
+ {"version":3,"file":"connect.spec.js","sourceRoot":"","sources":["../../test/connect.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,SAAS,YAAY,CACnB,GAAoB,EACpB,GAAW,EACX,YAAoB,EACpB,MAAe,EACf,MAAe;IAEf,GAAG,CAAC,OAAO,CAAC,wBAAwB,CAAC,GAAG,yBAAyB,CAAC;IAClE,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,iCAAiC,CAAC;IAChE,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;IACtC,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;IACtC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,6BAA6B,CAAC;IACvD,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,SAAS,GAAG,WAAW,YAAY,EAAE,CAAC;IACjE,GA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,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;QACvC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;QACrD,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,UAAU,EAAE,mBAAmB,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { CloudEventsDispatcher } from \"../src/cloudEventsDispatcher\";\nimport { assert } from \"chai\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport { Socket } from \"net\";\nimport * as sinon from \"sinon\";\nimport { toBase64JsonString } from \"../src/utils\";\n\nfunction buildRequest(\n req: IncomingMessage,\n hub: string,\n connectionId: string,\n userId?: string,\n states?: string,\n): void {\n req.headers[\"webhook-request-origin\"] = \"xxx.webpubsub.azure.com\";\n req.headers[\"content-type\"] = \"application/json; charset=utf-8\";\n req.headers[\"ce-awpsversion\"] = \"1.0\";\n req.headers[\"ce-specversion\"] = \"1.0\";\n req.headers[\"ce-type\"] = \"azure.webpubsub.sys.connect\";\n req.headers[\"ce-source\"] = `/hubs/${hub}/client/${connectionId}`;\n req.headers[\"ce-id\"] = \"1\";\n req.headers[\"ce-time\"] = new Date().toUTCString();\n if (userId !== undefined) {\n req.headers[\"ce-userId\"] = userId;\n }\n req.headers[\"ce-connectionId\"] = connectionId;\n req.headers[\"ce-hub\"] = hub;\n req.headers[\"ce-event\"] = \"connect\";\n req.headers[\"ce-connectionstate\"] = states;\n}\n\nfunction mockBody(req: IncomingMessage, body: string): void {\n req.emit(\"data\", Buffer.from(body, \"utf-8\"));\n req.emit(\"end\");\n}\n\ndescribe(\"Can handle connect event\", function () {\n let req: IncomingMessage;\n let res: ServerResponse;\n\n beforeEach(function () {\n req = new IncomingMessage(new Socket());\n res = new ServerResponse(req);\n });\n\n it(\"Should not handle the request if request is not cloud events\", async function () {\n const endSpy = sinon.spy(res.end);\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should not handle the request if hub does not match\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should response with 200 when option is not specified\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response with 200 when handler is not specified\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {});\n const result = await dispatcher.handleRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response with error when handler returns error\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleConnect: async (_, response) => {\n response.fail(400);\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(400, res.statusCode, \"should be error\");\n });\n\n it(\"Should response with success when handler returns success\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleConnect: async (_, response) => {\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n });\n\n it(\"Should response with success when handler returns success value\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleConnect: async (_, response) => {\n response.success({ userId: \"vic\" });\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n });\n\n it(\"Should be able to set connection state\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleConnect: async (_, response) => {\n response.setState(\"key1\", \"val1\");\n response.setState(\"key2\", \"val2\");\n response.setState(\"key1\", [\"val3\"]);\n response.setState(\"key3\", \"\");\n response.success({ userId: \"vic\" });\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(\n toBase64JsonString({\n key1: [\"val3\"],\n key2: \"val2\",\n key3: \"\",\n }),\n res.getHeader(\"ce-connectionState\"),\n \"should contain multiple state headers\",\n );\n });\n\n it(\"Should be able to get the connection states if it exists in the header\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n const states = toBase64JsonString({\n key1: [\"val3\"],\n key2: \"val2\",\n key3: \"\",\n });\n buildRequest(req, \"hub1\", \"conn1\", undefined, states);\n const dispatcher = new CloudEventsDispatcher(\"hub1\", {\n handleConnect: (request, response) => {\n assert.equal(\"val3\", request.context.states[\"key1\"][0]);\n assert.equal(\"val2\", request.context.states[\"key2\"]);\n assert.equal(\"\", request.context.states[\"key3\"]);\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n });\n\n it(\"Invalid state header gets ignored\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub1\", \"conn1\", undefined, \"\");\n const dispatcher = new CloudEventsDispatcher(\"hub1\", {\n handleConnect: (request, response) => {\n assert.deepEqual({}, request.context.states);\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n });\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"connected.spec.js","sourceRoot":"","sources":["../../test/connected.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,SAAS,YAAY,CACnB,GAAoB,EACpB,GAAW,EACX,YAAoB,EACpB,MAAe;IAEf,GAAG,CAAC,OAAO,CAAC,wBAAwB,CAAC,GAAG,yBAAyB,CAAC;IAClE,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,iCAAiC,CAAC;IAChE,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,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MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;QACrD,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { CloudEventsDispatcher } from \"../src/cloudEventsDispatcher\";\nimport { assert } from \"chai\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport { Socket } from \"net\";\nimport * as sinon from \"sinon\";\n\nfunction buildRequest(\n req: IncomingMessage,\n hub: string,\n connectionId: string,\n userId?: string\n): void {\n req.headers[\"webhook-request-origin\"] = \"xxx.webpubsub.azure.com\";\n req.headers[\"content-type\"] = \"application/json; charset=utf-8\";\n req.headers[\"ce-awpsversion\"] = \"1.0\";\n req.headers[\"ce-specversion\"] = \"1.0\";\n req.headers[\"ce-type\"] = \"azure.webpubsub.user.connected\";\n req.headers[\"ce-source\"] = `/hubs/${hub}/client/${connectionId}`;\n req.headers[\"ce-id\"] = \"1\";\n req.headers[\"ce-time\"] = new Date().toUTCString();\n if (userId !== undefined) {\n req.headers[\"ce-userId\"] = userId;\n }\n req.headers[\"ce-connectionId\"] = connectionId;\n req.headers[\"ce-hub\"] = hub;\n req.headers[\"ce-event\"] = \"connected\";\n}\n\nfunction mockBody(req: IncomingMessage, body: string): void {\n req.emit(\"data\", body);\n req.emit(\"end\");\n}\n\ndescribe(\"Can handle connected event\", function () {\n let req: IncomingMessage;\n let res: ServerResponse;\n\n beforeEach(function () {\n req = new IncomingMessage(new Socket());\n res = new ServerResponse(req);\n });\n\n it(\"Should not handle the request if request is not cloud events\", async function () {\n const endSpy = sinon.spy(res.end);\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should not handle the request if hub does not match\", async function () {\n const endSpy = sinon.spy(res.end);\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should response with 200 when option is not specified\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response with 200 when handler is not specified\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {});\n const result = await dispatcher.handleRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response 200 even the event handler throws\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n onConnected: async (_) => {\n throw new Error();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be error\");\n });\n});\n"]}
1
+ {"version":3,"file":"connected.spec.js","sourceRoot":"","sources":["../../test/connected.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,eA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ClD,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;gBACvB,MAAM,IAAI,KAAK,EAAE,CAAC;YACpB,CAAC;SACF,CAAC,CAAC;QACH,MAAM,OAAO,GAAG,UAAU,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACnD,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;QAClC,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;QACvC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;QACrD,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { CloudEventsDispatcher } from \"../src/cloudEventsDispatcher\";\nimport { assert } from \"chai\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport { Socket } from \"net\";\nimport * as sinon from \"sinon\";\n\nfunction buildRequest(\n req: IncomingMessage,\n hub: string,\n connectionId: string,\n userId?: string,\n): void {\n req.headers[\"webhook-request-origin\"] = \"xxx.webpubsub.azure.com\";\n req.headers[\"content-type\"] = \"application/json; charset=utf-8\";\n req.headers[\"ce-awpsversion\"] = \"1.0\";\n req.headers[\"ce-specversion\"] = \"1.0\";\n req.headers[\"ce-type\"] = \"azure.webpubsub.user.connected\";\n req.headers[\"ce-source\"] = `/hubs/${hub}/client/${connectionId}`;\n req.headers[\"ce-id\"] = \"1\";\n req.headers[\"ce-time\"] = new Date().toUTCString();\n if (userId !== undefined) {\n req.headers[\"ce-userId\"] = userId;\n }\n req.headers[\"ce-connectionId\"] = connectionId;\n req.headers[\"ce-hub\"] = hub;\n req.headers[\"ce-event\"] = \"connected\";\n}\n\nfunction mockBody(req: IncomingMessage, body: string): void {\n req.emit(\"data\", body);\n req.emit(\"end\");\n}\n\ndescribe(\"Can handle connected event\", function () {\n let req: IncomingMessage;\n let res: ServerResponse;\n\n beforeEach(function () {\n req = new IncomingMessage(new Socket());\n res = new ServerResponse(req);\n });\n\n it(\"Should not handle the request if request is not cloud events\", async function () {\n const endSpy = sinon.spy(res.end);\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should not handle the request if hub does not match\", async function () {\n const endSpy = sinon.spy(res.end);\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should response with 200 when option is not specified\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response with 200 when handler is not specified\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {});\n const result = await dispatcher.handleRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response 200 even the event handler throws\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n onConnected: async (_) => {\n throw new Error();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be error\");\n });\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"disconnected.spec.js","sourceRoot":"","sources":["../../test/disconnected.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,SAAS,YAAY,CACnB,GAAoB,EACpB,GAAW,EACX,YAAoB,EACpB,MAAe;IAEf,GAAG,CAAC,OAAO,CAAC,wBAAwB,CAAC,GAAG,yBAAyB,CAAC;IAClE,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,iCAAiC,CAAC;IAChE,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;IACtC,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;IACtC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,mCAAmC,CAAC;IAC7D,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,SAAS,GAAG,WAAW,YAAY,EAAE,CAAC;IACjE,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC;IAC3B,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAClD,IAAI,MAAM,KAAK,SAAS,EAAE;QACxB,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG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M,CAAC,MAAM,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;QACrD,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mDAAmD,EAAE,KAAK;QAC3D,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACrC,YAAY,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAElC,MAAM,UAAU,GAAG,IAAI,qBAAqB,CAAC,KAAK,EAAE;YAClD,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;gBACvB,MAAM,IAAI,KAAK,EAAE,CAAC;YACpB,CAAC;SACF,CAAC,CAAC;QACH,MAAM,OAAO,GAAG,UAAU,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACnD,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;QAClC,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;QACvC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;QACrD,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { CloudEventsDispatcher } from \"../src/cloudEventsDispatcher\";\nimport { assert } from \"chai\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport { Socket } from \"net\";\nimport * as sinon from \"sinon\";\n\nfunction buildRequest(\n req: IncomingMessage,\n hub: string,\n connectionId: string,\n userId?: string\n): void {\n req.headers[\"webhook-request-origin\"] = \"xxx.webpubsub.azure.com\";\n req.headers[\"content-type\"] = \"application/json; charset=utf-8\";\n req.headers[\"ce-awpsversion\"] = \"1.0\";\n req.headers[\"ce-specversion\"] = \"1.0\";\n req.headers[\"ce-type\"] = \"azure.webpubsub.user.disconnected\";\n req.headers[\"ce-source\"] = `/hubs/${hub}/client/${connectionId}`;\n req.headers[\"ce-id\"] = \"1\";\n req.headers[\"ce-time\"] = new Date().toUTCString();\n if (userId !== undefined) {\n req.headers[\"ce-userId\"] = userId;\n }\n req.headers[\"ce-connectionId\"] = connectionId;\n req.headers[\"ce-hub\"] = hub;\n req.headers[\"ce-event\"] = \"disconnected\";\n}\n\nfunction mockBody(req: IncomingMessage, body: string): void {\n req.emit(\"data\", body);\n req.emit(\"end\");\n}\n\ndescribe(\"Can handle disconnected event\", function () {\n let req: IncomingMessage;\n let res: ServerResponse;\n\n beforeEach(function () {\n req = new IncomingMessage(new Socket());\n res = new ServerResponse(req);\n });\n\n it(\"Should not handle the request if request is not cloud events\", async function () {\n const endSpy = sinon.spy(res.end);\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should not handle the request if hub does not match\", async function () {\n const endSpy = sinon.spy(res.end);\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should response with 200 when option is not specified\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response with 200 when handler is not specified\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {});\n const result = await dispatcher.handleRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response 200 even the event handler throws\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n onConnected: async (_) => {\n throw new Error();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be error\");\n });\n});\n"]}
1
+ {"version":3,"file":"disconnected.spec.js","sourceRoot":"","sources":["../../test/disconnected.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,SAAS,YAAY,CACnB,GAAoB,EACpB,GAAW,EACX,YAAoB,EACpB,MAAe;IAEf,GAAG,CAAC,OAAO,CAAC,wBAAwB,CAAC,GAAG,yBAAyB,CAAC;IAClE,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,iCAAiC,CAAC;IAChE,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;IACtC,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAA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AC;QACrD,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { CloudEventsDispatcher } from \"../src/cloudEventsDispatcher\";\nimport { assert } from \"chai\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport { Socket } from \"net\";\nimport * as sinon from \"sinon\";\n\nfunction buildRequest(\n req: IncomingMessage,\n hub: string,\n connectionId: string,\n userId?: string,\n): void {\n req.headers[\"webhook-request-origin\"] = \"xxx.webpubsub.azure.com\";\n req.headers[\"content-type\"] = \"application/json; charset=utf-8\";\n req.headers[\"ce-awpsversion\"] = \"1.0\";\n req.headers[\"ce-specversion\"] = \"1.0\";\n req.headers[\"ce-type\"] = \"azure.webpubsub.user.disconnected\";\n req.headers[\"ce-source\"] = `/hubs/${hub}/client/${connectionId}`;\n req.headers[\"ce-id\"] = \"1\";\n req.headers[\"ce-time\"] = new Date().toUTCString();\n if (userId !== undefined) {\n req.headers[\"ce-userId\"] = userId;\n }\n req.headers[\"ce-connectionId\"] = connectionId;\n req.headers[\"ce-hub\"] = hub;\n req.headers[\"ce-event\"] = \"disconnected\";\n}\n\nfunction mockBody(req: IncomingMessage, body: string): void {\n req.emit(\"data\", body);\n req.emit(\"end\");\n}\n\ndescribe(\"Can handle disconnected event\", function () {\n let req: IncomingMessage;\n let res: ServerResponse;\n\n beforeEach(function () {\n req = new IncomingMessage(new Socket());\n res = new ServerResponse(req);\n });\n\n it(\"Should not handle the request if request is not cloud events\", async function () {\n const endSpy = sinon.spy(res.end);\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should not handle the request if hub does not match\", async function () {\n const endSpy = sinon.spy(res.end);\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should response with 200 when option is not specified\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response with 200 when handler is not specified\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {});\n const result = await dispatcher.handleRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response 200 even the event handler throws\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n onConnected: async (_) => {\n throw new Error();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be error\");\n });\n});\n"]}
@@ -8,7 +8,7 @@ import { Socket } from "net";
8
8
  import * as sinon from "sinon";
9
9
  function buildRequest(req, hub, connectionId, userId, contentType) {
10
10
  req.headers["webhook-request-origin"] = "xxx.webpubsub.azure.com";
11
- req.headers["content-type"] = contentType !== null && contentType !== void 0 ? contentType : "application/json; charset=utf-8";
11
+ req.headers["content-type"] = contentType ?? "application/json; charset=utf-8";
12
12
  req.headers["ce-awpsversion"] = "1.0";
13
13
  req.headers["ce-specversion"] = "1.0";
14
14
  req.headers["ce-type"] = "azure.webpubsub.user.connect";
@@ -1 +1 @@
1
- {"version":3,"file":"user.spec.js","sourceRoot":"","sources":["../../test/user.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,SAAS,YAAY,CACnB,GAAoB,EACpB,GAAW,EACX,YAAoB,EACpB,MAAe,EACf,WAAoB;IAEpB,GAAG,CAAC,OAAO,CAAC,wBAAwB,CAAC,GAAG,yBAAyB,CAAC;IAClE,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,iCAAiC,CAAC;IAC/E,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;IACtC,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;IACtC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,8BAA8B,CAAC;IACxD,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,SAAS,GAAG,WAAW,YAAY,EAAE,CAAC;IACjE,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC;IAC3B,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAClD,IAAI,MAAM,KAAK,SAAS,EAAE;QACxB,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC;KACnC;IACD,GAAG,CAAC,OAAO,CAAC,iBA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C,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAClC,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAClC,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAClC,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;gBAC9B,QAAQ,CAAC,OAAO,EAAE,CAAC;YACrB,CAAC;SACF,CAAC,CAAC;QACH,MAAM,OAAO,GAAG,UAAU,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACnD,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;QAClC,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;QACvC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;QACrD,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,UAAU,EAAE,mBAAmB,CAAC,CAAC;QAEvD,MAAM,CAAC,KAAK,CACV,MAAM,CAAC,IAAI,CACT,IAAI,CAAC,SAAS,CAAC;YACb,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,EAAE;SACT,CAAC,CACH,CAAC,QAAQ,CAAC,QAAQ,CAAC,EACpB,GAAG,CAAC,SAAS,CAAC,oBAAoB,CAAC,EACnC,uCAAuC,CACxC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { CloudEventsDispatcher } from \"../src/cloudEventsDispatcher\";\nimport { assert } from \"chai\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport { Socket } from \"net\";\nimport * as sinon from \"sinon\";\n\nfunction buildRequest(\n req: IncomingMessage,\n hub: string,\n connectionId: string,\n userId?: string,\n contentType?: string\n): void {\n req.headers[\"webhook-request-origin\"] = \"xxx.webpubsub.azure.com\";\n req.headers[\"content-type\"] = contentType ?? \"application/json; charset=utf-8\";\n req.headers[\"ce-awpsversion\"] = \"1.0\";\n req.headers[\"ce-specversion\"] = \"1.0\";\n req.headers[\"ce-type\"] = \"azure.webpubsub.user.connect\";\n req.headers[\"ce-source\"] = `/hubs/${hub}/client/${connectionId}`;\n req.headers[\"ce-id\"] = \"1\";\n req.headers[\"ce-time\"] = new Date().toUTCString();\n if (userId !== undefined) {\n req.headers[\"ce-userId\"] = userId;\n }\n req.headers[\"ce-connectionId\"] = connectionId;\n req.headers[\"ce-hub\"] = hub;\n req.headers[\"ce-event\"] = \"connect\";\n}\n\nfunction mockBinaryBody(req: IncomingMessage, body: ArrayBuffer): void {\n req.emit(\"data\", body);\n req.emit(\"end\");\n}\n\nfunction mockBody(req: IncomingMessage, body: string): void {\n return mockBinaryBody(req, Buffer.from(body, \"utf-8\"));\n}\n\ndescribe(\"Can handle user event\", function () {\n let req: IncomingMessage;\n let res: ServerResponse;\n\n beforeEach(function () {\n req = new IncomingMessage(new Socket());\n res = new ServerResponse(req);\n });\n\n it(\"Should not handle the request if request is not cloud events\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n const dispatcher = new CloudEventsDispatcher(\"hub1\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should not handle the request if hub does not match\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should handle number requests\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (request, response) => {\n assert.equal(request.dataType, \"json\");\n assert.equal(typeof request.data, \"number\");\n assert.strictEqual(1, request.data);\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify(1));\n const result = await process;\n\n assert.isTrue(result);\n assert.equal(200, res.statusCode, \"should be 200\");\n assert.isTrue(endSpy.calledOnce);\n });\n\n it(\"Should handle boolean requests\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (request, response) => {\n assert.equal(request.dataType, \"json\");\n assert.equal(typeof request.data, \"boolean\");\n assert.strictEqual(true, request.data);\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify(true));\n const result = await process;\n\n assert.isTrue(result);\n assert.equal(200, res.statusCode, \"should be 200\");\n assert.isTrue(endSpy.calledOnce);\n });\n\n it(\"Should handle complex object requests\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (request, response) => {\n assert.equal(request.dataType, \"json\");\n assert.equal(typeof request.data, \"object\");\n assert.equal((<{ a: number }>request.data).a, 1);\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({ a: 1 }));\n const result = await process;\n\n assert.isTrue(result);\n assert.isTrue(endSpy.calledOnce);\n });\n\n it(\"Should handle complex array requests\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (request, response) => {\n assert.equal(request.dataType, \"json\");\n assert.equal(typeof request.data, \"object\");\n assert.isTrue(Array.isArray(request.data));\n assert.deepEqual(request.data, [1, 2, 3]);\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify([1, 2, 3]));\n const result = await process;\n\n assert.isTrue(result);\n assert.isTrue(endSpy.calledOnce);\n });\n\n it(\"Should handle binary requests\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\", \"user1\", \"application/octet-stream\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (request, response) => {\n assert.equal(request.dataType, \"binary\");\n assert.equal(typeof request.data, \"object\");\n assert.deepEqual(\n request.data,\n new Uint8Array([1, 2, 3, 4, 5, 6, 7]),\n \"buffer data matches\"\n );\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n const body = new Uint8Array([1, 2, 3, 4, 5, 6, 7]);\n mockBinaryBody(req, body);\n const result = await process;\n\n assert.isTrue(result, \"should be able to process\");\n assert.isTrue(endSpy.calledOnce, \"should be called once\");\n });\n\n it(\"Should handle text requests\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\", \"user1\", \"text/plain\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (request, response) => {\n assert.equal(request.dataType, \"text\");\n assert.equal(typeof request.data, \"string\");\n console.log(request);\n assert.equal(request.data, \"Hello\", \"string data matches\");\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, \"Hello\");\n const result = await process;\n\n assert.isTrue(result, \"should be able to process\");\n assert.isTrue(endSpy.calledOnce, \"should be called once\");\n });\n\n it(\"Should handle text requests with charset\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\", \"user1\", \"text/plain; charset=UTF-8;\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (request, response) => {\n assert.equal(request.dataType, \"text\");\n assert.equal(typeof request.data, \"string\");\n console.log(request);\n assert.equal(request.data, \"Hello\", \"string data matches\");\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, \"Hello\");\n const result = await process;\n\n assert.isTrue(result, \"should be able to process\");\n assert.isTrue(endSpy.calledOnce, \"should be called once\");\n });\n\n it(\"Should response with 200 when option is not specified\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response with 200 when handler is not specified\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {});\n const result = await dispatcher.handleRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response with error when handler returns error\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (_, response) => {\n response.fail(500);\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(500, res.statusCode, \"should be error\");\n });\n\n it(\"Should response with success when handler returns success\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (_, response) => {\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n });\n\n it(\"Should response with success when returns success binary\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (_, response) => {\n response.success(\"a\");\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n assert.equal(\"application/octet-stream\", res.getHeader(\"content-type\"), \"should be binary\");\n });\n\n it(\"Should response with success when returns success text\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (_, response) => {\n response.success(\"a\", \"text\");\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n assert.equal(\"text/plain; charset=utf-8\", res.getHeader(\"content-type\"), \"should be text\");\n });\n\n it(\"Should response with success when returns success json\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (_, response) => {\n response.success(\"a\", \"json\");\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n assert.equal(\n \"application/json; charset=utf-8\",\n res.getHeader(\"content-type\"),\n \"should be json\"\n );\n });\n\n it(\"Should be able to set connection state\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (_, response) => {\n response.setState(\"key1\", \"val1\");\n response.setState(\"key2\", \"val2\");\n response.setState(\"key1\", \"val3\");\n response.setState(\"key3\", \"\");\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n\n assert.equal(\n Buffer.from(\n JSON.stringify({\n key1: \"val3\",\n key2: \"val2\",\n key3: \"\",\n })\n ).toString(\"base64\"),\n res.getHeader(\"ce-connectionState\"),\n \"should contain multiple state headers\"\n );\n });\n});\n"]}
1
+ {"version":3,"file":"user.spec.js","sourceRoot":"","sources":["../../test/user.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,SAAS,YAAY,CACnB,GAAoB,EACpB,GAAW,EACX,YAAoB,EACpB,MAAe,EACf,WAAoB;IAEpB,GAAG,CAAC,OAAO,CAAC,wBAAwB,CAAC,GAAG,yBAAyB,CAAC;IAClE,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,WAAW,IAAI,iCAAiC,CAAC;IAC/E,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;IACtC,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;IACtC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,8BAA8B,CAAC;IACxD,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,SA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AQ,CAAC,QAAQ,CAAC,EACpB,GAAG,CAAC,SAAS,CAAC,oBAAoB,CAAC,EACnC,uCAAuC,CACxC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { CloudEventsDispatcher } from \"../src/cloudEventsDispatcher\";\nimport { assert } from \"chai\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport { Socket } from \"net\";\nimport * as sinon from \"sinon\";\n\nfunction buildRequest(\n req: IncomingMessage,\n hub: string,\n connectionId: string,\n userId?: string,\n contentType?: string,\n): void {\n req.headers[\"webhook-request-origin\"] = \"xxx.webpubsub.azure.com\";\n req.headers[\"content-type\"] = contentType ?? \"application/json; charset=utf-8\";\n req.headers[\"ce-awpsversion\"] = \"1.0\";\n req.headers[\"ce-specversion\"] = \"1.0\";\n req.headers[\"ce-type\"] = \"azure.webpubsub.user.connect\";\n req.headers[\"ce-source\"] = `/hubs/${hub}/client/${connectionId}`;\n req.headers[\"ce-id\"] = \"1\";\n req.headers[\"ce-time\"] = new Date().toUTCString();\n if (userId !== undefined) {\n req.headers[\"ce-userId\"] = userId;\n }\n req.headers[\"ce-connectionId\"] = connectionId;\n req.headers[\"ce-hub\"] = hub;\n req.headers[\"ce-event\"] = \"connect\";\n}\n\nfunction mockBinaryBody(req: IncomingMessage, body: ArrayBuffer): void {\n req.emit(\"data\", body);\n req.emit(\"end\");\n}\n\nfunction mockBody(req: IncomingMessage, body: string): void {\n return mockBinaryBody(req, Buffer.from(body, \"utf-8\"));\n}\n\ndescribe(\"Can handle user event\", function () {\n let req: IncomingMessage;\n let res: ServerResponse;\n\n beforeEach(function () {\n req = new IncomingMessage(new Socket());\n res = new ServerResponse(req);\n });\n\n it(\"Should not handle the request if request is not cloud events\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n const dispatcher = new CloudEventsDispatcher(\"hub1\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should not handle the request if hub does not match\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should handle number requests\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (request, response) => {\n assert.equal(request.dataType, \"json\");\n assert.equal(typeof request.data, \"number\");\n assert.strictEqual(1, request.data);\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify(1));\n const result = await process;\n\n assert.isTrue(result);\n assert.equal(200, res.statusCode, \"should be 200\");\n assert.isTrue(endSpy.calledOnce);\n });\n\n it(\"Should handle boolean requests\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (request, response) => {\n assert.equal(request.dataType, \"json\");\n assert.equal(typeof request.data, \"boolean\");\n assert.strictEqual(true, request.data);\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify(true));\n const result = await process;\n\n assert.isTrue(result);\n assert.equal(200, res.statusCode, \"should be 200\");\n assert.isTrue(endSpy.calledOnce);\n });\n\n it(\"Should handle complex object requests\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (request, response) => {\n assert.equal(request.dataType, \"json\");\n assert.equal(typeof request.data, \"object\");\n assert.equal((<{ a: number }>request.data).a, 1);\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({ a: 1 }));\n const result = await process;\n\n assert.isTrue(result);\n assert.isTrue(endSpy.calledOnce);\n });\n\n it(\"Should handle complex array requests\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (request, response) => {\n assert.equal(request.dataType, \"json\");\n assert.equal(typeof request.data, \"object\");\n assert.isTrue(Array.isArray(request.data));\n assert.deepEqual(request.data, [1, 2, 3]);\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify([1, 2, 3]));\n const result = await process;\n\n assert.isTrue(result);\n assert.isTrue(endSpy.calledOnce);\n });\n\n it(\"Should handle binary requests\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\", \"user1\", \"application/octet-stream\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (request, response) => {\n assert.equal(request.dataType, \"binary\");\n assert.equal(typeof request.data, \"object\");\n assert.deepEqual(\n request.data,\n new Uint8Array([1, 2, 3, 4, 5, 6, 7]),\n \"buffer data matches\",\n );\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n const body = new Uint8Array([1, 2, 3, 4, 5, 6, 7]);\n mockBinaryBody(req, body);\n const result = await process;\n\n assert.isTrue(result, \"should be able to process\");\n assert.isTrue(endSpy.calledOnce, \"should be called once\");\n });\n\n it(\"Should handle text requests\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\", \"user1\", \"text/plain\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (request, response) => {\n assert.equal(request.dataType, \"text\");\n assert.equal(typeof request.data, \"string\");\n console.log(request);\n assert.equal(request.data, \"Hello\", \"string data matches\");\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, \"Hello\");\n const result = await process;\n\n assert.isTrue(result, \"should be able to process\");\n assert.isTrue(endSpy.calledOnce, \"should be called once\");\n });\n\n it(\"Should handle text requests with charset\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\", \"user1\", \"text/plain; charset=UTF-8;\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (request, response) => {\n assert.equal(request.dataType, \"text\");\n assert.equal(typeof request.data, \"string\");\n console.log(request);\n assert.equal(request.data, \"Hello\", \"string data matches\");\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, \"Hello\");\n const result = await process;\n\n assert.isTrue(result, \"should be able to process\");\n assert.isTrue(endSpy.calledOnce, \"should be called once\");\n });\n\n it(\"Should response with 200 when option is not specified\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response with 200 when handler is not specified\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {});\n const result = await dispatcher.handleRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response with error when handler returns error\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (_, response) => {\n response.fail(500);\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(500, res.statusCode, \"should be error\");\n });\n\n it(\"Should response with success when handler returns success\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (_, response) => {\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n });\n\n it(\"Should response with success when returns success binary\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (_, response) => {\n response.success(\"a\");\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n assert.equal(\"application/octet-stream\", res.getHeader(\"content-type\"), \"should be binary\");\n });\n\n it(\"Should response with success when returns success text\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (_, response) => {\n response.success(\"a\", \"text\");\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n assert.equal(\"text/plain; charset=utf-8\", res.getHeader(\"content-type\"), \"should be text\");\n });\n\n it(\"Should response with success when returns success json\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (_, response) => {\n response.success(\"a\", \"json\");\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n assert.equal(\n \"application/json; charset=utf-8\",\n res.getHeader(\"content-type\"),\n \"should be json\",\n );\n });\n\n it(\"Should be able to set connection state\", async function () {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (_, response) => {\n response.setState(\"key1\", \"val1\");\n response.setState(\"key2\", \"val2\");\n response.setState(\"key1\", \"val3\");\n response.setState(\"key3\", \"\");\n response.success();\n },\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n\n assert.equal(\n Buffer.from(\n JSON.stringify({\n key1: \"val3\",\n key2: \"val2\",\n key3: \"\",\n }),\n ).toString(\"base64\"),\n res.getHeader(\"ce-connectionState\"),\n \"should contain multiple state headers\",\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.20231214.1",
3
+ "version": "1.0.6-alpha.20240112.1",
4
4
  "description": "Azure Web PubSub CloudEvents handlers",
5
5
  "sdk-type": "client",
6
6
  "main": "dist/index.js",
@@ -13,8 +13,8 @@
13
13
  "build:samples": "echo Obsolete.",
14
14
  "build:test": "tsc -p . && dev-tool run bundle --browser-test=false",
15
15
  "build": "npm run clean && tsc -p . && dev-tool run bundle --browser-test=false && api-extractor run --local",
16
- "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
17
- "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
16
+ "check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
17
+ "format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
18
18
  "clean": "rimraf dist dist-esm test-dist temp types *.tgz *.log",
19
19
  "execute:samples": "dev-tool samples run samples-dev",
20
20
  "extract-api": "tsc -p . && api-extractor run --local",
@@ -77,7 +77,6 @@
77
77
  "express": "^4.16.3",
78
78
  "mocha": "^10.0.0",
79
79
  "c8": "^8.0.0",
80
- "prettier": "^2.5.1",
81
80
  "puppeteer": "^19.2.2",
82
81
  "rimraf": "^3.0.0",
83
82
  "sinon": "^17.0.0",