@azure/notification-hubs 1.0.0-beta.6 → 1.0.0-beta.7
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 +84 -77
- package/dist/index.cjs +312 -369
- package/dist/index.cjs.map +1 -1
- package/dist-esm/src/{client → api}/beginSubmitNotificationHubJob.js +0 -0
- package/dist-esm/src/api/beginSubmitNotificationHubJob.js.map +1 -0
- package/dist-esm/src/{client → api}/cancelScheduledNotification.js +0 -0
- package/dist-esm/src/api/cancelScheduledNotification.js.map +1 -0
- package/dist-esm/src/{client → api}/createOrUpdateInstallation.js +0 -0
- package/dist-esm/src/api/createOrUpdateInstallation.js.map +1 -0
- package/dist-esm/src/{client → api}/createOrUpdateRegistration.js +0 -0
- package/dist-esm/src/api/createOrUpdateRegistration.js.map +1 -0
- package/dist-esm/src/{client → api}/createRegistration.js +0 -0
- package/dist-esm/src/api/createRegistration.js.map +1 -0
- package/dist-esm/src/{client → api}/createRegistrationId.js +0 -0
- package/dist-esm/src/api/createRegistrationId.js.map +1 -0
- package/dist-esm/src/{client → api}/deleteInstallation.js +0 -0
- package/dist-esm/src/api/deleteInstallation.js.map +1 -0
- package/dist-esm/src/{client → api}/deleteRegistration.js +0 -0
- package/dist-esm/src/api/deleteRegistration.js.map +1 -0
- package/dist-esm/src/{client → api}/getFeedbackContainerUrl.js +0 -0
- package/dist-esm/src/api/getFeedbackContainerUrl.js.map +1 -0
- package/dist-esm/src/{client → api}/getInstallation.js +0 -0
- package/dist-esm/src/api/getInstallation.js.map +1 -0
- package/dist-esm/src/{client → api}/getNotificationHubJob.js +0 -0
- package/dist-esm/src/api/getNotificationHubJob.js.map +1 -0
- package/dist-esm/src/{client → api}/getNotificationOutcomeDetails.js +0 -0
- package/dist-esm/src/api/getNotificationOutcomeDetails.js.map +1 -0
- package/dist-esm/src/{client → api}/getRegistration.js +0 -0
- package/dist-esm/src/api/getRegistration.js.map +1 -0
- package/dist-esm/src/{client → api}/index.js +22 -0
- package/dist-esm/src/api/index.js.map +1 -0
- package/dist-esm/src/{client → api}/internal/_client.js +1 -1
- package/dist-esm/src/api/internal/_client.js.map +1 -0
- package/dist-esm/src/{client → api}/internal/_createOrUpdateRegistrationDescription.js +0 -0
- package/dist-esm/src/api/internal/_createOrUpdateRegistrationDescription.js.map +1 -0
- package/dist-esm/src/{client/listRegistrations.js → api/internal/_listRegistrations.js} +6 -38
- package/dist-esm/src/api/internal/_listRegistrations.js.map +1 -0
- package/dist-esm/src/{client → api}/listNotificationHubJobs.js +0 -0
- package/dist-esm/src/api/listNotificationHubJobs.js.map +1 -0
- package/dist-esm/src/api/listRegistrations.js +35 -0
- package/dist-esm/src/api/listRegistrations.js.map +1 -0
- package/dist-esm/src/api/listRegistrationsByChannel.js +58 -0
- package/dist-esm/src/api/listRegistrationsByChannel.js.map +1 -0
- package/dist-esm/src/{client → api}/listRegistrationsByTag.js +0 -0
- package/dist-esm/src/api/listRegistrationsByTag.js.map +1 -0
- package/dist-esm/src/{client → api}/scheduleNotification.js +2 -3
- package/dist-esm/src/api/scheduleNotification.js.map +1 -0
- package/dist-esm/src/{client → api}/sendNotification.js +3 -3
- package/dist-esm/src/api/sendNotification.js.map +1 -0
- package/dist-esm/src/{client → api}/submitNotificationHubJob.js +0 -0
- package/dist-esm/src/api/submitNotificationHubJob.js.map +1 -0
- package/dist-esm/src/{client → api}/updateInstallation.js +0 -0
- package/dist-esm/src/api/updateInstallation.js.map +1 -0
- package/dist-esm/src/{client → api}/updateRegistration.js +0 -0
- package/dist-esm/src/api/updateRegistration.js.map +1 -0
- package/dist-esm/src/index.js +3 -2
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/models/index.js +12 -0
- package/dist-esm/src/models/index.js.map +1 -0
- package/dist-esm/src/models/installation.js.map +1 -1
- package/dist-esm/src/models/notification.js.map +1 -1
- package/dist-esm/src/models/notificationBodyBuilder.js +48 -0
- package/dist-esm/src/models/notificationBodyBuilder.js.map +1 -0
- package/dist-esm/src/models/notificationDetails.js.map +1 -1
- package/dist-esm/src/models/options.js.map +1 -1
- package/dist-esm/src/models/registration.js +12 -12
- package/dist-esm/src/models/registration.js.map +1 -1
- package/dist-esm/src/models/tagExpressionBuilder.js +11 -0
- package/dist-esm/src/models/tagExpressionBuilder.js.map +1 -0
- package/dist-esm/src/notificationHubsClient.js +34 -24
- package/dist-esm/src/notificationHubsClient.js.map +1 -1
- package/dist-esm/src/serializers/notificationDetailsSerializer.js.map +1 -1
- package/dist-esm/src/serializers/notificationOutcomeSerializer.js +2 -2
- package/dist-esm/src/serializers/notificationOutcomeSerializer.js.map +1 -1
- package/dist-esm/src/serializers/registrationSerializer.js +16 -16
- package/dist-esm/src/serializers/registrationSerializer.js.map +1 -1
- package/dist-esm/src/utils/constants.js +1 -1
- package/dist-esm/src/utils/constants.js.map +1 -1
- package/dist-esm/src/utils/notificationUtils.js +0 -6
- package/dist-esm/src/utils/notificationUtils.js.map +1 -1
- package/package.json +9 -13
- package/types/3.1/notification-hubs.d.ts +420 -249
- package/types/latest/notification-hubs.d.ts +448 -254
- package/types/latest/tsdoc-metadata.json +1 -1
- package/types/src/{client → api}/beginSubmitNotificationHubJob.d.ts +0 -0
- package/types/src/api/beginSubmitNotificationHubJob.d.ts.map +1 -0
- package/types/src/{client → api}/cancelScheduledNotification.d.ts +0 -0
- package/types/src/api/cancelScheduledNotification.d.ts.map +1 -0
- package/types/src/{client → api}/createOrUpdateInstallation.d.ts +0 -0
- package/types/src/api/createOrUpdateInstallation.d.ts.map +1 -0
- package/types/src/{client → api}/createOrUpdateRegistration.d.ts +0 -0
- package/types/src/api/createOrUpdateRegistration.d.ts.map +1 -0
- package/types/src/{client → api}/createRegistration.d.ts +0 -0
- package/types/src/api/createRegistration.d.ts.map +1 -0
- package/types/src/{client → api}/createRegistrationId.d.ts +0 -0
- package/types/src/api/createRegistrationId.d.ts.map +1 -0
- package/types/src/{client → api}/deleteInstallation.d.ts +0 -0
- package/types/src/api/deleteInstallation.d.ts.map +1 -0
- package/types/src/{client → api}/deleteRegistration.d.ts +0 -0
- package/types/src/api/deleteRegistration.d.ts.map +1 -0
- package/types/src/{client → api}/getFeedbackContainerUrl.d.ts +0 -0
- package/types/src/api/getFeedbackContainerUrl.d.ts.map +1 -0
- package/types/src/{client → api}/getInstallation.d.ts +0 -0
- package/types/src/api/getInstallation.d.ts.map +1 -0
- package/types/src/{client → api}/getNotificationHubJob.d.ts +0 -0
- package/types/src/api/getNotificationHubJob.d.ts.map +1 -0
- package/types/src/{client → api}/getNotificationOutcomeDetails.d.ts +0 -0
- package/types/src/api/getNotificationOutcomeDetails.d.ts.map +1 -0
- package/types/src/{client → api}/getRegistration.d.ts +0 -0
- package/types/src/api/getRegistration.d.ts.map +1 -0
- package/types/src/{client → api}/index.d.ts +22 -0
- package/types/src/api/index.d.ts.map +1 -0
- package/types/src/{client → api}/internal/_client.d.ts +0 -0
- package/types/src/api/internal/_client.d.ts.map +1 -0
- package/types/src/{client → api}/internal/_createOrUpdateRegistrationDescription.d.ts +0 -0
- package/types/src/api/internal/_createOrUpdateRegistrationDescription.d.ts.map +1 -0
- package/types/src/api/internal/_listRegistrations.d.ts +6 -0
- package/types/src/api/internal/_listRegistrations.d.ts.map +1 -0
- package/types/src/{client → api}/listNotificationHubJobs.d.ts +0 -0
- package/types/src/api/listNotificationHubJobs.d.ts.map +1 -0
- package/types/src/{client → api}/listRegistrations.d.ts +3 -3
- package/types/src/api/listRegistrations.d.ts.map +1 -0
- package/types/src/api/listRegistrationsByChannel.d.ts +13 -0
- package/types/src/api/listRegistrationsByChannel.d.ts.map +1 -0
- package/types/src/{client → api}/listRegistrationsByTag.d.ts +0 -0
- package/types/src/api/listRegistrationsByTag.d.ts.map +1 -0
- package/types/src/{client → api}/scheduleNotification.d.ts +0 -0
- package/types/src/api/scheduleNotification.d.ts.map +1 -0
- package/types/src/{client → api}/sendNotification.d.ts +0 -0
- package/types/src/api/sendNotification.d.ts.map +1 -0
- package/types/src/{client → api}/submitNotificationHubJob.d.ts +0 -0
- package/types/src/api/submitNotificationHubJob.d.ts.map +1 -0
- package/types/src/{client → api}/updateInstallation.d.ts +0 -0
- package/types/src/api/updateInstallation.d.ts.map +1 -0
- package/types/src/{client → api}/updateRegistration.d.ts +0 -0
- package/types/src/api/updateRegistration.d.ts.map +1 -0
- package/types/src/index.d.ts +3 -2
- package/types/src/index.d.ts.map +1 -1
- package/types/src/models/index.d.ts +10 -0
- package/types/src/models/index.d.ts.map +1 -0
- package/types/src/models/installation.d.ts +12 -11
- package/types/src/models/installation.d.ts.map +1 -1
- package/types/src/models/notification.d.ts +10 -18
- package/types/src/models/notification.d.ts.map +1 -1
- package/types/src/models/{notificationBuilder.d.ts → notificationBodyBuilder.d.ts} +62 -64
- package/types/src/models/notificationBodyBuilder.d.ts.map +1 -0
- package/types/src/models/notificationDetails.d.ts +9 -9
- package/types/src/models/notificationDetails.d.ts.map +1 -1
- package/types/src/models/options.d.ts +4 -4
- package/types/src/models/options.d.ts.map +1 -1
- package/types/src/models/registration.d.ts +235 -69
- package/types/src/models/registration.d.ts.map +1 -1
- package/types/src/models/tagExpressionBuilder.d.ts +7 -0
- package/types/src/models/tagExpressionBuilder.d.ts.map +1 -0
- package/types/src/notificationHubsClient.d.ts +12 -5
- package/types/src/notificationHubsClient.d.ts.map +1 -1
- package/types/src/serializers/registrationSerializer.d.ts +14 -14
- package/types/src/serializers/registrationSerializer.d.ts.map +1 -1
- package/types/src/utils/notificationUtils.d.ts +0 -4
- package/types/src/utils/notificationUtils.d.ts.map +1 -1
- package/dist-esm/src/client/beginSubmitNotificationHubJob.js.map +0 -1
- package/dist-esm/src/client/cancelScheduledNotification.js.map +0 -1
- package/dist-esm/src/client/createOrUpdateInstallation.js.map +0 -1
- package/dist-esm/src/client/createOrUpdateRegistration.js.map +0 -1
- package/dist-esm/src/client/createRegistration.js.map +0 -1
- package/dist-esm/src/client/createRegistrationId.js.map +0 -1
- package/dist-esm/src/client/deleteInstallation.js.map +0 -1
- package/dist-esm/src/client/deleteRegistration.js.map +0 -1
- package/dist-esm/src/client/getFeedbackContainerUrl.js.map +0 -1
- package/dist-esm/src/client/getInstallation.js.map +0 -1
- package/dist-esm/src/client/getNotificationHubJob.js.map +0 -1
- package/dist-esm/src/client/getNotificationOutcomeDetails.js.map +0 -1
- package/dist-esm/src/client/getRegistration.js.map +0 -1
- package/dist-esm/src/client/index.js.map +0 -1
- package/dist-esm/src/client/internal/_client.js.map +0 -1
- package/dist-esm/src/client/internal/_createOrUpdateRegistrationDescription.js.map +0 -1
- package/dist-esm/src/client/listNotificationHubJobs.js.map +0 -1
- package/dist-esm/src/client/listRegistrations.js.map +0 -1
- package/dist-esm/src/client/listRegistrationsByTag.js.map +0 -1
- package/dist-esm/src/client/scheduleNotification.js.map +0 -1
- package/dist-esm/src/client/sendNotification.js.map +0 -1
- package/dist-esm/src/client/submitNotificationHubJob.js.map +0 -1
- package/dist-esm/src/client/updateInstallation.js.map +0 -1
- package/dist-esm/src/client/updateRegistration.js.map +0 -1
- package/dist-esm/src/models/notificationBuilder.js +0 -169
- package/dist-esm/src/models/notificationBuilder.js.map +0 -1
- package/dist-esm/src/utils/retryPolicy.js +0 -144
- package/dist-esm/src/utils/retryPolicy.js.map +0 -1
- package/types/src/client/beginSubmitNotificationHubJob.d.ts.map +0 -1
- package/types/src/client/cancelScheduledNotification.d.ts.map +0 -1
- package/types/src/client/createOrUpdateInstallation.d.ts.map +0 -1
- package/types/src/client/createOrUpdateRegistration.d.ts.map +0 -1
- package/types/src/client/createRegistration.d.ts.map +0 -1
- package/types/src/client/createRegistrationId.d.ts.map +0 -1
- package/types/src/client/deleteInstallation.d.ts.map +0 -1
- package/types/src/client/deleteRegistration.d.ts.map +0 -1
- package/types/src/client/getFeedbackContainerUrl.d.ts.map +0 -1
- package/types/src/client/getInstallation.d.ts.map +0 -1
- package/types/src/client/getNotificationHubJob.d.ts.map +0 -1
- package/types/src/client/getNotificationOutcomeDetails.d.ts.map +0 -1
- package/types/src/client/getRegistration.d.ts.map +0 -1
- package/types/src/client/index.d.ts.map +0 -1
- package/types/src/client/internal/_client.d.ts.map +0 -1
- package/types/src/client/internal/_createOrUpdateRegistrationDescription.d.ts.map +0 -1
- package/types/src/client/listNotificationHubJobs.d.ts.map +0 -1
- package/types/src/client/listRegistrations.d.ts.map +0 -1
- package/types/src/client/listRegistrationsByTag.d.ts.map +0 -1
- package/types/src/client/scheduleNotification.d.ts.map +0 -1
- package/types/src/client/sendNotification.d.ts.map +0 -1
- package/types/src/client/submitNotificationHubJob.d.ts.map +0 -1
- package/types/src/client/updateInstallation.d.ts.map +0 -1
- package/types/src/client/updateRegistration.d.ts.map +0 -1
- package/types/src/models/notificationBuilder.d.ts.map +0 -1
- package/types/src/utils/retryPolicy.d.ts +0 -72
- package/types/src/utils/retryPolicy.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ import {
|
|
|
57
57
|
createAppleInstallation
|
|
58
58
|
} from "@azure/notification-hubs";
|
|
59
59
|
|
|
60
|
-
const client = new
|
|
60
|
+
const client = new NotificationHubsClient("<connection string>", "<hub name>");
|
|
61
61
|
|
|
62
62
|
const installation = createAppleInstallation({
|
|
63
63
|
installationId: "<installation-id>",
|
|
@@ -70,24 +70,17 @@ const result = await client.createOrUpdateInstallation(installation);
|
|
|
70
70
|
|
|
71
71
|
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.
|
|
72
72
|
|
|
73
|
-
Note that creating a client is exposed through the `"@azure/notification-hubs/
|
|
73
|
+
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.
|
|
74
74
|
|
|
75
75
|
The following subpaths are exposed:
|
|
76
76
|
|
|
77
|
-
- `@azure/notification-hubs/
|
|
78
|
-
- `@azure/notification-hubs/
|
|
79
|
-
- `@azure/notification-hubs/models/installation` - The installation models and factory methods.
|
|
80
|
-
- `@azure/notification-hubs/models/notification` - The notification models and factory methods.
|
|
81
|
-
- `@azure/notification-hubs/models/notificationBuilder` - The notification builder models and factory methods.
|
|
82
|
-
- `@azure/notification-hubs/models/options` - The method options such as `SendOperationOptions`.
|
|
83
|
-
- `@azure/notification-hubs/models/registration` - The registration models and factory methods.
|
|
77
|
+
- `@azure/notification-hubs/api` - The main entry point for the client via `createClientContext` and client methods such as `getInstallation` or `sendNotification`
|
|
78
|
+
- `@azure/notification-hubs/models` - The Notification Hubs models and factory methods.
|
|
84
79
|
|
|
85
80
|
The above code snippet then becomes the following:
|
|
86
81
|
|
|
87
82
|
```typescript
|
|
88
|
-
import { createClientContext } from "@azure/notification-hubs/
|
|
89
|
-
import { createAppleInstallation } from "@azure/notification-hubs/models/installation";
|
|
90
|
-
import { createOrUpdateInstallation } from "@azure/notification-hubs/client/createOrUpdateInstallation";
|
|
83
|
+
import { createClientContext, createOrUpdateInstallation } from "@azure/notification-hubs/api";
|
|
91
84
|
|
|
92
85
|
const context = createClientContext("<connection string>", "<hub name>");
|
|
93
86
|
|
|
@@ -102,22 +95,22 @@ const result = await createOrUpdateInstallation(context, installation);
|
|
|
102
95
|
|
|
103
96
|
### Authenticate the client
|
|
104
97
|
|
|
105
|
-
Interaction with an Azure Notification Hub starts with the `
|
|
98
|
+
Interaction with an Azure Notification Hub starts with the `NotificationHubsClient` which supports [Shared Access Signature connection strings](https://docs.microsoft.com/azure/notification-hubs/notification-hubs-push-notification-security). This includes the following permission levels: **Listen**, **Manage**, **Send**.
|
|
106
99
|
|
|
107
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.
|
|
108
101
|
|
|
109
|
-
A new `
|
|
102
|
+
A new `NotificationHubsClient` client can be created using the constructor with the connection string and Notification Hub name.
|
|
110
103
|
|
|
111
104
|
```typescript
|
|
112
|
-
import {
|
|
105
|
+
import { NotificationHubsClient } from "@azure/notification-hubs";
|
|
113
106
|
|
|
114
|
-
const client = new
|
|
107
|
+
const client = new NotificationHubsClient("<connection string>", "<hub name>");
|
|
115
108
|
```
|
|
116
109
|
|
|
117
|
-
Using the modular approach, the `createClientContext` can be imported via the `"@azure/notification-hubs/
|
|
110
|
+
Using the modular approach, the `createClientContext` can be imported via the `"@azure/notification-hubs/api"` subpath.
|
|
118
111
|
|
|
119
112
|
```typescript
|
|
120
|
-
import { createClientContext } from "@azure/notification-hubs/
|
|
113
|
+
import { createClientContext } from "@azure/notification-hubs/api";
|
|
121
114
|
|
|
122
115
|
const context = createClientContext("<connection string>", "<hub name>");
|
|
123
116
|
```
|
|
@@ -145,10 +138,10 @@ Installations are a newer and native JSON approach to device management that con
|
|
|
145
138
|
Installations can be created through the `createOrUpdateInstallation` method such as the following:
|
|
146
139
|
|
|
147
140
|
```typescript
|
|
148
|
-
import {
|
|
141
|
+
import { NotificationHubsClient, createAppleInstallation } from "@azure/notification-hubs";
|
|
149
142
|
import { v4 as uuid } from "uuid";
|
|
150
143
|
|
|
151
|
-
const client = new
|
|
144
|
+
const client = new NotificationHubsClient("<connection string>", "<hub name>");
|
|
152
145
|
|
|
153
146
|
// Create an installation for APNs
|
|
154
147
|
let installation = createAppleInstallation({
|
|
@@ -163,9 +156,8 @@ installation = await client.createOrUpdateInstallation(installation);
|
|
|
163
156
|
Using the modular approach, the code would be as follows:
|
|
164
157
|
|
|
165
158
|
```typescript
|
|
166
|
-
import { createClientContext } from "@azure/notification-hubs/
|
|
167
|
-
import { createAppleInstallation } from "@azure/notification-hubs/models
|
|
168
|
-
import { createOrUpdateInstallation } from "@azure/notification-hubs/client/createOrUpdateInstallation";
|
|
159
|
+
import { createClientContext, createOrUpdateInstallation } from "@azure/notification-hubs/api";
|
|
160
|
+
import { createAppleInstallation } from "@azure/notification-hubs/models";
|
|
169
161
|
import { v4 as uuid } from "uuid";
|
|
170
162
|
|
|
171
163
|
const context = createClientContext("<connection string>", "<hub name>");
|
|
@@ -183,9 +175,9 @@ installation = await createOrUpdateInstallation(context, installation);
|
|
|
183
175
|
An update to an installation can be made through the JSON Patch schema such as adding a tag and a user ID using the `updateInstallation` method.
|
|
184
176
|
|
|
185
177
|
```typescript
|
|
186
|
-
import {
|
|
178
|
+
import { NotificationHubsClient, JsonPatch } from "@azure/notification-hubs";
|
|
187
179
|
|
|
188
|
-
const client = new
|
|
180
|
+
const client = new NotificationHubsClient("<connection string>", "<hub name>");
|
|
189
181
|
|
|
190
182
|
const installationId = "<unique installation ID>";
|
|
191
183
|
|
|
@@ -200,9 +192,8 @@ const installation = await client.updateInstallation(installationId, updates);
|
|
|
200
192
|
Using the modular approach, the code would be as follows:
|
|
201
193
|
|
|
202
194
|
```typescript
|
|
203
|
-
import { createClientContext } from "@azure/notification-hubs/
|
|
204
|
-
import { JsonPatch, createAppleInstallation } from "@azure/notification-hubs/models
|
|
205
|
-
import { updateInstallation } from "@azure/notification-hubs/client/updateInstallation";
|
|
195
|
+
import { createClientContext, updateInstallation } from "@azure/notification-hubs/api";
|
|
196
|
+
import { JsonPatch, createAppleInstallation } from "@azure/notification-hubs/models";
|
|
206
197
|
|
|
207
198
|
const context = createClientContext("<connection string>", "<hub name>");
|
|
208
199
|
|
|
@@ -219,9 +210,9 @@ const installation = await updateInstallation(context, installationId, updates);
|
|
|
219
210
|
To retrieve an existing installation, use the `getInstallation` method with your existing unique installation ID.
|
|
220
211
|
|
|
221
212
|
```typescript
|
|
222
|
-
import {
|
|
213
|
+
import { NotificationHubsClient } from "@azure/notification-hubs";
|
|
223
214
|
|
|
224
|
-
const client = new
|
|
215
|
+
const client = new NotificationHubsClient("<connection string>", "<hub name>");
|
|
225
216
|
|
|
226
217
|
const installationId = "<unique installation ID>";
|
|
227
218
|
|
|
@@ -231,8 +222,7 @@ const installation = client.getInstallation(installationId);
|
|
|
231
222
|
Using the modular approach, the code would be as follows:
|
|
232
223
|
|
|
233
224
|
```typescript
|
|
234
|
-
import { createClientContext } from "@azure/notification-hubs/
|
|
235
|
-
import { getInstallation } from "@azure/notification-hubs/client/getInstallation";
|
|
225
|
+
import { createClientContext, getInstallation } from "@azure/notification-hubs/api";
|
|
236
226
|
|
|
237
227
|
const context = createClientContext("<connection string>", "<hub name>");
|
|
238
228
|
|
|
@@ -249,11 +239,11 @@ An installation may be created in one of two ways, first by getting a registrati
|
|
|
249
239
|
|
|
250
240
|
```typescript
|
|
251
241
|
import {
|
|
252
|
-
|
|
242
|
+
NotificationHubsClient,
|
|
253
243
|
createAppleRegistrationDescription,
|
|
254
244
|
} from "@azure/notification-hubs";
|
|
255
245
|
|
|
256
|
-
const client = new
|
|
246
|
+
const client = new NotificationHubsClient("<connection string>", "<hub name>");
|
|
257
247
|
|
|
258
248
|
let registration = createAppleRegistrationDescription({
|
|
259
249
|
deviceToken: "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0",
|
|
@@ -268,9 +258,8 @@ console.log(`New Registration ID: ${registration.registrationId}`);
|
|
|
268
258
|
Using the modular approach, the code would be as follows:
|
|
269
259
|
|
|
270
260
|
```typescript
|
|
271
|
-
import { createClientContext } from "@azure/notification-hubs/
|
|
272
|
-
import { createAppleRegistrationDescription } from "@azure/notification-hubs/models
|
|
273
|
-
import { createRegistration } from "@azure/notification-hubs/client/createRegistration";
|
|
261
|
+
import { createClientContext, createRegistration } from "@azure/notification-hubs/api";
|
|
262
|
+
import { createAppleRegistrationDescription } from "@azure/notification-hubs/models";
|
|
274
263
|
|
|
275
264
|
const context = createClientContext("<connection string>", "<hub name>");
|
|
276
265
|
|
|
@@ -287,9 +276,9 @@ console.log(`New Registration ID: ${registration.registrationId}`);
|
|
|
287
276
|
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.
|
|
288
277
|
|
|
289
278
|
```typescript
|
|
290
|
-
import {
|
|
279
|
+
import { NotificationHubsClient } from "@azure/notification-hubs";
|
|
291
280
|
|
|
292
|
-
const client = new
|
|
281
|
+
const client = new NotificationHubsClient("<connection string>", "<hub name>");
|
|
293
282
|
|
|
294
283
|
const registrationId = "<unique Registration ID>";
|
|
295
284
|
|
|
@@ -303,9 +292,11 @@ registration = await client.updateRegistration(registration);
|
|
|
303
292
|
Using the modular approach, the code would be as follows:
|
|
304
293
|
|
|
305
294
|
```typescript
|
|
306
|
-
import {
|
|
307
|
-
|
|
308
|
-
|
|
295
|
+
import {
|
|
296
|
+
createClientContext,
|
|
297
|
+
getRegistration,
|
|
298
|
+
updateRegistration
|
|
299
|
+
} from "@azure/notification-hubs/api";
|
|
309
300
|
|
|
310
301
|
const context = createClientContext("<connection string>", "<hub name>");
|
|
311
302
|
|
|
@@ -318,12 +309,12 @@ registration.tags.push("likes_sports");
|
|
|
318
309
|
registration = await updateRegistration(context, registration);
|
|
319
310
|
```
|
|
320
311
|
|
|
321
|
-
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` and `listRegistrationsByTag` method.
|
|
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.
|
|
322
313
|
|
|
323
314
|
```typescript
|
|
324
|
-
import {
|
|
315
|
+
import { NotificationHubsClient } from "@azure/notification-hubs/api";
|
|
325
316
|
|
|
326
|
-
const client = new
|
|
317
|
+
const client = new NotificationHubsClient("<connection string>", "<hub name>");
|
|
327
318
|
|
|
328
319
|
const registrations = await client.listRegistrationsByTag("likes_hockey");
|
|
329
320
|
|
|
@@ -339,8 +330,7 @@ for await (const pages of registrations.byPage()) {
|
|
|
339
330
|
Using the modular approach, the code would be as follows:
|
|
340
331
|
|
|
341
332
|
```typescript
|
|
342
|
-
import { createClientContext } from "@azure/notification-hubs/
|
|
343
|
-
import { listRegistrationsByTag } from "@azure/notification-hubs/client/listRegistrationsByTag";
|
|
333
|
+
import { createClientContext, listRegistrationsByTag } from "@azure/notification-hubs/api";
|
|
344
334
|
|
|
345
335
|
const context = createClientContext("<connection string>", "<hub name>");
|
|
346
336
|
|
|
@@ -361,16 +351,16 @@ Notification Hubs supports sending notifications to devices either directly usin
|
|
|
361
351
|
|
|
362
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.
|
|
363
353
|
|
|
364
|
-
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
|
|
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.
|
|
365
355
|
|
|
366
356
|
```typescript
|
|
367
357
|
// Using the class-based approach
|
|
368
|
-
import {
|
|
358
|
+
import { createAppleNotificationBody } from "@azure/notification-hubs";
|
|
369
359
|
|
|
370
360
|
// Using the modular approach
|
|
371
|
-
import {
|
|
361
|
+
import { createAppleNotification, createAppleNotificationBody } from "@azure/notification-hubs/models";
|
|
372
362
|
|
|
373
|
-
const
|
|
363
|
+
const apnsBody = createAppleNotificationBody({
|
|
374
364
|
alert: {
|
|
375
365
|
title: "Notification Title",
|
|
376
366
|
subtitle: "Notification Subtitle",
|
|
@@ -381,8 +371,11 @@ const apnsMessage = buildAppleNativeMessage({
|
|
|
381
371
|
});
|
|
382
372
|
|
|
383
373
|
// Send the message using the modular approach
|
|
374
|
+
const notification = createAppleNotification({
|
|
375
|
+
body: apnsBody
|
|
376
|
+
})
|
|
384
377
|
|
|
385
|
-
const result = await sendNotification(context,
|
|
378
|
+
const result = await sendNotification(context, notification);
|
|
386
379
|
```
|
|
387
380
|
|
|
388
381
|
#### Broadcast Send
|
|
@@ -391,9 +384,9 @@ Notification Hubs can be used to send notifications to all registered devices pe
|
|
|
391
384
|
|
|
392
385
|
```typescript
|
|
393
386
|
import {
|
|
394
|
-
|
|
387
|
+
NotificationHubsClient,
|
|
395
388
|
createAppleNotification,
|
|
396
|
-
} from "@azure/notification-hubs/
|
|
389
|
+
} from "@azure/notification-hubs/api";
|
|
397
390
|
|
|
398
391
|
const context = createClientContext(connectionString, hubName);
|
|
399
392
|
|
|
@@ -421,9 +414,8 @@ if (result.notificationId) {
|
|
|
421
414
|
Using the modular approach, the code would be as follows:
|
|
422
415
|
|
|
423
416
|
```typescript
|
|
424
|
-
import { createClientContext } from "@azure/notification-hubs/
|
|
425
|
-
import { createAppleNotification } from "@azure/notification-hubs/models
|
|
426
|
-
import { sendNotification } from "@azure/notification-hubs/client/sendNotification";
|
|
417
|
+
import { createClientContext, sendNotification } from "@azure/notification-hubs/api";
|
|
418
|
+
import { createAppleNotification } from "@azure/notification-hubs/models";
|
|
427
419
|
|
|
428
420
|
const context = createClientContext(connectionString, hubName);
|
|
429
421
|
|
|
@@ -454,11 +446,11 @@ To send directly a device, the user can send using the platform provided unique
|
|
|
454
446
|
|
|
455
447
|
```typescript
|
|
456
448
|
import {
|
|
457
|
-
|
|
449
|
+
NotificationHubsClient,
|
|
458
450
|
createAppleNotification,
|
|
459
451
|
} from "@azure/notification-hubs";
|
|
460
452
|
|
|
461
|
-
const client = new
|
|
453
|
+
const client = new NotificationHubsClient(connectionString, hubName);
|
|
462
454
|
|
|
463
455
|
const deviceHandle = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
|
|
464
456
|
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
|
|
@@ -485,9 +477,8 @@ if (result.notificationId) {
|
|
|
485
477
|
Using the modular approach, the code would be as follows:
|
|
486
478
|
|
|
487
479
|
```typescript
|
|
488
|
-
import { createClientContext } from "@azure/notification-hubs/
|
|
489
|
-
import { createAppleNotification } from "@azure/notification-hubs/models
|
|
490
|
-
import { sendNotification } from "@azure/notification-hubs/client/sendDirectNotification";
|
|
480
|
+
import { createClientContext, sendDirectNotification } from "@azure/notification-hubs/api";
|
|
481
|
+
import { createAppleNotification } from "@azure/notification-hubs/models";
|
|
491
482
|
|
|
492
483
|
const context = createClientContext(connectionString, hubName);
|
|
493
484
|
|
|
@@ -517,13 +508,31 @@ if (result.notificationId) {
|
|
|
517
508
|
|
|
518
509
|
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://docs.microsoft.com/azure/notification-hubs/notification-hubs-tags-segment-push-message).
|
|
519
510
|
|
|
511
|
+
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.
|
|
512
|
+
|
|
513
|
+
```typescript
|
|
514
|
+
// Top level import
|
|
515
|
+
import { createTagExpression } from "@azure/notification-hubs";
|
|
516
|
+
|
|
517
|
+
// Modular import
|
|
518
|
+
import { createTagExpression } from "@azure/notification-hubs/models";
|
|
519
|
+
|
|
520
|
+
const tags = ["likes_football", "likes_hockey"];
|
|
521
|
+
const tagExpression = createTagExpression(tags);
|
|
522
|
+
|
|
523
|
+
console.log(tagExpression);
|
|
524
|
+
// likes_football||likes_hockey
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
Tag expression messages can be sent using the following code:
|
|
528
|
+
|
|
520
529
|
```typescript
|
|
521
530
|
import {
|
|
522
|
-
|
|
531
|
+
NotificationHubsClient,
|
|
523
532
|
createAppleNotification,
|
|
524
533
|
} from "@azure/notification-hubs";
|
|
525
534
|
|
|
526
|
-
const client = new
|
|
535
|
+
const client = new NotificationHubsClient("<connection string>", "<hub name>");
|
|
527
536
|
|
|
528
537
|
const tagExpression = "likes_hockey && likes_football";
|
|
529
538
|
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
|
|
@@ -536,7 +545,7 @@ const notification = createAppleNotification({
|
|
|
536
545
|
},
|
|
537
546
|
});
|
|
538
547
|
|
|
539
|
-
const result = await client.sendNotification(notification, {
|
|
548
|
+
const result = await client.sendNotification(notification, { tagExpression });
|
|
540
549
|
|
|
541
550
|
console.log(`Tracking ID: ${result.trackingId}`);
|
|
542
551
|
console.log(`Correlation ID: ${result.correlationId}`);
|
|
@@ -550,9 +559,8 @@ if (result.notificationId) {
|
|
|
550
559
|
Using the modular approach, the code would be as follows:
|
|
551
560
|
|
|
552
561
|
```typescript
|
|
553
|
-
import { createClientContext } from "@azure/notification-hubs/
|
|
554
|
-
import { createAppleNotification } from "@azure/notification-hubs/models
|
|
555
|
-
import { sendNotification } from "@azure/notification-hubs/client/sendNotification";
|
|
562
|
+
import { createClientContext, sendNotification } from "@azure/notification-hubs/api";
|
|
563
|
+
import { createAppleNotification } from "@azure/notification-hubs/models";
|
|
556
564
|
|
|
557
565
|
const context = createClientContext("<connection string>", "<hub name>");
|
|
558
566
|
|
|
@@ -567,7 +575,7 @@ const notification = createAppleNotification({
|
|
|
567
575
|
},
|
|
568
576
|
});
|
|
569
577
|
|
|
570
|
-
const result = await sendNotification(context, notification, {
|
|
578
|
+
const result = await sendNotification(context, notification, { tagExpression });
|
|
571
579
|
|
|
572
580
|
console.log(`Tracking ID: ${result.trackingId}`);
|
|
573
581
|
console.log(`Correlation ID: ${result.correlationId}`);
|
|
@@ -584,11 +592,11 @@ Push notifications can be scheduled up to seven days in advance with Standard SK
|
|
|
584
592
|
|
|
585
593
|
```typescript
|
|
586
594
|
import {
|
|
587
|
-
|
|
595
|
+
NotificationHubsClient,
|
|
588
596
|
createAppleNotification,
|
|
589
597
|
} from "@azure/notification-hubs";
|
|
590
598
|
|
|
591
|
-
const client = new
|
|
599
|
+
const client = new NotificationHubsClient("<connection string>", "<hub name>");
|
|
592
600
|
|
|
593
601
|
const tagExpression = "likes_hockey && likes_football";
|
|
594
602
|
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
|
|
@@ -604,7 +612,7 @@ const message = createAppleNotification({
|
|
|
604
612
|
},
|
|
605
613
|
});
|
|
606
614
|
|
|
607
|
-
const result = await client.scheduleNotification(scheduledTime, message, {
|
|
615
|
+
const result = await client.scheduleNotification(scheduledTime, message, { tagExpression });
|
|
608
616
|
|
|
609
617
|
console.log(`Tracking ID: ${result.trackingId}`);
|
|
610
618
|
console.log(`Correlation ID: ${result.correlationId}`);
|
|
@@ -616,9 +624,8 @@ console.log(`Notification ID: ${result.notificationId}`);
|
|
|
616
624
|
Using the modular approach, the code would be as follows:
|
|
617
625
|
|
|
618
626
|
```typescript
|
|
619
|
-
import { createClientContext } from "@azure/notification-hubs/
|
|
620
|
-
import { createAppleNotification } from "@azure/notification-hubs/models
|
|
621
|
-
import { scheduleNotification } from "@azure/notification-hubs/client/scheduleNotification";
|
|
627
|
+
import { createClientContext, scheduleNotification } from "@azure/notification-hubs/api";
|
|
628
|
+
import { createAppleNotification } from "@azure/notification-hubs/models";
|
|
622
629
|
|
|
623
630
|
const context = createClientContext("<connection string>", "<hub name>");
|
|
624
631
|
|
|
@@ -636,7 +643,7 @@ const message = createAppleNotification({
|
|
|
636
643
|
},
|
|
637
644
|
});
|
|
638
645
|
|
|
639
|
-
const result = await scheduleNotification(context, scheduledTime, message, {
|
|
646
|
+
const result = await scheduleNotification(context, scheduledTime, message, { tagExpression });
|
|
640
647
|
|
|
641
648
|
console.log(`Tracking ID: ${result.trackingId}`);
|
|
642
649
|
console.log(`Correlation ID: ${result.correlationId}`);
|
|
@@ -655,7 +662,7 @@ Azure Notification Hubs has a complete guide to troubleshooting problems with dr
|
|
|
655
662
|
|
|
656
663
|
```typescript
|
|
657
664
|
// Using the client
|
|
658
|
-
const result = await client.sendNotification(
|
|
665
|
+
const result = await client.sendNotification(notification, { tags, enableTestSend: true });
|
|
659
666
|
|
|
660
667
|
// Using the modular approach
|
|
661
668
|
const result = await sendNotification(context, notification, { tags, enableTestSend: true });
|