diff --git a/package.json b/package.json index c47d12d..92e8caf 100644 --- a/package.json +++ b/package.json @@ -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", @@ -59,4 +59,4 @@ "typescript": "^5.2.0", "vitest": "^0.34.6" } -} +} \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4ea9456..3cf6957 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -24,8 +24,8 @@ importers: specifier: ^3.3.0 version: 3.3.0 '@smithy/signature-v4': - specifier: ^2.2.0 - version: 2.2.0 + specifier: ^2.3.0 + version: 2.3.0 devDependencies: '@biomejs/biome': specifier: 1.5.1 @@ -67,15 +67,16 @@ importers: test/iam: {} -packages: - - /@aws-crypto/crc32@3.0.0: - resolution: {integrity: sha512-IzSgsrxUcsrejQbPVilIKy16kAT52EwB6zSaI+M3xxIhKh5+aldEyvI+z6erM7TCLB2BJsFrtHjp6/4/sr+3dA==} + test/s3: dependencies: - '@aws-crypto/util': 3.0.0 - '@aws-sdk/types': 3.535.0 - tslib: 1.14.1 - dev: false + '@aws-sdk/client-api-gateway': + specifier: ^3.535.0 + version: 3.535.0 + '@aws-sdk/client-apigatewayv2': + specifier: ^3.535.0 + version: 3.535.0 + +packages: /@aws-crypto/ie11-detection@3.0.0: resolution: {integrity: sha512-341lBBkiY1DfDNKai/wXM3aujNBkXR7tq1URPQDL9wi3AUbI80NR74uF1TXHMm7po1AcnFk8iu2S2IeU/+/A+Q==} @@ -531,7 +532,7 @@ packages: dependencies: '@smithy/core': 1.4.0 '@smithy/protocol-http': 3.3.0 - '@smithy/signature-v4': 2.2.0 + '@smithy/signature-v4': 2.3.0 '@smithy/smithy-client': 2.5.0 '@smithy/types': 2.12.0 fast-xml-parser: 4.2.5 @@ -544,7 +545,7 @@ packages: dependencies: '@aws-sdk/types': 3.451.0 '@smithy/property-provider': 2.0.14 - '@smithy/types': 2.5.0 + '@smithy/types': 2.12.0 tslib: 2.6.2 dev: false @@ -585,7 +586,7 @@ packages: '@smithy/credential-provider-imds': 2.1.1 '@smithy/property-provider': 2.0.14 '@smithy/shared-ini-file-loader': 2.2.4 - '@smithy/types': 2.5.0 + '@smithy/types': 2.12.0 tslib: 2.6.2 transitivePeerDependencies: - aws-crt @@ -657,7 +658,7 @@ packages: '@aws-sdk/types': 3.451.0 '@smithy/property-provider': 2.0.14 '@smithy/shared-ini-file-loader': 2.2.4 - '@smithy/types': 2.5.0 + '@smithy/types': 2.12.0 tslib: 2.6.2 dev: false @@ -681,7 +682,7 @@ packages: '@aws-sdk/types': 3.451.0 '@smithy/property-provider': 2.0.14 '@smithy/shared-ini-file-loader': 2.2.4 - '@smithy/types': 2.5.0 + '@smithy/types': 2.12.0 tslib: 2.6.2 transitivePeerDependencies: - aws-crt @@ -709,7 +710,7 @@ packages: dependencies: '@aws-sdk/types': 3.451.0 '@smithy/property-provider': 2.0.14 - '@smithy/types': 2.5.0 + '@smithy/types': 2.12.0 tslib: 2.6.2 dev: false @@ -812,7 +813,7 @@ packages: '@aws-sdk/types': 3.451.0 '@smithy/property-provider': 2.0.14 '@smithy/protocol-http': 3.3.0 - '@smithy/signature-v4': 2.2.0 + '@smithy/signature-v4': 2.3.0 '@smithy/types': 2.12.0 '@smithy/util-middleware': 2.2.0 tslib: 2.6.2 @@ -1829,7 +1830,7 @@ packages: dependencies: '@smithy/node-config-provider': 2.1.5 '@smithy/property-provider': 2.0.14 - '@smithy/types': 2.5.0 + '@smithy/types': 2.12.0 '@smithy/url-parser': 2.0.13 tslib: 2.6.2 dev: false @@ -1845,15 +1846,6 @@ packages: tslib: 2.6.2 dev: false - /@smithy/eventstream-codec@2.2.0: - resolution: {integrity: sha512-8janZoJw85nJmQZc4L8TuePp2pk1nxLgkxIR0TUjKJ5Dkj5oelB9WtiSSGXCQvNsJl0VSTvK/2ueMXxvpa9GVw==} - dependencies: - '@aws-crypto/crc32': 3.0.0 - '@smithy/types': 2.12.0 - '@smithy/util-hex-encoding': 2.2.0 - tslib: 2.6.2 - dev: false - /@smithy/fetch-http-handler@2.2.6: resolution: {integrity: sha512-PStY3XO1Ksjwn3wMKye5U6m6zxXpXrXZYqLy/IeCbh3nM9QB3Jgw/B0PUSLUWKdXg4U8qgEu300e3ZoBvZLsDg==} dependencies: @@ -2066,7 +2058,7 @@ packages: resolution: {integrity: sha512-k3D2qp9o6imTrLaXRj6GdLYEJr1sXqS99nLhzq8fYmJjSVOeMg/G+1KVAAc7Oxpu71rlZ2f8SSZxcSxkevuR0A==} engines: {node: '>=14.0.0'} dependencies: - '@smithy/types': 2.5.0 + '@smithy/types': 2.12.0 tslib: 2.6.2 dev: false @@ -2130,7 +2122,7 @@ packages: resolution: {integrity: sha512-9dRknGgvYlRIsoTcmMJXuoR/3ekhGwhRq4un3ns2/byre4Ql5hyUN4iS0x8eITohjU90YOnUCsbRwZRvCkbRfw==} engines: {node: '>=14.0.0'} dependencies: - '@smithy/types': 2.5.0 + '@smithy/types': 2.12.0 tslib: 2.6.2 dev: false @@ -2142,11 +2134,10 @@ packages: tslib: 2.6.2 dev: false - /@smithy/signature-v4@2.2.0: - resolution: {integrity: sha512-+B5TNzj/fRZzVW3z8UUJOkNx15+4E0CLuvJmJUA1JUIZFp3rdJ/M2H5r2SqltaVPXL0oIxv/6YK92T9TsFGbFg==} + /@smithy/signature-v4@2.3.0: + resolution: {integrity: sha512-ui/NlpILU+6HAQBfJX8BBsDXuKSNrjTSuOYArRblcrErwKFutjrCNb/OExfVRyj9+26F9J+ZmfWT+fKWuDrH3Q==} engines: {node: '>=14.0.0'} dependencies: - '@smithy/eventstream-codec': 2.2.0 '@smithy/is-array-buffer': 2.2.0 '@smithy/types': 2.12.0 '@smithy/util-hex-encoding': 2.2.0 diff --git a/src/__tests__/encode-rfc3986.test.ts b/src/__tests__/encode-rfc3986.test.ts deleted file mode 100644 index 60bd644..0000000 --- a/src/__tests__/encode-rfc3986.test.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { encodeRfc3986 } from "../encode-rfc3986.js"; - -describe("encodeRfc3986", () => { - it("should encode reserved characters", () => { - // * ! ' ( ) - const encoded = encodeRfc3986("* ! ' ( )"); - expect(encoded).toEqual("%2A %21 %27 %28 %29"); - }); - - it("should not encode other characters", () => { - // A–Z a–z 0–9 - _ . ~ ; / ? : @ & = + $ , # - const str = - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789- _ . ~ ; / ? : @ & = + $ , #"; - const encoded = encodeRfc3986(str); - expect(encoded).toEqual(str); - }); -}); diff --git a/src/create-signed-fetcher.ts b/src/create-signed-fetcher.ts index 9a353bc..84bd8e0 100644 --- a/src/create-signed-fetcher.ts +++ b/src/create-signed-fetcher.ts @@ -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"; @@ -12,15 +11,6 @@ export type SignedFetcherOptions = { region?: string; credentials?: AwsCredentialIdentity | Provider; 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; @@ -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); @@ -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, diff --git a/src/encode-rfc3986.ts b/src/encode-rfc3986.ts deleted file mode 100644 index 9b07684..0000000 --- a/src/encode-rfc3986.ts +++ /dev/null @@ -1,11 +0,0 @@ -/** - * Encodes a string according to RFC 3986. - * - * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent#encoding_for_rfc3986 | MDN} - */ -export const encodeRfc3986 = (str: string): string => { - return str.replace( - /[!'()*]/g, - (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`, - ); -}; diff --git a/test/api-gateway/vitest.config.mts b/test/api-gateway/vitest.config.mts index de15e2e..d8c2af2 100644 --- a/test/api-gateway/vitest.config.mts +++ b/test/api-gateway/vitest.config.mts @@ -3,8 +3,5 @@ import { defineConfig } from "vitest/config"; export default defineConfig({ test: { name: "e2e/api-gateway", - typecheck: { - enabled: true, - }, }, }); diff --git a/test/commonjs/vitest.config.mts b/test/commonjs/vitest.config.mts index d7f971e..cfba422 100644 --- a/test/commonjs/vitest.config.mts +++ b/test/commonjs/vitest.config.mts @@ -3,8 +3,5 @@ import { defineConfig } from "vitest/config"; export default defineConfig({ test: { name: "commonjs", - typecheck: { - enabled: true, - }, }, }); diff --git a/test/esm/vitest.config.mts b/test/esm/vitest.config.mts index 42d8064..a3b67d4 100644 --- a/test/esm/vitest.config.mts +++ b/test/esm/vitest.config.mts @@ -3,8 +3,5 @@ import { defineConfig } from "vitest/config"; export default defineConfig({ test: { name: "esm", - typecheck: { - enabled: true, - }, }, }); diff --git a/test/iam/vitest.config.mts b/test/iam/vitest.config.mts index e87c8d8..0caaf39 100644 --- a/test/iam/vitest.config.mts +++ b/test/iam/vitest.config.mts @@ -3,8 +3,5 @@ import { defineConfig } from "vitest/config"; export default defineConfig({ test: { name: "e2e/iam", - typecheck: { - enabled: true, - }, }, }); diff --git a/test/s3/vitest.config.mts b/test/s3/vitest.config.mts index de15e2e..27935fa 100644 --- a/test/s3/vitest.config.mts +++ b/test/s3/vitest.config.mts @@ -2,9 +2,6 @@ import { defineConfig } from "vitest/config"; export default defineConfig({ test: { - name: "e2e/api-gateway", - typecheck: { - enabled: true, - }, + name: "e2e/s3", }, });