triqai 0.2.7 → 0.3.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 +25 -0
- package/README.md +48 -3
- package/dist/index.cjs +73 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +216 -23
- package/dist/index.d.ts +216 -23
- package/dist/index.js +73 -16
- package/dist/index.js.map +1 -1
- package/openapi-public.yaml +233 -28
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.3.0] - 2026-11-16
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `transactions.count()` for `GET /v1/transactions/count`, with an optional `afterDate`.
|
|
15
|
+
- `transactions.batchDelete()` for `DELETE /v1/transactions/batch`. Pass exactly one of `all: true`, `afterDate` or `ids`.
|
|
16
|
+
- `GoneError` for `410` responses (erased data or an inactive organization). It is never retried.
|
|
17
|
+
- `DuplicateRequestError.reason`, `"payload_mismatch"` when an idempotency key was already used for a different request.
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- 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.
|
|
22
|
+
- `EntityResult` now includes the optional `reasoning` text. Intermediary data on transaction lookups includes an optional `category`.
|
|
23
|
+
- 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.
|
|
24
|
+
|
|
25
|
+
### Deprecated
|
|
26
|
+
|
|
27
|
+
- The `force` option on `transactions.enrich()` has no effect and is no longer sent. The API has no cache bypass.
|
|
28
|
+
|
|
29
|
+
## [0.2.8] - 2026-11-15
|
|
30
|
+
|
|
31
|
+
### Added
|
|
32
|
+
|
|
33
|
+
- `options.p2p` on transaction enrichment: `true` for a known person-to-person transfer, `false` for a known payment to a business.
|
|
34
|
+
|
|
10
35
|
## [0.2.7] - 2026-10-23
|
|
11
36
|
|
|
12
37
|
### Changed
|
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", ... } }, ...]
|
|
@@ -96,6 +96,15 @@ const result = await triqai.transactions.enrich({
|
|
|
96
96
|
},
|
|
97
97
|
});
|
|
98
98
|
|
|
99
|
+
// When your payment rail already tells you who was paid, pass `p2p`:
|
|
100
|
+
// `true` for a person-to-person transfer, `false` for a payment to a business.
|
|
101
|
+
await triqai.transactions.enrich({
|
|
102
|
+
title: "BILL PAYMENT TO J D MORGAN REF RENT",
|
|
103
|
+
country: "GB",
|
|
104
|
+
type: "expense",
|
|
105
|
+
options: { p2p: true },
|
|
106
|
+
});
|
|
107
|
+
|
|
99
108
|
// API v1.1.11+: `data.transaction.channel` is no longer returned.
|
|
100
109
|
// Confidence reasons are dynamic and may include tags like:
|
|
101
110
|
// `venue_or_attraction`, `merchant_location_crosscheck_corrected`,
|
|
@@ -107,10 +116,14 @@ const result = await triqai.transactions.enrich({
|
|
|
107
116
|
```typescript
|
|
108
117
|
const result = await triqai.transactions.enrich(
|
|
109
118
|
{ title: "STARBUCKS", country: "US", type: "expense" },
|
|
110
|
-
|
|
119
|
+
// One key per bank transaction (e.g. your own transaction ID), so a retry
|
|
120
|
+
// replays the original result without a second charge.
|
|
121
|
+
{ idempotencyKey: "txn_8f14e45f" },
|
|
111
122
|
);
|
|
112
123
|
```
|
|
113
124
|
|
|
125
|
+
The `force` option is deprecated and has no effect. The API has no cache bypass, so the SDK no longer sends it.
|
|
126
|
+
|
|
114
127
|
#### List transactions
|
|
115
128
|
|
|
116
129
|
```typescript
|
|
@@ -141,6 +154,17 @@ for await (const tx of page) {
|
|
|
141
154
|
}
|
|
142
155
|
```
|
|
143
156
|
|
|
157
|
+
#### Count transactions
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
const { count } = await triqai.transactions.count();
|
|
161
|
+
|
|
162
|
+
// Only transactions created on or after a date (ISO 8601 string or Date)
|
|
163
|
+
const { count: recent } = await triqai.transactions.count({
|
|
164
|
+
afterDate: "2026-01-01T00:00:00Z",
|
|
165
|
+
});
|
|
166
|
+
```
|
|
167
|
+
|
|
144
168
|
#### Get a transaction
|
|
145
169
|
|
|
146
170
|
```typescript
|
|
@@ -155,6 +179,25 @@ const { deleted, transactionId } = await triqai.transactions.delete(
|
|
|
155
179
|
);
|
|
156
180
|
```
|
|
157
181
|
|
|
182
|
+
#### Delete transactions in bulk
|
|
183
|
+
|
|
184
|
+
Pass exactly one of `ids` (at most 1000 UUIDs), `afterDate`, or `all: true`:
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
// Specific transactions
|
|
188
|
+
const { count } = await triqai.transactions.batchDelete({
|
|
189
|
+
ids: ["550e8400-e29b-41d4-a716-446655440000", "a1b2c3d4-e5f6-7890-abcd-ef1234567890"],
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// Everything created on or after a date (ISO 8601 string or Date)
|
|
193
|
+
await triqai.transactions.batchDelete({ afterDate: "2026-01-01T00:00:00Z" });
|
|
194
|
+
|
|
195
|
+
// Every transaction in your organization
|
|
196
|
+
await triqai.transactions.batchDelete({ all: true });
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
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.
|
|
200
|
+
|
|
158
201
|
### Categories
|
|
159
202
|
|
|
160
203
|
```typescript
|
|
@@ -262,7 +305,8 @@ try {
|
|
|
262
305
|
| `AuthorizationError` | 403 | Key valid but not authorized |
|
|
263
306
|
| `NotFoundError` | 404 | Resource does not exist |
|
|
264
307
|
| `ClientDisconnectedError` | 499 | Client disconnected before completion |
|
|
265
|
-
| `DuplicateRequestError` | 409 | Idempotency key
|
|
308
|
+
| `DuplicateRequestError` | 409 | Idempotency key used for a different request (`reason: "payload_mismatch"`), or the same request is still in progress (retried automatically) |
|
|
309
|
+
| `GoneError` | 410 | Transaction data erased or organization inactive (never retried) |
|
|
266
310
|
| `ValidationError` | 422 | Request body validation failed |
|
|
267
311
|
| `RateLimitError` | 429 | Rate limit exceeded |
|
|
268
312
|
| `InternalServerError` | 500 | Server error (retried automatically) |
|
|
@@ -277,6 +321,7 @@ The SDK automatically retries on transient errors (429, 500, 503, 504, and netwo
|
|
|
277
321
|
|
|
278
322
|
- GET and DELETE requests are always retried
|
|
279
323
|
- Enrichment calls generate an idempotency key and reuse it across automatic retries. Supply your own `idempotencyKey` to safely retry across separate calls
|
|
324
|
+
- 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
|
|
280
325
|
- The `Retry-After` header is a minimum delay; the SDK never retries early to fit a limit
|
|
281
326
|
- 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
|
|
282
327
|
- Default: 3 retries, 500ms base delay, 30s max delay
|
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
// package.json
|
|
6
|
-
var version = "0.
|
|
6
|
+
var version = "0.3.0";
|
|
7
7
|
|
|
8
8
|
// src/errors.ts
|
|
9
9
|
var TriqaiError = class extends Error {
|
|
@@ -67,16 +67,25 @@ var ClientDisconnectedError = class extends TriqaiError {
|
|
|
67
67
|
};
|
|
68
68
|
var DuplicateRequestError = class extends TriqaiError {
|
|
69
69
|
state;
|
|
70
|
+
/** `payload_mismatch` when the key was already used for a different request. */
|
|
71
|
+
reason;
|
|
70
72
|
duplicateRequestId;
|
|
71
73
|
retryAfter;
|
|
72
74
|
constructor(message, opts) {
|
|
73
75
|
super(message, 409, { code: "DUPLICATE_REQUEST", ...opts });
|
|
74
76
|
this.name = "DuplicateRequestError";
|
|
75
77
|
this.state = opts?.state;
|
|
78
|
+
this.reason = opts?.reason;
|
|
76
79
|
this.duplicateRequestId = opts?.duplicateRequestId;
|
|
77
80
|
this.retryAfter = opts?.retryAfter;
|
|
78
81
|
}
|
|
79
82
|
};
|
|
83
|
+
var GoneError = class extends TriqaiError {
|
|
84
|
+
constructor(message, opts) {
|
|
85
|
+
super(message, 410, { code: "gone", ...opts });
|
|
86
|
+
this.name = "GoneError";
|
|
87
|
+
}
|
|
88
|
+
};
|
|
80
89
|
var RateLimitError = class extends TriqaiError {
|
|
81
90
|
rateLimitInfo;
|
|
82
91
|
constructor(message, rateLimitInfo, opts) {
|
|
@@ -164,8 +173,8 @@ var HttpClient = class {
|
|
|
164
173
|
async post(path, body) {
|
|
165
174
|
return this.request("POST", path, body);
|
|
166
175
|
}
|
|
167
|
-
async delete(path) {
|
|
168
|
-
return this.request("DELETE", path);
|
|
176
|
+
async delete(path, body) {
|
|
177
|
+
return this.request("DELETE", path, body);
|
|
169
178
|
}
|
|
170
179
|
async request(method, path, body, query, extraHeaders) {
|
|
171
180
|
const url = this.buildUrl(path, query);
|
|
@@ -236,13 +245,14 @@ var HttpClient = class {
|
|
|
236
245
|
rateLimitInfo: parseRateLimitHeaders(responseHeaders)
|
|
237
246
|
};
|
|
238
247
|
}
|
|
248
|
+
const error = this.mapError(response.status, responseBody, responseHeaders);
|
|
249
|
+
lastError = error;
|
|
239
250
|
const shouldRetry = this.canRetry(
|
|
240
251
|
attempt,
|
|
241
252
|
method,
|
|
242
253
|
headers,
|
|
243
|
-
|
|
254
|
+
isRetryableError(error)
|
|
244
255
|
);
|
|
245
|
-
lastError = this.mapError(response.status, responseBody, responseHeaders);
|
|
246
256
|
if (!shouldRetry) {
|
|
247
257
|
throw lastError;
|
|
248
258
|
}
|
|
@@ -252,7 +262,7 @@ var HttpClient = class {
|
|
|
252
262
|
attempt,
|
|
253
263
|
method,
|
|
254
264
|
headers,
|
|
255
|
-
|
|
265
|
+
isRetryableError(err)
|
|
256
266
|
);
|
|
257
267
|
if (!canRetry) {
|
|
258
268
|
throw err;
|
|
@@ -308,7 +318,7 @@ var HttpClient = class {
|
|
|
308
318
|
return qs ? `${base}?${qs}` : base;
|
|
309
319
|
}
|
|
310
320
|
calculateDelay(attempt, lastError) {
|
|
311
|
-
const retryAfter = lastError instanceof RateLimitError ? lastError.rateLimitInfo.retryAfter : lastError instanceof ServiceUnavailableError ? lastError.retryAfter : void 0;
|
|
321
|
+
const retryAfter = lastError instanceof RateLimitError ? lastError.rateLimitInfo.retryAfter : lastError instanceof ServiceUnavailableError || lastError instanceof DuplicateRequestError ? lastError.retryAfter : void 0;
|
|
312
322
|
if (retryAfter) {
|
|
313
323
|
const minimumDelay = retryAfter * 1e3;
|
|
314
324
|
return minimumDelay + Math.min(minimumDelay * 0.2, 1e3) * Math.random();
|
|
@@ -343,10 +353,13 @@ var HttpClient = class {
|
|
|
343
353
|
return new DuplicateRequestError(parsed.message, {
|
|
344
354
|
...opts,
|
|
345
355
|
state: details?.state,
|
|
356
|
+
reason: details?.reason,
|
|
346
357
|
duplicateRequestId: details?.requestId,
|
|
347
358
|
retryAfter: details?.retryAfterSeconds
|
|
348
359
|
});
|
|
349
360
|
}
|
|
361
|
+
case 410:
|
|
362
|
+
return new GoneError(parsed.message, opts);
|
|
350
363
|
case 422: {
|
|
351
364
|
const fieldErrors = parsed.error?.details?.fieldErrors;
|
|
352
365
|
return new ValidationError(parsed.message, fieldErrors, opts);
|
|
@@ -428,6 +441,12 @@ function parseErrorBody(body) {
|
|
|
428
441
|
meta: meta?.generatedAt ? meta : void 0
|
|
429
442
|
};
|
|
430
443
|
}
|
|
444
|
+
function isRetryableError(err) {
|
|
445
|
+
if (err instanceof DuplicateRequestError) {
|
|
446
|
+
return err.reason === void 0 && (err.state === "in_progress" || err.state === "completed");
|
|
447
|
+
}
|
|
448
|
+
return RETRYABLE_STATUS_CODES.has(err.statusCode);
|
|
449
|
+
}
|
|
431
450
|
function isIdempotent(method, headers) {
|
|
432
451
|
if (method === "GET" || method === "DELETE") return true;
|
|
433
452
|
return Object.entries(headers).some(
|
|
@@ -722,7 +741,7 @@ var Transactions = class {
|
|
|
722
741
|
* Enrich a transaction with merchant, category, location, and entity data.
|
|
723
742
|
*
|
|
724
743
|
* @param request - The transaction to enrich (title, country, type, and optional options).
|
|
725
|
-
* @param options - Optional enrichment controls (
|
|
744
|
+
* @param options - Optional enrichment controls (idempotency key).
|
|
726
745
|
* @returns The enriched transaction data.
|
|
727
746
|
*
|
|
728
747
|
* @example
|
|
@@ -739,15 +758,10 @@ var Transactions = class {
|
|
|
739
758
|
const headers = {
|
|
740
759
|
"Idempotency-Key": options?.idempotencyKey ?? await createIdempotencyKey()
|
|
741
760
|
};
|
|
742
|
-
const query = {};
|
|
743
|
-
if (options?.force) {
|
|
744
|
-
query.force = "true";
|
|
745
|
-
}
|
|
746
761
|
const resp = await this.http.postWithHeaders(
|
|
747
762
|
"/v1/transactions/enrich",
|
|
748
763
|
request,
|
|
749
|
-
headers
|
|
750
|
-
Object.keys(query).length > 0 ? query : void 0
|
|
764
|
+
headers
|
|
751
765
|
);
|
|
752
766
|
return resp.data;
|
|
753
767
|
}
|
|
@@ -786,6 +800,25 @@ var Transactions = class {
|
|
|
786
800
|
};
|
|
787
801
|
return fetchPage(params?.page ?? 1, params?.size ?? 25);
|
|
788
802
|
}
|
|
803
|
+
/**
|
|
804
|
+
* Count your organization's transactions.
|
|
805
|
+
*
|
|
806
|
+
* @param params - Optional `afterDate` to count only transactions created on or after it.
|
|
807
|
+
* @returns The number of matching transactions.
|
|
808
|
+
*
|
|
809
|
+
* @example
|
|
810
|
+
* ```ts
|
|
811
|
+
* const { count } = await triqai.transactions.count({ afterDate: "2026-01-01T00:00:00Z" });
|
|
812
|
+
* ```
|
|
813
|
+
*/
|
|
814
|
+
async count(params) {
|
|
815
|
+
const query = {};
|
|
816
|
+
if (params?.afterDate) {
|
|
817
|
+
query.afterDate = params.afterDate instanceof Date ? params.afterDate.toISOString() : params.afterDate;
|
|
818
|
+
}
|
|
819
|
+
const resp = await this.http.get("/v1/transactions/count", query);
|
|
820
|
+
return resp.data.data;
|
|
821
|
+
}
|
|
789
822
|
/**
|
|
790
823
|
* Get a single transaction by ID.
|
|
791
824
|
*
|
|
@@ -810,11 +843,35 @@ var Transactions = class {
|
|
|
810
843
|
);
|
|
811
844
|
return resp.data.data;
|
|
812
845
|
}
|
|
846
|
+
/**
|
|
847
|
+
* Delete many transactions in one request.
|
|
848
|
+
*
|
|
849
|
+
* Pass exactly one of `all: true` (every transaction in your organization),
|
|
850
|
+
* `afterDate` (transactions created on or after it), or `ids` (at most 1000
|
|
851
|
+
* UUIDs). The API rejects any other combination with a 422 `ValidationError`.
|
|
852
|
+
* A 503 means cleanup is incomplete; like other DELETE requests, it is retried
|
|
853
|
+
* automatically, and `count` then covers only the final attempt.
|
|
854
|
+
*
|
|
855
|
+
* @param request - The single selection mode.
|
|
856
|
+
* @returns Confirmation with the number of transactions deleted.
|
|
857
|
+
*
|
|
858
|
+
* @example
|
|
859
|
+
* ```ts
|
|
860
|
+
* const { count } = await triqai.transactions.batchDelete({
|
|
861
|
+
* ids: ["550e8400-e29b-41d4-a716-446655440000"],
|
|
862
|
+
* });
|
|
863
|
+
* ```
|
|
864
|
+
*/
|
|
865
|
+
async batchDelete(request) {
|
|
866
|
+
const body = "afterDate" in request && request.afterDate instanceof Date ? { ...request, afterDate: request.afterDate.toISOString() } : request;
|
|
867
|
+
const resp = await this.http.delete("/v1/transactions/batch", body);
|
|
868
|
+
return resp.data.data;
|
|
869
|
+
}
|
|
813
870
|
};
|
|
814
871
|
|
|
815
872
|
// src/client.ts
|
|
816
873
|
var Triqai = class {
|
|
817
|
-
/** Enrich, list, get, and delete transactions. */
|
|
874
|
+
/** Enrich, list, count, get, and delete transactions. */
|
|
818
875
|
transactions;
|
|
819
876
|
/** List the full category taxonomy. */
|
|
820
877
|
categories;
|
|
@@ -920,6 +977,7 @@ exports.ClientDisconnectedError = ClientDisconnectedError;
|
|
|
920
977
|
exports.ConnectionError = ConnectionError;
|
|
921
978
|
exports.DuplicateRequestError = DuplicateRequestError;
|
|
922
979
|
exports.GatewayTimeoutError = GatewayTimeoutError;
|
|
980
|
+
exports.GoneError = GoneError;
|
|
923
981
|
exports.InsufficientCreditsError = InsufficientCreditsError;
|
|
924
982
|
exports.InternalServerError = InternalServerError;
|
|
925
983
|
exports.NotFoundError = NotFoundError;
|