@loomcore/api 0.2.41 → 0.2.44

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 (245) hide show
  1. package/LICENSE +201 -201
  2. package/dist/__tests__/common-test.utils.d.ts +13 -13
  3. package/dist/__tests__/common-test.utils.js +72 -72
  4. package/dist/__tests__/models/category.model.d.ts +1 -1
  5. package/dist/__tests__/models/category.model.js +2 -2
  6. package/dist/__tests__/models/product-with-category.model.d.ts +3 -3
  7. package/dist/__tests__/models/product-with-category.model.js +4 -4
  8. package/dist/__tests__/models/product.model.d.ts +2 -2
  9. package/dist/__tests__/models/product.model.js +2 -2
  10. package/dist/__tests__/models/test-entity.model.d.ts +2 -2
  11. package/dist/__tests__/models/test-entity.model.js +2 -2
  12. package/dist/__tests__/models/test-item.model.d.ts +1 -1
  13. package/dist/__tests__/models/test-item.model.js +3 -3
  14. package/dist/__tests__/mongo-db.test-database.js +1 -1
  15. package/dist/__tests__/postgres-test-migrations/postgres-test-schema.d.ts +2 -2
  16. package/dist/__tests__/postgres-test-migrations/postgres-test-schema.js +38 -38
  17. package/dist/__tests__/postgres.test-database.d.ts +2 -2
  18. package/dist/__tests__/postgres.test-database.js +25 -25
  19. package/dist/__tests__/test-database.interface.d.ts +1 -1
  20. package/dist/__tests__/test-email-client.d.ts +1 -1
  21. package/dist/__tests__/test-express-app.d.ts +3 -3
  22. package/dist/__tests__/test-express-app.js +12 -12
  23. package/dist/__tests__/test-objects.d.ts +1 -1
  24. package/dist/__tests__/test-objects.js +26 -26
  25. package/dist/config/base-api-config.d.ts +2 -2
  26. package/dist/config/base-api-config.js +17 -17
  27. package/dist/controllers/auth.controller.d.ts +4 -4
  28. package/dist/controllers/auth.controller.js +32 -32
  29. package/dist/controllers/authorizations.controller.d.ts +4 -4
  30. package/dist/controllers/authorizations.controller.js +4 -4
  31. package/dist/controllers/features.controller.d.ts +4 -4
  32. package/dist/controllers/features.controller.js +4 -4
  33. package/dist/controllers/index.d.ts +10 -10
  34. package/dist/controllers/index.js +10 -10
  35. package/dist/controllers/organizations.controller.d.ts +5 -5
  36. package/dist/controllers/organizations.controller.js +10 -10
  37. package/dist/controllers/roles.controller.d.ts +4 -4
  38. package/dist/controllers/roles.controller.js +4 -4
  39. package/dist/controllers/types.d.ts +2 -2
  40. package/dist/controllers/user-roles.controller.d.ts +4 -4
  41. package/dist/controllers/user-roles.controller.js +4 -4
  42. package/dist/controllers/users.controller.d.ts +5 -5
  43. package/dist/controllers/users.controller.js +4 -4
  44. package/dist/databases/models/database.interface.d.ts +5 -5
  45. package/dist/databases/mongo-db/commands/mongo-batch-update.command.d.ts +3 -3
  46. package/dist/databases/mongo-db/commands/mongo-batch-update.command.js +5 -5
  47. package/dist/databases/mongo-db/commands/mongo-create-many.command.d.ts +1 -1
  48. package/dist/databases/mongo-db/commands/mongo-create-many.command.js +1 -1
  49. package/dist/databases/mongo-db/commands/mongo-create.command.d.ts +1 -1
  50. package/dist/databases/mongo-db/commands/mongo-create.command.js +1 -1
  51. package/dist/databases/mongo-db/commands/mongo-delete-by-id.command.d.ts +3 -3
  52. package/dist/databases/mongo-db/commands/mongo-delete-by-id.command.js +4 -4
  53. package/dist/databases/mongo-db/commands/mongo-delete-many.command.d.ts +3 -3
  54. package/dist/databases/mongo-db/commands/mongo-delete-many.command.js +2 -2
  55. package/dist/databases/mongo-db/commands/mongo-full-updateby-id.command.d.ts +3 -3
  56. package/dist/databases/mongo-db/commands/mongo-full-updateby-id.command.js +4 -4
  57. package/dist/databases/mongo-db/commands/mongo-partial-update-by-id.command.d.ts +3 -3
  58. package/dist/databases/mongo-db/commands/mongo-partial-update-by-id.command.js +4 -4
  59. package/dist/databases/mongo-db/commands/mongo-update.command.d.ts +3 -3
  60. package/dist/databases/mongo-db/commands/mongo-update.command.js +3 -3
  61. package/dist/databases/mongo-db/migrations/mongo-initial-schema.d.ts +2 -2
  62. package/dist/databases/mongo-db/migrations/mongo-initial-schema.js +108 -108
  63. package/dist/databases/mongo-db/models/no-sql-pipeline.d.ts +4 -4
  64. package/dist/databases/mongo-db/models/no-sql-pipeline.interface.d.ts +3 -3
  65. package/dist/databases/mongo-db/models/no-sql-pipeline.js +1 -1
  66. package/dist/databases/mongo-db/mongo-db.database.d.ts +7 -7
  67. package/dist/databases/mongo-db/mongo-db.database.js +5 -5
  68. package/dist/databases/mongo-db/queries/mongo-find-one.query.d.ts +2 -2
  69. package/dist/databases/mongo-db/queries/mongo-find-one.query.js +1 -1
  70. package/dist/databases/mongo-db/queries/mongo-find.query.d.ts +2 -2
  71. package/dist/databases/mongo-db/queries/mongo-find.query.js +1 -1
  72. package/dist/databases/mongo-db/queries/mongo-get-all.query.d.ts +2 -2
  73. package/dist/databases/mongo-db/queries/mongo-get-all.query.js +1 -1
  74. package/dist/databases/mongo-db/queries/mongo-get-by-id.query.d.ts +4 -4
  75. package/dist/databases/mongo-db/queries/mongo-get-by-id.query.js +3 -3
  76. package/dist/databases/mongo-db/queries/mongo-get-count.query.d.ts +1 -1
  77. package/dist/databases/mongo-db/queries/mongo-get.query.d.ts +3 -3
  78. package/dist/databases/mongo-db/queries/mongo-get.query.js +2 -2
  79. package/dist/databases/mongo-db/utils/build-find-options.util.d.ts +2 -2
  80. package/dist/databases/mongo-db/utils/build-mongo-url.util.d.ts +1 -1
  81. package/dist/databases/mongo-db/utils/build-mongo-url.util.js +4 -4
  82. package/dist/databases/operations/__tests__/models/test-agent.model.d.ts +2 -2
  83. package/dist/databases/operations/__tests__/models/test-agent.model.js +3 -3
  84. package/dist/databases/operations/__tests__/models/test-client-report.model.d.ts +4 -4
  85. package/dist/databases/operations/__tests__/models/test-client-report.model.js +5 -5
  86. package/dist/databases/operations/__tests__/models/test-district.model.d.ts +2 -2
  87. package/dist/databases/operations/__tests__/models/test-district.model.js +2 -2
  88. package/dist/databases/operations/__tests__/models/test-email-address.model.d.ts +1 -1
  89. package/dist/databases/operations/__tests__/models/test-email-address.model.js +2 -2
  90. package/dist/databases/operations/__tests__/models/test-person.model.d.ts +4 -4
  91. package/dist/databases/operations/__tests__/models/test-person.model.js +4 -4
  92. package/dist/databases/operations/__tests__/models/test-phone-number.model.d.ts +1 -1
  93. package/dist/databases/operations/__tests__/models/test-phone-number.model.js +2 -2
  94. package/dist/databases/operations/__tests__/models/test-policy.model.d.ts +3 -3
  95. package/dist/databases/operations/__tests__/models/test-policy.model.js +4 -4
  96. package/dist/databases/operations/__tests__/models/test-premium.model.d.ts +1 -1
  97. package/dist/databases/operations/__tests__/models/test-premium.model.js +2 -2
  98. package/dist/databases/operations/__tests__/models/test-school.model.d.ts +2 -2
  99. package/dist/databases/operations/__tests__/models/test-school.model.js +2 -2
  100. package/dist/databases/operations/__tests__/models/test-state.model.d.ts +1 -1
  101. package/dist/databases/operations/__tests__/models/test-state.model.js +2 -2
  102. package/dist/databases/operations/operation.d.ts +3 -3
  103. package/dist/databases/postgres/commands/postgres-batch-update.command.d.ts +1 -1
  104. package/dist/databases/postgres/commands/postgres-batch-update.command.js +11 -11
  105. package/dist/databases/postgres/commands/postgres-create-many.command.js +5 -5
  106. package/dist/databases/postgres/commands/postgres-create.command.d.ts +3 -3
  107. package/dist/databases/postgres/commands/postgres-create.command.js +5 -5
  108. package/dist/databases/postgres/commands/postgres-delete-by-id.command.d.ts +1 -1
  109. package/dist/databases/postgres/commands/postgres-delete-by-id.command.js +1 -1
  110. package/dist/databases/postgres/commands/postgres-delete-many.command.d.ts +2 -2
  111. package/dist/databases/postgres/commands/postgres-delete-many.command.js +1 -1
  112. package/dist/databases/postgres/commands/postgres-full-update-by-id.command.d.ts +1 -1
  113. package/dist/databases/postgres/commands/postgres-full-update-by-id.command.js +4 -4
  114. package/dist/databases/postgres/commands/postgres-partial-update-by-id.command.d.ts +1 -1
  115. package/dist/databases/postgres/commands/postgres-partial-update-by-id.command.js +11 -11
  116. package/dist/databases/postgres/commands/postgres-update.command.d.ts +2 -2
  117. package/dist/databases/postgres/commands/postgres-update.command.js +11 -11
  118. package/dist/databases/postgres/migrations/postgres-initial-schema.d.ts +2 -2
  119. package/dist/databases/postgres/migrations/postgres-initial-schema.js +69 -69
  120. package/dist/databases/postgres/postgres.database.d.ts +6 -6
  121. package/dist/databases/postgres/postgres.database.js +18 -18
  122. package/dist/databases/postgres/queries/postgres-find-one.query.d.ts +1 -1
  123. package/dist/databases/postgres/queries/postgres-find-one.query.js +2 -2
  124. package/dist/databases/postgres/queries/postgres-find.query.d.ts +1 -1
  125. package/dist/databases/postgres/queries/postgres-find.query.js +2 -2
  126. package/dist/databases/postgres/queries/postgres-get-all.query.d.ts +1 -1
  127. package/dist/databases/postgres/queries/postgres-get-all.query.js +3 -3
  128. package/dist/databases/postgres/queries/postgres-get-by-id.query.d.ts +1 -1
  129. package/dist/databases/postgres/queries/postgres-get-by-id.query.js +5 -5
  130. package/dist/databases/postgres/queries/postgres-get-count.query.js +1 -1
  131. package/dist/databases/postgres/queries/postgres-get.query.d.ts +2 -2
  132. package/dist/databases/postgres/queries/postgres-get.query.js +9 -9
  133. package/dist/databases/postgres/utils/build-count-query.d.ts +1 -1
  134. package/dist/databases/postgres/utils/build-count-query.js +1 -1
  135. package/dist/databases/postgres/utils/build-join-clauses.d.ts +1 -1
  136. package/dist/databases/postgres/utils/build-join-clauses.js +7 -7
  137. package/dist/databases/postgres/utils/build-order-by-clause.d.ts +1 -1
  138. package/dist/databases/postgres/utils/build-pagination-clause.d.ts +1 -1
  139. package/dist/databases/postgres/utils/build-postgres-url.util.d.ts +1 -1
  140. package/dist/databases/postgres/utils/build-postgres-url.util.js +2 -2
  141. package/dist/databases/postgres/utils/build-select-clause.js +9 -9
  142. package/dist/databases/postgres/utils/build-where-clause.d.ts +1 -1
  143. package/dist/databases/postgres/utils/build-where-clause.js +1 -1
  144. package/dist/databases/postgres/utils/columns-and-values-from-entity.d.ts +1 -1
  145. package/dist/databases/postgres/utils/does-table-exist.util.d.ts +1 -1
  146. package/dist/databases/postgres/utils/does-table-exist.util.js +5 -5
  147. package/dist/decorators/index.d.ts +1 -0
  148. package/dist/decorators/index.js +1 -0
  149. package/dist/middleware/authorize/authenticate-request.d.ts +2 -2
  150. package/dist/middleware/authorize/authenticate-request.js +5 -5
  151. package/dist/middleware/index.d.ts +4 -4
  152. package/dist/middleware/index.js +4 -4
  153. package/dist/models/app-config.interface.d.ts +1 -1
  154. package/dist/models/base-api-config.interface.d.ts +6 -6
  155. package/dist/models/initial-database-config.interface.d.ts +3 -3
  156. package/dist/models/log-level.type.d.ts +1 -1
  157. package/dist/services/authorizations.service.d.ts +3 -3
  158. package/dist/services/authorizations.service.js +7 -7
  159. package/dist/services/email.service.js +5 -5
  160. package/dist/services/features.service.d.ts +3 -3
  161. package/dist/services/features.service.js +4 -4
  162. package/dist/services/generic-api-service/generic-api-service.interface.d.ts +6 -6
  163. package/dist/services/generic-api-service/generic-api.service.d.ts +8 -8
  164. package/dist/services/generic-api-service/generic-api.service.js +7 -7
  165. package/dist/services/index.d.ts +16 -16
  166. package/dist/services/index.js +16 -16
  167. package/dist/services/multi-tenant-api.service.d.ts +4 -4
  168. package/dist/services/multi-tenant-api.service.js +9 -9
  169. package/dist/services/organization-domain.service.d.ts +3 -3
  170. package/dist/services/organization-domain.service.js +3 -3
  171. package/dist/services/organization.service.d.ts +4 -4
  172. package/dist/services/organization.service.js +7 -7
  173. package/dist/services/password-reset-token.service.d.ts +3 -3
  174. package/dist/services/password-reset-token.service.js +5 -5
  175. package/dist/services/refresh-token.service.d.ts +3 -3
  176. package/dist/services/refresh-token.service.js +3 -3
  177. package/dist/services/roles.service.d.ts +3 -3
  178. package/dist/services/roles.service.js +4 -4
  179. package/dist/services/tenant-query-decorator.d.ts +1 -1
  180. package/dist/services/tenant-query-decorator.js +8 -8
  181. package/dist/services/user-roles.service.d.ts +3 -3
  182. package/dist/services/user-roles.service.js +4 -4
  183. package/dist/services/user.service.d.ts +4 -4
  184. package/dist/services/user.service.js +11 -11
  185. package/dist/services/utils/audit-for-create.util.d.ts +1 -1
  186. package/dist/services/utils/audit-for-create.util.js +2 -2
  187. package/dist/services/utils/audit-for-update.util.d.ts +1 -1
  188. package/dist/services/utils/audit-for-update.util.js +2 -2
  189. package/dist/services/utils/strip-sender-provided-system-properties.util.d.ts +1 -1
  190. package/dist/services/utils/strip-sender-provided-system-properties.util.js +4 -4
  191. package/dist/utils/auth/assert-admin-or-feature.util.d.ts +1 -1
  192. package/dist/utils/auth/assert-admin-or-feature.util.js +2 -2
  193. package/dist/utils/auth/assert-admin.util.d.ts +1 -1
  194. package/dist/utils/auth/assert-admin.util.js +2 -2
  195. package/dist/utils/auth/assert-owner-or-admin.util.d.ts +1 -1
  196. package/dist/utils/auth/assert-owner-or-admin.util.js +2 -2
  197. package/dist/utils/auth/assert-user-has-feature.util.d.ts +1 -1
  198. package/dist/utils/auth/assert-user-has-feature.util.js +1 -1
  199. package/dist/utils/auth/assert-user-or-admin.util.d.ts +2 -2
  200. package/dist/utils/auth/assert-user-or-admin.util.js +2 -2
  201. package/dist/utils/auth/attempt-login.util.d.ts +4 -4
  202. package/dist/utils/auth/attempt-login.util.js +8 -8
  203. package/dist/utils/auth/auth-user-specs.util.d.ts +1 -1
  204. package/dist/utils/auth/auth-user-specs.util.js +3 -3
  205. package/dist/utils/auth/change-password.util.d.ts +4 -4
  206. package/dist/utils/auth/change-password.util.js +2 -2
  207. package/dist/utils/auth/create-new-refresh-token.util.d.ts +3 -3
  208. package/dist/utils/auth/create-new-refresh-token.util.js +8 -8
  209. package/dist/utils/auth/create-new-tokens.util.d.ts +1 -1
  210. package/dist/utils/auth/create-new-tokens.util.js +3 -3
  211. package/dist/utils/auth/generate-device-id.util.js +2 -2
  212. package/dist/utils/auth/generate-refresh-token.util.js +2 -2
  213. package/dist/utils/auth/get-active-refresh-token.util.d.ts +2 -2
  214. package/dist/utils/auth/get-active-refresh-token.util.js +1 -1
  215. package/dist/utils/auth/get-and-set-device-id-cookie.util.d.ts +1 -1
  216. package/dist/utils/auth/get-and-set-device-id-cookie.util.js +4 -4
  217. package/dist/utils/auth/get-auth-config.util.d.ts +1 -1
  218. package/dist/utils/auth/get-auth-config.util.js +3 -3
  219. package/dist/utils/auth/get-device-id-from-cookie.util.d.ts +1 -1
  220. package/dist/utils/auth/index.d.ts +26 -26
  221. package/dist/utils/auth/index.js +26 -26
  222. package/dist/utils/auth/is-admin.util.d.ts +1 -1
  223. package/dist/utils/auth/is-admin.util.js +1 -1
  224. package/dist/utils/auth/log-user-in.util.d.ts +3 -3
  225. package/dist/utils/auth/log-user-in.util.js +5 -5
  226. package/dist/utils/auth/request-token-using-refresh-token.util.d.ts +4 -4
  227. package/dist/utils/auth/request-token-using-refresh-token.util.js +7 -7
  228. package/dist/utils/auth/reset-password.util.d.ts +4 -4
  229. package/dist/utils/auth/reset-password.util.js +8 -8
  230. package/dist/utils/auth/send-reset-password-email.util.d.ts +2 -2
  231. package/dist/utils/auth/send-reset-password-email.util.js +5 -5
  232. package/dist/utils/auth/update-last-logged-in.util.d.ts +3 -3
  233. package/dist/utils/auth/update-last-logged-in.util.js +3 -3
  234. package/dist/utils/create-public-spec.utils.d.ts +1 -1
  235. package/dist/utils/create-public-spec.utils.js +3 -3
  236. package/dist/utils/express.utils.d.ts +4 -4
  237. package/dist/utils/express.utils.js +5 -5
  238. package/dist/utils/index.d.ts +10 -10
  239. package/dist/utils/index.js +10 -10
  240. package/dist/utils/jwt.utils.d.ts +1 -1
  241. package/dist/utils/jwt.utils.js +3 -3
  242. package/dist/utils/logger.utils.d.ts +1 -1
  243. package/dist/utils/logger.utils.js +10 -10
  244. package/dist/utils/password.utils.js +7 -7
  245. package/package.json +1 -1
