@notifica/node 0.1.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/LICENSE +21 -0
- package/README.md +444 -0
- package/dist/index.cjs +1751 -0
- package/dist/index.d.cts +1912 -0
- package/dist/index.d.ts +1912 -0
- package/dist/index.js +1705 -0
- package/package.json +60 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,1912 @@
|
|
|
1
|
+
interface PaginationParams {
|
|
2
|
+
/** Máximo por página (default: 20, max: 100) */
|
|
3
|
+
limit?: number;
|
|
4
|
+
/** Cursor de paginação retornado na resposta anterior */
|
|
5
|
+
cursor?: string;
|
|
6
|
+
}
|
|
7
|
+
interface PaginationMeta {
|
|
8
|
+
cursor: string | null;
|
|
9
|
+
has_more: boolean;
|
|
10
|
+
}
|
|
11
|
+
interface PaginatedResponse<T> {
|
|
12
|
+
data: T[];
|
|
13
|
+
meta: PaginationMeta;
|
|
14
|
+
}
|
|
15
|
+
interface SingleResponse<T> {
|
|
16
|
+
data: T;
|
|
17
|
+
}
|
|
18
|
+
interface ApiErrorBody {
|
|
19
|
+
error: {
|
|
20
|
+
code: string;
|
|
21
|
+
message: string;
|
|
22
|
+
details?: Record<string, string[]>;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
type Channel = 'email' | 'whatsapp' | 'sms' | 'in_app' | 'push';
|
|
26
|
+
type NotificationStatus = 'pending' | 'processing' | 'delivered' | 'failed' | 'bounced' | 'rejected';
|
|
27
|
+
type TemplateStatus = 'draft' | 'active';
|
|
28
|
+
type Environment = 'production' | 'sandbox';
|
|
29
|
+
type ApiKeyType = 'secret' | 'public';
|
|
30
|
+
interface RequestOptions {
|
|
31
|
+
/** Chave de idempotência customizada para requests POST */
|
|
32
|
+
idempotencyKey?: string;
|
|
33
|
+
/** Timeout em milissegundos para esta request específica */
|
|
34
|
+
timeout?: number;
|
|
35
|
+
/** Signal para abortar a request */
|
|
36
|
+
signal?: AbortSignal;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface NotificaClientConfig {
|
|
40
|
+
/** API key (nk_live_..., nk_test_..., pk_live_..., pk_test_...) */
|
|
41
|
+
apiKey: string;
|
|
42
|
+
/** Base URL da API (default: https://app.usenotifica.com.br/v1) */
|
|
43
|
+
baseUrl?: string;
|
|
44
|
+
/** Timeout padrão em ms (default: 30000) */
|
|
45
|
+
timeout?: number;
|
|
46
|
+
/** Máximo de retries em 429/5xx (default: 3) */
|
|
47
|
+
maxRetries?: number;
|
|
48
|
+
/** Gerar idempotency key automaticamente para POSTs (default: true) */
|
|
49
|
+
autoIdempotency?: boolean;
|
|
50
|
+
}
|
|
51
|
+
declare class NotificaClient {
|
|
52
|
+
private readonly apiKey;
|
|
53
|
+
private readonly baseUrl;
|
|
54
|
+
private readonly timeout;
|
|
55
|
+
private readonly maxRetries;
|
|
56
|
+
private readonly autoIdempotency;
|
|
57
|
+
constructor(config: NotificaClientConfig);
|
|
58
|
+
get<T>(path: string, query?: Record<string, unknown>, options?: RequestOptions): Promise<T>;
|
|
59
|
+
post<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
60
|
+
put<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
61
|
+
patch<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
62
|
+
delete<T = void>(path: string, options?: RequestOptions): Promise<T>;
|
|
63
|
+
/**
|
|
64
|
+
* Lista com paginação manual.
|
|
65
|
+
* Retorna { data, meta } com cursor para próxima página.
|
|
66
|
+
*/
|
|
67
|
+
list<T>(path: string, query?: Record<string, unknown>, options?: RequestOptions): Promise<PaginatedResponse<T>>;
|
|
68
|
+
/**
|
|
69
|
+
* Async iterator para auto-paginação.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* for await (const notification of client.paginate<Notification>('/notifications')) {
|
|
74
|
+
* console.log(notification.id);
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
paginate<T>(path: string, query?: Record<string, unknown>): AsyncIterableIterator<T>;
|
|
79
|
+
/**
|
|
80
|
+
* Wrapper para respostas { data: T }.
|
|
81
|
+
*/
|
|
82
|
+
getOne<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
83
|
+
private request;
|
|
84
|
+
private buildUrl;
|
|
85
|
+
private buildHeaders;
|
|
86
|
+
private generateIdempotencyKey;
|
|
87
|
+
private backoff;
|
|
88
|
+
private parseRetryAfter;
|
|
89
|
+
private safeParseJson;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
interface SendNotificationParams {
|
|
93
|
+
/** Canal de entrega */
|
|
94
|
+
channel: Channel;
|
|
95
|
+
/** Destinatário (email, telefone E.164, subscriber_id, etc.) */
|
|
96
|
+
to: string;
|
|
97
|
+
/** Slug do template para renderizar */
|
|
98
|
+
template?: string;
|
|
99
|
+
/** Variáveis para o template ou conteúdo direto */
|
|
100
|
+
data?: Record<string, unknown>;
|
|
101
|
+
/** Metadados arbitrários (não processados) */
|
|
102
|
+
metadata?: Record<string, unknown>;
|
|
103
|
+
}
|
|
104
|
+
interface Notification {
|
|
105
|
+
id: string;
|
|
106
|
+
channel: Channel;
|
|
107
|
+
recipient: string;
|
|
108
|
+
status: NotificationStatus;
|
|
109
|
+
template_id?: string;
|
|
110
|
+
metadata?: Record<string, unknown>;
|
|
111
|
+
created_at: string;
|
|
112
|
+
updated_at?: string;
|
|
113
|
+
}
|
|
114
|
+
interface MessageAttempt {
|
|
115
|
+
id: string;
|
|
116
|
+
attempt_number: number;
|
|
117
|
+
status: string;
|
|
118
|
+
provider_response?: Record<string, unknown>;
|
|
119
|
+
created_at: string;
|
|
120
|
+
}
|
|
121
|
+
interface ListNotificationsParams extends PaginationParams {
|
|
122
|
+
/** Filtrar por status */
|
|
123
|
+
status?: NotificationStatus;
|
|
124
|
+
/** Filtrar por canal */
|
|
125
|
+
channel?: Channel;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
declare class Notifications {
|
|
129
|
+
private readonly client;
|
|
130
|
+
constructor(client: NotificaClient);
|
|
131
|
+
/**
|
|
132
|
+
* Envia uma notificação.
|
|
133
|
+
* A notificação é enfileirada para entrega assíncrona.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* const notification = await notifica.notifications.send({
|
|
138
|
+
* channel: 'whatsapp',
|
|
139
|
+
* to: '+5511999999999',
|
|
140
|
+
* template: 'welcome',
|
|
141
|
+
* data: { name: 'João' },
|
|
142
|
+
* });
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
send(params: SendNotificationParams, options?: RequestOptions): Promise<Notification>;
|
|
146
|
+
/**
|
|
147
|
+
* Lista notificações com paginação.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* const { data, meta } = await notifica.notifications.list({ channel: 'email', limit: 50 });
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
list(params?: ListNotificationsParams, options?: RequestOptions): Promise<PaginatedResponse<Notification>>;
|
|
155
|
+
/**
|
|
156
|
+
* Itera automaticamente por todas as notificações.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* for await (const notification of notifica.notifications.listAll({ channel: 'email' })) {
|
|
161
|
+
* console.log(notification.id);
|
|
162
|
+
* }
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
listAll(params?: Omit<ListNotificationsParams, 'cursor'>): AsyncIterableIterator<Notification>;
|
|
166
|
+
/**
|
|
167
|
+
* Obtém detalhes de uma notificação.
|
|
168
|
+
*/
|
|
169
|
+
get(id: string, options?: RequestOptions): Promise<Notification>;
|
|
170
|
+
/**
|
|
171
|
+
* Lista tentativas de entrega de uma notificação.
|
|
172
|
+
*/
|
|
173
|
+
listAttempts(notificationId: string, options?: RequestOptions): Promise<MessageAttempt[]>;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
interface CreateTemplateParams {
|
|
177
|
+
/** Canal alvo */
|
|
178
|
+
channel: Channel;
|
|
179
|
+
/** Identificador URL-safe */
|
|
180
|
+
slug: string;
|
|
181
|
+
/** Nome legível */
|
|
182
|
+
name: string;
|
|
183
|
+
/** Conteúdo com {{variáveis}} */
|
|
184
|
+
content: string;
|
|
185
|
+
/** Lista de variáveis (auto-extraída se omitida) */
|
|
186
|
+
variables?: string[];
|
|
187
|
+
/** Variantes por canal (subject, html_body, etc.) */
|
|
188
|
+
variants?: Record<string, string>;
|
|
189
|
+
/** Idioma (default: pt_BR) */
|
|
190
|
+
language?: string;
|
|
191
|
+
/** Status (default: draft) */
|
|
192
|
+
status?: TemplateStatus;
|
|
193
|
+
/** Metadados extras */
|
|
194
|
+
metadata?: Record<string, unknown>;
|
|
195
|
+
/** Referência a template externo */
|
|
196
|
+
provider_template_id?: string;
|
|
197
|
+
}
|
|
198
|
+
interface UpdateTemplateParams {
|
|
199
|
+
name?: string;
|
|
200
|
+
content?: string;
|
|
201
|
+
variables?: string[];
|
|
202
|
+
variants?: Record<string, string>;
|
|
203
|
+
language?: string;
|
|
204
|
+
status?: TemplateStatus;
|
|
205
|
+
metadata?: Record<string, unknown>;
|
|
206
|
+
provider_template_id?: string;
|
|
207
|
+
}
|
|
208
|
+
interface Template {
|
|
209
|
+
id: string;
|
|
210
|
+
slug: string;
|
|
211
|
+
name: string;
|
|
212
|
+
channel: Channel;
|
|
213
|
+
content: string;
|
|
214
|
+
variables: string[];
|
|
215
|
+
variants?: Record<string, string>;
|
|
216
|
+
language: string;
|
|
217
|
+
status: TemplateStatus;
|
|
218
|
+
metadata?: Record<string, unknown>;
|
|
219
|
+
provider_template_id?: string;
|
|
220
|
+
created_at: string;
|
|
221
|
+
updated_at: string;
|
|
222
|
+
}
|
|
223
|
+
interface PreviewTemplateParams {
|
|
224
|
+
variables: Record<string, unknown>;
|
|
225
|
+
}
|
|
226
|
+
interface PreviewContentParams {
|
|
227
|
+
content: string;
|
|
228
|
+
channel: Channel;
|
|
229
|
+
variables?: Record<string, unknown>;
|
|
230
|
+
variants?: Record<string, string>;
|
|
231
|
+
}
|
|
232
|
+
interface PreviewResult {
|
|
233
|
+
rendered: Record<string, string>;
|
|
234
|
+
variables: string[];
|
|
235
|
+
validation: ValidationResult;
|
|
236
|
+
}
|
|
237
|
+
interface ValidateContentParams {
|
|
238
|
+
content: string;
|
|
239
|
+
channel: Channel;
|
|
240
|
+
variants?: Record<string, string>;
|
|
241
|
+
}
|
|
242
|
+
interface ValidationResult {
|
|
243
|
+
valid: boolean;
|
|
244
|
+
errors: string[];
|
|
245
|
+
warnings: string[];
|
|
246
|
+
variables?: string[];
|
|
247
|
+
}
|
|
248
|
+
interface ListTemplatesParams extends PaginationParams {
|
|
249
|
+
/** Filtrar por canal */
|
|
250
|
+
channel?: Channel;
|
|
251
|
+
/** Filtrar por status */
|
|
252
|
+
status?: TemplateStatus;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
declare class Templates {
|
|
256
|
+
private readonly client;
|
|
257
|
+
constructor(client: NotificaClient);
|
|
258
|
+
/**
|
|
259
|
+
* Cria um novo template.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```ts
|
|
263
|
+
* const template = await notifica.templates.create({
|
|
264
|
+
* channel: 'email',
|
|
265
|
+
* slug: 'welcome-email',
|
|
266
|
+
* name: 'Email de Boas-Vindas',
|
|
267
|
+
* content: 'Olá {{name}}, bem-vindo!',
|
|
268
|
+
* });
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
create(params: CreateTemplateParams, options?: RequestOptions): Promise<Template>;
|
|
272
|
+
/**
|
|
273
|
+
* Lista templates com paginação.
|
|
274
|
+
*/
|
|
275
|
+
list(params?: ListTemplatesParams, options?: RequestOptions): Promise<PaginatedResponse<Template>>;
|
|
276
|
+
/**
|
|
277
|
+
* Itera automaticamente por todos os templates.
|
|
278
|
+
*/
|
|
279
|
+
listAll(params?: Omit<ListTemplatesParams, 'cursor'>): AsyncIterableIterator<Template>;
|
|
280
|
+
/**
|
|
281
|
+
* Obtém detalhes de um template.
|
|
282
|
+
*/
|
|
283
|
+
get(id: string, options?: RequestOptions): Promise<Template>;
|
|
284
|
+
/**
|
|
285
|
+
* Atualiza um template.
|
|
286
|
+
*/
|
|
287
|
+
update(id: string, params: UpdateTemplateParams, options?: RequestOptions): Promise<Template>;
|
|
288
|
+
/**
|
|
289
|
+
* Deleta um template.
|
|
290
|
+
*/
|
|
291
|
+
delete(id: string, options?: RequestOptions): Promise<void>;
|
|
292
|
+
/**
|
|
293
|
+
* Preview de um template salvo com variáveis.
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```ts
|
|
297
|
+
* const preview = await notifica.templates.preview('tpl_abc', {
|
|
298
|
+
* variables: { name: 'João' },
|
|
299
|
+
* });
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
preview(id: string, params: PreviewTemplateParams, options?: RequestOptions): Promise<PreviewResult>;
|
|
303
|
+
/**
|
|
304
|
+
* Preview de conteúdo arbitrário (útil para editor em tempo real).
|
|
305
|
+
*/
|
|
306
|
+
previewContent(params: PreviewContentParams, options?: RequestOptions): Promise<PreviewResult>;
|
|
307
|
+
/**
|
|
308
|
+
* Valida um template salvo.
|
|
309
|
+
*/
|
|
310
|
+
validate(id: string, options?: RequestOptions): Promise<ValidationResult>;
|
|
311
|
+
/**
|
|
312
|
+
* Valida conteúdo arbitrário.
|
|
313
|
+
*/
|
|
314
|
+
validateContent(params: ValidateContentParams, options?: RequestOptions): Promise<ValidationResult>;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
interface SendStep {
|
|
318
|
+
type: 'send';
|
|
319
|
+
channel: Channel;
|
|
320
|
+
template: string;
|
|
321
|
+
}
|
|
322
|
+
interface DelayStep {
|
|
323
|
+
type: 'delay';
|
|
324
|
+
/** Duração no formato "5m", "1h", "1d" */
|
|
325
|
+
duration: string;
|
|
326
|
+
}
|
|
327
|
+
interface FallbackStep {
|
|
328
|
+
type: 'fallback';
|
|
329
|
+
channels: Channel[];
|
|
330
|
+
template: string;
|
|
331
|
+
}
|
|
332
|
+
type WorkflowStep = SendStep | DelayStep | FallbackStep;
|
|
333
|
+
interface CreateWorkflowParams {
|
|
334
|
+
/** Identificador URL-safe */
|
|
335
|
+
slug: string;
|
|
336
|
+
/** Nome legível */
|
|
337
|
+
name: string;
|
|
338
|
+
/** Passos do workflow (max 10) */
|
|
339
|
+
steps: WorkflowStep[];
|
|
340
|
+
}
|
|
341
|
+
interface UpdateWorkflowParams {
|
|
342
|
+
name?: string;
|
|
343
|
+
steps?: WorkflowStep[];
|
|
344
|
+
}
|
|
345
|
+
interface Workflow {
|
|
346
|
+
id: string;
|
|
347
|
+
slug: string;
|
|
348
|
+
name: string;
|
|
349
|
+
steps: WorkflowStep[];
|
|
350
|
+
version: number;
|
|
351
|
+
active: boolean;
|
|
352
|
+
created_at: string;
|
|
353
|
+
updated_at: string;
|
|
354
|
+
}
|
|
355
|
+
interface TriggerWorkflowParams {
|
|
356
|
+
/** Destinatário (email, telefone, subscriber_id) */
|
|
357
|
+
recipient: string;
|
|
358
|
+
/** Variáveis do template */
|
|
359
|
+
data?: Record<string, unknown>;
|
|
360
|
+
}
|
|
361
|
+
type WorkflowRunStatus = 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
362
|
+
interface WorkflowRun {
|
|
363
|
+
id: string;
|
|
364
|
+
workflow_id: string;
|
|
365
|
+
workflow_slug: string;
|
|
366
|
+
workflow_version: number;
|
|
367
|
+
status: WorkflowRunStatus;
|
|
368
|
+
recipient: string;
|
|
369
|
+
data?: Record<string, unknown>;
|
|
370
|
+
step_results?: StepResult[];
|
|
371
|
+
created_at: string;
|
|
372
|
+
updated_at: string;
|
|
373
|
+
}
|
|
374
|
+
interface StepResult {
|
|
375
|
+
step_index: number;
|
|
376
|
+
step_type: string;
|
|
377
|
+
status: string;
|
|
378
|
+
result?: Record<string, unknown>;
|
|
379
|
+
executed_at: string;
|
|
380
|
+
}
|
|
381
|
+
interface ListWorkflowsParams extends PaginationParams {
|
|
382
|
+
}
|
|
383
|
+
interface ListWorkflowRunsParams extends PaginationParams {
|
|
384
|
+
/** Filtrar por workflow_id */
|
|
385
|
+
workflow_id?: string;
|
|
386
|
+
/** Filtrar por status */
|
|
387
|
+
status?: WorkflowRunStatus;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
declare class Workflows {
|
|
391
|
+
private readonly client;
|
|
392
|
+
constructor(client: NotificaClient);
|
|
393
|
+
/**
|
|
394
|
+
* Cria um novo workflow.
|
|
395
|
+
*
|
|
396
|
+
* @example
|
|
397
|
+
* ```ts
|
|
398
|
+
* const workflow = await notifica.workflows.create({
|
|
399
|
+
* slug: 'welcome-flow',
|
|
400
|
+
* name: 'Fluxo de Boas-Vindas',
|
|
401
|
+
* steps: [
|
|
402
|
+
* { type: 'send', channel: 'email', template: 'welcome-email' },
|
|
403
|
+
* { type: 'delay', duration: '1h' },
|
|
404
|
+
* { type: 'send', channel: 'whatsapp', template: 'welcome-whatsapp' },
|
|
405
|
+
* ],
|
|
406
|
+
* });
|
|
407
|
+
* ```
|
|
408
|
+
*/
|
|
409
|
+
create(params: CreateWorkflowParams, options?: RequestOptions): Promise<Workflow>;
|
|
410
|
+
/**
|
|
411
|
+
* Lista workflows com paginação.
|
|
412
|
+
*/
|
|
413
|
+
list(params?: ListWorkflowsParams, options?: RequestOptions): Promise<PaginatedResponse<Workflow>>;
|
|
414
|
+
/**
|
|
415
|
+
* Itera automaticamente por todos os workflows.
|
|
416
|
+
*/
|
|
417
|
+
listAll(params?: Omit<ListWorkflowsParams, 'cursor'>): AsyncIterableIterator<Workflow>;
|
|
418
|
+
/**
|
|
419
|
+
* Obtém detalhes de um workflow.
|
|
420
|
+
*/
|
|
421
|
+
get(id: string, options?: RequestOptions): Promise<Workflow>;
|
|
422
|
+
/**
|
|
423
|
+
* Atualiza um workflow (cria nova versão).
|
|
424
|
+
*/
|
|
425
|
+
update(id: string, params: UpdateWorkflowParams, options?: RequestOptions): Promise<Workflow>;
|
|
426
|
+
/**
|
|
427
|
+
* Deleta um workflow (soft delete).
|
|
428
|
+
*/
|
|
429
|
+
delete(id: string, options?: RequestOptions): Promise<void>;
|
|
430
|
+
/**
|
|
431
|
+
* Dispara a execução de um workflow.
|
|
432
|
+
*
|
|
433
|
+
* @param slug — Slug do workflow
|
|
434
|
+
* @param params — Recipient e dados
|
|
435
|
+
*
|
|
436
|
+
* @example
|
|
437
|
+
* ```ts
|
|
438
|
+
* const run = await notifica.workflows.trigger('welcome-flow', {
|
|
439
|
+
* recipient: '+5511999999999',
|
|
440
|
+
* data: { name: 'João', plan: 'pro' },
|
|
441
|
+
* });
|
|
442
|
+
* ```
|
|
443
|
+
*/
|
|
444
|
+
trigger(slug: string, params: TriggerWorkflowParams, options?: RequestOptions): Promise<WorkflowRun>;
|
|
445
|
+
/**
|
|
446
|
+
* Lista execuções de workflows.
|
|
447
|
+
*/
|
|
448
|
+
listRuns(params?: ListWorkflowRunsParams, options?: RequestOptions): Promise<PaginatedResponse<WorkflowRun>>;
|
|
449
|
+
/**
|
|
450
|
+
* Obtém detalhes de uma execução (incluindo step_results).
|
|
451
|
+
*/
|
|
452
|
+
getRun(id: string, options?: RequestOptions): Promise<WorkflowRun>;
|
|
453
|
+
/**
|
|
454
|
+
* Cancela uma execução em andamento.
|
|
455
|
+
*/
|
|
456
|
+
cancelRun(id: string, options?: RequestOptions): Promise<WorkflowRun>;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
interface CreateSubscriberParams {
|
|
460
|
+
/** Seu identificador do usuário (upsert key) */
|
|
461
|
+
external_id: string;
|
|
462
|
+
/** Email do subscriber */
|
|
463
|
+
email?: string;
|
|
464
|
+
/** Telefone E.164 (ex: +5511999998888) */
|
|
465
|
+
phone?: string;
|
|
466
|
+
/** Nome de exibição */
|
|
467
|
+
name?: string;
|
|
468
|
+
/** Locale preferido */
|
|
469
|
+
locale?: string;
|
|
470
|
+
/** Timezone preferida */
|
|
471
|
+
timezone?: string;
|
|
472
|
+
/** Dados customizados */
|
|
473
|
+
custom_properties?: Record<string, unknown>;
|
|
474
|
+
}
|
|
475
|
+
interface UpdateSubscriberParams {
|
|
476
|
+
email?: string;
|
|
477
|
+
phone?: string;
|
|
478
|
+
name?: string;
|
|
479
|
+
locale?: string;
|
|
480
|
+
timezone?: string;
|
|
481
|
+
custom_properties?: Record<string, unknown>;
|
|
482
|
+
}
|
|
483
|
+
interface Subscriber {
|
|
484
|
+
id: string;
|
|
485
|
+
external_id: string;
|
|
486
|
+
email?: string;
|
|
487
|
+
phone?: string;
|
|
488
|
+
name?: string;
|
|
489
|
+
locale?: string;
|
|
490
|
+
timezone?: string;
|
|
491
|
+
custom_properties?: Record<string, unknown>;
|
|
492
|
+
created_at: string;
|
|
493
|
+
updated_at: string;
|
|
494
|
+
}
|
|
495
|
+
interface NotificationPreference {
|
|
496
|
+
category: string;
|
|
497
|
+
channel: string;
|
|
498
|
+
enabled: boolean;
|
|
499
|
+
}
|
|
500
|
+
interface UpdatePreferencesParams {
|
|
501
|
+
preferences: NotificationPreference[];
|
|
502
|
+
}
|
|
503
|
+
interface SubscriberPreferences {
|
|
504
|
+
preferences: NotificationPreference[];
|
|
505
|
+
}
|
|
506
|
+
interface BulkImportParams {
|
|
507
|
+
subscribers: CreateSubscriberParams[];
|
|
508
|
+
}
|
|
509
|
+
interface BulkImportResult {
|
|
510
|
+
imported: number;
|
|
511
|
+
subscribers: Subscriber[];
|
|
512
|
+
}
|
|
513
|
+
interface InAppNotification {
|
|
514
|
+
id: string;
|
|
515
|
+
title?: string;
|
|
516
|
+
body?: string;
|
|
517
|
+
action_url?: string;
|
|
518
|
+
read: boolean;
|
|
519
|
+
created_at: string;
|
|
520
|
+
}
|
|
521
|
+
interface ListInAppParams {
|
|
522
|
+
limit?: number;
|
|
523
|
+
offset?: number;
|
|
524
|
+
unread_only?: boolean;
|
|
525
|
+
}
|
|
526
|
+
interface UnreadCountResult {
|
|
527
|
+
count: number;
|
|
528
|
+
}
|
|
529
|
+
interface ListSubscribersParams extends PaginationParams {
|
|
530
|
+
/** Busca por email, nome ou external_id */
|
|
531
|
+
search?: string;
|
|
532
|
+
/** Offset de paginação */
|
|
533
|
+
offset?: number;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
declare class Subscribers {
|
|
537
|
+
private readonly client;
|
|
538
|
+
constructor(client: NotificaClient);
|
|
539
|
+
/**
|
|
540
|
+
* Cria ou atualiza um subscriber (upsert por external_id).
|
|
541
|
+
* LGPD: registra consentimento automaticamente.
|
|
542
|
+
*
|
|
543
|
+
* @example
|
|
544
|
+
* ```ts
|
|
545
|
+
* const subscriber = await notifica.subscribers.create({
|
|
546
|
+
* external_id: 'user-123',
|
|
547
|
+
* email: 'joao@empresa.com.br',
|
|
548
|
+
* phone: '+5511999998888',
|
|
549
|
+
* name: 'João Silva',
|
|
550
|
+
* });
|
|
551
|
+
* ```
|
|
552
|
+
*/
|
|
553
|
+
create(params: CreateSubscriberParams, options?: RequestOptions): Promise<Subscriber>;
|
|
554
|
+
/**
|
|
555
|
+
* Lista subscribers com paginação.
|
|
556
|
+
*/
|
|
557
|
+
list(params?: ListSubscribersParams, options?: RequestOptions): Promise<PaginatedResponse<Subscriber>>;
|
|
558
|
+
/**
|
|
559
|
+
* Itera automaticamente por todos os subscribers.
|
|
560
|
+
*/
|
|
561
|
+
listAll(params?: Omit<ListSubscribersParams, 'cursor'>): AsyncIterableIterator<Subscriber>;
|
|
562
|
+
/**
|
|
563
|
+
* Obtém detalhes de um subscriber.
|
|
564
|
+
*/
|
|
565
|
+
get(id: string, options?: RequestOptions): Promise<Subscriber>;
|
|
566
|
+
/**
|
|
567
|
+
* Atualiza um subscriber.
|
|
568
|
+
*/
|
|
569
|
+
update(id: string, params: UpdateSubscriberParams, options?: RequestOptions): Promise<Subscriber>;
|
|
570
|
+
/**
|
|
571
|
+
* Deleta um subscriber (soft delete com nullificação de PII — LGPD).
|
|
572
|
+
* ⚠️ Irreversível: email, telefone e nome são removidos.
|
|
573
|
+
*/
|
|
574
|
+
delete(id: string, options?: RequestOptions): Promise<void>;
|
|
575
|
+
/**
|
|
576
|
+
* Obtém preferências de notificação do subscriber.
|
|
577
|
+
*/
|
|
578
|
+
getPreferences(id: string, options?: RequestOptions): Promise<SubscriberPreferences>;
|
|
579
|
+
/**
|
|
580
|
+
* Atualiza preferências de notificação do subscriber.
|
|
581
|
+
*
|
|
582
|
+
* @example
|
|
583
|
+
* ```ts
|
|
584
|
+
* await notifica.subscribers.updatePreferences('sub_123', {
|
|
585
|
+
* preferences: [
|
|
586
|
+
* { category: 'marketing', channel: 'email', enabled: false },
|
|
587
|
+
* { category: 'transactional', channel: 'whatsapp', enabled: true },
|
|
588
|
+
* ],
|
|
589
|
+
* });
|
|
590
|
+
* ```
|
|
591
|
+
*/
|
|
592
|
+
updatePreferences(id: string, params: UpdatePreferencesParams, options?: RequestOptions): Promise<SubscriberPreferences>;
|
|
593
|
+
/**
|
|
594
|
+
* Importa subscribers em lote (upsert transacional).
|
|
595
|
+
* Se um subscriber falhar validação, todo o lote é revertido.
|
|
596
|
+
*/
|
|
597
|
+
bulkImport(params: BulkImportParams, options?: RequestOptions): Promise<BulkImportResult>;
|
|
598
|
+
/**
|
|
599
|
+
* Lista notificações in-app de um subscriber.
|
|
600
|
+
*/
|
|
601
|
+
listNotifications(subscriberId: string, params?: ListInAppParams, options?: RequestOptions): Promise<{
|
|
602
|
+
data: InAppNotification[];
|
|
603
|
+
}>;
|
|
604
|
+
/**
|
|
605
|
+
* Marca uma notificação in-app como lida.
|
|
606
|
+
*/
|
|
607
|
+
markRead(subscriberId: string, notificationId: string, options?: RequestOptions): Promise<void>;
|
|
608
|
+
/**
|
|
609
|
+
* Marca todas as notificações in-app como lidas.
|
|
610
|
+
*/
|
|
611
|
+
markAllRead(subscriberId: string, options?: RequestOptions): Promise<void>;
|
|
612
|
+
/**
|
|
613
|
+
* Obtém contagem de notificações não lidas.
|
|
614
|
+
*/
|
|
615
|
+
getUnreadCount(subscriberId: string, options?: RequestOptions): Promise<number>;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
interface CreateChannelParams {
|
|
619
|
+
/** Nome do canal */
|
|
620
|
+
channel: Channel;
|
|
621
|
+
/** Provider (ex: aws_ses, twilio, meta) */
|
|
622
|
+
provider: string;
|
|
623
|
+
/** Credenciais criptografadas */
|
|
624
|
+
credentials: Record<string, unknown>;
|
|
625
|
+
/** Configurações (from_address, from_name, etc.) */
|
|
626
|
+
settings?: Record<string, unknown>;
|
|
627
|
+
}
|
|
628
|
+
interface UpdateChannelParams {
|
|
629
|
+
provider?: string;
|
|
630
|
+
credentials?: Record<string, unknown>;
|
|
631
|
+
settings?: Record<string, unknown>;
|
|
632
|
+
}
|
|
633
|
+
interface ChannelConfiguration {
|
|
634
|
+
id: string;
|
|
635
|
+
channel: Channel;
|
|
636
|
+
provider: string;
|
|
637
|
+
/** Credenciais nunca são retornadas na resposta */
|
|
638
|
+
settings?: Record<string, unknown>;
|
|
639
|
+
created_at: string;
|
|
640
|
+
updated_at: string;
|
|
641
|
+
}
|
|
642
|
+
interface TestChannelResult {
|
|
643
|
+
success: boolean;
|
|
644
|
+
message: string;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
declare class Channels {
|
|
648
|
+
private readonly client;
|
|
649
|
+
constructor(client: NotificaClient);
|
|
650
|
+
/**
|
|
651
|
+
* Configura um canal de notificação.
|
|
652
|
+
*
|
|
653
|
+
* @example
|
|
654
|
+
* ```ts
|
|
655
|
+
* const channel = await notifica.channels.create({
|
|
656
|
+
* channel: 'email',
|
|
657
|
+
* provider: 'aws_ses',
|
|
658
|
+
* credentials: {
|
|
659
|
+
* access_key_id: 'AKIA...',
|
|
660
|
+
* secret_access_key: '...',
|
|
661
|
+
* region: 'us-east-1',
|
|
662
|
+
* },
|
|
663
|
+
* settings: {
|
|
664
|
+
* from_address: 'noreply@empresa.com.br',
|
|
665
|
+
* from_name: 'Empresa',
|
|
666
|
+
* },
|
|
667
|
+
* });
|
|
668
|
+
* ```
|
|
669
|
+
*/
|
|
670
|
+
create(params: CreateChannelParams, options?: RequestOptions): Promise<ChannelConfiguration>;
|
|
671
|
+
/**
|
|
672
|
+
* Lista todas as configurações de canal.
|
|
673
|
+
*/
|
|
674
|
+
list(options?: RequestOptions): Promise<ChannelConfiguration[]>;
|
|
675
|
+
/**
|
|
676
|
+
* Obtém a configuração de um canal específico.
|
|
677
|
+
*/
|
|
678
|
+
get(channel: Channel, options?: RequestOptions): Promise<ChannelConfiguration>;
|
|
679
|
+
/**
|
|
680
|
+
* Atualiza a configuração de um canal.
|
|
681
|
+
*/
|
|
682
|
+
update(channel: Channel, params: UpdateChannelParams, options?: RequestOptions): Promise<ChannelConfiguration>;
|
|
683
|
+
/**
|
|
684
|
+
* Remove a configuração de um canal.
|
|
685
|
+
*/
|
|
686
|
+
delete(channel: Channel, options?: RequestOptions): Promise<void>;
|
|
687
|
+
/**
|
|
688
|
+
* Envia uma notificação de teste usando a configuração atual do canal.
|
|
689
|
+
*/
|
|
690
|
+
test(channel: Channel, options?: RequestOptions): Promise<TestChannelResult>;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
interface CreateDomainParams {
|
|
694
|
+
domain: string;
|
|
695
|
+
}
|
|
696
|
+
type DomainStatus = 'pending' | 'verified' | 'failed';
|
|
697
|
+
interface DnsRecord {
|
|
698
|
+
name: string;
|
|
699
|
+
type: string;
|
|
700
|
+
value: string;
|
|
701
|
+
}
|
|
702
|
+
interface Domain {
|
|
703
|
+
id: string;
|
|
704
|
+
domain: string;
|
|
705
|
+
status: DomainStatus;
|
|
706
|
+
dns_records?: {
|
|
707
|
+
txt?: DnsRecord;
|
|
708
|
+
dkim?: DnsRecord[];
|
|
709
|
+
spf?: DnsRecord;
|
|
710
|
+
};
|
|
711
|
+
verified_at?: string;
|
|
712
|
+
created_at: string;
|
|
713
|
+
updated_at: string;
|
|
714
|
+
}
|
|
715
|
+
interface DomainHealth {
|
|
716
|
+
domain_id: string;
|
|
717
|
+
dns_valid: boolean;
|
|
718
|
+
dkim_valid: boolean;
|
|
719
|
+
spf_valid: boolean;
|
|
720
|
+
last_checked_at: string;
|
|
721
|
+
issues?: string[];
|
|
722
|
+
}
|
|
723
|
+
interface DomainAlert {
|
|
724
|
+
id: string;
|
|
725
|
+
domain_id: string;
|
|
726
|
+
alert_type: string;
|
|
727
|
+
message: string;
|
|
728
|
+
severity: string;
|
|
729
|
+
created_at: string;
|
|
730
|
+
}
|
|
731
|
+
interface ListDomainsParams extends PaginationParams {
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
declare class Domains {
|
|
735
|
+
private readonly client;
|
|
736
|
+
constructor(client: NotificaClient);
|
|
737
|
+
/**
|
|
738
|
+
* Registra um novo domínio de envio.
|
|
739
|
+
*
|
|
740
|
+
* @example
|
|
741
|
+
* ```ts
|
|
742
|
+
* const domain = await notifica.domains.create({ domain: 'suaempresa.com.br' });
|
|
743
|
+
* // Configure os registros DNS retornados em domain.dns_records
|
|
744
|
+
* ```
|
|
745
|
+
*/
|
|
746
|
+
create(params: CreateDomainParams, options?: RequestOptions): Promise<Domain>;
|
|
747
|
+
/**
|
|
748
|
+
* Lista domínios registrados.
|
|
749
|
+
*/
|
|
750
|
+
list(params?: ListDomainsParams, options?: RequestOptions): Promise<PaginatedResponse<Domain>>;
|
|
751
|
+
/**
|
|
752
|
+
* Obtém detalhes de um domínio.
|
|
753
|
+
*/
|
|
754
|
+
get(id: string, options?: RequestOptions): Promise<Domain>;
|
|
755
|
+
/**
|
|
756
|
+
* Dispara verificação DNS do domínio.
|
|
757
|
+
*/
|
|
758
|
+
verify(id: string, options?: RequestOptions): Promise<Domain>;
|
|
759
|
+
/**
|
|
760
|
+
* Remove um domínio.
|
|
761
|
+
*/
|
|
762
|
+
delete(id: string, options?: RequestOptions): Promise<void>;
|
|
763
|
+
/**
|
|
764
|
+
* Obtém status de saúde do domínio.
|
|
765
|
+
*/
|
|
766
|
+
getHealth(domainId: string, options?: RequestOptions): Promise<DomainHealth>;
|
|
767
|
+
/**
|
|
768
|
+
* Força verificação de saúde (rate limit: 1/min).
|
|
769
|
+
*/
|
|
770
|
+
checkHealth(domainId: string, options?: RequestOptions): Promise<DomainHealth>;
|
|
771
|
+
/**
|
|
772
|
+
* Lista alertas de domínio.
|
|
773
|
+
*/
|
|
774
|
+
listAlerts(options?: RequestOptions): Promise<DomainAlert[]>;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
interface CreateWebhookParams {
|
|
778
|
+
/** URL de destino */
|
|
779
|
+
url: string;
|
|
780
|
+
/** Lista de eventos para escutar */
|
|
781
|
+
events: string[];
|
|
782
|
+
}
|
|
783
|
+
interface UpdateWebhookParams {
|
|
784
|
+
url?: string;
|
|
785
|
+
events?: string[];
|
|
786
|
+
active?: boolean;
|
|
787
|
+
}
|
|
788
|
+
interface Webhook {
|
|
789
|
+
id: string;
|
|
790
|
+
url: string;
|
|
791
|
+
events: string[];
|
|
792
|
+
active: boolean;
|
|
793
|
+
/** Retornado apenas na criação */
|
|
794
|
+
signing_secret?: string;
|
|
795
|
+
created_at: string;
|
|
796
|
+
updated_at: string;
|
|
797
|
+
}
|
|
798
|
+
interface WebhookDelivery {
|
|
799
|
+
id: string;
|
|
800
|
+
event: string;
|
|
801
|
+
status: string;
|
|
802
|
+
status_code?: number;
|
|
803
|
+
response_body?: string;
|
|
804
|
+
created_at: string;
|
|
805
|
+
}
|
|
806
|
+
interface ListWebhooksParams extends PaginationParams {
|
|
807
|
+
}
|
|
808
|
+
interface ListDeliveriesParams {
|
|
809
|
+
limit?: number;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
declare class Webhooks {
|
|
813
|
+
private readonly client;
|
|
814
|
+
constructor(client: NotificaClient);
|
|
815
|
+
/**
|
|
816
|
+
* Cria um novo webhook.
|
|
817
|
+
* ⚠️ O signing_secret é retornado apenas na criação. Salve-o!
|
|
818
|
+
*
|
|
819
|
+
* @example
|
|
820
|
+
* ```ts
|
|
821
|
+
* const webhook = await notifica.webhooks.create({
|
|
822
|
+
* url: 'https://meuapp.com.br/webhooks/notifica',
|
|
823
|
+
* events: ['notification.delivered', 'notification.failed'],
|
|
824
|
+
* });
|
|
825
|
+
* // Salve: webhook.signing_secret
|
|
826
|
+
* ```
|
|
827
|
+
*/
|
|
828
|
+
create(params: CreateWebhookParams, options?: RequestOptions): Promise<Webhook>;
|
|
829
|
+
/**
|
|
830
|
+
* Lista webhooks com paginação.
|
|
831
|
+
*/
|
|
832
|
+
list(params?: ListWebhooksParams, options?: RequestOptions): Promise<PaginatedResponse<Webhook>>;
|
|
833
|
+
/**
|
|
834
|
+
* Obtém detalhes de um webhook.
|
|
835
|
+
*/
|
|
836
|
+
get(id: string, options?: RequestOptions): Promise<Webhook>;
|
|
837
|
+
/**
|
|
838
|
+
* Atualiza um webhook.
|
|
839
|
+
*/
|
|
840
|
+
update(id: string, params: UpdateWebhookParams, options?: RequestOptions): Promise<Webhook>;
|
|
841
|
+
/**
|
|
842
|
+
* Deleta um webhook.
|
|
843
|
+
*/
|
|
844
|
+
delete(id: string, options?: RequestOptions): Promise<void>;
|
|
845
|
+
/**
|
|
846
|
+
* Envia um evento de teste para o webhook.
|
|
847
|
+
*/
|
|
848
|
+
test(id: string, options?: RequestOptions): Promise<void>;
|
|
849
|
+
/**
|
|
850
|
+
* Lista entregas recentes de um webhook.
|
|
851
|
+
*/
|
|
852
|
+
listDeliveries(id: string, params?: ListDeliveriesParams, options?: RequestOptions): Promise<WebhookDelivery[]>;
|
|
853
|
+
/**
|
|
854
|
+
* Verifica a assinatura HMAC de um payload de webhook.
|
|
855
|
+
*
|
|
856
|
+
* Use para validar que o payload foi realmente enviado pelo Notifica.
|
|
857
|
+
*
|
|
858
|
+
* @param payload — Body da request (string ou Buffer)
|
|
859
|
+
* @param signature — Valor do header `X-Notifica-Signature`
|
|
860
|
+
* @param secret — signing_secret do webhook
|
|
861
|
+
* @returns true se a assinatura é válida
|
|
862
|
+
*
|
|
863
|
+
* @example
|
|
864
|
+
* ```ts
|
|
865
|
+
* app.post('/webhooks/notifica', (req, res) => {
|
|
866
|
+
* const payload = req.body; // raw body string
|
|
867
|
+
* const signature = req.headers['x-notifica-signature'];
|
|
868
|
+
* const secret = process.env.WEBHOOK_SECRET;
|
|
869
|
+
*
|
|
870
|
+
* if (!notifica.webhooks.verify(payload, signature, secret)) {
|
|
871
|
+
* return res.status(401).send('Invalid signature');
|
|
872
|
+
* }
|
|
873
|
+
*
|
|
874
|
+
* // Processar evento...
|
|
875
|
+
* res.status(200).send('OK');
|
|
876
|
+
* });
|
|
877
|
+
* ```
|
|
878
|
+
*/
|
|
879
|
+
verify(payload: string | ArrayBuffer | Uint8Array, signature: string, secret: string): Promise<boolean>;
|
|
880
|
+
/**
|
|
881
|
+
* Verifica a assinatura e lança erro se inválida.
|
|
882
|
+
* Versão "fail-fast" do verify().
|
|
883
|
+
*/
|
|
884
|
+
verifyOrThrow(payload: string | ArrayBuffer | Uint8Array, signature: string, secret: string): Promise<void>;
|
|
885
|
+
private toHex;
|
|
886
|
+
/**
|
|
887
|
+
* Constant-time string comparison to prevent timing attacks.
|
|
888
|
+
*/
|
|
889
|
+
private timingSafeEqual;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
interface CreateApiKeyParams {
|
|
893
|
+
key_type: ApiKeyType;
|
|
894
|
+
label: string;
|
|
895
|
+
environment: Environment;
|
|
896
|
+
}
|
|
897
|
+
interface ApiKey {
|
|
898
|
+
id: string;
|
|
899
|
+
key_type: ApiKeyType;
|
|
900
|
+
label: string;
|
|
901
|
+
prefix: string;
|
|
902
|
+
environment: Environment;
|
|
903
|
+
/** Retornado apenas na criação */
|
|
904
|
+
raw_key?: string;
|
|
905
|
+
created_at: string;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
declare class ApiKeys {
|
|
909
|
+
private readonly client;
|
|
910
|
+
constructor(client: NotificaClient);
|
|
911
|
+
/**
|
|
912
|
+
* Cria uma nova API key.
|
|
913
|
+
* ⚠️ O raw_key é retornado apenas na criação. Salve-o!
|
|
914
|
+
*
|
|
915
|
+
* @example
|
|
916
|
+
* ```ts
|
|
917
|
+
* const key = await notifica.apiKeys.create({
|
|
918
|
+
* key_type: 'secret',
|
|
919
|
+
* label: 'Backend Production',
|
|
920
|
+
* environment: 'production',
|
|
921
|
+
* });
|
|
922
|
+
* // Salve: key.raw_key
|
|
923
|
+
* ```
|
|
924
|
+
*/
|
|
925
|
+
create(params: CreateApiKeyParams, options?: RequestOptions): Promise<ApiKey>;
|
|
926
|
+
/**
|
|
927
|
+
* Lista API keys (sem raw_key).
|
|
928
|
+
*/
|
|
929
|
+
list(options?: RequestOptions): Promise<ApiKey[]>;
|
|
930
|
+
/**
|
|
931
|
+
* Revoga (deleta) uma API key.
|
|
932
|
+
*/
|
|
933
|
+
revoke(id: string, options?: RequestOptions): Promise<void>;
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
type AnalyticsPeriod = '1h' | '24h' | '7d' | '30d';
|
|
937
|
+
type Granularity = 'hour' | 'day';
|
|
938
|
+
interface AnalyticsParams {
|
|
939
|
+
period?: AnalyticsPeriod;
|
|
940
|
+
}
|
|
941
|
+
interface TimeseriesParams extends AnalyticsParams {
|
|
942
|
+
granularity?: Granularity;
|
|
943
|
+
}
|
|
944
|
+
interface TopTemplatesParams extends AnalyticsParams {
|
|
945
|
+
limit?: number;
|
|
946
|
+
}
|
|
947
|
+
interface AnalyticsOverview {
|
|
948
|
+
total_sent: number;
|
|
949
|
+
total_delivered: number;
|
|
950
|
+
total_failed: number;
|
|
951
|
+
delivery_rate: number;
|
|
952
|
+
period: AnalyticsPeriod;
|
|
953
|
+
}
|
|
954
|
+
interface ChannelAnalytics {
|
|
955
|
+
channel: string;
|
|
956
|
+
sent: number;
|
|
957
|
+
delivered: number;
|
|
958
|
+
failed: number;
|
|
959
|
+
delivery_rate: number;
|
|
960
|
+
}
|
|
961
|
+
interface TimeseriesPoint {
|
|
962
|
+
timestamp: string;
|
|
963
|
+
sent: number;
|
|
964
|
+
delivered: number;
|
|
965
|
+
failed: number;
|
|
966
|
+
}
|
|
967
|
+
interface TemplateAnalytics {
|
|
968
|
+
template_id: string;
|
|
969
|
+
template_name: string;
|
|
970
|
+
sent: number;
|
|
971
|
+
delivered: number;
|
|
972
|
+
delivery_rate: number;
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
declare class Analytics {
|
|
976
|
+
private readonly client;
|
|
977
|
+
constructor(client: NotificaClient);
|
|
978
|
+
/**
|
|
979
|
+
* Métricas gerais (total enviado, entregue, falhas, taxa de entrega).
|
|
980
|
+
*
|
|
981
|
+
* @example
|
|
982
|
+
* ```ts
|
|
983
|
+
* const overview = await notifica.analytics.overview({ period: '7d' });
|
|
984
|
+
* console.log(`Taxa de entrega: ${overview.delivery_rate}%`);
|
|
985
|
+
* ```
|
|
986
|
+
*/
|
|
987
|
+
overview(params?: AnalyticsParams, options?: RequestOptions): Promise<AnalyticsOverview>;
|
|
988
|
+
/**
|
|
989
|
+
* Métricas por canal.
|
|
990
|
+
*/
|
|
991
|
+
byChannel(params?: AnalyticsParams, options?: RequestOptions): Promise<ChannelAnalytics[]>;
|
|
992
|
+
/**
|
|
993
|
+
* Série temporal de envios.
|
|
994
|
+
*/
|
|
995
|
+
timeseries(params?: TimeseriesParams, options?: RequestOptions): Promise<TimeseriesPoint[]>;
|
|
996
|
+
/**
|
|
997
|
+
* Templates mais utilizados.
|
|
998
|
+
*/
|
|
999
|
+
topTemplates(params?: TopTemplatesParams, options?: RequestOptions): Promise<TemplateAnalytics[]>;
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
type SmsProviderType = 'twilio' | 'zenvia' | 'custom';
|
|
1003
|
+
interface TwilioConfig {
|
|
1004
|
+
/** Account SID da Twilio */
|
|
1005
|
+
account_sid: string;
|
|
1006
|
+
/** Auth Token da Twilio */
|
|
1007
|
+
auth_token: string;
|
|
1008
|
+
/** Número de telefone Twilio (E.164) */
|
|
1009
|
+
phone_number: string;
|
|
1010
|
+
/** SID do Messaging Service (opcional) */
|
|
1011
|
+
messaging_service_sid?: string;
|
|
1012
|
+
}
|
|
1013
|
+
interface ZenviaConfig {
|
|
1014
|
+
/** API Key da Zenvia */
|
|
1015
|
+
api_key: string;
|
|
1016
|
+
/** Nome do remetente (ex: sua empresa) */
|
|
1017
|
+
from: string;
|
|
1018
|
+
}
|
|
1019
|
+
interface CustomSmsConfig {
|
|
1020
|
+
/** URL do webhook para envio de SMS */
|
|
1021
|
+
webhook_url: string;
|
|
1022
|
+
/** Headers customizados para o webhook */
|
|
1023
|
+
headers?: Record<string, string>;
|
|
1024
|
+
/** Timeout em ms (default: 30000) */
|
|
1025
|
+
timeout?: number;
|
|
1026
|
+
}
|
|
1027
|
+
interface SmsProviderConfig {
|
|
1028
|
+
type: SmsProviderType;
|
|
1029
|
+
/** Nome identificador do provedor */
|
|
1030
|
+
name: string;
|
|
1031
|
+
/** Configuração específica do provedor */
|
|
1032
|
+
config: TwilioConfig | ZenviaConfig | CustomSmsConfig;
|
|
1033
|
+
/** Se o provedor está ativo */
|
|
1034
|
+
active?: boolean;
|
|
1035
|
+
/** Regiões permitidas (códigos ISO 3166-1 alpha-2) */
|
|
1036
|
+
allowed_regions?: string[];
|
|
1037
|
+
/** Limite de rate limit por minuto */
|
|
1038
|
+
rate_limit_per_minute?: number;
|
|
1039
|
+
}
|
|
1040
|
+
interface SmsProvider {
|
|
1041
|
+
id: string;
|
|
1042
|
+
type: SmsProviderType;
|
|
1043
|
+
name: string;
|
|
1044
|
+
/** Configuração mascarada (credenciais parciais) */
|
|
1045
|
+
config_mask?: string;
|
|
1046
|
+
active: boolean;
|
|
1047
|
+
is_default: boolean;
|
|
1048
|
+
allowed_regions: string[] | null;
|
|
1049
|
+
rate_limit_per_minute: number | null;
|
|
1050
|
+
created_at: string;
|
|
1051
|
+
updated_at: string;
|
|
1052
|
+
}
|
|
1053
|
+
interface CreateSmsProviderParams {
|
|
1054
|
+
type: SmsProviderType;
|
|
1055
|
+
name: string;
|
|
1056
|
+
config: TwilioConfig | ZenviaConfig | CustomSmsConfig;
|
|
1057
|
+
active?: boolean;
|
|
1058
|
+
allowed_regions?: string[];
|
|
1059
|
+
rate_limit_per_minute?: number;
|
|
1060
|
+
}
|
|
1061
|
+
interface UpdateSmsProviderParams {
|
|
1062
|
+
name?: string;
|
|
1063
|
+
config?: TwilioConfig | ZenviaConfig | CustomSmsConfig;
|
|
1064
|
+
active?: boolean;
|
|
1065
|
+
allowed_regions?: string[];
|
|
1066
|
+
rate_limit_per_minute?: number;
|
|
1067
|
+
}
|
|
1068
|
+
interface ValidateSmsProviderParams {
|
|
1069
|
+
type: SmsProviderType;
|
|
1070
|
+
config: TwilioConfig | ZenviaConfig | CustomSmsConfig;
|
|
1071
|
+
}
|
|
1072
|
+
interface ValidateSmsProviderResult {
|
|
1073
|
+
valid: boolean;
|
|
1074
|
+
message?: string;
|
|
1075
|
+
errors?: Record<string, string[]>;
|
|
1076
|
+
}
|
|
1077
|
+
interface TestSmsProviderParams {
|
|
1078
|
+
/** ID do provedor (para provedores já criados) */
|
|
1079
|
+
provider_id?: string;
|
|
1080
|
+
/** Configuração para teste (para validar antes de criar) */
|
|
1081
|
+
config?: SmsProviderConfig;
|
|
1082
|
+
/** Número de telefone de destino para teste (E.164) */
|
|
1083
|
+
to: string;
|
|
1084
|
+
/** Mensagem de teste (opcional) */
|
|
1085
|
+
message?: string;
|
|
1086
|
+
}
|
|
1087
|
+
interface TestSmsProviderResult {
|
|
1088
|
+
success: boolean;
|
|
1089
|
+
message: string;
|
|
1090
|
+
message_id?: string;
|
|
1091
|
+
}
|
|
1092
|
+
interface SmsComplianceSettings {
|
|
1093
|
+
/** Horário comercial permitido (formato HH:MM) */
|
|
1094
|
+
allowed_hours_start: string | null;
|
|
1095
|
+
/** Horário comercial permitido (formato HH:MM) */
|
|
1096
|
+
allowed_hours_end: string | null;
|
|
1097
|
+
/** Dias da semana permitidos (0=Domingo, 6=Sábado) */
|
|
1098
|
+
allowed_weekdays: number[] | null;
|
|
1099
|
+
/** Feriados nacionais brasileiros são respeitados automaticamente */
|
|
1100
|
+
respect_national_holidays: boolean;
|
|
1101
|
+
/** Feriados adicionais (formato MM-DD) */
|
|
1102
|
+
custom_holidays: string[] | null;
|
|
1103
|
+
/** Mensagem padrão de opt-out */
|
|
1104
|
+
opt_out_message: string | null;
|
|
1105
|
+
/** Palavras-chave para opt-out (ex: "SAIR, CANCELAR") */
|
|
1106
|
+
opt_out_keywords: string[] | null;
|
|
1107
|
+
/** Horas de quarentena após opt-out */
|
|
1108
|
+
opt_out_cooldown_hours: number | null;
|
|
1109
|
+
/** Mensagem de confirmação de opt-in */
|
|
1110
|
+
opt_in_confirmation_message: string | null;
|
|
1111
|
+
}
|
|
1112
|
+
interface UpdateSmsComplianceParams {
|
|
1113
|
+
allowed_hours_start?: string;
|
|
1114
|
+
allowed_hours_end?: string;
|
|
1115
|
+
allowed_weekdays?: number[];
|
|
1116
|
+
respect_national_holidays?: boolean;
|
|
1117
|
+
custom_holidays?: string[];
|
|
1118
|
+
opt_out_message?: string;
|
|
1119
|
+
opt_out_keywords?: string[];
|
|
1120
|
+
opt_out_cooldown_hours?: number;
|
|
1121
|
+
opt_in_confirmation_message?: string;
|
|
1122
|
+
}
|
|
1123
|
+
interface SmsComplianceAnalytics {
|
|
1124
|
+
period_start: string;
|
|
1125
|
+
period_end: string;
|
|
1126
|
+
total_messages: number;
|
|
1127
|
+
messages_blocked_by_compliance: number;
|
|
1128
|
+
opt_outs_received: number;
|
|
1129
|
+
opt_ins_received: number;
|
|
1130
|
+
violations_by_type: Record<string, number>;
|
|
1131
|
+
}
|
|
1132
|
+
interface SmsComplianceLog {
|
|
1133
|
+
id: string;
|
|
1134
|
+
message_id: string;
|
|
1135
|
+
phone: string;
|
|
1136
|
+
action: 'blocked' | 'allowed' | 'opt_out' | 'opt_in';
|
|
1137
|
+
reason?: string;
|
|
1138
|
+
created_at: string;
|
|
1139
|
+
}
|
|
1140
|
+
interface ListComplianceLogsParams extends PaginationParams {
|
|
1141
|
+
phone?: string;
|
|
1142
|
+
action?: 'blocked' | 'allowed' | 'opt_out' | 'opt_in';
|
|
1143
|
+
start_date?: string;
|
|
1144
|
+
end_date?: string;
|
|
1145
|
+
}
|
|
1146
|
+
type SmsConsentStatus = 'opted_in' | 'opted_out' | 'pending';
|
|
1147
|
+
type SmsConsentSource = 'manual' | 'import' | 'api' | 'webhook' | 'opt_out_reply' | 'opt_in_reply';
|
|
1148
|
+
interface SmsConsent {
|
|
1149
|
+
phone: string;
|
|
1150
|
+
status: SmsConsentStatus;
|
|
1151
|
+
source: SmsConsentSource;
|
|
1152
|
+
metadata?: Record<string, unknown>;
|
|
1153
|
+
opted_in_at: string | null;
|
|
1154
|
+
opted_out_at: string | null;
|
|
1155
|
+
created_at: string;
|
|
1156
|
+
updated_at: string;
|
|
1157
|
+
}
|
|
1158
|
+
interface CreateSmsConsentParams {
|
|
1159
|
+
phone: string;
|
|
1160
|
+
status?: SmsConsentStatus;
|
|
1161
|
+
source?: SmsConsentSource;
|
|
1162
|
+
metadata?: Record<string, unknown>;
|
|
1163
|
+
}
|
|
1164
|
+
interface BulkImportSmsConsentParams {
|
|
1165
|
+
consents: CreateSmsConsentParams[];
|
|
1166
|
+
}
|
|
1167
|
+
interface BulkImportSmsConsentResult {
|
|
1168
|
+
imported: number;
|
|
1169
|
+
errors?: Array<{
|
|
1170
|
+
phone: string;
|
|
1171
|
+
error: string;
|
|
1172
|
+
}>;
|
|
1173
|
+
}
|
|
1174
|
+
interface SmsConsentSummary {
|
|
1175
|
+
total: number;
|
|
1176
|
+
opted_in: number;
|
|
1177
|
+
opted_out: number;
|
|
1178
|
+
pending: number;
|
|
1179
|
+
by_source: Record<SmsConsentSource, number>;
|
|
1180
|
+
}
|
|
1181
|
+
interface ListSmsConsentsParams extends PaginationParams {
|
|
1182
|
+
phone?: string;
|
|
1183
|
+
status?: SmsConsentStatus;
|
|
1184
|
+
source?: SmsConsentSource;
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
declare class SmsProviders {
|
|
1188
|
+
private readonly client;
|
|
1189
|
+
constructor(client: NotificaClient);
|
|
1190
|
+
/**
|
|
1191
|
+
* Lista todos os provedores SMS configurados.
|
|
1192
|
+
*/
|
|
1193
|
+
list(options?: RequestOptions): Promise<SmsProvider[]>;
|
|
1194
|
+
/**
|
|
1195
|
+
* Cria um novo provedor SMS (idempotent).
|
|
1196
|
+
*/
|
|
1197
|
+
create(params: CreateSmsProviderParams, options?: RequestOptions): Promise<SmsProvider>;
|
|
1198
|
+
/**
|
|
1199
|
+
* Obtém detalhes de um provedor SMS.
|
|
1200
|
+
*/
|
|
1201
|
+
get(id: string, options?: RequestOptions): Promise<SmsProvider>;
|
|
1202
|
+
/**
|
|
1203
|
+
* Atualiza um provedor SMS (PATCH parcial).
|
|
1204
|
+
*/
|
|
1205
|
+
update(id: string, params: UpdateSmsProviderParams, options?: RequestOptions): Promise<SmsProvider>;
|
|
1206
|
+
/**
|
|
1207
|
+
* Ativa um provedor SMS.
|
|
1208
|
+
*/
|
|
1209
|
+
activate(id: string, options?: RequestOptions): Promise<SmsProvider>;
|
|
1210
|
+
/**
|
|
1211
|
+
* Remove um provedor SMS.
|
|
1212
|
+
*/
|
|
1213
|
+
delete(id: string, options?: RequestOptions): Promise<void>;
|
|
1214
|
+
/**
|
|
1215
|
+
* Valida a configuração de um provedor SMS.
|
|
1216
|
+
*/
|
|
1217
|
+
validate(params: ValidateSmsProviderParams, options?: RequestOptions): Promise<ValidateSmsProviderResult>;
|
|
1218
|
+
/**
|
|
1219
|
+
* Envia um SMS de teste.
|
|
1220
|
+
*/
|
|
1221
|
+
test(params: TestSmsProviderParams, options?: RequestOptions): Promise<TestSmsProviderResult>;
|
|
1222
|
+
}
|
|
1223
|
+
declare class SmsCompliance {
|
|
1224
|
+
private readonly client;
|
|
1225
|
+
constructor(client: NotificaClient);
|
|
1226
|
+
/**
|
|
1227
|
+
* Obtém as configurações de compliance SMS.
|
|
1228
|
+
*/
|
|
1229
|
+
show(options?: RequestOptions): Promise<SmsComplianceSettings>;
|
|
1230
|
+
/**
|
|
1231
|
+
* Atualiza as configurações de compliance SMS (PATCH parcial).
|
|
1232
|
+
*/
|
|
1233
|
+
update(params: UpdateSmsComplianceParams, options?: RequestOptions): Promise<SmsComplianceSettings>;
|
|
1234
|
+
/**
|
|
1235
|
+
* Obtém estatísticas de compliance.
|
|
1236
|
+
*/
|
|
1237
|
+
analytics(options?: RequestOptions): Promise<SmsComplianceAnalytics>;
|
|
1238
|
+
/**
|
|
1239
|
+
* Lista logs de compliance com paginação.
|
|
1240
|
+
*/
|
|
1241
|
+
logs(params?: ListComplianceLogsParams, options?: RequestOptions): Promise<PaginatedResponse<SmsComplianceLog>>;
|
|
1242
|
+
}
|
|
1243
|
+
declare class SmsConsents {
|
|
1244
|
+
private readonly client;
|
|
1245
|
+
constructor(client: NotificaClient);
|
|
1246
|
+
/**
|
|
1247
|
+
* Lista consentimentos SMS com paginação.
|
|
1248
|
+
*/
|
|
1249
|
+
list(params?: ListSmsConsentsParams, options?: RequestOptions): Promise<PaginatedResponse<SmsConsent>>;
|
|
1250
|
+
/**
|
|
1251
|
+
* Obtém resumo estatístico dos consentimentos.
|
|
1252
|
+
*/
|
|
1253
|
+
summary(options?: RequestOptions): Promise<SmsConsentSummary>;
|
|
1254
|
+
/**
|
|
1255
|
+
* Obtém o consentimento de um número específico.
|
|
1256
|
+
*/
|
|
1257
|
+
get(phone: string, options?: RequestOptions): Promise<SmsConsent>;
|
|
1258
|
+
/**
|
|
1259
|
+
* Revoga o consentimento de um número (DELETE).
|
|
1260
|
+
*/
|
|
1261
|
+
revoke(phone: string, options?: RequestOptions): Promise<void>;
|
|
1262
|
+
/**
|
|
1263
|
+
* Cria ou atualiza um consentimento SMS (idempotent).
|
|
1264
|
+
*/
|
|
1265
|
+
create(params: CreateSmsConsentParams, options?: RequestOptions): Promise<SmsConsent>;
|
|
1266
|
+
/**
|
|
1267
|
+
* Importa consentimentos em lote.
|
|
1268
|
+
*/
|
|
1269
|
+
import(params: BulkImportSmsConsentParams, options?: RequestOptions): Promise<BulkImportSmsConsentResult>;
|
|
1270
|
+
}
|
|
1271
|
+
declare class Sms {
|
|
1272
|
+
readonly providers: SmsProviders;
|
|
1273
|
+
readonly compliance: SmsCompliance;
|
|
1274
|
+
readonly consents: SmsConsents;
|
|
1275
|
+
constructor(client: NotificaClient);
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
interface BillingPlan {
|
|
1279
|
+
/** Identificador único do plano */
|
|
1280
|
+
name: string;
|
|
1281
|
+
/** Nome de exibição */
|
|
1282
|
+
display_name: string;
|
|
1283
|
+
/** Descrição do plano */
|
|
1284
|
+
description: string | null;
|
|
1285
|
+
/** Preço mensal em centavos */
|
|
1286
|
+
monthly_price_cents: number;
|
|
1287
|
+
/** Preço anual em centavos (com desconto) */
|
|
1288
|
+
yearly_price_cents: number;
|
|
1289
|
+
/** Período de trial em dias */
|
|
1290
|
+
trial_days: number;
|
|
1291
|
+
/** Quotas incluídas no plano */
|
|
1292
|
+
quotas: BillingQuotas;
|
|
1293
|
+
/** Recursos habilitados */
|
|
1294
|
+
features: BillingFeatures;
|
|
1295
|
+
/** Se o plano está disponível para novas assinaturas */
|
|
1296
|
+
available: boolean;
|
|
1297
|
+
/** Ordem de exibição */
|
|
1298
|
+
sort_order: number;
|
|
1299
|
+
}
|
|
1300
|
+
interface BillingQuotas {
|
|
1301
|
+
/** Limite de notificações por mês (null = ilimitado) */
|
|
1302
|
+
notifications_per_month: number | null;
|
|
1303
|
+
/** Limite de emails por mês */
|
|
1304
|
+
emails_per_month: number | null;
|
|
1305
|
+
/** Limite de SMS por mês */
|
|
1306
|
+
sms_per_month: number | null;
|
|
1307
|
+
/** Limite de WhatsApp por mês */
|
|
1308
|
+
whatsapp_per_month: number | null;
|
|
1309
|
+
/** Limite de subscribers */
|
|
1310
|
+
subscribers_limit: number | null;
|
|
1311
|
+
/** Limite de templates */
|
|
1312
|
+
templates_limit: number | null;
|
|
1313
|
+
/** Limite de workflows */
|
|
1314
|
+
workflows_limit: number | null;
|
|
1315
|
+
/** Limite de usuários do tenant */
|
|
1316
|
+
team_members_limit: number | null;
|
|
1317
|
+
}
|
|
1318
|
+
interface BillingFeatures {
|
|
1319
|
+
/** Suporte a múltiplos canais */
|
|
1320
|
+
multi_channel: boolean;
|
|
1321
|
+
/** Workflows avançados */
|
|
1322
|
+
advanced_workflows: boolean;
|
|
1323
|
+
/** Webhooks personalizados */
|
|
1324
|
+
custom_webhooks: boolean;
|
|
1325
|
+
/** API dedicada */
|
|
1326
|
+
dedicated_api: boolean;
|
|
1327
|
+
/** Suporte prioritário */
|
|
1328
|
+
priority_support: boolean;
|
|
1329
|
+
/** SLA garantido */
|
|
1330
|
+
sla_guarantee: boolean;
|
|
1331
|
+
/** LGPD compliance avançado */
|
|
1332
|
+
advanced_lgpd: boolean;
|
|
1333
|
+
/** SSO/SAML */
|
|
1334
|
+
sso: boolean;
|
|
1335
|
+
/** Logs de auditoria */
|
|
1336
|
+
audit_logs: boolean;
|
|
1337
|
+
}
|
|
1338
|
+
type BillingGatewayType = 'asaas' | 'efi';
|
|
1339
|
+
interface BillingSettings {
|
|
1340
|
+
/** Gateway de pagamento configurado */
|
|
1341
|
+
gateway: BillingGatewayType | null;
|
|
1342
|
+
/** Moeda (default: BRL) */
|
|
1343
|
+
currency: string;
|
|
1344
|
+
/** Fuso horário para faturamento */
|
|
1345
|
+
timezone: string;
|
|
1346
|
+
/** Dia de vencimento (1-31) */
|
|
1347
|
+
due_day: number | null;
|
|
1348
|
+
/** Informações fiscais */
|
|
1349
|
+
tax_info: BillingTaxInfo | null;
|
|
1350
|
+
}
|
|
1351
|
+
interface BillingTaxInfo {
|
|
1352
|
+
/** Tipo de pessoa: física ou jurídica */
|
|
1353
|
+
person_type: 'individual' | 'company';
|
|
1354
|
+
/** CPF ou CNPJ */
|
|
1355
|
+
document: string;
|
|
1356
|
+
/** Razão social ou nome completo */
|
|
1357
|
+
legal_name: string;
|
|
1358
|
+
/** Email para faturas */
|
|
1359
|
+
billing_email: string;
|
|
1360
|
+
/** Endereço */
|
|
1361
|
+
address?: BillingAddress;
|
|
1362
|
+
}
|
|
1363
|
+
interface BillingAddress {
|
|
1364
|
+
street: string;
|
|
1365
|
+
number: string;
|
|
1366
|
+
complement?: string;
|
|
1367
|
+
neighborhood: string;
|
|
1368
|
+
city: string;
|
|
1369
|
+
state: string;
|
|
1370
|
+
zip_code: string;
|
|
1371
|
+
country: string;
|
|
1372
|
+
}
|
|
1373
|
+
type SubscriptionStatus = 'trial' | 'active' | 'past_due' | 'canceled' | 'paused' | 'expired';
|
|
1374
|
+
type SubscriptionPeriod = 'monthly' | 'yearly';
|
|
1375
|
+
interface Subscription {
|
|
1376
|
+
id: string;
|
|
1377
|
+
plan_name: string;
|
|
1378
|
+
status: SubscriptionStatus;
|
|
1379
|
+
period: SubscriptionPeriod;
|
|
1380
|
+
/** Data de início da assinatura */
|
|
1381
|
+
starts_at: string;
|
|
1382
|
+
/** Próxima data de cobrança */
|
|
1383
|
+
current_period_ends_at: string;
|
|
1384
|
+
/** Data de término (se cancelada) */
|
|
1385
|
+
ends_at: string | null;
|
|
1386
|
+
/** Dias restantes de trial */
|
|
1387
|
+
trial_days_remaining: number | null;
|
|
1388
|
+
/** Se está em trial */
|
|
1389
|
+
in_trial: boolean;
|
|
1390
|
+
/** Se será renovada automaticamente */
|
|
1391
|
+
auto_renew: boolean;
|
|
1392
|
+
/** Valor atual em centavos */
|
|
1393
|
+
current_price_cents: number;
|
|
1394
|
+
created_at: string;
|
|
1395
|
+
updated_at: string;
|
|
1396
|
+
}
|
|
1397
|
+
interface SubscribeParams {
|
|
1398
|
+
plan_name: string;
|
|
1399
|
+
period?: SubscriptionPeriod;
|
|
1400
|
+
payment_method_id?: string;
|
|
1401
|
+
/** Código de cupom (opcional) */
|
|
1402
|
+
coupon_code?: string;
|
|
1403
|
+
}
|
|
1404
|
+
interface ChangePlanParams {
|
|
1405
|
+
plan_name: string;
|
|
1406
|
+
period?: SubscriptionPeriod;
|
|
1407
|
+
/** Efetivar imediatamente ou no próximo ciclo */
|
|
1408
|
+
effective_immediately?: boolean;
|
|
1409
|
+
}
|
|
1410
|
+
interface CancelSubscriptionParams {
|
|
1411
|
+
/** Efetivar no fim do período atual */
|
|
1412
|
+
at_period_end?: boolean;
|
|
1413
|
+
/** Motivo do cancelamento */
|
|
1414
|
+
reason?: string;
|
|
1415
|
+
}
|
|
1416
|
+
interface ReactivateSubscriptionParams {
|
|
1417
|
+
payment_method_id?: string;
|
|
1418
|
+
}
|
|
1419
|
+
interface CalculateProrationParams {
|
|
1420
|
+
plan_name: string;
|
|
1421
|
+
period?: SubscriptionPeriod;
|
|
1422
|
+
}
|
|
1423
|
+
interface CalculateProrationResult {
|
|
1424
|
+
/** Crédito do plano atual */
|
|
1425
|
+
current_plan_credit_cents: number;
|
|
1426
|
+
/** Débito do novo plano */
|
|
1427
|
+
new_plan_debit_cents: number;
|
|
1428
|
+
/** Valor a pagar (pode ser negativo = crédito) */
|
|
1429
|
+
proration_amount_cents: number;
|
|
1430
|
+
/** Nova data de vencimento */
|
|
1431
|
+
next_billing_date: string;
|
|
1432
|
+
}
|
|
1433
|
+
interface BillingUsage {
|
|
1434
|
+
/** Período atual */
|
|
1435
|
+
period_start: string;
|
|
1436
|
+
period_end: string;
|
|
1437
|
+
/** Uso atual */
|
|
1438
|
+
current: BillingUsageMetrics;
|
|
1439
|
+
/** Quotas do plano */
|
|
1440
|
+
quotas: BillingQuotas;
|
|
1441
|
+
/** Percentuais de uso (0-100, null = ilimitado) */
|
|
1442
|
+
percentages: BillingUsagePercentages;
|
|
1443
|
+
}
|
|
1444
|
+
interface BillingUsageMetrics {
|
|
1445
|
+
notifications: number;
|
|
1446
|
+
emails: number;
|
|
1447
|
+
sms: number;
|
|
1448
|
+
whatsapp: number;
|
|
1449
|
+
subscribers: number;
|
|
1450
|
+
templates: number;
|
|
1451
|
+
workflows: number;
|
|
1452
|
+
team_members: number;
|
|
1453
|
+
}
|
|
1454
|
+
interface BillingUsagePercentages {
|
|
1455
|
+
notifications: number | null;
|
|
1456
|
+
emails: number | null;
|
|
1457
|
+
sms: number | null;
|
|
1458
|
+
whatsapp: number | null;
|
|
1459
|
+
subscribers: number | null;
|
|
1460
|
+
templates: number | null;
|
|
1461
|
+
workflows: number | null;
|
|
1462
|
+
team_members: number | null;
|
|
1463
|
+
}
|
|
1464
|
+
type InvoiceStatus = 'pending' | 'paid' | 'overdue' | 'canceled' | 'refunded' | 'processing';
|
|
1465
|
+
type PaymentMethodType = 'credit_card' | 'pix' | 'boleto';
|
|
1466
|
+
interface Invoice {
|
|
1467
|
+
id: string;
|
|
1468
|
+
subscription_id: string;
|
|
1469
|
+
status: InvoiceStatus;
|
|
1470
|
+
/** Valor em centavos */
|
|
1471
|
+
amount_cents: number;
|
|
1472
|
+
/** Valor pago em centavos */
|
|
1473
|
+
amount_paid_cents: number;
|
|
1474
|
+
currency: string;
|
|
1475
|
+
/** Descrição da fatura */
|
|
1476
|
+
description: string;
|
|
1477
|
+
/** Método de pagamento utilizado */
|
|
1478
|
+
payment_method: PaymentMethodType | null;
|
|
1479
|
+
/** Data de vencimento */
|
|
1480
|
+
due_date: string;
|
|
1481
|
+
/** Data de pagamento */
|
|
1482
|
+
paid_at: string | null;
|
|
1483
|
+
/** URL do boleto (se aplicável) */
|
|
1484
|
+
boleto_url: string | null;
|
|
1485
|
+
/** Código PIX (se aplicável) */
|
|
1486
|
+
pix_code: string | null;
|
|
1487
|
+
/** QR Code PIX (base64) */
|
|
1488
|
+
pix_qr_code: string | null;
|
|
1489
|
+
/** Linha digitável do boleto */
|
|
1490
|
+
boleto_line: string | null;
|
|
1491
|
+
/** PDF do boleto */
|
|
1492
|
+
boleto_pdf_url: string | null;
|
|
1493
|
+
created_at: string;
|
|
1494
|
+
updated_at: string;
|
|
1495
|
+
}
|
|
1496
|
+
interface ListInvoicesParams extends PaginationParams {
|
|
1497
|
+
status?: InvoiceStatus;
|
|
1498
|
+
start_date?: string;
|
|
1499
|
+
end_date?: string;
|
|
1500
|
+
}
|
|
1501
|
+
type CardBrand = 'visa' | 'mastercard' | 'amex' | 'elo' | 'hipercard' | 'diners' | 'discover' | 'jcb' | 'aura' | 'unknown';
|
|
1502
|
+
interface PaymentMethodCard {
|
|
1503
|
+
brand: CardBrand;
|
|
1504
|
+
last_four: string;
|
|
1505
|
+
exp_month: number;
|
|
1506
|
+
exp_year: number;
|
|
1507
|
+
holder_name: string;
|
|
1508
|
+
}
|
|
1509
|
+
interface PaymentMethod {
|
|
1510
|
+
id: string;
|
|
1511
|
+
type: PaymentMethodType;
|
|
1512
|
+
/** Se é o método padrão */
|
|
1513
|
+
is_default: boolean;
|
|
1514
|
+
/** Dados do cartão (se type = credit_card) */
|
|
1515
|
+
card: PaymentMethodCard | null;
|
|
1516
|
+
/** Chave PIX (se type = pix) */
|
|
1517
|
+
pix_key: string | null;
|
|
1518
|
+
/** Tipo de chave PIX */
|
|
1519
|
+
pix_key_type: 'cpf' | 'cnpj' | 'email' | 'phone' | 'random' | null;
|
|
1520
|
+
/** Apelido do método */
|
|
1521
|
+
nickname: string | null;
|
|
1522
|
+
created_at: string;
|
|
1523
|
+
updated_at: string;
|
|
1524
|
+
}
|
|
1525
|
+
interface CreatePaymentMethodParams {
|
|
1526
|
+
type: PaymentMethodType;
|
|
1527
|
+
/** Token do cartão (do gateway de pagamento) */
|
|
1528
|
+
card_token?: string;
|
|
1529
|
+
/** Dados do cartão para tokenização */
|
|
1530
|
+
card?: CreateCardParams;
|
|
1531
|
+
/** Chave PIX */
|
|
1532
|
+
pix_key?: string;
|
|
1533
|
+
pix_key_type?: 'cpf' | 'cnpj' | 'email' | 'phone' | 'random';
|
|
1534
|
+
/** Apelido identificador */
|
|
1535
|
+
nickname?: string;
|
|
1536
|
+
/** Definir como padrão */
|
|
1537
|
+
set_as_default?: boolean;
|
|
1538
|
+
}
|
|
1539
|
+
interface CreateCardParams {
|
|
1540
|
+
number: string;
|
|
1541
|
+
holder_name: string;
|
|
1542
|
+
exp_month: number;
|
|
1543
|
+
exp_year: number;
|
|
1544
|
+
cvv: string;
|
|
1545
|
+
}
|
|
1546
|
+
interface UpdatePaymentMethodParams {
|
|
1547
|
+
nickname?: string;
|
|
1548
|
+
/** Apenas para cartões - atualizar dados */
|
|
1549
|
+
exp_month?: number;
|
|
1550
|
+
exp_year?: number;
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
declare class BillingPlans {
|
|
1554
|
+
private readonly client;
|
|
1555
|
+
constructor(client: NotificaClient);
|
|
1556
|
+
/**
|
|
1557
|
+
* Lista todos os planos disponíveis.
|
|
1558
|
+
*/
|
|
1559
|
+
list(options?: RequestOptions): Promise<BillingPlan[]>;
|
|
1560
|
+
/**
|
|
1561
|
+
* Obtém detalhes de um plano específico.
|
|
1562
|
+
*/
|
|
1563
|
+
get(name: string, options?: RequestOptions): Promise<BillingPlan>;
|
|
1564
|
+
}
|
|
1565
|
+
declare class BillingSettingsResource {
|
|
1566
|
+
private readonly client;
|
|
1567
|
+
constructor(client: NotificaClient);
|
|
1568
|
+
/**
|
|
1569
|
+
* Obtém as configurações de faturamento do tenant.
|
|
1570
|
+
*/
|
|
1571
|
+
get(options?: RequestOptions): Promise<BillingSettings>;
|
|
1572
|
+
}
|
|
1573
|
+
declare class BillingSubscription {
|
|
1574
|
+
private readonly client;
|
|
1575
|
+
constructor(client: NotificaClient);
|
|
1576
|
+
/**
|
|
1577
|
+
* Obtém a assinatura atual.
|
|
1578
|
+
*/
|
|
1579
|
+
get(options?: RequestOptions): Promise<Subscription>;
|
|
1580
|
+
/**
|
|
1581
|
+
* Cria uma nova assinatura (idempotent).
|
|
1582
|
+
*/
|
|
1583
|
+
subscribe(params: SubscribeParams, options?: RequestOptions): Promise<Subscription>;
|
|
1584
|
+
/**
|
|
1585
|
+
* Altera o plano da assinatura (idempotent).
|
|
1586
|
+
*/
|
|
1587
|
+
changePlan(params: ChangePlanParams, options?: RequestOptions): Promise<Subscription>;
|
|
1588
|
+
/**
|
|
1589
|
+
* Cancela a assinatura (idempotent).
|
|
1590
|
+
*/
|
|
1591
|
+
cancel(params?: CancelSubscriptionParams, options?: RequestOptions): Promise<Subscription>;
|
|
1592
|
+
/**
|
|
1593
|
+
* Calcula o valor de proration para mudança de plano.
|
|
1594
|
+
*/
|
|
1595
|
+
calculateProration(params: CalculateProrationParams, options?: RequestOptions): Promise<CalculateProrationResult>;
|
|
1596
|
+
/**
|
|
1597
|
+
* Reativa uma assinatura cancelada (idempotent).
|
|
1598
|
+
*/
|
|
1599
|
+
reactivate(params?: ReactivateSubscriptionParams, options?: RequestOptions): Promise<Subscription>;
|
|
1600
|
+
}
|
|
1601
|
+
declare class BillingUsageResource {
|
|
1602
|
+
private readonly client;
|
|
1603
|
+
constructor(client: NotificaClient);
|
|
1604
|
+
/**
|
|
1605
|
+
* Obtém o uso atual e quotas do tenant.
|
|
1606
|
+
*/
|
|
1607
|
+
get(options?: RequestOptions): Promise<BillingUsage>;
|
|
1608
|
+
}
|
|
1609
|
+
declare class BillingInvoices {
|
|
1610
|
+
private readonly client;
|
|
1611
|
+
constructor(client: NotificaClient);
|
|
1612
|
+
/**
|
|
1613
|
+
* Lista faturas com paginação.
|
|
1614
|
+
*/
|
|
1615
|
+
list(params?: ListInvoicesParams, options?: RequestOptions): Promise<PaginatedResponse<Invoice>>;
|
|
1616
|
+
/**
|
|
1617
|
+
* Obtém detalhes de uma fatura.
|
|
1618
|
+
*/
|
|
1619
|
+
get(id: string, options?: RequestOptions): Promise<Invoice>;
|
|
1620
|
+
}
|
|
1621
|
+
declare class BillingPaymentMethods {
|
|
1622
|
+
private readonly client;
|
|
1623
|
+
constructor(client: NotificaClient);
|
|
1624
|
+
/**
|
|
1625
|
+
* Lista métodos de pagamento.
|
|
1626
|
+
*/
|
|
1627
|
+
list(options?: RequestOptions): Promise<PaymentMethod[]>;
|
|
1628
|
+
/**
|
|
1629
|
+
* Cria um novo método de pagamento (idempotent).
|
|
1630
|
+
*/
|
|
1631
|
+
create(params: CreatePaymentMethodParams, options?: RequestOptions): Promise<PaymentMethod>;
|
|
1632
|
+
/**
|
|
1633
|
+
* Obtém detalhes de um método de pagamento.
|
|
1634
|
+
*/
|
|
1635
|
+
get(id: string, options?: RequestOptions): Promise<PaymentMethod>;
|
|
1636
|
+
/**
|
|
1637
|
+
* Atualiza um método de pagamento.
|
|
1638
|
+
*/
|
|
1639
|
+
update(id: string, params: UpdatePaymentMethodParams, options?: RequestOptions): Promise<PaymentMethod>;
|
|
1640
|
+
/**
|
|
1641
|
+
* Remove um método de pagamento.
|
|
1642
|
+
*/
|
|
1643
|
+
delete(id: string, options?: RequestOptions): Promise<void>;
|
|
1644
|
+
/**
|
|
1645
|
+
* Define um método de pagamento como padrão.
|
|
1646
|
+
*/
|
|
1647
|
+
setDefault(id: string, options?: RequestOptions): Promise<PaymentMethod>;
|
|
1648
|
+
}
|
|
1649
|
+
declare class Billing {
|
|
1650
|
+
readonly plans: BillingPlans;
|
|
1651
|
+
readonly settings: BillingSettingsResource;
|
|
1652
|
+
readonly subscription: BillingSubscription;
|
|
1653
|
+
readonly usage: BillingUsageResource;
|
|
1654
|
+
readonly invoices: BillingInvoices;
|
|
1655
|
+
readonly paymentMethods: BillingPaymentMethods;
|
|
1656
|
+
constructor(client: NotificaClient);
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
interface InboxEmbedSettings {
|
|
1660
|
+
/** Se o inbox embed está habilitado */
|
|
1661
|
+
enabled: boolean;
|
|
1662
|
+
/** Tema: 'light', 'dark', ou 'auto' */
|
|
1663
|
+
theme: 'light' | 'dark' | 'auto';
|
|
1664
|
+
/** Posição do widget: 'bottom-right', 'bottom-left', 'top-right', 'top-left' */
|
|
1665
|
+
position: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
1666
|
+
/** Título do widget */
|
|
1667
|
+
title: string | null;
|
|
1668
|
+
/** Cor primária (hex) */
|
|
1669
|
+
primary_color: string | null;
|
|
1670
|
+
/** Cor de fundo (hex) */
|
|
1671
|
+
background_color: string | null;
|
|
1672
|
+
/** Texto do botão quando há notificações não lidas */
|
|
1673
|
+
unread_badge_text: string | null;
|
|
1674
|
+
/** Mostrar avatar do remetente */
|
|
1675
|
+
show_sender_avatar: boolean;
|
|
1676
|
+
/** Mostrar timestamp */
|
|
1677
|
+
show_timestamp: boolean;
|
|
1678
|
+
/** Formato de data */
|
|
1679
|
+
date_format: 'relative' | 'absolute' | 'both';
|
|
1680
|
+
/** Máximo de notificações exibidas */
|
|
1681
|
+
max_notifications: number;
|
|
1682
|
+
/** Texto quando não há notificações */
|
|
1683
|
+
empty_state_text: string | null;
|
|
1684
|
+
/** URL do logo customizado */
|
|
1685
|
+
custom_logo_url: string | null;
|
|
1686
|
+
/** CSS customizado */
|
|
1687
|
+
custom_css: string | null;
|
|
1688
|
+
/** Chave de embed para uso no frontend (pk_...) */
|
|
1689
|
+
embed_key: string;
|
|
1690
|
+
/** Domínios permitidos (CORS) */
|
|
1691
|
+
allowed_domains: string[];
|
|
1692
|
+
created_at: string;
|
|
1693
|
+
updated_at: string;
|
|
1694
|
+
}
|
|
1695
|
+
interface UpdateInboxEmbedSettingsParams {
|
|
1696
|
+
enabled?: boolean;
|
|
1697
|
+
theme?: 'light' | 'dark' | 'auto';
|
|
1698
|
+
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
1699
|
+
title?: string;
|
|
1700
|
+
primary_color?: string;
|
|
1701
|
+
background_color?: string;
|
|
1702
|
+
unread_badge_text?: string;
|
|
1703
|
+
show_sender_avatar?: boolean;
|
|
1704
|
+
show_timestamp?: boolean;
|
|
1705
|
+
date_format?: 'relative' | 'absolute' | 'both';
|
|
1706
|
+
max_notifications?: number;
|
|
1707
|
+
empty_state_text?: string;
|
|
1708
|
+
custom_logo_url?: string;
|
|
1709
|
+
custom_css?: string;
|
|
1710
|
+
allowed_domains?: string[];
|
|
1711
|
+
}
|
|
1712
|
+
interface RotateEmbedKeyResult {
|
|
1713
|
+
/** Nova chave de embed gerada */
|
|
1714
|
+
embed_key: string;
|
|
1715
|
+
/** Data de expiração da chave antiga (grace period) */
|
|
1716
|
+
old_key_expires_at: string;
|
|
1717
|
+
}
|
|
1718
|
+
|
|
1719
|
+
declare class InboxEmbed {
|
|
1720
|
+
private readonly client;
|
|
1721
|
+
constructor(client: NotificaClient);
|
|
1722
|
+
/**
|
|
1723
|
+
* Obtém as configurações do inbox embed.
|
|
1724
|
+
*/
|
|
1725
|
+
getSettings(options?: RequestOptions): Promise<InboxEmbedSettings>;
|
|
1726
|
+
/**
|
|
1727
|
+
* Atualiza as configurações do inbox embed.
|
|
1728
|
+
*/
|
|
1729
|
+
updateSettings(params: UpdateInboxEmbedSettingsParams, options?: RequestOptions): Promise<InboxEmbedSettings>;
|
|
1730
|
+
/**
|
|
1731
|
+
* Rotaciona a chave de embed.
|
|
1732
|
+
* A chave antiga continua funcionando por um período de grace period.
|
|
1733
|
+
*/
|
|
1734
|
+
rotateKey(options?: RequestOptions): Promise<RotateEmbedKeyResult>;
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
/** Notificação do inbox público (similar ao InAppNotification de subscribers) */
|
|
1738
|
+
interface InboxNotification {
|
|
1739
|
+
id: string;
|
|
1740
|
+
/** Título da notificação */
|
|
1741
|
+
title: string | null;
|
|
1742
|
+
/** Corpo/conteúdo */
|
|
1743
|
+
body: string | null;
|
|
1744
|
+
/** URL para ação */
|
|
1745
|
+
action_url: string | null;
|
|
1746
|
+
/** Se já foi lida */
|
|
1747
|
+
read: boolean;
|
|
1748
|
+
/** Ícone/imagem (URL) */
|
|
1749
|
+
image_url: string | null;
|
|
1750
|
+
/** Categoria/tipo */
|
|
1751
|
+
category: string | null;
|
|
1752
|
+
/** Metadados customizados */
|
|
1753
|
+
metadata: Record<string, unknown> | null;
|
|
1754
|
+
/** Data de envio */
|
|
1755
|
+
sent_at: string;
|
|
1756
|
+
/** Data de criação */
|
|
1757
|
+
created_at: string;
|
|
1758
|
+
}
|
|
1759
|
+
interface ListInboxNotificationsParams extends PaginationParams {
|
|
1760
|
+
/** Filtrar apenas não lidas */
|
|
1761
|
+
unread_only?: boolean;
|
|
1762
|
+
/** Categoria específica */
|
|
1763
|
+
category?: string;
|
|
1764
|
+
/** Data de início (ISO 8601) */
|
|
1765
|
+
start_date?: string;
|
|
1766
|
+
/** Data de fim (ISO 8601) */
|
|
1767
|
+
end_date?: string;
|
|
1768
|
+
}
|
|
1769
|
+
interface InboxUnreadCountResult {
|
|
1770
|
+
count: number;
|
|
1771
|
+
}
|
|
1772
|
+
interface MarkInboxReadResult {
|
|
1773
|
+
success: boolean;
|
|
1774
|
+
notification_id?: string;
|
|
1775
|
+
}
|
|
1776
|
+
interface MarkInboxReadAllResult {
|
|
1777
|
+
success: boolean;
|
|
1778
|
+
marked_count: number;
|
|
1779
|
+
}
|
|
1780
|
+
|
|
1781
|
+
/**
|
|
1782
|
+
* Inbox público — usa publishable key (pk_*).
|
|
1783
|
+
* Este recurso permite consultar notificações usando a chave pública,
|
|
1784
|
+
* ideal para integração direta no frontend.
|
|
1785
|
+
*/
|
|
1786
|
+
declare class Inbox {
|
|
1787
|
+
private readonly client;
|
|
1788
|
+
constructor(client: NotificaClient);
|
|
1789
|
+
/**
|
|
1790
|
+
* Lista notificações do inbox.
|
|
1791
|
+
* Requer subscriber_id ou external_id como parâmetro de query.
|
|
1792
|
+
*/
|
|
1793
|
+
listNotifications(subscriberId: string, params?: Omit<ListInboxNotificationsParams, 'subscriber_id'>, options?: RequestOptions): Promise<PaginatedResponse<InboxNotification>>;
|
|
1794
|
+
/**
|
|
1795
|
+
* Obtém a contagem de notificações não lidas.
|
|
1796
|
+
*/
|
|
1797
|
+
getUnreadCount(subscriberId: string, options?: RequestOptions): Promise<number>;
|
|
1798
|
+
/**
|
|
1799
|
+
* Marca uma notificação como lida.
|
|
1800
|
+
*/
|
|
1801
|
+
markRead(notificationId: string, options?: RequestOptions): Promise<MarkInboxReadResult>;
|
|
1802
|
+
/**
|
|
1803
|
+
* Marca todas as notificações como lidas.
|
|
1804
|
+
* Requer subscriber_id como parâmetro de query.
|
|
1805
|
+
*/
|
|
1806
|
+
markAllRead(subscriberId: string, options?: RequestOptions): Promise<MarkInboxReadAllResult>;
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
/**
|
|
1810
|
+
* Classe base para todos os erros do SDK Notifica.
|
|
1811
|
+
*/
|
|
1812
|
+
declare class NotificaError extends Error {
|
|
1813
|
+
constructor(message: string);
|
|
1814
|
+
}
|
|
1815
|
+
/**
|
|
1816
|
+
* Erro retornado pela API.
|
|
1817
|
+
* Contém status HTTP, código do erro, e request ID para debugging.
|
|
1818
|
+
*/
|
|
1819
|
+
declare class ApiError extends NotificaError {
|
|
1820
|
+
/** HTTP status code */
|
|
1821
|
+
readonly status: number;
|
|
1822
|
+
/** Código do erro retornado pela API (ex: "validation_failed") */
|
|
1823
|
+
readonly code: string;
|
|
1824
|
+
/** Detalhes de validação por campo */
|
|
1825
|
+
readonly details: Record<string, string[]>;
|
|
1826
|
+
/** ID da request para suporte/debugging */
|
|
1827
|
+
readonly requestId: string | null;
|
|
1828
|
+
constructor(message: string, status: number, code: string, details?: Record<string, string[]>, requestId?: string | null);
|
|
1829
|
+
}
|
|
1830
|
+
/**
|
|
1831
|
+
* Erro de validação (HTTP 422).
|
|
1832
|
+
*/
|
|
1833
|
+
declare class ValidationError extends ApiError {
|
|
1834
|
+
constructor(message: string, details?: Record<string, string[]>, requestId?: string | null);
|
|
1835
|
+
}
|
|
1836
|
+
/**
|
|
1837
|
+
* Rate limit excedido (HTTP 429).
|
|
1838
|
+
* Inclui o tempo para tentar novamente.
|
|
1839
|
+
*/
|
|
1840
|
+
declare class RateLimitError extends ApiError {
|
|
1841
|
+
/** Segundos até poder tentar novamente */
|
|
1842
|
+
readonly retryAfter: number | null;
|
|
1843
|
+
constructor(message: string, retryAfter?: number | null, requestId?: string | null);
|
|
1844
|
+
}
|
|
1845
|
+
/**
|
|
1846
|
+
* Timeout de conexão ou request.
|
|
1847
|
+
*/
|
|
1848
|
+
declare class TimeoutError extends NotificaError {
|
|
1849
|
+
constructor(timeoutMs: number);
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
/**
|
|
1853
|
+
* Cliente oficial do Notifica para Node.js.
|
|
1854
|
+
*
|
|
1855
|
+
* @example
|
|
1856
|
+
* ```ts
|
|
1857
|
+
* import { Notifica } from '@notifica/node';
|
|
1858
|
+
*
|
|
1859
|
+
* const notifica = new Notifica('nk_live_...');
|
|
1860
|
+
*
|
|
1861
|
+
* // Enviar notificação
|
|
1862
|
+
* await notifica.notifications.send({
|
|
1863
|
+
* channel: 'whatsapp',
|
|
1864
|
+
* to: '+5511999999999',
|
|
1865
|
+
* template: 'welcome',
|
|
1866
|
+
* data: { name: 'João' },
|
|
1867
|
+
* });
|
|
1868
|
+
*
|
|
1869
|
+
* // Disparar workflow
|
|
1870
|
+
* await notifica.workflows.trigger('welcome-flow', {
|
|
1871
|
+
* recipient: '+5511999999999',
|
|
1872
|
+
* data: { name: 'João' },
|
|
1873
|
+
* });
|
|
1874
|
+
* ```
|
|
1875
|
+
*/
|
|
1876
|
+
declare class Notifica {
|
|
1877
|
+
readonly notifications: Notifications;
|
|
1878
|
+
readonly templates: Templates;
|
|
1879
|
+
readonly workflows: Workflows;
|
|
1880
|
+
readonly subscribers: Subscribers;
|
|
1881
|
+
readonly channels: Channels;
|
|
1882
|
+
readonly domains: Domains;
|
|
1883
|
+
readonly webhooks: Webhooks;
|
|
1884
|
+
readonly apiKeys: ApiKeys;
|
|
1885
|
+
readonly analytics: Analytics;
|
|
1886
|
+
readonly sms: Sms;
|
|
1887
|
+
readonly billing: Billing;
|
|
1888
|
+
readonly inboxEmbed: InboxEmbed;
|
|
1889
|
+
readonly inbox: Inbox;
|
|
1890
|
+
/**
|
|
1891
|
+
* Cria uma nova instância do cliente Notifica.
|
|
1892
|
+
*
|
|
1893
|
+
* @param apiKeyOrConfig — API key (string) ou objeto de configuração completo
|
|
1894
|
+
*
|
|
1895
|
+
* @example
|
|
1896
|
+
* ```ts
|
|
1897
|
+
* // Simples — apenas API key
|
|
1898
|
+
* const notifica = new Notifica('nk_live_...');
|
|
1899
|
+
*
|
|
1900
|
+
* // Configuração completa
|
|
1901
|
+
* const notifica = new Notifica({
|
|
1902
|
+
* apiKey: 'nk_live_...',
|
|
1903
|
+
* baseUrl: 'https://app.usenotifica.com.br/v1',
|
|
1904
|
+
* timeout: 15000,
|
|
1905
|
+
* maxRetries: 5,
|
|
1906
|
+
* });
|
|
1907
|
+
* ```
|
|
1908
|
+
*/
|
|
1909
|
+
constructor(apiKeyOrConfig: string | NotificaClientConfig);
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
export { Analytics, type AnalyticsOverview, type AnalyticsParams, type AnalyticsPeriod, ApiError, type ApiErrorBody, type ApiKey, type ApiKeyType, ApiKeys, Billing, type BillingAddress, type BillingFeatures, type BillingGatewayType, type BillingPlan, type BillingQuotas, type BillingSettings, type BillingTaxInfo, type BillingUsage, type BillingUsageMetrics, type BillingUsagePercentages, type BulkImportParams, type BulkImportResult, type BulkImportSmsConsentParams, type BulkImportSmsConsentResult, type CalculateProrationParams, type CalculateProrationResult, type CancelSubscriptionParams, type CardBrand, type ChangePlanParams, type Channel, type ChannelAnalytics, type ChannelConfiguration, Channels, type CreateApiKeyParams, type CreateCardParams, type CreateChannelParams, type CreateDomainParams, type CreatePaymentMethodParams, type CreateSmsConsentParams, type CreateSmsProviderParams, type CreateSubscriberParams, type CreateTemplateParams, type CreateWebhookParams, type CreateWorkflowParams, type CustomSmsConfig, type DelayStep, type DnsRecord, type Domain, type DomainAlert, type DomainHealth, type DomainStatus, Domains, type Environment, type FallbackStep, type Granularity, type InAppNotification, Inbox, InboxEmbed, type InboxEmbedSettings, type InboxNotification, type InboxUnreadCountResult, type Invoice, type InvoiceStatus, type ListComplianceLogsParams, type ListDeliveriesParams, type ListDomainsParams, type ListInAppParams, type ListInboxNotificationsParams, type ListInvoicesParams, type ListNotificationsParams, type ListSmsConsentsParams, type ListSubscribersParams, type ListTemplatesParams, type ListWebhooksParams, type ListWorkflowRunsParams, type ListWorkflowsParams, type MarkInboxReadAllResult, type MarkInboxReadResult, type MessageAttempt, Notifica, NotificaClient, type NotificaClientConfig, NotificaError, type Notification, type NotificationPreference, type NotificationStatus, Notifications, type PaginatedResponse, type PaginationMeta, type PaginationParams, type PaymentMethod, type PaymentMethodCard, type PaymentMethodType, type PreviewContentParams, type PreviewResult, type PreviewTemplateParams, RateLimitError, type ReactivateSubscriptionParams, type RequestOptions, type RotateEmbedKeyResult, type SendNotificationParams, type SendStep, type SingleResponse, Sms, type SmsComplianceAnalytics, type SmsComplianceLog, type SmsComplianceSettings, type SmsConsent, type SmsConsentSource, type SmsConsentStatus, type SmsConsentSummary, type SmsProvider, type SmsProviderConfig, type SmsProviderType, type StepResult, type SubscribeParams, type Subscriber, type SubscriberPreferences, Subscribers, type Subscription, type SubscriptionPeriod, type SubscriptionStatus, type Template, type TemplateAnalytics, type TemplateStatus, Templates, type TestChannelResult, type TestSmsProviderParams, type TestSmsProviderResult, TimeoutError, type TimeseriesParams, type TimeseriesPoint, type TopTemplatesParams, type TriggerWorkflowParams, type TwilioConfig, type UnreadCountResult, type UpdateChannelParams, type UpdateInboxEmbedSettingsParams, type UpdatePaymentMethodParams, type UpdatePreferencesParams, type UpdateSmsComplianceParams, type UpdateSmsProviderParams, type UpdateSubscriberParams, type UpdateTemplateParams, type UpdateWebhookParams, type UpdateWorkflowParams, type ValidateContentParams, type ValidateSmsProviderParams, type ValidateSmsProviderResult, ValidationError, type ValidationResult, type Webhook, type WebhookDelivery, Webhooks, type Workflow, type WorkflowRun, type WorkflowRunStatus, type WorkflowStep, Workflows, type ZenviaConfig };
|