evo360-types 1.3.662 → 1.3.667

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.
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ // ── Nexus FinOps — reembolso da taxa de NFS-e (feat-264) ──
3
+ //
4
+ // A Asaas debita da subconta do cliente a taxa de cada NFS-e autorizada. O
5
+ // Nexus apura, por competência, quantas notas nossas foram autorizadas e
6
+ // devolve `count × fee` por transferência interna (walletId) a partir da conta
7
+ // master. Cada apuração vira um registro de controle do backend.
8
+ //
9
+ // Runtime `lib: es6`: as constantes abaixo são só dados.
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.NFSE_FEE_REIMBURSEMENT_IN_FLIGHT_STATES = exports.NFSE_FEE_REIMBURSEMENT_CONSUMING_STATES = exports.NFSE_FEE_REIMBURSEMENT_TRANSITIONS = exports.NFSE_FEE_REIMBURSEMENT_EXTERNAL_REF_PREFIX = exports.NEX_FINOPS_NFSE_FEE_REIMBURSEMENTS_COLLECTION = void 0;
12
+ /** Coleção dos registros de reembolso. */
13
+ exports.NEX_FINOPS_NFSE_FEE_REIMBURSEMENTS_COLLECTION = 'nfse_fee_reimbursements';
14
+ // path: core/nexus/apps/nex-finops/nfse_fee_reimbursements/{id}
15
+ /** `externalReference` da transferência Asaas = `"nexnfr:{id}"`. */
16
+ exports.NFSE_FEE_REIMBURSEMENT_EXTERNAL_REF_PREFIX = 'nexnfr:';
17
+ /**
18
+ * `failed`/`canceled`/`refused` -> `done` existe só para a REALIDADE do Asaas: um
19
+ * `TRANSFER_DONE` do `transfer_id` vinculado significa que o dinheiro saiu; o
20
+ * registro vira `done` (as notas passam a ser consumidas e nunca são pagas duas
21
+ * vezes) e gera alerta CRITICAL. Nenhum fluxo nosso faz essa transição.
22
+ */
23
+ exports.NFSE_FEE_REIMBURSEMENT_TRANSITIONS = {
24
+ awaiting_authorization: ['pending', 'failed', 'refused', 'canceled', 'done'],
25
+ pending: ['done', 'failed', 'canceled'],
26
+ done: [],
27
+ failed: ['done'],
28
+ canceled: ['done'],
29
+ refused: ['done'],
30
+ };
31
+ /** Estados que consomem as notas do snapshot (não podem ser reembolsadas de novo). */
32
+ exports.NFSE_FEE_REIMBURSEMENT_CONSUMING_STATES = ['awaiting_authorization', 'pending', 'done'];
33
+ /** Estados em voo: bloqueiam nova execução para o mesmo tenant/competência. */
34
+ exports.NFSE_FEE_REIMBURSEMENT_IN_FLIGHT_STATES = ['awaiting_authorization', 'pending'];
@@ -0,0 +1,143 @@
1
+ // ── Nexus FinOps — reembolso da taxa de NFS-e (feat-264) ──
2
+ //
3
+ // A Asaas debita da subconta do cliente a taxa de cada NFS-e autorizada. O
4
+ // Nexus apura, por competência, quantas notas nossas foram autorizadas e
5
+ // devolve `count × fee` por transferência interna (walletId) a partir da conta
6
+ // master. Cada apuração vira um registro de controle do backend.
7
+ //
8
+ // Runtime `lib: es6`: as constantes abaixo são só dados.
9
+
10
+ /** Coleção dos registros de reembolso. */
11
+ export const NEX_FINOPS_NFSE_FEE_REIMBURSEMENTS_COLLECTION = 'nfse_fee_reimbursements';
12
+ // path: core/nexus/apps/nex-finops/nfse_fee_reimbursements/{id}
13
+
14
+ /** `externalReference` da transferência Asaas = `"nexnfr:{id}"`. */
15
+ export const NFSE_FEE_REIMBURSEMENT_EXTERNAL_REF_PREFIX = 'nexnfr:';
16
+
17
+ export type NfseFeeReimbursementState =
18
+ | 'awaiting_authorization' // intenção gravada; POST /v3/transfers chamado ou a chamar; aguarda validação
19
+ | 'pending' // validação APROVADA por nós (ou Asaas confirmou PENDING com id vinculado)
20
+ | 'done' // TRANSFER_DONE
21
+ | 'failed' // POST rejeitado/erro de rede, ou TRANSFER_FAILED
22
+ | 'canceled' // TRANSFER_CANCELLED (inclui 3 falhas da validação)
23
+ | 'refused'; // nosso webhook recusou (divergência) — terminal
24
+
25
+ /**
26
+ * `failed`/`canceled`/`refused` -> `done` existe só para a REALIDADE do Asaas: um
27
+ * `TRANSFER_DONE` do `transfer_id` vinculado significa que o dinheiro saiu; o
28
+ * registro vira `done` (as notas passam a ser consumidas e nunca são pagas duas
29
+ * vezes) e gera alerta CRITICAL. Nenhum fluxo nosso faz essa transição.
30
+ */
31
+ export const NFSE_FEE_REIMBURSEMENT_TRANSITIONS: Record<NfseFeeReimbursementState, NfseFeeReimbursementState[]> = {
32
+ awaiting_authorization: ['pending', 'failed', 'refused', 'canceled', 'done'],
33
+ pending: ['done', 'failed', 'canceled'],
34
+ done: [],
35
+ failed: ['done'],
36
+ canceled: ['done'],
37
+ refused: ['done'],
38
+ };
39
+
40
+ /** Estados que consomem as notas do snapshot (não podem ser reembolsadas de novo). */
41
+ export const NFSE_FEE_REIMBURSEMENT_CONSUMING_STATES: readonly string[] = ['awaiting_authorization', 'pending', 'done'];
42
+
43
+ /** Estados em voo: bloqueiam nova execução para o mesmo tenant/competência. */
44
+ export const NFSE_FEE_REIMBURSEMENT_IN_FLIGHT_STATES: readonly string[] = ['awaiting_authorization', 'pending'];
45
+
46
+ /** De onde veio o `wallet_id` do destino (Adendo D1). */
47
+ export type NfseFeeReimbursementWalletSource = 'account_scope' | 'asaas_wallets_api';
48
+
49
+ /** D1: plugável. Só `asaas_internal_transfer` é implementado; `pix` fica para depois. */
50
+ export type NfseFeeReimbursementPayoutMethod = 'asaas_internal_transfer';
51
+
52
+ export interface INfseFeeReimbursement {
53
+ /** `{tenant}_{YYYY-MM}[_{seq}]` */
54
+ id: string;
55
+ tenant: string;
56
+ /** `"YYYY-MM"` (mês de `authorized_at` em America/Sao_Paulo). */
57
+ competencia: string;
58
+ /** 1, 2, … */
59
+ seq: number;
60
+ state: NfseFeeReimbursementState;
61
+ state_reason?: string | null;
62
+ provider: {
63
+ id: string;
64
+ /** Adendo D1: `asaas` = conta própria do tenant; `asaas_subaccount` = subconta da master. */
65
+ type: 'asaas' | 'asaas_subaccount';
66
+ env: 'production';
67
+ /** Só a subconta tem; conta própria => `null`. */
68
+ asaas_account_id?: string | null;
69
+ wallet_id: string;
70
+ /** `account_scope` (subconta, persistido) | `asaas_wallets_api` (conta própria, `GET /v3/wallets/` com a chave do tenant; só snapshot). */
71
+ wallet_source: NfseFeeReimbursementWalletSource;
72
+ };
73
+ /** Snapshot do que foi reembolsado. */
74
+ invoices: { count: number; ids: string[] };
75
+ fee: { value: number; source: 'asaas_myaccount_fees'; fetched_at: string };
76
+ /** `round2(count * fee.value)` */
77
+ amount: number;
78
+ currency: 'BRL';
79
+ contract: { customer_id: string | null; contract_ids: string[] };
80
+ payout: {
81
+ method: NfseFeeReimbursementPayoutMethod;
82
+ /** `"nexnfr:{id}"` */
83
+ external_reference: string;
84
+ /** Ex.: `"Reembolso taxa NFS-e 09/2026 - 10 notas"` */
85
+ description: string;
86
+ /** Id Asaas — vinculado SÓ pela resposta do nosso POST /v3/transfers/ (validação e eventos nunca vinculam). */
87
+ transfer_id?: string | null;
88
+ /** PENDING | BANK_PROCESSING | DONE | CANCELLED | FAILED | BLOCKED */
89
+ asaas_status?: string | null;
90
+ transfer_fee?: number | null;
91
+ effective_date?: string | null;
92
+ fail_reason?: string | null;
93
+ };
94
+ validation: {
95
+ decision: 'APPROVED' | 'REFUSED' | null;
96
+ decided_at?: string | null;
97
+ attempts: number;
98
+ last_reason?: string | null;
99
+ };
100
+ last_event?: string | null;
101
+ last_event_at?: string | null;
102
+ requested_by: {
103
+ login_id: string;
104
+ email?: string | null;
105
+ second_factor: 'totp';
106
+ auth_time: string;
107
+ };
108
+ created_at: string;
109
+ updated_at: string;
110
+ done_at?: string | null;
111
+ }
112
+
113
+ export type NfseFeeReimbursementEligibility =
114
+ | 'eligible'
115
+ | 'nothing_to_reimburse'
116
+ | 'in_flight'
117
+ | 'open_competencia'
118
+ | 'not_eligible_contract_flag'
119
+ | 'no_contract'
120
+ | 'subaccount_not_ready' // subconta ativa sem account_scope.wallet_id
121
+ | 'wallet_unavailable' // conta própria: GET /v3/wallets/ com 0, >1 wallets ou erro
122
+ | 'ambiguous_provider' // mais de 1 provider Asaas ativo (asaas/asaas_subaccount) em production
123
+ | 'fee_unavailable'; // GET /v3/myAccount/fees falhou ou sem invoice.feeValue
124
+
125
+ export interface INfseFeeReimbursementPreviewRow {
126
+ tenant: string;
127
+ tenant_name?: string | null;
128
+ competencia: string;
129
+ eligibility: NfseFeeReimbursementEligibility;
130
+ reason?: string | null;
131
+ provider_id?: string | null;
132
+ provider_type?: string | null;
133
+ wallet_id?: string | null;
134
+ wallet_source?: NfseFeeReimbursementWalletSource | null;
135
+ /** Autorizadas na competência, do provider. */
136
+ invoice_count_total: number;
137
+ invoice_count_already_reimbursed: number;
138
+ invoice_count_to_reimburse: number;
139
+ fee_value: number | null;
140
+ amount: number | null;
141
+ next_record_id?: string | null;
142
+ records: Array<Pick<INfseFeeReimbursement, 'id' | 'state' | 'amount' | 'seq'> & { invoice_count: number }>;
143
+ }
@@ -5,6 +5,7 @@ export * from "./common/contract";
5
5
  export * from "./common/proposal";
