feat: custom widgets (#5889)
This commit is contained in:
1 parent
48e1844b5b
commit
aecbca2b81
69 files changed
+14620
-142
No files matched your search
@@ -49,6 +49,8 @@ export const {
|
||||
sectionLayouts,
|
||||
trustedCertificateHostnames,
|
||||
cronJobConfigurations,
|
||||
customWidgetDefinitions,
|
||||
customWidgetSecrets,
|
||||
} = schema;
|
||||
|
||||
export type User = InferSelectModel<typeof schema.users>;
|
||||
@@ -57,3 +59,5 @@ export type Session = InferSelectModel<typeof schema.sessions>;
|
||||
export type VerificationToken = InferSelectModel<typeof schema.verificationTokens>;
|
||||
export type Integration = InferSelectModel<typeof schema.integrations>;
|
||||
export type IntegrationSecret = InferSelectModel<typeof schema.integrationSecrets>;
|
||||
export type CustomWidgetDefinition = InferSelectModel<typeof schema.customWidgetDefinitions>;
|
||||
export type CustomWidgetSecret = InferSelectModel<typeof schema.customWidgetSecrets>;
|
||||
@@ -39,6 +39,12 @@ import type {
|
||||
SupportedAuthProvider,
|
||||
WidgetKind,
|
||||
} from "@homarr/definitions";
|
||||
import type {
|
||||
CustomWidgetAuthType,
|
||||
CustomWidgetDisplayType,
|
||||
CustomWidgetMethod,
|
||||
CustomWidgetSecretKind,
|
||||
} from "@homarr/validation/custom-widget";
|
||||
|
||||
const customBlob = customType<{ data: Buffer }>({
|
||||
dataType() {
|
||||
@@ -498,6 +504,43 @@ export const onboarding = mysqlTable("onboarding", {
|
||||
previousStep: varchar({ length: 64 }).$type<OnboardingStep>(),
|
||||
});
|
||||
|
||||
export const customWidgetDefinitions = mysqlTable("custom_widget_definition", {
|
||||
id: varchar({ length: 64 }).notNull().primaryKey(),
|
||||
name: varchar({ length: 256 }).notNull(),
|
||||
description: text(),
|
||||
iconUrl: text(),
|
||||
url: text().notNull(),
|
||||
authType: varchar({ length: 32 }).$type<CustomWidgetAuthType>().notNull().default("none"),
|
||||
headerName: varchar({ length: 256 }),
|
||||
method: varchar({ length: 16 }).$type<CustomWidgetMethod>().notNull().default("GET"),
|
||||
requestBody: text(),
|
||||
displayType: varchar({ length: 32 }).$type<CustomWidgetDisplayType>().notNull().default("singleValue"),
|
||||
displayConfig: text().default(emptySuperJSON).notNull(),
|
||||
enabled: boolean().notNull().default(true),
|
||||
createdAt: timestamp({ mode: "date" }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ mode: "date" }).notNull().defaultNow(),
|
||||
creatorId: varchar({ length: 64 }).references(() => users.id, { onDelete: "set null" }),
|
||||
});
|
||||
|
||||
export const customWidgetSecrets = mysqlTable(
|
||||
"custom_widget_secret",
|
||||
{
|
||||
kind: varchar({ length: 64 }).$type<CustomWidgetSecretKind>().notNull(),
|
||||
value: text().$type<`${string}.${string}`>().notNull(),
|
||||
updatedAt: timestamp()
|
||||
.$onUpdateFn(() => new Date())
|
||||
.notNull(),
|
||||
definitionId: varchar({ length: 64 })
|
||||
.notNull()
|
||||
.references(() => customWidgetDefinitions.id, { onDelete: "cascade" }),
|
||||
},
|
||||
(table) => ({
|
||||
compoundKey: primaryKey({
|
||||
columns: [table.definitionId, table.kind],
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
export const cronJobConfigurations = mysqlTable("cron_job_configuration", {
|
||||
name: varchar({ length: 256 }).notNull().primaryKey(),
|
||||
cronExpression: varchar({ length: 32 }).notNull(),
|
||||
@@ -768,3 +811,18 @@ export const layoutRelations = relations(layouts, ({ one, many }) => ({
|
||||
references: [boards.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const customWidgetDefinitionRelations = relations(customWidgetDefinitions, ({ many, one }) => ({
|
||||
secrets: many(customWidgetSecrets),
|
||||
creator: one(users, {
|
||||
fields: [customWidgetDefinitions.creatorId],
|
||||
references: [users.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const customWidgetSecretRelations = relations(customWidgetSecrets, ({ one }) => ({
|
||||
definition: one(customWidgetDefinitions, {
|
||||
fields: [customWidgetSecrets.definitionId],
|
||||
references: [customWidgetDefinitions.id],
|
||||
}),
|
||||
}));
|
||||
@@ -38,6 +38,12 @@ import type {
|
||||
SupportedAuthProvider,
|
||||
WidgetKind,
|
||||
} from "@homarr/definitions";
|
||||
import type {
|
||||
CustomWidgetAuthType,
|
||||
CustomWidgetDisplayType,
|
||||
CustomWidgetMethod,
|
||||
CustomWidgetSecretKind,
|
||||
} from "@homarr/validation/custom-widget";
|
||||
|
||||
const customBlob = customType<{ data: Buffer }>({
|
||||
dataType() {
|
||||
@@ -497,6 +503,43 @@ export const onboarding = pgTable("onboarding", {
|
||||
previousStep: varchar({ length: 64 }).$type<OnboardingStep>(),
|
||||
});
|
||||
|
||||
export const customWidgetDefinitions = pgTable("custom_widget_definition", {
|
||||
id: varchar({ length: 64 }).notNull().primaryKey(),
|
||||
name: varchar({ length: 256 }).notNull(),
|
||||
description: text(),
|
||||
iconUrl: text(),
|
||||
url: text().notNull(),
|
||||
authType: varchar({ length: 32 }).$type<CustomWidgetAuthType>().notNull().default("none"),
|
||||
headerName: varchar({ length: 256 }),
|
||||
method: varchar({ length: 16 }).$type<CustomWidgetMethod>().notNull().default("GET"),
|
||||
requestBody: text(),
|
||||
displayType: varchar({ length: 32 }).$type<CustomWidgetDisplayType>().notNull().default("singleValue"),
|
||||
displayConfig: text().default(emptySuperJSON).notNull(),
|
||||
enabled: boolean().notNull().default(true),
|
||||
createdAt: timestamp({ mode: "date" }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ mode: "date" }).notNull().defaultNow(),
|
||||
creatorId: varchar({ length: 64 }).references(() => users.id, { onDelete: "set null" }),
|
||||
});
|
||||
|
||||
export const customWidgetSecrets = pgTable(
|
||||
"custom_widget_secret",
|
||||
{
|
||||
kind: varchar({ length: 64 }).$type<CustomWidgetSecretKind>().notNull(),
|
||||
value: text().$type<`${string}.${string}`>().notNull(),
|
||||
updatedAt: timestamp()
|
||||
.$onUpdateFn(() => new Date())
|
||||
.notNull(),
|
||||
definitionId: varchar({ length: 64 })
|
||||
.notNull()
|
||||
.references(() => customWidgetDefinitions.id, { onDelete: "cascade" }),
|
||||
},
|
||||
(table) => ({
|
||||
compoundKey: primaryKey({
|
||||
columns: [table.definitionId, table.kind],
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
export const cronJobConfigurations = pgTable("cron_job_configuration", {
|
||||
name: varchar({ length: 256 }).notNull().primaryKey(),
|
||||
cronExpression: varchar({ length: 32 }).notNull(),
|
||||
@@ -767,3 +810,18 @@ export const layoutRelations = relations(layouts, ({ one, many }) => ({
|
||||
references: [boards.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const customWidgetDefinitionRelations = relations(customWidgetDefinitions, ({ many, one }) => ({
|
||||
secrets: many(customWidgetSecrets),
|
||||
creator: one(users, {
|
||||
fields: [customWidgetDefinitions.creatorId],
|
||||
references: [users.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const customWidgetSecretRelations = relations(customWidgetSecrets, ({ one }) => ({
|
||||
definition: one(customWidgetDefinitions, {
|
||||
fields: [customWidgetSecrets.definitionId],
|
||||
references: [customWidgetDefinitions.id],
|
||||
}),
|
||||
}));
|
||||
@@ -27,6 +27,12 @@ import type {
|
||||
SupportedAuthProvider,
|
||||
WidgetKind,
|
||||
} from "@homarr/definitions";
|
||||
import type {
|
||||
CustomWidgetAuthType,
|
||||
CustomWidgetDisplayType,
|
||||
CustomWidgetMethod,
|
||||
CustomWidgetSecretKind,
|
||||
} from "@homarr/validation/custom-widget";
|
||||
|
||||
export * from "@homarr/core/infrastructure/certificates/hostnames/db/sqlite";
|
||||
|
||||
@@ -483,6 +489,47 @@ export const onboarding = sqliteTable("onboarding", {
|
||||
previousStep: text().$type<OnboardingStep>(),
|
||||
});
|
||||
|
||||
export const customWidgetDefinitions = sqliteTable("custom_widget_definition", {
|
||||
id: text().notNull().primaryKey(),
|
||||
name: text().notNull(),
|
||||
description: text(),
|
||||
iconUrl: text(),
|
||||
url: text().notNull(),
|
||||
authType: text().$type<CustomWidgetAuthType>().notNull().default("none"),
|
||||
headerName: text(),
|
||||
method: text().$type<CustomWidgetMethod>().notNull().default("GET"),
|
||||
requestBody: text(),
|
||||
displayType: text().$type<CustomWidgetDisplayType>().notNull().default("singleValue"),
|
||||
displayConfig: text().default(emptySuperJSON).notNull(),
|
||||
enabled: int({ mode: "boolean" }).notNull().default(true),
|
||||
createdAt: int({ mode: "timestamp" })
|
||||
.notNull()
|
||||
.default(sql`(unixepoch())`),
|
||||
updatedAt: int({ mode: "timestamp" })
|
||||
.notNull()
|
||||
.default(sql`(unixepoch())`),
|
||||
creatorId: text().references(() => users.id, { onDelete: "set null" }),
|
||||
});
|
||||
|
||||
export const customWidgetSecrets = sqliteTable(
|
||||
"custom_widget_secret",
|
||||
{
|
||||
kind: text().$type<CustomWidgetSecretKind>().notNull(),
|
||||
value: text().$type<`${string}.${string}`>().notNull(),
|
||||
updatedAt: int({ mode: "timestamp" })
|
||||
.$onUpdateFn(() => new Date())
|
||||
.notNull(),
|
||||
definitionId: text()
|
||||
.notNull()
|
||||
.references(() => customWidgetDefinitions.id, { onDelete: "cascade" }),
|
||||
},
|
||||
(table) => ({
|
||||
compoundKey: primaryKey({
|
||||
columns: [table.definitionId, table.kind],
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
export const cronJobConfigurations = sqliteTable("cron_job_configuration", {
|
||||
name: text().notNull().primaryKey(),
|
||||
cronExpression: text().notNull(),
|
||||
@@ -753,3 +800,18 @@ export const layoutRelations = relations(layouts, ({ one, many }) => ({
|
||||
references: [boards.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const customWidgetDefinitionRelations = relations(customWidgetDefinitions, ({ many, one }) => ({
|
||||
secrets: many(customWidgetSecrets),
|
||||
creator: one(users, {
|
||||
fields: [customWidgetDefinitions.creatorId],
|
||||
references: [users.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const customWidgetSecretRelations = relations(customWidgetSecrets, ({ one }) => ({
|
||||
definition: one(customWidgetDefinitions, {
|
||||
fields: [customWidgetSecrets.definitionId],
|
||||
references: [customWidgetDefinitions.id],
|
||||
}),
|
||||
}));
|
||||
Reference in new issue
Block a user