@ordinatio/scheduling 0.6.1 → 0.8.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.6.1",
3
+ "version": "0.8.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,24 @@
1
+ -- CreateTable
2
+ CREATE TABLE "OrganizationApiKey" (
3
+ "id" TEXT NOT NULL,
4
+ "organizationId" TEXT NOT NULL,
5
+ "name" TEXT NOT NULL,
6
+ "access" TEXT NOT NULL,
7
+ "prefix" TEXT NOT NULL,
8
+ "keyHash" TEXT NOT NULL,
9
+ "createdByUserId" TEXT,
10
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
11
+ "lastUsedAt" TIMESTAMP(3),
12
+ "revokedAt" TIMESTAMP(3),
13
+
14
+ CONSTRAINT "OrganizationApiKey_pkey" PRIMARY KEY ("id")
15
+ );
16
+
17
+ -- CreateIndex
18
+ CREATE UNIQUE INDEX "OrganizationApiKey_keyHash_key" ON "OrganizationApiKey"("keyHash");
19
+
20
+ -- CreateIndex
21
+ CREATE INDEX "OrganizationApiKey_organizationId_idx" ON "OrganizationApiKey"("organizationId");
22
+
23
+ -- AddForeignKey
24
+ ALTER TABLE "OrganizationApiKey" ADD CONSTRAINT "OrganizationApiKey_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -0,0 +1,67 @@
1
+ -- CreateTable
2
+ CREATE TABLE "GiftCertificate" (
3
+ "id" TEXT NOT NULL,
4
+ "organizationId" TEXT NOT NULL,
5
+ "code" TEXT NOT NULL,
6
+ "status" TEXT NOT NULL DEFAULT 'ACTIVE',
7
+ "currency" TEXT NOT NULL DEFAULT 'usd',
8
+ "initialCents" INTEGER NOT NULL,
9
+ "balanceCents" INTEGER NOT NULL,
10
+ "ledgerSeq" INTEGER NOT NULL DEFAULT 0,
11
+ "expiresAt" TIMESTAMP(3),
12
+ "recipientName" TEXT,
13
+ "recipientEmail" TEXT,
14
+ "purchaserName" TEXT,
15
+ "purchaserEmail" TEXT,
16
+ "message" TEXT,
17
+ "notes" TEXT,
18
+ "paymentId" TEXT,
19
+ "createdByUserId" TEXT,
20
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
21
+ "updatedAt" TIMESTAMP(3) NOT NULL,
22
+
23
+ CONSTRAINT "GiftCertificate_pkey" PRIMARY KEY ("id"),
24
+ -- A balance can never go below nothing or above what the certificate was issued for, whatever the application does.
25
+ CONSTRAINT "GiftCertificate_balance_range" CHECK ("balanceCents" >= 0 AND "balanceCents" <= "initialCents")
26
+ );
27
+
28
+ -- CreateTable
29
+ CREATE TABLE "GiftCertificateTransaction" (
30
+ "id" TEXT NOT NULL,
31
+ "certificateId" TEXT NOT NULL,
32
+ "organizationId" TEXT NOT NULL,
33
+ "seq" INTEGER NOT NULL,
34
+ "type" TEXT NOT NULL,
35
+ "amountCents" INTEGER NOT NULL,
36
+ "balanceAfterCents" INTEGER NOT NULL,
37
+ "appointmentId" TEXT,
38
+ "note" TEXT,
39
+ "createdByUserId" TEXT,
40
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
41
+
42
+ CONSTRAINT "GiftCertificateTransaction_pkey" PRIMARY KEY ("id")
43
+ );
44
+
45
+ -- CreateIndex
46
+ CREATE UNIQUE INDEX "GiftCertificate_code_key" ON "GiftCertificate"("code");
47
+
48
+ -- CreateIndex
49
+ CREATE UNIQUE INDEX "GiftCertificate_organizationId_paymentId_key" ON "GiftCertificate"("organizationId", "paymentId");
50
+
51
+ -- CreateIndex
52
+ CREATE INDEX "GiftCertificate_organizationId_status_idx" ON "GiftCertificate"("organizationId", "status");
53
+
54
+ -- CreateIndex
55
+ CREATE UNIQUE INDEX "GiftCertificateTransaction_certificateId_seq_key" ON "GiftCertificateTransaction"("certificateId", "seq");
56
+
57
+ -- CreateIndex
58
+ CREATE INDEX "GiftCertificateTransaction_organizationId_idx" ON "GiftCertificateTransaction"("organizationId");
59
+
60
+ -- CreateIndex
61
+ CREATE INDEX "GiftCertificateTransaction_appointmentId_idx" ON "GiftCertificateTransaction"("appointmentId");
62
+
63
+ -- AddForeignKey
64
+ ALTER TABLE "GiftCertificate" ADD CONSTRAINT "GiftCertificate_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE;
65
+
66
+ -- AddForeignKey
67
+ ALTER TABLE "GiftCertificateTransaction" ADD CONSTRAINT "GiftCertificateTransaction_certificateId_fkey" FOREIGN KEY ("certificateId") REFERENCES "GiftCertificate"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -37,6 +37,8 @@ model Organization {
37
37
  dataSubjectRequests DataSubjectRequest[]
38
38
  brand OrganizationBrand?
39
39
  textSettings OrganizationTextSettings?
40
+ apiKeys OrganizationApiKey[]
41
+ giftCertificates GiftCertificate[]
40
42
  }
