@hailer/app-sdk 2.4.2 → 2.5.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?)`. |
40
+ | `hailer.file` | `get(fileId)`, `upload(file, filename, options?)`, `addTags(fileId, tags)`, `removeTags(fileId, tags)`. |
41
41
  | `hailer.insight` | `list()`, `data(insightId, options)`. |
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`. |
@@ -89,9 +89,23 @@ The publish script will also load `~/.env` via `dotenv`, so a key set there work
89
89
  | `--host <url>` | Override target host URL. |
90
90
  | `--development` / `--staging` / `--production` / `--local` | Pick a default host. |
91
91
 
92
- ## Developing the SDK
92
+ ### Workflow
93
93
 
94
- These commands are for contributors working on this repo, not consumers of the published package:
94
+ 1. Create a new branch for every feature or fix — don't commit directly to `master`.
95
+ 2. **Before publishing**, document what changed in [`CHANGELOG.md`](./CHANGELOG.md) under a new version heading. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/):
96
+
97
+ ```md
98
+ ## [2.4.2] - 25-05-2026
99
+
100
+ ### Changed
101
+
102
+ - Updated `Workflow`, `WorkflowField`, and `WorkflowPhase` types to match more closely the actual shape of the objects.
103
+ - Updated `README.md` file to explain more clearly what the `hailer-app-sdk` package is.
104
+ ```
105
+
106
+ 3. Publish with one of the `release:*` scripts below — these bump the version, tag the commit, and push.
107
+
108
+ ### Dev commands
95
109
 
96
110
  ```bash
97
111
  npm run build # Build the SDK + publish CLI
@@ -100,6 +114,17 @@ npm test # Run vitest test suite
100
114
  npm run docs # Generate typedoc and open it
101
115
  ```
102
116
 
103
- ## Versioning
117
+ ### Releasing
118
+
119
+ This project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Pick the script that matches the kind of change:
120
+
121
+ | Script | When to use | Example bump |
122
+ |--------|-------------|--------------|
123
+ | `npm run release:patch` | Bug fix, no API change | `1.1.1` → `1.1.2` |
124
+ | `npm run release:minor` | New feature, backwards compatible | `1.1.1` → `1.2.0` |
125
+ | `npm run release:major` | Breaking change | `1.1.1` → `2.0.0` |
126
+ | `npm run release:beta-patch` | Pre-release patch | `1.1.1` → `1.1.2-beta.0` |
127
+ | `npm run release:beta-minor` | Pre-release minor | `1.1.1` → `1.2.0-beta.0` |
128
+ | `npm run release:beta-major` | Pre-release major | `1.1.1` → `2.0.0-beta.0` |
104
129
 
