@azure/notification-hubs 1.0.4-alpha.20240213.1 → 1.1.0-alpha.20240220.1

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 (29) hide show
  1. package/README.md +2 -2
  2. package/dist/index.cjs +102 -49
  3. package/dist/index.cjs.map +1 -1
  4. package/dist-esm/src/api/beginSubmitNotificationHubJob.js +26 -42
  5. package/dist-esm/src/api/beginSubmitNotificationHubJob.js.map +1 -1
  6. package/dist-esm/src/models/installation.js +8 -0
  7. package/dist-esm/src/models/installation.js.map +1 -1
  8. package/dist-esm/src/models/notification.js +9 -0
  9. package/dist-esm/src/models/notification.js.map +1 -1
  10. package/dist-esm/src/models/notificationBodyBuilder.js +8 -0
  11. package/dist-esm/src/models/notificationBodyBuilder.js.map +1 -1
  12. package/dist-esm/src/models/registration.js +16 -0
  13. package/dist-esm/src/models/registration.js.map +1 -1
  14. package/dist-esm/src/serializers/registrationSerializer.js +28 -2
  15. package/dist-esm/src/serializers/registrationSerializer.js.map +1 -1
  16. package/package.json +15 -16
  17. package/types/latest/notification-hubs.d.ts +485 -4
  18. package/types/latest/tsdoc-metadata.json +1 -1
  19. package/types/src/api/beginSubmitNotificationHubJob.d.ts.map +1 -1
  20. package/types/src/models/installation.d.ts +16 -1
  21. package/types/src/models/installation.d.ts.map +1 -1
  22. package/types/src/models/notification.d.ts +29 -1
  23. package/types/src/models/notification.d.ts.map +1 -1
  24. package/types/src/models/notificationBodyBuilder.d.ts +357 -0
  25. package/types/src/models/notificationBodyBuilder.d.ts.map +1 -1
  26. package/types/src/models/registration.d.ts +60 -3
  27. package/types/src/models/registration.d.ts.map +1 -1
  28. package/types/src/serializers/registrationSerializer.d.ts +21 -1
  29. package/types/src/serializers/registrationSerializer.d.ts.map +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Azure Notification Hubs SDK for JavaScript
2
2
 
3
- Azure Notification Hubs provide a scaled-out push engine that enables you to send notifications to any platform (Apple, Amazon Kindle, Android, Baidu, Xiaomi, Web, Windows, etc.) from any back-end (cloud or on-premises). Notification Hubs works well for both enterprise and consumer scenarios. Here are a few example scenarios:
3
+ Azure Notification Hubs provide a scaled-out push engine that enables you to send notifications to any platform (Apple, Amazon Kindle, Firebase, Baidu, Xiaomi, Web, Windows, etc.) from any back-end (cloud or on-premises). Notification Hubs works well for both enterprise and consumer scenarios. Here are a few example scenarios:
4
4
 
5
5
  - Send breaking news notifications to millions with low latency.
6
6
  - Send location-based coupons to interested user segments.
@@ -735,7 +735,7 @@ This module's tests are a mixture of live and unit tests, which require you to h
735
735
  `NOTIFICATIONHUBS_CONNECTION_STRING=connection string for your Notification Hubs instance`
736
736
  `NOTIFICATION_HUB_NAME=Notification Hub name`
737
737
  4. `cd sdk\notificationhubs\notification-hubs`
738
- 5. `npm run test`.
738
+ 5. `rushx test`.
739
739
 
740
740
  View our [tests](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/notificationhubs/notification-hubs/test)
741
741
  folder for more details.
package/dist/index.cjs CHANGED
@@ -5,11 +5,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var coreRestPipeline = require('@azure/core-rest-pipeline');
6
6
  var crypto = require('crypto');
7
7
  var coreClient = require('@azure-rest/core-client');
8
- var abortController = require('@azure/abort-controller');
8
+ var coreUtil = require('@azure/core-util');
9
9
  var coreXml = require('@azure/core-xml');
10
10
  var coreTracing = require('@azure/core-tracing');
11
11
  var tslib = require('tslib');
12
- var coreUtil = require('@azure/core-util');
13
12
 
14
13
  // Copyright (c) Microsoft Corporation.
15
14
  // Licensed under the MIT license.
