@hailer/app-sdk 2.4.0 → 2.4.2

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
@@ -1,12 +1,105 @@
1
- # Hailer apps SDK
1
+ # @hailer/app-sdk
2
+
3
+ SDK for building **Hailer Apps** — web apps that run as iframes inside the Hailer frontend.
4
+
5
+ The SDK gives your app a `HailerApi` client that talks to the host frame — so runtime calls inherit the user's session and you don't deal with auth or API tokens. It also ships a publish CLI for pushing your built app to a Hailer instance (or to the Hailer marketplace); that one *does* need a user API key.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @hailer/app-sdk
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ The fastest way to start is the official scaffolder, which sets up a Vite project with the SDK already wired up:
16
+
17
+ ```bash
18
+ npm create @hailer/app@latest
19
+ cd my-app
20
+ npm install
21
+ npm run dev
22
+ ```
23
+
24
+ Then in Hailer, create a "Local Development" app pointing to `http://localhost:3000` and open it — changes reload automatically.
25
+
26
+ See [`@hailer/create-app`](https://www.npmjs.com/package/@hailer/create-app) for templates, non-interactive flags, and publishing instructions.
27
+
28
+ ## Modules
29
+
30
+ The `HailerApi` instance exposes these modules:
31
+
32
+ | Module | Purpose |
33
+ |--------|---------|
34
+ | `hailer.user` | `current()`, `get(userId)`, `list()`. |
35
+ | `hailer.workspace` | `current()`, `list()`, plus `hailer.workspace.product` for product/template install lookups. |
36
+ | `hailer.workflow` | `list()`, `get(workflowId)`, `install(spec, options?)`. |
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
+ | `hailer.team` | `list()` — teams grouped by workspace. |
39
+ | `hailer.permission` | `map({ workspaceId? })` — permission map for the current user. |
40
+ | `hailer.file` | `get(fileId)`, `upload(file, filename, options?)`. |
41
+ | `hailer.insight` | `list()`, `data(insightId, options)`. |
42
+ | `hailer.app` | `hailer.app.product`: `isProductInstalled`, `get`, `install`, `getInstalledVersion`, `getManifest` — marketplace lookups for the running app. |
43
+ | `hailer.product` | Full CRUD on your own marketplace products: `list`, `get`, `create`, `update`, `remove`, `setPublic`. |
44
+ | `hailer.payment` | Pricing and purchases: `createPricing`, `updatePricing`, `getPricing`, `createPurchase`, `getPurchases`, `calculateStripeTax`. |
45
+ | `hailer.admin` | Admin-only endpoints (workspace overrides, invoices, revenue, token transactions, referrals, etc). |
46
+ | `hailer.metrics` | Read usage metrics: `list(options?)`, `get(metricTypes, options?)`. |
47
+ | `hailer.http` | Authenticated proxy through the parent frame: `fetch`, `upload`, `openWebSocket`. |
48
+ | `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. |
49
+ | `hailer.ui` | Sub-modules for commanding the host frame: `.activity`, `.discussion`, `.snackbar`, `.workflow`, `.insight`, `.files`. |
50
+
51
+ Each module is fully typed. Browse the type definitions at [`src/types.ts`](./src/types.ts), or generate a typedoc site locally with `npm run docs` from a clone of this repo.
52
+
53
+ ## Publishing an app
54
+
55
+ > **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>`.
2
56
 
3
- ## Building
4
57
  ```bash
5
- npm run build
58
+ # Authenticate with an API key and publish a built bundle
59
+ npm run publish-production -- --user-api-key <key>
60
+
61
+ # Create and publish in one go
62
+ npm run publish-production -- --create \
63
+ --app-name "My App" \
64
+ --workspace <workspaceId> \
65
+ --user-api-key <key> \
66
+ --force
6
67
  ```
7
68
 
8
- ## Documentation
9
- Create a docs folder with typedoc
69
+ ### Auth
70
+
71
+ Provide one of:
72
+
73
+ - `--user-api-key <key>` (or `USER_API_KEY` / `HAILER_USER_API_KEY` env vars)
74
+ - `--email <email>` (will prompt for password)
75
+
76
+ The publish script will also load `~/.env` via `dotenv`, so a key set there works automatically — handy for AI agents.
77
+
78
+ ### Flags
79
+
80
+ | Flag | Purpose |
81
+ |------|---------|
82
+ | `--user-api-key <key>` | API-key auth. |
83
+ | `--email <email>` | Email auth (password prompt). |
84
+ | `--create` | Create a new app before publishing. |
85
+ | `--app-name <name>` | App name (with `--create`). |
86
+ | `--workspace <id>` | Workspace ID (with `--create`). |
87
+ | `--market` | Also publish to the Hailer marketplace. |
88
+ | `--force` | Skip confirmation prompt. |
89
+ | `--host <url>` | Override target host URL. |
90
+ | `--development` / `--staging` / `--production` / `--local` | Pick a default host. |
91
+
92
+ ## Developing the SDK
93
+
94
+ These commands are for contributors working on this repo, not consumers of the published package:
95
+
10
96
  ```bash
11
- npm run docs
97
+ npm run build # Build the SDK + publish CLI
98
+ npm run watch # Rebuild on change (tsc + esbuild)
99
+ npm test # Run vitest test suite
100
+ npm run docs # Generate typedoc and open it
12
101
  ```
102
+
103
+ ## Versioning
104
+
105
+ This project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html). See [CHANGELOG.md](./CHANGELOG.md) for release notes.
package/lib/app-sdk.js CHANGED
@@ -1,3 +1,3 @@
1
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 _=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 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(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 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(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 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 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.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 E(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 _(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 N(this.client),this.metrics=new H(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,H as MetricsApi};
2
+ Field: ${this.details}, ${this.debug}`}};var f=class{constructor(e){this.client=e}async get(e){try{return await this.client.requestAsync("user.get",[e])}catch(t){throw new n(t)}}async current(){try{return await this.client.requestAsync("user.current",[])}catch(e){throw new n(e)}}async list(){try{return await this.client.requestAsync("user.list",[])}catch(e){throw new n(e)}}};var b=class{constructor(e){this.client=e}async list(e,t){try{return await this.client.requestAsync("activity.kanban.list",[e,...t?[t]:[]])}catch(i){throw new n(i)}}async load(e){try{return await this.client.requestAsync("activity.kanban.load",[e])}catch(t){throw new n(t)}}async updatePriority(e,t){try{return await this.client.requestAsync("activity.kanban.updatePriority",[{activityId:e,priority:t}])}catch(i){throw new n(i)}}};var w=class{constructor(e){this.client=e}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};
3
3
  //# sourceMappingURL=app-sdk.js.map