@nebulr-group/bridge-auth-core 0.1.2 → 0.4.0-beta.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/billing/bridge-subscription.d.ts +71 -0
- package/dist/billing/bridge-subscription.d.ts.map +1 -0
- package/dist/billing/bridge-subscription.js +209 -0
- package/dist/billing/bridge-subscription.js.map +1 -0
- package/dist/billing/entitlements-store.d.ts +61 -0
- package/dist/billing/entitlements-store.d.ts.map +1 -0
- package/dist/billing/entitlements-store.js +127 -0
- package/dist/billing/entitlements-store.js.map +1 -0
- package/dist/billing/fetch-billing-state.d.ts +9 -0
- package/dist/billing/fetch-billing-state.d.ts.map +1 -0
- package/dist/billing/fetch-billing-state.js +22 -0
- package/dist/billing/fetch-billing-state.js.map +1 -0
- package/dist/billing/lock-signal.d.ts +6 -0
- package/dist/billing/lock-signal.d.ts.map +1 -0
- package/dist/billing/lock-signal.js +8 -0
- package/dist/billing/lock-signal.js.map +1 -0
- package/dist/billing/quota-store.d.ts +86 -0
- package/dist/billing/quota-store.d.ts.map +1 -0
- package/dist/billing/quota-store.js +180 -0
- package/dist/billing/quota-store.js.map +1 -0
- package/dist/billing/types.d.ts +64 -0
- package/dist/billing/types.d.ts.map +1 -0
- package/dist/billing/types.js +49 -0
- package/dist/billing/types.js.map +1 -0
- package/dist/billing/use-bridge.d.ts +131 -0
- package/dist/billing/use-bridge.d.ts.map +1 -0
- package/dist/billing/use-bridge.js +181 -0
- package/dist/billing/use-bridge.js.map +1 -0
- package/dist/bridge-auth.d.ts +36 -1
- package/dist/bridge-auth.d.ts.map +1 -1
- package/dist/bridge-auth.js +57 -3
- package/dist/bridge-auth.js.map +1 -1
- package/dist/direct-auth.d.ts +1 -0
- package/dist/direct-auth.d.ts.map +1 -1
- package/dist/direct-auth.js +7 -0
- package/dist/direct-auth.js.map +1 -1
- package/dist/errors.d.ts +11 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +14 -0
- package/dist/errors.js.map +1 -1
- package/dist/flags/attribute-providers.d.ts +229 -0
- package/dist/flags/attribute-providers.d.ts.map +1 -0
- package/dist/flags/attribute-providers.js +375 -0
- package/dist/flags/attribute-providers.js.map +1 -0
- package/dist/flags/dev-attribute-provider.d.ts +67 -0
- package/dist/flags/dev-attribute-provider.d.ts.map +1 -0
- package/dist/flags/dev-attribute-provider.js +200 -0
- package/dist/flags/dev-attribute-provider.js.map +1 -0
- package/dist/flags/evaluator.d.ts +58 -0
- package/dist/flags/evaluator.d.ts.map +1 -0
- package/dist/flags/evaluator.js +160 -0
- package/dist/flags/evaluator.js.map +1 -0
- package/dist/flags/flag.d.ts +199 -0
- package/dist/flags/flag.d.ts.map +1 -0
- package/dist/flags/flag.js +337 -0
- package/dist/flags/flag.js.map +1 -0
- package/dist/flags/identity.d.ts +77 -0
- package/dist/flags/identity.d.ts.map +1 -0
- package/dist/flags/identity.js +134 -0
- package/dist/flags/identity.js.map +1 -0
- package/dist/flags/index.d.ts +20 -0
- package/dist/flags/index.d.ts.map +1 -0
- package/dist/flags/index.js +21 -0
- package/dist/flags/index.js.map +1 -0
- package/dist/flags/operators.d.ts +63 -0
- package/dist/flags/operators.d.ts.map +1 -0
- package/dist/flags/operators.js +299 -0
- package/dist/flags/operators.js.map +1 -0
- package/dist/flags/propagation.d.ts +16 -0
- package/dist/flags/propagation.d.ts.map +1 -0
- package/dist/flags/propagation.js +107 -0
- package/dist/flags/propagation.js.map +1 -0
- package/dist/flags/realtime.d.ts +328 -0
- package/dist/flags/realtime.d.ts.map +1 -0
- package/dist/flags/realtime.js +504 -0
- package/dist/flags/realtime.js.map +1 -0
- package/dist/flags/runtime-mode.d.ts +32 -0
- package/dist/flags/runtime-mode.d.ts.map +1 -0
- package/dist/flags/runtime-mode.js +84 -0
- package/dist/flags/runtime-mode.js.map +1 -0
- package/dist/flags/telemetry.d.ts +79 -0
- package/dist/flags/telemetry.d.ts.map +1 -0
- package/dist/flags/telemetry.js +286 -0
- package/dist/flags/telemetry.js.map +1 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +11 -1
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/dist/management-types.d.ts +38 -0
- package/dist/management-types.d.ts.map +1 -1
- package/dist/route-guard.d.ts.map +1 -1
- package/dist/route-guard.js +15 -5
- package/dist/route-guard.js.map +1 -1
- package/dist/token-manager.d.ts +3 -1
- package/dist/token-manager.d.ts.map +1 -1
- package/dist/token-manager.js +10 -6
- package/dist/token-manager.js.map +1 -1
- package/dist/types.d.ts +10 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/usage/index.d.ts +3 -0
- package/dist/usage/index.d.ts.map +1 -0
- package/dist/usage/index.js +4 -0
- package/dist/usage/index.js.map +1 -0
- package/dist/usage/storage/durable-storage.d.ts +47 -0
- package/dist/usage/storage/durable-storage.d.ts.map +1 -0
- package/dist/usage/storage/durable-storage.js +27 -0
- package/dist/usage/storage/durable-storage.js.map +1 -0
- package/dist/usage/storage/index.d.ts +7 -0
- package/dist/usage/storage/index.d.ts.map +1 -0
- package/dist/usage/storage/index.js +28 -0
- package/dist/usage/storage/index.js.map +1 -0
- package/dist/usage/storage/indexeddb-storage.d.ts +18 -0
- package/dist/usage/storage/indexeddb-storage.d.ts.map +1 -0
- package/dist/usage/storage/indexeddb-storage.js +159 -0
- package/dist/usage/storage/indexeddb-storage.js.map +1 -0
- package/dist/usage/storage/node-fs-storage.d.ts +29 -0
- package/dist/usage/storage/node-fs-storage.d.ts.map +1 -0
- package/dist/usage/storage/node-fs-storage.js +180 -0
- package/dist/usage/storage/node-fs-storage.js.map +1 -0
- package/dist/usage/storage/noop-storage.d.ts +17 -0
- package/dist/usage/storage/noop-storage.d.ts.map +1 -0
- package/dist/usage/storage/noop-storage.js +67 -0
- package/dist/usage/storage/noop-storage.js.map +1 -0
- package/dist/usage/usage-reporter.d.ts +64 -0
- package/dist/usage/usage-reporter.d.ts.map +1 -0
- package/dist/usage/usage-reporter.js +234 -0
- package/dist/usage/usage-reporter.js.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import type { BridgeFlags, CachedFlag } from './flag.js';
|
|
2
|
+
export interface RealtimeClientConfig {
|
|
3
|
+
/** Bridge API base URL — same as the telemetry batcher. */
|
|
4
|
+
apiBaseUrl: string;
|
|
5
|
+
/** JWT workspace API key. */
|
|
6
|
+
apiKey: string;
|
|
7
|
+
/**
|
|
8
|
+
* App identifier for the `app:<appId>` channel. Set when the SDK is wired
|
|
9
|
+
* to a known app context.
|
|
10
|
+
*/
|
|
11
|
+
appId?: string;
|
|
12
|
+
/** Optional workspace + user identifier for authorize. Defaults derived from the API key. */
|
|
13
|
+
workspaceId?: string;
|
|
14
|
+
userId?: string;
|
|
15
|
+
/** When false, the client is a no-op. Defaults to true. */
|
|
16
|
+
enabled?: boolean;
|
|
17
|
+
/** Initial backoff in ms after an unexpected disconnect. Default 1000. */
|
|
18
|
+
reconnectBaseMs?: number;
|
|
19
|
+
/** Cap on reconnect backoff. Default 30_000. */
|
|
20
|
+
reconnectMaxMs?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Optional WebSocket factory — used in tests + non-browser environments.
|
|
23
|
+
* Default is `globalThis.WebSocket`.
|
|
24
|
+
*/
|
|
25
|
+
websocketFactory?: (url: string, protocols?: string | string[]) => WebSocketLike;
|
|
26
|
+
/** Optional fetch — same default-and-override pattern. */
|
|
27
|
+
fetchFn?: typeof fetch;
|
|
28
|
+
/**
|
|
29
|
+
* Called just before each /realtime/authorize round-trip. Return the user's
|
|
30
|
+
* JWT when authenticated so the server can allow per-user channel subscriptions.
|
|
31
|
+
* Falls back to apiKey when this is undefined or returns undefined.
|
|
32
|
+
*/
|
|
33
|
+
getAuthToken?: () => string | undefined;
|
|
34
|
+
}
|
|
35
|
+
/** Minimal WebSocket surface the client uses. */
|
|
36
|
+
export interface WebSocketLike {
|
|
37
|
+
readyState: number;
|
|
38
|
+
send(data: string): void;
|
|
39
|
+
close(code?: number, reason?: string): void;
|
|
40
|
+
onopen: ((ev: any) => void) | null;
|
|
41
|
+
onclose: ((ev: any) => void) | null;
|
|
42
|
+
onerror: ((ev: any) => void) | null;
|
|
43
|
+
onmessage: ((ev: {
|
|
44
|
+
data: any;
|
|
45
|
+
}) => void) | null;
|
|
46
|
+
}
|
|
47
|
+
/** Flag-update payload published on the workspace channel. */
|
|
48
|
+
export interface FlagUpdateMessage {
|
|
49
|
+
kind: 'flag.updated';
|
|
50
|
+
flag: CachedFlag;
|
|
51
|
+
}
|
|
52
|
+
/** Flag-removed payload. */
|
|
53
|
+
export interface FlagRemovedMessage {
|
|
54
|
+
kind: 'flag.removed';
|
|
55
|
+
key: string;
|
|
56
|
+
}
|
|
57
|
+
/** Per-user payload — e.g. token refresh signal or attribute change. */
|
|
58
|
+
export interface UserStateMessage {
|
|
59
|
+
kind: 'user.state_changed';
|
|
60
|
+
reason: 'token_invalidated' | 'attributes_changed' | 'role_changed' | string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Billing 2.0 / Phase A / US-3 — canonical plan-change payload published on
|
|
64
|
+
* the workspace channel. Consumers (the SDK billing surface) hydrate their
|
|
65
|
+
* cached state on receipt; no refetch required.
|
|
66
|
+
*/
|
|
67
|
+
export interface SubscriptionPlanChangedMessage {
|
|
68
|
+
kind: 'subscription.plan_changed';
|
|
69
|
+
tenantId: string;
|
|
70
|
+
from: {
|
|
71
|
+
slug: string;
|
|
72
|
+
};
|
|
73
|
+
to: {
|
|
74
|
+
slug: string;
|
|
75
|
+
name: string;
|
|
76
|
+
};
|
|
77
|
+
status: string;
|
|
78
|
+
effectiveAt: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Billing 2.0 / Phase B (US-4 onwards) — canonical billing lifecycle events.
|
|
82
|
+
* One discriminator-union covers every lifecycle event the workspace channel
|
|
83
|
+
* carries. Fields are optional per-kind; consumers should be defensive.
|
|
84
|
+
*/
|
|
85
|
+
export interface BillingLifecycleMessage {
|
|
86
|
+
kind: 'payment.failed' | 'payment.succeeded' | 'subscription.created' | 'subscription.updated' | 'subscription.canceled' | 'subscription.reactivated' | 'subscription.trial_started' | 'subscription.trial_ending_soon' | 'subscription.trial_converted' | 'subscription.trial_expired' | 'dunning.entered' | 'dunning.retry_scheduled' | 'dunning.recovered' | 'dunning.exhausted' | 'entitlements.changed';
|
|
87
|
+
tenantId: string;
|
|
88
|
+
stripeEventId?: string;
|
|
89
|
+
effectiveAt: string;
|
|
90
|
+
status?: string;
|
|
91
|
+
pastDueReason?: string | null;
|
|
92
|
+
cardLast4?: string;
|
|
93
|
+
hasCardOnFile?: boolean;
|
|
94
|
+
endsAt?: string;
|
|
95
|
+
daysLeft?: number;
|
|
96
|
+
nextRetryAt?: string;
|
|
97
|
+
finalRetryAt?: string;
|
|
98
|
+
gateEngaged?: boolean;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Billing 2.0 US-11 — live quota counter push. The bridge-api QuotaService
|
|
102
|
+
* publishes one of these whenever the workspace's used/limit ratio crosses a
|
|
103
|
+
* threshold or just changes (throttled ~1/sec per metric, last-write-wins).
|
|
104
|
+
* Consumers cache the snapshot per metric and re-render reactively.
|
|
105
|
+
*
|
|
106
|
+
* US-12 adds `policy` so the SDK can mark a metric as `metered` (Stripe-bills
|
|
107
|
+
* overage, no entitlement produced) or `hard` (entitlement flips at cap).
|
|
108
|
+
*/
|
|
109
|
+
export interface QuotaUpdatedMessage {
|
|
110
|
+
kind: 'quota.updated';
|
|
111
|
+
tenantId: string;
|
|
112
|
+
/** Optional — server-side context for telemetry. SDK does not use this. */
|
|
113
|
+
appId?: string;
|
|
114
|
+
effectiveAt: string;
|
|
115
|
+
metric: string;
|
|
116
|
+
used: number;
|
|
117
|
+
limit: number;
|
|
118
|
+
remaining: number;
|
|
119
|
+
/** null = under 80% used (UI renders nothing). */
|
|
120
|
+
warningLevel: null | 'approaching' | 'critical';
|
|
121
|
+
/**
|
|
122
|
+
* US-12 — per-metric policy. Optional for backward compatibility: a server
|
|
123
|
+
* that hasn't shipped US-12 yet won't populate this; the SDK defaults to
|
|
124
|
+
* `'metered'` in that case.
|
|
125
|
+
*/
|
|
126
|
+
policy?: 'hard' | 'metered';
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Billing 2.0 US-12 — wholesale entitlement snapshot push. The bridge-api
|
|
130
|
+
* EntitlementService publishes one of these whenever the diff against the
|
|
131
|
+
* previously published snapshot is non-empty. Consumers replace their cache
|
|
132
|
+
* wholesale on receipt.
|
|
133
|
+
*
|
|
134
|
+
* Distinct from `BillingLifecycleMessage`'s `'entitlements.changed'` kind:
|
|
135
|
+
* that one is a SIGNAL (no payload) on the lifecycle channel; this one
|
|
136
|
+
* carries the actual map. Both can be present on the wire — the SDK dispatch
|
|
137
|
+
* routes the carrying-map variant to `setOnEntitlementsChanged`.
|
|
138
|
+
*/
|
|
139
|
+
export interface EntitlementsChangedMessage {
|
|
140
|
+
kind: 'entitlements.changed';
|
|
141
|
+
tenantId: string;
|
|
142
|
+
effectiveAt: string;
|
|
143
|
+
entitlements: Record<string, boolean>;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Phase 3 (TBP-287/314) — first-paint snapshot. The server emits one per
|
|
147
|
+
* successful per-user channel subscribe (and again on reconnect). The SDK
|
|
148
|
+
* fans the `data` out to whichever slices the consumer has wired up — see
|
|
149
|
+
* `setOnSnapshot()`. Lazy slices (`tenant.quotas`, `tenant.members`,
|
|
150
|
+
* `app.plans`, etc.) are NOT in this payload; consumers call their `.load()`
|
|
151
|
+
* to populate them on demand.
|
|
152
|
+
*/
|
|
153
|
+
export interface SessionSnapshotMessage {
|
|
154
|
+
kind: 'session.snapshot';
|
|
155
|
+
data: {
|
|
156
|
+
app: {
|
|
157
|
+
branding: {
|
|
158
|
+
logo: string;
|
|
159
|
+
name: string;
|
|
160
|
+
primaryButtonBgColor?: string;
|
|
161
|
+
textColor?: string;
|
|
162
|
+
bgColor?: string;
|
|
163
|
+
fontFamily?: string;
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
tenant: {
|
|
167
|
+
id: string;
|
|
168
|
+
name: string;
|
|
169
|
+
subscription: {
|
|
170
|
+
plan: {
|
|
171
|
+
slug: string;
|
|
172
|
+
name: string;
|
|
173
|
+
};
|
|
174
|
+
status: string;
|
|
175
|
+
endsAt?: string;
|
|
176
|
+
gateEngaged?: boolean;
|
|
177
|
+
};
|
|
178
|
+
entitlements: Record<string, boolean>;
|
|
179
|
+
};
|
|
180
|
+
user: {
|
|
181
|
+
id: string;
|
|
182
|
+
email?: string;
|
|
183
|
+
role: string;
|
|
184
|
+
tenantId: string;
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
export type RealtimeMessage = FlagUpdateMessage | FlagRemovedMessage | UserStateMessage | SubscriptionPlanChangedMessage | BillingLifecycleMessage | QuotaUpdatedMessage | EntitlementsChangedMessage | SessionSnapshotMessage;
|
|
189
|
+
export type ConnectionState = 'idle' | 'connecting' | 'open' | 'closed';
|
|
190
|
+
export declare class RealtimeClient {
|
|
191
|
+
private readonly cfg;
|
|
192
|
+
private ws?;
|
|
193
|
+
private state;
|
|
194
|
+
private reconnectDelayMs;
|
|
195
|
+
private reconnectTimer?;
|
|
196
|
+
private bridge?;
|
|
197
|
+
private onUserStateHook?;
|
|
198
|
+
private onSubscriptionPlanChangedHook?;
|
|
199
|
+
private onBillingLifecycleHook?;
|
|
200
|
+
private onQuotaUpdatedHook?;
|
|
201
|
+
private onEntitlementsChangedHook?;
|
|
202
|
+
private onSnapshotHook?;
|
|
203
|
+
private onOpenHook?;
|
|
204
|
+
private onCloseHook?;
|
|
205
|
+
private stopped;
|
|
206
|
+
constructor(cfg: RealtimeClientConfig);
|
|
207
|
+
/** Attach to a BridgeFlags instance — flag updates auto-apply to its cache. */
|
|
208
|
+
attach(bridge: BridgeFlags): void;
|
|
209
|
+
/** Register a hook for per-user channel messages. */
|
|
210
|
+
setOnUserState(hook: (msg: UserStateMessage) => void): void;
|
|
211
|
+
/**
|
|
212
|
+
* Billing 2.0 US-3 — register a hook for canonical subscription plan-change
|
|
213
|
+
* events. The billing reactive surface (`BridgeSubscription.attach(rt)`)
|
|
214
|
+
* wires this up; framework SDKs typically don't call it directly.
|
|
215
|
+
*/
|
|
216
|
+
setOnSubscriptionPlanChanged(hook: (msg: SubscriptionPlanChangedMessage) => void): void;
|
|
217
|
+
/**
|
|
218
|
+
* Billing 2.0 US-5+ — register a hook for all canonical lifecycle events
|
|
219
|
+
* (payment.*, subscription.*, dunning.*, entitlements.*). `BridgeSubscription.attach(rt)`
|
|
220
|
+
* wires this; user-level event handlers can also register here via
|
|
221
|
+
* `useBridge().handle({ "payment.failed": ... })`.
|
|
222
|
+
*/
|
|
223
|
+
setOnBillingLifecycle(hook: (msg: BillingLifecycleMessage) => void): void;
|
|
224
|
+
/**
|
|
225
|
+
* Billing 2.0 US-11 — register a hook for `quota.updated` payloads on the
|
|
226
|
+
* workspace channel. `useBridge().quota(metric)` consumers wire this up
|
|
227
|
+
* so live counter UI reflects server-side ingest without polling.
|
|
228
|
+
*/
|
|
229
|
+
setOnQuotaUpdated(hook: (msg: QuotaUpdatedMessage) => void): void;
|
|
230
|
+
/**
|
|
231
|
+
* Billing 2.0 US-12 — register a hook for `entitlements.changed` payloads
|
|
232
|
+
* on the workspace channel that carry the full entitlements map.
|
|
233
|
+
* `useBridge().entitlements.can(...)` consumers wire this up so the cache
|
|
234
|
+
* replaces wholesale on every diff.
|
|
235
|
+
*
|
|
236
|
+
* Note: the legacy `BillingLifecycleMessage` `entitlements.changed` kind
|
|
237
|
+
* (signal-only, no payload) keeps firing through `setOnBillingLifecycle`
|
|
238
|
+
* — this hook ONLY fires when the wire payload includes the `entitlements`
|
|
239
|
+
* field. Allows both old and new consumers to coexist during rollout.
|
|
240
|
+
*/
|
|
241
|
+
setOnEntitlementsChanged(hook: (msg: EntitlementsChangedMessage) => void): void;
|
|
242
|
+
/**
|
|
243
|
+
* Phase 3 (TBP-287/314) — register a hook for `session.snapshot`. The server
|
|
244
|
+
* publishes one on every successful per-user channel subscribe (initial
|
|
245
|
+
* connect AND reconnect). Framework SDKs use this to pre-populate the
|
|
246
|
+
* `bridge.app.branding` / `bridge.tenant.{subscription,entitlements}` /
|
|
247
|
+
* `bridge.user` slices on first paint, eliminating the per-slice REST
|
|
248
|
+
* hydrate round-trips that the legacy bootstrap path required.
|
|
249
|
+
*
|
|
250
|
+
* Composition is fixed (no consumer config). If a later release promotes
|
|
251
|
+
* another slice into the snapshot, that slice's `.load()` becomes a no-op
|
|
252
|
+
* automatically — consumers don't need code changes.
|
|
253
|
+
*/
|
|
254
|
+
setOnSnapshot(hook: (msg: SessionSnapshotMessage) => void): void;
|
|
255
|
+
/**
|
|
256
|
+
* Register a hook fired when the WebSocket transitions to `'open'` —
|
|
257
|
+
* fires on initial connect AND on every successful reconnect. Framework
|
|
258
|
+
* SDKs use this to re-fire startup tasks (e.g. cache hydration) that
|
|
259
|
+
* may have been missed during an outage.
|
|
260
|
+
*/
|
|
261
|
+
setOnOpen(hook: () => void): void;
|
|
262
|
+
/**
|
|
263
|
+
* Register a hook fired when the WebSocket transitions to `'closed'` —
|
|
264
|
+
* use for surfacing connection status to consumers (e.g. an "offline"
|
|
265
|
+
* indicator). Fires on intentional close as well; check `getState()`
|
|
266
|
+
* if you need to distinguish.
|
|
267
|
+
*/
|
|
268
|
+
setOnClose(hook: () => void): void;
|
|
269
|
+
/**
|
|
270
|
+
* Re-run the authorize step against the current `getAuthToken()` value and
|
|
271
|
+
* re-open the WebSocket. Used by the framework SDK on every token rotation
|
|
272
|
+
* where the userId is unchanged but the JWT value rotated (post-refresh).
|
|
273
|
+
*
|
|
274
|
+
* Without this, the existing connection keeps riding the OLD token until
|
|
275
|
+
* Centrifugo's own connection-token TTL drops it — a strictly-larger
|
|
276
|
+
* blast-radius window than necessary.
|
|
277
|
+
*
|
|
278
|
+
* Behavior:
|
|
279
|
+
* - Disabled / stopped → no-op.
|
|
280
|
+
* - Mid-`connecting` → no-op; the in-flight authorize() reads the current
|
|
281
|
+
* token by closure, so it will already pick up the new value.
|
|
282
|
+
* - Open → drop the ws ref (so the old socket's onclose treats itself as
|
|
283
|
+
* stale via the identity guard in `openWebSocket`), close it with
|
|
284
|
+
* `1000 / sdk.reauthorize`, reset backoff, then `start()` immediately.
|
|
285
|
+
*/
|
|
286
|
+
reauthorize(): Promise<void>;
|
|
287
|
+
/**
|
|
288
|
+
* Phase 2 (TBP-307) — Set/update the appId after initial start. Framework
|
|
289
|
+
* SDKs call this when the app context first lands (e.g. after the first
|
|
290
|
+
* authorize round-trip exposes the JWT `aid` claim). Triggers a reconnect
|
|
291
|
+
* so the new `app:<appId>` channel is included in the next authorize.
|
|
292
|
+
*/
|
|
293
|
+
setAppId(appId: string | undefined): void;
|
|
294
|
+
/**
|
|
295
|
+
* Phase 2 (TBP-307) — Set/update the workspaceId after initial start. Used
|
|
296
|
+
* by framework SDKs when the tenant context lands or changes (workspace
|
|
297
|
+
* switcher, tenant join/leave). Triggers a reconnect.
|
|
298
|
+
*/
|
|
299
|
+
setWorkspaceId(workspaceId: string | undefined): void;
|
|
300
|
+
/**
|
|
301
|
+
* Update the userId after initial start — used by the framework SDK to
|
|
302
|
+
* subscribe to the per-user channel when the user logs in post-bootstrap.
|
|
303
|
+
* Triggers a reconnect so the new channel is included in the next authorize.
|
|
304
|
+
*/
|
|
305
|
+
setUserId(userId: string | undefined): void;
|
|
306
|
+
/** Begin connecting. Idempotent. */
|
|
307
|
+
start(): Promise<void>;
|
|
308
|
+
/** Close the connection. Idempotent. */
|
|
309
|
+
stop(): Promise<void>;
|
|
310
|
+
/** Read connection state. */
|
|
311
|
+
getState(): ConnectionState;
|
|
312
|
+
/**
|
|
313
|
+
* Channels this client subscribes to — the three canonical channels:
|
|
314
|
+
* - `app:<appId>` — flag mutations, app config (app-scoped)
|
|
315
|
+
* - `workspace:<wsId>` — subscription, quota, entitlement (tenant-scoped)
|
|
316
|
+
* - `user:<userId>` — user-state, role/attr change (user-scoped)
|
|
317
|
+
*
|
|
318
|
+
* Each id is optional; the SDK skips the channel if its id isn't configured.
|
|
319
|
+
* The anonymous-only standalone case ends up with just `app:<appId>`.
|
|
320
|
+
*/
|
|
321
|
+
channelsToSubscribe(): string[];
|
|
322
|
+
private fetchServerConfig;
|
|
323
|
+
private authorize;
|
|
324
|
+
private openWebSocket;
|
|
325
|
+
private handleMessage;
|
|
326
|
+
private scheduleReconnect;
|
|
327
|
+
}
|
|
328
|
+
//# sourceMappingURL=realtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"realtime.d.ts","sourceRoot":"","sources":["../../src/flags/realtime.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEzD,MAAM,WAAW,oBAAoB;IACnC,2DAA2D;IAC3D,UAAU,EAAE,MAAM,CAAC;IACnB,6BAA6B;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6FAA6F;IAC7F,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2DAA2D;IAC3D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0EAA0E;IAC1E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gDAAgD;IAChD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,aAAa,CAAC;IACjF,0DAA0D;IAC1D,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;IACvB;;;;OAIG;IACH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