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/dist/index.js ADDED
@@ -0,0 +1,842 @@
1
+ // src/errors.ts
2
+ var TriqaiError = class extends Error {
3
+ /** HTTP status code from the API response. */
4
+ statusCode;
5
+ /** Machine-readable error code from the API (e.g. "validation_error"). */
6
+ code;
7
+ /** Correlation ID for support inquiries. */
8
+ requestId;
9
+ /** The raw error body returned by the API. */
10
+ rawError;
11
+ /** Response metadata. */
12
+ meta;
13
+ constructor(message, statusCode, opts) {
14
+ super(message);
15
+ this.name = "TriqaiError";
16
+ this.statusCode = statusCode;
17
+ this.code = opts?.code ?? "unknown_error";
18
+ this.requestId = opts?.requestId;
19
+ this.rawError = opts?.rawError;
20
+ this.meta = opts?.meta;
21
+ }
22
+ };
23
+ var AuthenticationError = class extends TriqaiError {
24
+ constructor(message, opts) {
25
+ super(message, 401, { code: "authentication_error", ...opts });
26
+ this.name = "AuthenticationError";
27
+ }
28
+ };
29
+ var AuthorizationError = class extends TriqaiError {
30
+ constructor(message, opts) {
31
+ super(message, 403, { code: "authorization_error", ...opts });
32
+ this.name = "AuthorizationError";
33
+ }
34
+ };
35
+ var InsufficientCreditsError = class extends TriqaiError {
36
+ constructor(message, opts) {
37
+ super(message, 402, { code: "insufficient_credits", ...opts });
38
+ this.name = "InsufficientCreditsError";
39
+ }
40
+ };
41
+ var NotFoundError = class extends TriqaiError {
42
+ constructor(message, opts) {
43
+ super(message, 404, { code: "not_found", ...opts });
44
+ this.name = "NotFoundError";
45
+ }
46
+ };
47
+ var ValidationError = class extends TriqaiError {
48
+ fieldErrors;
49
+ constructor(message, fieldErrors, opts) {
50
+ super(message, 422, { code: "validation_error", ...opts });
51
+ this.name = "ValidationError";
52
+ this.fieldErrors = fieldErrors ?? {};
53
+ }
54
+ };
55
+ var ClientDisconnectedError = class extends TriqaiError {
56
+ constructor(message, opts) {
57
+ super(message, 499, { code: "client_disconnected", ...opts });
58
+ this.name = "ClientDisconnectedError";
59
+ }
60
+ };
61
+ var DuplicateRequestError = class extends TriqaiError {
62
+ state;
63
+ duplicateRequestId;
64
+ retryAfter;
65
+ constructor(message, opts) {
66
+ super(message, 409, { code: "DUPLICATE_REQUEST", ...opts });
67
+ this.name = "DuplicateRequestError";
68
+ this.state = opts?.state;
69
+ this.duplicateRequestId = opts?.duplicateRequestId;
70
+ this.retryAfter = opts?.retryAfter;
71
+ }
72
+ };
73
+ var RateLimitError = class extends TriqaiError {
74
+ rateLimitInfo;
75
+ constructor(message, rateLimitInfo, opts) {
76
+ super(message, 429, { code: "rate_limited", ...opts });
77
+ this.name = "RateLimitError";
78
+ this.rateLimitInfo = rateLimitInfo;
79
+ }
80
+ };
81
+ var InternalServerError = class extends TriqaiError {
82
+ constructor(message, opts) {
83
+ super(message, 500, { code: "internal_error", ...opts });
84
+ this.name = "InternalServerError";
85
+ }
86
+ };
87
+ var ServiceUnavailableError = class extends TriqaiError {
88
+ retryAfter;
89
+ constructor(message, retryAfter, opts) {
90
+ super(message, 503, { code: "service_unavailable", ...opts });
91
+ this.name = "ServiceUnavailableError";
92
+ this.retryAfter = retryAfter;
93
+ }
94
+ };
95
+ var GatewayTimeoutError = class extends TriqaiError {
96
+ constructor(message, opts) {
97
+ super(message, 504, { code: "gateway_timeout", ...opts });
98
+ this.name = "GatewayTimeoutError";
99
+ }
100
+ };
101
+ var ConnectionError = class extends TriqaiError {
102
+ constructor(message) {
103
+ super(message, 0, { code: "connection_error" });
104
+ this.name = "ConnectionError";
105
+ }
106
+ };
107
+ var TimeoutError = class extends TriqaiError {
108
+ constructor(message) {
109
+ super(message, 0, { code: "timeout" });
110
+ this.name = "TimeoutError";
111
+ }
112
+ };
113
+
114
+ // src/http-client.ts
115
+ var DEFAULT_BASE_URL = "https://api.triqai.com";
116
+ var DEFAULT_MAX_RETRIES = 3;
117
+ var DEFAULT_RETRY_DELAY = 500;
118
+ var DEFAULT_MAX_RETRY_DELAY = 3e4;
119
+ var DEFAULT_TIMEOUT = 6e4;
120
+ var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([429, 500, 503, 504]);
121
+ var SDK_VERSION = "0.1.0";
122
+ var HttpClient = class {
123
+ apiKey;
124
+ baseUrl;
125
+ maxRetries;
126
+ retryDelay;
127
+ maxRetryDelay;
128
+ timeout;
129
+ defaultHeaders;
130
+ onRequest;
131
+ onResponse;
132
+ constructor(apiKey, config = {}) {
133
+ if (!apiKey) {
134
+ throw new Error(
135
+ "API key is required. Get yours at https://triqai.com/dashboard"
136
+ );
137
+ }
138
+ this.apiKey = apiKey;
139
+ this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
140
+ this.maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;
141
+ this.retryDelay = config.retryDelay ?? DEFAULT_RETRY_DELAY;
142
+ this.maxRetryDelay = config.maxRetryDelay ?? DEFAULT_MAX_RETRY_DELAY;
143
+ this.timeout = config.timeout ?? DEFAULT_TIMEOUT;
144
+ this.defaultHeaders = config.defaultHeaders ?? {};
145
+ this.onRequest = config.onRequest;
146
+ this.onResponse = config.onResponse;
147
+ }
148
+ async get(path, query) {
149
+ return this.request("GET", path, void 0, query);
150
+ }
151
+ async post(path, body) {
152
+ return this.request("POST", path, body);
153
+ }
154
+ async delete(path) {
155
+ return this.request("DELETE", path);
156
+ }
157
+ async request(method, path, body, query, extraHeaders) {
158
+ const url = this.buildUrl(path, query);
159
+ const headers = {
160
+ "X-API-Key": this.apiKey,
161
+ "User-Agent": `triqai-node/${SDK_VERSION}`,
162
+ Accept: "application/json",
163
+ ...this.defaultHeaders,
164
+ ...extraHeaders
165
+ };
166
+ if (body !== void 0) {
167
+ headers["Content-Type"] = "application/json";
168
+ }
169
+ let lastError;
170
+ for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
171
+ if (attempt > 0) {
172
+ const delay = this.calculateDelay(attempt, lastError);
173
+ await sleep(delay);
174
+ }
175
+ const startMs = Date.now();
176
+ this.onRequest?.({ method, url, headers: { ...headers }, body });
177
+ try {
178
+ const controller = new AbortController();
179
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
180
+ let response;
181
+ try {
182
+ response = await fetch(url, {
183
+ method,
184
+ headers,
185
+ body: body !== void 0 ? JSON.stringify(body) : void 0,
186
+ signal: controller.signal
187
+ });
188
+ } finally {
189
+ clearTimeout(timeoutId);
190
+ }
191
+ const responseHeaders = parseHeaders(response.headers);
192
+ const responseBody = await response.json().catch(() => null);
193
+ const durationMs = Date.now() - startMs;
194
+ this.onResponse?.({
195
+ status: response.status,
196
+ headers: responseHeaders,
197
+ body: responseBody,
198
+ durationMs,
199
+ retryCount: attempt
200
+ });
201
+ if (response.ok) {
202
+ return {
203
+ data: responseBody,
204
+ status: response.status,
205
+ headers: responseHeaders,
206
+ rateLimitInfo: parseRateLimitHeaders(responseHeaders)
207
+ };
208
+ }
209
+ const shouldRetry = this.canRetry(
210
+ attempt,
211
+ method,
212
+ headers,
213
+ RETRYABLE_STATUS_CODES.has(response.status)
214
+ );
215
+ lastError = this.mapError(response.status, responseBody, responseHeaders);
216
+ if (!shouldRetry) {
217
+ throw lastError;
218
+ }
219
+ } catch (err) {
220
+ if (err instanceof TriqaiError) {
221
+ const canRetry = this.canRetry(
222
+ attempt,
223
+ method,
224
+ headers,
225
+ RETRYABLE_STATUS_CODES.has(err.statusCode)
226
+ );
227
+ if (!canRetry) {
228
+ throw err;
229
+ }
230
+ lastError = err;
231
+ continue;
232
+ }
233
+ if (err instanceof DOMException && err.name === "AbortError") {
234
+ lastError = new TimeoutError(
235
+ `Request timed out after ${this.timeout}ms: ${method} ${path}`
236
+ );
237
+ if (!this.canRetry(attempt, method, headers, true)) {
238
+ throw lastError;
239
+ }
240
+ continue;
241
+ }
242
+ if (isNetworkError(err)) {
243
+ lastError = new ConnectionError(
244
+ `Network error: ${err instanceof Error ? err.message : String(err)}`
245
+ );
246
+ if (!this.canRetry(attempt, method, headers, true)) {
247
+ throw lastError;
248
+ }
249
+ continue;
250
+ }
251
+ throw err;
252
+ }
253
+ }
254
+ throw lastError ?? new TriqaiError("Request failed after retries", 0);
255
+ }
256
+ /**
257
+ * Variant that injects custom headers (used by resources for Idempotency-Key etc.).
258
+ */
259
+ async postWithHeaders(path, body, headers, query) {
260
+ return this.request("POST", path, body, query, headers);
261
+ }
262
+ buildUrl(path, query) {
263
+ const base = `${this.baseUrl}${path}`;
264
+ if (!query) return base;
265
+ const params = new URLSearchParams();
266
+ for (const [k, v] of Object.entries(query)) {
267
+ if (v !== void 0 && v !== null) {
268
+ if (v instanceof Date) {
269
+ params.set(k, v.toISOString());
270
+ } else {
271
+ params.set(k, String(v));
272
+ }
273
+ }
274
+ }
275
+ const qs = params.toString();
276
+ return qs ? `${base}?${qs}` : base;
277
+ }
278
+ calculateDelay(attempt, lastError) {
279
+ if (lastError instanceof RateLimitError && lastError.rateLimitInfo.retryAfter) {
280
+ return lastError.rateLimitInfo.retryAfter * 1e3;
281
+ }
282
+ if (lastError instanceof ServiceUnavailableError && lastError.retryAfter) {
283
+ return lastError.retryAfter * 1e3;
284
+ }
285
+ const exponential = this.retryDelay * Math.pow(2, attempt - 1);
286
+ const jitter = exponential * 0.2 * Math.random();
287
+ return Math.min(exponential + jitter, this.maxRetryDelay);
288
+ }
289
+ canRetry(attempt, method, headers, retryableSignal) {
290
+ return retryableSignal && attempt < this.maxRetries && isIdempotent(method, headers);
291
+ }
292
+ mapError(status, body, headers) {
293
+ const parsed = parseErrorBody(body);
294
+ const opts = {
295
+ code: parsed.code,
296
+ requestId: parsed.requestId,
297
+ rawError: parsed.error,
298
+ meta: parsed.meta
299
+ };
300
+ switch (status) {
301
+ case 401:
302
+ return new AuthenticationError(parsed.message, opts);
303
+ case 402:
304
+ return new InsufficientCreditsError(parsed.message, opts);
305
+ case 403:
306
+ return new AuthorizationError(parsed.message, opts);
307
+ case 404:
308
+ return new NotFoundError(parsed.message, opts);
309
+ case 499:
310
+ return new ClientDisconnectedError(parsed.message, opts);
311
+ case 409: {
312
+ const details = parsed.error?.details ?? {};
313
+ return new DuplicateRequestError(parsed.message, {
314
+ ...opts,
315
+ state: details?.state,
316
+ duplicateRequestId: details?.requestId,
317
+ retryAfter: details?.retryAfterSeconds
318
+ });
319
+ }
320
+ case 422: {
321
+ const fieldErrors = parsed.error?.details?.fieldErrors;
322
+ return new ValidationError(parsed.message, fieldErrors, opts);
323
+ }
324
+ case 429:
325
+ return new RateLimitError(
326
+ parsed.message,
327
+ parseRateLimitHeaders(headers),
328
+ opts
329
+ );
330
+ case 503: {
331
+ const retryAfter = headers["retry-after"] ? parseInt(headers["retry-after"], 10) : void 0;
332
+ return new ServiceUnavailableError(parsed.message, retryAfter, opts);
333
+ }
334
+ case 504:
335
+ return new GatewayTimeoutError(parsed.message, opts);
336
+ default:
337
+ if (status >= 500) {
338
+ return new InternalServerError(parsed.message, opts);
339
+ }
340
+ return new TriqaiError(parsed.message, status, opts);
341
+ }
342
+ }
343
+ };
344
+ function parseHeaders(headers) {
345
+ const out = {};
346
+ headers.forEach((value, key) => {
347
+ out[key.toLowerCase()] = value;
348
+ });
349
+ return out;
350
+ }
351
+ function parseRateLimitHeaders(headers) {
352
+ return {
353
+ limit: maybeInt(headers["x-ratelimit-limit"]),
354
+ remaining: maybeInt(headers["x-ratelimit-remaining"]),
355
+ reset: headers["x-ratelimit-reset"] ?? void 0,
356
+ scope: headers["x-ratelimit-scope"],
357
+ concurrencyLimit: maybeInt(headers["x-ratelimit-concurrency-limit"]),
358
+ concurrencyRemaining: maybeInt(headers["x-ratelimit-concurrency-remaining"]),
359
+ retryAfter: maybeInt(headers["retry-after"])
360
+ };
361
+ }
362
+ function maybeInt(val) {
363
+ if (val === void 0) return void 0;
364
+ const n = parseInt(val, 10);
365
+ return Number.isNaN(n) ? void 0 : n;
366
+ }
367
+ function parseErrorBody(body) {
368
+ if (!body || typeof body !== "object") {
369
+ return {
370
+ message: "Unknown error",
371
+ code: "unknown_error",
372
+ requestId: void 0,
373
+ error: void 0,
374
+ meta: void 0
375
+ };
376
+ }
377
+ const b = body;
378
+ const error = b.error;
379
+ const meta = b.meta;
380
+ return {
381
+ message: error?.message ?? "Unknown error",
382
+ code: error?.code ?? "unknown_error",
383
+ requestId: meta?.requestId,
384
+ error: error?.code ? { code: error.code, message: error.message ?? "Unknown error", details: error.details } : void 0,
385
+ meta: meta?.generatedAt ? meta : void 0
386
+ };
387
+ }
388
+ function isIdempotent(method, headers) {
389
+ if (method === "GET" || method === "DELETE") return true;
390
+ const normalized = normalizeHeaderKeyMap(headers);
391
+ if (normalized.has("idempotency-key") || normalized.has("x-idempotency-key")) {
392
+ return true;
393
+ }
394
+ return false;
395
+ }
396
+ function normalizeHeaderKeyMap(headers) {
397
+ return new Set(Object.keys(headers).map((key) => key.toLowerCase()));
398
+ }
399
+ function isNetworkError(err) {
400
+ if (err instanceof TypeError) return true;
401
+ if (err instanceof Error && err.message.includes("fetch")) return true;
402
+ return false;
403
+ }
404
+ function sleep(ms) {
405
+ return new Promise((resolve) => setTimeout(resolve, ms));
406
+ }
407
+
408
+ // src/resources/categories.ts
409
+ var Categories = class {
410
+ constructor(http) {
411
+ this.http = http;
412
+ }
413
+ /**
414
+ * List all available transaction categories.
415
+ *
416
+ * Returns the full category tree used for transaction classification,
417
+ * including MCC, SIC, and NAICS codes.
418
+ *
419
+ * @returns Array of category info objects and the total count.
420
+ *
421
+ * @example
422
+ * ```ts
423
+ * const { categories, total } = await triqai.categories.list();
424
+ * console.log(`${total} categories available`);
425
+ * ```
426
+ */
427
+ async list() {
428
+ const resp = await this.http.get("/v1/categories");
429
+ return {
430
+ categories: resp.data.data.categories,
431
+ total: resp.data.data.total,
432
+ categoryVersion: resp.data.meta.categoryVersion
433
+ };
434
+ }
435
+ };
436
+
437
+ // src/resources/intermediaries.ts
438
+ var Intermediaries = class {
439
+ constructor(http) {
440
+ this.http = http;
441
+ }
442
+ /**
443
+ * Get an intermediary (payment processor / platform) by ID.
444
+ *
445
+ * @param id - Intermediary UUID.
446
+ * @returns The intermediary data (name, icon, description, website, domain, etc.).
447
+ *
448
+ * @example
449
+ * ```ts
450
+ * const intermediary = await triqai.intermediaries.get("550e8400-...");
451
+ * console.log(intermediary.name); // "PayPal", "Square", etc.
452
+ * ```
453
+ */
454
+ async get(id) {
455
+ const resp = await this.http.get(
456
+ `/v1/intermediaries/${encodeURIComponent(id)}`
457
+ );
458
+ return resp.data.data.intermediary;
459
+ }
460
+ };
461
+
462
+ // src/pagination.ts
463
+ var Page = class _Page {
464
+ data;
465
+ pageInfo;
466
+ _fetchPage;
467
+ constructor(data, pageInfo, fetchPage) {
468
+ this.data = data;
469
+ this.pageInfo = pageInfo;
470
+ this._fetchPage = fetchPage;
471
+ }
472
+ get hasNextPage() {
473
+ return this.pageInfo.page < this.pageInfo.totalPages;
474
+ }
475
+ get hasPreviousPage() {
476
+ return this.pageInfo.page > 1;
477
+ }
478
+ async nextPage() {
479
+ if (!this.hasNextPage) {
480
+ return new _Page([], this.pageInfo, this._fetchPage);
481
+ }
482
+ return this._fetchPage(this.pageInfo.page + 1, this.pageInfo.size);
483
+ }
484
+ async previousPage() {
485
+ if (!this.hasPreviousPage) {
486
+ return new _Page([], this.pageInfo, this._fetchPage);
487
+ }
488
+ return this._fetchPage(this.pageInfo.page - 1, this.pageInfo.size);
489
+ }
490
+ /**
491
+ * Returns an async iterator that yields every item across all pages,
492
+ * starting from the current page.
493
+ *
494
+ * ```ts
495
+ * for await (const item of page.autoPaginate()) {
496
+ * console.log(item);
497
+ * }
498
+ * ```
499
+ */
500
+ async *autoPaginate() {
501
+ let current = this;
502
+ while (true) {
503
+ for (const item of current.data) {
504
+ yield item;
505
+ }
506
+ if (!current.hasNextPage) break;
507
+ current = await current.nextPage();
508
+ }
509
+ }
510
+ /**
511
+ * Symbol.asyncIterator so `Page` itself can be used in `for await...of`.
512
+ */
513
+ [Symbol.asyncIterator]() {
514
+ return this.autoPaginate();
515
+ }
516
+ };
517
+
518
+ // src/resources/issue-reports.ts
519
+ var IssueReports = class {
520
+ constructor(http) {
521
+ this.http = http;
522
+ }
523
+ /**
524
+ * Report an issue with an enrichment result.
525
+ *
526
+ * @param params - The issue report details.
527
+ * @returns The created issue report.
528
+ *
529
+ * @example
530
+ * ```ts
531
+ * const report = await triqai.issueReports.create({
532
+ * transactionId: "tx-uuid",
533
+ * description: "Merchant was identified incorrectly",
534
+ * fields: ["entities.merchant.data.name"],
535
+ * });
536
+ * console.log(report.id, report.status);
537
+ * ```
538
+ */
539
+ async create(params) {
540
+ const resp = await this.http.post("/v1/report-issue", {
541
+ transaction_id: params.transactionId,
542
+ description: params.description,
543
+ fields: params.fields
544
+ });
545
+ return resp.data.data.issueReport;
546
+ }
547
+ /**
548
+ * List issue reports with pagination.
549
+ *
550
+ * @returns A `Page` of issue reports. Use `.autoPaginate()` or
551
+ * `for await...of` to iterate through all pages automatically.
552
+ *
553
+ * @example
554
+ * ```ts
555
+ * const page = await triqai.issueReports.list({ status: "pending" });
556
+ * for (const report of page.data) {
557
+ * console.log(report.id, report.status);
558
+ * }
559
+ * ```
560
+ */
561
+ async list(params) {
562
+ const fetchPage = async (page, size) => {
563
+ const query = { page, size };
564
+ if (params?.status) query.status = params.status;
565
+ if (params?.transactionId) query.transaction_id = params.transactionId;
566
+ const resp = await this.http.get("/v1/report-issue", query);
567
+ const pageInfo = {
568
+ page: resp.data.meta.page,
569
+ size: resp.data.meta.size,
570
+ total: resp.data.meta.total,
571
+ totalPages: resp.data.meta.totalPages
572
+ };
573
+ return new Page(resp.data.data, pageInfo, fetchPage);
574
+ };
575
+ return fetchPage(params?.page ?? 1, params?.size ?? 25);
576
+ }
577
+ /**
578
+ * Get a single issue report by ID.
579
+ *
580
+ * @param id - Issue report UUID.
581
+ * @returns The issue report details.
582
+ */
583
+ async get(id) {
584
+ const resp = await this.http.get(
585
+ `/v1/report-issue/${encodeURIComponent(id)}`
586
+ );
587
+ return resp.data.data.issueReport;
588
+ }
589
+ };
590
+
591
+ // src/resources/locations.ts
592
+ var Locations = class {
593
+ constructor(http) {
594
+ this.http = http;
595
+ }
596
+ /**
597
+ * Get a location by ID.
598
+ *
599
+ * @param id - Location UUID.
600
+ * @returns The location data (name, formatted address, coordinates, phone, rating, etc.).
601
+ *
602
+ * @example
603
+ * ```ts
604
+ * const location = await triqai.locations.get("550e8400-e29b-41d4-a716-446655440000");
605
+ * console.log(location.formatted, location.structured.city);
606
+ * ```
607
+ */
608
+ async get(id) {
609
+ const resp = await this.http.get(
610
+ `/v1/locations/${encodeURIComponent(id)}`
611
+ );
612
+ return resp.data.data.location;
613
+ }
614
+ };
615
+
616
+ // src/resources/merchants.ts
617
+ var Merchants = class {
618
+ constructor(http) {
619
+ this.http = http;
620
+ }
621
+ /**
622
+ * Get a merchant by ID.
623
+ *
624
+ * @param id - Merchant UUID.
625
+ * @returns The merchant data (name, icon, website, domain, aliases, etc.).
626
+ *
627
+ * @example
628
+ * ```ts
629
+ * const merchant = await triqai.merchants.get("550e8400-e29b-41d4-a716-446655440000");
630
+ * console.log(merchant.name, merchant.website);
631
+ * ```
632
+ */
633
+ async get(id) {
634
+ const resp = await this.http.get(
635
+ `/v1/merchants/${encodeURIComponent(id)}`
636
+ );
637
+ return resp.data.data.merchant;
638
+ }
639
+ };
640
+
641
+ // src/resources/transactions.ts
642
+ var Transactions = class {
643
+ constructor(http) {
644
+ this.http = http;
645
+ }
646
+ /**
647
+ * Enrich a transaction with merchant, category, location, and entity data.
648
+ *
649
+ * @param request - The transaction to enrich (title, country, type, and optional options).
650
+ * @param options - Optional enrichment controls (force bypass cache, idempotency key).
651
+ * @returns The enriched transaction data.
652
+ *
653
+ * @example
654
+ * ```ts
655
+ * const result = await triqai.transactions.enrich({
656
+ * title: "STARBUCKS SEATTLE WA",
657
+ * country: "US",
658
+ * type: "expense",
659
+ * });
660
+ * console.log(result.data.entities);
661
+ * ```
662
+ */
663
+ async enrich(request, options) {
664
+ const headers = {};
665
+ const query = {};
666
+ if (options?.idempotencyKey) {
667
+ headers["Idempotency-Key"] = options.idempotencyKey;
668
+ }
669
+ if (options?.force) {
670
+ query.force = "true";
671
+ }
672
+ const resp = await this.http.postWithHeaders(
673
+ "/v1/transactions/enrich",
674
+ request,
675
+ headers,
676
+ Object.keys(query).length > 0 ? query : void 0
677
+ );
678
+ return resp.data;
679
+ }
680
+ /**
681
+ * List enriched transactions with pagination.
682
+ *
683
+ * @returns A `Page` of enriched transactions. Use `.autoPaginate()` or
684
+ * `for await...of` to iterate through all pages automatically.
685
+ *
686
+ * @example
687
+ * ```ts
688
+ * const page = await triqai.transactions.list({ size: 10 });
689
+ * console.log(page.data); // first 10 transactions
690
+ *
691
+ * // Auto-paginate through all:
692
+ * for await (const tx of page) {
693
+ * console.log(tx.id, tx.raw);
694
+ * }
695
+ * ```
696
+ */
697
+ async list(params) {
698
+ const fetchPage = async (page, size) => {
699
+ const query = {
700
+ page,
701
+ size
702
+ };
703
+ if (params?.startDate) {
704
+ query.startDate = params.startDate instanceof Date ? params.startDate.toISOString() : params.startDate;
705
+ }
706
+ if (params?.endDate) {
707
+ query.endDate = params.endDate instanceof Date ? params.endDate.toISOString() : params.endDate;
708
+ }
709
+ const resp = await this.http.get("/v1/transactions", query);
710
+ const { transactions, pagination } = resp.data.data;
711
+ return new Page(transactions, pagination, fetchPage);
712
+ };
713
+ return fetchPage(params?.page ?? 1, params?.size ?? 25);
714
+ }
715
+ /**
716
+ * Get a single transaction by ID.
717
+ *
718
+ * @param id - Transaction UUID.
719
+ * @returns The enriched transaction record.
720
+ */
721
+ async get(id) {
722
+ const resp = await this.http.get(
723
+ `/v1/transactions/${encodeURIComponent(id)}`
724
+ );
725
+ return resp.data.data.transaction;
726
+ }
727
+ /**
728
+ * Delete a transaction by ID.
729
+ *
730
+ * @param id - Transaction UUID.
731
+ * @returns Confirmation with the deleted transaction ID.
732
+ */
733
+ async delete(id) {
734
+ const resp = await this.http.delete(
735
+ `/v1/transactions/${encodeURIComponent(id)}`
736
+ );
737
+ return resp.data.data;
738
+ }
739
+ };
740
+
741
+ // src/client.ts
742
+ var Triqai = class {
743
+ /** Enrich, list, get, and delete transactions. */
744
+ transactions;
745
+ /** List the full category taxonomy. */
746
+ categories;
747
+ /** Look up merchant details by ID. */
748
+ merchants;
749
+ /** Look up location details by ID. */
750
+ locations;
751
+ /** Look up intermediary (payment processor) details by ID. */
752
+ intermediaries;
753
+ /** Create and manage enrichment issue reports. */
754
+ issueReports;
755
+ http;
756
+ /**
757
+ * Create a new Triqai SDK client.
758
+ *
759
+ * @param apiKey - Your Triqai API key (starts with `triq_`). Get one at https://triqai.com/dashboard
760
+ * @param config - Optional configuration (base URL, retry settings, hooks).
761
+ */
762
+ constructor(apiKey, config) {
763
+ this.http = new HttpClient(apiKey, config);
764
+ this.transactions = new Transactions(this.http);
765
+ this.categories = new Categories(this.http);
766
+ this.merchants = new Merchants(this.http);
767
+ this.locations = new Locations(this.http);
768
+ this.intermediaries = new Intermediaries(this.http);
769
+ this.issueReports = new IssueReports(this.http);
770
+ }
771
+ /**
772
+ * Check the API health status.
773
+ *
774
+ * @returns Health status including service name and version.
775
+ *
776
+ * @example
777
+ * ```ts
778
+ * const health = await triqai.health();
779
+ * console.log(health.data.status); // "healthy"
780
+ * console.log(health.data.version); // "1.1.9"
781
+ * ```
782
+ */
783
+ async health() {
784
+ const resp = await this.http.get("/health");
785
+ return resp.data;
786
+ }
787
+ /**
788
+ * Get API version and endpoint directory.
789
+ *
790
+ * @returns API version info and available endpoint paths.
791
+ *
792
+ * @example
793
+ * ```ts
794
+ * const info = await triqai.apiInfo();
795
+ * console.log(info.data.version); // "v1"
796
+ * console.log(info.data.endpoints);
797
+ * ```
798
+ */
799
+ async apiInfo() {
800
+ const resp = await this.http.get("/v1");
801
+ return resp.data;
802
+ }
803
+ /**
804
+ * Make a raw GET request to any API path.
805
+ * Useful for accessing endpoints not yet covered by a resource class.
806
+ *
807
+ * @param path - API path (e.g. "/v1/some-endpoint").
808
+ * @param query - Optional query parameters.
809
+ * @returns The full HTTP response including headers and rate limit info.
810
+ */
811
+ async rawGet(path, query) {
812
+ return this.http.get(path, query);
813
+ }
814
+ /**
815
+ * Make a raw POST request to any API path.
816
+ * Useful for accessing endpoints not yet covered by a resource class.
817
+ *
818
+ * @param path - API path (e.g. "/v1/some-endpoint").
819
+ * @param body - Request body.
820
+ * @returns The full HTTP response including headers and rate limit info.
821
+ */
822
+ async rawPost(path, body) {
823
+ return this.http.post(path, body);
824
+ }
825
+ /**
826
+ * Make a raw DELETE request to any API path.
827
+ * Useful for accessing endpoints not yet covered by a resource class.
828
+ *
829
+ * @param path - API path (e.g. "/v1/some-resource/uuid").
830
+ * @returns The full HTTP response including headers and rate limit info.
831
+ */
832
+ async rawDelete(path) {
833
+ return this.http.delete(path);
834
+ }
835
+ };
836
+
837
+ // src/index.ts
838
+ var index_default = Triqai;
839
+
840
+ export { AuthenticationError, AuthorizationError, ClientDisconnectedError, ConnectionError, DuplicateRequestError, GatewayTimeoutError, InsufficientCreditsError, InternalServerError, NotFoundError, Page, RateLimitError, ServiceUnavailableError, TimeoutError, Triqai, TriqaiError, ValidationError, index_default as default };
841
+ //# sourceMappingURL=index.js.map
842
+ //# sourceMappingURL=index.js.map