@abyss-project/reflex 6.6.0 → 6.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (268) hide show
  1. package/.eslintrc.js +32 -32
  2. package/.prettierrc +5 -5
  3. package/README.md +15 -15
  4. package/dist/api/function-run.api.d.ts +1 -2
  5. package/dist/api/function-run.api.js +1 -3
  6. package/dist/api/function-run.api.js.map +1 -1
  7. package/dist/api/index.d.ts +1 -0
  8. package/dist/api/index.js +1 -0
  9. package/dist/api/index.js.map +1 -1
  10. package/dist/api/reflex-admin.admin.api.d.ts +5 -0
  11. package/dist/api/reflex-admin.admin.api.js +18 -0
  12. package/dist/api/reflex-admin.admin.api.js.map +1 -0
  13. package/dist/discord/discord-event-filter-cases.js +11 -27
  14. package/dist/discord/discord-event-filter-cases.js.map +1 -1
  15. package/dist/discord/discord-event-filters.js +3 -7
  16. package/dist/discord/discord-event-filters.js.map +1 -1
  17. package/dist/discord/discord-event-intents.d.ts +2 -8
  18. package/dist/discord/discord-event-intents.js +2 -13
  19. package/dist/discord/discord-event-intents.js.map +1 -1
  20. package/dist/discord/index.d.ts +0 -1
  21. package/dist/discord/index.js +0 -1
  22. package/dist/discord/index.js.map +1 -1
  23. package/dist/index.d.ts +13 -1
  24. package/dist/index.js +13 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/types/enum/discord-event-type.enum.d.ts +1 -3
  27. package/dist/types/enum/discord-event-type.enum.js +0 -2
  28. package/dist/types/enum/discord-event-type.enum.js.map +1 -1
  29. package/dist/types/enum/index.d.ts +2 -2
  30. package/dist/types/enum/index.js +2 -2
  31. package/dist/types/enum/index.js.map +1 -1
  32. package/dist/types/enum/reflex-abuse-rule.enum.d.ts +5 -0
  33. package/dist/types/enum/reflex-abuse-rule.enum.js +10 -0
  34. package/dist/types/enum/reflex-abuse-rule.enum.js.map +1 -0
  35. package/dist/types/enum/reflex-admin-hold-kind.enum.d.ts +4 -0
  36. package/dist/types/enum/reflex-admin-hold-kind.enum.js +9 -0
  37. package/dist/types/enum/reflex-admin-hold-kind.enum.js.map +1 -0
  38. package/dist/types/enum/reflex-error-code.enum.d.ts +3 -11
  39. package/dist/types/enum/reflex-error-code.enum.js +2 -10
  40. package/dist/types/enum/reflex-error-code.enum.js.map +1 -1
  41. package/dist/types/interface/api/requests/function-run.request.d.ts +0 -8
  42. package/dist/types/interface/api/requests/index.d.ts +1 -0
  43. package/dist/types/interface/api/requests/index.js +1 -0
  44. package/dist/types/interface/api/requests/index.js.map +1 -1
  45. package/dist/types/interface/api/requests/reflex-admin.admin.request.d.ts +21 -0
  46. package/dist/types/interface/api/requests/reflex-admin.admin.request.js +3 -0
  47. package/dist/types/interface/api/requests/reflex-admin.admin.request.js.map +1 -0
  48. package/dist/types/interface/api/requests/service-discord.request.d.ts +3 -7
  49. package/dist/types/interface/api/responses/function-run.response.d.ts +0 -8
  50. package/dist/types/interface/api/responses/index.d.ts +1 -0
  51. package/dist/types/interface/api/responses/index.js +1 -0
  52. package/dist/types/interface/api/responses/index.js.map +1 -1
  53. package/dist/types/interface/api/responses/reflex-admin.admin.response.d.ts +19 -0
  54. package/dist/types/interface/api/responses/reflex-admin.admin.response.js +3 -0
  55. package/dist/types/interface/api/responses/reflex-admin.admin.response.js.map +1 -0
  56. package/dist/types/interface/models/index.d.ts +1 -0
  57. package/dist/types/interface/models/index.js +1 -0
  58. package/dist/types/interface/models/index.js.map +1 -1
  59. package/dist/types/interface/models/reflex-admin-hold.model.d.ts +44 -0
  60. package/dist/types/interface/models/reflex-admin-hold.model.js +11 -0
  61. package/dist/types/interface/models/reflex-admin-hold.model.js.map +1 -0
  62. package/dist/types/interface/models/reflex-discord.model.d.ts +2 -18
  63. package/dist/types/interface/models/reflex-discord.model.js +0 -4
  64. package/dist/types/interface/models/reflex-discord.model.js.map +1 -1
  65. package/dist/types/interface/models/reflex-run.model.d.ts +0 -4
  66. package/dist/types/interface/models/reflex-run.model.js +1 -4
  67. package/dist/types/interface/models/reflex-run.model.js.map +1 -1
  68. package/dist/types/interface/models/reflex-service-deployment.model.d.ts +2 -1
  69. package/dist/types/interface/models/reflex-service.model.d.ts +2 -0
  70. package/dist/types/interface/models/reflex-service.model.js.map +1 -1
  71. package/jest.config.ts +11 -11
  72. package/package.json +1 -1
  73. package/src/api/alert-rule.api.test.ts +72 -72
  74. package/src/api/alert-rule.api.ts +57 -57
  75. package/src/api/application-insights.api.test.ts +42 -42
  76. package/src/api/application-insights.api.ts +38 -38
  77. package/src/api/application-run-settings.api.ts +30 -30
  78. package/src/api/function-access.api.ts +87 -87
  79. package/src/api/function-insights.api.test.ts +27 -27
  80. package/src/api/function-insights.api.ts +18 -18
  81. package/src/api/function-run.api.ts +53 -72
  82. package/src/api/function-template.api.test.ts +72 -72
  83. package/src/api/function-template.api.ts +52 -52
  84. package/src/api/function-test.api.ts +34 -34
  85. package/src/api/function-version.api.ts +66 -66
  86. package/src/api/function.api.ts +62 -62
  87. package/src/api/health.api.ts +10 -10
  88. package/src/api/index.ts +1 -0
  89. package/src/api/reflex-admin.admin.api.test.ts +52 -0
  90. package/src/api/reflex-admin.admin.api.ts +53 -0
  91. package/src/api/route-stats.api.test.ts +45 -45
  92. package/src/api/route-stats.api.ts +36 -36
  93. package/src/api/service-completion-webhook.api.test.ts +97 -97
  94. package/src/api/service-completion-webhook.api.ts +39 -39
  95. package/src/api/service-configuration.api.ts +16 -16
  96. package/src/api/service-consumer.api.test.ts +104 -104
  97. package/src/api/service-consumer.api.ts +90 -90
  98. package/src/api/service-deployment.api.ts +79 -79
  99. package/src/api/service-discord-event.api.test.ts +106 -106
  100. package/src/api/service-discord-event.api.ts +78 -78
  101. package/src/api/service-discord.api.test.ts +178 -178
  102. package/src/api/service-discord.api.ts +222 -222
  103. package/src/api/service-insights.api.test.ts +36 -36
  104. package/src/api/service-insights.api.ts +42 -42
  105. package/src/api/service-limits.api.test.ts +100 -100
  106. package/src/api/service-limits.api.ts +37 -37
  107. package/src/api/service-openapi.api.test.ts +52 -52
  108. package/src/api/service-openapi.api.ts +21 -21
  109. package/src/api/service-route.api.ts +74 -74
  110. package/src/api/service-task.api.test.ts +140 -140
  111. package/src/api/service-task.api.ts +141 -141
  112. package/src/api/service-version.api.ts +54 -54
  113. package/src/api/service.api.ts +55 -55
  114. package/src/discord/discord-event-filter-cases.ts +261 -299
  115. package/src/discord/discord-event-filters.test.ts +91 -120
  116. package/src/discord/discord-event-filters.ts +95 -103
  117. package/src/discord/discord-event-intents.test.ts +112 -139
  118. package/src/discord/discord-event-intents.ts +55 -80
  119. package/src/discord/index.ts +3 -4
  120. package/src/index.test.ts +104 -104
  121. package/src/index.ts +26 -2
  122. package/src/insights/index.ts +1 -1
  123. package/src/insights/percentiles.test.ts +75 -75
  124. package/src/insights/percentiles.ts +37 -37
  125. package/src/types/enum/access-grant-status.enum.ts +12 -12
  126. package/src/types/enum/access-kind.enum.ts +7 -7
  127. package/src/types/enum/access-request-status.enum.ts +11 -11
  128. package/src/types/enum/bot-event-block-reason.enum.ts +7 -7
  129. package/src/types/enum/completion-delivery-status.enum.ts +9 -9
  130. package/src/types/enum/configuration-read-as.enum.ts +5 -5
  131. package/src/types/enum/discord-activity-type.enum.ts +9 -9
  132. package/src/types/enum/discord-channel-type.enum.ts +11 -11
  133. package/src/types/enum/discord-component-kind.enum.ts +7 -7
  134. package/src/types/enum/discord-event-drop-reason.enum.ts +13 -13
  135. package/src/types/enum/discord-event-filter-name.enum.ts +11 -11
  136. package/src/types/enum/discord-event-status.enum.ts +13 -13
  137. package/src/types/enum/discord-event-type.enum.ts +7 -11
  138. package/src/types/enum/discord-gateway-failure-code.enum.ts +11 -11
  139. package/src/types/enum/discord-gateway-state.enum.ts +11 -11
  140. package/src/types/enum/discord-host-action.enum.ts +37 -37
  141. package/src/types/enum/discord-locale.enum.ts +35 -35
  142. package/src/types/enum/discord-option-type.enum.ts +12 -12
  143. package/src/types/enum/discord-presence-status.enum.ts +8 -8
  144. package/src/types/enum/discord-sync-status.enum.ts +6 -6
  145. package/src/types/enum/discord-token-state.enum.ts +11 -11
  146. package/src/types/enum/execution-mode.enum.ts +9 -9
  147. package/src/types/enum/execution-profile.enum.ts +20 -20
  148. package/src/types/enum/execution-settings-source.enum.ts +9 -9
  149. package/src/types/enum/health-status.enum.ts +4 -4
  150. package/src/types/enum/index.ts +53 -53
  151. package/src/types/enum/insights-period.enum.ts +8 -8
  152. package/src/types/enum/log-cap-mode.enum.ts +6 -6
  153. package/src/types/enum/log-drop-cause.enum.ts +8 -8
  154. package/src/types/enum/reflex-abuse-rule.enum.ts +9 -0
  155. package/src/types/enum/reflex-admin-hold-kind.enum.ts +7 -0
  156. package/src/types/enum/reflex-error-code.enum.ts +7 -23
  157. package/src/types/enum/route-method.enum.ts +9 -9
  158. package/src/types/enum/run-log-level.enum.ts +6 -6
  159. package/src/types/enum/run-mode.enum.ts +11 -11
  160. package/src/types/enum/run-status.enum.ts +16 -16
  161. package/src/types/enum/run-step-status.enum.ts +7 -7
  162. package/src/types/enum/schedule-sync-status.enum.ts +6 -6
  163. package/src/types/enum/scheduled-run-failure-code.enum.ts +14 -14
  164. package/src/types/enum/scheduled-run-origin.enum.ts +5 -5
  165. package/src/types/enum/scheduled-run-status.enum.ts +17 -17
  166. package/src/types/enum/service-block-reason.enum.ts +13 -13
  167. package/src/types/enum/service-deployment-action.enum.ts +11 -11
  168. package/src/types/enum/service-deployment-status.enum.ts +5 -5
  169. package/src/types/enum/service-type.enum.ts +9 -9
  170. package/src/types/enum/service-version-change-kind.enum.ts +6 -6
  171. package/src/types/enum/trace-effect-type.enum.ts +12 -12
  172. package/src/types/enum/trigger-access-mode.enum.ts +12 -12
  173. package/src/types/enum/trigger-kind.enum.ts +8 -8
  174. package/src/types/enum/vault-value-source.enum.ts +12 -12
  175. package/src/types/enum/vault-visibility.enum.ts +5 -5
  176. package/src/types/index.ts +2 -2
  177. package/src/types/interface/api/index.ts +3 -3
  178. package/src/types/interface/api/requests/alert-rule.request.ts +53 -53
  179. package/src/types/interface/api/requests/application-insights.request.ts +18 -18
  180. package/src/types/interface/api/requests/function-access.request.ts +51 -51
  181. package/src/types/interface/api/requests/function-run.request.ts +0 -11
  182. package/src/types/interface/api/requests/function-template.request.ts +29 -29
  183. package/src/types/interface/api/requests/function-test.request.ts +44 -44
  184. package/src/types/interface/api/requests/function-version.request.ts +38 -38
  185. package/src/types/interface/api/requests/function.request.ts +36 -36
  186. package/src/types/interface/api/requests/index.ts +1 -0
  187. package/src/types/interface/api/requests/reflex-admin.admin.request.ts +26 -0
  188. package/src/types/interface/api/requests/route-stats.request.ts +22 -22
  189. package/src/types/interface/api/requests/service-completion-webhook.request.ts +11 -11
  190. package/src/types/interface/api/requests/service-configuration.request.ts +4 -4
  191. package/src/types/interface/api/requests/service-consumer.request.ts +51 -51
  192. package/src/types/interface/api/requests/service-deployment.request.ts +49 -49
  193. package/src/types/interface/api/requests/service-discord-event.request.ts +68 -68
  194. package/src/types/interface/api/requests/service-discord.request.ts +155 -168
  195. package/src/types/interface/api/requests/service-insights.request.ts +31 -31
  196. package/src/types/interface/api/requests/service-limits.request.ts +28 -28
  197. package/src/types/interface/api/requests/service-openapi.request.ts +10 -10
  198. package/src/types/interface/api/requests/service-route.request.ts +52 -52
  199. package/src/types/interface/api/requests/service-task.request.ts +80 -80
  200. package/src/types/interface/api/requests/service-version.request.ts +24 -24
  201. package/src/types/interface/api/response.ts +4 -4
  202. package/src/types/interface/api/responses/alert-rule.response.ts +24 -24
  203. package/src/types/interface/api/responses/application-insights.response.ts +11 -11
  204. package/src/types/interface/api/responses/application-run-settings.response.ts +8 -8
  205. package/src/types/interface/api/responses/function-access.response.ts +45 -45
  206. package/src/types/interface/api/responses/function-run.response.ts +0 -12
  207. package/src/types/interface/api/responses/function-template.response.ts +21 -21
  208. package/src/types/interface/api/responses/function-test.response.ts +19 -19
  209. package/src/types/interface/api/responses/function-version.response.ts +42 -42
  210. package/src/types/interface/api/responses/function.response.ts +25 -25
  211. package/src/types/interface/api/responses/index.ts +1 -0
  212. package/src/types/interface/api/responses/reflex-admin.admin.response.ts +25 -0
  213. package/src/types/interface/api/responses/route-stats.response.ts +15 -15
  214. package/src/types/interface/api/responses/service-completion-webhook.response.ts +13 -13
  215. package/src/types/interface/api/responses/service-configuration.response.ts +8 -8
  216. package/src/types/interface/api/responses/service-consumer.response.ts +33 -33
  217. package/src/types/interface/api/responses/service-deployment.response.ts +32 -32
  218. package/src/types/interface/api/responses/service-discord-event.response.ts +24 -24
  219. package/src/types/interface/api/responses/service-discord.response.ts +110 -110
  220. package/src/types/interface/api/responses/service-insights.response.ts +11 -11
  221. package/src/types/interface/api/responses/service-limits.response.ts +13 -13
  222. package/src/types/interface/api/responses/service-openapi.response.ts +7 -7
  223. package/src/types/interface/api/responses/service-route.response.ts +31 -31
  224. package/src/types/interface/api/responses/service-task.response.ts +57 -57
  225. package/src/types/interface/api/responses/service-version.response.ts +112 -112
  226. package/src/types/interface/api/responses/service.response.ts +31 -31
  227. package/src/types/interface/health.response.ts +7 -7
  228. package/src/types/interface/index.ts +3 -3
  229. package/src/types/interface/models/index.ts +1 -0
  230. package/src/types/interface/models/reflex-access-grant.model.ts +14 -14
  231. package/src/types/interface/models/reflex-access-request.model.ts +15 -15
  232. package/src/types/interface/models/reflex-admin-hold.model.ts +55 -0
  233. package/src/types/interface/models/reflex-alert-rule.model.ts +56 -56
  234. package/src/types/interface/models/reflex-bot-limits.model.ts +53 -53
  235. package/src/types/interface/models/reflex-completion-webhook.model.ts +111 -111
  236. package/src/types/interface/models/reflex-consumer.model.ts +50 -50
  237. package/src/types/interface/models/reflex-definition.model.ts +31 -31
  238. package/src/types/interface/models/reflex-discord-event-log.model.ts +58 -58
  239. package/src/types/interface/models/reflex-discord-event.model.ts +79 -79
  240. package/src/types/interface/models/reflex-discord.model.ts +208 -249
  241. package/src/types/interface/models/reflex-execution-settings.model.ts +57 -57
  242. package/src/types/interface/models/reflex-function-template.model.ts +18 -18
  243. package/src/types/interface/models/reflex-function-version.model.ts +19 -19
  244. package/src/types/interface/models/reflex-function.model.ts +30 -30
  245. package/src/types/interface/models/reflex-insights.model.ts +215 -215
  246. package/src/types/interface/models/reflex-price-list.model.ts +22 -22
  247. package/src/types/interface/models/reflex-route-contract.model.ts +46 -46
  248. package/src/types/interface/models/reflex-route.model.ts +23 -23
  249. package/src/types/interface/models/reflex-run.model.ts +0 -8
  250. package/src/types/interface/models/reflex-service-deployment.model.ts +51 -48
  251. package/src/types/interface/models/reflex-service.model.ts +50 -47
  252. package/src/types/interface/models/reflex-step-stats.model.ts +35 -35
  253. package/src/types/interface/models/reflex-task.model.ts +97 -97
  254. package/tsconfig.check.json +15 -15
  255. package/tsconfig.json +35 -35
  256. package/dist/discord/discord-command-tree.d.ts +0 -5
  257. package/dist/discord/discord-command-tree.js +0 -38
  258. package/dist/discord/discord-command-tree.js.map +0 -1
  259. package/dist/types/enum/discord-command-node-type.enum.d.ts +0 -5
  260. package/dist/types/enum/discord-command-node-type.enum.js +0 -10
  261. package/dist/types/enum/discord-command-node-type.enum.js.map +0 -1
  262. package/dist/types/enum/discord-command-type.enum.d.ts +0 -5
  263. package/dist/types/enum/discord-command-type.enum.js +0 -10
  264. package/dist/types/enum/discord-command-type.enum.js.map +0 -1
  265. package/src/discord/discord-command-tree.test.ts +0 -47
  266. package/src/discord/discord-command-tree.ts +0 -60
  267. package/src/types/enum/discord-command-node-type.enum.ts +0 -10
  268. package/src/types/enum/discord-command-type.enum.ts +0 -9
