* refactor: apply biome formatting to packages/features (batch 1 - small subdirs) Format small subdirectories in packages/features: di, flags, holidays, oauth, settings, users, assignment-reason, selectedCalendar, hashedLink, host, form, form-builder, availability, data-table, pbac, schedules, troubleshooter, eventtypes, calendar-subscription, and root-level files. Also includes straggler apps/web BookEventForm.tsx. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: apply biome formatting to packages/features (batch 2 - medium subdirs) Format medium subdirectories in packages/features: auth, credentials, calendars, routing-forms, routing-trace, attributes, watchlist, calAIPhone, tasker, and webhooks. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: apply biome formatting to packages/features (batch 3 - bookings + insights) Format bookings and insights subdirectories in packages/features. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: apply biome formatting to packages/features (batch 4 - ee) Format packages/features/ee subdirectory covering billing, workflows, organizations, teams, managed-event-types, round-robin, dsync, integration-attribute-sync, and payments. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: apply biome formatting to packages/features (batch 5 - booking-audit part 1) Format booking-audit di, actions, common, dto, repository, and types subdirectories in packages/features/booking-audit. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: apply biome formatting to packages/features (batch 6 - booking-audit part 2) Format booking-audit service subdirectory in packages/features/booking-audit. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
96 lines
3.1 KiB
TypeScript
96 lines
3.1 KiB
TypeScript
import z from "zod";
|
|
|
|
import {
|
|
ConditionIdentifierEnum,
|
|
ConditionOperatorEnum,
|
|
type IAttributeSyncRule,
|
|
type ICreateAttributeSyncInput,
|
|
type IFieldMapping,
|
|
type IFieldMappingFormState,
|
|
type IFieldMappingWithOptionalId,
|
|
type INewFieldMapping,
|
|
type ISyncFormData,
|
|
RuleOperatorEnum,
|
|
type TAttributeSyncRuleCondition,
|
|
} from "../repositories/IIntegrationAttributeSyncRepository";
|
|
|
|
const conditionIdentifierSchema = z.nativeEnum(ConditionIdentifierEnum);
|
|
const conditionOperatorSchema = z.nativeEnum(ConditionOperatorEnum);
|
|
const ruleOperatorSchema = z.nativeEnum(RuleOperatorEnum);
|
|
|
|
// Base condition schema
|
|
const baseConditionSchema = z.object({
|
|
identifier: conditionIdentifierSchema,
|
|
operator: conditionOperatorSchema,
|
|
});
|
|
|
|
// Team condition schema
|
|
const teamConditionSchema = baseConditionSchema.extend({
|
|
identifier: z.literal(ConditionIdentifierEnum.TEAM_ID),
|
|
value: z.array(z.number()),
|
|
});
|
|
|
|
// Attribute condition schema
|
|
const attributeConditionSchema = baseConditionSchema.extend({
|
|
identifier: z.literal(ConditionIdentifierEnum.ATTRIBUTE_ID),
|
|
attributeId: z.string(),
|
|
value: z.array(z.string()),
|
|
});
|
|
|
|
// Discriminated union for conditions
|
|
export const attributeSyncRuleConditionSchema: z.ZodType<TAttributeSyncRuleCondition> = z.discriminatedUnion(
|
|
"identifier",
|
|
[teamConditionSchema, attributeConditionSchema]
|
|
);
|
|
|
|
export const attributeSyncRuleSchema: z.ZodType<IAttributeSyncRule> = z.object({
|
|
operator: ruleOperatorSchema,
|
|
conditions: z.array(attributeSyncRuleConditionSchema),
|
|
});
|
|
|
|
// Define base schema without type annotation to preserve ZodObject methods like .extend()
|
|
const _newFieldMappingSchema = z.object({
|
|
integrationFieldName: z.string().min(1),
|
|
attributeId: z.string().min(1),
|
|
enabled: z.boolean(),
|
|
});
|
|
|
|
const _fieldMappingSchema = _newFieldMappingSchema.extend({
|
|
id: z.string(),
|
|
});
|
|
|
|
const _fieldMappingWithOptionalIdSchema = _newFieldMappingSchema.extend({
|
|
id: z.string().optional(),
|
|
});
|
|
|
|
// Cast to ZodType for type safety
|
|
export const newFieldMappingSchema: z.ZodType<INewFieldMapping> = _newFieldMappingSchema;
|
|
export const fieldMappingSchema: z.ZodType<IFieldMapping> = _fieldMappingSchema;
|
|
export const fieldMappingWithOptionalIdSchema: z.ZodType<IFieldMappingWithOptionalId> =
|
|
_fieldMappingWithOptionalIdSchema;
|
|
|
|
const _fieldMappingFormStateSchema: z.ZodType<IFieldMappingFormState> = z.object({
|
|
mappings: z.array(fieldMappingWithOptionalIdSchema),
|
|
});
|
|
|
|
export const syncFormDataSchema: z.ZodType<ISyncFormData> = z.object({
|
|
id: z.string(),
|
|
name: z.string().min(1, "Name is required"),
|
|
credentialId: z.number().optional(),
|
|
enabled: z.boolean(),
|
|
organizationId: z.number(),
|
|
ruleId: z.string(),
|
|
rule: attributeSyncRuleSchema,
|
|
syncFieldMappings: z.array(z.union([fieldMappingSchema, newFieldMappingSchema])),
|
|
});
|
|
|
|
export const createAttributeSyncSchema: z.ZodType<ICreateAttributeSyncInput> = z.object({
|
|
name: z.string().min(1, "Name is required"),
|
|
credentialId: z.number(),
|
|
rule: attributeSyncRuleSchema,
|
|
syncFieldMappings: z.array(newFieldMappingSchema),
|
|
enabled: z.boolean(),
|
|
});
|
|
|
|
export type ZCreateAttributeSyncSchema = ICreateAttributeSyncInput;
|