{"version":3,"file":"review-workflows.mjs","sources":["../../../server/src/middlewares/review-workflows.ts"],"sourcesContent":["import type { Context } from 'koa';\nimport type { Core } from '@strapi/types';\n\nimport { set } from 'lodash/fp';\n\n/**\n * A Strapi middleware function that adds support for review workflows.\n *\n * Why is it needed ?\n * For now, the admin panel cannot have anything but top-level attributes in the content-type for options.\n * But we need the CE part to be agnostics from Review Workflow (which is an EE feature).\n * CE handle the `options` object, that's why we move the reviewWorkflows boolean to the options object.\n *\n * @param {object} strapi - The Strapi instance.\n */\nexport function contentTypeMiddleware(strapi: Core.Strapi) {\n  /**\n   * A middleware function that moves the `reviewWorkflows` attribute from the top level of\n   * the request body to the `options` object within the request body.\n   *\n   * @param {object} ctx - The Koa context object.\n   */\n  const moveReviewWorkflowOption = (ctx: Context) => {\n    // Move reviewWorkflows to options.reviewWorkflows\n    const { reviewWorkflows, ...contentType } = ctx.request.body.contentType;\n\n    if (typeof reviewWorkflows === 'boolean') {\n      ctx.request.body.contentType = set('options.reviewWorkflows', reviewWorkflows, contentType);\n    }\n  };\n  strapi.server.router.use('/content-type-builder/content-types/:uid?', (ctx, next) => {\n    if (ctx.method === 'PUT' || ctx.method === 'POST') {\n      moveReviewWorkflowOption(ctx);\n    }\n    return next();\n  });\n}\n\nexport default {\n  contentTypeMiddleware,\n};\n"],"names":["contentTypeMiddleware","strapi","moveReviewWorkflowOption","ctx","reviewWorkflows","contentType","request","body","set","server","router","use","next","method"],"mappings":";;AAKA;;;;;;;;;IAUO,SAASA,qBAAAA,CAAsBC,MAAmB,EAAA;AACvD;;;;;MAMA,MAAMC,2BAA2B,CAACC,GAAAA,GAAAA;;QAEhC,MAAM,EAAEC,eAAe,EAAE,GAAGC,WAAAA,EAAa,GAAGF,GAAAA,CAAIG,OAAO,CAACC,IAAI,CAACF,WAAW;QAExE,IAAI,OAAOD,oBAAoB,SAAA,EAAW;YACxCD,GAAAA,CAAIG,OAAO,CAACC,IAAI,CAACF,WAAW,GAAGG,GAAAA,CAAI,2BAA2BJ,eAAAA,EAAiBC,WAAAA,CAAAA;AACjF,QAAA;AACF,IAAA,CAAA;IACAJ,MAAAA,CAAOQ,MAAM,CAACC,MAAM,CAACC,GAAG,CAAC,2CAAA,EAA6C,CAACR,GAAAA,EAAKS,IAAAA,GAAAA;AAC1E,QAAA,IAAIT,IAAIU,MAAM,KAAK,SAASV,GAAAA,CAAIU,MAAM,KAAK,MAAA,EAAQ;YACjDX,wBAAAA,CAAyBC,GAAAA,CAAAA;AAC3B,QAAA;QACA,OAAOS,IAAAA,EAAAA;AACT,IAAA,CAAA,CAAA;AACF;AAEA,iCAAe;AACbZ,IAAAA;AACF,CAAA;;;;"}