@@ -1,36 +1,36 @@
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";
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 "@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";
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 = "test-secret";
31
- const newUser1Email = "one@test.com";
32
- const newUser1Password = "testone1";
33
- const constDeviceIdCookie = crypto.randomBytes(16).toString("hex");
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) ? "number" : "string";
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("OrganizationService not initialized. Call initialize() first.");
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("Error in createMetaOrg:", error);
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("Error deleting meta org:", error);
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("Database not initialized. Call initialize() first.");
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("Meta organization does not exist. Test setup is incorrect - meta org should be created by migrations or createMetaOrg().");
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("Failed to create test organization");
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("Failed to create test user");
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("Error in createTestUser:", error);
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 === "deviceId") {
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("Database not initialized. Call initialize() first.");
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("Failed to login with test user");
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, "categories", "category", CategorySpec);
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("categories", app, categoryService, "category", CategorySpec);
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: "test-app",
230
+ name: 'test-app',
231
231
  dbType: dbType,
232
232
  },
233
233
  auth: {
234
- clientSecret: "test-secret",
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: "test-db",
243
- host: "localhost",
244
- password: "test-password",
242
+ name: 'test-db',
243
+ host: 'localhost',
244
+ password: 'test-password',
245
245
  port: 27017,
246
- username: "test-user",
246
+ username: 'test-user',
247
247
  },
