hobots 5.0.0 → 5.2.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/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { RunAttachmentContentType, EnvironmentInput, EventType, FileRef, RunItemStatus, RunProgress } from './protocol.cjs';
2
- export { Breadcrumb, BreadcrumbLevel, Envelope, EnvelopeItem, Environment, EventPayload, EventUser, ExceptionData, FileDownloadResponse, FileStorage, HeartbeatPayload, InstanceInfo, InstanceMode, ItemColumn, ItemsDeclaration, MachineProcess, MachineSnapshot, PollRequest, PollResponse, RunAttachmentConfirmRequest, RunAttachmentConfirmResponse, RunAttachmentCreateRequest, RunAttachmentCreateResponse, RunCreateRequest, RunCreateResponse, RunDescriptor, RunError, RunItemInput, RunItemsCreateRequest, RunItemsCreateResponse, RunLogEntry, RunLogLevel, RunStartRequest, RunStartResponse, RunStatus, RunUpdateRequest, RunUpdateResponse, RunUpdateStatus, StackFrame, StepData, StepStatus, TransactionPayload } from './protocol.cjs';
2
+ export { Breadcrumb, BreadcrumbLevel, Envelope, EnvelopeItem, Environment, EventPayload, EventUser, ExceptionData, FileDownloadResponse, FileStorage, HeartbeatPayload, InstanceInfo, InstanceMode, ItemColumn, ItemsDeclaration, MachineProcess, MachineSnapshot, PollRequest, PollResponse, RunAttachmentConfirmRequest, RunAttachmentConfirmResponse, RunAttachmentCreateRequest, RunAttachmentCreateResponse, RunCreateRequest, RunCreateResponse, RunDescriptor, RunError, RunItemInput, RunItemsCreateRequest, RunItemsCreateResponse, RunItemsDoneRequest, RunItemsDoneResponse, RunLogEntry, RunLogLevel, RunStartRequest, RunStartResponse, RunStatus, RunUpdateRequest, RunUpdateResponse, RunUpdateStatus, StackFrame, StepData, StepStatus, TransactionPayload } from './protocol.cjs';
3
3
 
4
4
  /** Espera entre tentativas: ms fixo ou função do número da tentativa que acabou de falhar (1-based). */
5
5
  type RetryDelay = number | ((attempt: number) => number);
