@aws-sdk/middleware-sdk-s3 3.714.0 → 3.723.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-cjs/index.js CHANGED
@@ -59,12 +59,11 @@ var import_smithy_client = require("@smithy/smithy-client");
59
59
  var CONTENT_LENGTH_HEADER = "content-length";
60
60
  function checkContentLengthHeader() {
61
61
  return (next, context) => async (args) => {
62
- var _a;
63
62
  const { request } = args;
64
63
  if (import_protocol_http.HttpRequest.isInstance(request)) {
65
64
  if (!(CONTENT_LENGTH_HEADER in request.headers)) {
66
65
  const message = `Are you using a Stream of unknown length as the Body of a PutObject request? Consider using Upload instead from @aws-sdk/lib-storage.`;
67
- if (typeof ((_a = context == null ? void 0 : context.logger) == null ? void 0 : _a.warn) === "function" && !(context.logger instanceof import_smithy_client.NoOpLogger)) {
66
+ if (typeof context?.logger?.warn === "function" && !(context.logger instanceof import_smithy_client.NoOpLogger)) {
68
67
  context.logger.warn(message);
69
68
  } else {
70
69
  console.warn(message);
@@ -133,16 +132,15 @@ var regionRedirectEndpointMiddlewareOptions = {
133
132
  // src/region-redirect-middleware.ts
134
133
  function regionRedirectMiddleware(clientConfig) {
135
134
  return (next, context) => async (args) => {
136
- var _a, _b, _c;
137
135
  try {
138
136
  return await next(args);
139
137
  } catch (err) {
140
138
  if (clientConfig.followRegionRedirects) {
141
- if (((_a = err == null ? void 0 : err.$metadata) == null ? void 0 : _a.httpStatusCode) === 301 || // err.name === "PermanentRedirect" && --> removing the error name check, as that allows for HEAD operations (which have the 301 status code, but not the same error name) to be covered for region redirection as well
142
- ((_b = err == null ? void 0 : err.$metadata) == null ? void 0 : _b.httpStatusCode) === 400 && (err == null ? void 0 : err.name) === "IllegalLocationConstraintException") {
139
+ if (err?.$metadata?.httpStatusCode === 301 || // err.name === "PermanentRedirect" && --> removing the error name check, as that allows for HEAD operations (which have the 301 status code, but not the same error name) to be covered for region redirection as well
140
+ err?.$metadata?.httpStatusCode === 400 && err?.name === "IllegalLocationConstraintException") {
143
141
  try {
144
142
  const actualRegion = err.$response.headers["x-amz-bucket-region"];
145
- (_c = context.logger) == null ? void 0 : _c.debug(`Redirecting from ${await clientConfig.region()} to ${actualRegion}`);
143
+ context.logger?.debug(`Redirecting from ${await clientConfig.region()} to ${actualRegion}`);
146
144
  context.__s3RegionRedirect = actualRegion;
147
145
  } catch (e) {
148
146
  throw new Error("Region redirect failed: " + e);
@@ -173,7 +171,6 @@ var getRegionRedirectMiddlewarePlugin = /* @__PURE__ */ __name((clientConfig) =>
173
171
 
174
172
  var s3ExpiresMiddleware = /* @__PURE__ */ __name((config) => {
175
173
  return (next, context) => async (args) => {
176
- var _a;
177
174
  const result = await next(args);
178
175
  const { response } = result;
179
176
  if (import_protocol_http.HttpResponse.isInstance(response)) {
@@ -182,7 +179,7 @@ var s3ExpiresMiddleware = /* @__PURE__ */ __name((config) => {
182
179
  try {
183
180
  (0, import_smithy_client.parseRfc7231DateTime)(response.headers.expires);
184
181
  } catch (e) {
185
- (_a = context.logger) == null ? void 0 : _a.warn(
182
+ context.logger?.warn(
186
183
  `AWS SDK Warning for ${context.clientName}::${context.commandName} response parsing (${response.headers.expires}): ${e}`
187
184
  );
188
185
  delete response.headers.expires;
@@ -206,11 +203,15 @@ var getS3ExpiresMiddlewarePlugin = /* @__PURE__ */ __name((clientConfig) => ({
206
203
  }), "getS3ExpiresMiddlewarePlugin");
207
204
 
208
205
  // src/s3-express/classes/S3ExpressIdentityCache.ts
209
- var _S3ExpressIdentityCache = class _S3ExpressIdentityCache {
206
+ var S3ExpressIdentityCache = class _S3ExpressIdentityCache {
210
207
  constructor(data = {}) {
211
208
  this.data = data;
212
- this.lastPurgeTime = Date.now();
213
209
  }
210
+ static {
211
+ __name(this, "S3ExpressIdentityCache");
212
+ }
213
+ lastPurgeTime = Date.now();
214
+ static EXPIRED_CREDENTIAL_PURGE_INTERVAL_MS = 3e4;
214
215
  get(key) {
215
216
  const entry = this.data[key];
216
217
  if (!entry) {
@@ -243,12 +244,9 @@ var _S3ExpressIdentityCache = class _S3ExpressIdentityCache {
243
244
  }
244
245
  }
245
246
  };
246
- __name(_S3ExpressIdentityCache, "S3ExpressIdentityCache");
247
- _S3ExpressIdentityCache.EXPIRED_CREDENTIAL_PURGE_INTERVAL_MS = 3e4;
248
- var S3ExpressIdentityCache = _S3ExpressIdentityCache;
249
247
 
250
248
  // src/s3-express/classes/S3ExpressIdentityCacheEntry.ts
251
- var _S3ExpressIdentityCacheEntry = class _S3ExpressIdentityCacheEntry {
249
+ var S3ExpressIdentityCacheEntry = class {
252
250
  /**
253
251
  * @param identity - stored identity.
254
252
  * @param accessed - timestamp of last access in epoch ms.
@@ -259,32 +257,36 @@ var _S3ExpressIdentityCacheEntry = class _S3ExpressIdentityCacheEntry {
259
257
  this.isRefreshing = isRefreshing;
260
258
  this.accessed = accessed;
261
259
  }
260
+ static {
261
+ __name(this, "S3ExpressIdentityCacheEntry");
262
+ }
262
263
  get identity() {
263
264
  this.accessed = Date.now();
264
265
  return this._identity;
265
266
  }
266
267
  };
267
- __name(_S3ExpressIdentityCacheEntry, "S3ExpressIdentityCacheEntry");
268
- var S3ExpressIdentityCacheEntry = _S3ExpressIdentityCacheEntry;
269
268
 
270
269
  // src/s3-express/classes/S3ExpressIdentityProviderImpl.ts
271
- var _S3ExpressIdentityProviderImpl = class _S3ExpressIdentityProviderImpl {
270
+ var S3ExpressIdentityProviderImpl = class _S3ExpressIdentityProviderImpl {
272
271
  constructor(createSessionFn, cache = new S3ExpressIdentityCache()) {
273
272
  this.createSessionFn = createSessionFn;
274
273
  this.cache = cache;
275
274
  }
275
+ static {
276
+ __name(this, "S3ExpressIdentityProviderImpl");
277
+ }
278
+ static REFRESH_WINDOW_MS = 6e4;
276
279
  async getS3ExpressIdentity(awsIdentity, identityProperties) {
277
280
  const key = identityProperties.Bucket;
278
281
  const { cache } = this;
279
282
  const entry = cache.get(key);
280
283
  if (entry) {
281
284
  return entry.identity.then((identity) => {
282
- var _a, _b;
283
- const isExpired = (((_a = identity.expiration) == null ? void 0 : _a.getTime()) ?? 0) < Date.now();
285
+ const isExpired = (identity.expiration?.getTime() ?? 0) < Date.now();
284
286
  if (isExpired) {
285
287
  return cache.set(key, new S3ExpressIdentityCacheEntry(this.getIdentity(key))).identity;
286
288
  }
287
- const isExpiringSoon = (((_b = identity.expiration) == null ? void 0 : _b.getTime()) ?? 0) < Date.now() + _S3ExpressIdentityProviderImpl.REFRESH_WINDOW_MS;
289
+ const isExpiringSoon = (identity.expiration?.getTime() ?? 0) < Date.now() + _S3ExpressIdentityProviderImpl.REFRESH_WINDOW_MS;
288
290
  if (isExpiringSoon && !entry.isRefreshing) {
289
291
  entry.isRefreshing = true;
290
292
  this.getIdentity(key).then((id) => {
@@ -297,12 +299,11 @@ var _S3ExpressIdentityProviderImpl = class _S3ExpressIdentityProviderImpl {
297
299
  return cache.set(key, new S3ExpressIdentityCacheEntry(this.getIdentity(key))).identity;
298
300
  }
299
301
  async getIdentity(key) {
300
- var _a, _b;
301
302
  await this.cache.purgeExpired().catch((error) => {
302
303
  console.warn("Error while clearing expired entries in S3ExpressIdentityCache: \n" + error);
303
304
  });
304
305
  const session = await this.createSessionFn(key);
305
- if (!((_a = session.Credentials) == null ? void 0 : _a.AccessKeyId) || !((_b = session.Credentials) == null ? void 0 : _b.SecretAccessKey)) {
306
+ if (!session.Credentials?.AccessKeyId || !session.Credentials?.SecretAccessKey) {
306
307
  throw new Error("s3#createSession response credential missing AccessKeyId or SecretAccessKey.");
307
308
  }
308
309
  const identity = {
@@ -314,9 +315,6 @@ var _S3ExpressIdentityProviderImpl = class _S3ExpressIdentityProviderImpl {
314
315
  return identity;
315
316
  }
316
317
  };
317
- __name(_S3ExpressIdentityProviderImpl, "S3ExpressIdentityProviderImpl");
318
- _S3ExpressIdentityProviderImpl.REFRESH_WINDOW_MS = 6e4;
319
- var S3ExpressIdentityProviderImpl = _S3ExpressIdentityProviderImpl;
320
318
 
321
319
  // src/s3-express/classes/SignatureV4S3Express.ts
322
320
  var import_signature_v4 = require("@smithy/signature-v4");
@@ -337,7 +335,10 @@ var NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS = {
337
335
  };
338
336
 
339
337
  // src/s3-express/classes/SignatureV4S3Express.ts
340
- var _SignatureV4S3Express = class _SignatureV4S3Express extends import_signature_v4.SignatureV4 {
338
+ var SignatureV4S3Express = class extends import_signature_v4.SignatureV4 {
339
+ static {
340
+ __name(this, "SignatureV4S3Express");
341
+ }
341
342
  /**
342
343
  * Signs with alternate provided credentials instead of those provided in the
343
344
  * constructor.
@@ -366,8 +367,6 @@ var _SignatureV4S3Express = class _SignatureV4S3Express extends import_signature
366
367
  return this.presign(requestToSign, options);
367
368
  }
368
369
  };
369
- __name(_SignatureV4S3Express, "SignatureV4S3Express");
370
- var SignatureV4S3Express = _SignatureV4S3Express;
371
370
  function getCredentialsWithoutSessionToken(credentials) {
372
371
  const credentialsWithoutSessionToken = {
373
372
  accessKeyId: credentials.accessKeyId,
@@ -396,11 +395,10 @@ var import_core = require("@aws-sdk/core");
396
395
 
397
396
  var s3ExpressMiddleware = /* @__PURE__ */ __name((options) => {
398
397
  return (next, context) => async (args) => {
399
- var _a, _b, _c, _d, _e;
400
398
  if (context.endpointV2) {
401
399
  const endpoint = context.endpointV2;
402
- const isS3ExpressAuth = ((_c = (_b = (_a = endpoint.properties) == null ? void 0 : _a.authSchemes) == null ? void 0 : _b[0]) == null ? void 0 : _c.name) === S3_EXPRESS_AUTH_SCHEME;
403
- const isS3ExpressBucket = ((_d = endpoint.properties) == null ? void 0 : _d.backend) === S3_EXPRESS_BACKEND || ((_e = endpoint.properties) == null ? void 0 : _e.bucketType) === S3_EXPRESS_BUCKET_TYPE;
400
+ const isS3ExpressAuth = endpoint.properties?.authSchemes?.[0]?.name === S3_EXPRESS_AUTH_SCHEME;
401
+ const isS3ExpressBucket = endpoint.properties?.backend === S3_EXPRESS_BACKEND || endpoint.properties?.bucketType === S3_EXPRESS_BUCKET_TYPE;
404
402
  if (isS3ExpressBucket) {
405
403
  (0, import_core.setFeature)(context, "S3_EXPRESS_BUCKET", "J");
406
404
  context.isS3ExpressBucket = true;
@@ -540,7 +538,7 @@ var throw200ExceptionsMiddleware = /* @__PURE__ */ __name((config) => (next, con
540
538
  if (statusCode < 200 || statusCode >= 300) {
541
539
  return result;
542
540
  }
543
- const isSplittableStream = typeof (sourceBody == null ? void 0 : sourceBody.stream) === "function" || typeof (sourceBody == null ? void 0 : sourceBody.pipe) === "function" || typeof (sourceBody == null ? void 0 : sourceBody.tee) === "function";
541
+ const isSplittableStream = typeof sourceBody?.stream === "function" || typeof sourceBody?.pipe === "function" || typeof sourceBody?.tee === "function";
544
542
  if (!isSplittableStream) {
545
543
  return result;
546
544
  }
@@ -555,7 +553,7 @@ var throw200ExceptionsMiddleware = /* @__PURE__ */ __name((config) => (next, con
555
553
  return (0, import_util_stream.headStream)(stream, MAX_BYTES_TO_INSPECT);
556
554
  }
557
555
  });
558
- if (typeof (bodyCopy == null ? void 0 : bodyCopy.destroy) === "function") {
556
+ if (typeof bodyCopy?.destroy === "function") {
559
557
  bodyCopy.destroy();
560
558
  }
561
559
  const bodyStringTail = config.utf8Encoder(bodyBytes.subarray(bodyBytes.length - 16));
@@ -594,7 +592,6 @@ var import_util_arn_parser = require("@aws-sdk/util-arn-parser");
594
592
  // src/bucket-endpoint-middleware.ts
595
593
  function bucketEndpointMiddleware(options) {
596
594
  return (next, context) => async (args) => {
597
- var _a, _b, _c, _d;
598
595
  if (options.bucketEndpoint) {
599
596
  const endpoint = context.endpointV2;
600
597
  if (endpoint) {
@@ -608,10 +605,10 @@ function bucketEndpointMiddleware(options) {
608
605
  };
609
606
  } catch (e) {
610
607
  const warning = `@aws-sdk/middleware-sdk-s3: bucketEndpoint=true was set but Bucket=${bucket} could not be parsed as URL.`;
611
- if (((_b = (_a = context.logger) == null ? void 0 : _a.constructor) == null ? void 0 : _b.name) === "NoOpLogger") {
608
+ if (context.logger?.constructor?.name === "NoOpLogger") {
612
609
  console.warn(warning);
613
610
  } else {
614
- (_d = (_c = context.logger) == null ? void 0 : _c.warn) == null ? void 0 : _d.call(_c, warning);
611
+ context.logger?.warn?.(warning);
615
612
  }
616
613
  throw e;
617
614
  }
@@ -1,7 +1,9 @@
1
1
  export class S3ExpressIdentityCache {
2
+ data;
3
+ lastPurgeTime = Date.now();
4
+ static EXPIRED_CREDENTIAL_PURGE_INTERVAL_MS = 30000;
2
5
  constructor(data = {}) {
3
6
  this.data = data;
4
- this.lastPurgeTime = Date.now();
5
7
  }
6
8
  get(key) {
7
9
  const entry = this.data[key];
@@ -35,4 +37,3 @@ export class S3ExpressIdentityCache {
35
37
  }
36
38
  }
37
39
  }
38
- S3ExpressIdentityCache.EXPIRED_CREDENTIAL_PURGE_INTERVAL_MS = 30000;
@@ -1,4 +1,7 @@
1
1
  export class S3ExpressIdentityCacheEntry {
2
+ _identity;
3
+ isRefreshing;
4
+ accessed;
2
5
  constructor(_identity, isRefreshing = false, accessed = Date.now()) {
3
6
  this._identity = _identity;
4
7
  this.isRefreshing = isRefreshing;
@@ -1,6 +1,9 @@
1
1
  import { S3ExpressIdentityCache } from "./S3ExpressIdentityCache";
2
2
  import { S3ExpressIdentityCacheEntry } from "./S3ExpressIdentityCacheEntry";
3
3
  export class S3ExpressIdentityProviderImpl {
4
+ createSessionFn;
5
+ cache;
6
+ static REFRESH_WINDOW_MS = 60000;
4
7
  constructor(createSessionFn, cache = new S3ExpressIdentityCache()) {
5
8
  this.createSessionFn = createSessionFn;
6
9
  this.cache = cache;
@@ -44,4 +47,3 @@ export class S3ExpressIdentityProviderImpl {
44
47
  return identity;
45
48
  }
46
49
  }
47
- S3ExpressIdentityProviderImpl.REFRESH_WINDOW_MS = 60000;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/middleware-sdk-s3",
3
- "version": "3.714.0",
3
+ "version": "3.723.0",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
6
6
  "build:cjs": "node ../../scripts/compilation/inline middleware-sdk-s3",
@@ -27,19 +27,19 @@
27
27
  },
28
28
  "license": "Apache-2.0",
29
29
  "dependencies": {
30
- "@aws-sdk/core": "3.714.0",
31
- "@aws-sdk/types": "3.714.0",
32
- "@aws-sdk/util-arn-parser": "3.693.0",
33
- "@smithy/core": "^2.5.5",
34
- "@smithy/node-config-provider": "^3.1.12",
35
- "@smithy/protocol-http": "^4.1.8",
36
- "@smithy/signature-v4": "^4.2.4",
37
- "@smithy/smithy-client": "^3.5.0",
38
- "@smithy/types": "^3.7.2",
39
- "@smithy/util-config-provider": "^3.0.0",
40
- "@smithy/util-middleware": "^3.0.11",
41
- "@smithy/util-stream": "^3.3.2",
42
- "@smithy/util-utf8": "^3.0.0",
30
+ "@aws-sdk/core": "3.723.0",
31
+ "@aws-sdk/types": "3.723.0",
32
+ "@aws-sdk/util-arn-parser": "3.723.0",
33
+ "@smithy/core": "^3.0.0",
34
+ "@smithy/node-config-provider": "^4.0.0",
35
+ "@smithy/protocol-http": "^5.0.0",
36
+ "@smithy/signature-v4": "^5.0.0",
37
+ "@smithy/smithy-client": "^4.0.0",
38
+ "@smithy/types": "^4.0.0",
39
+ "@smithy/util-config-provider": "^4.0.0",
40
+ "@smithy/util-middleware": "^4.0.0",
41
+ "@smithy/util-stream": "^4.0.0",
42
+ "@smithy/util-utf8": "^4.0.0",
43
43
  "tslib": "^2.6.2"
44
44
  },
45
45
  "devDependencies": {
@@ -47,10 +47,10 @@
47
47
  "concurrently": "7.0.0",
48
48
  "downlevel-dts": "0.10.1",
49
49
  "rimraf": "3.0.2",
50
- "typescript": "~4.9.5"
50
+ "typescript": "~5.2.2"
51
51
  },
52
52
  "engines": {
53
- "node": ">=16.0.0"
53
+ "node": ">=18.0.0"
54
54
  },
55
55
  "typesVersions": {
56
56
  "<4.0": {