6
6
  export * from "./common/billing";
7
7
  export * from "./common/payment-method";
8
+ export * from "./common/nfse-fee-reimbursement";
8
9
  export * from "./providers";
9
10
  export * from "./providers/provider_fiscal_types";
10
11
  export * from "./providers/asaas/asaas_provider";
@@ -22,6 +22,7 @@ __exportStar(require("./common/contract"), exports);
22
22
  __exportStar(require("./common/proposal"), exports);
23
23
  __exportStar(require("./common/billing"), exports);
24
24
  __exportStar(require("./common/payment-method"), exports);
25
+ __exportStar(require("./common/nfse-fee-reimbursement"), exports);
25
26
  __exportStar(require("./providers"), exports);
26
27
  __exportStar(require("./providers/provider_fiscal_types"), exports);
27
28
  __exportStar(require("./providers/asaas/asaas_provider"), exports);
@@ -7,6 +7,7 @@ export * from "./common/contract";
7
7
  export * from "./common/proposal";
8
8
  export * from "./common/billing";
9
9
  export * from "./common/payment-method";
10
+ export * from "./common/nfse-fee-reimbursement";
10
11
  export * from "./providers";
11
12
  export * from "./providers/provider_fiscal_types";
12
13
  export * from "./providers/asaas/asaas_provider";
@@ -39,6 +39,8 @@ export interface IAddress {
39
39
  name?: string;
40
40
  kind?: string;
41
41
  line1?: string;
42
+ /** Número do logradouro. */
43
+ number?: string;
42
44
  line2?: string;
43
45
  neighborhood?: string;
44
46
  city?: string;
@@ -51,6 +51,8 @@ export interface IAddress {
51
51
  name?: string;
52
52
  kind?: string;
53
53
  line1?: string;
54
+ /** Número do logradouro. */
55
+ number?: string;
54
56
  line2?: string;
55
57
  neighborhood?: string;
56
58
  city?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evo360-types",
3
- "version": "1.3.662",
3
+ "version": "1.3.667",
4
4
  "description": "HREVO360 Shared Types",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",