fix: v2 event types booking fields & enable booker atom google-meet location (#17321)

* fix: v2 phone system booking field

* feat: atom support google-meet

* feat: unknown booking field return type

* tests

* bump platform libraries

* driveby: improve create-booking-input
This commit is contained in:
Lauris Skraucis authored and GitHub committed 2024-10-25 15:55:29 +03:00
1 parent 9157e1faf3
commit 69ca57e45a
16 files changed
+496 -1470

No files matched your search

@@ -230,6 +230,8 @@ function getLocations(locations: EventTypeOutput_2024_06_14["locations"]) {
function isAtomSupportedLocation(
location: EventTypeOutput_2024_06_14["locations"][number]
): location is InputLocation_2024_06_14 {
const supportedIntegrations = ["cal-video", "google-meet"];
return (
location.type === "address" ||
location.type === "attendeeAddress" ||
@@ -237,7 +239,7 @@ function isAtomSupportedLocation(
location.type === "phone" ||
location.type === "attendeePhone" ||
location.type === "attendeeDefined" ||
(location.type === "integration" && location.integration === "cal-video")
(location.type === "integration" && supportedIntegrations.includes(location.integration))
);
}
@@ -291,7 +293,7 @@ function getBookingFields(
function isCustomField(
field: EventTypeOutput_2024_06_14["bookingFields"][number]
): field is CustomFieldOutput_2024_06_14 {
return !field.isDefault;
return field.type !== "unknown" && !field.isDefault;
}
function isDefaultEditableField(
+1
View File
@@ -129,6 +129,7 @@ export {
InternalLocationsSchema,
InternalLocationSchema,
BookingFieldsSchema,
BookingFieldSchema,
// note(Lauris): constants
systemBeforeFieldName,
systemBeforeFieldEmail,
@@ -102,7 +102,7 @@ export class CreateBookingInputPipe implements PipeTransform {
private isRecurringBookingInput(
value: CreateBookingInput
): value is CreateRecurringBookingInput_2024_08_13 {
return value.hasOwnProperty("eventTypeId");
return value.hasOwnProperty("recurrenceCount");
}
private isInstantBookingInput(value: CreateBookingInput): value is CreateInstantBookingInput_2024_08_13 {
@@ -145,85 +145,7 @@ export class CreateInstantBookingInput_2024_08_13 extends CreateBookingInput_202
instant!: boolean;
}
export class CreateRecurringBookingInput_2024_08_13 {
@ApiProperty({
type: String,
description: "The start time of the booking in ISO 8601 format in UTC timezone.",
example: "2024-08-13T09:00:00Z",
})
@IsDateString()
start!: string;
@ApiProperty({
type: Number,
description: "The ID of the event type that is booked.",
example: 123,
})
@IsInt()
eventTypeId!: number;
@ApiProperty({
type: Attendee,
description: "The attendee's details.",
})
@ValidateNested()
@Type(() => Attendee)
attendee!: Attendee;
@ApiProperty({
type: [String],
description: "An optional list of guest emails attending the event.",
example: ["[email protected]", "[email protected]"],
required: false,
})
@IsArray()
@IsString({ each: true })
@IsOptional()
guests?: string[];
@ApiProperty({
type: String,
description:
"Deprecated - use 'location' instead. Meeting URL just for this booking. Displayed in email and calendar event. If not provided then cal video link will be generated.",
example: "https://example.com/meeting",
required: false,
deprecated: true,
})
@IsUrl()
@IsOptional()
meetingUrl?: string;
@ApiProperty({
type: String,
description: "Location for this booking. Displayed in email and calendar event.",
example: "https://example.com/meeting",
required: false,
})
@IsUrl()
@IsOptional()
location?: string;
// todo(Lauris): expose after refactoring metadata https://app.campsite.co/cal/posts/zysq8w9rwm9c
// @ApiProperty({
// type: Object,
// description: "Optional metadata for the booking.",
// example: { key: "value" },
// required: false,
// })
// @IsObject()
// @IsOptional()
// metadata!: Record<string, unknown>;
@ApiProperty({
type: Object,
description: "Booking field responses.",
example: { customField: "customValue" },
required: false,
})
@IsObject()
@IsOptional()
bookingFieldsResponses?: Record<string, unknown>;
export class CreateRecurringBookingInput_2024_08_13 extends CreateBookingInput_2024_08_13 {
@ApiPropertyOptional({
type: Number,
description: `The number of recurrences. If not provided then event type recurrence count will be used. Can't be more than
@@ -521,7 +521,7 @@ class InputBookingFieldValidator_2024_06_14 implements ValidatorConstraintInterf
boolean: BooleanFieldInput_2024_06_14,
};
private reservedSystemSlugs = ["location", "rescheduleReason"];
private reservedSystemSlugs = ["location", "rescheduleReason", "attendeePhoneNumber"];
async validate(bookingFields: { type: string; slug: string }[]) {
if (!Array.isArray(bookingFields)) {
@@ -43,16 +43,16 @@ export class InputLinkLocation_2024_06_14 {
public!: boolean;
}
const integrations = ["cal-video"] as const;
export type Integration_2024_06_14 = (typeof integrations)[number];
export const supportedIntegrations = ["cal-video", "google-meet"] as const;
export type Integration_2024_06_14 = (typeof supportedIntegrations)[number];
export class InputIntegrationLocation_2024_06_14 {
@IsIn(inputLocations)
@DocsProperty({ example: "integration", description: "only allowed value for type is `integration`" })
type!: "integration";
@IsIn(integrations)
@DocsProperty({ example: integrations[0], enum: integrations })
@IsIn(supportedIntegrations)
@DocsProperty({ example: supportedIntegrations[0], enum: supportedIntegrations })
integration!: Integration_2024_06_14;
}
@@ -205,6 +205,32 @@ export class GuestsDefaultFieldOutput_2024_06_14 {
required!: false;
}
export class PhoneDefaultFieldOutput_2024_06_14 {
@IsBoolean()
@DocsProperty({
description: "This property is always true because it's a default field",
example: true,
default: true,
})
isDefault = true;
@IsString()
@DocsProperty({
default: "attendeePhoneNumber",
})
slug!: "attendeePhoneNumber";
@IsString()
@DocsProperty({
default: "phone",
})
type!: "phone";
@IsBoolean()
@DocsProperty()
required!: boolean;
}
export class PhoneFieldOutput_2024_06_14 extends PhoneFieldInput_2024_06_14 {
@IsBoolean()
@DocsProperty({
@@ -315,6 +341,17 @@ export class BooleanFieldOutput_2024_06_14 extends BooleanFieldInput_2024_06_14
isDefault = false;
}
export class OutputUnknownBookingField_2024_06_14 {
@DocsProperty({ example: "unknown", description: "only allowed value for type is `unknown`" })
type!: "unknown";
@DocsProperty({ example: "unknown", description: "only allowed value for type is `unknown`" })
slug!: "unknown";
@IsString()
bookingField!: string;
}
export type DefaultFieldOutput_2024_06_14 =
| NameDefaultFieldOutput_2024_06_14
| EmailDefaultFieldOutput_2024_06_14
@@ -322,7 +359,8 @@ export type DefaultFieldOutput_2024_06_14 =
| RescheduleReasonDefaultFieldOutput_2024_06_14
| TitleDefaultFieldOutput_2024_06_14
| NotesDefaultFieldOutput_2024_06_14
| GuestsDefaultFieldOutput_2024_06_14;
| GuestsDefaultFieldOutput_2024_06_14
| PhoneDefaultFieldOutput_2024_06_14;
export type CustomFieldOutput_2024_06_14 =
| PhoneFieldOutput_2024_06_14
@@ -337,7 +375,10 @@ export type CustomFieldOutput_2024_06_14 =
| RadioGroupFieldOutput_2024_06_14
| BooleanFieldOutput_2024_06_14;
export type OutputBookingField_2024_06_14 = DefaultFieldOutput_2024_06_14 | CustomFieldOutput_2024_06_14;
export type OutputBookingField_2024_06_14 =
| DefaultFieldOutput_2024_06_14
| CustomFieldOutput_2024_06_14
| OutputUnknownBookingField_2024_06_14;
@ValidatorConstraint({ async: true })
class OutputBookingFieldValidator_2024_06_14 implements ValidatorConstraintInterface {
@@ -349,6 +390,7 @@ class OutputBookingFieldValidator_2024_06_14 implements ValidatorConstraintInter
title: TitleDefaultFieldOutput_2024_06_14,
notes: NotesDefaultFieldOutput_2024_06_14,
guests: GuestsDefaultFieldOutput_2024_06_14,
attendeePhoneNumber: PhoneDefaultFieldOutput_2024_06_14,
};
private customOutputTypeMap: { [key: string]: new () => CustomFieldOutput_2024_06_14 } = {
@@ -390,9 +432,13 @@ class OutputBookingFieldValidator_2024_06_14 implements ValidatorConstraintInter
`Duplicate bookingFields slug '${slug}' found. All bookingFields slugs must be unique.`
);
}
slugs.push(slug);
if (slug !== "unknown") {
slugs.push(slug);
}
if (this.isDefaultField(field)) {
if (this.isUnknownField(field)) {
await this.validateUnknownField(field);
} else if (this.isDefaultField(field)) {
await this.validateDefaultField(field);
} else {
await this.validateCustomField(field);
@@ -403,13 +449,26 @@ class OutputBookingFieldValidator_2024_06_14 implements ValidatorConstraintInter
}
isDefaultField(field: OutputBookingField_2024_06_14): field is DefaultFieldOutput_2024_06_14 {
return field.isDefault === true;
return field.type !== "unknown" && "isDefault" in field && field.isDefault === true;
}
isUnknownField(field: OutputBookingField_2024_06_14): field is OutputUnknownBookingField_2024_06_14 {
return field.type === "unknown";
}
async validateUnknownField(field: OutputUnknownBookingField_2024_06_14) {
const instance = plainToInstance(OutputUnknownBookingField_2024_06_14, field);
const errors = await validate(instance);
if (errors.length > 0) {
const message = errors.flatMap((error) => Object.values(error.constraints || {})).join(", ");
throw new BadRequestException(`Validation failed for ${field.slug} booking field: ${message}`);
}
}
async validateDefaultField(field: DefaultFieldOutput_2024_06_14) {
const ClassType = this.defaultOutputNameMap[field.slug];
if (!ClassType) {
throw new BadRequestException(`Unsupported booking field slgu '${field.slug}'.`);
throw new BadRequestException(`Unsupported default booking field slug '${field.slug}'.`);
}
const instance = plainToInstance(ClassType, field);