@theholocron/cli 5.0.0-alpha.514 → 5.0.0-alpha.515

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 CHANGED
@@ -691,7 +691,7 @@ commands and the config are provider-neutral; Discord is the first provider.
691
691
 
692
692
  Channels fed by another service are declared with `feeds` on the channel: `{ name: "uptime", webhook: true, feeds: { monitoring: true } }` (the object form `{ name?, webhook?, avatar?, alerts? }` overrides the alert channel's name, default `Message to #<channel>`, the dedicated webhook's name, default the provider's, and gives that webhook a picture, a file path or `https://` URL, or `{ url, image }` (the URL is tried first, the file in the repo is the fallback), else the provider's own icon (`Monitoring.icon`, a URL and an embedded `data:` image; Checkly provides one), else the layout's `webhookAvatar`). A channel's own `webhook.avatar` and the layout's `webhookAvatar` take the same forms, a path or `https://` URL, or `{ url, image }` (the URL first, the file in the repo as the fallback); a relative path is read from the repository root. `setup` gives the channel a dedicated webhook and hands its URL straight to the `monitoring` provider through `Monitoring.ensureAlertChannel({ name, format: "discord", url? })`, which finds an alert channel of that name or creates one and subscribes every check; the URL is never stored as a secret. It needs a `monitoring` provider that implements `ensureAlertChannel` (Checkly does). `alerts: { failure?, recovery?, degraded?, sslExpiry?, sslExpiryThreshold? }` (`MonitoringAlertSettings`, passed as `ensureAlertChannel({ ..., alerts })`) sets what the alert channel alerts about: a new channel defaults to failure, recovery and degraded on and `sslExpiry` off, and on an existing channel a setting left out is left alone. A check in the `monitoring` provider's `checks` can route itself with `alertChannels: ["Message to #uptime"]` (`MonitoringCheckInput.alertChannels`, the alert channel names): it is then subscribed to those channels only, and a name no feed declares is refused by `setup`. `inspectAlertChannel` returns the channel's `alerts` and the `misrouted` checks that `doctor notifications` reports. Two feeds may not share an alert channel name, and a feed's webhook may not share the channel's own webhook name (compared without regard to case).
693
693
 
694
- Channels fed by the error tracker add `feeds: { errors: true }` and a layout `relay: { host, zone?, script?, code? }`: `setup` makes a dedicated webhook, points `host` at the Comlink Worker (a proxied DNS record via `dns`), and deploys it via `workers.deployScript` with the webhook URL as `COMLINK_<SOURCE>_WEBHOOK`. The URL never leaves the Worker's secret; other secrets on the script are kept. A service other than the error tracker is declared in `relay.sources: { <id>: { capability, provider?, name?, events?, scope?, options? } }` and carried by a channel with `feeds.relay.<id>`: `provider` names the plugin for a capability the root config gives to another one (`vercel` for `deployment`; the layout check validates its shape, and loading it is the next change, #2522, #2523); `setup` asks the provider of `capability` to make the vendor's webhook (optional `ensureRelaySource`, found again by its URL, never deleted), hands the Worker `COMLINK_<ID>_SECRET` (when the provider made or chose a secret) and `COMLINK_<ID>_WEBHOOK` in the same deploy, and `doctor notifications` adds a `relay-source:<id>` row (optional `inspectRelaySource`). With `relay.errors: { projects, integration?, rule?, frequency? }` it also ensures the tracker's integration and alert rule (`errors.ensureRelay`) and deploys the Worker with the integration's signing secret. Needs `errors`, `workers` and `dns`; only one channel may be fed.
694
+ Channels fed by the error tracker add `feeds: { errors: true }` and a layout `relay: { host, zone?, script?, code? }`: `setup` makes a dedicated webhook, points `host` at the Comlink Worker (a proxied DNS record via `dns`), and deploys it via `workers.deployScript` with the webhook URL as `COMLINK_<SOURCE>_WEBHOOK`. The URL never leaves the Worker's secret; other secrets on the script are kept. A service other than the error tracker is declared in `relay.sources: { <id>: { capability, provider?, name?, events?, scope?, options? } }` and carried by a channel with `feeds.relay.<id>`: `provider` names the plugin for a capability the root config gives to another one (`vercel` for `deployment`; `setup` loads it by name with the options of the config that names it, root or a workspace package's, and refuses, before writing, one that is missing, cannot make a webhook or has no token; `doctor notifications` finds it the same way and skips the `relay-source:<id>` row, with the reason, when it cannot load or read it); `setup` asks the provider of `capability` to make the vendor's webhook (optional `ensureRelaySource`, found again by its URL, never deleted), hands the Worker `COMLINK_<ID>_SECRET` (when the provider made or chose a secret) and `COMLINK_<ID>_WEBHOOK` in the same deploy, and `doctor notifications` adds a `relay-source:<id>` row (optional `inspectRelaySource`). With `relay.errors: { projects, integration?, rule?, frequency? }` it also ensures the tracker's integration and alert rule (`errors.ensureRelay`) and deploys the Worker with the integration's signing secret. Needs `errors`, `workers` and `dns`; only one channel may be fed.
695
695
 
