evo360-types 1.3.408 → 1.3.409

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.
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.zAutomationDryRunRequestSchema = exports.zHubAutomationConfigSchema = exports.zAutomationRoutineSchema = exports.zAutomationBranchModeSchema = exports.zAutomationBranchSchema = exports.zAutomationOutputSchema = exports.zAutomationHumanTaskOutputSchema = exports.zAutomationAutoTaskOutputSchema = exports.zAutomationExecuteAtSchema = exports.zAutomationConditionGroupSchema = exports.zAutomationConditionSchema = exports.zAutomationOperatorSchema = exports.zAutomationSelectionSchema = exports.zAutomationAppointmentSelectionSchema = exports.zAutomationDateWindowSchema = exports.zAutomationDateOffsetModeSchema = exports.zAutomationTriggerSchema = exports.zAutomationCronTriggerSchema = void 0;
3
+ exports.zAutomationTriggerRequestSchema = exports.zAutomationDryRunRequestSchema = exports.zHubAutomationConfigSchema = exports.zAutomationRoutineUpdateRequestSchema = exports.zAutomationRoutineWriteSchema = exports.zAutomationRoutineSchema = exports.zAutomationBranchModeSchema = exports.zAutomationBranchSchema = exports.zAutomationOutputSchema = exports.zAutomationHumanTaskOutputSchema = exports.zAutomationAutoTaskOutputSchema = exports.zAutomationExecuteAtSchema = exports.zAutomationConditionGroupSchema = exports.zAutomationConditionSchema = exports.zAutomationOperatorSchema = exports.zAutomationSelectionSchema = exports.zAutomationAppointmentSelectionSchema = exports.zAutomationDateWindowSchema = exports.zAutomationDateOffsetModeSchema = exports.zAutomationTriggerSchema = exports.zAutomationWebhookTriggerSchema = exports.zAutomationCronTriggerSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const zod_schemas_1 = require("../evo-task/zod-schemas");
6
6
  // ------------------------------------------------------
7
- // Trigger (F1: cron only)
7
+ // Trigger (cron sweep | webhook reverse-trigger)
8
8
  // ------------------------------------------------------
9
9
  exports.zAutomationCronTriggerSchema = zod_1.z.object({
10
10
  type: zod_1.z.literal("cron"),
@@ -13,7 +13,14 @@ exports.zAutomationCronTriggerSchema = zod_1.z.object({
13
13
  timezone: zod_1.z.string().optional(),
14
14
  }),
15
15
  });
16
- exports.zAutomationTriggerSchema = exports.zAutomationCronTriggerSchema;
16
+ // F2: fired only by POST /routines/:id/trigger; invisible to the sweep.
17
+ exports.zAutomationWebhookTriggerSchema = zod_1.z.object({
18
+ type: zod_1.z.literal("webhook"),
19
+ });
20
+ exports.zAutomationTriggerSchema = zod_1.z.discriminatedUnion("type", [
21
+ exports.zAutomationCronTriggerSchema,
22
+ exports.zAutomationWebhookTriggerSchema,
23
+ ]);
17
24
  // ------------------------------------------------------
18
25
  // Selection (F1: appointment target only)
19
26
  // ------------------------------------------------------
@@ -135,6 +142,32 @@ exports.zAutomationRoutineSchema = zod_1.z.object({
135
142
  updated_at: zod_1.z.coerce.date(),
136
143
  });
137
144
  // ------------------------------------------------------
145
+ // Routine write payload (CRUD via POST/PUT — F3)
146
+ // Same structure as zAutomationRoutineSchema WITHOUT the server-managed fields
147
+ // (version/dry_run_stamp/trigger_state/stats/created_at/updated_at), which the
148
+ // backend owns. `active` defaults false (create) — activation is a separate
149
+ // endpoint that also enforces the Q11 dry-run gate.
150
+ // ------------------------------------------------------
151
+ exports.zAutomationRoutineWriteSchema = zod_1.z.object({
152
+ id: zod_1.z.string(),
153
+ name: zod_1.z.string().min(1),
154
+ description: zod_1.z.string().optional(),
155
+ active: zod_1.z.boolean().default(false),
156
+ trigger: exports.zAutomationTriggerSchema,
157
+ selection: exports.zAutomationSelectionSchema,
158
+ branch_mode: exports.zAutomationBranchModeSchema,
159
+ branches: zod_1.z.array(exports.zAutomationBranchSchema),
160
+ guards: zod_1.z.object({
161
+ max_tasks_per_run: zod_1.z.number().int().positive(),
162
+ }),
163
+ });
164
+ // PUT /routines/:id body — optimistic concurrency: expected_version must match
165
+ // the stored routine's version or the backend returns 409.
166
+ exports.zAutomationRoutineUpdateRequestSchema = zod_1.z.object({
167
+ routine: exports.zAutomationRoutineWriteSchema,
168
+ expected_version: zod_1.z.number().int().positive(),
169
+ });
170
+ // ------------------------------------------------------
138
171
  // Module config (mirrors zTaskRunnerConfigSchema: active default false, passthrough)
