@azure/notification-hubs 1.0.0-alpha.20220906.2 → 1.0.0-alpha.20220916.4

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 (98) hide show
  1. package/README.md +15 -20
  2. package/dist/index.cjs +125 -136
  3. package/dist/index.cjs.map +1 -1
  4. package/dist-esm/src/auth/hmacSha256.browser.js +1 -0
  5. package/dist-esm/src/auth/hmacSha256.browser.js.map +1 -1
  6. package/dist-esm/src/auth/sasTokenProvider.js +2 -23
  7. package/dist-esm/src/auth/sasTokenProvider.js.map +1 -1
  8. package/dist-esm/src/client/cancelScheduledNotification.js.map +1 -1
  9. package/dist-esm/src/client/createOrUpdateInstallation.js.map +1 -1
  10. package/dist-esm/src/client/deleteInstallation.js.map +1 -1
  11. package/dist-esm/src/client/deleteRegistration.js.map +1 -1
  12. package/dist-esm/src/client/internal/_client.js +23 -7
  13. package/dist-esm/src/client/internal/_client.js.map +1 -1
  14. package/dist-esm/src/client/internal/_scheduleNotificationPayload.js.map +1 -1
  15. package/dist-esm/src/client/internal/_sendNotificationPayload.js +1 -1
  16. package/dist-esm/src/client/internal/_sendNotificationPayload.js.map +1 -1
  17. package/dist-esm/src/client/scheduleBroadcastNotification.js.map +1 -1
  18. package/dist-esm/src/client/scheduleNotification.js.map +1 -1
  19. package/dist-esm/src/client/sendBroadcastNotification.js.map +1 -1
  20. package/dist-esm/src/client/sendDirectNotification.js +1 -2
  21. package/dist-esm/src/client/sendDirectNotification.js.map +1 -1
  22. package/dist-esm/src/client/sendNotification.js.map +1 -1
  23. package/dist-esm/src/client/updateInstallation.js.map +1 -1
  24. package/dist-esm/src/models/installation.js +1 -1
  25. package/dist-esm/src/models/installation.js.map +1 -1
  26. package/dist-esm/src/models/notification.js +1 -1
  27. package/dist-esm/src/models/notification.js.map +1 -1
  28. package/dist-esm/src/models/notificationBuilder.js +6 -6
  29. package/dist-esm/src/models/notificationBuilder.js.map +1 -1
  30. package/dist-esm/src/models/notificationDetails.js.map +1 -1
  31. package/dist-esm/src/models/registration.js +3 -39
  32. package/dist-esm/src/models/registration.js.map +1 -1
  33. package/dist-esm/src/models/response.js.map +1 -1
  34. package/dist-esm/src/notificationHubsClient.js +12 -2
  35. package/dist-esm/src/notificationHubsClient.js.map +1 -1
  36. package/dist-esm/src/serializers/notificationHubJobSerializer.js +5 -1
  37. package/dist-esm/src/serializers/notificationHubJobSerializer.js.map +1 -1
  38. package/dist-esm/src/serializers/notificationOutcomeSerializer.js +31 -0
  39. package/dist-esm/src/serializers/notificationOutcomeSerializer.js.map +1 -0
  40. package/dist-esm/src/serializers/registrationSerializer.js +2 -29
  41. package/dist-esm/src/serializers/registrationSerializer.js.map +1 -1
  42. package/dist-esm/src/utils/constants.js +1 -1
  43. package/dist-esm/src/utils/constants.js.map +1 -1
  44. package/package.json +3 -3
  45. package/types/3.1/notification-hubs.d.ts +68 -77
  46. package/types/latest/notification-hubs.d.ts +69 -83
  47. package/types/latest/tsdoc-metadata.json +1 -1
  48. package/types/src/auth/hmacSha256.browser.d.ts +1 -0
  49. package/types/src/auth/hmacSha256.browser.d.ts.map +1 -1
  50. package/types/src/auth/sasTokenProvider.d.ts +28 -8
  51. package/types/src/auth/sasTokenProvider.d.ts.map +1 -1
  52. package/types/src/client/cancelScheduledNotification.d.ts +1 -1
  53. package/types/src/client/cancelScheduledNotification.d.ts.map +1 -1
  54. package/types/src/client/createOrUpdateInstallation.d.ts +1 -1
  55. package/types/src/client/createOrUpdateInstallation.d.ts.map +1 -1
  56. package/types/src/client/deleteInstallation.d.ts +1 -1
  57. package/types/src/client/deleteInstallation.d.ts.map +1 -1
  58. package/types/src/client/deleteRegistration.d.ts +1 -1
  59. package/types/src/client/deleteRegistration.d.ts.map +1 -1
  60. package/types/src/client/index.d.ts +0 -1
  61. package/types/src/client/index.d.ts.map +1 -1
  62. package/types/src/client/internal/_client.d.ts +8 -8
  63. package/types/src/client/internal/_client.d.ts.map +1 -1
  64. package/types/src/client/internal/_scheduleNotificationPayload.d.ts +1 -1
  65. package/types/src/client/internal/_scheduleNotificationPayload.d.ts.map +1 -1
  66. package/types/src/client/internal/_sendNotificationPayload.d.ts +1 -1
  67. package/types/src/client/internal/_sendNotificationPayload.d.ts.map +1 -1
  68. package/types/src/client/scheduleBroadcastNotification.d.ts +1 -1
  69. package/types/src/client/scheduleBroadcastNotification.d.ts.map +1 -1
  70. package/types/src/client/scheduleNotification.d.ts +1 -1
  71. package/types/src/client/scheduleNotification.d.ts.map +1 -1
  72. package/types/src/client/sendBroadcastNotification.d.ts +1 -1
  73. package/types/src/client/sendBroadcastNotification.d.ts.map +1 -1
  74. package/types/src/client/sendDirectNotification.d.ts +4 -5
  75. package/types/src/client/sendDirectNotification.d.ts.map +1 -1
  76. package/types/src/client/sendNotification.d.ts +1 -1
  77. package/types/src/client/sendNotification.d.ts.map +1 -1
  78. package/types/src/client/updateInstallation.d.ts +1 -1
  79. package/types/src/client/updateInstallation.d.ts.map +1 -1
  80. package/types/src/models/installation.d.ts +3 -3
  81. package/types/src/models/installation.d.ts.map +1 -1
  82. package/types/src/models/notification.d.ts +3 -3
  83. package/types/src/models/notification.d.ts.map +1 -1
  84. package/types/src/models/notificationBuilder.d.ts +4 -4
  85. package/types/src/models/notificationBuilder.d.ts.map +1 -1
  86. package/types/src/models/notificationDetails.d.ts +63 -0
  87. package/types/src/models/notificationDetails.d.ts.map +1 -1
  88. package/types/src/models/registration.d.ts +6 -59
  89. package/types/src/models/registration.d.ts.map +1 -1
  90. package/types/src/models/response.d.ts +0 -26
  91. package/types/src/models/response.d.ts.map +1 -1
  92. package/types/src/notificationHubsClient.d.ts +12 -6
  93. package/types/src/notificationHubsClient.d.ts.map +1 -1
  94. package/types/src/serializers/notificationHubJobSerializer.d.ts.map +1 -1
  95. package/types/src/serializers/notificationOutcomeSerializer.d.ts +3 -0
  96. package/types/src/serializers/notificationOutcomeSerializer.d.ts.map +1 -0
  97. package/types/src/serializers/registrationSerializer.d.ts +1 -21
  98. package/types/src/serializers/registrationSerializer.d.ts.map +1 -1
