@persei/perseed-api 5.0.20 → 5.0.22

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 (166) hide show
  1. package/dist/client.cjs +773 -37
  2. package/dist/client.cjs.map +1 -1
  3. package/dist/client.mjs +773 -37
  4. package/dist/client.mjs.map +1 -1
  5. package/dist/{lib-CDM5aEJG.cjs → dates.helper-CDM5aEJG.cjs} +1 -1
  6. package/dist/dates.helper-CDM5aEJG.cjs.map +1 -0
  7. package/dist/{lib-XRCJ_UAQ.js → dates.helper-XRCJ_UAQ.js} +1 -1
  8. package/dist/dates.helper-XRCJ_UAQ.js.map +1 -0
  9. package/dist/ecosystem-action-system.cjs +124 -34
  10. package/dist/ecosystem-action-system.cjs.map +1 -1
  11. package/dist/ecosystem-action-system.mjs +124 -34
  12. package/dist/ecosystem-action-system.mjs.map +1 -1
  13. package/dist/ecosystem-container-widget.cjs +6 -6
  14. package/dist/ecosystem-container-widget.cjs.map +1 -1
  15. package/dist/ecosystem-container-widget.mjs +1 -1
  16. package/dist/global-dates.cjs +9 -3
  17. package/dist/global-dates.cjs.map +1 -1
  18. package/dist/global-dates.mjs +7 -1
  19. package/dist/global-dates.mjs.map +1 -1
  20. package/dist/lib/src/generated/client.d.ts +5815 -839
  21. package/dist/lib/src/generated/client.d.ts.map +1 -1
  22. package/dist/src/Services/ProcessLogService.d.ts +1 -1
  23. package/dist/src/Services/ProcessLogService.d.ts.map +1 -1
  24. package/dist/src/Services/QueryService.d.ts +24 -1
  25. package/dist/src/Services/QueryService.d.ts.map +1 -1
  26. package/dist/src/Services/RedisQueueService.d.ts.map +1 -1
  27. package/dist/src/Services/TriggerService.d.ts.map +1 -1
  28. package/dist/src/config/apiPublicKey.d.ts +19 -4
  29. package/dist/src/config/apiPublicKey.d.ts.map +1 -1
  30. package/dist/src/config/apiPublicKey.test.d.ts +2 -0
  31. package/dist/src/config/apiPublicKey.test.d.ts.map +1 -0
  32. package/dist/src/constants/SeedPrivilege.d.ts +1 -0
  33. package/dist/src/constants/SeedPrivilege.d.ts.map +1 -1
  34. package/dist/src/controllers/IntrospectionController.d.ts.map +1 -1
  35. package/dist/src/controllers/UserController.d.ts.map +1 -1
  36. package/dist/src/models/ecosystem/NotificationConfiguration.d.ts +1 -1
  37. package/dist/src/models/ecosystem/NotificationConfiguration.d.ts.map +1 -1
  38. package/dist/src/models/ecosystem/User.d.ts +17 -0
  39. package/dist/src/models/ecosystem/User.d.ts.map +1 -1
  40. package/dist/src/models/ecosystem/User.getProjectUser.test.d.ts +2 -0
  41. package/dist/src/models/ecosystem/User.getProjectUser.test.d.ts.map +1 -0
  42. package/dist/src/models/perseed/PerseedEcosystem.d.ts +2 -0
  43. package/dist/src/models/perseed/PerseedEcosystem.d.ts.map +1 -1
  44. package/dist/src/schemas/api_action/ApiActionTypes.d.ts +11 -0
  45. package/dist/src/schemas/api_action/ApiActionTypes.d.ts.map +1 -1
  46. package/dist/src/schemas/container_widget/create_widget_payload.schema.json +1 -1
  47. package/dist/src/schemas/container_widget/update_widget_payload.schema.json +1 -1
  48. package/dist/src/schemas/container_widget/widgetTypes/PatientListProps.d.ts +2 -1
  49. package/dist/src/schemas/container_widget/widgetTypes/PatientListProps.d.ts.map +1 -1
  50. package/dist/src/schemas/index.d.ts +1 -0
  51. package/dist/src/schemas/index.d.ts.map +1 -1
  52. package/dist/src/schemas/project_user/index.d.ts +2 -0
  53. package/dist/src/schemas/project_user/index.d.ts.map +1 -0
  54. package/dist/src/schemas/project_user/types.d.ts +44 -0
  55. package/dist/src/schemas/project_user/types.d.ts.map +1 -0
  56. package/dist/src/test/e2e-permissions.d.ts +32 -3
  57. package/dist/src/test/e2e-permissions.d.ts.map +1 -1
  58. package/dist/src/test/test-helpers.d.ts +12 -0
  59. package/dist/src/test/test-helpers.d.ts.map +1 -1
  60. package/dist/src/v2/modules/ecosystem/action-system/action-system.controller/manual-trigger.controller.d.ts.map +1 -1
  61. package/dist/src/v2/modules/ecosystem/action-system/action-system.helper/action-system.helper.d.ts +27 -5
  62. package/dist/src/v2/modules/ecosystem/action-system/action-system.helper/action-system.helper.d.ts.map +1 -1
  63. package/dist/src/v2/modules/ecosystem/action-system/action-system.helper/index.d.ts +1 -0
  64. package/dist/src/v2/modules/ecosystem/action-system/action-system.helper/index.d.ts.map +1 -1
  65. package/dist/src/v2/modules/ecosystem/action-system/action-system.helper/manual-trigger.helper.d.ts +13 -0
  66. package/dist/src/v2/modules/ecosystem/action-system/action-system.helper/manual-trigger.helper.d.ts.map +1 -0
  67. package/dist/src/v2/modules/ecosystem/action-system/action-system.helper/manual-trigger.helper.test.d.ts +2 -0
  68. package/dist/src/v2/modules/ecosystem/action-system/action-system.helper/manual-trigger.helper.test.d.ts.map +1 -0
  69. package/dist/src/v2/modules/ecosystem/action-system/action-system.model.d.ts +7 -3
  70. package/dist/src/v2/modules/ecosystem/action-system/action-system.model.d.ts.map +1 -1
  71. package/dist/src/v2/modules/ecosystem/action-system/action-system.model.test.d.ts +2 -0
  72. package/dist/src/v2/modules/ecosystem/action-system/action-system.model.test.d.ts.map +1 -0
  73. package/dist/src/v2/modules/ecosystem/action-system/action-system.schema.d.ts +234 -58
  74. package/dist/src/v2/modules/ecosystem/action-system/action-system.schema.d.ts.map +1 -1
  75. package/dist/src/v2/modules/ecosystem/action-system/action-system.service/automatic-trigger.service.d.ts +14 -6
  76. package/dist/src/v2/modules/ecosystem/action-system/action-system.service/automatic-trigger.service.d.ts.map +1 -1
  77. package/dist/src/v2/modules/ecosystem/action-system/action-system.service/manual-trigger-engine.service.d.ts +6 -0
  78. package/dist/src/v2/modules/ecosystem/action-system/action-system.service/manual-trigger-engine.service.d.ts.map +1 -1
  79. package/dist/src/v2/modules/ecosystem/action-system/action-system.service/manual-trigger.service.d.ts +60 -10
  80. package/dist/src/v2/modules/ecosystem/action-system/action-system.service/manual-trigger.service.d.ts.map +1 -1
  81. package/dist/src/v2/modules/ecosystem/action-system/action-system.service/trigger-engine.service.d.ts +6 -0
  82. package/dist/src/v2/modules/ecosystem/action-system/action-system.service/trigger-engine.service.d.ts.map +1 -1
  83. package/dist/src/v2/modules/ecosystem/alert/alert.controller.d.ts +12 -0
  84. package/dist/src/v2/modules/ecosystem/alert/alert.controller.d.ts.map +1 -0
  85. package/dist/src/v2/modules/ecosystem/alert/alert.controller.e2e.d.ts +2 -0
  86. package/dist/src/v2/modules/ecosystem/alert/alert.controller.e2e.d.ts.map +1 -0
  87. package/dist/src/v2/modules/ecosystem/alert/alert.controller.test.d.ts +2 -0
  88. package/dist/src/v2/modules/ecosystem/alert/alert.controller.test.d.ts.map +1 -0
  89. package/dist/src/v2/modules/ecosystem/alert/alert.helper.d.ts +55 -0
  90. package/dist/src/v2/modules/ecosystem/alert/alert.helper.d.ts.map +1 -0
  91. package/dist/src/v2/modules/ecosystem/alert/alert.helper.test.d.ts +2 -0
  92. package/dist/src/v2/modules/ecosystem/alert/alert.helper.test.d.ts.map +1 -0
  93. package/dist/src/v2/modules/ecosystem/alert/alert.model.d.ts +61 -0
  94. package/dist/src/v2/modules/ecosystem/alert/alert.model.d.ts.map +1 -0
  95. package/dist/src/v2/modules/ecosystem/alert/alert.model.test.d.ts +2 -0
  96. package/dist/src/v2/modules/ecosystem/alert/alert.model.test.d.ts.map +1 -0
  97. package/dist/src/v2/modules/ecosystem/alert/alert.schema.d.ts +134 -0
  98. package/dist/src/v2/modules/ecosystem/alert/alert.schema.d.ts.map +1 -0
  99. package/dist/src/v2/modules/ecosystem/alert/alert.service.d.ts +73 -0
  100. package/dist/src/v2/modules/ecosystem/alert/alert.service.d.ts.map +1 -0
  101. package/dist/src/v2/modules/ecosystem/alert/alert.service.test.d.ts +2 -0
  102. package/dist/src/v2/modules/ecosystem/alert/alert.service.test.d.ts.map +1 -0
  103. package/dist/src/v2/modules/ecosystem/alert/index.d.ts +7 -0
  104. package/dist/src/v2/modules/ecosystem/alert/index.d.ts.map +1 -0
  105. package/dist/src/v2/modules/ecosystem/alert-type/alert-type.controller.d.ts +6 -0
  106. package/dist/src/v2/modules/ecosystem/alert-type/alert-type.controller.d.ts.map +1 -0
  107. package/dist/src/v2/modules/ecosystem/alert-type/alert-type.controller.e2e.d.ts +2 -0
  108. package/dist/src/v2/modules/ecosystem/alert-type/alert-type.controller.e2e.d.ts.map +1 -0
  109. package/dist/src/v2/modules/ecosystem/alert-type/alert-type.controller.test.d.ts +2 -0
  110. package/dist/src/v2/modules/ecosystem/alert-type/alert-type.controller.test.d.ts.map +1 -0
  111. package/dist/src/v2/modules/ecosystem/alert-type/alert-type.helper.d.ts +14 -0
  112. package/dist/src/v2/modules/ecosystem/alert-type/alert-type.helper.d.ts.map +1 -0
  113. package/dist/src/v2/modules/ecosystem/alert-type/alert-type.helper.test.d.ts +2 -0
  114. package/dist/src/v2/modules/ecosystem/alert-type/alert-type.helper.test.d.ts.map +1 -0
  115. package/dist/src/v2/modules/ecosystem/alert-type/alert-type.model.d.ts +18 -0
  116. package/dist/src/v2/modules/ecosystem/alert-type/alert-type.model.d.ts.map +1 -0
  117. package/dist/src/v2/modules/ecosystem/alert-type/alert-type.schema.d.ts +29 -0
  118. package/dist/src/v2/modules/ecosystem/alert-type/alert-type.schema.d.ts.map +1 -0
  119. package/dist/src/v2/modules/ecosystem/alert-type/alert-type.service.d.ts +38 -0
  120. package/dist/src/v2/modules/ecosystem/alert-type/alert-type.service.d.ts.map +1 -0
  121. package/dist/src/v2/modules/ecosystem/alert-type/alert-type.service.test.d.ts +2 -0
  122. package/dist/src/v2/modules/ecosystem/alert-type/alert-type.service.test.d.ts.map +1 -0
  123. package/dist/src/v2/modules/ecosystem/alert-type/index.d.ts +6 -0
  124. package/dist/src/v2/modules/ecosystem/alert-type/index.d.ts.map +1 -0
  125. package/dist/src/v2/modules/ecosystem/process-log/index.d.ts +3 -0
  126. package/dist/src/v2/modules/ecosystem/process-log/index.d.ts.map +1 -0
  127. package/dist/src/{models/ecosystem/ProcessLog.d.ts → v2/modules/ecosystem/process-log/process-log.model.d.ts} +5 -5
  128. package/dist/src/v2/modules/ecosystem/process-log/process-log.model.d.ts.map +1 -0
  129. package/dist/src/v2/modules/ecosystem/process-log/process-log.model.test.d.ts +2 -0
  130. package/dist/src/v2/modules/ecosystem/process-log/process-log.model.test.d.ts.map +1 -0
  131. package/dist/src/v2/modules/ecosystem/process-log/process-log.service.d.ts +20 -0
  132. package/dist/src/v2/modules/ecosystem/process-log/process-log.service.d.ts.map +1 -0
  133. package/dist/src/v2/modules/ecosystem/process-log/process-log.service.e2e.d.ts +2 -0
  134. package/dist/src/v2/modules/ecosystem/process-log/process-log.service.e2e.d.ts.map +1 -0
  135. package/dist/src/v2/modules/ecosystem/process-log/process-log.service.test.d.ts +2 -0
  136. package/dist/src/v2/modules/ecosystem/process-log/process-log.service.test.d.ts.map +1 -0
  137. package/dist/src/v2/modules/global/auth-token/auth-token.controller.d.ts.map +1 -1
  138. package/dist/src/v2/modules/global/dates/dates.helper.d.ts.map +1 -1
  139. package/dist/src/v2/modules/global/dates/dates.schema.d.ts +39 -0
  140. package/dist/src/v2/modules/global/dates/dates.schema.d.ts.map +1 -1
  141. package/dist/src/v2/modules/global/e2e-operation/e2e-operation.controller.d.ts.map +1 -1
  142. package/dist/src/v2/modules/global/e2e-operation/e2e-operation.service.d.ts.map +1 -1
  143. package/dist/src/v2/modules/global/permissions/index.d.ts +2 -0
  144. package/dist/src/v2/modules/global/permissions/index.d.ts.map +1 -0
  145. package/dist/src/v2/modules/global/permissions/permissions.helper.d.ts +32 -0
  146. package/dist/src/v2/modules/global/permissions/permissions.helper.d.ts.map +1 -0
  147. package/dist/src/v2/modules/global/permissions/permissions.helper.test.d.ts +2 -0
  148. package/dist/src/v2/modules/global/permissions/permissions.helper.test.d.ts.map +1 -0
  149. package/dist/src/v2/routes/v2/ecosystem/_ecosystemName/alert/index.d.ts +3 -0
  150. package/dist/src/v2/routes/v2/ecosystem/_ecosystemName/alert/index.d.ts.map +1 -0
  151. package/dist/src/v2/routes/v2/ecosystem/_ecosystemName/alert-type/index.d.ts +3 -0
  152. package/dist/src/v2/routes/v2/ecosystem/_ecosystemName/alert-type/index.d.ts.map +1 -0
  153. package/dist/src/v2/routes/v2/ecosystem/_ecosystemName/project/_projectName/alert/index.d.ts +3 -0
  154. package/dist/src/v2/routes/v2/ecosystem/_ecosystemName/project/_projectName/alert/index.d.ts.map +1 -0
  155. package/dist/v1/perseed-api.cjs +2 -0
  156. package/dist/v1/perseed-api.cjs.map +1 -1
  157. package/dist/v1/perseed-api.mjs +2 -0
  158. package/dist/v1/perseed-api.mjs.map +1 -1
  159. package/package.json +1 -1
  160. package/dist/lib-CDM5aEJG.cjs.map +0 -1
  161. package/dist/lib-XRCJ_UAQ.js.map +0 -1
  162. package/dist/src/models/ecosystem/ProcessLog.d.ts.map +0 -1
  163. package/dist/src/models/ecosystem/ProcessLog.test.d.ts +0 -2
  164. package/dist/src/models/ecosystem/ProcessLog.test.d.ts.map +0 -1
  165. package/dist/src/test/global-setup.d.ts +0 -2
  166. package/dist/src/test/global-setup.d.ts.map +0 -1
