2025-11-24 01:00:50 +01:00
|
|
|
import * as z from 'zod';
|
|
|
|
|
|
2025-12-02 09:54:38 +01:00
|
|
|
import { blockedSubdomain } from '@cio/utils/constants';
|
|
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
export const ZGetOrganizations = z.object({
|
|
|
|
|
siteName: z.string().min(1).optional(),
|
|
|
|
|
customDomain: z.string().min(1).optional(),
|
2026-05-19 10:24:18 +01:00
|
|
|
/**
|
|
|
|
|
* Accepts a real boolean (server-side direct calls) or the URL-encoded `'true'`/`'false'`
|
|
|
|
|
* string Hono RPC produces when serializing query params.
|
|
|
|
|
*/
|
|
|
|
|
isCustomDomainVerified: z
|
|
|
|
|
.union([z.boolean(), z.literal('true').transform(() => true), z.literal('false').transform(() => false)])
|
|
|
|
|
.optional()
|
2025-11-24 01:00:50 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TGetOrganizations = z.infer<typeof ZGetOrganizations>;
|
|
|
|
|
|
|
|
|
|
export const ZGetCoursesBySiteName = z.object({
|
2026-03-09 11:18:22 +01:00
|
|
|
siteName: z.string().min(1),
|
2026-06-07 18:43:05 +01:00
|
|
|
tags: z.string().optional(),
|
|
|
|
|
page: z.coerce.number().int().min(1).optional(),
|
|
|
|
|
limit: z.coerce.number().int().min(1).max(100).optional()
|
2025-11-24 01:00:50 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TGetCoursesBySiteName = z.infer<typeof ZGetCoursesBySiteName>;
|
|
|
|
|
|
2026-03-09 11:18:22 +01:00
|
|
|
export const ZGetOrganizationCoursesQuery = z.object({
|
2026-04-12 08:58:41 +01:00
|
|
|
page: z.coerce.number().int().min(1).default(1),
|
|
|
|
|
limit: z.coerce.number().int().min(1).max(100).default(20),
|
|
|
|
|
search: z.string().trim().optional(),
|
2026-03-09 11:18:22 +01:00
|
|
|
tags: z.string().optional()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TGetOrganizationCoursesQuery = z.infer<typeof ZGetOrganizationCoursesQuery>;
|
|
|
|
|
|
2025-12-02 09:54:38 +01:00
|
|
|
export const ZGetOrgSetup = z.object({
|
|
|
|
|
siteName: z.string().min(1)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TGetOrgSetup = z.infer<typeof ZGetOrgSetup>;
|
|
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
export const ZCreateOrgPlan = z.object({
|
|
|
|
|
orgId: z.uuid(),
|
|
|
|
|
planName: z.enum(['EARLY_ADOPTER', 'ENTERPRISE', 'BASIC']),
|
|
|
|
|
subscriptionId: z.string().min(1),
|
|
|
|
|
triggeredBy: z.number().int().positive(),
|
|
|
|
|
payload: z.record(z.string(), z.unknown())
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TCreateOrgPlan = z.infer<typeof ZCreateOrgPlan>;
|
|
|
|
|
|
|
|
|
|
export const ZUpdateOrgPlan = z.object({
|
|
|
|
|
subscriptionId: z.string().min(1),
|
|
|
|
|
payload: z.record(z.string(), z.unknown())
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TUpdateOrgPlan = z.infer<typeof ZUpdateOrgPlan>;
|
|
|
|
|
|
|
|
|
|
export const ZCancelOrgPlan = z.object({
|
|
|
|
|
subscriptionId: z.string().min(1),
|
|
|
|
|
payload: z.record(z.string(), z.unknown())
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TCancelOrgPlan = z.infer<typeof ZCancelOrgPlan>;
|
2025-12-02 09:54:38 +01:00
|
|
|
|
|
|
|
|
export const ZCreateOrganization = z.object({
|
|
|
|
|
name: z
|
|
|
|
|
.string()
|
|
|
|
|
.min(5)
|
|
|
|
|
.refine((val) => !/^[-]|[-]$/.test(val), {
|
|
|
|
|
message: 'Organization name cannot start or end with a hyphen'
|
|
|
|
|
}),
|
|
|
|
|
siteName: z
|
|
|
|
|
.string()
|
|
|
|
|
.min(5)
|
|
|
|
|
.refine((val) => !/^[-]|[-]$/.test(val), {
|
|
|
|
|
message: 'Site name cannot start or end with a hyphen'
|
|
|
|
|
})
|
|
|
|
|
.refine((val) => !blockedSubdomain.includes(val), {
|
|
|
|
|
message: 'Sitename already exists.'
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TCreateOrganization = z.infer<typeof ZCreateOrganization>;
|
|
|
|
|
|
|
|
|
|
export const ZUpdateOrganization = z.object({
|
|
|
|
|
name: z
|
|
|
|
|
.string()
|
|
|
|
|
.min(5)
|
|
|
|
|
.refine((val) => !/^[-]|[-]$/.test(val), {
|
|
|
|
|
message: 'Organization name cannot start or end with a hyphen'
|
|
|
|
|
})
|
|
|
|
|
.optional(),
|
|
|
|
|
avatarUrl: z.url().optional(),
|
|
|
|
|
theme: z.string().optional(),
|
|
|
|
|
landingpage: z.record(z.string(), z.unknown()).optional(),
|
|
|
|
|
siteName: z.string().min(1).optional(),
|
|
|
|
|
customDomain: z.string().nullable().optional(),
|
|
|
|
|
isCustomDomainVerified: z.boolean().optional(),
|
2026-03-09 11:18:22 +01:00
|
|
|
customization: z.record(z.string(), z.unknown()).optional(),
|
|
|
|
|
disableSignup: z.boolean().optional(),
|
|
|
|
|
disableSignupMessage: z.string().optional(),
|
|
|
|
|
disableEmailPassword: z.boolean().optional(),
|
|
|
|
|
disableGoogleAuth: z.boolean().optional(),
|
|
|
|
|
/** Nested settings (stored in organization.settings JSONB). signup.inviteOnly = true means invite-only signup. */
|
|
|
|
|
settings: z
|
|
|
|
|
.object({
|
|
|
|
|
signup: z
|
|
|
|
|
.object({
|
|
|
|
|
inviteOnly: z.boolean().optional()
|
|
|
|
|
})
|
|
|
|
|
.optional()
|
|
|
|
|
})
|
|
|
|
|
.optional()
|
2025-12-02 09:54:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TUpdateOrganization = z.infer<typeof ZUpdateOrganization>;
|
|
|
|
|
|
|
|
|
|
export const ZInviteTeamMembers = z.object({
|
|
|
|
|
emails: z.array(z.string().email()).min(1).max(50),
|
|
|
|
|
roleId: z.number().int().positive()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TInviteTeamMembers = z.infer<typeof ZInviteTeamMembers>;
|
|
|
|
|
|
|
|
|
|
export const ZRemoveTeamMember = z.object({
|
2026-03-09 11:18:22 +01:00
|
|
|
memberId: z.coerce.number().int().positive()
|
2025-12-02 09:54:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TRemoveTeamMember = z.infer<typeof ZRemoveTeamMember>;
|
2026-03-09 11:18:22 +01:00
|
|
|
|
2026-06-07 18:43:05 +01:00
|
|
|
export const ZCreateLinkInvite = z.object({
|
|
|
|
|
roleId: z.number().int().positive()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TCreateLinkInvite = z.infer<typeof ZCreateLinkInvite>;
|
|
|
|
|
|
|
|
|
|
export const ZToggleLinkInvite = z.object({
|
|
|
|
|
isRevoked: z.boolean()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TToggleLinkInvite = z.infer<typeof ZToggleLinkInvite>;
|
|
|
|
|
|
2026-03-09 11:18:22 +01:00
|
|
|
export const ZGetUserAnalytics = z.object({
|
|
|
|
|
userId: z.uuid()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type TGetUserAnalytics = z.infer<typeof ZGetUserAnalytics>;
|