Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] default params for signedUrl() #749

Merged
merged 1 commit into from
Jan 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ export async function* listObjects({bucket, prefix}) {
* Generate a signed URL for an S3 object.
*
* @param {object} params
* @param {string} params.method - HEAD, GET, PUT, DELETE
* @param {string} params.bucket - name of bucket
* @param {string} params.key - object key
* @param {string} [params.method] - HEAD, GET, PUT, DELETE. Default: GET
* @param {object} [params.headers] - Content-Type and/or Content-Encoding headers for PUT
* @param {number} [params.expiresIn] - seconds until the URL expires
* @param {number} [params.issuedAt] - absolute time in seconds since the Unix epoch at which the signed URL should be considered issued at, i.e. when the countdown for expiresIn starts
* @returns {string} signed URL
*/
export async function signedUrl({method, bucket, key, headers, expiresIn, issuedAt} = {method: "GET", headers: {}}) {
export async function signedUrl({method="GET", bucket, key, headers={}, expiresIn, issuedAt}) {
Copy link
Member

@tsibley tsibley Jan 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, this dropped the trailing = {} that I'd intentionally suggested in {method="GET", …} = {}. Without it, a call to signedUrl() generates an error like:

Uncaught TypeError: Cannot read properties of undefined (reading 'method')

While calling signedUrl() is always an error, omitting the default = {} seems a weirder way to throw the error compared to signedUrl({}):

Uncaught Error: No value provided for input HTTP label: Bucket.

const normalizedHeaders = normalizeHeaders(headers);

const commands = new Map([
Expand Down
Loading