@noeva/etl-core 1.0.0-next.3 → 1.0.0-next.5
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/README.md +7 -11
- package/deploy/deploy-ecr.sh +4 -7
- package/dist/chunk-BVUOUBLW.js +1 -0
- package/dist/chunk-CRR3Q2C7.js +2 -0
- package/dist/chunk-J3PBMWSP.js +2 -0
- package/dist/{chunk-KMUNED7K.js → chunk-LJ7DVP5F.js} +1 -1
- package/dist/{chunk-ZBKP2UOF.js → chunk-P6B2KLNJ.js} +2 -2
- package/dist/chunk-PKBSETMV.js +2 -0
- package/dist/chunk-QPJC4GWR.js +1 -0
- package/dist/chunk-RCRMQPFH.js +5 -0
- package/dist/chunk-RS5SGDUU.js +1 -0
- package/dist/chunk-RWPHH4E2.js +1 -0
- package/dist/chunk-SRFFKE5W.js +6 -0
- package/dist/chunk-WVODQB6Z.js +1 -0
- package/dist/chunk-XZMCC6VQ.js +1 -0
- package/dist/chunk-ZCYGHS7P.js +2 -0
- package/dist/cli.js +3 -3
- package/dist/connector-kit.d.ts +4 -2
- package/dist/connector-kit.js +1 -1
- package/dist/connectors/file.js +1 -1
- package/dist/connectors/http.js +1 -1
- package/dist/connectors/imap.js +1 -1
- package/dist/connectors/jira.js +2 -2
- package/dist/connectors/mail.js +1 -1
- package/dist/connectors/noeva.js +1 -1
- package/dist/connectors/oauth.js +1 -1
- package/dist/connectors/postgres.js +1 -1
- package/dist/connectors/process.js +1 -1
- package/dist/connectors/sendgrid.d.ts +1 -1
- package/dist/connectors/sendgrid.js +1 -1
- package/dist/connectors/smtp.js +1 -1
- package/dist/connectors/sqlserver.js +1 -1
- package/dist/connectors/zoho.d.ts +304 -0
- package/dist/connectors/zoho.js +2 -0
- package/dist/etl.config.js +7 -15
- package/dist/guida/404.html +2 -2
- package/dist/guida/GUIDA_SVILUPPO.html +6 -6
- package/dist/guida/TECHNICAL_OVERVIEW.html +5 -5
- package/dist/guida/assets/{GUIDA_SVILUPPO.md.D13C7Zwu.js → GUIDA_SVILUPPO.md.CrN52ZDN.js} +1 -1
- package/dist/guida/assets/{TECHNICAL_OVERVIEW.md.DQP0pWc8.js → TECHNICAL_OVERVIEW.md.iD1gDlJY.js} +1 -1
- package/dist/guida/assets/{app.lWZ5GK2m.js → app.BrI3mcoI.js} +1 -1
- package/dist/guida/assets/chunks/@localSearchIndexroot.DjrQYH6x.js +1 -0
- package/dist/guida/assets/chunks/{VPLocalSearchBox.C0h2R-Ih.js → VPLocalSearchBox.BlKLVNlB.js} +1 -1
- package/dist/guida/assets/chunks/{theme.BYWumH0G.js → theme.Cuah39Zj.js} +2 -2
- package/dist/guida/assets/connectors_README.md.BqI2RLCu.js +1 -0
- package/dist/guida/assets/connectors_README.md.BqI2RLCu.lean.js +1 -0
- package/dist/guida/assets/connectors_oauth.md.BeotXAWb.js +7 -0
- package/dist/guida/assets/connectors_oauth.md.BeotXAWb.lean.js +1 -0
- package/dist/guida/assets/connectors_zoho.md.BfEzRNZk.js +17 -0
- package/dist/guida/assets/connectors_zoho.md.BfEzRNZk.lean.js +1 -0
- package/dist/guida/assets/{conventions_node-descriptor.md.D8Si7E2S.js → conventions_node-descriptor.md.MQaGlm8a.js} +1 -1
- package/dist/guida/assets/{nodes_source.md.V_vlNfOz.js → nodes_source.md.DP2i3GFv.js} +3 -3
- package/dist/guida/assets/{nodes_source.md.V_vlNfOz.lean.js → nodes_source.md.DP2i3GFv.lean.js} +1 -1
- package/dist/guida/assets/{runbooks_deploy-ecr.md.6M67F85S.js → runbooks_deploy-ecr.md.4jQypInn.js} +2 -2
- package/dist/guida/assets/{runbooks_deploy-ecr.md.6M67F85S.lean.js → runbooks_deploy-ecr.md.4jQypInn.lean.js} +1 -1
- package/dist/guida/connectors/README.html +5 -5
- package/dist/guida/connectors/file.html +4 -4
- package/dist/guida/connectors/http.html +4 -4
- package/dist/guida/connectors/imap.html +4 -4
- package/dist/guida/connectors/jira.html +4 -4
- package/dist/guida/connectors/noeva.html +5 -5
- package/dist/guida/connectors/oauth.html +6 -6
- package/dist/guida/connectors/postgres.html +5 -5
- package/dist/guida/connectors/process.html +4 -4
- package/dist/guida/connectors/sendgrid.html +4 -4
- package/dist/guida/connectors/smtp.html +4 -4
- package/dist/guida/connectors/sqlserver.html +5 -5
- package/dist/guida/connectors/zoho.html +43 -0
- package/dist/guida/conventions/node-columns.html +4 -4
- package/dist/guida/conventions/node-descriptor.html +6 -6
- package/dist/guida/conventions/run-report.html +4 -4
- package/dist/guida/conventions/run-trace.html +4 -4
- package/dist/guida/conventions/variabili-del-core.html +4 -4
- package/dist/guida/conventions/versioni-di-pipeline.html +4 -4
- package/dist/guida/guide/claude-code/index.html +4 -4
- package/dist/guida/guide/claude-code/prompt.html +5 -5
- package/dist/guida/guide/claude-code/strumenti.html +4 -4
- package/dist/guida/guide/grafo.html +4 -4
- package/dist/guida/guide/usare/app-desktop.html +4 -4
- package/dist/guida/guide/usare/esito-di-una-run.html +4 -4
- package/dist/guida/guide/usare/index.html +4 -4
- package/dist/guida/hashmap.json +1 -1
- package/dist/guida/index.html +4 -4
- package/dist/guida/nodes/README.html +4 -4
- package/dist/guida/nodes/action.html +4 -4
- package/dist/guida/nodes/ai.html +4 -4
- package/dist/guida/nodes/join.html +4 -4
- package/dist/guida/nodes/lookup.html +4 -4
- package/dist/guida/nodes/pipeline.html +4 -4
- package/dist/guida/nodes/route.html +4 -4
- package/dist/guida/nodes/sink.html +4 -4
- package/dist/guida/nodes/source.html +6 -6
- package/dist/guida/nodes/task.html +4 -4
- package/dist/guida/nodes/transform.html +4 -4
- package/dist/guida/nodes/try-catch.html +4 -4
- package/dist/guida/nodes/union.html +4 -4
- package/dist/guida/pagine.json +1 -0
- package/dist/guida/pipelines/README.html +5 -5
- package/dist/guida/pipelines/crm-leads-sync.html +4 -4
- package/dist/guida/pipelines/cross-workspace-csv-merge.html +4 -4
- package/dist/guida/pipelines/movimenti-per-conto.html +4 -4
- package/dist/guida/pipelines/orders-enriched-daily.html +4 -4
- package/dist/guida/pipelines/test-posta.html +4 -4
- package/dist/guida/runbooks/aggiornamento-pm2.html +4 -4
- package/dist/guida/runbooks/deploy-ecr.html +6 -6
- package/dist/guida/runbooks/deployment.html +4 -4
- package/dist/guida/runbooks/etl-worker.html +4 -4
- package/dist/guida/runbooks/graph-server.html +4 -4
- package/dist/guida/runbooks/mask-key.html +4 -4
- package/dist/guida/runbooks/oauth-google-posta.html +4 -4
- package/dist/guida/runbooks/rollback-di-pipeline.html +4 -4
- package/dist/guida/runbooks/scd2-rehash.html +4 -4
- package/dist/guida/runbooks/sql-task-truncate-swap.html +4 -4
- package/dist/guida/runbooks/stato-incrementale.html +4 -4
- package/dist/guida/sub-pipelines/README.html +4 -4
- package/dist/guida/sub-pipelines/riepilogo-ordini.html +4 -4
- package/dist/index.js +1 -1
- package/dist/pipelines.js +1 -1
- package/dist/testing.js +1 -1
- package/docs/.vitepress/lib/published-docs.ts +1 -7
- package/kit/skills/etl-graph/references/wiring.md +4 -3
- package/kit/skills/new-connector/SKILL.md +1 -1
- package/package.json +8 -3
- package/dist/chunk-5B2425TT.js +0 -1
- package/dist/chunk-BFW7HTF6.js +0 -2
- package/dist/chunk-BPRH262Y.js +0 -2
- package/dist/chunk-DPWGI266.js +0 -1
- package/dist/chunk-H75NY6Z4.js +0 -1
- package/dist/chunk-HMED2UDJ.js +0 -2
- package/dist/chunk-MOHJWOCB.js +0 -1
- package/dist/chunk-MXSKD3Z4.js +0 -2
- package/dist/chunk-PGJWGJEB.js +0 -5
- package/dist/chunk-R53642SH.js +0 -1
- package/dist/chunk-RU6CZIDB.js +0 -1
- package/dist/chunk-UN3BPCPA.js +0 -1
- package/dist/chunk-XFHTODDW.js +0 -6
- package/dist/chunk-ZCYSL5A6.js +0 -1
- package/dist/guida/assets/chunks/@localSearchIndexroot.B5zFGbAC.js +0 -1
- package/dist/guida/assets/connectors_README.md.ChyXSf73.js +0 -1
- package/dist/guida/assets/connectors_README.md.ChyXSf73.lean.js +0 -1
- package/dist/guida/assets/connectors_oauth.md.DUHajB0u.js +0 -7
- package/dist/guida/assets/connectors_oauth.md.DUHajB0u.lean.js +0 -1
- /package/dist/guida/assets/{GUIDA_SVILUPPO.md.D13C7Zwu.lean.js → GUIDA_SVILUPPO.md.CrN52ZDN.lean.js} +0 -0
- /package/dist/guida/assets/{TECHNICAL_OVERVIEW.md.DQP0pWc8.lean.js → TECHNICAL_OVERVIEW.md.iD1gDlJY.lean.js} +0 -0
- /package/dist/guida/assets/{conventions_node-descriptor.md.D8Si7E2S.lean.js → conventions_node-descriptor.md.MQaGlm8a.lean.js} +0 -0
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { C as ConfigError, e as ConnectorDetail, d as RetryPolicy, a as Source } from '../errors-bgSO6lGO.js';
|
|
3
|
+
import { M as ManifestVariabili, V as VariabileRisolta, R as RisoluzioneVariabili } from '../manifest-variabili-U1UfPDfF.js';
|
|
4
|
+
import { H as HttpConfig } from '../config-BSUwK4p_.js';
|
|
5
|
+
import { I as IstanzaPerIlPiano } from '../istanza-per-il-piano-CucqUF7b.js';
|
|
6
|
+
import { C as ConnectorRegistry } from '../registry-tB3G64MU.js';
|
|
7
|
+
import '../ambiente-della-pipeline-BoymQ6uN.js';
|
|
8
|
+
import '../variabili-dichiarate-DmfcxsT9.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Un campo di un modulo Zoho CRM come lo dichiara la pipeline (ADR-0106,
|
|
12
|
+
* punto 4): il nome API e il tipo di Zoho (`data_type` di
|
|
13
|
+
* `/settings/fields`). La lista dei campi dichiarati **è** la regola di
|
|
14
|
+
* privacy: un campo che non c'è non si chiede e non esce.
|
|
15
|
+
*/
|
|
16
|
+
interface CampoZoho {
|
|
17
|
+
/** Il nome API: `Stage`, `Account_Name`, `Data_Inizio_Terapia`. */
|
|
18
|
+
readonly nome: string;
|
|
19
|
+
/** Il `data_type` di Zoho: `text`, `picklist`, `lookup`, `datetime`… */
|
|
20
|
+
readonly tipo: string;
|
|
21
|
+
}
|
|
22
|
+
/** Il campo che ogni lettura chiede: la chiave del record. */
|
|
23
|
+
declare const CAMPO_ID = "id";
|
|
24
|
+
/** Il campo che la Records API chiede sempre oltre a `id`; con COQL è un campo come gli altri. */
|
|
25
|
+
declare const CAMPO_MODIFICA = "Modified_Time";
|
|
26
|
+
/** I campi per chiamata della Records API. */
|
|
27
|
+
declare const MAX_CAMPI_PER_CHIAMATA = 50;
|
|
28
|
+
/**
|
|
29
|
+
* I campi dichiarabili per passata con la Records API: i 50 meno `id` e
|
|
30
|
+
* `Modified_Time`. Con COQL vale {@link MAX_CAMPI_COQL}.
|
|
31
|
+
*/
|
|
32
|
+
declare const MAX_CAMPI_DICHIARATI: number;
|
|
33
|
+
/**
|
|
34
|
+
* I campi di una `SELECT` COQL: 500, `id` compreso. Nome e cognome di ogni
|
|
35
|
+
* collegamento a un utente contano anche loro (vedi `coql.ts`).
|
|
36
|
+
*/
|
|
37
|
+
declare const MAX_CAMPI_COQL: number;
|
|
38
|
+
/**
|
|
39
|
+
* Come il source legge un modulo (ADR-0106, emendamento del 2026-10-23):
|
|
40
|
+
*
|
|
41
|
+
* - `records`: la Records API, a pagine di 200 ordinate per `id`, fino a
|
|
42
|
+
* 100.000 record e 48 campi oltre a `Modified_Time` per chiamata;
|
|
43
|
+
* - `coql`: la Query API, a blocchi di 2.000 con `id` crescente, senza tetto
|
|
44
|
+
* di record e fino a 499 campi. Vuole lo scope `ZohoCRM.coql.READ`.
|
|
45
|
+
*/
|
|
46
|
+
type LetturaZoho = "records" | "coql";
|
|
47
|
+
/** I campi dichiarabili in una lettura, `Modified_Time` escluso per `records`. */
|
|
48
|
+
declare const maxCampiDi: (lettura: LetturaZoho) => number;
|
|
49
|
+
/** Il suffisso della colonna con il nome dell'utente di un `userlookup`. */
|
|
50
|
+
declare const SUFFISSO_NOME = "_nome";
|
|
51
|
+
/**
|
|
52
|
+
* Il nome della colonna di un campo: i caratteri non di parola diventano `_`,
|
|
53
|
+
* gli `_` ripetuti uno, senza `_` ai bordi, in minuscolo. È `colonna()` dello
|
|
54
|
+
* script Python che ha letto il CRM fino a oggi, così le colonne restano
|
|
55
|
+
* quelle dei parquet.
|
|
56
|
+
*/
|
|
57
|
+
declare function colonnaZoho(api: string): string;
|
|
58
|
+
/** `true` se il campo è un collegamento a un utente, con la colonna del nome. */
|
|
59
|
+
declare const eCampoUtente: (campo: CampoZoho) => boolean;
|
|
60
|
+
/** Il tipo della colonna in uscita, per il DAG e per lo schema del record. */
|
|
61
|
+
type TipoColonnaZoho = "string" | "integer" | "number" | "boolean" | "date" | "datetime";
|
|
62
|
+
/** Il tipo della colonna di un campo, come lo converte {@link valoreZoho}. */
|
|
63
|
+
declare function tipoColonnaZoho(tipo: string): TipoColonnaZoho;
|
|
64
|
+
/** Una colonna del record: da quale campo viene e di che tipo è. */
|
|
65
|
+
interface ColonnaZoho {
|
|
66
|
+
readonly colonna: string;
|
|
67
|
+
readonly campo: CampoZoho;
|
|
68
|
+
readonly tipo: TipoColonnaZoho;
|
|
69
|
+
/** `true` per la colonna `<colonna>_nome` di un collegamento a un utente. */
|
|
70
|
+
readonly nomeUtente: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Le colonne di un record letto con questi campi, nell'ordine: `id`, poi una
|
|
74
|
+
* per campo e, per un collegamento a un utente, subito dopo `<colonna>_nome`.
|
|
75
|
+
*/
|
|
76
|
+
declare function colonneZoho(campi: readonly CampoZoho[]): ColonnaZoho[];
|
|
77
|
+
/** I nomi delle colonne del record, `id` compreso: quelle che scrive un sink. */
|
|
78
|
+
declare function nomiColonneZoho(campi: readonly CampoZoho[]): string[];
|
|
79
|
+
/** Il valore di una colonna del record. */
|
|
80
|
+
type ValoreZoho = string | number | boolean | null;
|
|
81
|
+
/**
|
|
82
|
+
* Il valore di un campo come lo scrive la colonna. È `valore()` dello script
|
|
83
|
+
* Python che ha letto il CRM fino a oggi:
|
|
84
|
+
*
|
|
85
|
+
* - vuoto (`null`, `""`) → `null`;
|
|
86
|
+
* - un collegamento → il solo `id`: il nome accanto (il paziente, il medico)
|
|
87
|
+
* non esce mai;
|
|
88
|
+
* - una multiselezione → le voci unite da `"; "`;
|
|
89
|
+
* - una data e ora → l'ora locale come la dà Zoho, senza fuso
|
|
90
|
+
* (`AAAA-MM-GGTHH:MM:SS`); una data → `AAAA-MM-GG`;
|
|
91
|
+
* - booleani, interi e decimali → il loro tipo;
|
|
92
|
+
* - il resto (testo, picklist, formule) → testo.
|
|
93
|
+
*
|
|
94
|
+
* Un valore che non si converte lancia {@link ValoreNonConvertibile}, senza il
|
|
95
|
+
* valore: chi legge lo trasforma in un errore che nomina campo e record.
|
|
96
|
+
*/
|
|
97
|
+
declare function valoreZoho(valore: unknown, tipo: string): ValoreZoho;
|
|
98
|
+
/** Un record di Zoho dopo la conversione: `id` e una colonna per campo. */
|
|
99
|
+
type RecordZoho = Readonly<Record<string, ValoreZoho>> & {
|
|
100
|
+
readonly id: string;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Il contratto di un record letto con questi campi: `id` non vuoto, ogni
|
|
104
|
+
* colonna del suo tipo, e **nient'altro** (`strict`). È il controllo di
|
|
105
|
+
* privacy al confine: una colonna non dichiarata ferma la run.
|
|
106
|
+
*/
|
|
107
|
+
declare function schemaRecordZoho(campi: readonly CampoZoho[]): z.ZodType<RecordZoho>;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Un'organizzazione Zoho CRM, come la vede il connettore (ADR-0106). Solo la
|
|
111
|
+
* Records API v8.
|
|
112
|
+
*
|
|
113
|
+
* Non porta credenziali: il token lo rinnova l'identità OAuth2 nominata da
|
|
114
|
+
* `oauthInstance` (`OAUTH_<ID>_*`, ADR-0065), con il refresh token di Zoho.
|
|
115
|
+
* Così il segreto vive in un posto solo, e questo connettore non ha un
|
|
116
|
+
* fornitore di token suo.
|
|
117
|
+
*/
|
|
118
|
+
interface ZohoConfig {
|
|
119
|
+
/**
|
|
120
|
+
* La base delle API, `https://www.zohoapis.<dc>/crm/v8`, senza barra
|
|
121
|
+
* finale. Decide anche il data center: un token emesso da
|
|
122
|
+
* `accounts.zoho.eu` vale solo su `zohoapis.eu`.
|
|
123
|
+
*/
|
|
124
|
+
readonly baseUrl: string;
|
|
125
|
+
/** L'identità OAuth2 del registry che rinnova il token. */
|
|
126
|
+
readonly oauthInstance: string;
|
|
127
|
+
/** Tempo massimo di una singola richiesta, in millisecondi. */
|
|
128
|
+
readonly timeoutMs: number;
|
|
129
|
+
/** Dimensione massima di una risposta, in byte. */
|
|
130
|
+
readonly maxResponseBytes: number;
|
|
131
|
+
/**
|
|
132
|
+
* Le variabili da cui arriva la config, con la loro origine (ADR-0089): il
|
|
133
|
+
* descriptor le mostra accanto ai valori. Le mette {@link loadZohoConfig};
|
|
134
|
+
* assenti in una config scritta a mano.
|
|
135
|
+
*/
|
|
136
|
+
readonly variabili?: readonly VariabileRisolta[];
|
|
137
|
+
/**
|
|
138
|
+
* Solo in un'istanza d'esempio del piano: il `ConfigError` per cui la
|
|
139
|
+
* configurazione risolta non si costruisce (ADR-0089).
|
|
140
|
+
*/
|
|
141
|
+
readonly ricaduta?: ConfigError;
|
|
142
|
+
/**
|
|
143
|
+
* Solo nel piano: le variabili dell'identità OAuth2 `oauthInstance`, per dire
|
|
144
|
+
* nella riga `credenziale` se è completa (`conIdentitaOauth`).
|
|
145
|
+
*/
|
|
146
|
+
readonly identitaOauth?: RisoluzioneVariabili;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Più largo di quello di `http`: una pagina di 200 record con 50 campi può
|
|
150
|
+
* metterci secondi, e un timeout la farebbe ripetere da capo.
|
|
151
|
+
*/
|
|
152
|
+
declare const DEFAULT_ZOHO_TIMEOUT_MS = 60000;
|
|
153
|
+
declare const DEFAULT_ZOHO_MAX_RESPONSE_BYTES: number;
|
|
154
|
+
/**
|
|
155
|
+
* Le variabili di un'organizzazione Zoho, per suffisso del prefisso d'istanza
|
|
156
|
+
* (ADR-0089). Le leggono sia {@link loadZohoConfig} sia il piano.
|
|
157
|
+
*/
|
|
158
|
+
declare const MANIFEST_ZOHO: ManifestVariabili;
|
|
159
|
+
/**
|
|
160
|
+
* Config di un'organizzazione Zoho CRM da variabili d'ambiente con prefisso
|
|
161
|
+
* (default `ZOHO_`), dichiarate in {@link MANIFEST_ZOHO}:
|
|
162
|
+
*
|
|
163
|
+
* - `ZOHO_BASE_URL` (obbligatoria): la base delle API v8 del data center,
|
|
164
|
+
* `https://www.zohoapis.eu/crm/v8` per l'Europa;
|
|
165
|
+
* - `ZOHO_OAUTH_INSTANCE` (default `default`): l'identità OAuth2 del registry
|
|
166
|
+
* (`OAUTH_INSTANCES`) che rinnova il token, con il token endpoint di Zoho
|
|
167
|
+
* (`https://accounts.zoho.eu/oauth/v2/token`);
|
|
168
|
+
* - `ZOHO_TIMEOUT_MS` (default {@link DEFAULT_ZOHO_TIMEOUT_MS}).
|
|
169
|
+
*
|
|
170
|
+
* Con variabili mancanti lancia un `ConfigError` che le elenca **tutte**. Gli
|
|
171
|
+
* errori nominano le variabili, mai i valori.
|
|
172
|
+
*/
|
|
173
|
+
declare function loadZohoConfig(prefix?: string, env?: NodeJS.ProcessEnv): ZohoConfig;
|
|
174
|
+
/**
|
|
175
|
+
* La config del trasporto condiviso di `http` per **una** richiesta, con il
|
|
176
|
+
* token valido in quel momento. Zoho vuole `Zoho-oauthtoken`, non `Bearer`, e
|
|
177
|
+
* il token si rinnova durante una lettura lunga: per questo il connettore la
|
|
178
|
+
* costruisce a ogni richiesta invece di tenerne una per run (ADR-0106).
|
|
179
|
+
*/
|
|
180
|
+
declare function trasportoZoho(config: ZohoConfig, token: string): HttpConfig;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* La riga `credenziale` di un nodo Zoho: l'identità OAuth2 e, nel piano, se le
|
|
184
|
+
* sue variabili ci sono tutte o quali mancano (il badge punta alla prima).
|
|
185
|
+
* Senza risoluzione, una config costruita a mano, nomina solo l'identità.
|
|
186
|
+
*/
|
|
187
|
+
declare function dettaglioCredenzialeZoho(config: ZohoConfig): ConnectorDetail;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Retry di una lettura: `Retry-After` come attesa minima (il trasporto lo
|
|
191
|
+
* legge su 429 e 5xx transitori), backoff da 2 secondi con jitter, al più 5
|
|
192
|
+
* tentativi. `maxMs` è il tetto di **ogni** attesa (ADR-0059): Zoho conta le
|
|
193
|
+
* chiamate per minuto, e una pausa di un minuto basta a rientrare.
|
|
194
|
+
*/
|
|
195
|
+
declare const DEFAULT_ZOHO_RETRY: RetryPolicy;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* L'organizzazione `id` per il piano (ADR-0089): quella risolta dall'ambiente,
|
|
199
|
+
* o l'esempio con le variabili e le origini dell'istanza vera, sempre con lo
|
|
200
|
+
* stato dell'identità OAuth2 che le rinnova il token. Senza caricare le altre
|
|
201
|
+
* istanze, così una rotta non trascina le sane.
|
|
202
|
+
*/
|
|
203
|
+
declare function istanzaZohoPerIlPiano(id: string, env: NodeJS.ProcessEnv): IstanzaPerIlPiano<ZohoConfig>;
|
|
204
|
+
|
|
205
|
+
/** Registry validato delle organizzazioni Zoho CRM configurate (ADR-0030). */
|
|
206
|
+
type ZohoRegistry = ConnectorRegistry<ZohoConfig>;
|
|
207
|
+
/**
|
|
208
|
+
* Risolve lo {@link ZohoRegistry} da env. Con `ZOHO_INSTANCES` (es. `vendite`)
|
|
209
|
+
* carica un'organizzazione per id dalle variabili `ZOHO_<ID>_*`; senza,
|
|
210
|
+
* l'istanza `default` dalle variabili base `ZOHO_*`. Più clienti con Zoho CRM
|
|
211
|
+
* convivono nello stesso worker, ognuno con la sua identità OAuth2.
|
|
212
|
+
*/
|
|
213
|
+
declare function loadZohoRegistry(env?: NodeJS.ProcessEnv): ZohoRegistry;
|
|
214
|
+
/**
|
|
215
|
+
* La config della sola organizzazione `id`, senza caricare le altre: è ciò che
|
|
216
|
+
* usa il piano, dove un'istanza rotta non deve trascinare le altre (ADR-0089).
|
|
217
|
+
*/
|
|
218
|
+
declare function loadZohoInstance(id: string, env?: NodeJS.ProcessEnv): ZohoConfig;
|
|
219
|
+
|
|
220
|
+
/** Record per pagina: il massimo che la Records API restituisce. */
|
|
221
|
+
declare const MAX_ZOHO_PER_PAGINA = 200;
|
|
222
|
+
/**
|
|
223
|
+
* I record che una sola interrogazione della Records API può scorrere: oltre,
|
|
224
|
+
* Zoho risponde `PAGINATION_LIMIT_EXCEEDED`.
|
|
225
|
+
*/
|
|
226
|
+
declare const MAX_ZOHO_PER_INTERROGAZIONE = 100000;
|
|
227
|
+
|
|
228
|
+
/** Record per query: il massimo che la Query API restituisce. */
|
|
229
|
+
declare const MAX_ZOHO_PER_QUERY = 2000;
|
|
230
|
+
|
|
231
|
+
interface ZohoCrmRecordsOptions {
|
|
232
|
+
/** L'organizzazione, da `loadZohoRegistry().get(id)` (ADR-0030). */
|
|
233
|
+
readonly config: ZohoConfig;
|
|
234
|
+
/**
|
|
235
|
+
* Il token valido in questo momento, da `fornitoreToken` sull'identità
|
|
236
|
+
* OAuth2 `config.oauthInstance`. Un fornitore per run, condiviso fra i nodi
|
|
237
|
+
* della stessa organizzazione: tiene la cache del token.
|
|
238
|
+
*/
|
|
239
|
+
readonly token: () => Promise<string>;
|
|
240
|
+
/** Id dell'istanza, mostrato nel DAG. */
|
|
241
|
+
readonly instanceId?: string;
|
|
242
|
+
readonly name?: string;
|
|
243
|
+
/** Il nome API del modulo: `Deals`, `Sales_Orders`. */
|
|
244
|
+
readonly modulo: string;
|
|
245
|
+
/**
|
|
246
|
+
* I campi da leggere, con il loro tipo (ADR-0106, punto 4). Ognuno diventa
|
|
247
|
+
* una colonna; un collegamento a un utente anche `<colonna>_nome`. Nessun
|
|
248
|
+
* altro campo esce dal source. Quanti ne stanno in una lettura lo dice
|
|
249
|
+
* {@link lettura}: 48 oltre a `Modified_Time` con `records`, 499 con `coql`.
|
|
250
|
+
*/
|
|
251
|
+
readonly campi: readonly CampoZoho[];
|
|
252
|
+
/**
|
|
253
|
+
* Come leggere il modulo (vedi `LetturaZoho`). Default `records`, che basta
|
|
254
|
+
* fino a 100.000 record; oltre serve `coql`, con lo scope
|
|
255
|
+
* `ZohoCRM.coql.READ`.
|
|
256
|
+
*/
|
|
257
|
+
readonly lettura?: LetturaZoho;
|
|
258
|
+
/** `records`: record per pagina, fra 1 e {@link MAX_ZOHO_PER_PAGINA} (default 200). */
|
|
259
|
+
readonly perPagina?: number;
|
|
260
|
+
/**
|
|
261
|
+
* `records`: record per interrogazione prima di fermarsi. Default
|
|
262
|
+
* {@link MAX_ZOHO_PER_INTERROGAZIONE}, il tetto di Zoho: più basso solo nei
|
|
263
|
+
* test, dove centomila record finti non servono.
|
|
264
|
+
*/
|
|
265
|
+
readonly maxPerInterrogazione?: number;
|
|
266
|
+
/** `coql`: record per query, fra 1 e {@link MAX_ZOHO_PER_QUERY} (default 2000). */
|
|
267
|
+
readonly perQuery?: number;
|
|
268
|
+
/** Retry del catalogo e di ogni richiesta. */
|
|
269
|
+
readonly retry?: RetryPolicy;
|
|
270
|
+
/** Iniettabile nei test; default il `fetch` di Node. */
|
|
271
|
+
readonly fetchImpl?: typeof fetch;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* I record di un modulo Zoho CRM con i soli campi dichiarati (ADR-0106). Ogni
|
|
275
|
+
* run rilegge tutto il modulo, senza stato: è il carico completo della v1.
|
|
276
|
+
*
|
|
277
|
+
* A ogni run legge prima il catalogo dei campi del modulo
|
|
278
|
+
* (`GET /settings/fields`), una volta: un campo dichiarato che Zoho non
|
|
279
|
+
* conosce più è un `ConfigError` che lo nomina, prima del primo record.
|
|
280
|
+
*
|
|
281
|
+
* Poi legge il modulo **in ordine di `id`**, che un record modificato durante
|
|
282
|
+
* la lettura non cambia, con una delle due letture (`lettura`):
|
|
283
|
+
*
|
|
284
|
+
* - `records`: la Records API, `GET /{modulo}` a pagine di 200 con
|
|
285
|
+
* `page_token`, fino a 100.000 record;
|
|
286
|
+
* - `coql`: la Query API, `POST /coql` a blocchi di 2.000 con `id > ultimo`,
|
|
287
|
+
* senza tetto di record.
|
|
288
|
+
*
|
|
289
|
+
* In entrambe una richiesta parte solo quando chi legge ha consumato il
|
|
290
|
+
* blocco precedente, e in memoria restano gli `id` visti, non i record.
|
|
291
|
+
*
|
|
292
|
+
* Ogni record esce con `id` e una colonna per campo dichiarato, convertita
|
|
293
|
+
* come dice `valoreZoho`: di un collegamento solo l'`id`, di un utente Zoho
|
|
294
|
+
* anche il nome. Un valore che non si converte nel tipo del suo campo è un
|
|
295
|
+
* `ExtractError` che nomina modulo, campo e `id` del record, mai il valore.
|
|
296
|
+
*
|
|
297
|
+
* Usa il trasporto condiviso di `http`: timeout, tetto sui byte, abort,
|
|
298
|
+
* validazione Zod, 429 e 5xx transitori con `Retry-After`. Il token si chiede
|
|
299
|
+
* al fornitore a ogni richiesta, quindi una lettura lunga sopravvive alla sua
|
|
300
|
+
* scadenza.
|
|
301
|
+
*/
|
|
302
|
+
declare function zohoCrmRecords(options: ZohoCrmRecordsOptions): Source<RecordZoho>;
|
|
303
|
+
|
|
304
|
+
export { CAMPO_ID, CAMPO_MODIFICA, type CampoZoho, type ColonnaZoho, DEFAULT_ZOHO_MAX_RESPONSE_BYTES, DEFAULT_ZOHO_RETRY, DEFAULT_ZOHO_TIMEOUT_MS, type LetturaZoho, MANIFEST_ZOHO, MAX_CAMPI_COQL, MAX_CAMPI_DICHIARATI, MAX_CAMPI_PER_CHIAMATA, MAX_ZOHO_PER_INTERROGAZIONE, MAX_ZOHO_PER_PAGINA, MAX_ZOHO_PER_QUERY, type RecordZoho, SUFFISSO_NOME, type TipoColonnaZoho, type ValoreZoho, type ZohoConfig, type ZohoCrmRecordsOptions, type ZohoRegistry, colonnaZoho, colonneZoho, dettaglioCredenzialeZoho, eCampoUtente, istanzaZohoPerIlPiano, loadZohoConfig, loadZohoInstance, loadZohoRegistry, maxCampiDi, nomiColonneZoho, schemaRecordZoho, tipoColonnaZoho, trasportoZoho, valoreZoho, zohoCrmRecords };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import'../chunk-ZCYGHS7P.js';import {e as e$1}from'../chunk-JLPK6MMQ.js';import {c as c$2}from'../chunk-LJ7DVP5F.js';import {A as A$1,O as O$1,l,P,Q as Q$1,G as G$1,H as H$1,J,m,r,s,a as a$1}from'../chunk-PKBSETMV.js';import {a,g,c as c$1,e,aa,Z as Z$1}from'../chunk-PE2QKU34.js';import {z}from'zod';var c="id",y="Modified_Time",N=50,T=N-[c,y].length,L=499,ao=15,So=a(o=>o==="coql"?L:T,"maxCampiDi"),co=new Set(["userlookup","ownerlookup"]),xo=new Set(["lookup",...co]),wo=new Set(["double","currency","decimal","percent"]),uo="_nome",Po=/^[A-Za-z_][A-Za-z0-9_]*$/;function mo(o){return o.replace(/[^\p{L}\p{N}_]/gu,"_").replace(/_+/g,"_").replace(/^_+|_+$/g,"").toLowerCase()}a(mo,"colonnaZoho");var Z=a(o=>co.has(o.tipo),"eCampoUtente");function H(o){return o==="integer"?"integer":wo.has(o)?"number":o==="boolean"?"boolean":o==="date"?"date":o==="datetime"?"datetime":"string"}a(H,"tipoColonnaZoho");function R(o){return o.flatMap(e=>{let n=mo(e.nome),t={colonna:n,campo:e,tipo:H(e.tipo),nomeUtente:false};return Z(e)?[t,{colonna:`${n}${uo}`,campo:e,tipo:"string",nomeUtente:true}]:[t]})}a(R,"colonneZoho");function To(o){return [c,...R(o).map(e=>e.colonna)]}a(To,"nomiColonneZoho");function po(o,e,n="records"){let t=a(s=>{throw new g(`${o}: ${s}`)},"fail");e.length===0&&t("serve almeno un campo");let i=new Set;for(let s of e)Po.test(s.nome)||t(`"${s.nome}" non \xE8 un nome API di Zoho valido`),s.nome===c&&t(`"${c}" non si dichiara: ogni record lo porta gi\xE0`),i.has(s.nome)&&t(`il campo "${s.nome}" \xE8 dichiarato due volte`),i.add(s.nome);let a$1=n==="coql"?e.length:e.filter(s=>s.nome!==y).length;if(n==="coql"){let s=e.filter(Z).length;a$1+2*s>L&&t(`${a$1} campi, pi\xF9 nome e cognome di ${s} utenti, ma una SELECT COQL ne ammette ${L} oltre a ${c}: dividi il modulo in pi\xF9 passate`),s>ao&&t(`${s} collegamenti a utenti, ma una SELECT COQL ammette ${ao} join: dividi il modulo in pi\xF9 passate`);}n==="records"&&a$1>T&&t(`${a$1} campi oltre a ${y}, ma la Records API ne restituisce ${N} per chiamata (${T} pi\xF9 ${c} e ${y}): dividi il modulo in pi\xF9 passate, o leggilo con COQL`);let l=new Map([[c,c]]);for(let{colonna:s,campo:d}of R(e)){let g=l.get(s);g!==void 0&&t(`i campi "${g}" e "${d.nome}" finirebbero entrambi nella colonna "${s}"`),l.set(s,d.nome);}return e}a(po,"campiDichiaratiZoho");function ho(o){return [{id:c,name:c,dataType:"string",isKey:true},...R(o).map(({colonna:e,tipo:n})=>({id:e,name:e,dataType:n,isKey:false}))]}a(ho,"colonneDelPianoZoho");var Lo=/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2})(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?$/,fo=/^\d{4}-\d{2}-\d{2}$/,$o=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/,A=class extends Error{static{a(this,"ValoreNonConvertibile");}},O=a(()=>{throw new A},"nonConvertibile");function so(o){let e=typeof o=="number"?o:typeof o=="string"&&o.trim()!==""?Number(o):Number.NaN;return Number.isFinite(e)?e:O()}a(so,"numero");var q=a(o=>typeof o=="object"&&o!==null&&!Array.isArray(o),"eOggetto");function lo(o){let e=o.id;return typeof e=="string"||typeof e=="number"?String(e):null}a(lo,"idDi");function Mo(o){if(q(o)){let e=o.name;return typeof e=="string"?e:JSON.stringify(o)}return String(o)}a(Mo,"voce");function F(o,e){if(o==null||o==="")return null;if(q(o))return xo.has(e)?lo(o):lo(o)??JSON.stringify(o);if(Array.isArray(o))return o.map(Mo).join("; ");switch(H(e)){case "datetime":{let n=typeof o=="string"?Lo.exec(o):null;return n===null?O():`${n[1]??""}T${n[2]??""}`}case "date":return typeof o=="string"&&fo.test(o)?o:O();case "boolean":return typeof o=="boolean"?o:o==="true"?true:o==="false"?false:O();case "integer":{let n=so(o);return Number.isInteger(n)?n:O()}case "number":return so(o);case "string":return typeof o=="string"?o:JSON.stringify(o)}}a(F,"valoreZoho");function go(o){if(!q(o))return null;let e=o.name;return typeof e=="string"&&e!==""?e:null}a(go,"nomeUtenteZoho");function Do(o){switch(o){case "integer":return z.number().int().nullable();case "number":return z.number().nullable();case "boolean":return z.boolean().nullable();case "date":return z.string().regex(fo).nullable();case "datetime":return z.string().regex($o).nullable();case "string":return z.string().nullable()}}a(Do,"schemaColonna");function vo(o){let e={};for(let{colonna:n,tipo:t}of R(o))e[n]=Do(t);return z.object({[c]:z.string().min(1),...e}).strict()}a(vo,"schemaRecordZoho");var $=6e4,M=20*1024*1024,Uo=new Set(["localhost","127.0.0.1","[::1]"]),D=[{suffisso:"BASE_URL",obbligatoria:true},{suffisso:"OAUTH_INSTANCE",default:l},{suffisso:"TIMEOUT_MS",default:String($)}];function zo(o,e){let n;try{n=new URL(e);}catch{throw new g(`${o}BASE_URL non \xE8 un URL valido`)}if(n.username!==""||n.password!=="")throw new g(`${o}BASE_URL contiene credenziali nell'URL: il token lo rinnova l'identit\xE0 OAuth2 (${o}OAUTH_INSTANCE)`);if(!(n.protocol==="https:"||n.protocol==="http:"&&Uo.has(n.hostname)))throw new g(`${o}BASE_URL deve usare https: il token viaggia in ogni richiesta`);if(n.search!==""||n.hash!=="")throw new g(`${o}BASE_URL deve essere la base delle API, senza query (https://www.zohoapis.eu/crm/v8)`);if(!/\/crm\/v8\/?$/.test(n.pathname))throw new g(`${o}BASE_URL deve finire con /crm/v8: il connettore parla la Records API v8 (https://www.zohoapis.eu/crm/v8)`);return `${n.origin}${n.pathname.replace(/\/+$/,"")}`}a(zo,"parseBaseUrl");function ko(o,e){let n=Number(e);if(!Number.isInteger(n)||n<=0)throw new g(`${o}TIMEOUT_MS non valido (atteso un intero positivo di millisecondi)`);return n}a(ko,"parseTimeout");function Q(o=A$1,e=process.env){let n=O$1(D,o,e);P(n);let t=a(i=>Q$1(n,i),"valore");return {baseUrl:zo(o,t("BASE_URL")),oauthInstance:t("OAUTH_INSTANCE"),timeoutMs:ko(o,t("TIMEOUT_MS")),maxResponseBytes:M,variabili:n.variabili}}a(Q,"loadZohoConfig");function B(o,e){return {baseUrl:o.baseUrl,auth:{kind:"header",name:"authorization",value:`Zoho-oauthtoken ${e}`},timeoutMs:o.timeoutMs,maxResponseBytes:o.maxResponseBytes}}a(B,"trasportoZoho");function yo(o){try{let e=new URL(o);return `${e.origin}${e.pathname.replace(/\/+$/,"")}`}catch{return "non valido"}}a(yo,"apiMostrabile");function Zo(o,e){let n=G$1(o.variabili,"BASE_URL");return [H$1("api",yo(o.baseUrl),n?.valore===void 0?n:{...n,valore:yo(n.valore)}),...e,...J(o.ricaduta),Ro(o)]}a(Zo,"dettagliZoho");var j="credenziale";function Ro(o){let e=G$1(o.variabili,"OAUTH_INSTANCE"),n=`OAuth \xB7 identit\xE0 ${e?.valore??o.oauthInstance}`,t=o.identitaOauth;if(t===void 0)return {label:j,value:n,...e!==void 0?{env:e.variabile,origine:e.origine}:{}};let[i]=t.mancanti;if(i===void 0)return {label:j,value:`${n} \xB7 impostata`,...e!==void 0?{env:e.variabile,origine:e.origine}:{}};let a=t.mancanti.length===1?"manca":"mancano";return {label:j,value:`${n} \xB7 ${a} ${t.mancanti.join(", ")}`,env:i,origine:"mancante"}}a(Ro,"dettaglioCredenzialeZoho");var X={attempts:5,baseMs:2e3,maxMs:6e4,jitter:.3},No={400:"richiesta rifiutata: un campo dichiarato non si legge pi\xF9, o la query COQL usa un campo che COQL non ammette",401:"token rifiutato: controlla l'identit\xE0 OAuth2 dell'istanza, il suo data center (BASE_URL) e gli scope ZohoCRM.modules.READ, ZohoCRM.settings.fields.READ e, per la lettura COQL, ZohoCRM.coql.READ",403:"permesso negato: l'utente del refresh token non vede questo modulo",404:"non trovato: controlla il nome API del modulo e BASE_URL"};function Ho(o,e$1,n){if(!(o instanceof c$1)||o instanceof g)return o;let t=o.context.details?.status,i=typeof t=="number"?No[t]:void 0;return new e(`Zoho, ${e$1.descrizione}: ${o.message}${i!==void 0?` (${i})`:""}`,{stage:n.stage,...o.context.details!==void 0?{details:o.context.details}:{},...o.context.transient!==void 0?{transient:o.context.transient}:{}},{cause:o})}a(Ho,"erroreDelSource");async function _(o,e$2,n){try{return await aa(async()=>{let t=await o.token(),i=await e$1(B(o.config,t),{method:e$2.method??"GET",path:e$2.path,endpoint:e$2.path,...e$2.body!==void 0?{body:e$2.body}:{},...e$2.query!==void 0?{query:e$2.query}:{},...e$2.headers!==void 0?{headers:e$2.headers}:{}},e$2.schema,n,o.fetchImpl!==void 0?{fetchImpl:o.fetchImpl}:{});if(i.kind!=="ok")throw new e(`${e$2.method??"GET"} ${e$2.path}: risposta inattesa`,{stage:o.stage});return i.value},o.retry,n,{onRetry:a(({retry:t,delayMs:i,error:a})=>n.logger.warn("zoho-source.retry",{stage:o.stage,endpoint:e$2.path,retry:t,delayMs:i,status:a instanceof c$1?a.context.details?.status:void 0}),"onRetry")})}catch(t){throw Ho(t,e$2,o)}}a(_,"leggiDaZoho");function Co(o){return {kind:"zoho",listEnvVar:"ZOHO_INSTANCES",instancesRaw:o.ZOHO_INSTANCES,defaultId:l,loadOne:a(e=>Q(m(A$1,e),o),"loadOne")}}a(Co,"opzioni");function qo(o=process.env){return r(Co(o))}a(qo,"loadZohoRegistry");function V(o,e=process.env){return s(Co(e),o)}a(V,"loadZohoInstance");var Fo={baseUrl:"https://zoho.esempio/crm/v8",oauthInstance:"default",timeoutMs:$,maxResponseBytes:M};function Qo(o,e){return {risolta:a(()=>c$2(V(o,e),e),"risolta"),esempio:a(n=>c$2({...Fo,ricaduta:n,variabili:O$1(D,m(A$1,o),e).variabili},e),"esempio")}}a(Qo,"istanzaZohoPerIlPiano");var _o=a(()=>({visti:new Set,chiamate:0,duplicati:0}),"nuovoStato");function Bo(o,e$1,n){let t=o[c];if(typeof t=="string"&&t!=="")return t;if(typeof t=="number")return String(t);throw new e(`Zoho, modulo ${e$1.modulo}: un record senza id`,{stage:n,details:{modulo:e$1.modulo}})}a(Bo,"idDelRecord");function jo(o,e$1,n,t){let i={[c]:e$1};for(let{colonna:a,campo:l,nomeUtente:s}of n.colonne){let d=o[l.nome];try{i[a]=s?go(d):F(d,l.tipo);}catch(g){throw g instanceof A?new e(`Zoho, modulo ${n.modulo}: il campo ${l.nome} del record ${e$1} non si legge come ${l.tipo}`,{stage:t,details:{modulo:n.modulo,campo:l.nome,id:e$1}}):g}}return i}a(jo,"versoRecord");function*v(o,e,n,t){for(let i of o){let a=Bo(i,e,t);if(n.visti.has(a)){n.duplicati++;continue}n.visti.add(a),yield jo(i,a,e,t);}}a(v,"nuoviDelBlocco");var E=2e3,Xo=/^\d+$/,Oo=["first_name","last_name"],Vo=z.union([z.null(),z.object({data:z.array(z.record(z.unknown())),info:z.object({more_records:z.boolean().optional()}).passthrough().optional()})]);function Go(o,e){let n=o.campi.filter(Z).flatMap(a=>Oo.map(l=>`${a.nome}.${l}`)),t=[c,...o.campi.map(a=>a.nome),...n].map(a=>`'${a}'`).join(", "),i=e===void 0?"id is not null":`id > '${e}'`;return `select ${t} from ${o.modulo} where ${i} order by id asc limit ${o.perQuery}`}a(Go,"queryCoql");async function*Ao(o,e,n,t){let i=new Set,a;for(;;){let l=await _(o,{descrizione:`query COQL del modulo ${e.modulo}`,method:"POST",path:"/coql",body:{select_query:Go(e,a)},schema:Vo},n);t.chiamate++;let s=(l?.data??[]).map(g=>Jo(g,e));if(s.length===0)return;Ko(s,e,i,o.stage,n);let d=Yo(s,a,e,o.stage);if(yield*v(s,e,t,o.stage),l?.info?.more_records!==true)return;a=d;}}a(Ao,"leggiConCoql");function Yo(o,e$1,n,t){let i=o[o.length-1]?.[c],a=typeof i=="number"?String(i):i;if(typeof a!="string"||!Xo.test(a))throw new e(`Zoho, modulo ${n.modulo}: la query COQL ha restituito un id che non \xE8 un numero`,{stage:t,details:{modulo:n.modulo}});if(e$1!==void 0&&BigInt(a)<=BigInt(e$1))throw new e(`Zoho, modulo ${n.modulo}: gli id della query COQL non crescono dopo ${e$1}, la lettura girerebbe in tondo`,{stage:t,details:{modulo:n.modulo,dopo:e$1}});return a}a(Yo,"ultimoId");var Eo=a(o=>typeof o=="string"&&o.trim()!=="","eNome");function Jo(o,e){let n=o;for(let t of e.campi.filter(Z)){let i=o[t.nome];if(typeof i!="object"||i===null)continue;let a=i,l=Oo.map(s=>o[`${t.nome}.${s}`]).filter(Eo);l.length!==0&&(n={...n,[t.nome]:{...a,name:l.join(" ")}});}return n}a(Jo,"conNomiUtente");function Ko(o,e,n,t,i){for(let a of e.campi.filter(Z)){if(n.has(a.nome))continue;o.some(s=>{let d=s[a.nome];return typeof d=="object"&&d!==null&&!Eo(d.name)})&&(n.add(a.nome),i.logger.warn("zoho-source.nome-utente-assente",{stage:t,modulo:e.modulo,campo:a.nome}));}}a(Ko,"segnalaNomiAssenti");var b=200,I=1e5,Wo=z.union([z.null(),z.object({data:z.array(z.record(z.unknown())),info:z.object({more_records:z.boolean().optional(),next_page_token:z.string().nullish()}).passthrough().optional()})]);async function*bo(o,e$1,n,t){let i=new Set,a,l=0;for(;;){let s=await _(o,{descrizione:`record del modulo ${e$1.modulo}`,path:`/${e$1.modulo}`,query:{fields:e$1.fields,per_page:String(e$1.perPagina),sort_by:c,sort_order:"asc",...a!==void 0?{page_token:a}:{}},schema:Wo},n);t.chiamate++;let d=s?.data??[];if(l+=d.length,yield*v(d,e$1,t,o.stage),s?.info?.more_records!==true)return;if(l>=e$1.maxPerInterrogazione-e$1.perPagina)throw new e(`Zoho, modulo ${e$1.modulo}: oltre ${e$1.maxPerInterrogazione} record la Records API non legge; leggi il modulo con lettura "coql"`,{stage:o.stage,details:{modulo:e$1.modulo}});a=oe(s.info,i,e$1,o.stage),i.add(a);}}a(bo,"leggiConRecords");var Io=a(o=>[...new Set([c,y,...o.map(e=>e.nome)])].join(","),"fieldsRecords");function oe(o,e$1,n,t){let i=o.next_page_token;if(i==null||i==="")throw new e(`Zoho, modulo ${n.modulo}: more_records senza next_page_token`,{stage:t,details:{modulo:n.modulo}});if(e$1.has(i))throw new e(`Zoho, modulo ${n.modulo}: next_page_token ripetuto, la lettura girerebbe in tondo`,{stage:t,details:{modulo:n.modulo}});return i}a(oe,"prossimoToken");var ee=/^[A-Za-z][A-Za-z0-9_]*$/,ne=z.object({fields:z.array(z.object({api_name:z.string(),data_type:z.string().optional()}).passthrough())});function G(o,e,n,t){if(!Number.isInteger(n)||n<1||n>t)throw new g(`zohoCrmRecords "${o}": ${e} deve essere un intero fra 1 e ${t}`);return n}a(G,"interoFra");function te(o,e,n){return e.lettura==="coql"?{lettura:"coql",perQuery:G(o,"perQuery",e.perQuery??E,E)}:{lettura:"records",fields:Io(n),perPagina:G(o,"perPagina",e.perPagina??b,b),maxPerInterrogazione:G(o,"maxPerInterrogazione",e.maxPerInterrogazione??I,I)}}a(te,"letturaScelta");function re(o){let e=o.name??`zoho:${o.modulo}`;if(!ee.test(o.modulo))throw new g(`zohoCrmRecords "${e}": "${o.modulo}" non \xE8 un nome API di modulo valido`);let n=o.lettura??"records",t=po(`zohoCrmRecords "${e}"`,o.campi,n),i={modulo:o.modulo,campi:t,colonne:R(t)},a$2=te(e,o,t),l={config:o.config,token:o.token,retry:Z$1({...X,...o.retry},e),stage:e,...o.fetchImpl!==void 0?{fetchImpl:o.fetchImpl}:{}};return {name:e,columns:ho(t),descriptor:{kind:"zoho-source",...a$1(o.instanceId),details:Zo(o.config,[{label:"modulo",value:o.modulo},{label:"lettura",value:n==="coql"?"COQL, per id crescente":"Records API, per id"},{label:"campi",value:t.map(s=>s.nome).join(", ")}])},extract:a(s=>ae(l,i,a$2,s),"extract")}}a(re,"zohoCrmRecords");async function ie(o,e,n){let{fields:t}=await _(o,{descrizione:`catalogo dei campi del modulo ${e.modulo}`,path:"/settings/fields",query:{module:e.modulo},schema:ne},n),i=new Map(t.map(l=>[l.api_name,l.data_type])),a=e.campi.map(l=>l.nome).filter(l=>!i.has(l));if(a.length>0)throw new g(`zohoCrmRecords "${o.stage}": il modulo ${e.modulo} non ha pi\xF9 ${a.length===1?"il campo":"i campi"} ${a.join(", ")}. Togli${a.length===1?"lo":"li"} dalla pipeline con una versione nuova`);for(let l of e.campi){let s=i.get(l.nome);s!==void 0&&s!==l.tipo&&n.logger.warn("zoho-source.tipo-cambiato",{stage:o.stage,modulo:e.modulo,campo:l.nome,dichiarato:l.tipo,zoho:s});}}a(ie,"controllaCatalogo");async function*ae(o,e,n,t){await ie(o,e,t);let i=_o();n.lettura==="coql"?yield*Ao(o,{...e,...n},t,i):yield*bo(o,{...e,...n},t,i),t.logger.info("zoho-source.lettura",{stage:o.stage,modulo:e.modulo,lettura:n.lettura,chiamate:i.chiamate,record:i.visti.size,duplicati:i.duplicati});}a(ae,"leggiTutti");
|
|
2
|
+
export{c as CAMPO_ID,y as CAMPO_MODIFICA,M as DEFAULT_ZOHO_MAX_RESPONSE_BYTES,X as DEFAULT_ZOHO_RETRY,$ as DEFAULT_ZOHO_TIMEOUT_MS,D as MANIFEST_ZOHO,L as MAX_CAMPI_COQL,T as MAX_CAMPI_DICHIARATI,N as MAX_CAMPI_PER_CHIAMATA,I as MAX_ZOHO_PER_INTERROGAZIONE,b as MAX_ZOHO_PER_PAGINA,E as MAX_ZOHO_PER_QUERY,uo as SUFFISSO_NOME,mo as colonnaZoho,R as colonneZoho,Ro as dettaglioCredenzialeZoho,Z as eCampoUtente,Qo as istanzaZohoPerIlPiano,Q as loadZohoConfig,V as loadZohoInstance,qo as loadZohoRegistry,So as maxCampiDi,To as nomiColonneZoho,vo as schemaRecordZoho,H as tipoColonnaZoho,B as trasportoZoho,F as valoreZoho,re as zohoCrmRecords};
|