nixflex 0.1.0 → 0.2.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/LICENSE +21 -0
- package/README.md +37 -0
- package/dist/index.cjs +47 -2
- package/dist/index.d.cts +32 -1
- package/dist/index.d.ts +32 -1
- package/dist/index.js +45 -1
- package/package.json +34 -8
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nixflex
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -75,6 +75,43 @@ try {
|
|
|
75
75
|
- **Timeouts + AbortSignal support** per client or per request
|
|
76
76
|
- **Zero runtime dependencies** — native fetch, Node 18+
|
|
77
77
|
|
|
78
|
+
## Verifying webhooks
|
|
79
|
+
|
|
80
|
+
Nixflex signs every webhook delivery with an `X-Nixflex-Signature` header. Verify it before trusting a payload — pass the **raw** request body, not a re-serialized object:
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
import express from 'express';
|
|
84
|
+
import { verifyWebhookSignature } from 'nixflex';
|
|
85
|
+
|
|
86
|
+
const app = express();
|
|
87
|
+
|
|
88
|
+
app.post('/nixflex/calls', express.raw({ type: 'application/json' }), (req, res) => {
|
|
89
|
+
const ok = verifyWebhookSignature(
|
|
90
|
+
req.body, // raw Buffer
|
|
91
|
+
req.get('x-nixflex-signature'),
|
|
92
|
+
process.env.NIXFLEX_KEY_SECRET // the nxfs_... half of your key
|
|
93
|
+
);
|
|
94
|
+
if (!ok) return res.sendStatus(400);
|
|
95
|
+
|
|
96
|
+
const event = JSON.parse(req.body.toString('utf8'));
|
|
97
|
+
// handle event.event === 'call.completed'
|
|
98
|
+
res.sendStatus(200);
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Returns `false` for a tampered body, wrong secret, malformed header, or a signature older than the tolerance window (300 seconds; override with `{ toleranceSeconds }`). It never throws.
|
|
103
|
+
|
|
104
|
+
## Deleting call data
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
await client.calls.delete(callId); // one call: record, transcript, recording
|
|
108
|
+
await client.calls.deleteAll(); // everything on the key
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Both are immediate and irreversible — fetch anything you need to keep first.
|
|
112
|
+
|
|
78
113
|
## Docs
|
|
79
114
|
|
|
80
115
|
Full API reference: **https://docs.nixflex.com**
|
|
116
|
+
|
|
117
|
+
Release history: [CHANGELOG.md](CHANGELOG.md). Licensed under [MIT](LICENSE).
|
package/dist/index.cjs
CHANGED
|
@@ -29,7 +29,8 @@ __export(index_exports, {
|
|
|
29
29
|
NixflexRateLimitError: () => NixflexRateLimitError,
|
|
30
30
|
NixflexServerError: () => NixflexServerError,
|
|
31
31
|
default: () => index_default,
|
|
32
|
-
errorFromResponse: () => errorFromResponse
|
|
32
|
+
errorFromResponse: () => errorFromResponse,
|
|
33
|
+
verifyWebhookSignature: () => verifyWebhookSignature
|
|
33
34
|
});
|
|
34
35
|
module.exports = __toCommonJS(index_exports);
|
|
35
36
|
|
|
@@ -285,6 +286,16 @@ var Calls = class {
|
|
|
285
286
|
get(callId, opts) {
|
|
286
287
|
return this.http.request("GET", `/calls/${encodeURIComponent(callId)}`, void 0, void 0, opts);
|
|
287
288
|
}
|
|
289
|
+
/** GDPR: PERMANENTLY erase one call - the record AND its recording file.
|
|
290
|
+
* Irreversible. Throws NixflexNotFoundError if the ID is not yours. */
|
|
291
|
+
delete(callId, opts) {
|
|
292
|
+
return this.http.request("DELETE", `/calls/${encodeURIComponent(callId)}`, void 0, void 0, opts);
|
|
293
|
+
}
|
|
294
|
+
/** GDPR: PERMANENTLY erase ALL calls, recordings, and SMS messages on this
|
|
295
|
+
* key. Irreversible - intended for data-erasure requests and offboarding. */
|
|
296
|
+
deleteAll(opts) {
|
|
297
|
+
return this.http.request("DELETE", "/calls", void 0, void 0, opts);
|
|
298
|
+
}
|
|
288
299
|
};
|
|
289
300
|
var Campaigns = class {
|
|
290
301
|
constructor(http) {
|
|
@@ -306,6 +317,33 @@ var Campaigns = class {
|
|
|
306
317
|
}
|
|
307
318
|
};
|
|
308
319
|
|
|
320
|
+
// src/webhook-verify.ts
|
|
321
|
+
var import_node_crypto = require("crypto");
|
|
322
|
+
function verifyWebhookSignature(rawBody, signatureHeader, keySecret, options = {}) {
|
|
323
|
+
try {
|
|
324
|
+
if (!signatureHeader || !keySecret) return false;
|
|
325
|
+
const parts = {};
|
|
326
|
+
for (const seg of signatureHeader.split(",")) {
|
|
327
|
+
const i = seg.indexOf("=");
|
|
328
|
+
if (i > 0) parts[seg.slice(0, i).trim()] = seg.slice(i + 1).trim();
|
|
329
|
+
}
|
|
330
|
+
const t = parseInt(parts["t"] || "", 10);
|
|
331
|
+
const v1 = parts["v1"] || "";
|
|
332
|
+
if (!isFinite(t) || !/^[0-9a-f]{64}$/.test(v1)) return false;
|
|
333
|
+
const tolerance = options.toleranceSeconds ?? 300;
|
|
334
|
+
const now = options.now ?? Math.floor(Date.now() / 1e3);
|
|
335
|
+
if (Math.abs(now - t) > tolerance) return false;
|
|
336
|
+
const body = typeof rawBody === "string" ? rawBody : rawBody.toString("utf8");
|
|
337
|
+
const expected = (0, import_node_crypto.createHmac)("sha256", keySecret).update(t + "." + body).digest("hex");
|
|
338
|
+
const a = Buffer.from(expected, "hex");
|
|
339
|
+
const b = Buffer.from(v1, "hex");
|
|
340
|
+
if (a.length !== b.length) return false;
|
|
341
|
+
return (0, import_node_crypto.timingSafeEqual)(a, b);
|
|
342
|
+
} catch {
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
309
347
|
// src/resources/stage3.ts
|
|
310
348
|
function enc(phoneNumber) {
|
|
311
349
|
return encodeURIComponent(phoneNumber);
|
|
@@ -432,6 +470,12 @@ var Webhooks = class {
|
|
|
432
470
|
this.http = http;
|
|
433
471
|
}
|
|
434
472
|
http;
|
|
473
|
+
/** Verify a webhook delivery's X-Nixflex-Signature header. Pass the RAW
|
|
474
|
+
* request body (string or Buffer) and your key_secret. Returns true only
|
|
475
|
+
* for an authentic, fresh signature. See webhook-verify.ts. */
|
|
476
|
+
verify(rawBody, signatureHeader, keySecret, options) {
|
|
477
|
+
return verifyWebhookSignature(rawBody, signatureHeader, keySecret, options);
|
|
478
|
+
}
|
|
435
479
|
/** Point a number's post-call events at your HTTPS endpoint.
|
|
436
480
|
* slot 2 = the second destination (webhook2). */
|
|
437
481
|
set(phoneNumber, url, slot = 1, opts) {
|
|
@@ -512,5 +556,6 @@ var index_default = Nixflex;
|
|
|
512
556
|
NixflexPaymentRequiredError,
|
|
513
557
|
NixflexRateLimitError,
|
|
514
558
|
NixflexServerError,
|
|
515
|
-
errorFromResponse
|
|
559
|
+
errorFromResponse,
|
|
560
|
+
verifyWebhookSignature
|
|
516
561
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -281,6 +281,18 @@ interface BatchLaunchResponse {
|
|
|
281
281
|
recipients_count: number;
|
|
282
282
|
queued_count: number;
|
|
283
283
|
}
|
|
284
|
+
interface CallDeleteResponse {
|
|
285
|
+
call_id: string;
|
|
286
|
+
deleted: boolean;
|
|
287
|
+
/** Whether a recording file was found and removed from storage. */
|
|
288
|
+
recording_deleted: boolean;
|
|
289
|
+
}
|
|
290
|
+
interface CallDeleteAllResponse {
|
|
291
|
+
deleted: boolean;
|
|
292
|
+
calls_deleted: number;
|
|
293
|
+
recordings_deleted: number;
|
|
294
|
+
sms_deleted: number;
|
|
295
|
+
}
|
|
284
296
|
|
|
285
297
|
declare class Calls {
|
|
286
298
|
private readonly http;
|
|
@@ -302,6 +314,12 @@ declare class Calls {
|
|
|
302
314
|
* excluded, so it will not equal end_timestamp - start_timestamp on
|
|
303
315
|
* outbound calls. */
|
|
304
316
|
get(callId: string, opts?: RequestOptions): Promise<Call>;
|
|
317
|
+
/** GDPR: PERMANENTLY erase one call - the record AND its recording file.
|
|
318
|
+
* Irreversible. Throws NixflexNotFoundError if the ID is not yours. */
|
|
319
|
+
delete(callId: string, opts?: RequestOptions): Promise<CallDeleteResponse>;
|
|
320
|
+
/** GDPR: PERMANENTLY erase ALL calls, recordings, and SMS messages on this
|
|
321
|
+
* key. Irreversible - intended for data-erasure requests and offboarding. */
|
|
322
|
+
deleteAll(opts?: RequestOptions): Promise<CallDeleteAllResponse>;
|
|
305
323
|
}
|
|
306
324
|
|
|
307
325
|
declare class Campaigns {
|
|
@@ -318,6 +336,15 @@ declare class Campaigns {
|
|
|
318
336
|
launch(campaignId: string, opts?: RequestOptions): Promise<BatchLaunchResponse>;
|
|
319
337
|
}
|
|
320
338
|
|
|
339
|
+
interface VerifyOptions {
|
|
340
|
+
/** Max allowed age of the signature in seconds (replay protection). Default 300. */
|
|
341
|
+
toleranceSeconds?: number;
|
|
342
|
+
/** Override "now" (unix seconds) - for testing. */
|
|
343
|
+
now?: number;
|
|
344
|
+
}
|
|
345
|
+
/** Returns true only if the signature is authentic AND fresh. Never throws. */
|
|
346
|
+
declare function verifyWebhookSignature(rawBody: string | Buffer, signatureHeader: string | null | undefined, keySecret: string, options?: VerifyOptions): boolean;
|
|
347
|
+
|
|
321
348
|
/** Import params - the carrier is INFERRED from which credentials you send.
|
|
322
349
|
* Twilio: twilio_sid + twilio_token. Telnyx: telnyx_api_key + telnyx_connection_id
|
|
323
350
|
* (the ID of a TeXML Application you created in your Telnyx portal, voice webhook
|
|
@@ -609,6 +636,10 @@ declare class UsageResource {
|
|
|
609
636
|
declare class Webhooks {
|
|
610
637
|
private readonly http;
|
|
611
638
|
constructor(http: HttpClient);
|
|
639
|
+
/** Verify a webhook delivery's X-Nixflex-Signature header. Pass the RAW
|
|
640
|
+
* request body (string or Buffer) and your key_secret. Returns true only
|
|
641
|
+
* for an authentic, fresh signature. See webhook-verify.ts. */
|
|
642
|
+
verify(rawBody: string | Buffer, signatureHeader: string | null | undefined, keySecret: string, options?: VerifyOptions): boolean;
|
|
612
643
|
/** Point a number's post-call events at your HTTPS endpoint.
|
|
613
644
|
* slot 2 = the second destination (webhook2). */
|
|
614
645
|
set(phoneNumber: string, url: string, slot?: 1 | 2, opts?: RequestOptions): Promise<WebhookConfigResponse>;
|
|
@@ -701,4 +732,4 @@ declare class Nixflex {
|
|
|
701
732
|
}, baseUrl?: string): Promise<KeyCreateResponse>;
|
|
702
733
|
}
|
|
703
734
|
|
|
704
|
-
export { type Agent, type AgentCreateParams, type AgentDeleteResponse, type AgentUpdateParams, type BatchCampaignParams, type BatchCreateResponse, type BatchInvalidEntry, type BatchLaunchResponse, type BatchRecipient, type Call, type CallDirection, type CallerSentiment, type KeyCreateResponse, type KeyRotateResponse, type ListParams, type MonitorToggleResponse, Nixflex, type NixflexAPIErrorBody, NixflexAuthenticationError, type NixflexClientOptions, NixflexConnectionError, NixflexError, NixflexInvalidRequestError, NixflexNotFoundError, NixflexPaymentRequiredError, NixflexRateLimitError, NixflexServerError, type OutboundCallParams, type OutboundCallResponse, type PhoneNumber, type PhoneNumberDeleteResponse, type PhoneNumberImportParams, type PhoneNumberListResponse, type PhoneNumberUpdateParams, type RequestOptions, type ResponseLength, type SmsCampaign, type SmsCampaignCreateParams, type SmsCampaignDeleteResponse, type SmsCampaignLaunchResponse, type SmsCampaignListResponse, type SmsCampaignRecipient, type SmsCampaignStatus, type SmsSendParams, type SmsSendResponse, type TransferType, type Usage, type WebCallsToggleResponse, type WebhookConfigResponse, type Weekday, Nixflex as default, errorFromResponse };
|
|
735
|
+
export { type Agent, type AgentCreateParams, type AgentDeleteResponse, type AgentUpdateParams, type BatchCampaignParams, type BatchCreateResponse, type BatchInvalidEntry, type BatchLaunchResponse, type BatchRecipient, type Call, type CallDeleteAllResponse, type CallDeleteResponse, type CallDirection, type CallerSentiment, type KeyCreateResponse, type KeyRotateResponse, type ListParams, type MonitorToggleResponse, Nixflex, type NixflexAPIErrorBody, NixflexAuthenticationError, type NixflexClientOptions, NixflexConnectionError, NixflexError, NixflexInvalidRequestError, NixflexNotFoundError, NixflexPaymentRequiredError, NixflexRateLimitError, NixflexServerError, type OutboundCallParams, type OutboundCallResponse, type PhoneNumber, type PhoneNumberDeleteResponse, type PhoneNumberImportParams, type PhoneNumberListResponse, type PhoneNumberUpdateParams, type RequestOptions, type ResponseLength, type SmsCampaign, type SmsCampaignCreateParams, type SmsCampaignDeleteResponse, type SmsCampaignLaunchResponse, type SmsCampaignListResponse, type SmsCampaignRecipient, type SmsCampaignStatus, type SmsSendParams, type SmsSendResponse, type TransferType, type Usage, type VerifyOptions, type WebCallsToggleResponse, type WebhookConfigResponse, type Weekday, Nixflex as default, errorFromResponse, verifyWebhookSignature };
|
package/dist/index.d.ts
CHANGED
|
@@ -281,6 +281,18 @@ interface BatchLaunchResponse {
|
|
|
281
281
|
recipients_count: number;
|
|
282
282
|
queued_count: number;
|
|
283
283
|
}
|
|
284
|
+
interface CallDeleteResponse {
|
|
285
|
+
call_id: string;
|
|
286
|
+
deleted: boolean;
|
|
287
|
+
/** Whether a recording file was found and removed from storage. */
|
|
288
|
+
recording_deleted: boolean;
|
|
289
|
+
}
|
|
290
|
+
interface CallDeleteAllResponse {
|
|
291
|
+
deleted: boolean;
|
|
292
|
+
calls_deleted: number;
|
|
293
|
+
recordings_deleted: number;
|
|
294
|
+
sms_deleted: number;
|
|
295
|
+
}
|
|
284
296
|
|
|
285
297
|
declare class Calls {
|
|
286
298
|
private readonly http;
|
|
@@ -302,6 +314,12 @@ declare class Calls {
|
|
|
302
314
|
* excluded, so it will not equal end_timestamp - start_timestamp on
|
|
303
315
|
* outbound calls. */
|
|
304
316
|
get(callId: string, opts?: RequestOptions): Promise<Call>;
|
|
317
|
+
/** GDPR: PERMANENTLY erase one call - the record AND its recording file.
|
|
318
|
+
* Irreversible. Throws NixflexNotFoundError if the ID is not yours. */
|
|
319
|
+
delete(callId: string, opts?: RequestOptions): Promise<CallDeleteResponse>;
|
|
320
|
+
/** GDPR: PERMANENTLY erase ALL calls, recordings, and SMS messages on this
|
|
321
|
+
* key. Irreversible - intended for data-erasure requests and offboarding. */
|
|
322
|
+
deleteAll(opts?: RequestOptions): Promise<CallDeleteAllResponse>;
|
|
305
323
|
}
|
|
306
324
|
|
|
307
325
|
declare class Campaigns {
|
|
@@ -318,6 +336,15 @@ declare class Campaigns {
|
|
|
318
336
|
launch(campaignId: string, opts?: RequestOptions): Promise<BatchLaunchResponse>;
|
|
319
337
|
}
|
|
320
338
|
|
|
339
|
+
interface VerifyOptions {
|
|
340
|
+
/** Max allowed age of the signature in seconds (replay protection). Default 300. */
|
|
341
|
+
toleranceSeconds?: number;
|
|
342
|
+
/** Override "now" (unix seconds) - for testing. */
|
|
343
|
+
now?: number;
|
|
344
|
+
}
|
|
345
|
+
/** Returns true only if the signature is authentic AND fresh. Never throws. */
|
|
346
|
+
declare function verifyWebhookSignature(rawBody: string | Buffer, signatureHeader: string | null | undefined, keySecret: string, options?: VerifyOptions): boolean;
|
|
347
|
+
|
|
321
348
|
/** Import params - the carrier is INFERRED from which credentials you send.
|
|
322
349
|
* Twilio: twilio_sid + twilio_token. Telnyx: telnyx_api_key + telnyx_connection_id
|
|
323
350
|
* (the ID of a TeXML Application you created in your Telnyx portal, voice webhook
|
|
@@ -609,6 +636,10 @@ declare class UsageResource {
|
|
|
609
636
|
declare class Webhooks {
|
|
610
637
|
private readonly http;
|
|
611
638
|
constructor(http: HttpClient);
|
|
639
|
+
/** Verify a webhook delivery's X-Nixflex-Signature header. Pass the RAW
|
|
640
|
+
* request body (string or Buffer) and your key_secret. Returns true only
|
|
641
|
+
* for an authentic, fresh signature. See webhook-verify.ts. */
|
|
642
|
+
verify(rawBody: string | Buffer, signatureHeader: string | null | undefined, keySecret: string, options?: VerifyOptions): boolean;
|
|
612
643
|
/** Point a number's post-call events at your HTTPS endpoint.
|
|
613
644
|
* slot 2 = the second destination (webhook2). */
|
|
614
645
|
set(phoneNumber: string, url: string, slot?: 1 | 2, opts?: RequestOptions): Promise<WebhookConfigResponse>;
|
|
@@ -701,4 +732,4 @@ declare class Nixflex {
|
|
|
701
732
|
}, baseUrl?: string): Promise<KeyCreateResponse>;
|
|
702
733
|
}
|
|
703
734
|
|
|
704
|
-
export { type Agent, type AgentCreateParams, type AgentDeleteResponse, type AgentUpdateParams, type BatchCampaignParams, type BatchCreateResponse, type BatchInvalidEntry, type BatchLaunchResponse, type BatchRecipient, type Call, type CallDirection, type CallerSentiment, type KeyCreateResponse, type KeyRotateResponse, type ListParams, type MonitorToggleResponse, Nixflex, type NixflexAPIErrorBody, NixflexAuthenticationError, type NixflexClientOptions, NixflexConnectionError, NixflexError, NixflexInvalidRequestError, NixflexNotFoundError, NixflexPaymentRequiredError, NixflexRateLimitError, NixflexServerError, type OutboundCallParams, type OutboundCallResponse, type PhoneNumber, type PhoneNumberDeleteResponse, type PhoneNumberImportParams, type PhoneNumberListResponse, type PhoneNumberUpdateParams, type RequestOptions, type ResponseLength, type SmsCampaign, type SmsCampaignCreateParams, type SmsCampaignDeleteResponse, type SmsCampaignLaunchResponse, type SmsCampaignListResponse, type SmsCampaignRecipient, type SmsCampaignStatus, type SmsSendParams, type SmsSendResponse, type TransferType, type Usage, type WebCallsToggleResponse, type WebhookConfigResponse, type Weekday, Nixflex as default, errorFromResponse };
|
|
735
|
+
export { type Agent, type AgentCreateParams, type AgentDeleteResponse, type AgentUpdateParams, type BatchCampaignParams, type BatchCreateResponse, type BatchInvalidEntry, type BatchLaunchResponse, type BatchRecipient, type Call, type CallDeleteAllResponse, type CallDeleteResponse, type CallDirection, type CallerSentiment, type KeyCreateResponse, type KeyRotateResponse, type ListParams, type MonitorToggleResponse, Nixflex, type NixflexAPIErrorBody, NixflexAuthenticationError, type NixflexClientOptions, NixflexConnectionError, NixflexError, NixflexInvalidRequestError, NixflexNotFoundError, NixflexPaymentRequiredError, NixflexRateLimitError, NixflexServerError, type OutboundCallParams, type OutboundCallResponse, type PhoneNumber, type PhoneNumberDeleteResponse, type PhoneNumberImportParams, type PhoneNumberListResponse, type PhoneNumberUpdateParams, type RequestOptions, type ResponseLength, type SmsCampaign, type SmsCampaignCreateParams, type SmsCampaignDeleteResponse, type SmsCampaignLaunchResponse, type SmsCampaignListResponse, type SmsCampaignRecipient, type SmsCampaignStatus, type SmsSendParams, type SmsSendResponse, type TransferType, type Usage, type VerifyOptions, type WebCallsToggleResponse, type WebhookConfigResponse, type Weekday, Nixflex as default, errorFromResponse, verifyWebhookSignature };
|
package/dist/index.js
CHANGED
|
@@ -250,6 +250,16 @@ var Calls = class {
|
|
|
250
250
|
get(callId, opts) {
|
|
251
251
|
return this.http.request("GET", `/calls/${encodeURIComponent(callId)}`, void 0, void 0, opts);
|
|
252
252
|
}
|
|
253
|
+
/** GDPR: PERMANENTLY erase one call - the record AND its recording file.
|
|
254
|
+
* Irreversible. Throws NixflexNotFoundError if the ID is not yours. */
|
|
255
|
+
delete(callId, opts) {
|
|
256
|
+
return this.http.request("DELETE", `/calls/${encodeURIComponent(callId)}`, void 0, void 0, opts);
|
|
257
|
+
}
|
|
258
|
+
/** GDPR: PERMANENTLY erase ALL calls, recordings, and SMS messages on this
|
|
259
|
+
* key. Irreversible - intended for data-erasure requests and offboarding. */
|
|
260
|
+
deleteAll(opts) {
|
|
261
|
+
return this.http.request("DELETE", "/calls", void 0, void 0, opts);
|
|
262
|
+
}
|
|
253
263
|
};
|
|
254
264
|
var Campaigns = class {
|
|
255
265
|
constructor(http) {
|
|
@@ -271,6 +281,33 @@ var Campaigns = class {
|
|
|
271
281
|
}
|
|
272
282
|
};
|
|
273
283
|
|
|
284
|
+
// src/webhook-verify.ts
|
|
285
|
+
import { createHmac, timingSafeEqual } from "crypto";
|
|
286
|
+
function verifyWebhookSignature(rawBody, signatureHeader, keySecret, options = {}) {
|
|
287
|
+
try {
|
|
288
|
+
if (!signatureHeader || !keySecret) return false;
|
|
289
|
+
const parts = {};
|
|
290
|
+
for (const seg of signatureHeader.split(",")) {
|
|
291
|
+
const i = seg.indexOf("=");
|
|
292
|
+
if (i > 0) parts[seg.slice(0, i).trim()] = seg.slice(i + 1).trim();
|
|
293
|
+
}
|
|
294
|
+
const t = parseInt(parts["t"] || "", 10);
|
|
295
|
+
const v1 = parts["v1"] || "";
|
|
296
|
+
if (!isFinite(t) || !/^[0-9a-f]{64}$/.test(v1)) return false;
|
|
297
|
+
const tolerance = options.toleranceSeconds ?? 300;
|
|
298
|
+
const now = options.now ?? Math.floor(Date.now() / 1e3);
|
|
299
|
+
if (Math.abs(now - t) > tolerance) return false;
|
|
300
|
+
const body = typeof rawBody === "string" ? rawBody : rawBody.toString("utf8");
|
|
301
|
+
const expected = createHmac("sha256", keySecret).update(t + "." + body).digest("hex");
|
|
302
|
+
const a = Buffer.from(expected, "hex");
|
|
303
|
+
const b = Buffer.from(v1, "hex");
|
|
304
|
+
if (a.length !== b.length) return false;
|
|
305
|
+
return timingSafeEqual(a, b);
|
|
306
|
+
} catch {
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
274
311
|
// src/resources/stage3.ts
|
|
275
312
|
function enc(phoneNumber) {
|
|
276
313
|
return encodeURIComponent(phoneNumber);
|
|
@@ -397,6 +434,12 @@ var Webhooks = class {
|
|
|
397
434
|
this.http = http;
|
|
398
435
|
}
|
|
399
436
|
http;
|
|
437
|
+
/** Verify a webhook delivery's X-Nixflex-Signature header. Pass the RAW
|
|
438
|
+
* request body (string or Buffer) and your key_secret. Returns true only
|
|
439
|
+
* for an authentic, fresh signature. See webhook-verify.ts. */
|
|
440
|
+
verify(rawBody, signatureHeader, keySecret, options) {
|
|
441
|
+
return verifyWebhookSignature(rawBody, signatureHeader, keySecret, options);
|
|
442
|
+
}
|
|
400
443
|
/** Point a number's post-call events at your HTTPS endpoint.
|
|
401
444
|
* slot 2 = the second destination (webhook2). */
|
|
402
445
|
set(phoneNumber, url, slot = 1, opts) {
|
|
@@ -477,5 +520,6 @@ export {
|
|
|
477
520
|
NixflexRateLimitError,
|
|
478
521
|
NixflexServerError,
|
|
479
522
|
index_default as default,
|
|
480
|
-
errorFromResponse
|
|
523
|
+
errorFromResponse,
|
|
524
|
+
verifyWebhookSignature
|
|
481
525
|
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nixflex",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Official Node.js SDK for the Nixflex voice AI platform - AI phone agents, outbound campaigns, and SMS.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
"keywords": [
|
|
6
|
+
"nixflex",
|
|
7
|
+
"voice-ai",
|
|
8
|
+
"voice-agent",
|
|
9
|
+
"phone",
|
|
10
|
+
"telephony",
|
|
11
|
+
"ai-receptionist",
|
|
12
|
+
"twilio",
|
|
13
|
+
"telnyx",
|
|
14
|
+
"sms",
|
|
15
|
+
"speech",
|
|
16
|
+
"api-client",
|
|
17
|
+
"sdk"
|
|
18
|
+
],
|
|
19
|
+
"homepage": "https://github.com/nixflex/nixflex-node#readme",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/nixflex/nixflex-node/issues"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/nixflex/nixflex-node.git"
|
|
26
|
+
},
|
|
9
27
|
"license": "MIT",
|
|
10
28
|
"type": "module",
|
|
11
29
|
"main": "./dist/index.cjs",
|
|
@@ -18,15 +36,23 @@
|
|
|
18
36
|
"require": "./dist/index.cjs"
|
|
19
37
|
}
|
|
20
38
|
},
|
|
21
|
-
"files": [
|
|
22
|
-
|
|
39
|
+
"files": [
|
|
40
|
+
"dist",
|
|
41
|
+
"README.md",
|
|
42
|
+
"LICENSE"
|
|
43
|
+
],
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=18"
|
|
46
|
+
},
|
|
23
47
|
"scripts": {
|
|
24
48
|
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
25
49
|
"check": "node --test tests/*.test.cjs",
|
|
26
50
|
"prepublishOnly": "npm run build && npm run check"
|
|
27
51
|
},
|
|
28
52
|
"devDependencies": {
|
|
53
|
+
"@types/node": "^26.2.0",
|
|
29
54
|
"tsup": "^8.0.0",
|
|
30
55
|
"typescript": "^5.4.0"
|
|
31
|
-
}
|
|
56
|
+
},
|
|
57
|
+
"author": "Nixflex"
|
|
32
58
|
}
|