@ordinatio/scheduling 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ordinatio/scheduling",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "license": "MIT",
5
5
  "description": "Scheduling engine for appointment-based businesses. API-first, no iframes.",
6
6
  "main": "./dist/index.js",
@@ -0,0 +1,51 @@
1
+ -- CreateTable
2
+ CREATE TABLE "WaitlistEntry" (
3
+ "id" TEXT NOT NULL,
4
+ "organizationId" TEXT NOT NULL,
5
+ "typeId" TEXT NOT NULL,
6
+ "calendarId" TEXT,
7
+ "day" TEXT NOT NULL,
8
+ "slotStart" TIMESTAMP(3),
9
+ "timezone" TEXT NOT NULL,
10
+ "clientName" TEXT NOT NULL,
11
+ "clientEmail" TEXT NOT NULL,
12
+ "clientPhone" TEXT,
13
+ "token" TEXT NOT NULL,
14
+ "status" TEXT NOT NULL DEFAULT 'WAITING',
15
+ "offerCalendarId" TEXT,
16
+ "offerSlotStart" TIMESTAMP(3),
17
+ "offerExpiresAt" TIMESTAMP(3),
18
+ "offeredAt" TIMESTAMP(3),
19
+ "acceptingAt" TIMESTAMP(3),
20
+ "bookedAppointmentId" TEXT,
21
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
22
+
23
+ CONSTRAINT "WaitlistEntry_pkey" PRIMARY KEY ("id")
24
+ );
25
+
26
+ -- CreateIndex
27
+ CREATE UNIQUE INDEX "WaitlistEntry_token_key" ON "WaitlistEntry"("token");
28
+
29
+ -- CreateIndex
30
+ CREATE INDEX "WaitlistEntry_organizationId_status_createdAt_idx" ON "WaitlistEntry"("organizationId", "status", "createdAt");
31
+
32
+ -- CreateIndex
33
+ CREATE INDEX "WaitlistEntry_typeId_day_status_createdAt_idx" ON "WaitlistEntry"("typeId", "day", "status", "createdAt");
34
+
35
+ -- CreateIndex
36
+ CREATE INDEX "WaitlistEntry_status_offerExpiresAt_idx" ON "WaitlistEntry"("status", "offerExpiresAt");
37
+
38
+ -- CreateIndex
39
+ CREATE INDEX "WaitlistEntry_clientEmail_idx" ON "WaitlistEntry"("clientEmail");
40
+
41
+ -- AddForeignKey
42
+ ALTER TABLE "WaitlistEntry" ADD CONSTRAINT "WaitlistEntry_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE;
43
+
44
+ -- AddForeignKey
45
+ ALTER TABLE "WaitlistEntry" ADD CONSTRAINT "WaitlistEntry_typeId_fkey" FOREIGN KEY ("typeId") REFERENCES "AppointmentType"("id") ON DELETE CASCADE ON UPDATE CASCADE;
46
+
47
+
48
+ -- One live offer holds a slot at a time: two cancellations that free the same slot cannot both offer it.
49
+ CREATE UNIQUE INDEX "waitlist_one_live_offer_per_slot"
50
+ ON "WaitlistEntry" ("offerCalendarId", "offerSlotStart")
51
+ WHERE status IN ('OFFERED', 'ACCEPTING');
@@ -0,0 +1,26 @@
1
+ -- CreateTable
2
+ CREATE TABLE "RoutingForm" (
3
+ "id" TEXT NOT NULL,
4
+ "organizationId" TEXT NOT NULL,
5
+ "name" TEXT NOT NULL,
6
+ "slug" TEXT NOT NULL,
7
+ "description" TEXT,
8
+ "isActive" BOOLEAN NOT NULL DEFAULT true,
9
+ "questions" JSONB NOT NULL,
10
+ "rules" JSONB NOT NULL,
11
+ "fallback" JSONB NOT NULL,
12
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
13
+ "updatedAt" TIMESTAMP(3) NOT NULL,
14
+
15
+ CONSTRAINT "RoutingForm_pkey" PRIMARY KEY ("id")
16
+ );
17
+
18
+ -- CreateIndex
19
+ CREATE INDEX "RoutingForm_organizationId_isActive_idx" ON "RoutingForm"("organizationId", "isActive");
20
+
21
+ -- CreateIndex
22
+ CREATE UNIQUE INDEX "RoutingForm_organizationId_slug_key" ON "RoutingForm"("organizationId", "slug");
23
+
24
+ -- AddForeignKey
25
+ ALTER TABLE "RoutingForm" ADD CONSTRAINT "RoutingForm_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE;
26
+
@@ -0,0 +1,18 @@
1
+ -- CreateTable
2
+ CREATE TABLE "DataSubjectRequest" (
3
+ "id" TEXT NOT NULL,
4
+ "organizationId" TEXT NOT NULL,
5
+ "kind" TEXT NOT NULL,
6
+ "subjectHashes" TEXT[],
7
+ "requestedBy" TEXT NOT NULL,
8
+ "counts" JSONB NOT NULL,
9
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
10
+
11
+ CONSTRAINT "DataSubjectRequest_pkey" PRIMARY KEY ("id")
12
+ );
13
+
14
+ -- CreateIndex
15
+ CREATE INDEX "DataSubjectRequest_organizationId_createdAt_idx" ON "DataSubjectRequest"("organizationId", "createdAt");
16
+
17
+ -- AddForeignKey
18
+ ALTER TABLE "DataSubjectRequest" ADD CONSTRAINT "DataSubjectRequest_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -0,0 +1,26 @@
1
+ -- CreateTable
2
+ CREATE TABLE "OrganizationBrand" (
3
+ "id" TEXT NOT NULL,
4
+ "organizationId" TEXT NOT NULL,
5
+ "displayName" TEXT NOT NULL,
6
+ "logoUrl" TEXT,
7
+ "primaryColor" TEXT,
8
+ "accentColor" TEXT,
9
+ "backgroundColor" TEXT,
10
+ "textColor" TEXT,
11
+ "fontFamily" TEXT,
12
+ "footerText" TEXT,
13
+ "replyToEmail" TEXT,
14
+ "fromName" TEXT,
15
+ "fromEmail" TEXT,
16
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
17
+ "updatedAt" TIMESTAMP(3) NOT NULL,
18
+
19
+ CONSTRAINT "OrganizationBrand_pkey" PRIMARY KEY ("id")
20
+ );
21
+
22
+ -- CreateIndex
23
+ CREATE UNIQUE INDEX "OrganizationBrand_organizationId_key" ON "OrganizationBrand"("organizationId");
24
+
25
+ -- AddForeignKey
26
+ ALTER TABLE "OrganizationBrand" ADD CONSTRAINT "OrganizationBrand_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -28,6 +28,10 @@ model Organization {
28
28
  recurringSeries RecurringSeries[]
