UNPKG

contentful-management

Version:
88 lines 2.88 kB
import { freezeSys, toPlainObject } from 'contentful-sdk-core'; import copy from 'fast-copy'; import { wrapCollection } from '../common-utils'; import enhanceWithMethods from '../enhance-with-methods'; import { wrapAiActionInvocation } from './ai-action-invocation'; export let StatusFilter = /*#__PURE__*/function (StatusFilter) { StatusFilter["ALL"] = "all"; StatusFilter["PUBLISHED"] = "published"; return StatusFilter; }({}); export let VariableType = /*#__PURE__*/function (VariableType) { VariableType["RESOURCE_LINK"] = "ResourceLink"; VariableType["TEXT"] = "Text"; VariableType["STANDARD_INPUT"] = "StandardInput"; VariableType["LOCALE"] = "Locale"; VariableType["MEDIA_REFERENCE"] = "MediaReference"; VariableType["REFERENCE"] = "Reference"; VariableType["SMART_CONTEXT"] = "SmartContext"; return VariableType; }({}); export let EntityTypeEntry = /*#__PURE__*/function (EntityTypeEntry) { EntityTypeEntry["ENTRY"] = "Entry"; return EntityTypeEntry; }({}); function createAiActionApi(makeRequest) { const getParams = data => ({ spaceId: data.sys.space.sys.id, aiActionId: data.sys.id }); return { update: function update() { const self = this; return makeRequest({ entityType: 'AiAction', action: 'update', params: getParams(self), payload: self }).then(data => wrapAiAction(makeRequest, data)); }, delete: function del() { const self = this; return makeRequest({ entityType: 'AiAction', action: 'delete', params: getParams(self) }); }, publish: function publish() { const self = this; return makeRequest({ entityType: 'AiAction', action: 'publish', params: { aiActionId: self.sys.id, spaceId: self.sys.space.sys.id, version: self.sys.version } }).then(data => wrapAiAction(makeRequest, data)); }, unpublish: function unpublish() { const self = this; return makeRequest({ entityType: 'AiAction', action: 'unpublish', params: getParams(self) }).then(data => wrapAiAction(makeRequest, data)); }, invoke: function invoke(environmentId, payload) { const self = this; return makeRequest({ entityType: 'AiAction', action: 'invoke', params: { spaceId: self.sys.space.sys.id, environmentId, aiActionId: self.sys.id }, payload }).then(data => wrapAiActionInvocation(makeRequest, data)); } }; } export function wrapAiAction(makeRequest, data) { const aiAction = toPlainObject(copy(data)); const aiActionWithMethods = enhanceWithMethods(aiAction, createAiActionApi(makeRequest)); return freezeSys(aiActionWithMethods); } export const wrapAiActionCollection = wrapCollection(wrapAiAction);