tilda-client
Version:
Tilda API client for Node.js and browser
134 lines • 5.33 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TildaClient = void 0;
const _1 = require(".");
const cross_fetch_1 = require("cross-fetch");
class TildaClient {
constructor(publicKey, secretKey) {
this.publicKey = publicKey;
this.secretKey = secretKey;
}
/**
* @returns The list of available projects
*/
getProjectsList() {
return __awaiter(this, void 0, void 0, function* () {
const res = yield cross_fetch_1.default(`https://api.tildacdn.info/v1/getprojectslist/?publickey=${this.publicKey}&secretkey=${this.secretKey}`);
if (res.ok) {
return (yield res.json()).result || [];
}
else {
yield _1.throwTildaError(res);
}
});
}
/**
* @returns The information about the project
*/
getProject(projectId) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield cross_fetch_1.default(`https://api.tildacdn.info/v1/getproject/?publickey=${this.publicKey}&secretkey=${this.secretKey}&projectid=${projectId}`);
if (res.ok) {
return (yield res.json()).result;
}
else {
yield _1.throwTildaError(res);
}
});
}
/**
* @returns The information about the project for export
*/
getProjectExport(projectId) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield cross_fetch_1.default(`https://api.tildacdn.info/v1/getprojectexport/?publickey=${this.publicKey}&secretkey=${this.secretKey}&projectid=${projectId}`);
if (res.ok) {
return (yield res.json()).result;
}
else {
yield _1.throwTildaError(res);
}
});
}
/**
* @returns The list of available pages in the project
*/
getPagesList(projectId) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield cross_fetch_1.default(`https://api.tildacdn.info/v1/getpageslist/?publickey=${this.publicKey}&secretkey=${this.secretKey}&projectid=${projectId}`);
if (res.ok) {
return (yield res.json()).result || [];
}
else {
yield _1.throwTildaError(res);
}
});
}
/**
* @returns The information about the page (+ body html-code)
*/
getPage(pageId) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield cross_fetch_1.default(`https://api.tildacdn.info/v1/getpage/?publickey=${this.publicKey}&secretkey=${this.secretKey}&pageid=${pageId}`);
if (res.ok) {
return (yield res.json()).result;
}
else {
yield _1.throwTildaError(res);
}
});
}
/**
* @returns The information about the page (+ fullpage html-code)
*/
getPageFull(pageId) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield cross_fetch_1.default(`https://api.tildacdn.info/v1/getpagefull/?publickey=${this.publicKey}&secretkey=${this.secretKey}&pageid=${pageId}`);
if (res.ok) {
return (yield res.json()).result;
}
else {
yield _1.throwTildaError(res);
}
});
}
/**
* @returns The information about the page for export (+ body html-code)
*/
getPageExport(pageId) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield cross_fetch_1.default(`https://api.tildacdn.info/v1/getpageexport/?publickey=${this.publicKey}&secretkey=${this.secretKey}&pageid=${pageId}`);
if (res.ok) {
return (yield res.json()).result;
}
else {
yield _1.throwTildaError(res);
}
});
}
/**
* @returns The information about the page for export (+ fullpage html-code)
*/
getPageFullExport(pageId) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield cross_fetch_1.default(`https://api.tildacdn.info/v1/getpagefullexport/?publickey=${this.publicKey}&secretkey=${this.secretKey}&pageid=${pageId}`);
if (res.ok) {
return (yield res.json()).result;
}
else {
yield _1.throwTildaError(res);
}
});
}
}
exports.TildaClient = TildaClient;
//# sourceMappingURL=tilda.client.js.map