@grafana-experiments/sdk 0.0.0 → 0.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/LICENSE +201 -0
- package/README.md +339 -0
- package/RELEASING.md +36 -0
- package/dist/chunk-W7444I4G.js +792 -0
- package/dist/grafana.cjs +852 -0
- package/dist/grafana.d.cts +22 -0
- package/dist/grafana.d.ts +22 -0
- package/dist/grafana.js +49 -0
- package/dist/index.cjs +846 -0
- package/dist/index.d.cts +35 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +26 -0
- package/dist/react.cjs +63 -0
- package/dist/react.d.cts +14 -0
- package/dist/react.d.ts +14 -0
- package/dist/react.js +36 -0
- package/dist/types-M9Kqiiqw.d.cts +171 -0
- package/dist/types-M9Kqiiqw.d.ts +171 -0
- package/package.json +73 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { E as ExperimentsOptions, a as ExperimentConfig, b as ExperimentDefinition, c as Experiment, P as Properties, R as ReportOptions, J as Journey, d as EventManifest, D as Diagnostic, A as Assignment } from './types-M9Kqiiqw.cjs';
|
|
2
|
+
import '@grafana/faro-web-sdk';
|
|
3
|
+
import '@openfeature/web-sdk';
|
|
4
|
+
|
|
5
|
+
type GrafanaExperimentsOptions = Omit<ExperimentsOptions, 'client' | 'reportAnalytics' | 'reportExposure'> & {
|
|
6
|
+
domain: string;
|
|
7
|
+
};
|
|
8
|
+
declare function createGrafanaExperiments(options: GrafanaExperimentsOptions): {
|
|
9
|
+
dispose(): void;
|
|
10
|
+
ready: Promise<void>;
|
|
11
|
+
defineExperiment: <T extends ExperimentConfig = ExperimentConfig>(definition: ExperimentDefinition<T>) => Experiment<T>;
|
|
12
|
+
reportAnalytics: (name: string, properties?: Properties, options?: ReportOptions) => void;
|
|
13
|
+
refreshSession: () => void;
|
|
14
|
+
resetContext: (contextKey: string) => void;
|
|
15
|
+
beginJourney: () => Journey;
|
|
16
|
+
getEventManifest: () => EventManifest;
|
|
17
|
+
getDiagnostics: () => readonly Diagnostic[];
|
|
18
|
+
subscribeDiagnostics: (listener: (diagnostic: Diagnostic) => void) => () => void;
|
|
19
|
+
getActiveAssignments: () => readonly Assignment[];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { type GrafanaExperimentsOptions, createGrafanaExperiments };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { E as ExperimentsOptions, a as ExperimentConfig, b as ExperimentDefinition, c as Experiment, P as Properties, R as ReportOptions, J as Journey, d as EventManifest, D as Diagnostic, A as Assignment } from './types-M9Kqiiqw.js';
|
|
2
|
+
import '@grafana/faro-web-sdk';
|
|
3
|
+
import '@openfeature/web-sdk';
|
|
4
|
+
|
|
5
|
+
type GrafanaExperimentsOptions = Omit<ExperimentsOptions, 'client' | 'reportAnalytics' | 'reportExposure'> & {
|
|
6
|
+
domain: string;
|
|
7
|
+
};
|
|
8
|
+
declare function createGrafanaExperiments(options: GrafanaExperimentsOptions): {
|
|
9
|
+
dispose(): void;
|
|
10
|
+
ready: Promise<void>;
|
|
11
|
+
defineExperiment: <T extends ExperimentConfig = ExperimentConfig>(definition: ExperimentDefinition<T>) => Experiment<T>;
|
|
12
|
+
reportAnalytics: (name: string, properties?: Properties, options?: ReportOptions) => void;
|
|
13
|
+
refreshSession: () => void;
|
|
14
|
+
resetContext: (contextKey: string) => void;
|
|
15
|
+
beginJourney: () => Journey;
|
|
16
|
+
getEventManifest: () => EventManifest;
|
|
17
|
+
getDiagnostics: () => readonly Diagnostic[];
|
|
18
|
+
subscribeDiagnostics: (listener: (diagnostic: Diagnostic) => void) => () => void;
|
|
19
|
+
getActiveAssignments: () => readonly Assignment[];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { type GrafanaExperimentsOptions, createGrafanaExperiments };
|
package/dist/grafana.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createExperiments
|
|
3
|
+
} from "./chunk-W7444I4G.js";
|
|
4
|
+
|
|
5
|
+
// src/grafana.ts
|
|
6
|
+
import {
|
|
7
|
+
createOpenFeatureLocalStorageProvider,
|
|
8
|
+
createOpenFeatureOFREPWebProvider,
|
|
9
|
+
reportExperimentView,
|
|
10
|
+
reportInteraction
|
|
11
|
+
} from "@grafana/runtime";
|
|
12
|
+
import { MultiProvider, OpenFeature, NOOP_PROVIDER } from "@openfeature/web-sdk";
|
|
13
|
+
var releasedDomains = /* @__PURE__ */ new Set();
|
|
14
|
+
function createGrafanaExperiments(options) {
|
|
15
|
+
const { domain } = options;
|
|
16
|
+
if (!domain.trim()) {
|
|
17
|
+
throw new Error("An isolated OpenFeature domain is required");
|
|
18
|
+
}
|
|
19
|
+
const existing = OpenFeature.getProvider(domain);
|
|
20
|
+
if (existing !== OpenFeature.getProvider() && !(existing === NOOP_PROVIDER && releasedDomains.has(domain))) {
|
|
21
|
+
throw new Error(`OpenFeature domain is already registered: ${domain}`);
|
|
22
|
+
}
|
|
23
|
+
const provider = new MultiProvider([
|
|
24
|
+
{ provider: createOpenFeatureLocalStorageProvider() },
|
|
25
|
+
{ provider: createOpenFeatureOFREPWebProvider() }
|
|
26
|
+
]);
|
|
27
|
+
OpenFeature.setProvider(domain, provider);
|
|
28
|
+
releasedDomains.delete(domain);
|
|
29
|
+
const sdk = createExperiments({
|
|
30
|
+
...options,
|
|
31
|
+
client: OpenFeature.getClient(domain),
|
|
32
|
+
reportAnalytics: reportInteraction,
|
|
33
|
+
reportExposure: (assignment) => reportExperimentView(assignment.experiment_id, assignment.experiment_group, assignment.variant)
|
|
34
|
+
});
|
|
35
|
+
const dispose = sdk.dispose;
|
|
36
|
+
return {
|
|
37
|
+
...sdk,
|
|
38
|
+
dispose() {
|
|
39
|
+
dispose();
|
|
40
|
+
if (OpenFeature.getProvider(domain) === provider) {
|
|
41
|
+
OpenFeature.setProvider(domain, NOOP_PROVIDER);
|
|
42
|
+
releasedDomains.add(domain);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
createGrafanaExperiments
|
|
49
|
+
};
|