@loomcore/api 0.1.19 → 0.1.20

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.
@@ -4,9 +4,10 @@ export declare class CreateAdminUserMigration implements IMigration {
4
4
  private readonly client;
5
5
  private readonly adminEmail;
6
6
  private readonly adminPassword;
7
- constructor(client: Client, adminEmail: string, adminPassword: string);
7
+ private readonly _orgId?;
8
+ constructor(client: Client, adminEmail: string, adminPassword: string, _orgId?: string | undefined);
8
9
  index: number;
9
- execute(_orgId?: string): Promise<{
10
+ execute(): Promise<{
10
11
  success: boolean;
11
12
  error: Error;
12
13
  } | {
@@ -6,20 +6,22 @@ export class CreateAdminUserMigration {
6
6
  client;
7
7
  adminEmail;
8
8
  adminPassword;
9
- constructor(client, adminEmail, adminPassword) {
9
+ _orgId;
10
+ constructor(client, adminEmail, adminPassword, _orgId) {
10
11
  this.client = client;
11
12
  this.adminEmail = adminEmail;
12
13
  this.adminPassword = adminPassword;
14
+ this._orgId = _orgId;
13
15
  }
14
16
  index = 6;
15
- async execute(_orgId) {
17
+ async execute() {
16
18
  const _id = randomUUID().toString();
17
19
  try {
18
20
  const database = new PostgresDatabase(this.client);
19
21
  const authService = new AuthService(database);
20
22
  const adminUser = await authService.createUser(getSystemUserContext(), {
21
23
  _id: _id,
22
- _orgId: _orgId,
24
+ _orgId: this._orgId,
23
25
  email: this.adminEmail,
24
26
  password: this.adminPassword,
25
27
  firstName: 'Admin',
@@ -3,6 +3,7 @@ import { CreateMigrationTableMigration } from "./001-create-migrations-table.mig
3
3
  import { CreateUsersTableMigration } from "./003-create-users-table.migration.js";
4
4
  import { doesTableExist } from "../utils/does-table-exist.util.js";
5
5
  import { CreateAdminUserMigration } from "./006-create-admin-user.migration.js";
6
+ import { getSystemUserContext } from "@loomcore/common/models";
6
7
  export async function setupDatabaseForAuth(client, adminUsername, adminPassword) {
7
8
  let runMigrations = [];
8
9
  if (await doesTableExist(client, 'migrations')) {
@@ -22,8 +23,10 @@ export async function setupDatabaseForAuth(client, adminUsername, adminPassword)
22
23
  migrationsToRun.push(new CreateUsersTableMigration(client));
23
24
  if (!runMigrations.includes(4))
24
25
  migrationsToRun.push(new CreateRefreshTokenTableMigration(client));
25
- if (!runMigrations.includes(6))
26
- migrationsToRun.push(new CreateAdminUserMigration(client, adminUsername, adminPassword));
26
+ if (!runMigrations.includes(6)) {
27
+ const systemUserContext = getSystemUserContext();
28
+ migrationsToRun.push(new CreateAdminUserMigration(client, adminUsername, adminPassword, systemUserContext._orgId));
29
+ }
27
30
  for (const migration of migrationsToRun) {
28
31
  await migration.execute();
29
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcore/api",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "private": false,
5
5
  "description": "Loom Core Api - An opinionated Node.js api using Typescript, Express, and MongoDb or PostgreSQL",
6
6
  "scripts": {