@certalis/agent-smith 0.1.4 → 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.
@@ -1372,6 +1372,12 @@ function sanitizeConfigData(value) {
1372
1372
  sanitized.provider_pools = providerPools;
1373
1373
  continue;
1374
1374
  }
1375
+ if (key === "alerts") {
1376
+ const alerts = sanitizeAlerts(entry);
1377
+ if (alerts)
1378
+ sanitized.alerts = alerts;
1379
+ continue;
1380
+ }
1375
1381
  if (typeof entry === "string" || typeof entry === "boolean" || isFiniteNumber(entry)) {
1376
1382
  sanitized[key] = entry;
1377
1383
  }
@@ -1402,6 +1408,46 @@ function sanitizeConfigData(value) {
1402
1408
  }
1403
1409
  return sanitized;
1404
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
+ }
1405
1451
  function isProviderStrategy(value) {
1406
1452
  return typeof value === "string" && PROVIDER_STRATEGIES.includes(value);
1407
1453
  }
@@ -1503,7 +1549,7 @@ function sanitizeTeamRouting(value) {
1503
1549
  }
1504
1550
  return result;
1505
1551
  }
1506
- 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;
1507
1553
  var init_src4 = __esm(() => {
1508
1554
  init_src2();
1509
1555
  init_src3();
@@ -1569,12 +1615,23 @@ var init_src4 = __esm(() => {
1569
1615
  }
1570
1616
  saveConfig() {
1571
1617
  try {
1572
- const content = JSON.stringify(this.data, null, 2);
1573
- writeFileSync(this.configPath, content, "utf8");
1618
+ this.writePrivately(this.data);
1574
1619
  } catch (error) {
1575
1620
  log2.error(`Failed to save config file: ${error}`);
1576
1621
  }
1577
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
+ }
1578
1635
  get(key, defaultValue) {
1579
1636
  const value = this.data[key];
1580
1637
  if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
@@ -1669,6 +1726,20 @@ var init_src4 = __esm(() => {
1669
1726
  quotaProbeSeconds: file?.quota_probe_seconds ?? TEAM_ROUTING_DEFAULTS.quotaProbeSeconds
1670
1727
  };
1671
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
+ }
1672
1743
  getProviderConfig(name) {
1673
1744
  const builtin = BUILTIN_PROVIDER_CONFIG_BY_NAME.get(name);
1674
1745
  const configured = this.data.providers?.[name];
@@ -1769,22 +1840,14 @@ var init_src4 = __esm(() => {
1769
1840
  }
1770
1841
  persistStrictly(key, value) {
1771
1842
  const next = { ...this.data, [key]: value };
1772
- const temporary = `${this.configPath}.${crypto.randomUUID()}.tmp`;
1773
- try {
1774
- writeFileSync(temporary, JSON.stringify(next, null, 2), {
1775
- mode: 384,
1776
- flag: "wx"
1777
- });
1778
- renameSync(temporary, this.configPath);
1779
- } finally {
1780
- rmSync(temporary, { force: true });
1781
- }
1843
+ this.writePrivately(next);
1782
1844
  const oldValue = this.data[key];
1783
1845
  this.data = next;
1784
1846
  this.emit("change", { key, oldValue, newValue: value });
1785
1847
  }
1786
1848
  getRuntime() {
1787
1849
  const defaults = {
1850
+ blockWhenAllFull: this.getBlockWhenAllFull(),
1788
1851
  clientId: "9d1c250a-e61b-44d9-88ed-5944d1962f5e",
1789
1852
  maxBodyBytes: 64 * 1024 * 1024,
1790
1853
  quotaThreshold: 0.98,