av6-core 1.5.9 → 1.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +36 -12
- package/dist/index.mjs +36 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2447,6 +2447,10 @@ var EmailProvider = class {
|
|
|
2447
2447
|
};
|
|
2448
2448
|
|
|
2449
2449
|
// src/providers/sms.provider.ts
|
|
2450
|
+
var import_axios2 = __toESM(require("axios"));
|
|
2451
|
+
var import_node_https = __toESM(require("https"));
|
|
2452
|
+
var import_promises = __toESM(require("dns/promises"));
|
|
2453
|
+
var import_node_url = require("url");
|
|
2450
2454
|
var SmsProvider = class {
|
|
2451
2455
|
constructor(logger = console, args) {
|
|
2452
2456
|
this.logger = logger;
|
|
@@ -2506,13 +2510,9 @@ var SmsProvider = class {
|
|
|
2506
2510
|
type: "plain",
|
|
2507
2511
|
message: this.cleanMessage(args.message)
|
|
2508
2512
|
};
|
|
2509
|
-
const res = await
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
body: JSON.stringify(payload)
|
|
2513
|
-
});
|
|
2514
|
-
const data = await res.json().catch(() => ({}));
|
|
2515
|
-
const isError = !res.ok || data?.status === "error";
|
|
2513
|
+
const res = await this.postWithResolvedIp(this.normalizeUrl(this.url), JSON.stringify(payload));
|
|
2514
|
+
const data = res.data ?? {};
|
|
2515
|
+
const isError = res.status >= 400 || data?.status === "error";
|
|
2516
2516
|
if (isError) {
|
|
2517
2517
|
return {
|
|
2518
2518
|
ok: false,
|
|
@@ -2522,12 +2522,11 @@ var SmsProvider = class {
|
|
|
2522
2522
|
meta: data
|
|
2523
2523
|
};
|
|
2524
2524
|
}
|
|
2525
|
-
const externalId = data?.id || data?.data?.id || data?.message_id || data?.data?.message_id;
|
|
2526
2525
|
return {
|
|
2527
2526
|
ok: true,
|
|
2528
2527
|
provider: "SMS" /* SMS */,
|
|
2529
2528
|
recipients,
|
|
2530
|
-
externalId,
|
|
2529
|
+
externalId: data?.id || data?.data?.id || data?.message_id || data?.data?.message_id,
|
|
2531
2530
|
meta: data
|
|
2532
2531
|
};
|
|
2533
2532
|
} catch (err) {
|
|
@@ -2540,6 +2539,31 @@ var SmsProvider = class {
|
|
|
2540
2539
|
}
|
|
2541
2540
|
}
|
|
2542
2541
|
// ---------------- helpers ----------------
|
|
2542
|
+
async postWithResolvedIp(urlStr, payload) {
|
|
2543
|
+
const u = new import_node_url.URL(urlStr);
|
|
2544
|
+
const host = u.hostname;
|
|
2545
|
+
const ips = await import_promises.default.resolve4(host);
|
|
2546
|
+
if (!ips.length) throw new Error(`No A records for ${host}`);
|
|
2547
|
+
const ip = ips[0];
|
|
2548
|
+
const ipUrl = urlStr.replace(host, ip);
|
|
2549
|
+
const httpsAgent = new import_node_https.default.Agent({
|
|
2550
|
+
keepAlive: true,
|
|
2551
|
+
servername: host
|
|
2552
|
+
// ✅ TLS SNI
|
|
2553
|
+
});
|
|
2554
|
+
return import_axios2.default.post(ipUrl, payload, {
|
|
2555
|
+
timeout: 15e3,
|
|
2556
|
+
httpsAgent,
|
|
2557
|
+
headers: {
|
|
2558
|
+
"Content-Type": "application/json",
|
|
2559
|
+
Accept: "application/json",
|
|
2560
|
+
Host: host
|
|
2561
|
+
// ✅ must keep Host
|
|
2562
|
+
},
|
|
2563
|
+
validateStatus: () => true
|
|
2564
|
+
// ✅ we handle errors ourselves
|
|
2565
|
+
});
|
|
2566
|
+
}
|
|
2543
2567
|
/**
|
|
2544
2568
|
* Normalize phones:
|
|
2545
2569
|
* - trim
|
|
@@ -2571,7 +2595,7 @@ var SmsProvider = class {
|
|
|
2571
2595
|
};
|
|
2572
2596
|
|
|
2573
2597
|
// src/providers/whatsapp.provider.ts
|
|
2574
|
-
var
|
|
2598
|
+
var import_axios3 = __toESM(require("axios"));
|
|
2575
2599
|
|
|
2576
2600
|
// src/utils/notification.utils.ts
|
|
2577
2601
|
function defaultValueField(t) {
|
|
@@ -2886,7 +2910,7 @@ var WhatsAppProvider = class {
|
|
|
2886
2910
|
}
|
|
2887
2911
|
try {
|
|
2888
2912
|
const { requestBody, headers } = this.buildRequest(to, inp);
|
|
2889
|
-
const response = await
|
|
2913
|
+
const response = await import_axios3.default.post(this.apiUrl, requestBody, { headers });
|
|
2890
2914
|
const data = response.data;
|
|
2891
2915
|
return {
|
|
2892
2916
|
ok: true,
|
|
@@ -2944,7 +2968,7 @@ var WhatsAppProvider = class {
|
|
|
2944
2968
|
const items = await mapWithConcurrency(recipients, concurrency, async (recipient) => {
|
|
2945
2969
|
try {
|
|
2946
2970
|
const { requestBody, headers } = this.buildRequest(recipient, baseInp);
|
|
2947
|
-
const response = await
|
|
2971
|
+
const response = await import_axios3.default.post(this.apiUrl, requestBody, { headers });
|
|
2948
2972
|
const data = response.data;
|
|
2949
2973
|
return {
|
|
2950
2974
|
recipient,
|
package/dist/index.mjs
CHANGED
|
@@ -2397,6 +2397,10 @@ var EmailProvider = class {
|
|
|
2397
2397
|
};
|
|
2398
2398
|
|
|
2399
2399
|
// src/providers/sms.provider.ts
|
|
2400
|
+
import axios2 from "axios";
|
|
2401
|
+
import https from "https";
|
|
2402
|
+
import dns from "dns/promises";
|
|
2403
|
+
import { URL } from "url";
|
|
2400
2404
|
var SmsProvider = class {
|
|
2401
2405
|
constructor(logger = console, args) {
|
|
2402
2406
|
this.logger = logger;
|
|
@@ -2456,13 +2460,9 @@ var SmsProvider = class {
|
|
|
2456
2460
|
type: "plain",
|
|
2457
2461
|
message: this.cleanMessage(args.message)
|
|
2458
2462
|
};
|
|
2459
|
-
const res = await
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
body: JSON.stringify(payload)
|
|
2463
|
-
});
|
|
2464
|
-
const data = await res.json().catch(() => ({}));
|
|
2465
|
-
const isError = !res.ok || data?.status === "error";
|
|
2463
|
+
const res = await this.postWithResolvedIp(this.normalizeUrl(this.url), JSON.stringify(payload));
|
|
2464
|
+
const data = res.data ?? {};
|
|
2465
|
+
const isError = res.status >= 400 || data?.status === "error";
|
|
2466
2466
|
if (isError) {
|
|
2467
2467
|
return {
|
|
2468
2468
|
ok: false,
|
|
@@ -2472,12 +2472,11 @@ var SmsProvider = class {
|
|
|
2472
2472
|
meta: data
|
|
2473
2473
|
};
|
|
2474
2474
|
}
|
|
2475
|
-
const externalId = data?.id || data?.data?.id || data?.message_id || data?.data?.message_id;
|
|
2476
2475
|
return {
|
|
2477
2476
|
ok: true,
|
|
2478
2477
|
provider: "SMS" /* SMS */,
|
|
2479
2478
|
recipients,
|
|
2480
|
-
externalId,
|
|
2479
|
+
externalId: data?.id || data?.data?.id || data?.message_id || data?.data?.message_id,
|
|
2481
2480
|
meta: data
|
|
2482
2481
|
};
|
|
2483
2482
|
} catch (err) {
|
|
@@ -2490,6 +2489,31 @@ var SmsProvider = class {
|
|
|
2490
2489
|
}
|
|
2491
2490
|
}
|
|
2492
2491
|
// ---------------- helpers ----------------
|
|
2492
|
+
async postWithResolvedIp(urlStr, payload) {
|
|
2493
|
+
const u = new URL(urlStr);
|
|
2494
|
+
const host = u.hostname;
|
|
2495
|
+
const ips = await dns.resolve4(host);
|
|
2496
|
+
if (!ips.length) throw new Error(`No A records for ${host}`);
|
|
2497
|
+
const ip = ips[0];
|
|
2498
|
+
const ipUrl = urlStr.replace(host, ip);
|
|
2499
|
+
const httpsAgent = new https.Agent({
|
|
2500
|
+
keepAlive: true,
|
|
2501
|
+
servername: host
|
|
2502
|
+
// ✅ TLS SNI
|
|
2503
|
+
});
|
|
2504
|
+
return axios2.post(ipUrl, payload, {
|
|
2505
|
+
timeout: 15e3,
|
|
2506
|
+
httpsAgent,
|
|
2507
|
+
headers: {
|
|
2508
|
+
"Content-Type": "application/json",
|
|
2509
|
+
Accept: "application/json",
|
|
2510
|
+
Host: host
|
|
2511
|
+
// ✅ must keep Host
|
|
2512
|
+
},
|
|
2513
|
+
validateStatus: () => true
|
|
2514
|
+
// ✅ we handle errors ourselves
|
|
2515
|
+
});
|
|
2516
|
+
}
|
|
2493
2517
|
/**
|
|
2494
2518
|
* Normalize phones:
|
|
2495
2519
|
* - trim
|
|
@@ -2521,7 +2545,7 @@ var SmsProvider = class {
|
|
|
2521
2545
|
};
|
|
2522
2546
|
|
|
2523
2547
|
// src/providers/whatsapp.provider.ts
|
|
2524
|
-
import
|
|
2548
|
+
import axios3 from "axios";
|
|
2525
2549
|
|
|
2526
2550
|
// src/utils/notification.utils.ts
|
|
2527
2551
|
function defaultValueField(t) {
|
|
@@ -2836,7 +2860,7 @@ var WhatsAppProvider = class {
|
|
|
2836
2860
|
}
|
|
2837
2861
|
try {
|
|
2838
2862
|
const { requestBody, headers } = this.buildRequest(to, inp);
|
|
2839
|
-
const response = await
|
|
2863
|
+
const response = await axios3.post(this.apiUrl, requestBody, { headers });
|
|
2840
2864
|
const data = response.data;
|
|
2841
2865
|
return {
|
|
2842
2866
|
ok: true,
|
|
@@ -2894,7 +2918,7 @@ var WhatsAppProvider = class {
|
|
|
2894
2918
|
const items = await mapWithConcurrency(recipients, concurrency, async (recipient) => {
|
|
2895
2919
|
try {
|
|
2896
2920
|
const { requestBody, headers } = this.buildRequest(recipient, baseInp);
|
|
2897
|
-
const response = await
|
|
2921
|
+
const response = await axios3.post(this.apiUrl, requestBody, { headers });
|
|
2898
2922
|
const data = response.data;
|
|
2899
2923
|
return {
|
|
2900
2924
|
recipient,
|