feat: Add private links to API (#22943)

* --init

* address change requests

* adding further changes

* address feedback

* further changes

* further clean-up

* clean up

* fix module import and others

* add guards

* remove unnecessary comments

* remove unnecessary comments

* cleanup

* sort coderabbig suggestions

* improve check

* chore: bump platform libraries

---------

Co-authored-by: Lauris Skraucis <[email protected]>
Co-authored-by: supalarry <[email protected]>
This commit is contained in:
authored and GitHub committed 2025-08-11 11:04:23 +00:00
1 parent 076e93ca56
commit af51df2b4d
23 files changed
+5286 -862

No files matched your search

@@ -129,6 +129,24 @@ export class HashedLinkService {
return hashedLink;
}
async createLinkForEventType(eventTypeId: number, input: string | HashedLinkInputType) {
const normalized = this.normalizeLinkInput(input);
return this.hashedLinkRepository.createLink(eventTypeId, normalized);
}
async updateLinkForEventType(eventTypeId: number, input: string | HashedLinkInputType) {
const normalized = this.normalizeLinkInput(input);
return this.hashedLinkRepository.updateLink(eventTypeId, normalized);
}
async deleteLinkForEventType(eventTypeId: number, linkId: string) {
return this.hashedLinkRepository.deleteLinks(eventTypeId, [linkId]);
}
async listLinksByEventType(eventTypeId: number) {
return this.hashedLinkRepository.findLinksByEventTypeId(eventTypeId);
}
/**
* Checks if a user has permission to access a link
* @param link - Link object with event type information
+8
View File
@@ -78,6 +78,11 @@
"import": "./dist/bookings.js",
"require": "./dist/bookings.cjs",
"types": "./dist/bookings.d.ts"
},
"./private-links": {
"import": "./dist/private-links.js",
"require": "./dist/private-links.cjs",
"types": "./dist/private-links.d.ts"
}
},
"typesVersions": {
@@ -108,6 +113,9 @@
],
"bookings": [
"dist/bookings.d.ts"
],
"private-links": [
"dist/private-links.d.ts"
]
}
}
@@ -0,0 +1,2 @@
export { generateHashedLink } from "@calcom/lib/generateHashedLink";
export { isLinkExpired } from "@calcom/lib/hashedLinksUtils";
@@ -27,6 +27,7 @@ export default defineConfig({
conferencing: resolve(__dirname, "./conferencing.ts"),
repositories: resolve(__dirname, "./repositories.ts"),
bookings: resolve(__dirname, "./bookings.ts"),
"private-links": resolve(__dirname, "./private-links.ts"),
},
name: "calcom-lib",
fileName: "calcom-lib",
@@ -1 +1,3 @@
export * from "./event-types_2024_06_14";
export * from "./inputs/private-link.input";
export * from "./outputs/private-link.output";
@@ -0,0 +1,61 @@
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import { Type } from "class-transformer";
import { IsOptional, IsDate, IsInt, Min, IsString } from "class-validator";
export class CreatePrivateLinkInput {
@IsOptional()
@IsDate()
@Type(() => Date)
@ApiPropertyOptional({
description: "Expiration date for time-based links",
type: String,
format: "date-time",
example: "2024-12-31T23:59:59.000Z",
})
expiresAt?: Date;
@IsOptional()
@IsInt()
@Min(1)
@ApiPropertyOptional({
description: "Maximum number of times the link can be used. If omitted and expiresAt is not provided, defaults to 1 (one time use).",
type: Number,
example: 10,
minimum: 1,
default: 1,
})
maxUsageCount?: number;
}
export class UpdatePrivateLinkInput {
@IsString()
@ApiProperty({
description: "The private link hash to update",
type: String,
example: "abc123def456",
})
linkId!: string;
@IsOptional()
@IsDate()
@Type(() => Date)
@ApiPropertyOptional({
description: "New expiration date for time-based links",
type: Date,
example: "2024-12-31T23:59:59.000Z",
})
expiresAt?: Date;
@IsOptional()
@IsInt()
@Min(1)
@ApiPropertyOptional({
description: "New maximum number of times the link can be used",
type: Number,
example: 10,
minimum: 1,
})
maxUsageCount?: number;
}
@@ -0,0 +1,132 @@
import { ApiExtraModels, ApiProperty, getSchemaPath } from "@nestjs/swagger";
// Base class with common properties
abstract class BasePrivateLinkOutput {
@ApiProperty({
description: "The private link ID",
type: String,
example: "abc123def456",
})
linkId!: string;
@ApiProperty({
description: "Event type ID this link belongs to",
type: Number,
example: 123,
})
eventTypeId!: number;
@ApiProperty({
description: "Whether the link is currently expired",
type: Boolean,
example: false,
})
isExpired!: boolean;
@ApiProperty({
description: "Full booking URL for this private link",
type: String,
format: "uri",
example: "https://cal.com/d/abc123def456/30min",
})
bookingUrl!: string;
}
// Time-based private link (expires at a specific date)
export class TimeBasedPrivateLinkOutput extends BasePrivateLinkOutput {
@ApiProperty({
description: "Expiration date for this time-based link",
type: String,
format: "date-time",
example: "2025-12-31T23:59:59.000Z",
})
expiresAt!: Date;
}
// Usage-based private link (expires after N uses)
export class UsageBasedPrivateLinkOutput extends BasePrivateLinkOutput {
@ApiProperty({
description: "Maximum number of times this link can be used",
type: Number,
example: 10,
})
maxUsageCount!: number;
@ApiProperty({
description: "Current usage count for this link",
type: Number,
example: 3,
})
usageCount!: number;
}
// Union type for either time-based or usage-based links
export type PrivateLinkOutput = TimeBasedPrivateLinkOutput | UsageBasedPrivateLinkOutput;
@ApiExtraModels(TimeBasedPrivateLinkOutput, UsageBasedPrivateLinkOutput)
export class CreatePrivateLinkOutput {
@ApiProperty({ description: "Response status", example: "success" })
status!: string;
@ApiProperty({
description: "Created private link data (either time-based or usage-based)",
oneOf: [
{ $ref: getSchemaPath(TimeBasedPrivateLinkOutput) },
{ $ref: getSchemaPath(UsageBasedPrivateLinkOutput) },
],
})
data!: PrivateLinkOutput;
}
@ApiExtraModels(TimeBasedPrivateLinkOutput, UsageBasedPrivateLinkOutput)
export class GetPrivateLinksOutput {
@ApiProperty({ description: "Response status", example: "success" })
status!: string;
@ApiProperty({
description: "Array of private links for the event type (mix of time-based and usage-based)",
type: "array",
items: {
oneOf: [
{ $ref: getSchemaPath(TimeBasedPrivateLinkOutput) },
{ $ref: getSchemaPath(UsageBasedPrivateLinkOutput) },
],
},
})
data!: PrivateLinkOutput[];
}
@ApiExtraModels(TimeBasedPrivateLinkOutput, UsageBasedPrivateLinkOutput)
export class UpdatePrivateLinkOutput {
@ApiProperty({ description: "Response status", example: "success" })
status!: string;
@ApiProperty({
description: "Updated private link data (either time-based or usage-based)",
oneOf: [
{ $ref: getSchemaPath(TimeBasedPrivateLinkOutput) },
{ $ref: getSchemaPath(UsageBasedPrivateLinkOutput) },
],
})
data!: PrivateLinkOutput;
}
export class DeletePrivateLinkOutput {
@ApiProperty({ description: "Response status", example: "success" })
status!: string;
@ApiProperty({
description: "Deleted link information",
type: "object",
properties: {
linkId: { type: "string", example: "abc123def456" },
message: { type: "string", example: "Private link deleted successfully" },
},
})
data!: {
linkId: string;
message: string;
};
}
+1
View File
@@ -7,6 +7,7 @@ export * from "./bookings";
export * from "./billing";
export * from "./schedules";
export * from "./event-types";
export * from "./event-types/inputs/private-link.input";
export * from "./organizations";
export * from "./teams";
export * from "./embed";