@lucidtech/las-sdk-core
Advanced tools
Comparing version 12.0.1-rc.4 to 13.0.0-beta.1
@@ -66,11 +66,11 @@ /// <reference types="node" /> | ||
* | ||
* @param content Content to POST (base64 string | Buffer) | ||
* @param content Content to POST (Buffer) | ||
* @param contentType MIME type for the document | ||
* @param options.consentId Id of the consent that marks the owner of the document | ||
* @param options.groundTruth List of GroundTruth items representing the ground truth values for the document | ||
* @param data.description Description of document | ||
* @param data.name Name of document | ||
* @param options.description Description of document | ||
* @param options.name Name of document | ||
* @returns Document response from REST API | ||
*/ | ||
createDocument(content: string | Buffer, contentType: ContentType, options?: CreateDocumentOptions): Promise<LasDocumentWithoutContent>; | ||
createDocument(content: ArrayBuffer | Uint8Array | Buffer, contentType: ContentType, options?: CreateDocumentOptions): Promise<LasDocumentWithoutContent>; | ||
/** | ||
@@ -661,3 +661,5 @@ * Get document from the REST API, calls the GET /documents/{documentId} endpoint. | ||
makeFileServerGetRequest(fileUrl: string, options?: any): Promise<ArrayBuffer>; | ||
makeFileServerPutRequest<T>(fileUrl: string, content: Buffer, options?: any): Promise<T>; | ||
private makeAuthorizedFileServerRequest; | ||
private makeAuthorizedFileServerBodyRequest; | ||
private makeAuthorizedRequest; | ||
@@ -664,0 +666,0 @@ private makeAuthorizedBodyRequest; |
@@ -112,8 +112,8 @@ "use strict"; | ||
* | ||
* @param content Content to POST (base64 string | Buffer) | ||
* @param content Content to POST (Buffer) | ||
* @param contentType MIME type for the document | ||
* @param options.consentId Id of the consent that marks the owner of the document | ||
* @param options.groundTruth List of GroundTruth items representing the ground truth values for the document | ||
* @param data.description Description of document | ||
* @param data.name Name of document | ||
* @param options.description Description of document | ||
* @param options.name Name of document | ||
* @returns Document response from REST API | ||
@@ -123,5 +123,4 @@ */ | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const encodedContent = typeof content === 'string' ? content : buffer_1.Buffer.from(content).toString('base64'); | ||
let body = { | ||
content: encodedContent, | ||
content: null, | ||
contentType, | ||
@@ -132,3 +131,6 @@ }; | ||
} | ||
return this.makePostRequest('/documents', body); | ||
const lasDoc = yield this.makePostRequest('/documents', body); | ||
const asBuffer = buffer_1.Buffer.from(content); | ||
yield this.makeFileServerPutRequest(lasDoc.fileUrl, asBuffer); | ||
return lasDoc; | ||
}); | ||
@@ -1088,2 +1090,8 @@ } | ||
} | ||
makeFileServerPutRequest(fileUrl, content, options = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
options.body = content; | ||
return this.makeAuthorizedFileServerBodyRequest(axios_1.default.put, fileUrl, options); | ||
}); | ||
} | ||
makeAuthorizedFileServerRequest(axiosFn, fileUrl, requestConfig = {}) { | ||
@@ -1100,2 +1108,14 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
makeAuthorizedFileServerBodyRequest(axiosFn, fileUrl, options = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const headers = yield this.getAuthorizationHeaders(); | ||
const { requestConfig } = options, body = __rest(options, ["requestConfig"]); | ||
let config = { headers }; | ||
if (requestConfig) { | ||
config = Object.assign(Object.assign({}, config), requestConfig); | ||
} | ||
const result = yield axiosFn(fileUrl, body, config); | ||
return result.data; | ||
}); | ||
} | ||
makeAuthorizedRequest(axiosFn, path, requestConfig = {}) { | ||
@@ -1102,0 +1122,0 @@ return __awaiter(this, void 0, void 0, function* () { |
@@ -10,3 +10,3 @@ import { JSONValue, PaginationOptions, RequestConfig } from './common'; | ||
consentId?: string; | ||
content: string; | ||
content: string | null; | ||
contentMD5: string | null; | ||
@@ -20,2 +20,3 @@ contentType: ContentType; | ||
groundTruth?: GroundTruth; | ||
fileUrl: string | null; | ||
metadata: Record<string, unknown> | null; | ||
@@ -22,0 +23,0 @@ name: string | null; |
{ | ||
"name": "@lucidtech/las-sdk-core", | ||
"version": "12.0.1-rc.4", | ||
"version": "13.0.0-beta.1", | ||
"author": "Lucidtech AS <hello@lucidtech.ai>", | ||
@@ -5,0 +5,0 @@ "maintainers": [ |
134177
2867