@aws-sdk/middleware-sdk-s3 3.622.0 → 3.626.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
@@ -31,6 +31,7 @@ __export(src_exports, {
31
31
  getCheckContentLengthHeaderPlugin: () => getCheckContentLengthHeaderPlugin,
32
32
  getRegionRedirectMiddlewarePlugin: () => getRegionRedirectMiddlewarePlugin,
33
33
  getS3ExpiresMiddlewarePlugin: () => getS3ExpiresMiddlewarePlugin,
34
+ getS3ExpressHttpSigningPlugin: () => getS3ExpressHttpSigningPlugin,
34
35
  getS3ExpressPlugin: () => getS3ExpressPlugin,
35
36
  getThrow200ExceptionsPlugin: () => getThrow200ExceptionsPlugin,
36
37
  getValidateBucketNamePlugin: () => getValidateBucketNamePlugin,
@@ -41,6 +42,8 @@ __export(src_exports, {
41
42
  resolveS3Config: () => resolveS3Config,
42
43
  s3ExpiresMiddleware: () => s3ExpiresMiddleware,
43
44
  s3ExpiresMiddlewareOptions: () => s3ExpiresMiddlewareOptions,
45
+ s3ExpressHttpSigningMiddleware: () => s3ExpressHttpSigningMiddleware,
46
+ s3ExpressHttpSigningMiddlewareOptions: () => s3ExpressHttpSigningMiddlewareOptions,
44
47
  s3ExpressMiddleware: () => s3ExpressMiddleware,
45
48
  s3ExpressMiddlewareOptions: () => s3ExpressMiddlewareOptions,
46
49
  throw200ExceptionsMiddleware: () => throw200ExceptionsMiddleware,
@@ -89,20 +92,34 @@ var regionRedirectEndpointMiddleware = /* @__PURE__ */ __name((config) => {
89
92
  return (next, context) => async (args) => {
90
93
  const originalRegion = await config.region();
91
94
  const regionProviderRef = config.region;
95
+ let unlock = /* @__PURE__ */ __name(() => {
96
+ }, "unlock");
92
97
  if (context.__s3RegionRedirect) {
93
- config.region = async () => {
94
- config.region = regionProviderRef;
95
- return context.__s3RegionRedirect;
96
- };
98
+ Object.defineProperty(config, "region", {
99
+ writable: false,
100
+ value: async () => {
101
+ return context.__s3RegionRedirect;
102
+ }
103
+ });
104
+ unlock = /* @__PURE__ */ __name(() => Object.defineProperty(config, "region", {
105
+ writable: true,
106
+ value: regionProviderRef
107
+ }), "unlock");
97
108
  }
98
- const result = await next(args);
99
- if (context.__s3RegionRedirect) {
100
- const region = await config.region();
101
- if (originalRegion !== region) {
102
- throw new Error("Region was not restored following S3 region redirect.");
109
+ try {
110
+ const result = await next(args);
111
+ if (context.__s3RegionRedirect) {
112
+ unlock();
113
+ const region = await config.region();
114
+ if (originalRegion !== region) {
115
+ throw new Error("Region was not restored following S3 region redirect.");
116
+ }
103
117
  }
118
+ return result;
119
+ } catch (e) {
120
+ unlock();
121
+ throw e;
104
122
  }
105
- return result;
106
123
  };
107
124
  }, "regionRedirectEndpointMiddleware");
108
125
  var regionRedirectEndpointMiddlewareOptions = {
@@ -416,6 +433,68 @@ var getS3ExpressPlugin = /* @__PURE__ */ __name((options) => ({
416
433
  }
417
434
  }), "getS3ExpressPlugin");
418
435
 
436
+ // src/s3-express/functions/s3ExpressHttpSigningMiddleware.ts
437
+ var import_core = require("@smithy/core");
438
+
439
+ var import_util_middleware = require("@smithy/util-middleware");
440
+
441
+ // src/s3-express/functions/signS3Express.ts
442
+ var signS3Express = /* @__PURE__ */ __name(async (s3ExpressIdentity, signingOptions, request, sigV4MultiRegionSigner) => {
443
+ const signedRequest = await sigV4MultiRegionSigner.signWithCredentials(request, s3ExpressIdentity, {});
444
+ if (signedRequest.headers["X-Amz-Security-Token"] || signedRequest.headers["x-amz-security-token"]) {
445
+ throw new Error("X-Amz-Security-Token must not be set for s3-express requests.");
446
+ }
447
+ return signedRequest;
448
+ }, "signS3Express");
449
+
450
+ // src/s3-express/functions/s3ExpressHttpSigningMiddleware.ts
451
+ var defaultErrorHandler = /* @__PURE__ */ __name((signingProperties) => (error) => {
452
+ throw error;
453
+ }, "defaultErrorHandler");
454
+ var defaultSuccessHandler = /* @__PURE__ */ __name((httpResponse, signingProperties) => {
455
+ }, "defaultSuccessHandler");
456
+ var s3ExpressHttpSigningMiddlewareOptions = import_core.httpSigningMiddlewareOptions;
457
+ var s3ExpressHttpSigningMiddleware = /* @__PURE__ */ __name((config) => (next, context) => async (args) => {
458
+ if (!import_protocol_http.HttpRequest.isInstance(args.request)) {
459
+ return next(args);
460
+ }
461
+ const smithyContext = (0, import_util_middleware.getSmithyContext)(context);
462
+ const scheme = smithyContext.selectedHttpAuthScheme;
463
+ if (!scheme) {
464
+ throw new Error(`No HttpAuthScheme was selected: unable to sign request`);
465
+ }
466
+ const {
467
+ httpAuthOption: { signingProperties = {} },
468
+ identity,
469
+ signer
470
+ } = scheme;
471
+ let request;
472
+ if (context.s3ExpressIdentity) {
473
+ request = await signS3Express(
474
+ context.s3ExpressIdentity,
475
+ signingProperties,
476
+ args.request,
477
+ await config.signer()
478
+ );
479
+ } else {
480
+ request = await signer.sign(args.request, identity, signingProperties);
481
+ }
482
+ const output = await next({
483
+ ...args,
484
+ request
485
+ }).catch((signer.errorHandler || defaultErrorHandler)(signingProperties));
486
+ (signer.successHandler || defaultSuccessHandler)(output.response, signingProperties);
487
+ return output;
488
+ }, "s3ExpressHttpSigningMiddleware");
489
+ var getS3ExpressHttpSigningPlugin = /* @__PURE__ */ __name((config) => ({
490
+ applyToStack: (clientStack) => {
491
+ clientStack.addRelativeTo(
492
+ s3ExpressHttpSigningMiddleware(config),
493
+ import_core.httpSigningMiddlewareOptions
494
+ );
495
+ }
496
+ }), "getS3ExpressHttpSigningPlugin");
497
+
419
498
  // src/s3Configuration.ts
420
499
  var resolveS3Config = /* @__PURE__ */ __name((input, {
421
500
  session
@@ -589,6 +668,9 @@ var getValidateBucketNamePlugin = /* @__PURE__ */ __name((options) => ({
589
668
  getS3ExpressPlugin,
590
669
  s3ExpressMiddleware,
591
670
  s3ExpressMiddlewareOptions,
671
+ getS3ExpressHttpSigningPlugin,
672
+ s3ExpressHttpSigningMiddleware,
673
+ s3ExpressHttpSigningMiddlewareOptions,
592
674
  resolveS3Config,
593
675
  throw200ExceptionsMiddleware,
594
676
  throw200ExceptionsMiddlewareOptions,
@@ -2,20 +2,34 @@ export const regionRedirectEndpointMiddleware = (config) => {
2
2
  return (next, context) => async (args) => {
3
3
  const originalRegion = await config.region();
4
4
  const regionProviderRef = config.region;
5
+ let unlock = () => { };
5
6
  if (context.__s3RegionRedirect) {
6
- config.region = async () => {
7
- config.region = regionProviderRef;
8
- return context.__s3RegionRedirect;
9
- };
7
+ Object.defineProperty(config, "region", {
8
+ writable: false,
9
+ value: async () => {
10
+ return context.__s3RegionRedirect;
11
+ },
12
+ });
13
+ unlock = () => Object.defineProperty(config, "region", {
14
+ writable: true,
15
+ value: regionProviderRef,
16
+ });
10
17
  }
11
- const result = await next(args);
12
- if (context.__s3RegionRedirect) {
13
- const region = await config.region();
14
- if (originalRegion !== region) {
15
- throw new Error("Region was not restored following S3 region redirect.");
18
+ try {
19
+ const result = await next(args);
20
+ if (context.__s3RegionRedirect) {
21
+ unlock();
22
+ const region = await config.region();
23
+ if (originalRegion !== region) {
24
+ throw new Error("Region was not restored following S3 region redirect.");
25
+ }
16
26
  }
27
+ return result;
28
+ }
29
+ catch (e) {
30
+ unlock();
31
+ throw e;
17
32
  }
18
- return result;
19
33
  };
20
34
  };
21
35
  export const regionRedirectEndpointMiddlewareOptions = {
@@ -0,0 +1,39 @@
1
+ import { httpSigningMiddlewareOptions } from "@smithy/core";
2
+ import { HttpRequest } from "@smithy/protocol-http";
3
+ import { SMITHY_CONTEXT_KEY, } from "@smithy/types";
4
+ import { getSmithyContext } from "@smithy/util-middleware";
5
+ import { signS3Express } from "./signS3Express";
6
+ const defaultErrorHandler = (signingProperties) => (error) => {
7
+ throw error;
8
+ };
9
+ const defaultSuccessHandler = (httpResponse, signingProperties) => { };
10
+ export const s3ExpressHttpSigningMiddlewareOptions = httpSigningMiddlewareOptions;
11
+ export const s3ExpressHttpSigningMiddleware = (config) => (next, context) => async (args) => {
12
+ if (!HttpRequest.isInstance(args.request)) {
13
+ return next(args);
14
+ }
15
+ const smithyContext = getSmithyContext(context);
16
+ const scheme = smithyContext.selectedHttpAuthScheme;
17
+ if (!scheme) {
18
+ throw new Error(`No HttpAuthScheme was selected: unable to sign request`);
19
+ }
20
+ const { httpAuthOption: { signingProperties = {} }, identity, signer, } = scheme;
21
+ let request;
22
+ if (context.s3ExpressIdentity) {
23
+ request = await signS3Express(context.s3ExpressIdentity, signingProperties, args.request, await config.signer());
24
+ }
25
+ else {
26
+ request = await signer.sign(args.request, identity, signingProperties);
27
+ }
28
+ const output = await next({
29
+ ...args,
30
+ request,
31
+ }).catch((signer.errorHandler || defaultErrorHandler)(signingProperties));
32
+ (signer.successHandler || defaultSuccessHandler)(output.response, signingProperties);
33
+ return output;
34
+ };
35
+ export const getS3ExpressHttpSigningPlugin = (config) => ({
36
+ applyToStack: (clientStack) => {
37
+ clientStack.addRelativeTo(s3ExpressHttpSigningMiddleware(config), httpSigningMiddlewareOptions);
38
+ },
39
+ });
@@ -0,0 +1,7 @@
1
+ export const signS3Express = async (s3ExpressIdentity, signingOptions, request, sigV4MultiRegionSigner) => {
2
+ const signedRequest = await sigV4MultiRegionSigner.signWithCredentials(request, s3ExpressIdentity, {});
3
+ if (signedRequest.headers["X-Amz-Security-Token"] || signedRequest.headers["x-amz-security-token"]) {
4
+ throw new Error("X-Amz-Security-Token must not be set for s3-express requests.");
5
+ }
6
+ return signedRequest;
7
+ };
@@ -4,3 +4,4 @@ export { S3ExpressIdentityProviderImpl } from "./classes/S3ExpressIdentityProvid
4
4
  export { SignatureV4S3Express } from "./classes/SignatureV4S3Express";
5
5
  export { NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS } from "./constants";
6
6
  export { getS3ExpressPlugin, s3ExpressMiddleware, s3ExpressMiddlewareOptions } from "./functions/s3ExpressMiddleware";
7
+ export { getS3ExpressHttpSigningPlugin, s3ExpressHttpSigningMiddleware, s3ExpressHttpSigningMiddlewareOptions, } from "./functions/s3ExpressHttpSigningMiddleware";
@@ -0,0 +1,27 @@
1
+ import { IHttpRequest } from "@smithy/protocol-http";
2
+ import { AuthScheme, AwsCredentialIdentity, FinalizeRequestMiddleware, Pluggable, RequestSigner } from "@smithy/types";
3
+ interface SigningProperties {
4
+ signingRegion: string;
5
+ signingDate: Date;
6
+ signingService: string;
7
+ }
8
+ interface PreviouslyResolved {
9
+ signer: (authScheme?: AuthScheme | undefined) => Promise<RequestSigner & {
10
+ signWithCredentials(req: IHttpRequest, identity: AwsCredentialIdentity, opts?: Partial<SigningProperties>): Promise<IHttpRequest>;
11
+ }>;
12
+ }
13
+ /**
14
+ * @internal
15
+ */
16
+ export declare const s3ExpressHttpSigningMiddlewareOptions: import("@smithy/types").FinalizeRequestHandlerOptions & import("@smithy/types").RelativeLocation & Omit<import("@smithy/types").HandlerOptions, "step">;
17
+ /**
18
+ * @internal
19
+ */
20
+ export declare const s3ExpressHttpSigningMiddleware: <Input extends object, Output extends object>(config: PreviouslyResolved) => FinalizeRequestMiddleware<any, any>;
21
+ /**
22
+ * @internal
23
+ */
24
+ export declare const getS3ExpressHttpSigningPlugin: (config: {
25
+ signer: (authScheme?: AuthScheme | undefined) => Promise<RequestSigner>;
26
+ }) => Pluggable<any, any>;
27
+ export {};
@@ -0,0 +1,13 @@
1
+ import type { AwsCredentialIdentity, HttpRequest as IHttpRequest } from "@smithy/types";
2
+ import { S3ExpressIdentity } from "../interfaces/S3ExpressIdentity";
3
+ export declare const signS3Express: (s3ExpressIdentity: S3ExpressIdentity, signingOptions: {
4
+ signingDate: Date;
5
+ signingRegion: string;
6
+ signingService: string;
7
+ }, request: IHttpRequest, sigV4MultiRegionSigner: {
8
+ signWithCredentials(req: IHttpRequest, identity: AwsCredentialIdentity, opts?: Partial<{
9
+ signingDate: Date;
10
+ signingRegion: string;
11
+ signingService: string;
12
+ }> | undefined): Promise<IHttpRequest>;
13
+ }) => Promise<IHttpRequest>;
@@ -4,5 +4,6 @@ export { S3ExpressIdentityProviderImpl } from "./classes/S3ExpressIdentityProvid
4
4
  export { SignatureV4S3Express } from "./classes/SignatureV4S3Express";
5
5
  export { NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS } from "./constants";
6
6
  export { getS3ExpressPlugin, s3ExpressMiddleware, s3ExpressMiddlewareOptions } from "./functions/s3ExpressMiddleware";
7
+ export { getS3ExpressHttpSigningPlugin, s3ExpressHttpSigningMiddleware, s3ExpressHttpSigningMiddlewareOptions, } from "./functions/s3ExpressHttpSigningMiddleware";
7
8
  export { S3ExpressIdentity } from "./interfaces/S3ExpressIdentity";
8
9
  export { S3ExpressIdentityProvider } from "./interfaces/S3ExpressIdentityProvider";
@@ -0,0 +1,40 @@
1
+ import { IHttpRequest } from "@smithy/protocol-http";
2
+ import {
3
+ AuthScheme,
4
+ AwsCredentialIdentity,
5
+ FinalizeRequestMiddleware,
6
+ Pluggable,
7
+ RequestSigner,
8
+ } from "@smithy/types";
9
+ interface SigningProperties {
10
+ signingRegion: string;
11
+ signingDate: Date;
12
+ signingService: string;
13
+ }
14
+ interface PreviouslyResolved {
15
+ signer: (authScheme?: AuthScheme | undefined) => Promise<
16
+ RequestSigner & {
17
+ signWithCredentials(
18
+ req: IHttpRequest,
19
+ identity: AwsCredentialIdentity,
20
+ opts?: Partial<SigningProperties>
21
+ ): Promise<IHttpRequest>;
22
+ }
23
+ >;
24
+ }
25
+ export declare const s3ExpressHttpSigningMiddlewareOptions: import("@smithy/types").FinalizeRequestHandlerOptions &
26
+ import("@smithy/types").RelativeLocation &
27
+ Pick<
28
+ import("@smithy/types").HandlerOptions,
29
+ Exclude<keyof import("@smithy/types").HandlerOptions, "step">
30
+ >;
31
+ export declare const s3ExpressHttpSigningMiddleware: <
32
+ Input extends object,
33
+ Output extends object
34
+ >(
35
+ config: PreviouslyResolved
36
+ ) => FinalizeRequestMiddleware<any, any>;
37
+ export declare const getS3ExpressHttpSigningPlugin: (config: {
38
+ signer: (authScheme?: AuthScheme | undefined) => Promise<RequestSigner>;
39
+ }) => Pluggable<any, any>;
40
+ export {};
@@ -0,0 +1,27 @@
1
+ import {
2
+ AwsCredentialIdentity,
3
+ HttpRequest as IHttpRequest,
4
+ } from "@smithy/types";
5
+ import { S3ExpressIdentity } from "../interfaces/S3ExpressIdentity";
6
+ export declare const signS3Express: (
7
+ s3ExpressIdentity: S3ExpressIdentity,
8
+ signingOptions: {
9
+ signingDate: Date;
10
+ signingRegion: string;
11
+ signingService: string;
12
+ },
13
+ request: IHttpRequest,
14
+ sigV4MultiRegionSigner: {
15
+ signWithCredentials(
16
+ req: IHttpRequest,
17
+ identity: AwsCredentialIdentity,
18
+ opts?:
19
+ | Partial<{
20
+ signingDate: Date;
21
+ signingRegion: string;
22
+ signingService: string;
23
+ }>
24
+ | undefined
25
+ ): Promise<IHttpRequest>;
26
+ }
27
+ ) => Promise<IHttpRequest>;
@@ -8,5 +8,10 @@ export {
8
8
  s3ExpressMiddleware,
9
9
  s3ExpressMiddlewareOptions,
10
10
  } from "./functions/s3ExpressMiddleware";
11
+ export {
12
+ getS3ExpressHttpSigningPlugin,
13
+ s3ExpressHttpSigningMiddleware,
14
+ s3ExpressHttpSigningMiddlewareOptions,
15
+ } from "./functions/s3ExpressHttpSigningMiddleware";
11
16
  export { S3ExpressIdentity } from "./interfaces/S3ExpressIdentity";
12
17
  export { S3ExpressIdentityProvider } from "./interfaces/S3ExpressIdentityProvider";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/middleware-sdk-s3",
3
- "version": "3.622.0",
3
+ "version": "3.626.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",
@@ -23,14 +23,17 @@
23
23
  },
24
24
  "license": "Apache-2.0",
25
25
  "dependencies": {
26
+ "@aws-sdk/core": "3.624.0",
26
27
  "@aws-sdk/types": "3.609.0",
27
28
  "@aws-sdk/util-arn-parser": "3.568.0",
29
+ "@smithy/core": "^2.3.2",
28
30
  "@smithy/node-config-provider": "^3.1.4",
29
31
  "@smithy/protocol-http": "^4.1.0",
30
32
  "@smithy/signature-v4": "^4.1.0",
31
33
  "@smithy/smithy-client": "^3.1.12",
32
34
  "@smithy/types": "^3.3.0",
33
35
  "@smithy/util-config-provider": "^3.0.0",
36
+ "@smithy/util-middleware": "^3.0.3",
34
37
  "@smithy/util-stream": "^3.1.3",
35
38
  "@smithy/util-utf8": "^3.0.0",
36
39
  "tslib": "^2.6.2"