1;!function(){try { var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&((e._debugIds|| (e._debugIds={}))[n]="ddd0f579-dc82-8910-667d-2a0701de3964")}catch(e){}}(); 2(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,574176,e=>{"use strict";let t={seats:"seats",automationSlots:"automation_slots",maxFileSize:"max_file_size",maxFileDuration:"max_file_duration",maxFilesPerUpload:"max_files_per_upload",maxParallelTranscriptJobsMetered:"max_parallel_transcript_jobs_metered",maxPendingTranscriptJobsMetered:"max_pending_transcript_jobs_metered",maxParallelTranscriptJobsUnlimited:"max_parallel_transcript_jobs_unlimited",maxPendingTranscriptJobsUnlimited:"max_pending_transcript_jobs_unlimited",transcriptionMinutesFree:"transcription_minutes_free",transcriptionMinutesMetered:"transcription_minutes_metered",transcriptionMinutesUnlimited:"transcription_minutes_unlimited",translationMinutesMetered:"translation_minutes_metered",transcriptsCount:"transcript_count",credits:"credits",aiTokensUsage:"ai_tokens_usage",transcriptExports:"transcript_exports",transcriptBulkExports:"transcript_bulk_exports",apiAccess:"api_access",watermarkFreeExports:"watermark_free_exports",modelSelectionUI:"model_selection_ui",googleDriveIntegration:"google_drive_integration",autoClipLongerFiles:"auto_clip_longer_files",hasLtdPlan:"has_ltd_plan",hasRecurringSubscription:"has_recurring_subscription"},s={addonSeatsMonthly:"addon-seats",addonAutomationsMonthly:"addon-automations",addonCreditsMonthly:"addon-credits",creditsTopupMonthly:"topup-credits",addonSeatsYearly:"addon-seats-yearly",addonAutomationsYearly:"addon-automations-yearly",addonCreditsYearly:"addon-credits-yearly",creditsTopupYearly:"topup-credits-yearly",free:"free",unlimitedMonthly:"unlimited-monthly",unlimitedYearly:"unlimited-yearly",ltdTier1:"lifetime-tier1",ltdTier2:"lifetime-tier2",ltdTier3:"lifetime-tier3",ltdTier4:"lifetime-tier4",specialFeatures:"special-features"};s.unlimitedYearly,s.unlimitedMonthly,s.free,s.ltdTier4,s.ltdTier3,s.ltdTier2,s.ltdTier1;let r={[t.transcriptionMinutesMetered]:1,[t.translationMinutesMetered]:1,[t.aiTokensUsage]:400};e.s(["AI_USAGE_CREDITS_PER_USD",0,400,"AUTUMN_CREDIT_COSTS",0,r,"AUTUMN_FEATURES",0,t,"AUTUMN_PLANS",0,s,"UNLIMITED_GRANT_INTERVAL_HOURS",0,5,"UNLIMITED_GRANT_MINUTES",0,300,"UNLIMITED_ROLLOVER_MAX_MINUTES",0,1080])},669305,128644,951350,949855,267676,582681,641688,627288,754485,916349,650379,e=>{"use strict";let t,s,r,i,n,a,u;var o=class extends Error{code;statusCode;details;constructor({message:e,code:t,statusCode:s,details:r}){super(e),this.name="AutumnClientError",this.code=t,this.statusCode=s,this.details=r}};e.s(["AutumnClientError",0,o],128644);var l=e=>{let t=(e=>{let{backendUrl:t,pathPrefix:s,includeCredentials:r,headers:i}=e,n=t?`${t}${s}`:s;return{request:async({route:e,body:t,method:s="POST"})=>{let a=`${n}/${e}`,u={"Content-Type":"application/json",...i};try{let e=await fetch(a,{method:s,headers:u,...r&&{credentials:"include"},...void 0!==t&&{body:JSON.stringify(t)}}),i=e.status;if(204===i)return null;let n=await e.json();if(!e.ok){let e=new o(n&&"object"==typeof n&&"message"in n&&"code"in n&&"statusCode"in n?n:{message:n?.message||"Request failed",code:n?.code||"request_failed",statusCode:i});throw console.error(`[Autumn] ${e.message}`),e}return n}catch(t){if(t instanceof o)throw t;let e=new o({message:t instanceof Error?t.message:"Network error",code:"network_error",statusCode:0});throw console.error(`[Autumn] ${e.code}: ${e.message}`),e}}}})({backendUrl:e.backendUrl,pathPrefix:e.pathPrefix,includeCredentials:e.includeCredentials,headers:e.headers});return{getOrCreateCustomer:e=>t.request({route:"getOrCreateCustomer",body:e}),attach:e=>t.request({route:"attach",body:e}),previewAttach:e=>t.request({route:"previewAttach",body:e}),updateSubscription:e=>t.request({route:"updateSubscription",body:e}),previewUpdateSubscription:e=>t.request({route:"previewUpdateSubscription",body:e}),multiAttach:e=>t.request({route:"multiAttach",body:e}),previewMultiAttach:e=>t.request({route:"previewMultiAttach",body:e}),setupPayment:e=>t.request({route:"setupPayment",body:e}),openCustomerPortal:e=>t.request({route:"openCustomerPortal",body:e}),createReferralCode:e=>t.request({route:"createReferralCode",body:e}),redeemReferralCode:e=>t.request({route:"redeemReferralCode",body:e}),listPlans:e=>t.request({route:"listPlans",body:e??{}}),listEvents:e=>t.request({route:"listEvents",body:e}),aggregateEvents:e=>t.request({route:"aggregateEvents",body:e}),getEntity:e=>t.request({route:"getEntity",body:e})}};e.s(["createAutumnClient",0,l],951350),e.i(247167);var c=e.i(271645),h=e.i(843476),d="u"<typeof window||"Deno"in globalThis;function p(){}function f(e){return"number"==typeof e&&e>=0&&e!==1/0}function y(e,t){return Math.max(e+(t||0)-Date.now(),0)}function m(e,t){return"function"==typeof e?e(t):e}function b(e,t){return"function"==typeof e?e(t):e}function g(e,t){let{type:s="all",exact:r,fetchStatus:i,predicate:n,queryKey:a,stale:u}=e;if(a){if(r){if(t.queryHash!==C(a,t.options))return!1}else if(!O(t.queryKey,a))return!1}if("all"!==s){let e=t.isActive();if("active"===s&&!e||"inactive"===s&&e)return!1}return("boolean"!=typeof u||t.isStale()===u)&&(!i||i===t.state.fetchStatus)&&(!n||!!n(t))}function v(e,t){let{exact:s,status:r,predicate:i,mutationKey:n}=e;if(n){if(!t.options.mutationKey)return!1;if(s){if(w(t.options.mutationKey)!==w(n))return!1}else if(!O(t.options.mutationKey,n))return!1}return(!r||t.state.status===r)&&(!i||!!i(t))}function C(e,t){return(t?.queryKeyHashFn||w)(e)}function w(e){return JSON.stringify(e,(e,t)=>q(t)?Object.keys(t).sort().reduce((e,s)=>(e[s]=t[s],e),{}):t)}function O(e,t){return e===t||typeof e==typeof t&&!!e&&!!t&&"object"==typeof e&&"object"==typeof t&&Object.keys(t).every(s=>O(e[s],t[s]))}function R(e,t){if(!t||Object.keys(e).length!==Object.keys(t).length)return!1;for(let s in e)if(e[s]!==t[s])return!1;return!0}function S(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function q(e){if(!T(e))return!1;let t=e.constructor;if(void 0===t)return!0;let s=t.prototype;return!!T(s)&&!!s.hasOwnProperty("isPrototypeOf")&&Object.getPrototypeOf(e)===Object.prototype}function T(e){return"[object Object]"===Object.prototype.toString.call(e)}function I(e,t,s){return"function"==typeof s.structuralSharing?s.structuralSharing(e,t):!1!==s.structuralSharing?function e(t,s){if(t===s)return t;let r=S(t)&&S(s);if(r||q(t)&&q(s)){let i=r?t:Object.keys(t),n=i.length,a=r?s:Object.keys(s),u=a.length,o=r?[]:{},l=new Set(i),c=0;for(let i=0;i<u;i++){let n=r?i:a[i];(!r&&l.has(n)||r)&&void 0===t[n]&&void 0===s[n]?(o[n]=void 0,c++):(o[n]=e(t[n],s[n]),o[n]===t[n]&&void 0!==t[n]&&c++)}return n===u&&c===n?t:o}return s}(e,t):t}function P(e,t,s=0){let r=[...e,t];return s&&r.length>s?r.slice(1):r}function E(e,t,s=0){let r=[t,...e];return s&&r.length>s?r.slice(0,-1):r}var Q=Symbol();function x(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:e.queryFn&&e.queryFn!==Q?e.queryFn:()=>Promise.reject(Error(`Missing queryFn: '${e.queryHash}'`))}var F=(t=[],s=0,r=e=>{e()},i=e=>{e()},n=e=>setTimeout(e,0),{batch:e=>{let a;s++;try{a=e()}finally{let e;--s||(e=t,t=[],e.length&&n(()=>{i(()=>
2{e.forEach(e=>{r(e)})})}))}return a},batchCalls:e=>(...t)=>{a(()=>{e(...t)})},schedule:a=e=>{s?t.push(e):n(()=>{r(e)})},setNotifyFunction:e=>{r=e},setBatchNotifyFunction:e=>{i=e},setScheduler:e=>{n=e}}),_=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},A=new class extends _{#e;#t;#s;constructor(){super(),this.#s=e=>{if(!d&&window.addEventListener){let t=()=>e();return window.addEventListener("visibilitychange",t,!1),()=>{window.removeEventListener("visibilitychange",t)}}}}onSubscribe(){this.#t||this.setEventListener(this.#s)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#s=e,this.#t?.(),this.#t=e(e=>{"boolean"==typeof e?this.setFocused(e):this.onFocus()})}setFocused(e){this.#e!==e&&(this.#e=e,this.onFocus())}onFocus(){let e=this.isFocused();this.listeners.forEach(t=>{t(e)})}isFocused(){return"boolean"==typeof this.#e?this.#e:globalThis.document?.visibilityState!=="hidden"}},M=new class extends _{#r=!0;#t;#s;constructor(){super(),this.#s=e=>{if(!d&&window.addEventListener){let t=()=>e(!0),s=()=>e(!1);return window.addEventListener("online",t,!1),window.addEventListener("offline",s,!1),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",s)}}}}onSubscribe(){this.#t||this.setEventListener(this.#s)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#s=e,this.#t?.(),this.#t=e(this.setOnline.bind(this))}setOnline(e){this.#r!==e&&(this.#r=e,this.listeners.forEach(t=>{t(e)}))}isOnline(){return this.#r}};function U(){let e,t,s=new Promise((s,r)=>{e=s,t=r});function r(e){Object.assign(s,e),delete s.resolve,delete s.reject}return s.status="pending",s.catch(()=>{}),s.resolve=t=>{r({status:"fulfilled",value:t}),e(t)},s.reject=e=>{r({status:"rejected",reason:e}),t(e)},s}function D(e){return Math.min(1e3*2**e,3e4)}function k(e){return(e??"online")!=="online"||M.isOnline()}var j=class extends Error{constructor(e){super("CancelledError"),this.revert=e?.revert,this.silent=e?.silent}};function L(e){let t,s=!1,r=0,i=U(),n=()=>A.isFocused()&&("always"===e.networkMode||M.isOnline())&&e.canRun(),a=()=>k(e.networkMode)&&e.canRun(),u=e=>{"pending"===i.status&&(t?.(),i.resolve(e))},o=e=>{"pending"===i.status&&(t?.(),i.reject(e))},l=()=>new Promise(s=>{t=e=>{("pending"!==i.status||n())&&s(e)},e.onPause?.()}).then(()=>{t=void 0,"pending"===i.status&&e.onContinue?.()}),c=()=>{let t;if("pending"!==i.status)return;let a=0===r?e.initialPromise:void 0;try{t=a??e.fn()}catch(e){t=Promise.reject(e)}Promise.resolve(t).then(u).catch(t=>{if("pending"!==i.status)return;let a=e.retry??3*!d,u=e.retryDelay??D,h="function"==typeof u?u(r,t):u,p=!0===a||"number"==typeof a&&r<a||"function"==typeof a&&a(r,t);s||!p?o(t):(r++,e.onFail?.(r,t),new Promise(e=>{setTimeout(e,h)}).then(()=>n()?void 0:l()).then(()=>{s?o(t):c()}))})};return{promise:i,status:()=>i.status,cancel:t=>{if("pending"===i.status){let s=new j(t);o(s),e.onCancel?.(s)}},continue:()=>(t?.(),i),cancelRetry:()=>{s=!0},continueRetry:()=>{s=!1},canStart:a,start:()=>(a()?c():l().then(c),i)}}var N=class{#i;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),f(this.gcTime)&&(this.#i=setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(d?1/0:3e5))}clearGcTimeout(){this.#i&&(clearTimeout(this.#i),this.#i=void 0)}},K=class extends N{#n;#a;#u;#o;#l;#c;#h;constructor(e){super(),this.#h=!1,this.#c=e.defaultOptions,this.setOptions(e.options),this.observers=[],this.#o=e.client,this.#u=this.#o.getQueryCache(),this.queryKey=e.queryKey,this.queryHash=e.queryHash,this.#n=function(e){let t="function"==typeof e.initialData?e.initialData():e.initialData,s=void 0!==t,r=s?"function"==typeof e.initialDataUpdatedAt?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:s?r??Date.now():0,error:null,errorUpdate
2Count:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:s?"success":"pending",fetchStatus:"idle"}}(this.options),this.state=e.state??this.#n,this.scheduleGc()}get meta(){return this.options.meta}get promise(){return this.#l?.promise}setOptions(e){this.options={...this.#c,...e},this.updateGcTime(this.options.gcTime)}optionalRemove(){this.observers.length||"idle"!==this.state.fetchStatus||this.#u.remove(this)}setData(e,t){let s=I(this.state.data,e,this.options);return this.#d({data:s,type:"success",dataUpdatedAt:t?.updatedAt,manual:t?.manual}),s}setState(e,t){this.#d({type:"setState",state:e,setStateOptions:t})}cancel(e){let t=this.#l?.promise;return this.#l?.cancel(e),t?t.then(p).catch(p):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(this.#n)}isActive(){return this.observers.some(e=>!1!==b(e.options.enabled,this))}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===Q||this.state.dataUpdateCount+this.state.errorUpdateCount===0}isStatic(){return this.getObserversCount()>0&&this.observers.some(e=>"static"===m(e.options.staleTime,this))}isStale(){return this.getObserversCount()>0?this.observers.some(e=>e.getCurrentResult().isStale):void 0===this.state.data||this.state.isInvalidated}isStaleByTime(e=0){return void 0===this.state.data||"static"!==e&&(!!this.state.isInvalidated||!y(this.state.dataUpdatedAt,e))}onFocus(){let e=this.observers.find(e=>e.shouldFetchOnWindowFocus());e?.refetch({cancelRefetch:!1}),this.#l?.continue()}onOnline(){let e=this.observers.find(e=>e.shouldFetchOnReconnect());e?.refetch({cancelRefetch:!1}),this.#l?.continue()}addObserver(e){this.observers.includes(e)||(this.observers.push(e),this.clearGcTimeout(),this.#u.notify({type:"observerAdded",query:this,observer:e}))}removeObserver(e){this.observers.includes(e)&&(this.observers=this.observers.filter(t=>t!==e),this.observers.length||(this.#l&&(this.#h?this.#l.cancel({revert:!0}):this.#l.cancelRetry()),this.scheduleGc()),this.#u.notify({type:"observerRemoved",query:this,observer:e}))}getObserversCount(){return this.observers.length}invalidate(){this.state.isInvalidated||this.#d({type:"invalidate"})}async fetch(e,t){let s;if("idle"!==this.state.fetchStatus&&this.#l?.status()!=="rejected"){if(void 0!==this.state.data&&t?.cancelRefetch)this.cancel({silent:!0});else if(this.#l)return this.#l.continueRetry(),this.#l.promise}if(e&&this.setOptions(e),!this.options.queryFn){let e=this.observers.find(e=>e.options.queryFn);e&&this.setOptions(e.options)}let r=new AbortController,i=e=>{Object.defineProperty(e,"signal",{enumerable:!0,get:()=>(this.#h=!0,r.signal)})},n=()=>{let e,s=x(this.options,t),r=(i(e={client:this.#o,queryKey:this.queryKey,meta:this.meta}),e);return(this.#h=!1,this.options.persister)?this.options.persister(s,r,this):s(r)},a=(i(s={fetchOptions:t,options:this.options,queryKey:this.queryKey,client:this.#o,state:this.state,fetchFn:n}),s);this.options.behavior?.onFetch(a,this),this.#a=this.state,("idle"===this.state.fetchStatus||this.state.fetchMeta!==a.fetchOptions?.meta)&&this.#d({type:"fetch",meta:a.fetchOptions?.meta}),this.#l=L({initialPromise:t?.initialPromise,fn:a.fetchFn,onCancel:e=>{e instanceof j&&e.revert&&this.setState({...this.#a,fetchStatus:"idle"}),r.abort()},onFail:(e,t)=>{this.#d({type:"failed",failureCount:e,error:t})},onPause:()=>{this.#d({type:"pause"})},onContinue:()=>{this.#d({type:"continue"})},retry:a.options.retry,retryDelay:a.options.retryDelay,networkMode:a.options.networkMode,canRun:()=>!0});try{let e=await this.#l.start();if(void 0===e)throw Error(`${this.queryHash} data is undefined`);return this.setData(e),this.#u.config.onSuccess?.(e,this),this.#u.config.onSettled?.(e,this.state.error,this),e}catch(e){if(e instanceof j){if(e.silent)return this.#l.promise;else if(e.revert){if(void 0===this.state.data)throw e;return this.state.data}}throw this.#d({type:"error",error:e}),this.#u.config.onError?.(e,this),this.#u.config.onSettled?.(this.state.data,e,this),e}finally{this.scheduleGc()}}#d(e){let t=t=>{switch(e.type){case"failed":return{...t,fetchFailureCount:e.failureCount,fetchFailureReason:e.error};case"pause":return{...t,fetchStatus:"paused"};case"continue":return{...t,fetchStatus:"fetching"};case"fetch":return{...t,...H(t.data,this.options),fetchMeta:e.meta??null};case"success":let s={...t,data:e.data,dataUpdateCount:t.dataUpdateCount+1,dataUpdatedAt:e.dataUpdatedAt??Date.now(),error:null,isInvalidated:!1,status:"success",...!e.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};return this.#a=e.manual?s:void 0,s;case"error":let r=e.error;
2return{...t,error:r,errorUpdateCount:t.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:t.fetchFailureCount+1,fetchFailureReason:r,fetchStatus:"idle",status:"error"};case"invalidate":return{...t,isInvalidated:!0};case"setState":return{...t,...e.state}}};this.state=t(this.state),F.batch(()=>{this.observers.forEach(e=>{e.onQueryUpdate()}),this.#u.notify({query:this,type:"updated",action:e})})}};function H(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:k(t.networkMode)?"fetching":"paused",...void 0===e&&{error:null,status:"pending"}}}var G=class extends _{constructor(e={}){super(),this.config=e,this.#p=new Map}#p;build(e,t,s){let r=t.queryKey,i=t.queryHash??C(r,t),n=this.get(i);return n||(n=new K({client:e,queryKey:r,queryHash:i,options:e.defaultQueryOptions(t),state:s,defaultOptions:e.getQueryDefaults(r)}),this.add(n)),n}add(e){this.#p.has(e.queryHash)||(this.#p.set(e.queryHash,e),this.notify({type:"added",query:e}))}remove(e){let t=this.#p.get(e.queryHash);t&&(e.destroy(),t===e&&this.#p.delete(e.queryHash),this.notify({type:"removed",query:e}))}clear(){F.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return this.#p.get(e)}getAll(){return[...this.#p.values()]}find(e){let t={exact:!0,...e};return this.getAll().find(e=>g(t,e))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(t=>g(e,t)):t}notify(e){F.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){F.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){F.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},B=class extends N{#f;#y;#l;constructor(e){super(),this.mutationId=e.mutationId,this.#y=e.mutationCache,this.#f=[],this.state=e.state||{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0},this.setOptions(e.options),this.scheduleGc()}setOptions(e){this.options=e,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(e){this.#f.includes(e)||(this.#f.push(e),this.clearGcTimeout(),this.#y.notify({type:"observerAdded",mutation:this,observer:e}))}removeObserver(e){this.#f=this.#f.filter(t=>t!==e),this.scheduleGc(),this.#y.notify({type:"observerRemoved",mutation:this,observer:e})}optionalRemove(){this.#f.length||("pending"===this.state.status?this.scheduleGc():this.#y.remove(this))}continue(){return this.#l?.continue()??this.execute(this.state.variables)}async execute(e){let t=()=>{this.#d({type:"continue"})};this.#l=L({fn:()=>this.options.mutationFn?this.options.mutationFn(e):Promise.reject(Error("No mutationFn found")),onFail:(e,t)=>{this.#d({type:"failed",failureCount:e,error:t})},onPause:()=>{this.#d({type:"pause"})},onContinue:t,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#y.canRun(this)});let s="pending"===this.state.status,r=!this.#l.canStart();try{if(s)t();else{this.#d({type:"pending",variables:e,isPaused:r}),await this.#y.config.onMutate?.(e,this);let t=await this.options.onMutate?.(e);t!==this.state.context&&this.#d({type:"pending",context:t,variables:e,isPaused:r})}let i=await this.#l.start();return await this.#y.config.onSuccess?.(i,e,this.state.context,this),await this.options.onSuccess?.(i,e,this.state.context),await this.#y.config.onSettled?.(i,null,this.state.variables,this.state.context,this),await this.options.onSettled?.(i,null,e,this.state.context),this.#d({type:"success",data:i}),i}catch(t){try{throw await this.#y.config.onError?.(t,e,this.state.context,this),await this.options.onError?.(t,e,this.state.context),await this.#y.config.onSettled?.(void 0,t,this.state.variables,this.state.context,this),await this.options.onSettled?.(void 0,t,e,this.state.context),t}finally{this.#d({type:"error",error:t})}}finally{this.#y.runNext(this)}}#d(e){this.state=(t=>{switch(e.type){case"failed":return{...t,failureCount:e.failureCount,failureReason:e.error};case"pause":return{...t,isPaused:!0};case"continue":return{...t,isPaused:!1};case"pending":return{...t,context:e.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:e.isPaused,status:"pending",variables:e.variables,submittedAt:Date.now()};case"success":return{...t,data:e.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...t,data:void 0,error:e.error,failureCount:t.failureCount+1,failureReason:e.error,isPau
2sed:!1,status:"error"}}})(this.state),F.batch(()=>{this.#f.forEach(t=>{t.onMutationUpdate(e)}),this.#y.notify({mutation:this,type:"updated",action:e})})}},$=class extends _{constructor(e={}){super(),this.config=e,this.#m=new Set,this.#b=new Map,this.#g=0}#m;#b;#g;build(e,t,s){let r=new B({mutationCache:this,mutationId:++this.#g,options:e.defaultMutationOptions(t),state:s});return this.add(r),r}add(e){this.#m.add(e);let t=J(e);if("string"==typeof t){let s=this.#b.get(t);s?s.push(e):this.#b.set(t,[e])}this.notify({type:"added",mutation:e})}remove(e){if(this.#m.delete(e)){let t=J(e);if("string"==typeof t){let s=this.#b.get(t);if(s)if(s.length>1){let t=s.indexOf(e);-1!==t&&s.splice(t,1)}else s[0]===e&&this.#b.delete(t)}}this.notify({type:"removed",mutation:e})}canRun(e){let t=J(e);if("string"!=typeof t)return!0;{let s=this.#b.get(t),r=s?.find(e=>"pending"===e.state.status);return!r||r===e}}runNext(e){let t=J(e);if("string"!=typeof t)return Promise.resolve();{let s=this.#b.get(t)?.find(t=>t!==e&&t.state.isPaused);return s?.continue()??Promise.resolve()}}clear(){F.batch(()=>{this.#m.forEach(e=>{this.notify({type:"removed",mutation:e})}),this.#m.clear(),this.#b.clear()})}getAll(){return Array.from(this.#m)}find(e){let t={exact:!0,...e};return this.getAll().find(e=>v(t,e))}findAll(e={}){return this.getAll().filter(t=>v(e,t))}notify(e){F.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(e=>
2e.state.isPaused);return F.batch(()=>Promise.all(e.map(e=>e.continue().catch(p))))}};function J(e){return e.options.scope?.id}function W(e){return{onFetch:(t,s)=>{let r=t.options,i=t.fetchOptions?.meta?.fetchMore?.direction,n=t.state.data?.pages||[],a=t.state.data?.pageParams||[],u={pages:[],pageParams:[]},o=0,l=async()=>{let s=!1,l=x(t.options,t.fetchOptions),c=async(e,r,i)=>{let n;if(s)return Promise.reject();if(null==r&&e.pages.length)return Promise.resolve(e);let a=(Object.defineProperty(n={client:t.client,queryKey:t.queryKey,pageParam:r,direction:i?"backward":"forward",meta:t.options.meta},"signal",{enumerable:!0,get:()=>(t.signal.aborted?s=!0:t.signal.addEventListener("abort",()=>{s=!0}),t.signal)}),n),u=await l(a),{maxPages:o}=t.options,c=i?E:P;return{pages:c(e.pages,u,o),pageParams:c(e.pageParams,r,o)}};if(i&&n.length){let e="backward"===i,t={pages:n,pageParams:a},s=(e?function(e,{pages:t,pageParams:s}){return t.length>0?e.getPreviousPageParam?.(t[0],t,s[0],s):void 0}:z)(r,t);u=await c(t,s,e)}else{let t=e??n.length;do{let e=0===o?a[0]??r.initialPageParam:z(r,u);if(o>0&&null==e)break;u=await c(u,e),o++}while(o<t)}return u};t.options.persister?t.fetchFn=()=>t.options.persister?.(l,{client:t.client,queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},s):t.fetchFn=l}}}function z(e,{pages:t,pageParams:s}){let r=t.length-1;return t.length>0?e.getNextPageParam(t[r],t,s[r],s):void 0}var Y=class{#v;#y;#c;#C;#w;#O;#R;#S;constructor(e={}){this.#v=e.queryCache||new G,this.#y=e.mutationCache||new $,this.#c=e.defaultOptions||{},this.#C=new Map,this.#w=new Map,this.#O=0}mount(){this.#O++,1===this.#O&&(this.#R=A.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#v.onFocus())}),this.#S=M.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#v.onOnline())}))}unmount(){this.#O--,0===this.#O&&(this.#R?.(),this.#R=void 0,this.#S?.(),this.#S=void 0)}isFetching(e){return this.#v.findAll({...e,fetchStatus:"fetching"}).length}isMutating(e){return this.#y.findAll({...e,status:"pending"}).length}getQueryData(e){let t=this.defaultQueryOptions({queryKey:e});return this.#v.get(t.queryHash)?.state.data}ensureQueryData(e){let t=this.defaultQueryOptions(e),s=this.#v.build(this,t),r=s.state.data;return void 0===r?this.fetchQuery(e):(e.revalidateIfStale&&s.isStaleByTime(m(t.staleTime,s))&&this.prefetchQuery(t),Promise.resolve(r))}getQueriesData(e){return this.#v.findAll(e).map(({queryKey:e,state:t})=>[e,t.data])}setQueryData(e,t,s){let r=this.defaultQueryOptions({queryKey:e}),i=this.#v.get(r.queryHash),n=i?.state.data,a="function"==typeof t?t(n):t;if(void 0!==a)return this.#v.build(this,r).setData(a,{...s,manual:!0})}setQueriesData(e,t,s){return F.batch(()=>this.#v.findAll(e).map(({queryKey:e})=>[e,this.setQueryData(e,t,s)]))}getQueryState(e){let t=this.defaultQueryOptions({queryKey:e});return this.#v.get(t.queryHash)?.state}removeQueries(e){let t=this.#v;F.batch(()=>{t.findAll(e).forEach(e=>{t.remove(e)})})}resetQueries(e,t){let s=this.#v;return F.batch(()=>(s.findAll(e).forEach(e=>{e.reset()}),this.refetchQueries({type:"active",...e},t)))}cancelQueries(e,t={}){let s={revert:!0,...t};return Promise.all(F.batch(()=>this.#v.findAll(e).map(e=>e.cancel(s)))).then(p).catch(p)}invalidateQueries(e,t={}){return F.batch(()=>(this.#v.findAll(e).forEach(e=>{e.invalidate()}),e?.refetchType==="none")?Promise.resolve():this.refetchQueries({...e,type:e?.refetchType??e?.type??"active"},t))}refetchQueries(e,t={}){let s={...t,cancelRefetch:t.cancelRefetch??!0};return Promise.all(F.batch(()=>this.#v.findAll(e).filter(e=>!e.isDisabled()&&!e.isStatic()).map(e=>{let t=e.fetch(void 0,s);return s.throwOnError||(t=t.catch(p)),"paused"===e.state.fetchStatus?Promise.resolve():t}))).then(p)}fetchQuery(e){let t=this.defaultQueryOptions(e);void 0===t.retry&&(t.retry=!1);let s=this.#v.build(this,t);return s.isStaleByTime(m(t.staleTime,s))?s.fetch(t):Promise.resolve(s.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(p).catch(p)}fetchInfiniteQuery(e){return e.behavior=W(e.pages),this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(p).catch(p)}ensureInfiniteQueryData(e){return e.behavior=W(e.pages),this.ensureQueryData(e)}resumePausedMutations(){return M.isOnline()?this.#y.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#v}getMutationCache(){return this.#y}getDefaultOptions(){return this.#c}setDefaultOptions(e){this.#c=e}setQueryDefaults(e,t){this.#C.set(w(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#C.values()],s={};return t.forEach(t=>{O(e,t.queryKey)&&Object.assign(s,t.defaultOptions)}),s}setMutationDefaults(e,t){this.#w.set(w(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#w.values()],s={};return t.forEach(t=>{O(e,t.mutationKey)&&Object.assign(s,t.defaultOptions)}),s}defaultQueryOptions(e){if(e._defaulted)return e;let t={...this.#c.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=C(t.queryKey,t)),void 0===t.refetchOnReconnect&&(t.refetchOnReconnect="always"!==t.networkMode),void 0===t.throwOnError&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode="offlineFirst"),t.queryFn===Q&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#c.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#v.clear(),this.#y.clear()}},V=class extends _{constructor(e,t){super(),this.options=t,this.#o=e,this.#q=null,this.#T=U(),this.bindMethods(),this.setOptions(t)}#o;#I=void 0;#P=void 0;#E=void 0;#Q;#x;#T;#q;#F;#_;#A;#M;#U;#D;#k=new Set;bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){1===this.listeners.size&&(this.#I.addObserver(this),X(this.#I,this.options)?this.#j():this.updateResult(),this.#L())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return Z(this.#I,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return Z(this.#I,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#N(),this.#K(),this.#I.removeObserver(this)}setOptions(e){let t=this.options,s=this.#I;
2if(this.options=this.#o.defaultQueryOptions(e),void 0!==this.options.enabled&&"boolean"!=typeof this.options.enabled&&"function"!=typeof this.options.enabled&&"boolean"!=typeof b(this.options.enabled,this.#I))throw Error("Expected enabled to be a boolean or a callback that returns a boolean");this.#H(),this.#I.setOptions(this.options),t._defaulted&&!R(this.options,t)&&this.#o.getQueryCache().notify({type:"observerOptionsUpdated",query:this.#I,observer:this});let r=this.hasListeners();r&&ee(this.#I,s,this.options,t)&&this.#j(),this.updateResult(),r&&(this.#I!==s||b(this.options.enabled,this.#I)!==b(t.enabled,this.#I)||m(this.options.staleTime,this.#I)!==m(t.staleTime,this.#I))&&this.#G();let i=this.#B();r&&(this.#I!==s||b(this.options.enabled,this.#I)!==b(t.enabled,this.#I)||i!==this.#D)&&this.#$(i)}getOptimisticResult(e){var t,s;let r=this.#o.getQueryCache().build(this.#o,e),i=this.createResult(r,e);return t=this,s=i,R(t.getCurrentResult(),s)||(this.#E=i,this.#x=this.options,this.#Q=this.#I.state),i}getCurrentResult(){return this.#E}trackResult(e,t){return new Proxy(e,{get:(e,s)=>(this.trackProp(s),t?.(s),"promise"!==s||this.options.experimental_prefetchInRender||"pending"!==this.#T.status||this.#T.reject(Error("experimental_prefetchInRender feature flag is not enabled")),Reflect.get(e,s))})}trackProp(e){this.#k.add(e)}getCurrentQuery(){return this.#I}refetch({...e}={}){return this.fetch({...e})}fetchOptimistic(e){let t=this.#o.defaultQueryOptions(e),s=this.#o.getQueryCache().build(this.#o,t);return s.fetch().then(()=>this.createResult(s,t))}fetch(e){return this.#j({...e,cancelRefetch:e.cancelRefetch??!0}).then(()=>(this.updateResult(),this.#E))}#j(e){this.#H();let t=this.#I.fetch(this.options,e);return e?.throwOnError||(t=t.catch(p)),t}#G(){this.#N();let e=m(this.options.staleTime,this.#I);if(d||this.#E.isStale||!f(e))return;let t=y(this.#E.dataUpdatedAt,e);this.#M=setTimeout(()=>{this.#E.isStale||this.updateResult()},t+1)}#B(){return("function"==typeof this.options.refetchInterval?this.options.refetchInterval(this.#I):this.options.refetchInterval)??!1}#$(e){this.#K(),this.#D=e,!d&&!1!==b(this.options.enabled,this.#I)&&f(this.#D)&&0!==this.#D&&(this.#U=setInterval(()=>{(this.options.refetchIntervalInBackground||A.isFocused())&&this.#j()},this.#D))}#L(){this.#G(),this.#$(this.#B())}#N(){this.#M&&(clearTimeout(this.#M),this.#M=void 0)}#K(){this.#U&&(clearInterval(this.#U),this.#U=void 0)}createResult(e,t){let s,r=this.#I,i=this.options,n=this.#E,a=this.#Q,u=this.#x,o=e!==r?e.state:this.#P,{state:l}=e,c={...l},h=!1;if(t._optimisticResults){let s=this.hasListeners(),n=!s&&X(e,t),a=s&&ee(e,r,t,i);(n||a)&&(c={...c,...H(l.data,e.options)}),"isRestoring"===t._optimisticResults&&(c.fetchStatus="idle")}let{error:d,errorUpdatedAt:p,status:f}=c;s=c.data;let y=!1;if(void 0!==t.placeholderData&&void 0===s&&"pending"===f){let e;n?.isPlaceholderData&&t.placeholderData===u?.placeholderData?(e=n.data,y=!0):e="function"==typeof t.placeholderData?t.placeholderData(this.#A?.state.data,this.#A):t.placeholderData,void 0!==e&&(f="success",s=I(n?.data,e,t),h=!0)}if(t.select&&void 0!==s&&!y)if(n&&s===a?.data&&t.select===this.#F)s=this.#_;else try{this.#F=t.select,s=t.select(s),s=I(n?.data,s,t),this.#_=s,this.#q=null}catch(e){this.#q=e}this.#q&&(d=this.#q,s=this.#_,p=Date.now(),f="error");let m="fetching"===c.fetchStatus,g="pending"===f,v="error"===f,C=g&&m,w=void 0!==s,O={status:f,fetchStatus:c.fetchStatus,isPending:g,isSuccess:"success"===f,isError:v,isInitialLoading:C,isLoading:C,data:s,dataUpdatedAt:c.dataUpdatedAt,error:d,errorUpdatedAt:p,failureCount:c.fetchFailureCount,failureReason:c.fetchFailureReason,errorUpdateCount:c.errorUpdateCount,isFetched:c.dataUpdateCount>0||c.errorUpdateCount>0,isFetchedAfterMount:c.dataUpdateCount>o.dataUpdateCount||c.errorUpdateCount>o.errorUpdateCount,isFetching:m,isRefetching:m&&!g,isLoadingError:v&&!w,isPaused:"paused"===c.fetchStatus,isPlaceholderData:h,isRefetchError:v&&w,isStale:et(e,t),refetch:this.refetch,promise:this.#T,isEnabled:!1!==b(t.enabled,e)};if(this.options.experimental_prefetchInRender){let t=e=>{"error"===O.status?e.reject(O.error):void 0!==O.data&&e.resolve(O.data)},s=()=>{t(this.#T=O.promise=U())},i=this.#T;
2switch(i.status){case"pending":e.queryHash===r.queryHash&&t(i);break;case"fulfilled":("error"===O.status||O.data!==i.value)&&s();break;case"rejected":("error"!==O.status||O.error!==i.reason)&&s()}}return O}updateResult(){let e=this.#E,t=this.createResult(this.#I,this.options);if(this.#Q=this.#I.state,this.#x=this.options,void 0!==this.#Q.data&&(this.#A=this.#I),R(t,e))return;this.#E=t;let s=()=>{if(!e)return!0;let{notifyOnChangeProps:t}=this.options,s="function"==typeof t?t():t;if("all"===s||!s&&!this.#k.size)return!0;let r=new Set(s??this.#k);return this.options.throwOnError&&r.add("error"),Object.keys(this.#E).some(t=>this.#E[t]!==e[t]&&r.has(t))};this.#J({listeners:s()})}#H(){let e=this.#o.getQueryCache().build(this.#o,this.options);if(e===this.#I)return;let t=this.#I;this.#I=e,this.#P=e.state,this.hasListeners()&&(t?.removeObserver(this),e.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#L()}#J(e){F.batch(()=>{e.listeners&&this.listeners.forEach(e=>{e(this.#E)}),this.#o.getQueryCache().notify({query:this.#I,type:"observerResultsUpdated"})})}};function X(e,t){return!1!==b(t.enabled,e)&&void 0===e.state.data&&("error"!==e.state.status||!1!==t.retryOnMount)||void 0!==e.state.data&&Z(e,t,t.refetchOnMount)}function Z(e,t,s){if(!1!==b(t.enabled,e)&&"static"!==m(t.staleTime,e)){let r="function"==typeof s?s(e):s;return"always"===r||!1!==r&&et(e,t)}return!1}function ee(e,t,s,r){return(e!==t||!1===b(r.enabled,e))&&(!s.suspense||"error"!==e.state.status)&&et(e,s)}function et(e,t){return!1!==b(t.enabled,e)&&e.isStaleByTime(m(t.staleTime,e))}var es=c.createContext(void 0),er=e=>{let t=c.useContext(es);if(e)return e;if(!t)throw Error("No QueryClient set, use QueryClientProvider to set one");return t},ei=({client:e,children:t})=>(c.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),(0,h.jsx)(es.Provider,{value:e,children:t})),en=c.createContext((u=!1,{clearReset:()=>{u=!1},reset:()=>{u=!0},isReset:()=>u})),ea=c.createContext(!1);ea.Provider;var eu=(e,t,s)=>t.fetchOptimistic(e).catch(()=>{s.clearReset()});function eo(e,t){return function(e,t,s){let r=c.useContext(ea),i=c.useContext(en),n=er(s),a=n.defaultQueryOptions(e);if(n.getDefaultOptions().queries?._experimental_beforeQuery?.(a),a._optimisticResults=r?"isRestoring":"optimistic",a.suspense){let e=e=>"static"===e?e:Math.max(e??1e3,1e3),t=a.staleTime;a.staleTime="function"==typeof t?(...s)=>e(t(...s)):e(t),"number"==typeof a.gcTime&&(a.gcTime=Math.max(a.gcTime,1e3))}(a.suspense||a.throwOnError||a.experimental_prefetchInRender)&&!i.isReset()&&(a.retryOnMount=!1),c.useEffect(()=>{i.clearReset()},[i]);let u=!n.getQueryCache().get(a.queryHash),[o]=c.useState(()=>new t(n,a)),l=o.getOptimisticResult(a),h=!r&&!1!==e.subscribed;if(c.useSyncExternalStore(c.useCallback(e=>{let t=h?o.subscribe(F.batchCalls(e)):p;return o.updateResult(),t},[o,h]),()=>o.getCurrentResult(),()=>o.getCurrentResult()),c.useEffect(()=>{o.setOptions(a)},[a,o]),a?.suspense&&l.isPending)throw eu(a,o,i);if((({result:e,errorResetBoundary:t,throwOnError:s,query:r,suspense:i})=>{var n;return e.isError&&!t.isReset()&&!e.isFetching&&r&&(i&&void 0===e.data||(n=[e.error,r],"function"==typeof s?s(...n):!!s))})({result:l,errorResetBoundary:i,throwOnError:a.throwOnError,query:n.getQueryCache().get(a.queryHash),suspense:a.suspense}))throw l.error;if(n.getDefaultOptions().queries?._experimental_afterQuery?.(a,l),a.experimental_prefetchInRender&&!d&&l.isLoading&&l.isFetching&&!r){let e=u?eu(a,o,i):n.getQueryCache().get(a.queryHash)?.promise;e?.catch(p).finally(()=>{o.updateResult()})}return a.notifyOnChangeProps?l:o.trackResult(l)}(e,V,t)}var el=(0,c.createContext)(null),ec=({caller:e})=>{let t=(0,c.useContext)(el);if(!t)throw Error(`${e} must be used within <AutumnProvider/>`);return t.client};e.s(["AutumnContext",0,el,"useAutumnClient",0,ec],949855),e.s(["AutumnProvider",0,({children:e,backendUrl:t,pathPrefix:s,useBetterAuth:r,includeCredentials:i,headers:n})=>{let a=(0,c.useRef)(null);a.current||(a.current=new Y({defaultOptions:{queries:{staleTime:6e4,retry:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1}}}));let u=(0,c.useMemo)(()=>({client:l({backendUrl:t,pathPrefix:s??(r?"/api/auth/autumn":"/api/autumn"),includeCredentials:i??r,headers:n})}),[t,s,r,i,JSON.stringify(n)]);return(0,h.jsx)(ei,{client:a.current,children:(0,h.jsx)(el.Provider,{value:u,children:e})})}],267676),e.s(["useAggregateEvents",0,e=>{let t=ec({caller:"useAggregateEvents"}),{queryOptions:s,customRange:r,...i}=e,n=r?.start?new Date(r.start).toISOString().slice(0,13):void 0,a=r?.end?new Date(r.end).toISOString().slice(0,13):void 0,u=eo({queryKey:["autumn","events","aggregate",i.featureId,i.groupBy,i.range,i.binSize,n,a],queryFn:()=>t.aggregateEvents({...i,customRange:r}),...s});return(0,c.useMemo)(()=>({...u,list:u.data?.list,total:u.data?.total}),[u])}],582681);var eh=({balance:e,feature:t,requiredBalance:s})=>{if("boolean"===t.type||e.unlimited||s<0)return!0;
2if(e.overageAllowed){let t=(({balance:e})=>{let t=(e.breakdown??[]).filter(e=>e.price?.billingMethod==="usage_based");if(0===t.length)return e.maxPurchase??void 0;let s=0,r=0;for(let e of t){if(e.price?.maxPurchase===null)return;e.price?.maxPurchase!==void 0&&(s+=e.price.maxPurchase),r+=Math.max(0,e.usage-e.includedGrant-e.prepaidGrant)}return Math.max(0,s-r)})({balance:e});return void 0===t||e.remaining+t>=s}return e.remaining>=s},ed=({featureId:e,creditSystem:t,amount:s=1})=>{if("credit_system"!==t.type)return s;let r=t.creditSchema?.find(t=>t.meteredFeatureId===e);return s*(r?.creditCost??1)},ep=({url:e,openInNewTab:t})=>{t?window.open(e,"_blank"):window.location.href=e};e.s(["useCustomer",0,(e={})=>{let t=ec({caller:"useCustomer"}),{errorOnNotFound:s,queryOptions:r,...i}=e,n=eo({queryKey:["autumn","customer",i],queryFn:()=>t.getOrCreateCustomer({...i,...void 0!==s&&{errorOnNotFound:s}}),...r}),a=(({client:e,customer:t})=>{let s=er(),r=(0,c.useCallback)(async t=>{let r=await e.attach({...t,successUrl:t.successUrl??window.location.href});return r.paymentUrl?ep({url:r.paymentUrl,openInNewTab:t.openInNewTab}):s.invalidateQueries({queryKey:["autumn"]}),r},[e,s]),i=(0,c.useCallback)(async t=>e.previewAttach(t),[e]),n=(0,c.useCallback)(async t=>{let r=await e.updateSubscription(t);return r.paymentUrl?ep({url:r.paymentUrl,openInNewTab:t.openInNewTab}):s.invalidateQueries({queryKey:["autumn"]}),r},[e,s]),a=(0,c.useCallback)(async t=>e.previewUpdateSubscription(t),[e]),u=(0,c.useCallback)(e=>(({customer:e,params:t})=>{if(!e)return{allowed:!1,customerId:"",entityId:t.entityId??null,requiredBalance:t.requiredBalance??1,balance:null,flag:null};if(!t.featureId)throw Error("check() requires featureId");return(({customer:e,params:t})=>{let{featureId:s,requiredBalance:r=1}=t;if(e.flags[s])return{allowed:!0,customerId:e.id??"",entityId:t.entityId??null,requiredBalance:r,balance:null,flag:e.flags[s]};let i=(({customer:e})=>{let t=[...Object.values(e.balances),...Object.values(e.flags)];if(0===t.length)return[];if(!t[0].feature)throw Error("[customerToFeatures] please expand `balances.feature` or `flags.feature` to get features for the customer");return t.map(e=>e.feature).filter(e=>!!e)})({customer:e}),n=i.find(e=>e.id===s);if(!n)return{allowed:!1,customerId:e.id??"",entityId:t.entityId??null,requiredBalance:r,balance:null,flag:null};let a=(({featureId:e,features:t,feature:s,customer:r,requiredBalance:i})=>{let n=(({featureId:e,features:t})=>t.filter(t=>t.id!==e&&"credit_system"===t.type&&t.creditSchema?.some(t=>t.meteredFeatureId===e)))({featureId:e,features:t});if(0===n.length)return s;let a=r.balances[s.id];if(a&&eh({balance:a,feature:s,requiredBalance:i}))return s;for(let e of n){let t=r.balances[e.id];if(!t)continue;let n=ed({featureId:s.id,creditSystem:e,amount:i});if(eh({balance:t,feature:e,requiredBalance:n}))return e}return n[0]})({featureId:s,features:i,feature:n,customer:e,requiredBalance:r}),u=e.balances[a.id];if(!u)return{allowed:!1,customerId:e.id??"",entityId:t.entityId??null,requiredBalance:r,balance:null,flag:null};let o="credit_system"===a.type&&a.id!==n.id?ed({featureId:n.id,creditSystem:a,amount:r}):r;return{allowed:eh({balance:u,feature:a,requiredBalance:o}),customerId:e.id??"",entityId:t.entityId??null,requiredBalance:o,balance:u,flag:null}})({customer:e,params:t})})({customer:t,params:e}),[t]),o=(0,c.useCallback)(async(t={})=>{let s=await e.openCustomerPortal({...t,returnUrl:t.returnUrl??window.location.href});return ep({url:s.url,openInNewTab:t.openInNewTab}),s},[e]),l=(0,c.useCallback)(async t=>{let r=await e.multiAttach({...t,successUrl:t.successUrl??window.location.href});return r.paymentUrl?ep({url:r.paymentUrl,openInNewTab:t.openInNewTab}):s.invalidateQueries({queryKey:["autumn"]}),r},[e,s]);return{attach:r,previewAttach:i,updateSubscription:n,previewUpdateSubscription:a,multiAttach:l,previewMultiAttach:(0,c.useCallback)(async t=>e.previewMultiAttach(t),[e]),check:u,openCustomerPortal:o,setupPayment:(0,c.useCallback)(async(t={})=>{let s=await e.setupPayment({...t,successUrl:t.successUrl??window.location.href}),r=s.url;return r&&ep({url:r,openInNewTab:t.openInNewTab}),s},[e])}})({client:t,customer:n.data??null});return{...n,...a}}],641688),e.s(["useEntity",0,e=>{let t=ec({caller:"useEntity"}),{queryOptions:s,...r}=e;return eo({queryKey:["autumn","entity",r],queryFn:()=>t.getEntity(r),...s})}],627288),e.s(["useListEvents",0,(e={})=>{let t=ec({caller:"useListEvents"}),{queryOptions:s,limit:r,startCursor:i,customRange:n,...a}=e,u=r??100,o=i??"",l=JSON.stringify({...a,customRange:n,limit:u,initialStartCursor:o}),[h,d]=(0,c.useState)({key:l,page:0,startCursors:[o]}),p=h.key===l?h:{key:l,page:0,startCursors:[o]},f=p.startCursors[p.page]??o,y=n?.start?new Date(n.start).toISOString().slice(0,13):void 0,m=n?.end?new Date(n.end).toISOString().slice(0,13):void 0,b=eo({queryKey:["autumn","events","list",a.featureId,a.entity
2Id,y,m,f,u],queryFn:()=>t.listEvents({...a,customRange:n,startCursor:f,limit:u}),...s}),g=b.data?.nextCursor!==null&&b.data?.nextCursor!==void 0,v=p.page>0,C=(0,c.useCallback)(()=>{g&&d(e=>{let t=e.key===l?e:{key:l,page:0,startCursors:[o]},s=t.startCursors.slice(0,t.page+1);return s[t.page+1]=b.data?.nextCursor??"",{key:l,page:t.page+1,startCursors:s}})},[g,o,l,b.data?.nextCursor]),w=(0,c.useCallback)(()=>{v&&d(e=>{let t=e.key===l?e:p;return{...t,page:Math.max(0,t.page-1)}})},[v,p,l]),O=(0,c.useCallback)(({pageNum:e})=>{d(t=>{let s=t.key===l?t:p;return{...s,page:Math.max(0,Math.min(e,s.startCursors.length-1))}})},[p,l]),R=(0,c.useCallback)(()=>{d({key:l,page:0,startCursors:[o]})},[o,l]);return(0,c.useMemo)(()=>({...b,list:b.data?.list,hasMore:g,hasPrevious:v,page:p.page,nextPage:C,prevPage:w,goToPage:O,resetPagination:R}),[b,g,v,p.page,C,w,O,R])}],754485),e.s(["useListPlans",0,(e={})=>{let t=ec({caller:"useListPlans"}),{queryOptions:s,...r}=e;return eo({queryKey:["autumn","plans",r],queryFn:async()=>(await t.listPlans(r)).list,...s})}],916349),e.s(["useReferrals",0,e=>{let t=ec({caller:"useReferrals"}),{programId:s,queryOptions:r}=e,i=eo({queryKey:["autumn","referrals","create",s],queryFn:()=>t.createReferralCode({programId:s}),enabled:!1,...r}),n=(0,c.useCallback)(async e=>t.redeemReferralCode(e),[t]);return{...i,redeemCode:n}}],650379),e.s([],669305)}]); 3 4//# debugId=ddd0f579-dc82-8910-667d-2a0701de3964
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.