text: (()=>{"use strict";var t={430:function(t){var e=this&&this.__awaiter||function(t,e,n,o){function adopt(t){return t instanceof n?t:new n((function(e){e(t)}))}return new(n||(n=Promise))((function(n,s){function fulfilled(t){try{step(o.next(t))}catch(t){s(t)}}function rejected(t){try{step(o["throw"](t))}catch(t){s(t)}}function step(t){t.done?n(t.value):adopt(t.value).then(fulfilled,rejected)}step((o=o.apply(t,e||[])).next())}))};const n="https://contentful-app.chec.io";const handler=(t,o)=>e(void 0,void 0,void 0,(function*(){if(t.body.event==="integrations.create"){return{statusCode:202,body:""}}if(t.body.event!=="integrations.ready"){return{statusCode:400,body:"The event that triggered this integration is unsupported."}}const s=yield o.integration();const i=s.config;const r=i.selectedSpaces.reduce(((t,e)=>{const n=e.match(/^o:([a-zA-Z0-9-_.]{1,64})==s:([a-zA-Z0-9-_.]{1,64})$/);if(!n){return t}const[o,s,i]=n;const r=Object.hasOwnProperty.call(t,s)?t[s]:[];return Object.assign(Object.assign({},t),{[s]:[...r,i]})}),{});const c={};const a={responseType:"json",headers:{Authorization:`Bearer ${i.contentManagementApiKey}`,"Content-Type":"application/vnd.contentful.management.v1+json"}};const d=Object.keys(r).map((t=>e(void 0,void 0,void 0,(function*(){const e=`https://api.contentful.com/organizations/${t}/app_definitions`;const{items:s}=yield o.got(e,a).json();const i=s.find((t=>t.src.startsWith(n)));if(i){c[t]=i;return}const r=Object.assign(Object.assign({},a),{method:"POST",json:{name:"Commerce.js App",src:n,locations:[{location:"app-config"},{location:"entry-field",fieldTypes:[{type:"Symbol"},{type:"Array",items:{type:"Symbol"}}]},{location:"dialog"}]}});const d=yield o.got(e,r);if(d.statusCode!==201){throw new Error(JSON.stringify(d.body))}c[t]=d.body}))));try{yield Promise.all(d)}catch(t){return{statusCode:500,body:`An error occurred creating Contentful app definitions: ${t.message}`}}const u=Object.entries(r).reduce(((t,[n,s])=>t.concat(s.map((t=>e(void 0,void 0,void 0,(function*(){const e=c[n];const s=`https://api.contentful.com/spaces/${t}/environments/${i.environmentName}/app_installations/${e.sys.id}`;const r=Object.assign(Object.assign({},a),{method:"PUT",json:{parameters:{publicKey:o.publicKey}}});const d=yield o.got(s,r);if(d.statusCode<200||d.statusCode>=300){throw new Error(JSON.stringify(d.body))}return d.body})))))),[]);yield Promise.all(u);o.store.set("installed",true);return{statusCode:200,body:"Successfully installed Commerce.js for Contentful to the configured spaces"}}));t.exports=handler}};var e={};function __nccwpck_require__(n){var o=e[n];if(o!==undefined){return o.exports}var s=e[n]={exports:{}};var i=true;try{t[n].call(s.exports,s,s.exports,__nccwpck_require__);i=false}finally{if(i)delete e[n]}return s.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var n=__nccwpck_require__(430);module.exports=n})();