@theholocron/holocron-plugin-slack 5.0.0-alpha.28 → 5.0.0-alpha.280

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.d.mts CHANGED
@@ -1,80 +1,62 @@
1
- import { AuthError, Notifications, ResolveTokenInput } from "@theholocron/cli";
2
- //#region src/auth.d.ts
3
- declare const resolveToken: (input?: ResolveTokenInput) => string;
4
- //#endregion
5
- //#region src/rest.d.ts
6
- interface SlackClientOptions {
7
- token: string;
8
- /** Override base URL for tests. Default: https://slack.com/api */
9
- baseUrl?: string;
10
- fetch?: typeof fetch;
11
- }
12
- interface SlackClient {
13
- auth: {
14
- test(): Promise<{
15
- ok: true;
16
- team: string;
17
- user: string;
18
- }>;
19
- };
20
- chat: {
21
- postMessage(channel: string, text: string): Promise<void>;
22
- };
23
- }
24
- declare function createSlackClient({ token, baseUrl, fetch: fetchImpl }: SlackClientOptions): SlackClient;
25
- //#endregion
26
- //#region src/capabilities/notifications.d.ts
1
+ import { AuthError, Notifications, PluginToken, ResolveTokenInput, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess } from "@theholocron/cli";
2
+ import { SlackClient, SlackClientOptions, createSlackClient } from "@theholocron/slack-client";
3
+ /** Resolves the Slack bot token from `--token`, `HOLOCRON_SLACK_TOKEN`, `SLACK_BOT_TOKEN` or the keyring entry for `slack`, and throws `AuthError` when none is set. */
4
+ export declare const resolveToken: import("@theholocron/cli").TokenResolver;
5
+ /** Every token this plugin takes, for `holocron doctor tokens`. */
6
+ export declare const tokens: PluginToken[];
7
+ /** Options for the Slack `notifications` capability. */
27
8
  interface SlackNotificationsOptions {
28
9
  /** Default channel id used when `send()` is called without an explicit channel. */
29
10
  defaultChannel?: string;
30
11
  }
