@nopaque/sdk 0.1.1

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.cjs ADDED
@@ -0,0 +1,1192 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ APIConnectionError: () => APIConnectionError,
24
+ APITimeoutError: () => APITimeoutError,
25
+ AuthenticationError: () => AuthenticationError,
26
+ ConflictError: () => ConflictError,
27
+ Nopaque: () => Nopaque,
28
+ NopaqueAPIError: () => NopaqueAPIError,
29
+ NopaqueConfigError: () => NopaqueConfigError,
30
+ NopaqueError: () => NopaqueError,
31
+ NopaqueTimeoutError: () => NopaqueTimeoutError,
32
+ NotFoundError: () => NotFoundError,
33
+ Page: () => Page,
34
+ Paginator: () => Paginator,
35
+ PermissionError: () => PermissionError,
36
+ RateLimitError: () => RateLimitError,
37
+ ServerError: () => ServerError,
38
+ VERSION: () => VERSION,
39
+ ValidationError: () => ValidationError
40
+ });
41
+ module.exports = __toCommonJS(index_exports);
42
+
43
+ // src/errors.ts
44
+ var NopaqueError = class extends Error {
45
+ constructor(message) {
46
+ super(message);
47
+ this.name = this.constructor.name;
48
+ }
49
+ };
50
+ var NopaqueConfigError = class extends NopaqueError {
51
+ };
52
+ var NopaqueTimeoutError = class extends NopaqueError {
53
+ };
54
+ var APIConnectionError = class extends NopaqueError {
55
+ cause;
56
+ constructor(message, cause) {
57
+ super(message);
58
+ this.cause = cause;
59
+ }
60
+ };
61
+ var APITimeoutError = class extends NopaqueError {
62
+ };
63
+ var NopaqueAPIError = class extends NopaqueError {
64
+ status;
65
+ code;
66
+ details;
67
+ requestId;
68
+ response;
69
+ constructor(init) {
70
+ super(init.message ?? `HTTP ${init.status}`);
71
+ this.status = init.status;
72
+ this.code = init.code ?? null;
73
+ this.details = init.details ?? null;
74
+ this.requestId = init.requestId ?? null;
75
+ this.response = init.response ?? null;
76
+ }
77
+ };
78
+ var ValidationError = class extends NopaqueAPIError {
79
+ };
80
+ var AuthenticationError = class extends NopaqueAPIError {
81
+ };
82
+ var PermissionError = class extends NopaqueAPIError {
83
+ };
84
+ var NotFoundError = class extends NopaqueAPIError {
85
+ };
86
+ var ConflictError = class extends NopaqueAPIError {
87
+ };
88
+ var ServerError = class extends NopaqueAPIError {
89
+ };
90
+ var RateLimitError = class extends NopaqueAPIError {
91
+ retryAfter;
92
+ constructor(init) {
93
+ super(init);
94
+ this.retryAfter = init.retryAfter ?? null;
95
+ }
96
+ };
97
+ var STATUS_MAP = {
98
+ 400: ValidationError,
99
+ 401: AuthenticationError,
100
+ 403: PermissionError,
101
+ 404: NotFoundError,
102
+ 409: ConflictError,
103
+ 429: RateLimitError
104
+ };
105
+ function classifyStatus(status) {
106
+ const specific = STATUS_MAP[status];
107
+ if (specific) return specific;
108
+ if (status >= 500 && status < 600) return ServerError;
109
+ return NopaqueAPIError;
110
+ }
111
+
112
+ // src/config.ts
113
+ var DEFAULT_BASE_URL = "https://api.nopaque.co.uk";
114
+ var DEFAULT_TIMEOUT_MS = 6e4;
115
+ var DEFAULT_MAX_RETRIES = 3;
116
+ function resolveConfig(opts) {
117
+ const apiKey = opts.apiKey ?? process.env.NOPAQUE_API_KEY ?? "";
118
+ if (!apiKey) {
119
+ throw new NopaqueConfigError(
120
+ "No API key provided. Pass apiKey in the constructor or set NOPAQUE_API_KEY."
121
+ );
122
+ }
123
+ const baseUrl = (opts.baseUrl ?? process.env.NOPAQUE_BASE_URL ?? DEFAULT_BASE_URL).replace(/\/$/, "");
124
+ return {
125
+ apiKey,
126
+ baseUrl,
127
+ timeout: opts.timeout ?? DEFAULT_TIMEOUT_MS,
128
+ maxRetries: opts.maxRetries ?? DEFAULT_MAX_RETRIES,
129
+ defaultHeaders: opts.defaultHeaders ?? {},
130
+ onRetry: opts.onRetry,
131
+ fetch: opts.fetch ?? globalThis.fetch.bind(globalThis)
132
+ };
133
+ }
134
+
135
+ // src/version.ts
136
+ var VERSION = true ? "0.1.1" : "0.0.0-dev";
137
+
138
+ // src/userAgent.ts
139
+ function composeUserAgent() {
140
+ const nodeVersion = typeof process !== "undefined" ? process.version : "unknown";
141
+ return `nopaque-node/${VERSION} (node/${nodeVersion})`;
142
+ }
143
+
144
+ // src/requestOptions.ts
145
+ function mergeOptions(base, override) {
146
+ if (!base) return override ?? {};
147
+ if (!override) return base;
148
+ return {
149
+ ...base,
150
+ ...override,
151
+ headers: { ...base.headers ?? {}, ...override.headers ?? {} }
152
+ };
153
+ }
154
+
155
+ // src/retry.ts
156
+ var DEFAULTS = { base: 500, cap: 8e3, jitter: 1.5 };
157
+ function computeBackoff(attempt, p = {}) {
158
+ const { base, cap, jitter } = { ...DEFAULTS, ...p };
159
+ const raw = Math.min(cap, base * 2 ** attempt);
160
+ const mul = 0.5 + Math.random() * (jitter - 0.5);
161
+ return Math.round(raw * mul);
162
+ }
163
+ function delayFor(args) {
164
+ const { attempt, error, ...p } = args;
165
+ if (error instanceof RateLimitError && error.retryAfter !== null) {
166
+ return Math.round(error.retryAfter * 1e3);
167
+ }
168
+ return computeBackoff(attempt, p);
169
+ }
170
+ function shouldRetry({ method, error, beforeSend }) {
171
+ const m = method.toUpperCase();
172
+ if (error instanceof RateLimitError) return true;
173
+ if (m === "POST") {
174
+ return error instanceof APIConnectionError && beforeSend;
175
+ }
176
+ if (error instanceof APIConnectionError || error instanceof APITimeoutError || error instanceof ServerError) {
177
+ return true;
178
+ }
179
+ if (error instanceof NopaqueAPIError) return false;
180
+ return false;
181
+ }
182
+
183
+ // src/transport.ts
184
+ var Transport = class {
185
+ constructor(config) {
186
+ this.config = config;
187
+ }
188
+ config;
189
+ async request(method, path, { params, body, requestOptions } = {}) {
190
+ const url = this.buildUrl(path, params);
191
+ const headers = this.buildHeaders(requestOptions);
192
+ const merged = mergeOptions(void 0, requestOptions);
193
+ const timeout = merged.timeout ?? this.config.timeout;
194
+ const maxRetries = merged.maxRetries ?? this.config.maxRetries;
195
+ let attempt = 0;
196
+ while (true) {
197
+ let beforeSend = true;
198
+ const controller = new AbortController();
199
+ const timer = setTimeout(() => controller.abort(), timeout);
200
+ const combinedSignal = mergeAbortSignals([controller.signal, merged.signal]);
201
+ let err = null;
202
+ let response = null;
203
+ try {
204
+ response = await this.config.fetch(url, {
205
+ method,
206
+ headers,
207
+ body: body === void 0 ? void 0 : JSON.stringify(body),
208
+ signal: combinedSignal
209
+ });
210
+ beforeSend = false;
211
+ if (!response.ok) {
212
+ err = await classifyResponse(response);
213
+ }
214
+ } catch (fetchErr) {
215
+ if (fetchErr.name === "AbortError") {
216
+ err = new APITimeoutError(`request timed out after ${timeout}ms`);
217
+ } else {
218
+ err = new APIConnectionError(
219
+ `fetch failed: ${fetchErr.message ?? "unknown"}`,
220
+ fetchErr
221
+ );
222
+ }
223
+ } finally {
224
+ clearTimeout(timer);
225
+ }
226
+ if (!err) {
227
+ if (response.status === 204) return void 0;
228
+ const ct = response.headers.get("content-type") ?? "";
229
+ if (!ct.includes("application/json")) return void 0;
230
+ return await response.json();
231
+ }
232
+ if (attempt >= maxRetries) throw err;
233
+ if (!shouldRetry({ method, error: err, beforeSend })) throw err;
234
+ const delay = delayFor({ attempt, error: err });
235
+ if (this.config.onRetry) {
236
+ try {
237
+ this.config.onRetry(attempt, err, delay);
238
+ } catch {
239
+ }
240
+ }
241
+ await new Promise((r) => setTimeout(r, delay));
242
+ attempt++;
243
+ }
244
+ }
245
+ buildUrl(path, params) {
246
+ const normalized = path.startsWith("/") ? path : `/${path}`;
247
+ const url = new URL(`${this.config.baseUrl}${normalized}`);
248
+ if (params) {
249
+ for (const [k, v] of Object.entries(params)) {
250
+ if (v === void 0 || v === null) continue;
251
+ url.searchParams.set(k, String(v));
252
+ }
253
+ }
254
+ return url.toString();
255
+ }
256
+ buildHeaders(options) {
257
+ const h = new Headers({
258
+ "x-api-key": this.config.apiKey,
259
+ "user-agent": composeUserAgent(),
260
+ "accept": "application/json"
261
+ });
262
+ for (const [k, v] of Object.entries(this.config.defaultHeaders)) h.set(k, v);
263
+ if (options?.headers) {
264
+ for (const [k, v] of Object.entries(options.headers)) h.set(k, v);
265
+ }
266
+ return h;
267
+ }
268
+ };
269
+ async function classifyResponse(response) {
270
+ let body = null;
271
+ try {
272
+ body = await response.clone().json();
273
+ } catch {
274
+ body = null;
275
+ }
276
+ const bodyObj = body && typeof body === "object" ? body : {};
277
+ const message = typeof bodyObj.error === "string" ? bodyObj.error : `HTTP ${response.status}`;
278
+ const code = typeof bodyObj.code === "string" ? bodyObj.code : null;
279
+ const details = bodyObj.details ?? null;
280
+ const requestId = response.headers.get("x-request-id");
281
+ const Cls = classifyStatus(response.status);
282
+ if (Cls === RateLimitError) {
283
+ const raw = response.headers.get("retry-after");
284
+ const retryAfter = raw !== null ? Number.parseFloat(raw) : null;
285
+ return new RateLimitError({
286
+ status: response.status,
287
+ code,
288
+ message,
289
+ details,
290
+ requestId,
291
+ response,
292
+ retryAfter: Number.isFinite(retryAfter) ? retryAfter : null
293
+ });
294
+ }
295
+ return new Cls({
296
+ status: response.status,
297
+ code,
298
+ message,
299
+ details,
300
+ requestId,
301
+ response
302
+ });
303
+ }
304
+ function mergeAbortSignals(signals) {
305
+ const valid = signals.filter((s) => !!s);
306
+ if (valid.length === 1) return valid[0];
307
+ if (valid.length === 0) return new AbortController().signal;
308
+ const ctrl = new AbortController();
309
+ for (const s of valid) {
310
+ if (s.aborted) {
311
+ ctrl.abort(s.reason);
312
+ return ctrl.signal;
313
+ }
314
+ s.addEventListener("abort", () => ctrl.abort(s.reason), { once: true });
315
+ }
316
+ return ctrl.signal;
317
+ }
318
+
319
+ // src/resources/audio.ts
320
+ var import_node_fs2 = require("fs");
321
+
322
+ // src/resource.ts
323
+ var Resource = class {
324
+ constructor(transport) {
325
+ this.transport = transport;
326
+ }
327
+ transport;
328
+ };
329
+
330
+ // src/pagination.ts
331
+ var Page = class {
332
+ constructor(items, nextToken) {
333
+ this.items = items;
334
+ this.nextToken = nextToken;
335
+ }
336
+ items;
337
+ nextToken;
338
+ };
339
+ var Paginator = class {
340
+ constructor(options) {
341
+ this.options = options;
342
+ }
343
+ options;
344
+ async *[Symbol.asyncIterator]() {
345
+ const limit = this.options.params.limit;
346
+ const params = { ...this.options.params };
347
+ const key = this.options.itemsKey;
348
+ let yielded = 0;
349
+ while (true) {
350
+ const page = await this.options.fetchPage(params);
351
+ const rawItems = (key ? page[key] : void 0) ?? page.items ?? [];
352
+ const items = rawItems;
353
+ for (const raw of items) {
354
+ const item = this.options.mapItem ? this.options.mapItem(raw) : raw;
355
+ yield item;
356
+ yielded++;
357
+ if (limit !== void 0 && yielded >= limit) return;
358
+ }
359
+ const nextToken = page.nextToken;
360
+ if (!nextToken) return;
361
+ params.nextToken = nextToken;
362
+ }
363
+ }
364
+ };
365
+
366
+ // src/s3.ts
367
+ var import_node_fs = require("fs");
368
+ var import_node_path = require("path");
369
+ async function readBytes(input) {
370
+ if (typeof input === "string") {
371
+ const buf = await import_node_fs.promises.readFile(input);
372
+ return { bytes: new Uint8Array(buf), inferredName: (0, import_node_path.basename)(input) };
373
+ }
374
+ if (input instanceof Uint8Array) {
375
+ return { bytes: input, inferredName: null };
376
+ }
377
+ if (typeof Blob !== "undefined" && input instanceof Blob) {
378
+ const buf = await input.arrayBuffer();
379
+ const name = input.name ?? null;
380
+ return { bytes: new Uint8Array(buf), inferredName: name };
381
+ }
382
+ if (typeof input.getReader === "function") {
383
+ const reader = input.getReader();
384
+ const chunks = [];
385
+ let total = 0;
386
+ while (true) {
387
+ const { done, value } = await reader.read();
388
+ if (done) break;
389
+ chunks.push(value);
390
+ total += value.byteLength;
391
+ }
392
+ const out = new Uint8Array(total);
393
+ let off = 0;
394
+ for (const c of chunks) {
395
+ out.set(c, off);
396
+ off += c.byteLength;
397
+ }
398
+ return { bytes: out, inferredName: null };
399
+ }
400
+ if (typeof input.on === "function") {
401
+ const chunks = [];
402
+ for await (const chunk of input) {
403
+ chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
404
+ }
405
+ const buf = Buffer.concat(chunks);
406
+ return { bytes: new Uint8Array(buf), inferredName: null };
407
+ }
408
+ throw new TypeError("unsupported file input");
409
+ }
410
+ var EXTENSION_MAP = {
411
+ ".wav": "audio/wav",
412
+ ".mp3": "audio/mpeg",
413
+ ".mp4": "audio/mp4",
414
+ ".m4a": "audio/mp4",
415
+ ".ogg": "audio/ogg",
416
+ ".flac": "audio/flac",
417
+ ".webm": "audio/webm"
418
+ };
419
+ function sniffContentType(name) {
420
+ if (!name) return "application/octet-stream";
421
+ const dot = name.lastIndexOf(".");
422
+ const ext = dot >= 0 ? name.slice(dot).toLowerCase() : "";
423
+ return EXTENSION_MAP[ext] ?? "application/octet-stream";
424
+ }
425
+ async function s3Put(url, data, { contentType, fetch }) {
426
+ let resp;
427
+ try {
428
+ resp = await fetch(url, {
429
+ method: "PUT",
430
+ body: data,
431
+ headers: { "content-type": contentType }
432
+ });
433
+ } catch (err) {
434
+ throw new APIConnectionError(`S3 PUT failed: ${err.message}`, err);
435
+ }
436
+ if (resp.status >= 400) {
437
+ const text = await resp.text().catch(() => "");
438
+ throw new APIConnectionError(`S3 PUT returned ${resp.status}: ${text.slice(0, 200)}`);
439
+ }
440
+ }
441
+ async function s3Get(url, { fetch }) {
442
+ let resp;
443
+ try {
444
+ resp = await fetch(url);
445
+ } catch (err) {
446
+ throw new APIConnectionError(`S3 GET failed: ${err.message}`, err);
447
+ }
448
+ if (resp.status >= 400) {
449
+ const text = await resp.text().catch(() => "");
450
+ throw new APIConnectionError(`S3 GET returned ${resp.status}: ${text.slice(0, 200)}`);
451
+ }
452
+ return new Uint8Array(await resp.arrayBuffer());
453
+ }
454
+
455
+ // src/resources/audio.ts
456
+ var AudioResource = class extends Resource {
457
+ list(params = {}, requestOptions) {
458
+ return new Paginator({
459
+ fetchPage: async (p) => await this.transport.request("GET", "/audio", {
460
+ params: p,
461
+ requestOptions
462
+ }),
463
+ params: { ...params },
464
+ itemsKey: "audioFiles"
465
+ });
466
+ }
467
+ async listPage(params = {}, requestOptions) {
468
+ const raw = await this.transport.request("GET", "/audio", { params, requestOptions });
469
+ return new Page(raw.audioFiles ?? raw.items ?? [], raw.nextToken ?? null);
470
+ }
471
+ async get(audioId, requestOptions) {
472
+ return await this.transport.request("GET", `/audio/${audioId}`, { requestOptions });
473
+ }
474
+ async delete(audioId, requestOptions) {
475
+ await this.transport.request("DELETE", `/audio/${audioId}`, { requestOptions });
476
+ }
477
+ async createUploadUrl(body, requestOptions) {
478
+ return await this.transport.request("POST", "/audio/upload-url", {
479
+ body,
480
+ requestOptions
481
+ });
482
+ }
483
+ async createDownloadUrl(audioId, requestOptions) {
484
+ return await this.transport.request("GET", "/audio/download-url", {
485
+ params: { audioId },
486
+ requestOptions
487
+ });
488
+ }
489
+ async upload(input, requestOptions) {
490
+ const { bytes, inferredName } = await readBytes(input.file);
491
+ const resolvedName = input.name ?? inferredName ?? "upload.bin";
492
+ const resolvedType = input.contentType ?? sniffContentType(resolvedName);
493
+ const presign = await this.createUploadUrl(
494
+ { fileName: resolvedName, contentType: resolvedType },
495
+ requestOptions
496
+ );
497
+ await s3Put(presign.uploadUrl, bytes, {
498
+ contentType: resolvedType,
499
+ fetch: this.transport.config.fetch
500
+ });
501
+ return await this.get(presign.audioId, requestOptions);
502
+ }
503
+ async download(audioId, options, requestOptions) {
504
+ const presign = await this.createDownloadUrl(audioId, requestOptions);
505
+ const bytes = await s3Get(presign.downloadUrl, { fetch: this.transport.config.fetch });
506
+ if (options?.to) {
507
+ await import_node_fs2.promises.writeFile(options.to, bytes);
508
+ return;
509
+ }
510
+ return bytes;
511
+ }
512
+ };
513
+
514
+ // src/polling.ts
515
+ var DEFAULT_BASE = 5e3;
516
+ var DEFAULT_CAP = 15e3;
517
+ function pollIntervalCurve(step, { base = DEFAULT_BASE, cap = DEFAULT_CAP } = {}) {
518
+ if (step < 2) return base;
519
+ const soft = base * 1.2 ** (step - 1);
520
+ return Math.min(cap, soft);
521
+ }
522
+ async function waitFor(args) {
523
+ const timeout = args.timeout ?? 6e5;
524
+ const initial = args.initialInterval ?? DEFAULT_BASE;
525
+ const cap = args.intervalCap ?? DEFAULT_CAP;
526
+ const deadline = Date.now() + timeout;
527
+ let step = 0;
528
+ while (true) {
529
+ const doc = await args.fetch();
530
+ if (args.onUpdate) {
531
+ try {
532
+ args.onUpdate(doc);
533
+ } catch {
534
+ }
535
+ }
536
+ if (args.isTerminal(doc)) return doc;
537
+ const now = Date.now();
538
+ if (now >= deadline) {
539
+ throw new NopaqueTimeoutError(`waitFor timed out after ${timeout}ms`);
540
+ }
541
+ const interval = Math.min(
542
+ pollIntervalCurve(step, { base: initial, cap }),
543
+ Math.max(0, deadline - now)
544
+ );
545
+ await new Promise((r) => setTimeout(r, interval));
546
+ step++;
547
+ }
548
+ }
549
+
550
+ // src/resources/batches.ts
551
+ var RUN_TERMINAL_STATUSES = /* @__PURE__ */ new Set(["completed", "failed", "cancelled"]);
552
+ var BatchesResource = class extends Resource {
553
+ async create(body, requestOptions) {
554
+ return await this.transport.request("POST", "/testing/batches", { body, requestOptions });
555
+ }
556
+ list(params = {}, requestOptions) {
557
+ return new Paginator({
558
+ fetchPage: async (p) => await this.transport.request("GET", "/testing/batches", { params: p, requestOptions }),
559
+ params: { ...params },
560
+ itemsKey: "batches"
561
+ });
562
+ }
563
+ async listPage(params = {}, requestOptions) {
564
+ const raw = await this.transport.request("GET", "/testing/batches", { params, requestOptions });
565
+ return new Page(raw.batches ?? raw.items ?? [], raw.nextToken ?? null);
566
+ }
567
+ async get(batchId, requestOptions) {
568
+ return await this.transport.request("GET", `/testing/batches/${batchId}`, { requestOptions });
569
+ }
570
+ async update(batchId, body, requestOptions) {
571
+ return await this.transport.request("PUT", `/testing/batches/${batchId}`, {
572
+ body,
573
+ requestOptions
574
+ });
575
+ }
576
+ async delete(batchId, requestOptions) {
577
+ await this.transport.request("DELETE", `/testing/batches/${batchId}`, { requestOptions });
578
+ }
579
+ async run(batchId, requestOptions) {
580
+ return await this.transport.request("POST", `/testing/batches/${batchId}/run`, {
581
+ requestOptions
582
+ });
583
+ }
584
+ runs(batchId, params = {}, requestOptions) {
585
+ return new Paginator({
586
+ fetchPage: async (p) => await this.transport.request("GET", `/testing/batches/${batchId}/runs`, {
587
+ params: p,
588
+ requestOptions
589
+ }),
590
+ params: { ...params },
591
+ itemsKey: "runs"
592
+ });
593
+ }
594
+ listRuns(params = {}, requestOptions) {
595
+ return new Paginator({
596
+ fetchPage: async (p) => await this.transport.request("GET", "/testing/batch-runs", {
597
+ params: p,
598
+ requestOptions
599
+ }),
600
+ params: { ...params },
601
+ itemsKey: "runs"
602
+ });
603
+ }
604
+ async getRun(runId, requestOptions) {
605
+ return await this.transport.request("GET", `/testing/batch-runs/${runId}`, { requestOptions });
606
+ }
607
+ async waitForRun(runId, opts = {}) {
608
+ return await waitFor({
609
+ fetch: () => this.getRun(runId, opts.requestOptions),
610
+ isTerminal: (run) => RUN_TERMINAL_STATUSES.has(run.status),
611
+ timeout: opts.timeout,
612
+ initialInterval: opts.pollInterval,
613
+ intervalCap: opts.intervalCap,
614
+ onUpdate: opts.onUpdate
615
+ });
616
+ }
617
+ };
618
+
619
+ // src/resources/datasets.ts
620
+ var DatasetsResource = class extends Resource {
621
+ async create(body, requestOptions) {
622
+ return await this.transport.request("POST", "/datasets", { body, requestOptions });
623
+ }
624
+ list(params = {}, requestOptions) {
625
+ return new Paginator({
626
+ fetchPage: async (p) => await this.transport.request("GET", "/datasets", { params: p, requestOptions }),
627
+ params: { ...params },
628
+ itemsKey: "datasets"
629
+ });
630
+ }
631
+ async listPage(params = {}, requestOptions) {
632
+ const raw = await this.transport.request("GET", "/datasets", { params, requestOptions });
633
+ return new Page(raw.datasets ?? raw.items ?? [], raw.nextToken ?? null);
634
+ }
635
+ async get(datasetId, requestOptions) {
636
+ return await this.transport.request("GET", `/datasets/${datasetId}`, { requestOptions });
637
+ }
638
+ async update(datasetId, body, requestOptions) {
639
+ return await this.transport.request("PUT", `/datasets/${datasetId}`, { body, requestOptions });
640
+ }
641
+ async delete(datasetId, requestOptions) {
642
+ await this.transport.request("DELETE", `/datasets/${datasetId}`, { requestOptions });
643
+ }
644
+ async resolve(datasetId, requestOptions) {
645
+ return await this.transport.request("GET", `/datasets/${datasetId}/resolve`, {
646
+ requestOptions
647
+ });
648
+ }
649
+ };
650
+
651
+ // src/resources/enrichment.ts
652
+ var EnrichmentResource = class extends Resource {
653
+ async get(jobId, runId, type, requestOptions) {
654
+ return await this.transport.request(
655
+ "GET",
656
+ `/mapping/${jobId}/runs/${runId}/enrichments/${encodeURIComponent(type)}`,
657
+ { requestOptions }
658
+ );
659
+ }
660
+ async tokenUsage(jobId, runId, requestOptions) {
661
+ return await this.transport.request(
662
+ "GET",
663
+ `/mapping/${jobId}/runs/${runId}/token-usage`,
664
+ { requestOptions }
665
+ );
666
+ }
667
+ async enrich(jobId, runId, body, requestOptions) {
668
+ return await this.transport.request(
669
+ "POST",
670
+ `/mapping/${jobId}/runs/${runId}/enrich`,
671
+ { body, requestOptions }
672
+ );
673
+ }
674
+ };
675
+
676
+ // src/resources/loadTesting.ts
677
+ var TERMINAL_STATUSES = /* @__PURE__ */ new Set(["completed", "aborted", "failed"]);
678
+ var LoadTestingResource = class extends Resource {
679
+ async create(body, requestOptions) {
680
+ const raw = await this.transport.request(
681
+ "POST",
682
+ "/testing/load-tests",
683
+ { body, requestOptions }
684
+ );
685
+ return raw.config ?? raw;
686
+ }
687
+ list(params = {}, requestOptions) {
688
+ return new Paginator({
689
+ fetchPage: async (p) => await this.transport.request("GET", "/testing/load-tests", {
690
+ params: p,
691
+ requestOptions
692
+ }),
693
+ params: { ...params },
694
+ itemsKey: "configs"
695
+ });
696
+ }
697
+ async listPage(params = {}, requestOptions) {
698
+ const raw = await this.transport.request("GET", "/testing/load-tests", { params, requestOptions });
699
+ return new Page(raw.configs ?? raw.items ?? [], raw.nextToken ?? null);
700
+ }
701
+ async get(loadTestId, requestOptions) {
702
+ return await this.transport.request("GET", `/testing/load-tests/${loadTestId}`, {
703
+ requestOptions
704
+ });
705
+ }
706
+ async update(loadTestId, body, requestOptions) {
707
+ const raw = await this.transport.request(
708
+ "PUT",
709
+ `/testing/load-tests/${loadTestId}`,
710
+ { body, requestOptions }
711
+ );
712
+ return raw.config ?? raw;
713
+ }
714
+ async delete(loadTestId, requestOptions) {
715
+ await this.transport.request("DELETE", `/testing/load-tests/${loadTestId}`, { requestOptions });
716
+ }
717
+ async estimate(body, requestOptions) {
718
+ return await this.transport.request("POST", "/testing/load-tests/estimate", {
719
+ body,
720
+ requestOptions
721
+ });
722
+ }
723
+ async start(loadTestId, requestOptions) {
724
+ return await this.transport.request("POST", `/testing/load-tests/${loadTestId}/start`, {
725
+ requestOptions
726
+ });
727
+ }
728
+ async abort(loadTestId, requestOptions) {
729
+ return await this.transport.request("POST", `/testing/load-tests/${loadTestId}/abort`, {
730
+ requestOptions
731
+ });
732
+ }
733
+ async status(loadTestId, requestOptions) {
734
+ return await this.transport.request("GET", `/testing/load-tests/${loadTestId}/status`, {
735
+ requestOptions
736
+ });
737
+ }
738
+ listRuns(params = {}, requestOptions) {
739
+ return new Paginator({
740
+ fetchPage: async (p) => await this.transport.request("GET", "/testing/load-tests/runs", {
741
+ params: p,
742
+ requestOptions
743
+ }),
744
+ params: { ...params },
745
+ itemsKey: "runs"
746
+ });
747
+ }
748
+ async waitForComplete(loadTestId, opts = {}) {
749
+ return await waitFor({
750
+ fetch: () => this.status(loadTestId, opts.requestOptions),
751
+ isTerminal: (s) => TERMINAL_STATUSES.has(s.status),
752
+ timeout: opts.timeout,
753
+ initialInterval: opts.pollInterval,
754
+ intervalCap: opts.intervalCap,
755
+ onUpdate: opts.onUpdate
756
+ });
757
+ }
758
+ };
759
+
760
+ // src/resources/mapping.ts
761
+ var TERMINAL_STATUSES2 = /* @__PURE__ */ new Set(["completed", "failed", "limited", "cancelled"]);
762
+ var MappingResource = class extends Resource {
763
+ list(params = {}, requestOptions) {
764
+ return new Paginator({
765
+ fetchPage: async (p) => await this.transport.request("GET", "/mapping", { params: p, requestOptions }),
766
+ params: { ...params }
767
+ });
768
+ }
769
+ async listPage(params = {}, requestOptions) {
770
+ const raw = await this.transport.request(
771
+ "GET",
772
+ "/mapping",
773
+ { params, requestOptions }
774
+ );
775
+ return new Page(raw.items, raw.nextToken);
776
+ }
777
+ async get(jobId, requestOptions) {
778
+ return await this.transport.request("GET", `/mapping/${jobId}`, { requestOptions });
779
+ }
780
+ async create(body, requestOptions) {
781
+ return await this.transport.request("POST", "/mapping", { body, requestOptions });
782
+ }
783
+ async update(jobId, body, requestOptions) {
784
+ return await this.transport.request("PATCH", `/mapping/${jobId}`, { body, requestOptions });
785
+ }
786
+ async delete(jobId, requestOptions) {
787
+ await this.transport.request("DELETE", `/mapping/${jobId}`, { requestOptions });
788
+ }
789
+ async start(jobId, requestOptions) {
790
+ return await this.transport.request("POST", `/mapping/${jobId}/start`, { requestOptions });
791
+ }
792
+ async cancel(jobId, requestOptions) {
793
+ return await this.transport.request("POST", `/mapping/${jobId}/cancel`, { requestOptions });
794
+ }
795
+ async attest(jobId, requestOptions) {
796
+ return await this.transport.request("POST", "/mapping/attest", {
797
+ body: { jobId },
798
+ requestOptions
799
+ });
800
+ }
801
+ steps(jobId, params = {}, requestOptions) {
802
+ return new Paginator({
803
+ fetchPage: async (p) => await this.transport.request("GET", `/mapping/${jobId}/steps`, {
804
+ params: p,
805
+ requestOptions
806
+ }),
807
+ params: { ...params }
808
+ });
809
+ }
810
+ async tree(jobId, opts = {}, requestOptions) {
811
+ return await this.transport.request("GET", `/mapping/${jobId}/tree`, {
812
+ params: { format: opts.format ?? "tree" },
813
+ requestOptions
814
+ });
815
+ }
816
+ runs(jobId, params = {}, requestOptions) {
817
+ return new Paginator({
818
+ fetchPage: async (p) => await this.transport.request("GET", `/mapping/${jobId}/runs`, {
819
+ params: p,
820
+ requestOptions
821
+ }),
822
+ params: { ...params },
823
+ itemsKey: "runs"
824
+ });
825
+ }
826
+ paths(jobId, params = {}, requestOptions) {
827
+ return new Paginator({
828
+ fetchPage: async (p) => await this.transport.request("GET", `/mapping/${jobId}/paths`, {
829
+ params: p,
830
+ requestOptions
831
+ }),
832
+ params: { ...params },
833
+ itemsKey: "rules"
834
+ });
835
+ }
836
+ async updatePath(jobId, path, body, requestOptions) {
837
+ return await this.transport.request(
838
+ "PATCH",
839
+ `/mapping/${jobId}/paths/${encodeURIComponent(path)}`,
840
+ { body, requestOptions }
841
+ );
842
+ }
843
+ async deletePath(jobId, path, requestOptions) {
844
+ await this.transport.request(
845
+ "DELETE",
846
+ `/mapping/${jobId}/paths/${encodeURIComponent(path)}`,
847
+ { requestOptions }
848
+ );
849
+ }
850
+ async remap(jobId, path, requestOptions) {
851
+ return await this.transport.request(
852
+ "POST",
853
+ `/mapping/${jobId}/remap/${encodeURIComponent(path)}`,
854
+ { requestOptions }
855
+ );
856
+ }
857
+ async probe(jobId, runId, body = {}, requestOptions) {
858
+ return await this.transport.request(
859
+ "POST",
860
+ `/mapping/${jobId}/runs/${runId}/probe`,
861
+ { body, requestOptions }
862
+ );
863
+ }
864
+ async waitForComplete(jobId, opts = {}) {
865
+ return await waitFor({
866
+ fetch: () => this.get(jobId, opts.requestOptions),
867
+ isTerminal: (job) => TERMINAL_STATUSES2.has(job.status),
868
+ timeout: opts.timeout,
869
+ initialInterval: opts.pollInterval,
870
+ intervalCap: opts.intervalCap,
871
+ onUpdate: opts.onUpdate
872
+ });
873
+ }
874
+ };
875
+
876
+ // src/resources/profiles.ts
877
+ var ProfilesResource = class extends Resource {
878
+ async create(body, requestOptions) {
879
+ return await this.transport.request("POST", "/profiles", { body, requestOptions });
880
+ }
881
+ list(params = {}, requestOptions) {
882
+ return new Paginator({
883
+ fetchPage: async (p) => await this.transport.request("GET", "/profiles", { params: p, requestOptions }),
884
+ params: { ...params },
885
+ itemsKey: "profiles"
886
+ });
887
+ }
888
+ async listPage(params = {}, requestOptions) {
889
+ const raw = await this.transport.request("GET", "/profiles", { params, requestOptions });
890
+ return new Page(raw.profiles ?? raw.items ?? [], raw.nextToken ?? null);
891
+ }
892
+ async get(profileId, requestOptions) {
893
+ return await this.transport.request("GET", `/profiles/${profileId}`, { requestOptions });
894
+ }
895
+ async update(profileId, body, requestOptions) {
896
+ return await this.transport.request("PUT", `/profiles/${profileId}`, { body, requestOptions });
897
+ }
898
+ async delete(profileId, requestOptions) {
899
+ await this.transport.request("DELETE", `/profiles/${profileId}`, { requestOptions });
900
+ }
901
+ async addItem(profileId, body, requestOptions) {
902
+ return await this.transport.request("POST", `/profiles/${profileId}/items`, {
903
+ body,
904
+ requestOptions
905
+ });
906
+ }
907
+ async updateItem(profileId, itemId, body, requestOptions) {
908
+ return await this.transport.request("PUT", `/profiles/${profileId}/items/${itemId}`, {
909
+ body,
910
+ requestOptions
911
+ });
912
+ }
913
+ async deleteItem(profileId, itemId, requestOptions) {
914
+ await this.transport.request(
915
+ "DELETE",
916
+ `/profiles/${profileId}/items/${itemId}`,
917
+ { requestOptions }
918
+ );
919
+ }
920
+ async listParameters(requestOptions) {
921
+ return await this.transport.request("GET", "/profiles/parameters", { requestOptions });
922
+ }
923
+ async findByParameters(params, requestOptions) {
924
+ const labels = Array.isArray(params.labels) ? params.labels.join(",") : params.labels;
925
+ return await this.transport.request("GET", "/profiles/by-parameters", {
926
+ params: { labels },
927
+ requestOptions
928
+ });
929
+ }
930
+ };
931
+
932
+ // src/resources/scheduler.ts
933
+ var SchedulerResource = class extends Resource {
934
+ async create(body, requestOptions) {
935
+ return await this.transport.request("POST", "/schedules", { body, requestOptions });
936
+ }
937
+ list(params = {}, requestOptions) {
938
+ return new Paginator({
939
+ fetchPage: async (p) => await this.transport.request("GET", "/schedules", { params: p, requestOptions }),
940
+ params: { ...params },
941
+ itemsKey: "schedules"
942
+ });
943
+ }
944
+ async listPage(params = {}, requestOptions) {
945
+ const raw = await this.transport.request("GET", "/schedules", { params, requestOptions });
946
+ return new Page(raw.schedules ?? raw.items ?? [], raw.nextToken ?? null);
947
+ }
948
+ async get(scheduleId, requestOptions) {
949
+ return await this.transport.request("GET", `/schedules/${scheduleId}`, { requestOptions });
950
+ }
951
+ async update(scheduleId, body, requestOptions) {
952
+ return await this.transport.request("PUT", `/schedules/${scheduleId}`, { body, requestOptions });
953
+ }
954
+ async delete(scheduleId, requestOptions) {
955
+ await this.transport.request("DELETE", `/schedules/${scheduleId}`, { requestOptions });
956
+ }
957
+ async pause(scheduleId, requestOptions) {
958
+ return await this.transport.request("POST", `/schedules/${scheduleId}/pause`, {
959
+ requestOptions
960
+ });
961
+ }
962
+ async resume(scheduleId, requestOptions) {
963
+ return await this.transport.request("POST", `/schedules/${scheduleId}/resume`, {
964
+ requestOptions
965
+ });
966
+ }
967
+ };
968
+
969
+ // src/resources/sweeps.ts
970
+ var RUN_TERMINAL_STATUSES2 = /* @__PURE__ */ new Set(["completed", "failed", "cancelled"]);
971
+ var SweepsResource = class extends Resource {
972
+ async create(body, requestOptions) {
973
+ return await this.transport.request("POST", "/testing/sweeps", { body, requestOptions });
974
+ }
975
+ list(params = {}, requestOptions) {
976
+ return new Paginator({
977
+ fetchPage: async (p) => await this.transport.request("GET", "/testing/sweeps", { params: p, requestOptions }),
978
+ params: { ...params },
979
+ itemsKey: "sweeps"
980
+ });
981
+ }
982
+ async listPage(params = {}, requestOptions) {
983
+ const raw = await this.transport.request("GET", "/testing/sweeps", { params, requestOptions });
984
+ return new Page(raw.sweeps ?? raw.items ?? [], raw.nextToken ?? null);
985
+ }
986
+ async get(sweepId, requestOptions) {
987
+ return await this.transport.request("GET", `/testing/sweeps/${sweepId}`, { requestOptions });
988
+ }
989
+ async update(sweepId, body, requestOptions) {
990
+ return await this.transport.request("PUT", `/testing/sweeps/${sweepId}`, {
991
+ body,
992
+ requestOptions
993
+ });
994
+ }
995
+ async delete(sweepId, requestOptions) {
996
+ await this.transport.request("DELETE", `/testing/sweeps/${sweepId}`, { requestOptions });
997
+ }
998
+ async run(sweepId, requestOptions) {
999
+ return await this.transport.request("POST", `/testing/sweeps/${sweepId}/run`, {
1000
+ requestOptions
1001
+ });
1002
+ }
1003
+ runs(sweepId, params = {}, requestOptions) {
1004
+ return new Paginator({
1005
+ fetchPage: async (p) => await this.transport.request("GET", `/testing/sweeps/${sweepId}/runs`, {
1006
+ params: p,
1007
+ requestOptions
1008
+ }),
1009
+ params: { ...params },
1010
+ itemsKey: "runs"
1011
+ });
1012
+ }
1013
+ listRuns(params = {}, requestOptions) {
1014
+ return new Paginator({
1015
+ fetchPage: async (p) => await this.transport.request("GET", "/testing/sweep-runs", {
1016
+ params: p,
1017
+ requestOptions
1018
+ }),
1019
+ params: { ...params },
1020
+ itemsKey: "runs"
1021
+ });
1022
+ }
1023
+ async getRun(runId, requestOptions) {
1024
+ return await this.transport.request("GET", `/testing/sweep-runs/${runId}`, { requestOptions });
1025
+ }
1026
+ async waitForRun(runId, opts = {}) {
1027
+ return await waitFor({
1028
+ fetch: () => this.getRun(runId, opts.requestOptions),
1029
+ isTerminal: (run) => RUN_TERMINAL_STATUSES2.has(run.status),
1030
+ timeout: opts.timeout,
1031
+ initialInterval: opts.pollInterval,
1032
+ intervalCap: opts.intervalCap,
1033
+ onUpdate: opts.onUpdate
1034
+ });
1035
+ }
1036
+ };
1037
+
1038
+ // src/resources/testing.ts
1039
+ var RUN_TERMINAL_STATUSES3 = /* @__PURE__ */ new Set(["completed", "failed", "cancelled"]);
1040
+ var TestingConfigsResource = class extends Resource {
1041
+ async create(body, requestOptions) {
1042
+ return await this.transport.request("POST", "/testing/configs", { body, requestOptions });
1043
+ }
1044
+ list(params = {}, requestOptions) {
1045
+ return new Paginator({
1046
+ fetchPage: async (p) => {
1047
+ const raw = await this.transport.request("GET", "/testing/configs", { params: p, requestOptions });
1048
+ return { items: raw.configs ?? raw.items ?? [], nextToken: null };
1049
+ },
1050
+ params: { ...params }
1051
+ });
1052
+ }
1053
+ async listPage(params = {}, requestOptions) {
1054
+ const raw = await this.transport.request("GET", "/testing/configs", { params, requestOptions });
1055
+ return new Page(raw.configs ?? raw.items ?? [], raw.nextToken ?? null);
1056
+ }
1057
+ async get(configId, requestOptions) {
1058
+ return await this.transport.request("GET", `/testing/configs/${configId}`, { requestOptions });
1059
+ }
1060
+ async update(configId, body, requestOptions) {
1061
+ return await this.transport.request("PUT", `/testing/configs/${configId}`, {
1062
+ body,
1063
+ requestOptions
1064
+ });
1065
+ }
1066
+ async delete(configId, requestOptions) {
1067
+ await this.transport.request("DELETE", `/testing/configs/${configId}`, { requestOptions });
1068
+ }
1069
+ };
1070
+ var TestingJobsResource = class extends Resource {
1071
+ async create(body, requestOptions) {
1072
+ return await this.transport.request("POST", "/testing/jobs", { body, requestOptions });
1073
+ }
1074
+ list(params = {}, requestOptions) {
1075
+ return new Paginator({
1076
+ fetchPage: async (p) => {
1077
+ const raw = await this.transport.request("GET", "/testing/jobs", { params: p, requestOptions });
1078
+ return { items: raw.jobs ?? raw.items ?? [], nextToken: null };
1079
+ },
1080
+ params: { ...params }
1081
+ });
1082
+ }
1083
+ async listPage(params = {}, requestOptions) {
1084
+ const raw = await this.transport.request("GET", "/testing/jobs", { params, requestOptions });
1085
+ return new Page(raw.jobs ?? raw.items ?? [], raw.nextToken ?? null);
1086
+ }
1087
+ async get(jobId, requestOptions) {
1088
+ return await this.transport.request("GET", `/testing/jobs/${jobId}`, { requestOptions });
1089
+ }
1090
+ async delete(jobId, requestOptions) {
1091
+ await this.transport.request("DELETE", `/testing/jobs/${jobId}`, { requestOptions });
1092
+ }
1093
+ };
1094
+ var TestingRunsResource = class extends Resource {
1095
+ async create(body, requestOptions) {
1096
+ const raw = await this.transport.request(
1097
+ "POST",
1098
+ "/testing/runs",
1099
+ { body, requestOptions }
1100
+ );
1101
+ return raw.run ?? raw;
1102
+ }
1103
+ list(params = {}, requestOptions) {
1104
+ return new Paginator({
1105
+ fetchPage: async (p) => {
1106
+ const raw = await this.transport.request("GET", "/testing/runs", { params: p, requestOptions });
1107
+ return { items: raw.runs ?? raw.items ?? [], nextToken: null };
1108
+ },
1109
+ params: { ...params }
1110
+ });
1111
+ }
1112
+ async listPage(params = {}, requestOptions) {
1113
+ const raw = await this.transport.request("GET", "/testing/runs", { params, requestOptions });
1114
+ return new Page(raw.runs ?? raw.items ?? [], raw.nextToken ?? null);
1115
+ }
1116
+ async get(runId, requestOptions) {
1117
+ return await this.transport.request("GET", `/testing/runs/${runId}`, { requestOptions });
1118
+ }
1119
+ async waitForRun(runId, opts = {}) {
1120
+ return await waitFor({
1121
+ fetch: () => this.get(runId, opts.requestOptions),
1122
+ isTerminal: (run) => run.status !== void 0 && RUN_TERMINAL_STATUSES3.has(run.status),
1123
+ timeout: opts.timeout,
1124
+ initialInterval: opts.pollInterval,
1125
+ intervalCap: opts.intervalCap,
1126
+ onUpdate: opts.onUpdate
1127
+ });
1128
+ }
1129
+ };
1130
+ var TestingResource = class extends Resource {
1131
+ configs;
1132
+ jobs;
1133
+ runs;
1134
+ constructor(transport) {
1135
+ super(transport);
1136
+ this.configs = new TestingConfigsResource(transport);
1137
+ this.jobs = new TestingJobsResource(transport);
1138
+ this.runs = new TestingRunsResource(transport);
1139
+ }
1140
+ };
1141
+
1142
+ // src/client.ts
1143
+ var Nopaque = class {
1144
+ mapping;
1145
+ audio;
1146
+ profiles;
1147
+ testing;
1148
+ batches;
1149
+ sweeps;
1150
+ datasets;
1151
+ loadTesting;
1152
+ scheduler;
1153
+ enrichment;
1154
+ transport;
1155
+ constructor(options = {}) {
1156
+ const config = resolveConfig(options);
1157
+ this.transport = new Transport(config);
1158
+ this.mapping = new MappingResource(this.transport);
1159
+ this.audio = new AudioResource(this.transport);
1160
+ this.profiles = new ProfilesResource(this.transport);
1161
+ this.testing = new TestingResource(this.transport);
1162
+ this.batches = new BatchesResource(this.transport);
1163
+ this.sweeps = new SweepsResource(this.transport);
1164
+ this.datasets = new DatasetsResource(this.transport);
1165
+ this.loadTesting = new LoadTestingResource(this.transport);
1166
+ this.scheduler = new SchedulerResource(this.transport);
1167
+ this.enrichment = new EnrichmentResource(this.transport);
1168
+ }
1169
+ close() {
1170
+ }
1171
+ };
1172
+ // Annotate the CommonJS export names for ESM import in node:
1173
+ 0 && (module.exports = {
1174
+ APIConnectionError,
1175
+ APITimeoutError,
1176
+ AuthenticationError,
1177
+ ConflictError,
1178
+ Nopaque,
1179
+ NopaqueAPIError,
1180
+ NopaqueConfigError,
1181
+ NopaqueError,
1182
+ NopaqueTimeoutError,
1183
+ NotFoundError,
1184
+ Page,
1185
+ Paginator,
1186
+ PermissionError,
1187
+ RateLimitError,
1188
+ ServerError,
1189
+ VERSION,
1190
+ ValidationError
1191
+ });
1192
+ //# sourceMappingURL=index.cjs.map