@@ -0,0 +1,55 @@
1
+ import type {
2
+ ReflexAbuseRule,
3
+ ReflexAdminHoldKind,
4
+ ServiceBlockReason,
5
+ ServiceDeploymentStatus,
6
+ ServiceType,
7
+ } from '../../enum';
8
+
9
+ /** A hold Abyss put on a Service in one environment. The reason is not stored here: it lives in the audit log of abyss-main. */
10
+ export interface IReflexAdminHold {
11
+ kind: ReflexAdminHoldKind;
12
+ /** The environment of the application (abyss-main's id). */
13
+ environmentId: string;
14
+ createdAt: Date;
15
+ }
16
+
17
+ /**
18
+ * Thresholds of the abuse detector, over a sliding window. Money is in millicredits: 1 credit = 1000 millicredits
19
+ * (as the price list), so `minMillicredits: 100_000` is 100 credits.
20
+ */
21
+ export const REFLEX_ABUSE_THRESHOLDS = {
22
+ windowMinutes: 60,
23
+ failureRate: { minRuns: 200, minRatio: 0.5 },
24
+ costSpike: { baselineDays: 7, factor: 10, minMillicredits: 100_000 },
25
+ netOut: { minBytes: 1_000_000_000 },
26
+ alertCooldownHours: 24,
27
+ } as const;
28
+
29
+ /** The last alert the detector raised for a Service in an environment. */
30
+ export interface IReflexAdminUsageAbuseAlert {
31
+ rule: ReflexAbuseRule;
32
+ /** ISO date of the alert. */
33
+ at: string;
34
+ }
35
+
36
+ /** One line of the admin usage view: a Service in an environment over the asked window. */
37
+ export interface IReflexAdminUsageRow {
38
+ serviceId: string;
39
+ serviceName: string;
40
+ serviceType: ServiceType;
41
+ applicationId: string;
42
+ applicationName: string;
43
+ projectId: string;
44
+ environmentId: string;
45
+ environmentSlug: string;
46
+ runs: number;
47
+ failed: number;
48
+ costMillicredits: number;
49
+ netOutBytes: number;
50
+ /** Status of the current deployment; null when nothing was put in service there. */
51
+ status: ServiceDeploymentStatus | null;
52
+ blockReason: ServiceBlockReason | null;
53
+ adminHold: ReflexAdminHoldKind | null;
54
+ lastAbuseAlert: IReflexAdminUsageAbuseAlert | null;
55
+ }
@@ -1,56 +1,56 @@
1
- import { ReflexAlertMetric } from '../../enum';
2
- import type { ReflexAlertNotificationState, ReflexAlertScope } from '../../enum';
3
-
4
- /** Bounds of the alert rules. */
5
- export const REFLEX_ALERT_RULE_LIMITS = {
6
- /** Active rules per application. */
7
- maxActivePerApplication: 20,
8
- /** Evaluation windows, in minutes. */
9
- windowMinutes: [5, 15, 30, 60],
10
- /** Bounds of the threshold by metric: a percentage for the error rate, milliseconds for the latency. */
11
- threshold: {
12
- [ReflexAlertMetric.ERROR_RATE]: { min: 1, max: 100 },
13
- [ReflexAlertMetric.LATENCY_P95]: { min: 1, max: 3_600_000 },
14
- },
15
- /** Runs a window needs before the rule is evaluated. */
16
- minRuns: { default: 20, min: 1, max: 10_000 },
17
- name: { minLength: 1, maxLength: 64 },
18
- } as const;
19
-
20
- export interface IReflexAlertRule {
21
- id: string;
22
- applicationId: string;
23
- environmentId: string;
24
- scope: ReflexAlertScope;
25
- /** The Service watched (scope SERVICE or ROUTE); null for a FUNCTION. */
26
- serviceId: string | null;
27
- /** The route watched (scope ROUTE); null otherwise. */
28
- routeId: string | null;
29
- /** The function watched (scope FUNCTION); null otherwise. */
30
- functionId: string | null;
31
- metric: ReflexAlertMetric;
32
- threshold: number;
33
- windowMinutes: number;
34
- minRuns: number;
35
- enabled: boolean;
36
- name: string;
37
- createdByUserId: string;
38
- createdAt: Date;
39
- updatedAt: Date;
40
- }
41
-
42
- /** What the last evaluation of a rule found. */
43
- export interface IReflexAlertRuleState {
44
- ruleId: string;
45
- environmentId: string;
46
- evaluatedAt: Date;
47
- /** Null when the window held fewer runs than `minRuns`. */
48
- value: number | null;
49
- runs: number;
50
- firing: boolean;
51
- firingSince: Date | null;
52
- lastReportedAt: Date | null;
53
- /** The Monitor incident the rule opened; null when none. */
54
- incidentId: string | null;
55
- notificationState: ReflexAlertNotificationState | null;
56
- }
1
+ import { ReflexAlertMetric } from '../../enum';
2
+ import type { ReflexAlertNotificationState, ReflexAlertScope } from '../../enum';
3
+
4
+ /** Bounds of the alert rules. */
5
+ export const REFLEX_ALERT_RULE_LIMITS = {
6
+ /** Active rules per application. */
7
+ maxActivePerApplication: 20,
8
+ /** Evaluation windows, in minutes. */
9
+ windowMinutes: [5, 15, 30, 60],
10
+ /** Bounds of the threshold by metric: a percentage for the error rate, milliseconds for the latency. */
11
+ threshold: {
12
+ [ReflexAlertMetric.ERROR_RATE]: { min: 1, max: 100 },
13
+ [ReflexAlertMetric.LATENCY_P95]: { min: 1, max: 3_600_000 },
14
+ },
15
+ /** Runs a window needs before the rule is evaluated. */
16
+ minRuns: { default: 20, min: 1, max: 10_000 },
17
+ name: { minLength: 1, maxLength: 64 },
18
+ } as const;
19
+
20
+ export interface IReflexAlertRule {
21
+ id: string;
22
+ applicationId: string;
23
+ environmentId: string;
24
+ scope: ReflexAlertScope;
25
+ /** The Service watched (scope SERVICE or ROUTE); null for a FUNCTION. */
26
+ serviceId: string | null;
27
+ /** The route watched (scope ROUTE); null otherwise. */
28
+ routeId: string | null;
29
+ /** The function watched (scope FUNCTION); null otherwise. */
30
+ functionId: string | null;
31
+ metric: ReflexAlertMetric;
32
+ threshold: number;
33
+ windowMinutes: number;
34
+ minRuns: number;
35
+ enabled: boolean;
36
+ name: string;
37
+ createdByUserId: string;
38
+ createdAt: Date;
39
+ updatedAt: Date;
40
+ }
41
+
42
+ /** What the last evaluation of a rule found. */
43
+ export interface IReflexAlertRuleState {
44
+ ruleId: string;
45
+ environmentId: string;
46
+ evaluatedAt: Date;
47
+ /** Null when the window held fewer runs than `minRuns`. */
48
+ value: number | null;
49
+ runs: number;
50
+ firing: boolean;
51
+ firingSince: Date | null;
52
+ lastReportedAt: Date | null;
53
+ /** The Monitor incident the rule opened; null when none. */
54
+ incidentId: string | null;
55
+ notificationState: ReflexAlertNotificationState | null;
56
+ }
@@ -1,53 +1,53 @@
1
- import { REFLEX_SERVICE_SPEND_LIMITS } from './reflex-service-limits.model';
2
-
3
- /**
4
- * Bounds of the per-bot limits and of their alerts. The monthly spend cap and its alerts are those of every
5
- * Service (`REFLEX_SERVICE_SPEND_LIMITS`).
6
- */
7
- export const REFLEX_BOT_LIMITS = {
8
- /** Events per minute added by one lot of the `reflex-bot-events` module. */
9
- eventsPerMinutePerLot: 500,
10
- monthlySpendCapDefaultCents: REFLEX_SERVICE_SPEND_LIMITS.monthlySpendCapDefaultCents,
11
- monthlySpendCapMinCents: REFLEX_SERVICE_SPEND_LIMITS.monthlySpendCapMinCents,
12
- monthlySpendCapMaxCents: REFLEX_SERVICE_SPEND_LIMITS.monthlySpendCapMaxCents,
13
- alertThresholdsMax: REFLEX_SERVICE_SPEND_LIMITS.alertThresholdsMax,
14
- alertThresholdMin: REFLEX_SERVICE_SPEND_LIMITS.alertThresholdMin,
15
- alertThresholdMax: REFLEX_SERVICE_SPEND_LIMITS.alertThresholdMax,
16
- spendCapDefaultThresholds: REFLEX_SERVICE_SPEND_LIMITS.spendCapDefaultThresholds,
17
- /** Rate alert: minutes of the UTC day above `rateAlertDefaultPercent` of the rate, by default. */
18
- rateAlertDefaultMinutes: 5,
19
- rateAlertDefaultPercent: 80,
20
- } as const;
21
-
22
- /** The events per minute of a bot in one environment: the plan base plus the lots allocated to it. */
23
- export interface IReflexBotEventRate {
24
- /** From the plan of the organization (100, 250 or 500). */
25
- baseEventsPerMinute: number;
26
- /** Lots of 500 allocated to this bot, from 0 to `lotsMax`. */
27
- lots: number;
28
- lotsMax: number;
29
- /** `baseEventsPerMinute + 500 * lots`. */
30
- eventsPerMinute: number;
31
- /** Event runs at once: `min(maxConcurrencyPerBot, ceil(eventsPerMinute / runsPerSlotPerMinute))`. */
32
- concurrency: number;
33
- /** Lots of the reserve of the organization nobody holds yet. */
34
- reserveLotsFree: number;
35
- }
36
-
37
- /** The lots of the reserve of the organization a bot holds in one environment. */
38
- export interface IReflexBotEventRateAllocation {
39
- serviceId: string;
40
- environmentId: string;
41
- lots: number;
42
- updatedAt: Date;
43
- }
44
-
45
- /** A bot going past its rate, as the Gateway counted it. */
46
- export interface IReflexBotRateExcess {
47
- /** Minutes of the UTC day spent above the alert percent of the rate. */
48
- minutesAboveAlertToday: number;
49
- /** Highest count of retained events in one minute, over the period. */
50
- peakPerMinute: number;
51
- /** Minutes in which at least one event was rejected for the rate. */
52
- minutesAtCap: number;
53
- }
1
+ import { REFLEX_SERVICE_SPEND_LIMITS } from './reflex-service-limits.model';
2
+
3
+ /**
4
+ * Bounds of the per-bot limits and of their alerts. The monthly spend cap and its alerts are those of every
5
+ * Service (`REFLEX_SERVICE_SPEND_LIMITS`).
6
+ */
7
+ export const REFLEX_BOT_LIMITS = {
8
+ /** Events per minute added by one lot of the `reflex-bot-events` module. */
9
+ eventsPerMinutePerLot: 500,
10
+ monthlySpendCapDefaultCents: REFLEX_SERVICE_SPEND_LIMITS.monthlySpendCapDefaultCents,
11
+ monthlySpendCapMinCents: REFLEX_SERVICE_SPEND_LIMITS.monthlySpendCapMinCents,
12
+ monthlySpendCapMaxCents: REFLEX_SERVICE_SPEND_LIMITS.monthlySpendCapMaxCents,
13
+ alertThresholdsMax: REFLEX_SERVICE_SPEND_LIMITS.alertThresholdsMax,
14
+ alertThresholdMin: REFLEX_SERVICE_SPEND_LIMITS.alertThresholdMin,
15
+ alertThresholdMax: REFLEX_SERVICE_SPEND_LIMITS.alertThresholdMax,
16
+ spendCapDefaultThresholds: REFLEX_SERVICE_SPEND_LIMITS.spendCapDefaultThresholds,
17
+ /** Rate alert: minutes of the UTC day above `rateAlertDefaultPercent` of the rate, by default. */
18
+ rateAlertDefaultMinutes: 5,
19
+ rateAlertDefaultPercent: 80,
20
+ } as const;
21
+
22
+ /** The events per minute of a bot in one environment: the plan base plus the lots allocated to it. */
23
+ export interface IReflexBotEventRate {
24
+ /** From the plan of the organization (100, 250 or 500). */
25
+ baseEventsPerMinute: number;
26
+ /** Lots of 500 allocated to this bot, from 0 to `lotsMax`. */
27
+ lots: number;
28
+ lotsMax: number;
29
+ /** `baseEventsPerMinute + 500 * lots`. */
30
+ eventsPerMinute: number;
31
+ /** Event runs at once: `min(maxConcurrencyPerBot, ceil(eventsPerMinute / runsPerSlotPerMinute))`. */
32
+ concurrency: number;
33
+ /** Lots of the reserve of the organization nobody holds yet. */
34
+ reserveLotsFree: number;
35
+ }
36
+
37
+ /** The lots of the reserve of the organization a bot holds in one environment. */
38
+ export interface IReflexBotEventRateAllocation {
39
+ serviceId: string;
40
+ environmentId: string;
41
+ lots: number;
42
+ updatedAt: Date;
43
+ }
44
+
45
+ /** A bot going past its rate, as the Gateway counted it. */
46
+ export interface IReflexBotRateExcess {
47
+ /** Minutes of the UTC day spent above the alert percent of the rate. */
48
+ minutesAboveAlertToday: number;
49
+ /** Highest count of retained events in one minute, over the period. */
50
+ peakPerMinute: number;
51
+ /** Minutes in which at least one event was rejected for the rate. */
52
+ minutesAtCap: number;
53
+ }
@@ -1,111 +1,111 @@
1
- import type { CompletionDeliveryStatus, RunStatus } from '../../enum';
2
-
3
- /** The header that carries the id of a delivery, the same at every attempt: the receiver drops a repeat by it. */
4
- export const COMPLETION_DELIVERY_ID_HEADER = 'x-abyss-delivery-id';
5
-
6
- /**
7
- * The first path segment the edge keeps for the state of an async execution:
8
- * `GET /<application>/<environment>/<service>/_executions/:executionId`, with the key of the consumer that started it.
9
- */
10
- export const RESERVED_EXECUTIONS_SEGMENT = '_executions';
11
-
12
- /** Bounds of the completion webhook. */
13
- export const REFLEX_COMPLETION_WEBHOOK_LIMITS = {
14
- /** Characters of the URL; `https` only. */
15
- urlMaxLength: 2048,
16
- /** Minutes before each retry, after the first attempt: 5 retries at most. */
17
- retryDelaysMinutes: [1, 5, 15, 30, 60],
18
- /** Timeout of one attempt. */
19
- sendTimeoutMs: 10_000,
20
- /** Bytes of the UTF-8 JSON of `output`; past it, `output` is null and `outputTruncated` true. */
21
- outputMaxBytes: 65_536,
22
- } as const;
23
-
24
- /**
25
- * The sentences the edge writes into the `error` of a delivery attempt (`IReflexCompletionDeliveryAttempt.error`)
26
- * when it is not a bare receiver answer, for a reader that has to recognise them. They are English and fixed; the
27
- * edge builds the rest of an `error` around the prefixes:
28
- * - `HTTP <status>` or `HTTP <status>: redirects are not followed` (`httpPrefix`, `redirectsNotFollowed`);
29
- * - `The receiver did not answer within <sendTimeoutMs> ms` (`receiverTimeoutPrefix`);
30
- * - `The request failed (<code>)` where `<code>` is the undici or Node error code (`requestFailedPrefix`).
31
- * The edge keeps a local copy (it does not depend on this SDK); `edge-contract-parity.spec.ts` fails when they differ.
32
- */
33
- export const REFLEX_COMPLETION_DELIVERY_ERRORS = {
34
- /** The URL is not https, or it (or the address it resolves to) is one the edge may not reach: the SSRF guard refused it. */
35
- refusedAddress: 'The URL is not https, or reaches an address the edge may not reach',
36
- /** The Service has no signing secret in the environment (or it does not unseal): nothing was posted. */
37
- noSigningSecret: 'No signing secret for the Service in the environment',
38
- /** The URL does not parse: nothing was posted. */
39
- invalidUrl: 'The URL is not valid',
40
- /** Start of the sentence written when the receiver did not answer in time; followed by ` <ms> ms`. */
41
- receiverTimeoutPrefix: 'The receiver did not answer within',
42
- /** Start of the sentence written for a network failure; followed by ` (<error code>)`. */
43
- requestFailedPrefix: 'The request failed',
44
- /** Start of the sentence written for an HTTP status that ended the attempt; followed by ` <status>`. */
45
- httpPrefix: 'HTTP',
46
- /** The reason that follows `HTTP <status>: ` for a 3xx answer. */
47
- redirectsNotFollowed: 'redirects are not followed',
48
- } as const;
49
-
50
- /**
51
- * The JSON body the edge `POST`s to the completion webhook URL once an async execution finished, signed
52
- * `x-abyss-signature: t=<seconds>,v1=<hmac>` (ADR-0257) with the secret of the Service and the environment, and
53
- * sent with `COMPLETION_DELIVERY_ID_HEADER`. The body is the same at every attempt.
54
- */
55
- export interface IReflexCompletionWebhookPayload {
56
- executionId: string;
57
- functionId: string;
58
- status: RunStatus;
59
- /** The status of the response the function built. */
60
- httpStatus: number;
61
- /** The body of that response; null when none, or when it was cut. */
62
- output: unknown | null;
63
- /** True when the output went past `REFLEX_COMPLETION_WEBHOOK_LIMITS.outputMaxBytes`. */
64
- outputTruncated: boolean;
65
- /** Set when the execution failed. */
66
- error: { code: string; message: string } | null;
67
- durationMs: number;
68
- /** The cost of the execution in credits, the deliveries left out (each attempt costs 0.01 credit on its own). */
69
- costCredits: number;
70
- /** ISO 8601. */
71
- finishedAt: string;
72
- }
73
-
74
- /** One attempt to deliver the completion webhook. Each attempt costs 0.01 credit, retries included. */
75
- export interface IReflexCompletionDeliveryAttempt {
76
- /** 1 for the first send, then 2 to 6 for the retries. */
77
- attempt: number;
78
- attemptedAt: Date;
79
- /** The status the receiver answered; null when it did not answer (network, timeout, refused address). */
80
- httpStatus: number | null;
81
- durationMs: number;
82
- /** Why the attempt failed; null for a 2xx. */
83
- error: string | null;
84
- }
85
-
86
- /** The delivery of the completion webhook of one async execution, with its attempts. */
87
- export interface IReflexCompletionDelivery {
88
- /** The value of `COMPLETION_DELIVERY_ID_HEADER`. */
89
- id: string;
90
- url: string;
91
- status: CompletionDeliveryStatus;
92
- /** In order. */
93
- attempts: IReflexCompletionDeliveryAttempt[];
94
- /** When the next attempt is due; null once DELIVERED or FAILED. */
95
- nextAttemptAt: Date | null;
96
- createdAt: Date;
97
- }
98
-
99
- /** A signing secret of the completion webhook, in clear, shown ONCE when created or rotated. */
100
- export interface IReflexIssuedCompletionSecret {
101
- environmentId: string;
102
- secret: string;
103
- }
104
-
105
- /** The signing secret of the completion webhook of a Service in one environment. Never carries the secret. */
106
- export interface IReflexCompletionWebhookSecret {
107
- environmentId: string;
108
- createdAt: Date;
109
- /** Null until rotated once. */
110
- rotatedAt: Date | null;
111
- }
1
+ import type { CompletionDeliveryStatus, RunStatus } from '../../enum';
2
+
3
+ /** The header that carries the id of a delivery, the same at every attempt: the receiver drops a repeat by it. */
4
+ export const COMPLETION_DELIVERY_ID_HEADER = 'x-abyss-delivery-id';
5
+
6
+ /**
7
+ * The first path segment the edge keeps for the state of an async execution:
8
+ * `GET /<application>/<environment>/<service>/_executions/:executionId`, with the key of the consumer that started it.
9
+ */
10
+ export const RESERVED_EXECUTIONS_SEGMENT = '_executions';
11
+
12
+ /** Bounds of the completion webhook. */
13
+ export const REFLEX_COMPLETION_WEBHOOK_LIMITS = {
14
+ /** Characters of the URL; `https` only. */
15
+ urlMaxLength: 2048,
16
+ /** Minutes before each retry, after the first attempt: 5 retries at most. */
17
+ retryDelaysMinutes: [1, 5, 15, 30, 60],
18
+ /** Timeout of one attempt. */
19
+ sendTimeoutMs: 10_000,
20
+ /** Bytes of the UTF-8 JSON of `output`; past it, `output` is null and `outputTruncated` true. */
21
+ outputMaxBytes: 65_536,
22
+ } as const;
23
+
24
+ /**
25
+ * The sentences the edge writes into the `error` of a delivery attempt (`IReflexCompletionDeliveryAttempt.error`)
26
+ * when it is not a bare receiver answer, for a reader that has to recognise them. They are English and fixed; the
27
+ * edge builds the rest of an `error` around the prefixes:
28
+ * - `HTTP <status>` or `HTTP <status>: redirects are not followed` (`httpPrefix`, `redirectsNotFollowed`);
29
+ * - `The receiver did not answer within <sendTimeoutMs> ms` (`receiverTimeoutPrefix`);
30
+ * - `The request failed (<code>)` where `<code>` is the undici or Node error code (`requestFailedPrefix`).
31
+ * The edge keeps a local copy (it does not depend on this SDK); `edge-contract-parity.spec.ts` fails when they differ.
32
+ */
33
+ export const REFLEX_COMPLETION_DELIVERY_ERRORS = {
34
+ /** The URL is not https, or it (or the address it resolves to) is one the edge may not reach: the SSRF guard refused it. */
35
+ refusedAddress: 'The URL is not https, or reaches an address the edge may not reach',
36
+ /** The Service has no signing secret in the environment (or it does not unseal): nothing was posted. */
37
+ noSigningSecret: 'No signing secret for the Service in the environment',
38
+ /** The URL does not parse: nothing was posted. */
39
+ invalidUrl: 'The URL is not valid',
40
+ /** Start of the sentence written when the receiver did not answer in time; followed by ` <ms> ms`. */
41
+ receiverTimeoutPrefix: 'The receiver did not answer within',
42
+ /** Start of the sentence written for a network failure; followed by ` (<error code>)`. */
43
+ requestFailedPrefix: 'The request failed',
44
+ /** Start of the sentence written for an HTTP status that ended the attempt; followed by ` <status>`. */
45
+ httpPrefix: 'HTTP',
46
+ /** The reason that follows `HTTP <status>: ` for a 3xx answer. */
47
+ redirectsNotFollowed: 'redirects are not followed',
48
+ } as const;
49
+
50
+ /**
51
+ * The JSON body the edge `POST`s to the completion webhook URL once an async execution finished, signed
52
+ * `x-abyss-signature: t=<seconds>,v1=<hmac>` (ADR-0257) with the secret of the Service and the environment, and
53
+ * sent with `COMPLETION_DELIVERY_ID_HEADER`. The body is the same at every attempt.
54
+ */
55
+ export interface IReflexCompletionWebhookPayload {
56
+ executionId: string;
57
+ functionId: string;
58
+ status: RunStatus;
59
+ /** The status of the response the function built. */
60
+ httpStatus: number;
61
+ /** The body of that response; null when none, or when it was cut. */
62
+ output: unknown | null;
63
+ /** True when the output went past `REFLEX_COMPLETION_WEBHOOK_LIMITS.outputMaxBytes`. */
64
+ outputTruncated: boolean;
65
+ /** Set when the execution failed. */
66
+ error: { code: string; message: string } | null;
67
+ durationMs: number;
68
+ /** The cost of the execution in credits, the deliveries left out (each attempt costs 0.01 credit on its own). */
69
+ costCredits: number;
70
+ /** ISO 8601. */
71
+ finishedAt: string;
72
+ }
73
+
74
+ /** One attempt to deliver the completion webhook. Each attempt costs 0.01 credit, retries included. */
75
+ export interface IReflexCompletionDeliveryAttempt {
76
+ /** 1 for the first send, then 2 to 6 for the retries. */
77
+ attempt: number;
78
+ attemptedAt: Date;
79
+ /** The status the receiver answered; null when it did not answer (network, timeout, refused address). */
80
+ httpStatus: number | null;
81
+ durationMs: number;
82
+ /** Why the attempt failed; null for a 2xx. */
83
+ error: string | null;
84
+ }
85
+
86
+ /** The delivery of the completion webhook of one async execution, with its attempts. */
87
+ export interface IReflexCompletionDelivery {
88
+ /** The value of `COMPLETION_DELIVERY_ID_HEADER`. */
89
+ id: string;
90
+ url: string;
91
+ status: CompletionDeliveryStatus;
92
+ /** In order. */
93
+ attempts: IReflexCompletionDeliveryAttempt[];
94
+ /** When the next attempt is due; null once DELIVERED or FAILED. */
95
+ nextAttemptAt: Date | null;
96
+ createdAt: Date;
97
+ }
98
+
99
+ /** A signing secret of the completion webhook, in clear, shown ONCE when created or rotated. */
100
+ export interface IReflexIssuedCompletionSecret {
101
+ environmentId: string;
102
+ secret: string;
103
+ }
104
+
105
+ /** The signing secret of the completion webhook of a Service in one environment. Never carries the secret. */
106
+ export interface IReflexCompletionWebhookSecret {
107
+ environmentId: string;
108
+ createdAt: Date;
109
+ /** Null until rotated once. */
110
+ rotatedAt: Date | null;
111
+ }
@@ -1,50 +1,50 @@
1
- /**
2
- * A key of a consumer: `rfx_` followed by 48 hexadecimal characters, kept as its SHA-256 only. The key itself is
3
- * shown once, when created.
4
- */
5
- export interface IReflexConsumerKey {
6
- id: string;
7
- consumerId: string;
8
- /**
9
- * The first 8 characters of the key, to recognize it; null for a key migrated from a route, whose clear value
10
- * was never kept.
11
- */
12
- prefix: string | null;
13
- createdAt: Date;
14
- /** The last call the edge accepted with it, written at most once a minute; null when never used. */
15
- lastUsedAt: Date | null;
16
- /** Null while it is active; a revoked key is refused (`401`) as soon as the revocation answered. */
17
- revokedAt: Date | null;
18
- }
19
-
20
- /**
21
- * Who calls the `API_KEY` routes of a Service: the edge identifies it by its key and passes
22
- * `consumer: { id, name }` to the function. Not versioned: a change applies at once wherever the Service is in
23
- * service.
24
- */
25
- export interface IReflexConsumer {
26
- id: string;
27
- serviceId: string;
28
- /** 1 to 64 characters, unique in the Service whatever the case. */
29
- name: string;
30
- /** 500 characters at most; null when none. */
31
- description: string | null;
32
- /** The `API_KEY` routes of the Service it may call; null for all of them. */
33
- routeIds: string[] | null;
34
- /** Calls per minute of its own, on top of the limit per IP; null for no limit of its own. */
35
- rateLimitPerMinute: number | null;
36
- /** Its keys, active and revoked, newest first. */
37
- keys: IReflexConsumerKey[];
38
- createdByUserId: string;
39
- createdAt: Date;
40
- updatedAt: Date;
41
- }
42
-
43
- /** Bounds of the consumers of a Service (system limits, not quotas of a plan). */
44
- export const REFLEX_CONSUMER_LIMITS = {
45
- perService: 100,
46
- activeKeysPerConsumer: 5,
47
- nameMaxLength: 64,
48
- descriptionMaxLength: 500,
49
- rateLimitPerMinute: { min: 1, max: 100_000 },
50
- } as const;
1
+ /**
2
+ * A key of a consumer: `rfx_` followed by 48 hexadecimal characters, kept as its SHA-256 only. The key itself is
3
+ * shown once, when created.
4
+ */
5
+ export interface IReflexConsumerKey {
6
+ id: string;
7
+ consumerId: string;
8
+ /**
9
+ * The first 8 characters of the key, to recognize it; null for a key migrated from a route, whose clear value
10
+ * was never kept.
11
+ */
12
+ prefix: string | null;
13
+ createdAt: Date;
14
+ /** The last call the edge accepted with it, written at most once a minute; null when never used. */
15
+ lastUsedAt: Date | null;
16
+ /** Null while it is active; a revoked key is refused (`401`) as soon as the revocation answered. */
17
+ revokedAt: Date | null;
18
+ }
19
+
20
+ /**
21
+ * Who calls the `API_KEY` routes of a Service: the edge identifies it by its key and passes
22
+ * `consumer: { id, name }` to the function. Not versioned: a change applies at once wherever the Service is in
23
+ * service.
24
+ */
25
+ export interface IReflexConsumer {
26
+ id: string;
27
+ serviceId: string;
28
+ /** 1 to 64 characters, unique in the Service whatever the case. */
29
+ name: string;
30
+ /** 500 characters at most; null when none. */
31
+ description: string | null;
32
+ /** The `API_KEY` routes of the Service it may call; null for all of them. */
33
+ routeIds: string[] | null;
34
+ /** Calls per minute of its own, on top of the limit per IP; null for no limit of its own. */
35
+ rateLimitPerMinute: number | null;
36
+ /** Its keys, active and revoked, newest first. */
37
+ keys: IReflexConsumerKey[];
38
+ createdByUserId: string;
39
+ createdAt: Date;
40
+ updatedAt: Date;
41
+ }
42
+
43
+ /** Bounds of the consumers of a Service (system limits, not quotas of a plan). */
44
+ export const REFLEX_CONSUMER_LIMITS = {
45
+ perService: 100,
46
+ activeKeysPerConsumer: 5,
47
+ nameMaxLength: 64,
48
+ descriptionMaxLength: 500,
49
+ rateLimitPerMinute: { min: 1, max: 100_000 },
50
+ } as const;