31
- declare class SlackNotifications implements Notifications {
12
+ /** `notifications` capability for Slack: posts messages to a channel as the bot. */
13
+ export declare class SlackNotifications implements Notifications {
32
14
  /** Memoized client thunk — resolves the token on first authenticated call. */
33
15
  private readonly client;
34
16
  private readonly opts;
17
+ /** Capability key; always `"notifications"`. */
35
18
  readonly key: "notifications";
19
+ /** Provider name; always `"slack"`. */
36
20
  readonly providerName = "slack";
37
21
  constructor(
38
22
  /** Memoized client thunk — resolves the token on first authenticated call. */
39
23
  client: () => SlackClient, opts: SlackNotificationsOptions);
40
24
  send(channel: string, message: string): Promise<void>;
41
25
  }
42
- //#endregion
43
- //#region src/verify-token.d.ts
44
- interface VerifyTokenSuccess {
45
- ok: true;
46
- subject: string;
47
- }
48
- interface VerifyTokenFailure {
49
- ok: false;
50
- message: string;
51
- }
52
- type VerifyTokenResult = VerifyTokenSuccess | VerifyTokenFailure;
53
26
  interface VerifyTokenOptions {
54
27
  baseUrl?: string;
55
28
  fetch?: typeof fetch;
56
29
  }
57
- declare function verifyToken(token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult>;
58
- //#endregion
59
- //#region src/index.d.ts
60
- interface SlackPluginOptions extends ResolveTokenInput, SlackNotificationsOptions {
30
+ /** Checks a Slack bot token with `auth.test` and reports the bot user and workspace, or why it was rejected. */
31
+ export declare function verifyToken(token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult$1>;
32
+ /** Options for the Slack plugin: the token lookup inputs plus the notification defaults. */
33
+ export interface SlackPluginOptions extends ResolveTokenInput, SlackNotificationsOptions {
61
34
  /** Override base URL for tests. Default: https://slack.com/api */
62
35
  baseUrl?: string;
36
+ /** Override `fetch` for tests. */
63
37
  fetch?: typeof fetch;
64
38
  }
65
- interface PluginContext {
39
+ /** Shared state for one Slack plugin instance: its options and a lazily created client. */
40
+ export interface PluginContext {
41
+ /** The options the plugin was created with. */
66
42
  options: SlackPluginOptions;
67
43
  /** Memoized client — the token is resolved on first use, not at plugin load. */
68
44
  client: () => SlackClient;
69
45
  }
70
- declare function createContext(options?: SlackPluginOptions): PluginContext;
71
- declare function notifications(ctx: PluginContext): Notifications;
72
- declare function createPlugin(options?: SlackPluginOptions): {
46
+ /** Builds the plugin context from its options. */
47
+ export declare function createContext(options?: SlackPluginOptions): PluginContext;
48
+ /** Builds the `notifications` capability for the context. */
49
+ export declare function notifications(ctx: PluginContext): Notifications;
50
+ /** Creates the Slack plugin: its `connection` probe and the `notifications` capability. */
51
+ export declare function createPlugin(options?: SlackPluginOptions): {
73
52
  name: string;
53
+ probes: {
54
+ connection: import("@theholocron/cli").Probe;
55
+ };
74
56
  capabilities: {
75
57
  notifications: () => Notifications;
76
58
  };
77
59
  };
78
- declare const AUTH_HINT: string;
79
- //#endregion
80
- export { AUTH_HINT, AuthError, PluginContext, type ResolveTokenInput, type SlackClient, type SlackClientOptions, SlackNotifications, type SlackNotificationsOptions, SlackPluginOptions, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, createContext, createPlugin, createSlackClient, notifications, resolveToken, verifyToken };
60
+ /** Hint printed by `holocron auth set slack` when no token is supplied or the token is rejected; explains how to create a bot token. */
61
+ export declare const AUTH_HINT: string;
62
+ export { AuthError, type ResolveTokenInput, type SlackClient, type SlackClientOptions, type SlackNotificationsOptions, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, createSlackClient };
package/dist/index.mjs CHANGED
@@ -1,17 +1,24 @@
1
- import { AuthError, ProviderApiError, createResolveToken } from "@theholocron/cli";
2
- //#region src/auth.ts
1
+ import { AuthError, connectionProbe, createResolveToken } from "@theholocron/cli";
2
+ import { createSlackClient } from "@theholocron/slack-client";
3
+ import { errorMessage } from "@theholocron/misc-utils";
4
+ // src/auth.ts
5
+ /** Resolves the Slack bot token from `--token`, `HOLOCRON_SLACK_TOKEN`, `SLACK_BOT_TOKEN` or the keyring entry for `slack`, and throws `AuthError` when none is set. */
3
6
  const resolveToken = createResolveToken({
4
7
  envName: "HOLOCRON_SLACK_TOKEN",
5
8
  vendorEnvName: "SLACK_BOT_TOKEN",
6
9
  keyringService: "slack",
7
10
  errorMessage: "no Slack bot token found. Pass --token <TOKEN>, set HOLOCRON_SLACK_TOKEN / SLACK_BOT_TOKEN, or run: holocron auth set slack <xoxb-TOKEN>"
8
11
  });
9
- //#endregion
10
- //#region src/capabilities/notifications.ts
12
+ /** Every token this plugin takes, for `holocron doctor tokens`. */
13
+ const tokens = [resolveToken.token];
14
+ // src/capabilities/notifications.ts
15
+ /** `notifications` capability for Slack: posts messages to a channel as the bot. */
11
16
  var SlackNotifications = class {
12
17
  client;
13
18
  opts;
19
+ /** Capability key; always `"notifications"`. */
14
20
  key = "notifications";
21
+ /** Provider name; always `"slack"`. */
15
22
  providerName = "slack";
16
23
  constructor(client, opts) {
17
24
  this.client = client;
@@ -23,36 +30,8 @@ var SlackNotifications = class {
23
30
  await this.client().chat.postMessage(ch, message);
24
31
  }
25
32
  };
26
- //#endregion
27
- //#region src/rest.ts
28
- function createSlackClient({ token, baseUrl, fetch: fetchImpl }) {
29
- const base = baseUrl ?? "https://slack.com/api";
30
- const f = fetchImpl ?? globalThis.fetch;
31
- async function call(method, body) {
32
- const res = await f(`${base}/${method}`, {
33
- method: "POST",
34
- headers: {
35
- "content-type": "application/json; charset=utf-8",
36
- authorization: `Bearer ${token}`
37
- },
38
- body: JSON.stringify(body)
39
- });
40
- const data = await res.json();
41
- if (!data.ok) throw new ProviderApiError(data.error ?? "unknown Slack error", res.status, data);
42
- return data;
43
- }
44
- return {
45
- auth: { test: () => call("auth.test", {}) },
46
- chat: { postMessage: async (channel, text) => {
47
- await call("chat.postMessage", {
48
- channel,
49
- text
50
- });
51
- } }
52
- };
53
- }
54
- //#endregion
55
- //#region src/verify-token.ts
33
+ // src/verify-token.ts
34
+ /** Checks a Slack bot token with `auth.test` and reports the bot user and workspace, or why it was rejected. */
56
35
  async function verifyToken(token, opts = {}) {
57
36
  const client = createSlackClient({
58
37
  token,
@@ -68,12 +47,12 @@ async function verifyToken(token, opts = {}) {
68
47
  } catch (err) {
69
48
  return {
70
49
  ok: false,
71
- message: err instanceof Error ? err.message : String(err)
50
+ message: errorMessage(err)
72
51
  };
73
52
  }
74
53
  }
75
- //#endregion
76
- //#region src/index.ts
54
+ // src/index.ts
55
+ /** Builds the plugin context from its options. */
77
56
  function createContext(options = {}) {
78
57
  let client;
79
58
  return {
@@ -85,16 +64,28 @@ function createContext(options = {}) {
85
64
  })
86
65
  };
87
66
  }
67
+ /** Builds the `notifications` capability for the context. */
88
68
  function notifications(ctx) {
89
69
  return new SlackNotifications(ctx.client, ctx.options);
90
70
  }
71
+ /** Creates the Slack plugin: its `connection` probe and the `notifications` capability. */
91
72
  function createPlugin(options = {}) {
92
73
  const ctx = createContext(options);
93
74
  return {
94
75
  name: "@theholocron/holocron-plugin-slack",
76
+ probes: { connection: connectionProbe({
77
+ provider: "Slack",
78
+ url: options.baseUrl ?? "https://slack.com",
79
+ fetch: options.fetch,
80
+ token: () => resolveToken(options),
81
+ verify: (token) => verifyToken(token, {
82
+ baseUrl: options.baseUrl,
83
+ fetch: options.fetch
84
+ })
85
+ }) },
95
86
  capabilities: { notifications: () => notifications(ctx) }
96
87
  };
97
88
  }
89
+ /** Hint printed by `holocron auth set slack` when no token is supplied or the token is rejected; explains how to create a bot token. */
98
90
  const AUTH_HINT = "create a Slack app at https://api.slack.com/apps, add the chat:write bot scope, install it to your workspace, copy the Bot User OAuth Token (xoxb-...), then run: holocron auth set slack <xoxb-TOKEN>";
99
- //#endregion
100
- export { AUTH_HINT, AuthError, SlackNotifications, createContext, createPlugin, createSlackClient, notifications, resolveToken, verifyToken };
91
+ export { AUTH_HINT, AuthError, SlackNotifications, createContext, createPlugin, createSlackClient, notifications, resolveToken, tokens, verifyToken };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-slack",
3
- "version": "5.0.0-alpha.28",
3
+ "version": "5.0.0-alpha.280",
4
4
  "description": "Holocron plugin for Slack. Implements the notifications capability via Slack's bot API.",
5
5
  "keywords": [
6
6
  "holocron",
@@ -8,12 +8,12 @@
8
8
  "plugin",
9
9
  "slack"
10
10
  ],
11
- "homepage": "https://github.com/theholocron/holocron/tree/main/packages/holocron-plugin-slack#readme",
11
+ "homepage": "https://docs.theholocron.dev/holocron/plugins/slack/",
12
12
  "bugs": "https://github.com/theholocron/holocron/issues",
13
13
  "repository": {
14
14
  "type": "git",
15
15
  "url": "git+https://github.com/theholocron/holocron.git",
16
- "directory": "packages/holocron-plugin-slack"
16
+ "directory": "plugins/holocron-plugin-slack"
17
17
  },
18
18
  "license": "MIT",
19
19
  "author": "Newton Koumantzelis",
@@ -30,26 +30,30 @@
30
30
  "dist"
31
31
  ],
32
32
  "devDependencies": {
33
- "@theholocron/eslint-config": "^8.0.0",
34
- "@theholocron/http-client": "^1.23.0",
35
- "@theholocron/tsconfig": "^8.0.0",
36
- "@theholocron/tsdown-config": "^8.0.0",
37
- "@theholocron/vitest-config": "^8.0.0",
38
33
  "@types/node": "^26",
39
- "@vitest/coverage-v8": "^4.1.11",
34
+ "@vitest/coverage-v8": "^5.0.5",
40
35
  "@vitest/eslint-plugin": "^1.6.27",
41
36
  "chalk": "^6.0.0",
42
37
  "eslint": "^10.8.1",
43
38
  "eslint-plugin-n": "^18.3.0",
44
39
  "globals": "^17.11.0",
45
- "tsdown": "^0.22.14",
46
- "tsx": "4.23.12",
40
+ "tsdown": "^0.23.3",
41
+ "tsx": "4.23.15",
47
42
  "typescript": "^5.9.3",
48
- "vitest": "^4.1.11",
49
- "@theholocron/cli": "5.0.0-alpha.28"
43
+ "vitest": "^5.0.5",
44
+ "@theholocron/cli": "5.0.0-alpha.280",
45
+ "@theholocron/http-client": "^1.58.0-alpha.3",
46
+ "@theholocron/eslint-config": "^8.9.0-alpha.4",
47
+ "@theholocron/misc-utils": "^1.16.1-alpha.3",
48
+ "@theholocron/slack-client": "^1.58.0-alpha.3",
49
+ "@theholocron/tsconfig": "^8.9.0-alpha.4",
50
+ "@theholocron/tsdown-config": "^8.9.0-alpha.4",
51
+ "@theholocron/vitest-config": "^8.9.0-alpha.4"
50
52
  },
51
53
  "peerDependencies": {
52
- "@theholocron/cli": "5.0.0-alpha.28"
54
+ "@theholocron/misc-utils": "^1.16.0",
55
+ "@theholocron/slack-client": "^1.43.1",
56
+ "@theholocron/cli": "5.0.0-alpha.280"
53
57
  },
54
58
  "engines": {
55
59
  "node": ">=22"
@@ -59,10 +63,10 @@
59
63
  },
60
64
  "scripts": {
61
65
  "delivery.build": "tsdown",
62
- "sourceQuality.staticAnalysis": "holocron run sourceQuality.staticAnalysis --",
66
+ "sourceQuality.staticAnalysis": "eslint .",
63
67
  "test:watch": "vitest",
64
68
  "validate": "tsx scripts/validate.mjs",
65
- "verification.typeSafety": "holocron run verification.typeSafety --",
66
- "verification.unitTests": "holocron run verification.unitTests --"
69
+ "verification.typeSafety": "tsc --noEmit",
70
+ "verification.unitTests": "vitest run"
67
71
  }
68
72
  }