diff --git a/package.json b/package.json index e31f73a..93b4eb4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "typehub-javascript-sdk", - "version": "1.1.5", + "version": "1.1.6", "description": "SDK to talk to the TypeHub API", "keywords": [ "TypeHub", diff --git a/src/DocumentMeta.ts b/src/DocumentMeta.ts new file mode 100644 index 0000000..3a08380 --- /dev/null +++ b/src/DocumentMeta.ts @@ -0,0 +1,13 @@ +/** + * DocumentMeta automatically generated by SDKgen please do not edit this file manually + * {@link https://sdkgen.app} + */ + +export interface DocumentMeta { + description?: string + baseUrl?: string + baseVersion?: string + keywords?: string + homepage?: string + license?: string +} diff --git a/src/DocumentTag.ts b/src/DocumentTag.ts index ff10a8c..a490226 100644 --- a/src/DocumentTag.ts +++ b/src/DocumentTag.ts @@ -12,6 +12,7 @@ import {DocumentCollection} from "./DocumentCollection"; import {DocumentCreate} from "./DocumentCreate"; import {DocumentExportRequest} from "./DocumentExportRequest"; import {DocumentExportResponse} from "./DocumentExportResponse"; +import {DocumentMeta} from "./DocumentMeta"; import {DocumentPreview} from "./DocumentPreview"; import {DocumentUpdate} from "./DocumentUpdate"; import {Message} from "./Message"; @@ -19,6 +20,50 @@ import {MessageException} from "./MessageException"; import {Passthru} from "./Passthru"; export class DocumentTag extends TagAbstract { + /** + * Updates the meta data of an document + * + * @returns {Promise} + * @throws {MessageException} + * @throws {ClientException} + */ + public async meta(user: string, document: string, payload: DocumentMeta): Promise { + const url = this.parser.url('/document/:user/:document/meta', { + 'user': user, + 'document': document, + }); + + let params: AxiosRequestConfig = { + url: url, + method: 'PUT', + params: this.parser.query({ + }), + data: payload + }; + + try { + const response = await this.httpClient.request(params); + return response.data; + } catch (error) { + if (error instanceof ClientException) { + throw error; + } else if (axios.isAxiosError(error) && error.response) { + switch (error.response.status) { + case 400: + throw new MessageException(error.response.data); + case 404: + throw new MessageException(error.response.data); + case 500: + throw new MessageException(error.response.data); + default: + throw new UnknownStatusCodeException('The server returned an unknown status code'); + } + } else { + throw new ClientException('An unknown error occurred: ' + String(error)); + } + } + } + /** * Reverts your document to this commit *