'use strict'; var api = require('@flatfile/api'); var pluginJobHandler = require('@flatfile/plugin-job-handler'); var utilCommon = require('@flatfile/util-common'); var i=new api.FlatfileClient;function j(){return l=>{l.on("job:completed",{job:"workbook:map"},async({context:{jobId:r,workbookId:t}})=>{await i.jobs.create({type:"workbook",operation:"viewMappedFieldsOnly",source:t,trigger:"immediate",mode:"foreground",input:{mappingJobId:r}});}),l.use(pluginJobHandler.jobHandler("workbook:viewMappedFieldsOnly",async(r,t)=>{let{jobId:m,workbookId:p}=r.context;try{await t(10,"Updating the table to only view mapped fields");let c=(await i.jobs.get(m)).data.input.mappingJobId,s=await i.jobs.getExecutionPlan(c),f=[];for(let e=0;e{e.config.fields.forEach(o=>{f.includes(o.key)&&(o.metadata={mapped:!0});});});let g=n.sheets.map(e=>{let o=e.config.fields.filter(a=>a.metadata&&a.metadata.mapped===!0);return o.length>0?o:null});await t(50,"Halfway there, hang tight...");let w=n.sheets.map((e,o)=>{let a=g[o];return a?{...e,config:{...e.config,fields:a}}:e});return await t(80,"Almost done..."),await i.workbooks.update(p,{...n,sheets:w}),{outcome:{message:"Table update complete. Please audit the data",acknowledge:!1}}}catch(d){throw utilCommon.logError("@flatfile/plugin-view-mapped",JSON.stringify(d,null,2)),new Error("An error occured while updating the workbook. See Event Logs.")}}));}} exports.viewMappedPlugin = j; //# sourceMappingURL=index.cjs.map //# sourceMappingURL=index.cjs.map