@kizenapps/cli 1.1.2-590a1f4 → 1.4.0-fcc7387

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.
Files changed (46) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/index.js.map +1 -1
  3. package/dist/viewer/assets/{AppDetailPage-BorvgFPN.js → AppDetailPage-bXSN_SkL.js} +1 -1
  4. package/dist/viewer/assets/{BootstrapContext-D5ZnMrOp.js → BootstrapContext-BJMPPV2t.js} +1 -1
  5. package/dist/viewer/assets/Card-DRaOqhzt.js +1 -0
  6. package/dist/viewer/assets/{CodeStepsPage-DnL8JwSJ.js → CodeStepsPage-BzLWCjg6.js} +1 -1
  7. package/dist/viewer/assets/{CodeViewer-C9aVhzG7.js → CodeViewer-sTHrPWAx.js} +1 -1
  8. package/dist/viewer/assets/{ConfigurationPage-CAdaFi9y.js → ConfigurationPage-DHbuiVlX.js} +1 -1
  9. package/dist/viewer/assets/{DevSidebar-DS8UU-G8.js → DevSidebar-C8F2KFXY.js} +1 -1
  10. package/dist/viewer/assets/{IconReferencePage-bTBpdJEd.js → IconReferencePage-BDKMGmeG.js} +1 -1
  11. package/dist/viewer/assets/{SandboxPage-CU6fvI8A.js → SandboxPage-CMq8Xrjk.js} +1 -1
  12. package/dist/viewer/assets/SidebarContext-CENlTk-2.js +1 -0
  13. package/dist/viewer/assets/{SourceBrowserPage-BBZcr3MI.js → SourceBrowserPage-Clg_fH0I.js} +1 -1
  14. package/dist/viewer/assets/{Tooltip-tpqNw0op.js → Tooltip-9-UcK9bz.js} +1 -1
  15. package/dist/viewer/assets/{VersionsPage-D6QScnTb.js → VersionsPage-BRfN-13x.js} +1 -1
  16. package/dist/viewer/assets/{WhenBadge-DZrl6k94.js → WhenBadge-DY21YMpA.js} +1 -1
  17. package/dist/viewer/assets/api-DJcHZP2k.js +10 -0
  18. package/dist/viewer/assets/{bundleQuery-CjbA01rb.js → bundleQuery-Bjqi6ox2.js} +1 -1
  19. package/dist/viewer/assets/{calendarSource.worker-DGRTJYHs.js → calendarSource.worker-2UhvqVzo.js} +4 -4
  20. package/dist/viewer/assets/{configStorage-aLI-65re.js → configStorage-fNlYS08a.js} +1 -1
  21. package/dist/viewer/assets/{fa-core-BoBqCOD3.js → fa-core-B7dAyAZA.js} +1 -1
  22. package/dist/viewer/assets/{fa-pro-icons-j8-_MCQ7.js → fa-pro-icons-DtrKpGj8.js} +1 -1
  23. package/dist/viewer/assets/floatingFrame.worker-BPvRqAU5.js +23 -0
  24. package/dist/viewer/assets/{generic.worker-Bzr3c9PO.js → generic.worker-CaEdS_L8.js} +4 -4
  25. package/dist/viewer/assets/index-BqEAhAQ_.css +2 -0
  26. package/dist/viewer/assets/index-ZdHVsbQr.js +5 -0
  27. package/dist/viewer/assets/{react-csXWLXSE.js → react-j0eBFjQW.js} +1 -1
  28. package/dist/viewer/assets/{recordDetail.worker-B-1qFS5m.js → recordDetail.worker-DIZ1eFYu.js} +6 -6
  29. package/dist/viewer/assets/rolldown-runtime-Dw2cE7zH.js +1 -0
  30. package/dist/viewer/assets/storageKeys-CSWy3aiP.js +1 -0
  31. package/dist/viewer/assets/useCriticalExceptionDialog-4AtgdUhp.js +40 -0
  32. package/dist/viewer/assets/{useLocalStorage-CyZiO78q.js → useLocalStorage-BTxXC7un.js} +1 -1
  33. package/dist/viewer/assets/{useNavigate-BblEmQ3O.js → useNavigate-AMIImip9.js} +1 -1
  34. package/dist/viewer/assets/{useQuery-5OkVbV1s.js → useQuery-CHCkzQbK.js} +1 -1
  35. package/dist/viewer/assets/{validIcons-BzGQ4tWD.js → validIcons-LvIGHq2c.js} +1 -1
  36. package/dist/viewer/index.html +13 -13
  37. package/package.json +12 -2
  38. package/dist/viewer/assets/Card-BpDJPrPZ.js +0 -1
  39. package/dist/viewer/assets/SidebarContext-Cn8QRb77.js +0 -1
  40. package/dist/viewer/assets/api-DtXiAEKW.js +0 -10
  41. package/dist/viewer/assets/floatingFrame.worker-CKAMagoG.js +0 -23
  42. package/dist/viewer/assets/index-Cp0A29vq.js +0 -5
  43. package/dist/viewer/assets/index-DtzraybB.css +0 -2
  44. package/dist/viewer/assets/rolldown-runtime-DF2fYuay.js +0 -1
  45. package/dist/viewer/assets/storageKeys-C6c8YF5Y.js +0 -1
  46. package/dist/viewer/assets/useCriticalExceptionDialog-C8PL9Dxt.js +0 -5
