@datocms/cma-client-node
Advanced tools
Comparing version 3.0.2 to 3.0.4
@@ -28,3 +28,5 @@ "use strict"; | ||
} | ||
const { id, url } = yield client.uploadRequest.create({ filename }); | ||
const { id, url, request_headers } = yield client.uploadRequest.create({ | ||
filename, | ||
}); | ||
if (isCanceledBeforeUpload) { | ||
@@ -41,3 +43,3 @@ throw new rest_client_utils_2.CanceledPromiseError(); | ||
} | ||
uploadPromise = (0, uploadLocalFileToS3_1.uploadLocalFileToS3)(localPath, url, options); | ||
uploadPromise = (0, uploadLocalFileToS3_1.uploadLocalFileToS3)(localPath, url, Object.assign(Object.assign({}, options), { additionalHeaders: request_headers })); | ||
yield uploadPromise; | ||
@@ -44,0 +46,0 @@ return id; |
@@ -44,3 +44,3 @@ "use strict"; | ||
const rest_client_utils_2 = require("@datocms/rest-client-utils"); | ||
function uploadLocalFileToS3(filePath, url, { onProgress } = {}) { | ||
function uploadLocalFileToS3(filePath, url, { onProgress, additionalHeaders } = {}) { | ||
let isCanceled = false; | ||
@@ -58,6 +58,3 @@ let putPromise; | ||
putPromise = got_1.default.put(url, { | ||
headers: { | ||
'Content-Type': mime_types_1.default.lookup(filePath) || 'application/octet-stream', | ||
'Content-Length': `${totalLength}`, | ||
}, | ||
headers: Object.assign(Object.assign({}, (additionalHeaders || {})), { 'Content-Type': mime_types_1.default.lookup(filePath) || 'application/octet-stream', 'Content-Length': `${totalLength}` }), | ||
responseType: 'json', | ||
@@ -64,0 +61,0 @@ body: (0, fs_1.createReadStream)(filePath), |
@@ -25,3 +25,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
const { id, url } = yield client.uploadRequest.create({ filename }); | ||
const { id, url, request_headers } = yield client.uploadRequest.create({ | ||
filename, | ||
}); | ||
if (isCanceledBeforeUpload) { | ||
@@ -38,3 +40,3 @@ throw new CanceledPromiseError(); | ||
} | ||
uploadPromise = uploadLocalFileToS3(localPath, url, options); | ||
uploadPromise = uploadLocalFileToS3(localPath, url, Object.assign(Object.assign({}, options), { additionalHeaders: request_headers })); | ||
yield uploadPromise; | ||
@@ -41,0 +43,0 @@ return id; |
@@ -5,4 +5,5 @@ import { OnProgressInfo } from './uploadLocalFileAndReturnPath'; | ||
onProgress?: (info: OnProgressInfo) => void; | ||
additionalHeaders?: Record<string, string>; | ||
}; | ||
export declare function uploadLocalFileToS3(filePath: string, url: string, { onProgress }?: Options): CancelablePromise<void>; | ||
export declare function uploadLocalFileToS3(filePath: string, url: string, { onProgress, additionalHeaders }?: Options): CancelablePromise<void>; | ||
export {}; |
@@ -15,3 +15,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { makeCancelablePromise } from '@datocms/rest-client-utils'; | ||
export function uploadLocalFileToS3(filePath, url, { onProgress } = {}) { | ||
export function uploadLocalFileToS3(filePath, url, { onProgress, additionalHeaders } = {}) { | ||
let isCanceled = false; | ||
@@ -29,6 +29,3 @@ let putPromise; | ||
putPromise = got.put(url, { | ||
headers: { | ||
'Content-Type': mime.lookup(filePath) || 'application/octet-stream', | ||
'Content-Length': `${totalLength}`, | ||
}, | ||
headers: Object.assign(Object.assign({}, (additionalHeaders || {})), { 'Content-Type': mime.lookup(filePath) || 'application/octet-stream', 'Content-Length': `${totalLength}` }), | ||
responseType: 'json', | ||
@@ -35,0 +32,0 @@ body: createReadStream(filePath), |
@@ -5,4 +5,5 @@ import { OnProgressInfo } from './uploadLocalFileAndReturnPath'; | ||
onProgress?: (info: OnProgressInfo) => void; | ||
additionalHeaders?: Record<string, string>; | ||
}; | ||
export declare function uploadLocalFileToS3(filePath: string, url: string, { onProgress }?: Options): CancelablePromise<void>; | ||
export declare function uploadLocalFileToS3(filePath: string, url: string, { onProgress, additionalHeaders }?: Options): CancelablePromise<void>; | ||
export {}; |
{ | ||
"name": "@datocms/cma-client-node", | ||
"version": "3.0.2", | ||
"version": "3.0.4", | ||
"description": "NodeJS client for DatoCMS REST Content Management API", | ||
@@ -31,3 +31,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@datocms/cma-client": "^3.0.1", | ||
"@datocms/cma-client": "^3.0.4", | ||
"@datocms/rest-client-utils": "^3.0.1", | ||
@@ -39,3 +39,3 @@ "got": "^11.8.5", | ||
"devDependencies": { | ||
"@datocms/dashboard-client": "^3.0.1", | ||
"@datocms/dashboard-client": "^3.0.4", | ||
"@types/mime-types": "^2.1.1", | ||
@@ -54,3 +54,3 @@ "@types/tmp": "^0.2.3", | ||
}, | ||
"gitHead": "816bfe40698fb0a70dd02949f626a4bf442361b6" | ||
"gitHead": "d6bbcf5972f0854f49bbf2e04270de9596287092" | ||
} |
@@ -61,3 +61,5 @@ import { Client } from '@datocms/cma-client'; | ||
const { id, url } = await client.uploadRequest.create({ filename }); | ||
const { id, url, request_headers } = await client.uploadRequest.create({ | ||
filename, | ||
}); | ||
@@ -77,3 +79,6 @@ if (isCanceledBeforeUpload) { | ||
uploadPromise = uploadLocalFileToS3(localPath, url, options); | ||
uploadPromise = uploadLocalFileToS3(localPath, url, { | ||
...options, | ||
additionalHeaders: request_headers as Record<string, string>, | ||
}); | ||
@@ -80,0 +85,0 @@ await uploadPromise; |
@@ -13,2 +13,3 @@ import got, { CancelError, CancelableRequest, Response } from 'got'; | ||
onProgress?: (info: OnProgressInfo) => void; | ||
additionalHeaders?: Record<string, string>; | ||
}; | ||
@@ -19,3 +20,3 @@ | ||
url: string, | ||
{ onProgress }: Options = {}, | ||
{ onProgress, additionalHeaders }: Options = {}, | ||
): CancelablePromise<void> { | ||
@@ -40,2 +41,3 @@ let isCanceled = false; | ||
headers: { | ||
...(additionalHeaders || {}), | ||
'Content-Type': mime.lookup(filePath) || 'application/octet-stream', | ||
@@ -42,0 +44,0 @@ 'Content-Length': `${totalLength}`, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
96096
1639
Updated@datocms/cma-client@^3.0.4