UNPKG

contentful-management

Version:
54 lines (51 loc) 1.81 kB
import { toPlainObject, freezeSys } from 'contentful-sdk-core'; import copy from 'fast-copy'; import { wrapCollection } from '../common-utils.js'; import { pollAsyncActionStatus } from '../methods/action.js'; import enhanceWithMethods from '../enhance-with-methods.js'; /* eslint-disable @typescript-eslint/no-explicit-any */ /** * @internal */ function createReleaseActionApi(makeRequest) { const getParams = (self) => { const action = self.toPlainObject(); return { spaceId: action.sys.space.sys.id, environmentId: action.sys.environment.sys.id, releaseId: action.sys.release.sys.id, actionId: action.sys.id, }; }; return { async get() { const params = getParams(this); return makeRequest({ entityType: 'ReleaseAction', action: 'get', params, }).then((releaseAction) => wrapReleaseAction(makeRequest, releaseAction)); }, /** Waits for a Release Action to complete */ async waitProcessing(options) { return pollAsyncActionStatus(async () => this.get(), options); }, }; } /** * @internal * @param makeRequest - function to make requests via an adapter * @param data - Raw Release data * @returns Wrapped Release data */ function wrapReleaseAction(makeRequest, data) { const releaseAction = toPlainObject(copy(data)); const releaseActionWithApiMethods = enhanceWithMethods(releaseAction, createReleaseActionApi(makeRequest)); return freezeSys(releaseActionWithApiMethods); } /** * @internal */ const wrapReleaseActionCollection = wrapCollection(wrapReleaseAction); export { wrapReleaseAction, wrapReleaseActionCollection }; //# sourceMappingURL=release-action.js.map