@agility/management-sdk
Version:
Agility CMS Tyescript SDK for Management API.
459 lines (458 loc) • 26.1 kB
JavaScript
"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.ContentMethods = void 0;
var clientInstance_1 = require("./clientInstance");
var batchMethods_1 = require("./batchMethods");
var exception_1 = require("../models/exception");
var ContentMethods = /** @class */ (function () {
function ContentMethods(options) {
this._options = options;
this._clientInstance = new clientInstance_1.ClientInstance(this._options);
this._batchMethods = new batchMethods_1.BatchMethods(this._options);
}
ContentMethods.prototype.getContentItem = function (contentID, 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 + "/item/" + contentID;
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 the content for id: " + contentID, err_1);
case 3: return [2 /*return*/];
}
});
});
};
ContentMethods.prototype.publishContent = function (contentID, 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, contentIDs_1, err_2;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 3, , 4]);
apiPath = locale + "/item/" + contentID + "/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();
contentIDs_1 = [];
batch.items.forEach(function (element) { return contentIDs_1.push(element.itemID); });
return [2 /*return*/, contentIDs_1];
case 3:
err_2 = _a.sent();
throw new exception_1.Exception("Unable to publish the content for id: " + contentID, err_2);
case 4: return [2 /*return*/];
}
});
});
};
ContentMethods.prototype.unPublishContent = function (contentID, 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, contentIDs_2, err_3;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 3, , 4]);
apiPath = locale + "/item/" + contentID + "/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();
contentIDs_2 = [];
batch.items.forEach(function (element) { return contentIDs_2.push(element.itemID); });
return [2 /*return*/, contentIDs_2];
case 3:
err_3 = _a.sent();
throw new exception_1.Exception("Unable to un-publish the content for id: " + contentID, err_3);
case 4: return [2 /*return*/];
}
});
});
};
ContentMethods.prototype.contentRequestApproval = function (contentID, 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, contentIDs_3, err_4;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 3, , 4]);
apiPath = locale + "/item/" + contentID + "/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();
contentIDs_3 = [];
batch.items.forEach(function (element) { return contentIDs_3.push(element.itemID); });
return [2 /*return*/, contentIDs_3];
case 3:
err_4 = _a.sent();
throw new exception_1.Exception("Unable to request approval the content for id: " + contentID, err_4);
case 4: return [2 /*return*/];
}
});
});
};
ContentMethods.prototype.approveContent = function (contentID, 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, contentIDs_4, err_5;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 3, , 4]);
apiPath = locale + "/item/" + contentID + "/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();
contentIDs_4 = [];
batch.items.forEach(function (element) { return contentIDs_4.push(element.itemID); });
return [2 /*return*/, contentIDs_4];
case 3:
err_5 = _a.sent();
throw new exception_1.Exception("Unable to approve the content for id: " + contentID, err_5);
case 4: return [2 /*return*/];
}
});
});
};
ContentMethods.prototype.declineContent = function (contentID, 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, contentIDs_5, err_6;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 3, , 4]);
apiPath = locale + "/item/" + contentID + "/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();
contentIDs_5 = [];
batch.items.forEach(function (element) { return contentIDs_5.push(element.itemID); });
return [2 /*return*/, contentIDs_5];
case 3:
err_6 = _a.sent();
throw new exception_1.Exception("Unable to decline the content for id: " + contentID, err_6);
case 4: return [2 /*return*/];
}
});
});
};
ContentMethods.prototype.deleteContent = function (contentID, 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, contentIDs_6, err_7;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 3, , 4]);
apiPath = locale + "/item/" + contentID + "?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();
contentIDs_6 = [];
batch.items.forEach(function (element) { return contentIDs_6.push(element.itemID); });
return [2 /*return*/, contentIDs_6];
case 3:
err_7 = _a.sent();
throw new exception_1.Exception("Unable to delete the content for id: " + contentID, err_7);
case 4: return [2 /*return*/];
}
});
});
};
ContentMethods.prototype.saveContentItem = function (contentItem, guid, locale, returnBatchId) {
if (returnBatchId === void 0) { returnBatchId = false; }
return __awaiter(this, void 0, void 0, function () {
var apiPath, resp, batchID_7, batch, contentIDs_7, err_8;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 3, , 4]);
apiPath = locale + "/item";
return [4 /*yield*/, this._clientInstance.executePost(apiPath, guid, this._options.token, contentItem)];
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();
contentIDs_7 = [];
batch.items.forEach(function (element) { return contentIDs_7.push(element.itemID); });
return [2 /*return*/, contentIDs_7];
case 3:
err_8 = _a.sent();
throw new exception_1.Exception('Unable to create content.', err_8);
case 4: return [2 /*return*/];
}
});
});
};
ContentMethods.prototype.saveContentItems = function (contentItems, guid, locale, returnBatchId) {
if (returnBatchId === void 0) { returnBatchId = false; }
return __awaiter(this, void 0, void 0, function () {
var apiPath, resp, batchID_8, batch, contentIDs_8, err_9;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 3, , 4]);
apiPath = locale + "/item/multi";
return [4 /*yield*/, this._clientInstance.executePost(apiPath, guid, this._options.token, contentItems)];
case 1:
resp = _a.sent();
batchID_8 = resp.data;
// If user wants batchID immediately, return it for custom polling
if (returnBatchId) {
return [2 /*return*/, [batchID_8]];
}
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_8, guid)];
case 1: return [2 /*return*/, _a.sent()];
}
}); }); })];
case 2:
batch = _a.sent();
contentIDs_8 = [];
batch.items.forEach(function (element) { return contentIDs_8.push(element.itemID); });
return [2 /*return*/, contentIDs_8];
case 3:
err_9 = _a.sent();
throw new exception_1.Exception('Unable to create contents.', err_9);
case 4: return [2 /*return*/];
}
});
});
};
ContentMethods.prototype.getContentItems = function (referenceName, guid, locale, listParams) {
return __awaiter(this, void 0, void 0, function () {
var apiPath, resp, err_10;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
apiPath = locale + "/list/" + referenceName + "?filter=" + listParams.filter + "&fields=" + listParams.fields + "&sortDirection=" + listParams.sortDirection + "&sortField=" + listParams.sortField + "&take=" + listParams.take + "&skip=" + listParams.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_10 = _a.sent();
throw new exception_1.Exception("Unable retrieve the content details for reference name: " + referenceName, err_10);
case 3: return [2 /*return*/];
}
});
});
};
ContentMethods.prototype.getContentList = function (referenceName, guid, locale, listParams, filterObject) {
if (filterObject === void 0) { filterObject = null; }
return __awaiter(this, void 0, void 0, function () {
var apiPath, resp, err_11;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
apiPath = locale + "/list/" + referenceName + "?fields=" + listParams.fields + "&sortDirection=" + listParams.sortDirection + "&sortField=" + listParams.sortField + "&take=" + listParams.take + "&skip=" + listParams.skip + "&showDeleted=" + listParams.showDeleted;
return [4 /*yield*/, this._clientInstance.executePost(apiPath, guid, this._options.token, filterObject)];
case 1:
resp = _a.sent();
return [2 /*return*/, resp.data];
case 2:
err_11 = _a.sent();
throw new exception_1.Exception("Unable retrieve the content details for list with reference name: " + referenceName, err_11);
case 3: return [2 /*return*/];
}
});
});
};
ContentMethods.prototype.getContentHistory = function (locale, guid, contentID, 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_12;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
apiPath = locale + "/item/" + contentID + "/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_12 = _a.sent();
throw new exception_1.Exception("Unable to retrieve history for contentID: " + contentID);
case 3: return [2 /*return*/];
}
});
});
};
ContentMethods.prototype.getContentComments = function (locale, guid, contentID, 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_13;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
apiPath = locale + "/item/" + contentID + "/comments?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_13 = _a.sent();
throw new exception_1.Exception("Unable to retrieve comments for contentID: " + contentID);
case 3: return [2 /*return*/];
}
});
});
};
return ContentMethods;
}());
exports.ContentMethods = ContentMethods;