@azure/core-amqp 2.2.0-alpha.20210326.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -2
- package/dist/index.js +301 -39
- package/dist/index.js.map +1 -1
- package/dist-esm/src/amqpAnnotatedMessage.js +7 -0
- package/dist-esm/src/amqpAnnotatedMessage.js.map +1 -1
- package/dist-esm/src/auth/tokenProvider.js +79 -0
- package/dist-esm/src/auth/tokenProvider.js.map +1 -0
- package/dist-esm/src/cbs.js +14 -13
- package/dist-esm/src/cbs.js.map +1 -1
- package/dist-esm/src/errors.js +8 -0
- package/dist-esm/src/errors.js.map +1 -1
- package/dist-esm/src/index.js +3 -2
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/internals.js +6 -0
- package/dist-esm/src/internals.js.map +1 -0
- package/dist-esm/src/messageProperties.js +4 -4
- package/dist-esm/src/messageProperties.js.map +1 -1
- package/dist-esm/src/requestResponseLink.js +2 -2
- package/dist-esm/src/requestResponseLink.js.map +1 -1
- package/dist-esm/src/retry.js +1 -0
- package/dist-esm/src/retry.js.map +1 -1
- package/dist-esm/src/util/lock.js +165 -0
- package/dist-esm/src/util/lock.js.map +1 -0
- package/dist-esm/src/util/typeGuards.js +8 -0
- package/dist-esm/src/util/typeGuards.js.map +1 -1
- package/dist-esm/src/util/utils.js +5 -15
- package/dist-esm/src/util/utils.js.map +1 -1
- package/package.json +6 -9
- package/types/3.1/core-amqp.d.ts +103 -6
- package/types/latest/core-amqp.d.ts +109 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
# Release History
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 3.0.0 (2021-06-09)
|
|
4
|
+
|
|
5
|
+
### Breaking changes
|
|
6
|
+
|
|
7
|
+
- Updates the `rhea-promise` and `rhea` dependencies to version 2.x. `rhea` contains a breaking change that changes deserialization of timestamps from numbers to Date objects.
|
|
8
|
+
- Removes the `AsyncLock` and `defaultLock` exports. `defaultCancellableLock` should be used instead.
|
|
9
|
+
|
|
10
|
+
## 2.3.0 (2021-04-29)
|
|
11
|
+
|
|
12
|
+
- Updates `AmqpAnnotatedMessage` to identify the AMQP section where body data was decoded from. [PR 14703](https://github.com/Azure/azure-sdk-for-js/pull/14703).
|
|
13
|
+
|
|
14
|
+
- Adds `CancellableAsyncLock` as an alternative to `AsyncLock` that supports cancellation via the abort signal. [PR 14844](https://github.com/Azure/azure-sdk-for-js/pull/14844).
|
|
15
|
+
|
|
16
|
+
## 2.2.0 (2021-03-30)
|
|
4
17
|
|
|
5
18
|
- Updates `translateError` to convert non-object type parameters to errors.
|
|
6
19
|
The parameter will be part of the error's `message` property unless the parameter is null or undefined.
|
|
@@ -11,6 +24,7 @@
|
|
|
11
24
|
- CbsClient.init()
|
|
12
25
|
- CbsClient.negotiateClaim()
|
|
13
26
|
- RequestResponseLink.create()
|
|
27
|
+
- Exporting `StandardAbortMessage` that is the standard error message accompanying the `AbortError`.
|
|
14
28
|
|
|
15
29
|
## 2.1.0 (2021-02-08)
|
|
16
30
|
|
|
@@ -138,7 +152,7 @@ We are cleaning the public API surface by
|
|
|
138
152
|
- Updated to use the latest version of the `rhea` package.
|
|
139
153
|
This update improves support for [bundling](https://github.com/Azure/azure-sdk-for-js/blob/master/documentation/Bundling.md) this library.
|
|
140
154
|
|
|
141
|
-
## 1.0.0 (
|
|
155
|
+
## 1.0.0 (2020-01-08)
|
|
142
156
|
|
|
143
157
|
- This release marks the general availability of the `@azure/core-amqp` package.
|
|
144
158
|
- Improved detection of when an established socket is no longer receiving data from the service.
|
package/dist/index.js
CHANGED
|
@@ -7,10 +7,11 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
|
|
|
7
7
|
var tslib = require('tslib');
|
|
8
8
|
var abortController = require('@azure/abort-controller');
|
|
9
9
|
var rheaPromise = require('rhea-promise');
|
|
10
|
-
var AsyncLock = _interopDefault(require('async-lock'));
|
|
11
10
|
var logger$1 = require('@azure/logger');
|
|
12
11
|
var dns = require('dns');
|
|
13
12
|
var os = require('os');
|
|
13
|
+
var coreAuth = require('@azure/core-auth');
|
|
14
|
+
var jssha = _interopDefault(require('jssha'));
|
|
14
15
|
|
|
15
16
|
// Copyright (c) Microsoft Corporation.
|
|
16
17
|
// Licensed under the MIT license.
|
|
@@ -173,6 +174,190 @@ function isObjectWithProperties(thing, properties) {
|
|
|
173
174
|
function objectHasProperty(thing, property) {
|
|
174
175
|
return typeof thing === "object" && property in thing;
|
|
175
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Typeguard that checks if the input is a SasTokenProvider.
|
|
179
|
+
* @param thing - Any object.
|
|
180
|
+
* @hidden
|
|
181
|
+
*/
|
|
182
|
+
function isSasTokenProvider(thing) {
|
|
183
|
+
return isObjectWithProperties(thing, ["isSasTokenProvider"]) && thing.isSasTokenProvider === true;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Copyright (c) Microsoft Corporation.
|
|
187
|
+
/**
|
|
188
|
+
* The \@azure/logger configuration for this package.
|
|
189
|
+
* This will output logs using the `azure:event-hubs` namespace prefix.
|
|
190
|
+
*/
|
|
191
|
+
const logger = logger$1.createClientLogger("core-amqp");
|
|
192
|
+
/**
|
|
193
|
+
* Logs the error's stack trace to "verbose" if a stack trace is available.
|
|
194
|
+
* @param error - Error containing a stack trace.
|
|
195
|
+
* @internal
|
|
196
|
+
*/
|
|
197
|
+
function logErrorStackTrace(error) {
|
|
198
|
+
if (isObjectWithProperties(error, ["stack"])) {
|
|
199
|
+
logger.verbose(error.stack);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Copyright (c) Microsoft Corporation.
|
|
204
|
+
/**
|
|
205
|
+
* This class is used to coordinate executing tasks that should not be run in parallel.
|
|
206
|
+
* @internal
|
|
207
|
+
*/
|
|
208
|
+
class CancellableAsyncLockImpl {
|
|
209
|
+
constructor() {
|
|
210
|
+
this._keyMap = new Map();
|
|
211
|
+
this._executionRunningSet = new Set();
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Returns a promise that resolves to the value returned by the provided task function.
|
|
215
|
+
* Only 1 task can be invoked at a time for a given `key` value.
|
|
216
|
+
*
|
|
217
|
+
* An acquire call can be cancelled via an `abortSignal`.
|
|
218
|
+
* If cancelled, the promise will be rejected with an `AbortError`.
|
|
219
|
+
*
|
|
220
|
+
* `acquireTimeoutInMs` can also be provided to properties.
|
|
221
|
+
* If the timeout is reached before the provided `task` is invoked,
|
|
222
|
+
* then the promise will be rejected with an Error stating the task
|
|
223
|
+
* timed out waiting to acquire a lock.
|
|
224
|
+
*
|
|
225
|
+
* @param key - All `acquire` calls are grouped by the provided `key`.
|
|
226
|
+
* @param task - The function to invoke once the lock has been acquired.
|
|
227
|
+
* @param properties - Additional properties to control the behavior of `acquire`.
|
|
228
|
+
*/
|
|
229
|
+
acquire(key, task, properties) {
|
|
230
|
+
var _a;
|
|
231
|
+
const { abortSignal, timeoutInMs } = properties;
|
|
232
|
+
// Fast exit if the operation is already cancelled.
|
|
233
|
+
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
|
|
234
|
+
return Promise.reject(new abortController.AbortError(StandardAbortMessage));
|
|
235
|
+
}
|
|
236
|
+
// Ensure we've got a task queue for the given key.
|
|
237
|
+
const taskQueue = (_a = this._keyMap.get(key)) !== null && _a !== void 0 ? _a : [];
|
|
238
|
+
this._keyMap.set(key, taskQueue);
|
|
239
|
+
// This method will return a promise that will be fulfilled outside this function.
|
|
240
|
+
const { promise, rejecter, resolver } = getPromiseParts();
|
|
241
|
+
const taskDetails = {
|
|
242
|
+
reject: rejecter,
|
|
243
|
+
resolve: resolver,
|
|
244
|
+
task
|
|
245
|
+
};
|
|
246
|
+
// Handle timeouts by removing the task from the queue when hit.
|
|
247
|
+
if (typeof timeoutInMs === "number") {
|
|
248
|
+
const tid = setTimeout(() => {
|
|
249
|
+
this._removeTaskDetails(key, taskDetails);
|
|
250
|
+
rejecter(new rheaPromise.OperationTimeoutError(`The task timed out waiting to acquire a lock for ${key}`));
|
|
251
|
+
}, timeoutInMs);
|
|
252
|
+
taskDetails.tid = tid;
|
|
253
|
+
}
|
|
254
|
+
// Handle cancellation by removing the task from the queue when cancelled.
|
|
255
|
+
if (abortSignal) {
|
|
256
|
+
const abortListener = () => {
|
|
257
|
+
this._removeTaskDetails(key, taskDetails);
|
|
258
|
+
rejecter(new abortController.AbortError(StandardAbortMessage));
|
|
259
|
+
};
|
|
260
|
+
abortSignal.addEventListener("abort", abortListener);
|
|
261
|
+
taskDetails.abortSignal = abortSignal;
|
|
262
|
+
taskDetails.abortListener = abortListener;
|
|
263
|
+
}
|
|
264
|
+
// Enqueue the task!
|
|
265
|
+
taskQueue.push(taskDetails);
|
|
266
|
+
logger.verbose(`Called acquire() for lock "${key}". Lock "${key}" has ${taskQueue.length} pending tasks.`);
|
|
267
|
+
// Start a loop to iterate over the task queue.
|
|
268
|
+
// This will run asynchronously and won't allow
|
|
269
|
+
// more than 1 concurrent execution per key at a time.
|
|
270
|
+
this._execute(key);
|
|
271
|
+
return promise;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Iterates over all the pending tasks for a given `key` serially.
|
|
275
|
+
*
|
|
276
|
+
* Note: If the pending tasks are already being iterated by an early
|
|
277
|
+
* _execute invocation, this returns immediately.
|
|
278
|
+
* @returns
|
|
279
|
+
*/
|
|
280
|
+
_execute(key) {
|
|
281
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
282
|
+
// If the key already exists in the set, then exit because
|
|
283
|
+
// tasks are already being processed.
|
|
284
|
+
if (this._executionRunningSet.has(key)) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const taskQueue = this._keyMap.get(key);
|
|
288
|
+
// If the queue is empty, exit early!
|
|
289
|
+
if (!taskQueue || !taskQueue.length) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
// Add the key to the set so we can tell the
|
|
293
|
+
// task queue is already being processed.
|
|
294
|
+
this._executionRunningSet.add(key);
|
|
295
|
+
while (taskQueue.length) {
|
|
296
|
+
// Remove tasks from the front of the queue.
|
|
297
|
+
// Order matters!
|
|
298
|
+
const taskDetails = taskQueue.shift();
|
|
299
|
+
if (!taskDetails) {
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
try {
|
|
303
|
+
logger.verbose(`Acquired lock for "${key}", invoking task.`);
|
|
304
|
+
cleanupTaskDetails(taskDetails);
|
|
305
|
+
const value = yield taskDetails.task();
|
|
306
|
+
taskDetails.resolve(value);
|
|
307
|
+
}
|
|
308
|
+
catch (err) {
|
|
309
|
+
taskDetails.reject(err);
|
|
310
|
+
}
|
|
311
|
+
logger.verbose(`Task completed for lock "${key}". Lock "${key}" has ${taskQueue.length} pending tasks.`);
|
|
312
|
+
}
|
|
313
|
+
// Indicate that the task queue for the key is empty
|
|
314
|
+
// and we're done processing it.
|
|
315
|
+
this._executionRunningSet.delete(key);
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
_removeTaskDetails(key, taskDetails) {
|
|
319
|
+
const taskQueue = this._keyMap.get(key);
|
|
320
|
+
if (!taskQueue || !taskQueue.length) {
|
|
321
|
+
// The task is already gone from the queue, so our work here is done!
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const index = taskQueue.indexOf(taskDetails);
|
|
325
|
+
if (index !== -1) {
|
|
326
|
+
const [details] = taskQueue.splice(index, 1);
|
|
327
|
+
// Cleanup the task rejection code paths.
|
|
328
|
+
cleanupTaskDetails(details);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* @internal
|
|
334
|
+
* Returns a promise and the promise's resolve and reject methods.
|
|
335
|
+
*/
|
|
336
|
+
function getPromiseParts() {
|
|
337
|
+
let resolver;
|
|
338
|
+
let rejecter;
|
|
339
|
+
const promise = new Promise((resolve, reject) => {
|
|
340
|
+
resolver = resolve;
|
|
341
|
+
rejecter = reject;
|
|
342
|
+
});
|
|
343
|
+
return {
|
|
344
|
+
promise,
|
|
345
|
+
resolver: resolver,
|
|
346
|
+
rejecter: rejecter
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* @internal
|
|
351
|
+
* Removes any abort listener or pending timeout from a task.
|
|
352
|
+
*/
|
|
353
|
+
function cleanupTaskDetails(taskDetails) {
|
|
354
|
+
// Cleanup the task rejection code paths.
|
|
355
|
+
if (taskDetails.tid)
|
|
356
|
+
clearTimeout(taskDetails.tid);
|
|
357
|
+
if (taskDetails.abortSignal && taskDetails.abortListener) {
|
|
358
|
+
taskDetails.abortSignal.removeEventListener("abort", taskDetails.abortListener);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
176
361
|
|
|
177
362
|
// Copyright (c) Microsoft Corporation.
|
|
178
363
|
/**
|
|
@@ -218,9 +403,9 @@ function parseConnectionString(connectionString) {
|
|
|
218
403
|
return output;
|
|
219
404
|
}
|
|
220
405
|
/**
|
|
221
|
-
* The async lock instance
|
|
406
|
+
* The cancellable async lock instance.
|
|
222
407
|
*/
|
|
223
|
-
const
|
|
408
|
+
const defaultCancellableLock = new CancellableAsyncLockImpl();
|
|
224
409
|
/**
|
|
225
410
|
* A wrapper for setTimeout that resolves a promise after t milliseconds.
|
|
226
411
|
* @param delayInMs - The number of milliseconds to be delayed.
|
|
@@ -234,7 +419,7 @@ function delay(delayInMs, abortSignal, abortErrorMsg, value) {
|
|
|
234
419
|
let timer = undefined;
|
|
235
420
|
let onAborted = undefined;
|
|
236
421
|
const rejectOnAbort = () => {
|
|
237
|
-
return reject(new abortController.AbortError(abortErrorMsg ? abortErrorMsg :
|
|
422
|
+
return reject(new abortController.AbortError(abortErrorMsg ? abortErrorMsg : StandardAbortMessage));
|
|
238
423
|
};
|
|
239
424
|
const removeListeners = () => {
|
|
240
425
|
if (abortSignal && onAborted) {
|
|
@@ -274,6 +459,11 @@ function isNumber(n) {
|
|
|
274
459
|
}
|
|
275
460
|
|
|
276
461
|
// Copyright (c) Microsoft Corporation.
|
|
462
|
+
/**
|
|
463
|
+
* The standard error message accompanying an AbortError.
|
|
464
|
+
* @hidden
|
|
465
|
+
*/
|
|
466
|
+
const StandardAbortMessage = "The operation was aborted.";
|
|
277
467
|
/**
|
|
278
468
|
* Maps the conditions to the numeric AMQP Response status codes.
|
|
279
469
|
* @internal
|
|
@@ -757,6 +947,9 @@ const retryableErrors = [
|
|
|
757
947
|
"ServerBusyError",
|
|
758
948
|
"ServiceUnavailableError",
|
|
759
949
|
"OperationCancelledError",
|
|
950
|
+
// The service may throw UnauthorizedError if credentials have been rotated.
|
|
951
|
+
// Attempt to retry in case the user has also rotated their credentials.
|
|
952
|
+
"UnauthorizedError",
|
|
760
953
|
// OperationTimeoutError occurs when the service fails to respond within a given timeframe.
|
|
761
954
|
// Since reasons for such failures can be transient, this is treated as a retryable error.
|
|
762
955
|
"OperationTimeoutError",
|
|
@@ -912,23 +1105,6 @@ function isAmqpError(error) {
|
|
|
912
1105
|
return rheaPromise.isAmqpError(error);
|
|
913
1106
|
}
|
|
914
1107
|
|
|
915
|
-
// Copyright (c) Microsoft Corporation.
|
|
916
|
-
/**
|
|
917
|
-
* The \@azure/logger configuration for this package.
|
|
918
|
-
* This will output logs using the `azure:event-hubs` namespace prefix.
|
|
919
|
-
*/
|
|
920
|
-
const logger = logger$1.createClientLogger("core-amqp");
|
|
921
|
-
/**
|
|
922
|
-
* Logs the error's stack trace to "verbose" if a stack trace is available.
|
|
923
|
-
* @param error - Error containing a stack trace.
|
|
924
|
-
* @internal
|
|
925
|
-
*/
|
|
926
|
-
function logErrorStackTrace(error) {
|
|
927
|
-
if (isObjectWithProperties(error, ["stack"])) {
|
|
928
|
-
logger.verbose(error.stack);
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
|
-
|
|
932
1108
|
// Copyright (c) Microsoft Corporation.
|
|
933
1109
|
/**
|
|
934
1110
|
* Describes an amqp request(sender)-response(receiver) link that is created over an amqp session.
|
|
@@ -996,7 +1172,7 @@ class RequestResponseLink {
|
|
|
996
1172
|
`to "${address}" has been cancelled by the user.`;
|
|
997
1173
|
// Cancellation is a user-intended action, so log to info instead of warning.
|
|
998
1174
|
logger.info(desc);
|
|
999
|
-
const error = new abortController.AbortError(
|
|
1175
|
+
const error = new abortController.AbortError(StandardAbortMessage);
|
|
1000
1176
|
reject(error);
|
|
1001
1177
|
};
|
|
1002
1178
|
const onAbort = () => {
|
|
@@ -1206,6 +1382,7 @@ function isDelivery(obj) {
|
|
|
1206
1382
|
RetryOperationType["sendMessage"] = "sendMessage";
|
|
1207
1383
|
RetryOperationType["receiveMessage"] = "receiveMessage";
|
|
1208
1384
|
RetryOperationType["session"] = "session";
|
|
1385
|
+
RetryOperationType["messageSettlement"] = "settlement";
|
|
1209
1386
|
})(exports.RetryOperationType || (exports.RetryOperationType = {}));
|
|
1210
1387
|
/**
|
|
1211
1388
|
* Validates the retry config.
|
|
@@ -1439,20 +1616,19 @@ class CbsClient {
|
|
|
1439
1616
|
*/
|
|
1440
1617
|
init(options = {}) {
|
|
1441
1618
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1442
|
-
const { abortSignal } = options;
|
|
1443
|
-
const initAbortMessage = "The init operation has been cancelled by the user.";
|
|
1619
|
+
const { abortSignal, timeoutInMs } = options;
|
|
1444
1620
|
try {
|
|
1445
1621
|
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
|
|
1446
|
-
throw new abortController.AbortError(
|
|
1622
|
+
throw new abortController.AbortError(StandardAbortMessage);
|
|
1447
1623
|
}
|
|
1448
1624
|
// Acquire the lock and establish an amqp connection if it does not exist.
|
|
1449
1625
|
if (!this.connection.isOpen()) {
|
|
1450
1626
|
logger.verbose("The CBS client is trying to establish an AMQP connection.");
|
|
1451
|
-
yield
|
|
1627
|
+
yield defaultCancellableLock.acquire(this.connectionLock, () => {
|
|
1452
1628
|
return this.connection.open({ abortSignal });
|
|
1453
|
-
});
|
|
1629
|
+
}, { abortSignal: abortSignal, timeoutInMs: timeoutInMs });
|
|
1454
1630
|
}
|
|
1455
|
-
if (!this.
|
|
1631
|
+
if (!this.isOpen()) {
|
|
1456
1632
|
const rxOpt = {
|
|
1457
1633
|
source: {
|
|
1458
1634
|
address: this.endpoint
|
|
@@ -1530,10 +1706,10 @@ class CbsClient {
|
|
|
1530
1706
|
*/
|
|
1531
1707
|
negotiateClaim(audience, token, tokenType, options = {}) {
|
|
1532
1708
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1533
|
-
const { abortSignal } = options;
|
|
1709
|
+
const { abortSignal, timeoutInMs } = options;
|
|
1534
1710
|
try {
|
|
1535
1711
|
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
|
|
1536
|
-
throw new abortController.AbortError(
|
|
1712
|
+
throw new abortController.AbortError(StandardAbortMessage);
|
|
1537
1713
|
}
|
|
1538
1714
|
if (!this._cbsSenderReceiverLink) {
|
|
1539
1715
|
throw new Error("Attempted to negotiate a claim but the CBS link does not exist.");
|
|
@@ -1551,6 +1727,7 @@ class CbsClient {
|
|
|
1551
1727
|
};
|
|
1552
1728
|
const responseMessage = yield this._cbsSenderReceiverLink.sendRequest(request, {
|
|
1553
1729
|
abortSignal,
|
|
1730
|
+
timeoutInMs,
|
|
1554
1731
|
requestName: "negotiateClaim"
|
|
1555
1732
|
});
|
|
1556
1733
|
logger.verbose("[%s] The CBS response is: %O", this.connection.id, responseMessage);
|
|
@@ -1571,7 +1748,7 @@ class CbsClient {
|
|
|
1571
1748
|
close() {
|
|
1572
1749
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1573
1750
|
try {
|
|
1574
|
-
if (this.
|
|
1751
|
+
if (this.isOpen()) {
|
|
1575
1752
|
const cbsLink = this._cbsSenderReceiverLink;
|
|
1576
1753
|
this._cbsSenderReceiverLink = undefined;
|
|
1577
1754
|
yield cbsLink.close();
|
|
@@ -1610,8 +1787,9 @@ class CbsClient {
|
|
|
1610
1787
|
* Indicates whether the cbs sender receiver link is open or closed.
|
|
1611
1788
|
* @returns `true` open, `false` closed.
|
|
1612
1789
|
*/
|
|
1613
|
-
|
|
1614
|
-
|
|
1790
|
+
isOpen() {
|
|
1791
|
+
var _a;
|
|
1792
|
+
return Boolean((_a = this._cbsSenderReceiverLink) === null || _a === void 0 ? void 0 : _a.isOpen());
|
|
1615
1793
|
}
|
|
1616
1794
|
_fromRheaMessageResponse(msg) {
|
|
1617
1795
|
const cbsResponse = {
|
|
@@ -1699,7 +1877,7 @@ const AmqpMessageProperties = {
|
|
|
1699
1877
|
toRheaMessageProperties(props) {
|
|
1700
1878
|
const amqpProperties = {};
|
|
1701
1879
|
if (props.absoluteExpiryTime != undefined) {
|
|
1702
|
-
amqpProperties.absolute_expiry_time = props.absoluteExpiryTime;
|
|
1880
|
+
amqpProperties.absolute_expiry_time = new Date(props.absoluteExpiryTime);
|
|
1703
1881
|
}
|
|
1704
1882
|
if (props.contentEncoding != undefined) {
|
|
1705
1883
|
amqpProperties.content_encoding = props.contentEncoding;
|
|
@@ -1711,7 +1889,7 @@ const AmqpMessageProperties = {
|
|
|
1711
1889
|
amqpProperties.correlation_id = props.correlationId;
|
|
1712
1890
|
}
|
|
1713
1891
|
if (props.creationTime != undefined) {
|
|
1714
|
-
amqpProperties.creation_time = props.creationTime;
|
|
1892
|
+
amqpProperties.creation_time = new Date(props.creationTime);
|
|
1715
1893
|
}
|
|
1716
1894
|
if (props.groupId != undefined) {
|
|
1717
1895
|
amqpProperties.group_id = props.groupId;
|
|
@@ -1748,7 +1926,7 @@ const AmqpMessageProperties = {
|
|
|
1748
1926
|
fromRheaMessageProperties(props) {
|
|
1749
1927
|
const msgProperties = {};
|
|
1750
1928
|
if (props.absolute_expiry_time != undefined) {
|
|
1751
|
-
msgProperties.absoluteExpiryTime = props.absolute_expiry_time;
|
|
1929
|
+
msgProperties.absoluteExpiryTime = props.absolute_expiry_time.getTime();
|
|
1752
1930
|
}
|
|
1753
1931
|
if (props.content_encoding != undefined) {
|
|
1754
1932
|
msgProperties.contentEncoding = props.content_encoding;
|
|
@@ -1760,7 +1938,7 @@ const AmqpMessageProperties = {
|
|
|
1760
1938
|
msgProperties.correlationId = props.correlation_id;
|
|
1761
1939
|
}
|
|
1762
1940
|
if (props.creation_time != undefined) {
|
|
1763
|
-
msgProperties.creationTime = props.creation_time;
|
|
1941
|
+
msgProperties.creationTime = props.creation_time.getTime();
|
|
1764
1942
|
}
|
|
1765
1943
|
if (props.group_id != undefined) {
|
|
1766
1944
|
msgProperties.groupId = props.group_id;
|
|
@@ -1902,10 +2080,91 @@ const AmqpAnnotatedMessage = {
|
|
|
1902
2080
|
properties: AmqpMessageProperties.fromRheaMessageProperties(msg),
|
|
1903
2081
|
body: msg.body
|
|
1904
2082
|
};
|
|
2083
|
+
},
|
|
2084
|
+
/**
|
|
2085
|
+
* Takes AmqpAnnotatedMessage and returns it in the RheaMessage(`Message` type from "rhea") format.
|
|
2086
|
+
*/
|
|
2087
|
+
toRheaMessage(msg) {
|
|
2088
|
+
const message = Object.assign(Object.assign(Object.assign({}, AmqpMessageProperties.toRheaMessageProperties(msg.properties || {})), AmqpMessageHeader.toRheaMessageHeader(msg.header || {})), { body: msg.body, message_annotations: msg.messageAnnotations, delivery_annotations: msg.deliveryAnnotations, application_properties: msg.applicationProperties, footer: msg.footer });
|
|
2089
|
+
return message;
|
|
1905
2090
|
}
|
|
1906
2091
|
};
|
|
1907
2092
|
|
|
1908
|
-
|
|
2093
|
+
// Copyright (c) Microsoft Corporation.
|
|
2094
|
+
/**
|
|
2095
|
+
* Creates a token provider from the provided shared access data.
|
|
2096
|
+
* @param data - The sharedAccessKeyName/sharedAccessKey pair or the sharedAccessSignature.
|
|
2097
|
+
* @hidden
|
|
2098
|
+
*/
|
|
2099
|
+
function createSasTokenProvider(data) {
|
|
2100
|
+
if (coreAuth.isNamedKeyCredential(data) || coreAuth.isSASCredential(data)) {
|
|
2101
|
+
return new SasTokenProviderImpl(data);
|
|
2102
|
+
}
|
|
2103
|
+
else if (isObjectWithProperties(data, ["sharedAccessKeyName", "sharedAccessKey"])) {
|
|
2104
|
+
return new SasTokenProviderImpl({ name: data.sharedAccessKeyName, key: data.sharedAccessKey });
|
|
2105
|
+
}
|
|
2106
|
+
else {
|
|
2107
|
+
return new SasTokenProviderImpl({ signature: data.sharedAccessSignature });
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
/**
|
|
2111
|
+
* A TokenProvider that generates a Sas token:
|
|
2112
|
+
* `SharedAccessSignature sr=<resource>&sig=<signature>&se=<expiry>&skn=<keyname>`
|
|
2113
|
+
*
|
|
2114
|
+
* @internal
|
|
2115
|
+
*/
|
|
2116
|
+
class SasTokenProviderImpl {
|
|
2117
|
+
/**
|
|
2118
|
+
* Initializes a new instance of SasTokenProvider
|
|
2119
|
+
* @param credential - The source `NamedKeyCredential` or `SASCredential`.
|
|
2120
|
+
*/
|
|
2121
|
+
constructor(credential) {
|
|
2122
|
+
this._credential = credential;
|
|
2123
|
+
}
|
|
2124
|
+
/**
|
|
2125
|
+
* Property used to distinguish TokenProvider from TokenCredential.
|
|
2126
|
+
*/
|
|
2127
|
+
get isSasTokenProvider() {
|
|
2128
|
+
return true;
|
|
2129
|
+
}
|
|
2130
|
+
/**
|
|
2131
|
+
* Gets the sas token for the specified audience
|
|
2132
|
+
* @param audience - The audience for which the token is desired.
|
|
2133
|
+
*/
|
|
2134
|
+
getToken(audience) {
|
|
2135
|
+
if (coreAuth.isNamedKeyCredential(this._credential)) {
|
|
2136
|
+
return createToken(this._credential.name, this._credential.key, Math.floor(Date.now() / 1000) + 3600, audience);
|
|
2137
|
+
}
|
|
2138
|
+
else {
|
|
2139
|
+
return {
|
|
2140
|
+
token: this._credential.signature,
|
|
2141
|
+
expiresOnTimestamp: 0
|
|
2142
|
+
};
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
/**
|
|
2147
|
+
* Creates the sas token based on the provided information.
|
|
2148
|
+
* @param keyName - The shared access key name.
|
|
2149
|
+
* @param key - The shared access key.
|
|
2150
|
+
* @param expiry - The time period in unix time after which the token will expire.
|
|
2151
|
+
* @param audience - The audience for which the token is desired.
|
|
2152
|
+
* @internal
|
|
2153
|
+
*/
|
|
2154
|
+
function createToken(keyName, key, expiry, audience) {
|
|
2155
|
+
audience = encodeURIComponent(audience);
|
|
2156
|
+
keyName = encodeURIComponent(keyName);
|
|
2157
|
+
const stringToSign = audience + "\n" + expiry;
|
|
2158
|
+
const shaObj = new jssha("SHA-256", "TEXT");
|
|
2159
|
+
shaObj.setHMACKey(key, "TEXT");
|
|
2160
|
+
shaObj.update(stringToSign);
|
|
2161
|
+
const sig = encodeURIComponent(shaObj.getHMAC("B64"));
|
|
2162
|
+
return {
|
|
2163
|
+
token: `SharedAccessSignature sr=${audience}&sig=${sig}&se=${expiry}&skn=${keyName}`,
|
|
2164
|
+
expiresOnTimestamp: expiry
|
|
2165
|
+
};
|
|
2166
|
+
}
|
|
2167
|
+
|
|
1909
2168
|
exports.AmqpAnnotatedMessage = AmqpAnnotatedMessage;
|
|
1910
2169
|
exports.AmqpMessageHeader = AmqpMessageHeader;
|
|
1911
2170
|
exports.AmqpMessageProperties = AmqpMessageProperties;
|
|
@@ -1915,9 +2174,12 @@ exports.ConnectionContextBase = ConnectionContextBase;
|
|
|
1915
2174
|
exports.Constants = Constants;
|
|
1916
2175
|
exports.MessagingError = MessagingError;
|
|
1917
2176
|
exports.RequestResponseLink = RequestResponseLink;
|
|
1918
|
-
exports.
|
|
2177
|
+
exports.StandardAbortMessage = StandardAbortMessage;
|
|
2178
|
+
exports.createSasTokenProvider = createSasTokenProvider;
|
|
2179
|
+
exports.defaultCancellableLock = defaultCancellableLock;
|
|
1919
2180
|
exports.delay = delay;
|
|
1920
2181
|
exports.isMessagingError = isMessagingError;
|
|
2182
|
+
exports.isSasTokenProvider = isSasTokenProvider;
|
|
1921
2183
|
exports.isSystemError = isSystemError;
|
|
1922
2184
|
exports.logger = logger;
|
|
1923
2185
|
exports.parseConnectionString = parseConnectionString;
|