triqai 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/CHANGELOG.md +27 -0
- package/LICENSE +21 -0
- package/README.md +357 -0
- package/dist/index.cjs +862 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1206 -0
- package/dist/index.d.ts +1206 -0
- package/dist/index.js +842 -0
- package/dist/index.js.map +1 -0
- package/openapi-public.yaml +1923 -0
- package/package.json +71 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-03-21
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Initial release of the Triqai Node.js SDK
|
|
13
|
+
- Full coverage of the Triqai Transaction Enrichment API v1.1.9
|
|
14
|
+
- `transactions.enrich()` with idempotency key and force-bypass support
|
|
15
|
+
- `transactions.list()` with pagination and auto-pagination via async iterators
|
|
16
|
+
- `transactions.get()` and `transactions.delete()`
|
|
17
|
+
- `categories.list()` for the full category taxonomy
|
|
18
|
+
- `merchants.get()`, `locations.get()`, `intermediaries.get()` for entity lookups
|
|
19
|
+
- `issueReports.create()`, `issueReports.list()`, `issueReports.get()` for enrichment feedback
|
|
20
|
+
- Typed error hierarchy: `AuthenticationError`, `ValidationError`, `RateLimitError`, etc.
|
|
21
|
+
- Automatic retries with exponential backoff on 429, 500, 503
|
|
22
|
+
- `Retry-After` header support
|
|
23
|
+
- Rate limit header parsing on all responses
|
|
24
|
+
- `onRequest` / `onResponse` debug hooks
|
|
25
|
+
- ESM + CJS dual output
|
|
26
|
+
- OpenAPI-driven type generation pipeline
|
|
27
|
+
- Zero runtime dependencies (native `fetch`)
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Triqai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
# Triqai Node.js SDK
|
|
2
|
+
|
|
3
|
+
The official Node.js / TypeScript SDK for the [Triqai Transaction Enrichment API](https://docs.triqai.com).
|
|
4
|
+
|
|
5
|
+
Enrich raw bank transaction descriptions into structured data: merchants, categories, locations, intermediaries, and more.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install triqai
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
yarn add triqai
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add triqai
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import Triqai from "triqai";
|
|
25
|
+
|
|
26
|
+
const triqai = new Triqai("triq_your_api_key");
|
|
27
|
+
|
|
28
|
+
const result = await triqai.transactions.enrich({
|
|
29
|
+
title: "STARBUCKS SEATTLE WA",
|
|
30
|
+
country: "US",
|
|
31
|
+
type: "expense",
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
console.log(result.data.transaction.category.primary.name);
|
|
35
|
+
// => "Food & Dining"
|
|
36
|
+
|
|
37
|
+
console.log(result.data.entities);
|
|
38
|
+
// => [{ type: "merchant", data: { name: "Starbucks", ... } }, ...]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Requirements
|
|
42
|
+
|
|
43
|
+
- Node.js 18+ (uses native `fetch`)
|
|
44
|
+
- Also works in Bun, Deno, and Cloudflare Workers
|
|
45
|
+
|
|
46
|
+
## Configuration
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
const triqai = new Triqai("triq_your_api_key", {
|
|
50
|
+
// Base URL (default: https://api.triqai.com)
|
|
51
|
+
baseUrl: "https://api.triqai.com",
|
|
52
|
+
|
|
53
|
+
// Retry configuration
|
|
54
|
+
maxRetries: 3, // default: 3
|
|
55
|
+
retryDelay: 500, // base delay in ms (default: 500)
|
|
56
|
+
maxRetryDelay: 30_000, // max delay in ms (default: 30000)
|
|
57
|
+
|
|
58
|
+
// Request timeout in ms (default: 60000)
|
|
59
|
+
timeout: 60_000,
|
|
60
|
+
|
|
61
|
+
// Extra headers for every request
|
|
62
|
+
defaultHeaders: {
|
|
63
|
+
"X-Custom-Header": "value",
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
// Debug hooks
|
|
67
|
+
onRequest: (info) => console.log(`${info.method} ${info.url}`),
|
|
68
|
+
onResponse: (info) => console.log(`${info.status} in ${info.durationMs}ms`),
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## API Reference
|
|
73
|
+
|
|
74
|
+
### Transactions
|
|
75
|
+
|
|
76
|
+
#### Enrich a transaction
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
const result = await triqai.transactions.enrich({
|
|
80
|
+
title: "AMAZON MKTPLACE PMTS AMZN.COM/BILL WA",
|
|
81
|
+
country: "US",
|
|
82
|
+
type: "expense",
|
|
83
|
+
options: {
|
|
84
|
+
// Skip specific entity extraction
|
|
85
|
+
filters: {
|
|
86
|
+
noLocation: true,
|
|
87
|
+
noIntermediary: true,
|
|
88
|
+
},
|
|
89
|
+
// Pre-fill known data to improve accuracy
|
|
90
|
+
merchant: {
|
|
91
|
+
name: "Amazon",
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
#### Enrich with idempotency
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
const result = await triqai.transactions.enrich(
|
|
101
|
+
{ title: "STARBUCKS", country: "US", type: "expense" },
|
|
102
|
+
{ idempotencyKey: "my-unique-key-123", force: false },
|
|
103
|
+
);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### List transactions
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
// Get a single page
|
|
110
|
+
const page = await triqai.transactions.list({
|
|
111
|
+
page: 1,
|
|
112
|
+
size: 50,
|
|
113
|
+
startDate: "2026-01-01T00:00:00Z",
|
|
114
|
+
endDate: "2026-03-01T00:00:00Z",
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
console.log(page.data); // EnrichedTransaction[]
|
|
118
|
+
console.log(page.pageInfo); // { page, size, total, totalPages }
|
|
119
|
+
|
|
120
|
+
// Navigate pages
|
|
121
|
+
if (page.hasNextPage) {
|
|
122
|
+
const nextPage = await page.nextPage();
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### Auto-paginate
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
const page = await triqai.transactions.list();
|
|
130
|
+
|
|
131
|
+
for await (const tx of page) {
|
|
132
|
+
console.log(tx.id, tx.raw, tx.status);
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
#### Get a transaction
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
const tx = await triqai.transactions.get("550e8400-e29b-41d4-a716-446655440000");
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
#### Delete a transaction
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
const { deleted, transactionId } = await triqai.transactions.delete(
|
|
146
|
+
"550e8400-e29b-41d4-a716-446655440000",
|
|
147
|
+
);
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Categories
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
const { categories, total, categoryVersion } = await triqai.categories.list();
|
|
154
|
+
|
|
155
|
+
for (const cat of categories) {
|
|
156
|
+
console.log(`${cat.name} (level ${cat.level}, type: ${cat.type})`);
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Merchants
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
const merchant = await triqai.merchants.get("merchant-uuid");
|
|
164
|
+
console.log(merchant.name, merchant.website, merchant.icon);
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Locations
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
const location = await triqai.locations.get("location-uuid");
|
|
171
|
+
console.log(location.formatted, location.structured.city);
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Intermediaries
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
const intermediary = await triqai.intermediaries.get("intermediary-uuid");
|
|
178
|
+
console.log(intermediary.name); // "PayPal", "Square", etc.
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Issue Reports
|
|
182
|
+
|
|
183
|
+
#### Report an enrichment issue
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
const report = await triqai.issueReports.create({
|
|
187
|
+
transactionId: "tx-uuid",
|
|
188
|
+
description: "Merchant was identified incorrectly",
|
|
189
|
+
fields: ["entities.merchant.data.name"],
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
#### List issue reports
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
const page = await triqai.issueReports.list({
|
|
197
|
+
status: "pending",
|
|
198
|
+
transactionId: "tx-uuid",
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// Auto-paginate
|
|
202
|
+
for await (const report of page) {
|
|
203
|
+
console.log(report.id, report.status);
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
#### Get an issue report
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
const report = await triqai.issueReports.get("report-uuid");
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## Error Handling
|
|
214
|
+
|
|
215
|
+
All API errors are thrown as `TriqaiError`. Common HTTP statuses are mapped to typed subclasses:
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
import Triqai, {
|
|
219
|
+
TriqaiError,
|
|
220
|
+
AuthenticationError,
|
|
221
|
+
ValidationError,
|
|
222
|
+
RateLimitError,
|
|
223
|
+
InsufficientCreditsError,
|
|
224
|
+
NotFoundError,
|
|
225
|
+
} from "triqai";
|
|
226
|
+
|
|
227
|
+
try {
|
|
228
|
+
await triqai.transactions.enrich({ title: "", country: "US", type: "expense" });
|
|
229
|
+
} catch (err) {
|
|
230
|
+
if (err instanceof ValidationError) {
|
|
231
|
+
console.log("Field errors:", err.fieldErrors);
|
|
232
|
+
// { title: ["Title cannot be empty"] }
|
|
233
|
+
} else if (err instanceof RateLimitError) {
|
|
234
|
+
console.log("Retry after:", err.rateLimitInfo.retryAfter, "seconds");
|
|
235
|
+
} else if (err instanceof AuthenticationError) {
|
|
236
|
+
console.log("Check your API key");
|
|
237
|
+
} else if (err instanceof InsufficientCreditsError) {
|
|
238
|
+
console.log("Top up credits at https://triqai.com/dashboard");
|
|
239
|
+
} else if (err instanceof NotFoundError) {
|
|
240
|
+
console.log("Resource not found");
|
|
241
|
+
} else if (err instanceof TriqaiError) {
|
|
242
|
+
console.log(`API error ${err.statusCode}: ${err.message} [${err.code}]`);
|
|
243
|
+
console.log("Request ID:", err.requestId);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Error Classes
|
|
249
|
+
|
|
250
|
+
| Class | Status | When |
|
|
251
|
+
| --- | --- | --- |
|
|
252
|
+
| `AuthenticationError` | 401 | Invalid or missing API key |
|
|
253
|
+
| `InsufficientCreditsError` | 402 | No credits remaining |
|
|
254
|
+
| `AuthorizationError` | 403 | Key valid but not authorized |
|
|
255
|
+
| `NotFoundError` | 404 | Resource does not exist |
|
|
256
|
+
| `ClientDisconnectedError` | 499 | Client disconnected before completion |
|
|
257
|
+
| `DuplicateRequestError` | 409 | Idempotency key reused |
|
|
258
|
+
| `ValidationError` | 422 | Request body validation failed |
|
|
259
|
+
| `RateLimitError` | 429 | Rate limit exceeded |
|
|
260
|
+
| `InternalServerError` | 500 | Server error (retried automatically) |
|
|
261
|
+
| `ServiceUnavailableError` | 503 | Service temporarily down (retried automatically) |
|
|
262
|
+
| `GatewayTimeoutError` | 504 | Upstream timeout |
|
|
263
|
+
| `ConnectionError` | - | Network/DNS failure |
|
|
264
|
+
| `TimeoutError` | - | Request exceeded timeout |
|
|
265
|
+
|
|
266
|
+
## Automatic Retries
|
|
267
|
+
|
|
268
|
+
The SDK automatically retries on transient errors (429, 500, 503, 504, and network errors) with exponential backoff:
|
|
269
|
+
|
|
270
|
+
- GET and DELETE requests are always retried
|
|
271
|
+
- POST requests are only retried when an `idempotencyKey` is provided
|
|
272
|
+
- The `Retry-After` header is respected when present
|
|
273
|
+
- Default: 3 retries, 500ms base delay, 30s max delay
|
|
274
|
+
|
|
275
|
+
Disable retries:
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
const triqai = new Triqai("triq_your_api_key", { maxRetries: 0 });
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
## Rate Limiting
|
|
282
|
+
|
|
283
|
+
Rate limit information is available on successful responses. The SDK handles 429 responses automatically, but you can monitor usage via the `onResponse` hook or `rawGet`/`rawPost`/`rawDelete` methods:
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
// Option 1: Debug hook
|
|
287
|
+
const triqai = new Triqai("triq_your_api_key", {
|
|
288
|
+
onResponse: (info) => {
|
|
289
|
+
// info.headers contains X-RateLimit-* values
|
|
290
|
+
},
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
// Option 2: Raw request with full response
|
|
294
|
+
const resp = await triqai.rawGet("/v1/categories");
|
|
295
|
+
console.log(resp.rateLimitInfo.remaining); // tokens left
|
|
296
|
+
console.log(resp.rateLimitInfo.limit); // max tokens
|
|
297
|
+
console.log(resp.rateLimitInfo.concurrencyRemaining); // concurrent slots left
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### Health & API Info
|
|
301
|
+
|
|
302
|
+
```typescript
|
|
303
|
+
// Check API health
|
|
304
|
+
const health = await triqai.health();
|
|
305
|
+
console.log(health.data.status); // "healthy"
|
|
306
|
+
|
|
307
|
+
// Get API version and endpoint directory
|
|
308
|
+
const info = await triqai.apiInfo();
|
|
309
|
+
console.log(info.data.version); // "v1"
|
|
310
|
+
console.log(info.data.endpoints);
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### Raw Requests
|
|
314
|
+
|
|
315
|
+
For endpoints not yet covered by a resource class, or when you need the full HTTP response (headers, rate limit info):
|
|
316
|
+
|
|
317
|
+
```typescript
|
|
318
|
+
import type { HttpResponse } from "triqai";
|
|
319
|
+
|
|
320
|
+
// Full response with headers and rate limit info
|
|
321
|
+
const resp: HttpResponse<any> = await triqai.rawGet("/v1/categories");
|
|
322
|
+
console.log(resp.data); // response body
|
|
323
|
+
console.log(resp.rateLimitInfo); // { limit, remaining, ... }
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
## Pricing
|
|
327
|
+
|
|
328
|
+
The Triqai API uses a credit-based pricing model. See [triqai.com/pricing](https://triqai.com/pricing) for details.
|
|
329
|
+
|
|
330
|
+
## TypeScript
|
|
331
|
+
|
|
332
|
+
This package is written in TypeScript and ships with full type definitions. All request/response types are exported:
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
import type {
|
|
336
|
+
EnrichRequest,
|
|
337
|
+
EnrichSuccessResponse,
|
|
338
|
+
EnrichedTransaction,
|
|
339
|
+
MerchantData,
|
|
340
|
+
LocationData,
|
|
341
|
+
CategoryInfo,
|
|
342
|
+
EntityResult,
|
|
343
|
+
TransactionType,
|
|
344
|
+
TransactionChannel,
|
|
345
|
+
EnrichmentFieldPath,
|
|
346
|
+
} from "triqai";
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
## Contributing
|
|
350
|
+
|
|
351
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines.
|
|
352
|
+
|
|
353
|
+
## License
|
|
354
|
+
|
|
355
|
+
MIT - see [LICENSE](LICENSE) for details.
|
|
356
|
+
|
|
357
|
+
The Triqai API itself is a commercial product. This SDK is open source, but API usage requires an API key and is subject to [Triqai's terms of service](https://triqai.com/terms).
|