@azure/notification-hubs 1.0.0-beta.7 → 1.0.0
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.
- package/README.md +4 -3
- package/dist/index.cjs +80 -3
- package/dist/index.cjs.map +1 -1
- package/dist-esm/src/api/createRegistrationId.js +8 -0
- package/dist-esm/src/api/createRegistrationId.js.map +1 -1
- package/dist-esm/src/models/installation.js +8 -0
- package/dist-esm/src/models/installation.js.map +1 -1
- package/dist-esm/src/models/notification.js +9 -1
- package/dist-esm/src/models/notification.js.map +1 -1
- package/dist-esm/src/models/notificationDetails.js.map +1 -1
- package/dist-esm/src/models/registration.js +16 -0
- package/dist-esm/src/models/registration.js.map +1 -1
- package/dist-esm/src/serializers/notificationDetailsSerializer.js +6 -1
- package/dist-esm/src/serializers/notificationDetailsSerializer.js.map +1 -1
- package/dist-esm/src/serializers/registrationSerializer.js +29 -0
- package/dist-esm/src/serializers/registrationSerializer.js.map +1 -1
- package/dist-esm/src/utils/constants.js +1 -1
- package/dist-esm/src/utils/constants.js.map +1 -1
- package/package.json +25 -12
- package/types/3.1/notification-hubs.d.ts +97 -6
- package/types/latest/notification-hubs.d.ts +108 -6
- package/types/latest/tsdoc-metadata.json +1 -1
- package/types/src/api/createRegistrationId.d.ts.map +1 -1
- package/types/src/models/installation.d.ts +16 -1
- package/types/src/models/installation.d.ts.map +1 -1
- package/types/src/models/notification.d.ts +17 -2
- package/types/src/models/notification.d.ts.map +1 -1
- package/types/src/models/notificationDetails.d.ts +4 -0
- package/types/src/models/notificationDetails.d.ts.map +1 -1
- package/types/src/models/registration.d.ts +60 -3
- package/types/src/models/registration.d.ts.map +1 -1
- package/types/src/serializers/notificationDetailsSerializer.d.ts.map +1 -1
- package/types/src/serializers/registrationSerializer.d.ts +21 -1
- package/types/src/serializers/registrationSerializer.d.ts.map +1 -1
- package/types/src/utils/constants.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, 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, 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:
|
|
4
4
|
|
|
5
5
|
- Send breaking news notifications to millions with low latency.
|
|
6
6
|
- Send location-based coupons to interested user segments.
|
|
@@ -53,7 +53,7 @@ This SDK for JavaScript offers two ways of interacting with Azure Notification H
|
|
|
53
53
|
|
|
54
54
|
```typescript
|
|
55
55
|
import {
|
|
56
|
-
|
|
56
|
+
NotificationHubsClient,
|
|
57
57
|
createAppleInstallation
|
|
58
58
|
} from "@azure/notification-hubs";
|
|
59
59
|
|
|
@@ -81,6 +81,7 @@ The above code snippet then becomes the following:
|
|
|
81
81
|
|
|
82
82
|
```typescript
|
|
83
83
|
import { createClientContext, createOrUpdateInstallation } from "@azure/notification-hubs/api";
|
|
84
|
+
import { createAppleInstallation } from "@azure/notification-hubs/models";
|
|
84
85
|
|
|
85
86
|
const context = createClientContext("<connection string>", "<hub name>");
|
|
86
87
|
|
|
@@ -193,7 +194,7 @@ Using the modular approach, the code would be as follows:
|
|
|
193
194
|
|
|
194
195
|
```typescript
|
|
195
196
|
import { createClientContext, updateInstallation } from "@azure/notification-hubs/api";
|
|
196
|
-
import { JsonPatch
|
|
197
|
+
import { JsonPatch } from "@azure/notification-hubs/models";
|
|
197
198
|
|
|
198
199
|
const context = createClientContext("<connection string>", "<hub name>");
|
|
199
200
|
|
package/dist/index.cjs
CHANGED
|
@@ -14,7 +14,7 @@ var uuid = require('uuid');
|
|
|
14
14
|
|
|
15
15
|
// Copyright (c) Microsoft Corporation.
|
|
16
16
|
// Licensed under the MIT license.
|
|
17
|
-
const SDK_VERSION = "1.0.0
|
|
17
|
+
const SDK_VERSION = "1.0.0";
|
|
18
18
|
const JSON_CONTENT_TYPE = "application/json;charset=utf-8";
|
|
19
19
|
const XML_CONTENT_TYPE = "application/xml";
|
|
20
20
|
const STREAM_CONTENT_TYPE = "application/octet-stream";
|
|
@@ -771,6 +771,7 @@ const registrationDescriptionParser = {
|
|
|
771
771
|
*/
|
|
772
772
|
async parseRegistrationEntry(bodyText) {
|
|
773
773
|
const xml = await coreXml.parseXML(bodyText, { includeRoot: true });
|
|
774
|
+
delete xml.entry.content["$"];
|
|
774
775
|
const keyName = Object.keys(xml.entry.content)[0];
|
|
775
776
|
const content = xml.entry.content[keyName];
|
|
776
777
|
const methodName = `create${keyName}`;
|
|
@@ -890,6 +891,20 @@ const registrationDescriptionParser = {
|
|
|
890
891
|
var _a;
|
|
891
892
|
return Object.assign(Object.assign(Object.assign({ mpnsHeaders: getHeadersOrUndefined((_a = rawRegistrationDescription["MpnsHeaders"]) === null || _a === void 0 ? void 0 : _a["MpnsHeader"]) }, this.createWindowsRegistrationDescription(rawRegistrationDescription)), createTemplateRegistrationDescription(rawRegistrationDescription)), { kind: "MpnsTemplate" });
|
|
892
893
|
},
|
|
894
|
+
/**
|
|
895
|
+
* @internal
|
|
896
|
+
* Creates a Xiaomi registration description from incoming XML property bag.
|
|
897
|
+
*/
|
|
898
|
+
createXiaomiRegistrationDescription(rawRegistrationDescription) {
|
|
899
|
+
return Object.assign(Object.assign({ xiaomiRegistrationId: getString(rawRegistrationDescription["XiaomiRegistrationId"], "xiaomiRegistrationId") }, createRegistrationDescription(rawRegistrationDescription)), { kind: "Xiaomi" });
|
|
900
|
+
},
|
|
901
|
+
/**
|
|
902
|
+
* @internal
|
|
903
|
+
* Creates a Xiaomi template registration description from incoming XML property bag.
|
|
904
|
+
*/
|
|
905
|
+
createXiaomiTemplateRegistrationDescription(rawRegistrationDescription) {
|
|
906
|
+
return Object.assign(Object.assign(Object.assign({}, this.createXiaomiRegistrationDescription(rawRegistrationDescription)), createTemplateRegistrationDescription(rawRegistrationDescription)), { kind: "XiaomiTemplate" });
|
|
907
|
+
},
|
|
893
908
|
/**
|
|
894
909
|
* @internal
|
|
895
910
|
* Creates a Windows registration description from incoming XML property bag.
|
|
@@ -1060,6 +1075,20 @@ const registrationDescriptionSerializer = {
|
|
|
1060
1075
|
}
|
|
1061
1076
|
return Object.assign(Object.assign(Object.assign({}, this.serializeMpnsRegistrationDescription(description)), serializeTemplateRegistrationDescription(description)), { MpnsHeaders: mpnsHeaders });
|
|
1062
1077
|
},
|
|
1078
|
+
/**
|
|
1079
|
+
* @internal
|
|
1080
|
+
* Serializes an existing Xiaomi registration description to an object for serialization.
|
|
1081
|
+
*/
|
|
1082
|
+
serializeXiaomiRegistrationDescription(description) {
|
|
1083
|
+
return Object.assign(Object.assign({}, serializeRegistrationDescription(description)), { XiaomiRegistrationId: getString(description.xiaomiRegistrationId, "xiaomiRegistrationId") });
|
|
1084
|
+
},
|
|
1085
|
+
/**
|
|
1086
|
+
* @internal
|
|
1087
|
+
* Serializes an existing Xiaomi template registration description to an object for serialization.
|
|
1088
|
+
*/
|
|
1089
|
+
serializeXiaomiTemplateRegistrationDescription(description) {
|
|
1090
|
+
return Object.assign(Object.assign({}, this.serializeXiaomiRegistrationDescription(description)), serializeTemplateRegistrationDescription(description));
|
|
1091
|
+
},
|
|
1063
1092
|
/**
|
|
1064
1093
|
* @internal
|
|
1065
1094
|
* Serializes an existing Windows registration description to an object for serialization.
|
|
@@ -1190,6 +1219,13 @@ function createRegistrationId(context, options = {}) {
|
|
|
1190
1219
|
const response = await sendRequest(context, request, 201);
|
|
1191
1220
|
// In the form: https://{namespace}.servicebus.windows.net/{NotificationHub}/registrations/<registrationId>
|
|
1192
1221
|
const locationHeader = response.headers.get("Location");
|
|
1222
|
+
if (!locationHeader || !locationHeader.startsWith("https://")) {
|
|
1223
|
+
throw new coreRestPipeline.RestError(`Location header ${locationHeader} is an invalid URL`, {
|
|
1224
|
+
statusCode: 500,
|
|
1225
|
+
request,
|
|
1226
|
+
response,
|
|
1227
|
+
});
|
|
1228
|
+
}
|
|
1193
1229
|
const locationUrl = new URL(locationHeader);
|
|
1194
1230
|
const registrationId = locationUrl.pathname.split("/")[3];
|
|
1195
1231
|
return registrationId;
|
|
@@ -1288,7 +1324,6 @@ function getInstallation(context, installationId, options = {}) {
|
|
|
1288
1324
|
async function parseNotificationDetails(bodyText) {
|
|
1289
1325
|
const xml = await coreXml.parseXML(bodyText, {
|
|
1290
1326
|
includeRoot: true,
|
|
1291
|
-
stopNodes: ["NotificationDetails.NotificationBody"],
|
|
1292
1327
|
});
|
|
1293
1328
|
const notificationDetails = xml["NotificationDetails"];
|
|
1294
1329
|
let apnsOutcomeCounts;
|
|
@@ -1307,6 +1342,10 @@ async function parseNotificationDetails(bodyText) {
|
|
|
1307
1342
|
if (isDefined(notificationDetails["GcmOutcomeCounts"])) {
|
|
1308
1343
|
fcmOutcomeCounts = parseOutcomeCounts(notificationDetails["GcmOutcomeCounts"]["Outcome"]);
|
|
1309
1344
|
}
|
|
1345
|
+
let xiaomiOutcomeCounts;
|
|
1346
|
+
if (isDefined(notificationDetails["XiaomiOutcomeCounts"])) {
|
|
1347
|
+
xiaomiOutcomeCounts = parseOutcomeCounts(notificationDetails["XiaomiOutcomeCounts"]["Outcome"]);
|
|
1348
|
+
}
|
|
1310
1349
|
let wnsOutcomeCounts;
|
|
1311
1350
|
if (isDefined(notificationDetails["WnsOutcomeCounts"])) {
|
|
1312
1351
|
wnsOutcomeCounts = parseOutcomeCounts(notificationDetails["WnsOutcomeCounts"]["Outcome"]);
|
|
@@ -1320,10 +1359,12 @@ async function parseNotificationDetails(bodyText) {
|
|
|
1320
1359
|
endTime: getDateOrUndefined(notificationDetails["EndTime"]),
|
|
1321
1360
|
pnsErrorDetailsUrl: getStringOrUndefined(notificationDetails["PnsErrorDetailsUri"]),
|
|
1322
1361
|
targetPlatforms: getStringOrUndefined(notificationDetails["TargetPlatforms"]),
|
|
1362
|
+
notificationBody: getStringOrUndefined(notificationDetails["NotificationBody"]),
|
|
1323
1363
|
apnsOutcomeCounts,
|
|
1324
1364
|
admOutcomeCounts,
|
|
1325
1365
|
baiduOutcomeCounts,
|
|
1326
1366
|
fcmOutcomeCounts,
|
|
1367
|
+
xiaomiOutcomeCounts,
|
|
1327
1368
|
wnsOutcomeCounts,
|
|
1328
1369
|
};
|
|
1329
1370
|
}
|
|
@@ -2078,6 +2119,14 @@ function createBaiduInstallation(installation) {
|
|
|
2078
2119
|
function createFcmLegacyInstallation(installation) {
|
|
2079
2120
|
return Object.assign(Object.assign({}, installation), { platform: "gcm" });
|
|
2080
2121
|
}
|
|
2122
|
+
/**
|
|
2123
|
+
* Creates a Xiaomi based installation.
|
|
2124
|
+
* @param installation - A partial installation used to create the Xiaomi installation.
|
|
2125
|
+
* @returns The newly created Xiaomi installation.
|
|
2126
|
+
*/
|
|
2127
|
+
function createXiaomiInstallation(installation) {
|
|
2128
|
+
return Object.assign(Object.assign({}, installation), { platform: "xiaomi" });
|
|
2129
|
+
}
|
|
2081
2130
|
/**
|
|
2082
2131
|
* Creates a Windows Notification Services (WNS) based installation.
|
|
2083
2132
|
* @param installation - A partial installation used to create the WNS installation.
|
|
@@ -2131,11 +2180,19 @@ function createBrowserNotification(notification) {
|
|
|
2131
2180
|
/**
|
|
2132
2181
|
* Creates a notification to send to Firebase.
|
|
2133
2182
|
* @param notification - A partial message used to create a message for Firebase.
|
|
2134
|
-
* @returns A newly created Firebase.
|
|
2183
|
+
* @returns A newly created Firebase notification.
|
|
2135
2184
|
*/
|
|
2136
2185
|
function createFcmLegacyNotification(notification) {
|
|
2137
2186
|
return Object.assign(Object.assign({}, notification), { platform: "gcm", contentType: JSON_CONTENT_TYPE });
|
|
2138
2187
|
}
|
|
2188
|
+
/**
|
|
2189
|
+
* Creates a notification to send to Xiaomi.
|
|
2190
|
+
* @param notification - A partial message used to create a message for Xiaomi.
|
|
2191
|
+
* @returns A newly created Xiaomi notification.
|
|
2192
|
+
*/
|
|
2193
|
+
function createXiaomiNotification(notification) {
|
|
2194
|
+
return Object.assign(Object.assign({}, notification), { platform: "xiaomi", contentType: JSON_CONTENT_TYPE });
|
|
2195
|
+
}
|
|
2139
2196
|
/**
|
|
2140
2197
|
* Creates a notification to send to Firebase.
|
|
2141
2198
|
* @param notification - A partial message used to create a message for Firebase.
|
|
@@ -2341,6 +2398,22 @@ function createWindowsRegistrationDescription(description) {
|
|
|
2341
2398
|
function createWindowsTemplateRegistrationDescription(description) {
|
|
2342
2399
|
return Object.assign(Object.assign({}, description), { kind: "WindowsTemplate" });
|
|
2343
2400
|
}
|
|
2401
|
+
/**
|
|
2402
|
+
* Creates a Xiaomi registration description.
|
|
2403
|
+
* @param description - A partial Xiaomi registration description.
|
|
2404
|
+
* @returns A created Xiaomi registration description.
|
|
2405
|
+
*/
|
|
2406
|
+
function createXiaomiRegistrationDescription(description) {
|
|
2407
|
+
return Object.assign(Object.assign({}, description), { kind: "Xiaomi" });
|
|
2408
|
+
}
|
|
2409
|
+
/**
|
|
2410
|
+
* Creates a Xiaomi template registration description.
|
|
2411
|
+
* @param description - A partial Xiaomi template registration description.
|
|
2412
|
+
* @returns A created Xiaomi template registration description.
|
|
2413
|
+
*/
|
|
2414
|
+
function createXiaomiTemplateRegistrationDescription(description) {
|
|
2415
|
+
return Object.assign(Object.assign({}, description), { kind: "XiaomiTemplate" });
|
|
2416
|
+
}
|
|
2344
2417
|
|
|
2345
2418
|
// Copyright (c) Microsoft Corporation.
|
|
2346
2419
|
// Licensed under the MIT license.
|
|
@@ -2388,4 +2461,8 @@ exports.createWindowsRegistrationDescription = createWindowsRegistrationDescript
|
|
|
2388
2461
|
exports.createWindowsTemplateRegistrationDescription = createWindowsTemplateRegistrationDescription;
|
|
2389
2462
|
exports.createWindowsTileNotification = createWindowsTileNotification;
|
|
2390
2463
|
exports.createWindowsToastNotification = createWindowsToastNotification;
|
|
2464
|
+
exports.createXiaomiInstallation = createXiaomiInstallation;
|
|
2465
|
+
exports.createXiaomiNotification = createXiaomiNotification;
|
|
2466
|
+
exports.createXiaomiRegistrationDescription = createXiaomiRegistrationDescription;
|
|
2467
|
+
exports.createXiaomiTemplateRegistrationDescription = createXiaomiTemplateRegistrationDescription;
|
|
2391
2468
|
//# sourceMappingURL=index.js.map
|