@infinitetoken/lumber-kit 0.6.0 → 0.7.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 CHANGED
@@ -125,6 +125,19 @@ import { LogLevel, LogRecord, LogEncrypted, LogPayload, LogsQuery } from '@infin
125
125
 
126
126
  A plugin sends only the token to the API (`Authorization: Bearer <token>`) and encrypts with the rest, so the encryption key never leaves it.
127
127
 
128
+ ### Plugins
129
+
130
+ | Export | Kind | Purpose |
131
+ |--------|------|---------|
132
+ | `LogIngestBody` | interface | `POST /logs`' body: `{ level, encrypted }` |
133
+ | `LogData` | interface | What a log call takes beside its message: `requestId`, `traceId`, `context`, `metadata` and any other keys |
134
+ | `buildLogPayload` | function | The `LogPayload` a log call encrypts, from its level, message, data and the plugin's automatic context |
135
+ | `DEFAULT_API_ENDPOINT` | constant | `https://api.lumber.infinitetoken.com` |
136
+ | `LOG_KEY_VERSION` | constant | `LogEncrypted`'s `keyVersion` (1) |
137
+ | `logDelivery` | object | Attempts, retry delays and the pause after a 429 |
138
+ | `logDeliveryOutcome` | function | `sent`, `retry`, `drop` or `pause` for a `POST /logs` status (null for a network error) |
139
+ | `logRetryDelayMs` | function | The wait after a log's nth failed attempt: 1s, 2s, 4s, up to 30s |
140
+
128
141
  ## Wire format
129
142
 
130
143
  All log content is E2E encrypted before leaving the client. `LogRecord` contains only:
@@ -135,14 +148,14 @@ All log content is E2E encrypted before leaving the client. `LogRecord` contains
135
148
  createdAt: string // ISO 8601
136
149
  updatedAt: string // ISO 8601
137
150
  appId: string
138
- encrypted: LogEncrypted // opaque blob — server cannot read this
151
+ encrypted: LogEncrypted // opaque to the server, which can't read it
139
152
  }
140
153
  ```
141
154
 
142
155
  `LogEncrypted` uses AES-256-GCM:
143
- - `nonce` — base64(random IV, 12 bytes)
144
- - `payload` — base64(authTag[16 bytes] + ciphertext)
145
- - `keyVersion` — always `1` for the current format; changes are semver major
156
+ - `nonce`: base64(random IV, 12 bytes)
157
+ - `payload`: base64(authTag[16 bytes] + ciphertext)
158
+ - `keyVersion`: always `1` for the current format; changes are semver major
146
159
 
147
160
  The plaintext shape inside `payload` is `LogPayload`:
148
161
 
@@ -157,6 +170,10 @@ The plaintext shape inside `payload` is `LogPayload`:
157
170
  }
158
171
  ```
159
172
 
173
+ ## Other languages
174
+
175
+ TypeScript can't be imported from Python or Go, so the kit ships its contract in `contract/`: a JSON Schema of every exported type (`schema.json`, generated from the TypeScript by `npm run contract`) and known answers (`vectors.json`) for API keys, AES-256-GCM, payloads and delivery, which the kit's own tests check against its code. Lumber-Python and Lumber-Go test against a pinned copy. See `contract/README.md`.
176
+
160
177
  ## const enum and Babel consumers
161
178
 
162
179
  `LogLevel` is a TypeScript `const enum`. TypeScript consumers have values inlined at compile time (zero runtime overhead).
@@ -0,0 +1,21 @@
1
+ # Lumber's contract
2
+
3
+ The shapes and known answers every Lumber client is tested against, whatever its language. Lumber-Kit's TypeScript is the source: these files are generated from it or checked against it by the kit's own tests, and they ship in the npm package, so a client pins them by the kit's version.
4
+
5
+ - `schema.json`: a JSON Schema (draft-07) of every type the kit exports, generated by `npm run contract`. A plugin sends `LogIngestBody` to `POST /logs` and encrypts a `LogPayload` into its `encrypted`. `LogPayload` allows no other keys, so a misspelled field (`request_id`) fails validation rather than going missing in the app.
6
+ - `vectors.json`: known answers.
7
+ - `constants`: the default endpoint, ingestion path, key version, key, nonce and tag sizes, log levels and the delivery policy.
8
+ - `apiKeys`: how an API key (`<token>.<encryptionKey>`) splits.
9
+ - `encryption`: AES-256-GCM with a fixed key and nonce, so a plugin's encryption has to give these exact bytes (`payload` is base64 of the 16-byte tag and then the ciphertext, `nonce` the 12-byte IV).
10
+ - `payloads`: the plaintext a log call builds from its level, message, data and the plugin's automatic context.
11
+ - `deliveryOutcomes` and `retryDelaysMs`: what each answer from `POST /logs` means, and how long to wait after each failure.
12
+
13
+ ## In another language
14
+
15
+ Copy this folder into the client's tests at a pinned kit version, and test every vector against the client's own code. The kit's version is the contract's: when the kit changes a shape, the new version's files fail the client's tests until it catches up.
16
+
17
+ ```bash
18
+ curl -sL https://registry.npmjs.org/@infinitetoken/lumber-kit/-/lumber-kit-0.7.0.tgz | tar -xz --strip-components=1 package/contract
19
+ ```
20
+
21
+ Lumber-Python (`scripts/sync_contract.py`) and Lumber-Go (`scripts/sync-contract.sh`) each have a script that does this, and their CI fails when the copy differs from the pinned version's. Lumber-Node reads the contract straight from its installed kit (`@infinitetoken/lumber-kit/contract/vectors.json`).