@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,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';
@@ -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 isAdmin(userContext: IUserContext): boolean;
@@ -1,3 +1,3 @@
1
1
  export function isAdmin(userContext) {
2
- return userContext.features.some((feature) => feature === "admin" || feature === "system");
2
+ return userContext.features.some((feature) => feature === 'admin' || feature === 'system');
3
3
  }
@@ -1,4 +1,4 @@
1
- import type { ITokenResponse, IUserContext } from "@loomcore/common/models";
2
- import type { IDatabase } from "../../databases/models/index.js";
3
- import type { UserService } from "../../services/user.service.js";
1
+ import type { ITokenResponse, IUserContext } from '@loomcore/common/models';
2
+ import type { IDatabase } from '../../databases/models/index.js';
3
+ import type { UserService } from '../../services/user.service.js';
4
4
  export declare function logUserIn(database: IDatabase, userContext: IUserContext, deviceId: string, userService?: UserService): Promise<ITokenResponse>;
@@ -1,8 +1,8 @@
1
- import { generateJwt } from "../jwt.utils.js";
2
- import { createNewRefreshToken } from "./create-new-refresh-token.util.js";
3
- import { getAuthConfig } from "./get-auth-config.util.js";
4
- import { getExpiresOnFromSeconds } from "./get-expires-on-from-seconds.util.js";
5
- import { updateLastLoggedIn } from "./update-last-logged-in.util.js";
1
+ import { generateJwt } from '../jwt.utils.js';
2
+ import { createNewRefreshToken } from './create-new-refresh-token.util.js';
3
+ import { getAuthConfig } from './get-auth-config.util.js';
4
+ import { getExpiresOnFromSeconds } from './get-expires-on-from-seconds.util.js';
5
+ import { updateLastLoggedIn } from './update-last-logged-in.util.js';
6
6
  export async function logUserIn(database, userContext, deviceId, userService) {
7
7
  const authConfig = getAuthConfig();
8
8
  const accessToken = generateJwt(userContext);
@@ -1,5 +1,5 @@
1
- import { type ITokenResponse } 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 ITokenResponse } 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 requestTokenUsingRefreshToken(database: IDatabase, refreshToken: string, deviceId: string, userService?: UserService, authorizationsService?: AuthorizationsService): Promise<ITokenResponse | null>;
@@ -1,9 +1,9 @@
1
- import { getSystemUserContext, } from "@loomcore/common/models";
2
- import { AuthorizationsService } from "../../services/authorizations.service.js";
3
- import { UserService } from "../../services/user.service.js";
4
- import { createNewTokens } from "./create-new-tokens.util.js";
5
- import { getActiveRefreshToken } from "./get-active-refresh-token.util.js";
6
- import { BadRequestError } from "../../errors/index.js";
1
+ import { getSystemUserContext, } from '@loomcore/common/models';
2
+ import { AuthorizationsService } from '../../services/authorizations.service.js';
3
+ import { UserService } from '../../services/user.service.js';
4
+ import { createNewTokens } from './create-new-tokens.util.js';
5
+ import { getActiveRefreshToken } from './get-active-refresh-token.util.js';
6
+ import { BadRequestError } from '../../errors/index.js';
7
7
  export async function requestTokenUsingRefreshToken(database, refreshToken, deviceId, userService = new UserService(database), authorizationsService = new AuthorizationsService(database)) {
8
8
  const systemUserContext = getSystemUserContext();
9
9
  const activeRefreshToken = await getActiveRefreshToken(database, systemUserContext, refreshToken, deviceId);
@@ -15,7 +15,7 @@ export async function requestTokenUsingRefreshToken(database, refreshToken, devi
15
15
  };
16
16
  const user = await userService.findOne(systemUserContext, userQueryOptions);
17
17
  if (!user) {
18
- throw new BadRequestError("User not found");
18
+ throw new BadRequestError('User not found');
19
19
  }
20
20
  const features = await authorizationsService.getUserContextFeatures(user);
21
21
  const userContext = {
@@ -1,5 +1,5 @@
1
- import { type IModelSpec, type IOrganization } 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 IModelSpec, type IOrganization } 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 resetPassword(database: IDatabase, email: string, passwordResetToken: string, password: string, organization: IOrganization | null, userService?: UserService, userSpec?: IModelSpec): Promise<UpdateResult>;
@@ -1,12 +1,12 @@
1
- import { EmptyUserContext, passwordValidator, UserSpec, } from "@loomcore/common/models";
2
- import { entityUtils } from "@loomcore/common/utils";
3
- import { BadRequestError, ServerError } from "../../errors/index.js";
4
- import { PasswordResetTokenService } from "../../services/password-reset-token.service.js";
5
- import { UserService } from "../../services/user.service.js";
6
- import { changePassword } from "./change-password.util.js";
1
+ import { EmptyUserContext, passwordValidator, UserSpec, } from '@loomcore/common/models';
2
+ import { entityUtils } from '@loomcore/common/utils';
3
+ import { BadRequestError, ServerError } from '../../errors/index.js';
4
+ import { PasswordResetTokenService } from '../../services/password-reset-token.service.js';
5
+ import { UserService } from '../../services/user.service.js';
6
+ import { changePassword } from './change-password.util.js';
7
7
  export async function resetPassword(database, email, passwordResetToken, password, organization, userService = new UserService(database), userSpec = UserSpec) {
8
8
  const validationErrors = entityUtils.validate(userSpec, { password: password }, true, passwordValidator);
9
- entityUtils.handleValidationResult(validationErrors, "AuthService.resetPassword");
9
+ entityUtils.handleValidationResult(validationErrors, 'AuthService.resetPassword');
10
10
  const lowerCaseEmail = email.toLowerCase();
11
11
  const passwordResetTokenService = new PasswordResetTokenService(database);
12
12
  const userContext = {
@@ -24,7 +24,7 @@ export async function resetPassword(database, email, passwordResetToken, passwor
24
24
  }
25
25
  if (retrievedPasswordResetToken.token !== passwordResetToken ||
26
26
  retrievedPasswordResetToken.expiresOn < Date.now()) {
27
- throw new BadRequestError("Invalid password reset token");
27
+ throw new BadRequestError('Invalid password reset token');
28
28
  }
29
29
  const user = await userService.findOne(userContext, {
30
30
  filters: { email: { eq: lowerCaseEmail } },
@@ -1,3 +1,3 @@
1
- import { type IUserContext } from "@loomcore/common/models";
2
- import type { IDatabase } from "../../databases/models/index.js";
1
+ import { type IUserContext } from '@loomcore/common/models';
2
+ import type { IDatabase } from '../../databases/models/index.js';
3
3
  export declare function sendResetPasswordEmail(userContext: IUserContext, database: IDatabase, emailAddress: string, clientBaseUrl: string): Promise<void>;
@@ -1,8 +1,8 @@
1
- import { ServerError } from "../../errors/index.js";
2
- import { EmailService } from "../../services/email.service.js";
3
- import { PasswordResetTokenService } from "../../services/password-reset-token.service.js";
4
- import { getAuthConfig } from "./get-auth-config.util.js";
5
- import { getExpiresOnFromMinutes } from "./get-expires-on-from-minutes.util.js";
1
+ import { ServerError } from '../../errors/index.js';
2
+ import { EmailService } from '../../services/email.service.js';
3
+ import { PasswordResetTokenService } from '../../services/password-reset-token.service.js';
4
+ import { getAuthConfig } from './get-auth-config.util.js';
5
+ import { getExpiresOnFromMinutes } from './get-expires-on-from-minutes.util.js';
6
6
  export async function sendResetPasswordEmail(userContext, database, emailAddress, clientBaseUrl) {
7
7
  const authConfig = getAuthConfig();
8
8
  const passwordResetTokenService = new PasswordResetTokenService(database);
@@ -1,4 +1,4 @@
1
- import type { AppIdType } from "@loomcore/common/types";
2
- import type { IDatabase } from "../../databases/models/index.js";
3
- import { UserService } from "../../services/user.service.js";
1
+ import type { AppIdType } from '@loomcore/common/types';
2
+ import type { IDatabase } from '../../databases/models/index.js';
3
+ import { UserService } from '../../services/user.service.js';
4
4
  export declare function updateLastLoggedIn(database: IDatabase, userId: AppIdType, userService?: UserService): Promise<void>;
@@ -1,6 +1,6 @@
1
- import { getSystemUserContext } from "@loomcore/common/models";
2
- import moment from "moment";
3
- import { UserService } from "../../services/user.service.js";
1
+ import { getSystemUserContext } from '@loomcore/common/models';
2
+ import moment from 'moment';
3
+ import { UserService } from '../../services/user.service.js';
4
4
  export async function updateLastLoggedIn(database, userId, userService = new UserService(database)) {
5
5
  try {
6
6
  const updates = {
@@ -1,2 +1,2 @@
1
- import { IModelSpec } from "@loomcore/common/models";
1
+ import { IModelSpec } from '@loomcore/common/models';
2
2
  export declare function createPublicSpec(spec: IModelSpec): IModelSpec;
@@ -1,5 +1,5 @@
1
- import { entityUtils } from "@loomcore/common/utils";
2
- import { config } from "../config/index.js";
1
+ import { entityUtils } from '@loomcore/common/utils';
2
+ import { config } from '../config/index.js';
3
3
  export function createPublicSpec(spec) {
4
4
  if (config.debug?.showAuditFields) {
5
5
  return spec;
@@ -1,8 +1,8 @@
1
1
  import { Application } from 'express';
2
- import { MongoClient } from "mongodb";
3
- import type { Client, Pool } from "pg";
4
- import { Server } from "http";
5
- import { IBaseApiConfig } from "../models/index.js";
2
+ import { MongoClient } from 'mongodb';
3
+ import type { Client, Pool } from 'pg';
4
+ import { Server } from 'http';
5
+ import { IBaseApiConfig } from '../models/index.js';
6
6
  import { IDatabase } from '../databases/models/index.js';
7
7
  type RouteSetupFunction = (app: Application, database: IDatabase, config: IBaseApiConfig) => void;
8
8
  declare function setupExpressApp(database: IDatabase, config: IBaseApiConfig, setupRoutes: RouteSetupFunction): Application;
@@ -1,10 +1,10 @@
1
1
  import express from 'express';
2
- import cookieParser from "cookie-parser";
3
- import bodyParser from "body-parser";
4
- import cors from "cors";
2
+ import cookieParser from 'cookie-parser';
3
+ import bodyParser from 'body-parser';
4
+ import cors from 'cors';
5
5
  import qs from 'qs';
6
- import { NotFoundError } from "../errors/not-found.error.js";
7
- import { errorHandler } from "../middleware/error-handler.js";
6
+ import { NotFoundError } from '../errors/not-found.error.js';
7
+ import { errorHandler } from '../middleware/error-handler.js';
8
8
  import { ensureUserContext } from '../middleware/ensure-user-context.js';
9
9
  function setupExpressApp(database, config, setupRoutes) {
10
10
  const app = express();
@@ -1,10 +1,10 @@
1
- export * from "./address.utils.js";
2
- export * from "./api.utils.js";
3
- export * from "./auth/index.js";
4
- export * from "./conversion.utils.js";
5
- export * from "./create-public-spec.utils.js";
6
- export * from "./express.utils.js";
7
- export * from "./jwt.utils.js";
8
- export * from "./logger.utils.js";
9
- export * from "./password.utils.js";
10
- export * from "./string.utils.js";
1
+ export * from './address.utils.js';
2
+ export * from './api.utils.js';
3
+ export * from './auth/index.js';
4
+ export * from './conversion.utils.js';
5
+ export * from './create-public-spec.utils.js';
6
+ export * from './express.utils.js';
7
+ export * from './jwt.utils.js';
8
+ export * from './logger.utils.js';
9
+ export * from './password.utils.js';
10
+ export * from './string.utils.js';
@@ -1,10 +1,10 @@
1
- export * from "./address.utils.js";
2
- export * from "./api.utils.js";
3
- export * from "./auth/index.js";
4
- export * from "./conversion.utils.js";
5
- export * from "./create-public-spec.utils.js";
6
- export * from "./express.utils.js";
7
- export * from "./jwt.utils.js";
8
- export * from "./logger.utils.js";
9
- export * from "./password.utils.js";
10
- export * from "./string.utils.js";
1
+ export * from './address.utils.js';
2
+ export * from './api.utils.js';
3
+ export * from './auth/index.js';
4
+ export * from './conversion.utils.js';
5
+ export * from './create-public-spec.utils.js';
6
+ export * from './express.utils.js';
7
+ export * from './jwt.utils.js';
8
+ export * from './logger.utils.js';
9
+ export * from './password.utils.js';
10
+ export * from './string.utils.js';
@@ -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 generateJwt(userContext: IUserContext): string;
@@ -1,9 +1,9 @@
1
- import jwt from "jsonwebtoken";
2
- import { getAuthConfig } from "./auth/get-auth-config.util.js";
1
+ import jwt from 'jsonwebtoken';
2
+ import { getAuthConfig } from './auth/get-auth-config.util.js';
3
3
  export function generateJwt(userContext) {
4
4
  const authConfig = getAuthConfig();
5
5
  const jwtExpiryConfig = authConfig.jwtExpirationInSeconds;
6
- const jwtExpirationInSeconds = typeof jwtExpiryConfig === "string"
6
+ const jwtExpirationInSeconds = typeof jwtExpiryConfig === 'string'
7
7
  ? Number.parseInt(jwtExpiryConfig, 10)
8
8
  : jwtExpiryConfig;
9
9
  return jwt.sign(userContext, authConfig.clientSecret, {
@@ -1,4 +1,4 @@
1
- import { LogLevel } from "../models/index.js";
1
+ import { LogLevel } from '../models/index.js';
2
2
  export declare const getCurrentLogLevel: () => LogLevel;
3
3
  export declare const logger: {
4
4
  debug: (...args: unknown[]) => void;
@@ -1,4 +1,4 @@
1
- import { config } from "../config/index.js";
1
+ import { config } from '../config/index.js';
2
2
  const LOG_LEVEL_PRIORITIES = {
3
3
  debug: 0,
4
4
  info: 1,
@@ -7,13 +7,13 @@ const LOG_LEVEL_PRIORITIES = {
7
7
  };
8
8
  export const getCurrentLogLevel = () => {
9
9
  const envLogLevel = config.debug?.logLevel?.toLowerCase();
10
- if (envLogLevel === "debug" ||
11
- envLogLevel === "info" ||
12
- envLogLevel === "warn" ||
13
- envLogLevel === "error") {
10
+ if (envLogLevel === 'debug' ||
11
+ envLogLevel === 'info' ||
12
+ envLogLevel === 'warn' ||
13
+ envLogLevel === 'error') {
14
14
  return envLogLevel;
15
15
  }
16
- return "info";
16
+ return 'info';
17
17
  };
18
18
  const shouldLog = (messageLevel) => {
19
19
  const currentLevel = getCurrentLogLevel();
@@ -21,22 +21,22 @@ const shouldLog = (messageLevel) => {
21
21
  };
22
22
  export const logger = {
23
23
  debug: (...args) => {
24
- if (shouldLog("debug")) {
24
+ if (shouldLog('debug')) {
25
25
  console.debug(...args);
26
26
  }
27
27
  },
28
28
  info: (...args) => {
29
- if (shouldLog("info")) {
29
+ if (shouldLog('info')) {
30
30
  console.info(...args);
31
31
  }
32
32
  },
33
33
  warn: (...args) => {
34
- if (shouldLog("warn")) {
34
+ if (shouldLog('warn')) {
35
35
  console.warn(...args);
36
36
  }
37
37
  },
38
38
  error: (...args) => {
39
- if (shouldLog("error")) {
39
+ if (shouldLog('error')) {
40
40
  console.error(...args);
41
41
  }
42
42
  },
@@ -1,21 +1,21 @@
1
- import { randomBytes, scrypt } from "node:crypto";
2
- import { promisify } from "util";
1
+ import { randomBytes, scrypt } from 'node:crypto';
2
+ import { promisify } from 'util';
3
3
  const scryptAsync = promisify(scrypt);
4
4
  async function hashPassword(password) {
5
- const salt = randomBytes(8).toString("hex");
5
+ const salt = randomBytes(8).toString('hex');
6
6
  const buf = (await scryptAsync(password, salt, 64));
7
- return `${buf.toString("hex")}.${salt}`;
7
+ return `${buf.toString('hex')}.${salt}`;
8
8
  }
9
9
  async function comparePasswords(storedPassword, suppliedPassword) {
10
- if (!storedPassword?.includes(".")) {
10
+ if (!storedPassword?.includes('.')) {
11
11
  return false;
12
12
  }
13
- const [hashedPassword, salt] = storedPassword.split(".");
13
+ const [hashedPassword, salt] = storedPassword.split('.');
14
14
  if (!salt) {
15
15
  return false;
16
16
  }
17
17
  const buf = (await scryptAsync(suppliedPassword, salt, 64));
18
- return buf.toString("hex") === hashedPassword;
18
+ return buf.toString('hex') === hashedPassword;
19
19
  }
20
20
  export const passwordUtils = {
21
21
  hashPassword,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcore/api",
3
- "version": "0.2.42",
3
+ "version": "0.2.45",
4
4
  "private": false,
5
5
  "description": "Loom Core Api - An opinionated Node.js api using Typescript, Express, and MongoDb or PostgreSQL",
6
6
  "scripts": {
@@ -46,6 +46,7 @@
46
46
  "./config": "./dist/config/index.js",
47
47
  "./controllers": "./dist/controllers/index.js",
48
48
  "./databases": "./dist/databases/index.js",
49
+ "./decorators": "./dist/decorators/index.js",
49
50
  "./errors": "./dist/errors/index.js",
50
51
  "./middleware": "./dist/middleware/index.js",
51
52
  "./models": "./dist/models/index.js",