package/README.md CHANGED
@@ -9,8 +9,12 @@ Azure Notification Hubs provide a scaled-out push engine that enables you to sen
9
9
  - Notify users of enterprise events such as new messages and work items.
10
10
  - Send codes for multi-factor authentication.
11
11
 
12
- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/notificationhubs/notification-hubs/) |
13
- [Product documentation](https://docs.microsoft.com/azure/notification-hubs/)
12
+ Key links:
13
+
14
+ - [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/notificationhubs/notification-hubs/)
15
+ - [Package (npm)](https://www.npmjs.com/package/@azure/notification-hubs)
16
+ - [Product documentation](https://docs.microsoft.com/azure/notification-hubs/)
17
+ - [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/notificationhubs/notification-hubs/samples-dev)
14
18
 
15
19
  ## Getting started
16
20
 
@@ -134,7 +138,7 @@ Device management is a core concept to Notification Hubs to be able to store the
134
138
  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:
135
139
 
136
140
  - Fully idempotent API so calling create on the installation, so an operation can be retried without worries about duplications.
137
- - Support for `userId` and `installationId` properties which can be then used in tag expressions such as `$InstallationId:myInstallId` and `$UserId:bob@contoso.com`.
141
+ - Support for `userId` and `installationId` properties which can be then used in tag expressions such as `$InstallationId:{myInstallId}` and `$UserId:{bob@contoso.com}`.
138
142
  - Templates are now part of the installation instead of a separate registration and can be reference by name as a tag for sending.
139
143
  - Partial updates are supported through the [JSON Patch Standard](https://tools.ietf.org/html/rfc6902), which allows to add tags and change other data without having to first query the installation.
140
144
 
@@ -355,7 +359,7 @@ for await (const pages of registrations.byPage()) {
355
359
 
356
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.
357
361
 
358
- For debugging purposes, the `enableTestSend` options can be set to `true` which gets immediate feedback from the PNS on the `send*` 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` or `sendBroadcastNotification` methods, however, is not supported in production scenarios. This is not supported on the scheduled send methods.
359
363
 
360
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.
361
365
 
@@ -366,6 +370,7 @@ import { buildAppleNativeMessage } from "@azure/notification-hubs";
366
370
  // Using the modular approach
367
371
  import { buildAppleNativeMessage } from "@azure/notification-hubs/models/notificationBuilder";
368
372
 
373
+
369
374
  const apnsMessage = buildAppleNativeMessage({
370
375
  alert: {
371
376
  title: "Notification Title",
@@ -377,6 +382,7 @@ const apnsMessage = buildAppleNativeMessage({
377
382
  });
378
383
 
379
384
  // Send the message using the modular approach
385
+
380
386
  const result = await sendBroadcastNotification(context, apnsMessage);
381
387
  ```
382
388
 
@@ -473,9 +479,7 @@ const message = createAppleNotification({
473
479
  },
474
480
  });
475
481
 
476
- // Not required but can set test send to true for debugging purposes.
477
- const sendOptions: SendOperationOptions = { enableTestSend: false };
478
- const result = await client.sendDirectNotification(devicetoken, message, sendOptions);
482
+ const result = await client.sendDirectNotification(devicetoken, message);
479
483
 
480
484
  console.log(`Tracking ID: ${result.trackingId}`);
481
485
  console.log(`Correlation ID: ${result.correlationId}`);
@@ -507,8 +511,6 @@ const message = createAppleNotification({
507
511
  },
508
512
  });
509
513
 
510
- // Not required but can set test send to true for debugging purposes.
511
- const sendOptions: SendOperationOptions = { enableTestSend: false };
512
514
  const result = await sendDirectNotification(context, devicetoken, message, sendOptions);
513
515
 
514
516
  console.log(`Tracking ID: ${result.trackingId}`);
@@ -620,9 +622,7 @@ const message = createAppleNotification({
620
622
  },
621
623
  });
622
624
 
623
- // Not required but can set test send to true for debugging purposes.
624
- const sendOptions: SendOperationOptions = { enableTestSend: false };
625
- const result = await client.scheduleNotification(scheduledTime, tagExpression, message, sendOptions);
625
+ const result = await client.scheduleNotification(scheduledTime, tagExpression, message);
626
626
 
627
627
  console.log(`Tracking ID: ${result.trackingId}`);
628
628
  console.log(`Correlation ID: ${result.correlationId}`);
@@ -655,9 +655,7 @@ const message = createAppleNotification({
655
655
  },
656
656
  });
657
657
 
658
- // Not required but can set test send to true for debugging purposes.
659
- const sendOptions: SendOperationOptions = { enableTestSend: false };
660
- const result = await scheduleNotification(context, scheduledTime, tagExpression, message, sendOptions);
658
+ const result = await scheduleNotification(context, scheduledTime, tagExpression, message);
661
659
 
662
660
  console.log(`Tracking ID: ${result.trackingId}`);
663
661
  console.log(`Correlation ID: ${result.correlationId}`);
@@ -672,11 +670,11 @@ console.log(`Notification ID: ${result.notificationId}`);
672
670
 
673
671
  Azure Notification Hubs has a complete guide to troubleshooting problems with dropped notifications in the [Diagnose dropped notifications in Azure Notification Hubs Guide](https://docs.microsoft.com/azure/notification-hubs/notification-hubs-push-notification-fixer).
674
672
 
675
- [Test send](https://docs.microsoft.com/azure/notification-hubs/notification-hubs-push-notification-fixer#enabletestsend-property) is supported supported in the send methods with the `enableTestSend` option:
673
+ [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:
676
674
 
677
675
  ```typescript
678
676
  const sendOptions: SendOperationOptions = { enableTestSend: true };
679
- const result = await client.sendDirectNotification(devicetoken, message, sendOptions);
677
+ const result = await client.sendNotification(tags, message, sendOptions);
680
678
  ```
681
679
 
682
680
  ### Logging
@@ -744,6 +742,3 @@ folder for more details.
744
742
  - [Azure Notification Hubs](https://docs.microsoft.com/azure/notification-hubs/notification-hubs-push-notification-overview)
745
743
 
746
744
  ![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%notificationhubs%2Fnotification-hubs%2FREADME.png)
747
-
748
- [azure_cli]: https://docs.microsoft.com/cli/azure
749
- [azure_sub]: https://azure.microsoft.com/free/
package/dist/index.cjs CHANGED
@@ -3,8 +3,6 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var coreRestPipeline = require('@azure/core-rest-pipeline');
6
- var coreAuth = require('@azure/core-auth');
7
- var coreUtil = require('@azure/core-util');
8
6
  var crypto = require('crypto');
9
7
  var coreXml = require('@azure/core-xml');
10
8
  var coreClient = require('@azure/core-client');
@@ -13,7 +11,7 @@ var tslib = require('tslib');
13
11
 
14
12
  // Copyright (c) Microsoft Corporation.
15
13
  // Licensed under the MIT license.
16
- const SDK_VERSION = "1.0.0-beta.4";
14
+ const SDK_VERSION = "1.0.0-beta.6";
17
15
  const JSON_CONTENT_TYPE = "application/json;charset=utf-8";
18
16
  const XML_CONTENT_TYPE = "application/xml";
19
17
  const STREAM_CONTENT_TYPE = "application/octet-stream";
@@ -36,18 +34,7 @@ async function signString(key, toSign) {
36
34
  * @hidden
37
35
  */
38
36
  function createSasTokenProvider(data) {
39
- if (coreAuth.isNamedKeyCredential(data) || coreAuth.isSASCredential(data)) {
40
- return new SasTokenProviderImpl(data);
41
- }
42
- else if (coreUtil.isObjectWithProperties(data, ["sharedAccessKeyName", "sharedAccessKey"])) {
43
- return new SasTokenProviderImpl({
44
- name: data.sharedAccessKeyName,
45
- key: data.sharedAccessKey,
46
- });
47
- }
48
- else {
49
- return new SasTokenProviderImpl({ signature: data.sharedAccessSignature });
50
- }
37
+ return new SasTokenProviderImpl(data);
51
38
  }
52
39
  /**
53
40
  * A TokenProvider that generates a Sas token:
@@ -74,15 +61,7 @@ class SasTokenProviderImpl {
74
61
  * @param audience - The audience for which the token is desired.
75
62
  */
76
63
  async getToken(audience) {
77
- if (coreAuth.isNamedKeyCredential(this._credential)) {
78
- return createToken(this._credential.name, this._credential.key, Math.floor(Date.now() / 1000) + 3600, audience);
79
- }
80
- else {
81
- return {
82
- token: this._credential.signature,
83
- expiresOnTimestamp: 0,
84
- };
85
- }
64
+ return createToken(this._credential.sharedAccessKeyName, this._credential.sharedAccessKey, Math.floor(Date.now() / 1000) + 3600, audience);
86
65
  }
87
66
  }
88
67
  /**
@@ -324,6 +303,34 @@ function getTagsOrUndefined(value) {
324
303
  return result.split(",");
325
304
  }
326
305
 
306
+ // Copyright (c) Microsoft Corporation.
307
+ async function parseNotificationOutcome(bodyText) {
308
+ const xml = await coreXml.parseXML(bodyText, { includeRoot: true });
309
+ const outcome = xml.NotificationOutcome;
310
+ return {
311
+ success: getInteger(outcome.Success, "Success"),
312
+ failure: getInteger(outcome.Failure, "Failure"),
313
+ results: parseRegistrationResults(outcome.Results.RegistrationResult),
314
+ state: "DetailedStateAvailable",
315
+ };
316
+ }
317
+ function parseRegistrationResults(results) {
318
+ const registrationResults = [];
319
+ if (!isDefined(results)) {
320
+ return registrationResults;
321
+ }
322
+ const resultsArray = Array.isArray(results) ? results : [results];
323
+ for (const result of resultsArray) {
324
+ registrationResults.push({
325
+ applicationPlatform: getString(result.ApplicationPlatform, "ApplicationPlatform"),
326
+ registrationId: getString(result.RegistrationId, "RegistrationId"),
327
+ outcome: getString(result.Outcome, "Outcome"),
328
+ pnsHandle: getString(result.PnsHandle, "PnsHandle"),
329
+ });
330
+ }
331
+ return registrationResults;
332
+ }
333
+
327
334
  // Copyright (c) Microsoft Corporation.
328
335
  /**
329
336
  * Marker for atom metadata.
@@ -417,15 +424,14 @@ async function parseXMLError(bodyText) {
417
424
  }
418
425
 
419
426
  // Copyright (c) Microsoft Corporation.
420
- /**
421
- * @internal
422
- */
423
427
  function createRequest(endpoint, method, headers, options) {
424
428
  return coreRestPipeline.createPipelineRequest(Object.assign(Object.assign(Object.assign({}, options.tracingOptions), options.requestOptions), { url: endpoint.toString(), abortSignal: options.abortSignal, method,
425
429
  headers }));
426
430
  }
427
431
  /**
428
- * @internal
432
+ * Parses the HTTP response and creates a NotificationHubsResponse with header information from the operation.
433
+ * @param response - The HTTP response used to populate the result.
434
+ * @returns A NotificationHubsResponse with header information from the operation.
429
435
  */
430
436
  function parseNotificationResponse(response) {
431
437
  const correlationId = response.headers.get("x-ms-correlation-request-id");
@@ -438,16 +444,32 @@ function parseNotificationResponse(response) {
438
444
  };
439
445
  }
440
446
  /**
441
- * @internal
447
+ * Parses the HTTP response and creates a NotificationHubsMessageResponse with results from the notification.
448
+ * @param response - The HTTP response used to populate the result.
449
+ * @returns A NotificationHubsMessageResponse with results from the notification.
442
450
  */
443
- function parseNotificationSendResponse(response) {
451
+ async function parseNotificationSendResponse(response) {
444
452
  const result = parseNotificationResponse(response);
445
453
  let notificationId;
446
454
  if (result.location) {
447
455
  const locationUrl = new URL(result.location);
448
456
  notificationId = locationUrl.pathname.split("/")[3];
449
457
  }
450
- return Object.assign(Object.assign({}, result), { notificationId });
458
+ const requestUrl = new URL(response.request.url);
459
+ const isTestSend = requestUrl.searchParams.has("test");
460
+ const isDirectSend = requestUrl.searchParams.has("direct");
461
+ // Only broadcast/tag based sends are supported for test send
462
+ const responseBody = response.bodyAsText;
463
+ if (isTestSend && !isDirectSend && isDefined(responseBody)) {
464
+ const outcome = await parseNotificationOutcome(responseBody);
465
+ return Object.assign(Object.assign(Object.assign({}, result), outcome), { notificationId });
466
+ }
467
+ else {
468
+ return createDefaultResponse(result, notificationId);
469
+ }
470
+ }
471
+ function createDefaultResponse(response, notificationId) {
472
+ return Object.assign(Object.assign({}, response), { notificationId, success: 0, failure: 0, results: [], state: "Enqueued" });
451
473
  }
452
474
  /**
453
475
  * Sends a request through the client context.
@@ -499,7 +521,7 @@ const tracingClient = coreTracing.createTracingClient({
499
521
  });
500
522
 
501
523
  // Copyright (c) Microsoft Corporation.
502
- const OPERATION_NAME$h = "cancelScheduledNotification";
524
+ const OPERATION_NAME$i = "cancelScheduledNotification";
503
525
  /**
504
526
  * Cancels the scheduled notification with the given notification ID.
505
527
  * NOTE: This is only available in Standard SKU Azure Notification Hubs.
@@ -509,10 +531,10 @@ const OPERATION_NAME$h = "cancelScheduledNotification";
509
531
  * @returns A notification hub response with correlation ID and tracking ID.
510
532
  */
511
533
  function cancelScheduledNotification(context, notificationId, options = {}) {
512
- return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$h}`, options, async (updatedOptions) => {
534
+ return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$i}`, options, async (updatedOptions) => {
513
535
  const endpoint = context.requestUrl();
514
536
  endpoint.pathname += `/schedulednotifications/${notificationId}`;
515
- const headers = await context.createHeaders(OPERATION_NAME$h);
537
+ const headers = await context.createHeaders(OPERATION_NAME$i);
516
538
  const request = createRequest(endpoint, "DELETE", headers, updatedOptions);
517
539
  const response = await sendRequest(context, request, 200);
518
540
  return parseNotificationSendResponse(response);
@@ -520,7 +542,7 @@ function cancelScheduledNotification(context, notificationId, options = {}) {
520
542
  }
521
543
 
522
544
  // Copyright (c) Microsoft Corporation.
523
- const OPERATION_NAME$g = "createOrUpdateInstallation";
545
+ const OPERATION_NAME$h = "createOrUpdateInstallation";
524
546
  /**
525
547
  * Creates or overwrites an installation to a Notification Hub.
526
548
  * @param context - The Notification Hubs client.
@@ -529,10 +551,10 @@ const OPERATION_NAME$g = "createOrUpdateInstallation";
529
551
  * @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
530
552
  */
531
553
  function createOrUpdateInstallation(context, installation, options = {}) {
532
- return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$g}`, options, async (updatedOptions) => {
554
+ return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$h}`, options, async (updatedOptions) => {
533
555
  const endpoint = context.requestUrl();
534
556
  endpoint.pathname += `/installations/${installation.installationId}`;
535
- const headers = await context.createHeaders(OPERATION_NAME$g);
557
+ const headers = await context.createHeaders(OPERATION_NAME$h);
536
558
  headers.set("Content-Type", "application/json");
537
559
  const request = createRequest(endpoint, "PUT", headers, updatedOptions);
538
560
  request.body = JSON.stringify(installation);
@@ -568,7 +590,8 @@ const registrationDescriptionParser = {
568
590
  if (!isDefined(xml.feed.entry)) {
569
591
  return results;
570
592
  }
571
- for (const entry of xml.feed.entry) {
593
+ const entries = Array.isArray(xml.feed.entry) ? xml.feed.entry : [xml.feed.entry];
594
+ for (const entry of entries) {
572
595
  delete entry.content["$"];
573
596
  const keyName = Object.keys(entry.content)[0];
574
597
  const methodName = `create${keyName}`;
@@ -652,20 +675,6 @@ const registrationDescriptionParser = {
652
675
  createGcmTemplateRegistrationDescription(rawRegistrationDescription) {
653
676
  return Object.assign(Object.assign(Object.assign({}, this.createGcmRegistrationDescription(rawRegistrationDescription)), createTemplateRegistrationDescription(rawRegistrationDescription)), { type: "GcmTemplate" });
654
677
  },
655
- /**
656
- * @internal
657
- * Creates an FCM registration description from incoming XML property bag.
658
- */
659
- createFcmRegistrationDescription(rawRegistrationDescription) {
660
- return Object.assign(Object.assign({ fcmRegistrationId: getString(rawRegistrationDescription["FcmRegistrationId"], "fcmRegistrationId") }, createRegistrationDescription(rawRegistrationDescription)), { type: "Fcm" });
661
- },
662
- /**
663
- * @internal
664
- * Creates an FCM template registration description from incoming XML property bag.
665
- */
666
- createFcmTemplateRegistrationDescription(rawRegistrationDescription) {
667
- return Object.assign(Object.assign(Object.assign({}, this.createFcmRegistrationDescription(rawRegistrationDescription)), createTemplateRegistrationDescription(rawRegistrationDescription)), { type: "FcmTemplate" });
668
- },
669
678
  /**
670
679
  * @internal
671
680
  * Creates a Windows Phone registration description from incoming XML property bag.
@@ -823,20 +832,6 @@ const registrationDescriptionSerializer = {
823
832
  serializeGcmTemplateRegistrationDescription(description) {
824
833
  return Object.assign(Object.assign({}, this.serializeGcmRegistrationDescription(description)), serializeTemplateRegistrationDescription(description));
825
834
  },
826
- /**
827
- * @internal
828
- * Serializes an existing FCM registration description to an object for serialization.
829
- */
830
- serializeFcmRegistrationDescription(description) {
831
- return Object.assign(Object.assign({}, serializeRegistrationDescription(description)), { FcmRegistrationId: description.fcmRegistrationId });
832
- },
833
- /**
834
- * @internal
835
- * Serializes an existing FCM template registration description to an object for serialization.
836
- */
837
- serializeFcmTemplateRegistrationDescription(description) {
838
- return Object.assign(Object.assign({}, this.serializeFcmRegistrationDescription(description)), serializeTemplateRegistrationDescription(description));
839
- },
840
835
  /**
841
836
  * @internal
842
837
  * @deprecated Windows Phone is no longer supported.
@@ -942,7 +937,7 @@ async function createOrUpdateRegistrationDescription(context, registration, oper
942
937
  }
943
938
 
944
939
  // Copyright (c) Microsoft Corporation.
945
- const OPERATION_NAME$f = "createOrUpdateRegistration";
940
+ const OPERATION_NAME$g = "createOrUpdateRegistration";
946
941
  /**
947
942
  * Creates or updates a registration.
948
943
  * @param context - The Notification Hubs client.
@@ -951,13 +946,13 @@ const OPERATION_NAME$f = "createOrUpdateRegistration";
951
946
  * @returns The created or updated registration description.
952
947
  */
953
948
  function createOrUpdateRegistration(context, registration, options = {}) {
954
- return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$f}`, options, async (updatedOptions) => {
949
+ return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$g}`, options, async (updatedOptions) => {
955
950
  return createOrUpdateRegistrationDescription(context, registration, "createOrUpdate", updatedOptions);
956
951
  });
957
952
  }
958
953
 
959
954
  // Copyright (c) Microsoft Corporation.
960
- const OPERATION_NAME$e = "createRegistrationId";
955
+ const OPERATION_NAME$f = "createRegistrationId";
961
956
  /**
962
957
  * Creates a new registration ID.
963
958
  * @param context - The Notification Hubs client.
@@ -965,10 +960,10 @@ const OPERATION_NAME$e = "createRegistrationId";
965
960
  * @returns The newly created registration ID.
966
961
  */
967
962
  function createRegistrationId(context, options = {}) {
968
- return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$e}`, options, async (updatedOptions) => {
963
+ return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$f}`, options, async (updatedOptions) => {
969
964
  const endpoint = context.requestUrl();
970
965
  endpoint.pathname += "/registrationIDs";
971
- const headers = await context.createHeaders(OPERATION_NAME$e);
966
+ const headers = await context.createHeaders(OPERATION_NAME$f);
972
967
  headers.set("Content-Type", "application/xml;type=entry;charset=utf-8");
973
968
  const request = createRequest(endpoint, "POST", headers, updatedOptions);
974
969
  const response = await sendRequest(context, request, 201);
@@ -981,7 +976,7 @@ function createRegistrationId(context, options = {}) {
981
976
  }
982
977
 
983
978
  // Copyright (c) Microsoft Corporation.
984
- const OPERATION_NAME$d = "createRegistration";
979
+ const OPERATION_NAME$e = "createRegistration";
985
980
  /**
986
981
  * Creates a new registration. This method generates a registration ID,
987
982
  * which you can subsequently use to retrieve, update, and delete this registration.
@@ -991,7 +986,7 @@ const OPERATION_NAME$d = "createRegistration";
991
986
  * @returns The newly created registration description.
992
987
  */
993
988
  function createRegistration(context, registration, options = {}) {
994
- return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$d}`, options, async (updatedOptions) => {
989
+ return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$e}`, options, async (updatedOptions) => {
995
990
  if (registration.registrationId) {
996
991
  throw new coreRestPipeline.RestError("registrationId must not be set during a create operation", {
997
992
  statusCode: 400,
@@ -1002,7 +997,7 @@ function createRegistration(context, registration, options = {}) {
1002
997
  }
1003
998
 
1004
999
  // Copyright (c) Microsoft Corporation.
1005
- const OPERATION_NAME$c = "deleteInstallation";
1000
+ const OPERATION_NAME$d = "deleteInstallation";
1006
1001
  /**
1007
1002
  * Deletes an installation from a Notification Hub.
1008
1003
  * @param context - The Notification Hubs client.
@@ -1011,16 +1006,38 @@ const OPERATION_NAME$c = "deleteInstallation";
1011
1006
  * @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
1012
1007
  */
1013
1008
  function deleteInstallation(context, installationId, options = {}) {
1014
- return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$c}`, options, async (updatedOptions) => {
1009
+ return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$d}`, options, async (updatedOptions) => {
1015
1010
  const endpoint = context.requestUrl();
1016
1011
  endpoint.pathname += `/installations/${installationId}`;
1017
- const headers = await context.createHeaders(OPERATION_NAME$c);
1012
+ const headers = await context.createHeaders(OPERATION_NAME$d);
1018
1013
  const request = createRequest(endpoint, "DELETE", headers, updatedOptions);
1019
1014
  const response = await sendRequest(context, request, 204);
1020
1015
  return parseNotificationResponse(response);
1021
1016
  });
1022
1017
  }
1023
1018
 
1019
+ // Copyright (c) Microsoft Corporation.
1020
+ const OPERATION_NAME$c = "deleteRegistration";
1021
+ /**
1022
+ * Deletes a registration with the given registration ID.
1023
+ * @param context - The Notification Hubs client.
1024
+ * @param registrationId - The registration ID of the registration to delete.
1025
+ * @param options - The options for delete operations including the ETag
1026
+ * @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
1027
+ */
1028
+ function deleteRegistration(context, registrationId, options = {}) {
1029
+ return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$c}`, options, async (updatedOptions) => {
1030
+ const endpoint = context.requestUrl();
1031
+ endpoint.pathname += `/registrations/${registrationId}`;
1032
+ const headers = await context.createHeaders(OPERATION_NAME$c);
1033
+ headers.set("Content-Type", "application/atom+xml;type=entry;charset=utf-8");
1034
+ headers.set("If-Match", isDefined(options.etag) ? `"${options.etag}"` : "*");
1035
+ const request = createRequest(endpoint, "GET", headers, updatedOptions);
1036
+ const response = await sendRequest(context, request, 200);
1037
+ return parseNotificationResponse(response);
1038
+ });
1039
+ }
1040
+
1024
1041
  // Copyright (c) Microsoft Corporation.
1025
1042
  const OPERATION_NAME$b = "getFeedbackContainerUrl";
1026
1043
  /**
@@ -1097,7 +1114,11 @@ async function parseNotificationHubJobEntry(bodyText) {
1097
1114
  async function parseNotificationHubJobFeed(bodyText) {
1098
1115
  const xml = await coreXml.parseXML(bodyText, { includeRoot: true });
1099
1116
  const results = [];
1100
- for (const item of xml.feed.entry) {
1117
+ if (!isDefined(xml.feed.entry)) {
1118
+ return results;
1119
+ }
1120
+ const entries = Array.isArray(xml.feed.entry) ? xml.feed.entry : [xml.feed.entry];
1121
+ for (const item of entries) {
1101
1122
  results.push(createNotificationHubJob(item.content.NotificationHubJob));
1102
1123
  }
1103
1124
  return results;
@@ -1514,7 +1535,7 @@ function sendNotificationPayload(context, notification, method, pushHandle, tags
1514
1535
  const endpoint = context.requestUrl();
1515
1536
  endpoint.pathname += "/messages/";
1516
1537
  if (options.enableTestSend) {
1517
- endpoint.searchParams.append("debug", "true");
1538
+ endpoint.searchParams.append("test", "true");
1518
1539
  }
1519
1540
  const headers = await context.createHeaders(method);
1520
1541
  if (notification.headers) {
@@ -1572,8 +1593,7 @@ function sendBroadcastNotification(context, notification, options = {}) {
1572
1593
  * @param context - The Notification Hubs client.
1573
1594
  * @param pushHandle - The push handle which is the unique identifier for the device.
1574
1595
  * @param notification - The notification to send to the device.
1575
- * @param options - Configuration options for the direct send operation which can contain custom headers
1576
- * which may include APNs specific such as apns-topic or for WNS, X-WNS-TYPE.
1596
+ * @param options - The options for sending a direct notification.
1577
1597
  * @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
1578
1598
  */
1579
1599
  function sendDirectNotification(context, pushHandle, notification, options = {}) {
@@ -1746,6 +1766,16 @@ class NotificationHubsServiceClient {
1746
1766
  updateRegistration(registration, options = {}) {
1747
1767
  return updateRegistration(this._client, registration, options);
1748
1768
  }
1769
+ /**
1770
+ * Deletes a registration with the given registration ID.
1771
+ * @param context - The Notification Hubs client.
1772
+ * @param registrationId - The registration ID of the registration to delete.
1773
+ * @param options - The options for delete operations including the ETag
1774
+ * @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
1775
+ */
1776
+ deleteRegistration(registrationId, options = {}) {
1777
+ return deleteRegistration(this._client, registrationId, options);
1778
+ }
1749
1779
  /**
1750
1780
  * Gets a registration by the given registration ID.
1751
1781
  * @param registrationId - The ID of the registration to get.
@@ -1776,8 +1806,7 @@ class NotificationHubsServiceClient {
1776
1806
  * Sends a direct push notification to a device with the given push handle.
1777
1807
  * @param pushHandle - The push handle which is the unique identifier for the device.
1778
1808
  * @param notification - The notification to send to the device.
1779
- * @param options - Configuration options for the direct send operation which can contain custom headers
1780
- * which may include APNs specific such as apns-topic or for WNS, X-WNS-TYPE.
1809
+ * @param options - The options for sending a direct notification.
1781
1810
  * @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
1782
1811
  */
1783
1812
  sendDirectNotification(pushHandle, notification, options = {}) {
@@ -1916,7 +1945,7 @@ function createBaiduInstallation(installation) {
1916
1945
  * @param installation - A partial installation used to create the Firebase Legacy HTTP installation.
1917
1946
  * @returns The newly created Baidu installation.
1918
1947
  */
1919
- function createFirebaseLegacyInstallation(installation) {
1948
+ function createFcmLegacyInstallation(installation) {
1920
1949
  return Object.assign(Object.assign({}, installation), { platform: "gcm" });
1921
1950
  }
1922
1951
  /**
@@ -1974,7 +2003,7 @@ function createBrowserNotification(notification) {
1974
2003
  * @param notification - A partial message used to create a message for Firebase.
1975
2004
  * @returns A newly created Firebase.
1976
2005
  */
1977
- function createFirebaseLegacyNotification(notification) {
2006
+ function createFcmLegacyNotification(notification) {
1978
2007
  return Object.assign(Object.assign({}, notification), { platform: "gcm", contentType: JSON_CONTENT_TYPE });
1979
2008
  }
1980
2009
  /**
@@ -2088,7 +2117,7 @@ function buildAppleNativeMessage(nativeMessage, additionalProperties) {
2088
2117
  headers: headers,
2089
2118
  });
2090
2119
  }
2091
- function buildFirebaseLegacyNativePayload(nativeNotification) {
2120
+ function buildFcmLegacyNativePayload(nativeNotification) {
2092
2121
  if (!isDefined(nativeNotification)) {
2093
2122
  return undefined;
2094
2123
  }
@@ -2115,9 +2144,9 @@ function buildFirebaseLegacyNativePayload(nativeNotification) {
2115
2144
  return notification;
2116
2145
  }
2117
2146
  /**
2118
- * Creates a FirebaseLegacyNotification from a native Firebase payload.
2147
+ * Creates a FcmLegacyNotification from a native Firebase payload.
2119
2148
  * @param nativeMessage - The native message payload to send to Notification Hubs.
2120
- * @returns The FirebaseLegacyNotification to send to Notification Hubs.
2149
+ * @returns The FcmLegacyNotification to send to Notification Hubs.
2121
2150
  */
2122
2151
  function buildFirebaseLegacyNativeMessage(nativeMessage) {
2123
2152
  const jsonMessage = {
@@ -2132,9 +2161,9 @@ function buildFirebaseLegacyNativeMessage(nativeMessage) {
2132
2161
  restricted_package_name: nativeMessage.restrictedPackageName,
2133
2162
  dry_run: nativeMessage.dryRun,
2134
2163
  data: nativeMessage.data,
2135
- notification: buildFirebaseLegacyNativePayload(nativeMessage.notification),
2164
+ notification: buildFcmLegacyNativePayload(nativeMessage.notification),
2136
2165
  };
2137
- return createFirebaseLegacyNotification({
2166
+ return createFcmLegacyNotification({
2138
2167
  body: JSON.stringify(jsonMessage),
2139
2168
  });
2140
2169
  }
@@ -2270,57 +2299,21 @@ function createBrowserTemplateRegistrationDescription(description) {
2270
2299
  return Object.assign(Object.assign({}, description), { type: "BrowserTemplate" });
2271
2300
  }
2272
2301
  /**
2273
- * @deprecated Use createFcmRegistrationDescription instead.
2274
- * Creates a GCM registration description.
2302
+ * Creates a Firebase Legacy registration description.
2275
2303
  * @param description - A partial GCM registration description.
2276
2304
  * @returns A created GCM registration description.
2277
2305
  */
2278
- function createGcmRegistrationDescription(description) {
2306
+ function createFcmLegacyRegistrationDescription(description) {
2279
2307
  return Object.assign(Object.assign({}, description), { type: "Gcm" });
2280
2308
  }
2281
2309
  /**
2282
- * @deprecated Use createFcmTemplateRegistrationDescription instead.
2283
2310
  * Creates a GCM template registration description.
2284
2311
  * @param description - A partial GCM template registration description.
2285
2312
  * @returns A created GCM template registration description.
2286
2313
  */
2287
- function createGcmTemplateRegistrationDescription(description) {
2314
+ function createFcmLegacyTemplateRegistrationDescription(description) {
2288
2315
  return Object.assign(Object.assign({}, description), { type: "GcmTemplate" });
2289
2316
  }
2290
- /**
2291
- * Creates an FCM registration description.
2292
- * @param description - A partial FCM registration description.
2293
- * @returns A created FCM registration description.
2294
- */
2295
- function createFcmRegistrationDescription(description) {
2296
- return Object.assign(Object.assign({}, description), { type: "Fcm" });
2297
- }
2298
- /**
2299
- * Creates an FCM template registration description.
2300
- * @param description - A partial FCM template registration description.
2301
- * @returns A created FCM template registration description.
2302
- */
2303
- function createFcmTemplateRegistrationDescription(description) {
2304
- return Object.assign(Object.assign({}, description), { type: "FcmTemplate" });
2305
- }
2306
- /**
2307
- * @deprecated Windows Phone is no longer supported.
2308
- * Creates an MPNS registration description.
2309
- * @param description - A partial MPNS registration description.
2310
- * @returns A created MPNS registration description.
2311
- */
2312
- function createMpnsRegistrationDescription(description) {
2313
- return Object.assign(Object.assign({}, description), { type: "Mpns" });
2314
- }
2315
- /**
2316
- * @deprecated Windows Phone is no longer supported.
2317
- * Creates an MPNS template registration description.
2318
- * @param description - A partial MPNS template registration description.
2319
- * @returns A created MPNS template registration description.
2320
- */
2321
- function createMpnsTemplateRegistrationDescription(description) {
2322
- return Object.assign(Object.assign({}, description), { type: "MpnsTemplate" });
2323
- }
2324
2317
  /**
2325
2318
  * Creates a Windows registration description.
2326
2319
  * @param description - A partial Windows registration description.
@@ -2360,14 +2353,10 @@ exports.createBrowserInstallation = createBrowserInstallation;
2360
2353
  exports.createBrowserNotification = createBrowserNotification;
2361
2354
  exports.createBrowserRegistrationDescription = createBrowserRegistrationDescription;
2362
2355
  exports.createBrowserTemplateRegistrationDescription = createBrowserTemplateRegistrationDescription;
2363
- exports.createFcmRegistrationDescription = createFcmRegistrationDescription;
2364
- exports.createFcmTemplateRegistrationDescription = createFcmTemplateRegistrationDescription;
2365
- exports.createFirebaseLegacyInstallation = createFirebaseLegacyInstallation;
2366
- exports.createFirebaseLegacyNotification = createFirebaseLegacyNotification;
2367
- exports.createGcmRegistrationDescription = createGcmRegistrationDescription;
2368
- exports.createGcmTemplateRegistrationDescription = createGcmTemplateRegistrationDescription;
2369
- exports.createMpnsRegistrationDescription = createMpnsRegistrationDescription;
2370
- exports.createMpnsTemplateRegistrationDescription = createMpnsTemplateRegistrationDescription;
2356
+ exports.createFcmLegacyInstallation = createFcmLegacyInstallation;
2357
+ exports.createFcmLegacyNotification = createFcmLegacyNotification;
2358
+ exports.createFcmLegacyRegistrationDescription = createFcmLegacyRegistrationDescription;
2359
+ exports.createFcmLegacyTemplateRegistrationDescription = createFcmLegacyTemplateRegistrationDescription;
2371
2360
  exports.createTemplateNotification = createTemplateNotification;
2372
2361
  exports.createWindowsBadgeNotification = createWindowsBadgeNotification;
2373
2362
  exports.createWindowsInstallation = createWindowsInstallation;