openloops 0.10.3 → 0.11.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 (612) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +11 -17
  3. package/dist/clients/llm/llm-client.d.ts +2 -2
  4. package/dist/clients/llm/llm-client.js +17 -18
  5. package/dist/clients/llm/llm-client.mjs +12 -13
  6. package/dist/clients/llm/llm-types.d.ts +2 -2
  7. package/dist/clients/llm/model-resolution.js +4 -5
  8. package/dist/clients/llm/model-resolution.mjs +1 -2
  9. package/dist/clients/serper/serper-client.js +3 -4
  10. package/dist/clients/serper/serper-client.mjs +1 -2
  11. package/dist/clients/slack/slack-client.js +2 -2
  12. package/dist/clients/slack/slack-client.mjs +1 -1
  13. package/dist/common/utils/number-setting.js +2 -2
  14. package/dist/common/utils/number-setting.mjs +1 -1
  15. package/dist/db/indexes/index.js +1 -5
  16. package/dist/db/indexes/index.mjs +1 -5
  17. package/dist/guardrails/guard.d.ts +4 -4
  18. package/dist/harness/actor-profile.d.ts +2 -0
  19. package/dist/{common/error/error-reporter.js → harness/actor-profile.js} +10 -13
  20. package/dist/harness/actor-profile.mjs +9 -0
  21. package/dist/harness/agent-loop.d.ts +4 -5
  22. package/dist/harness/agent.d.ts +7 -7
  23. package/dist/harness/agent.js +46 -46
  24. package/dist/harness/agent.mjs +44 -44
  25. package/dist/harness/default-model.d.ts +20 -0
  26. package/dist/harness/default-model.js +72 -0
  27. package/dist/harness/default-model.mjs +46 -0
  28. package/dist/harness/index.d.ts +2 -0
  29. package/dist/harness/index.js +8 -1
  30. package/dist/harness/index.mjs +5 -1
  31. package/dist/harness/tool-pipeline.d.ts +1 -1
  32. package/dist/harness/tool-pipeline.js +3 -3
  33. package/dist/harness/tool-pipeline.mjs +1 -1
  34. package/dist/harness/usage-limit.d.ts +2 -2
  35. package/dist/harness/usage-limit.js +5 -3
  36. package/dist/harness/usage-limit.mjs +5 -3
  37. package/dist/harness/workspace.d.ts +3 -3
  38. package/dist/harness/workspace.js +8 -8
  39. package/dist/harness/workspace.mjs +8 -8
  40. package/dist/services/automations/entities/automation-run.entity.d.ts +1 -1
  41. package/dist/services/automations/entities/automation-run.entity.js +4 -4
  42. package/dist/services/automations/entities/automation-run.entity.mjs +1 -1
  43. package/dist/services/automations/entities/automation.entity.d.ts +1 -1
  44. package/dist/services/automations/entities/automation.entity.js +3 -3
  45. package/dist/services/automations/entities/automation.entity.mjs +1 -1
  46. package/dist/services/automations/repositories/automation-run.repository.d.ts +1 -1
  47. package/dist/services/automations/repositories/automation-run.repository.js +5 -6
  48. package/dist/services/automations/repositories/automation-run.repository.mjs +2 -3
  49. package/dist/services/automations/repositories/automation.repository.d.ts +1 -1
  50. package/dist/services/automations/repositories/automation.repository.js +5 -6
  51. package/dist/services/automations/repositories/automation.repository.mjs +2 -3
  52. package/dist/services/automations/runner/automation-runner.d.ts +4 -4
  53. package/dist/services/automations/runner/automation-runner.js +16 -15
  54. package/dist/services/automations/runner/automation-runner.mjs +11 -10
  55. package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.d.ts +1 -1
  56. package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.js +2 -2
  57. package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.mjs +1 -1
  58. package/dist/services/automations/use-cases/claim-due-automations.use-case.d.ts +1 -1
  59. package/dist/services/automations/use-cases/claim-due-automations.use-case.js +3 -4
  60. package/dist/services/automations/use-cases/claim-due-automations.use-case.mjs +1 -2
  61. package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.d.ts +1 -1
  62. package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.js +2 -2
  63. package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.mjs +1 -1
  64. package/dist/services/automations/use-cases/create-automation.use-case.d.ts +1 -1
  65. package/dist/services/automations/use-cases/create-automation.use-case.js +8 -8
  66. package/dist/services/automations/use-cases/create-automation.use-case.mjs +5 -5
  67. package/dist/services/automations/use-cases/delete-automation.use-case.d.ts +1 -1
  68. package/dist/services/automations/use-cases/delete-automation.use-case.js +8 -8
  69. package/dist/services/automations/use-cases/delete-automation.use-case.mjs +5 -5
  70. package/dist/services/automations/use-cases/finish-automation-run.use-case.d.ts +1 -1
  71. package/dist/services/automations/use-cases/finish-automation-run.use-case.js +2 -2
  72. package/dist/services/automations/use-cases/finish-automation-run.use-case.mjs +1 -1
  73. package/dist/services/automations/use-cases/get-automation-by-id.use-case.d.ts +1 -1
  74. package/dist/services/automations/use-cases/get-automation-by-id.use-case.js +7 -7
  75. package/dist/services/automations/use-cases/get-automation-by-id.use-case.mjs +4 -4
  76. package/dist/services/automations/use-cases/issue-automation-event-token.use-case.d.ts +1 -1
  77. package/dist/services/automations/use-cases/issue-automation-event-token.use-case.js +7 -7
  78. package/dist/services/automations/use-cases/issue-automation-event-token.use-case.mjs +4 -4
  79. package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.d.ts +2 -2
  80. package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.js +7 -7
  81. package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.mjs +4 -4
  82. package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.d.ts +2 -2
  83. package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.js +9 -9
  84. package/dist/services/automations/use-cases/list-automation-runs-by-user.use-case.mjs +6 -6
  85. package/dist/services/automations/use-cases/list-automations-by-user.use-case.d.ts +2 -2
  86. package/dist/services/automations/use-cases/list-automations-by-user.use-case.js +9 -9
  87. package/dist/services/automations/use-cases/list-automations-by-user.use-case.mjs +6 -6
  88. package/dist/services/automations/use-cases/preview-automation-runs.use-case.d.ts +1 -1
  89. package/dist/services/automations/use-cases/preview-automation-runs.use-case.js +2 -2
  90. package/dist/services/automations/use-cases/preview-automation-runs.use-case.mjs +1 -1
  91. package/dist/services/automations/use-cases/receive-automation-event.use-case.d.ts +1 -1
  92. package/dist/services/automations/use-cases/receive-automation-event.use-case.js +3 -3
  93. package/dist/services/automations/use-cases/receive-automation-event.use-case.mjs +2 -2
  94. package/dist/services/automations/use-cases/renew-automation-lease.use-case.d.ts +1 -1
  95. package/dist/services/automations/use-cases/renew-automation-lease.use-case.js +2 -2
  96. package/dist/services/automations/use-cases/renew-automation-lease.use-case.mjs +1 -1
  97. package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.d.ts +1 -1
  98. package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.js +10 -11
  99. package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.mjs +7 -8
  100. package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.d.ts +1 -1
  101. package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.js +7 -7
  102. package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.mjs +4 -4
  103. package/dist/services/automations/use-cases/start-automation-run.use-case.d.ts +1 -1
  104. package/dist/services/automations/use-cases/start-automation-run.use-case.js +5 -5
  105. package/dist/services/automations/use-cases/start-automation-run.use-case.mjs +4 -4
  106. package/dist/services/automations/use-cases/sync-automation-run.use-case.d.ts +1 -1
  107. package/dist/services/automations/use-cases/sync-automation-run.use-case.js +2 -2
  108. package/dist/services/automations/use-cases/sync-automation-run.use-case.mjs +1 -1
  109. package/dist/services/automations/use-cases/sync-automation-runs.use-case.d.ts +1 -1
  110. package/dist/services/automations/use-cases/sync-automation-runs.use-case.js +2 -2
  111. package/dist/services/automations/use-cases/sync-automation-runs.use-case.mjs +1 -1
  112. package/dist/services/automations/use-cases/update-automation.use-case.d.ts +1 -1
  113. package/dist/services/automations/use-cases/update-automation.use-case.js +8 -9
  114. package/dist/services/automations/use-cases/update-automation.use-case.mjs +4 -5
  115. package/dist/services/automations/utils/event-token.d.ts +1 -0
  116. package/dist/services/automations/utils/event-token.js +9 -6
  117. package/dist/services/automations/utils/event-token.mjs +3 -1
  118. package/dist/services/automations/utils/open-run.d.ts +1 -1
  119. package/dist/services/automations/utils/runner-scope.d.ts +1 -1
  120. package/dist/services/automations/utils/runner-scope.js +3 -3
  121. package/dist/services/automations/utils/runner-scope.mjs +1 -1
  122. package/dist/services/chats/entities/chat-message.entity.d.ts +1 -1
  123. package/dist/services/chats/entities/chat-message.entity.js +3 -3
  124. package/dist/services/chats/entities/chat-message.entity.mjs +1 -1
  125. package/dist/services/chats/entities/chat.entity.d.ts +1 -1
  126. package/dist/services/chats/entities/chat.entity.js +4 -4
  127. package/dist/services/chats/entities/chat.entity.mjs +1 -1
  128. package/dist/services/chats/repositories/chat.repository.d.ts +1 -1
  129. package/dist/services/chats/repositories/chat.repository.js +5 -6
  130. package/dist/services/chats/repositories/chat.repository.mjs +2 -3
  131. package/dist/services/chats/use-cases/create-chat.use-case.d.ts +1 -1
  132. package/dist/services/chats/use-cases/create-chat.use-case.js +7 -7
  133. package/dist/services/chats/use-cases/create-chat.use-case.mjs +4 -4
  134. package/dist/services/chats/use-cases/delete-chat.use-case.d.ts +1 -1
  135. package/dist/services/chats/use-cases/delete-chat.use-case.js +8 -8
  136. package/dist/services/chats/use-cases/delete-chat.use-case.mjs +5 -5
  137. package/dist/services/chats/use-cases/get-chat-by-id.use-case.d.ts +2 -2
  138. package/dist/services/chats/use-cases/get-chat-by-id.use-case.js +7 -7
  139. package/dist/services/chats/use-cases/get-chat-by-id.use-case.mjs +4 -4
  140. package/dist/services/chats/use-cases/interrupt-execution.use-case.d.ts +1 -1
  141. package/dist/services/chats/use-cases/interrupt-execution.use-case.js +7 -7
  142. package/dist/services/chats/use-cases/interrupt-execution.use-case.mjs +4 -4
  143. package/dist/services/chats/use-cases/list-chats-by-props.use-case.d.ts +2 -2
  144. package/dist/services/chats/use-cases/list-chats-by-props.use-case.js +7 -7
  145. package/dist/services/chats/use-cases/list-chats-by-props.use-case.mjs +4 -4
  146. package/dist/services/chats/use-cases/list-chats-by-user.use-case.d.ts +2 -2
  147. package/dist/services/chats/use-cases/list-chats-by-user.use-case.js +8 -8
  148. package/dist/services/chats/use-cases/list-chats-by-user.use-case.mjs +5 -5
  149. package/dist/services/chats/use-cases/update-chat.use-case.d.ts +1 -1
  150. package/dist/services/chats/use-cases/update-chat.use-case.js +7 -7
  151. package/dist/services/chats/use-cases/update-chat.use-case.mjs +4 -4
  152. package/dist/services/llmcalls/entities/llmcall.entity.d.ts +1 -1
  153. package/dist/services/llmcalls/entities/llmcall.entity.js +4 -4
  154. package/dist/services/llmcalls/entities/llmcall.entity.mjs +1 -1
  155. package/dist/services/llmcalls/repositories/llmcall.repository.d.ts +1 -1
  156. package/dist/services/llmcalls/repositories/llmcall.repository.js +5 -6
  157. package/dist/services/llmcalls/repositories/llmcall.repository.mjs +2 -3
  158. package/dist/services/llmcalls/use-cases/create-llmcall.use-case.d.ts +1 -1
  159. package/dist/services/llmcalls/use-cases/create-llmcall.use-case.js +7 -7
  160. package/dist/services/llmcalls/use-cases/create-llmcall.use-case.mjs +4 -4
  161. package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.d.ts +1 -1
  162. package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.js +8 -8
  163. package/dist/services/llmcalls/use-cases/delete-llmcall.use-case.mjs +5 -5
  164. package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.d.ts +1 -1
  165. package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.js +9 -9
  166. package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.mjs +6 -6
  167. package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.d.ts +1 -1
  168. package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.js +9 -9
  169. package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.mjs +6 -6
  170. package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.d.ts +2 -2
  171. package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.js +12 -10
  172. package/dist/services/llmcalls/use-cases/get-llm-usage-stats.use-case.mjs +9 -7
  173. package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.d.ts +1 -1
  174. package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.js +7 -7
  175. package/dist/services/llmcalls/use-cases/get-llmcall-by-id.use-case.mjs +4 -4
  176. package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.d.ts +2 -2
  177. package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.js +5 -5
  178. package/dist/services/llmcalls/use-cases/list-llmcalls-by-props.use-case.mjs +4 -4
  179. package/dist/services/llmcalls/use-cases/update-llmcall.use-case.d.ts +1 -1
  180. package/dist/services/llmcalls/use-cases/update-llmcall.use-case.js +7 -7
  181. package/dist/services/llmcalls/use-cases/update-llmcall.use-case.mjs +4 -4
  182. package/dist/services/mcp-servers/admin/admin-params.d.ts +5 -0
  183. package/dist/{common/logger/index.js → services/mcp-servers/admin/admin-params.js} +2 -8
  184. package/dist/services/mcp-servers/admin/admin-params.mjs +0 -0
  185. package/dist/services/mcp-servers/admin/use-cases/create-internal-mcp.use-case.d.ts +3 -2
  186. package/dist/services/mcp-servers/admin/use-cases/create-internal-mcp.use-case.js +7 -7
  187. package/dist/services/mcp-servers/admin/use-cases/create-internal-mcp.use-case.mjs +4 -4
  188. package/dist/services/mcp-servers/admin/use-cases/delete-internal-mcp.use-case.d.ts +3 -2
  189. package/dist/services/mcp-servers/admin/use-cases/delete-internal-mcp.use-case.js +7 -7
  190. package/dist/services/mcp-servers/admin/use-cases/delete-internal-mcp.use-case.mjs +4 -4
  191. package/dist/services/mcp-servers/admin/use-cases/get-internal-mcp-by-id.use-case.d.ts +3 -2
  192. package/dist/services/mcp-servers/admin/use-cases/get-internal-mcp-by-id.use-case.js +7 -7
  193. package/dist/services/mcp-servers/admin/use-cases/get-internal-mcp-by-id.use-case.mjs +4 -4
  194. package/dist/services/mcp-servers/admin/use-cases/list-internal-mcps.use-case.d.ts +4 -3
  195. package/dist/services/mcp-servers/admin/use-cases/list-internal-mcps.use-case.js +7 -7
  196. package/dist/services/mcp-servers/admin/use-cases/list-internal-mcps.use-case.mjs +4 -4
  197. package/dist/services/mcp-servers/admin/use-cases/update-internal-mcp.use-case.d.ts +3 -2
  198. package/dist/services/mcp-servers/admin/use-cases/update-internal-mcp.use-case.js +8 -9
  199. package/dist/services/mcp-servers/admin/use-cases/update-internal-mcp.use-case.mjs +4 -5
  200. package/dist/services/mcp-servers/entities/mcpserver.entity.d.ts +1 -1
  201. package/dist/services/mcp-servers/entities/mcpserver.entity.js +2 -2
  202. package/dist/services/mcp-servers/entities/mcpserver.entity.mjs +1 -1
  203. package/dist/services/mcp-servers/repositories/mcpserver.repository.d.ts +1 -1
  204. package/dist/services/mcp-servers/repositories/mcpserver.repository.js +6 -7
  205. package/dist/services/mcp-servers/repositories/mcpserver.repository.mjs +2 -3
  206. package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.d.ts +1 -1
  207. package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.js +8 -8
  208. package/dist/services/mcp-servers/use-cases/create-mcpserver.use-case.mjs +5 -5
  209. package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.d.ts +1 -1
  210. package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.js +7 -7
  211. package/dist/services/mcp-servers/use-cases/decide-mcpserver-trust.use-case.mjs +4 -4
  212. package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.d.ts +1 -1
  213. package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.js +8 -8
  214. package/dist/services/mcp-servers/use-cases/delete-mcpserver.use-case.mjs +5 -5
  215. package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.d.ts +1 -1
  216. package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.js +7 -7
  217. package/dist/services/mcp-servers/use-cases/get-mcpserver-by-id.use-case.mjs +4 -4
  218. package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.d.ts +1 -1
  219. package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.js +8 -8
  220. package/dist/services/mcp-servers/use-cases/list-all-mcpservers-by-user.use-case.mjs +5 -5
  221. package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.d.ts +2 -2
  222. package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.js +8 -8
  223. package/dist/services/mcp-servers/use-cases/list-mcpservers-by-user.use-case.mjs +5 -5
  224. package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.d.ts +1 -1
  225. package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.js +9 -10
  226. package/dist/services/mcp-servers/use-cases/update-mcpserver.use-case.mjs +5 -6
  227. package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.d.ts +1 -1
  228. package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.js +9 -10
  229. package/dist/services/mcp-servers/use-cases/verify-mcpserver-connection.use-case.mjs +4 -5
  230. package/dist/services/tasks/entities/agent-action.entity.d.ts +1 -1
  231. package/dist/services/tasks/entities/agent-action.entity.js +6 -7
  232. package/dist/services/tasks/entities/agent-action.entity.mjs +1 -2
  233. package/dist/services/tasks/entities/agent-task.entity.d.ts +1 -1
  234. package/dist/services/tasks/entities/agent-task.entity.js +4 -4
  235. package/dist/services/tasks/entities/agent-task.entity.mjs +1 -1
  236. package/dist/services/tasks/repositories/agent-action.repository.d.ts +1 -1
  237. package/dist/services/tasks/repositories/agent-action.repository.js +5 -6
  238. package/dist/services/tasks/repositories/agent-action.repository.mjs +2 -3
  239. package/dist/services/tasks/repositories/agent-task.repository.d.ts +1 -1
  240. package/dist/services/tasks/repositories/agent-task.repository.js +5 -6
  241. package/dist/services/tasks/repositories/agent-task.repository.mjs +2 -3
  242. package/dist/services/tasks/use-cases/create-agent-action.use-case.d.ts +1 -1
  243. package/dist/services/tasks/use-cases/create-agent-action.use-case.js +7 -7
  244. package/dist/services/tasks/use-cases/create-agent-action.use-case.mjs +4 -4
  245. package/dist/services/tasks/use-cases/create-agent-task.use-case.d.ts +1 -1
  246. package/dist/services/tasks/use-cases/create-agent-task.use-case.js +7 -7
  247. package/dist/services/tasks/use-cases/create-agent-task.use-case.mjs +4 -4
  248. package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.d.ts +1 -1
  249. package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.js +7 -7
  250. package/dist/services/tasks/use-cases/get-agent-task-by-id.use-case.mjs +4 -4
  251. package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.d.ts +2 -2
  252. package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.js +9 -10
  253. package/dist/services/tasks/use-cases/list-agent-actions-by-task.use-case.mjs +6 -7
  254. package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.d.ts +2 -2
  255. package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.js +9 -10
  256. package/dist/services/tasks/use-cases/list-agent-tasks-by-chat.use-case.mjs +6 -7
  257. package/dist/services/tasks/use-cases/update-agent-action.use-case.d.ts +1 -1
  258. package/dist/services/tasks/use-cases/update-agent-action.use-case.js +7 -7
  259. package/dist/services/tasks/use-cases/update-agent-action.use-case.mjs +4 -4
  260. package/dist/services/tasks/use-cases/update-agent-task.use-case.d.ts +1 -1
  261. package/dist/services/tasks/use-cases/update-agent-task.use-case.js +7 -7
  262. package/dist/services/tasks/use-cases/update-agent-task.use-case.mjs +4 -4
  263. package/dist/services/traces/entities/agent-trace-entry.entity.d.ts +1 -1
  264. package/dist/services/traces/entities/agent-trace-entry.entity.js +6 -6
  265. package/dist/services/traces/entities/agent-trace-entry.entity.mjs +1 -1
  266. package/dist/services/traces/repositories/agent-trace.repository.d.ts +1 -1
  267. package/dist/services/traces/repositories/agent-trace.repository.js +4 -4
  268. package/dist/services/traces/repositories/agent-trace.repository.mjs +2 -2
  269. package/dist/services/traces/use-cases/create-agent-traces.use-case.d.ts +1 -1
  270. package/dist/services/traces/use-cases/create-agent-traces.use-case.js +7 -7
  271. package/dist/services/traces/use-cases/create-agent-traces.use-case.mjs +4 -4
  272. package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.d.ts +2 -2
  273. package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.js +12 -13
  274. package/dist/services/traces/use-cases/list-agent-traces-by-chat.use-case.mjs +6 -7
  275. package/dist/services/workspaces/entities/workspace-item.entity.d.ts +1 -1
  276. package/dist/services/workspaces/entities/workspace-item.entity.js +5 -5
  277. package/dist/services/workspaces/entities/workspace-item.entity.mjs +1 -1
  278. package/dist/services/workspaces/repositories/workspace-item.repository.d.ts +1 -1
  279. package/dist/services/workspaces/repositories/workspace-item.repository.js +5 -6
  280. package/dist/services/workspaces/repositories/workspace-item.repository.mjs +2 -3
  281. package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.d.ts +1 -1
  282. package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.js +11 -12
  283. package/dist/services/workspaces/use-cases/delete-workspace-item.use-case.mjs +6 -7
  284. package/dist/services/workspaces/use-cases/get-workspace-item.use-case.d.ts +1 -1
  285. package/dist/services/workspaces/use-cases/get-workspace-item.use-case.js +11 -12
  286. package/dist/services/workspaces/use-cases/get-workspace-item.use-case.mjs +6 -7
  287. package/dist/services/workspaces/use-cases/list-workspace-items.use-case.d.ts +2 -2
  288. package/dist/services/workspaces/use-cases/list-workspace-items.use-case.js +11 -12
  289. package/dist/services/workspaces/use-cases/list-workspace-items.use-case.mjs +6 -7
  290. package/dist/services/workspaces/use-cases/save-workspace-item.use-case.d.ts +1 -1
  291. package/dist/services/workspaces/use-cases/save-workspace-item.use-case.js +10 -11
  292. package/dist/services/workspaces/use-cases/save-workspace-item.use-case.mjs +6 -7
  293. package/dist/services/workspaces/use-cases/search-workspace-items.use-case.d.ts +2 -2
  294. package/dist/services/workspaces/use-cases/search-workspace-items.use-case.js +11 -12
  295. package/dist/services/workspaces/use-cases/search-workspace-items.use-case.mjs +6 -7
  296. package/dist/skills/runtime-context.d.ts +3 -3
  297. package/dist/skills/runtime-context.js +24 -21
  298. package/dist/skills/runtime-context.mjs +24 -21
  299. package/dist/skills/skill.d.ts +3 -3
  300. package/dist/skills/skill.js +5 -5
  301. package/dist/skills/skill.mjs +4 -4
  302. package/dist/tools/core/call-ai/call-ai.tool.js +2 -2
  303. package/dist/tools/core/call-ai/call-ai.tool.mjs +2 -2
  304. package/dist/tools/core/web-search/web-search.tool.js +1 -1
  305. package/dist/tools/core/web-search/web-search.tool.mjs +1 -1
  306. package/dist/tools/tool.d.ts +2 -2
  307. package/dist/tools/tool.js +1 -1
  308. package/dist/tools/tool.mjs +1 -1
  309. package/docs/README.md +1 -1
  310. package/docs/agent.md +10 -10
  311. package/docs/authentication.md +15 -114
  312. package/docs/authorization.md +18 -18
  313. package/docs/automations.md +28 -28
  314. package/docs/chats.md +14 -14
  315. package/docs/configuration.md +14 -15
  316. package/docs/error-reporting.md +6 -6
  317. package/docs/guardrails.md +1 -1
  318. package/docs/integration-guide.md +12 -12
  319. package/docs/loops.md +2 -2
  320. package/docs/mcp-servers.md +15 -15
  321. package/docs/skills.md +1 -1
  322. package/docs/tools.md +2 -2
  323. package/docs/usage.md +5 -5
  324. package/docs/users.md +18 -91
  325. package/examples/automations/create-automation.ts +4 -4
  326. package/examples/automations/create-event-automation.ts +5 -5
  327. package/examples/automations/list-automation-runs.ts +7 -7
  328. package/examples/automations/list-automations.ts +4 -4
  329. package/examples/automations/preview-automation-runs.ts +1 -1
  330. package/examples/automations/receive-automation-event.ts +1 -1
  331. package/examples/automations/revoke-automation-event-token.ts +6 -6
  332. package/examples/automations/run-automation-now.ts +4 -4
  333. package/examples/automations/run-automation-worker.ts +1 -1
  334. package/examples/automations/update-automation.ts +6 -6
  335. package/examples/chats/delete-chat.ts +6 -6
  336. package/examples/chats/get-chat-by-id.ts +6 -6
  337. package/examples/chats/list-autonomous-chats.ts +4 -4
  338. package/examples/chats/list-chats.ts +4 -4
  339. package/examples/chats/search-chats.ts +5 -5
  340. package/examples/errors/error-reporting.ts +6 -6
  341. package/examples/loops/custom-loop.ts +5 -5
  342. package/examples/mcps/create-mcp.ts +4 -4
  343. package/examples/mcps/decide-mcp.ts +7 -7
  344. package/examples/mcps/delete-mcp.ts +6 -6
  345. package/examples/mcps/get-mcp-by-id.ts +4 -4
  346. package/examples/mcps/internal-mcp-admin.ts +8 -8
  347. package/examples/mcps/internal-mcp.ts +5 -5
  348. package/examples/mcps/list-all-mcps.ts +4 -4
  349. package/examples/mcps/list-user-mcps.ts +4 -4
  350. package/examples/mcps/update-mcp.ts +4 -4
  351. package/examples/mcps/verify-mcp.ts +4 -4
  352. package/examples/run-agent/interrupt-agent.ts +5 -5
  353. package/examples/run-agent/run-agent-autonomous.ts +5 -5
  354. package/examples/run-agent/run-agent-multi-tenant.ts +10 -11
  355. package/examples/run-agent/run-agent-strict-mode.ts +5 -5
  356. package/examples/run-agent/run-agent-with-confirmation.ts +6 -6
  357. package/examples/run-agent/run-agent-with-fallback-model.ts +5 -5
  358. package/examples/run-agent/run-agent-with-fetch-url.ts +5 -5
  359. package/examples/run-agent/run-agent-with-guards.ts +5 -5
  360. package/examples/run-agent/run-agent-with-hooks.ts +5 -5
  361. package/examples/run-agent/run-agent-with-identity.ts +5 -5
  362. package/examples/run-agent/run-agent-with-model.ts +5 -5
  363. package/examples/run-agent/run-agent-with-slack.ts +5 -5
  364. package/examples/run-agent/run-agent-with-tools.ts +5 -5
  365. package/examples/run-agent/run-agent-with-usage-limit-stop.ts +5 -5
  366. package/examples/run-agent/run-agent-with-usage-limit.ts +5 -5
  367. package/examples/tools/basic-tool.ts +1 -1
  368. package/examples/tools/web-search-tool.ts +1 -1
  369. package/examples/usage/get-chat-usage.ts +4 -4
  370. package/examples/usage/get-message-usage.ts +4 -4
  371. package/examples/usage/get-usage-stats-by-range.ts +4 -4
  372. package/examples/usage/get-usage-stats.ts +4 -4
  373. package/examples/users/set-default-model.ts +12 -21
  374. package/package.json +5 -20
  375. package/dist/common/base/base.app.d.ts +0 -12
  376. package/dist/common/base/base.app.js +0 -57
  377. package/dist/common/base/base.app.mjs +0 -33
  378. package/dist/common/base/base.entity.d.ts +0 -38
  379. package/dist/common/base/base.entity.js +0 -100
  380. package/dist/common/base/base.entity.mjs +0 -76
  381. package/dist/common/base/base.use-case.d.ts +0 -11
  382. package/dist/common/base/base.use-case.js +0 -30
  383. package/dist/common/base/base.use-case.mjs +0 -6
  384. package/dist/common/base/current-session.d.ts +0 -129
  385. package/dist/common/base/current-session.js +0 -123
  386. package/dist/common/base/current-session.mjs +0 -98
  387. package/dist/common/base/current-user.d.ts +0 -16
  388. package/dist/common/base/current-user.js +0 -85
  389. package/dist/common/base/current-user.mjs +0 -61
  390. package/dist/common/base/index.d.ts +0 -3
  391. package/dist/common/base/index.js +0 -26
  392. package/dist/common/base/index.mjs +0 -3
  393. package/dist/common/base/share.d.ts +0 -12
  394. package/dist/common/base/share.js +0 -45
  395. package/dist/common/base/share.mjs +0 -20
  396. package/dist/common/base/utils/index.d.ts +0 -2
  397. package/dist/common/base/utils/index.js +0 -24
  398. package/dist/common/base/utils/index.mjs +0 -2
  399. package/dist/common/base/utils/is-plain-object.d.ts +0 -1
  400. package/dist/common/base/utils/is-plain-object.js +0 -32
  401. package/dist/common/base/utils/is-plain-object.mjs +0 -8
  402. package/dist/common/base/utils/to-patch.d.ts +0 -9
  403. package/dist/common/base/utils/to-patch.js +0 -46
  404. package/dist/common/base/utils/to-patch.mjs +0 -21
  405. package/dist/common/error/error-reporter.d.ts +0 -11
  406. package/dist/common/error/error-reporter.mjs +0 -11
  407. package/dist/common/error/http-error.d.ts +0 -11
  408. package/dist/common/error/http-error.js +0 -37
  409. package/dist/common/error/http-error.mjs +0 -13
  410. package/dist/common/error/index.d.ts +0 -3
  411. package/dist/common/error/index.js +0 -26
  412. package/dist/common/error/index.mjs +0 -3
  413. package/dist/common/error/reportError.d.ts +0 -2
  414. package/dist/common/error/reportError.js +0 -61
  415. package/dist/common/error/reportError.mjs +0 -37
  416. package/dist/common/error/sentry-client.d.ts +0 -10
  417. package/dist/common/error/sentry-client.js +0 -82
  418. package/dist/common/error/sentry-client.mjs +0 -57
  419. package/dist/common/index.d.ts +0 -6
  420. package/dist/common/index.js +0 -37
  421. package/dist/common/index.mjs +0 -9
  422. package/dist/common/logger/index.d.ts +0 -1
  423. package/dist/common/logger/index.mjs +0 -1
  424. package/dist/common/logger/pino.d.ts +0 -12
  425. package/dist/common/logger/pino.js +0 -79
  426. package/dist/common/logger/pino.mjs +0 -44
  427. package/dist/common/repositories/index.d.ts +0 -3
  428. package/dist/common/repositories/index.js +0 -26
  429. package/dist/common/repositories/index.mjs +0 -3
  430. package/dist/common/repositories/mongo-db.client.d.ts +0 -11
  431. package/dist/common/repositories/mongo-db.client.js +0 -83
  432. package/dist/common/repositories/mongo-db.client.mjs +0 -60
  433. package/dist/common/repositories/mongo-db.repository.d.ts +0 -130
  434. package/dist/common/repositories/mongo-db.repository.js +0 -357
  435. package/dist/common/repositories/mongo-db.repository.mjs +0 -332
  436. package/dist/common/repositories/scope.d.ts +0 -19
  437. package/dist/common/repositories/scope.js +0 -63
  438. package/dist/common/repositories/scope.mjs +0 -39
  439. package/dist/common/utils/config-context.d.ts +0 -3
  440. package/dist/common/utils/config-context.js +0 -33
  441. package/dist/common/utils/config-context.mjs +0 -8
  442. package/dist/common/utils/database-name.d.ts +0 -2
  443. package/dist/common/utils/database-name.js +0 -32
  444. package/dist/common/utils/database-name.mjs +0 -7
  445. package/dist/common/utils/secret-manager.d.ts +0 -17
  446. package/dist/common/utils/secret-manager.js +0 -124
  447. package/dist/common/utils/secret-manager.mjs +0 -89
  448. package/dist/db/indexes/refresh-tokens.d.ts +0 -2
  449. package/dist/db/indexes/refresh-tokens.js +0 -33
  450. package/dist/db/indexes/refresh-tokens.mjs +0 -9
  451. package/dist/db/indexes/revoked-tokens.d.ts +0 -2
  452. package/dist/db/indexes/revoked-tokens.js +0 -31
  453. package/dist/db/indexes/revoked-tokens.mjs +0 -7
  454. package/dist/services/authentication/entities/index.d.ts +0 -2
  455. package/dist/services/authentication/entities/index.js +0 -24
  456. package/dist/services/authentication/entities/index.mjs +0 -2
  457. package/dist/services/authentication/entities/refresh-token.entity.d.ts +0 -25
  458. package/dist/services/authentication/entities/refresh-token.entity.js +0 -75
  459. package/dist/services/authentication/entities/refresh-token.entity.mjs +0 -51
  460. package/dist/services/authentication/entities/revoked-token.entity.d.ts +0 -17
  461. package/dist/services/authentication/entities/revoked-token.entity.js +0 -67
  462. package/dist/services/authentication/entities/revoked-token.entity.mjs +0 -43
  463. package/dist/services/authentication/helpers/auth-config.d.ts +0 -9
  464. package/dist/services/authentication/helpers/auth-config.js +0 -36
  465. package/dist/services/authentication/helpers/auth-config.mjs +0 -12
  466. package/dist/services/authentication/helpers/session-tokens.d.ts +0 -16
  467. package/dist/services/authentication/helpers/session-tokens.js +0 -60
  468. package/dist/services/authentication/helpers/session-tokens.mjs +0 -35
  469. package/dist/services/authentication/helpers/tokens.d.ts +0 -43
  470. package/dist/services/authentication/helpers/tokens.js +0 -113
  471. package/dist/services/authentication/helpers/tokens.mjs +0 -71
  472. package/dist/services/authentication/index.d.ts +0 -5
  473. package/dist/services/authentication/index.js +0 -47
  474. package/dist/services/authentication/index.mjs +0 -13
  475. package/dist/services/authentication/module.d.ts +0 -16
  476. package/dist/services/authentication/module.js +0 -81
  477. package/dist/services/authentication/module.mjs +0 -50
  478. package/dist/services/authentication/repositories/index.d.ts +0 -2
  479. package/dist/services/authentication/repositories/index.js +0 -24
  480. package/dist/services/authentication/repositories/index.mjs +0 -2
  481. package/dist/services/authentication/repositories/refresh-token.repository.d.ts +0 -10
  482. package/dist/services/authentication/repositories/refresh-token.repository.js +0 -60
  483. package/dist/services/authentication/repositories/refresh-token.repository.mjs +0 -36
  484. package/dist/services/authentication/repositories/revoked-token.repository.d.ts +0 -7
  485. package/dist/services/authentication/repositories/revoked-token.repository.js +0 -44
  486. package/dist/services/authentication/repositories/revoked-token.repository.mjs +0 -20
  487. package/dist/services/authentication/use-cases/claim-refresh-token.use-case.d.ts +0 -12
  488. package/dist/services/authentication/use-cases/claim-refresh-token.use-case.js +0 -40
  489. package/dist/services/authentication/use-cases/claim-refresh-token.use-case.mjs +0 -16
  490. package/dist/services/authentication/use-cases/create-refresh-token.use-case.d.ts +0 -11
  491. package/dist/services/authentication/use-cases/create-refresh-token.use-case.js +0 -43
  492. package/dist/services/authentication/use-cases/create-refresh-token.use-case.mjs +0 -19
  493. package/dist/services/authentication/use-cases/find-refresh-token-by-hash.use-case.d.ts +0 -11
  494. package/dist/services/authentication/use-cases/find-refresh-token-by-hash.use-case.js +0 -40
  495. package/dist/services/authentication/use-cases/find-refresh-token-by-hash.use-case.mjs +0 -16
  496. package/dist/services/authentication/use-cases/is-token-revoked.use-case.d.ts +0 -13
  497. package/dist/services/authentication/use-cases/is-token-revoked.use-case.js +0 -42
  498. package/dist/services/authentication/use-cases/is-token-revoked.use-case.mjs +0 -18
  499. package/dist/services/authentication/use-cases/issue-password-reset-token.use-case.d.ts +0 -18
  500. package/dist/services/authentication/use-cases/issue-password-reset-token.use-case.js +0 -49
  501. package/dist/services/authentication/use-cases/issue-password-reset-token.use-case.mjs +0 -25
  502. package/dist/services/authentication/use-cases/issue-session.use-case.d.ts +0 -13
  503. package/dist/services/authentication/use-cases/issue-session.use-case.js +0 -48
  504. package/dist/services/authentication/use-cases/issue-session.use-case.mjs +0 -24
  505. package/dist/services/authentication/use-cases/login.use-case.d.ts +0 -20
  506. package/dist/services/authentication/use-cases/login.use-case.js +0 -54
  507. package/dist/services/authentication/use-cases/login.use-case.mjs +0 -30
  508. package/dist/services/authentication/use-cases/logout.use-case.d.ts +0 -14
  509. package/dist/services/authentication/use-cases/logout.use-case.js +0 -48
  510. package/dist/services/authentication/use-cases/logout.use-case.mjs +0 -24
  511. package/dist/services/authentication/use-cases/refresh.use-case.d.ts +0 -23
  512. package/dist/services/authentication/use-cases/refresh.use-case.js +0 -84
  513. package/dist/services/authentication/use-cases/refresh.use-case.mjs +0 -60
  514. package/dist/services/authentication/use-cases/reset-password.use-case.d.ts +0 -15
  515. package/dist/services/authentication/use-cases/reset-password.use-case.js +0 -61
  516. package/dist/services/authentication/use-cases/reset-password.use-case.mjs +0 -37
  517. package/dist/services/authentication/use-cases/revoke-refresh-token-family.use-case.d.ts +0 -11
  518. package/dist/services/authentication/use-cases/revoke-refresh-token-family.use-case.js +0 -40
  519. package/dist/services/authentication/use-cases/revoke-refresh-token-family.use-case.mjs +0 -16
  520. package/dist/services/authentication/use-cases/revoke-token.use-case.d.ts +0 -12
  521. package/dist/services/authentication/use-cases/revoke-token.use-case.js +0 -52
  522. package/dist/services/authentication/use-cases/revoke-token.use-case.mjs +0 -28
  523. package/dist/services/authentication/use-cases/revoke-user-refresh-tokens.use-case.d.ts +0 -13
  524. package/dist/services/authentication/use-cases/revoke-user-refresh-tokens.use-case.js +0 -40
  525. package/dist/services/authentication/use-cases/revoke-user-refresh-tokens.use-case.mjs +0 -16
  526. package/dist/services/users/entities/index.d.ts +0 -1
  527. package/dist/services/users/entities/index.js +0 -22
  528. package/dist/services/users/entities/index.mjs +0 -1
  529. package/dist/services/users/entities/user-acquisition.d.ts +0 -12
  530. package/dist/services/users/entities/user-acquisition.js +0 -42
  531. package/dist/services/users/entities/user-acquisition.mjs +0 -18
  532. package/dist/services/users/entities/user-country.d.ts +0 -11
  533. package/dist/services/users/entities/user-country.js +0 -44
  534. package/dist/services/users/entities/user-country.mjs +0 -20
  535. package/dist/services/users/entities/user-currency.d.ts +0 -13
  536. package/dist/services/users/entities/user-currency.js +0 -44
  537. package/dist/services/users/entities/user-currency.mjs +0 -20
  538. package/dist/services/users/entities/user-default-model.d.ts +0 -11
  539. package/dist/services/users/entities/user-default-model.js +0 -42
  540. package/dist/services/users/entities/user-default-model.mjs +0 -18
  541. package/dist/services/users/entities/user-email.value-object.d.ts +0 -6
  542. package/dist/services/users/entities/user-email.value-object.js +0 -43
  543. package/dist/services/users/entities/user-email.value-object.mjs +0 -19
  544. package/dist/services/users/entities/user-language.d.ts +0 -11
  545. package/dist/services/users/entities/user-language.js +0 -44
  546. package/dist/services/users/entities/user-language.mjs +0 -20
  547. package/dist/services/users/entities/user-marketing.d.ts +0 -9
  548. package/dist/services/users/entities/user-marketing.js +0 -40
  549. package/dist/services/users/entities/user-marketing.mjs +0 -16
  550. package/dist/services/users/entities/user-notification-preferences.d.ts +0 -11
  551. package/dist/services/users/entities/user-notification-preferences.js +0 -41
  552. package/dist/services/users/entities/user-notification-preferences.mjs +0 -17
  553. package/dist/services/users/entities/user-password.value-object.d.ts +0 -8
  554. package/dist/services/users/entities/user-password.value-object.js +0 -69
  555. package/dist/services/users/entities/user-password.value-object.mjs +0 -35
  556. package/dist/services/users/entities/user-permissions.d.ts +0 -21
  557. package/dist/services/users/entities/user-permissions.js +0 -59
  558. package/dist/services/users/entities/user-permissions.mjs +0 -35
  559. package/dist/services/users/entities/user-preferences.d.ts +0 -28
  560. package/dist/services/users/entities/user-preferences.js +0 -74
  561. package/dist/services/users/entities/user-preferences.mjs +0 -50
  562. package/dist/services/users/entities/user-report-preferences.d.ts +0 -16
  563. package/dist/services/users/entities/user-report-preferences.js +0 -56
  564. package/dist/services/users/entities/user-report-preferences.mjs +0 -32
  565. package/dist/services/users/entities/user-report-schedule.d.ts +0 -11
  566. package/dist/services/users/entities/user-report-schedule.js +0 -41
  567. package/dist/services/users/entities/user-report-schedule.mjs +0 -17
  568. package/dist/services/users/entities/user-timezone.d.ts +0 -11
  569. package/dist/services/users/entities/user-timezone.js +0 -44
  570. package/dist/services/users/entities/user-timezone.mjs +0 -20
  571. package/dist/services/users/entities/user.entity.d.ts +0 -42
  572. package/dist/services/users/entities/user.entity.js +0 -117
  573. package/dist/services/users/entities/user.entity.mjs +0 -92
  574. package/dist/services/users/index.d.ts +0 -3
  575. package/dist/services/users/index.js +0 -26
  576. package/dist/services/users/index.mjs +0 -3
  577. package/dist/services/users/module.d.ts +0 -12
  578. package/dist/services/users/module.js +0 -67
  579. package/dist/services/users/module.mjs +0 -38
  580. package/dist/services/users/repositories/index.d.ts +0 -1
  581. package/dist/services/users/repositories/index.js +0 -22
  582. package/dist/services/users/repositories/index.mjs +0 -1
  583. package/dist/services/users/repositories/user.repository.d.ts +0 -18
  584. package/dist/services/users/repositories/user.repository.js +0 -88
  585. package/dist/services/users/repositories/user.repository.mjs +0 -64
  586. package/dist/services/users/use-cases/change-password.use-case.d.ts +0 -15
  587. package/dist/services/users/use-cases/change-password.use-case.js +0 -52
  588. package/dist/services/users/use-cases/change-password.use-case.mjs +0 -28
  589. package/dist/services/users/use-cases/create-user.use-case.d.ts +0 -12
  590. package/dist/services/users/use-cases/create-user.use-case.js +0 -49
  591. package/dist/services/users/use-cases/create-user.use-case.mjs +0 -25
  592. package/dist/services/users/use-cases/delete-user.use-case.d.ts +0 -16
  593. package/dist/services/users/use-cases/delete-user.use-case.js +0 -48
  594. package/dist/services/users/use-cases/delete-user.use-case.mjs +0 -24
  595. package/dist/services/users/use-cases/get-user-by-id.use-case.d.ts +0 -12
  596. package/dist/services/users/use-cases/get-user-by-id.use-case.js +0 -43
  597. package/dist/services/users/use-cases/get-user-by-id.use-case.mjs +0 -19
  598. package/dist/services/users/use-cases/list-users-by-props.use-case.d.ts +0 -17
  599. package/dist/services/users/use-cases/list-users-by-props.use-case.js +0 -42
  600. package/dist/services/users/use-cases/list-users-by-props.use-case.mjs +0 -18
  601. package/dist/services/users/use-cases/update-user.use-case.d.ts +0 -13
  602. package/dist/services/users/use-cases/update-user.use-case.js +0 -53
  603. package/dist/services/users/use-cases/update-user.use-case.mjs +0 -29
  604. package/dist/services/users/utils/default-model.d.ts +0 -6
  605. package/dist/services/users/utils/default-model.js +0 -38
  606. package/dist/services/users/utils/default-model.mjs +0 -14
  607. package/examples/authentication/login.ts +0 -22
  608. package/examples/users/create-user.ts +0 -25
  609. package/examples/users/delete-user.ts +0 -42
  610. package/examples/users/get-user-by-id.ts +0 -21
  611. package/examples/users/list-users.ts +0 -22
  612. package/examples/users/update-user.ts +0 -25
