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/)
51 lines • 1.93 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.DotApiPage = void 0;
const tslib_1 = require("tslib");
/**
* Allow easy interaction with {@link https://dotcms.com/docs/latest/page-rest-api-layout-as-a-service-laas | DotCMS Page API}
*
*/
class DotApiPage {
constructor(httpClient, appLanguage) {
this.dotCMSHttpClient = httpClient;
this.dotAppLanguage = appLanguage;
}
/**
* Given the page url and the language return a {@link DotCMSPageAsset}
*
*/
get(params, format = "json" /* DotCMSPageFormat.JSON */) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (params.language) {
params = Object.assign(Object.assign({}, params), { language: isNaN(params.language)
? yield this.dotAppLanguage.getId(params.language)
: params.language });
}
params = Object.assign(Object.assign({}, params), { url: `/api/v1/page/${format}${params.url}` });
return this.dotCMSHttpClient.request(params).then((res) => tslib_1.__awaiter(this, void 0, void 0, function* () {
if (res.status === 200) {
const data = yield res.json();
return data.entity;
}
const response = yield res.text();
let error;
try {
error = {
statusCode: res.status,
message: JSON.parse(response).message
};
}
catch (_a) {
error = {
statusCode: res.status,
message: response
};
}
throw error;
}));
});
}
}
exports.DotApiPage = DotApiPage;
//# sourceMappingURL=DotApiPage.js.map
;