@@ -272,20 +272,32 @@ interface RunItemOptions extends RunItemImageOptions {
272
272
  /**
273
273
  * O item em processamento dentro de `items.each`: o desfecho (`succeeded`/`failed`/
274
274
  * `occurrence`) com o `id` e o payload base já resolvidos, e o handle `step` da etapa do
275
- * item (`warning`/`image`/`data`). Sub-etapas: `hobots.step(...)` dentro do handler já
275
+ * item (`warning`/`image`/`data`), e `data(...)` para ir guardando o payload do item sem
276
+ * decidir o desfecho. Sub-etapas: `hobots.step(...)` dentro do handler já
276
277
  * aninha na etapa do item. Sem chamada explícita, o SDK decide: retornou → `succeeded`;
277
278
  * lançou → `failed` com a mensagem do erro.
278
279
  */
279
280
  interface RunItemHandle {
280
281
  /** Posição do elemento na lista (0-based). */
281
282
  readonly index: number;
282
- /** Identidade de negócio resolvida por `options.id` (undefined = o SDK gera uma). */
283
- readonly id: string | undefined;
283
+ /** Identidade do item: a resolvida por `options.id` ou, sem ela, uma gerada pelo SDK — a mesma em todas as tentativas. */
284
+ readonly id: string;
284
285
  /** Handle da etapa deste item no waterfall de performance; undefined fora de uma execução. */
285
286
  readonly step: StepHandle | undefined;
286
287
  /** true depois do primeiro desfecho registrado (o SDK não sobrescreve o que o handler decidiu). */
287
288
  readonly reported: boolean;
288
- /** Item processado com sucesso. `payload` é mesclado sobre o payload base de `options.payload`. */
289
+ /** Desfecho registrado até agora (undefined = nenhum). */
290
+ readonly status: RunItemStatus | undefined;
291
+ /** Tentativa em curso (1-based) — o handler pode ler para logar. */
292
+ readonly attempt: number;
293
+ /**
294
+ * Guarda atributos do item sem registrar desfecho — vai mesclando a cada chamada (chave repetida:
295
+ * a última vence). Entra em qualquer desfecho, inclusive nos implícitos (handler retornou →
296
+ * `succeeded`; lançou → `failed`), entre o payload base de `options.payload` e o payload da
297
+ * chamada de desfecho. Uma nova tentativa começa do zero. Depois do desfecho só acumula: nada é reenviado.
298
+ */
299
+ data(payload: Record<string, unknown>): void;
300
+ /** Item processado com sucesso. `payload` é mesclado sobre o payload base e o de `item.data`. */
289
301
  succeeded(payload?: Record<string, unknown>, options?: RunItemImageOptions): void;
290
302
  /** Falha sem lançar — o loop segue igual; a etapa vira `error` com o motivo. A imagem vai no item. */
291
303
  failed(message: string, payload?: Record<string, unknown>, options?: RunItemImageOptions): void;
@@ -293,8 +305,14 @@ interface RunItemHandle {
293
305
  occurrence(message: string, payload?: Record<string, unknown>, options?: RunItemImageOptions): void;
294
306
  }
295
307
  interface RunItemsEachOptions<T> {
296
- /** Identidade de negócio do item (ex.: nº do cliente). Omitido/null: o SDK gera um id único. */
297
- id?: (element: T, index: number) => string | number | null | undefined;
308
+ /**
309
+ * Identidade de negócio do item: nome do campo do elemento (`'numero'`), chave composta
310
+ * (`['cnpj', 'competencia']`, juntada com `|`) ou função `(elemento, índice) => id`.
311
+ * Omitido: o campo `id` do elemento, se existir. `null`, ou elemento sem o campo padrão:
312
+ * o SDK gera um id único (e o item nunca é pulado na reexecução). Campo explícito ausente
313
+ * no elemento é erro do bot (lança e interrompe o loop).
314
+ */
315
+ id?: string | readonly string[] | ((element: T, index: number) => string | number | null | undefined) | null;
298
316
  /** Atributos base do item (viram colunas no app) — presentes em qualquer desfecho, inclusive falha. */
299
317
  payload?: (element: T, index: number) => Record<string, unknown> | undefined;
300
318
  /** `op` da etapa de cada item no waterfall. Default: 'item'. */
@@ -311,6 +329,18 @@ interface RunItemsEachOptions<T> {
311
329
  * Central na hora. `false` desliga (tudo sai no envio periódico ou no fim da run). Default: true.
312
330
  */
313
331
  flush?: boolean;
332
+ /**
333
+ * Tentativas extras quando o handler lança (falha técnica). Uma etapa só por elemento,
334
+ * com `data.attempts`. `0` desliga. `Occurrence` nunca é retentada. Default: 1.
335
+ */
336
+ retries?: number;
337
+ /** Espera entre as tentativas: ms fixo ou função da tentativa que falhou (1-based). Default: 5_000. */
338
+ retryDelayMs?: RetryDelay;
339
+ /**
340
+ * Na reexecução do mesmo trabalho (Central/Studio → executar novamente), pula o item cujo `id`
341
+ * já deu `succeeded`/`occurrence` — só `failed` roda de novo. `false` processa tudo. Default: true.
342
+ */
343
+ skipDone?: boolean;
314
344
  }
315
345
  /** Totalizadores do `items.each`, pelo desfecho final de cada elemento. */
316
346
  interface RunItemsEachResult {
@@ -318,6 +348,8 @@ interface RunItemsEachResult {
318
348
  succeeded: number;
319
349
  failed: number;
320
350
  occurrence: number;
351
+ /** Já concluídos neste trabalho (reexecução): não rodaram, mas contam no `total`. */
352
+ skipped: number;
321
353
  }
322
354
  type RunItemsEachHandler<T> = (element: T, item: RunItemHandle, index: number) => unknown;
323
355
  /**
@@ -462,4 +494,26 @@ declare const retry: <T>(fn: (attempt: number) => T | Promise<T>, options?: Retr
462
494
  declare const image: (input: AttachInput, options?: ImageOptions) => ImageAttachment;
463
495
  declare const isFileRef: (value: unknown) => value is FileRef;
464
496
 
465
- export { type AttachInput, type CaptureAttachment, type CaptureHint, EnvironmentInput, EventType, type FileDownloadOptions, FileRef, type Hobots, type HobotsOptions, ImageAttachment, type ImageInput, type ImageOptions, type ItemColumnInput, type ItemsOptions, type RegisterOptions, type RetryDelay, type RetryOptions, RunAttachmentContentType, type RunContext, type RunFiles, type RunHandler, type RunItemHandle, type RunItemImageOptions, type RunItemOptions, RunItemStatus, type RunItems, type RunItemsEachHandler, type RunItemsEachOptions, type RunItemsEachResult, type RunLogger, type RunOptions, RunProgress, type RunProgressReporter, type StartOptions, type StepFn, type StepHandle, type StepOptions, captureException, close, hobots as default, hobots, image, isFileRef, register, retry, start };
497
+ /** Erros de controle do ciclo de vida de uma run — identificados pelo `name`, nunca pela classe. */
498
+ /**
499
+ * Ocorrência de negócio lançada de dentro do handler de `hobots.items.each`: o item vira
500
+ * `occurrence` com esta mensagem (e `payload`/`image`, se vierem), a etapa do item vira
501
+ * `warning` e o loop segue — **sem nova tentativa**: o retry do `each` é só para falha
502
+ * técnica (qualquer outro erro). Use para regra de negócio: "nota já cadastrada",
503
+ * "cliente sem pendência", "produto fora do cardápio".
504
+ *
505
+ * throw new Occurrence('nota já cadastrada', { situacao: 'já cadastrada' });
506
+ *
507
+ * Fora do `each` (handler de `register()`/`start()` sem loop) é um erro comum: a run falha
508
+ * com ele como com qualquer outro.
509
+ */
510
+ declare class Occurrence extends Error {
511
+ readonly payload: Record<string, unknown> | undefined;
512
+ /** Print do item (bytes/caminho ou `hobots.image(...)`) — o `each` pendura no item. */
513
+ readonly image: ImageInput | undefined;
514
+ constructor(message: string, payload?: Record<string, unknown>, options?: {
515
+ image?: ImageInput;
516
+ });
517
+ }
518
+
519
+ export { type AttachInput, type CaptureAttachment, type CaptureHint, EnvironmentInput, EventType, type FileDownloadOptions, FileRef, type Hobots, type HobotsOptions, ImageAttachment, type ImageInput, type ImageOptions, type ItemColumnInput, type ItemsOptions, Occurrence, type RegisterOptions, type RetryDelay, type RetryOptions, RunAttachmentContentType, type RunContext, type RunFiles, type RunHandler, type RunItemHandle, type RunItemImageOptions, type RunItemOptions, RunItemStatus, type RunItems, type RunItemsEachHandler, type RunItemsEachOptions, type RunItemsEachResult, type RunLogger, type RunOptions, RunProgress, type RunProgressReporter, type StartOptions, type StepFn, type StepHandle, type StepOptions, captureException, close, hobots as default, hobots, image, isFileRef, register, retry, start };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { RunAttachmentContentType, EnvironmentInput, EventType, FileRef, RunItemStatus, RunProgress } from './protocol.js';
2
- export { Breadcrumb, BreadcrumbLevel, Envelope, EnvelopeItem, Environment, EventPayload, EventUser, ExceptionData, FileDownloadResponse, FileStorage, HeartbeatPayload, InstanceInfo, InstanceMode, ItemColumn, ItemsDeclaration, MachineProcess, MachineSnapshot, PollRequest, PollResponse, RunAttachmentConfirmRequest, RunAttachmentConfirmResponse, RunAttachmentCreateRequest, RunAttachmentCreateResponse, RunCreateRequest, RunCreateResponse, RunDescriptor, RunError, RunItemInput, RunItemsCreateRequest, RunItemsCreateResponse, RunLogEntry, RunLogLevel, RunStartRequest, RunStartResponse, RunStatus, RunUpdateRequest, RunUpdateResponse, RunUpdateStatus, StackFrame, StepData, StepStatus, TransactionPayload } from './protocol.js';
2
+ export { Breadcrumb, BreadcrumbLevel, Envelope, EnvelopeItem, Environment, EventPayload, EventUser, ExceptionData, FileDownloadResponse, FileStorage, HeartbeatPayload, InstanceInfo, InstanceMode, ItemColumn, ItemsDeclaration, MachineProcess, MachineSnapshot, PollRequest, PollResponse, RunAttachmentConfirmRequest, RunAttachmentConfirmResponse, RunAttachmentCreateRequest, RunAttachmentCreateResponse, RunCreateRequest, RunCreateResponse, RunDescriptor, RunError, RunItemInput, RunItemsCreateRequest, RunItemsCreateResponse, RunItemsDoneRequest, RunItemsDoneResponse, RunLogEntry, RunLogLevel, RunStartRequest, RunStartResponse, RunStatus, RunUpdateRequest, RunUpdateResponse, RunUpdateStatus, StackFrame, StepData, StepStatus, TransactionPayload } from './protocol.js';
3
3
 
4
4
  /** Espera entre tentativas: ms fixo ou função do número da tentativa que acabou de falhar (1-based). */
5
5
  type RetryDelay = number | ((attempt: number) => number);
@@ -272,20 +272,32 @@ interface RunItemOptions extends RunItemImageOptions {
272
272
  /**
273
273
  * O item em processamento dentro de `items.each`: o desfecho (`succeeded`/`failed`/
274
274
  * `occurrence`) com o `id` e o payload base já resolvidos, e o handle `step` da etapa do
275
- * item (`warning`/`image`/`data`). Sub-etapas: `hobots.step(...)` dentro do handler já
275
+ * item (`warning`/`image`/`data`), e `data(...)` para ir guardando o payload do item sem
276
+ * decidir o desfecho. Sub-etapas: `hobots.step(...)` dentro do handler já
276
277
  * aninha na etapa do item. Sem chamada explícita, o SDK decide: retornou → `succeeded`;
277
278
  * lançou → `failed` com a mensagem do erro.
278
279
  */
279
280
  interface RunItemHandle {
280
281
  /** Posição do elemento na lista (0-based). */
281
282
  readonly index: number;
282
- /** Identidade de negócio resolvida por `options.id` (undefined = o SDK gera uma). */
283
- readonly id: string | undefined;
283
+ /** Identidade do item: a resolvida por `options.id` ou, sem ela, uma gerada pelo SDK — a mesma em todas as tentativas. */
284
+ readonly id: string;
284
285
  /** Handle da etapa deste item no waterfall de performance; undefined fora de uma execução. */
285
286
  readonly step: StepHandle | undefined;
286
287
  /** true depois do primeiro desfecho registrado (o SDK não sobrescreve o que o handler decidiu). */
287
288
  readonly reported: boolean;
288
- /** Item processado com sucesso. `payload` é mesclado sobre o payload base de `options.payload`. */
289
+ /** Desfecho registrado até agora (undefined = nenhum). */
290
+ readonly status: RunItemStatus | undefined;
291
+ /** Tentativa em curso (1-based) — o handler pode ler para logar. */
292
+ readonly attempt: number;
293
+ /**
294
+ * Guarda atributos do item sem registrar desfecho — vai mesclando a cada chamada (chave repetida:
295
+ * a última vence). Entra em qualquer desfecho, inclusive nos implícitos (handler retornou →
296
+ * `succeeded`; lançou → `failed`), entre o payload base de `options.payload` e o payload da
297
+ * chamada de desfecho. Uma nova tentativa começa do zero. Depois do desfecho só acumula: nada é reenviado.
298
+ */
299
+ data(payload: Record<string, unknown>): void;
300
+ /** Item processado com sucesso. `payload` é mesclado sobre o payload base e o de `item.data`. */
289
301
  succeeded(payload?: Record<string, unknown>, options?: RunItemImageOptions): void;
290
302
  /** Falha sem lançar — o loop segue igual; a etapa vira `error` com o motivo. A imagem vai no item. */
291
303
  failed(message: string, payload?: Record<string, unknown>, options?: RunItemImageOptions): void;
@@ -293,8 +305,14 @@ interface RunItemHandle {
293
305
  occurrence(message: string, payload?: Record<string, unknown>, options?: RunItemImageOptions): void;
294
306
  }
295
307
  interface RunItemsEachOptions<T> {
296
- /** Identidade de negócio do item (ex.: nº do cliente). Omitido/null: o SDK gera um id único. */
297
- id?: (element: T, index: number) => string | number | null | undefined;
308
+ /**
309
+ * Identidade de negócio do item: nome do campo do elemento (`'numero'`), chave composta
310
+ * (`['cnpj', 'competencia']`, juntada com `|`) ou função `(elemento, índice) => id`.
311
+ * Omitido: o campo `id` do elemento, se existir. `null`, ou elemento sem o campo padrão:
312
+ * o SDK gera um id único (e o item nunca é pulado na reexecução). Campo explícito ausente
313
+ * no elemento é erro do bot (lança e interrompe o loop).
314
+ */
315
+ id?: string | readonly string[] | ((element: T, index: number) => string | number | null | undefined) | null;
298
316
  /** Atributos base do item (viram colunas no app) — presentes em qualquer desfecho, inclusive falha. */
299
317
  payload?: (element: T, index: number) => Record<string, unknown> | undefined;
300
318
  /** `op` da etapa de cada item no waterfall. Default: 'item'. */
@@ -311,6 +329,18 @@ interface RunItemsEachOptions<T> {
311
329
  * Central na hora. `false` desliga (tudo sai no envio periódico ou no fim da run). Default: true.
312
330
  */
313
331
  flush?: boolean;
332
+ /**
333
+ * Tentativas extras quando o handler lança (falha técnica). Uma etapa só por elemento,
334
+ * com `data.attempts`. `0` desliga. `Occurrence` nunca é retentada. Default: 1.
335
+ */
336
+ retries?: number;
337
+ /** Espera entre as tentativas: ms fixo ou função da tentativa que falhou (1-based). Default: 5_000. */
338
+ retryDelayMs?: RetryDelay;
339
+ /**
340
+ * Na reexecução do mesmo trabalho (Central/Studio → executar novamente), pula o item cujo `id`
341
+ * já deu `succeeded`/`occurrence` — só `failed` roda de novo. `false` processa tudo. Default: true.
342
+ */
343
+ skipDone?: boolean;
314
344
  }
315
345
  /** Totalizadores do `items.each`, pelo desfecho final de cada elemento. */
316
346
  interface RunItemsEachResult {
@@ -318,6 +348,8 @@ interface RunItemsEachResult {
318
348
  succeeded: number;
319
349
  failed: number;
320
350
  occurrence: number;
351
+ /** Já concluídos neste trabalho (reexecução): não rodaram, mas contam no `total`. */
352
+ skipped: number;
321
353
  }
322
354
  type RunItemsEachHandler<T> = (element: T, item: RunItemHandle, index: number) => unknown;
323
355
  /**
@@ -462,4 +494,26 @@ declare const retry: <T>(fn: (attempt: number) => T | Promise<T>, options?: Retr
462
494
  declare const image: (input: AttachInput, options?: ImageOptions) => ImageAttachment;
463
495
  declare const isFileRef: (value: unknown) => value is FileRef;
464
496
 
465
- export { type AttachInput, type CaptureAttachment, type CaptureHint, EnvironmentInput, EventType, type FileDownloadOptions, FileRef, type Hobots, type HobotsOptions, ImageAttachment, type ImageInput, type ImageOptions, type ItemColumnInput, type ItemsOptions, type RegisterOptions, type RetryDelay, type RetryOptions, RunAttachmentContentType, type RunContext, type RunFiles, type RunHandler, type RunItemHandle, type RunItemImageOptions, type RunItemOptions, RunItemStatus, type RunItems, type RunItemsEachHandler, type RunItemsEachOptions, type RunItemsEachResult, type RunLogger, type RunOptions, RunProgress, type RunProgressReporter, type StartOptions, type StepFn, type StepHandle, type StepOptions, captureException, close, hobots as default, hobots, image, isFileRef, register, retry, start };
497
+ /** Erros de controle do ciclo de vida de uma run — identificados pelo `name`, nunca pela classe. */
498
+ /**
499
+ * Ocorrência de negócio lançada de dentro do handler de `hobots.items.each`: o item vira
500
+ * `occurrence` com esta mensagem (e `payload`/`image`, se vierem), a etapa do item vira
501
+ * `warning` e o loop segue — **sem nova tentativa**: o retry do `each` é só para falha
502
+ * técnica (qualquer outro erro). Use para regra de negócio: "nota já cadastrada",
503
+ * "cliente sem pendência", "produto fora do cardápio".
504
+ *
505
+ * throw new Occurrence('nota já cadastrada', { situacao: 'já cadastrada' });
506
+ *
507
+ * Fora do `each` (handler de `register()`/`start()` sem loop) é um erro comum: a run falha
508
+ * com ele como com qualquer outro.
509
+ */
510
+ declare class Occurrence extends Error {
511
+ readonly payload: Record<string, unknown> | undefined;
512
+ /** Print do item (bytes/caminho ou `hobots.image(...)`) — o `each` pendura no item. */
513
+ readonly image: ImageInput | undefined;
514
+ constructor(message: string, payload?: Record<string, unknown>, options?: {
515
+ image?: ImageInput;
516
+ });
517
+ }
518
+
519
+ export { type AttachInput, type CaptureAttachment, type CaptureHint, EnvironmentInput, EventType, type FileDownloadOptions, FileRef, type Hobots, type HobotsOptions, ImageAttachment, type ImageInput, type ImageOptions, type ItemColumnInput, type ItemsOptions, Occurrence, type RegisterOptions, type RetryDelay, type RetryOptions, RunAttachmentContentType, type RunContext, type RunFiles, type RunHandler, type RunItemHandle, type RunItemImageOptions, type RunItemOptions, RunItemStatus, type RunItems, type RunItemsEachHandler, type RunItemsEachOptions, type RunItemsEachResult, type RunLogger, type RunOptions, RunProgress, type RunProgressReporter, type StartOptions, type StepFn, type StepHandle, type StepOptions, captureException, close, hobots as default, hobots, image, isFileRef, register, retry, start };