@naisys/supervisor-database 3.0.0-beta.10
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/dist/dbConfig.js +9 -0
- package/dist/generated/prisma/browser.js +17 -0
- package/dist/generated/prisma/client.js +34 -0
- package/dist/generated/prisma/commonInputTypes.js +10 -0
- package/dist/generated/prisma/enums.js +18 -0
- package/dist/generated/prisma/internal/class.js +49 -0
- package/dist/generated/prisma/internal/prismaNamespace.js +118 -0
- package/dist/generated/prisma/internal/prismaNamespaceBrowser.js +89 -0
- package/dist/generated/prisma/models/SchemaVersion.js +1 -0
- package/dist/generated/prisma/models/Session.js +1 -0
- package/dist/generated/prisma/models/User.js +1 -0
- package/dist/generated/prisma/models/UserPermission.js +1 -0
- package/dist/generated/prisma/models.js +1 -0
- package/dist/index.js +10 -0
- package/dist/migrationHelper.js +13 -0
- package/dist/prismaClient.js +21 -0
- package/dist/sessionService.js +208 -0
- package/package.json +43 -0
- package/prisma/migrations/20260219193117_init/migration.sql +36 -0
- package/prisma/migrations/20260225045447_add_manage_hosts_permission/migration.sql +1 -0
- package/prisma/migrations/20260308000000_multi_session/migration.sql +22 -0
- package/prisma/migrations/20260309000000_add_user_api_key/migration.sql +5 -0
- package/prisma/migrations/migration_lock.toml +3 -0
- package/prisma/schema.prisma +66 -0
- package/prisma.config.ts +18 -0
package/dist/dbConfig.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { join } from "path";
|
|
2
|
+
export function supervisorDbPath() {
|
|
3
|
+
return join(process.env.NAISYS_FOLDER || "", "database", "supervisor.db");
|
|
4
|
+
}
|
|
5
|
+
export function supervisorDbUrl() {
|
|
6
|
+
return "file:" + supervisorDbPath();
|
|
7
|
+
}
|
|
8
|
+
/** We run migration scripts if this is greater than what's in the schema_version table */
|
|
9
|
+
export const SUPERVISOR_DB_VERSION = 8;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* !!! This is code generated by Prisma. Do not edit directly. !!! */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// biome-ignore-all lint: generated file
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
/*
|
|
6
|
+
* This file should be your main import to use Prisma-related types and utilities in a browser.
|
|
7
|
+
* Use it to get access to models, enums, and input types.
|
|
8
|
+
*
|
|
9
|
+
* This file does not contain a `PrismaClient` class, nor several other helpers that are intended as server-side only.
|
|
10
|
+
* See `client.ts` for the standard, server-side entry point.
|
|
11
|
+
*
|
|
12
|
+
* 🟢 You can import this file directly.
|
|
13
|
+
*/
|
|
14
|
+
import * as Prisma from './internal/prismaNamespaceBrowser.js';
|
|
15
|
+
export { Prisma };
|
|
16
|
+
export * as $Enums from './enums.js';
|
|
17
|
+
export * from './enums.js';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/* !!! This is code generated by Prisma. Do not edit directly. !!! */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// biome-ignore-all lint: generated file
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
/*
|
|
6
|
+
* This file should be your main import to use Prisma. Through it you get access to all the models, enums, and input types.
|
|
7
|
+
* If you're looking for something you can import in the client-side of your application, please refer to the `browser.ts` file instead.
|
|
8
|
+
*
|
|
9
|
+
* 🟢 You can import this file directly.
|
|
10
|
+
*/
|
|
11
|
+
import * as path from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
globalThis['__dirname'] = path.dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
import * as $Class from "./internal/class.js";
|
|
15
|
+
import * as Prisma from "./internal/prismaNamespace.js";
|
|
16
|
+
export * as $Enums from './enums.js';
|
|
17
|
+
export * from "./enums.js";
|
|
18
|
+
/**
|
|
19
|
+
* ## Prisma Client
|
|
20
|
+
*
|
|
21
|
+
* Type-safe database client for TypeScript
|
|
22
|
+
* @example
|
|
23
|
+
* ```
|
|
24
|
+
* const prisma = new PrismaClient({
|
|
25
|
+
* adapter: new PrismaPg({ connectionString: process.env.DATABASE_URL })
|
|
26
|
+
* })
|
|
27
|
+
* // Fetch zero or more Users
|
|
28
|
+
* const users = await prisma.user.findMany()
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* Read more in our [docs](https://pris.ly/d/client).
|
|
32
|
+
*/
|
|
33
|
+
export const PrismaClient = $Class.getPrismaClientClass();
|
|
34
|
+
export { Prisma };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* !!! This is code generated by Prisma. Do not edit directly. !!! */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// biome-ignore-all lint: generated file
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
/*
|
|
6
|
+
* This file exports various common sort, input & filter types that are not directly linked to a particular model.
|
|
7
|
+
*
|
|
8
|
+
* 🟢 You can import this file directly.
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* !!! This is code generated by Prisma. Do not edit directly. !!! */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// biome-ignore-all lint: generated file
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
/*
|
|
6
|
+
* This file exports all enum related types from the schema.
|
|
7
|
+
*
|
|
8
|
+
* 🟢 You can import this file directly.
|
|
9
|
+
*/
|
|
10
|
+
export const Permission = {
|
|
11
|
+
supervisor_admin: 'supervisor_admin',
|
|
12
|
+
manage_agents: 'manage_agents',
|
|
13
|
+
manage_hosts: 'manage_hosts',
|
|
14
|
+
agent_communication: 'agent_communication',
|
|
15
|
+
manage_models: 'manage_models',
|
|
16
|
+
manage_variables: 'manage_variables',
|
|
17
|
+
view_run_logs: 'view_run_logs'
|
|
18
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/* !!! This is code generated by Prisma. Do not edit directly. !!! */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// biome-ignore-all lint: generated file
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
/*
|
|
6
|
+
* WARNING: This is an internal file that is subject to change!
|
|
7
|
+
*
|
|
8
|
+
* 🛑 Under no circumstances should you import this file directly! 🛑
|
|
9
|
+
*
|
|
10
|
+
* Please import the `PrismaClient` class from the `client.ts` file instead.
|
|
11
|
+
*/
|
|
12
|
+
import * as runtime from "@prisma/client/runtime/client";
|
|
13
|
+
const config = {
|
|
14
|
+
"previewFeatures": [],
|
|
15
|
+
"clientVersion": "7.6.0",
|
|
16
|
+
"engineVersion": "75cbdc1eb7150937890ad5465d861175c6624711",
|
|
17
|
+
"activeProvider": "sqlite",
|
|
18
|
+
"inlineSchema": "datasource db {\n provider = \"sqlite\"\n}\n\ngenerator client {\n provider = \"prisma-client\"\n output = \"../src/generated/prisma\"\n}\n\nenum Permission {\n supervisor_admin\n manage_agents\n manage_hosts\n agent_communication\n manage_models\n manage_variables\n view_run_logs\n}\n\nmodel User {\n id Int @id @default(autoincrement())\n username String @unique\n uuid String @default(\"\")\n isAgent Boolean @default(false) @map(\"is_agent\")\n passwordHash String @default(\"\") @map(\"password_hash\")\n createdAt DateTime @default(now()) @map(\"created_at\")\n apiKey String? @unique @map(\"api_key\")\n updatedAt DateTime @updatedAt @map(\"updated_at\")\n permissions UserPermission[] @relation(\"UserPermissions\")\n grantedPermissions UserPermission[] @relation(\"GrantedByPermissions\")\n sessions Session[]\n\n @@map(\"users\")\n}\n\nmodel Session {\n id Int @id @default(autoincrement())\n userId Int @map(\"user_id\")\n tokenHash String @unique @map(\"token_hash\")\n expiresAt DateTime @map(\"expires_at\")\n createdAt DateTime @default(now()) @map(\"created_at\")\n user User @relation(fields: [userId], references: [id], onDelete: Cascade)\n\n @@map(\"sessions\")\n}\n\nmodel UserPermission {\n id Int @id @default(autoincrement())\n userId Int @map(\"user_id\")\n permission Permission\n grantedAt DateTime @default(now()) @map(\"granted_at\")\n grantedBy Int? @map(\"granted_by\")\n user User @relation(\"UserPermissions\", fields: [userId], references: [id], onDelete: Cascade)\n grantedByUser User? @relation(\"GrantedByPermissions\", fields: [grantedBy], references: [id])\n\n @@unique([userId, permission])\n @@map(\"user_permissions\")\n}\n\nmodel SchemaVersion {\n id Int @id @default(1)\n version Int\n updated String\n\n @@map(\"schema_version\")\n}\n",
|
|
19
|
+
"runtimeDataModel": {
|
|
20
|
+
"models": {},
|
|
21
|
+
"enums": {},
|
|
22
|
+
"types": {}
|
|
23
|
+
},
|
|
24
|
+
"parameterizationSchema": {
|
|
25
|
+
"strings": [],
|
|
26
|
+
"graph": ""
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
config.runtimeDataModel = JSON.parse("{\"models\":{\"User\":{\"fields\":[{\"name\":\"id\",\"kind\":\"scalar\",\"type\":\"Int\"},{\"name\":\"username\",\"kind\":\"scalar\",\"type\":\"String\"},{\"name\":\"uuid\",\"kind\":\"scalar\",\"type\":\"String\"},{\"name\":\"isAgent\",\"kind\":\"scalar\",\"type\":\"Boolean\",\"dbName\":\"is_agent\"},{\"name\":\"passwordHash\",\"kind\":\"scalar\",\"type\":\"String\",\"dbName\":\"password_hash\"},{\"name\":\"createdAt\",\"kind\":\"scalar\",\"type\":\"DateTime\",\"dbName\":\"created_at\"},{\"name\":\"apiKey\",\"kind\":\"scalar\",\"type\":\"String\",\"dbName\":\"api_key\"},{\"name\":\"updatedAt\",\"kind\":\"scalar\",\"type\":\"DateTime\",\"dbName\":\"updated_at\"},{\"name\":\"permissions\",\"kind\":\"object\",\"type\":\"UserPermission\",\"relationName\":\"UserPermissions\"},{\"name\":\"grantedPermissions\",\"kind\":\"object\",\"type\":\"UserPermission\",\"relationName\":\"GrantedByPermissions\"},{\"name\":\"sessions\",\"kind\":\"object\",\"type\":\"Session\",\"relationName\":\"SessionToUser\"}],\"dbName\":\"users\"},\"Session\":{\"fields\":[{\"name\":\"id\",\"kind\":\"scalar\",\"type\":\"Int\"},{\"name\":\"userId\",\"kind\":\"scalar\",\"type\":\"Int\",\"dbName\":\"user_id\"},{\"name\":\"tokenHash\",\"kind\":\"scalar\",\"type\":\"String\",\"dbName\":\"token_hash\"},{\"name\":\"expiresAt\",\"kind\":\"scalar\",\"type\":\"DateTime\",\"dbName\":\"expires_at\"},{\"name\":\"createdAt\",\"kind\":\"scalar\",\"type\":\"DateTime\",\"dbName\":\"created_at\"},{\"name\":\"user\",\"kind\":\"object\",\"type\":\"User\",\"relationName\":\"SessionToUser\"}],\"dbName\":\"sessions\"},\"UserPermission\":{\"fields\":[{\"name\":\"id\",\"kind\":\"scalar\",\"type\":\"Int\"},{\"name\":\"userId\",\"kind\":\"scalar\",\"type\":\"Int\",\"dbName\":\"user_id\"},{\"name\":\"permission\",\"kind\":\"enum\",\"type\":\"Permission\"},{\"name\":\"grantedAt\",\"kind\":\"scalar\",\"type\":\"DateTime\",\"dbName\":\"granted_at\"},{\"name\":\"grantedBy\",\"kind\":\"scalar\",\"type\":\"Int\",\"dbName\":\"granted_by\"},{\"name\":\"user\",\"kind\":\"object\",\"type\":\"User\",\"relationName\":\"UserPermissions\"},{\"name\":\"grantedByUser\",\"kind\":\"object\",\"type\":\"User\",\"relationName\":\"GrantedByPermissions\"}],\"dbName\":\"user_permissions\"},\"SchemaVersion\":{\"fields\":[{\"name\":\"id\",\"kind\":\"scalar\",\"type\":\"Int\"},{\"name\":\"version\",\"kind\":\"scalar\",\"type\":\"Int\"},{\"name\":\"updated\",\"kind\":\"scalar\",\"type\":\"String\"}],\"dbName\":\"schema_version\"}},\"enums\":{},\"types\":{}}");
|
|
30
|
+
config.parameterizationSchema = {
|
|
31
|
+
strings: JSON.parse("[\"where\",\"orderBy\",\"cursor\",\"user\",\"grantedByUser\",\"permissions\",\"grantedPermissions\",\"sessions\",\"_count\",\"User.findUnique\",\"User.findUniqueOrThrow\",\"User.findFirst\",\"User.findFirstOrThrow\",\"User.findMany\",\"data\",\"User.createOne\",\"User.createMany\",\"User.createManyAndReturn\",\"User.updateOne\",\"User.updateMany\",\"User.updateManyAndReturn\",\"create\",\"update\",\"User.upsertOne\",\"User.deleteOne\",\"User.deleteMany\",\"having\",\"_avg\",\"_sum\",\"_min\",\"_max\",\"User.groupBy\",\"User.aggregate\",\"Session.findUnique\",\"Session.findUniqueOrThrow\",\"Session.findFirst\",\"Session.findFirstOrThrow\",\"Session.findMany\",\"Session.createOne\",\"Session.createMany\",\"Session.createManyAndReturn\",\"Session.updateOne\",\"Session.updateMany\",\"Session.updateManyAndReturn\",\"Session.upsertOne\",\"Session.deleteOne\",\"Session.deleteMany\",\"Session.groupBy\",\"Session.aggregate\",\"UserPermission.findUnique\",\"UserPermission.findUniqueOrThrow\",\"UserPermission.findFirst\",\"UserPermission.findFirstOrThrow\",\"UserPermission.findMany\",\"UserPermission.createOne\",\"UserPermission.createMany\",\"UserPermission.createManyAndReturn\",\"UserPermission.updateOne\",\"UserPermission.updateMany\",\"UserPermission.updateManyAndReturn\",\"UserPermission.upsertOne\",\"UserPermission.deleteOne\",\"UserPermission.deleteMany\",\"UserPermission.groupBy\",\"UserPermission.aggregate\",\"SchemaVersion.findUnique\",\"SchemaVersion.findUniqueOrThrow\",\"SchemaVersion.findFirst\",\"SchemaVersion.findFirstOrThrow\",\"SchemaVersion.findMany\",\"SchemaVersion.createOne\",\"SchemaVersion.createMany\",\"SchemaVersion.createManyAndReturn\",\"SchemaVersion.updateOne\",\"SchemaVersion.updateMany\",\"SchemaVersion.updateManyAndReturn\",\"SchemaVersion.upsertOne\",\"SchemaVersion.deleteOne\",\"SchemaVersion.deleteMany\",\"SchemaVersion.groupBy\",\"SchemaVersion.aggregate\",\"AND\",\"OR\",\"NOT\",\"id\",\"version\",\"updated\",\"equals\",\"in\",\"notIn\",\"lt\",\"lte\",\"gt\",\"gte\",\"contains\",\"startsWith\",\"endsWith\",\"not\",\"userId\",\"Permission\",\"permission\",\"grantedAt\",\"grantedBy\",\"tokenHash\",\"expiresAt\",\"createdAt\",\"username\",\"uuid\",\"isAgent\",\"passwordHash\",\"apiKey\",\"updatedAt\",\"every\",\"some\",\"none\",\"userId_permission\",\"is\",\"isNot\",\"connectOrCreate\",\"upsert\",\"createMany\",\"set\",\"disconnect\",\"delete\",\"connect\",\"updateMany\",\"deleteMany\",\"increment\",\"decrement\",\"multiply\",\"divide\"]"),
|
|
32
|
+
graph: "9gEqQA4FAACSAQAgBgAAkgEAIAcAAJMBACBRAACPAQAwUgAABwAQUwAAjwEAMFQCAAAAAWlAAI0BACFqAQAAAAFrAQB4ACFsIACQAQAhbQEAeAAhbgEAAAABb0AAjQEAIQEAAAABACAKAwAAjgEAIAQAAJgBACBRAACVAQAwUgAAAwAQUwAAlQEAMFQCAHcAIWICAHcAIWQAAJYBZCJlQACNAQAhZgIAlwEAIQMDAADkAQAgBAAA5AEAIGYAAKABACALAwAAjgEAIAQAAJgBACBRAACVAQAwUgAAAwAQUwAAlQEAMFQCAAAAAWICAHcAIWQAAJYBZCJlQACNAQAhZgIAlwEAIXMAAJQBACADAAAAAwAgAQAABAAwAgAABQAgDgUAAJIBACAGAACSAQAgBwAAkwEAIFEAAI8BADBSAAAHABBTAACPAQAwVAIAdwAhaUAAjQEAIWoBAHgAIWsBAHgAIWwgAJABACFtAQB4ACFuAQCRAQAhb0AAjQEAIQEAAAAHACADAAAAAwAgAQAABAAwAgAABQAgCQMAAI4BACBRAACMAQAwUgAACgAQUwAAjAEAMFQCAHcAIWICAHcAIWcBAHgAIWhAAI0BACFpQACNAQAhAQMAAOQBACAJAwAAjgEAIFEAAIwBADBSAAAKABBTAACMAQAwVAIAAAABYgIAdwAhZwEAAAABaEAAjQEAIWlAAI0BACEDAAAACgAgAQAACwAwAgAADAAgAQAAAAMAIAEAAAADACABAAAACgAgAQAAAAEAIAQFAADiAQAgBgAA4gEAIAcAAOMBACBuAACgAQAgAwAAAAcAIAEAABIAMAIAAAEAIAMAAAAHACABAAASADACAAABACADAAAABwAgAQAAEgAwAgAAAQAgCwUAAN8BACAGAADgAQAgBwAA4QEAIFQCAAAAAWlAAAAAAWoBAAAAAWsBAAAAAWwgAAAAAW0BAAAAAW4BAAAAAW9AAAAAAQEOA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4BACFpQACnAQAhagEAnwEAIWsBAJ8BACFsIAC5AQAhbQEAnwEAIW4BALoBACFvQACnAQAhBAUGAgYJAgcNAwgABAIDAAEECAEBAwABAwUOAAYPAAcQAAAAAAUIAAkbAAocAAsdAAweAA0AAAAAAAUIAAkbAAocAAsdAAweAA0BAwABAQMAAQUIABIbABMcABQdABUeABYAAAAAAAUIABIbABMcABQdABUeABYCAwABBEcBAgMAAQRNAQUIABsbABwcAB0dAB4eAB8AAAAAAAUIABsbABwcAB0dAB4eAB8AAAAFCAAlGwAmHAAnHQAoHgApAAAAAAAFCAAlGwAmHAAnHQAoHgApCQIBChEBCxMBDBQBDRUBDxcBEBkFERoGEhwBEx4FFB8HFyABGCEBGSIFHyUIICYOIScDIigDIykDJCoDJSsDJi0DJy8FKDAPKTIDKjQFKzUQLDYDLTcDLjgFLzsRMDwXMT0CMj4CMz8CNEACNUECNkMCN0UFOEYYOUkCOksFO0wZPE4CPU8CPlAFP1MaQFQgQVYhQlchQ1ohRFshRVwhRl4hR2AFSGEiSWMhSmUFS2YjTGchTWghTmkFT2wkUG0q"
|
|
33
|
+
};
|
|
34
|
+
async function decodeBase64AsWasm(wasmBase64) {
|
|
35
|
+
const { Buffer } = await import('node:buffer');
|
|
36
|
+
const wasmArray = Buffer.from(wasmBase64, 'base64');
|
|
37
|
+
return new WebAssembly.Module(wasmArray);
|
|
38
|
+
}
|
|
39
|
+
config.compilerWasm = {
|
|
40
|
+
getRuntime: async () => await import("@prisma/client/runtime/query_compiler_fast_bg.sqlite.mjs"),
|
|
41
|
+
getQueryCompilerWasmModule: async () => {
|
|
42
|
+
const { wasm } = await import("@prisma/client/runtime/query_compiler_fast_bg.sqlite.wasm-base64.mjs");
|
|
43
|
+
return await decodeBase64AsWasm(wasm);
|
|
44
|
+
},
|
|
45
|
+
importName: "./query_compiler_fast_bg.js"
|
|
46
|
+
};
|
|
47
|
+
export function getPrismaClientClass() {
|
|
48
|
+
return runtime.getPrismaClient(config);
|
|
49
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/* !!! This is code generated by Prisma. Do not edit directly. !!! */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// biome-ignore-all lint: generated file
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
/*
|
|
6
|
+
* WARNING: This is an internal file that is subject to change!
|
|
7
|
+
*
|
|
8
|
+
* 🛑 Under no circumstances should you import this file directly! 🛑
|
|
9
|
+
*
|
|
10
|
+
* All exports from this file are wrapped under a `Prisma` namespace object in the client.ts file.
|
|
11
|
+
* While this enables partial backward compatibility, it is not part of the stable public API.
|
|
12
|
+
*
|
|
13
|
+
* If you are looking for your Models, Enums, and Input Types, please import them from the respective
|
|
14
|
+
* model files in the `model` directory!
|
|
15
|
+
*/
|
|
16
|
+
import * as runtime from "@prisma/client/runtime/client";
|
|
17
|
+
/**
|
|
18
|
+
* Prisma Errors
|
|
19
|
+
*/
|
|
20
|
+
export const PrismaClientKnownRequestError = runtime.PrismaClientKnownRequestError;
|
|
21
|
+
export const PrismaClientUnknownRequestError = runtime.PrismaClientUnknownRequestError;
|
|
22
|
+
export const PrismaClientRustPanicError = runtime.PrismaClientRustPanicError;
|
|
23
|
+
export const PrismaClientInitializationError = runtime.PrismaClientInitializationError;
|
|
24
|
+
export const PrismaClientValidationError = runtime.PrismaClientValidationError;
|
|
25
|
+
/**
|
|
26
|
+
* Re-export of sql-template-tag
|
|
27
|
+
*/
|
|
28
|
+
export const sql = runtime.sqltag;
|
|
29
|
+
export const empty = runtime.empty;
|
|
30
|
+
export const join = runtime.join;
|
|
31
|
+
export const raw = runtime.raw;
|
|
32
|
+
export const Sql = runtime.Sql;
|
|
33
|
+
/**
|
|
34
|
+
* Decimal.js
|
|
35
|
+
*/
|
|
36
|
+
export const Decimal = runtime.Decimal;
|
|
37
|
+
export const getExtensionContext = runtime.Extensions.getExtensionContext;
|
|
38
|
+
/**
|
|
39
|
+
* Prisma Client JS version: 7.6.0
|
|
40
|
+
* Query Engine version: 75cbdc1eb7150937890ad5465d861175c6624711
|
|
41
|
+
*/
|
|
42
|
+
export const prismaVersion = {
|
|
43
|
+
client: "7.6.0",
|
|
44
|
+
engine: "75cbdc1eb7150937890ad5465d861175c6624711"
|
|
45
|
+
};
|
|
46
|
+
export const NullTypes = {
|
|
47
|
+
DbNull: runtime.NullTypes.DbNull,
|
|
48
|
+
JsonNull: runtime.NullTypes.JsonNull,
|
|
49
|
+
AnyNull: runtime.NullTypes.AnyNull,
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Helper for filtering JSON entries that have `null` on the database (empty on the db)
|
|
53
|
+
*
|
|
54
|
+
* @see https://www.prisma.io/docs/concepts/components/prisma-client/working-with-fields/working-with-json-fields#filtering-on-a-json-field
|
|
55
|
+
*/
|
|
56
|
+
export const DbNull = runtime.DbNull;
|
|
57
|
+
/**
|
|
58
|
+
* Helper for filtering JSON entries that have JSON `null` values (not empty on the db)
|
|
59
|
+
*
|
|
60
|
+
* @see https://www.prisma.io/docs/concepts/components/prisma-client/working-with-fields/working-with-json-fields#filtering-on-a-json-field
|
|
61
|
+
*/
|
|
62
|
+
export const JsonNull = runtime.JsonNull;
|
|
63
|
+
/**
|
|
64
|
+
* Helper for filtering JSON entries that are `Prisma.DbNull` or `Prisma.JsonNull`
|
|
65
|
+
*
|
|
66
|
+
* @see https://www.prisma.io/docs/concepts/components/prisma-client/working-with-fields/working-with-json-fields#filtering-on-a-json-field
|
|
67
|
+
*/
|
|
68
|
+
export const AnyNull = runtime.AnyNull;
|
|
69
|
+
export const ModelName = {
|
|
70
|
+
User: 'User',
|
|
71
|
+
Session: 'Session',
|
|
72
|
+
UserPermission: 'UserPermission',
|
|
73
|
+
SchemaVersion: 'SchemaVersion'
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Enums
|
|
77
|
+
*/
|
|
78
|
+
export const TransactionIsolationLevel = runtime.makeStrictEnum({
|
|
79
|
+
Serializable: 'Serializable'
|
|
80
|
+
});
|
|
81
|
+
export const UserScalarFieldEnum = {
|
|
82
|
+
id: 'id',
|
|
83
|
+
username: 'username',
|
|
84
|
+
uuid: 'uuid',
|
|
85
|
+
isAgent: 'isAgent',
|
|
86
|
+
passwordHash: 'passwordHash',
|
|
87
|
+
createdAt: 'createdAt',
|
|
88
|
+
apiKey: 'apiKey',
|
|
89
|
+
updatedAt: 'updatedAt'
|
|
90
|
+
};
|
|
91
|
+
export const SessionScalarFieldEnum = {
|
|
92
|
+
id: 'id',
|
|
93
|
+
userId: 'userId',
|
|
94
|
+
tokenHash: 'tokenHash',
|
|
95
|
+
expiresAt: 'expiresAt',
|
|
96
|
+
createdAt: 'createdAt'
|
|
97
|
+
};
|
|
98
|
+
export const UserPermissionScalarFieldEnum = {
|
|
99
|
+
id: 'id',
|
|
100
|
+
userId: 'userId',
|
|
101
|
+
permission: 'permission',
|
|
102
|
+
grantedAt: 'grantedAt',
|
|
103
|
+
grantedBy: 'grantedBy'
|
|
104
|
+
};
|
|
105
|
+
export const SchemaVersionScalarFieldEnum = {
|
|
106
|
+
id: 'id',
|
|
107
|
+
version: 'version',
|
|
108
|
+
updated: 'updated'
|
|
109
|
+
};
|
|
110
|
+
export const SortOrder = {
|
|
111
|
+
asc: 'asc',
|
|
112
|
+
desc: 'desc'
|
|
113
|
+
};
|
|
114
|
+
export const NullsOrder = {
|
|
115
|
+
first: 'first',
|
|
116
|
+
last: 'last'
|
|
117
|
+
};
|
|
118
|
+
export const defineExtension = runtime.Extensions.defineExtension;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/* !!! This is code generated by Prisma. Do not edit directly. !!! */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// biome-ignore-all lint: generated file
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
/*
|
|
6
|
+
* WARNING: This is an internal file that is subject to change!
|
|
7
|
+
*
|
|
8
|
+
* 🛑 Under no circumstances should you import this file directly! 🛑
|
|
9
|
+
*
|
|
10
|
+
* All exports from this file are wrapped under a `Prisma` namespace object in the browser.ts file.
|
|
11
|
+
* While this enables partial backward compatibility, it is not part of the stable public API.
|
|
12
|
+
*
|
|
13
|
+
* If you are looking for your Models, Enums, and Input Types, please import them from the respective
|
|
14
|
+
* model files in the `model` directory!
|
|
15
|
+
*/
|
|
16
|
+
import * as runtime from "@prisma/client/runtime/index-browser";
|
|
17
|
+
export const Decimal = runtime.Decimal;
|
|
18
|
+
export const NullTypes = {
|
|
19
|
+
DbNull: runtime.NullTypes.DbNull,
|
|
20
|
+
JsonNull: runtime.NullTypes.JsonNull,
|
|
21
|
+
AnyNull: runtime.NullTypes.AnyNull,
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Helper for filtering JSON entries that have `null` on the database (empty on the db)
|
|
25
|
+
*
|
|
26
|
+
* @see https://www.prisma.io/docs/concepts/components/prisma-client/working-with-fields/working-with-json-fields#filtering-on-a-json-field
|
|
27
|
+
*/
|
|
28
|
+
export const DbNull = runtime.DbNull;
|
|
29
|
+
/**
|
|
30
|
+
* Helper for filtering JSON entries that have JSON `null` values (not empty on the db)
|
|
31
|
+
*
|
|
32
|
+
* @see https://www.prisma.io/docs/concepts/components/prisma-client/working-with-fields/working-with-json-fields#filtering-on-a-json-field
|
|
33
|
+
*/
|
|
34
|
+
export const JsonNull = runtime.JsonNull;
|
|
35
|
+
/**
|
|
36
|
+
* Helper for filtering JSON entries that are `Prisma.DbNull` or `Prisma.JsonNull`
|
|
37
|
+
*
|
|
38
|
+
* @see https://www.prisma.io/docs/concepts/components/prisma-client/working-with-fields/working-with-json-fields#filtering-on-a-json-field
|
|
39
|
+
*/
|
|
40
|
+
export const AnyNull = runtime.AnyNull;
|
|
41
|
+
export const ModelName = {
|
|
42
|
+
User: 'User',
|
|
43
|
+
Session: 'Session',
|
|
44
|
+
UserPermission: 'UserPermission',
|
|
45
|
+
SchemaVersion: 'SchemaVersion'
|
|
46
|
+
};
|
|
47
|
+
/*
|
|
48
|
+
* Enums
|
|
49
|
+
*/
|
|
50
|
+
export const TransactionIsolationLevel = runtime.makeStrictEnum({
|
|
51
|
+
Serializable: 'Serializable'
|
|
52
|
+
});
|
|
53
|
+
export const UserScalarFieldEnum = {
|
|
54
|
+
id: 'id',
|
|
55
|
+
username: 'username',
|
|
56
|
+
uuid: 'uuid',
|
|
57
|
+
isAgent: 'isAgent',
|
|
58
|
+
passwordHash: 'passwordHash',
|
|
59
|
+
createdAt: 'createdAt',
|
|
60
|
+
apiKey: 'apiKey',
|
|
61
|
+
updatedAt: 'updatedAt'
|
|
62
|
+
};
|
|
63
|
+
export const SessionScalarFieldEnum = {
|
|
64
|
+
id: 'id',
|
|
65
|
+
userId: 'userId',
|
|
66
|
+
tokenHash: 'tokenHash',
|
|
67
|
+
expiresAt: 'expiresAt',
|
|
68
|
+
createdAt: 'createdAt'
|
|
69
|
+
};
|
|
70
|
+
export const UserPermissionScalarFieldEnum = {
|
|
71
|
+
id: 'id',
|
|
72
|
+
userId: 'userId',
|
|
73
|
+
permission: 'permission',
|
|
74
|
+
grantedAt: 'grantedAt',
|
|
75
|
+
grantedBy: 'grantedBy'
|
|
76
|
+
};
|
|
77
|
+
export const SchemaVersionScalarFieldEnum = {
|
|
78
|
+
id: 'id',
|
|
79
|
+
version: 'version',
|
|
80
|
+
updated: 'updated'
|
|
81
|
+
};
|
|
82
|
+
export const SortOrder = {
|
|
83
|
+
asc: 'asc',
|
|
84
|
+
desc: 'desc'
|
|
85
|
+
};
|
|
86
|
+
export const NullsOrder = {
|
|
87
|
+
first: 'first',
|
|
88
|
+
last: 'last'
|
|
89
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Re-export Database Config
|
|
2
|
+
export { SUPERVISOR_DB_VERSION, supervisorDbPath, supervisorDbUrl, } from "./dbConfig.js";
|
|
3
|
+
// Re-export Prisma client factory
|
|
4
|
+
export { createPrismaClient } from "./prismaClient.js";
|
|
5
|
+
// Re-export Migration Helper
|
|
6
|
+
export { deploySupervisorMigrations } from "./migrationHelper.js";
|
|
7
|
+
export { authenticateAndCreateSession, createSupervisorDatabaseClient, deleteSession, ensureSuperAdmin, findSession, findUserByApiKey, handleResetPassword, lookupUsername, resetPassword, updateUserPassword, } from "./sessionService.js";
|
|
8
|
+
// Re-export Prisma Client and all generated types
|
|
9
|
+
export * from "./generated/prisma/client.js";
|
|
10
|
+
export { PrismaClient } from "./generated/prisma/client.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { deployPrismaMigrations } from "@naisys/common-node";
|
|
2
|
+
import { dirname, join } from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
import { SUPERVISOR_DB_VERSION, supervisorDbPath } from "./dbConfig.js";
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const packageDir = join(dirname(__filename), "..");
|
|
7
|
+
export async function deploySupervisorMigrations() {
|
|
8
|
+
await deployPrismaMigrations({
|
|
9
|
+
packageDir,
|
|
10
|
+
databasePath: supervisorDbPath(),
|
|
11
|
+
expectedVersion: SUPERVISOR_DB_VERSION,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PrismaBetterSqlite3 } from "@prisma/adapter-better-sqlite3";
|
|
2
|
+
import { PrismaClient } from "./generated/prisma/client.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create a Prisma client with a dynamic database path
|
|
5
|
+
* @param databasePath - Absolute path to the SQLite database file
|
|
6
|
+
* @returns Configured PrismaClient instance
|
|
7
|
+
*/
|
|
8
|
+
export async function createPrismaClient(databasePath) {
|
|
9
|
+
const adapter = new PrismaBetterSqlite3({
|
|
10
|
+
url: `file:${databasePath}`,
|
|
11
|
+
timeout: 10_000, // Wait up to 10s for SQLite lock to be released
|
|
12
|
+
});
|
|
13
|
+
const prisma = new PrismaClient({ adapter });
|
|
14
|
+
// Enable WAL mode for better concurrent read/write performance
|
|
15
|
+
await prisma.$executeRawUnsafe("PRAGMA journal_mode=WAL");
|
|
16
|
+
// NORMAL is safe with WAL and avoids an extra fsync per commit
|
|
17
|
+
await prisma.$executeRawUnsafe("PRAGMA synchronous=NORMAL");
|
|
18
|
+
// SQLite doesn't enforce foreign keys by default — must be enabled per connection
|
|
19
|
+
await prisma.$executeRawUnsafe("PRAGMA foreign_keys=ON");
|
|
20
|
+
return prisma;
|
|
21
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { SUPER_ADMIN_USERNAME } from "@naisys/common";
|
|
2
|
+
import { hashToken } from "@naisys/common-node";
|
|
3
|
+
import bcrypt from "bcryptjs";
|
|
4
|
+
import { randomBytes, randomUUID } from "crypto";
|
|
5
|
+
import { existsSync } from "fs";
|
|
6
|
+
import readline from "readline/promises";
|
|
7
|
+
import { supervisorDbPath } from "./dbConfig.js";
|
|
8
|
+
import { createPrismaClient } from "./prismaClient.js";
|
|
9
|
+
const SESSION_DURATION_MS = 30 * 24 * 60 * 60 * 1000; // 30 days
|
|
10
|
+
let supervisorDb = null;
|
|
11
|
+
/**
|
|
12
|
+
* Initialize supervisor sessions by connecting to supervisor.db.
|
|
13
|
+
* Idempotent — returns early if already initialized.
|
|
14
|
+
* No-ops gracefully if NAISYS_FOLDER is unset or the database doesn't exist.
|
|
15
|
+
*/
|
|
16
|
+
export async function createSupervisorDatabaseClient() {
|
|
17
|
+
if (supervisorDb)
|
|
18
|
+
return true;
|
|
19
|
+
const dbPath = supervisorDbPath();
|
|
20
|
+
if (!existsSync(dbPath))
|
|
21
|
+
return false;
|
|
22
|
+
supervisorDb = await createPrismaClient(dbPath);
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Find a session user by session token hash. Returns null if not found or expired.
|
|
27
|
+
*/
|
|
28
|
+
export async function findSession(tokenHash) {
|
|
29
|
+
if (!supervisorDb)
|
|
30
|
+
return null;
|
|
31
|
+
const session = await supervisorDb.session.findUnique({
|
|
32
|
+
where: {
|
|
33
|
+
tokenHash,
|
|
34
|
+
expiresAt: { gt: new Date() },
|
|
35
|
+
},
|
|
36
|
+
include: { user: true },
|
|
37
|
+
});
|
|
38
|
+
if (!session)
|
|
39
|
+
return null;
|
|
40
|
+
return {
|
|
41
|
+
userId: session.user.id,
|
|
42
|
+
username: session.user.username,
|
|
43
|
+
passwordHash: session.user.passwordHash,
|
|
44
|
+
uuid: session.user.uuid,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Look up a session user by username.
|
|
49
|
+
*/
|
|
50
|
+
export async function lookupUsername(username) {
|
|
51
|
+
if (!supervisorDb)
|
|
52
|
+
return null;
|
|
53
|
+
const user = await supervisorDb.user.findUnique({
|
|
54
|
+
where: { username },
|
|
55
|
+
});
|
|
56
|
+
if (!user)
|
|
57
|
+
return null;
|
|
58
|
+
return {
|
|
59
|
+
userId: user.id,
|
|
60
|
+
username: user.username,
|
|
61
|
+
passwordHash: user.passwordHash,
|
|
62
|
+
uuid: user.uuid,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Find a supervisor user by API key. Returns null if not found or DB not initialized.
|
|
67
|
+
*/
|
|
68
|
+
export async function findUserByApiKey(apiKey) {
|
|
69
|
+
if (!supervisorDb)
|
|
70
|
+
return null;
|
|
71
|
+
const user = await supervisorDb.user.findUnique({
|
|
72
|
+
where: { apiKey },
|
|
73
|
+
select: { uuid: true, username: true },
|
|
74
|
+
});
|
|
75
|
+
return user;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Authenticate a user by username/password and create a session.
|
|
79
|
+
* Returns null if credentials are invalid or DB is not initialized.
|
|
80
|
+
*/
|
|
81
|
+
export async function authenticateAndCreateSession(username, password) {
|
|
82
|
+
const user = await lookupUsername(username);
|
|
83
|
+
if (!user)
|
|
84
|
+
return null;
|
|
85
|
+
const valid = await bcrypt.compare(password, user.passwordHash);
|
|
86
|
+
if (!valid)
|
|
87
|
+
return null;
|
|
88
|
+
const token = randomUUID();
|
|
89
|
+
const tokenHash = hashToken(token);
|
|
90
|
+
const expiresAt = new Date(Date.now() + SESSION_DURATION_MS);
|
|
91
|
+
const dbUser = await supervisorDb.user.findUnique({
|
|
92
|
+
where: { username },
|
|
93
|
+
});
|
|
94
|
+
await supervisorDb.session.create({
|
|
95
|
+
data: {
|
|
96
|
+
userId: dbUser.id,
|
|
97
|
+
tokenHash,
|
|
98
|
+
expiresAt,
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
return { token, user, expiresAt };
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Update a user's password hash. No-op if not initialized.
|
|
105
|
+
*/
|
|
106
|
+
export async function updateUserPassword(username, passwordHash) {
|
|
107
|
+
if (!supervisorDb)
|
|
108
|
+
return;
|
|
109
|
+
await supervisorDb.user.update({
|
|
110
|
+
where: { username },
|
|
111
|
+
data: { passwordHash },
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Delete a session by token hash.
|
|
116
|
+
*/
|
|
117
|
+
export async function deleteSession(tokenHash) {
|
|
118
|
+
if (!supervisorDb)
|
|
119
|
+
return;
|
|
120
|
+
await supervisorDb.session.deleteMany({
|
|
121
|
+
where: { tokenHash },
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Ensure a "superadmin" user exists in the supervisor database.
|
|
126
|
+
* If already exists, returns it as-is. Otherwise creates with generated credentials.
|
|
127
|
+
*/
|
|
128
|
+
export async function ensureSuperAdmin() {
|
|
129
|
+
if (!supervisorDb)
|
|
130
|
+
throw new Error("Supervisor DB not initialized");
|
|
131
|
+
const existing = await supervisorDb.user.findUnique({
|
|
132
|
+
where: { username: SUPER_ADMIN_USERNAME },
|
|
133
|
+
});
|
|
134
|
+
if (existing) {
|
|
135
|
+
return {
|
|
136
|
+
created: false,
|
|
137
|
+
user: {
|
|
138
|
+
uuid: existing.uuid,
|
|
139
|
+
username: existing.username,
|
|
140
|
+
passwordHash: existing.passwordHash,
|
|
141
|
+
apiKey: existing.apiKey,
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
const uuid = randomUUID();
|
|
146
|
+
const password = randomUUID().slice(0, 8);
|
|
147
|
+
const passwordHash = await bcrypt.hash(password, 10);
|
|
148
|
+
const apiKey = randomBytes(32).toString("hex");
|
|
149
|
+
const user = await supervisorDb.user.create({
|
|
150
|
+
data: { uuid, username: SUPER_ADMIN_USERNAME, passwordHash, apiKey },
|
|
151
|
+
});
|
|
152
|
+
await supervisorDb.userPermission.create({
|
|
153
|
+
data: { userId: user.id, permission: "supervisor_admin" },
|
|
154
|
+
});
|
|
155
|
+
return {
|
|
156
|
+
created: true,
|
|
157
|
+
generatedPassword: password,
|
|
158
|
+
user: { uuid, username: SUPER_ADMIN_USERNAME, passwordHash, apiKey },
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* CLI entry point for --reset-password. Initializes supervisor sessions,
|
|
163
|
+
* then runs the interactive password reset.
|
|
164
|
+
*/
|
|
165
|
+
export async function handleResetPassword(options) {
|
|
166
|
+
console.log(`NAISYS_FOLDER: ${process.env.NAISYS_FOLDER}`);
|
|
167
|
+
await createSupervisorDatabaseClient();
|
|
168
|
+
await resetPassword(options.findLocalUser, options.updateLocalPassword, options.username, options.password);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* CLI to reset a user's password. Updates both local DB (via callbacks) and
|
|
172
|
+
* the supervisor DB. If username/password are provided, skips interactive
|
|
173
|
+
* prompts.
|
|
174
|
+
*/
|
|
175
|
+
export async function resetPassword(findLocalUser, updateLocalPassword, usernameArg, passwordArg) {
|
|
176
|
+
let username;
|
|
177
|
+
let password;
|
|
178
|
+
if (usernameArg && passwordArg) {
|
|
179
|
+
username = usernameArg;
|
|
180
|
+
password = passwordArg;
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
const rl = readline.createInterface({
|
|
184
|
+
input: process.stdin,
|
|
185
|
+
output: process.stdout,
|
|
186
|
+
});
|
|
187
|
+
try {
|
|
188
|
+
username = usernameArg || (await rl.question("Username: "));
|
|
189
|
+
password = passwordArg || (await rl.question("New password: "));
|
|
190
|
+
}
|
|
191
|
+
finally {
|
|
192
|
+
rl.close();
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const user = await findLocalUser(username);
|
|
196
|
+
if (!user) {
|
|
197
|
+
console.error(`User '${username}' not found.`);
|
|
198
|
+
process.exit(1);
|
|
199
|
+
}
|
|
200
|
+
if (password.length < 6) {
|
|
201
|
+
console.error("Password must be at least 6 characters.");
|
|
202
|
+
process.exit(1);
|
|
203
|
+
}
|
|
204
|
+
const hash = await bcrypt.hash(password, 10);
|
|
205
|
+
await updateLocalPassword(user.id, hash);
|
|
206
|
+
await updateUserPassword(username, hash);
|
|
207
|
+
console.log(`Password reset for '${username}'.`);
|
|
208
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@naisys/supervisor-database",
|
|
3
|
+
"version": "3.0.0-beta.10",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "[internal] Supervisor database schema and Prisma client for NAISYS",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"prisma.config.ts",
|
|
9
|
+
"prisma/schema.prisma",
|
|
10
|
+
"prisma/migrations",
|
|
11
|
+
"!dist/**/*.map",
|
|
12
|
+
"!dist/**/*.d.ts",
|
|
13
|
+
"!dist/**/*.d.ts.map"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"clean": "rimraf dist",
|
|
17
|
+
"prisma:migrate": "prisma migrate dev --create-only",
|
|
18
|
+
"prisma:generate": "prisma generate",
|
|
19
|
+
"prisma:studio": "prisma studio",
|
|
20
|
+
"build": "npm run prisma:generate && tsc",
|
|
21
|
+
"npm:publish:dryrun": "npm publish --dry-run",
|
|
22
|
+
"npm:publish": "npm publish --access public"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/better-sqlite3": "^7.6.13",
|
|
26
|
+
"typescript": "^5.9.3"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@naisys/common": "3.0.0-beta.10",
|
|
30
|
+
"@naisys/common-node": "3.0.0-beta.10",
|
|
31
|
+
"bcryptjs": "^3.0.2",
|
|
32
|
+
"@prisma/adapter-better-sqlite3": "^7.5.0",
|
|
33
|
+
"@prisma/client": "^7.5.0",
|
|
34
|
+
"better-sqlite3": "^12.6.2",
|
|
35
|
+
"prisma": "^7.5.0"
|
|
36
|
+
},
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"default": "./dist/index.js"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
-- CreateTable
|
|
2
|
+
CREATE TABLE "users" (
|
|
3
|
+
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
4
|
+
"username" TEXT NOT NULL,
|
|
5
|
+
"uuid" TEXT NOT NULL DEFAULT '',
|
|
6
|
+
"is_agent" BOOLEAN NOT NULL DEFAULT false,
|
|
7
|
+
"password_hash" TEXT NOT NULL DEFAULT '',
|
|
8
|
+
"session_token_hash" TEXT,
|
|
9
|
+
"session_expires_at" DATETIME,
|
|
10
|
+
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
11
|
+
"updated_at" DATETIME NOT NULL
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
-- CreateTable
|
|
15
|
+
CREATE TABLE "user_permissions" (
|
|
16
|
+
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
17
|
+
"user_id" INTEGER NOT NULL,
|
|
18
|
+
"permission" TEXT NOT NULL,
|
|
19
|
+
"granted_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
20
|
+
"granted_by" INTEGER,
|
|
21
|
+
CONSTRAINT "user_permissions_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
|
|
22
|
+
CONSTRAINT "user_permissions_granted_by_fkey" FOREIGN KEY ("granted_by") REFERENCES "users" ("id") ON DELETE SET NULL ON UPDATE CASCADE
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
-- CreateTable
|
|
26
|
+
CREATE TABLE "schema_version" (
|
|
27
|
+
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT DEFAULT 1,
|
|
28
|
+
"version" INTEGER NOT NULL,
|
|
29
|
+
"updated" TEXT NOT NULL
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
-- CreateIndex
|
|
33
|
+
CREATE UNIQUE INDEX "users_username_key" ON "users"("username");
|
|
34
|
+
|
|
35
|
+
-- CreateIndex
|
|
36
|
+
CREATE UNIQUE INDEX "user_permissions_user_id_permission_key" ON "user_permissions"("user_id", "permission");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
-- This is an empty migration.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
-- CreateTable
|
|
2
|
+
CREATE TABLE "sessions" (
|
|
3
|
+
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
4
|
+
"user_id" INTEGER NOT NULL,
|
|
5
|
+
"token_hash" TEXT NOT NULL,
|
|
6
|
+
"expires_at" DATETIME NOT NULL,
|
|
7
|
+
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
8
|
+
CONSTRAINT "sessions_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
-- CreateIndex
|
|
12
|
+
CREATE UNIQUE INDEX "sessions_token_hash_key" ON "sessions"("token_hash");
|
|
13
|
+
|
|
14
|
+
-- Migrate existing sessions
|
|
15
|
+
INSERT INTO "sessions" ("user_id", "token_hash", "expires_at", "created_at")
|
|
16
|
+
SELECT "id", "session_token_hash", "session_expires_at", CURRENT_TIMESTAMP
|
|
17
|
+
FROM "users"
|
|
18
|
+
WHERE "session_token_hash" IS NOT NULL AND "session_expires_at" IS NOT NULL;
|
|
19
|
+
|
|
20
|
+
-- DropColumns
|
|
21
|
+
ALTER TABLE "users" DROP COLUMN "session_token_hash";
|
|
22
|
+
ALTER TABLE "users" DROP COLUMN "session_expires_at";
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
datasource db {
|
|
2
|
+
provider = "sqlite"
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
generator client {
|
|
6
|
+
provider = "prisma-client"
|
|
7
|
+
output = "../src/generated/prisma"
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
enum Permission {
|
|
11
|
+
supervisor_admin
|
|
12
|
+
manage_agents
|
|
13
|
+
manage_hosts
|
|
14
|
+
agent_communication
|
|
15
|
+
manage_models
|
|
16
|
+
manage_variables
|
|
17
|
+
view_run_logs
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
model User {
|
|
21
|
+
id Int @id @default(autoincrement())
|
|
22
|
+
username String @unique
|
|
23
|
+
uuid String @default("")
|
|
24
|
+
isAgent Boolean @default(false) @map("is_agent")
|
|
25
|
+
passwordHash String @default("") @map("password_hash")
|
|
26
|
+
createdAt DateTime @default(now()) @map("created_at")
|
|
27
|
+
apiKey String? @unique @map("api_key")
|
|
28
|
+
updatedAt DateTime @updatedAt @map("updated_at")
|
|
29
|
+
permissions UserPermission[] @relation("UserPermissions")
|
|
30
|
+
grantedPermissions UserPermission[] @relation("GrantedByPermissions")
|
|
31
|
+
sessions Session[]
|
|
32
|
+
|
|
33
|
+
@@map("users")
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
model Session {
|
|
37
|
+
id Int @id @default(autoincrement())
|
|
38
|
+
userId Int @map("user_id")
|
|
39
|
+
tokenHash String @unique @map("token_hash")
|
|
40
|
+
expiresAt DateTime @map("expires_at")
|
|
41
|
+
createdAt DateTime @default(now()) @map("created_at")
|
|
42
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
43
|
+
|
|
44
|
+
@@map("sessions")
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
model UserPermission {
|
|
48
|
+
id Int @id @default(autoincrement())
|
|
49
|
+
userId Int @map("user_id")
|
|
50
|
+
permission Permission
|
|
51
|
+
grantedAt DateTime @default(now()) @map("granted_at")
|
|
52
|
+
grantedBy Int? @map("granted_by")
|
|
53
|
+
user User @relation("UserPermissions", fields: [userId], references: [id], onDelete: Cascade)
|
|
54
|
+
grantedByUser User? @relation("GrantedByPermissions", fields: [grantedBy], references: [id])
|
|
55
|
+
|
|
56
|
+
@@unique([userId, permission])
|
|
57
|
+
@@map("user_permissions")
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
model SchemaVersion {
|
|
61
|
+
id Int @id @default(1)
|
|
62
|
+
version Int
|
|
63
|
+
updated String
|
|
64
|
+
|
|
65
|
+
@@map("schema_version")
|
|
66
|
+
}
|
package/prisma.config.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { defineConfig } from "prisma/config";
|
|
4
|
+
|
|
5
|
+
// Use placeholder during generation, actual path provided at runtime
|
|
6
|
+
const naisysFolder = process.env.NAISYS_FOLDER || "";
|
|
7
|
+
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
schema: "prisma/schema.prisma",
|
|
10
|
+
migrations: {
|
|
11
|
+
path: "prisma/migrations",
|
|
12
|
+
},
|
|
13
|
+
datasource: {
|
|
14
|
+
// Used in dev when we run migrate manually to generate migration scripts
|
|
15
|
+
// Used in prod when self-migrating an existing database
|
|
16
|
+
url: `file:` + join(naisysFolder, "database", `supervisor.db`),
|
|
17
|
+
},
|
|
18
|
+
});
|