@azure/notification-hubs 2.0.1-alpha.20250108.1 → 2.0.1-alpha.20250110.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/README.md +25 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ Key links:
|
|
|
13
13
|
|
|
14
14
|
- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/notificationhubs/notification-hubs/)
|
|
15
15
|
- [Package (npm)](https://www.npmjs.com/package/@azure/notification-hubs)
|
|
16
|
-
- [Product documentation](https://
|
|
16
|
+
- [Product documentation](https://learn.microsoft.com/azure/notification-hubs/)
|
|
17
17
|
- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/notificationhubs/notification-hubs/samples-dev)
|
|
18
18
|
|
|
19
19
|
**NOTE**: If you are coming from using the `azure-sb` package, see the [migration guide to move from azure-sb to @azure/notification-hubs](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/notificationhubs/notification-hubs/migrationguide.md)
|
|
@@ -36,22 +36,22 @@ npm install @azure/notification-hubs
|
|
|
36
36
|
### Prerequisites
|
|
37
37
|
|
|
38
38
|
- An [Azure Subscription](https://azure.microsoft.com)
|
|
39
|
-
- An [App Notification Hubs](https://
|
|
39
|
+
- An [App Notification Hubs](https://learn.microsoft.com/azure/notification-hubs/) resource.
|
|
40
40
|
|
|
41
41
|
### Create an Azure Notification Hubs resource
|
|
42
42
|
|
|
43
43
|
An Azure Notification Hub can be created using the following methods:
|
|
44
44
|
|
|
45
|
-
1. [Azure Portal](https://
|
|
46
|
-
2. [Azure CLI](https://
|
|
47
|
-
3. [Bicep](https://
|
|
48
|
-
4. [ARM Template](https://
|
|
45
|
+
1. [Azure Portal](https://learn.microsoft.com/azure/notification-hubs/create-notification-hub-portal)
|
|
46
|
+
2. [Azure CLI](https://learn.microsoft.com/azure/notification-hubs/create-notification-hub-azure-cli)
|
|
47
|
+
3. [Bicep](https://learn.microsoft.com/azure/notification-hubs/create-notification-hub-bicep)
|
|
48
|
+
4. [ARM Template](https://learn.microsoft.com/azure/notification-hubs/create-notification-hub-template)
|
|
49
49
|
|
|
50
|
-
Once created, the Notification Hub can be configured using the [Azure Portal or Azure CLI](https://
|
|
50
|
+
Once created, the Notification Hub can be configured using the [Azure Portal or Azure CLI](https://learn.microsoft.com/azure/notification-hubs/configure-notification-hub-portal-pns-settings?tabs=azure-portal).
|
|
51
51
|
|
|
52
52
|
### Importing the Client
|
|
53
53
|
|
|
54
|
-
This SDK for JavaScript offers two ways of interacting with Azure Notification Hubs, either through the class-based approach, or with a modular design approach.
|
|
54
|
+
This SDK for JavaScript offers two ways of interacting with Azure Notification Hubs, either through the class-based approach, or with a modular design approach. The class-based approach is consistent across all packages to create a client and then interact with the methods on the client.
|
|
55
55
|
|
|
56
56
|
```ts snippet:importing_classical
|
|
57
57
|
import { NotificationHubsClient, createAppleInstallation } from "@azure/notification-hubs";
|
|
@@ -67,9 +67,9 @@ const installation = createAppleInstallation({
|
|
|
67
67
|
const result = await client.createOrUpdateInstallation(installation);
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
The modular approach allows the developer to pick and choose which functions to import as each method is exposed individually.
|
|
70
|
+
The modular approach allows the developer to pick and choose which functions to import as each method is exposed individually. This approach uses subpath-exports with ES-Modules to expose the methods via direct imports. With the individual exports, this creates a better tree-shaking experience and smaller bundle sizes that the developer can take advantage of.
|
|
71
71
|
|
|
72
|
-
Note that creating a client is exposed through the `"@azure/notification-hubs/api"` subpath and all client methods are exposed through the `"@azure/notification-hubs/api"` subpath.
|
|
72
|
+
Note that creating a client is exposed through the `"@azure/notification-hubs/api"` subpath and all client methods are exposed through the `"@azure/notification-hubs/api"` subpath. Each function exported takes the `client` as the first parameter and the rest of the parameters remain unchanged.
|
|
73
73
|
|
|
74
74
|
The following subpaths are exposed:
|
|
75
75
|
|
|
@@ -95,7 +95,7 @@ const result = await createOrUpdateInstallation(context, installation);
|
|
|
95
95
|
|
|
96
96
|
### Authenticate the client
|
|
97
97
|
|
|
98
|
-
Interaction with an Azure Notification Hub starts with the `NotificationHubsClient` which supports [Shared Access Signature connection strings](https://
|
|
98
|
+
Interaction with an Azure Notification Hub starts with the `NotificationHubsClient` which supports [Shared Access Signature connection strings](https://learn.microsoft.com/azure/notification-hubs/notification-hubs-push-notification-security). This includes the following permission levels: **Listen**, **Manage**, **Send**.
|
|
99
99
|
|
|
100
100
|
Listen allows for a client to register itself via the Registration and Installations API. Send allows for the client to send notifications to devices using the send APIs. Finally, Manage allows the user to do Registration and Installation management, such as queries.
|
|
101
101
|
|
|
@@ -124,11 +124,11 @@ Once the `NotificationHubClient` has been initialized, the following concepts ca
|
|
|
124
124
|
|
|
125
125
|
### Device Management
|
|
126
126
|
|
|
127
|
-
Device management is a core concept to Notification Hubs to be able to store the unique identifier from the native Platform Notification Service (PNS) such as APNs or Firebase, and associated metadata such as tags used for sending push notifications to audiences.
|
|
127
|
+
Device management is a core concept to Notification Hubs to be able to store the unique identifier from the native Platform Notification Service (PNS) such as APNs or Firebase, and associated metadata such as tags used for sending push notifications to audiences. This is done with two APIs, the Installation API which is the newer and preferred mechanism, and Registrations.
|
|
128
128
|
|
|
129
129
|
#### Installations API
|
|
130
130
|
|
|
131
|
-
Installations are a newer and native JSON approach to device management that contains additional properties such as an installation ID and user ID which can be used for sending to audiences.
|
|
131
|
+
Installations are a newer and native JSON approach to device management that contains additional properties such as an installation ID and user ID which can be used for sending to audiences. The installations API has a few advantages over the existing Registration APIs in the following ways:
|
|
132
132
|
|
|
133
133
|
- Fully idempotent API so calling create on the installation, so an operation can be retried without worries about duplications.
|
|
134
134
|
- Support for `userId` and `installationId` properties which can be then used in tag expressions such as `$InstallationId:{myInstallId}` and `$UserId:{bob@contoso.com}`.
|
|
@@ -230,7 +230,7 @@ const installation = getInstallation(context, installationId);
|
|
|
230
230
|
|
|
231
231
|
#### Registrations API
|
|
232
232
|
|
|
233
|
-
A registration is associated with a PNS just as the installation above, with the unique device identifier from the PNS, and associated tags.
|
|
233
|
+
A registration is associated with a PNS just as the installation above, with the unique device identifier from the PNS, and associated tags. Templates registrations are a way of creating pre-defined body templates which can then be customized at send time with properties to fill in for the message. For more information about templates, see [Templates documentation](https://learn.microsoft.com/azure/notification-hubs/notification-hubs-templates-cross-platform-push-messages).
|
|
234
234
|
|
|
235
235
|
An installation may be created in one of two ways, first by getting a registration ID from the server using `getInstallationId` and then `createOrUpdateRegistration` or via the `createRegistration` method.
|
|
236
236
|
|
|
@@ -265,7 +265,7 @@ const registration = createAppleRegistrationDescription({
|
|
|
265
265
|
const updatedRegistration = await createRegistration(context, registration);
|
|
266
266
|
```
|
|
267
267
|
|
|
268
|
-
Updates can be done via the `updateRegistration` method but unlike installations, does not support incremental updates.
|
|
268
|
+
Updates can be done via the `updateRegistration` method but unlike installations, does not support incremental updates. Querying for an existing registration can be done with the `getRegistration` method.
|
|
269
269
|
|
|
270
270
|
```ts snippet:updateRegistration_classical
|
|
271
271
|
import { NotificationHubsClient } from "@azure/notification-hubs";
|
|
@@ -309,7 +309,7 @@ if (registration.tags) {
|
|
|
309
309
|
const updatedRegistration = await updateRegistration(context, registration);
|
|
310
310
|
```
|
|
311
311
|
|
|
312
|
-
Registrations, unlike installations, can be queried to get all registrations, matching registrations to a condition, or by tags.
|
|
312
|
+
Registrations, unlike installations, can be queried to get all registrations, matching registrations to a condition, or by tags. Registrations can be queried using the `listRegistrations`, `listRegistrationsByChannel` and `listRegistrationsByTag` method. All methods support limiting via the `top` option and support asynchronous paging.
|
|
313
313
|
|
|
314
314
|
```ts snippet:listRegistrationsByTag_classical
|
|
315
315
|
import { NotificationHubsClient } from "@azure/notification-hubs";
|
|
@@ -347,11 +347,11 @@ for await (const pages of registrations.byPage()) {
|
|
|
347
347
|
|
|
348
348
|
### Send Operations
|
|
349
349
|
|
|
350
|
-
Notification Hubs supports sending notifications to devices either directly using the unique PNS provided identifier, using tags for audience send, or a general broadcast to all devices.
|
|
350
|
+
Notification Hubs supports sending notifications to devices either directly using the unique PNS provided identifier, using tags for audience send, or a general broadcast to all devices. Using the Standard SKU and above, [scheduled send](https://learn.microsoft.com/azure/notification-hubs/notification-hubs-send-push-notifications-scheduled) allows the user to schedule notifications up to seven days in advance. All send operations return a Tracking ID and Correlation ID which can be used for Notification Hubs support cases. With the Standard SKU and above, a Notification ID is also returned which can be used to get notification telemetry via the `getNotificationOutcomeDetails` method.
|
|
351
351
|
|
|
352
|
-
For debugging purposes, the `enableTestSend` options can be set to `true` which gets immediate feedback from the PNS on the `sendNotification` method, however, is not supported in production scenarios.
|
|
352
|
+
For debugging purposes, the `enableTestSend` options can be set to `true` which gets immediate feedback from the PNS on the `sendNotification` method, however, is not supported in production scenarios. This is not supported on the scheduled send methods.
|
|
353
353
|
|
|
354
|
-
Raw JSON or XML strings can be sent to the send or scheduled send methods, or the notification builders can be used which helps construct messages per PNS such as APNs, Firebase, Baidu, ADM and WNS.
|
|
354
|
+
Raw JSON or XML strings can be sent to the send or scheduled send methods, or the notification builders can be used which helps construct messages per PNS such as APNs, Firebase, Baidu, ADM and WNS. These builders will build the native message format so there is no guessing about which fields are available for each PNS.
|
|
355
355
|
|
|
356
356
|
```ts snippet:createAppleNotificationBody
|
|
357
357
|
import { createAppleNotificationBody, createAppleNotification } from "@azure/notification-hubs";
|
|
@@ -494,7 +494,7 @@ if (result.notificationId) {
|
|
|
494
494
|
|
|
495
495
|
#### Audience Send
|
|
496
496
|
|
|
497
|
-
In addition to targeting a single device, a user can target multiple devices using tags.
|
|
497
|
+
In addition to targeting a single device, a user can target multiple devices using tags. These tags can be supplied as a list of tags, which then creates a tag expression to match registered devices, or via a tag expression which can then use Boolean logic to target the right audience. For more information about tags and tags expressions, see [Routing and Tag Expressions](https://learn.microsoft.com/azure/notification-hubs/notification-hubs-tags-segment-push-message).
|
|
498
498
|
|
|
499
499
|
If you wish to create a tag expression from an array of tags, there is a Tag Expression Builder available with the `createTagExpression` method which is exposed at the top level import or `@azure/notification-hubs/models/tagExpressionBuilder` modular import which creates an "or tag expression" from the tags.
|
|
500
500
|
|
|
@@ -568,7 +568,7 @@ if (result.notificationId) {
|
|
|
568
568
|
|
|
569
569
|
#### Scheduled Send
|
|
570
570
|
|
|
571
|
-
Push notifications can be scheduled up to seven days in advance with Standard SKU namespaces and above using the `scheduleNotification` method to send to devices with tags or a general broadcast with `scheduleBroadcastNotification`.
|
|
571
|
+
Push notifications can be scheduled up to seven days in advance with Standard SKU namespaces and above using the `scheduleNotification` method to send to devices with tags or a general broadcast with `scheduleBroadcastNotification`. This returns a notification ID which can be then used to cancel if necessary via the `cancelScheduledNotification` method.
|
|
572
572
|
|
|
573
573
|
```ts snippet:scheduledSendNotification_classical
|
|
574
574
|
import { NotificationHubsClient, createAppleNotification } from "@azure/notification-hubs";
|
|
@@ -633,15 +633,15 @@ console.log(`Notification ID: ${result.notificationId}`);
|
|
|
633
633
|
|
|
634
634
|
## React Native Support
|
|
635
635
|
|
|
636
|
-
React Native currently does not have support for [`URLSearchParams`] which is used by the Azure Notification Hubs SDK.
|
|
636
|
+
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.
|
|
637
637
|
|
|
638
638
|
We also need to provide polyfill for `TextEncoder` API and async iterator API. Please see our [React Native sample with Expo](https://github.com/Azure/azure-sdk-for-js/blob/main/samples/frameworks/react-native/appconfigBasic/README.md#add-polyfills) for more details.
|
|
639
639
|
|
|
640
640
|
### Diagnose Dropped Notifications
|
|
641
641
|
|
|
642
|
-
Azure Notification Hubs has a complete guide to troubleshooting problems with dropped notifications in the [Diagnose dropped notifications in Azure Notification Hubs Guide](https://
|
|
642
|
+
Azure Notification Hubs has a complete guide to troubleshooting problems with dropped notifications in the [Diagnose dropped notifications in Azure Notification Hubs Guide](https://learn.microsoft.com/azure/notification-hubs/notification-hubs-push-notification-fixer).
|
|
643
643
|
|
|
644
|
-
[Test send](https://
|
|
644
|
+
[Test send](https://learn.microsoft.com/azure/notification-hubs/notification-hubs-push-notification-fixer#enabletestsend-property) is supported supported in the `sendNotification` and `sendBroadcastNotification` methods with the `enableTestSend` option:
|
|
645
645
|
|
|
646
646
|
```ts snippet:testSend_classical
|
|
647
647
|
import { NotificationHubsClient, createAppleNotification } from "@azure/notification-hubs";
|
|
@@ -750,6 +750,6 @@ folder for more details.
|
|
|
750
750
|
## Related projects
|
|
751
751
|
|
|
752
752
|
- [Microsoft Azure SDK for JavaScript](https://github.com/Azure/azure-sdk-for-js)
|
|
753
|
-
- [Azure Notification Hubs](https://
|
|
753
|
+
- [Azure Notification Hubs](https://learn.microsoft.com/azure/notification-hubs/notification-hubs-push-notification-overview)
|
|
754
754
|
|
|
755
755
|

|
package/package.json
CHANGED