@hailer/app-sdk 2.13.0 → 2.15.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/README.md CHANGED
@@ -37,7 +37,7 @@ The `HailerApi` instance exposes these modules:
37
37
  | `hailer.activity` | `list`, `get`, `create`, `update`, `remove`, `print`, plus `hailer.activity.kanban` (`list`/`load`/`updatePriority`) and `hailer.activity.ball` (`pass`/`take`/`list`) sub-modules. |
38
38
  | `hailer.team` | `list()` — teams grouped by workspace. |
39
39
  | `hailer.permission` | `map({ workspaceId? })` — permission map for the current user. |
40
- | `hailer.file` | `get(fileId)`, `upload(file, filename, options?)`, `addTags(fileId, tags)`, `removeTags(fileId, tags)`. |
40
+ | `hailer.file` | `get(fileId)`, `upload(file, filename, options?)`, `addTags(fileId, tags)`, `removeTags(fileId, tags)`, `remove(fileIds)`, scoped files: `getScope(fileId)`, `setReaders(fileId, readers)`, `list(options?)`, `setOwner(fileId, userId)`. |
41
41
  | `hailer.insight` | `list()`, `data(insightId, options)`, `update(insightId, update)`, `query(workspaceId, sources, query)`. |
42
42
  | `hailer.app` | `hailer.app.product`: `isProductInstalled`, `get`, `install`, `getInstalledVersion`, `getManifest` — marketplace lookups for the running app. |
43
43
  | `hailer.product` | Full CRUD on your own marketplace products: `list`, `get`, `create`, `update`, `remove`, `setPublic`. |
@@ -46,6 +46,7 @@ The `HailerApi` instance exposes these modules:
46
46
  | `hailer.metrics` | Read usage metrics: `list(options?)`, `get(metricTypes, options?)`. |
47
47
  | `hailer.http` | Authenticated proxy through the parent frame: `fetch`, `upload`, `openWebSocket`. |
48
48
  | `hailer.credential` | Securely store and retrieve personal credentials bound to your app: `create`, `list`, `get`, `update`. Supports `basic`, `apiKey`, and `custom` payloads. |
49
+ | `hailer.action` | Trigger workspace actions and read back their runs: `trigger(target, input?)`, `getRun(runId)`. |
49
50
  | `hailer.public` | Endpoints callable without a Hailer session — talks directly to the public backend (`https://api.hailer.com` by default). Sub-modules: `.app` (public app config), `.form` (public form submit/read), `.insight` (public insight viewing), `.product` (marketplace lookup). The only namespace usable in `outside` mode. |
50
51
  | `hailer.ui` | Sub-modules for commanding the host frame: `.activity`, `.discussion`, `.snackbar`, `.workflow`, `.insight`, `.files`. |
51
52
 
