mirror of
https://github.com/ajnart/homarr.git
synced 2026-01-30 19:29:17 +01:00
* feat: add integration access settings * fix: typecheck and test issues * fix: test timeout * chore: address pull request feedback * chore: add throw if action forbidden for integration permissions * fix: unable to create new migrations because of duplicate prevId in sqlite snapshots * chore: add sqlite migration for integration permissions * test: add unit tests for integration access * test: add permission checks to integration router tests * test: add unit test for integration permissions * chore: add mysql migration * fix: format issues
58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import { z } from "zod";
|
|
|
|
import { integrationKinds, integrationPermissions, integrationSecretKinds } from "@homarr/definitions";
|
|
|
|
import { zodEnumFromArray } from "./enums";
|
|
import { createSavePermissionsSchema } from "./permissions";
|
|
|
|
const integrationCreateSchema = z.object({
|
|
name: z.string().nonempty().max(127),
|
|
url: z.string().url(),
|
|
kind: zodEnumFromArray(integrationKinds),
|
|
secrets: z.array(
|
|
z.object({
|
|
kind: zodEnumFromArray(integrationSecretKinds),
|
|
value: z.string().nonempty(),
|
|
}),
|
|
),
|
|
});
|
|
|
|
const integrationUpdateSchema = z.object({
|
|
id: z.string().cuid2(),
|
|
name: z.string().nonempty().max(127),
|
|
url: z.string().url(),
|
|
secrets: z.array(
|
|
z.object({
|
|
kind: zodEnumFromArray(integrationSecretKinds),
|
|
value: z.string().nullable(),
|
|
}),
|
|
),
|
|
});
|
|
|
|
const idSchema = z.object({
|
|
id: z.string(),
|
|
});
|
|
|
|
const testConnectionSchema = z.object({
|
|
id: z.string().cuid2().nullable(), // Is used to use existing secrets if they have not been updated
|
|
url: z.string().url(),
|
|
kind: zodEnumFromArray(integrationKinds),
|
|
secrets: z.array(
|
|
z.object({
|
|
kind: zodEnumFromArray(integrationSecretKinds),
|
|
value: z.string().nullable(),
|
|
}),
|
|
),
|
|
});
|
|
|
|
const savePermissionsSchema = createSavePermissionsSchema(zodEnumFromArray(integrationPermissions));
|
|
|
|
export const integrationSchemas = {
|
|
create: integrationCreateSchema,
|
|
update: integrationUpdateSchema,
|
|
delete: idSchema,
|
|
byId: idSchema,
|
|
testConnection: testConnectionSchema,
|
|
savePermissions: savePermissionsSchema,
|
|
};
|