@@ -658,8 +657,7 @@ async function beginSubmitNotificationHubJob(context, notificationHubJob, polled
658
657
  const progressCallbacks = new Map();
659
658
  const processProgressCallbacks = async () => progressCallbacks.forEach((h) => h(state));
660
659
  let resultPromise;
661
- let cancelJob;
662
- const abortController$1 = new abortController.AbortController();
660
+ const abortController = new AbortController();
663
661
  const currentPollIntervalInMs = (_a = polledOperationOptions.updateIntervalInMs) !== null && _a !== void 0 ? _a : 2000;
664
662
  const poller = {
665
663
  async poll(options) {
@@ -686,33 +684,39 @@ async function beginSubmitNotificationHubJob(context, notificationHubJob, polled
686
684
  pollUntilDone(pollOptions) {
687
685
  return (resultPromise !== null && resultPromise !== void 0 ? resultPromise : (resultPromise = (async () => {
688
686
  const { abortSignal: inputAbortSignal } = pollOptions || {};
689
- const { signal: abortSignal } = inputAbortSignal
690
- ? new abortController.AbortController([inputAbortSignal, abortController$1.signal])
691
- : abortController$1;
692
- if (!poller.isDone()) {
693
- await poller.poll({ abortSignal });
694
- while (!poller.isDone()) {
695
- const delay = sleep(currentPollIntervalInMs, abortSignal);
696
- cancelJob = () => abortController$1.abort();
697
- await delay;
687
+ // In the future we can use AbortSignal.any() instead
688
+ function abortListener() {
689
+ abortController.abort();
690
+ }
691
+ const abortSignal = abortController.signal;
692
+ if (inputAbortSignal === null || inputAbortSignal === void 0 ? void 0 : inputAbortSignal.aborted) {
693
+ abortController.abort();
694
+ }
695
+ else if (!abortSignal.aborted) {
696
+ inputAbortSignal === null || inputAbortSignal === void 0 ? void 0 : inputAbortSignal.addEventListener("abort", abortListener, { once: true });
697
+ }
698
+ try {
699
+ if (!poller.isDone()) {
698
700
  await poller.poll({ abortSignal });
701
+ while (!poller.isDone()) {
702
+ await coreUtil.delay(currentPollIntervalInMs, { abortSignal });
703
+ await poller.poll({ abortSignal });
704
+ }
699
705
  }
700
706
  }
707
+ finally {
708
+ inputAbortSignal === null || inputAbortSignal === void 0 ? void 0 : inputAbortSignal.removeEventListener("abort", abortListener);
709
+ }
701
710
  switch (state.status) {
702
- case "succeeded": {
711
+ case "succeeded":
703
712
  return poller.getResult();
704
- }
705
- case "canceled": {
713
+ case "canceled":
706
714
  throw new Error("Operation was canceled");
707
- }
708
- case "failed": {
715
+ case "failed":
709
716
  throw state.error;
710
- }
711
717
  case "notStarted":
712
- case "running": {
713
- // Unreachable
714
- throw new Error(`polling completed without succeeding or failing`);
715
- }
718
+ case "running":
719
+ throw new Error(`Polling completed without succeeding or failing`);
716
720
  }
717
721
  })().finally(() => {
718
722
  resultPromise = undefined;
@@ -727,8 +731,7 @@ async function beginSubmitNotificationHubJob(context, notificationHubJob, polled
727
731
  return ["succeeded", "failed", "canceled"].includes(state.status);
728
732
  },
729
733
  stopPolling() {
730
- abortController$1.abort();
731
- cancelJob === null || cancelJob === void 0 ? void 0 : cancelJob();
734
+ abortController.abort();
732
735
  },
733
736
  isStopped() {
734
737
  return resultPromise === undefined;
@@ -745,28 +748,6 @@ async function beginSubmitNotificationHubJob(context, notificationHubJob, polled
745
748
  };
746
749
  return poller;
747
750
  }
748
- const REJECTED_ERR = new Error("The operation has been aborted");
749
- function sleep(ms, signal) {
750
- return new Promise((resolve, reject) => {
751
- if (signal.aborted) {
752
- reject(REJECTED_ERR);
753
- return;
754
- }
755
- const id = setTimeout(() => {
756
- signal.removeEventListener("abort", onAbort);
757
- if (signal.aborted) {
758
- reject(REJECTED_ERR);
759
- return;
760
- }
761
- resolve();
762
- }, ms);
763
- signal.addEventListener("abort", onAbort, { once: true });
764
- function onAbort() {
765
- clearTimeout(id);
766
- reject(REJECTED_ERR);
767
- }
768
- });
769
- }
770
751
 
771
752
  // Copyright (c) Microsoft Corporation.
772
753
  // Licensed under the MIT license.
@@ -913,6 +894,20 @@ const registrationDescriptionParser = {
913
894
  createBrowserTemplateRegistrationDescription(rawRegistrationDescription) {
914
895
  return Object.assign(Object.assign(Object.assign({}, this.createBrowserRegistrationDescription(rawRegistrationDescription)), createTemplateRegistrationDescription(rawRegistrationDescription)), { kind: "BrowserTemplate" });
915
896
  },
897
+ /**
898
+ * @internal
899
+ * Creates an GCM registration description from incoming XML property bag.
900
+ */
901
+ createFcmV1RegistrationDescription(rawRegistrationDescription) {
902
+ return Object.assign(Object.assign({ fcmV1RegistrationId: getString(rawRegistrationDescription["FcmV1RegistrationId"], "fcmV1RegistrationId") }, createRegistrationDescription(rawRegistrationDescription)), { kind: "FcmV1" });
903
+ },
904
+ /**
905
+ * @internal
906
+ * Creates an FCM template registration description from incoming XML property bag.
907
+ */
908
+ createFcmV1TemplateRegistrationDescription(rawRegistrationDescription) {
909
+ return Object.assign(Object.assign(Object.assign({}, this.createFcmV1RegistrationDescription(rawRegistrationDescription)), createTemplateRegistrationDescription(rawRegistrationDescription)), { kind: "FcmV1Template" });
910
+ },
916
911
  /**
917
912
  * @internal
918
913
  * Creates an GCM registration description from incoming XML property bag.
@@ -1084,7 +1079,20 @@ const registrationDescriptionSerializer = {
1084
1079
  },
1085
1080
  /**
1086
1081
  * @internal
1087
- * @deprecated Should use FCM registrations instead of GCM.
1082
+ * Serializes an existing FCM V1 registration description to an object for serialization.
1083
+ */
1084
+ serializeFcmV1RegistrationDescription(description) {
1085
+ return Object.assign(Object.assign({}, serializeRegistrationDescription(description)), { FcmV1RegistrationId: getString(description.fcmV1RegistrationId, "fcmRegistrationId") });
1086
+ },
1087
+ /**
1088
+ * @internal
1089
+ * Serializes an existing FCM V1 template registration description to an object for serialization.
1090
+ */
1091
+ serializeFcmV1TemplateRegistrationDescription(description) {
1092
+ return Object.assign(Object.assign({}, this.serializeFcmV1RegistrationDescription(description)), serializeTemplateRegistrationDescription(description));
1093
+ },
1094
+ /**
1095
+ * @internal
1088
1096
  * Serializes an existing GCM registration description to an object for serialization.
1089
1097
  */
1090
1098
  serializeGcmRegistrationDescription(description) {
@@ -1092,7 +1100,6 @@ const registrationDescriptionSerializer = {
1092
1100
  },
1093
1101
  /**
1094
1102
  * @internal
1095
- * @deprecated Should use FCM template registrations instead of GCM.
1096
1103
  * Serializes an existing GCM template registration description to an object for serialization.
1097
1104
  */
1098
1105
  serializeGcmTemplateRegistrationDescription(description) {
@@ -2154,6 +2161,14 @@ function createBaiduInstallation(installation) {
2154
2161
  function createFcmLegacyInstallation(installation) {
2155
2162
  return Object.assign(Object.assign({}, installation), { platform: "gcm" });
2156
2163
  }
2164
+ /**
2165
+ * Creates an Firebase V1 Cloud Messaging based installation.
2166
+ * @param installation - A partial installation used to create the Firebase V1 Cloud Messaging installation.
2167
+ * @returns The newly created Firebase V1 Cloud Messaging installation.
2168
+ */
2169
+ function createFcmV1Installation(installation) {
2170
+ return Object.assign(Object.assign({}, installation), { platform: "fcmv1" });
2171
+ }
2157
2172
  /**
2158
2173
  * Creates a Xiaomi based installation.
2159
2174
  * @param installation - A partial installation used to create the Xiaomi installation.
@@ -2227,6 +2242,15 @@ function createFcmLegacyNotification(notification) {
2227
2242
  const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);
2228
2243
  return Object.assign(Object.assign({}, notification), { body, platform: "gcm", contentType: JSON_CONTENT_TYPE });
2229
2244
  }
2245
+ /**
2246
+ * Creates a notification to send to Firebase.
2247
+ * @param notification - A partial message used to create a message for Firebase.
2248
+ * @returns A newly created Firebase notification.
2249
+ */
2250
+ function createFcmV1Notification(notification) {
2251
+ const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);
2252
+ return Object.assign(Object.assign({}, notification), { body, platform: "fcmv1", contentType: JSON_CONTENT_TYPE });
2253
+ }
2230
2254
  /**
2231
2255
  * Creates a notification to send to Xiaomi.
2232
2256
  * @param notification - A partial message used to create a message for Xiaomi.
@@ -2348,6 +2372,14 @@ function createAppleNotificationBody(nativeMessage) {
2348
2372
  function createFirebaseLegacyNotificationBody(nativeMessage) {
2349
2373
  return JSON.stringify(nativeMessage);
2350
2374
  }
2375
+ /**
2376
+ * Creates a FcmV1Notification from a native Firebase payload.
2377
+ * @param nativeMessage - The native message payload to send to Notification Hubs.
2378
+ * @returns The JSON body to send to Notification Hubs.
2379
+ */
2380
+ function createFirebaseV1NotificationBody(nativeMessage) {
2381
+ return JSON.stringify(nativeMessage);
2382
+ }
2351
2383
  /**
2352
2384
  * Creates a AdmNotification from a native ADM payload.
2353
2385
  * @param nativeMessage - The native message payload to send to Notification Hubs.
@@ -2458,6 +2490,22 @@ function createFcmLegacyRegistrationDescription(description) {
2458
2490
  function createFcmLegacyTemplateRegistrationDescription(description) {
2459
2491
  return Object.assign(Object.assign({}, description), { kind: "GcmTemplate" });
2460
2492
  }
2493
+ /**
2494
+ * Creates a Firebase V1 registration description.
2495
+ * @param description - A partial FCM V1 registration description.
2496
+ * @returns A created FCM V1 registration description.
2497
+ */
2498
+ function createFcmV1RegistrationDescription(description) {
2499
+ return Object.assign(Object.assign({}, description), { kind: "FcmV1" });
2500
+ }
2501
+ /**
2502
+ * Creates a FCM V1 template registration description.
2503
+ * @param description - A partial FCM V1 template registration description.
2504
+ * @returns A created FCM V1 template registration description.
2505
+ */
2506
+ function createFcmV1TemplateRegistrationDescription(description) {
2507
+ return Object.assign(Object.assign({}, description), { kind: "FcmV1Template" });
2508
+ }
2461
2509
  /**
2462
2510
  * Creates a Windows registration description.
2463
2511
  * @param description - A partial Windows registration description.
@@ -2526,7 +2574,12 @@ exports.createFcmLegacyInstallation = createFcmLegacyInstallation;
2526
2574
  exports.createFcmLegacyNotification = createFcmLegacyNotification;
2527
2575
  exports.createFcmLegacyRegistrationDescription = createFcmLegacyRegistrationDescription;
2528
2576
  exports.createFcmLegacyTemplateRegistrationDescription = createFcmLegacyTemplateRegistrationDescription;
2577
+ exports.createFcmV1Installation = createFcmV1Installation;
2578
+ exports.createFcmV1Notification = createFcmV1Notification;
2579
+ exports.createFcmV1RegistrationDescription = createFcmV1RegistrationDescription;
2580
+ exports.createFcmV1TemplateRegistrationDescription = createFcmV1TemplateRegistrationDescription;
2529
2581
  exports.createFirebaseLegacyNotificationBody = createFirebaseLegacyNotificationBody;
2582
+ exports.createFirebaseV1NotificationBody = createFirebaseV1NotificationBody;
2530
2583
  exports.createTagExpression = createTagExpression;
2531
2584
  exports.createTemplateNotification = createTemplateNotification;
2532
2585
  exports.createWindowsBadgeNotification = createWindowsBadgeNotification;