flagsmith-toolbar 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +98 -2
- package/dist/index.cjs +3002 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +149 -0
- package/dist/index.d.ts +149 -0
- package/dist/index.global.js +391 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +2969 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
type FlagValue = string | number | boolean | null;
|
|
2
|
+
/** A flag as the Flagsmith JS SDK stores it. */
|
|
3
|
+
interface ToolbarFlag {
|
|
4
|
+
id?: number;
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
value: FlagValue;
|
|
7
|
+
variant?: string;
|
|
8
|
+
/** Why the flag has this value, e.g. "TARGETING_MATCH; segment=Pro members". Flagsmith 2.295+. */
|
|
9
|
+
reason?: string;
|
|
10
|
+
experiment?: {
|
|
11
|
+
id: number;
|
|
12
|
+
name: string;
|
|
13
|
+
inExperiment: boolean;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
type FlagMap = Record<string, ToolbarFlag>;
|
|
17
|
+
/** A change made in the toolbar. Only the fields that are set replace the real flag. */
|
|
18
|
+
interface FlagOverride {
|
|
19
|
+
enabled?: boolean;
|
|
20
|
+
value?: FlagValue;
|
|
21
|
+
}
|
|
22
|
+
type Overrides = Record<string, FlagOverride>;
|
|
23
|
+
type TraitValue = string | number | boolean;
|
|
24
|
+
/** A user to preview the app as. */
|
|
25
|
+
interface Persona {
|
|
26
|
+
/** Shown in the toolbar, e.g. "Priya · Pro member · India". */
|
|
27
|
+
name: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
/**
|
|
30
|
+
* A real identity in Flagsmith. Its identity overrides apply.
|
|
31
|
+
* Leave it out to preview a temporary user that Flagsmith never saves.
|
|
32
|
+
*/
|
|
33
|
+
identifier?: string;
|
|
34
|
+
/** Traits to evaluate with. They are sent as transient, so they are never saved. */
|
|
35
|
+
traits?: Record<string, TraitValue>;
|
|
36
|
+
}
|
|
37
|
+
interface ToolbarOptions {
|
|
38
|
+
/** Set to false to turn the toolbar off, for example in production. Defaults to true. */
|
|
39
|
+
enabled?: boolean;
|
|
40
|
+
/** Ready-made users for the "View as" tab. */
|
|
41
|
+
personas?: Persona[];
|
|
42
|
+
/** Your Flagsmith dashboard URL, used for "Open in Flagsmith" links. */
|
|
43
|
+
dashboardUrl?: string;
|
|
44
|
+
/** Your Flagsmith project ID, used for "Open in Flagsmith" links. */
|
|
45
|
+
projectId?: string | number;
|
|
46
|
+
/** Keyboard shortcut that opens and closes the toolbar. Defaults to "shift+f". */
|
|
47
|
+
hotkey?: string;
|
|
48
|
+
/** Open the panel straight away. Defaults to false. */
|
|
49
|
+
open?: boolean;
|
|
50
|
+
/** Which side of the screen the toolbar sits on. Defaults to "right". */
|
|
51
|
+
position?: 'right' | 'left';
|
|
52
|
+
/**
|
|
53
|
+
* "overlay" (default) floats the panel over the page. "push" makes room for it on
|
|
54
|
+
* wide screens, so the panel never covers the page you're testing.
|
|
55
|
+
*/
|
|
56
|
+
layout?: 'overlay' | 'push';
|
|
57
|
+
/** localStorage key for the toolbar's saved state. Defaults to "flagsmith-toolbar". */
|
|
58
|
+
storageKey?: string;
|
|
59
|
+
}
|
|
60
|
+
/** The SDK's loading state (`flagsmith.loadingState`). */
|
|
61
|
+
interface LoadingStateLike {
|
|
62
|
+
isLoading?: boolean;
|
|
63
|
+
isFetching?: boolean;
|
|
64
|
+
error?: unknown;
|
|
65
|
+
/** Where the current flags came from: "NONE", "DEFAULT_FLAGS", "CACHE" or "SERVER". */
|
|
66
|
+
source?: string;
|
|
67
|
+
}
|
|
68
|
+
interface TraitContext {
|
|
69
|
+
value: unknown;
|
|
70
|
+
transient?: boolean;
|
|
71
|
+
}
|
|
72
|
+
interface IdentityContext {
|
|
73
|
+
identifier?: string | null;
|
|
74
|
+
transient?: boolean | null;
|
|
75
|
+
traits?: Record<string, TraitContext | null> | null;
|
|
76
|
+
[key: string]: unknown;
|
|
77
|
+
}
|
|
78
|
+
interface EvaluationContextLike {
|
|
79
|
+
environment?: {
|
|
80
|
+
apiKey: string;
|
|
81
|
+
[key: string]: unknown;
|
|
82
|
+
} | null;
|
|
83
|
+
identity?: IdentityContext | null;
|
|
84
|
+
[key: string]: unknown;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The parts of a Flagsmith JS SDK instance (`@flagsmith/flagsmith`) the toolbar uses.
|
|
88
|
+
* Declared structurally so the toolbar works with any compatible instance.
|
|
89
|
+
*/
|
|
90
|
+
interface FlagsmithLike {
|
|
91
|
+
api?: string | null;
|
|
92
|
+
identity?: string | null;
|
|
93
|
+
initialised?: boolean;
|
|
94
|
+
loadingState?: LoadingStateLike | null;
|
|
95
|
+
/** Extra request headers the app configured, reused when comparing users. */
|
|
96
|
+
headers?: Record<string, string> | null;
|
|
97
|
+
/** Fetches the latest flags from Flagsmith. */
|
|
98
|
+
getFlags?(): Promise<unknown>;
|
|
99
|
+
/** True when the SDK was started with enableEvents and sends Experimentation events. */
|
|
100
|
+
readonly eventsEnabled?: boolean;
|
|
101
|
+
getAllFlags(): FlagMap | null | undefined;
|
|
102
|
+
hasFeature(key: string, options?: any): boolean;
|
|
103
|
+
getValue(key: string, options?: any, skipAnalytics?: boolean): any;
|
|
104
|
+
getContext(): EvaluationContextLike;
|
|
105
|
+
setContext(context: any): Promise<void>;
|
|
106
|
+
trackEvent?(event: string, opts?: any): void;
|
|
107
|
+
trackExposureEvent?(featureName: string, opts?: any): void;
|
|
108
|
+
getExperimentFlag?(featureName: string): unknown;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
type ReasonKind = 'static' | 'default' | 'segment' | 'identity' | 'split' | 'experiment' | 'override' | 'error' | 'missing' | 'other';
|
|
112
|
+
interface Explanation {
|
|
113
|
+
kind: ReasonKind;
|
|
114
|
+
/** A few words for a badge, e.g. "Segment: Pro members". */
|
|
115
|
+
label: string;
|
|
116
|
+
/** One plain sentence for the details view. */
|
|
117
|
+
detail: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Splits a Flagsmith reason such as "TARGETING_MATCH; segment=Pro members"
|
|
121
|
+
* into its code and parameters.
|
|
122
|
+
*/
|
|
123
|
+
declare function parseReason(raw: string | null | undefined): {
|
|
124
|
+
code: string;
|
|
125
|
+
params: Record<string, string>;
|
|
126
|
+
};
|
|
127
|
+
/** Explains, in plain words, why a flag has its value. */
|
|
128
|
+
declare function explainReason(raw: string | null | undefined): Explanation;
|
|
129
|
+
|
|
130
|
+
/** Attaches the toolbar to a Flagsmith SDK instance. Call it before or after flagsmith.init(). */
|
|
131
|
+
declare function init(flagsmith: FlagsmithLike, options?: ToolbarOptions): void;
|
|
132
|
+
/** Opens the toolbar panel. */
|
|
133
|
+
declare function show(): void;
|
|
134
|
+
/** Closes the toolbar panel. The launcher button stays. */
|
|
135
|
+
declare function hide(): void;
|
|
136
|
+
declare function toggle(): void;
|
|
137
|
+
/** Removes the toolbar and puts the SDK back exactly as it was. */
|
|
138
|
+
declare function destroy(): void;
|
|
139
|
+
|
|
140
|
+
declare const FlagsmithToolbar: {
|
|
141
|
+
init: typeof init;
|
|
142
|
+
show: typeof show;
|
|
143
|
+
hide: typeof hide;
|
|
144
|
+
toggle: typeof toggle;
|
|
145
|
+
destroy: typeof destroy;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export { FlagsmithToolbar as default, destroy, explainReason, hide, init, parseReason, show, toggle };
|
|
149
|
+
export type { Explanation, FlagMap, FlagOverride, FlagValue, FlagsmithLike, Overrides, Persona, ReasonKind, ToolbarFlag, ToolbarOptions, TraitValue };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
type FlagValue = string | number | boolean | null;
|
|
2
|
+
/** A flag as the Flagsmith JS SDK stores it. */
|
|
3
|
+
interface ToolbarFlag {
|
|
4
|
+
id?: number;
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
value: FlagValue;
|
|
7
|
+
variant?: string;
|
|
8
|
+
/** Why the flag has this value, e.g. "TARGETING_MATCH; segment=Pro members". Flagsmith 2.295+. */
|
|
9
|
+
reason?: string;
|
|
10
|
+
experiment?: {
|
|
11
|
+
id: number;
|
|
12
|
+
name: string;
|
|
13
|
+
inExperiment: boolean;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
type FlagMap = Record<string, ToolbarFlag>;
|
|
17
|
+
/** A change made in the toolbar. Only the fields that are set replace the real flag. */
|
|
18
|
+
interface FlagOverride {
|
|
19
|
+
enabled?: boolean;
|
|
20
|
+
value?: FlagValue;
|
|
21
|
+
}
|
|
22
|
+
type Overrides = Record<string, FlagOverride>;
|
|
23
|
+
type TraitValue = string | number | boolean;
|
|
24
|
+
/** A user to preview the app as. */
|
|
25
|
+
interface Persona {
|
|
26
|
+
/** Shown in the toolbar, e.g. "Priya · Pro member · India". */
|
|
27
|
+
name: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
/**
|
|
30
|
+
* A real identity in Flagsmith. Its identity overrides apply.
|
|
31
|
+
* Leave it out to preview a temporary user that Flagsmith never saves.
|
|
32
|
+
*/
|
|
33
|
+
identifier?: string;
|
|
34
|
+
/** Traits to evaluate with. They are sent as transient, so they are never saved. */
|
|
35
|
+
traits?: Record<string, TraitValue>;
|
|
36
|
+
}
|
|
37
|
+
interface ToolbarOptions {
|
|
38
|
+
/** Set to false to turn the toolbar off, for example in production. Defaults to true. */
|
|
39
|
+
enabled?: boolean;
|
|
40
|
+
/** Ready-made users for the "View as" tab. */
|
|
41
|
+
personas?: Persona[];
|
|
42
|
+
/** Your Flagsmith dashboard URL, used for "Open in Flagsmith" links. */
|
|
43
|
+
dashboardUrl?: string;
|
|
44
|
+
/** Your Flagsmith project ID, used for "Open in Flagsmith" links. */
|
|
45
|
+
projectId?: string | number;
|
|
46
|
+
/** Keyboard shortcut that opens and closes the toolbar. Defaults to "shift+f". */
|
|
47
|
+
hotkey?: string;
|
|
48
|
+
/** Open the panel straight away. Defaults to false. */
|
|
49
|
+
open?: boolean;
|
|
50
|
+
/** Which side of the screen the toolbar sits on. Defaults to "right". */
|
|
51
|
+
position?: 'right' | 'left';
|
|
52
|
+
/**
|
|
53
|
+
* "overlay" (default) floats the panel over the page. "push" makes room for it on
|
|
54
|
+
* wide screens, so the panel never covers the page you're testing.
|
|
55
|
+
*/
|
|
56
|
+
layout?: 'overlay' | 'push';
|
|
57
|
+
/** localStorage key for the toolbar's saved state. Defaults to "flagsmith-toolbar". */
|
|
58
|
+
storageKey?: string;
|
|
59
|
+
}
|
|
60
|
+
/** The SDK's loading state (`flagsmith.loadingState`). */
|
|
61
|
+
interface LoadingStateLike {
|
|
62
|
+
isLoading?: boolean;
|
|
63
|
+
isFetching?: boolean;
|
|
64
|
+
error?: unknown;
|
|
65
|
+
/** Where the current flags came from: "NONE", "DEFAULT_FLAGS", "CACHE" or "SERVER". */
|
|
66
|
+
source?: string;
|
|
67
|
+
}
|
|
68
|
+
interface TraitContext {
|
|
69
|
+
value: unknown;
|
|
70
|
+
transient?: boolean;
|
|
71
|
+
}
|
|
72
|
+
interface IdentityContext {
|
|
73
|
+
identifier?: string | null;
|
|
74
|
+
transient?: boolean | null;
|
|
75
|
+
traits?: Record<string, TraitContext | null> | null;
|
|
76
|
+
[key: string]: unknown;
|
|
77
|
+
}
|
|
78
|
+
interface EvaluationContextLike {
|
|
79
|
+
environment?: {
|
|
80
|
+
apiKey: string;
|
|
81
|
+
[key: string]: unknown;
|
|
82
|
+
} | null;
|
|
83
|
+
identity?: IdentityContext | null;
|
|
84
|
+
[key: string]: unknown;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The parts of a Flagsmith JS SDK instance (`@flagsmith/flagsmith`) the toolbar uses.
|
|
88
|
+
* Declared structurally so the toolbar works with any compatible instance.
|
|
89
|
+
*/
|
|
90
|
+
interface FlagsmithLike {
|
|
91
|
+
api?: string | null;
|
|
92
|
+
identity?: string | null;
|
|
93
|
+
initialised?: boolean;
|
|
94
|
+
loadingState?: LoadingStateLike | null;
|
|
95
|
+
/** Extra request headers the app configured, reused when comparing users. */
|
|
96
|
+
headers?: Record<string, string> | null;
|
|
97
|
+
/** Fetches the latest flags from Flagsmith. */
|
|
98
|
+
getFlags?(): Promise<unknown>;
|
|
99
|
+
/** True when the SDK was started with enableEvents and sends Experimentation events. */
|
|
100
|
+
readonly eventsEnabled?: boolean;
|
|
101
|
+
getAllFlags(): FlagMap | null | undefined;
|
|
102
|
+
hasFeature(key: string, options?: any): boolean;
|
|
103
|
+
getValue(key: string, options?: any, skipAnalytics?: boolean): any;
|
|
104
|
+
getContext(): EvaluationContextLike;
|
|
105
|
+
setContext(context: any): Promise<void>;
|
|
106
|
+
trackEvent?(event: string, opts?: any): void;
|
|
107
|
+
trackExposureEvent?(featureName: string, opts?: any): void;
|
|
108
|
+
getExperimentFlag?(featureName: string): unknown;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
type ReasonKind = 'static' | 'default' | 'segment' | 'identity' | 'split' | 'experiment' | 'override' | 'error' | 'missing' | 'other';
|
|
112
|
+
interface Explanation {
|
|
113
|
+
kind: ReasonKind;
|
|
114
|
+
/** A few words for a badge, e.g. "Segment: Pro members". */
|
|
115
|
+
label: string;
|
|
116
|
+
/** One plain sentence for the details view. */
|
|
117
|
+
detail: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Splits a Flagsmith reason such as "TARGETING_MATCH; segment=Pro members"
|
|
121
|
+
* into its code and parameters.
|
|
122
|
+
*/
|
|
123
|
+
declare function parseReason(raw: string | null | undefined): {
|
|
124
|
+
code: string;
|
|
125
|
+
params: Record<string, string>;
|
|
126
|
+
};
|
|
127
|
+
/** Explains, in plain words, why a flag has its value. */
|
|
128
|
+
declare function explainReason(raw: string | null | undefined): Explanation;
|
|
129
|
+
|
|
130
|
+
/** Attaches the toolbar to a Flagsmith SDK instance. Call it before or after flagsmith.init(). */
|
|
131
|
+
declare function init(flagsmith: FlagsmithLike, options?: ToolbarOptions): void;
|
|
132
|
+
/** Opens the toolbar panel. */
|
|
133
|
+
declare function show(): void;
|
|
134
|
+
/** Closes the toolbar panel. The launcher button stays. */
|
|
135
|
+
declare function hide(): void;
|
|
136
|
+
declare function toggle(): void;
|
|
137
|
+
/** Removes the toolbar and puts the SDK back exactly as it was. */
|
|
138
|
+
declare function destroy(): void;
|
|
139
|
+
|
|
140
|
+
declare const FlagsmithToolbar: {
|
|
141
|
+
init: typeof init;
|
|
142
|
+
show: typeof show;
|
|
143
|
+
hide: typeof hide;
|
|
144
|
+
toggle: typeof toggle;
|
|
145
|
+
destroy: typeof destroy;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export { FlagsmithToolbar as default, destroy, explainReason, hide, init, parseReason, show, toggle };
|
|
149
|
+
export type { Explanation, FlagMap, FlagOverride, FlagValue, FlagsmithLike, Overrides, Persona, ReasonKind, ToolbarFlag, ToolbarOptions, TraitValue };
|