Switch to zod/mini

This commit is contained in:
Michael Telatynski
2025-09-23 17:06:57 +01:00
parent d8da6652b8
commit 8cba4eaf8b
5 changed files with 42 additions and 39 deletions
@@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
import { z } from "zod";
import { z } from "zod/mini";
import { StaticConfig } from "../config";
@@ -44,7 +44,7 @@ const UniventionCentralNavigation = z.object({
/**
* Its usually empty.
*/
keywords: z.object({}).optional(),
keywords: z.optional(z.object({})),
}),
),
}),
+14 -12
View File
@@ -5,10 +5,12 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
import { z, ZodSchema, ZodTypeDef } from "zod";
import { z, ZodMiniType, input } from "zod/mini";
import { Theme } from "./theme.ts";
z.config(z.locales.en());
const StaticConfig = z.object({
type: z.literal("static"),
@@ -16,7 +18,7 @@ const StaticConfig = z.object({
* Alternative logo URL to display in the popover menu.
* Will use the main logo url if omitted.
*/
logo_url: z.string().url().optional(),
logo_url: z.optional(z.url()),
/**
* Categories of links to display in the menu.
@@ -35,7 +37,7 @@ const StaticConfig = z.object({
/**
* The URL to the icon.
*/
icon_uri: z.string().url(),
icon_uri: z.url(),
/**
* The label of the link.
*/
@@ -43,11 +45,11 @@ const StaticConfig = z.object({
/**
* The destination URL of the link.
*/
link_url: z.string().url(),
link_url: z.url(),
/**
* The browsing context in which the browser opens the link.
*/
target: z.string().optional(),
target: z.optional(z.string()),
}),
),
}),
@@ -63,13 +65,13 @@ const UniventionConfig = z.object({
* Alternative logo URL to display in the popover menu.
* Will use the main logo url if omitted.
*/
logo_url: z.string().url().optional(),
logo_url: z.optional(z.url()),
/**
* Base URL to an Intercom Service
* https://docs.software-univention.de/intercom-service/latest/architecture.html#endpoints
*/
ics_url: z.string().url(),
ics_url: z.url(),
});
export type UniventionConfig = z.infer<typeof UniventionConfig>;
@@ -79,13 +81,13 @@ export const ModuleConfig = z.object({
* The URL of the portal logo.svg file.
* @example `https://example.com/logo.svg`
*/
logo_url: z.string().url(),
logo_url: z.url(),
/**
* The URL of the portal.
* @example `https://example.com`
*/
logo_link_url: z.string().url(),
logo_link_url: z.url(),
/**
* Configuration for the menu.
@@ -95,17 +97,17 @@ export const ModuleConfig = z.object({
/**
* Theme variable overrides, optional.
*/
theme: Theme.default({}),
theme: z.prefault(Theme, {}),
});
export type ModuleConfig = z.infer<typeof ModuleConfig>;
export type ConfigSchema = ZodSchema<z.output<typeof ModuleConfig>, ZodTypeDef, z.input<typeof ModuleConfig>>;
export type ConfigSchema = ZodMiniType<z.output<typeof ModuleConfig>, z.input<typeof ModuleConfig>>;
export const CONFIG_KEY = "io.element.element-web-modules.banner";
declare module "@element-hq/element-web-module-api" {
export interface Config {
[CONFIG_KEY]: ConfigSchema["_input"];
[CONFIG_KEY]: input<ConfigSchema>;
}
}
+15 -15
View File
@@ -5,23 +5,23 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
import { z } from "zod";
import { z } from "zod/mini";
export const Theme = z.object({
textColor: z.string().default("var(--cpd-color-text-primary)"),
subheadingColor: z.string().default("var(--cpd-color-text-secondary)"),
bannerBackgroundColor: z.string().default("var(--cpd-color-bg-canvas-default)"),
bannerHeight: z.string().default("60px"),
triggerWidth: z.string().default("68px"),
triggerBackgroundColor: z.string().default("var(--cpd-color-bg-subtle-secondary)"),
triggerBackgroundColorHover: z.string().default("var(--cpd-color-bg-accent-hovered)"),
triggerBackgroundColorPressed: z.string().default("var(--cpd-color-bg-accent-pressed)"),
triggerColor: z.string().default("var(--cpd-color-icon-primary)"),
triggerColorContrast: z.string().default("var(--cpd-color-icon-on-solid-primary)"),
menuWidth: z.string().default("320px"),
menuBackgroundColor: z.string().default("var(--cpd-color-bg-canvas-default)"),
menuButtonBackgroundColorHover: z.string().default("var(--cpd-color-bg-action-secondary-hovered)"),
menuButtonBackgroundColorPressed: z.string().default("var(--cpd-color-bg-action-secondary-pressed)"),
textColor: z.prefault(z.string(), "var(--cpd-color-text-primary)"),
subheadingColor: z.prefault(z.string(), "var(--cpd-color-text-secondary)"),
bannerBackgroundColor: z.prefault(z.string(), "var(--cpd-color-bg-canvas-default)"),
bannerHeight: z.prefault(z.string(), "60px"),
triggerWidth: z.prefault(z.string(), "68px"),
triggerBackgroundColor: z.prefault(z.string(), "var(--cpd-color-bg-subtle-secondary)"),
triggerBackgroundColorHover: z.prefault(z.string(), "var(--cpd-color-bg-accent-hovered)"),
triggerBackgroundColorPressed: z.prefault(z.string(), "var(--cpd-color-bg-accent-pressed)"),
triggerColor: z.prefault(z.string(), "var(--cpd-color-icon-primary)"),
triggerColorContrast: z.prefault(z.string(), "var(--cpd-color-icon-on-solid-primary)"),
menuWidth: z.prefault(z.string(), "320px"),
menuBackgroundColor: z.prefault(z.string(), "var(--cpd-color-bg-canvas-default)"),
menuButtonBackgroundColorHover: z.prefault(z.string(), "var(--cpd-color-bg-action-secondary-hovered)"),
menuButtonBackgroundColorPressed: z.prefault(z.string(), "var(--cpd-color-bg-action-secondary-pressed)"),
});
export type Theme = z.infer<typeof Theme>;
@@ -5,6 +5,8 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
import { input } from "zod/mini";
import { test as base, expect } from "../../../../playwright/element-web-test.ts";
import { type ConfigSchema } from "../src/config.ts";
@@ -39,7 +41,7 @@ test.describe("Banner", () => {
// We don't take a screenshot as we don't want to assert Element's styling, only our own
});
const configs: ConfigSchema["_input"][] = [
const configs: input<ConfigSchema>[] = [
{
logo_url: "http://localhost:8080/logo.svg",
logo_link_url: "https://example.com/portal",
@@ -5,7 +5,9 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
import { z, ZodSchema, ZodTypeDef } from "zod";
import { z, ZodMiniType, input } from "zod/mini";
z.config(z.locales.en());
export const ModuleConfig = z.object({
/**
@@ -13,33 +15,30 @@ export const ModuleConfig = z.object({
* must have the `synapse-restricted-guests-module` installed.
* @example `https://synapse.local`
*/
guest_user_homeserver_url: z.string().url(),
guest_user_homeserver_url: z.url(),
/**
* The username prefix that identifies guest users.
* @defaultValue `@guest-`
*/
guest_user_prefix: z
.string()
.regex(/@[a-zA-Z-_1-9]+/)
.default("@guest-"),
guest_user_prefix: z._default(z.string().check(z.regex(/@[a-zA-Z-_1-9]+/)), "@guest-"),
/**
* If true, the user will be forwarded to the login page instead of to the SSO
* login. This is only required if the home server has no SSO support.
* @defaultValue `false`
*/
skip_single_sign_on: z.boolean().default(false),
skip_single_sign_on: z._default(z.boolean(), false),
});
export type ModuleConfig = z.infer<typeof ModuleConfig>;
type ConfigSchema = ZodSchema<z.output<typeof ModuleConfig>, ZodTypeDef, z.input<typeof ModuleConfig>>;
type ConfigSchema = ZodMiniType<z.output<typeof ModuleConfig>, z.input<typeof ModuleConfig>>;
export const CONFIG_KEY = "io.element.element-web-modules.restricted-guests";
declare module "@element-hq/element-web-module-api" {
export interface Config {
[CONFIG_KEY]: ConfigSchema["_input"];
[CONFIG_KEY]: input<ConfigSchema>;
}
}