feat: v2 expose booking metadata (#17708)
* feat: accept metadata and store it in database * feat: accept metadata and store it in database * feat: add BookingSeat.metadata column * feat: handleNewBooking: store booking seat metadata when first time seated booking * feat: handleSeats, createNewSeat store metadata when 2nd+ seated booking * feat: return booking metadata in output * tests: metadata * test: seated bookings * swagger * fix: reassign bookings test * test: use different metadata in recurring * fix: test * test invalid metadata * refactor: output service * readd new line * chore: bump platform libraries * refactor: metadata doc
This commit is contained in:
1 parent
1404581f78
commit
58cac84f4a
21 files changed
+6158
-120
No files matched your search
@@ -1,8 +1,10 @@
|
||||
import { EMAIL_FROM_NAME } from "@calcom/lib/constants";
|
||||
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
||||
|
||||
import { renderEmail } from "../";
|
||||
import generateIcsFile, { GenerateIcsRole } from "../lib/generateIcsFile";
|
||||
import OrganizerScheduledEmail from "./organizer-scheduled-email";
|
||||
import type { Reassigned } from "./organizer-scheduled-email";
|
||||
|
||||
export default class OrganizerReassignedEmail extends OrganizerScheduledEmail {
|
||||
protected async getNodeMailerPayload(): Promise<Record<string, unknown>> {
|
||||
@@ -20,12 +22,16 @@ export default class OrganizerReassignedEmail extends OrganizerScheduledEmail {
|
||||
title: this.calEvent.title,
|
||||
date: this.getFormattedDate(),
|
||||
})}`,
|
||||
html: await renderEmail("OrganizerReassignedEmail", {
|
||||
attendee: this.calEvent.organizer,
|
||||
calEvent: this.calEvent,
|
||||
reassigned: this.reassigned,
|
||||
}),
|
||||
html: await this.getHtml(this.calEvent, this.calEvent.organizer, this.reassigned),
|
||||
text: this.getTextBody("event_request_reassigned"),
|
||||
};
|
||||
}
|
||||
|
||||
protected async getHtml(calEvent: CalendarEvent, attendee: Person, reassigned: Reassigned | undefined) {
|
||||
return await renderEmail("OrganizerReassignedEmail", {
|
||||
calEvent,
|
||||
attendee,
|
||||
reassigned,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import generateIcsFile from "../lib/generateIcsFile";
|
||||
import { GenerateIcsRole } from "../lib/generateIcsFile";
|
||||
import BaseEmail from "./_base-email";
|
||||
|
||||
type Reassigned = { name: string | null; email: string; reason?: string; byUser?: string };
|
||||
export type Reassigned = { name: string | null; email: string; reason?: string; byUser?: string };
|
||||
export default class OrganizerScheduledEmail extends BaseEmail {
|
||||
calEvent: CalendarEvent;
|
||||
t: TFunction;
|
||||
|
||||
@@ -1183,6 +1183,7 @@ async function handler(
|
||||
description: additionalNotes,
|
||||
responses,
|
||||
},
|
||||
metadata: reqBody.metadata,
|
||||
booking: {
|
||||
connect: {
|
||||
id: booking.id,
|
||||
|
||||
@@ -21,7 +21,8 @@ import type { SeatedBooking, NewSeatedBookingObject, HandleSeatsResultBooking }
|
||||
|
||||
const createNewSeat = async (
|
||||
rescheduleSeatedBookingObject: NewSeatedBookingObject,
|
||||
seatedBooking: SeatedBooking
|
||||
seatedBooking: SeatedBooking,
|
||||
metadata?: Record<string, string>
|
||||
) => {
|
||||
const {
|
||||
tAttendees,
|
||||
@@ -92,6 +93,7 @@ const createNewSeat = async (
|
||||
description: additionalNotes,
|
||||
responses,
|
||||
},
|
||||
metadata,
|
||||
booking: {
|
||||
connect: {
|
||||
id: seatedBooking.id,
|
||||
|
||||
@@ -95,7 +95,7 @@ const handleSeats = async (newSeatedBookingObject: NewSeatedBookingObject) => {
|
||||
loggerWithEventDetails
|
||||
);
|
||||
} else {
|
||||
resultBooking = await createNewSeat(newSeatedBookingObject, seatedBooking);
|
||||
resultBooking = await createNewSeat(newSeatedBookingObject, seatedBooking, reqBodyMetadata);
|
||||
}
|
||||
|
||||
// If the resultBooking is defined we should trigger workflows else, trigger in handleNewBooking
|
||||
|
||||
@@ -9,6 +9,7 @@ import AttendeeCancelledEmail from "@calcom/emails/templates/attendee-cancelled-
|
||||
import AttendeeDeclinedEmail from "@calcom/emails/templates/attendee-declined-email";
|
||||
import AttendeeScheduledEmail from "@calcom/emails/templates/attendee-scheduled-email";
|
||||
import OrganizerCancelledEmail from "@calcom/emails/templates/organizer-cancelled-email";
|
||||
import OrganizerReassignedEmail from "@calcom/emails/templates/organizer-reassigned-email";
|
||||
import OrganizerScheduledEmail from "@calcom/emails/templates/organizer-scheduled-email";
|
||||
import { getBookingForReschedule } from "@calcom/features/bookings/lib/get-booking";
|
||||
import getBookingInfo from "@calcom/features/bookings/lib/getBookingInfo";
|
||||
@@ -109,7 +110,7 @@ export { handleCancelBooking };
|
||||
|
||||
export { eventTypeBookingFields, eventTypeLocations } from "@calcom/prisma/zod-utils";
|
||||
|
||||
export { EventTypeMetaDataSchema, userMetadata } from "@calcom/prisma/zod-utils";
|
||||
export { EventTypeMetaDataSchema, userMetadata, bookingMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
export {
|
||||
// note(Lauris): Api to internal
|
||||
@@ -200,3 +201,5 @@ export { AttendeeDeclinedEmail };
|
||||
export { AttendeeCancelledEmail };
|
||||
|
||||
export { OrganizerCancelledEmail };
|
||||
|
||||
export { OrganizerReassignedEmail };
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
|
||||
import type { BookingLanguageType } from "./language";
|
||||
import { BookingLanguage } from "./language";
|
||||
import { ValidateMetadata } from "./validators/validate-metadata";
|
||||
|
||||
class Attendee {
|
||||
@ApiProperty({
|
||||
@@ -122,16 +123,20 @@ export class CreateBookingInput_2024_08_13 {
|
||||
@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:
|
||||
"You can store any additional data you want here. Metadata must have at most 50 keys, each key up to 40 characters, and string values up to 500 characters.",
|
||||
example: { key: "value" },
|
||||
required: false,
|
||||
})
|
||||
@IsObject()
|
||||
@IsOptional()
|
||||
@ValidateMetadata({
|
||||
message:
|
||||
"Metadata must have at most 50 keys, each key up to 40 characters, and string values up to 500 characters.",
|
||||
})
|
||||
metadata?: Record<string, string>;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
type: Object,
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import type { ValidationOptions, ValidationArguments } from "class-validator";
|
||||
import { registerDecorator } from "class-validator";
|
||||
|
||||
export function ValidateMetadata(validationOptions?: ValidationOptions) {
|
||||
return function (object: any, propertyName: string) {
|
||||
registerDecorator({
|
||||
name: "ValidateMetadata",
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
options: validationOptions,
|
||||
validator: {
|
||||
validate(metadata: any) {
|
||||
if (typeof metadata !== "object" || metadata === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const keys = Object.keys(metadata);
|
||||
|
||||
if (keys.length > 50) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const key of keys) {
|
||||
if (key.length > 40) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isInvalidValidKeyValue(metadata[key])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
defaultMessage(args: ValidationArguments) {
|
||||
return `${args.property} must be an object with up to 50 keys, each key name up to 40 characters, and values with a maximum length of 500 characters.`;
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function isInvalidValidKeyValue(keyValue: any) {
|
||||
if (!isString(keyValue)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isTooLong(keyValue)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isString(keyValue: any): keyValue is string {
|
||||
return typeof keyValue === "string";
|
||||
}
|
||||
|
||||
function isTooLong(keyValue: string) {
|
||||
return keyValue.length > 500;
|
||||
}
|
||||
@@ -57,6 +57,16 @@ export class SeatedAttendee extends Attendee {
|
||||
@IsObject()
|
||||
@Expose()
|
||||
bookingFieldsResponses!: Record<string, unknown>;
|
||||
|
||||
@ApiProperty({
|
||||
type: Object,
|
||||
example: { key: "value" },
|
||||
required: false,
|
||||
})
|
||||
@IsObject()
|
||||
@IsOptional()
|
||||
@Expose()
|
||||
metadata?: Record<string, string>;
|
||||
}
|
||||
|
||||
class Host {
|
||||
@@ -189,6 +199,16 @@ class BaseBookingOutput_2024_08_13 {
|
||||
@IsBoolean()
|
||||
@Expose()
|
||||
absentHost!: boolean;
|
||||
|
||||
@ApiProperty({
|
||||
type: Object,
|
||||
example: { key: "value" },
|
||||
required: false,
|
||||
})
|
||||
@IsObject()
|
||||
@IsOptional()
|
||||
@Expose()
|
||||
metadata?: Record<string, string>;
|
||||
}
|
||||
|
||||
export class BookingOutput_2024_08_13 extends BaseBookingOutput_2024_08_13 {
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "BookingSeat" ADD COLUMN "metadata" JSONB;
|
||||
@@ -1179,6 +1179,7 @@ model BookingSeat {
|
||||
attendee Attendee @relation(fields: [attendeeId], references: [id], onDelete: Cascade)
|
||||
/// @zod.custom(imports.bookingSeatDataSchema)
|
||||
data Json?
|
||||
metadata Json?
|
||||
|
||||
@@index([bookingId])
|
||||
@@index([attendeeId])
|
||||
|
||||
Reference in new issue
Block a user