palbase 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai/index.js +2 -2
- package/dist/backend/engine.js +2 -2
- package/dist/backend/env.js +1 -1
- package/dist/backend/index.js +3 -3
- package/dist/backend/stack.js +1 -1
- package/dist/backend/test.js +2 -2
- package/dist/chunks/{RO5Y5YU4.js → 23G5YVSL.js} +1 -1
- package/dist/chunks/{JSJVV43D.js → 3X7CRIHE.js} +1 -1
- package/dist/chunks/5UXVSEM2.js +2 -0
- package/dist/chunks/6YCANJ7U.js +2 -0
- package/dist/chunks/{BO5KR2EQ.js → 7HMBZG2R.js} +2 -2
- package/dist/chunks/{RBA6V3UO.js → 7OZCS3BA.js} +2 -2
- package/dist/chunks/FFWT3RBE.js +13 -0
- package/dist/chunks/{TUGRIOFX.js → GGKL7UV2.js} +2 -2
- package/dist/chunks/HGQXQMYU.js +95 -0
- package/dist/chunks/{Z5JVQNAZ.js → I45DYZZL.js} +2 -2
- package/dist/chunks/{WEI32SAJ.js → KSU226RI.js} +2 -2
- package/dist/chunks/MEIN5GAG.js +22 -0
- package/dist/chunks/OEZLXSQN.js +6 -0
- package/dist/chunks/{BRBCWPR3.js → OGREZP5F.js} +1 -1
- package/dist/chunks/{PGPQGKH2.js → ONP77MHF.js} +2 -2
- package/dist/chunks/{KDWDPSL2.js → QR4Z3ORW.js} +1 -1
- package/dist/chunks/{K6RRNI23.js → R5NCHIW3.js} +2 -2
- package/dist/chunks/{PDOHT46N.js → RV35QG7V.js} +2 -2
- package/dist/chunks/{P4Z5E6ZI.js → YOTK5642.js} +2 -2
- package/dist/chunks/{5VTGMNPL.js → Z7VRCVKE.js} +6 -6
- package/dist/cli.js +129 -127
- package/dist/refuse/ai.js +1 -1
- package/dist/refuse/backend.js +1 -1
- package/dist/refuse/server.js +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/testing.js +2 -2
- package/dist/web/index.js +2 -2
- package/dist/web/message.js +2 -0
- package/dist/web/palbe.js +2 -2
- package/dist/web/paywall.js +2 -2
- package/dist/web/push-sw.js +2 -0
- package/dist/web/ssr.js +2 -2
- package/dist/web/vite.js +2 -2
- package/package.json +9 -2
- package/types/backend/src/services.d.ts +2 -2
- package/types/internal/src/modules/ai.d.ts +1 -1
- package/types/internal/src/modules/analytics.d.ts +618 -1
- package/types/internal/src/modules/auth.d.ts +409 -90
- package/types/internal/src/modules/events.d.ts +7 -3
- package/types/internal/src/modules/flags.d.ts +380 -14
- package/types/internal/src/modules/notify.d.ts +2270 -99
- package/types/internal/src/modules/purchases.d.ts +773 -2
- package/types/server/src/webhooks.d.ts +1 -1
- package/types/web/src/analytics.d.ts +56 -5
- package/types/web/src/client.d.ts +26 -4
- package/types/web/src/consent.d.ts +218 -0
- package/types/web/src/flags.d.ts +75 -0
- package/types/web/src/inapp.d.ts +129 -0
- package/types/web/src/inbox.d.ts +59 -0
- package/types/web/src/index.d.ts +9 -3
- package/types/web/src/installation.d.ts +16 -0
- package/types/web/src/message/index.d.ts +5 -0
- package/types/web/src/message/present.d.ts +20 -0
- package/types/web/src/notify.d.ts +67 -0
- package/types/web/src/paywall/index.d.ts +4 -4
- package/types/web/src/paywall/placement.d.ts +11 -12
- package/types/web/src/paywall/prices.d.ts +7 -2
- package/types/web/src/purchases.d.ts +80 -5
- package/types/web/src/{paywall → screen}/assets.d.ts +6 -6
- package/types/web/src/screen/render.d.ts +186 -0
- package/types/web/src/{paywall → screen}/resolve.d.ts +56 -8
- package/dist/chunks/DB3SIBKB.js +0 -2
- package/dist/chunks/EGNEXFTZ.js +0 -2
- package/dist/chunks/FZ3MQOVA.js +0 -6
- package/dist/chunks/WINBISC2.js +0 -92
- package/types/web/src/paywall/render.d.ts +0 -93
- /package/types/web/src/{paywall → screen}/icons.d.ts +0 -0
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import type { purchases } from '../../../internal/src/modules/index.js';
|
|
1
|
+
import type { notify, purchases } from '../../../internal/src/modules/index.js';
|
|
2
2
|
export type PaywallDefinition = purchases.PaywallDefinition;
|
|
3
|
+
export type MessageDefinition = notify.MessageDefinition;
|
|
4
|
+
/** What a screen is for: a paywall sells the catalog's packages; a message is shown in the app, or as a card of its inbox. */
|
|
5
|
+
export type ScreenKind = 'paywall' | 'message';
|
|
3
6
|
export type Platform = 'ios' | 'android' | 'web';
|
|
4
7
|
export type Appearance = 'light' | 'dark';
|
|
5
8
|
/** What the store gave a package, as the variables of its texts: `{{price}}` … */
|
|
@@ -10,9 +13,12 @@ export interface PackageValues {
|
|
|
10
13
|
trial?: string;
|
|
11
14
|
savings?: string;
|
|
12
15
|
product_name?: string;
|
|
16
|
+
/** The price of the package's offer while the customer may take it (ResolveOptions.offers). */
|
|
17
|
+
offer_price?: string;
|
|
13
18
|
}
|
|
14
|
-
/** The schema this renderer draws: what the SDK asks the server for (X-Palbase-Paywall-Schema). */
|
|
19
|
+
/** The schema this renderer draws: what the SDK asks the server for (X-Palbase-Paywall-Schema, X-Palbase-Screen-Schema). */
|
|
15
20
|
export declare const PAYWALL_SCHEMA = 2;
|
|
21
|
+
export declare const MESSAGE_SCHEMA = 2;
|
|
16
22
|
export interface ResolveOptions {
|
|
17
23
|
/** The app's language (`tr-TR`). */
|
|
18
24
|
locale: string;
|
|
@@ -22,6 +28,8 @@ export interface ResolveOptions {
|
|
|
22
28
|
packages: Record<string, PackageValues>;
|
|
23
29
|
/** The packages whose introductory offer (a trial) the customer can still take. */
|
|
24
30
|
eligible?: readonly string[];
|
|
31
|
+
/** The catalog's offers the customer may take now (GET /purchases/offers): a package sold with one is bought with it, its {{offer_price}} the offer's price. */
|
|
32
|
+
offers?: readonly string[];
|
|
25
33
|
/** The package the customer selected; absent, the paywall's own selection. */
|
|
26
34
|
selected?: string;
|
|
27
35
|
/** The tab shown in every tabs component, and each switch's side — the paywall's defaults when absent. */
|
|
@@ -34,6 +42,11 @@ export interface ResolveOptions {
|
|
|
34
42
|
openedSecondsAgo?: number;
|
|
35
43
|
now?: number;
|
|
36
44
|
}
|
|
45
|
+
/** A message resolved: what its texts name is its sender's values — no packages, nothing selected. */
|
|
46
|
+
export interface MessageResolveOptions extends Omit<ResolveOptions, 'packages' | 'eligible' | 'offers' | 'selected'> {
|
|
47
|
+
/** The values its sender gave: `{{first_name}}`, `{{order}}` …; a text naming one it gave none for is not drawn. */
|
|
48
|
+
variables?: Readonly<Record<string, string>>;
|
|
49
|
+
}
|
|
37
50
|
/** A component resolved: its type, its fields with every token and default resolved. */
|
|
38
51
|
export type ResolvedNode = {
|
|
39
52
|
type: string;
|
|
@@ -115,9 +128,8 @@ export interface ResolvedTypeStyle {
|
|
|
115
128
|
letter_spacing: number;
|
|
116
129
|
text_style: string;
|
|
117
130
|
}
|
|
118
|
-
/**
|
|
119
|
-
export interface
|
|
120
|
-
selected: string;
|
|
131
|
+
/** A definition as drawn, the contract's resolved tree: what every kind's has. */
|
|
132
|
+
export interface ResolvedScreen {
|
|
121
133
|
theme: {
|
|
122
134
|
colors: Record<string, string>;
|
|
123
135
|
typography: Record<string, ResolvedTypeStyle>;
|
|
@@ -129,9 +141,32 @@ export interface ResolvedPaywall {
|
|
|
129
141
|
footer?: ResolvedNode;
|
|
130
142
|
sheets?: Record<string, ResolvedNode>;
|
|
131
143
|
}
|
|
144
|
+
/** A paywall as drawn: the package selected, too. */
|
|
145
|
+
export interface ResolvedPaywall extends ResolvedScreen {
|
|
146
|
+
selected: string;
|
|
147
|
+
}
|
|
148
|
+
/** How a message is shown, with its type's fields and their defaults (contracts/message/README.md). */
|
|
149
|
+
export type ResolvedPresentation = {
|
|
150
|
+
type: 'modal';
|
|
151
|
+
dismissible: boolean;
|
|
152
|
+
backdrop: string;
|
|
153
|
+
} | {
|
|
154
|
+
type: 'fullscreen';
|
|
155
|
+
} | {
|
|
156
|
+
type: 'banner';
|
|
157
|
+
position: 'top' | 'bottom';
|
|
158
|
+
dismissible: boolean;
|
|
159
|
+
auto_dismiss_seconds?: number;
|
|
160
|
+
} | {
|
|
161
|
+
type: 'card';
|
|
162
|
+
};
|
|
163
|
+
/** A message as drawn: how it is shown, too. */
|
|
164
|
+
export interface ResolvedMessage extends ResolvedScreen {
|
|
165
|
+
presentation: ResolvedPresentation;
|
|
166
|
+
}
|
|
132
167
|
/** Beside the tree: where in the definition each node is (its path, as the server's problems name it), and what is not part of the tree. */
|
|
133
|
-
export interface Resolution {
|
|
134
|
-
tree:
|
|
168
|
+
export interface Resolution<T extends ResolvedScreen = ResolvedPaywall> {
|
|
169
|
+
tree: T;
|
|
135
170
|
/** A node's path in the definition: `root.children[2]`, `sheets.offer.root`. */
|
|
136
171
|
pathOf(node: object): string | undefined;
|
|
137
172
|
/** The tab shown in each tabs component and each switch's side, by path. */
|
|
@@ -173,12 +208,25 @@ type Spec = Record<string, Field>;
|
|
|
173
208
|
export declare const COMPONENT_FIELDS: Record<string, Spec>;
|
|
174
209
|
/** The components a definition has, by type. */
|
|
175
210
|
export declare const PAYWALL_COMPONENTS: readonly string[];
|
|
211
|
+
export declare const MESSAGE_COMPONENTS: readonly string[];
|
|
212
|
+
/**
|
|
213
|
+
* A value as a part of an address: every byte of its UTF-8 but a letter, a
|
|
214
|
+
* digit and -._~ as %XX (contracts/message/README.md) — a value never adds a
|
|
215
|
+
* part, a query or a fragment.
|
|
216
|
+
*/
|
|
217
|
+
export declare function pathPart(value: string): string;
|
|
176
218
|
/** {{countdown}} and its parts for a time left, in seconds. */
|
|
177
219
|
export declare function countdownValues(left: number): Record<string, string>;
|
|
178
220
|
/** Every package a definition sells, `<product>.<plan>`, in the order it names them: the header, the root, the footer, then its sheets. */
|
|
179
221
|
export declare function packagesOf(definition: PaywallDefinition): string[];
|
|
180
|
-
/**
|
|
222
|
+
/** The offer each package of a definition is sold with, by `<product>.<plan>`: its first package component's `offer`. */
|
|
223
|
+
export declare function packageOffers(definition: PaywallDefinition | MessageDefinition): Map<string, string>;
|
|
224
|
+
/** A paywall's definition as drawn (contracts/paywall/README.md). */
|
|
181
225
|
export declare function resolve(definition: PaywallDefinition, opts: ResolveOptions): ResolvedPaywall;
|
|
182
226
|
/** The same, with each node's path in the definition and the state the renderer keeps. */
|
|
183
227
|
export declare function resolution(definition: PaywallDefinition, opts: ResolveOptions): Resolution;
|
|
228
|
+
/** A message's definition as drawn (contracts/message/README.md). */
|
|
229
|
+
export declare function resolveMessage(definition: MessageDefinition, opts: MessageResolveOptions): ResolvedMessage;
|
|
230
|
+
/** The same, with each node's path in the definition and the state the renderer keeps. */
|
|
231
|
+
export declare function messageResolution(definition: MessageDefinition, opts: MessageResolveOptions): Resolution<ResolvedMessage>;
|
|
184
232
|
export {};
|
package/dist/chunks/DB3SIBKB.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/*! palbase 0.8.0 — Palbase SDK License (see LICENSE) */
|
|
2
|
-
import{e as B,g as G,h as H}from"./WEI32SAJ.js";import{u as J}from"./WINBISC2.js";import{b as M,c as w,h as F}from"./EGNEXFTZ.js";import{a as $,b as S}from"./BO5KR2EQ.js";import{b as O,d as b}from"./PDOHT46N.js";function re(n){let e=n,t=e?.body,s=t&&typeof t=="object"?t.reason:void 0;return s==="user_deleted"?"userDeleted":s==="user_banned"?"userBanned":e?.code==="session_expired"||e?.code==="token_expired"?"expired":"revoked"}var y=class extends Error{code="session_changed";constructor(e){super(e),this.name="SessionChangedError"}};function V(){let n=null;return{load:()=>n,save:e=>{n=e},clear:()=>{n=null},shared:!1}}function W(n){let e=null,t=!0,s=()=>{try{return globalThis.localStorage}catch{return}};return{shared:!0,load(){try{let i=s()?.getItem(n);return i==null?t?null:e:JSON.parse(i)}catch{return e}},save(i){e=i;try{let r=s();if(!r)throw new Error("no storage");r.setItem(n,JSON.stringify(i)),t=!0}catch{t=!1}},clear(){e=null,t=!0;try{s()?.removeItem(n)}catch{}},watch(i){let r=globalThis;if(typeof r.addEventListener!="function")return()=>{};let a=o=>{(o.key===n||o.key===null)&&i()};return r.addEventListener("storage",a),()=>r.removeEventListener?.("storage",a)}}}function oe(n){try{let e=n.split(".")[1]??"",t=atob(e.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(e.length/4)*4,"=")),s=JSON.parse(t).sub;return typeof s=="string"?s:""}catch{return""}}var ae=6e4,le=15e3;function ce(n,e,t){let s=n?globalThis.navigator?.locks:void 0;return s?s.request(e,t):t()}var k=class{current=null;loaded;inflight=null;endReason=null;listeners=new Set;store;refresher;isRejected;now;lockName;refreshTimeoutMs;mode;constructor(e,t,s,i={}){this.store=e,this.refresher=t,this.isRejected=s,this.now=i.now??Date.now,this.lockName=i.lockName??"palbase.session.refresh",this.refreshTimeoutMs=i.refreshTimeoutMs??le,this.mode=i.refresh??"behind",this.loaded=Promise.resolve(e.load()).then(r=>{this.current=r}),e.watch?.(()=>{this.reconcile()})}async session(){return await this.loaded,this.current}snapshot(){return this.current}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}async set(e,t,s){await this.loaded;let i=t==="TOKEN_REFRESHED"?this.current:null,r={accessToken:e.access_token,refreshToken:e.refresh_token,expiresAt:this.now()+e.expires_in*1e3,userId:s?.id??i?.userId??oe(e.access_token),user:s??i?.user};return this.current=r,await this.store.save(r),this.emit(t,r),r}async setUser(e,t){await this.loaded,!(!this.current||!t||this.current.userId!==t.userId)&&(this.current={...this.current,user:e},await this.store.save(this.current),this.emit("USER_UPDATED",this.current))}async clear(e,t){await this.loaded;let s=this.current;this.current=null,this.inflight=null;let i=await this.store.load();(!i||!s||i.userId===s.userId)&&await this.store.clear(),s&&(e==="SESSION_EXPIRED"&&(this.endReason=t??"revoked"),this.emit(e,null))}async accessToken(){await this.loaded;let e=this.current;if(!e)return;let t=e.expiresAt-this.now();if(t>ae)return e.accessToken;if(this.mode==="never")return t>0?e.accessToken:void 0;if(t>0&&this.mode==="behind")return this.refresh().catch(()=>{}),e.accessToken;if(t>0)try{return(await this.refresh()).accessToken}catch(s){if(this.current===e)return e.accessToken;throw s}return(await this.refresh()).accessToken}refresh(){if(this.mode==="never")return Promise.reject(new Error("this client does not renew its session (refresh: 'never'): where the session cannot be written back, the request's middleware renews it"));if(this.inflight)return this.inflight;let e=ce(this.store.shared===!0,this.lockName,async()=>{await this.loaded;let t=this.current;if(!t)throw new y("no session to refresh");let s=await this.adoptStored(t);if(s)return s;try{let i=await this.withTimeout(this.refresher(t.refreshToken));if(this.current?.refreshToken!==t.refreshToken)throw new y("the session changed while it was refreshed");return await this.set(i,"TOKEN_REFRESHED")}catch(i){throw this.isRejected(i)&&this.current?.refreshToken===t.refreshToken&&await this.clear("SESSION_EXPIRED",re(i)),i}});return this.inflight=e,e.finally(()=>{this.inflight===e&&(this.inflight=null)}).catch(()=>{}),e}async adoptStored(e){let t=await this.store.load();if(!t)throw this.current=null,this.emit("SIGNED_OUT",null),new y("signed out in another tab");if(t.userId!==e.userId)throw this.current=t,this.emit("SIGNED_OUT",null),this.emit("SIGNED_IN",t),new y("another user signed in in another tab");if(t.refreshToken!==e.refreshToken&&t.expiresAt>=e.expiresAt)return this.current=t,this.emit("TOKEN_REFRESHED",t),t}async reconcile(){await this.loaded;let e=this.current,t=await this.store.load();if(!e){t&&(this.current=t,this.emit("SIGNED_IN",t));return}await this.adoptStored(e).catch(()=>{})}withTimeout(e){let t,s=new Promise((i,r)=>{t=setTimeout(()=>r(new Error(`the refresh did not answer within ${this.refreshTimeoutMs/1e3} s`)),this.refreshTimeoutMs)});return Promise.race([e,s]).finally(()=>clearTimeout(t))}emit(e,t){(e==="SIGNED_IN"||e==="SIGNED_OUT")&&(this.endReason=null);for(let s of this.listeners)try{s(e,t)}catch{}}};var N=class{state="closed";refusal;logSeq;joinRef=null;listeners=new Map;closers=new Set;joinWaiters=[];name;socket;constructor(e,t,s={}){this.name=e,this.socket=t,this.logSeq=s.after}get topic(){return`realtime:${this.name}`}join(){if(this.state==="joined")return Promise.resolve();let e=new Promise((t,s)=>this.joinWaiters.push({resolve:t,reject:s}));return this.state!=="joining"&&this.socket.join(this),e}leave(){this.socket.leave(this)}push(e,t){return this.socket.request(this,e,t)}on(e,t){let s=this.listeners.get(e);return s||this.listeners.set(e,s=new Set),s.add(t),()=>s.delete(t)}onClosed(e){return this.closers.add(e),()=>this.closers.delete(e)}deliver(e,t){e==="broadcast"&&typeof t.seq=="number"&&(this.logSeq=t.seq);for(let s of this.listeners.get(e)??[])try{s(t)}catch{}}settled(e,t){e&&typeof t.log_seq=="number"&&(this.logSeq=t.log_seq),this.state=e?"joined":"refused",this.refusal=e?void 0:t;let s=this.joinWaiters.splice(0);for(let i of s)e?i.resolve():i.reject(new Error(`join ${this.name} refused: ${JSON.stringify(t)}`))}closed(e){this.state="closed",this.joinRef=null;let t=this.joinWaiters.splice(0);for(let s of t)s.reject(new Error(`join ${this.name}: ${e}`));for(let s of[...this.closers])try{s()}catch{}}},R=class{ws=null;opening=null;ref=0;channels=new Map;replies=new Map;heartbeat=null;heartbeatRef=null;reconnectTimer=null;attempts=0;closedByUs=!1;reconnects=0;opts;constructor(e){this.opts=e}channel(e,t){let s=this.channels.get(e);return s||this.channels.set(e,s=new N(e,this,t)),s}disconnect(){this.closedByUs=!0,this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectTimer=null,this.stopHeartbeat();let e=this.ws;this.ws=null,this.opening=null,e?.close(1e3);for(let[,t]of this.replies)t("error",{reason:"socket closed"});this.replies.clear();for(let t of this.channels.values())t.closed("the socket was closed")}async tokenChanged(){if(!this.ws||this.ws.readyState!==1)return;let e=await this.opts.accessToken();if(e)for(let t of this.channels.values())t.state==="joined"&&this.push(t.joinRef,t.topic,"access_token",{access_token:e})}join(e){e.state="joining",this.open().then(()=>this.sendJoin(e)).catch(t=>e.settled(!1,{reason:t instanceof Error?t.message:String(t)}))}leave(e){e.state==="joined"&&this.ws?.readyState===1&&this.push(e.joinRef,e.topic,"phx_leave",{}),e.state="closed",this.channels.delete(e.name)}async request(e,t,s){let i=this.ws;if(this.channels.get(e.name)!==e||e.state!=="joined"||i?.readyState!==1)return{status:"error",response:{reason:"not joined"}};let r=this.nextRef(),a=JSON.stringify([e.joinRef,r,e.topic,t,s]),o=this.awaitReply(r);return i.send(a),o}open(){if(this.ws?.readyState===1)return Promise.resolve();if(this.opening)return this.opening;this.closedByUs=!1;let e=this.opts.webSocket??globalThis.WebSocket,t=`${this.opts.baseUrl.replace(/^http/,"ws")}/realtime/v1/websocket?vsn=2.0.0&apikey=${encodeURIComponent(this.opts.publishableKey)}`,s=new Promise((i,r)=>{let a=new e(t);this.ws=a,a.onopen=()=>{this.attempts=0,this.startHeartbeat(),i()},a.onmessage=o=>this.receive(String(o.data)),a.onerror=()=>r(new Error("the realtime socket could not be opened")),a.onclose=()=>this.dropped(a)});return this.opening=s,s.finally(()=>{this.opening===s&&(this.opening=null)}).catch(()=>{}),s}dropped(e){if(this.ws!==e)return;this.ws=null,this.stopHeartbeat();for(let[,i]of this.replies)i("error",{reason:"socket closed"});this.replies.clear();for(let i of this.channels.values())i.state==="joined"&&(i.state="joining");if(this.closedByUs||![...this.channels.values()].some(i=>i.state==="joining"))return;let t=this.opts.backoff??[500,1e3,2e3,5e3,1e4,3e4],s=t[Math.min(this.attempts,t.length-1)]*(.8+Math.random()*.4);this.attempts++,this.reconnectTimer=T(setTimeout(()=>{this.reconnectTimer=null,this.reconnects++;let i=[...this.channels.values()].filter(r=>r.state==="joining");this.open().then(()=>Promise.all(i.map(r=>this.sendJoin(r)))).catch(()=>{})},s))}async sendJoin(e){let t=await this.opts.accessToken(),s=this.nextRef();e.joinRef=s;let i=this.awaitReply(s),r={broadcast:{self:!1}};e.logSeq!==void 0&&(r.log={after:e.logSeq}),this.push(s,e.topic,"phx_join",{access_token:t,config:r},s);let{status:a,response:o}=await i;if(this.channels.get(e.name)!==e||e.state!=="joining"){a==="ok"&&this.ws?.readyState===1&&this.push(s,e.topic,"phx_leave",{});return}e.settled(a==="ok",o)}awaitReply(e){return new Promise(t=>{let s=T(setTimeout(()=>{this.replies.delete(e),t({status:"timeout",response:{reason:"no reply"}})},this.opts.replyTimeoutMs??1e4));this.replies.set(e,(i,r)=>{clearTimeout(s),this.replies.delete(e),t({status:i,response:r})})})}receive(e){let t;try{t=JSON.parse(e)}catch{return}if(!Array.isArray(t)||t.length!==5||typeof t[2]!="string"||typeof t[3]!="string")return;let[,s,i,r,a]=t,o=typeof a=="object"&&a!==null?a:{};if(r==="phx_reply"&&typeof s=="string"){if(s===this.heartbeatRef){this.heartbeatRef=null;return}this.replies.get(s)?.(String(o.status),o.response??{});return}let c=[...this.channels.values()].find(l=>l.topic===i);if(c){if(r==="phx_close"){c.state="closed";return}if(r==="phx_error"){c.state="joining",T(setTimeout(()=>this.channels.get(c.name)===c&&c.state==="joining"&&this.ws?.readyState===1&&void this.sendJoin(c),1e3));return}c.deliver(r,o)}}push(e,t,s,i,r=this.nextRef()){this.ws?.send(JSON.stringify([e,r,t,s,i]))}nextRef(){return String(++this.ref)}startHeartbeat(){this.stopHeartbeat(),this.heartbeat=T(setInterval(()=>{if(this.heartbeatRef!==null){this.heartbeatRef=null,this.ws?.close(4e3);return}this.heartbeatRef=this.nextRef(),this.push(null,"phoenix","heartbeat",{},this.heartbeatRef)},this.opts.heartbeatMs??25e3))}stopHeartbeat(){this.heartbeat&&clearInterval(this.heartbeat),this.heartbeat=null,this.heartbeatRef=null}};function T(n){return n.unref?.(),n}var he=30*6e4,X=1e3,de=100,fe=60*1024,P=()=>globalThis.crypto?.randomUUID?globalThis.crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;function I(){try{return globalThis.localStorage}catch{return}}var _=class{api;closingApi;flushMs;flushAt;now;anonKey;sessionKey;events=[];samples=[];timer;memoryAnon;memorySession;appVersion;stopAuto;session;identifyPending=!1;constructor(e,t,s,i={}){this.session=t,this.api=M.client(e),this.closingApi=M.client({send:r=>e.send({...r,keepalive:!0})}),this.flushMs=i.flushMs??5e3,this.flushAt=i.flushAt??20,this.now=i.now??Date.now,this.anonKey=`palbase.analytics.anonymous.${s}`,this.sessionKey=`palbase.analytics.session.${s}`,t.onChange(r=>{r==="SIGNED_IN"?(this.identifyPending=!0,this.soon()):r==="SIGNED_OUT"&&(this.identifyPending=!1,this.reset())})}capture(e,t){let s=this.now();this.hold({event:e,distinct_id:this.distinctId(),properties:t,timestamp:s,session_id:this.sessionId(s),...this.appVersion?{app_version:this.appVersion}:{}})}page(e={}){let t=globalThis.location,s=globalThis.document,i=e.url??(t?`${t.origin}${t.pathname}`:"");if(!i)return;let r=e.referrer??ve(s?.referrer);this.capture("$pageview",{...e.properties,url:i,...e.title??s?.title?{title:e.title??s?.title}:{},...r?{referrer:r}:{}})}async identify(e){this.identifyPending=!1;let t=this.session.snapshot()?.userId;t&&(await this.flush(),await this.sendIdentify(this.api,t,e))}async sendIdentify(e,t,s){try{await e.identify({body:{distinct_id:t,anonymous_id:this.anonymousId(),traits:s,timestamp:this.now(),sent_at:this.now()}})}catch{}}reset(){this.memoryAnon=void 0,this.memorySession=void 0;try{I()?.removeItem(this.anonKey),I()?.removeItem(this.sessionKey)}catch{}}async flush(e=!1){this.timer&&clearTimeout(this.timer),this.timer=void 0;let t=e?this.closingApi:this.api,s=this.now(),i=this.session.snapshot()?.userId;for(this.identifyPending&&i&&(this.identifyPending=!1,await this.sendIdentify(t,i));this.events.length>0;){let r=this.take(this.events,e);try{await t.batch({body:{events:r.map(a=>({...a,sent_at:s}))}})}catch{}}for(;this.samples.length>0;){let r=this.take(this.samples,e);try{await t.sendPerf({body:{items:r}})}catch{}}}start(e={}){this.stopAuto?.(),this.appVersion=e.appVersion;let t=globalThis;if(typeof t.addEventListener!="function"||typeof globalThis.document>"u")return()=>{};let s=[];e.pageViews!==!1&&s.push(this.watchPages(t)),e.webVitals!==!1&&s.push(me((a,o)=>this.sample("web_vital",a,o))),e.network!==!1&&s.push(this.watchFetch(t));let i=()=>{document.visibilityState==="hidden"&&this.flush(!0)},r=()=>{this.flush(!0)};return document.addEventListener("visibilitychange",i),t.addEventListener("pagehide",r),s.push(()=>{document.removeEventListener("visibilitychange",i),t.removeEventListener("pagehide",r)}),this.stopAuto=()=>{for(let a of s.splice(0))a();this.stopAuto=void 0},this.stopAuto}hold(e){this.events.length>=X&&this.events.shift(),this.events.push(e),this.soon()}sample(e,t,s,i={}){this.samples.length>=X&&this.samples.shift(),this.samples.push({row_id:P(),trace_type:e,name:t,value:Math.max(0,s),timestamp:this.now(),distinct_id:this.distinctId(),...i}),this.soon()}soon(){if(this.events.length+this.samples.length>=this.flushAt){this.flush();return}this.timer||(this.timer=setTimeout(()=>{this.flush()},this.flushMs),this.timer.unref?.())}take(e,t){let s=e.splice(0,de);if(!t)return s;for(;s.length>1&&JSON.stringify(s).length>fe;)e.unshift(s.pop());return s}distinctId(){return this.session.snapshot()?.userId??this.anonymousId()}anonymousId(){let e=I();try{let t=e?.getItem(this.anonKey);if(t)return t;let s=`anon_${P()}`;if(e?.setItem(this.anonKey,s),e?.getItem(this.anonKey)===s)return s}catch{}return this.memoryAnon??=`anon_${P()}`,this.memoryAnon}sessionId(e){let t=I(),s=this.memorySession;try{let r=t?.getItem(this.sessionKey);r&&(s=JSON.parse(r))}catch{}let i=s&&e-s.last<he?{id:s.id,last:e}:{id:`ses_${P()}`,last:e};this.memorySession=i;try{t?.setItem(this.sessionKey,JSON.stringify(i))}catch{}return i.id}watchPages(e){let t="",s=()=>{let o=`${e.location.origin}${e.location.pathname}`;o!==t&&(t=o,setTimeout(()=>this.page({url:o}),0))},i=e.history,r=i.pushState.bind(i),a=i.replaceState.bind(i);return i.pushState=(...o)=>{r(...o),s()},i.replaceState=(...o)=>{a(...o),s()},e.addEventListener("popstate",s),s(),()=>{i.pushState=r,i.replaceState=a,e.removeEventListener("popstate",s)}}watchFetch(e){let t=e.fetch;if(typeof t!="function")return()=>{};let s=async(i,r)=>{let a=performance.now(),o=i instanceof Request?i:void 0,c=(r?.method??o?.method??"GET").toUpperCase(),l;try{l=new URL(o?.url??String(i),e.location.href)}catch{l=void 0}let h=!!l&&l.pathname.startsWith("/analytics/")||ye(r?.headers??o?.headers);try{let d=await t(i,r);return l&&!h&&this.sample("network",`${c} ${l.origin}${l.pathname}`,performance.now()-a,{attrs:{status:String(d.status)},...d.headers.get("x-request-id")?{request_id:d.headers.get("x-request-id")}:{}}),d}catch(d){throw l&&!h&&this.sample("network",`${c} ${l.origin}${l.pathname}`,performance.now()-a,{attrs:{status:"0"}}),d}};return e.fetch=s,()=>{e.fetch===s&&(e.fetch=t)}}},pe=n=>n.entryType==="layout-shift"&&"value"in n&&"hadRecentInput"in n,ge=n=>n.entryType==="event"||n.entryType==="first-input";function E(n,e){if(!(typeof PerformanceObserver>"u"))try{let t=new PerformanceObserver(s=>e(s.getEntries()));return t.observe({type:n,buffered:!0}),t}catch{return}}function me(n){if(typeof document>"u"||typeof performance>"u"||typeof performance.getEntriesByType!="function")return()=>{};let e=0,t=0,s=0,i=[E("largest-contentful-paint",l=>{for(let h of l)e=Math.max(e,h.startTime)}),E("layout-shift",l=>{for(let h of l)pe(h)&&!h.hadRecentInput&&(t+=h.value)}),E("event",l=>{for(let h of l)ge(h)&&(s=Math.max(s,h.duration))}),E("paint",l=>{for(let h of l)h.name==="first-contentful-paint"&&n("FCP",h.startTime)})],r=performance.getEntriesByType("navigation")[0];r&&r.responseStart>0&&n("TTFB",r.responseStart);let a=!1,o=()=>{a||(a=!0,e>0&&n("LCP",e),n("CLS",t),s>0&&n("INP",s))},c=()=>{document.visibilityState==="hidden"&&o()};return document.addEventListener("visibilitychange",c),()=>{o(),document.removeEventListener("visibilitychange",c);for(let l of i)l?.disconnect()}}function ye(n){if(!n)return!1;try{return new Headers(n).has("next-router-prefetch")}catch{return!1}}function ve(n){if(!n)return"";try{let e=new URL(n);return`${e.origin}${e.pathname}`}catch{return n.split(/[?#]/,1)[0]??""}}var C=class{api;session;socket;ref;fetch;appVersion;app;listeners=new Set;watch;following;last;constructor(e,t,s,i,r,a,o){this.api=F.client(e),this.session=t,this.socket=s,this.ref=i,this.fetch=r,this.appVersion=a,this.app=o}async me(){let e=this.session.snapshot()?.userId,t=(await this.api.getMyCustomerInfo()).data;return this.watch&&this.watch.userId===e&&this.offer(this.watch,t),t}async offerings(e="web"){return(await this.api.getOfferings({query:{channel:e}})).data}async paywall(e,t={}){return J(this.api,this.ref,e,s=>this.checkout(s),{signal:t.signal,fetch:this.fetch,attributes:t.attributes,locale:t.locale,appVersion:this.appVersion,app:this.app})}async checkout(e){let t={product:e.product,plan:e.plan,success_url:e.successUrl,cancel_url:e.cancelUrl};return(await this.api.createCheckout({body:t})).data.url}async portal(e){return(await this.api.createPortalSession({body:{return_url:e}})).data.url}async mergeGrant(){return(await this.api.createMergeGrant()).data}async merge(e){let t=this.session.snapshot()?.userId,s=(await this.api.mergeGuest({body:{grant:typeof e=="string"?e:e.grant}})).data;return this.watch&&this.watch.userId===t&&this.offer(this.watch,s),s}onCustomerInfo(e){if(this.listeners.add(e),this.listeners.size===1)this.start();else if(this.last!==void 0){let t=this.last;queueMicrotask(()=>this.listeners.has(e)&&Y(e,t))}return()=>{this.listeners.delete(e)&&this.listeners.size===0&&this.stop()}}start(){this.following=this.session.onChange((e,t)=>{(e==="SIGNED_IN"||e==="SIGNED_OUT"||e==="SESSION_EXPIRED")&&this.follow(t)}),this.session.session().then(e=>{this.following&&!this.watch&&this.last===void 0&&this.follow(e)})}stop(){this.following?.(),this.following=void 0,this.unfollow(),this.last=void 0}follow(e){if(this.unfollow(),!e){this.tell(null);return}let t=this.socket.channel(`purchases:${this.ref}:${e.userId}`),s={userId:e.userId,channel:t,off:()=>{},revision:-1,reading:!1,wanted:Number.NEGATIVE_INFINITY},i=[t.on("broadcast",r=>{r.event==="changed"&&this.changed(s,L(r.payload))}),t.on("state_snapshot",r=>this.held(s,L(z(r.entries)))),t.on("state_diff",r=>this.held(s,L(z(r.set))))];s.off=()=>i.forEach(r=>r()),this.watch=s,t.join().catch(()=>{}),this.read(s)}unfollow(){let e=this.watch;e&&(this.watch=void 0,e.off(),e.channel.leave())}changed(e,t){this.watch!==e||t!==void 0&&t<=e.revision||(e.reading?e.wanted=Math.max(e.wanted,t??Number.POSITIVE_INFINITY):this.read(e))}held(e,t){t!==void 0&&this.changed(e,t)}async read(e){e.reading=!0;try{for(;;){e.wanted=Number.NEGATIVE_INFINITY;try{let t=(await this.api.getMyCustomerInfo()).data;if(this.watch!==e)return;this.offer(e,t)}catch{}if(this.watch!==e||e.wanted<=e.revision)return}}finally{e.reading=!1}}offer(e,t){this.watch!==e||t.revision<=e.revision||(e.revision=t.revision,this.tell(t))}tell(e){if(!(this.last===null&&e===null)){this.last=e;for(let t of[...this.listeners])Y(t,e)}}};function Y(n,e){try{n(e)}catch{}}function z(n){let e=typeof n=="object"&&n!==null?n.revision:void 0;return typeof e=="object"&&e!==null?e.v:void 0}function L(n){let e=typeof n=="object"&&n!==null?n.revision:void 0;return typeof e=="number"&&Number.isFinite(e)?e:void 0}var A=class{api;open;session;credentials;mfa;passkey;magicLink;phone;password;email;sessions;constructor(e,t,s,i){this.api=w.client(e),this.open=w.client(t),this.session=s,this.credentials=i;let r=this.api,a=this.open;this.mfa={challenge:async(o,c,l)=>this.signedIn((await a.mfaChallenge({body:{mfa_token:o,type:c,code:l}})).data),recovery:async(o,c)=>this.signedIn((await a.mfaRecovery({body:{mfa_token:o,code:c}})).data),sendSmsCode:async o=>{await a.mfaSmsChallenge({body:{mfa_token:o}})},sendEmailCode:async o=>{await a.mfaEmailChallenge({body:{mfa_token:o}})},enrollTotp:async()=>{let o=(await r.mfaEnroll({body:{type:"totp"}})).data;return{enrollmentId:o.enrollment_id,secret:o.secret,otpUrl:o.otp_url,qrCode:o.qr_code,recoveryCodes:o.recovery_codes}},verifyTotp:async o=>{await r.mfaVerifyEnrollment({body:{code:o}})},enrollSms:async o=>(await r.mfaSmsEnroll({body:{phone:o}})).data,verifySms:async o=>{await r.mfaSmsVerifyEnrollment({body:{code:o}})},enrollEmail:async()=>{await r.mfaEmailEnroll()},factors:async()=>(await r.mfaListFactors()).data,removeFactor:async(o,c)=>{await r.mfaRemoveFactor({path:{id:o},body:{current_password:c}})},regenerateRecoveryCodes:async()=>(await r.mfaRegenerateRecoveryCodes()).data},this.passkey={register:async o=>{let c=(await r.webauthnRegisterBegin({body:{name:o}})).data,l=await this.authenticator().create({publicKey:Z(c.options.publicKey)});return(await r.webauthnRegisterFinish({body:ee(l)})).data},signIn:async(o={})=>{let c=(await a.webauthnLoginBegin({body:o.userId?{user_id:o.userId}:{}})).data,l=await this.authenticator().get({publicKey:Q(c.options.publicKey)}),h=await a.webauthnLoginFinish({query:o.userId?{user_id:o.userId}:void 0,body:te(l)});return this.signedIn(h.data)},signUp:async(o,c)=>{let l=(await a.webauthnSignupBegin({body:{identifier:o,user_name:c}})).data,h=await this.authenticator().create({publicKey:Z(l.options.publicKey)});await a.webauthnSignupFinish({query:{user_id:l.user_id},body:ee(h)});let d=(await a.webauthnLoginBegin({body:{user_id:l.user_id}})).data,m=await this.authenticator().get({publicKey:Q(d.options.publicKey)});return this.signedIn((await a.webauthnLoginFinish({query:{user_id:l.user_id},body:te(m)})).data)},list:async()=>(await r.webauthnListCredentials()).data,remove:async o=>{await r.webauthnDeleteCredential({path:{id:o}})}},this.magicLink={send:async(o,c={})=>{await a.magicLinkRequest({body:{email:o,...c.redirectTo?{redirect_to:c.redirectTo}:{}}})},verify:async o=>this.signedIn((await a.magicLinkVerify({body:{token:o}})).data)},this.phone={sendCode:async o=>(await a.requestPhoneOtp({body:{phone:o,channel:"sms"}})).data,verifyCode:async(o,c)=>this.signInResult((await a.verifyPhoneOtp({body:{phone:o,token:c}})).data)},this.password={requestReset:async(o,c={})=>{await a.passwordResetRequest({body:{email:o,...c.redirectTo?{redirect_to:c.redirectTo}:{}}})},confirmReset:async(o,c)=>{await a.passwordResetConfirm({body:{token:o,new_password:c}})},change:async o=>(await r.passwordChange({body:o})).data,set:async o=>(await r.setPassword({body:o})).data},this.email={verify:async o=>{await a.verifyEmail({body:o})},resendVerification:async o=>(await a.resendVerification({body:{email:o}})).data},this.sessions={list:async()=>(await r.listSessions()).data,revoke:async o=>{await r.revokeSession({path:{id:o}})},revokeAll:async()=>{await r.revokeAllSessions()}}}onAuthStateChange(e){return this.session.onChange(e)}currentSession(){return this.session.session()}get sessionEndReason(){return this.session.endReason}async signUp(e){let t=(await this.open.signup({body:e})).data;return t.access_token&&t.refresh_token&&t.expires_in!==void 0&&await this.session.set({access_token:t.access_token,refresh_token:t.refresh_token,expires_in:t.expires_in},"SIGNED_IN",t.user),t}async signIn(e,t){return this.signInResult((await this.open.login({body:{email:e,password:t}})).data)}async signOut(){try{await this.session.session()&&await this.api.logout()}finally{await this.session.clear("SIGNED_OUT")}}async getUser(){let e=this.session.snapshot(),t=(await this.api.getMe()).data;return await this.session.setUser(t,e),t}async refreshSession(){return this.session.refresh()}async deleteAccount(e){await this.api.deleteAccount(e===void 0?void 0:{body:{password:e}}),await this.session.clear("SIGNED_OUT")}async signInResult(e){return"mfa_required"in e&&e.mfa_required?{mfaRequired:{mfaToken:e.mfa_token,factors:e.factors}}:{user:await this.signedIn(e)}}async setSession(e){return this.signedIn(e)}async signedIn(e){let t=await this.session.set({access_token:e.access_token,refresh_token:e.refresh_token,expires_in:e.expires_in},"SIGNED_IN",e.user);if(e.user)return e.user;let s=(await this.api.verifyTokenUser()).data;return await this.session.setUser(s,t),s}authenticator(){if(!this.credentials)throw new Error("passkeys need navigator.credentials (or createClient({ webauthn }))");return this.credentials}},x=n=>{let e=atob(n.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(n.length/4)*4,"=")),t=new Uint8Array(e.length);for(let s=0;s<e.length;s++)t[s]=e.charCodeAt(s);return t.buffer},g=n=>{if(!n)return;let e=n instanceof ArrayBuffer?new Uint8Array(n):new Uint8Array(n.buffer,n.byteOffset,n.byteLength),t="";for(let s of e)t+=String.fromCharCode(s);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")},se=n=>Array.isArray(n)?n.map(e=>({...e,id:x(String(e.id))})):void 0;function Z(n){let e=n.user;return{...n,challenge:x(String(n.challenge)),user:{...e,id:x(String(e.id))},excludeCredentials:se(n.excludeCredentials)}}function Q(n){return{...n,challenge:x(String(n.challenge)),allowCredentials:se(n.allowCredentials)}}function ee(n){let e=n,t=e.response;return{id:e.id,rawId:g(e.rawId),type:"public-key",authenticatorAttachment:e.authenticatorAttachment??void 0,clientExtensionResults:e.getClientExtensionResults?.()??{},response:{clientDataJSON:g(t.clientDataJSON),attestationObject:g(t.attestationObject),transports:t.getTransports?.()}}}function te(n){let e=n,t=e.response;return{id:e.id,rawId:g(e.rawId),type:"public-key",authenticatorAttachment:e.authenticatorAttachment??void 0,clientExtensionResults:e.getClientExtensionResults?.()??{},response:{clientDataJSON:g(t.clientDataJSON),authenticatorData:g(t.authenticatorData),signature:g(t.signature),userHandle:g(t.userHandle)}}}var we=/^pb_[a-z0-9]+_s/,be=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,Se=new Set(["invalid_token","token_expired","session_expired","session_revoked","missing_token"]),ke=new Set(["invalid_token","token_reuse","token_expired","session_revoked","session_expired","session_device_changed"]);function Te(n){return n.status===400&&n.code==="invalid_request"}function Be(n){if(we.test(n.publishableKey)||"secretKey"in n)throw new TypeError("a secret key never goes into a client app: palbase/web takes the publishable key (pb_<ref>_c\u2026); servers use palbase/server");let e=/^pb_([a-z0-9]+)_c/.exec(n.publishableKey)?.[1];if(e===void 0)throw new TypeError("publishableKey is the project publishable key (pb_<ref>_c\u2026)");if(n.appId!==void 0&&!be.test(n.appId))throw new TypeError("appId is the registered app's id, a UUID (settings.appId of palbase apps:sync), not its slug");let t=ne(n.language),s=(u,f)=>{let p=n.fetch??globalThis.fetch;if(t===void 0)return p(u,f);let v=new Headers(f?.headers);return v.has("accept-language")||v.set("accept-language",t),p(u,{...f,headers:v})},i=new URL(n.url).origin,r=n.storage??(Pe()?W(`palbase.session.${i}`):V()),a=n.retry??$,o=S(b({baseUrl:n.url,credentials:{publishableKey:n.publishableKey},fetch:s}),a),c=w.client(o),l=new k(r,async u=>(await c.refreshToken({body:{refresh_token:u}})).data,u=>u instanceof O&&(u.status===401&&ke.has(u.code)||Te(u)),{lockName:`palbase.session.refresh.${i}`,refresh:n.refresh}),h=b({baseUrl:n.url,credentials:{publishableKey:n.publishableKey,accessToken:()=>l.accessToken()},fetch:s,xmlHttpRequest:n.xmlHttpRequest??(n.fetch===void 0?globalThis.XMLHttpRequest:void 0)}),d=S(U(h,l),a),m=new R({baseUrl:n.url,publishableKey:n.publishableKey,accessToken:()=>l.accessToken(),webSocket:n.webSocket});l.onChange(u=>{u==="SIGNED_OUT"||u==="SESSION_EXPIRED"||u==="SIGNED_IN"?m.disconnect():u==="TOKEN_REFRESHED"&&m.tokenChanged()});let j=new _(U(h,l),l,i);n.analytics&&j.start(n.analytics===!0?{}:n.analytics);let q=new Map,ie=u=>{let f=new URL(u).origin,p=q.get(f);return p||(p=S(U(b({baseUrl:f,credentials:{accessToken:()=>l.accessToken()},fetch:s}),l),a),q.set(f,p)),p},D=B(d),K=Object.assign(Object.create(G),{auth:new A(d,o,l,n.webauthn??globalThis.navigator?.credentials),socket:m,transport:d,analytics:j,purchases:new C(d,l,m,e,s,n.appVersion,n.appId),setLanguage(u){t=ne(u??void 0)},chatToolCall:(u,f,p={})=>D.toolCall(u,f,p.signal),chatWorkspaceFile:(u,f,p,v={})=>D.workspaceFile(u,f,p,v.signal)});return H(K,i,ie,d,m,()=>l.snapshot()?.userId),K}var Re=/^[A-Za-z]{1,8}(-[A-Za-z0-9]{1,8})*$/;function ne(n){if(n===void 0)return;let e=typeof n=="string"?[n]:[...n];if(e.length!==0){for(let t of e)if(!Re.test(t))throw new TypeError(`language ${JSON.stringify(t)} is a BCP 47 tag ("tr", "pt-BR")`);return e.map((t,s)=>s===0?t:`${t};q=${Math.max(.1,1-s/10).toFixed(1)}`).join(", ")}}function Pe(){try{return typeof globalThis.localStorage<"u"}catch{return!1}}function U(n,e){return{async send(t){let s=await e.session();try{return await n.send(t)}catch(i){let r=t.auth.some(a=>a.includes("userJWT"));if(!(i instanceof O)||i.status!==401||!Se.has(i.code)||!r||!s)throw i;try{e.snapshot()?.refreshToken===s.refreshToken&&await e.refresh()}catch{throw i}if(e.snapshot()?.userId!==s.userId)throw i;return n.send(t)}}}}export{y as a,V as b,W as c,N as d,R as e,_ as f,C as g,Be as h};
|