aws-sigv4-fetch
Version:
SignatureV4 fetch function implemented with the official AWS SDK
34 lines (31 loc) • 971 B
JavaScript
// src/create-signed-fetcher.ts
import { signRequest } from "aws-sigv4-sign";
// src/get-fetch.ts
var getFetchFn = (customFetchFn) => {
if (customFetchFn) {
return customFetchFn;
}
if (typeof window !== "undefined" && typeof window.fetch === "function") {
return window.fetch.bind(window);
}
if (typeof globalThis !== "undefined" && typeof globalThis.fetch === "function") {
return globalThis.fetch.bind(globalThis);
}
throw new Error("No fetch implementation found");
};
// src/create-signed-fetcher.ts
var createSignedFetcher = (options) => {
const fetchFn = getFetchFn(options.fetch);
const signOptions = {
service: options.service,
region: options.region,
credentials: options.credentials
};
return async (input, init) => {
const signedRequest = init ? await signRequest(input, init, signOptions) : await signRequest(input, signOptions);
return fetchFn(signedRequest);
};
};
export {
createSignedFetcher
};