Skip to content

Commit

Permalink
upgrade smithy and remove manual encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
zirkelc committed Apr 12, 2024
1 parent b80a15a commit bf564e8
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 101 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@aws-sdk/credential-provider-node": "^3.358.0",
"@aws-sdk/types": "^3.357.0",
"@smithy/protocol-http": "^3.3.0",
"@smithy/signature-v4": "^2.2.0"
"@smithy/signature-v4": "^2.3.0"
},
"devDependencies": {
"@biomejs/biome": "1.5.1",
Expand All @@ -59,4 +59,4 @@
"typescript": "^5.2.0",
"vitest": "^0.34.6"
}
}
}
55 changes: 23 additions & 32 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 0 additions & 18 deletions src/__tests__/encode-rfc3986.test.ts

This file was deleted.

22 changes: 0 additions & 22 deletions src/create-signed-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { defaultProvider } from "@aws-sdk/credential-provider-node";
import type { AwsCredentialIdentity, Provider } from "@aws-sdk/types";
import { HttpRequest } from "@smithy/protocol-http";
import { SignatureV4 } from "@smithy/signature-v4";
import { encodeRfc3986 } from "./encode-rfc3986.js";
import { getFetchFn } from "./get-fetch.js";
import { getHeaders } from "./get-headers.js";

Expand All @@ -12,15 +11,6 @@ export type SignedFetcherOptions = {
region?: string;
credentials?: AwsCredentialIdentity | Provider<AwsCredentialIdentity>;
fetch?: typeof fetch;
/**
* Automatically encode the request path and query string according to RFC 3986.
* This might be necessary for AWS services that require strict adherence to the RFC 3986 standard.
* For example, AWS API Gateway requires the path and query string to be encoded according to RFC 3986,
* otherwise it will return a 403 error because the calculated does not match the signature you provided.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent#encoding_for_rfc3986 | Encoding for RFC3986}
*/
encodeRfc3986?: boolean;
};

export type CreateSignedFetcher = (init: SignedFetcherOptions) => typeof fetch;
Expand Down Expand Up @@ -51,15 +41,6 @@ export const createSignedFetcher: CreateSignedFetcher = (
: input.url,
);

// // encode path and query string according to RFC 3986
// if (opts.encodeRfc3986) {
// url.pathname = encodeRfc3986(url.pathname);
// url.searchParams.forEach((value, key) => {
// url.searchParams.delete(key);
// url.searchParams.append(encodeRfc3986(key), encodeRfc3986(value));
// });
// }

const headers = getHeaders(init?.headers);
// host is required by AWS Signature V4: https://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html
headers.set("host", url.host);
Expand All @@ -83,13 +64,10 @@ export const createSignedFetcher: CreateSignedFetcher = (
service,
region,
sha256: Sha256,
// uriEscapePath: true,
});

const signedRequest = await signer.sign(request);

console.log(signedRequest);

return fetchFn(url, {
...init,
headers: signedRequest.headers,
Expand Down
11 changes: 0 additions & 11 deletions src/encode-rfc3986.ts

This file was deleted.

3 changes: 0 additions & 3 deletions test/api-gateway/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
name: "e2e/api-gateway",
typecheck: {
enabled: true,
},
},
});
3 changes: 0 additions & 3 deletions test/commonjs/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
name: "commonjs",
typecheck: {
enabled: true,
},
},
});
3 changes: 0 additions & 3 deletions test/esm/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
name: "esm",
typecheck: {
enabled: true,
},
},
});
3 changes: 0 additions & 3 deletions test/iam/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
name: "e2e/iam",
typecheck: {
enabled: true,
},
},
});
5 changes: 1 addition & 4 deletions test/s3/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
name: "e2e/api-gateway",
typecheck: {
enabled: true,
},
name: "e2e/s3",
},
});

0 comments on commit bf564e8

Please sign in to comment.