metis-desk/modules/resources/src/common/dto/shared/application-reference.dto.ts

116 lines
3.5 KiB
TypeScript
Raw Normal View History

2026-10-24 23:19:17 +00:00
import { z } from "zod/v4";
import { ResourceInputSchema, ResourceSpecificationSchema } from "../../inventory";
import { OperatingSystemIdentitySchema } from "../../operating-system-identity";
2026-10-24 23:19:17 +00:00
export const ResourcePurposeSchema = z.enum(["software-installation", "application-configuration"]);
const identity = {
id: z.uuid(),
templateId: z.uuid(),
name: z.string().min(1).max(100),
active: z.boolean(),
};
export const ApplicationReferenceSchema = z.discriminatedUnion("scope", [
z.strictObject({
...identity,
kind: z.literal("application"),
scope: z.literal("global"),
companyId: z.null(),
}),
z.strictObject({
...identity,
kind: z.literal("application"),
scope: z.literal("company"),
companyId: z.uuid(),
}),
]);
export const LocalOsReferenceSchema = z.strictObject({
...identity,
kind: z.literal("os"),
scope: z.literal("company"),
companyId: z.uuid(),
});
export const GlobalOperatingSystemReferenceSchema = z.strictObject({
...identity,
...OperatingSystemIdentitySchema.shape,
kind: z.literal("os"),
scope: z.literal("global"),
companyId: z.null(),
href: z.string().startsWith("/catalogs/global-operating-systems/"),
});
export const GlobalOperatingSystemDetailSchema = GlobalOperatingSystemReferenceSchema.extend({
url: z.string().nullable(),
description: z.string().nullable(),
});
export type GlobalOperatingSystemReference = z.infer<typeof GlobalOperatingSystemReferenceSchema>;
export type GlobalOperatingSystemDetail = z.infer<typeof GlobalOperatingSystemDetailSchema>;
2026-10-24 23:19:17 +00:00
export const SoftwareReferenceSchema = z.union([
GlobalOperatingSystemReferenceSchema,
2026-10-24 23:19:17 +00:00
ApplicationReferenceSchema,
LocalOsReferenceSchema,
]);
export const CompanyApplicationSummarySchema = z.union([
ApplicationReferenceSchema.options[0].extend({ provider: z.string().nullable() }),
ApplicationReferenceSchema.options[1].extend({ provider: z.string().nullable() }),
]);
export type CompanyApplicationSummary = z.infer<typeof CompanyApplicationSummarySchema>;
2026-10-24 23:19:17 +00:00
export const ApplicationCandidateSchema = z.union([
ApplicationReferenceSchema.options[0].extend({
active: z.literal(true),
provider: z.string().nullable(),
}),
ApplicationReferenceSchema.options[1].extend({
active: z.literal(true),
provider: z.string().nullable(),
}),
]);
export const ResourceCandidateSchema = z.union([
GlobalOperatingSystemReferenceSchema.extend({ active: z.literal(true) }),
2026-10-24 23:19:17 +00:00
ApplicationCandidateSchema,
LocalOsReferenceSchema.extend({ active: z.literal(true), provider: z.string().nullable() }),
]);
export const GlobalApplicationSummarySchema = z.strictObject({
...identity,
kind: z.literal("application"),
scope: z.literal("global"),
companyId: z.null(),
provider: z.string().nullable(),
});
export const GlobalApplicationDetailSchema = GlobalApplicationSummarySchema.extend({
url: z.string().nullable(),
description: z.string().nullable(),
});
export const GlobalResourceAdminSchema = z.strictObject({
revisionId: z.uuid(),
id: z.uuid(),
scope: z.literal("global"),
companyId: z.null(),
values: ResourceInputSchema.omit({ integration: true }),
specification: ResourceSpecificationSchema,
});
export type ResourcePurpose = z.infer<typeof ResourcePurposeSchema>;
export type SoftwareReference = z.infer<typeof SoftwareReferenceSchema>;
export type ResourceCandidate = z.infer<typeof ResourceCandidateSchema>;
export type GlobalApplicationSummary = z.infer<typeof GlobalApplicationSummarySchema>;
export type GlobalApplicationDetail = z.infer<typeof GlobalApplicationDetailSchema>;