@azure/notification-hubs 1.0.3-alpha.20230724.1 → 1.0.3-alpha.20230810.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/dist/index.js +31 -36
- package/dist/index.js.map +1 -1
- package/dist-esm/src/api/cancelScheduledNotification.js.map +1 -1
- package/dist-esm/src/api/clientContext.js +24 -17
- package/dist-esm/src/api/clientContext.js.map +1 -1
- package/dist-esm/src/api/createOrUpdateInstallation.js.map +1 -1
- package/dist-esm/src/api/createOrUpdateRegistration.js.map +1 -1
- package/dist-esm/src/api/createRegistration.js.map +1 -1
- package/dist-esm/src/api/createRegistrationId.js.map +1 -1
- package/dist-esm/src/api/deleteInstallation.js.map +1 -1
- package/dist-esm/src/api/getFeedbackContainerUrl.js.map +1 -1
- package/dist-esm/src/api/getInstallation.js.map +1 -1
- package/dist-esm/src/api/getNotificationHubJob.js.map +1 -1
- package/dist-esm/src/api/getNotificationOutcomeDetails.js.map +1 -1
- package/dist-esm/src/api/getRegistration.js.map +1 -1
- package/dist-esm/src/api/internal/_client.js.map +1 -1
- package/dist-esm/src/api/internal/_createOrUpdateRegistrationDescription.js.map +1 -1
- package/dist-esm/src/api/listNotificationHubJobs.js.map +1 -1
- package/dist-esm/src/api/submitNotificationHubJob.js.map +1 -1
- package/dist-esm/src/api/updateInstallation.js.map +1 -1
- package/dist-esm/src/api/updateRegistration.js.map +1 -1
- package/dist-esm/src/auth/connectionStringUtils.js +5 -5
- package/dist-esm/src/auth/connectionStringUtils.js.map +1 -1
- package/dist-esm/src/auth/{sasTokenProvider.js → sasTokenCredential.js} +5 -18
- package/dist-esm/src/auth/sasTokenCredential.js.map +1 -0
- package/dist-esm/src/models/options.js.map +1 -1
- package/dist-esm/src/notificationHubsClient.js.map +1 -1
- package/package.json +3 -2
- package/types/3.1/notification-hubs.d.ts +3 -3
- package/types/latest/notification-hubs.d.ts +3 -3
- package/types/latest/tsdoc-metadata.json +1 -1
- package/types/src/api/cancelScheduledNotification.d.ts +1 -1
- package/types/src/api/cancelScheduledNotification.d.ts.map +1 -1
- package/types/src/api/clientContext.d.ts +0 -13
- package/types/src/api/clientContext.d.ts.map +1 -1
- package/types/src/api/createOrUpdateInstallation.d.ts +1 -1
- package/types/src/api/createOrUpdateInstallation.d.ts.map +1 -1
- package/types/src/api/createOrUpdateRegistration.d.ts +1 -1
- package/types/src/api/createOrUpdateRegistration.d.ts.map +1 -1
- package/types/src/api/createRegistration.d.ts +1 -1
- package/types/src/api/createRegistration.d.ts.map +1 -1
- package/types/src/api/createRegistrationId.d.ts +1 -1
- package/types/src/api/createRegistrationId.d.ts.map +1 -1
- package/types/src/api/deleteInstallation.d.ts +1 -1
- package/types/src/api/deleteInstallation.d.ts.map +1 -1
- package/types/src/api/getFeedbackContainerUrl.d.ts +1 -1
- package/types/src/api/getFeedbackContainerUrl.d.ts.map +1 -1
- package/types/src/api/getInstallation.d.ts +1 -1
- package/types/src/api/getInstallation.d.ts.map +1 -1
- package/types/src/api/getNotificationHubJob.d.ts +1 -1
- package/types/src/api/getNotificationHubJob.d.ts.map +1 -1
- package/types/src/api/getNotificationOutcomeDetails.d.ts +1 -1
- package/types/src/api/getNotificationOutcomeDetails.d.ts.map +1 -1
- package/types/src/api/getRegistration.d.ts +1 -1
- package/types/src/api/getRegistration.d.ts.map +1 -1
- package/types/src/api/internal/_client.d.ts +1 -1
- package/types/src/api/internal/_client.d.ts.map +1 -1
- package/types/src/api/internal/_createOrUpdateRegistrationDescription.d.ts +1 -1
- package/types/src/api/internal/_createOrUpdateRegistrationDescription.d.ts.map +1 -1
- package/types/src/api/listNotificationHubJobs.d.ts +1 -1
- package/types/src/api/listNotificationHubJobs.d.ts.map +1 -1
- package/types/src/api/submitNotificationHubJob.d.ts +1 -1
- package/types/src/api/submitNotificationHubJob.d.ts.map +1 -1
- package/types/src/api/updateInstallation.d.ts +1 -1
- package/types/src/api/updateInstallation.d.ts.map +1 -1
- package/types/src/api/updateRegistration.d.ts +1 -1
- package/types/src/api/updateRegistration.d.ts.map +1 -1
- package/types/src/auth/connectionStringUtils.d.ts +4 -4
- package/types/src/auth/connectionStringUtils.d.ts.map +1 -1
- package/types/src/auth/sasTokenCredential.d.ts +37 -0
- package/types/src/auth/sasTokenCredential.d.ts.map +1 -0
- package/types/src/models/options.d.ts +2 -2
- package/types/src/models/options.d.ts.map +1 -1
- package/types/src/notificationHubsClient.d.ts +1 -1
- package/types/src/notificationHubsClient.d.ts.map +1 -1
- package/dist-esm/src/auth/sasTokenProvider.js.map +0 -1
- package/types/src/auth/sasTokenProvider.d.ts +0 -77
- package/types/src/auth/sasTokenProvider.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var coreRestPipeline = require('@azure/core-rest-pipeline');
|
|
4
4
|
var crypto = require('crypto');
|
|
5
|
-
var
|
|
6
|
-
var coreClient = require('@azure/core-client');
|
|
5
|
+
var coreClient = require('@azure-rest/core-client');
|
|
7
6
|
var abortController = require('@azure/abort-controller');
|
|
7
|
+
var coreXml = require('@azure/core-xml');
|
|
8
8
|
var coreTracing = require('@azure/core-tracing');
|
|
9
9
|
var tslib = require('tslib');
|
|
10
10
|
var coreUtil = require('@azure/core-util');
|
|
@@ -30,27 +30,13 @@ async function signString(key, toSign) {
|
|
|
30
30
|
|
|
31
31
|
// Copyright (c) Microsoft Corporation.
|
|
32
32
|
// Licensed under the MIT license.
|
|
33
|
-
/**
|
|
34
|
-
* Creates a token provider from the provided shared access data.
|
|
35
|
-
* @param data - The sharedAccessKeyName/sharedAccessKey pair or the sharedAccessSignature.
|
|
36
|
-
* @hidden
|
|
37
|
-
*/
|
|
38
|
-
function createSasTokenProvider(data) {
|
|
39
|
-
return new SasTokenProviderImpl(data);
|
|
40
|
-
}
|
|
41
33
|
/**
|
|
42
34
|
* A TokenProvider that generates a Sas token:
|
|
43
35
|
* `SharedAccessSignature sr=<resource>&sig=<signature>&se=<expiry>&skn=<keyname>`
|
|
44
36
|
*
|
|
45
37
|
* @internal
|
|
46
38
|
*/
|
|
47
|
-
class
|
|
48
|
-
/**
|
|
49
|
-
* Property used to distinguish TokenProvider from TokenCredential.
|
|
50
|
-
*/
|
|
51
|
-
get isSasTokenProvider() {
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
39
|
+
class SasTokenCredential {
|
|
54
40
|
/**
|
|
55
41
|
* Initializes a new instance of SasTokenProvider
|
|
56
42
|
* @param credential - The source `NamedKeyCredential` or `SASCredential`.
|
|
@@ -60,9 +46,10 @@ class SasTokenProviderImpl {
|
|
|
60
46
|
}
|
|
61
47
|
/**
|
|
62
48
|
* Gets the sas token for the specified audience
|
|
63
|
-
* @param
|
|
49
|
+
* @param scopes - The scope for which the token is desired.
|
|
64
50
|
*/
|
|
65
|
-
async getToken(
|
|
51
|
+
async getToken(scopes) {
|
|
52
|
+
const audience = Array.isArray(scopes) ? scopes[0] : scopes;
|
|
66
53
|
return createToken(this._credential.sharedAccessKeyName, this._credential.sharedAccessKey, Math.floor(Date.now() / 1000) + 3600, audience);
|
|
67
54
|
}
|
|
68
55
|
}
|
|
@@ -124,13 +111,13 @@ function parseConnectionString(connectionString) {
|
|
|
124
111
|
return output;
|
|
125
112
|
}
|
|
126
113
|
/**
|
|
127
|
-
* Creates a
|
|
114
|
+
* Creates a SasTokenCredential from a shared access key and shared access key name.
|
|
128
115
|
* @param sharedAccessKey - The shared access key value.
|
|
129
116
|
* @param sharedAccessKeyName - The shared access key name.
|
|
130
|
-
* @returns A
|
|
117
|
+
* @returns A SasTokenCredential with the given shared access token information.
|
|
131
118
|
*/
|
|
132
|
-
function
|
|
133
|
-
return
|
|
119
|
+
function createTokenCredentialFromConnection(sharedAccessKey, sharedAccessKeyName) {
|
|
120
|
+
return new SasTokenCredential({ sharedAccessKey, sharedAccessKeyName });
|
|
134
121
|
}
|
|
135
122
|
/**
|
|
136
123
|
* Parses given connection string into the different properties applicable to Azure Service Bus.
|
|
@@ -169,31 +156,39 @@ const API_VERSION = "2020-06";
|
|
|
169
156
|
function createClientContext(connectionString, hubName, options = {}) {
|
|
170
157
|
return new NotificationHubsServiceClient(connectionString, hubName, options);
|
|
171
158
|
}
|
|
172
|
-
class NotificationHubsServiceClient
|
|
159
|
+
class NotificationHubsServiceClient {
|
|
173
160
|
constructor(connectionString, hubName, options = {}) {
|
|
174
|
-
|
|
175
|
-
parseXML: coreXml.parseXML,
|
|
176
|
-
}, serializationOptions: {
|
|
177
|
-
stringifyXML: coreXml.stringifyXML,
|
|
178
|
-
}, userAgentOptions: {
|
|
179
|
-
userAgentPrefix: `azsdk-js-messaging-notificationhubs/${SDK_VERSION}`,
|
|
180
|
-
} }, options));
|
|
161
|
+
var _a, _b;
|
|
181
162
|
this.hubName = hubName;
|
|
182
163
|
const parsedConnection = parseNotificationHubsConnectionString(connectionString);
|
|
183
|
-
|
|
184
|
-
this.
|
|
164
|
+
// Node doesn't allow change in protocol but browsers do, so doing a string replace
|
|
165
|
+
this.baseUrl = parsedConnection.endpoint.replace("sb://", "https://");
|
|
166
|
+
this.sasTokenCredential = createTokenCredentialFromConnection(parsedConnection.sharedAccessKey, parsedConnection.sharedAccessKeyName);
|
|
167
|
+
const packageDetails = `azsdk-js-notificationhubs/${SDK_VERSION}`;
|
|
168
|
+
const userAgentPrefix = ((_a = options.userAgentOptions) === null || _a === void 0 ? void 0 : _a.userAgentPrefix)
|
|
169
|
+
? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
|
|
170
|
+
: `${packageDetails}`;
|
|
171
|
+
this.httpClient = (_b = options === null || options === void 0 ? void 0 : options.httpClient) !== null && _b !== void 0 ? _b : coreRestPipeline.createDefaultHttpClient();
|
|
172
|
+
this.client = coreClient.getClient(this.baseUrl, Object.assign({ userAgentOptions: {
|
|
173
|
+
userAgentPrefix,
|
|
174
|
+
} }, options));
|
|
185
175
|
}
|
|
186
176
|
async createHeaders(operationName, rawHeaders) {
|
|
187
|
-
const authorization = await this.
|
|
177
|
+
const authorization = await this.sasTokenCredential.getToken(this.baseUrl);
|
|
178
|
+
if (!authorization) {
|
|
179
|
+
throw new coreRestPipeline.RestError("Failed to get the authorization header", { statusCode: 401 });
|
|
180
|
+
}
|
|
188
181
|
const headers = coreRestPipeline.createHttpHeaders(rawHeaders);
|
|
189
182
|
headers.set("Authorization", authorization.token);
|
|
190
183
|
headers.set("x-ms-version", API_VERSION);
|
|
191
184
|
headers.set("x-ms-azsdk-telemetry", `class=NotificationHubsServiceClient;method=${operationName}`);
|
|
192
185
|
return headers;
|
|
193
186
|
}
|
|
187
|
+
sendRequest(request) {
|
|
188
|
+
return this.client.pipeline.sendRequest(this.httpClient, request);
|
|
189
|
+
}
|
|
194
190
|
requestUrl() {
|
|
195
|
-
|
|
196
|
-
const url = new URL(this.baseUrl.replace("sb://", "https://"));
|
|
191
|
+
const url = new URL(this.baseUrl);
|
|
197
192
|
url.pathname = this.hubName;
|
|
198
193
|
url.searchParams.set("api-version", API_VERSION);
|
|
199
194
|
return url;
|