@azure/storage-file-datalake 12.15.0 → 12.16.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/dist/index.js CHANGED
@@ -123,8 +123,8 @@ class AnonymousCredential extends Credential {
123
123
 
124
124
  // Copyright (c) Microsoft Corporation.
125
125
  // Licensed under the MIT license.
126
- const SDK_VERSION = "12.15.0";
127
- const SERVICE_VERSION = "2023-08-03";
126
+ const SDK_VERSION = "12.16.0";
127
+ const SERVICE_VERSION = "2023-11-03";
128
128
  const KB = 1024;
129
129
  const MB = KB * 1024;
130
130
  const DEFAULT_HIGH_LEVEL_CONCURRENCY = 5;
@@ -4002,7 +4002,7 @@ const timeout = {
4002
4002
  const version = {
4003
4003
  parameterPath: "version",
4004
4004
  mapper: {
4005
- defaultValue: "2023-08-03",
4005
+ defaultValue: "2023-11-03",
4006
4006
  isConstant: true,
4007
4007
  serializedName: "x-ms-version",
4008
4008
  type: {
@@ -6099,6 +6099,247 @@ function getCachedDefaultHttpClient() {
6099
6099
  return _defaultHttpClient;
6100
6100
  }
6101
6101
 
6102
+ // Copyright (c) Microsoft Corporation.
6103
+ /**
6104
+ * A set of constants used internally when processing requests.
6105
+ */
6106
+ const Constants = {
6107
+ DefaultScope: "/.default",
6108
+ /**
6109
+ * Defines constants for use with HTTP headers.
6110
+ */
6111
+ HeaderConstants: {
6112
+ /**
6113
+ * The Authorization header.
6114
+ */
6115
+ AUTHORIZATION: "authorization",
6116
+ },
6117
+ };
6118
+ // Default options for the cycler if none are provided
6119
+ const DEFAULT_CYCLER_OPTIONS = {
6120
+ forcedRefreshWindowInMs: 1000,
6121
+ retryIntervalInMs: 3000,
6122
+ refreshWindowInMs: 1000 * 60 * 2, // Start refreshing 2m before expiry
6123
+ };
6124
+ /**
6125
+ * Converts an an unreliable access token getter (which may resolve with null)
6126
+ * into an AccessTokenGetter by retrying the unreliable getter in a regular
6127
+ * interval.
6128
+ *
6129
+ * @param getAccessToken - a function that produces a promise of an access
6130
+ * token that may fail by returning null
6131
+ * @param retryIntervalInMs - the time (in milliseconds) to wait between retry
6132
+ * attempts
6133
+ * @param timeoutInMs - the timestamp after which the refresh attempt will fail,
6134
+ * throwing an exception
6135
+ * @returns - a promise that, if it resolves, will resolve with an access token
6136
+ */
6137
+ async function beginRefresh(getAccessToken, retryIntervalInMs, timeoutInMs) {
6138
+ // This wrapper handles exceptions gracefully as long as we haven't exceeded
6139
+ // the timeout.
6140
+ async function tryGetAccessToken() {
6141
+ if (Date.now() < timeoutInMs) {
6142
+ try {
6143
+ return await getAccessToken();
6144
+ }
6145
+ catch (_a) {
6146
+ return null;
6147
+ }
6148
+ }
6149
+ else {
6150
+ const finalToken = await getAccessToken();
6151
+ // Timeout is up, so throw if it's still null
6152
+ if (finalToken === null) {
6153
+ throw new Error("Failed to refresh access token.");
6154
+ }
6155
+ return finalToken;
6156
+ }
6157
+ }
6158
+ let token = await tryGetAccessToken();
6159
+ while (token === null) {
6160
+ await coreHttp.delay(retryIntervalInMs);
6161
+ token = await tryGetAccessToken();
6162
+ }
6163
+ return token;
6164
+ }
6165
+ /**
6166
+ * Creates a token cycler from a credential, scopes, and optional settings.
6167
+ *
6168
+ * A token cycler represents a way to reliably retrieve a valid access token
6169
+ * from a TokenCredential. It will handle initializing the token, refreshing it
6170
+ * when it nears expiration, and synchronizes refresh attempts to avoid
6171
+ * concurrency hazards.
6172
+ *
6173
+ * @param credential - the underlying TokenCredential that provides the access
6174
+ * token
6175
+ * @param scopes - the scopes to request authorization for
6176
+ * @param tokenCyclerOptions - optionally override default settings for the cycler
6177
+ *
6178
+ * @returns - a function that reliably produces a valid access token
6179
+ */
6180
+ function createTokenCycler(credential, scopes, tokenCyclerOptions) {
6181
+ let refreshWorker = null;
6182
+ let token = null;
6183
+ const options = Object.assign(Object.assign({}, DEFAULT_CYCLER_OPTIONS), tokenCyclerOptions);
6184
+ /**
6185
+ * This little holder defines several predicates that we use to construct
6186
+ * the rules of refreshing the token.
6187
+ */
6188
+ const cycler = {
6189
+ /**
6190
+ * Produces true if a refresh job is currently in progress.
6191
+ */
6192
+ get isRefreshing() {
6193
+ return refreshWorker !== null;
6194
+ },
6195
+ /**
6196
+ * Produces true if the cycler SHOULD refresh (we are within the refresh
6197
+ * window and not already refreshing)
6198
+ */
6199
+ get shouldRefresh() {
6200
+ var _a;
6201
+ return (!cycler.isRefreshing &&
6202
+ ((_a = token === null || token === void 0 ? void 0 : token.expiresOnTimestamp) !== null && _a !== void 0 ? _a : 0) - options.refreshWindowInMs < Date.now());
6203
+ },
6204
+ /**
6205
+ * Produces true if the cycler MUST refresh (null or nearly-expired
6206
+ * token).
6207
+ */
6208
+ get mustRefresh() {
6209
+ return (token === null || token.expiresOnTimestamp - options.forcedRefreshWindowInMs < Date.now());
6210
+ },
6211
+ };
6212
+ /**
6213
+ * Starts a refresh job or returns the existing job if one is already
6214
+ * running.
6215
+ */
6216
+ function refresh(getTokenOptions) {
6217
+ var _a;
6218
+ if (!cycler.isRefreshing) {
6219
+ // We bind `scopes` here to avoid passing it around a lot
6220
+ const tryGetAccessToken = () => credential.getToken(scopes, getTokenOptions);
6221
+ // Take advantage of promise chaining to insert an assignment to `token`
6222
+ // before the refresh can be considered done.
6223
+ refreshWorker = beginRefresh(tryGetAccessToken, options.retryIntervalInMs,
6224
+ // If we don't have a token, then we should timeout immediately
6225
+ (_a = token === null || token === void 0 ? void 0 : token.expiresOnTimestamp) !== null && _a !== void 0 ? _a : Date.now())
6226
+ .then((_token) => {
6227
+ refreshWorker = null;
6228
+ token = _token;
6229
+ return token;
6230
+ })
6231
+ .catch((reason) => {
6232
+ // We also should reset the refresher if we enter a failed state. All
6233
+ // existing awaiters will throw, but subsequent requests will start a
6234
+ // new retry chain.
6235
+ refreshWorker = null;
6236
+ token = null;
6237
+ throw reason;
6238
+ });
6239
+ }
6240
+ return refreshWorker;
6241
+ }
6242
+ return async (tokenOptions) => {
6243
+ //
6244
+ // Simple rules:
6245
+ // - If we MUST refresh, then return the refresh task, blocking
6246
+ // the pipeline until a token is available.
6247
+ // - If we SHOULD refresh, then run refresh but don't return it
6248
+ // (we can still use the cached token).
6249
+ // - Return the token, since it's fine if we didn't return in
6250
+ // step 1.
6251
+ //
6252
+ if (cycler.mustRefresh)
6253
+ return refresh(tokenOptions);
6254
+ if (cycler.shouldRefresh) {
6255
+ refresh(tokenOptions);
6256
+ }
6257
+ return token;
6258
+ };
6259
+ }
6260
+ /**
6261
+ * We will retrieve the challenge only if the response status code was 401,
6262
+ * and if the response contained the header "WWW-Authenticate" with a non-empty value.
6263
+ */
6264
+ function getChallenge(response) {
6265
+ const challenge = response.headers.get("WWW-Authenticate");
6266
+ if (response.status === 401 && challenge) {
6267
+ return challenge;
6268
+ }
6269
+ return;
6270
+ }
6271
+ /**
6272
+ * Converts: `Bearer a="b" c="d"`.
6273
+ * Into: `[ { a: 'b', c: 'd' }]`.
6274
+ *
6275
+ * @internal
6276
+ */
6277
+ function parseChallenge(challenge) {
6278
+ const bearerChallenge = challenge.slice("Bearer ".length);
6279
+ const challengeParts = `${bearerChallenge.trim()} `.split(" ").filter((x) => x);
6280
+ const keyValuePairs = challengeParts.map((keyValue) => (([key, value]) => ({ [key]: value }))(keyValue.trim().split("=")));
6281
+ // Key-value pairs to plain object:
6282
+ return keyValuePairs.reduce((a, b) => (Object.assign(Object.assign({}, a), b)), {});
6283
+ }
6284
+ // #endregion
6285
+ /**
6286
+ * Creates a new factory for a RequestPolicy that applies a bearer token to
6287
+ * the requests' `Authorization` headers.
6288
+ *
6289
+ * @param credential - The TokenCredential implementation that can supply the bearer token.
6290
+ * @param scopes - The scopes for which the bearer token applies.
6291
+ */
6292
+ function storageBearerTokenChallengeAuthenticationPolicy(credential, scopes) {
6293
+ // This simple function encapsulates the entire process of reliably retrieving the token
6294
+ let getToken = createTokenCycler(credential, scopes);
6295
+ class StorageBearerTokenChallengeAuthenticationPolicy extends coreHttp.BaseRequestPolicy {
6296
+ constructor(nextPolicy, options) {
6297
+ super(nextPolicy, options);
6298
+ }
6299
+ async sendRequest(webResource) {
6300
+ if (!webResource.url.toLowerCase().startsWith("https://")) {
6301
+ throw new Error("Bearer token authentication is not permitted for non-TLS protected (non-https) URLs.");
6302
+ }
6303
+ const getTokenInternal = getToken;
6304
+ const token = (await getTokenInternal({
6305
+ abortSignal: webResource.abortSignal,
6306
+ tracingOptions: {
6307
+ tracingContext: webResource.tracingContext,
6308
+ },
6309
+ })).token;
6310
+ webResource.headers.set(Constants.HeaderConstants.AUTHORIZATION, `Bearer ${token}`);
6311
+ const response = await this._nextPolicy.sendRequest(webResource);
6312
+ if ((response === null || response === void 0 ? void 0 : response.status) === 401) {
6313
+ const challenge = getChallenge(response);
6314
+ if (challenge) {
6315
+ const challengeInfo = parseChallenge(challenge);
6316
+ const challengeScopes = challengeInfo.resource_id + Constants.DefaultScope;
6317
+ const parsedAuthUri = coreHttp.URLBuilder.parse(challengeInfo.authorization_uri);
6318
+ const pathSegments = parsedAuthUri.getPath().split("/");
6319
+ const tenantId = pathSegments[1];
6320
+ const getTokenForChallenge = createTokenCycler(credential, challengeScopes);
6321
+ const tokenForChallenge = (await getTokenForChallenge({
6322
+ abortSignal: webResource.abortSignal,
6323
+ tracingOptions: {
6324
+ tracingContext: webResource.tracingContext,
6325
+ },
6326
+ tenantId: tenantId,
6327
+ })).token;
6328
+ getToken = getTokenForChallenge;
6329
+ webResource.headers.set(Constants.HeaderConstants.AUTHORIZATION, `Bearer ${tokenForChallenge}`);
6330
+ return this._nextPolicy.sendRequest(webResource);
6331
+ }
6332
+ }
6333
+ return response;
6334
+ }
6335
+ }
6336
+ return {
6337
+ create: (nextPolicy, options) => {
6338
+ return new StorageBearerTokenChallengeAuthenticationPolicy(nextPolicy, options);
6339
+ },
6340
+ };
6341
+ }
6342
+
6102
6343
  // Copyright (c) Microsoft Corporation.
6103
6344
  /**
6104
6345
  * A Pipeline class containing HTTP request policies.
@@ -6142,6 +6383,7 @@ class Pipeline {
6142
6383
  * @returns A new Pipeline object.
6143
6384
  */
6144
6385
  function newPipeline(credential, pipelineOptions = {}) {
6386
+ var _a;
6145
6387
  if (credential === undefined) {
6146
6388
  credential = new AnonymousCredential();
6147
6389
  }
@@ -6169,7 +6411,7 @@ function newPipeline(credential, pipelineOptions = {}) {
6169
6411
  factories.push(coreHttp.disableResponseDecompressionPolicy());
6170
6412
  }
6171
6413
  factories.push(coreHttp.isTokenCredential(credential)
6172
- ? attachCredential(coreHttp.bearerTokenAuthenticationPolicy(credential, StorageOAuthScopes), credential)
6414
+ ? attachCredential(storageBearerTokenChallengeAuthenticationPolicy(credential, (_a = pipelineOptions.audience) !== null && _a !== void 0 ? _a : StorageOAuthScopes), credential)
6173
6415
  : credential);
6174
6416
  return new Pipeline(factories, pipelineOptions);
6175
6417
  }
@@ -6192,7 +6434,7 @@ function attachCredential(thing, credential) {
6192
6434
  * Changes may cause incorrect behavior and will be lost if the code is regenerated.
6193
6435
  */
6194
6436
  const packageName = "azure-storage-datalake";
6195
- const packageVersion = "12.15.0";
6437
+ const packageVersion = "12.16.0";
6196
6438
  class StorageClientContext extends coreHttp__namespace.ServiceClient {
6197
6439
  /**
6198
6440
  * Initializes a new instance of the StorageClientContext class.
@@ -6218,7 +6460,7 @@ class StorageClientContext extends coreHttp__namespace.ServiceClient {
6218
6460
  // Parameter assignments
6219
6461
  this.url = url;
6220
6462
  // Assigning values to Constant parameters
6221
- this.version = options.version || "2023-08-03";
6463
+ this.version = options.version || "2023-11-03";
6222
6464
  this.resource = options.resource || "filesystem";
6223
6465
  }
6224
6466
  }
@@ -10880,6 +11122,19 @@ exports.PathResourceType = void 0;
10880
11122
  PathResourceType["Directory"] = "directory";
10881
11123
  PathResourceType["File"] = "file";
10882
11124
  })(exports.PathResourceType || (exports.PathResourceType = {}));
11125
+ /**
11126
+ * Defines the known cloud audiences for Storage.
11127
+ */
11128
+ exports.StorageDataLakeAudience = void 0;
11129
+ (function (StorageDataLakeAudience) {
11130
+ /**
11131
+ * The OAuth scope to use to retrieve an AAD token for Azure Storage.
11132
+ */
11133
+ StorageDataLakeAudience["StorageOAuthScopes"] = "https://storage.azure.com/.default";
11134
+ })(exports.StorageDataLakeAudience || (exports.StorageDataLakeAudience = {}));
11135
+ function getDataLakeServiceAccountAudience(storageAccountName) {
11136
+ return `https://${storageAccountName}.dfs.core.windows.net/.default`;
11137
+ }
10883
11138
  /** *********************************************************/
10884
11139
  /** DataLakeLeaseClient option and response related models */
10885
11140
  /** *********************************************************/
@@ -10938,6 +11193,7 @@ exports.ToBlobEndpointHostMappings = ToBlobEndpointHostMappings;
10938
11193
  exports.ToDfsEndpointHostMappings = ToDfsEndpointHostMappings;
10939
11194
  exports.generateAccountSASQueryParameters = generateAccountSASQueryParameters;
10940
11195
  exports.generateDataLakeSASQueryParameters = generateDataLakeSASQueryParameters;
11196
+ exports.getDataLakeServiceAccountAudience = getDataLakeServiceAccountAudience;
10941
11197
  exports.logger = logger;
10942
11198
  exports.newPipeline = newPipeline;
10943
11199
  //# sourceMappingURL=index.js.map