Accounts 1.1.0: moving Events' users in, people.* requests, new recovery codes
POST /api/accounts/v1/requests (crosscode.identity-request/1): import.* keeps each person's Events id as sub, password hash and authenticator secret (sealed in transit), consent, notices and lockout; linked when the email already has an account. people.* for product admins, limited to people the product knows. New recovery codes after the first 2FA sign-in for people moved in with 2FA. screen=signup. auth-client: request(), seal(), signUp. 8 new tests (47 in all). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
-- Accounts 1.1.0 (docs/EVENTS-3.0-PLAN.md §8): moving a product's users in, and its people.* requests.
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Account" ADD COLUMN "recoveryCodesNeeded" BOOLEAN NOT NULL DEFAULT false;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "EmailToken" ADD COLUMN "returnUrl" TEXT;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "ProductLink" ADD COLUMN "importStartedAt" TIMESTAMP(3);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "ProductPerson" (
|
||||
"id" TEXT NOT NULL,
|
||||
"linkId" TEXT NOT NULL,
|
||||
"accountId" TEXT NOT NULL,
|
||||
"via" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "ProductPerson_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "ProductRequest" (
|
||||
"requestId" TEXT NOT NULL,
|
||||
"linkId" TEXT NOT NULL,
|
||||
"type" TEXT NOT NULL,
|
||||
"reply" JSONB NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "ProductRequest_pkey" PRIMARY KEY ("requestId")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "ProductPerson_linkId_accountId_key" ON "ProductPerson"("linkId", "accountId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "ProductPerson_accountId_idx" ON "ProductPerson"("accountId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "ProductRequest_createdAt_idx" ON "ProductRequest"("createdAt");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "ProductPerson" ADD CONSTRAINT "ProductPerson_linkId_fkey" FOREIGN KEY ("linkId") REFERENCES "ProductLink"("installId") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "ProductPerson" ADD CONSTRAINT "ProductPerson_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "Account"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "ProductRequest" ADD CONSTRAINT "ProductRequest_linkId_fkey" FOREIGN KEY ("linkId") REFERENCES "ProductLink"("installId") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -55,6 +55,9 @@ model Account {
|
||||
lastSignInAt DateTime?
|
||||
deactivatedAt DateTime?
|
||||
anonymisedAt DateTime?
|
||||
// 1.1.0: moved in from a product with 2FA but without recovery codes (Events keys its codes with
|
||||
// its own secret, so they can't move): new ones are shown after the next sign-in's second step.
|
||||
recoveryCodesNeeded Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@ -65,6 +68,7 @@ model Account {
|
||||
consentChanges ConsentChange[]
|
||||
exports DataExport[]
|
||||
deletionRequests DeletionRequest[]
|
||||
products ProductPerson[]
|
||||
|
||||
@@index([status])
|
||||
}
|
||||
@@ -107,6 +111,8 @@ model EmailToken {
|
||||
tokenHash String @unique
|
||||
// The sign-in the link belongs to, so it carries on to the product afterwards (§5).
|
||||
interactionUid String?
|
||||
// 1.1.0: a "set your password" link a product asked for (people.ensure) ends on that product.
|
||||
returnUrl String?
|
||||
expiresAt DateTime
|
||||
usedAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
@@ -195,16 +201,47 @@ model AppSetting {
|
||||
// A linked product (Connect, crosscode.link/1). Each is also an OIDC client (§4): client_id is
|
||||
// installId, the client secret is derived from `secret`, the addresses are fixed paths on `url`.
|
||||
model ProductLink {
|
||||
installId String @id
|
||||
product String // events | website | app
|
||||
url String
|
||||
publicKey String
|
||||
secret String // encrypted
|
||||
connectedAt DateTime
|
||||
connectedById String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
deliveries Delivery[]
|
||||
installId String @id
|
||||
product String // events | website | app
|
||||
url String
|
||||
publicKey String
|
||||
secret String // encrypted
|
||||
connectedAt DateTime
|
||||
connectedById String?
|
||||
// 1.1.0: a move of this product's users into Accounts is under way (import.begin … finish).
|
||||
importStartedAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
deliveries Delivery[]
|
||||
people ProductPerson[]
|
||||
requests ProductRequest[]
|
||||
}
|
||||
|
||||
// 1.1.0: the people a linked product knows (imported by it, added by it, or signed in through it).
|
||||
// A product's people.* requests only reach these.
|
||||
model ProductPerson {
|
||||
id String @id @default(uuid())
|
||||
linkId String
|
||||
link ProductLink @relation(fields: [linkId], references: [installId], onDelete: Cascade)
|
||||
accountId String
|
||||
account Account @relation(fields: [accountId], references: [id], onDelete: Cascade)
|
||||
via String // import | ensure | sign_in
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@unique([linkId, accountId])
|
||||
@@index([accountId])
|
||||
}
|
||||
|
||||
// 1.1.0: crosscode.identity-request/1 requests already handled, so a retry gets the same answer.
|
||||
model ProductRequest {
|
||||
requestId String @id
|
||||
linkId String
|
||||
link ProductLink @relation(fields: [linkId], references: [installId], onDelete: Cascade)
|
||||
type String
|
||||
reply Json
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@index([createdAt])
|
||||
}
|
||||
|
||||
model LinkNonce {
|
||||
|
||||
Reference in New Issue
Block a user