 faa67e0bb6
			
		
	
	
		faa67e0bb6
		
			
		
	
	
	
	
		
			
			* feat: add ApiKey model for new Api auth, owned by a user * fix: remove metadata:Json and add note:String instead in new apiKey model * fix: rename apiKey to apiKeys in moder User relation in schema.prisma * feat: add hashedKey to apiKey and lastUsedAt datetime to keep track of usage of keys and makiung them securely stored in db * fix 30 day -> 30 days in expiresAt * feat: api keys frontend in security page * adds hashedKey to api key model, add frontend api keys in security page * Make frontend work to create api keys with or without expiry, note, defaults to 1 month expiry * remove migration for now, add env.example to swagger, sync api * feat: hashed api keys * fix: minor refactor and cleanup in apiKeys generator * add api key success modal * sync apps/api * feat: We have API Keys in Security =) * remove swagger env from pr * apps api sync * remove comments in password section * feat: migration for api keys schema * sync api w main * delete apps/api * add back apps/api * make min date and disabled optional props in datepicker * feat fix type check errors * fix : types * fix: rmeove renaming of verificationrequest token indexes in migration * fix: remove extra div * Fixes for feedback in PR * fix button /> * fix: rename weird naming of translation for you_will_only_view_it_once * fix: remove ternary and use && to avoid null for false * fix sync apps/api with main not old commit * fix empty className * fix: remove unused imports * fix remove commented jsx fragment close * fix rename editing * improve translations * feat: adds beta tag in security tab under api keys * fix: use api keys everywhere * fix: cleanup code in api keys * fix: use watch and controller for neverexpires/datepicker * Fixes: improve api key never expires * add back change password h2 title section in security page * fix update env API_KEY_ prefix default to cal_ * fix: improve eidt api keys modal * fix: update edit mutation in viewer.apiKeys * Update apps/web/ee/components/apiKeys/ApiKeyListItem.tsx Co-authored-by: Alex van Andel <me@alexvanandel.com> * fix: item: any to pass build Co-authored-by: Agusti Fernandez Pardo <git@agusti.me> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Omar López <zomars@me.com> Co-authored-by: Alex van Andel <me@alexvanandel.com>
		
			
				
	
	
		
			387 lines
		
	
	
	
		
			12 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
			
		
		
	
	
			387 lines
		
	
	
	
		
			12 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
| // This is your Prisma schema file,
 | |
| // learn more about it in the docs: https://pris.ly/d/prisma-schema
 | |
| 
 | |
| datasource db {
 | |
|   provider = "postgresql"
 | |
|   url      = env("DATABASE_URL")
 | |
| }
 | |
| 
 | |
| generator client {
 | |
|   provider        = "prisma-client-js"
 | |
|   previewFeatures = ["filterJson"]
 | |
| }
 | |
| 
 | |
| generator zod {
 | |
|   provider      = "zod-prisma"
 | |
|   output        = "./zod"
 | |
|   imports       = "./zod-utils"
 | |
|   relationModel = "default"
 | |
| }
 | |
| 
 | |
| enum SchedulingType {
 | |
|   ROUND_ROBIN  @map("roundRobin")
 | |
|   COLLECTIVE   @map("collective")
 | |
| }
 | |
| 
 | |
| enum PeriodType {
 | |
|   UNLIMITED  @map("unlimited")
 | |
|   ROLLING    @map("rolling")
 | |
|   RANGE      @map("range")
 | |
| }
 | |
| 
 | |
| model EventType {
 | |
|   id                      Int                    @id @default(autoincrement())
 | |
|   /// @zod.nonempty()
 | |
|   title                   String
 | |
|   /// @zod.custom(imports.eventTypeSlug)
 | |
|   slug                    String
 | |
|   description             String?
 | |
|   position                Int                    @default(0)
 | |
|   /// @zod.custom(imports.eventTypeLocations)
 | |
|   locations               Json?
 | |
|   length                  Int
 | |
|   hidden                  Boolean                @default(false)
 | |
|   users                   User[]                 @relation("user_eventtype")
 | |
|   userId                  Int?
 | |
|   team                    Team?                  @relation(fields: [teamId], references: [id])
 | |
|   teamId                  Int?
 | |
|   bookings                Booking[]
 | |
|   availability            Availability[]
 | |
|   webhooks                Webhook[]
 | |
|   destinationCalendar     DestinationCalendar?
 | |
|   eventName               String?
 | |
|   customInputs            EventTypeCustomInput[]
 | |
|   timeZone                String?
 | |
|   periodType              PeriodType             @default(UNLIMITED)
 | |
|   periodStartDate         DateTime?
 | |
|   periodEndDate           DateTime?
 | |
|   periodDays              Int?
 | |
|   periodCountCalendarDays Boolean?
 | |
|   requiresConfirmation    Boolean                @default(false)
 | |
|   disableGuests           Boolean                @default(false)
 | |
|   hideCalendarNotes       Boolean                @default(false)
 | |
|   minimumBookingNotice    Int                    @default(120)
 | |
|   beforeEventBuffer       Int                    @default(0)
 | |
|   afterEventBuffer        Int                    @default(0)
 | |
|   schedulingType          SchedulingType?
 | |
|   schedule                Schedule?
 | |
|   price                   Int                    @default(0)
 | |
|   currency                String                 @default("usd")
 | |
|   slotInterval            Int?
 | |
|   metadata                Json?
 | |
|   successRedirectUrl      String?
 | |
| 
 | |
|   @@unique([userId, slug])
 | |
| }
 | |
