@winning-sales/nexo 0.7.0 → 0.8.0
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 +18 -3
- package/assets/connect/connect-sdk.d.ts +294 -11
- package/assets/connect/manifest.schema.json +598 -9
- package/assets/docs/pages.json +1 -1
- package/assets/skills/nexo-api/SKILL.md +8 -0
- package/assets/skills/nexo-automations/SKILL.md +6 -0
- package/assets/skills/nexo-connect/SKILL.md +15 -4
- package/assets/skills/nexo-dashboards/SKILL.md +2 -0
- package/dist/auth/callback-page.js +51 -0
- package/dist/auth/loopback-server.js +17 -7
- package/dist/commands/agents.js +241 -0
- package/dist/commands/automations.js +32 -17
- package/dist/commands/connect-access.js +64 -23
- package/dist/connect/access.js +81 -7
- package/dist/connect/changes.js +12 -1
- package/dist/connect/runs.js +1 -1
- package/dist/program-agents.js +65 -0
- package/dist/program-connect-access.js +16 -9
- package/dist/program.js +2 -0
- package/dist/tools/tool-manifest.js +13 -1
- package/package.json +1 -1
- package/reference.json +210 -39
package/README.md
CHANGED
|
@@ -140,8 +140,9 @@ Cada comando que muda algo mostra a prévia e pede o sim num terminal; `-y` apli
|
|
|
140
140
|
nexo connect hosts # os hosts aprovados e os que esperam o sim de uma pessoa
|
|
141
141
|
nexo connect hosts approve # abre a tela do conector nos hosts e espera a aprovação (até 10 minutos); --no-wait só abre
|
|
142
142
|
nexo connect secrets list # cada segredo: preenchido ou faltando, e desde quando (nunca o valor)
|
|
143
|
-
nexo connect webhook # a
|
|
144
|
-
nexo connect webhook
|
|
143
|
+
nexo connect webhook # o endereço (que é a credencial), a autenticação declarada e os segredos que faltam
|
|
144
|
+
nexo connect webhook deliveries --limit 25 # as últimas chamadas ao webhook, com o desfecho (rodou, esperando, recusada, descartada) e o motivo; --before <id> pagina
|
|
145
|
+
nexo connect webhook rotate # troca o token do endereço: mostra o que muda e pede o sim (ou --yes); o endereço antigo para na hora
|
|
145
146
|
nexo connect oauth # o app, o estado e até quando o token vale
|
|
146
147
|
nexo connect oauth authorize # abre a página do outro sistema e espera a volta (até 10 minutos)
|
|
147
148
|
nexo connect oauth client set --client-id <id> # o app OAuth da empresa; o client secret é digitado sem eco ou vem por --stdin; pede o sim
|
|
@@ -155,7 +156,7 @@ nexo connect email files # os arquivos recebidos e os
|
|
|
155
156
|
|
|
156
157
|
**Aprovar host é da pessoa, na tela.** O token do `nexo login` nunca recebe `connectors:hosts`, e por isso a CLI não aprova nada sozinha: `hosts approve` mostra os hosts (cada um passa a receber as chamadas do conector com os segredos dele), abre a tela do conector já nos hosts, a pessoa aprova lá com a sessão dela, e a CLI só espera o host aparecer entre os aprovados e diz quais foram. Não precisa mais criar uma chave pessoal para isso; uma chave pessoal com `connectors:hosts` continua valendo, mas só com uma pessoa no terminal: a CLI mostra a prévia do `/v1` e a pessoa digita `aprovar` (ou o host) para aplicar. `hosts approve` não tem `-y` nem `--confirm`, e fora de um terminal vai sempre pela tela. Passou dos 10 minutos, a CLI sai com código 1. Num ambiente que a CLI não conhece, ela mostra o link e não abre o navegador.
|
|
157
158
|
|
|
158
|
-
**Nenhum valor secreto sai na tela nem no `--json`.** `secrets list` diz só se está preenchido. O client secret do `oauth client set`
|
|
159
|
+
**Nenhum valor secreto sai na tela nem no `--json`.** `secrets list` diz só se está preenchido. O client secret do `oauth client set` é digitado sem eco ou vem por `--stdin`. **O endereço do webhook (`/webhooks/connect/<token>`) é a credencial dele** (o token vai na URL; o Nexo não exige assinatura, e `auth` no manifesto é opcional, para exigir também cabeçalho, Basic ou HMAC): `webhook` e `webhook rotate` o mostram, e quem o tem pode chamar o webhook. `webhook rotate` mostra a prévia e pede o sim (`-y`, ou `--confirm <token>` fora de um terminal); com `--json` o stdout é um JSON só e nada troca sem `--yes`. O segredo do webhook agora é um segredo comum do manifesto (`nexo connect secrets set`). `oauth client set` e `remove` avisam que as autorizações do app anterior caem; `sftp accept` e `email renew` mostram o que muda. Os quatro pedem o sim num terminal (`-y`, ou `--confirm` fora de um terminal, só depois do sim da pessoa).
|
|
159
160
|
|
|
160
161
|
`oauth authorize` não conclui sem o navegador: a volta do outro sistema passa pela página do Nexo, no navegador em que a pessoa está logada. A CLI abre a página, espera o estado virar autorizado e diz "Autorizado". Sem app configurado para o sistema, ela abre a tela do conector no OAuth, onde a empresa traz o app dela. Todos aceitam `--json`.
|
|
161
162
|
|
|
@@ -310,6 +311,20 @@ Os modelos são os do app, nos dois canais. O e-mail é um documento de blocos c
|
|
|
310
311
|
|
|
311
312
|
O token precisa de `automations:read` para ler, prever e estruturar, e de `automations:write` para criar, mudar e publicar (admin ou líder de vendas, com o módulo Automações no plano). Também atende por `nexo modelos`. A skill `nexo-automations` traz as diretrizes de estilo do e-mail.
|
|
312
313
|
|
|
314
|
+
## Agentes de atendimento
|
|
315
|
+
|
|
316
|
+
```
|
|
317
|
+
nexo agents # o Agente SDR e o Agente CS, com o estado
|
|
318
|
+
nexo agents show <sdr|cs> # a configuração de um agente
|
|
319
|
+
nexo agents set <sdr|cs> --on --cases after_hours,stalled_queue --yes
|
|
320
|
+
nexo agents hours # o seu horário de reunião
|
|
321
|
+
nexo agents hours --day seg-sex=09:00-12:00,14:00-18:00
|
|
322
|
+
nexo agents hours --company # volta ao horário da empresa
|
|
323
|
+
nexo agents hours <vendedor> # só lê o horário de outro vendedor
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
`set` pede perfil que edita os agentes (administrador) e `--on`, `--off`, `--cases`, `--book-meeting`, `--no-book-meeting`, `--meeting-minutes`, `--meeting-lead` ou `--name`. Toda mudança mostra o que muda e pede o sim (ou `--yes`). Cada vendedor muda o próprio horário de reunião; o de outra pessoa só se lê. Também atende por `nexo agentes`.
|
|
327
|
+
|
|
313
328
|
## Plano e cobrança
|
|
314
329
|
|
|
315
330
|
```sh
|
|
@@ -6,6 +6,12 @@ export interface HttpRequest {
|
|
|
6
6
|
* down that agent's tunnel into the customer's network. The gateway refuses anything else.
|
|
7
7
|
*/
|
|
8
8
|
readonly url: string;
|
|
9
|
+
/**
|
|
10
|
+
* x-nexo-agent-page (path=<array path>&offset=<n>&limit=<n>, limit up to 10000) works only on the initial load
|
|
11
|
+
* (ctx.input.initialLoad) and only on an API of an agent: the agent calls once (up to 6 minutes and 120 MiB), keeps the answer and
|
|
12
|
+
* returns 200 { itens, total, offset, proximo } per page, or 202 { carregando: true } while it loads (call again). After the
|
|
13
|
+
* page whose proximo is null the agent deletes it.
|
|
14
|
+
*/
|
|
9
15
|
readonly headers?: Readonly<Record<string, string>>;
|
|
10
16
|
readonly query?: Readonly<Record<string, string>>;
|
|
11
17
|
/** A string goes as is; anything else is sent as JSON. */
|
|
@@ -84,13 +90,32 @@ export interface ConnectorContext {
|
|
|
84
90
|
/** live applies writes; dry_run records them as planned. External reads are real in both. */
|
|
85
91
|
readonly mode: RunMode;
|
|
86
92
|
/**
|
|
87
|
-
* What started the run:
|
|
88
|
-
* triggers started it,
|
|
93
|
+
* What started the run: a NexoWebhookInput for a call to the connector's webhook, a NexoEventInput when a Nexo event of the manifest's
|
|
94
|
+
* triggers started it, a NexoCallInput when a flow called it, a NexoOperationInput when someone asked for one of the
|
|
95
|
+
* manifest's operations, a NexoInitialLoadInput on the initial load an admin started, or null for a scheduled or manual run.
|
|
89
96
|
*/
|
|
90
97
|
readonly input: JsonValue | null;
|
|
91
98
|
}
|
|
92
99
|
/** A Nexo event that can start a run: a record created or changed, or a deal that went into a won stage. */
|
|
93
100
|
export type NexoEventName = 'company.created' | 'company.updated' | 'contact.created' | 'contact.updated' | 'deal.created' | 'deal.updated' | 'deal.won' | 'lead.created' | 'lead.updated' | 'ticket.created' | 'ticket.updated';
|
|
101
|
+
/**
|
|
102
|
+
* The input of a run a call to the connector's webhook started. `body` is the JSON object, or the fields of a form-encoded body (a repeated field
|
|
103
|
+
* becomes a list), or null for XML and plain text: then read `rawBody`. `authorization`, `cookie`, `proxy-authorization` and the header the
|
|
104
|
+
* trigger's `auth` reads never reach `headers`. A rehearsal has no call: `ctx.input` is null, so treat null.
|
|
105
|
+
*/
|
|
106
|
+
export interface NexoWebhookInput {
|
|
107
|
+
readonly body: JsonValue | null;
|
|
108
|
+
readonly rawBody: string;
|
|
109
|
+
readonly contentType: string | null;
|
|
110
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
111
|
+
readonly query: Readonly<Record<string, string>>;
|
|
112
|
+
/** When the Nexo accepted the call, as an ISO instant. */
|
|
113
|
+
readonly receivedAt: string;
|
|
114
|
+
}
|
|
115
|
+
/** The input of the initial load: started once by an admin, never by the cron; read the whole source and leave the cursor for the cron. */
|
|
116
|
+
export interface NexoInitialLoadInput {
|
|
117
|
+
readonly initialLoad: true;
|
|
118
|
+
}
|
|
94
119
|
/**
|
|
95
120
|
* The input of a run a Nexo event started: ids only, never the record's data; read the record with ctx.nexo.get. The run starts once per eventId, however many
|
|
96
121
|
* times the event arrives; deal.won has one eventId per deal, so a deal won again starts nothing. A write of this same
|
|
@@ -104,11 +129,49 @@ export interface NexoEventInput {
|
|
|
104
129
|
/** ISO time of the change. */
|
|
105
130
|
readonly occurredAt: string;
|
|
106
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* The input of a run another module of the Nexo called (trigger "call"), contract 1: the object the caller built, with `contract` at its
|
|
134
|
+
* top. The caller sizes it under the limit and never cuts it silently; the code never receives a secret in it.
|
|
135
|
+
*/
|
|
136
|
+
export interface NexoCallInput {
|
|
137
|
+
readonly contract: 1;
|
|
138
|
+
readonly [key: string]: JsonValue;
|
|
139
|
+
}
|
|
140
|
+
/** A profile the person holds: key is the default profile's key (admin, sales_lead, rep, read_only), or null for one the company made. */
|
|
141
|
+
export interface NexoOperationProfile {
|
|
142
|
+
readonly id: string;
|
|
143
|
+
readonly name: string;
|
|
144
|
+
readonly key: string | null;
|
|
145
|
+
}
|
|
146
|
+
/** Who asked for the operation: the code may filter what it returns by this person (their own orders, their clients). */
|
|
147
|
+
export interface NexoOperationPerson {
|
|
148
|
+
readonly userId: string;
|
|
149
|
+
readonly name: string;
|
|
150
|
+
readonly email: string;
|
|
151
|
+
readonly profiles: readonly NexoOperationProfile[];
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The input of a run of one operation of the manifest, contract 2: which operation, its args (checked against the manifest before
|
|
155
|
+
* the run: each of its type, the required ones present, nothing else) and who asked. A rehearsal of an action plans its writes,
|
|
156
|
+
* as any rehearsal. The output is checked against the operation's own output.
|
|
157
|
+
*/
|
|
158
|
+
export interface NexoOperationInput {
|
|
159
|
+
readonly contract: 2;
|
|
160
|
+
readonly operation: string;
|
|
161
|
+
readonly args: Readonly<Record<string, JsonValue>>;
|
|
162
|
+
readonly person: NexoOperationPerson;
|
|
163
|
+
}
|
|
107
164
|
export type RunMode = 'live' | 'dry_run';
|
|
108
165
|
export type CallIntent = 'read' | 'write';
|
|
109
166
|
/** What the connector's default export returns. Nothing, or done: true, ends the run. */
|
|
110
167
|
export interface ConnectorResult {
|
|
111
168
|
readonly done?: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* What the run hands back to whoever called it (a flow step), on the run that ends: the fields of the manifest's output, each of
|
|
171
|
+
* its type; a `list` field is an array of up to 50 objects with the item fields the manifest declares, and an `html` field is a string with the body of an e-mail (the Nexo cleans it when the run closes). Anything else, or a field of the wrong type, ends the run failed (invalid_output). Ignored by a run with no output
|
|
172
|
+
* in its manifest, and in the slices that go on.
|
|
173
|
+
*/
|
|
174
|
+
readonly output?: Readonly<Record<string, JsonValue>>;
|
|
112
175
|
}
|
|
113
176
|
export type ConnectorMain = (ctx: ConnectorContext) => Promise<ConnectorResult | undefined>;
|
|
114
177
|
export interface RunLimits {
|
|
@@ -330,8 +393,11 @@ export interface LocalDatabases {
|
|
|
330
393
|
}
|
|
331
394
|
|
|
332
395
|
|
|
333
|
-
/**
|
|
334
|
-
|
|
396
|
+
/**
|
|
397
|
+
* Nexo objects a connector reads and writes; the manifest says which ones and which fields. `product` is the catalog of products
|
|
398
|
+
* and services: its properties are the attributes the admin defined in the Nexo Admin, and a product never gets a twin (see `createMany`).
|
|
399
|
+
*/
|
|
400
|
+
export type NexoObject = 'company' | 'contact' | 'deal' | 'lead' | 'ticket' | 'product';
|
|
335
401
|
/** A record a lookup found. An archived one comes too: restore it in the update instead of creating a twin. */
|
|
336
402
|
export interface NexoMatch {
|
|
337
403
|
readonly id: string;
|
|
@@ -348,11 +414,70 @@ export type NexoLookup = {
|
|
|
348
414
|
} | {
|
|
349
415
|
readonly ref: string;
|
|
350
416
|
};
|
|
351
|
-
|
|
417
|
+
/** A boolean only where the field is one (`active` of a product). */
|
|
418
|
+
export type NexoFieldValue = string | number | boolean | null;
|
|
419
|
+
/**
|
|
420
|
+
* A product's table of price tiers (`priceTiers` of the `product` object), in place of a single price. `mode` `flat` is a closed
|
|
421
|
+
* price (the amount of the tier is the total) and `per_unit` a unit price (the amount is of each unit, times the quantity).
|
|
422
|
+
* `measure` is what is counted ("fornecedores"), optional. From 1 to 200 tiers, `upTo` a positive integer rising from one tier to
|
|
423
|
+
* the next, the last one alone with `upTo: null` (no ceiling); `amountInCents` an integer, 0 or more.
|
|
424
|
+
*/
|
|
425
|
+
export interface NexoPriceTiers {
|
|
426
|
+
readonly mode: 'flat' | 'per_unit';
|
|
427
|
+
readonly measure?: string | null;
|
|
428
|
+
readonly tiers: readonly {
|
|
429
|
+
readonly upTo: number | null;
|
|
430
|
+
readonly amountInCents: number;
|
|
431
|
+
}[];
|
|
432
|
+
}
|
|
433
|
+
/** The value of a field of a record: a scalar, or `priceTiers` of a product. */
|
|
434
|
+
export type NexoRecordValue = NexoFieldValue | NexoPriceTiers;
|
|
352
435
|
export type NexoPropertyValue = string | number | boolean | readonly string[] | null;
|
|
436
|
+
/**
|
|
437
|
+
* Where a new lead came from, all optional: it is written as the lead's arrival (campaign, ad, form, UTM, landing page, consent),
|
|
438
|
+
* so a rule can filter by it. The source stays `connect`; the connector (and its system) is recorded by the Nexo, never informed
|
|
439
|
+
* here. Only on a lead that does not exist yet; a field outside this list refuses the record.
|
|
440
|
+
*/
|
|
441
|
+
export interface NexoLeadOrigin {
|
|
442
|
+
readonly campaign?: string | null;
|
|
443
|
+
readonly adId?: string | null;
|
|
444
|
+
readonly formId?: string | null;
|
|
445
|
+
readonly utm?: {
|
|
446
|
+
readonly source?: string | null;
|
|
447
|
+
readonly medium?: string | null;
|
|
448
|
+
readonly campaign?: string | null;
|
|
449
|
+
readonly term?: string | null;
|
|
450
|
+
readonly content?: string | null;
|
|
451
|
+
};
|
|
452
|
+
readonly landingUrl?: string | null;
|
|
453
|
+
readonly legalBasis?: string | null;
|
|
454
|
+
readonly consentText?: string | null;
|
|
455
|
+
/** When the person arrived, as an ISO instant; without it, the moment of the write. */
|
|
456
|
+
readonly arrivedAt?: string;
|
|
457
|
+
}
|
|
458
|
+
/** The UTM of a planned origin: every key present, null when the connector did not tell it. */
|
|
459
|
+
interface NexoPlannedUtm {
|
|
460
|
+
readonly source: string | null;
|
|
461
|
+
readonly medium: string | null;
|
|
462
|
+
readonly campaign: string | null;
|
|
463
|
+
readonly term: string | null;
|
|
464
|
+
readonly content: string | null;
|
|
465
|
+
}
|
|
466
|
+
/** The origin a rehearsal would write for a lead, with the source and the arrival moment filled. */
|
|
467
|
+
export interface NexoPlannedOrigin {
|
|
468
|
+
readonly source: 'connect';
|
|
469
|
+
readonly campaign: string | null;
|
|
470
|
+
readonly adId: string | null;
|
|
471
|
+
readonly formId: string | null;
|
|
472
|
+
readonly utm: NexoPlannedUtm;
|
|
473
|
+
readonly landingUrl: string | null;
|
|
474
|
+
readonly legalBasis: string | null;
|
|
475
|
+
readonly consentText: string | null;
|
|
476
|
+
readonly arrivedAt: string;
|
|
477
|
+
}
|
|
353
478
|
export interface NexoRecordInput {
|
|
354
479
|
/** Native fields, as the manifest names them. */
|
|
355
|
-
readonly values?: Readonly<Record<string,
|
|
480
|
+
readonly values?: Readonly<Record<string, NexoRecordValue>>;
|
|
356
481
|
/** Custom properties by key; the manifest declares each as `property:<key>`. */
|
|
357
482
|
readonly properties?: Readonly<Record<string, NexoPropertyValue>>;
|
|
358
483
|
/**
|
|
@@ -360,6 +485,13 @@ export interface NexoRecordInput {
|
|
|
360
485
|
* core refuses keeps it in quarantine, so the reprocess that creates it links it too and the next run finds it by the ref.
|
|
361
486
|
*/
|
|
362
487
|
readonly ref?: NexoRecordRef;
|
|
488
|
+
/** Only on a new `lead`: where it came from (campaign, UTM...), written with its arrival. */
|
|
489
|
+
readonly origin?: NexoLeadOrigin;
|
|
490
|
+
/**
|
|
491
|
+
* Only on a new `lead`, and not with `values.ownerId`: `"none"` opens it with no owner and outside the default routing. Without
|
|
492
|
+
* `ownerId` and `routing`, the default routing picks the owner. `values.ownerId` (the id `users.findByEmail` returns) opens it with that owner.
|
|
493
|
+
*/
|
|
494
|
+
readonly routing?: 'none';
|
|
363
495
|
}
|
|
364
496
|
export interface NexoRecordRef {
|
|
365
497
|
readonly system: string;
|
|
@@ -400,18 +532,95 @@ export interface NexoRefusal {
|
|
|
400
532
|
readonly reason: string;
|
|
401
533
|
}
|
|
402
534
|
/**
|
|
403
|
-
* A record as the connector reads it: its native fields by their manifest names and its custom properties by key. A
|
|
404
|
-
*
|
|
535
|
+
* A record as the connector reads it: its native fields by their manifest names and its custom properties by key. A script a rule
|
|
536
|
+
* called reads only the records the rule's person reaches; one a trigger of its own started reads the company. An archived record
|
|
537
|
+
* comes too, marked.
|
|
405
538
|
*/
|
|
406
539
|
export interface NexoRecordRead {
|
|
407
540
|
readonly id: string;
|
|
408
541
|
readonly archived: boolean;
|
|
409
|
-
readonly values: Readonly<Record<string,
|
|
542
|
+
readonly values: Readonly<Record<string, NexoRecordValue>>;
|
|
410
543
|
readonly properties: Readonly<Record<string, NexoPropertyValue>>;
|
|
411
544
|
}
|
|
545
|
+
/** How a filter of `query` compares; the same operators as the condition of an automation. */
|
|
546
|
+
export type NexoOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'between' | 'in' | 'not_in' | 'contains' | 'is_empty' | 'is_not_empty' | 'older_than' | 'within_last';
|
|
547
|
+
/**
|
|
548
|
+
* What a filter compares to: one value (`eq`, `neq`, `gt`, `gte`, `lt`, `lte`, `contains`), a list of up to 50 (`in`, `not_in`), the
|
|
549
|
+
* smaller and the larger (`between`), or a number of days (`older_than`, `within_last`). `is_empty` and `is_not_empty` take none.
|
|
550
|
+
* Dates are YYYY-MM-DD (or an ISO instant) and money is in cents.
|
|
551
|
+
*/
|
|
552
|
+
export type NexoFilterValue = string | number | boolean | readonly (string | number | boolean)[];
|
|
553
|
+
/**
|
|
554
|
+
* One condition of a query, on a native field (`{ field: 'amountInCents', op: 'gt', value: 1000000 }`) or on a custom property
|
|
555
|
+
* (`{ property: 'segment', op: 'eq', value: 'varejo' }`). A comparison holds only for a filled value: a record with no value never
|
|
556
|
+
* matches `neq` or `not_in`, and only `is_empty` asks for the empty. Text ignores case and edges. A `contains` or a range (`gt`,
|
|
557
|
+
* `gte`, `lt`, `lte`, `between`, `older_than`, `within_last`) on a property comes only together with an `eq` or `in` on another
|
|
558
|
+
* property, or on an indexed field (`email` of a contact, `cnpj` of a company, `ownerId`, `pipelineId`, `stageId`, `personId` of a
|
|
559
|
+
* lead or ticket).
|
|
560
|
+
*/
|
|
561
|
+
export type NexoFilter = {
|
|
562
|
+
readonly field: string;
|
|
563
|
+
readonly op: NexoOperator;
|
|
564
|
+
readonly value?: NexoFilterValue;
|
|
565
|
+
} | {
|
|
566
|
+
readonly property: string;
|
|
567
|
+
readonly op: NexoOperator;
|
|
568
|
+
readonly value?: NexoFilterValue;
|
|
569
|
+
};
|
|
570
|
+
/** What `query` takes besides the entity. All the filters must hold (and). */
|
|
571
|
+
export interface NexoQueryInput {
|
|
572
|
+
readonly where?: readonly NexoFilter[];
|
|
573
|
+
/** `id` (the default) or `createdAt`, the second only for `deal`. */
|
|
574
|
+
readonly orderBy?: 'id' | 'createdAt';
|
|
575
|
+
/** `asc` is the default. */
|
|
576
|
+
readonly direction?: 'asc' | 'desc';
|
|
577
|
+
/** Records per page, from 1 to 500; 100 when absent. */
|
|
578
|
+
readonly limit?: number;
|
|
579
|
+
/** The `next` of the page before; absent for the first page. */
|
|
580
|
+
readonly cursor?: string;
|
|
581
|
+
/** Archived records stay out unless true. */
|
|
582
|
+
readonly includeArchived?: boolean;
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* A page of a query. `next` is the cursor of the page after, or null at the end. The cursor is opaque and is not a snapshot of
|
|
586
|
+
* the moment: it continues after the last record of this page, so a record created or changed while the pages are read can come
|
|
587
|
+
* in a later page, or not come.
|
|
588
|
+
*/
|
|
589
|
+
export interface NexoPage {
|
|
590
|
+
readonly records: NexoRecordRead[];
|
|
591
|
+
readonly next: string | null;
|
|
592
|
+
}
|
|
412
593
|
export interface NexoUser {
|
|
413
594
|
readonly id: string;
|
|
414
595
|
readonly name: string;
|
|
596
|
+
/** The person's owner in the Nexo CRM, the id `ownerId` takes; null when the person is not an active owner there. */
|
|
597
|
+
readonly ownerId: string | null;
|
|
598
|
+
}
|
|
599
|
+
/** A record of the person the lookup found: its id and its owner in the Nexo CRM (null when it has none). */
|
|
600
|
+
export interface NexoPersonRecord {
|
|
601
|
+
readonly id: string;
|
|
602
|
+
readonly ownerId: string | null;
|
|
603
|
+
}
|
|
604
|
+
/** What the lead entry sees for a phone and an e-mail: the open lead and the contact, and how many deals the contact has in progress and won. */
|
|
605
|
+
export interface NexoPersonLookup {
|
|
606
|
+
readonly found: boolean;
|
|
607
|
+
readonly lead: NexoPersonRecord | null;
|
|
608
|
+
readonly contact: NexoPersonRecord | null;
|
|
609
|
+
readonly deals: {
|
|
610
|
+
readonly open: number;
|
|
611
|
+
readonly won: number;
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
/** The keys of a person lookup: at least one of the two, as the lead entry reads them. */
|
|
615
|
+
export interface NexoPersonKeys {
|
|
616
|
+
readonly phone?: string;
|
|
617
|
+
readonly email?: string;
|
|
618
|
+
}
|
|
619
|
+
/** A person of the other system (a rep of the ERP) to find in the company by e-mail, or to add to its list. */
|
|
620
|
+
export interface NexoPersonInput {
|
|
621
|
+
readonly email: string;
|
|
622
|
+
/** The name the person gets when added; the start of the e-mail when it is shorter than two letters. */
|
|
623
|
+
readonly name: string;
|
|
415
624
|
}
|
|
416
625
|
/**
|
|
417
626
|
* The Nexo, through the core write: every write of a run is one change, undone at once. It never deletes. A rehearsal finds
|
|
@@ -422,11 +631,23 @@ export interface NexoApi {
|
|
|
422
631
|
/** One record by its id, for an object of the manifest's reads; null when it does not exist. The run of a Nexo event reads its record here. */
|
|
423
632
|
get(object: NexoObject, id: string): Promise<NexoRecordRead | null>;
|
|
424
633
|
find(object: NexoObject, by: NexoLookup, values: readonly string[]): Promise<Record<string, NexoMatch[]>>;
|
|
634
|
+
/**
|
|
635
|
+
* Lists the records of an entity by filter, in pages of up to 500: `deal`, `lead`, `contact`, `company` and `ticket`, with their
|
|
636
|
+
* custom properties (a `product`, with its attributes, is read with `get` and `find`), `meeting`, `task`, `document`, `negotiation` and `temperature` (native fields only), `lead_arrival` (the arrivals of a lead: `leadId`, `contactId`, `system`, `source`, `campaign` and the UTM fields filter them; most recent first by `arrivedAt` with `direction: 'desc'`), and `whatsapp_chat`, the WhatsApp chats whose client waits for an answer. The entity must be in the manifest's reads and have a read door:
|
|
637
|
+
* one without it is refused, never read as the company. The records are the native ones, as `get` brings them, and a script a
|
|
638
|
+
* rule called gets only the ones the rule's person reaches. Pages by `id` come in the order of the id, and by `createdAt` where
|
|
639
|
+
* the entity has an index for it. The step keeps the entity, the filtered fields and the count, never the values.
|
|
640
|
+
* To list everything, ask page after page until `next` is null:
|
|
641
|
+
* `let cursor; do { const page = await ctx.nexo.query('deal', { where, cursor }); ...; cursor = page.next ?? undefined; } while (cursor)`.
|
|
642
|
+
*/
|
|
643
|
+
query(entity: string, query?: NexoQueryInput): Promise<NexoPage>;
|
|
425
644
|
/** The id, or null when the core refused the record: it is in the run's quarantine and the run ends partial. */
|
|
426
645
|
create(object: NexoObject, record: NexoRecordInput): Promise<string | null>;
|
|
427
646
|
/**
|
|
428
647
|
* Up to 100 records in one call, created in order; the ids come back in the same order. A record the core refuses (an
|
|
429
|
-
* invalid CNPJ, an option that does not exist) gets null and goes to the run's quarantine; the others are written.
|
|
648
|
+
* invalid CNPJ, an option that does not exist) gets null and goes to the run's quarantine; the others are written. A
|
|
649
|
+
* `product` needs its `ref`, and lands on the product its ref already points at, or the one with its `code` (whatever made
|
|
650
|
+
* it), before a new one is born: the id that comes back may be of a product that already existed.
|
|
430
651
|
*/
|
|
431
652
|
createMany(object: NexoObject, records: readonly NexoRecordInput[]): Promise<(string | null)[]>;
|
|
432
653
|
/** False when the core refused the record and set it aside in quarantine. */
|
|
@@ -448,6 +669,23 @@ export interface NexoApi {
|
|
|
448
669
|
readonly users: {
|
|
449
670
|
/** People of the company by e-mail, to pick an owner; an unknown e-mail maps to null. */
|
|
450
671
|
findByEmail(emails: readonly string[]): Promise<Record<string, NexoUser | null>>;
|
|
672
|
+
/**
|
|
673
|
+
* The same answer as `findByEmail`, adding the ones the company does not have yet: a new e-mail becomes a person only on the
|
|
674
|
+
* list (viewer seat, Somente leitura profile, no login, no e-mail sent) with an owner id the same run can write. A person of
|
|
675
|
+
* the company, active or not, comes back as is, nothing changed. An invalid e-mail, or one of another company, maps to null.
|
|
676
|
+
* Up to 500 per call, a repeated e-mail counting once; the keys are the e-mails as sent. Needs `"users": ["ensure"]` in the
|
|
677
|
+
* manifest. A rehearsal adds nobody and answers ids that exist only in the rehearsal. Undoing the run removes nobody.
|
|
678
|
+
*/
|
|
679
|
+
ensure(people: readonly NexoPersonInput[]): Promise<Record<string, NexoUser | null>>;
|
|
680
|
+
};
|
|
681
|
+
readonly people: {
|
|
682
|
+
/**
|
|
683
|
+
* What the Nexo knows of a person by phone and e-mail, the keys normalized as the lead entry does (the phone with or without the
|
|
684
|
+
* ninth digit is the same person). Writes nothing, and runs for real in a rehearsal. Needs `person` in the manifest's reads; a run a
|
|
685
|
+
* rule called sees only what that rule's person reaches. `found` is false for a person nobody holds.
|
|
686
|
+
* To skip who already has a deal in progress: `const known = await ctx.nexo.people.lookup({ phone }); if (known.deals.open > 0) return;`.
|
|
687
|
+
*/
|
|
688
|
+
lookup(keys: NexoPersonKeys): Promise<NexoPersonLookup>;
|
|
451
689
|
};
|
|
452
690
|
}
|
|
453
691
|
/** The call as the gateway takes it. */
|
|
@@ -460,7 +698,10 @@ export type NexoCall = {
|
|
|
460
698
|
readonly op: 'get';
|
|
461
699
|
readonly object: NexoObject;
|
|
462
700
|
readonly id: string;
|
|
463
|
-
} | {
|
|
701
|
+
} | ({
|
|
702
|
+
readonly op: 'query';
|
|
703
|
+
readonly entity: string;
|
|
704
|
+
} & NexoQueryInput) | {
|
|
464
705
|
readonly op: 'write';
|
|
465
706
|
readonly object: NexoObject;
|
|
466
707
|
readonly records: readonly NexoRecordCall[];
|
|
@@ -475,6 +716,11 @@ export type NexoCall = {
|
|
|
475
716
|
} | {
|
|
476
717
|
readonly op: 'users';
|
|
477
718
|
readonly emails: readonly string[];
|
|
719
|
+
} | ({
|
|
720
|
+
readonly op: 'person';
|
|
721
|
+
} & NexoPersonKeys) | {
|
|
722
|
+
readonly op: 'ensureUsers';
|
|
723
|
+
readonly people: readonly NexoPersonInput[];
|
|
478
724
|
};
|
|
479
725
|
export type NexoLookupCall = {
|
|
480
726
|
readonly kind: 'field';
|
|
@@ -497,11 +743,17 @@ export type NexoReply = {
|
|
|
497
743
|
} | {
|
|
498
744
|
readonly op: 'get';
|
|
499
745
|
readonly record: NexoRecordRead | null;
|
|
746
|
+
} | {
|
|
747
|
+
readonly op: 'query';
|
|
748
|
+
readonly records: NexoRecordRead[];
|
|
749
|
+
readonly next: string | null;
|
|
500
750
|
} | {
|
|
501
751
|
readonly op: 'write';
|
|
502
752
|
readonly planned: boolean;
|
|
503
753
|
readonly ids: (string | null)[];
|
|
504
754
|
readonly refused: NexoRefusal[];
|
|
755
|
+
/** A rehearsal of new leads: the origin each would be written with (null for a refused one), in the order of the records. */
|
|
756
|
+
readonly origins?: (NexoPlannedOrigin | null)[];
|
|
505
757
|
} | {
|
|
506
758
|
readonly op: 'link';
|
|
507
759
|
readonly planned: boolean;
|
|
@@ -516,4 +768,35 @@ export type NexoReply = {
|
|
|
516
768
|
} | {
|
|
517
769
|
readonly op: 'users';
|
|
518
770
|
readonly users: Record<string, NexoUser | null>;
|
|
771
|
+
} | {
|
|
772
|
+
readonly op: 'person';
|
|
773
|
+
readonly person: NexoPersonLookup;
|
|
774
|
+
} | {
|
|
775
|
+
readonly op: 'ensureUsers';
|
|
776
|
+
readonly planned: boolean;
|
|
777
|
+
/** How many people the call added to the list, or would add in a rehearsal. */
|
|
778
|
+
readonly created: number;
|
|
779
|
+
readonly users: Record<string, NexoUser | null>;
|
|
519
780
|
};
|
|
781
|
+
export {};
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
/** One operation of the manifest, as the code implements it: ctx as always, and the input with the args and the person. */
|
|
785
|
+
export type OperationHandler = (ctx: ConnectorContext, input: NexoOperationInput) => Promise<ConnectorResult | undefined>;
|
|
786
|
+
/** The name the run records for an operation that refused the call by the connector's own rule. */
|
|
787
|
+
export declare const OPERATION_REFUSED: string;
|
|
788
|
+
/**
|
|
789
|
+
* Thrown by an operation that refuses the call by the connector's own rule, before any call to the other system: an operation
|
|
790
|
+
* outside the allowed list, a DELETE, a payroll or ledger operation. The Nexo answers that the connector does not allow it, and
|
|
791
|
+
* not that the other system failed, so the assistant knows that calling again changes nothing:
|
|
792
|
+
* `throw new OperationRefused('ExcluirPedido fica sempre fora da ponte')`. A failure of the other system stays a plain Error.
|
|
793
|
+
*/
|
|
794
|
+
export declare class OperationRefused extends Error {
|
|
795
|
+
constructor(message: string);
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* The default export of a connector made of operations, from one function per operation key:
|
|
799
|
+
* `export default operations({ titulos_vencidos: async (ctx, { args, person }) => ({ output: { ... } }) })`.
|
|
800
|
+
* An operation the manifest declares and the code does not implement fails the run with its name.
|
|
801
|
+
*/
|
|
802
|
+
export declare function operations(handlers: Readonly<Record<string, OperationHandler>>): ConnectorMain;
|