696
696
  `holocron sync secrets --env <environment> --worker <script>` also sets every key of the vault environment on a deployed Worker as a secret, through the optional `Workers.setSecret(script, name, value)` (write-only; the Cloudflare plugin implements it). The Worker must already exist. Sync only adds and updates: it never removes a binding, because a Worker also holds secrets that are not in the vault (for Comlink, the `COMLINK_<SOURCE>_WEBHOOK` that `setup notifications` sets), so a key deleted from the vault must be deleted from the Worker separately. Keys are written one at a time and each is reported; if one fails, the exit code is 1 and re-running finishes the rest, since every write is idempotent.
697
697
 
package/dist/cli.mjs CHANGED
@@ -3819,6 +3819,28 @@ var PluginLoader = class extends system.PluginLoader {
3819
3819
  throw err;
3820
3820
  }
3821
3821
  }
3822
+ /**
3823
+ * Loads one provider by name with the given options, whether or not `holocron.config` names it under `key`, and
3824
+ * returns what it makes for that capability, leaving the capability registry alone (a relay source names the plugin
3825
+ * that makes its webhook). The token is read when the capability is first used, not here. Throws
3826
+ * {@link WorkspaceContextError} when the provider's package cannot be imported here, a {@link LoaderError} when it
3827
+ * does not implement `key`, and what `createPlugin` throws as it is.
3828
+ */
3829
+ async loadNamedCapability(provider, options, key) {
3830
+ const packageName = system.resolvePackage(provider);
3831
+ try {
3832
+ const factory = (await this.loadProvider({
3833
+ provider,
3834
+ packageName,
3835
+ options
3836
+ })).capabilities[key];
3837
+ if (typeof factory !== "function") throw new LoaderError(`\`${packageName}\` does not implement the \`${key}\` capability`);
3838
+ return factory();
3839
+ } catch (err) {
3840
+ if (err instanceof LoaderError && err.message.startsWith("failed to import")) throw new WorkspaceContextError("provider", [packageName]);
3841
+ throw err;
3842
+ }
3843
+ }
3822
3844
  };
3823
3845
  /** The `setup` and `doctor` a created plugin carries. */
