@azure/notification-hubs 2.0.1-alpha.20250102.1 → 2.0.1-alpha.20250103.2

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.
Files changed (2) hide show
  1. package/README.md +82 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -57,11 +57,13 @@ This SDK for JavaScript offers two ways of interacting with Azure Notification H
57
57
  import { NotificationHubsClient, createAppleInstallation } from "@azure/notification-hubs";
58
58
 
59
59
  const client = new NotificationHubsClient("<connection string>", "<hub name>");
60
+
60
61
  const installation = createAppleInstallation({
61
62
  installationId: "<installation-id>",
62
63
  pushChannel: "<push-channel>",
63
64
  tags: ["likes_javascript"],
64
65
  });
66
+
65
67
  const result = await client.createOrUpdateInstallation(installation);
66
68
  ```
67
69
 
@@ -81,11 +83,13 @@ import { createClientContext, createOrUpdateInstallation } from "@azure/notifica
81
83
  import { createAppleInstallation } from "@azure/notification-hubs";
82
84
 
83
85
  const context = createClientContext("<connection string>", "<hub name>");
86
+
84
87
  const installation = createAppleInstallation({
85
88
  installationId: "<installation-id>",
86
89
  pushChannel: "<push-channel>",
87
90
  tags: ["likes_javascript"],
88
91
  });
92
+
89
93
  const result = await createOrUpdateInstallation(context, installation);
90
94
  ```
91
95
 
@@ -137,12 +141,14 @@ Installations can be created through the `createOrUpdateInstallation` method suc
137
141
  import { NotificationHubsClient, createAppleInstallation } from "@azure/notification-hubs";
138
142
 
139
143
  const client = new NotificationHubsClient("<connection string>", "<hub name>");
144
+
140
145
  // Create an installation for APNs
141
146
  const installation = createAppleInstallation({
142
147
  installationId: "0d8ab095-c449-493f-9195-17e4917806c4", // Must be unique
143
148
  pushChannel: "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0", // PNS specific handle
144
149
  tags: ["likes_hockey", "likes_football"],
145
150
  });
151
+
146
152
  const response = await client.createOrUpdateInstallation(installation);
147
153
  ```
148
154
 
@@ -153,12 +159,14 @@ import { createClientContext, createOrUpdateInstallation } from "@azure/notifica
153
159
  import { createAppleInstallation } from "@azure/notification-hubs";
154
160
 
155
161
  const context = createClientContext("<connection string>", "<hub name>");
162
+
156
163
  // Create an installation for APNs
157
164
  const installation = createAppleInstallation({
158
165
  installationId: "0d8ab095-c449-493f-9195-17e4917806c4", // Must be unique
159
166
  pushChannel: "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0", // PNS specific handle
160
167
  tags: ["likes_hockey", "likes_football"],
161
168
  });
169
+
162
170
  const response = await createOrUpdateInstallation(context, installation);
163
171
  ```
164
172
 
@@ -168,11 +176,13 @@ An update to an installation can be made through the JSON Patch schema such as a
168
176
  import { NotificationHubsClient, JsonPatch } from "@azure/notification-hubs";
169
177
 
170
178
  const client = new NotificationHubsClient("<connection string>", "<hub name>");
179
+
171
180
  const installationId = "<unique installation ID>";
172
181
  const updates: JsonPatch[] = [
173
182
  { op: "add", path: "/tags", value: "likes_baseball" },
174
183
  { op: "add", path: "/userId", value: "bob@contoso.com" },
175
184
  ];
185
+
176
186
  const installation = await client.updateInstallation(installationId, updates);
