@theholocron/holocron-plugin-slack 5.0.0-alpha.25 → 5.0.0-alpha.250
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 +15 -49
- package/dist/index.mjs +18 -38
- package/package.json +18 -14
package/dist/index.d.mts
CHANGED
|
@@ -1,34 +1,11 @@
|
|
|
1
|
-
import { AuthError, Notifications, ResolveTokenInput } from "@theholocron/cli";
|
|
2
|
-
|
|
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, ResolveTokenInput, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess } from "@theholocron/cli";
|
|
2
|
+
import { SlackClient, SlackClientOptions, createSlackClient } from "@theholocron/slack-client";
|
|
3
|
+
export declare const resolveToken: (input?: ResolveTokenInput) => string;
|
|
27
4
|
interface SlackNotificationsOptions {
|
|
28
5
|
/** Default channel id used when `send()` is called without an explicit channel. */
|
|
29
6
|
defaultChannel?: string;
|
|
30
7
|
}
|
|
31
|
-
declare class SlackNotifications implements Notifications {
|
|
8
|
+
export declare class SlackNotifications implements Notifications {
|
|
32
9
|
/** Memoized client thunk — resolves the token on first authenticated call. */
|
|
33
10
|
private readonly client;
|
|
34
11
|
private readonly opts;
|
|
@@ -39,42 +16,31 @@ declare class SlackNotifications implements Notifications {
|
|
|
39
16
|
client: () => SlackClient, opts: SlackNotificationsOptions);
|
|
40
17
|
send(channel: string, message: string): Promise<void>;
|
|
41
18
|
}
|
|
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
19
|
interface VerifyTokenOptions {
|
|
54
20
|
baseUrl?: string;
|
|
55
21
|
fetch?: typeof fetch;
|
|
56
22
|
}
|
|
57
|
-
declare function verifyToken(token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult>;
|
|
58
|
-
|
|
59
|
-
//#region src/index.d.ts
|
|
60
|
-
interface SlackPluginOptions extends ResolveTokenInput, SlackNotificationsOptions {
|
|
23
|
+
export declare function verifyToken(token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult$1>;
|
|
24
|
+
export interface SlackPluginOptions extends ResolveTokenInput, SlackNotificationsOptions {
|
|
61
25
|
/** Override base URL for tests. Default: https://slack.com/api */
|
|
62
26
|
baseUrl?: string;
|
|
63
27
|
fetch?: typeof fetch;
|
|
64
28
|
}
|
|
65
|
-
interface PluginContext {
|
|
29
|
+
export interface PluginContext {
|
|
66
30
|
options: SlackPluginOptions;
|
|
67
31
|
/** Memoized client — the token is resolved on first use, not at plugin load. */
|
|
68
32
|
client: () => SlackClient;
|
|
69
33
|
}
|
|
70
|
-
declare function createContext(options?: SlackPluginOptions): PluginContext;
|
|
71
|
-
declare function notifications(ctx: PluginContext): Notifications;
|
|
72
|
-
declare function createPlugin(options?: SlackPluginOptions): {
|
|
34
|
+
export declare function createContext(options?: SlackPluginOptions): PluginContext;
|
|
35
|
+
export declare function notifications(ctx: PluginContext): Notifications;
|
|
36
|
+
export declare function createPlugin(options?: SlackPluginOptions): {
|
|
73
37
|
name: string;
|
|
38
|
+
probes: {
|
|
39
|
+
connection: import("@theholocron/cli").Probe;
|
|
40
|
+
};
|
|
74
41
|
capabilities: {
|
|
75
42
|
notifications: () => Notifications;
|
|
76
43
|
};
|
|
77
44
|
};
|
|
78
|
-
declare const AUTH_HINT: string;
|
|
79
|
-
|
|
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 };
|
|
45
|
+
export declare const AUTH_HINT: string;
|
|
46
|
+
export { AuthError, type ResolveTokenInput, type SlackClient, type SlackClientOptions, type SlackNotificationsOptions, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, createSlackClient };
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { AuthError,
|
|
2
|
-
|
|
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
|
|
3
5
|
const resolveToken = createResolveToken({
|
|
4
6
|
envName: "HOLOCRON_SLACK_TOKEN",
|
|
5
7
|
vendorEnvName: "SLACK_BOT_TOKEN",
|
|
6
8
|
keyringService: "slack",
|
|
7
9
|
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
10
|
});
|
|
9
|
-
|
|
10
|
-
//#region src/capabilities/notifications.ts
|
|
11
|
+
// src/capabilities/notifications.ts
|
|
11
12
|
var SlackNotifications = class {
|
|
12
13
|
client;
|
|
13
14
|
opts;
|
|
@@ -23,36 +24,7 @@ var SlackNotifications = class {
|
|
|
23
24
|
await this.client().chat.postMessage(ch, message);
|
|
24
25
|
}
|
|
25
26
|
};
|
|
26
|
-
|
|
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
|
|
27
|
+
// src/verify-token.ts
|
|
56
28
|
async function verifyToken(token, opts = {}) {
|
|
57
29
|
const client = createSlackClient({
|
|
58
30
|
token,
|
|
@@ -68,12 +40,11 @@ async function verifyToken(token, opts = {}) {
|
|
|
68
40
|
} catch (err) {
|
|
69
41
|
return {
|
|
70
42
|
ok: false,
|
|
71
|
-
message:
|
|
43
|
+
message: errorMessage(err)
|
|
72
44
|
};
|
|
73
45
|
}
|
|
74
46
|
}
|
|
75
|
-
|
|
76
|
-
//#region src/index.ts
|
|
47
|
+
// src/index.ts
|
|
77
48
|
function createContext(options = {}) {
|
|
78
49
|
let client;
|
|
79
50
|
return {
|
|
@@ -92,9 +63,18 @@ function createPlugin(options = {}) {
|
|
|
92
63
|
const ctx = createContext(options);
|
|
93
64
|
return {
|
|
94
65
|
name: "@theholocron/holocron-plugin-slack",
|
|
66
|
+
probes: { connection: connectionProbe({
|
|
67
|
+
provider: "Slack",
|
|
68
|
+
url: options.baseUrl ?? "https://slack.com",
|
|
69
|
+
fetch: options.fetch,
|
|
70
|
+
token: () => resolveToken(options),
|
|
71
|
+
verify: (token) => verifyToken(token, {
|
|
72
|
+
baseUrl: options.baseUrl,
|
|
73
|
+
fetch: options.fetch
|
|
74
|
+
})
|
|
75
|
+
}) },
|
|
95
76
|
capabilities: { notifications: () => notifications(ctx) }
|
|
96
77
|
};
|
|
97
78
|
}
|
|
98
79
|
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
80
|
export { AUTH_HINT, AuthError, SlackNotifications, createContext, createPlugin, createSlackClient, notifications, resolveToken, verifyToken };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/holocron-plugin-slack",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.250",
|
|
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/
|
|
11
|
+
"homepage": "https://github.com/theholocron/holocron/tree/main/plugins/holocron-plugin-slack#readme",
|
|
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": "
|
|
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.
|
|
34
|
-
"@theholocron/http-client": "^1.
|
|
35
|
-
"@theholocron/
|
|
36
|
-
"@theholocron/
|
|
37
|
-
"@theholocron/
|
|
33
|
+
"@theholocron/eslint-config": "^8.8.2",
|
|
34
|
+
"@theholocron/http-client": "^1.57.0",
|
|
35
|
+
"@theholocron/misc-utils": "^1.16.0",
|
|
36
|
+
"@theholocron/slack-client": "^1.43.1",
|
|
37
|
+
"@theholocron/tsconfig": "^8.8.2",
|
|
38
|
+
"@theholocron/tsdown-config": "^8.8.2",
|
|
39
|
+
"@theholocron/vitest-config": "^8.8.2",
|
|
38
40
|
"@types/node": "^26",
|
|
39
|
-
"@vitest/coverage-v8": "^
|
|
41
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
40
42
|
"@vitest/eslint-plugin": "^1.6.27",
|
|
41
43
|
"chalk": "^6.0.0",
|
|
42
44
|
"eslint": "^10.8.1",
|
|
43
45
|
"eslint-plugin-n": "^18.3.0",
|
|
44
46
|
"globals": "^17.11.0",
|
|
45
|
-
"tsdown": "^0.
|
|
46
|
-
"tsx": "4.23.
|
|
47
|
+
"tsdown": "^0.23.3",
|
|
48
|
+
"tsx": "4.23.15",
|
|
47
49
|
"typescript": "^5.9.3",
|
|
48
|
-
"vitest": "^
|
|
49
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
50
|
+
"vitest": "^5.0.5",
|
|
51
|
+
"@theholocron/cli": "5.0.0-alpha.250"
|
|
50
52
|
},
|
|
51
53
|
"peerDependencies": {
|
|
52
|
-
"@theholocron/
|
|
54
|
+
"@theholocron/misc-utils": "^1.16.0",
|
|
55
|
+
"@theholocron/slack-client": "^1.43.1",
|
|
56
|
+
"@theholocron/cli": "5.0.0-alpha.250"
|
|
53
57
|
},
|
|
54
58
|
"engines": {
|
|
55
59
|
"node": ">=22"
|