UNPKG

@agility/management-sdk

Version:
544 lines (543 loc) 29.4 kB
"use strict"; 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()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PageMethods = void 0; var clientInstance_1 = require("./clientInstance"); var batchMethods_1 = require("./batchMethods"); var exception_1 = require("../models/exception"); var PageMethods = /** @class */ (function () { function PageMethods(options) { this._options = options; this._clientInstance = new clientInstance_1.ClientInstance(this._options); this._batchMethods = new batchMethods_1.BatchMethods(this._options); } PageMethods.prototype.getSitemap = function (guid, locale) { return __awaiter(this, void 0, void 0, function () { var apiPath, resp, err_1; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); apiPath = locale + "/sitemap"; return [4 /*yield*/, this._clientInstance.executeGet(apiPath, guid, this._options.token)]; case 1: resp = _a.sent(); return [2 /*return*/, resp.data]; case 2: err_1 = _a.sent(); throw new exception_1.Exception("Unable to retrieve sitemap.", err_1); case 3: return [2 /*return*/]; } }); }); }; PageMethods.prototype.getPageTemplates = function (guid, locale, includeModuleZones, searchFilter) { if (searchFilter === void 0) { searchFilter = null; } return __awaiter(this, void 0, void 0, function () { var apiPath, resp, err_2; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); if (!searchFilter) searchFilter = ''; apiPath = locale + "/page/templates?includeModuleZones=" + includeModuleZones + "&searchFilter=" + searchFilter; return [4 /*yield*/, this._clientInstance.executeGet(apiPath, guid, this._options.token)]; case 1: resp = _a.sent(); return [2 /*return*/, resp.data]; case 2: err_2 = _a.sent(); throw new exception_1.Exception("Unable to retrieve Page Templates.", err_2); case 3: return [2 /*return*/]; } }); }); }; PageMethods.prototype.getPageTemplate = function (guid, locale, pageTemplateId) { return __awaiter(this, void 0, void 0, function () { var apiPath, resp, err_3; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); apiPath = locale + "/page/template/" + pageTemplateId; return [4 /*yield*/, this._clientInstance.executeGet(apiPath, guid, this._options.token)]; case 1: resp = _a.sent(); return [2 /*return*/, resp.data]; case 2: err_3 = _a.sent(); throw new exception_1.Exception("Unable to retrieve Page Template.", err_3); case 3: return [2 /*return*/]; } }); }); }; PageMethods.prototype.getPageTemplateName = function (guid, locale, templateName) { return __awaiter(this, void 0, void 0, function () { var apiPath, resp, err_4; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); apiPath = locale + "/page/template/" + templateName; return [4 /*yield*/, this._clientInstance.executeGet(apiPath, guid, this._options.token)]; case 1: resp = _a.sent(); return [2 /*return*/, resp.data]; case 2: err_4 = _a.sent(); throw new exception_1.Exception("Unable to retrieve Page Template.", err_4); case 3: return [2 /*return*/]; } }); }); }; PageMethods.prototype.deletePageTemplate = function (guid, locale, pageTemplateId) { return __awaiter(this, void 0, void 0, function () { var apiPath, resp, err_5; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); apiPath = locale + "/page/template/" + pageTemplateId; return [4 /*yield*/, this._clientInstance.executeDelete(apiPath, guid, this._options.token)]; case 1: resp = _a.sent(); return [2 /*return*/, resp.data]; case 2: err_5 = _a.sent(); throw new exception_1.Exception("Unable to delete Page Template.", err_5); case 3: return [2 /*return*/]; } }); }); }; PageMethods.prototype.getPageItemTemplates = function (guid, locale, id) { return __awaiter(this, void 0, void 0, function () { var apiPath, resp, err_6; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); apiPath = locale + "/page/template/items/" + id; return [4 /*yield*/, this._clientInstance.executeGet(apiPath, guid, this._options.token)]; case 1: resp = _a.sent(); return [2 /*return*/, resp.data]; case 2: err_6 = _a.sent(); throw new exception_1.Exception("Unable to retrieve Page Template Items.", err_6); case 3: return [2 /*return*/]; } }); }); }; PageMethods.prototype.savePageTemplate = function (guid, locale, pageModel) { return __awaiter(this, void 0, void 0, function () { var apiPath, resp, err_7; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); apiPath = locale + "/page/template"; return [4 /*yield*/, this._clientInstance.executePost(apiPath, guid, this._options.token, pageModel)]; case 1: resp = _a.sent(); return [2 /*return*/, resp.data]; case 2: err_7 = _a.sent(); throw new exception_1.Exception("Unable to save Page Template.", err_7); case 3: return [2 /*return*/]; } }); }); }; PageMethods.prototype.getPage = function (pageID, guid, locale) { return __awaiter(this, void 0, void 0, function () { var apiPath, resp, err_8; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); apiPath = locale + "/page/" + pageID; return [4 /*yield*/, this._clientInstance.executeGet(apiPath, guid, this._options.token)]; case 1: resp = _a.sent(); return [2 /*return*/, resp.data]; case 2: err_8 = _a.sent(); throw new exception_1.Exception("Unable to retrieve page for id " + pageID + ".", err_8); case 3: return [2 /*return*/]; } }); }); }; PageMethods.prototype.publishPage = function (pageID, guid, locale, comments, returnBatchId) { if (comments === void 0) { comments = null; } if (returnBatchId === void 0) { returnBatchId = false; } return __awaiter(this, void 0, void 0, function () { var apiPath, resp, batchID_1, batch, pageIDs_1, err_9; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 3, , 4]); apiPath = locale + "/page/" + pageID + "/publish?comments=" + comments; return [4 /*yield*/, this._clientInstance.executeGet(apiPath, guid, this._options.token)]; case 1: resp = _a.sent(); batchID_1 = resp.data; // If user wants batchID immediately, return it for custom polling if (returnBatchId) { return [2 /*return*/, [batchID_1]]; } return [4 /*yield*/, this._batchMethods.Retry(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this._batchMethods.getBatch(batchID_1, guid)]; case 1: return [2 /*return*/, _a.sent()]; } }); }); })]; case 2: batch = _a.sent(); pageIDs_1 = []; batch.items.forEach(function (element) { return pageIDs_1.push(element.itemID); }); return [2 /*return*/, pageIDs_1]; case 3: err_9 = _a.sent(); throw new exception_1.Exception("Unable to publish the page for id: " + pageID, err_9); case 4: return [2 /*return*/]; } }); }); }; PageMethods.prototype.unPublishPage = function (pageID, guid, locale, comments, returnBatchId) { if (comments === void 0) { comments = null; } if (returnBatchId === void 0) { returnBatchId = false; } return __awaiter(this, void 0, void 0, function () { var apiPath, resp, batchID_2, batch, pageIDs_2, err_10; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 3, , 4]); apiPath = locale + "/page/" + pageID + "/unpublish?comments=" + comments; return [4 /*yield*/, this._clientInstance.executeGet(apiPath, guid, this._options.token)]; case 1: resp = _a.sent(); batchID_2 = resp.data; // If user wants batchID immediately, return it for custom polling if (returnBatchId) { return [2 /*return*/, [batchID_2]]; } return [4 /*yield*/, this._batchMethods.Retry(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this._batchMethods.getBatch(batchID_2, guid)]; case 1: return [2 /*return*/, _a.sent()]; } }); }); })]; case 2: batch = _a.sent(); pageIDs_2 = []; batch.items.forEach(function (element) { return pageIDs_2.push(element.itemID); }); return [2 /*return*/, pageIDs_2]; case 3: err_10 = _a.sent(); throw new exception_1.Exception("Unable to un-publish the page for id: " + pageID, err_10); case 4: return [2 /*return*/]; } }); }); }; PageMethods.prototype.pageRequestApproval = function (pageID, guid, locale, comments, returnBatchId) { if (comments === void 0) { comments = null; } if (returnBatchId === void 0) { returnBatchId = false; } return __awaiter(this, void 0, void 0, function () { var apiPath, resp, batchID_3, batch, pageIDs_3, err_11; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 3, , 4]); apiPath = locale + "/page/" + pageID + "/request-approval?comments=" + comments; return [4 /*yield*/, this._clientInstance.executeGet(apiPath, guid, this._options.token)]; case 1: resp = _a.sent(); batchID_3 = resp.data; // If user wants batchID immediately, return it for custom polling if (returnBatchId) { return [2 /*return*/, [batchID_3]]; } return [4 /*yield*/, this._batchMethods.Retry(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this._batchMethods.getBatch(batchID_3, guid)]; case 1: return [2 /*return*/, _a.sent()]; } }); }); })]; case 2: batch = _a.sent(); pageIDs_3 = []; batch.items.forEach(function (element) { return pageIDs_3.push(element.itemID); }); return [2 /*return*/, pageIDs_3]; case 3: err_11 = _a.sent(); throw new exception_1.Exception("Unable to request approval the page for id: " + pageID, err_11); case 4: return [2 /*return*/]; } }); }); }; PageMethods.prototype.approvePage = function (pageID, guid, locale, comments, returnBatchId) { if (comments === void 0) { comments = null; } if (returnBatchId === void 0) { returnBatchId = false; } return __awaiter(this, void 0, void 0, function () { var apiPath, resp, batchID_4, batch, pageIDs_4, err_12; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 3, , 4]); apiPath = locale + "/page/" + pageID + "/approve?comments=" + comments; return [4 /*yield*/, this._clientInstance.executeGet(apiPath, guid, this._options.token)]; case 1: resp = _a.sent(); batchID_4 = resp.data; // If user wants batchID immediately, return it for custom polling if (returnBatchId) { return [2 /*return*/, [batchID_4]]; } return [4 /*yield*/, this._batchMethods.Retry(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this._batchMethods.getBatch(batchID_4, guid)]; case 1: return [2 /*return*/, _a.sent()]; } }); }); })]; case 2: batch = _a.sent(); pageIDs_4 = []; batch.items.forEach(function (element) { return pageIDs_4.push(element.itemID); }); return [2 /*return*/, pageIDs_4]; case 3: err_12 = _a.sent(); throw new exception_1.Exception("Unable to approve the page for id: " + pageID, err_12); case 4: return [2 /*return*/]; } }); }); }; PageMethods.prototype.declinePage = function (pageID, guid, locale, comments, returnBatchId) { if (comments === void 0) { comments = null; } if (returnBatchId === void 0) { returnBatchId = false; } return __awaiter(this, void 0, void 0, function () { var apiPath, resp, batchID_5, batch, pageIDs_5, err_13; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 3, , 4]); apiPath = locale + "/page/" + pageID + "/decline?comments=" + comments; return [4 /*yield*/, this._clientInstance.executeGet(apiPath, guid, this._options.token)]; case 1: resp = _a.sent(); batchID_5 = resp.data; // If user wants batchID immediately, return it for custom polling if (returnBatchId) { return [2 /*return*/, [batchID_5]]; } return [4 /*yield*/, this._batchMethods.Retry(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this._batchMethods.getBatch(batchID_5, guid)]; case 1: return [2 /*return*/, _a.sent()]; } }); }); })]; case 2: batch = _a.sent(); pageIDs_5 = []; batch.items.forEach(function (element) { return pageIDs_5.push(element.itemID); }); return [2 /*return*/, pageIDs_5]; case 3: err_13 = _a.sent(); throw new exception_1.Exception("Unable to decline the page for id: " + pageID, err_13); case 4: return [2 /*return*/]; } }); }); }; PageMethods.prototype.deletePage = function (pageID, guid, locale, comments, returnBatchId) { if (comments === void 0) { comments = null; } if (returnBatchId === void 0) { returnBatchId = false; } return __awaiter(this, void 0, void 0, function () { var apiPath, resp, batchID_6, batch, pageIDs_6, err_14; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 3, , 4]); apiPath = locale + "/page/" + pageID + "?comments=" + comments; return [4 /*yield*/, this._clientInstance.executeDelete(apiPath, guid, this._options.token)]; case 1: resp = _a.sent(); batchID_6 = resp.data; // If user wants batchID immediately, return it for custom polling if (returnBatchId) { return [2 /*return*/, [batchID_6]]; } return [4 /*yield*/, this._batchMethods.Retry(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this._batchMethods.getBatch(batchID_6, guid)]; case 1: return [2 /*return*/, _a.sent()]; } }); }); })]; case 2: batch = _a.sent(); pageIDs_6 = []; batch.items.forEach(function (element) { return pageIDs_6.push(element.itemID); }); return [2 /*return*/, pageIDs_6]; case 3: err_14 = _a.sent(); throw new exception_1.Exception("Unable to delete the page for id: " + pageID, err_14); case 4: return [2 /*return*/]; } }); }); }; /** * Save a new page or update an existing page. * @param pageItem The PageItem to save * @param guid The GUID of the user making the request * @param locale The locale of the page * @param parentPageID The ID of the parent page * @param placeBeforePageItemID The ID of the page item to place this page before * @param returnBatchId Whether to return the batch ID immediately * @param pageIDInOtherLocale The ID of the page in the other locale if you need to link it up. * @param otherLocale The other locale to link the page to. * @returns The IDs of the created or updated pages */ PageMethods.prototype.savePage = function (pageItem, guid, locale, parentPageID, placeBeforePageItemID, returnBatchId, pageIDInOtherLocale, otherLocale) { if (parentPageID === void 0) { parentPageID = -1; } if (placeBeforePageItemID === void 0) { placeBeforePageItemID = -1; } if (returnBatchId === void 0) { returnBatchId = false; } if (pageIDInOtherLocale === void 0) { pageIDInOtherLocale = -1; } if (otherLocale === void 0) { otherLocale = null; } return __awaiter(this, void 0, void 0, function () { var apiPath, resp, batchID_7, batch, pageIDs_7, err_15; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 3, , 4]); apiPath = locale + "/page?parentPageID=" + parentPageID + "&placeBeforePageItemID=" + placeBeforePageItemID; if (pageIDInOtherLocale > -1 && otherLocale) { // If we have the other locale and the pageID in that locale, we need to link it up. apiPath += "&pageIDInOtherLocale=" + pageIDInOtherLocale + "&otherLocale=" + otherLocale; } return [4 /*yield*/, this._clientInstance.executePost(apiPath, guid, this._options.token, pageItem)]; case 1: resp = _a.sent(); batchID_7 = resp.data; // If user wants batchID immediately, return it for custom polling if (returnBatchId) { return [2 /*return*/, [batchID_7]]; } return [4 /*yield*/, this._batchMethods.Retry(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this._batchMethods.getBatch(batchID_7, guid)]; case 1: return [2 /*return*/, _a.sent()]; } }); }); })]; case 2: batch = _a.sent(); pageIDs_7 = []; batch.items.forEach(function (element) { return pageIDs_7.push(element.itemID); }); return [2 /*return*/, pageIDs_7]; case 3: err_15 = _a.sent(); throw new exception_1.Exception("Unable to create page. " + err_15, err_15); case 4: return [2 /*return*/]; } }); }); }; PageMethods.prototype.getPageHistory = function (locale, guid, pageID, take, skip) { if (take === void 0) { take = 50; } if (skip === void 0) { skip = 0; } return __awaiter(this, void 0, void 0, function () { var apiPath, resp, err_16; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); apiPath = locale + "/item/" + pageID + "/history?take=" + take + "&skip=" + skip; return [4 /*yield*/, this._clientInstance.executeGet(apiPath, guid, this._options.token)]; case 1: resp = _a.sent(); return [2 /*return*/, resp.data]; case 2: err_16 = _a.sent(); throw new exception_1.Exception("Unable to retrieve history for pageID: " + pageID); case 3: return [2 /*return*/]; } }); }); }; PageMethods.prototype.getPageComments = function (locale, guid, pageID, take, skip) { if (take === void 0) { take = 50; } if (skip === void 0) { skip = 0; } return __awaiter(this, void 0, void 0, function () { var apiPath, resp, err_17; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); apiPath = locale + "/item/" + pageID + "/history?take=" + take + "&skip=" + skip; return [4 /*yield*/, this._clientInstance.executeGet(apiPath, guid, this._options.token)]; case 1: resp = _a.sent(); return [2 /*return*/, resp.data]; case 2: err_17 = _a.sent(); throw new exception_1.Exception("Unable to retrieve history for pageID: " + pageID); case 3: return [2 /*return*/]; } }); }); }; return PageMethods; }()); exports.PageMethods = PageMethods;