139
172
  // ------------------------------------------------------
140
173
  exports.zHubAutomationConfigSchema = zod_1.z
@@ -157,3 +190,14 @@ exports.zAutomationDryRunRequestSchema = zod_1.z.object({
157
190
  .regex(/^\d{4}-\d{2}-\d{2}$/, "expected yyyy-MM-dd")
158
191
  .optional(),
159
192
  });
193
+ // ------------------------------------------------------
194
+ // Trigger request (endpoint POST /routines/:id/trigger)
195
+ // Same shape as the dry-run request — only an optional run_date; no
196
+ // calendar_ids override or arbitrary payload (F2 scope, see plan-f2 §1).
197
+ // ------------------------------------------------------
198
+ exports.zAutomationTriggerRequestSchema = zod_1.z.object({
199
+ run_date: zod_1.z
200
+ .string()
201
+ .regex(/^\d{4}-\d{2}-\d{2}$/, "expected yyyy-MM-dd")
202
+ .optional(),
203
+ });
@@ -6,7 +6,7 @@ import {
6
6
  } from "../evo-task/zod-schemas";
7
7
 
8
8
  // ------------------------------------------------------
9
- // Trigger (F1: cron only)
9
+ // Trigger (cron sweep | webhook reverse-trigger)
10
10
  // ------------------------------------------------------
11
11
  export const zAutomationCronTriggerSchema = z.object({
12
12
  type: z.literal("cron"),
@@ -16,7 +16,15 @@ export const zAutomationCronTriggerSchema = z.object({
16
16
  }),
17
17
  });
18
18
 
19
- export const zAutomationTriggerSchema = zAutomationCronTriggerSchema;
19
+ // F2: fired only by POST /routines/:id/trigger; invisible to the sweep.
20
+ export const zAutomationWebhookTriggerSchema = z.object({
21
+ type: z.literal("webhook"),
22
+ });
23
+
24
+ export const zAutomationTriggerSchema = z.discriminatedUnion("type", [
25
+ zAutomationCronTriggerSchema,
26
+ zAutomationWebhookTriggerSchema,
27
+ ]);
20
28
 
21
29
  // ------------------------------------------------------
22
30
  // Selection (F1: appointment target only)
@@ -165,6 +173,34 @@ export const zAutomationRoutineSchema = z.object({
165
173
  updated_at: z.coerce.date(),
166
174
  });
167
175
 
176
+ // ------------------------------------------------------
177
+ // Routine write payload (CRUD via POST/PUT — F3)
178
+ // Same structure as zAutomationRoutineSchema WITHOUT the server-managed fields
179
+ // (version/dry_run_stamp/trigger_state/stats/created_at/updated_at), which the
180
+ // backend owns. `active` defaults false (create) — activation is a separate
181
+ // endpoint that also enforces the Q11 dry-run gate.
182
+ // ------------------------------------------------------
183
+ export const zAutomationRoutineWriteSchema = z.object({
184
+ id: z.string(),
185
+ name: z.string().min(1),
186
+ description: z.string().optional(),
187
+ active: z.boolean().default(false),
188
+ trigger: zAutomationTriggerSchema,
189
+ selection: zAutomationSelectionSchema,
190
+ branch_mode: zAutomationBranchModeSchema,
191
+ branches: z.array(zAutomationBranchSchema),
192
+ guards: z.object({
193
+ max_tasks_per_run: z.number().int().positive(),
194
+ }),
195
+ });
196
+
197
+ // PUT /routines/:id body — optimistic concurrency: expected_version must match
198
+ // the stored routine's version or the backend returns 409.
199
+ export const zAutomationRoutineUpdateRequestSchema = z.object({
200
+ routine: zAutomationRoutineWriteSchema,
201
+ expected_version: z.number().int().positive(),
202
+ });
203
+
168
204
  // ------------------------------------------------------
169
205
  // Module config (mirrors zTaskRunnerConfigSchema: active default false, passthrough)
170
206
  // ------------------------------------------------------
@@ -189,3 +225,15 @@ export const zAutomationDryRunRequestSchema = z.object({
189
225
  .regex(/^\d{4}-\d{2}-\d{2}$/, "expected yyyy-MM-dd")
190
226
  .optional(),
191
227
  });
228
+
229
+ // ------------------------------------------------------
230
+ // Trigger request (endpoint POST /routines/:id/trigger)
231
+ // Same shape as the dry-run request — only an optional run_date; no
232
+ // calendar_ids override or arbitrary payload (F2 scope, see plan-f2 §1).
233
+ // ------------------------------------------------------
234
+ export const zAutomationTriggerRequestSchema = z.object({
235
+ run_date: z
236
+ .string()
237
+ .regex(/^\d{4}-\d{2}-\d{2}$/, "expected yyyy-MM-dd")
238
+ .optional(),
239
+ });
@@ -12,7 +12,10 @@ export interface IAutomationCronTrigger {
12
12
  timezone?: string;
13
13
  };
14
14
  }
