@loomcore/api 0.1.146 → 0.1.148

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.
@@ -67,7 +67,7 @@ export class AuthController {
67
67
  async changePassword(req, res) {
68
68
  const userContext = req.userContext;
69
69
  const body = req.body;
70
- const validationErrors = entityUtils.validate(passwordValidator, { password: body.password });
70
+ const validationErrors = entityUtils.validate(UserSpec, { password: body.password }, true, passwordValidator);
71
71
  entityUtils.handleValidationResult(validationErrors, 'AuthController.changePassword');
72
72
  const updateResult = await this.authService.changeLoggedInUsersPassword(userContext, body);
73
73
  apiUtils.apiResponse(res, 200, { data: updateResult });
@@ -40,8 +40,8 @@ export const getPostgresInitialSchema = (dbConfig) => {
40
40
  "auth_token" TEXT,
41
41
  "_created" TIMESTAMPTZ NOT NULL,
42
42
  "_createdBy" INTEGER NOT NULL,
43
- "_updated" TIMESTAMPTZ NOT NULL,
44
- "_updatedBy" INTEGER NOT NULL,
43
+ "_updated" TIMESTAMPTZ,
44
+ "_updatedBy" INTEGER,
45
45
  "_deleted" TIMESTAMPTZ,
46
46
  "_deletedBy" INTEGER
47
47
  )
@@ -78,8 +78,8 @@ export const getPostgresInitialSchema = (dbConfig) => {
78
78
  "extended_types" INTEGER,
79
79
  "_created" TIMESTAMPTZ NOT NULL,
80
80
  "_createdBy" INTEGER NOT NULL,
81
- "_updated" TIMESTAMPTZ NOT NULL,
82
- "_updatedBy" INTEGER NOT NULL,
81
+ "_updated" TIMESTAMPTZ,
82
+ "_updatedBy" INTEGER,
83
83
  "_deleted" TIMESTAMPTZ,
84
84
  "_deletedBy" INTEGER,
85
85
  ${personsUniqueConstraints}
@@ -116,8 +116,8 @@ export const getPostgresInitialSchema = (dbConfig) => {
116
116
  "_lastPasswordChange" TIMESTAMPTZ,
117
117
  "_created" TIMESTAMPTZ NOT NULL,
118
118
  "_createdBy" INTEGER NOT NULL,
119
- "_updated" TIMESTAMPTZ NOT NULL,
120
- "_updatedBy" INTEGER NOT NULL,
119
+ "_updated" TIMESTAMPTZ,
120
+ "_updatedBy" INTEGER,
121
121
  "_deleted" TIMESTAMPTZ,
122
122
  "_deletedBy" INTEGER,
123
123
  ${uniqueConstraint}
@@ -173,8 +173,8 @@ export const getPostgresInitialSchema = (dbConfig) => {
173
173
  "expires_on" BIGINT NOT NULL,
174
174
  "_created" TIMESTAMPTZ NOT NULL,
175
175
  "_createdBy" INTEGER NOT NULL,
176
- "_updated" TIMESTAMPTZ NOT NULL,
177
- "_updatedBy" INTEGER NOT NULL,
176
+ "_updated" TIMESTAMPTZ,
177
+ "_updatedBy" INTEGER,
178
178
  "_deleted" TIMESTAMPTZ,
179
179
  "_deletedBy" INTEGER,
180
180
  ${uniqueConstraint}
@@ -223,8 +223,8 @@ export const getPostgresInitialSchema = (dbConfig) => {
223
223
  "role_id" INTEGER NOT NULL,
224
224
  "_created" TIMESTAMPTZ NOT NULL,
225
225
  "_createdBy" INTEGER NOT NULL,
226
- "_updated" TIMESTAMPTZ NOT NULL,
227
- "_updatedBy" INTEGER NOT NULL,
226
+ "_updated" TIMESTAMPTZ,
227
+ "_updatedBy" INTEGER,
228
228
  "_deleted" TIMESTAMPTZ,
229
229
  "_deletedBy" INTEGER,
230
230
  CONSTRAINT "fk_user_roles_user" FOREIGN KEY("user_id") REFERENCES "users"("_id") ON DELETE CASCADE,
@@ -278,8 +278,8 @@ export const getPostgresInitialSchema = (dbConfig) => {
278
278
  "config" JSONB,
279
279
  "_created" TIMESTAMPTZ NOT NULL,
280
280
  "_createdBy" INTEGER NOT NULL,
281
- "_updated" TIMESTAMPTZ NOT NULL,
282
- "_updatedBy" INTEGER NOT NULL,
281
+ "_updated" TIMESTAMPTZ,
282
+ "_updatedBy" INTEGER,
283
283
  "_deleted" TIMESTAMPTZ,
284
284
  "_deletedBy" INTEGER,
285
285
  CONSTRAINT "fk_authorizations_role" FOREIGN KEY("role_id") REFERENCES "roles"("_id") ON DELETE CASCADE,
@@ -297,9 +297,9 @@ export const getPostgresInitialSchema = (dbConfig) => {
297
297
  name: '00000000000011_data-meta-org',
298
298
  up: async ({ context: pool }) => {
299
299
  const result = await pool.query(`
300
- INSERT INTO "organizations"("name", "code", "status", "is_meta_org", "_created", "_createdBy", "_updated", "_updatedBy")
301
- VALUES($1, $2, 1, true, NOW(), 0, NOW(), 0)
302
- RETURNING "_id", "name", "code", "status", "is_meta_org", "_created", "_createdBy", "_updated", "_updatedBy"
300
+ INSERT INTO "organizations"("name", "code", "status", "is_meta_org", "_created", "_createdBy")
301
+ VALUES($1, $2, 1, true, NOW(), 0)
302
+ RETURNING "_id", "name", "code", "status", "is_meta_org", "_created", "_createdBy"
303
303
  `, [dbConfig.multiTenant?.metaOrgName, dbConfig.multiTenant?.metaOrgCode]);
304
304
  if (result.rowCount === 0) {
305
305
  throw new Error('Failed to create meta organization');
@@ -330,20 +330,20 @@ export const getPostgresInitialSchema = (dbConfig) => {
330
330
  const client = await pool.connect();
331
331
  try {
332
332
  const personResult = isMultiTenant && orgId
333
- ? await client.query(`INSERT INTO "persons"("_orgId", "first_name", "last_name", "is_agent", "is_client", "is_employee", "_created", "_createdBy", "_updated", "_updatedBy")
334
- VALUES($1, 'Admin', 'User', false, false, false, NOW(), 0, NOW(), 0)
333
+ ? await client.query(`INSERT INTO "persons"("_orgId", "first_name", "last_name", "is_agent", "is_client", "is_employee", "_created", "_createdBy")
334
+ VALUES($1, 'Admin', 'User', false, false, false, NOW(), 0)
335
335
  RETURNING "_id"`, [orgId])
336
- : await client.query(`INSERT INTO "persons"("first_name", "last_name", "is_agent", "is_client", "is_employee", "_created", "_createdBy", "_updated", "_updatedBy")
337
- VALUES('Admin', 'User', false, false, false, NOW(), 0, NOW(), 0)
336
+ : await client.query(`INSERT INTO "persons"("first_name", "last_name", "is_agent", "is_client", "is_employee", "_created", "_createdBy")
337
+ VALUES('Admin', 'User', false, false, false, NOW(), 0)
338
338
  RETURNING "_id"`);
339
339
  const personId = personResult.rows[0]._id;
340
340
  if (isMultiTenant && orgId) {
341
- await client.query(`INSERT INTO "users"("_orgId", "email", "display_name", "password", "person_id", "_created", "_createdBy", "_updated", "_updatedBy")
342
- VALUES($1, $2, 'Admin User', $3, $4, NOW(), 0, NOW(), 0)`, [orgId, email, hashedPassword, personId]);
341
+ await client.query(`INSERT INTO "users"("_orgId", "email", "display_name", "password", "person_id", "_created", "_createdBy")
342
+ VALUES($1, $2, 'Admin User', $3, $4, NOW(), 0)`, [orgId, email, hashedPassword, personId]);
343
343
  }
344
344
  else {
345
- await client.query(`INSERT INTO "users"("email", "display_name", "password", "person_id", "_created", "_createdBy", "_updated", "_updatedBy")
346
- VALUES($1, 'Admin User', $2, $3, NOW(), 0, NOW(), 0)`, [email, hashedPassword, personId]);
345
+ await client.query(`INSERT INTO "users"("email", "display_name", "password", "person_id", "_created", "_createdBy")
346
+ VALUES($1, 'Admin User', $2, $3, NOW(), 0)`, [email, hashedPassword, personId]);
347
347
  }
348
348
  }
349
349
  finally {
@@ -395,12 +395,12 @@ export const getPostgresInitialSchema = (dbConfig) => {
395
395
  const roleId = roleResult.rows[0]._id;
396
396
  const userRoleResult = isMultiTenant
397
397
  ? await client.query(`
398
- INSERT INTO "user_roles"("_orgId", "user_id", "role_id", "_created", "_createdBy", "_updated", "_updatedBy")
399
- VALUES($1, $2, $3, NOW(), 0, NOW(), 0)
398
+ INSERT INTO "user_roles"("_orgId", "user_id", "role_id", "_created", "_createdBy")
399
+ VALUES($1, $2, $3, NOW(), 0)
400
400
  `, [metaOrg._id, adminUserId, roleId])
401
401
  : await client.query(`
402
- INSERT INTO "user_roles"("user_id", "role_id", "_created", "_createdBy", "_updated", "_updatedBy")
403
- VALUES($1, $2, NOW(), 0, NOW(), 0)
402
+ INSERT INTO "user_roles"("user_id", "role_id", "_created", "_createdBy")
403
+ VALUES($1, $2, NOW(), 0)
404
404
  `, [adminUserId, roleId]);
405
405
  if (userRoleResult.rowCount === 0) {
406
406
  throw new Error('Failed to create user role');
@@ -424,16 +424,16 @@ export const getPostgresInitialSchema = (dbConfig) => {
424
424
  ? await client.query(`
425
425
  INSERT INTO "authorizations"(
426
426
  "_orgId", "role_id", "feature_id",
427
- "_created", "_createdBy", "_updated", "_updatedBy"
427
+ "_created", "_createdBy"
428
428
  )
429
- VALUES($1, $2, $3, NOW(), 0, NOW(), 0)
429
+ VALUES($1, $2, $3, NOW(), 0)
430
430
  `, [metaOrg._id, roleId, featureId])
431
431
  : await client.query(`
432
432
  INSERT INTO "authorizations"(
433
433
  "role_id", "feature_id",
434
- "_created", "_createdBy", "_updated", "_updatedBy"
434
+ "_created", "_createdBy"
435
435
  )
436
- VALUES($1, $2, NOW(), 0, NOW(), 0)
436
+ VALUES($1, $2, NOW(), 0)
437
437
  `, [roleId, featureId]);
438
438
  if (authorizationResult.rowCount === 0) {
439
439
  throw new Error('Failed to create admin authorization');
@@ -212,7 +212,7 @@ export class AuthService extends MultiTenantApiService {
212
212
  if (retrievedPasswordResetToken.token !== passwordResetToken || retrievedPasswordResetToken.expiresOn < Date.now()) {
213
213
  throw new BadRequestError('Invalid password reset token');
214
214
  }
215
- const validationErrors = entityUtils.validate(passwordValidator, { password: password });
215
+ const validationErrors = entityUtils.validate(UserSpec, { password: password }, true, passwordValidator);
216
216
  entityUtils.handleValidationResult(validationErrors, 'AuthService.resetPassword');
217
217
  const result = await this.changePassword(getSystemUserContext(), { email: lowerCaseEmail }, password);
218
218
  console.log(`password changed using forgot-password for email: ${lowerCaseEmail}`);
@@ -37,14 +37,12 @@ export class GenericApiService {
37
37
  return { queryObject, operations };
38
38
  }
39
39
  validate(doc, isPartial = false) {
40
- const validator = isPartial ? this.modelSpec.partialValidator : this.modelSpec.validator;
41
- return entityUtils.validate(validator, doc);
40
+ return entityUtils.validate(this.modelSpec, doc, isPartial);
42
41
  }
43
42
  validateMany(docs, isPartial = false) {
44
- const validator = isPartial ? this.modelSpec.partialValidator : this.modelSpec.validator;
45
43
  let allErrors = [];
46
44
  for (const doc of docs) {
47
- const errors = entityUtils.validate(validator, doc);
45
+ const errors = entityUtils.validate(this.modelSpec, doc, isPartial);
48
46
  if (errors && errors.length > 0) {
49
47
  allErrors.push(...errors);
50
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcore/api",
3
- "version": "0.1.146",
3
+ "version": "0.1.148",
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": {
@@ -58,7 +58,7 @@
58
58
  "qs": "^6.15.0"
59
59
  },
60
60
  "peerDependencies": {
61
- "@loomcore/common": "^0.0.67",
61
+ "@loomcore/common": "^0.0.70",
62
62
  "@sinclair/typebox": "0.34.33",
63
63
  "cookie-parser": "^1.4.6",
64
64
  "cors": "^2.8.5",