Skip to content

Commit 50cdeab

Browse files
authored
[notification hubs] Fixing tag expression send (Azure#25326)
### Packages impacted by this PR - @azure/notification-hubs ### Issues associated with this PR - Azure#25316 - Azure#25230 ### Describe the problem that is addressed by this PR The `optionUtils` function `isSendNotificationOptions` used the old version of the `SendNotificationOptions` which had the `tags` and not the `tagExpression`. This PR fixes that. ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? ### Are there test cases added in this PR? _(If not, why?)_ Yes ### Provide a list of related PRs _(if any)_ ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [x] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [x] Added a changelog (if necessary)
1 parent 1130087 commit 50cdeab

File tree

5 files changed

+77
-6
lines changed

5 files changed

+77
-6
lines changed

sdk/notificationhubs/notification-hubs/CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Release History
22

3-
## 1.0.1 (Unreleased)
3+
## 1.0.1 (2023-03-21)
44

55
### Features Added
66

7-
### Breaking Changes
7+
- [#25230](ttps://github.com/Azure/azure-sdk-for-js/issues/25230) - Added section for React Native support in troubleshooting.
88

99
### Bugs Fixed
1010

11-
### Other Changes
11+
- [#25316](https://github.com/Azure/azure-sdk-for-js/issues/25316) - Fix `isSendNotificationOptions` to check for `tagExpression` instead of `tags`.
1212

1313
## 1.0.0 (2023-03-15)
1414

sdk/notificationhubs/notification-hubs/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,14 @@ console.log(`Notification ID: ${result.notificationId}`);
655655

656656
## Troubleshooting
657657

658+
## React Native Support
659+
660+
React Native currently does not have support for [`URLSearchParams`] which is used by the Azure Notification Hubs SDK. In order to use the SDK in React Native, you will need to install the [`url-search-params-polyfill`](https://www.npmjs.com/package/url-search-params-polyfill) package and import it before using the SDK.
661+
662+
```typescript
663+
import 'url-search-params-polyfill';
664+
```
665+
658666
### Diagnose Dropped Notifications
659667

660668
Azure Notification Hubs has a complete guide to troubleshooting problems with dropped notifications in the [Diagnose dropped notifications in Azure Notification Hubs Guide](https://docs.microsoft.com/azure/notification-hubs/notification-hubs-push-notification-fixer).

sdk/notificationhubs/notification-hubs/src/auth/hmacSha256.browser.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ export async function signString(key: string, toSign: string): Promise<string> {
77
const enc = new TextEncoder();
88
const algorithm: HmacImportParams = { name: "HMAC", hash: { name: "SHA-256" } };
99

10-
const extractedKey = await self.crypto.subtle.importKey(
10+
const extractedKey = await globalThis.crypto.subtle.importKey(
1111
"raw",
1212
enc.encode(key),
1313
algorithm,
1414
false,
1515
["sign", "verify"]
1616
);
17-
const signature = await self.crypto.subtle.sign(algorithm, extractedKey, enc.encode(toSign));
17+
const signature = await globalThis.crypto.subtle.sign(
18+
algorithm,
19+
extractedKey,
20+
enc.encode(toSign)
21+
);
1822
const digest = btoa(String.fromCharCode(...new Uint8Array(signature)));
1923

2024
return encodeURIComponent(digest);

sdk/notificationhubs/notification-hubs/src/utils/optionUtils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import { objectHasProperty } from "@azure/core-util";
1010
* @returns true if SendNotificationOptions otherwise false.
1111
*/
1212
export function isSendNotificationOptions(options: unknown): options is SendNotificationOptions {
13-
return objectHasProperty(options, "tags") || objectHasProperty(options, "enableTestSend");
13+
return (
14+
objectHasProperty(options, "tagExpression") || objectHasProperty(options, "enableTestSend")
15+
);
1416
}
1517

1618
/**
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
import { assert } from "@azure/test-utils";
5+
import {
6+
isDirectSendNotificationOptions,
7+
isSendNotificationOptions,
8+
} from "../../../src/utils/optionUtils.js";
9+
10+
describe("optionUtils", () => {
11+
describe("isSendNotificationOptions", () => {
12+
it("should return true if options has tagExpression", () => {
13+
const options = { tagExpression: "tag" };
14+
assert.isTrue(isSendNotificationOptions(options));
15+
});
16+
17+
it("should return true if options has enableTestSend", () => {
18+
const options = { enableTestSend: true };
19+
assert.isTrue(isSendNotificationOptions(options));
20+
});
21+
22+
it("should return false if options is bad", () => {
23+
const options1 = undefined;
24+
assert.isFalse(isSendNotificationOptions(options1));
25+
26+
const options2 = null;
27+
assert.isFalse(isSendNotificationOptions(options2));
28+
29+
const options3 = "";
30+
assert.isFalse(isSendNotificationOptions(options3));
31+
32+
const options4 = {};
33+
assert.isFalse(isSendNotificationOptions(options4));
34+
});
35+
});
36+
37+
describe("isDirectSendNotificationOptions", () => {
38+
it("should return true if options has deviceHandle", () => {
39+
const options = { deviceHandle: "handle" };
40+
assert.isTrue(isDirectSendNotificationOptions(options));
41+
});
42+
43+
it("should return false if options is bad", () => {
44+
const options1 = undefined;
45+
assert.isFalse(isDirectSendNotificationOptions(options1));
46+
47+
const options2 = null;
48+
assert.isFalse(isDirectSendNotificationOptions(options2));
49+
50+
const options3 = "";
51+
assert.isFalse(isDirectSendNotificationOptions(options3));
52+
53+
const options4 = {};
54+
assert.isFalse(isDirectSendNotificationOptions(options4));
55+
});
56+
});
57+
});

0 commit comments

Comments
 (0)