@loomcore/api 0.1.27 → 0.1.29

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.
Files changed (44) hide show
  1. package/dist/__tests__/common-test.utils.d.ts +7 -2
  2. package/dist/__tests__/common-test.utils.js +65 -11
  3. package/dist/__tests__/postgres-test-migrations/run-test-migrations.js +0 -2
  4. package/dist/__tests__/postgres.test-database.js +7 -6
  5. package/dist/__tests__/test-express-app.js +2 -31
  6. package/dist/__tests__/test-objects.d.ts +1 -0
  7. package/dist/__tests__/test-objects.js +5 -1
  8. package/dist/config/base-api-config.js +1 -1
  9. package/dist/controllers/api.controller.d.ts +2 -3
  10. package/dist/controllers/api.controller.js +12 -12
  11. package/dist/controllers/auth.controller.js +2 -2
  12. package/dist/controllers/users.controller.d.ts +2 -1
  13. package/dist/controllers/users.controller.js +2 -2
  14. package/dist/databases/postgres/migrations/003-create-users-table.migration.js +5 -2
  15. package/dist/databases/postgres/migrations/004-create-refresh-tokens-table.migration.js +5 -1
  16. package/dist/databases/postgres/migrations/005-create-meta-org.migration.d.ts +1 -5
  17. package/dist/databases/postgres/migrations/005-create-meta-org.migration.js +7 -7
  18. package/dist/databases/postgres/migrations/006-create-admin-user.migration.d.ts +6 -3
  19. package/dist/databases/postgres/migrations/006-create-admin-user.migration.js +16 -13
  20. package/dist/databases/postgres/migrations/007-create-roles-table.migration.d.ts +1 -1
  21. package/dist/databases/postgres/migrations/007-create-roles-table.migration.js +6 -3
  22. package/dist/databases/postgres/migrations/008-create-user-roles-table.migration.d.ts +1 -1
  23. package/dist/databases/postgres/migrations/008-create-user-roles-table.migration.js +6 -2
  24. package/dist/databases/postgres/migrations/009-create-features-table.migration.d.ts +1 -1
  25. package/dist/databases/postgres/migrations/009-create-features-table.migration.js +6 -3
  26. package/dist/databases/postgres/migrations/010-create-authorizations-table.migration.d.ts +1 -1
  27. package/dist/databases/postgres/migrations/010-create-authorizations-table.migration.js +6 -3
  28. package/dist/databases/postgres/migrations/011-create-admin-authorization.migration.d.ts +3 -3
  29. package/dist/databases/postgres/migrations/011-create-admin-authorization.migration.js +22 -9
  30. package/dist/databases/postgres/migrations/database-builder.d.ts +15 -0
  31. package/dist/databases/postgres/migrations/database-builder.interface.d.ts +10 -0
  32. package/dist/databases/postgres/migrations/database-builder.interface.js +1 -0
  33. package/dist/databases/postgres/migrations/database-builder.js +62 -0
  34. package/dist/databases/postgres/migrations/setup-for-auth.migration.d.ts +5 -2
  35. package/dist/databases/postgres/migrations/setup-for-auth.migration.js +12 -18
  36. package/dist/databases/postgres/migrations/setup-for-multitenant.migration.d.ts +5 -3
  37. package/dist/databases/postgres/migrations/setup-for-multitenant.migration.js +7 -9
  38. package/dist/models/base-api-config.interface.d.ts +11 -5
  39. package/dist/services/email.service.js +6 -3
  40. package/dist/utils/api.utils.d.ts +1 -2
  41. package/dist/utils/api.utils.js +2 -3
  42. package/package.json +2 -2
  43. package/dist/__tests__/postgres-test-migrations/004-create-test-users-table.migration.d.ts +0 -21
  44. package/dist/__tests__/postgres-test-migrations/004-create-test-users-table.migration.js +0 -75
@@ -1,12 +1,11 @@
1
1
  import { Request, Response } from 'express';
2
- import { TSchema } from '@sinclair/typebox';
3
2
  import { IQueryOptions, IError, IPagedResult, IModelSpec } from '@loomcore/common/models';
4
3
  export interface IApiResponseOptions<T> {
5
4
  messages?: string[];
6
5
  errors?: IError[];
7
6
  data?: T;
8
7
  }
9
- declare function apiResponse<T>(response: Response, status: number, options?: IApiResponseOptions<T>, modelSpec?: IModelSpec, publicSchema?: TSchema): Response;
8
+ declare function apiResponse<T>(response: Response, status: number, options?: IApiResponseOptions<T>, modelSpec?: IModelSpec, publicSpec?: IModelSpec): Response;
10
9
  declare function getQueryOptionsFromRequest(request: Request): IQueryOptions;
11
10
  declare function getPagedResult<T>(entities: T[], totalRows: number, queryOptions: IQueryOptions): IPagedResult<T>;
