diff --git a/src/global-messages/index.ts b/src/global-messages/index.ts index bf7daf2..67c9158 100644 --- a/src/global-messages/index.ts +++ b/src/global-messages/index.ts @@ -1 +1 @@ -export {createGlobalMessageSchema, GenericGlobalMessageType} from './types'; +export {GlobalMessageSchema, GlobalMessageType} from './types'; diff --git a/src/global-messages/types.ts b/src/global-messages/types.ts index 8239c00..6b1d113 100644 --- a/src/global-messages/types.ts +++ b/src/global-messages/types.ts @@ -3,41 +3,23 @@ import {LanguageAndTextSchema} from '../common/language-and-text'; import {Rule} from '../rules/types'; import {AppPlatform} from '../common/app-platform'; -/** - * Create a global message schema with a consumer specific context enum. - * - * @example - * export enum GlobalMessageContextEnum { - * webOverview = 'web-overview', - * } - * const GlobalMessageContextSchema = z.enum(GlobalMessageContextEnum); - * export const GlobalMessageSchema = createGlobalMessageSchema( - * GlobalMessageContextSchema, - * ); - */ -export function createGlobalMessageSchema( - contextEnum: ContextEnum, -) { - return z.object({ - id: z.string(), - active: z.boolean(), - title: z.array(LanguageAndTextSchema).optional(), - body: z.array(LanguageAndTextSchema), - link: z.array(LanguageAndTextSchema).optional(), - linkText: z.array(LanguageAndTextSchema).optional(), - type: z.enum(['error', 'valid', 'info', 'warning']), - subtle: z.boolean().optional(), - context: z.array(contextEnum), - isDismissable: z.boolean().optional(), - appPlatforms: z.array(AppPlatform).optional(), - appVersionMin: z.string().optional(), - appVersionMax: z.string().optional(), - startDate: z.coerce.date().optional(), - endDate: z.coerce.date().optional(), - rules: z.array(Rule).optional(), - }); -} +export const GlobalMessageSchema = z.object({ + id: z.string(), + active: z.boolean(), + title: z.array(LanguageAndTextSchema).optional(), + body: z.array(LanguageAndTextSchema), + link: z.array(LanguageAndTextSchema).optional(), + linkText: z.array(LanguageAndTextSchema).optional(), + type: z.enum(['error', 'valid', 'info', 'warning']), + subtle: z.boolean().optional(), + context: z.array(z.string()).nonempty(), + isDismissable: z.boolean().optional(), + appPlatforms: z.array(AppPlatform).optional(), + appVersionMin: z.string().optional(), + appVersionMax: z.string().optional(), + startDate: z.coerce.date().optional(), + endDate: z.coerce.date().optional(), + rules: z.array(Rule).optional(), +}); -export type GenericGlobalMessageType = z.infer< - ReturnType> ->; +export type GlobalMessageType = z.infer;