248
- env: "test",
248
+ env: 'test',
249
249
  email: {
250
- fromAddress: "test@test.com",
251
- systemEmailAddress: "system@test.com",
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: "localhost",
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("categories", "category_id", "_id", "category"),
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, "products", "product", ProductSpec);
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("products", app, productService, "product", ProductSpec);
287
+ super('products', app, productService, 'product', ProductSpec);
288
288
  }
289
289
  async get(req, res, next) {
290
- res.set("Content-Type", "application/json");
290
+ res.set('Content-Type', 'application/json');
291
291
  const userContext = req.userContext;
292
292
  if (!userContext) {
293
- throw new Error("User context not found");
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("Content-Type", "application/json");
300
+ res.set('Content-Type', 'application/json');
301
301
  const userContext = req.userContext;
302
302
  if (!userContext) {
303
- throw new Error("User context not found");
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("Content-Type", "application/json");
309
+ res.set('Content-Type', 'application/json');
310
310
  const userContext = req.userContext;
311
311
  if (!userContext) {
312
- throw new Error("User context not found");
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("ID parameter is required");
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, "products", "product", ProductSpec);
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("categories", "categoryId", "_id", "category"),
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
- "internalNumber",
360
+ 'internalNumber',
361
361
  ]);
362
362
  const PublicAggregatedProductSpec = entityUtils.getModelSpec(PublicAggregatedProductSchema);
363
- super("multi-tenant-products", app, productService, "product", ProductSpec, PublicAggregatedProductSpec);
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("Cookie", [`deviceId=${deviceIdCookie}`]);
371
+ agent.set('Cookie', [`deviceId=${deviceIdCookie}`]);
372
372
  const testUser = getTestMetaOrgUser();
373
373
  const response = await agent
374
- .post("/api/auth/login")
375
- .set("Referer", getTestMetaOrgRefererUrl())
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("Login failed:", response.body);
382
- throw new Error("Failed to login with test user");
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("Error during cleanup:", error);
393
+ console.log('Error during cleanup:', error);
394
394
  }
