@loomcore/api 0.2.42 → 0.2.45
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/LICENSE +201 -201
- package/dist/__tests__/common-test.utils.d.ts +13 -13
- package/dist/__tests__/common-test.utils.js +72 -72
- package/dist/__tests__/models/category.model.d.ts +1 -1
- package/dist/__tests__/models/category.model.js +2 -2
- package/dist/__tests__/models/product-with-category.model.d.ts +3 -3
- package/dist/__tests__/models/product-with-category.model.js +4 -4
- package/dist/__tests__/models/product.model.d.ts +2 -2
- package/dist/__tests__/models/product.model.js +2 -2
- package/dist/__tests__/models/test-entity.model.d.ts +2 -2
- package/dist/__tests__/models/test-entity.model.js +2 -2
- package/dist/__tests__/models/test-item.model.d.ts +1 -1
- package/dist/__tests__/models/test-item.model.js +3 -3
- package/dist/__tests__/mongo-db.test-database.js +1 -1
- package/dist/__tests__/postgres-test-migrations/postgres-test-schema.d.ts +2 -2
- package/dist/__tests__/postgres-test-migrations/postgres-test-schema.js +38 -38
- package/dist/__tests__/postgres.test-database.d.ts +2 -2
- package/dist/__tests__/postgres.test-database.js +25 -25
- package/dist/__tests__/test-database.interface.d.ts +1 -1
- package/dist/__tests__/test-email-client.d.ts +1 -1
- package/dist/__tests__/test-express-app.d.ts +3 -3
- package/dist/__tests__/test-express-app.js +12 -12
- package/dist/__tests__/test-objects.d.ts +1 -1
- package/dist/__tests__/test-objects.js +26 -26
- package/dist/config/base-api-config.d.ts +2 -2
- package/dist/config/base-api-config.js +17 -17
- package/dist/controllers/auth.controller.d.ts +4 -4
- package/dist/controllers/auth.controller.js +32 -32
- package/dist/controllers/authorizations.controller.d.ts +4 -4
- package/dist/controllers/authorizations.controller.js +4 -4
- package/dist/controllers/features.controller.d.ts +4 -4
- package/dist/controllers/features.controller.js +4 -4
- package/dist/controllers/index.d.ts +10 -10
- package/dist/controllers/index.js +10 -10
- package/dist/controllers/organizations.controller.d.ts +5 -5
- package/dist/controllers/organizations.controller.js +10 -10
- package/dist/controllers/roles.controller.d.ts +4 -4
- package/dist/controllers/roles.controller.js +4 -4
- package/dist/controllers/types.d.ts +2 -2
- package/dist/controllers/user-roles.controller.d.ts +4 -4
- package/dist/controllers/user-roles.controller.js +4 -4
- package/dist/controllers/users.controller.d.ts +5 -5
- package/dist/controllers/users.controller.js +4 -4
- package/dist/databases/models/database.interface.d.ts +5 -5
- package/dist/databases/mongo-db/commands/mongo-batch-update.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-batch-update.command.js +5 -5
- package/dist/databases/mongo-db/commands/mongo-create-many.command.d.ts +1 -1
- package/dist/databases/mongo-db/commands/mongo-create-many.command.js +1 -1
- package/dist/databases/mongo-db/commands/mongo-create.command.d.ts +1 -1
- package/dist/databases/mongo-db/commands/mongo-create.command.js +1 -1
- package/dist/databases/mongo-db/commands/mongo-delete-by-id.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-delete-by-id.command.js +4 -4
- package/dist/databases/mongo-db/commands/mongo-delete-many.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-delete-many.command.js +2 -2
- package/dist/databases/mongo-db/commands/mongo-full-updateby-id.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-full-updateby-id.command.js +4 -4
- package/dist/databases/mongo-db/commands/mongo-partial-update-by-id.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-partial-update-by-id.command.js +4 -4
- package/dist/databases/mongo-db/commands/mongo-update.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-update.command.js +3 -3
- package/dist/databases/mongo-db/migrations/mongo-initial-schema.d.ts +2 -2
- package/dist/databases/mongo-db/migrations/mongo-initial-schema.js +108 -108
- package/dist/databases/mongo-db/models/no-sql-pipeline.d.ts +4 -4
- package/dist/databases/mongo-db/models/no-sql-pipeline.interface.d.ts +3 -3
- package/dist/databases/mongo-db/models/no-sql-pipeline.js +1 -1
- package/dist/databases/mongo-db/mongo-db.database.d.ts +7 -7
- package/dist/databases/mongo-db/mongo-db.database.js +5 -5
- package/dist/databases/mongo-db/queries/mongo-find-one.query.d.ts +2 -2
- package/dist/databases/mongo-db/queries/mongo-find-one.query.js +1 -1
- package/dist/databases/mongo-db/queries/mongo-find.query.d.ts +2 -2
- package/dist/databases/mongo-db/queries/mongo-find.query.js +1 -1
- package/dist/databases/mongo-db/queries/mongo-get-all.query.d.ts +2 -2
- package/dist/databases/mongo-db/queries/mongo-get-all.query.js +1 -1
- package/dist/databases/mongo-db/queries/mongo-get-by-id.query.d.ts +4 -4
- package/dist/databases/mongo-db/queries/mongo-get-by-id.query.js +3 -3
- package/dist/databases/mongo-db/queries/mongo-get-count.query.d.ts +1 -1
- package/dist/databases/mongo-db/queries/mongo-get.query.d.ts +3 -3
- package/dist/databases/mongo-db/queries/mongo-get.query.js +2 -2
- package/dist/databases/mongo-db/utils/build-find-options.util.d.ts +2 -2
- package/dist/databases/mongo-db/utils/build-mongo-url.util.d.ts +1 -1
- package/dist/databases/mongo-db/utils/build-mongo-url.util.js +4 -4
- package/dist/databases/operations/__tests__/models/test-agent.model.d.ts +2 -2
- package/dist/databases/operations/__tests__/models/test-agent.model.js +3 -3
- package/dist/databases/operations/__tests__/models/test-client-report.model.d.ts +4 -4
- package/dist/databases/operations/__tests__/models/test-client-report.model.js +5 -5
- package/dist/databases/operations/__tests__/models/test-district.model.d.ts +2 -2
- package/dist/databases/operations/__tests__/models/test-district.model.js +2 -2
- package/dist/databases/operations/__tests__/models/test-email-address.model.d.ts +1 -1
- package/dist/databases/operations/__tests__/models/test-email-address.model.js +2 -2
- package/dist/databases/operations/__tests__/models/test-person.model.d.ts +4 -4
- package/dist/databases/operations/__tests__/models/test-person.model.js +4 -4
- package/dist/databases/operations/__tests__/models/test-phone-number.model.d.ts +1 -1
- package/dist/databases/operations/__tests__/models/test-phone-number.model.js +2 -2
- package/dist/databases/operations/__tests__/models/test-policy.model.d.ts +3 -3
- package/dist/databases/operations/__tests__/models/test-policy.model.js +4 -4
- package/dist/databases/operations/__tests__/models/test-premium.model.d.ts +1 -1
- package/dist/databases/operations/__tests__/models/test-premium.model.js +2 -2
- package/dist/databases/operations/__tests__/models/test-school.model.d.ts +2 -2
- package/dist/databases/operations/__tests__/models/test-school.model.js +2 -2
- package/dist/databases/operations/__tests__/models/test-state.model.d.ts +1 -1
- package/dist/databases/operations/__tests__/models/test-state.model.js +2 -2
- package/dist/databases/operations/operation.d.ts +3 -3
- package/dist/databases/postgres/commands/postgres-batch-update.command.d.ts +1 -1
- package/dist/databases/postgres/commands/postgres-batch-update.command.js +11 -11
- package/dist/databases/postgres/commands/postgres-create-many.command.js +5 -5
- package/dist/databases/postgres/commands/postgres-create.command.d.ts +3 -3
- package/dist/databases/postgres/commands/postgres-create.command.js +5 -5
- package/dist/databases/postgres/commands/postgres-delete-by-id.command.d.ts +1 -1
- package/dist/databases/postgres/commands/postgres-delete-by-id.command.js +1 -1
- package/dist/databases/postgres/commands/postgres-delete-many.command.d.ts +2 -2
- package/dist/databases/postgres/commands/postgres-delete-many.command.js +1 -1
- package/dist/databases/postgres/commands/postgres-full-update-by-id.command.d.ts +1 -1
- package/dist/databases/postgres/commands/postgres-full-update-by-id.command.js +4 -4
- package/dist/databases/postgres/commands/postgres-partial-update-by-id.command.d.ts +1 -1
- package/dist/databases/postgres/commands/postgres-partial-update-by-id.command.js +11 -11
- package/dist/databases/postgres/commands/postgres-update.command.d.ts +2 -2
- package/dist/databases/postgres/commands/postgres-update.command.js +11 -11
- package/dist/databases/postgres/migrations/postgres-initial-schema.d.ts +2 -2
- package/dist/databases/postgres/migrations/postgres-initial-schema.js +69 -69
- package/dist/databases/postgres/postgres.database.d.ts +6 -6
- package/dist/databases/postgres/postgres.database.js +18 -18
- package/dist/databases/postgres/queries/postgres-find-one.query.d.ts +1 -1
- package/dist/databases/postgres/queries/postgres-find-one.query.js +2 -2
- package/dist/databases/postgres/queries/postgres-find.query.d.ts +1 -1
- package/dist/databases/postgres/queries/postgres-find.query.js +2 -2
- package/dist/databases/postgres/queries/postgres-get-all.query.d.ts +1 -1
- package/dist/databases/postgres/queries/postgres-get-all.query.js +3 -3
- package/dist/databases/postgres/queries/postgres-get-by-id.query.d.ts +1 -1
- package/dist/databases/postgres/queries/postgres-get-by-id.query.js +5 -5
- package/dist/databases/postgres/queries/postgres-get-count.query.js +1 -1
- package/dist/databases/postgres/queries/postgres-get.query.d.ts +2 -2
- package/dist/databases/postgres/queries/postgres-get.query.js +9 -9
- package/dist/databases/postgres/utils/build-count-query.d.ts +1 -1
- package/dist/databases/postgres/utils/build-count-query.js +1 -1
- package/dist/databases/postgres/utils/build-join-clauses.d.ts +1 -1
- package/dist/databases/postgres/utils/build-join-clauses.js +7 -7
- package/dist/databases/postgres/utils/build-order-by-clause.d.ts +1 -1
- package/dist/databases/postgres/utils/build-pagination-clause.d.ts +1 -1
- package/dist/databases/postgres/utils/build-postgres-url.util.d.ts +1 -1
- package/dist/databases/postgres/utils/build-postgres-url.util.js +2 -2
- package/dist/databases/postgres/utils/build-select-clause.js +9 -9
- package/dist/databases/postgres/utils/build-where-clause.d.ts +1 -1
- package/dist/databases/postgres/utils/build-where-clause.js +1 -1
- package/dist/databases/postgres/utils/columns-and-values-from-entity.d.ts +1 -1
- package/dist/databases/postgres/utils/does-table-exist.util.d.ts +1 -1
- package/dist/databases/postgres/utils/does-table-exist.util.js +5 -5
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +1 -0
- package/dist/middleware/authorize/authenticate-request.d.ts +2 -2
- package/dist/middleware/authorize/authenticate-request.js +5 -5
- package/dist/middleware/index.d.ts +4 -4
- package/dist/middleware/index.js +4 -4
- package/dist/models/app-config.interface.d.ts +1 -1
- package/dist/models/base-api-config.interface.d.ts +6 -6
- package/dist/models/initial-database-config.interface.d.ts +3 -3
- package/dist/models/log-level.type.d.ts +1 -1
- package/dist/services/authorizations.service.d.ts +3 -3
- package/dist/services/authorizations.service.js +7 -7
- package/dist/services/email.service.js +5 -5
- package/dist/services/features.service.d.ts +3 -3
- package/dist/services/features.service.js +4 -4
- package/dist/services/generic-api-service/generic-api-service.interface.d.ts +6 -6
- package/dist/services/generic-api-service/generic-api.service.d.ts +8 -8
- package/dist/services/generic-api-service/generic-api.service.js +7 -7
- package/dist/services/index.d.ts +16 -16
- package/dist/services/index.js +16 -16
- package/dist/services/multi-tenant-api.service.d.ts +4 -4
- package/dist/services/multi-tenant-api.service.js +9 -9
- package/dist/services/organization-domain.service.d.ts +3 -3
- package/dist/services/organization-domain.service.js +3 -3
- package/dist/services/organization.service.d.ts +4 -4
- package/dist/services/organization.service.js +7 -7
- package/dist/services/password-reset-token.service.d.ts +3 -3
- package/dist/services/password-reset-token.service.js +5 -5
- package/dist/services/refresh-token.service.d.ts +3 -3
- package/dist/services/refresh-token.service.js +3 -3
- package/dist/services/roles.service.d.ts +3 -3
- package/dist/services/roles.service.js +4 -4
- package/dist/services/tenant-query-decorator.d.ts +1 -1
- package/dist/services/tenant-query-decorator.js +8 -8
- package/dist/services/user-roles.service.d.ts +3 -3
- package/dist/services/user-roles.service.js +4 -4
- package/dist/services/user.service.d.ts +4 -4
- package/dist/services/user.service.js +11 -11
- package/dist/services/utils/audit-for-create.util.d.ts +1 -1
- package/dist/services/utils/audit-for-create.util.js +2 -2
- package/dist/services/utils/audit-for-update.util.d.ts +1 -1
- package/dist/services/utils/audit-for-update.util.js +2 -2
- package/dist/services/utils/strip-sender-provided-system-properties.util.d.ts +1 -1
- package/dist/services/utils/strip-sender-provided-system-properties.util.js +4 -4
- package/dist/utils/auth/assert-admin-or-feature.util.d.ts +1 -1
- package/dist/utils/auth/assert-admin-or-feature.util.js +2 -2
- package/dist/utils/auth/assert-admin.util.d.ts +1 -1
- package/dist/utils/auth/assert-admin.util.js +2 -2
- package/dist/utils/auth/assert-owner-or-admin.util.d.ts +1 -1
- package/dist/utils/auth/assert-owner-or-admin.util.js +2 -2
- package/dist/utils/auth/assert-user-has-feature.util.d.ts +1 -1
- package/dist/utils/auth/assert-user-has-feature.util.js +1 -1
- package/dist/utils/auth/assert-user-or-admin.util.d.ts +2 -2
- package/dist/utils/auth/assert-user-or-admin.util.js +2 -2
- package/dist/utils/auth/attempt-login.util.d.ts +4 -4
- package/dist/utils/auth/attempt-login.util.js +8 -8
- package/dist/utils/auth/auth-user-specs.util.d.ts +1 -1
- package/dist/utils/auth/auth-user-specs.util.js +3 -3
- package/dist/utils/auth/change-password.util.d.ts +4 -4
- package/dist/utils/auth/change-password.util.js +2 -2
- package/dist/utils/auth/create-new-refresh-token.util.d.ts +3 -3
- package/dist/utils/auth/create-new-refresh-token.util.js +8 -8
- package/dist/utils/auth/create-new-tokens.util.d.ts +1 -1
- package/dist/utils/auth/create-new-tokens.util.js +3 -3
- package/dist/utils/auth/generate-device-id.util.js +2 -2
- package/dist/utils/auth/generate-refresh-token.util.js +2 -2
- package/dist/utils/auth/get-active-refresh-token.util.d.ts +2 -2
- package/dist/utils/auth/get-active-refresh-token.util.js +1 -1
- package/dist/utils/auth/get-and-set-device-id-cookie.util.d.ts +1 -1
- package/dist/utils/auth/get-and-set-device-id-cookie.util.js +4 -4
- package/dist/utils/auth/get-auth-config.util.d.ts +1 -1
- package/dist/utils/auth/get-auth-config.util.js +3 -3
- package/dist/utils/auth/get-device-id-from-cookie.util.d.ts +1 -1
- package/dist/utils/auth/index.d.ts +26 -26
- package/dist/utils/auth/index.js +26 -26
- package/dist/utils/auth/is-admin.util.d.ts +1 -1
- package/dist/utils/auth/is-admin.util.js +1 -1
- package/dist/utils/auth/log-user-in.util.d.ts +3 -3
- package/dist/utils/auth/log-user-in.util.js +5 -5
- package/dist/utils/auth/request-token-using-refresh-token.util.d.ts +4 -4
- package/dist/utils/auth/request-token-using-refresh-token.util.js +7 -7
- package/dist/utils/auth/reset-password.util.d.ts +4 -4
- package/dist/utils/auth/reset-password.util.js +8 -8
- package/dist/utils/auth/send-reset-password-email.util.d.ts +2 -2
- package/dist/utils/auth/send-reset-password-email.util.js +5 -5
- package/dist/utils/auth/update-last-logged-in.util.d.ts +3 -3
- package/dist/utils/auth/update-last-logged-in.util.js +3 -3
- package/dist/utils/create-public-spec.utils.d.ts +1 -1
- package/dist/utils/create-public-spec.utils.js +2 -2
- package/dist/utils/express.utils.d.ts +4 -4
- package/dist/utils/express.utils.js +5 -5
- package/dist/utils/index.d.ts +10 -10
- package/dist/utils/index.js +10 -10
- package/dist/utils/jwt.utils.d.ts +1 -1
- package/dist/utils/jwt.utils.js +3 -3
- package/dist/utils/logger.utils.d.ts +1 -1
- package/dist/utils/logger.utils.js +10 -10
- package/dist/utils/password.utils.js +7 -7
- package/package.json +2 -1
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import crypto from
|
|
2
|
-
import { EmptyUserContext, getSystemUserContext, } from
|
|
3
|
-
import { Type } from
|
|
4
|
-
import { Value } from
|
|
5
|
-
import jwt from
|
|
6
|
-
import { ObjectId } from
|
|
7
|
-
import { ApiController } from
|
|
8
|
-
import { MongoDBDatabase } from
|
|
9
|
-
import { LeftJoin } from
|
|
10
|
-
import { PostgresDatabase } from
|
|
11
|
-
import { GenericApiService, UserService } from
|
|
12
|
-
import { MultiTenantApiService } from
|
|
13
|
-
import { OrganizationService } from
|
|
14
|
-
import { OrganizationDomainService } from
|
|
15
|
-
import * as testObjectsModule from
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import { EmptyUserContext, getSystemUserContext, } from '@loomcore/common/models';
|
|
3
|
+
import { Type } from '@sinclair/typebox';
|
|
4
|
+
import { Value } from '@sinclair/typebox/value';
|
|
5
|
+
import jwt from 'jsonwebtoken';
|
|
6
|
+
import { ObjectId } from 'mongodb';
|
|
7
|
+
import { ApiController } from '../controllers/api.controller.js';
|
|
8
|
+
import { MongoDBDatabase } from '../databases/mongo-db/mongo-db.database.js';
|
|
9
|
+
import { LeftJoin } from '../databases/operations/left-join.operation.js';
|
|
10
|
+
import { PostgresDatabase } from '../databases/postgres/postgres.database.js';
|
|
11
|
+
import { GenericApiService, UserService } from '../services/index.js';
|
|
12
|
+
import { MultiTenantApiService } from '../services/multi-tenant-api.service.js';
|
|
13
|
+
import { OrganizationService } from '../services/organization.service.js';
|
|
14
|
+
import { OrganizationDomainService } from '../services/organization-domain.service.js';
|
|
15
|
+
import * as testObjectsModule from './test-objects.js';
|
|
16
16
|
const { getTestMetaOrg, getTestMetaOrgDomain, getTestMetaOrgRefererUrl, getTestOrg, getTestOrgDomain, getTestMetaOrgUser, getTestMetaOrgUserContext, getTestOrgUser, getTestOrgUserContext, setTestOrgId, setTestMetaOrgId, setTestMetaOrgUserId, setTestOrgUserId, TEST_META_ORG_DOMAIN, TEST_ORG_DOMAIN, } = testObjectsModule;
|
|
17
|
-
import { entityUtils } from
|
|
18
|
-
import { config, setBaseApiConfig } from
|
|
19
|
-
import { attemptLogin } from
|
|
20
|
-
import { apiUtils } from
|
|
21
|
-
import { CategorySpec } from
|
|
22
|
-
import { ProductSpec } from
|
|
23
|
-
import { ProductWithCategoryPublicSpec, ProductWithCategorySpec, } from
|
|
24
|
-
import { TestEmailClient } from
|
|
17
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
18
|
+
import { config, setBaseApiConfig } from '../config/index.js';
|
|
19
|
+
import { attemptLogin } from '../utils/auth/index.js';
|
|
20
|
+
import { apiUtils } from '../utils/index.js';
|
|
21
|
+
import { CategorySpec } from './models/category.model.js';
|
|
22
|
+
import { ProductSpec } from './models/product.model.js';
|
|
23
|
+
import { ProductWithCategoryPublicSpec, ProductWithCategorySpec, } from './models/product-with-category.model.js';
|
|
24
|
+
import { TestEmailClient } from './test-email-client.js';
|
|
25
25
|
let deviceIdCookie;
|
|
26
26
|
let database;
|
|
27
27
|
let organizationService;
|
|
28
28
|
let organizationDomainService;
|
|
29
29
|
let userService;
|
|
30
|
-
const JWT_SECRET =
|
|
31
|
-
const newUser1Email =
|
|
32
|
-
const newUser1Password =
|
|
33
|
-
const constDeviceIdCookie = crypto.randomBytes(16).toString(
|
|
30
|
+
const JWT_SECRET = 'test-secret';
|
|
31
|
+
const newUser1Email = 'one@test.com';
|
|
32
|
+
const newUser1Password = 'testone1';
|
|
33
|
+
const constDeviceIdCookie = crypto.randomBytes(16).toString('hex');
|
|
34
34
|
function initialize(db) {
|
|
35
35
|
database = db;
|
|
36
36
|
organizationService = new OrganizationService(db);
|
|
@@ -48,14 +48,14 @@ function isPostgresDatabase(database) {
|
|
|
48
48
|
return database instanceof PostgresDatabase;
|
|
49
49
|
}
|
|
50
50
|
function getExpectedIdType(database) {
|
|
51
|
-
return isPostgresDatabase(database) ?
|
|
51
|
+
return isPostgresDatabase(database) ? 'number' : 'string';
|
|
52
52
|
}
|
|
53
53
|
async function createMetaOrg() {
|
|
54
54
|
if (!config.app.isMultiTenant) {
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
if (!organizationService || !organizationDomainService) {
|
|
58
|
-
throw new Error(
|
|
58
|
+
throw new Error('OrganizationService not initialized. Call initialize() first.');
|
|
59
59
|
}
|
|
60
60
|
try {
|
|
61
61
|
const existingMetaOrg = await organizationService.getMetaOrg(EmptyUserContext);
|
|
@@ -75,7 +75,7 @@ async function createMetaOrg() {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
catch (error) {
|
|
78
|
-
console.log(
|
|
78
|
+
console.log('Error in createMetaOrg:', error);
|
|
79
79
|
throw error;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
@@ -89,7 +89,7 @@ async function deleteMetaOrg() {
|
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
catch (error) {
|
|
92
|
-
console.log(
|
|
92
|
+
console.log('Error deleting meta org:', error);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
async function setupTestUsers() {
|
|
@@ -105,19 +105,19 @@ async function setupTestUsers() {
|
|
|
105
105
|
}
|
|
106
106
|
async function createTestUsers() {
|
|
107
107
|
if (!organizationService || !organizationDomainService || !userService) {
|
|
108
|
-
throw new Error(
|
|
108
|
+
throw new Error('Database not initialized. Call initialize() first.');
|
|
109
109
|
}
|
|
110
110
|
try {
|
|
111
111
|
const existingMetaOrg = await organizationService.getMetaOrg(EmptyUserContext);
|
|
112
112
|
if (!existingMetaOrg) {
|
|
113
|
-
throw new Error(
|
|
113
|
+
throw new Error('Meta organization does not exist. Test setup is incorrect - meta org should be created by migrations or createMetaOrg().');
|
|
114
114
|
}
|
|
115
115
|
setTestMetaOrgId(existingMetaOrg._id);
|
|
116
116
|
const existingTestOrg = await organizationService.findOne(getTestMetaOrgUserContext(), { filters: { _id: { eq: getTestOrg()._id } } });
|
|
117
117
|
if (!existingTestOrg) {
|
|
118
118
|
const createdTestOrg = await organizationService.create(getTestMetaOrgUserContext(), getTestOrg());
|
|
119
119
|
if (!createdTestOrg) {
|
|
120
|
-
throw new Error(
|
|
120
|
+
throw new Error('Failed to create test organization');
|
|
121
121
|
}
|
|
122
122
|
setTestOrgId(createdTestOrg._id);
|
|
123
123
|
await organizationDomainService.create(EmptyUserContext, getTestOrgDomain(createdTestOrg._id));
|
|
@@ -132,14 +132,14 @@ async function createTestUsers() {
|
|
|
132
132
|
const createdTestOrgUser = await userService.create(getTestOrgUserContext(), getTestOrgUser());
|
|
133
133
|
const createdMetaOrgUser = await userService.create(getTestMetaOrgUserContext(), getTestMetaOrgUser());
|
|
134
134
|
if (!createdTestOrgUser || !createdMetaOrgUser) {
|
|
135
|
-
throw new Error(
|
|
135
|
+
throw new Error('Failed to create test user');
|
|
136
136
|
}
|
|
137
137
|
setTestMetaOrgUserId(createdMetaOrgUser._id);
|
|
138
138
|
setTestOrgUserId(createdTestOrgUser._id);
|
|
139
139
|
return { metaOrgUser: createdMetaOrgUser, testOrgUser: createdTestOrgUser };
|
|
140
140
|
}
|
|
141
141
|
catch (error) {
|
|
142
|
-
console.log(
|
|
142
|
+
console.log('Error in createTestUser:', error);
|
|
143
143
|
throw error;
|
|
144
144
|
}
|
|
145
145
|
}
|
|
@@ -188,18 +188,18 @@ async function simulateloginWithTestUser() {
|
|
|
188
188
|
}
|
|
189
189
|
const res = {
|
|
190
190
|
cookie: (name, value) => {
|
|
191
|
-
if (name ===
|
|
191
|
+
if (name === 'deviceId') {
|
|
192
192
|
deviceIdCookie = value;
|
|
193
193
|
}
|
|
194
194
|
return res;
|
|
195
195
|
},
|
|
196
196
|
};
|
|
197
197
|
if (!database) {
|
|
198
|
-
throw new Error(
|
|
198
|
+
throw new Error('Database not initialized. Call initialize() first.');
|
|
199
199
|
}
|
|
200
200
|
const loginResponse = await attemptLogin(database, getTestMetaOrgUser().email, testObjectsModule.TEST_META_ORG_USER_PASSWORD, deviceIdCookie, getTestMetaOrg());
|
|
201
201
|
if (!loginResponse?.tokens?.accessToken) {
|
|
202
|
-
throw new Error(
|
|
202
|
+
throw new Error('Failed to login with test user');
|
|
203
203
|
}
|
|
204
204
|
return `Bearer ${loginResponse.tokens.accessToken}`;
|
|
205
205
|
}
|
|
@@ -213,13 +213,13 @@ function verifyToken(token) {
|
|
|
213
213
|
}
|
|
214
214
|
export class CategoryService extends GenericApiService {
|
|
215
215
|
constructor(database) {
|
|
216
|
-
super(database,
|
|
216
|
+
super(database, 'categories', 'category', CategorySpec);
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
export class CategoryController extends ApiController {
|
|
220
220
|
constructor(app, database) {
|
|
221
221
|
const categoryService = new CategoryService(database);
|
|
222
|
-
super(
|
|
222
|
+
super('categories', app, categoryService, 'category', CategorySpec);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
export function setupTestConfig(isMultiTenant = true, dbType) {
|
|
@@ -227,11 +227,11 @@ export function setupTestConfig(isMultiTenant = true, dbType) {
|
|
|
227
227
|
app: {
|
|
228
228
|
isMultiTenant: isMultiTenant,
|
|
229
229
|
isAuthEnabled: true,
|
|
230
|
-
name:
|
|
230
|
+
name: 'test-app',
|
|
231
231
|
dbType: dbType,
|
|
232
232
|
},
|
|
233
233
|
auth: {
|
|
234
|
-
clientSecret:
|
|
234
|
+
clientSecret: 'test-secret',
|
|
235
235
|
saltWorkFactor: 10,
|
|
236
236
|
jwtExpirationInSeconds: 3600,
|
|
237
237
|
refreshTokenExpirationInDays: 7,
|
|
@@ -239,25 +239,25 @@ export function setupTestConfig(isMultiTenant = true, dbType) {
|
|
|
239
239
|
passwordResetTokenExpirationInMinutes: 20,
|
|
240
240
|
},
|
|
241
241
|
database: {
|
|
242
|
-
name:
|
|
243
|
-
host:
|
|
244
|
-
password:
|
|
242
|
+
name: 'test-db',
|
|
243
|
+
host: 'localhost',
|
|
244
|
+
password: 'test-password',
|
|
245
245
|
port: 27017,
|
|
246
|
-
username:
|
|
246
|
+
username: 'test-user',
|
|
247
247
|
},
|
|
248
|
-
env:
|
|
248
|
+
env: 'test',
|
|
249
249
|
email: {
|
|
250
|
-
fromAddress:
|
|
251
|
-
systemEmailAddress:
|
|
250
|
+
fromAddress: 'test@test.com',
|
|
251
|
+
systemEmailAddress: 'system@test.com',
|
|
252
252
|
},
|
|
253
253
|
thirdPartyClients: {
|
|
254
254
|
emailClient: new TestEmailClient(),
|
|
255
255
|
},
|
|
256
256
|
network: {
|
|
257
|
-
hostName:
|
|
257
|
+
hostName: 'localhost',
|
|
258
258
|
internalPort: 8083,
|
|
259
259
|
externalPort: 4000,
|
|
260
|
-
corsAllowedOrigins: [
|
|
260
|
+
corsAllowedOrigins: ['*'],
|
|
261
261
|
},
|
|
262
262
|
});
|
|
263
263
|
}
|
|
@@ -266,7 +266,7 @@ const prepareQueryCustom = (userContext, queryObject, operations) => {
|
|
|
266
266
|
queryObject: queryObject,
|
|
267
267
|
operations: [
|
|
268
268
|
...operations,
|
|
269
|
-
new LeftJoin(
|
|
269
|
+
new LeftJoin('categories', 'category_id', '_id', 'category'),
|
|
270
270
|
],
|
|
271
271
|
};
|
|
272
272
|
};
|
|
@@ -278,42 +278,42 @@ const postProcessEntityCustom = (userContext, entity) => {
|
|
|
278
278
|
};
|
|
279
279
|
export class ProductService extends GenericApiService {
|
|
280
280
|
constructor(database) {
|
|
281
|
-
super(database,
|
|
281
|
+
super(database, 'products', 'product', ProductSpec);
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
284
|
export class ProductsController extends ApiController {
|
|
285
285
|
constructor(app, database) {
|
|
286
286
|
const productService = new ProductService(database);
|
|
287
|
-
super(
|
|
287
|
+
super('products', app, productService, 'product', ProductSpec);
|
|
288
288
|
}
|
|
289
289
|
async get(req, res, next) {
|
|
290
|
-
res.set(
|
|
290
|
+
res.set('Content-Type', 'application/json');
|
|
291
291
|
const userContext = req.userContext;
|
|
292
292
|
if (!userContext) {
|
|
293
|
-
throw new Error(
|
|
293
|
+
throw new Error('User context not found');
|
|
294
294
|
}
|
|
295
295
|
const queryOptions = apiUtils.getQueryOptionsFromRequest(req);
|
|
296
296
|
const pagedResult = await this.service.get(userContext, queryOptions, prepareQueryCustom, postProcessEntityCustom);
|
|
297
297
|
apiUtils.apiResponse(res, 200, { data: pagedResult }, ProductWithCategorySpec, ProductWithCategoryPublicSpec);
|
|
298
298
|
}
|
|
299
299
|
async getAll(req, res, next) {
|
|
300
|
-
res.set(
|
|
300
|
+
res.set('Content-Type', 'application/json');
|
|
301
301
|
const userContext = req.userContext;
|
|
302
302
|
if (!userContext) {
|
|
303
|
-
throw new Error(
|
|
303
|
+
throw new Error('User context not found');
|
|
304
304
|
}
|
|
305
305
|
const entities = await this.service.getAll(userContext, prepareQueryCustom, postProcessEntityCustom);
|
|
306
306
|
apiUtils.apiResponse(res, 200, { data: entities }, ProductWithCategorySpec, ProductWithCategoryPublicSpec);
|
|
307
307
|
}
|
|
308
308
|
async getById(req, res, next) {
|
|
309
|
-
res.set(
|
|
309
|
+
res.set('Content-Type', 'application/json');
|
|
310
310
|
const userContext = req.userContext;
|
|
311
311
|
if (!userContext) {
|
|
312
|
-
throw new Error(
|
|
312
|
+
throw new Error('User context not found');
|
|
313
313
|
}
|
|
314
314
|
const idParam = req.params?.id;
|
|
315
315
|
if (!idParam) {
|
|
316
|
-
throw new Error(
|
|
316
|
+
throw new Error('ID parameter is required');
|
|
317
317
|
}
|
|
318
318
|
let id;
|
|
319
319
|
try {
|
|
@@ -329,13 +329,13 @@ export class ProductsController extends ApiController {
|
|
|
329
329
|
export class MultiTenantProductService extends MultiTenantApiService {
|
|
330
330
|
db;
|
|
331
331
|
constructor(database) {
|
|
332
|
-
super(database,
|
|
332
|
+
super(database, 'products', 'product', ProductSpec);
|
|
333
333
|
this.db = database;
|
|
334
334
|
}
|
|
335
335
|
prepareQuery(userContext, queryObject, operations) {
|
|
336
336
|
const newOperations = [
|
|
337
337
|
...operations,
|
|
338
|
-
new LeftJoin(
|
|
338
|
+
new LeftJoin('categories', 'categoryId', '_id', 'category'),
|
|
339
339
|
];
|
|
340
340
|
return super.prepareQuery(userContext, queryObject, newOperations);
|
|
341
341
|
}
|
|
@@ -357,10 +357,10 @@ export class MultiTenantProductsController extends ApiController {
|
|
|
357
357
|
})),
|
|
358
358
|
]);
|
|
359
359
|
const PublicAggregatedProductSchema = Type.Omit(AggregatedProductSchema, [
|
|
360
|
-
|
|
360
|
+
'internalNumber',
|
|
361
361
|
]);
|
|
362
362
|
const PublicAggregatedProductSpec = entityUtils.getModelSpec(PublicAggregatedProductSchema);
|
|
363
|
-
super(
|
|
363
|
+
super('multi-tenant-products', app, productService, 'product', ProductSpec, PublicAggregatedProductSpec);
|
|
364
364
|
}
|
|
365
365
|
}
|
|
366
366
|
function configureJwtSecret() {
|
|
@@ -368,18 +368,18 @@ function configureJwtSecret() {
|
|
|
368
368
|
jwt.verify = (token, _secret, options) => originalJwtVerify(token, JWT_SECRET, options);
|
|
369
369
|
}
|
|
370
370
|
async function loginWithTestUser(agent) {
|
|
371
|
-
agent.set(
|
|
371
|
+
agent.set('Cookie', [`deviceId=${deviceIdCookie}`]);
|
|
372
372
|
const testUser = getTestMetaOrgUser();
|
|
373
373
|
const response = await agent
|
|
374
|
-
.post(
|
|
375
|
-
.set(
|
|
374
|
+
.post('/api/auth/login')
|
|
375
|
+
.set('Referer', getTestMetaOrgRefererUrl())
|
|
376
376
|
.send({
|
|
377
377
|
email: testUser.email,
|
|
378
378
|
password: testUser.password,
|
|
379
379
|
});
|
|
380
380
|
if (!response.body?.data?.tokens?.accessToken) {
|
|
381
|
-
console.error(
|
|
382
|
-
throw new Error(
|
|
381
|
+
console.error('Login failed:', response.body);
|
|
382
|
+
throw new Error('Failed to login with test user');
|
|
383
383
|
}
|
|
384
384
|
const authorizationHeaderValue = `Bearer ${response.body?.data?.tokens?.accessToken}`;
|
|
385
385
|
return authorizationHeaderValue;
|
|
@@ -390,7 +390,7 @@ async function cleanup() {
|
|
|
390
390
|
await deleteMetaOrg();
|
|
391
391
|
}
|
|
392
392
|
catch (error) {
|
|
393
|
-
console.log(
|
|
393
|
+
console.log('Error during cleanup:', error);
|
|
394
394
|
}
|
|
395
395
|
}
|
|
396
396
|
const testUtils = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { entityUtils } from
|
|
2
|
-
import { Type } from
|
|
1
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
3
|
export const CategorySchema = Type.Object({
|
|
4
4
|
name: Type.String(),
|
|
5
5
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ICategory } from
|
|
2
|
-
import { IProduct } from
|
|
3
|
-
import { IEntity } from
|
|
1
|
+
import { ICategory } from './category.model.js';
|
|
2
|
+
import { IProduct } from './product.model.js';
|
|
3
|
+
import { IEntity } from '@loomcore/common/models';
|
|
4
4
|
export interface IProductWithCategory extends IProduct, IEntity {
|
|
5
5
|
category: ICategory;
|
|
6
6
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { entityUtils } from
|
|
2
|
-
import { Type } from
|
|
3
|
-
import { CategorySpec } from
|
|
4
|
-
import { ProductPublicSchema, ProductSchema } from
|
|
1
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
|
+
import { CategorySpec } from './category.model.js';
|
|
4
|
+
import { ProductPublicSchema, ProductSchema } from './product.model.js';
|
|
5
5
|
export const ProductWithCategorySchema = Type.Intersect([
|
|
6
6
|
ProductSchema,
|
|
7
7
|
Type.Object({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IAuditable, IEntity } from
|
|
2
|
-
import { AppIdType } from
|
|
1
|
+
import { IAuditable, IEntity } from '@loomcore/common/models';
|
|
2
|
+
import { AppIdType } from '@loomcore/common/types';
|
|
3
3
|
export interface IProduct extends IEntity, IAuditable {
|
|
4
4
|
name: string;
|
|
5
5
|
description?: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { entityUtils } from
|
|
2
|
-
import { Type } from
|
|
1
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
3
|
export const ProductSchema = Type.Object({
|
|
4
4
|
name: Type.String(),
|
|
5
5
|
description: Type.Optional(Type.String()),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IAuditable, IEntity, IModelSpec } from
|
|
2
|
-
import { TSchema } from
|
|
1
|
+
import { IAuditable, IEntity, IModelSpec } from '@loomcore/common/models';
|
|
2
|
+
import { TSchema } from '@sinclair/typebox';
|
|
3
3
|
export declare const TestEntitySchema: TSchema;
|
|
4
4
|
export interface TestEntity extends IEntity, IAuditable {
|
|
5
5
|
name: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { entityUtils } from
|
|
2
|
-
import { Type } from
|
|
1
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
3
|
export const TestEntitySchema = Type.Object({
|
|
4
4
|
name: Type.String({ minLength: 1 }),
|
|
5
5
|
description: Type.Optional(Type.String()),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { entityUtils } from
|
|
2
|
-
import { TypeboxIsoDate } from
|
|
3
|
-
import { Type } from
|
|
1
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
2
|
+
import { TypeboxIsoDate } from '@loomcore/common/validation';
|
|
3
|
+
import { Type } from '@sinclair/typebox';
|
|
4
4
|
export const TestItemSchema = Type.Object({
|
|
5
5
|
name: Type.String(),
|
|
6
6
|
value: Type.Optional(Type.Number()),
|
|
@@ -44,7 +44,7 @@ export class TestMongoDatabase {
|
|
|
44
44
|
}
|
|
45
45
|
async createIndexes(db) {
|
|
46
46
|
await db.command({
|
|
47
|
-
createIndexes:
|
|
47
|
+
createIndexes: 'users', indexes: [{ key: { email: 1 }, name: 'email_index', unique: true, collation: { locale: 'en', strength: 1 } }]
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
async clearCollections() {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { SyntheticMigration } from
|
|
2
|
-
import type { IBaseApiConfig } from
|
|
1
|
+
import type { SyntheticMigration } from '../../databases/postgres/migrations/postgres-initial-schema.js';
|
|
2
|
+
import type { IBaseApiConfig } from '../../models/base-api-config.interface.js';
|
|
3
3
|
export declare const getPostgresTestSchema: (config: IBaseApiConfig) => SyntheticMigration[];
|