@@ -1,357 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var mongo_db_repository_exports = {};
20
- __export(mongo_db_repository_exports, {
21
- MongoRepository: () => MongoRepository,
22
- VersionConflictError: () => VersionConflictError
23
- });
24
- module.exports = __toCommonJS(mongo_db_repository_exports);
25
- var import_mongodb = require("mongodb");
26
- var import_error = require("../error/index.js");
27
- var import_mongo_db = require("./mongo-db.client");
28
- const DEFAULT_LIMIT = 10;
29
- const PROTECTED_FIELDS = ["__v", "ownerId", "sharedWith", "createdAt", "createdBy", "updatedAt", "updatedBy", "deletedAt", "deletedBy", "archivedAt", "archivedBy"];
30
- const IMMUTABLE_FIELDS = ["_id", "__v", "createdAt", "createdBy"];
31
- class VersionConflictError extends Error {
32
- code = "VERSION_CONFLICT";
33
- statusCode = 409;
34
- constructor(message = "[Mongo Repository] The document was modified by someone else, reload and try again") {
35
- super(message);
36
- this.name = "VersionConflictError";
37
- }
38
- }
39
- class MongoRepository {
40
- database;
41
- collection;
42
- envvar;
43
- _where = { deletedAt: null, archivedAt: null };
44
- scoped;
45
- ownerField;
46
- protectedFields;
47
- report = (error) => (0, import_error.reportError)(error, { source: "mongo", collection: this.collection });
48
- constructor(props) {
49
- const { database, collection, envvar, scoped = false, ownerField = "ownerId", protectedFields = [] } = props || {};
50
- if (!database) throw new Error("[Mongo Repository] Database name is required");
51
- if (!collection) throw new Error("[Mongo Repository] Collection name is required");
52
- this.envvar = envvar;
53
- this.database = database;
54
- this.collection = collection;
55
- this.scoped = scoped;
56
- this.ownerField = ownerField;
57
- this.protectedFields = [...PROTECTED_FIELDS, ...protectedFields];
58
- }
59
- async db() {
60
- const client = (0, import_mongo_db.getMongoDBClient)(this.envvar);
61
- if (!client) throw new Error("[Mongo Repository] Database client not found");
62
- return client.db(typeof this.database === "function" ? this.database() : this.database);
63
- }
64
- assertScope(scope) {
65
- if (!scope && this.scoped) throw new Error(`[Mongo Repository] Scope is required in ${this.collection}`);
66
- }
67
- actorId(scope) {
68
- if (!scope || scope.kind === "system") return void 0;
69
- const userId = this.parseId(scope.userId);
70
- if (!userId) throw new Error("[Mongo Repository] Invalid user id in scope");
71
- return userId;
72
- }
73
- withScope(filter, scope) {
74
- this.assertScope(scope);
75
- if (!scope || scope.trusted) return filter;
76
- return { $and: [filter, { [this.ownerField]: this.actorId(scope) }] };
77
- }
78
- stampCreate(payload, scope) {
79
- this.assertScope(scope);
80
- if (!scope) return { ...payload };
81
- const actor = this.actorId(scope);
82
- return {
83
- ...this.withoutProtected(payload, scope),
84
- ...scope.trusted || this.ownerField === "_id" ? {} : { [this.ownerField]: actor },
85
- createdAt: /* @__PURE__ */ new Date(),
86
- ...actor ? { createdBy: actor } : {}
87
- };
88
- }
89
- withoutProtected(payload, scope) {
90
- if (!scope || scope.trusted) return payload;
91
- const kept = Object.fromEntries(Object.entries(payload).filter(([key]) => !this.protectedFields.includes(key)));
92
- return this.protectedFields.filter((path) => path.includes(".")).reduce((result, path) => this.withoutPath(result, path.split(".")), kept);
93
- }
94
- withoutPath(node, path) {
95
- const [head, ...rest] = path;
96
- if (!(head in node)) return node;
97
- if (!rest.length) {
98
- const { [head]: removed, ...others2 } = node;
99
- return others2;
100
- }
101
- const child = node[head];
102
- if (!child || typeof child !== "object" || Array.isArray(child) || child instanceof Date || child instanceof import_mongodb.ObjectId) return node;
103
- const cleaned = this.withoutPath(child, rest);
104
- if (Object.keys(cleaned).length) return { ...node, [head]: cleaned };
105
- const { [head]: dropped, ...others } = node;
106
- return others;
107
- }
108
- parseId(id) {
109
- return typeof id === "string" && import_mongodb.ObjectId.isValid(id) ? new import_mongodb.ObjectId(id) : void 0;
110
- }
111
- cleanInput(value) {
112
- return value?.replace(/[{}[\]()\/\\]/g, "");
113
- }
114
- clampLimit(limit) {
115
- const n = Number(limit);
116
- return !Number.isFinite(n) || n <= 0 ? DEFAULT_LIMIT : n;
117
- }
118
- async findOne({ where, select, options, scope }) {
119
- const filter = this.withScope({ ...where, ...this._where }, scope);
120
- try {
121
- const db = await this.db();
122
- const collection = db.collection(this.collection);
123
- const result = await collection.findOne(
124
- filter,
125
- {
126
- ...select ? { projection: select } : {},
127
- ...options
128
- }
129
- );
130
- return result;
131
- } catch (error) {
132
- await this.report(error);
133
- throw error;
134
- }
135
- }
136
- async findMany(params) {
137
- const _limit = this.clampLimit(params.options?.limit);
138
- return this.query(params, _limit, _limit);
139
- }
140
- async findManyPaginated(params) {
141
- const _limit = this.clampLimit(params.options?.limit);
142
- const results = await this.query(params, _limit, _limit + 1);
143
- return { items: results.slice(0, _limit), hasMore: results.length > _limit };
144
- }
145
- async query({ where, select, options, scope }, pageSize, fetchSize) {
146
- const filter = this.withScope({ ...where, ...this._where }, scope);
147
- try {
148
- const db = await this.db();
149
- const collection = db.collection(this.collection);
150
- const { page = 1 } = options || {};
151
- const _skip = +page > 0 ? (+page - 1) * pageSize : 0;
152
- const result = await collection.find(filter, { projection: select }).sort(options?.sortBy || { _id: -1 }).skip(_skip).limit(fetchSize).toArray();
153
- return result;
154
- } catch (error) {
155
- await this.report(error);
156
- throw error;
157
- }
158
- }
159
- async findAll({ where, select, options, scope }) {
160
- const filter = this.withScope({ ...where, ...this._where }, scope);
161
- try {
162
- const db = await this.db();
163
- const collection = db.collection(this.collection);
164
- const cursor = collection.find(filter, { projection: select });
165
- const result = await (options?.sortBy ? cursor.sort(options.sortBy) : cursor).toArray();
166
- return result;
167
- } catch (error) {
168
- await this.report(error);
169
- throw error;
170
- }
171
- }
172
- async createOne({ payload, scope }) {
173
- if (!payload || Object.keys(payload).length === 0) throw new Error("[Mongo Repository] Payload is required for createOne operation");
174
- const document = this.stampCreate(payload, scope);
175
- try {
176
- const db = await this.db();
177
- const collection = db.collection(this.collection);
178
- const { insertedId } = await collection.insertOne({ ...document, __v: 1 }, { ignoreUndefined: true });
179
- return { ...document, _id: insertedId, __v: 1 };
180
- } catch (error) {
181
- await this.report(error);
182
- throw error;
183
- }
184
- }
185
- async createMany({ payload, scope }) {
186
- const documents = payload.map((item) => this.stampCreate(item, scope));
187
- try {
188
- const db = await this.db();
189
- const collection = db.collection(this.collection);
190
- const { insertedIds } = await collection.insertMany(documents.map((document) => ({ ...document, __v: 1 })), { ignoreUndefined: true });
191
- return insertedIds;
192
- } catch (error) {
193
- await this.report(error);
194
- throw error;
195
- }
196
- }
197
- async patchOne({ where, set, unset, expectedVersion, scope }) {
198
- return this.applyPatch({ where, set, unset, expectedVersion, scope });
199
- }
200
- async archiveByPatch(params) {
201
- const actor = this.actorId(params.scope);
202
- return this.applyPatch(params, { archivedAt: /* @__PURE__ */ new Date(), ...actor ? { archivedBy: actor } : {} });
203
- }
204
- async applyPatch({ where, set, unset, expectedVersion, scope }, stamps = {}) {
205
- if (!where || Object.keys(where).length === 0) throw new Error("[Mongo Repository] Where is required for patchOne operation");
206
- const actor = this.actorId(scope);
207
- const toSet = {
208
- ...this.withoutProtectedPaths(set ?? {}, scope),
209
- ...scope ? { updatedAt: /* @__PURE__ */ new Date(), ...actor ? { updatedBy: actor } : {} } : {},
210
- ...stamps
211
- };
212
- const toUnset = this.withoutProtectedPaths(unset ?? {}, scope);
213
- return this.modifyOne(where, {
214
- $set: toSet,
215
- ...Object.keys(toUnset).length ? { $unset: toUnset } : {}
216
- }, scope, expectedVersion);
217
- }
218
- async claimOne({ where, set, scope }) {
219
- const filter = this.withScope({ ...where, ...this._where }, scope);
220
- try {
221
- const db = await this.db();
222
- const collection = db.collection(this.collection);
223
- const result = await collection.findOneAndUpdate(
224
- filter,
225
- { $set: this.withoutProtectedPaths(set ?? {}, scope) },
226
- { returnDocument: "before", ignoreUndefined: true }
227
- );
228
- return result;
229
- } catch (error) {
230
- await this.report(error);
231
- throw error;
232
- }
233
- }
234
- withoutProtectedPaths(fields, scope) {
235
- const guarded = scope && !scope.trusted;
236
- const isProtected = (key) => this.protectedFields.some((field) => key === field || key.startsWith(`${field}.`) || field.startsWith(`${key}.`));
237
- return Object.fromEntries(Object.entries(fields).filter(([key]) => !IMMUTABLE_FIELDS.includes(key) && !(guarded && isProtected(key))));
238
- }
239
- async softDelete({ where, payload, unset, scope }) {
240
- if (!where || Object.keys(where).length === 0) throw new Error("[Mongo Repository] Where is required for softDelete operation");
241
- const actor = this.actorId(scope);
242
- const extra = this.withoutProtected(payload ?? {}, scope);
243
- const toUnset = this.withoutProtectedPaths(unset ?? {}, scope);
244
- return this.modifyOne(where, {
245
- $set: { ...extra, deletedAt: /* @__PURE__ */ new Date(), ...actor ? { deletedBy: actor } : {} },
246
- ...Object.keys(toUnset).length ? { $unset: toUnset } : {}
247
- }, scope);
248
- }
249
- async modifyOne(where, update, scope, expectedVersion) {
250
- const checkVersion = typeof expectedVersion === "number";
251
- const filter = this.withScope({ ...where, ...checkVersion ? { __v: expectedVersion } : {}, ...this._where }, scope);
252
- try {
253
- const db = await this.db();
254
- const collection = db.collection(this.collection);
255
- const result = await collection.findOneAndUpdate(
256
- filter,
257
- { $inc: { __v: 1 }, ...update },
258
- { returnDocument: "after", ignoreUndefined: true }
259
- );
260
- if (!result && checkVersion) {
261
- const exists = await collection.findOne(this.withScope({ ...where, ...this._where }, scope), { projection: { _id: 1 } });
262
- if (exists) throw new VersionConflictError();
263
- }
264
- return result;
265
- } catch (error) {
266
- if (!(error instanceof VersionConflictError)) await this.report(error);
267
- throw error;
268
- }
269
- }
270
- async updateMany({ where, payload, scope }) {
271
- const filter = this.withScope({ ...where, ...this._where }, scope);
272
- const actor = this.actorId(scope);
273
- const toSet = {
274
- ...this.withoutProtected(payload ?? {}, scope),
275
- ...scope ? { updatedAt: /* @__PURE__ */ new Date(), ...actor ? { updatedBy: actor } : {} } : {}
276
- };
277
- try {
278
- const db = await this.db();
279
- const collection = db.collection(this.collection);
280
- const result = await collection.updateMany(
281
- filter,
282
- { $set: toSet }
283
- );
284
- const countUpdated = result.modifiedCount;
285
- return countUpdated;
286
- } catch (error) {
287
- await this.report(error);
288
- throw error;
289
- }
290
- }
291
- async deleteOne({ where, scope }) {
292
- const filter = this.withScope({ ...where }, scope);
293
- try {
294
- const db = await this.db();
295
- const collection = db.collection(this.collection);
296
- const { deletedCount } = await collection.deleteOne(filter);
297
- return deletedCount;
298
- } catch (error) {
299
- await this.report(error);
300
- throw error;
301
- }
302
- }
303
- async deleteMany({ where, scope }) {
304
- const filter = this.withScope({ ...where }, scope);
305
- try {
306
- const db = await this.db();
307
- const collection = db.collection(this.collection);
308
- const { deletedCount } = await collection.deleteMany(filter);
309
- return deletedCount;
310
- } catch (error) {
311
- await this.report(error);
312
- throw error;
313
- }
314
- }
315
- async count({ where, options, scope }) {
316
- const filter = this.withScope({ ...where, ...options?.includeDeleted ? {} : this._where }, scope);
317
- try {
318
- const db = await this.db();
319
- const collection = db.collection(this.collection);
320
- const result = await collection.countDocuments(filter);
321
- return result;
322
- } catch (error) {
323
- await this.report(error);
324
- throw error;
325
- }
326
- }
327
- async aggregate(pipeline, scope) {
328
- const scopeFilter = this.withScope({}, scope);
329
- const scopedPipeline = Object.keys(scopeFilter).length ? [{ $match: scopeFilter }, ...pipeline] : pipeline;
330
- try {
331
- const db = await this.db();
332
- const collection = db.collection(this.collection);
333
- const result = await collection.aggregate(scopedPipeline).toArray();
334
- return result;
335
- } catch (error) {
336
- await this.report(error);
337
- throw error;
338
- }
339
- }
340
- async distinct(field, where, scope) {
341
- const filter = this.withScope({ ...where, ...this._where }, scope);
342
- try {
343
- const db = await this.db();
344
- const collection = db.collection(this.collection);
345
- const result = await collection.distinct(field, filter);
346
- return result;
347
- } catch (error) {
348
- await this.report(error);
349
- throw error;
350
- }
351
- }
352
- }
353
- // Annotate the CommonJS export names for ESM import in node:
354
- 0 && (module.exports = {
355
- MongoRepository,
356
- VersionConflictError
357
- });
@@ -1,332 +0,0 @@
1
- import { ObjectId } from "mongodb";
2
- import { reportError } from "../error/index.js";
3
- import { getMongoDBClient } from "./mongo-db.client";
4
- const DEFAULT_LIMIT = 10;
5
- const PROTECTED_FIELDS = ["__v", "ownerId", "sharedWith", "createdAt", "createdBy", "updatedAt", "updatedBy", "deletedAt", "deletedBy", "archivedAt", "archivedBy"];
6
- const IMMUTABLE_FIELDS = ["_id", "__v", "createdAt", "createdBy"];
7
- class VersionConflictError extends Error {
8
- code = "VERSION_CONFLICT";
9
- statusCode = 409;
10
- constructor(message = "[Mongo Repository] The document was modified by someone else, reload and try again") {
11
- super(message);
12
- this.name = "VersionConflictError";
13
- }
14
- }
15
- class MongoRepository {
16
- database;
17
- collection;
18
- envvar;
19
- _where = { deletedAt: null, archivedAt: null };
20
- scoped;
21
- ownerField;
22
- protectedFields;
23
- report = (error) => reportError(error, { source: "mongo", collection: this.collection });
24
- constructor(props) {
25
- const { database, collection, envvar, scoped = false, ownerField = "ownerId", protectedFields = [] } = props || {};
26
- if (!database) throw new Error("[Mongo Repository] Database name is required");
27
- if (!collection) throw new Error("[Mongo Repository] Collection name is required");
28
- this.envvar = envvar;
29
- this.database = database;
30
- this.collection = collection;
31
- this.scoped = scoped;
32
- this.ownerField = ownerField;
33
- this.protectedFields = [...PROTECTED_FIELDS, ...protectedFields];
34
- }
35
- async db() {
36
- const client = getMongoDBClient(this.envvar);
37
- if (!client) throw new Error("[Mongo Repository] Database client not found");
38
- return client.db(typeof this.database === "function" ? this.database() : this.database);
39
- }
40
- assertScope(scope) {
41
- if (!scope && this.scoped) throw new Error(`[Mongo Repository] Scope is required in ${this.collection}`);
42
- }
43
- actorId(scope) {
44
- if (!scope || scope.kind === "system") return void 0;
45
- const userId = this.parseId(scope.userId);
46
- if (!userId) throw new Error("[Mongo Repository] Invalid user id in scope");
47
- return userId;
48
- }
49
- withScope(filter, scope) {
50
- this.assertScope(scope);
51
- if (!scope || scope.trusted) return filter;
52
- return { $and: [filter, { [this.ownerField]: this.actorId(scope) }] };
53
- }
54
- stampCreate(payload, scope) {
55
- this.assertScope(scope);
56
- if (!scope) return { ...payload };
57
- const actor = this.actorId(scope);
58
- return {
59
- ...this.withoutProtected(payload, scope),
60
- ...scope.trusted || this.ownerField === "_id" ? {} : { [this.ownerField]: actor },
61
- createdAt: /* @__PURE__ */ new Date(),
62
- ...actor ? { createdBy: actor } : {}
63
- };
64
- }
65
- withoutProtected(payload, scope) {
66
- if (!scope || scope.trusted) return payload;
67
- const kept = Object.fromEntries(Object.entries(payload).filter(([key]) => !this.protectedFields.includes(key)));
68
- return this.protectedFields.filter((path) => path.includes(".")).reduce((result, path) => this.withoutPath(result, path.split(".")), kept);
69
- }
70
- withoutPath(node, path) {
71
- const [head, ...rest] = path;
72
- if (!(head in node)) return node;
73
- if (!rest.length) {
74
- const { [head]: removed, ...others2 } = node;
75
- return others2;
76
- }
77
- const child = node[head];
78
- if (!child || typeof child !== "object" || Array.isArray(child) || child instanceof Date || child instanceof ObjectId) return node;
79
- const cleaned = this.withoutPath(child, rest);
80
- if (Object.keys(cleaned).length) return { ...node, [head]: cleaned };
81
- const { [head]: dropped, ...others } = node;
82
- return others;
83
- }
84
- parseId(id) {
85
- return typeof id === "string" && ObjectId.isValid(id) ? new ObjectId(id) : void 0;
86
- }
87
- cleanInput(value) {
88
- return value?.replace(/[{}[\]()\/\\]/g, "");
89
- }
90
- clampLimit(limit) {
91
- const n = Number(limit);
92
- return !Number.isFinite(n) || n <= 0 ? DEFAULT_LIMIT : n;
93
- }
94
- async findOne({ where, select, options, scope }) {
95
- const filter = this.withScope({ ...where, ...this._where }, scope);
96
- try {
97
- const db = await this.db();
98
- const collection = db.collection(this.collection);
99
- const result = await collection.findOne(
100
- filter,
101
- {
102
- ...select ? { projection: select } : {},
103
- ...options
104
- }
105
- );
106
- return result;
107
- } catch (error) {
108
- await this.report(error);
109
- throw error;
110
- }
111
- }
112
- async findMany(params) {
113
- const _limit = this.clampLimit(params.options?.limit);
114
- return this.query(params, _limit, _limit);
115
- }
116
- async findManyPaginated(params) {
117
- const _limit = this.clampLimit(params.options?.limit);
118
- const results = await this.query(params, _limit, _limit + 1);
119
- return { items: results.slice(0, _limit), hasMore: results.length > _limit };
120
- }
121
- async query({ where, select, options, scope }, pageSize, fetchSize) {
122
- const filter = this.withScope({ ...where, ...this._where }, scope);
123
- try {
124
- const db = await this.db();
125
- const collection = db.collection(this.collection);
126
- const { page = 1 } = options || {};
127
- const _skip = +page > 0 ? (+page - 1) * pageSize : 0;
128
- const result = await collection.find(filter, { projection: select }).sort(options?.sortBy || { _id: -1 }).skip(_skip).limit(fetchSize).toArray();
129
- return result;
130
- } catch (error) {
131
- await this.report(error);
132
- throw error;
133
- }
134
- }
135
- async findAll({ where, select, options, scope }) {
136
- const filter = this.withScope({ ...where, ...this._where }, scope);
137
- try {
138
- const db = await this.db();
139
- const collection = db.collection(this.collection);
140
- const cursor = collection.find(filter, { projection: select });
141
- const result = await (options?.sortBy ? cursor.sort(options.sortBy) : cursor).toArray();
142
- return result;
143
- } catch (error) {
144
- await this.report(error);
145
- throw error;
146
- }
147
- }
148
- async createOne({ payload, scope }) {
149
- if (!payload || Object.keys(payload).length === 0) throw new Error("[Mongo Repository] Payload is required for createOne operation");
150
- const document = this.stampCreate(payload, scope);
151
- try {
152
- const db = await this.db();
153
- const collection = db.collection(this.collection);
154
- const { insertedId } = await collection.insertOne({ ...document, __v: 1 }, { ignoreUndefined: true });
155
- return { ...document, _id: insertedId, __v: 1 };
156
- } catch (error) {
157
- await this.report(error);
158
- throw error;
159
- }
160
- }
161
- async createMany({ payload, scope }) {
162
- const documents = payload.map((item) => this.stampCreate(item, scope));
163
- try {
164
- const db = await this.db();
165
- const collection = db.collection(this.collection);
166
- const { insertedIds } = await collection.insertMany(documents.map((document) => ({ ...document, __v: 1 })), { ignoreUndefined: true });
167
- return insertedIds;
168
- } catch (error) {
169
- await this.report(error);
170
- throw error;
171
- }
172
- }
173
- async patchOne({ where, set, unset, expectedVersion, scope }) {
174
- return this.applyPatch({ where, set, unset, expectedVersion, scope });
175
- }
176
- async archiveByPatch(params) {
177
- const actor = this.actorId(params.scope);
178
- return this.applyPatch(params, { archivedAt: /* @__PURE__ */ new Date(), ...actor ? { archivedBy: actor } : {} });
179
- }
180
- async applyPatch({ where, set, unset, expectedVersion, scope }, stamps = {}) {
181
- if (!where || Object.keys(where).length === 0) throw new Error("[Mongo Repository] Where is required for patchOne operation");
182
- const actor = this.actorId(scope);
183
- const toSet = {
184
- ...this.withoutProtectedPaths(set ?? {}, scope),
185
- ...scope ? { updatedAt: /* @__PURE__ */ new Date(), ...actor ? { updatedBy: actor } : {} } : {},
186
- ...stamps
187
- };
188
- const toUnset = this.withoutProtectedPaths(unset ?? {}, scope);
189
- return this.modifyOne(where, {
190
- $set: toSet,
191
- ...Object.keys(toUnset).length ? { $unset: toUnset } : {}
192
- }, scope, expectedVersion);
193
- }
194
- async claimOne({ where, set, scope }) {
195
- const filter = this.withScope({ ...where, ...this._where }, scope);
196
- try {
197
- const db = await this.db();
198
- const collection = db.collection(this.collection);
199
- const result = await collection.findOneAndUpdate(
200
- filter,
201
- { $set: this.withoutProtectedPaths(set ?? {}, scope) },
202
- { returnDocument: "before", ignoreUndefined: true }
203
- );
204
- return result;
205
- } catch (error) {
206
- await this.report(error);
207
- throw error;
208
- }
209
- }
210
- withoutProtectedPaths(fields, scope) {
211
- const guarded = scope && !scope.trusted;
212
- const isProtected = (key) => this.protectedFields.some((field) => key === field || key.startsWith(`${field}.`) || field.startsWith(`${key}.`));
213
- return Object.fromEntries(Object.entries(fields).filter(([key]) => !IMMUTABLE_FIELDS.includes(key) && !(guarded && isProtected(key))));
214
- }
215
- async softDelete({ where, payload, unset, scope }) {
216
- if (!where || Object.keys(where).length === 0) throw new Error("[Mongo Repository] Where is required for softDelete operation");
217
- const actor = this.actorId(scope);
218
- const extra = this.withoutProtected(payload ?? {}, scope);
219
- const toUnset = this.withoutProtectedPaths(unset ?? {}, scope);
220
- return this.modifyOne(where, {
221
- $set: { ...extra, deletedAt: /* @__PURE__ */ new Date(), ...actor ? { deletedBy: actor } : {} },
222
- ...Object.keys(toUnset).length ? { $unset: toUnset } : {}
223
- }, scope);
224
- }
225
- async modifyOne(where, update, scope, expectedVersion) {
226
- const checkVersion = typeof expectedVersion === "number";
227
- const filter = this.withScope({ ...where, ...checkVersion ? { __v: expectedVersion } : {}, ...this._where }, scope);
228
- try {
229
- const db = await this.db();
230
- const collection = db.collection(this.collection);
231
- const result = await collection.findOneAndUpdate(
232
- filter,
233
- { $inc: { __v: 1 }, ...update },
234
- { returnDocument: "after", ignoreUndefined: true }
235
- );
236
- if (!result && checkVersion) {
237
- const exists = await collection.findOne(this.withScope({ ...where, ...this._where }, scope), { projection: { _id: 1 } });
238
- if (exists) throw new VersionConflictError();
239
- }
240
- return result;
241
- } catch (error) {
242
- if (!(error instanceof VersionConflictError)) await this.report(error);
243
- throw error;
244
- }
245
- }
246
- async updateMany({ where, payload, scope }) {
247
- const filter = this.withScope({ ...where, ...this._where }, scope);
248
- const actor = this.actorId(scope);
249
- const toSet = {
250
- ...this.withoutProtected(payload ?? {}, scope),
251
- ...scope ? { updatedAt: /* @__PURE__ */ new Date(), ...actor ? { updatedBy: actor } : {} } : {}
252
- };
253
- try {
254
- const db = await this.db();
255
- const collection = db.collection(this.collection);
256
- const result = await collection.updateMany(
257
- filter,
258
- { $set: toSet }
259
- );
260
- const countUpdated = result.modifiedCount;
261
- return countUpdated;
262
- } catch (error) {
263
- await this.report(error);
264
- throw error;
265
- }
266
- }
267
- async deleteOne({ where, scope }) {
268
- const filter = this.withScope({ ...where }, scope);
269
- try {
270
- const db = await this.db();
271
- const collection = db.collection(this.collection);
272
- const { deletedCount } = await collection.deleteOne(filter);
273
- return deletedCount;
274
- } catch (error) {
275
- await this.report(error);
276
- throw error;
277
- }
278
- }
279
- async deleteMany({ where, scope }) {
280
- const filter = this.withScope({ ...where }, scope);
281
- try {
282
- const db = await this.db();
283
- const collection = db.collection(this.collection);
284
- const { deletedCount } = await collection.deleteMany(filter);
285
- return deletedCount;
286
- } catch (error) {
287
- await this.report(error);
288
- throw error;
289
- }
290
- }
291
- async count({ where, options, scope }) {
292
- const filter = this.withScope({ ...where, ...options?.includeDeleted ? {} : this._where }, scope);
293
- try {
294
- const db = await this.db();
295
- const collection = db.collection(this.collection);
296
- const result = await collection.countDocuments(filter);
297
- return result;
298
- } catch (error) {
299
- await this.report(error);
300
- throw error;
301
- }
302
- }
303
- async aggregate(pipeline, scope) {
304
- const scopeFilter = this.withScope({}, scope);
305
- const scopedPipeline = Object.keys(scopeFilter).length ? [{ $match: scopeFilter }, ...pipeline] : pipeline;
306
- try {
307
- const db = await this.db();
308
- const collection = db.collection(this.collection);
309
- const result = await collection.aggregate(scopedPipeline).toArray();
310
- return result;
311
- } catch (error) {
312
- await this.report(error);
313
- throw error;
314
- }
315
- }
316
- async distinct(field, where, scope) {
317
- const filter = this.withScope({ ...where, ...this._where }, scope);
318
- try {
319
- const db = await this.db();
320
- const collection = db.collection(this.collection);
321
- const result = await collection.distinct(field, filter);
322
- return result;
323
- } catch (error) {
324
- await this.report(error);
325
- throw error;
326
- }
327
- }
328
- }
329
- export {
330
- MongoRepository,
331
- VersionConflictError
332
- };