Skip to content

Commit 45e3c0f

Browse files
committed
fix: cloning params forgets about its instance, failing upload file test
1 parent 95f5bf2 commit 45e3c0f

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

src/Api.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222
import * as NodeFormData from 'form-data'
2323
import 'isomorphic-fetch'
2424
import * as objectAssign from 'object-assign'
25-
import * as stream from 'stream'
25+
import {Readable} from 'stream'
2626
import {INTERNAL_PREFIX} from 'workfront-api-constants'
2727

28-
export type THttpParams = any
2928
export interface IHttpOptions {
3029
path?: string
3130
method?: string
@@ -56,9 +55,7 @@ export class Api {
5655
DELETE: 'DELETE',
5756
POST: 'POST'
5857
}
59-
6058
_httpOptions: IHttpOptions
61-
_httpParams: THttpParams = {}
6259

6360
constructor(config) {
6461
this._httpOptions = {
@@ -350,8 +347,8 @@ export class Api {
350347
* @param {String} [method=GET] The method which the request will do (GET|POST|PUT|DELETE)
351348
* @return {Promise} A promise which will resolved with results if everything went ok and rejected otherwise
352349
*/
353-
request(path: string, params: THttpParams, fields?: TFields, method: string = Api.Methods.GET): Promise<any> {
354-
const clonedParams = objectAssign({}, params || {}, this._httpParams)
350+
request(path: string, params, fields?: TFields, method: string = Api.Methods.GET): Promise<any> {
351+
const clonedParams = objectAssign({}, params)
355352

356353
const alwaysUseGet = this._httpOptions.alwaysUseGet
357354

@@ -388,8 +385,8 @@ export class Api {
388385
}
389386

390387
let bodyParams = null, queryString = ''
391-
if (NodeFormData && clonedParams instanceof NodeFormData) {
392-
bodyParams = clonedParams
388+
if (NodeFormData && params instanceof NodeFormData) {
389+
bodyParams = params
393390
}
394391
else if (GlobalScope.FormData && clonedParams instanceof GlobalScope.FormData) {
395392
bodyParams = clonedParams
@@ -480,7 +477,7 @@ export class Api {
480477
* @param {fs.ReadStream} stream A readable stream with file contents
481478
* @param {String} filename Override the filename
482479
*/
483-
uploadFromStream(stream: stream.Readable, filename: string) {
480+
uploadFromStream(stream: Readable, filename: string) {
484481
const data = new NodeFormData()
485482
data.append('uploadedFile', stream, filename)
486483
return this.request('upload', data, null, Api.Methods.POST)

0 commit comments

Comments
 (0)