openloops 0.5.0 → 0.7.0

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 (547) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +3 -2
  3. package/dist/clients/llm/llm-client.mjs +0 -1
  4. package/dist/clients/llm/llm-error.mjs +0 -1
  5. package/dist/clients/llm/llm-types.mjs +0 -1
  6. package/dist/clients/llm/model-resolution.mjs +0 -1
  7. package/dist/clients/llm/pi-ai-adapter.mjs +0 -1
  8. package/dist/clients/llm/sampling-rules.mjs +0 -1
  9. package/dist/clients/serper/serper-client.mjs +0 -1
  10. package/dist/clients/slack/slack-client.mjs +0 -1
  11. package/dist/common/base/base.app.d.ts +3 -3
  12. package/dist/common/base/base.app.mjs +0 -1
  13. package/dist/common/base/base.entity.d.ts +7 -25
  14. package/dist/common/base/base.entity.js +26 -133
  15. package/dist/common/base/base.entity.mjs +26 -128
  16. package/dist/common/base/base.use-case.d.ts +3 -7
  17. package/dist/common/base/base.use-case.mjs +0 -1
  18. package/dist/common/base/current-session.mjs +0 -1
  19. package/dist/common/base/current-user.mjs +0 -1
  20. package/dist/common/base/index.d.ts +1 -0
  21. package/dist/common/base/index.js +3 -1
  22. package/dist/common/base/index.mjs +1 -0
  23. package/dist/common/base/share.d.ts +12 -0
  24. package/dist/common/base/share.js +45 -0
  25. package/dist/common/base/share.mjs +20 -0
  26. package/dist/common/base/utils/index.d.ts +1 -2
  27. package/dist/common/base/utils/index.js +2 -4
  28. package/dist/common/base/utils/index.mjs +1 -2
  29. package/dist/common/base/utils/is-plain-object.mjs +0 -1
  30. package/dist/common/base/utils/to-patch.d.ts +9 -0
  31. package/dist/common/base/utils/to-patch.js +46 -0
  32. package/dist/common/base/utils/to-patch.mjs +21 -0
  33. package/dist/common/constants/harness.mjs +0 -1
  34. package/dist/common/error/http-error.mjs +0 -1
  35. package/dist/common/error/reportError.mjs +0 -1
  36. package/dist/common/error/sentry-client.mjs +0 -1
  37. package/dist/common/helpers/escape-regex.mjs +0 -1
  38. package/dist/common/helpers/extract-json-from-text.mjs +0 -1
  39. package/dist/common/helpers/sanitize-string.mjs +0 -1
  40. package/dist/common/logger/pino.mjs +0 -1
  41. package/dist/common/repositories/index.d.ts +1 -0
  42. package/dist/common/repositories/index.js +3 -1
  43. package/dist/common/repositories/index.mjs +1 -0
  44. package/dist/common/repositories/mongo-db.client.mjs +0 -1
  45. package/dist/common/repositories/mongo-db.repository.d.ts +42 -11
  46. package/dist/common/repositories/mongo-db.repository.js +152 -42
  47. package/dist/common/repositories/mongo-db.repository.mjs +152 -43
  48. package/dist/common/repositories/scope.d.ts +19 -0
  49. package/dist/common/repositories/scope.js +63 -0
  50. package/dist/common/repositories/scope.mjs +39 -0
  51. package/dist/common/utils/database-name.mjs +0 -1
  52. package/dist/common/utils/number-setting.mjs +0 -1
  53. package/dist/common/utils/secret-manager.mjs +0 -1
  54. package/dist/db/indexes/agent-actions.mjs +0 -1
  55. package/dist/db/indexes/agent-tasks.mjs +0 -1
  56. package/dist/db/indexes/agent-traces.mjs +0 -1
  57. package/dist/db/indexes/automation-runs.mjs +0 -1
  58. package/dist/db/indexes/automations.mjs +0 -1
  59. package/dist/db/indexes/chats.mjs +0 -1
  60. package/dist/db/indexes/index.js +3 -1
  61. package/dist/db/indexes/index.mjs +3 -2
  62. package/dist/db/indexes/llm-calls.mjs +0 -1
  63. package/dist/db/indexes/mcp-servers.mjs +0 -1
  64. package/dist/db/indexes/refresh-tokens.d.ts +2 -0
  65. package/dist/{common/decorators/admin-only/index.js → db/indexes/refresh-tokens.js} +16 -5
  66. package/dist/db/indexes/refresh-tokens.mjs +9 -0
  67. package/dist/db/indexes/revoked-tokens.mjs +0 -1
  68. package/dist/db/indexes/workspace-items.mjs +0 -1
  69. package/dist/db/migrations/automations.mjs +0 -1
  70. package/dist/guardrails/guard.mjs +0 -1
  71. package/dist/guardrails/index.mjs +0 -1
  72. package/dist/guardrails/input/block-card.mjs +0 -1
  73. package/dist/guardrails/input/block-code.mjs +0 -1
  74. package/dist/guardrails/input/block-email.mjs +0 -1
  75. package/dist/guardrails/input/create-block-input-oversize.mjs +0 -1
  76. package/dist/guardrails/input/diagnostic-sanity.mjs +0 -1
  77. package/dist/guardrails/input/input-check.mjs +0 -1
  78. package/dist/harness/agent-loop.mjs +0 -1
  79. package/dist/harness/agent-state.mjs +0 -1
  80. package/dist/harness/agent.d.ts +0 -1
  81. package/dist/harness/agent.js +14 -14
  82. package/dist/harness/agent.mjs +14 -15
  83. package/dist/harness/native-tools.mjs +0 -1
  84. package/dist/harness/skills/approval-request.mjs +0 -1
  85. package/dist/harness/skills/autonomous-answer.mjs +0 -1
  86. package/dist/harness/skills/confirmation-gate.mjs +0 -1
  87. package/dist/harness/skills/mcp-change-review.mjs +0 -1
  88. package/dist/harness/tool-catalog.mjs +0 -1
  89. package/dist/harness/tool-pipeline.mjs +0 -1
  90. package/dist/harness/utils/activity.mjs +0 -1
  91. package/dist/harness/utils/describe-shape.mjs +0 -1
  92. package/dist/harness/utils/grounding.mjs +0 -1
  93. package/dist/harness/utils/rank-tools-by-keywords.mjs +0 -1
  94. package/dist/harness/workspace.js +7 -7
  95. package/dist/harness/workspace.mjs +7 -8
  96. package/dist/loops/agi/loop.mjs +0 -1
  97. package/dist/loops/agi/skills/reasoning-engine.mjs +0 -1
  98. package/dist/loops/shared/skills/fast-responder.mjs +0 -1
  99. package/dist/services/authentication/entities/index.d.ts +1 -0
  100. package/dist/services/authentication/entities/index.js +3 -1
  101. package/dist/services/authentication/entities/index.mjs +1 -0
  102. package/dist/services/authentication/entities/refresh-token.entity.d.ts +25 -0
  103. package/dist/services/authentication/entities/refresh-token.entity.js +75 -0
  104. package/dist/services/authentication/entities/refresh-token.entity.mjs +51 -0
  105. package/dist/services/authentication/entities/revoked-token.entity.mjs +0 -1
  106. package/dist/services/authentication/helpers/auth-config.d.ts +9 -0
  107. package/dist/{common/decorators/owner-only/index.js → services/authentication/helpers/auth-config.js} +19 -5
  108. package/dist/services/authentication/helpers/auth-config.mjs +12 -0
  109. package/dist/services/authentication/helpers/session-tokens.d.ts +16 -0
  110. package/dist/services/authentication/helpers/session-tokens.js +60 -0
  111. package/dist/services/authentication/helpers/session-tokens.mjs +35 -0
  112. package/dist/services/authentication/helpers/tokens.d.ts +43 -0
  113. package/dist/services/authentication/helpers/tokens.js +113 -0
  114. package/dist/services/authentication/helpers/tokens.mjs +71 -0
  115. package/dist/services/authentication/index.d.ts +3 -0
  116. package/dist/services/authentication/index.js +23 -0
  117. package/dist/services/authentication/index.mjs +11 -0
  118. package/dist/services/authentication/module.d.ts +12 -3
  119. package/dist/services/authentication/module.js +40 -7
  120. package/dist/services/authentication/module.mjs +34 -7
  121. package/dist/services/authentication/repositories/index.d.ts +1 -0
  122. package/dist/services/authentication/repositories/index.js +3 -1
  123. package/dist/services/authentication/repositories/index.mjs +1 -0
  124. package/dist/services/authentication/repositories/refresh-token.repository.d.ts +10 -0
  125. package/dist/services/authentication/repositories/refresh-token.repository.js +60 -0
  126. package/dist/services/authentication/repositories/refresh-token.repository.mjs +36 -0
  127. package/dist/services/authentication/repositories/revoked-token.repository.d.ts +3 -3
  128. package/dist/services/authentication/repositories/revoked-token.repository.js +9 -20
  129. package/dist/services/authentication/repositories/revoked-token.repository.mjs +9 -15
  130. package/dist/services/authentication/use-cases/claim-refresh-token.use-case.d.ts +12 -0
  131. package/dist/services/authentication/use-cases/claim-refresh-token.use-case.js +40 -0
  132. package/dist/services/authentication/use-cases/claim-refresh-token.use-case.mjs +16 -0
  133. package/dist/services/authentication/use-cases/create-refresh-token.use-case.d.ts +11 -0
  134. package/dist/services/authentication/use-cases/create-refresh-token.use-case.js +43 -0
  135. package/dist/services/authentication/use-cases/create-refresh-token.use-case.mjs +19 -0
  136. package/dist/services/authentication/use-cases/find-refresh-token-by-hash.use-case.d.ts +11 -0
  137. package/dist/services/authentication/use-cases/find-refresh-token-by-hash.use-case.js +40 -0
  138. package/dist/services/authentication/use-cases/find-refresh-token-by-hash.use-case.mjs +16 -0
  139. package/dist/services/authentication/use-cases/is-token-revoked.use-case.d.ts +6 -8
  140. package/dist/services/authentication/use-cases/is-token-revoked.use-case.js +6 -19
  141. package/dist/services/authentication/use-cases/is-token-revoked.use-case.mjs +6 -14
  142. package/dist/services/authentication/use-cases/issue-password-reset-token.use-case.d.ts +18 -0
  143. package/dist/services/authentication/use-cases/issue-password-reset-token.use-case.js +49 -0
  144. package/dist/services/authentication/use-cases/issue-password-reset-token.use-case.mjs +25 -0
  145. package/dist/services/authentication/use-cases/issue-session.use-case.d.ts +13 -0
  146. package/dist/services/authentication/use-cases/issue-session.use-case.js +48 -0
  147. package/dist/services/authentication/use-cases/issue-session.use-case.mjs +24 -0
  148. package/dist/services/authentication/use-cases/login.use-case.d.ts +11 -11
  149. package/dist/services/authentication/use-cases/login.use-case.js +18 -53
  150. package/dist/services/authentication/use-cases/login.use-case.mjs +18 -38
  151. package/dist/services/authentication/use-cases/logout.use-case.d.ts +14 -0
  152. package/dist/services/authentication/use-cases/logout.use-case.js +48 -0
  153. package/dist/services/authentication/use-cases/logout.use-case.mjs +24 -0
  154. package/dist/services/authentication/use-cases/refresh.use-case.d.ts +23 -0
  155. package/dist/services/authentication/use-cases/refresh.use-case.js +84 -0
  156. package/dist/services/authentication/use-cases/refresh.use-case.mjs +60 -0
  157. package/dist/services/authentication/use-cases/reset-password.use-case.d.ts +15 -0
  158. package/dist/services/authentication/use-cases/reset-password.use-case.js +61 -0
  159. package/dist/services/authentication/use-cases/reset-password.use-case.mjs +37 -0
  160. package/dist/services/authentication/use-cases/revoke-refresh-token-family.use-case.d.ts +11 -0
  161. package/dist/services/authentication/use-cases/revoke-refresh-token-family.use-case.js +40 -0
  162. package/dist/services/authentication/use-cases/revoke-refresh-token-family.use-case.mjs +16 -0
  163. package/dist/services/authentication/use-cases/revoke-token.use-case.d.ts +4 -6
  164. package/dist/services/authentication/use-cases/revoke-token.use-case.js +12 -25
  165. package/dist/services/authentication/use-cases/revoke-token.use-case.mjs +11 -19
  166. package/dist/services/authentication/use-cases/revoke-user-refresh-tokens.use-case.d.ts +13 -0
  167. package/dist/services/authentication/use-cases/revoke-user-refresh-tokens.use-case.js +40 -0
  168. package/dist/services/authentication/use-cases/revoke-user-refresh-tokens.use-case.mjs +16 -0
  169. package/dist/services/automations/entities/automation-run.entity.mjs +0 -1
  170. package/dist/services/automations/entities/automation.entity.d.ts +1 -0
  171. package/dist/services/automations/entities/automation.entity.js +2 -1
  172. package/dist/services/automations/entities/automation.entity.mjs +2 -2
  173. package/dist/services/automations/entities/recurrence.mjs +0 -1
  174. package/dist/services/automations/entities/trigger.mjs +0 -1
  175. package/dist/services/automations/module.d.ts +0 -1
  176. package/dist/services/automations/module.js +20 -22
  177. package/dist/services/automations/module.mjs +20 -23
  178. package/dist/services/automations/repositories/automation-run.repository.d.ts +10 -10
  179. package/dist/services/automations/repositories/automation-run.repository.js +26 -38
  180. package/dist/services/automations/repositories/automation-run.repository.mjs +26 -33
  181. package/dist/services/automations/repositories/automation.repository.d.ts +14 -13
  182. package/dist/services/automations/repositories/automation.repository.js +52 -54
  183. package/dist/services/automations/repositories/automation.repository.mjs +52 -49
  184. package/dist/services/automations/runner/automation-runner.d.ts +3 -0
  185. package/dist/services/automations/runner/automation-runner.js +8 -9
  186. package/dist/services/automations/runner/automation-runner.mjs +8 -10
  187. package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.d.ts +4 -6
  188. package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.js +8 -21
  189. package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.mjs +8 -16
  190. package/dist/services/automations/use-cases/claim-due-automations.use-case.d.ts +9 -11
  191. package/dist/services/automations/use-cases/claim-due-automations.use-case.js +11 -26
  192. package/dist/services/automations/use-cases/claim-due-automations.use-case.mjs +11 -21
  193. package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.d.ts +9 -11
  194. package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.js +13 -28
  195. package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.mjs +13 -23
  196. package/dist/services/automations/use-cases/create-automation.use-case.d.ts +4 -6
  197. package/dist/services/automations/use-cases/create-automation.use-case.js +7 -22
  198. package/dist/services/automations/use-cases/create-automation.use-case.mjs +6 -16
  199. package/dist/services/automations/use-cases/delete-automation.use-case.d.ts +6 -6
  200. package/dist/services/automations/use-cases/delete-automation.use-case.js +10 -27
  201. package/dist/services/automations/use-cases/delete-automation.use-case.mjs +9 -21
  202. package/dist/services/automations/use-cases/finish-automation-run.use-case.d.ts +5 -7
  203. package/dist/services/automations/use-cases/finish-automation-run.use-case.js +9 -23
  204. package/dist/services/automations/use-cases/finish-automation-run.use-case.mjs +9 -18
  205. package/dist/services/automations/use-cases/get-automation-by-id.use-case.d.ts +4 -6
  206. package/dist/services/automations/use-cases/get-automation-by-id.use-case.js +8 -21
  207. package/dist/services/automations/use-cases/get-automation-by-id.use-case.mjs +7 -15
  208. package/dist/services/automations/use-cases/issue-automation-event-token.use-case.d.ts +7 -9
  209. package/dist/services/automations/use-cases/issue-automation-event-token.use-case.js +8 -22
  210. package/dist/services/automations/use-cases/issue-automation-event-token.use-case.mjs +7 -16
  211. package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.d.ts +6 -6
  212. package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.js +8 -20
  213. package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.mjs +8 -15
  214. package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.d.ts +6 -6
  215. package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.js +7 -19
  216. package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.mjs +7 -14
  217. package/dist/services/automations/use-cases/list-automations-by-user.use-case.d.ts +6 -6
  218. package/dist/services/automations/use-cases/list-automations-by-user.use-case.js +7 -19
  219. package/dist/services/automations/use-cases/list-automations-by-user.use-case.mjs +7 -14
  220. package/dist/services/automations/use-cases/preview-automation-runs.use-case.d.ts +4 -6
  221. package/dist/services/automations/use-cases/preview-automation-runs.use-case.js +3 -15
  222. package/dist/services/automations/use-cases/preview-automation-runs.use-case.mjs +3 -10
  223. package/dist/services/automations/use-cases/receive-automation-event.use-case.d.ts +8 -10
  224. package/dist/services/automations/use-cases/receive-automation-event.use-case.js +15 -29
  225. package/dist/services/automations/use-cases/receive-automation-event.use-case.mjs +15 -24
  226. package/dist/services/automations/use-cases/renew-automation-lease.use-case.d.ts +6 -8
  227. package/dist/services/automations/use-cases/renew-automation-lease.use-case.js +6 -19
  228. package/dist/services/automations/use-cases/renew-automation-lease.use-case.mjs +6 -14
  229. package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.d.ts +6 -8
  230. package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.js +10 -23
  231. package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.mjs +10 -18
  232. package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.d.ts +4 -6
  233. package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.js +11 -25
  234. package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.mjs +10 -19
  235. package/dist/services/automations/use-cases/start-automation-run.use-case.d.ts +8 -10
  236. package/dist/services/automations/use-cases/start-automation-run.use-case.js +12 -25
  237. package/dist/services/automations/use-cases/start-automation-run.use-case.mjs +12 -20
  238. package/dist/services/automations/use-cases/sync-automation-run.use-case.d.ts +5 -7
  239. package/dist/services/automations/use-cases/sync-automation-run.use-case.js +13 -27
  240. package/dist/services/automations/use-cases/sync-automation-run.use-case.mjs +13 -22
  241. package/dist/services/automations/use-cases/sync-automation-runs.use-case.d.ts +8 -10
  242. package/dist/services/automations/use-cases/sync-automation-runs.use-case.js +8 -22
  243. package/dist/services/automations/use-cases/sync-automation-runs.use-case.mjs +8 -17
  244. package/dist/services/automations/use-cases/update-automation.use-case.d.ts +4 -6
  245. package/dist/services/automations/use-cases/update-automation.use-case.js +13 -26
  246. package/dist/services/automations/use-cases/update-automation.use-case.mjs +12 -20
  247. package/dist/services/automations/utils/automation-event-error.mjs +0 -1
  248. package/dist/services/automations/utils/automation-fields.mjs +0 -1
  249. package/dist/services/automations/utils/event-message.mjs +0 -1
  250. package/dist/services/automations/utils/event-token.d.ts +1 -2
  251. package/dist/services/automations/utils/event-token.js +9 -35
  252. package/dist/services/automations/utils/event-token.mjs +9 -25
  253. package/dist/services/automations/utils/next-run.mjs +0 -1
  254. package/dist/services/automations/utils/open-run.d.ts +2 -0
  255. package/dist/services/automations/utils/open-run.js +2 -2
  256. package/dist/services/automations/utils/open-run.mjs +2 -3
  257. package/dist/services/automations/utils/previous-run.js +4 -3
  258. package/dist/services/automations/utils/previous-run.mjs +4 -4
  259. package/dist/services/automations/utils/runner-scope.d.ts +3 -0
  260. package/dist/{common/base/utils/flatten-object.js → services/automations/utils/runner-scope.js} +10 -23
  261. package/dist/services/automations/utils/runner-scope.mjs +7 -0
  262. package/dist/services/automations/utils/settings.mjs +0 -1
  263. package/dist/services/chats/entities/chat-message.entity.mjs +0 -1
  264. package/dist/services/chats/entities/chat-settings.entity.mjs +0 -1
  265. package/dist/services/chats/entities/chat.entity.d.ts +1 -0
  266. package/dist/services/chats/entities/chat.entity.js +3 -2
  267. package/dist/services/chats/entities/chat.entity.mjs +3 -3
  268. package/dist/services/chats/module.d.ts +0 -1
  269. package/dist/services/chats/module.js +5 -7
  270. package/dist/services/chats/module.mjs +5 -8
  271. package/dist/services/chats/repositories/chat.repository.d.ts +7 -6
  272. package/dist/services/chats/repositories/chat.repository.js +19 -29
  273. package/dist/services/chats/repositories/chat.repository.mjs +19 -24
  274. package/dist/services/chats/use-cases/create-chat.use-case.d.ts +4 -6
  275. package/dist/services/chats/use-cases/create-chat.use-case.js +7 -22
  276. package/dist/services/chats/use-cases/create-chat.use-case.mjs +6 -16
  277. package/dist/services/chats/use-cases/delete-chat.use-case.d.ts +6 -6
  278. package/dist/services/chats/use-cases/delete-chat.use-case.js +10 -26
  279. package/dist/services/chats/use-cases/delete-chat.use-case.mjs +9 -20
  280. package/dist/services/chats/use-cases/get-chat-by-id.use-case.d.ts +4 -6
  281. package/dist/services/chats/use-cases/get-chat-by-id.use-case.js +8 -21
  282. package/dist/services/chats/use-cases/get-chat-by-id.use-case.mjs +8 -16
  283. package/dist/services/chats/use-cases/interrupt-execution.use-case.d.ts +4 -6
  284. package/dist/services/chats/use-cases/interrupt-execution.use-case.js +8 -24
  285. package/dist/services/chats/use-cases/interrupt-execution.use-case.mjs +7 -18
  286. package/dist/services/chats/use-cases/list-chats-by-props.use-case.d.ts +6 -6
  287. package/dist/services/chats/use-cases/list-chats-by-props.use-case.js +7 -20
  288. package/dist/services/chats/use-cases/list-chats-by-props.use-case.mjs +7 -15
  289. package/dist/services/chats/use-cases/list-chats-by-user.use-case.d.ts +6 -6
  290. package/dist/services/chats/use-cases/list-chats-by-user.use-case.js +7 -19
  291. package/dist/services/chats/use-cases/list-chats-by-user.use-case.mjs +7 -14
  292. package/dist/services/chats/use-cases/update-chat.use-case.d.ts +5 -6
  293. package/dist/services/chats/use-cases/update-chat.use-case.js +10 -30
  294. package/dist/services/chats/use-cases/update-chat.use-case.mjs +9 -24
  295. package/dist/services/chats/utils/deprecated-activity.mjs +0 -1
  296. package/dist/services/llmcalls/entities/llmcall.entity.mjs +0 -1
  297. package/dist/services/llmcalls/module.d.ts +0 -1
  298. package/dist/services/llmcalls/module.js +4 -6
  299. package/dist/services/llmcalls/module.mjs +4 -7
  300. package/dist/services/llmcalls/repositories/llmcall.repository.d.ts +7 -6
  301. package/dist/services/llmcalls/repositories/llmcall.repository.js +19 -29
  302. package/dist/services/llmcalls/repositories/llmcall.repository.mjs +19 -24
  303. package/dist/services/llmcalls/use-cases/create-llmcall.use-case.d.ts +4 -6
  304. package/dist/services/llmcalls/use-cases/create-llmcall.use-case.js +7 -22
  305. package/dist/services/llmcalls/use-cases/create-llmcall.use-case.mjs +6 -16
  306. package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.d.ts +6 -6
  307. package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.js +10 -26
  308. package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.mjs +9 -20
  309. package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.d.ts +4 -6
  310. package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.js +8 -21
  311. package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.mjs +7 -15
  312. package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.d.ts +4 -6
  313. package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.js +8 -21
  314. package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.mjs +7 -15
  315. package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.d.ts +4 -6
  316. package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.js +6 -19
  317. package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.mjs +6 -14
  318. package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.d.ts +4 -6
  319. package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.js +9 -21
  320. package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.mjs +8 -15
  321. package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.d.ts +6 -6
  322. package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.js +7 -20
  323. package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.mjs +7 -15
  324. package/dist/services/llmcalls/use-cases/update-llmcall.use-case.d.ts +4 -6
  325. package/dist/services/llmcalls/use-cases/update-llmcall.use-case.js +9 -25
  326. package/dist/services/llmcalls/use-cases/update-llmcall.use-case.mjs +8 -19
  327. package/dist/services/llmcalls/utils/usage-periods.mjs +0 -1
  328. package/dist/services/llmcalls/utils/usage-totals.mjs +0 -1
  329. package/dist/services/mcp-servers/entities/mcp-manifest.mjs +0 -1
  330. package/dist/services/mcp-servers/entities/mcpserver.entity.mjs +0 -1
  331. package/dist/services/mcp-servers/module.d.ts +0 -1
  332. package/dist/services/mcp-servers/module.js +8 -10
  333. package/dist/services/mcp-servers/module.mjs +8 -11
  334. package/dist/services/mcp-servers/repositories/mcpserver.repository.d.ts +8 -7
  335. package/dist/services/mcp-servers/repositories/mcpserver.repository.js +21 -31
  336. package/dist/services/mcp-servers/repositories/mcpserver.repository.mjs +21 -26
  337. package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.d.ts +5 -7
  338. package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.js +7 -24
  339. package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.mjs +6 -18
  340. package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.d.ts +4 -6
  341. package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.js +11 -26
  342. package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.mjs +10 -20
  343. package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.d.ts +6 -6
  344. package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.js +10 -26
  345. package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.mjs +9 -20
  346. package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.d.ts +4 -6
  347. package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.js +8 -21
  348. package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.mjs +7 -15
  349. package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.d.ts +6 -6
  350. package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.js +7 -20
  351. package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.mjs +6 -14
  352. package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.d.ts +6 -6
  353. package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.js +5 -19
  354. package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.mjs +5 -14
  355. package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.d.ts +5 -7
  356. package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.js +12 -31
  357. package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.mjs +11 -25
  358. package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.d.ts +4 -6
  359. package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.js +13 -27
  360. package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.mjs +12 -21
  361. package/dist/services/tasks/entities/agent-action.entity.mjs +0 -1
  362. package/dist/services/tasks/entities/agent-task.entity.mjs +0 -1
  363. package/dist/services/tasks/module.d.ts +0 -1
  364. package/dist/services/tasks/module.js +7 -9
  365. package/dist/services/tasks/module.mjs +7 -10
  366. package/dist/services/tasks/repositories/agent-action.repository.d.ts +4 -4
  367. package/dist/services/tasks/repositories/agent-action.repository.js +12 -26
  368. package/dist/services/tasks/repositories/agent-action.repository.mjs +12 -21
  369. package/dist/services/tasks/repositories/agent-task.repository.d.ts +5 -5
  370. package/dist/services/tasks/repositories/agent-task.repository.js +14 -28
  371. package/dist/services/tasks/repositories/agent-task.repository.mjs +14 -23
  372. package/dist/services/tasks/use-cases/create-agent-action.use-case.d.ts +4 -6
  373. package/dist/services/tasks/use-cases/create-agent-action.use-case.js +7 -22
  374. package/dist/services/tasks/use-cases/create-agent-action.use-case.mjs +6 -16
  375. package/dist/services/tasks/use-cases/create-agent-task.use-case.d.ts +4 -6
  376. package/dist/services/tasks/use-cases/create-agent-task.use-case.js +7 -22
  377. package/dist/services/tasks/use-cases/create-agent-task.use-case.mjs +6 -16
  378. package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.d.ts +4 -6
  379. package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.js +8 -21
  380. package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.mjs +7 -15
  381. package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.d.ts +6 -6
  382. package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.js +8 -20
  383. package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.mjs +8 -15
  384. package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.d.ts +6 -6
  385. package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.js +8 -20
  386. package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.mjs +8 -15
  387. package/dist/services/tasks/use-cases/update-agent-action.use-case.d.ts +4 -6
  388. package/dist/services/tasks/use-cases/update-agent-action.use-case.js +8 -24
  389. package/dist/services/tasks/use-cases/update-agent-action.use-case.mjs +7 -18
  390. package/dist/services/tasks/use-cases/update-agent-task.use-case.d.ts +4 -6
  391. package/dist/services/tasks/use-cases/update-agent-task.use-case.js +8 -24
  392. package/dist/services/tasks/use-cases/update-agent-task.use-case.mjs +7 -18
  393. package/dist/services/traces/entities/agent-trace-entry.entity.mjs +0 -1
  394. package/dist/services/traces/module.d.ts +0 -1
  395. package/dist/services/traces/module.js +2 -4
  396. package/dist/services/traces/module.mjs +2 -5
  397. package/dist/services/traces/repositories/agent-trace.repository.d.ts +3 -3
  398. package/dist/services/traces/repositories/agent-trace.repository.js +8 -19
  399. package/dist/services/traces/repositories/agent-trace.repository.mjs +8 -14
  400. package/dist/services/traces/use-cases/create-agent-traces.use-case.d.ts +6 -8
  401. package/dist/services/traces/use-cases/create-agent-traces.use-case.js +8 -26
  402. package/dist/services/traces/use-cases/create-agent-traces.use-case.mjs +7 -20
  403. package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.d.ts +6 -6
  404. package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.js +8 -20
  405. package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.mjs +8 -15
  406. package/dist/services/users/entities/user-acquisition.js +4 -17
  407. package/dist/services/users/entities/user-acquisition.mjs +4 -12
  408. package/dist/services/users/entities/user-country.js +2 -2
  409. package/dist/services/users/entities/user-country.mjs +2 -3
  410. package/dist/services/users/entities/user-currency.js +2 -2
  411. package/dist/services/users/entities/user-currency.mjs +2 -3
  412. package/dist/services/users/entities/user-default-model.js +2 -2
  413. package/dist/services/users/entities/user-default-model.mjs +2 -3
  414. package/dist/services/users/entities/user-email.value-object.mjs +0 -1
  415. package/dist/services/users/entities/user-language.js +2 -2
  416. package/dist/services/users/entities/user-language.mjs +2 -3
  417. package/dist/services/users/entities/user-marketing.js +4 -17
  418. package/dist/services/users/entities/user-marketing.mjs +4 -12
  419. package/dist/services/users/entities/user-notification-preferences.mjs +0 -1
  420. package/dist/services/users/entities/user-password.value-object.mjs +0 -1
  421. package/dist/services/users/entities/user-permissions.mjs +0 -1
  422. package/dist/services/users/entities/user-preferences.mjs +0 -1
  423. package/dist/services/users/entities/user-report-preferences.mjs +0 -1
  424. package/dist/services/users/entities/user-report-schedule.mjs +0 -1
  425. package/dist/services/users/entities/user-timezone.js +2 -2
  426. package/dist/services/users/entities/user-timezone.mjs +2 -3
  427. package/dist/services/users/entities/user.entity.d.ts +1 -0
  428. package/dist/services/users/entities/user.entity.js +9 -25
  429. package/dist/services/users/entities/user.entity.mjs +9 -20
  430. package/dist/services/users/module.d.ts +2 -1
  431. package/dist/services/users/module.js +12 -7
  432. package/dist/services/users/module.mjs +11 -8
  433. package/dist/services/users/repositories/user.repository.d.ts +10 -7
  434. package/dist/services/users/repositories/user.repository.js +34 -29
  435. package/dist/services/users/repositories/user.repository.mjs +34 -24
  436. package/dist/services/users/use-cases/change-password.use-case.d.ts +15 -0
  437. package/dist/services/users/use-cases/change-password.use-case.js +52 -0
  438. package/dist/services/users/use-cases/change-password.use-case.mjs +28 -0
  439. package/dist/services/users/use-cases/create-user.use-case.d.ts +4 -7
  440. package/dist/services/users/use-cases/create-user.use-case.js +8 -22
  441. package/dist/services/users/use-cases/create-user.use-case.mjs +7 -16
  442. package/dist/services/users/use-cases/delete-user.use-case.d.ts +6 -6
  443. package/dist/services/users/use-cases/delete-user.use-case.js +10 -26
  444. package/dist/services/users/use-cases/delete-user.use-case.mjs +9 -20
  445. package/dist/services/users/use-cases/get-user-by-id.use-case.d.ts +4 -6
  446. package/dist/services/users/use-cases/get-user-by-id.use-case.js +9 -21
  447. package/dist/services/users/use-cases/get-user-by-id.use-case.mjs +8 -15
  448. package/dist/services/users/use-cases/list-users-by-props.use-case.d.ts +6 -6
  449. package/dist/services/users/use-cases/list-users-by-props.use-case.js +7 -20
  450. package/dist/services/users/use-cases/list-users-by-props.use-case.mjs +7 -15
  451. package/dist/services/users/use-cases/update-user.use-case.d.ts +4 -6
  452. package/dist/services/users/use-cases/update-user.use-case.js +11 -26
  453. package/dist/services/users/use-cases/update-user.use-case.mjs +10 -20
  454. package/dist/services/users/utils/default-model.mjs +0 -1
  455. package/dist/services/workspaces/entities/workspace-item.entity.mjs +0 -1
  456. package/dist/services/workspaces/module.d.ts +0 -1
  457. package/dist/services/workspaces/module.js +5 -7
  458. package/dist/services/workspaces/module.mjs +5 -8
  459. package/dist/services/workspaces/repositories/workspace-item.repository.d.ts +8 -8
  460. package/dist/services/workspaces/repositories/workspace-item.repository.js +20 -32
  461. package/dist/services/workspaces/repositories/workspace-item.repository.mjs +20 -27
  462. package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.d.ts +6 -8
  463. package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.js +11 -22
  464. package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.mjs +10 -16
  465. package/dist/services/workspaces/use-cases/get-workspace-item.use-case.d.ts +4 -6
  466. package/dist/services/workspaces/use-cases/get-workspace-item.use-case.js +8 -21
  467. package/dist/services/workspaces/use-cases/get-workspace-item.use-case.mjs +7 -15
  468. package/dist/services/workspaces/use-cases/list-workspace-items.use-case.d.ts +6 -6
  469. package/dist/services/workspaces/use-cases/list-workspace-items.use-case.js +7 -19
  470. package/dist/services/workspaces/use-cases/list-workspace-items.use-case.mjs +7 -14
  471. package/dist/services/workspaces/use-cases/save-workspace-item.use-case.d.ts +4 -6
  472. package/dist/services/workspaces/use-cases/save-workspace-item.use-case.js +14 -28
  473. package/dist/services/workspaces/use-cases/save-workspace-item.use-case.mjs +13 -22
  474. package/dist/services/workspaces/use-cases/search-workspace-items.use-case.d.ts +6 -6
  475. package/dist/services/workspaces/use-cases/search-workspace-items.use-case.js +7 -19
  476. package/dist/services/workspaces/use-cases/search-workspace-items.use-case.mjs +7 -14
  477. package/dist/skills/call-modes.mjs +0 -1
  478. package/dist/skills/runtime-context.mjs +0 -1
  479. package/dist/skills/shared/shared-rules.mjs +0 -1
  480. package/dist/skills/skill.js +1 -2
  481. package/dist/skills/skill.mjs +1 -3
  482. package/dist/tools/core/call-ai/call-ai.skill.mjs +0 -1
  483. package/dist/tools/core/call-ai/call-ai.tool.mjs +0 -1
  484. package/dist/tools/core/slack/send-slack-message.tool.mjs +0 -1
  485. package/dist/tools/core/web-search/web-search.tool.mjs +0 -1
  486. package/dist/tools/tool.mjs +0 -1
  487. package/docs/README.md +2 -1
  488. package/docs/authentication.md +95 -16
  489. package/docs/authorization.md +77 -0
  490. package/docs/automations.md +10 -9
  491. package/docs/chats.md +1 -1
  492. package/docs/configuration.md +1 -1
  493. package/docs/integration-guide.md +9 -11
  494. package/docs/llms.txt +1 -0
  495. package/docs/mcp-servers.md +1 -1
  496. package/docs/usage.md +5 -5
  497. package/docs/users.md +7 -5
  498. package/examples/authentication/login.ts +1 -1
  499. package/examples/automations/create-automation.ts +1 -1
  500. package/examples/automations/create-event-automation.ts +2 -2
  501. package/examples/automations/list-automation-runs.ts +4 -2
  502. package/examples/automations/list-automations.ts +1 -1
  503. package/examples/automations/preview-automation-runs.ts +1 -1
  504. package/examples/automations/receive-automation-event.ts +1 -1
  505. package/examples/automations/revoke-automation-event-token.ts +2 -2
  506. package/examples/automations/run-automation-now.ts +3 -1
  507. package/examples/automations/update-automation.ts +2 -2
  508. package/examples/chats/delete-chat.ts +1 -1
  509. package/examples/chats/get-chat-by-id.ts +2 -2
  510. package/examples/chats/list-autonomous-chats.ts +1 -1
  511. package/examples/chats/list-chats.ts +1 -1
  512. package/examples/mcps/decide-mcp.ts +3 -3
  513. package/examples/mcps/list-all-mcps.ts +1 -1
  514. package/examples/mcps/verify-mcp.ts +1 -1
  515. package/examples/usage/get-chat-usage.ts +2 -2
  516. package/examples/usage/get-message-usage.ts +2 -2
  517. package/examples/usage/get-usage-stats-by-range.ts +1 -1
  518. package/examples/usage/get-usage-stats.ts +3 -3
  519. package/examples/users/create-user.ts +2 -1
  520. package/examples/users/list-users.ts +1 -0
  521. package/examples/users/set-default-model.ts +1 -1
  522. package/package.json +2 -4
  523. package/dist/chunk-CF3WOMB3.mjs +0 -16
  524. package/dist/common/base/utils/delete-empty-fields.d.ts +0 -1
  525. package/dist/common/base/utils/delete-empty-fields.js +0 -66
  526. package/dist/common/base/utils/delete-empty-fields.mjs +0 -43
  527. package/dist/common/base/utils/flatten-object.d.ts +0 -1
  528. package/dist/common/base/utils/flatten-object.mjs +0 -22
  529. package/dist/common/decorators/admin-only/admin-only.d.ts +0 -2
  530. package/dist/common/decorators/admin-only/admin-only.js +0 -52
  531. package/dist/common/decorators/admin-only/admin-only.mjs +0 -28
  532. package/dist/common/decorators/admin-only/index.d.ts +0 -1
  533. package/dist/common/decorators/admin-only/index.mjs +0 -1
  534. package/dist/common/decorators/index.d.ts +0 -3
  535. package/dist/common/decorators/index.js +0 -26
  536. package/dist/common/decorators/index.mjs +0 -3
  537. package/dist/common/decorators/mask-in-logs/index.d.ts +0 -1
  538. package/dist/common/decorators/mask-in-logs/index.js +0 -22
  539. package/dist/common/decorators/mask-in-logs/index.mjs +0 -1
  540. package/dist/common/decorators/mask-in-logs/mask-in-logs.d.ts +0 -2
  541. package/dist/common/decorators/mask-in-logs/mask-in-logs.js +0 -53
  542. package/dist/common/decorators/mask-in-logs/mask-in-logs.mjs +0 -29
  543. package/dist/common/decorators/owner-only/index.d.ts +0 -1
  544. package/dist/common/decorators/owner-only/index.mjs +0 -1
  545. package/dist/common/decorators/owner-only/owner-only.d.ts +0 -2
  546. package/dist/common/decorators/owner-only/owner-only.js +0 -52
  547. package/dist/common/decorators/owner-only/owner-only.mjs +0 -28
