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

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 +128 -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 +5 -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 +4 -4
  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.3";
14
+ const SDK_VERSION = "1.0.0-beta.5";
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);
@@ -565,7 +587,11 @@ const registrationDescriptionParser = {
565
587
  async parseRegistrationFeed(bodyText) {
566
588
  const xml = await coreXml.parseXML(bodyText, { includeRoot: true });
567
589
  const results = [];
568
- for (const entry of xml.feed.entry) {
590
+ if (!isDefined(xml.feed.entry)) {
591
+ return results;
592
+ }
593
+ const entries = Array.isArray(xml.feed.entry) ? xml.feed.entry : [xml.feed.entry];
594
+ for (const entry of entries) {
569
595
  delete entry.content["$"];
570
596
  const keyName = Object.keys(entry.content)[0];
571
597
  const methodName = `create${keyName}`;
@@ -649,20 +675,6 @@ const registrationDescriptionParser = {
649
675
  createGcmTemplateRegistrationDescription(rawRegistrationDescription) {
650
676
  return Object.assign(Object.assign(Object.assign({}, this.createGcmRegistrationDescription(rawRegistrationDescription)), createTemplateRegistrationDescription(rawRegistrationDescription)), { type: "GcmTemplate" });
651
677
  },
652
- /**
653
- * @internal
654
- * Creates an FCM registration description from incoming XML property bag.
655
- */
656
- createFcmRegistrationDescription(rawRegistrationDescription) {
657
- return Object.assign(Object.assign({ fcmRegistrationId: getString(rawRegistrationDescription["FcmRegistrationId"], "fcmRegistrationId") }, createRegistrationDescription(rawRegistrationDescription)), { type: "Fcm" });
658
- },
659
- /**
660
- * @internal
661
- * Creates an FCM template registration description from incoming XML property bag.
662
- */
663
- createFcmTemplateRegistrationDescription(rawRegistrationDescription) {
664
- return Object.assign(Object.assign(Object.assign({}, this.createFcmRegistrationDescription(rawRegistrationDescription)), createTemplateRegistrationDescription(rawRegistrationDescription)), { type: "FcmTemplate" });
665
- },
666
678
  /**
667
679
  * @internal
668
680
  * Creates a Windows Phone registration description from incoming XML property bag.
@@ -820,20 +832,6 @@ const registrationDescriptionSerializer = {
820
832
  serializeGcmTemplateRegistrationDescription(description) {
821
833
  return Object.assign(Object.assign({}, this.serializeGcmRegistrationDescription(description)), serializeTemplateRegistrationDescription(description));
822
834
  },
823
- /**
824
- * @internal
825
- * Serializes an existing FCM registration description to an object for serialization.
826
- */
827
- serializeFcmRegistrationDescription(description) {
828
- return Object.assign(Object.assign({}, serializeRegistrationDescription(description)), { FcmRegistrationId: description.fcmRegistrationId });
829
- },
830
- /**
831
- * @internal
832
- * Serializes an existing FCM template registration description to an object for serialization.
833
- */
834
- serializeFcmTemplateRegistrationDescription(description) {
835
- return Object.assign(Object.assign({}, this.serializeFcmRegistrationDescription(description)), serializeTemplateRegistrationDescription(description));
836
- },
837
835
  /**
838
836
  * @internal
839
837
  * @deprecated Windows Phone is no longer supported.
@@ -939,7 +937,7 @@ async function createOrUpdateRegistrationDescription(context, registration, oper
939
937
  }
940
938
 
941
939
  // Copyright (c) Microsoft Corporation.
942
- const OPERATION_NAME$f = "createOrUpdateRegistration";
940
+ const OPERATION_NAME$g = "createOrUpdateRegistration";
943
941
  /**
944
942
  * Creates or updates a registration.
945
943
  * @param context - The Notification Hubs client.
@@ -948,13 +946,13 @@ const OPERATION_NAME$f = "createOrUpdateRegistration";
948
946
  * @returns The created or updated registration description.
949
947
  */
950
948
  function createOrUpdateRegistration(context, registration, options = {}) {
951
- return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$f}`, options, async (updatedOptions) => {
949
+ return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$g}`, options, async (updatedOptions) => {
952
950
  return createOrUpdateRegistrationDescription(context, registration, "createOrUpdate", updatedOptions);
953
951
  });
954
952
  }
955
953
 
956
954
  // Copyright (c) Microsoft Corporation.
957
- const OPERATION_NAME$e = "createRegistrationId";
955
+ const OPERATION_NAME$f = "createRegistrationId";
958
956
  /**
959
957
  * Creates a new registration ID.
960
958
  * @param context - The Notification Hubs client.
@@ -962,10 +960,10 @@ const OPERATION_NAME$e = "createRegistrationId";
962
960
  * @returns The newly created registration ID.
963
961
  */
964
962
  function createRegistrationId(context, options = {}) {
965
- return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$e}`, options, async (updatedOptions) => {
963
+ return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$f}`, options, async (updatedOptions) => {
966
964
  const endpoint = context.requestUrl();
967
965
  endpoint.pathname += "/registrationIDs";
968
- const headers = await context.createHeaders(OPERATION_NAME$e);
966
+ const headers = await context.createHeaders(OPERATION_NAME$f);
969
967
  headers.set("Content-Type", "application/xml;type=entry;charset=utf-8");
970
968
  const request = createRequest(endpoint, "POST", headers, updatedOptions);
971
969
  const response = await sendRequest(context, request, 201);
@@ -978,7 +976,7 @@ function createRegistrationId(context, options = {}) {
978
976
  }
979
977
 
980
978
  // Copyright (c) Microsoft Corporation.
981
- const OPERATION_NAME$d = "createRegistration";
979
+ const OPERATION_NAME$e = "createRegistration";
982
980
  /**
983
981
  * Creates a new registration. This method generates a registration ID,
984
982
  * which you can subsequently use to retrieve, update, and delete this registration.
@@ -988,7 +986,7 @@ const OPERATION_NAME$d = "createRegistration";
988
986
  * @returns The newly created registration description.
989
987
  */
990
988
  function createRegistration(context, registration, options = {}) {
991
- return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$d}`, options, async (updatedOptions) => {
989
+ return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$e}`, options, async (updatedOptions) => {
992
990
  if (registration.registrationId) {
993
991
  throw new coreRestPipeline.RestError("registrationId must not be set during a create operation", {
994
992
  statusCode: 400,
@@ -999,7 +997,7 @@ function createRegistration(context, registration, options = {}) {
999
997
  }
1000
998
 
1001
999
  // Copyright (c) Microsoft Corporation.
1002
- const OPERATION_NAME$c = "deleteInstallation";
1000
+ const OPERATION_NAME$d = "deleteInstallation";
1003
1001
  /**
1004
1002
  * Deletes an installation from a Notification Hub.
1005
1003
  * @param context - The Notification Hubs client.
@@ -1008,16 +1006,38 @@ const OPERATION_NAME$c = "deleteInstallation";
1008
1006
  * @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
1009
1007
  */
1010
1008
  function deleteInstallation(context, installationId, options = {}) {
1011
- return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$c}`, options, async (updatedOptions) => {
1009
+ return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$d}`, options, async (updatedOptions) => {
1012
1010
  const endpoint = context.requestUrl();
1013
1011
  endpoint.pathname += `/installations/${installationId}`;
1014
- const headers = await context.createHeaders(OPERATION_NAME$c);
1012
+ const headers = await context.createHeaders(OPERATION_NAME$d);
1015
1013
  const request = createRequest(endpoint, "DELETE", headers, updatedOptions);
1016
1014
  const response = await sendRequest(context, request, 204);
1017
1015
  return parseNotificationResponse(response);
1018
1016
  });
1019
1017
  }
1020
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
+
1021
1041
  // Copyright (c) Microsoft Corporation.
1022
1042
  const OPERATION_NAME$b = "getFeedbackContainerUrl";
1023
1043
  /**
@@ -1094,7 +1114,11 @@ async function parseNotificationHubJobEntry(bodyText) {
1094
1114
  async function parseNotificationHubJobFeed(bodyText) {
1095
1115
  const xml = await coreXml.parseXML(bodyText, { includeRoot: true });
1096
1116
  const results = [];
1097
- 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) {
1098
1122
  results.push(createNotificationHubJob(item.content.NotificationHubJob));
1099
1123
  }
1100
1124
  return results;
@@ -1511,7 +1535,7 @@ function sendNotificationPayload(context, notification, method, pushHandle, tags
1511
1535
  const endpoint = context.requestUrl();
1512
1536
  endpoint.pathname += "/messages/";
1513
1537
  if (options.enableTestSend) {
1514
- endpoint.searchParams.append("debug", "true");
1538
+ endpoint.searchParams.append("test", "true");
1515
1539
  }
1516
1540
  const headers = await context.createHeaders(method);
1517
1541
  if (notification.headers) {
@@ -1569,8 +1593,7 @@ function sendBroadcastNotification(context, notification, options = {}) {
1569
1593
  * @param context - The Notification Hubs client.
1570
1594
  * @param pushHandle - The push handle which is the unique identifier for the device.
1571
1595
  * @param notification - The notification to send to the device.
1572
- * @param options - Configuration options for the direct send operation which can contain custom headers
1573
- * 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.
1574
1597
  * @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
1575
1598
  */
1576
1599
  function sendDirectNotification(context, pushHandle, notification, options = {}) {
@@ -1743,6 +1766,16 @@ class NotificationHubsServiceClient {
1743
1766
  updateRegistration(registration, options = {}) {
1744
1767
  return updateRegistration(this._client, registration, options);
1745
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
+ }
1746
1779
  /**
1747
1780
  * Gets a registration by the given registration ID.
1748
1781
  * @param registrationId - The ID of the registration to get.
@@ -1773,8 +1806,7 @@ class NotificationHubsServiceClient {
1773
1806
  * Sends a direct push notification to a device with the given push handle.
1774
1807
  * @param pushHandle - The push handle which is the unique identifier for the device.
1775
1808
  * @param notification - The notification to send to the device.
1776
- * @param options - Configuration options for the direct send operation which can contain custom headers
1777
- * 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.
1778
1810
  * @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
1779
1811
  */
1780
1812
  sendDirectNotification(pushHandle, notification, options = {}) {
@@ -1913,7 +1945,7 @@ function createBaiduInstallation(installation) {
1913
1945
  * @param installation - A partial installation used to create the Firebase Legacy HTTP installation.
1914
1946
  * @returns The newly created Baidu installation.
1915
1947
  */
1916
- function createFirebaseLegacyInstallation(installation) {
1948
+ function createFcmLegacyInstallation(installation) {
1917
1949
  return Object.assign(Object.assign({}, installation), { platform: "gcm" });
1918
1950
  }
1919
1951
  /**
@@ -1971,7 +2003,7 @@ function createBrowserNotification(notification) {
1971
2003
  * @param notification - A partial message used to create a message for Firebase.
1972
2004
  * @returns A newly created Firebase.
1973
2005
  */
1974
- function createFirebaseLegacyNotification(notification) {
2006
+ function createFcmLegacyNotification(notification) {
1975
2007
  return Object.assign(Object.assign({}, notification), { platform: "gcm", contentType: JSON_CONTENT_TYPE });
1976
2008
  }
1977
2009
  /**
@@ -2085,7 +2117,7 @@ function buildAppleNativeMessage(nativeMessage, additionalProperties) {
2085
2117
  headers: headers,
2086
2118
  });
2087
2119
  }
2088
- function buildFirebaseLegacyNativePayload(nativeNotification) {
2120
+ function buildFcmLegacyNativePayload(nativeNotification) {
2089
2121
  if (!isDefined(nativeNotification)) {
2090
2122
  return undefined;
2091
2123
  }
@@ -2112,9 +2144,9 @@ function buildFirebaseLegacyNativePayload(nativeNotification) {
2112
2144
  return notification;
2113
2145
  }
2114
2146
  /**
2115
- * Creates a FirebaseLegacyNotification from a native Firebase payload.
2147
+ * Creates a FcmLegacyNotification from a native Firebase payload.
2116
2148
  * @param nativeMessage - The native message payload to send to Notification Hubs.
2117
- * @returns The FirebaseLegacyNotification to send to Notification Hubs.
2149
+ * @returns The FcmLegacyNotification to send to Notification Hubs.
2118
2150
  */
2119
2151
  function buildFirebaseLegacyNativeMessage(nativeMessage) {
2120
2152
  const jsonMessage = {
@@ -2129,9 +2161,9 @@ function buildFirebaseLegacyNativeMessage(nativeMessage) {
2129
2161
  restricted_package_name: nativeMessage.restrictedPackageName,
2130
2162
  dry_run: nativeMessage.dryRun,
2131
2163
  data: nativeMessage.data,
2132
- notification: buildFirebaseLegacyNativePayload(nativeMessage.notification),
2164
+ notification: buildFcmLegacyNativePayload(nativeMessage.notification),
2133
2165
  };
2134
- return createFirebaseLegacyNotification({
2166
+ return createFcmLegacyNotification({
2135
2167
  body: JSON.stringify(jsonMessage),
2136
2168
  });
2137
2169
  }
@@ -2267,57 +2299,21 @@ function createBrowserTemplateRegistrationDescription(description) {
2267
2299
  return Object.assign(Object.assign({}, description), { type: "BrowserTemplate" });
2268
2300
  }
2269
2301
  /**
2270
- * @deprecated Use createFcmRegistrationDescription instead.
2271
- * Creates a GCM registration description.
2302
+ * Creates a Firebase Legacy registration description.
2272
2303
  * @param description - A partial GCM registration description.
2273
2304
  * @returns A created GCM registration description.
2274
2305
  */
2275
- function createGcmRegistrationDescription(description) {
2306
+ function createFcmLegacyRegistrationDescription(description) {
2276
2307
  return Object.assign(Object.assign({}, description), { type: "Gcm" });
2277
2308
  }
2278
2309
  /**
2279
- * @deprecated Use createFcmTemplateRegistrationDescription instead.
2280
2310
  * Creates a GCM template registration description.
2281
2311
  * @param description - A partial GCM template registration description.
2282
2312
  * @returns A created GCM template registration description.
2283
2313
  */
2284
- function createGcmTemplateRegistrationDescription(description) {
2314
+ function createFcmLegacyTemplateRegistrationDescription(description) {
2285
2315
  return Object.assign(Object.assign({}, description), { type: "GcmTemplate" });
2286
2316
  }
2287
- /**
2288
- * Creates an FCM registration description.
2289
- * @param description - A partial FCM registration description.
2290
- * @returns A created FCM registration description.
2291
- */
2292
- function createFcmRegistrationDescription(description) {
2293
- return Object.assign(Object.assign({}, description), { type: "Fcm" });
2294
- }
2295
- /**
2296
- * Creates an FCM template registration description.
2297
- * @param description - A partial FCM template registration description.
2298
- * @returns A created FCM template registration description.
2299
- */
2300
- function createFcmTemplateRegistrationDescription(description) {
2301
- return Object.assign(Object.assign({}, description), { type: "FcmTemplate" });
2302
- }
2303
- /**
2304
- * @deprecated Windows Phone is no longer supported.
2305
- * Creates an MPNS registration description.
2306
- * @param description - A partial MPNS registration description.
2307
- * @returns A created MPNS registration description.
2308
- */
2309
- function createMpnsRegistrationDescription(description) {
2310
- return Object.assign(Object.assign({}, description), { type: "Mpns" });
2311
- }
2312
- /**
2313
- * @deprecated Windows Phone is no longer supported.
2314
- * Creates an MPNS template registration description.
2315
- * @param description - A partial MPNS template registration description.
2316
- * @returns A created MPNS template registration description.
2317
- */
2318
- function createMpnsTemplateRegistrationDescription(description) {
2319
- return Object.assign(Object.assign({}, description), { type: "MpnsTemplate" });
2320
- }
2321
2317
  /**
2322
2318
  * Creates a Windows registration description.
2323
2319
  * @param description - A partial Windows registration description.
@@ -2357,14 +2353,10 @@ exports.createBrowserInstallation = createBrowserInstallation;
2357
2353
  exports.createBrowserNotification = createBrowserNotification;
2358
2354
  exports.createBrowserRegistrationDescription = createBrowserRegistrationDescription;
2359
2355
  exports.createBrowserTemplateRegistrationDescription = createBrowserTemplateRegistrationDescription;
2360
- exports.createFcmRegistrationDescription = createFcmRegistrationDescription;
2361
- exports.createFcmTemplateRegistrationDescription = createFcmTemplateRegistrationDescription;
2362
- exports.createFirebaseLegacyInstallation = createFirebaseLegacyInstallation;
2363
- exports.createFirebaseLegacyNotification = createFirebaseLegacyNotification;
2364
- exports.createGcmRegistrationDescription = createGcmRegistrationDescription;
2365
- exports.createGcmTemplateRegistrationDescription = createGcmTemplateRegistrationDescription;
2366
- exports.createMpnsRegistrationDescription = createMpnsRegistrationDescription;
2367
- exports.createMpnsTemplateRegistrationDescription = createMpnsTemplateRegistrationDescription;
2356
+ exports.createFcmLegacyInstallation = createFcmLegacyInstallation;
2357
+ exports.createFcmLegacyNotification = createFcmLegacyNotification;
2358
+ exports.createFcmLegacyRegistrationDescription = createFcmLegacyRegistrationDescription;
2359
+ exports.createFcmLegacyTemplateRegistrationDescription = createFcmLegacyTemplateRegistrationDescription;
2368
2360
  exports.createTemplateNotification = createTemplateNotification;
2369
2361
  exports.createWindowsBadgeNotification = createWindowsBadgeNotification;
2370
2362
  exports.createWindowsInstallation = createWindowsInstallation;