@reddoorla/maintenance 0.14.0 → 0.16.0

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 CHANGED
@@ -753,25 +753,27 @@ var DEFAULT_AUDIT_TIMEOUT_MS = 3e4;
753
753
  function timedSpawn(timeoutMs) {
754
754
  return (cmd, args, opts = {}) => defaultSpawn(cmd, args, { ...opts, timeoutMs: opts.timeoutMs ?? timeoutMs });
755
755
  }
756
+ async function runOneAudit(site, name) {
757
+ if (!(name in REGISTRY)) throw new Error(`unknown audit: ${name}`);
758
+ const spawn2 = timedSpawn(DEFAULT_AUDIT_TIMEOUT_MS);
759
+ const label = site.name ?? site.path;
760
+ try {
761
+ return await REGISTRY[name]({ site, spawn: spawn2 });
762
+ } catch (err) {
763
+ return {
764
+ audit: name,
765
+ site: label,
766
+ status: "fail",
767
+ summary: `${name}: unexpected error \u2014 ${String(err)}`
768
+ };
769
+ }
770
+ }
756
771
  async function runAudits(site, which) {
757
772
  const names = which ?? ALL_AUDIT_NAMES;
758
773
  for (const n of names) {
759
774
  if (!(n in REGISTRY)) throw new Error(`unknown audit: ${n}`);
760
775
  }
761
- const spawn2 = timedSpawn(DEFAULT_AUDIT_TIMEOUT_MS);
762
- const label = site.name ?? site.path;
763
- return Promise.all(
764
- names.map(
765
- (n) => REGISTRY[n]({ site, spawn: spawn2 }).catch(
766
- (err) => ({
767
- audit: n,
768
- site: label,
769
- status: "fail",
770
- summary: `${n}: unexpected error \u2014 ${String(err)}`
771
- })
772
- )
773
- )
774
- );
776
+ return Promise.all(names.map((n) => runOneAudit(site, n)));
775
777
  }
776
778
  async function runAuditsAcross(sites, which) {
777
779
  const all = await Promise.all(sites.map((s) => runAudits(s, which)));
@@ -2701,11 +2703,30 @@ async function derivePeriodStart(base, siteRow, reportType, today) {
2701
2703
 
2702
2704
  // src/reports/airtable/client.ts
2703
2705
  import Airtable from "airtable";
2706
+
2707
+ // src/util/credentials.ts
2708
+ import { readFileSync as readFileSync2 } from "fs";
2709
+ import { homedir } from "os";
2710
+ import { join as join20 } from "path";
2711
+ function defaultCredentialsPath() {
2712
+ const base = process.env.XDG_CONFIG_HOME ?? join20(homedir(), ".config");
2713
+ return join20(base, "reddoor-maint", "credentials.env");
2714
+ }
2715
+
2716
+ // src/reports/airtable/client.ts
2717
+ function missing(name) {
2718
+ return Object.assign(
2719
+ new Error(
2720
+ `${name} not set. Export it in your shell or put it in ${defaultCredentialsPath()} as ${name}=...`
2721
+ ),
2722
+ { exitCode: 2 }
2723
+ );
2724
+ }
2704
2725
  function readAirtableConfig() {
2705
2726
  const apiKey = process.env.AIRTABLE_PAT;
2706
2727
  const baseId = process.env.AIRTABLE_BASE_ID;
2707
- if (!apiKey) throw Object.assign(new Error("AIRTABLE_PAT not set"), { exitCode: 2 });
2708
- if (!baseId) throw Object.assign(new Error("AIRTABLE_BASE_ID not set"), { exitCode: 2 });
2728
+ if (!apiKey) throw missing("AIRTABLE_PAT");
2729
+ if (!baseId) throw missing("AIRTABLE_BASE_ID");
2709
2730
  return { apiKey, baseId };
2710
2731
  }
2711
2732
  function openBase(cfg) {