@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.
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 +2 -2
  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 +2 -1
@@ -1,9 +1,9 @@
1
- import { RoleModelSpec } from "@loomcore/common/models";
2
- import { MultiTenantApiService } from "./multi-tenant-api.service.js";
3
- import { assertUserHasFeature } from "../utils/index.js";
1
+ import { RoleModelSpec } from '@loomcore/common/models';
2
+ import { MultiTenantApiService } from './multi-tenant-api.service.js';
3
+ import { assertUserHasFeature } from '../utils/index.js';
4
4
  export class RolesService extends MultiTenantApiService {
5
5
  constructor(database) {
6
- super(database, "roles", "role", RoleModelSpec);
6
+ super(database, 'roles', 'role', RoleModelSpec);
7
7
  }
8
8
  async preProcessEntity(userContext, entity, isCreate, allowId = true) {
9
9
  assertUserHasFeature(userContext, ['admin', 'system', 'roles']);
@@ -1,4 +1,4 @@
1
- import type { IEntity, IQueryOptions, IUserContext } from "@loomcore/common/models";
1
+ import type { IEntity, IQueryOptions, IUserContext } from '@loomcore/common/models';
2
2
  export interface ITenantQueryOptions {
3
3
  orgIdField?: string;
4
4
  excludedCollections?: string[];
@@ -1,6 +1,6 @@
1
- import { ServerError } from "../errors/index.js";
1
+ import { ServerError } from '../errors/index.js';
2
2
  export const DEFAULT_TENANT_OPTIONS = {
3
- orgIdField: "_orgId",
3
+ orgIdField: '_orgId',
4
4
  excludedCollections: [],
5
5
  };
6
6
  export class TenantQueryDecorator {
@@ -13,7 +13,7 @@ export class TenantQueryDecorator {
13
13
  const shouldApplyTenantFilter = !this.options.excludedCollections?.includes(collectionName) &&
14
14
  userContext?.user._orgId;
15
15
  if (shouldApplyTenantFilter) {
16
- const orgIdField = this.options.orgIdField || "_orgId";
16
+ const orgIdField = this.options.orgIdField || '_orgId';
17
17
  result = {
18
18
  ...queryObject,
19
19
  filters: {
@@ -24,7 +24,7 @@ export class TenantQueryDecorator {
24
24
  }
25
25
  else if (!userContext?.user._orgId) {
26
26
  if (!this.options.excludedCollections?.includes(collectionName)) {
27
- throw new ServerError("No _orgId found in userContext");
27
+ throw new ServerError('No _orgId found in userContext');
28
28
  }
29
29
  }
30
30
  return result;
@@ -34,7 +34,7 @@ export class TenantQueryDecorator {
34
34
  const shouldApplyTenantFilter = !this.options.excludedCollections?.includes(collectionName);
35
35
  if (shouldApplyTenantFilter) {
36
36
  if (!userContext?.user._orgId) {
37
- throw new ServerError("userContext must have an _orgId property to apply tenant filtering");
37
+ throw new ServerError('userContext must have an _orgId property to apply tenant filtering');
38
38
  }
39
39
  if (!result.filters) {
40
40
  result.filters = {};
@@ -49,7 +49,7 @@ export class TenantQueryDecorator {
49
49
  const shouldApplyTenantFilter = !this.options.excludedCollections?.includes(collectionName) &&
50
50
  userContext?.user._orgId;
51
51
  if (shouldApplyTenantFilter) {
52
- const orgIdField = this.options.orgIdField || "_orgId";
52
+ const orgIdField = this.options.orgIdField || '_orgId';
53
53
  result = {
54
54
  ...entity,
55
55
  [orgIdField]: userContext.user._orgId,
@@ -57,12 +57,12 @@ export class TenantQueryDecorator {
57
57
  }
58
58
  else if (!userContext?.user._orgId) {
59
59
  if (!this.options.excludedCollections?.includes(collectionName)) {
60
- throw new ServerError("No _orgId found in userContext");
60
+ throw new ServerError('No _orgId found in userContext');
61
61
  }
62
62
  }
63
63
  return result;
64
64
  }
65
65
  getOrgIdField() {
66
- return this.options.orgIdField || "_orgId";
66
+ return this.options.orgIdField || '_orgId';
67
67
  }
68
68
  }
@@ -1,6 +1,6 @@
1
- import { IUserContext, IUserRole } from "@loomcore/common/models";
2
- import { IDatabase } from "../databases/index.js";
3
- import { MultiTenantApiService } from "./multi-tenant-api.service.js";
1
+ import { IUserContext, IUserRole } from '@loomcore/common/models';
2
+ import { IDatabase } from '../databases/index.js';
3
+ import { MultiTenantApiService } from './multi-tenant-api.service.js';
4
4
  export declare class UserRolesService extends MultiTenantApiService<IUserRole> {
5
5
  constructor(database: IDatabase);
6
6
  preProcessEntity(userContext: IUserContext, entity: Partial<IUserRole>, isCreate: boolean, allowId?: boolean): Promise<Partial<IUserRole>>;
@@ -1,9 +1,9 @@
1
- import { UserRoleModelSpec } from "@loomcore/common/models";
2
- import { MultiTenantApiService } from "./multi-tenant-api.service.js";
3
- import { assertUserHasFeature } from "../utils/index.js";
1
+ import { UserRoleModelSpec } from '@loomcore/common/models';
2
+ import { MultiTenantApiService } from './multi-tenant-api.service.js';
3
+ import { assertUserHasFeature } from '../utils/index.js';
4
4
  export class UserRolesService extends MultiTenantApiService {
5
5
  constructor(database) {
6
- super(database, "userRoles", "userRole", UserRoleModelSpec);
6
+ super(database, 'userRoles', 'userRole', UserRoleModelSpec);
7
7
  }
8
8
  async preProcessEntity(userContext, entity, isCreate, allowId = true) {
9
9
  assertUserHasFeature(userContext, ['admin', 'system', 'user-roles']);
@@ -1,7 +1,7 @@
1
- import { type IModelSpec, type IPagedResult, type IQueryOptions, type IUser, type IUserContext } from "@loomcore/common/models";
2
- import type { AppIdType } from "@loomcore/common/types";
3
- import type { IDatabase } from "../databases/models/index.js";
4
- import { MultiTenantApiService } from "./multi-tenant-api.service.js";
1
+ import { type IModelSpec, type IPagedResult, type IQueryOptions, type IUser, type IUserContext } from '@loomcore/common/models';
2
+ import type { AppIdType } from '@loomcore/common/types';
3
+ import type { IDatabase } from '../databases/models/index.js';
4
+ import { MultiTenantApiService } from './multi-tenant-api.service.js';
5
5
  export declare class UserService extends MultiTenantApiService<IUser> {
6
6
  constructor(database: IDatabase, modelSpec?: IModelSpec);
7
7
  getById(userContext: IUserContext, id: AppIdType): Promise<IUser>;
@@ -1,11 +1,11 @@
1
- import { UserSpec, } from "@loomcore/common/models";
2
- import { BadRequestError, ServerError } from "../errors/index.js";
3
- import { assertAdmin, assertUserOrAdmin, } from "../utils/auth/index.js";
4
- import { passwordUtils } from "../utils/password.utils.js";
5
- import { MultiTenantApiService } from "./multi-tenant-api.service.js";
1
+ import { UserSpec, } from '@loomcore/common/models';
2
+ import { BadRequestError, ServerError } from '../errors/index.js';
3
+ import { assertAdmin, assertUserOrAdmin, } from '../utils/auth/index.js';
4
+ import { passwordUtils } from '../utils/password.utils.js';
5
+ import { MultiTenantApiService } from './multi-tenant-api.service.js';
6
6
  export class UserService extends MultiTenantApiService {
7
7
  constructor(database, modelSpec = UserSpec) {
8
- super(database, "users", "user", modelSpec);
8
+ super(database, 'users', 'user', modelSpec);
9
9
  }
10
10
  async getById(userContext, id) {
11
11
  assertUserOrAdmin(userContext, id);
@@ -24,7 +24,7 @@ export class UserService extends MultiTenantApiService {
24
24
  return super.getCount(userContext);
25
25
  }
26
26
  async fullUpdateById(_userContext, _id, _entity) {
27
- throw new ServerError("User full update is not allowed.");
27
+ throw new ServerError('User full update is not allowed.');
28
28
  }
29
29
  async update(userContext, queryObject, entity) {
30
30
  assertAdmin(userContext);
@@ -44,17 +44,17 @@ export class UserService extends MultiTenantApiService {
44
44
  return super.partialUpdateById(userContext, id, entity);
45
45
  }
46
46
  assertPasswordUpdateAllowed(userContext, id, entity, allowPasswordUpdate) {
47
- if (!("password" in entity)) {
47
+ if (!('password' in entity)) {
48
48
  return;
49
49
  }
50
50
  if (!entity.password) {
51
- throw new BadRequestError("Password cannot be empty.");
51
+ throw new BadRequestError('Password cannot be empty.');
52
52
  }
53
53
  if (!allowPasswordUpdate) {
54
- throw new ServerError("Use auth change password endpoint to update password.");
54
+ throw new ServerError('Use auth change password endpoint to update password.');
55
55
  }
56
56
  if (userContext.user._id !== id) {
57
- throw new ServerError("You can only update your own password.");
57
+ throw new ServerError('You can only update your own password.');
58
58
  }
59
59
  }
60
60
  async preProcessEntity(userContext, entity, isCreate, allowId = false) {
@@ -1,2 +1,2 @@
1
- import type { IUserContext } from "@loomcore/common/models";
1
+ import type { IUserContext } from '@loomcore/common/models';
2
2
  export declare function auditForCreate(userContext: IUserContext, doc: any): void;
@@ -1,5 +1,5 @@
1
- import { getSystemUserId } from "@loomcore/common/validation";
2
- import moment from "moment";
1
+ import { getSystemUserId } from '@loomcore/common/validation';
2
+ import moment from 'moment';
3
3
  export function auditForCreate(userContext, doc) {
4
4
  const now = moment().utc().toDate();
5
5
  const userId = userContext.user?._id ?? getSystemUserId();
@@ -1,2 +1,2 @@
1
- import type { IUserContext } from "@loomcore/common/models";
1
+ import type { IUserContext } from '@loomcore/common/models';
2
2
  export declare function auditForUpdate(userContext: IUserContext, doc: any): void;
@@ -1,5 +1,5 @@
1
- import { getSystemUserId } from "@loomcore/common/validation";
2
- import moment from "moment";
1
+ import { getSystemUserId } from '@loomcore/common/validation';
2
+ import moment from 'moment';
3
3
  export function auditForUpdate(userContext, doc) {
4
4
  const userId = userContext.user?._id ?? getSystemUserId();
5
5
  doc._updated = moment().utc().toDate();
@@ -1,2 +1,2 @@
1
- import type { IUserContext } from "@loomcore/common/models";
1
+ import type { IUserContext } from '@loomcore/common/models';
2
2
  export declare function stripSenderProvidedSystemProperties(userContext: IUserContext, entity: any, allowId?: boolean): void;
@@ -1,16 +1,16 @@
1
- import { getSystemUserId } from "@loomcore/common/validation";
1
+ import { getSystemUserId } from '@loomcore/common/validation';
2
2
  export function stripSenderProvidedSystemProperties(userContext, entity, allowId = false) {
3
3
  const isSystemUser = userContext.user?._id === getSystemUserId();
4
4
  if (isSystemUser) {
5
5
  return;
6
6
  }
7
- const propertiesToIgnore = ["_orgId"];
7
+ const propertiesToIgnore = ['_orgId'];
8
8
  if (allowId) {
9
- propertiesToIgnore.push("_id");
9
+ propertiesToIgnore.push('_id');
10
10
  }
11
11
  for (const key in entity) {
12
12
  if (Object.prototype.hasOwnProperty.call(entity, key) &&
13
- key.startsWith("_") &&
13
+ key.startsWith('_') &&
14
14
  !propertiesToIgnore.includes(key)) {
15
15
  delete entity[key];
16
16
  }
@@ -1,2 +1,2 @@
1
- import type { IUserContext } from "@loomcore/common/models";
1
+ import type { IUserContext } from '@loomcore/common/models';
2
2
  export declare function assertAdminOrFeature(userContext: IUserContext, features: string[], requireAll?: boolean): void;
@@ -1,5 +1,5 @@
1
- import { isAdmin } from "./is-admin.util.js";
2
- import { assertUserHasFeature } from "./assert-user-has-feature.util.js";
1
+ import { isAdmin } from './is-admin.util.js';
2
+ import { assertUserHasFeature } from './assert-user-has-feature.util.js';
3
3
  export function assertAdminOrFeature(userContext, features, requireAll = false) {
4
4
  if (isAdmin(userContext)) {
5
5
  return;
@@ -1,2 +1,2 @@
1
- import type { IUserContext } from "@loomcore/common/models";
1
+ import type { IUserContext } from '@loomcore/common/models';
2
2
  export declare function assertAdmin(userContext: IUserContext): void;
@@ -1,5 +1,5 @@
1
- import { UnauthorizedError } from "../../errors/index.js";
2
- import { isAdmin } from "./is-admin.util.js";
1
+ import { UnauthorizedError } from '../../errors/index.js';
2
+ import { isAdmin } from './is-admin.util.js';
3
3
  export function assertAdmin(userContext) {
4
4
  if (!isAdmin(userContext)) {
5
5
  throw new UnauthorizedError();
@@ -1,2 +1,2 @@
1
- import type { IAuditable, IUserContext } from "@loomcore/common/models";
1
+ import type { IAuditable, IUserContext } from '@loomcore/common/models';
2
2
  export declare function assertOwnerOrAdmin(userContext: IUserContext, auditable: IAuditable): void;
@@ -1,5 +1,5 @@
1
- import { UnauthorizedError } from "../../errors/index.js";
2
- import { isAdmin } from "./is-admin.util.js";
1
+ import { UnauthorizedError } from '../../errors/index.js';
2
+ import { isAdmin } from './is-admin.util.js';
3
3
  export function assertOwnerOrAdmin(userContext, auditable) {
4
4
  if (isAdmin(userContext)) {
5
5
  return;
@@ -1,2 +1,2 @@
1
- import { IUserContext } from "@loomcore/common/models";
1
+ import { IUserContext } from '@loomcore/common/models';
2
2
  export declare function assertUserHasFeature(userContext: IUserContext, features: string[], requireAll?: boolean): void;
@@ -1,4 +1,4 @@
1
- import { UnauthorizedError } from "../../errors/index.js";
1
+ import { UnauthorizedError } from '../../errors/index.js';
2
2
  export function assertUserHasFeature(userContext, features, requireAll = false) {
3
3
  if (features.length === 0) {
4
4
  return;
@@ -1,3 +1,3 @@
1
- import type { IUserContext } from "@loomcore/common/models";
2
- import type { AppIdType } from "@loomcore/common/types";
1
+ import type { IUserContext } from '@loomcore/common/models';
2
+ import type { AppIdType } from '@loomcore/common/types';
3
3
  export declare function assertUserOrAdmin(userContext: IUserContext, userId: AppIdType): void;
@@ -1,5 +1,5 @@
1
- import { UnauthorizedError } from "../../errors/index.js";
2
- import { isAdmin } from "./is-admin.util.js";
1
+ import { UnauthorizedError } from '../../errors/index.js';
2
+ import { isAdmin } from './is-admin.util.js';
3
3
  export function assertUserOrAdmin(userContext, userId) {
4
4
  if (isAdmin(userContext)) {
5
5
  return;
@@ -1,5 +1,5 @@
1
- import { type ILoginResponse, type IOrganization } from "@loomcore/common/models";
2
- import type { IDatabase } from "../../databases/models/index.js";
3
- import { AuthorizationsService } from "../../services/authorizations.service.js";
4
- import { UserService } from "../../services/user.service.js";
1
+ import { type ILoginResponse, type IOrganization } from '@loomcore/common/models';
2
+ import type { IDatabase } from '../../databases/models/index.js';
3
+ import { AuthorizationsService } from '../../services/authorizations.service.js';
4
+ import { UserService } from '../../services/user.service.js';
5
5
  export declare function attemptLogin(database: IDatabase, email: string, password: string, deviceId: string, organization: IOrganization | null, userService?: UserService, authorizationsService?: AuthorizationsService): Promise<ILoginResponse>;
@@ -1,9 +1,9 @@
1
- import { EmptyUserContext, } from "@loomcore/common/models";
2
- import { BadRequestError } from "../../errors/index.js";
3
- import { AuthorizationsService } from "../../services/authorizations.service.js";
4
- import { UserService } from "../../services/user.service.js";
5
- import { passwordUtils } from "../password.utils.js";
6
- import { logUserIn } from "./log-user-in.util.js";
1
+ import { EmptyUserContext, } from '@loomcore/common/models';
2
+ import { BadRequestError } from '../../errors/index.js';
3
+ import { AuthorizationsService } from '../../services/authorizations.service.js';
4
+ import { UserService } from '../../services/user.service.js';
5
+ import { passwordUtils } from '../password.utils.js';
6
+ import { logUserIn } from './log-user-in.util.js';
7
7
  export async function attemptLogin(database, email, password, deviceId, organization, userService = new UserService(database), authorizationsService = new AuthorizationsService(database)) {
8
8
  const lowerCaseEmail = email.toLowerCase();
9
9
  const userContext = {
@@ -19,11 +19,11 @@ export async function attemptLogin(database, email, password, deviceId, organiza
19
19
  },
20
20
  });
21
21
  if (!user) {
22
- throw new BadRequestError("Invalid Credentials");
22
+ throw new BadRequestError('Invalid Credentials');
23
23
  }
24
24
  const passwordsMatch = await passwordUtils.comparePasswords(user.password, password);
25
25
  if (!passwordsMatch) {
26
- throw new BadRequestError("Invalid Credentials");
26
+ throw new BadRequestError('Invalid Credentials');
27
27
  }
28
28
  const features = await authorizationsService.getUserContextFeatures(user);
29
29
  const authenticatedUserContext = {
@@ -1,3 +1,3 @@
1
- import { type IModelSpec } from "@loomcore/common/models";
1
+ import { type IModelSpec } from '@loomcore/common/models';
2
2
  export declare function createLoginResponseSpec(userContextSpec: IModelSpec): IModelSpec;
3
3
  export declare function getAuthUserContextSpec(): IModelSpec;
@@ -1,6 +1,6 @@
1
- import { TokenResponseSchema, UserContextSpec, } from "@loomcore/common/models";
2
- import { entityUtils } from "@loomcore/common/utils";
3
- import { Type } from "@sinclair/typebox";
1
+ import { TokenResponseSchema, UserContextSpec, } from '@loomcore/common/models';
2
+ import { entityUtils } from '@loomcore/common/utils';
3
+ import { Type } from '@sinclair/typebox';
4
4
  export function createLoginResponseSpec(userContextSpec) {
5
5
  authUserContextSpec = userContextSpec;
6
6
  return entityUtils.getModelSpec(Type.Object({
@@ -1,5 +1,5 @@
1
- import type { IUserContext } from "@loomcore/common/models";
2
- import type { IDatabase } from "../../databases/models/index.js";
3
- import type { UpdateResult } from "../../databases/models/update-result.js";
4
- import { UserService } from "../../services/user.service.js";
1
+ import type { IUserContext } from '@loomcore/common/models';
2
+ import type { IDatabase } from '../../databases/models/index.js';
3
+ import type { UpdateResult } from '../../databases/models/update-result.js';
4
+ import { UserService } from '../../services/user.service.js';
5
5
  export declare function changePassword(database: IDatabase, userContext: IUserContext, password: string, userService?: UserService): Promise<UpdateResult>;
@@ -1,5 +1,5 @@
1
- import moment from "moment";
2
- import { UserService } from "../../services/user.service.js";
1
+ import moment from 'moment';
2
+ import { UserService } from '../../services/user.service.js';
3
3
  export async function changePassword(database, userContext, password, userService = new UserService(database)) {
4
4
  const updates = {
5
5
  password: password,
@@ -1,4 +1,4 @@
1
- import { type IRefreshToken } from "@loomcore/common/models";
2
- import type { AppIdType } from "@loomcore/common/types";
3
- import type { IDatabase } from "../../databases/models/index.js";
1
+ import { type IRefreshToken } from '@loomcore/common/models';
2
+ import type { AppIdType } from '@loomcore/common/types';
3
+ import type { IDatabase } from '../../databases/models/index.js';
4
4
  export declare function createNewRefreshToken(database: IDatabase, userId: AppIdType, deviceId: string, orgId?: AppIdType): Promise<IRefreshToken>;
@@ -1,10 +1,10 @@
1
- import { getSystemUserContext } from "@loomcore/common/models";
2
- import moment from "moment";
3
- import { ServerError } from "../../errors/index.js";
4
- import { RefreshTokenService } from "../../services/refresh-token.service.js";
5
- import { generateRefreshToken } from "./generate-refresh-token.util.js";
6
- import { getAuthConfig } from "./get-auth-config.util.js";
7
- import { getExpiresOnFromDays } from "./get-expires-on-from-days.util.js";
1
+ import { getSystemUserContext } from '@loomcore/common/models';
2
+ import moment from 'moment';
3
+ import { ServerError } from '../../errors/index.js';
4
+ import { RefreshTokenService } from '../../services/refresh-token.service.js';
5
+ import { generateRefreshToken } from './generate-refresh-token.util.js';
6
+ import { getAuthConfig } from './get-auth-config.util.js';
7
+ import { getExpiresOnFromDays } from './get-expires-on-from-days.util.js';
8
8
  export async function createNewRefreshToken(database, userId, deviceId, orgId) {
9
9
  const authConfig = getAuthConfig();
10
10
  const expiresOn = getExpiresOnFromDays(authConfig.refreshTokenExpirationInDays);
@@ -23,7 +23,7 @@ export async function createNewRefreshToken(database, userId, deviceId, orgId) {
23
23
  });
24
24
  const insertResult = await refreshTokenService.create(getSystemUserContext(), newRefreshToken);
25
25
  if (!insertResult) {
26
- throw new ServerError("Failed to create refresh token");
26
+ throw new ServerError('Failed to create refresh token');
27
27
  }
28
28
  return insertResult;
29
29
  }
@@ -1,2 +1,2 @@
1
- import type { IRefreshToken, ITokenResponse, IUserContext } from "@loomcore/common/models";
1
+ import type { IRefreshToken, ITokenResponse, IUserContext } from '@loomcore/common/models';
2
2
  export declare function createNewTokens(userContext: IUserContext, activeRefreshToken: IRefreshToken): Promise<ITokenResponse>;
@@ -1,6 +1,6 @@
1
- import { generateJwt } from "../jwt.utils.js";
2
- import { getAuthConfig } from "./get-auth-config.util.js";
3
- import { getExpiresOnFromSeconds } from "./get-expires-on-from-seconds.util.js";
1
+ import { generateJwt } from '../jwt.utils.js';
2
+ import { getAuthConfig } from './get-auth-config.util.js';
3
+ import { getExpiresOnFromSeconds } from './get-expires-on-from-seconds.util.js';
4
4
  export async function createNewTokens(userContext, activeRefreshToken) {
5
5
  const authConfig = getAuthConfig();
6
6
  const accessToken = generateJwt(userContext);
@@ -1,4 +1,4 @@
1
- import crypto from "node:crypto";
1
+ import crypto from 'node:crypto';
2
2
  export function generateDeviceId() {
3
- return crypto.randomBytes(40).toString("hex");
3
+ return crypto.randomBytes(40).toString('hex');
4
4
  }
@@ -1,4 +1,4 @@
1
- import crypto from "node:crypto";
1
+ import crypto from 'node:crypto';
2
2
  export function generateRefreshToken() {
3
- return crypto.randomBytes(40).toString("hex");
3
+ return crypto.randomBytes(40).toString('hex');
4
4
  }
@@ -1,3 +1,3 @@
1
- import type { IRefreshToken, IUserContext } from "@loomcore/common/models";
2
- import type { IDatabase } from "../../databases/models/index.js";
1
+ import type { IRefreshToken, IUserContext } from '@loomcore/common/models';
2
+ import type { IDatabase } from '../../databases/models/index.js';
3
3
  export declare function getActiveRefreshToken(database: IDatabase, userContext: IUserContext, refreshToken: string, deviceId: string): Promise<IRefreshToken | null>;
@@ -1,4 +1,4 @@
1
- import { RefreshTokenService } from "../../services/refresh-token.service.js";
1
+ import { RefreshTokenService } from '../../services/refresh-token.service.js';
2
2
  export async function getActiveRefreshToken(database, userContext, refreshToken, deviceId) {
3
3
  const refreshTokenService = new RefreshTokenService(database);
4
4
  const refreshTokenResult = await refreshTokenService.findOne(userContext, {
@@ -1,2 +1,2 @@
1
- import type { Request, Response } from "express";
1
+ import type { Request, Response } from 'express';
2
2
  export declare function getAndSetDeviceIdCookie(req: Request, res: Response): string;
@@ -1,6 +1,6 @@
1
- import { generateDeviceId } from "./generate-device-id.util.js";
2
- import { getAuthConfig } from "./get-auth-config.util.js";
3
- import { getDeviceIdFromCookie } from "./get-device-id-from-cookie.util.js";
1
+ import { generateDeviceId } from './generate-device-id.util.js';
2
+ import { getAuthConfig } from './get-auth-config.util.js';
3
+ import { getDeviceIdFromCookie } from './get-device-id-from-cookie.util.js';
4
4
  export function getAndSetDeviceIdCookie(req, res) {
5
5
  let deviceId;
6
6
  const deviceIdFromCookie = getDeviceIdFromCookie(req);
@@ -17,7 +17,7 @@ export function getAndSetDeviceIdCookie(req, res) {
17
17
  maxAge: authConfig.deviceIdCookieMaxAgeInDays * 24 * 60 * 60 * 1000,
18
18
  httpOnly: true,
19
19
  };
20
- res.cookie("deviceId", deviceId, cookieOptions);
20
+ res.cookie('deviceId', deviceId, cookieOptions);
21
21
  }
22
22
  return deviceId;
23
23
  }
@@ -1,2 +1,2 @@
1
- import type { IAuthConfig } from "../../models/auth-config.interface.js";
1
+ import type { IAuthConfig } from '../../models/auth-config.interface.js';
2
2
  export declare function getAuthConfig(): IAuthConfig;
@@ -1,8 +1,8 @@
1
- import { config } from "../../config/index.js";
2
- import { ServerError } from "../../errors/index.js";
1
+ import { config } from '../../config/index.js';
2
+ import { ServerError } from '../../errors/index.js';
3
3
  export function getAuthConfig() {
4
4
  if (!config.auth) {
5
- throw new ServerError("Auth configuration is not set");
5
+ throw new ServerError('Auth configuration is not set');
6
6
  }
7
7
  return config.auth;
8
8
  }
@@ -1,2 +1,2 @@
1
- import type { Request } from "express";
1
+ import type { Request } from 'express';
2
2
  export declare function getDeviceIdFromCookie(req: Request): any;
@@ -1,26 +1,26 @@
1
- export * from "./assert-admin.util.js";
2
- export * from "./assert-admin-or-feature.util.js";
3
- export * from "./assert-owner-or-admin.util.js";
4
- export * from "./assert-user-or-admin.util.js";
5
- export * from "./attempt-login.util.js";
6
- export * from "./auth-user-specs.util.js";
7
- export * from "./assert-user-has-feature.util.js";
8
- export * from "./change-password.util.js";
9
- export * from "./create-new-refresh-token.util.js";
10
- export * from "./create-new-tokens.util.js";
11
- export * from "./generate-device-id.util.js";
12
- export * from "./generate-refresh-token.util.js";
13
- export * from "./get-active-refresh-token.util.js";
14
- export * from "./get-and-set-device-id-cookie.util.js";
15
- export * from "./get-auth-config.util.js";
16
- export * from "./get-device-id-from-cookie.util.js";
17
- export * from "./get-expires-on-from-days.util.js";
18
- export * from "./get-expires-on-from-minutes.util.js";
19
- export * from "./get-expires-on-from-seconds.util.js";
20
- export * from "./is-admin.util.js";
21
- export * from "./log-user-in.util.js";
22
- export * from "./request-token-using-refresh-token.util.js";
23
- export * from "./reset-password.util.js";
24
- export * from "./send-reset-password-email.util.js";
25
- export * from "./update-last-logged-in.util.js";
26
- export * from "./authorize-method.util.js";
1
+ export * from './assert-admin.util.js';
2
+ export * from './assert-admin-or-feature.util.js';
3
+ export * from './assert-owner-or-admin.util.js';
4
+ export * from './assert-user-or-admin.util.js';
5
+ export * from './attempt-login.util.js';
6
+ export * from './auth-user-specs.util.js';
7
+ export * from './assert-user-has-feature.util.js';
8
+ export * from './change-password.util.js';
9
+ export * from './create-new-refresh-token.util.js';
10
+ export * from './create-new-tokens.util.js';
11
+ export * from './generate-device-id.util.js';
12
+ export * from './generate-refresh-token.util.js';
13
+ export * from './get-active-refresh-token.util.js';
14
+ export * from './get-and-set-device-id-cookie.util.js';
15
+ export * from './get-auth-config.util.js';
16
+ export * from './get-device-id-from-cookie.util.js';
17
+ export * from './get-expires-on-from-days.util.js';
18
+ export * from './get-expires-on-from-minutes.util.js';
19
+ export * from './get-expires-on-from-seconds.util.js';
20
+ export * from './is-admin.util.js';
21
+ export * from './log-user-in.util.js';
22
+ export * from './request-token-using-refresh-token.util.js';
23
+ export * from './reset-password.util.js';
24
+ export * from './send-reset-password-email.util.js';
25
+ export * from './update-last-logged-in.util.js';
26
+ export * from './authorize-method.util.js';