@savvagent/solid 1.0.0 → 1.1.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/index.d.mts +232 -16
- package/dist/index.d.ts +232 -16
- package/dist/index.js +294 -19
- package/dist/index.mjs +290 -27
- package/package.json +16 -7
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,39 @@
|
|
|
1
1
|
import * as solid_js from 'solid-js';
|
|
2
2
|
import { ParentProps, Accessor } from 'solid-js';
|
|
3
3
|
import { FlagClientConfig, FlagClient, FlagContext, FlagEvaluationResult } from '@savvagent/sdk';
|
|
4
|
-
export { ApiTypes, ErrorEvent, EvaluationEvent, FlagClient, FlagClientConfig, FlagContext, FlagEvaluationResult, FlagUpdateEvent, components } from '@savvagent/sdk';
|
|
4
|
+
export { ApiTypes, ErrorEvent, EvaluationEvent, FlagClient, FlagClientConfig, FlagContext, FlagDefinition, FlagEvaluationResult, FlagUpdateEvent, components } from '@savvagent/sdk';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Default context values that apply to all flag evaluations
|
|
8
|
+
* Per SDK Developer Guide: https://docs.savvagent.com/sdk-developer-guide
|
|
9
|
+
*/
|
|
10
|
+
interface DefaultFlagContext {
|
|
11
|
+
/** Application ID for application-scoped flags */
|
|
12
|
+
applicationId?: string;
|
|
13
|
+
/** Environment (development, staging, production) */
|
|
14
|
+
environment?: string;
|
|
15
|
+
/** Organization ID for multi-tenant apps */
|
|
16
|
+
organizationId?: string;
|
|
17
|
+
/** Default user ID (required for percentage rollouts) */
|
|
18
|
+
userId?: string;
|
|
19
|
+
/** Default anonymous ID (alternative to userId for anonymous users) */
|
|
20
|
+
anonymousId?: string;
|
|
21
|
+
/** Session ID as fallback identifier */
|
|
22
|
+
sessionId?: string;
|
|
23
|
+
/** User's language code (e.g., "en", "es") */
|
|
24
|
+
language?: string;
|
|
25
|
+
/** Default attributes for targeting */
|
|
26
|
+
attributes?: Record<string, any>;
|
|
27
|
+
}
|
|
28
|
+
interface SavvagentContextValue {
|
|
29
|
+
client: FlagClient;
|
|
30
|
+
isReady: Accessor<boolean>;
|
|
31
|
+
defaultContext: Accessor<FlagContext>;
|
|
32
|
+
}
|
|
6
33
|
interface SavvagentProviderProps extends ParentProps {
|
|
7
34
|
config: FlagClientConfig;
|
|
35
|
+
/** Default context values applied to all flag evaluations */
|
|
36
|
+
defaultContext?: DefaultFlagContext;
|
|
8
37
|
}
|
|
9
38
|
/**
|
|
10
39
|
* Provider component that initializes and provides the Savvagent client.
|
|
@@ -15,7 +44,15 @@ interface SavvagentProviderProps extends ParentProps {
|
|
|
15
44
|
*
|
|
16
45
|
* function App() {
|
|
17
46
|
* return (
|
|
18
|
-
* <SavvagentProvider
|
|
47
|
+
* <SavvagentProvider
|
|
48
|
+
* config={{ apiKey: 'sdk_...' }}
|
|
49
|
+
* defaultContext={{
|
|
50
|
+
* applicationId: 'my-app-id',
|
|
51
|
+
* environment: 'development',
|
|
52
|
+
* userId: 'user-123',
|
|
53
|
+
* attributes: { plan: 'pro' }
|
|
54
|
+
* }}
|
|
55
|
+
* >
|
|
19
56
|
* <MyApp />
|
|
20
57
|
* </SavvagentProvider>
|
|
21
58
|
* );
|
|
@@ -24,10 +61,10 @@ interface SavvagentProviderProps extends ParentProps {
|
|
|
24
61
|
*/
|
|
25
62
|
declare function SavvagentProvider(props: SavvagentProviderProps): solid_js.JSX.Element;
|
|
26
63
|
/**
|
|
27
|
-
* Get the Savvagent client
|
|
64
|
+
* Get the Savvagent context including client, ready state, and default context.
|
|
28
65
|
* Must be used within a SavvagentProvider.
|
|
29
66
|
*
|
|
30
|
-
* @returns The FlagClient instance
|
|
67
|
+
* @returns The FlagClient instance, ready state accessor, and default context accessor
|
|
31
68
|
* @throws Error if used outside of SavvagentProvider
|
|
32
69
|
*
|
|
33
70
|
* @example
|
|
@@ -35,13 +72,17 @@ declare function SavvagentProvider(props: SavvagentProviderProps): solid_js.JSX.
|
|
|
35
72
|
* import { useSavvagent } from '@savvagent/solid';
|
|
36
73
|
*
|
|
37
74
|
* function MyComponent() {
|
|
38
|
-
* const client = useSavvagent();
|
|
39
|
-
*
|
|
40
|
-
* return
|
|
75
|
+
* const { client, isReady, defaultContext } = useSavvagent();
|
|
76
|
+
*
|
|
77
|
+
* return (
|
|
78
|
+
* <Show when={isReady()}>
|
|
79
|
+
* <div>Client ready!</div>
|
|
80
|
+
* </Show>
|
|
81
|
+
* );
|
|
41
82
|
* }
|
|
42
83
|
* ```
|
|
43
84
|
*/
|
|
44
|
-
declare function useSavvagent():
|
|
85
|
+
declare function useSavvagent(): SavvagentContextValue;
|
|
45
86
|
interface CreateFlagOptions {
|
|
46
87
|
/** Context for flag evaluation */
|
|
47
88
|
context?: FlagContext;
|
|
@@ -118,34 +159,209 @@ declare function createFlag(flagKey: string, options?: CreateFlagOptions): Creat
|
|
|
118
159
|
* ```
|
|
119
160
|
*/
|
|
120
161
|
declare function createFlagValue(flagKey: string, options?: CreateFlagOptions): Accessor<boolean>;
|
|
162
|
+
interface CreateFlagsOptions {
|
|
163
|
+
/** Context for flag evaluation */
|
|
164
|
+
context?: FlagContext;
|
|
165
|
+
/** Default values for flags (keyed by flag key) */
|
|
166
|
+
defaultValues?: Record<string, boolean>;
|
|
167
|
+
/** Enable real-time updates */
|
|
168
|
+
realtime?: boolean;
|
|
169
|
+
/** Custom error handler */
|
|
170
|
+
onError?: (error: Error, flagKey: string) => void;
|
|
171
|
+
}
|
|
172
|
+
interface CreateFlagsReturn {
|
|
173
|
+
/** Map of flag keys to their current values */
|
|
174
|
+
values: Accessor<Record<string, boolean>>;
|
|
175
|
+
/** Whether any flag is currently being evaluated */
|
|
176
|
+
loading: Accessor<boolean>;
|
|
177
|
+
/** Map of flag keys to their errors (if any) */
|
|
178
|
+
errors: Accessor<Record<string, Error | null>>;
|
|
179
|
+
/** Map of flag keys to their detailed evaluation results */
|
|
180
|
+
results: Accessor<Record<string, FlagEvaluationResult | null>>;
|
|
181
|
+
/** Force re-evaluation of all flags */
|
|
182
|
+
refetch: () => void;
|
|
183
|
+
}
|
|
121
184
|
/**
|
|
122
|
-
* Create
|
|
185
|
+
* Create reactive flags for multiple flag keys with a single state update.
|
|
186
|
+
* This is more efficient than using multiple createFlag calls when you need
|
|
187
|
+
* several flags in the same component.
|
|
123
188
|
*
|
|
124
|
-
* @
|
|
189
|
+
* @param flagKeys - Array of feature flag keys to evaluate
|
|
190
|
+
* @param options - Configuration options
|
|
191
|
+
* @returns Reactive flag state for all flags
|
|
125
192
|
*
|
|
126
193
|
* @example
|
|
127
194
|
* ```tsx
|
|
128
|
-
* import {
|
|
195
|
+
* import { createFlags } from '@savvagent/solid';
|
|
196
|
+
* import { Show, For } from 'solid-js';
|
|
197
|
+
*
|
|
198
|
+
* function MyComponent() {
|
|
199
|
+
* const flags = createFlags(
|
|
200
|
+
* ['feature-a', 'feature-b', 'feature-c'],
|
|
201
|
+
* {
|
|
202
|
+
* context: { user_id: 'user-123' },
|
|
203
|
+
* defaultValues: { 'feature-a': false, 'feature-b': true },
|
|
204
|
+
* realtime: true
|
|
205
|
+
* }
|
|
206
|
+
* );
|
|
207
|
+
*
|
|
208
|
+
* return (
|
|
209
|
+
* <Show when={!flags.loading()} fallback={<Spinner />}>
|
|
210
|
+
* <div>
|
|
211
|
+
* <Show when={flags.values()['feature-a']}>
|
|
212
|
+
* <FeatureA />
|
|
213
|
+
* </Show>
|
|
214
|
+
* <Show when={flags.values()['feature-b']}>
|
|
215
|
+
* <FeatureB />
|
|
216
|
+
* </Show>
|
|
217
|
+
* </div>
|
|
218
|
+
* </Show>
|
|
219
|
+
* );
|
|
220
|
+
* }
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
declare function createFlags(flagKeys: string[], options?: CreateFlagsOptions): CreateFlagsReturn;
|
|
224
|
+
/**
|
|
225
|
+
* Execute a callback conditionally based on a flag value.
|
|
226
|
+
*
|
|
227
|
+
* @param flagKey - The feature flag key to check
|
|
228
|
+
* @param callback - Function to execute if flag is enabled
|
|
229
|
+
* @param options - Configuration options
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```tsx
|
|
233
|
+
* import { createWithFlag } from '@savvagent/solid';
|
|
234
|
+
*
|
|
235
|
+
* function MyComponent() {
|
|
236
|
+
* createWithFlag('analytics-enabled', async () => {
|
|
237
|
+
* await trackEvent('page_view');
|
|
238
|
+
* });
|
|
239
|
+
*
|
|
240
|
+
* return <div>Content</div>;
|
|
241
|
+
* }
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
declare function createWithFlag(flagKey: string, callback: () => void | Promise<void>, options?: CreateFlagOptions): void;
|
|
245
|
+
interface CreateUserReturn {
|
|
246
|
+
/** Current user ID */
|
|
247
|
+
userId: Accessor<string | null>;
|
|
248
|
+
/** Set user ID */
|
|
249
|
+
setUserId: (id: string | null) => void;
|
|
250
|
+
/** Get current user ID from client */
|
|
251
|
+
getUserId: () => string | null;
|
|
252
|
+
/** Current anonymous ID */
|
|
253
|
+
anonymousId: Accessor<string | null>;
|
|
254
|
+
/** Set anonymous ID */
|
|
255
|
+
setAnonymousId: (id: string) => void;
|
|
256
|
+
/** Get current anonymous ID from client */
|
|
257
|
+
getAnonymousId: () => string | null;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Create signals for user identification management.
|
|
261
|
+
*
|
|
262
|
+
* @returns User ID management functions and reactive signals
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```tsx
|
|
266
|
+
* import { createUser } from '@savvagent/solid';
|
|
129
267
|
* import { createEffect } from 'solid-js';
|
|
130
268
|
*
|
|
131
269
|
* function AuthHandler() {
|
|
132
|
-
* const
|
|
270
|
+
* const user = createUser();
|
|
133
271
|
*
|
|
134
272
|
* createEffect(() => {
|
|
135
273
|
* if (currentUser()) {
|
|
136
|
-
* setUserId(currentUser().id);
|
|
274
|
+
* user.setUserId(currentUser().id);
|
|
137
275
|
* } else {
|
|
138
|
-
* setUserId(null);
|
|
276
|
+
* user.setUserId(null);
|
|
139
277
|
* }
|
|
140
278
|
* });
|
|
141
279
|
*
|
|
142
|
-
* return
|
|
280
|
+
* return <div>User ID: {user.userId()}</div>;
|
|
281
|
+
* }
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
declare function createUser(): CreateUserReturn;
|
|
285
|
+
interface CreateEnvironmentReturn {
|
|
286
|
+
/** Current environment as a reactive signal */
|
|
287
|
+
environment: Accessor<string>;
|
|
288
|
+
/** Set the environment */
|
|
289
|
+
setEnvironment: (env: string) => void;
|
|
290
|
+
/** Get the current environment from client */
|
|
291
|
+
getEnvironment: () => string;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Create signals for environment management.
|
|
295
|
+
*
|
|
296
|
+
* @returns Environment management functions and reactive signal
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```tsx
|
|
300
|
+
* import { createEnvironment } from '@savvagent/solid';
|
|
301
|
+
*
|
|
302
|
+
* function EnvironmentSwitcher() {
|
|
303
|
+
* const { environment, setEnvironment } = createEnvironment();
|
|
304
|
+
*
|
|
305
|
+
* return (
|
|
306
|
+
* <select value={environment()} onChange={(e) => setEnvironment(e.target.value)}>
|
|
307
|
+
* <option value="development">Development</option>
|
|
308
|
+
* <option value="staging">Staging</option>
|
|
309
|
+
* <option value="production">Production</option>
|
|
310
|
+
* </select>
|
|
311
|
+
* );
|
|
312
|
+
* }
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
declare function createEnvironment(): CreateEnvironmentReturn;
|
|
316
|
+
/**
|
|
317
|
+
* Legacy function - use createUser() instead.
|
|
318
|
+
* Create signals for user identification.
|
|
319
|
+
*
|
|
320
|
+
* @returns User ID signal tuple [userId, setUserId]
|
|
321
|
+
* @deprecated Use createUser() for full user management
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```tsx
|
|
325
|
+
* import { createUserSignals } from '@savvagent/solid';
|
|
326
|
+
*
|
|
327
|
+
* function AuthHandler() {
|
|
328
|
+
* const [userId, setUserId] = createUserSignals();
|
|
329
|
+
*
|
|
330
|
+
* return <div>User ID: {userId()}</div>;
|
|
143
331
|
* }
|
|
144
332
|
* ```
|
|
145
333
|
*/
|
|
146
334
|
declare function createUserSignals(): readonly [Accessor<string | null>, (id: string | null) => void];
|
|
335
|
+
/**
|
|
336
|
+
* Create an error tracking function for a specific flag.
|
|
337
|
+
*
|
|
338
|
+
* @param flagKey - The flag key associated with errors
|
|
339
|
+
* @param context - Optional context
|
|
340
|
+
* @returns Error tracking function
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* ```tsx
|
|
344
|
+
* import { createTrackError } from '@savvagent/solid';
|
|
345
|
+
*
|
|
346
|
+
* function FeatureComponent() {
|
|
347
|
+
* const trackError = createTrackError('new-feature');
|
|
348
|
+
*
|
|
349
|
+
* const handleAction = async () => {
|
|
350
|
+
* try {
|
|
351
|
+
* await doSomething();
|
|
352
|
+
* } catch (error) {
|
|
353
|
+
* trackError(error as Error);
|
|
354
|
+
* }
|
|
355
|
+
* };
|
|
356
|
+
*
|
|
357
|
+
* return <button onClick={handleAction}>Try Feature</button>;
|
|
358
|
+
* }
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
declare function createTrackError(flagKey: string, context?: FlagContext): (error: Error) => void;
|
|
147
362
|
/**
|
|
148
363
|
* Track an error with flag context.
|
|
364
|
+
* Direct function call (not reactive).
|
|
149
365
|
*
|
|
150
366
|
* @param flagKey - The flag key associated with the error
|
|
151
367
|
* @param error - The error that occurred
|
|
@@ -170,4 +386,4 @@ declare function createUserSignals(): readonly [Accessor<string | null>, (id: st
|
|
|
170
386
|
*/
|
|
171
387
|
declare function trackError(flagKey: string, error: Error, context?: FlagContext): void;
|
|
172
388
|
|
|
173
|
-
export { type CreateFlagOptions, type CreateFlagReturn, SavvagentProvider, type SavvagentProviderProps, createFlag, createFlagValue, createUserSignals, trackError, useSavvagent };
|
|
389
|
+
export { type CreateEnvironmentReturn, type CreateFlagOptions, type CreateFlagReturn, type CreateFlagsOptions, type CreateFlagsReturn, type CreateUserReturn, type DefaultFlagContext, SavvagentProvider, type SavvagentProviderProps, createEnvironment, createFlag, createFlagValue, createFlags, createTrackError, createUser, createUserSignals, createWithFlag, trackError, useSavvagent };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,39 @@
|
|
|
1
1
|
import * as solid_js from 'solid-js';
|
|
2
2
|
import { ParentProps, Accessor } from 'solid-js';
|
|
3
3
|
import { FlagClientConfig, FlagClient, FlagContext, FlagEvaluationResult } from '@savvagent/sdk';
|
|
4
|
-
export { ApiTypes, ErrorEvent, EvaluationEvent, FlagClient, FlagClientConfig, FlagContext, FlagEvaluationResult, FlagUpdateEvent, components } from '@savvagent/sdk';
|
|
4
|
+
export { ApiTypes, ErrorEvent, EvaluationEvent, FlagClient, FlagClientConfig, FlagContext, FlagDefinition, FlagEvaluationResult, FlagUpdateEvent, components } from '@savvagent/sdk';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Default context values that apply to all flag evaluations
|
|
8
|
+
* Per SDK Developer Guide: https://docs.savvagent.com/sdk-developer-guide
|
|
9
|
+
*/
|
|
10
|
+
interface DefaultFlagContext {
|
|
11
|
+
/** Application ID for application-scoped flags */
|
|
12
|
+
applicationId?: string;
|
|
13
|
+
/** Environment (development, staging, production) */
|
|
14
|
+
environment?: string;
|
|
15
|
+
/** Organization ID for multi-tenant apps */
|
|
16
|
+
organizationId?: string;
|
|
17
|
+
/** Default user ID (required for percentage rollouts) */
|
|
18
|
+
userId?: string;
|
|
19
|
+
/** Default anonymous ID (alternative to userId for anonymous users) */
|
|
20
|
+
anonymousId?: string;
|
|
21
|
+
/** Session ID as fallback identifier */
|
|
22
|
+
sessionId?: string;
|
|
23
|
+
/** User's language code (e.g., "en", "es") */
|
|
24
|
+
language?: string;
|
|
25
|
+
/** Default attributes for targeting */
|
|
26
|
+
attributes?: Record<string, any>;
|
|
27
|
+
}
|
|
28
|
+
interface SavvagentContextValue {
|
|
29
|
+
client: FlagClient;
|
|
30
|
+
isReady: Accessor<boolean>;
|
|
31
|
+
defaultContext: Accessor<FlagContext>;
|
|
32
|
+
}
|
|
6
33
|
interface SavvagentProviderProps extends ParentProps {
|
|
7
34
|
config: FlagClientConfig;
|
|
35
|
+
/** Default context values applied to all flag evaluations */
|
|
36
|
+
defaultContext?: DefaultFlagContext;
|
|
8
37
|
}
|
|
9
38
|
/**
|
|
10
39
|
* Provider component that initializes and provides the Savvagent client.
|
|
@@ -15,7 +44,15 @@ interface SavvagentProviderProps extends ParentProps {
|
|
|
15
44
|
*
|
|
16
45
|
* function App() {
|
|
17
46
|
* return (
|
|
18
|
-
* <SavvagentProvider
|
|
47
|
+
* <SavvagentProvider
|
|
48
|
+
* config={{ apiKey: 'sdk_...' }}
|
|
49
|
+
* defaultContext={{
|
|
50
|
+
* applicationId: 'my-app-id',
|
|
51
|
+
* environment: 'development',
|
|
52
|
+
* userId: 'user-123',
|
|
53
|
+
* attributes: { plan: 'pro' }
|
|
54
|
+
* }}
|
|
55
|
+
* >
|
|
19
56
|
* <MyApp />
|
|
20
57
|
* </SavvagentProvider>
|
|
21
58
|
* );
|
|
@@ -24,10 +61,10 @@ interface SavvagentProviderProps extends ParentProps {
|
|
|
24
61
|
*/
|
|
25
62
|
declare function SavvagentProvider(props: SavvagentProviderProps): solid_js.JSX.Element;
|
|
26
63
|
/**
|
|
27
|
-
* Get the Savvagent client
|
|
64
|
+
* Get the Savvagent context including client, ready state, and default context.
|
|
28
65
|
* Must be used within a SavvagentProvider.
|
|
29
66
|
*
|
|
30
|
-
* @returns The FlagClient instance
|
|
67
|
+
* @returns The FlagClient instance, ready state accessor, and default context accessor
|
|
31
68
|
* @throws Error if used outside of SavvagentProvider
|
|
32
69
|
*
|
|
33
70
|
* @example
|
|
@@ -35,13 +72,17 @@ declare function SavvagentProvider(props: SavvagentProviderProps): solid_js.JSX.
|
|
|
35
72
|
* import { useSavvagent } from '@savvagent/solid';
|
|
36
73
|
*
|
|
37
74
|
* function MyComponent() {
|
|
38
|
-
* const client = useSavvagent();
|
|
39
|
-
*
|
|
40
|
-
* return
|
|
75
|
+
* const { client, isReady, defaultContext } = useSavvagent();
|
|
76
|
+
*
|
|
77
|
+
* return (
|
|
78
|
+
* <Show when={isReady()}>
|
|
79
|
+
* <div>Client ready!</div>
|
|
80
|
+
* </Show>
|
|
81
|
+
* );
|
|
41
82
|
* }
|
|
42
83
|
* ```
|
|
43
84
|
*/
|
|
44
|
-
declare function useSavvagent():
|
|
85
|
+
declare function useSavvagent(): SavvagentContextValue;
|
|
45
86
|
interface CreateFlagOptions {
|
|
46
87
|
/** Context for flag evaluation */
|
|
47
88
|
context?: FlagContext;
|
|
@@ -118,34 +159,209 @@ declare function createFlag(flagKey: string, options?: CreateFlagOptions): Creat
|
|
|
118
159
|
* ```
|
|
119
160
|
*/
|
|
120
161
|
declare function createFlagValue(flagKey: string, options?: CreateFlagOptions): Accessor<boolean>;
|
|
162
|
+
interface CreateFlagsOptions {
|
|
163
|
+
/** Context for flag evaluation */
|
|
164
|
+
context?: FlagContext;
|
|
165
|
+
/** Default values for flags (keyed by flag key) */
|
|
166
|
+
defaultValues?: Record<string, boolean>;
|
|
167
|
+
/** Enable real-time updates */
|
|
168
|
+
realtime?: boolean;
|
|
169
|
+
/** Custom error handler */
|
|
170
|
+
onError?: (error: Error, flagKey: string) => void;
|
|
171
|
+
}
|
|
172
|
+
interface CreateFlagsReturn {
|
|
173
|
+
/** Map of flag keys to their current values */
|
|
174
|
+
values: Accessor<Record<string, boolean>>;
|
|
175
|
+
/** Whether any flag is currently being evaluated */
|
|
176
|
+
loading: Accessor<boolean>;
|
|
177
|
+
/** Map of flag keys to their errors (if any) */
|
|
178
|
+
errors: Accessor<Record<string, Error | null>>;
|
|
179
|
+
/** Map of flag keys to their detailed evaluation results */
|
|
180
|
+
results: Accessor<Record<string, FlagEvaluationResult | null>>;
|
|
181
|
+
/** Force re-evaluation of all flags */
|
|
182
|
+
refetch: () => void;
|
|
183
|
+
}
|
|
121
184
|
/**
|
|
122
|
-
* Create
|
|
185
|
+
* Create reactive flags for multiple flag keys with a single state update.
|
|
186
|
+
* This is more efficient than using multiple createFlag calls when you need
|
|
187
|
+
* several flags in the same component.
|
|
123
188
|
*
|
|
124
|
-
* @
|
|
189
|
+
* @param flagKeys - Array of feature flag keys to evaluate
|
|
190
|
+
* @param options - Configuration options
|
|
191
|
+
* @returns Reactive flag state for all flags
|
|
125
192
|
*
|
|
126
193
|
* @example
|
|
127
194
|
* ```tsx
|
|
128
|
-
* import {
|
|
195
|
+
* import { createFlags } from '@savvagent/solid';
|
|
196
|
+
* import { Show, For } from 'solid-js';
|
|
197
|
+
*
|
|
198
|
+
* function MyComponent() {
|
|
199
|
+
* const flags = createFlags(
|
|
200
|
+
* ['feature-a', 'feature-b', 'feature-c'],
|
|
201
|
+
* {
|
|
202
|
+
* context: { user_id: 'user-123' },
|
|
203
|
+
* defaultValues: { 'feature-a': false, 'feature-b': true },
|
|
204
|
+
* realtime: true
|
|
205
|
+
* }
|
|
206
|
+
* );
|
|
207
|
+
*
|
|
208
|
+
* return (
|
|
209
|
+
* <Show when={!flags.loading()} fallback={<Spinner />}>
|
|
210
|
+
* <div>
|
|
211
|
+
* <Show when={flags.values()['feature-a']}>
|
|
212
|
+
* <FeatureA />
|
|
213
|
+
* </Show>
|
|
214
|
+
* <Show when={flags.values()['feature-b']}>
|
|
215
|
+
* <FeatureB />
|
|
216
|
+
* </Show>
|
|
217
|
+
* </div>
|
|
218
|
+
* </Show>
|
|
219
|
+
* );
|
|
220
|
+
* }
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
declare function createFlags(flagKeys: string[], options?: CreateFlagsOptions): CreateFlagsReturn;
|
|
224
|
+
/**
|
|
225
|
+
* Execute a callback conditionally based on a flag value.
|
|
226
|
+
*
|
|
227
|
+
* @param flagKey - The feature flag key to check
|
|
228
|
+
* @param callback - Function to execute if flag is enabled
|
|
229
|
+
* @param options - Configuration options
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```tsx
|
|
233
|
+
* import { createWithFlag } from '@savvagent/solid';
|
|
234
|
+
*
|
|
235
|
+
* function MyComponent() {
|
|
236
|
+
* createWithFlag('analytics-enabled', async () => {
|
|
237
|
+
* await trackEvent('page_view');
|
|
238
|
+
* });
|
|
239
|
+
*
|
|
240
|
+
* return <div>Content</div>;
|
|
241
|
+
* }
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
declare function createWithFlag(flagKey: string, callback: () => void | Promise<void>, options?: CreateFlagOptions): void;
|
|
245
|
+
interface CreateUserReturn {
|
|
246
|
+
/** Current user ID */
|
|
247
|
+
userId: Accessor<string | null>;
|
|
248
|
+
/** Set user ID */
|
|
249
|
+
setUserId: (id: string | null) => void;
|
|
250
|
+
/** Get current user ID from client */
|
|
251
|
+
getUserId: () => string | null;
|
|
252
|
+
/** Current anonymous ID */
|
|
253
|
+
anonymousId: Accessor<string | null>;
|
|
254
|
+
/** Set anonymous ID */
|
|
255
|
+
setAnonymousId: (id: string) => void;
|
|
256
|
+
/** Get current anonymous ID from client */
|
|
257
|
+
getAnonymousId: () => string | null;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Create signals for user identification management.
|
|
261
|
+
*
|
|
262
|
+
* @returns User ID management functions and reactive signals
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```tsx
|
|
266
|
+
* import { createUser } from '@savvagent/solid';
|
|
129
267
|
* import { createEffect } from 'solid-js';
|
|
130
268
|
*
|
|
131
269
|
* function AuthHandler() {
|
|
132
|
-
* const
|
|
270
|
+
* const user = createUser();
|
|
133
271
|
*
|
|
134
272
|
* createEffect(() => {
|
|
135
273
|
* if (currentUser()) {
|
|
136
|
-
* setUserId(currentUser().id);
|
|
274
|
+
* user.setUserId(currentUser().id);
|
|
137
275
|
* } else {
|
|
138
|
-
* setUserId(null);
|
|
276
|
+
* user.setUserId(null);
|
|
139
277
|
* }
|
|
140
278
|
* });
|
|
141
279
|
*
|
|
142
|
-
* return
|
|
280
|
+
* return <div>User ID: {user.userId()}</div>;
|
|
281
|
+
* }
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
declare function createUser(): CreateUserReturn;
|
|
285
|
+
interface CreateEnvironmentReturn {
|
|
286
|
+
/** Current environment as a reactive signal */
|
|
287
|
+
environment: Accessor<string>;
|
|
288
|
+
/** Set the environment */
|
|
289
|
+
setEnvironment: (env: string) => void;
|
|
290
|
+
/** Get the current environment from client */
|
|
291
|
+
getEnvironment: () => string;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Create signals for environment management.
|
|
295
|
+
*
|
|
296
|
+
* @returns Environment management functions and reactive signal
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```tsx
|
|
300
|
+
* import { createEnvironment } from '@savvagent/solid';
|
|
301
|
+
*
|
|
302
|
+
* function EnvironmentSwitcher() {
|
|
303
|
+
* const { environment, setEnvironment } = createEnvironment();
|
|
304
|
+
*
|
|
305
|
+
* return (
|
|
306
|
+
* <select value={environment()} onChange={(e) => setEnvironment(e.target.value)}>
|
|
307
|
+
* <option value="development">Development</option>
|
|
308
|
+
* <option value="staging">Staging</option>
|
|
309
|
+
* <option value="production">Production</option>
|
|
310
|
+
* </select>
|
|
311
|
+
* );
|
|
312
|
+
* }
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
declare function createEnvironment(): CreateEnvironmentReturn;
|
|
316
|
+
/**
|
|
317
|
+
* Legacy function - use createUser() instead.
|
|
318
|
+
* Create signals for user identification.
|
|
319
|
+
*
|
|
320
|
+
* @returns User ID signal tuple [userId, setUserId]
|
|
321
|
+
* @deprecated Use createUser() for full user management
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```tsx
|
|
325
|
+
* import { createUserSignals } from '@savvagent/solid';
|
|
326
|
+
*
|
|
327
|
+
* function AuthHandler() {
|
|
328
|
+
* const [userId, setUserId] = createUserSignals();
|
|
329
|
+
*
|
|
330
|
+
* return <div>User ID: {userId()}</div>;
|
|
143
331
|
* }
|
|
144
332
|
* ```
|
|
145
333
|
*/
|
|
146
334
|
declare function createUserSignals(): readonly [Accessor<string | null>, (id: string | null) => void];
|
|
335
|
+
/**
|
|
336
|
+
* Create an error tracking function for a specific flag.
|
|
337
|
+
*
|
|
338
|
+
* @param flagKey - The flag key associated with errors
|
|
339
|
+
* @param context - Optional context
|
|
340
|
+
* @returns Error tracking function
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* ```tsx
|
|
344
|
+
* import { createTrackError } from '@savvagent/solid';
|
|
345
|
+
*
|
|
346
|
+
* function FeatureComponent() {
|
|
347
|
+
* const trackError = createTrackError('new-feature');
|
|
348
|
+
*
|
|
349
|
+
* const handleAction = async () => {
|
|
350
|
+
* try {
|
|
351
|
+
* await doSomething();
|
|
352
|
+
* } catch (error) {
|
|
353
|
+
* trackError(error as Error);
|
|
354
|
+
* }
|
|
355
|
+
* };
|
|
356
|
+
*
|
|
357
|
+
* return <button onClick={handleAction}>Try Feature</button>;
|
|
358
|
+
* }
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
declare function createTrackError(flagKey: string, context?: FlagContext): (error: Error) => void;
|
|
147
362
|
/**
|
|
148
363
|
* Track an error with flag context.
|
|
364
|
+
* Direct function call (not reactive).
|
|
149
365
|
*
|
|
150
366
|
* @param flagKey - The flag key associated with the error
|
|
151
367
|
* @param error - The error that occurred
|
|
@@ -170,4 +386,4 @@ declare function createUserSignals(): readonly [Accessor<string | null>, (id: st
|
|
|
170
386
|
*/
|
|
171
387
|
declare function trackError(flagKey: string, error: Error, context?: FlagContext): void;
|
|
172
388
|
|
|
173
|
-
export { type CreateFlagOptions, type CreateFlagReturn, SavvagentProvider, type SavvagentProviderProps, createFlag, createFlagValue, createUserSignals, trackError, useSavvagent };
|
|
389
|
+
export { type CreateEnvironmentReturn, type CreateFlagOptions, type CreateFlagReturn, type CreateFlagsOptions, type CreateFlagsReturn, type CreateUserReturn, type DefaultFlagContext, SavvagentProvider, type SavvagentProviderProps, createEnvironment, createFlag, createFlagValue, createFlags, createTrackError, createUser, createUserSignals, createWithFlag, trackError, useSavvagent };
|