@palbase/web 1.7.0 → 1.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/{analytics-facade-9GPSKnVG.d.cts → analytics-facade-DFd5LB3_.d.cts} +190 -5
- package/dist/{analytics-facade-CQJ3b-zB.d.ts → analytics-facade-DsvKx5A5.d.ts} +190 -5
- package/dist/{chunk-QRO632M7.js → chunk-I3ZMB7XM.js} +632 -21
- package/dist/chunk-I3ZMB7XM.js.map +1 -0
- package/dist/index.cjs +99 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/internal.cjs +631 -20
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +3 -3
- package/dist/internal.d.ts +3 -3
- package/dist/internal.js +1 -1
- package/dist/next/client.cjs +621 -17
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.js +1 -1
- package/dist/next/index.cjs +627 -17
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.cts +2 -2
- package/dist/next/index.d.ts +2 -2
- package/dist/next/index.js +1 -1
- package/dist/{pb-BvfCJZux.d.ts → pb-CDVMy1l1.d.ts} +9 -1
- package/dist/{pb-D4HyUbpb.d.cts → pb-D_fuhafL.d.cts} +9 -1
- package/dist/react/index.cjs +69 -13
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-QRO632M7.js.map +0 -1
|
@@ -622,6 +622,16 @@ interface PalbeConfig {
|
|
|
622
622
|
apiKey: string;
|
|
623
623
|
/** Informational — url+apiKey are already branch-specific (endpointRef embeds the branch slug); gen bakes all three consistently. */
|
|
624
624
|
branch?: string;
|
|
625
|
+
/**
|
|
626
|
+
* F2 app-registration: the registered app `identifier` from
|
|
627
|
+
* `palbase-config.json` — for web this is the declared ORIGIN (e.g.
|
|
628
|
+
* `https://app.example.com`). When non-empty, `configure` REFUSES to build the
|
|
629
|
+
* runtime if `window.location.origin` does not match (SDK-REFUSES), and the
|
|
630
|
+
* value rides on `X-Palbase-Bundle` on EVERY request so the Kong gate can match
|
|
631
|
+
* it (the IDENTICAL header + value the iOS SDK sends). Empty/absent → legacy /
|
|
632
|
+
* tooling: no guard, no header.
|
|
633
|
+
*/
|
|
634
|
+
identifier?: string;
|
|
625
635
|
oauth?: PalbeOAuthConfig;
|
|
626
636
|
/** Refresh-token persistence. Default: endpoint-scoped localStorage in browsers, memory elsewhere. */
|
|
627
637
|
storage?: SessionStorageAdapter;
|
|
@@ -1436,6 +1446,153 @@ declare class PalbeMessaging {
|
|
|
1436
1446
|
onChatsChange(cb: () => void): Unsubscribe$1;
|
|
1437
1447
|
}
|
|
1438
1448
|
|
|
1449
|
+
/** The Faz-1 trace kinds plus the Faz-1.5 web-vital family. */
|
|
1450
|
+
type PerfTraceType = 'network' | 'app_start' | 'custom' | 'web_vital';
|
|
1451
|
+
/**
|
|
1452
|
+
* One perf measurement, shaped EXACTLY as the ingest wire expects. Keys are
|
|
1453
|
+
* snake_case to match the Go decode tags — do not rename to camelCase.
|
|
1454
|
+
*/
|
|
1455
|
+
interface PerfItem {
|
|
1456
|
+
/** Client-generated UUIDv7 — server dedup key. */
|
|
1457
|
+
row_id: string;
|
|
1458
|
+
trace_type: PerfTraceType;
|
|
1459
|
+
name: string;
|
|
1460
|
+
/** Duration in milliseconds. */
|
|
1461
|
+
value: number;
|
|
1462
|
+
counters?: Record<string, number>;
|
|
1463
|
+
attrs?: Record<string, string>;
|
|
1464
|
+
request_id?: string;
|
|
1465
|
+
/** Unix milliseconds. */
|
|
1466
|
+
timestamp: number;
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
/**
|
|
1470
|
+
* Bounded FIFO perf-item queue. `enqueue` appends and evicts the oldest on
|
|
1471
|
+
* overflow; `drainAll` returns everything (oldest-first) and clears the store;
|
|
1472
|
+
* `count` is the current depth; `dropped` is the cumulative eviction counter.
|
|
1473
|
+
*
|
|
1474
|
+
* When `localStorage` is present the queue is read-through / write-through to a
|
|
1475
|
+
* fixed key, so a fresh instance after a reload sees the persisted items. With
|
|
1476
|
+
* no `localStorage` it is purely in-memory.
|
|
1477
|
+
*/
|
|
1478
|
+
declare class PerfOfflineQueue {
|
|
1479
|
+
private items;
|
|
1480
|
+
private _dropped;
|
|
1481
|
+
private readonly maxItems;
|
|
1482
|
+
constructor(maxItems?: number);
|
|
1483
|
+
/** Append items; FIFO-evict the oldest when over `maxItems`. */
|
|
1484
|
+
enqueue(items: PerfItem[]): void;
|
|
1485
|
+
/** Return all queued items (oldest-first) and clear the queue + store. */
|
|
1486
|
+
drainAll(): PerfItem[];
|
|
1487
|
+
/** Current queue depth. */
|
|
1488
|
+
get count(): number;
|
|
1489
|
+
/** Cumulative count of FIFO-evicted items (a `dropped` metric, not silent). */
|
|
1490
|
+
get dropped(): number;
|
|
1491
|
+
/** Drop the oldest items until at most `maxItems` remain, counting each. */
|
|
1492
|
+
private trim;
|
|
1493
|
+
private persist;
|
|
1494
|
+
private clearStore;
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
/**
|
|
1498
|
+
* The mutable PalPerf state shared between the facade and the network hook.
|
|
1499
|
+
* `testDevice` is signalled to the server via the `X-Palbase-Test-Device: 1`
|
|
1500
|
+
* request header (server-authoritative tagging — the SDK only flips the bit).
|
|
1501
|
+
*/
|
|
1502
|
+
declare class PerfState {
|
|
1503
|
+
/** Pending, un-flushed perf items (FIFO). */
|
|
1504
|
+
readonly buffer: PerfItem[];
|
|
1505
|
+
/** When true, every flush carries `X-Palbase-Test-Device: 1`. */
|
|
1506
|
+
testDevice: boolean;
|
|
1507
|
+
enqueue(item: PerfItem): void;
|
|
1508
|
+
/** Detach up to `MAX_PERF_BATCH` items for one POST (FIFO order preserved). */
|
|
1509
|
+
take(limit?: number): PerfItem[];
|
|
1510
|
+
get size(): number;
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
/**
|
|
1514
|
+
* A running custom trace. `putAttribute`/`incrementMetric` accumulate metadata;
|
|
1515
|
+
* `stop()` records ONE `custom` PerfItem whose `value` is the elapsed
|
|
1516
|
+
* milliseconds since `startTrace`. Idempotent: a second `stop()` is a no-op.
|
|
1517
|
+
*/
|
|
1518
|
+
declare class PerfTrace {
|
|
1519
|
+
private readonly name;
|
|
1520
|
+
private readonly onStop;
|
|
1521
|
+
private readonly attrs;
|
|
1522
|
+
private readonly counters;
|
|
1523
|
+
private readonly startedAt;
|
|
1524
|
+
private stopped;
|
|
1525
|
+
constructor(name: string, onStop: (item: PerfItem) => void);
|
|
1526
|
+
putAttribute(key: string, value: string): void;
|
|
1527
|
+
incrementMetric(name: string, by?: number): void;
|
|
1528
|
+
stop(): void;
|
|
1529
|
+
}
|
|
1530
|
+
declare class PalbePerf {
|
|
1531
|
+
private readonly rt;
|
|
1532
|
+
private readonly state;
|
|
1533
|
+
/** Durable offline buffer for failed flushes (persist-on-fail). Browser →
|
|
1534
|
+
* localStorage-backed; server → in-memory. */
|
|
1535
|
+
private readonly queue;
|
|
1536
|
+
private flushTimer;
|
|
1537
|
+
/** Browser → buffer + size/timer flush. Server (no document) → immediate
|
|
1538
|
+
* per-item flush, zero timers (nothing leaks into RSC/route handlers). */
|
|
1539
|
+
private readonly browser;
|
|
1540
|
+
/** Bound `online` handler so it can be removed on `dispose()` (no leak). */
|
|
1541
|
+
private readonly onOnline;
|
|
1542
|
+
/** Server-controlled client-side sample rate (0..100). 100 until the config
|
|
1543
|
+
* client fetches `/v1/analytics/perf/config` — the SDK obeys this ceiling and
|
|
1544
|
+
* never raises its own rate (invariant 3). `record` drops an item whose
|
|
1545
|
+
* deterministic `row_id` bucket is >= this pct, mirroring the server's
|
|
1546
|
+
* `SampleDecision` so client + server keep the SAME rows. */
|
|
1547
|
+
private samplePct;
|
|
1548
|
+
constructor(rt: PalbeRuntime, state?: PerfState,
|
|
1549
|
+
/** Durable offline buffer for failed flushes (persist-on-fail). Browser →
|
|
1550
|
+
* localStorage-backed; server → in-memory. */
|
|
1551
|
+
queue?: PerfOfflineQueue);
|
|
1552
|
+
/** Remove the `online` listener. Called when the runtime is replaced so the
|
|
1553
|
+
* handler does not outlive this facade. No-op outside the browser. */
|
|
1554
|
+
dispose(): void;
|
|
1555
|
+
/** Mark (or unmark) this client's traffic as test — the server tags the rows
|
|
1556
|
+
* when the `X-Palbase-Test-Device: 1` header rides along on flush. */
|
|
1557
|
+
setTestDevice(on: boolean): void;
|
|
1558
|
+
/** Apply the server-resolved client-side sample rate (0..100), clamped. Called
|
|
1559
|
+
* by `PerfConfigClient` after fetching `/v1/analytics/perf/config`. The SDK
|
|
1560
|
+
* OBEYS this value — it is a ceiling, never raised locally. */
|
|
1561
|
+
setSamplePct(pct: number): void;
|
|
1562
|
+
/** Pending (un-flushed) buffer depth. Test-only visibility into the buffer so
|
|
1563
|
+
* the remote-sampling tests can assert how many items were sampled in. */
|
|
1564
|
+
get bufferSizeForTest(): number;
|
|
1565
|
+
/** Opt-in: wrap the global `fetch` so every app-level request is recorded as a
|
|
1566
|
+
* redacted `network` perf item (the `/v1/analytics/*` ingest paths are
|
|
1567
|
+
* self-excluded). OFF by default — swizzling a global is a page-wide side
|
|
1568
|
+
* effect. Returns an `uninstall` that restores the original `fetch`. */
|
|
1569
|
+
enableFetchCapture(): () => void;
|
|
1570
|
+
/** Start a custom trace; the returned handle records a `custom` item on
|
|
1571
|
+
* `.stop()`. */
|
|
1572
|
+
startTrace(name: string): PerfTrace;
|
|
1573
|
+
/** Buffer one perf item. In the browser, flush on size/timer; on the server
|
|
1574
|
+
* flush immediately (no timers). Never throws.
|
|
1575
|
+
*
|
|
1576
|
+
* Client-side remote sampling: an item whose deterministic `row_id` bucket is
|
|
1577
|
+
* NOT below the server-controlled `samplePct` is dropped before buffering —
|
|
1578
|
+
* the SAME FNV-1a-mod-100 decision the server applies at ingest, so the two
|
|
1579
|
+
* keep identical rows and the SDK saves the upload (defense-in-depth: the
|
|
1580
|
+
* server re-samples authoritatively). */
|
|
1581
|
+
record(item: PerfItem): void;
|
|
1582
|
+
/** Buffer a network trace — called by `request.ts` around `rt.http.request`
|
|
1583
|
+
* (the analytics ingest path is excluded by the caller to avoid recursion). */
|
|
1584
|
+
recordNetwork(method: string, url: string, status: number, durationMs: number, requestId?: string): void;
|
|
1585
|
+
/** Drain the offline queue (oldest-first) and the live buffer to
|
|
1586
|
+
* `/v1/analytics/perf` (≤100 items per request, sequential). Resolves when
|
|
1587
|
+
* delivery finished; NEVER rejects. A failed slice is NOT dropped — it goes
|
|
1588
|
+
* to the offline queue (persist-on-fail) so the next flush (size/timer or the
|
|
1589
|
+
* `online` reconnect event) retries it. Items keep their original `row_id`,
|
|
1590
|
+
* so a redelivery dedups server-side (ReplacingMergeTree). */
|
|
1591
|
+
flush(): Promise<void>;
|
|
1592
|
+
private startTimer;
|
|
1593
|
+
private cancelTimer;
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1439
1596
|
/**
|
|
1440
1597
|
* The connection state of the shared realtime WebSocket (iOS enum parity), plus
|
|
1441
1598
|
* `'error'` — surfaced when a channel could not be recovered after a
|
|
@@ -1533,6 +1690,14 @@ declare class PalbeRealtime {
|
|
|
1533
1690
|
|
|
1534
1691
|
interface PalbeRuntime {
|
|
1535
1692
|
config: PalbeConfig;
|
|
1693
|
+
/**
|
|
1694
|
+
* F2 app-registration: the registered app `identifier` (web ORIGIN) stashed at
|
|
1695
|
+
* configure. Rides on `X-Palbase-Bundle` on EVERY request (request.ts) so the
|
|
1696
|
+
* Kong gate can match it. Empty string when the binding is unconfigured/tooling
|
|
1697
|
+
* (no header is sent). Origin-match is enforced in `buildRuntime` BEFORE this
|
|
1698
|
+
* runtime is returned — a mismatch throws there and no runtime is built.
|
|
1699
|
+
*/
|
|
1700
|
+
appIdentifier: string;
|
|
1536
1701
|
http: HttpClient$1;
|
|
1537
1702
|
tokenManager: TokenManager$1;
|
|
1538
1703
|
authClient: AuthClient;
|
|
@@ -1542,6 +1707,13 @@ interface PalbeRuntime {
|
|
|
1542
1707
|
analytics: PalbeAnalytics;
|
|
1543
1708
|
calls: PalbeCalls;
|
|
1544
1709
|
messaging: PalbeMessaging;
|
|
1710
|
+
/**
|
|
1711
|
+
* PalPerf surface. EAGER (like analytics identity): `request.ts` records a
|
|
1712
|
+
* `network` trace around EVERY SDK fetch, so the facade must exist from the
|
|
1713
|
+
* first request — never lazy. The buffer/timer it owns is inert until the
|
|
1714
|
+
* first item is recorded.
|
|
1715
|
+
*/
|
|
1716
|
+
perf: PalbePerf;
|
|
1545
1717
|
storage: SessionStorageAdapter;
|
|
1546
1718
|
/**
|
|
1547
1719
|
* Destroy the realtime facade if it was already constructed (no-op otherwise).
|
|
@@ -1599,6 +1771,7 @@ declare class PalbeAuth {
|
|
|
1599
1771
|
private signingOut;
|
|
1600
1772
|
private signingIn;
|
|
1601
1773
|
private signedInState;
|
|
1774
|
+
private hydratingUser;
|
|
1602
1775
|
private readonly stateListeners;
|
|
1603
1776
|
private readonly eventListeners;
|
|
1604
1777
|
private readonly userListeners;
|
|
@@ -1616,12 +1789,24 @@ declare class PalbeAuth {
|
|
|
1616
1789
|
signOut(): Promise<void>;
|
|
1617
1790
|
getUser(): Promise<AuthUser>;
|
|
1618
1791
|
refreshUser(): Promise<AuthUser>;
|
|
1792
|
+
/**
|
|
1793
|
+
* Restore the user after a session was rehydrated from storage (page reload).
|
|
1794
|
+
* Hydration in buildRuntime restores the TOKENS synchronously, but the access
|
|
1795
|
+
* token JWT does not carry emailVerified/createdAt, so the full AuthUser can't
|
|
1796
|
+
* be reconstructed offline — this fetches GET /auth/user once and announces
|
|
1797
|
+
* `signedIn`, so the app no longer has to `await pb.auth.refreshUser()` itself
|
|
1798
|
+
* on boot. Idempotent (runs once), browser-safe (no-op when not signed in or
|
|
1799
|
+
* a user is already cached), and never throws (a boot-time network failure
|
|
1800
|
+
* must not break app startup — isSignedIn stays true, the app can retry).
|
|
1801
|
+
*/
|
|
1802
|
+
hydrateUser(): void;
|
|
1619
1803
|
/**
|
|
1620
1804
|
* Subscribe to signed-in/signed-out state. Fires immediately with the
|
|
1621
|
-
* current snapshot (iOS parity).
|
|
1622
|
-
*
|
|
1623
|
-
*
|
|
1624
|
-
*
|
|
1805
|
+
* current snapshot (iOS parity). A restored session (page reload) hydrates
|
|
1806
|
+
* the user asynchronously via `hydrateUser()` (fired once at boot), so the
|
|
1807
|
+
* FIRST snapshot may report signedOut for a tick even when `isSignedIn` is
|
|
1808
|
+
* true; the listener then fires again with `signedIn` once the user lands.
|
|
1809
|
+
* Rely on `isSignedIn` for the session truth if you need it synchronously.
|
|
1625
1810
|
*/
|
|
1626
1811
|
onAuthStateChange(callback: (state: AuthState) => void): Unsubscribe;
|
|
1627
1812
|
onAuthEvent(callback: (event: AuthChangeEvent) => void): Unsubscribe;
|
|
@@ -1793,4 +1978,4 @@ declare class PalbeAnalytics {
|
|
|
1793
1978
|
private post;
|
|
1794
1979
|
}
|
|
1795
1980
|
|
|
1796
|
-
export { type AnalyticsProperties as A, type PresenceState as B, Call as C, type RealtimeConnectionState as D, type RealtimeHandler as E, type FlagsView as F, type RealtimePayload as G, type RealtimeStatus as H, type RealtimeStatusSnapshot as I, type RealtimeSubscription as J, type ResolvedMention as K, type ResolvedReply as L, type MagicLinkResult as M, type NotifyScope as N, type OAuthExchangeResult as O, PalbeAnalytics as P, type Unsubscribe as Q, RealtimeChannel as R, type SentReceipt as S, type PalbeRuntime as T, type UnreadView as U, buildRuntime as V, type AuthChangeEvent as a, type AuthState as b, type AuthSuccess as c, type AuthUser as d, type CallChangeCallback as e, type CallParticipant as f, type CallState as g, Chat as h, type ChatBackend as i, type ChatDraft as j, type ChatKind as k, type ChatMember as l, type ChatMessage as m, type ChatMessageKind as n, type ChatRole as o, type ChatState as p, type CommsPrefs as q, type MentionRange as r, type MessageDirection as s, PalbeAuth as t, PalbeCalls as u, type PalbeConfig as v, PalbeFlags as w, PalbeMessaging as x, type PalbeOAuthConfig as y, PalbeRealtime as z };
|
|
1981
|
+
export { type AnalyticsProperties as A, type PresenceState as B, Call as C, type RealtimeConnectionState as D, type RealtimeHandler as E, type FlagsView as F, type RealtimePayload as G, type RealtimeStatus as H, type RealtimeStatusSnapshot as I, type RealtimeSubscription as J, type ResolvedMention as K, type ResolvedReply as L, type MagicLinkResult as M, type NotifyScope as N, type OAuthExchangeResult as O, PalbeAnalytics as P, type Unsubscribe as Q, RealtimeChannel as R, type SentReceipt as S, type PalbeRuntime as T, type UnreadView as U, buildRuntime as V, PalbePerf as W, type AuthChangeEvent as a, type AuthState as b, type AuthSuccess as c, type AuthUser as d, type CallChangeCallback as e, type CallParticipant as f, type CallState as g, Chat as h, type ChatBackend as i, type ChatDraft as j, type ChatKind as k, type ChatMember as l, type ChatMessage as m, type ChatMessageKind as n, type ChatRole as o, type ChatState as p, type CommsPrefs as q, type MentionRange as r, type MessageDirection as s, PalbeAuth as t, PalbeCalls as u, type PalbeConfig as v, PalbeFlags as w, PalbeMessaging as x, type PalbeOAuthConfig as y, PalbeRealtime as z };
|
|
@@ -622,6 +622,16 @@ interface PalbeConfig {
|
|
|
622
622
|
apiKey: string;
|
|
623
623
|
/** Informational — url+apiKey are already branch-specific (endpointRef embeds the branch slug); gen bakes all three consistently. */
|
|
624
624
|
branch?: string;
|
|
625
|
+
/**
|
|
626
|
+
* F2 app-registration: the registered app `identifier` from
|
|
627
|
+
* `palbase-config.json` — for web this is the declared ORIGIN (e.g.
|
|
628
|
+
* `https://app.example.com`). When non-empty, `configure` REFUSES to build the
|
|
629
|
+
* runtime if `window.location.origin` does not match (SDK-REFUSES), and the
|
|
630
|
+
* value rides on `X-Palbase-Bundle` on EVERY request so the Kong gate can match
|
|
631
|
+
* it (the IDENTICAL header + value the iOS SDK sends). Empty/absent → legacy /
|
|
632
|
+
* tooling: no guard, no header.
|
|
633
|
+
*/
|
|
634
|
+
identifier?: string;
|
|
625
635
|
oauth?: PalbeOAuthConfig;
|
|
626
636
|
/** Refresh-token persistence. Default: endpoint-scoped localStorage in browsers, memory elsewhere. */
|
|
627
637
|
storage?: SessionStorageAdapter;
|
|
@@ -1436,6 +1446,153 @@ declare class PalbeMessaging {
|
|
|
1436
1446
|
onChatsChange(cb: () => void): Unsubscribe$1;
|
|
1437
1447
|
}
|
|
1438
1448
|
|
|
1449
|
+
/** The Faz-1 trace kinds plus the Faz-1.5 web-vital family. */
|
|
1450
|
+
type PerfTraceType = 'network' | 'app_start' | 'custom' | 'web_vital';
|
|
1451
|
+
/**
|
|
1452
|
+
* One perf measurement, shaped EXACTLY as the ingest wire expects. Keys are
|
|
1453
|
+
* snake_case to match the Go decode tags — do not rename to camelCase.
|
|
1454
|
+
*/
|
|
1455
|
+
interface PerfItem {
|
|
1456
|
+
/** Client-generated UUIDv7 — server dedup key. */
|
|
1457
|
+
row_id: string;
|
|
1458
|
+
trace_type: PerfTraceType;
|
|
1459
|
+
name: string;
|
|
1460
|
+
/** Duration in milliseconds. */
|
|
1461
|
+
value: number;
|
|
1462
|
+
counters?: Record<string, number>;
|
|
1463
|
+
attrs?: Record<string, string>;
|
|
1464
|
+
request_id?: string;
|
|
1465
|
+
/** Unix milliseconds. */
|
|
1466
|
+
timestamp: number;
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
/**
|
|
1470
|
+
* Bounded FIFO perf-item queue. `enqueue` appends and evicts the oldest on
|
|
1471
|
+
* overflow; `drainAll` returns everything (oldest-first) and clears the store;
|
|
1472
|
+
* `count` is the current depth; `dropped` is the cumulative eviction counter.
|
|
1473
|
+
*
|
|
1474
|
+
* When `localStorage` is present the queue is read-through / write-through to a
|
|
1475
|
+
* fixed key, so a fresh instance after a reload sees the persisted items. With
|
|
1476
|
+
* no `localStorage` it is purely in-memory.
|
|
1477
|
+
*/
|
|
1478
|
+
declare class PerfOfflineQueue {
|
|
1479
|
+
private items;
|
|
1480
|
+
private _dropped;
|
|
1481
|
+
private readonly maxItems;
|
|
1482
|
+
constructor(maxItems?: number);
|
|
1483
|
+
/** Append items; FIFO-evict the oldest when over `maxItems`. */
|
|
1484
|
+
enqueue(items: PerfItem[]): void;
|
|
1485
|
+
/** Return all queued items (oldest-first) and clear the queue + store. */
|
|
1486
|
+
drainAll(): PerfItem[];
|
|
1487
|
+
/** Current queue depth. */
|
|
1488
|
+
get count(): number;
|
|
1489
|
+
/** Cumulative count of FIFO-evicted items (a `dropped` metric, not silent). */
|
|
1490
|
+
get dropped(): number;
|
|
1491
|
+
/** Drop the oldest items until at most `maxItems` remain, counting each. */
|
|
1492
|
+
private trim;
|
|
1493
|
+
private persist;
|
|
1494
|
+
private clearStore;
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
/**
|
|
1498
|
+
* The mutable PalPerf state shared between the facade and the network hook.
|
|
1499
|
+
* `testDevice` is signalled to the server via the `X-Palbase-Test-Device: 1`
|
|
1500
|
+
* request header (server-authoritative tagging — the SDK only flips the bit).
|
|
1501
|
+
*/
|
|
1502
|
+
declare class PerfState {
|
|
1503
|
+
/** Pending, un-flushed perf items (FIFO). */
|
|
1504
|
+
readonly buffer: PerfItem[];
|
|
1505
|
+
/** When true, every flush carries `X-Palbase-Test-Device: 1`. */
|
|
1506
|
+
testDevice: boolean;
|
|
1507
|
+
enqueue(item: PerfItem): void;
|
|
1508
|
+
/** Detach up to `MAX_PERF_BATCH` items for one POST (FIFO order preserved). */
|
|
1509
|
+
take(limit?: number): PerfItem[];
|
|
1510
|
+
get size(): number;
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
/**
|
|
1514
|
+
* A running custom trace. `putAttribute`/`incrementMetric` accumulate metadata;
|
|
1515
|
+
* `stop()` records ONE `custom` PerfItem whose `value` is the elapsed
|
|
1516
|
+
* milliseconds since `startTrace`. Idempotent: a second `stop()` is a no-op.
|
|
1517
|
+
*/
|
|
1518
|
+
declare class PerfTrace {
|
|
1519
|
+
private readonly name;
|
|
1520
|
+
private readonly onStop;
|
|
1521
|
+
private readonly attrs;
|
|
1522
|
+
private readonly counters;
|
|
1523
|
+
private readonly startedAt;
|
|
1524
|
+
private stopped;
|
|
1525
|
+
constructor(name: string, onStop: (item: PerfItem) => void);
|
|
1526
|
+
putAttribute(key: string, value: string): void;
|
|
1527
|
+
incrementMetric(name: string, by?: number): void;
|
|
1528
|
+
stop(): void;
|
|
1529
|
+
}
|
|
1530
|
+
declare class PalbePerf {
|
|
1531
|
+
private readonly rt;
|
|
1532
|
+
private readonly state;
|
|
1533
|
+
/** Durable offline buffer for failed flushes (persist-on-fail). Browser →
|
|
1534
|
+
* localStorage-backed; server → in-memory. */
|
|
1535
|
+
private readonly queue;
|
|
1536
|
+
private flushTimer;
|
|
1537
|
+
/** Browser → buffer + size/timer flush. Server (no document) → immediate
|
|
1538
|
+
* per-item flush, zero timers (nothing leaks into RSC/route handlers). */
|
|
1539
|
+
private readonly browser;
|
|
1540
|
+
/** Bound `online` handler so it can be removed on `dispose()` (no leak). */
|
|
1541
|
+
private readonly onOnline;
|
|
1542
|
+
/** Server-controlled client-side sample rate (0..100). 100 until the config
|
|
1543
|
+
* client fetches `/v1/analytics/perf/config` — the SDK obeys this ceiling and
|
|
1544
|
+
* never raises its own rate (invariant 3). `record` drops an item whose
|
|
1545
|
+
* deterministic `row_id` bucket is >= this pct, mirroring the server's
|
|
1546
|
+
* `SampleDecision` so client + server keep the SAME rows. */
|
|
1547
|
+
private samplePct;
|
|
1548
|
+
constructor(rt: PalbeRuntime, state?: PerfState,
|
|
1549
|
+
/** Durable offline buffer for failed flushes (persist-on-fail). Browser →
|
|
1550
|
+
* localStorage-backed; server → in-memory. */
|
|
1551
|
+
queue?: PerfOfflineQueue);
|
|
1552
|
+
/** Remove the `online` listener. Called when the runtime is replaced so the
|
|
1553
|
+
* handler does not outlive this facade. No-op outside the browser. */
|
|
1554
|
+
dispose(): void;
|
|
1555
|
+
/** Mark (or unmark) this client's traffic as test — the server tags the rows
|
|
1556
|
+
* when the `X-Palbase-Test-Device: 1` header rides along on flush. */
|
|
1557
|
+
setTestDevice(on: boolean): void;
|
|
1558
|
+
/** Apply the server-resolved client-side sample rate (0..100), clamped. Called
|
|
1559
|
+
* by `PerfConfigClient` after fetching `/v1/analytics/perf/config`. The SDK
|
|
1560
|
+
* OBEYS this value — it is a ceiling, never raised locally. */
|
|
1561
|
+
setSamplePct(pct: number): void;
|
|
1562
|
+
/** Pending (un-flushed) buffer depth. Test-only visibility into the buffer so
|
|
1563
|
+
* the remote-sampling tests can assert how many items were sampled in. */
|
|
1564
|
+
get bufferSizeForTest(): number;
|
|
1565
|
+
/** Opt-in: wrap the global `fetch` so every app-level request is recorded as a
|
|
1566
|
+
* redacted `network` perf item (the `/v1/analytics/*` ingest paths are
|
|
1567
|
+
* self-excluded). OFF by default — swizzling a global is a page-wide side
|
|
1568
|
+
* effect. Returns an `uninstall` that restores the original `fetch`. */
|
|
1569
|
+
enableFetchCapture(): () => void;
|
|
1570
|
+
/** Start a custom trace; the returned handle records a `custom` item on
|
|
1571
|
+
* `.stop()`. */
|
|
1572
|
+
startTrace(name: string): PerfTrace;
|
|
1573
|
+
/** Buffer one perf item. In the browser, flush on size/timer; on the server
|
|
1574
|
+
* flush immediately (no timers). Never throws.
|
|
1575
|
+
*
|
|
1576
|
+
* Client-side remote sampling: an item whose deterministic `row_id` bucket is
|
|
1577
|
+
* NOT below the server-controlled `samplePct` is dropped before buffering —
|
|
1578
|
+
* the SAME FNV-1a-mod-100 decision the server applies at ingest, so the two
|
|
1579
|
+
* keep identical rows and the SDK saves the upload (defense-in-depth: the
|
|
1580
|
+
* server re-samples authoritatively). */
|
|
1581
|
+
record(item: PerfItem): void;
|
|
1582
|
+
/** Buffer a network trace — called by `request.ts` around `rt.http.request`
|
|
1583
|
+
* (the analytics ingest path is excluded by the caller to avoid recursion). */
|
|
1584
|
+
recordNetwork(method: string, url: string, status: number, durationMs: number, requestId?: string): void;
|
|
1585
|
+
/** Drain the offline queue (oldest-first) and the live buffer to
|
|
1586
|
+
* `/v1/analytics/perf` (≤100 items per request, sequential). Resolves when
|
|
1587
|
+
* delivery finished; NEVER rejects. A failed slice is NOT dropped — it goes
|
|
1588
|
+
* to the offline queue (persist-on-fail) so the next flush (size/timer or the
|
|
1589
|
+
* `online` reconnect event) retries it. Items keep their original `row_id`,
|
|
1590
|
+
* so a redelivery dedups server-side (ReplacingMergeTree). */
|
|
1591
|
+
flush(): Promise<void>;
|
|
1592
|
+
private startTimer;
|
|
1593
|
+
private cancelTimer;
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1439
1596
|
/**
|
|
1440
1597
|
* The connection state of the shared realtime WebSocket (iOS enum parity), plus
|
|
1441
1598
|
* `'error'` — surfaced when a channel could not be recovered after a
|
|
@@ -1533,6 +1690,14 @@ declare class PalbeRealtime {
|
|
|
1533
1690
|
|
|
1534
1691
|
interface PalbeRuntime {
|
|
1535
1692
|
config: PalbeConfig;
|
|
1693
|
+
/**
|
|
1694
|
+
* F2 app-registration: the registered app `identifier` (web ORIGIN) stashed at
|
|
1695
|
+
* configure. Rides on `X-Palbase-Bundle` on EVERY request (request.ts) so the
|
|
1696
|
+
* Kong gate can match it. Empty string when the binding is unconfigured/tooling
|
|
1697
|
+
* (no header is sent). Origin-match is enforced in `buildRuntime` BEFORE this
|
|
1698
|
+
* runtime is returned — a mismatch throws there and no runtime is built.
|
|
1699
|
+
*/
|
|
1700
|
+
appIdentifier: string;
|
|
1536
1701
|
http: HttpClient$1;
|
|
1537
1702
|
tokenManager: TokenManager$1;
|
|
1538
1703
|
authClient: AuthClient;
|
|
@@ -1542,6 +1707,13 @@ interface PalbeRuntime {
|
|
|
1542
1707
|
analytics: PalbeAnalytics;
|
|
1543
1708
|
calls: PalbeCalls;
|
|
1544
1709
|
messaging: PalbeMessaging;
|
|
1710
|
+
/**
|
|
1711
|
+
* PalPerf surface. EAGER (like analytics identity): `request.ts` records a
|
|
1712
|
+
* `network` trace around EVERY SDK fetch, so the facade must exist from the
|
|
1713
|
+
* first request — never lazy. The buffer/timer it owns is inert until the
|
|
1714
|
+
* first item is recorded.
|
|
1715
|
+
*/
|
|
1716
|
+
perf: PalbePerf;
|
|
1545
1717
|
storage: SessionStorageAdapter;
|
|
1546
1718
|
/**
|
|
1547
1719
|
* Destroy the realtime facade if it was already constructed (no-op otherwise).
|
|
@@ -1599,6 +1771,7 @@ declare class PalbeAuth {
|
|
|
1599
1771
|
private signingOut;
|
|
1600
1772
|
private signingIn;
|
|
1601
1773
|
private signedInState;
|
|
1774
|
+
private hydratingUser;
|
|
1602
1775
|
private readonly stateListeners;
|
|
1603
1776
|
private readonly eventListeners;
|
|
1604
1777
|
private readonly userListeners;
|
|
@@ -1616,12 +1789,24 @@ declare class PalbeAuth {
|
|
|
1616
1789
|
signOut(): Promise<void>;
|
|
1617
1790
|
getUser(): Promise<AuthUser>;
|
|
1618
1791
|
refreshUser(): Promise<AuthUser>;
|
|
1792
|
+
/**
|
|
1793
|
+
* Restore the user after a session was rehydrated from storage (page reload).
|
|
1794
|
+
* Hydration in buildRuntime restores the TOKENS synchronously, but the access
|
|
1795
|
+
* token JWT does not carry emailVerified/createdAt, so the full AuthUser can't
|
|
1796
|
+
* be reconstructed offline — this fetches GET /auth/user once and announces
|
|
1797
|
+
* `signedIn`, so the app no longer has to `await pb.auth.refreshUser()` itself
|
|
1798
|
+
* on boot. Idempotent (runs once), browser-safe (no-op when not signed in or
|
|
1799
|
+
* a user is already cached), and never throws (a boot-time network failure
|
|
1800
|
+
* must not break app startup — isSignedIn stays true, the app can retry).
|
|
1801
|
+
*/
|
|
1802
|
+
hydrateUser(): void;
|
|
1619
1803
|
/**
|
|
1620
1804
|
* Subscribe to signed-in/signed-out state. Fires immediately with the
|
|
1621
|
-
* current snapshot (iOS parity).
|
|
1622
|
-
*
|
|
1623
|
-
*
|
|
1624
|
-
*
|
|
1805
|
+
* current snapshot (iOS parity). A restored session (page reload) hydrates
|
|
1806
|
+
* the user asynchronously via `hydrateUser()` (fired once at boot), so the
|
|
1807
|
+
* FIRST snapshot may report signedOut for a tick even when `isSignedIn` is
|
|
1808
|
+
* true; the listener then fires again with `signedIn` once the user lands.
|
|
1809
|
+
* Rely on `isSignedIn` for the session truth if you need it synchronously.
|
|
1625
1810
|
*/
|
|
1626
1811
|
onAuthStateChange(callback: (state: AuthState) => void): Unsubscribe;
|
|
1627
1812
|
onAuthEvent(callback: (event: AuthChangeEvent) => void): Unsubscribe;
|
|
@@ -1793,4 +1978,4 @@ declare class PalbeAnalytics {
|
|
|
1793
1978
|
private post;
|
|
1794
1979
|
}
|
|
1795
1980
|
|
|
1796
|
-
export { type AnalyticsProperties as A, type PresenceState as B, Call as C, type RealtimeConnectionState as D, type RealtimeHandler as E, type FlagsView as F, type RealtimePayload as G, type RealtimeStatus as H, type RealtimeStatusSnapshot as I, type RealtimeSubscription as J, type ResolvedMention as K, type ResolvedReply as L, type MagicLinkResult as M, type NotifyScope as N, type OAuthExchangeResult as O, PalbeAnalytics as P, type Unsubscribe as Q, RealtimeChannel as R, type SentReceipt as S, type PalbeRuntime as T, type UnreadView as U, buildRuntime as V, type AuthChangeEvent as a, type AuthState as b, type AuthSuccess as c, type AuthUser as d, type CallChangeCallback as e, type CallParticipant as f, type CallState as g, Chat as h, type ChatBackend as i, type ChatDraft as j, type ChatKind as k, type ChatMember as l, type ChatMessage as m, type ChatMessageKind as n, type ChatRole as o, type ChatState as p, type CommsPrefs as q, type MentionRange as r, type MessageDirection as s, PalbeAuth as t, PalbeCalls as u, type PalbeConfig as v, PalbeFlags as w, PalbeMessaging as x, type PalbeOAuthConfig as y, PalbeRealtime as z };
|
|
1981
|
+
export { type AnalyticsProperties as A, type PresenceState as B, Call as C, type RealtimeConnectionState as D, type RealtimeHandler as E, type FlagsView as F, type RealtimePayload as G, type RealtimeStatus as H, type RealtimeStatusSnapshot as I, type RealtimeSubscription as J, type ResolvedMention as K, type ResolvedReply as L, type MagicLinkResult as M, type NotifyScope as N, type OAuthExchangeResult as O, PalbeAnalytics as P, type Unsubscribe as Q, RealtimeChannel as R, type SentReceipt as S, type PalbeRuntime as T, type UnreadView as U, buildRuntime as V, PalbePerf as W, type AuthChangeEvent as a, type AuthState as b, type AuthSuccess as c, type AuthUser as d, type CallChangeCallback as e, type CallParticipant as f, type CallState as g, Chat as h, type ChatBackend as i, type ChatDraft as j, type ChatKind as k, type ChatMember as l, type ChatMessage as m, type ChatMessageKind as n, type ChatRole as o, type ChatState as p, type CommsPrefs as q, type MentionRange as r, type MessageDirection as s, PalbeAuth as t, PalbeCalls as u, type PalbeConfig as v, PalbeFlags as w, PalbeMessaging as x, type PalbeOAuthConfig as y, PalbeRealtime as z };
|