fix: v2 event-types (#16132)

* refactor: have system and user booking fields schemas and united schema

* fix: event-types output service filter out system booking fields for response

* chore: v2 update platform-libraries to 0.0.25

* chore: platform-libraries export types and update changelog

* chore: add updated lock file
This commit is contained in:
Lauris Skraucis authored and GitHub committed 2024-08-08 20:21:56 +03:00
1 parent 90ce124bbb
commit 2b9bdb9c80
33 files changed
+327 -1162

No files matched your search

@@ -267,7 +267,7 @@ export default class Office365CalendarService implements Calendar {
subject: event.title,
body: {
contentType: "HTML",
content: getRichDescription(event),
content: getRichDescription(event).replace(/\n/g, "<br>"),
},
start: {
dateTime: dayjs(event.startTime).tz(event.organizer.timeZone).format("YYYY-MM-DDTHH:mm:ss"),
@@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";
import type { BookingField_2024_06_14, Location_2024_06_14 } from "@calcom/platform-types";
import type { CommonField, OptionsField } from "./api-request";
import type { UserField, OptionsField } from "./api-request";
import {
transformApiEventTypeLocations,
transformApiEventTypeBookingFields,
@@ -90,7 +90,7 @@ describe("transformApiEventTypeBookingFields", () => {
const input: BookingField_2024_06_14[] = [bookingField];
const expectedOutput: CommonField[] = [
const expectedOutput: UserField[] = [
{
name: bookingField.slug,
type: bookingField.type,
@@ -125,7 +125,7 @@ describe("transformApiEventTypeBookingFields", () => {
const input: BookingField_2024_06_14[] = [bookingField];
const expectedOutput: CommonField[] = [
const expectedOutput: UserField[] = [
{
name: bookingField.slug,
type: bookingField.type,
@@ -160,7 +160,7 @@ describe("transformApiEventTypeBookingFields", () => {
const input: BookingField_2024_06_14[] = [bookingField];
const expectedOutput: CommonField[] = [
const expectedOutput: UserField[] = [
{
name: bookingField.slug,
type: bookingField.type,
@@ -195,7 +195,7 @@ describe("transformApiEventTypeBookingFields", () => {
const input: BookingField_2024_06_14[] = [bookingField];
const expectedOutput: CommonField[] = [
const expectedOutput: UserField[] = [
{
name: bookingField.slug,
type: bookingField.type,
@@ -230,7 +230,7 @@ describe("transformApiEventTypeBookingFields", () => {
const input: BookingField_2024_06_14[] = [bookingField];
const expectedOutput: CommonField[] = [
const expectedOutput: UserField[] = [
{
name: bookingField.slug,
type: bookingField.type,
@@ -265,7 +265,7 @@ describe("transformApiEventTypeBookingFields", () => {
const input: BookingField_2024_06_14[] = [bookingField];
const expectedOutput: CommonField[] = [
const expectedOutput: UserField[] = [
{
name: bookingField.slug,
type: bookingField.type,
@@ -300,7 +300,7 @@ describe("transformApiEventTypeBookingFields", () => {
const input: BookingField_2024_06_14[] = [bookingField];
const expectedOutput: CommonField[] = [
const expectedOutput: UserField[] = [
{
name: bookingField.slug,
type: bookingField.type,
@@ -408,7 +408,7 @@ describe("transformApiEventTypeBookingFields", () => {
const input: BookingField_2024_06_14[] = [bookingField];
const expectedOutput: CommonField[] = [
const expectedOutput: UserField[] = [
{
name: bookingField.slug,
type: bookingField.type,
@@ -514,7 +514,7 @@ describe("transformApiEventTypeBookingFields", () => {
const input: BookingField_2024_06_14[] = [bookingField];
const expectedOutput: CommonField[] = [
const expectedOutput: UserField[] = [
{
name: bookingField.slug,
type: bookingField.type,
@@ -70,7 +70,7 @@ function transformApiEventTypeBookingFields(
}
const customBookingFields = inputBookingFields.map((field) => {
const commonFields: CommonField = {
const commonFields: UserField = {
name: field.slug,
type: field.type,
label: field.label,
@@ -126,7 +126,7 @@ const FieldTypeEnum = z.enum([
"radioInput",
]);
const CommonFieldsSchema = z.object({
const UserFieldsSchema = z.object({
name: z.string(),
type: FieldTypeEnum,
label: z.string(),
@@ -141,13 +141,21 @@ const CommonFieldsSchema = z.object({
editable: z.literal("user"),
required: z.boolean(),
placeholder: z.string().optional(),
options: z
.array(
z.object({
label: z.string(),
value: z.string(),
})
)
.optional(),
});
const SystemFieldsSchema = z.object({
name: z.string(),
type: FieldTypeEnum,
defaultLabel: z.string(),
labe: z.string().optional(),
label: z.string().optional(),
editable: z.enum(["system-but-optional", "system"]),
sources: z.array(
z.object({
@@ -187,18 +195,8 @@ const SystemFieldsSchema = z.object({
export type SystemField = z.infer<typeof SystemFieldsSchema>;
export type CommonField = z.infer<typeof CommonFieldsSchema>;
export type UserField = z.infer<typeof UserFieldsSchema>;
const OptionSchema = z.object({
label: z.string(),
value: z.string(),
});
const BookingFieldSchema = CommonFieldsSchema.extend({
options: z.array(OptionSchema).optional(),
});
export type OptionsField = z.infer<typeof BookingFieldSchema>;
export const BookingFieldsSchema = z.array(BookingFieldSchema);
export const BookingFieldsSchema = z.array(z.union([UserFieldsSchema, SystemFieldsSchema]));
export { transformApiEventTypeLocations, transformApiEventTypeBookingFields };
@@ -7,7 +7,7 @@ import type {
IntegrationLocation_2024_06_14,
} from "@calcom/platform-types";
import type { CommonField, OptionsField } from "./api-request";
import type { UserField, OptionsField } from "./api-request";
import { getResponseEventTypeLocations, getResponseEventTypeBookingFields } from "./api-response";
describe("getResponseEventTypeLocations", () => {
@@ -99,7 +99,7 @@ describe("getResponseEventTypeLocations", () => {
describe("getResponseEventTypeBookingFields", () => {
it("should reverse transform name field", () => {
const transformedField: CommonField[] = [
const transformedField: UserField[] = [
{
name: "your-name",
type: "name",
@@ -134,7 +134,7 @@ describe("getResponseEventTypeBookingFields", () => {
});
it("should reverse transform email field", () => {
const transformedField: CommonField[] = [
const transformedField: UserField[] = [
{
name: "your-email",
type: "email",
@@ -169,7 +169,7 @@ describe("getResponseEventTypeBookingFields", () => {
});
it("should reverse transform phone field", () => {
const transformedField: CommonField[] = [
const transformedField: UserField[] = [
{
name: "your-phone",
type: "phone",
@@ -204,7 +204,7 @@ describe("getResponseEventTypeBookingFields", () => {
});
it("should reverse transform address field", () => {
const transformedField: CommonField[] = [
const transformedField: UserField[] = [
{
name: "your-address",
type: "address",
@@ -239,7 +239,7 @@ describe("getResponseEventTypeBookingFields", () => {
});
it("should reverse transform text field", () => {
const transformedField: CommonField[] = [
const transformedField: UserField[] = [
{
name: "your-text",
type: "text",
@@ -274,7 +274,7 @@ describe("getResponseEventTypeBookingFields", () => {
});
it("should reverse transform number field", () => {
const transformedField: CommonField[] = [
const transformedField: UserField[] = [
{
name: "your-number",
type: "number",
@@ -309,7 +309,7 @@ describe("getResponseEventTypeBookingFields", () => {
});
it("should reverse transform textarea field", () => {
const transformedField: CommonField[] = [
const transformedField: UserField[] = [
{
name: "your-textarea",
type: "textarea",
@@ -422,7 +422,7 @@ describe("getResponseEventTypeBookingFields", () => {
});
it("should reverse transform multiemail field", () => {
const transformedField: CommonField[] = [
const transformedField: UserField[] = [
{
name: "your-multiemail",
type: "multiemail",
@@ -533,7 +533,7 @@ describe("getResponseEventTypeBookingFields", () => {
});
it("should reverse transform boolean field", () => {
const transformedField: CommonField[] = [
const transformedField: UserField[] = [
{
name: "agree-to-terms",
type: "boolean",
@@ -4,6 +4,7 @@ import type {
LinkLocation_2024_06_14,
PhoneLocation_2024_06_14,
Integration_2024_06_14,
BookingField_2024_06_14,
} from "@calcom/platform-types";
import type { transformApiEventTypeBookingFields, transformApiEventTypeLocations } from "./api-request";
@@ -71,7 +72,7 @@ function getResponseEventTypeLocations(
function getResponseEventTypeBookingFields(
transformedBookingFields: ReturnType<typeof transformApiEventTypeBookingFields>
) {
): BookingField_2024_06_14[] {
if (!transformedBookingFields) {
return [];
}
@@ -156,7 +157,7 @@ function getResponseEventTypeBookingFields(
label: field.label,
required: field.required,
placeholder: field.placeholder,
options: "options" in field ? field.options?.map((option) => option.value) : [],
options: field.options ? field.options.map((option) => option.value) : [],
};
case "multiselect":
return {
@@ -164,7 +165,7 @@ function getResponseEventTypeBookingFields(
slug: field.name,
label: field.label,
required: field.required,
options: "options" in field ? field.options?.map((option) => option.value) : [],
options: field.options ? field.options?.map((option) => option.value) : [],
};
case "checkbox":
return {
@@ -172,7 +173,7 @@ function getResponseEventTypeBookingFields(
slug: field.name,
label: field.label,
required: field.required,
options: "options" in field ? field.options?.map((option) => option.value) : [],
options: field.options ? field.options?.map((option) => option.value) : [],
};
case "radio":
return {
@@ -180,7 +181,7 @@ function getResponseEventTypeBookingFields(
slug: field.name,
label: field.label,
required: field.required,
options: "options" in field ? field.options?.map((option) => option.value) : [],
options: field.options ? field.options?.map((option) => option.value) : [],
};
default:
throw new Error(`Unsupported booking field type '${field.type}'.`);
+15
View File
@@ -1,3 +1,18 @@
## 0.0.26
Update `packages/app-store/office365calendar/lib/CalendarService.ts` "translateEvent" content so that in microsoft outlook calendar event the description
has newlines instead of being all in 1 line.
## 0.0.25
Refactor "packages/lib/event-types/transformers/api-request.ts" getResponseEventTypeBookingFields - make sure that booking fields with options don't have
undefines options.
## 0.0.24
Refactor "packages/lib/event-types/transformers/api-request.ts" - we access event-type booking fields in database and then distinguish them as either
created by the user or system. Then in v2 api "event-types_2024_06_14/services/output-event-types.service.ts" we first parse them and then filter
out only user fields. This is done because when creating an event-type we only store user passed booking fields, but if someone already had created
booking-fields using event-types version 2024_04_15, then they contained system fields which is why event-types 2024_06_14 controller was failing.
## 0.0.23
Update "createBooking" (packages/features/bookings/lib/handleNewBooking/createBooking.ts) that is used by handleNewBooking (packages/features/bookings/lib/handleNewBooking.ts) to correctly handle metadata of a re-scheduled booking. Previously,
metadata of original booking was overwriting metadata in the request body of the new booking (rescheduled), but now
+2
View File
@@ -100,6 +100,8 @@ export {
BookingFieldsSchema,
} from "@calcom/lib/event-types/transformers";
export type { SystemField, UserField } from "@calcom/lib/event-types/transformers";
export { parseRecurringEvent } from "@calcom/lib/isRecurringEvent";
export { dynamicEvent } from "@calcom/lib/defaultEvents";