3824
3846
  function actionsOf(plugin) {
@@ -12493,16 +12515,17 @@ async function relaySourceChecks(input) {
12493
12515
  const { layout } = input;
12494
12516
  const host = layout.relay?.host;
12495
12517
  const rows = [];
12496
- for (const { id, spec } of declaredRelaySources(layout)) {
12518
+ for (const source of declaredRelaySources(layout)) {
12519
+ const { id, spec } = source;
12497
12520
  const rowId = `relay-source:${id}`;
12498
12521
  const title = `${shown$6(id)} webhook at the vendor posts to the relay`;
12499
12522
  if (!host) {
12500
12523
  rows.push(skipRow$1(rowId, title, "no `relay.host` is declared"));
12501
12524
  continue;
12502
12525
  }
12503
- const provider = input.provider(spec.capability);
12526
+ const { provider, problem } = await input.resolve(source);
12504
12527
  if (!provider) {
12505
- rows.push(skipRow$1(rowId, title, input.missingReason(spec.capability)));
12528
+ rows.push(skipRow$1(rowId, title, problem));
12506
12529
  continue;
12507
12530
  }
12508
12531
  if (!provider.inspectRelaySource) {
@@ -12591,6 +12614,71 @@ function relaySourcesProblem(layout, errorsSource) {
12591
12614
  }
12592
12615
  }
12593
12616
  }
12617
+ // src/commands/provider-tuples/provider-tuples.ts
12618
+ /** The providers a config names, in the order it names them: one tuple per capability entry, so a provider named twice appears twice. */
12619
+ function providerTuples(providers) {
12620
+ return Object.values(providers).flatMap((entry) => entry.cardinality === "single" ? [entry.tuple] : entry.tuples);
12621
+ }
12622
+ // src/commands/workspace-providers/workspace-providers.ts
12623
+ /**
12624
+ * The providers the configs of the workspace's packages name (`apps/sentinel` names `vercel` for its `deployment`) that
12625
+ * `config` does not: what `doctor tokens` and `probe` load by name next to the repo's own, so the token a package's
12626
+ * provider needs is checked from the root. Nothing is written and the root config needs no key for it. The first
12627
+ * package to name a provider supplies its options (its `teamId`, from the shared `org` area). A package whose config
12628
+ * cannot be read is left out: its own commands report it.
12629
+ */
12630
+ async function workspaceProviders(repoRoot, config) {
12631
+ const known = new Set(providerTuples(config.providers).map((t) => t.provider));
12632
+ const found = [];
12633
+ for (const pkg of await readWorkspaceConfigs(repoRoot)) {
12634
+ if ("error" in pkg) continue;
12635
+ for (const tuple of providerTuples(pkg.resolved.providers)) {
12636
+ if (known.has(tuple.provider)) continue;
12637
+ known.add(tuple.provider);
12638
+ found.push(tuple);
12639
+ }
12640
+ }
12641
+ return found;
12642
+ }
12643
+ // src/commands/relay-sources/resolve-relay-source-provider.ts
12644
+ /**
12645
+ * The provider that makes a relay source's webhook: the configured provider of its `capability`, or, when the source
12646
+ * names a `provider` (spec `tech-relay-source-provider`), that plugin loaded by name beside the configured ones.
12647
+ *
12648
+ * - No `provider`: the configured provider of the capability (a problem when there is none).
12649
+ * - `provider` equal to the configured one: that same provider, loaded once.
12650
+ * - Any other: the plugin is loaded with the options of the first provider entry that names it, the root config's (for
12651
+ * another capability) then a workspace package's (`apps/sentinel` names `vercel`), through
12652
+ * `PluginLoader.loadNamedCapability`; the registry, the cardinality rules and what the root deploys are untouched. A
12653
+ * plugin no config names, that does not resolve, that fails to build or that lacks `ensureRelaySource` is a
12654
+ * `problem` that names it, never a throw, so the caller can refuse before it writes.
12655
+ *
12656
+ * Reads the workspace's package configs and loads a plugin; creates no webhook and calls no vendor.
12657
+ */
12658
+ async function resolveRelaySourceProvider(input) {
12659
+ const { loader, source } = input;
12660
+ const { id, spec } = source;
12661
+ const configured = loader.has(spec.capability) ? loader.get(spec.capability) : void 0;
12662
+ if (spec.provider === void 0 || configured?.providerName === spec.provider) return configured ? { provider: configured } : { problem: `relay source \`${id}\`: no \`${spec.capability}\` provider is configured` };
12663
+ const named = spec.provider;
12664
+ const tuple = await optionsFor(named, input);
12665
+ if (!tuple) return { problem: `relay source \`${id}\`: provider \`${named}\` is named by no \`holocron.config\` here, so there are no options to load it with — name it in the config of the package that uses it` };
12666
+ let made;
12667
+ try {
12668
+ made = await loader.loadNamedCapability(named, tuple.options, spec.capability);
12669
+ } catch (err) {
12670
+ return { problem: `relay source \`${id}\`: provider \`${named}\` (${tuple.packageName}) could not be loaded for \`${spec.capability}\`: ${describeError(err)}` };
12671
+ }
12672
+ const provider = made;
12673
+ if (typeof provider.ensureRelaySource !== "function") return { problem: `relay source \`${id}\`: provider \`${named}\` cannot make a relay webhook (its \`${spec.capability}\` has no \`ensureRelaySource\`)` };
12674
+ return { provider };
12675
+ }
12676
+ /** The tuple that supplies the named plugin's options: the root config's entry, else the first workspace package's. */
12677
+ async function optionsFor(name, input) {
12678
+ const root = providerTuples(input.config.providers).find((t) => t.provider === name);
12679
+ if (root) return root;
12680
+ return (await (input.workspace ?? workspaceProviders)(input.repoRoot, input.config)).find((t) => t.provider === name);
12681
+ }
12594
12682
  // src/commands/read-repo-text/read-repo-text.ts
12595
12683
  /** A text file named in a config is a few paragraphs; this only keeps a wrong file from filling memory. */
12596
12684
  const MAX_REPO_TEXT_BYTES = 102400;
@@ -13023,6 +13111,14 @@ async function runNotificationsSetup(input$1) {
13023
13111
  let workers;
13024
13112
  let dns;
13025
13113
  const sourceProviders = /* @__PURE__ */ new Map();
13114
+ const inspectInputOf = (source) => ({
13115
+ source: source.id,
13116
+ url: `https://${layout.relay?.host}/${source.id}`,
13117
+ name: source.spec.name ?? source.id.charAt(0).toUpperCase() + source.id.slice(1),
13118
+ ...source.spec.events ? { events: source.spec.events } : {},
13119
+ ...source.spec.scope ? { scope: source.spec.scope } : {},
13120
+ ...source.spec.options ? { options: source.spec.options } : {}
13121
+ });
13026
13122
  const declaredSources = declaredRelaySources(layout);
13027
13123
  const wantsErrors = wantsRelay(layout);
13028
13124
  if (wantsAnyRelay(layout) || declaredSources.length > 0) {
@@ -13033,12 +13129,27 @@ async function runNotificationsSetup(input$1) {
13033
13129
  ["dns", "a `dns` provider (for its host)"],
13034
13130
  ...wantsErrors ? [["errors", "an `errors` provider (the tracker whose alerts it carries)"]] : []
13035
13131
  ];
13036
- for (const { id, spec } of declaredSources) needs.push([spec.capability, `a \`${spec.capability}\` provider (it makes the ${id} webhook)`]);
13132
+ for (const { id, spec } of declaredSources) if (spec.provider === void 0) needs.push([spec.capability, `a \`${spec.capability}\` provider (it makes the ${id} webhook)`]);
13037
13133
  for (const [key, what] of needs) if (!loader.has(key)) return refuse(whyMissing(loader, key, `the relay Worker needs ${what} — add one`));
13038
13134
  if (wantsErrors) errors = loader.get("errors");
13039
13135
  workers = loader.get("workers");
13040
13136
  dns = loader.get("dns");
13041
- for (const { id, spec } of declaredSources) sourceProviders.set(id, loader.get(spec.capability));
13137
+ for (const source of declaredSources) {
13138
+ const resolved = await resolveRelaySourceProvider({
13139
+ loader,
13140
+ config: input$1.loaded.resolved,
13141
+ repoRoot: input$1.context.repoRoot,
13142
+ source,
13143
+ ...input$1.workspaceProviders ? { workspace: input$1.workspaceProviders } : {}
13144
+ });
13145
+ if (!resolved.provider) return refuse(resolved.problem);
13146
+ if (source.spec.provider !== void 0 && !dryRun) try {
13147
+ await resolved.provider.inspectRelaySource?.(inspectInputOf(source));
13148
+ } catch (err) {
13149
+ if (err instanceof AuthError) return refuse(`relay source \`${source.id}\`: provider \`${source.spec.provider}\` has no token — ${describeError(err)}`);
13150
+ }
13151
+ sourceProviders.set(source.id, resolved.provider);
13152
+ }
13042
13153
  const clash = relayProblem(layout, errors, monitoring) ?? relaySourcesProblem(layout, errors?.providerName);
13043
13154
  if (clash) return refuse(clash);
13044
13155
  }
@@ -13350,14 +13461,7 @@ async function runNotificationsSetup(input$1) {
13350
13461
  const provider = sourceProviders.get(source.id);
13351
13462
  if (!provider.inspectRelaySource || !relayWebhooks.has(source.id)) continue;
13352
13463
  try {
13353
- if (!(await provider.inspectRelaySource({
13354
- source: source.id,
13355
- url: `https://${layout.relay.host}/${source.id}`,
13356
- name: source.spec.name ?? source.id.charAt(0).toUpperCase() + source.id.slice(1),
13357
- ...source.spec.events ? { events: source.spec.events } : {},
13358
- ...source.spec.scope ? { scope: source.spec.scope } : {},
13359
- ...source.spec.options ? { options: source.spec.options } : {}
13360
- })).exists) chosen.set(source.id, newRelaySecret());
13464
+ if (!(await provider.inspectRelaySource(inspectInputOf(source))).exists) chosen.set(source.id, newRelaySecret());
13361
13465
  } catch {}
13362
13466
  }
13363
13467
  if (chosen.size > 0) {
@@ -14942,8 +15046,16 @@ async function runDoctorNotifications(input) {
14942
15046
  }));
14943
15047
  checks.push(...await relaySourceChecks({
14944
15048
  layout,
14945
- provider: (capability) => loader.has(capability) ? loader.get(capability) : void 0,
14946
- missingReason: (capability) => whyMissing(loader, capability, `no \`${capability}\` provider is configured`)
15049
+ resolve: async (source) => {
15050
+ const resolved = await resolveRelaySourceProvider({
15051
+ loader,
15052
+ config: input.loaded.resolved,
15053
+ repoRoot: input.context.repoRoot,
15054
+ source,
15055
+ ...input.workspaceProviders ? { workspace: input.workspaceProviders } : {}
15056
+ });
15057
+ return resolved.provider || source.spec.provider !== void 0 ? resolved : { problem: whyMissing(loader, source.spec.capability, `no \`${source.spec.capability}\` provider is configured`) };
15058
+ }
14947
15059
  }));
14948
15060
  const withHook = (layout.categories ?? []).flatMap((cat) => (cat.channels ?? []).filter((c) => c.webhook).map((channel) => ({
14949
15061
  cat,
@@ -18551,11 +18663,6 @@ async function runProbe(input) {
18551
18663
  rows
18552
18664
  };
18553
18665
  }
18554
- // src/commands/provider-tuples/provider-tuples.ts
18555
- /** The providers a config names, in the order it names them: one tuple per capability entry, so a provider named twice appears twice. */
18556
- function providerTuples(providers) {
18557
- return Object.values(providers).flatMap((entry) => entry.cardinality === "single" ? [entry.tuple] : entry.tuples);
18558
- }
18559
18666
  // src/commands/token-rotation/token-rotation.ts
18560
18667
  /** The rotation policy of a token that declares none: a token is due after 90 days, and an expiry is flagged 14 days ahead. */
18561
18668
  const DEFAULT_TOKEN_ROTATION = {
@@ -18593,27 +18700,6 @@ function tokenExpectations(tokens, filter = {}) {
18593
18700
  }
18594
18701
  return found;
18595
18702
  }
18596
- // src/commands/workspace-providers/workspace-providers.ts
18597
- /**
18598
- * The providers the configs of the workspace's packages name (`apps/sentinel` names `vercel` for its `deployment`) that
18599
- * `config` does not: what `doctor tokens` and `probe` load by name next to the repo's own, so the token a package's
18600
- * provider needs is checked from the root. Nothing is written and the root config needs no key for it. The first
18601
- * package to name a provider supplies its options (its `teamId`, from the shared `org` area). A package whose config
18602
- * cannot be read is left out: its own commands report it.
18603
- */
18604
- async function workspaceProviders(repoRoot, config) {
18605
- const known = new Set(providerTuples(config.providers).map((t) => t.provider));
18606
- const found = [];
18607
- for (const pkg of await readWorkspaceConfigs(repoRoot)) {
18608
- if ("error" in pkg) continue;
18609
- for (const tuple of providerTuples(pkg.resolved.providers)) {
18610
- if (known.has(tuple.provider)) continue;
18611
- known.add(tuple.provider);
18612
- found.push(tuple);
18613
- }
18614
- }
18615
- return found;
18616
- }
18617
18703
  // src/commands/doctor-tokens/summarise-probe-rows.ts
18618
18704
  /**
18619
18705
  * Folds what one token probe reported into the one row the doctor shows for that token in that layer. A failing probe row