@flagix/js-sdk 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/.turbo/turbo-build.log +19 -0
- package/CHANGELOG.md +12 -0
- package/dist/index.d.mts +68 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.js +561 -0
- package/dist/index.mjs +524 -0
- package/package.json +46 -0
- package/src/client.ts +482 -0
- package/src/index.ts +139 -0
- package/src/lib/constants.ts +12 -0
- package/src/lib/emitter.ts +10 -0
- package/src/lib/logger.ts +41 -0
- package/src/sse/create-event-source.ts +33 -0
- package/src/types.ts +22 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
> @flagix/js-sdk@1.1.0 build /home/runner/work/flagixx/flagixx/sdk/javascript
|
|
3
|
+
> tsup src/index.ts --format cjs,esm --dts --clean
|
|
4
|
+
|
|
5
|
+
[34mCLI[39m Building entry: src/index.ts
|
|
6
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
+
[34mCLI[39m tsup v8.5.1
|
|
8
|
+
[34mCLI[39m Target: es2020
|
|
9
|
+
[34mCLI[39m Cleaning output folder
|
|
10
|
+
[34mCJS[39m Build start
|
|
11
|
+
[34mESM[39m Build start
|
|
12
|
+
[32mCJS[39m [1mdist/index.js [22m[32m17.16 KB[39m
|
|
13
|
+
[32mCJS[39m ⚡️ Build success in 49ms
|
|
14
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m15.47 KB[39m
|
|
15
|
+
[32mESM[39m ⚡️ Build success in 49ms
|
|
16
|
+
[34mDTS[39m Build start
|
|
17
|
+
[32mDTS[39m ⚡️ Build success in 1843ms
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m2.30 KB[39m
|
|
19
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m2.30 KB[39m
|
package/CHANGELOG.md
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { EvaluationContext, VariationValue } from '@flagix/evaluation-core';
|
|
2
|
+
export { EvaluationContext, FlagConfig, FlagVariation, VariationValue } from '@flagix/evaluation-core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 'info' is for detailed debugging information
|
|
6
|
+
* 'warn' is for non-critical issues
|
|
7
|
+
* 'error' is for critical failures
|
|
8
|
+
* 'none' suppresses all output.
|
|
9
|
+
*/
|
|
10
|
+
type LogLevel = "none" | "error" | "warn" | "info";
|
|
11
|
+
|
|
12
|
+
type FlagixClientOptions = {
|
|
13
|
+
/** The API Key for the environment */
|
|
14
|
+
apiKey: string;
|
|
15
|
+
/** The base URL for the flag evaluation API */
|
|
16
|
+
apiBaseUrl: string;
|
|
17
|
+
/** Optional context attributes */
|
|
18
|
+
initialContext?: EvaluationContext;
|
|
19
|
+
/** Enable SDK logging */
|
|
20
|
+
logs?: {
|
|
21
|
+
level?: LogLevel;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
declare const Flagix: {
|
|
26
|
+
/**
|
|
27
|
+
* Initializes the Flagix SDK, fetches all flags, and sets up an SSE connection.
|
|
28
|
+
*/
|
|
29
|
+
initialize(options: FlagixClientOptions): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Evaluates a flag based on the local cache and current context.
|
|
32
|
+
* @param flagKey The key of the flag to evaluate.
|
|
33
|
+
* @param contextOverrides Optional, temporary context overrides.
|
|
34
|
+
*/
|
|
35
|
+
evaluate<T extends VariationValue>(flagKey: string, contextOverrides?: EvaluationContext): T | null;
|
|
36
|
+
/**
|
|
37
|
+
* Records a custom event for analytics.
|
|
38
|
+
* @param eventName The name of the event.
|
|
39
|
+
* @param properties Optional custom metadata.
|
|
40
|
+
* @param contextOverrides Optional context.
|
|
41
|
+
*/
|
|
42
|
+
track(eventName: string, properties?: Record<string, unknown>, contextOverrides?: EvaluationContext): void;
|
|
43
|
+
/**
|
|
44
|
+
* Sets or updates the global evaluation context.
|
|
45
|
+
* @param newContext New context attributes to merge or replace.
|
|
46
|
+
*/
|
|
47
|
+
setContext(newContext: EvaluationContext): void;
|
|
48
|
+
/**
|
|
49
|
+
* Closes the SSE connection and cleans up resources.
|
|
50
|
+
*/
|
|
51
|
+
close(): void;
|
|
52
|
+
/**
|
|
53
|
+
* checks initialization status
|
|
54
|
+
*/
|
|
55
|
+
isInitialized(): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Subscribes a listener to updates for any flag.
|
|
58
|
+
* @param listener The callback function (receives the updated flagKey).
|
|
59
|
+
*/
|
|
60
|
+
onFlagUpdate(listener: (flagKey: string) => void): void;
|
|
61
|
+
/**
|
|
62
|
+
* Unsubscribes a listener from flag updates.
|
|
63
|
+
* @param listener The callback function to remove.
|
|
64
|
+
*/
|
|
65
|
+
offFlagUpdate(listener: (flagKey: string) => void): void;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export { Flagix, type FlagixClientOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { EvaluationContext, VariationValue } from '@flagix/evaluation-core';
|
|
2
|
+
export { EvaluationContext, FlagConfig, FlagVariation, VariationValue } from '@flagix/evaluation-core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 'info' is for detailed debugging information
|
|
6
|
+
* 'warn' is for non-critical issues
|
|
7
|
+
* 'error' is for critical failures
|
|
8
|
+
* 'none' suppresses all output.
|
|
9
|
+
*/
|
|
10
|
+
type LogLevel = "none" | "error" | "warn" | "info";
|
|
11
|
+
|
|
12
|
+
type FlagixClientOptions = {
|
|
13
|
+
/** The API Key for the environment */
|
|
14
|
+
apiKey: string;
|
|
15
|
+
/** The base URL for the flag evaluation API */
|
|
16
|
+
apiBaseUrl: string;
|
|
17
|
+
/** Optional context attributes */
|
|
18
|
+
initialContext?: EvaluationContext;
|
|
19
|
+
/** Enable SDK logging */
|
|
20
|
+
logs?: {
|
|
21
|
+
level?: LogLevel;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
declare const Flagix: {
|
|
26
|
+
/**
|
|
27
|
+
* Initializes the Flagix SDK, fetches all flags, and sets up an SSE connection.
|
|
28
|
+
*/
|
|
29
|
+
initialize(options: FlagixClientOptions): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Evaluates a flag based on the local cache and current context.
|
|
32
|
+
* @param flagKey The key of the flag to evaluate.
|
|
33
|
+
* @param contextOverrides Optional, temporary context overrides.
|
|
34
|
+
*/
|
|
35
|
+
evaluate<T extends VariationValue>(flagKey: string, contextOverrides?: EvaluationContext): T | null;
|
|
36
|
+
/**
|
|
37
|
+
* Records a custom event for analytics.
|
|
38
|
+
* @param eventName The name of the event.
|
|
39
|
+
* @param properties Optional custom metadata.
|
|
40
|
+
* @param contextOverrides Optional context.
|
|
41
|
+
*/
|
|
42
|
+
track(eventName: string, properties?: Record<string, unknown>, contextOverrides?: EvaluationContext): void;
|
|
43
|
+
/**
|
|
44
|
+
* Sets or updates the global evaluation context.
|
|
45
|
+
* @param newContext New context attributes to merge or replace.
|
|
46
|
+
*/
|
|
47
|
+
setContext(newContext: EvaluationContext): void;
|
|
48
|
+
/**
|
|
49
|
+
* Closes the SSE connection and cleans up resources.
|
|
50
|
+
*/
|
|
51
|
+
close(): void;
|
|
52
|
+
/**
|
|
53
|
+
* checks initialization status
|
|
54
|
+
*/
|
|
55
|
+
isInitialized(): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Subscribes a listener to updates for any flag.
|
|
58
|
+
* @param listener The callback function (receives the updated flagKey).
|
|
59
|
+
*/
|
|
60
|
+
onFlagUpdate(listener: (flagKey: string) => void): void;
|
|
61
|
+
/**
|
|
62
|
+
* Unsubscribes a listener from flag updates.
|
|
63
|
+
* @param listener The callback function to remove.
|
|
64
|
+
*/
|
|
65
|
+
offFlagUpdate(listener: (flagKey: string) => void): void;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export { Flagix, type FlagixClientOptions };
|