@azure/notification-hubs 1.0.0-beta.1 → 1.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -20
- package/dist/{index.js → index.cjs} +245 -146
- package/dist/index.cjs.map +1 -0
- package/dist-esm/src/{utils → auth}/connectionStringUtils.js +37 -1
- package/dist-esm/src/auth/connectionStringUtils.js.map +1 -0
- package/dist-esm/src/auth/hmacSha256.browser.js +12 -0
- package/dist-esm/src/auth/hmacSha256.browser.js.map +1 -0
- package/dist-esm/src/auth/hmacSha256.js +8 -0
- package/dist-esm/src/auth/hmacSha256.js.map +1 -0
- package/dist-esm/src/auth/sasTokenProvider.js +58 -0
- package/dist-esm/src/auth/sasTokenProvider.js.map +1 -0
- package/dist-esm/src/client/cancelScheduledNotification.js +3 -2
- package/dist-esm/src/client/cancelScheduledNotification.js.map +1 -1
- package/dist-esm/src/client/createOrUpdateInstallation.js +3 -2
- package/dist-esm/src/client/createOrUpdateInstallation.js.map +1 -1
- package/dist-esm/src/client/createOrUpdateRegistration.js +2 -1
- package/dist-esm/src/client/createOrUpdateRegistration.js.map +1 -1
- package/dist-esm/src/client/createRegistration.js +2 -1
- package/dist-esm/src/client/createRegistration.js.map +1 -1
- package/dist-esm/src/client/createRegistrationId.js +3 -2
- package/dist-esm/src/client/createRegistrationId.js.map +1 -1
- package/dist-esm/src/client/deleteInstallation.js +3 -2
- package/dist-esm/src/client/deleteInstallation.js.map +1 -1
- package/dist-esm/src/client/deleteRegistration.js +3 -2
- package/dist-esm/src/client/deleteRegistration.js.map +1 -1
- package/dist-esm/src/client/getFeedbackContainerUrl.js +3 -2
- package/dist-esm/src/client/getFeedbackContainerUrl.js.map +1 -1
- package/dist-esm/src/client/getInstallation.js +3 -2
- package/dist-esm/src/client/getInstallation.js.map +1 -1
- package/dist-esm/src/client/getNotificationHubJob.js +3 -2
- package/dist-esm/src/client/getNotificationHubJob.js.map +1 -1
- package/dist-esm/src/client/getNotificationOutcomeDetails.js +3 -2
- package/dist-esm/src/client/getNotificationOutcomeDetails.js.map +1 -1
- package/dist-esm/src/client/getRegistration.js +3 -2
- package/dist-esm/src/client/getRegistration.js.map +1 -1
- package/dist-esm/src/client/index.js +7 -3
- package/dist-esm/src/client/index.js.map +1 -1
- package/dist-esm/src/client/internal/_client.js +23 -7
- package/dist-esm/src/client/internal/_client.js.map +1 -1
- package/dist-esm/src/client/internal/_createOrUpdateRegistrationDescription.js +1 -1
- package/dist-esm/src/client/internal/_createOrUpdateRegistrationDescription.js.map +1 -1
- package/dist-esm/src/client/internal/_scheduleNotificationPayload.js +3 -2
- package/dist-esm/src/client/internal/_scheduleNotificationPayload.js.map +1 -1
- package/dist-esm/src/client/internal/_sendNotificationPayload.js +2 -2
- package/dist-esm/src/client/internal/_sendNotificationPayload.js.map +1 -1
- package/dist-esm/src/client/listNotificationHubJobs.js +3 -2
- package/dist-esm/src/client/listNotificationHubJobs.js.map +1 -1
- package/dist-esm/src/client/listRegistrations.js +3 -2
- package/dist-esm/src/client/listRegistrations.js.map +1 -1
- package/dist-esm/src/client/listRegistrationsByTag.js +3 -2
- package/dist-esm/src/client/listRegistrationsByTag.js.map +1 -1
- package/dist-esm/src/client/scheduleBroadcastNotification.js.map +1 -1
- package/dist-esm/src/client/scheduleNotification.js.map +1 -1
- package/dist-esm/src/client/sendBroadcastNotification.js.map +1 -1
- package/dist-esm/src/client/sendDirectNotification.js +1 -2
- package/dist-esm/src/client/sendDirectNotification.js.map +1 -1
- package/dist-esm/src/client/sendNotification.js.map +1 -1
- package/dist-esm/src/client/submitNotificationHubJob.js +3 -2
- package/dist-esm/src/client/submitNotificationHubJob.js.map +1 -1
- package/dist-esm/src/client/updateInstallation.js +3 -2
- package/dist-esm/src/client/updateInstallation.js.map +1 -1
- package/dist-esm/src/client/updateRegistration.js +2 -1
- package/dist-esm/src/client/updateRegistration.js.map +1 -1
- package/dist-esm/src/models/installation.js +1 -1
- package/dist-esm/src/models/installation.js.map +1 -1
- package/dist-esm/src/models/notification.js +1 -1
- package/dist-esm/src/models/notification.js.map +1 -1
- package/dist-esm/src/models/notificationBuilder.js +6 -6
- package/dist-esm/src/models/notificationBuilder.js.map +1 -1
- package/dist-esm/src/models/notificationDetails.js.map +1 -1
- package/dist-esm/src/models/registration.js +3 -39
- package/dist-esm/src/models/registration.js.map +1 -1
- package/dist-esm/src/models/response.js.map +1 -1
- package/dist-esm/src/notificationHubsClient.js +1 -2
- package/dist-esm/src/notificationHubsClient.js.map +1 -1
- package/dist-esm/src/serializers/notificationHubJobSerializer.js +3 -0
- package/dist-esm/src/serializers/notificationHubJobSerializer.js.map +1 -1
- package/dist-esm/src/serializers/notificationOutcomeSerializer.js +31 -0
- package/dist-esm/src/serializers/notificationOutcomeSerializer.js.map +1 -0
- package/dist-esm/src/serializers/registrationSerializer.js +3 -28
- package/dist-esm/src/serializers/registrationSerializer.js.map +1 -1
- package/dist-esm/src/utils/constants.js +1 -0
- package/dist-esm/src/utils/constants.js.map +1 -1
- package/dist-esm/src/utils/retryPolicy.js +2 -2
- package/dist-esm/src/utils/retryPolicy.js.map +1 -1
- package/dist-esm/src/utils/tracing.js +2 -1
- package/dist-esm/src/utils/tracing.js.map +1 -1
- package/package.json +18 -13
- package/types/3.1/notification-hubs.d.ts +60 -77
- package/types/latest/notification-hubs.d.ts +61 -83
- package/types/latest/tsdoc-metadata.json +1 -1
- package/types/src/{utils → auth}/connectionStringUtils.d.ts +7 -1
- package/types/src/auth/connectionStringUtils.d.ts.map +1 -0
- package/types/src/auth/hmacSha256.browser.d.ts +3 -0
- package/types/src/auth/hmacSha256.browser.d.ts.map +1 -0
- package/types/src/auth/hmacSha256.d.ts +2 -0
- package/types/src/auth/hmacSha256.d.ts.map +1 -0
- package/types/src/auth/sasTokenProvider.d.ts +77 -0
- package/types/src/auth/sasTokenProvider.d.ts.map +1 -0
- package/types/src/client/cancelScheduledNotification.d.ts +1 -1
- package/types/src/client/cancelScheduledNotification.d.ts.map +1 -1
- package/types/src/client/createOrUpdateInstallation.d.ts +1 -1
- package/types/src/client/createOrUpdateInstallation.d.ts.map +1 -1
- package/types/src/client/createOrUpdateRegistration.d.ts.map +1 -1
- package/types/src/client/createRegistration.d.ts.map +1 -1
- package/types/src/client/createRegistrationId.d.ts.map +1 -1
- package/types/src/client/deleteInstallation.d.ts +1 -1
- package/types/src/client/deleteInstallation.d.ts.map +1 -1
- package/types/src/client/deleteRegistration.d.ts +1 -1
- package/types/src/client/deleteRegistration.d.ts.map +1 -1
- package/types/src/client/getFeedbackContainerUrl.d.ts.map +1 -1
- package/types/src/client/getInstallation.d.ts.map +1 -1
- package/types/src/client/getNotificationHubJob.d.ts.map +1 -1
- package/types/src/client/getNotificationOutcomeDetails.d.ts.map +1 -1
- package/types/src/client/getRegistration.d.ts.map +1 -1
- package/types/src/client/index.d.ts +2 -3
- package/types/src/client/index.d.ts.map +1 -1
- package/types/src/client/internal/_client.d.ts +8 -8
- package/types/src/client/internal/_client.d.ts.map +1 -1
- package/types/src/client/internal/_scheduleNotificationPayload.d.ts +1 -1
- package/types/src/client/internal/_scheduleNotificationPayload.d.ts.map +1 -1
- package/types/src/client/internal/_sendNotificationPayload.d.ts +1 -1
- package/types/src/client/internal/_sendNotificationPayload.d.ts.map +1 -1
- package/types/src/client/listNotificationHubJobs.d.ts.map +1 -1
- package/types/src/client/listRegistrations.d.ts.map +1 -1
- package/types/src/client/listRegistrationsByTag.d.ts.map +1 -1
- package/types/src/client/scheduleBroadcastNotification.d.ts +1 -1
- package/types/src/client/scheduleBroadcastNotification.d.ts.map +1 -1
- package/types/src/client/scheduleNotification.d.ts +1 -1
- package/types/src/client/scheduleNotification.d.ts.map +1 -1
- package/types/src/client/sendBroadcastNotification.d.ts +1 -1
- package/types/src/client/sendBroadcastNotification.d.ts.map +1 -1
- package/types/src/client/sendDirectNotification.d.ts +4 -5
- package/types/src/client/sendDirectNotification.d.ts.map +1 -1
- package/types/src/client/sendNotification.d.ts +1 -1
- package/types/src/client/sendNotification.d.ts.map +1 -1
- package/types/src/client/submitNotificationHubJob.d.ts.map +1 -1
- package/types/src/client/updateInstallation.d.ts +1 -1
- package/types/src/client/updateInstallation.d.ts.map +1 -1
- package/types/src/client/updateRegistration.d.ts.map +1 -1
- package/types/src/models/installation.d.ts +3 -3
- package/types/src/models/installation.d.ts.map +1 -1
- package/types/src/models/notification.d.ts +3 -3
- package/types/src/models/notification.d.ts.map +1 -1
- package/types/src/models/notificationBuilder.d.ts +4 -4
- package/types/src/models/notificationBuilder.d.ts.map +1 -1
- package/types/src/models/notificationDetails.d.ts +63 -0
- package/types/src/models/notificationDetails.d.ts.map +1 -1
- package/types/src/models/registration.d.ts +6 -59
- package/types/src/models/registration.d.ts.map +1 -1
- package/types/src/models/response.d.ts +0 -26
- package/types/src/models/response.d.ts.map +1 -1
- package/types/src/notificationHubsClient.d.ts +3 -5
- package/types/src/notificationHubsClient.d.ts.map +1 -1
- package/types/src/serializers/notificationHubJobSerializer.d.ts.map +1 -1
- package/types/src/serializers/notificationOutcomeSerializer.d.ts +3 -0
- package/types/src/serializers/notificationOutcomeSerializer.d.ts.map +1 -0
- package/types/src/serializers/registrationSerializer.d.ts +1 -21
- package/types/src/serializers/registrationSerializer.d.ts.map +1 -1
- package/types/src/utils/constants.d.ts +1 -0
- package/types/src/utils/constants.d.ts.map +1 -1
- package/types/src/utils/tracing.d.ts.map +1 -1
- package/dist/index.js.map +0 -1
- package/dist-esm/src/utils/connectionStringUtils.js.map +0 -1
- package/types/src/utils/connectionStringUtils.d.ts.map +0 -1
|
@@ -3,13 +3,123 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var coreRestPipeline = require('@azure/core-rest-pipeline');
|
|
6
|
-
var
|
|
6
|
+
var crypto = require('crypto');
|
|
7
7
|
var coreXml = require('@azure/core-xml');
|
|
8
8
|
var coreClient = require('@azure/core-client');
|
|
9
9
|
var coreTracing = require('@azure/core-tracing');
|
|
10
10
|
var tslib = require('tslib');
|
|
11
11
|
|
|
12
|
+
// Copyright (c) Microsoft Corporation.
|
|
13
|
+
// Licensed under the MIT license.
|
|
14
|
+
const SDK_VERSION = "1.0.0-beta.4";
|
|
15
|
+
const JSON_CONTENT_TYPE = "application/json;charset=utf-8";
|
|
16
|
+
const XML_CONTENT_TYPE = "application/xml";
|
|
17
|
+
const STREAM_CONTENT_TYPE = "application/octet-stream";
|
|
18
|
+
const WNS_TYPE_NAME = "X-WNS-Type";
|
|
19
|
+
const WNS_RAW = "wns/raw";
|
|
20
|
+
const WNS_BADGE = "wns/badge";
|
|
21
|
+
const WNS_TITLE = "wns/tile";
|
|
22
|
+
const WNS_TOAST = "wns/toast";
|
|
23
|
+
|
|
24
|
+
// Copyright (c) Microsoft Corporation.
|
|
25
|
+
async function signString(key, toSign) {
|
|
26
|
+
const hmac = crypto.createHmac("sha256", key).update(toSign).digest("base64");
|
|
27
|
+
return encodeURIComponent(hmac);
|
|
28
|
+
}
|
|
29
|
+
|
|
12
30
|
// Copyright (c) Microsoft Corporation.
|
|
31
|
+
/**
|
|
32
|
+
* Creates a token provider from the provided shared access data.
|
|
33
|
+
* @param data - The sharedAccessKeyName/sharedAccessKey pair or the sharedAccessSignature.
|
|
34
|
+
* @hidden
|
|
35
|
+
*/
|
|
36
|
+
function createSasTokenProvider(data) {
|
|
37
|
+
return new SasTokenProviderImpl(data);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A TokenProvider that generates a Sas token:
|
|
41
|
+
* `SharedAccessSignature sr=<resource>&sig=<signature>&se=<expiry>&skn=<keyname>`
|
|
42
|
+
*
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
class SasTokenProviderImpl {
|
|
46
|
+
/**
|
|
47
|
+
* Initializes a new instance of SasTokenProvider
|
|
48
|
+
* @param credential - The source `NamedKeyCredential` or `SASCredential`.
|
|
49
|
+
*/
|
|
50
|
+
constructor(credential) {
|
|
51
|
+
this._credential = credential;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Property used to distinguish TokenProvider from TokenCredential.
|
|
55
|
+
*/
|
|
56
|
+
get isSasTokenProvider() {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Gets the sas token for the specified audience
|
|
61
|
+
* @param audience - The audience for which the token is desired.
|
|
62
|
+
*/
|
|
63
|
+
async getToken(audience) {
|
|
64
|
+
return createToken(this._credential.sharedAccessKeyName, this._credential.sharedAccessKey, Math.floor(Date.now() / 1000) + 3600, audience);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Creates the sas token based on the provided information.
|
|
69
|
+
* @param keyName - The shared access key name.
|
|
70
|
+
* @param key - The shared access key.
|
|
71
|
+
* @param expiry - The time period in unix time after which the token will expire.
|
|
72
|
+
* @param audience - The audience for which the token is desired.
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
async function createToken(keyName, key, expiry, audience) {
|
|
76
|
+
audience = encodeURIComponent(audience.toLowerCase());
|
|
77
|
+
keyName = encodeURIComponent(keyName);
|
|
78
|
+
const stringToSign = audience + "\n" + expiry;
|
|
79
|
+
const sig = await signString(key, stringToSign);
|
|
80
|
+
return {
|
|
81
|
+
token: `SharedAccessSignature sr=${audience}&sig=${sig}&se=${expiry}&skn=${keyName}`,
|
|
82
|
+
expiresOnTimestamp: expiry,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Copyright (c) Microsoft Corporation.
|
|
87
|
+
/**
|
|
88
|
+
* Parses the connection string and returns an object of type T.
|
|
89
|
+
*
|
|
90
|
+
* Connection strings have the following syntax:
|
|
91
|
+
*
|
|
92
|
+
* ConnectionString ::= `Part { ";" Part } [ ";" ] [ WhiteSpace ]`
|
|
93
|
+
* Part ::= [ PartLiteral [ "=" PartLiteral ] ]
|
|
94
|
+
* PartLiteral ::= [ WhiteSpace ] Literal [ WhiteSpace ]
|
|
95
|
+
* Literal ::= ? any sequence of characters except ; or = or WhiteSpace ?
|
|
96
|
+
* WhiteSpace ::= ? all whitespace characters including `\r` and `\n` ?
|
|
97
|
+
*
|
|
98
|
+
* @param connectionString - The connection string to be parsed.
|
|
99
|
+
* @returns ParsedOutput<T>.
|
|
100
|
+
*/
|
|
101
|
+
function parseConnectionString(connectionString) {
|
|
102
|
+
const output = {};
|
|
103
|
+
const parts = connectionString.trim().split(";");
|
|
104
|
+
for (let part of parts) {
|
|
105
|
+
part = part.trim();
|
|
106
|
+
if (part === "") {
|
|
107
|
+
// parts can be empty
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const splitIndex = part.indexOf("=");
|
|
111
|
+
if (splitIndex === -1) {
|
|
112
|
+
throw new Error("Connection string malformed: each part of the connection string must have an `=` assignment.");
|
|
113
|
+
}
|
|
114
|
+
const key = part.substring(0, splitIndex).trim();
|
|
115
|
+
if (key === "") {
|
|
116
|
+
throw new Error("Connection string malformed: missing key for assignment");
|
|
117
|
+
}
|
|
118
|
+
const value = part.substring(splitIndex + 1).trim();
|
|
119
|
+
output[key] = value;
|
|
120
|
+
}
|
|
121
|
+
return output;
|
|
122
|
+
}
|
|
13
123
|
/**
|
|
14
124
|
* Creates a SasTokenProvider from a shared access key and shared access key name.
|
|
15
125
|
* @param sharedAccessKey - The shared access key value.
|
|
@@ -17,7 +127,7 @@ var tslib = require('tslib');
|
|
|
17
127
|
* @returns A SasTokenProvider with the given shared access token information.
|
|
18
128
|
*/
|
|
19
129
|
function createTokenProviderFromConnection(sharedAccessKey, sharedAccessKeyName) {
|
|
20
|
-
return
|
|
130
|
+
return createSasTokenProvider({ sharedAccessKey, sharedAccessKeyName });
|
|
21
131
|
}
|
|
22
132
|
/**
|
|
23
133
|
* Parses given connection string into the different properties applicable to Azure Service Bus.
|
|
@@ -26,7 +136,7 @@ function createTokenProviderFromConnection(sharedAccessKey, sharedAccessKeyName)
|
|
|
26
136
|
* for the Service Bus namespace, queue or topic.
|
|
27
137
|
*/
|
|
28
138
|
function parseNotificationHubsConnectionString(connectionString) {
|
|
29
|
-
const parsedResult =
|
|
139
|
+
const parsedResult = parseConnectionString(connectionString);
|
|
30
140
|
if (!parsedResult.Endpoint) {
|
|
31
141
|
throw new Error("Connection string should have an Endpoint key.");
|
|
32
142
|
}
|
|
@@ -61,17 +171,20 @@ class NotificationHubsServiceClient$1 extends coreClient.ServiceClient {
|
|
|
61
171
|
parseXML: coreXml.parseXML,
|
|
62
172
|
}, serializationOptions: {
|
|
63
173
|
stringifyXML: coreXml.stringifyXML,
|
|
174
|
+
}, userAgentOptions: {
|
|
175
|
+
userAgentPrefix: `azsdk-js-messaging-notificationhubs/${SDK_VERSION}`,
|
|
64
176
|
} }, options));
|
|
65
177
|
this.hubName = hubName;
|
|
66
178
|
const parsedConnection = parseNotificationHubsConnectionString(connectionString);
|
|
67
179
|
this.baseUrl = parsedConnection.endpoint;
|
|
68
180
|
this.sasTokenProvider = createTokenProviderFromConnection(parsedConnection.sharedAccessKey, parsedConnection.sharedAccessKeyName);
|
|
69
181
|
}
|
|
70
|
-
createHeaders() {
|
|
71
|
-
const authorization = this.sasTokenProvider.getToken(this.baseUrl);
|
|
182
|
+
async createHeaders(operationName) {
|
|
183
|
+
const authorization = await this.sasTokenProvider.getToken(this.baseUrl);
|
|
72
184
|
const headers = coreRestPipeline.createHttpHeaders();
|
|
73
185
|
headers.set("Authorization", authorization.token);
|
|
74
186
|
headers.set("x-ms-version", API_VERSION);
|
|
187
|
+
headers.set("x-ms-azsdk-telemetry", `class=NotificationHubsServiceClient;method=${operationName}`);
|
|
75
188
|
return headers;
|
|
76
189
|
}
|
|
77
190
|
requestUrl() {
|
|
@@ -190,6 +303,34 @@ function getTagsOrUndefined(value) {
|
|
|
190
303
|
return result.split(",");
|
|
191
304
|
}
|
|
192
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
|
+
|
|
193
334
|
// Copyright (c) Microsoft Corporation.
|
|
194
335
|
/**
|
|
195
336
|
* Marker for atom metadata.
|
|
@@ -283,15 +424,14 @@ async function parseXMLError(bodyText) {
|
|
|
283
424
|
}
|
|
284
425
|
|
|
285
426
|
// Copyright (c) Microsoft Corporation.
|
|
286
|
-
/**
|
|
287
|
-
* @internal
|
|
288
|
-
*/
|
|
289
427
|
function createRequest(endpoint, method, headers, options) {
|
|
290
428
|
return coreRestPipeline.createPipelineRequest(Object.assign(Object.assign(Object.assign({}, options.tracingOptions), options.requestOptions), { url: endpoint.toString(), abortSignal: options.abortSignal, method,
|
|
291
429
|
headers }));
|
|
292
430
|
}
|
|
293
431
|
/**
|
|
294
|
-
*
|
|
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.
|
|
295
435
|
*/
|
|
296
436
|
function parseNotificationResponse(response) {
|
|
297
437
|
const correlationId = response.headers.get("x-ms-correlation-request-id");
|
|
@@ -304,16 +444,32 @@ function parseNotificationResponse(response) {
|
|
|
304
444
|
};
|
|
305
445
|
}
|
|
306
446
|
/**
|
|
307
|
-
*
|
|
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.
|
|
308
450
|
*/
|
|
309
|
-
function parseNotificationSendResponse(response) {
|
|
451
|
+
async function parseNotificationSendResponse(response) {
|
|
310
452
|
const result = parseNotificationResponse(response);
|
|
311
453
|
let notificationId;
|
|
312
454
|
if (result.location) {
|
|
313
455
|
const locationUrl = new URL(result.location);
|
|
314
456
|
notificationId = locationUrl.pathname.split("/")[3];
|
|
315
457
|
}
|
|
316
|
-
|
|
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" });
|
|
317
473
|
}
|
|
318
474
|
/**
|
|
319
475
|
* Sends a request through the client context.
|
|
@@ -361,10 +517,11 @@ async function sendRequest(context, request, successStatusCode) {
|
|
|
361
517
|
const tracingClient = coreTracing.createTracingClient({
|
|
362
518
|
namespace: "Microsoft.NotificationHubs",
|
|
363
519
|
packageName: "@azure/notification-hubs",
|
|
364
|
-
packageVersion:
|
|
520
|
+
packageVersion: SDK_VERSION,
|
|
365
521
|
});
|
|
366
522
|
|
|
367
523
|
// Copyright (c) Microsoft Corporation.
|
|
524
|
+
const OPERATION_NAME$h = "cancelScheduledNotification";
|
|
368
525
|
/**
|
|
369
526
|
* Cancels the scheduled notification with the given notification ID.
|
|
370
527
|
* NOTE: This is only available in Standard SKU Azure Notification Hubs.
|
|
@@ -374,10 +531,10 @@ const tracingClient = coreTracing.createTracingClient({
|
|
|
374
531
|
* @returns A notification hub response with correlation ID and tracking ID.
|
|
375
532
|
*/
|
|
376
533
|
function cancelScheduledNotification(context, notificationId, options = {}) {
|
|
377
|
-
return tracingClient.withSpan(
|
|
534
|
+
return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$h}`, options, async (updatedOptions) => {
|
|
378
535
|
const endpoint = context.requestUrl();
|
|
379
536
|
endpoint.pathname += `/schedulednotifications/${notificationId}`;
|
|
380
|
-
const headers = context.createHeaders();
|
|
537
|
+
const headers = await context.createHeaders(OPERATION_NAME$h);
|
|
381
538
|
const request = createRequest(endpoint, "DELETE", headers, updatedOptions);
|
|
382
539
|
const response = await sendRequest(context, request, 200);
|
|
383
540
|
return parseNotificationSendResponse(response);
|
|
@@ -385,6 +542,7 @@ function cancelScheduledNotification(context, notificationId, options = {}) {
|
|
|
385
542
|
}
|
|
386
543
|
|
|
387
544
|
// Copyright (c) Microsoft Corporation.
|
|
545
|
+
const OPERATION_NAME$g = "createOrUpdateInstallation";
|
|
388
546
|
/**
|
|
389
547
|
* Creates or overwrites an installation to a Notification Hub.
|
|
390
548
|
* @param context - The Notification Hubs client.
|
|
@@ -393,10 +551,10 @@ function cancelScheduledNotification(context, notificationId, options = {}) {
|
|
|
393
551
|
* @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
|
|
394
552
|
*/
|
|
395
553
|
function createOrUpdateInstallation(context, installation, options = {}) {
|
|
396
|
-
return tracingClient.withSpan(
|
|
554
|
+
return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$g}`, options, async (updatedOptions) => {
|
|
397
555
|
const endpoint = context.requestUrl();
|
|
398
556
|
endpoint.pathname += `/installations/${installation.installationId}`;
|
|
399
|
-
const headers = context.createHeaders();
|
|
557
|
+
const headers = await context.createHeaders(OPERATION_NAME$g);
|
|
400
558
|
headers.set("Content-Type", "application/json");
|
|
401
559
|
const request = createRequest(endpoint, "PUT", headers, updatedOptions);
|
|
402
560
|
request.body = JSON.stringify(installation);
|
|
@@ -429,6 +587,9 @@ const registrationDescriptionParser = {
|
|
|
429
587
|
async parseRegistrationFeed(bodyText) {
|
|
430
588
|
const xml = await coreXml.parseXML(bodyText, { includeRoot: true });
|
|
431
589
|
const results = [];
|
|
590
|
+
if (!isDefined(xml.feed.entry)) {
|
|
591
|
+
return results;
|
|
592
|
+
}
|
|
432
593
|
for (const entry of xml.feed.entry) {
|
|
433
594
|
delete entry.content["$"];
|
|
434
595
|
const keyName = Object.keys(entry.content)[0];
|
|
@@ -513,20 +674,6 @@ const registrationDescriptionParser = {
|
|
|
513
674
|
createGcmTemplateRegistrationDescription(rawRegistrationDescription) {
|
|
514
675
|
return Object.assign(Object.assign(Object.assign({}, this.createGcmRegistrationDescription(rawRegistrationDescription)), createTemplateRegistrationDescription(rawRegistrationDescription)), { type: "GcmTemplate" });
|
|
515
676
|
},
|
|
516
|
-
/**
|
|
517
|
-
* @internal
|
|
518
|
-
* Creates an FCM registration description from incoming XML property bag.
|
|
519
|
-
*/
|
|
520
|
-
createFcmRegistrationDescription(rawRegistrationDescription) {
|
|
521
|
-
return Object.assign(Object.assign({ fcmRegistrationId: getString(rawRegistrationDescription["FcmRegistrationId"], "fcmRegistrationId") }, createRegistrationDescription(rawRegistrationDescription)), { type: "Fcm" });
|
|
522
|
-
},
|
|
523
|
-
/**
|
|
524
|
-
* @internal
|
|
525
|
-
* Creates an FCM template registration description from incoming XML property bag.
|
|
526
|
-
*/
|
|
527
|
-
createFcmTemplateRegistrationDescription(rawRegistrationDescription) {
|
|
528
|
-
return Object.assign(Object.assign(Object.assign({}, this.createFcmRegistrationDescription(rawRegistrationDescription)), createTemplateRegistrationDescription(rawRegistrationDescription)), { type: "FcmTemplate" });
|
|
529
|
-
},
|
|
530
677
|
/**
|
|
531
678
|
* @internal
|
|
532
679
|
* Creates a Windows Phone registration description from incoming XML property bag.
|
|
@@ -684,20 +831,6 @@ const registrationDescriptionSerializer = {
|
|
|
684
831
|
serializeGcmTemplateRegistrationDescription(description) {
|
|
685
832
|
return Object.assign(Object.assign({}, this.serializeGcmRegistrationDescription(description)), serializeTemplateRegistrationDescription(description));
|
|
686
833
|
},
|
|
687
|
-
/**
|
|
688
|
-
* @internal
|
|
689
|
-
* Serializes an existing FCM registration description to an object for serialization.
|
|
690
|
-
*/
|
|
691
|
-
serializeFcmRegistrationDescription(description) {
|
|
692
|
-
return Object.assign(Object.assign({}, serializeRegistrationDescription(description)), { FcmRegistrationId: description.fcmRegistrationId });
|
|
693
|
-
},
|
|
694
|
-
/**
|
|
695
|
-
* @internal
|
|
696
|
-
* Serializes an existing FCM template registration description to an object for serialization.
|
|
697
|
-
*/
|
|
698
|
-
serializeFcmTemplateRegistrationDescription(description) {
|
|
699
|
-
return Object.assign(Object.assign({}, this.serializeFcmRegistrationDescription(description)), serializeTemplateRegistrationDescription(description));
|
|
700
|
-
},
|
|
701
834
|
/**
|
|
702
835
|
* @internal
|
|
703
836
|
* @deprecated Windows Phone is no longer supported.
|
|
@@ -791,7 +924,7 @@ async function createOrUpdateRegistrationDescription(context, registration, oper
|
|
|
791
924
|
// Clear out readonly properties
|
|
792
925
|
registration.registrationId = undefined;
|
|
793
926
|
registration.etag = undefined;
|
|
794
|
-
const headers = context.createHeaders();
|
|
927
|
+
const headers = await context.createHeaders(`${operationName}Registration`);
|
|
795
928
|
headers.set("Content-Type", "application/atom+xml;type=entry;charset=utf-8");
|
|
796
929
|
if (operationName === "update") {
|
|
797
930
|
headers.set("If-Match", isDefined(etag) ? `"${etag}"` : "*");
|
|
@@ -803,6 +936,7 @@ async function createOrUpdateRegistrationDescription(context, registration, oper
|
|
|
803
936
|
}
|
|
804
937
|
|
|
805
938
|
// Copyright (c) Microsoft Corporation.
|
|
939
|
+
const OPERATION_NAME$f = "createOrUpdateRegistration";
|
|
806
940
|
/**
|
|
807
941
|
* Creates or updates a registration.
|
|
808
942
|
* @param context - The Notification Hubs client.
|
|
@@ -811,12 +945,13 @@ async function createOrUpdateRegistrationDescription(context, registration, oper
|
|
|
811
945
|
* @returns The created or updated registration description.
|
|
812
946
|
*/
|
|
813
947
|
function createOrUpdateRegistration(context, registration, options = {}) {
|
|
814
|
-
return tracingClient.withSpan(
|
|
948
|
+
return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$f}`, options, async (updatedOptions) => {
|
|
815
949
|
return createOrUpdateRegistrationDescription(context, registration, "createOrUpdate", updatedOptions);
|
|
816
950
|
});
|
|
817
951
|
}
|
|
818
952
|
|
|
819
953
|
// Copyright (c) Microsoft Corporation.
|
|
954
|
+
const OPERATION_NAME$e = "createRegistrationId";
|
|
820
955
|
/**
|
|
821
956
|
* Creates a new registration ID.
|
|
822
957
|
* @param context - The Notification Hubs client.
|
|
@@ -824,10 +959,10 @@ function createOrUpdateRegistration(context, registration, options = {}) {
|
|
|
824
959
|
* @returns The newly created registration ID.
|
|
825
960
|
*/
|
|
826
961
|
function createRegistrationId(context, options = {}) {
|
|
827
|
-
return tracingClient.withSpan(
|
|
962
|
+
return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$e}`, options, async (updatedOptions) => {
|
|
828
963
|
const endpoint = context.requestUrl();
|
|
829
964
|
endpoint.pathname += "/registrationIDs";
|
|
830
|
-
const headers = context.createHeaders();
|
|
965
|
+
const headers = await context.createHeaders(OPERATION_NAME$e);
|
|
831
966
|
headers.set("Content-Type", "application/xml;type=entry;charset=utf-8");
|
|
832
967
|
const request = createRequest(endpoint, "POST", headers, updatedOptions);
|
|
833
968
|
const response = await sendRequest(context, request, 201);
|
|
@@ -840,6 +975,7 @@ function createRegistrationId(context, options = {}) {
|
|
|
840
975
|
}
|
|
841
976
|
|
|
842
977
|
// Copyright (c) Microsoft Corporation.
|
|
978
|
+
const OPERATION_NAME$d = "createRegistration";
|
|
843
979
|
/**
|
|
844
980
|
* Creates a new registration. This method generates a registration ID,
|
|
845
981
|
* which you can subsequently use to retrieve, update, and delete this registration.
|
|
@@ -849,7 +985,7 @@ function createRegistrationId(context, options = {}) {
|
|
|
849
985
|
* @returns The newly created registration description.
|
|
850
986
|
*/
|
|
851
987
|
function createRegistration(context, registration, options = {}) {
|
|
852
|
-
return tracingClient.withSpan(
|
|
988
|
+
return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$d}`, options, async (updatedOptions) => {
|
|
853
989
|
if (registration.registrationId) {
|
|
854
990
|
throw new coreRestPipeline.RestError("registrationId must not be set during a create operation", {
|
|
855
991
|
statusCode: 400,
|
|
@@ -860,6 +996,7 @@ function createRegistration(context, registration, options = {}) {
|
|
|
860
996
|
}
|
|
861
997
|
|
|
862
998
|
// Copyright (c) Microsoft Corporation.
|
|
999
|
+
const OPERATION_NAME$c = "deleteInstallation";
|
|
863
1000
|
/**
|
|
864
1001
|
* Deletes an installation from a Notification Hub.
|
|
865
1002
|
* @param context - The Notification Hubs client.
|
|
@@ -868,10 +1005,10 @@ function createRegistration(context, registration, options = {}) {
|
|
|
868
1005
|
* @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
|
|
869
1006
|
*/
|
|
870
1007
|
function deleteInstallation(context, installationId, options = {}) {
|
|
871
|
-
return tracingClient.withSpan(
|
|
1008
|
+
return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$c}`, options, async (updatedOptions) => {
|
|
872
1009
|
const endpoint = context.requestUrl();
|
|
873
1010
|
endpoint.pathname += `/installations/${installationId}`;
|
|
874
|
-
const headers = context.createHeaders();
|
|
1011
|
+
const headers = await context.createHeaders(OPERATION_NAME$c);
|
|
875
1012
|
const request = createRequest(endpoint, "DELETE", headers, updatedOptions);
|
|
876
1013
|
const response = await sendRequest(context, request, 204);
|
|
877
1014
|
return parseNotificationResponse(response);
|
|
@@ -879,6 +1016,7 @@ function deleteInstallation(context, installationId, options = {}) {
|
|
|
879
1016
|
}
|
|
880
1017
|
|
|
881
1018
|
// Copyright (c) Microsoft Corporation.
|
|
1019
|
+
const OPERATION_NAME$b = "getFeedbackContainerUrl";
|
|
882
1020
|
/**
|
|
883
1021
|
* Retrieves an Azure Storage container URL. The container has feedback data for the notification hub.
|
|
884
1022
|
* The caller can then use the Azure Storage Services SDK to retrieve the contents of the container.
|
|
@@ -887,10 +1025,10 @@ function deleteInstallation(context, installationId, options = {}) {
|
|
|
887
1025
|
* @returns The URL of the Azure Storage Container containing the feedback data.
|
|
888
1026
|
*/
|
|
889
1027
|
function getFeedbackContainerUrl(context, options = {}) {
|
|
890
|
-
return tracingClient.withSpan(
|
|
1028
|
+
return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$b}`, options, async (updatedOptions) => {
|
|
891
1029
|
const endpoint = context.requestUrl();
|
|
892
1030
|
endpoint.pathname += "/feedbackcontainer";
|
|
893
|
-
const headers = context.createHeaders();
|
|
1031
|
+
const headers = await context.createHeaders(OPERATION_NAME$b);
|
|
894
1032
|
headers.set("Content-Type", "application/xml;type=entry;charset=utf-8");
|
|
895
1033
|
const request = createRequest(endpoint, "GET", headers, updatedOptions);
|
|
896
1034
|
const response = await sendRequest(context, request, 200);
|
|
@@ -899,6 +1037,7 @@ function getFeedbackContainerUrl(context, options = {}) {
|
|
|
899
1037
|
}
|
|
900
1038
|
|
|
901
1039
|
// Copyright (c) Microsoft Corporation.
|
|
1040
|
+
const OPERATION_NAME$a = "getInstallation";
|
|
902
1041
|
/**
|
|
903
1042
|
* Gets an Azure Notification Hub installation by the installation ID.
|
|
904
1043
|
* @param context - The Notification Hubs client.
|
|
@@ -907,10 +1046,10 @@ function getFeedbackContainerUrl(context, options = {}) {
|
|
|
907
1046
|
* @returns The installation that matches the installation ID.
|
|
908
1047
|
*/
|
|
909
1048
|
function getInstallation(context, installationId, options = {}) {
|
|
910
|
-
return tracingClient.withSpan(
|
|
1049
|
+
return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$a}`, options, async (updatedOptions) => {
|
|
911
1050
|
const endpoint = context.requestUrl();
|
|
912
1051
|
endpoint.pathname += `/installations/${installationId}`;
|
|
913
|
-
const headers = context.createHeaders();
|
|
1052
|
+
const headers = await context.createHeaders(OPERATION_NAME$a);
|
|
914
1053
|
headers.set("Content-Type", "application/json");
|
|
915
1054
|
const request = createRequest(endpoint, "GET", headers, updatedOptions);
|
|
916
1055
|
const response = await sendRequest(context, request, 200);
|
|
@@ -952,6 +1091,9 @@ async function parseNotificationHubJobEntry(bodyText) {
|
|
|
952
1091
|
async function parseNotificationHubJobFeed(bodyText) {
|
|
953
1092
|
const xml = await coreXml.parseXML(bodyText, { includeRoot: true });
|
|
954
1093
|
const results = [];
|
|
1094
|
+
if (!isDefined(xml.feed.entry)) {
|
|
1095
|
+
return results;
|
|
1096
|
+
}
|
|
955
1097
|
for (const item of xml.feed.entry) {
|
|
956
1098
|
results.push(createNotificationHubJob(item.content.NotificationHubJob));
|
|
957
1099
|
}
|
|
@@ -989,6 +1131,7 @@ function createNotificationHubJob(content) {
|
|
|
989
1131
|
}
|
|
990
1132
|
|
|
991
1133
|
// Copyright (c) Microsoft Corporation.
|
|
1134
|
+
const OPERATION_NAME$9 = "getNotificationHubJob";
|
|
992
1135
|
/**
|
|
993
1136
|
* Gets a Notification Hub Job by the ID.
|
|
994
1137
|
* @param context - The Notification Hubs client.
|
|
@@ -997,10 +1140,10 @@ function createNotificationHubJob(content) {
|
|
|
997
1140
|
* @returns The Notification Hub Job with the matching ID.
|
|
998
1141
|
*/
|
|
999
1142
|
function getNotificationHubJob(context, jobId, options = {}) {
|
|
1000
|
-
return tracingClient.withSpan(
|
|
1143
|
+
return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$9}`, options, async (updatedOptions) => {
|
|
1001
1144
|
const endpoint = context.requestUrl();
|
|
1002
1145
|
endpoint.pathname += `/jobs/${jobId}`;
|
|
1003
|
-
const headers = context.createHeaders();
|
|
1146
|
+
const headers = await context.createHeaders(OPERATION_NAME$9);
|
|
1004
1147
|
headers.set("Content-Type", "application/atom+xml;type=entry;charset=utf-8");
|
|
1005
1148
|
const request = createRequest(endpoint, "GET", headers, updatedOptions);
|
|
1006
1149
|
const response = await sendRequest(context, request, 200);
|
|
@@ -1064,6 +1207,7 @@ function parseOutcomeCounts(counts) {
|
|
|
1064
1207
|
}
|
|
1065
1208
|
|
|
1066
1209
|
// Copyright (c) Microsoft Corporation.
|
|
1210
|
+
const OPERATION_NAME$8 = "getNotificationOutcomeDetails";
|
|
1067
1211
|
/**
|
|
1068
1212
|
* Retrieves the results of a send operation. This can retrieve intermediate results if the send is being processed
|
|
1069
1213
|
* or final results if the Send* has completed. This API can only be called for Standard SKU and above.
|
|
@@ -1073,10 +1217,10 @@ function parseOutcomeCounts(counts) {
|
|
|
1073
1217
|
* @returns The results of the send operation.
|
|
1074
1218
|
*/
|
|
1075
1219
|
function getNotificationOutcomeDetails(context, notificationId, options = {}) {
|
|
1076
|
-
return tracingClient.withSpan(
|
|
1220
|
+
return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$8}`, options, async (updatedOptions) => {
|
|
1077
1221
|
const endpoint = context.requestUrl();
|
|
1078
1222
|
endpoint.pathname += `/messages/${notificationId}`;
|
|
1079
|
-
const headers = context.createHeaders();
|
|
1223
|
+
const headers = await context.createHeaders(OPERATION_NAME$8);
|
|
1080
1224
|
const request = createRequest(endpoint, "GET", headers, updatedOptions);
|
|
1081
1225
|
const response = await sendRequest(context, request, 200);
|
|
1082
1226
|
return parseNotificationDetails(response.bodyAsText);
|
|
@@ -1084,6 +1228,7 @@ function getNotificationOutcomeDetails(context, notificationId, options = {}) {
|
|
|
1084
1228
|
}
|
|
1085
1229
|
|
|
1086
1230
|
// Copyright (c) Microsoft Corporation.
|
|
1231
|
+
const OPERATION_NAME$7 = "getRegistration";
|
|
1087
1232
|
/**
|
|
1088
1233
|
* Gets a registration by the given registration ID.
|
|
1089
1234
|
* @param context - The Notification Hubs client.
|
|
@@ -1092,10 +1237,10 @@ function getNotificationOutcomeDetails(context, notificationId, options = {}) {
|
|
|
1092
1237
|
* @returns A RegistrationDescription that has the given registration ID.
|
|
1093
1238
|
*/
|
|
1094
1239
|
function getRegistration(context, registrationId, options = {}) {
|
|
1095
|
-
return tracingClient.withSpan(
|
|
1240
|
+
return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$7}`, options, async (updatedOptions) => {
|
|
1096
1241
|
const endpoint = context.requestUrl();
|
|
1097
1242
|
endpoint.pathname += `/registrations/${registrationId}`;
|
|
1098
|
-
const headers = context.createHeaders();
|
|
1243
|
+
const headers = await context.createHeaders(OPERATION_NAME$7);
|
|
1099
1244
|
headers.set("Content-Type", "application/xml;type=entry;charset=utf-8");
|
|
1100
1245
|
const request = createRequest(endpoint, "GET", headers, updatedOptions);
|
|
1101
1246
|
const response = await sendRequest(context, request, 200);
|
|
@@ -1104,6 +1249,7 @@ function getRegistration(context, registrationId, options = {}) {
|
|
|
1104
1249
|
}
|
|
1105
1250
|
|
|
1106
1251
|
// Copyright (c) Microsoft Corporation.
|
|
1252
|
+
const OPERATION_NAME$6 = "listNotificationHubJobs";
|
|
1107
1253
|
/**
|
|
1108
1254
|
* Gets all Notification Hub Jobs for this Notification Hub.
|
|
1109
1255
|
* @param context - The Notification Hubs client.xs
|
|
@@ -1111,10 +1257,10 @@ function getRegistration(context, registrationId, options = {}) {
|
|
|
1111
1257
|
* @returns An array of all Notification Hub Jobs for this Notification Hub.
|
|
1112
1258
|
*/
|
|
1113
1259
|
function listNotificationHubJobs(context, options = {}) {
|
|
1114
|
-
return tracingClient.withSpan(
|
|
1260
|
+
return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$6}`, options, async (updatedOptions) => {
|
|
1115
1261
|
const endpoint = context.requestUrl();
|
|
1116
1262
|
endpoint.pathname += "/jobs";
|
|
1117
|
-
const headers = context.createHeaders();
|
|
1263
|
+
const headers = await context.createHeaders(OPERATION_NAME$6);
|
|
1118
1264
|
headers.set("Content-Type", "application/atom+xml;type=entry;charset=utf-8");
|
|
1119
1265
|
const request = createRequest(endpoint, "GET", headers, updatedOptions);
|
|
1120
1266
|
const response = await sendRequest(context, request, 200);
|
|
@@ -1123,6 +1269,7 @@ function listNotificationHubJobs(context, options = {}) {
|
|
|
1123
1269
|
}
|
|
1124
1270
|
|
|
1125
1271
|
// Copyright (c) Microsoft Corporation.
|
|
1272
|
+
const OPERATION_NAME$5 = "listRegistrationsByTag";
|
|
1126
1273
|
/**
|
|
1127
1274
|
* Lists all registrations with the matching tag.
|
|
1128
1275
|
* @param context - The Notification Hubs client.
|
|
@@ -1131,7 +1278,7 @@ function listNotificationHubJobs(context, options = {}) {
|
|
|
1131
1278
|
* @returns A paged async iterable containing the matching registrations for the notification hub.
|
|
1132
1279
|
*/
|
|
1133
1280
|
function listRegistrationsByTag(context, tag, options = {}) {
|
|
1134
|
-
const { span, updatedOptions } = tracingClient.startSpan(
|
|
1281
|
+
const { span, updatedOptions } = tracingClient.startSpan(`NotificationHubsClientContext-${OPERATION_NAME$5}`, options);
|
|
1135
1282
|
try {
|
|
1136
1283
|
const iter = listRegistrationsByTagAll(context, tag, updatedOptions);
|
|
1137
1284
|
return {
|
|
@@ -1193,7 +1340,7 @@ async function _listRegistrationsByTag(context, tag, options, continuationToken)
|
|
|
1193
1340
|
if (continuationToken !== undefined) {
|
|
1194
1341
|
endpoint.searchParams.set("continuationtoken", continuationToken);
|
|
1195
1342
|
}
|
|
1196
|
-
const headers = context.createHeaders();
|
|
1343
|
+
const headers = await context.createHeaders(OPERATION_NAME$5);
|
|
1197
1344
|
const request = createRequest(endpoint, "GET", headers, options);
|
|
1198
1345
|
const response = await sendRequest(context, request, 200);
|
|
1199
1346
|
const registrations = await registrationDescriptionParser.parseRegistrationFeed(response.bodyAsText);
|
|
@@ -1205,6 +1352,7 @@ async function _listRegistrationsByTag(context, tag, options, continuationToken)
|
|
|
1205
1352
|
}
|
|
1206
1353
|
|
|
1207
1354
|
// Copyright (c) Microsoft Corporation.
|
|
1355
|
+
const OPERATION_NAME$4 = "listRegistrations";
|
|
1208
1356
|
/**
|
|
1209
1357
|
* Gets all registrations for the notification hub with the given query options.
|
|
1210
1358
|
* @param context - The Notification Hubs client.
|
|
@@ -1212,7 +1360,7 @@ async function _listRegistrationsByTag(context, tag, options, continuationToken)
|
|
|
1212
1360
|
* @returns A paged async iterable containing all of the registrations for the notification hub.
|
|
1213
1361
|
*/
|
|
1214
1362
|
function listRegistrations(context, options = {}) {
|
|
1215
|
-
const { span, updatedOptions } = tracingClient.startSpan(
|
|
1363
|
+
const { span, updatedOptions } = tracingClient.startSpan(`NotificationHubsClientContext-${OPERATION_NAME$4}`, options);
|
|
1216
1364
|
try {
|
|
1217
1365
|
const iter = listRegistrationsAll(context, updatedOptions);
|
|
1218
1366
|
return {
|
|
@@ -1277,7 +1425,7 @@ async function _listRegistrations(context, options, continuationToken) {
|
|
|
1277
1425
|
if (continuationToken !== undefined) {
|
|
1278
1426
|
endpoint.searchParams.set("continuationtoken", continuationToken);
|
|
1279
1427
|
}
|
|
1280
|
-
const headers = context.createHeaders();
|
|
1428
|
+
const headers = await context.createHeaders(OPERATION_NAME$4);
|
|
1281
1429
|
const request = createRequest(endpoint, "GET", headers, options);
|
|
1282
1430
|
const response = await sendRequest(context, request, 200);
|
|
1283
1431
|
const registrations = await registrationDescriptionParser.parseRegistrationFeed(response.bodyAsText);
|
|
@@ -1289,14 +1437,15 @@ async function _listRegistrations(context, options, continuationToken) {
|
|
|
1289
1437
|
}
|
|
1290
1438
|
|
|
1291
1439
|
// Copyright (c) Microsoft Corporation.
|
|
1440
|
+
const OPERATION_NAME$3 = "scheduleNotificationPayload";
|
|
1292
1441
|
/**
|
|
1293
1442
|
* @internal
|
|
1294
1443
|
*/
|
|
1295
1444
|
function scheduleNotificationPayload(context, scheduledTime, tags, notification, options = {}) {
|
|
1296
|
-
return tracingClient.withSpan(
|
|
1445
|
+
return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$3}`, options, async (updatedOptions) => {
|
|
1297
1446
|
const endpoint = context.requestUrl();
|
|
1298
1447
|
endpoint.pathname += "/schedulednotifications/";
|
|
1299
|
-
const headers = context.createHeaders();
|
|
1448
|
+
const headers = await context.createHeaders(OPERATION_NAME$3);
|
|
1300
1449
|
if (notification.headers) {
|
|
1301
1450
|
for (const headerName of Object.keys(notification.headers)) {
|
|
1302
1451
|
headers.set(headerName, notification.headers[headerName]);
|
|
@@ -1362,9 +1511,9 @@ function sendNotificationPayload(context, notification, method, pushHandle, tags
|
|
|
1362
1511
|
const endpoint = context.requestUrl();
|
|
1363
1512
|
endpoint.pathname += "/messages/";
|
|
1364
1513
|
if (options.enableTestSend) {
|
|
1365
|
-
endpoint.searchParams.append("
|
|
1514
|
+
endpoint.searchParams.append("test", "true");
|
|
1366
1515
|
}
|
|
1367
|
-
const headers = context.createHeaders();
|
|
1516
|
+
const headers = await context.createHeaders(method);
|
|
1368
1517
|
if (notification.headers) {
|
|
1369
1518
|
for (const headerName of Object.keys(notification.headers)) {
|
|
1370
1519
|
headers.set(headerName, notification.headers[headerName]);
|
|
@@ -1420,8 +1569,7 @@ function sendBroadcastNotification(context, notification, options = {}) {
|
|
|
1420
1569
|
* @param context - The Notification Hubs client.
|
|
1421
1570
|
* @param pushHandle - The push handle which is the unique identifier for the device.
|
|
1422
1571
|
* @param notification - The notification to send to the device.
|
|
1423
|
-
* @param options -
|
|
1424
|
-
* which may include APNs specific such as apns-topic or for WNS, X-WNS-TYPE.
|
|
1572
|
+
* @param options - The options for sending a direct notification.
|
|
1425
1573
|
* @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
|
|
1426
1574
|
*/
|
|
1427
1575
|
function sendDirectNotification(context, pushHandle, notification, options = {}) {
|
|
@@ -1443,6 +1591,7 @@ function sendNotification(context, tags, notification, options = {}) {
|
|
|
1443
1591
|
}
|
|
1444
1592
|
|
|
1445
1593
|
// Copyright (c) Microsoft Corporation.
|
|
1594
|
+
const OPERATION_NAME$2 = "submitNotificationHubJob";
|
|
1446
1595
|
/**
|
|
1447
1596
|
* Submits a Notification Hub Job.
|
|
1448
1597
|
* Note: this is available to Standard SKU namespace and above.
|
|
@@ -1452,10 +1601,10 @@ function sendNotification(context, tags, notification, options = {}) {
|
|
|
1452
1601
|
* @returns The notification hub job details including job ID and status.
|
|
1453
1602
|
*/
|
|
1454
1603
|
function submitNotificationHubJob(context, job, options = {}) {
|
|
1455
|
-
return tracingClient.withSpan(
|
|
1604
|
+
return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$2}`, options, async (updatedOptions) => {
|
|
1456
1605
|
const endpoint = context.requestUrl();
|
|
1457
1606
|
endpoint.pathname += "/jobs";
|
|
1458
|
-
const headers = context.createHeaders();
|
|
1607
|
+
const headers = await context.createHeaders(OPERATION_NAME$2);
|
|
1459
1608
|
headers.set("Content-Type", "application/atom+xml;type=entry;charset=utf-8");
|
|
1460
1609
|
const request = createRequest(endpoint, "POST", headers, updatedOptions);
|
|
1461
1610
|
request.body = serializeNotificationHubJobEntry(job);
|
|
@@ -1465,6 +1614,7 @@ function submitNotificationHubJob(context, job, options = {}) {
|
|
|
1465
1614
|
}
|
|
1466
1615
|
|
|
1467
1616
|
// Copyright (c) Microsoft Corporation.
|
|
1617
|
+
const OPERATION_NAME$1 = "updateInstallation";
|
|
1468
1618
|
/**
|
|
1469
1619
|
* Updates an installation using the JSON-Patch standard in RFC6902.
|
|
1470
1620
|
* @param context - The Notification Hubs client.
|
|
@@ -1474,10 +1624,10 @@ function submitNotificationHubJob(context, job, options = {}) {
|
|
|
1474
1624
|
* @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
|
|
1475
1625
|
*/
|
|
1476
1626
|
function updateInstallation(context, installationId, installationPatches, options = {}) {
|
|
1477
|
-
return tracingClient.withSpan(
|
|
1627
|
+
return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME$1}`, options, async (updatedOptions) => {
|
|
1478
1628
|
const endpoint = context.requestUrl();
|
|
1479
1629
|
endpoint.pathname += `/installations/${installationId}`;
|
|
1480
|
-
const headers = context.createHeaders();
|
|
1630
|
+
const headers = await context.createHeaders(OPERATION_NAME$1);
|
|
1481
1631
|
headers.set("Content-Type", "application/json");
|
|
1482
1632
|
const request = createRequest(endpoint, "PATCH", headers, updatedOptions);
|
|
1483
1633
|
request.body = JSON.stringify(installationPatches);
|
|
@@ -1487,6 +1637,7 @@ function updateInstallation(context, installationId, installationPatches, option
|
|
|
1487
1637
|
}
|
|
1488
1638
|
|
|
1489
1639
|
// Copyright (c) Microsoft Corporation.
|
|
1640
|
+
const OPERATION_NAME = "updateRegistration";
|
|
1490
1641
|
/**
|
|
1491
1642
|
* Updates an existing registration.
|
|
1492
1643
|
* @param context - The Notification Hubs client.
|
|
@@ -1495,7 +1646,7 @@ function updateInstallation(context, installationId, installationPatches, option
|
|
|
1495
1646
|
* @returns The updated registration description.
|
|
1496
1647
|
*/
|
|
1497
1648
|
function updateRegistration(context, registration, options = {}) {
|
|
1498
|
-
return tracingClient.withSpan(
|
|
1649
|
+
return tracingClient.withSpan(`NotificationHubsClientContext-${OPERATION_NAME}`, options, async (updatedOptions) => {
|
|
1499
1650
|
if (!registration.etag) {
|
|
1500
1651
|
throw new coreRestPipeline.RestError("ETag is required for registration update", { statusCode: 400 });
|
|
1501
1652
|
}
|
|
@@ -1621,8 +1772,7 @@ class NotificationHubsServiceClient {
|
|
|
1621
1772
|
* Sends a direct push notification to a device with the given push handle.
|
|
1622
1773
|
* @param pushHandle - The push handle which is the unique identifier for the device.
|
|
1623
1774
|
* @param notification - The notification to send to the device.
|
|
1624
|
-
* @param options -
|
|
1625
|
-
* which may include APNs specific such as apns-topic or for WNS, X-WNS-TYPE.
|
|
1775
|
+
* @param options - The options for sending a direct notification.
|
|
1626
1776
|
* @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
|
|
1627
1777
|
*/
|
|
1628
1778
|
sendDirectNotification(pushHandle, notification, options = {}) {
|
|
@@ -1761,7 +1911,7 @@ function createBaiduInstallation(installation) {
|
|
|
1761
1911
|
* @param installation - A partial installation used to create the Firebase Legacy HTTP installation.
|
|
1762
1912
|
* @returns The newly created Baidu installation.
|
|
1763
1913
|
*/
|
|
1764
|
-
function
|
|
1914
|
+
function createFcmLegacyInstallation(installation) {
|
|
1765
1915
|
return Object.assign(Object.assign({}, installation), { platform: "gcm" });
|
|
1766
1916
|
}
|
|
1767
1917
|
/**
|
|
@@ -1781,17 +1931,6 @@ function createBrowserInstallation(installation) {
|
|
|
1781
1931
|
return Object.assign(Object.assign({}, installation), { platform: "browser" });
|
|
1782
1932
|
}
|
|
1783
1933
|
|
|
1784
|
-
// Copyright (c) Microsoft Corporation.
|
|
1785
|
-
// Licensed under the MIT license.
|
|
1786
|
-
const JSON_CONTENT_TYPE = "application/json;charset=utf-8";
|
|
1787
|
-
const XML_CONTENT_TYPE = "application/xml";
|
|
1788
|
-
const STREAM_CONTENT_TYPE = "application/octet-stream";
|
|
1789
|
-
const WNS_TYPE_NAME = "X-WNS-Type";
|
|
1790
|
-
const WNS_RAW = "wns/raw";
|
|
1791
|
-
const WNS_BADGE = "wns/badge";
|
|
1792
|
-
const WNS_TITLE = "wns/tile";
|
|
1793
|
-
const WNS_TOAST = "wns/toast";
|
|
1794
|
-
|
|
1795
1934
|
// Copyright (c) Microsoft Corporation.
|
|
1796
1935
|
/**
|
|
1797
1936
|
* Creates a notification to send to an Apple device.
|
|
@@ -1830,7 +1969,7 @@ function createBrowserNotification(notification) {
|
|
|
1830
1969
|
* @param notification - A partial message used to create a message for Firebase.
|
|
1831
1970
|
* @returns A newly created Firebase.
|
|
1832
1971
|
*/
|
|
1833
|
-
function
|
|
1972
|
+
function createFcmLegacyNotification(notification) {
|
|
1834
1973
|
return Object.assign(Object.assign({}, notification), { platform: "gcm", contentType: JSON_CONTENT_TYPE });
|
|
1835
1974
|
}
|
|
1836
1975
|
/**
|
|
@@ -1944,7 +2083,7 @@ function buildAppleNativeMessage(nativeMessage, additionalProperties) {
|
|
|
1944
2083
|
headers: headers,
|
|
1945
2084
|
});
|
|
1946
2085
|
}
|
|
1947
|
-
function
|
|
2086
|
+
function buildFcmLegacyNativePayload(nativeNotification) {
|
|
1948
2087
|
if (!isDefined(nativeNotification)) {
|
|
1949
2088
|
return undefined;
|
|
1950
2089
|
}
|
|
@@ -1971,9 +2110,9 @@ function buildFirebaseLegacyNativePayload(nativeNotification) {
|
|
|
1971
2110
|
return notification;
|
|
1972
2111
|
}
|
|
1973
2112
|
/**
|
|
1974
|
-
* Creates a
|
|
2113
|
+
* Creates a FcmLegacyNotification from a native Firebase payload.
|
|
1975
2114
|
* @param nativeMessage - The native message payload to send to Notification Hubs.
|
|
1976
|
-
* @returns The
|
|
2115
|
+
* @returns The FcmLegacyNotification to send to Notification Hubs.
|
|
1977
2116
|
*/
|
|
1978
2117
|
function buildFirebaseLegacyNativeMessage(nativeMessage) {
|
|
1979
2118
|
const jsonMessage = {
|
|
@@ -1988,9 +2127,9 @@ function buildFirebaseLegacyNativeMessage(nativeMessage) {
|
|
|
1988
2127
|
restricted_package_name: nativeMessage.restrictedPackageName,
|
|
1989
2128
|
dry_run: nativeMessage.dryRun,
|
|
1990
2129
|
data: nativeMessage.data,
|
|
1991
|
-
notification:
|
|
2130
|
+
notification: buildFcmLegacyNativePayload(nativeMessage.notification),
|
|
1992
2131
|
};
|
|
1993
|
-
return
|
|
2132
|
+
return createFcmLegacyNotification({
|
|
1994
2133
|
body: JSON.stringify(jsonMessage),
|
|
1995
2134
|
});
|
|
1996
2135
|
}
|
|
@@ -2126,57 +2265,21 @@ function createBrowserTemplateRegistrationDescription(description) {
|
|
|
2126
2265
|
return Object.assign(Object.assign({}, description), { type: "BrowserTemplate" });
|
|
2127
2266
|
}
|
|
2128
2267
|
/**
|
|
2129
|
-
*
|
|
2130
|
-
* Creates a GCM registration description.
|
|
2268
|
+
* Creates a Firebase Legacy registration description.
|
|
2131
2269
|
* @param description - A partial GCM registration description.
|
|
2132
2270
|
* @returns A created GCM registration description.
|
|
2133
2271
|
*/
|
|
2134
|
-
function
|
|
2272
|
+
function createFcmLegacyRegistrationDescription(description) {
|
|
2135
2273
|
return Object.assign(Object.assign({}, description), { type: "Gcm" });
|
|
2136
2274
|
}
|
|
2137
2275
|
/**
|
|
2138
|
-
* @deprecated Use createFcmTemplateRegistrationDescription instead.
|
|
2139
2276
|
* Creates a GCM template registration description.
|
|
2140
2277
|
* @param description - A partial GCM template registration description.
|
|
2141
2278
|
* @returns A created GCM template registration description.
|
|
2142
2279
|
*/
|
|
2143
|
-
function
|
|
2280
|
+
function createFcmLegacyTemplateRegistrationDescription(description) {
|
|
2144
2281
|
return Object.assign(Object.assign({}, description), { type: "GcmTemplate" });
|
|
2145
2282
|
}
|
|
2146
|
-
/**
|
|
2147
|
-
* Creates an FCM registration description.
|
|
2148
|
-
* @param description - A partial FCM registration description.
|
|
2149
|
-
* @returns A created FCM registration description.
|
|
2150
|
-
*/
|
|
2151
|
-
function createFcmRegistrationDescription(description) {
|
|
2152
|
-
return Object.assign(Object.assign({}, description), { type: "Fcm" });
|
|
2153
|
-
}
|
|
2154
|
-
/**
|
|
2155
|
-
* Creates an FCM template registration description.
|
|
2156
|
-
* @param description - A partial FCM template registration description.
|
|
2157
|
-
* @returns A created FCM template registration description.
|
|
2158
|
-
*/
|
|
2159
|
-
function createFcmTemplateRegistrationDescription(description) {
|
|
2160
|
-
return Object.assign(Object.assign({}, description), { type: "FcmTemplate" });
|
|
2161
|
-
}
|
|
2162
|
-
/**
|
|
2163
|
-
* @deprecated Windows Phone is no longer supported.
|
|
2164
|
-
* Creates an MPNS registration description.
|
|
2165
|
-
* @param description - A partial MPNS registration description.
|
|
2166
|
-
* @returns A created MPNS registration description.
|
|
2167
|
-
*/
|
|
2168
|
-
function createMpnsRegistrationDescription(description) {
|
|
2169
|
-
return Object.assign(Object.assign({}, description), { type: "Mpns" });
|
|
2170
|
-
}
|
|
2171
|
-
/**
|
|
2172
|
-
* @deprecated Windows Phone is no longer supported.
|
|
2173
|
-
* Creates an MPNS template registration description.
|
|
2174
|
-
* @param description - A partial MPNS template registration description.
|
|
2175
|
-
* @returns A created MPNS template registration description.
|
|
2176
|
-
*/
|
|
2177
|
-
function createMpnsTemplateRegistrationDescription(description) {
|
|
2178
|
-
return Object.assign(Object.assign({}, description), { type: "MpnsTemplate" });
|
|
2179
|
-
}
|
|
2180
2283
|
/**
|
|
2181
2284
|
* Creates a Windows registration description.
|
|
2182
2285
|
* @param description - A partial Windows registration description.
|
|
@@ -2216,14 +2319,10 @@ exports.createBrowserInstallation = createBrowserInstallation;
|
|
|
2216
2319
|
exports.createBrowserNotification = createBrowserNotification;
|
|
2217
2320
|
exports.createBrowserRegistrationDescription = createBrowserRegistrationDescription;
|
|
2218
2321
|
exports.createBrowserTemplateRegistrationDescription = createBrowserTemplateRegistrationDescription;
|
|
2219
|
-
exports.
|
|
2220
|
-
exports.
|
|
2221
|
-
exports.
|
|
2222
|
-
exports.
|
|
2223
|
-
exports.createGcmRegistrationDescription = createGcmRegistrationDescription;
|
|
2224
|
-
exports.createGcmTemplateRegistrationDescription = createGcmTemplateRegistrationDescription;
|
|
2225
|
-
exports.createMpnsRegistrationDescription = createMpnsRegistrationDescription;
|
|
2226
|
-
exports.createMpnsTemplateRegistrationDescription = createMpnsTemplateRegistrationDescription;
|
|
2322
|
+
exports.createFcmLegacyInstallation = createFcmLegacyInstallation;
|
|
2323
|
+
exports.createFcmLegacyNotification = createFcmLegacyNotification;
|
|
2324
|
+
exports.createFcmLegacyRegistrationDescription = createFcmLegacyRegistrationDescription;
|
|
2325
|
+
exports.createFcmLegacyTemplateRegistrationDescription = createFcmLegacyTemplateRegistrationDescription;
|
|
2227
2326
|
exports.createTemplateNotification = createTemplateNotification;
|
|
2228
2327
|
exports.createWindowsBadgeNotification = createWindowsBadgeNotification;
|
|
2229
2328
|
exports.createWindowsInstallation = createWindowsInstallation;
|