@growth-loop/sdk 0.1.1
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 +202 -0
- package/dist/browser.d.ts +13 -0
- package/dist/browser.js +4512 -0
- package/dist/browser.js.map +1 -0
- package/dist/client-CC-8sBba.d.ts +60 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +4381 -0
- package/dist/index.js.map +1 -0
- package/dist/node.d.ts +10 -0
- package/dist/node.js +4345 -0
- package/dist/node.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Properties, EventContext, IngestPayload } from '@growth/shared';
|
|
2
|
+
|
|
3
|
+
interface Transport {
|
|
4
|
+
send(url: string, payload: IngestPayload, headers: Record<string, string>): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
interface GrowthOptions {
|
|
7
|
+
apiKey: string;
|
|
8
|
+
host?: string;
|
|
9
|
+
flushInterval?: number;
|
|
10
|
+
batchSize?: number;
|
|
11
|
+
defaultContext?: EventContext;
|
|
12
|
+
transport?: Transport;
|
|
13
|
+
onError?: (error: Error) => void;
|
|
14
|
+
debug?: boolean;
|
|
15
|
+
}
|
|
16
|
+
interface TrackOptions {
|
|
17
|
+
distinctId?: string;
|
|
18
|
+
timestamp?: Date;
|
|
19
|
+
context?: EventContext;
|
|
20
|
+
}
|
|
21
|
+
interface IdentifyOptions {
|
|
22
|
+
distinctId: string;
|
|
23
|
+
properties?: Properties;
|
|
24
|
+
context?: EventContext;
|
|
25
|
+
}
|
|
26
|
+
interface GrowthClient {
|
|
27
|
+
track(name: string, properties?: Properties, options?: TrackOptions): void;
|
|
28
|
+
identify(options: IdentifyOptions): void;
|
|
29
|
+
alias(distinctId: string, previousId: string): void;
|
|
30
|
+
group(groupType: string, groupKey: string, properties?: Properties): void;
|
|
31
|
+
setContext(context: EventContext): void;
|
|
32
|
+
setDistinctId(id: string): void;
|
|
33
|
+
flush(): Promise<void>;
|
|
34
|
+
shutdown(): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
declare function createClient(options: GrowthOptions): GrowthClient;
|
|
37
|
+
declare class Growth implements GrowthClient {
|
|
38
|
+
private readonly apiKey;
|
|
39
|
+
private readonly host;
|
|
40
|
+
private readonly transport;
|
|
41
|
+
private readonly queue;
|
|
42
|
+
private readonly onError;
|
|
43
|
+
private readonly debug;
|
|
44
|
+
private context;
|
|
45
|
+
private distinctId;
|
|
46
|
+
private flushTimer;
|
|
47
|
+
private closed;
|
|
48
|
+
constructor(options: GrowthOptions);
|
|
49
|
+
setDistinctId(id: string): void;
|
|
50
|
+
setContext(context: EventContext): void;
|
|
51
|
+
track(name: string, properties?: Properties, options?: TrackOptions): void;
|
|
52
|
+
identify(options: IdentifyOptions): void;
|
|
53
|
+
alias(distinctId: string, previousId: string): void;
|
|
54
|
+
group(groupType: string, groupKey: string, properties?: Properties): void;
|
|
55
|
+
flush(): Promise<void>;
|
|
56
|
+
shutdown(): Promise<void>;
|
|
57
|
+
private send;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { type GrowthClient as G, type IdentifyOptions as I, type TrackOptions as T, Growth as a, type GrowthOptions as b, type Transport as c, createClient as d };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { G as GrowthClient, T as TrackOptions } from './client-CC-8sBba.js';
|
|
2
|
+
export { a as Growth, b as GrowthOptions, I as IdentifyOptions, c as Transport, d as createClient } from './client-CC-8sBba.js';
|
|
3
|
+
import { Properties } from '@growth/shared';
|
|
4
|
+
export { EventContext, Properties, TrackEvent } from '@growth/shared';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Higher-level instrumentation: spans, steps, tracked clicks.
|
|
8
|
+
*
|
|
9
|
+
* These wrap the low-level `track()` API in patterns the agent (and a human)
|
|
10
|
+
* can drop into existing code with minimal change. Designed to be applied
|
|
11
|
+
* automatically by `claude /growth init`.
|
|
12
|
+
*
|
|
13
|
+
* const checkout = growth.span('checkout', async () => { ... });
|
|
14
|
+
* const onLogin = growth.button('login_clicked', () => doLogin());
|
|
15
|
+
* growth.step('activation.invited_team', { team_id });
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
interface SpanOptions extends TrackOptions {
|
|
19
|
+
/** Static properties merged into both started/completed/failed events. */
|
|
20
|
+
properties?: Properties;
|
|
21
|
+
/** Optional dynamic property extractor — runs with the function args (or result on success). */
|
|
22
|
+
enrich?: (args: unknown[], phase: 'start' | 'success' | 'failure', result?: unknown) => Properties | undefined;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Wraps an async or sync function so it emits start + completed events with
|
|
26
|
+
* latency, plus a failed event on throw. Returns a function with the same
|
|
27
|
+
* signature.
|
|
28
|
+
*
|
|
29
|
+
* Naming convention: emits `<name>.started`, `<name>.completed`, `<name>.failed`.
|
|
30
|
+
*/
|
|
31
|
+
declare function span<TArgs extends unknown[], TRet>(growth: GrowthClient, name: string, fn: (...args: TArgs) => TRet | Promise<TRet>, options?: SpanOptions): (...args: TArgs) => Promise<TRet>;
|
|
32
|
+
/**
|
|
33
|
+
* Marks one funnel step. Cheaper than span — single event, no timing.
|
|
34
|
+
*
|
|
35
|
+
* growth.step('onboarding.completed_setup');
|
|
36
|
+
* growth.step('signup.passed_email_verification', { email_domain });
|
|
37
|
+
*/
|
|
38
|
+
declare function step(growth: GrowthClient, funnelStep: string, properties?: Properties, options?: TrackOptions): void;
|
|
39
|
+
/**
|
|
40
|
+
* Wraps an event handler (e.g. button onClick) so the click is logged before
|
|
41
|
+
* the handler fires. Synchronous and reentrant-safe.
|
|
42
|
+
*
|
|
43
|
+
* <button onClick={growth.button('login_clicked', onLogin)}>Login</button>
|
|
44
|
+
*/
|
|
45
|
+
declare function button<TArgs extends unknown[], TRet>(growth: GrowthClient, name: string, handler?: (...args: TArgs) => TRet, properties?: Properties): (...args: TArgs) => TRet | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Adds the helpers above as methods on a Growth client instance. Call once
|
|
48
|
+
* after constructing the client and the API surface becomes:
|
|
49
|
+
*
|
|
50
|
+
* const growth = createBrowserClient({ apiKey, host });
|
|
51
|
+
* instrument(growth);
|
|
52
|
+
* growth.span('checkout', fn); // ✓ now available
|
|
53
|
+
*/
|
|
54
|
+
interface GrowthInstrumented extends GrowthClient {
|
|
55
|
+
span: <TArgs extends unknown[], TRet>(name: string, fn: (...args: TArgs) => TRet | Promise<TRet>, options?: SpanOptions) => (...args: TArgs) => Promise<TRet>;
|
|
56
|
+
step: (funnelStep: string, properties?: Properties, options?: TrackOptions) => void;
|
|
57
|
+
button: <TArgs extends unknown[], TRet>(name: string, handler?: (...args: TArgs) => TRet, properties?: Properties) => (...args: TArgs) => TRet | undefined;
|
|
58
|
+
}
|
|
59
|
+
declare function instrument(growth: GrowthClient): GrowthInstrumented;
|
|
60
|
+
|
|
61
|
+
export { GrowthClient, type GrowthInstrumented, type SpanOptions, TrackOptions, button, instrument, span, step };
|