@azure/notification-hubs 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +749 -0
- package/dist/index.js +2235 -0
- package/dist/index.js.map +1 -0
- package/dist-esm/src/client/cancelScheduledNotification.js +23 -0
- package/dist-esm/src/client/cancelScheduledNotification.js.map +1 -0
- package/dist-esm/src/client/createOrUpdateInstallation.js +24 -0
- package/dist-esm/src/client/createOrUpdateInstallation.js.map +1 -0
- package/dist-esm/src/client/createOrUpdateRegistration.js +17 -0
- package/dist-esm/src/client/createOrUpdateRegistration.js.map +1 -0
- package/dist-esm/src/client/createRegistration.js +24 -0
- package/dist-esm/src/client/createRegistration.js.map +1 -0
- package/dist-esm/src/client/createRegistrationId.js +26 -0
- package/dist-esm/src/client/createRegistrationId.js.map +1 -0
- package/dist-esm/src/client/deleteInstallation.js +22 -0
- package/dist-esm/src/client/deleteInstallation.js.map +1 -0
- package/dist-esm/src/client/deleteRegistration.js +25 -0
- package/dist-esm/src/client/deleteRegistration.js.map +1 -0
- package/dist-esm/src/client/getFeedbackContainerUrl.js +23 -0
- package/dist-esm/src/client/getFeedbackContainerUrl.js.map +1 -0
- package/dist-esm/src/client/getInstallation.js +23 -0
- package/dist-esm/src/client/getInstallation.js.map +1 -0
- package/dist-esm/src/client/getNotificationHubJob.js +24 -0
- package/dist-esm/src/client/getNotificationHubJob.js.map +1 -0
- package/dist-esm/src/client/getNotificationOutcomeDetails.js +24 -0
- package/dist-esm/src/client/getNotificationOutcomeDetails.js.map +1 -0
- package/dist-esm/src/client/getRegistration.js +24 -0
- package/dist-esm/src/client/getRegistration.js.map +1 -0
- package/dist-esm/src/client/index.js +44 -0
- package/dist-esm/src/client/index.js.map +1 -0
- package/dist-esm/src/client/internal/_client.js +75 -0
- package/dist-esm/src/client/internal/_client.js.map +1 -0
- package/dist-esm/src/client/internal/_createOrUpdateRegistrationDescription.js +31 -0
- package/dist-esm/src/client/internal/_createOrUpdateRegistrationDescription.js.map +1 -0
- package/dist-esm/src/client/internal/_scheduleNotificationPayload.js +37 -0
- package/dist-esm/src/client/internal/_scheduleNotificationPayload.js.map +1 -0
- package/dist-esm/src/client/internal/_sendNotificationPayload.js +51 -0
- package/dist-esm/src/client/internal/_sendNotificationPayload.js.map +1 -0
- package/dist-esm/src/client/listNotificationHubJobs.js +23 -0
- package/dist-esm/src/client/listNotificationHubJobs.js.map +1 -0
- package/dist-esm/src/client/listRegistrations.js +89 -0
- package/dist-esm/src/client/listRegistrations.js.map +1 -0
- package/dist-esm/src/client/listRegistrationsByTag.js +87 -0
- package/dist-esm/src/client/listRegistrationsByTag.js.map +1 -0
- package/dist-esm/src/client/scheduleBroadcastNotification.js +17 -0
- package/dist-esm/src/client/scheduleBroadcastNotification.js.map +1 -0
- package/dist-esm/src/client/scheduleNotification.js +18 -0
- package/dist-esm/src/client/scheduleNotification.js.map +1 -0
- package/dist-esm/src/client/sendBroadcastNotification.js +15 -0
- package/dist-esm/src/client/sendBroadcastNotification.js.map +1 -0
- package/dist-esm/src/client/sendDirectNotification.js +16 -0
- package/dist-esm/src/client/sendDirectNotification.js.map +1 -0
- package/dist-esm/src/client/sendNotification.js +16 -0
- package/dist-esm/src/client/sendNotification.js.map +1 -0
- package/dist-esm/src/client/submitNotificationHubJob.js +26 -0
- package/dist-esm/src/client/submitNotificationHubJob.js.map +1 -0
- package/dist-esm/src/client/updateInstallation.js +25 -0
- package/dist-esm/src/client/updateInstallation.js.map +1 -0
- package/dist-esm/src/client/updateRegistration.js +21 -0
- package/dist-esm/src/client/updateRegistration.js.map +1 -0
- package/dist-esm/src/index.js +12 -0
- package/dist-esm/src/index.js.map +1 -0
- package/dist-esm/src/models/installation.js +51 -0
- package/dist-esm/src/models/installation.js.map +1 -0
- package/dist-esm/src/models/notification.js +104 -0
- package/dist-esm/src/models/notification.js.map +1 -0
- package/dist-esm/src/models/notificationBuilder.js +169 -0
- package/dist-esm/src/models/notificationBuilder.js.map +1 -0
- package/dist-esm/src/models/notificationDetails.js +4 -0
- package/dist-esm/src/models/notificationDetails.js.map +1 -0
- package/dist-esm/src/models/notificationHubJob.js +4 -0
- package/dist-esm/src/models/notificationHubJob.js.map +1 -0
- package/dist-esm/src/models/options.js +4 -0
- package/dist-esm/src/models/options.js.map +1 -0
- package/dist-esm/src/models/registration.js +135 -0
- package/dist-esm/src/models/registration.js.map +1 -0
- package/dist-esm/src/models/response.js +4 -0
- package/dist-esm/src/models/response.js.map +1 -0
- package/dist-esm/src/notificationHubsClient.js +251 -0
- package/dist-esm/src/notificationHubsClient.js.map +1 -0
- package/dist-esm/src/serializers/notificationDetailsSerializer.js +58 -0
- package/dist-esm/src/serializers/notificationDetailsSerializer.js.map +1 -0
- package/dist-esm/src/serializers/notificationHubJobSerializer.js +74 -0
- package/dist-esm/src/serializers/notificationHubJobSerializer.js.map +1 -0
- package/dist-esm/src/serializers/registrationSerializer.js +375 -0
- package/dist-esm/src/serializers/registrationSerializer.js.map +1 -0
- package/dist-esm/src/utils/connectionStringUtils.js +37 -0
- package/dist-esm/src/utils/connectionStringUtils.js.map +1 -0
- package/dist-esm/src/utils/constants.js +11 -0
- package/dist-esm/src/utils/constants.js.map +1 -0
- package/dist-esm/src/utils/retryPolicy.js +144 -0
- package/dist-esm/src/utils/retryPolicy.js.map +1 -0
- package/dist-esm/src/utils/tracing.js +13 -0
- package/dist-esm/src/utils/tracing.js.map +1 -0
- package/dist-esm/src/utils/utils.js +130 -0
- package/dist-esm/src/utils/utils.js.map +1 -0
- package/dist-esm/src/utils/xmlUtils.js +101 -0
- package/dist-esm/src/utils/xmlUtils.js.map +1 -0
- package/package.json +144 -0
- package/types/3.1/notification-hubs.d.ts +1728 -0
- package/types/latest/notification-hubs.d.ts +1840 -0
- package/types/latest/tsdoc-metadata.json +11 -0
- package/types/src/client/cancelScheduledNotification.d.ts +13 -0
- package/types/src/client/cancelScheduledNotification.d.ts.map +1 -0
- package/types/src/client/createOrUpdateInstallation.d.ts +13 -0
- package/types/src/client/createOrUpdateInstallation.d.ts.map +1 -0
- package/types/src/client/createOrUpdateRegistration.d.ts +12 -0
- package/types/src/client/createOrUpdateRegistration.d.ts.map +1 -0
- package/types/src/client/createRegistration.d.ts +13 -0
- package/types/src/client/createRegistration.d.ts.map +1 -0
- package/types/src/client/createRegistrationId.d.ts +10 -0
- package/types/src/client/createRegistrationId.d.ts.map +1 -0
- package/types/src/client/deleteInstallation.d.ts +12 -0
- package/types/src/client/deleteInstallation.d.ts.map +1 -0
- package/types/src/client/deleteRegistration.d.ts +12 -0
- package/types/src/client/deleteRegistration.d.ts.map +1 -0
- package/types/src/client/getFeedbackContainerUrl.d.ts +11 -0
- package/types/src/client/getFeedbackContainerUrl.d.ts.map +1 -0
- package/types/src/client/getInstallation.d.ts +12 -0
- package/types/src/client/getInstallation.d.ts.map +1 -0
- package/types/src/client/getNotificationHubJob.d.ts +12 -0
- package/types/src/client/getNotificationHubJob.d.ts.map +1 -0
- package/types/src/client/getNotificationOutcomeDetails.d.ts +13 -0
- package/types/src/client/getNotificationOutcomeDetails.d.ts.map +1 -0
- package/types/src/client/getRegistration.d.ts +12 -0
- package/types/src/client/getRegistration.d.ts.map +1 -0
- package/types/src/client/index.d.ts +41 -0
- package/types/src/client/index.d.ts.map +1 -0
- package/types/src/client/internal/_client.d.ts +26 -0
- package/types/src/client/internal/_client.d.ts.map +1 -0
- package/types/src/client/internal/_createOrUpdateRegistrationDescription.d.ts +8 -0
- package/types/src/client/internal/_createOrUpdateRegistrationDescription.d.ts.map +1 -0
- package/types/src/client/internal/_scheduleNotificationPayload.d.ts +9 -0
- package/types/src/client/internal/_scheduleNotificationPayload.d.ts.map +1 -0
- package/types/src/client/internal/_sendNotificationPayload.d.ts +10 -0
- package/types/src/client/internal/_sendNotificationPayload.d.ts.map +1 -0
- package/types/src/client/listNotificationHubJobs.d.ts +11 -0
- package/types/src/client/listNotificationHubJobs.d.ts.map +1 -0
- package/types/src/client/listRegistrations.d.ts +12 -0
- package/types/src/client/listRegistrations.d.ts.map +1 -0
- package/types/src/client/listRegistrationsByTag.d.ts +13 -0
- package/types/src/client/listRegistrationsByTag.d.ts.map +1 -0
- package/types/src/client/scheduleBroadcastNotification.d.ts +16 -0
- package/types/src/client/scheduleBroadcastNotification.d.ts.map +1 -0
- package/types/src/client/scheduleNotification.d.ts +17 -0
- package/types/src/client/scheduleNotification.d.ts.map +1 -0
- package/types/src/client/sendBroadcastNotification.d.ts +14 -0
- package/types/src/client/sendBroadcastNotification.d.ts.map +1 -0
- package/types/src/client/sendDirectNotification.d.ts +16 -0
- package/types/src/client/sendDirectNotification.d.ts.map +1 -0
- package/types/src/client/sendNotification.d.ts +15 -0
- package/types/src/client/sendNotification.d.ts.map +1 -0
- package/types/src/client/submitNotificationHubJob.d.ts +13 -0
- package/types/src/client/submitNotificationHubJob.d.ts.map +1 -0
- package/types/src/client/updateInstallation.d.ts +14 -0
- package/types/src/client/updateInstallation.d.ts.map +1 -0
- package/types/src/client/updateRegistration.d.ts +12 -0
- package/types/src/client/updateRegistration.d.ts.map +1 -0
- package/types/src/index.d.ts +10 -0
- package/types/src/index.d.ts.map +1 -0
- package/types/src/models/installation.d.ts +200 -0
- package/types/src/models/installation.d.ts.map +1 -0
- package/types/src/models/notification.d.ts +166 -0
- package/types/src/models/notification.d.ts.map +1 -0
- package/types/src/models/notificationBuilder.d.ts +546 -0
- package/types/src/models/notificationBuilder.d.ts.map +1 -0
- package/types/src/models/notificationDetails.d.ts +87 -0
- package/types/src/models/notificationDetails.d.ts.map +1 -0
- package/types/src/models/notificationHubJob.d.ts +104 -0
- package/types/src/models/notificationHubJob.d.ts.map +1 -0
- package/types/src/models/options.d.ts +43 -0
- package/types/src/models/options.d.ts.map +1 -0
- package/types/src/models/registration.d.ts +368 -0
- package/types/src/models/registration.d.ts.map +1 -0
- package/types/src/models/response.d.ts +41 -0
- package/types/src/models/response.d.ts.map +1 -0
- package/types/src/notificationHubsClient.d.ts +190 -0
- package/types/src/notificationHubsClient.d.ts.map +1 -0
- package/types/src/serializers/notificationDetailsSerializer.d.ts +7 -0
- package/types/src/serializers/notificationDetailsSerializer.d.ts.map +1 -0
- package/types/src/serializers/notificationHubJobSerializer.d.ts +21 -0
- package/types/src/serializers/notificationHubJobSerializer.d.ts.map +1 -0
- package/types/src/serializers/registrationSerializer.d.ts +193 -0
- package/types/src/serializers/registrationSerializer.d.ts.map +1 -0
- package/types/src/utils/connectionStringUtils.d.ts +37 -0
- package/types/src/utils/connectionStringUtils.d.ts.map +1 -0
- package/types/src/utils/constants.d.ts +9 -0
- package/types/src/utils/constants.d.ts.map +1 -0
- package/types/src/utils/retryPolicy.d.ts +72 -0
- package/types/src/utils/retryPolicy.d.ts.map +1 -0
- package/types/src/utils/tracing.d.ts +6 -0
- package/types/src/utils/tracing.d.ts.map +1 -0
- package/types/src/utils/utils.d.ts +65 -0
- package/types/src/utils/utils.d.ts.map +1 -0
- package/types/src/utils/xmlUtils.d.ts +46 -0
- package/types/src/utils/xmlUtils.d.ts.map +1 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2235 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var coreRestPipeline = require('@azure/core-rest-pipeline');
|
|
6
|
+
var coreAmqp = require('@azure/core-amqp');
|
|
7
|
+
var coreXml = require('@azure/core-xml');
|
|
8
|
+
var coreClient = require('@azure/core-client');
|
|
9
|
+
var coreTracing = require('@azure/core-tracing');
|
|
10
|
+
var tslib = require('tslib');
|
|
11
|
+
|
|
12
|
+
// Copyright (c) Microsoft Corporation.
|
|
13
|
+
/**
|
|
14
|
+
* Creates a SasTokenProvider from a shared access key and shared access key name.
|
|
15
|
+
* @param sharedAccessKey - The shared access key value.
|
|
16
|
+
* @param sharedAccessKeyName - The shared access key name.
|
|
17
|
+
* @returns A SasTokenProvider with the given shared access token information.
|
|
18
|
+
*/
|
|
19
|
+
function createTokenProviderFromConnection(sharedAccessKey, sharedAccessKeyName) {
|
|
20
|
+
return coreAmqp.createSasTokenProvider({ sharedAccessKey, sharedAccessKeyName });
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Parses given connection string into the different properties applicable to Azure Service Bus.
|
|
24
|
+
* The properties are useful to then construct a ServiceBusClient.
|
|
25
|
+
* @param connectionString - The connection string associated with the Shared Access Policy created
|
|
26
|
+
* for the Service Bus namespace, queue or topic.
|
|
27
|
+
*/
|
|
28
|
+
function parseNotificationHubsConnectionString(connectionString) {
|
|
29
|
+
const parsedResult = coreAmqp.parseConnectionString(connectionString);
|
|
30
|
+
if (!parsedResult.Endpoint) {
|
|
31
|
+
throw new Error("Connection string should have an Endpoint key.");
|
|
32
|
+
}
|
|
33
|
+
if (parsedResult.SharedAccessKey && !parsedResult.SharedAccessKeyName) {
|
|
34
|
+
throw new Error("Connection string with SharedAccessKey should have SharedAccessKeyName.");
|
|
35
|
+
}
|
|
36
|
+
else if (!parsedResult.SharedAccessKey && parsedResult.SharedAccessKeyName) {
|
|
37
|
+
throw new Error("Connection string with SharedAccessKeyName should have SharedAccessKey as well.");
|
|
38
|
+
}
|
|
39
|
+
const output = {
|
|
40
|
+
endpoint: parsedResult.Endpoint,
|
|
41
|
+
sharedAccessKey: parsedResult.SharedAccessKey,
|
|
42
|
+
sharedAccessKeyName: parsedResult.SharedAccessKeyName,
|
|
43
|
+
};
|
|
44
|
+
return output;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Copyright (c) Microsoft Corporation.
|
|
48
|
+
const API_VERSION = "2020-06";
|
|
49
|
+
/**
|
|
50
|
+
* Creates a NotificationHubClient from the Access Policy connection string and hub name.
|
|
51
|
+
* @param connectionString - The Access Policy connection string for the notification hub.
|
|
52
|
+
* @param hubName - The notification hub name.
|
|
53
|
+
* @returns A NotificationHubsClientContext initialized from the connection string and hub name.
|
|
54
|
+
*/
|
|
55
|
+
function createClientContext(connectionString, hubName, options = {}) {
|
|
56
|
+
return new NotificationHubsServiceClient$1(connectionString, hubName, options);
|
|
57
|
+
}
|
|
58
|
+
class NotificationHubsServiceClient$1 extends coreClient.ServiceClient {
|
|
59
|
+
constructor(connectionString, hubName, options = {}) {
|
|
60
|
+
super(Object.assign({ deserializationOptions: {
|
|
61
|
+
parseXML: coreXml.parseXML,
|
|
62
|
+
}, serializationOptions: {
|
|
63
|
+
stringifyXML: coreXml.stringifyXML,
|
|
64
|
+
} }, options));
|
|
65
|
+
this.hubName = hubName;
|
|
66
|
+
const parsedConnection = parseNotificationHubsConnectionString(connectionString);
|
|
67
|
+
this.baseUrl = parsedConnection.endpoint;
|
|
68
|
+
this.sasTokenProvider = createTokenProviderFromConnection(parsedConnection.sharedAccessKey, parsedConnection.sharedAccessKeyName);
|
|
69
|
+
}
|
|
70
|
+
createHeaders() {
|
|
71
|
+
const authorization = this.sasTokenProvider.getToken(this.baseUrl);
|
|
72
|
+
const headers = coreRestPipeline.createHttpHeaders();
|
|
73
|
+
headers.set("Authorization", authorization.token);
|
|
74
|
+
headers.set("x-ms-version", API_VERSION);
|
|
75
|
+
return headers;
|
|
76
|
+
}
|
|
77
|
+
requestUrl() {
|
|
78
|
+
// Node doesn't allow change in protocol but browsers do, so doing a string replace
|
|
79
|
+
const url = new URL(this.baseUrl.replace("sb://", "https://"));
|
|
80
|
+
url.pathname = this.hubName;
|
|
81
|
+
url.searchParams.set("api-version", API_VERSION);
|
|
82
|
+
return url;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Copyright (c) Microsoft Corporation.
|
|
87
|
+
// Licensed under the MIT license.
|
|
88
|
+
/**
|
|
89
|
+
* Helper TypeGuard that checks if something is defined or not.
|
|
90
|
+
* @param thing - Anything
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
93
|
+
function isDefined(thing) {
|
|
94
|
+
return typeof thing !== "undefined" && thing !== null;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Helper TypeGuard that checks if something is a string or not.
|
|
98
|
+
* @param thing - Anything
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
101
|
+
function isString(thing) {
|
|
102
|
+
return typeof thing === "string" || thing instanceof String;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* @internal
|
|
106
|
+
* Helper utility to retrieve `string` value from given string,
|
|
107
|
+
* or throws error if undefined.
|
|
108
|
+
*/
|
|
109
|
+
function getString(value, nameOfProperty) {
|
|
110
|
+
const result = getStringOrUndefined(value);
|
|
111
|
+
if (result === undefined) {
|
|
112
|
+
throw new Error(`"${nameOfProperty}" received from service expected to be a string value and not undefined.`);
|
|
113
|
+
}
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* @internal
|
|
118
|
+
* Helper utility to retrieve `string` value from given input,
|
|
119
|
+
* or undefined if not passed in.
|
|
120
|
+
*/
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
122
|
+
function getStringOrUndefined(value) {
|
|
123
|
+
if (!isDefined(value)) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
return value.toString();
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* @internal
|
|
130
|
+
* Helper utility to retrieve `integer` value from given string,
|
|
131
|
+
* or throws error if undefined.
|
|
132
|
+
*/
|
|
133
|
+
function getInteger(value, nameOfProperty) {
|
|
134
|
+
const result = getIntegerOrUndefined(value);
|
|
135
|
+
if (result === undefined) {
|
|
136
|
+
throw new Error(`"${nameOfProperty}" received from service expected to be a number value and not undefined.`);
|
|
137
|
+
}
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* @internal
|
|
142
|
+
* Helper utility to retrieve `integer` value from given string,
|
|
143
|
+
* or undefined if not passed in.
|
|
144
|
+
*/
|
|
145
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
146
|
+
function getIntegerOrUndefined(value) {
|
|
147
|
+
if (!isDefined(value)) {
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
const result = parseInt(value.toString());
|
|
151
|
+
return isNaN(result) ? undefined : result;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* @internal
|
|
155
|
+
* Helper utility to retrieve `float` value from given string,
|
|
156
|
+
* or undefined if not passed in.
|
|
157
|
+
*/
|
|
158
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
159
|
+
function getFloatOrUndefined(value) {
|
|
160
|
+
if (!isDefined(value)) {
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
const result = parseFloat(value.toString());
|
|
164
|
+
return Number.isNaN(result) ? undefined : result;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* @internal
|
|
168
|
+
* Helper utility to convert ISO-8601 time into Date type,
|
|
169
|
+
* or undefined if not passed in.
|
|
170
|
+
*/
|
|
171
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
172
|
+
function getDateOrUndefined(value) {
|
|
173
|
+
const stringValue = getStringOrUndefined(value);
|
|
174
|
+
if (stringValue === undefined) {
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
const result = new Date(stringValue.toString());
|
|
178
|
+
return Number.isNaN(+result) ? undefined : result;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* @internal
|
|
182
|
+
* Helper utility to parse tags from a comma separated string.
|
|
183
|
+
*/
|
|
184
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
185
|
+
function getTagsOrUndefined(value) {
|
|
186
|
+
const result = getStringOrUndefined(value);
|
|
187
|
+
if (result === undefined) {
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
return result.split(",");
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Copyright (c) Microsoft Corporation.
|
|
194
|
+
/**
|
|
195
|
+
* Marker for atom metadata.
|
|
196
|
+
*
|
|
197
|
+
* @internal
|
|
198
|
+
*/
|
|
199
|
+
const XML_METADATA_MARKER = "$";
|
|
200
|
+
/**
|
|
201
|
+
* @internal
|
|
202
|
+
* Helps in differentiating JSON like objects from other kinds of objects.
|
|
203
|
+
*/
|
|
204
|
+
const EMPTY_JSON_OBJECT_CONSTRUCTOR = {}.constructor;
|
|
205
|
+
/**
|
|
206
|
+
* @internal
|
|
207
|
+
* Returns `true` if given input is a JSON like object.
|
|
208
|
+
*/
|
|
209
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
210
|
+
function isJSONLikeObject(value) {
|
|
211
|
+
// `value.constructor === {}.constructor` differentiates among the "object"s,
|
|
212
|
+
// would filter the JSON objects and won't match any array or other kinds of objects
|
|
213
|
+
// -------------------------------------------------------------------------------
|
|
214
|
+
// Few examples | typeof obj ==="object" | obj.constructor==={}.constructor
|
|
215
|
+
// -------------------------------------------------------------------------------
|
|
216
|
+
// {abc:1} | true | true
|
|
217
|
+
// ["a","b"] | true | false
|
|
218
|
+
// [{"a":1},{"b":2}] | true | false
|
|
219
|
+
// new Date() | true | false
|
|
220
|
+
// 123 | false | false
|
|
221
|
+
// -------------------------------------------------------------------------------
|
|
222
|
+
return typeof value === "object" && value.constructor === EMPTY_JSON_OBJECT_CONSTRUCTOR;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* @internal
|
|
226
|
+
* The key-value pairs having undefined/null as the values would lead to the empty tags in the serialized XML request.
|
|
227
|
+
* Empty tags in the request body is problematic because of the following reasons.
|
|
228
|
+
* - ATOM based management operations throw a "Bad Request" error if empty tags are included in the XML request body at top level.
|
|
229
|
+
* - At the inner levels, Service assigns the empty strings as values to the empty tags instead of throwing an error.
|
|
230
|
+
*
|
|
231
|
+
* This method recursively removes the key-value pairs with undefined/null as the values from the request object that is to be serialized.
|
|
232
|
+
*
|
|
233
|
+
*/
|
|
234
|
+
function sanitizeSerializableObject(resource) {
|
|
235
|
+
Object.keys(resource).forEach(function (property) {
|
|
236
|
+
if (!isDefined(resource[property])) {
|
|
237
|
+
delete resource[property];
|
|
238
|
+
}
|
|
239
|
+
else if (isJSONLikeObject(resource[property])) {
|
|
240
|
+
sanitizeSerializableObject(resource[property]);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* @internal
|
|
246
|
+
* Serializes input information to construct the Atom XML request
|
|
247
|
+
* @param resourceName - Name of the resource to be serialized like `QueueDescription`
|
|
248
|
+
* @param resource - The entity details
|
|
249
|
+
* @returns An object to be serialized into a string.
|
|
250
|
+
*/
|
|
251
|
+
function serializeToAtomXmlRequest(resourceName, resource) {
|
|
252
|
+
const content = {};
|
|
253
|
+
content[resourceName] = Object.assign({}, resource);
|
|
254
|
+
sanitizeSerializableObject(content[resourceName]);
|
|
255
|
+
content[resourceName][XML_METADATA_MARKER] = {
|
|
256
|
+
xmlns: "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
|
|
257
|
+
"xmlns:i": "http://www.w3.org/2001/XMLSchema-instance",
|
|
258
|
+
};
|
|
259
|
+
content[XML_METADATA_MARKER] = { type: "application/xml" };
|
|
260
|
+
const requestDetails = {
|
|
261
|
+
updated: new Date().toISOString(),
|
|
262
|
+
content: content,
|
|
263
|
+
};
|
|
264
|
+
requestDetails[XML_METADATA_MARKER] = {
|
|
265
|
+
xmlns: "http://www.w3.org/2005/Atom",
|
|
266
|
+
};
|
|
267
|
+
return requestDetails;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* @internal
|
|
271
|
+
* Parses the XML message from a Notification Hubs response
|
|
272
|
+
* @param bodyText - The HTTP response body.
|
|
273
|
+
* @returns The notification details if any from the XML.
|
|
274
|
+
*/
|
|
275
|
+
async function parseXMLError(bodyText) {
|
|
276
|
+
let result;
|
|
277
|
+
const xmlError = await coreXml.parseXML(bodyText, { includeRoot: true });
|
|
278
|
+
const detail = xmlError["Detail"];
|
|
279
|
+
if (isDefined(detail)) {
|
|
280
|
+
return detail;
|
|
281
|
+
}
|
|
282
|
+
return result;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Copyright (c) Microsoft Corporation.
|
|
286
|
+
/**
|
|
287
|
+
* @internal
|
|
288
|
+
*/
|
|
289
|
+
function createRequest(endpoint, method, headers, options) {
|
|
290
|
+
return coreRestPipeline.createPipelineRequest(Object.assign(Object.assign(Object.assign({}, options.tracingOptions), options.requestOptions), { url: endpoint.toString(), abortSignal: options.abortSignal, method,
|
|
291
|
+
headers }));
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* @internal
|
|
295
|
+
*/
|
|
296
|
+
function parseNotificationResponse(response) {
|
|
297
|
+
const correlationId = response.headers.get("x-ms-correlation-request-id");
|
|
298
|
+
const trackingId = response.headers.get("TrackingId");
|
|
299
|
+
const location = response.headers.get("Location");
|
|
300
|
+
return {
|
|
301
|
+
correlationId,
|
|
302
|
+
trackingId,
|
|
303
|
+
location,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* @internal
|
|
308
|
+
*/
|
|
309
|
+
function parseNotificationSendResponse(response) {
|
|
310
|
+
const result = parseNotificationResponse(response);
|
|
311
|
+
let notificationId;
|
|
312
|
+
if (result.location) {
|
|
313
|
+
const locationUrl = new URL(result.location);
|
|
314
|
+
notificationId = locationUrl.pathname.split("/")[3];
|
|
315
|
+
}
|
|
316
|
+
return Object.assign(Object.assign({}, result), { notificationId });
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Sends a request through the client context.
|
|
320
|
+
* @param context - The client context to use.
|
|
321
|
+
* @param request - The HTTP request to send.
|
|
322
|
+
* @param successStatusCode - A status code or list of status codes to check for success.
|
|
323
|
+
* @returns The HTTP Response.
|
|
324
|
+
*/
|
|
325
|
+
async function sendRequest(context, request, successStatusCode) {
|
|
326
|
+
const statuses = Array.isArray(successStatusCode)
|
|
327
|
+
? successStatusCode
|
|
328
|
+
: [successStatusCode];
|
|
329
|
+
const response = await context.sendRequest(request);
|
|
330
|
+
if (!statuses.some((statusCode) => statusCode === response.status)) {
|
|
331
|
+
const responseBody = response.bodyAsText;
|
|
332
|
+
let details;
|
|
333
|
+
if (isDefined(responseBody)) {
|
|
334
|
+
try {
|
|
335
|
+
details = await parseXMLError(responseBody);
|
|
336
|
+
}
|
|
337
|
+
catch (err) {
|
|
338
|
+
// eslint-disable no-empty
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
let errorMessage;
|
|
342
|
+
if (isDefined(details)) {
|
|
343
|
+
errorMessage = `operations failed with: ${details}`;
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
errorMessage = `operation failed with status ${response.status}`;
|
|
347
|
+
}
|
|
348
|
+
throw new coreRestPipeline.RestError(errorMessage, {
|
|
349
|
+
statusCode: response.status,
|
|
350
|
+
response,
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
return response;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Copyright (c) Microsoft Corporation.
|
|
357
|
+
/**
|
|
358
|
+
* A tracing client to handle spans.
|
|
359
|
+
* @internal
|
|
360
|
+
*/
|
|
361
|
+
const tracingClient = coreTracing.createTracingClient({
|
|
362
|
+
namespace: "Microsoft.NotificationHubs",
|
|
363
|
+
packageName: "@azure/notification-hubs",
|
|
364
|
+
packageVersion: "1.0.0",
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
// Copyright (c) Microsoft Corporation.
|
|
368
|
+
/**
|
|
369
|
+
* Cancels the scheduled notification with the given notification ID.
|
|
370
|
+
* NOTE: This is only available in Standard SKU Azure Notification Hubs.
|
|
371
|
+
* @param context - The Notification Hubs client.
|
|
372
|
+
* @param notificationId - The notification ID from the scheduled notification.
|
|
373
|
+
* @param options - The operation options.
|
|
374
|
+
* @returns A notification hub response with correlation ID and tracking ID.
|
|
375
|
+
*/
|
|
376
|
+
function cancelScheduledNotification(context, notificationId, options = {}) {
|
|
377
|
+
return tracingClient.withSpan("NotificationHubsClientContext-cancelScheduledNotification", options, async (updatedOptions) => {
|
|
378
|
+
const endpoint = context.requestUrl();
|
|
379
|
+
endpoint.pathname += `/schedulednotifications/${notificationId}`;
|
|
380
|
+
const headers = context.createHeaders();
|
|
381
|
+
const request = createRequest(endpoint, "DELETE", headers, updatedOptions);
|
|
382
|
+
const response = await sendRequest(context, request, 200);
|
|
383
|
+
return parseNotificationSendResponse(response);
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// Copyright (c) Microsoft Corporation.
|
|
388
|
+
/**
|
|
389
|
+
* Creates or overwrites an installation to a Notification Hub.
|
|
390
|
+
* @param context - The Notification Hubs client.
|
|
391
|
+
* @param installation - The installation to create or overwrite.
|
|
392
|
+
* @param options - Configuration options for the create or update installation operation.
|
|
393
|
+
* @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
|
|
394
|
+
*/
|
|
395
|
+
function createOrUpdateInstallation(context, installation, options = {}) {
|
|
396
|
+
return tracingClient.withSpan("NotificationHubsClientContext-createOrUpdateInstallation", options, async (updatedOptions) => {
|
|
397
|
+
const endpoint = context.requestUrl();
|
|
398
|
+
endpoint.pathname += `/installations/${installation.installationId}`;
|
|
399
|
+
const headers = context.createHeaders();
|
|
400
|
+
headers.set("Content-Type", "application/json");
|
|
401
|
+
const request = createRequest(endpoint, "PUT", headers, updatedOptions);
|
|
402
|
+
request.body = JSON.stringify(installation);
|
|
403
|
+
const response = await sendRequest(context, request, 200);
|
|
404
|
+
return parseNotificationResponse(response);
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// Copyright (c) Microsoft Corporation.
|
|
409
|
+
const registrationDescriptionParser = {
|
|
410
|
+
/**
|
|
411
|
+
* @internal
|
|
412
|
+
* Creates a registration type from the incoming entry.
|
|
413
|
+
*/
|
|
414
|
+
async parseRegistrationEntry(bodyText) {
|
|
415
|
+
const xml = await coreXml.parseXML(bodyText, { includeRoot: true });
|
|
416
|
+
const keyName = Object.keys(xml.entry.content)[0];
|
|
417
|
+
const content = xml.entry.content[keyName];
|
|
418
|
+
const methodName = `create${keyName}`;
|
|
419
|
+
const method = this[methodName];
|
|
420
|
+
if (!methodName) {
|
|
421
|
+
throw new coreRestPipeline.RestError(`${keyName} is not a supported registration type`, { statusCode: 500 });
|
|
422
|
+
}
|
|
423
|
+
return method.call(this, content);
|
|
424
|
+
},
|
|
425
|
+
/**
|
|
426
|
+
* @internal
|
|
427
|
+
* Creates a list of registrations from an incoming ATOM XML Feed.
|
|
428
|
+
*/
|
|
429
|
+
async parseRegistrationFeed(bodyText) {
|
|
430
|
+
const xml = await coreXml.parseXML(bodyText, { includeRoot: true });
|
|
431
|
+
const results = [];
|
|
432
|
+
for (const entry of xml.feed.entry) {
|
|
433
|
+
delete entry.content["$"];
|
|
434
|
+
const keyName = Object.keys(entry.content)[0];
|
|
435
|
+
const methodName = `create${keyName}`;
|
|
436
|
+
const content = entry.content[keyName];
|
|
437
|
+
const method = this[methodName];
|
|
438
|
+
if (!methodName) {
|
|
439
|
+
throw new coreRestPipeline.RestError(`${keyName} is not a supported registration type`, { statusCode: 500 });
|
|
440
|
+
}
|
|
441
|
+
results.push(method.call(this, content));
|
|
442
|
+
}
|
|
443
|
+
return results;
|
|
444
|
+
},
|
|
445
|
+
/**
|
|
446
|
+
* @internal
|
|
447
|
+
* Creates an ADM registration description from incoming XML property bag.
|
|
448
|
+
*/
|
|
449
|
+
createAdmRegistrationDescription(rawRegistrationDescription) {
|
|
450
|
+
return Object.assign(Object.assign({ admRegistrationId: getString(rawRegistrationDescription["AdmRegistrationId"], "admRegistrationId") }, createRegistrationDescription(rawRegistrationDescription)), { type: "Adm" });
|
|
451
|
+
},
|
|
452
|
+
/**
|
|
453
|
+
* @internal
|
|
454
|
+
* Creates an ADM template registration description from incoming XML property bag.
|
|
455
|
+
*/
|
|
456
|
+
createAdmTemplateRegistrationDescription(rawRegistrationDescription) {
|
|
457
|
+
return Object.assign(Object.assign(Object.assign({}, this.createAdmRegistrationDescription(rawRegistrationDescription)), createTemplateRegistrationDescription(rawRegistrationDescription)), { type: "AdmTemplate" });
|
|
458
|
+
},
|
|
459
|
+
/**
|
|
460
|
+
* @internal
|
|
461
|
+
* Creates an Apple registration description from incoming XML property bag.
|
|
462
|
+
*/
|
|
463
|
+
createAppleRegistrationDescription(rawRegistrationDescription) {
|
|
464
|
+
return Object.assign(Object.assign({ deviceToken: getString(rawRegistrationDescription["DeviceToken"], "deviceToken") }, createRegistrationDescription(rawRegistrationDescription)), { type: "Apple" });
|
|
465
|
+
},
|
|
466
|
+
/**
|
|
467
|
+
* @internal
|
|
468
|
+
* Creates an Apple template registration description from incoming XML property bag.
|
|
469
|
+
*/
|
|
470
|
+
createAppleTemplateRegistrationDescription(rawRegistrationDescription) {
|
|
471
|
+
var _a;
|
|
472
|
+
return Object.assign(Object.assign(Object.assign({ priority: getStringOrUndefined(rawRegistrationDescription["Priority"]), apnsHeaders: getHeadersOrUndefined((_a = rawRegistrationDescription["ApnsHeaders"]) === null || _a === void 0 ? void 0 : _a["ApnsHeader"]) }, this.createAppleRegistrationDescription(rawRegistrationDescription)), createTemplateRegistrationDescription(rawRegistrationDescription)), { type: "AppleTemplate" });
|
|
473
|
+
},
|
|
474
|
+
/**
|
|
475
|
+
* @internal
|
|
476
|
+
* Creates a Baidu registration description from incoming XML property bag.
|
|
477
|
+
*/
|
|
478
|
+
createBaiduRegistrationDescription(rawRegistrationDescription) {
|
|
479
|
+
return Object.assign(Object.assign({ baiduChannelId: getString(rawRegistrationDescription["BaiduChannelId"], "baiduChannelId"), baiduUserId: getString(rawRegistrationDescription["BaiduUserId"], "baiduUserId") }, createRegistrationDescription(rawRegistrationDescription)), { type: "Baidu" });
|
|
480
|
+
},
|
|
481
|
+
/**
|
|
482
|
+
* @internal
|
|
483
|
+
* Creates a Baidu template registration description from incoming XML property bag.
|
|
484
|
+
*/
|
|
485
|
+
createBaiduTemplateRegistrationDescription(rawRegistrationDescription) {
|
|
486
|
+
return Object.assign(Object.assign(Object.assign({}, this.createBaiduRegistrationDescription(rawRegistrationDescription)), createTemplateRegistrationDescription(rawRegistrationDescription)), { type: "BaiduTemplate" });
|
|
487
|
+
},
|
|
488
|
+
/**
|
|
489
|
+
* @internal
|
|
490
|
+
* Creates a Browser registration description from incoming XML property bag.
|
|
491
|
+
*/
|
|
492
|
+
createBrowserRegistrationDescription(rawRegistrationDescription) {
|
|
493
|
+
return Object.assign(Object.assign({ endpoint: getString(rawRegistrationDescription["Endpoint"], "endpoint"), p256dh: getString(rawRegistrationDescription["P256DH"], "p256dh"), auth: getString(rawRegistrationDescription["Auth"], "auth") }, createRegistrationDescription(rawRegistrationDescription)), { type: "Browser" });
|
|
494
|
+
},
|
|
495
|
+
/**
|
|
496
|
+
* @internal
|
|
497
|
+
* Creates a Browser template registration description from incoming XML property bag.
|
|
498
|
+
*/
|
|
499
|
+
createBrowserTemplateRegistrationDescription(rawRegistrationDescription) {
|
|
500
|
+
return Object.assign(Object.assign(Object.assign({}, this.createBrowserRegistrationDescription(rawRegistrationDescription)), createTemplateRegistrationDescription(rawRegistrationDescription)), { type: "BrowserTemplate" });
|
|
501
|
+
},
|
|
502
|
+
/**
|
|
503
|
+
* @internal
|
|
504
|
+
* Creates an GCM registration description from incoming XML property bag.
|
|
505
|
+
*/
|
|
506
|
+
createGcmRegistrationDescription(rawRegistrationDescription) {
|
|
507
|
+
return Object.assign(Object.assign({ gcmRegistrationId: getString(rawRegistrationDescription["GcmRegistrationId"], "gcmRegistrationId") }, createRegistrationDescription(rawRegistrationDescription)), { type: "Gcm" });
|
|
508
|
+
},
|
|
509
|
+
/**
|
|
510
|
+
* @internal
|
|
511
|
+
* Creates an FCM template registration description from incoming XML property bag.
|
|
512
|
+
*/
|
|
513
|
+
createGcmTemplateRegistrationDescription(rawRegistrationDescription) {
|
|
514
|
+
return Object.assign(Object.assign(Object.assign({}, this.createGcmRegistrationDescription(rawRegistrationDescription)), createTemplateRegistrationDescription(rawRegistrationDescription)), { type: "GcmTemplate" });
|
|
515
|
+
},
|
|
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
|
+
/**
|
|
531
|
+
* @internal
|
|
532
|
+
* Creates a Windows Phone registration description from incoming XML property bag.
|
|
533
|
+
*/
|
|
534
|
+
createMpnsRegistrationDescription(rawRegistrationDescription) {
|
|
535
|
+
return Object.assign(Object.assign({ channelUri: getString(rawRegistrationDescription["ChannelUri"], "channelUri") }, createRegistrationDescription(rawRegistrationDescription)), { type: "Mpns" });
|
|
536
|
+
},
|
|
537
|
+
/**
|
|
538
|
+
* @internal
|
|
539
|
+
* Creates a Windows Phone template registration description from incoming XML property bag.
|
|
540
|
+
*/
|
|
541
|
+
createMpnsTemplateRegistrationDescription(rawRegistrationDescription) {
|
|
542
|
+
var _a;
|
|
543
|
+
return Object.assign(Object.assign(Object.assign({ mpnsHeaders: getHeadersOrUndefined((_a = rawRegistrationDescription["MpnsHeaders"]) === null || _a === void 0 ? void 0 : _a["MpnsHeader"]) }, this.createWindowsRegistrationDescription(rawRegistrationDescription)), createTemplateRegistrationDescription(rawRegistrationDescription)), { type: "MpnsTemplate" });
|
|
544
|
+
},
|
|
545
|
+
/**
|
|
546
|
+
* @internal
|
|
547
|
+
* Creates a Windows registration description from incoming XML property bag.
|
|
548
|
+
*/
|
|
549
|
+
createWindowsRegistrationDescription(rawRegistrationDescription) {
|
|
550
|
+
return Object.assign(Object.assign({ channelUri: getString(rawRegistrationDescription["ChannelUri"], "channelUri") }, createRegistrationDescription(rawRegistrationDescription)), { type: "Windows" });
|
|
551
|
+
},
|
|
552
|
+
/**
|
|
553
|
+
* @internal
|
|
554
|
+
* Creates a Windows template registration description from incoming XML property bag.
|
|
555
|
+
*/
|
|
556
|
+
createWindowsTemplateRegistrationDescription(rawRegistrationDescription) {
|
|
557
|
+
var _a;
|
|
558
|
+
return Object.assign(Object.assign(Object.assign({ wnsHeaders: getHeadersOrUndefined((_a = rawRegistrationDescription["WnsHeaders"]) === null || _a === void 0 ? void 0 : _a["WnsHeader"]) }, this.createWindowsRegistrationDescription(rawRegistrationDescription)), createTemplateRegistrationDescription(rawRegistrationDescription)), { type: "WindowsTemplate" });
|
|
559
|
+
},
|
|
560
|
+
};
|
|
561
|
+
function getHeadersOrUndefined(value) {
|
|
562
|
+
if (!isDefined(value)) {
|
|
563
|
+
return undefined;
|
|
564
|
+
}
|
|
565
|
+
const headerObj = {};
|
|
566
|
+
for (const { Header, Value } of value) {
|
|
567
|
+
headerObj[Header] = Value;
|
|
568
|
+
}
|
|
569
|
+
return headerObj;
|
|
570
|
+
}
|
|
571
|
+
function createRegistrationDescription(rawRegistrationDescription) {
|
|
572
|
+
let pushVariables;
|
|
573
|
+
const unparsed = getStringOrUndefined(rawRegistrationDescription["PushVariables"]);
|
|
574
|
+
if (unparsed) {
|
|
575
|
+
pushVariables = JSON.parse(unparsed);
|
|
576
|
+
}
|
|
577
|
+
return {
|
|
578
|
+
registrationId: getStringOrUndefined(rawRegistrationDescription["RegistrationId"]),
|
|
579
|
+
expirationTime: getDateOrUndefined(rawRegistrationDescription["ExpirationTime"]),
|
|
580
|
+
etag: getStringOrUndefined(rawRegistrationDescription["ETag"]),
|
|
581
|
+
tags: getTagsOrUndefined(rawRegistrationDescription["Tags"]),
|
|
582
|
+
pushVariables: pushVariables,
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
function createTemplateRegistrationDescription(rawRegistrationDescription) {
|
|
586
|
+
return Object.assign({ bodyTemplate: getString(rawRegistrationDescription["BodyTemplate"], "bodyTemplate"), templateName: getStringOrUndefined(rawRegistrationDescription["TemplateName"]) }, createRegistrationDescription(rawRegistrationDescription));
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Represents a RegistrationDescription serializer.
|
|
590
|
+
*/
|
|
591
|
+
const registrationDescriptionSerializer = {
|
|
592
|
+
serializeRegistrationDescription(description) {
|
|
593
|
+
const rootName = `${description.type}RegistrationDescription`;
|
|
594
|
+
const methodName = `serialize${rootName}`;
|
|
595
|
+
const method = this[methodName].bind(this);
|
|
596
|
+
if (!isDefined(method)) {
|
|
597
|
+
throw new coreRestPipeline.RestError(`Undefined platform ${description.type}`, { statusCode: 400 });
|
|
598
|
+
}
|
|
599
|
+
const registration = method(description);
|
|
600
|
+
const requestObject = serializeToAtomXmlRequest(rootName, registration);
|
|
601
|
+
return coreXml.stringifyXML(requestObject, { rootName: "entry" });
|
|
602
|
+
},
|
|
603
|
+
/**
|
|
604
|
+
* @internal
|
|
605
|
+
* Serializes an existing ADM registration description to an object for serialization.
|
|
606
|
+
*/
|
|
607
|
+
serializeAdmRegistrationDescription(description) {
|
|
608
|
+
return Object.assign(Object.assign({}, serializeRegistrationDescription(description)), { AdmRegistrationId: getString(description.admRegistrationId, "admRegistrationId") });
|
|
609
|
+
},
|
|
610
|
+
/**
|
|
611
|
+
* @internal
|
|
612
|
+
* Serializes an existing ADM template registration description to an object for serialization.
|
|
613
|
+
*/
|
|
614
|
+
serializeAdmTemplateRegistrationDescription(description) {
|
|
615
|
+
return Object.assign(Object.assign({}, this.serializeAdmRegistrationDescription(description)), serializeTemplateRegistrationDescription(description));
|
|
616
|
+
},
|
|
617
|
+
/**
|
|
618
|
+
* @internal
|
|
619
|
+
* Serializes an existing Apple registration description to an object for serialization.
|
|
620
|
+
*/
|
|
621
|
+
serializeAppleRegistrationDescription(description) {
|
|
622
|
+
return Object.assign(Object.assign({}, serializeRegistrationDescription(description)), { DeviceToken: getString(description.deviceToken, "deviceToken") });
|
|
623
|
+
},
|
|
624
|
+
/**
|
|
625
|
+
* @internal
|
|
626
|
+
* Serializes an existing Apple template registration description to an object for serialization.
|
|
627
|
+
*/
|
|
628
|
+
serializeAppleTemplateRegistrationDescription(description) {
|
|
629
|
+
let apnsHeaders;
|
|
630
|
+
if (description.apnsHeaders) {
|
|
631
|
+
apnsHeaders = {
|
|
632
|
+
ApnsHeader: [],
|
|
633
|
+
};
|
|
634
|
+
for (const header of Object.keys(description.apnsHeaders)) {
|
|
635
|
+
apnsHeaders["ApnsHeader"].push({
|
|
636
|
+
Header: header,
|
|
637
|
+
Value: description.apnsHeaders[header],
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
return Object.assign(Object.assign(Object.assign({}, this.serializeAppleRegistrationDescription(description)), serializeTemplateRegistrationDescription(description)), { Expiry: getStringOrUndefined(description.expiry), ApnsHeaders: apnsHeaders });
|
|
642
|
+
},
|
|
643
|
+
/**
|
|
644
|
+
* @internal
|
|
645
|
+
* Serializes an existing Baidu registration description to an object for serialization.
|
|
646
|
+
*/
|
|
647
|
+
serializeBaiduRegistrationDescription(description) {
|
|
648
|
+
return Object.assign(Object.assign({}, serializeRegistrationDescription(description)), { BaiduChannelId: getString(description.baiduChannelId, "baiduChannelId"), BaiduUserId: getString(description.baiduUserId, "baiduUserId") });
|
|
649
|
+
},
|
|
650
|
+
/**
|
|
651
|
+
* @internal
|
|
652
|
+
* Serializes an existing Baidu template registration description to an object for serialization.
|
|
653
|
+
*/
|
|
654
|
+
serializeBaiduTemplateRegistrationDescription(description) {
|
|
655
|
+
return Object.assign(Object.assign({}, this.serializeBaiduRegistrationDescription(description)), serializeTemplateRegistrationDescription(description));
|
|
656
|
+
},
|
|
657
|
+
/**
|
|
658
|
+
* @internal
|
|
659
|
+
* Serializes an existing Browser registration description to an object for serialization.
|
|
660
|
+
*/
|
|
661
|
+
serializeBrowserRegistrationDescription(description) {
|
|
662
|
+
return Object.assign(Object.assign({}, serializeRegistrationDescription(description)), { Endpoint: description.endpoint, Auth: description.auth, P256DH: description.p256dh });
|
|
663
|
+
},
|
|
664
|
+
/**
|
|
665
|
+
* @internal
|
|
666
|
+
* Serializes an existing Browser template registration description to an object for serialization.
|
|
667
|
+
*/
|
|
668
|
+
serializeBrowserTemplateRegistrationDescription(description) {
|
|
669
|
+
return Object.assign(Object.assign({}, this.serializeBrowserRegistrationDescription(description)), serializeTemplateRegistrationDescription(description));
|
|
670
|
+
},
|
|
671
|
+
/**
|
|
672
|
+
* @internal
|
|
673
|
+
* @deprecated Should use FCM registrations instead of GCM.
|
|
674
|
+
* Serializes an existing GCM registration description to an object for serialization.
|
|
675
|
+
*/
|
|
676
|
+
serializeGcmRegistrationDescription(description) {
|
|
677
|
+
return Object.assign(Object.assign({}, serializeRegistrationDescription(description)), { GcmRegistrationId: getString(description.gcmRegistrationId, "gcmRegistrationId") });
|
|
678
|
+
},
|
|
679
|
+
/**
|
|
680
|
+
* @internal
|
|
681
|
+
* @deprecated Should use FCM template registrations instead of GCM.
|
|
682
|
+
* Serializes an existing GCM template registration description to an object for serialization.
|
|
683
|
+
*/
|
|
684
|
+
serializeGcmTemplateRegistrationDescription(description) {
|
|
685
|
+
return Object.assign(Object.assign({}, this.serializeGcmRegistrationDescription(description)), serializeTemplateRegistrationDescription(description));
|
|
686
|
+
},
|
|
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
|
+
/**
|
|
702
|
+
* @internal
|
|
703
|
+
* @deprecated Windows Phone is no longer supported.
|
|
704
|
+
* Serializes an existing MPNS registration description to an object for serialization.
|
|
705
|
+
*/
|
|
706
|
+
serializeMpnsRegistrationDescription(description) {
|
|
707
|
+
return Object.assign(Object.assign({}, serializeRegistrationDescription(description)), { ChannelUri: description.channelUri });
|
|
708
|
+
},
|
|
709
|
+
/**
|
|
710
|
+
* @internal
|
|
711
|
+
* @deprecated Windows Phone is no longer supported.
|
|
712
|
+
* Serializes an existing MPNS template registration description to an object for serialization.
|
|
713
|
+
*/
|
|
714
|
+
serializeMpnsTemplateRegistrationDescription(description) {
|
|
715
|
+
let mpnsHeaders;
|
|
716
|
+
if (description.mpnsHeaders) {
|
|
717
|
+
mpnsHeaders = {
|
|
718
|
+
MpnsHeader: [],
|
|
719
|
+
};
|
|
720
|
+
for (const header of Object.keys(description.mpnsHeaders)) {
|
|
721
|
+
mpnsHeaders["MpnsHeader"].push({
|
|
722
|
+
Header: header,
|
|
723
|
+
Value: description.mpnsHeaders[header],
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
return Object.assign(Object.assign(Object.assign({}, this.serializeMpnsRegistrationDescription(description)), serializeTemplateRegistrationDescription(description)), { MpnsHeaders: mpnsHeaders });
|
|
728
|
+
},
|
|
729
|
+
/**
|
|
730
|
+
* @internal
|
|
731
|
+
* Serializes an existing Windows registration description to an object for serialization.
|
|
732
|
+
*/
|
|
733
|
+
serializeWindowsRegistrationDescription(description) {
|
|
734
|
+
return Object.assign(Object.assign({}, serializeRegistrationDescription(description)), { ChannelUri: description.channelUri });
|
|
735
|
+
},
|
|
736
|
+
/**
|
|
737
|
+
* @internal
|
|
738
|
+
* Serializes an existing Windows template registration description to an object for serialization.
|
|
739
|
+
*/
|
|
740
|
+
serializeWindowsTemplateRegistrationDescription(description) {
|
|
741
|
+
let wnsHeaders;
|
|
742
|
+
if (description.wnsHeaders) {
|
|
743
|
+
wnsHeaders = {
|
|
744
|
+
WnsHeader: [],
|
|
745
|
+
};
|
|
746
|
+
for (const header of Object.keys(description.wnsHeaders)) {
|
|
747
|
+
wnsHeaders["WnsHeader"].push({
|
|
748
|
+
Header: header,
|
|
749
|
+
Value: description.wnsHeaders[header],
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
return Object.assign(Object.assign(Object.assign({}, this.serializeWindowsRegistrationDescription(description)), serializeTemplateRegistrationDescription(description)), { WnsHeaders: wnsHeaders });
|
|
754
|
+
},
|
|
755
|
+
};
|
|
756
|
+
function serializeRegistrationDescription(description) {
|
|
757
|
+
let tags;
|
|
758
|
+
if (description.tags) {
|
|
759
|
+
tags = description.tags.join(",");
|
|
760
|
+
}
|
|
761
|
+
let pushVariables;
|
|
762
|
+
if (description.pushVariables) {
|
|
763
|
+
pushVariables = JSON.stringify(description.pushVariables);
|
|
764
|
+
}
|
|
765
|
+
return {
|
|
766
|
+
RegistrationId: getStringOrUndefined(description.registrationId),
|
|
767
|
+
Tags: tags,
|
|
768
|
+
PushVariables: pushVariables,
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
function serializeTemplateRegistrationDescription(description) {
|
|
772
|
+
return {
|
|
773
|
+
BodyTemplate: { __cdata: description.bodyTemplate },
|
|
774
|
+
TemplateName: getStringOrUndefined(description.templateName),
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
// Copyright (c) Microsoft Corporation.
|
|
779
|
+
/**
|
|
780
|
+
* @internal
|
|
781
|
+
*/
|
|
782
|
+
async function createOrUpdateRegistrationDescription(context, registration, operationName, options) {
|
|
783
|
+
const endpoint = context.requestUrl();
|
|
784
|
+
endpoint.pathname += "/registrations";
|
|
785
|
+
let httpMethod = "POST";
|
|
786
|
+
if (operationName === "createOrUpdate" || operationName === "update") {
|
|
787
|
+
endpoint.pathname += `/${registration.registrationId}`;
|
|
788
|
+
httpMethod = "PUT";
|
|
789
|
+
}
|
|
790
|
+
const etag = registration.etag;
|
|
791
|
+
// Clear out readonly properties
|
|
792
|
+
registration.registrationId = undefined;
|
|
793
|
+
registration.etag = undefined;
|
|
794
|
+
const headers = context.createHeaders();
|
|
795
|
+
headers.set("Content-Type", "application/atom+xml;type=entry;charset=utf-8");
|
|
796
|
+
if (operationName === "update") {
|
|
797
|
+
headers.set("If-Match", isDefined(etag) ? `"${etag}"` : "*");
|
|
798
|
+
}
|
|
799
|
+
const request = createRequest(endpoint, httpMethod, headers, options);
|
|
800
|
+
request.body = registrationDescriptionSerializer.serializeRegistrationDescription(registration);
|
|
801
|
+
const response = await sendRequest(context, request, [200, 201]);
|
|
802
|
+
return registrationDescriptionParser.parseRegistrationEntry(response.bodyAsText);
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
// Copyright (c) Microsoft Corporation.
|
|
806
|
+
/**
|
|
807
|
+
* Creates or updates a registration.
|
|
808
|
+
* @param context - The Notification Hubs client.
|
|
809
|
+
* @param registration - The registration to create or update.
|
|
810
|
+
* @param options - The operation options.
|
|
811
|
+
* @returns The created or updated registration description.
|
|
812
|
+
*/
|
|
813
|
+
function createOrUpdateRegistration(context, registration, options = {}) {
|
|
814
|
+
return tracingClient.withSpan("NotificationHubsClientContext-createOrUpdateRegistration", options, async (updatedOptions) => {
|
|
815
|
+
return createOrUpdateRegistrationDescription(context, registration, "createOrUpdate", updatedOptions);
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
// Copyright (c) Microsoft Corporation.
|
|
820
|
+
/**
|
|
821
|
+
* Creates a new registration ID.
|
|
822
|
+
* @param context - The Notification Hubs client.
|
|
823
|
+
* @param options - The options for creating a new registration ID.
|
|
824
|
+
* @returns The newly created registration ID.
|
|
825
|
+
*/
|
|
826
|
+
function createRegistrationId(context, options = {}) {
|
|
827
|
+
return tracingClient.withSpan("NotificationHubsClientContext-createRegistrationId", options, async (updatedOptions) => {
|
|
828
|
+
const endpoint = context.requestUrl();
|
|
829
|
+
endpoint.pathname += "/registrationIDs";
|
|
830
|
+
const headers = context.createHeaders();
|
|
831
|
+
headers.set("Content-Type", "application/xml;type=entry;charset=utf-8");
|
|
832
|
+
const request = createRequest(endpoint, "POST", headers, updatedOptions);
|
|
833
|
+
const response = await sendRequest(context, request, 201);
|
|
834
|
+
// In the form: https://{namespace}.servicebus.windows.net/{NotificationHub}/registrations/<registrationId>
|
|
835
|
+
const locationHeader = response.headers.get("Location");
|
|
836
|
+
const locationUrl = new URL(locationHeader);
|
|
837
|
+
const registrationId = locationUrl.pathname.split("/")[3];
|
|
838
|
+
return registrationId;
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
// Copyright (c) Microsoft Corporation.
|
|
843
|
+
/**
|
|
844
|
+
* Creates a new registration. This method generates a registration ID,
|
|
845
|
+
* which you can subsequently use to retrieve, update, and delete this registration.
|
|
846
|
+
* @param context - The Notification Hubs client.
|
|
847
|
+
* @param registration - The registration to create.
|
|
848
|
+
* @param options - Options for creating a new registration.
|
|
849
|
+
* @returns The newly created registration description.
|
|
850
|
+
*/
|
|
851
|
+
function createRegistration(context, registration, options = {}) {
|
|
852
|
+
return tracingClient.withSpan("NotificationHubsClientContext-createRegistration", options, async (updatedOptions) => {
|
|
853
|
+
if (registration.registrationId) {
|
|
854
|
+
throw new coreRestPipeline.RestError("registrationId must not be set during a create operation", {
|
|
855
|
+
statusCode: 400,
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
return createOrUpdateRegistrationDescription(context, registration, "create", updatedOptions);
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
// Copyright (c) Microsoft Corporation.
|
|
863
|
+
/**
|
|
864
|
+
* Deletes an installation from a Notification Hub.
|
|
865
|
+
* @param context - The Notification Hubs client.
|
|
866
|
+
* @param installationId - The installation ID of the installation to delete.
|
|
867
|
+
* @param options - Configuration options for the installation delete operation.
|
|
868
|
+
* @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
|
|
869
|
+
*/
|
|
870
|
+
function deleteInstallation(context, installationId, options = {}) {
|
|
871
|
+
return tracingClient.withSpan("NotificationHubsClientContext-deleteInstallation", options, async (updatedOptions) => {
|
|
872
|
+
const endpoint = context.requestUrl();
|
|
873
|
+
endpoint.pathname += `/installations/${installationId}`;
|
|
874
|
+
const headers = context.createHeaders();
|
|
875
|
+
const request = createRequest(endpoint, "DELETE", headers, updatedOptions);
|
|
876
|
+
const response = await sendRequest(context, request, 204);
|
|
877
|
+
return parseNotificationResponse(response);
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
// Copyright (c) Microsoft Corporation.
|
|
882
|
+
/**
|
|
883
|
+
* Retrieves an Azure Storage container URL. The container has feedback data for the notification hub.
|
|
884
|
+
* The caller can then use the Azure Storage Services SDK to retrieve the contents of the container.
|
|
885
|
+
* @param context - The Notification Hubs client.
|
|
886
|
+
* @param options - The options for getting the push notification feedback container URL.
|
|
887
|
+
* @returns The URL of the Azure Storage Container containing the feedback data.
|
|
888
|
+
*/
|
|
889
|
+
function getFeedbackContainerUrl(context, options = {}) {
|
|
890
|
+
return tracingClient.withSpan("NotificationHubsClientContext-getFeedbackContainerUrl", options, async (updatedOptions) => {
|
|
891
|
+
const endpoint = context.requestUrl();
|
|
892
|
+
endpoint.pathname += "/feedbackcontainer";
|
|
893
|
+
const headers = context.createHeaders();
|
|
894
|
+
headers.set("Content-Type", "application/xml;type=entry;charset=utf-8");
|
|
895
|
+
const request = createRequest(endpoint, "GET", headers, updatedOptions);
|
|
896
|
+
const response = await sendRequest(context, request, 200);
|
|
897
|
+
return response.bodyAsText;
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
// Copyright (c) Microsoft Corporation.
|
|
902
|
+
/**
|
|
903
|
+
* Gets an Azure Notification Hub installation by the installation ID.
|
|
904
|
+
* @param context - The Notification Hubs client.
|
|
905
|
+
* @param installationId - The ID of the installation to get.
|
|
906
|
+
* @param options - Configuration options for the get installation operation.
|
|
907
|
+
* @returns The installation that matches the installation ID.
|
|
908
|
+
*/
|
|
909
|
+
function getInstallation(context, installationId, options = {}) {
|
|
910
|
+
return tracingClient.withSpan("NotificationHubsClientContext-getInstallation", options, async (updatedOptions) => {
|
|
911
|
+
const endpoint = context.requestUrl();
|
|
912
|
+
endpoint.pathname += `/installations/${installationId}`;
|
|
913
|
+
const headers = context.createHeaders();
|
|
914
|
+
headers.set("Content-Type", "application/json");
|
|
915
|
+
const request = createRequest(endpoint, "GET", headers, updatedOptions);
|
|
916
|
+
const response = await sendRequest(context, request, 200);
|
|
917
|
+
return JSON.parse(response.bodyAsText);
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
// Copyright (c) Microsoft Corporation.
|
|
922
|
+
/**
|
|
923
|
+
* @internal
|
|
924
|
+
* Serializes a NotificationHubJob into an Atom XML entry.
|
|
925
|
+
* @param entry - The NotificationHubJob to turn into an Atom XML entry.
|
|
926
|
+
* @returns An Atom XML entry containing the notification hub job.
|
|
927
|
+
*/
|
|
928
|
+
function serializeNotificationHubJobEntry(entry) {
|
|
929
|
+
const job = {
|
|
930
|
+
Type: entry.type,
|
|
931
|
+
OutputContainerUri: { __cdata: entry.outputContainerUrl },
|
|
932
|
+
ImportFileUri: isDefined(entry.importFileUrl) ? { __cdata: entry.importFileUrl } : undefined,
|
|
933
|
+
};
|
|
934
|
+
const requestObject = serializeToAtomXmlRequest("NotificationHubJob", job);
|
|
935
|
+
return coreXml.stringifyXML(requestObject, { rootName: "entry", cdataPropName: "__cdata" });
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
* Parses an Atom XML of an notification hub job entry.
|
|
939
|
+
* @param bodyText - The incoming Atom XML entry to parse into a notification hub job.
|
|
940
|
+
* @returns A parsed NotificationHubJob.
|
|
941
|
+
*/
|
|
942
|
+
async function parseNotificationHubJobEntry(bodyText) {
|
|
943
|
+
const xml = await coreXml.parseXML(bodyText, { includeRoot: true });
|
|
944
|
+
const content = xml.entry.content.NotificationHubJob;
|
|
945
|
+
return createNotificationHubJob(content);
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* Parses an Atom XML feed of notification hub jobs.
|
|
949
|
+
* @param bodyText - The incoming Atom XML feed to parse into notification hub jobs.
|
|
950
|
+
* @returns A list of notification hub jobs.
|
|
951
|
+
*/
|
|
952
|
+
async function parseNotificationHubJobFeed(bodyText) {
|
|
953
|
+
const xml = await coreXml.parseXML(bodyText, { includeRoot: true });
|
|
954
|
+
const results = [];
|
|
955
|
+
for (const item of xml.feed.entry) {
|
|
956
|
+
results.push(createNotificationHubJob(item.content.NotificationHubJob));
|
|
957
|
+
}
|
|
958
|
+
return results;
|
|
959
|
+
}
|
|
960
|
+
function createInputOutputProperties(content) {
|
|
961
|
+
const props = {};
|
|
962
|
+
for (const item of content["d3p1:KeyValueOfstringstring"]) {
|
|
963
|
+
props[item["d3p1:Key"]] = item["d3p1:Value"];
|
|
964
|
+
}
|
|
965
|
+
return props;
|
|
966
|
+
}
|
|
967
|
+
function createNotificationHubJob(content) {
|
|
968
|
+
let outputProperties;
|
|
969
|
+
if (isDefined(content["OutputProperties"])) {
|
|
970
|
+
outputProperties = createInputOutputProperties(content["OutputProperties"]);
|
|
971
|
+
}
|
|
972
|
+
let inputProperties;
|
|
973
|
+
if (isDefined(content["InputProperties"])) {
|
|
974
|
+
inputProperties = createInputOutputProperties(content["InputProperties"]);
|
|
975
|
+
}
|
|
976
|
+
return {
|
|
977
|
+
jobId: getStringOrUndefined(content["JobId"]),
|
|
978
|
+
type: getString(content["Type"], "type"),
|
|
979
|
+
status: getStringOrUndefined(content["Status"]),
|
|
980
|
+
progress: getFloatOrUndefined(content["Progress"]),
|
|
981
|
+
outputContainerUrl: getString(content["OutputContainerUri"], "outputContainerUrl"),
|
|
982
|
+
importFileUrl: getStringOrUndefined(content["ImportFileUri"]),
|
|
983
|
+
failure: getStringOrUndefined(content["Failure"]),
|
|
984
|
+
createdAt: getDateOrUndefined(content["CreatedAt"]),
|
|
985
|
+
updatedAt: getDateOrUndefined(content["UpdatedAt"]),
|
|
986
|
+
inputProperties,
|
|
987
|
+
outputProperties,
|
|
988
|
+
};
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
// Copyright (c) Microsoft Corporation.
|
|
992
|
+
/**
|
|
993
|
+
* Gets a Notification Hub Job by the ID.
|
|
994
|
+
* @param context - The Notification Hubs client.
|
|
995
|
+
* @param jobId - The Notification Hub Job ID.
|
|
996
|
+
* @param options - The operation options.
|
|
997
|
+
* @returns The Notification Hub Job with the matching ID.
|
|
998
|
+
*/
|
|
999
|
+
function getNotificationHubJob(context, jobId, options = {}) {
|
|
1000
|
+
return tracingClient.withSpan("NotificationHubsClientContext-getNotificationHubJob", options, async (updatedOptions) => {
|
|
1001
|
+
const endpoint = context.requestUrl();
|
|
1002
|
+
endpoint.pathname += `/jobs/${jobId}`;
|
|
1003
|
+
const headers = context.createHeaders();
|
|
1004
|
+
headers.set("Content-Type", "application/atom+xml;type=entry;charset=utf-8");
|
|
1005
|
+
const request = createRequest(endpoint, "GET", headers, updatedOptions);
|
|
1006
|
+
const response = await sendRequest(context, request, 200);
|
|
1007
|
+
return parseNotificationHubJobEntry(response.bodyAsText);
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
// Copyright (c) Microsoft Corporation.
|
|
1012
|
+
/**
|
|
1013
|
+
* @internal
|
|
1014
|
+
* Parses a NotificationDetails from incoming XML.
|
|
1015
|
+
*/
|
|
1016
|
+
async function parseNotificationDetails(bodyText) {
|
|
1017
|
+
const xml = await coreXml.parseXML(bodyText, {
|
|
1018
|
+
includeRoot: true,
|
|
1019
|
+
stopNodes: ["NotificationDetails.NotificationBody"],
|
|
1020
|
+
});
|
|
1021
|
+
const notificationDetails = xml["NotificationDetails"];
|
|
1022
|
+
let apnsOutcomeCounts;
|
|
1023
|
+
if (isDefined(notificationDetails["ApnsOutcomeCounts"])) {
|
|
1024
|
+
apnsOutcomeCounts = parseOutcomeCounts(notificationDetails["ApnsOutcomeCounts"]["Outcome"]);
|
|
1025
|
+
}
|
|
1026
|
+
let admOutcomeCounts;
|
|
1027
|
+
if (isDefined(notificationDetails["AdmOutcomeCounts"])) {
|
|
1028
|
+
admOutcomeCounts = parseOutcomeCounts(notificationDetails["AdmOutcomeCounts"]["Outcome"]);
|
|
1029
|
+
}
|
|
1030
|
+
let baiduOutcomeCounts;
|
|
1031
|
+
if (isDefined(notificationDetails["BaiduOutcomeCounts"])) {
|
|
1032
|
+
baiduOutcomeCounts = parseOutcomeCounts(notificationDetails["BaiduOutcomeCounts"]["Outcome"]);
|
|
1033
|
+
}
|
|
1034
|
+
let fcmOutcomeCounts;
|
|
1035
|
+
if (isDefined(notificationDetails["GcmOutcomeCounts"])) {
|
|
1036
|
+
fcmOutcomeCounts = parseOutcomeCounts(notificationDetails["GcmOutcomeCounts"]["Outcome"]);
|
|
1037
|
+
}
|
|
1038
|
+
let wnsOutcomeCounts;
|
|
1039
|
+
if (isDefined(notificationDetails["WnsOutcomeCounts"])) {
|
|
1040
|
+
wnsOutcomeCounts = parseOutcomeCounts(notificationDetails["WnsOutcomeCounts"]["Outcome"]);
|
|
1041
|
+
}
|
|
1042
|
+
return {
|
|
1043
|
+
notificationId: getStringOrUndefined(notificationDetails["NotificationId"]),
|
|
1044
|
+
location: getStringOrUndefined(notificationDetails["Location"]),
|
|
1045
|
+
state: getStringOrUndefined(notificationDetails["State"]),
|
|
1046
|
+
enqueueTime: getDateOrUndefined(notificationDetails["EnqueueTime"]),
|
|
1047
|
+
startTime: getDateOrUndefined(notificationDetails["StartTime"]),
|
|
1048
|
+
endTime: getDateOrUndefined(notificationDetails["EndTime"]),
|
|
1049
|
+
pnsErrorDetailsUrl: getStringOrUndefined(notificationDetails["PnsErrorDetailsUri"]),
|
|
1050
|
+
targetPlatforms: getStringOrUndefined(notificationDetails["TargetPlatforms"]),
|
|
1051
|
+
apnsOutcomeCounts,
|
|
1052
|
+
admOutcomeCounts,
|
|
1053
|
+
baiduOutcomeCounts,
|
|
1054
|
+
fcmOutcomeCounts,
|
|
1055
|
+
wnsOutcomeCounts,
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
function parseOutcomeCounts(counts) {
|
|
1059
|
+
const results = [];
|
|
1060
|
+
for (const item of counts) {
|
|
1061
|
+
results.push({ state: item["Name"], count: getInteger(item["Count"], "Count") });
|
|
1062
|
+
}
|
|
1063
|
+
return results;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
// Copyright (c) Microsoft Corporation.
|
|
1067
|
+
/**
|
|
1068
|
+
* Retrieves the results of a send operation. This can retrieve intermediate results if the send is being processed
|
|
1069
|
+
* or final results if the Send* has completed. This API can only be called for Standard SKU and above.
|
|
1070
|
+
* @param context - The Notification Hubs client.
|
|
1071
|
+
* @param notificationId - The notification ID returned from the send operation.
|
|
1072
|
+
* @param options - The operation options.
|
|
1073
|
+
* @returns The results of the send operation.
|
|
1074
|
+
*/
|
|
1075
|
+
function getNotificationOutcomeDetails(context, notificationId, options = {}) {
|
|
1076
|
+
return tracingClient.withSpan("NotificationHubsClientContext-getNotificationOutcomeDetails", options, async (updatedOptions) => {
|
|
1077
|
+
const endpoint = context.requestUrl();
|
|
1078
|
+
endpoint.pathname += `/messages/${notificationId}`;
|
|
1079
|
+
const headers = context.createHeaders();
|
|
1080
|
+
const request = createRequest(endpoint, "GET", headers, updatedOptions);
|
|
1081
|
+
const response = await sendRequest(context, request, 200);
|
|
1082
|
+
return parseNotificationDetails(response.bodyAsText);
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
// Copyright (c) Microsoft Corporation.
|
|
1087
|
+
/**
|
|
1088
|
+
* Gets a registration by the given registration ID.
|
|
1089
|
+
* @param context - The Notification Hubs client.
|
|
1090
|
+
* @param registrationId - The ID of the registration to get.
|
|
1091
|
+
* @param options - The options for getting a registration by ID.
|
|
1092
|
+
* @returns A RegistrationDescription that has the given registration ID.
|
|
1093
|
+
*/
|
|
1094
|
+
function getRegistration(context, registrationId, options = {}) {
|
|
1095
|
+
return tracingClient.withSpan("NotificationHubsClientContext-getRegistration", options, async (updatedOptions) => {
|
|
1096
|
+
const endpoint = context.requestUrl();
|
|
1097
|
+
endpoint.pathname += `/registrations/${registrationId}`;
|
|
1098
|
+
const headers = context.createHeaders();
|
|
1099
|
+
headers.set("Content-Type", "application/xml;type=entry;charset=utf-8");
|
|
1100
|
+
const request = createRequest(endpoint, "GET", headers, updatedOptions);
|
|
1101
|
+
const response = await sendRequest(context, request, 200);
|
|
1102
|
+
return registrationDescriptionParser.parseRegistrationEntry(response.bodyAsText);
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
// Copyright (c) Microsoft Corporation.
|
|
1107
|
+
/**
|
|
1108
|
+
* Gets all Notification Hub Jobs for this Notification Hub.
|
|
1109
|
+
* @param context - The Notification Hubs client.xs
|
|
1110
|
+
* @param options - The operation options.
|
|
1111
|
+
* @returns An array of all Notification Hub Jobs for this Notification Hub.
|
|
1112
|
+
*/
|
|
1113
|
+
function listNotificationHubJobs(context, options = {}) {
|
|
1114
|
+
return tracingClient.withSpan("NotificationHubsClientContext-getNotificationHubJobs", options, async (updatedOptions) => {
|
|
1115
|
+
const endpoint = context.requestUrl();
|
|
1116
|
+
endpoint.pathname += "/jobs";
|
|
1117
|
+
const headers = context.createHeaders();
|
|
1118
|
+
headers.set("Content-Type", "application/atom+xml;type=entry;charset=utf-8");
|
|
1119
|
+
const request = createRequest(endpoint, "GET", headers, updatedOptions);
|
|
1120
|
+
const response = await sendRequest(context, request, 200);
|
|
1121
|
+
return parseNotificationHubJobFeed(response.bodyAsText);
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
// Copyright (c) Microsoft Corporation.
|
|
1126
|
+
/**
|
|
1127
|
+
* Lists all registrations with the matching tag.
|
|
1128
|
+
* @param context - The Notification Hubs client.
|
|
1129
|
+
* @param tag - The tag to query for matching registrations.
|
|
1130
|
+
* @param options - The query options such as $top.
|
|
1131
|
+
* @returns A paged async iterable containing the matching registrations for the notification hub.
|
|
1132
|
+
*/
|
|
1133
|
+
function listRegistrationsByTag(context, tag, options = {}) {
|
|
1134
|
+
const { span, updatedOptions } = tracingClient.startSpan("NotificationHubsClientContext-listRegistrationsByTag", options);
|
|
1135
|
+
try {
|
|
1136
|
+
const iter = listRegistrationsByTagAll(context, tag, updatedOptions);
|
|
1137
|
+
return {
|
|
1138
|
+
next() {
|
|
1139
|
+
return iter.next();
|
|
1140
|
+
},
|
|
1141
|
+
[Symbol.asyncIterator]() {
|
|
1142
|
+
return this;
|
|
1143
|
+
},
|
|
1144
|
+
byPage: () => {
|
|
1145
|
+
return listRegistrationsByTagPagingPage(context, tag, options);
|
|
1146
|
+
},
|
|
1147
|
+
};
|
|
1148
|
+
}
|
|
1149
|
+
catch (e) {
|
|
1150
|
+
span.setStatus({ status: "error", error: e });
|
|
1151
|
+
throw e;
|
|
1152
|
+
}
|
|
1153
|
+
finally {
|
|
1154
|
+
span.end();
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
function listRegistrationsByTagAll(context, tag, options) {
|
|
1158
|
+
return tslib.__asyncGenerator(this, arguments, function* listRegistrationsByTagAll_1() {
|
|
1159
|
+
var e_1, _a;
|
|
1160
|
+
try {
|
|
1161
|
+
for (var _b = tslib.__asyncValues(listRegistrationsByTagPagingPage(context, tag, options)), _c; _c = yield tslib.__await(_b.next()), !_c.done;) {
|
|
1162
|
+
const page = _c.value;
|
|
1163
|
+
yield tslib.__await(yield* tslib.__asyncDelegator(tslib.__asyncValues(page)));
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1167
|
+
finally {
|
|
1168
|
+
try {
|
|
1169
|
+
if (_c && !_c.done && (_a = _b.return)) yield tslib.__await(_a.call(_b));
|
|
1170
|
+
}
|
|
1171
|
+
finally { if (e_1) throw e_1.error; }
|
|
1172
|
+
}
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
function listRegistrationsByTagPagingPage(context, tag, options) {
|
|
1176
|
+
return tslib.__asyncGenerator(this, arguments, function* listRegistrationsByTagPagingPage_1() {
|
|
1177
|
+
let result = yield tslib.__await(_listRegistrationsByTag(context, tag, options));
|
|
1178
|
+
yield yield tslib.__await(result.registrations || []);
|
|
1179
|
+
let continuationToken = result.continuationToken;
|
|
1180
|
+
while (continuationToken) {
|
|
1181
|
+
result = yield tslib.__await(_listRegistrationsByTag(context, tag, options, continuationToken));
|
|
1182
|
+
continuationToken = result.continuationToken;
|
|
1183
|
+
yield yield tslib.__await(result.registrations || []);
|
|
1184
|
+
}
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
async function _listRegistrationsByTag(context, tag, options, continuationToken) {
|
|
1188
|
+
const endpoint = context.requestUrl();
|
|
1189
|
+
endpoint.pathname += `/tags/${tag}/registrations`;
|
|
1190
|
+
if (options.top !== undefined) {
|
|
1191
|
+
endpoint.searchParams.set("$top", `${options.top}`);
|
|
1192
|
+
}
|
|
1193
|
+
if (continuationToken !== undefined) {
|
|
1194
|
+
endpoint.searchParams.set("continuationtoken", continuationToken);
|
|
1195
|
+
}
|
|
1196
|
+
const headers = context.createHeaders();
|
|
1197
|
+
const request = createRequest(endpoint, "GET", headers, options);
|
|
1198
|
+
const response = await sendRequest(context, request, 200);
|
|
1199
|
+
const registrations = await registrationDescriptionParser.parseRegistrationFeed(response.bodyAsText);
|
|
1200
|
+
const nextToken = response.headers.get("x-ms-continuationtoken");
|
|
1201
|
+
return {
|
|
1202
|
+
registrations,
|
|
1203
|
+
continuationToken: nextToken,
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
// Copyright (c) Microsoft Corporation.
|
|
1208
|
+
/**
|
|
1209
|
+
* Gets all registrations for the notification hub with the given query options.
|
|
1210
|
+
* @param context - The Notification Hubs client.
|
|
1211
|
+
* @param options - The options for querying the registrations such as $top and $filter.
|
|
1212
|
+
* @returns A paged async iterable containing all of the registrations for the notification hub.
|
|
1213
|
+
*/
|
|
1214
|
+
function listRegistrations(context, options = {}) {
|
|
1215
|
+
const { span, updatedOptions } = tracingClient.startSpan("NotificationHubsClientContext-listRegistrations", options);
|
|
1216
|
+
try {
|
|
1217
|
+
const iter = listRegistrationsAll(context, updatedOptions);
|
|
1218
|
+
return {
|
|
1219
|
+
next() {
|
|
1220
|
+
return iter.next();
|
|
1221
|
+
},
|
|
1222
|
+
[Symbol.asyncIterator]() {
|
|
1223
|
+
return this;
|
|
1224
|
+
},
|
|
1225
|
+
byPage: () => {
|
|
1226
|
+
return listRegistrationPagingPage(context, options);
|
|
1227
|
+
},
|
|
1228
|
+
};
|
|
1229
|
+
}
|
|
1230
|
+
catch (e) {
|
|
1231
|
+
span.setStatus({ status: "error", error: e });
|
|
1232
|
+
throw e;
|
|
1233
|
+
}
|
|
1234
|
+
finally {
|
|
1235
|
+
span.end();
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
function listRegistrationsAll(context, options) {
|
|
1239
|
+
return tslib.__asyncGenerator(this, arguments, function* listRegistrationsAll_1() {
|
|
1240
|
+
var e_1, _a;
|
|
1241
|
+
try {
|
|
1242
|
+
for (var _b = tslib.__asyncValues(listRegistrationPagingPage(context, options)), _c; _c = yield tslib.__await(_b.next()), !_c.done;) {
|
|
1243
|
+
const page = _c.value;
|
|
1244
|
+
yield tslib.__await(yield* tslib.__asyncDelegator(tslib.__asyncValues(page)));
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1248
|
+
finally {
|
|
1249
|
+
try {
|
|
1250
|
+
if (_c && !_c.done && (_a = _b.return)) yield tslib.__await(_a.call(_b));
|
|
1251
|
+
}
|
|
1252
|
+
finally { if (e_1) throw e_1.error; }
|
|
1253
|
+
}
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1256
|
+
function listRegistrationPagingPage(context, options) {
|
|
1257
|
+
return tslib.__asyncGenerator(this, arguments, function* listRegistrationPagingPage_1() {
|
|
1258
|
+
let result = yield tslib.__await(_listRegistrations(context, options));
|
|
1259
|
+
yield yield tslib.__await(result.registrations || []);
|
|
1260
|
+
let continuationToken = result.continuationToken;
|
|
1261
|
+
while (continuationToken) {
|
|
1262
|
+
result = yield tslib.__await(_listRegistrations(context, options, continuationToken));
|
|
1263
|
+
continuationToken = result.continuationToken;
|
|
1264
|
+
yield yield tslib.__await(result.registrations || []);
|
|
1265
|
+
}
|
|
1266
|
+
});
|
|
1267
|
+
}
|
|
1268
|
+
async function _listRegistrations(context, options, continuationToken) {
|
|
1269
|
+
const endpoint = context.requestUrl();
|
|
1270
|
+
endpoint.pathname += "/registrations";
|
|
1271
|
+
if (options.top !== undefined) {
|
|
1272
|
+
endpoint.searchParams.set("$top", `${options.top}`);
|
|
1273
|
+
}
|
|
1274
|
+
if (options.filter !== undefined) {
|
|
1275
|
+
endpoint.searchParams.set("$filter", options.filter);
|
|
1276
|
+
}
|
|
1277
|
+
if (continuationToken !== undefined) {
|
|
1278
|
+
endpoint.searchParams.set("continuationtoken", continuationToken);
|
|
1279
|
+
}
|
|
1280
|
+
const headers = context.createHeaders();
|
|
1281
|
+
const request = createRequest(endpoint, "GET", headers, options);
|
|
1282
|
+
const response = await sendRequest(context, request, 200);
|
|
1283
|
+
const registrations = await registrationDescriptionParser.parseRegistrationFeed(response.bodyAsText);
|
|
1284
|
+
const nextToken = response.headers.get("x-ms-continuationtoken");
|
|
1285
|
+
return {
|
|
1286
|
+
registrations,
|
|
1287
|
+
continuationToken: nextToken,
|
|
1288
|
+
};
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
// Copyright (c) Microsoft Corporation.
|
|
1292
|
+
/**
|
|
1293
|
+
* @internal
|
|
1294
|
+
*/
|
|
1295
|
+
function scheduleNotificationPayload(context, scheduledTime, tags, notification, options = {}) {
|
|
1296
|
+
return tracingClient.withSpan("NotificationHubsClientContext-$scheduleNotification", options, async (updatedOptions) => {
|
|
1297
|
+
const endpoint = context.requestUrl();
|
|
1298
|
+
endpoint.pathname += "/schedulednotifications/";
|
|
1299
|
+
const headers = context.createHeaders();
|
|
1300
|
+
if (notification.headers) {
|
|
1301
|
+
for (const headerName of Object.keys(notification.headers)) {
|
|
1302
|
+
headers.set(headerName, notification.headers[headerName]);
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
headers.set("ServiceBusNotification-ScheduleTime", scheduledTime.toISOString());
|
|
1306
|
+
headers.set("Content-Type", notification.contentType);
|
|
1307
|
+
headers.set("ServiceBusNotification-Format", notification.platform);
|
|
1308
|
+
if (tags) {
|
|
1309
|
+
let tagExpression = null;
|
|
1310
|
+
if (Array.isArray(tags)) {
|
|
1311
|
+
tagExpression = tags.join("||");
|
|
1312
|
+
}
|
|
1313
|
+
else {
|
|
1314
|
+
tagExpression = tags;
|
|
1315
|
+
}
|
|
1316
|
+
headers.set("ServiceBusNotification-Tags", tagExpression);
|
|
1317
|
+
}
|
|
1318
|
+
const request = createRequest(endpoint, "POST", headers, updatedOptions);
|
|
1319
|
+
request.body = notification.body;
|
|
1320
|
+
const response = await sendRequest(context, request, 201);
|
|
1321
|
+
return parseNotificationSendResponse(response);
|
|
1322
|
+
});
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
// Copyright (c) Microsoft Corporation.
|
|
1326
|
+
/**
|
|
1327
|
+
* Schedules a push notification to all devices registered on the Notification Hub.
|
|
1328
|
+
* NOTE: This is only available in Standard SKU Azure Notification Hubs.
|
|
1329
|
+
* @param context - The Notification Hubs client.
|
|
1330
|
+
* @param scheduledTime - The Date to send the push notification.
|
|
1331
|
+
* @param notification - The notification to send to the matching devices.
|
|
1332
|
+
* @param options - Configuration options for the direct send operation which can contain custom headers
|
|
1333
|
+
* which may include APNs specific such as apns-topic or for WNS, X-WNS-TYPE.
|
|
1334
|
+
* @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
|
|
1335
|
+
*/
|
|
1336
|
+
function scheduleBroadcastNotification(context, scheduledTime, notification, options = {}) {
|
|
1337
|
+
return scheduleNotificationPayload(context, scheduledTime, undefined, notification, options);
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
// Copyright (c) Microsoft Corporation.
|
|
1341
|
+
/**
|
|
1342
|
+
* Schedules a push notification to devices that match the given tags or tag expression at the specified time.
|
|
1343
|
+
* NOTE: This is only available in Standard SKU Azure Notification Hubs.
|
|
1344
|
+
* @param context - The Notification Hubs client.
|
|
1345
|
+
* @param scheduledTime - The Date to send the push notification.
|
|
1346
|
+
* @param tags - The tags used to target the device for push notifications in either an array or tag expression.
|
|
1347
|
+
* @param notification - The notification to send to the matching devices.
|
|
1348
|
+
* @param options - Configuration options for the direct send operation which can contain custom headers
|
|
1349
|
+
* which may include APNs specific such as apns-topic or for WNS, X-WNS-TYPE.
|
|
1350
|
+
* @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
|
|
1351
|
+
*/
|
|
1352
|
+
function scheduleNotification(context, scheduledTime, tags, notification, options = {}) {
|
|
1353
|
+
return scheduleNotificationPayload(context, scheduledTime, tags, notification, options);
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
// Copyright (c) Microsoft Corporation.
|
|
1357
|
+
/**
|
|
1358
|
+
* @internal
|
|
1359
|
+
*/
|
|
1360
|
+
function sendNotificationPayload(context, notification, method, pushHandle, tags, options = {}) {
|
|
1361
|
+
return tracingClient.withSpan(`NotificationHubsClientContext-${method}`, options, async (updatedOptions) => {
|
|
1362
|
+
const endpoint = context.requestUrl();
|
|
1363
|
+
endpoint.pathname += "/messages/";
|
|
1364
|
+
if (options.enableTestSend) {
|
|
1365
|
+
endpoint.searchParams.append("debug", "true");
|
|
1366
|
+
}
|
|
1367
|
+
const headers = context.createHeaders();
|
|
1368
|
+
if (notification.headers) {
|
|
1369
|
+
for (const headerName of Object.keys(notification.headers)) {
|
|
1370
|
+
headers.set(headerName, notification.headers[headerName]);
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
if (pushHandle) {
|
|
1374
|
+
endpoint.searchParams.append("direct", "true");
|
|
1375
|
+
if (notification.platform === "browser") {
|
|
1376
|
+
const browserHandle = pushHandle;
|
|
1377
|
+
headers.set("ServiceBusNotification-DeviceHandle", browserHandle.endpoint);
|
|
1378
|
+
headers.set("Auth", browserHandle.auth);
|
|
1379
|
+
headers.set("P256DH", browserHandle.p256dh);
|
|
1380
|
+
}
|
|
1381
|
+
else {
|
|
1382
|
+
headers.set("ServiceBusNotification-DeviceHandle", pushHandle);
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
headers.set("Content-Type", notification.contentType);
|
|
1386
|
+
headers.set("ServiceBusNotification-Format", notification.platform);
|
|
1387
|
+
if (tags) {
|
|
1388
|
+
let tagExpression = null;
|
|
1389
|
+
if (Array.isArray(tags)) {
|
|
1390
|
+
tagExpression = tags.join("||");
|
|
1391
|
+
}
|
|
1392
|
+
else {
|
|
1393
|
+
tagExpression = tags;
|
|
1394
|
+
}
|
|
1395
|
+
headers.set("ServiceBusNotification-Tags", tagExpression);
|
|
1396
|
+
}
|
|
1397
|
+
const request = createRequest(endpoint, "POST", headers, updatedOptions);
|
|
1398
|
+
request.body = notification.body;
|
|
1399
|
+
const response = await sendRequest(context, request, 201);
|
|
1400
|
+
return parseNotificationSendResponse(response);
|
|
1401
|
+
});
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
// Copyright (c) Microsoft Corporation.
|
|
1405
|
+
/**
|
|
1406
|
+
* Sends push notifications to all devices on the Notification Hub.
|
|
1407
|
+
* @param context - The Notification Hubs client.
|
|
1408
|
+
* @param notification - The notification to send to all devices.
|
|
1409
|
+
* @param options - Configuration options for the direct send operation which can contain custom headers
|
|
1410
|
+
* which may include APNs specific such as apns-topic or for WNS, X-WNS-TYPE.
|
|
1411
|
+
* @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
|
|
1412
|
+
*/
|
|
1413
|
+
function sendBroadcastNotification(context, notification, options = {}) {
|
|
1414
|
+
return sendNotificationPayload(context, notification, "sendNotification", undefined, undefined, options);
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
// Copyright (c) Microsoft Corporation.
|
|
1418
|
+
/**
|
|
1419
|
+
* Sends a direct push notification to a device with the given push handle.
|
|
1420
|
+
* @param context - The Notification Hubs client.
|
|
1421
|
+
* @param pushHandle - The push handle which is the unique identifier for the device.
|
|
1422
|
+
* @param notification - The notification to send to the device.
|
|
1423
|
+
* @param options - Configuration options for the direct send operation which can contain custom headers
|
|
1424
|
+
* which may include APNs specific such as apns-topic or for WNS, X-WNS-TYPE.
|
|
1425
|
+
* @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
|
|
1426
|
+
*/
|
|
1427
|
+
function sendDirectNotification(context, pushHandle, notification, options = {}) {
|
|
1428
|
+
return sendNotificationPayload(context, notification, "sendDirectNotification", pushHandle, undefined, options);
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
// Copyright (c) Microsoft Corporation.
|
|
1432
|
+
/**
|
|
1433
|
+
* Sends push notifications to devices that match the given tags or tag expression.
|
|
1434
|
+
* @param context - The Notification Hubs client.
|
|
1435
|
+
* @param tags - The tags used to target the device for push notifications in either an array or tag expression.
|
|
1436
|
+
* @param notification - The notification to send to the matching devices.
|
|
1437
|
+
* @param options - Configuration options for the direct send operation which can contain custom headers
|
|
1438
|
+
* which may include APNs specific such as apns-topic or for WNS, X-WNS-TYPE.
|
|
1439
|
+
* @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
|
|
1440
|
+
*/
|
|
1441
|
+
function sendNotification(context, tags, notification, options = {}) {
|
|
1442
|
+
return sendNotificationPayload(context, notification, "sendNotification", undefined, tags, options);
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
// Copyright (c) Microsoft Corporation.
|
|
1446
|
+
/**
|
|
1447
|
+
* Submits a Notification Hub Job.
|
|
1448
|
+
* Note: this is available to Standard SKU namespace and above.
|
|
1449
|
+
* @param context - The Notification Hubs client.
|
|
1450
|
+
* @param job - The notification hub job to submit.
|
|
1451
|
+
* @param options - The operation options.
|
|
1452
|
+
* @returns The notification hub job details including job ID and status.
|
|
1453
|
+
*/
|
|
1454
|
+
function submitNotificationHubJob(context, job, options = {}) {
|
|
1455
|
+
return tracingClient.withSpan("NotificationHubsClientContext-submitNotificationHubJob", options, async (updatedOptions) => {
|
|
1456
|
+
const endpoint = context.requestUrl();
|
|
1457
|
+
endpoint.pathname += "/jobs";
|
|
1458
|
+
const headers = context.createHeaders();
|
|
1459
|
+
headers.set("Content-Type", "application/atom+xml;type=entry;charset=utf-8");
|
|
1460
|
+
const request = createRequest(endpoint, "POST", headers, updatedOptions);
|
|
1461
|
+
request.body = serializeNotificationHubJobEntry(job);
|
|
1462
|
+
const response = await sendRequest(context, request, 201);
|
|
1463
|
+
return parseNotificationHubJobEntry(response.bodyAsText);
|
|
1464
|
+
});
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
// Copyright (c) Microsoft Corporation.
|
|
1468
|
+
/**
|
|
1469
|
+
* Updates an installation using the JSON-Patch standard in RFC6902.
|
|
1470
|
+
* @param context - The Notification Hubs client.
|
|
1471
|
+
* @param installationId - The ID of the installation to update.
|
|
1472
|
+
* @param installationPatches - An array of patches following the JSON-Patch standard.
|
|
1473
|
+
* @param options - Configuration options for the patch installation operation.
|
|
1474
|
+
* @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
|
|
1475
|
+
*/
|
|
1476
|
+
function updateInstallation(context, installationId, installationPatches, options = {}) {
|
|
1477
|
+
return tracingClient.withSpan("NotificationHubsClientContext-updateInstallation", options, async (updatedOptions) => {
|
|
1478
|
+
const endpoint = context.requestUrl();
|
|
1479
|
+
endpoint.pathname += `/installations/${installationId}`;
|
|
1480
|
+
const headers = context.createHeaders();
|
|
1481
|
+
headers.set("Content-Type", "application/json");
|
|
1482
|
+
const request = createRequest(endpoint, "PATCH", headers, updatedOptions);
|
|
1483
|
+
request.body = JSON.stringify(installationPatches);
|
|
1484
|
+
const response = await sendRequest(context, request, 200);
|
|
1485
|
+
return parseNotificationResponse(response);
|
|
1486
|
+
});
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
// Copyright (c) Microsoft Corporation.
|
|
1490
|
+
/**
|
|
1491
|
+
* Updates an existing registration.
|
|
1492
|
+
* @param context - The Notification Hubs client.
|
|
1493
|
+
* @param registration - The registration to update.
|
|
1494
|
+
* @param options - The operation options.
|
|
1495
|
+
* @returns The updated registration description.
|
|
1496
|
+
*/
|
|
1497
|
+
function updateRegistration(context, registration, options = {}) {
|
|
1498
|
+
return tracingClient.withSpan("NotificationHubsClientContext-updateRegistration", options, async (updatedOptions) => {
|
|
1499
|
+
if (!registration.etag) {
|
|
1500
|
+
throw new coreRestPipeline.RestError("ETag is required for registration update", { statusCode: 400 });
|
|
1501
|
+
}
|
|
1502
|
+
return createOrUpdateRegistrationDescription(context, registration, "update", updatedOptions);
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
// Copyright (c) Microsoft Corporation.
|
|
1507
|
+
/**
|
|
1508
|
+
* This represents a client for Azure Notification Hubs to manage installations and send
|
|
1509
|
+
* messages to devices.
|
|
1510
|
+
*/
|
|
1511
|
+
class NotificationHubsServiceClient {
|
|
1512
|
+
/**
|
|
1513
|
+
* Creates a new instance of the NotificationClient with a connection string, hub name and options.
|
|
1514
|
+
* @param connectionString - The Notification Hub Access Policy connection string.
|
|
1515
|
+
* @param hubName - The name of the Azure Notification Hub.
|
|
1516
|
+
* @param options - Options for configuring the Azure Notification Hubs client.
|
|
1517
|
+
*/
|
|
1518
|
+
constructor(connectionString, hubName, options = {}) {
|
|
1519
|
+
this._client = createClientContext(connectionString, hubName, options);
|
|
1520
|
+
}
|
|
1521
|
+
/**
|
|
1522
|
+
* Creates or overwrites an installation to a Notification Hub.
|
|
1523
|
+
* @param installation - The installation to create or overwrite.
|
|
1524
|
+
* @param options - Configuration options for the create or update installation operation.
|
|
1525
|
+
* @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
|
|
1526
|
+
*/
|
|
1527
|
+
createOrUpdateInstallation(installation, options = {}) {
|
|
1528
|
+
return createOrUpdateInstallation(this._client, installation, options);
|
|
1529
|
+
}
|
|
1530
|
+
/**
|
|
1531
|
+
* Deletes an installation from a Notification Hub.
|
|
1532
|
+
* @param installationId - The installation ID of the installation to delete.
|
|
1533
|
+
* @param options - Configuration options for the installation delete operation.
|
|
1534
|
+
* @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
|
|
1535
|
+
*/
|
|
1536
|
+
deleteInstallation(installationId, options = {}) {
|
|
1537
|
+
return deleteInstallation(this._client, installationId, options);
|
|
1538
|
+
}
|
|
1539
|
+
/**
|
|
1540
|
+
* Gets an Azure Notification Hub installation by the installation ID.
|
|
1541
|
+
* @param installationId - The ID of the installation to get.
|
|
1542
|
+
* @param options - Configuration options for the get installation operation.
|
|
1543
|
+
* @returns The installation that matches the installation ID.
|
|
1544
|
+
*/
|
|
1545
|
+
getInstallation(installationId, options = {}) {
|
|
1546
|
+
return getInstallation(this._client, installationId, options);
|
|
1547
|
+
}
|
|
1548
|
+
/**
|
|
1549
|
+
* Updates an installation using the JSON-Patch standard in RFC6902.
|
|
1550
|
+
* @param installationId - The ID of the installation to update.
|
|
1551
|
+
* @param patches - An array of patches following the JSON-Patch standard.
|
|
1552
|
+
* @param options - Configuration options for the patch installation operation.
|
|
1553
|
+
* @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
|
|
1554
|
+
*/
|
|
1555
|
+
updateInstallation(installationId, patches, options = {}) {
|
|
1556
|
+
return updateInstallation(this._client, installationId, patches, options);
|
|
1557
|
+
}
|
|
1558
|
+
/**
|
|
1559
|
+
* Creates a new registration ID.
|
|
1560
|
+
* @param options - The options for creating a new registration ID.
|
|
1561
|
+
* @returns The newly created registration ID.
|
|
1562
|
+
*/
|
|
1563
|
+
createRegistrationId(options = {}) {
|
|
1564
|
+
return createRegistrationId(this._client, options);
|
|
1565
|
+
}
|
|
1566
|
+
/**
|
|
1567
|
+
* Creates a new registration. This method generates a registration ID,
|
|
1568
|
+
* which you can subsequently use to retrieve, update, and delete this registration.
|
|
1569
|
+
* @param registration - The registration to create.
|
|
1570
|
+
* @param options - Options for creating a new registration.
|
|
1571
|
+
* @returns The newly created registration description.
|
|
1572
|
+
*/
|
|
1573
|
+
createRegistration(registration, options = {}) {
|
|
1574
|
+
return createRegistration(this._client, registration, options);
|
|
1575
|
+
}
|
|
1576
|
+
/**
|
|
1577
|
+
* Creates or updates a registration.
|
|
1578
|
+
* @param registration - The registration to create or update.
|
|
1579
|
+
* @param options - The operation options.
|
|
1580
|
+
* @returns The created or updated registration description.
|
|
1581
|
+
*/
|
|
1582
|
+
createOrUpdateRegistration(registration, options = {}) {
|
|
1583
|
+
return createOrUpdateRegistration(this._client, registration, options);
|
|
1584
|
+
}
|
|
1585
|
+
/**
|
|
1586
|
+
* Updates an existing registration.
|
|
1587
|
+
* @param registration - The registration to update.
|
|
1588
|
+
* @param options - The operation options.
|
|
1589
|
+
* @returns The updated registration description.
|
|
1590
|
+
*/
|
|
1591
|
+
updateRegistration(registration, options = {}) {
|
|
1592
|
+
return updateRegistration(this._client, registration, options);
|
|
1593
|
+
}
|
|
1594
|
+
/**
|
|
1595
|
+
* Gets a registration by the given registration ID.
|
|
1596
|
+
* @param registrationId - The ID of the registration to get.
|
|
1597
|
+
* @param options - The options for getting a registration by ID.
|
|
1598
|
+
* @returns A RegistrationDescription that has the given registration ID.
|
|
1599
|
+
*/
|
|
1600
|
+
getRegistration(registrationId, options = {}) {
|
|
1601
|
+
return getRegistration(this._client, registrationId, options);
|
|
1602
|
+
}
|
|
1603
|
+
/**
|
|
1604
|
+
* Gets all registrations for the notification hub with the given query options.
|
|
1605
|
+
* @param options - The options for querying the registrations such as $top and $filter.
|
|
1606
|
+
* @returns A paged async iterable containing all of the registrations for the notification hub.
|
|
1607
|
+
*/
|
|
1608
|
+
listRegistrations(options = {}) {
|
|
1609
|
+
return listRegistrations(this._client, options);
|
|
1610
|
+
}
|
|
1611
|
+
/**
|
|
1612
|
+
* Lists all registrations with the matching tag.
|
|
1613
|
+
* @param tag - The tag to query for matching registrations.
|
|
1614
|
+
* @param options - The query options such as $top.
|
|
1615
|
+
* @returns A paged async iterable containing the matching registrations for the notification hub.
|
|
1616
|
+
*/
|
|
1617
|
+
listRegistrationsByTag(tag, options = {}) {
|
|
1618
|
+
return listRegistrationsByTag(this._client, tag, options);
|
|
1619
|
+
}
|
|
1620
|
+
/**
|
|
1621
|
+
* Sends a direct push notification to a device with the given push handle.
|
|
1622
|
+
* @param pushHandle - The push handle which is the unique identifier for the device.
|
|
1623
|
+
* @param notification - The notification to send to the device.
|
|
1624
|
+
* @param options - Configuration options for the direct send operation which can contain custom headers
|
|
1625
|
+
* which may include APNs specific such as apns-topic or for WNS, X-WNS-TYPE.
|
|
1626
|
+
* @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
|
|
1627
|
+
*/
|
|
1628
|
+
sendDirectNotification(pushHandle, notification, options = {}) {
|
|
1629
|
+
return sendDirectNotification(this._client, pushHandle, notification, options);
|
|
1630
|
+
}
|
|
1631
|
+
/**
|
|
1632
|
+
* Sends push notifications to devices that match the given tags or tag expression.
|
|
1633
|
+
* @param tags - The tags used to target the device for push notifications in either an array or tag expression.
|
|
1634
|
+
* @param notification - The notification to send to the matching devices.
|
|
1635
|
+
* @param options - Configuration options for the direct send operation which can contain custom headers
|
|
1636
|
+
* which may include APNs specific such as apns-topic or for WNS, X-WNS-TYPE.
|
|
1637
|
+
* @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
|
|
1638
|
+
*/
|
|
1639
|
+
sendNotification(tags, notification, options = {}) {
|
|
1640
|
+
return sendNotification(this._client, tags, notification, options);
|
|
1641
|
+
}
|
|
1642
|
+
/**
|
|
1643
|
+
* Sends push notifications to all devices on the Notification Hub.
|
|
1644
|
+
* @param notification - The notification to send to all devices.
|
|
1645
|
+
* @param options - Configuration options for the direct send operation which can contain custom headers
|
|
1646
|
+
* which may include APNs specific such as apns-topic or for WNS, X-WNS-TYPE.
|
|
1647
|
+
* @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
|
|
1648
|
+
*/
|
|
1649
|
+
sendBroadcastNotification(notification, options = {}) {
|
|
1650
|
+
return sendBroadcastNotification(this._client, notification, options);
|
|
1651
|
+
}
|
|
1652
|
+
/**
|
|
1653
|
+
* Schedules a push notification to devices that match the given tags or tag expression at the specified time.
|
|
1654
|
+
* NOTE: This is only available in Standard SKU Azure Notification Hubs.
|
|
1655
|
+
* @param scheduledTime - The Date to send the push notification.
|
|
1656
|
+
* @param tags - The tags used to target the device for push notifications in either an array or tag expression.
|
|
1657
|
+
* @param notification - The notification to send to the matching devices.
|
|
1658
|
+
* @param options - Configuration options for the direct send operation which can contain custom headers
|
|
1659
|
+
* which may include APNs specific such as apns-topic or for WNS, X-WNS-TYPE.
|
|
1660
|
+
* @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
|
|
1661
|
+
*/
|
|
1662
|
+
scheduleNotification(scheduledTime, tags, notification, options = {}) {
|
|
1663
|
+
return scheduleNotification(this._client, scheduledTime, tags, notification, options);
|
|
1664
|
+
}
|
|
1665
|
+
/**
|
|
1666
|
+
* Schedules a push notification to all devices registered on the Notification Hub.
|
|
1667
|
+
* NOTE: This is only available in Standard SKU Azure Notification Hubs.
|
|
1668
|
+
* @param scheduledTime - The Date to send the push notification.
|
|
1669
|
+
* @param notification - The notification to send to the matching devices.
|
|
1670
|
+
* @param options - Configuration options for the direct send operation which can contain custom headers
|
|
1671
|
+
* which may include APNs specific such as apns-topic or for WNS, X-WNS-TYPE.
|
|
1672
|
+
* @returns A NotificationHubResponse with the tracking ID, correlation ID and location.
|
|
1673
|
+
*/
|
|
1674
|
+
scheduleBroadcastNotification(scheduledTime, notification, options = {}) {
|
|
1675
|
+
return scheduleBroadcastNotification(this._client, scheduledTime, notification, options);
|
|
1676
|
+
}
|
|
1677
|
+
/**
|
|
1678
|
+
* Cancels the scheduled notification with the given notification ID.
|
|
1679
|
+
* @param notificationId - The notification ID from the scheduled notification.
|
|
1680
|
+
* @param options - The operation options.
|
|
1681
|
+
* @returns A notification hub response with correlation ID and tracking ID.
|
|
1682
|
+
*/
|
|
1683
|
+
cancelScheduledNotification(notificationId, options = {}) {
|
|
1684
|
+
return cancelScheduledNotification(this._client, notificationId, options);
|
|
1685
|
+
}
|
|
1686
|
+
/**
|
|
1687
|
+
* Retrieves an Azure Storage container URL. The container has feedback data for the notification hub.
|
|
1688
|
+
* The caller can then use the Azure Storage Services SDK to retrieve the contents of the container.
|
|
1689
|
+
* @param options - The options for getting the push notification feedback container URL.
|
|
1690
|
+
* @returns The URL of the Azure Storage Container containing the feedback data.
|
|
1691
|
+
*/
|
|
1692
|
+
getFeedbackContainerUrl(options = {}) {
|
|
1693
|
+
return getFeedbackContainerUrl(this._client, options);
|
|
1694
|
+
}
|
|
1695
|
+
/**
|
|
1696
|
+
* Retrieves the results of a send operation. This can retrieve intermediate results if the send is being processed
|
|
1697
|
+
* or final results if the Send* has completed. This API can only be called for Standard SKU and above.
|
|
1698
|
+
* @param notificationId - The notification ID returned from the send operation.
|
|
1699
|
+
* @param options - The operation options.
|
|
1700
|
+
* @returns The results of the send operation.
|
|
1701
|
+
*/
|
|
1702
|
+
getNotificationOutcomeDetails(notificationId, options = {}) {
|
|
1703
|
+
return getNotificationOutcomeDetails(this._client, notificationId, options);
|
|
1704
|
+
}
|
|
1705
|
+
/**
|
|
1706
|
+
* Gets a Notification Hub Job by the ID.
|
|
1707
|
+
* @param jobId - The Notification Hub Job ID.
|
|
1708
|
+
* @param options - The operation options.
|
|
1709
|
+
* @returns The Notification Hub Job with the matching ID.
|
|
1710
|
+
*/
|
|
1711
|
+
getNotificationHubJob(jobId, options = {}) {
|
|
1712
|
+
return getNotificationHubJob(this._client, jobId, options);
|
|
1713
|
+
}
|
|
1714
|
+
/**
|
|
1715
|
+
* Submits a Notification Hub Job. Note this is available to Standard SKU namespace and above.
|
|
1716
|
+
* @param job - The notification hub job to submit.
|
|
1717
|
+
* @param options - The operation options.
|
|
1718
|
+
* @returns The notification hub job details including job ID and status.
|
|
1719
|
+
*/
|
|
1720
|
+
submitNotificationHubJob(job, options = {}) {
|
|
1721
|
+
return submitNotificationHubJob(this._client, job, options);
|
|
1722
|
+
}
|
|
1723
|
+
/**
|
|
1724
|
+
* Gets all Notification Hub Jobs for this Notification Hub.
|
|
1725
|
+
* @param options - The operation options.
|
|
1726
|
+
* @returns An array of all Notification Hub Jobs for this Notification Hub.
|
|
1727
|
+
*/
|
|
1728
|
+
listNotificationHubJobs(options = {}) {
|
|
1729
|
+
return listNotificationHubJobs(this._client, options);
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
// Copyright (c) Microsoft Corporation.
|
|
1734
|
+
// Licensed under the MIT license.
|
|
1735
|
+
/**
|
|
1736
|
+
* Creates an Apple based installation.
|
|
1737
|
+
* @param installation - A partial installation used to create the Apple installation.
|
|
1738
|
+
* @returns The newly created Apple installation.
|
|
1739
|
+
*/
|
|
1740
|
+
function createAppleInstallation(installation) {
|
|
1741
|
+
return Object.assign(Object.assign({}, installation), { platform: "apns" });
|
|
1742
|
+
}
|
|
1743
|
+
/**
|
|
1744
|
+
* Creates an Amazon Device Messaging (ADM) based installation.
|
|
1745
|
+
* @param installation - A partial installation used to create the ADM installation.
|
|
1746
|
+
* @returns The newly created ADM installation.
|
|
1747
|
+
*/
|
|
1748
|
+
function createAdmInstallation(installation) {
|
|
1749
|
+
return Object.assign(Object.assign({}, installation), { platform: "adm" });
|
|
1750
|
+
}
|
|
1751
|
+
/**
|
|
1752
|
+
* Creates a Baidu based installation.
|
|
1753
|
+
* @param installation - A partial installation used to create the Baidu installation.
|
|
1754
|
+
* @returns The newly created Baidu installation.
|
|
1755
|
+
*/
|
|
1756
|
+
function createBaiduInstallation(installation) {
|
|
1757
|
+
return Object.assign(Object.assign({}, installation), { platform: "baidu" });
|
|
1758
|
+
}
|
|
1759
|
+
/**
|
|
1760
|
+
* Creates a Firebase legacy HTTP based installation.
|
|
1761
|
+
* @param installation - A partial installation used to create the Firebase Legacy HTTP installation.
|
|
1762
|
+
* @returns The newly created Baidu installation.
|
|
1763
|
+
*/
|
|
1764
|
+
function createFirebaseLegacyInstallation(installation) {
|
|
1765
|
+
return Object.assign(Object.assign({}, installation), { platform: "gcm" });
|
|
1766
|
+
}
|
|
1767
|
+
/**
|
|
1768
|
+
* Creates a Windows Notification Services (WNS) based installation.
|
|
1769
|
+
* @param installation - A partial installation used to create the WNS installation.
|
|
1770
|
+
* @returns The newly created WNS installation.
|
|
1771
|
+
*/
|
|
1772
|
+
function createWindowsInstallation(installation) {
|
|
1773
|
+
return Object.assign(Object.assign({}, installation), { platform: "wns" });
|
|
1774
|
+
}
|
|
1775
|
+
/**
|
|
1776
|
+
* Creates a Web Push based installation.
|
|
1777
|
+
* @param installation - A partial installation used to create the Web Push installation.
|
|
1778
|
+
* @returns The newly created Web Push installation.
|
|
1779
|
+
*/
|
|
1780
|
+
function createBrowserInstallation(installation) {
|
|
1781
|
+
return Object.assign(Object.assign({}, installation), { platform: "browser" });
|
|
1782
|
+
}
|
|
1783
|
+
|
|
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
|
+
// Copyright (c) Microsoft Corporation.
|
|
1796
|
+
/**
|
|
1797
|
+
* Creates a notification to send to an Apple device.
|
|
1798
|
+
* @param notification - A partial message used to create a message for Apple.
|
|
1799
|
+
* @returns A newly created Apple.
|
|
1800
|
+
*/
|
|
1801
|
+
function createAppleNotification(notification) {
|
|
1802
|
+
return Object.assign(Object.assign({}, notification), { platform: "apple", contentType: JSON_CONTENT_TYPE });
|
|
1803
|
+
}
|
|
1804
|
+
/**
|
|
1805
|
+
* Creates a notification to send to an Amazon Device Messaging device.
|
|
1806
|
+
* @param notification - A partial message used to create a message for Amazon Device Messaging.
|
|
1807
|
+
* @returns A newly created Amazon Device Messaging.
|
|
1808
|
+
*/
|
|
1809
|
+
function createAdmNotification(notification) {
|
|
1810
|
+
return Object.assign(Object.assign({}, notification), { platform: "adm", contentType: JSON_CONTENT_TYPE });
|
|
1811
|
+
}
|
|
1812
|
+
/**
|
|
1813
|
+
* Creates a notification to send to a Baidu registered device.
|
|
1814
|
+
* @param notification - A partial message used to create a message for Baidu.
|
|
1815
|
+
* @returns A newly created Baidu.
|
|
1816
|
+
*/
|
|
1817
|
+
function createBaiduNotification(notification) {
|
|
1818
|
+
return Object.assign(Object.assign({}, notification), { platform: "baidu", contentType: JSON_CONTENT_TYPE });
|
|
1819
|
+
}
|
|
1820
|
+
/**
|
|
1821
|
+
* Creates a notification to send to a browser.
|
|
1822
|
+
* @param notification - A partial message used to create a message for a browser.
|
|
1823
|
+
* @returns A newly created Web Push browser.
|
|
1824
|
+
*/
|
|
1825
|
+
function createBrowserNotification(notification) {
|
|
1826
|
+
return Object.assign(Object.assign({}, notification), { platform: "browser", contentType: JSON_CONTENT_TYPE });
|
|
1827
|
+
}
|
|
1828
|
+
/**
|
|
1829
|
+
* Creates a notification to send to Firebase.
|
|
1830
|
+
* @param notification - A partial message used to create a message for Firebase.
|
|
1831
|
+
* @returns A newly created Firebase.
|
|
1832
|
+
*/
|
|
1833
|
+
function createFirebaseLegacyNotification(notification) {
|
|
1834
|
+
return Object.assign(Object.assign({}, notification), { platform: "gcm", contentType: JSON_CONTENT_TYPE });
|
|
1835
|
+
}
|
|
1836
|
+
/**
|
|
1837
|
+
* Creates a notification to send to Firebase.
|
|
1838
|
+
* @param notification - A partial message used to create a message for Firebase.
|
|
1839
|
+
* @returns A newly created Firebase.
|
|
1840
|
+
*/
|
|
1841
|
+
function createTemplateNotification(notification) {
|
|
1842
|
+
return Object.assign(Object.assign({}, notification), { platform: "template", contentType: JSON_CONTENT_TYPE });
|
|
1843
|
+
}
|
|
1844
|
+
/**
|
|
1845
|
+
* Creates a badge message to send to WNS.
|
|
1846
|
+
* @param notification - A partial message used to create a badge message for WNS.
|
|
1847
|
+
* @returns A newly created WNS badge.
|
|
1848
|
+
*/
|
|
1849
|
+
function createWindowsBadgeNotification(notification) {
|
|
1850
|
+
const result = Object.assign(Object.assign({}, notification), { platform: "wns", contentType: XML_CONTENT_TYPE });
|
|
1851
|
+
if (!result.headers) {
|
|
1852
|
+
result.headers = {};
|
|
1853
|
+
}
|
|
1854
|
+
result.headers[WNS_TYPE_NAME] = WNS_BADGE;
|
|
1855
|
+
return result;
|
|
1856
|
+
}
|
|
1857
|
+
/**
|
|
1858
|
+
* Creates a tile message to send to WNS.
|
|
1859
|
+
* @param notification - A partial message used to create a tile message for WNS.
|
|
1860
|
+
* @returns A newly created WNS tile.
|
|
1861
|
+
*/
|
|
1862
|
+
function createWindowsTileNotification(notification) {
|
|
1863
|
+
const result = Object.assign(Object.assign({}, notification), { platform: "wns", contentType: XML_CONTENT_TYPE });
|
|
1864
|
+
if (!result.headers) {
|
|
1865
|
+
result.headers = {};
|
|
1866
|
+
}
|
|
1867
|
+
result.headers[WNS_TYPE_NAME] = WNS_TITLE;
|
|
1868
|
+
return result;
|
|
1869
|
+
}
|
|
1870
|
+
/**
|
|
1871
|
+
* Creates a toast message to send to WNS.
|
|
1872
|
+
* @param notification - A partial message used to create a toast message for WNS.
|
|
1873
|
+
* @returns A newly created WNS toast.
|
|
1874
|
+
*/
|
|
1875
|
+
function createWindowsToastNotification(notification) {
|
|
1876
|
+
const result = Object.assign(Object.assign({}, notification), { platform: "wns", contentType: XML_CONTENT_TYPE });
|
|
1877
|
+
if (!result.headers) {
|
|
1878
|
+
result.headers = {};
|
|
1879
|
+
}
|
|
1880
|
+
result.headers[WNS_TYPE_NAME] = WNS_TOAST;
|
|
1881
|
+
return result;
|
|
1882
|
+
}
|
|
1883
|
+
/**
|
|
1884
|
+
* Creates a notification to send to WNS in wns/raw format..
|
|
1885
|
+
* @param notification - A partial message used to create a message for WNS in XML format.
|
|
1886
|
+
* @returns A newly created WNS message using XML.
|
|
1887
|
+
*/
|
|
1888
|
+
function createWindowsRawNotification(notification) {
|
|
1889
|
+
const result = Object.assign(Object.assign({}, notification), { platform: "wns", contentType: STREAM_CONTENT_TYPE });
|
|
1890
|
+
if (!result.headers) {
|
|
1891
|
+
result.headers = {};
|
|
1892
|
+
}
|
|
1893
|
+
result.headers[WNS_TYPE_NAME] = WNS_RAW;
|
|
1894
|
+
return result;
|
|
1895
|
+
}
|
|
1896
|
+
|
|
1897
|
+
// Copyright (c) Microsoft Corporation.
|
|
1898
|
+
function createAppleNativeAlert(nativeAlert) {
|
|
1899
|
+
if (!isDefined(nativeAlert)) {
|
|
1900
|
+
return undefined;
|
|
1901
|
+
}
|
|
1902
|
+
if (isString(nativeAlert)) {
|
|
1903
|
+
return nativeAlert;
|
|
1904
|
+
}
|
|
1905
|
+
const alert = {
|
|
1906
|
+
title: nativeAlert.title,
|
|
1907
|
+
subtitle: nativeAlert.subtitle,
|
|
1908
|
+
body: nativeAlert.body,
|
|
1909
|
+
"launch-image": nativeAlert.launchImage,
|
|
1910
|
+
"title-loc-key": nativeAlert.titleLocKey,
|
|
1911
|
+
"title-loc-args": nativeAlert.titleLocArgs,
|
|
1912
|
+
"subtitle-loc-key": nativeAlert.subtitleLocKey,
|
|
1913
|
+
"subtitle-loc-args": nativeAlert.subtitleLocArgs,
|
|
1914
|
+
"loc-key": nativeAlert.locKey,
|
|
1915
|
+
"loc-args": nativeAlert.locArgs,
|
|
1916
|
+
};
|
|
1917
|
+
return alert;
|
|
1918
|
+
}
|
|
1919
|
+
/**
|
|
1920
|
+
* Creates an APNs native message to send to Notification Hubs.
|
|
1921
|
+
* @param nativeMessage - The Apple native message properties to set.
|
|
1922
|
+
* @param additionalProperties - Additional properties for Apple messages.
|
|
1923
|
+
* @returns An AppleNotification to send to Notification Hubs.
|
|
1924
|
+
*/
|
|
1925
|
+
function buildAppleNativeMessage(nativeMessage, additionalProperties) {
|
|
1926
|
+
const headers = {};
|
|
1927
|
+
const message = Object.assign({ aps: {
|
|
1928
|
+
alert: createAppleNativeAlert(nativeMessage.alert),
|
|
1929
|
+
sound: nativeMessage.sound,
|
|
1930
|
+
badge: nativeMessage.badge,
|
|
1931
|
+
"thread-id": nativeMessage.threadId,
|
|
1932
|
+
category: nativeMessage.category,
|
|
1933
|
+
"content-available": nativeMessage.contentAvailable,
|
|
1934
|
+
"mutable-content": nativeMessage.mutableContent,
|
|
1935
|
+
"target-content-id": nativeMessage.targetContentId,
|
|
1936
|
+
"interruption-level": nativeMessage.interruptionLevel,
|
|
1937
|
+
"relevance-score": nativeMessage.relevanceScore,
|
|
1938
|
+
"filter-criteria": nativeMessage.filterCriteria,
|
|
1939
|
+
} }, additionalProperties);
|
|
1940
|
+
const apnsPriority = (nativeMessage === null || nativeMessage === void 0 ? void 0 : nativeMessage.contentAvailable) === 1 ? "5" : "10";
|
|
1941
|
+
headers["apns-priority"] = apnsPriority;
|
|
1942
|
+
return createAppleNotification({
|
|
1943
|
+
body: JSON.stringify(message),
|
|
1944
|
+
headers: headers,
|
|
1945
|
+
});
|
|
1946
|
+
}
|
|
1947
|
+
function buildFirebaseLegacyNativePayload(nativeNotification) {
|
|
1948
|
+
if (!isDefined(nativeNotification)) {
|
|
1949
|
+
return undefined;
|
|
1950
|
+
}
|
|
1951
|
+
const androidMessage = nativeNotification;
|
|
1952
|
+
const appleMessage = nativeNotification;
|
|
1953
|
+
const notification = {
|
|
1954
|
+
title: nativeNotification.title,
|
|
1955
|
+
body: nativeNotification.body,
|
|
1956
|
+
click_action: nativeNotification.clickAction,
|
|
1957
|
+
// Apple/Android fields
|
|
1958
|
+
sound: appleMessage.sound,
|
|
1959
|
+
badge: appleMessage.badge,
|
|
1960
|
+
subtitle: appleMessage.subtitle,
|
|
1961
|
+
body_loc_key: appleMessage.bodyLocKey,
|
|
1962
|
+
body_loc_args: appleMessage.bodyLocArgs,
|
|
1963
|
+
title_loc_key: appleMessage.bodyLocKey,
|
|
1964
|
+
title_loc_args: appleMessage.bodyLocArgs,
|
|
1965
|
+
// Android/Web fields
|
|
1966
|
+
android_channel_id: androidMessage.androidChannelId,
|
|
1967
|
+
icon: androidMessage.icon,
|
|
1968
|
+
tag: androidMessage.tag,
|
|
1969
|
+
color: androidMessage.color,
|
|
1970
|
+
};
|
|
1971
|
+
return notification;
|
|
1972
|
+
}
|
|
1973
|
+
/**
|
|
1974
|
+
* Creates a FirebaseLegacyNotification from a native Firebase payload.
|
|
1975
|
+
* @param nativeMessage - The native message payload to send to Notification Hubs.
|
|
1976
|
+
* @returns The FirebaseLegacyNotification to send to Notification Hubs.
|
|
1977
|
+
*/
|
|
1978
|
+
function buildFirebaseLegacyNativeMessage(nativeMessage) {
|
|
1979
|
+
const jsonMessage = {
|
|
1980
|
+
to: nativeMessage.to,
|
|
1981
|
+
registration_ids: nativeMessage.registrationIds,
|
|
1982
|
+
condition: nativeMessage.condition,
|
|
1983
|
+
collapse_key: nativeMessage.collapseKey,
|
|
1984
|
+
priority: nativeMessage.priority,
|
|
1985
|
+
content_available: nativeMessage.contentAvailable,
|
|
1986
|
+
mutable_content: nativeMessage.mutableContent,
|
|
1987
|
+
time_to_live: nativeMessage.timeToLive,
|
|
1988
|
+
restricted_package_name: nativeMessage.restrictedPackageName,
|
|
1989
|
+
dry_run: nativeMessage.dryRun,
|
|
1990
|
+
data: nativeMessage.data,
|
|
1991
|
+
notification: buildFirebaseLegacyNativePayload(nativeMessage.notification),
|
|
1992
|
+
};
|
|
1993
|
+
return createFirebaseLegacyNotification({
|
|
1994
|
+
body: JSON.stringify(jsonMessage),
|
|
1995
|
+
});
|
|
1996
|
+
}
|
|
1997
|
+
function buildAdmNativeNotification(nativeNotification) {
|
|
1998
|
+
if (!isDefined(nativeNotification)) {
|
|
1999
|
+
return undefined;
|
|
2000
|
+
}
|
|
2001
|
+
return {
|
|
2002
|
+
title: nativeNotification.title,
|
|
2003
|
+
body: nativeNotification.body,
|
|
2004
|
+
icon: nativeNotification.icon,
|
|
2005
|
+
color: nativeNotification.color,
|
|
2006
|
+
sound: nativeNotification.sound,
|
|
2007
|
+
tag: nativeNotification.tag,
|
|
2008
|
+
click_action: nativeNotification.clickAction,
|
|
2009
|
+
body_loc_key: nativeNotification.bodyLocKey,
|
|
2010
|
+
body_loc_args: nativeNotification.bodyLocArgs,
|
|
2011
|
+
title_loc_key: nativeNotification.titleLocKey,
|
|
2012
|
+
title_loc_args: nativeNotification.titleLocArgs,
|
|
2013
|
+
channel_id: nativeNotification.channelId,
|
|
2014
|
+
ticker: nativeNotification.ticker,
|
|
2015
|
+
sticky: nativeNotification.sticky,
|
|
2016
|
+
event_time: nativeNotification.eventTime,
|
|
2017
|
+
local_only: nativeNotification.localOnly,
|
|
2018
|
+
notification_priority: nativeNotification.notificationPriority,
|
|
2019
|
+
default_sound: nativeNotification.defaultSound,
|
|
2020
|
+
visibility: nativeNotification.visibility,
|
|
2021
|
+
notification_count: nativeNotification.notificationCount,
|
|
2022
|
+
image: nativeNotification.image,
|
|
2023
|
+
};
|
|
2024
|
+
}
|
|
2025
|
+
/**
|
|
2026
|
+
* Creates a AdmNotification from a native ADM payload.
|
|
2027
|
+
* @param nativeMessage - The native message payload to send to Notification Hubs.
|
|
2028
|
+
* @returns The AdmNotification to send to Notification Hubs.
|
|
2029
|
+
*/
|
|
2030
|
+
function buildAdmNativeMessage(nativeMessage) {
|
|
2031
|
+
const jsonObj = Object.assign({ notification: buildAdmNativeNotification(nativeMessage.notification), data: nativeMessage.data || {} }, nativeMessage);
|
|
2032
|
+
return createAdmNotification({
|
|
2033
|
+
body: JSON.stringify(jsonObj),
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
/**
|
|
2037
|
+
* Creates a BaiduNotification from a native Baidu payload.
|
|
2038
|
+
* @param nativeMessage - The native message payload to send to Notification Hubs.
|
|
2039
|
+
* @param additionalProperties - Additional properties for Apple Baidu messages.
|
|
2040
|
+
* @returns The BaiduNotification to send to Notification Hubs.
|
|
2041
|
+
*/
|
|
2042
|
+
function buildBaiduNativeMessage(nativeMessage, additionalProperties) {
|
|
2043
|
+
const jsonObj = Object.assign({ title: nativeMessage.title, description: nativeMessage.description, notification_builder_id: nativeMessage.notificationBuilderId, notification_basic_style: nativeMessage.notificationBasicStyle, open_type: nativeMessage.openType, net_support: nativeMessage.netSupport, user_confirm: nativeMessage.userConfirm, url: nativeMessage.url, pkg_content: nativeMessage.pkgContent, pkg_version: nativeMessage.pkgVersion, custom_content: nativeMessage.customContent, aps: nativeMessage.aps }, additionalProperties);
|
|
2044
|
+
return createBaiduNotification({
|
|
2045
|
+
body: JSON.stringify(jsonObj),
|
|
2046
|
+
});
|
|
2047
|
+
}
|
|
2048
|
+
/**
|
|
2049
|
+
* Builds a WindowsNotification from a Windows Badge.
|
|
2050
|
+
* @param nativeMessage - The Windows Badge Message to build.
|
|
2051
|
+
* @returns A WindowsNotification created with the badge information.
|
|
2052
|
+
*/
|
|
2053
|
+
function buildWindowsBadgeNativeMessage(nativeMessage) {
|
|
2054
|
+
const badge = {
|
|
2055
|
+
$: { value: nativeMessage.value },
|
|
2056
|
+
};
|
|
2057
|
+
return createWindowsBadgeNotification({
|
|
2058
|
+
body: coreXml.stringifyXML(badge, { rootName: "badge" }),
|
|
2059
|
+
});
|
|
2060
|
+
}
|
|
2061
|
+
|
|
2062
|
+
// Copyright (c) Microsoft Corporation.
|
|
2063
|
+
// Licensed under the MIT license.
|
|
2064
|
+
/**
|
|
2065
|
+
* Creates an ADM registration description.
|
|
2066
|
+
* @param description - A partial ADM registration description.
|
|
2067
|
+
* @returns A created ADM registration description.
|
|
2068
|
+
*/
|
|
2069
|
+
function createAdmRegistrationDescription(description) {
|
|
2070
|
+
return Object.assign(Object.assign({}, description), { type: "Adm" });
|
|
2071
|
+
}
|
|
2072
|
+
/**
|
|
2073
|
+
* Creates an ADM template registration description.
|
|
2074
|
+
* @param description - A partial ADM template registration description.
|
|
2075
|
+
* @returns A created ADM template registration description.
|
|
2076
|
+
*/
|
|
2077
|
+
function createAdmTemplateRegistrationDescription(description) {
|
|
2078
|
+
return Object.assign(Object.assign({}, description), { type: "AdmTemplate" });
|
|
2079
|
+
}
|
|
2080
|
+
/**
|
|
2081
|
+
* Creates an Apple registration description.
|
|
2082
|
+
* @param description - A partial Apple registration description.
|
|
2083
|
+
* @returns A created Apple registration description.
|
|
2084
|
+
*/
|
|
2085
|
+
function createAppleRegistrationDescription(description) {
|
|
2086
|
+
return Object.assign(Object.assign({}, description), { type: "Apple" });
|
|
2087
|
+
}
|
|
2088
|
+
/**
|
|
2089
|
+
* Creates an Apple template registration description.
|
|
2090
|
+
* @param description - A partial Apple template registration description.
|
|
2091
|
+
* @returns A created Apple template registration description.
|
|
2092
|
+
*/
|
|
2093
|
+
function createAppleTemplateRegistrationDescription(description) {
|
|
2094
|
+
return Object.assign(Object.assign({}, description), { type: "AppleTemplate" });
|
|
2095
|
+
}
|
|
2096
|
+
/**
|
|
2097
|
+
* Creates a Baidu registration description.
|
|
2098
|
+
* @param description - A partial Baidu registration description.
|
|
2099
|
+
* @returns A created Baidu registration description.
|
|
2100
|
+
*/
|
|
2101
|
+
function createBaiduRegistrationDescription(description) {
|
|
2102
|
+
return Object.assign(Object.assign({}, description), { type: "Baidu" });
|
|
2103
|
+
}
|
|
2104
|
+
/**
|
|
2105
|
+
* Creates a Baidu template registration description.
|
|
2106
|
+
* @param description - A partial Baidu template registration description.
|
|
2107
|
+
* @returns A created Baidu template registration description.
|
|
2108
|
+
*/
|
|
2109
|
+
function createBaiduTemplateRegistrationDescription(description) {
|
|
2110
|
+
return Object.assign(Object.assign({}, description), { type: "BaiduTemplate" });
|
|
2111
|
+
}
|
|
2112
|
+
/**
|
|
2113
|
+
* Creates a Web Push registration description.
|
|
2114
|
+
* @param description - A partial Web Push registration description.
|
|
2115
|
+
* @returns A created Web Push registration description.
|
|
2116
|
+
*/
|
|
2117
|
+
function createBrowserRegistrationDescription(description) {
|
|
2118
|
+
return Object.assign(Object.assign({}, description), { type: "Browser" });
|
|
2119
|
+
}
|
|
2120
|
+
/**
|
|
2121
|
+
* Creates a Web Push registration description.
|
|
2122
|
+
* @param description - A partial Web Push template registration description.
|
|
2123
|
+
* @returns A created Web Push template registration description.
|
|
2124
|
+
*/
|
|
2125
|
+
function createBrowserTemplateRegistrationDescription(description) {
|
|
2126
|
+
return Object.assign(Object.assign({}, description), { type: "BrowserTemplate" });
|
|
2127
|
+
}
|
|
2128
|
+
/**
|
|
2129
|
+
* @deprecated Use createFcmRegistrationDescription instead.
|
|
2130
|
+
* Creates a GCM registration description.
|
|
2131
|
+
* @param description - A partial GCM registration description.
|
|
2132
|
+
* @returns A created GCM registration description.
|
|
2133
|
+
*/
|
|
2134
|
+
function createGcmRegistrationDescription(description) {
|
|
2135
|
+
return Object.assign(Object.assign({}, description), { type: "Gcm" });
|
|
2136
|
+
}
|
|
2137
|
+
/**
|
|
2138
|
+
* @deprecated Use createFcmTemplateRegistrationDescription instead.
|
|
2139
|
+
* Creates a GCM template registration description.
|
|
2140
|
+
* @param description - A partial GCM template registration description.
|
|
2141
|
+
* @returns A created GCM template registration description.
|
|
2142
|
+
*/
|
|
2143
|
+
function createGcmTemplateRegistrationDescription(description) {
|
|
2144
|
+
return Object.assign(Object.assign({}, description), { type: "GcmTemplate" });
|
|
2145
|
+
}
|
|
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
|
+
/**
|
|
2181
|
+
* Creates a Windows registration description.
|
|
2182
|
+
* @param description - A partial Windows registration description.
|
|
2183
|
+
* @returns A created Windows registration description.
|
|
2184
|
+
*/
|
|
2185
|
+
function createWindowsRegistrationDescription(description) {
|
|
2186
|
+
return Object.assign(Object.assign({}, description), { type: "Windows" });
|
|
2187
|
+
}
|
|
2188
|
+
/**
|
|
2189
|
+
* Creates a Windows template registration description.
|
|
2190
|
+
* @param description - A partial Windows template registration description.
|
|
2191
|
+
* @returns A created Windows template registration description.
|
|
2192
|
+
*/
|
|
2193
|
+
function createWindowsTemplateRegistrationDescription(description) {
|
|
2194
|
+
return Object.assign(Object.assign({}, description), { type: "WindowsTemplate" });
|
|
2195
|
+
}
|
|
2196
|
+
|
|
2197
|
+
exports.NotificationHubsServiceClient = NotificationHubsServiceClient;
|
|
2198
|
+
exports.buildAdmNativeMessage = buildAdmNativeMessage;
|
|
2199
|
+
exports.buildAppleNativeMessage = buildAppleNativeMessage;
|
|
2200
|
+
exports.buildBaiduNativeMessage = buildBaiduNativeMessage;
|
|
2201
|
+
exports.buildFirebaseLegacyNativeMessage = buildFirebaseLegacyNativeMessage;
|
|
2202
|
+
exports.buildWindowsBadgeNativeMessage = buildWindowsBadgeNativeMessage;
|
|
2203
|
+
exports.createAdmInstallation = createAdmInstallation;
|
|
2204
|
+
exports.createAdmNotification = createAdmNotification;
|
|
2205
|
+
exports.createAdmRegistrationDescription = createAdmRegistrationDescription;
|
|
2206
|
+
exports.createAdmTemplateRegistrationDescription = createAdmTemplateRegistrationDescription;
|
|
2207
|
+
exports.createAppleInstallation = createAppleInstallation;
|
|
2208
|
+
exports.createAppleNotification = createAppleNotification;
|
|
2209
|
+
exports.createAppleRegistrationDescription = createAppleRegistrationDescription;
|
|
2210
|
+
exports.createAppleTemplateRegistrationDescription = createAppleTemplateRegistrationDescription;
|
|
2211
|
+
exports.createBaiduInstallation = createBaiduInstallation;
|
|
2212
|
+
exports.createBaiduNotification = createBaiduNotification;
|
|
2213
|
+
exports.createBaiduRegistrationDescription = createBaiduRegistrationDescription;
|
|
2214
|
+
exports.createBaiduTemplateRegistrationDescription = createBaiduTemplateRegistrationDescription;
|
|
2215
|
+
exports.createBrowserInstallation = createBrowserInstallation;
|
|
2216
|
+
exports.createBrowserNotification = createBrowserNotification;
|
|
2217
|
+
exports.createBrowserRegistrationDescription = createBrowserRegistrationDescription;
|
|
2218
|
+
exports.createBrowserTemplateRegistrationDescription = createBrowserTemplateRegistrationDescription;
|
|
2219
|
+
exports.createFcmRegistrationDescription = createFcmRegistrationDescription;
|
|
2220
|
+
exports.createFcmTemplateRegistrationDescription = createFcmTemplateRegistrationDescription;
|
|
2221
|
+
exports.createFirebaseLegacyInstallation = createFirebaseLegacyInstallation;
|
|
2222
|
+
exports.createFirebaseLegacyNotification = createFirebaseLegacyNotification;
|
|
2223
|
+
exports.createGcmRegistrationDescription = createGcmRegistrationDescription;
|
|
2224
|
+
exports.createGcmTemplateRegistrationDescription = createGcmTemplateRegistrationDescription;
|
|
2225
|
+
exports.createMpnsRegistrationDescription = createMpnsRegistrationDescription;
|
|
2226
|
+
exports.createMpnsTemplateRegistrationDescription = createMpnsTemplateRegistrationDescription;
|
|
2227
|
+
exports.createTemplateNotification = createTemplateNotification;
|
|
2228
|
+
exports.createWindowsBadgeNotification = createWindowsBadgeNotification;
|
|
2229
|
+
exports.createWindowsInstallation = createWindowsInstallation;
|
|
2230
|
+
exports.createWindowsRawNotification = createWindowsRawNotification;
|
|
2231
|
+
exports.createWindowsRegistrationDescription = createWindowsRegistrationDescription;
|
|
2232
|
+
exports.createWindowsTemplateRegistrationDescription = createWindowsTemplateRegistrationDescription;
|
|
2233
|
+
exports.createWindowsTileNotification = createWindowsTileNotification;
|
|
2234
|
+
exports.createWindowsToastNotification = createWindowsToastNotification;
|
|
2235
|
+
//# sourceMappingURL=index.js.map
|