@@ -53,17 +54,17 @@ Each module is fully typed. Browse the type definitions at [`src/types.ts`](./sr
53
54
 
54
55
  ## Publishing an app
55
56
 
56
- > **Note:** The `npm run publish-*` scripts shown below only exist in projects scaffolded with [`@hailer/create-app`](https://www.npmjs.com/package/@hailer/create-app). They are *not* defined in `@hailer/app-sdk` itself — what the SDK ships is the underlying `publish.cjs` binary that those scripts invoke. If you're integrating into a non-scaffolded project, run it directly: `node node_modules/@hailer/app-sdk/lib/tools/publish.cjs <path-to-bundle> --user-api-key <key>`.
57
+ > **Note:** The `npm run publish-*` scripts shown below only exist in projects scaffolded with [`@hailer/create-app`](https://www.npmjs.com/package/@hailer/create-app). They are *not* defined in `@hailer/app-sdk` itself — what the SDK ships is the underlying `publish.cjs` binary that those scripts invoke. If you're integrating into a non-scaffolded project, run it directly: `node node_modules/@hailer/app-sdk/lib/tools/publish.cjs <path-to-bundle> --email <email>` (prompts for the password; `--user-api-key <key>` works instead).
57
58
 
58
59
  ```bash
59
- # Authenticate with an API key and publish a built bundle
60
- npm run publish-production -- --user-api-key <key>
60
+ # Publish a built bundle (--email prompts for the password; --user-api-key <key> works instead)
61
+ npm run publish-production -- --email <email>
61
62
 
62
63
  # Create and publish in one go
63
64
  npm run publish-production -- --create \
64
65
  --app-name "My App" \
65
66
  --workspace <workspaceId> \
66
- --user-api-key <key> \
67
+ --email <email> \
67
68
  --force
68
69
  ```
69
70
 
package/lib/app-sdk.js CHANGED
@@ -1,3 +1,3 @@
1
- var oe=Object.create;var X=Object.defineProperty;var ae=Object.getOwnPropertyDescriptor;var ce=Object.getOwnPropertyNames;var ue=Object.getPrototypeOf,le=Object.prototype.hasOwnProperty;var J=(o,e)=>()=>{try{return e||o((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}};var pe=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ce(e))!le.call(o,i)&&i!==t&&X(o,i,{get:()=>e[i],enumerable:!(r=ae(e,i))||r.enumerable});return o};var de=(o,e,t)=>(t=o!=null?oe(ue(o)):{},pe(e||!o||!o.__esModule?X(t,"default",{value:o,enumerable:!0}):t,o));var Z=J(d=>{"use strict";var me=d&&d.__awaiter||function(o,e,t,r){function i(s){return s instanceof t?s:new t(function(a){a(s)})}return new(t||(t=Promise))(function(s,a){function u(c){try{p(r.next(c))}catch(K){a(K)}}function m(c){try{p(r.throw(c))}catch(K){a(K)}}function p(c){c.done?s(c.value):i(c.value).then(u,m)}p((r=r.apply(o,e||[])).next())})};Object.defineProperty(d,"__esModule",{value:!0});d.Client=void 0;var $=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),r=e.ack||e.err||e.sig||e.fin,i=this.requests[r],s;if(i&&typeof i.cb=="function"){let a;e.fin?i.cb.call(i.context,null,null,!0):i.canceled?console.log("This request is canceled. Not calling the callback."):(a=e.err?e.data:null,s=i.cb.call(i.context,a,e.data,t))}return t&&delete this.requests[r],s}requestAsync(e,t){return me(this,void 0,void 0,function*(){return new Promise((r,i)=>{this.request(e,t,(s,a)=>{if(s)return i(a);r(a)})})})}request(e,t,r){this.id++;let i={op:e};return Array.isArray(t)&&(i.args=t),r&&(i.id=this.id,this.requests[i.id]={cb:r,context:{id:i.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])})(i.id),1500),this.requests[i.id].canceled=!0,this.write({end:i.id})},emit:s=>this.write({sig:i.id,data:s})}}),this.write(i),i.id||null}send(e,t){this.write({push:e,data:t})}end(e){this.write({end:e})}};d.Client=$});var ee=J(y=>{"use strict";Object.defineProperty(y,"__esModule",{value:!0});y.Server=void 0;var h=console.log,G=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 r=e?e+".":"";for(let i in t)if(i!=="_"){if(i.substring(0,1)!=="_"&&t["_"+i])if(typeof t[i]=="function"){let s=t["_"+i].name||i;t["_"+i].fullname=r+s;try{this.modules[r+s]=t["_"+i],this.methods[r+s]=t[i]}catch(a){console.log("Kaboom! ",a)}}else typeof t[i]=="object"&&this.addMethods(r+i,t[i])}}listMethods(e,t,r){let i={};function s(u,m){let p={};for(let c in u)m[c]||(p[c]=u[c]);return p}let a={fullname:!0};for(let u in this.modules)i[u]=s(this.modules[u],a);r(null,i)}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,r,i){if(typeof i=="number")try{if(e.push){this.requests[i]&&this.requests[i][e.push]&&this.invokeRaw(e,t,this.requests[i][e.push].context,i);return}if(e.sig){this.requests[i]&&this.requests[i][e.sig]&&this.invokeRaw(e,t,this.requests[i][e.sig].context,i);return}if(e.end){let s=e.end;if(this.requests[i]&&this.requests[i][s]){typeof this.requests[i][s].end=="function"&&this.requests[i][s].end(),t({fin:s}),delete this.requests[i][s];return}if(!this.requests[i][s])return;typeof this.requests[i][s].end=="function"&&this.requests[s].end();return}if(e.op==="methods"){this.listMethods(e.args,r,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,r,i)}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 r in this.requests)if(this.requests[r]){for(let i in this.requests[r])if(this.requests[r][i].op===e){let{send:s}=this.requests[r][i];s({sig:i,data:t})}}}invokeRaw(e,t,r,i){if(++this.requestId,!this.requests[i])return console.log("Session not opened for client. Use Server.open() first");if(e.push){let s=this.requests[i][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[i][e.sig];try{this.methods[s.op].call(this.requests[i][e.sig],e.data,{send:a=>{typeof s.end=="function"&&s.end(),this.requests[i][e.sig]&&delete this.requests[i][e.sig],t({ack:e.sig,data:a})},emit:a=>(this.requests[i][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[i][e.sig],t({err:e.sig,data:a})},close:a=>{typeof s.end=="function"&&s.end(),delete this.requests[i][e.sig],t({fin:e.sig})}},r)}catch(a){console.log("Calling the method in RPC failed:",e.op,e.args,a.stack),delete this.requests[i][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.")}},r)}else{let s={id:e.id,op:e.op,args:e.args,context:r,end:null,send:t};this.requests[i]||(this.requests[i]={}),this.requests[i][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:",i,"msg",e,"stack trace:",new Error().stack),typeof this.requests[i][e.id].end=="function"&&this.requests[i][e.id].end(),delete this.requests[i][e.id],console.log("Removed old request by same id from same client...")),this.requests[i][e.id]=s;try{this.methods[e.op].call(s,{args:e.args},{send:a=>{typeof s.end=="function"&&s.end(),this.requests[i][e.id]&&delete this.requests[i][e.id],t({ack:e.id,data:a})},emit:a=>(this.requests[i][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[i][e.id],t({err:e.id,data:a})},close:a=>{typeof s.end=="function"&&s.end(),delete this.requests[i][e.id],t({fin:e.id})}},r)}catch(a){console.log("Calling the method in RPC failed:",e.op,e.args,a.stack),delete this.requests[i][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=G});var re=J(l=>{"use strict";var he=l&&l.__createBinding||(Object.create?(function(o,e,t,r){r===void 0&&(r=t),Object.defineProperty(o,r,{enumerable:!0,get:function(){return e[t]}})}):(function(o,e,t,r){r===void 0&&(r=t),o[r]=e[t]})),te=l&&l.__exportStar||function(o,e){for(var t in o)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&he(e,o,t)};Object.defineProperty(l,"__esModule",{value:!0});te(Z(),l);te(ee(),l)});var se=de(re(),1);var z=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 z{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(r){throw new n(r)}}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(r){throw new n(r)}}};var w=class{constructor(e){this.client=e}async pass(e,t){try{return await this.client.requestAsync("activity.ball.pass",[e,t])}catch(r){throw new n(r)}}async take(e){try{return await this.client.requestAsync("activity.ball.take",[e])}catch(t){throw new n(t)}}async list(e){if(Array.isArray(e)&&e.length===0)return[];try{return await this.client.requestAsync("activity.ball.list",[e])}catch(t){throw new n(t)}}};var A=class{constructor(e){this.client=e;this.kanban=new b(e),this.ball=new w(e)}async list(e,t,r){try{return await this.client.requestAsync("activity.list",[e,t,r])}catch(i){throw new n(i)}}async get(e){try{return await this.client.requestAsync("activity.get",[e])}catch(t){throw new n(t)}}async create(e,t,r){try{return await this.client.requestAsync("activity.create",[e,t,...r?[r]:[]])}catch(i){throw new n(i)}}async update(e,t){try{return await this.client.requestAsync("activity.update",[e,...t?[t]:[]])}catch(r){throw new n(r)}}async remove(e){try{return await this.client.requestAsync("activity.remove",[e])}catch(t){throw new n(t)}}async print(e,t){try{return await this.client.requestAsync("activity.print",[e,...t?[t]:[]])}catch(r){throw new n(r)}}};var P=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 create(e){try{return await this.client.requestAsync("workspace.create",[e])}catch(t){throw new n(t)}}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(r){throw new n(r)}}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(r){throw new n(r)}}async getManifest(e){try{return await this.client.requestAsync("workspace.product.getManifest",[e])}catch(t){throw new n(t)}}};var v=class{constructor(e){this.client=e}async list(){try{return await this.client.requestAsync("team.list",[])}catch(e){throw new n(e)}}};var k=class{constructor(e){this.client=e}async get(e){try{return await this.client.requestAsync("file.get",[e])}catch(t){throw new n(t)}}async upload(e,t,r){try{let i=await this.toBase64(e);return await this.client.requestAsync("file.upload",[i,t,!!r?.isPublic])}catch(i){throw new n(i)}}async addTags(e,t){try{return await this.client.requestAsync("file.addTags",[e,t])}catch(r){throw new n(r)}}async removeTags(e,t){try{return await this.client.requestAsync("file.removeTags",[e,t])}catch(r){throw new n(r)}}toBase64(e){return new Promise((t,r)=>{let i=new FileReader;i.readAsDataURL(e),i.onload=()=>t(i.result??""),i.onerror=r})}};var x=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 this.client.requestAsync("ui.activity.create",[e,...t?[t]:[]])}async editMultiple(e){return this.client.requestAsync("ui.activity.editMultiple",[e])}};var q=class{constructor(e){this.client=e}async open(e,t){await this.client.requestAsync("ui.discussion.open",[e,...t?[t]:[]])}};var R=class{constructor(e){this.client=e}async open(e,t,r){await this.client.requestAsync("ui.snackbar.open",[e,t,r])}};var I=class{constructor(e){this.client=e}async uploadFile(e,t,r){return this.client.requestAsync("ui.file.upload",[await this.toBase64(e),t,!!r?.isPublic])}toBase64(e){return new Promise((t,r)=>{let i=new FileReader;i.readAsDataURL(e),i.onload=()=>t(i.result??""),i.onerror=r})}};var C=class{constructor(e){this.client=e;this.function={edit:async(e,t)=>{await this.client.requestAsync("ui.workflow.function.edit",[e,t])}}}};var T=class{constructor(e){this.client=e;this.activity=new x(e),this.discussion=new q(e),this.snackbar=new R(e),this.workflow=new C(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 I(e)}};var ie=["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",ne={"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 S=class{constructor(e){this.options=e}async config(){let e="manifest.json",t=window.location.origin+window.location.pathname,r=t+e;t.endsWith("/index.html")&&(r=t.slice(0,-10)+e);let i=await(await fetch(r)).text(),a=JSON.parse(i).appId;return(await fetch(`${this.options.publicBackendUrl}/api/v3/app/public`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify([a])})).json()}};var U=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 t.json()}async submit(e,t){let r=await fetch(`${this.options.publicBackendUrl}/api/v2/forms/activity/create`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify([e,t])});if(!r.ok)throw new n(await r.json());return r.json()}};var O=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 t.json()}async dataAsObject(e){let r=(await this.data(e)).data,i=[];return r.rows.forEach(s=>{let a={};r.headers.forEach((u,m)=>{a[u]=s[m]}),i.push(a)}),i}};var L=class{constructor(e){this.options=e}async list(e,t){let r=await fetch(`${this.options.publicBackendUrl}/api/v3/product/list`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify([e,t])});if(!r.ok)throw new n(await r.json());return r.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 t.json()}};var D=class{constructor(e){this.insight=new O(e),this.form=new U(e),this.app=new S(e),this.product=new L(e)}};var _=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(r){throw new n(r)}}};var W=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(r){throw new n(r)}}};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(r){throw new n(r)}}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(r){throw new n(r)}}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 E=class{constructor(e){this.client=e}async data(e,t){try{return await this.client.requestAsync("insight.data",[e,...t?[t]:[]])}catch(r){throw new n(r)}}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(r){throw new n(r)}}async query(e,t,r){try{return await this.client.requestAsync("insight.query",[e,{sources:t,query:r}])}catch(i){throw new n(i)}}};var M=class{constructor(e){this.client=e;this.map=async({workspaceId:e}={})=>{try{return await this.client.requestAsync("permission.map",e?[{workspaceId:e}]:[])}catch(t){throw console.log("Failed to read permissions from Hailer, error:",t),new n(t)}}}};var F=class{constructor(e){this.client=e}async list(e,t){try{return await this.client.requestAsync("product.list",[e,t])}catch(r){throw new n(r)}}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(r){throw new n(r)}}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(r){throw new n(r)}}};var B=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 N=class{constructor(e){this.client=e;this.referral={listCodes:async e=>{try{return await this.client.requestAsync("admin.referral.listCodes",[e?.filter||null,e?.options||null])}catch(t){throw new n(t)}},listEvents:async e=>{try{return await this.client.requestAsync("admin.referral.listEvents",[e?.filter||null,e?.options||null])}catch(t){throw new n(t)}},updateCode:async(e,t)=>{try{return await this.client.requestAsync("admin.referral.updateCode",[{codeId:e,...t}])}catch(r){throw new n(r)}}}}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 setSubscriptionActivityId(e,t){try{return await this.client.requestAsync("admin.invoice.setSubscriptionActivityId",[e,t])}catch(r){throw new n(r)}}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(r){throw new n(r)}}};var H=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(){try{return await this.client.requestAsync("metrics.list",[])}catch(e){throw new n(e)}}async get(e,t){try{let r=Array.isArray(e)?e:[e];return await this.client.requestAsync("metrics.get",[r,t])}catch(r){throw new n(r)}}};var Q=class{constructor(e,t){this.client=e;this.onopen=null;this.onmessage=null;this.onclose=null;this.onerror=null;this.readyState=WebSocket.CONNECTING;this.connectionId=null;this.client.request("http.ws.open",[t],(r,i)=>{if(r){this.readyState=WebSocket.CLOSED,this.onerror?.({error:r});return}if(i)switch(i.connectionId&&!this.connectionId&&(this.connectionId=i.connectionId),i.event){case"open":this.readyState=WebSocket.OPEN,this.onopen?.({});break;case"message":this.onmessage?.({data:i.data??""});break;case"close":this.readyState=WebSocket.CLOSED,this.onclose?.({code:i.code,reason:i.reason});break;case"error":this.onerror?.({error:i.data});break}})}send(e){if(this.readyState!==WebSocket.OPEN||!this.connectionId)throw new Error("WebSocket is not open");this.client.requestAsync("http.ws.send",[this.connectionId,e]).catch(t=>{this.onerror?.({error:t})})}close(e,t){this.connectionId&&this.client.requestAsync("http.ws.close",[this.connectionId,e,t]).catch(r=>{this.onerror?.({error:r})}),this.readyState=WebSocket.CLOSING}},j=class{constructor(e){this.client=e}async fetch(e,t){return this.client.requestAsync("http.fetch",[e,t]).catch(r=>{throw r})}async upload(e,t){return this.client.requestAsync("http.upload",[e,t]).catch(r=>{throw r})}openWebSocket(e){return new Q(this.client,e)}};var V=class{constructor(e){this.client=e}async create(e,t,r){try{return await this.client.requestAsync("credential.create",[{name:e,type:t,secret:r}])}catch(i){throw new n(i)}}async list(){try{return await this.client.requestAsync("credential.list",[])}catch(e){throw new n(e)}}async get(e){try{return await this.client.requestAsync("credential.get",[e])}catch(t){throw new n(t)}}async update(e,t){try{return await this.client.requestAsync("credential.update",[e,t])}catch(r){throw new n(r)}}};var Y=class{constructor(e={}){this.options=e;this.outside=null;let t=e.allowedUrls??ie;this.client=new se.Client(i=>{this.hostUrl&&parent.postMessage(JSON.stringify(i),this.hostUrl)}),this.user=new f(this.client),this.app=new W(this.client),this.activity=new A(this.client),this.insight=new E(this.client),this.workspace=new P(this.client),this.team=new v(this.client),this.file=new k(this.client),this.workflow=new _(this.client),this.permission=new M(this.client),this.public=new D(this.options),this.ui=new T(this.client),this.product=new F(this.client),this.payment=new B(this.client),this.admin=new N(this.client),this.metrics=new H(this.client),this.http=new j(this.client),this.credential=new V(this.client);let r=JSON.stringify({op:"register",args:[{appApiVersion:"2"}]});window.location===window.parent.location?(this.options.publicBackendUrl||(this.options.publicBackendUrl=g),this.public.app.config().then(i=>{this.outside=!0,this.options.outside?.(i)}).catch(i=>{this.options.error?.(i),console.error("Failed to get app configuration in Public App.",i)})):(t.forEach(i=>parent.postMessage(r,i)),this.timer=setTimeout(()=>{this.outside=!0,this.options.outside?.()},100)),this.createEventListener()}createEventListener(){window.addEventListener("message",async e=>{let t=e.data;try{let r=JSON.parse(t);if(r.op==="register"){if(this.appId){console.error("App Id is already set...! Are you using hot-reload?");return}clearTimeout(this.timer),this.appId=r.data.appId,this.workspaceId=r.data.workspaceId,this.hostUrl=e.origin,this.options.publicBackendUrl||(this.options.publicBackendUrl=ne[this.hostUrl]||g),this.client.request("ui.settings",[],(i,s,a)=>{if(i){console.log("ui.settings error:",i,s);return}this.options.settings?.(s)}),this.client.request("config",[],(i,s,a)=>{if(i){console.log("config error:",i,s);return}this.config=s,this.options.config?.(s)}),this.client.request("signal",[],(i,s,a)=>{if(i){console.log("signal error:",i,s);return}s&&(this.options.signals?.(s),typeof s.name=="string"&&s.name.startsWith("workspace.role.")&&this.options.permissions?.())}),this.outside=!1,this.options.permissions?.(),this.options.connected?.();return}if(!this.appId)return;this.client.messageReceived(r)}catch{console.log("Dropped invalid JSON message")}})}info(){return{hostUrl:this.hostUrl,config:this.config,outside:this.outside,workspaceId:this.workspaceId}}};export{Y as HailerApi,n as HailerError,H as MetricsApi};
1
+ var ae=Object.create;var Z=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var le=Object.getPrototypeOf,pe=Object.prototype.hasOwnProperty;var $=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports);var de=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ue(e))!pe.call(o,i)&&i!==t&&Z(o,i,{get:()=>e[i],enumerable:!(r=ce(e,i))||r.enumerable});return o};var me=(o,e,t)=>(t=o!=null?ae(le(o)):{},de(e||!o||!o.__esModule?Z(t,"default",{value:o,enumerable:!0}):t,o));var ee=$(d=>{"use strict";var he=d&&d.__awaiter||function(o,e,t,r){function i(s){return s instanceof t?s:new t(function(a){a(s)})}return new(t||(t=Promise))(function(s,a){function u(c){try{p(r.next(c))}catch(J){a(J)}}function m(c){try{p(r.throw(c))}catch(J){a(J)}}function p(c){c.done?s(c.value):i(c.value).then(u,m)}p((r=r.apply(o,e||[])).next())})};Object.defineProperty(d,"__esModule",{value:!0});d.Client=void 0;var G=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),r=e.ack||e.err||e.sig||e.fin,i=this.requests[r],s;if(i&&typeof i.cb=="function"){let a;e.fin?i.cb.call(i.context,null,null,!0):i.canceled?console.log("This request is canceled. Not calling the callback."):(a=e.err?e.data:null,s=i.cb.call(i.context,a,e.data,t))}return t&&delete this.requests[r],s}requestAsync(e,t){return he(this,void 0,void 0,function*(){return new Promise((r,i)=>{this.request(e,t,(s,a)=>{if(s)return i(a);r(a)})})})}request(e,t,r){this.id++;let i={op:e};return Array.isArray(t)&&(i.args=t),r&&(i.id=this.id,this.requests[i.id]={cb:r,context:{id:i.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])})(i.id),1500),this.requests[i.id].canceled=!0,this.write({end:i.id})},emit:s=>this.write({sig:i.id,data:s})}}),this.write(i),i.id||null}send(e,t){this.write({push:e,data:t})}end(e){this.write({end:e})}};d.Client=G});var te=$(y=>{"use strict";Object.defineProperty(y,"__esModule",{value:!0});y.Server=void 0;var h=console.log,z=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 r=e?e+".":"";for(let i in t)if(i!=="_"){if(i.substring(0,1)!=="_"&&t["_"+i])if(typeof t[i]=="function"){let s=t["_"+i].name||i;t["_"+i].fullname=r+s;try{this.modules[r+s]=t["_"+i],this.methods[r+s]=t[i]}catch(a){console.log("Kaboom! ",a)}}else typeof t[i]=="object"&&this.addMethods(r+i,t[i])}}listMethods(e,t,r){let i={};function s(u,m){let p={};for(let c in u)m[c]||(p[c]=u[c]);return p}let a={fullname:!0};for(let u in this.modules)i[u]=s(this.modules[u],a);r(null,i)}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,r,i){if(typeof i=="number")try{if(e.push){this.requests[i]&&this.requests[i][e.push]&&this.invokeRaw(e,t,this.requests[i][e.push].context,i);return}if(e.sig){this.requests[i]&&this.requests[i][e.sig]&&this.invokeRaw(e,t,this.requests[i][e.sig].context,i);return}if(e.end){let s=e.end;if(this.requests[i]&&this.requests[i][s]){typeof this.requests[i][s].end=="function"&&this.requests[i][s].end(),t({fin:s}),delete this.requests[i][s];return}if(!this.requests[i][s])return;typeof this.requests[i][s].end=="function"&&this.requests[s].end();return}if(e.op==="methods"){this.listMethods(e.args,r,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,r,i)}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 r in this.requests)if(this.requests[r]){for(let i in this.requests[r])if(this.requests[r][i].op===e){let{send:s}=this.requests[r][i];s({sig:i,data:t})}}}invokeRaw(e,t,r,i){if(++this.requestId,!this.requests[i])return console.log("Session not opened for client. Use Server.open() first");if(e.push){let s=this.requests[i][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[i][e.sig];try{this.methods[s.op].call(this.requests[i][e.sig],e.data,{send:a=>{typeof s.end=="function"&&s.end(),this.requests[i][e.sig]&&delete this.requests[i][e.sig],t({ack:e.sig,data:a})},emit:a=>(this.requests[i][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[i][e.sig],t({err:e.sig,data:a})},close:a=>{typeof s.end=="function"&&s.end(),delete this.requests[i][e.sig],t({fin:e.sig})}},r)}catch(a){console.log("Calling the method in RPC failed:",e.op,e.args,a.stack),delete this.requests[i][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.")}},r)}else{let s={id:e.id,op:e.op,args:e.args,context:r,end:null,send:t};this.requests[i]||(this.requests[i]={}),this.requests[i][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:",i,"msg",e,"stack trace:",new Error().stack),typeof this.requests[i][e.id].end=="function"&&this.requests[i][e.id].end(),delete this.requests[i][e.id],console.log("Removed old request by same id from same client...")),this.requests[i][e.id]=s;try{this.methods[e.op].call(s,{args:e.args},{send:a=>{typeof s.end=="function"&&s.end(),this.requests[i][e.id]&&delete this.requests[i][e.id],t({ack:e.id,data:a})},emit:a=>(this.requests[i][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[i][e.id],t({err:e.id,data:a})},close:a=>{typeof s.end=="function"&&s.end(),delete this.requests[i][e.id],t({fin:e.id})}},r)}catch(a){console.log("Calling the method in RPC failed:",e.op,e.args,a.stack),delete this.requests[i][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=z});var ie=$(l=>{"use strict";var ge=l&&l.__createBinding||(Object.create?(function(o,e,t,r){r===void 0&&(r=t),Object.defineProperty(o,r,{enumerable:!0,get:function(){return e[t]}})}):(function(o,e,t,r){r===void 0&&(r=t),o[r]=e[t]})),re=l&&l.__exportStar||function(o,e){for(var t in o)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&ge(e,o,t)};Object.defineProperty(l,"__esModule",{value:!0});re(ee(),l);re(te(),l)});var oe=me(ie(),1);var ve=["queued","running"],Q=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 Q{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(r){throw new n(r)}}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(r){throw new n(r)}}};var w=class{constructor(e){this.client=e}async pass(e,t){try{return await this.client.requestAsync("activity.ball.pass",[e,t])}catch(r){throw new n(r)}}async take(e){try{return await this.client.requestAsync("activity.ball.take",[e])}catch(t){throw new n(t)}}async list(e){if(Array.isArray(e)&&e.length===0)return[];try{return await this.client.requestAsync("activity.ball.list",[e])}catch(t){throw new n(t)}}};var A=class{constructor(e){this.client=e;this.kanban=new b(e),this.ball=new w(e)}async list(e,t,r){try{return await this.client.requestAsync("activity.list",[e,t,r])}catch(i){throw new n(i)}}async get(e){try{return await this.client.requestAsync("activity.get",[e])}catch(t){throw new n(t)}}async create(e,t,r){try{return await this.client.requestAsync("activity.create",[e,t,...r?[r]:[]])}catch(i){throw new n(i)}}async update(e,t){try{return await this.client.requestAsync("activity.update",[e,...t?[t]:[]])}catch(r){throw new n(r)}}async remove(e){try{return await this.client.requestAsync("activity.remove",[e])}catch(t){throw new n(t)}}async print(e,t){try{return await this.client.requestAsync("activity.print",[e,...t?[t]:[]])}catch(r){throw new n(r)}}};var P=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 create(e){try{return await this.client.requestAsync("workspace.create",[e])}catch(t){throw new n(t)}}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(r){throw new n(r)}}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(r){throw new n(r)}}async getManifest(e){try{return await this.client.requestAsync("workspace.product.getManifest",[e])}catch(t){throw new n(t)}}};var v=class{constructor(e){this.client=e}async list(){try{return await this.client.requestAsync("team.list",[])}catch(e){throw new n(e)}}};var ye=300,fe={workspace:o=>`network_${o}`,team:o=>`team_${o}`,user:o=>`user_${o}`},k=class{constructor(e){this.client=e;this.readers=fe}async get(e){try{return await this.client.requestAsync("file.get",[e])}catch(t){throw new n(t)}}async upload(e,t,r){if(r?.isPublic&&r?.scoped)throw new n({code:400,msg:"A file cannot be both public and scoped",debug:void 0});try{let i=await this.toBase64(e);if(!r?.scoped)return await this.client.requestAsync("file.upload",[i,t,!!r?.isPublic]);let s=await this.client.requestAsync("file.upload",[i,t,!1,!0]);return await this.assertScoped(s),s}catch(i){throw i instanceof n?i:new n(i)}}async addTags(e,t){try{return await this.client.requestAsync("file.addTags",[e,t])}catch(r){throw new n(r)}}async removeTags(e,t){try{return await this.client.requestAsync("file.removeTags",[e,t])}catch(r){throw new n(r)}}async getScope(e){try{return await this.client.requestAsync("file.getScope",[e])}catch(t){throw new n(t)}}async setReaders(e,t){try{return await this.client.requestAsync("file.setReaders",[e,t])}catch(r){throw new n(r)}}async list(e){try{return await this.client.requestAsync("file.list",e?[e]:[])}catch(t){throw new n(t)}}async setOwner(e,t){try{return await this.client.requestAsync("file.setOwner",[e,t])}catch(r){throw new n(r)}}async remove(e){try{return await this.client.requestAsync("file.remove",[e])}catch(t){throw new n(t)}}async assertScoped(e){let t;try{t=await this.client.requestAsync("file.getScope",[e])}catch(r){if(r?.code!==ye)throw new n(r)}if(!t?.workspaceId)throw new n({code:501,msg:`File ${e} was uploaded but not scoped: this Hailer version does not support scoped files`,debug:void 0})}toBase64(e){return new Promise((t,r)=>{let i=new FileReader;i.readAsDataURL(e),i.onload=()=>t(i.result??""),i.onerror=r})}};var x=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 this.client.requestAsync("ui.activity.create",[e,...t?[t]:[]])}async editMultiple(e){return this.client.requestAsync("ui.activity.editMultiple",[e])}};var R=class{constructor(e){this.client=e}async open(e,t){await this.client.requestAsync("ui.discussion.open",[e,...t?[t]:[]])}};var q=class{constructor(e){this.client=e}async open(e,t,r){await this.client.requestAsync("ui.snackbar.open",[e,t,r])}};var I=class{constructor(e){this.client=e}async uploadFile(e,t,r){return this.client.requestAsync("ui.file.upload",[await this.toBase64(e),t,!!r?.isPublic])}toBase64(e){return new Promise((t,r)=>{let i=new FileReader;i.readAsDataURL(e),i.onload=()=>t(i.result??""),i.onerror=r})}};var C=class{constructor(e){this.client=e;this.function={edit:async(e,t)=>{await this.client.requestAsync("ui.workflow.function.edit",[e,t])}}}};var T=class{constructor(e){this.client=e;this.activity=new x(e),this.discussion=new R(e),this.snackbar=new q(e),this.workflow=new C(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 I(e)}};var ne=["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",se={"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 S=class{constructor(e){this.options=e}async config(){let e="manifest.json",t=window.location.origin+window.location.pathname,r=t+e;t.endsWith("/index.html")&&(r=t.slice(0,-10)+e);let i=await(await fetch(r)).text(),a=JSON.parse(i).appId;return(await fetch(`${this.options.publicBackendUrl}/api/v3/app/public`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify([a])})).json()}};var U=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 t.json()}async submit(e,t){let r=await fetch(`${this.options.publicBackendUrl}/api/v2/forms/activity/create`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify([e,t])});if(!r.ok)throw new n(await r.json());return r.json()}};var O=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 t.json()}async dataAsObject(e){let r=(await this.data(e)).data,i=[];return r.rows.forEach(s=>{let a={};r.headers.forEach((u,m)=>{a[u]=s[m]}),i.push(a)}),i}};var L=class{constructor(e){this.options=e}async list(e,t){let r=await fetch(`${this.options.publicBackendUrl}/api/v3/product/list`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify([e,t])});if(!r.ok)throw new n(await r.json());return r.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 t.json()}};var _=class{constructor(e){this.insight=new O(e),this.form=new U(e),this.app=new S(e),this.product=new L(e)}};var D=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(r){throw new n(r)}}};var E=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(r){throw new n(r)}}};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(r){throw new n(r)}}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(r){throw new n(r)}}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 W=class{constructor(e){this.client=e}async data(e,t){try{return await this.client.requestAsync("insight.data",[e,...t?[t]:[]])}catch(r){throw new n(r)}}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(r){throw new n(r)}}async query(e,t,r){try{return await this.client.requestAsync("insight.query",[e,{sources:t,query:r}])}catch(i){throw new n(i)}}};var F=class{constructor(e){this.client=e;this.map=async({workspaceId:e}={})=>{try{return await this.client.requestAsync("permission.map",e?[{workspaceId:e}]:[])}catch(t){throw console.log("Failed to read permissions from Hailer, error:",t),new n(t)}}}};var M=class{constructor(e){this.client=e}async list(e,t){try{return await this.client.requestAsync("product.list",[e,t])}catch(r){throw new n(r)}}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(r){throw new n(r)}}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(r){throw new n(r)}}};var B=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 N=class{constructor(e){this.client=e;this.referral={listCodes:async e=>{try{return await this.client.requestAsync("admin.referral.listCodes",[e?.filter||null,e?.options||null])}catch(t){throw new n(t)}},listEvents:async e=>{try{return await this.client.requestAsync("admin.referral.listEvents",[e?.filter||null,e?.options||null])}catch(t){throw new n(t)}},updateCode:async(e,t)=>{try{return await this.client.requestAsync("admin.referral.updateCode",[{codeId:e,...t}])}catch(r){throw new n(r)}}}}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 setSubscriptionActivityId(e,t){try{return await this.client.requestAsync("admin.invoice.setSubscriptionActivityId",[e,t])}catch(r){throw new n(r)}}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(r){throw new n(r)}}};var H=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(){try{return await this.client.requestAsync("metrics.list",[])}catch(e){throw new n(e)}}async get(e,t){try{let r=Array.isArray(e)?e:[e];return await this.client.requestAsync("metrics.get",[r,t])}catch(r){throw new n(r)}}};var Y=class{constructor(e,t){this.client=e;this.onopen=null;this.onmessage=null;this.onclose=null;this.onerror=null;this.readyState=WebSocket.CONNECTING;this.connectionId=null;this.client.request("http.ws.open",[t],(r,i)=>{if(r){this.readyState=WebSocket.CLOSED,this.onerror?.({error:r});return}if(i)switch(i.connectionId&&!this.connectionId&&(this.connectionId=i.connectionId),i.event){case"open":this.readyState=WebSocket.OPEN,this.onopen?.({});break;case"message":this.onmessage?.({data:i.data??""});break;case"close":this.readyState=WebSocket.CLOSED,this.onclose?.({code:i.code,reason:i.reason});break;case"error":this.onerror?.({error:i.data});break}})}send(e){if(this.readyState!==WebSocket.OPEN||!this.connectionId)throw new Error("WebSocket is not open");this.client.requestAsync("http.ws.send",[this.connectionId,e]).catch(t=>{this.onerror?.({error:t})})}close(e,t){this.connectionId&&this.client.requestAsync("http.ws.close",[this.connectionId,e,t]).catch(r=>{this.onerror?.({error:r})}),this.readyState=WebSocket.CLOSING}},j=class{constructor(e){this.client=e}async fetch(e,t){return this.client.requestAsync("http.fetch",[e,t]).catch(r=>{throw r})}async upload(e,t){return this.client.requestAsync("http.upload",[e,t]).catch(r=>{throw r})}openWebSocket(e){return new Y(this.client,e)}};var V=class{constructor(e){this.client=e}async create(e,t,r){try{return await this.client.requestAsync("credential.create",[{name:e,type:t,secret:r}])}catch(i){throw new n(i)}}async list(){try{return await this.client.requestAsync("credential.list",[])}catch(e){throw new n(e)}}async get(e){try{return await this.client.requestAsync("credential.get",[e])}catch(t){throw new n(t)}}async update(e,t){try{return await this.client.requestAsync("credential.update",[e,t])}catch(r){throw new n(r)}}};var K=class{constructor(e){this.client=e}async trigger(e,t){try{return await this.client.requestAsync("action.trigger",[e,t??null])}catch(r){throw new n(r)}}async getRun(e){try{return await this.client.requestAsync("action.getRun",[e])}catch(t){throw new n(t)}}};var X=class{constructor(e={}){this.options=e;this.outside=null;let t=e.allowedUrls??ne;this.client=new oe.Client(i=>{this.hostUrl&&parent.postMessage(JSON.stringify(i),this.hostUrl)}),this.user=new f(this.client),this.app=new E(this.client),this.activity=new A(this.client),this.insight=new W(this.client),this.workspace=new P(this.client),this.team=new v(this.client),this.file=new k(this.client),this.workflow=new D(this.client),this.permission=new F(this.client),this.public=new _(this.options),this.ui=new T(this.client),this.product=new M(this.client),this.payment=new B(this.client),this.admin=new N(this.client),this.metrics=new H(this.client),this.http=new j(this.client),this.credential=new V(this.client),this.action=new K(this.client);let r=JSON.stringify({op:"register",args:[{appApiVersion:"2"}]});window.location===window.parent.location?(this.options.publicBackendUrl||(this.options.publicBackendUrl=g),this.public.app.config().then(i=>{this.outside=!0,this.options.outside?.(i)}).catch(i=>{this.options.error?.(i),console.error("Failed to get app configuration in Public App.",i)})):(t.forEach(i=>parent.postMessage(r,i)),this.timer=setTimeout(()=>{this.outside=!0,this.options.outside?.()},100)),this.createEventListener()}createEventListener(){window.addEventListener("message",async e=>{let t=e.data;try{let r=JSON.parse(t);if(r.op==="register"){if(this.appId){console.error("App Id is already set...! Are you using hot-reload?");return}clearTimeout(this.timer),this.appId=r.data.appId,this.workspaceId=r.data.workspaceId,this.hostUrl=e.origin,this.options.publicBackendUrl||(this.options.publicBackendUrl=se[this.hostUrl]||g),this.client.request("ui.settings",[],(i,s,a)=>{if(i){console.log("ui.settings error:",i,s);return}this.options.settings?.(s)}),this.client.request("config",[],(i,s,a)=>{if(i){console.log("config error:",i,s);return}this.config=s,this.options.config?.(s)}),this.client.request("signal",[],(i,s,a)=>{if(i){console.log("signal error:",i,s);return}s&&(this.options.signals?.(s),typeof s.name=="string"&&s.name.startsWith("workspace.role.")&&this.options.permissions?.())}),this.outside=!1,this.options.permissions?.(),this.options.connected?.();return}if(!this.appId)return;this.client.messageReceived(r)}catch{console.log("Dropped invalid JSON message")}})}info(){return{hostUrl:this.hostUrl,config:this.config,outside:this.outside,workspaceId:this.workspaceId}}};export{ve as ACTION_RUN_ACTIVE_STATUSES,k as FileApi,X as HailerApi,n as HailerError,H as MetricsApi,fe as fileReaders};
3
3
  //# sourceMappingURL=app-sdk.js.map