@rolder/kit 3.0.0-alpha.105 → 3.0.0-alpha.107

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.
@@ -1,10 +1,6 @@
1
- import { readFile } from "node:fs/promises";
2
- import node_path from "node:path";
3
- import { fileURLToPath } from "node:url";
4
1
  import { createServerOnlyFn } from "@tanstack/react-start";
5
2
  import { getDBInstance } from "../../../../surrealDB/index.js";
6
- const getDB_dirname = node_path.dirname(fileURLToPath(import.meta.url));
7
- const authSchemaPath = node_path.resolve(getDB_dirname, './schema.surql');
3
+ import { schema } from "./schema.js";
8
4
  let schemaApplied = false;
9
5
  let schemaApplying = false;
10
6
  const ensureAuthSchema = async (props = {})=>{
@@ -12,7 +8,6 @@ const ensureAuthSchema = async (props = {})=>{
12
8
  if (!schemaApplying) try {
13
9
  schemaApplying = true;
14
10
  const db = await getDBInstance(props);
15
- const schema = await readFile(authSchemaPath, 'utf8');
16
11
  const betterAuthUrl = "/";
17
12
  const betterAuthJwksUrl = `${betterAuthUrl}/api/auth/jwks`;
18
13
  await db.query(schema, {
@@ -0,0 +1 @@
1
+ export declare const schema = "\n-- Better Auth JWT Access\n-- URL \u043F\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044F \u0447\u0435\u0440\u0435\u0437 \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440 $BETTER_AUTH_JWKS_URL \u043F\u0440\u0438 \u0432\u044B\u043F\u043E\u043B\u043D\u0435\u043D\u0438\u0438 \u0441\u0445\u0435\u043C\u044B\nDEFINE ACCESS IF NOT EXISTS better_auth_jwt\n ON DATABASE\n TYPE JWT\n URL $BETTER_AUTH_JWKS_URL\n;\n\n// User\nDEFINE TABLE IF NOT EXISTS user TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;\nDEFINE FIELD IF NOT EXISTS name ON user TYPE string;\nDEFINE FIELD OVERWRITE email ON user TYPE option<string> ASSERT $value = NONE OR string::is_email($value);\nDEFINE FIELD OVERWRITE email_address ON user TYPE option<string> ASSERT $value = NONE OR string::is_email($value);\nDEFINE INDEX IF NOT EXISTS userUserUnique ON user COLUMNS email UNIQUE;\nDEFINE FIELD IF NOT EXISTS emailVerified ON user TYPE bool;\nDEFINE FIELD IF NOT EXISTS image ON user TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS createdAt ON user TYPE option<datetime> DEFAULT time::now();\nDEFINE FIELD IF NOT EXISTS updatedAt ON user TYPE option<datetime> DEFAULT time::now();\n-- Admin plugin\nDEFINE FIELD IF NOT EXISTS role ON user TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS banned ON user TYPE option<bool>;\nDEFINE FIELD IF NOT EXISTS banReason ON user TYPE option<string> | NULL;\nDEFINE FIELD IF NOT EXISTS banExpires ON user TYPE option<datetime> | NULL;\n-- Username plugin\nDEFINE FIELD OVERWRITE username ON user TYPE option<string>;\nDEFINE FIELD OVERWRITE displayUsername ON user TYPE option<string>;\n-- Custom\nDEFINE FIELD IF NOT EXISTS accounts ON user COMPUTED <~account;\nDEFINE FIELD IF NOT EXISTS sessions ON user COMPUTED <~session;\n\n-- // Session\nDEFINE TABLE IF NOT EXISTS session TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;\nDEFINE FIELD IF NOT EXISTS expiresAt ON session TYPE datetime;\nDEFINE FIELD IF NOT EXISTS token ON session TYPE string;\nDEFINE INDEX IF NOT EXISTS sessionSessionUnique ON session COLUMNS token UNIQUE;\nDEFINE FIELD IF NOT EXISTS createdAt ON session TYPE option<datetime> DEFAULT time::now();\nDEFINE FIELD IF NOT EXISTS updatedAt ON session TYPE option<datetime> DEFAULT time::now();\nDEFINE FIELD IF NOT EXISTS ipAddress ON session TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS userAgent ON session TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS userId ON session TYPE record<user> REFERENCE ON DELETE IGNORE;\n-- Admin plugin\nDEFINE FIELD IF NOT EXISTS impersonatedBy ON user TYPE option<record<user>>;\n\n-- // Account\nDEFINE TABLE IF NOT EXISTS account TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;\nDEFINE FIELD IF NOT EXISTS accountId ON account TYPE string;\nDEFINE FIELD IF NOT EXISTS providerId ON account TYPE string;\nDEFINE FIELD IF NOT EXISTS accessToken ON account TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS refreshToken ON account TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS idToken ON account TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS accessTokenExpiresAt ON account TYPE option<datetime>;\nDEFINE FIELD IF NOT EXISTS refreshTokenExpiresAt ON account TYPE option<datetime>;\nDEFINE FIELD IF NOT EXISTS scope ON account TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS password ON account TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS createdAt ON account TYPE option<datetime> DEFAULT time::now();\nDEFINE FIELD IF NOT EXISTS updatedAt ON account TYPE option<datetime> DEFAULT time::now();\n-- Custom\nDEFINE FIELD IF NOT EXISTS userId ON account TYPE record<user> REFERENCE ON DELETE IGNORE;\n\n// Verification\nDEFINE TABLE IF NOT EXISTS verification TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;\nDEFINE FIELD IF NOT EXISTS identifier ON verification TYPE string;\nDEFINE FIELD IF NOT EXISTS value ON verification TYPE string;\nDEFINE FIELD IF NOT EXISTS expiresAt ON verification TYPE datetime;\nDEFINE FIELD IF NOT EXISTS createdAt ON verification TYPE option<datetime> DEFAULT time::now();\nDEFINE FIELD IF NOT EXISTS updatedAt ON verification TYPE option<datetime> DEFAULT time::now();\n\n// JWKS\nDEFINE TABLE IF NOT EXISTS jwks TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;\nDEFINE FIELD IF NOT EXISTS publicKey ON jwks TYPE string;\nDEFINE FIELD IF NOT EXISTS privateKey ON jwks TYPE string;\nDEFINE FIELD IF NOT EXISTS createdAt ON jwks TYPE option<datetime> DEFAULT time::now();\nDEFINE FIELD IF NOT EXISTS updatedAt ON jwks TYPE option<datetime> DEFAULT time::now();\n\n// Root auth user\nIF !user:root.* {\n CREATE user:root CONTENT {\n \tname: '\u0421\u0438\u0441\u0442\u0435\u043C\u043D\u0430\u044F \u0443\u0447\u0435\u0442\u043D\u0430\u044F \u0437\u0430\u043F\u0438\u0441\u044C',\n \trole: 'admin',\n \tusername: 'root',\n \tdisplayUsername: 'Root',\n \temail: 'mail@rolder.dev',\n \temailVerified: true,\n \tbanned: false,\n };\n};\n\nIF !account:root.* {\n CREATE account:root CONTENT {\n \taccountId: 'root',\n \tuserId: user:root,\n \tpassword: '52c2da6bc1a525ee0f6a298e228a1314:c7ba714b9467d4582c5848947c2536340ff9f85ff6ca6c9ee022f68cd5eb60e227ba0cbadd3d46e9316c4562cef9d7551c957192809bf2a4b27f2a2b1365a08e',\n providerId: 'credential',\n };\n};";
@@ -0,0 +1,97 @@
1
+ const schema = `
2
+ -- Better Auth JWT Access
3
+ -- URL передается через параметр $BETTER_AUTH_JWKS_URL при выполнении схемы
4
+ DEFINE ACCESS IF NOT EXISTS better_auth_jwt
5
+ ON DATABASE
6
+ TYPE JWT
7
+ URL $BETTER_AUTH_JWKS_URL
8
+ ;
9
+
10
+ // User
11
+ DEFINE TABLE IF NOT EXISTS user TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;
12
+ DEFINE FIELD IF NOT EXISTS name ON user TYPE string;
13
+ DEFINE FIELD OVERWRITE email ON user TYPE option<string> ASSERT $value = NONE OR string::is_email($value);
14
+ DEFINE FIELD OVERWRITE email_address ON user TYPE option<string> ASSERT $value = NONE OR string::is_email($value);
15
+ DEFINE INDEX IF NOT EXISTS userUserUnique ON user COLUMNS email UNIQUE;
16
+ DEFINE FIELD IF NOT EXISTS emailVerified ON user TYPE bool;
17
+ DEFINE FIELD IF NOT EXISTS image ON user TYPE option<string>;
18
+ DEFINE FIELD IF NOT EXISTS createdAt ON user TYPE option<datetime> DEFAULT time::now();
19
+ DEFINE FIELD IF NOT EXISTS updatedAt ON user TYPE option<datetime> DEFAULT time::now();
20
+ -- Admin plugin
21
+ DEFINE FIELD IF NOT EXISTS role ON user TYPE option<string>;
22
+ DEFINE FIELD IF NOT EXISTS banned ON user TYPE option<bool>;
23
+ DEFINE FIELD IF NOT EXISTS banReason ON user TYPE option<string> | NULL;
24
+ DEFINE FIELD IF NOT EXISTS banExpires ON user TYPE option<datetime> | NULL;
25
+ -- Username plugin
26
+ DEFINE FIELD OVERWRITE username ON user TYPE option<string>;
27
+ DEFINE FIELD OVERWRITE displayUsername ON user TYPE option<string>;
28
+ -- Custom
29
+ DEFINE FIELD IF NOT EXISTS accounts ON user COMPUTED <~account;
30
+ DEFINE FIELD IF NOT EXISTS sessions ON user COMPUTED <~session;
31
+
32
+ -- // Session
33
+ DEFINE TABLE IF NOT EXISTS session TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;
34
+ DEFINE FIELD IF NOT EXISTS expiresAt ON session TYPE datetime;
35
+ DEFINE FIELD IF NOT EXISTS token ON session TYPE string;
36
+ DEFINE INDEX IF NOT EXISTS sessionSessionUnique ON session COLUMNS token UNIQUE;
37
+ DEFINE FIELD IF NOT EXISTS createdAt ON session TYPE option<datetime> DEFAULT time::now();
38
+ DEFINE FIELD IF NOT EXISTS updatedAt ON session TYPE option<datetime> DEFAULT time::now();
39
+ DEFINE FIELD IF NOT EXISTS ipAddress ON session TYPE option<string>;
40
+ DEFINE FIELD IF NOT EXISTS userAgent ON session TYPE option<string>;
41
+ DEFINE FIELD IF NOT EXISTS userId ON session TYPE record<user> REFERENCE ON DELETE IGNORE;
42
+ -- Admin plugin
43
+ DEFINE FIELD IF NOT EXISTS impersonatedBy ON user TYPE option<record<user>>;
44
+
45
+ -- // Account
46
+ DEFINE TABLE IF NOT EXISTS account TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;
47
+ DEFINE FIELD IF NOT EXISTS accountId ON account TYPE string;
48
+ DEFINE FIELD IF NOT EXISTS providerId ON account TYPE string;
49
+ DEFINE FIELD IF NOT EXISTS accessToken ON account TYPE option<string>;
50
+ DEFINE FIELD IF NOT EXISTS refreshToken ON account TYPE option<string>;
51
+ DEFINE FIELD IF NOT EXISTS idToken ON account TYPE option<string>;
52
+ DEFINE FIELD IF NOT EXISTS accessTokenExpiresAt ON account TYPE option<datetime>;
53
+ DEFINE FIELD IF NOT EXISTS refreshTokenExpiresAt ON account TYPE option<datetime>;
54
+ DEFINE FIELD IF NOT EXISTS scope ON account TYPE option<string>;
55
+ DEFINE FIELD IF NOT EXISTS password ON account TYPE option<string>;
56
+ DEFINE FIELD IF NOT EXISTS createdAt ON account TYPE option<datetime> DEFAULT time::now();
57
+ DEFINE FIELD IF NOT EXISTS updatedAt ON account TYPE option<datetime> DEFAULT time::now();
58
+ -- Custom
59
+ DEFINE FIELD IF NOT EXISTS userId ON account TYPE record<user> REFERENCE ON DELETE IGNORE;
60
+
61
+ // Verification
62
+ DEFINE TABLE IF NOT EXISTS verification TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;
63
+ DEFINE FIELD IF NOT EXISTS identifier ON verification TYPE string;
64
+ DEFINE FIELD IF NOT EXISTS value ON verification TYPE string;
65
+ DEFINE FIELD IF NOT EXISTS expiresAt ON verification TYPE datetime;
66
+ DEFINE FIELD IF NOT EXISTS createdAt ON verification TYPE option<datetime> DEFAULT time::now();
67
+ DEFINE FIELD IF NOT EXISTS updatedAt ON verification TYPE option<datetime> DEFAULT time::now();
68
+
69
+ // JWKS
70
+ DEFINE TABLE IF NOT EXISTS jwks TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;
71
+ DEFINE FIELD IF NOT EXISTS publicKey ON jwks TYPE string;
72
+ DEFINE FIELD IF NOT EXISTS privateKey ON jwks TYPE string;
73
+ DEFINE FIELD IF NOT EXISTS createdAt ON jwks TYPE option<datetime> DEFAULT time::now();
74
+ DEFINE FIELD IF NOT EXISTS updatedAt ON jwks TYPE option<datetime> DEFAULT time::now();
75
+
76
+ // Root auth user
77
+ IF !user:root.* {
78
+ CREATE user:root CONTENT {
79
+ name: 'Системная учетная запись',
80
+ role: 'admin',
81
+ username: 'root',
82
+ displayUsername: 'Root',
83
+ email: 'mail@rolder.dev',
84
+ emailVerified: true,
85
+ banned: false,
86
+ };
87
+ };
88
+
89
+ IF !account:root.* {
90
+ CREATE account:root CONTENT {
91
+ accountId: 'root',
92
+ userId: user:root,
93
+ password: '52c2da6bc1a525ee0f6a298e228a1314:c7ba714b9467d4582c5848947c2536340ff9f85ff6ca6c9ee022f68cd5eb60e227ba0cbadd3d46e9316c4562cef9d7551c957192809bf2a4b27f2a2b1365a08e',
94
+ providerId: 'credential',
95
+ };
96
+ };`;
97
+ export { schema };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rolder/kit",
3
- "version": "3.0.0-alpha.105",
3
+ "version": "3.0.0-alpha.107",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./ai": {