| 
 | |
| model Credential {
 | |
|   id     Int    @id @default(autoincrement())
 | |
|   type   String
 | |
|   key    Json
 | |
|   user   User?  @relation(fields: [userId], references: [id], onDelete: Cascade)
 | |
|   userId Int?
 | |
| }
 | |
| 
 | |
| enum UserPlan {
 | |
|   FREE
 | |
|   TRIAL
 | |
|   PRO
 | |
| }
 | |
| 
 | |
| enum IdentityProvider {
 | |
|   CAL
 | |
|   GOOGLE
 | |
|   SAML
 | |
| }
 | |
| 
 | |
| model DestinationCalendar {
 | |
|   id          Int        @id @default(autoincrement())
 | |
|   integration String
 | |
|   externalId  String
 | |
|   user        User?      @relation(fields: [userId], references: [id])
 | |
|   userId      Int?       @unique
 | |
|   booking     Booking?   @relation(fields: [bookingId], references: [id])
 | |
|   bookingId   Int?       @unique
 | |
|   eventType   EventType? @relation(fields: [eventTypeId], references: [id])
 | |
|   eventTypeId Int?       @unique
 | |
| }
 | |
| 
 | |
| model User {
 | |
|   id                  Int                  @id @default(autoincrement())
 | |
|   username            String?              @unique
 | |
|   name                String?
 | |
|   /// @zod.email()
 | |
|   email               String               @unique
 | |
|   emailVerified       DateTime?
 | |
|   password            String?
 | |
|   bio                 String?
 | |
|   avatar              String?
 | |
|   timeZone            String               @default("Europe/London")
 | |
|   weekStart           String               @default("Sunday")
 | |
|   // DEPRECATED - TO BE REMOVED
 | |
|   startTime           Int                  @default(0)
 | |
|   endTime             Int                  @default(1440)
 | |
|   // </DEPRECATED>
 | |
|   bufferTime          Int                  @default(0)
 | |
|   hideBranding        Boolean              @default(false)
 | |
|   theme               String?
 | |
|   createdDate         DateTime             @default(now()) @map(name: "created")
 | |
|   trialEndsAt         DateTime?
 | |
|   eventTypes          EventType[]          @relation("user_eventtype")
 | |
|   credentials         Credential[]
 | |
|   teams               Membership[]
 | |
|   bookings            Booking[]
 | |
|   schedules           Schedule[]
 | |
|   defaultScheduleId   Int?
 | |
|   selectedCalendars   SelectedCalendar[]
 | |
|   completedOnboarding Boolean              @default(false)
 | |
|   locale              String?
 | |
|   timeFormat          Int?                 @default(12)
 | |
|   twoFactorSecret     String?
 | |
|   twoFactorEnabled    Boolean              @default(false)
 | |
|   identityProvider    IdentityProvider     @default(CAL)
 | |
|   identityProviderId  String?
 | |
|   availability        Availability[]
 | |
|   invitedTo           Int?
 | |
|   plan                UserPlan             @default(TRIAL)
 | |
|   webhooks            Webhook[]
 | |
|   brandColor          String               @default("#292929")
 | |
|   darkBrandColor      String               @default("#fafafa")
 | |
|   // the location where the events will end up
 | |
|   destinationCalendar DestinationCalendar?
 | |
|   away                Boolean              @default(false)
 | |
|   // participate in dynamic group booking or not
 | |
|   allowDynamicBooking Boolean?             @default(true)
 | |
|   metadata            Json?
 | |
|   verified            Boolean?             @default(false)
 | |
|   apiKeys             ApiKey[]
 | |
| 
 | |
|   @@map(name: "users")
 | |
| }
 | |
| 
 | |
