@developer.krd/discord-dashboard 0.1.0
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 +673 -0
- package/dist/index.cjs +2495 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +317 -0
- package/dist/index.d.ts +317 -0
- package/dist/index.js +2453 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { Express } from 'express';
|
|
2
|
+
|
|
3
|
+
type CardIntent = "neutral" | "success" | "warning" | "danger" | "info";
|
|
4
|
+
interface DashboardCard {
|
|
5
|
+
id: string;
|
|
6
|
+
title: string;
|
|
7
|
+
value: string | number;
|
|
8
|
+
subtitle?: string;
|
|
9
|
+
intent?: CardIntent;
|
|
10
|
+
trend?: {
|
|
11
|
+
value: string;
|
|
12
|
+
direction: "up" | "down" | "flat";
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
type DashboardBoxWidth = 100 | 50 | 33 | 20;
|
|
16
|
+
interface DashboardDesignConfig {
|
|
17
|
+
bg?: string;
|
|
18
|
+
rail?: string;
|
|
19
|
+
contentBg?: string;
|
|
20
|
+
panel?: string;
|
|
21
|
+
panel2?: string;
|
|
22
|
+
text?: string;
|
|
23
|
+
muted?: string;
|
|
24
|
+
primary?: string;
|
|
25
|
+
success?: string;
|
|
26
|
+
warning?: string;
|
|
27
|
+
danger?: string;
|
|
28
|
+
info?: string;
|
|
29
|
+
border?: string;
|
|
30
|
+
}
|
|
31
|
+
interface DashboardTemplateRenderContext {
|
|
32
|
+
dashboardName: string;
|
|
33
|
+
basePath: string;
|
|
34
|
+
setupDesign?: DashboardDesignConfig;
|
|
35
|
+
}
|
|
36
|
+
type DashboardTemplateRenderer = (context: DashboardTemplateRenderContext) => string;
|
|
37
|
+
interface PluginPanelField {
|
|
38
|
+
id?: string;
|
|
39
|
+
label: string;
|
|
40
|
+
value: string | number | boolean | string[] | Record<string, unknown>;
|
|
41
|
+
type?: HomeFieldType | "url";
|
|
42
|
+
editable?: boolean;
|
|
43
|
+
placeholder?: string;
|
|
44
|
+
required?: boolean;
|
|
45
|
+
options?: HomeFieldOption[];
|
|
46
|
+
lookup?: HomeLookupConfig;
|
|
47
|
+
}
|
|
48
|
+
interface PluginPanelAction {
|
|
49
|
+
id: string;
|
|
50
|
+
label: string;
|
|
51
|
+
variant?: "primary" | "secondary" | "danger";
|
|
52
|
+
collectFields?: boolean;
|
|
53
|
+
}
|
|
54
|
+
interface PluginPanel {
|
|
55
|
+
id: string;
|
|
56
|
+
title: string;
|
|
57
|
+
description?: string;
|
|
58
|
+
width?: DashboardBoxWidth;
|
|
59
|
+
fields?: PluginPanelField[];
|
|
60
|
+
actions?: PluginPanelAction[];
|
|
61
|
+
}
|
|
62
|
+
interface PluginActionResult {
|
|
63
|
+
ok: boolean;
|
|
64
|
+
message?: string;
|
|
65
|
+
refresh?: boolean;
|
|
66
|
+
data?: unknown;
|
|
67
|
+
}
|
|
68
|
+
interface DiscordChannel {
|
|
69
|
+
id: string;
|
|
70
|
+
guild_id?: string;
|
|
71
|
+
name: string;
|
|
72
|
+
type: number;
|
|
73
|
+
parent_id?: string | null;
|
|
74
|
+
nsfw?: boolean;
|
|
75
|
+
}
|
|
76
|
+
interface DiscordRole {
|
|
77
|
+
id: string;
|
|
78
|
+
name: string;
|
|
79
|
+
color: number;
|
|
80
|
+
position: number;
|
|
81
|
+
permissions: string;
|
|
82
|
+
managed?: boolean;
|
|
83
|
+
mentionable?: boolean;
|
|
84
|
+
hoist?: boolean;
|
|
85
|
+
}
|
|
86
|
+
interface DiscordMember {
|
|
87
|
+
user?: {
|
|
88
|
+
id: string;
|
|
89
|
+
username: string;
|
|
90
|
+
discriminator: string;
|
|
91
|
+
avatar: string | null;
|
|
92
|
+
};
|
|
93
|
+
roles: string[];
|
|
94
|
+
nick?: string | null;
|
|
95
|
+
joined_at?: string;
|
|
96
|
+
}
|
|
97
|
+
interface DashboardDiscordHelpers {
|
|
98
|
+
getChannel: (channelId: string) => Promise<DiscordChannel | null>;
|
|
99
|
+
getGuildChannels: (guildId: string) => Promise<DiscordChannel[]>;
|
|
100
|
+
searchGuildChannels: (guildId: string, query: string, options?: {
|
|
101
|
+
limit?: number;
|
|
102
|
+
nsfw?: boolean;
|
|
103
|
+
channelTypes?: number[];
|
|
104
|
+
}) => Promise<DiscordChannel[]>;
|
|
105
|
+
getRole: (guildId: string, roleId: string) => Promise<DiscordRole | null>;
|
|
106
|
+
getGuildRoles: (guildId: string) => Promise<DiscordRole[]>;
|
|
107
|
+
searchGuildRoles: (guildId: string, query: string, options?: {
|
|
108
|
+
limit?: number;
|
|
109
|
+
includeManaged?: boolean;
|
|
110
|
+
}) => Promise<DiscordRole[]>;
|
|
111
|
+
searchGuildMembers: (guildId: string, query: string, options?: {
|
|
112
|
+
limit?: number;
|
|
113
|
+
}) => Promise<DiscordMember[]>;
|
|
114
|
+
getGuildMember: (guildId: string, userId: string) => Promise<DiscordMember | null>;
|
|
115
|
+
}
|
|
116
|
+
type DashboardScope = "setup" | "user" | "guild";
|
|
117
|
+
interface HomeCategory {
|
|
118
|
+
id: string;
|
|
119
|
+
label: string;
|
|
120
|
+
scope: DashboardScope;
|
|
121
|
+
description?: string;
|
|
122
|
+
}
|
|
123
|
+
type HomeFieldType = "text" | "textarea" | "number" | "select" | "boolean" | "role-search" | "channel-search" | "member-search" | "string-list";
|
|
124
|
+
interface HomeLookupConfig {
|
|
125
|
+
limit?: number;
|
|
126
|
+
minQueryLength?: number;
|
|
127
|
+
nsfw?: boolean;
|
|
128
|
+
channelTypes?: number[];
|
|
129
|
+
includeManaged?: boolean;
|
|
130
|
+
}
|
|
131
|
+
interface HomeFieldOption {
|
|
132
|
+
label: string;
|
|
133
|
+
value: string;
|
|
134
|
+
}
|
|
135
|
+
interface HomeSectionField {
|
|
136
|
+
id: string;
|
|
137
|
+
label: string;
|
|
138
|
+
type: HomeFieldType;
|
|
139
|
+
value?: string | number | boolean | string[] | Record<string, unknown>;
|
|
140
|
+
placeholder?: string;
|
|
141
|
+
required?: boolean;
|
|
142
|
+
readOnly?: boolean;
|
|
143
|
+
options?: HomeFieldOption[];
|
|
144
|
+
lookup?: HomeLookupConfig;
|
|
145
|
+
}
|
|
146
|
+
interface HomeSectionAction {
|
|
147
|
+
id: string;
|
|
148
|
+
label: string;
|
|
149
|
+
variant?: "primary" | "secondary" | "danger";
|
|
150
|
+
}
|
|
151
|
+
interface HomeSection {
|
|
152
|
+
id: string;
|
|
153
|
+
title: string;
|
|
154
|
+
description?: string;
|
|
155
|
+
width?: DashboardBoxWidth;
|
|
156
|
+
scope?: DashboardScope;
|
|
157
|
+
categoryId?: string;
|
|
158
|
+
fields?: HomeSectionField[];
|
|
159
|
+
actions?: HomeSectionAction[];
|
|
160
|
+
}
|
|
161
|
+
interface HomeActionPayload {
|
|
162
|
+
sectionId: string;
|
|
163
|
+
values: Record<string, unknown>;
|
|
164
|
+
}
|
|
165
|
+
interface DashboardHomeBuilder {
|
|
166
|
+
getOverviewSections?: (context: DashboardContext) => Promise<HomeSection[]> | HomeSection[];
|
|
167
|
+
getCategories?: (context: DashboardContext) => Promise<HomeCategory[]> | HomeCategory[];
|
|
168
|
+
getSections?: (context: DashboardContext) => Promise<HomeSection[]> | HomeSection[];
|
|
169
|
+
actions?: Record<string, (context: DashboardContext, payload: HomeActionPayload) => Promise<PluginActionResult> | PluginActionResult>;
|
|
170
|
+
}
|
|
171
|
+
interface DashboardUser {
|
|
172
|
+
id: string;
|
|
173
|
+
username: string;
|
|
174
|
+
discriminator: string;
|
|
175
|
+
avatar: string | null;
|
|
176
|
+
global_name?: string | null;
|
|
177
|
+
}
|
|
178
|
+
interface DashboardGuild {
|
|
179
|
+
id: string;
|
|
180
|
+
name: string;
|
|
181
|
+
icon: string | null;
|
|
182
|
+
owner: boolean;
|
|
183
|
+
permissions: string;
|
|
184
|
+
iconUrl?: string | null;
|
|
185
|
+
botInGuild?: boolean;
|
|
186
|
+
inviteUrl?: string;
|
|
187
|
+
}
|
|
188
|
+
interface DashboardContext {
|
|
189
|
+
user: DashboardUser;
|
|
190
|
+
guilds: DashboardGuild[];
|
|
191
|
+
accessToken: string;
|
|
192
|
+
selectedGuildId?: string;
|
|
193
|
+
helpers: DashboardDiscordHelpers;
|
|
194
|
+
}
|
|
195
|
+
interface DashboardPlugin {
|
|
196
|
+
id: string;
|
|
197
|
+
name: string;
|
|
198
|
+
description?: string;
|
|
199
|
+
scope?: DashboardScope | "both";
|
|
200
|
+
getPanels: (context: DashboardContext) => Promise<PluginPanel[]> | PluginPanel[];
|
|
201
|
+
actions?: Record<string, (context: DashboardContext, body: unknown) => Promise<PluginActionResult> | PluginActionResult>;
|
|
202
|
+
}
|
|
203
|
+
interface DashboardOptions {
|
|
204
|
+
app?: Express;
|
|
205
|
+
port?: number;
|
|
206
|
+
host?: string;
|
|
207
|
+
trustProxy?: boolean | number;
|
|
208
|
+
basePath?: string;
|
|
209
|
+
dashboardName?: string;
|
|
210
|
+
setupDesign?: DashboardDesignConfig;
|
|
211
|
+
uiTemplate?: string;
|
|
212
|
+
uiTemplates?: Record<string, DashboardTemplateRenderer>;
|
|
213
|
+
botToken: string;
|
|
214
|
+
clientId: string;
|
|
215
|
+
clientSecret: string;
|
|
216
|
+
redirectUri: string;
|
|
217
|
+
sessionSecret: string;
|
|
218
|
+
sessionName?: string;
|
|
219
|
+
sessionMaxAgeMs?: number;
|
|
220
|
+
scopes?: string[];
|
|
221
|
+
botInvitePermissions?: string;
|
|
222
|
+
botInviteScopes?: string[];
|
|
223
|
+
ownerIds?: string[];
|
|
224
|
+
guildFilter?: (guild: DashboardGuild, context: DashboardContext) => Promise<boolean> | boolean;
|
|
225
|
+
getOverviewCards?: (context: DashboardContext) => Promise<DashboardCard[]> | DashboardCard[];
|
|
226
|
+
home?: DashboardHomeBuilder;
|
|
227
|
+
plugins?: DashboardPlugin[];
|
|
228
|
+
}
|
|
229
|
+
interface DashboardInstance {
|
|
230
|
+
app: Express;
|
|
231
|
+
start: () => Promise<void>;
|
|
232
|
+
stop: () => Promise<void>;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
declare function createDashboard(options: DashboardOptions): DashboardInstance;
|
|
236
|
+
|
|
237
|
+
type HomeActionHandler = (context: DashboardContext, payload: HomeActionPayload) => Promise<PluginActionResult> | PluginActionResult;
|
|
238
|
+
type HomeLoadHandler = (context: DashboardContext, section: HomeSection) => Promise<Partial<HomeSection> | HomeSection | void> | Partial<HomeSection> | HomeSection | void;
|
|
239
|
+
declare class CategoryBuilder {
|
|
240
|
+
private readonly scope;
|
|
241
|
+
private readonly categoryId;
|
|
242
|
+
private readonly categoryLabel;
|
|
243
|
+
private sections;
|
|
244
|
+
constructor(scope: DashboardScope, categoryId: string, categoryLabel: string);
|
|
245
|
+
section(input: {
|
|
246
|
+
id: string;
|
|
247
|
+
title: string;
|
|
248
|
+
description?: string;
|
|
249
|
+
width?: 100 | 50 | 33 | 20;
|
|
250
|
+
fields?: HomeSectionField[];
|
|
251
|
+
actions?: HomeSectionAction[];
|
|
252
|
+
}): this;
|
|
253
|
+
buildCategory(): HomeCategory;
|
|
254
|
+
buildSections(): HomeSection[];
|
|
255
|
+
}
|
|
256
|
+
declare class DashboardDesigner {
|
|
257
|
+
private readonly partialOptions;
|
|
258
|
+
private readonly categories;
|
|
259
|
+
private readonly pages;
|
|
260
|
+
private readonly homeActions;
|
|
261
|
+
private readonly loadHandlers;
|
|
262
|
+
private readonly saveHandlers;
|
|
263
|
+
constructor(baseOptions: Omit<DashboardOptions, "home">);
|
|
264
|
+
setup(input: {
|
|
265
|
+
ownerIds?: string[];
|
|
266
|
+
botInvitePermissions?: string;
|
|
267
|
+
botInviteScopes?: string[];
|
|
268
|
+
dashboardName?: string;
|
|
269
|
+
basePath?: string;
|
|
270
|
+
uiTemplate?: string;
|
|
271
|
+
}): this;
|
|
272
|
+
useTemplate(templateId: string): this;
|
|
273
|
+
addTemplate(templateId: string, renderer: DashboardTemplateRenderer): this;
|
|
274
|
+
setupDesign(input: {
|
|
275
|
+
bg?: string;
|
|
276
|
+
rail?: string;
|
|
277
|
+
contentBg?: string;
|
|
278
|
+
panel?: string;
|
|
279
|
+
panel2?: string;
|
|
280
|
+
text?: string;
|
|
281
|
+
muted?: string;
|
|
282
|
+
primary?: string;
|
|
283
|
+
success?: string;
|
|
284
|
+
warning?: string;
|
|
285
|
+
danger?: string;
|
|
286
|
+
info?: string;
|
|
287
|
+
border?: string;
|
|
288
|
+
}): this;
|
|
289
|
+
userCategory(categoryId: string, categoryLabel: string, build: (builder: CategoryBuilder) => void): this;
|
|
290
|
+
guildCategory(categoryId: string, categoryLabel: string, build: (builder: CategoryBuilder) => void): this;
|
|
291
|
+
setupCategory(categoryId: string, categoryLabel: string, build: (builder: CategoryBuilder) => void): this;
|
|
292
|
+
setupPage(input: {
|
|
293
|
+
id: string;
|
|
294
|
+
title: string;
|
|
295
|
+
label?: string;
|
|
296
|
+
scope?: DashboardScope;
|
|
297
|
+
categoryId?: string;
|
|
298
|
+
description?: string;
|
|
299
|
+
width?: 100 | 50 | 33 | 20;
|
|
300
|
+
fields?: HomeSectionField[];
|
|
301
|
+
actions?: HomeSectionAction[];
|
|
302
|
+
}): this;
|
|
303
|
+
onHomeAction(actionId: string, handler: HomeActionHandler): this;
|
|
304
|
+
onLoad(pageId: string, handler: HomeLoadHandler): this;
|
|
305
|
+
onload(pageId: string, handler: HomeLoadHandler): this;
|
|
306
|
+
onSave(pageId: string, handler: HomeActionHandler): this;
|
|
307
|
+
onsave(pageId: string, handler: HomeActionHandler): this;
|
|
308
|
+
build(): DashboardOptions;
|
|
309
|
+
}
|
|
310
|
+
declare function createDashboardDesigner(baseOptions: Omit<DashboardOptions, "home">): DashboardDesigner;
|
|
311
|
+
|
|
312
|
+
declare function createDiscordHelpers(botToken: string): DashboardDiscordHelpers;
|
|
313
|
+
|
|
314
|
+
declare const builtinTemplateRenderers: Record<string, DashboardTemplateRenderer>;
|
|
315
|
+
declare function getBuiltinTemplateRenderer(templateId: string): DashboardTemplateRenderer | undefined;
|
|
316
|
+
|
|
317
|
+
export { type CardIntent, type DashboardBoxWidth, type DashboardCard, type DashboardContext, type DashboardDesignConfig, DashboardDesigner, type DashboardDiscordHelpers, type DashboardGuild, type DashboardHomeBuilder, type DashboardInstance, type DashboardOptions, type DashboardPlugin, type DashboardScope, type DashboardTemplateRenderContext, type DashboardTemplateRenderer, type DashboardUser, type DiscordChannel, type DiscordMember, type DiscordRole, type HomeActionPayload, type HomeCategory, type HomeFieldOption, type HomeFieldType, type HomeLookupConfig, type HomeSection, type HomeSectionAction, type HomeSectionField, type PluginActionResult, type PluginPanel, type PluginPanelAction, type PluginPanelField, builtinTemplateRenderers, createDashboard, createDashboardDesigner, createDiscordHelpers, getBuiltinTemplateRenderer };
|