395
395
  }
396
396
  const testUtils = {
@@ -1,4 +1,4 @@
1
- import { IEntity } from "@loomcore/common/models";
1
+ import { IEntity } from '@loomcore/common/models';
2
2
  export interface ICategory extends IEntity {
3
3
  name: string;
4
4
  }
@@ -1,5 +1,5 @@
1
- import { entityUtils } from "@loomcore/common/utils";
2
- import { Type } from "@sinclair/typebox";
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 "./category.model.js";
2
- import { IProduct } from "./product.model.js";
3
- import { IEntity } from "@loomcore/common/models";
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 "@loomcore/common/utils";
2
- import { Type } from "@sinclair/typebox";
3
- import { CategorySpec } from "./category.model.js";
4
- import { ProductPublicSchema, ProductSchema } from "./product.model.js";
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 "@loomcore/common/models";
2
- import { AppIdType } from "@loomcore/common/types";
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 "@loomcore/common/utils";
2
- import { Type } from "@sinclair/typebox";
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 "@loomcore/common/models";
2
- import { TSchema } from "@sinclair/typebox";
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 "@loomcore/common/utils";
2
- import { Type } from "@sinclair/typebox";
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,4 +1,4 @@
1
- import { IAuditable, IEntity } from "@loomcore/common/models";
1
+ import { IAuditable, IEntity } from '@loomcore/common/models';
2
2
  export interface ITestItem extends IEntity, IAuditable {
3
3
  name: string;
4
4
  value?: number;
@@ -1,6 +1,6 @@
1
- import { entityUtils } from "@loomcore/common/utils";
2
- import { TypeboxIsoDate } from "@loomcore/common/validation";
3
- import { Type } from "@sinclair/typebox";
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: "users", indexes: [{ key: { email: 1 }, name: 'email_index', unique: true, collation: { locale: 'en', strength: 1 } }]
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 "../../databases/postgres/migrations/postgres-initial-schema.js";
2
- import type { IBaseApiConfig } from "../../models/base-api-config.interface.js";
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[];