12
11
  export declare const apiUtils: {
@@ -1,9 +1,8 @@
1
- import { entityUtils } from '@loomcore/common/utils';
2
1
  import { DefaultQueryOptions } from '@loomcore/common/models';
3
- function apiResponse(response, status, options = {}, modelSpec, publicSchema) {
2
+ function apiResponse(response, status, options = {}, modelSpec, publicSpec) {
4
3
  const success = status >= 200 && status < 300;
5
4
  let apiResponse;
6
- const specForEncoding = publicSchema ? entityUtils.getModelSpec(publicSchema) : modelSpec;
5
+ const specForEncoding = publicSpec ?? modelSpec;
7
6
  if (specForEncoding && options.data) {
8
7
  if (Array.isArray(options.data)) {
9
8
  options.data = options.data.map((item) => specForEncoding.encode(item));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcore/api",
3
- "version": "0.1.27",
3
+ "version": "0.1.29",
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": {
@@ -53,7 +53,7 @@
53
53
  "qs": "^6.14.0"
54
54
  },
55
55
  "peerDependencies": {
56
- "@loomcore/common": "^0.0.28",
56
+ "@loomcore/common": "^0.0.29",
57
57
  "@sinclair/typebox": "0.34.33",
58
58
  "cookie-parser": "^1.4.6",
59
59
  "cors": "^2.8.5",
@@ -1,21 +0,0 @@
1
- import { Client } from "pg";
2
- import { IMigration } from "../../databases/postgres/migrations/index.js";
3
- export declare class CreateTestUsersTableMigration implements IMigration {
4
- private readonly client;
5
- constructor(client: Client);
6
- index: number;
7
- execute(_orgId?: string): Promise<{
8
- success: boolean;
9
- error: Error;
10
- } | {
11
- success: boolean;
12
- error: null;
13
- }>;
14
- revert(_orgId?: string): Promise<{
15
- success: boolean;
16
- error: Error;
17
- } | {
18
- success: boolean;
19
- error: null;
20
- }>;
21
- }
@@ -1,75 +0,0 @@
1
- import { randomUUID } from "crypto";
2
- export class CreateTestUsersTableMigration {
3
- client;
4
- constructor(client) {
5
- this.client = client;
6
- }
7
- index = 4;
8
- async execute(_orgId) {
9
- const _id = randomUUID().toString();
10
- try {
11
- await this.client.query(`
12
- CREATE TABLE "testUsers" (
13
- "_id" VARCHAR(255) PRIMARY KEY,
14
- "_orgId" VARCHAR(255),
15
- "email" VARCHAR(255) NOT NULL,
16
- "password" VARCHAR(255) NOT NULL,
17
- "firstName" VARCHAR(255),
18
- "lastName" VARCHAR(255),
19
- "displayName" VARCHAR(255),
20
- "_lastLoggedIn" TIMESTAMP,
21
- "_lastPasswordChange" TIMESTAMP,
22
- "_created" TIMESTAMP NOT NULL,
23
- "_createdBy" VARCHAR(255) NOT NULL,
24
- "_updated" TIMESTAMP NOT NULL,
25
- "_updatedBy" VARCHAR(255) NOT NULL,
26
- "_deleted" TIMESTAMP,
27
- "_deletedBy" VARCHAR(255)
28
- )
29
- `);
30
- }
31
- catch (error) {
32
- return { success: false, error: new Error(`Error creating test users table: ${error.message}`) };
33
- }
34
- if (_orgId) {
35
- try {
36
- await this.client.query(`
37
- Insert into "migrations" ("_id", "_orgId", "index", "hasRun", "reverted") values ('${_id}', '${_orgId}', ${this.index}, TRUE, FALSE);
38
- `);
39
- }
40
- catch (error) {
41
- return { success: false, error: new Error(`Error inserting migration ${this.index} to migrations table: ${error.message}`) };
42
- }
43
- }
44
- else {
45
- try {
46
- await this.client.query(`
47
- Insert into "migrations" ("_id", "index", "hasRun", "reverted") values ('${_id}', ${this.index}, TRUE, FALSE);
48
- `);
49
- }
50
- catch (error) {
51
- return { success: false, error: new Error(`Error inserting migration ${this.index} to migrations table: ${error.message}`) };
52
- }
53
- }
54
- return { success: true, error: null };
55
- }
56
- async revert(_orgId) {
57
- try {
58
- await this.client.query(`
59
- DROP TABLE "testUsers";
60
- `);
61
- }
62
- catch (error) {
63
- return { success: false, error: new Error(`Error dropping test users table: ${error.message}`) };
64
- }
65
- try {
66
- await this.client.query(`
67
- Update "migrations" SET "reverted" = TRUE WHERE "index" = '${this.index}' AND "_orgId" = '${_orgId}';
68
- `);
69
- }
70
- catch (error) {
71
- return { success: false, error: new Error(`Error updating migration record: ${error.message}`) };
72
- }
73
- return { success: true, error: null };
74
- }
75
- }