@databuddy/sdk 2.3.29 → 2.4.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/README.md +1 -2
- package/dist/core/index.d.mts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.mjs +1 -1
- package/dist/node/index.d.mts +34 -80
- package/dist/node/index.d.ts +34 -80
- package/dist/node/index.mjs +12 -244
- package/dist/react/index.d.mts +4 -47
- package/dist/react/index.d.ts +4 -47
- package/dist/react/index.mjs +21 -103
- package/dist/shared/@databuddy/{sdk.BsF1xr6_.d.ts → sdk.DOtKE9NQ.d.mts} +7 -13
- package/dist/shared/@databuddy/{sdk.BsF1xr6_.d.mts → sdk.DOtKE9NQ.d.ts} +7 -13
- package/dist/shared/@databuddy/sdk.GM10R1Kp.mjs +46 -0
- package/dist/shared/@databuddy/{sdk.urY7MmVr.mjs → sdk.P9GHqNXr.mjs} +1 -1
- package/dist/shared/@databuddy/sdk.Ugr1p2j9.mjs +601 -0
- package/dist/shared/@databuddy/sdk.rnu91OSC.d.mts +81 -0
- package/dist/shared/@databuddy/sdk.rnu91OSC.d.ts +81 -0
- package/dist/vue/index.d.mts +8 -28
- package/dist/vue/index.d.ts +8 -28
- package/dist/vue/index.mjs +29 -65
- package/package.json +8 -23
- package/dist/ai/vercel/index.d.mts +0 -236
- package/dist/ai/vercel/index.d.ts +0 -236
- package/dist/ai/vercel/index.mjs +0 -708
- package/dist/shared/@databuddy/sdk.CALvx07o.mjs +0 -208
- package/dist/shared/@databuddy/sdk.CdLp6SQb.d.mts +0 -132
- package/dist/shared/@databuddy/sdk.CdLp6SQb.d.ts +0 -132
- package/dist/shared/@databuddy/sdk.DE24-JrU.mjs +0 -559
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
class Logger {
|
|
2
|
-
debugEnabled = false;
|
|
3
|
-
/**
|
|
4
|
-
* Enable or disable debug logging
|
|
5
|
-
*/
|
|
6
|
-
setDebug(enabled) {
|
|
7
|
-
this.debugEnabled = enabled;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Log debug messages (only when debug is enabled)
|
|
11
|
-
*/
|
|
12
|
-
debug(...args) {
|
|
13
|
-
if (this.debugEnabled) {
|
|
14
|
-
console.log("[Databuddy]", ...args);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Log info messages (always enabled)
|
|
19
|
-
*/
|
|
20
|
-
info(...args) {
|
|
21
|
-
console.info("[Databuddy]", ...args);
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Log warning messages (always enabled)
|
|
25
|
-
*/
|
|
26
|
-
warn(...args) {
|
|
27
|
-
console.warn("[Databuddy]", ...args);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Log error messages (always enabled)
|
|
31
|
-
*/
|
|
32
|
-
error(...args) {
|
|
33
|
-
console.error("[Databuddy]", ...args);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Log with table format (only when debug is enabled)
|
|
37
|
-
*/
|
|
38
|
-
table(data) {
|
|
39
|
-
if (this.debugEnabled) {
|
|
40
|
-
console.table(data);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Time a function execution (only when debug is enabled)
|
|
45
|
-
*/
|
|
46
|
-
time(label) {
|
|
47
|
-
if (this.debugEnabled) {
|
|
48
|
-
console.time(`[Databuddy] ${label}`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* End timing a function execution (only when debug is enabled)
|
|
53
|
-
*/
|
|
54
|
-
timeEnd(label) {
|
|
55
|
-
if (this.debugEnabled) {
|
|
56
|
-
console.timeEnd(`[Databuddy] ${label}`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Log JSON data (only when debug is enabled)
|
|
61
|
-
*/
|
|
62
|
-
json(data) {
|
|
63
|
-
if (this.debugEnabled) {
|
|
64
|
-
console.log("[Databuddy]", JSON.stringify(data, null, 2));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
const logger = new Logger();
|
|
69
|
-
|
|
70
|
-
const DEFAULT_RESULT = {
|
|
71
|
-
enabled: false,
|
|
72
|
-
value: false,
|
|
73
|
-
payload: null,
|
|
74
|
-
reason: "DEFAULT"
|
|
75
|
-
};
|
|
76
|
-
function getCacheKey(key, user) {
|
|
77
|
-
if (!(user?.userId || user?.email)) {
|
|
78
|
-
return key;
|
|
79
|
-
}
|
|
80
|
-
return `${key}:${user.userId ?? ""}:${user.email ?? ""}`;
|
|
81
|
-
}
|
|
82
|
-
function buildQueryParams(config, user) {
|
|
83
|
-
const params = new URLSearchParams();
|
|
84
|
-
params.set("clientId", config.clientId);
|
|
85
|
-
const u = user ?? config.user;
|
|
86
|
-
if (u?.userId) {
|
|
87
|
-
params.set("userId", u.userId);
|
|
88
|
-
}
|
|
89
|
-
if (u?.email) {
|
|
90
|
-
params.set("email", u.email);
|
|
91
|
-
}
|
|
92
|
-
if (u?.organizationId) {
|
|
93
|
-
params.set("organizationId", u.organizationId);
|
|
94
|
-
}
|
|
95
|
-
if (u?.teamId) {
|
|
96
|
-
params.set("teamId", u.teamId);
|
|
97
|
-
}
|
|
98
|
-
if (u?.properties) {
|
|
99
|
-
params.set("properties", JSON.stringify(u.properties));
|
|
100
|
-
}
|
|
101
|
-
if (config.environment) {
|
|
102
|
-
params.set("environment", config.environment);
|
|
103
|
-
}
|
|
104
|
-
return params;
|
|
105
|
-
}
|
|
106
|
-
async function fetchFlags(apiUrl, keys, params) {
|
|
107
|
-
const batchParams = new URLSearchParams(params);
|
|
108
|
-
batchParams.set("keys", keys.join(","));
|
|
109
|
-
const url = `${apiUrl}/public/v1/flags/bulk?${batchParams}`;
|
|
110
|
-
const response = await fetch(url);
|
|
111
|
-
if (!response.ok) {
|
|
112
|
-
const result = {};
|
|
113
|
-
for (const key of keys) {
|
|
114
|
-
result[key] = { ...DEFAULT_RESULT, reason: "ERROR" };
|
|
115
|
-
}
|
|
116
|
-
return result;
|
|
117
|
-
}
|
|
118
|
-
const data = await response.json();
|
|
119
|
-
return data.flags ?? {};
|
|
120
|
-
}
|
|
121
|
-
async function fetchAllFlags(apiUrl, params) {
|
|
122
|
-
const url = `${apiUrl}/public/v1/flags/bulk?${params}`;
|
|
123
|
-
const response = await fetch(url);
|
|
124
|
-
if (!response.ok) {
|
|
125
|
-
return {};
|
|
126
|
-
}
|
|
127
|
-
const data = await response.json();
|
|
128
|
-
return data.flags ?? {};
|
|
129
|
-
}
|
|
130
|
-
function isCacheValid(entry) {
|
|
131
|
-
if (!entry) {
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
return Date.now() <= entry.expiresAt;
|
|
135
|
-
}
|
|
136
|
-
function isCacheStale(entry) {
|
|
137
|
-
return Date.now() > entry.staleAt;
|
|
138
|
-
}
|
|
139
|
-
function createCacheEntry(result, ttl, staleTime) {
|
|
140
|
-
const now = Date.now();
|
|
141
|
-
return {
|
|
142
|
-
result,
|
|
143
|
-
staleAt: now + (staleTime ?? ttl / 2),
|
|
144
|
-
expiresAt: now + ttl
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
class RequestBatcher {
|
|
148
|
-
pending = /* @__PURE__ */ new Map();
|
|
149
|
-
timer = null;
|
|
150
|
-
batchDelayMs;
|
|
151
|
-
apiUrl;
|
|
152
|
-
params;
|
|
153
|
-
constructor(apiUrl, params, batchDelayMs = 10) {
|
|
154
|
-
this.apiUrl = apiUrl;
|
|
155
|
-
this.params = params;
|
|
156
|
-
this.batchDelayMs = batchDelayMs;
|
|
157
|
-
}
|
|
158
|
-
request(key) {
|
|
159
|
-
return new Promise((resolve, reject) => {
|
|
160
|
-
const existing = this.pending.get(key);
|
|
161
|
-
if (existing) {
|
|
162
|
-
existing.push({ resolve, reject });
|
|
163
|
-
} else {
|
|
164
|
-
this.pending.set(key, [{ resolve, reject }]);
|
|
165
|
-
}
|
|
166
|
-
if (!this.timer) {
|
|
167
|
-
this.timer = setTimeout(() => this.flush(), this.batchDelayMs);
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
async flush() {
|
|
172
|
-
this.timer = null;
|
|
173
|
-
const keys = [...this.pending.keys()];
|
|
174
|
-
const callbacks = new Map(this.pending);
|
|
175
|
-
this.pending.clear();
|
|
176
|
-
if (keys.length === 0) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
try {
|
|
180
|
-
const results = await fetchFlags(this.apiUrl, keys, this.params);
|
|
181
|
-
for (const [key, cbs] of callbacks) {
|
|
182
|
-
const result = results[key] ?? {
|
|
183
|
-
...DEFAULT_RESULT,
|
|
184
|
-
reason: "NOT_FOUND"
|
|
185
|
-
};
|
|
186
|
-
for (const cb of cbs) {
|
|
187
|
-
cb.resolve(result);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
} catch (err) {
|
|
191
|
-
const error = err instanceof Error ? err : new Error("Fetch failed");
|
|
192
|
-
for (const cbs of callbacks.values()) {
|
|
193
|
-
for (const cb of cbs) {
|
|
194
|
-
cb.reject(error);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
destroy() {
|
|
200
|
-
if (this.timer) {
|
|
201
|
-
clearTimeout(this.timer);
|
|
202
|
-
this.timer = null;
|
|
203
|
-
}
|
|
204
|
-
this.pending.clear();
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
export { DEFAULT_RESULT as D, RequestBatcher as R, isCacheStale as a, buildQueryParams as b, createCacheEntry as c, fetchAllFlags as f, getCacheKey as g, isCacheValid as i, logger as l };
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/** Flag evaluation result from API */
|
|
2
|
-
interface FlagResult {
|
|
3
|
-
enabled: boolean;
|
|
4
|
-
value: boolean | string | number;
|
|
5
|
-
payload: Record<string, unknown> | null;
|
|
6
|
-
reason: string;
|
|
7
|
-
variant?: string;
|
|
8
|
-
}
|
|
9
|
-
/** User context for flag evaluation */
|
|
10
|
-
interface UserContext {
|
|
11
|
-
userId?: string;
|
|
12
|
-
email?: string;
|
|
13
|
-
/** Organization ID for org-level rollouts (all org members get same result) */
|
|
14
|
-
organizationId?: string;
|
|
15
|
-
/** Team ID for team-level rollouts (all team members get same result) */
|
|
16
|
-
teamId?: string;
|
|
17
|
-
properties?: Record<string, unknown>;
|
|
18
|
-
}
|
|
19
|
-
/** SDK configuration */
|
|
20
|
-
interface FlagsConfig {
|
|
21
|
-
/** Client ID (website or organization ID) */
|
|
22
|
-
clientId: string;
|
|
23
|
-
/** API URL (default: https://api.databuddy.cc) */
|
|
24
|
-
apiUrl?: string;
|
|
25
|
-
/** User context for evaluation */
|
|
26
|
-
user?: UserContext;
|
|
27
|
-
/** Disable flag evaluation entirely */
|
|
28
|
-
disabled?: boolean;
|
|
29
|
-
/** Enable debug logging */
|
|
30
|
-
debug?: boolean;
|
|
31
|
-
/** Skip persistent storage (browser only) */
|
|
32
|
-
skipStorage?: boolean;
|
|
33
|
-
/** Session is loading - defer evaluation */
|
|
34
|
-
isPending?: boolean;
|
|
35
|
-
/** Auto-fetch all flags on init (default: true) */
|
|
36
|
-
autoFetch?: boolean;
|
|
37
|
-
/** Environment name */
|
|
38
|
-
environment?: string;
|
|
39
|
-
/** Cache TTL in ms - after this, cache is invalid (default: 60000) */
|
|
40
|
-
cacheTtl?: number;
|
|
41
|
-
/** Stale time in ms - after this, revalidate in background (default: cacheTtl/2) */
|
|
42
|
-
staleTime?: number;
|
|
43
|
-
}
|
|
44
|
-
/** Flag status for clear state management */
|
|
45
|
-
type FlagStatus = "loading" | "ready" | "error" | "pending";
|
|
46
|
-
/** Synchronous flag state for React hooks */
|
|
47
|
-
interface FlagState {
|
|
48
|
-
/** Whether the flag is enabled (true/false) */
|
|
49
|
-
on: boolean;
|
|
50
|
-
/** @deprecated Use `on` instead */
|
|
51
|
-
enabled: boolean;
|
|
52
|
-
/** Current status: loading, ready, error, or pending */
|
|
53
|
-
status: FlagStatus;
|
|
54
|
-
/** Whether the flag is still loading */
|
|
55
|
-
loading: boolean;
|
|
56
|
-
/** @deprecated Use `status === 'ready'` instead */
|
|
57
|
-
isLoading: boolean;
|
|
58
|
-
/** @deprecated Use `status === 'ready'` instead */
|
|
59
|
-
isReady: boolean;
|
|
60
|
-
/** The flag's value (boolean, string, or number) */
|
|
61
|
-
value?: boolean | string | number;
|
|
62
|
-
/** Variant name for multivariate flags */
|
|
63
|
-
variant?: string;
|
|
64
|
-
}
|
|
65
|
-
/** Feature state returned by useFeature hook */
|
|
66
|
-
interface FeatureState {
|
|
67
|
-
/** Whether the feature is enabled */
|
|
68
|
-
on: boolean;
|
|
69
|
-
/** Whether the flag is loading */
|
|
70
|
-
loading: boolean;
|
|
71
|
-
/** Current status */
|
|
72
|
-
status: FlagStatus;
|
|
73
|
-
/** The flag's value */
|
|
74
|
-
value?: boolean | string | number;
|
|
75
|
-
/** Variant for A/B tests */
|
|
76
|
-
variant?: string;
|
|
77
|
-
}
|
|
78
|
-
/** Context returned by useFlags hook */
|
|
79
|
-
interface FlagsContext {
|
|
80
|
-
/** @deprecated Use getFlag instead - confusing name */
|
|
81
|
-
isEnabled: (key: string) => FlagState;
|
|
82
|
-
/** Get a flag's full state */
|
|
83
|
-
getFlag: (key: string) => FlagState;
|
|
84
|
-
/** Get a flag's value with type safety */
|
|
85
|
-
getValue: <T extends boolean | string | number = boolean>(key: string, defaultValue?: T) => T;
|
|
86
|
-
/** Check if a flag is on (simple boolean) */
|
|
87
|
-
isOn: (key: string) => boolean;
|
|
88
|
-
/** Async fetch a specific flag */
|
|
89
|
-
fetchFlag: (key: string) => Promise<FlagResult>;
|
|
90
|
-
/** Fetch all flags */
|
|
91
|
-
fetchAllFlags: () => Promise<void>;
|
|
92
|
-
/** Update user context */
|
|
93
|
-
updateUser: (user: UserContext) => void;
|
|
94
|
-
/** Refresh all flags */
|
|
95
|
-
refresh: (forceClear?: boolean) => Promise<void>;
|
|
96
|
-
/** Whether the SDK is ready */
|
|
97
|
-
isReady: boolean;
|
|
98
|
-
}
|
|
99
|
-
/** Storage interface for persistence */
|
|
100
|
-
interface StorageInterface {
|
|
101
|
-
get(key: string): FlagResult | null;
|
|
102
|
-
set(key: string, value: FlagResult): void;
|
|
103
|
-
getAll(): Record<string, FlagResult>;
|
|
104
|
-
setAll(flags: Record<string, FlagResult>): void;
|
|
105
|
-
delete?(key: string): void;
|
|
106
|
-
deleteMultiple?(keys: string[]): void;
|
|
107
|
-
clear(): void;
|
|
108
|
-
cleanupExpired(): void;
|
|
109
|
-
}
|
|
110
|
-
/** Manager constructor options */
|
|
111
|
-
interface FlagsManagerOptions {
|
|
112
|
-
config: FlagsConfig;
|
|
113
|
-
storage?: StorageInterface;
|
|
114
|
-
onFlagsUpdate?: (flags: Record<string, FlagResult>) => void;
|
|
115
|
-
onConfigUpdate?: (config: FlagsConfig) => void;
|
|
116
|
-
onReady?: () => void;
|
|
117
|
-
}
|
|
118
|
-
/** Flags manager interface */
|
|
119
|
-
interface FlagsManager {
|
|
120
|
-
getFlag: (key: string, user?: UserContext) => Promise<FlagResult>;
|
|
121
|
-
isEnabled: (key: string) => FlagState;
|
|
122
|
-
getValue: <T = boolean | string | number>(key: string, defaultValue?: T) => T;
|
|
123
|
-
fetchAllFlags: (user?: UserContext) => Promise<void>;
|
|
124
|
-
updateUser: (user: UserContext) => void;
|
|
125
|
-
refresh: (forceClear?: boolean) => Promise<void>;
|
|
126
|
-
updateConfig: (config: FlagsConfig) => void;
|
|
127
|
-
getMemoryFlags: () => Record<string, FlagResult>;
|
|
128
|
-
isReady: () => boolean;
|
|
129
|
-
destroy?: () => void;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export type { FlagsConfig as F, UserContext as U, FeatureState as a, FlagState as b, FlagsContext as c, FlagResult as d, FlagsManager as e, FlagsManagerOptions as f };
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/** Flag evaluation result from API */
|
|
2
|
-
interface FlagResult {
|
|
3
|
-
enabled: boolean;
|
|
4
|
-
value: boolean | string | number;
|
|
5
|
-
payload: Record<string, unknown> | null;
|
|
6
|
-
reason: string;
|
|
7
|
-
variant?: string;
|
|
8
|
-
}
|
|
9
|
-
/** User context for flag evaluation */
|
|
10
|
-
interface UserContext {
|
|
11
|
-
userId?: string;
|
|
12
|
-
email?: string;
|
|
13
|
-
/** Organization ID for org-level rollouts (all org members get same result) */
|
|
14
|
-
organizationId?: string;
|
|
15
|
-
/** Team ID for team-level rollouts (all team members get same result) */
|
|
16
|
-
teamId?: string;
|
|
17
|
-
properties?: Record<string, unknown>;
|
|
18
|
-
}
|
|
19
|
-
/** SDK configuration */
|
|
20
|
-
interface FlagsConfig {
|
|
21
|
-
/** Client ID (website or organization ID) */
|
|
22
|
-
clientId: string;
|
|
23
|
-
/** API URL (default: https://api.databuddy.cc) */
|
|
24
|
-
apiUrl?: string;
|
|
25
|
-
/** User context for evaluation */
|
|
26
|
-
user?: UserContext;
|
|
27
|
-
/** Disable flag evaluation entirely */
|
|
28
|
-
disabled?: boolean;
|
|
29
|
-
/** Enable debug logging */
|
|
30
|
-
debug?: boolean;
|
|
31
|
-
/** Skip persistent storage (browser only) */
|
|
32
|
-
skipStorage?: boolean;
|
|
33
|
-
/** Session is loading - defer evaluation */
|
|
34
|
-
isPending?: boolean;
|
|
35
|
-
/** Auto-fetch all flags on init (default: true) */
|
|
36
|
-
autoFetch?: boolean;
|
|
37
|
-
/** Environment name */
|
|
38
|
-
environment?: string;
|
|
39
|
-
/** Cache TTL in ms - after this, cache is invalid (default: 60000) */
|
|
40
|
-
cacheTtl?: number;
|
|
41
|
-
/** Stale time in ms - after this, revalidate in background (default: cacheTtl/2) */
|
|
42
|
-
staleTime?: number;
|
|
43
|
-
}
|
|
44
|
-
/** Flag status for clear state management */
|
|
45
|
-
type FlagStatus = "loading" | "ready" | "error" | "pending";
|
|
46
|
-
/** Synchronous flag state for React hooks */
|
|
47
|
-
interface FlagState {
|
|
48
|
-
/** Whether the flag is enabled (true/false) */
|
|
49
|
-
on: boolean;
|
|
50
|
-
/** @deprecated Use `on` instead */
|
|
51
|
-
enabled: boolean;
|
|
52
|
-
/** Current status: loading, ready, error, or pending */
|
|
53
|
-
status: FlagStatus;
|
|
54
|
-
/** Whether the flag is still loading */
|
|
55
|
-
loading: boolean;
|
|
56
|
-
/** @deprecated Use `status === 'ready'` instead */
|
|
57
|
-
isLoading: boolean;
|
|
58
|
-
/** @deprecated Use `status === 'ready'` instead */
|
|
59
|
-
isReady: boolean;
|
|
60
|
-
/** The flag's value (boolean, string, or number) */
|
|
61
|
-
value?: boolean | string | number;
|
|
62
|
-
/** Variant name for multivariate flags */
|
|
63
|
-
variant?: string;
|
|
64
|
-
}
|
|
65
|
-
/** Feature state returned by useFeature hook */
|
|
66
|
-
interface FeatureState {
|
|
67
|
-
/** Whether the feature is enabled */
|
|
68
|
-
on: boolean;
|
|
69
|
-
/** Whether the flag is loading */
|
|
70
|
-
loading: boolean;
|
|
71
|
-
/** Current status */
|
|
72
|
-
status: FlagStatus;
|
|
73
|
-
/** The flag's value */
|
|
74
|
-
value?: boolean | string | number;
|
|
75
|
-
/** Variant for A/B tests */
|
|
76
|
-
variant?: string;
|
|
77
|
-
}
|
|
78
|
-
/** Context returned by useFlags hook */
|
|
79
|
-
interface FlagsContext {
|
|
80
|
-
/** @deprecated Use getFlag instead - confusing name */
|
|
81
|
-
isEnabled: (key: string) => FlagState;
|
|
82
|
-
/** Get a flag's full state */
|
|
83
|
-
getFlag: (key: string) => FlagState;
|
|
84
|
-
/** Get a flag's value with type safety */
|
|
85
|
-
getValue: <T extends boolean | string | number = boolean>(key: string, defaultValue?: T) => T;
|
|
86
|
-
/** Check if a flag is on (simple boolean) */
|
|
87
|
-
isOn: (key: string) => boolean;
|
|
88
|
-
/** Async fetch a specific flag */
|
|
89
|
-
fetchFlag: (key: string) => Promise<FlagResult>;
|
|
90
|
-
/** Fetch all flags */
|
|
91
|
-
fetchAllFlags: () => Promise<void>;
|
|
92
|
-
/** Update user context */
|
|
93
|
-
updateUser: (user: UserContext) => void;
|
|
94
|
-
/** Refresh all flags */
|
|
95
|
-
refresh: (forceClear?: boolean) => Promise<void>;
|
|
96
|
-
/** Whether the SDK is ready */
|
|
97
|
-
isReady: boolean;
|
|
98
|
-
}
|
|
99
|
-
/** Storage interface for persistence */
|
|
100
|
-
interface StorageInterface {
|
|
101
|
-
get(key: string): FlagResult | null;
|
|
102
|
-
set(key: string, value: FlagResult): void;
|
|
103
|
-
getAll(): Record<string, FlagResult>;
|
|
104
|
-
setAll(flags: Record<string, FlagResult>): void;
|
|
105
|
-
delete?(key: string): void;
|
|
106
|
-
deleteMultiple?(keys: string[]): void;
|
|
107
|
-
clear(): void;
|
|
108
|
-
cleanupExpired(): void;
|
|
109
|
-
}
|
|
110
|
-
/** Manager constructor options */
|
|
111
|
-
interface FlagsManagerOptions {
|
|
112
|
-
config: FlagsConfig;
|
|
113
|
-
storage?: StorageInterface;
|
|
114
|
-
onFlagsUpdate?: (flags: Record<string, FlagResult>) => void;
|
|
115
|
-
onConfigUpdate?: (config: FlagsConfig) => void;
|
|
116
|
-
onReady?: () => void;
|
|
117
|
-
}
|
|
118
|
-
/** Flags manager interface */
|
|
119
|
-
interface FlagsManager {
|
|
120
|
-
getFlag: (key: string, user?: UserContext) => Promise<FlagResult>;
|
|
121
|
-
isEnabled: (key: string) => FlagState;
|
|
122
|
-
getValue: <T = boolean | string | number>(key: string, defaultValue?: T) => T;
|
|
123
|
-
fetchAllFlags: (user?: UserContext) => Promise<void>;
|
|
124
|
-
updateUser: (user: UserContext) => void;
|
|
125
|
-
refresh: (forceClear?: boolean) => Promise<void>;
|
|
126
|
-
updateConfig: (config: FlagsConfig) => void;
|
|
127
|
-
getMemoryFlags: () => Record<string, FlagResult>;
|
|
128
|
-
isReady: () => boolean;
|
|
129
|
-
destroy?: () => void;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export type { FlagsConfig as F, UserContext as U, FeatureState as a, FlagState as b, FlagsContext as c, FlagResult as d, FlagsManager as e, FlagsManagerOptions as f };
|