15
- export type IAutomationTrigger = IAutomationCronTrigger;
15
+ export interface IAutomationWebhookTrigger {
16
+ type: "webhook";
17
+ }
18
+ export type IAutomationTrigger = IAutomationCronTrigger | IAutomationWebhookTrigger;
16
19
  export type AutomationDateOffsetMode = "calendar" | "business";
17
20
  export interface IAutomationDateWindow {
18
21
  offset_days: number;
@@ -118,6 +121,19 @@ export interface IAutomationRoutine {
118
121
  created_at: Date;
119
122
  updated_at: Date;
120
123
  }
124
+ export interface IAutomationRoutineWrite {
125
+ id: string;
126
+ name: string;
127
+ description?: string;
128
+ active: boolean;
129
+ trigger: IAutomationTrigger;
130
+ selection: IAutomationSelection;
131
+ branch_mode: AutomationBranchMode;
132
+ branches: IAutomationBranch[];
133
+ guards: {
134
+ max_tasks_per_run: number;
135
+ };
136
+ }
121
137
  export interface IHubAutomationConfig {
122
138
  active: boolean;
123
139
  limits?: {
@@ -147,10 +163,12 @@ export interface IAutomationRunSample {
147
163
  appointment_id: string;
148
164
  branch_id?: string;
149
165
  decision: string;
166
+ task_id?: string;
150
167
  conditions?: IAutomationConditionResult[];
151
168
  [key: string]: unknown;
152
169
  }
153
170
  export interface IAutomationRunTrace {
171
+ run_id?: string;
154
172
  routine_id: string;
155
173
  routine_version: number;
156
174
  trigger: {
@@ -27,7 +27,7 @@ export type HubAutomationPermissions =
27
27
  (typeof HubAutomationPermissions)[keyof typeof HubAutomationPermissions];
28
28
 
29
29
  // ------------------------------------------------------
30
- // Trigger (F1: cron only)
30
+ // Trigger (cron sweep | webhook reverse-trigger)
31
31
  // ------------------------------------------------------
32
32
  export interface IAutomationCronTrigger {
33
33
  type: "cron";
@@ -39,7 +39,15 @@ export interface IAutomationCronTrigger {
39
39
  };
40
40
  }
41
41
 
42
- export type IAutomationTrigger = IAutomationCronTrigger;
42
+ // F2: fired only by POST /routines/:id/trigger (n8n as a client of the engine);
43
+ // invisible to the sweep (listActiveCronRoutines filters type === 'cron').
44
+ export interface IAutomationWebhookTrigger {
45
+ type: "webhook";
46
+ }
47
+
48
+ export type IAutomationTrigger =
49
+ | IAutomationCronTrigger
50
+ | IAutomationWebhookTrigger;
43
51
 
44
52
  // ------------------------------------------------------
45
53
  // Selection (F1: appointment target only)
@@ -230,6 +238,27 @@ export interface IAutomationRoutine {
230
238
  updated_at: Date;
231
239
  }
232
240
 
241
+ // ------------------------------------------------------
242
+ // Routine write payload (CRUD via POST/PUT on hub_automation_admin — F3)
243
+ // The routine WITHOUT server-managed fields: `version`, `dry_run_stamp`,
244
+ // `trigger_state`, `stats`, `created_at`, `updated_at` are set by the backend
245
+ // (version bookkeeping, Q11 gate, cursor, run stats, timestamps). The FE never
246
+ // writes them. Written by hand (no utility types) to keep the contract explicit.
247
+ // ------------------------------------------------------
248
+ export interface IAutomationRoutineWrite {
249
+ id: string;
250
+ name: string;
251
+ description?: string;
252
+ active: boolean;
253
+ trigger: IAutomationTrigger;
254
+ selection: IAutomationSelection;
255
+ branch_mode: AutomationBranchMode;
256
+ branches: IAutomationBranch[];
257
+ guards: {
258
+ max_tasks_per_run: number;
259
+ };
260
+ }
261
+
233
262
  // ------------------------------------------------------
234
263
  // Module config (Firestore doc: tenants/{t}/apps/hub-automation/config/config)
235
264
  // ------------------------------------------------------
@@ -275,11 +304,17 @@ export interface IAutomationRunSample {
275
304
  branch_id?: string;
276
305
  // e.g. 'created' | 'already_existed' | 'not_matched' | 'suppressed_by_limit'
277
306
  decision: string;
307
+ // Set by the materializer when decision === 'created'; lets the run viewer
308
+ // deep-link from a sample to the materialized Task (F3).
309
+ task_id?: string;
278
310
  conditions?: IAutomationConditionResult[];
279
311
  [key: string]: unknown;
280
312
  }
281
313
 
282
314
  export interface IAutomationRunTrace {
315
+ // Engine-generated run id; surfaced in the webhook trigger response (F2) so
316
+ // the caller can deep-link to this run. Optional for backward compatibility.
317
+ run_id?: string;
283
318
  routine_id: string;
284
319
  routine_version: number;
285
320
  trigger: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evo360-types",
3
- "version": "1.3.408",
3
+ "version": "1.3.409",
4
4
  "description": "HREVO360 Shared Types",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",