@theholocron/holocron-plugin-discord 5.0.0-alpha.115 → 5.0.0-alpha.117
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 +3 -35
- package/dist/index.mjs +6 -33
- package/package.json +8 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,31 +1,8 @@
|
|
|
1
|
-
import { AuthError, Notifications, ResolveTokenInput } from "@theholocron/cli";
|
|
1
|
+
import { AuthError, Notifications, ResolveTokenInput, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess } from "@theholocron/cli";
|
|
2
|
+
import { DiscordClient, DiscordClientOptions, DiscordWebhookInfo, createDiscordClient, parseWebhookUrl } from "@theholocron/discord-client";
|
|
2
3
|
//#region src/auth.d.ts
|
|
3
4
|
declare const resolveToken: (input?: ResolveTokenInput) => string;
|
|
4
5
|
//#endregion
|
|
5
|
-
//#region src/rest.d.ts
|
|
6
|
-
interface DiscordClientOptions {
|
|
7
|
-
/** Override base URL for tests. Default: https://discord.com/api/v10 */
|
|
8
|
-
baseUrl?: string;
|
|
9
|
-
fetch?: typeof fetch;
|
|
10
|
-
}
|
|
11
|
-
interface DiscordWebhookInfo {
|
|
12
|
-
id: string;
|
|
13
|
-
name: string;
|
|
14
|
-
guild_id?: string;
|
|
15
|
-
}
|
|
16
|
-
interface DiscordClient {
|
|
17
|
-
webhooks: {
|
|
18
|
-
get(id: string, token: string): Promise<DiscordWebhookInfo>;
|
|
19
|
-
execute(id: string, token: string, content: string): Promise<void>;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
declare function createDiscordClient({ baseUrl, fetch: fetchImpl }?: DiscordClientOptions): DiscordClient;
|
|
23
|
-
/** Parse a Discord webhook URL into its id and token parts. */
|
|
24
|
-
declare function parseWebhookUrl(url: string): {
|
|
25
|
-
id: string;
|
|
26
|
-
token: string;
|
|
27
|
-
};
|
|
28
|
-
//#endregion
|
|
29
6
|
//#region src/capabilities/notifications.d.ts
|
|
30
7
|
interface DiscordNotificationsOptions {
|
|
31
8
|
/**
|
|
@@ -54,20 +31,11 @@ declare class DiscordNotifications implements Notifications {
|
|
|
54
31
|
}
|
|
55
32
|
//#endregion
|
|
56
33
|
//#region src/verify-token.d.ts
|
|
57
|
-
interface VerifyTokenSuccess {
|
|
58
|
-
ok: true;
|
|
59
|
-
subject: string;
|
|
60
|
-
}
|
|
61
|
-
interface VerifyTokenFailure {
|
|
62
|
-
ok: false;
|
|
63
|
-
message: string;
|
|
64
|
-
}
|
|
65
|
-
type VerifyTokenResult = VerifyTokenSuccess | VerifyTokenFailure;
|
|
66
34
|
interface VerifyTokenOptions {
|
|
67
35
|
baseUrl?: string;
|
|
68
36
|
fetch?: typeof fetch;
|
|
69
37
|
}
|
|
70
|
-
declare function verifyToken(webhookUrl: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult>;
|
|
38
|
+
declare function verifyToken(webhookUrl: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult$1>;
|
|
71
39
|
//#endregion
|
|
72
40
|
//#region src/index.d.ts
|
|
73
41
|
interface DiscordPluginOptions extends ResolveTokenInput, DiscordNotificationsOptions {
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { AuthError,
|
|
1
|
+
import { AuthError, createResolveToken } from "@theholocron/cli";
|
|
2
|
+
import { createDiscordClient, parseWebhookUrl } from "@theholocron/discord-client";
|
|
3
|
+
import { errorMessage } from "@theholocron/misc-utils";
|
|
2
4
|
//#region src/auth.ts
|
|
3
5
|
const resolveToken = createResolveToken({
|
|
4
6
|
envName: "HOLOCRON_DISCORD_WEBHOOK",
|
|
@@ -7,36 +9,6 @@ const resolveToken = createResolveToken({
|
|
|
7
9
|
errorMessage: "no Discord webhook URL found. Pass --token <WEBHOOK_URL>, set HOLOCRON_DISCORD_WEBHOOK / DISCORD_WEBHOOK_URL, or run: holocron auth set discord <https://discord.com/api/webhooks/...>"
|
|
8
10
|
});
|
|
9
11
|
//#endregion
|
|
10
|
-
//#region src/rest.ts
|
|
11
|
-
function createDiscordClient({ baseUrl, fetch: fetchImpl } = {}) {
|
|
12
|
-
const base = baseUrl ?? "https://discord.com/api/v10";
|
|
13
|
-
const f = fetchImpl ?? globalThis.fetch;
|
|
14
|
-
return { webhooks: {
|
|
15
|
-
get: async (id, token) => {
|
|
16
|
-
const res = await f(`${base}/webhooks/${id}/${token}`, { method: "GET" });
|
|
17
|
-
if (!res.ok) throw new ProviderApiError(`Discord webhook not found or invalid (${res.status})`, res.status, void 0);
|
|
18
|
-
return res.json();
|
|
19
|
-
},
|
|
20
|
-
execute: async (id, token, content) => {
|
|
21
|
-
const res = await f(`${base}/webhooks/${id}/${token}`, {
|
|
22
|
-
method: "POST",
|
|
23
|
-
headers: { "content-type": "application/json" },
|
|
24
|
-
body: JSON.stringify({ content })
|
|
25
|
-
});
|
|
26
|
-
if (!res.ok) throw new ProviderApiError(`Discord webhook POST failed (${res.status})`, res.status, void 0);
|
|
27
|
-
}
|
|
28
|
-
} };
|
|
29
|
-
}
|
|
30
|
-
/** Parse a Discord webhook URL into its id and token parts. */
|
|
31
|
-
function parseWebhookUrl(url) {
|
|
32
|
-
const match = url.match(/webhooks\/(\d+)\/([^/?#]+)/);
|
|
33
|
-
if (!match) throw new Error(`Invalid Discord webhook URL: ${url}`);
|
|
34
|
-
return {
|
|
35
|
-
id: match[1],
|
|
36
|
-
token: match[2]
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
//#endregion
|
|
40
12
|
//#region src/capabilities/notifications.ts
|
|
41
13
|
var DiscordNotifications = class {
|
|
42
14
|
client;
|
|
@@ -50,7 +22,8 @@ var DiscordNotifications = class {
|
|
|
50
22
|
this.defaultWebhookUrl = defaultWebhookUrl;
|
|
51
23
|
}
|
|
52
24
|
async send(channel, message) {
|
|
53
|
-
const
|
|
25
|
+
const webhookUrl = this.resolve(channel || this.opts.defaultChannel || "");
|
|
26
|
+
const { id, token } = parseWebhookUrl(webhookUrl);
|
|
54
27
|
await this.client.webhooks.execute(id, token, message);
|
|
55
28
|
}
|
|
56
29
|
resolve(channel) {
|
|
@@ -78,7 +51,7 @@ async function verifyToken(webhookUrl, opts = {}) {
|
|
|
78
51
|
} catch (err) {
|
|
79
52
|
return {
|
|
80
53
|
ok: false,
|
|
81
|
-
message:
|
|
54
|
+
message: errorMessage(err)
|
|
82
55
|
};
|
|
83
56
|
}
|
|
84
57
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/holocron-plugin-discord",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.117",
|
|
4
4
|
"description": "Holocron plugin for Discord. Implements the notifications capability via Discord incoming webhooks.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"discord",
|
|
@@ -30,8 +30,10 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"devDependencies": {
|
|
33
|
+
"@theholocron/discord-client": "^1.37.1",
|
|
33
34
|
"@theholocron/eslint-config": "^8.7.0",
|
|
34
|
-
"@theholocron/http-client": "^1.
|
|
35
|
+
"@theholocron/http-client": "^1.38.0",
|
|
36
|
+
"@theholocron/misc-utils": "^1.9.2",
|
|
35
37
|
"@theholocron/tsconfig": "^8.7.0",
|
|
36
38
|
"@theholocron/tsdown-config": "^8.7.0",
|
|
37
39
|
"@theholocron/vitest-config": "^8.7.0",
|
|
@@ -46,10 +48,12 @@
|
|
|
46
48
|
"tsx": "4.23.12",
|
|
47
49
|
"typescript": "^5.9.3",
|
|
48
50
|
"vitest": "^4.1.11",
|
|
49
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
51
|
+
"@theholocron/cli": "5.0.0-alpha.117"
|
|
50
52
|
},
|
|
51
53
|
"peerDependencies": {
|
|
52
|
-
"@theholocron/
|
|
54
|
+
"@theholocron/discord-client": "^1.37.1",
|
|
55
|
+
"@theholocron/misc-utils": "^1.9.2",
|
|
56
|
+
"@theholocron/cli": "5.0.0-alpha.117"
|
|
53
57
|
},
|
|
54
58
|
"engines": {
|
|
55
59
|
"node": ">=22"
|