@contentstack/management
Version:
The Content Management API is used to manage the content of your Contentstack account
104 lines (102 loc) • 4.29 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
import cloneDeep from 'lodash/cloneDeep';
import error from '../../core/contentstackError';
import { fetchAll } from '../../entity';
/**
*
* @namespace AuditLog
*/
export function AuditLog(http) {
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
this.stackHeaders = data.stackHeaders;
this.urlPath = "/audit-logs";
if (data.logs) {
Object.assign(this, cloneDeep(data.logs));
this.urlPath = "/audit-logs/".concat(this.uid);
/**
* @description The fetch AuditLog call fetches AuditLog details.
* @memberof AuditLog
* @func fetch
* @returns {Promise<Object>} Promise for AuditLog data
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).auditLog('audit_log_item_uid').fetch()
* .then((log) => console.log(log))
*
*/
this.fetch = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
var param,
headers,
response,
_args = arguments,
_t;
return _regeneratorRuntime.wrap(function (_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
param = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
_context.prev = 1;
headers = {
headers: _objectSpread({}, cloneDeep(this.stackHeaders)),
params: _objectSpread({}, cloneDeep(param))
} || {};
_context.next = 2;
return http.get(this.urlPath, headers);
case 2:
response = _context.sent;
if (!response.data) {
_context.next = 3;
break;
}
return _context.abrupt("return", response.data);
case 3:
throw error(response);
case 4:
_context.next = 6;
break;
case 5:
_context.prev = 5;
_t = _context["catch"](1);
throw error(_t);
case 6:
case "end":
return _context.stop();
}
}, _callee, this, [[1, 5]]);
}));
} else {
/**
* @description The Get all AuditLog request retrieves the details of all the AuditLog entries of a stack.
* @memberof AuditLog
* @func fetchAll
* @param {Number} limit The limit parameter will return a specific number of AuditLog entries in the output.
* @param {Number} skip The skip parameter will skip a specific number of AuditLog entries in the output.
* @param {Boolean} include_count - To retrieve the count of AuditLog entries.
* @returns {Promise<ContentstackCollection>} Promise for ContentstackCollection instance.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).auditLog().fetchAll()
* .then((logs) => console.log(logs))
*
*/
this.fetchAll = fetchAll(http, LogCollection);
}
return this;
}
export function LogCollection(http, data) {
var obj = cloneDeep(data.logs) || [];
var logCollection = obj.map(function (userdata) {
return new AuditLog(http, {
logs: userdata,
stackHeaders: data.stackHeaders
});
});
return logCollection;
}