@truxl/javascript-sdk 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.
@@ -0,0 +1,27 @@
1
+ /**
2
+ * High-level event tracking helpers.
3
+ *
4
+ * Provides convenience wrappers around `TruxlClient.track()` for common
5
+ * event types such as custom events and page views. Each helper enriches
6
+ * the event payload with contextual browser information.
7
+ */
8
+ import { TruxlClient } from '../core/client';
9
+ /**
10
+ * Track a custom event.
11
+ *
12
+ * @param client The TruxlClient instance.
13
+ * @param eventName A descriptive name for the event (e.g. "button_click",
14
+ * "signup_started").
15
+ * @param properties Arbitrary key/value properties to attach to the event.
16
+ */
17
+ export declare function trackEvent(client: TruxlClient, eventName: string, properties?: Record<string, unknown>): void;
18
+ /**
19
+ * Track a page view event.
20
+ *
21
+ * Automatically captures the current URL, path, referrer, page title and
22
+ * other contextual data.
23
+ *
24
+ * @param client The TruxlClient instance.
25
+ * @param properties Optional extra properties to merge into the event.
26
+ */
27
+ export declare function trackPageView(client: TruxlClient, properties?: Record<string, unknown>): void;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Form submission tracking.
3
+ *
4
+ * Intercepts native `<form>` submit events via a delegated listener on
5
+ * `document` and tracks a `$form_submit` event with metadata about the
6
+ * form and its fields (excluding sensitive inputs such as passwords and
7
+ * credit card numbers).
8
+ */
9
+ import { TruxlClient } from '../core/client';
10
+ /**
11
+ * Start tracking form submissions. Idempotent -- calling this multiple
12
+ * times will not register duplicate listeners.
13
+ *
14
+ * @param client The TruxlClient instance to report events to.
15
+ */
16
+ export declare function startFormTracking(client: TruxlClient): void;
17
+ /**
18
+ * Stop tracking form submissions and remove the event listener.
19
+ */
20
+ export declare function stopFormTracking(): void;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Beacon transport for page unload scenarios.
3
+ *
4
+ * Uses `navigator.sendBeacon()` which is designed to reliably deliver small
5
+ * payloads even when the page is being closed. This is the preferred
6
+ * transport for `beforeunload` / `visibilitychange` events where a normal
7
+ * `fetch()` would likely be cancelled by the browser.
8
+ *
9
+ * Falls back to a synchronous `XMLHttpRequest` (keepalive-style) when
10
+ * `sendBeacon` is not available.
11
+ */
12
+ import { TruxlConfig } from '../core/config';
13
+ export interface BeaconTransportOptions {
14
+ config: Required<TruxlConfig>;
15
+ }
16
+ export declare class BeaconTransport {
17
+ private config;
18
+ constructor(options: BeaconTransportOptions);
19
+ /**
20
+ * Send a payload via `navigator.sendBeacon`. Returns `true` when the
21
+ * browser accepted the request for delivery (note: this does NOT
22
+ * guarantee the server received it).
23
+ *
24
+ * Because `sendBeacon` is fire-and-forget, HMAC signing is performed
25
+ * synchronously using the pre-computed signature passed in via headers
26
+ * encoded as a Blob.
27
+ */
28
+ send(payload: unknown): Promise<boolean>;
29
+ /**
30
+ * Synchronous variant that can be called from `beforeunload` handlers
31
+ * where async work is unreliable. Requires the caller to pre-compute
32
+ * the HMAC signature.
33
+ */
34
+ sendSync(payload: unknown, precomputedSignature: string): boolean;
35
+ private isBeaconAvailable;
36
+ private sendViaBeacon;
37
+ private sendViaXHR;
38
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Fetch-based HTTP transport with exponential back-off retry.
3
+ *
4
+ * Retry delays follow the pattern: baseDelay * 2^attempt
5
+ * attempt 0 -> 1 s
6
+ * attempt 1 -> 2 s
7
+ * attempt 2 -> 4 s
8
+ * attempt 3 -> 8 s
9
+ * ...
10
+ * capped at MAX_RETRY_DELAY (60 s)
11
+ *
12
+ * Only 5xx (server) errors and network failures are retried. 4xx responses
13
+ * are treated as permanent failures and are NOT retried.
14
+ */
15
+ import { TruxlConfig } from '../core/config';
16
+ import { Transport, TransportResult } from './transport';
17
+ export interface HttpTransportOptions {
18
+ /** Fully resolved TruxlConfig (all optional fields filled in). */
19
+ config: Required<TruxlConfig>;
20
+ }
21
+ /**
22
+ * Low-level HTTP transport. Send a JSON payload to the Truxl ingestion
23
+ * endpoint with HMAC signing and automatic retry on transient errors.
24
+ */
25
+ export declare class HttpTransport implements Transport {
26
+ private config;
27
+ constructor(options: HttpTransportOptions);
28
+ /**
29
+ * Send a JSON-serialisable payload to the batch endpoint.
30
+ *
31
+ * @param payload The body to POST (will be JSON-stringified).
32
+ * @returns A result object indicating success/failure and number of
33
+ * retries performed.
34
+ */
35
+ send(payload: unknown): Promise<TransportResult>;
36
+ private sendWithRetry;
37
+ /**
38
+ * Calculate the delay for a given retry attempt and sleep.
39
+ * delay = min(baseDelay * 2^attempt, MAX_RETRY_DELAY)
40
+ */
41
+ private wait;
42
+ }
@@ -0,0 +1,9 @@
1
+ export interface TransportResult {
2
+ ok: boolean;
3
+ status: number;
4
+ retries: number;
5
+ }
6
+ export interface Transport {
7
+ send(payload: unknown): Promise<TransportResult>;
8
+ destroy?(): void;
9
+ }
@@ -0,0 +1,19 @@
1
+ import { TruxlConfig } from '../core/config';
2
+ import { Transport, TransportResult } from './transport';
3
+ export interface WebSocketTransportOptions {
4
+ config: Required<TruxlConfig>;
5
+ }
6
+ export declare class WebSocketTransport implements Transport {
7
+ private config;
8
+ private ws;
9
+ private reconnectAttempt;
10
+ private reconnectTimer;
11
+ private pendingMessages;
12
+ private connected;
13
+ private destroyed;
14
+ constructor(options: WebSocketTransportOptions);
15
+ send(payload: unknown): Promise<TransportResult>;
16
+ destroy(): void;
17
+ private connect;
18
+ private scheduleReconnect;
19
+ }