@clickroom/sdk-js 0.2.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 +106 -0
- package/dist/__tests__/channel.test.d.ts +1 -0
- package/dist/__tests__/device.test.d.ts +1 -0
- package/dist/__tests__/exposure.test.d.ts +1 -0
- package/dist/__tests__/flag-polling.test.d.ts +1 -0
- package/dist/__tests__/flags.test.d.ts +1 -0
- package/dist/__tests__/identify.test.d.ts +1 -0
- package/dist/__tests__/session.test.d.ts +1 -0
- package/dist/__tests__/transport.test.d.ts +1 -0
- package/dist/__tests__/utm.test.d.ts +1 -0
- package/dist/autocapture.d.ts +7 -0
- package/dist/channel.d.ts +11 -0
- package/dist/clickroom.js +2 -0
- package/dist/clickroom.js.map +7 -0
- package/dist/device.d.ts +5 -0
- package/dist/elements-chain.d.ts +13 -0
- package/dist/eval.d.ts +3 -0
- package/dist/eval.js +151 -0
- package/dist/eval.js.map +7 -0
- package/dist/flags.d.ts +74 -0
- package/dist/global.d.ts +7 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +1004 -0
- package/dist/index.js.map +7 -0
- package/dist/loader.min.js +2 -0
- package/dist/loader.min.js.map +7 -0
- package/dist/session.d.ts +15 -0
- package/dist/sha1.d.ts +2 -0
- package/dist/transport.d.ts +7 -0
- package/dist/types.d.ts +22 -0
- package/dist/utm.d.ts +5 -0
- package/loader.js +72 -0
- package/package.json +59 -0
package/dist/flags.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export type FlagOperator = 'exact' | 'is_not' | 'icontains' | 'gt' | 'lt' | 'is_set';
|
|
2
|
+
export interface PropFilter {
|
|
3
|
+
key: string;
|
|
4
|
+
operator: FlagOperator;
|
|
5
|
+
value: unknown;
|
|
6
|
+
}
|
|
7
|
+
export interface Group {
|
|
8
|
+
properties: PropFilter[];
|
|
9
|
+
rollout_percentage: number;
|
|
10
|
+
variant?: string | null;
|
|
11
|
+
}
|
|
12
|
+
export interface Variant {
|
|
13
|
+
key: string;
|
|
14
|
+
rollout_percentage: number;
|
|
15
|
+
}
|
|
16
|
+
export interface Multivariate {
|
|
17
|
+
variants: Variant[];
|
|
18
|
+
}
|
|
19
|
+
export interface Filters {
|
|
20
|
+
groups: Group[];
|
|
21
|
+
multivariate?: Multivariate;
|
|
22
|
+
payloads?: Record<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
export interface Flag {
|
|
25
|
+
key: string;
|
|
26
|
+
active: boolean;
|
|
27
|
+
filters: Filters;
|
|
28
|
+
}
|
|
29
|
+
export interface FlagResult {
|
|
30
|
+
enabled: boolean;
|
|
31
|
+
variant: string | null;
|
|
32
|
+
payload: unknown;
|
|
33
|
+
}
|
|
34
|
+
/** Deterministic bucket in [0,1): int(sha1(key+"."+distinctId+salt)[0:15]) / 0xFFFFFFFFFFFFFFF. */
|
|
35
|
+
export declare function hashFlag(key: string, distinctId: string, salt: string): number;
|
|
36
|
+
/** actual = person_properties[key]; value = filter value. */
|
|
37
|
+
export declare function propMatch(op: FlagOperator, actual: unknown, value: unknown): boolean;
|
|
38
|
+
/** First matching group wins; in-group-off stops (no fallthrough). */
|
|
39
|
+
export declare function evaluate(flag: Flag, distinctId: string, personProps?: Record<string, unknown>): FlagResult;
|
|
40
|
+
export type FlagMap = Record<string, FlagResult>;
|
|
41
|
+
export interface FlagsResponse {
|
|
42
|
+
flags: FlagMap;
|
|
43
|
+
}
|
|
44
|
+
export interface FlagClientDeps {
|
|
45
|
+
getApiHost: () => string;
|
|
46
|
+
getWriteKey: () => string;
|
|
47
|
+
getDistinctId: () => string;
|
|
48
|
+
getPersonProperties: () => Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
export interface FlagClient {
|
|
51
|
+
/** In-memory cache of the last evaluated flags (or restored from localStorage). */
|
|
52
|
+
getCache(): FlagMap;
|
|
53
|
+
isFeatureEnabled(key: string): boolean;
|
|
54
|
+
getFeatureFlag(key: string): boolean | string;
|
|
55
|
+
getFeatureFlagPayload(key: string): unknown;
|
|
56
|
+
/** Fetch + cache flags for the current distinct id/props. Never throws. */
|
|
57
|
+
fetchFlags(): Promise<FlagMap>;
|
|
58
|
+
/**
|
|
59
|
+
* Cheap version check (GET `{apiHost}/flags/version`) before paying for a
|
|
60
|
+
* full `fetchFlags()`. Only calls `fetchFlags()` (and updates the stored
|
|
61
|
+
* `lastVersion`) when the returned version differs from the last one seen
|
|
62
|
+
* — or on the very first check. Network/parse failure on the version check
|
|
63
|
+
* fails open (treated as "changed") and falls through to a full fetch,
|
|
64
|
+
* matching this client's existing never-throw/best-effort tolerance.
|
|
65
|
+
* Never throws.
|
|
66
|
+
*/
|
|
67
|
+
checkVersionAndMaybeFetch(): Promise<{
|
|
68
|
+
changed: boolean;
|
|
69
|
+
flags: FlagMap;
|
|
70
|
+
}>;
|
|
71
|
+
/** Drop the in-memory + persisted cache. */
|
|
72
|
+
clear(): void;
|
|
73
|
+
}
|
|
74
|
+
export declare function createFlagClient(deps: FlagClientDeps): FlagClient;
|
package/dist/global.d.ts
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AutocaptureContext, ClickroomConfig, ClickroomOptions, EventPayload } from './types';
|
|
2
|
+
export declare const PACKAGE_NAME = "@clickroom/sdk-js";
|
|
3
|
+
declare function init(writeKey: string, opts?: ClickroomOptions): void;
|
|
4
|
+
declare function capture(event: string, properties?: Record<string, unknown>): void;
|
|
5
|
+
declare function identify(distinctId: string, personProps?: Record<string, unknown>): void;
|
|
6
|
+
declare function reset(): void;
|
|
7
|
+
declare function isFeatureEnabled(key: string): boolean;
|
|
8
|
+
declare function getFeatureFlag(key: string): boolean | string;
|
|
9
|
+
declare function getFeatureFlagPayload(key: string): unknown;
|
|
10
|
+
declare function onFeatureFlags(cb: (flags: Record<string, boolean | string>) => void): void;
|
|
11
|
+
/** Manually re-fetch flag definitions and notify `onFeatureFlags` listeners.
|
|
12
|
+
* Same trigger `identify()` already uses internally — exposed directly so a
|
|
13
|
+
* consumer can refresh on its own signal (a manual "reload flags" button, a
|
|
14
|
+
* websocket/SSE event from elsewhere, etc.) without faking an identify call. */
|
|
15
|
+
declare function refreshFeatureFlags(): void;
|
|
16
|
+
/** Stop the `feature_flag_poll_interval` loop started in `init()`, if any. */
|
|
17
|
+
declare function stopFeatureFlagPolling(): void;
|
|
18
|
+
declare const clickroom: {
|
|
19
|
+
init: typeof init;
|
|
20
|
+
capture: typeof capture;
|
|
21
|
+
identify: typeof identify;
|
|
22
|
+
reset: typeof reset;
|
|
23
|
+
isFeatureEnabled: typeof isFeatureEnabled;
|
|
24
|
+
getFeatureFlag: typeof getFeatureFlag;
|
|
25
|
+
getFeatureFlagPayload: typeof getFeatureFlagPayload;
|
|
26
|
+
onFeatureFlags: typeof onFeatureFlags;
|
|
27
|
+
refreshFeatureFlags: typeof refreshFeatureFlags;
|
|
28
|
+
stopFeatureFlagPolling: typeof stopFeatureFlagPolling;
|
|
29
|
+
};
|
|
30
|
+
export type { AutocaptureContext, ClickroomConfig, ClickroomOptions, EventPayload };
|
|
31
|
+
export { capture, getFeatureFlag, getFeatureFlagPayload, identify, init, isFeatureEnabled, onFeatureFlags, refreshFeatureFlags, reset, stopFeatureFlagPolling, };
|
|
32
|
+
export default clickroom;
|