@koderlabs/tasks-sdk 0.1.0 → 0.1.2

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.
Files changed (2) hide show
  1. package/README.md +177 -6
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,9 +1,180 @@
1
- # Proprietary Software
1
+ # @koderlabs/tasks-sdk
2
2
 
3
- KoderLabs proprietary. All rights reserved.
3
+ > Runtime: any JS — browser, Node, React Native, edge workers.
4
+ > Platform-agnostic core for the **InstantTasks SDK suite**.
4
5
 
5
- See the bundled `LICENSE` for terms. No grant of any rights, express or
6
- implied, is conferred by access to or possession of this package. A
7
- separate signed written licence from KoderLabs is required for any use.
6
+ Core client + transport. Owns `init()`, the singleton client, span/trace IDs, the
7
+ integration registration surface, request signing, PII scrubbing, retries +
8
+ backoff, and the platform abstractions every other package plugs into.
8
9
 
9
- Licensing inquiries: jawaidgadiwala@gmail.com
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install @koderlabs/tasks-sdk
14
+ # or
15
+ pnpm add @koderlabs/tasks-sdk
16
+ # or
17
+ yarn add @koderlabs/tasks-sdk
18
+ ```
19
+
20
+ ## Quick start
21
+
22
+ ```ts
23
+ import { init } from '@koderlabs/tasks-sdk';
24
+
25
+ const client = init({
26
+ projectId: 'FE', // Project key from InstantTasks
27
+ accessKey: 'sk_live_…', // SDK ingest key (Project → SDK Keys)
28
+ endpoint: 'https://tasks.koderlabs.net', // root only — no /api/v1 suffix
29
+ release: process.env.APP_VERSION, // commit SHA or semver
30
+ environment: process.env.NODE_ENV,
31
+ integrations: [], // see suite map below
32
+ });
33
+ ```
34
+
35
+ `init()` is **idempotent**. Calling it again synchronously flushes spans, runs
36
+ integration teardowns, and replaces the prior client. Safe across HMR and React
37
+ StrictMode double-mount.
38
+
39
+ ## The InstantTasks SDK suite
40
+
41
+ Pick the packages that match your runtime; ignore the rest.
42
+
43
+ ```
44
+ @koderlabs/tasks-sdk (core — this package)
45
+ @koderlabs/tasks-sdk-types (wire shapes)
46
+
47
+ ┌──────────────────┼──────────────────┬────────────────┐
48
+ │ Web (DOM) │ React Native │ Server (Node) │ Tooling
49
+ ├ tasks-sdk-web-errors ├ tasks-sdk-rn ├ tasks-sdk-nestjs ├ tasks-cli
50
+ ├ tasks-sdk-web-network └ tasks-sdk-rn-native │ ├ tasks-mcp
51
+ ├ tasks-sdk-web-reporter (native crashes) │
52
+
53
+ Framework adapters
54
+ ├ @koderlabs/tasks-sdk-react — Provider, hooks, ErrorBoundary
55
+ ├ @koderlabs/tasks-sdk-nextjs — next.config plugin + sourcemap upload
56
+ └ @koderlabs/tasks-sdk-vue — Vue 3 plugin
57
+ ```
58
+
59
+ ### Pick your stack
60
+
61
+ | Stack | Install |
62
+ |---|---|
63
+ | **Vanilla browser** | `tasks-sdk` + `tasks-sdk-web-errors` + `tasks-sdk-web-network` (+ `-web-reporter` for bug modal) |
64
+ | **React** | `tasks-sdk` + `tasks-sdk-react` + the web-* packages above |
65
+ | **Next.js** | `tasks-sdk` + `tasks-sdk-nextjs` + the web-* packages above |
66
+ | **Vue 3** | `tasks-sdk` + `tasks-sdk-vue` + the web-* packages above |
67
+ | **React Native** | `tasks-sdk` + `tasks-sdk-rn` (+ `-rn-native` for native crashes, `-rn-reporter` for bug modal) |
68
+ | **NestJS** | `tasks-sdk` + `tasks-sdk-nestjs` |
69
+ | **Other Node** | `tasks-sdk` (use `reportError()` from `getClient()` directly) |
70
+ | **Sourcemap/symbol upload** | `tasks-cli` |
71
+ | **MCP agent integration** | `tasks-mcp` (separate npm package) |
72
+
73
+ ## `InitOptions`
74
+
75
+ | Field | Type | Default | Notes |
76
+ |---|---|---|---|
77
+ | `projectId` | `string` | required | Project key. Sent as `X-Project-Id`. CRLF-validated. |
78
+ | `accessKey` | `string` | required | SDK ingest key. Sent as `Authorization: Bearer …`. CRLF-validated. |
79
+ | `endpoint` | `string` | `https://tasks.koderlabs.net` | Root only. SDK appends `/api/v1/sdk/events`. HTTPS-only outside localhost (SSRF guard). |
80
+ | `release` | `string` | — | Commit SHA or semver. Required for source-map symbolication. |
81
+ | `environment` | `string` | — | `production`, `staging`, etc. |
82
+ | `user` | `{ id?, email? }` | — | Default user attached to events. |
83
+ | `customData` | `Record<string, Serializable>` | — | Default custom data. |
84
+ | `integrations` | `Integration[]` | `[]` | Plug-in integrations. |
85
+ | `debug` | `boolean` | `false` | Internal-logger output. Suppressed in `NODE_ENV=production` regardless. |
86
+ | `dryRun` | `boolean` | `false` | Build events but don't POST. |
87
+ | `beforeSend` | `(event) => event \| null` | — | Mutate / drop events. May be async. **Fail-closed**: a throw drops the event and emits `beforesend_error`. |
88
+ | `scrub` | `boolean \| (event) => event` | `true` | Built-in PII scrubber (Authorization/Cookie headers, `password`/`token`/`secret` fields, URL query params). Set `false` to disable; pass a function to override. |
89
+ | `fetch` | `typeof fetch` | `globalThis.fetch` | Custom fetch impl (e.g. RN TLS-pinned fetch). |
90
+ | `signingSecret` | `string` | — | If set, every request is HMAC-SHA256 signed (`X-IT-Timestamp`, `X-IT-Nonce`, `X-IT-Signature`). Backend verifies when project requires signed events. |
91
+
92
+ ## Surface
93
+
94
+ | Export | Purpose |
95
+ |---|---|
96
+ | `init(opts)` | Create / replace the singleton client. |
97
+ | `getClient()` | Read the current client or `null`. |
98
+ | `Client` | Class (rarely used directly). |
99
+ | `newTraceId()`, `newSpanId()` | ID generators for manual spans. |
100
+ | `captureWebVitals(opts)` | LCP / CLS / INP / FCP / TTFB capture (browser only). Debounced per metric. |
101
+ | `TransportHttpError`, `PayloadTooLargeError` | Error types thrown by transport. |
102
+ | Types | `InitOptions`, `Integration`, `ClientInterface`, `SpanRecord`, `ActiveSpan`, `SpanOptions`, `WebVitalsOptions` + all `@koderlabs/tasks-sdk-types` re-exports. |
103
+
104
+ ## Behaviour
105
+
106
+ | Concern | Behaviour |
107
+ |---|---|
108
+ | Request timeout | 10s via `AbortSignal.timeout()` (polyfilled for old RN) |
109
+ | Payload cap | 500 KB serialised. Throws `PayloadTooLargeError` — no retry. |
110
+ | Retry | Exp backoff (1s, 2s) for 5xx; never for 4xx. Max 2 retries. |
111
+ | 429 handling | Honors `Retry-After` header; sets cooldown window; drops subsequent events until elapsed. Listener event `send_rate_limited`. |
112
+ | PII scrubbing | Default on. Runs BEFORE `beforeSend` so caller sees scrubbed event. |
113
+ | `init()` re-call | Tears down prior client synchronously: flush spans, stop interval, run each integration's `teardown()`. |
114
+ | `beforeSend` failure | Drops event, emits `beforesend_error` (fail-closed). |
115
+ | Console output | Gated by `debug && NODE_ENV!=='production'`. Programming errors always log via `internalError`. |
116
+ | Span batching | 50-span buffer, 5s flush interval. `client.flushSpans()` for explicit drain. |
117
+
118
+ ## Writing an integration
119
+
120
+ ```ts
121
+ import type { Integration, ClientInterface } from '@koderlabs/tasks-sdk';
122
+
123
+ export function myIntegration(): Integration {
124
+ let teardown = () => {};
125
+ return {
126
+ name: 'my-integration',
127
+ setup(client: ClientInterface) {
128
+ // Hook into globals, register listeners, etc.
129
+ teardown = () => { /* undo */ };
130
+ },
131
+ teardown() { teardown(); },
132
+ };
133
+ }
134
+ ```
135
+
136
+ `init()` calls `setup()` in registration order. On re-init, every prior
137
+ integration's `teardown()` runs before the new client boots.
138
+
139
+ ## Transport contract
140
+
141
+ ```
142
+ POST {endpoint}/api/v1/sdk/events
143
+ Headers:
144
+ Authorization: Bearer {accessKey}
145
+ X-Project-Id: {projectId}
146
+ Content-Type: application/json
147
+ [X-IT-Timestamp / X-IT-Nonce / X-IT-Signature if signingSecret set]
148
+ Body: AnyEvent (see @koderlabs/tasks-sdk-types)
149
+ Response: { id: string, ticketKey?: string }
150
+ ```
151
+
152
+ Multipart variant `/api/v1/sdk/events/multipart` for bug reports with screenshots.
153
+
154
+ ## Caveats
155
+
156
+ - `endpoint` must be the **root** URL. Do not include `/api/v1` — SDK appends.
157
+ - Default endpoint `https://tasks.koderlabs.net` emits a one-time deprecation
158
+ warning. Set `endpoint` explicitly; default will throw in next major.
159
+ - No offline buffer in v1. Events dropped during net loss are lost (unless 429
160
+ with `Retry-After` — then queued briefly).
161
+ - Spans are best-effort: flushed on 5s interval and on `client.flushSpans()`.
162
+ Process exits before flush = lost.
163
+ - `signingSecret` only signs JSON bodies. Multipart (bug reports w/
164
+ screenshots) is NOT signed — multipart boundaries make the hash unstable.
165
+
166
+ ## Versioning
167
+
168
+ This package and all `@koderlabs/tasks-sdk-*` siblings move together until v1.0.
169
+ Always upgrade them as a set (`@koderlabs/tasks-sdk` + `@koderlabs/tasks-sdk-XXX`
170
+ at the same version).
171
+
172
+ ---
173
+
174
+ ## License
175
+
176
+ KoderLabs proprietary. See [`LICENSE`](./LICENSE) for terms. Use of this package
177
+ requires a separate signed written agreement with KoderLabs; access alone
178
+ confers no rights.
179
+
180
+ Licensing inquiries: **jawaidgadiwala@gmail.com**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koderlabs/tasks-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "InstantTasks SDK — platform-agnostic event + span client.",
5
5
  "keywords": [
6
6
  "instanttasks",
@@ -40,7 +40,7 @@
40
40
  ],
41
41
  "sideEffects": false,
42
42
  "dependencies": {
43
- "@koderlabs/tasks-sdk-types": "0.1.0"
43
+ "@koderlabs/tasks-sdk-types": "0.1.2"
44
44
  },
45
45
  "devDependencies": {
46
46
  "tsup": "^8.3.0",
@@ -51,7 +51,7 @@
51
51
  "node": ">=20"
52
52
  },
53
53
  "publishConfig": {
54
- "access": "restricted"
54
+ "access": "public"
55
55
  },
56
56
  "scripts": {
57
57
  "build": "tsup",