@@ -24,7 +24,6 @@ const conditionsFormatSchema = Type.Enum(Object.values(ConditionsFormat), {
24
24
  });
25
25
  const TriggerSource = {
26
26
  MODEL: "model",
27
- DESIGNER: "designer",
28
27
  DISPLAYER: "displayer"
29
28
  };
30
29
  const triggerSourceSchema = Type.Enum(Object.values(TriggerSource), {
@@ -101,6 +100,14 @@ const actionContextBaseSchema = Type.Object(
101
100
  requestContextData: Type.Optional(
102
101
  Type.Unknown({ description: "Snapshot of the request context (user, ecosystem, project…) when available" })
103
102
  ),
103
+ // Declared even though `additionalProperties: true` would already let it through: what a
104
+ // condition may be written against is part of the contract, and a field only the engine knows
105
+ // about is one no admin can discover.
106
+ requester: Type.Optional(
107
+ Type.Unknown({
108
+ description: "Who is making the request — role, administrator flags, privileges and clinics of their profiling in the project. Absent when the request carries no user (an internal call, a job)"
109
+ })
110
+ ),
104
111
  projectId: Type.Optional(
105
112
  Type.Union([Type.Number(), Type.Null()], {
106
113
  description: "Project the event belongs to. Null for ecosystem-wide events"
@@ -140,12 +147,19 @@ const actionSchema = Type.Object(
140
147
  description: "Project this action belongs to. Null when it is ecosystem-wide"
141
148
  })
142
149
  ),
143
- name: Type.String({ maxLength: 255, description: "Human-readable identifier of the action" }),
150
+ // Optional for the same reason as the trigger's: it labels the action where it is
151
+ // administered, and nothing renders it to whoever fires the trigger, so requiring it only
152
+ // forced a placeholder. Null when it has none.
153
+ name: Type.Optional(
154
+ Type.Union([Type.String({ maxLength: 255 }), Type.Null()], {
155
+ description: "Human-readable label of the action. Null when it has none"
156
+ })
157
+ ),
144
158
  type: actionTypeSchema,
145
159
  config: actionConfigSchema,
146
160
  retention_days: Type.Optional(
147
161
  Type.Union([Type.Number(), Type.Null()], {
148
- description: "Retention in days for the process_log entries of this action (issue #175). Null = inherit (use the firing trigger retention; never if the trigger is null/0); 0 = disabled (never expires, regardless of the trigger); N (>0) = enabled (expires N days after write)."
162
+ description: "Retention in days for the process_log entries of this action. Null = inherit (use the firing trigger retention; never if the trigger is null/0); 0 = disabled (never expires, regardless of the trigger); N (>0) = enabled (expires N days after write)."
149
163
  })
150
164
  ),
151
165
  // Mirrors `dashboard_widget.library`. False by default, so an action created
@@ -193,6 +207,16 @@ const triggerActionInputSchema = Type.Union(
193
207
  const triggerActionsInputSchema = Type.Array(triggerActionInputSchema, {
194
208
  description: "Full ordered set of actions the trigger runs; the array position is the execution order. An empty array leaves the trigger with none"
195
209
  });
210
+ const triggerNameSchema = Type.Optional(
211
+ Type.Union([Type.String({ maxLength: 255 }), Type.Null()], {
212
+ description: "Human-readable label of the trigger. Null when it has none"
213
+ })
214
+ );
215
+ const triggerDescriptionSchema = Type.Optional(
216
+ Type.Union([Type.String(), Type.Null()], {
217
+ description: "What the trigger is for, for whoever administers it. Null when it has none"
218
+ })
219
+ );
196
220
  const automaticTriggerSchema = Type.Object(
197
221
  {
198
222
  id: Type.Number({ description: "Unique identifier of the automatic trigger" }),
@@ -201,6 +225,8 @@ const automaticTriggerSchema = Type.Object(
201
225
  description: "Project this trigger belongs to. Null when it is ecosystem-wide"
202
226
  })
203
227
  ),
228
+ name: triggerNameSchema,
229
+ description: triggerDescriptionSchema,
204
230
  source: triggerSourceSchema,
205
231
  target: Type.Optional(
206
232
  Type.Union([Type.String({ maxLength: 255 }), Type.Null()], {
@@ -225,7 +251,7 @@ const automaticTriggerSchema = Type.Object(
225
251
  enabled: Type.Optional(Type.Boolean({ description: "Whether the trigger is active" })),
226
252
  retention_days: Type.Optional(
227
253
  Type.Union([Type.Number(), Type.Null()], {
228
- description: "Retention in days for the process_log entries of this trigger (issue #175). Origin — no inheritance: null or 0 = disabled (never expires); N (>0) = enabled (expires N days after write)."
254
+ description: "Retention in days for the process_log entries of this trigger. Origin — no inheritance: null or 0 = disabled (never expires); N (>0) = enabled (expires N days after write)."
229
255
  })
230
256
  )
231
257
  },
@@ -244,6 +270,8 @@ const includeActionsQuerySchema = Type.Object(
244
270
  );
245
271
  const createAutomaticTriggerSchema = Type.Object(
246
272
  {
273
+ name: triggerNameSchema,
274
+ description: triggerDescriptionSchema,
247
275
  source: triggerSourceSchema,
248
276
  target: Type.Optional(
249
277
  Type.Union([Type.String({ maxLength: 255 }), Type.Null()], {
@@ -268,7 +296,7 @@ const createAutomaticTriggerSchema = Type.Object(
268
296
  enabled: Type.Optional(Type.Boolean({ description: "Whether the trigger is active" })),
269
297
  retention_days: Type.Optional(
270
298
  Type.Union([Type.Number(), Type.Null()], {
271
- description: "Retention in days for the process_log entries of this trigger (issue #175). Origin — no inheritance: null or 0 = disabled (never expires); N (>0) = enabled (expires N days after write)."
299
+ description: "Retention in days for the process_log entries of this trigger. Origin — no inheritance: null or 0 = disabled (never expires); N (>0) = enabled (expires N days after write)."
272
300
  })
273
301
  ),
274
302
  actions: Type.Optional(triggerActionsInputSchema)
@@ -284,6 +312,61 @@ const updateAutomaticTriggerSchema = Type.Partial(createAutomaticTriggerSchema,
284
312
  description: "Payload used to update an automatic trigger, optionally replacing the actions it runs",
285
313
  additionalProperties: false
286
314
  });
315
+ const UnmatchedBehavior = {
316
+ HIDE: "hide",
317
+ DISABLE: "disable"
318
+ };
319
+ const unmatchedBehaviorSchema = Type.Enum(Object.values(UnmatchedBehavior), {
320
+ title: "UnmatchedBehavior",
321
+ description: "What to do with the button when the trigger does not match: hide it or disable it"
322
+ });
323
+ const IconPosition = {
324
+ LEFT: "left",
325
+ RIGHT: "right"
326
+ };
327
+ const iconPositionSchema = Type.Enum(Object.values(IconPosition), {
328
+ title: "IconPosition",
329
+ description: "Side of the label the icon sits on"
330
+ });
331
+ const manualTriggerButtonStyleSchema = Type.Object(
332
+ {
333
+ text: Type.Optional(Type.String({ description: "Handlebars template rendered as the button label" })),
334
+ tooltip: Type.Optional(
335
+ Type.String({
336
+ description: "Handlebars template rendered as the button tooltip. Written for whoever uses the listing, unlike `name`, which labels the trigger where it is administered"
337
+ })
338
+ ),
339
+ textColor: Type.Optional(Type.String({ description: "Label colour" })),
340
+ bgColor: Type.Optional(Type.String({ description: "Background colour" })),
341
+ icon: Type.Optional(Type.String({ description: "Icon name, resolved by the consumer" })),
342
+ iconPosition: Type.Optional(iconPositionSchema)
343
+ },
344
+ { title: "ManualTriggerButtonStyle", description: "Presentation of the button a manual trigger is offered on" }
345
+ );
346
+ const manualTriggerConditionalStyleSchema = Type.Intersect(
347
+ [
348
+ manualTriggerButtonStyleSchema,
349
+ Type.Object({
350
+ conditions: Type.Optional(
351
+ Type.Union([Type.Object({}, { additionalProperties: true }), Type.Null()], {
352
+ description: "jsonLogic conditions selecting this style. Absent or null always applies"
353
+ })
354
+ ),
355
+ continueEvaluate: Type.Optional(
356
+ Type.Boolean({ description: "Keep evaluating later entries after this one matches" })
357
+ )
358
+ })
359
+ ],
360
+ { title: "ManualTriggerConditionalStyle" }
361
+ );
362
+ const manualTriggerConfigSchema = Type.Object(
363
+ {
364
+ unmatchedBehavior: Type.Optional(unmatchedBehaviorSchema),
365
+ styles: Type.Optional(manualTriggerButtonStyleSchema),
366
+ conditionalStyles: Type.Optional(Type.Array(manualTriggerConditionalStyleSchema))
367
+ },
368
+ { title: "ManualTriggerConfig", additionalProperties: true }
369
+ );
287
370
  const manualTriggerSchema = Type.Object(
288
371
  {
289
372
  id: Type.Number({ description: "Unique identifier of the manual trigger" }),
@@ -292,7 +375,8 @@ const manualTriggerSchema = Type.Object(
292
375
  description: "Project this trigger belongs to. Null when it is ecosystem-wide"
293
376
  })
294
377
  ),
295
- name: Type.String({ maxLength: 255, description: "Human-readable label of the trigger where it is offered" }),
378
+ name: triggerNameSchema,
379
+ description: triggerDescriptionSchema,
296
380
  source: triggerSourceSchema,
297
381
  target: Type.String({
298
382
  maxLength: 255,
@@ -311,7 +395,12 @@ const manualTriggerSchema = Type.Object(
311
395
  enabled: Type.Optional(Type.Boolean({ description: "Whether the trigger is active" })),
312
396
  retention_days: Type.Optional(
313
397
  Type.Union([Type.Number(), Type.Null()], {
314
- description: "Retention in days for the process_log entries of this trigger (issue #175). Origin — no inheritance: null or 0 = disabled (never expires); N (>0) = enabled (expires N days after write)."
398
+ description: "Retention in days for the process_log entries of this trigger. Origin — no inheritance: null or 0 = disabled (never expires); N (>0) = enabled (expires N days after write)."
399
+ })
400
+ ),
401
+ config: Type.Optional(
402
+ Type.Union([manualTriggerConfigSchema, Type.Null()], {
403
+ description: "Configuration of the trigger beyond its firing rules. Null means none"
315
404
  })
316
405
  )
317
406
  },
@@ -319,7 +408,8 @@ const manualTriggerSchema = Type.Object(
319
408
  );
320
409
  const createManualTriggerSchema = Type.Object(
321
410
  {
322
- name: Type.String({ maxLength: 255, description: "Human-readable label of the trigger where it is offered" }),
411
+ name: triggerNameSchema,
412
+ description: triggerDescriptionSchema,
323
413
  source: triggerSourceSchema,
324
414
  target: Type.String({
325
415
  maxLength: 255,
@@ -338,7 +428,12 @@ const createManualTriggerSchema = Type.Object(
338
428
  enabled: Type.Optional(Type.Boolean({ description: "Whether the trigger is active" })),
339
429
  retention_days: Type.Optional(
340
430
  Type.Union([Type.Number(), Type.Null()], {
341
- description: "Retention in days for the process_log entries of this trigger (issue #175). Origin — no inheritance: null or 0 = disabled (never expires); N (>0) = enabled (expires N days after write)."
431
+ description: "Retention in days for the process_log entries of this trigger. Origin — no inheritance: null or 0 = disabled (never expires); N (>0) = enabled (expires N days after write)."
432
+ })
433
+ ),
434
+ config: Type.Optional(
435
+ Type.Union([manualTriggerConfigSchema, Type.Null()], {
436
+ description: "Configuration of the trigger beyond its firing rules. Null means none"
342
437
  })
343
438
  ),
344
439
  actions: Type.Optional(triggerActionsInputSchema)
@@ -357,16 +452,21 @@ const updateManualTriggerSchema = Type.Partial(createManualTriggerSchema, {
357
452
  const manualTriggerAvailabilitySchema = Type.Object(
358
453
  {
359
454
  id: Type.Number({ description: "Identifier of the manual trigger" }),
360
- name: Type.String({ description: "Human-readable label of the trigger" }),
455
+ name: triggerNameSchema,
361
456
  matched: Type.Boolean({
362
- description: "Whether the trigger conditions hold for this entity right now. A trigger with no conditions always matches"
457
+ description: "Whether the trigger conditions hold for this entity right now. A trigger with no conditions always matches. False means the button is shown disabled: triggers configured to hide when unmatched are not listed"
363
458
  }),
364
459
  actionsCount: Type.Number({ description: "Number of actions the trigger would run" }),
365
460
  relationsSkipped: Type.Optional(
366
461
  Type.Union([Type.String(), Type.Null()], {
367
462
  description: "Reason the declared relations could not be loaded before evaluating, when that happened. Null otherwise"
368
463
  })
369
- )
464
+ ),
465
+ /**
466
+ * Resolved server-side: conditional styles already evaluated and label already compiled. Absent
467
+ * when the trigger has no config — the consumer then paints its own default button.
468
+ */
469
+ style: Type.Optional(manualTriggerButtonStyleSchema)
370
470
  },
371
471
  {
372
472
  title: "ManualTriggerAvailability",
@@ -403,14 +503,6 @@ const automaticTriggerActionSchema = Type.Object(
403
503
  },
404
504
  { title: "AutomaticTriggerAction", description: "Ordered link between an automatic trigger and an action" }
405
505
  );
406
- const createAutomaticTriggerActionSchema = Type.Omit(automaticTriggerActionSchema, ["id"], {
407
- title: "CreateAutomaticTriggerAction",
408
- description: "Row shape of an automatic trigger-action link"
409
- });
410
- const updateAutomaticTriggerActionSchema = Type.Partial(createAutomaticTriggerActionSchema, {
411
- title: "UpdateAutomaticTriggerAction",
412
- description: "Partial row shape of an automatic trigger-action link"
413
- });
414
506
  const manualTriggerActionSchema = Type.Object(
415
507
  {
416
508
  id: Type.Number({ description: "Unique identifier of the trigger-action link" }),
@@ -422,14 +514,6 @@ const manualTriggerActionSchema = Type.Object(
422
514
  },
423
515
  { title: "ManualTriggerAction", description: "Ordered link between a manual trigger and an action" }
424
516
  );
425
- const createManualTriggerActionSchema = Type.Omit(manualTriggerActionSchema, ["id"], {
426
- title: "CreateManualTriggerAction",
427
- description: "Row shape of a manual trigger-action link"
428
- });
429
- const updateManualTriggerActionSchema = Type.Partial(createManualTriggerActionSchema, {
430
- title: "UpdateManualTriggerAction",
431
- description: "Partial row shape of a manual trigger-action link"
432
- });
433
517
  const withResolvedActions = Type.Object({
434
518
  actions: Type.Optional(Type.Array(actionSchema, { description: "Actions the trigger runs, in execution order" }))
435
519
  });
@@ -445,8 +529,11 @@ const triggerExecutionResultSchema = Type.Object(
445
529
  {
446
530
  triggerId: Type.Number({ description: "Identifier of the evaluated trigger" }),
447
531
  matched: Type.Boolean({ description: "Whether the conditions held, so the actions were run" }),
448
- actionsRun: Type.Number({ description: "Number of actions that were executed" }),
449
- actionsAborted: Type.Number({ description: "Number of actions aborted by context validation" })
532
+ actionsRun: Type.Number({ description: "Number of actions that were executed, whether they succeeded or not" }),
533
+ actionsAborted: Type.Number({ description: "Number of actions aborted by context validation" }),
534
+ actionsFailed: Type.Number({
535
+ description: "Number of executed actions that ended in error. A subset of actionsRun"
536
+ })
450
537
  },
451
538
  { title: "TriggerExecutionResult", description: "Outcome of evaluating and running one trigger" }
452
539
  );
@@ -463,8 +550,10 @@ export {
463
550
  ACTION_CONTEXT_SCHEMAS,
464
551
  ActionType,
465
552
  ConditionsFormat,
553
+ IconPosition,
466
554
  TriggerOperation,
467
555
  TriggerSource,
556
+ UnmatchedBehavior,
468
557
  actionConfigBaseSchema,
469
558
  actionConfigSchema,
470
559
  actionContextBaseSchema,
@@ -477,15 +566,17 @@ export {
477
566
  automaticTriggerWithActionsSchema,
478
567
  conditionsFormatSchema,
479
568
  createActionSchema,
480
- createAutomaticTriggerActionSchema,
481
569
  createAutomaticTriggerSchema,
482
- createManualTriggerActionSchema,
483
570
  createManualTriggerSchema,
571
+ iconPositionSchema,
484
572
  includeActionsQuerySchema,
485
573
  manualTriggerActionSchema,
486
574
  manualTriggerAvailabilityListSchema,
487
575
  manualTriggerAvailabilityQuerySchema,
488
576
  manualTriggerAvailabilitySchema,
577
+ manualTriggerButtonStyleSchema,
578
+ manualTriggerConditionalStyleSchema,
579
+ manualTriggerConfigSchema,
489
580
  manualTriggerSchema,
490
581
  manualTriggerWithActionsSchema,
491
582
  runManualTriggerSchema,
@@ -496,10 +587,9 @@ export {
496
587
  triggerOperationSchema,
497
588
  triggerRelationsSchema,
498
589
  triggerSourceSchema,
590
+ unmatchedBehaviorSchema,
499
591
  updateActionSchema,
500
- updateAutomaticTriggerActionSchema,
501
592
  updateAutomaticTriggerSchema,
502
- updateManualTriggerActionSchema,
503
593
  updateManualTriggerSchema,
504
594
  withIdParamsSchema
505
595
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ecosystem-action-system.mjs","sources":["../../src/v2/routes/v2/ecosystem/_ecosystemName/param.schema.ts","../../src/v2/routes/v2/ecosystem/_ecosystemName/project/_projectName/params.schema.ts","../../src/v2/modules/ecosystem/action-system/action-system.schema.ts"],"sourcesContent":["import { Type } from 'typebox'\n\nexport const ecosystemParamsSchema = Type.Object(\n {\n ecosystemName: Type.String({ maxLength: 255, description: 'Ecosystem name code' }),\n },\n { title: 'EcosystemParams', description: 'Params with ecosystem name' },\n)\n","import { Type } from 'typebox'\nimport { ecosystemParamsSchema } from '@/routes/v2/ecosystem/_ecosystemName/param.schema'\n\nexport const ecosystemProjectParamsSchema = Type.Intersect(\n [\n ecosystemParamsSchema,\n Type.Object({\n projectName: Type.String({ maxLength: 255, description: 'Project name code' }),\n }),\n ],\n { title: 'EcosystemProjectParams', description: 'Params with ecosystem name and project name' },\n)\n","import { Type, Static, type TSchema } from 'typebox'\nimport { ecosystemProjectParamsSchema } from '@/routes/v2/ecosystem/_ecosystemName/project/_projectName/params.schema'\n\n// ── Enums / literal unions ────────────────────────────────────────────\n// Each enum is a const object (source of truth, ergonomic dot access like\n// `TriggerSource.MODEL`) from which the runtime schema is derived with\n// `Type.Enum(Object.values(...))` and the type with `Static`.\n\nexport const ConditionsFormat = {\n JSON_LOGIC: 'jsonLogic',\n CUSTOM: 'custom',\n} as const\nexport const conditionsFormatSchema = Type.Enum(Object.values(ConditionsFormat), {\n title: 'ConditionsFormat',\n description: 'Format of the conditions evaluated by the conditions matcher',\n})\nexport type ConditionsFormat = Static<typeof conditionsFormatSchema>\n\nexport const TriggerSource = {\n MODEL: 'model',\n DESIGNER: 'designer',\n DISPLAYER: 'displayer',\n} as const\nexport const triggerSourceSchema = Type.Enum(Object.values(TriggerSource), {\n title: 'TriggerSource',\n description: 'Source of the event that fires a trigger',\n})\nexport type TriggerSource = Static<typeof triggerSourceSchema>\n\nexport const TriggerOperation = {\n CREATE: 'create',\n UPDATE: 'update',\n DELETE: 'delete',\n} as const\nexport const triggerOperationSchema = Type.Enum(Object.values(TriggerOperation), {\n title: 'TriggerOperation',\n description: 'Operation on the target that fires the trigger',\n})\nexport type TriggerOperation = Static<typeof triggerOperationSchema>\n\n// Executable mechanism of an action. `ApiAction` now; extensible to\n// `ExternalApiCall`, `Webhook`, … in the future (each adds a member here plus a\n// config schema below).\nexport const ActionType = {\n API_ACTION: 'ApiAction',\n} as const\nexport const actionTypeSchema = Type.Enum(Object.values(ActionType), {\n title: 'ActionType',\n description: 'Executable mechanism of an action',\n})\nexport type ActionType = Static<typeof actionTypeSchema>\n\n// ── Action config (discriminated union by `actions.type`) ─────────────\n// Forward-compatible contract shared with front/app via @persei/perseed-api.\n// Principles that the structure keeps prepared (not implemented here):\n// - `id` + fixed per-type fields: every type extends `ActionConfigBase`, so its\n// structure is known from `actions.type`.\n// - Objects always under a key (`payload`, …), never loose object fields, so new\n// fields can be added later without breaking compatibility.\n// - default + override: a type may carry a default config plus a `payload` that\n// overrides parts of it, both with the same typing (effective config = merge).\n//\n// `overridable`/`default`/`location` are generic base support for future\n// override-types (e.g. `ExternalApiCall`, #175): an override-type MUST declare\n// `overridable` (the allow-list of keys its payload may override on top of\n// `default`); `location` is a generic string here, refined per type when a\n// concrete type needs it. `ApiAction` is NOT an override-type — its `payload`\n// is the Handlebars data mapping, not an override of a default config — so it\n// gains these fields optionally but never sets `overridable`/`default`.\n\nexport const actionConfigBaseSchema = Type.Object(\n {\n id: Type.String({\n description:\n 'Identifier of the concrete action within its type (e.g. the ApiAction value for type \"ApiAction\"). Any identifier for future types.',\n }),\n location: Type.Optional(\n Type.String({\n description:\n 'Where the effective config is resolved from. Generic string in the base; refined per type in the future (e.g. \"inline\" | \"file\").',\n }),\n ),\n overridable: Type.Optional(\n Type.Array(Type.String(), {\n description:\n 'Allow-list of config keys a payload may override on top of `default`. Mandatory for override-types; absent for non-override types such as ApiAction.',\n }),\n ),\n default: Type.Optional(\n Type.Record(Type.String(), Type.Unknown(), {\n description: 'Base config an override-type merges its `payload` over (only overridable keys are applied).',\n }),\n ),\n },\n { title: 'ActionConfigBase', description: 'Base fields shared by every action config' },\n)\nexport type ActionConfigBaseData = Static<typeof actionConfigBaseSchema>\n\n// type = 'ApiAction' (current). `payload` is the data mapping needed to run the\n// ApiAction; it is always an object under a key for forward compatibility.\nexport const apiActionConfigSchema = Type.Intersect(\n [\n actionConfigBaseSchema,\n Type.Object({\n payload: Type.Record(Type.String(), Type.Unknown(), {\n description: 'Data mapping needed to run the ApiAction',\n }),\n }),\n ],\n { title: 'ApiActionConfig', description: 'Config for actions of type \"ApiAction\"' },\n)\nexport type ApiActionConfig = Static<typeof apiActionConfigSchema>\n\n// Discriminated (by `actions.type`) union of every action config. Extensible:\n// new types add a member that inherits from `ActionConfigBase`.\nexport const actionConfigSchema = Type.Union([apiActionConfigSchema], {\n title: 'ActionConfig',\n description: 'Union of action configs, selected by actions.type',\n})\nexport type ActionConfig = Static<typeof actionConfigSchema>\n\n// Registry mapping each action type to its config schema. Single seam to extend\n// when a new type is added, and the source used to validate a config by type.\nexport const ACTION_CONFIG_SCHEMAS: Record<ActionType, TSchema> = {\n [ActionType.API_ACTION]: apiActionConfigSchema,\n}\n\n// ── Action context (assembled data each action type evaluates against) ─\n// Mirrors the config-schema pattern above but for the *runtime* context\n// (jsonLogic conditions + handlebars payload refs are resolved against it),\n// not the static config. `additionalProperties: true` because the context is\n// enriched dynamically by the engine/ApiActionController (e.g. `ctx`).\n\nexport const actionContextBaseSchema = Type.Object(\n {\n current: Type.Record(Type.String(), Type.Unknown(), {\n description: 'Current state of the entity that fired the event',\n }),\n old: Type.Optional(\n Type.Union([Type.Record(Type.String(), Type.Unknown()), Type.Null()], {\n description: 'Previous state of the entity, when applicable (e.g. update/delete). Null otherwise',\n }),\n ),\n requestContextData: Type.Optional(\n Type.Unknown({ description: 'Snapshot of the request context (user, ecosystem, project…) when available' }),\n ),\n projectId: Type.Optional(\n Type.Union([Type.Number(), Type.Null()], {\n description: 'Project the event belongs to. Null for ecosystem-wide events',\n }),\n ),\n },\n {\n title: 'ActionContextBase',\n description: 'Base fields of the context assembled for every action execution',\n additionalProperties: true,\n },\n)\nexport type ActionContextBaseData = Static<typeof actionContextBaseSchema>\n\n// type = 'ApiAction' (current). No extra required keys beyond the base context\n// yet; kept as a distinct schema so future types can refine it independently.\nexport const apiActionContextSchema = actionContextBaseSchema\n\n// Registry mapping each action type to its context schema. Mirrors\n// `ACTION_CONFIG_SCHEMAS` — single seam to extend when a new type is added.\nexport const ACTION_CONTEXT_SCHEMAS: Record<ActionType, TSchema> = {\n [ActionType.API_ACTION]: apiActionContextSchema,\n}\n\n// Related models to load into the context before a trigger is evaluated — the\n// \"Load relations\" selector of the admin UI. Declared explicitly instead of being\n// derived from the paths a trigger uses: an action templating the whole context\n// (`{{json current}}`) references `current`, never `current.patient`, so deriving\n// would tie the loaded data to how a template is written rather than to what the\n// action needs. An object (not a bare list) because assembling the context has\n// historically taken more than one knob, leaving room to grow.\n//\n// Closed to unknown keys on purpose. The legacy trigger system had a second knob,\n// `load_patient` (`{where, join}`), with semantics this engine does not implement:\n// accepting it would persist a configuration that is then silently ignored, so a\n// trigger would look configured while its conditions never see the related data.\n// Rejecting it at the edge surfaces the mismatch as a 400 instead. Adding a knob\n// here is a deliberate act: declare the field AND read it in `loadRelations`.\nexport const triggerRelationsSchema = Type.Object(\n {\n join: Type.Optional(\n Type.Array(\n // A relation name, not free text: it is interpolated into the eager-loading graph\n // expression. Objection resolves it against the relations declared on the model (never\n // SQL), so an unknown name throws rather than leaking data — but validating the shape\n // here turns that runtime failure into a 400 at the edge, which is cheaper to diagnose.\n Type.String({ pattern: '^[A-Za-z_][A-Za-z0-9_]*$' }),\n { description: 'Relation names to eager-load onto `current` (e.g. [\"patient\"])' },\n ),\n ),\n },\n { title: 'TriggerRelations', additionalProperties: false },\n)\nexport type TriggerRelations = Static<typeof triggerRelationsSchema>\n\n// ── actions (independent reusable catalog) ────────────────────────────\n// Declared before the triggers because a trigger payload can carry actions\n// inline (see `triggerActionsInputSchema` below).\n\nexport const actionSchema = Type.Object(\n {\n id: Type.Number({ description: 'Unique identifier of the action' }),\n project_id: Type.Optional(\n Type.Union([Type.Number(), Type.Null()], {\n description: 'Project this action belongs to. Null when it is ecosystem-wide',\n }),\n ),\n name: Type.String({ maxLength: 255, description: 'Human-readable identifier of the action' }),\n type: actionTypeSchema,\n config: actionConfigSchema,\n retention_days: Type.Optional(\n Type.Union([Type.Number(), Type.Null()], {\n description:\n 'Retention in days for the process_log entries of this action (issue #175). Null = inherit (use the firing trigger retention; never if the trigger is null/0); 0 = disabled (never expires, regardless of the trigger); N (>0) = enabled (expires N days after write).',\n }),\n ),\n // Mirrors `dashboard_widget.library`. False by default, so an action created\n // inline from a trigger screen is single-use unless it is said otherwise.\n library: Type.Optional(\n Type.Boolean({\n description:\n 'Whether the action belongs to the reusable catalog. False (the default) marks it single-use: it is deleted once no trigger links it any more, including before it is ever linked — a standalone action created through POST /action and left unlinked is swept as soon as any trigger of the project writes its links. Set it to true to create one that survives on its own',\n }),\n ),\n },\n { title: 'Action', description: 'Reusable executable action (ecosystem level)' },\n)\nexport type ActionData = Static<typeof actionSchema>\n\n// `Type.Omit` keeps this a plain object — unlike `Type.Intersect` — so closing it here works: an\n// undeclared key is rejected with its name instead of being dropped on the way in. `id` and\n// `project_id` are omitted because the server sets them.\nexport const createActionSchema = Type.Omit(actionSchema, ['id', 'project_id'], {\n title: 'CreateAction',\n description: 'Payload used to create an action',\n additionalProperties: false,\n})\nexport type CreateActionData = Static<typeof createActionSchema>\n\n// Restated: `Type.Partial` rebuilds the object and does not carry over the options it derives from.\nexport const updateActionSchema = Type.Partial(createActionSchema, {\n title: 'UpdateAction',\n description: 'Payload used to update an action',\n additionalProperties: false,\n})\nexport type UpdateActionData = Static<typeof updateActionSchema>\n\n// ── Actions carried by a trigger payload ──────────────────────────────\n// One array, not two fields (`action_ids` + `new_actions`): the position IS the\n// `execution_order`, so splitting the list would make an order that interleaves\n// new and existing actions inexpressible. Each item takes one of three forms,\n// which `number` vs object and object with/without `id` disambiguate on their\n// own — no marker field needed:\n//\n// number link an existing catalog action, untouched\n// object without `id` create the action and link it\n// object with `id` update that catalog action and link it\n//\n// An object carrying only `id` is equivalent to passing the bare number.\n//\n// A malformed id is rejected rather than reinterpreted: `{ id: \"55\", name, type, config }` matches\n// no branch — the update one needs a numeric `id`, and the create one is closed against the key —\n// so it answers 400 instead of quietly landing on \"create a new action\".\nexport const triggerActionInputSchema = Type.Union(\n [\n Type.Number({ description: 'Identifier of an existing action to link, left untouched' }),\n Type.Object(\n { ...createActionSchema.properties },\n {\n title: 'TriggerActionCreate',\n description: 'Action created and linked in the same request',\n additionalProperties: false,\n },\n ),\n Type.Object(\n { id: Type.Number(), ...updateActionSchema.properties },\n {\n title: 'TriggerActionUpdate',\n description: 'Existing action updated and linked in the same request',\n additionalProperties: false,\n },\n ),\n ],\n { title: 'TriggerActionInput', description: 'An action a trigger runs: linked, created, or updated in place' },\n)\nexport type TriggerActionInput = Static<typeof triggerActionInputSchema>\n\nexport const triggerActionsInputSchema = Type.Array(triggerActionInputSchema, {\n description:\n 'Full ordered set of actions the trigger runs; the array position is the execution order. An empty array leaves the trigger with none',\n})\n\n// ── automatic_trigger ─────────────────────────────────────────────────\n\nexport const automaticTriggerSchema = Type.Object(\n {\n id: Type.Number({ description: 'Unique identifier of the automatic trigger' }),\n project_id: Type.Optional(\n Type.Union([Type.Number(), Type.Null()], {\n description: 'Project this trigger belongs to. Null when it is ecosystem-wide',\n }),\n ),\n source: triggerSourceSchema,\n target: Type.Optional(\n Type.Union([Type.String({ maxLength: 255 }), Type.Null()], {\n description: 'Concrete model/designer/field the event refers to. Null for sourceless events',\n }),\n ),\n operation: Type.Optional(\n Type.Union([triggerOperationSchema, Type.Null()], {\n description: 'Operation on the target that fires the trigger. Null when not applicable',\n }),\n ),\n conditions: Type.Optional(\n Type.Union([Type.Object({}, { additionalProperties: true }), Type.Null()], {\n description: 'jsonLogic conditions (root object) evaluated to decide whether the trigger runs',\n }),\n ),\n relations: Type.Optional(\n Type.Union([triggerRelationsSchema, Type.Null()], {\n description:\n 'Related models loaded into the context before evaluating the conditions and running the actions. Null means none.',\n }),\n ),\n enabled: Type.Optional(Type.Boolean({ description: 'Whether the trigger is active' })),\n retention_days: Type.Optional(\n Type.Union([Type.Number(), Type.Null()], {\n description:\n 'Retention in days for the process_log entries of this trigger (issue #175). Origin — no inheritance: null or 0 = disabled (never expires); N (>0) = enabled (expires N days after write).',\n }),\n ),\n },\n { title: 'AutomaticTrigger', description: 'Automatic trigger definition (ecosystem level)' },\n)\nexport type AutomaticTriggerData = Static<typeof automaticTriggerSchema>\n\n// `includeActions` arrives from the query string, where everything is a string: Fastify coerces\n// `?includeActions=true` to a boolean against this schema, so the handler reads a real boolean.\n//\n// Opt-in rather than always-on: the join costs a query per trigger and most reads do not need it.\n// The read reuses the `*WithActions` schema of each kind (declared with the write responses below):\n// `actions` is optional there, so with the flag off the key is simply absent — the same way a\n// write that did not touch the field says nothing about it instead of reporting an empty set.\n//\n// Shared by both trigger kinds: the flag means the same thing on each, and the query schema carries\n// no kind-specific field.\nexport const includeActionsQuerySchema = Type.Object(\n {\n includeActions: Type.Optional(\n Type.Boolean({\n default: false,\n description: 'Return each trigger with its ordered `actions` resolved, in a single request',\n }),\n ),\n },\n { title: 'IncludeActionsQuery', description: 'Opt-in flag to embed the actions of a trigger' },\n)\n\n// Written out rather than derived from `automaticTriggerSchema`: a request schema and an entity\n// schema answer different questions — what a client may send vs what a row holds — and only the\n// first can close itself. `additionalProperties: false` does not survive `Type.Intersect`, so a\n// derived payload had to be cleaned before validating, which dropped unknown keys silently. Spelled\n// out, an undeclared key is a 400 that names it, and `id`/`project_id` are absent because the server\n// owns them, not because an `Omit` removed them.\nexport const createAutomaticTriggerSchema = Type.Object(\n {\n source: triggerSourceSchema,\n target: Type.Optional(\n Type.Union([Type.String({ maxLength: 255 }), Type.Null()], {\n description: 'Concrete model/designer/field the event refers to. Null for sourceless events',\n }),\n ),\n operation: Type.Optional(\n Type.Union([triggerOperationSchema, Type.Null()], {\n description: 'Operation on the target that fires the trigger. Null when not applicable',\n }),\n ),\n conditions: Type.Optional(\n Type.Union([Type.Object({}, { additionalProperties: true }), Type.Null()], {\n description: 'jsonLogic conditions (root object) evaluated to decide whether the trigger runs',\n }),\n ),\n relations: Type.Optional(\n Type.Union([triggerRelationsSchema, Type.Null()], {\n description:\n 'Related models loaded into the context before evaluating the conditions and running the actions. Null means none.',\n }),\n ),\n enabled: Type.Optional(Type.Boolean({ description: 'Whether the trigger is active' })),\n retention_days: Type.Optional(\n Type.Union([Type.Number(), Type.Null()], {\n description:\n 'Retention in days for the process_log entries of this trigger (issue #175). Origin — no inheritance: null or 0 = disabled (never expires); N (>0) = enabled (expires N days after write).',\n }),\n ),\n actions: Type.Optional(triggerActionsInputSchema),\n },\n {\n title: 'CreateAutomaticTrigger',\n description: 'Payload used to create an automatic trigger, optionally with the actions it runs',\n additionalProperties: false,\n },\n)\nexport type CreateAutomaticTriggerData = Static<typeof createAutomaticTriggerSchema>\n\n// `actions` is inherited from the create schema and stays optional here, which is\n// what the update contract wants: absent leaves the links untouched, present\n// replaces the whole ordered set (never merges), `[]` leaves the trigger with none.\n// `additionalProperties: false` is restated: `Type.Partial` rebuilds the object and drops the\n// options of the schema it derives from, so inheriting it would leave this payload open.\nexport const updateAutomaticTriggerSchema = Type.Partial(createAutomaticTriggerSchema, {\n title: 'UpdateAutomaticTrigger',\n description: 'Payload used to update an automatic trigger, optionally replacing the actions it runs',\n additionalProperties: false,\n})\nexport type UpdateAutomaticTriggerData = Static<typeof updateAutomaticTriggerSchema>\n\n// ── manual_trigger ────────────────────────────────────────────────────\n\nexport const manualTriggerSchema = Type.Object(\n {\n id: Type.Number({ description: 'Unique identifier of the manual trigger' }),\n project_id: Type.Optional(\n Type.Union([Type.Number(), Type.Null()], {\n description: 'Project this trigger belongs to. Null when it is ecosystem-wide',\n }),\n ),\n name: Type.String({ maxLength: 255, description: 'Human-readable label of the trigger where it is offered' }),\n source: triggerSourceSchema,\n target: Type.String({\n maxLength: 255,\n description: 'Concrete model/designer/field the trigger is bound to. Always set: there is no wildcard',\n }),\n conditions: Type.Optional(\n Type.Union([Type.Object({}, { additionalProperties: true }), Type.Null()], {\n description:\n 'jsonLogic conditions (root object) evaluated to decide whether the trigger runs. Evaluated against the selected entity and the request context; `old` is always null, because the trigger is invoked explicitly and there is no previous state to compare against.',\n }),\n ),\n relations: Type.Optional(\n Type.Union([triggerRelationsSchema, Type.Null()], {\n description:\n 'Related models loaded into the context before evaluating the conditions and running the actions. Null means none.',\n }),\n ),\n enabled: Type.Optional(Type.Boolean({ description: 'Whether the trigger is active' })),\n retention_days: Type.Optional(\n Type.Union([Type.Number(), Type.Null()], {\n description:\n 'Retention in days for the process_log entries of this trigger (issue #175). Origin — no inheritance: null or 0 = disabled (never expires); N (>0) = enabled (expires N days after write).',\n }),\n ),\n },\n { title: 'ManualTrigger', description: 'Manual trigger definition (ecosystem level)' },\n)\nexport type ManualTriggerData = Static<typeof manualTriggerSchema>\n\n// Written out and closed, for the same reasons as `createAutomaticTriggerSchema` above.\nexport const createManualTriggerSchema = Type.Object(\n {\n name: Type.String({ maxLength: 255, description: 'Human-readable label of the trigger where it is offered' }),\n source: triggerSourceSchema,\n target: Type.String({\n maxLength: 255,\n description: 'Concrete model/designer/field the trigger is bound to. Always set: there is no wildcard',\n }),\n conditions: Type.Optional(\n Type.Union([Type.Object({}, { additionalProperties: true }), Type.Null()], {\n description:\n 'jsonLogic conditions (root object) evaluated to decide whether the trigger runs. Evaluated against the selected entity and the request context; `old` is always null, because the trigger is invoked explicitly and there is no previous state to compare against.',\n }),\n ),\n relations: Type.Optional(\n Type.Union([triggerRelationsSchema, Type.Null()], {\n description:\n 'Related models loaded into the context before evaluating the conditions and running the actions. Null means none.',\n }),\n ),\n enabled: Type.Optional(Type.Boolean({ description: 'Whether the trigger is active' })),\n retention_days: Type.Optional(\n Type.Union([Type.Number(), Type.Null()], {\n description:\n 'Retention in days for the process_log entries of this trigger (issue #175). Origin — no inheritance: null or 0 = disabled (never expires); N (>0) = enabled (expires N days after write).',\n }),\n ),\n actions: Type.Optional(triggerActionsInputSchema),\n },\n {\n title: 'CreateManualTrigger',\n description: 'Payload used to create a manual trigger, optionally with the actions it runs',\n additionalProperties: false,\n },\n)\nexport type CreateManualTriggerData = Static<typeof createManualTriggerSchema>\n\n// Same inheritance and semantics as `updateAutomaticTriggerSchema`.\nexport const updateManualTriggerSchema = Type.Partial(createManualTriggerSchema, {\n title: 'UpdateManualTrigger',\n description: 'Payload used to update a manual trigger, optionally replacing the actions it runs',\n additionalProperties: false,\n})\nexport type UpdateManualTriggerData = Static<typeof updateManualTriggerSchema>\n\n// What the listing endpoint returns per applicable manual trigger: enough to\n// render it and nothing more. `matched` is the *evaluated* conditions outcome —\n// the back reports it, the front decides whether to show the trigger disabled or\n// hide it. It is never an authorisation: running re-evaluates server-side.\nexport const manualTriggerAvailabilitySchema = Type.Object(\n {\n id: Type.Number({ description: 'Identifier of the manual trigger' }),\n name: Type.String({ description: 'Human-readable label of the trigger' }),\n matched: Type.Boolean({\n description:\n 'Whether the trigger conditions hold for this entity right now. A trigger with no conditions always matches',\n }),\n actionsCount: Type.Number({ description: 'Number of actions the trigger would run' }),\n relationsSkipped: Type.Optional(\n Type.Union([Type.String(), Type.Null()], {\n description:\n 'Reason the declared relations could not be loaded before evaluating, when that happened. Null otherwise',\n }),\n ),\n },\n {\n title: 'ManualTriggerAvailability',\n description: 'A manual trigger applicable to an entity, with its conditions already evaluated',\n },\n)\nexport type ManualTriggerAvailability = Static<typeof manualTriggerAvailabilitySchema>\n\nexport const manualTriggerAvailabilityListSchema = Type.Object(\n { results: Type.Array(manualTriggerAvailabilitySchema, { description: 'Applicable manual triggers' }) },\n {\n title: 'ManualTriggerAvailabilityList',\n description: 'Manual triggers applicable to an entity, with their conditions evaluated',\n },\n)\n\n// Query the listing endpoint is called with: the entity the triggers are offered\n// on. `source`/`target` are the coordinates a manual trigger is bound to, and\n// `entityId` the concrete row.\nexport const manualTriggerAvailabilityQuerySchema = Type.Object(\n {\n source: triggerSourceSchema,\n target: Type.String({ maxLength: 255, description: 'Concrete model/designer/field the triggers are bound to' }),\n entityId: Type.Number({ description: 'Identifier of the entity the triggers would run against' }),\n },\n { title: 'ManualTriggerAvailabilityQuery', description: 'Entity the applicable manual triggers are listed for' },\n)\nexport type ManualTriggerAvailabilityQuery = Static<typeof manualTriggerAvailabilityQuerySchema>\n\n// Body of the run endpoint. It carries only the entity: `source`/`target` are\n// read from the trigger row, never from the client, so a trigger cannot be\n// re-pointed at an entity it was not bound to.\nexport const runManualTriggerSchema = Type.Object(\n { entityId: Type.Number({ description: 'Identifier of the entity to run the trigger against' }) },\n { title: 'RunManualTrigger', description: 'Payload used to run a manual trigger against an entity' },\n)\nexport type RunManualTriggerData = Static<typeof runManualTriggerSchema>\n\n// ── automatic_trigger_action (intermediate N:M automatic_trigger↔actions,\n// ordered) ──────────────────────────────────────────────────────────────\n// Dedicated table per trigger kind (no ORM polymorphism): `automatic_trigger_id`\n// is a real FK. `manual_trigger_action` is a future table for manual triggers.\n\nexport const automaticTriggerActionSchema = Type.Object(\n {\n id: Type.Number({ description: 'Unique identifier of the trigger-action link' }),\n automatic_trigger_id: Type.Number({\n description: 'Automatic trigger executing the action (FK to automatic_trigger)',\n }),\n action_id: Type.Number({ description: 'Action executed by the trigger (FK to actions)' }),\n execution_order: Type.Number({ description: 'Execution order of the action within the trigger' }),\n },\n { title: 'AutomaticTriggerAction', description: 'Ordered link between an automatic trigger and an action' },\n)\nexport type AutomaticTriggerActionData = Static<typeof automaticTriggerActionSchema>\n\n// The `create*`/`update*` pair below is not an endpoint contract: the links are\n// written through the `actions` field of the trigger create/update payloads.\n// They remain because `action-system.model.ts` builds the Objection\n// `jsonSchema` of the link models out of their union.\nexport const createAutomaticTriggerActionSchema = Type.Omit(automaticTriggerActionSchema, ['id'], {\n title: 'CreateAutomaticTriggerAction',\n description: 'Row shape of an automatic trigger-action link',\n})\nexport type CreateAutomaticTriggerActionData = Static<typeof createAutomaticTriggerActionSchema>\n\nexport const updateAutomaticTriggerActionSchema = Type.Partial(createAutomaticTriggerActionSchema, {\n title: 'UpdateAutomaticTriggerAction',\n description: 'Partial row shape of an automatic trigger-action link',\n})\nexport type UpdateAutomaticTriggerActionData = Static<typeof updateAutomaticTriggerActionSchema>\n\n// ── manual_trigger_action (intermediate N:M manual_trigger↔actions,\n// ordered) ──────────────────────────────────────────────────────────────\n// Same dedicated-table-per-trigger-kind rule as `automatic_trigger_action`:\n// `manual_trigger_id` is a real FK, and the `actions` catalog is shared\n// between kinds — only the link table differs.\n\nexport const manualTriggerActionSchema = Type.Object(\n {\n id: Type.Number({ description: 'Unique identifier of the trigger-action link' }),\n manual_trigger_id: Type.Number({\n description: 'Manual trigger executing the action (FK to manual_trigger)',\n }),\n action_id: Type.Number({ description: 'Action executed by the trigger (FK to actions)' }),\n execution_order: Type.Number({ description: 'Execution order of the action within the trigger' }),\n },\n { title: 'ManualTriggerAction', description: 'Ordered link between a manual trigger and an action' },\n)\nexport type ManualTriggerActionData = Static<typeof manualTriggerActionSchema>\n\n// Same as the automatic pair above: kept for the model `jsonSchema`, not as an\n// endpoint contract.\nexport const createManualTriggerActionSchema = Type.Omit(manualTriggerActionSchema, ['id'], {\n title: 'CreateManualTriggerAction',\n description: 'Row shape of a manual trigger-action link',\n})\nexport type CreateManualTriggerActionData = Static<typeof createManualTriggerActionSchema>\n\nexport const updateManualTriggerActionSchema = Type.Partial(createManualTriggerActionSchema, {\n title: 'UpdateManualTriggerAction',\n description: 'Partial row shape of a manual trigger-action link',\n})\nexport type UpdateManualTriggerActionData = Static<typeof updateManualTriggerActionSchema>\n\n// ── Declarative trigger↔actions contract ──────────────────────────────\n// The link tables are written as a whole through the `actions` field of the trigger payload,\n// never row by row. The array position IS the `execution_order`, so ordering can\n// never disagree with the list the client sent — which per-row endpoints allowed\n// (duplicate or gapped orders after a reorder). Shared by both trigger kinds:\n// only the parent FK differs, and that comes from the URL.\n//\n// The field is `actions`, not `action_ids`: items are no longer only ids (see\n// `triggerActionInputSchema`). Same body as the `actions` field of the create and\n// update trigger payloads, so the three ways of writing the set agree.\n\n// What create/update answer with. `actions` carries the resolved catalog rows —\n// not the link rows — so a client that sent actions inline learns the ids they\n// were given without chaining a second request. It is present only when the\n// request carried the field: a create/update that did not mention actions says\n// nothing about them, rather than reporting an empty set it never touched.\nconst withResolvedActions = Type.Object({\n actions: Type.Optional(Type.Array(actionSchema, { description: 'Actions the trigger runs, in execution order' })),\n})\n\nexport const automaticTriggerWithActionsSchema = Type.Intersect([automaticTriggerSchema, withResolvedActions], {\n title: 'AutomaticTriggerWithActions',\n description:\n 'An automatic trigger and, when the request wrote them or `includeActions` asked for them, the actions it runs',\n})\nexport type AutomaticTriggerWithActionsData = Static<typeof automaticTriggerWithActionsSchema>\n\nexport const manualTriggerWithActionsSchema = Type.Intersect([manualTriggerSchema, withResolvedActions], {\n title: 'ManualTriggerWithActions',\n description:\n 'A manual trigger and, when the request wrote them or `includeActions` asked for them, the actions it runs',\n})\nexport type ManualTriggerWithActionsData = Static<typeof manualTriggerWithActionsSchema>\n\n// ── Execution engine (pure, model-independent contract types) ──────────\n// Exported types the engine (service/helper) works with. Kept here (rather\n// than in service/helper) so they can be imported without pulling in\n// service/helper code. None of them references a model: the engine types\n// itself structurally (see the `*Like` shapes below).\n\nexport interface ActionEvent {\n source: TriggerSource\n target?: string | null\n operation?: TriggerOperation | null\n current: Record<string, unknown>\n old?: Record<string, unknown> | null\n}\n\n// Outcome of evaluating (and, when matched, running) a single trigger. Declared\n// as a TypeBox schema — not just an interface — because the manual-trigger run\n// endpoint returns it verbatim; `TriggerExecutionResult` is its static type, so\n// engine and endpoint cannot drift apart.\nexport const triggerExecutionResultSchema = Type.Object(\n {\n triggerId: Type.Number({ description: 'Identifier of the evaluated trigger' }),\n matched: Type.Boolean({ description: 'Whether the conditions held, so the actions were run' }),\n actionsRun: Type.Number({ description: 'Number of actions that were executed' }),\n actionsAborted: Type.Number({ description: 'Number of actions aborted by context validation' }),\n },\n { title: 'TriggerExecutionResult', description: 'Outcome of evaluating and running one trigger' },\n)\nexport type TriggerExecutionResult = Static<typeof triggerExecutionResultSchema>\n\n// ── Trigger-kind-agnostic engine contract ─────────────────────────────\n// The execution engine is shared by every kind of trigger: it consumes the\n// minimal structural shapes below rather than a concrete model, so a new kind\n// only has to resolve its own candidates and hand them over. The `*Like` types\n// are deliberately structural (not the Objection classes) so the engine never\n// imports a model to type itself — `AutomaticTrigger` / `AutomaticTriggerAction`\n// / `Action` satisfy them as they are, without a cast.\n\n/**\n * Structural shape the engine needs from an action it is about to run: the\n * identity it logs, the `type` that selects the validation/dispatch branch, the\n * config it executes with, and the retention it resolves `expires_at` from.\n * Deliberately loose (`type: string`, not `ActionType`) so an unknown type still\n * reaches the always-blocking context validation instead of failing to typecheck.\n */\nexport interface ActionLike {\n id: number\n type: string\n config: ActionConfig\n retention_days?: number | null\n}\n\n/** Ordered trigger↔action link in the minimal shape the engine consumes. */\nexport interface TriggerActionLike {\n action_id: number\n execution_order: number\n action?: ActionLike\n}\n\n/** Minimal shape of a trigger for the engine, whatever its kind. */\nexport interface EvaluableTrigger {\n id: number\n conditions?: object | null\n relations?: TriggerRelations | null\n retention_days?: number | null\n trigger_actions?: TriggerActionLike[]\n}\n\n/**\n * A batch of already-resolved candidates a trigger kind hands to the engine,\n * together with the event data they were resolved for. `relatedModel` is what\n * the evaluation `process_log` row is related to (the trigger table of that\n * kind), which is how trigger evaluations stay independently queryable per kind.\n */\nexport interface TriggerBatch<T extends EvaluableTrigger = EvaluableTrigger> {\n triggers: T[]\n relatedModel: string\n source: TriggerSource\n target?: string | null\n operation?: TriggerOperation | null\n current: Record<string, unknown>\n old?: Record<string, unknown> | null\n}\n\n// ── Context validation (pure data types) ────────────────────────────────\n\nexport interface ContextValidationResult {\n ok: boolean\n type: string\n baseErrors: { path: string; message: string }[]\n missingRefs: string[]\n referencedRefs: string[]\n overridableErrors: string[]\n}\n\n// Structural shape `buildEffectiveConfig`/`validateActionContext` need from an\n// action config — deliberately loose (not `ActionConfig`) so it works for any\n// current or future type without a cast at every call site.\nexport interface ActionConfigLike {\n payload?: Record<string, unknown>\n overridable?: string[]\n default?: Record<string, unknown>\n}\n\nexport interface EffectiveConfigResult {\n effective: Record<string, unknown>\n overridableErrors: string[]\n}\n\n// ── Route-level schemas ───────────────────────────────────────────────\n// Shared by every router of the module.\n\nexport const successResponseSchema = Type.Object(\n { success: Type.Boolean({ description: 'If the request success or not' }) },\n { title: 'ActionSystemSuccessResponse', description: 'Response when the request is successful' },\n)\n\nexport const withIdParamsSchema = Type.Intersect(\n [ecosystemProjectParamsSchema, Type.Object({ id: Type.Number({ description: 'Entity ID' }) })],\n { title: 'EcosystemProjectWithActionSystemIdParams', description: 'Params with ecosystem, project and entity ID' },\n)\n"],"names":[],"mappings":";AAEO,MAAM,wBAAwB,KAAK;AAAA,EACxC;AAAA,IACE,eAAe,KAAK,OAAO,EAAE,WAAW,KAAK,aAAa,uBAAuB;AAAA,EAAA;AAAA,EAEnF,EAAE,OAAO,mBAAmB,aAAa,6BAAA;AAC3C;ACJO,MAAM,+BAA+B,KAAK;AAAA,EAC/C;AAAA,IACE;AAAA,IACA,KAAK,OAAO;AAAA,MACV,aAAa,KAAK,OAAO,EAAE,WAAW,KAAK,aAAa,qBAAqB;AAAA,IAAA,CAC9E;AAAA,EAAA;AAAA,EAEH,EAAE,OAAO,0BAA0B,aAAa,8CAAA;AAClD;ACHO,MAAM,mBAAmB;AAAA,EAC9B,YAAY;AAAA,EACZ,QAAQ;AACV;AACO,MAAM,yBAAyB,KAAK,KAAK,OAAO,OAAO,gBAAgB,GAAG;AAAA,EAC/E,OAAO;AAAA,EACP,aAAa;AACf,CAAC;AAGM,MAAM,gBAAgB;AAAA,EAC3B,OAAO;AAAA,EACP,UAAU;AAAA,EACV,WAAW;AACb;AACO,MAAM,sBAAsB,KAAK,KAAK,OAAO,OAAO,aAAa,GAAG;AAAA,EACzE,OAAO;AAAA,EACP,aAAa;AACf,CAAC;AAGM,MAAM,mBAAmB;AAAA,EAC9B,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AACV;AACO,MAAM,yBAAyB,KAAK,KAAK,OAAO,OAAO,gBAAgB,GAAG;AAAA,EAC/E,OAAO;AAAA,EACP,aAAa;AACf,CAAC;AAMM,MAAM,aAAa;AAAA,EACxB,YAAY;AACd;AACO,MAAM,mBAAmB,KAAK,KAAK,OAAO,OAAO,UAAU,GAAG;AAAA,EACnE,OAAO;AAAA,EACP,aAAa;AACf,CAAC;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AG;AAAA,EAC7G,OAAO;AAAA,EACP,aACE;AACJ,CAAC;AAGM,MAAM,iCAAiC,KAAK,UAAU,CAAC,qBAAqB,mBAAmB,GAAG;AAAA,EACvG,OAAO;AAAA,EACP,aACE;AACJ,CAAC;AAqBM,MAAM,+BAA+B,KAAK;AAAA,EAC/C;AAAA,IACE,WAAW,KAAK,OAAO,EAAE,aAAa,uCAAuC;AAAA,IAC7E,SAAS,KAAK,QAAQ,EAAE,aAAa,wDAAwD;AAAA,IAC7F,YAAY,KAAK,OAAO,EAAE,aAAa,wCAAwC;AAAA,IAC/E,gBAAgB,KAAK,OAAO,EAAE,aAAa,mDAAmD;AAAA,EAAA;AAAA,EAEhG,EAAE,OAAO,0BAA0B,aAAa,gDAAA;AAClD;AAqFO,MAAM,wBAAwB,KAAK;AAAA,EACxC,EAAE,SAAS,KAAK,QAAQ,EAAE,aAAa,gCAAA,CAAiC,EAAA;AAAA,EACxE,EAAE,OAAO,+BAA+B,aAAa,0CAAA;AACvD;AAEO,MAAM,qBAAqB,KAAK;AAAA,EACrC,CAAC,8BAA8B,KAAK,OAAO,EAAE,IAAI,KAAK,OAAO,EAAE,aAAa,YAAA,CAAa,EAAA,CAAG,CAAC;AAAA,EAC7F,EAAE,OAAO,4CAA4C,aAAa,+CAAA;AACpE;"}
1
+ {"version":3,"file":"ecosystem-action-system.mjs","sources":["../../src/v2/routes/v2/ecosystem/_ecosystemName/param.schema.ts","../../src/v2/routes/v2/ecosystem/_ecosystemName/project/_projectName/params.schema.ts","../../src/v2/modules/ecosystem/action-system/action-system.schema.ts"],"sourcesContent":["import { Type } from 'typebox'\n\nexport const ecosystemParamsSchema = Type.Object(\n {\n ecosystemName: Type.String({ maxLength: 255, description: 'Ecosystem name code' }),\n },\n { title: 'EcosystemParams', description: 'Params with ecosystem name' },\n)\n","import { Type } from 'typebox'\nimport { ecosystemParamsSchema } from '@/routes/v2/ecosystem/_ecosystemName/param.schema'\n\nexport const ecosystemProjectParamsSchema = Type.Intersect(\n [\n ecosystemParamsSchema,\n Type.Object({\n projectName: Type.String({ maxLength: 255, description: 'Project name code' }),\n }),\n ],\n { title: 'EcosystemProjectParams', description: 'Params with ecosystem name and project name' },\n)\n","import { Type, Static, type TSchema } from 'typebox'\nimport { ecosystemProjectParamsSchema } from '@/routes/v2/ecosystem/_ecosystemName/project/_projectName/params.schema'\n\n// ── Enums / literal unions ────────────────────────────────────────────\n// Each enum is a const object (source of truth, ergonomic dot access like\n// `TriggerSource.MODEL`) from which the runtime schema is derived with\n// `Type.Enum(Object.values(...))` and the type with `Static`.\n\nexport const ConditionsFormat = {\n JSON_LOGIC: 'jsonLogic',\n CUSTOM: 'custom',\n} as const\nexport const conditionsFormatSchema = Type.Enum(Object.values(ConditionsFormat), {\n title: 'ConditionsFormat',\n description: 'Format of the conditions evaluated by the conditions matcher',\n})\nexport type ConditionsFormat = Static<typeof conditionsFormatSchema>\n\n/**\n * What a trigger binds to: a row of a model, or the data of a form.\n *\n * These are the two the platform emits — `emitModelAfterSave` for one, the form save for the\n * other — and the two `resolveTargetQuery` can load an entity from. A third, `designer` (the form\n * definition), was declared and never emitted: an automatic trigger bound to it could not fire,\n * and a manual one answered 404 both when listing its availability and when running it, because\n * the name of a form does not resolve through the relation-loadable models it fell back to.\n */\nexport const TriggerSource = {\n MODEL: 'model',\n DISPLAYER: 'displayer',\n} as const\nexport const triggerSourceSchema = Type.Enum(Object.values(TriggerSource), {\n title: 'TriggerSource',\n description: 'Source of the event that fires a trigger',\n})\nexport type TriggerSource = Static<typeof triggerSourceSchema>\n\nexport const TriggerOperation = {\n CREATE: 'create',\n UPDATE: 'update',\n DELETE: 'delete',\n} as const\nexport const triggerOperationSchema = Type.Enum(Object.values(TriggerOperation), {\n title: 'TriggerOperation',\n description: 'Operation on the target that fires the trigger',\n})\nexport type TriggerOperation = Static<typeof triggerOperationSchema>\n\n// Executable mechanism of an action. `ApiAction` now; extensible to\n// `ExternalApiCall`, `Webhook`, … in the future (each adds a member here plus a\n// config schema below).\nexport const ActionType = {\n API_ACTION: 'ApiAction',\n} as const\nexport const actionTypeSchema = Type.Enum(Object.values(ActionType), {\n title: 'ActionType',\n description: 'Executable mechanism of an action',\n})\nexport type ActionType = Static<typeof actionTypeSchema>\n\n// ── Action config (discriminated union by `actions.type`) ─────────────\n// Forward-compatible contract shared with front/app via @persei/perseed-api.\n// Principles that the structure keeps prepared (not implemented here):\n// - `id` + fixed per-type fields: every type extends `ActionConfigBase`, so its\n// structure is known from `actions.type`.\n// - Objects always under a key (`payload`, …), never loose object fields, so new\n// fields can be added later without breaking compatibility.\n// - default + override: a type may carry a default config plus a `payload` that\n// overrides parts of it, both with the same typing (effective config = merge).\n//\n// `overridable`/`default`/`location` are generic base support for future\n// override-types (e.g. `ExternalApiCall`): an override-type MUST declare\n// `overridable` (the allow-list of keys its payload may override on top of\n// `default`); `location` is a generic string here, refined per type when a\n// concrete type needs it. `ApiAction` is NOT an override-type — its `payload`\n// is the Handlebars data mapping, not an override of a default config — so it\n// gains these fields optionally but never sets `overridable`/`default`.\n\nexport const actionConfigBaseSchema = Type.Object(\n {\n id: Type.String({\n description:\n 'Identifier of the concrete action within its type (e.g. the ApiAction value for type \"ApiAction\"). Any identifier for future types.',\n }),\n location: Type.Optional(\n Type.String({\n description:\n 'Where the effective config is resolved from. Generic string in the base; refined per type in the future (e.g. \"inline\" | \"file\").',\n }),\n ),\n overridable: Type.Optional(\n Type.Array(Type.String(), {\n description:\n 'Allow-list of config keys a payload may override on top of `default`. Mandatory for override-types; absent for non-override types such as ApiAction.',\n }),\n ),\n default: Type.Optional(\n Type.Record(Type.String(), Type.Unknown(), {\n description: 'Base config an override-type merges its `payload` over (only overridable keys are applied).',\n }),\n ),\n },\n { title: 'ActionConfigBase', description: 'Base fields shared by every action config' },\n)\nexport type ActionConfigBaseData = Static<typeof actionConfigBaseSchema>\n\n// type = 'ApiAction' (current). `payload` is the data mapping needed to run the\n// ApiAction; it is always an object under a key for forward compatibility.\nexport const apiActionConfigSchema = Type.Intersect(\n [\n actionConfigBaseSchema,\n Type.Object({\n payload: Type.Record(Type.String(), Type.Unknown(), {\n description: 'Data mapping needed to run the ApiAction',\n }),\n }),\n ],\n { title: 'ApiActionConfig', description: 'Config for actions of type \"ApiAction\"' },\n)\nexport type ApiActionConfig = Static<typeof apiActionConfigSchema>\n\n// Discriminated (by `actions.type`) union of every action config. Extensible:\n// new types add a member that inherits from `ActionConfigBase`.\nexport const actionConfigSchema = Type.Union([apiActionConfigSchema], {\n title: 'ActionConfig',\n description: 'Union of action configs, selected by actions.type',\n})\nexport type ActionConfig = Static<typeof actionConfigSchema>\n\n// Registry mapping each action type to its config schema. Single seam to extend\n// when a new type is added, and the source used to validate a config by type.\nexport const ACTION_CONFIG_SCHEMAS: Record<ActionType, TSchema> = {\n [ActionType.API_ACTION]: apiActionConfigSchema,\n}\n\n// ── Action context (assembled data each action type evaluates against) ─\n// Mirrors the config-schema pattern above but for the *runtime* context\n// (jsonLogic conditions + handlebars payload refs are resolved against it),\n// not the static config. `additionalProperties: true` because the context is\n// enriched dynamically by the engine/ApiActionController (e.g. `ctx`).\n\nexport const actionContextBaseSchema = Type.Object(\n {\n current: Type.Record(Type.String(), Type.Unknown(), {\n description: 'Current state of the entity that fired the event',\n }),\n old: Type.Optional(\n Type.Union([Type.Record(Type.String(), Type.Unknown()), Type.Null()], {\n description: 'Previous state of the entity, when applicable (e.g. update/delete). Null otherwise',\n }),\n ),\n requestContextData: Type.Optional(\n Type.Unknown({ description: 'Snapshot of the request context (user, ecosystem, project…) when available' }),\n ),\n // Declared even though `additionalProperties: true` would already let it through: what a\n // condition may be written against is part of the contract, and a field only the engine knows\n // about is one no admin can discover.\n requester: Type.Optional(\n Type.Unknown({\n description:\n 'Who is making the request — role, administrator flags, privileges and clinics of their profiling in the project. Absent when the request carries no user (an internal call, a job)',\n }),\n ),\n projectId: Type.Optional(\n Type.Union([Type.Number(), Type.Null()], {\n description: 'Project the event belongs to. Null for ecosystem-wide events',\n }),\n ),\n },\n {\n title: 'ActionContextBase',\n description: 'Base fields of the context assembled for every action execution',\n additionalProperties: true,\n },\n)\nexport type ActionContextBaseData = Static<typeof actionContextBaseSchema>\n\n// type = 'ApiAction' (current). No extra required keys beyond the base context\n// yet; kept as a distinct schema so future types can refine it independently.\nexport const apiActionContextSchema = actionContextBaseSchema\n\n// Registry mapping each action type to its context schema. Mirrors\n// `ACTION_CONFIG_SCHEMAS` — single seam to extend when a new type is added.\nexport const ACTION_CONTEXT_SCHEMAS: Record<ActionType, TSchema> = {\n [ActionType.API_ACTION]: apiActionContextSchema,\n}\n\n// Related models to load into the context before a trigger is evaluated — the\n// \"Load relations\" selector of the admin UI. Declared explicitly instead of being\n// derived from the paths a trigger uses: an action templating the whole context\n// (`{{json current}}`) references `current`, never `current.patient`, so deriving\n// would tie the loaded data to how a template is written rather than to what the\n// action needs. An object (not a bare list) because assembling the context has\n// historically taken more than one knob, leaving room to grow.\n//\n// Closed to unknown keys on purpose. The legacy trigger system had a second knob,\n// `load_patient` (`{where, join}`), with semantics this engine does not implement:\n// accepting it would persist a configuration that is then silently ignored, so a\n// trigger would look configured while its conditions never see the related data.\n// Rejecting it at the edge surfaces the mismatch as a 400 instead. Adding a knob\n// here is a deliberate act: declare the field AND read it in `loadRelations`.\nexport const triggerRelationsSchema = Type.Object(\n {\n join: Type.Optional(\n Type.Array(\n // A relation name, not free text: it is interpolated into the eager-loading graph\n // expression. Objection resolves it against the relations declared on the model (never\n // SQL), so an unknown name throws rather than leaking data — but validating the shape\n // here turns that runtime failure into a 400 at the edge, which is cheaper to diagnose.\n Type.String({ pattern: '^[A-Za-z_][A-Za-z0-9_]*$' }),\n { description: 'Relation names to eager-load onto `current` (e.g. [\"patient\"])' },\n ),\n ),\n },\n { title: 'TriggerRelations', additionalProperties: false },\n)\nexport type TriggerRelations = Static<typeof triggerRelationsSchema>\n\n// ── actions (independent reusable catalog) ────────────────────────────\n// Declared before the triggers because a trigger payload can carry actions\n// inline (see `triggerActionsInputSchema` below).\n\nexport const actionSchema = Type.Object(\n {\n id: Type.Number({ description: 'Unique identifier of the action' }),\n project_id: Type.Optional(\n Type.Union([Type.Number(), Type.Null()], {\n description: 'Project this action belongs to. Null when it is ecosystem-wide',\n }),\n ),\n // Optional for the same reason as the trigger's: it labels the action where it is\n // administered, and nothing renders it to whoever fires the trigger, so requiring it only\n // forced a placeholder. Null when it has none.\n name: Type.Optional(\n Type.Union([Type.String({ maxLength: 255 }), Type.Null()], {\n description: 'Human-readable label of the action. Null when it has none',\n }),\n ),\n type: actionTypeSchema,\n config: actionConfigSchema,\n retention_days: Type.Optional(\n Type.Union([Type.Number(), Type.Null()], {\n description:\n 'Retention in days for the process_log entries of this action. Null = inherit (use the firing trigger retention; never if the trigger is null/0); 0 = disabled (never expires, regardless of the trigger); N (>0) = enabled (expires N days after write).',\n }),\n ),\n // Mirrors `dashboard_widget.library`. False by default, so an action created\n // inline from a trigger screen is single-use unless it is said otherwise.\n library: Type.Optional(\n Type.Boolean({\n description:\n 'Whether the action belongs to the reusable catalog. False (the default) marks it single-use: it is deleted once no trigger links it any more, including before it is ever linked — a standalone action created through POST /action and left unlinked is swept as soon as any trigger of the project writes its links. Set it to true to create one that survives on its own',\n }),\n ),\n },\n { title: 'Action', description: 'Reusable executable action (ecosystem level)' },\n)\nexport type ActionData = Static<typeof actionSchema>\n\n// `Type.Omit` keeps this a plain object — unlike `Type.Intersect` — so closing it here works: an\n// undeclared key is rejected with its name instead of being dropped on the way in. `id` and\n// `project_id` are omitted because the server sets them.\nexport const createActionSchema = Type.Omit(actionSchema, ['id', 'project_id'], {\n title: 'CreateAction',\n description: 'Payload used to create an action',\n additionalProperties: false,\n})\nexport type CreateActionData = Static<typeof createActionSchema>\n\n// Restated: `Type.Partial` rebuilds the object and does not carry over the options it derives from.\nexport const updateActionSchema = Type.Partial(createActionSchema, {\n title: 'UpdateAction',\n description: 'Payload used to update an action',\n additionalProperties: false,\n})\nexport type UpdateActionData = Static<typeof updateActionSchema>\n\n// ── Actions carried by a trigger payload ──────────────────────────────\n// One array, not two fields (`action_ids` + `new_actions`): the position IS the\n// `execution_order`, so splitting the list would make an order that interleaves\n// new and existing actions inexpressible. Each item takes one of three forms,\n// which `number` vs object and object with/without `id` disambiguate on their\n// own — no marker field needed:\n//\n// number link an existing catalog action, untouched\n// object without `id` create the action and link it\n// object with `id` update that catalog action and link it\n//\n// An object carrying only `id` is equivalent to passing the bare number.\n//\n// A malformed id is rejected rather than reinterpreted: `{ id: \"55\", name, type, config }` matches\n// no branch — the update one needs a numeric `id`, and the create one is closed against the key —\n// so it answers 400 instead of quietly landing on \"create a new action\".\nexport const triggerActionInputSchema = Type.Union(\n [\n Type.Number({ description: 'Identifier of an existing action to link, left untouched' }),\n Type.Object(\n { ...createActionSchema.properties },\n {\n title: 'TriggerActionCreate',\n description: 'Action created and linked in the same request',\n additionalProperties: false,\n },\n ),\n Type.Object(\n { id: Type.Number(), ...updateActionSchema.properties },\n {\n title: 'TriggerActionUpdate',\n description: 'Existing action updated and linked in the same request',\n additionalProperties: false,\n },\n ),\n ],\n { title: 'TriggerActionInput', description: 'An action a trigger runs: linked, created, or updated in place' },\n)\nexport type TriggerActionInput = Static<typeof triggerActionInputSchema>\n\nexport const triggerActionsInputSchema = Type.Array(triggerActionInputSchema, {\n description:\n 'Full ordered set of actions the trigger runs; the array position is the execution order. An empty array leaves the trigger with none',\n})\n\n// ── automatic_trigger ─────────────────────────────────────────────────\n\n/** Optional label a trigger is known by wherever it is administered. Not shown to end users. */\nconst triggerNameSchema = Type.Optional(\n Type.Union([Type.String({ maxLength: 255 }), Type.Null()], {\n description: 'Human-readable label of the trigger. Null when it has none',\n }),\n)\n\n/** Free text for whoever maintains the trigger; never rendered where the trigger is offered. */\nconst triggerDescriptionSchema = Type.Optional(\n Type.Union([Type.String(), Type.Null()], {\n description: 'What the trigger is for, for whoever administers it. Null when it has none',\n }),\n)\n\nexport const automaticTriggerSchema = Type.Object(\n {\n id: Type.Number({ description: 'Unique identifier of the automatic trigger' }),\n project_id: Type.Optional(\n Type.Union([Type.Number(), Type.Null()], {\n description: 'Project this trigger belongs to. Null when it is ecosystem-wide',\n }),\n ),\n name: triggerNameSchema,\n description: triggerDescriptionSchema,\n source: triggerSourceSchema,\n target: Type.Optional(\n Type.Union([Type.String({ maxLength: 255 }), Type.Null()], {\n description: 'Concrete model/designer/field the event refers to. Null for sourceless events',\n }),\n ),\n operation: Type.Optional(\n Type.Union([triggerOperationSchema, Type.Null()], {\n description: 'Operation on the target that fires the trigger. Null when not applicable',\n }),\n ),\n conditions: Type.Optional(\n Type.Union([Type.Object({}, { additionalProperties: true }), Type.Null()], {\n description: 'jsonLogic conditions (root object) evaluated to decide whether the trigger runs',\n }),\n ),\n relations: Type.Optional(\n Type.Union([triggerRelationsSchema, Type.Null()], {\n description:\n 'Related models loaded into the context before evaluating the conditions and running the actions. Null means none.',\n }),\n ),\n enabled: Type.Optional(Type.Boolean({ description: 'Whether the trigger is active' })),\n retention_days: Type.Optional(\n Type.Union([Type.Number(), Type.Null()], {\n description:\n 'Retention in days for the process_log entries of this trigger. Origin — no inheritance: null or 0 = disabled (never expires); N (>0) = enabled (expires N days after write).',\n }),\n ),\n },\n { title: 'AutomaticTrigger', description: 'Automatic trigger definition (ecosystem level)' },\n)\nexport type AutomaticTriggerData = Static<typeof automaticTriggerSchema>\n\n// `includeActions` arrives from the query string, where everything is a string: Fastify coerces\n// `?includeActions=true` to a boolean against this schema, so the handler reads a real boolean.\n//\n// Opt-in rather than always-on: the join costs a query per trigger and most reads do not need it.\n// The read reuses the `*WithActions` schema of each kind (declared with the write responses below):\n// `actions` is optional there, so with the flag off the key is simply absent — the same way a\n// write that did not touch the field says nothing about it instead of reporting an empty set.\n//\n// Shared by both trigger kinds: the flag means the same thing on each, and the query schema carries\n// no kind-specific field.\nexport const includeActionsQuerySchema = Type.Object(\n {\n includeActions: Type.Optional(\n Type.Boolean({\n default: false,\n description: 'Return each trigger with its ordered `actions` resolved, in a single request',\n }),\n ),\n },\n { title: 'IncludeActionsQuery', description: 'Opt-in flag to embed the actions of a trigger' },\n)\n\n// Written out rather than derived from `automaticTriggerSchema`: a request schema and an entity\n// schema answer different questions — what a client may send vs what a row holds — and only the\n// first can close itself. `additionalProperties: false` does not survive `Type.Intersect`, so a\n// derived payload had to be cleaned before validating, which dropped unknown keys silently. Spelled\n// out, an undeclared key is a 400 that names it, and `id`/`project_id` are absent because the server\n// owns them, not because an `Omit` removed them.\nexport const createAutomaticTriggerSchema = Type.Object(\n {\n name: triggerNameSchema,\n description: triggerDescriptionSchema,\n source: triggerSourceSchema,\n target: Type.Optional(\n Type.Union([Type.String({ maxLength: 255 }), Type.Null()], {\n description: 'Concrete model/designer/field the event refers to. Null for sourceless events',\n }),\n ),\n operation: Type.Optional(\n Type.Union([triggerOperationSchema, Type.Null()], {\n description: 'Operation on the target that fires the trigger. Null when not applicable',\n }),\n ),\n conditions: Type.Optional(\n Type.Union([Type.Object({}, { additionalProperties: true }), Type.Null()], {\n description: 'jsonLogic conditions (root object) evaluated to decide whether the trigger runs',\n }),\n ),\n relations: Type.Optional(\n Type.Union([triggerRelationsSchema, Type.Null()], {\n description:\n 'Related models loaded into the context before evaluating the conditions and running the actions. Null means none.',\n }),\n ),\n enabled: Type.Optional(Type.Boolean({ description: 'Whether the trigger is active' })),\n retention_days: Type.Optional(\n Type.Union([Type.Number(), Type.Null()], {\n description:\n 'Retention in days for the process_log entries of this trigger. Origin — no inheritance: null or 0 = disabled (never expires); N (>0) = enabled (expires N days after write).',\n }),\n ),\n actions: Type.Optional(triggerActionsInputSchema),\n },\n {\n title: 'CreateAutomaticTrigger',\n description: 'Payload used to create an automatic trigger, optionally with the actions it runs',\n additionalProperties: false,\n },\n)\nexport type CreateAutomaticTriggerData = Static<typeof createAutomaticTriggerSchema>\n\n// `actions` is inherited from the create schema and stays optional here, which is\n// what the update contract wants: absent leaves the links untouched, present\n// replaces the whole ordered set (never merges), `[]` leaves the trigger with none.\n// `additionalProperties: false` is restated: `Type.Partial` rebuilds the object and drops the\n// options of the schema it derives from, so inheriting it would leave this payload open.\nexport const updateAutomaticTriggerSchema = Type.Partial(createAutomaticTriggerSchema, {\n title: 'UpdateAutomaticTrigger',\n description: 'Payload used to update an automatic trigger, optionally replacing the actions it runs',\n additionalProperties: false,\n})\nexport type UpdateAutomaticTriggerData = Static<typeof updateAutomaticTriggerSchema>\n\n// ── manual_trigger ────────────────────────────────────────────────────\n\n// What the consumer does with the button when the trigger conditions do not hold. It lives at the\n// root of the config, outside `styles`, so no conditional style can reach it: whether the button is\n// active is decided by the trigger conditions alone, and the style system only dresses it.\nexport const UnmatchedBehavior = {\n HIDE: 'hide',\n DISABLE: 'disable',\n} as const\nexport const unmatchedBehaviorSchema = Type.Enum(Object.values(UnmatchedBehavior), {\n title: 'UnmatchedBehavior',\n description: 'What to do with the button when the trigger does not match: hide it or disable it',\n})\nexport type UnmatchedBehavior = Static<typeof unmatchedBehaviorSchema>\n\nexport const IconPosition = {\n LEFT: 'left',\n RIGHT: 'right',\n} as const\nexport const iconPositionSchema = Type.Enum(Object.values(IconPosition), {\n title: 'IconPosition',\n description: 'Side of the label the icon sits on',\n})\nexport type IconPosition = Static<typeof iconPositionSchema>\n\nexport const manualTriggerButtonStyleSchema = Type.Object(\n {\n text: Type.Optional(Type.String({ description: 'Handlebars template rendered as the button label' })),\n tooltip: Type.Optional(\n Type.String({\n description:\n 'Handlebars template rendered as the button tooltip. Written for whoever uses the listing, unlike `name`, which labels the trigger where it is administered',\n }),\n ),\n textColor: Type.Optional(Type.String({ description: 'Label colour' })),\n bgColor: Type.Optional(Type.String({ description: 'Background colour' })),\n icon: Type.Optional(Type.String({ description: 'Icon name, resolved by the consumer' })),\n iconPosition: Type.Optional(iconPositionSchema),\n },\n { title: 'ManualTriggerButtonStyle', description: 'Presentation of the button a manual trigger is offered on' },\n)\nexport type ManualTriggerButtonStyleData = Static<typeof manualTriggerButtonStyleSchema>\n\n// Same shape as the base style plus the conditions that select it. Every style field is optional:\n// an entry only overrides what it declares.\nexport const manualTriggerConditionalStyleSchema = Type.Intersect(\n [\n manualTriggerButtonStyleSchema,\n Type.Object({\n conditions: Type.Optional(\n Type.Union([Type.Object({}, { additionalProperties: true }), Type.Null()], {\n description: 'jsonLogic conditions selecting this style. Absent or null always applies',\n }),\n ),\n continueEvaluate: Type.Optional(\n Type.Boolean({ description: 'Keep evaluating later entries after this one matches' }),\n ),\n }),\n ],\n { title: 'ManualTriggerConditionalStyle' },\n)\nexport type ManualTriggerConditionalStyleData = Static<typeof manualTriggerConditionalStyleSchema>\n\n/**\n * Envelope for everything a manual trigger configures beyond its firing rules. Today it carries\n * whether an unmatched trigger is hidden or shown disabled, plus the button presentation;\n * `additionalProperties` stays open so a future concern can be added without another column.\n *\n * The two are deliberately separate concerns: `unmatchedBehavior` answers whether the button is\n * offered at all, which only the trigger `conditions` decide, while `styles`/`conditionalStyles`\n * only dress a button that is already going to be shown.\n */\nexport const manualTriggerConfigSchema = Type.Object(\n {\n unmatchedBehavior: Type.Optional(unmatchedBehaviorSchema),\n styles: Type.Optional(manualTriggerButtonStyleSchema),\n conditionalStyles: Type.Optional(Type.Array(manualTriggerConditionalStyleSchema)),\n },\n { title: 'ManualTriggerConfig', additionalProperties: true },\n)\nexport type ManualTriggerConfigData = Static<typeof manualTriggerConfigSchema>\n\nexport const manualTriggerSchema = Type.Object(\n {\n id: Type.Number({ description: 'Unique identifier of the manual trigger' }),\n project_id: Type.Optional(\n Type.Union([Type.Number(), Type.Null()], {\n description: 'Project this trigger belongs to. Null when it is ecosystem-wide',\n }),\n ),\n name: triggerNameSchema,\n description: triggerDescriptionSchema,\n source: triggerSourceSchema,\n target: Type.String({\n maxLength: 255,\n description: 'Concrete model/designer/field the trigger is bound to. Always set: there is no wildcard',\n }),\n conditions: Type.Optional(\n Type.Union([Type.Object({}, { additionalProperties: true }), Type.Null()], {\n description:\n 'jsonLogic conditions (root object) evaluated to decide whether the trigger runs. Evaluated against the selected entity and the request context; `old` is always null, because the trigger is invoked explicitly and there is no previous state to compare against.',\n }),\n ),\n relations: Type.Optional(\n Type.Union([triggerRelationsSchema, Type.Null()], {\n description:\n 'Related models loaded into the context before evaluating the conditions and running the actions. Null means none.',\n }),\n ),\n enabled: Type.Optional(Type.Boolean({ description: 'Whether the trigger is active' })),\n retention_days: Type.Optional(\n Type.Union([Type.Number(), Type.Null()], {\n description:\n 'Retention in days for the process_log entries of this trigger. Origin — no inheritance: null or 0 = disabled (never expires); N (>0) = enabled (expires N days after write).',\n }),\n ),\n config: Type.Optional(\n Type.Union([manualTriggerConfigSchema, Type.Null()], {\n description: 'Configuration of the trigger beyond its firing rules. Null means none',\n }),\n ),\n },\n { title: 'ManualTrigger', description: 'Manual trigger definition (ecosystem level)' },\n)\nexport type ManualTriggerData = Static<typeof manualTriggerSchema>\n\n// Written out and closed, for the same reasons as `createAutomaticTriggerSchema` above.\nexport const createManualTriggerSchema = Type.Object(\n {\n name: triggerNameSchema,\n description: triggerDescriptionSchema,\n source: triggerSourceSchema,\n target: Type.String({\n maxLength: 255,\n description: 'Concrete model/designer/field the trigger is bound to. Always set: there is no wildcard',\n }),\n conditions: Type.Optional(\n Type.Union([Type.Object({}, { additionalProperties: true }), Type.Null()], {\n description:\n 'jsonLogic conditions (root object) evaluated to decide whether the trigger runs. Evaluated against the selected entity and the request context; `old` is always null, because the trigger is invoked explicitly and there is no previous state to compare against.',\n }),\n ),\n relations: Type.Optional(\n Type.Union([triggerRelationsSchema, Type.Null()], {\n description:\n 'Related models loaded into the context before evaluating the conditions and running the actions. Null means none.',\n }),\n ),\n enabled: Type.Optional(Type.Boolean({ description: 'Whether the trigger is active' })),\n retention_days: Type.Optional(\n Type.Union([Type.Number(), Type.Null()], {\n description:\n 'Retention in days for the process_log entries of this trigger. Origin — no inheritance: null or 0 = disabled (never expires); N (>0) = enabled (expires N days after write).',\n }),\n ),\n config: Type.Optional(\n Type.Union([manualTriggerConfigSchema, Type.Null()], {\n description: 'Configuration of the trigger beyond its firing rules. Null means none',\n }),\n ),\n actions: Type.Optional(triggerActionsInputSchema),\n },\n {\n title: 'CreateManualTrigger',\n description: 'Payload used to create a manual trigger, optionally with the actions it runs',\n additionalProperties: false,\n },\n)\nexport type CreateManualTriggerData = Static<typeof createManualTriggerSchema>\n\n// Same inheritance and semantics as `updateAutomaticTriggerSchema`.\nexport const updateManualTriggerSchema = Type.Partial(createManualTriggerSchema, {\n title: 'UpdateManualTrigger',\n description: 'Payload used to update a manual trigger, optionally replacing the actions it runs',\n additionalProperties: false,\n})\nexport type UpdateManualTriggerData = Static<typeof updateManualTriggerSchema>\n\n// What the listing endpoint returns per applicable manual trigger: enough to\n// render it and nothing more. Only triggers that are going to be shown are\n// listed, so `matched: false` means a button rendered disabled, never a hidden\n// one. `matched` is never an authorisation: running re-evaluates server-side.\nexport const manualTriggerAvailabilitySchema = Type.Object(\n {\n id: Type.Number({ description: 'Identifier of the manual trigger' }),\n name: triggerNameSchema,\n matched: Type.Boolean({\n description:\n 'Whether the trigger conditions hold for this entity right now. A trigger with no conditions always matches. False means the button is shown disabled: triggers configured to hide when unmatched are not listed',\n }),\n actionsCount: Type.Number({ description: 'Number of actions the trigger would run' }),\n relationsSkipped: Type.Optional(\n Type.Union([Type.String(), Type.Null()], {\n description:\n 'Reason the declared relations could not be loaded before evaluating, when that happened. Null otherwise',\n }),\n ),\n /**\n * Resolved server-side: conditional styles already evaluated and label already compiled. Absent\n * when the trigger has no config — the consumer then paints its own default button.\n */\n style: Type.Optional(manualTriggerButtonStyleSchema),\n },\n {\n title: 'ManualTriggerAvailability',\n description: 'A manual trigger applicable to an entity, with its conditions already evaluated',\n },\n)\nexport type ManualTriggerAvailability = Static<typeof manualTriggerAvailabilitySchema>\n\nexport const manualTriggerAvailabilityListSchema = Type.Object(\n { results: Type.Array(manualTriggerAvailabilitySchema, { description: 'Applicable manual triggers' }) },\n {\n title: 'ManualTriggerAvailabilityList',\n description: 'Manual triggers applicable to an entity, with their conditions evaluated',\n },\n)\n\n// Query the listing endpoint is called with: the entity the triggers are offered\n// on. `source`/`target` are the coordinates a manual trigger is bound to, and\n// `entityId` the concrete row.\nexport const manualTriggerAvailabilityQuerySchema = Type.Object(\n {\n source: triggerSourceSchema,\n target: Type.String({ maxLength: 255, description: 'Concrete model/designer/field the triggers are bound to' }),\n entityId: Type.Number({ description: 'Identifier of the entity the triggers would run against' }),\n },\n { title: 'ManualTriggerAvailabilityQuery', description: 'Entity the applicable manual triggers are listed for' },\n)\nexport type ManualTriggerAvailabilityQuery = Static<typeof manualTriggerAvailabilityQuerySchema>\n\n// Body of the run endpoint. It carries only the entity: `source`/`target` are\n// read from the trigger row, never from the client, so a trigger cannot be\n// re-pointed at an entity it was not bound to.\nexport const runManualTriggerSchema = Type.Object(\n { entityId: Type.Number({ description: 'Identifier of the entity to run the trigger against' }) },\n { title: 'RunManualTrigger', description: 'Payload used to run a manual trigger against an entity' },\n)\nexport type RunManualTriggerData = Static<typeof runManualTriggerSchema>\n\n// ── automatic_trigger_action (intermediate N:M automatic_trigger↔actions,\n// ordered) ──────────────────────────────────────────────────────────────\n// Dedicated table per trigger kind (no ORM polymorphism): `automatic_trigger_id`\n// is a real FK. `manual_trigger_action` is a future table for manual triggers.\n\nexport const automaticTriggerActionSchema = Type.Object(\n {\n id: Type.Number({ description: 'Unique identifier of the trigger-action link' }),\n automatic_trigger_id: Type.Number({\n description: 'Automatic trigger executing the action (FK to automatic_trigger)',\n }),\n action_id: Type.Number({ description: 'Action executed by the trigger (FK to actions)' }),\n execution_order: Type.Number({ description: 'Execution order of the action within the trigger' }),\n },\n { title: 'AutomaticTriggerAction', description: 'Ordered link between an automatic trigger and an action' },\n)\nexport type AutomaticTriggerActionData = Static<typeof automaticTriggerActionSchema>\n\n// ── manual_trigger_action (intermediate N:M manual_trigger↔actions,\n// ordered) ──────────────────────────────────────────────────────────────\n// Same dedicated-table-per-trigger-kind rule as `automatic_trigger_action`:\n// `manual_trigger_id` is a real FK, and the `actions` catalog is shared\n// between kinds — only the link table differs.\n\nexport const manualTriggerActionSchema = Type.Object(\n {\n id: Type.Number({ description: 'Unique identifier of the trigger-action link' }),\n manual_trigger_id: Type.Number({\n description: 'Manual trigger executing the action (FK to manual_trigger)',\n }),\n action_id: Type.Number({ description: 'Action executed by the trigger (FK to actions)' }),\n execution_order: Type.Number({ description: 'Execution order of the action within the trigger' }),\n },\n { title: 'ManualTriggerAction', description: 'Ordered link between a manual trigger and an action' },\n)\nexport type ManualTriggerActionData = Static<typeof manualTriggerActionSchema>\n\n// ── Declarative trigger↔actions contract ──────────────────────────────\n// The link tables are written as a whole through the `actions` field of the trigger payload,\n// never row by row. The array position IS the `execution_order`, so ordering can\n// never disagree with the list the client sent — which per-row endpoints allowed\n// (duplicate or gapped orders after a reorder). Shared by both trigger kinds:\n// only the parent FK differs, and that comes from the URL.\n//\n// The field is `actions`, not `action_ids`: items are no longer only ids (see\n// `triggerActionInputSchema`). Same body as the `actions` field of the create and\n// update trigger payloads, so the three ways of writing the set agree.\n\n// What create/update answer with. `actions` carries the resolved catalog rows —\n// not the link rows — so a client that sent actions inline learns the ids they\n// were given without chaining a second request. It is present only when the\n// request carried the field: a create/update that did not mention actions says\n// nothing about them, rather than reporting an empty set it never touched.\nconst withResolvedActions = Type.Object({\n actions: Type.Optional(Type.Array(actionSchema, { description: 'Actions the trigger runs, in execution order' })),\n})\n\nexport const automaticTriggerWithActionsSchema = Type.Intersect([automaticTriggerSchema, withResolvedActions], {\n title: 'AutomaticTriggerWithActions',\n description:\n 'An automatic trigger and, when the request wrote them or `includeActions` asked for them, the actions it runs',\n})\nexport type AutomaticTriggerWithActionsData = Static<typeof automaticTriggerWithActionsSchema>\n\nexport const manualTriggerWithActionsSchema = Type.Intersect([manualTriggerSchema, withResolvedActions], {\n title: 'ManualTriggerWithActions',\n description:\n 'A manual trigger and, when the request wrote them or `includeActions` asked for them, the actions it runs',\n})\nexport type ManualTriggerWithActionsData = Static<typeof manualTriggerWithActionsSchema>\n\n// ── Execution engine (pure, model-independent contract types) ──────────\n// Exported types the engine (service/helper) works with. Kept here (rather\n// than in service/helper) so they can be imported without pulling in\n// service/helper code. None of them references a model: the engine types\n// itself structurally (see the `*Like` shapes below).\n\nexport interface ActionEvent {\n source: TriggerSource\n target?: string | null\n operation?: TriggerOperation | null\n current: Record<string, unknown>\n old?: Record<string, unknown> | null\n}\n\n// Outcome of evaluating (and, when matched, running) a single trigger. Declared\n// as a TypeBox schema — not just an interface — because the manual-trigger run\n// endpoint returns it verbatim; `TriggerExecutionResult` is its static type, so\n// engine and endpoint cannot drift apart.\nexport const triggerExecutionResultSchema = Type.Object(\n {\n triggerId: Type.Number({ description: 'Identifier of the evaluated trigger' }),\n matched: Type.Boolean({ description: 'Whether the conditions held, so the actions were run' }),\n actionsRun: Type.Number({ description: 'Number of actions that were executed, whether they succeeded or not' }),\n actionsAborted: Type.Number({ description: 'Number of actions aborted by context validation' }),\n actionsFailed: Type.Number({\n description: 'Number of executed actions that ended in error. A subset of actionsRun',\n }),\n },\n { title: 'TriggerExecutionResult', description: 'Outcome of evaluating and running one trigger' },\n)\nexport type TriggerExecutionResult = Static<typeof triggerExecutionResultSchema>\n\n// ── Trigger-kind-agnostic engine contract ─────────────────────────────\n// The execution engine is shared by every kind of trigger: it consumes the\n// minimal structural shapes below rather than a concrete model, so a new kind\n// only has to resolve its own candidates and hand them over. The `*Like` types\n// are deliberately structural (not the Objection classes) so the engine never\n// imports a model to type itself — `AutomaticTrigger` / `AutomaticTriggerAction`\n// / `Action` satisfy them as they are, without a cast.\n\n/**\n * Structural shape the engine needs from an action it is about to run: the\n * identity it logs, the `type` that selects the validation/dispatch branch, the\n * config it executes with, and the retention it resolves `expires_at` from.\n * Deliberately loose (`type: string`, not `ActionType`) so an unknown type still\n * reaches the always-blocking context validation instead of failing to typecheck.\n */\nexport interface ActionLike {\n id: number\n type: string\n config: ActionConfig\n retention_days?: number | null\n}\n\n/** Ordered trigger↔action link in the minimal shape the engine consumes. */\nexport interface TriggerActionLike {\n action_id: number\n execution_order: number\n action?: ActionLike\n}\n\n/** Minimal shape of a trigger for the engine, whatever its kind. */\nexport interface EvaluableTrigger {\n id: number\n conditions?: object | null\n relations?: TriggerRelations | null\n retention_days?: number | null\n trigger_actions?: TriggerActionLike[]\n}\n\n/**\n * A batch of already-resolved candidates a trigger kind hands to the engine,\n * together with the event data they were resolved for. `relatedModel` is what\n * the evaluation `process_log` row is related to (the trigger table of that\n * kind), which is how trigger evaluations stay independently queryable per kind.\n */\nexport interface TriggerBatch<T extends EvaluableTrigger = EvaluableTrigger> {\n triggers: T[]\n relatedModel: string\n source: TriggerSource\n target?: string | null\n operation?: TriggerOperation | null\n current: Record<string, unknown>\n old?: Record<string, unknown> | null\n}\n\n// ── Context validation (pure data types) ────────────────────────────────\n\nexport interface ContextValidationResult {\n ok: boolean\n type: string\n baseErrors: { path: string; message: string }[]\n missingRefs: string[]\n referencedRefs: string[]\n overridableErrors: string[]\n}\n\n// Structural shape `buildEffectiveConfig`/`validateActionContext` need from an\n// action config — deliberately loose (not `ActionConfig`) so it works for any\n// current or future type without a cast at every call site.\nexport interface ActionConfigLike {\n payload?: Record<string, unknown>\n overridable?: string[]\n default?: Record<string, unknown>\n}\n\nexport interface EffectiveConfigResult {\n effective: Record<string, unknown>\n overridableErrors: string[]\n}\n\n// ── Route-level schemas ───────────────────────────────────────────────\n// Shared by every router of the module.\n\nexport const successResponseSchema = Type.Object(\n { success: Type.Boolean({ description: 'If the request success or not' }) },\n { title: 'ActionSystemSuccessResponse', description: 'Response when the request is successful' },\n)\n\nexport const withIdParamsSchema = Type.Intersect(\n [ecosystemProjectParamsSchema, Type.Object({ id: Type.Number({ description: 'Entity ID' }) })],\n { title: 'EcosystemProjectWithActionSystemIdParams', description: 'Params with ecosystem, project and entity ID' },\n)\n"],"names":[],"mappings":";AAEO,MAAM,wBAAwB,KAAK;AAAA,EACxC;AAAA,IACE,eAAe,KAAK,OAAO,EAAE,WAAW,KAAK,aAAa,uBAAuB;AAAA,EAAA;AAAA,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A4C,aAAa,+CAAA;AACpE;"}
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const globalDates = require("./lib-CDM5aEJG.cjs");
3
+ const dates_helper = require("./dates.helper-CDM5aEJG.cjs");
4
4
  const globalLocale = require("./global-locale.cjs");
5
5
  function resolveTrendWindow(nowMs, config, weekStart = globalLocale.getWeekStart(), utc = false) {
6
6
  const { fromValue, unit } = config;
7
7
  const toValue = config.toValue ?? 0;
8
8
  return {
9
- start: globalDates.getPeriodStart(globalDates.subtractPeriods(nowMs, fromValue, unit, utc), unit, weekStart, utc),
10
- end: globalDates.getPeriodStart(globalDates.subtractPeriods(nowMs, toValue - 1, unit, utc), unit, weekStart, utc)
9
+ start: dates_helper.getPeriodStart(dates_helper.subtractPeriods(nowMs, fromValue, unit, utc), unit, weekStart, utc),
10
+ end: dates_helper.getPeriodStart(dates_helper.subtractPeriods(nowMs, toValue - 1, unit, utc), unit, weekStart, utc)
11
11
  };
12
12
  }
13
13
  function resolveRelativePeriod(nowMs, { value, unit, excludeCurrentPeriod = false }, weekStart = globalLocale.getWeekStart(), utc = false) {
@@ -21,11 +21,11 @@ function resolveRelativePeriod(nowMs, { value, unit, excludeCurrentPeriod = fals
21
21
  function resolveRelativeDateRange(nowMs, config, format, weekStart = globalLocale.getWeekStart(), utc = false) {
22
22
  const { start, end } = resolveRelativePeriod(nowMs, config, weekStart, utc);
23
23
  const cappedEnd = Math.min(end, nowMs);
24
- const startDate = globalDates.toCalendar(start, utc);
24
+ const startDate = dates_helper.toCalendar(start, utc);
25
25
  if (format === "discrete") {
26
- return { start_date: startDate.toISOString(), end_date: globalDates.toCalendar(cappedEnd, utc).toISOString() };
26
+ return { start_date: startDate.toISOString(), end_date: dates_helper.toCalendar(cappedEnd, utc).toISOString() };
27
27
  }
28
- const endDate = config.excludeCurrentPeriod ? globalDates.toCalendar(end, utc).subtract(1, "day") : globalDates.toCalendar(cappedEnd, utc);
28
+ const endDate = config.excludeCurrentPeriod ? dates_helper.toCalendar(end, utc).subtract(1, "day") : dates_helper.toCalendar(cappedEnd, utc);
29
29
  return { start_date: startDate.format("YYYY-MM-DD"), end_date: endDate.format("YYYY-MM-DD") };
30
30
  }
31
31
  exports.resolveRelativeDateRange = resolveRelativeDateRange;