177
187
  ```
178
188
 
@@ -183,11 +193,14 @@ import { createClientContext, updateInstallation } from "@azure/notification-hub
183
193
  import { JsonPatch } from "@azure/notification-hubs";
184
194
 
185
195
  const context = createClientContext("<connection string>", "<hub name>");
196
+
186
197
  const installationId = "<unique installation ID>";
198
+
187
199
  const updates: JsonPatch[] = [
188
200
  { op: "add", path: "/tags", value: "likes_baseball" },
189
201
  { op: "add", path: "/userId", value: "bob@contoso.com" },
190
202
  ];
203
+
191
204
  const installation = await updateInstallation(context, installationId, updates);
192
205
  ```
193
206
 
@@ -197,7 +210,9 @@ To retrieve an existing installation, use the `getInstallation` method with your
197
210
  import { NotificationHubsClient } from "@azure/notification-hubs";
198
211
 
199
212
  const client = new NotificationHubsClient("<connection string>", "<hub name>");
213
+
200
214
  const installationId = "<unique installation ID>";
215
+
201
216
  const installation = client.getInstallation(installationId);
202
217
  ```
203
218
 
@@ -207,7 +222,9 @@ Using the modular approach, the code would be as follows:
207
222
  import { createClientContext, getInstallation } from "@azure/notification-hubs/api";
208
223
 
209
224
  const context = createClientContext("<connection string>", "<hub name>");
225
+
210
226
  const installationId = "<unique installation ID>";
227
+
211
228
  const installation = getInstallation(context, installationId);
212
229
  ```
213
230
 
@@ -224,6 +241,7 @@ import {
224
241
  } from "@azure/notification-hubs";
225
242
 
226
243
  const client = new NotificationHubsClient("<connection string>", "<hub name>");
