@certalis/agent-smith 0.1.0 → 0.1.2

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.
@@ -1327,12 +1327,30 @@ function parseNumber(value) {
1327
1327
  const parsed = Number(value);
1328
1328
  return Number.isFinite(parsed) ? parsed : undefined;
1329
1329
  }
1330
+ function normalizeEnrollmentEmail(value) {
1331
+ if (typeof value !== "string")
1332
+ return;
1333
+ const email = value.trim().toLowerCase();
1334
+ return email.length <= 254 && patterns.email.test(email) ? email : undefined;
1335
+ }
1336
+ function sanitizeEnrollmentEmails(value) {
1337
+ if (!Array.isArray(value))
1338
+ return;
1339
+ const emails = value.map(normalizeEnrollmentEmail).filter((email) => email !== undefined);
1340
+ return [...new Set(emails)].slice(0, MAX_ENROLLMENT_EMAILS);
1341
+ }
1330
1342
  function sanitizeConfigData(value) {
1331
1343
  if (!isRecord(value)) {
1332
1344
  return {};
1333
1345
  }
1334
1346
  const sanitized = {};
1335
1347
  for (const [key, entry] of Object.entries(value)) {
1348
+ if (key === "enrollment_emails") {
1349
+ const emails = sanitizeEnrollmentEmails(entry);
1350
+ if (emails)
1351
+ sanitized.enrollment_emails = emails;
1352
+ continue;
1353
+ }
1336
1354
  if (key === "team_routing") {
1337
1355
  const teamRouting = sanitizeTeamRouting(entry);
1338
1356
  if (teamRouting)
@@ -1482,7 +1500,7 @@ function sanitizeTeamRouting(value) {
1482
1500
  }
1483
1501
  return result;
1484
1502
  }
1485
- var log2, PROVIDER_STRATEGIES, BUILTIN_PROVIDER_CONFIGS, BUILTIN_PROVIDER_CONFIG_BY_NAME, PROVIDER_NAME_PATTERN, TEAM_ROUTING_DEFAULTS, Config;
1503
+ var log2, PROVIDER_STRATEGIES, BUILTIN_PROVIDER_CONFIGS, BUILTIN_PROVIDER_CONFIG_BY_NAME, PROVIDER_NAME_PATTERN, TEAM_ROUTING_DEFAULTS, MAX_ENROLLMENT_EMAILS = 200, Config;
1486
1504
  var init_src4 = __esm(() => {
1487
1505
  init_src2();
1488
1506
  init_src3();
@@ -1726,11 +1744,28 @@ var init_src4 = __esm(() => {
1726
1744
  this.persistAccountAllowlist(current.filter((uuid) => uuid !== accountUuid));
1727
1745
  }
1728
1746
  persistAccountAllowlist(accountUuids) {
1729
- const teamRouting = {
1747
+ this.persistStrictly("team_routing", {
1730
1748
  ...this.data.team_routing,
1731
1749
  allowlisted_account_uuids: accountUuids
1732
- };
1733
- const next = { ...this.data, team_routing: teamRouting };
1750
+ });
1751
+ }
1752
+ getEnrollmentEmails() {
1753
+ return [...this.data.enrollment_emails ?? []];
1754
+ }
1755
+ setEnrollmentEmails(emails) {
1756
+ const normalized = emails.map(normalizeEnrollmentEmail);
1757
+ if (normalized.some((email) => email === undefined)) {
1758
+ throw new ValidationError("Invalid enrollment email", "enrollment_emails");
1759
+ }
1760
+ const unique = [...new Set(normalized)];
1761
+ if (unique.length > MAX_ENROLLMENT_EMAILS) {
1762
+ throw new ValidationError(`At most ${MAX_ENROLLMENT_EMAILS} enrollment emails`, "enrollment_emails");
1763
+ }
1764
+ this.persistStrictly("enrollment_emails", unique);
1765
+ return [...unique];
1766
+ }
1767
+ persistStrictly(key, value) {
1768
+ const next = { ...this.data, [key]: value };
1734
1769
  const temporary = `${this.configPath}.${crypto.randomUUID()}.tmp`;
1735
1770
  try {
1736
1771
  writeFileSync(temporary, JSON.stringify(next, null, 2), {
@@ -1741,13 +1776,9 @@ var init_src4 = __esm(() => {
1741
1776
  } finally {
1742
1777
  rmSync(temporary, { force: true });
1743
1778
  }
1744
- const oldValue = this.data.team_routing;
1779
+ const oldValue = this.data[key];
1745
1780
  this.data = next;
1746
- this.emit("change", {
1747
- key: "team_routing",
1748
- oldValue,
1749
- newValue: teamRouting
1750
- });
1781
+ this.emit("change", { key, oldValue, newValue: value });
1751
1782
  }
1752
1783
  getRuntime() {
1753
1784
  const defaults = {