@azure/notification-hubs 1.0.2 → 1.0.3-alpha.20230703.2
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/dist/{index.cjs → index.js} +185 -108
- package/dist/index.js.map +1 -0
- package/dist-esm/src/api/clientContext.js +48 -0
- package/dist-esm/src/api/clientContext.js.map +1 -0
- package/dist-esm/src/api/index.js +1 -45
- package/dist-esm/src/api/index.js.map +1 -1
- package/dist-esm/src/api/scheduleNotification.js.map +1 -1
- package/dist-esm/src/api/sendNotification.js.map +1 -1
- package/dist-esm/src/auth/hmacSha256.browser.js +0 -1
- package/dist-esm/src/auth/hmacSha256.browser.js.map +1 -1
- package/dist-esm/src/index.js +2 -10
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/models/index.js +1 -0
- package/dist-esm/src/models/index.js.map +1 -1
- package/dist-esm/src/models/notification.js +46 -7
- package/dist-esm/src/models/notification.js.map +1 -1
- package/dist-esm/src/models/notificationBodyBuilder.js.map +1 -1
- package/dist-esm/src/models/notificationHeaderBuilder.js +4 -0
- package/dist-esm/src/models/notificationHeaderBuilder.js.map +1 -0
- package/dist-esm/src/notificationHubsClient.js +1 -1
- package/dist-esm/src/notificationHubsClient.js.map +1 -1
- package/dist-esm/src/utils/constants.js +1 -1
- package/dist-esm/src/utils/constants.js.map +1 -1
- package/dist-esm/src/utils/utils.js.map +1 -1
- package/package.json +15 -18
- package/types/3.1/notification-hubs.d.ts +171 -38
- package/types/latest/notification-hubs.d.ts +183 -40
- package/types/latest/tsdoc-metadata.json +1 -1
- package/types/src/api/clientContext.d.ts +41 -0
- package/types/src/api/clientContext.d.ts.map +1 -0
- package/types/src/api/index.d.ts +1 -39
- package/types/src/api/index.d.ts.map +1 -1
- package/types/src/api/internal/_client.d.ts +1 -0
- package/types/src/api/internal/_client.d.ts.map +1 -1
- package/types/src/api/scheduleNotification.d.ts.map +1 -1
- package/types/src/api/sendNotification.d.ts.map +1 -1
- package/types/src/auth/hmacSha256.browser.d.ts +18 -1
- package/types/src/auth/hmacSha256.browser.d.ts.map +1 -1
- package/types/src/index.d.ts +2 -10
- package/types/src/index.d.ts.map +1 -1
- package/types/src/models/index.d.ts +1 -0
- package/types/src/models/index.d.ts.map +1 -1
- package/types/src/models/notification.d.ts +69 -9
- package/types/src/models/notification.d.ts.map +1 -1
- package/types/src/models/notificationBodyBuilder.d.ts +29 -0
- package/types/src/models/notificationBodyBuilder.d.ts.map +1 -1
- package/types/src/models/notificationHeaderBuilder.d.ts +47 -0
- package/types/src/models/notificationHeaderBuilder.d.ts.map +1 -0
- package/types/src/utils/utils.d.ts +2 -0
- package/types/src/utils/utils.d.ts.map +1 -1
- package/dist/index.cjs.map +0 -1
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var coreRestPipeline = require('@azure/core-rest-pipeline');
|
|
6
4
|
var crypto = require('crypto');
|
|
7
5
|
var coreXml = require('@azure/core-xml');
|
|
@@ -13,7 +11,7 @@ var coreUtil = require('@azure/core-util');
|
|
|
13
11
|
|
|
14
12
|
// Copyright (c) Microsoft Corporation.
|
|
15
13
|
// Licensed under the MIT license.
|
|
16
|
-
const SDK_VERSION = "1.0.
|
|
14
|
+
const SDK_VERSION = "1.0.3";
|
|
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";
|
|
@@ -24,12 +22,14 @@ const WNS_TITLE = "wns/tile";
|
|
|
24
22
|
const WNS_TOAST = "wns/toast";
|
|
25
23
|
|
|
26
24
|
// Copyright (c) Microsoft Corporation.
|
|
25
|
+
// Licensed under the MIT license.
|
|
27
26
|
async function signString(key, toSign) {
|
|
28
27
|
const hmac = crypto.createHmac("sha256", key).update(toSign).digest("base64");
|
|
29
28
|
return encodeURIComponent(hmac);
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
// Copyright (c) Microsoft Corporation.
|
|
32
|
+
// Licensed under the MIT license.
|
|
33
33
|
/**
|
|
34
34
|
* Creates a token provider from the provided shared access data.
|
|
35
35
|
* @param data - The sharedAccessKeyName/sharedAccessKey pair or the sharedAccessSignature.
|
|
@@ -86,6 +86,7 @@ async function createToken(keyName, key, expiry, audience) {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
// Copyright (c) Microsoft Corporation.
|
|
89
|
+
// Licensed under the MIT license.
|
|
89
90
|
/**
|
|
90
91
|
* Parses the connection string and returns an object of type T.
|
|
91
92
|
*
|
|
@@ -156,6 +157,49 @@ function parseNotificationHubsConnectionString(connectionString) {
|
|
|
156
157
|
return output;
|
|
157
158
|
}
|
|
158
159
|
|
|
160
|
+
// Copyright (c) Microsoft Corporation.
|
|
161
|
+
// Licensed under the MIT license.
|
|
162
|
+
const API_VERSION = "2020-06";
|
|
163
|
+
/**
|
|
164
|
+
* Creates a NotificationHubClient from the Access Policy connection string and hub name.
|
|
165
|
+
* @param connectionString - The Access Policy connection string for the notification hub.
|
|
166
|
+
* @param hubName - The notification hub name.
|
|
167
|
+
* @returns A NotificationHubsClientContext initialized from the connection string and hub name.
|
|
168
|
+
*/
|
|
169
|
+
function createClientContext(connectionString, hubName, options = {}) {
|
|
170
|
+
return new NotificationHubsServiceClient(connectionString, hubName, options);
|
|
171
|
+
}
|
|
172
|
+
class NotificationHubsServiceClient extends coreClient.ServiceClient {
|
|
173
|
+
constructor(connectionString, hubName, options = {}) {
|
|
174
|
+
super(Object.assign({ deserializationOptions: {
|
|
175
|
+
parseXML: coreXml.parseXML,
|
|
176
|
+
}, serializationOptions: {
|
|
177
|
+
stringifyXML: coreXml.stringifyXML,
|
|
178
|
+
}, userAgentOptions: {
|
|
179
|
+
userAgentPrefix: `azsdk-js-messaging-notificationhubs/${SDK_VERSION}`,
|
|
180
|
+
} }, options));
|
|
181
|
+
this.hubName = hubName;
|
|
182
|
+
const parsedConnection = parseNotificationHubsConnectionString(connectionString);
|
|
183
|
+
this.baseUrl = parsedConnection.endpoint;
|
|
184
|
+
this.sasTokenProvider = createTokenProviderFromConnection(parsedConnection.sharedAccessKey, parsedConnection.sharedAccessKeyName);
|
|
185
|
+
}
|
|
186
|
+
async createHeaders(operationName, rawHeaders) {
|
|
187
|
+
const authorization = await this.sasTokenProvider.getToken(this.baseUrl);
|
|
188
|
+
const headers = coreRestPipeline.createHttpHeaders(rawHeaders);
|
|
189
|
+
headers.set("Authorization", authorization.token);
|
|
190
|
+
headers.set("x-ms-version", API_VERSION);
|
|
191
|
+
headers.set("x-ms-azsdk-telemetry", `class=NotificationHubsServiceClient;method=${operationName}`);
|
|
192
|
+
return headers;
|
|
193
|
+
}
|
|
194
|
+
requestUrl() {
|
|
195
|
+
// Node doesn't allow change in protocol but browsers do, so doing a string replace
|
|
196
|
+
const url = new URL(this.baseUrl.replace("sb://", "https://"));
|
|
197
|
+
url.pathname = this.hubName;
|
|
198
|
+
url.searchParams.set("api-version", API_VERSION);
|
|
199
|
+
return url;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
159
203
|
// Copyright (c) Microsoft Corporation.
|
|
160
204
|
// Licensed under the MIT license.
|
|
161
205
|
/**
|
|
@@ -256,6 +300,7 @@ function getTagsOrUndefined(value) {
|
|
|
256
300
|
}
|
|
257
301
|
|
|
258
302
|
// Copyright (c) Microsoft Corporation.
|
|
303
|
+
// Licensed under the MIT license.
|
|
259
304
|
async function parseNotificationOutcome(bodyText) {
|
|
260
305
|
const xml = await coreXml.parseXML(bodyText, { includeRoot: true });
|
|
261
306
|
const outcome = xml.NotificationOutcome;
|
|
@@ -284,6 +329,7 @@ function parseRegistrationResults(results) {
|
|
|
284
329
|
}
|
|
285
330
|
|
|
286
331
|
// Copyright (c) Microsoft Corporation.
|
|
332
|
+
// Licensed under the MIT license.
|
|
287
333
|
/**
|
|
288
334
|
* Marker for atom metadata.
|
|
289
335
|
*
|
|
@@ -376,6 +422,7 @@ async function parseXMLError(bodyText) {
|
|
|
376
422
|
}
|
|
377
423
|
|
|
378
424
|
// Copyright (c) Microsoft Corporation.
|
|
425
|
+
// Licensed under the MIT license.
|
|
379
426
|
function createRequest(endpoint, method, headers, options) {
|
|
380
427
|
return coreRestPipeline.createPipelineRequest(Object.assign(Object.assign(Object.assign({}, options.tracingOptions), options.requestOptions), { url: endpoint.toString(), abortSignal: options.abortSignal, method,
|
|
381
428
|
headers }));
|
|
@@ -462,6 +509,7 @@ async function sendRequest(context, request, successStatusCode) {
|
|
|
462
509
|
}
|
|
463
510
|
|
|
464
511
|
// Copyright (c) Microsoft Corporation.
|
|
512
|
+
// Licensed under the MIT license.
|
|
465
513
|
/**
|
|
466
514
|
* @internal
|
|
467
515
|
* Serializes a NotificationHubJob into an Atom XML entry.
|
|
@@ -538,6 +586,7 @@ function createNotificationHubJob(content) {
|
|
|
538
586
|
}
|
|
539
587
|
|
|
540
588
|
// Copyright (c) Microsoft Corporation.
|
|
589
|
+
// Licensed under the MIT license.
|
|
541
590
|
/**
|
|
542
591
|
* A tracing client to handle spans.
|
|
543
592
|
* @internal
|
|
@@ -549,6 +598,7 @@ const tracingClient = coreTracing.createTracingClient({
|
|
|
549
598
|
});
|
|
550
599
|
|
|
551
600
|
// Copyright (c) Microsoft Corporation.
|
|
601
|
+
// Licensed under the MIT license.
|
|
552
602
|
const OPERATION_NAME$g = "getNotificationHubJob";
|
|
553
603
|
/**
|
|
554
604
|
* Gets a Notification Hub Job by the ID.
|
|
@@ -570,6 +620,7 @@ function getNotificationHubJob(context, jobId, options = {}) {
|
|
|
570
620
|
}
|
|
571
621
|
|
|
572
622
|
// Copyright (c) Microsoft Corporation.
|
|
623
|
+
// Licensed under the MIT license.
|
|
573
624
|
const OPERATION_NAME$f = "submitNotificationHubJob";
|
|
574
625
|
/**
|
|
575
626
|
* Submits a Notification Hub Job.
|
|
@@ -593,6 +644,7 @@ function submitNotificationHubJob(context, job, options = {}) {
|
|
|
593
644
|
}
|
|
594
645
|
|
|
595
646
|
// Copyright (c) Microsoft Corporation.
|
|
647
|
+
// Licensed under the MIT license.
|
|
596
648
|
/**
|
|
597
649
|
* Submits a Notification Hub job and creates a poller to poll for results.
|
|
598
650
|
* @param context - The Notification Hubs client.
|
|
@@ -720,6 +772,7 @@ function sleep(ms, signal) {
|
|
|
720
772
|
}
|
|
721
773
|
|
|
722
774
|
// Copyright (c) Microsoft Corporation.
|
|
775
|
+
// Licensed under the MIT license.
|
|
723
776
|
const OPERATION_NAME$e = "cancelScheduledNotification";
|
|
724
777
|
/**
|
|
725
778
|
* Cancels the scheduled notification with the given notification ID.
|
|
@@ -741,6 +794,7 @@ function cancelScheduledNotification(context, notificationId, options = {}) {
|
|
|
741
794
|
}
|
|
742
795
|
|
|
743
796
|
// Copyright (c) Microsoft Corporation.
|
|
797
|
+
// Licensed under the MIT license.
|
|
744
798
|
const OPERATION_NAME$d = "createOrUpdateInstallation";
|
|
745
799
|
/**
|
|
746
800
|
* Creates or overwrites an installation to a Notification Hub.
|
|
@@ -763,6 +817,7 @@ function createOrUpdateInstallation(context, installation, options = {}) {
|
|
|
763
817
|
}
|
|
764
818
|
|
|
765
819
|
// Copyright (c) Microsoft Corporation.
|
|
820
|
+
// Licensed under the MIT license.
|
|
766
821
|
const registrationDescriptionParser = {
|
|
767
822
|
/**
|
|
768
823
|
* @internal
|
|
@@ -1138,6 +1193,7 @@ function serializeTemplateRegistrationDescription(description) {
|
|
|
1138
1193
|
}
|
|
1139
1194
|
|
|
1140
1195
|
// Copyright (c) Microsoft Corporation.
|
|
1196
|
+
// Licensed under the MIT license.
|
|
1141
1197
|
/**
|
|
1142
1198
|
* @internal
|
|
1143
1199
|
*/
|
|
@@ -1165,6 +1221,7 @@ async function createOrUpdateRegistrationDescription(context, registration, oper
|
|
|
1165
1221
|
}
|
|
1166
1222
|
|
|
1167
1223
|
// Copyright (c) Microsoft Corporation.
|
|
1224
|
+
// Licensed under the MIT license.
|
|
1168
1225
|
const OPERATION_NAME$c = "createOrUpdateRegistration";
|
|
1169
1226
|
/**
|
|
1170
1227
|
* Creates or updates a registration.
|
|
@@ -1180,28 +1237,8 @@ function createOrUpdateRegistration(context, registration, options = {}) {
|
|
|
1180
1237
|
}
|
|
1181
1238
|
|
|
1182
1239
|
// Copyright (c) Microsoft Corporation.
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
* Creates a new registration. This method generates a registration ID,
|
|
1186
|
-
* which you can subsequently use to retrieve, update, and delete this registration.
|
|
1187
|
-
* @param context - The Notification Hubs client.
|
|
1188
|
-
* @param registration - The registration to create.
|
|
1189
|
-
* @param options - Options for creating a new registration.
|
|
1190
|
-
* @returns The newly created registration description.
|
|
1191
|
-
*/
|
|
1192
|
-
function createRegistration(context, registration, options = {}) {
|
|
1193
|
-
return tracingClient.withSpan(`NotificationHubsClientContext.${OPERATION_NAME$b}`, options, async (updatedOptions) => {
|
|
1194
|
-
if (registration.registrationId) {
|
|
1195
|
-
throw new coreRestPipeline.RestError("registrationId must not be set during a create operation", {
|
|
1196
|
-
statusCode: 400,
|
|
1197
|
-
});
|
|
1198
|
-
}
|
|
1199
|
-
return createOrUpdateRegistrationDescription(context, registration, "create", updatedOptions);
|
|
1200
|
-
});
|
|
1201
|
-
}
|
|
1202
|
-
|
|
1203
|
-
// Copyright (c) Microsoft Corporation.
|
|
1204
|
-
const OPERATION_NAME$a = "createRegistrationId";
|
|
1240
|
+
// Licensed under the MIT license.
|
|
1241
|
+
const OPERATION_NAME$b = "createRegistrationId";
|
|
1205
1242
|
/**
|
|
1206
1243
|
* Creates a new registration ID.
|
|
1207
1244
|
* @param context - The Notification Hubs client.
|
|
@@ -1209,10 +1246,10 @@ const OPERATION_NAME$a = "createRegistrationId";
|
|
|
1209
1246
|
* @returns The newly created registration ID.
|
|
1210
1247
|
*/
|
|
1211
1248
|
function createRegistrationId(context, options = {}) {
|
|
1212
|
-
return tracingClient.withSpan(`NotificationHubsClientContext.${OPERATION_NAME$
|
|
1249
|
+
return tracingClient.withSpan(`NotificationHubsClientContext.${OPERATION_NAME$b}`, options, async (updatedOptions) => {
|
|
1213
1250
|
const endpoint = context.requestUrl();
|
|
1214
1251
|
endpoint.pathname += "/registrationIDs";
|
|
1215
|
-
const headers = await context.createHeaders(OPERATION_NAME$
|
|
1252
|
+
const headers = await context.createHeaders(OPERATION_NAME$b);
|
|
1216
1253
|
headers.set("Content-Type", "application/xml;type=entry;charset=utf-8");
|
|
1217
1254
|
const request = createRequest(endpoint, "POST", headers, updatedOptions);
|
|
1218
1255
|
const response = await sendRequest(context, request, 201);
|
|
@@ -1232,6 +1269,29 @@ function createRegistrationId(context, options = {}) {
|
|
|
1232
1269
|
}
|
|
1233
1270
|
|
|
1234
1271
|
// Copyright (c) Microsoft Corporation.
|
|
1272
|
+
// Licensed under the MIT license.
|
|
1273
|
+
const OPERATION_NAME$a = "createRegistration";
|
|
1274
|
+
/**
|
|
1275
|
+
* Creates a new registration. This method generates a registration ID,
|
|
1276
|
+
* which you can subsequently use to retrieve, update, and delete this registration.
|
|
1277
|
+
* @param context - The Notification Hubs client.
|
|
1278
|
+
* @param registration - The registration to create.
|
|
1279
|
+
* @param options - Options for creating a new registration.
|
|
1280
|
+
* @returns The newly created registration description.
|
|
1281
|
+
*/
|
|
1282
|
+
function createRegistration(context, registration, options = {}) {
|
|
1283
|
+
return tracingClient.withSpan(`NotificationHubsClientContext.${OPERATION_NAME$a}`, options, async (updatedOptions) => {
|
|
1284
|
+
if (registration.registrationId) {
|
|
1285
|
+
throw new coreRestPipeline.RestError("registrationId must not be set during a create operation", {
|
|
1286
|
+
statusCode: 400,
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1289
|
+
return createOrUpdateRegistrationDescription(context, registration, "create", updatedOptions);
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
// Copyright (c) Microsoft Corporation.
|
|
1294
|
+
// Licensed under the MIT license.
|
|
1235
1295
|
const OPERATION_NAME$9 = "deleteInstallation";
|
|
1236
1296
|
/**
|
|
1237
1297
|
* Deletes an installation from a Notification Hub.
|
|
@@ -1252,6 +1312,7 @@ function deleteInstallation(context, installationId, options = {}) {
|
|
|
1252
1312
|
}
|
|
1253
1313
|
|
|
1254
1314
|
// Copyright (c) Microsoft Corporation.
|
|
1315
|
+
// Licensed under the MIT license.
|
|
1255
1316
|
const OPERATION_NAME$8 = "deleteRegistration";
|
|
1256
1317
|
/**
|
|
1257
1318
|
* Deletes a registration with the given registration ID.
|
|
@@ -1274,6 +1335,7 @@ function deleteRegistration(context, registrationId, options = {}) {
|
|
|
1274
1335
|
}
|
|
1275
1336
|
|
|
1276
1337
|
// Copyright (c) Microsoft Corporation.
|
|
1338
|
+
// Licensed under the MIT license.
|
|
1277
1339
|
const OPERATION_NAME$7 = "getFeedbackContainerUrl";
|
|
1278
1340
|
/**
|
|
1279
1341
|
* Retrieves an Azure Storage container URL. The container has feedback data for the notification hub.
|
|
@@ -1295,6 +1357,7 @@ function getFeedbackContainerUrl(context, options = {}) {
|
|
|
1295
1357
|
}
|
|
1296
1358
|
|
|
1297
1359
|
// Copyright (c) Microsoft Corporation.
|
|
1360
|
+
// Licensed under the MIT license.
|
|
1298
1361
|
const OPERATION_NAME$6 = "getInstallation";
|
|
1299
1362
|
/**
|
|
1300
1363
|
* Gets an Azure Notification Hub installation by the installation ID.
|
|
@@ -1316,6 +1379,7 @@ function getInstallation(context, installationId, options = {}) {
|
|
|
1316
1379
|
}
|
|
1317
1380
|
|
|
1318
1381
|
// Copyright (c) Microsoft Corporation.
|
|
1382
|
+
// Licensed under the MIT license.
|
|
1319
1383
|
/**
|
|
1320
1384
|
* @internal
|
|
1321
1385
|
* Parses a NotificationDetails from incoming XML.
|
|
@@ -1377,6 +1441,7 @@ function parseOutcomeCounts(counts) {
|
|
|
1377
1441
|
}
|
|
1378
1442
|
|
|
1379
1443
|
// Copyright (c) Microsoft Corporation.
|
|
1444
|
+
// Licensed under the MIT license.
|
|
1380
1445
|
const OPERATION_NAME$5 = "getNotificationOutcomeDetails";
|
|
1381
1446
|
/**
|
|
1382
1447
|
* Retrieves the results of a send operation. This can retrieve intermediate results if the send is being processed
|
|
@@ -1398,6 +1463,7 @@ function getNotificationOutcomeDetails(context, notificationId, options = {}) {
|
|
|
1398
1463
|
}
|
|
1399
1464
|
|
|
1400
1465
|
// Copyright (c) Microsoft Corporation.
|
|
1466
|
+
// Licensed under the MIT license.
|
|
1401
1467
|
const OPERATION_NAME$4 = "getRegistration";
|
|
1402
1468
|
/**
|
|
1403
1469
|
* Gets a registration by the given registration ID.
|
|
@@ -1419,6 +1485,7 @@ function getRegistration(context, registrationId, options = {}) {
|
|
|
1419
1485
|
}
|
|
1420
1486
|
|
|
1421
1487
|
// Copyright (c) Microsoft Corporation.
|
|
1488
|
+
// Licensed under the MIT license.
|
|
1422
1489
|
const OPERATION_NAME$3 = "listNotificationHubJobs";
|
|
1423
1490
|
/**
|
|
1424
1491
|
* Gets all Notification Hub Jobs for this Notification Hub.
|
|
@@ -1439,6 +1506,7 @@ function listNotificationHubJobs(context, options = {}) {
|
|
|
1439
1506
|
}
|
|
1440
1507
|
|
|
1441
1508
|
// Copyright (c) Microsoft Corporation.
|
|
1509
|
+
// Licensed under the MIT license.
|
|
1442
1510
|
function listRegistrationsAll(context, options) {
|
|
1443
1511
|
return tslib.__asyncGenerator(this, arguments, function* listRegistrationsAll_1() {
|
|
1444
1512
|
var _a, e_1, _b, _c;
|
|
@@ -1500,38 +1568,7 @@ async function _listRegistrations(context, options, continuationToken) {
|
|
|
1500
1568
|
}
|
|
1501
1569
|
|
|
1502
1570
|
// Copyright (c) Microsoft Corporation.
|
|
1503
|
-
|
|
1504
|
-
* Gets all registrations for the notification hub with the given query options.
|
|
1505
|
-
* @param context - The Notification Hubs client.
|
|
1506
|
-
* @param options - The options for querying the registrations such as $top.
|
|
1507
|
-
* @returns A paged async iterable containing all of the registrations for the notification hub.
|
|
1508
|
-
*/
|
|
1509
|
-
function listRegistrations(context, options = {}) {
|
|
1510
|
-
const { span, updatedOptions } = tracingClient.startSpan("NotificationHubsClientContext.listRegistrations", options);
|
|
1511
|
-
try {
|
|
1512
|
-
const iter = listRegistrationsAll(context, updatedOptions);
|
|
1513
|
-
return {
|
|
1514
|
-
next() {
|
|
1515
|
-
return iter.next();
|
|
1516
|
-
},
|
|
1517
|
-
[Symbol.asyncIterator]() {
|
|
1518
|
-
return this;
|
|
1519
|
-
},
|
|
1520
|
-
byPage: () => {
|
|
1521
|
-
return listRegistrationPagingPage(context, updatedOptions);
|
|
1522
|
-
},
|
|
1523
|
-
};
|
|
1524
|
-
}
|
|
1525
|
-
catch (e) {
|
|
1526
|
-
span.setStatus({ status: "error", error: e });
|
|
1527
|
-
throw e;
|
|
1528
|
-
}
|
|
1529
|
-
finally {
|
|
1530
|
-
span.end();
|
|
1531
|
-
}
|
|
1532
|
-
}
|
|
1533
|
-
|
|
1534
|
-
// Copyright (c) Microsoft Corporation.
|
|
1571
|
+
// Licensed under the MIT license.
|
|
1535
1572
|
/**
|
|
1536
1573
|
* Gets all registrations for the notification hub with the given device information and options.
|
|
1537
1574
|
* @param context - The Notification Hubs client.
|
|
@@ -1586,6 +1623,7 @@ function getFilterByChannel(device) {
|
|
|
1586
1623
|
}
|
|
1587
1624
|
|
|
1588
1625
|
// Copyright (c) Microsoft Corporation.
|
|
1626
|
+
// Licensed under the MIT license.
|
|
1589
1627
|
const OPERATION_NAME$2 = "listRegistrationsByTag";
|
|
1590
1628
|
/**
|
|
1591
1629
|
* Lists all registrations with the matching tag.
|
|
@@ -1676,6 +1714,40 @@ async function _listRegistrationsByTag(context, tag, options, continuationToken)
|
|
|
1676
1714
|
}
|
|
1677
1715
|
|
|
1678
1716
|
// Copyright (c) Microsoft Corporation.
|
|
1717
|
+
// Licensed under the MIT license.
|
|
1718
|
+
/**
|
|
1719
|
+
* Gets all registrations for the notification hub with the given query options.
|
|
1720
|
+
* @param context - The Notification Hubs client.
|
|
1721
|
+
* @param options - The options for querying the registrations such as $top.
|
|
1722
|
+
* @returns A paged async iterable containing all of the registrations for the notification hub.
|
|
1723
|
+
*/
|
|
1724
|
+
function listRegistrations(context, options = {}) {
|
|
1725
|
+
const { span, updatedOptions } = tracingClient.startSpan("NotificationHubsClientContext.listRegistrations", options);
|
|
1726
|
+
try {
|
|
1727
|
+
const iter = listRegistrationsAll(context, updatedOptions);
|
|
1728
|
+
return {
|
|
1729
|
+
next() {
|
|
1730
|
+
return iter.next();
|
|
1731
|
+
},
|
|
1732
|
+
[Symbol.asyncIterator]() {
|
|
1733
|
+
return this;
|
|
1734
|
+
},
|
|
1735
|
+
byPage: () => {
|
|
1736
|
+
return listRegistrationPagingPage(context, updatedOptions);
|
|
1737
|
+
},
|
|
1738
|
+
};
|
|
1739
|
+
}
|
|
1740
|
+
catch (e) {
|
|
1741
|
+
span.setStatus({ status: "error", error: e });
|
|
1742
|
+
throw e;
|
|
1743
|
+
}
|
|
1744
|
+
finally {
|
|
1745
|
+
span.end();
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
// Copyright (c) Microsoft Corporation.
|
|
1750
|
+
// Licensed under the MIT license.
|
|
1679
1751
|
/**
|
|
1680
1752
|
* Schedules a push notification to devices that match the given tags or tag expression at the specified time.
|
|
1681
1753
|
* NOTE: This is only available in Standard SKU Azure Notification Hubs.
|
|
@@ -1704,6 +1776,7 @@ function scheduleNotification(context, scheduledTime, notification, options = {}
|
|
|
1704
1776
|
}
|
|
1705
1777
|
|
|
1706
1778
|
// Copyright (c) Microsoft Corporation.
|
|
1779
|
+
// Licensed under the MIT license.
|
|
1707
1780
|
/**
|
|
1708
1781
|
* Determines whether the options are of type SendNotificationOptions.
|
|
1709
1782
|
* @param options - The options to test if SendNotificationOptions.
|
|
@@ -1741,6 +1814,7 @@ function createMultipartDirectNotification(boundaryName, notification, deviceHan
|
|
|
1741
1814
|
}
|
|
1742
1815
|
|
|
1743
1816
|
// Copyright (c) Microsoft Corporation.
|
|
1817
|
+
// Licensed under the MIT license.
|
|
1744
1818
|
/**
|
|
1745
1819
|
* Sends push notifications to devices that match the given tags or tag expression.
|
|
1746
1820
|
* @param context - The Notification Hubs client.
|
|
@@ -1798,6 +1872,7 @@ function sendNotification(context, notification, options = { enableTestSend: fal
|
|
|
1798
1872
|
}
|
|
1799
1873
|
|
|
1800
1874
|
// Copyright (c) Microsoft Corporation.
|
|
1875
|
+
// Licensed under the MIT license.
|
|
1801
1876
|
const OPERATION_NAME$1 = "updateInstallation";
|
|
1802
1877
|
/**
|
|
1803
1878
|
* Updates an installation using the JSON-Patch standard in RFC6902.
|
|
@@ -1821,6 +1896,7 @@ function updateInstallation(context, installationId, installationPatches, option
|
|
|
1821
1896
|
}
|
|
1822
1897
|
|
|
1823
1898
|
// Copyright (c) Microsoft Corporation.
|
|
1899
|
+
// Licensed under the MIT license.
|
|
1824
1900
|
const OPERATION_NAME = "updateRegistration";
|
|
1825
1901
|
/**
|
|
1826
1902
|
* Updates an existing registration.
|
|
@@ -1839,48 +1915,7 @@ function updateRegistration(context, registration, options = {}) {
|
|
|
1839
1915
|
}
|
|
1840
1916
|
|
|
1841
1917
|
// Copyright (c) Microsoft Corporation.
|
|
1842
|
-
|
|
1843
|
-
/**
|
|
1844
|
-
* Creates a NotificationHubClient from the Access Policy connection string and hub name.
|
|
1845
|
-
* @param connectionString - The Access Policy connection string for the notification hub.
|
|
1846
|
-
* @param hubName - The notification hub name.
|
|
1847
|
-
* @returns A NotificationHubsClientContext initialized from the connection string and hub name.
|
|
1848
|
-
*/
|
|
1849
|
-
function createClientContext(connectionString, hubName, options = {}) {
|
|
1850
|
-
return new NotificationHubsServiceClient(connectionString, hubName, options);
|
|
1851
|
-
}
|
|
1852
|
-
class NotificationHubsServiceClient extends coreClient.ServiceClient {
|
|
1853
|
-
constructor(connectionString, hubName, options = {}) {
|
|
1854
|
-
super(Object.assign({ deserializationOptions: {
|
|
1855
|
-
parseXML: coreXml.parseXML,
|
|
1856
|
-
}, serializationOptions: {
|
|
1857
|
-
stringifyXML: coreXml.stringifyXML,
|
|
1858
|
-
}, userAgentOptions: {
|
|
1859
|
-
userAgentPrefix: `azsdk-js-messaging-notificationhubs/${SDK_VERSION}`,
|
|
1860
|
-
} }, options));
|
|
1861
|
-
this.hubName = hubName;
|
|
1862
|
-
const parsedConnection = parseNotificationHubsConnectionString(connectionString);
|
|
1863
|
-
this.baseUrl = parsedConnection.endpoint;
|
|
1864
|
-
this.sasTokenProvider = createTokenProviderFromConnection(parsedConnection.sharedAccessKey, parsedConnection.sharedAccessKeyName);
|
|
1865
|
-
}
|
|
1866
|
-
async createHeaders(operationName, rawHeaders) {
|
|
1867
|
-
const authorization = await this.sasTokenProvider.getToken(this.baseUrl);
|
|
1868
|
-
const headers = coreRestPipeline.createHttpHeaders(rawHeaders);
|
|
1869
|
-
headers.set("Authorization", authorization.token);
|
|
1870
|
-
headers.set("x-ms-version", API_VERSION);
|
|
1871
|
-
headers.set("x-ms-azsdk-telemetry", `class=NotificationHubsServiceClient;method=${operationName}`);
|
|
1872
|
-
return headers;
|
|
1873
|
-
}
|
|
1874
|
-
requestUrl() {
|
|
1875
|
-
// Node doesn't allow change in protocol but browsers do, so doing a string replace
|
|
1876
|
-
const url = new URL(this.baseUrl.replace("sb://", "https://"));
|
|
1877
|
-
url.pathname = this.hubName;
|
|
1878
|
-
url.searchParams.set("api-version", API_VERSION);
|
|
1879
|
-
return url;
|
|
1880
|
-
}
|
|
1881
|
-
}
|
|
1882
|
-
|
|
1883
|
-
// Copyright (c) Microsoft Corporation.
|
|
1918
|
+
// Licensed under the MIT license.
|
|
1884
1919
|
/**
|
|
1885
1920
|
* This represents a client for Azure Notification Hubs to manage installations and send
|
|
1886
1921
|
* messages to devices.
|
|
@@ -2158,13 +2193,18 @@ function createBrowserInstallation(installation) {
|
|
|
2158
2193
|
}
|
|
2159
2194
|
|
|
2160
2195
|
// Copyright (c) Microsoft Corporation.
|
|
2196
|
+
// Licensed under the MIT license.
|
|
2197
|
+
function isString(value) {
|
|
2198
|
+
return typeof value === "string" || value instanceof String;
|
|
2199
|
+
}
|
|
2161
2200
|
/**
|
|
2162
2201
|
* Creates a notification to send to an Apple device.
|
|
2163
2202
|
* @param notification - A partial message used to create a message for Apple.
|
|
2164
2203
|
* @returns A newly created Apple.
|
|
2165
2204
|
*/
|
|
2166
2205
|
function createAppleNotification(notification) {
|
|
2167
|
-
|
|
2206
|
+
const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);
|
|
2207
|
+
return Object.assign(Object.assign({}, notification), { body, platform: "apple", contentType: JSON_CONTENT_TYPE });
|
|
2168
2208
|
}
|
|
2169
2209
|
/**
|
|
2170
2210
|
* Creates a notification to send to an Amazon Device Messaging device.
|
|
@@ -2172,7 +2212,8 @@ function createAppleNotification(notification) {
|
|
|
2172
2212
|
* @returns A newly created Amazon Device Messaging.
|
|
2173
2213
|
*/
|
|
2174
2214
|
function createAdmNotification(notification) {
|
|
2175
|
-
|
|
2215
|
+
const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);
|
|
2216
|
+
return Object.assign(Object.assign({}, notification), { body, platform: "adm", contentType: JSON_CONTENT_TYPE });
|
|
2176
2217
|
}
|
|
2177
2218
|
/**
|
|
2178
2219
|
* Creates a notification to send to a Baidu registered device.
|
|
@@ -2196,7 +2237,8 @@ function createBrowserNotification(notification) {
|
|
|
2196
2237
|
* @returns A newly created Firebase notification.
|
|
2197
2238
|
*/
|
|
2198
2239
|
function createFcmLegacyNotification(notification) {
|
|
2199
|
-
|
|
2240
|
+
const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);
|
|
2241
|
+
return Object.assign(Object.assign({}, notification), { body, platform: "gcm", contentType: JSON_CONTENT_TYPE });
|
|
2200
2242
|
}
|
|
2201
2243
|
/**
|
|
2202
2244
|
* Creates a notification to send to Xiaomi.
|
|
@@ -2214,6 +2256,31 @@ function createXiaomiNotification(notification) {
|
|
|
2214
2256
|
function createTemplateNotification(notification) {
|
|
2215
2257
|
return Object.assign(Object.assign({}, notification), { platform: "template", contentType: JSON_CONTENT_TYPE });
|
|
2216
2258
|
}
|
|
2259
|
+
/**
|
|
2260
|
+
* Creates a notification to send to WNS.
|
|
2261
|
+
* @param notification - The WNS notification to send.
|
|
2262
|
+
* @returns A newly created WNS message.
|
|
2263
|
+
*/
|
|
2264
|
+
function createWindowsNotification(notification) {
|
|
2265
|
+
if ((notification === null || notification === void 0 ? void 0 : notification.headers) && notification.headers["X-WNS-Type"]) {
|
|
2266
|
+
const wnsType = notification.headers["X-WNS-Type"];
|
|
2267
|
+
switch (wnsType) {
|
|
2268
|
+
case WNS_TOAST:
|
|
2269
|
+
return createWindowsToastNotification(notification);
|
|
2270
|
+
case WNS_TITLE:
|
|
2271
|
+
return createWindowsTileNotification(notification);
|
|
2272
|
+
case WNS_BADGE:
|
|
2273
|
+
return createWindowsBadgeNotification(notification);
|
|
2274
|
+
case WNS_RAW:
|
|
2275
|
+
return createWindowsRawNotification(notification);
|
|
2276
|
+
default:
|
|
2277
|
+
throw new Error(`Invalid WNS type: ${wnsType}`);
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
else {
|
|
2281
|
+
throw new Error(`Missing WNS type in headers`);
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2217
2284
|
/**
|
|
2218
2285
|
* Creates a badge message to send to WNS.
|
|
2219
2286
|
* @param notification - A partial message used to create a badge message for WNS.
|
|
@@ -2224,7 +2291,9 @@ function createWindowsBadgeNotification(notification) {
|
|
|
2224
2291
|
if (!result.headers) {
|
|
2225
2292
|
result.headers = {};
|
|
2226
2293
|
}
|
|
2227
|
-
result.headers[WNS_TYPE_NAME]
|
|
2294
|
+
if (!result.headers[WNS_TYPE_NAME]) {
|
|
2295
|
+
result.headers[WNS_TYPE_NAME] = WNS_BADGE;
|
|
2296
|
+
}
|
|
2228
2297
|
return result;
|
|
2229
2298
|
}
|
|
2230
2299
|
/**
|
|
@@ -2237,7 +2306,9 @@ function createWindowsTileNotification(notification) {
|
|
|
2237
2306
|
if (!result.headers) {
|
|
2238
2307
|
result.headers = {};
|
|
2239
2308
|
}
|
|
2240
|
-
result.headers[WNS_TYPE_NAME]
|
|
2309
|
+
if (!result.headers[WNS_TYPE_NAME]) {
|
|
2310
|
+
result.headers[WNS_TYPE_NAME] = WNS_TITLE;
|
|
2311
|
+
}
|
|
2241
2312
|
return result;
|
|
2242
2313
|
}
|
|
2243
2314
|
/**
|
|
@@ -2250,7 +2321,9 @@ function createWindowsToastNotification(notification) {
|
|
|
2250
2321
|
if (!result.headers) {
|
|
2251
2322
|
result.headers = {};
|
|
2252
2323
|
}
|
|
2253
|
-
result.headers[WNS_TYPE_NAME]
|
|
2324
|
+
if (!result.headers[WNS_TYPE_NAME]) {
|
|
2325
|
+
result.headers[WNS_TYPE_NAME] = WNS_TOAST;
|
|
2326
|
+
}
|
|
2254
2327
|
return result;
|
|
2255
2328
|
}
|
|
2256
2329
|
/**
|
|
@@ -2263,11 +2336,14 @@ function createWindowsRawNotification(notification) {
|
|
|
2263
2336
|
if (!result.headers) {
|
|
2264
2337
|
result.headers = {};
|
|
2265
2338
|
}
|
|
2266
|
-
result.headers[WNS_TYPE_NAME]
|
|
2339
|
+
if (!result.headers[WNS_TYPE_NAME]) {
|
|
2340
|
+
result.headers[WNS_TYPE_NAME] = WNS_RAW;
|
|
2341
|
+
}
|
|
2267
2342
|
return result;
|
|
2268
2343
|
}
|
|
2269
2344
|
|
|
2270
2345
|
// Copyright (c) Microsoft Corporation.
|
|
2346
|
+
// Licensed under the MIT license.
|
|
2271
2347
|
/**
|
|
2272
2348
|
* Creates an APNs native message to send to Notification Hubs.
|
|
2273
2349
|
* @param nativeMessage - The Apple native message properties to set.
|
|
@@ -2469,6 +2545,7 @@ exports.createTemplateNotification = createTemplateNotification;
|
|
|
2469
2545
|
exports.createWindowsBadgeNotification = createWindowsBadgeNotification;
|
|
2470
2546
|
exports.createWindowsBadgeNotificationBody = createWindowsBadgeNotificationBody;
|
|
2471
2547
|
exports.createWindowsInstallation = createWindowsInstallation;
|
|
2548
|
+
exports.createWindowsNotification = createWindowsNotification;
|
|
2472
2549
|
exports.createWindowsRawNotification = createWindowsRawNotification;
|
|
2473
2550
|
exports.createWindowsRegistrationDescription = createWindowsRegistrationDescription;
|
|
2474
2551
|
exports.createWindowsTemplateRegistrationDescription = createWindowsTemplateRegistrationDescription;
|