evo360-types 1.3.407 → 1.3.408
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.
- package/dist/apps/evo-hub-ia/v1/zod-schemas.d.ts +340 -340
- package/dist/apps/hub-automation/zod-schemas.d.ts +3322 -0
- package/dist/apps/hub-automation/zod-schemas.js +159 -0
- package/dist/apps/hub-automation/zod-schemas.ts +191 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.ts +2 -0
- package/dist/types/hub-automation/fb_collections.d.ts +4 -0
- package/dist/types/hub-automation/fb_collections.js +16 -0
- package/dist/types/hub-automation/fb_collections.ts +17 -0
- package/dist/types/hub-automation/index.d.ts +181 -0
- package/dist/types/hub-automation/index.js +86 -0
- package/dist/types/hub-automation/index.ts +312 -0
- package/package.json +1 -1
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.AutomationRunStatusEnum = exports.AutomationOutputTypeEnum = exports.AutomationOperatorEnum = exports.AUTOMATION_APPOINTMENT_FACTS = exports.HubAutomationPermissions = void 0;
|
|
18
|
+
__exportStar(require("./fb_collections"), exports);
|
|
19
|
+
// ======================================================
|
|
20
|
+
// hub-automation
|
|
21
|
+
//
|
|
22
|
+
// Declarative automation routines that MATERIALIZE Tasks (no side effects —
|
|
23
|
+
// every effect on the world flows through the Task Runner, decision Q1).
|
|
24
|
+
//
|
|
25
|
+
// A routine is: a TRIGGER (F1: cron) + a SELECTION of domain targets
|
|
26
|
+
// (F1: appointments) + nested condition BRANCHES → OUTPUTS (auto/human Tasks).
|
|
27
|
+
//
|
|
28
|
+
// NOTE:
|
|
29
|
+
// - These are hand-written contracts (no z.infer). Zod schemas live in
|
|
30
|
+
// src/apps/hub-automation/zod-schemas.ts.
|
|
31
|
+
// - F1 has no `patient.*` facts and no patient hydration (decision Q15):
|
|
32
|
+
// contact-data validation is the handler's responsibility at run time.
|
|
33
|
+
// ======================================================
|
|
34
|
+
// ----- Permissions (Firestore path: tenants/{t}/apps/hub-automation/...)
|
|
35
|
+
exports.HubAutomationPermissions = {
|
|
36
|
+
Read: "hub_automation_read",
|
|
37
|
+
Write: "hub_automation_write",
|
|
38
|
+
};
|
|
39
|
+
// ------------------------------------------------------
|
|
40
|
+
// Fact catalog (F1: appointment domain facts only — Q15: no patient.* facts)
|
|
41
|
+
// ------------------------------------------------------
|
|
42
|
+
exports.AUTOMATION_APPOINTMENT_FACTS = [
|
|
43
|
+
"appointment.status",
|
|
44
|
+
// Confirmation is a first-class fact via statusBase (Q9) — no dedicated field.
|
|
45
|
+
"appointment.status_base",
|
|
46
|
+
"appointment.appointment_type",
|
|
47
|
+
"appointment.appointment_base_type",
|
|
48
|
+
// 'telemedicine' | 'in_person'
|
|
49
|
+
"appointment.appointment_mode",
|
|
50
|
+
// Derived from professional.professionalRef.id
|
|
51
|
+
"appointment.professional_id",
|
|
52
|
+
"appointment.procedure_ids",
|
|
53
|
+
"appointment.payment_status",
|
|
54
|
+
"appointment.calendar_id",
|
|
55
|
+
];
|
|
56
|
+
// ------------------------------------------------------
|
|
57
|
+
// Conditions (recursive AND/OR groups)
|
|
58
|
+
// ------------------------------------------------------
|
|
59
|
+
exports.AutomationOperatorEnum = {
|
|
60
|
+
Eq: "eq",
|
|
61
|
+
Neq: "neq",
|
|
62
|
+
In: "in",
|
|
63
|
+
NotIn: "not_in",
|
|
64
|
+
Exists: "exists",
|
|
65
|
+
NotExists: "not_exists",
|
|
66
|
+
IsTrue: "is_true",
|
|
67
|
+
IsFalse: "is_false",
|
|
68
|
+
};
|
|
69
|
+
// ------------------------------------------------------
|
|
70
|
+
// Outputs (auto Task | human Task)
|
|
71
|
+
// ------------------------------------------------------
|
|
72
|
+
exports.AutomationOutputTypeEnum = {
|
|
73
|
+
AutoTask: "auto_task",
|
|
74
|
+
HumanTask: "human_task",
|
|
75
|
+
};
|
|
76
|
+
// ------------------------------------------------------
|
|
77
|
+
// Run trace (Firestore doc: tenants/{t}/apps/hub-automation/runs/{runId})
|
|
78
|
+
// One doc per run; trace kept as fields (not a subcollection). 1MB cap →
|
|
79
|
+
// counts + capped samples, never a dump of every target.
|
|
80
|
+
// ------------------------------------------------------
|
|
81
|
+
exports.AutomationRunStatusEnum = {
|
|
82
|
+
Ok: "ok",
|
|
83
|
+
Limited: "limited",
|
|
84
|
+
BlockedDryRunRequired: "blocked_dry_run_required",
|
|
85
|
+
Error: "error",
|
|
86
|
+
};
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
export * from "./fb_collections";
|
|
2
|
+
|
|
3
|
+
import type { TaskAutoHandler, ITaskRetryPolicy, ITaskOnFailure } from "../evo-task";
|
|
4
|
+
|
|
5
|
+
// ======================================================
|
|
6
|
+
// hub-automation
|
|
7
|
+
//
|
|
8
|
+
// Declarative automation routines that MATERIALIZE Tasks (no side effects —
|
|
9
|
+
// every effect on the world flows through the Task Runner, decision Q1).
|
|
10
|
+
//
|
|
11
|
+
// A routine is: a TRIGGER (F1: cron) + a SELECTION of domain targets
|
|
12
|
+
// (F1: appointments) + nested condition BRANCHES → OUTPUTS (auto/human Tasks).
|
|
13
|
+
//
|
|
14
|
+
// NOTE:
|
|
15
|
+
// - These are hand-written contracts (no z.infer). Zod schemas live in
|
|
16
|
+
// src/apps/hub-automation/zod-schemas.ts.
|
|
17
|
+
// - F1 has no `patient.*` facts and no patient hydration (decision Q15):
|
|
18
|
+
// contact-data validation is the handler's responsibility at run time.
|
|
19
|
+
// ======================================================
|
|
20
|
+
|
|
21
|
+
// ----- Permissions (Firestore path: tenants/{t}/apps/hub-automation/...)
|
|
22
|
+
export const HubAutomationPermissions = {
|
|
23
|
+
Read: "hub_automation_read",
|
|
24
|
+
Write: "hub_automation_write",
|
|
25
|
+
} as const;
|
|
26
|
+
export type HubAutomationPermissions =
|
|
27
|
+
(typeof HubAutomationPermissions)[keyof typeof HubAutomationPermissions];
|
|
28
|
+
|
|
29
|
+
// ------------------------------------------------------
|
|
30
|
+
// Trigger (F1: cron only)
|
|
31
|
+
// ------------------------------------------------------
|
|
32
|
+
export interface IAutomationCronTrigger {
|
|
33
|
+
type: "cron";
|
|
34
|
+
cron: {
|
|
35
|
+
// Standard 5-field cron expression.
|
|
36
|
+
expression: string;
|
|
37
|
+
// IANA timezone; when omitted, the resolved tenant timezone is used.
|
|
38
|
+
timezone?: string;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type IAutomationTrigger = IAutomationCronTrigger;
|
|
43
|
+
|
|
44
|
+
// ------------------------------------------------------
|
|
45
|
+
// Selection (F1: appointment target only)
|
|
46
|
+
// ------------------------------------------------------
|
|
47
|
+
|
|
48
|
+
// `calendar` → a single target date (runDate + offset), for clinics that
|
|
49
|
+
// run/notify on weekends.
|
|
50
|
+
// `business` → an ARRAY of target dates via the D+X-Especial semantics
|
|
51
|
+
// (weekend anticipation/recovery); resolved by resolveTargetDates.
|
|
52
|
+
export type AutomationDateOffsetMode = "calendar" | "business";
|
|
53
|
+
|
|
54
|
+
export interface IAutomationDateWindow {
|
|
55
|
+
// May be negative (retroactive routines, e.g. post-consultation).
|
|
56
|
+
offset_days: number;
|
|
57
|
+
offset_mode: AutomationDateOffsetMode;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface IAutomationAppointmentSelection {
|
|
61
|
+
target: "appointment";
|
|
62
|
+
appointment: {
|
|
63
|
+
// Empty/omitted = all calendars of the tenant.
|
|
64
|
+
calendar_ids?: string[];
|
|
65
|
+
date_window: IAutomationDateWindow;
|
|
66
|
+
// Filters applied in memory over the day window (no server-side status query).
|
|
67
|
+
status_in?: string[];
|
|
68
|
+
status_base_in?: string[];
|
|
69
|
+
appointment_type_not_in?: string[];
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type IAutomationSelection = IAutomationAppointmentSelection;
|
|
74
|
+
|
|
75
|
+
// ------------------------------------------------------
|
|
76
|
+
// Fact catalog (F1: appointment domain facts only — Q15: no patient.* facts)
|
|
77
|
+
// ------------------------------------------------------
|
|
78
|
+
export const AUTOMATION_APPOINTMENT_FACTS = [
|
|
79
|
+
"appointment.status",
|
|
80
|
+
// Confirmation is a first-class fact via statusBase (Q9) — no dedicated field.
|
|
81
|
+
"appointment.status_base",
|
|
82
|
+
"appointment.appointment_type",
|
|
83
|
+
"appointment.appointment_base_type",
|
|
84
|
+
// 'telemedicine' | 'in_person'
|
|
85
|
+
"appointment.appointment_mode",
|
|
86
|
+
// Derived from professional.professionalRef.id
|
|
87
|
+
"appointment.professional_id",
|
|
88
|
+
"appointment.procedure_ids",
|
|
89
|
+
"appointment.payment_status",
|
|
90
|
+
"appointment.calendar_id",
|
|
91
|
+
] as const;
|
|
92
|
+
|
|
93
|
+
export type AutomationAppointmentFact =
|
|
94
|
+
(typeof AUTOMATION_APPOINTMENT_FACTS)[number];
|
|
95
|
+
|
|
96
|
+
export type AutomationFact = AutomationAppointmentFact;
|
|
97
|
+
|
|
98
|
+
// ------------------------------------------------------
|
|
99
|
+
// Conditions (recursive AND/OR groups)
|
|
100
|
+
// ------------------------------------------------------
|
|
101
|
+
export const AutomationOperatorEnum = {
|
|
102
|
+
Eq: "eq",
|
|
103
|
+
Neq: "neq",
|
|
104
|
+
In: "in",
|
|
105
|
+
NotIn: "not_in",
|
|
106
|
+
Exists: "exists",
|
|
107
|
+
NotExists: "not_exists",
|
|
108
|
+
IsTrue: "is_true",
|
|
109
|
+
IsFalse: "is_false",
|
|
110
|
+
} as const;
|
|
111
|
+
|
|
112
|
+
export type AutomationOperator =
|
|
113
|
+
(typeof AutomationOperatorEnum)[keyof typeof AutomationOperatorEnum];
|
|
114
|
+
|
|
115
|
+
export interface IAutomationCondition {
|
|
116
|
+
// A fact key from the catalog (AutomationFact); kept as string for forward
|
|
117
|
+
// compatibility with facts added in later slices.
|
|
118
|
+
fact: string;
|
|
119
|
+
operator: AutomationOperator;
|
|
120
|
+
// Not required for unary operators (exists/not_exists/is_true/is_false).
|
|
121
|
+
value?: unknown;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export type AutomationCombinator = "and" | "or";
|
|
125
|
+
|
|
126
|
+
export interface IAutomationConditionGroup {
|
|
127
|
+
combinator: AutomationCombinator;
|
|
128
|
+
conditions: Array<IAutomationCondition | IAutomationConditionGroup>;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ------------------------------------------------------
|
|
132
|
+
// Outputs (auto Task | human Task)
|
|
133
|
+
// ------------------------------------------------------
|
|
134
|
+
export const AutomationOutputTypeEnum = {
|
|
135
|
+
AutoTask: "auto_task",
|
|
136
|
+
HumanTask: "human_task",
|
|
137
|
+
} as const;
|
|
138
|
+
|
|
139
|
+
export type AutomationOutputType =
|
|
140
|
+
(typeof AutomationOutputTypeEnum)[keyof typeof AutomationOutputTypeEnum];
|
|
141
|
+
|
|
142
|
+
// When the materialized Task should execute:
|
|
143
|
+
// - immediate: now (Task Runner picks it up on the next tick)
|
|
144
|
+
// - send_at_local: HH:mm resolved in the tenant timezone, anchored to the
|
|
145
|
+
// target date or the run date.
|
|
146
|
+
export type IAutomationExecuteAt =
|
|
147
|
+
| { rule: "immediate" }
|
|
148
|
+
| {
|
|
149
|
+
rule: "send_at_local";
|
|
150
|
+
// "HH:mm" (24h)
|
|
151
|
+
time: string;
|
|
152
|
+
base: "target_date" | "run_date";
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export interface IAutomationAutoTaskOutput {
|
|
156
|
+
type: "auto_task";
|
|
157
|
+
handler: TaskAutoHandler;
|
|
158
|
+
kind: string;
|
|
159
|
+
// Payload values that are strings accept refs: {{appointment.id}},
|
|
160
|
+
// {{appointment.calendar_id}}, {{patient.id}} (resolved by the materializer).
|
|
161
|
+
payload: Record<string, unknown>;
|
|
162
|
+
execute_at: IAutomationExecuteAt;
|
|
163
|
+
retry?: ITaskRetryPolicy;
|
|
164
|
+
on_failure?: ITaskOnFailure;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface IAutomationHumanTaskOutput {
|
|
168
|
+
type: "human_task";
|
|
169
|
+
title: string;
|
|
170
|
+
description?: string;
|
|
171
|
+
// Firestore path to the assignee user doc.
|
|
172
|
+
assignee_ref?: string;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export type IAutomationOutput =
|
|
176
|
+
| IAutomationAutoTaskOutput
|
|
177
|
+
| IAutomationHumanTaskOutput;
|
|
178
|
+
|
|
179
|
+
// ------------------------------------------------------
|
|
180
|
+
// Branches
|
|
181
|
+
// ------------------------------------------------------
|
|
182
|
+
export interface IAutomationBranch {
|
|
183
|
+
id: string;
|
|
184
|
+
name: string;
|
|
185
|
+
// Guard group; omitted = always matches (typical for a fallback branch).
|
|
186
|
+
when?: IAutomationConditionGroup;
|
|
187
|
+
// The "else" branch (fires when no other branch matched, exclusive mode).
|
|
188
|
+
is_fallback?: boolean;
|
|
189
|
+
outputs: IAutomationOutput[];
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// 'all' = every matching branch fires; 'exclusive' = first match wins,
|
|
193
|
+
// fallback catches the rest.
|
|
194
|
+
export type AutomationBranchMode = "all" | "exclusive";
|
|
195
|
+
|
|
196
|
+
// ------------------------------------------------------
|
|
197
|
+
// Routine (Firestore doc: tenants/{t}/apps/hub-automation/routines/{id})
|
|
198
|
+
// ------------------------------------------------------
|
|
199
|
+
export interface IAutomationRoutine {
|
|
200
|
+
id: string;
|
|
201
|
+
name: string;
|
|
202
|
+
description?: string;
|
|
203
|
+
active: boolean;
|
|
204
|
+
// Routine's own version counter (bumped on edit; distinct from doc model_ver).
|
|
205
|
+
version: number;
|
|
206
|
+
trigger: IAutomationTrigger;
|
|
207
|
+
selection: IAutomationSelection;
|
|
208
|
+
branch_mode: AutomationBranchMode;
|
|
209
|
+
branches: IAutomationBranch[];
|
|
210
|
+
guards: {
|
|
211
|
+
max_tasks_per_run: number;
|
|
212
|
+
};
|
|
213
|
+
// Q11: presence gates materialization (dry-run required on first activation).
|
|
214
|
+
// `version` is stored for audit only (edits do not re-require a dry-run).
|
|
215
|
+
dry_run_stamp?: {
|
|
216
|
+
version: number;
|
|
217
|
+
at: Date;
|
|
218
|
+
by: string;
|
|
219
|
+
};
|
|
220
|
+
// Cron bookkeeping: last occurrence already fired by the sweeper.
|
|
221
|
+
trigger_state?: {
|
|
222
|
+
last_fired_at?: Date;
|
|
223
|
+
};
|
|
224
|
+
stats?: {
|
|
225
|
+
last_run_at?: Date;
|
|
226
|
+
last_materialized_at?: Date;
|
|
227
|
+
last_run_id?: string;
|
|
228
|
+
};
|
|
229
|
+
created_at: Date;
|
|
230
|
+
updated_at: Date;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// ------------------------------------------------------
|
|
234
|
+
// Module config (Firestore doc: tenants/{t}/apps/hub-automation/config/config)
|
|
235
|
+
// ------------------------------------------------------
|
|
236
|
+
export interface IHubAutomationConfig {
|
|
237
|
+
active: boolean;
|
|
238
|
+
limits?: {
|
|
239
|
+
max_tasks_per_run_default?: number;
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// ------------------------------------------------------
|
|
244
|
+
// Run trace (Firestore doc: tenants/{t}/apps/hub-automation/runs/{runId})
|
|
245
|
+
// One doc per run; trace kept as fields (not a subcollection). 1MB cap →
|
|
246
|
+
// counts + capped samples, never a dump of every target.
|
|
247
|
+
// ------------------------------------------------------
|
|
248
|
+
export const AutomationRunStatusEnum = {
|
|
249
|
+
Ok: "ok",
|
|
250
|
+
Limited: "limited",
|
|
251
|
+
BlockedDryRunRequired: "blocked_dry_run_required",
|
|
252
|
+
Error: "error",
|
|
253
|
+
} as const;
|
|
254
|
+
|
|
255
|
+
export type AutomationRunStatus =
|
|
256
|
+
(typeof AutomationRunStatusEnum)[keyof typeof AutomationRunStatusEnum];
|
|
257
|
+
|
|
258
|
+
// Per-condition evaluation result (shape mirrors HubIA's ConditionResult).
|
|
259
|
+
export interface IAutomationConditionResult {
|
|
260
|
+
fact: string;
|
|
261
|
+
op: AutomationOperator;
|
|
262
|
+
value?: unknown;
|
|
263
|
+
actual?: unknown;
|
|
264
|
+
passed: boolean;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export interface IAutomationRunBranchCounts {
|
|
268
|
+
matched: number;
|
|
269
|
+
created: number;
|
|
270
|
+
already_existed: number;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface IAutomationRunSample {
|
|
274
|
+
appointment_id: string;
|
|
275
|
+
branch_id?: string;
|
|
276
|
+
// e.g. 'created' | 'already_existed' | 'not_matched' | 'suppressed_by_limit'
|
|
277
|
+
decision: string;
|
|
278
|
+
conditions?: IAutomationConditionResult[];
|
|
279
|
+
[key: string]: unknown;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export interface IAutomationRunTrace {
|
|
283
|
+
routine_id: string;
|
|
284
|
+
routine_version: number;
|
|
285
|
+
trigger: {
|
|
286
|
+
type: string;
|
|
287
|
+
fired_at: Date;
|
|
288
|
+
cron_expression?: string;
|
|
289
|
+
};
|
|
290
|
+
dry_run: boolean;
|
|
291
|
+
window: {
|
|
292
|
+
// Q16: a run may span multiple target dates (yyyy-MM-dd).
|
|
293
|
+
target_dates: string[];
|
|
294
|
+
timezone: string;
|
|
295
|
+
};
|
|
296
|
+
status: AutomationRunStatus;
|
|
297
|
+
counts: {
|
|
298
|
+
targets_scanned: number;
|
|
299
|
+
tasks_created: number;
|
|
300
|
+
tasks_already_existed: number;
|
|
301
|
+
tasks_suppressed_by_limit: number;
|
|
302
|
+
per_branch: Record<string, IAutomationRunBranchCounts>;
|
|
303
|
+
};
|
|
304
|
+
// Capped (~20/branch) — full detail goes to BigQuery.
|
|
305
|
+
samples?: IAutomationRunSample[];
|
|
306
|
+
error?: {
|
|
307
|
+
message: string;
|
|
308
|
+
code?: string | number;
|
|
309
|
+
details?: Record<string, unknown>;
|
|
310
|
+
};
|
|
311
|
+
duration_ms: number;
|
|
312
|
+
}
|