nixflex 0.8.0 → 0.11.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/B57-DELETES.md +52 -0
- package/CALL-REQUESTS.md +73 -0
- package/CHANGELOG.md +204 -84
- package/KIT-EXAMPLES-K6.md +118 -0
- package/KIT-EXAMPLES-K7.md +104 -0
- package/KNOWLEDGE.md +61 -0
- package/LICENSE +21 -21
- package/METHODS.md +176 -0
- package/NUMBER-FEATURES.md +51 -0
- package/ORGANISATIONS.md +9 -0
- package/README.md +56 -117
- package/TEAM-INTEGRATIONS.md +69 -0
- package/THIRD-PARTY-NOTICES.md +26 -0
- package/dist/cli/index.js +3901 -371
- package/dist/index.cjs +1255 -174
- package/dist/index.d.cts +2031 -322
- package/dist/index.d.ts +2031 -322
- package/dist/index.js +1233 -171
- package/package.json +72 -60
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@ var NixflexError = class extends Error {
|
|
|
12
12
|
details;
|
|
13
13
|
/** The x-railway-request-id (or similar) header when present - quote it to support. */
|
|
14
14
|
requestId;
|
|
15
|
-
constructor(status, body,
|
|
15
|
+
constructor(status, body, requestId2, fallbackMessage) {
|
|
16
16
|
const e = body == null ? void 0 : body.error;
|
|
17
17
|
super((e == null ? void 0 : e.message) || fallbackMessage || `Nixflex API error (HTTP ${status})`);
|
|
18
18
|
this.name = "NixflexError";
|
|
@@ -21,7 +21,24 @@ var NixflexError = class extends Error {
|
|
|
21
21
|
this.type = (e == null ? void 0 : e.type) || "error";
|
|
22
22
|
this.docUrl = e == null ? void 0 : e.doc_url;
|
|
23
23
|
this.details = (e == null ? void 0 : e.details) || {};
|
|
24
|
-
this.requestId =
|
|
24
|
+
this.requestId = requestId2 || (e == null ? void 0 : e.request_id) || (typeof this.details.request_id === "string" ? this.details.request_id : void 0);
|
|
25
|
+
}
|
|
26
|
+
get doc_url() {
|
|
27
|
+
return this.docUrl ?? null;
|
|
28
|
+
}
|
|
29
|
+
get request_id() {
|
|
30
|
+
return this.requestId ?? null;
|
|
31
|
+
}
|
|
32
|
+
toJSON() {
|
|
33
|
+
return { error: {
|
|
34
|
+
type: this.type,
|
|
35
|
+
code: this.code,
|
|
36
|
+
message: this.message,
|
|
37
|
+
details: this.details,
|
|
38
|
+
doc_url: this.doc_url,
|
|
39
|
+
status: this.status,
|
|
40
|
+
request_id: this.request_id
|
|
41
|
+
} };
|
|
25
42
|
}
|
|
26
43
|
};
|
|
27
44
|
var NixflexAuthenticationError = class extends NixflexError {
|
|
@@ -44,8 +61,8 @@ var NixflexNotFoundError = class extends NixflexError {
|
|
|
44
61
|
};
|
|
45
62
|
var NixflexRateLimitError = class extends NixflexError {
|
|
46
63
|
retryAfterSeconds;
|
|
47
|
-
constructor(status, body,
|
|
48
|
-
super(status, body,
|
|
64
|
+
constructor(status, body, requestId2, retryAfterSeconds) {
|
|
65
|
+
super(status, body, requestId2);
|
|
49
66
|
this.name = "NixflexRateLimitError";
|
|
50
67
|
this.retryAfterSeconds = retryAfterSeconds;
|
|
51
68
|
}
|
|
@@ -68,25 +85,337 @@ var NixflexConnectionError = class extends NixflexError {
|
|
|
68
85
|
this.name = "NixflexConnectionError";
|
|
69
86
|
}
|
|
70
87
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
88
|
+
var NixflexOutcomeUnknownError = class extends NixflexServerError {
|
|
89
|
+
outcome = "unknown";
|
|
90
|
+
safe_to_retry = false;
|
|
91
|
+
constructor(status = 0, body = null, requestId2) {
|
|
92
|
+
var _a, _b, _c;
|
|
93
|
+
super(status, { error: {
|
|
94
|
+
type: "outcome_unknown",
|
|
95
|
+
code: "outcome_unknown",
|
|
96
|
+
message: "Outcome unknown - check before retrying. The change may already have happened; it was not automatically repeated.",
|
|
97
|
+
doc_url: (_a = body == null ? void 0 : body.error) == null ? void 0 : _a.doc_url,
|
|
98
|
+
details: {
|
|
99
|
+
...(_b = body == null ? void 0 : body.error) == null ? void 0 : _b.details,
|
|
100
|
+
original_code: (_c = body == null ? void 0 : body.error) == null ? void 0 : _c.code,
|
|
101
|
+
outcome: "unknown",
|
|
102
|
+
safe_to_retry: false
|
|
103
|
+
}
|
|
104
|
+
} }, requestId2);
|
|
105
|
+
this.name = "NixflexOutcomeUnknownError";
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
var NixflexConflictError = class extends NixflexError {
|
|
109
|
+
constructor(...args) {
|
|
110
|
+
super(...args);
|
|
111
|
+
this.name = "NixflexConflictError";
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
var NixflexDoNotContactError = class extends NixflexConflictError {
|
|
115
|
+
constructor(...args) {
|
|
116
|
+
super(...args);
|
|
117
|
+
this.name = "NixflexDoNotContactError";
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
function errorFromResponse(status, body, requestId2, retryAfterSeconds, mutation = false) {
|
|
121
|
+
var _a, _b;
|
|
122
|
+
const proof = (_a = body == null ? void 0 : body.error) == null ? void 0 : _a.details;
|
|
123
|
+
const notSent = (proof == null ? void 0 : proof.outcome) === "not_sent" && proof.sent === false && proof.charged === false && proof.safe_to_retry === true;
|
|
124
|
+
if (mutation && (status >= 500 || status >= 300 && status < 400) && !notSent) {
|
|
125
|
+
return new NixflexOutcomeUnknownError(status, body, requestId2);
|
|
126
|
+
}
|
|
127
|
+
if (status === 401) return new NixflexAuthenticationError(status, body, requestId2);
|
|
128
|
+
if (status === 402) return new NixflexPaymentRequiredError(status, body, requestId2);
|
|
129
|
+
if (status === 404) return new NixflexNotFoundError(status, body, requestId2);
|
|
130
|
+
if (status === 409 && ((_b = body == null ? void 0 : body.error) == null ? void 0 : _b.code) === "do_not_contact") return new NixflexDoNotContactError(status, body, requestId2);
|
|
131
|
+
if (status === 409) return new NixflexConflictError(status, body, requestId2);
|
|
132
|
+
if (status === 429) return new NixflexRateLimitError(status, body, requestId2, retryAfterSeconds);
|
|
133
|
+
if (status === 400 || status === 422) return new NixflexInvalidRequestError(status, body, requestId2);
|
|
134
|
+
if (status >= 500) return new NixflexServerError(status, body, requestId2);
|
|
135
|
+
return new NixflexError(status, body, requestId2);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/request-body.ts
|
|
139
|
+
function encodeRequest(body, options = {}) {
|
|
140
|
+
const headers = { "Content-Type": "application/json" };
|
|
141
|
+
if (options.rawBody !== void 0 && body !== void 0) throw new TypeError("Use JSON body or rawBody, not both.");
|
|
142
|
+
if (options.contentType && options.contentType !== "application/octet-stream") throw new TypeError("Unsupported content type.");
|
|
143
|
+
for (const [key, value] of Object.entries({
|
|
144
|
+
"Idempotency-Key": options.idempotencyKey,
|
|
145
|
+
"X-Filename": options.filename,
|
|
146
|
+
"X-Source-Title": options.sourceTitle
|
|
147
|
+
})) {
|
|
148
|
+
if (value === void 0) continue;
|
|
149
|
+
if (typeof value !== "string" || !value || value.length > 1024 || /[^\x20-\x7e]/.test(value))
|
|
150
|
+
throw new TypeError(`Invalid ${key}; use printable ASCII metadata.`);
|
|
151
|
+
headers[key] = value;
|
|
152
|
+
}
|
|
153
|
+
if (options.review !== void 0) {
|
|
154
|
+
if (typeof options.review !== "boolean") throw new TypeError("review must be boolean.");
|
|
155
|
+
headers["X-Review"] = String(options.review);
|
|
156
|
+
}
|
|
157
|
+
if (options.expectedRevision !== void 0) {
|
|
158
|
+
if (!Number.isSafeInteger(options.expectedRevision) || options.expectedRevision < 0) throw new TypeError("Invalid expectedRevision.");
|
|
159
|
+
headers["X-Expected-Revision"] = String(options.expectedRevision);
|
|
160
|
+
}
|
|
161
|
+
if (options.rawBody !== void 0) {
|
|
162
|
+
if (!(options.rawBody instanceof Uint8Array)) throw new TypeError("rawBody must be bytes.");
|
|
163
|
+
headers["Content-Type"] = "application/octet-stream";
|
|
164
|
+
return { headers, body: options.rawBody };
|
|
165
|
+
}
|
|
166
|
+
return { headers, body: body === void 0 ? void 0 : JSON.stringify(body) };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// src/response-stream.ts
|
|
170
|
+
async function* readStream(url, headers, timeout, retries, opts) {
|
|
171
|
+
var _a, _b, _c, _d, _e, _f;
|
|
172
|
+
if (!Number.isFinite(timeout) || timeout <= 0) throw new RangeError("timeoutMs must be positive.");
|
|
173
|
+
let emitted = false;
|
|
174
|
+
for (let attempt = 0; ; attempt++) {
|
|
175
|
+
const controller = new AbortController();
|
|
176
|
+
const abort = () => controller.abort();
|
|
177
|
+
if ((_a = opts == null ? void 0 : opts.signal) == null ? void 0 : _a.aborted) abort();
|
|
178
|
+
(_b = opts == null ? void 0 : opts.signal) == null ? void 0 : _b.addEventListener("abort", abort, { once: true });
|
|
179
|
+
const timer = setTimeout(abort, timeout);
|
|
180
|
+
let reader;
|
|
181
|
+
let response;
|
|
182
|
+
let delay;
|
|
183
|
+
try {
|
|
184
|
+
response = await fetch(url, { method: "GET", redirect: "error", headers, signal: controller.signal });
|
|
185
|
+
if (!response.ok) {
|
|
186
|
+
let body = null;
|
|
187
|
+
try {
|
|
188
|
+
body = await response.json();
|
|
189
|
+
} catch {
|
|
190
|
+
}
|
|
191
|
+
const retryAfter = Math.max(0, parseInt(response.headers.get("retry-after") || "0", 10) || 0);
|
|
192
|
+
if ((response.status === 429 || response.status >= 500) && attempt < retries) {
|
|
193
|
+
delay = response.status === 429 ? Math.min(retryAfter, 30) * 1e3 || 1e3 : 500 * (attempt + 1);
|
|
194
|
+
} else {
|
|
195
|
+
throw errorFromResponse(response.status, body, response.headers.get("x-request-id") || void 0, retryAfter);
|
|
196
|
+
}
|
|
197
|
+
} else {
|
|
198
|
+
if (!/^text\/csv(?:;|$)/i.test(response.headers.get("content-type") || "") || !response.body) {
|
|
199
|
+
throw new NixflexConnectionError("The activity export did not return CSV.");
|
|
200
|
+
}
|
|
201
|
+
reader = response.body.getReader();
|
|
202
|
+
while (true) {
|
|
203
|
+
const chunk = await reader.read();
|
|
204
|
+
if (chunk.done) return;
|
|
205
|
+
if (chunk.value.byteLength) {
|
|
206
|
+
emitted = true;
|
|
207
|
+
yield chunk.value;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
} catch (error) {
|
|
212
|
+
if (error instanceof Error && error.name.startsWith("Nixflex")) throw error;
|
|
213
|
+
if (emitted || ((_c = opts == null ? void 0 : opts.signal) == null ? void 0 : _c.aborted) || attempt >= retries) {
|
|
214
|
+
throw new NixflexConnectionError(emitted ? "Activity export interrupted; discard the incomplete file. It was not restarted." : "Could not read the activity export.");
|
|
215
|
+
}
|
|
216
|
+
delay = 300 * (attempt + 1);
|
|
217
|
+
} finally {
|
|
218
|
+
try {
|
|
219
|
+
if (reader) await reader.cancel();
|
|
220
|
+
else await ((_d = response == null ? void 0 : response.body) == null ? void 0 : _d.cancel());
|
|
221
|
+
} catch {
|
|
222
|
+
}
|
|
223
|
+
controller.abort();
|
|
224
|
+
clearTimeout(timer);
|
|
225
|
+
(_e = opts == null ? void 0 : opts.signal) == null ? void 0 : _e.removeEventListener("abort", abort);
|
|
226
|
+
}
|
|
227
|
+
if ((_f = opts == null ? void 0 : opts.signal) == null ? void 0 : _f.aborted) throw new NixflexConnectionError("Activity export cancelled.");
|
|
228
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// src/knowledge/transfer-context.ts
|
|
233
|
+
function transferContext(base, key, version, path2, timeout, retries, options, query) {
|
|
234
|
+
if (!path2.startsWith("/") || path2.startsWith("//") || /[?#\\]/.test(path2)) throw new TypeError("Use a relative API path.");
|
|
235
|
+
const url = new URL(base + "/v1" + path2);
|
|
236
|
+
for (const [name, value] of Object.entries(query || {})) if (value !== void 0) url.searchParams.set(name, value);
|
|
237
|
+
const deadline = (options == null ? void 0 : options.timeoutMs) ?? timeout;
|
|
238
|
+
if (!Number.isFinite(deadline) || deadline <= 0) throw new RangeError("timeoutMs must be positive.");
|
|
239
|
+
return {
|
|
240
|
+
url,
|
|
241
|
+
headers: { Authorization: "Bearer " + key, "User-Agent": "nixflex-node/" + version },
|
|
242
|
+
timeout: deadline,
|
|
243
|
+
retries
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
function transferAbort(timeout, signal) {
|
|
247
|
+
const controller = new AbortController();
|
|
248
|
+
const abort = () => controller.abort();
|
|
249
|
+
if (signal == null ? void 0 : signal.aborted) abort();
|
|
250
|
+
signal == null ? void 0 : signal.addEventListener("abort", abort, { once: true });
|
|
251
|
+
const timer = setTimeout(abort, timeout);
|
|
252
|
+
return { signal: controller.signal, close: () => {
|
|
253
|
+
clearTimeout(timer);
|
|
254
|
+
signal == null ? void 0 : signal.removeEventListener("abort", abort);
|
|
255
|
+
controller.abort();
|
|
256
|
+
} };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// src/knowledge/upload.ts
|
|
260
|
+
import { open } from "fs/promises";
|
|
261
|
+
import { basename } from "path";
|
|
262
|
+
import { Transform } from "stream";
|
|
263
|
+
async function uploadFile(ctx, path2, opts = {}) {
|
|
264
|
+
const metadata = encodeRequest(void 0, { ...opts, filename: opts.filename || basename(path2) }).headers;
|
|
265
|
+
const file = await open(path2, "r");
|
|
266
|
+
let source;
|
|
267
|
+
let bounded;
|
|
268
|
+
let deadline;
|
|
269
|
+
try {
|
|
270
|
+
const info = await file.stat();
|
|
271
|
+
if (!info.isFile() || info.size <= 0 || info.size > 10 * 1024 * 1024)
|
|
272
|
+
throw new RangeError("Choose a non-empty regular file up to 10 MiB.");
|
|
273
|
+
if (ctx.url.pathname.endsWith("/replacements") && opts.expectedRevision === void 0)
|
|
274
|
+
throw new TypeError("File replacement requires the source expectedRevision.");
|
|
275
|
+
source = file.createReadStream({ highWaterMark: 64 * 1024, autoClose: false });
|
|
276
|
+
let bytes = 0;
|
|
277
|
+
bounded = new Transform({ transform(chunk, _encoding, done) {
|
|
278
|
+
bytes += chunk.length;
|
|
279
|
+
done(bytes > info.size ? new Error("The upload file changed.") : null, chunk);
|
|
280
|
+
}, flush(done) {
|
|
281
|
+
done(bytes !== info.size ? new Error("The upload file changed.") : null);
|
|
282
|
+
} });
|
|
283
|
+
source.on("error", (error) => bounded == null ? void 0 : bounded.destroy(error));
|
|
284
|
+
source.pipe(bounded);
|
|
285
|
+
deadline = transferAbort(ctx.timeout, opts.signal);
|
|
286
|
+
try {
|
|
287
|
+
const res = await fetch(ctx.url, {
|
|
288
|
+
method: "POST",
|
|
289
|
+
redirect: "error",
|
|
290
|
+
headers: { ...ctx.headers, ...metadata, "Content-Type": "application/octet-stream", "Content-Length": String(info.size) },
|
|
291
|
+
body: bounded,
|
|
292
|
+
signal: deadline.signal,
|
|
293
|
+
duplex: "half"
|
|
294
|
+
});
|
|
295
|
+
let data = null;
|
|
296
|
+
try {
|
|
297
|
+
data = await res.json();
|
|
298
|
+
} catch {
|
|
299
|
+
if (res.ok) throw new NixflexOutcomeUnknownError(res.status);
|
|
300
|
+
}
|
|
301
|
+
if (!res.ok) throw errorFromResponse(
|
|
302
|
+
res.status,
|
|
303
|
+
data,
|
|
304
|
+
res.headers.get("x-request-id") || void 0,
|
|
305
|
+
Number(res.headers.get("retry-after")) || 0,
|
|
306
|
+
true
|
|
307
|
+
);
|
|
308
|
+
return data;
|
|
309
|
+
} catch (error) {
|
|
310
|
+
if (error instanceof NixflexError) throw error;
|
|
311
|
+
throw new NixflexOutcomeUnknownError();
|
|
312
|
+
}
|
|
313
|
+
} finally {
|
|
314
|
+
deadline == null ? void 0 : deadline.close();
|
|
315
|
+
source == null ? void 0 : source.destroy();
|
|
316
|
+
bounded == null ? void 0 : bounded.destroy();
|
|
317
|
+
await file.close();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// src/knowledge/download.ts
|
|
322
|
+
async function* download(ctx, opts) {
|
|
323
|
+
var _a, _b, _c;
|
|
324
|
+
let emitted = false;
|
|
325
|
+
for (let attempt = 0; ; attempt++) {
|
|
326
|
+
const deadline = transferAbort(ctx.timeout, opts == null ? void 0 : opts.signal);
|
|
327
|
+
let response, reader;
|
|
328
|
+
let delay = 300 * (attempt + 1);
|
|
329
|
+
try {
|
|
330
|
+
response = await fetch(ctx.url, {
|
|
331
|
+
method: "GET",
|
|
332
|
+
redirect: "error",
|
|
333
|
+
signal: deadline.signal,
|
|
334
|
+
headers: { ...ctx.headers, Accept: "application/json" }
|
|
335
|
+
});
|
|
336
|
+
if (!response.ok) {
|
|
337
|
+
let data = null;
|
|
338
|
+
try {
|
|
339
|
+
data = await response.json();
|
|
340
|
+
} catch {
|
|
341
|
+
}
|
|
342
|
+
if ((response.status === 429 || response.status >= 500) && attempt < ctx.retries) {
|
|
343
|
+
delay = response.status === 429 ? Math.min(30, Math.max(0, Number(response.headers.get("retry-after")) || 1)) * 1e3 : 500 * (attempt + 1);
|
|
344
|
+
} else throw errorFromResponse(response.status, data, response.headers.get("x-request-id") || void 0, 0);
|
|
345
|
+
} else {
|
|
346
|
+
if (!/^application\/json(?:;|$)/i.test(response.headers.get("content-type") || "") || !response.body)
|
|
347
|
+
throw new NixflexConnectionError("The knowledge export did not return JSON.");
|
|
348
|
+
reader = response.body.getReader();
|
|
349
|
+
while (true) {
|
|
350
|
+
const item = await reader.read();
|
|
351
|
+
if (item.done) return;
|
|
352
|
+
if (item.value.byteLength) {
|
|
353
|
+
emitted = true;
|
|
354
|
+
yield item.value;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
} catch (error) {
|
|
359
|
+
if (error instanceof NixflexError) throw error;
|
|
360
|
+
if (emitted || ((_a = opts == null ? void 0 : opts.signal) == null ? void 0 : _a.aborted) || attempt >= ctx.retries)
|
|
361
|
+
throw new NixflexConnectionError("Knowledge download interrupted. Discard any partial file; it was not restarted.");
|
|
362
|
+
} finally {
|
|
363
|
+
try {
|
|
364
|
+
if (reader) await reader.cancel();
|
|
365
|
+
else await ((_b = response == null ? void 0 : response.body) == null ? void 0 : _b.cancel());
|
|
366
|
+
} catch {
|
|
367
|
+
}
|
|
368
|
+
deadline.close();
|
|
369
|
+
}
|
|
370
|
+
if ((_c = opts == null ? void 0 : opts.signal) == null ? void 0 : _c.aborted) throw new NixflexConnectionError("Knowledge download cancelled.");
|
|
371
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// src/content-delete.ts
|
|
376
|
+
function contentDeleteId(id) {
|
|
377
|
+
if (typeof id !== "string" || !id.length || id.length > 200 || id === "." || id === ".." || /[\x00-\x1f\x7f]/.test(id)) {
|
|
378
|
+
throw new TypeError("Choose a valid call or campaign identifier. Nothing was sent.");
|
|
379
|
+
}
|
|
380
|
+
return encodeURIComponent(id);
|
|
381
|
+
}
|
|
382
|
+
function queuedContentDelete(method, path2, status, body, requestId2) {
|
|
383
|
+
const route = /^\/(?:calls\/batch|sms\/campaigns|calls)\/[^/]+$/.test(path2);
|
|
384
|
+
const error = body == null ? void 0 : body.error, proof = error == null ? void 0 : error.details;
|
|
385
|
+
if (method === "DELETE" && route && status === 503 && (error == null ? void 0 : error.code) === "hangup_pending" && error.type === "server_error" && typeof error.message === "string" && (proof == null ? void 0 : proof.deleted) === false && proof.retry_pending === true) {
|
|
386
|
+
return new NixflexServerError(status, body, requestId2);
|
|
387
|
+
}
|
|
388
|
+
return void 0;
|
|
79
389
|
}
|
|
80
390
|
|
|
81
391
|
// src/client.ts
|
|
392
|
+
var SDK_VERSION = "0.11.0";
|
|
82
393
|
var DEFAULT_BASE_URL = "https://api.nixflex.com";
|
|
83
394
|
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
84
|
-
var SDK_VERSION = "0.8.0";
|
|
85
395
|
var HttpClient = class {
|
|
396
|
+
knowledgeUpload(path2, file, opts) {
|
|
397
|
+
return uploadFile(transferContext(this.baseUrl, this.apiKey, SDK_VERSION, path2, this.timeoutMs, this.maxRetries, opts), file, opts);
|
|
398
|
+
}
|
|
399
|
+
knowledgeDownload(path2, query = {}, opts) {
|
|
400
|
+
return download(transferContext(this.baseUrl, this.apiKey, SDK_VERSION, path2, this.timeoutMs, this.maxRetries, opts, query), opts);
|
|
401
|
+
}
|
|
86
402
|
apiKey;
|
|
87
403
|
baseUrl;
|
|
88
404
|
timeoutMs;
|
|
89
405
|
maxRetries;
|
|
406
|
+
/** Streaming GET for activity CSV. No retry after the first returned byte. */
|
|
407
|
+
stream(path2, query, opts) {
|
|
408
|
+
if (!path2.startsWith("/") || path2.startsWith("//") || /[?#\\]/.test(path2)) throw new TypeError("Use a relative API path.");
|
|
409
|
+
const url = new URL(this.baseUrl + "/v1" + path2);
|
|
410
|
+
for (const [key, value] of Object.entries(query)) if (value !== void 0) url.searchParams.set(key, value);
|
|
411
|
+
return readStream(
|
|
412
|
+
url,
|
|
413
|
+
{ Authorization: `Bearer ${this.apiKey}`, Accept: "text/csv", "User-Agent": `nixflex-node/${SDK_VERSION}` },
|
|
414
|
+
(opts == null ? void 0 : opts.timeoutMs) ?? this.timeoutMs,
|
|
415
|
+
this.maxRetries,
|
|
416
|
+
opts
|
|
417
|
+
);
|
|
418
|
+
}
|
|
90
419
|
constructor(opts) {
|
|
91
420
|
if (!opts || typeof opts.apiKey !== "string" || !opts.apiKey.includes(":")) {
|
|
92
421
|
throw new Error(
|
|
@@ -96,16 +425,21 @@ var HttpClient = class {
|
|
|
96
425
|
this.apiKey = opts.apiKey;
|
|
97
426
|
this.baseUrl = (opts.baseUrl || DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
98
427
|
this.timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
99
|
-
this.maxRetries = opts.maxRetries ?? 1;
|
|
428
|
+
this.maxRetries = Math.min(opts.maxRetries ?? 1, 3);
|
|
429
|
+
if (!Number.isInteger(this.maxRetries) || this.maxRetries < 0 || this.maxRetries > 3) throw new RangeError("maxRetries must be 0..3.");
|
|
430
|
+
if (!Number.isFinite(this.timeoutMs) || this.timeoutMs <= 0) throw new RangeError("timeoutMs must be positive.");
|
|
100
431
|
}
|
|
101
|
-
async request(method,
|
|
102
|
-
const url = new URL(this.baseUrl + "/v1" +
|
|
432
|
+
async request(method, path2, body, query, reqOpts) {
|
|
433
|
+
const url = new URL(this.baseUrl + "/v1" + path2);
|
|
103
434
|
if (query) {
|
|
104
435
|
for (const [k, v] of Object.entries(query)) {
|
|
105
436
|
if (v !== void 0 && v !== null) url.searchParams.set(k, String(v));
|
|
106
437
|
}
|
|
107
438
|
}
|
|
108
|
-
|
|
439
|
+
if (!path2.startsWith("/") || path2.startsWith("//") || /[?#\\]/.test(path2)) throw new TypeError("Use a relative API path and the query argument.");
|
|
440
|
+
encodeRequest(body, reqOpts);
|
|
441
|
+
if ((reqOpts == null ? void 0 : reqOpts.timeoutMs) !== void 0 && (!Number.isFinite(reqOpts.timeoutMs) || reqOpts.timeoutMs <= 0)) throw new RangeError("timeoutMs must be positive.");
|
|
442
|
+
const isRead = method === "GET";
|
|
109
443
|
let attempt = 0;
|
|
110
444
|
while (true) {
|
|
111
445
|
attempt++;
|
|
@@ -113,19 +447,29 @@ var HttpClient = class {
|
|
|
113
447
|
try {
|
|
114
448
|
res = await this.fetchWithTimeout(url.toString(), method, body, reqOpts);
|
|
115
449
|
} catch (err) {
|
|
450
|
+
if (!isRead) throw new NixflexOutcomeUnknownError();
|
|
116
451
|
if (attempt <= this.maxRetries) {
|
|
117
452
|
await sleep(300 * attempt);
|
|
118
453
|
continue;
|
|
119
454
|
}
|
|
120
455
|
throw new NixflexConnectionError(
|
|
121
|
-
|
|
456
|
+
"Could not reach the Nixflex API. Check connectivity and https://nixflex.com/status"
|
|
122
457
|
);
|
|
123
458
|
}
|
|
124
459
|
if (res.ok) {
|
|
125
460
|
if (res.status === 204) return void 0;
|
|
126
|
-
|
|
461
|
+
try {
|
|
462
|
+
return await res.json();
|
|
463
|
+
} catch {
|
|
464
|
+
if (!isRead) throw new NixflexOutcomeUnknownError(
|
|
465
|
+
res.status,
|
|
466
|
+
null,
|
|
467
|
+
res.headers.get("x-request-id") || res.headers.get("x-railway-request-id") || void 0
|
|
468
|
+
);
|
|
469
|
+
throw new NixflexConnectionError("The API read returned an incomplete or invalid JSON reply.");
|
|
470
|
+
}
|
|
127
471
|
}
|
|
128
|
-
const
|
|
472
|
+
const requestId2 = res.headers.get("x-request-id") || res.headers.get("x-railway-request-id") || void 0;
|
|
129
473
|
const retryAfter = parseInt(res.headers.get("retry-after") || "0", 10) || 0;
|
|
130
474
|
let errBody = null;
|
|
131
475
|
try {
|
|
@@ -133,13 +477,13 @@ var HttpClient = class {
|
|
|
133
477
|
} catch {
|
|
134
478
|
}
|
|
135
479
|
const retryable429 = res.status === 429;
|
|
136
|
-
const retryable5xx = res.status >= 500
|
|
137
|
-
if ((retryable429 || retryable5xx) && attempt <= this.maxRetries) {
|
|
480
|
+
const retryable5xx = res.status >= 500;
|
|
481
|
+
if (isRead && (retryable429 || retryable5xx) && attempt <= this.maxRetries) {
|
|
138
482
|
const waitMs = retryable429 ? Math.min(retryAfter, 30) * 1e3 || 1e3 : 500 * attempt;
|
|
139
483
|
await sleep(waitMs);
|
|
140
484
|
continue;
|
|
141
485
|
}
|
|
142
|
-
throw errorFromResponse(res.status, errBody,
|
|
486
|
+
throw queuedContentDelete(method, path2, res.status, errBody, requestId2) ?? errorFromResponse(res.status, errBody, requestId2, retryAfter, !isRead);
|
|
143
487
|
}
|
|
144
488
|
}
|
|
145
489
|
async fetchWithTimeout(url, method, body, reqOpts) {
|
|
@@ -151,16 +495,19 @@ var HttpClient = class {
|
|
|
151
495
|
else reqOpts.signal.addEventListener("abort", () => controller.abort(reqOpts.signal.reason), { once: true });
|
|
152
496
|
}
|
|
153
497
|
try {
|
|
154
|
-
|
|
498
|
+
const res = await fetch(url, {
|
|
155
499
|
method,
|
|
500
|
+
redirect: "error",
|
|
156
501
|
headers: {
|
|
157
502
|
Authorization: `Bearer ${this.apiKey}`,
|
|
158
|
-
|
|
503
|
+
...encodeRequest(body, reqOpts).headers,
|
|
159
504
|
"User-Agent": `nixflex-node/${SDK_VERSION}`
|
|
160
505
|
},
|
|
161
|
-
body: body
|
|
506
|
+
body: encodeRequest(body, reqOpts).body,
|
|
162
507
|
signal: controller.signal
|
|
163
508
|
});
|
|
509
|
+
const bytes = res.status === 204 ? null : await res.arrayBuffer();
|
|
510
|
+
return new Response(bytes, { status: res.status, statusText: res.statusText, headers: res.headers });
|
|
164
511
|
} finally {
|
|
165
512
|
clearTimeout(timer);
|
|
166
513
|
}
|
|
@@ -181,14 +528,17 @@ var Agents = class {
|
|
|
181
528
|
create(params = {}, opts) {
|
|
182
529
|
return this.http.request("POST", "/agents", params, void 0, opts);
|
|
183
530
|
}
|
|
184
|
-
/**
|
|
531
|
+
/** Bare array. Active by default; stable created_at DESC, agent_id DESC order. */
|
|
185
532
|
list(params = {}, opts) {
|
|
186
|
-
return this.http.request("GET", "/agents", void 0, { limit: params.limit, offset: params.offset }, opts);
|
|
533
|
+
return this.http.request("GET", "/agents", void 0, { limit: params.limit, offset: params.offset, status: params.status, search: params.search }, opts);
|
|
187
534
|
}
|
|
188
|
-
/** Iterate
|
|
535
|
+
/** Iterate active agents across pages. pageSize must be a whole number 1..200.
|
|
536
|
+
* Offset pages are not a snapshot: concurrent creates/disables can shift rows. */
|
|
189
537
|
async *iter(pageSize = 100, opts) {
|
|
538
|
+
if (!Number.isInteger(pageSize) || pageSize < 1 || pageSize > 200) throw new RangeError("Agent pageSize must be a whole number from 1 to 200.");
|
|
190
539
|
let offset = 0;
|
|
191
540
|
while (true) {
|
|
541
|
+
if (offset > 1e6) throw new RangeError("Agent iteration exceeds the maximum offset of 1000000.");
|
|
192
542
|
const page = await this.list({ limit: pageSize, offset }, opts);
|
|
193
543
|
for (const item of page) yield item;
|
|
194
544
|
if (page.length < pageSize) return;
|
|
@@ -201,40 +551,198 @@ var Agents = class {
|
|
|
201
551
|
}
|
|
202
552
|
/** Update an agent. Send ONLY the fields you want to change - omitted fields
|
|
203
553
|
* keep their values. Active calls are unaffected; new calls use the new config.
|
|
204
|
-
*
|
|
554
|
+
* Empty/unknown-only updates fail; mixed unknown keys return warnings. */
|
|
205
555
|
update(agentId, params, opts) {
|
|
206
556
|
return this.http.request("PUT", `/agents/${encodeURIComponent(agentId)}`, params, void 0, opts);
|
|
207
557
|
}
|
|
208
|
-
/**
|
|
209
|
-
*
|
|
210
|
-
* update(agentId, { is_active: false }) instead. */
|
|
558
|
+
/** Soft disable only (is_active=false). Does not detach numbers or erase history.
|
|
559
|
+
* The legacy response message is "Agent deleted". */
|
|
211
560
|
delete(agentId, opts) {
|
|
212
561
|
return this.http.request("DELETE", `/agents/${encodeURIComponent(agentId)}`, void 0, void 0, opts);
|
|
213
562
|
}
|
|
214
563
|
};
|
|
215
564
|
|
|
565
|
+
// src/call-requests.ts
|
|
566
|
+
import { randomUUID } from "crypto";
|
|
567
|
+
|
|
568
|
+
// src/call-request-errors.ts
|
|
569
|
+
var NixflexOutboundRequestError = class extends NixflexError {
|
|
570
|
+
};
|
|
571
|
+
var NixflexOutboundRequestPendingError = class extends NixflexOutboundRequestError {
|
|
572
|
+
};
|
|
573
|
+
var NixflexOutboundRequestUnknownError = class extends NixflexOutboundRequestError {
|
|
574
|
+
};
|
|
575
|
+
var NixflexRequestIdConflictError = class extends NixflexOutboundRequestError {
|
|
576
|
+
};
|
|
577
|
+
var NixflexOutboundRequestUnavailableError = class extends NixflexOutboundRequestError {
|
|
578
|
+
};
|
|
579
|
+
var NixflexCallBookingsUnavailableError = class extends NixflexError {
|
|
580
|
+
};
|
|
581
|
+
var classes = {
|
|
582
|
+
outbound_request_pending: NixflexOutboundRequestPendingError,
|
|
583
|
+
outbound_request_unknown: NixflexOutboundRequestUnknownError,
|
|
584
|
+
request_id_conflict: NixflexRequestIdConflictError,
|
|
585
|
+
outbound_request_unavailable: NixflexOutboundRequestUnavailableError
|
|
586
|
+
};
|
|
587
|
+
function outboundRequestError(value, requestId2, mutation) {
|
|
588
|
+
const e = value, raw = (e == null ? void 0 : e.details) || {};
|
|
589
|
+
const status = Number.isInteger(e == null ? void 0 : e.status) && e.status >= 0 && e.status <= 599 ? e.status : 0;
|
|
590
|
+
const original = (e == null ? void 0 : e.code) === "outcome_unknown" ? raw.original_code : e == null ? void 0 : e.code;
|
|
591
|
+
const code = typeof original === "string" && /^[a-z][a-z0-9_]{0,79}$/.test(original) && !["unknown_error", "invalid_response"].includes(original) ? original : mutation ? "outbound_request_unknown" : "outbound_request_unavailable";
|
|
592
|
+
const details = { request_id: requestId2 };
|
|
593
|
+
if (["pending", "accepted", "rejected", "unknown"].includes(String(raw.state))) details.state = raw.state;
|
|
594
|
+
if (mutation) {
|
|
595
|
+
details.safe_to_retry = false;
|
|
596
|
+
if (!details.state && (status === 0 || code === "outbound_request_unknown")) details.state = "unknown";
|
|
597
|
+
}
|
|
598
|
+
const type = {
|
|
599
|
+
400: "invalid_request",
|
|
600
|
+
422: "invalid_request",
|
|
601
|
+
401: "authentication_error",
|
|
602
|
+
402: "payment_required",
|
|
603
|
+
403: "permission_denied",
|
|
604
|
+
404: "not_found",
|
|
605
|
+
409: "conflict",
|
|
606
|
+
429: "rate_limit"
|
|
607
|
+
}[status] || (status >= 500 ? "server_error" : status === 0 && mutation ? "outcome_unknown" : "error");
|
|
608
|
+
const ErrorClass = classes[code] || NixflexOutboundRequestError;
|
|
609
|
+
const result = new ErrorClass(status, { error: {
|
|
610
|
+
type,
|
|
611
|
+
code,
|
|
612
|
+
message: mutation ? "Call request not confirmed. Keep this request_id; check its status and Call History before any manual retry. No automatic repeat." : "Call request status could not be read. Check the error code; this read placed no call.",
|
|
613
|
+
details
|
|
614
|
+
} });
|
|
615
|
+
result.name = ErrorClass.name;
|
|
616
|
+
return result;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
// src/call-request-projection.ts
|
|
620
|
+
var requestUuid = (v) => typeof v === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(v);
|
|
621
|
+
function requestId(value) {
|
|
622
|
+
if (!requestUuid(value)) throw new TypeError("request_id must be a UUID. No request sent.");
|
|
623
|
+
return value;
|
|
624
|
+
}
|
|
625
|
+
function callIdentifier(value) {
|
|
626
|
+
if (typeof value !== "string" || !value || value.length > 200 || [".", ".."].includes(value) || /[\u0000-\u001f]/.test(value))
|
|
627
|
+
throw new TypeError("call_id must be an existing call identifier. No request sent.");
|
|
628
|
+
return value;
|
|
629
|
+
}
|
|
630
|
+
var invalid = () => {
|
|
631
|
+
throw new NixflexConnectionError("Invalid call result shape. No result was inferred.");
|
|
632
|
+
};
|
|
633
|
+
var object = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : invalid();
|
|
634
|
+
var nullable = (v) => v === null || typeof v === "string";
|
|
635
|
+
var appointment = ["start", "end", "attendee_name", "attendee_email", "service", "timezone"];
|
|
636
|
+
function row(value, final) {
|
|
637
|
+
const v = object(value), fields = final ? ["booking_uid", "status", ...appointment] : ["action", "booking_uid", ...appointment, "at"];
|
|
638
|
+
if (typeof v.booking_uid !== "string" || !v.booking_uid || appointment.some((k) => k === "service" ? !(nullable(v[k]) || typeof v[k] === "number" && Number.isFinite(v[k])) : !nullable(v[k])) || (final ? !["active", "cancelled"].includes(v.status) : !["created", "rescheduled", "cancelled"].includes(v.action) || typeof v.at !== "string")) invalid();
|
|
639
|
+
return Object.fromEntries(fields.map((k) => [k, v[k]]));
|
|
640
|
+
}
|
|
641
|
+
function callBookings(value, id) {
|
|
642
|
+
const v = object(value);
|
|
643
|
+
if (v.call_id !== id || !["ready", "none", "processing", "deleted", "unavailable"].includes(v.state)) invalid();
|
|
644
|
+
if (v.state !== "ready") {
|
|
645
|
+
if (v.result !== null) invalid();
|
|
646
|
+
return { call_id: id, state: v.state, result: null };
|
|
647
|
+
}
|
|
648
|
+
const r = object(v.result), fields = ["event", "call_id", "agent_id", "from", "to", "number", "ended_at"];
|
|
649
|
+
if (r.event !== "call.bookings" || r.call_id !== id || fields.slice(2).some((k) => !nullable(r[k])) || !Array.isArray(r.timeline) || !r.timeline.length || !Array.isArray(r.final) || !r.final.length) invalid();
|
|
650
|
+
return { call_id: id, state: "ready", result: {
|
|
651
|
+
...Object.fromEntries(fields.map((k) => [k, r[k]])),
|
|
652
|
+
timeline: r.timeline.map((v2) => row(v2, false)),
|
|
653
|
+
final: r.final.map((v2) => row(v2, true))
|
|
654
|
+
} };
|
|
655
|
+
}
|
|
656
|
+
function outboundRequest(value, id) {
|
|
657
|
+
const v = object(value);
|
|
658
|
+
if (typeof v.request_id !== "string" || v.request_id.toLowerCase() !== id.toLowerCase() || !["pending", "accepted", "rejected", "unknown"].includes(v.state) || !nullable(v.call_id) || !nullable(v.reason) || v.state === "accepted" && !v.call_id) invalid();
|
|
659
|
+
return { request_id: v.request_id, state: v.state, call_id: v.call_id, reason: v.reason };
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// src/call-requests.ts
|
|
663
|
+
function prepareOutboundCall(params) {
|
|
664
|
+
const id = params.request_id === void 0 ? randomUUID() : requestId(params.request_id);
|
|
665
|
+
return { ...JSON.parse(JSON.stringify(params)), request_id: id };
|
|
666
|
+
}
|
|
667
|
+
async function createOutboundRequest(http, params, opts) {
|
|
668
|
+
const id = requestId(params.request_id);
|
|
669
|
+
try {
|
|
670
|
+
const value = await http.request("POST", "/calls/outbound", params, void 0, opts);
|
|
671
|
+
if (!value || typeof value.call_id !== "string" || !value.call_id || value.call_id.length > 200 || /[\u0000-\u0020]/.test(value.call_id) || value.status !== "initiated" || typeof value.request_id !== "string" || value.request_id.toLowerCase() !== id.toLowerCase() || value.replayed !== void 0 && value.replayed !== true || value.request_status !== void 0 && (value.request_status !== "unconfirmed" || value.safe_to_retry !== false) || value.safe_to_retry !== void 0 && value.safe_to_retry !== false) throw new NixflexConnectionError("Invalid acceptance receipt.");
|
|
672
|
+
return value;
|
|
673
|
+
} catch (e) {
|
|
674
|
+
throw outboundRequestError(e, id, true);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
async function readCallBookings(http, id, opts) {
|
|
678
|
+
callIdentifier(id);
|
|
679
|
+
try {
|
|
680
|
+
return callBookings(await http.request("GET", `/calls/${encodeURIComponent(id)}/bookings`, void 0, void 0, opts), id);
|
|
681
|
+
} catch (e) {
|
|
682
|
+
if (!(e instanceof NixflexError) || e.code !== "call_bookings_unavailable") throw e;
|
|
683
|
+
const result = new NixflexCallBookingsUnavailableError(e.status, { error: {
|
|
684
|
+
type: e.type,
|
|
685
|
+
code: e.code,
|
|
686
|
+
message: "The booking result could not be checked. This does not mean no booking was made.",
|
|
687
|
+
details: {}
|
|
688
|
+
} });
|
|
689
|
+
result.name = "NixflexCallBookingsUnavailableError";
|
|
690
|
+
throw result;
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
async function readOutboundRequest(http, id, opts) {
|
|
694
|
+
requestId(id);
|
|
695
|
+
try {
|
|
696
|
+
return outboundRequest(await http.request("GET", `/calls/outbound/requests/${encodeURIComponent(id)}`, void 0, void 0, opts), id);
|
|
697
|
+
} catch (e) {
|
|
698
|
+
if (e instanceof NixflexError && e.code === "outbound_request_unavailable") throw outboundRequestError(e, id, false);
|
|
699
|
+
throw e;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
|
|
216
703
|
// src/resources/calls.ts
|
|
217
704
|
var Calls = class {
|
|
218
705
|
constructor(http) {
|
|
219
706
|
this.http = http;
|
|
220
707
|
}
|
|
221
708
|
http;
|
|
222
|
-
/**
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
709
|
+
/** Generate a UUID locally before sending; save and reuse the returned body unchanged. */
|
|
710
|
+
prepare(params) {
|
|
711
|
+
return prepareOutboundCall(params);
|
|
712
|
+
}
|
|
713
|
+
bookings(callId, opts) {
|
|
714
|
+
return readCallBookings(this.http, callId, opts);
|
|
715
|
+
}
|
|
716
|
+
outboundRequest(requestId2, opts) {
|
|
717
|
+
return readOutboundRequest(this.http, requestId2, opts);
|
|
718
|
+
}
|
|
227
719
|
create(params, opts) {
|
|
720
|
+
if (params.request_id !== void 0) return createOutboundRequest(this.http, params, opts);
|
|
228
721
|
return this.http.request("POST", "/calls/outbound", params, void 0, opts);
|
|
229
722
|
}
|
|
230
723
|
/** List calls, newest first. Default 50, hard cap 200. The response is a
|
|
231
724
|
* bare array with no total - page until you get fewer rows than you asked
|
|
232
|
-
* for (or use iter()).
|
|
725
|
+
* for within the 200 cap (or use iter()). Availability depends on retention. */
|
|
233
726
|
list(params = {}, opts) {
|
|
727
|
+
if ("agent_id" in params) throw new TypeError("Legacy calls.list does not filter by agent; use calls.history({agent: id}).");
|
|
234
728
|
return this.http.request("GET", "/calls", void 0, { limit: params.limit, offset: params.offset }, opts);
|
|
235
729
|
}
|
|
236
|
-
/**
|
|
730
|
+
/** Dashboard-style filtered metadata, totals and stable cursor order. Not a frozen database snapshot. */
|
|
731
|
+
history(params = {}, opts) {
|
|
732
|
+
return this.http.request("GET", "/calls/history", void 0, { ...params }, opts);
|
|
733
|
+
}
|
|
734
|
+
/** Explicit nullable detail, failed-start and retained stubs; no raw storage URL. */
|
|
735
|
+
read(callId, opts) {
|
|
736
|
+
return this.http.request("GET", `/calls/${encodeURIComponent(callId)}`, void 0, { view: "detail" }, opts);
|
|
737
|
+
}
|
|
738
|
+
/** Managed-storage link: use expires_at, never a hardcoded lifetime, or a truthful non-downloadable state. Never reads BYO storage. */
|
|
739
|
+
recording(callId, opts) {
|
|
740
|
+
return this.http.request("GET", `/calls/${encodeURIComponent(callId)}/recording`, void 0, void 0, opts);
|
|
741
|
+
}
|
|
742
|
+
/** Iterate calls across pages. pageSize must be a whole number 1..200.
|
|
743
|
+
* Offset pages are not a snapshot: concurrent changes can shift rows. */
|
|
237
744
|
async *iter(pageSize = 100, opts) {
|
|
745
|
+
if (!Number.isInteger(pageSize) || pageSize < 1 || pageSize > 200) throw new RangeError("Call pageSize must be a whole number from 1 to 200.");
|
|
238
746
|
let offset = 0;
|
|
239
747
|
while (true) {
|
|
240
748
|
const page = await this.list({ limit: pageSize, offset }, opts);
|
|
@@ -244,19 +752,20 @@ var Calls = class {
|
|
|
244
752
|
}
|
|
245
753
|
}
|
|
246
754
|
/** Fetch one call: transcript, recording URL, post-call analysis. Note:
|
|
247
|
-
* duration_ms is time CONNECTED (
|
|
755
|
+
* duration_ms is time CONNECTED (not necessarily AI billed time) - ring time is
|
|
248
756
|
* excluded, so it will not equal end_timestamp - start_timestamp on
|
|
249
757
|
* outbound calls. */
|
|
250
758
|
get(callId, opts) {
|
|
251
759
|
return this.http.request("GET", `/calls/${encodeURIComponent(callId)}`, void 0, void 0, opts);
|
|
252
760
|
}
|
|
253
|
-
/**
|
|
254
|
-
*
|
|
761
|
+
/** End a running call, then delete its content. 503 hangup_pending with
|
|
762
|
+
* retry_pending:true means queued, not deleted. Recording cleanup may remain
|
|
763
|
+
* queued or carrier best effort. One DELETE; never automatically repeated. */
|
|
255
764
|
delete(callId, opts) {
|
|
256
|
-
return this.http.request("DELETE", `/calls/${
|
|
765
|
+
return this.http.request("DELETE", `/calls/${contentDeleteId(callId)}`, void 0, void 0, opts);
|
|
257
766
|
}
|
|
258
|
-
/**
|
|
259
|
-
*
|
|
767
|
+
/** Request guarded call cleanup, not account/SMS erasure. Safety holds can
|
|
768
|
+
* refuse it; legacy recording counters are not proof of every copy's erasure. */
|
|
260
769
|
deleteAll(opts) {
|
|
261
770
|
return this.http.request("DELETE", "/calls", void 0, void 0, opts);
|
|
262
771
|
}
|
|
@@ -266,21 +775,164 @@ var Campaigns = class {
|
|
|
266
775
|
this.http = http;
|
|
267
776
|
}
|
|
268
777
|
http;
|
|
269
|
-
/**
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
|
|
273
|
-
|
|
778
|
+
/** Cancel waiting work, end running calls and hide the campaign. History and used
|
|
779
|
+
* charges remain; no refund. Owner/Admin only. 503 hangup_pending is queued.
|
|
780
|
+
* Missing/foreign is 404. One DELETE; never automatically repeated. */
|
|
781
|
+
delete(id, opts) {
|
|
782
|
+
return this.http.request("DELETE", `/calls/batch/${contentDeleteId(id)}`, void 0, void 0, opts);
|
|
783
|
+
}
|
|
784
|
+
cancel(id, opts) {
|
|
785
|
+
return this.http.request("POST", `/calls/batch/${encodeURIComponent(id)}/cancel`, void 0, void 0, opts);
|
|
786
|
+
}
|
|
787
|
+
consent(id, params, opts) {
|
|
788
|
+
return this.http.request("POST", `/calls/batch/${encodeURIComponent(id)}/consent`, params, void 0, opts);
|
|
789
|
+
}
|
|
790
|
+
resume(id, opts) {
|
|
791
|
+
return this.http.request("POST", `/calls/batch/${encodeURIComponent(id)}/resume`, void 0, void 0, opts);
|
|
792
|
+
}
|
|
793
|
+
list(params = {}, opts) {
|
|
794
|
+
return this.http.request("GET", "/campaigns", void 0, { ...params }, opts);
|
|
795
|
+
}
|
|
796
|
+
/** Create executable work, not a draft. The default requests immediate launch; scheduled work can start automatically. Each dispatch still checks consent and local hours. */
|
|
274
797
|
create(params, opts) {
|
|
275
798
|
return this.http.request("POST", "/calls/batch", params, void 0, opts);
|
|
276
799
|
}
|
|
277
|
-
/**
|
|
278
|
-
* Already running = no-op returning current status. */
|
|
800
|
+
/** Request launch; it does not bypass recipient checks or prove delivery. Never auto-retried. */
|
|
279
801
|
launch(campaignId, opts) {
|
|
280
802
|
return this.http.request("POST", `/calls/batch/${encodeURIComponent(campaignId)}/launch`, void 0, void 0, opts);
|
|
281
803
|
}
|
|
282
804
|
};
|
|
283
805
|
|
|
806
|
+
// src/feature-errors.ts
|
|
807
|
+
var calendarErrorCodes = [
|
|
808
|
+
"invalid_return_url",
|
|
809
|
+
"number_not_found",
|
|
810
|
+
"already_connected",
|
|
811
|
+
"booking_provider_conflict",
|
|
812
|
+
"not_connected",
|
|
813
|
+
"agent_not_assigned",
|
|
814
|
+
"invalid_settings",
|
|
815
|
+
"invalid_timezone",
|
|
816
|
+
"invalid_hours",
|
|
817
|
+
"invalid_slot_minutes",
|
|
818
|
+
"invalid_calendar_id",
|
|
819
|
+
"invalid_send_invites",
|
|
820
|
+
"calendar_unavailable",
|
|
821
|
+
"expired_link",
|
|
822
|
+
"not_configured",
|
|
823
|
+
"guard_unavailable"
|
|
824
|
+
];
|
|
825
|
+
var credentialErrorCodes = [
|
|
826
|
+
"invalid_request",
|
|
827
|
+
"invalid_credentials",
|
|
828
|
+
"number_not_in_account",
|
|
829
|
+
"number_not_found",
|
|
830
|
+
"carrier_mismatch",
|
|
831
|
+
"account_unavailable",
|
|
832
|
+
"number_operation_pending",
|
|
833
|
+
"number_release_pending",
|
|
834
|
+
"carrier_unavailable",
|
|
835
|
+
"credential_update_unavailable",
|
|
836
|
+
"carrier_outcome_unknown",
|
|
837
|
+
"credential_save_pending"
|
|
838
|
+
];
|
|
839
|
+
var common = [
|
|
840
|
+
"unauthorized",
|
|
841
|
+
"invalid_api_key",
|
|
842
|
+
"permission_denied",
|
|
843
|
+
"forbidden",
|
|
844
|
+
"rate_limit_exceeded",
|
|
845
|
+
"organisation_disabled",
|
|
846
|
+
"organisation_unavailable",
|
|
847
|
+
"account_closed",
|
|
848
|
+
"account_inactive",
|
|
849
|
+
"outcome_unknown"
|
|
850
|
+
];
|
|
851
|
+
var NixflexCalendarError = class extends NixflexError {
|
|
852
|
+
};
|
|
853
|
+
var NixflexCredentialError = class extends NixflexError {
|
|
854
|
+
};
|
|
855
|
+
function featureError(value, kind, mutation) {
|
|
856
|
+
var _a, _b;
|
|
857
|
+
const e = value;
|
|
858
|
+
const status = Number.isInteger(e == null ? void 0 : e.status) && e.status >= 0 && e.status <= 599 ? e.status : 0;
|
|
859
|
+
const original = (e == null ? void 0 : e.code) === "outcome_unknown" ? (_a = e.details) == null ? void 0 : _a.original_code : e == null ? void 0 : e.code;
|
|
860
|
+
const allowed = kind === "calendar" ? calendarErrorCodes : credentialErrorCodes;
|
|
861
|
+
const code = typeof original === "string" && (allowed.includes(original) || common.includes(original)) ? original : (e == null ? void 0 : e.code) === "outcome_unknown" ? "outcome_unknown" : "request_failed";
|
|
862
|
+
const uncertain = mutation && ((e == null ? void 0 : e.code) === "outcome_unknown" || status === 0 || status >= 500 || status >= 300 && status < 400);
|
|
863
|
+
const details = uncertain ? { outcome: "unknown", safe_to_retry: false } : {};
|
|
864
|
+
if (/^[a-f0-9-]{36}$/i.test(String(((_b = e == null ? void 0 : e.details) == null ? void 0 : _b.operation_id) || ""))) details.operation_id = e.details.operation_id;
|
|
865
|
+
const type = status === 400 || status === 422 ? "invalid_request" : status === 409 ? "conflict" : status === 404 ? "not_found" : status === 401 ? "authentication_error" : status === 403 ? "permission_denied" : status === 429 ? "rate_limit" : status >= 500 ? "server_error" : uncertain ? "outcome_unknown" : "error";
|
|
866
|
+
let message = kind === "calendar" ? "Google Calendar request failed. Check status and code." : "Carrier details update failed. Check status and code.";
|
|
867
|
+
if (code === "carrier_outcome_unknown") message = "Carrier routing is unconfirmed. Contact support before retrying.";
|
|
868
|
+
else if (code === "credential_save_pending") message = "Carrier change succeeded; saving is pending. Retry manually with exactly the same details to finish saving.";
|
|
869
|
+
else if (uncertain) message += " Outcome is unconfirmed; check before retrying. No automatic repeat.";
|
|
870
|
+
const ErrorClass = kind === "calendar" ? NixflexCalendarError : NixflexCredentialError;
|
|
871
|
+
const result = new ErrorClass(status, { error: { type, code, message, details } });
|
|
872
|
+
result.name = kind === "calendar" ? "NixflexCalendarError" : "NixflexCredentialError";
|
|
873
|
+
if (uncertain) Object.assign(result, { outcome: "unknown", safe_to_retry: false });
|
|
874
|
+
return result;
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
// src/number-features.ts
|
|
878
|
+
async function numberFeature(http, method, path2, body, kind, opts) {
|
|
879
|
+
try {
|
|
880
|
+
return await http.request(method, path2, body, void 0, opts);
|
|
881
|
+
} catch (e) {
|
|
882
|
+
throw featureError(e, kind, method !== "GET");
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
var calendarPath = (number) => `/integrations/google-calendar/number/${encodeURIComponent(number)}`;
|
|
886
|
+
function credentialPair(body) {
|
|
887
|
+
const keys = body && typeof body === "object" ? Object.keys(body) : [];
|
|
888
|
+
const fields = keys.includes("twilio_sid") ? ["twilio_sid", "twilio_token"] : ["telnyx_api_key", "telnyx_connection_id"];
|
|
889
|
+
const values = body;
|
|
890
|
+
if (keys.length !== 2 || keys.some((k) => !fields.includes(k)) || fields.some((k) => typeof values[k] !== "string" || !values[k].trim() || values[k].length > 4096 || /[\r\n\x00]/.test(values[k])))
|
|
891
|
+
throw new TypeError("Supply exactly one complete carrier credential pair privately.");
|
|
892
|
+
const clean = Object.fromEntries(fields.map((k) => [k, values[k].trim()]));
|
|
893
|
+
if (fields[0] === "twilio_sid" ? !/^AC[a-f0-9]{32}$/i.test(clean.twilio_sid) : clean.telnyx_connection_id.length > 200)
|
|
894
|
+
throw new TypeError("Invalid carrier credential format.");
|
|
895
|
+
return clean;
|
|
896
|
+
}
|
|
897
|
+
async function updateCredentials(http, number, body, opts) {
|
|
898
|
+
const result = await numberFeature(http, "POST", `/phone-numbers/${encodeURIComponent(number)}/credentials`, credentialPair(body), "credentials", opts);
|
|
899
|
+
if (!result || result.updated !== true || result.phone_number !== number || result.provider !== ("twilio_sid" in body ? "twilio" : "telnyx"))
|
|
900
|
+
throw featureError({ status: 0 }, "credentials", true);
|
|
901
|
+
return { phone_number: result.phone_number, provider: result.provider, updated: true };
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
// src/sms-campaign-input.ts
|
|
905
|
+
function smsCampaignInput(input) {
|
|
906
|
+
const data = { ...input };
|
|
907
|
+
for (const [alias, field] of [["message", "message_template"], ["scheduled_at", "scheduled_date"]]) {
|
|
908
|
+
if (Object.prototype.hasOwnProperty.call(data, alias)) {
|
|
909
|
+
if (Object.prototype.hasOwnProperty.call(data, field)) throw new TypeError(`Use ${alias} or ${field}, not both.`);
|
|
910
|
+
data[field] = data[alias];
|
|
911
|
+
delete data[alias];
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
return data;
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
// src/resources/number-usage.ts
|
|
918
|
+
function readNumberUsage(http, phone, params = {}, opts) {
|
|
919
|
+
return http.request(
|
|
920
|
+
"GET",
|
|
921
|
+
`/phone-numbers/${encodeURIComponent(phone)}/usage`,
|
|
922
|
+
void 0,
|
|
923
|
+
{ period: params.period, time_zone: params.time_zone },
|
|
924
|
+
opts
|
|
925
|
+
);
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
// src/resources/number-move.ts
|
|
929
|
+
function moveNumber(http, number, params, opts) {
|
|
930
|
+
if (Object.keys(params).length !== 1 || typeof params.agent_id !== "string" || !params.agent_id.trim()) {
|
|
931
|
+
throw new Error("Send only agent_id when moving a number. Update other settings separately.");
|
|
932
|
+
}
|
|
933
|
+
return http.request("PATCH", `/phone-numbers/${encodeURIComponent(number)}`, params, void 0, opts);
|
|
934
|
+
}
|
|
935
|
+
|
|
284
936
|
// src/webhook-verify.ts
|
|
285
937
|
import { createHmac, timingSafeEqual } from "crypto";
|
|
286
938
|
function verifyWebhookSignature(rawBody, signatureHeader, keySecret, options = {}) {
|
|
@@ -317,6 +969,13 @@ var PhoneNumbers = class {
|
|
|
317
969
|
this.http = http;
|
|
318
970
|
}
|
|
319
971
|
http;
|
|
972
|
+
updateCredentials(phoneNumber, body, opts) {
|
|
973
|
+
return updateCredentials(this.http, phoneNumber, body, opts);
|
|
974
|
+
}
|
|
975
|
+
/** Retained-history usage, not a billing ledger. Defaults: all, UTC. */
|
|
976
|
+
usage(phoneNumber, params = {}, opts) {
|
|
977
|
+
return readNumberUsage(this.http, phoneNumber, params, opts);
|
|
978
|
+
}
|
|
320
979
|
/** Attach a number you already own. Carrier inferred from credentials
|
|
321
980
|
* (twilio_sid+twilio_token OR telnyx_api_key+telnyx_connection_id).
|
|
322
981
|
* WARNING: Twilio import REPLACES the number's existing webhooks - another
|
|
@@ -324,35 +983,32 @@ var PhoneNumbers = class {
|
|
|
324
983
|
import(params, opts) {
|
|
325
984
|
return this.http.request("POST", "/phone-numbers", params, void 0, opts);
|
|
326
985
|
}
|
|
327
|
-
/**
|
|
328
|
-
*
|
|
986
|
+
/** Owned public numbers, newest first. Opt into paging with limit/cursor.
|
|
987
|
+
* count is returned rows. Without paging, the server's row cap still applies. */
|
|
329
988
|
list(params = {}, opts) {
|
|
330
|
-
return this.http.request("GET", "/phone-numbers", void 0, { agent_id: params.agent_id }, opts);
|
|
989
|
+
return this.http.request("GET", "/phone-numbers", void 0, { agent_id: params.agent_id, provider: params.provider, limit: params.limit, cursor: params.cursor }, opts);
|
|
990
|
+
}
|
|
991
|
+
/** Saved safe settings, effective website voice switch, and safe key status. */
|
|
992
|
+
get(phoneNumber, opts) {
|
|
993
|
+
return this.http.request("GET", `/phone-numbers/${enc(phoneNumber)}`, void 0, void 0, opts);
|
|
331
994
|
}
|
|
332
|
-
/** Update per-number settings. Send ONLY what changes (empty body is
|
|
333
|
-
* rejected). null clears/inherits - see each field's JSDoc; speaking_rate
|
|
334
|
-
* null INHERITS the agent's speed (send 1, not null, to force normal). */
|
|
335
995
|
update(phoneNumber, params, opts) {
|
|
996
|
+
if ("agent_id" in params) return moveNumber(this.http, phoneNumber, params, opts);
|
|
336
997
|
return this.http.request("PATCH", `/phone-numbers/${enc(phoneNumber)}`, params, void 0, opts);
|
|
337
998
|
}
|
|
999
|
+
/** Same-account move; busy work is refused. Own number settings and history stay. */
|
|
1000
|
+
move(phoneNumber, agentId, opts) {
|
|
1001
|
+
return moveNumber(this.http, phoneNumber, { agent_id: agentId }, opts);
|
|
1002
|
+
}
|
|
338
1003
|
/** Disconnect from Nixflex (clears carrier webhooks + our record). Does NOT
|
|
339
1004
|
* release the number from your carrier - carrier billing continues until
|
|
340
1005
|
* you release it in Twilio/Telnyx yourself. Reversible by re-importing. */
|
|
341
1006
|
delete(phoneNumber, opts) {
|
|
342
1007
|
return this.http.request("DELETE", `/phone-numbers/${enc(phoneNumber)}`, void 0, void 0, opts);
|
|
343
1008
|
}
|
|
344
|
-
/** Turn live call monitoring on/off for a number (off by default).
|
|
345
|
-
* NOTE: enabling bills that number's inbound calls at $0.09/min. */
|
|
346
|
-
setMonitor(phoneNumber, enabled, opts) {
|
|
347
|
-
return this.http.request("PUT", `/integrations/monitor/number/${enc(phoneNumber)}`, { enabled }, void 0, opts);
|
|
348
|
-
}
|
|
349
|
-
/** Current monitoring state for a number. */
|
|
350
|
-
getMonitor(phoneNumber, opts) {
|
|
351
|
-
return this.http.request("GET", `/integrations/monitor/number/${enc(phoneNumber)}`, void 0, void 0, opts);
|
|
352
|
-
}
|
|
353
1009
|
/** Enable/disable browser (web) calls for a number (off by default).
|
|
354
|
-
*
|
|
355
|
-
*
|
|
1010
|
+
* Enabling alone is free. Premium applies to actual browser calls,
|
|
1011
|
+
* not ordinary phone calls just because this switch is enabled. */
|
|
356
1012
|
setWebCalls(phoneNumber, enabled, opts) {
|
|
357
1013
|
return this.http.request("PUT", `/integrations/web-calls/number/${enc(phoneNumber)}`, { enabled }, void 0, opts);
|
|
358
1014
|
}
|
|
@@ -366,29 +1022,47 @@ var SmsCampaigns = class {
|
|
|
366
1022
|
this.http = http;
|
|
367
1023
|
}
|
|
368
1024
|
http;
|
|
1025
|
+
cancel(id, opts) {
|
|
1026
|
+
return this.http.request("POST", `/sms/campaigns/${encodeURIComponent(id)}/cancel`, void 0, void 0, opts);
|
|
1027
|
+
}
|
|
1028
|
+
consent(id, params, opts) {
|
|
1029
|
+
return this.http.request("POST", `/sms/campaigns/${encodeURIComponent(id)}/consent`, params, void 0, opts);
|
|
1030
|
+
}
|
|
1031
|
+
resume(id, opts) {
|
|
1032
|
+
return this.http.request("POST", `/sms/campaigns/${encodeURIComponent(id)}/resume`, void 0, void 0, opts);
|
|
1033
|
+
}
|
|
1034
|
+
update(id, params, opts) {
|
|
1035
|
+
return this.http.request("PATCH", `/sms/campaigns/${encodeURIComponent(id)}`, params, void 0, opts);
|
|
1036
|
+
}
|
|
369
1037
|
/** Create a one-time SMS broadcast ({{variable}} templating per recipient,
|
|
370
|
-
* up to
|
|
1038
|
+
* up to 100,000 recipients). from_number may be on either carrier (Twilio or
|
|
371
1039
|
* Telnyx) and must be a number on your own account. */
|
|
372
1040
|
create(params, opts) {
|
|
373
|
-
return this.http.request("POST", "/sms/campaigns", params, void 0, opts);
|
|
1041
|
+
return this.http.request("POST", "/sms/campaigns", smsCampaignInput(params), void 0, opts);
|
|
374
1042
|
}
|
|
375
|
-
/**
|
|
1043
|
+
/** Request launch; scheduling and recipient contact-hour gates still apply. */
|
|
376
1044
|
launch(campaignId, opts) {
|
|
377
1045
|
return this.http.request("POST", `/sms/campaigns/${encodeURIComponent(campaignId)}/launch`, void 0, void 0, opts);
|
|
378
1046
|
}
|
|
379
1047
|
/** All campaigns, newest first, with live-computed delivery counts. */
|
|
380
1048
|
list(params = {}, opts) {
|
|
381
|
-
return this.http.request("GET", "/sms/campaigns", void 0, { status: params.status, limit: params.limit }, opts);
|
|
1049
|
+
return this.http.request("GET", "/sms/campaigns", void 0, { status: params.status, limit: params.limit, before: params.before }, opts);
|
|
382
1050
|
}
|
|
383
|
-
/**
|
|
384
|
-
* carrier, never confirmed on the handset) counts as FAILED, not delivered. */
|
|
1051
|
+
/** Detail envelope with independent recipient/message cursors; sent is not failed. */
|
|
385
1052
|
get(campaignId, opts) {
|
|
386
|
-
return this.http.request(
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
1053
|
+
return this.http.request(
|
|
1054
|
+
"GET",
|
|
1055
|
+
`/sms/campaigns/${encodeURIComponent(campaignId)}`,
|
|
1056
|
+
void 0,
|
|
1057
|
+
{ limit: opts == null ? void 0 : opts.limit, recipient_cursor: opts == null ? void 0 : opts.recipient_cursor, message_cursor: opts == null ? void 0 : opts.message_cursor },
|
|
1058
|
+
opts
|
|
1059
|
+
);
|
|
1060
|
+
}
|
|
1061
|
+
/** Cancel waiting work and hide the campaign. History/used charges remain, no refund
|
|
1062
|
+
* or recall of sent SMS. Owner/Admin only. 503 hangup_pending is queued, not success.
|
|
1063
|
+
* Missing/foreign is 404. One DELETE; never automatically repeated. */
|
|
390
1064
|
delete(campaignId, opts) {
|
|
391
|
-
return this.http.request("DELETE", `/sms/campaigns/${
|
|
1065
|
+
return this.http.request("DELETE", `/sms/campaigns/${contentDeleteId(campaignId)}`, void 0, void 0, opts);
|
|
392
1066
|
}
|
|
393
1067
|
};
|
|
394
1068
|
var Sms = class {
|
|
@@ -411,6 +1085,10 @@ var Keys = class {
|
|
|
411
1085
|
this.http = http;
|
|
412
1086
|
}
|
|
413
1087
|
http;
|
|
1088
|
+
/** Retained request-log snapshot, not organisation audit events. Default today (UTC). */
|
|
1089
|
+
activity(params = {}, opts) {
|
|
1090
|
+
return this.http.request("GET", "/keys/activity", void 0, { ...params }, opts);
|
|
1091
|
+
}
|
|
414
1092
|
/** Rotate the key SECRET (key_id stays stable - the Stripe model). The old
|
|
415
1093
|
* secret stops working THE INSTANT this returns; the new one is shown ONCE.
|
|
416
1094
|
* Update every deployed app before rotating in production. */
|
|
@@ -429,78 +1107,13 @@ var UsageResource = class {
|
|
|
429
1107
|
return this.http.request("GET", "/usage", void 0, void 0, opts);
|
|
430
1108
|
}
|
|
431
1109
|
};
|
|
432
|
-
var Storage = class {
|
|
433
|
-
constructor(http) {
|
|
434
|
-
this.http = http;
|
|
435
|
-
}
|
|
436
|
-
http;
|
|
437
|
-
/** Connect your own S3-compatible bucket for call recordings (data residency).
|
|
438
|
-
* The connection is verified with a probe write BEFORE saving - broken
|
|
439
|
-
* credentials are rejected, never stored. Recordings then upload to your
|
|
440
|
-
* bucket and Nixflex keeps no copy; recording_url becomes a byo: path. */
|
|
441
|
-
set(params, opts) {
|
|
442
|
-
return this.http.request("PUT", "/account/storage", params, void 0, opts);
|
|
443
|
-
}
|
|
444
|
-
/** Current storage configuration. The secret is never included. */
|
|
445
|
-
get(opts) {
|
|
446
|
-
return this.http.request("GET", "/account/storage", void 0, void 0, opts);
|
|
447
|
-
}
|
|
448
|
-
/** Disconnect and clear. Recordings return to Nixflex EU storage from the
|
|
449
|
-
* next call; files already in your bucket are untouched - they are yours. */
|
|
450
|
-
delete(opts) {
|
|
451
|
-
return this.http.request("DELETE", "/account/storage", void 0, void 0, opts);
|
|
452
|
-
}
|
|
453
|
-
};
|
|
454
|
-
var Llm = class {
|
|
455
|
-
constructor(http) {
|
|
456
|
-
this.http = http;
|
|
457
|
-
}
|
|
458
|
-
http;
|
|
459
|
-
/** Connect an OpenAI-compatible model. Verified BEFORE saving with a real
|
|
460
|
-
* completion + a tool-calling round trip (models without tool calling are
|
|
461
|
-
* refused). Calls your model serves bill at a $0.015/min discount; if it
|
|
462
|
-
* fails on a call the standard stack takes over and that call bills standard. */
|
|
463
|
-
set(params, opts) {
|
|
464
|
-
return this.http.request("PUT", "/account/llm", params, void 0, opts);
|
|
465
|
-
}
|
|
466
|
-
/** Current LLM configuration. The provider key is never included. */
|
|
467
|
-
get(opts) {
|
|
468
|
-
return this.http.request("GET", "/account/llm", void 0, void 0, opts);
|
|
469
|
-
}
|
|
470
|
-
/** Disconnect. Calls return to the standard stack and rate from the next call. */
|
|
471
|
-
delete(opts) {
|
|
472
|
-
return this.http.request("DELETE", "/account/llm", void 0, void 0, opts);
|
|
473
|
-
}
|
|
474
|
-
};
|
|
475
|
-
var Tts = class {
|
|
476
|
-
constructor(http) {
|
|
477
|
-
this.http = http;
|
|
478
|
-
}
|
|
479
|
-
http;
|
|
480
|
-
/** Connect your voice provider (elevenlabs or cartesia). Verified BEFORE
|
|
481
|
-
* saving with one real synthesis using the exact voice ID. Phone calls only -
|
|
482
|
-
* web calls keep the standard voice. Calls your voice serves bill at a
|
|
483
|
-
* $0.02/min discount; on failure the standard voice takes over and that call
|
|
484
|
-
* bills the standard TTS rate. */
|
|
485
|
-
set(params, opts) {
|
|
486
|
-
return this.http.request("PUT", "/account/tts", params, void 0, opts);
|
|
487
|
-
}
|
|
488
|
-
/** Current TTS configuration. The provider key is never included. */
|
|
489
|
-
get(opts) {
|
|
490
|
-
return this.http.request("GET", "/account/tts", void 0, void 0, opts);
|
|
491
|
-
}
|
|
492
|
-
/** Disconnect. Calls return to the standard voice and rate from the next call. */
|
|
493
|
-
delete(opts) {
|
|
494
|
-
return this.http.request("DELETE", "/account/tts", void 0, void 0, opts);
|
|
495
|
-
}
|
|
496
|
-
};
|
|
497
1110
|
var Webhooks = class {
|
|
498
1111
|
constructor(http) {
|
|
499
1112
|
this.http = http;
|
|
500
1113
|
}
|
|
501
1114
|
http;
|
|
502
1115
|
/** Verify a webhook delivery's X-Nixflex-Signature header. Pass the RAW
|
|
503
|
-
* request body (string or Buffer) and
|
|
1116
|
+
* request body (string or Buffer) and the organisation signing secret (independent of API-key rotation). Returns true only
|
|
504
1117
|
* for an authentic, fresh signature. See webhook-verify.ts. */
|
|
505
1118
|
verify(rawBody, signatureHeader, keySecret, options) {
|
|
506
1119
|
return verifyWebhookSignature(rawBody, signatureHeader, keySecret, options);
|
|
@@ -553,8 +1166,453 @@ var Callers = class {
|
|
|
553
1166
|
}
|
|
554
1167
|
};
|
|
555
1168
|
|
|
1169
|
+
// src/key-create.ts
|
|
1170
|
+
async function createKey(params, baseUrl) {
|
|
1171
|
+
let res;
|
|
1172
|
+
try {
|
|
1173
|
+
res = await fetch(baseUrl.replace(/\/+$/, "") + "/v1/keys", {
|
|
1174
|
+
method: "POST",
|
|
1175
|
+
redirect: "error",
|
|
1176
|
+
headers: { "Content-Type": "application/json", "User-Agent": `nixflex-node/${SDK_VERSION}` },
|
|
1177
|
+
body: JSON.stringify(params),
|
|
1178
|
+
signal: AbortSignal.timeout(3e4)
|
|
1179
|
+
});
|
|
1180
|
+
} catch {
|
|
1181
|
+
throw new NixflexOutcomeUnknownError();
|
|
1182
|
+
}
|
|
1183
|
+
const requestId2 = res.headers.get("x-request-id") || res.headers.get("x-railway-request-id") || void 0;
|
|
1184
|
+
let body;
|
|
1185
|
+
try {
|
|
1186
|
+
body = await res.json();
|
|
1187
|
+
} catch {
|
|
1188
|
+
if (res.ok) throw new NixflexOutcomeUnknownError(res.status, null, requestId2);
|
|
1189
|
+
body = null;
|
|
1190
|
+
}
|
|
1191
|
+
if (!res.ok) throw errorFromResponse(
|
|
1192
|
+
res.status,
|
|
1193
|
+
body,
|
|
1194
|
+
requestId2,
|
|
1195
|
+
parseInt(res.headers.get("retry-after") || "0", 10) || 0,
|
|
1196
|
+
true
|
|
1197
|
+
);
|
|
1198
|
+
return body;
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
// src/resources/integrations.ts
|
|
1202
|
+
var providers = ["calcom", "slack", "zapier", "make", "gohighlevel", "webhook", "webhook2", "precall", "web-calls"];
|
|
1203
|
+
function path(provider, number) {
|
|
1204
|
+
if (!providers.includes(provider)) throw new TypeError("Unknown public integration provider.");
|
|
1205
|
+
return `/integrations/${provider}/number/${encodeURIComponent(number)}`;
|
|
1206
|
+
}
|
|
1207
|
+
var functions = (number) => `/integrations/custom-functions/number/${encodeURIComponent(number)}`;
|
|
1208
|
+
var Integrations = class {
|
|
1209
|
+
constructor(http) {
|
|
1210
|
+
this.http = http;
|
|
1211
|
+
}
|
|
1212
|
+
http;
|
|
1213
|
+
/** Returns a short-lived link for a human to open; never opens a browser. */
|
|
1214
|
+
connectGoogleCalendar(number, returnUrl, opts) {
|
|
1215
|
+
return numberFeature(this.http, "POST", calendarPath(number) + "/connect", { return_url: returnUrl }, "calendar", opts);
|
|
1216
|
+
}
|
|
1217
|
+
getGoogleCalendar(number, opts) {
|
|
1218
|
+
return numberFeature(this.http, "GET", calendarPath(number), void 0, "calendar", opts);
|
|
1219
|
+
}
|
|
1220
|
+
disconnectGoogleCalendar(number, opts) {
|
|
1221
|
+
return numberFeature(this.http, "DELETE", calendarPath(number), void 0, "calendar", opts);
|
|
1222
|
+
}
|
|
1223
|
+
updateGoogleCalendarSettings(number, body, opts) {
|
|
1224
|
+
return numberFeature(this.http, "PATCH", calendarPath(number), body, "calendar", opts);
|
|
1225
|
+
}
|
|
1226
|
+
get(provider, number, opts) {
|
|
1227
|
+
return this.http.request("GET", path(provider, number), void 0, void 0, opts);
|
|
1228
|
+
}
|
|
1229
|
+
/** Provider PUT replaces configuration. Never automatically repeated. */
|
|
1230
|
+
set(provider, number, body, opts) {
|
|
1231
|
+
return this.http.request("PUT", path(provider, number), body, void 0, opts);
|
|
1232
|
+
}
|
|
1233
|
+
delete(provider, number, opts) {
|
|
1234
|
+
return this.http.request("DELETE", path(provider, number), void 0, void 0, opts);
|
|
1235
|
+
}
|
|
1236
|
+
getAgentPrecall(agentId, opts) {
|
|
1237
|
+
return this.http.request("GET", `/integrations/precall/agent/${encodeURIComponent(agentId)}`, void 0, void 0, opts);
|
|
1238
|
+
}
|
|
1239
|
+
setAgentPrecall(agentId, url, opts) {
|
|
1240
|
+
return this.http.request("PUT", `/integrations/precall/agent/${encodeURIComponent(agentId)}`, { url }, void 0, opts);
|
|
1241
|
+
}
|
|
1242
|
+
/** Removing the agent default affects every number without an override. */
|
|
1243
|
+
deleteAgentPrecall(agentId, opts) {
|
|
1244
|
+
return this.http.request("DELETE", `/integrations/precall/agent/${encodeURIComponent(agentId)}`, void 0, void 0, opts);
|
|
1245
|
+
}
|
|
1246
|
+
/** At most 15; an empty list is not proof that the number exists. */
|
|
1247
|
+
listFunctions(number, opts) {
|
|
1248
|
+
return this.http.request("GET", functions(number), void 0, void 0, opts);
|
|
1249
|
+
}
|
|
1250
|
+
createFunction(number, body, opts) {
|
|
1251
|
+
return this.http.request("POST", functions(number), body, void 0, opts);
|
|
1252
|
+
}
|
|
1253
|
+
/** PATCH changes supplied fields only. {} is refused by the server. */
|
|
1254
|
+
updateFunction(number, id, body, opts) {
|
|
1255
|
+
return this.http.request("PATCH", functions(number) + "/" + encodeURIComponent(id), body, void 0, opts);
|
|
1256
|
+
}
|
|
1257
|
+
deleteFunction(number, id, opts) {
|
|
1258
|
+
return this.http.request("DELETE", functions(number) + "/" + encodeURIComponent(id), void 0, void 0, opts);
|
|
1259
|
+
}
|
|
1260
|
+
};
|
|
1261
|
+
|
|
1262
|
+
// src/knowledge/guards.ts
|
|
1263
|
+
function writeOptions(opts) {
|
|
1264
|
+
const key = opts == null ? void 0 : opts.idempotencyKey;
|
|
1265
|
+
if (typeof key !== "string" || !/^[A-Za-z0-9_.:-]{8,128}$/.test(key) || key.startsWith("prompt:"))
|
|
1266
|
+
throw new TypeError("Supply an Idempotency-Key of 8..128 letters, digits, . _ : -, without the reserved prefix.");
|
|
1267
|
+
return opts;
|
|
1268
|
+
}
|
|
1269
|
+
function identifier(value) {
|
|
1270
|
+
if (typeof value !== "string" || !value) throw new TypeError("A non-empty knowledge identifier is required.");
|
|
1271
|
+
return encodeURIComponent(value);
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
// src/knowledge/poll.ts
|
|
1275
|
+
async function pollJob(read, options = {}) {
|
|
1276
|
+
const { maxAttempts = 20, intervalMs = 1e3, timeoutMs = 3e4, signal } = options;
|
|
1277
|
+
if (!Number.isInteger(maxAttempts) || maxAttempts < 1 || maxAttempts > 100 || !Number.isFinite(intervalMs) || intervalMs < 0 || intervalMs > 3e4 || !Number.isFinite(timeoutMs) || timeoutMs <= 0 || timeoutMs > 3e5)
|
|
1278
|
+
throw new RangeError("Use 1..100 attempts, a 0..30000 ms interval and a timeout up to 300000 ms.");
|
|
1279
|
+
const end = Date.now() + timeoutMs;
|
|
1280
|
+
for (let n = 0; n < maxAttempts; n++) {
|
|
1281
|
+
if (signal == null ? void 0 : signal.aborted) throw new NixflexConnectionError("Knowledge polling cancelled; the server job was not cancelled.");
|
|
1282
|
+
if (Date.now() >= end) break;
|
|
1283
|
+
const job = await read(Math.max(1, end - Date.now()));
|
|
1284
|
+
if (["ready", "failed", "cancelled", "deleted", "needs_review"].includes(job.state)) return job;
|
|
1285
|
+
if (n + 1 >= maxAttempts) break;
|
|
1286
|
+
await new Promise((resolve) => {
|
|
1287
|
+
const finish = () => {
|
|
1288
|
+
clearTimeout(timer);
|
|
1289
|
+
signal == null ? void 0 : signal.removeEventListener("abort", finish);
|
|
1290
|
+
resolve();
|
|
1291
|
+
};
|
|
1292
|
+
const timer = setTimeout(finish, Math.min(intervalMs, Math.max(0, end - Date.now())));
|
|
1293
|
+
signal == null ? void 0 : signal.addEventListener("abort", finish, { once: true });
|
|
1294
|
+
});
|
|
1295
|
+
}
|
|
1296
|
+
throw new NixflexConnectionError("Knowledge polling limit reached. Read the job again later; no change was sent.");
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
// src/resources/knowledge.ts
|
|
1300
|
+
var Knowledge = class {
|
|
1301
|
+
constructor(http) {
|
|
1302
|
+
this.http = http;
|
|
1303
|
+
}
|
|
1304
|
+
http;
|
|
1305
|
+
/** DELETE /agents/:target/knowledge-base. Never auto-repeated; use a stable explicit operation key. */
|
|
1306
|
+
deleteScope(target, body, opts) {
|
|
1307
|
+
return this.http.request("DELETE", `/agents/${identifier(target)}/knowledge-base`, body, void 0, writeOptions(opts));
|
|
1308
|
+
}
|
|
1309
|
+
/** GET /agents/:target/knowledge-base. Read result is private customer data. */
|
|
1310
|
+
getScope(target, opts) {
|
|
1311
|
+
return this.http.request("GET", `/agents/${identifier(target)}/knowledge-base`, void 0, void 0, opts);
|
|
1312
|
+
}
|
|
1313
|
+
/** PUT /agents/:target/knowledge-base. Never auto-repeated; use a stable explicit operation key. */
|
|
1314
|
+
putScope(target, body, opts) {
|
|
1315
|
+
return this.http.request("PUT", `/agents/${identifier(target)}/knowledge-base`, body, void 0, writeOptions(opts));
|
|
1316
|
+
}
|
|
1317
|
+
/** POST /agents/:target/knowledge-base/source-measure. Read result is private customer data. */
|
|
1318
|
+
measureSource(target, body, opts) {
|
|
1319
|
+
return this.http.request("POST", `/agents/${identifier(target)}/knowledge-base/source-measure`, body, void 0, opts);
|
|
1320
|
+
}
|
|
1321
|
+
/** POST /agents/:target/knowledge-base/test-sessions. Never auto-repeated; use a stable explicit operation key. */
|
|
1322
|
+
startSession(target, body, opts) {
|
|
1323
|
+
return this.http.request("POST", `/agents/${identifier(target)}/knowledge-base/test-sessions`, body, void 0, writeOptions(opts));
|
|
1324
|
+
}
|
|
1325
|
+
/** GET /knowledge-bases/:kb. Read result is private customer data. */
|
|
1326
|
+
getBase(kb, opts) {
|
|
1327
|
+
return this.http.request("GET", `/knowledge-bases/${identifier(kb)}`, void 0, void 0, opts);
|
|
1328
|
+
}
|
|
1329
|
+
/** DELETE /knowledge-bases/:kb/drafts/:id. Never auto-repeated; use a stable explicit operation key. */
|
|
1330
|
+
discardDraft(kb, id, body, opts) {
|
|
1331
|
+
return this.http.request("DELETE", `/knowledge-bases/${identifier(kb)}/drafts/${identifier(id)}`, body, void 0, writeOptions(opts));
|
|
1332
|
+
}
|
|
1333
|
+
/** GET /knowledge-bases/:kb/drafts/:id. Read result is private customer data. */
|
|
1334
|
+
getDraft(kb, id, opts) {
|
|
1335
|
+
return this.http.request("GET", `/knowledge-bases/${identifier(kb)}/drafts/${identifier(id)}`, void 0, void 0, opts);
|
|
1336
|
+
}
|
|
1337
|
+
/** PATCH /knowledge-bases/:kb/drafts/:id. Never auto-repeated; use a stable explicit operation key. */
|
|
1338
|
+
updateDraft(kb, id, body, opts) {
|
|
1339
|
+
return this.http.request("PATCH", `/knowledge-bases/${identifier(kb)}/drafts/${identifier(id)}`, body, void 0, writeOptions(opts));
|
|
1340
|
+
}
|
|
1341
|
+
/** POST /knowledge-bases/:kb/drafts/:id/accept. Never auto-repeated; use a stable explicit operation key. */
|
|
1342
|
+
acceptDraft(kb, id, body, opts) {
|
|
1343
|
+
return this.http.request("POST", `/knowledge-bases/${identifier(kb)}/drafts/${identifier(id)}/accept`, body, void 0, writeOptions(opts));
|
|
1344
|
+
}
|
|
1345
|
+
/** POST /knowledge-bases/:kb/exports. Never auto-repeated; use a stable explicit operation key. */
|
|
1346
|
+
createExport(kb, body, opts) {
|
|
1347
|
+
return this.http.request("POST", `/knowledge-bases/${identifier(kb)}/exports`, body, void 0, writeOptions(opts));
|
|
1348
|
+
}
|
|
1349
|
+
/** GET /knowledge-bases/:kb/overview. Read result is private customer data. */
|
|
1350
|
+
overview(kb, opts) {
|
|
1351
|
+
return this.http.request("GET", `/knowledge-bases/${identifier(kb)}/overview`, void 0, void 0, opts);
|
|
1352
|
+
}
|
|
1353
|
+
/** PATCH /knowledge-bases/:kb/settings. Never auto-repeated; use a stable explicit operation key. */
|
|
1354
|
+
updateSettings(kb, body, opts) {
|
|
1355
|
+
return this.http.request("PATCH", `/knowledge-bases/${identifier(kb)}/settings`, body, void 0, writeOptions(opts));
|
|
1356
|
+
}
|
|
1357
|
+
/** GET /knowledge-bases/:kb/sources. Read result is private customer data. */
|
|
1358
|
+
listSources(kb, query = {}, opts) {
|
|
1359
|
+
return this.http.request("GET", `/knowledge-bases/${identifier(kb)}/sources`, void 0, { ...query }, opts);
|
|
1360
|
+
}
|
|
1361
|
+
/** POST /knowledge-bases/:kb/sources. Never auto-repeated; use a stable explicit operation key. */
|
|
1362
|
+
addSource(kb, body, opts) {
|
|
1363
|
+
return this.http.request("POST", `/knowledge-bases/${identifier(kb)}/sources`, body, void 0, writeOptions(opts));
|
|
1364
|
+
}
|
|
1365
|
+
/** DELETE /knowledge-bases/:kb/sources/:id. Never auto-repeated; use a stable explicit operation key. */
|
|
1366
|
+
deleteSource(kb, id, body, opts) {
|
|
1367
|
+
return this.http.request("DELETE", `/knowledge-bases/${identifier(kb)}/sources/${identifier(id)}`, body, void 0, writeOptions(opts));
|
|
1368
|
+
}
|
|
1369
|
+
/** PATCH /knowledge-bases/:kb/sources/:id. Never auto-repeated; use a stable explicit operation key. */
|
|
1370
|
+
renameSource(kb, id, body, opts) {
|
|
1371
|
+
return this.http.request("PATCH", `/knowledge-bases/${identifier(kb)}/sources/${identifier(id)}`, body, void 0, writeOptions(opts));
|
|
1372
|
+
}
|
|
1373
|
+
/** POST /knowledge-bases/:kb/sources/:id/replacements. Never auto-repeated; use a stable explicit operation key. */
|
|
1374
|
+
replaceSource(kb, id, body, opts) {
|
|
1375
|
+
return this.http.request("POST", `/knowledge-bases/${identifier(kb)}/sources/${identifier(id)}/replacements`, body, void 0, writeOptions(opts));
|
|
1376
|
+
}
|
|
1377
|
+
/** POST /knowledge-bases/:kb/sources/refresh. Never auto-repeated; use a stable explicit operation key. */
|
|
1378
|
+
refreshSources(kb, body, opts) {
|
|
1379
|
+
return this.http.request("POST", `/knowledge-bases/${identifier(kb)}/sources/refresh`, body, void 0, writeOptions(opts));
|
|
1380
|
+
}
|
|
1381
|
+
/** POST /knowledge-bases/:kb/topic-search. Read result is private customer data. */
|
|
1382
|
+
searchTopics(kb, body, opts) {
|
|
1383
|
+
return this.http.request("POST", `/knowledge-bases/${identifier(kb)}/topic-search`, body, void 0, opts);
|
|
1384
|
+
}
|
|
1385
|
+
/** GET /knowledge-bases/:kb/topics. Read result is private customer data. */
|
|
1386
|
+
listTopics(kb, query = {}, opts) {
|
|
1387
|
+
return this.http.request("GET", `/knowledge-bases/${identifier(kb)}/topics`, void 0, { ...query }, opts);
|
|
1388
|
+
}
|
|
1389
|
+
/** POST /knowledge-bases/:kb/topics. Never auto-repeated; use a stable explicit operation key. */
|
|
1390
|
+
createTopic(kb, body, opts) {
|
|
1391
|
+
return this.http.request("POST", `/knowledge-bases/${identifier(kb)}/topics`, body, void 0, writeOptions(opts));
|
|
1392
|
+
}
|
|
1393
|
+
/** DELETE /knowledge-bases/:kb/topics/:id. Never auto-repeated; use a stable explicit operation key. */
|
|
1394
|
+
deleteTopic(kb, id, body, opts) {
|
|
1395
|
+
return this.http.request("DELETE", `/knowledge-bases/${identifier(kb)}/topics/${identifier(id)}`, body, void 0, writeOptions(opts));
|
|
1396
|
+
}
|
|
1397
|
+
/** GET /knowledge-bases/:kb/topics/:id. Read result is private customer data. */
|
|
1398
|
+
getTopic(kb, id, opts) {
|
|
1399
|
+
return this.http.request("GET", `/knowledge-bases/${identifier(kb)}/topics/${identifier(id)}`, void 0, void 0, opts);
|
|
1400
|
+
}
|
|
1401
|
+
/** PATCH /knowledge-bases/:kb/topics/:id. Never auto-repeated; use a stable explicit operation key. */
|
|
1402
|
+
updateTopic(kb, id, body, opts) {
|
|
1403
|
+
return this.http.request("PATCH", `/knowledge-bases/${identifier(kb)}/topics/${identifier(id)}`, body, void 0, writeOptions(opts));
|
|
1404
|
+
}
|
|
1405
|
+
/** GET /knowledge-bases/:kb/unanswered. Read result is private customer data. */
|
|
1406
|
+
unanswered(kb, query = {}, opts) {
|
|
1407
|
+
return this.http.request("GET", `/knowledge-bases/${identifier(kb)}/unanswered`, void 0, { ...query }, opts);
|
|
1408
|
+
}
|
|
1409
|
+
/** POST /knowledge-bases/:kb/website-discoveries. Never auto-repeated; use a stable explicit operation key. */
|
|
1410
|
+
discoverWebsite(kb, body, opts) {
|
|
1411
|
+
return this.http.request("POST", `/knowledge-bases/${identifier(kb)}/website-discoveries`, body, void 0, writeOptions(opts));
|
|
1412
|
+
}
|
|
1413
|
+
/** POST /knowledge-bases/:kb/website-imports. Never auto-repeated; use a stable explicit operation key. */
|
|
1414
|
+
importWebsite(kb, body, opts) {
|
|
1415
|
+
return this.http.request("POST", `/knowledge-bases/${identifier(kb)}/website-imports`, body, void 0, writeOptions(opts));
|
|
1416
|
+
}
|
|
1417
|
+
/** GET /knowledge/capabilities. Read result is private customer data. */
|
|
1418
|
+
capabilities(opts) {
|
|
1419
|
+
return this.http.request("GET", `/knowledge/capabilities`, void 0, void 0, opts);
|
|
1420
|
+
}
|
|
1421
|
+
/** GET /knowledge/events. Read result is private customer data. */
|
|
1422
|
+
events(query = {}, opts) {
|
|
1423
|
+
return this.http.request("GET", `/knowledge/events`, void 0, { ...query }, opts);
|
|
1424
|
+
}
|
|
1425
|
+
/** GET /knowledge/exports/:id. Read result is private customer data. */
|
|
1426
|
+
downloadExport(id, query = {}, opts) {
|
|
1427
|
+
return this.http.knowledgeDownload(`/knowledge/exports/${identifier(id)}`, { ...query }, opts);
|
|
1428
|
+
}
|
|
1429
|
+
/** GET /knowledge/jobs/:id. Read result is private customer data. */
|
|
1430
|
+
getJob(id, opts) {
|
|
1431
|
+
return this.http.request("GET", `/knowledge/jobs/${identifier(id)}`, void 0, void 0, opts);
|
|
1432
|
+
}
|
|
1433
|
+
/** POST /knowledge/jobs/:id/cancel. Never auto-repeated; use a stable explicit operation key. */
|
|
1434
|
+
cancelJob(id, body, opts) {
|
|
1435
|
+
return this.http.request("POST", `/knowledge/jobs/${identifier(id)}/cancel`, body, void 0, writeOptions(opts));
|
|
1436
|
+
}
|
|
1437
|
+
/** POST /knowledge/jobs/:id/retry. Never auto-repeated; use a stable explicit operation key. */
|
|
1438
|
+
retryJob(id, body, opts) {
|
|
1439
|
+
return this.http.request("POST", `/knowledge/jobs/${identifier(id)}/retry`, body, void 0, writeOptions(opts));
|
|
1440
|
+
}
|
|
1441
|
+
/** GET /knowledge/targets. Read result is private customer data. */
|
|
1442
|
+
targets(query = {}, opts) {
|
|
1443
|
+
return this.http.request("GET", `/knowledge/targets`, void 0, { ...query }, opts);
|
|
1444
|
+
}
|
|
1445
|
+
/** GET /knowledge/test-sessions/:id. Read result is private customer data. */
|
|
1446
|
+
getSession(id, opts) {
|
|
1447
|
+
return this.http.request("GET", `/knowledge/test-sessions/${identifier(id)}`, void 0, void 0, opts);
|
|
1448
|
+
}
|
|
1449
|
+
/** POST /knowledge/test-sessions/:id/cancel. Never auto-repeated; use a stable explicit operation key. */
|
|
1450
|
+
cancelSession(id, body, opts) {
|
|
1451
|
+
return this.http.request("POST", `/knowledge/test-sessions/${identifier(id)}/cancel`, body, void 0, writeOptions(opts));
|
|
1452
|
+
}
|
|
1453
|
+
/** POST /knowledge/test-sessions/:id/messages. Never auto-repeated; use a stable explicit operation key. */
|
|
1454
|
+
ask(id, body, opts) {
|
|
1455
|
+
return this.http.request("POST", `/knowledge/test-sessions/${identifier(id)}/messages`, body, void 0, writeOptions(opts));
|
|
1456
|
+
}
|
|
1457
|
+
/** GET /knowledge/usage. Read result is private customer data. */
|
|
1458
|
+
usage(query = {}, opts) {
|
|
1459
|
+
return this.http.request("GET", `/knowledge/usage`, void 0, { ...query }, opts);
|
|
1460
|
+
}
|
|
1461
|
+
/** GET /agents/:target/knowledge-keyterms. Read result is private customer data. */
|
|
1462
|
+
keyterms(target, opts) {
|
|
1463
|
+
return this.http.request("GET", `/agents/${identifier(target)}/knowledge-keyterms`, void 0, void 0, opts);
|
|
1464
|
+
}
|
|
1465
|
+
uploadSource(kb, file, opts) {
|
|
1466
|
+
return this.http.knowledgeUpload("/knowledge-bases/" + identifier(kb) + "/sources", file, writeOptions(opts));
|
|
1467
|
+
}
|
|
1468
|
+
replaceSourceFile(kb, id, file, opts) {
|
|
1469
|
+
return this.http.knowledgeUpload("/knowledge-bases/" + identifier(kb) + "/sources/" + identifier(id) + "/replacements", file, writeOptions(opts));
|
|
1470
|
+
}
|
|
1471
|
+
measureFile(target, file, opts = {}) {
|
|
1472
|
+
return this.http.knowledgeUpload("/agents/" + identifier(target) + "/knowledge-base/source-measure", file, opts);
|
|
1473
|
+
}
|
|
1474
|
+
waitJob(id, options = {}) {
|
|
1475
|
+
return pollJob((timeoutMs) => this.getJob(id, { timeoutMs, signal: options.signal }), options);
|
|
1476
|
+
}
|
|
1477
|
+
};
|
|
1478
|
+
|
|
1479
|
+
// src/resources/organisation.ts
|
|
1480
|
+
var Organisation = class {
|
|
1481
|
+
constructor(http) {
|
|
1482
|
+
this.http = http;
|
|
1483
|
+
}
|
|
1484
|
+
http;
|
|
1485
|
+
get(opts) {
|
|
1486
|
+
return this.http.request("GET", "/organisation", void 0, void 0, opts);
|
|
1487
|
+
}
|
|
1488
|
+
members(opts) {
|
|
1489
|
+
return this.http.request("GET", "/organisation/members", void 0, void 0, opts);
|
|
1490
|
+
}
|
|
1491
|
+
invite(email, role = "member", opts) {
|
|
1492
|
+
return this.http.request("POST", "/organisation/invites", { email, role }, void 0, opts);
|
|
1493
|
+
}
|
|
1494
|
+
resend(inviteId, opts) {
|
|
1495
|
+
return this.http.request("POST", "/organisation/invites/" + encodeURIComponent(inviteId) + "/resend", void 0, void 0, opts);
|
|
1496
|
+
}
|
|
1497
|
+
revoke(inviteId, opts) {
|
|
1498
|
+
return this.http.request("DELETE", "/organisation/invites/" + encodeURIComponent(inviteId), void 0, void 0, opts);
|
|
1499
|
+
}
|
|
1500
|
+
removeMember(userId, opts) {
|
|
1501
|
+
return this.http.request("DELETE", "/organisation/members/" + encodeURIComponent(userId), void 0, void 0, opts);
|
|
1502
|
+
}
|
|
1503
|
+
setRole(userId, role, opts) {
|
|
1504
|
+
return this.http.request("PATCH", "/organisation/members/" + encodeURIComponent(userId), { role }, void 0, opts);
|
|
1505
|
+
}
|
|
1506
|
+
activity(params = {}, opts) {
|
|
1507
|
+
return this.http.request("GET", "/organisation/activity", void 0, { ...params }, opts);
|
|
1508
|
+
}
|
|
1509
|
+
/** Default JSON page is 50 events. Keep IDs/cursors as strings; from/to are inclusive UTC dates. */
|
|
1510
|
+
activityCsv(params = {}, opts) {
|
|
1511
|
+
return this.http.stream("/organisation/activity", { ...params, format: "csv" }, opts);
|
|
1512
|
+
}
|
|
1513
|
+
/** Owner API-key authority; trims to 2..100 characters on the server. */
|
|
1514
|
+
rename(name, opts) {
|
|
1515
|
+
return this.http.request("PATCH", "/organisation/name", { name }, void 0, opts);
|
|
1516
|
+
}
|
|
1517
|
+
/** Claim an existing API-only account: sends a verified-email invitation, never transfers an owned account. */
|
|
1518
|
+
claimInvite(email, opts) {
|
|
1519
|
+
return this.http.request("POST", "/organisation/claim-invite", { email }, void 0, opts);
|
|
1520
|
+
}
|
|
1521
|
+
};
|
|
1522
|
+
|
|
1523
|
+
// src/resources/core.ts
|
|
1524
|
+
var Account = class {
|
|
1525
|
+
constructor(http) {
|
|
1526
|
+
this.http = http;
|
|
1527
|
+
}
|
|
1528
|
+
http;
|
|
1529
|
+
retention(opts) {
|
|
1530
|
+
return this.http.request("GET", "/account/retention", void 0, void 0, opts);
|
|
1531
|
+
}
|
|
1532
|
+
};
|
|
1533
|
+
var Voices = class {
|
|
1534
|
+
constructor(http) {
|
|
1535
|
+
this.http = http;
|
|
1536
|
+
}
|
|
1537
|
+
http;
|
|
1538
|
+
list(params = {}, opts) {
|
|
1539
|
+
return this.http.request("GET", "/voices", void 0, { ...params }, opts);
|
|
1540
|
+
}
|
|
1541
|
+
get(voiceKey, params = {}, opts) {
|
|
1542
|
+
return this.http.request("GET", `/voices/${encodeURIComponent(voiceKey)}`, void 0, { ...params }, opts);
|
|
1543
|
+
}
|
|
1544
|
+
};
|
|
1545
|
+
|
|
1546
|
+
// src/resources/contacts.ts
|
|
1547
|
+
var Contacts = class {
|
|
1548
|
+
constructor(http) {
|
|
1549
|
+
this.http = http;
|
|
1550
|
+
}
|
|
1551
|
+
http;
|
|
1552
|
+
preview(params, opts) {
|
|
1553
|
+
return this.http.request("POST", "/contact-hours/preview", params, void 0, opts);
|
|
1554
|
+
}
|
|
1555
|
+
list(params = {}, opts) {
|
|
1556
|
+
return this.http.request("GET", "/contact-suppressions", void 0, { ...params }, opts);
|
|
1557
|
+
}
|
|
1558
|
+
add(params, opts) {
|
|
1559
|
+
return this.http.request("POST", "/contact-suppressions", params, void 0, opts);
|
|
1560
|
+
}
|
|
1561
|
+
remove(params, opts) {
|
|
1562
|
+
return this.http.request("DELETE", "/contact-suppressions", params, void 0, opts);
|
|
1563
|
+
}
|
|
1564
|
+
};
|
|
1565
|
+
|
|
1566
|
+
// src/resources/web-agent.ts
|
|
1567
|
+
var WebAgent = class {
|
|
1568
|
+
constructor(http) {
|
|
1569
|
+
this.http = http;
|
|
1570
|
+
}
|
|
1571
|
+
http;
|
|
1572
|
+
get(number, opts) {
|
|
1573
|
+
return this.http.request("GET", `/agent-web/${encodeURIComponent(number)}`, void 0, void 0, opts);
|
|
1574
|
+
}
|
|
1575
|
+
update(number, params, opts) {
|
|
1576
|
+
return this.http.request("PATCH", `/agent-web/${encodeURIComponent(number)}`, params, void 0, opts);
|
|
1577
|
+
}
|
|
1578
|
+
};
|
|
1579
|
+
|
|
1580
|
+
// src/resources/inbox.ts
|
|
1581
|
+
var Inbox = class {
|
|
1582
|
+
constructor(http) {
|
|
1583
|
+
this.http = http;
|
|
1584
|
+
}
|
|
1585
|
+
http;
|
|
1586
|
+
list(channel, number, params = {}, opts) {
|
|
1587
|
+
return this.http.request("GET", `/agent-inbox/${encodeURIComponent(channel)}/${encodeURIComponent(number)}`, void 0, { ...params }, opts);
|
|
1588
|
+
}
|
|
1589
|
+
thread(channel, number, thread, params = {}, opts) {
|
|
1590
|
+
return this.http.request("GET", `/agent-inbox/${encodeURIComponent(channel)}/${encodeURIComponent(number)}/thread/${encodeURIComponent(thread)}`, void 0, { ...params }, opts);
|
|
1591
|
+
}
|
|
1592
|
+
update(channel, number, thread, params, opts) {
|
|
1593
|
+
return this.http.request("PATCH", `/agent-inbox/${encodeURIComponent(channel)}/${encodeURIComponent(number)}/thread/${encodeURIComponent(thread)}`, params, void 0, opts);
|
|
1594
|
+
}
|
|
1595
|
+
features(opts) {
|
|
1596
|
+
return this.http.request("GET", "/agent-inbox/features", void 0, void 0, opts);
|
|
1597
|
+
}
|
|
1598
|
+
numbers(params = {}, opts) {
|
|
1599
|
+
return this.http.request("GET", "/agent-inbox/numbers", void 0, { ...params }, opts);
|
|
1600
|
+
}
|
|
1601
|
+
retention(params = {}, opts) {
|
|
1602
|
+
return this.http.request("GET", "/agent-inbox/retention", void 0, { ...params }, opts);
|
|
1603
|
+
}
|
|
1604
|
+
};
|
|
1605
|
+
|
|
556
1606
|
// src/index.ts
|
|
557
1607
|
var Nixflex = class {
|
|
1608
|
+
inbox;
|
|
1609
|
+
webAgent;
|
|
1610
|
+
contacts;
|
|
1611
|
+
account;
|
|
1612
|
+
voices;
|
|
1613
|
+
organisation;
|
|
1614
|
+
integrations;
|
|
1615
|
+
knowledge;
|
|
558
1616
|
/** AI agents - create, list, get, update, delete. */
|
|
559
1617
|
agents;
|
|
560
1618
|
/** Calls - trigger outbound, list history, fetch transcripts + analysis. */
|
|
@@ -571,16 +1629,18 @@ var Nixflex = class {
|
|
|
571
1629
|
usage;
|
|
572
1630
|
/** Per-number post-call webhook configuration. */
|
|
573
1631
|
webhooks;
|
|
574
|
-
/** Your own S3-compatible recording storage (data residency). */
|
|
575
|
-
storage;
|
|
576
|
-
/** Your own LLM (OpenAI-compatible endpoint, verified with tool-calling probe). */
|
|
577
|
-
llm;
|
|
578
|
-
/** Your own TTS (elevenlabs/cartesia, verified with a real synthesis). */
|
|
579
|
-
tts;
|
|
580
1632
|
/** Caller context - what the agent knows about each caller on one of your numbers. */
|
|
581
1633
|
callers;
|
|
582
1634
|
constructor(options) {
|
|
583
1635
|
const http = new HttpClient(options);
|
|
1636
|
+
this.inbox = new Inbox(http);
|
|
1637
|
+
this.webAgent = new WebAgent(http);
|
|
1638
|
+
this.contacts = new Contacts(http);
|
|
1639
|
+
this.account = new Account(http);
|
|
1640
|
+
this.voices = new Voices(http);
|
|
1641
|
+
this.organisation = new Organisation(http);
|
|
1642
|
+
this.integrations = new Integrations(http);
|
|
1643
|
+
this.knowledge = new Knowledge(http);
|
|
584
1644
|
this.agents = new Agents(http);
|
|
585
1645
|
this.calls = new Calls(http);
|
|
586
1646
|
this.campaigns = new Campaigns(http);
|
|
@@ -589,44 +1649,46 @@ var Nixflex = class {
|
|
|
589
1649
|
this.keys = new Keys(http);
|
|
590
1650
|
this.usage = new UsageResource(http);
|
|
591
1651
|
this.webhooks = new Webhooks(http);
|
|
592
|
-
this.storage = new Storage(http);
|
|
593
|
-
this.llm = new Llm(http);
|
|
594
|
-
this.tts = new Tts(http);
|
|
595
1652
|
this.callers = new Callers(http);
|
|
596
1653
|
}
|
|
597
1654
|
/** Create a brand-new API key (unauthenticated signup endpoint - most
|
|
598
1655
|
* developers use the dashboard instead). The key_secret is shown ONCE.
|
|
599
1656
|
* Rate-limited per IP to prevent abuse. */
|
|
600
1657
|
static async createKey(params = {}, baseUrl = "https://api.nixflex.com") {
|
|
601
|
-
|
|
602
|
-
method: "POST",
|
|
603
|
-
headers: { "Content-Type": "application/json" },
|
|
604
|
-
body: JSON.stringify(params)
|
|
605
|
-
});
|
|
606
|
-
const body = await res.json();
|
|
607
|
-
if (!res.ok) {
|
|
608
|
-
throw errorFromResponse(
|
|
609
|
-
res.status,
|
|
610
|
-
body,
|
|
611
|
-
res.headers.get("x-railway-request-id") || void 0,
|
|
612
|
-
parseInt(res.headers.get("retry-after") || "0", 10) || 0
|
|
613
|
-
);
|
|
614
|
-
}
|
|
615
|
-
return body;
|
|
1658
|
+
return createKey(params, baseUrl);
|
|
616
1659
|
}
|
|
617
1660
|
};
|
|
618
1661
|
var src_default = Nixflex;
|
|
619
1662
|
export {
|
|
1663
|
+
HttpClient,
|
|
620
1664
|
Nixflex,
|
|
621
1665
|
NixflexAuthenticationError,
|
|
1666
|
+
NixflexCalendarError,
|
|
1667
|
+
NixflexCallBookingsUnavailableError,
|
|
1668
|
+
NixflexConflictError,
|
|
622
1669
|
NixflexConnectionError,
|
|
1670
|
+
NixflexCredentialError,
|
|
1671
|
+
NixflexDoNotContactError,
|
|
623
1672
|
NixflexError,
|
|
624
1673
|
NixflexInvalidRequestError,
|
|
625
1674
|
NixflexNotFoundError,
|
|
1675
|
+
NixflexOutboundRequestError,
|
|
1676
|
+
NixflexOutboundRequestPendingError,
|
|
1677
|
+
NixflexOutboundRequestUnavailableError,
|
|
1678
|
+
NixflexOutboundRequestUnknownError,
|
|
1679
|
+
NixflexOutcomeUnknownError,
|
|
626
1680
|
NixflexPaymentRequiredError,
|
|
627
1681
|
NixflexRateLimitError,
|
|
1682
|
+
NixflexRequestIdConflictError,
|
|
628
1683
|
NixflexServerError,
|
|
1684
|
+
Organisation,
|
|
1685
|
+
SDK_VERSION,
|
|
1686
|
+
calendarErrorCodes,
|
|
1687
|
+
credentialErrorCodes,
|
|
629
1688
|
src_default as default,
|
|
630
1689
|
errorFromResponse,
|
|
1690
|
+
featureError,
|
|
1691
|
+
outboundRequestError,
|
|
1692
|
+
prepareOutboundCall,
|
|
631
1693
|
verifyWebhookSignature
|
|
632
1694
|
};
|