@azure/notification-hubs 1.0.0-beta.5 → 1.0.0-beta.6

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 (103) hide show
  1. package/README.md +28 -44
  2. package/dist/index.cjs +390 -310
  3. package/dist/index.cjs.map +1 -1
  4. package/dist-esm/src/client/beginSubmitNotificationHubJob.js +131 -0
  5. package/dist-esm/src/client/beginSubmitNotificationHubJob.js.map +1 -0
  6. package/dist-esm/src/client/cancelScheduledNotification.js +1 -1
  7. package/dist-esm/src/client/cancelScheduledNotification.js.map +1 -1
  8. package/dist-esm/src/client/createOrUpdateInstallation.js +1 -1
  9. package/dist-esm/src/client/createOrUpdateInstallation.js.map +1 -1
  10. package/dist-esm/src/client/createOrUpdateRegistration.js +1 -1
  11. package/dist-esm/src/client/createOrUpdateRegistration.js.map +1 -1
  12. package/dist-esm/src/client/createRegistration.js +1 -1
  13. package/dist-esm/src/client/createRegistration.js.map +1 -1
  14. package/dist-esm/src/client/createRegistrationId.js +1 -1
  15. package/dist-esm/src/client/createRegistrationId.js.map +1 -1
  16. package/dist-esm/src/client/deleteInstallation.js +1 -1
  17. package/dist-esm/src/client/deleteInstallation.js.map +1 -1
  18. package/dist-esm/src/client/deleteRegistration.js +1 -1
  19. package/dist-esm/src/client/deleteRegistration.js.map +1 -1
  20. package/dist-esm/src/client/getFeedbackContainerUrl.js +1 -1
  21. package/dist-esm/src/client/getFeedbackContainerUrl.js.map +1 -1
  22. package/dist-esm/src/client/getInstallation.js +1 -1
  23. package/dist-esm/src/client/getInstallation.js.map +1 -1
  24. package/dist-esm/src/client/getNotificationHubJob.js +1 -1
  25. package/dist-esm/src/client/getNotificationHubJob.js.map +1 -1
  26. package/dist-esm/src/client/getNotificationOutcomeDetails.js +1 -1
  27. package/dist-esm/src/client/getNotificationOutcomeDetails.js.map +1 -1
  28. package/dist-esm/src/client/getRegistration.js +1 -1
  29. package/dist-esm/src/client/getRegistration.js.map +1 -1
  30. package/dist-esm/src/client/index.js +2 -2
  31. package/dist-esm/src/client/index.js.map +1 -1
  32. package/dist-esm/src/client/listNotificationHubJobs.js +1 -1
  33. package/dist-esm/src/client/listNotificationHubJobs.js.map +1 -1
  34. package/dist-esm/src/client/listRegistrations.js +1 -1
  35. package/dist-esm/src/client/listRegistrations.js.map +1 -1
  36. package/dist-esm/src/client/listRegistrationsByTag.js +1 -1
  37. package/dist-esm/src/client/listRegistrationsByTag.js.map +1 -1
  38. package/dist-esm/src/client/scheduleNotification.js +20 -6
  39. package/dist-esm/src/client/scheduleNotification.js.map +1 -1
  40. package/dist-esm/src/client/sendNotification.js +53 -6
  41. package/dist-esm/src/client/sendNotification.js.map +1 -1
  42. package/dist-esm/src/client/submitNotificationHubJob.js +1 -1
  43. package/dist-esm/src/client/submitNotificationHubJob.js.map +1 -1
  44. package/dist-esm/src/client/updateInstallation.js +1 -1
  45. package/dist-esm/src/client/updateInstallation.js.map +1 -1
  46. package/dist-esm/src/client/updateRegistration.js +1 -1
  47. package/dist-esm/src/client/updateRegistration.js.map +1 -1
  48. package/dist-esm/src/models/notificationHubJob.js.map +1 -1
  49. package/dist-esm/src/models/options.js.map +1 -1
  50. package/dist-esm/src/notificationHubsClient.js +16 -45
  51. package/dist-esm/src/notificationHubsClient.js.map +1 -1
  52. package/dist-esm/src/serializers/notificationDetailsSerializer.js +2 -1
  53. package/dist-esm/src/serializers/notificationDetailsSerializer.js.map +1 -1
  54. package/dist-esm/src/serializers/notificationHubJobSerializer.js +3 -1
  55. package/dist-esm/src/serializers/notificationHubJobSerializer.js.map +1 -1
  56. package/dist-esm/src/utils/constants.js +1 -1
  57. package/dist-esm/src/utils/constants.js.map +1 -1
  58. package/dist-esm/src/utils/notificationUtils.js +25 -0
  59. package/dist-esm/src/utils/notificationUtils.js.map +1 -0
  60. package/dist-esm/src/utils/optionUtils.js +20 -0
  61. package/dist-esm/src/utils/optionUtils.js.map +1 -0
  62. package/package.json +6 -5
  63. package/types/3.1/notification-hubs.d.ts +52 -36
  64. package/types/latest/notification-hubs.d.ts +56 -36
  65. package/types/latest/tsdoc-metadata.json +1 -1
  66. package/types/src/client/beginSubmitNotificationHubJob.d.ts +12 -0
  67. package/types/src/client/beginSubmitNotificationHubJob.d.ts.map +1 -0
  68. package/types/src/client/index.d.ts +1 -1
  69. package/types/src/client/index.d.ts.map +1 -1
  70. package/types/src/client/scheduleNotification.d.ts +3 -5
  71. package/types/src/client/scheduleNotification.d.ts.map +1 -1
  72. package/types/src/client/sendNotification.d.ts +3 -5
  73. package/types/src/client/sendNotification.d.ts.map +1 -1
  74. package/types/src/models/notificationHubJob.d.ts +5 -0
  75. package/types/src/models/notificationHubJob.d.ts.map +1 -1
  76. package/types/src/models/options.d.ts +36 -2
  77. package/types/src/models/options.d.ts.map +1 -1
  78. package/types/src/notificationHubsClient.d.ts +14 -37
  79. package/types/src/notificationHubsClient.d.ts.map +1 -1
  80. package/types/src/utils/notificationUtils.d.ts +10 -0
  81. package/types/src/utils/notificationUtils.d.ts.map +1 -0
  82. package/types/src/utils/optionUtils.d.ts +14 -0
  83. package/types/src/utils/optionUtils.d.ts.map +1 -0
  84. package/dist-esm/src/client/internal/_scheduleNotificationPayload.js +0 -38
  85. package/dist-esm/src/client/internal/_scheduleNotificationPayload.js.map +0 -1
  86. package/dist-esm/src/client/internal/_sendNotificationPayload.js +0 -51
  87. package/dist-esm/src/client/internal/_sendNotificationPayload.js.map +0 -1
  88. package/dist-esm/src/client/scheduleBroadcastNotification.js +0 -17
  89. package/dist-esm/src/client/scheduleBroadcastNotification.js.map +0 -1
  90. package/dist-esm/src/client/sendBroadcastNotification.js +0 -15
  91. package/dist-esm/src/client/sendBroadcastNotification.js.map +0 -1
  92. package/dist-esm/src/client/sendDirectNotification.js +0 -15
  93. package/dist-esm/src/client/sendDirectNotification.js.map +0 -1
  94. package/types/src/client/internal/_scheduleNotificationPayload.d.ts +0 -9
  95. package/types/src/client/internal/_scheduleNotificationPayload.d.ts.map +0 -1
  96. package/types/src/client/internal/_sendNotificationPayload.d.ts +0 -10
  97. package/types/src/client/internal/_sendNotificationPayload.d.ts.map +0 -1
  98. package/types/src/client/scheduleBroadcastNotification.d.ts +0 -16
  99. package/types/src/client/scheduleBroadcastNotification.d.ts.map +0 -1
  100. package/types/src/client/sendBroadcastNotification.d.ts +0 -14
  101. package/types/src/client/sendBroadcastNotification.d.ts.map +0 -1
  102. package/types/src/client/sendDirectNotification.d.ts +0 -15
  103. package/types/src/client/sendDirectNotification.d.ts.map +0 -1