41
43
 
42
44
  // ===== BEGIN SHARED SCHEDULING MODELS (copied verbatim into the host schema by packages/database/scripts/sync-scheduling-schema.ts) =====
@@ -556,6 +558,80 @@ model OrganizationTextSettings {
556
558
  updatedAt DateTime @updatedAt
557
559
  }
558
560
 
561
+ /// A key that lets an outside tool act for one business. Only a hash of the secret is stored.
562
+ model OrganizationApiKey {
563
+ id String @id @default(cuid())
564
+ organizationId String
565
+ organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
566
+ name String
567
+ /// READ or FULL.
568
+ access String
569
+ /// The start of the key, to recognise it in a list.
570
+ prefix String
571
+ keyHash String @unique
572
+ createdByUserId String?
573
+ createdAt DateTime @default(now())
574
+ lastUsedAt DateTime?
575
+ revokedAt DateTime?
576
+
577
+ @@index([organizationId])
578
+ }
579
+
580
+ /// Prepaid value a business sells or gives away. The balance moves only together with a GiftCertificateTransaction row.
581
+ model GiftCertificate {
582
+ id String @id @default(cuid())
583
+ organizationId String
584
+ organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
585
+ /// The code in its stored form: upper case, no hyphens. Unique across all businesses.
586
+ code String @unique
587
+ /// ACTIVE or VOID. "Expired" and "used up" follow from expiresAt and balanceCents.
588
+ status String @default("ACTIVE")
589
+ currency String @default("usd")
590
+ initialCents Int
591
+ balanceCents Int
592
+ /// The number of the newest ledger line. Every change takes the row lock by adding one, so line numbers never repeat or go backwards.
593
+ ledgerSeq Int @default(0)
594
+ expiresAt DateTime?
595
+ recipientName String?
596
+ recipientEmail String?
597
+ purchaserName String?
598
+ purchaserEmail String?
599
+ message String?
600
+ notes String?
601
+ /// The payment that bought it, when it was sold online. One certificate per payment in a business, so a repeated payment notice cannot make a second.
602
+ paymentId String?
603
+ createdByUserId String?
604
+ createdAt DateTime @default(now())
605
+ updatedAt DateTime @updatedAt
606
+ transactions GiftCertificateTransaction[]
607
+
608
+ @@unique([organizationId, paymentId])
609
+ @@index([organizationId, status])
610
+ }
611
+
612
+ /// One line of a certificate's history. Never edited; removed only when its certificate is.
613
+ model GiftCertificateTransaction {
614
+ id String @id @default(cuid())
615
+ certificateId String
616
+ certificate GiftCertificate @relation(fields: [certificateId], references: [id], onDelete: Cascade)
617
+ organizationId String
618
+ /// The line's place in the certificate's history, from GiftCertificate.ledgerSeq at the time it was written.
619
+ seq Int
620
+ /// ISSUE, REDEEM, RESTORE or VOID.
621
+ type String
622
+ /// Signed: positive adds to the balance, negative takes from it.
623
+ amountCents Int
624
+ balanceAfterCents Int
625
+ appointmentId String?
626
+ note String?
627
+ createdByUserId String?
628
+ createdAt DateTime @default(now())
629
+
630
+ @@unique([certificateId, seq])
631
+ @@index([organizationId])
632
+ @@index([appointmentId])
633
+ }
634
+
559
635
  model ServicePackage {
560
636
  id String @id @default(cuid())
561
637
  name String