@scoperat/tracker 0.1.1 → 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/dist/index.d.ts +163 -4
- package/dist/index.js +630 -2
- package/dist/index.js.map +1 -1
- package/dist/widget/index.d.ts +41 -0
- package/dist/widget/index.js +2633 -0
- package/dist/widget/index.js.map +1 -0
- package/dist/widget.global.js +970 -0
- package/dist/widget.global.js.map +1 -0
- package/package.json +15 -3
- package/dist/client.d.ts +0 -30
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -217
- package/dist/client.js.map +0 -1
- package/dist/context.d.ts +0 -5
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js +0 -24
- package/dist/context.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/types.d.ts +0 -33
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,163 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
type EventSource = "browser" | "server" | "worker";
|
|
2
|
+
interface TrackEvent {
|
|
3
|
+
event: string;
|
|
4
|
+
properties?: Record<string, unknown>;
|
|
5
|
+
context?: Record<string, unknown>;
|
|
6
|
+
source?: EventSource;
|
|
7
|
+
occurred_at?: Date | string;
|
|
8
|
+
org_id?: string;
|
|
9
|
+
user_id?: string;
|
|
10
|
+
anonymous_id?: string;
|
|
11
|
+
session_id?: string;
|
|
12
|
+
}
|
|
13
|
+
interface IdentifyTraits {
|
|
14
|
+
orgId?: string;
|
|
15
|
+
orgName?: string;
|
|
16
|
+
email?: string;
|
|
17
|
+
name?: string;
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
interface IdentifyOptions {
|
|
21
|
+
/**
|
|
22
|
+
* HMAC-SHA256(identityVerificationSecret, userId) in lowercase
|
|
23
|
+
* hex, computed by the host site's backend. Required for the
|
|
24
|
+
* support-ticket widget to authenticate the end-user — without
|
|
25
|
+
* it, ticket reads/writes fall back to the anonymous session
|
|
26
|
+
* channel (bootstrapped via `POST /ticket/session`).
|
|
27
|
+
*
|
|
28
|
+
* Retrieve the per-project `identityVerificationSecret` from the
|
|
29
|
+
* ScopeRat dashboard (Analytics → Project → Install). Never ship
|
|
30
|
+
* the secret to the browser — compute the hash server-side.
|
|
31
|
+
*/
|
|
32
|
+
userHash?: string;
|
|
33
|
+
}
|
|
34
|
+
interface InitOptions {
|
|
35
|
+
endpoint?: string;
|
|
36
|
+
flushAt?: number;
|
|
37
|
+
flushInterval?: number;
|
|
38
|
+
timeout?: number;
|
|
39
|
+
onError?: (error: Error, events: TrackEvent[]) => void;
|
|
40
|
+
/** Session inactivity timeout in ms. Defaults to 30 minutes. */
|
|
41
|
+
sessionTimeout?: number;
|
|
42
|
+
/** Automatically capture uncaught errors and unhandled rejections. Defaults to false. */
|
|
43
|
+
captureErrors?: boolean;
|
|
44
|
+
/** Environment name for feature flag evaluation (e.g. "production", "development"). */
|
|
45
|
+
environment?: string;
|
|
46
|
+
/** Polling interval for feature flag updates in ms. Defaults to 60 seconds. */
|
|
47
|
+
flagPollInterval?: number;
|
|
48
|
+
}
|
|
49
|
+
interface FlushResult {
|
|
50
|
+
success: boolean;
|
|
51
|
+
ingested: number;
|
|
52
|
+
}
|
|
53
|
+
interface EvaluatedFlag {
|
|
54
|
+
key: string;
|
|
55
|
+
value: unknown;
|
|
56
|
+
type: "boolean" | "string" | "number" | "json";
|
|
57
|
+
source: "default" | "override" | "targeted" | "rollout";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface FlagClientConfig {
|
|
61
|
+
endpoint: string;
|
|
62
|
+
writeKey: string;
|
|
63
|
+
timeout?: number;
|
|
64
|
+
environment?: string;
|
|
65
|
+
pollInterval?: number;
|
|
66
|
+
getIdentity: () => {
|
|
67
|
+
userId?: string;
|
|
68
|
+
anonymousId?: string;
|
|
69
|
+
orgId?: string;
|
|
70
|
+
};
|
|
71
|
+
/** Called when a flag is first evaluated (for impression tracking). */
|
|
72
|
+
onEvaluation?: (key: string, flag: EvaluatedFlag) => void;
|
|
73
|
+
}
|
|
74
|
+
declare class FlagClient {
|
|
75
|
+
private endpoint;
|
|
76
|
+
private writeKey;
|
|
77
|
+
private timeout;
|
|
78
|
+
private environment;
|
|
79
|
+
private getIdentity;
|
|
80
|
+
private onEvaluation;
|
|
81
|
+
private cache;
|
|
82
|
+
private ready;
|
|
83
|
+
private readyCallbacks;
|
|
84
|
+
private changeListeners;
|
|
85
|
+
private evalTracked;
|
|
86
|
+
private timer;
|
|
87
|
+
constructor(config: FlagClientConfig);
|
|
88
|
+
getFlag<T = unknown>(key: string, defaultValue: T): T;
|
|
89
|
+
onFlagsReady(callback: () => void): void;
|
|
90
|
+
onFlagChange(listener: () => void): () => void;
|
|
91
|
+
refresh(): Promise<void>;
|
|
92
|
+
destroy(): void;
|
|
93
|
+
private fetch;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
interface StoredTicketSession {
|
|
97
|
+
anonymousId: string;
|
|
98
|
+
token: string;
|
|
99
|
+
expiresAt: number;
|
|
100
|
+
}
|
|
101
|
+
declare class TrackerImpl {
|
|
102
|
+
private writeKey;
|
|
103
|
+
private endpoint;
|
|
104
|
+
private flushAt;
|
|
105
|
+
private flushInterval;
|
|
106
|
+
private timeout;
|
|
107
|
+
private onError?;
|
|
108
|
+
private buffer;
|
|
109
|
+
private timer;
|
|
110
|
+
private visibilityHandler;
|
|
111
|
+
private userId;
|
|
112
|
+
private orgId;
|
|
113
|
+
private traits;
|
|
114
|
+
private userHash;
|
|
115
|
+
private anonymousId;
|
|
116
|
+
private sessionTimeout;
|
|
117
|
+
private ticketSessionFetch;
|
|
118
|
+
private _flagClient;
|
|
119
|
+
init(writeKey: string, options?: InitOptions): void;
|
|
120
|
+
/** The underlying flag evaluation client. Use for direct SDK integration. */
|
|
121
|
+
get flags(): FlagClient;
|
|
122
|
+
identify(userId: string, traits?: IdentifyTraits, options?: IdentifyOptions): void;
|
|
123
|
+
reset(): void;
|
|
124
|
+
private clearTicketSession;
|
|
125
|
+
private readStoredTicketSession;
|
|
126
|
+
/**
|
|
127
|
+
* @internal Used by the widget API helpers. Returns a cached or
|
|
128
|
+
* newly-minted anonymous session token, or `null` if the server
|
|
129
|
+
* has anonymous sessions disabled. Coalesces concurrent callers
|
|
130
|
+
* onto a single in-flight network request so mount-time parallel
|
|
131
|
+
* API calls don't each trigger a `POST /ticket/session`.
|
|
132
|
+
*/
|
|
133
|
+
_ensureTicketSession(): Promise<StoredTicketSession | null>;
|
|
134
|
+
private getOrCreateSessionId;
|
|
135
|
+
private clearSession;
|
|
136
|
+
getSessionId(): string | undefined;
|
|
137
|
+
/** @internal Used by the widget to read tracker config. */
|
|
138
|
+
_getEndpoint(): string;
|
|
139
|
+
/** @internal Used by the widget to read the write key. */
|
|
140
|
+
_getWriteKey(): string | null;
|
|
141
|
+
/** @internal Used by the widget to read the current user identity. */
|
|
142
|
+
_getIdentity(): {
|
|
143
|
+
userId?: string;
|
|
144
|
+
anonymousId?: string;
|
|
145
|
+
email?: string;
|
|
146
|
+
name?: string;
|
|
147
|
+
userHash?: string;
|
|
148
|
+
};
|
|
149
|
+
captureException(error: Error, context?: Record<string, unknown>): void;
|
|
150
|
+
addBreadcrumb(category: string, message: string, data?: Record<string, unknown>): void;
|
|
151
|
+
track(event: string, properties?: Record<string, unknown>): void;
|
|
152
|
+
track(event: TrackEvent): void;
|
|
153
|
+
flush(): Promise<FlushResult>;
|
|
154
|
+
private flushSync;
|
|
155
|
+
getFlag<T = unknown>(key: string, defaultValue: T): T;
|
|
156
|
+
onFlagsReady(callback: () => void): void;
|
|
157
|
+
onFlagChange(listener: () => void): () => void;
|
|
158
|
+
refreshFlags(): Promise<void>;
|
|
159
|
+
shutdown(): Promise<void>;
|
|
160
|
+
}
|
|
161
|
+
declare const scoperat: TrackerImpl;
|
|
162
|
+
|
|
163
|
+
export { type EvaluatedFlag, type EventSource, FlagClient, type FlushResult, type IdentifyOptions, type IdentifyTraits, type InitOptions, type TrackEvent, scoperat as default };
|