@agenus-io/webhook-centralizer 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,350 @@
1
+ # Webhook Centralizer SDK
2
+
3
+ SDK para centralização de webhooks focado atualmente em plataformas de pagamentos.
4
+
5
+ ## Instalação
6
+
7
+ ```bash
8
+ npm install @agenus-io/webhook-centralizer
9
+ # ou
10
+ yarn add @agenus-io/webhook-centralizer
11
+ # ou
12
+ pnpm add @agenus-io/webhook-centralizer
13
+ ```
14
+
15
+ ## Funcionalidades
16
+
17
+ Este SDK fornece funcionalidades para centralização de webhooks de plataformas de pagamentos, permitindo:
18
+
19
+ 1. **Gerenciamento de Configurações**: CRUD completo de configurações de webhooks
20
+ 2. **Processamento de Webhooks**: Recebimento e processamento de webhooks de plataformas de pagamento via AWS SQS
21
+
22
+ ## Uso
23
+
24
+ ### Configuração Inicial
25
+
26
+ ```typescript
27
+ import { WebhookCentralizerSDK } from "@agenus-io/webhook-centralizer";
28
+ import type { AWSConfig, Order } from "@agenus-io/webhook-centralizer";
29
+
30
+ // Configure o SDK com suas credenciais AWS e credenciais da aplicação
31
+ const config: AWSConfig = {
32
+ region: "us-east-1",
33
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
34
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
35
+ queueUrl: process.env.QUEUE_SALES_URL!,
36
+ };
37
+
38
+ const appId = process.env.APP_ID!;
39
+ const appToken = process.env.APP_TOKEN!;
40
+
41
+ const sdk = new WebhookCentralizerSDK(config, appId, appToken);
42
+ ```
43
+
44
+ ### 1. Processar Webhook de Pagamento
45
+
46
+ ```typescript
47
+ const order: Order = {
48
+ dispatch: "META", // "META", "GOOGLE" ou "TIKTOK"
49
+ event: "PURCHASE_COMPLETED", // ou "PURCHASE_PENDING"
50
+ checkout: "cartpanda",
51
+ orderId: "ORD-123456",
52
+ subscriptionId: "SUB-789012", // opcional
53
+ currency: "BRL",
54
+ valueGross: 347.0,
55
+ valueNet: 329.9,
56
+ createdAt: new Date(),
57
+
58
+ // Pixel IDs (opcional, dependendo da plataforma)
59
+ fbc: "fb.1.1733718123.uYhGtFdSLoPqWeRtYuIo", // Meta/Facebook
60
+ fbp: "fb.1.1733718123.4455667788", // Meta/Facebook
61
+ fbclid: "fbclid-value", // Meta/Facebook
62
+ gclid: "Cj0KCQi...", // Google
63
+ gbraid: "gbraid-value", // Google
64
+ wbraid: "wbraid-value", // Google
65
+
66
+ customer: {
67
+ email: "cliente@example.com",
68
+ externalId: "USR-123", // opcional
69
+ firstName: "João",
70
+ lastName: "Silva",
71
+ phone: "+55 11 99999-9999", // opcional
72
+ city: "São Paulo", // opcional
73
+ state: "SP", // opcional
74
+ zipCode: "01310-100", // opcional
75
+ country: "BR", // opcional
76
+ ip: "189.45.201.77", // opcional
77
+ userAgent: "Mozilla/5.0...", // opcional
78
+ },
79
+
80
+ products: [
81
+ {
82
+ id: "PROD-001",
83
+ title: "Produto 1",
84
+ externalId: "EXT-001",
85
+ quantity: 2,
86
+ },
87
+ {
88
+ id: "PROD-002",
89
+ title: "Produto 2",
90
+ externalId: "EXT-002",
91
+ quantity: 1,
92
+ },
93
+ ],
94
+ };
95
+
96
+ try {
97
+ await sdk.SendOrder({
98
+ workspaceId: "workspace-123",
99
+ order,
100
+ });
101
+ console.log("Venda enviada com sucesso!");
102
+ } catch (error) {
103
+ console.error("Erro ao enviar venda:", error);
104
+ }
105
+ ```
106
+
107
+ ### 2. Gerenciar Configurações de Webhooks
108
+
109
+ #### Criar Configuração de Webhook
110
+
111
+ ```typescript
112
+ await sdk.Create({
113
+ workspaceId: "workspace-123",
114
+ data: {
115
+ title: "Pixel Meta",
116
+ status: true,
117
+ sendLead: true,
118
+ sendLeadText: "Lead capturado",
119
+ addToCart: true,
120
+ addToCartText: "Produto adicionado ao carrinho",
121
+ initiateCheckout: true,
122
+ initiateCheckoutDetection: "AUTOMATIC",
123
+ initiateCheckoutDetectionText: undefined,
124
+ purchaseSendType: "SALES_APPROVED",
125
+ purchaseValueType: "SALE_VALUE",
126
+ type: "META",
127
+ productIds: ["prod-1", "prod-2"],
128
+ sendIp: "IPV6_AND_IPV4",
129
+ pixelMeta: [
130
+ {
131
+ id: "pixel-id-123",
132
+ title: "Pixel Principal",
133
+ token: "pixel-token-123",
134
+ },
135
+ ],
136
+ },
137
+ });
138
+ ```
139
+
140
+ #### Listar Configurações de Webhooks
141
+
142
+ ```typescript
143
+ const result = await sdk.Get({
144
+ workSpaceId: "workspace-123",
145
+ page: 1,
146
+ pageSize: 10,
147
+ filter: undefined, // opcional
148
+ });
149
+
150
+ console.log(result.data); // Array de configurações de webhooks
151
+ console.log(result.meta); // Metadados de paginação
152
+ ```
153
+
154
+ #### Buscar uma Configuração de Webhook Específica
155
+
156
+ ```typescript
157
+ const result = await sdk.GetOne({
158
+ id: "pixel-id-123",
159
+ workSpaceId: "workspace-123",
160
+ });
161
+
162
+ console.log(result.data); // Dados da configuração de webhook ou null
163
+ ```
164
+
165
+ #### Atualizar Configuração de Webhook
166
+
167
+ ```typescript
168
+ await sdk.Update({
169
+ id: "pixel-id-123",
170
+ workspaceId: "workspace-123",
171
+ data: {
172
+ title: "Pixel Atualizado",
173
+ status: false,
174
+ // Apenas os campos que deseja atualizar
175
+ },
176
+ });
177
+ ```
178
+
179
+ #### Deletar Configuração de Webhook
180
+
181
+ ```typescript
182
+ await sdk.Delete({
183
+ id: "pixel-id-123",
184
+ workspaceId: "workspace-123",
185
+ });
186
+ ```
187
+
188
+ ## Tipos Exportados
189
+
190
+ ### `MarketingPlatform`
191
+ ```typescript
192
+ type MarketingPlatform = "GOOGLE" | "META" | "TIKTOK";
193
+ ```
194
+
195
+ ### `PurchaseEventType`
196
+ ```typescript
197
+ type PurchaseEventType = "PURCHASE_PENDING" | "PURCHASE_COMPLETED";
198
+ ```
199
+
200
+ ### `PurchaseSendType`
201
+ ```typescript
202
+ type PurchaseSendType = "SALES_APPROVED" | "SALES_APPROVED_AND_PENDING";
203
+ ```
204
+
205
+ ### `PurchaseValueType`
206
+ ```typescript
207
+ type PurchaseValueType = "SALE_VALUE" | "COMMISSION";
208
+ ```
209
+
210
+ ### `PixelDetection`
211
+ ```typescript
212
+ type PixelDetection = "AUTOMATIC" | "CONTAINS_TEXT" | "CONTAINS_CSS" | "CONTAINS_URL";
213
+ ```
214
+
215
+ ### `SendIp`
216
+ ```typescript
217
+ type SendIp = "IPV6_AND_IPV4" | "ONLY_IPV6" | "DONT_SEND";
218
+ ```
219
+
220
+ ### `Order`
221
+ Estrutura completa de dados da venda (veja exemplo acima).
222
+
223
+ ### `AWSConfig`
224
+ Configuração necessária para conexão com AWS SQS:
225
+ - `region`: string - Região AWS
226
+ - `accessKeyId`: string - Access Key ID
227
+ - `secretAccessKey`: string - Secret Access Key
228
+ - `queueUrl`: string - URL da fila SQS
229
+
230
+ ### `SendSaleParams`
231
+ Parâmetros para envio de venda:
232
+ - `workspaceId`: string - ID do workspace
233
+ - `order`: Order - Dados da venda/pedido
234
+
235
+ ## Variáveis de Ambiente
236
+
237
+ As credenciais AWS e da aplicação devem ser fornecidas ao instanciar o SDK. Recomendamos usar variáveis de ambiente:
238
+
239
+ ```env
240
+ AWS_REGION=us-east-1
241
+ AWS_ACCESS_KEY_ID=AKIA...
242
+ AWS_SECRET_ACCESS_KEY=secret...
243
+ QUEUE_SALES_URL=https://sqs.us-east-1.amazonaws.com/123456789012/queue-name
244
+ APP_ID=your-app-id
245
+ APP_TOKEN=your-app-token
246
+ ```
247
+
248
+ ## Exemplo Completo
249
+
250
+ ```typescript
251
+ import { WebhookCentralizerSDK } from "@agenus-io/webhook-centralizer";
252
+ import type { AWSConfig, Order } from "@agenus-io/webhook-centralizer";
253
+
254
+ // 1. Configurar SDK
255
+ const config: AWSConfig = {
256
+ region: process.env.AWS_REGION!,
257
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
258
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
259
+ queueUrl: process.env.QUEUE_SALES_URL!,
260
+ };
261
+
262
+ const sdk = new WebhookCentralizerSDK(
263
+ config,
264
+ process.env.APP_ID!,
265
+ process.env.APP_TOKEN!
266
+ );
267
+
268
+ // 2. Mapear venda do seu sistema para o formato do SDK
269
+ function mapOrderToSDKFormat(order: YourOrderType): Order {
270
+ return {
271
+ dispatch: order.platform, // "META", "GOOGLE", ou "TIKTOK"
272
+ event: order.status === "completed" ? "PURCHASE_COMPLETED" : "PURCHASE_PENDING",
273
+ checkout: order.checkoutProvider,
274
+ orderId: order.id,
275
+ currency: order.currency,
276
+ valueGross: order.total,
277
+ valueNet: order.subtotal,
278
+ createdAt: order.createdAt,
279
+ customer: {
280
+ email: order.customer.email,
281
+ firstName: order.customer.firstName,
282
+ lastName: order.customer.lastName,
283
+ phone: order.customer.phone,
284
+ // ... outros campos opcionais
285
+ },
286
+ products: order.items.map(item => ({
287
+ id: item.productId,
288
+ title: item.title,
289
+ externalId: item.externalId,
290
+ quantity: item.quantity,
291
+ })),
292
+ };
293
+ }
294
+
295
+ // 3. Enviar venda
296
+ async function handleOrderCompleted(order: YourOrderType, workspaceId: string) {
297
+ const orderData = mapOrderToSDKFormat(order);
298
+
299
+ try {
300
+ await sdk.SendOrder({
301
+ workspaceId,
302
+ order: orderData,
303
+ });
304
+ console.log(`Venda ${order.id} enviada com sucesso!`);
305
+ } catch (error) {
306
+ console.error(`Erro ao enviar venda ${order.id}:`, error);
307
+ // Implemente sua lógica de retry ou notificação aqui
308
+ }
309
+ }
310
+
311
+ // 4. Exemplo de uso completo com gerenciamento de pixels
312
+ async function exemploCompleto() {
313
+ // Listar configurações de webhooks
314
+ const webhooks = await sdk.Get({
315
+ workSpaceId: "workspace-123",
316
+ page: 1,
317
+ pageSize: 10,
318
+ });
319
+
320
+ console.log(`Total de configurações de webhooks: ${webhooks.meta.total}`);
321
+
322
+ // Processar um webhook de pagamento
323
+ await handleOrderCompleted(myOrder, "workspace-123");
324
+ }
325
+ ```
326
+
327
+ ## Manutenção
328
+
329
+ Quando houver atualizações no SDK:
330
+
331
+ 1. A versão será atualizada no npm
332
+ 2. Atualize o pacote nos seus apps: `npm update @agenus-io/webhook-centralizer`
333
+ 3. Se houver breaking changes, serão documentados nas release notes
334
+
335
+ ## Segurança
336
+
337
+ ⚠️ **IMPORTANTE**: Nunca commite credenciais AWS ou tokens de aplicação no código fonte. Sempre use variáveis de ambiente ou serviços de gerenciamento de segredos (AWS Secrets Manager, etc).
338
+
339
+ ## API de Webhooks
340
+
341
+ O SDK se conecta à API de centralização de webhooks hospedada em: `https://micro-service-pixel-production-4826.up.railway.app`
342
+
343
+ Todas as operações CRUD de configurações de webhooks utilizam autenticação via headers:
344
+ - `app-id`: ID da aplicação
345
+ - `app-secret-token`: Token secreto da aplicação
346
+ - `work-space-id`: ID do workspace
347
+
348
+ ## Suporte
349
+
350
+ Para questões ou problemas, abra uma issue no repositório do projeto.
File without changes
@@ -0,0 +1,198 @@
1
+ "use strict";
2
+ // import AWS from "aws-sdk";
3
+ // import type { AWSConfig, SendSaleParams } from "../config";
4
+ // import type { Order } from "../types";
5
+ // import { ICreatePixelDTO, IGetOnePixelDTO, IGetPixelDTO, IDeletePixelDTO, IUpdatePixelDTO, IWebhookCentralizerSdk, IUpdateOffersDTO, IMetricsDTO } from './interface';
6
+ // import axios, { AxiosError } from "axios";
7
+ // /**
8
+ // * Classe responsável pela centralização de webhooks de plataformas de pagamento
9
+ // */
10
+ // export class WebhookCentralizerSDK implements IWebhookCentralizerSdk{
11
+ // private sqs: AWS.SQS;
12
+ // private queueUrl: string;
13
+ // private appId: string;
14
+ // private appToken: string;
15
+ // private apiUrl: string;
16
+ // /**
17
+ // * Constrói uma instância do SDK com as credenciais AWS
18
+ // * @param config Configuração AWS (credenciais e URL da fila)
19
+ // * @param appId ID da aplicação
20
+ // * @param appToken Token da aplicação
21
+ // */
22
+ // constructor(config: AWSConfig, appId: string, appToken: string, environment: "production" | "develop" = "production") {
23
+ // this.queueUrl = config.queueUrl;
24
+ // this.appId = appId;
25
+ // this.appToken = appToken;
26
+ // this.apiUrl = environment === "production" ? "https://micro-service-pixel-production-4826.up.railway.app" : "https://micro-servico-pixel-develop.up.railway.app";
27
+ // this.sqs = new AWS.SQS({
28
+ // region: config.region,
29
+ // credentials: {
30
+ // accessKeyId: config.accessKeyId,
31
+ // secretAccessKey: config.secretAccessKey,
32
+ // },
33
+ // });
34
+ // }
35
+ // /**
36
+ // * Processa um webhook de pagamento e envia para a fila AWS SQS
37
+ // * @param params Parâmetros contendo os dados do webhook de pagamento
38
+ // * @throws {Error} Se houver erro ao enviar a mensagem para a fila
39
+ // */
40
+ // async SendOrder(params: SendSaleParams): Promise<void> {
41
+ // const { workspaceId, order } = params;
42
+ // try {
43
+ // await this.sqs
44
+ // .sendMessage({
45
+ // QueueUrl: this.queueUrl,
46
+ // MessageBody: JSON.stringify({
47
+ // body: {
48
+ // workspaceId,
49
+ // order,
50
+ // app: {
51
+ // id: this.appId,
52
+ // token: this.appToken,
53
+ // }
54
+ // },
55
+ // }),
56
+ // })
57
+ // .promise();
58
+ // } catch (error) {
59
+ // const errorMessage = error instanceof Error ? error.message : "Erro desconhecido ao processar webhook";
60
+ // throw new Error(`Falha ao processar webhook de pagamento: ${errorMessage}`);
61
+ // }
62
+ // }
63
+ // async Create({ data, workspaceId }: ICreatePixelDTO.Params): Promise<ICreatePixelDTO.Result> {
64
+ // try {
65
+ // const token = {
66
+ // appId: this.appId,
67
+ // secretToken: this.appToken,
68
+ // workSpaceId: workspaceId,
69
+ // };
70
+ // const response = await axios.post<ICreatePixelDTO.Result>(`${this.apiUrl}/pixels`, { token, ...data });
71
+ // return response.data;
72
+ // } catch (error) {
73
+ // if (error instanceof AxiosError) {
74
+ // console.log(error.response?.data);
75
+ // } else {
76
+ // console.log(error);
77
+ // }
78
+ // throw "Erro ao criar pixel";
79
+ // }
80
+ // }
81
+ // async Update({ data, workspaceId, id }: IUpdatePixelDTO.Params): Promise<void> {
82
+ // try {
83
+ // const token = {
84
+ // appId: this.appId,
85
+ // secretToken: this.appToken,
86
+ // workSpaceId: workspaceId,
87
+ // };
88
+ // await axios.put(`${this.apiUrl}/pixels/${id}`, { token, ...data });
89
+ // } catch (error) {
90
+ // if (error instanceof AxiosError) {
91
+ // console.log(error.response?.data);
92
+ // } else {
93
+ // console.log(error);
94
+ // }
95
+ // throw "Erro ao atualizar pixel";
96
+ // }
97
+ // }
98
+ // async Delete({ id, workspaceId }: IDeletePixelDTO.Params): Promise<void> {
99
+ // try {
100
+ // const token = {
101
+ // appId: this.appId,
102
+ // secretToken: this.appToken,
103
+ // workSpaceId: workspaceId,
104
+ // };
105
+ // await axios.delete(`${this.apiUrl}/pixels/${id}`, {
106
+ // headers: { "app-id": token.appId, "app-secret-token": token.secretToken, "work-space-id": token.workSpaceId },
107
+ // });
108
+ // } catch (error) {
109
+ // if (error instanceof AxiosError) {
110
+ // console.log(error.response?.data);
111
+ // } else {
112
+ // console.log(error);
113
+ // }
114
+ // throw "Erro ao deletar pixel";
115
+ // }
116
+ // }
117
+ // async Get({ page, pageSize, filter, workSpaceId, platform, productIds, offerIds }: IGetPixelDTO.Params): Promise<IGetPixelDTO.Result> {
118
+ // try {
119
+ // const token = {
120
+ // appId: this.appId,
121
+ // secretToken: this.appToken,
122
+ // workSpaceId: workSpaceId,
123
+ // };
124
+ // const response = await axios.get<IGetPixelDTO.Result>(`${this.apiUrl}/pixels`, {
125
+ // headers: { "app-id": token.appId, "app-secret-token": token.secretToken, "work-space-id": token.workSpaceId },
126
+ // params: { page, pageSize, filter, platform, productIds, offerIds },
127
+ // });
128
+ // return response.data;
129
+ // } catch (error) {
130
+ // if (error instanceof AxiosError) {
131
+ // console.log(error.response?.data);
132
+ // } else {
133
+ // console.log(error);
134
+ // }
135
+ // throw "Erro ao deletar pixel";
136
+ // }
137
+ // }
138
+ // async GetOne({ id, workSpaceId }: IGetOnePixelDTO.Params): Promise<IGetOnePixelDTO.Result> {
139
+ // try {
140
+ // const token = {
141
+ // appId: this.appId,
142
+ // secretToken: this.appToken,
143
+ // workSpaceId: workSpaceId,
144
+ // };
145
+ // const response = await axios.get<IGetOnePixelDTO.Result["data"]>(`${this.apiUrl}/pixels/${id}`, {
146
+ // headers: { "app-id": token.appId, "app-secret-token": token.secretToken, "work-space-id": token.workSpaceId },
147
+ // });
148
+ // return {
149
+ // data: response.data,
150
+ // };
151
+ // } catch (error) {
152
+ // if (error instanceof AxiosError) {
153
+ // console.log(error.response?.data);
154
+ // } else {
155
+ // console.log(error);
156
+ // }
157
+ // throw "Erro ao deletar pixel";
158
+ // }
159
+ // }
160
+ // async UpdateOffers({ id, workspaceId, offerIds, type }: IUpdateOffersDTO.Params): Promise<void> {
161
+ // try {
162
+ // const token = {
163
+ // appId: this.appId,
164
+ // secretToken: this.appToken,
165
+ // workSpaceId: workspaceId,
166
+ // };
167
+ // await axios.post(`${this.apiUrl}/pixels/${id}/offer`, { token, offerIds, type });
168
+ // } catch (error) {
169
+ // if (error instanceof AxiosError) {
170
+ // console.log(error.response?.data);
171
+ // } else {
172
+ // console.log(error);
173
+ // }
174
+ // throw "Erro ao criar pixel";
175
+ // }
176
+ // }
177
+ // async Metrics({ workSpaceId, platform, productIds, offerIds, filter }: IMetricsDTO.Params): Promise<IMetricsDTO.Result> {
178
+ // try {
179
+ // const token = {
180
+ // appId: this.appId,
181
+ // secretToken: this.appToken,
182
+ // workSpaceId: workSpaceId,
183
+ // };
184
+ // const response = await axios.get<IMetricsDTO.Result>(`${this.apiUrl}/pixels/metrics`, {
185
+ // headers: { "app-id": token.appId, "app-secret-token": token.secretToken, "work-space-id": token.workSpaceId },
186
+ // params: { platform, productIds, offerIds, filter },
187
+ // });
188
+ // return response.data;
189
+ // } catch (error) {
190
+ // if (error instanceof AxiosError) {
191
+ // console.log(error.response?.data);
192
+ // } else {
193
+ // console.log(error);
194
+ // }
195
+ // throw "Erro ao obter métricas";
196
+ // }
197
+ // }
198
+ // }
File without changes
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ // import { PixelDetection, MarketingPlatform, PurchaseSendType, PurchaseValueType, SendIp } from '../types';
3
+ // interface CreatePixel {
4
+ // title: string;
5
+ // status: boolean;
6
+ // sendLead: boolean;
7
+ // sendLeadText?: string;
8
+ // addToCart: boolean;
9
+ // addToCartText?: string;
10
+ // addToCartDetection: PixelDetection;
11
+ // sendLeadDetection: PixelDetection;
12
+ // initiateCheckout: boolean;
13
+ // initiateCheckoutDetection: PixelDetection;
14
+ // initiateCheckoutDetectionText?: string;
15
+ // purchaseSendType: PurchaseSendType;
16
+ // purchaseValueType: PurchaseValueType;
17
+ // type: MarketingPlatform;
18
+ // productIds: string[];
19
+ // offerIds: string[];
20
+ // sendIp: SendIp;
21
+ // pixelMeta?: {
22
+ // id: string;
23
+ // title?: string;
24
+ // token: string;
25
+ // }[];
26
+ // pixelTikTok?: {
27
+ // id: string;
28
+ // title?: string;
29
+ // token: string;
30
+ // }[];
31
+ // pixelGoogle?: {
32
+ // id: string;
33
+ // title?: string;
34
+ // token: string;
35
+ // customerId: string;
36
+ // }[];
37
+ // pixelGoogleTags?: {
38
+ // id: string;
39
+ // title?: string;
40
+ // token: string;
41
+ // }[]
42
+ // }
43
+ // export namespace ICreatePixelDTO {
44
+ // export type Params = {
45
+ // workspaceId: string;
46
+ // data: CreatePixel;
47
+ // };
48
+ // export type Result = {
49
+ // id: string;
50
+ // };
51
+ // }
52
+ // export namespace IUpdatePixelDTO {
53
+ // export type Params = {
54
+ // id: string;
55
+ // workspaceId: string;
56
+ // data: Partial<CreatePixel>;
57
+ // };
58
+ // }
59
+ // export namespace IDeletePixelDTO {
60
+ // export type Params = {
61
+ // id: string;
62
+ // workspaceId: string;
63
+ // };
64
+ // }
65
+ // export namespace IGetPixelDTO {
66
+ // export type Params = {
67
+ // workSpaceId: string;
68
+ // page: number;
69
+ // pageSize: number;
70
+ // filter?: string;
71
+ // platform?: MarketingPlatform;
72
+ // productIds?: string[];
73
+ // offerIds?: string[];
74
+ // };
75
+ // export type Result = {
76
+ // data: {
77
+ // offerIds: string[];
78
+ // productIds: string[];
79
+ // id: string;
80
+ // code: string;
81
+ // title: string;
82
+ // createdAt: Date;
83
+ // status: boolean;
84
+ // type: MarketingPlatform;
85
+ // sendLead: boolean;
86
+ // sendLeadText: string | null;
87
+ // addToCart: boolean;
88
+ // addToCartText: string | null;
89
+ // initiateCheckout: boolean;
90
+ // initiateCheckoutDetection: PixelDetection;
91
+ // initiateCheckoutDetectionText: string | null;
92
+ // purchaseSendType: PurchaseSendType;
93
+ // purchaseValueType: PurchaseValueType;
94
+ // sendIp: SendIp;
95
+ // }[];
96
+ // meta: {
97
+ // total: number;
98
+ // totalPages: number;
99
+ // page: number;
100
+ // pageSize: number;
101
+ // };
102
+ // };
103
+ // }
104
+ // export namespace IGetOnePixelDTO {
105
+ // export type Params = {
106
+ // id: string;
107
+ // workSpaceId: string;
108
+ // };
109
+ // export type Result = {
110
+ // data: {
111
+ // productIds: string[];
112
+ // offerIds: string[];
113
+ // pixelGoogleTags: {
114
+ // id: string;
115
+ // title?: string;
116
+ // token: string;
117
+ // }[];
118
+ // pixelTikTok: {
119
+ // id: string;
120
+ // title?: string;
121
+ // token: string;
122
+ // externalId: string;
123
+ // }[];
124
+ // pixelGoogle: {
125
+ // id: true;
126
+ // title?: string;
127
+ // token: true;
128
+ // customerId: true;
129
+ // resourceName: true;
130
+ // }[];
131
+ // pixelMeta: {
132
+ // id: string;
133
+ // title?: string;
134
+ // token: string;
135
+ // externalId: string;
136
+ // }[];
137
+ // id: string;
138
+ // code: string;
139
+ // title: string;
140
+ // createdAt: Date;
141
+ // status: boolean;
142
+ // type: MarketingPlatform;
143
+ // sendLead: boolean;
144
+ // sendLeadText: string | null;
145
+ // addToCart: boolean;
146
+ // addToCartText: string | null;
147
+ // initiateCheckout: boolean;
148
+ // initiateCheckoutDetection: PixelDetection;
149
+ // initiateCheckoutDetectionText: string | null;
150
+ // purchaseSendType: PurchaseSendType;
151
+ // purchaseValueType: PurchaseValueType;
152
+ // sendIp: SendIp;
153
+ // } | null;
154
+ // };
155
+ // }
156
+ // export namespace IUpdateOffersDTO {
157
+ // export type Params = {
158
+ // id: string;
159
+ // type: "ADD" | "REMOVE";
160
+ // workspaceId: string;
161
+ // offerIds: string[];
162
+ // };
163
+ // }
164
+ // export namespace IMetricsDTO {
165
+ // export type Params = {
166
+ // workSpaceId: string;
167
+ // platform?: MarketingPlatform;
168
+ // productIds?: string[];
169
+ // offerIds?: string[];
170
+ // filter?: string;
171
+ // };
172
+ // export type Result = {
173
+ // metrics: {
174
+ // total: number;
175
+ // active: number;
176
+ // sendedEvents: number;
177
+ // };
178
+ // };
179
+ // }
180
+ // export interface IWebhookCentralizerSdk {
181
+ // Create(params: ICreatePixelDTO.Params): Promise<ICreatePixelDTO.Result>;
182
+ // Update(params: IUpdatePixelDTO.Params): Promise<void>;
183
+ // Delete(params: IDeletePixelDTO.Params): Promise<void>;
184
+ // Get(params: IGetPixelDTO.Params): Promise<IGetPixelDTO.Result>;
185
+ // GetOne(params: IGetOnePixelDTO.Params): Promise<IGetOnePixelDTO.Result>;
186
+ // UpdateOffers(params: IUpdateOffersDTO.Params): Promise<void>;
187
+ // Metrics(params: IMetricsDTO.Params): Promise<IMetricsDTO.Result>;
188
+ // }
File without changes
package/dist/config.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ // import type { Order } from "./types";
3
+ // /**
4
+ // * Configuração de credenciais AWS para conexão com SQS
5
+ // */
6
+ // export interface AWSConfig {
7
+ // /**
8
+ // * Região AWS onde a fila SQS está localizada
9
+ // * Exemplo: "us-east-1", "sa-east-1"
10
+ // */
11
+ // region: string;
12
+ // /**
13
+ // * Access Key ID da AWS
14
+ // */
15
+ // accessKeyId: string;
16
+ // /**
17
+ // * Secret Access Key da AWS
18
+ // */
19
+ // secretAccessKey: string;
20
+ // /**
21
+ // * URL da fila SQS
22
+ // * Exemplo: "https://sqs.us-east-1.amazonaws.com/123456789012/my-queue"
23
+ // */
24
+ // queueUrl: string;
25
+ // }
26
+ // /**
27
+ // * Parâmetros para processamento de webhook de pagamento
28
+ // */
29
+ // export interface SendSaleParams {
30
+ // /**
31
+ // * Dados do webhook de pagamento a serem processados
32
+ // */
33
+ // workspaceId: string;
34
+ // order: Order;
35
+ // }
File without changes
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ // /**
3
+ // * SDK para centralização de webhooks focado atualmente em plataformas de pagamentos
4
+ // *
5
+ // * Este pacote permite que aplicações clientes centralizem e processem
6
+ // * webhooks de plataformas de pagamento através de uma fila AWS SQS.
7
+ // */
8
+ // export type { AWSConfig, SendSaleParams } from "./config";
9
+ // export { WebhookCentralizerSDK } from "./Class";
10
+ // export type {
11
+ // PixelDetection,
12
+ // MarketingPlatform,
13
+ // PurchaseEventType,
14
+ // PurchaseSendType,
15
+ // PurchaseValueType,
16
+ // SendIp,
17
+ // Order,
18
+ // } from "./types";
19
+ // export {
20
+ // PixelDetectionEnum,
21
+ // PurchaseValueTypeEnum,
22
+ // MarketingPlatformEnum,
23
+ // PurchaseEventTypeEnum,
24
+ // PurchaseSendTypeEnum,
25
+ // SendIpEnum,
26
+ // } from "./types";
File without changes
package/dist/types.js ADDED
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ // export type PixelDetection = "AUTOMATIC" | "CLASS" | "ID" |"ATTRIBUTE" | "DATA_ATTRIBUTE" | "TAG" | "URL" | "CUSTOM" |"TEXT";
3
+ // export type PurchaseSendType = "SALES_APPROVED" | "SALES_APPROVED_AND_PENDING";
4
+ // export type PurchaseEventType = "PURCHASE_PENDING" | "PURCHASE_COMPLETED";
5
+ // export type SendIp = "IPV6_AND_IPV4" | "ONLY_IPV6" | "DONT_SEND";
6
+ // export type MarketingPlatform = "GOOGLE" | "META" | "TIKTOK";
7
+ // export type PurchaseValueType = "SALE_VALUE" | "COMMISSION";
8
+ // export const PixelDetectionEnum: Record<PixelDetection, PixelDetection> = {
9
+ // AUTOMATIC: "AUTOMATIC",
10
+ // CLASS: "CLASS",
11
+ // ID: "ID",
12
+ // ATTRIBUTE: "ATTRIBUTE",
13
+ // DATA_ATTRIBUTE: "DATA_ATTRIBUTE",
14
+ // TAG: "TAG",
15
+ // URL: "URL",
16
+ // CUSTOM: "CUSTOM",
17
+ // TEXT: "TEXT",
18
+ // } as const;
19
+ // export const PurchaseSendTypeEnum: Record<PurchaseSendType, PurchaseSendType> = {
20
+ // SALES_APPROVED: "SALES_APPROVED",
21
+ // SALES_APPROVED_AND_PENDING: "SALES_APPROVED_AND_PENDING",
22
+ // } as const;
23
+ // export const PurchaseValueTypeEnum: Record<PurchaseValueType, PurchaseValueType> = {
24
+ // SALE_VALUE: "SALE_VALUE",
25
+ // COMMISSION: "COMMISSION",
26
+ // } as const;
27
+ // export const SendIpEnum: Record<SendIp, SendIp> = {
28
+ // IPV6_AND_IPV4: "IPV6_AND_IPV4",
29
+ // ONLY_IPV6: "ONLY_IPV6",
30
+ // DONT_SEND: "DONT_SEND",
31
+ // } as const;
32
+ // export const MarketingPlatformEnum: Record<MarketingPlatform, MarketingPlatform> = {
33
+ // META: "META",
34
+ // GOOGLE: "GOOGLE",
35
+ // TIKTOK: "TIKTOK",
36
+ // } as const;
37
+ // export const PurchaseEventTypeEnum: Record<PurchaseEventType, PurchaseEventType> = {
38
+ // PURCHASE_PENDING: "PURCHASE_PENDING",
39
+ // PURCHASE_COMPLETED: "PURCHASE_COMPLETED",
40
+ // } as const;
41
+ // export interface CustomerData {
42
+ // email: string;
43
+ // externalId?: string;
44
+ // firstName: string;
45
+ // lastName: string;
46
+ // phone?: string;
47
+ // city?: string;
48
+ // state?: string;
49
+ // zipCode?: string;
50
+ // country?: string;
51
+ // ip?: string;
52
+ // userAgent?: string;
53
+ // }
54
+ // export interface ProductData {
55
+ // id: string;
56
+ // title: string;
57
+ // externalId: string;
58
+ // quantity: number;
59
+ // }
60
+ // export interface Order {
61
+ // dispatch: MarketingPlatform;
62
+ // event: PurchaseEventType;
63
+ // checkout: string;
64
+ // orderId: string;
65
+ // subscriptionId?: string;
66
+ // fbc?: string;
67
+ // fbp?: string;
68
+ // fbclid?: string;
69
+ // gclid?: string;
70
+ // gbraid?: string;
71
+ // wbraid?: string;
72
+ // currency: string;
73
+ // valueGross: number;
74
+ // valueNet: number;
75
+ // createdAt: Date;
76
+ // customer: CustomerData;
77
+ // products: ProductData[];
78
+ // }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@agenus-io/webhook-centralizer",
3
+ "version": "1.0.1",
4
+ "description": "SDK para centralização de webhooks focado atualmente em plataformas de pagamentos",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "prepublishOnly": "npm run build"
10
+ },
11
+ "keywords": [
12
+ "webhook",
13
+ "centralizer",
14
+ "payment",
15
+ "platform"
16
+ ],
17
+ "author": "David de Sousa Pimenta",
18
+ "email": "davidpimanta@gmail.com",
19
+ "license": "ISC",
20
+ "dependencies": {
21
+ "aws-sdk": "^2.1692.0",
22
+ "axios": "^1.13.2"
23
+ },
24
+ "devDependencies": {
25
+ "@types/node": "^24.5.2",
26
+ "typescript": "^5.9.2"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "README.md"
31
+ ]
32
+ }