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