@certalis/agent-smith 0.1.3 → 0.1.5
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/README.md +4 -1
- package/dist/bin.js +359 -108
- package/dist/post-processor.worker.js +79 -13
- package/dist/server.js +347 -96
- package/package.json +1 -1
|
@@ -704,6 +704,9 @@ function quotaThresholdFor(account, bucket, fleetThreshold) {
|
|
|
704
704
|
function isCurrentQuotaWindow(window, now) {
|
|
705
705
|
return (window.resetAt === null || window.resetAt > now) && now - window.seenAt <= QUOTA_STALE_MS;
|
|
706
706
|
}
|
|
707
|
+
function isOpenQuotaWindow(window, now) {
|
|
708
|
+
return window.resetAt === null ? isCurrentQuotaWindow(window, now) : window.resetAt > now;
|
|
709
|
+
}
|
|
707
710
|
var QUOTA_STALE_MS;
|
|
708
711
|
var init_quota = __esm(() => {
|
|
709
712
|
QUOTA_STALE_MS = 30 * 60000;
|
|
@@ -1369,6 +1372,12 @@ function sanitizeConfigData(value) {
|
|
|
1369
1372
|
sanitized.provider_pools = providerPools;
|
|
1370
1373
|
continue;
|
|
1371
1374
|
}
|
|
1375
|
+
if (key === "alerts") {
|
|
1376
|
+
const alerts = sanitizeAlerts(entry);
|
|
1377
|
+
if (alerts)
|
|
1378
|
+
sanitized.alerts = alerts;
|
|
1379
|
+
continue;
|
|
1380
|
+
}
|
|
1372
1381
|
if (typeof entry === "string" || typeof entry === "boolean" || isFiniteNumber(entry)) {
|
|
1373
1382
|
sanitized[key] = entry;
|
|
1374
1383
|
}
|
|
@@ -1399,6 +1408,46 @@ function sanitizeConfigData(value) {
|
|
|
1399
1408
|
}
|
|
1400
1409
|
return sanitized;
|
|
1401
1410
|
}
|
|
1411
|
+
function filledText(value) {
|
|
1412
|
+
if (typeof value !== "string")
|
|
1413
|
+
return;
|
|
1414
|
+
const text = value.trim();
|
|
1415
|
+
return text.length > 0 && text.length <= MAX_ALERT_VALUE_LENGTH ? text : undefined;
|
|
1416
|
+
}
|
|
1417
|
+
function sanitizeHttpsUrl(value) {
|
|
1418
|
+
const text = filledText(value);
|
|
1419
|
+
if (!text)
|
|
1420
|
+
return;
|
|
1421
|
+
try {
|
|
1422
|
+
return new URL(text).protocol === "https:" ? text : undefined;
|
|
1423
|
+
} catch {
|
|
1424
|
+
return;
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
function sanitizeAlerts(value) {
|
|
1428
|
+
if (!isRecord(value))
|
|
1429
|
+
return;
|
|
1430
|
+
const alerts = {};
|
|
1431
|
+
const slackWebhookUrl = sanitizeHttpsUrl(value.slack_webhook_url);
|
|
1432
|
+
if (slackWebhookUrl)
|
|
1433
|
+
alerts.slack_webhook_url = slackWebhookUrl;
|
|
1434
|
+
const slackBotToken = filledText(value.slack_bot_token);
|
|
1435
|
+
if (slackBotToken)
|
|
1436
|
+
alerts.slack_bot_token = slackBotToken;
|
|
1437
|
+
const slackChannel = filledText(value.slack_channel);
|
|
1438
|
+
if (slackChannel)
|
|
1439
|
+
alerts.slack_channel = slackChannel;
|
|
1440
|
+
const email = normalizeEnrollmentEmail(value.email);
|
|
1441
|
+
if (email)
|
|
1442
|
+
alerts.email = email;
|
|
1443
|
+
const emailFrom = filledText(value.email_from);
|
|
1444
|
+
if (emailFrom)
|
|
1445
|
+
alerts.email_from = emailFrom;
|
|
1446
|
+
const resendApiKey = filledText(value.resend_api_key);
|
|
1447
|
+
if (resendApiKey)
|
|
1448
|
+
alerts.resend_api_key = resendApiKey;
|
|
1449
|
+
return alerts;
|
|
1450
|
+
}
|
|
1402
1451
|
function isProviderStrategy(value) {
|
|
1403
1452
|
return typeof value === "string" && PROVIDER_STRATEGIES.includes(value);
|
|
1404
1453
|
}
|
|
@@ -1500,7 +1549,7 @@ function sanitizeTeamRouting(value) {
|
|
|
1500
1549
|
}
|
|
1501
1550
|
return result;
|
|
1502
1551
|
}
|
|
1503
|
-
var log2, PROVIDER_STRATEGIES, BUILTIN_PROVIDER_CONFIGS, BUILTIN_PROVIDER_CONFIG_BY_NAME, PROVIDER_NAME_PATTERN, TEAM_ROUTING_DEFAULTS, MAX_ENROLLMENT_EMAILS = 200, Config;
|
|
1552
|
+
var log2, PROVIDER_STRATEGIES, BUILTIN_PROVIDER_CONFIGS, BUILTIN_PROVIDER_CONFIG_BY_NAME, PROVIDER_NAME_PATTERN, TEAM_ROUTING_DEFAULTS, MAX_ENROLLMENT_EMAILS = 200, MAX_ALERT_VALUE_LENGTH = 512, Config;
|
|
1504
1553
|
var init_src4 = __esm(() => {
|
|
1505
1554
|
init_src2();
|
|
1506
1555
|
init_src3();
|
|
@@ -1566,12 +1615,23 @@ var init_src4 = __esm(() => {
|
|
|
1566
1615
|
}
|
|
1567
1616
|
saveConfig() {
|
|
1568
1617
|
try {
|
|
1569
|
-
|
|
1570
|
-
writeFileSync(this.configPath, content, "utf8");
|
|
1618
|
+
this.writePrivately(this.data);
|
|
1571
1619
|
} catch (error) {
|
|
1572
1620
|
log2.error(`Failed to save config file: ${error}`);
|
|
1573
1621
|
}
|
|
1574
1622
|
}
|
|
1623
|
+
writePrivately(data) {
|
|
1624
|
+
const temporary = `${this.configPath}.${crypto.randomUUID()}.tmp`;
|
|
1625
|
+
try {
|
|
1626
|
+
writeFileSync(temporary, JSON.stringify(data, null, 2), {
|
|
1627
|
+
mode: 384,
|
|
1628
|
+
flag: "wx"
|
|
1629
|
+
});
|
|
1630
|
+
renameSync(temporary, this.configPath);
|
|
1631
|
+
} finally {
|
|
1632
|
+
rmSync(temporary, { force: true });
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1575
1635
|
get(key, defaultValue) {
|
|
1576
1636
|
const value = this.data[key];
|
|
1577
1637
|
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
@@ -1666,6 +1726,20 @@ var init_src4 = __esm(() => {
|
|
|
1666
1726
|
quotaProbeSeconds: file?.quota_probe_seconds ?? TEAM_ROUTING_DEFAULTS.quotaProbeSeconds
|
|
1667
1727
|
};
|
|
1668
1728
|
}
|
|
1729
|
+
getAlerts() {
|
|
1730
|
+
const file = this.data.alerts;
|
|
1731
|
+
return {
|
|
1732
|
+
slackWebhookUrl: file?.slack_webhook_url ?? null,
|
|
1733
|
+
slackBotToken: file?.slack_bot_token ?? null,
|
|
1734
|
+
slackChannel: file?.slack_channel ?? null,
|
|
1735
|
+
email: file?.email ?? null,
|
|
1736
|
+
emailFrom: file?.email_from ?? null,
|
|
1737
|
+
resendApiKey: file?.resend_api_key ?? null
|
|
1738
|
+
};
|
|
1739
|
+
}
|
|
1740
|
+
getBlockWhenAllFull() {
|
|
1741
|
+
return this.data.block_when_all_full !== false;
|
|
1742
|
+
}
|
|
1669
1743
|
getProviderConfig(name) {
|
|
1670
1744
|
const builtin = BUILTIN_PROVIDER_CONFIG_BY_NAME.get(name);
|
|
1671
1745
|
const configured = this.data.providers?.[name];
|
|
@@ -1766,22 +1840,14 @@ var init_src4 = __esm(() => {
|
|
|
1766
1840
|
}
|
|
1767
1841
|
persistStrictly(key, value) {
|
|
1768
1842
|
const next = { ...this.data, [key]: value };
|
|
1769
|
-
|
|
1770
|
-
try {
|
|
1771
|
-
writeFileSync(temporary, JSON.stringify(next, null, 2), {
|
|
1772
|
-
mode: 384,
|
|
1773
|
-
flag: "wx"
|
|
1774
|
-
});
|
|
1775
|
-
renameSync(temporary, this.configPath);
|
|
1776
|
-
} finally {
|
|
1777
|
-
rmSync(temporary, { force: true });
|
|
1778
|
-
}
|
|
1843
|
+
this.writePrivately(next);
|
|
1779
1844
|
const oldValue = this.data[key];
|
|
1780
1845
|
this.data = next;
|
|
1781
1846
|
this.emit("change", { key, oldValue, newValue: value });
|
|
1782
1847
|
}
|
|
1783
1848
|
getRuntime() {
|
|
1784
1849
|
const defaults = {
|
|
1850
|
+
blockWhenAllFull: this.getBlockWhenAllFull(),
|
|
1785
1851
|
clientId: "9d1c250a-e61b-44d9-88ed-5944d1962f5e",
|
|
1786
1852
|
maxBodyBytes: 64 * 1024 * 1024,
|
|
1787
1853
|
quotaThreshold: 0.98,
|