@sheepit-ai/sdk-js 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/LICENSE +21 -0
- package/README.md +99 -0
- package/dist/boot-error.d.mts +39 -0
- package/dist/boot-error.d.ts +39 -0
- package/dist/boot-error.js +32 -0
- package/dist/boot-error.mjs +2 -0
- package/dist/chunk-35ZDSFHA.mjs +32 -0
- package/dist/chunk-6BNLBHZS.mjs +2 -0
- package/dist/chunk-X5MDWZGR.mjs +3 -0
- package/dist/experiments.d.mts +29 -0
- package/dist/experiments.d.ts +29 -0
- package/dist/experiments.js +2 -0
- package/dist/experiments.mjs +2 -0
- package/dist/flags.d.mts +34 -0
- package/dist/flags.d.ts +34 -0
- package/dist/flags.js +2 -0
- package/dist/flags.mjs +2 -0
- package/dist/index.d.mts +170 -0
- package/dist/index.d.ts +170 -0
- package/dist/index.js +32 -0
- package/dist/index.mjs +3 -0
- package/dist/types-CxAq_Cds.d.mts +371 -0
- package/dist/types-CxAq_Cds.d.ts +371 -0
- package/package.json +78 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { F as FlagValue, E as ExperimentResult, S as SDKStatus, D as DiagnosticBus, a as DiagnosticEvent, G as GoaTechConfig } from './types-CxAq_Cds.mjs';
|
|
2
|
+
export { B as BrowserErrorCapture, C as Condition, b as ConditionOp, c as DeviceInfo, d as DiagnosticCategory, e as DiagnosticListener, f as DiagnosticSeverity, g as EnrichedEvent, h as ErrorCaptureConfig, i as EventContext, j as ExperimentConfig, k as ExperimentStatus, l as ExperimentVariant, m as FlagConfig, n as FlagRule, H as HttpErrorCapture, o as HttpErrorCaptureConfig, p as HttpErrorEventDetail, q as SDKConfig, r as SubscribeOptions } from './types-CxAq_Cds.mjs';
|
|
3
|
+
export { BootErrorPayload, BootErrorScriptOptions, getBootErrorScript } from './boot-error.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Public API surface of a GoaTech client instance.
|
|
7
|
+
* Use this type when you need to pass around a client reference
|
|
8
|
+
* without depending on the concrete GoaTech class.
|
|
9
|
+
*/
|
|
10
|
+
interface IGoaTech {
|
|
11
|
+
track(eventName: string, properties?: Record<string, unknown>): void;
|
|
12
|
+
identify(userId: string, traits?: Record<string, unknown>): void;
|
|
13
|
+
reset(): void;
|
|
14
|
+
flag(flagKey: string, defaultValue?: FlagValue): FlagValue;
|
|
15
|
+
experiment(experimentKey: string): ExperimentResult;
|
|
16
|
+
/** Override a flag value for local testing. Only active when debug=true. */
|
|
17
|
+
overrideFlag(key: string, value: FlagValue): void;
|
|
18
|
+
/** Clear all debug overrides. */
|
|
19
|
+
clearOverrides(): void;
|
|
20
|
+
/** Get all current debug overrides (for debug menu UI). */
|
|
21
|
+
getOverrides(): Record<string, unknown>;
|
|
22
|
+
flush(): Promise<void>;
|
|
23
|
+
/** Notify the SDK of a route change in a single-page app. Emits a
|
|
24
|
+
* synthetic `$page_leave` for the prior route (if any) and resets
|
|
25
|
+
* the page-leave timer for the new path. */
|
|
26
|
+
recordPageView(path: string): void;
|
|
27
|
+
status(): SDKStatus;
|
|
28
|
+
destroy(): void;
|
|
29
|
+
/** Access the diagnostic event bus for runtime subscribe/unsubscribe. */
|
|
30
|
+
diagnostics(): DiagnosticBus;
|
|
31
|
+
/** Get buffered recent diagnostic events. */
|
|
32
|
+
getRecentDiagnostics(): DiagnosticEvent[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
declare class GoaTech implements IGoaTech {
|
|
36
|
+
private static instance;
|
|
37
|
+
private readonly cfg;
|
|
38
|
+
private readonly log;
|
|
39
|
+
private readonly bus;
|
|
40
|
+
private readonly context;
|
|
41
|
+
private readonly queue;
|
|
42
|
+
private readonly flagManager;
|
|
43
|
+
private readonly experimentManager;
|
|
44
|
+
private readonly identityManager;
|
|
45
|
+
private readonly configSync;
|
|
46
|
+
private readonly transport;
|
|
47
|
+
private readonly offlineQueue;
|
|
48
|
+
private readonly connectivity;
|
|
49
|
+
private readonly lifecycle;
|
|
50
|
+
private readonly errorCapture;
|
|
51
|
+
private readonly httpErrorCapture;
|
|
52
|
+
private readonly clickFrustrationCapture;
|
|
53
|
+
private flushTimer;
|
|
54
|
+
private destroyed;
|
|
55
|
+
private constructor();
|
|
56
|
+
/**
|
|
57
|
+
* Create a new, independent GoaTech instance.
|
|
58
|
+
* The caller owns the instance lifecycle — no global state.
|
|
59
|
+
* Preferred for React apps (pass instance to Context).
|
|
60
|
+
*/
|
|
61
|
+
static create(config: GoaTechConfig): GoaTech;
|
|
62
|
+
/**
|
|
63
|
+
* Create a singleton instance. Returns existing instance if already
|
|
64
|
+
* initialized (logs a warning). Call `destroy()` first to re-initialize.
|
|
65
|
+
*
|
|
66
|
+
* For React apps, prefer `GoaTech.create()` + Context instead.
|
|
67
|
+
*/
|
|
68
|
+
static init(config: GoaTechConfig): GoaTech;
|
|
69
|
+
/** Get the singleton instance. Throws if `init()` was never called. */
|
|
70
|
+
static getInstance(): GoaTech;
|
|
71
|
+
/**
|
|
72
|
+
* Returns true if the singleton has been initialized via `init()`.
|
|
73
|
+
* Useful for HMR guards and conditional initialization.
|
|
74
|
+
*/
|
|
75
|
+
static isInitialized(): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Queue an analytics event. Auto-flushes when the queue reaches
|
|
78
|
+
* `flushSize` (default 20) or when the periodic flush timer fires.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* gt.track("course_viewed", { course_id: "c_123", source: "catalog" });
|
|
82
|
+
*/
|
|
83
|
+
track(eventName: string, properties?: Record<string, unknown>): void;
|
|
84
|
+
/**
|
|
85
|
+
* Resolve a feature flag for the current device + identity. Reads
|
|
86
|
+
* the cached server-evaluated value from `/v1/config` (refreshed on
|
|
87
|
+
* `configRefreshInterval`). Fires `$flag_exposure` once per session
|
|
88
|
+
* per flag.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* if (gt.flag("new_checkout_flow", false)) {
|
|
92
|
+
* renderNewCheckout();
|
|
93
|
+
* }
|
|
94
|
+
*/
|
|
95
|
+
flag(flagKey: string, defaultValue?: FlagValue): FlagValue;
|
|
96
|
+
overrideFlag(key: string, value: FlagValue): void;
|
|
97
|
+
clearOverrides(): void;
|
|
98
|
+
getOverrides(): Record<string, unknown>;
|
|
99
|
+
/**
|
|
100
|
+
* Resolve the bucketed variant + payload for an experiment. Sticky
|
|
101
|
+
* per device. Fires `$experiment_exposure` once per session per
|
|
102
|
+
* experiment.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* const { variant, payload } = gt.experiment("hero_h1_copy_v1");
|
|
106
|
+
* if (variant !== "control") setHeadline((payload as { headline: string }).headline);
|
|
107
|
+
*/
|
|
108
|
+
experiment(experimentKey: string): ExperimentResult;
|
|
109
|
+
/**
|
|
110
|
+
* Tie the current device to a stable user id and merge traits onto
|
|
111
|
+
* the GoaTech user record. Re-identifying with a different userId
|
|
112
|
+
* clears the cached experiment assignments so the new identity
|
|
113
|
+
* gets fresh buckets.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* await api.login(form);
|
|
117
|
+
* gt.identify("user_abc123", { email: "jane@example.com", plan: "pro" });
|
|
118
|
+
*/
|
|
119
|
+
identify(userId: string, traits?: Record<string, unknown>): void;
|
|
120
|
+
/**
|
|
121
|
+
* Forget the current identity + experiment assignments and start a
|
|
122
|
+
* fresh anonymous session. Call on logout.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* await api.logout();
|
|
126
|
+
* gt.reset();
|
|
127
|
+
*/
|
|
128
|
+
reset(): void;
|
|
129
|
+
/**
|
|
130
|
+
* Drain any queued events to the GoaTech ingest endpoint. Useful
|
|
131
|
+
* before navigation in single-page apps and required before
|
|
132
|
+
* Vercel/Lambda function exits.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* router.beforeEach(async () => {
|
|
136
|
+
* await gt.flush();
|
|
137
|
+
* });
|
|
138
|
+
*/
|
|
139
|
+
flush(): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Notify the SDK of a route change. The first call starts a page-leave
|
|
142
|
+
* timer; subsequent calls emit a synthetic `$page_leave` for the prior
|
|
143
|
+
* route (with `exit_kind: "spa_nav"`) before resetting state. Wire
|
|
144
|
+
* this into your router — for Next.js, use `<PageViewTracker>` from
|
|
145
|
+
* `@sheepit-ai/react`, which calls this for you.
|
|
146
|
+
*
|
|
147
|
+
* Idempotent for repeat calls with the same path.
|
|
148
|
+
*/
|
|
149
|
+
recordPageView(path: string): void;
|
|
150
|
+
status(): SDKStatus;
|
|
151
|
+
diagnostics(): DiagnosticBus;
|
|
152
|
+
getRecentDiagnostics(): DiagnosticEvent[];
|
|
153
|
+
/**
|
|
154
|
+
* Stop all timers, drain remaining events, and tear down auto-error
|
|
155
|
+
* + lifecycle listeners. After `destroy()` further `track()` /
|
|
156
|
+
* `flag()` calls are no-ops. Idempotent.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* // Replacing the SDK instance (rare; usually just call once)
|
|
160
|
+
* const old = GoaTech.getInstance();
|
|
161
|
+
* old.destroy();
|
|
162
|
+
* const fresh = GoaTech.init({ apiKey: nextKey });
|
|
163
|
+
*/
|
|
164
|
+
destroy(): void;
|
|
165
|
+
private start;
|
|
166
|
+
private applyConfig;
|
|
167
|
+
private postIdentityResolve;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export { DiagnosticBus, DiagnosticEvent, ExperimentResult, FlagValue, GoaTech, GoaTechConfig, type IGoaTech, SDKStatus };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { F as FlagValue, E as ExperimentResult, S as SDKStatus, D as DiagnosticBus, a as DiagnosticEvent, G as GoaTechConfig } from './types-CxAq_Cds.js';
|
|
2
|
+
export { B as BrowserErrorCapture, C as Condition, b as ConditionOp, c as DeviceInfo, d as DiagnosticCategory, e as DiagnosticListener, f as DiagnosticSeverity, g as EnrichedEvent, h as ErrorCaptureConfig, i as EventContext, j as ExperimentConfig, k as ExperimentStatus, l as ExperimentVariant, m as FlagConfig, n as FlagRule, H as HttpErrorCapture, o as HttpErrorCaptureConfig, p as HttpErrorEventDetail, q as SDKConfig, r as SubscribeOptions } from './types-CxAq_Cds.js';
|
|
3
|
+
export { BootErrorPayload, BootErrorScriptOptions, getBootErrorScript } from './boot-error.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Public API surface of a GoaTech client instance.
|
|
7
|
+
* Use this type when you need to pass around a client reference
|
|
8
|
+
* without depending on the concrete GoaTech class.
|
|
9
|
+
*/
|
|
10
|
+
interface IGoaTech {
|
|
11
|
+
track(eventName: string, properties?: Record<string, unknown>): void;
|
|
12
|
+
identify(userId: string, traits?: Record<string, unknown>): void;
|
|
13
|
+
reset(): void;
|
|
14
|
+
flag(flagKey: string, defaultValue?: FlagValue): FlagValue;
|
|
15
|
+
experiment(experimentKey: string): ExperimentResult;
|
|
16
|
+
/** Override a flag value for local testing. Only active when debug=true. */
|
|
17
|
+
overrideFlag(key: string, value: FlagValue): void;
|
|
18
|
+
/** Clear all debug overrides. */
|
|
19
|
+
clearOverrides(): void;
|
|
20
|
+
/** Get all current debug overrides (for debug menu UI). */
|
|
21
|
+
getOverrides(): Record<string, unknown>;
|
|
22
|
+
flush(): Promise<void>;
|
|
23
|
+
/** Notify the SDK of a route change in a single-page app. Emits a
|
|
24
|
+
* synthetic `$page_leave` for the prior route (if any) and resets
|
|
25
|
+
* the page-leave timer for the new path. */
|
|
26
|
+
recordPageView(path: string): void;
|
|
27
|
+
status(): SDKStatus;
|
|
28
|
+
destroy(): void;
|
|
29
|
+
/** Access the diagnostic event bus for runtime subscribe/unsubscribe. */
|
|
30
|
+
diagnostics(): DiagnosticBus;
|
|
31
|
+
/** Get buffered recent diagnostic events. */
|
|
32
|
+
getRecentDiagnostics(): DiagnosticEvent[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
declare class GoaTech implements IGoaTech {
|
|
36
|
+
private static instance;
|
|
37
|
+
private readonly cfg;
|
|
38
|
+
private readonly log;
|
|
39
|
+
private readonly bus;
|
|
40
|
+
private readonly context;
|
|
41
|
+
private readonly queue;
|
|
42
|
+
private readonly flagManager;
|
|
43
|
+
private readonly experimentManager;
|
|
44
|
+
private readonly identityManager;
|
|
45
|
+
private readonly configSync;
|
|
46
|
+
private readonly transport;
|
|
47
|
+
private readonly offlineQueue;
|
|
48
|
+
private readonly connectivity;
|
|
49
|
+
private readonly lifecycle;
|
|
50
|
+
private readonly errorCapture;
|
|
51
|
+
private readonly httpErrorCapture;
|
|
52
|
+
private readonly clickFrustrationCapture;
|
|
53
|
+
private flushTimer;
|
|
54
|
+
private destroyed;
|
|
55
|
+
private constructor();
|
|
56
|
+
/**
|
|
57
|
+
* Create a new, independent GoaTech instance.
|
|
58
|
+
* The caller owns the instance lifecycle — no global state.
|
|
59
|
+
* Preferred for React apps (pass instance to Context).
|
|
60
|
+
*/
|
|
61
|
+
static create(config: GoaTechConfig): GoaTech;
|
|
62
|
+
/**
|
|
63
|
+
* Create a singleton instance. Returns existing instance if already
|
|
64
|
+
* initialized (logs a warning). Call `destroy()` first to re-initialize.
|
|
65
|
+
*
|
|
66
|
+
* For React apps, prefer `GoaTech.create()` + Context instead.
|
|
67
|
+
*/
|
|
68
|
+
static init(config: GoaTechConfig): GoaTech;
|
|
69
|
+
/** Get the singleton instance. Throws if `init()` was never called. */
|
|
70
|
+
static getInstance(): GoaTech;
|
|
71
|
+
/**
|
|
72
|
+
* Returns true if the singleton has been initialized via `init()`.
|
|
73
|
+
* Useful for HMR guards and conditional initialization.
|
|
74
|
+
*/
|
|
75
|
+
static isInitialized(): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Queue an analytics event. Auto-flushes when the queue reaches
|
|
78
|
+
* `flushSize` (default 20) or when the periodic flush timer fires.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* gt.track("course_viewed", { course_id: "c_123", source: "catalog" });
|
|
82
|
+
*/
|
|
83
|
+
track(eventName: string, properties?: Record<string, unknown>): void;
|
|
84
|
+
/**
|
|
85
|
+
* Resolve a feature flag for the current device + identity. Reads
|
|
86
|
+
* the cached server-evaluated value from `/v1/config` (refreshed on
|
|
87
|
+
* `configRefreshInterval`). Fires `$flag_exposure` once per session
|
|
88
|
+
* per flag.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* if (gt.flag("new_checkout_flow", false)) {
|
|
92
|
+
* renderNewCheckout();
|
|
93
|
+
* }
|
|
94
|
+
*/
|
|
95
|
+
flag(flagKey: string, defaultValue?: FlagValue): FlagValue;
|
|
96
|
+
overrideFlag(key: string, value: FlagValue): void;
|
|
97
|
+
clearOverrides(): void;
|
|
98
|
+
getOverrides(): Record<string, unknown>;
|
|
99
|
+
/**
|
|
100
|
+
* Resolve the bucketed variant + payload for an experiment. Sticky
|
|
101
|
+
* per device. Fires `$experiment_exposure` once per session per
|
|
102
|
+
* experiment.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* const { variant, payload } = gt.experiment("hero_h1_copy_v1");
|
|
106
|
+
* if (variant !== "control") setHeadline((payload as { headline: string }).headline);
|
|
107
|
+
*/
|
|
108
|
+
experiment(experimentKey: string): ExperimentResult;
|
|
109
|
+
/**
|
|
110
|
+
* Tie the current device to a stable user id and merge traits onto
|
|
111
|
+
* the GoaTech user record. Re-identifying with a different userId
|
|
112
|
+
* clears the cached experiment assignments so the new identity
|
|
113
|
+
* gets fresh buckets.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* await api.login(form);
|
|
117
|
+
* gt.identify("user_abc123", { email: "jane@example.com", plan: "pro" });
|
|
118
|
+
*/
|
|
119
|
+
identify(userId: string, traits?: Record<string, unknown>): void;
|
|
120
|
+
/**
|
|
121
|
+
* Forget the current identity + experiment assignments and start a
|
|
122
|
+
* fresh anonymous session. Call on logout.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* await api.logout();
|
|
126
|
+
* gt.reset();
|
|
127
|
+
*/
|
|
128
|
+
reset(): void;
|
|
129
|
+
/**
|
|
130
|
+
* Drain any queued events to the GoaTech ingest endpoint. Useful
|
|
131
|
+
* before navigation in single-page apps and required before
|
|
132
|
+
* Vercel/Lambda function exits.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* router.beforeEach(async () => {
|
|
136
|
+
* await gt.flush();
|
|
137
|
+
* });
|
|
138
|
+
*/
|
|
139
|
+
flush(): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Notify the SDK of a route change. The first call starts a page-leave
|
|
142
|
+
* timer; subsequent calls emit a synthetic `$page_leave` for the prior
|
|
143
|
+
* route (with `exit_kind: "spa_nav"`) before resetting state. Wire
|
|
144
|
+
* this into your router — for Next.js, use `<PageViewTracker>` from
|
|
145
|
+
* `@sheepit-ai/react`, which calls this for you.
|
|
146
|
+
*
|
|
147
|
+
* Idempotent for repeat calls with the same path.
|
|
148
|
+
*/
|
|
149
|
+
recordPageView(path: string): void;
|
|
150
|
+
status(): SDKStatus;
|
|
151
|
+
diagnostics(): DiagnosticBus;
|
|
152
|
+
getRecentDiagnostics(): DiagnosticEvent[];
|
|
153
|
+
/**
|
|
154
|
+
* Stop all timers, drain remaining events, and tear down auto-error
|
|
155
|
+
* + lifecycle listeners. After `destroy()` further `track()` /
|
|
156
|
+
* `flag()` calls are no-ops. Idempotent.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* // Replacing the SDK instance (rare; usually just call once)
|
|
160
|
+
* const old = GoaTech.getInstance();
|
|
161
|
+
* old.destroy();
|
|
162
|
+
* const fresh = GoaTech.init({ apiKey: nextKey });
|
|
163
|
+
*/
|
|
164
|
+
destroy(): void;
|
|
165
|
+
private start;
|
|
166
|
+
private applyConfig;
|
|
167
|
+
private postIdentityResolve;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export { DiagnosticBus, DiagnosticEvent, ExperimentResult, FlagValue, GoaTech, GoaTechConfig, type IGoaTech, SDKStatus };
|