mirror of
https://github.com/hanzoai/agency.git
synced 2026-11-02 19:13:28 +00:00
2 lines
2.5 KiB
Plaintext
2 lines
2.5 KiB
Plaintext
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=class{baseUrl;prefix;fetchFn;constructor(e={}){this.baseUrl=(e.baseUrl??(typeof window<`u`?window.location.origin:``)).replace(/\/$/,``),this.prefix=(e.pathPrefix??``).replace(/\/$/,``),this.fetchFn=e.fetch??(typeof fetch<`u`?fetch.bind(globalThis):(()=>{throw Error(`fetch is not available`)})())}url(e){return`${this.baseUrl}${this.prefix}/v1/waitlist${e}`}async join(e){let t=await this.fetchFn(this.url(`/join`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});return this.parse(t)}async status(e){let t=new URLSearchParams({waitlist:e.waitlist,email:e.email}),n=await this.fetchFn(this.url(`/status?${t}`),{method:`GET`});return this.parse(n)}async list(e){let t=new URLSearchParams({waitlist:e.waitlist});e.page&&t.set(`page`,String(e.page)),e.pageSize&&t.set(`pageSize`,String(e.pageSize));let n=await this.fetchFn(this.url(`/list?${t}`),{method:`GET`});return this.parseGeneric(n)}async neighborhood(e){let t=new URLSearchParams({waitlist:e.waitlist,email:e.email});e.window&&t.set(`window`,String(e.window));let n=await this.fetchFn(this.url(`/neighborhood?${t}`),{method:`GET`});return this.parseGeneric(n)}async trackShare(e){let t=await this.fetchFn(this.url(`/track-share`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});return this.parseGeneric(t)}async invite(e){let t=await this.fetchFn(this.url(`/invite`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});return this.parseGeneric(t)}async activity(e){let t=new URLSearchParams({waitlist:e.waitlist});e.limit&&t.set(`limit`,String(e.limit)),e.types?.length&&t.set(`types`,e.types.join(`,`));let n=await this.fetchFn(this.url(`/activity?${t}`),{method:`GET`});return this.parseGeneric(n)}async exportCsv(e,t={}){let n=new URLSearchParams({waitlist:e}),r={};t.authorization&&(r.Authorization=t.authorization);let i=await this.fetchFn(this.url(`/export?${n}`),{method:`GET`,headers:r});if(!i.ok)throw Error(`export failed: ${i.status} ${await i.text()}`);return i.text()}async parse(e){return this.parseGeneric(e)}async parseGeneric(e){let t=null;try{t=await e.json()}catch{}if(!e.ok){let n=t&&typeof t==`object`&&`message`in t&&typeof t.message==`string`?t.message:`request failed with ${e.status}`;return{ok:!1,status:e.status,message:n,data:t}}return t}};async function t(t,n){return new e(n).join(t)}async function n(t,n){return new e(n).status(t)}exports.WaitlistClient=e,exports.join=t,exports.status=n;
|
|
//# sourceMappingURL=client.cjs.map |