From cb11c3b47209bab2dcdec2017b07bd2e56668c53 Mon Sep 17 00:00:00 2001 From: supalarry Date: Wed, 15 Jan 2025 08:34:39 +0100 Subject: [PATCH 01/13] chore: examples app make managed user admin --- packages/platform/examples/base/src/pages/api/managed-user.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/platform/examples/base/src/pages/api/managed-user.ts b/packages/platform/examples/base/src/pages/api/managed-user.ts index a7cca4f40552e4..344be347fb385f 100644 --- a/packages/platform/examples/base/src/pages/api/managed-user.ts +++ b/packages/platform/examples/base/src/pages/api/managed-user.ts @@ -169,6 +169,7 @@ async function createMembership(orgId: number, teamId: number, userId: number) { body: JSON.stringify({ userId, accepted: true, + role: "ADMIN", }), } ); From c55174b3797b1c01640cacad7ef3b393b3448aa5 Mon Sep 17 00:00:00 2001 From: supalarry Date: Wed, 15 Jan 2025 08:41:07 +0100 Subject: [PATCH 02/13] fix: phone field not appearing --- .../event-types/transformers/api-to-internal/booking-fields.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/lib/event-types/transformers/api-to-internal/booking-fields.ts b/packages/lib/event-types/transformers/api-to-internal/booking-fields.ts index ab6b7ed1d588f3..123870892087e7 100644 --- a/packages/lib/event-types/transformers/api-to-internal/booking-fields.ts +++ b/packages/lib/event-types/transformers/api-to-internal/booking-fields.ts @@ -84,6 +84,7 @@ function getBaseProperties(field: InputBookingField): CustomField | SystemField return { ...systemBeforeFieldPhone, required: field.required, + hidden: field.hidden, }; } From 8112bc7f4d0d0cd15e3f821a1f38be8fac9b9e8d Mon Sep 17 00:00:00 2001 From: supalarry Date: Wed, 15 Jan 2025 09:57:50 +0100 Subject: [PATCH 03/13] fix: booking fields order --- .../services/output-event-types.service.ts | 14 +- .../internal-to-api/booking-fields.ts | 175 ++---------------- .../outputs/booking-fields.output.ts | 7 + 3 files changed, 21 insertions(+), 175 deletions(-) diff --git a/apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts b/apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts index d443159619e8ce..2c85608a79f664 100644 --- a/apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts +++ b/apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts @@ -243,19 +243,7 @@ export class OutputEventTypesService_2024_06_14 { } } - const fields = [...transformBookingFieldsInternalToApi(knownBookingFields), ...unknownBookingFields]; - - // ensure additional notes are always at the end - return fields.sort((a, b) => { - if (!a?.slug || !b?.slug) return 0; - if (a.slug === "notes" && b.slug !== "notes") { - return 1; - } - if (b.slug === "notes" && a.slug !== "notes") { - return -1; - } - return 0; - }); + return [...transformBookingFieldsInternalToApi(knownBookingFields), ...unknownBookingFields]; } getDefaultBookingFields(isOrgTeamEvent: boolean) { diff --git a/packages/lib/event-types/transformers/internal-to-api/booking-fields.ts b/packages/lib/event-types/transformers/internal-to-api/booking-fields.ts index fb85b3ba3f1035..1ff725ff7a11ae 100644 --- a/packages/lib/event-types/transformers/internal-to-api/booking-fields.ts +++ b/packages/lib/event-types/transformers/internal-to-api/booking-fields.ts @@ -5,32 +5,14 @@ import type { DefaultFieldOutput_2024_06_14, CustomFieldOutput_2024_06_14, } from "@calcom/platform-types"; -import type { OutputUnknownBookingField_2024_06_14 } from "@calcom/platform-types/event-types/event-types_2024_06_14/outputs/booking-fields.output"; export function transformBookingFieldsInternalToApi( databaseBookingFields: (SystemField | CustomField)[] ): OutputBookingField_2024_06_14[] { - const defaultFields: SystemField[] = databaseBookingFields.filter( - (field): field is SystemField => field.editable === "system" || field.editable === "system-but-optional" - ); - - const customFields: CustomField[] = databaseBookingFields.filter( - (field): field is CustomField => field.editable === "user" - ); - - const responseDefaultFields: (DefaultFieldOutput_2024_06_14 | OutputUnknownBookingField_2024_06_14)[] = - defaultFields.map((field) => { + return databaseBookingFields.map((field) => { + if (field.editable === "system" || field.editable === "system-but-optional") { switch (field.name) { case "name": - return { - isDefault: true, - type: field.type, - slug: field.name, - required: !!field.required, - label: field.label, - placeholder: field.placeholder, - disableOnPrefill: !!field.disableOnPrefill, - }; case "email": return { isDefault: true, @@ -40,70 +22,23 @@ export function transformBookingFieldsInternalToApi( label: field.label, placeholder: field.placeholder, disableOnPrefill: !!field.disableOnPrefill, - }; + } as DefaultFieldOutput_2024_06_14; case "location": - return { - isDefault: true, - type: field.type, - slug: field.name, - required: !!field.required, - hidden: !!field.hidden, - label: field.label, - placeholder: field.placeholder, - disableOnPrefill: !!field.disableOnPrefill, - }; case "rescheduleReason": - return { - isDefault: true, - type: field.type, - slug: field.name, - required: !!field.required, - hidden: !!field.hidden, - label: field.label, - placeholder: field.placeholder, - disableOnPrefill: !!field.disableOnPrefill, - }; case "title": - return { - isDefault: true, - type: field.type, - slug: field.name, - required: !!field.required, - hidden: !!field.hidden, - label: field.label, - placeholder: field.placeholder, - disableOnPrefill: !!field.disableOnPrefill, - }; case "notes": - return { - isDefault: true, - type: field.type, - slug: field.name, - required: !!field.required, - hidden: !!field.hidden, - label: field.label, - placeholder: field.placeholder, - disableOnPrefill: !!field.disableOnPrefill, - }; case "guests": + case "attendeePhoneNumber": return { isDefault: true, type: field.type, slug: field.name, required: !!field.required, - hidden: !!field.hidden, label: field.label, placeholder: field.placeholder, disableOnPrefill: !!field.disableOnPrefill, - }; - case "attendeePhoneNumber": - return { - isDefault: true, - type: field.type, - slug: field.name, - required: !!field.required, hidden: !!field.hidden, - }; + } as DefaultFieldOutput_2024_06_14; default: return { type: "unknown", @@ -111,66 +46,13 @@ export function transformBookingFieldsInternalToApi( bookingField: JSON.stringify(field), }; } - }); - - const responseCustomFields: (CustomFieldOutput_2024_06_14 | OutputUnknownBookingField_2024_06_14)[] = - customFields.map((field) => { + } else { switch (field.type) { case "phone": - return { - isDefault: false, - type: field.type, - slug: field.name, - label: field.label, - required: !!field.required, - placeholder: field.placeholder, - disableOnPrefill: !!field.disableOnPrefill, - hidden: !!field.hidden, - }; case "address": - return { - isDefault: false, - type: field.type, - slug: field.name, - label: field.label, - required: !!field.required, - placeholder: field.placeholder, - disableOnPrefill: !!field.disableOnPrefill, - hidden: !!field.hidden, - }; case "text": - return { - isDefault: false, - type: field.type, - slug: field.name, - label: field.label, - required: !!field.required, - placeholder: field.placeholder, - disableOnPrefill: !!field.disableOnPrefill, - hidden: !!field.hidden, - }; case "number": - return { - isDefault: false, - type: field.type, - slug: field.name, - label: field.label, - required: !!field.required, - placeholder: field.placeholder, - disableOnPrefill: !!field.disableOnPrefill, - hidden: !!field.hidden, - }; case "textarea": - return { - isDefault: false, - type: field.type, - slug: field.name, - label: field.label, - required: !!field.required, - placeholder: field.placeholder, - disableOnPrefill: !!field.disableOnPrefill, - hidden: !!field.hidden, - }; case "multiemail": return { isDefault: false, @@ -181,7 +63,7 @@ export function transformBookingFieldsInternalToApi( placeholder: field.placeholder, disableOnPrefill: !!field.disableOnPrefill, hidden: !!field.hidden, - }; + } as CustomFieldOutput_2024_06_14; case "boolean": return { isDefault: false, @@ -191,41 +73,10 @@ export function transformBookingFieldsInternalToApi( required: !!field.required, disableOnPrefill: !!field.disableOnPrefill, hidden: !!field.hidden, - }; + } as CustomFieldOutput_2024_06_14; case "select": - return { - isDefault: false, - type: field.type, - slug: field.name, - label: field.label, - required: !!field.required, - placeholder: field.placeholder, - options: field.options ? field.options.map((option) => option.value) : [], - disableOnPrefill: !!field.disableOnPrefill, - hidden: !!field.hidden, - }; case "multiselect": - return { - isDefault: false, - type: field.type, - slug: field.name, - label: field.label, - required: !!field.required, - options: field.options ? field.options?.map((option) => option.value) : [], - disableOnPrefill: !!field.disableOnPrefill, - hidden: !!field.hidden, - }; case "checkbox": - return { - isDefault: false, - type: field.type, - slug: field.name, - label: field.label, - required: !!field.required, - options: field.options ? field.options?.map((option) => option.value) : [], - disableOnPrefill: !!field.disableOnPrefill, - hidden: !!field.hidden, - }; case "radio": return { isDefault: false, @@ -233,10 +84,11 @@ export function transformBookingFieldsInternalToApi( slug: field.name, label: field.label, required: !!field.required, - options: field.options ? field.options?.map((option) => option.value) : [], + options: field.options ? field.options.map((option) => option.value) : [], + ...(field.type === "select" ? { placeholder: field.placeholder } : {}), disableOnPrefill: !!field.disableOnPrefill, hidden: !!field.hidden, - }; + } as CustomFieldOutput_2024_06_14; default: return { type: "unknown", @@ -244,9 +96,8 @@ export function transformBookingFieldsInternalToApi( bookingField: JSON.stringify(field), }; } - }); - - return [...responseDefaultFields, ...responseCustomFields]; + } + }); } const CustomFieldTypeEnum = z.enum([ diff --git a/packages/platform/types/event-types/event-types_2024_06_14/outputs/booking-fields.output.ts b/packages/platform/types/event-types/event-types_2024_06_14/outputs/booking-fields.output.ts index fbdc01873cb1bb..2994b03821301a 100644 --- a/packages/platform/types/event-types/event-types_2024_06_14/outputs/booking-fields.output.ts +++ b/packages/platform/types/event-types/event-types_2024_06_14/outputs/booking-fields.output.ts @@ -348,6 +348,13 @@ export class PhoneDefaultFieldOutput_2024_06_14 { @IsBoolean() @DocsProperty() required!: boolean; + + @IsBoolean() + @DocsProperty({ + description: + "If true show under event type settings but don't show this booking field in the Booker. If false show in both.", + }) + hidden!: boolean; } export class PhoneFieldOutput_2024_06_14 extends PhoneFieldInput_2024_06_14 { From eb58dc8f8af61e2c001d635f2bb07404a7234b96 Mon Sep 17 00:00:00 2001 From: supalarry Date: Wed, 15 Jan 2025 09:58:53 +0100 Subject: [PATCH 04/13] feat: local libraries setup script --- packages/platform/libraries/package.json | 1 + packages/platform/libraries/scripts/local.js | 25 ++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 packages/platform/libraries/scripts/local.js diff --git a/packages/platform/libraries/package.json b/packages/platform/libraries/package.json index 2df5d3d0370e2a..2e071397df6259 100644 --- a/packages/platform/libraries/package.json +++ b/packages/platform/libraries/package.json @@ -12,6 +12,7 @@ "build": "yarn vite build", "build:watch": "yarn vite build --watch", "build:dev": "yarn vite build && sed -i'' -e 's/const CACHE = new lruCache\\.LRUCache({ max: 1e3 });/const CACHE = new lruCache({ max: 1e3 });/g' ./dist/index.cjs", + "local": "node scripts/local.js && rm -rf dist && yarn build:dev && cd ../../.. && yarn", "publish": "rm -rf dist && yarn build && npm publish --access public" }, "dependencies": { diff --git a/packages/platform/libraries/scripts/local.js b/packages/platform/libraries/scripts/local.js new file mode 100644 index 00000000000000..76694926242d49 --- /dev/null +++ b/packages/platform/libraries/scripts/local.js @@ -0,0 +1,25 @@ +import fs from "fs"; +import path from "path"; +import { fileURLToPath } from "url"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +const VERSION = "9.9.9"; + +// note(Lauris): update libraries package.json version +const librariesPath = path.join(__dirname, ".."); +const librariesPackageJsonPath = path.join(librariesPath, "package.json"); +const librariesPackageJson = JSON.parse(fs.readFileSync(librariesPackageJsonPath, "utf8")); + +librariesPackageJson.version = VERSION; + +fs.writeFileSync(librariesPackageJsonPath, `${JSON.stringify(librariesPackageJson, null, 2)}\n`); + +// note(Lauris): update API v2 package.json dependency +const apiV2PackageJsonPath = path.join(librariesPath, "..", "..", "..", "apps", "api", "v2", "package.json"); +const apiV2PackageJson = JSON.parse(fs.readFileSync(apiV2PackageJsonPath, "utf8")); + +apiV2PackageJson.dependencies["@calcom/platform-libraries"] = `npm:@calcom/platform-libraries@${VERSION}`; + +fs.writeFileSync(apiV2PackageJsonPath, `${JSON.stringify(apiV2PackageJson, null, 2)}\n`); From 48fdbe9652ee59d15ce7e52c30ff1c101e822460 Mon Sep 17 00:00:00 2001 From: supalarry Date: Wed, 15 Jan 2025 10:55:48 +0100 Subject: [PATCH 05/13] chore: add log when parsing booking field fails --- .../services/output-event-types.service.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts b/apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts index 2c85608a79f664..45345326c381de 100644 --- a/apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts +++ b/apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts @@ -235,6 +235,8 @@ export class OutputEventTypesService_2024_06_14 { if (result.success) { knownBookingFields.push(result.data); } else { + console.log("transformBookingFields - failed to parse a field", bookingField); + console.log("transformBookingFields - parsing error", result.error); unknownBookingFields.push({ type: "unknown", slug: "unknown", From 6567836055e41ec06604223305d4a78b7f9db65b Mon Sep 17 00:00:00 2001 From: supalarry Date: Wed, 15 Jan 2025 10:56:19 +0100 Subject: [PATCH 06/13] fix: backwards compatbile name booking field --- .../internal-to-api/booking-fields.ts | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/lib/event-types/transformers/internal-to-api/booking-fields.ts b/packages/lib/event-types/transformers/internal-to-api/booking-fields.ts index e1e26b27b88cff..2dd07e065883b8 100644 --- a/packages/lib/event-types/transformers/internal-to-api/booking-fields.ts +++ b/packages/lib/event-types/transformers/internal-to-api/booking-fields.ts @@ -242,17 +242,19 @@ const NameSystemFieldSchema = SystemFieldSchema.extend({ }) ), }), - firstAndLastName: z.object({ - fields: z.array( - z.object({ - name: z.enum(["firstName", "lastName"]), - type: z.literal("text"), - label: z.string().optional(), - required: z.boolean(), - placeholder: z.string().optional(), - }) - ), - }), + firstAndLastName: z + .object({ + fields: z.array( + z.object({ + name: z.enum(["firstName", "lastName"]), + type: z.literal("text"), + label: z.string().optional(), + required: z.boolean(), + placeholder: z.string().optional(), + }) + ), + }) + .optional(), }), }) .optional(), From 4cb05dbe014b654df4fcfdee8f00adab53a490f5 Mon Sep 17 00:00:00 2001 From: supalarry Date: Wed, 15 Jan 2025 12:00:52 +0100 Subject: [PATCH 07/13] chore: libraries publish support scripts --- .../platform/libraries/scripts/postpublish.js | 58 +++++++++++++++++ .../platform/libraries/scripts/prepublish.js | 65 +++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 packages/platform/libraries/scripts/postpublish.js create mode 100644 packages/platform/libraries/scripts/prepublish.js diff --git a/packages/platform/libraries/scripts/postpublish.js b/packages/platform/libraries/scripts/postpublish.js new file mode 100644 index 00000000000000..6e6ee3467b59d1 --- /dev/null +++ b/packages/platform/libraries/scripts/postpublish.js @@ -0,0 +1,58 @@ +import { spawn } from "child_process"; +import fs from "fs"; +import path from "path"; +import { fileURLToPath } from "url"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +async function main() { + try { + // Get the published version before resetting + const librariesPath = path.join(__dirname, ".."); + const librariesPackageJsonPath = path.join(librariesPath, "package.json"); + const librariesPackageJson = JSON.parse(fs.readFileSync(librariesPackageJsonPath, "utf8")); + const publishedVersion = librariesPackageJson.version; + + // Reset libraries package.json version to 0.0.0 + librariesPackageJson.version = "0.0.0"; + fs.writeFileSync(librariesPackageJsonPath, `${JSON.stringify(librariesPackageJson, null, 2)}\n`); + + // Update API v2 package.json dependency + const apiV2PackageJsonPath = path.join( + librariesPath, + "..", + "..", + "..", + "apps", + "api", + "v2", + "package.json" + ); + const apiV2PackageJson = JSON.parse(fs.readFileSync(apiV2PackageJsonPath, "utf8")); + + apiV2PackageJson.dependencies[ + "@calcom/platform-libraries" + ] = `npm:@calcom/platform-libraries@${publishedVersion}`; + fs.writeFileSync(apiV2PackageJsonPath, `${JSON.stringify(apiV2PackageJson, null, 2)}\n`); + + // Run yarn install + const yarnInstall = spawn("yarn", ["install"], { + stdio: "inherit", + cwd: path.join(librariesPath, "..", "..", ".."), + }); + + yarnInstall.on("close", (code) => { + if (code !== 0) { + console.error("yarn install failed"); + process.exit(1); + } + console.log("Successfully reset version and updated dependencies"); + }); + } catch (error) { + console.error("Error:", error); + process.exit(1); + } +} + +main(); diff --git a/packages/platform/libraries/scripts/prepublish.js b/packages/platform/libraries/scripts/prepublish.js new file mode 100644 index 00000000000000..979889b1fa93fc --- /dev/null +++ b/packages/platform/libraries/scripts/prepublish.js @@ -0,0 +1,65 @@ +import fs from "fs"; +import https from "https"; +import path from "path"; +import { fileURLToPath } from "url"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +// Fetch current version from npm registry +function getCurrentVersion() { + return new Promise((resolve, reject) => { + https + .get( + "https://registry.npmjs.org/@calcom/platform-libraries", + { + headers: { Accept: "application/json" }, + }, + (res) => { + let data = ""; + res.on("data", (chunk) => (data += chunk)); + res.on("end", () => { + try { + const packageInfo = JSON.parse(data); + const currentVersion = packageInfo["dist-tags"].latest; + resolve(currentVersion); + } catch (error) { + reject(error); + } + }); + } + ) + .on("error", reject); + }); +} + +// Increment patch version (a.b.c -> a.b.c+1) +function incrementPatchVersion(version) { + const parts = version.split("."); + parts[2] = String(Number(parts[2]) + 1); + return parts.join("."); +} + +async function main() { + try { + // Get and increment version + const currentVersion = await getCurrentVersion(); + const newVersion = incrementPatchVersion(currentVersion); + console.log(`Current version in npm: ${currentVersion}. Incremented locally to ${newVersion}`); + + // Update libraries package.json version + const librariesPath = path.join(__dirname, ".."); + const librariesPackageJsonPath = path.join(librariesPath, "package.json"); + const librariesPackageJson = JSON.parse(fs.readFileSync(librariesPackageJsonPath, "utf8")); + + librariesPackageJson.version = newVersion; + fs.writeFileSync(librariesPackageJsonPath, `${JSON.stringify(librariesPackageJson, null, 2)}\n`); + + console.log("Successfully incremented @calcom/platform-libraries package.json version."); + } catch (error) { + console.error("Error:", error); + process.exit(1); + } +} + +main(); From 27c81fa00ea6947cfac6ee72e5198d793f4ba760 Mon Sep 17 00:00:00 2001 From: supalarry Date: Wed, 15 Jan 2025 12:03:47 +0100 Subject: [PATCH 08/13] chore: bump libraries --- apps/api/v2/package.json | 2 +- packages/platform/libraries/package.json | 4 +++- yarn.lock | 10 +++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/api/v2/package.json b/apps/api/v2/package.json index cd9f4223e1d7e6..475dda9081ea49 100644 --- a/apps/api/v2/package.json +++ b/apps/api/v2/package.json @@ -29,7 +29,7 @@ "@axiomhq/winston": "^1.2.0", "@calcom/platform-constants": "*", "@calcom/platform-enums": "*", - "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.82", + "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.83", "@calcom/platform-libraries-0.0.2": "npm:@calcom/platform-libraries@0.0.2", "@calcom/platform-types": "*", "@calcom/platform-utils": "*", diff --git a/packages/platform/libraries/package.json b/packages/platform/libraries/package.json index 2e071397df6259..b89c30802411bc 100644 --- a/packages/platform/libraries/package.json +++ b/packages/platform/libraries/package.json @@ -13,7 +13,9 @@ "build:watch": "yarn vite build --watch", "build:dev": "yarn vite build && sed -i'' -e 's/const CACHE = new lruCache\\.LRUCache({ max: 1e3 });/const CACHE = new lruCache({ max: 1e3 });/g' ./dist/index.cjs", "local": "node scripts/local.js && rm -rf dist && yarn build:dev && cd ../../.. && yarn", - "publish": "rm -rf dist && yarn build && npm publish --access public" + "prepublish": "yarn && node scripts/prepublish.js", + "publish": "rm -rf dist && yarn build && npm publish --access public", + "postpublish": "node scripts/postpublish.js" }, "dependencies": { "@calcom/core": "*", diff --git a/yarn.lock b/yarn.lock index 7397900b16f02e..b97c8734ac21d4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4141,7 +4141,7 @@ __metadata: "@axiomhq/winston": ^1.2.0 "@calcom/platform-constants": "*" "@calcom/platform-enums": "*" - "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.82" + "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.83" "@calcom/platform-libraries-0.0.2": "npm:@calcom/platform-libraries@0.0.2" "@calcom/platform-types": "*" "@calcom/platform-utils": "*" @@ -5194,14 +5194,14 @@ __metadata: languageName: node linkType: hard -"@calcom/platform-libraries@npm:@calcom/platform-libraries@0.0.82": - version: 0.0.82 - resolution: "@calcom/platform-libraries@npm:0.0.82" +"@calcom/platform-libraries@npm:@calcom/platform-libraries@0.0.83": + version: 0.0.83 + resolution: "@calcom/platform-libraries@npm:0.0.83" dependencies: "@calcom/core": "*" "@calcom/features": "*" "@calcom/lib": "*" - checksum: 46c8d73dcd0a21faa40cbf0605686dcff70d0f8b9e42410ce2e4252fba73d8c618a3b8f9729f503fc7200a2d36ac9b38d6b9570598c8efdafcfbac04722fa405 + checksum: ff740aa56c52a304726a1a249ae7436b5f04f2e01eb4cbdb7701f48c062e965345f9b3b014ff0dfdb1dbcbc7a68b76a1223c133c3f85a4609a228f8514c94d07 languageName: node linkType: hard From 3082a19e0c3bc851613c9b7f745faf212b95405c Mon Sep 17 00:00:00 2001 From: supalarry Date: Wed, 15 Jan 2025 12:12:15 +0100 Subject: [PATCH 09/13] docs --- packages/platform/libraries/README.md | 35 ++++++--------------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/packages/platform/libraries/README.md b/packages/platform/libraries/README.md index 759756c7d820aa..c9d1845f0b5676 100644 --- a/packages/platform/libraries/README.md +++ b/packages/platform/libraries/README.md @@ -1,34 +1,15 @@ # How to work with platform libraries in Dev -whenever you want to change anything in platform libraries, or if you modify the code of one of the functions imported in libraries you will need to build the code again. - -first thing to know is that we version this package using NPM - +We version this package using NPM: https://www.npmjs.com/package/@calcom/platform-libraries?activeTab=code -In order to work using the locally built platform libraries you need to: - -- in packages/platform/libraries/package.json set the version to for example 1.2.3 - -- in apps/api/v2/package.json add to dependencies: - "@calcom/platform-libraries-1.2.3": "npm:@calcom/platform-libraries@1.2.3" - -- in api v2 code simply import using the new alias: - import { - getAllUserBookings as getAllUserBookings1.2.3, - } from "@calcom/platform-libraries-1.2.3"; - -since the versions are matching in both package.json yarn will try to use the locally built code - -now go to packages/platform/libraries and do - -- yarn build:dev - -then go back to /apps/api/v2 and run - -- yarn - -- yarn dev +Here is the workflow: +1. If you change platform libraries for the first time, then run `yarn local` to build them locally for the first time. This will also make v2 api point to the local libraries. +2. If you change them for the second time, then run `yarn build:dev` to re-build them. +3. Once you are happy with platform libraries: +- run `yarn prebulish` - it will check "@calcom/platform-libraries" version in npm and update it's package.json to the next version. +- run `yarn publish` - it will publish the package to npm +- run `yarn postpublish` - it will update the version of "@calcom/platform-libraries" in the api v2 package.json, reset "@calcom/platform-libraries" to 0.0.0 and run yarn install. # Before Merging to main From ed0e95047c8383aa50f610c0a91942ac99802bf2 Mon Sep 17 00:00:00 2001 From: supalarry Date: Wed, 15 Jan 2025 12:30:32 +0100 Subject: [PATCH 10/13] fix: phone default field return label and placeholder --- apps/api/v2/package.json | 2 +- .../api-to-internal/booking-fields.ts | 3 +++ .../internal-to-api/internal-to-api.spec.ts | 3 +++ packages/platform/libraries/README.md | 5 +++-- packages/platform/libraries/package.json | 3 +-- .../outputs/booking-fields.output.ts | 20 +++++++++++++++++++ yarn.lock | 10 +++++----- 7 files changed, 36 insertions(+), 10 deletions(-) diff --git a/apps/api/v2/package.json b/apps/api/v2/package.json index 475dda9081ea49..09baad2604373c 100644 --- a/apps/api/v2/package.json +++ b/apps/api/v2/package.json @@ -29,7 +29,7 @@ "@axiomhq/winston": "^1.2.0", "@calcom/platform-constants": "*", "@calcom/platform-enums": "*", - "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.83", + "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.84", "@calcom/platform-libraries-0.0.2": "npm:@calcom/platform-libraries@0.0.2", "@calcom/platform-types": "*", "@calcom/platform-utils": "*", diff --git a/packages/lib/event-types/transformers/api-to-internal/booking-fields.ts b/packages/lib/event-types/transformers/api-to-internal/booking-fields.ts index 79c6e2352d935e..dac35bdcb909c4 100644 --- a/packages/lib/event-types/transformers/api-to-internal/booking-fields.ts +++ b/packages/lib/event-types/transformers/api-to-internal/booking-fields.ts @@ -87,6 +87,9 @@ function getBaseProperties(field: InputBookingField): CustomField | SystemField ...systemBeforeFieldPhone, required: field.required, hidden: field.hidden, + label: field.label, + placeholder: field.placeholder, + disableOnPrefill: !!field.disableOnPrefill, }; } diff --git a/packages/lib/event-types/transformers/internal-to-api/internal-to-api.spec.ts b/packages/lib/event-types/transformers/internal-to-api/internal-to-api.spec.ts index 0f56a1760bf022..853f617d823e85 100644 --- a/packages/lib/event-types/transformers/internal-to-api/internal-to-api.spec.ts +++ b/packages/lib/event-types/transformers/internal-to-api/internal-to-api.spec.ts @@ -835,6 +835,9 @@ describe("transformBookingFieldsInternalToApi", () => { slug: "attendeePhoneNumber", required: false, hidden: true, + disableOnPrefill: false, + label: undefined, + placeholder: undefined, }, ]; diff --git a/packages/platform/libraries/README.md b/packages/platform/libraries/README.md index c9d1845f0b5676..ce8e2a3959d92b 100644 --- a/packages/platform/libraries/README.md +++ b/packages/platform/libraries/README.md @@ -7,10 +7,11 @@ Here is the workflow: 1. If you change platform libraries for the first time, then run `yarn local` to build them locally for the first time. This will also make v2 api point to the local libraries. 2. If you change them for the second time, then run `yarn build:dev` to re-build them. 3. Once you are happy with platform libraries: -- run `yarn prebulish` - it will check "@calcom/platform-libraries" version in npm and update it's package.json to the next version. -- run `yarn publish` - it will publish the package to npm +- run `yarn publish` - it will check "@calcom/platform-libraries" version in npm and update it's package.json to the next version and then it will publish the package to np. - run `yarn postpublish` - it will update the version of "@calcom/platform-libraries" in the api v2 package.json, reset "@calcom/platform-libraries" to 0.0.0 and run yarn install. +note(Lauris) - we could have 1 publish script but the problem is that `yarn publish` does not exit for some reason. + # Before Merging to main - Publish Your Version of Libraries on NPM: diff --git a/packages/platform/libraries/package.json b/packages/platform/libraries/package.json index b89c30802411bc..2f5ce50a9da8cc 100644 --- a/packages/platform/libraries/package.json +++ b/packages/platform/libraries/package.json @@ -13,8 +13,7 @@ "build:watch": "yarn vite build --watch", "build:dev": "yarn vite build && sed -i'' -e 's/const CACHE = new lruCache\\.LRUCache({ max: 1e3 });/const CACHE = new lruCache({ max: 1e3 });/g' ./dist/index.cjs", "local": "node scripts/local.js && rm -rf dist && yarn build:dev && cd ../../.. && yarn", - "prepublish": "yarn && node scripts/prepublish.js", - "publish": "rm -rf dist && yarn build && npm publish --access public", + "publish": "yarn && node scripts/prepublish.js && rm -rf dist && yarn build && npm publish --access public", "postpublish": "node scripts/postpublish.js" }, "dependencies": { diff --git a/packages/platform/types/event-types/event-types_2024_06_14/outputs/booking-fields.output.ts b/packages/platform/types/event-types/event-types_2024_06_14/outputs/booking-fields.output.ts index 793e6e303ca504..7106155c457b72 100644 --- a/packages/platform/types/event-types/event-types_2024_06_14/outputs/booking-fields.output.ts +++ b/packages/platform/types/event-types/event-types_2024_06_14/outputs/booking-fields.output.ts @@ -378,6 +378,26 @@ export class PhoneDefaultFieldOutput_2024_06_14 { "If true show under event type settings but don't show this booking field in the Booker. If false show in both.", }) hidden!: boolean; + + @IsString() + @IsOptional() + @DocsProperty() + label?: string; + + @IsString() + @IsOptional() + @DocsProperty() + placeholder?: string; + + @IsBoolean() + @ApiProperty({ + type: Boolean, + description: + "Disable this booking field if the URL contains query parameter with key equal to the slug and prefill it with the provided value.\ + For example, if URL contains query parameter `&attendeePhoneNumber=+37122222222`,\ + the guests field will be prefilled with this value and disabled.", + }) + disableOnPrefill!: boolean; } export class PhoneFieldOutput_2024_06_14 extends PhoneFieldInput_2024_06_14 { diff --git a/yarn.lock b/yarn.lock index b97c8734ac21d4..ba82b2ade482f8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4141,7 +4141,7 @@ __metadata: "@axiomhq/winston": ^1.2.0 "@calcom/platform-constants": "*" "@calcom/platform-enums": "*" - "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.83" + "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.84" "@calcom/platform-libraries-0.0.2": "npm:@calcom/platform-libraries@0.0.2" "@calcom/platform-types": "*" "@calcom/platform-utils": "*" @@ -5194,14 +5194,14 @@ __metadata: languageName: node linkType: hard -"@calcom/platform-libraries@npm:@calcom/platform-libraries@0.0.83": - version: 0.0.83 - resolution: "@calcom/platform-libraries@npm:0.0.83" +"@calcom/platform-libraries@npm:@calcom/platform-libraries@0.0.84": + version: 0.0.84 + resolution: "@calcom/platform-libraries@npm:0.0.84" dependencies: "@calcom/core": "*" "@calcom/features": "*" "@calcom/lib": "*" - checksum: ff740aa56c52a304726a1a249ae7436b5f04f2e01eb4cbdb7701f48c062e965345f9b3b014ff0dfdb1dbcbc7a68b76a1223c133c3f85a4609a228f8514c94d07 + checksum: 4372a4b7942ce8e13f1bb36c6b4e9193917ea1bc5322a4ca6af4176de01c70f199ff1fe707077f470df9d054a055be069a80d764cebd4ead502ac684b55ea5c9 languageName: node linkType: hard From a16420aff505a1e74c50cb6dbba0eb5cd6bc7317 Mon Sep 17 00:00:00 2001 From: supalarry Date: Wed, 15 Jan 2025 15:37:02 +0100 Subject: [PATCH 11/13] fix: e2e tests --- .../event-types.controller.e2e-spec.ts | 31 +++++++++++------- .../organizations-event-types.e2e-spec.ts | 32 ++++++++++++------- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.e2e-spec.ts b/apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.e2e-spec.ts index 4ba15325601cc4..2d79b8a4ef9950 100644 --- a/apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.e2e-spec.ts +++ b/apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.e2e-spec.ts @@ -452,9 +452,6 @@ describe("Event types Endpoints", () => { { ...defaultResponseBookingFieldName, ...nameBookingField }, { ...defaultResponseBookingFieldEmail }, { ...defaultResponseBookingFieldLocation }, - { ...defaultResponseBookingFieldTitle }, - { ...defaultResponseBookingFieldGuests }, - { ...defaultResponseBookingFieldRescheduleReason }, { type: "select", label: "select which language you want to learn", @@ -466,7 +463,10 @@ describe("Event types Endpoints", () => { hidden: false, isDefault: false, }, + { ...defaultResponseBookingFieldTitle }, { ...defaultResponseBookingFieldNotes }, + { ...defaultResponseBookingFieldGuests }, + { ...defaultResponseBookingFieldRescheduleReason }, ]; expect(createdEventType.bookingFields).toEqual(expectedBookingFields); @@ -942,9 +942,6 @@ describe("Event types Endpoints", () => { { ...defaultResponseBookingFieldName, ...nameBookingField }, { ...defaultResponseBookingFieldEmail }, { ...defaultResponseBookingFieldLocation }, - { ...defaultResponseBookingFieldTitle }, - { ...defaultResponseBookingFieldGuests }, - { ...defaultResponseBookingFieldRescheduleReason }, { type: "select", label: "select which language you want to learn", @@ -956,7 +953,10 @@ describe("Event types Endpoints", () => { hidden: false, isDefault: false, }, + { ...defaultResponseBookingFieldTitle }, { ...defaultResponseBookingFieldNotes, ...notesBookingField }, + { ...defaultResponseBookingFieldGuests }, + { ...defaultResponseBookingFieldRescheduleReason }, ]; expect(updatedEventType.bookingFields).toEqual(expectedBookingFields); @@ -1185,7 +1185,14 @@ describe("Event types Endpoints", () => { disableOnPrefill: false, hidden: false, }, - { isDefault: true, type: "phone", slug: "attendeePhoneNumber", required: false, hidden: true }, + { + disableOnPrefill: false, + isDefault: true, + type: "phone", + slug: "attendeePhoneNumber", + required: false, + hidden: true, + }, { isDefault: true, required: false, @@ -1623,16 +1630,16 @@ describe("Event types Endpoints", () => { }, { isDefault: true, - type: "multiemail", - slug: "guests", + type: "textarea", + slug: "notes", required: false, disableOnPrefill: false, hidden: false, }, { isDefault: true, - type: "textarea", - slug: "rescheduleReason", + type: "multiemail", + slug: "guests", required: false, disableOnPrefill: false, hidden: false, @@ -1640,7 +1647,7 @@ describe("Event types Endpoints", () => { { isDefault: true, type: "textarea", - slug: "notes", + slug: "rescheduleReason", required: false, disableOnPrefill: false, hidden: false, diff --git a/apps/api/v2/src/modules/organizations/controllers/event-types/organizations-event-types.e2e-spec.ts b/apps/api/v2/src/modules/organizations/controllers/event-types/organizations-event-types.e2e-spec.ts index 51efc4dce1a94e..4f4a309461332f 100644 --- a/apps/api/v2/src/modules/organizations/controllers/event-types/organizations-event-types.e2e-spec.ts +++ b/apps/api/v2/src/modules/organizations/controllers/event-types/organizations-event-types.e2e-spec.ts @@ -590,6 +590,7 @@ describe("Organizations Event Types Endpoints", () => { slug: "attendeePhoneNumber", required: true, label: "Phone number", + hidden: true, }, ], }; @@ -632,6 +633,8 @@ describe("Organizations Event Types Endpoints", () => { slug: "attendeePhoneNumber", required: true, hidden: true, + label: "Phone number", + disableOnPrefill: false, }, { isDefault: true, @@ -643,16 +646,16 @@ describe("Organizations Event Types Endpoints", () => { }, { isDefault: true, - type: "multiemail", - slug: "guests", + type: "textarea", + slug: "notes", required: false, disableOnPrefill: false, hidden: false, }, { isDefault: true, - type: "textarea", - slug: "rescheduleReason", + type: "multiemail", + slug: "guests", required: false, disableOnPrefill: false, hidden: false, @@ -660,7 +663,7 @@ describe("Organizations Event Types Endpoints", () => { { isDefault: true, type: "textarea", - slug: "notes", + slug: "rescheduleReason", required: false, disableOnPrefill: false, hidden: false, @@ -771,7 +774,14 @@ describe("Organizations Event Types Endpoints", () => { expect(fetchedEventType.bookingFields).toEqual([ { isDefault: true, required: true, slug: "name", type: "name", disableOnPrefill: false }, { isDefault: true, required: true, slug: "email", type: "email", disableOnPrefill: false }, - { isDefault: true, type: "phone", slug: "attendeePhoneNumber", required: false, hidden: true }, + { + disableOnPrefill: false, + isDefault: true, + type: "phone", + slug: "attendeePhoneNumber", + required: false, + hidden: true, + }, { isDefault: true, type: "radioInput", @@ -791,23 +801,23 @@ describe("Organizations Event Types Endpoints", () => { { isDefault: true, required: false, - slug: "guests", - type: "multiemail", + slug: "notes", + type: "textarea", disableOnPrefill: false, hidden: false, }, { isDefault: true, required: false, - slug: "rescheduleReason", - type: "textarea", + slug: "guests", + type: "multiemail", disableOnPrefill: false, hidden: false, }, { isDefault: true, required: false, - slug: "notes", + slug: "rescheduleReason", type: "textarea", disableOnPrefill: false, hidden: false, From ebe6fb53df59bdd461eade89dad525eef0eba70a Mon Sep 17 00:00:00 2001 From: supalarry Date: Thu, 16 Jan 2025 07:53:46 +0100 Subject: [PATCH 12/13] refactor: remove console logs --- .../services/output-event-types.service.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts b/apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts index 45345326c381de..2c85608a79f664 100644 --- a/apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts +++ b/apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts @@ -235,8 +235,6 @@ export class OutputEventTypesService_2024_06_14 { if (result.success) { knownBookingFields.push(result.data); } else { - console.log("transformBookingFields - failed to parse a field", bookingField); - console.log("transformBookingFields - parsing error", result.error); unknownBookingFields.push({ type: "unknown", slug: "unknown", From 6efc490f92769c9811d9b683790f140fa6defab2 Mon Sep 17 00:00:00 2001 From: supalarry Date: Thu, 16 Jan 2025 09:25:42 +0100 Subject: [PATCH 13/13] refactor: internal-to-api/booking-fields.ts --- apps/api/v2/package.json | 2 +- .../event-types.controller.e2e-spec.ts | 5 - .../organizations-event-types.e2e-spec.ts | 2 - .../internal-to-api/booking-fields.ts | 172 ++++++++++++++++-- yarn.lock | 10 +- 5 files changed, 165 insertions(+), 26 deletions(-) diff --git a/apps/api/v2/package.json b/apps/api/v2/package.json index 09baad2604373c..5c7c639c4d876f 100644 --- a/apps/api/v2/package.json +++ b/apps/api/v2/package.json @@ -29,7 +29,7 @@ "@axiomhq/winston": "^1.2.0", "@calcom/platform-constants": "*", "@calcom/platform-enums": "*", - "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.84", + "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.85", "@calcom/platform-libraries-0.0.2": "npm:@calcom/platform-libraries@0.0.2", "@calcom/platform-types": "*", "@calcom/platform-utils": "*", diff --git a/apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.e2e-spec.ts b/apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.e2e-spec.ts index 2d79b8a4ef9950..55688922fadc57 100644 --- a/apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.e2e-spec.ts +++ b/apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.e2e-spec.ts @@ -123,7 +123,6 @@ describe("Event types Endpoints", () => { slug: "location", required: false, hidden: false, - disableOnPrefill: false, }; const defaultResponseBookingFieldTitle = { @@ -1163,10 +1162,7 @@ describe("Event types Endpoints", () => { type: "radioInput", slug: "location", required: false, - disableOnPrefill: false, hidden: false, - label: "", - placeholder: "", }, { isDefault: true, required: true, slug: "title", type: "text", disableOnPrefill: false, hidden: true }, { @@ -1617,7 +1613,6 @@ describe("Event types Endpoints", () => { type: "radioInput", slug: "location", required: false, - disableOnPrefill: false, hidden: false, }, { diff --git a/apps/api/v2/src/modules/organizations/controllers/event-types/organizations-event-types.e2e-spec.ts b/apps/api/v2/src/modules/organizations/controllers/event-types/organizations-event-types.e2e-spec.ts index 4f4a309461332f..7f3021bc9f7ed2 100644 --- a/apps/api/v2/src/modules/organizations/controllers/event-types/organizations-event-types.e2e-spec.ts +++ b/apps/api/v2/src/modules/organizations/controllers/event-types/organizations-event-types.e2e-spec.ts @@ -624,7 +624,6 @@ describe("Organizations Event Types Endpoints", () => { type: "radioInput", slug: "location", required: false, - disableOnPrefill: false, hidden: false, }, { @@ -787,7 +786,6 @@ describe("Organizations Event Types Endpoints", () => { type: "radioInput", slug: "location", required: false, - disableOnPrefill: false, hidden: false, }, { diff --git a/packages/lib/event-types/transformers/internal-to-api/booking-fields.ts b/packages/lib/event-types/transformers/internal-to-api/booking-fields.ts index 2dd07e065883b8..1d915c0a932887 100644 --- a/packages/lib/event-types/transformers/internal-to-api/booking-fields.ts +++ b/packages/lib/event-types/transformers/internal-to-api/booking-fields.ts @@ -2,8 +2,27 @@ import { z } from "zod"; import type { OutputBookingField_2024_06_14, - DefaultFieldOutput_2024_06_14, - CustomFieldOutput_2024_06_14, + SplitNameDefaultFieldOutput_2024_06_14, + NameDefaultFieldOutput_2024_06_14, + EmailDefaultFieldOutput_2024_06_14, + PhoneDefaultFieldOutput_2024_06_14, + LocationDefaultFieldOutput_2024_06_14, + RescheduleReasonDefaultFieldOutput_2024_06_14, + TitleDefaultFieldOutput_2024_06_14, + NotesDefaultFieldOutput_2024_06_14, + GuestsDefaultFieldOutput_2024_06_14, + OutputUnknownBookingField_2024_06_14, + AddressFieldOutput_2024_06_14, + BooleanFieldOutput_2024_06_14, + CheckboxGroupFieldOutput_2024_06_14, + MultiEmailFieldOutput_2024_06_14, + MultiSelectFieldOutput_2024_06_14, + NumberFieldOutput_2024_06_14, + PhoneFieldOutput_2024_06_14, + RadioGroupFieldOutput_2024_06_14, + SelectFieldOutput_2024_06_14, + TextAreaFieldOutput_2024_06_14, + TextFieldOutput_2024_06_14, } from "@calcom/platform-types"; export function transformBookingFieldsInternalToApi( @@ -31,7 +50,7 @@ export function transformBookingFieldsInternalToApi( lastNamePlaceholder: lastNameField?.placeholder, lastNameRequired: !!lastNameField?.required, disableOnPrefill: !!field.disableOnPrefill, - }; + } satisfies SplitNameDefaultFieldOutput_2024_06_14; } return { @@ -42,7 +61,7 @@ export function transformBookingFieldsInternalToApi( label: field.variantsConfig?.variants?.fullName?.fields[0]?.label, placeholder: field.variantsConfig?.variants?.fullName?.fields[0]?.placeholder, disableOnPrefill: !!field.disableOnPrefill, - }; + } satisfies NameDefaultFieldOutput_2024_06_14; } case "email": return { @@ -53,12 +72,59 @@ export function transformBookingFieldsInternalToApi( label: field.label, placeholder: field.placeholder, disableOnPrefill: !!field.disableOnPrefill, - } as DefaultFieldOutput_2024_06_14; + } satisfies EmailDefaultFieldOutput_2024_06_14; case "location": + return { + isDefault: true, + type: "radioInput", + slug: "location", + required: !!field.required, + hidden: !!field.hidden, + } satisfies LocationDefaultFieldOutput_2024_06_14; case "rescheduleReason": + return { + isDefault: true, + type: "textarea", + slug: "rescheduleReason", + required: !!field.required, + label: field.label, + placeholder: field.placeholder, + disableOnPrefill: !!field.disableOnPrefill, + hidden: !!field.hidden, + } satisfies RescheduleReasonDefaultFieldOutput_2024_06_14; case "title": + return { + isDefault: true, + type: "text", + slug: "title", + required: !!field.required, + label: field.label, + placeholder: field.placeholder, + disableOnPrefill: !!field.disableOnPrefill, + hidden: !!field.hidden, + } satisfies TitleDefaultFieldOutput_2024_06_14; case "notes": + return { + isDefault: true, + type: "textarea", + slug: "notes", + required: !!field.required, + label: field.label, + placeholder: field.placeholder, + disableOnPrefill: !!field.disableOnPrefill, + hidden: !!field.hidden, + } satisfies NotesDefaultFieldOutput_2024_06_14; case "guests": + return { + isDefault: true, + type: "multiemail", + slug: "guests", + required: !!field.required, + label: field.label, + placeholder: field.placeholder, + disableOnPrefill: !!field.disableOnPrefill, + hidden: !!field.hidden, + } satisfies GuestsDefaultFieldOutput_2024_06_14; case "attendeePhoneNumber": return { isDefault: true, @@ -69,32 +135,82 @@ export function transformBookingFieldsInternalToApi( placeholder: field.placeholder, disableOnPrefill: !!field.disableOnPrefill, hidden: !!field.hidden, - } as DefaultFieldOutput_2024_06_14; + } satisfies PhoneDefaultFieldOutput_2024_06_14; default: return { type: "unknown", slug: "unknown", bookingField: JSON.stringify(field), - }; + } satisfies OutputUnknownBookingField_2024_06_14; } } else { switch (field.type) { case "phone": + return { + isDefault: false, + type: field.type, + slug: field.name, + label: field.label || "", + required: !!field.required, + placeholder: field.placeholder, + disableOnPrefill: !!field.disableOnPrefill, + hidden: !!field.hidden, + } satisfies PhoneFieldOutput_2024_06_14; case "address": + return { + isDefault: false, + type: field.type, + slug: field.name, + label: field.label, + required: !!field.required, + placeholder: field.placeholder, + disableOnPrefill: !!field.disableOnPrefill, + hidden: !!field.hidden, + } satisfies AddressFieldOutput_2024_06_14; case "text": + return { + isDefault: false, + type: field.type, + slug: field.name, + label: field.label || "", + required: !!field.required, + placeholder: field.placeholder, + disableOnPrefill: !!field.disableOnPrefill, + hidden: !!field.hidden, + } satisfies TextFieldOutput_2024_06_14; case "number": + return { + isDefault: false, + type: field.type, + slug: field.name, + label: field.label, + required: !!field.required, + placeholder: field.placeholder, + disableOnPrefill: !!field.disableOnPrefill, + hidden: !!field.hidden, + } satisfies NumberFieldOutput_2024_06_14; case "textarea": + return { + isDefault: false, + type: field.type, + slug: field.name, + label: field.label || "", + required: !!field.required, + placeholder: field.placeholder, + disableOnPrefill: !!field.disableOnPrefill, + hidden: !!field.hidden, + } satisfies TextAreaFieldOutput_2024_06_14; case "multiemail": return { isDefault: false, type: field.type, slug: field.name, - label: field.label, + label: field.label || "", required: !!field.required, placeholder: field.placeholder, disableOnPrefill: !!field.disableOnPrefill, hidden: !!field.hidden, - } as CustomFieldOutput_2024_06_14; + } satisfies MultiEmailFieldOutput_2024_06_14; case "boolean": return { isDefault: false, @@ -104,10 +220,41 @@ export function transformBookingFieldsInternalToApi( required: !!field.required, disableOnPrefill: !!field.disableOnPrefill, hidden: !!field.hidden, - } as CustomFieldOutput_2024_06_14; + } satisfies BooleanFieldOutput_2024_06_14; case "select": + return { + isDefault: false, + type: field.type, + slug: field.name, + label: field.label, + required: !!field.required, + placeholder: field.placeholder, + disableOnPrefill: !!field.disableOnPrefill, + options: field.options ? field.options.map((option) => option.value) : [], + hidden: !!field.hidden, + } satisfies SelectFieldOutput_2024_06_14; case "multiselect": + return { + isDefault: false, + type: field.type, + slug: field.name, + label: field.label, + required: !!field.required, + disableOnPrefill: !!field.disableOnPrefill, + options: field.options ? field.options.map((option) => option.value) : [], + hidden: !!field.hidden, + } satisfies MultiSelectFieldOutput_2024_06_14; case "checkbox": + return { + isDefault: false, + type: field.type, + slug: field.name, + label: field.label, + required: !!field.required, + disableOnPrefill: !!field.disableOnPrefill, + options: field.options ? field.options.map((option) => option.value) : [], + hidden: !!field.hidden, + } satisfies CheckboxGroupFieldOutput_2024_06_14; case "radio": return { isDefault: false, @@ -116,16 +263,15 @@ export function transformBookingFieldsInternalToApi( label: field.label, required: !!field.required, options: field.options ? field.options.map((option) => option.value) : [], - ...(field.type === "select" ? { placeholder: field.placeholder } : {}), disableOnPrefill: !!field.disableOnPrefill, hidden: !!field.hidden, - } as CustomFieldOutput_2024_06_14; + } satisfies RadioGroupFieldOutput_2024_06_14; default: return { type: "unknown", slug: "unknown", bookingField: JSON.stringify(field), - }; + } satisfies OutputUnknownBookingField_2024_06_14; } } }); diff --git a/yarn.lock b/yarn.lock index ba82b2ade482f8..342d9379a1307b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4141,7 +4141,7 @@ __metadata: "@axiomhq/winston": ^1.2.0 "@calcom/platform-constants": "*" "@calcom/platform-enums": "*" - "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.84" + "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.85" "@calcom/platform-libraries-0.0.2": "npm:@calcom/platform-libraries@0.0.2" "@calcom/platform-types": "*" "@calcom/platform-utils": "*" @@ -5194,14 +5194,14 @@ __metadata: languageName: node linkType: hard -"@calcom/platform-libraries@npm:@calcom/platform-libraries@0.0.84": - version: 0.0.84 - resolution: "@calcom/platform-libraries@npm:0.0.84" +"@calcom/platform-libraries@npm:@calcom/platform-libraries@0.0.85": + version: 0.0.85 + resolution: "@calcom/platform-libraries@npm:0.0.85" dependencies: "@calcom/core": "*" "@calcom/features": "*" "@calcom/lib": "*" - checksum: 4372a4b7942ce8e13f1bb36c6b4e9193917ea1bc5322a4ca6af4176de01c70f199ff1fe707077f470df9d054a055be069a80d764cebd4ead502ac684b55ea5c9 + checksum: 19e00a1de600805d800fc7027c246164f1c1ce58b837ca934313fe31c0c77e6338179e72b8045ceabcc9d754ddc3600028b8676dcf2b456696a443a3aed186ea languageName: node linkType: hard