evo360-types 1.3.762 → 1.3.766
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-docs/zod-schemas.d.ts +3260 -0
- package/dist/apps/evo-docs/zod-schemas.js +258 -0
- package/dist/apps/evo-docs/zod-schemas.ts +299 -0
- package/dist/apps/evo-task/zod-schemas.d.ts +52 -52
- package/dist/apps/evo-task/zod-schemas.js +3 -0
- package/dist/apps/evo-task/zod-schemas.ts +3 -0
- package/dist/apps/hub-automation/zod-schemas.d.ts +941 -172
- package/dist/apps/hub-automation/zod-schemas.js +68 -4
- package/dist/apps/hub-automation/zod-schemas.ts +72 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.ts +2 -0
- package/dist/types/evo-docs/fb_collections.d.ts +2 -0
- package/dist/types/evo-docs/fb_collections.js +9 -0
- package/dist/types/evo-docs/fb_collections.ts +7 -0
- package/dist/types/evo-docs/index.d.ts +291 -0
- package/dist/types/evo-docs/index.js +125 -0
- package/dist/types/evo-docs/index.ts +385 -0
- package/dist/types/evo-reports/index.d.ts +3 -1
- package/dist/types/evo-reports/index.ts +8 -1
- package/dist/types/evo-task/index.d.ts +1 -0
- package/dist/types/evo-task/index.js +7 -0
- package/dist/types/evo-task/index.ts +7 -0
- package/dist/types/hub-automation/index.d.ts +59 -2
- package/dist/types/hub-automation/index.js +16 -3
- package/dist/types/hub-automation/index.ts +116 -11
- package/package.json +1 -1
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.zAttachmentReindexBodySchema = exports.zAttachmentPatchBodySchema = exports.zAttachmentSubjectRefSchema = exports.zAttachmentListQuerySchema = exports.zAttachmentIndexEventSchema = exports.zAttachmentSchema = exports.zAttachmentLegacySchema = exports.zAttachmentPrimarySubjectSchema = exports.zAttachmentExternalLinkSchema = exports.zAttachmentClassificationSchema = exports.zAttachmentAiSuggestionSchema = exports.zAttachmentFileSchema = exports.zAttachmentSourceSchema = exports.zAttachmentActorSchema = exports.zAttachmentIndexReasonSchema = exports.zAttachmentSubjectTypeSchema = exports.zAttachmentMediaKindSchema = exports.zAttachmentClassificationSourceSchema = exports.zAttachmentDirectionSchema = exports.zAttachmentSourceKindSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const zod_schemas_1 = require("../shared/zod-schemas");
|
|
6
|
+
const zod_schemas_2 = require("../evo-task/zod-schemas");
|
|
7
|
+
const zod_schemas_3 = require("../evo-med/dic/zod-schemas");
|
|
8
|
+
const evo_docs_1 = require("../../types/evo-docs");
|
|
9
|
+
// Schemas zod do evo-docs (feat-312). As interfaces TS equivalentes ficam em
|
|
10
|
+
// src/types/evo-docs/index.ts (convenção do projeto: `apps/` = zod, `types/` = interfaces).
|
|
11
|
+
// Os enums vêm das constantes de lá (`z.nativeEnum`), sem lista espelhada à mão.
|
|
12
|
+
// ───────── Enums ─────────
|
|
13
|
+
exports.zAttachmentSourceKindSchema = zod_1.z.nativeEnum(evo_docs_1.AttachmentSourceKindEnum);
|
|
14
|
+
exports.zAttachmentDirectionSchema = zod_1.z.nativeEnum(evo_docs_1.AttachmentDirectionEnum);
|
|
15
|
+
exports.zAttachmentClassificationSourceSchema = zod_1.z.nativeEnum(evo_docs_1.AttachmentClassificationSourceEnum);
|
|
16
|
+
exports.zAttachmentMediaKindSchema = zod_1.z.nativeEnum(evo_docs_1.AttachmentMediaKindEnum);
|
|
17
|
+
exports.zAttachmentSubjectTypeSchema = zod_1.z.enum(evo_docs_1.ATTACHMENT_SUBJECT_TYPES);
|
|
18
|
+
exports.zAttachmentIndexReasonSchema = zod_1.z.nativeEnum(evo_docs_1.AttachmentIndexReasonEnum);
|
|
19
|
+
// ───────── Entidade ─────────
|
|
20
|
+
exports.zAttachmentActorSchema = zod_1.z
|
|
21
|
+
.object({
|
|
22
|
+
userId: zod_1.z.string(),
|
|
23
|
+
displayName: zod_1.z.string(),
|
|
24
|
+
})
|
|
25
|
+
.passthrough();
|
|
26
|
+
const MESSAGE_SOURCE_KINDS = evo_docs_1.ATTACHMENT_MESSAGE_SOURCE_KINDS;
|
|
27
|
+
/** `direction` é obrigatório (inbound|outbound) quando a fonte é mensagem (Q9). */
|
|
28
|
+
exports.zAttachmentSourceSchema = zod_1.z
|
|
29
|
+
.object({
|
|
30
|
+
kind: exports.zAttachmentSourceKindSchema,
|
|
31
|
+
provider: zod_1.z.string().nullable().optional(),
|
|
32
|
+
channel_id: zod_1.z.string().nullable().optional(),
|
|
33
|
+
channel_type: zod_1.z.string().nullable().optional(),
|
|
34
|
+
department_id: zod_1.z.string().nullable().optional(),
|
|
35
|
+
thread_id: zod_1.z.string().nullable().optional(),
|
|
36
|
+
message_id: zod_1.z.string().nullable().optional(),
|
|
37
|
+
ticket_id: zod_1.z.string().nullable().optional(),
|
|
38
|
+
message_index: zod_1.z.number().int().nonnegative().nullable().optional(),
|
|
39
|
+
direction: exports.zAttachmentDirectionSchema.nullable().optional(),
|
|
40
|
+
email: zod_1.z
|
|
41
|
+
.object({
|
|
42
|
+
subject: zod_1.z.string().nullable().optional(),
|
|
43
|
+
from: zod_1.z.string().nullable().optional(),
|
|
44
|
+
})
|
|
45
|
+
.passthrough()
|
|
46
|
+
.nullable()
|
|
47
|
+
.optional(),
|
|
48
|
+
uploaded_by: exports.zAttachmentActorSchema.nullable().optional(),
|
|
49
|
+
occurred_at: zod_1.z.coerce.date(),
|
|
50
|
+
})
|
|
51
|
+
.passthrough()
|
|
52
|
+
.superRefine((source, ctx) => {
|
|
53
|
+
if (MESSAGE_SOURCE_KINDS.indexOf(source.kind) >= 0 && !source.direction) {
|
|
54
|
+
ctx.addIssue({
|
|
55
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
56
|
+
path: ["direction"],
|
|
57
|
+
message: `direction is required when source.kind is ${source.kind}`,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
/** Bloqueado pode vir sem `gcs_uri` (só `quarantine_uri`); não bloqueado exige `gcs_uri`. */
|
|
62
|
+
exports.zAttachmentFileSchema = zod_1.z
|
|
63
|
+
.object({
|
|
64
|
+
gcs_uri: zod_1.z.string().min(1).nullable().optional(),
|
|
65
|
+
filename: zod_1.z.string().min(1),
|
|
66
|
+
original_filename: zod_1.z.string().nullable().optional(),
|
|
67
|
+
content_type: zod_1.z.string().min(1),
|
|
68
|
+
size_bytes: zod_1.z.number().int().nonnegative().nullable().optional(),
|
|
69
|
+
sha256: zod_1.z.string().nullable().optional(),
|
|
70
|
+
blocked: zod_1.z.boolean().optional(),
|
|
71
|
+
blocked_reason: zod_1.z.string().nullable().optional(),
|
|
72
|
+
quarantine_uri: zod_1.z.string().nullable().optional(),
|
|
73
|
+
media_kind: exports.zAttachmentMediaKindSchema,
|
|
74
|
+
caption: zod_1.z.string().nullable().optional(),
|
|
75
|
+
})
|
|
76
|
+
.passthrough()
|
|
77
|
+
.superRefine((file, ctx) => {
|
|
78
|
+
if (file.blocked) {
|
|
79
|
+
if (!file.quarantine_uri) {
|
|
80
|
+
ctx.addIssue({
|
|
81
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
82
|
+
path: ["quarantine_uri"],
|
|
83
|
+
message: "quarantine_uri is required when the file is blocked",
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else if (!file.gcs_uri) {
|
|
88
|
+
ctx.addIssue({
|
|
89
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
90
|
+
path: ["gcs_uri"],
|
|
91
|
+
message: "gcs_uri is required unless the file is blocked",
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
exports.zAttachmentAiSuggestionSchema = zod_1.z
|
|
96
|
+
.object({
|
|
97
|
+
kind: zod_1.z.string().min(1),
|
|
98
|
+
label: zod_1.z.string().nullable().optional(),
|
|
99
|
+
summary: zod_1.z.string(),
|
|
100
|
+
confidence: zod_1.z.number().min(0).max(1),
|
|
101
|
+
prompt_version: zod_1.z.string(),
|
|
102
|
+
suggested_base_category: zod_schemas_3.zPatientAttachmentBaseCategorySchema.nullable(),
|
|
103
|
+
classified_at: zod_1.z.coerce.date(),
|
|
104
|
+
})
|
|
105
|
+
.passthrough();
|
|
106
|
+
exports.zAttachmentClassificationSchema = zod_1.z
|
|
107
|
+
.object({
|
|
108
|
+
category: zod_1.z.string().nullable().optional(),
|
|
109
|
+
base_category: zod_schemas_3.zPatientAttachmentBaseCategorySchema.nullable().optional(),
|
|
110
|
+
category_color: zod_1.z.string().nullable().optional(),
|
|
111
|
+
source: exports.zAttachmentClassificationSourceSchema,
|
|
112
|
+
reviewed_by: exports.zAttachmentActorSchema.nullable().optional(),
|
|
113
|
+
reviewed_at: zod_1.z.coerce.date().nullable().optional(),
|
|
114
|
+
ai: exports.zAttachmentAiSuggestionSchema.nullable().optional(),
|
|
115
|
+
})
|
|
116
|
+
.passthrough();
|
|
117
|
+
/** Link do anexo: o `type` precisa ser de `ATTACHMENT_SUBJECT_TYPES`. */
|
|
118
|
+
exports.zAttachmentExternalLinkSchema = zod_schemas_2.zExternalLinkSchema.refine((link) => (0, evo_docs_1.isAttachmentSubjectType)(link.type), { message: `externalLinks type must be one of ${evo_docs_1.ATTACHMENT_SUBJECT_TYPES.join(", ")}`, path: ["type"] });
|
|
119
|
+
exports.zAttachmentPrimarySubjectSchema = zod_1.z.object({
|
|
120
|
+
type: exports.zAttachmentSubjectTypeSchema,
|
|
121
|
+
id: zod_1.z.string().min(1),
|
|
122
|
+
});
|
|
123
|
+
exports.zAttachmentLegacySchema = zod_1.z
|
|
124
|
+
.object({
|
|
125
|
+
patient_id: zod_1.z.string().min(1),
|
|
126
|
+
migrated_at: zod_1.z.coerce.date(),
|
|
127
|
+
})
|
|
128
|
+
.passthrough();
|
|
129
|
+
exports.zAttachmentSchema = zod_schemas_1.zFireDocSchema
|
|
130
|
+
.extend({
|
|
131
|
+
externalLinks: zod_1.z.array(exports.zAttachmentExternalLinkSchema),
|
|
132
|
+
externalLinkKeys: zod_1.z.array(zod_1.z.string()),
|
|
133
|
+
primary_subject: exports.zAttachmentPrimarySubjectSchema,
|
|
134
|
+
source: exports.zAttachmentSourceSchema,
|
|
135
|
+
file: exports.zAttachmentFileSchema,
|
|
136
|
+
classification: exports.zAttachmentClassificationSchema,
|
|
137
|
+
tags: zod_1.z.array(zod_schemas_1.zTagSchema).nullable().optional(),
|
|
138
|
+
description: zod_1.z.string().nullable().optional(),
|
|
139
|
+
legacy: exports.zAttachmentLegacySchema.nullable().optional(),
|
|
140
|
+
created_by: exports.zAttachmentActorSchema.nullable().optional(),
|
|
141
|
+
})
|
|
142
|
+
.passthrough();
|
|
143
|
+
// ───────── Evento de indexação (tópico app_evo-docs_attachments_index) ─────────
|
|
144
|
+
exports.zAttachmentIndexEventSchema = zod_1.z
|
|
145
|
+
.object({
|
|
146
|
+
tenant: zod_1.z.string().min(1),
|
|
147
|
+
thread_id: zod_1.z.string().min(1),
|
|
148
|
+
message_id: zod_1.z.string().min(1),
|
|
149
|
+
direction: zod_1.z.enum(["in", "out"]),
|
|
150
|
+
provider: zod_1.z.string().min(1),
|
|
151
|
+
channel_id: zod_1.z.string().min(1),
|
|
152
|
+
channel_type: zod_1.z.string().min(1),
|
|
153
|
+
ticket_id: zod_1.z.string().nullable().optional(),
|
|
154
|
+
department_id: zod_1.z.string().nullable().optional(),
|
|
155
|
+
lead_id: zod_1.z.string().nullable().optional(),
|
|
156
|
+
external_links: zod_1.z.array(zod_schemas_2.zExternalLinkSchema).nullable().optional(),
|
|
157
|
+
created_by: exports.zAttachmentActorSchema.nullable().optional(),
|
|
158
|
+
occurred_at: zod_1.z.coerce.date(),
|
|
159
|
+
trace_id: zod_1.z.string().nullable().optional(),
|
|
160
|
+
reason: exports.zAttachmentIndexReasonSchema.default(evo_docs_1.AttachmentIndexReasonEnum.Message),
|
|
161
|
+
})
|
|
162
|
+
.passthrough();
|
|
163
|
+
// ───────── API (hubomni_admin) ─────────
|
|
164
|
+
/** Query string booleana: aceita true/false, "1"/"0", "true"/"false". */
|
|
165
|
+
const zQueryBoolean = zod_1.z.preprocess((v) => {
|
|
166
|
+
if (v === "1" || v === "true")
|
|
167
|
+
return true;
|
|
168
|
+
if (v === "0" || v === "false")
|
|
169
|
+
return false;
|
|
170
|
+
return v;
|
|
171
|
+
}, zod_1.z.boolean());
|
|
172
|
+
const LIST_ROOT_TYPES = evo_docs_1.ATTACHMENT_LIST_ROOT_TYPES;
|
|
173
|
+
const ATTACHMENT_PATCH_LINKS_MAX = 20;
|
|
174
|
+
exports.zAttachmentListQuerySchema = zod_1.z
|
|
175
|
+
.object({
|
|
176
|
+
subject: zod_1.z
|
|
177
|
+
.string()
|
|
178
|
+
.refine((s) => {
|
|
179
|
+
const i = s.indexOf(":");
|
|
180
|
+
return i > 0 && i < s.length - 1 && LIST_ROOT_TYPES.indexOf(s.slice(0, i)) >= 0;
|
|
181
|
+
}, { message: `subject must be "type:id" with type in ${evo_docs_1.ATTACHMENT_LIST_ROOT_TYPES.join(", ")}` })
|
|
182
|
+
.optional(),
|
|
183
|
+
/** Aceita array ou string separada por vírgula (query string). */
|
|
184
|
+
message_ids: zod_1.z
|
|
185
|
+
.preprocess((v) => typeof v === "string"
|
|
186
|
+
? v
|
|
187
|
+
.split(",")
|
|
188
|
+
.map((s) => s.trim())
|
|
189
|
+
.filter((s) => s !== "")
|
|
190
|
+
: v, zod_1.z.array(zod_1.z.string().min(1)).min(1).max(evo_docs_1.ATTACHMENT_LIST_MAX_MESSAGE_IDS))
|
|
191
|
+
.optional(),
|
|
192
|
+
family: zQueryBoolean.optional(),
|
|
193
|
+
/** Interno (Q5): não expor na tela nem no service do FE. */
|
|
194
|
+
family_depth: zod_1.z.coerce.number().int().min(1).max(2).optional(),
|
|
195
|
+
patient: zod_1.z.string().min(1).optional(),
|
|
196
|
+
direction: exports.zAttachmentDirectionSchema.optional(),
|
|
197
|
+
base_category: zod_schemas_3.zPatientAttachmentBaseCategorySchema.optional(),
|
|
198
|
+
blocked: zQueryBoolean.optional(),
|
|
199
|
+
media_kind: exports.zAttachmentMediaKindSchema.optional(),
|
|
200
|
+
source_kind: exports.zAttachmentSourceKindSchema.optional(),
|
|
201
|
+
tag: zod_1.z.string().min(1).max(50).optional(),
|
|
202
|
+
limit: zod_1.z.coerce.number().int().min(1).max(evo_docs_1.ATTACHMENT_LIST_MAX_LIMIT).optional(),
|
|
203
|
+
cursor: zod_1.z.string().min(1).optional(),
|
|
204
|
+
})
|
|
205
|
+
.superRefine((q, ctx) => {
|
|
206
|
+
const hasSubject = q.subject !== undefined;
|
|
207
|
+
const hasMessageIds = q.message_ids !== undefined;
|
|
208
|
+
if (hasSubject === hasMessageIds) {
|
|
209
|
+
ctx.addIssue({
|
|
210
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
211
|
+
path: ["subject"],
|
|
212
|
+
message: "exactly one of subject or message_ids is required",
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
if (hasMessageIds && q.family) {
|
|
216
|
+
ctx.addIssue({
|
|
217
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
218
|
+
path: ["family"],
|
|
219
|
+
message: "family is not supported with message_ids",
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
if (hasMessageIds && q.cursor !== undefined) {
|
|
223
|
+
ctx.addIssue({
|
|
224
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
225
|
+
path: ["cursor"],
|
|
226
|
+
message: "cursor is not supported with message_ids",
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
exports.zAttachmentSubjectRefSchema = zod_1.z
|
|
231
|
+
.object({
|
|
232
|
+
type: exports.zAttachmentSubjectTypeSchema,
|
|
233
|
+
id: zod_1.z.string().min(1),
|
|
234
|
+
label: zod_1.z.string().optional(),
|
|
235
|
+
})
|
|
236
|
+
.strict();
|
|
237
|
+
exports.zAttachmentPatchBodySchema = zod_1.z
|
|
238
|
+
.object({
|
|
239
|
+
category: zod_1.z.string().min(1).max(255).nullable().optional(),
|
|
240
|
+
base_category: zod_schemas_3.zPatientAttachmentBaseCategorySchema.nullable().optional(),
|
|
241
|
+
category_color: zod_1.z
|
|
242
|
+
.string()
|
|
243
|
+
.regex(/^#[0-9A-Fa-f]{6}$/)
|
|
244
|
+
.nullable()
|
|
245
|
+
.optional(),
|
|
246
|
+
description: zod_1.z.string().max(evo_docs_1.ATTACHMENT_DESCRIPTION_MAX).nullable().optional(),
|
|
247
|
+
tags: zod_1.z.array(zod_schemas_1.zTagSchema).max(evo_docs_1.ATTACHMENT_TAGS_MAX).optional(),
|
|
248
|
+
add_links: zod_1.z.array(exports.zAttachmentSubjectRefSchema).max(ATTACHMENT_PATCH_LINKS_MAX).optional(),
|
|
249
|
+
remove_links: zod_1.z.array(exports.zAttachmentSubjectRefSchema).max(ATTACHMENT_PATCH_LINKS_MAX).optional(),
|
|
250
|
+
})
|
|
251
|
+
.strict()
|
|
252
|
+
.refine((b) => Object.keys(b).length > 0, { message: "empty patch body" });
|
|
253
|
+
exports.zAttachmentReindexBodySchema = zod_1.z
|
|
254
|
+
.object({
|
|
255
|
+
thread_id: zod_1.z.string().min(1),
|
|
256
|
+
message_id: zod_1.z.string().min(1).optional(),
|
|
257
|
+
})
|
|
258
|
+
.strict();
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { zFireDocSchema, zTagSchema } from "../shared/zod-schemas";
|
|
3
|
+
import { zExternalLinkSchema } from "../evo-task/zod-schemas";
|
|
4
|
+
import { zPatientAttachmentBaseCategorySchema } from "../evo-med/dic/zod-schemas";
|
|
5
|
+
import {
|
|
6
|
+
ATTACHMENT_DESCRIPTION_MAX,
|
|
7
|
+
ATTACHMENT_LIST_MAX_LIMIT,
|
|
8
|
+
ATTACHMENT_LIST_MAX_MESSAGE_IDS,
|
|
9
|
+
ATTACHMENT_LIST_ROOT_TYPES,
|
|
10
|
+
ATTACHMENT_MESSAGE_SOURCE_KINDS,
|
|
11
|
+
ATTACHMENT_SUBJECT_TYPES,
|
|
12
|
+
ATTACHMENT_TAGS_MAX,
|
|
13
|
+
AttachmentClassificationSourceEnum,
|
|
14
|
+
AttachmentDirectionEnum,
|
|
15
|
+
AttachmentIndexReasonEnum,
|
|
16
|
+
AttachmentMediaKindEnum,
|
|
17
|
+
AttachmentSourceKindEnum,
|
|
18
|
+
isAttachmentSubjectType,
|
|
19
|
+
} from "../../types/evo-docs";
|
|
20
|
+
|
|
21
|
+
// Schemas zod do evo-docs (feat-312). As interfaces TS equivalentes ficam em
|
|
22
|
+
// src/types/evo-docs/index.ts (convenção do projeto: `apps/` = zod, `types/` = interfaces).
|
|
23
|
+
// Os enums vêm das constantes de lá (`z.nativeEnum`), sem lista espelhada à mão.
|
|
24
|
+
|
|
25
|
+
// ───────── Enums ─────────
|
|
26
|
+
|
|
27
|
+
export const zAttachmentSourceKindSchema = z.nativeEnum(AttachmentSourceKindEnum);
|
|
28
|
+
export const zAttachmentDirectionSchema = z.nativeEnum(AttachmentDirectionEnum);
|
|
29
|
+
export const zAttachmentClassificationSourceSchema = z.nativeEnum(AttachmentClassificationSourceEnum);
|
|
30
|
+
export const zAttachmentMediaKindSchema = z.nativeEnum(AttachmentMediaKindEnum);
|
|
31
|
+
export const zAttachmentSubjectTypeSchema = z.enum(ATTACHMENT_SUBJECT_TYPES);
|
|
32
|
+
export const zAttachmentIndexReasonSchema = z.nativeEnum(AttachmentIndexReasonEnum);
|
|
33
|
+
|
|
34
|
+
// ───────── Entidade ─────────
|
|
35
|
+
|
|
36
|
+
export const zAttachmentActorSchema = z
|
|
37
|
+
.object({
|
|
38
|
+
userId: z.string(),
|
|
39
|
+
displayName: z.string(),
|
|
40
|
+
})
|
|
41
|
+
.passthrough();
|
|
42
|
+
|
|
43
|
+
const MESSAGE_SOURCE_KINDS: readonly string[] = ATTACHMENT_MESSAGE_SOURCE_KINDS;
|
|
44
|
+
|
|
45
|
+
/** `direction` é obrigatório (inbound|outbound) quando a fonte é mensagem (Q9). */
|
|
46
|
+
export const zAttachmentSourceSchema = z
|
|
47
|
+
.object({
|
|
48
|
+
kind: zAttachmentSourceKindSchema,
|
|
49
|
+
provider: z.string().nullable().optional(),
|
|
50
|
+
channel_id: z.string().nullable().optional(),
|
|
51
|
+
channel_type: z.string().nullable().optional(),
|
|
52
|
+
department_id: z.string().nullable().optional(),
|
|
53
|
+
thread_id: z.string().nullable().optional(),
|
|
54
|
+
message_id: z.string().nullable().optional(),
|
|
55
|
+
ticket_id: z.string().nullable().optional(),
|
|
56
|
+
message_index: z.number().int().nonnegative().nullable().optional(),
|
|
57
|
+
direction: zAttachmentDirectionSchema.nullable().optional(),
|
|
58
|
+
email: z
|
|
59
|
+
.object({
|
|
60
|
+
subject: z.string().nullable().optional(),
|
|
61
|
+
from: z.string().nullable().optional(),
|
|
62
|
+
})
|
|
63
|
+
.passthrough()
|
|
64
|
+
.nullable()
|
|
65
|
+
.optional(),
|
|
66
|
+
uploaded_by: zAttachmentActorSchema.nullable().optional(),
|
|
67
|
+
occurred_at: z.coerce.date(),
|
|
68
|
+
})
|
|
69
|
+
.passthrough()
|
|
70
|
+
.superRefine((source, ctx) => {
|
|
71
|
+
if (MESSAGE_SOURCE_KINDS.indexOf(source.kind) >= 0 && !source.direction) {
|
|
72
|
+
ctx.addIssue({
|
|
73
|
+
code: z.ZodIssueCode.custom,
|
|
74
|
+
path: ["direction"],
|
|
75
|
+
message: `direction is required when source.kind is ${source.kind}`,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
/** Bloqueado pode vir sem `gcs_uri` (só `quarantine_uri`); não bloqueado exige `gcs_uri`. */
|
|
81
|
+
export const zAttachmentFileSchema = z
|
|
82
|
+
.object({
|
|
83
|
+
gcs_uri: z.string().min(1).nullable().optional(),
|
|
84
|
+
filename: z.string().min(1),
|
|
85
|
+
original_filename: z.string().nullable().optional(),
|
|
86
|
+
content_type: z.string().min(1),
|
|
87
|
+
size_bytes: z.number().int().nonnegative().nullable().optional(),
|
|
88
|
+
sha256: z.string().nullable().optional(),
|
|
89
|
+
blocked: z.boolean().optional(),
|
|
90
|
+
blocked_reason: z.string().nullable().optional(),
|
|
91
|
+
quarantine_uri: z.string().nullable().optional(),
|
|
92
|
+
media_kind: zAttachmentMediaKindSchema,
|
|
93
|
+
caption: z.string().nullable().optional(),
|
|
94
|
+
})
|
|
95
|
+
.passthrough()
|
|
96
|
+
.superRefine((file, ctx) => {
|
|
97
|
+
if (file.blocked) {
|
|
98
|
+
if (!file.quarantine_uri) {
|
|
99
|
+
ctx.addIssue({
|
|
100
|
+
code: z.ZodIssueCode.custom,
|
|
101
|
+
path: ["quarantine_uri"],
|
|
102
|
+
message: "quarantine_uri is required when the file is blocked",
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
} else if (!file.gcs_uri) {
|
|
106
|
+
ctx.addIssue({
|
|
107
|
+
code: z.ZodIssueCode.custom,
|
|
108
|
+
path: ["gcs_uri"],
|
|
109
|
+
message: "gcs_uri is required unless the file is blocked",
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
export const zAttachmentAiSuggestionSchema = z
|
|
115
|
+
.object({
|
|
116
|
+
kind: z.string().min(1),
|
|
117
|
+
label: z.string().nullable().optional(),
|
|
118
|
+
summary: z.string(),
|
|
119
|
+
confidence: z.number().min(0).max(1),
|
|
120
|
+
prompt_version: z.string(),
|
|
121
|
+
suggested_base_category: zPatientAttachmentBaseCategorySchema.nullable(),
|
|
122
|
+
classified_at: z.coerce.date(),
|
|
123
|
+
})
|
|
124
|
+
.passthrough();
|
|
125
|
+
|
|
126
|
+
export const zAttachmentClassificationSchema = z
|
|
127
|
+
.object({
|
|
128
|
+
category: z.string().nullable().optional(),
|
|
129
|
+
base_category: zPatientAttachmentBaseCategorySchema.nullable().optional(),
|
|
130
|
+
category_color: z.string().nullable().optional(),
|
|
131
|
+
source: zAttachmentClassificationSourceSchema,
|
|
132
|
+
reviewed_by: zAttachmentActorSchema.nullable().optional(),
|
|
133
|
+
reviewed_at: z.coerce.date().nullable().optional(),
|
|
134
|
+
ai: zAttachmentAiSuggestionSchema.nullable().optional(),
|
|
135
|
+
})
|
|
136
|
+
.passthrough();
|
|
137
|
+
|
|
138
|
+
/** Link do anexo: o `type` precisa ser de `ATTACHMENT_SUBJECT_TYPES`. */
|
|
139
|
+
export const zAttachmentExternalLinkSchema = zExternalLinkSchema.refine(
|
|
140
|
+
(link) => isAttachmentSubjectType(link.type),
|
|
141
|
+
{ message: `externalLinks type must be one of ${ATTACHMENT_SUBJECT_TYPES.join(", ")}`, path: ["type"] },
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
export const zAttachmentPrimarySubjectSchema = z.object({
|
|
145
|
+
type: zAttachmentSubjectTypeSchema,
|
|
146
|
+
id: z.string().min(1),
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
export const zAttachmentLegacySchema = z
|
|
150
|
+
.object({
|
|
151
|
+
patient_id: z.string().min(1),
|
|
152
|
+
migrated_at: z.coerce.date(),
|
|
153
|
+
})
|
|
154
|
+
.passthrough();
|
|
155
|
+
|
|
156
|
+
export const zAttachmentSchema = zFireDocSchema
|
|
157
|
+
.extend({
|
|
158
|
+
externalLinks: z.array(zAttachmentExternalLinkSchema),
|
|
159
|
+
externalLinkKeys: z.array(z.string()),
|
|
160
|
+
primary_subject: zAttachmentPrimarySubjectSchema,
|
|
161
|
+
source: zAttachmentSourceSchema,
|
|
162
|
+
file: zAttachmentFileSchema,
|
|
163
|
+
classification: zAttachmentClassificationSchema,
|
|
164
|
+
tags: z.array(zTagSchema).nullable().optional(),
|
|
165
|
+
description: z.string().nullable().optional(),
|
|
166
|
+
legacy: zAttachmentLegacySchema.nullable().optional(),
|
|
167
|
+
created_by: zAttachmentActorSchema.nullable().optional(),
|
|
168
|
+
})
|
|
169
|
+
.passthrough();
|
|
170
|
+
|
|
171
|
+
// ───────── Evento de indexação (tópico app_evo-docs_attachments_index) ─────────
|
|
172
|
+
|
|
173
|
+
export const zAttachmentIndexEventSchema = z
|
|
174
|
+
.object({
|
|
175
|
+
tenant: z.string().min(1),
|
|
176
|
+
thread_id: z.string().min(1),
|
|
177
|
+
message_id: z.string().min(1),
|
|
178
|
+
direction: z.enum(["in", "out"]),
|
|
179
|
+
provider: z.string().min(1),
|
|
180
|
+
channel_id: z.string().min(1),
|
|
181
|
+
channel_type: z.string().min(1),
|
|
182
|
+
ticket_id: z.string().nullable().optional(),
|
|
183
|
+
department_id: z.string().nullable().optional(),
|
|
184
|
+
lead_id: z.string().nullable().optional(),
|
|
185
|
+
external_links: z.array(zExternalLinkSchema).nullable().optional(),
|
|
186
|
+
created_by: zAttachmentActorSchema.nullable().optional(),
|
|
187
|
+
occurred_at: z.coerce.date(),
|
|
188
|
+
trace_id: z.string().nullable().optional(),
|
|
189
|
+
reason: zAttachmentIndexReasonSchema.default(AttachmentIndexReasonEnum.Message),
|
|
190
|
+
})
|
|
191
|
+
.passthrough();
|
|
192
|
+
|
|
193
|
+
// ───────── API (hubomni_admin) ─────────
|
|
194
|
+
|
|
195
|
+
/** Query string booleana: aceita true/false, "1"/"0", "true"/"false". */
|
|
196
|
+
const zQueryBoolean = z.preprocess((v) => {
|
|
197
|
+
if (v === "1" || v === "true") return true;
|
|
198
|
+
if (v === "0" || v === "false") return false;
|
|
199
|
+
return v;
|
|
200
|
+
}, z.boolean());
|
|
201
|
+
|
|
202
|
+
const LIST_ROOT_TYPES: readonly string[] = ATTACHMENT_LIST_ROOT_TYPES;
|
|
203
|
+
const ATTACHMENT_PATCH_LINKS_MAX = 20;
|
|
204
|
+
|
|
205
|
+
export const zAttachmentListQuerySchema = z
|
|
206
|
+
.object({
|
|
207
|
+
subject: z
|
|
208
|
+
.string()
|
|
209
|
+
.refine(
|
|
210
|
+
(s) => {
|
|
211
|
+
const i = s.indexOf(":");
|
|
212
|
+
return i > 0 && i < s.length - 1 && LIST_ROOT_TYPES.indexOf(s.slice(0, i)) >= 0;
|
|
213
|
+
},
|
|
214
|
+
{ message: `subject must be "type:id" with type in ${ATTACHMENT_LIST_ROOT_TYPES.join(", ")}` },
|
|
215
|
+
)
|
|
216
|
+
.optional(),
|
|
217
|
+
/** Aceita array ou string separada por vírgula (query string). */
|
|
218
|
+
message_ids: z
|
|
219
|
+
.preprocess(
|
|
220
|
+
(v) =>
|
|
221
|
+
typeof v === "string"
|
|
222
|
+
? v
|
|
223
|
+
.split(",")
|
|
224
|
+
.map((s) => s.trim())
|
|
225
|
+
.filter((s) => s !== "")
|
|
226
|
+
: v,
|
|
227
|
+
z.array(z.string().min(1)).min(1).max(ATTACHMENT_LIST_MAX_MESSAGE_IDS),
|
|
228
|
+
)
|
|
229
|
+
.optional(),
|
|
230
|
+
family: zQueryBoolean.optional(),
|
|
231
|
+
/** Interno (Q5): não expor na tela nem no service do FE. */
|
|
232
|
+
family_depth: z.coerce.number().int().min(1).max(2).optional(),
|
|
233
|
+
patient: z.string().min(1).optional(),
|
|
234
|
+
direction: zAttachmentDirectionSchema.optional(),
|
|
235
|
+
base_category: zPatientAttachmentBaseCategorySchema.optional(),
|
|
236
|
+
blocked: zQueryBoolean.optional(),
|
|
237
|
+
media_kind: zAttachmentMediaKindSchema.optional(),
|
|
238
|
+
source_kind: zAttachmentSourceKindSchema.optional(),
|
|
239
|
+
tag: z.string().min(1).max(50).optional(),
|
|
240
|
+
limit: z.coerce.number().int().min(1).max(ATTACHMENT_LIST_MAX_LIMIT).optional(),
|
|
241
|
+
cursor: z.string().min(1).optional(),
|
|
242
|
+
})
|
|
243
|
+
.superRefine((q, ctx) => {
|
|
244
|
+
const hasSubject = q.subject !== undefined;
|
|
245
|
+
const hasMessageIds = q.message_ids !== undefined;
|
|
246
|
+
if (hasSubject === hasMessageIds) {
|
|
247
|
+
ctx.addIssue({
|
|
248
|
+
code: z.ZodIssueCode.custom,
|
|
249
|
+
path: ["subject"],
|
|
250
|
+
message: "exactly one of subject or message_ids is required",
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
if (hasMessageIds && q.family) {
|
|
254
|
+
ctx.addIssue({
|
|
255
|
+
code: z.ZodIssueCode.custom,
|
|
256
|
+
path: ["family"],
|
|
257
|
+
message: "family is not supported with message_ids",
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
if (hasMessageIds && q.cursor !== undefined) {
|
|
261
|
+
ctx.addIssue({
|
|
262
|
+
code: z.ZodIssueCode.custom,
|
|
263
|
+
path: ["cursor"],
|
|
264
|
+
message: "cursor is not supported with message_ids",
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
export const zAttachmentSubjectRefSchema = z
|
|
270
|
+
.object({
|
|
271
|
+
type: zAttachmentSubjectTypeSchema,
|
|
272
|
+
id: z.string().min(1),
|
|
273
|
+
label: z.string().optional(),
|
|
274
|
+
})
|
|
275
|
+
.strict();
|
|
276
|
+
|
|
277
|
+
export const zAttachmentPatchBodySchema = z
|
|
278
|
+
.object({
|
|
279
|
+
category: z.string().min(1).max(255).nullable().optional(),
|
|
280
|
+
base_category: zPatientAttachmentBaseCategorySchema.nullable().optional(),
|
|
281
|
+
category_color: z
|
|
282
|
+
.string()
|
|
283
|
+
.regex(/^#[0-9A-Fa-f]{6}$/)
|
|
284
|
+
.nullable()
|
|
285
|
+
.optional(),
|
|
286
|
+
description: z.string().max(ATTACHMENT_DESCRIPTION_MAX).nullable().optional(),
|
|
287
|
+
tags: z.array(zTagSchema).max(ATTACHMENT_TAGS_MAX).optional(),
|
|
288
|
+
add_links: z.array(zAttachmentSubjectRefSchema).max(ATTACHMENT_PATCH_LINKS_MAX).optional(),
|
|
289
|
+
remove_links: z.array(zAttachmentSubjectRefSchema).max(ATTACHMENT_PATCH_LINKS_MAX).optional(),
|
|
290
|
+
})
|
|
291
|
+
.strict()
|
|
292
|
+
.refine((b) => Object.keys(b).length > 0, { message: "empty patch body" });
|
|
293
|
+
|
|
294
|
+
export const zAttachmentReindexBodySchema = z
|
|
295
|
+
.object({
|
|
296
|
+
thread_id: z.string().min(1),
|
|
297
|
+
message_id: z.string().min(1).optional(),
|
|
298
|
+
})
|
|
299
|
+
.strict();
|