@newtalaria/browser 0.1.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 ADDED
@@ -0,0 +1,123 @@
1
+ # `@newtalaria/browser`
2
+
3
+ Browser SDK for [Talaria](https://github.com/) — error capture and **session replay** (rrweb event streams, not video).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @newtalaria/browser
9
+ ```
10
+
11
+ From this monorepo:
12
+
13
+ ```bash
14
+ cd new_talaria_js/packages/browser
15
+ npm install
16
+ npm run build
17
+ ```
18
+
19
+ ## Quick start
20
+
21
+ ```ts
22
+ import { Talaria } from '@newtalaria/browser';
23
+
24
+ Talaria.init({
25
+ // Serverpod base URL (no trailing path)
26
+ dsn: 'http://localhost:8080',
27
+ apiKey: 'tal_live_…', // full raw key from createApiKey
28
+ environment: 'development',
29
+ release: '1.0.0',
30
+ // Continuous session upload (0–1). Default 0 = buffer only until an error.
31
+ replaysSessionSampleRate: 0,
32
+ // On error, flush buffer + attach replayId (0–1). Default 1.
33
+ replaysOnErrorSampleRate: 1,
34
+ maskAllInputs: true, // default
35
+ });
36
+
37
+ try {
38
+ throw new Error('Something broke');
39
+ } catch (error) {
40
+ await Talaria.captureException(error);
41
+ }
42
+
43
+ await Talaria.captureMessage('Checkout opened', 'info');
44
+ console.log('replay', Talaria.getReplayId());
45
+
46
+ await Talaria.flush();
47
+ await Talaria.close();
48
+ ```
49
+
50
+ `Talaria.init` also installs `window.onerror` / `unhandledrejection` handlers unless you pass `disableDefaultIntegrations: true`.
51
+
52
+ ## Serverpod URL pattern
53
+
54
+ Talaria uses **Serverpod RPC**, not REST resource URLs:
55
+
56
+ | Call | Method | URL |
57
+ | --- | --- | --- |
58
+ | Start replay | `POST` | `{baseUrl}/replays/start` |
59
+ | Upload segment | `POST` | `{baseUrl}/replays/ingestSegment` |
60
+ | Finish replay | `POST` | `{baseUrl}/replays/finish` |
61
+ | Ingest event | `POST` | `{baseUrl}/events/ingest` |
62
+
63
+ Local default: `http://localhost:8080`.
64
+
65
+ Bodies are JSON with named parameters and `__className__` on typed inputs:
66
+
67
+ ```json
68
+ {
69
+ "input": {
70
+ "__className__": "StartReplayInput",
71
+ "replayId": "…",
72
+ "environment": "development",
73
+ "sessionId": "…",
74
+ "url": "http://localhost:5173/"
75
+ }
76
+ }
77
+ ```
78
+
79
+ Auth (ingest):
80
+
81
+ - `X-API-Key: tal_live_…` (preferred)
82
+ - or `Authorization: Bearer tal_live_…`
83
+
84
+ ### ByteData (`gzipBytes`)
85
+
86
+ Serverpod serializes `ByteData` as a wrapped base64 string:
87
+
88
+ ```text
89
+ decode('<base64>', 'base64')
90
+ ```
91
+
92
+ Segment payloads are a **gzip-compressed JSON array** of rrweb events.
93
+
94
+ ## Replay sampling
95
+
96
+ | Mode | Behavior |
97
+ | --- | --- |
98
+ | Session sample hit | `replays/start` immediately; segments upload every ~5s or ~100KB |
99
+ | Session sample miss | Record into a ~60s ring buffer; nothing uploaded until an error sample hits |
100
+ | Error sample hit | Enable upload, flush buffer, send event with `replayId` |
101
+ | `pagehide` / `close` | Flush pending segments with `fetch` `keepalive`, then `replays/finish` |
102
+
103
+ Custom rrweb events:
104
+
105
+ - `talaria-console` — console level + args (truncated)
106
+ - `talaria-network` — method, redacted URL, status, duration (no bodies / no auth headers)
107
+
108
+ Privacy defaults: `maskAllInputs: true`, password fields masked, `[data-talaria-mask]` blocked.
109
+
110
+ ## Public API
111
+
112
+ | API | Description |
113
+ | --- | --- |
114
+ | `Talaria.init(options)` | Configure + start recording |
115
+ | `Talaria.captureException(error)` | Ingest error (+ replay link when sampled) |
116
+ | `Talaria.captureMessage(message, level?)` | Ingest message |
117
+ | `Talaria.getReplayId()` | Active upload replay id, or `null` |
118
+ | `Talaria.flush()` | Upload buffered segments |
119
+ | `Talaria.close()` | Stop recording, flush, finish |
120
+
121
+ ## Example
122
+
123
+ See [`../../examples/sdk-spa`](../../examples/sdk-spa) for a minimal page wired to `localhost:8080`.
@@ -0,0 +1,35 @@
1
+ import type { CaptureContext, SeverityLevel, TalariaInitOptions } from './types.js';
2
+ export declare class TalariaClient {
3
+ private options;
4
+ private transport;
5
+ private replayId;
6
+ private sessionId;
7
+ private recorder;
8
+ private buffer;
9
+ private uploadEnabled;
10
+ private startedOnServer;
11
+ private finishedOnServer;
12
+ private segmentIndex;
13
+ private flushTimer;
14
+ private uploadChain;
15
+ private closed;
16
+ private teardowns;
17
+ init(options: TalariaInitOptions): void;
18
+ getReplayId(): string | null;
19
+ captureException(error: unknown, context?: CaptureContext): Promise<void>;
20
+ captureMessage(message: string, level?: SeverityLevel, context?: CaptureContext): Promise<void>;
21
+ flush(opts?: {
22
+ reason?: string;
23
+ keepalive?: boolean;
24
+ finish?: boolean;
25
+ }): Promise<void>;
26
+ close(): Promise<void>;
27
+ private onRrwebEvent;
28
+ private capture;
29
+ private installGlobalHandlers;
30
+ private enqueueUpload;
31
+ private ensureStarted;
32
+ private uploadPendingSegments;
33
+ private finishOnServer;
34
+ }
35
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,aAAa,EACb,kBAAkB,EACnB,MAAM,YAAY,CAAC;AA6DpB,qBAAa,aAAa;IACxB,OAAO,CAAC,OAAO,CAAgC;IAC/C,OAAO,CAAC,SAAS,CAAmC;IACpD,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,QAAQ,CAA+B;IAC/C,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,UAAU,CAA+C;IACjE,OAAO,CAAC,WAAW,CAAoC;IACvD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAkB;IAEnC,IAAI,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI;IA0DvC,WAAW,IAAI,MAAM,GAAG,IAAI;IAItB,gBAAgB,CACpB,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,IAAI,CAAC;IAcV,cAAc,CAClB,OAAO,EAAE,MAAM,EACf,KAAK,GAAE,aAAsB,EAC7B,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,IAAI,CAAC;IASV,KAAK,CAAC,IAAI,CAAC,EAAE;QACjB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,MAAM,CAAC,EAAE,OAAO,CAAC;KAClB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBX,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAyB5B,OAAO,CAAC,YAAY;YAcN,OAAO;IA4DrB,OAAO,CAAC,qBAAqB;IA6B7B,OAAO,CAAC,aAAa;YAKP,aAAa;YAiBb,qBAAqB;YAqCrB,cAAc;CAkB7B"}
@@ -0,0 +1,33 @@
1
+ import type { CaptureContext, SeverityLevel, TalariaInitOptions } from './types.js';
2
+ /**
3
+ * Talaria browser SDK — error capture + session replay.
4
+ *
5
+ * ```ts
6
+ * import { Talaria } from '@newtalaria/browser';
7
+ *
8
+ * Talaria.init({
9
+ * dsn: 'http://localhost:8080',
10
+ * apiKey: 'tal_live_…',
11
+ * environment: 'development',
12
+ * replaysOnErrorSampleRate: 1,
13
+ * });
14
+ *
15
+ * try {
16
+ * throw new Error('boom');
17
+ * } catch (e) {
18
+ * await Talaria.captureException(e);
19
+ * }
20
+ * ```
21
+ */
22
+ export declare const Talaria: {
23
+ init(options: TalariaInitOptions): void;
24
+ captureException(error: unknown, context?: CaptureContext): Promise<void>;
25
+ captureMessage(message: string, level?: SeverityLevel, context?: CaptureContext): Promise<void>;
26
+ getReplayId(): string | null;
27
+ flush(): Promise<void>;
28
+ close(): Promise<void>;
29
+ };
30
+ export type { CaptureContext, Environment, SeverityLevel, TalariaInitOptions, } from './types.js';
31
+ export { TalariaClient } from './client.js';
32
+ export default Talaria;
33
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAIpB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,OAAO;kBACJ,kBAAkB,GAAG,IAAI;4BAIf,OAAO,YAAY,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;4BAK9D,MAAM,UACP,aAAa,YACX,cAAc,GACvB,OAAO,CAAC,IAAI,CAAC;mBAID,MAAM,GAAG,IAAI;aAInB,OAAO,CAAC,IAAI,CAAC;aAIb,OAAO,CAAC,IAAI,CAAC;CAGvB,CAAC;AAEF,YAAY,EACV,cAAc,EACd,WAAW,EACX,aAAa,EACb,kBAAkB,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,eAAe,OAAO,CAAC"}