package/README.md CHANGED
@@ -20,7 +20,7 @@ Key links:
20
20
 
21
21
  ### Currently supported environments
22
22
 
23
- - [LTS versions of Node.js](https://nodejs.org/about/releases/)
23
+ - [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
24
24
  - Latest versions of Safari, Chrome, Edge, and Firefox.
25
25
 
26
26
  See our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.
@@ -359,7 +359,7 @@ for await (const pages of registrations.byPage()) {
359
359
 
360
360
  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://docs.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.
361
361
 
362
- For debugging purposes, the `enableTestSend` options can be set to `true` which gets immediate feedback from the PNS on the `sendNotification` or `sendBroadcastNotification` methods, however, is not supported in production scenarios. This is not supported on the scheduled send methods.
362
+ 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
363
 
364
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 and fill in associated HTTP headers so there is no guessing about which fields are available for each PNS.
365
365
 
@@ -370,7 +370,6 @@ import { buildAppleNativeMessage } from "@azure/notification-hubs";
370
370
  // Using the modular approach
371
371
  import { buildAppleNativeMessage } from "@azure/notification-hubs/models/notificationBuilder";
372
372
 
373
-
374
373
  const apnsMessage = buildAppleNativeMessage({
375
374
  alert: {
376
375
  title: "Notification Title",
@@ -383,17 +382,16 @@ const apnsMessage = buildAppleNativeMessage({
383
382
 
384
383
  // Send the message using the modular approach
385
384
 
386
- const result = await sendBroadcastNotification(context, apnsMessage);
385
+ const result = await sendNotification(context, apnsMessage);
387
386
  ```
388
387
 
389
388
  #### Broadcast Send
390
389
 
391
- Notification Hubs can be used to send notifications to all registered devices per platform using broadcast send through the `sendBroadcastNotification` method.
390
+ Notification Hubs can be used to send notifications to all registered devices per platform using broadcast send through the `sendNotification` method.
392
391
 
393
392
  ```typescript
394
393
  import {
395
394
  NotificationHubServiceClient,
396
- SendOperationOptions,
397
395
  createAppleNotification,
398
396
  } from "@azure/notification-hubs/client";
399
397
 
@@ -409,9 +407,7 @@ const message = createAppleNotification({
409
407
  },
410
408
  });
411
409
 
412
- // Not required but can set test send to true for debugging purposes.
413
- const sendOptions: SendOperationOptions = { enableTestSend: false };
414
- const result = await client.sendBroadcastNotification(message, sendOptions);
410
+ const result = await client.sendNotification(message);
415
411
 
416
412
  console.log(`Tracking ID: ${result.trackingId}`);
417
413
  console.log(`Correlation ID: ${result.correlationId}`);
@@ -425,10 +421,9 @@ if (result.notificationId) {
425
421
  Using the modular approach, the code would be as follows:
426
422
 
427
423
  ```typescript
428
- import { SendOperationOptions } from "@azure/notification-hubs/models/options";
429
424
  import { createClientContext } from "@azure/notification-hubs/client";
430
425
  import { createAppleNotification } from "@azure/notification-hubs/models/notification";
431
- import { sendBroadcastNotification } from "@azure/notification-hubs/client/sendBroadcastNotification";
426
+ import { sendNotification } from "@azure/notification-hubs/client/sendNotification";
432
427
 
433
428
  const context = createClientContext(connectionString, hubName);
434
429
 
@@ -442,9 +437,7 @@ const message = createAppleNotification({
442
437
  },
443
438
  });
444
439
 
445
- // Not required but can set test send to true for debugging purposes.
446
- const sendOptions: SendOperationOptions = { enableTestSend: false };
447
- const result = await sendBroadcastNotification(context, message, sendOptions);
440
+ const result = await sendNotification(context, message);
448
441
 
449
442
  console.log(`Tracking ID: ${result.trackingId}`);
450
443
  console.log(`Correlation ID: ${result.correlationId}`);
@@ -457,18 +450,17 @@ if (result.notificationId) {
457
450
 
458
451
  #### Direct Send
459
452
 
460
- To send directly a device, the user can send using the platform provided unique identifier such as APNs device token by calling the `sendDirectNotification` method.
453
+ To send directly a device, the user can send using the platform provided unique identifier such as APNs device token by calling the `sendNotification` method with a `deviceHandle` parameter.
461
454
 
462
455
  ```typescript
463
456
  import {
464
457
  NotificationHubServiceClient,
465
- SendOperationOptions,
466
458
  createAppleNotification,
467
459
  } from "@azure/notification-hubs";
468
460
 
469
461
  const client = new NotificationHubServiceClient(connectionString, hubName);
470
462
 
471
- const deviceToken = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
463
+ const deviceHandle = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
472
464
  const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
473
465
 
474
466
  const message = createAppleNotification({
@@ -479,7 +471,7 @@ const message = createAppleNotification({
479
471
  },
480
472
  });
481
473
 
482
- const result = await client.sendDirectNotification(devicetoken, message);
474
+ const result = await client.sendNotification(message, { deviceHandle });
483
475
 
484
476
  console.log(`Tracking ID: ${result.trackingId}`);
485
477
  console.log(`Correlation ID: ${result.correlationId}`);
@@ -493,14 +485,13 @@ if (result.notificationId) {
493
485
  Using the modular approach, the code would be as follows:
494
486
 
495
487
  ```typescript
496
- import { SendOperationOptions } from "@azure/notification-hubs/models/options";
497
488
  import { createClientContext } from "@azure/notification-hubs/client";
498
489
  import { createAppleNotification } from "@azure/notification-hubs/models/notification";
499
- import { sendDirectNotification } from "@azure/notification-hubs/client/sendDirectNotification";
490
+ import { sendNotification } from "@azure/notification-hubs/client/sendDirectNotification";
500
491
 
501
492
  const context = createClientContext(connectionString, hubName);
502
493
 
503
- const deviceToken = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
494
+ const deviceHandle = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
504
495
  const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
505
496
 
506
497
  const message = createAppleNotification({
@@ -511,7 +502,7 @@ const message = createAppleNotification({
511
502
  },
512
503
  });
513
504
 
514
- const result = await sendDirectNotification(context, devicetoken, message, sendOptions);
505
+ const result = await sendNotification(context, message, { deviceHandle });
515
506
 
516
507
  console.log(`Tracking ID: ${result.trackingId}`);
517
508
  console.log(`Correlation ID: ${result.correlationId}`);
@@ -529,8 +520,7 @@ In addition to targeting a single device, a user can target multiple devices usi
529
520
  ```typescript
530
521
  import {
531
522
  NotificationHubServiceClient,
532
- SendOperationOptions,
533
- createAppleMessage,
523
+ createAppleNotification,
534
524
  } from "@azure/notification-hubs";
535
525
 
536
526
  const client = new NotificationHubServiceClient("<connection string>", "<hub name>");
@@ -538,7 +528,7 @@ const client = new NotificationHubServiceClient("<connection string>", "<hub nam
538
528
  const tagExpression = "likes_hockey && likes_football";
539
529
  const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
540
530
 
541
- const message = createAppleMessage({
531
+ const notification = createAppleNotification({
542
532
  body: messageBody,
543
533
  headers: {
544
534
  "apns-priority": "10",
@@ -546,10 +536,7 @@ const message = createAppleMessage({
546
536
  },
547
537
  });
548
538
 
549
-
550
- // Not required but can set test send to true for debugging purposes.
551
- const sendOptions: SendOperationOptions = { enableTestSend: false };
552
- const result = await client.sendNotification(tagExpression, message, sendOptions);
539
+ const result = await client.sendNotification(notification, { tags: tagExpression });
553
540
 
554
541
  console.log(`Tracking ID: ${result.trackingId}`);
555
542
  console.log(`Correlation ID: ${result.correlationId}`);
@@ -563,7 +550,6 @@ if (result.notificationId) {
563
550
  Using the modular approach, the code would be as follows:
564
551
 
565
552
  ```typescript
566
- import { SendOperationOptions } from "@azure/notification-hubs/models/options";
567
553
  import { createClientContext } from "@azure/notification-hubs/client";
568
554
  import { createAppleNotification } from "@azure/notification-hubs/models/notification";
569
555
  import { sendNotification } from "@azure/notification-hubs/client/sendNotification";
@@ -573,7 +559,7 @@ const context = createClientContext("<connection string>", "<hub name>");
573
559
  const tagExpression = "likes_hockey && likes_football";
574
560
  const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
575
561
 
576
- const message = createAppleMessage({
562
+ const notification = createAppleNotification({
577
563
  body: messageBody,
578
564
  headers: {
579
565
  "apns-priority": "10",
@@ -581,10 +567,7 @@ const message = createAppleMessage({
581
567
  },
582
568
  });
583
569
 
584
-
585
- // Not required but can set test send to true for debugging purposes.
586
- const sendOptions: SendOperationOptions = { enableTestSend: false };
587
- const result = await sendNotification(context, tagExpression, message, sendOptions);
570
+ const result = await sendNotification(context, notification, { tags: tagExpression });
588
571
 
589
572
  console.log(`Tracking ID: ${result.trackingId}`);
590
573
  console.log(`Correlation ID: ${result.correlationId}`);
@@ -597,12 +580,11 @@ if (result.notificationId) {
597
580
 
598
581
  #### Scheduled Send
599
582
 
600
- Push notifications can be scheduled up to seven days in advance with Standard SKU namespaces and above using the `scheduleBroadcastNotification` method to send to devices with tags or a general broadcast with the `scheduleBroadcastNotification`. This returns a notification ID which can be then used to cancel if necessary via the `cancelScheduledNotification` method.
583
+ Push notifications can be scheduled up to seven days in advance with Standard SKU namespaces and above using the `scheduleBroadcastNotification` method to send to devices with tags or a general broadcast. This returns a notification ID which can be then used to cancel if necessary via the `cancelScheduledNotification` method.
601
584
 
602
585
  ```typescript
603
586
  import {
604
587
  NotificationHubServiceClient,
605
- SendOperationOptions,
606
588
  createAppleNotification,
607
589
  } from "@azure/notification-hubs";
608
590
 
@@ -611,7 +593,7 @@ const client = new NotificationHubServiceClient("<connection string>", "<hub nam
611
593
  const tagExpression = "likes_hockey && likes_football";
612
594
  const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
613
595
 
614
- // Schedule 8 hours from nows
596
+ // Schedule 8 hours from now
615
597
  const scheduledTime = new Date(Date.now() + (8 * 60 * 60 * 1000));
616
598
 
617
599
  const message = createAppleNotification({
@@ -622,7 +604,7 @@ const message = createAppleNotification({
622
604
  },
623
605
  });
624
606
 
625
- const result = await client.scheduleNotification(scheduledTime, tagExpression, message);
607
+ const result = await client.scheduleNotification(scheduledTime, message, { tags: tagExpression });
626
608
 
627
609
  console.log(`Tracking ID: ${result.trackingId}`);
628
610
  console.log(`Correlation ID: ${result.correlationId}`);
@@ -634,7 +616,6 @@ console.log(`Notification ID: ${result.notificationId}`);
634
616
  Using the modular approach, the code would be as follows:
635
617
 
636
618
  ```typescript
637
- import { SendOperationOptions } from "@azure/notification-hubs/models/options";
638
619
  import { createClientContext } from "@azure/notification-hubs/client";
639
620
  import { createAppleNotification } from "@azure/notification-hubs/models/notification";
640
621
  import { scheduleNotification } from "@azure/notification-hubs/client/scheduleNotification";
@@ -644,7 +625,7 @@ const context = createClientContext("<connection string>", "<hub name>");
644
625
  const tagExpression = "likes_hockey && likes_football";
645
626
  const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
646
627
 
647
- // Schedule 8 hours from nows
628
+ // Schedule 8 hours from now
648
629
  const scheduledTime = new Date(Date.now() + (8 * 60 * 60 * 1000));
649
630
 
650
631
  const message = createAppleNotification({
@@ -655,7 +636,7 @@ const message = createAppleNotification({
655
636
  },
656
637
  });
657
638
 
658
- const result = await scheduleNotification(context, scheduledTime, tagExpression, message);
639
+ const result = await scheduleNotification(context, scheduledTime, message, { tags: tagExpression });
659
640
 
660
641
  console.log(`Tracking ID: ${result.trackingId}`);
661
642
  console.log(`Correlation ID: ${result.correlationId}`);
@@ -673,8 +654,11 @@ Azure Notification Hubs has a complete guide to troubleshooting problems with dr
673
654
  [Test send](https://docs.microsoft.com/azure/notification-hubs/notification-hubs-push-notification-fixer#enabletestsend-property) is supported supported in the `sendNotification` method with the `enableTestSend` option:
674
655
 
675
656
  ```typescript
676
- const sendOptions: SendOperationOptions = { enableTestSend: true };
677
- const result = await client.sendNotification(tags, message, sendOptions);
657
+ // Using the client
658
+ const result = await client.sendNotification(message, { tags, enableTestSend: true });
659
+
660
+ // Using the modular approach
661
+ const result = await sendNotification(context, notification, { tags, enableTestSend: true });
678
662
  ```
679
663
 
680
664
  ### Logging