@goatech/sdk-js 0.1.0 → 1.0.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 +21 -83
- package/dist/boot-error.d.mts +1 -39
- package/dist/boot-error.d.ts +1 -39
- package/dist/boot-error.js +12 -32
- package/dist/boot-error.mjs +1 -2
- package/dist/experiments.d.mts +1 -29
- package/dist/experiments.d.ts +1 -29
- package/dist/experiments.js +12 -2
- package/dist/experiments.mjs +1 -2
- package/dist/flags.d.mts +1 -34
- package/dist/flags.d.ts +1 -34
- package/dist/flags.js +12 -2
- package/dist/flags.mjs +1 -2
- package/dist/index.d.mts +4 -170
- package/dist/index.d.ts +4 -170
- package/dist/index.js +18 -31
- package/dist/index.mjs +10 -3
- package/package.json +21 -24
- package/dist/chunk-6BNLBHZS.mjs +0 -2
- package/dist/chunk-BQTMRKY5.mjs +0 -32
- package/dist/chunk-X5MDWZGR.mjs +0 -3
- package/dist/types-CxAq_Cds.d.mts +0 -371
- package/dist/types-CxAq_Cds.d.ts +0 -371
package/dist/types-CxAq_Cds.d.ts
DELETED
|
@@ -1,371 +0,0 @@
|
|
|
1
|
-
type DiagnosticSeverity = "debug" | "info" | "warn" | "error";
|
|
2
|
-
type DiagnosticCategory = "transport" | "config" | "identity" | "lifecycle" | "flag" | "experiment" | "connectivity";
|
|
3
|
-
interface DiagnosticEvent {
|
|
4
|
-
timestamp: string;
|
|
5
|
-
severity: DiagnosticSeverity;
|
|
6
|
-
category: DiagnosticCategory;
|
|
7
|
-
/** Machine-readable code, e.g. "transport.flush_failed" */
|
|
8
|
-
code: string;
|
|
9
|
-
/** Human-readable description */
|
|
10
|
-
message: string;
|
|
11
|
-
/** Structured payload */
|
|
12
|
-
data?: Record<string, unknown>;
|
|
13
|
-
/** Correlates with API-side X-Request-ID */
|
|
14
|
-
requestId?: string;
|
|
15
|
-
}
|
|
16
|
-
type DiagnosticListener = (event: DiagnosticEvent) => void;
|
|
17
|
-
|
|
18
|
-
interface SubscribeOptions {
|
|
19
|
-
/** Only receive events at or above this severity. Default: "debug" (all). */
|
|
20
|
-
minSeverity?: DiagnosticSeverity;
|
|
21
|
-
/** Only receive events in these categories. Default: all. */
|
|
22
|
-
categories?: DiagnosticCategory[];
|
|
23
|
-
}
|
|
24
|
-
declare class DiagnosticBus {
|
|
25
|
-
private readonly listeners;
|
|
26
|
-
private readonly buffer;
|
|
27
|
-
private readonly maxSize;
|
|
28
|
-
private writeIndex;
|
|
29
|
-
private count;
|
|
30
|
-
private counts;
|
|
31
|
-
constructor(bufferSize?: number);
|
|
32
|
-
emit(event: DiagnosticEvent): void;
|
|
33
|
-
subscribe(fn: DiagnosticListener, options?: SubscribeOptions): () => void;
|
|
34
|
-
getRecentDiagnostics(): DiagnosticEvent[];
|
|
35
|
-
getCounts(): Record<DiagnosticSeverity, number>;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
declare class Logger {
|
|
39
|
-
private readonly debugEnabled;
|
|
40
|
-
private readonly prefix;
|
|
41
|
-
private readonly bus;
|
|
42
|
-
constructor(debug: boolean, bus?: DiagnosticBus);
|
|
43
|
-
debug(message: string, ...args: unknown[]): void;
|
|
44
|
-
warn(message: string, ...args: unknown[]): void;
|
|
45
|
-
error(message: string, ...args: unknown[]): void;
|
|
46
|
-
/**
|
|
47
|
-
* Emit a diagnostic event with explicit category and code.
|
|
48
|
-
* Use this instead of debug/warn/error when you want fine-grained control.
|
|
49
|
-
*/
|
|
50
|
-
diagnostic(severity: DiagnosticSeverity, category: DiagnosticCategory, code: string, message: string, data?: Record<string, unknown>, requestId?: string): void;
|
|
51
|
-
private emitDiagnostic;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
type Tracker$1 = (eventName: string, properties?: Record<string, unknown>) => void;
|
|
55
|
-
interface ErrorCaptureConfig {
|
|
56
|
-
/** Capture uncaught errors via `window.onerror`. Default: true. */
|
|
57
|
-
errors?: boolean;
|
|
58
|
-
/** Capture unhandled promise rejections. Default: true. */
|
|
59
|
-
rejections?: boolean;
|
|
60
|
-
/** Forward `goatech:auth-event` CustomEvents verbatim as tracked events. Default: true. */
|
|
61
|
-
authEvents?: boolean;
|
|
62
|
-
/** Max stack frames length in characters. Default: 4096. */
|
|
63
|
-
stackLimit?: number;
|
|
64
|
-
/** De-dup window in ms — identical errors within this window are dropped. Default: 1000. */
|
|
65
|
-
dedupeWindowMs?: number;
|
|
66
|
-
}
|
|
67
|
-
declare class BrowserErrorCapture {
|
|
68
|
-
private readonly track;
|
|
69
|
-
private readonly log;
|
|
70
|
-
private readonly cfg;
|
|
71
|
-
private readonly handlers;
|
|
72
|
-
private lastSignature;
|
|
73
|
-
private lastSignatureAt;
|
|
74
|
-
constructor(track: Tracker$1, log: Logger, config?: ErrorCaptureConfig);
|
|
75
|
-
install(): void;
|
|
76
|
-
uninstall(): void;
|
|
77
|
-
private suppress;
|
|
78
|
-
private safeTrack;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* HTTP error auto-capture — wraps `window.fetch` and emits a structured
|
|
83
|
-
* `$http_error` event for every 4xx/5xx response or network failure.
|
|
84
|
-
*
|
|
85
|
-
* Why: without this, customers have to hand-instrument every endpoint that
|
|
86
|
-
* might return an error (the 04-22 sign-out debug session is the canonical
|
|
87
|
-
* example — we spent hours theorizing about cookie behavior instead of
|
|
88
|
-
* reading `cookie_keys=[]` off a structured event). With it, every failing
|
|
89
|
-
* request becomes a queryable event on the GoaTech dashboard with enough
|
|
90
|
-
* context to diagnose auth, CORS, CDN, and proxy bugs without touching
|
|
91
|
-
* customer code.
|
|
92
|
-
*
|
|
93
|
-
* Design:
|
|
94
|
-
* - Monkey-patches `window.fetch` with an idempotent install — a second
|
|
95
|
-
* install() call is a no-op.
|
|
96
|
-
* - Captures CORS-exposed response headers only (Set-Cookie is hidden from
|
|
97
|
-
* JavaScript per spec, so we capture cookie *names* via `document.cookie`
|
|
98
|
-
* as a proxy for "did the server's Set-Cookie land").
|
|
99
|
-
* - Dedupe window prevents error loops (identical (url, status) within
|
|
100
|
-
* `dedupeWindowMs` is dropped).
|
|
101
|
-
* - NEVER captures request or response bodies — those may carry secrets.
|
|
102
|
-
* If a customer needs bodies they can extend via the `onCapture` hook.
|
|
103
|
-
*/
|
|
104
|
-
|
|
105
|
-
type Tracker = (eventName: string, properties?: Record<string, unknown>) => void;
|
|
106
|
-
interface HttpErrorCaptureConfig {
|
|
107
|
-
/** Master switch. Default: true. */
|
|
108
|
-
enabled?: boolean;
|
|
109
|
-
/**
|
|
110
|
-
* Status predicate — return true to capture. Default: `s >= 400`.
|
|
111
|
-
* Network failures (fetch rejections) are ALWAYS captured regardless.
|
|
112
|
-
*/
|
|
113
|
-
shouldCapture?: (status: number) => boolean;
|
|
114
|
-
/**
|
|
115
|
-
* URL patterns to exclude (tested with `.test(url)`). Useful to skip
|
|
116
|
-
* analytics/monitoring endpoints that would otherwise recurse.
|
|
117
|
-
* Default: excludes `/v1/ingest` and `/v1/config` on the SDK's own API URL.
|
|
118
|
-
*/
|
|
119
|
-
excludeUrlPatterns?: RegExp[];
|
|
120
|
-
/**
|
|
121
|
-
* CORS-exposed response headers to capture (lowercased). Default:
|
|
122
|
-
* ["x-request-id", "vary", "content-type", "access-control-allow-origin"].
|
|
123
|
-
*/
|
|
124
|
-
captureResponseHeaders?: string[];
|
|
125
|
-
/** Dedupe window in ms — identical (url, status) inside is dropped. Default: 1000. */
|
|
126
|
-
dedupeWindowMs?: number;
|
|
127
|
-
/** Called AFTER the event is tracked — hook for custom enrichment or sinks. */
|
|
128
|
-
onCapture?: (detail: HttpErrorEventDetail) => void;
|
|
129
|
-
}
|
|
130
|
-
interface HttpErrorEventDetail {
|
|
131
|
-
url: string;
|
|
132
|
-
method: string;
|
|
133
|
-
status: number;
|
|
134
|
-
latency_ms: number;
|
|
135
|
-
request_id: string | null;
|
|
136
|
-
response_headers: Record<string, string>;
|
|
137
|
-
/**
|
|
138
|
-
* Non-HttpOnly cookie NAMES present on document.cookie at the time of
|
|
139
|
-
* the error. Values are never captured. This is the client-side proxy
|
|
140
|
-
* for "did the server's Set-Cookie get accepted" — if an auth endpoint
|
|
141
|
-
* 401s and there are zero cookies on the origin that *should* have set
|
|
142
|
-
* one, the cookie was rejected by the browser.
|
|
143
|
-
*/
|
|
144
|
-
cookie_names: string[];
|
|
145
|
-
/** "network_failure" | "http_error". */
|
|
146
|
-
kind: "network_failure" | "http_error";
|
|
147
|
-
/** Present on kind=network_failure. */
|
|
148
|
-
error_name?: string;
|
|
149
|
-
/** Present on kind=network_failure. */
|
|
150
|
-
error_message?: string;
|
|
151
|
-
/** True if the fetch was aborted (e.g., timeout). */
|
|
152
|
-
aborted?: boolean;
|
|
153
|
-
}
|
|
154
|
-
declare class HttpErrorCapture {
|
|
155
|
-
private readonly track;
|
|
156
|
-
private readonly log;
|
|
157
|
-
private readonly cfg;
|
|
158
|
-
private originalFetch;
|
|
159
|
-
private installed;
|
|
160
|
-
private lastSig;
|
|
161
|
-
private lastSigAt;
|
|
162
|
-
constructor(track: Tracker, log: Logger, config?: HttpErrorCaptureConfig);
|
|
163
|
-
install(): void;
|
|
164
|
-
uninstall(): void;
|
|
165
|
-
private shouldSkip;
|
|
166
|
-
private emit;
|
|
167
|
-
private pluckHeaders;
|
|
168
|
-
private readCookieNames;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
interface ClickFrustrationConfig {
|
|
172
|
-
/** Detect rage clicks. Default: true. */
|
|
173
|
-
rage?: boolean;
|
|
174
|
-
/** Detect dead clicks. Default: true. */
|
|
175
|
-
dead?: boolean;
|
|
176
|
-
/** Number of clicks within window+radius that constitute rage. Default: 3. */
|
|
177
|
-
rageThreshold?: number;
|
|
178
|
-
/** Time window for rage clustering. Default: 1000ms. */
|
|
179
|
-
rageWindowMs?: number;
|
|
180
|
-
/** Pixel radius for rage clustering. Default: 50. */
|
|
181
|
-
rageRadiusPx?: number;
|
|
182
|
-
/** Cap the emission rate (combined rage+dead). Default: 5/sec. */
|
|
183
|
-
maxEmitsPerSec?: number;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
interface GoaTechConfig {
|
|
187
|
-
apiKey: string;
|
|
188
|
-
environment?: string;
|
|
189
|
-
apiUrl?: string;
|
|
190
|
-
flushInterval?: number;
|
|
191
|
-
flushSize?: number;
|
|
192
|
-
debug?: boolean;
|
|
193
|
-
configRefreshInterval?: number;
|
|
194
|
-
maxQueueSize?: number;
|
|
195
|
-
retryAttempts?: number;
|
|
196
|
-
/** Called for every tracked event. Useful for logging, debugging, or
|
|
197
|
-
* forwarding events to systems outside the React tree. */
|
|
198
|
-
onEvent?: (eventName: string, properties?: Record<string, unknown>) => void;
|
|
199
|
-
/** Subscribe to SDK diagnostic events for monitoring integration. */
|
|
200
|
-
onDiagnostic?: DiagnosticListener;
|
|
201
|
-
/** Maximum diagnostic events to retain in memory ring buffer. Default: 100. */
|
|
202
|
-
diagnosticBufferSize?: number;
|
|
203
|
-
/**
|
|
204
|
-
* Automatic error capture in the browser. Registers listeners for
|
|
205
|
-
* `window.onerror` and `unhandledrejection` and forwards them as `$error`
|
|
206
|
-
* events. Pass `false` to disable completely, or a partial config to tune
|
|
207
|
-
* individual channels. Default: enabled with defaults.
|
|
208
|
-
*/
|
|
209
|
-
autoCaptureErrors?: boolean | ErrorCaptureConfig;
|
|
210
|
-
/**
|
|
211
|
-
* Automatic HTTP error capture. Wraps `window.fetch` and emits a
|
|
212
|
-
* `$http_error` event for every 4xx/5xx response and network failure —
|
|
213
|
-
* making auth, CORS, CDN, and proxy bugs visible on the dashboard without
|
|
214
|
-
* customers touching their code. Pass `false` to disable, or a partial
|
|
215
|
-
* config to tune status predicate, URL exclusions, captured response
|
|
216
|
-
* headers, and dedupe window. Default: OFF — opt in with `true` or a
|
|
217
|
-
* partial config after verifying in your specific browser matrix. Monkey-
|
|
218
|
-
* patching window.fetch has sharp edges (native contract, other libs that
|
|
219
|
-
* also patch it); leaving this opt-in avoids surprise regressions.
|
|
220
|
-
*/
|
|
221
|
-
autoCaptureHttpErrors?: boolean | HttpErrorCaptureConfig;
|
|
222
|
-
/**
|
|
223
|
-
* Automatic click-frustration capture. Listens for global clicks and
|
|
224
|
-
* emits `$rage_click` (≥3 clicks within 1s in a 50px radius) and
|
|
225
|
-
* `$dead_click` (click on a non-interactive target) so the dashboard
|
|
226
|
-
* can surface UX dead-ends. Pass `false` to disable, or a partial
|
|
227
|
-
* config to tune thresholds. Default: ON.
|
|
228
|
-
*/
|
|
229
|
-
autoCaptureClickFrustration?: boolean | ClickFrustrationConfig;
|
|
230
|
-
/**
|
|
231
|
-
* Application version string (e.g. build SHA or semver). When set, sent on
|
|
232
|
-
* every event as `app_version` so the backend can attribute events to a
|
|
233
|
-
* Release. Without this, release-health metrics can't correlate events to
|
|
234
|
-
* specific builds.
|
|
235
|
-
*/
|
|
236
|
-
appVersion?: string;
|
|
237
|
-
}
|
|
238
|
-
type FlagValue = boolean | string | number | Record<string, unknown>;
|
|
239
|
-
interface ExperimentResult {
|
|
240
|
-
variant: string;
|
|
241
|
-
payload?: Record<string, unknown>;
|
|
242
|
-
}
|
|
243
|
-
interface SDKStatus {
|
|
244
|
-
initialized: boolean;
|
|
245
|
-
online: boolean;
|
|
246
|
-
queueDepth: number;
|
|
247
|
-
offlineQueueDepth: number;
|
|
248
|
-
lastFlushAt: Date | null;
|
|
249
|
-
deviceId: string | null;
|
|
250
|
-
userId: string | null;
|
|
251
|
-
flagCount: number;
|
|
252
|
-
experimentCount: number;
|
|
253
|
-
sdkVersion: string;
|
|
254
|
-
}
|
|
255
|
-
interface DeviceInfo {
|
|
256
|
-
platform: string;
|
|
257
|
-
userAgent: string;
|
|
258
|
-
language: string;
|
|
259
|
-
screenWidth: number;
|
|
260
|
-
screenHeight: number;
|
|
261
|
-
timezone: string;
|
|
262
|
-
}
|
|
263
|
-
interface EnrichedEvent {
|
|
264
|
-
event_id: string;
|
|
265
|
-
event_name: string;
|
|
266
|
-
event_properties?: Record<string, unknown>;
|
|
267
|
-
device_id: string;
|
|
268
|
-
anonymous_id: string;
|
|
269
|
-
session_id: string;
|
|
270
|
-
user_id: string | null;
|
|
271
|
-
platform: string;
|
|
272
|
-
app_version?: string;
|
|
273
|
-
sdk_version: string;
|
|
274
|
-
locale: string;
|
|
275
|
-
timezone: string;
|
|
276
|
-
timestamp: string;
|
|
277
|
-
}
|
|
278
|
-
interface FlagConfig {
|
|
279
|
-
key: string;
|
|
280
|
-
enabled: boolean;
|
|
281
|
-
default_value: FlagValue;
|
|
282
|
-
flag_type: string;
|
|
283
|
-
rules: FlagRule[];
|
|
284
|
-
}
|
|
285
|
-
interface FlagRule {
|
|
286
|
-
conditions: Condition[];
|
|
287
|
-
value: FlagValue;
|
|
288
|
-
percentage: number;
|
|
289
|
-
enabled: boolean;
|
|
290
|
-
}
|
|
291
|
-
type ConditionOp = "eq" | "neq" | "in" | "not_in" | "gt" | "gte" | "lt" | "lte" | "contains" | "exists";
|
|
292
|
-
interface Condition {
|
|
293
|
-
field: string;
|
|
294
|
-
op: ConditionOp;
|
|
295
|
-
values: unknown[];
|
|
296
|
-
}
|
|
297
|
-
type ExperimentStatus = "draft" | "running" | "paused" | "completed";
|
|
298
|
-
/** Pre-bucketed assignment returned by `/v1/config`. */
|
|
299
|
-
interface ExperimentAssignment {
|
|
300
|
-
variant_key: string;
|
|
301
|
-
payload?: Record<string, unknown>;
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Full experiment config — only used internally for admin flows and
|
|
305
|
-
* tests. Regular SDK consumers receive `ExperimentAssignment`.
|
|
306
|
-
*/
|
|
307
|
-
interface ExperimentConfig {
|
|
308
|
-
key: string;
|
|
309
|
-
name: string;
|
|
310
|
-
status: ExperimentStatus;
|
|
311
|
-
traffic_pct: number;
|
|
312
|
-
variants: ExperimentVariant[];
|
|
313
|
-
}
|
|
314
|
-
interface ExperimentVariant {
|
|
315
|
-
key: string;
|
|
316
|
-
name: string;
|
|
317
|
-
weight: number;
|
|
318
|
-
is_control: boolean;
|
|
319
|
-
payload?: Record<string, unknown>;
|
|
320
|
-
}
|
|
321
|
-
interface SDKConfig {
|
|
322
|
-
/** Server-evaluated flag values keyed by flag_key. */
|
|
323
|
-
flags: Record<string, unknown>;
|
|
324
|
-
/** Pre-bucketed experiment assignments keyed by experiment_key. */
|
|
325
|
-
experiments: Record<string, ExperimentAssignment>;
|
|
326
|
-
server_time?: string;
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* First-touch attribution payload attached to every event fired during a
|
|
330
|
-
* given session. Captured from the session's first pageview (UTM params
|
|
331
|
-
* on the URL + document.referrer + landing pathname). All fields are
|
|
332
|
-
* optional because most organic visits have none of them set.
|
|
333
|
-
*/
|
|
334
|
-
interface AttributionContext {
|
|
335
|
-
utm_source?: string;
|
|
336
|
-
utm_medium?: string;
|
|
337
|
-
utm_campaign?: string;
|
|
338
|
-
utm_content?: string;
|
|
339
|
-
utm_term?: string;
|
|
340
|
-
/** Ad-click IDs the ad platforms round-trip on their click URLs. */
|
|
341
|
-
gclid?: string;
|
|
342
|
-
fbclid?: string;
|
|
343
|
-
/** `document.referrer` minus query + trailing slash. May be the empty
|
|
344
|
-
* string when direct-traffic / privacy mode hides it. */
|
|
345
|
-
referrer?: string;
|
|
346
|
-
/** Hostname of the referrer, for easy grouping without full-URL parsing
|
|
347
|
-
* server-side. */
|
|
348
|
-
referrer_host?: string;
|
|
349
|
-
/** Pathname + search that the user first hit this session. */
|
|
350
|
-
landing_page?: string;
|
|
351
|
-
}
|
|
352
|
-
interface EventContext {
|
|
353
|
-
device_id: string;
|
|
354
|
-
anonymous_id: string;
|
|
355
|
-
session_id: string;
|
|
356
|
-
user_id: string | null;
|
|
357
|
-
platform: string;
|
|
358
|
-
locale: string;
|
|
359
|
-
timezone: string;
|
|
360
|
-
sdk_version: string;
|
|
361
|
-
/** First-touch attribution captured at session start. Same snapshot is
|
|
362
|
-
* attached to every event in the session so segmenting "events from
|
|
363
|
-
* users who came via utm_source=twitter" works without a join. */
|
|
364
|
-
attribution?: AttributionContext;
|
|
365
|
-
/** Ever-first-touch attribution across the whole device lifetime.
|
|
366
|
-
* Written once; lets you distinguish "first-session" from "returning"
|
|
367
|
-
* traffic even after the original UTM params are long gone. */
|
|
368
|
-
first_touch?: AttributionContext;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
export { BrowserErrorCapture as B, type Condition as C, DiagnosticBus as D, type ExperimentResult as E, type FlagValue as F, type GoaTechConfig as G, HttpErrorCapture as H, type SDKStatus as S, type DiagnosticEvent as a, type ConditionOp as b, type DeviceInfo as c, type DiagnosticCategory as d, type DiagnosticListener as e, type DiagnosticSeverity as f, type EnrichedEvent as g, type ErrorCaptureConfig as h, type EventContext as i, type ExperimentConfig as j, type ExperimentStatus as k, type ExperimentVariant as l, type FlagConfig as m, type FlagRule as n, type HttpErrorCaptureConfig as o, type HttpErrorEventDetail as p, type SDKConfig as q, type SubscribeOptions as r, type ExperimentAssignment as s };
|