feat build

This commit is contained in:
mahmood
2026-09-25 19:12:39 +03:30
parent 36f239e02c
commit 148b99c4a6
310 changed files with 4709 additions and 329 deletions
@@ -0,0 +1,38 @@
-- Revocable admin sessions.
--
-- Until now an admin-panel token was purely self-contained: once signed it was
-- valid for its full 12h and nothing could cut it short — not deactivating the
-- account, not a central "sign out everywhere". Connecting the central IAM made
-- that gap concrete, because an IAM session revocation had no effect on a token
-- this API had already issued.
--
-- Each issued token now carries a `jti` recorded here, and JwtStrategy rejects a
-- token whose row is revoked. Rows are only written (and only enforced) while
-- session tracking is enabled, so a deployment that leaves it off keeps exactly
-- the previous behaviour and the previous query count.
CREATE TABLE "AdminSession" (
"id" TEXT NOT NULL,
"jti" TEXT NOT NULL,
"adminUserId" TEXT NOT NULL,
"iamSessionId" TEXT,
"iamSub" TEXT,
"ipAddress" TEXT,
"userAgent" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"expiresAt" TIMESTAMP(3),
"lastSeenAt" TIMESTAMP(3),
"revokedAt" TIMESTAMP(3),
"revokedReason" TEXT,
CONSTRAINT "AdminSession_pkey" PRIMARY KEY ("id")
);
CREATE UNIQUE INDEX "AdminSession_jti_key" ON "AdminSession"("jti");
CREATE INDEX "AdminSession_adminUserId_idx" ON "AdminSession"("adminUserId");
CREATE INDEX "AdminSession_iamSessionId_idx" ON "AdminSession"("iamSessionId");
CREATE INDEX "AdminSession_iamSub_idx" ON "AdminSession"("iamSub");
CREATE INDEX "AdminSession_expiresAt_idx" ON "AdminSession"("expiresAt");
ALTER TABLE "AdminSession"
ADD CONSTRAINT "AdminSession_adminUserId_fkey"
FOREIGN KEY ("adminUserId") REFERENCES "AdminUser"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -0,0 +1,33 @@
-- Revocable app sessions (customer app and sales-expert app).
--
-- The admin panel got this in 20260925120000_admin_session; the app token family
-- had the same gap: a 30-day self-contained token that nothing could end early.
-- That matters more here, because the app's login is OTP-only — there is no
-- password an operator could change to cut access.
--
-- No foreign key on purpose: an app token's subject is a Customer for a customer
-- and an AdminUser for a sales expert (D21), which one FK cannot express.
CREATE TABLE "AppSession" (
"id" TEXT NOT NULL,
"jti" TEXT NOT NULL,
"subjectId" TEXT NOT NULL,
"subjectType" TEXT NOT NULL,
"mobile" TEXT,
"iamSessionId" TEXT,
"iamSub" TEXT,
"ipAddress" TEXT,
"userAgent" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"expiresAt" TIMESTAMP(3),
"lastSeenAt" TIMESTAMP(3),
"revokedAt" TIMESTAMP(3),
"revokedReason" TEXT,
CONSTRAINT "AppSession_pkey" PRIMARY KEY ("id")
);
CREATE UNIQUE INDEX "AppSession_jti_key" ON "AppSession"("jti");
CREATE INDEX "AppSession_subjectId_idx" ON "AppSession"("subjectId");
CREATE INDEX "AppSession_iamSessionId_idx" ON "AppSession"("iamSessionId");
CREATE INDEX "AppSession_iamSub_idx" ON "AppSession"("iamSub");
CREATE INDEX "AppSession_expiresAt_idx" ON "AppSession"("expiresAt");