package/CHANGELOG.md CHANGED
@@ -2,6 +2,66 @@
2
2
 
3
3
  All notable changes to `openloops` are written here, newest first. The format follows [Keep a Changelog](https://keepachangelog.com) and the versions follow [semantic versioning](https://semver.org), where a minor version can still break the API while the package is in beta. Changes before 0.4.0 are not recorded here, see the commits and the tags.
4
4
 
5
+ ## 0.7.0
6
+
7
+ This version breaks the API of the entities, of the repository, of the results of the use cases and of the authentication, and removes `tsyringe`. The tokens that 0.6 issued (logins and event automations) stop working: issue new ones. Read [authentication](docs/authentication.md). The parameters of the use cases do not change, except for `updateChat`, which accepts `unset`.
8
+
9
+ ### Added
10
+
11
+ - **Sessions with refresh.** `refreshSession`, `logout` and `revokeUserSessions` in `openloops/authentication`, and the collection `refresh_tokens` (the index is created by `ensureIndexes`). The refresh token rotates in each use, a token that is used again after 10 seconds closes the whole session, and a session ends at 90 days at most (7 for an admin).
12
+ - **Password reset.** `issuePasswordResetToken` and `resetPassword` in `openloops/authentication`, and `changePassword` in `openloops/users`, which closes the other sessions. The package does not send the email, and does not limit the attempts: your backend does both.
13
+ - `verifySessionToken`, `signToken`, `verifyToken`, `TokenError` and the audiences, to read the tokens in your backend.
14
+ - `MongoRepository.patchOne`, `archiveByPatch` and `claimOne`. `patchOne` takes `set` and `unset` (paths with dots), stamps who and when, drops the paths of control of a user scope, never writes `_id`, `__v`, `createdAt` nor `createdBy`, and accepts `expectedVersion` to detect conflicts. `claimOne` gives back the document as it was before the change.
15
+ - `softDelete` accepts `unset`.
16
+ - `toPatch` and `entityPatch` in `@common/base/utils`: the first turns an object into `set` and `unset` (a `null` or a blank text removes the field), the second adds the `clearedFields` of an entity.
17
+ - `clearedFields` in `Chat`, `Automation` and `User`, for the fields that an entity removes from the stored document.
18
+ - `updateChat` accepts `unset`, with the paths to remove.
19
+
20
+ ### Changed
21
+
22
+ - **One convention for every token.** They are signed with `HS256`, carry `iss: openloops`, an `aud` (`session`, `password-reset` or `automation-event`) and `sub`, and are refused if any of them is wrong. The tokens of event automations follow it too.
23
+ - **`login` gives `{ accessToken, refreshToken, expiresIn, refreshExpiresAt, user }`**, not `{ token, user }`. The access token lasts 1 hour for everyone. An unknown user and a wrong password fail with the same 401 (`{{invalid_credentials}}`), before it was 404 and 401.
24
+ - `revokeToken` answers `true` the first time and `false` if the `jti` was already revoked, and not the record.
25
+ - `updateUser` refuses a `password` (400): use `changePassword`.
26
+ - **The use cases and the functions of the services return the result itself, no longer `{ data }`.** `const { data } = await getChatById(...)` becomes `const chat = await getChatById(...)`. The lists return `{ items, hasMore }` (`hasMore` is always there), the functions that delete return the record, or `{ deletedCount }` on a hard delete, and `execute` does not return an `HttpError` anymore: it throws. `BaseUseCaseOutput` is gone. `Agent.run` and the tools are not affected, they still use `{ data, error }` and `{ data }`.
27
+ - A getter that finds nothing answers `null`, also `getChatById`, which answered `{}`.
28
+ - `BaseEntity` is the one with `toJSON` only. Its static `toDate` and `toNumber` are public, an invalid id, date or number is a 400 `HttpError` and not a plain `Error`, and `toText` answers `undefined` for a blank text (it answered `''`).
29
+ - The repositories save with `patchOne`, so a text that is blank inside a document is removed and not stored as `''`, and the inserts and the patches ignore the `undefined` values, also inside arrays.
30
+ - The use cases take their repositories as default parameters of the constructor (`new XUseCase(repository)` still works).
31
+
32
+ ### Removed
33
+
34
+ - `tsyringe`, `reflect-metadata`, the `MaskInLogs` decorator and `BaseUseCaseOutput`.
35
+ - `toDocument`, `toFlatDocument`, `toUnset`, `unset`, `setId`, `setDefaults`, `stringify` and `clean` of `BaseEntity`, and the `Document` type.
36
+ - `MongoRepository.updateOne`, replaced by `patchOne`.
37
+
38
+ ## 0.6.0
39
+
40
+ This version breaks the API of the use cases. The functions that read or write the records of a user need the `currentUser` or a `scope` (login, the tokens, the preview of runs, the events and the functions of the runner do not), creating a record takes its owner from the scope and not from the payload, and the ownership of the records is checked by the repository. Follow the [migration steps](docs/authorization.md#migrating-from-05) when you update.
41
+
42
+ ### Added
43
+
44
+ - `Scope`, exported from `openloops/base`. Every repository receives one and filters by owner in the same query that reads or writes, so a record that is not the user's is answered as not found (a 404 `HttpError`, `{}` in `getChatById`, `null` in the other getters). `Scope.canView`, `canEdit` and `canManage` take the `currentUser`, `Scope.asAdmin` fails with 403 when the user is not an admin, and `Scope.system(reason)` is for workers and flows without a user.
45
+ - Every use case accepts `scope`, to override the one it builds from `currentUser`.
46
+ - The repository removes the fields of control (`ownerId`, `sharedWith`, `createdAt`, `createdBy`, `updatedAt`, `updatedBy`, `deletedAt`, `deletedBy`, `archivedAt`, `archivedBy`, `__v`, and `role`, `marketing.drawNumber` and `acquisition.referrerCode` in the users) from the payload of a user and fills them in itself. `createOne` returns the stored document, and there are `softDelete` and `createMany` with the same behavior.
47
+ - `docs/authorization.md`.
48
+
49
+ ### Changed
50
+
51
+ - **Creating records.** `createChat`, `createMcpServer`, `createAutomation`, `createUser`, `createLLMCall`, `createAgentTask`, `createAgentAction`, `createAgentTraces` and `saveWorkspaceItem` set the owner and the author from the scope. A user scope ignores the `ownerId` and the other fields of control of the payload, and a record cannot be created without a `currentUser` or a `scope` (401). To create a record for another user, or without a user, pass `Scope.asAdmin(currentUser)` or `Scope.system(reason)`. See [creating records](docs/authorization.md#creating-records).
52
+ - `getAutomationById`, `listAutomationRunsByAutomation`, `startAutomationRun` and `runner.runNow` need the `currentUser` and only reach the automations of that user. `runner.runNow` also accepts `scope`.
53
+ - A call without `currentUser` and without `scope` fails with 401.
54
+ - `issueAutomationEventToken`, `revokeAutomationEventToken` and `rotateAutomationEventTokens` are for the owner, and an admin needs `Scope.asAdmin`. They answer 404, not 403, to anyone else.
55
+ - The hard delete is for `Scope.asAdmin` or `Scope.system`, and a user that asks for it gets 403.
56
+ - Updating or deleting a record that does not exist or is not the user's answers a 404 `HttpError` and not a generic error.
57
+ - `sharedWith` is a list of `{ userId, permission }`, where `permission` is `read`, `write` or `manage`, and not a list of ids. Nothing reads it yet.
58
+ - `createUser` creates the account with the scope you pass, and keeps `role`, the draw number and the referrer code only with a trusted scope.
59
+
60
+ ### Removed
61
+
62
+ - The `sanitize` parameter of `createUser`.
63
+ - `setOwner`, `setCreatedBy`, `setUpdatedBy`, `setDeletedBy` and `setArchivedBy` of `BaseEntity`, and the `AdminOnly` and `OwnerOnly` decorators. The repository does that work.
64
+
5
65
  ## 0.5.0
6
66
 
7
67
  This version breaks the shape of the automations. Follow the [migration steps](docs/automations.md#migrating-to-050) when you update.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # openloops
2
2
 
3
- **Build production-grade enterprise agents in minutes, not days, weeks, or months.**
3
+ **Build production-grade enterprise agents in minutes, not days, weeks, or months.** · [openloops.xyz](https://openloops.xyz)
4
4
 
5
5
  `openloops` is an open source **harness** for AI agents. An agent is three things: a **model** that thinks (the engine), a **harness** that gives it hands, memory and rules (the chassis), and a **loop** that decides what it is for (the body). `openloops` is the harness, and it ships the loop. Change the model, or the loop, and the rest stays the same.
6
6
 
@@ -281,13 +281,14 @@ Every pattern above, and a lot more, lives as a runnable example in [`examples/`
281
281
  | `openloops/users` | User management |
282
282
  | `openloops/authentication` | Login and token issuing |
283
283
  | `openloops/llmcalls` | LLM usage and cost tracking |
284
- | `openloops/base` | `CurrentUser`, `CurrentSession` |
284
+ | `openloops/base` | `CurrentUser`, `CurrentSession`, `Scope` |
285
285
  | `openloops/common` | `Logger` and shared utilities |
286
286
  | `openloops/clients` | `LLMClient` and the HTTP clients used by built-in tools (e.g. Serper) |
287
287
 
288
288
  ## Learn more
289
289
 
290
290
  - [Integration guide](docs/integration-guide.md)
291
+ - [Authorization](docs/authorization.md)
291
292
  - [Documentation index](docs/README.md)
292
293
  - [The `Agent`](docs/agent.md)
293
294
  - [Building an `AgentLoop`](docs/loops.md)
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  import { Langfuse } from "langfuse";
3
2
  import { secretManager } from "../../common/utils/secret-manager.js";
4
3
  import { Logger } from "../../common/logger/index.js";
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  const USER_MESSAGES = {
3
2
  LLM_RATE_LIMITED: "The model is receiving too many requests right now. Please try again in a few seconds.",
4
3
  LLM_QUOTA_EXCEEDED: "The usage quota of the model provider has been exhausted. Please check the plan and billing of the provider.",
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  const SELECTABLE_THINKING_EFFORTS = ["low", "medium", "high"];
3
2
  const isSelectableThinkingEffort = (value) => SELECTABLE_THINKING_EFFORTS.includes(value);
4
3
  export {
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  import { secretManager } from "../../common/utils/secret-manager.js";
3
2
  import { logger } from "../../common/logger/index.js";
4
3
  const CLIENT_FALLBACK_MODEL = { provider: "anthropic", model: "claude-haiku-5-5" };
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  const ZERO_USAGE = {
3
2
  input: 0,
4
3
  output: 0,
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  const NO_TEMPERATURE = [
3
2
  { provider: "amazon-bedrock", model: /claude/, withThinking: true }
4
3
  ];
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  import { Logger } from "../../common/logger/index.js";
3
2
  import { secretManager } from "../../common/utils/secret-manager.js";
4
3
  class SerperClient {
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  import { secretManager } from "../../common/utils/secret-manager.js";
3
2
  class SlackClient {
4
3
  async sendMessage({ channel, text }) {
@@ -6,7 +6,7 @@ export declare abstract class BaseApp {
6
6
  secretManager: import("../utils/secret-manager.js").SecretManager;
7
7
  reportError: (error: Error | HttpError | string, details?: object) => Promise<void>;
8
8
  onCatch(error: Error): Promise<void>;
9
- throwHttpError(error: HttpErrorProps): void;
10
- throwError401(currentSession?: CurrentSessionProps): void;
11
- throwError403(currentSession?: CurrentSessionProps): void;
9
+ throwHttpError(error: HttpErrorProps): never;
10
+ throwError401(currentSession?: CurrentSessionProps): never;
11
+ throwError403(currentSession?: CurrentSessionProps): never;
12
12
  }
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  import { Logger } from "../logger/index.js";
3
2
  import { reportError } from "../error/index.js";
4
3
  import { HttpError } from "../error/index.js";
@@ -1,6 +1,5 @@
1
- import 'reflect-metadata';
2
1
  import { ObjectId } from 'bson';
3
- import { CurrentUser } from './index.js';
2
+ import { Share, ShareProps } from './share';
4
3
  export interface BaseEntityProps {
5
4
  _id?: string | ObjectId;
6
5
  __v?: number;
@@ -14,11 +13,7 @@ export interface BaseEntityProps {
14
13
  deletedReason?: string;
15
14
  archivedAt?: string | Date;
16
15
  archivedBy?: string | ObjectId;
17
- sharedWith?: string[] | ObjectId[];
18
- toUnset?: Record<string, unknown>;
19
- }
20
- export interface Document extends BaseEntityProps {
21
- toUnset?: Record<string, unknown>;
16
+ sharedWith?: ShareProps[];
22
17
  }
23
18
  export declare class BaseEntity {
24
19
  _id?: ObjectId;
@@ -33,24 +28,11 @@ export declare class BaseEntity {
33
28
  deletedReason?: string;
34
29
  archivedAt?: Date;
35
30
  archivedBy?: ObjectId;
36
- sharedWith?: ObjectId[];
37
- toUnset?: Record<string, unknown>;
31
+ sharedWith?: Share[];
38
32
  static toObjectId(id?: string | ObjectId): ObjectId | undefined;
39
- private static toDate;
40
- private static toNumber;
41
- static clean(json: any): any;
33
+ static toText(value?: string): string | undefined;
34
+ static toDate(value?: string | Date): Date | undefined;
35
+ static toNumber(value?: number): number | undefined;
42
36
  constructor(props: BaseEntityProps);
43
- toJSON(): Document;
44
- setDefaults(): void;
45
- setId(id: string | ObjectId): void;
46
- setOwner(currentUser?: CurrentUser): void;
47
- setCreatedBy(currentUser?: CurrentUser, sanitize?: boolean): void;
48
- setUpdatedBy(currentUser?: CurrentUser): void;
49
- setDeletedBy(currentUser?: CurrentUser): void;
50
- setArchivedBy(currentUser?: CurrentUser): void;
51
- toDocument(): Document;
52
- toFlatDocument(): Document;
53
- stringify(): string;
54
- unset(fields: (keyof this)[]): {} | undefined;
55
- private sanitize;
37
+ toJSON(): BaseEntityProps;
56
38
  }
@@ -16,25 +16,16 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var __decorateClass = (decorators, target, key, kind) => {
20
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
21
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
22
- if (decorator = decorators[i])
23
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
24
- if (kind && result) __defProp(target, key, result);
25
- return result;
26
- };
27
19
  var base_entity_exports = {};
28
20
  __export(base_entity_exports, {
29
21
  BaseEntity: () => BaseEntity
30
22
  });
31
23
  module.exports = __toCommonJS(base_entity_exports);
32
- var import_reflect_metadata = require("reflect-metadata");
33
24
  var import_bson = require("bson");
34
- var import_decorators = require("../decorators/index.js");
25
+ var import_error = require("../error/index.js");
35
26
  var import_helpers = require("../helpers/index.js");
36
- var import_utils = require("./utils");
37
- const _BaseEntity = class _BaseEntity {
27
+ var import_share = require("./share");
28
+ class BaseEntity {
38
29
  _id;
39
30
  __v;
40
31
  ownerId;
@@ -48,41 +39,42 @@ const _BaseEntity = class _BaseEntity {
48
39
  archivedAt;
49
40
  archivedBy;
50
41
  sharedWith;
51
- toUnset;
52
42
  static toObjectId(id) {
53
43
  if (!id) return void 0;
54
44
  if (id instanceof import_bson.ObjectId) return id;
55
- if (!import_bson.ObjectId.isValid(id)) throw new Error(`Invalid ObjectId: ${id}`);
45
+ if (!import_bson.ObjectId.isValid(id)) throw new import_error.HttpError({ statusCode: 400, errorMessage: "{{invalid_object_id}}", errorDetails: { id } });
56
46
  return new import_bson.ObjectId(id);
57
47
  }
48
+ static toText(value) {
49
+ if (value === void 0 || value === null) return void 0;
50
+ if (typeof value !== "string") throw new import_error.HttpError({ statusCode: 400, errorMessage: "{{value_must_be_a_string}}" });
51
+ return (0, import_helpers.sanitizeString)(value.trim()) || void 0;
52
+ }
58
53
  static toDate(value) {
59
54
  if (!value) return void 0;
60
55
  const date = new Date(value);
61
- if (isNaN(date.getTime())) throw new Error("{{value_must_be_a_date}}");
56
+ if (isNaN(date.getTime())) throw new import_error.HttpError({ statusCode: 400, errorMessage: "{{value_must_be_a_date}}" });
62
57
  return date;
63
58
  }
64
59
  static toNumber(value) {
65
60
  if (value === void 0 || value === null) return void 0;
66
- if (typeof value !== "number") throw new Error("{{value_must_be_a_number}}");
61
+ if (typeof value !== "number") throw new import_error.HttpError({ statusCode: 400, errorMessage: "{{value_must_be_a_number}}" });
67
62
  return value;
68
63
  }
69
- static clean(json) {
70
- return (0, import_utils.deleteEmptyFields)(json);
71
- }
72
64
  constructor(props) {
73
- this._id = _BaseEntity.toObjectId(props._id);
74
- this.__v = _BaseEntity.toNumber(props.__v);
75
- this.ownerId = _BaseEntity.toObjectId(props.ownerId);
76
- this.createdAt = _BaseEntity.toDate(props.createdAt);
77
- this.createdBy = _BaseEntity.toObjectId(props.createdBy);
78
- this.updatedAt = _BaseEntity.toDate(props.updatedAt);
79
- this.updatedBy = _BaseEntity.toObjectId(props.updatedBy);
80
- this.deletedAt = _BaseEntity.toDate(props.deletedAt);
81
- this.deletedBy = _BaseEntity.toObjectId(props.deletedBy);
82
- this.deletedReason = (0, import_helpers.sanitizeString)(props.deletedReason);
83
- this.archivedAt = _BaseEntity.toDate(props.archivedAt);
84
- this.archivedBy = _BaseEntity.toObjectId(props.archivedBy);
85
- this.sharedWith = props.sharedWith?.length ? props.sharedWith.map((id) => _BaseEntity.toObjectId(id)) : void 0;
65
+ this._id = BaseEntity.toObjectId(props._id);
66
+ this.__v = BaseEntity.toNumber(props.__v);
67
+ this.ownerId = BaseEntity.toObjectId(props.ownerId);
68
+ this.createdAt = BaseEntity.toDate(props.createdAt);
69
+ this.createdBy = BaseEntity.toObjectId(props.createdBy);
70
+ this.updatedAt = BaseEntity.toDate(props.updatedAt);
71
+ this.updatedBy = BaseEntity.toObjectId(props.updatedBy);
72
+ this.deletedAt = BaseEntity.toDate(props.deletedAt);
73
+ this.deletedBy = BaseEntity.toObjectId(props.deletedBy);
74
+ this.deletedReason = BaseEntity.toText(props.deletedReason);
75
+ this.archivedAt = BaseEntity.toDate(props.archivedAt);
76
+ this.archivedBy = BaseEntity.toObjectId(props.archivedBy);
77
+ this.sharedWith = (0, import_share.createShares)(props.sharedWith);
86
78
  }
87
79
  toJSON() {
88
80
  return {
@@ -98,109 +90,10 @@ const _BaseEntity = class _BaseEntity {
98
90
  deletedReason: this.deletedReason,
99
91
  archivedAt: this.archivedAt,
100
92
  archivedBy: this.archivedBy,
101
- sharedWith: this.sharedWith?.length ? this.sharedWith.map((id) => id.toHexString()) : void 0,
102
- toUnset: this.toUnset
93
+ sharedWith: this.sharedWith?.length ? this.sharedWith : void 0
103
94
  };
104
95
  }
105
- setDefaults() {
106
- }
107
- setId(id) {
108
- this._id = _BaseEntity.toObjectId(id);
109
- }
110
- setOwner(currentUser) {
111
- if (!currentUser) return;
112
- this.ownerId = _BaseEntity.toObjectId(currentUser.userId);
113
- }
114
- setCreatedBy(currentUser, sanitize = true) {
115
- if (sanitize) this.sanitize(currentUser);
116
- this.createdAt = /* @__PURE__ */ new Date();
117
- this.createdBy = _BaseEntity.toObjectId(currentUser?.userId);
118
- this.setDefaults();
119
- }
120
- setUpdatedBy(currentUser) {
121
- if (!currentUser) return;
122
- this.sanitize(currentUser);
123
- this.updatedAt = /* @__PURE__ */ new Date();
124
- this.updatedBy = _BaseEntity.toObjectId(currentUser.userId);
125
- }
126
- setDeletedBy(currentUser) {
127
- if (!currentUser) return;
128
- this.sanitize(currentUser);
129
- this.deletedAt = /* @__PURE__ */ new Date();
130
- this.deletedBy = _BaseEntity.toObjectId(currentUser.userId);
131
- }
132
- setArchivedBy(currentUser) {
133
- if (!currentUser) return;
134
- this.sanitize(currentUser);
135
- this.archivedAt = /* @__PURE__ */ new Date();
136
- this.archivedBy = _BaseEntity.toObjectId(currentUser.userId);
137
- }
138
- toDocument() {
139
- return (0, import_utils.deleteEmptyFields)(this.toJSON());
140
- }
141
- toFlatDocument() {
142
- const { toUnset, ...doc } = this.toDocument();
143
- return { ...(0, import_utils.flattenObject)(doc), toUnset };
144
- }
145
- stringify() {
146
- return JSON.stringify((0, import_decorators.handleMaskInLogs)(this), null, 2);
147
- }
148
- unset(fields) {
149
- const toUnset = Array.from(new Set(fields.map((field) => String(field))));
150
- if (!toUnset || !Array.isArray(toUnset)) return {};
151
- this.toUnset = toUnset.reduce((acc, field) => {
152
- acc[field] = "";
153
- return acc;
154
- }, {});
155
- fields.forEach((field) => {
156
- delete this[field];
157
- });
158
- }
159
- sanitize(currentUser) {
160
- if (!currentUser?.isAdmin()) {
161
- for (const key in this) {
162
- const isAdminOnly = Reflect.getMetadata("adminOnly", this.constructor.prototype, key);
163
- if (isAdminOnly) {
164
- delete this[key];
165
- }
166
- }
167
- }
168
- }
169
- };
170
- __decorateClass([
171
- import_decorators.AdminOnly
172
- ], _BaseEntity.prototype, "__v", 2);
173
- __decorateClass([
174
- import_decorators.AdminOnly
175
- ], _BaseEntity.prototype, "ownerId", 2);
176
- __decorateClass([
177
- import_decorators.AdminOnly
178
- ], _BaseEntity.prototype, "createdAt", 2);
179
- __decorateClass([
180
- import_decorators.AdminOnly
181
- ], _BaseEntity.prototype, "createdBy", 2);
182
- __decorateClass([
183
- import_decorators.AdminOnly
184
- ], _BaseEntity.prototype, "updatedAt", 2);
185
- __decorateClass([
186
- import_decorators.AdminOnly
187
- ], _BaseEntity.prototype, "updatedBy", 2);
188
- __decorateClass([
189
- import_decorators.AdminOnly
190
- ], _BaseEntity.prototype, "deletedAt", 2);
191
- __decorateClass([
192
- import_decorators.AdminOnly
193
- ], _BaseEntity.prototype, "deletedBy", 2);
194
- __decorateClass([
195
- import_decorators.AdminOnly
196
- ], _BaseEntity.prototype, "archivedAt", 2);
197
- __decorateClass([
198
- import_decorators.AdminOnly
199
- ], _BaseEntity.prototype, "archivedBy", 2);
200
- __decorateClass([
201
- import_decorators.OwnerOnly
202
- ], _BaseEntity.prototype, "sharedWith", 2);
203
- let BaseEntity = _BaseEntity;
96
+ }
204
97
  // Annotate the CommonJS export names for ESM import in node:
205
98
  0 && (module.exports = {
206
99
  BaseEntity
@@ -1,12 +1,8 @@
1
- import {
2
- __decorateClass
3
- } from "../../chunk-CF3WOMB3.mjs";
4
- import "reflect-metadata";
5
1
  import { ObjectId } from "bson";
6
- import { AdminOnly, OwnerOnly, handleMaskInLogs } from "../decorators/index.js";
2
+ import { HttpError } from "../error/index.js";
7
3
  import { sanitizeString } from "../helpers/index.js";
8
- import { deleteEmptyFields, flattenObject } from "./utils";
9
- const _BaseEntity = class _BaseEntity {
4
+ import { createShares } from "./share";
5
+ class BaseEntity {
10
6
  _id;
11
7
  __v;
12
8
  ownerId;
@@ -20,41 +16,42 @@ const _BaseEntity = class _BaseEntity {
20
16
  archivedAt;
21
17
  archivedBy;
22
18
  sharedWith;
23
- toUnset;
24
19
  static toObjectId(id) {
25
20
  if (!id) return void 0;
26
21
  if (id instanceof ObjectId) return id;
27
- if (!ObjectId.isValid(id)) throw new Error(`Invalid ObjectId: ${id}`);
22
+ if (!ObjectId.isValid(id)) throw new HttpError({ statusCode: 400, errorMessage: "{{invalid_object_id}}", errorDetails: { id } });
28
23
  return new ObjectId(id);
29
24
  }
25
+ static toText(value) {
26
+ if (value === void 0 || value === null) return void 0;
27
+ if (typeof value !== "string") throw new HttpError({ statusCode: 400, errorMessage: "{{value_must_be_a_string}}" });
28
+ return sanitizeString(value.trim()) || void 0;
29
+ }
30
30
  static toDate(value) {
31
31
  if (!value) return void 0;
32
32
  const date = new Date(value);
33
- if (isNaN(date.getTime())) throw new Error("{{value_must_be_a_date}}");
33
+ if (isNaN(date.getTime())) throw new HttpError({ statusCode: 400, errorMessage: "{{value_must_be_a_date}}" });
34
34
  return date;
35
35
  }
36
36
  static toNumber(value) {
37
37
  if (value === void 0 || value === null) return void 0;
38
- if (typeof value !== "number") throw new Error("{{value_must_be_a_number}}");
38
+ if (typeof value !== "number") throw new HttpError({ statusCode: 400, errorMessage: "{{value_must_be_a_number}}" });
39
39
  return value;
40
40
  }
41
- static clean(json) {
42
- return deleteEmptyFields(json);
43
- }
44
41
  constructor(props) {
45
- this._id = _BaseEntity.toObjectId(props._id);
46
- this.__v = _BaseEntity.toNumber(props.__v);
47
- this.ownerId = _BaseEntity.toObjectId(props.ownerId);
48
- this.createdAt = _BaseEntity.toDate(props.createdAt);
49
- this.createdBy = _BaseEntity.toObjectId(props.createdBy);
50
- this.updatedAt = _BaseEntity.toDate(props.updatedAt);
51
- this.updatedBy = _BaseEntity.toObjectId(props.updatedBy);
52
- this.deletedAt = _BaseEntity.toDate(props.deletedAt);
53
- this.deletedBy = _BaseEntity.toObjectId(props.deletedBy);
54
- this.deletedReason = sanitizeString(props.deletedReason);
55
- this.archivedAt = _BaseEntity.toDate(props.archivedAt);
56
- this.archivedBy = _BaseEntity.toObjectId(props.archivedBy);
57
- this.sharedWith = props.sharedWith?.length ? props.sharedWith.map((id) => _BaseEntity.toObjectId(id)) : void 0;
42
+ this._id = BaseEntity.toObjectId(props._id);
43
+ this.__v = BaseEntity.toNumber(props.__v);
44
+ this.ownerId = BaseEntity.toObjectId(props.ownerId);
45
+ this.createdAt = BaseEntity.toDate(props.createdAt);
46
+ this.createdBy = BaseEntity.toObjectId(props.createdBy);
47
+ this.updatedAt = BaseEntity.toDate(props.updatedAt);
48
+ this.updatedBy = BaseEntity.toObjectId(props.updatedBy);
49
+ this.deletedAt = BaseEntity.toDate(props.deletedAt);
50
+ this.deletedBy = BaseEntity.toObjectId(props.deletedBy);
51
+ this.deletedReason = BaseEntity.toText(props.deletedReason);
52
+ this.archivedAt = BaseEntity.toDate(props.archivedAt);
53
+ this.archivedBy = BaseEntity.toObjectId(props.archivedBy);
54
+ this.sharedWith = createShares(props.sharedWith);
58
55
  }
59
56
  toJSON() {
60
57
  return {
@@ -70,109 +67,10 @@ const _BaseEntity = class _BaseEntity {
70
67
  deletedReason: this.deletedReason,
71
68
  archivedAt: this.archivedAt,
72
69
  archivedBy: this.archivedBy,
73
- sharedWith: this.sharedWith?.length ? this.sharedWith.map((id) => id.toHexString()) : void 0,
74
- toUnset: this.toUnset
70
+ sharedWith: this.sharedWith?.length ? this.sharedWith : void 0
75
71
  };
76
72
  }
77
- setDefaults() {
78
- }
79
- setId(id) {
80
- this._id = _BaseEntity.toObjectId(id);
81
- }
82
- setOwner(currentUser) {
83
- if (!currentUser) return;
84
- this.ownerId = _BaseEntity.toObjectId(currentUser.userId);
85
- }
86
- setCreatedBy(currentUser, sanitize = true) {
87
- if (sanitize) this.sanitize(currentUser);
88
- this.createdAt = /* @__PURE__ */ new Date();
89
- this.createdBy = _BaseEntity.toObjectId(currentUser?.userId);
90
- this.setDefaults();
91
- }
92
- setUpdatedBy(currentUser) {
93
- if (!currentUser) return;
94
- this.sanitize(currentUser);
95
- this.updatedAt = /* @__PURE__ */ new Date();
96
- this.updatedBy = _BaseEntity.toObjectId(currentUser.userId);
97
- }
98
- setDeletedBy(currentUser) {
99
- if (!currentUser) return;
100
- this.sanitize(currentUser);
101
- this.deletedAt = /* @__PURE__ */ new Date();
102
- this.deletedBy = _BaseEntity.toObjectId(currentUser.userId);
103
- }
104
- setArchivedBy(currentUser) {
105
- if (!currentUser) return;
106
- this.sanitize(currentUser);
107
- this.archivedAt = /* @__PURE__ */ new Date();
108
- this.archivedBy = _BaseEntity.toObjectId(currentUser.userId);
109
- }
110
- toDocument() {
111
- return deleteEmptyFields(this.toJSON());
112
- }
113
- toFlatDocument() {
114
- const { toUnset, ...doc } = this.toDocument();
115
- return { ...flattenObject(doc), toUnset };
116
- }
117
- stringify() {
118
- return JSON.stringify(handleMaskInLogs(this), null, 2);
119
- }
120
- unset(fields) {
121
- const toUnset = Array.from(new Set(fields.map((field) => String(field))));
122
- if (!toUnset || !Array.isArray(toUnset)) return {};
123
- this.toUnset = toUnset.reduce((acc, field) => {
124
- acc[field] = "";
125
- return acc;
126
- }, {});
127
- fields.forEach((field) => {
128
- delete this[field];
129
- });
130
- }
131
- sanitize(currentUser) {
132
- if (!currentUser?.isAdmin()) {
133
- for (const key in this) {
134
- const isAdminOnly = Reflect.getMetadata("adminOnly", this.constructor.prototype, key);
135
- if (isAdminOnly) {
136
- delete this[key];
137
- }
138
- }
139
- }
140
- }
141
- };
142
- __decorateClass([
143
- AdminOnly
144
- ], _BaseEntity.prototype, "__v", 2);
145
- __decorateClass([
146
- AdminOnly
147
- ], _BaseEntity.prototype, "ownerId", 2);
148
- __decorateClass([
149
- AdminOnly
150
- ], _BaseEntity.prototype, "createdAt", 2);
151
- __decorateClass([
152
- AdminOnly
153
- ], _BaseEntity.prototype, "createdBy", 2);
154
- __decorateClass([
155
- AdminOnly
156
- ], _BaseEntity.prototype, "updatedAt", 2);
157
- __decorateClass([
158
- AdminOnly
159
- ], _BaseEntity.prototype, "updatedBy", 2);
160
- __decorateClass([
161
- AdminOnly
162
- ], _BaseEntity.prototype, "deletedAt", 2);
163
- __decorateClass([
164
- AdminOnly
165
- ], _BaseEntity.prototype, "deletedBy", 2);
166
- __decorateClass([
167
- AdminOnly
168
- ], _BaseEntity.prototype, "archivedAt", 2);
169
- __decorateClass([
170
- AdminOnly
171
- ], _BaseEntity.prototype, "archivedBy", 2);
172
- __decorateClass([
173
- OwnerOnly
174
- ], _BaseEntity.prototype, "sharedWith", 2);
175
- let BaseEntity = _BaseEntity;
73
+ }
176
74
  export {
177
75
  BaseEntity
178
76
  };
@@ -1,15 +1,11 @@
1
1
  import { CurrentUser, CurrentSession } from './index.js';
2
- import { HttpError } from '../error/index.js';
2
+ import { Scope } from '../repositories/index.js';
3
3
  import { BaseApp } from './base.app';
4
4
  export interface BaseUseCaseParams {
5
5
  currentUser?: CurrentUser;
6
6
  currentSession?: CurrentSession;
7
- }
8
- export interface BaseUseCaseOutput {
9
- message?: string;
10
- data?: any;
11
- error?: any;
7
+ scope?: Scope;
12
8
  }
13
9
  export declare abstract class BaseUseCase<TReq, TRes> extends BaseApp {
14
- abstract execute(params?: TReq): Promise<TRes | HttpError>;
10
+ abstract execute(params?: TReq): Promise<TRes>;
15
11
  }
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  import { BaseApp } from "./base.app";
3
2
  class BaseUseCase extends BaseApp {
4
3
  }
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  import { getCountry, getTimezone } from "iso-data";
3
2
  class CurrentSession {
4
3
  constructor(clientType, environment, app, device, preferences, location, request) {
@@ -1,4 +1,3 @@
1
- import "../../chunk-CF3WOMB3.mjs";
2
1
  import { ObjectId } from "mongodb";
3
2
  import { getTimezone } from "iso-data";
4
3
  import { getMongoDBClient } from "../repositories/mongo-db.client.js";
@@ -1,2 +1,3 @@
1
1
  export * from './current-session';
2
2
  export * from './current-user';
3
+ export * from '../repositories/scope';