@hailer/app-sdk 2.0.0-beta-13 → 2.0.0-beta-15
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/lib/app-sdk.js +1 -1
- package/lib/app-sdk.js.map +2 -2
- package/lib/modules/metrics.d.ts +32 -14
- package/lib/tools/minimal-password-prompt.d.ts +1 -0
- package/lib/tools/minimal-password-prompt.js +50 -0
- package/package.json +1 -1
- package/lib/modules/network.d.ts +0 -14
- package/lib/modules/process.d.ts +0 -38
- package/lib/modules/product-installed.d.ts +0 -40
- package/lib/modules/product-version.d.ts +0 -38
- package/lib/modules/public/product-version.d.ts +0 -16
- package/lib/modules/public/version.d.ts +0 -16
- package/lib/modules/version.d.ts +0 -16
- package/lib/src/constants.d.ts +0 -7
- package/lib/src/hailer-api.d.ts +0 -92
- package/lib/src/index.d.ts +0 -2
- package/lib/src/modules/activity/kanban.d.ts +0 -36
- package/lib/src/modules/activity.d.ts +0 -83
- package/lib/src/modules/app.d.ts +0 -12
- package/lib/src/modules/insight.d.ts +0 -36
- package/lib/src/modules/network.d.ts +0 -14
- package/lib/src/modules/permission.d.ts +0 -9
- package/lib/src/modules/process.d.ts +0 -38
- package/lib/src/modules/product-installed.d.ts +0 -40
- package/lib/src/modules/product-version.d.ts +0 -16
- package/lib/src/modules/product.d.ts +0 -104
- package/lib/src/modules/public/app.d.ts +0 -17
- package/lib/src/modules/public/form.d.ts +0 -31
- package/lib/src/modules/public/insight.d.ts +0 -30
- package/lib/src/modules/public/product-version.d.ts +0 -16
- package/lib/src/modules/public/product.d.ts +0 -27
- package/lib/src/modules/public.d.ts +0 -22
- package/lib/src/modules/ui/activity.d.ts +0 -30
- package/lib/src/modules/ui/files.d.ts +0 -18
- package/lib/src/modules/ui/snackbar.d.ts +0 -18
- package/lib/src/modules/ui.d.ts +0 -17
- package/lib/src/modules/user.d.ts +0 -36
- package/lib/src/modules/workflow.d.ts +0 -24
- package/lib/src/types.d.ts +0 -381
- package/lib/version.d.ts +0 -0
package/lib/app-sdk.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
var Z=Object.create;var K=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var re=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var j=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports);var ne=(o,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of te(e))!ie.call(o,r)&&r!==t&&K(o,r,{get:()=>e[r],enumerable:!(i=ee(e,r))||i.enumerable});return o};var se=(o,e,t)=>(t=o!=null?Z(re(o)):{},ne(e||!o||!o.__esModule?K(t,"default",{value:o,enumerable:!0}):t,o));var J=j(d=>{"use strict";var oe=d&&d.__awaiter||function(o,e,t,i){function r(s){return s instanceof t?s:new t(function(a){a(s)})}return new(t||(t=Promise))(function(s,a){function u(c){try{l(i.next(c))}catch(E){a(E)}}function m(c){try{l(i.throw(c))}catch(E){a(E)}}function l(c){c.done?s(c.value):r(c.value).then(u,m)}l((i=i.apply(o,e||[])).next())})};Object.defineProperty(d,"__esModule",{value:!0});d.Client=void 0;var B=class{constructor(e,t){this.write=e,this.requests={},this.id=0,this.mtu=65535,t&&t.mtu&&(this.mtu=t.mtu)}destroy(){this.requests=null,this.write=null}messageReceived(e){let t=!!(e.err||e.ack||e.fin),i=e.ack||e.err||e.sig||e.fin,r=this.requests[i],s;if(r&&typeof r.cb=="function"){let a;e.fin?r.cb.call(r.context,null,null,!0):r.canceled?console.log("This request is canceled. Not calling the callback."):(a=e.err?e.data:null,s=r.cb.call(r.context,a,e.data,t))}return t&&delete this.requests[i],s}requestAsync(e,t){return oe(this,void 0,void 0,function*(){return new Promise((i,r)=>{this.request(e,t,(s,a)=>{if(s)return r(a);i(a)})})})}request(e,t,i){this.id++;let r={op:e};return Array.isArray(t)&&(r.args=t),i&&(r.id=this.id,this.requests[r.id]={cb:i,context:{id:r.id,cancel:()=>{setTimeout((s=>()=>{this.requests[s]&&console.log("rpc-client.js: timeout, the request has not been removed while it was canceled",s,this.requests[s])})(r.id),1500),this.requests[r.id].canceled=!0,this.write({end:r.id})},emit:s=>this.write({sig:r.id,data:s})}}),this.write(r),r.id||null}send(e,t){this.write({push:e,data:t})}end(e){this.write({end:e})}};d.Client=B});var z=j(y=>{"use strict";Object.defineProperty(y,"__esModule",{value:!0});y.Server=void 0;var h=console.log,N=class{constructor(e){this.modules={},this.methods={},this.requests={},this.clientIdCounter=0,this.requestId=0,this.invokeId=0,e&&this.insertMethods(e)}destroy(){for(let e in this.requests){for(let t in this.requests[e])typeof this.requests[e][t].end=="function"&&this.requests[e][t].end();delete this.requests[e]}}insertMethods(e){this.addMethods("",e)}addMethods(e,t){let i=e?e+".":"";for(let r in t)if(r!=="_"){if(r.substring(0,1)!=="_"&&t["_"+r])if(typeof t[r]=="function"){let s=t["_"+r].name||r;t["_"+r].fullname=i+s;try{this.modules[i+s]=t["_"+r],this.methods[i+s]=t[r]}catch(a){console.log("Kaboom! ",a)}}else typeof t[r]=="object"&&this.addMethods(i+r,t[r])}}listMethods(e,t,i){let r={};function s(u,m){let l={};for(let c in u)m[c]||(l[c]=u[c]);return l}let a={fullname:!0};for(let u in this.modules)r[u]=s(this.modules[u],a);i(null,r)}clientOffline(e){for(let t in this.requests[e])typeof this.requests[e][t].end=="function"&&this.requests[e][t].end(),delete this.requests[e][t]}closeAll(){for(let e in this.requests)for(let t in this.requests[e])typeof this.requests[e][t].end=="function"&&this.requests[e][t].end(),delete this.requests[e][t]}parse(e,t,i,r){if(typeof r=="number")try{if(e.push){this.requests[r]&&this.requests[r][e.push]&&this.invokeRaw(e,t,this.requests[r][e.push].context,r);return}if(e.sig){this.requests[r]&&this.requests[r][e.sig]&&this.invokeRaw(e,t,this.requests[r][e.sig].context,r);return}if(e.end){let s=e.end;if(this.requests[r]&&this.requests[r][s]){typeof this.requests[r][s].end=="function"&&this.requests[r][s].end(),t({fin:s}),delete this.requests[r][s];return}if(!this.requests[r][s])return;typeof this.requests[r][s].end=="function"&&this.requests[s].end();return}if(e.op==="methods"){this.listMethods(e.args,i,function(s,a){t({ack:e.id,data:a})});return}if(typeof this.methods[e.op]>"u"){t({err:e.id,data:{code:300,msg:"No method found: "+e.op}});return}this.invokeRaw(e,t,i,r)}catch(s){h("Dynamic RPC failed to execute ",e.op,s,s.stack);try{console.log("RPC caught error",s.stack),t({ack:e.id,err:e.id,data:"caught error in "+e.op+": "+s.toString(),debug:s.stack})}catch(a){t({err:e.id,data:"rpc",errmsg:a.toString()})}}}emit(e,t){for(let i in this.requests)if(this.requests[i]){for(let r in this.requests[i])if(this.requests[i][r].op===e){let{send:s}=this.requests[i][r];s({sig:r,data:t})}}}invokeRaw(e,t,i,r){if(++this.requestId,!this.requests[r])return console.log("Session not opened for client. Use Server.open() first");if(e.push){let s=this.requests[r][e.push];if(e.data===null){console.log("msg.data is null:",e);return}s.data(e.data);return}if(e.sig){let s=this.requests[r][e.sig];try{this.methods[s.op].call(this.requests[r][e.sig],e.data,{send:a=>{typeof s.end=="function"&&s.end(),this.requests[r][e.sig]&&delete this.requests[r][e.sig],t({ack:e.sig,data:a})},emit:a=>(this.requests[r][e.sig]||typeof s.end=="function"&&s.end(),t({sig:e.sig,data:a})),error:a=>{typeof s.end=="function"&&s.end(),delete this.requests[r][e.sig],t({err:e.sig,data:a})},close:a=>{typeof s.end=="function"&&s.end(),delete this.requests[r][e.sig],t({fin:e.sig})}},i)}catch(a){console.log("Calling the method in RPC failed:",e.op,e.args,a.stack),delete this.requests[r][e.sig],t({err:e.sig,data:{msg:"rpc failed during execution of "+e.op,code:578}})}return}if(typeof e.id>"u"){let s={};this.methods[e.op].call(s,{args:e.args},{send:()=>{h("Trying to send response to event ("+e.op+"). Dropping.")},emit:()=>{h("Trying to emit response to event ("+e.op+"). Dropping.")},error:()=>{h("Trying to respond with error to event ("+e.op+"). Dropping.")},close:()=>{h("Trying to close event ("+e.op+"). Dropping.")}},i)}else{let s={id:e.id,op:e.op,args:e.args,context:i,end:null,send:t};this.requests[r]||(this.requests[r]={}),this.requests[r][e.id]&&(console.log("Serious warning. There is already a request by that id, we'll kill it off! This session is likely not clean. clientId:",r,"msg",e,"stack trace:",new Error().stack),typeof this.requests[r][e.id].end=="function"&&this.requests[r][e.id].end(),delete this.requests[r][e.id],console.log("Removed old request by same id from same client...")),this.requests[r][e.id]=s;try{this.methods[e.op].call(s,{args:e.args},{send:a=>{typeof s.end=="function"&&s.end(),this.requests[r][e.id]&&delete this.requests[r][e.id],t({ack:e.id,data:a})},emit:a=>(this.requests[r][e.id]||typeof s.end=="function"&&s.end(),t({sig:e.id,data:a})),error:a=>{typeof s.end=="function"&&s.end(),delete this.requests[r][e.id],t({err:e.id,data:a})},close:a=>{typeof s.end=="function"&&s.end(),delete this.requests[r][e.id],t({fin:e.id})}},i)}catch(a){console.log("Calling the method in RPC failed:",e.op,e.args,a.stack),delete this.requests[r][e.id],t({err:e.id,data:{msg:"rpc failed during execution of "+e.op,code:578}})}}}close(e){for(let t in this.requests[e])typeof this.requests[e][t].end=="function"&&this.requests[e][t].end(),delete this.requests[e][t];delete this.requests[e]}open(){let e=++this.clientIdCounter;return this.requests[e]={},e}};y.Server=N});var Y=j(p=>{"use strict";var ae=p&&p.__createBinding||(Object.create?function(o,e,t,i){i===void 0&&(i=t),Object.defineProperty(o,i,{enumerable:!0,get:function(){return e[t]}})}:function(o,e,t,i){i===void 0&&(i=t),o[i]=e[t]}),G=p&&p.__exportStar||function(o,e){for(var t in o)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&ae(e,o,t)};Object.defineProperty(p,"__esModule",{value:!0});G(J(),p);G(z(),p)});var X=se(Y(),1);var V=class extends Error{constructor(e,t){super(e),this.name=this.constructor.name,this.msg=e,this.code=t,Error.captureStackTrace?.(this,this.constructor)}},n=class extends V{constructor(e){super(e.msg,e.code),this.details=e.details,this.debug=e.debug}toString(){return console.log("Going to log an error... ;-D"),`${super.toString()}
|
|
2
|
-
Field: ${this.details}, ${this.debug}`}};var f=class{constructor(e){this.client=e}async get(e){try{return await this.client.requestAsync("user.get",[e])}catch(t){throw new n(t)}}async current(){try{return await this.client.requestAsync("user.current",[])}catch(e){throw new n(e)}}async list(){try{return await this.client.requestAsync("user.list",[])}catch(e){throw new n(e)}}};var b=class{constructor(e){this.client=e}async list(e,t){try{return await this.client.requestAsync("activity.kanban.list",[e,...t?[t]:[]])}catch(i){throw new n(i)}}async load(e){try{return await this.client.requestAsync("activity.kanban.load",[e])}catch(t){throw new n(t)}}async updatePriority(e,t){try{return await this.client.requestAsync("activity.kanban.updatePriority",[{activityId:e,priority:t}])}catch(i){throw new n(i)}}};var w=class{constructor(e){this.client=e;this.kanban=new b(e)}async list(e,t,i){try{return await this.client.requestAsync("activity.list",[e,t,i])}catch(r){throw new n(r)}}async get(e){try{return await this.client.requestAsync("activity.get",[e])}catch(t){throw new n(t)}}async create(e,t,i){try{return await this.client.requestAsync("activity.create",[e,t,...i?[i]:[]])}catch(r){throw new n(r)}}async update(e,t){try{return await this.client.requestAsync("activity.update",[e,...t?[t]:[]])}catch(i){throw new n(i)}}async remove(e){try{return await this.client.requestAsync("activity.remove",[e])}catch(t){throw new n(t)}}};var A=class{constructor(e){this.client=e;this.product={publishTemplate:this.publishTemplate.bind(this),isProductInstalled:this.isProductInstalled.bind(this),get:this.get.bind(this),install:this.install.bind(this),getManifest:this.getManifest.bind(this)}}async current(){try{return await this.client.requestAsync("workspace.current",[])}catch(e){throw new n(e)}}async list(){try{return await this.client.requestAsync("workspace.list",[])}catch(e){throw new n(e)}}async publishTemplate(e){try{return await this.client.requestAsync("workspace.product.publishTemplate",[e])}catch(t){throw new n(t)}}async isProductInstalled(e,t){try{return await this.client.requestAsync("workspace.product.isProductInstalled",[e,t])}catch(i){throw new n(i)}}async get(e){try{return await this.client.requestAsync("workspace.product.get",[e])}catch(t){throw new n(t)}}async install(e,t){try{return await this.client.requestAsync("workspace.product.install",[e,t])}catch(i){throw new n(i)}}async getManifest(e){try{return await this.client.requestAsync("workspace.product.getManifest",[e])}catch(t){throw new n(t)}}};var P=class{constructor(e){this.client=e}async open(e,t){await this.client.requestAsync("ui.activity.open",[e,...t?[t]:[]])}async create(e,t){return await this.client.requestAsync("ui.activity.create",[e,...t?[t]:[]])}async editMultiple(e){return await this.client.requestAsync("ui.activity.editMultiple",[e])}};var v=class{constructor(e){this.client=e}async open(e,t,i){await this.client.requestAsync("ui.snackbar.open",[e,t,i])}};var k=class{constructor(e){this.client=e}async uploadFile(e,t,i){return await this.client.requestAsync("ui.file.upload",[await this.toBase64(e),t,!!i?.isPublic])}toBase64(e){return new Promise((t,i)=>{let r=new FileReader;r.readAsDataURL(e),r.onload=()=>t(r.result??""),r.onerror=i})}};var q=class{constructor(e){this.client=e;this.function={edit:async(e,t)=>{await this.client.requestAsync("ui.workflow.function.edit",[e,t])}}}};var x=class{constructor(e){this.client=e;this.activity=new P(e),this.snackbar=new v(e),this.workflow=new q(e),this.insight={create:async t=>{await e.requestAsync("ui.insight.create",[t])},edit:async t=>{await e.requestAsync("ui.insight.edit",[t])},delete:async t=>{await e.requestAsync("ui.insight.delete",[t])},permission:async t=>{await e.requestAsync("ui.insight.permission",[t])}},this.files=new k(e)}};var $=["https://app.hailer.com","https://next.hailer.com","https://testapp.hailer.biz","https://app.hailer.biz","https://app.hailer.local.gd","https://app.k8s.hailer.com","https://next.k8s.hailer.com","https://localhost:9443"],g="https://api.hailer.com",Q={"https://app.hailer.com":g,"https://next.hailer.com":g,"https://app.hailer.biz":"https://api.hailer.biz","https://testapp.hailer.biz":"https://testapi.hailer.biz","https://app.hailer.local.gd":"https://api.hailer.local.gd","https://app.k8s.hailer.com":"https://api.k8s.hailer.com","https://next.k8s.hailer.com":"https://api.k8s.hailer.com","https://localhost:9443":"http://localhost:1337"};var R=class{constructor(e){this.options=e}async config(){let e="manifest.json",t=window.location.origin+window.location.pathname,i=t+e;t.endsWith("/index.html")&&(i=t.slice(0,-10)+e);let r=await(await fetch(i)).text(),a=JSON.parse(r).appId;return await(await fetch(this.options.publicBackendUrl+"/api/v3/app/public",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify([a])})).json()}};var I=class{constructor(e){this.options=e}async data(e){let t=await fetch(this.options.publicBackendUrl+"/api/v2/forms/process/get",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify([e])});if(!t.ok)throw new n(await t.json());return await t.json()}async submit(e,t){let i=await fetch(this.options.publicBackendUrl+"/api/v2/forms/activity/create",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify([e,t])});if(!i.ok)throw new n(await i.json());return await i.json()}};var T=class{constructor(e){this.options=e}async data(e){let t=await fetch(this.options.publicBackendUrl+"/api/v3/insight/public",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify([e])});if(!t.ok)throw new n(await t.json());return await t.json()}async dataAsObject(e){let i=(await this.data(e)).data,r=[];return i.rows.forEach(s=>{let a={};i.headers.forEach((u,m)=>{a[u]=s[m]}),r.push(a)}),r}};var S=class{constructor(e){this.options=e}async list(e,t){let i=await fetch(this.options.publicBackendUrl+"/api/v3/product/list",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify([e,t])});if(!i.ok)throw new n(await i.json());return await i.json()}async get(e){let t=await fetch(this.options.publicBackendUrl+"/api/v3/product/get",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify([e])});if(!t.ok)throw new n(await t.json());return await t.json()}};var C=class{constructor(e){this.insight=new T(e),this.form=new I(e),this.app=new R(e),this.product=new S(e)}};var U=class{constructor(e){this.client=e}async list(){try{return await this.client.requestAsync("workflow.list",[])}catch(e){throw console.error(e.msg,e),new n(e)}}async get(e){try{return await this.client.requestAsync("workflow.get",[e])}catch(t){throw new n(t)}}async install(e,t){try{return await this.client.requestAsync("workflow.install",[e,t])}catch(i){throw new n(i)}}};var O=class{constructor(e){this.client=e;this.config={update:async(e,t)=>{try{return await this.client.requestAsync("app.config.update",[e,...t?[t]:[]])}catch(i){throw console.log("Errorasd ",i),new n(i)}}};this.product={isProductInstalled:this.isProductInstalled.bind(this),get:this.get.bind(this),install:this.install.bind(this),getInstalledVersion:this.getInstalledVersion.bind(this),getManifest:this.getManifest.bind(this)}}async isProductInstalled(e,t){try{return await this.client.requestAsync("app.product.isProductInstalled",[e,t])}catch(i){throw new n(i)}}async get(e){try{return await this.client.requestAsync("app.product.get",[e])}catch(t){throw new n(t)}}async install(e,t){try{return await this.client.requestAsync("app.product.install",[e,t])}catch(i){throw new n(i)}}async getInstalledVersion(e){try{return await this.client.requestAsync("app.product.getInstalledVersion",[e])}catch(t){throw new n(t)}}async getManifest(e){try{return await this.client.requestAsync("app.product.getManifest",[e])}catch(t){throw new n(t)}}};var L=class{constructor(e){this.client=e}async data(e,t){try{return await this.client.requestAsync("insight.data",[e,...t?[t]:[]])}catch(i){throw new n(i)}}async list(){try{return await this.client.requestAsync("insight.list",[])}catch(e){throw new n(e)}}async update(e,t){try{return await this.client.requestAsync("insight.update",[e,t])}catch(i){throw new n(i)}}};var _=class{constructor(e){this.client=e;this.map=async()=>{try{return await this.client.requestAsync("permission.map",[])}catch(e){throw console.log("Failed to read permissions from Hailer, error:",e),new n(e)}}}};var D=class{constructor(e){this.client=e}async list(e,t){try{return await this.client.requestAsync("product.list",[e,t])}catch(i){throw new n(i)}}async get(e){try{return await this.client.requestAsync("product.get",[e])}catch(t){throw new n(t)}}async create(e){try{return await this.client.requestAsync("product.create",[e])}catch(t){throw new n(t)}}async update(e,t){try{return await this.client.requestAsync("product.update",[e,t])}catch(i){throw new n(i)}}async remove(e){try{return await this.client.requestAsync("product.remove",[e])}catch(t){throw new n(t)}}async setPublic(e,t){try{return await this.client.requestAsync("product.setPublic",[e,t])}catch(i){throw new n(i)}}};var W=class{constructor(e){this.client=e}async createPricing(e){try{return await this.client.requestAsync("payment.createPricing",[e])}catch(t){throw new n(t)}}async updatePricing(e){try{return await this.client.requestAsync("payment.updatePricing",[e])}catch(t){throw new n(t)}}async getPricing(e){try{return await this.client.requestAsync("payment.getPricing",[{productId:e}])}catch(t){throw new n(t)}}async createPurchase(e){try{return await this.client.requestAsync("payment.createPurchase",[e])}catch(t){throw new n(t)}}async getPurchases(e){try{return await this.client.requestAsync("payment.getPurchases",[{workspaceId:e}])||[]}catch(t){throw new n(t)}}async calculateStripeTax(e){try{return await this.client.requestAsync("payment.calculateStripeTax",[e])}catch(t){throw new n(t)}}};var M=class{constructor(e){this.client=e}async listWorkspaces(e){try{return await this.client.requestAsync("admin.workspace.list",[e?.filter,e?.options])}catch(t){throw new n(t)}}async getWorkspace(e){try{return await this.client.requestAsync("admin.workspace.get",[e])}catch(t){throw new n(t)}}async createStripeSession(e){try{return await this.client.requestAsync("admin.workspace.createStripeSession",[e])}catch(t){throw new n(t)}}async createInvoiceIntegration(e){try{return await this.client.requestAsync("admin.workspace.createInvoiceIntegration",[e])}catch(t){throw new n(t)}}async updateWorkspaceSubscription(e){try{return await this.client.requestAsync("admin.workspace.updateSubscription",[e])}catch(t){throw new n(t)}}async updatePurchasePrice(e){try{return await this.client.requestAsync("admin.purchase.updatePrice",[e])}catch(t){throw new n(t)}}async listWorkspaceUsers(e){try{return await this.client.requestAsync("admin.workspace.listUsers",[e.workspaceId,e.filter,e.options])}catch(t){throw new n(t)}}async updateUser(e){try{return await this.client.requestAsync("admin.user.update",[e.userId,e.updates])}catch(t){throw new n(t)}}async updateTokenBalance(e){try{return await this.client.requestAsync("admin.workspace.updateTokenBalance",[e])}catch(t){throw new n(t)}}async updateWorkspaceOverrides(e){try{return await this.client.requestAsync("admin.workspace.updateOverrides",[e])}catch(t){throw new n(t)}}async updateWorkspaceMarketplaceSettings(e){try{return await this.client.requestAsync("admin.workspace.updateMarketplaceSettings",[e])}catch(t){throw new n(t)}}async listTokenTransactions(e){try{return await this.client.requestAsync("admin.tokenTransaction.list",[e?.filter,e?.options])}catch(t){throw new n(t)}}async listInvoices(e){try{return await this.client.requestAsync("admin.invoice.list",[e?.filter,e?.options])}catch(t){throw new n(t)}}async updateInvoiceHandled(e){try{return await this.client.requestAsync("admin.invoice.updateHandled",[e.purchaseIds,e.handled])}catch(t){throw new n(t)}}async listMonthlyRevenue(e){try{return await this.client.requestAsync("admin.revenue.list",[e.month,e.year,e.filter,e.options])}catch(t){throw new n(t)}}async getDashboardStatistics(e){try{return await this.client.requestAsync("admin.dashboard.statistics",[e])}catch(t){throw new n(t)}}async getDashboardTrends(e,t){try{return await this.client.requestAsync("admin.dashboard.trends",[e,t])}catch(i){throw new n(i)}}};var F=class{constructor(e){this.client=e;this.admin={workspacesList:async e=>{try{return await this.client.requestAsync("admin.workspace.metricsList",[e])}catch(t){throw new n(t)}}}}async list(e){try{return await this.client.requestAsync("metrics.list",e?[e]:[])}catch(t){throw new n(t)}}async get(e,t){try{let i=Array.isArray(e)?e:[e];return await this.client.requestAsync("metrics.get",[i,t])}catch(i){throw new n(i)}}};var H=class{constructor(e={}){this.options=e;this.outside=null;let t=e.allowedUrls??$;this.client=new X.Client(r=>{this.hostUrl&&parent.postMessage(JSON.stringify(r),this.hostUrl)}),this.user=new f(this.client),this.app=new O(this.client),this.activity=new w(this.client),this.insight=new L(this.client),this.workspace=new A(this.client),this.workflow=new U(this.client),this.permission=new _(this.client),this.public=new C(this.options),this.ui=new x(this.client),this.product=new D(this.client),this.payment=new W(this.client),this.admin=new M(this.client),this.metrics=new F(this.client);let i=JSON.stringify({op:"register",args:[{appApiVersion:"2"}]});window.location===window.parent.location?(this.options.publicBackendUrl||(this.options.publicBackendUrl=g),this.public.app.config().then(r=>{this.outside=!0,this.options.outside?.(r)}).catch(r=>{this.options.error?.(r),console.error("Failed to get app configuration in Public App.",r)})):(t.forEach(r=>parent.postMessage(i,r)),this.timer=setTimeout(()=>{this.outside=!0,this.options.outside?.()},100)),this.createEventListener()}createEventListener(){window.addEventListener("message",async e=>{let t=e.data;try{let i=JSON.parse(t);if(i.op==="register"){if(this.appId){console.error("App Id is already set...! Are you using hot-reload?");return}clearTimeout(this.timer),this.appId=i.data.appId,this.workspaceId=i.data.workspaceId,this.hostUrl=e.origin,this.options.publicBackendUrl||(this.options.publicBackendUrl=Q[this.hostUrl]||g),this.client.request("ui.settings",[],(r,s,a)=>{if(r){console.log("ui.settings error:",r,s);return}this.options.settings?.(s)}),this.client.request("config",[],(r,s,a)=>{if(r){console.log("config error:",r,s);return}this.options.config?.(s)}),this.client.request("signal",[],(r,s,a)=>{if(r){console.log("signal error:",r,s);return}s&&this.options.signals?.(s)}),this.outside=!1,this.options.connected?.();return}if(!this.appId)return;this.client.messageReceived(i)}catch{console.log("Dropped invalid JSON message")}})}info(){return{hostUrl:this.hostUrl,config:this.config,outside:this.outside,workspaceId:this.workspaceId}}};export{H as HailerApi,n as HailerError,F as MetricsApi};
|
|
2
|
+
Field: ${this.details}, ${this.debug}`}};var f=class{constructor(e){this.client=e}async get(e){try{return await this.client.requestAsync("user.get",[e])}catch(t){throw new n(t)}}async current(){try{return await this.client.requestAsync("user.current",[])}catch(e){throw new n(e)}}async list(){try{return await this.client.requestAsync("user.list",[])}catch(e){throw new n(e)}}};var b=class{constructor(e){this.client=e}async list(e,t){try{return await this.client.requestAsync("activity.kanban.list",[e,...t?[t]:[]])}catch(i){throw new n(i)}}async load(e){try{return await this.client.requestAsync("activity.kanban.load",[e])}catch(t){throw new n(t)}}async updatePriority(e,t){try{return await this.client.requestAsync("activity.kanban.updatePriority",[{activityId:e,priority:t}])}catch(i){throw new n(i)}}};var w=class{constructor(e){this.client=e;this.kanban=new b(e)}async list(e,t,i){try{return await this.client.requestAsync("activity.list",[e,t,i])}catch(r){throw new n(r)}}async get(e){try{return await this.client.requestAsync("activity.get",[e])}catch(t){throw new n(t)}}async create(e,t,i){try{return await this.client.requestAsync("activity.create",[e,t,...i?[i]:[]])}catch(r){throw new n(r)}}async update(e,t){try{return await this.client.requestAsync("activity.update",[e,...t?[t]:[]])}catch(i){throw new n(i)}}async remove(e){try{return await this.client.requestAsync("activity.remove",[e])}catch(t){throw new n(t)}}};var A=class{constructor(e){this.client=e;this.product={publishTemplate:this.publishTemplate.bind(this),isProductInstalled:this.isProductInstalled.bind(this),get:this.get.bind(this),install:this.install.bind(this),getManifest:this.getManifest.bind(this)}}async current(){try{return await this.client.requestAsync("workspace.current",[])}catch(e){throw new n(e)}}async list(){try{return await this.client.requestAsync("workspace.list",[])}catch(e){throw new n(e)}}async publishTemplate(e){try{return await this.client.requestAsync("workspace.product.publishTemplate",[e])}catch(t){throw new n(t)}}async isProductInstalled(e,t){try{return await this.client.requestAsync("workspace.product.isProductInstalled",[e,t])}catch(i){throw new n(i)}}async get(e){try{return await this.client.requestAsync("workspace.product.get",[e])}catch(t){throw new n(t)}}async install(e,t){try{return await this.client.requestAsync("workspace.product.install",[e,t])}catch(i){throw new n(i)}}async getManifest(e){try{return await this.client.requestAsync("workspace.product.getManifest",[e])}catch(t){throw new n(t)}}};var P=class{constructor(e){this.client=e}async open(e,t){await this.client.requestAsync("ui.activity.open",[e,...t?[t]:[]])}async create(e,t){return await this.client.requestAsync("ui.activity.create",[e,...t?[t]:[]])}async editMultiple(e){return await this.client.requestAsync("ui.activity.editMultiple",[e])}};var v=class{constructor(e){this.client=e}async open(e,t,i){await this.client.requestAsync("ui.snackbar.open",[e,t,i])}};var k=class{constructor(e){this.client=e}async uploadFile(e,t,i){return await this.client.requestAsync("ui.file.upload",[await this.toBase64(e),t,!!i?.isPublic])}toBase64(e){return new Promise((t,i)=>{let r=new FileReader;r.readAsDataURL(e),r.onload=()=>t(r.result??""),r.onerror=i})}};var q=class{constructor(e){this.client=e;this.function={edit:async(e,t)=>{await this.client.requestAsync("ui.workflow.function.edit",[e,t])}}}};var x=class{constructor(e){this.client=e;this.activity=new P(e),this.snackbar=new v(e),this.workflow=new q(e),this.insight={create:async t=>{await e.requestAsync("ui.insight.create",[t])},edit:async t=>{await e.requestAsync("ui.insight.edit",[t])},delete:async t=>{await e.requestAsync("ui.insight.delete",[t])},permission:async t=>{await e.requestAsync("ui.insight.permission",[t])}},this.files=new k(e)}};var $=["https://app.hailer.com","https://next.hailer.com","https://testapp.hailer.biz","https://app.hailer.biz","https://app.hailer.local.gd","https://app.k8s.hailer.com","https://next.k8s.hailer.com","https://localhost:9443"],g="https://api.hailer.com",Q={"https://app.hailer.com":g,"https://next.hailer.com":g,"https://app.hailer.biz":"https://api.hailer.biz","https://testapp.hailer.biz":"https://testapi.hailer.biz","https://app.hailer.local.gd":"https://api.hailer.local.gd","https://app.k8s.hailer.com":"https://api.k8s.hailer.com","https://next.k8s.hailer.com":"https://api.k8s.hailer.com","https://localhost:9443":"http://localhost:1337"};var R=class{constructor(e){this.options=e}async config(){let e="manifest.json",t=window.location.origin+window.location.pathname,i=t+e;t.endsWith("/index.html")&&(i=t.slice(0,-10)+e);let r=await(await fetch(i)).text(),a=JSON.parse(r).appId;return await(await fetch(this.options.publicBackendUrl+"/api/v3/app/public",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify([a])})).json()}};var I=class{constructor(e){this.options=e}async data(e){let t=await fetch(this.options.publicBackendUrl+"/api/v2/forms/process/get",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify([e])});if(!t.ok)throw new n(await t.json());return await t.json()}async submit(e,t){let i=await fetch(this.options.publicBackendUrl+"/api/v2/forms/activity/create",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify([e,t])});if(!i.ok)throw new n(await i.json());return await i.json()}};var T=class{constructor(e){this.options=e}async data(e){let t=await fetch(this.options.publicBackendUrl+"/api/v3/insight/public",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify([e])});if(!t.ok)throw new n(await t.json());return await t.json()}async dataAsObject(e){let i=(await this.data(e)).data,r=[];return i.rows.forEach(s=>{let a={};i.headers.forEach((u,m)=>{a[u]=s[m]}),r.push(a)}),r}};var S=class{constructor(e){this.options=e}async list(e,t){let i=await fetch(this.options.publicBackendUrl+"/api/v3/product/list",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify([e,t])});if(!i.ok)throw new n(await i.json());return await i.json()}async get(e){let t=await fetch(this.options.publicBackendUrl+"/api/v3/product/get",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify([e])});if(!t.ok)throw new n(await t.json());return await t.json()}};var C=class{constructor(e){this.insight=new T(e),this.form=new I(e),this.app=new R(e),this.product=new S(e)}};var U=class{constructor(e){this.client=e}async list(){try{return await this.client.requestAsync("workflow.list",[])}catch(e){throw console.error(e.msg,e),new n(e)}}async get(e){try{return await this.client.requestAsync("workflow.get",[e])}catch(t){throw new n(t)}}async install(e,t){try{return await this.client.requestAsync("workflow.install",[e,t])}catch(i){throw new n(i)}}};var O=class{constructor(e){this.client=e;this.config={update:async(e,t)=>{try{return await this.client.requestAsync("app.config.update",[e,...t?[t]:[]])}catch(i){throw console.log("Errorasd ",i),new n(i)}}};this.product={isProductInstalled:this.isProductInstalled.bind(this),get:this.get.bind(this),install:this.install.bind(this),getInstalledVersion:this.getInstalledVersion.bind(this),getManifest:this.getManifest.bind(this)}}async isProductInstalled(e,t){try{return await this.client.requestAsync("app.product.isProductInstalled",[e,t])}catch(i){throw new n(i)}}async get(e){try{return await this.client.requestAsync("app.product.get",[e])}catch(t){throw new n(t)}}async install(e,t){try{return await this.client.requestAsync("app.product.install",[e,t])}catch(i){throw new n(i)}}async getInstalledVersion(e){try{return await this.client.requestAsync("app.product.getInstalledVersion",[e])}catch(t){throw new n(t)}}async getManifest(e){try{return await this.client.requestAsync("app.product.getManifest",[e])}catch(t){throw new n(t)}}};var L=class{constructor(e){this.client=e}async data(e,t){try{return await this.client.requestAsync("insight.data",[e,...t?[t]:[]])}catch(i){throw new n(i)}}async list(){try{return await this.client.requestAsync("insight.list",[])}catch(e){throw new n(e)}}async update(e,t){try{return await this.client.requestAsync("insight.update",[e,t])}catch(i){throw new n(i)}}};var _=class{constructor(e){this.client=e;this.map=async()=>{try{return await this.client.requestAsync("permission.map",[])}catch(e){throw console.log("Failed to read permissions from Hailer, error:",e),new n(e)}}}};var M=class{constructor(e){this.client=e}async list(e,t){try{return await this.client.requestAsync("product.list",[e,t])}catch(i){throw new n(i)}}async get(e){try{return await this.client.requestAsync("product.get",[e])}catch(t){throw new n(t)}}async create(e){try{return await this.client.requestAsync("product.create",[e])}catch(t){throw new n(t)}}async update(e,t){try{return await this.client.requestAsync("product.update",[e,t])}catch(i){throw new n(i)}}async remove(e){try{return await this.client.requestAsync("product.remove",[e])}catch(t){throw new n(t)}}async setPublic(e,t){try{return await this.client.requestAsync("product.setPublic",[e,t])}catch(i){throw new n(i)}}};var D=class{constructor(e){this.client=e}async createPricing(e){try{return await this.client.requestAsync("payment.createPricing",[e])}catch(t){throw new n(t)}}async updatePricing(e){try{return await this.client.requestAsync("payment.updatePricing",[e])}catch(t){throw new n(t)}}async getPricing(e){try{return await this.client.requestAsync("payment.getPricing",[{productId:e}])}catch(t){throw new n(t)}}async createPurchase(e){try{return await this.client.requestAsync("payment.createPurchase",[e])}catch(t){throw new n(t)}}async getPurchases(e){try{return await this.client.requestAsync("payment.getPurchases",[{workspaceId:e}])||[]}catch(t){throw new n(t)}}async calculateStripeTax(e){try{return await this.client.requestAsync("payment.calculateStripeTax",[e])}catch(t){throw new n(t)}}};var W=class{constructor(e){this.client=e}async listWorkspaces(e){try{return await this.client.requestAsync("admin.workspace.list",[e?.filter,e?.options])}catch(t){throw new n(t)}}async getWorkspace(e){try{return await this.client.requestAsync("admin.workspace.get",[e])}catch(t){throw new n(t)}}async createStripeSession(e){try{return await this.client.requestAsync("admin.workspace.createStripeSession",[e])}catch(t){throw new n(t)}}async createInvoiceIntegration(e){try{return await this.client.requestAsync("admin.workspace.createInvoiceIntegration",[e])}catch(t){throw new n(t)}}async updateWorkspaceSubscription(e){try{return await this.client.requestAsync("admin.workspace.updateSubscription",[e])}catch(t){throw new n(t)}}async updatePurchasePrice(e){try{return await this.client.requestAsync("admin.purchase.updatePrice",[e])}catch(t){throw new n(t)}}async listWorkspaceUsers(e){try{return await this.client.requestAsync("admin.workspace.listUsers",[e.workspaceId,e.filter,e.options])}catch(t){throw new n(t)}}async updateUser(e){try{return await this.client.requestAsync("admin.user.update",[e.userId,e.updates])}catch(t){throw new n(t)}}async updateTokenBalance(e){try{return await this.client.requestAsync("admin.workspace.updateTokenBalance",[e])}catch(t){throw new n(t)}}async updateWorkspaceOverrides(e){try{return await this.client.requestAsync("admin.workspace.updateOverrides",[e])}catch(t){throw new n(t)}}async updateWorkspaceMarketplaceSettings(e){try{return await this.client.requestAsync("admin.workspace.updateMarketplaceSettings",[e])}catch(t){throw new n(t)}}async listTokenTransactions(e){try{return await this.client.requestAsync("admin.tokenTransaction.list",[e?.filter,e?.options])}catch(t){throw new n(t)}}async listInvoices(e){try{return await this.client.requestAsync("admin.invoice.list",[e?.filter,e?.options])}catch(t){throw new n(t)}}async updateInvoiceHandled(e){try{return await this.client.requestAsync("admin.invoice.updateHandled",[e.purchaseIds,e.handled])}catch(t){throw new n(t)}}async listMonthlyRevenue(e){try{return await this.client.requestAsync("admin.revenue.list",[e.month,e.year,e.filter,e.options])}catch(t){throw new n(t)}}async getDashboardStatistics(e){try{return await this.client.requestAsync("admin.dashboard.statistics",[e])}catch(t){throw new n(t)}}async getDashboardTrends(e,t){try{return await this.client.requestAsync("admin.dashboard.trends",[e,t])}catch(i){throw new n(i)}}};var F=class{constructor(e){this.client=e;this.admin={workspacesList:async e=>{try{return await this.client.requestAsync("metrics.workspaceSearch",[e])}catch(t){throw new n(t)}},usersList:async e=>{try{return await this.client.requestAsync("metrics.userList",[e])}catch(t){throw new n(t)}}}}async list(e){try{return await this.client.requestAsync("metrics.list",e?[e]:[])}catch(t){throw new n(t)}}async get(e,t){try{let i=Array.isArray(e)?e:[e];return await this.client.requestAsync("metrics.get",[i,t])}catch(i){throw new n(i)}}};var H=class{constructor(e={}){this.options=e;this.outside=null;let t=e.allowedUrls??$;this.client=new X.Client(r=>{this.hostUrl&&parent.postMessage(JSON.stringify(r),this.hostUrl)}),this.user=new f(this.client),this.app=new O(this.client),this.activity=new w(this.client),this.insight=new L(this.client),this.workspace=new A(this.client),this.workflow=new U(this.client),this.permission=new _(this.client),this.public=new C(this.options),this.ui=new x(this.client),this.product=new M(this.client),this.payment=new D(this.client),this.admin=new W(this.client),this.metrics=new F(this.client);let i=JSON.stringify({op:"register",args:[{appApiVersion:"2"}]});window.location===window.parent.location?(this.options.publicBackendUrl||(this.options.publicBackendUrl=g),this.public.app.config().then(r=>{this.outside=!0,this.options.outside?.(r)}).catch(r=>{this.options.error?.(r),console.error("Failed to get app configuration in Public App.",r)})):(t.forEach(r=>parent.postMessage(i,r)),this.timer=setTimeout(()=>{this.outside=!0,this.options.outside?.()},100)),this.createEventListener()}createEventListener(){window.addEventListener("message",async e=>{let t=e.data;try{let i=JSON.parse(t);if(i.op==="register"){if(this.appId){console.error("App Id is already set...! Are you using hot-reload?");return}clearTimeout(this.timer),this.appId=i.data.appId,this.workspaceId=i.data.workspaceId,this.hostUrl=e.origin,this.options.publicBackendUrl||(this.options.publicBackendUrl=Q[this.hostUrl]||g),this.client.request("ui.settings",[],(r,s,a)=>{if(r){console.log("ui.settings error:",r,s);return}this.options.settings?.(s)}),this.client.request("config",[],(r,s,a)=>{if(r){console.log("config error:",r,s);return}this.options.config?.(s)}),this.client.request("signal",[],(r,s,a)=>{if(r){console.log("signal error:",r,s);return}s&&this.options.signals?.(s)}),this.outside=!1,this.options.connected?.();return}if(!this.appId)return;this.client.messageReceived(i)}catch{console.log("Dropped invalid JSON message")}})}info(){return{hostUrl:this.hostUrl,config:this.config,outside:this.outside,workspaceId:this.workspaceId}}};export{H as HailerApi,n as HailerError,F as MetricsApi};
|
|
3
3
|
//# sourceMappingURL=app-sdk.js.map
|