@@ -1,9 +1,9 @@
1
- (function(){var e=class e extends Error{proxyStatus;upstreamStatus;upstreamResponse;constructor(t,n,r,i){super(i??r?.error?.message??(n?`Request failed with status code ${String(n)}`:`Request failed with proxy status code ${String(t)}`)),this.name=`KizenRequestError`,this.proxyStatus=t,this.upstreamStatus=n,this.upstreamResponse=r,Object.setPrototypeOf(this,e.prototype)}},t={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`,HIDE:`hide`,SHOW:`show`,EXPAND:`expand`,COLLAPSE:`collapse`,HIDE_HEADER:`hideheader`,SHOW_HEADER:`showheader`,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`},n={QUERY_RESPONSE:`query:response`,POSTFORMDATA_RESPONSE:`postformdata:response`,ERROR:`error`,UPLOADFILE_RESPONSE:`uploadfile:response`,UPLOADFILE_PROGRESS:`uploadfile:progress`,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`},r={RUN_FRAME_SCRIPT:`runframescript`,SEND_MESSAGE_TO_FRAME:`sendmessagetoframe`,CALL_THIRD_PARTY_SCRIPT:`callthirdpartyscript`},i=/https:\/\/.*widget\.freshworks\.com\/.*\.js/,a=/https:\/\/widget\.intercom\.io\/widget\/[a-z0-9]+/,o={FRESHWORKS:`freshworks`,INTERCOM:`intercom`},s=e=>{if(i.test(e))return o.FRESHWORKS;if(a.test(e))return o.INTERCOM};o.FRESHWORKS,o.INTERCOM,o.FRESHWORKS,o.INTERCOM,o.FRESHWORKS,o.INTERCOM;var c=class{instance;scriptUrl;integration;constructor(e,t){this.instance=e,this.scriptUrl=t;let n=s(t);if(n)this.integration=n;else throw Error(`Error: Disallowed script url: ${t}`)}get type(){return this.integration}call(...e){this.instance.postMessage(JSON.stringify({action:t.COMMUNICATE,type:r.CALL_THIRD_PARTY_SCRIPT,eventName:`thirdParty:${r.CALL_THIRD_PARTY_SCRIPT}`,recipient:{script:this.scriptUrl,type:this.type},params:e}))}},l=e=>({key:`action__${e.api_name}`,type:`custom_object`,label:e.name,allow_multiple:!0}),u=(e,t)=>{let n=(e.fields??[]).filter(e=>e.type!==`container`&&e.type!==`description`).map(e=>({...e,when:t?`(${t}) && (${e.when??`true`})`:e.when})),r=(e.fields??[]).filter(e=>e.type===`container`).flatMap(e=>u(e,e.when)),i=e.actions?.filter(e=>e.hint_object_name)??[];return[...n,...r,...i.map(e=>({...l(e),match_hint:e.hint_object_name??``}))]},d=(e,t)=>{let n=u(e).reduce((e,t)=>({...e,[t.key]:t}),{}),r=Object.keys(t),i={};return r.forEach(e=>{let r=t[e],a=n[e];if(a?.type){switch(a.type){case`boolean`:let t=r;if(!t)return;i[e]=t.value;return;case`custom_object`:{let t=r;if(!t)return;i[e]={objectId:t.value?.id,objectName:t.value?.objectName};return}case`field`:{let t=r;if(!t?.value)return;Array.isArray(t.value)?i[e]=t.value.map(e=>({fieldId:e.value,fieldName:e.label,objectId:t.associatedObject?.id,objectName:t.associatedObject?.name})):typeof t.value==`object`&&typeof t.associatedObject==`object`&&(i[e]={fieldId:t.value.value,fieldName:t.value.label,objectId:t.associatedObject.id,objectName:t.associatedObject.name});return}case`number`:{let t=r;if(!t)return;try{let n=Number(t.value);if(!n&&n!==0)return;i[e]=n}catch{i[e]=NaN}return}case`select`:{let t=r;if(!t)return;i[e]=t.value;return}case`text`:{let t=r?.value;if(t){i[e]=t;return}let n=a.default;n&&(i[e]=n);return}case`description`:case`container`:return}return r?.value}}),i},f=(e,n)=>r=>async(i,a,o)=>new Promise((s,c)=>{let l=n.register(s,c);e.postMessage(JSON.stringify({action:t.QUERY_REQUEST,id:l,method:r,url:i,payload:a,options:o}))}),p=(e,n)=>(r,i,a=!0)=>new Promise((o,s)=>{let c=n.register(o,s);e.postMessage(JSON.stringify({action:t.POSTFORMDATA_REQUEST,url:r,id:c,payload:i,createNewTab:a}))}),m=(e,n)=>r=>new Promise((i,a)=>{let o=n.register(i,a);e.postMessage(JSON.stringify({action:t.PROMPT_REQUEST,id:o,config:r}))}),h=(e,n)=>r=>new Promise((i,a)=>{let o=n.register(i,a);e.postMessage(JSON.stringify({action:t.DYNAMIC_PROMPT_REQUEST,id:o,config:r}))}),g=(e,n)=>r=>new Promise((i,a)=>{let o=n.register(i,a);e.postMessage(JSON.stringify({action:t.UPLOADFILE_REQUEST,id:o,payload:r}))}),_=(e,n)=>(r,i)=>new Promise((a,o)=>{let s=n.register(a,o);e.postMessage(JSON.stringify({action:t.INSTALL_THIRD_PARTY_SCRIPT_REQUEST,url:r,id:s,args:i}))}),v=(e,n)=>r=>new Promise((i,a)=>{let o=n.register(i,a);e.postMessage(JSON.stringify({action:t.REFRESH_ENTITY,id:o,entityId:r}))}),y=(e,n)=>r=>new Promise((i,a)=>{let o=n.register(i,a);e.postMessage(JSON.stringify({action:t.OPEN_CREATE_RECORD_MODAL_REQUEST,id:o,entityId:r}))}),b=(e,n)=>(r,i)=>new Promise((a,o)=>{let s=n.register(a,o);e.postMessage(JSON.stringify({action:t.OPEN_CREATE_RELATED_RECORD_MODAL_REQUEST,id:s,objectId:r,relatedEntityId:i}))}),x=(t,r,i)=>{switch(t){case n.QUERY_RESPONSE:{let{id:t,data:n,error:a}=JSON.parse(r.data);if(a){let n=typeof a==`object`&&`__kizenError`in a?new e(a.proxyStatus,a.upstreamStatus,a.upstreamResponse,a.message):a;i.reject(t,n)}else i.resolve(t,n);break}case n.POSTFORMDATA_RESPONSE:{let{id:e,success:t}=JSON.parse(r.data);t?i.resolve(e):i.reject(e);break}case n.UPLOADFILE_RESPONSE:{let{id:e,data:t,error:n}=JSON.parse(r.data);t?i.resolve(e,t):i.reject(e,n);break}case n.INSTALL_THIRD_PARTY_SCRIPT_RESPONSE:{let{id:e,data:t}=JSON.parse(r.data);t.success?i.resolve(e,t):i.reject(e);break}case n.PROMPT_RESPONSE:{let{id:e,data:t}=JSON.parse(r.data);i.resolve(e,t);break}case n.CREATE_RECORD_RESPONSE:{let{id:e,data:t}=JSON.parse(r.data);i.resolve(e,t);break}case n.CREATE_RELATED_RECORD_RESPONSE:{let{id:e,data:t}=JSON.parse(r.data);i.resolve(e,t);break}case n.REFRESH_ENTITY_RESPONSE:{let{id:e,data:t}=JSON.parse(r.data);t.success?i.resolve(e,!0):i.reject(e);break}}},S=`integration:${r.RUN_FRAME_SCRIPT}`,C=class{instance;constructor(e){this.instance=e}runFrameScript(e,n,i){this.instance.postMessage(JSON.stringify({action:t.COMMUNICATE,type:r.RUN_FRAME_SCRIPT,eventName:S,recipient:{frame:e,script:n},args:i}))}sendMessageToOwnFrame(e,n){this.instance.postMessage(JSON.stringify({action:t.COMMUNICATE,type:r.SEND_MESSAGE_TO_FRAME,args:{payload:e,path:n}}))}},w=async e=>{let t=null;try{t=await e.json()}catch{}return{status:e.status,statusText:e.statusText,body:t}},T=(e,t,n={},r=``)=>`(function() { ${r}
2
- return ${`(${e.toString()})({ state: {{${t}}}, args: ${JSON.stringify(n)}, utils: __kizen_utils })`}; })()`,E=class{user;teamMember;business;clientObject;appPath;dataCache=new Map;queryOptions={};api;postFormData;executionTimer=0;setupExecutions=0;cleanupExecutions=0;isDebug=!1;scriptBody;internalState={indicator:`none`};console=console;instance;breakOnException=!1;args;communicate;shouldPreserve=!1;uploadFileHandler;internalSessionData;pluginComponentId;installThirdPartyScriptHandler;promptHandler;dynamicPromptHandler;refreshEntityHandler;openCreateRecordHandler;openCreateRelatedRecordHandler;runnerType;pluginApiName;tempPromptState={};partialLocation;constructor({user:e,teamMember:t,business:n,clientObject:r,appPath:i,isDebug:a,kizenRequest:o,postFormData:s,scriptBody:c,instance:l,args:u,uploadFile:d,sessionData:f,pluginComponentId:p,installThirdPartyScript:m,prompt:h,refreshEntity:g,openCreateRecord:_,openCreateRelatedRecord:v,pluginApiName:y,dynamicPrompt:b,location:x}){this.user=e,this.teamMember=t,this.business=n,this.clientObject=r,this.partialLocation=x,this.appPath=i,this.isDebug=a??!1,this.api={get:o(`get`),post:o(`post`),put:o(`put`),delete:o(`delete`),patch:o(`patch`)},this.postFormData=s,this.scriptBody=c,this.instance=l,this.communicate=new C(l),this.uploadFileHandler=d,this.internalSessionData=f??{},this.pluginComponentId=p,this.installThirdPartyScriptHandler=m,this.promptHandler=h,this.refreshEntityHandler=g,this.openCreateRecordHandler=_,this.openCreateRelatedRecordHandler=v,this.runnerType=`base`,this.pluginApiName=y,this.dynamicPromptHandler=b;try{this.args=JSON.parse(u??`{}`)}catch{this.args={}}}onError(e){if(this.breakOnException)debugger;this.instance.postMessage(JSON.stringify({action:n.ERROR,error: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,n=`_blank`){this.instance.postMessage(JSON.stringify({action:t.OPEN_WINDOW,url:e,target:n,features:`noopener noreferrer`}))}authorize(e,n={}){if(!e)throw Error(`Service name is required to authorize`);this.instance.postMessage(JSON.stringify({action:t.AUTHORIZE,serviceName:e,config:{successRedirectPath:n.successRedirectPath??`/marketplace/${this.pluginApiName}/auth`,errorRedirectPath:n.errorRedirectPath??`/marketplace/${this.pluginApiName}/auth`}}))}getServiceUrl(e,t){if(!e)throw Error(`Service name is required to get a service url`);let n=`/external-integrations/proxy/${this.pluginApiName}/${e}`;return t.startsWith(`/`)?`${n}${t}`:`${n}/${t}`}get currentBusiness(){return this.business}get applicationPath(){return this.appPath}get currentUser(){return{profile:{id:this.teamMember?.id??``,full_name:this.teamMember?.full_name??``,first_name:this.teamMember?.first_name??``,last_name:this.teamMember?.last_name??``,email:this.teamMember?.email??``,phone:this.teamMember?.phone??``,created:this.teamMember?.created??``,crm_client_id:this.user?.crm_client_id??``}}}get sessionData(){return this.internalSessionData}get config(){return this.args.__kizen_clean_config?new Proxy(this.args.__kizen_clean_config??{},{get:(e,t)=>{if(Reflect.has(e,t))return Reflect.get(e,t)}}):{}}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 Error(`Property ${String(t)} is not available on location object for plugin apps`)}})}get userConfig(){let e=this.args.__kizen_user_config?.__kizen_clean_config;return e?new Proxy(e,{get:(e,t)=>{if(Reflect.has(e,t))return Reflect.get(e,t)}}):{}}setSessionData(e){if(typeof e!=`object`)throw Error(`Invalid session update with type ${typeof e}`);if(Array.isArray(e))throw Error(`Invalid session update with type array`);this.internalSessionData={...this.internalSessionData,...e},this.instance.postMessage(JSON.stringify({action:t.UPDATE_SESSION_DATA,update:e}))}async get(e,t){try{if(this.isRelativeUrl(e)){let n=this.dataCache.get(e);if(n&&!t?.ignoreCache)return t?.returnErrors?[n.data,null]:n.data;let{data:r}=await this.api.get(e,{...this.queryOptions,headers:this.buildHeaders(t?.headers)});return this.dataCache.set(e,{ts:Date.now(),data:r}),t?.returnErrors?[r,null]:r}else{let n=await fetch(e,{method:`GET`,headers:new Headers(t?.headers),credentials:t?.credentials??`same-origin`});if(!n.ok)throw await w(n);let r=await n.json();return t?.returnErrors?[r,null]:r}}catch(e){if(t?.returnErrors)return[null,e];this.onError(e)}}async getWithErrors(e,t){return this.get(e,{...t,returnErrors:!0})}async getUserConfig(){if(!this.args.pluginId||!this.pluginComponentId)throw Error(`User config is not available for scripts not associated to a plugin or plugin component`);return(await this.get(`/employee/mine/configs/plugins/${this.args.pluginId}`,{ignoreCache:!0})).config?.[this.pluginComponentId]??{}}async setUserConfig(e){if(!this.args.pluginId||!this.pluginComponentId)throw Error(`User config is not available for scripts not associated to a plugin or plugin component`);let 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?.config,[this.pluginComponentId]:{...t?.config?.[this.pluginComponentId],...e}}})}async patch(e,t,n){try{if(this.isRelativeUrl(e)){let{data:r}=await this.api.patch(e,t,{...this.queryOptions,headers:n?.headers});return n?.returnErrors?[r,null]:r}else{let r=await fetch(e,{method:`PATCH`,body:t?JSON.stringify(t):null,headers:new Headers(n?.headers),credentials:n?.credentials??`same-origin`});if(!r.ok)throw await w(r);let i=await r.json();return n?.returnErrors?[i,null]:i}}catch(e){if(n?.returnErrors)return[null,e];this.onError(e)}}async patchWithErrors(e,t,n){return this.patch(e,t,{...n,returnErrors:!0})}async post(e,t,n){try{if(this.isRelativeUrl(e)){let{data:r}=await this.api.post(e,t,{...this.queryOptions,headers:this.buildHeaders(n?.headers)});return n?.returnErrors?[r,null]:r}else{let r=await fetch(e,{method:`POST`,body:t?JSON.stringify(t):null,headers:new Headers(n?.headers),credentials:n?.credentials??`same-origin`});if(!r.ok)throw await w(r);let i=await r.json();return n?.returnErrors?[i,null]:i}}catch(e){if(n?.returnErrors)return[null,e];this.onError(e)}}async postWithErrors(e,t,n){return this.post(e,t,{...n,returnErrors:!0})}async delete(e,t){try{if(this.isRelativeUrl(e)){let{data:n}=await this.api.delete(e,{...this.queryOptions,headers:this.buildHeaders(t?.headers)});return t?.returnErrors?[n,null]:n}else{let n=await fetch(e,{method:`DELETE`,headers:new Headers(t?.headers),credentials:t?.credentials??`same-origin`});if(!n.ok)throw await w(n);let r=null;return n.status!==204&&(r=await n.json()),t?.returnErrors?[r,null]:r}}catch(e){if(t?.returnErrors)return[null,e];this.onError(e)}}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,n){this.instance.postMessage(JSON.stringify({action:t.SHOW_TOAST,message:e,toastOptions:n}))}clearToasts(){this.instance.postMessage(JSON.stringify({action:t.CLEAR_TOASTS}))}outputUI(e){this.instance.postMessage(JSON.stringify({action:t.UI_OUTPUT,markup:e}))}prompt(e){return this.promptHandler(e)}async dynamicPrompt(e){let t=`__kizen_state`,n=`const __kizen_utils = {};
1
+ (function(){var e={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`,HIDE:`hide`,SHOW:`show`,EXPAND:`expand`,COLLAPSE:`collapse`,HIDE_HEADER:`hideheader`,SHOW_HEADER:`showheader`,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`},t={QUERY_RESPONSE:`query:response`,POSTFORMDATA_RESPONSE:`postformdata:response`,ERROR:`error`,UPLOADFILE_RESPONSE:`uploadfile:response`,UPLOADFILE_PROGRESS:`uploadfile:progress`,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`},n={RUN_FRAME_SCRIPT:`runframescript`,SEND_MESSAGE_TO_FRAME:`sendmessagetoframe`,CALL_THIRD_PARTY_SCRIPT:`callthirdpartyscript`},r=/https:\/\/.*widget\.freshworks\.com\/.*\.js/,i=/https:\/\/widget\.intercom\.io\/widget\/[a-z0-9]+/,a={FRESHWORKS:`freshworks`,INTERCOM:`intercom`},o=e=>{if(r.test(e))return a.FRESHWORKS;if(i.test(e))return a.INTERCOM};a.FRESHWORKS,a.INTERCOM,a.FRESHWORKS,a.INTERCOM,a.FRESHWORKS,a.INTERCOM;var s=class{instance;scriptUrl;integration;constructor(e,t){this.instance=e,this.scriptUrl=t;let n=o(t);if(n)this.integration=n;else throw Error(`Error: Disallowed script url: ${t}`)}get type(){return this.integration}call(...t){this.instance.postMessage(JSON.stringify({action:e.COMMUNICATE,type:n.CALL_THIRD_PARTY_SCRIPT,eventName:`thirdParty:${n.CALL_THIRD_PARTY_SCRIPT}`,recipient:{script:this.scriptUrl,type:this.type},params:t}))}},c=class e extends Error{proxyStatus;upstreamStatus;upstreamResponse;constructor(t,n,r,i){super(i??r?.error?.message??(n?`Request failed with status code ${String(n)}`:`Request failed with proxy status code ${String(t)}`)),this.name=`KizenRequestError`,this.proxyStatus=t,this.upstreamStatus=n,this.upstreamResponse=r,Object.setPrototypeOf(this,e.prototype)}},l=e=>({key:`action__${e.api_name}`,type:`custom_object`,label:e.name,allow_multiple:!0}),u=[`description`,`container`,`qr`,`image`,`link`],d=(e,t)=>{let n=(e.fields??[]).filter(e=>!u.includes(e.type)).map(e=>({...e,when:t?`(${t}) && (${e.when??`true`})`:e.when})),r=(e.fields??[]).filter(e=>e.type===`container`).flatMap(e=>d(e,e.when)),i=e.actions?.filter(e=>e.hint_object_name)??[];return[...n,...r,...i.map(e=>({...l(e),match_hint:e.hint_object_name??``}))]},f=(e,t)=>{let n=d(e).reduce((e,t)=>({...e,[t.key]:t}),{}),r=Object.keys(t),i={};return r.forEach(e=>{let r=t[e],a=n[e];if(a?.type){switch(a.type){case`boolean`:let t=r;if(!t)return;i[e]=t.value;return;case`custom_object`:{let t=r;if(!t)return;i[e]={objectId:t.value?.id,objectName:t.value?.objectName};return}case`field`:{let t=r;if(!t?.value)return;Array.isArray(t.value)?i[e]=t.value.map(e=>({fieldId:e.value,fieldName:e.label,objectId:t.associatedObject?.id,objectName:t.associatedObject?.name})):typeof t.value==`object`&&typeof t.associatedObject==`object`&&(i[e]={fieldId:t.value.value,fieldName:t.value.label,objectId:t.associatedObject.id,objectName:t.associatedObject.name});return}case`number`:{let t=r;if(!t)return;try{let n=Number(t.value);if(!n&&n!==0)return;i[e]=n}catch{i[e]=NaN}return}case`select`:{let t=r;if(!t)return;i[e]=t.value;return}case`text`:{let t=r?.value;if(t){i[e]=t;return}let n=a.default;n&&(i[e]=n);return}case`description`:case`container`:case`qr`:case`image`:case`link`:return}return r?.value}}),i},p=(t,n)=>r=>async(i,a,o)=>new Promise((s,c)=>{let l=n.register(s,c);t.postMessage(JSON.stringify({action:e.QUERY_REQUEST,id:l,method:r,url:i,payload:a,options:o}))}),m=(t,n)=>(r,i,a=!0)=>new Promise((o,s)=>{let c=n.register(o,s);t.postMessage(JSON.stringify({action:e.POSTFORMDATA_REQUEST,url:r,id:c,payload:i,createNewTab:a}))}),h=(t,n)=>r=>new Promise((i,a)=>{let o=n.register(i,a);t.postMessage(JSON.stringify({action:e.PROMPT_REQUEST,id:o,config:r}))}),g=(t,n)=>r=>new Promise((i,a)=>{let o=n.register(i,a);t.postMessage(JSON.stringify({action:e.DYNAMIC_PROMPT_REQUEST,id:o,config:r}))}),_=(t,n)=>r=>new Promise((i,a)=>{let o=n.register(i,a);t.postMessage(JSON.stringify({action:e.UPLOADFILE_REQUEST,id:o,payload:r}))}),v=(t,n)=>(r,i)=>new Promise((a,o)=>{let s=n.register(a,o);t.postMessage(JSON.stringify({action:e.INSTALL_THIRD_PARTY_SCRIPT_REQUEST,url:r,id:s,args:i}))}),y=(t,n)=>r=>new Promise((i,a)=>{let o=n.register(i,a);t.postMessage(JSON.stringify({action:e.REFRESH_ENTITY,id:o,entityId:r}))}),b=(t,n)=>r=>new Promise((i,a)=>{let o=n.register(i,a);t.postMessage(JSON.stringify({action:e.OPEN_CREATE_RECORD_MODAL_REQUEST,id:o,entityId:r}))}),x=(t,n)=>(r,i)=>new Promise((a,o)=>{let s=n.register(a,o);t.postMessage(JSON.stringify({action:e.OPEN_CREATE_RELATED_RECORD_MODAL_REQUEST,id:s,objectId:r,relatedEntityId:i}))}),S=(e,n,r)=>{switch(e){case t.QUERY_RESPONSE:{let{id:e,data:t,error:i}=JSON.parse(n.data);if(i){let t=typeof i==`object`&&`__kizenError`in i?new c(i.proxyStatus,i.upstreamStatus,i.upstreamResponse,i.message):i;r.reject(e,t)}else r.resolve(e,t);break}case t.POSTFORMDATA_RESPONSE:{let{id:e,success:t}=JSON.parse(n.data);t?r.resolve(e):r.reject(e);break}case t.UPLOADFILE_RESPONSE:{let{id:e,data:t,error:i}=JSON.parse(n.data);t?r.resolve(e,t):r.reject(e,i);break}case t.INSTALL_THIRD_PARTY_SCRIPT_RESPONSE:{let{id:e,data:t}=JSON.parse(n.data);t.success?r.resolve(e,t):r.reject(e);break}case t.PROMPT_RESPONSE:{let{id:e,data:t}=JSON.parse(n.data);r.resolve(e,t);break}case t.CREATE_RECORD_RESPONSE:{let{id:e,data:t}=JSON.parse(n.data);r.resolve(e,t);break}case t.CREATE_RELATED_RECORD_RESPONSE:{let{id:e,data:t}=JSON.parse(n.data);r.resolve(e,t);break}case t.REFRESH_ENTITY_RESPONSE:{let{id:e,data:t}=JSON.parse(n.data);t.success?r.resolve(e,!0):r.reject(e);break}}},C=`integration:${n.RUN_FRAME_SCRIPT}`,w=class{instance;constructor(e){this.instance=e}runFrameScript(t,r,i){this.instance.postMessage(JSON.stringify({action:e.COMMUNICATE,type:n.RUN_FRAME_SCRIPT,eventName:C,recipient:{frame:t,script:r},args:i}))}sendMessageToOwnFrame(t,r){this.instance.postMessage(JSON.stringify({action:e.COMMUNICATE,type:n.SEND_MESSAGE_TO_FRAME,args:{payload:t,path:r}}))}},T=async e=>{let t=null;try{t=await e.json()}catch{}return{status:e.status,statusText:e.statusText,body:t}},E=(e,t,n={},r=``)=>`(function() { ${r}
2
+ return ${`(${e.toString()})({ state: {{${t}}}, args: ${JSON.stringify(n)}, utils: __kizen_utils })`}; })()`,D=class{user;teamMember;business;clientObject;appPath;dataCache=new Map;queryOptions={};api;postFormData;executionTimer=0;setupExecutions=0;cleanupExecutions=0;isDebug=!1;scriptBody;internalState={indicator:`none`};console=console;instance;breakOnException=!1;args;communicate;shouldPreserve=!1;uploadFileHandler;internalSessionData;pluginComponentId;installThirdPartyScriptHandler;promptHandler;dynamicPromptHandler;refreshEntityHandler;openCreateRecordHandler;openCreateRelatedRecordHandler;runnerType;pluginApiName;tempPromptState={};partialLocation;constructor({user:e,teamMember:t,business:n,clientObject:r,appPath:i,isDebug:a,kizenRequest:o,postFormData:s,scriptBody:c,instance:l,args:u,uploadFile:d,sessionData:f,pluginComponentId:p,installThirdPartyScript:m,prompt:h,refreshEntity:g,openCreateRecord:_,openCreateRelatedRecord:v,pluginApiName:y,dynamicPrompt:b,location:x}){this.user=e,this.teamMember=t,this.business=n,this.clientObject=r,this.partialLocation=x,this.appPath=i,this.isDebug=a??!1,this.api={get:o(`get`),post:o(`post`),put:o(`put`),delete:o(`delete`),patch:o(`patch`)},this.postFormData=s,this.scriptBody=c,this.instance=l,this.communicate=new w(l),this.uploadFileHandler=d,this.internalSessionData=f??{},this.pluginComponentId=p,this.installThirdPartyScriptHandler=m,this.promptHandler=h,this.refreshEntityHandler=g,this.openCreateRecordHandler=_,this.openCreateRelatedRecordHandler=v,this.runnerType=`base`,this.pluginApiName=y,this.dynamicPromptHandler=b;try{this.args=JSON.parse(u??`{}`)}catch{this.args={}}}onError(e){if(this.breakOnException)debugger;this.instance.postMessage(JSON.stringify({action:t.ERROR,error: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(t,n=`_blank`){this.instance.postMessage(JSON.stringify({action:e.OPEN_WINDOW,url:t,target:n,features:`noopener noreferrer`}))}authorize(t,n={}){if(!t)throw Error(`Service name is required to authorize`);this.instance.postMessage(JSON.stringify({action:e.AUTHORIZE,serviceName:t,config:{successRedirectPath:n.successRedirectPath??`/marketplace/${this.pluginApiName}/auth`,errorRedirectPath:n.errorRedirectPath??`/marketplace/${this.pluginApiName}/auth`}}))}getServiceUrl(e,t){if(!e)throw Error(`Service name is required to get a service url`);let n=`/external-integrations/proxy/${this.pluginApiName}/${e}`;return t.startsWith(`/`)?`${n}${t}`:`${n}/${t}`}get currentBusiness(){return this.business}get applicationPath(){return this.appPath}get currentUser(){return{profile:{id:this.teamMember?.id??``,full_name:this.teamMember?.full_name??``,first_name:this.teamMember?.first_name??``,last_name:this.teamMember?.last_name??``,email:this.teamMember?.email??``,phone:this.teamMember?.phone??``,created:this.teamMember?.created??``,crm_client_id:this.user?.crm_client_id??``}}}get sessionData(){return this.internalSessionData}get config(){return this.args.__kizen_clean_config?new Proxy(this.args.__kizen_clean_config??{},{get:(e,t)=>{if(Reflect.has(e,t))return Reflect.get(e,t)}}):{}}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 Error(`Property ${String(t)} is not available on location object for plugin apps`)}})}get userConfig(){let e=this.args.__kizen_user_config?.__kizen_clean_config;return e?new Proxy(e,{get:(e,t)=>{if(Reflect.has(e,t))return Reflect.get(e,t)}}):{}}setSessionData(t){if(typeof t!=`object`)throw Error(`Invalid session update with type ${typeof t}`);if(Array.isArray(t))throw Error(`Invalid session update with type array`);this.internalSessionData={...this.internalSessionData,...t},this.instance.postMessage(JSON.stringify({action:e.UPDATE_SESSION_DATA,update:t}))}async get(e,t){try{if(this.isRelativeUrl(e)){let n=this.dataCache.get(e);if(n&&!t?.ignoreCache)return t?.returnErrors?[n.data,null]:n.data;let{data:r}=await this.api.get(e,{...this.queryOptions,headers:this.buildHeaders(t?.headers)});return this.dataCache.set(e,{ts:Date.now(),data:r}),t?.returnErrors?[r,null]:r}else{let n=await fetch(e,{method:`GET`,headers:new Headers(t?.headers),credentials:t?.credentials??`same-origin`});if(!n.ok)throw await T(n);let r=await n.json();return t?.returnErrors?[r,null]:r}}catch(e){if(t?.returnErrors)return[null,e];this.onError(e)}}async getWithErrors(e,t){return this.get(e,{...t,returnErrors:!0})}async getUserConfig(){if(!this.args.pluginId||!this.pluginComponentId)throw Error(`User config is not available for scripts not associated to a plugin or plugin component`);return(await this.get(`/employee/mine/configs/plugins/${this.args.pluginId}`,{ignoreCache:!0})).config?.[this.pluginComponentId]??{}}async setUserConfig(e){if(!this.args.pluginId||!this.pluginComponentId)throw Error(`User config is not available for scripts not associated to a plugin or plugin component`);let 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?.config,[this.pluginComponentId]:{...t?.config?.[this.pluginComponentId],...e}}})}async patch(e,t,n){try{if(this.isRelativeUrl(e)){let{data:r}=await this.api.patch(e,t,{...this.queryOptions,headers:n?.headers});return n?.returnErrors?[r,null]:r}else{let r=await fetch(e,{method:`PATCH`,body:t?JSON.stringify(t):null,headers:new Headers(n?.headers),credentials:n?.credentials??`same-origin`});if(!r.ok)throw await T(r);let i=await r.json();return n?.returnErrors?[i,null]:i}}catch(e){if(n?.returnErrors)return[null,e];this.onError(e)}}async patchWithErrors(e,t,n){return this.patch(e,t,{...n,returnErrors:!0})}async post(e,t,n){try{if(this.isRelativeUrl(e)){let{data:r}=await this.api.post(e,t,{...this.queryOptions,headers:this.buildHeaders(n?.headers)});return n?.returnErrors?[r,null]:r}else{let r=await fetch(e,{method:`POST`,body:t?JSON.stringify(t):null,headers:new Headers(n?.headers),credentials:n?.credentials??`same-origin`});if(!r.ok)throw await T(r);let i=await r.json();return n?.returnErrors?[i,null]:i}}catch(e){if(n?.returnErrors)return[null,e];this.onError(e)}}async postWithErrors(e,t,n){return this.post(e,t,{...n,returnErrors:!0})}async delete(e,t){try{if(this.isRelativeUrl(e)){let{data:n}=await this.api.delete(e,{...this.queryOptions,headers:this.buildHeaders(t?.headers)});return t?.returnErrors?[n,null]:n}else{let n=await fetch(e,{method:`DELETE`,headers:new Headers(t?.headers),credentials:t?.credentials??`same-origin`});if(!n.ok)throw await T(n);let r=null;return n.status!==204&&(r=await n.json()),t?.returnErrors?[r,null]:r}}catch(e){if(t?.returnErrors)return[null,e];this.onError(e)}}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(t,n){this.instance.postMessage(JSON.stringify({action:e.SHOW_TOAST,message:t,toastOptions:n}))}clearToasts(){this.instance.postMessage(JSON.stringify({action:e.CLEAR_TOASTS}))}outputUI(t){this.instance.postMessage(JSON.stringify({action:e.UI_OUTPUT,markup:t}))}prompt(e){return this.promptHandler(e)}async dynamicPrompt(e){let t=`__kizen_state`,n=`const __kizen_utils = {};
3
3
  `;if(e.registerUtils){let t=Object.keys(e.registerUtils);n+=t.map(t=>{let n=e.registerUtils?.[t];if(typeof n!=`function`)throw Error(`Registered util ${t} is not a function, got ${typeof n}`);return`__kizen_utils["${t}"] = (${n.toString()});`}).join(`
4
- `)}let r=e.content?.map(e=>{let r=``;`optionMapper`in e&&(r=T(e.optionMapper,t,e.args,n));let i=``;`getFetchUrl`in e&&(i=T(e.getFetchUrl,t,e.args,n));let a=``;`getHeaders`in e&&(a=T(e.getHeaders,t,e.args,n));let o=``;return`getBody`in e&&(o=T(e.getBody,t,e.args,n)),{...e,optionMapper:r,getFetchUrl:i,getHeaders:a,getBody:o}}),i={...e,content:r},a={fields:i.content},o=await this.dynamicPromptHandler(i),s=d(a,o.values);return{...o,values:s}}outputIframe(e,n,r){this.instance.postMessage(JSON.stringify({action:t.IFRAME_OUTPUT,url:e,allow:n,sandbox:r,preserve:this.preserve}))}getBase64EncodedBlob(e){return new Promise((t,n)=>{let r=new FileReader;r.readAsDataURL(e),r.onload=()=>{t(r.result)},r.onerror=e=>{n(e)}})}async uploadFile(e,t,n=!1){let r=await this.getBase64EncodedBlob(e);return await this.uploadFileHandler({file:r,fileName:t??`file_`+String(Date.now()),isPublic:n})}afterSetup(){}__setup(){if(this.setupExecutions!==0)throw Error(`Setup must be called exactly once, and should never be called by a script directly.`);if(this.cleanupExecutions!==0)throw Error(`Setup was called after cleanup`);this.isDebug&&this.console.log(`Running script:
4
+ `)}let r=e.content?.map(e=>{let r=``;`optionMapper`in e&&(r=E(e.optionMapper,t,e.args,n));let i=``;`getFetchUrl`in e&&(i=E(e.getFetchUrl,t,e.args,n));let a=``;`getHeaders`in e&&(a=E(e.getHeaders,t,e.args,n));let o=``;return`getBody`in e&&(o=E(e.getBody,t,e.args,n)),{...e,optionMapper:r,getFetchUrl:i,getHeaders:a,getBody:o}}),i={...e,content:r},a={fields:i.content},o=await this.dynamicPromptHandler(i),s=f(a,o.values);return{...o,values:s}}outputIframe(t,n,r){this.instance.postMessage(JSON.stringify({action:e.IFRAME_OUTPUT,url:t,allow:n,sandbox:r,preserve:this.preserve}))}getBase64EncodedBlob(e){return new Promise((t,n)=>{let r=new FileReader;r.readAsDataURL(e),r.onload=()=>{t(r.result)},r.onerror=e=>{n(e)}})}async uploadFile(e,t,n=!1){let r=await this.getBase64EncodedBlob(e);return await this.uploadFileHandler({file:r,fileName:t??`file_`+String(Date.now()),isPublic:n})}afterSetup(){}__setup(){if(this.setupExecutions!==0)throw Error(`Setup must be called exactly once, and should never be called by a script directly.`);if(this.cleanupExecutions!==0)throw Error(`Setup was called after cleanup`);this.isDebug&&this.console.log(`Running script:
5
5
 
6
- ${this.scriptBody}`),this.setupExecutions++,this.executionTimer=performance.now(),this.afterSetup()}__cleanup(e){if(this.cleanupExecutions!==0)throw Error(`Cleanup must be called exactly once, and should never be called by a script directly.`);if(this.setupExecutions!==1)throw Error(`Cleanup was called before setup`);this.cleanupExecutions++,this.setIndicator(`none`);let 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,n){this.instance.postMessage(JSON.stringify({action:t.DONE,result:n,preserve:e}))}setState(e){this.instance.postMessage(JSON.stringify({action:t.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:t.REFRESH_TIMELINE,entityId:e}))}refreshEntityForId(e){if(e)return this.refreshEntityHandler(e)}async installThirdPartyScript(e){try{let t=await this.installThirdPartyScriptHandler(e,this.args);return new c(this.instance,t.url)}catch{this.onError(Error(`Third party script ${e} could not be installed.`))}}releaseBlockingScript(){this.instance.postMessage(JSON.stringify({action:t.RELEASE_BLOCKING_SCRIPT}))}copyToClipboard(e){this.instance.postMessage(JSON.stringify({action:t.COPY_TO_CLIPBOARD,text:e}))}createDateObject(e){if(typeof e!=`string`)throw Error(`Invalid date string ${String(e)}`);if(!/^\d{4}-\d{2}-\d{2}$/.test(e))throw Error(`Date string ${e} is not in the format YYYY-MM-DD`);let t=e.split(`-`).map(e=>parseInt(e,10));if(t.length<3)throw 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()}},D=e=>e.object_type===`pipeline`||e.fetch_url===`pipeline`,O=class extends E{objectId;entityId;actionObjectId;actionEntityId;constructor({objectId:e,entityId:t,actionObjectId:n,actionEntityId:r,...i}){super(i),this.objectId=e,this.entityId=t,this.actionObjectId=n,this.actionEntityId=r,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(e,t){return e.fields?.[t]?.value}async getClientEntity(e){return await this.get(`/client/${e}`)}isClientObject(e){return e===this.clientObject?.id}async getEntity(e,t){try{return this.isClientObject(e)?await this.getClientEntity(t):D(await this.get(`/custom-objects/${e}`))?await this.getPipelineEntity(e,t):await this.getCustomEntity(e,t)}catch(e){this.onError(e)}}async getRelatedEntitiesForField(e,t,n){try{let r=(await this.getEntity(e,t)).fields?.[n];if(!r)return this.onError(Error(`Field not found for ID ${n}`)),[];let i=(await this.getObjectDetail(e))?.related_objects?.find(e=>e.field_id===r.id);return i?(await Promise.all(r.value.map(e=>e.id===void 0?null:this.getEntity(i.related_object,e.id)).filter(e=>e!==null))).filter(Boolean):(this.onError(Error(`Related object not found`)),[])}catch(e){this.onError(e)}return[]}async getPipelineEntity(e,t){return await this.get(`/pipelines/${e}/entity-records/${t}`)}async getCustomEntity(e,t){return await this.get(`/custom-objects/${e}/entity-records/${t}`)}async getObjectDetail(e){try{return await this.get(`/custom-objects/${e}/detail`)}catch(e){this.onError(e)}}refreshTimeline(){this.refreshTimelineForId(this.entityId)}refreshEntity(){this.refreshEntityForId(this.entityId)}},k=()=>{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=>{let n=(e+Math.random()*16)%16|0;return e=Math.floor(e/16),(t===`x`?n:n&3|8).toString(16)})},A=Object.getPrototypeOf(async function(){}).constructor,j=e=>{let t=`
6
+ ${this.scriptBody}`),this.setupExecutions++,this.executionTimer=performance.now(),this.afterSetup()}__cleanup(e){if(this.cleanupExecutions!==0)throw Error(`Cleanup must be called exactly once, and should never be called by a script directly.`);if(this.setupExecutions!==1)throw Error(`Cleanup was called before setup`);this.cleanupExecutions++,this.setIndicator(`none`);let 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(t,n){this.instance.postMessage(JSON.stringify({action:e.DONE,result:n,preserve:t}))}setState(t){this.instance.postMessage(JSON.stringify({action:e.SETSTATE,state:t}))}isRelativeUrl(e){return e.startsWith(`/`)}buildHeaders(e={}){return{...e,"X-Request-Type":`kizen-ui-scripting-api`}}refreshTimelineForId(t){t&&this.instance.postMessage(JSON.stringify({action:e.REFRESH_TIMELINE,entityId:t}))}refreshEntityForId(e){if(e)return this.refreshEntityHandler(e)}async installThirdPartyScript(e){try{let t=await this.installThirdPartyScriptHandler(e,this.args);return new s(this.instance,t.url)}catch{this.onError(Error(`Third party script ${e} could not be installed.`))}}releaseBlockingScript(){this.instance.postMessage(JSON.stringify({action:e.RELEASE_BLOCKING_SCRIPT}))}copyToClipboard(t){this.instance.postMessage(JSON.stringify({action:e.COPY_TO_CLIPBOARD,text:t}))}createDateObject(e){if(typeof e!=`string`)throw Error(`Invalid date string ${String(e)}`);if(!/^\d{4}-\d{2}-\d{2}$/.test(e))throw Error(`Date string ${e} is not in the format YYYY-MM-DD`);let t=e.split(`-`).map(e=>parseInt(e,10));if(t.length<3)throw 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()}},O=e=>e.object_type===`pipeline`||e.fetch_url===`pipeline`,k=class extends D{objectId;entityId;actionObjectId;actionEntityId;constructor({objectId:e,entityId:t,actionObjectId:n,actionEntityId:r,...i}){super(i),this.objectId=e,this.entityId=t,this.actionObjectId=n,this.actionEntityId=r,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(e,t){return e.fields?.[t]?.value}async getClientEntity(e){return await this.get(`/client/${e}`)}isClientObject(e){return e===this.clientObject?.id}async getEntity(e,t){try{return this.isClientObject(e)?await this.getClientEntity(t):O(await this.get(`/custom-objects/${e}`))?await this.getPipelineEntity(e,t):await this.getCustomEntity(e,t)}catch(e){this.onError(e)}}async getRelatedEntitiesForField(e,t,n){try{let r=(await this.getEntity(e,t)).fields?.[n];if(!r)return this.onError(Error(`Field not found for ID ${n}`)),[];let i=(await this.getObjectDetail(e))?.related_objects?.find(e=>e.field_id===r.id);return i?(await Promise.all(r.value.map(e=>e.id===void 0?null:this.getEntity(i.related_object,e.id)).filter(e=>e!==null))).filter(Boolean):(this.onError(Error(`Related object not found`)),[])}catch(e){this.onError(e)}return[]}async getPipelineEntity(e,t){return await this.get(`/pipelines/${e}/entity-records/${t}`)}async getCustomEntity(e,t){return await this.get(`/custom-objects/${e}/entity-records/${t}`)}async getObjectDetail(e){try{return await this.get(`/custom-objects/${e}/detail`)}catch(e){this.onError(e)}}refreshTimeline(){this.refreshTimelineForId(this.entityId)}refreshEntity(){this.refreshEntityForId(this.entityId)}},A=()=>{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=>{let n=(e+Math.random()*16)%16|0;return e=Math.floor(e/16),(t===`x`?n:n&3|8).toString(16)})},j=Object.getPrototypeOf(async function(){}).constructor,M=e=>{let t=`
7
7
  const __cleanup = this.__cleanup.bind(this);
8
8
  const __error = this.onError.bind(this);
9
9
  {
@@ -16,8 +16,8 @@ ${this.scriptBody}`),this.setupExecutions++,this.executionTimer=performance.now(
16
16
  } finally {
17
17
  __cleanup();
18
18
  }
19
- `;try{return{fn:new A(t),functionBody:t}}catch{let e=`
19
+ `;try{return{fn:new j(t),functionBody:t}}catch{let e=`
20
20
  this.__setup();
21
21
  this.onError({ message: "The script has a syntax error and could not be parsed" });
22
22
  this.__cleanup();
23
- `;return{fn:new A(e),functionBody:e}}},M=new class{promises;isDebug;constructor({isDebug:e=!1}){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,n){this.promises.set(e,{resolve:t,reject:n})}id(){return k()}register(e,t){let n=this.id();return this.set(n,e,t),n}resolve(e,t){this.get(e)?.resolve(t),this.delete(e)}reject(e,t){this.get(e)?.reject(t),this.delete(e)}}({isDebug:!1});self.onmessage=async e=>{let{action:n,script:r,setup:i,args:a,sessionData:o={},pluginComponentId:s,pluginApiName:c,location:l}=JSON.parse(e.data);if(n===t.RUN&&i&&r){let{fn:e,functionBody:t}=j(r),n=new O({user:i.user,teamMember:i.teamMember,business:i.business,entityId:i.entityId??``,objectId:i.objectId??``,actionObjectId:i.actionObjectId??``,actionEntityId:i.actionEntityId??``,clientObject:i.clientObject,appPath:i.appPath,isDebug:i.isDebug,scriptBody:r,functionBody:t,instance:self,kizenRequest:f(self,M),postFormData:p(self,M),uploadFile:g(self,M),installThirdPartyScript:_(self,M),args:a??``,sessionData:o,pluginComponentId:s,prompt:m(self,M),dynamicPrompt:h(self,M),refreshEntity:v(self,M),openCreateRecord:y(self,M),openCreateRelatedRecord:b(self,M),pluginApiName:c,location:l});await e.bind(n)()}else x(n,e,M)}})();
23
+ `;return{fn:new j(e),functionBody:e}}},N=new class{promises;isDebug;constructor({isDebug:e=!1}){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,n){this.promises.set(e,{resolve:t,reject:n})}id(){return A()}register(e,t){let n=this.id();return this.set(n,e,t),n}resolve(e,t){this.get(e)?.resolve(t),this.delete(e)}reject(e,t){this.get(e)?.reject(t),this.delete(e)}}({isDebug:!1});self.onmessage=async t=>{let{action:n,script:r,setup:i,args:a,sessionData:o={},pluginComponentId:s,pluginApiName:c,location:l}=JSON.parse(t.data);if(n===e.RUN&&i&&r){let{fn:e,functionBody:t}=M(r),n=new k({user:i.user,teamMember:i.teamMember,business:i.business,entityId:i.entityId??``,objectId:i.objectId??``,actionObjectId:i.actionObjectId??``,actionEntityId:i.actionEntityId??``,clientObject:i.clientObject,appPath:i.appPath,isDebug:i.isDebug,scriptBody:r,functionBody:t,instance:self,kizenRequest:p(self,N),postFormData:m(self,N),uploadFile:_(self,N),installThirdPartyScript:v(self,N),args:a??``,sessionData:o,pluginComponentId:s,prompt:h(self,N),dynamicPrompt:g(self,N),refreshEntity:y(self,N),openCreateRecord:b(self,N),openCreateRelatedRecord:x(self,N),pluginApiName:c,location:l});await e.bind(n)()}else S(n,t,N)}})();
@@ -0,0 +1 @@
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),s=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},c=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},l=(n,r,a)=>(a=n==null?{}:e(i(n)),c(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));export{s as n,l as r,o as t};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{j as t}from"./fa-core-B7dAyAZA.js";var n=e(t(),1),r=[`go`,`fmo`,`staging`,`integration`,`test1`],i=(0,n.createContext)({apiKey:``,userId:``,businessId:``,environment:`go`}),a=()=>(0,n.useContext)(i),o={credentials:`devtools-credentials`,activeProfile:`devtools-active-profile`,sidebarOpen:`devtools-sidebar-open`,sidebarWidth:`devtools-sidebar-width`,credsPanelOpen:`devtools-creds-open`,routesPanelOpen:`devtools-routes-open`,consolePanelOpen:`devtools-console-open`,proxyPanelOpen:`devtools-proxy-open`,buildPanelOpen:`devtools-build-open`,scriptRunnerLogging:`kizen-flag-script-runner-logging`,sandboxFramesEnabled:`frames-enabled`},s=null;function c(){return s===null&&(s=localStorage.getItem(o.activeProfile)??`credentials`),s}function l(e){s=e??`credentials`,localStorage.setItem(o.activeProfile,s)}var u=e=>`${c()}:kizen-plugin-config:${e}`,d=e=>`${c()}:kizen-plugin-user-config:${e}`,f=e=>`${c()}:calendar-harness-selection:${e}`,p=(e,t)=>`${c()}:kizen-sandbox:${e}:service:${t}:requestHistory`,m=e=>e?`:${e}`:``,h=(e,t=``)=>`${c()}:kizen-sandbox:${e}:selectedObject${m(t)}`,g=(e,t=``)=>`${c()}:kizen-sandbox:${e}:selectedEntity${m(t)}`,_=e=>`${c()}:kizen-sandbox:${e}:objectSettings:selectedObject`,v=e=>`floating-frame-pos-${e}`;export{d as a,h as c,i as d,a as f,u as i,p as l,f as n,_ as o,r as p,v as r,g as s,o as t,l as u};