@rebasepro/server-postgresql 0.4.0 → 0.6.0
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/README.md +69 -89
- package/dist/{server-postgresql/src/PostgresAdapter.d.ts → PostgresAdapter.d.ts} +1 -1
- package/dist/{server-postgresql/src/PostgresBackendDriver.d.ts → PostgresBackendDriver.d.ts} +2 -2
- package/dist/{server-postgresql/src/PostgresBootstrapper.d.ts → PostgresBootstrapper.d.ts} +11 -1
- package/dist/{server-postgresql/src/auth → auth}/services.d.ts +11 -11
- package/dist/{server-postgresql/src/collections → collections}/PostgresCollectionRegistry.d.ts +4 -0
- package/dist/{server-postgresql/src/data-transformer.d.ts → data-transformer.d.ts} +0 -3
- package/dist/{server-postgresql/src/databasePoolManager.d.ts → databasePoolManager.d.ts} +1 -1
- package/dist/index.es.js +10174 -11184
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +10735 -11462
- package/dist/index.umd.js.map +1 -1
- package/dist/{server-postgresql/src/services → services}/EntityPersistService.d.ts +0 -14
- package/dist/types.d.ts +3 -0
- package/dist/utils/pg-error-utils.d.ts +55 -0
- package/dist/{server-postgresql/src/websocket.d.ts → websocket.d.ts} +8 -3
- package/package.json +24 -21
- package/src/PostgresAdapter.ts +9 -10
- package/src/PostgresBackendDriver.ts +135 -122
- package/src/PostgresBootstrapper.ts +90 -16
- package/src/auth/ensure-tables.ts +28 -5
- package/src/auth/services.ts +56 -45
- package/src/cli.ts +140 -110
- package/src/collections/PostgresCollectionRegistry.ts +7 -0
- package/src/connection.ts +11 -6
- package/src/data-transformer.ts +73 -109
- package/src/databasePoolManager.ts +5 -3
- package/src/history/HistoryService.ts +3 -2
- package/src/history/ensure-history-table.ts +5 -4
- package/src/schema/auth-schema.ts +1 -2
- package/src/schema/doctor-cli.ts +2 -1
- package/src/schema/doctor.ts +40 -37
- package/src/schema/generate-drizzle-schema-logic.ts +56 -18
- package/src/schema/generate-drizzle-schema.ts +11 -11
- package/src/schema/introspect-db-inference.ts +25 -25
- package/src/schema/introspect-db-logic.ts +38 -38
- package/src/schema/introspect-db.ts +28 -27
- package/src/services/BranchService.ts +14 -0
- package/src/services/EntityFetchService.ts +28 -25
- package/src/services/EntityPersistService.ts +11 -124
- package/src/services/RelationService.ts +57 -37
- package/src/services/entity-helpers.ts +6 -2
- package/src/services/realtimeService.ts +45 -32
- package/src/types.ts +4 -0
- package/src/utils/drizzle-conditions.ts +31 -15
- package/src/utils/pg-error-utils.ts +211 -0
- package/src/websocket.ts +51 -33
- package/test/auth-services.test.ts +36 -19
- package/test/batch-many-to-many-regression.test.ts +119 -39
- package/test/data-transformer-hardening.test.ts +67 -33
- package/test/data-transformer.test.ts +4 -2
- package/test/doctor.test.ts +10 -5
- package/test/drizzle-conditions.test.ts +59 -6
- package/test/generate-drizzle-schema.test.ts +65 -40
- package/test/introspect-db-generation.test.ts +179 -81
- package/test/introspect-db-utils.test.ts +92 -37
- package/test/mocks/chalk.cjs +7 -0
- package/test/pg-error-utils.test.ts +221 -0
- package/test/postgresDataDriver.test.ts +14 -5
- package/test/property-ordering.test.ts +126 -79
- package/test/realtimeService.test.ts +6 -2
- package/test/relation-pipeline-gaps.test.ts +84 -36
- package/test/relations.test.ts +247 -0
- package/test/unmapped-tables-safety.test.ts +14 -6
- package/test/websocket.test.ts +1 -1
- package/tsconfig.json +5 -0
- package/tsconfig.prod.json +3 -0
- package/vite.config.ts +5 -5
- package/dist/common/src/collections/CollectionRegistry.d.ts +0 -56
- package/dist/common/src/collections/default-collections.d.ts +0 -9
- package/dist/common/src/collections/index.d.ts +0 -2
- package/dist/common/src/data/buildRebaseData.d.ts +0 -14
- package/dist/common/src/data/query_builder.d.ts +0 -55
- package/dist/common/src/index.d.ts +0 -4
- package/dist/common/src/util/builders.d.ts +0 -57
- package/dist/common/src/util/callbacks.d.ts +0 -6
- package/dist/common/src/util/collections.d.ts +0 -11
- package/dist/common/src/util/common.d.ts +0 -2
- package/dist/common/src/util/conditions.d.ts +0 -26
- package/dist/common/src/util/entities.d.ts +0 -58
- package/dist/common/src/util/enums.d.ts +0 -3
- package/dist/common/src/util/index.d.ts +0 -16
- package/dist/common/src/util/navigation_from_path.d.ts +0 -34
- package/dist/common/src/util/navigation_utils.d.ts +0 -20
- package/dist/common/src/util/parent_references_from_path.d.ts +0 -6
- package/dist/common/src/util/paths.d.ts +0 -14
- package/dist/common/src/util/permissions.d.ts +0 -6
- package/dist/common/src/util/references.d.ts +0 -2
- package/dist/common/src/util/relations.d.ts +0 -22
- package/dist/common/src/util/resolutions.d.ts +0 -72
- package/dist/common/src/util/storage.d.ts +0 -24
- package/dist/types/src/controllers/analytics_controller.d.ts +0 -7
- package/dist/types/src/controllers/auth.d.ts +0 -104
- package/dist/types/src/controllers/client.d.ts +0 -168
- package/dist/types/src/controllers/collection_registry.d.ts +0 -46
- package/dist/types/src/controllers/customization_controller.d.ts +0 -60
- package/dist/types/src/controllers/data.d.ts +0 -207
- package/dist/types/src/controllers/data_driver.d.ts +0 -218
- package/dist/types/src/controllers/database_admin.d.ts +0 -11
- package/dist/types/src/controllers/dialogs_controller.d.ts +0 -36
- package/dist/types/src/controllers/effective_role.d.ts +0 -4
- package/dist/types/src/controllers/email.d.ts +0 -36
- package/dist/types/src/controllers/index.d.ts +0 -18
- package/dist/types/src/controllers/local_config_persistence.d.ts +0 -20
- package/dist/types/src/controllers/navigation.d.ts +0 -225
- package/dist/types/src/controllers/registry.d.ts +0 -63
- package/dist/types/src/controllers/side_dialogs_controller.d.ts +0 -67
- package/dist/types/src/controllers/side_entity_controller.d.ts +0 -97
- package/dist/types/src/controllers/snackbar.d.ts +0 -24
- package/dist/types/src/controllers/storage.d.ts +0 -171
- package/dist/types/src/index.d.ts +0 -4
- package/dist/types/src/rebase_context.d.ts +0 -122
- package/dist/types/src/types/auth_adapter.d.ts +0 -301
- package/dist/types/src/types/backend.d.ts +0 -536
- package/dist/types/src/types/backend_hooks.d.ts +0 -172
- package/dist/types/src/types/builders.d.ts +0 -15
- package/dist/types/src/types/chips.d.ts +0 -5
- package/dist/types/src/types/collections.d.ts +0 -941
- package/dist/types/src/types/component_ref.d.ts +0 -47
- package/dist/types/src/types/cron.d.ts +0 -102
- package/dist/types/src/types/data_source.d.ts +0 -64
- package/dist/types/src/types/database_adapter.d.ts +0 -94
- package/dist/types/src/types/entities.d.ts +0 -145
- package/dist/types/src/types/entity_actions.d.ts +0 -104
- package/dist/types/src/types/entity_callbacks.d.ts +0 -173
- package/dist/types/src/types/entity_link_builder.d.ts +0 -7
- package/dist/types/src/types/entity_overrides.d.ts +0 -10
- package/dist/types/src/types/entity_views.d.ts +0 -87
- package/dist/types/src/types/export_import.d.ts +0 -21
- package/dist/types/src/types/formex.d.ts +0 -40
- package/dist/types/src/types/index.d.ts +0 -28
- package/dist/types/src/types/locales.d.ts +0 -4
- package/dist/types/src/types/modify_collections.d.ts +0 -5
- package/dist/types/src/types/plugins.d.ts +0 -282
- package/dist/types/src/types/properties.d.ts +0 -1181
- package/dist/types/src/types/property_config.d.ts +0 -74
- package/dist/types/src/types/relations.d.ts +0 -336
- package/dist/types/src/types/slots.d.ts +0 -262
- package/dist/types/src/types/translations.d.ts +0 -900
- package/dist/types/src/types/user_management_delegate.d.ts +0 -86
- package/dist/types/src/types/websockets.d.ts +0 -78
- package/dist/types/src/users/index.d.ts +0 -1
- package/dist/types/src/users/user.d.ts +0 -50
- package/drizzle.test.config.ts +0 -10
- /package/dist/{server-postgresql/src/auth → auth}/ensure-tables.d.ts +0 -0
- /package/dist/{server-postgresql/src/cli.d.ts → cli.d.ts} +0 -0
- /package/dist/{server-postgresql/src/connection.d.ts → connection.d.ts} +0 -0
- /package/dist/{server-postgresql/src/history → history}/HistoryService.d.ts +0 -0
- /package/dist/{server-postgresql/src/history → history}/ensure-history-table.d.ts +0 -0
- /package/dist/{server-postgresql/src/index.d.ts → index.d.ts} +0 -0
- /package/dist/{server-postgresql/src/interfaces.d.ts → interfaces.d.ts} +0 -0
- /package/dist/{server-postgresql/src/schema → schema}/auth-schema.d.ts +0 -0
- /package/dist/{server-postgresql/src/schema → schema}/doctor-cli.d.ts +0 -0
- /package/dist/{server-postgresql/src/schema → schema}/doctor.d.ts +0 -0
- /package/dist/{server-postgresql/src/schema → schema}/generate-drizzle-schema-logic.d.ts +0 -0
- /package/dist/{server-postgresql/src/schema → schema}/generate-drizzle-schema.d.ts +0 -0
- /package/dist/{server-postgresql/src/schema → schema}/introspect-db-inference.d.ts +0 -0
- /package/dist/{server-postgresql/src/schema → schema}/introspect-db-logic.d.ts +0 -0
- /package/dist/{server-postgresql/src/schema → schema}/introspect-db.d.ts +0 -0
- /package/dist/{server-postgresql/src/schema → schema}/test-schema.d.ts +0 -0
- /package/dist/{server-postgresql/src/services → services}/BranchService.d.ts +0 -0
- /package/dist/{server-postgresql/src/services → services}/EntityFetchService.d.ts +0 -0
- /package/dist/{server-postgresql/src/services → services}/RelationService.d.ts +0 -0
- /package/dist/{server-postgresql/src/services → services}/entity-helpers.d.ts +0 -0
- /package/dist/{server-postgresql/src/services → services}/entityService.d.ts +0 -0
- /package/dist/{server-postgresql/src/services → services}/index.d.ts +0 -0
- /package/dist/{server-postgresql/src/services → services}/realtimeService.d.ts +0 -0
- /package/dist/{server-postgresql/src/utils → utils}/drizzle-conditions.d.ts +0 -0
|
@@ -4,7 +4,6 @@ import { logger } from "@rebasepro/server-core";
|
|
|
4
4
|
import type { EntityCollection } from "@rebasepro/types";
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Auto-create auth tables if they don't exist.
|
|
10
9
|
*
|
|
@@ -20,16 +19,17 @@ export async function ensureAuthTablesExist(db: NodePgDatabase, collection?: Ent
|
|
|
20
19
|
let usersTableName = '"rebase"."users"';
|
|
21
20
|
let userIdType = "TEXT";
|
|
22
21
|
let usersSchema = "rebase";
|
|
22
|
+
let resolvedTable = "users";
|
|
23
23
|
if (collection) {
|
|
24
|
-
|
|
24
|
+
resolvedTable = ("table" in collection && typeof collection.table === "string")
|
|
25
25
|
? collection.table
|
|
26
26
|
: collection.slug;
|
|
27
27
|
usersSchema = ("schema" in collection && typeof collection.schema === "string")
|
|
28
28
|
? collection.schema
|
|
29
29
|
: "public";
|
|
30
30
|
usersTableName = usersSchema === "public"
|
|
31
|
-
? `"${
|
|
32
|
-
: `"${usersSchema}"."${
|
|
31
|
+
? `"${resolvedTable}"`
|
|
32
|
+
: `"${usersSchema}"."${resolvedTable}"`;
|
|
33
33
|
|
|
34
34
|
// Derive ID column type from collection properties
|
|
35
35
|
const idProp = collection.properties?.id;
|
|
@@ -44,6 +44,30 @@ export async function ensureAuthTablesExist(db: NodePgDatabase, collection?: Ent
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
// Introspect the database to find the actual type of usersTableName's ID column if the table exists
|
|
48
|
+
try {
|
|
49
|
+
const result = await db.execute(sql`
|
|
50
|
+
SELECT data_type
|
|
51
|
+
FROM information_schema.columns
|
|
52
|
+
WHERE table_schema = ${usersSchema}
|
|
53
|
+
AND table_name = ${resolvedTable}
|
|
54
|
+
AND column_name = 'id'
|
|
55
|
+
`);
|
|
56
|
+
if (result && result.rows && result.rows.length > 0) {
|
|
57
|
+
const dbType = String((result.rows[0] as { data_type: string }).data_type).toUpperCase();
|
|
58
|
+
if (dbType === "UUID") {
|
|
59
|
+
userIdType = "UUID";
|
|
60
|
+
} else if (dbType === "INTEGER" || dbType === "SMALLINT" || dbType === "BIGINT") {
|
|
61
|
+
userIdType = "INTEGER";
|
|
62
|
+
} else {
|
|
63
|
+
userIdType = "TEXT";
|
|
64
|
+
}
|
|
65
|
+
logger.info(`✨ Detected ${usersTableName}.id type from database: ${dbType}. Using user_id type: ${userIdType}`);
|
|
66
|
+
}
|
|
67
|
+
} catch (err) {
|
|
68
|
+
// Ignore introspection errors, fallback to derived/default type
|
|
69
|
+
logger.warn(`⚠️ Failed to introspect ${usersTableName}.id type from database, falling back to config type: ${userIdType}`, { error: err });
|
|
70
|
+
}
|
|
47
71
|
|
|
48
72
|
|
|
49
73
|
// ── Create schemas (idempotent) ──────────────────────────────────
|
|
@@ -81,7 +105,6 @@ export async function ensureAuthTablesExist(db: NodePgDatabase, collection?: Ent
|
|
|
81
105
|
`);
|
|
82
106
|
|
|
83
107
|
|
|
84
|
-
|
|
85
108
|
// Create refresh tokens table (includes user_agent, ip_address, and unique constraint)
|
|
86
109
|
await db.execute(sql`
|
|
87
110
|
CREATE TABLE IF NOT EXISTS ${sql.raw(refreshTokensTableName)} (
|
package/src/auth/services.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { eq, getTableName, sql } from "drizzle-orm";
|
|
2
2
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
3
|
-
import { getTableConfig
|
|
3
|
+
import { getTableConfig } from "drizzle-orm/pg-core";
|
|
4
|
+
import type { RebasePgTable } from "../types";
|
|
4
5
|
import { users, refreshTokens, passwordResetTokens, userIdentities } from "../schema/auth-schema";
|
|
5
6
|
import {
|
|
6
7
|
UserRepository,
|
|
@@ -20,21 +21,20 @@ import {
|
|
|
20
21
|
MfaFactor,
|
|
21
22
|
MfaChallengeInfo,
|
|
22
23
|
RoleData as Role
|
|
23
|
-
// @ts-ignore
|
|
24
24
|
} from "@rebasepro/server-core";
|
|
25
25
|
import { toSnakeCase, camelCase } from "@rebasepro/utils";
|
|
26
26
|
|
|
27
27
|
export type { Role };
|
|
28
28
|
|
|
29
29
|
export interface AuthSchemaTables {
|
|
30
|
-
users:
|
|
31
|
-
refreshTokens:
|
|
32
|
-
passwordResetTokens:
|
|
33
|
-
appConfig:
|
|
34
|
-
userIdentities:
|
|
30
|
+
users: RebasePgTable;
|
|
31
|
+
refreshTokens: RebasePgTable;
|
|
32
|
+
passwordResetTokens: RebasePgTable;
|
|
33
|
+
appConfig: RebasePgTable;
|
|
34
|
+
userIdentities: RebasePgTable;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
function getColumnKey(table:
|
|
37
|
+
function getColumnKey(table: RebasePgTable | undefined, ...keys: string[]): string | undefined {
|
|
38
38
|
if (!table) return undefined;
|
|
39
39
|
for (const key of keys) {
|
|
40
40
|
if (key in table) return key;
|
|
@@ -46,7 +46,7 @@ function getColumnKey(table: (PgTable & Record<string, AnyPgColumn>) | undefined
|
|
|
46
46
|
return undefined;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
function getColumn(table:
|
|
49
|
+
function getColumn(table: RebasePgTable | undefined, ...keys: string[]): RebasePgTable[string] | undefined {
|
|
50
50
|
if (!table) return undefined;
|
|
51
51
|
const key = getColumnKey(table, ...keys);
|
|
52
52
|
return key ? table[key] : undefined;
|
|
@@ -57,21 +57,21 @@ function getColumn(table: (PgTable & Record<string, AnyPgColumn>) | undefined, .
|
|
|
57
57
|
* Handles all user-related database operations using Drizzle ORM.
|
|
58
58
|
*/
|
|
59
59
|
export class UserService implements UserRepository {
|
|
60
|
-
private usersTable:
|
|
61
|
-
private userIdentitiesTable:
|
|
60
|
+
private usersTable: RebasePgTable;
|
|
61
|
+
private userIdentitiesTable: RebasePgTable;
|
|
62
62
|
|
|
63
63
|
constructor(
|
|
64
64
|
private db: NodePgDatabase,
|
|
65
|
-
tableOrTables?:
|
|
65
|
+
tableOrTables?: RebasePgTable | Partial<AuthSchemaTables>
|
|
66
66
|
) {
|
|
67
67
|
if (tableOrTables && ((tableOrTables as Partial<AuthSchemaTables>).users)) {
|
|
68
68
|
const tables = tableOrTables as Partial<AuthSchemaTables>;
|
|
69
|
-
this.usersTable = (tables.users || users) as
|
|
70
|
-
this.userIdentitiesTable = (tables.userIdentities || userIdentities) as
|
|
69
|
+
this.usersTable = (tables.users || users) as RebasePgTable;
|
|
70
|
+
this.userIdentitiesTable = (tables.userIdentities || userIdentities) as RebasePgTable;
|
|
71
71
|
} else {
|
|
72
|
-
const table = tableOrTables as
|
|
73
|
-
this.usersTable = table || (users as unknown as
|
|
74
|
-
this.userIdentitiesTable = userIdentities as unknown as
|
|
72
|
+
const table = tableOrTables as RebasePgTable | undefined;
|
|
73
|
+
this.usersTable = table || (users as unknown as RebasePgTable);
|
|
74
|
+
this.userIdentitiesTable = userIdentities as unknown as RebasePgTable;
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
@@ -82,7 +82,7 @@ export class UserService implements UserRepository {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
private mapRowToUser(row: Record<string, unknown>): UserData {
|
|
85
|
-
if (!row) return row as
|
|
85
|
+
if (!row) return row as UserData;
|
|
86
86
|
|
|
87
87
|
const id = (row.id ?? row.uid) as string;
|
|
88
88
|
const email = row.email as string;
|
|
@@ -171,18 +171,18 @@ export class UserService implements UserRepository {
|
|
|
171
171
|
|
|
172
172
|
for (const [key, val] of Object.entries(metadata)) {
|
|
173
173
|
const tableColKey = getColumnKey(this.usersTable, key);
|
|
174
|
-
if (tableColKey &&
|
|
175
|
-
tableColKey !== idKey &&
|
|
176
|
-
tableColKey !== emailKey &&
|
|
177
|
-
tableColKey !== passwordHashKey &&
|
|
178
|
-
tableColKey !== displayNameKey &&
|
|
179
|
-
tableColKey !== photoUrlKey &&
|
|
180
|
-
tableColKey !== emailVerifiedKey &&
|
|
181
|
-
tableColKey !== emailVerificationTokenKey &&
|
|
182
|
-
tableColKey !== emailVerificationSentAtKey &&
|
|
174
|
+
if (tableColKey &&
|
|
175
|
+
tableColKey !== idKey &&
|
|
176
|
+
tableColKey !== emailKey &&
|
|
177
|
+
tableColKey !== passwordHashKey &&
|
|
178
|
+
tableColKey !== displayNameKey &&
|
|
179
|
+
tableColKey !== photoUrlKey &&
|
|
180
|
+
tableColKey !== emailVerifiedKey &&
|
|
181
|
+
tableColKey !== emailVerificationTokenKey &&
|
|
182
|
+
tableColKey !== emailVerificationSentAtKey &&
|
|
183
183
|
tableColKey !== isAnonymousKey &&
|
|
184
|
-
tableColKey !== createdAtKey &&
|
|
185
|
-
tableColKey !== updatedAtKey &&
|
|
184
|
+
tableColKey !== createdAtKey &&
|
|
185
|
+
tableColKey !== updatedAtKey &&
|
|
186
186
|
tableColKey !== metadataKey) {
|
|
187
187
|
payload[tableColKey] = val;
|
|
188
188
|
} else {
|
|
@@ -220,7 +220,7 @@ export class UserService implements UserRepository {
|
|
|
220
220
|
async getUserByIdentity(provider: string, providerId: string): Promise<UserData | null> {
|
|
221
221
|
const userIdCol = getColumn(this.usersTable, "id");
|
|
222
222
|
if (!userIdCol) return null;
|
|
223
|
-
|
|
223
|
+
|
|
224
224
|
const result = await this.db
|
|
225
225
|
.select({ user: this.usersTable })
|
|
226
226
|
.from(this.usersTable)
|
|
@@ -495,18 +495,17 @@ export class UserService implements UserRepository {
|
|
|
495
495
|
}
|
|
496
496
|
|
|
497
497
|
|
|
498
|
-
|
|
499
498
|
export class RefreshTokenService {
|
|
500
|
-
private refreshTokensTable:
|
|
499
|
+
private refreshTokensTable: RebasePgTable;
|
|
501
500
|
|
|
502
501
|
constructor(
|
|
503
502
|
private db: NodePgDatabase,
|
|
504
|
-
tableOrTables?:
|
|
503
|
+
tableOrTables?: RebasePgTable | Partial<AuthSchemaTables>
|
|
505
504
|
) {
|
|
506
505
|
if (tableOrTables && ((tableOrTables as Partial<AuthSchemaTables>).refreshTokens || (tableOrTables as Partial<AuthSchemaTables>).users)) {
|
|
507
|
-
this.refreshTokensTable = ((tableOrTables as Partial<AuthSchemaTables>).refreshTokens || refreshTokens) as
|
|
506
|
+
this.refreshTokensTable = ((tableOrTables as Partial<AuthSchemaTables>).refreshTokens || refreshTokens) as RebasePgTable;
|
|
508
507
|
} else {
|
|
509
|
-
this.refreshTokensTable = (tableOrTables as
|
|
508
|
+
this.refreshTokensTable = (tableOrTables as RebasePgTable) || (refreshTokens as unknown as RebasePgTable);
|
|
510
509
|
}
|
|
511
510
|
}
|
|
512
511
|
|
|
@@ -595,16 +594,16 @@ export class RefreshTokenService {
|
|
|
595
594
|
* Password reset token service
|
|
596
595
|
*/
|
|
597
596
|
export class PasswordResetTokenService {
|
|
598
|
-
private passwordResetTokensTable:
|
|
597
|
+
private passwordResetTokensTable: RebasePgTable;
|
|
599
598
|
|
|
600
599
|
constructor(
|
|
601
600
|
private db: NodePgDatabase,
|
|
602
|
-
tableOrTables?:
|
|
601
|
+
tableOrTables?: RebasePgTable | Partial<AuthSchemaTables>
|
|
603
602
|
) {
|
|
604
603
|
if (tableOrTables && ((tableOrTables as Partial<AuthSchemaTables>).passwordResetTokens || (tableOrTables as Partial<AuthSchemaTables>).users)) {
|
|
605
|
-
this.passwordResetTokensTable = ((tableOrTables as Partial<AuthSchemaTables>).passwordResetTokens || passwordResetTokens) as
|
|
604
|
+
this.passwordResetTokensTable = ((tableOrTables as Partial<AuthSchemaTables>).passwordResetTokens || passwordResetTokens) as RebasePgTable;
|
|
606
605
|
} else {
|
|
607
|
-
this.passwordResetTokensTable = (tableOrTables as
|
|
606
|
+
this.passwordResetTokensTable = (tableOrTables as RebasePgTable) || (passwordResetTokens as unknown as RebasePgTable);
|
|
608
607
|
}
|
|
609
608
|
}
|
|
610
609
|
|
|
@@ -704,7 +703,7 @@ export class PostgresTokenRepository implements TokenRepository {
|
|
|
704
703
|
|
|
705
704
|
constructor(
|
|
706
705
|
private db: NodePgDatabase,
|
|
707
|
-
tableOrTables?:
|
|
706
|
+
tableOrTables?: RebasePgTable | Partial<AuthSchemaTables>
|
|
708
707
|
) {
|
|
709
708
|
this.refreshTokenService = new RefreshTokenService(db, tableOrTables);
|
|
710
709
|
this.passwordResetTokenService = new PasswordResetTokenService(db, tableOrTables);
|
|
@@ -770,7 +769,7 @@ export class PostgresAuthRepository implements AuthRepository {
|
|
|
770
769
|
|
|
771
770
|
constructor(
|
|
772
771
|
private db: NodePgDatabase,
|
|
773
|
-
tableOrTables?:
|
|
772
|
+
tableOrTables?: RebasePgTable | Partial<AuthSchemaTables>
|
|
774
773
|
) {
|
|
775
774
|
this.userService = new UserService(db, tableOrTables);
|
|
776
775
|
this.tokenRepository = new PostgresTokenRepository(db, tableOrTables);
|
|
@@ -868,9 +867,21 @@ export class PostgresAuthRepository implements AuthRepository {
|
|
|
868
867
|
|
|
869
868
|
async listRoles(): Promise<RoleData[]> {
|
|
870
869
|
return [
|
|
871
|
-
{ id: "admin",
|
|
872
|
-
|
|
873
|
-
|
|
870
|
+
{ id: "admin",
|
|
871
|
+
name: "Admin",
|
|
872
|
+
isAdmin: true,
|
|
873
|
+
defaultPermissions: null,
|
|
874
|
+
collectionPermissions: null },
|
|
875
|
+
{ id: "editor",
|
|
876
|
+
name: "Editor",
|
|
877
|
+
isAdmin: false,
|
|
878
|
+
defaultPermissions: null,
|
|
879
|
+
collectionPermissions: null },
|
|
880
|
+
{ id: "viewer",
|
|
881
|
+
name: "Viewer",
|
|
882
|
+
isAdmin: false,
|
|
883
|
+
defaultPermissions: null,
|
|
884
|
+
collectionPermissions: null }
|
|
874
885
|
];
|
|
875
886
|
}
|
|
876
887
|
|
|
@@ -1016,7 +1027,7 @@ export class PostgresAuthRepository implements AuthRepository {
|
|
|
1016
1027
|
* Handles all MFA-related database operations.
|
|
1017
1028
|
*/
|
|
1018
1029
|
export class MfaService implements MfaRepository {
|
|
1019
|
-
constructor(private db: NodePgDatabase, private schemaName
|
|
1030
|
+
constructor(private db: NodePgDatabase, private schemaName = "rebase") {}
|
|
1020
1031
|
|
|
1021
1032
|
private qualify(tableName: string): string {
|
|
1022
1033
|
return `"${this.schemaName}"."${tableName}"`;
|