| model Team {
 | |
|   id           Int          @id @default(autoincrement())
 | |
|   name         String?
 | |
|   slug         String?      @unique
 | |
|   logo         String?
 | |
|   bio          String?
 | |
|   hideBranding Boolean      @default(false)
 | |
|   members      Membership[]
 | |
|   eventTypes   EventType[]
 | |
| }
 | |
| 
 | |
| enum MembershipRole {
 | |
|   MEMBER
 | |
|   ADMIN
 | |
|   OWNER
 | |
| }
 | |
| 
 | |
| model Membership {
 | |
|   teamId   Int
 | |
|   userId   Int
 | |
|   accepted Boolean        @default(false)
 | |
|   role     MembershipRole
 | |
|   team     Team           @relation(fields: [teamId], references: [id])
 | |
|   user     User           @relation(fields: [userId], references: [id], onDelete: Cascade)
 | |
| 
 | |
|   @@id([userId, teamId])
 | |
| }
 | |
| 
 | |
| model VerificationRequest {
 | |
|   id         Int      @id @default(autoincrement())
 | |
|   identifier String
 | |
|   token      String   @unique
 | |
|   expires    DateTime
 | |
|   createdAt  DateTime @default(now())
 | |
|   updatedAt  DateTime @updatedAt
 | |
| 
 | |
|   @@unique([identifier, token])
 | |
| }
 | |
| 
 | |
| model BookingReference {
 | |
|   id              Int      @id @default(autoincrement())
 | |
|   type            String
 | |
|   uid             String
 | |
|   meetingId       String?
 | |
|   meetingPassword String?
 | |
|   meetingUrl      String?
 | |
|   booking         Booking? @relation(fields: [bookingId], references: [id], onDelete: Cascade)
 | |
|   bookingId       Int?
 | |
|   deleted         Boolean?
 | |
| }
 | |
| 
 | |
| model Attendee {
 | |
|   id        Int      @id @default(autoincrement())
 | |
|   email     String
 | |
|   name      String
 | |
|   timeZone  String
 | |
|   locale    String?  @default("en")
 | |
|   booking   Booking? @relation(fields: [bookingId], references: [id])
 | |
|   bookingId Int?
 | |
| }
 | |
| 
 | |
| enum BookingStatus {
 | |
|   CANCELLED  @map("cancelled")
 | |
|   ACCEPTED   @map("accepted")
 | |
|   REJECTED   @map("rejected")
 | |
|   PENDING    @map("pending")
 | |
| }
 | |
| 
 | |
| model DailyEventReference {
 | |
|   id         Int      @id @default(autoincrement())
 | |
|   dailyurl   String   @default("dailycallurl")
 | |
|   dailytoken String   @default("dailytoken")
 | |
|   booking    Booking? @relation(fields: [bookingId], references: [id])
 | |
|   bookingId  Int?     @unique
 | |
| }
 | |
| 
 | |
| model Booking {
 | |
|   id                  Int                  @id @default(autoincrement())
 | |
|   uid                 String               @unique
 | |
|   user                User?                @relation(fields: [userId], references: [id])
 | |
|   userId              Int?
 | |
|   references          BookingReference[]
 | |
|   eventType           EventType?           @relation(fields: [eventTypeId], references: [id])
 | |
|   eventTypeId         Int?
 | |
|   title               String
 | |
|   description         String?
 | |
|   startTime           DateTime
 | |
|   endTime             DateTime
 | |
|   attendees           Attendee[]
 | |
|   location            String?
 | |
|   dailyRef            DailyEventReference?
 | |
|   createdAt           DateTime             @default(now())
 | |
|   updatedAt           DateTime?
 | |
|   confirmed           Boolean              @default(true)
 | |
|   rejected            Boolean              @default(false)
 | |
|   status              BookingStatus        @default(ACCEPTED)
 | |
|   paid                Boolean              @default(false)
 | |
|   payment             Payment[]
 | |
|   destinationCalendar DestinationCalendar?
 | |
|   cancellationReason  String?
 | |
|   rejectionReason     String?
 | |
|   dynamicEventSlugRef String?
 | |
|   dynamicGroupSlugRef String?
 | |
|   rescheduled         Boolean?
 | |
|   fromReschedule      String?
 | |
| }
 | |
| 
 | |
| model Schedule {
 | |
|   id           Int            @id @default(autoincrement())
 | |
|   user         User           @relation(fields: [userId], references: [id], onDelete: Cascade)
 | |
|   userId       Int
 | |
|   eventType    EventType?     @relation(fields: [eventTypeId], references: [id])
 | |
|   eventTypeId  Int?           @unique
 | |
|   name         String
 | |
|   timeZone     String?
 | |
|   availability Availability[]
 | |
| }
 | |
