@cabrapi/sdk 1.0.0-alpha.0 → 1.0.0-alpha.2
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 +201 -0
- package/dist/index.cjs +2 -184
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +728 -18
- package/dist/index.d.ts +728 -18
- package/dist/index.js +2 -147
- package/dist/index.js.map +1 -1
- package/package.json +12 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,43 @@
|
|
|
1
|
-
import { AxiosInstance as AxiosInstance$1 } from 'axios';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
|
-
*
|
|
2
|
+
* Adapter HTTP simples usando fetch (nativo).
|
|
3
|
+
* Exporta `createAxios` para compatibilidade com restante do código.
|
|
5
4
|
*/
|
|
6
5
|
type AxiosConfig = {
|
|
7
|
-
/**
|
|
8
|
-
* URL base da API.
|
|
9
|
-
* @default "https://api.cabrapi.com.br"
|
|
10
|
-
*/
|
|
11
6
|
baseURL?: string;
|
|
12
|
-
/**
|
|
13
|
-
* Chave da API (modo privado).
|
|
14
|
-
*/
|
|
15
7
|
apiKey?: string;
|
|
8
|
+
timeout?: number;
|
|
9
|
+
};
|
|
10
|
+
type AxiosRequestConfig = {
|
|
11
|
+
url?: string;
|
|
12
|
+
params?: Record<string, unknown>;
|
|
13
|
+
headers?: Record<string, string>;
|
|
14
|
+
data?: unknown;
|
|
15
|
+
timeout?: number;
|
|
16
|
+
};
|
|
17
|
+
type AxiosResponse<T = unknown> = {
|
|
18
|
+
data: T;
|
|
19
|
+
status: number;
|
|
20
|
+
statusText: string;
|
|
21
|
+
headers: Record<string, string>;
|
|
22
|
+
config?: AxiosRequestConfig;
|
|
23
|
+
};
|
|
24
|
+
declare function createAxios(cfg?: AxiosConfig): {
|
|
25
|
+
interceptors: {
|
|
26
|
+
request: {
|
|
27
|
+
use(fulfilled: (c: AxiosRequestConfig) => AxiosRequestConfig | Promise<AxiosRequestConfig>, rejected?: (e: unknown) => unknown): void;
|
|
28
|
+
};
|
|
29
|
+
response: {
|
|
30
|
+
use(fulfilled: (r: AxiosResponse) => AxiosResponse | Promise<AxiosResponse>, rejected?: (e: unknown) => unknown): void;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
get<T = unknown>(url: string, options?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
|
34
|
+
post<T = unknown>(url: string, data?: unknown, options?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
|
35
|
+
put<T = unknown>(url: string, data?: unknown, options?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
|
36
|
+
delete<T = unknown>(url: string, options?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
|
37
|
+
request<T = unknown>(options: AxiosRequestConfig & {
|
|
38
|
+
method: string;
|
|
39
|
+
}): Promise<AxiosResponse<T>>;
|
|
16
40
|
};
|
|
17
|
-
/**
|
|
18
|
-
* Cria uma instância HTTP configurada para a caBRAPI.
|
|
19
|
-
*/
|
|
20
|
-
declare function createAxios(config?: AxiosConfig): AxiosInstance$1;
|
|
21
41
|
|
|
22
42
|
/**
|
|
23
43
|
* Tipo derivado da instância do Axios
|
|
@@ -35,6 +55,7 @@ type ClientOptions = {
|
|
|
35
55
|
type: ClientMode;
|
|
36
56
|
config?: {
|
|
37
57
|
key?: string;
|
|
58
|
+
baseURL?: string;
|
|
38
59
|
};
|
|
39
60
|
};
|
|
40
61
|
/**
|
|
@@ -59,8 +80,181 @@ declare class CoreClient {
|
|
|
59
80
|
assertPrivate(): void;
|
|
60
81
|
}
|
|
61
82
|
|
|
83
|
+
type Category = {
|
|
84
|
+
id: string;
|
|
85
|
+
name: string;
|
|
86
|
+
description: string | null;
|
|
87
|
+
image: string | null;
|
|
88
|
+
metadata: Record<string, unknown> | null;
|
|
89
|
+
position: number;
|
|
90
|
+
storeId: string;
|
|
91
|
+
createdAt: string;
|
|
92
|
+
updatedAt: string;
|
|
93
|
+
};
|
|
94
|
+
type CategoryDetails = Category & {
|
|
95
|
+
products?: unknown[];
|
|
96
|
+
coupons?: unknown[];
|
|
97
|
+
};
|
|
98
|
+
type Pagination$4 = {
|
|
99
|
+
page: number;
|
|
100
|
+
limit: number;
|
|
101
|
+
total: number;
|
|
102
|
+
totalPages: number;
|
|
103
|
+
};
|
|
104
|
+
type GetCategoriesInput = {
|
|
105
|
+
page?: number;
|
|
106
|
+
limit?: number;
|
|
107
|
+
};
|
|
108
|
+
type CreateCategoryInput = {
|
|
109
|
+
name?: string;
|
|
110
|
+
description?: string | null;
|
|
111
|
+
image?: string | null;
|
|
112
|
+
metadata?: Record<string, unknown> | null;
|
|
113
|
+
};
|
|
114
|
+
type UpdateCategoryInput = {
|
|
115
|
+
name?: string;
|
|
116
|
+
description?: string | null;
|
|
117
|
+
image?: string | null;
|
|
118
|
+
metadata?: Record<string, unknown> | null;
|
|
119
|
+
position?: number;
|
|
120
|
+
};
|
|
121
|
+
type GetCategoriesResponse = {
|
|
122
|
+
status: boolean;
|
|
123
|
+
code: string;
|
|
124
|
+
categories: Category[];
|
|
125
|
+
pagination: Pagination$4;
|
|
126
|
+
};
|
|
127
|
+
type GetCategoryByIdResponse = {
|
|
128
|
+
status: boolean;
|
|
129
|
+
code: string;
|
|
130
|
+
category: CategoryDetails;
|
|
131
|
+
};
|
|
132
|
+
type CreateCategoryResponse = {
|
|
133
|
+
status: boolean;
|
|
134
|
+
code?: string;
|
|
135
|
+
category: Category;
|
|
136
|
+
};
|
|
137
|
+
type UpdateCategoryResponse = {
|
|
138
|
+
status: boolean;
|
|
139
|
+
code: string;
|
|
140
|
+
category: Category;
|
|
141
|
+
};
|
|
142
|
+
type DeleteCategoryResponse = {
|
|
143
|
+
status: boolean;
|
|
144
|
+
code: string;
|
|
145
|
+
};
|
|
146
|
+
type ReorderCategoriesResponse = {
|
|
147
|
+
status: boolean;
|
|
148
|
+
code: string;
|
|
149
|
+
};
|
|
150
|
+
declare class Categories {
|
|
151
|
+
private core;
|
|
152
|
+
constructor(core: CoreClient);
|
|
153
|
+
get(storeId: string, input?: GetCategoriesInput): Promise<GetCategoriesResponse>;
|
|
154
|
+
getById(storeId: string, categoryId: string): Promise<GetCategoryByIdResponse>;
|
|
155
|
+
post(storeId: string, input: CreateCategoryInput): Promise<CreateCategoryResponse>;
|
|
156
|
+
put(storeId: string, categoryId: string, input: UpdateCategoryInput): Promise<UpdateCategoryResponse>;
|
|
157
|
+
delete(storeId: string, categoryId: string): Promise<DeleteCategoryResponse>;
|
|
158
|
+
reorder(storeId: string, categoryIds: string[]): Promise<ReorderCategoriesResponse>;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
type CouponRelationRef = {
|
|
162
|
+
id: string;
|
|
163
|
+
name: string;
|
|
164
|
+
};
|
|
165
|
+
type Coupon = {
|
|
166
|
+
id: string;
|
|
167
|
+
code: string;
|
|
168
|
+
position: number;
|
|
169
|
+
discount: number;
|
|
170
|
+
useLimit: number;
|
|
171
|
+
expiredAt: string | null;
|
|
172
|
+
storeId?: string;
|
|
173
|
+
products: CouponRelationRef[];
|
|
174
|
+
categories: CouponRelationRef[];
|
|
175
|
+
createdAt?: string;
|
|
176
|
+
updatedAt?: string;
|
|
177
|
+
};
|
|
178
|
+
type Pagination$3 = {
|
|
179
|
+
page: number;
|
|
180
|
+
limit: number;
|
|
181
|
+
total: number;
|
|
182
|
+
totalPages: number;
|
|
183
|
+
};
|
|
184
|
+
type GetCouponsInput = {
|
|
185
|
+
page?: number;
|
|
186
|
+
limit?: number;
|
|
187
|
+
};
|
|
188
|
+
type CreateCouponInput = {
|
|
189
|
+
code: string;
|
|
190
|
+
discount: number;
|
|
191
|
+
useLimit?: number | null;
|
|
192
|
+
expiredAt?: string | null;
|
|
193
|
+
productIds?: string[];
|
|
194
|
+
categoryIds?: string[];
|
|
195
|
+
};
|
|
196
|
+
type UpdateCouponInput = {
|
|
197
|
+
code?: string;
|
|
198
|
+
discount?: number;
|
|
199
|
+
position?: number;
|
|
200
|
+
useLimit?: number | null;
|
|
201
|
+
expiredAt?: string | null;
|
|
202
|
+
productIds?: string[];
|
|
203
|
+
categoryIds?: string[];
|
|
204
|
+
};
|
|
205
|
+
type GetCouponsResponse = {
|
|
206
|
+
status: boolean;
|
|
207
|
+
code: string;
|
|
208
|
+
coupons: Coupon[];
|
|
209
|
+
pagination: Pagination$3;
|
|
210
|
+
};
|
|
211
|
+
type GetCouponByCodeResponse = {
|
|
212
|
+
status: boolean;
|
|
213
|
+
code: string;
|
|
214
|
+
coupon: Coupon;
|
|
215
|
+
};
|
|
216
|
+
type GetCouponByIdResponse = {
|
|
217
|
+
status: boolean;
|
|
218
|
+
code: string;
|
|
219
|
+
coupon: Coupon;
|
|
220
|
+
};
|
|
221
|
+
type CreateCouponResponse = {
|
|
222
|
+
status: boolean;
|
|
223
|
+
code: string;
|
|
224
|
+
coupon: Coupon;
|
|
225
|
+
};
|
|
226
|
+
type UpdateCouponResponse = {
|
|
227
|
+
status: boolean;
|
|
228
|
+
code: string;
|
|
229
|
+
coupon: Coupon;
|
|
230
|
+
};
|
|
231
|
+
type DeleteCouponResponse = {
|
|
232
|
+
status: boolean;
|
|
233
|
+
code: string;
|
|
234
|
+
};
|
|
235
|
+
type ReorderCouponsResponse = {
|
|
236
|
+
status: boolean;
|
|
237
|
+
code: string;
|
|
238
|
+
};
|
|
239
|
+
declare class Coupons {
|
|
240
|
+
private core;
|
|
241
|
+
constructor(core: CoreClient);
|
|
242
|
+
get(storeId: string, input?: GetCouponsInput): Promise<GetCouponsResponse>;
|
|
243
|
+
getByCode(storeId: string, code: string): Promise<GetCouponByCodeResponse>;
|
|
244
|
+
getById(storeId: string, couponId: string): Promise<GetCouponByIdResponse>;
|
|
245
|
+
post(storeId: string, input: CreateCouponInput): Promise<CreateCouponResponse>;
|
|
246
|
+
put(storeId: string, couponId: string, input: UpdateCouponInput): Promise<UpdateCouponResponse>;
|
|
247
|
+
delete(storeId: string, couponId: string): Promise<DeleteCouponResponse>;
|
|
248
|
+
reorder(storeId: string, couponIds: string[]): Promise<ReorderCouponsResponse>;
|
|
249
|
+
}
|
|
250
|
+
|
|
62
251
|
/**
|
|
63
|
-
*
|
|
252
|
+
* Modelo de página retornado pela API de páginas.
|
|
253
|
+
*
|
|
254
|
+
* Observações:
|
|
255
|
+
* - Campos `createdAt` e `updatedAt` são timestamps em ISO 8601.
|
|
256
|
+
* - `version` pode ser usada pelo servidor para controle de versão do conteúdo.
|
|
257
|
+
* - `store` é metadado opcional com informações da loja proprietária.
|
|
64
258
|
*/
|
|
65
259
|
type Page = {
|
|
66
260
|
html: string;
|
|
@@ -70,26 +264,542 @@ type Page = {
|
|
|
70
264
|
updatedAt?: string;
|
|
71
265
|
store?: {
|
|
72
266
|
ownerId: string;
|
|
267
|
+
id: string;
|
|
73
268
|
};
|
|
74
269
|
};
|
|
75
270
|
|
|
271
|
+
/**
|
|
272
|
+
* Client de alto nível para operações relacionadas a `Page`.
|
|
273
|
+
*
|
|
274
|
+
* Instancie com um `CoreClient` já autenticado/configurado. Os métodos desta
|
|
275
|
+
* classe são pequenos wrappers que delegam a execução para as funções HTTP
|
|
276
|
+
* específicas em `./http/*`, mantendo a assinatura orientada ao domínio.
|
|
277
|
+
*/
|
|
76
278
|
declare class Pages {
|
|
77
279
|
private core;
|
|
280
|
+
/**
|
|
281
|
+
* Construtor.
|
|
282
|
+
* @param core - Instância de `CoreClient` usada para efetuar chamadas HTTP.
|
|
283
|
+
*/
|
|
78
284
|
constructor(core: CoreClient);
|
|
79
|
-
|
|
285
|
+
/**
|
|
286
|
+
* Recupera a página associada ao `domain` informado.
|
|
287
|
+
*
|
|
288
|
+
* @param domain - Identificador da página a recuperar (ex.: "exemplo.com").
|
|
289
|
+
* @returns Uma promise que resolve com o objeto `Page` caso exista.
|
|
290
|
+
* @throws Erros de rede/HTTP ou erro retornado pela API se a página não existir.
|
|
291
|
+
*
|
|
292
|
+
*/
|
|
293
|
+
get(domain: string): Promise<{
|
|
294
|
+
status: boolean;
|
|
295
|
+
data: Page;
|
|
296
|
+
}>;
|
|
297
|
+
/**
|
|
298
|
+
* Cria ou atualiza uma página.
|
|
299
|
+
*
|
|
300
|
+
* Se a página para o `domain` já existir, o servidor realizará um update;
|
|
301
|
+
* caso contrário, criará uma nova entrada.
|
|
302
|
+
*
|
|
303
|
+
* @param input - Objeto com os dados da página:
|
|
304
|
+
* - `domain`: chave única da página.
|
|
305
|
+
* - `html`: conteúdo HTML completo.
|
|
306
|
+
* - `template` (opcional): nome do template a aplicar.
|
|
307
|
+
* @returns Uma promise que resolve com o `Page` criado/atualizado ou com metadados retornados pela API.
|
|
308
|
+
* @throws Erros de validação, rede ou HTTP conforme a resposta da API.
|
|
309
|
+
*
|
|
310
|
+
*/
|
|
80
311
|
upsert(input: {
|
|
81
312
|
domain: string;
|
|
82
313
|
html: string;
|
|
83
314
|
template?: string;
|
|
84
|
-
}): Promise<
|
|
85
|
-
|
|
315
|
+
}): Promise<{
|
|
316
|
+
status: boolean;
|
|
317
|
+
code: string;
|
|
318
|
+
}>;
|
|
319
|
+
/**
|
|
320
|
+
* Remove a página associada ao `domain`.
|
|
321
|
+
*
|
|
322
|
+
* @param domain - Identificador da página a remover.
|
|
323
|
+
* @returns Uma promise que resolve quando a exclusão for confirmada pelo servidor.
|
|
324
|
+
* @throws Erro se a operação falhar (por exemplo, página não encontrada ou erro de permissão).
|
|
325
|
+
*
|
|
326
|
+
*/
|
|
327
|
+
delete(domain: string): Promise<{
|
|
328
|
+
status: boolean;
|
|
329
|
+
code: string;
|
|
330
|
+
}>;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
type PaymentStatus = "PENDING" | "APPROVED" | "REJECTED" | "CANCELLED" | "REFUNDED" | "CHARGED_BACK" | "EXPIRED";
|
|
334
|
+
type PaymentGateway = "MERCADOPAGO" | "EFI_BANK";
|
|
335
|
+
type PaymentCreateGateway = "MERCADOPAGO_SERVICE_PIX" | "MERCADOPAGO_SERVICE_CARD";
|
|
336
|
+
type PaymentShipmentStatus = "PENDING" | "PREPARING" | "SHIPPED" | "DELIVERED" | "RETURNED" | "CANCELLED";
|
|
337
|
+
type PaymentSortBy = "createdAt" | "updatedAt" | "price" | "name" | "email";
|
|
338
|
+
type PaymentSortOrder = "asc" | "desc";
|
|
339
|
+
type Payment = {
|
|
340
|
+
id: string;
|
|
341
|
+
uuid: string;
|
|
342
|
+
status: PaymentStatus;
|
|
343
|
+
name?: string;
|
|
344
|
+
email?: string;
|
|
345
|
+
cpf?: string | null;
|
|
346
|
+
price?: number;
|
|
347
|
+
gateway?: PaymentGateway;
|
|
348
|
+
shipment?: PaymentShipmentStatus;
|
|
349
|
+
storeId: string;
|
|
350
|
+
metadata?: Record<string, unknown> | null;
|
|
351
|
+
};
|
|
352
|
+
type Pagination$2 = {
|
|
353
|
+
page: number;
|
|
354
|
+
limit: number;
|
|
355
|
+
total: number;
|
|
356
|
+
totalPages: number;
|
|
357
|
+
};
|
|
358
|
+
type FilterPaymentsInput = {
|
|
359
|
+
id?: string;
|
|
360
|
+
uuid?: string;
|
|
361
|
+
status?: PaymentStatus;
|
|
362
|
+
name?: string;
|
|
363
|
+
email?: string;
|
|
364
|
+
cpf?: string;
|
|
365
|
+
price?: number;
|
|
366
|
+
minPrice?: number;
|
|
367
|
+
maxPrice?: number;
|
|
368
|
+
coupon?: boolean;
|
|
369
|
+
gateway?: PaymentGateway;
|
|
370
|
+
shipment?: PaymentShipmentStatus;
|
|
371
|
+
createdAtFrom?: string;
|
|
372
|
+
createdAtTo?: string;
|
|
373
|
+
updatedAtFrom?: string;
|
|
374
|
+
updatedAtTo?: string;
|
|
375
|
+
productId?: string;
|
|
376
|
+
metadataKey?: string;
|
|
377
|
+
metadataValue?: string;
|
|
378
|
+
sortBy?: PaymentSortBy;
|
|
379
|
+
sortOrder?: PaymentSortOrder;
|
|
380
|
+
page?: number;
|
|
381
|
+
limit?: number;
|
|
382
|
+
};
|
|
383
|
+
type FilterPaymentsResponse = {
|
|
384
|
+
status: boolean;
|
|
385
|
+
code: string;
|
|
386
|
+
payments: Payment[];
|
|
387
|
+
pagination: Pagination$2;
|
|
388
|
+
};
|
|
389
|
+
type GetPaymentsInput = {
|
|
390
|
+
page?: number;
|
|
391
|
+
limit?: number;
|
|
392
|
+
};
|
|
393
|
+
type GetPaymentsResponse = {
|
|
394
|
+
status: boolean;
|
|
395
|
+
code: string;
|
|
396
|
+
payments: Payment[];
|
|
397
|
+
pagination: Pagination$2;
|
|
398
|
+
};
|
|
399
|
+
type CreatePaymentItemInput = {
|
|
400
|
+
productId: string;
|
|
401
|
+
quantity: number;
|
|
402
|
+
};
|
|
403
|
+
type CreatePaymentInput = {
|
|
404
|
+
name: string;
|
|
405
|
+
email: string;
|
|
406
|
+
cpf?: string;
|
|
407
|
+
gateway: PaymentCreateGateway;
|
|
408
|
+
coupon?: string | null;
|
|
409
|
+
metadata?: Record<string, unknown>;
|
|
410
|
+
items: CreatePaymentItemInput[];
|
|
411
|
+
};
|
|
412
|
+
type CreatePaymentResponse = {
|
|
413
|
+
status: boolean;
|
|
414
|
+
data: {
|
|
415
|
+
service: {
|
|
416
|
+
type: string;
|
|
417
|
+
method: string;
|
|
418
|
+
payment: string;
|
|
419
|
+
};
|
|
420
|
+
payment: {
|
|
421
|
+
uuid: string;
|
|
422
|
+
url?: string;
|
|
423
|
+
qr_code?: {
|
|
424
|
+
image: string;
|
|
425
|
+
base_64: string;
|
|
426
|
+
};
|
|
427
|
+
};
|
|
428
|
+
};
|
|
429
|
+
};
|
|
430
|
+
type UpdatePaymentInput = {
|
|
431
|
+
shipment?: PaymentShipmentStatus;
|
|
432
|
+
metadata?: Record<string, unknown>;
|
|
433
|
+
};
|
|
434
|
+
type UpdatePaymentResponse = {
|
|
435
|
+
status: boolean;
|
|
436
|
+
code: string;
|
|
437
|
+
payment: {
|
|
438
|
+
id: string;
|
|
439
|
+
status: PaymentStatus;
|
|
440
|
+
shipment?: PaymentShipmentStatus;
|
|
441
|
+
metadata?: Record<string, unknown> | null;
|
|
442
|
+
};
|
|
443
|
+
};
|
|
444
|
+
type DeletePaymentResponse = {
|
|
445
|
+
status: boolean;
|
|
446
|
+
code: string;
|
|
447
|
+
message: string;
|
|
448
|
+
};
|
|
449
|
+
declare class Payments {
|
|
450
|
+
private core;
|
|
451
|
+
constructor(core: CoreClient);
|
|
452
|
+
get(storeId: string, input?: GetPaymentsInput): Promise<GetPaymentsResponse>;
|
|
453
|
+
filter(storeId: string, input?: FilterPaymentsInput): Promise<FilterPaymentsResponse>;
|
|
454
|
+
post(storeId: string, input: CreatePaymentInput): Promise<CreatePaymentResponse>;
|
|
455
|
+
put(storeId: string, paymentId: string, input: UpdatePaymentInput): Promise<UpdatePaymentResponse>;
|
|
456
|
+
delete(storeId: string, paymentId: string): Promise<DeletePaymentResponse>;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
type ProductDelivery = "DIGITAL" | "PHYSICAL";
|
|
460
|
+
type ProductCategoryRef = {
|
|
461
|
+
id: string;
|
|
462
|
+
name: string;
|
|
463
|
+
};
|
|
464
|
+
type Product = {
|
|
465
|
+
id: string;
|
|
466
|
+
name: string;
|
|
467
|
+
disabled: boolean;
|
|
468
|
+
position: number;
|
|
469
|
+
description: string | null;
|
|
470
|
+
price: number;
|
|
471
|
+
image: string | null;
|
|
472
|
+
delivery: ProductDelivery;
|
|
473
|
+
stock: number;
|
|
474
|
+
sold: number;
|
|
475
|
+
storeId: string;
|
|
476
|
+
metadata: Record<string, unknown> | null;
|
|
477
|
+
createdAt: string;
|
|
478
|
+
updatedAt: string;
|
|
479
|
+
categories?: ProductCategoryRef[];
|
|
480
|
+
};
|
|
481
|
+
type Pagination$1 = {
|
|
482
|
+
page: number;
|
|
483
|
+
limit: number;
|
|
484
|
+
total: number;
|
|
485
|
+
totalPages: number;
|
|
486
|
+
};
|
|
487
|
+
type GetProductsInput = {
|
|
488
|
+
page?: number;
|
|
489
|
+
limit?: number;
|
|
490
|
+
};
|
|
491
|
+
type CreateProductInput = {
|
|
492
|
+
name: string;
|
|
493
|
+
image?: string | null;
|
|
494
|
+
description?: string | null;
|
|
495
|
+
categoryIds?: string[];
|
|
496
|
+
delivery: ProductDelivery;
|
|
497
|
+
price: number;
|
|
498
|
+
stock?: number;
|
|
499
|
+
disabled?: boolean;
|
|
500
|
+
metadata?: Record<string, unknown> | null;
|
|
501
|
+
};
|
|
502
|
+
type UpdateProductInput = {
|
|
503
|
+
name?: string;
|
|
504
|
+
image?: string | null;
|
|
505
|
+
description?: string | null;
|
|
506
|
+
categoryIds?: string[];
|
|
507
|
+
delivery?: ProductDelivery;
|
|
508
|
+
price?: number;
|
|
509
|
+
stock?: number;
|
|
510
|
+
disabled?: boolean;
|
|
511
|
+
position?: number;
|
|
512
|
+
metadata?: Record<string, unknown> | null;
|
|
513
|
+
};
|
|
514
|
+
type GetProductsResponse = {
|
|
515
|
+
status: boolean;
|
|
516
|
+
code: string;
|
|
517
|
+
products: Product[];
|
|
518
|
+
pagination: Pagination$1;
|
|
519
|
+
};
|
|
520
|
+
type GetProductByIdResponse = {
|
|
521
|
+
status: boolean;
|
|
522
|
+
code: string;
|
|
523
|
+
product: Product;
|
|
524
|
+
};
|
|
525
|
+
type CreateProductResponse = {
|
|
526
|
+
status: boolean;
|
|
527
|
+
code: string;
|
|
528
|
+
product: Product;
|
|
529
|
+
};
|
|
530
|
+
type UpdateProductResponse = {
|
|
531
|
+
status: boolean;
|
|
532
|
+
code: string;
|
|
533
|
+
product: Product;
|
|
534
|
+
};
|
|
535
|
+
type DeleteProductResponse = {
|
|
536
|
+
status: boolean;
|
|
537
|
+
code: string;
|
|
538
|
+
};
|
|
539
|
+
type ReorderProductsResponse = {
|
|
540
|
+
status: boolean;
|
|
541
|
+
code: string;
|
|
542
|
+
};
|
|
543
|
+
declare class Products {
|
|
544
|
+
private core;
|
|
545
|
+
constructor(core: CoreClient);
|
|
546
|
+
get(storeId: string, input?: GetProductsInput): Promise<GetProductsResponse>;
|
|
547
|
+
getById(storeId: string, productId: string): Promise<GetProductByIdResponse>;
|
|
548
|
+
post(storeId: string, input: CreateProductInput): Promise<CreateProductResponse>;
|
|
549
|
+
put(storeId: string, productId: string, input: UpdateProductInput): Promise<UpdateProductResponse>;
|
|
550
|
+
delete(storeId: string, productId: string): Promise<DeleteProductResponse>;
|
|
551
|
+
reorder(storeId: string, productIds: string[]): Promise<ReorderProductsResponse>;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Templates válidos para loja.
|
|
556
|
+
*/
|
|
557
|
+
type StoreTemplate = "PERSONALIZADO" | "N/A";
|
|
558
|
+
/**
|
|
559
|
+
* Tipo do domínio informado no payload da loja.
|
|
560
|
+
*/
|
|
561
|
+
type StoreDomainType = "CUSTOM" | "DEFAULT";
|
|
562
|
+
/**
|
|
563
|
+
* Estrutura de domínio para criação/atualização.
|
|
564
|
+
*/
|
|
565
|
+
type StoreDomainInput = {
|
|
566
|
+
type: StoreDomainType;
|
|
567
|
+
value: string;
|
|
568
|
+
};
|
|
569
|
+
/**
|
|
570
|
+
* Modelo base de loja retornado nos endpoints de listagem e upsert.
|
|
571
|
+
*/
|
|
572
|
+
type Store = {
|
|
573
|
+
id: string;
|
|
574
|
+
name: string;
|
|
575
|
+
position: number;
|
|
576
|
+
description: string | null;
|
|
577
|
+
image: string | null;
|
|
578
|
+
domain: string;
|
|
579
|
+
template: StoreTemplate;
|
|
580
|
+
metadata: Record<string, unknown> | null;
|
|
581
|
+
createdAt: string;
|
|
582
|
+
updatedAt: string;
|
|
583
|
+
};
|
|
584
|
+
/**
|
|
585
|
+
* Modelo detalhado retornado por `GET /stores/:storeId`.
|
|
586
|
+
*/
|
|
587
|
+
type StoreDetails = Store & {
|
|
588
|
+
ownerId?: string;
|
|
589
|
+
deletedAt?: string | null;
|
|
590
|
+
categories?: unknown[];
|
|
591
|
+
products?: unknown[];
|
|
592
|
+
coupons?: unknown[];
|
|
593
|
+
payment?: unknown[];
|
|
594
|
+
};
|
|
595
|
+
/**
|
|
596
|
+
* Metadados de paginação padrão da API.
|
|
597
|
+
*/
|
|
598
|
+
type Pagination = {
|
|
599
|
+
page: number;
|
|
600
|
+
limit: number;
|
|
601
|
+
total: number;
|
|
602
|
+
totalPages: number;
|
|
603
|
+
};
|
|
604
|
+
/**
|
|
605
|
+
* Query params de listagem de lojas.
|
|
606
|
+
*/
|
|
607
|
+
type GetStoresInput = {
|
|
608
|
+
page?: number;
|
|
609
|
+
limit?: number;
|
|
610
|
+
};
|
|
611
|
+
/**
|
|
612
|
+
* Payload para criação de loja (`POST /stores`).
|
|
613
|
+
*/
|
|
614
|
+
type CreateStoreInput = {
|
|
615
|
+
template: StoreTemplate;
|
|
616
|
+
name?: string;
|
|
617
|
+
description?: string | null;
|
|
618
|
+
image?: string | null;
|
|
619
|
+
metadata?: Record<string, unknown> | null;
|
|
620
|
+
domain?: StoreDomainInput | null;
|
|
621
|
+
position?: number;
|
|
622
|
+
};
|
|
623
|
+
/**
|
|
624
|
+
* Payload para atualização de loja (`PUT /stores/:storeId`).
|
|
625
|
+
*
|
|
626
|
+
* Observação: no endpoint de update, todos os campos são opcionais,
|
|
627
|
+
* mas a API exige ao menos 1 campo no body.
|
|
628
|
+
*/
|
|
629
|
+
type UpdateStoreInput = {
|
|
630
|
+
template?: StoreTemplate;
|
|
631
|
+
name?: string;
|
|
632
|
+
description?: string | null;
|
|
633
|
+
image?: string | null;
|
|
634
|
+
metadata?: Record<string, unknown> | null;
|
|
635
|
+
domain?: StoreDomainInput | null;
|
|
636
|
+
position?: number;
|
|
637
|
+
};
|
|
638
|
+
/**
|
|
639
|
+
* Resposta de listagem de lojas.
|
|
640
|
+
*/
|
|
641
|
+
type GetStoresResponse = {
|
|
642
|
+
status: boolean;
|
|
643
|
+
code: string;
|
|
644
|
+
stores: Store[];
|
|
645
|
+
pagination: Pagination;
|
|
646
|
+
};
|
|
647
|
+
/**
|
|
648
|
+
* Resposta de consulta por ID.
|
|
649
|
+
*/
|
|
650
|
+
type GetStoreByIdResponse = {
|
|
651
|
+
status: boolean;
|
|
652
|
+
code: string;
|
|
653
|
+
store: StoreDetails;
|
|
654
|
+
};
|
|
655
|
+
/**
|
|
656
|
+
* Resposta de criação.
|
|
657
|
+
*/
|
|
658
|
+
type CreateStoreResponse = {
|
|
659
|
+
status: boolean;
|
|
660
|
+
code: string;
|
|
661
|
+
store: Store;
|
|
662
|
+
};
|
|
663
|
+
/**
|
|
664
|
+
* Resposta de atualização.
|
|
665
|
+
*/
|
|
666
|
+
type UpdateStoreResponse = {
|
|
667
|
+
status: boolean;
|
|
668
|
+
code: string;
|
|
669
|
+
store: Store;
|
|
670
|
+
};
|
|
671
|
+
/**
|
|
672
|
+
* Resposta de exclusão.
|
|
673
|
+
*/
|
|
674
|
+
type DeleteStoreResponse = {
|
|
675
|
+
status: boolean;
|
|
676
|
+
code: string;
|
|
677
|
+
};
|
|
678
|
+
/**
|
|
679
|
+
* Resposta de reordenação.
|
|
680
|
+
*/
|
|
681
|
+
type ReorderStoresResponse = {
|
|
682
|
+
status: boolean;
|
|
683
|
+
code: string;
|
|
684
|
+
};
|
|
685
|
+
/**
|
|
686
|
+
* Cliente de alto nível para operações do módulo de lojas.
|
|
687
|
+
*/
|
|
688
|
+
declare class Stores {
|
|
689
|
+
private core;
|
|
690
|
+
/**
|
|
691
|
+
* @param core Cliente base da SDK.
|
|
692
|
+
*/
|
|
693
|
+
constructor(core: CoreClient);
|
|
694
|
+
/**
|
|
695
|
+
* Lista lojas da conta com suporte a paginação.
|
|
696
|
+
*/
|
|
697
|
+
get(input?: GetStoresInput): Promise<GetStoresResponse>;
|
|
698
|
+
/**
|
|
699
|
+
* Busca uma loja pelo ID.
|
|
700
|
+
*/
|
|
701
|
+
getById(storeId: string): Promise<GetStoreByIdResponse>;
|
|
702
|
+
/**
|
|
703
|
+
* Cria uma nova loja.
|
|
704
|
+
*/
|
|
705
|
+
post(input: CreateStoreInput): Promise<CreateStoreResponse>;
|
|
706
|
+
/**
|
|
707
|
+
* Atualiza uma loja existente.
|
|
708
|
+
*/
|
|
709
|
+
put(storeId: string, input: UpdateStoreInput): Promise<UpdateStoreResponse>;
|
|
710
|
+
/**
|
|
711
|
+
* Exclui uma loja pelo ID.
|
|
712
|
+
*/
|
|
713
|
+
delete(storeId: string): Promise<DeleteStoreResponse>;
|
|
714
|
+
/**
|
|
715
|
+
* Reordena lojas pelo array final de IDs.
|
|
716
|
+
*/
|
|
717
|
+
reorder(storeIds: string[]): Promise<ReorderStoresResponse>;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
* Resposta de listagem de webhooks por loja.
|
|
722
|
+
*/
|
|
723
|
+
type GetWebhooksResponse = {
|
|
724
|
+
webhooks: string[];
|
|
725
|
+
max: number;
|
|
726
|
+
};
|
|
727
|
+
/**
|
|
728
|
+
* Payload para criar webhook em uma loja.
|
|
729
|
+
*/
|
|
730
|
+
type CreateWebhookInput = {
|
|
731
|
+
url: string;
|
|
732
|
+
};
|
|
733
|
+
/**
|
|
734
|
+
* Resposta de criação de webhook.
|
|
735
|
+
*/
|
|
736
|
+
type CreateWebhookResponse = {
|
|
737
|
+
status: boolean;
|
|
738
|
+
code: string;
|
|
739
|
+
webhook: string;
|
|
740
|
+
};
|
|
741
|
+
/**
|
|
742
|
+
* Payload para remover webhook de uma loja.
|
|
743
|
+
*/
|
|
744
|
+
type DeleteWebhookInput = {
|
|
745
|
+
url: string;
|
|
746
|
+
};
|
|
747
|
+
/**
|
|
748
|
+
* Resposta de remoção de webhook.
|
|
749
|
+
*/
|
|
750
|
+
type DeleteWebhookResponse = {
|
|
751
|
+
status: boolean;
|
|
752
|
+
code: string;
|
|
753
|
+
};
|
|
754
|
+
/**
|
|
755
|
+
* Cliente de alto nível para operações de webhooks da loja.
|
|
756
|
+
*/
|
|
757
|
+
declare class Webhooks {
|
|
758
|
+
private core;
|
|
759
|
+
/**
|
|
760
|
+
* @param core Cliente base da SDK.
|
|
761
|
+
*/
|
|
762
|
+
constructor(core: CoreClient);
|
|
763
|
+
/**
|
|
764
|
+
* Lista os webhooks cadastrados para uma loja.
|
|
765
|
+
*/
|
|
766
|
+
get(storeId: string): Promise<GetWebhooksResponse>;
|
|
767
|
+
/**
|
|
768
|
+
* Adiciona um webhook em uma loja.
|
|
769
|
+
*/
|
|
770
|
+
post(storeId: string, input: CreateWebhookInput): Promise<CreateWebhookResponse>;
|
|
771
|
+
/**
|
|
772
|
+
* Remove um webhook de uma loja.
|
|
773
|
+
*/
|
|
774
|
+
delete(storeId: string, input: DeleteWebhookInput): Promise<DeleteWebhookResponse>;
|
|
775
|
+
/**
|
|
776
|
+
* Descriptografa e valida o payload recebido no webhook de assinatura.
|
|
777
|
+
*
|
|
778
|
+
* Espera um payload no formato `iv:encrypted` (ambos em base64), criptografado
|
|
779
|
+
* com AES-256-CBC usando a chave informada.
|
|
780
|
+
*/
|
|
781
|
+
decrypty(secret: string, payload: string): Promise<Record<string, unknown>>;
|
|
782
|
+
/**
|
|
783
|
+
* Alias com nome corrigido para descriptografar payload de webhook.
|
|
784
|
+
*/
|
|
785
|
+
decrypt(secret: string, payload: string): Promise<Record<string, unknown>>;
|
|
786
|
+
/**
|
|
787
|
+
* Alias retrocompatível para quem já usa `parseSubscriptionPayload`.
|
|
788
|
+
*/
|
|
789
|
+
parseSubscriptionPayload(payload: string, secret: string): Promise<Record<string, unknown>>;
|
|
86
790
|
}
|
|
87
791
|
|
|
88
792
|
/**
|
|
89
793
|
* SDK principal da caBRAPI
|
|
90
794
|
*/
|
|
91
795
|
declare class caBRAPI {
|
|
796
|
+
categories: Categories;
|
|
797
|
+
coupons: Coupons;
|
|
798
|
+
payments: Payments;
|
|
92
799
|
pages: Pages;
|
|
800
|
+
products: Products;
|
|
801
|
+
stores: Stores;
|
|
802
|
+
webhooks: Webhooks;
|
|
93
803
|
constructor(options: ClientOptions);
|
|
94
804
|
}
|
|
95
805
|
|