244
+
227
245
  const registration = createAppleRegistrationDescription({
228
246
  deviceToken: "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0",
229
247
  tags: ["likes_hockey", "likes_football"],
@@ -238,10 +256,12 @@ import { createClientContext, createRegistration } from "@azure/notification-hub
238
256
  import { createAppleRegistrationDescription } from "@azure/notification-hubs";
239
257
 
240
258
  const context = createClientContext("<connection string>", "<hub name>");
259
+
241
260
  const registration = createAppleRegistrationDescription({
242
261
  deviceToken: "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0",
243
262
  tags: ["likes_hockey", "likes_football"],
244
263
  });
264
+
245
265
  const updatedRegistration = await createRegistration(context, registration);
246
266
  ```
247
267
 
@@ -251,13 +271,17 @@ Updates can be done via the `updateRegistration` method but unlike installations
251
271
  import { NotificationHubsClient } from "@azure/notification-hubs";
252
272
 
253
273
  const client = new NotificationHubsClient("<connection string>", "<hub name>");
274
+
254
275
  const registrationId = "<unique Registration ID>";
276
+
255
277
  const registration = await client.getRegistration(registrationId);
278
+
256
279
  if (registration.tags) {
257
280
  registration.tags.push("likes_sports");
258
281
  } else {
259
282
  registration.tags = ["likes_sports"];
260
283
  }
284
+
261
285
  const updatedRegistration = await client.updateRegistration(registration);
262
286
  ```
263
287
 
@@ -271,13 +295,17 @@ import {
271
295
  } from "@azure/notification-hubs/api";
272
296
 
273
297
  const context = createClientContext("<connection string>", "<hub name>");
298
+
274
299
  const registrationId = "<unique Registration ID>";
300
+
275
301
  const registration = await getRegistration(context, registrationId);
302
+
276
303
  if (registration.tags) {
277
304
  registration.tags.push("likes_sports");
278
305
  } else {
279
306
  registration.tags = ["likes_sports"];
280
307
  }
308
+
281
309
  const updatedRegistration = await updateRegistration(context, registration);
282
310
  ```
283
311
 
@@ -287,7 +315,9 @@ Registrations, unlike installations, can be queried to get all registrations, ma
287
315
  import { NotificationHubsClient } from "@azure/notification-hubs";
288
316
 
289
317
  const client = new NotificationHubsClient("<connection string>", "<hub name>");
318
+
290
319
  const registrations = client.listRegistrationsByTag("likes_hockey");
320
+
291
321
  let page = 0;
292
322
  for await (const pages of registrations.byPage()) {
293
323
  console.log(`Page number ${page++}`);
@@ -303,7 +333,9 @@ Using the modular approach, the code would be as follows:
303
333
  import { createClientContext, listRegistrationsByTag } from "@azure/notification-hubs/api";
304
334
 
305
335
  const context = createClientContext("<connection string>", "<hub name>");
336
+
306
337
  const registrations = await listRegistrationsByTag(context, "likes_hockey");
338
+
307
339
  let page = 0;
308
340
  for await (const pages of registrations.byPage()) {
309
341
  console.log(`Page number ${page++}`);
@@ -333,6 +365,7 @@ const apnsBody = createAppleNotificationBody({
333
365
  sound: "default",
334
366
  interruptionLevel: "time-sensitive",
335
367
  });
368
+
336
369
  // Send the message using the modular approach
337
370
  const notification = createAppleNotification({
338
371
  body: apnsBody,
@@ -347,7 +380,9 @@ Notification Hubs can be used to send notifications to all registered devices pe
347
380
  import { NotificationHubsClient, createAppleNotification } from "@azure/notification-hubs";
348
381
 
349
382
  const client = new NotificationHubsClient("<connection string>", "<hub name>");
383
+
350
384
  const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
385
+
351
386
  const message = createAppleNotification({
352
387
  body: messageBody,
353
388
  headers: {
@@ -355,9 +390,12 @@ const message = createAppleNotification({
355
390
  "apns-push-type": "alert",
356
391
  },
357
392
  });
393
+
358
394
  const result = await client.sendBroadcastNotification(message);
395
+
359
396
  console.log(`Tracking ID: ${result.trackingId}`);
360
397
  console.log(`Correlation ID: ${result.correlationId}`);
398
+
361
399
  // Only available in Standard SKU and above
362
400
  if (result.notificationId) {
363
401
  console.log(`Notification ID: ${result.notificationId}`);
@@ -371,7 +409,9 @@ import { createClientContext, sendBroadcastNotification } from "@azure/notificat
371
409
  import { createAppleNotification } from "@azure/notification-hubs";
372
410
 
373
411
  const context = createClientContext("<connection string>", "<hub name>");
412
+
374
413
  const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
414
+
375
415
  const message = createAppleNotification({
376
416
  body: messageBody,
377
417
  headers: {
@@ -379,9 +419,12 @@ const message = createAppleNotification({
379
419
  "apns-push-type": "alert",
380
420
  },
381
421
  });
422
+
382
423
  const result = await sendBroadcastNotification(context, message);
424
+
383
425
  console.log(`Tracking ID: ${result.trackingId}`);
384
426
  console.log(`Correlation ID: ${result.correlationId}`);
427
+
385
428
  // Only available in Standard SKU and above
386
429
  if (result.notificationId) {
387
430
  console.log(`Notification ID: ${result.notificationId}`);
@@ -396,8 +439,10 @@ To send directly a device, the user can send using the platform provided unique
396
439
  import { NotificationHubsClient, createAppleNotification } from "@azure/notification-hubs";
397
440
 
398
441
  const client = new NotificationHubsClient("<connection string>", "<hub name>");
442
+
399
443
  const deviceHandle = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
400
444
  const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
445
+
401
446
  const message = createAppleNotification({
402
447
  body: messageBody,
403
448
  headers: {
@@ -405,9 +450,12 @@ const message = createAppleNotification({
405
450
  "apns-push-type": "alert",
406
451
  },
407
452
  });
453
+
408
454
  const result = await client.sendNotification(message, { deviceHandle });
455
+
409
456
  console.log(`Tracking ID: ${result.trackingId}`);
410
457
  console.log(`Correlation ID: ${result.correlationId}`);
458
+
411
459
  // Only available in Standard SKU and above
412
460
  if (result.notificationId) {
413
461
  console.log(`Notification ID: ${result.notificationId}`);
@@ -421,8 +469,10 @@ import { createClientContext, sendNotification } from "@azure/notification-hubs/
421
469
  import { createAppleNotification } from "@azure/notification-hubs";
422
470
 
423
471
  const context = createClientContext("<connection string>", "<hub name>");
472
+
424
473
  const deviceHandle = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
425
474
  const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
475
+
426
476
  const message = createAppleNotification({
427
477
  body: messageBody,
428
478
  headers: {
@@ -430,9 +480,12 @@ const message = createAppleNotification({
430
480
  "apns-push-type": "alert",
431
481
  },
432
482
  });
483
+
433
484
  const result = await sendNotification(context, message, { deviceHandle });
485
+
434
486
  console.log(`Tracking ID: ${result.trackingId}`);
435
487
  console.log(`Correlation ID: ${result.correlationId}`);
488
+
436
489
  // Only available in Standard SKU and above
437
490
  if (result.notificationId) {
438
491
  console.log(`Notification ID: ${result.notificationId}`);
@@ -450,6 +503,7 @@ import { createTagExpression } from "@azure/notification-hubs";
450
503
 
451
504
  const tags = ["likes_football", "likes_hockey"];
452
505
  const tagExpression = createTagExpression(tags);
506
+
453
507
  console.log(tagExpression);
454
508
  ```
455
509
 
@@ -459,8 +513,10 @@ Tag expression messages can be sent using the following code:
459
513
  import { NotificationHubsClient, createAppleNotification } from "@azure/notification-hubs";
460
514
 
461
515
  const client = new NotificationHubsClient("<connection string>", "<hub name>");
516
+
462
517
  const tagExpression = "likes_hockey && likes_football";
463
518
  const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
519
+
464
520
  const notification = createAppleNotification({
465
521
  body: messageBody,
466
522
  headers: {
@@ -468,9 +524,12 @@ const notification = createAppleNotification({
468
524
  "apns-push-type": "alert",
469
525
  },
470
526
  });
527
+
471
528
  const result = await client.sendNotification(notification, { tagExpression });
529
+
472
530
  console.log(`Tracking ID: ${result.trackingId}`);
473
531
  console.log(`Correlation ID: ${result.correlationId}`);
532
+
474
533
  // Only available in Standard SKU and above
475
534
  if (result.notificationId) {
476
535
  console.log(`Notification ID: ${result.notificationId}`);
@@ -484,8 +543,10 @@ import { createClientContext, sendNotification } from "@azure/notification-hubs/
484
543
  import { createAppleNotification } from "@azure/notification-hubs";
485
544
 
486
545
  const context = createClientContext("<connection string>", "<hub name>");
546
+
487
547
  const tagExpression = "likes_hockey && likes_football";
488
548
  const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
549
+
489
550
  const notification = createAppleNotification({
490
551
  body: messageBody,
491
552
  headers: {
@@ -493,9 +554,12 @@ const notification = createAppleNotification({
493
554
  "apns-push-type": "alert",
494
555
  },
495
556
  });
557
+
496
558
  const result = await sendNotification(context, notification, { tagExpression });
559
+
497
560
  console.log(`Tracking ID: ${result.trackingId}`);
498
561
  console.log(`Correlation ID: ${result.correlationId}`);
562
+
499
563
  // Only available in Standard SKU and above
500
564
  if (result.notificationId) {
501
565
  console.log(`Notification ID: ${result.notificationId}`);
@@ -510,10 +574,13 @@ Push notifications can be scheduled up to seven days in advance with Standard SK
510
574
  import { NotificationHubsClient, createAppleNotification } from "@azure/notification-hubs";
511
575
 
512
576
  const client = new NotificationHubsClient("<connection string>", "<hub name>");
577
+
513
578
  const tagExpression = "likes_hockey && likes_football";
514
579
  const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
580
+
515
581
  // Schedule 8 hours from now
516
582
  const scheduledTime = new Date(Date.now() + 8 * 60 * 60 * 1000);
583
+
517
584
  const message = createAppleNotification({
518
585
  body: messageBody,
519
586
  headers: {
@@ -521,9 +588,12 @@ const message = createAppleNotification({
521
588
  "apns-push-type": "alert",
522
589
  },
523
590
  });
591
+
524
592
  const result = await client.scheduleNotification(scheduledTime, message, { tagExpression });
593
+
525
594
  console.log(`Tracking ID: ${result.trackingId}`);
526
595
  console.log(`Correlation ID: ${result.correlationId}`);
596
+
527
597
  // Can be used to cancel via the cancelScheduledSend method
528
598
  console.log(`Notification ID: ${result.notificationId}`);
529
599
  ```
@@ -535,10 +605,13 @@ import { createClientContext, scheduleNotification } from "@azure/notification-h
535
605
  import { createAppleNotification } from "@azure/notification-hubs";
536
606
 
537
607
  const context = createClientContext("<connection string>", "<hub name>");
608
+
538
609
  const tagExpression = "likes_hockey && likes_football";
539
610
  const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
611
+
540
612
  // Schedule 8 hours from now
541
613
  const scheduledTime = new Date(Date.now() + 8 * 60 * 60 * 1000);
614
+
542
615
  const message = createAppleNotification({
543
616
  body: messageBody,
544
617
  headers: {
@@ -546,9 +619,12 @@ const message = createAppleNotification({
546
619
  "apns-push-type": "alert",
547
620
  },
548
621
  });
622
+
549
623
  const result = await scheduleNotification(context, scheduledTime, message, { tagExpression });
624
+
550
625
  console.log(`Tracking ID: ${result.trackingId}`);
551
626
  console.log(`Correlation ID: ${result.correlationId}`);
627
+
552
628
  // Can be used to cancel via the cancelScheduledSend method
553
629
  console.log(`Notification ID: ${result.notificationId}`);
554
630
  ```
@@ -571,8 +647,10 @@ Azure Notification Hubs has a complete guide to troubleshooting problems with dr
571
647
  import { NotificationHubsClient, createAppleNotification } from "@azure/notification-hubs";
572
648
 
573
649
  const client = new NotificationHubsClient("<connection string>", "<hub name>");
650
+
574
651
  const tagExpression = "likes_hockey && likes_football";
575
652
  const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
653
+
576
654
  const notification = createAppleNotification({
577
655
  body: messageBody,
578
656
  headers: {
@@ -580,6 +658,7 @@ const notification = createAppleNotification({
580
658
  "apns-push-type": "alert",
581
659
  },
582
660
  });
661
+
583
662
  const result = await client.sendNotification(notification, {
584
663
  tagExpression,
585
664
  enableTestSend: true,
@@ -591,8 +670,10 @@ import { createClientContext, sendNotification } from "@azure/notification-hubs/
591
670
  import { createAppleNotification } from "@azure/notification-hubs";
592
671
 
593
672
  const context = createClientContext("<connection string>", "<hub name>");
673
+
594
674
  const tagExpression = "likes_hockey && likes_football";
595
675
  const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
676
+
596
677
  const notification = createAppleNotification({
597
678
  body: messageBody,
598
679
  headers: {
@@ -600,6 +681,7 @@ const notification = createAppleNotification({
600
681
  "apns-push-type": "alert",
601
682
  },
602
683
  });
684
+
603
685
  const result = await sendNotification(context, notification, {
604
686
  tagExpression,
605
687
  enableTestSend: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure/notification-hubs",
3
- "version": "2.0.1-alpha.20250102.1",
3
+ "version": "2.0.1-alpha.20250103.2",
4
4
  "description": "Azure Notification Hubs SDK for JavaScript",
5
5
  "sdk-type": "client",
6
6
  "main": "./dist/commonjs/index.js",