triqai 0.2.8 → 0.4.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/CHANGELOG.md +39 -0
- package/README.md +102 -5
- package/dist/index.cjs +808 -144
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +279 -41
- package/dist/index.d.ts +279 -41
- package/dist/index.js +807 -145
- package/dist/index.js.map +1 -1
- package/openapi-public.yaml +192 -26
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,45 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.4.0] - 2026-11-23
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Client-side pacing with the `pacing` option and the `PacingOptions` type. Calls on a client wait their turn within the rate and concurrency limits the API reports, instead of being refused with `429`. `pacing: { maxConcurrency, requestsPerSecond }` sets lower limits for a client, for example when several processes share an organization; `pacing: false` sends every request immediately.
|
|
15
|
+
- `pacing.maxWait`: the longest a call waits for its turn before its first attempt (default: `maxRetryTime`). It then rejects with the new `PacingTimeoutError`, a `TimeoutError` with code `pacing_timeout`, without being sent or charged.
|
|
16
|
+
- A `signal` option (`AbortSignal`) on every request method, including reads, `health()`, `apiInfo()` and the raw methods, through the new `RequestOptions` type. It cancels a call while it waits, between retries or in flight, and rejects with the signal's reason.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- Pacing is on by default in Node.js and Bun. Enrichments in flight stay within `X-RateLimit-Concurrency-Limit`, and all requests within the per-second rate in `X-RateLimit-Limit`. Until the API has reported its limits, at most five requests are in flight.
|
|
21
|
+
- After a `429`, every call on the client waits for the limit it names (`rps`, or `concurrency` for enrichments) until `Retry-After`, instead of each call retrying on its own. The refused call keeps its place and goes first when the pause ends.
|
|
22
|
+
- With pacing, `maxRetryTime` starts when a call's first attempt is sent, and a retry is only sent with at least `min(1s, timeout / 2)` of it left; otherwise the last server error is returned.
|
|
23
|
+
|
|
24
|
+
### Notes
|
|
25
|
+
|
|
26
|
+
- Cloudflare Workers, Deno, edge runtimes and browsers: pacing is off by default. Workers bind each request's work to that request, so create a client per request there or keep pacing off. If you opt in with a client shared across requests, a grant that its request no longer takes up returns to the pool within a second.
|
|
27
|
+
- Tests with fake timers: pacing uses `Date.now()` and `setTimeout`, so advance a faked clock with both faked, or set `pacing: false` in those tests.
|
|
28
|
+
- Unpaced clients (`pacing: false`) keep the 0.3.0 retry and budget behaviour.
|
|
29
|
+
|
|
30
|
+
## [0.3.0] - 2026-11-16
|
|
31
|
+
|
|
32
|
+
### Added
|
|
33
|
+
|
|
34
|
+
- `transactions.count()` for `GET /v1/transactions/count`, with an optional `afterDate`.
|
|
35
|
+
- `transactions.batchDelete()` for `DELETE /v1/transactions/batch`. Pass exactly one of `all: true`, `afterDate` or `ids`.
|
|
36
|
+
- `GoneError` for `410` responses (erased data or an inactive organization). It is never retried.
|
|
37
|
+
- `DuplicateRequestError.reason`, `"payload_mismatch"` when an idempotency key was already used for a different request.
|
|
38
|
+
|
|
39
|
+
### Changed
|
|
40
|
+
|
|
41
|
+
- Entity types are now a union selected by `type` (`merchant`, `location`, `intermediary`, `person`), so `entity.data` narrows to the right shape after checking `entity.type`. Code that reads fields shared by every entity type is unaffected.
|
|
42
|
+
- `EntityResult` now includes the optional `reasoning` text. Intermediary data on transaction lookups includes an optional `category`.
|
|
43
|
+
- Enrichment now retries a `409` for the same request, while it is still in progress or before its stored result can be read, after `Retry-After` and with the same idempotency key. The retry returns the stored result without a second charge. A `409` with `reason: "payload_mismatch"` is never retried.
|
|
44
|
+
|
|
45
|
+
### Deprecated
|
|
46
|
+
|
|
47
|
+
- The `force` option on `transactions.enrich()` has no effect and is no longer sent. The API has no cache bypass.
|
|
48
|
+
|
|
10
49
|
## [0.2.8] - 2026-11-15
|
|
11
50
|
|
|
12
51
|
### Added
|
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ const result = await triqai.transactions.enrich({
|
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
console.log(result.data.transaction.category.primary.name);
|
|
35
|
-
// => "
|
|
35
|
+
// => "Cafes" (the most specific category; secondary and tertiary are its parents)
|
|
36
36
|
|
|
37
37
|
console.log(result.data.entities);
|
|
38
38
|
// => [{ type: "merchant", data: { name: "Starbucks", ... } }, ...]
|
|
@@ -61,6 +61,9 @@ const triqai = new Triqai("triq_your_api_key", {
|
|
|
61
61
|
// Per-attempt timeout, including response body, in ms (default: 60000)
|
|
62
62
|
timeout: 60_000,
|
|
63
63
|
|
|
64
|
+
// Pacing within your rate limits (default: on in Node.js and Bun). See "Pacing" below.
|
|
65
|
+
pacing: true,
|
|
66
|
+
|
|
64
67
|
// Extra headers for every request
|
|
65
68
|
defaultHeaders: {
|
|
66
69
|
"X-Custom-Header": "value",
|
|
@@ -116,10 +119,32 @@ await triqai.transactions.enrich({
|
|
|
116
119
|
```typescript
|
|
117
120
|
const result = await triqai.transactions.enrich(
|
|
118
121
|
{ title: "STARBUCKS", country: "US", type: "expense" },
|
|
119
|
-
|
|
122
|
+
// One key per bank transaction (e.g. your own transaction ID), so a retry
|
|
123
|
+
// replays the original result without a second charge.
|
|
124
|
+
{ idempotencyKey: "txn_8f14e45f" },
|
|
125
|
+
);
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The `force` option is deprecated and has no effect. The API has no cache bypass, so the SDK no longer sends it.
|
|
129
|
+
|
|
130
|
+
#### Cancel a call
|
|
131
|
+
|
|
132
|
+
Every method accepts a `signal` in its last options argument:
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
const controller = new AbortController();
|
|
136
|
+
const result = await triqai.transactions.enrich(
|
|
137
|
+
{ title: "STARBUCKS", country: "US", type: "expense" },
|
|
138
|
+
{ signal: controller.signal },
|
|
120
139
|
);
|
|
140
|
+
|
|
141
|
+
const page = await triqai.transactions.list({ size: 50 }, { signal: AbortSignal.timeout(30_000) });
|
|
142
|
+
const merchant = await triqai.merchants.get("merchant-uuid", { signal: controller.signal });
|
|
143
|
+
const raw = await triqai.rawGet("/v1/categories", undefined, { signal: controller.signal });
|
|
121
144
|
```
|
|
122
145
|
|
|
146
|
+
Aborting rejects the call with the signal's reason (an `AbortError` by default), including while it waits its turn, between retries, or in flight.
|
|
147
|
+
|
|
123
148
|
#### List transactions
|
|
124
149
|
|
|
125
150
|
```typescript
|
|
@@ -150,6 +175,17 @@ for await (const tx of page) {
|
|
|
150
175
|
}
|
|
151
176
|
```
|
|
152
177
|
|
|
178
|
+
#### Count transactions
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
const { count } = await triqai.transactions.count();
|
|
182
|
+
|
|
183
|
+
// Only transactions created on or after a date (ISO 8601 string or Date)
|
|
184
|
+
const { count: recent } = await triqai.transactions.count({
|
|
185
|
+
afterDate: "2026-01-01T00:00:00Z",
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
153
189
|
#### Get a transaction
|
|
154
190
|
|
|
155
191
|
```typescript
|
|
@@ -164,6 +200,25 @@ const { deleted, transactionId } = await triqai.transactions.delete(
|
|
|
164
200
|
);
|
|
165
201
|
```
|
|
166
202
|
|
|
203
|
+
#### Delete transactions in bulk
|
|
204
|
+
|
|
205
|
+
Pass exactly one of `ids` (at most 1000 UUIDs), `afterDate`, or `all: true`:
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
// Specific transactions
|
|
209
|
+
const { count } = await triqai.transactions.batchDelete({
|
|
210
|
+
ids: ["550e8400-e29b-41d4-a716-446655440000", "a1b2c3d4-e5f6-7890-abcd-ef1234567890"],
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// Everything created on or after a date (ISO 8601 string or Date)
|
|
214
|
+
await triqai.transactions.batchDelete({ afterDate: "2026-01-01T00:00:00Z" });
|
|
215
|
+
|
|
216
|
+
// Every transaction in your organization
|
|
217
|
+
await triqai.transactions.batchDelete({ all: true });
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Any other combination throws a `ValidationError`. A 503 means cleanup is incomplete. The SDK retries it automatically. If it still fails, call again with the same request. After a retry, `count` covers only the final attempt.
|
|
221
|
+
|
|
167
222
|
### Categories
|
|
168
223
|
|
|
169
224
|
```typescript
|
|
@@ -271,7 +326,8 @@ try {
|
|
|
271
326
|
| `AuthorizationError` | 403 | Key valid but not authorized |
|
|
272
327
|
| `NotFoundError` | 404 | Resource does not exist |
|
|
273
328
|
| `ClientDisconnectedError` | 499 | Client disconnected before completion |
|
|
274
|
-
| `DuplicateRequestError` | 409 | Idempotency key
|
|
329
|
+
| `DuplicateRequestError` | 409 | Idempotency key used for a different request (`reason: "payload_mismatch"`), or the same request is still in progress (retried automatically) |
|
|
330
|
+
| `GoneError` | 410 | Transaction data erased or organization inactive (never retried) |
|
|
275
331
|
| `ValidationError` | 422 | Request body validation failed |
|
|
276
332
|
| `RateLimitError` | 429 | Rate limit exceeded |
|
|
277
333
|
| `InternalServerError` | 500 | Server error (retried automatically) |
|
|
@@ -279,6 +335,7 @@ try {
|
|
|
279
335
|
| `GatewayTimeoutError` | 504 | Upstream timeout |
|
|
280
336
|
| `ConnectionError` | - | Network/DNS failure |
|
|
281
337
|
| `TimeoutError` | - | Request exceeded timeout |
|
|
338
|
+
| `PacingTimeoutError` | - | A call waited longer than `pacing.maxWait` for its turn; it was never sent (a `TimeoutError` with code `pacing_timeout`) |
|
|
282
339
|
|
|
283
340
|
## Automatic Retries
|
|
284
341
|
|
|
@@ -286,8 +343,10 @@ The SDK automatically retries on transient errors (429, 500, 503, 504, and netwo
|
|
|
286
343
|
|
|
287
344
|
- GET and DELETE requests are always retried
|
|
288
345
|
- Enrichment calls generate an idempotency key and reuse it across automatic retries. Supply your own `idempotencyKey` to safely retry across separate calls
|
|
346
|
+
- A `409` for the same enrichment that is still in progress is retried after `Retry-After` and returns the stored result. A `409` with `reason: "payload_mismatch"` is not retried
|
|
289
347
|
- The `Retry-After` header is a minimum delay; the SDK never retries early to fit a limit
|
|
290
|
-
-
|
|
348
|
+
- With pacing, after a `429` other calls on the same client wait too (see [Pacing](#pacing))
|
|
349
|
+
- Calls have a 5-minute total budget (`maxRetryTime`), including attempts, response bodies, and retry waits. If a retry delay cannot fit, the SDK throws the last error with its retry information so you can schedule a later call using the same idempotency key. With pacing, the budget starts when the first attempt is sent, and a retry is only sent with at least `min(1s, timeout / 2)` of it left
|
|
291
350
|
- Default: 3 retries, 500ms base delay, 30s max delay
|
|
292
351
|
|
|
293
352
|
Disable retries:
|
|
@@ -296,9 +355,47 @@ Disable retries:
|
|
|
296
355
|
const triqai = new Triqai("triq_your_api_key", { maxRetries: 0 });
|
|
297
356
|
```
|
|
298
357
|
|
|
358
|
+
## Pacing
|
|
359
|
+
|
|
360
|
+
Pacing keeps a client's requests within your organization's rate limits, so a burst of calls, such as `Promise.all` over a batch, waits its turn on the client instead of being refused with `429`. It is on by default in Node.js and Bun, and off by default elsewhere (see [Cloudflare Workers and other runtimes](#cloudflare-workers-and-other-runtimes)).
|
|
361
|
+
|
|
362
|
+
- **Concurrency.** Enrichments in flight stay within `X-RateLimit-Concurrency-Limit`. Only enrichments wait for one of these slots, so reads are not held behind a queued batch.
|
|
363
|
+
- **Rate.** All requests are spaced to the per-second rate in `X-RateLimit-Limit` on responses whose `X-RateLimit-Scope` is `rps` or absent. When `X-RateLimit-Remaining` shows fewer requests left than the client expects, for example while another process uses the same organization, the client slows down to match.
|
|
364
|
+
- **Before the limits are known.** Until a response reports them, at most 5 requests are in flight, enrichments included. A proxy that strips the `X-RateLimit-*` headers keeps a client at this limit; set `pacing: false` or explicit limits in that case.
|
|
365
|
+
- **After a `429`.** Every call on the client waits for the limit it names: `X-RateLimit-Scope: rps`, or no scope, pauses all requests; `concurrency` pauses enrichments, and enrichments that hold a slot but have not been sent give it back. The pause lasts the `Retry-After` time plus up to 20% (at most 1 second) of jitter. Without `Retry-After`, it lasts until `X-RateLimit-Reset`, measured against the response's `Date` header, when that is at most 10 seconds away; otherwise the normal backoff applies. Other calls wait at most 60 seconds before trying again.
|
|
366
|
+
- **Fewer enrichments after a `concurrency` 429.** The client keeps fewer enrichments in flight than were running when it was refused, then adds one back after as many successful enrichments as its current limit, counting only enrichments sent after the decrease. Refusals of enrichments sent before the limit was known do not lower it.
|
|
367
|
+
- **Retries first.** A call that is retried keeps its place, and its enrichment slot while the limit allows, and goes ahead of calls that have not been sent yet.
|
|
368
|
+
- **Budgets.** Waiting for a turn before the first attempt is limited by `pacing.maxWait` (default: `maxRetryTime`), not by `timeout` or `maxRetryTime`. A call that waits longer rejects with `PacingTimeoutError` and is never sent or charged. `maxRetryTime` starts when the first attempt is sent. Pass a [`signal`](#cancel-a-call) to cancel a call at any point.
|
|
369
|
+
|
|
370
|
+
Pacing is per client, so share one client across a batch. Processes that share an organization also share its limits: give each one lower limits. Your limits apply when they are lower than the API's:
|
|
371
|
+
|
|
372
|
+
```typescript
|
|
373
|
+
const triqai = new Triqai("triq_your_api_key", {
|
|
374
|
+
pacing: {
|
|
375
|
+
maxConcurrency: 5, // enrichments in flight
|
|
376
|
+
requestsPerSecond: 3, // all requests, retries included
|
|
377
|
+
maxWait: 600_000, // wait up to 10 minutes for a turn
|
|
378
|
+
},
|
|
379
|
+
});
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
To send every request as soon as it is made, as before pacing, disable it:
|
|
383
|
+
|
|
384
|
+
```typescript
|
|
385
|
+
const triqai = new Triqai("triq_your_api_key", { pacing: false });
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
### Cloudflare Workers and other runtimes
|
|
389
|
+
|
|
390
|
+
Pacing is off by default in Cloudflare Workers, Deno, edge runtimes and browsers. Workers bind the work of each request to that request, so one request cannot reliably wait for another's call to finish. In Workers, create the client inside each request handler, or keep pacing off. Within one request, `pacing: true` still paces a batch of calls on that request's client. If you opt in with a client shared across requests, a slot granted to a request that no longer runs returns to the pool within a second; pass `{ signal: request.signal }` to each call, so a call whose client has gone is not sent.
|
|
391
|
+
|
|
392
|
+
### Tests with fake timers
|
|
393
|
+
|
|
394
|
+
Pacing uses `Date.now()` and `setTimeout`. In tests that fake timers, fake both and advance the clock, or set `pacing: false`.
|
|
395
|
+
|
|
299
396
|
## Rate Limiting
|
|
300
397
|
|
|
301
|
-
Rate limit information is available on
|
|
398
|
+
Rate limit information is available on responses from rate-limited endpoints. The SDK paces requests and handles 429 responses automatically, but you can monitor usage via the `onResponse` hook or `rawGet`/`rawPost`/`rawDelete` methods:
|
|
302
399
|
|
|
303
400
|
```typescript
|
|
304
401
|
// Option 1: Debug hook
|