UNPKG

dotcms

Version:

This library allows you to interact with DotCMS API's easily from the browser, nodejs and React Native. [Full Documentation](https://dotcms.github.io/core-web/dotcms/)

59 lines 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DotApiContent = void 0; const tslib_1 = require("tslib"); function populateQueryUrl(params) { let url = ''; const attrs = { depth: `/depth/${params.options.depth}`, limit: `/limit/${params.options.limit}`, offset: `/offset/${params.options.offset}`, orderBy: `/orderby/${params.options.orderBy}` }; if (params.queryParams) { for (const key of Object.keys(params.queryParams)) { url += `+${key}:${params.queryParams[key]}%20`; } } for (const key of Object.keys(params.options)) { url += attrs[key]; } return url; } /** * Query/Save/Publish the information of DotCMS Content * */ class DotApiContent { constructor(httpClient) { this.dotCMSHttpClient = httpClient; } query(params) { const url = `/api/content/query/+contentType:${params.contentType}%20${populateQueryUrl(params)}`; return this.doRequest(url, null, 'GET'); } save(params) { return this.doRequest('/api/content/save/1', params); } publish(params) { return this.doRequest('/api/content/publish/1', params); } doRequest(url, params, httpMethod = 'POST') { return tslib_1.__awaiter(this, void 0, void 0, function* () { const response = yield this.dotCMSHttpClient.request({ url, method: httpMethod, body: params ? JSON.stringify(params) : '' }); if (response.status !== 200) { throw { message: yield response.text(), statusCode: response.status }; } return response; }); } } exports.DotApiContent = DotApiContent; //# sourceMappingURL=DotApiContent.js.map