Skip to content

Commit 21f28dc

Browse files
authored
[web-pubsub] Migrate @azure/web-pubsub to new core pipeline (Azure#16010)
Update to latest core packages and improve pipeline robustness.
1 parent 13772c2 commit 21f28dc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1124
-794
lines changed

dataplane.code-workspace

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@
271271
{
272272
"name": "iot-device-update",
273273
"path": "sdk/deviceupdate/iot-device-update"
274+
},
275+
{
276+
"path": "sdk/web-pubsub/web-pubsub"
277+
},
278+
{
279+
"path": "sdk/web-pubsub/web-pubsub-express"
274280
}
275281
],
276282
"settings": {

sdk/core/core-rest-pipeline/src/nodeHttpClient.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ class NodeHttpClient implements HttpClient {
129129
request
130130
};
131131

132+
// Responses to HEAD must not have a body.
133+
// If they do return a body, that body must be ignored.
134+
if (request.method === "HEAD") {
135+
resolve(response);
136+
return;
137+
}
138+
132139
responseStream = shouldDecompress ? getDecodedResponseStream(res, headers) : res;
133140

134141
const onDownloadProgress = request.onDownloadProgress;
@@ -142,7 +149,11 @@ class NodeHttpClient implements HttpClient {
142149
if (request.streamResponseStatusCodes?.has(response.status)) {
143150
response.readableStreamBody = responseStream;
144151
} else {
145-
response.bodyAsText = await streamToText(responseStream);
152+
try {
153+
response.bodyAsText = await streamToText(responseStream);
154+
} catch (e) {
155+
reject(e);
156+
}
146157
}
147158

148159
resolve(response);

sdk/core/core-rest-pipeline/src/policies/decompressResponsePolicy.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ export function decompressResponsePolicy(): PipelinePolicy {
1717
return {
1818
name: decompressResponsePolicyName,
1919
async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {
20-
request.headers.set("Accept-Encoding", "gzip,deflate");
20+
// HEAD requests have no body
21+
if (request.method !== "HEAD") {
22+
request.headers.set("Accept-Encoding", "gzip,deflate");
23+
}
2124
return next(request);
2225
}
2326
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release History
22

3+
## 1.0.0-beta.2 (UNRELEASED)
4+
5+
- Removed unnecessary dependencies.
6+
37
## 1.0.0-beta.1 (2021-04-23)
48

59
This is the first release of the @azure/web-pubsub-express package.

sdk/web-pubsub/web-pubsub-express/package.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@azure/web-pubsub-express",
3-
"version": "1.0.0-beta.1",
3+
"version": "1.0.0-beta.2",
44
"description": "Azure Web PubSub CloudEvents handlers",
55
"sdk-type": "client",
66
"main": "dist/index.js",
@@ -57,18 +57,12 @@
5757
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search/",
5858
"sideEffects": false,
5959
"dependencies": {
60-
"@azure/core-auth": "^1.3.0",
61-
"@azure/core-http": "^2.0.0",
62-
"@azure/core-tracing": "1.0.0-preview.12",
63-
"@azure/logger": "^1.0.0",
6460
"tslib": "^2.2.0",
65-
"jsonwebtoken": "^8.5.1",
6661
"cloudevents": "^4.0.0"
6762
},
6863
"devDependencies": {
6964
"@azure/dev-tool": "^1.0.0",
7065
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
71-
"@azure/identity": "^1.1.0",
7266
"@azure/test-utils-recorder": "^1.0.0",
7367
"@microsoft/api-extractor": "7.7.11",
7468
"@rollup/plugin-commonjs": "11.0.2",

sdk/web-pubsub/web-pubsub/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
## 1.0.0-beta.3 (Unreleased)
44

5+
### Breaking Changes
6+
7+
- `hasUser` has been removed from `GroupClient` as that operation is no longer supported by the service.
8+
- Updated to have void returns for most operations. If you were previously using `RestResponse`, you can instead use the `onResponse` callback in the operation options. See README for an example.
59

610
## 1.0.0-beta.2 (2021-05-19)
11+
712
Remove "url" dependency
813

914
## 1.0.0-beta.1 (2021-04-23)

sdk/web-pubsub/web-pubsub/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,18 @@ const payload = new Uint8Array(10);
118118
await serviceClient.sendToAll(payload.buffer);
119119
```
120120

121+
### Access the raw HTTP response for an operation
122+
123+
```js
124+
const { WebPubSubServiceClient } = require("@azure/web-pubsub");
125+
126+
function onResponse(rawResponse: FullOperationResponse): void {
127+
console.log(rawResponse);
128+
}
129+
const serviceClient = new WebPubSubServiceClient("<ConnectionString>", "<hubName>");
130+
await serviceClient.sendToAll({ message: "Hello world!" }, { onResponse });
131+
```
132+
121133
## Troubleshooting
122134

123135
### Enable logs

sdk/web-pubsub/web-pubsub/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node",
3030
"test": "npm run build:test && npm run unit-test && npm run integration-test",
3131
"unit-test:browser": "echo \"Browser is not supported.\" && exit 0",
32-
"unit-test:node": "mocha --reporter ../../../common/tools/mocha-multi-reporter.js dist-test/index.node.js",
32+
"unit-test:node": "mocha --exit --reporter ../../../common/tools/mocha-multi-reporter.js dist-test/index.node.js",
3333
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
3434
"docs": "typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src"
3535
},
@@ -61,7 +61,8 @@
6161
"sideEffects": false,
6262
"dependencies": {
6363
"@azure/core-auth": "^1.3.0",
64-
"@azure/core-http": "^2.0.0",
64+
"@azure/core-client": "^1.0.0",
65+
"@azure/core-rest-pipeline": "^1.1.0",
6566
"@azure/core-tracing": "1.0.0-preview.12",
6667
"@azure/logger": "^1.0.0",
6768
"tslib": "^2.2.0",
@@ -78,12 +79,12 @@
7879
"@rollup/plugin-multi-entry": "^3.0.0",
7980
"@rollup/plugin-node-resolve": "^8.0.0",
8081
"@rollup/plugin-replace": "^2.2.0",
82+
"@types/chai": "^4.1.6",
8183
"@types/jsonwebtoken": "~8.5.0",
8284
"@types/mocha": "^7.0.2",
8385
"@types/node": "^8.0.0",
8486
"@types/query-string": "6.2.0",
8587
"@types/sinon": "^9.0.4",
86-
"assert": "^1.4.1",
8788
"chai": "^4.2.0",
8889
"cross-env": "^7.0.2",
8990
"dotenv": "^8.2.0",

sdk/web-pubsub/web-pubsub/review/web-pubsub.api.md

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
```ts
66

77
import { AzureKeyCredential } from '@azure/core-auth';
8-
import { HttpRequestBody } from '@azure/core-http';
9-
import { OperationOptions } from '@azure/core-http';
10-
import { PipelineOptions } from '@azure/core-http';
11-
import { RestResponse } from '@azure/core-http';
8+
import { CommonClientOptions } from '@azure/core-client';
9+
import { OperationOptions } from '@azure/core-client';
10+
import { RequestBodyType } from '@azure/core-rest-pipeline';
1211

1312
export { AzureKeyCredential }
1413

@@ -40,7 +39,7 @@ export interface GroupAddUserOptions extends OperationOptions {
4039
}
4140

4241
// @public
43-
export interface GroupAdminClientOptions extends PipelineOptions {
42+
export interface GroupAdminClientOptions extends CommonClientOptions {
4443
}
4544

4645
// @public
@@ -72,7 +71,7 @@ export interface HasConnectionOptions extends OperationOptions {
7271
}
7372

7473
// @public
75-
export interface HubAdminClientOptions extends PipelineOptions {
74+
export interface HubAdminClientOptions extends CommonClientOptions {
7675
}
7776

7877
// @public
@@ -141,46 +140,45 @@ export type Permission = "joinLeaveGroup" | "sendToGroup";
141140

142141
// @public (undocumented)
143142
export interface WebPubSubGroup {
144-
addConnection(connectionId: string, options?: GroupAddConnectionOptions): Promise<RestResponse>;
145-
addUser(username: string, options?: GroupAddUserOptions): Promise<RestResponse>;
143+
addConnection(connectionId: string, options?: GroupAddConnectionOptions): Promise<void>;
144+
addUser(username: string, options?: GroupAddUserOptions): Promise<void>;
146145
readonly apiVersion: string;
147146
readonly endpoint: string;
148147
readonly groupName: string;
149-
hasUser(username: string, options?: GroupHasUserOptions): Promise<boolean>;
150148
readonly hubName: string;
151-
removeConnection(connectionId: string, options?: GroupRemoveConnectionOptions): Promise<RestResponse>;
152-
removeUser(username: string, options?: GroupRemoveUserOptions): Promise<RestResponse>;
153-
sendToAll(message: string, options: GroupSendTextToAllOptions): Promise<RestResponse>;
154-
sendToAll(message: JSONTypes, options?: GroupSendToAllOptions): Promise<RestResponse>;
155-
sendToAll(message: HttpRequestBody, options?: GroupSendToAllOptions): Promise<RestResponse>;
149+
removeConnection(connectionId: string, options?: GroupRemoveConnectionOptions): Promise<void>;
150+
removeUser(username: string, options?: GroupRemoveUserOptions): Promise<void>;
151+
sendToAll(message: string, options: GroupSendTextToAllOptions): Promise<void>;
152+
sendToAll(message: JSONTypes, options?: GroupSendToAllOptions): Promise<void>;
153+
sendToAll(message: RequestBodyType, options?: GroupSendToAllOptions): Promise<void>;
156154
}
157155

158156
// @public
159157
export class WebPubSubServiceClient {
160158
constructor(connectionString: string, hubName: string, options?: HubAdminClientOptions);
161159
constructor(endpoint: string, credential: AzureKeyCredential, hubName: string, options?: HubAdminClientOptions);
162160
readonly apiVersion: string;
163-
closeConnection(connectionId: string, options?: CloseConnectionOptions): Promise<RestResponse>;
161+
closeConnection(connectionId: string, options?: CloseConnectionOptions): Promise<void>;
164162
endpoint: string;
165163
getAuthenticationToken(options?: GetAuthenticationTokenOptions): Promise<GetAuthenticationTokenResponse>;
166-
grantPermission(connectionId: string, permission: Permission, options?: HubGrantPermissionOptions): Promise<RestResponse>;
164+
grantPermission(connectionId: string, permission: Permission, options?: HubGrantPermissionOptions): Promise<void>;
167165
group(groupName: string): WebPubSubGroup;
168166
hasConnection(connectionId: string, options?: HasConnectionOptions): Promise<boolean>;
169167
hasGroup(groupName: string, options?: HubHasGroupOptions): Promise<boolean>;
170-
hasPermission(connectionId: string, permission: Permission, options?: HubHasPermissionOptions): Promise<RestResponse>;
168+
hasPermission(connectionId: string, permission: Permission, options?: HubHasPermissionOptions): Promise<boolean>;
171169
hasUser(username: string, options?: HubHasUserOptions): Promise<boolean>;
172170
readonly hubName: string;
173-
removeUserFromAllGroups(userId: string, options?: CloseConnectionOptions): Promise<RestResponse>;
174-
revokePermission(connectionId: string, permission: Permission, options?: HubRevokePermissionOptions): Promise<RestResponse>;
175-
sendToAll(message: string, options: HubSendTextToAllOptions): Promise<RestResponse>;
176-
sendToAll(message: JSONTypes, options?: HubSendToAllOptions): Promise<RestResponse>;
177-
sendToAll(message: HttpRequestBody, options?: HubSendToAllOptions): Promise<RestResponse>;
178-
sendToConnection(connectionId: string, message: string, options: HubSendTextToConnectionOptions): Promise<RestResponse>;
179-
sendToConnection(connectionId: string, message: JSONTypes, options?: HubSendToConnectionOptions): Promise<RestResponse>;
180-
sendToConnection(connectionId: string, message: HttpRequestBody | JSONTypes, options?: HubSendToConnectionOptions | HubSendTextToConnectionOptions): Promise<RestResponse>;
181-
sendToUser(username: string, message: string, options: HubSendTextToUserOptions): Promise<RestResponse>;
182-
sendToUser(username: string, message: JSONTypes, options?: HubSendToUserOptions): Promise<RestResponse>;
183-
sendToUser(username: string, message: HttpRequestBody, options?: HubSendToUserOptions | HubSendTextToUserOptions): Promise<RestResponse>;
171+
removeUserFromAllGroups(userId: string, options?: CloseConnectionOptions): Promise<void>;
172+
revokePermission(connectionId: string, permission: Permission, options?: HubRevokePermissionOptions): Promise<void>;
173+
sendToAll(message: string, options: HubSendTextToAllOptions): Promise<void>;
174+
sendToAll(message: JSONTypes, options?: HubSendToAllOptions): Promise<void>;
175+
sendToAll(message: RequestBodyType, options?: HubSendToAllOptions): Promise<void>;
176+
sendToConnection(connectionId: string, message: string, options: HubSendTextToConnectionOptions): Promise<void>;
177+
sendToConnection(connectionId: string, message: JSONTypes, options?: HubSendToConnectionOptions): Promise<void>;
178+
sendToConnection(connectionId: string, message: RequestBodyType, options?: HubSendToConnectionOptions | HubSendTextToConnectionOptions): Promise<void>;
179+
sendToUser(username: string, message: string, options: HubSendTextToUserOptions): Promise<void>;
180+
sendToUser(username: string, message: JSONTypes, options?: HubSendToUserOptions): Promise<void>;
181+
sendToUser(username: string, message: RequestBodyType, options?: HubSendToUserOptions | HubSendTextToUserOptions): Promise<void>;
184182
}
185183

186184

sdk/web-pubsub/web-pubsub/samples-dev/broadcasting.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ async function main() {
2828
chatHub.sendToAll(data.buffer);
2929
}
3030

31-
main();
31+
main().catch((e) => {
32+
console.error("Sample encountered an error", e);
33+
process.exit(1);
34+
});

0 commit comments

Comments
 (0)