105
- This project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html). See [CHANGELOG.md](./CHANGELOG.md) for release notes.
130
+ Each script runs `npm version <type>`, creates a commit + tag (`chore: release vX.Y.Z`), and pushes both to the remote. Tagging every release means we can check out and patch any historical version cleanly.
package/lib/app-sdk.js CHANGED
@@ -1,3 +1,3 @@
1
- var se=Object.create;var Q=Object.defineProperty;var oe=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var ce=Object.getPrototypeOf,ue=Object.prototype.hasOwnProperty;var K=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports);var pe=(o,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ae(e))!ue.call(o,r)&&r!==t&&Q(o,r,{get:()=>e[r],enumerable:!(i=oe(e,r))||i.enumerable});return o};var le=(o,e,t)=>(t=o!=null?se(ce(o)):{},pe(e||!o||!o.__esModule?Q(t,"default",{value:o,enumerable:!0}):t,o));var X=K(d=>{"use strict";var de=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(V){a(V)}}function m(c){try{l(i.throw(c))}catch(V){a(V)}}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 J=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 de(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=J});var Z=K(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 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=G});var te=K(p=>{"use strict";var me=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]})),ee=p&&p.__exportStar||function(o,e){for(var t in o)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&me(e,o,t)};Object.defineProperty(p,"__esModule",{value:!0});ee(X(),p);ee(Z(),p)});var ne=le(te(),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(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}async pass(e,t){try{return await this.client.requestAsync("activity.ball.pass",[e,t])}catch(i){throw new n(i)}}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,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)}}async print(e){try{return await this.client.requestAsync("activity.print",[e])}catch(t){throw new n(t)}}};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 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 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,i){try{let r=await this.toBase64(e);return await this.client.requestAsync("file.upload",[r,t,!!i?.isPublic])}catch(r){throw new n(r)}}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}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 R=class{constructor(e){this.client=e}async open(e,t){await this.client.requestAsync("ui.discussion.open",[e,...t?[t]:[]])}};var x=class{constructor(e){this.client=e}async open(e,t,i){await this.client.requestAsync("ui.snackbar.open",[e,t,i])}};var I=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 T=class{constructor(e){this.client=e;this.function={edit:async(e,t)=>{await this.client.requestAsync("ui.workflow.function.edit",[e,t])}}}};var C=class{constructor(e){this.client=e;this.activity=new q(e),this.discussion=new R(e),this.snackbar=new x(e),this.workflow=new T(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 re=["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",ie={"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,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 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 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 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 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 L=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 W=class{constructor(e){this.insight=new O(e),this.form=new U(e),this.app=new S(e),this.product=new L(e)}};var E=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 _=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 D=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 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(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 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 H=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(i){throw new n(i)}}}}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(i){throw new n(i)}}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 N=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.user.list",[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 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],(i,r)=>{if(i){this.readyState=WebSocket.CLOSED,this.onerror?.({error:i});return}if(r)switch(r.connectionId&&!this.connectionId&&(this.connectionId=r.connectionId),r.event){case"open":this.readyState=WebSocket.OPEN,this.onopen?.({});break;case"message":this.onmessage?.({data:r.data??""});break;case"close":this.readyState=WebSocket.CLOSED,this.onclose?.({code:r.code,reason:r.reason});break;case"error":this.onerror?.({error:r.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(i=>{this.onerror?.({error:i})}),this.readyState=WebSocket.CLOSING}},j=class{constructor(e){this.client=e}async fetch(e,t){return await this.client.requestAsync("http.fetch",[e,t]).catch(i=>{throw i})}async upload(e,t){return await this.client.requestAsync("http.upload",[e,t]).catch(i=>{throw i})}openWebSocket(e){return new Y(this.client,e)}};var $=class{constructor(e={}){this.options=e;this.outside=null;let t=e.allowedUrls??re;this.client=new ne.Client(r=>{this.hostUrl&&parent.postMessage(JSON.stringify(r),this.hostUrl)}),this.user=new f(this.client),this.app=new _(this.client),this.activity=new A(this.client),this.insight=new D(this.client),this.workspace=new P(this.client),this.team=new v(this.client),this.file=new k(this.client),this.workflow=new E(this.client),this.permission=new M(this.client),this.public=new W(this.options),this.ui=new C(this.client),this.product=new F(this.client),this.payment=new B(this.client),this.admin=new H(this.client),this.metrics=new N(this.client),this.http=new j(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=ie[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{$ as HailerApi,n as HailerError,N as MetricsApi};
1
+ var se=Object.create;var Q=Object.defineProperty;var oe=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var ce=Object.getPrototypeOf,ue=Object.prototype.hasOwnProperty;var K=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports);var pe=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ae(e))!ue.call(o,i)&&i!==t&&Q(o,i,{get:()=>e[i],enumerable:!(r=oe(e,i))||r.enumerable});return o};var le=(o,e,t)=>(t=o!=null?se(ce(o)):{},pe(e||!o||!o.__esModule?Q(t,"default",{value:o,enumerable:!0}):t,o));var X=K(d=>{"use strict";var de=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{l(r.next(c))}catch(V){a(V)}}function m(c){try{l(r.throw(c))}catch(V){a(V)}}function l(c){c.done?s(c.value):i(c.value).then(u,m)}l((r=r.apply(o,e||[])).next())})};Object.defineProperty(d,"__esModule",{value:!0});d.Client=void 0;var J=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 de(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=J});var Z=K(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 l={};for(let c in u)m[c]||(l[c]=u[c]);return l}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 te=K(p=>{"use strict";var me=p&&p.__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]})),ee=p&&p.__exportStar||function(o,e){for(var t in o)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&me(e,o,t)};Object.defineProperty(p,"__esModule",{value:!0});ee(X(),p);ee(Z(),p)});var ne=le(te(),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){try{return await this.client.requestAsync("activity.print",[e])}catch(t){throw new n(t)}}};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 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 q=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 x=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 T=class{constructor(e){this.client=e;this.function={edit:async(e,t)=>{await this.client.requestAsync("ui.workflow.function.edit",[e,t])}}}};var C=class{constructor(e){this.client=e;this.activity=new q(e),this.discussion=new R(e),this.snackbar=new x(e),this.workflow=new T(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 re=["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",ie={"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 W=class{constructor(e){this.insight=new O(e),this.form=new U(e),this.app=new S(e),this.product=new L(e)}};var E=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 _=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 console.log("Errorasd ",r),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 D=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)}}};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 H=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 N=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.user.list",[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 r=Array.isArray(e)?e:[e];return await this.client.requestAsync("metrics.get",[r,t])}catch(r){throw new n(r)}}};var $=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 $(this.client,e)}};var Y=class{constructor(e={}){this.options=e;this.outside=null;let t=e.allowedUrls??re;this.client=new ne.Client(i=>{this.hostUrl&&parent.postMessage(JSON.stringify(i),this.hostUrl)}),this.user=new f(this.client),this.app=new _(this.client),this.activity=new A(this.client),this.insight=new D(this.client),this.workspace=new P(this.client),this.team=new v(this.client),this.file=new k(this.client),this.workflow=new E(this.client),this.permission=new M(this.client),this.public=new W(this.options),this.ui=new C(this.client),this.product=new F(this.client),this.payment=new B(this.client),this.admin=new H(this.client),this.metrics=new N(this.client),this.http=new j(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=ie[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.options.config?.(s)}),this.client.request("signal",[],(i,s,a)=>{if(i){console.log("signal error:",i,s);return}s&&this.options.signals?.(s)}),this.outside=!1,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,N as MetricsApi};
3
3
  //# sourceMappingURL=app-sdk.js.map