Phase9
Some checks failed
CI / Node — lint, typecheck, test, build (push) Failing after 9s
CI / Go — node-agent tests (push) Failing after 8s
CI / Go — edge-gateway build (push) Successful in 17s

This commit is contained in:
smueller
2026-06-26 13:46:25 +02:00
parent b335f6a497
commit ed8334328e
49 changed files with 2219 additions and 16 deletions

View File

@@ -0,0 +1,94 @@
-- Phase 9: WHMCS integration and billing suspension
CREATE TYPE "WhmcsServiceStatus" AS ENUM ('PENDING', 'ACTIVE', 'SUSPENDED', 'TERMINATED');
CREATE TYPE "IntegrationOperationStatus" AS ENUM ('COMPLETED', 'FAILED');
ALTER TABLE "game_servers"
ADD COLUMN IF NOT EXISTS "billingSuspendedAt" TIMESTAMPTZ(3),
ADD COLUMN IF NOT EXISTS "billingSuspendReason" TEXT;
CREATE TABLE IF NOT EXISTS "whmcs_installations" (
"id" TEXT NOT NULL,
"integrationId" TEXT NOT NULL,
"name" TEXT NOT NULL,
"apiSecret" TEXT NOT NULL,
"isActive" BOOLEAN NOT NULL DEFAULT true,
"metadata" JSONB,
"createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMPTZ(3) NOT NULL,
CONSTRAINT "whmcs_installations_pkey" PRIMARY KEY ("id")
);
CREATE UNIQUE INDEX IF NOT EXISTS "whmcs_installations_integrationId_key"
ON "whmcs_installations"("integrationId");
CREATE TABLE IF NOT EXISTS "whmcs_client_links" (
"id" TEXT NOT NULL,
"installationId" TEXT NOT NULL,
"externalClientId" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMPTZ(3) NOT NULL,
CONSTRAINT "whmcs_client_links_pkey" PRIMARY KEY ("id")
);
CREATE UNIQUE INDEX IF NOT EXISTS "whmcs_client_links_userId_key" ON "whmcs_client_links"("userId");
CREATE UNIQUE INDEX IF NOT EXISTS "whmcs_client_links_installationId_externalClientId_key"
ON "whmcs_client_links"("installationId", "externalClientId");
CREATE TABLE IF NOT EXISTS "whmcs_service_links" (
"id" TEXT NOT NULL,
"installationId" TEXT NOT NULL,
"externalServiceId" TEXT NOT NULL,
"serverId" TEXT NOT NULL,
"externalProductId" TEXT,
"status" "WhmcsServiceStatus" NOT NULL DEFAULT 'PENDING',
"suspendedAt" TIMESTAMPTZ(3),
"terminatedAt" TIMESTAMPTZ(3),
"metadata" JSONB,
"createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMPTZ(3) NOT NULL,
CONSTRAINT "whmcs_service_links_pkey" PRIMARY KEY ("id")
);
CREATE UNIQUE INDEX IF NOT EXISTS "whmcs_service_links_serverId_key" ON "whmcs_service_links"("serverId");
CREATE UNIQUE INDEX IF NOT EXISTS "whmcs_service_links_installationId_externalServiceId_key"
ON "whmcs_service_links"("installationId", "externalServiceId");
CREATE INDEX IF NOT EXISTS "whmcs_service_links_installationId_status_idx"
ON "whmcs_service_links"("installationId", "status");
CREATE TABLE IF NOT EXISTS "integration_operations" (
"id" TEXT NOT NULL,
"installationId" TEXT NOT NULL,
"idempotencyKey" TEXT NOT NULL,
"operation" TEXT NOT NULL,
"externalRef" TEXT,
"status" "IntegrationOperationStatus" NOT NULL DEFAULT 'COMPLETED',
"result" JSONB,
"error" TEXT,
"createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "integration_operations_pkey" PRIMARY KEY ("id")
);
CREATE UNIQUE INDEX IF NOT EXISTS "integration_operations_idempotencyKey_key"
ON "integration_operations"("idempotencyKey");
CREATE INDEX IF NOT EXISTS "integration_operations_installationId_createdAt_idx"
ON "integration_operations"("installationId", "createdAt");
ALTER TABLE "whmcs_client_links"
ADD CONSTRAINT "whmcs_client_links_installationId_fkey"
FOREIGN KEY ("installationId") REFERENCES "whmcs_installations"("id") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "whmcs_client_links"
ADD CONSTRAINT "whmcs_client_links_userId_fkey"
FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "whmcs_service_links"
ADD CONSTRAINT "whmcs_service_links_installationId_fkey"
FOREIGN KEY ("installationId") REFERENCES "whmcs_installations"("id") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "whmcs_service_links"
ADD CONSTRAINT "whmcs_service_links_serverId_fkey"
FOREIGN KEY ("serverId") REFERENCES "game_servers"("id") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "integration_operations"
ADD CONSTRAINT "integration_operations_installationId_fkey"
FOREIGN KEY ("installationId") REFERENCES "whmcs_installations"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -135,6 +135,18 @@ enum DnsRecordStatus {
REMOVED
}
enum WhmcsServiceStatus {
PENDING
ACTIVE
SUSPENDED
TERMINATED
}
enum IntegrationOperationStatus {
COMPLETED
FAILED
}
model User {
id String @id @default(uuid())
email String @unique
@@ -156,6 +168,7 @@ model User {
passwordResetTokens PasswordResetToken[]
totpCredential TotpCredential?
creditWallet CreditWallet?
whmcsClientLink WhmcsClientLink?
@@map("users")
}
@@ -300,6 +313,8 @@ model GameServer {
lastMeteredAt DateTime? @db.Timestamptz(3)
joinSlug String? @unique
joinToStartEnabled Boolean @default(true)
billingSuspendedAt DateTime? @db.Timestamptz(3)
billingSuspendReason String?
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime @updatedAt @db.Timestamptz(3)
@@ -316,6 +331,7 @@ model GameServer {
startQueueEntry ServerStartQueueEntry?
usageRecords UsageRecord[]
dnsRecords ServerDnsRecord[]
whmcsServiceLink WhmcsServiceLink?
@@index([userId])
@@index([nodeId])
@@ -684,3 +700,73 @@ model ServerDnsRecord {
@@index([fqdn])
@@map("server_dns_records")
}
model WhmcsInstallation {
id String @id @default(uuid())
integrationId String @unique
name String
apiSecret String
isActive Boolean @default(true)
metadata Json?
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime @updatedAt @db.Timestamptz(3)
clientLinks WhmcsClientLink[]
serviceLinks WhmcsServiceLink[]
operations IntegrationOperation[]
@@map("whmcs_installations")
}
model WhmcsClientLink {
id String @id @default(uuid())
installationId String
externalClientId String
userId String @unique
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime @updatedAt @db.Timestamptz(3)
installation WhmcsInstallation @relation(fields: [installationId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([installationId, externalClientId])
@@map("whmcs_client_links")
}
model WhmcsServiceLink {
id String @id @default(uuid())
installationId String
externalServiceId String
serverId String @unique
externalProductId String?
status WhmcsServiceStatus @default(PENDING)
suspendedAt DateTime? @db.Timestamptz(3)
terminatedAt DateTime? @db.Timestamptz(3)
metadata Json?
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime @updatedAt @db.Timestamptz(3)
installation WhmcsInstallation @relation(fields: [installationId], references: [id], onDelete: Cascade)
server GameServer @relation(fields: [serverId], references: [id], onDelete: Cascade)
@@unique([installationId, externalServiceId])
@@index([installationId, status])
@@map("whmcs_service_links")
}
model IntegrationOperation {
id String @id @default(uuid())
installationId String
idempotencyKey String @unique
operation String
externalRef String?
status IntegrationOperationStatus @default(COMPLETED)
result Json?
error String?
createdAt DateTime @default(now()) @db.Timestamptz(3)
installation WhmcsInstallation @relation(fields: [installationId], references: [id], onDelete: Cascade)
@@index([installationId, createdAt])
@@map("integration_operations")
}

View File

@@ -14,6 +14,11 @@ export const DEV_NODE_ENROLLMENT_TOKEN =
export const DEV_NODE_2_ENROLLMENT_TOKEN =
'local-dev-node2-enrollment-token-32ch';
export const DEV_WHMCS_INTEGRATION_ID = 'local-dev-whmcs';
export const DEV_WHMCS_API_SECRET =
'local-dev-whmcs-api-secret-32chars-minimum';
async function main(): Promise<void> {
const prisma = new PrismaClient();
@@ -93,12 +98,28 @@ async function main(): Promise<void> {
},
});
const whmcsInstallation = await prisma.whmcsInstallation.upsert({
where: { integrationId: DEV_WHMCS_INTEGRATION_ID },
create: {
integrationId: DEV_WHMCS_INTEGRATION_ID,
name: 'Local Development',
apiSecret: DEV_WHMCS_API_SECRET,
isActive: true,
},
update: {
apiSecret: DEV_WHMCS_API_SECRET,
isActive: true,
},
});
console.log('Seed complete:');
console.log(` Plan Free: ${freePlan.id}`);
console.log(` Dev node: ${devNode.id} (${devNode.name})`);
console.log(` Dev node 2: ${devNode2.id} (${devNode2.name})`);
console.log(` Enrollment token (set NODE_TOKEN): ${DEV_NODE_ENROLLMENT_TOKEN}`);
console.log(` Node 2 enrollment token: ${DEV_NODE_2_ENROLLMENT_TOKEN}`);
console.log(` WHMCS integration: ${whmcsInstallation.integrationId}`);
console.log(` WHMCS API secret: ${DEV_WHMCS_API_SECRET}`);
} finally {
await prisma.$disconnect();
}

View File

@@ -24,6 +24,10 @@ export type {
CreditWallet,
CreditTransaction,
UsageRecord,
WhmcsInstallation,
WhmcsClientLink,
WhmcsServiceLink,
IntegrationOperation,
Plan,
FeatureFlag,
SystemSetting,

File diff suppressed because one or more lines are too long