diff --git a/sdk/web-pubsub/web-pubsub-express/package.json b/sdk/web-pubsub/web-pubsub-express/package.json index 49ba0a79d4a4..30afa0680cac 100644 --- a/sdk/web-pubsub/web-pubsub-express/package.json +++ b/sdk/web-pubsub/web-pubsub-express/package.json @@ -22,7 +22,7 @@ "integration-test:node": "echo skipped", "integration-test": "npm run integration-test:node && npm run integration-test:browser", "lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]", - "lint": "eslint package.json api-extractor.json src test --ext .ts -f html -o signalr-lintReport.html || exit 0", + "lint": "eslint package.json api-extractor.json src test --ext .ts -f html -o webpubsub-express-lintReport.html || exit 0", "pack": "npm pack 2>&1", "test:browser": "echo \"Browser is not supported.\" && exit 0", "test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node", @@ -42,7 +42,7 @@ ], "repository": "github:Azure/azure-sdk-for-js", "keywords": [ - "Azure", + "azure", "cloud" ], "author": "Microsoft Corporation", diff --git a/sdk/web-pubsub/web-pubsub-express/src/cloudEventsDispatcher.ts b/sdk/web-pubsub/web-pubsub-express/src/cloudEventsDispatcher.ts index 61b60d4e252e..9a9fa3dbd365 100644 --- a/sdk/web-pubsub/web-pubsub-express/src/cloudEventsDispatcher.ts +++ b/sdk/web-pubsub/web-pubsub-express/src/cloudEventsDispatcher.ts @@ -30,7 +30,7 @@ function getConnectResponseHandler( connectRequest: ConnectRequest, response: ServerResponse ): ConnectResponseHandler { - let states: Record = connectRequest.context.states; + const states: Record = connectRequest.context.states; let modified = false; const handler = { setState(name: string, value: unknown): void { @@ -62,7 +62,7 @@ function getUserEventResponseHandler( userRequest: UserEventRequest, response: ServerResponse ): UserEventResponseHandler { - let states: Record = userRequest.context.states; + const states: Record = userRequest.context.states; let modified = false; const handler = { setState(name: string, value: unknown): void { diff --git a/sdk/web-pubsub/web-pubsub-express/src/cloudEventsProtocols.ts b/sdk/web-pubsub/web-pubsub-express/src/cloudEventsProtocols.ts index 588b1418f304..7f653cb49d37 100644 --- a/sdk/web-pubsub/web-pubsub-express/src/cloudEventsProtocols.ts +++ b/sdk/web-pubsub/web-pubsub-express/src/cloudEventsProtocols.ts @@ -158,19 +158,19 @@ export interface DisconnectedRequest { export interface ConnectResponseHandler { /** * Set the state of the connection - * @param name The name of the state - * @param value The value of the state + * @param name - The name of the state + * @param value - The value of the state */ setState(name: string, value: unknown): void; /** * Return success response to the service. - * @param response The response for the connect event. + * @param response - The response for the connect event. */ success(response?: ConnectResponse): void; /** * Return failed response and the service will reject the client WebSocket connection. - * @param code Code can be 400 user error, 401 unauthorized and 500 server error. - * @param detail The detail of the error. + * @param code - Code can be 400 user error, 401 unauthorized and 500 server error. + * @param detail - The detail of the error. */ fail(code: 400 | 401 | 500, detail?: string): void; } @@ -181,20 +181,20 @@ export interface ConnectResponseHandler { export interface UserEventResponseHandler { /** * Set the state of the connection - * @param name The name of the state - * @param value The value of the state + * @param name - The name of the state + * @param value - The value of the state */ setState(name: string, value: unknown): void; /** * Return success response with data to be delivered to the client WebSocket connection. - * @param data The payload data to be returned to the client. - * @param dataType The type of the payload data. + * @param data - The payload data to be returned to the client. + * @param dataType - The type of the payload data. */ success(data?: string | ArrayBuffer, dataType?: "binary" | "text" | "json"): void; /** * Return failed response and the service will close the client WebSocket connection. - * @param code Code can be 400 user error, 401 unauthorized and 500 server error. - * @param detail The detail of the error. + * @param code - Code can be 400 user error, 401 unauthorized and 500 server error. + * @param detail - The detail of the error. */ fail(code: 400 | 401 | 500, detail?: string): void; } diff --git a/sdk/web-pubsub/web-pubsub-express/src/utils.ts b/sdk/web-pubsub/web-pubsub-express/src/utils.ts index 3f31055524e3..31dada4b4225 100644 --- a/sdk/web-pubsub/web-pubsub-express/src/utils.ts +++ b/sdk/web-pubsub/web-pubsub-express/src/utils.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import { IncomingMessage } from "http"; import { Message } from "cloudevents"; @@ -15,8 +18,8 @@ export function fromBase64JsonString(base64String: string): Record } try { - let buf = Buffer.from(base64String, "base64").toString(); - let parsed = JSON.parse(buf); + const buf = Buffer.from(base64String, "base64").toString(); + const parsed = JSON.parse(buf); return isJsonObject(parsed) ? parsed : {}; } catch (e) { console.warn("Unexpected state format:" + e); diff --git a/sdk/web-pubsub/web-pubsub-express/src/webPubSubEventHandler.ts b/sdk/web-pubsub/web-pubsub-express/src/webPubSubEventHandler.ts index 73fdd528bfcc..f9462acb6066 100644 --- a/sdk/web-pubsub/web-pubsub-express/src/webPubSubEventHandler.ts +++ b/sdk/web-pubsub/web-pubsub-express/src/webPubSubEventHandler.ts @@ -41,9 +41,9 @@ export class WebPubSubEventHandler { * }); * ``` * - * @param hub The name of the hub to listen to - * @param allowedEndpoints The allowed endpoints for the incoming CloudEvents request - * @param options Options to configure the event handler + * @param hub - The name of the hub to listen to + * @param allowedEndpoints - The allowed endpoints for the incoming CloudEvents request + * @param options - Options to configure the event handler */ constructor( private hub: string, diff --git a/sdk/web-pubsub/web-pubsub-express/test/connect.spec.ts b/sdk/web-pubsub/web-pubsub-express/test/connect.spec.ts index 5370222f2eb3..714c39babd42 100644 --- a/sdk/web-pubsub/web-pubsub-express/test/connect.spec.ts +++ b/sdk/web-pubsub/web-pubsub-express/test/connect.spec.ts @@ -49,7 +49,7 @@ describe("Can handle connect event", function() { const endSpy = sinon.spy(res.end); const dispatcher = new CloudEventsDispatcher("hub1", ["*"]); - var result = await dispatcher.processRequest(req, res); + const result = await dispatcher.processRequest(req, res); assert.isFalse(result); assert.isTrue(endSpy.notCalled); }); @@ -59,7 +59,7 @@ describe("Can handle connect event", function() { buildRequest(req, "hub", "conn1"); const dispatcher = new CloudEventsDispatcher("hub1", ["*"]); - var result = await dispatcher.processRequest(req, res); + const result = await dispatcher.processRequest(req, res); assert.isFalse(result); assert.isTrue(endSpy.notCalled); }); @@ -69,7 +69,7 @@ describe("Can handle connect event", function() { buildRequest(req, "hub", "conn1"); const dispatcher = new CloudEventsDispatcher("hub", ["*"]); - var result = await dispatcher.processRequest(req, res); + const result = await dispatcher.processRequest(req, res); assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); assert.equal(401, res.statusCode, "should be 401"); @@ -80,7 +80,7 @@ describe("Can handle connect event", function() { buildRequest(req, "hub", "conn1"); const dispatcher = new CloudEventsDispatcher("hub", ["*"], {}); - var result = await dispatcher.processRequest(req, res); + const result = await dispatcher.processRequest(req, res); assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); assert.equal(401, res.statusCode, "should be 401"); @@ -95,9 +95,9 @@ describe("Can handle connect event", function() { res.fail(400); } }); - var process = dispatcher.processRequest(req, res); + const process = dispatcher.processRequest(req, res); mockBody(req, JSON.stringify({})); - var result = await process; + const result = await process; assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); assert.equal(400, res.statusCode, "should be error"); @@ -112,9 +112,9 @@ describe("Can handle connect event", function() { res.success(); } }); - var process = dispatcher.processRequest(req, res); + const process = dispatcher.processRequest(req, res); mockBody(req, JSON.stringify({})); - var result = await process; + const result = await process; assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); assert.equal(200, res.statusCode, "should be success"); @@ -129,9 +129,9 @@ describe("Can handle connect event", function() { res.success({ userId: "vic" }); } }); - var process = dispatcher.processRequest(req, res); + const process = dispatcher.processRequest(req, res); mockBody(req, JSON.stringify({})); - var result = await process; + const result = await process; assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); assert.equal(200, res.statusCode, "should be success"); @@ -150,9 +150,9 @@ describe("Can handle connect event", function() { res.success({ userId: "vic" }); } }); - var process = dispatcher.processRequest(req, res); + const process = dispatcher.processRequest(req, res); mockBody(req, JSON.stringify({})); - var result = await process; + const result = await process; assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); assert.equal( @@ -182,9 +182,9 @@ describe("Can handle connect event", function() { response.success(); } }); - var process = dispatcher.processRequest(req, res); + const process = dispatcher.processRequest(req, res); mockBody(req, JSON.stringify({})); - var result = await process; + const result = await process; assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); assert.equal(200, res.statusCode, "should be success"); @@ -199,9 +199,9 @@ describe("Can handle connect event", function() { response.success(); } }); - var process = dispatcher.processRequest(req, res); + const process = dispatcher.processRequest(req, res); mockBody(req, JSON.stringify({})); - var result = await process; + const result = await process; assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); assert.equal(200, res.statusCode, "should be success"); diff --git a/sdk/web-pubsub/web-pubsub-express/test/connected.spec.ts b/sdk/web-pubsub/web-pubsub-express/test/connected.spec.ts index a4e4ea7f93f4..556815446560 100644 --- a/sdk/web-pubsub/web-pubsub-express/test/connected.spec.ts +++ b/sdk/web-pubsub/web-pubsub-express/test/connected.spec.ts @@ -46,7 +46,7 @@ describe("Can handle connected event", function() { const endSpy = sinon.spy(res.end); const dispatcher = new CloudEventsDispatcher("hub1", ["*"]); - var result = await dispatcher.processRequest(req, res); + const result = await dispatcher.processRequest(req, res); assert.isFalse(result); assert.isTrue(endSpy.notCalled); }); @@ -56,7 +56,7 @@ describe("Can handle connected event", function() { buildRequest(req, "hub", "conn1"); const dispatcher = new CloudEventsDispatcher("hub1", ["*"]); - var result = await dispatcher.processRequest(req, res); + const result = await dispatcher.processRequest(req, res); assert.isFalse(result); assert.isTrue(endSpy.notCalled); }); @@ -66,7 +66,7 @@ describe("Can handle connected event", function() { buildRequest(req, "hub", "conn1"); const dispatcher = new CloudEventsDispatcher("hub", ["*"]); - var result = await dispatcher.processRequest(req, res); + const result = await dispatcher.processRequest(req, res); assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); assert.equal(200, res.statusCode, "should be 200"); @@ -77,7 +77,7 @@ describe("Can handle connected event", function() { buildRequest(req, "hub", "conn1"); const dispatcher = new CloudEventsDispatcher("hub", ["*"], {}); - var result = await dispatcher.processRequest(req, res); + const result = await dispatcher.processRequest(req, res); assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); assert.equal(200, res.statusCode, "should be 200"); @@ -92,9 +92,9 @@ describe("Can handle connected event", function() { throw new Error(); } }); - var process = dispatcher.processRequest(req, res); + const process = dispatcher.processRequest(req, res); mockBody(req, JSON.stringify({})); - var result = await process; + const result = await process; assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); assert.equal(200, res.statusCode, "should be error"); diff --git a/sdk/web-pubsub/web-pubsub-express/test/disconnected.spec.ts b/sdk/web-pubsub/web-pubsub-express/test/disconnected.spec.ts index fc774548254f..a6d45a22426a 100644 --- a/sdk/web-pubsub/web-pubsub-express/test/disconnected.spec.ts +++ b/sdk/web-pubsub/web-pubsub-express/test/disconnected.spec.ts @@ -46,7 +46,7 @@ describe("Can handle disconnected event", function() { const endSpy = sinon.spy(res.end); const dispatcher = new CloudEventsDispatcher("hub1", ["*"]); - var result = await dispatcher.processRequest(req, res); + const result = await dispatcher.processRequest(req, res); assert.isFalse(result); assert.isTrue(endSpy.notCalled); }); @@ -56,7 +56,7 @@ describe("Can handle disconnected event", function() { buildRequest(req, "hub", "conn1"); const dispatcher = new CloudEventsDispatcher("hub1", ["*"]); - var result = await dispatcher.processRequest(req, res); + const result = await dispatcher.processRequest(req, res); assert.isFalse(result); assert.isTrue(endSpy.notCalled); }); @@ -66,7 +66,7 @@ describe("Can handle disconnected event", function() { buildRequest(req, "hub", "conn1"); const dispatcher = new CloudEventsDispatcher("hub", ["*"]); - var result = await dispatcher.processRequest(req, res); + const result = await dispatcher.processRequest(req, res); assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); assert.equal(200, res.statusCode, "should be 200"); @@ -77,7 +77,7 @@ describe("Can handle disconnected event", function() { buildRequest(req, "hub", "conn1"); const dispatcher = new CloudEventsDispatcher("hub", ["*"], {}); - var result = await dispatcher.processRequest(req, res); + const result = await dispatcher.processRequest(req, res); assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); assert.equal(200, res.statusCode, "should be 200"); @@ -92,9 +92,9 @@ describe("Can handle disconnected event", function() { throw new Error(); } }); - var process = dispatcher.processRequest(req, res); + const process = dispatcher.processRequest(req, res); mockBody(req, JSON.stringify({})); - var result = await process; + const result = await process; assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); assert.equal(200, res.statusCode, "should be error"); diff --git a/sdk/web-pubsub/web-pubsub-express/test/user.spec.ts b/sdk/web-pubsub/web-pubsub-express/test/user.spec.ts index 87d08567c95d..e4887dd573b7 100644 --- a/sdk/web-pubsub/web-pubsub-express/test/user.spec.ts +++ b/sdk/web-pubsub/web-pubsub-express/test/user.spec.ts @@ -46,7 +46,7 @@ describe("Can handle user event", function() { const endSpy = sinon.spy(res.end); const dispatcher = new CloudEventsDispatcher("hub1", ["*"]); - var result = await dispatcher.processRequest(req, res); + const result = await dispatcher.processRequest(req, res); assert.isFalse(result); assert.isTrue(endSpy.notCalled); }); @@ -56,7 +56,7 @@ describe("Can handle user event", function() { buildRequest(req, "hub", "conn1"); const dispatcher = new CloudEventsDispatcher("hub1", ["*"]); - var result = await dispatcher.processRequest(req, res); + const result = await dispatcher.processRequest(req, res); assert.isFalse(result); assert.isTrue(endSpy.notCalled); }); @@ -66,7 +66,7 @@ describe("Can handle user event", function() { buildRequest(req, "hub", "conn1"); const dispatcher = new CloudEventsDispatcher("hub", ["*"]); - var result = await dispatcher.processRequest(req, res); + const result = await dispatcher.processRequest(req, res); assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); assert.equal(200, res.statusCode, "should be 200"); @@ -77,7 +77,7 @@ describe("Can handle user event", function() { buildRequest(req, "hub", "conn1"); const dispatcher = new CloudEventsDispatcher("hub", ["*"], {}); - var result = await dispatcher.processRequest(req, res); + const result = await dispatcher.processRequest(req, res); assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); assert.equal(200, res.statusCode, "should be 200"); @@ -92,9 +92,9 @@ describe("Can handle user event", function() { res.fail(500); } }); - var process = dispatcher.processRequest(req, res); + const process = dispatcher.processRequest(req, res); mockBody(req, JSON.stringify({})); - var result = await process; + const result = await process; assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); assert.equal(500, res.statusCode, "should be error"); @@ -109,9 +109,9 @@ describe("Can handle user event", function() { res.success(); } }); - var process = dispatcher.processRequest(req, res); + const process = dispatcher.processRequest(req, res); mockBody(req, JSON.stringify({})); - var result = await process; + const result = await process; assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); assert.equal(200, res.statusCode, "should be success"); @@ -126,9 +126,9 @@ describe("Can handle user event", function() { res.success("a"); } }); - var process = dispatcher.processRequest(req, res); + const process = dispatcher.processRequest(req, res); mockBody(req, JSON.stringify({})); - var result = await process; + const result = await process; assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); assert.equal(200, res.statusCode, "should be success"); @@ -144,9 +144,9 @@ describe("Can handle user event", function() { res.success("a", "text"); } }); - var process = dispatcher.processRequest(req, res); + const process = dispatcher.processRequest(req, res); mockBody(req, JSON.stringify({})); - var result = await process; + const result = await process; assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); assert.equal(200, res.statusCode, "should be success"); @@ -162,9 +162,9 @@ describe("Can handle user event", function() { res.success("a", "json"); } }); - var process = dispatcher.processRequest(req, res); + const process = dispatcher.processRequest(req, res); mockBody(req, JSON.stringify({})); - var result = await process; + const result = await process; assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); assert.equal(200, res.statusCode, "should be success"); @@ -188,9 +188,9 @@ describe("Can handle user event", function() { res.success(); } }); - var process = dispatcher.processRequest(req, res); + const process = dispatcher.processRequest(req, res); mockBody(req, JSON.stringify({})); - var result = await process; + const result = await process; assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); assert.equal(200, res.statusCode, "should be success"); diff --git a/sdk/web-pubsub/web-pubsub-express/test/validate.spec.ts b/sdk/web-pubsub/web-pubsub-express/test/validate.spec.ts index 12ecbac70a83..becfaa546de9 100644 --- a/sdk/web-pubsub/web-pubsub-express/test/validate.spec.ts +++ b/sdk/web-pubsub/web-pubsub-express/test/validate.spec.ts @@ -12,7 +12,7 @@ describe("Abuse protection works", function() { const res = new ServerResponse(req); const dispatcher = new CloudEventsDispatcher("hub", ["*"]); - var result = dispatcher.processValidateRequest(req, res); + const result = dispatcher.processValidateRequest(req, res); assert.isFalse(result); }); @@ -22,7 +22,7 @@ describe("Abuse protection works", function() { const res = new ServerResponse(req); const dispatcher = new CloudEventsDispatcher("hub", ["*"]); - var result = dispatcher.processValidateRequest(req, res); + const result = dispatcher.processValidateRequest(req, res); assert.isTrue(result); assert.equal("*", res.getHeader("webhook-allowed-origin")); }); @@ -33,7 +33,7 @@ describe("Abuse protection works", function() { const res = new ServerResponse(req); const dispatcher = new CloudEventsDispatcher("hub", ["*", "https://a.com/c"]); - var result = dispatcher.processValidateRequest(req, res); + const result = dispatcher.processValidateRequest(req, res); assert.isTrue(result); assert.equal("*,a.com", res.getHeader("webhook-allowed-origin")); });