diff --git a/src/bucket.ts b/src/bucket.ts index 9eb66ed81..23baca69b 100644 --- a/src/bucket.ts +++ b/src/bucket.ts @@ -3269,7 +3269,7 @@ class Bucket extends ServiceObject { // You aren't allowed to set both predefinedAcl & acl properties on a bucket // so acl must explicitly be nullified. - const metadata = {...(options.metadata || {}), acl: null}; + const metadata = {...options.metadata, acl: null}; this.setMetadata(metadata, query, err => { if (err) { @@ -3513,7 +3513,7 @@ class Bucket extends ServiceObject { callback?: BodyResponseCallback ): void | Promise<[ResponseBody, Metadata]> { if (this.userProject && (!reqOpts.qs || !reqOpts.qs.userProject)) { - reqOpts.qs = {...(reqOpts.qs || {}), userProject: this.userProject}; + reqOpts.qs = {...reqOpts.qs, userProject: this.userProject}; } return super.request(reqOpts, callback!); } diff --git a/src/file.ts b/src/file.ts index f963a5d3e..11fa7f4b3 100644 --- a/src/file.ts +++ b/src/file.ts @@ -1150,14 +1150,14 @@ class File extends ServiceObject { throw noDestinationError; } - let options: ReadonlyOptions = {}; + let userOptions: ReadonlyOptions = {}; if (typeof optionsOrCallback === 'function') { callback = optionsOrCallback; } else if (optionsOrCallback) { - options = optionsOrCallback; + userOptions = optionsOrCallback; } - const payload = {...options}; + const options = {...userOptions}; callback = callback || util.noop; @@ -1189,16 +1189,16 @@ class File extends ServiceObject { if (this.generation !== undefined) { query.sourceGeneration = this.generation; } - if (options.token !== undefined) { - query.rewriteToken = options.token; + if (userOptions.token !== undefined) { + query.rewriteToken = userOptions.token; } - if (options.userProject !== undefined) { - query.userProject = options.userProject; - delete payload.userProject; + if (userOptions.userProject !== undefined) { + query.userProject = userOptions.userProject; + delete options.userProject; } - if (options.predefinedAcl !== undefined) { - query.destinationPredefinedAcl = options.predefinedAcl; - delete payload.predefinedAcl; + if (userOptions.predefinedAcl !== undefined) { + query.destinationPredefinedAcl = userOptions.predefinedAcl; + delete options.predefinedAcl; } newFile = newFile! || destBucket.file(destName); @@ -1214,9 +1214,9 @@ class File extends ServiceObject { if (newFile.encryptionKey !== undefined) { this.setEncryptionKey(newFile.encryptionKey!); - } else if (options.destinationKmsKeyName !== undefined) { - query.destinationKmsKeyName = options.destinationKmsKeyName; - delete payload.destinationKmsKeyName; + } else if (userOptions.destinationKmsKeyName !== undefined) { + query.destinationKmsKeyName = userOptions.destinationKmsKeyName; + delete options.destinationKmsKeyName; } else if (newFile.kmsKeyName !== undefined) { query.destinationKmsKeyName = newFile.kmsKeyName; } @@ -1234,15 +1234,15 @@ class File extends ServiceObject { if ( !this.shouldRetryBasedOnPreconditionAndIdempotencyStrat( - options?.preconditionOpts + userOptions?.preconditionOpts ) ) { this.storage.retryOptions.autoRetry = false; } - if (options.preconditionOpts?.ifGenerationMatch !== undefined) { - query.ifGenerationMatch = options.preconditionOpts?.ifGenerationMatch; - delete payload.preconditionOpts; + if (userOptions.preconditionOpts?.ifGenerationMatch !== undefined) { + query.ifGenerationMatch = userOptions.preconditionOpts?.ifGenerationMatch; + delete options.preconditionOpts; } this.request( @@ -1252,7 +1252,7 @@ class File extends ServiceObject { newFile.name )}`, qs: query, - json: payload, + json: options, headers, }, (err, resp) => { @@ -3072,7 +3072,6 @@ class File extends ServiceObject { // You aren't allowed to set both predefinedAcl & acl properties on a file, // so acl must explicitly be nullified, destroying all previous acls on the // file. - const metadata = {...options.metadata, acl: null}; this.setMetadata(metadata, query, callback!); diff --git a/src/nodejs-common/service-object.ts b/src/nodejs-common/service-object.ts index f739a2383..37b6ae262 100644 --- a/src/nodejs-common/service-object.ts +++ b/src/nodejs-common/service-object.ts @@ -507,7 +507,10 @@ class ServiceObject extends EventEmitter { method: 'PATCH', uri: '', ...methodConfig.reqOpts, - json: {...metadata} as ReadonlyOptions, + json: { + ...methodConfig.reqOpts?.json, + ...metadata, + } as ReadonlyOptions, qs: { ...methodConfig.reqOpts?.qs, ...options, diff --git a/src/nodejs-common/util.ts b/src/nodejs-common/util.ts index 8f70820a3..35db154a1 100644 --- a/src/nodejs-common/util.ts +++ b/src/nodejs-common/util.ts @@ -400,7 +400,7 @@ export class Util { callback = callback || util.noop; const parsedResp = { - err: err || undefined, + err: err || null, ...(resp && util.parseHttpRespMessage(resp)), ...(body && util.parseHttpRespBody(body)), }; @@ -515,6 +515,10 @@ export class Util { const reqOpts = { ...defaultReqOpts, ...options.request, + qs: { + ...defaultReqOpts.qs, + ...options.request?.qs, + }, multipart: [ { 'Content-Type': 'application/json', diff --git a/src/resumable-upload.ts b/src/resumable-upload.ts index cbfa6531c..4593d5e46 100644 --- a/src/resumable-upload.ts +++ b/src/resumable-upload.ts @@ -958,7 +958,12 @@ export class Upload extends Writable { const combinedReqOpts = { ...this.customRequestOptions, ...reqOpts, + headers: { + ...this.customRequestOptions.headers, + ...reqOpts.headers, + }, }; + const res = await this.authClient.request<{error?: object}>( combinedReqOpts ); @@ -983,6 +988,10 @@ export class Upload extends Writable { const combinedReqOpts = { ...this.customRequestOptions, ...reqOpts, + headers: { + ...this.customRequestOptions.headers, + ...reqOpts.headers, + }, }; const res = await this.authClient.request(combinedReqOpts); const successfulRequest = this.onResponse(res);