@kizenapps/cli 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-4OYGMEFM.js +3675 -0
- package/dist/chunk-4OYGMEFM.js.map +1 -0
- package/dist/chunk-4Z6S6LWP.js +6134 -0
- package/dist/chunk-4Z6S6LWP.js.map +1 -0
- package/dist/chunk-5WPGAZLP.js +6136 -0
- package/dist/chunk-5WPGAZLP.js.map +1 -0
- package/dist/chunk-6XGFZ4W5.js +3673 -0
- package/dist/chunk-6XGFZ4W5.js.map +1 -0
- package/dist/chunk-KMKDY2I6.js +46 -0
- package/dist/chunk-KMKDY2I6.js.map +1 -0
- package/dist/chunk-LSHHXCC6.js +3639 -0
- package/dist/chunk-LSHHXCC6.js.map +1 -0
- package/dist/chunk-NNDSADQG.js +3641 -0
- package/dist/chunk-NNDSADQG.js.map +1 -0
- package/dist/chunk-SEGVTWSK.js +44 -0
- package/dist/chunk-SEGVTWSK.js.map +1 -0
- package/dist/devtools-HNR7DD7Q.js +68 -0
- package/dist/devtools-HNR7DD7Q.js.map +1 -0
- package/dist/devtools-HW3UQAHH.js +69 -0
- package/dist/devtools-HW3UQAHH.js.map +1 -0
- package/dist/devtools-KXIXZGBY.js +64 -0
- package/dist/devtools-KXIXZGBY.js.map +1 -0
- package/dist/devtools-PDXM3L35.js +67 -0
- package/dist/devtools-PDXM3L35.js.map +1 -0
- package/dist/devtools-SDEASRYI.js +66 -0
- package/dist/devtools-SDEASRYI.js.map +1 -0
- package/dist/devtools-XBEEGBQ4.js +66 -0
- package/dist/devtools-XBEEGBQ4.js.map +1 -0
- package/dist/dist-4P5P64FK.js +8474 -0
- package/dist/dist-4P5P64FK.js.map +1 -0
- package/dist/dist-AVHDSU4X.js +137 -0
- package/dist/dist-AVHDSU4X.js.map +1 -0
- package/dist/dist-NUJOSN7W.js +8472 -0
- package/dist/dist-NUJOSN7W.js.map +1 -0
- package/dist/dist-QHDMIBVE.js +135 -0
- package/dist/dist-QHDMIBVE.js.map +1 -0
- package/dist/electron/icon.png +0 -0
- package/dist/electron/main.js +45 -3
- package/dist/electron/main.js.map +1 -1
- package/dist/electron/preload.cjs +5 -0
- package/dist/gzip-size-K37OQCQ2.js +137 -0
- package/dist/gzip-size-K37OQCQ2.js.map +1 -0
- package/dist/gzip-size-SHZBT5GU.js +139 -0
- package/dist/gzip-size-SHZBT5GU.js.map +1 -0
- package/dist/index.js +577 -168
- package/dist/index.js.map +1 -1
- package/dist/viewer/assets/calendarSource.worker-C9iglnKD.js +24 -0
- package/dist/viewer/assets/expression.worker-Cin-WNVB.js +5 -0
- package/dist/viewer/assets/floatingFrame.worker-CWLtchq3.js +23 -0
- package/dist/viewer/assets/generic.worker-DRXu0-5B.js +23 -0
- package/dist/viewer/assets/index-BERinSUs.css +2 -0
- package/dist/viewer/assets/index-BExFCUNb.js +582 -0
- package/dist/viewer/assets/index-BTnaSAbf.js +582 -0
- package/dist/viewer/assets/index-BsYWmcLM.css +2 -0
- package/dist/viewer/assets/index-C9gGMSH0.js +582 -0
- package/dist/viewer/assets/index-CGp_x2sR.js +582 -0
- package/dist/viewer/assets/index-D1lc5mUR.js +582 -0
- package/dist/viewer/assets/index-DBXDPp8Y.css +2 -0
- package/dist/viewer/assets/index-DUFimvi2.js +582 -0
- package/dist/viewer/assets/index-DVM12um9.js +582 -0
- package/dist/viewer/assets/index-DiwdXOw0.css +2 -0
- package/dist/viewer/assets/index-DxGbfW9l.js +582 -0
- package/dist/viewer/assets/index-o7N1iv71.js +582 -0
- package/dist/viewer/assets/index-wLgWfI8W.js +582 -0
- package/dist/viewer/assets/recordDetail.worker-BIHPFt8Y.js +23 -0
- package/dist/viewer/icon.png +0 -0
- package/dist/viewer/index.html +2 -2
- package/package.json +17 -13
- package/dist/viewer/assets/calendarSource.worker-DF0wAwJR.js +0 -24
- package/dist/viewer/assets/expression.worker-_W4VR2xe.js +0 -5
- package/dist/viewer/assets/floatingFrame.worker-DXcDBfqJ.js +0 -23
- package/dist/viewer/assets/generic.worker-CsqlYndL.js +0 -23
- package/dist/viewer/assets/index-CW_UqFf3.css +0 -1
- package/dist/viewer/assets/index-DaB01Qok.js +0 -637
- package/dist/viewer/assets/recordDetail.worker-Ccm59Np6.js +0 -23
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
var re=Object.defineProperty;var se=(u,E,y)=>E in u?re(u,E,{enumerable:!0,configurable:!0,writable:!0,value:y}):u[E]=y;var c=(u,E,y)=>se(u,typeof E!="symbol"?E+"":E,y);(function(){"use strict";var u={QUERY_REQUEST:"query:request",UI_OUTPUT:"outputui",IFRAME_OUTPUT:"iframeoutput",POSTFORMDATA_REQUEST:"postformdata:request",SETSTATE:"setstate",DONE:"done",RUN:"run",OPEN_WINDOW:"openwindow",COMMUNICATE:"communicate",OPEN_CREATE_RECORD_MODAL_REQUEST:"opencreaterecordmodal:request",OPEN_CREATE_RELATED_RECORD_MODAL_REQUEST:"opencreaterelatedrecordmodal:request",SHOW_TOAST:"showtoast",CLEAR_TOASTS:"cleartoasts",REFRESH_TIMELINE:"refreshtimeline",REFRESH_ENTITY:"refreshentity",UPLOADFILE_REQUEST:"uploadfile:request",UPDATE_SESSION_DATA:"updatesessiondata",INSTALL_THIRD_PARTY_SCRIPT_REQUEST:"installthirdpartyscript:request",PROMPT_REQUEST:"prompt:request",DYNAMIC_PROMPT_REQUEST:"dynamicprompt:request",RELEASE_BLOCKING_SCRIPT:"releaseblockingscript",AUTHORIZE:"authorize",COPY_TO_CLIPBOARD:"copytoclipboard"},E={QUERY_RESPONSE:"query:response",POSTFORMDATA_RESPONSE:"postformdata:response",ERROR:"error",UPLOADFILE_RESPONSE:"uploadfile:response",INSTALL_THIRD_PARTY_SCRIPT_RESPONSE:"installthirdpartyscript:response",PROMPT_RESPONSE:"prompt:response",REFRESH_ENTITY_RESPONSE:"refreshentity:response",CREATE_RECORD_RESPONSE:"createrecord:response",CREATE_RELATED_RECORD_RESPONSE:"createrelatedrecord:response"},y={RUN_FRAME_SCRIPT:"runframescript",SEND_MESSAGE_TO_FRAME:"sendmessagetoframe",CALL_THIRD_PARTY_SCRIPT:"callthirdpartyscript"},P=/https:\/\/.*widget\.freshworks\.com\/.*\.js/,N=/https:\/\/widget\.intercom\.io\/widget\/[a-z0-9]+/,T={FRESHWORKS:"freshworks",INTERCOM:"intercom"},I=e=>{if(P.test(e))return T.FRESHWORKS;if(N.test(e))return T.INTERCOM},C=class{constructor(e,t){c(this,"instance");c(this,"scriptUrl");c(this,"integration");this.instance=e,this.scriptUrl=t;const r=I(t);if(r)this.integration=r;else throw new Error(`Error: Disallowed script url: ${t}`)}get type(){return this.integration}call(...e){this.instance.postMessage(JSON.stringify({action:u.COMMUNICATE,type:y.CALL_THIRD_PARTY_SCRIPT,eventName:`thirdParty:${y.CALL_THIRD_PARTY_SCRIPT}`,recipient:{script:this.scriptUrl,type:this.type},params:e}))}},A=e=>({key:`action__${e.api_name}`,type:"custom_object",label:e.name,allow_multiple:!0}),w=(e,t)=>{var l;const r=(e.fields??[]).filter(i=>i.type!=="container"&&i.type!=="description").map(i=>({...i,when:t?`(${t}) && (${i.when??"true"})`:i.when})),n=(e.fields??[]).filter(i=>i.type==="container").flatMap(i=>w(i,i.when)),a=((l=e.actions)==null?void 0:l.filter(i=>i.hint_object_name))??[];return[...r,...n,...a.map(i=>({...A(i),match_hint:i.hint_object_name??""}))]},v=(e,t)=>{const s=w(e).reduce((l,i)=>({...l,[i.key]:i}),{}),n=Object.keys(t),a={};return n.forEach(l=>{var d,g;const i=t[l],h=s[l];if(h!=null&&h.type){switch(h.type){case"boolean":const f=i;if(!f)return;a[l]=f.value;return;case"custom_object":{const o=i;if(!o)return;a[l]={objectId:(d=o.value)==null?void 0:d.id,objectName:(g=o.value)==null?void 0:g.objectName};return}case"field":{const o=i;if(!(o!=null&&o.value))return;Array.isArray(o.value)?a[l]=o.value.map(p=>{var R,O;return{fieldId:p.value,fieldName:p.label,objectId:(R=o.associatedObject)==null?void 0:R.id,objectName:(O=o.associatedObject)==null?void 0:O.name}}):typeof o.value=="object"&&typeof o.associatedObject=="object"&&(a[l]={fieldId:o.value.value,fieldName:o.value.label,objectId:o.associatedObject.id,objectName:o.associatedObject.name});return}case"number":{const o=i;if(!o)return;try{const p=Number(o.value);if(!p&&p!==0)return;a[l]=p}catch{a[l]=NaN}return}case"select":{const o=i;if(!o)return;a[l]=o.value;return}case"text":{const o=i,p=o==null?void 0:o.value;if(p){a[l]=p;return}const R=h.default;R&&(a[l]=R);return}case"description":case"container":return}return i==null?void 0:i.value}}),a},D=(e,t)=>r=>async(s,n,a)=>new Promise((l,i)=>{const h=t.register(l,i);e.postMessage(JSON.stringify({action:u.QUERY_REQUEST,id:h,method:r,url:s,payload:n,options:a}))}),M=(e,t)=>(r,s,n=!0)=>new Promise((a,l)=>{const i=t.register(a,l);e.postMessage(JSON.stringify({action:u.POSTFORMDATA_REQUEST,url:r,id:i,payload:s,createNewTab:n}))}),j=(e,t)=>r=>new Promise((s,n)=>{const a=t.register(s,n);e.postMessage(JSON.stringify({action:u.PROMPT_REQUEST,id:a,config:r}))}),x=(e,t)=>r=>new Promise((s,n)=>{const a=t.register(s,n);e.postMessage(JSON.stringify({action:u.DYNAMIC_PROMPT_REQUEST,id:a,config:r}))}),U=(e,t)=>r=>new Promise((s,n)=>{const a=t.register(s,n);e.postMessage(JSON.stringify({action:u.UPLOADFILE_REQUEST,id:a,payload:r}))}),H=(e,t)=>(r,s)=>new Promise((n,a)=>{const l=t.register(n,a);e.postMessage(JSON.stringify({action:u.INSTALL_THIRD_PARTY_SCRIPT_REQUEST,url:r,id:l,args:s}))}),F=(e,t)=>r=>new Promise((s,n)=>{const a=t.register(s,n);e.postMessage(JSON.stringify({action:u.REFRESH_ENTITY,id:a,entityId:r}))}),L=(e,t)=>r=>new Promise((s,n)=>{const a=t.register(s,n);e.postMessage(JSON.stringify({action:u.OPEN_CREATE_RECORD_MODAL_REQUEST,id:a,entityId:r}))}),$=(e,t)=>(r,s)=>new Promise((n,a)=>{const l=t.register(n,a);e.postMessage(JSON.stringify({action:u.OPEN_CREATE_RELATED_RECORD_MODAL_REQUEST,id:l,objectId:r,relatedEntityId:s}))}),J=(e,t,r)=>{switch(e){case E.QUERY_RESPONSE:{const{id:s,data:n,error:a}=JSON.parse(t.data);a?r.reject(s,a):r.resolve(s,n);break}case E.POSTFORMDATA_RESPONSE:{const{id:s,success:n}=JSON.parse(t.data);n?r.resolve(s):r.reject(s);break}case E.UPLOADFILE_RESPONSE:{const{id:s,data:n,error:a}=JSON.parse(t.data);n?r.resolve(s,n):r.reject(s,a);break}case E.INSTALL_THIRD_PARTY_SCRIPT_RESPONSE:{const{id:s,data:n}=JSON.parse(t.data);n.success?r.resolve(s,n):r.reject(s);break}case E.PROMPT_RESPONSE:{const{id:s,data:n}=JSON.parse(t.data);r.resolve(s,n);break}case E.CREATE_RECORD_RESPONSE:{const{id:s,data:n}=JSON.parse(t.data);r.resolve(s,n);break}case E.CREATE_RELATED_RECORD_RESPONSE:{const{id:s,data:n}=JSON.parse(t.data);r.resolve(s,n);break}case E.REFRESH_ENTITY_RESPONSE:{const{id:s,data:n}=JSON.parse(t.data);n.success?r.resolve(s,!0):r.reject(s);break}}},k=`integration:${y.RUN_FRAME_SCRIPT}`,B=class{constructor(e){c(this,"instance");this.instance=e}runFrameScript(e,t,r){this.instance.postMessage(JSON.stringify({action:u.COMMUNICATE,type:y.RUN_FRAME_SCRIPT,eventName:k,recipient:{frame:e,script:t},args:r}))}sendMessageToOwnFrame(e,t){this.instance.postMessage(JSON.stringify({action:u.COMMUNICATE,type:y.SEND_MESSAGE_TO_FRAME,args:{payload:e,path:t}}))}},_=async e=>{let t=null;try{t=await e.json()}catch{}return{status:e.status,statusText:e.statusText,body:t}},S=(e,t,r={},s="")=>{const a=`(${e.toString()})({ state: {{${t}}}, args: ${JSON.stringify(r)}, utils: __kizen_utils })`;return`(function() { ${s}
|
|
2
|
-
return ${a}; })()`},Y=class{constructor({user:e,teamMember:t,business:r,clientObject:s,appPath:n,isDebug:a,kizenRequest:l,postFormData:i,scriptBody:h,instance:d,args:g,uploadFile:f,sessionData:o,pluginComponentId:p,installThirdPartyScript:R,prompt:O,refreshEntity:V,openCreateRecord:K,openCreateRelatedRecord:Z,pluginApiName:X,dynamicPrompt:ee,location:te}){c(this,"user");c(this,"teamMember");c(this,"business");c(this,"clientObject");c(this,"appPath");c(this,"dataCache",new Map);c(this,"queryOptions",{});c(this,"api");c(this,"postFormData");c(this,"executionTimer",0);c(this,"setupExecutions",0);c(this,"cleanupExecutions",0);c(this,"isDebug",!1);c(this,"scriptBody");c(this,"internalState",{indicator:"none"});c(this,"console",console);c(this,"instance");c(this,"breakOnException",!1);c(this,"args");c(this,"communicate");c(this,"shouldPreserve",!1);c(this,"uploadFileHandler");c(this,"internalSessionData");c(this,"pluginComponentId");c(this,"installThirdPartyScriptHandler");c(this,"promptHandler");c(this,"dynamicPromptHandler");c(this,"refreshEntityHandler");c(this,"openCreateRecordHandler");c(this,"openCreateRelatedRecordHandler");c(this,"runnerType");c(this,"pluginApiName");c(this,"tempPromptState",{});c(this,"partialLocation");this.user=e,this.teamMember=t,this.business=r,this.clientObject=s,this.partialLocation=te,this.appPath=n,this.isDebug=a??!1,this.api={get:l("get"),post:l("post"),put:l("put"),delete:l("delete"),patch:l("patch")},this.postFormData=i,this.scriptBody=h,this.instance=d,this.communicate=new B(d),this.uploadFileHandler=f,this.internalSessionData=o??{},this.pluginComponentId=p,this.installThirdPartyScriptHandler=R,this.promptHandler=O,this.refreshEntityHandler=V,this.openCreateRecordHandler=K,this.openCreateRelatedRecordHandler=Z,this.runnerType="base",this.pluginApiName=X,this.dynamicPromptHandler=ee;try{this.args=JSON.parse(g??"{}")}catch{this.args={}}}onError(e){if(this.breakOnException)debugger;this.instance.postMessage(JSON.stringify({action:E.ERROR,error:e==null?void 0:e.message}))}set debug(e){this.isDebug=e,this.breakOnException=e}set preserve(e){this.shouldPreserve=e}get preserve(){return this.shouldPreserve}parseDate(e){return e.split("-")}parsePhone(e){return e.replace(/\+/g,"")}openWindow(e,t="_blank"){this.instance.postMessage(JSON.stringify({action:u.OPEN_WINDOW,url:e,target:t,features:"noopener noreferrer"}))}authorize(e,t={}){if(!e)throw new Error("Service name is required to authorize");this.instance.postMessage(JSON.stringify({action:u.AUTHORIZE,serviceName:e,config:{successRedirectPath:t.successRedirectPath??`/marketplace/${this.pluginApiName}/auth`,errorRedirectPath:t.errorRedirectPath??`/marketplace/${this.pluginApiName}/auth`}}))}getServiceUrl(e,t){if(!e)throw new Error("Service name is required to get a service url");const r=`/external-integrations/proxy/${this.pluginApiName}/${e}`;return t.startsWith("/")?`${r}${t}`:`${r}/${t}`}get currentBusiness(){return this.business}get applicationPath(){return this.appPath}get currentUser(){var e,t,r,s,n,a,l,i;return{profile:{id:((e=this.teamMember)==null?void 0:e.id)??"",full_name:((t=this.teamMember)==null?void 0:t.full_name)??"",first_name:((r=this.teamMember)==null?void 0:r.first_name)??"",last_name:((s=this.teamMember)==null?void 0:s.last_name)??"",email:((n=this.teamMember)==null?void 0:n.email)??"",phone:((a=this.teamMember)==null?void 0:a.phone)??"",created:((l=this.teamMember)==null?void 0:l.created)??"",crm_client_id:((i=this.user)==null?void 0:i.crm_client_id)??""}}}get sessionData(){return this.internalSessionData}get config(){return!this.args.__kizen_clean_config?{}:new Proxy(this.args.__kizen_clean_config??{},{get:(r,s)=>{if(Reflect.has(r,s))return Reflect.get(r,s)}})}get location(){return new Proxy(this.partialLocation,{get:(e,t)=>{if(t==="toJSON")return()=>this.partialLocation;if(Reflect.has(e,t))return Reflect.get(e,t);throw new Error(`Property ${String(t)} is not available on location object for plugin apps`)}})}get userConfig(){var r;const e=(r=this.args.__kizen_user_config)==null?void 0:r.__kizen_clean_config;return e?new Proxy(e,{get:(s,n)=>{if(Reflect.has(s,n))return Reflect.get(s,n)}}):{}}setSessionData(e){if(typeof e!="object")throw new Error(`Invalid session update with type ${typeof e}`);if(Array.isArray(e))throw new Error("Invalid session update with type array");this.internalSessionData={...this.internalSessionData,...e},this.instance.postMessage(JSON.stringify({action:u.UPDATE_SESSION_DATA,update:e}))}async get(e,t){try{if(this.isRelativeUrl(e)){const r=this.dataCache.get(e);if(r&&!(t!=null&&t.ignoreCache))return t!=null&&t.returnErrors?[r.data,null]:r.data;const{data:s}=await this.api.get(e,{...this.queryOptions,headers:this.buildHeaders(t==null?void 0:t.headers)});return this.dataCache.set(e,{ts:Date.now(),data:s}),t!=null&&t.returnErrors?[s,null]:s}else{const r=await fetch(e,{method:"GET",headers:new Headers(t==null?void 0:t.headers),credentials:(t==null?void 0:t.credentials)??"same-origin"});if(!r.ok)throw await _(r);const s=await r.json();return t!=null&&t.returnErrors?[s,null]:s}}catch(r){if(t!=null&&t.returnErrors)return[null,r];this.onError(r)}}async getWithErrors(e,t){return this.get(e,{...t,returnErrors:!0})}async getUserConfig(){var t;if(!this.args.pluginId||!this.pluginComponentId)throw new Error("User config is not available for scripts not associated to a plugin or plugin component");return((t=(await this.get(`/employee/mine/configs/plugins/${this.args.pluginId}`,{ignoreCache:!0})).config)==null?void 0:t[this.pluginComponentId])??{}}async setUserConfig(e){var s;if(!this.args.pluginId||!this.pluginComponentId)throw new Error("User config is not available for scripts not associated to a plugin or plugin component");const t=await this.get(`/employee/mine/configs/plugins/${this.args.pluginId}`,{ignoreCache:!0});return await this.post(`/employee/mine/configs/plugins/${this.args.pluginId}`,{config:{...t==null?void 0:t.config,[this.pluginComponentId]:{...(s=t==null?void 0:t.config)==null?void 0:s[this.pluginComponentId],...e}}})}async patch(e,t,r){try{if(this.isRelativeUrl(e)){const{data:s}=await this.api.patch(e,t,{...this.queryOptions,headers:r==null?void 0:r.headers});return r!=null&&r.returnErrors?[s,null]:s}else{const s=await fetch(e,{method:"PATCH",body:t?JSON.stringify(t):null,headers:new Headers(r==null?void 0:r.headers),credentials:(r==null?void 0:r.credentials)??"same-origin"});if(!s.ok)throw await _(s);const n=await s.json();return r!=null&&r.returnErrors?[n,null]:n}}catch(s){if(r!=null&&r.returnErrors)return[null,s];this.onError(s)}}async patchWithErrors(e,t,r){return this.patch(e,t,{...r,returnErrors:!0})}async post(e,t,r){try{if(this.isRelativeUrl(e)){const{data:s}=await this.api.post(e,t,{...this.queryOptions,headers:this.buildHeaders(r==null?void 0:r.headers)});return r!=null&&r.returnErrors?[s,null]:s}else{const s=await fetch(e,{method:"POST",body:t?JSON.stringify(t):null,headers:new Headers(r==null?void 0:r.headers),credentials:(r==null?void 0:r.credentials)??"same-origin"});if(!s.ok)throw await _(s);const n=await s.json();return r!=null&&r.returnErrors?[n,null]:n}}catch(s){if(r!=null&&r.returnErrors)return[null,s];this.onError(s)}}async postWithErrors(e,t,r){return this.post(e,t,{...r,returnErrors:!0})}async delete(e,t){try{if(this.isRelativeUrl(e)){const{data:r}=await this.api.delete(e,{...this.queryOptions,headers:this.buildHeaders(t==null?void 0:t.headers)});return t!=null&&t.returnErrors?[r,null]:r}else{const r=await fetch(e,{method:"DELETE",headers:new Headers(t==null?void 0:t.headers),credentials:(t==null?void 0:t.credentials)??"same-origin"});if(!r.ok)throw await _(r);let s=null;return r.status!==204&&(s=await r.json()),t!=null&&t.returnErrors?[s,null]:s}}catch(r){if(t!=null&&t.returnErrors)return[null,r];this.onError(r)}}async deleteWithErrors(e,t){return this.delete(e,{...t,returnErrors:!0})}async openCreateRecordModal(e){return this.openCreateRecordHandler(e)}async openCreateRelatedRecordModal(e,t){return this.openCreateRelatedRecordHandler(e,t)}showToast(e,t){this.instance.postMessage(JSON.stringify({action:u.SHOW_TOAST,message:e,toastOptions:t}))}clearToasts(){this.instance.postMessage(JSON.stringify({action:u.CLEAR_TOASTS}))}outputUI(e){this.instance.postMessage(JSON.stringify({action:u.UI_OUTPUT,markup:e}))}prompt(e){return this.promptHandler(e)}async dynamicPrompt(e){var h;const t="__kizen_state";let r=`const __kizen_utils = {};
|
|
3
|
-
`;if(e.registerUtils){const d=Object.keys(e.registerUtils);r+=d.map(g=>{var o;const f=(o=e.registerUtils)==null?void 0:o[g];if(typeof f!="function")throw new Error(`Registered util ${g} is not a function, got ${typeof f}`);return`__kizen_utils["${g}"] = (${f.toString()});`}).join(`
|
|
4
|
-
`)}const s=(h=e.content)==null?void 0:h.map(d=>{let g="";"optionMapper"in d&&(g=S(d.optionMapper,t,d.args,r));let f="";"getFetchUrl"in d&&(f=S(d.getFetchUrl,t,d.args,r));let o="";"getHeaders"in d&&(o=S(d.getHeaders,t,d.args,r));let p="";return"getBody"in d&&(p=S(d.getBody,t,d.args,r)),{...d,optionMapper:g,getFetchUrl:f,getHeaders:o,getBody:p}}),n={...e,content:s},a={fields:n.content},l=await this.dynamicPromptHandler(n),i=v(a,l.values);return{...l,values:i}}outputIframe(e,t,r){this.instance.postMessage(JSON.stringify({action:u.IFRAME_OUTPUT,url:e,allow:t,sandbox:r,preserve:this.preserve}))}getBase64EncodedBlob(e){return new Promise((t,r)=>{const s=new FileReader;s.readAsDataURL(e),s.onload=()=>{t(s.result)},s.onerror=n=>{r(n)}})}async uploadFile(e,t,r=!1){const s=await this.getBase64EncodedBlob(e);return await this.uploadFileHandler({file:s,fileName:t??"file_"+String(Date.now()),isPublic:r})}afterSetup(){}__setup(){if(this.setupExecutions!==0)throw new Error("Setup must be called exactly once, and should never be called by a script directly.");if(this.cleanupExecutions!==0)throw new Error("Setup was called after cleanup");this.isDebug&&this.console.log(`Running script:
|
|
5
|
-
|
|
6
|
-
${this.scriptBody}`),this.setupExecutions++,this.executionTimer=performance.now(),this.afterSetup()}__cleanup(e){if(this.cleanupExecutions!==0)throw new Error("Cleanup must be called exactly once, and should never be called by a script directly.");if(this.setupExecutions!==1)throw new Error("Cleanup was called before setup");this.cleanupExecutions++,this.setIndicator("none");const t=performance.now();this.isDebug&&this.console.log(`Script execution took ${String(t-this.executionTimer)}ms`),this.done(this.preserve,e)}setIndicator(e="none"){this.internalState.indicator=e,this.setState({indicator:e})}wait(e){return new Promise(t=>setTimeout(t,e))}done(e,t){this.instance.postMessage(JSON.stringify({action:u.DONE,result:t,preserve:e}))}setState(e){this.instance.postMessage(JSON.stringify({action:u.SETSTATE,state:e}))}isRelativeUrl(e){return e.startsWith("/")}buildHeaders(e={}){return{...e,"X-Request-Type":"kizen-ui-scripting-api"}}refreshTimelineForId(e){e&&this.instance.postMessage(JSON.stringify({action:u.REFRESH_TIMELINE,entityId:e}))}refreshEntityForId(e){if(e)return this.refreshEntityHandler(e)}async installThirdPartyScript(e){try{const t=await this.installThirdPartyScriptHandler(e,this.args);return new C(this.instance,t.url)}catch{this.onError(new Error(`Third party script ${e} could not be installed.`))}}releaseBlockingScript(){this.instance.postMessage(JSON.stringify({action:u.RELEASE_BLOCKING_SCRIPT}))}copyToClipboard(e){this.instance.postMessage(JSON.stringify({action:u.COPY_TO_CLIPBOARD,text:e}))}createDateObject(e){if(typeof e!="string")throw new Error(`Invalid date string ${String(e)}`);if(!/^\d{4}-\d{2}-\d{2}$/.test(e))throw new Error(`Date string ${e} is not in the format YYYY-MM-DD`);const t=e.split("-").map(s=>parseInt(s,10));if(t.length<3)throw new Error(`Date string ${e} could not be parsed into valid date parts`);return new Date(t[0],t[1]-1,t[2])}formatDateForResponse(e){return e.getTime()}},Q=e=>e.object_type==="pipeline"||e.fetch_url==="pipeline",W=class extends Y{constructor({objectId:t,entityId:r,actionObjectId:s,actionEntityId:n,...a}){super(a);c(this,"objectId");c(this,"entityId");c(this,"actionObjectId");c(this,"actionEntityId");this.objectId=t,this.entityId=r,this.actionObjectId=s,this.actionEntityId=n,this.runnerType="recordDetail"}async currentObject(){if(this.objectId)return this.getObjectDetail(this.objectId)}async currentEntity(){if(this.entityId&&this.objectId)return this.getEntity(this.objectId,this.entityId)}async actionEntity(){if(this.actionEntityId&&this.actionObjectId)return this.getEntity(this.actionObjectId,this.actionEntityId)}getFieldValue(t,r){var s,n;return(n=(s=t.fields)==null?void 0:s[r])==null?void 0:n.value}async getClientEntity(t){return await this.get(`/client/${t}`)}isClientObject(t){var r;return t===((r=this.clientObject)==null?void 0:r.id)}async getEntity(t,r){try{if(this.isClientObject(t))return await this.getClientEntity(r);const s=await this.get(`/custom-objects/${t}`);return Q(s)?await this.getPipelineEntity(t,r):await this.getCustomEntity(t,r)}catch(s){this.onError(s)}}async getRelatedEntitiesForField(t,r,s){var n,a;try{const i=(n=(await this.getEntity(t,r)).fields)==null?void 0:n[s];if(!i)return this.onError(new Error(`Field not found for ID ${s}`)),[];const h=await this.getObjectDetail(t),d=(a=h==null?void 0:h.related_objects)==null?void 0:a.find(o=>o.field_id===i.id);return d?(await Promise.all(i.value.map(o=>o.id===void 0?null:this.getEntity(d.related_object,o.id)).filter(o=>o!==null))).filter(Boolean):(this.onError(new Error("Related object not found")),[])}catch(l){this.onError(l)}return[]}async getPipelineEntity(t,r){return await this.get(`/pipelines/${t}/entity-records/${r}`)}async getCustomEntity(t,r){return await this.get(`/custom-objects/${t}/entity-records/${r}`)}async getObjectDetail(t){try{return await this.get(`/custom-objects/${t}/detail`)}catch(r){this.onError(r)}}refreshTimeline(){this.refreshTimelineForId(this.entityId)}refreshEntity(){this.refreshEntityForId(this.entityId)}},q=()=>{let e=new Date().getTime();return typeof performance<"u"&&typeof performance.now=="function"&&(e+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const r=(e+Math.random()*16)%16|0;return e=Math.floor(e/16),(t==="x"?r:r&3|8).toString(16)})},b=Object.getPrototypeOf(async function(){}).constructor,z=e=>{const t=`
|
|
7
|
-
const __cleanup = this.__cleanup.bind(this);
|
|
8
|
-
const __error = this.onError.bind(this);
|
|
9
|
-
{
|
|
10
|
-
this.__setup();
|
|
11
|
-
}
|
|
12
|
-
try {
|
|
13
|
-
${e}
|
|
14
|
-
} catch (ex) {
|
|
15
|
-
__error(ex);
|
|
16
|
-
} finally {
|
|
17
|
-
__cleanup();
|
|
18
|
-
}
|
|
19
|
-
`;try{return{fn:new b(t),functionBody:t}}catch{const r=`
|
|
20
|
-
this.__setup();
|
|
21
|
-
this.onError({ message: "The script has a syntax error and could not be parsed" });
|
|
22
|
-
this.__cleanup();
|
|
23
|
-
`;return{fn:new b(r),functionBody:r}}},G=class{constructor({isDebug:e=!1}){c(this,"promises");c(this,"isDebug");this.promises=new Map,this.isDebug=e}delete(e){this.isDebug&&console.log(`Deleting promise ${e}`),this.promises.delete(e)}get(e){return this.isDebug&&console.log(`Getting promise ${e}`),this.promises.get(e)}set(e,t,r){this.promises.set(e,{resolve:t,reject:r})}id(){return q()}register(e,t){const r=this.id();return this.set(r,e,t),r}resolve(e,t){var r;(r=this.get(e))==null||r.resolve(t),this.delete(e)}reject(e,t){var r;(r=this.get(e))==null||r.reject(t),this.delete(e)}},m=new G({isDebug:!1});self.onmessage=async e=>{const t=JSON.parse(e.data),{action:r,script:s,setup:n,args:a,sessionData:l={},pluginComponentId:i,pluginApiName:h,location:d}=t;if(r===u.RUN&&n&&s){const{fn:g,functionBody:f}=z(s),o=new W({user:n.user,teamMember:n.teamMember,business:n.business,entityId:n.entityId??"",objectId:n.objectId??"",clientObject:n.clientObject,appPath:n.appPath,isDebug:n.isDebug,scriptBody:s,functionBody:f,instance:self,kizenRequest:D(self,m),postFormData:M(self,m),uploadFile:U(self,m),installThirdPartyScript:H(self,m),args:a??"",sessionData:l,pluginComponentId:i,prompt:j(self,m),dynamicPrompt:x(self,m),refreshEntity:F(self,m),openCreateRecord:L(self,m),openCreateRelatedRecord:$(self,m),pluginApiName:h,location:d});await g.bind(o)()}else J(r,e,m)}})();
|