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