29
29
  notificationTemplates NotificationTemplate[]
30
30
  webhookEndpoints WebhookEndpoint[]
31
+ waitlistEntries WaitlistEntry[]
32
+ routingForms RoutingForm[]
33
+ dataSubjectRequests DataSubjectRequest[]
34
+ brand OrganizationBrand?
31
35
  }
32
36
 
33
37
  // ===== BEGIN SHARED SCHEDULING MODELS (copied verbatim into the host schema by packages/database/scripts/sync-scheduling-schema.ts) =====
@@ -185,6 +189,8 @@ model AppointmentType {
185
189
 
186
190
  @@unique([organizationId, slug])
187
191
  @@index([organizationId])
192
+
193
+ waitlistEntries WaitlistEntry[]
188
194
  }
189
195
 
190
196
  model AppointmentCategory {
@@ -443,6 +449,96 @@ model WebhookAttempt {
443
449
  @@index([deliveryId])
444
450
  }
445
451
 
452
+ // A client waiting for a full slot or day. When a booking is cancelled the first matching WAITING entry is offered the
453
+ // freed slot (status OFFERED) until offerExpiresAt. `token` is the client's own handle: it opens the offer and leaves
454
+ // the list, so it is only ever given to that client. A partial unique index (see the waitlist migration) lets one
455
+ // live offer hold a slot at a time.
456
+ model WaitlistEntry {
457
+ id String @id @default(cuid())
458
+ organizationId String
459
+ organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
460
+ typeId String
461
+ type AppointmentType @relation(fields: [typeId], references: [id], onDelete: Cascade)
462
+ calendarId String? // null = any calendar of the type
463
+ day String // YYYY-MM-DD in the calendar's timezone
464
+ slotStart DateTime? // null = any time that day
465
+ timezone String
466
+ clientName String
467
+ clientEmail String
468
+ clientPhone String?
469
+ token String @unique
470
+ status String @default("WAITING") // WAITING | OFFERED | ACCEPTING | BOOKED | EXPIRED
471
+ offerCalendarId String?
472
+ offerSlotStart DateTime?
473
+ offerExpiresAt DateTime?
474
+ offeredAt DateTime?
475
+ acceptingAt DateTime?
476
+ bookedAppointmentId String?
477
+ createdAt DateTime @default(now())
478
+
479
+ @@index([organizationId, status, createdAt])
480
+ @@index([typeId, day, status, createdAt])
481
+ @@index([status, offerExpiresAt])
482
+ @@index([clientEmail])
483
+ }
484
+
485
+ // A short form that sends a client to the right appointment type or calendar. `questions`, `rules` and `fallback` are
486
+ // checked when the form is saved (see routing/validate-structure), so what is stored is always well formed. Rules run in order and
487
+ // the first one whose conditions hold wins; when none does, `fallback` says where to send the client or what to tell them.
488
+ model RoutingForm {
489
+ id String @id @default(cuid())
490
+ organizationId String
491
+ organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
492
+ name String
493
+ slug String
494
+ description String?
495
+ isActive Boolean @default(true)
496
+ questions Json
497
+ rules Json
498
+ fallback Json
499
+ createdAt DateTime @default(now())
500
+ updatedAt DateTime @updatedAt
501
+
502
+ @@unique([organizationId, slug])
503
+ @@index([organizationId, isActive])
504
+ }
505
+
506
+ // The record that a person's data was exported or erased. It holds no name or email: `subjectHashes` are SHA-256 digests of
507
+ // the identifiers (see privacy/subject), enough to show later that a request was made for a given address and nothing more.
508
+ model DataSubjectRequest {
509
+ id String @id @default(cuid())
510
+ organizationId String
511
+ organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
512
+ kind String // EXPORT | ERASE
513
+ subjectHashes String[]
514
+ requestedBy String
515
+ counts Json
516
+ createdAt DateTime @default(now())
517
+
518
+ @@index([organizationId, createdAt])
519
+ }
520
+
521
+ // How an organization looks to its clients: the name, logo and colours on the booking page and in messages, and who
522
+ // messages come from. `fromEmail` is only accepted for a domain the host has confirmed it may send from (see brand/validate).
523
+ model OrganizationBrand {
524
+ id String @id @default(cuid())
525
+ organizationId String @unique
526
+ organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
527
+ displayName String
528
+ logoUrl String?
529
+ primaryColor String?
530
+ accentColor String?
531
+ backgroundColor String?
532
+ textColor String?
533
+ fontFamily String?
534
+ footerText String?
535
+ replyToEmail String?
536
+ fromName String?
537
+ fromEmail String?
538
+ createdAt DateTime @default(now())
539
+ updatedAt DateTime @updatedAt
540
+ }
541
+
446
542
  model ServicePackage {
447
543
  id String @id @default(cuid())
448
544
  name String