| 
 | |
| model Availability {
 | |
|   id          Int        @id @default(autoincrement())
 | |
|   user        User?      @relation(fields: [userId], references: [id], onDelete: Cascade)
 | |
|   userId      Int?
 | |
|   eventType   EventType? @relation(fields: [eventTypeId], references: [id])
 | |
|   eventTypeId Int?
 | |
|   days        Int[]
 | |
|   startTime   DateTime   @db.Time
 | |
|   endTime     DateTime   @db.Time
 | |
|   date        DateTime?  @db.Date
 | |
|   Schedule    Schedule?  @relation(fields: [scheduleId], references: [id])
 | |
|   scheduleId  Int?
 | |
| }
 | |
| 
 | |
| model SelectedCalendar {
 | |
|   user        User   @relation(fields: [userId], references: [id], onDelete: Cascade)
 | |
|   userId      Int
 | |
|   integration String
 | |
|   externalId  String
 | |
| 
 | |
|   @@id([userId, integration, externalId])
 | |
| }
 | |
| 
 | |
| enum EventTypeCustomInputType {
 | |
|   TEXT      @map("text")
 | |
|   TEXTLONG  @map("textLong")
 | |
|   NUMBER    @map("number")
 | |
|   BOOL      @map("bool")
 | |
| }
 | |
| 
 | |
| model EventTypeCustomInput {
 | |
|   id          Int                      @id @default(autoincrement())
 | |
|   eventTypeId Int
 | |
|   eventType   EventType                @relation(fields: [eventTypeId], references: [id])
 | |
|   label       String
 | |
|   type        EventTypeCustomInputType
 | |
|   required    Boolean
 | |
|   placeholder String                   @default("")
 | |
| }
 | |
| 
 | |
| model ResetPasswordRequest {
 | |
|   id        String   @id @default(cuid())
 | |
|   createdAt DateTime @default(now())
 | |
|   updatedAt DateTime @updatedAt
 | |
|   email     String
 | |
|   expires   DateTime
 | |
| }
 | |
| 
 | |
| enum ReminderType {
 | |
|   PENDING_BOOKING_CONFIRMATION
 | |
| }
 | |
| 
 | |
| model ReminderMail {
 | |
|   id             Int          @id @default(autoincrement())
 | |
|   referenceId    Int
 | |
|   reminderType   ReminderType
 | |
|   elapsedMinutes Int
 | |
|   createdAt      DateTime     @default(now())
 | |
| }
 | |
| 
 | |
| enum PaymentType {
 | |
|   STRIPE
 | |
| }
 | |
| 
 | |
| model Payment {
 | |
|   id         Int         @id @default(autoincrement())
 | |
|   uid        String      @unique
 | |
|   type       PaymentType
 | |
|   bookingId  Int
 | |
|   booking    Booking?    @relation(fields: [bookingId], references: [id], onDelete: Cascade)
 | |
|   amount     Int
 | |
|   fee        Int
 | |
|   currency   String
 | |
|   success    Boolean
 | |
|   refunded   Boolean
 | |
|   data       Json
 | |
|   externalId String      @unique
 | |
| }
 | |
| 
 | |
| enum WebhookTriggerEvents {
 | |
|   BOOKING_CREATED
 | |
|   BOOKING_RESCHEDULED
 | |
|   BOOKING_CANCELLED
 | |
| }
 | |
| 
 | |
| model Webhook {
 | |
|   id              String                 @id @unique
 | |
|   userId          Int?
 | |
|   eventTypeId     Int?
 | |
|   subscriberUrl   String
 | |
|   payloadTemplate String?
 | |
|   createdAt       DateTime               @default(now())
 | |
|   active          Boolean                @default(true)
 | |
|   eventTriggers   WebhookTriggerEvents[]
 | |
|   user            User?                  @relation(fields: [userId], references: [id], onDelete: Cascade)
 | |
|   eventType       EventType?             @relation(fields: [eventTypeId], references: [id], onDelete: Cascade)
 | |
| }
 | |
| 
 | |
| model ApiKey {
 | |
|   id         String    @id @unique @default(cuid())
 | |
|   userId     Int
 | |
|   note       String?
 | |
|   createdAt  DateTime  @default(now())
 | |
|   expiresAt  DateTime?
 | |
|   lastUsedAt DateTime?
 | |
|   hashedKey  String    @unique()
 | |
|   user       User?     @relation(fields: [userId], references: [id], onDelete: Cascade)
 | |
| }
 |