evo360-types 1.3.780 → 1.3.784
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-chat/thread-message/zod-schemas.d.ts +36 -0
- package/dist/apps/evo-chat/thread-message/zod-schemas.js +3 -0
- package/dist/apps/evo-chat/thread-message/zod-schemas.ts +3 -0
- package/dist/apps/evo-chat/waba-template/zod-schemas.d.ts +70 -0
- package/dist/apps/evo-chat/waba-template/zod-schemas.js +6 -2
- package/dist/apps/evo-chat/waba-template/zod-schemas.ts +6 -1
- package/dist/apps/evo-finops/zod-schemas.d.ts +329 -2
- package/dist/apps/evo-finops/zod-schemas.js +66 -2
- package/dist/apps/evo-finops/zod-schemas.ts +74 -0
- package/dist/apps/evo-hub-ia/v1/zod-schemas.d.ts +4 -4
- package/dist/types/evo-chat/thread-message/index.d.ts +8 -0
- package/dist/types/evo-chat/thread-message/index.ts +8 -0
- package/dist/types/evo-finops/common/contract.d.ts +21 -1
- package/dist/types/evo-finops/common/contract.js +7 -0
- package/dist/types/evo-finops/common/contract.ts +23 -1
- package/dist/types/evo-finops/common/price-table.d.ts +89 -0
- package/dist/types/evo-finops/common/price-table.js +88 -0
- package/dist/types/evo-finops/common/price-table.ts +183 -0
- package/dist/types/evo-finops/index.d.ts +1 -0
- package/dist/types/evo-finops/index.js +1 -0
- package/dist/types/evo-finops/index.ts +1 -0
- package/dist/types/evo-reports/index.d.ts +9 -0
- package/dist/types/evo-reports/index.ts +9 -0
- package/dist/types/shared/template-profile.d.ts +23 -1
- package/dist/types/shared/template-profile.js +11 -0
- package/dist/types/shared/template-profile.ts +26 -1
- package/package.json +1 -1
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import type { IFireGlobalDoc } from '../../shared';
|
|
2
|
+
|
|
3
|
+
// ── Tabelas de preço (feat-328) ──
|
|
4
|
+
//
|
|
5
|
+
// A tabela de preço diz QUANTO custa cada métrica/módulo. Ela **só tem preço**:
|
|
6
|
+
// o que foi vendido (franquias, pacote comercial) vive na Oferta/contrato
|
|
7
|
+
// (decisão Q1). Contrato aponta para uma tabela via `price_table_id`
|
|
8
|
+
// (ausente = tabela padrão).
|
|
9
|
+
//
|
|
10
|
+
// Herança é **por linha**: uma tabela filha declara só as chaves que muda.
|
|
11
|
+
// - chave ausente na filha ⇒ herda da mãe (e assim por diante até a padrão);
|
|
12
|
+
// - chave com linha própria ⇒ sobrescreve a herdada;
|
|
13
|
+
// - chave com `kind: 'disabled'` ⇒ ANULA a herdada (a métrica deixa de ser cobrada).
|
|
14
|
+
//
|
|
15
|
+
// Para "voltar a herdar", remove-se a linha própria — nunca se grava `null`.
|
|
16
|
+
|
|
17
|
+
/** Coleção das tabelas: `core/nexus/apps/nex-finops/price_tables/{id}`. */
|
|
18
|
+
export const NEX_FINOPS_PRICE_TABLES_COLLECTION = 'price_tables';
|
|
19
|
+
|
|
20
|
+
/** Teto por faixas sobre o total da métrica (Q2): até `up_to` unidades, o total é `total`. */
|
|
21
|
+
export interface INexFinopsPriceCapTier {
|
|
22
|
+
/** Limite superior (inclusivo) de unidades da faixa. Inteiro > 0, estritamente crescente entre faixas. */
|
|
23
|
+
up_to: number;
|
|
24
|
+
/** Valor total (BRL) cobrado quando o consumo cai nesta faixa. */
|
|
25
|
+
total: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface INexFinopsPriceCap {
|
|
29
|
+
mode: 'tiered_total';
|
|
30
|
+
tiers: INexFinopsPriceCapTier[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Linha de uso: cobra `unit_price` por unidade consumida (opcionalmente com teto por faixas). */
|
|
34
|
+
export interface INexFinopsPriceLineUsage {
|
|
35
|
+
kind: 'usage';
|
|
36
|
+
/** Preço unitário (BRL). */
|
|
37
|
+
unit_price: number;
|
|
38
|
+
/** Categoria de `billing_services` (SSR, SMS, TELE, TELEGRV, …): vira item de cobrança e código de serviço da NFS-e. */
|
|
39
|
+
service_category: string;
|
|
40
|
+
cap?: INexFinopsPriceCap | null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Linha recorrente: valor fixo por ciclo (ex.: módulo ativo no fechamento). */
|
|
44
|
+
export interface INexFinopsPriceLineRecurring {
|
|
45
|
+
kind: 'recurring';
|
|
46
|
+
/** Valor por ciclo (BRL). */
|
|
47
|
+
amount: number;
|
|
48
|
+
/** Categoria de `billing_services`. */
|
|
49
|
+
service_category: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Anula a linha herdada: a chave passa a não ser cobrada nesta tabela (e nas
|
|
54
|
+
* filhas dela, salvo se alguma filha redeclarar). Conta como "declarada" na
|
|
55
|
+
* resolução — interrompe a busca na cadeia.
|
|
56
|
+
*/
|
|
57
|
+
export interface INexFinopsPriceLineDisabled {
|
|
58
|
+
kind: 'disabled';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Linha de preço, discriminada por `kind`. Chave do mapa = métrica (usage) ou módulo (recurring). */
|
|
62
|
+
export type INexFinopsPriceLine =
|
|
63
|
+
| INexFinopsPriceLineUsage
|
|
64
|
+
| INexFinopsPriceLineRecurring
|
|
65
|
+
| INexFinopsPriceLineDisabled;
|
|
66
|
+
|
|
67
|
+
export type NexFinopsPriceLineKind = INexFinopsPriceLine['kind'];
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Tabela de preço. Exatamente uma tem `is_default: true` — e é a única sem mãe.
|
|
71
|
+
* Toda outra tem `inherits_from` apontando para uma tabela viva, sem ciclo
|
|
72
|
+
* (validação na escrita, backend).
|
|
73
|
+
*/
|
|
74
|
+
export interface INexFinopsPriceTable extends IFireGlobalDoc {
|
|
75
|
+
name: string;
|
|
76
|
+
is_default: boolean;
|
|
77
|
+
/** Id da tabela mãe. Obrigatório quando `!is_default`; ausente/null na padrão. */
|
|
78
|
+
inherits_from?: string | null;
|
|
79
|
+
/** Linhas PRÓPRIAS desta tabela (não as herdadas). Chave ausente = herda. */
|
|
80
|
+
lines: Record<string, INexFinopsPriceLine>;
|
|
81
|
+
notes?: string | null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Linha efetiva após a resolução, com a tabela que a declarou (origem exibida no Nexus). */
|
|
85
|
+
export interface ResolvedPriceLine {
|
|
86
|
+
line: INexFinopsPriceLine;
|
|
87
|
+
/** Id da tabela da cadeia que declarou a chave. */
|
|
88
|
+
from_table: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface ResolvedPriceTable {
|
|
92
|
+
/** Ids percorridos, da tabela pedida até a padrão (inclusive). */
|
|
93
|
+
chain: string[];
|
|
94
|
+
/** Linhas efetivas por chave. Inclui `disabled` (o consumidor decide como exibir/ignorar). */
|
|
95
|
+
lines: Record<string, ResolvedPriceLine>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export type PriceTableResolveErrorCode = 'no_default' | 'missing_table' | 'missing_parent' | 'cycle';
|
|
99
|
+
|
|
100
|
+
/** Erro tipado do resolvedor. `table_id` = tabela onde o problema foi detectado (quando houver). */
|
|
101
|
+
export class PriceTableResolveError extends Error {
|
|
102
|
+
readonly code: PriceTableResolveErrorCode;
|
|
103
|
+
readonly table_id: string | null;
|
|
104
|
+
|
|
105
|
+
constructor(code: PriceTableResolveErrorCode, message: string, tableId: string | null = null) {
|
|
106
|
+
super(message);
|
|
107
|
+
this.name = 'PriceTableResolveError';
|
|
108
|
+
this.code = code;
|
|
109
|
+
this.table_id = tableId;
|
|
110
|
+
Object.setPrototypeOf(this, PriceTableResolveError.prototype);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Resolvedor PURO da cadeia de herança — o mesmo no backend e no Nexus (front),
|
|
116
|
+
* para a origem por linha mostrada na tela bater com o que o motor cobra.
|
|
117
|
+
*
|
|
118
|
+
* - `tableId` ausente/null ⇒ parte da tabela com `is_default` (erro `no_default` se não houver).
|
|
119
|
+
* - Caminha filha → `inherits_from` → … até a tabela sem mãe; a PRIMEIRA tabela da
|
|
120
|
+
* cadeia que DECLARA a chave vence (`disabled` também declara).
|
|
121
|
+
* - Erros: `missing_table` (o `tableId` pedido não existe), `missing_parent`
|
|
122
|
+
* (`inherits_from` aponta para id inexistente), `cycle` (a cadeia revisita uma tabela).
|
|
123
|
+
*
|
|
124
|
+
* Exemplo: padrão `{a: usage 1, b: usage 2}` ← filha `{b: disabled, c: usage 3}`
|
|
125
|
+
* resolve a filha em `{a ← padrão, b: disabled ← filha, c ← filha}`, chain `[filha, padrão]`.
|
|
126
|
+
*/
|
|
127
|
+
export function resolvePriceTableLines(
|
|
128
|
+
tables: Record<string, INexFinopsPriceTable>,
|
|
129
|
+
tableId: string | null | undefined,
|
|
130
|
+
): ResolvedPriceTable {
|
|
131
|
+
let startId: string;
|
|
132
|
+
if (tableId) {
|
|
133
|
+
if (!Object.prototype.hasOwnProperty.call(tables, tableId)) {
|
|
134
|
+
throw new PriceTableResolveError('missing_table', `price table "${tableId}" not found`, tableId);
|
|
135
|
+
}
|
|
136
|
+
startId = tableId;
|
|
137
|
+
} else {
|
|
138
|
+
const defaultId = Object.keys(tables).find((id) => tables[id]?.is_default === true);
|
|
139
|
+
if (!defaultId) {
|
|
140
|
+
throw new PriceTableResolveError('no_default', 'no default price table');
|
|
141
|
+
}
|
|
142
|
+
startId = defaultId;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const chain: string[] = [];
|
|
146
|
+
const lines: Record<string, ResolvedPriceLine> = {};
|
|
147
|
+
const seen = new Set<string>();
|
|
148
|
+
let currentId: string | null = startId;
|
|
149
|
+
|
|
150
|
+
while (currentId) {
|
|
151
|
+
if (seen.has(currentId)) {
|
|
152
|
+
throw new PriceTableResolveError(
|
|
153
|
+
'cycle',
|
|
154
|
+
`price table inheritance cycle: ${[...chain, currentId].join(' -> ')}`,
|
|
155
|
+
currentId,
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
seen.add(currentId);
|
|
159
|
+
chain.push(currentId);
|
|
160
|
+
|
|
161
|
+
const table: INexFinopsPriceTable = tables[currentId];
|
|
162
|
+
const ownLines: Record<string, INexFinopsPriceLine> = table.lines ?? {};
|
|
163
|
+
for (const key of Object.keys(ownLines)) {
|
|
164
|
+
const line = ownLines[key];
|
|
165
|
+
if (!line) continue;
|
|
166
|
+
if (!Object.prototype.hasOwnProperty.call(lines, key)) {
|
|
167
|
+
lines[key] = { line, from_table: currentId };
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const parentId: string | null = table.inherits_from ?? null;
|
|
172
|
+
if (parentId && !Object.prototype.hasOwnProperty.call(tables, parentId)) {
|
|
173
|
+
throw new PriceTableResolveError(
|
|
174
|
+
'missing_parent',
|
|
175
|
+
`price table "${currentId}" inherits from missing table "${parentId}"`,
|
|
176
|
+
currentId,
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
currentId = parentId;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return { chain, lines };
|
|
183
|
+
}
|
|
@@ -2,6 +2,7 @@ export * from "./fb_collections";
|
|
|
2
2
|
export * from "./common";
|
|
3
3
|
export * from "./common/taker";
|
|
4
4
|
export * from "./common/contract";
|
|
5
|
+
export * from "./common/price-table";
|
|
5
6
|
export * from "./common/proposal";
|
|
6
7
|
export * from "./common/billing";
|
|
7
8
|
export * from "./common/payment-method";
|
|
@@ -19,6 +19,7 @@ __exportStar(require("./fb_collections"), exports);
|
|
|
19
19
|
__exportStar(require("./common"), exports);
|
|
20
20
|
__exportStar(require("./common/taker"), exports);
|
|
21
21
|
__exportStar(require("./common/contract"), exports);
|
|
22
|
+
__exportStar(require("./common/price-table"), exports);
|
|
22
23
|
__exportStar(require("./common/proposal"), exports);
|
|
23
24
|
__exportStar(require("./common/billing"), exports);
|
|
24
25
|
__exportStar(require("./common/payment-method"), exports);
|
|
@@ -4,6 +4,7 @@ export * from "./fb_collections";
|
|
|
4
4
|
export * from "./common";
|
|
5
5
|
export * from "./common/taker";
|
|
6
6
|
export * from "./common/contract";
|
|
7
|
+
export * from "./common/price-table";
|
|
7
8
|
export * from "./common/proposal";
|
|
8
9
|
export * from "./common/billing";
|
|
9
10
|
export * from "./common/payment-method";
|
|
@@ -61,6 +61,15 @@ export interface IUsageDepartmentRow {
|
|
|
61
61
|
export interface IUsageContacts {
|
|
62
62
|
/** Contatos únicos no tenant no mês (dedup por pessoa, tenant-wide). */
|
|
63
63
|
atendidos: number;
|
|
64
|
+
/**
|
|
65
|
+
* feat-328 — dos `atendidos`, os que tiveram >=1 mensagem de SAÍDA humana no
|
|
66
|
+
* mês (inclui resposta pelo aparelho na coexistência — eco do WhatsApp
|
|
67
|
+
* Business App). Invariante: `atendidos = atendidos_humano + atendidos_ia`.
|
|
68
|
+
*/
|
|
69
|
+
atendidos_humano?: number;
|
|
70
|
+
/** feat-328 — complemento de `atendidos_humano`: atendidos só pela IA/automação no mês.
|
|
71
|
+
* Opcionais até a F3 preencher (a versão publicada não pode quebrar o build do `main`). */
|
|
72
|
+
atendidos_ia?: number;
|
|
64
73
|
/** Contatos únicos ativados no tenant no mês. */
|
|
65
74
|
ativados: number;
|
|
66
75
|
/**
|
|
@@ -79,6 +79,15 @@ export interface IUsageDepartmentRow {
|
|
|
79
79
|
export interface IUsageContacts {
|
|
80
80
|
/** Contatos únicos no tenant no mês (dedup por pessoa, tenant-wide). */
|
|
81
81
|
atendidos: number;
|
|
82
|
+
/**
|
|
83
|
+
* feat-328 — dos `atendidos`, os que tiveram >=1 mensagem de SAÍDA humana no
|
|
84
|
+
* mês (inclui resposta pelo aparelho na coexistência — eco do WhatsApp
|
|
85
|
+
* Business App). Invariante: `atendidos = atendidos_humano + atendidos_ia`.
|
|
86
|
+
*/
|
|
87
|
+
atendidos_humano?: number;
|
|
88
|
+
/** feat-328 — complemento de `atendidos_humano`: atendidos só pela IA/automação no mês.
|
|
89
|
+
* Opcionais até a F3 preencher (a versão publicada não pode quebrar o build do `main`). */
|
|
90
|
+
atendidos_ia?: number;
|
|
82
91
|
/** Contatos únicos ativados no tenant no mês. */
|
|
83
92
|
ativados: number;
|
|
84
93
|
/**
|
|
@@ -32,10 +32,32 @@ export type ITemplateProfile = ITemplateProfileFields & ITemplateProfileAudit;
|
|
|
32
32
|
* `tenants/{t}/apps/evo-chat/channels/{ch}/template_profiles/{name}__{language}`
|
|
33
33
|
*/
|
|
34
34
|
export declare const TEMPLATE_PROFILES_COLLECTION = "template_profiles";
|
|
35
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Campos editáveis do perfil do HSM: os quatro comuns + `enabled` (F1.1, D8).
|
|
37
|
+
* Mesma nomenclatura do "Habilitado" do template de e-mail. Desativação LÓGICA,
|
|
38
|
+
* só nossa: `enabled === false` tira o template dos seletores (web-app, Nexus,
|
|
39
|
+
* app Professional); na Meta nada muda e quem já o tem configurado continua
|
|
40
|
+
* enviando (D9). Ausente = habilitado.
|
|
41
|
+
*/
|
|
42
|
+
export interface IWabaTemplateProfileFields extends ITemplateProfileFields {
|
|
43
|
+
enabled?: boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface IWabaTemplateProfile extends ITemplateProfile, IWabaTemplateProfileFields {
|
|
36
46
|
/** `{name}__{language}` — igual ao doc id. */
|
|
37
47
|
id: string;
|
|
38
48
|
name: string;
|
|
39
49
|
language: string;
|
|
40
50
|
created_at?: Date | null;
|
|
41
51
|
}
|
|
52
|
+
/** HSM aparece nos seletores? Sem perfil ou sem `enabled` = sim (D8). */
|
|
53
|
+
export declare function isWabaTemplateProfileEnabled(profile?: {
|
|
54
|
+
enabled?: boolean;
|
|
55
|
+
} | null): boolean;
|
|
56
|
+
/** Ordem dos seletores (D10): nome, depois idioma — sem diferenciar maiúsculas/acentos. */
|
|
57
|
+
export declare function compareTemplatesByName(a: {
|
|
58
|
+
name?: string | null;
|
|
59
|
+
language?: string | null;
|
|
60
|
+
}, b: {
|
|
61
|
+
name?: string | null;
|
|
62
|
+
language?: string | null;
|
|
63
|
+
}): number;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TEMPLATE_PROFILES_COLLECTION = exports.TEMPLATE_PROFILE_TAGS_MAX = exports.TEMPLATE_PROFILE_MCP_DESCRIPTION_MAX = exports.TEMPLATE_PROFILE_DESCRIPTION_MAX = void 0;
|
|
4
|
+
exports.isWabaTemplateProfileEnabled = isWabaTemplateProfileEnabled;
|
|
5
|
+
exports.compareTemplatesByName = compareTemplatesByName;
|
|
4
6
|
// ----- Perfil de template (descrição, orientação para IA, tags) — feat-327
|
|
5
7
|
//
|
|
6
8
|
// Os mesmos quatro campos valem para templates HSM (WABA) e de e-mail (D4):
|
|
@@ -23,3 +25,12 @@ exports.TEMPLATE_PROFILE_TAGS_MAX = 20;
|
|
|
23
25
|
* `tenants/{t}/apps/evo-chat/channels/{ch}/template_profiles/{name}__{language}`
|
|
24
26
|
*/
|
|
25
27
|
exports.TEMPLATE_PROFILES_COLLECTION = "template_profiles";
|
|
28
|
+
/** HSM aparece nos seletores? Sem perfil ou sem `enabled` = sim (D8). */
|
|
29
|
+
function isWabaTemplateProfileEnabled(profile) {
|
|
30
|
+
return profile?.enabled !== false;
|
|
31
|
+
}
|
|
32
|
+
/** Ordem dos seletores (D10): nome, depois idioma — sem diferenciar maiúsculas/acentos. */
|
|
33
|
+
function compareTemplatesByName(a, b) {
|
|
34
|
+
const byName = (a.name ?? "").localeCompare(b.name ?? "", "pt-BR", { sensitivity: "base" });
|
|
35
|
+
return byName !== 0 ? byName : (a.language ?? "").localeCompare(b.language ?? "", "pt-BR", { sensitivity: "base" });
|
|
36
|
+
}
|
|
@@ -48,10 +48,35 @@ export type ITemplateProfile = ITemplateProfileFields & ITemplateProfileAudit;
|
|
|
48
48
|
*/
|
|
49
49
|
export const TEMPLATE_PROFILES_COLLECTION = "template_profiles";
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Campos editáveis do perfil do HSM: os quatro comuns + `enabled` (F1.1, D8).
|
|
53
|
+
* Mesma nomenclatura do "Habilitado" do template de e-mail. Desativação LÓGICA,
|
|
54
|
+
* só nossa: `enabled === false` tira o template dos seletores (web-app, Nexus,
|
|
55
|
+
* app Professional); na Meta nada muda e quem já o tem configurado continua
|
|
56
|
+
* enviando (D9). Ausente = habilitado.
|
|
57
|
+
*/
|
|
58
|
+
export interface IWabaTemplateProfileFields extends ITemplateProfileFields {
|
|
59
|
+
enabled?: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface IWabaTemplateProfile extends ITemplateProfile, IWabaTemplateProfileFields {
|
|
52
63
|
/** `{name}__{language}` — igual ao doc id. */
|
|
53
64
|
id: string;
|
|
54
65
|
name: string;
|
|
55
66
|
language: string;
|
|
56
67
|
created_at?: Date | null;
|
|
57
68
|
}
|
|
69
|
+
|
|
70
|
+
/** HSM aparece nos seletores? Sem perfil ou sem `enabled` = sim (D8). */
|
|
71
|
+
export function isWabaTemplateProfileEnabled(profile?: { enabled?: boolean } | null): boolean {
|
|
72
|
+
return profile?.enabled !== false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Ordem dos seletores (D10): nome, depois idioma — sem diferenciar maiúsculas/acentos. */
|
|
76
|
+
export function compareTemplatesByName(
|
|
77
|
+
a: { name?: string | null; language?: string | null },
|
|
78
|
+
b: { name?: string | null; language?: string | null },
|
|
79
|
+
): number {
|
|
80
|
+
const byName = (a.name ?? "").localeCompare(b.name ?? "", "pt-BR", { sensitivity: "base" });
|
|
81
|
+
return byName !== 0 ? byName : (a.language ?? "").localeCompare(b.language ?? "", "pt-BR", { sensitivity: "base" });
|
|
82
|
+
}
|