@theholocron/cli 5.0.0-alpha.214 → 5.0.0-alpha.215

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
@@ -548,7 +548,7 @@ commands and the config are provider-neutral; Discord is the first provider.
548
548
  | `holocron notifications sync-roles` | Makes who holds a role match a GitHub team, through the links file (`--keep` only adds; `--provider` picks one) |
549
549
  | `holocron doctor notifications [--built-only] [--deliver]` | Step by step: does the server match the layout, do the secrets exist, and does a person (not the bot) own it. A full run also leaves one `🧪 test:` post in the layout's `testChannel`; `--built-only` posts nothing; `--deliver` posts to every channel and removes each post |
550
550
 
551
- Channels fed by another service are declared with `feeds` on the channel: `{ name: "uptime", webhook: true, feeds: { monitoring: true } }` (the object form `{ name?, webhook? }` overrides the alert channel's name, default `Discord #<channel>`, and the dedicated webhook's name, default the provider's). `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). 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).
551
+ 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? }` overrides the alert channel's name, default `Discord #<channel>`, the dedicated webhook's name, default the provider's, and gives that webhook a picture, a file path or `https://` URL, else the layout's `webhookAvatar`). `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). 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).
552
552
 
553
553
  Pinned messages are declared under the provider's `layout` as `pinned: [{ channel, content }]` (`channel` is a channel in the layout, `content` up to 2000 characters); the layout is the whole set of messages the bot has pinned in those channels.
554
554
 
package/dist/cli.mjs CHANGED
@@ -2685,6 +2685,19 @@ const SIGNATURES = [
2685
2685
  ]]
2686
2686
  ];
2687
2687
  const tooBig = () => /* @__PURE__ */ new Error(`it is larger than ${MAX_AVATAR_BYTES / 1024 / 1024} MB`);
2688
+ /**
2689
+ * A source safe to print: an `https://` URL loses its credentials (userinfo), query and fragment, which is where signed
2690
+ * links keep their tokens. A file path is returned as written.
2691
+ */
2692
+ function describeAvatarSource(source) {
2693
+ if (!/^https:\/\//i.test(source)) return source;
2694
+ try {
2695
+ const url = new URL(source);
2696
+ return `${url.protocol}//${url.host}${url.pathname}`;
2697
+ } catch {
2698
+ return "an unreadable https URL";
2699
+ }
2700
+ }
2688
2701
  async function loadAvatar(source, baseDir = process.cwd(), fetchImpl = fetch) {
2689
2702
  let bytes;
2690
2703
  if (/^https:\/\//i.test(source)) {
@@ -2915,8 +2928,16 @@ async function provisionFeed(deps, spec, feed, outcome) {
2915
2928
  const hook = await notifications.ensureWebhook({
2916
2929
  channel: spec.name,
2917
2930
  name: feed.webhook,
2918
- ...spec.category ? { category: spec.category } : {}
2931
+ ...spec.category ? { category: spec.category } : {},
2932
+ ...feed.avatar ? { avatar: feed.avatar } : {}
2919
2933
  });
2934
+ const avatarSet = hook.updated?.includes("avatar") ?? false;
2935
+ print(` ${(hook.created || avatarSet ? style.success : style.skip)(`${hook.created ? "created" : "found "} webhook ${feed.webhook}${avatarSet ? " (avatar set)" : ""}`)}`);
2936
+ if (tally) {
2937
+ const done = Number(hook.created) + Number(avatarSet);
2938
+ if (done > 0) tally.ok += done;
2939
+ else tally.skip++;
2940
+ }
2920
2941
  let result;
2921
2942
  try {
2922
2943
  result = await monitoring.ensureAlertChannel({
@@ -2939,6 +2960,7 @@ async function provisionFeed(deps, spec, feed, outcome) {
2939
2960
  updated: result.updated,
2940
2961
  subscribed: result.subscribed
2941
2962
  };
2963
+ if (hook.avatarError) throw new Error(`webhook ${feed.webhook} is ready but setting its avatar failed (${hook.avatarError})`);
2942
2964
  }
2943
2965
  async function runNotificationsChannelAdd(input) {
2944
2966
  const print = input.print ?? ((line) => console.log(line));
@@ -4872,6 +4894,10 @@ async function withElevation(run, deps) {
4872
4894
  function webhookAvatarOf(layout, webhook) {
4873
4895
  return (typeof webhook === "object" ? webhook.avatar : void 0) ?? layout.webhookAvatar;
4874
4896
  }
4897
+ /** The picture a feed's webhook should have: its own, else the layout's, else none. */
4898
+ function feedAvatarOf(layout, feed) {
4899
+ return (typeof feed === "object" ? feed.avatar : void 0) ?? layout.webhookAvatar;
4900
+ }
4875
4901
  /** The names a channel's monitoring feed uses: the alert channel (`Discord #uptime`) and its dedicated webhook (`Checkly`). */
4876
4902
  function monitoringFeed(channel, feed, monitoring) {
4877
4903
  const own = typeof feed === "object" ? feed : {};
@@ -5054,12 +5080,15 @@ async function runNotificationsSetup(input$1) {
5054
5080
  const avatars = /* @__PURE__ */ new Map();
5055
5081
  const read = input$1.loadAvatar ?? loadAvatar;
5056
5082
  for (const channel of (layout.categories ?? []).flatMap((c) => c.channels ?? [])) {
5057
- const source = channel.webhook ? webhookAvatarOf(layout, channel.webhook) : void 0;
5058
- if (source === void 0 || avatars.has(source)) continue;
5059
- try {
5060
- avatars.set(source, await read(source));
5061
- } catch (err) {
5062
- return refuse(`webhook avatar \`${source}\`: ${errorMessage(err)}`);
5083
+ const feed = channel.feeds?.monitoring;
5084
+ const sources = [channel.webhook ? webhookAvatarOf(layout, channel.webhook) : void 0, feed ? feedAvatarOf(layout, feed) : void 0];
5085
+ for (const source of sources) {
5086
+ if (source === void 0 || avatars.has(source)) continue;
5087
+ try {
5088
+ avatars.set(source, await read(source));
5089
+ } catch (err) {
5090
+ return refuse(`webhook avatar \`${describeAvatarSource(source)}\`: ${errorMessage(err)}`);
5091
+ }
5063
5092
  }
5064
5093
  }
5065
5094
  if (secrets && scope && !dryRun) try {
@@ -5189,7 +5218,10 @@ async function runNotificationsSetup(input$1) {
5189
5218
  ...channel.topic ? { topic: channel.topic } : {},
5190
5219
  ...effectiveAccess(category.access, channel.access) ? { access: effectiveAccess(category.access, channel.access) } : {},
5191
5220
  ...webhook ? { webhook } : {},
5192
- ...channel.feeds?.monitoring ? { feeds: { monitoring: monitoringFeed(channel.name, channel.feeds.monitoring, monitoring) } } : {}
5221
+ ...channel.feeds?.monitoring ? { feeds: { monitoring: {
5222
+ ...monitoringFeed(channel.name, channel.feeds.monitoring, monitoring),
5223
+ ...feedAvatarOf(layout, channel.feeds.monitoring) ? { avatar: avatars.get(feedAvatarOf(layout, channel.feeds.monitoring)) } : {}
5224
+ } } } : {}
5193
5225
  });
5194
5226
  report.channels.push(outcome);
5195
5227
  if (outcome.webhook && !outcome.webhook.stored) report.failures.push({