@agenus-io/pixel-backend-sdk 1.0.18
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 +350 -0
- package/dist/Class/index.d.ts +30 -0
- package/dist/Class/index.js +201 -0
- package/dist/Class/interface.d.ts +143 -0
- package/dist/Class/interface.js +2 -0
- package/dist/config.d.ts +34 -0
- package/dist/config.js +2 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +18 -0
- package/dist/sendSale.d.ts +52 -0
- package/dist/sendSale.js +93 -0
- package/dist/types.d.ts +50 -0
- package/dist/types.js +31 -0
- package/package.json +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
# Pixel SDK
|
|
2
|
+
|
|
3
|
+
SDK completo para gerenciamento de pixels e envio de vendas para fila AWS SQS do micro-serviço de pixels (Meta/Facebook, Google, TikTok).
|
|
4
|
+
|
|
5
|
+
## Instalação
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @davidpimentabenony/pixel-sdk
|
|
9
|
+
# ou
|
|
10
|
+
yarn add @davidpimentabenony/pixel-sdk
|
|
11
|
+
# ou
|
|
12
|
+
pnpm add @davidpimentabenony/pixel-sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Funcionalidades
|
|
16
|
+
|
|
17
|
+
Este SDK fornece duas funcionalidades principais:
|
|
18
|
+
|
|
19
|
+
1. **Gerenciamento de Pixels**: CRUD completo de pixels (Create, Update, Delete, Get, GetOne)
|
|
20
|
+
2. **Envio de Vendas**: Envio de pedidos/vendas para processamento via AWS SQS
|
|
21
|
+
|
|
22
|
+
## Uso
|
|
23
|
+
|
|
24
|
+
### Configuração Inicial
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { PixelSDK } from "@davidpimentabenony/pixel-sdk";
|
|
28
|
+
import type { AWSConfig, Order } from "@davidpimentabenony/pixel-sdk";
|
|
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 PixelSDK(config, appId, appToken);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 1. Enviar Vendas para a Fila
|
|
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 Pixels
|
|
108
|
+
|
|
109
|
+
#### Criar Pixel
|
|
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 Pixels
|
|
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 pixels
|
|
151
|
+
console.log(result.meta); // Metadados de paginação
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
#### Buscar um Pixel Específico
|
|
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 do pixel ou null
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
#### Atualizar Pixel
|
|
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 Pixel
|
|
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
|
+
### `InitiateCheckoutDetection`
|
|
211
|
+
```typescript
|
|
212
|
+
type InitiateCheckoutDetection = "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 { PixelSDK } from "@davidpimentabenony/pixel-sdk";
|
|
252
|
+
import type { AWSConfig, Order } from "@davidpimentabenony/pixel-sdk";
|
|
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 PixelSDK(
|
|
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 pixels
|
|
314
|
+
const pixels = await sdk.Get({
|
|
315
|
+
workSpaceId: "workspace-123",
|
|
316
|
+
page: 1,
|
|
317
|
+
pageSize: 10,
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
console.log(`Total de pixels: ${pixels.meta.total}`);
|
|
321
|
+
|
|
322
|
+
// Enviar uma venda
|
|
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 @davidpimentabenony/pixel-sdk`
|
|
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 Pixels
|
|
340
|
+
|
|
341
|
+
O SDK se conecta à API de pixels hospedada em: `https://micro-servico-pixel-develop.up.railway.app`
|
|
342
|
+
|
|
343
|
+
Todas as operações CRUD de pixels 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.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AWSConfig, SendSaleParams } from "../config";
|
|
2
|
+
import { ICreatePixelDTO, IGetOnePixelDTO, IGetPixelDTO, IDeletePixelDTO, IUpdatePixelDTO, IPixelSdk } from './interface';
|
|
3
|
+
/**
|
|
4
|
+
* Classe responsável por com vendas e pixels
|
|
5
|
+
*/
|
|
6
|
+
export declare class PixelSDK implements IPixelSdk {
|
|
7
|
+
private sqs;
|
|
8
|
+
private queueUrl;
|
|
9
|
+
private appId;
|
|
10
|
+
private appToken;
|
|
11
|
+
private apiUrl;
|
|
12
|
+
/**
|
|
13
|
+
* Constrói uma instância do SDK com as credenciais AWS
|
|
14
|
+
* @param config Configuração AWS (credenciais e URL da fila)
|
|
15
|
+
* @param appId ID da aplicação
|
|
16
|
+
* @param appToken Token da aplicação
|
|
17
|
+
*/
|
|
18
|
+
constructor(config: AWSConfig, appId: string, appToken: string);
|
|
19
|
+
/**
|
|
20
|
+
* Envia uma venda para a fila AWS SQS
|
|
21
|
+
* @param params Parâmetros contendo os dados da venda
|
|
22
|
+
* @throws {Error} Se houver erro ao enviar a mensagem para a fila
|
|
23
|
+
*/
|
|
24
|
+
SendOrder(params: SendSaleParams): Promise<void>;
|
|
25
|
+
Create({ data, workspaceId }: ICreatePixelDTO.Params): Promise<void>;
|
|
26
|
+
Update({ data, workspaceId, id }: IUpdatePixelDTO.Params): Promise<void>;
|
|
27
|
+
Delete({ id, workspaceId }: IDeletePixelDTO.Params): Promise<void>;
|
|
28
|
+
Get({ page, pageSize, filter, workSpaceId }: IGetPixelDTO.Params): Promise<IGetPixelDTO.Result>;
|
|
29
|
+
GetOne({ id, workSpaceId }: IGetOnePixelDTO.Params): Promise<IGetOnePixelDTO.Result>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.PixelSDK = void 0;
|
|
40
|
+
const aws_sdk_1 = __importDefault(require("aws-sdk"));
|
|
41
|
+
const axios_1 = __importStar(require("axios"));
|
|
42
|
+
/**
|
|
43
|
+
* Classe responsável por com vendas e pixels
|
|
44
|
+
*/
|
|
45
|
+
class PixelSDK {
|
|
46
|
+
/**
|
|
47
|
+
* Constrói uma instância do SDK com as credenciais AWS
|
|
48
|
+
* @param config Configuração AWS (credenciais e URL da fila)
|
|
49
|
+
* @param appId ID da aplicação
|
|
50
|
+
* @param appToken Token da aplicação
|
|
51
|
+
*/
|
|
52
|
+
constructor(config, appId, appToken) {
|
|
53
|
+
this.queueUrl = config.queueUrl;
|
|
54
|
+
this.appId = appId;
|
|
55
|
+
this.appToken = appToken;
|
|
56
|
+
this.apiUrl = "https://micro-servico-pixel-develop.up.railway.app";
|
|
57
|
+
this.sqs = new aws_sdk_1.default.SQS({
|
|
58
|
+
region: config.region,
|
|
59
|
+
credentials: {
|
|
60
|
+
accessKeyId: config.accessKeyId,
|
|
61
|
+
secretAccessKey: config.secretAccessKey,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Envia uma venda para a fila AWS SQS
|
|
67
|
+
* @param params Parâmetros contendo os dados da venda
|
|
68
|
+
* @throws {Error} Se houver erro ao enviar a mensagem para a fila
|
|
69
|
+
*/
|
|
70
|
+
async SendOrder(params) {
|
|
71
|
+
const { workspaceId, order } = params;
|
|
72
|
+
try {
|
|
73
|
+
await this.sqs
|
|
74
|
+
.sendMessage({
|
|
75
|
+
QueueUrl: this.queueUrl,
|
|
76
|
+
MessageBody: JSON.stringify({
|
|
77
|
+
body: {
|
|
78
|
+
workspaceId,
|
|
79
|
+
order,
|
|
80
|
+
app: {
|
|
81
|
+
id: this.appId,
|
|
82
|
+
token: this.appToken,
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
}),
|
|
86
|
+
})
|
|
87
|
+
.promise();
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
const errorMessage = error instanceof Error ? error.message : "Erro desconhecido ao enviar venda";
|
|
91
|
+
throw new Error(`Falha ao enviar venda para a fila: ${errorMessage}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async Create({ data, workspaceId }) {
|
|
95
|
+
try {
|
|
96
|
+
const token = {
|
|
97
|
+
appId: this.appId,
|
|
98
|
+
secretToken: this.appToken,
|
|
99
|
+
workSpaceId: workspaceId,
|
|
100
|
+
};
|
|
101
|
+
await axios_1.default.post(`${this.apiUrl}/pixels`, { token, ...data });
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (error instanceof axios_1.AxiosError) {
|
|
105
|
+
console.log(error.response?.data);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
console.log(error);
|
|
109
|
+
}
|
|
110
|
+
throw "Erro ao criar pixel";
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async Update({ data, workspaceId, id }) {
|
|
114
|
+
try {
|
|
115
|
+
const token = {
|
|
116
|
+
appId: this.appId,
|
|
117
|
+
secretToken: this.appToken,
|
|
118
|
+
workSpaceId: workspaceId,
|
|
119
|
+
};
|
|
120
|
+
await axios_1.default.put(`${this.apiUrl}/pixels/${id}`, { token, ...data });
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
if (error instanceof axios_1.AxiosError) {
|
|
124
|
+
console.log(error.response?.data);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
console.log(error);
|
|
128
|
+
}
|
|
129
|
+
throw "Erro ao atualizar pixel";
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async Delete({ id, workspaceId }) {
|
|
133
|
+
try {
|
|
134
|
+
const token = {
|
|
135
|
+
appId: this.appId,
|
|
136
|
+
secretToken: this.appToken,
|
|
137
|
+
workSpaceId: workspaceId,
|
|
138
|
+
};
|
|
139
|
+
await axios_1.default.delete(`${this.apiUrl}/pixels/${id}`, {
|
|
140
|
+
headers: { "app-id": token.appId, "app-secret-token": token.secretToken, "work-space-id": token.workSpaceId },
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
if (error instanceof axios_1.AxiosError) {
|
|
145
|
+
console.log(error.response?.data);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
console.log(error);
|
|
149
|
+
}
|
|
150
|
+
throw "Erro ao deletar pixel";
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
async Get({ page, pageSize, filter, workSpaceId }) {
|
|
154
|
+
try {
|
|
155
|
+
const token = {
|
|
156
|
+
appId: this.appId,
|
|
157
|
+
secretToken: this.appToken,
|
|
158
|
+
workSpaceId: workSpaceId,
|
|
159
|
+
};
|
|
160
|
+
const response = await axios_1.default.get(`${this.apiUrl}/pixels`, {
|
|
161
|
+
headers: { "app-id": token.appId, "app-secret-token": token.secretToken, "work-space-id": token.workSpaceId },
|
|
162
|
+
params: { page, pageSize, filter },
|
|
163
|
+
});
|
|
164
|
+
return response.data;
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
if (error instanceof axios_1.AxiosError) {
|
|
168
|
+
console.log(error.response?.data);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
console.log(error);
|
|
172
|
+
}
|
|
173
|
+
throw "Erro ao deletar pixel";
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
async GetOne({ id, workSpaceId }) {
|
|
177
|
+
try {
|
|
178
|
+
const token = {
|
|
179
|
+
appId: this.appId,
|
|
180
|
+
secretToken: this.appToken,
|
|
181
|
+
workSpaceId: workSpaceId,
|
|
182
|
+
};
|
|
183
|
+
const response = await axios_1.default.get(`${this.apiUrl}/pixels/${id}`, {
|
|
184
|
+
headers: { "app-id": token.appId, "app-secret-token": token.secretToken, "work-space-id": token.workSpaceId },
|
|
185
|
+
});
|
|
186
|
+
return {
|
|
187
|
+
data: response.data,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
if (error instanceof axios_1.AxiosError) {
|
|
192
|
+
console.log(error.response?.data);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
console.log(error);
|
|
196
|
+
}
|
|
197
|
+
throw "Erro ao deletar pixel";
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
exports.PixelSDK = PixelSDK;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { InitiateCheckoutDetection, MarketingPlatform, PurchaseSendType, PurchaseValueType, SendIp } from '../types';
|
|
2
|
+
interface CreatePixel {
|
|
3
|
+
title: string;
|
|
4
|
+
status: boolean;
|
|
5
|
+
sendLead: boolean;
|
|
6
|
+
sendLeadText?: string;
|
|
7
|
+
addToCart: boolean;
|
|
8
|
+
addToCartText?: string;
|
|
9
|
+
initiateCheckout: boolean;
|
|
10
|
+
initiateCheckoutDetection: InitiateCheckoutDetection;
|
|
11
|
+
initiateCheckoutDetectionText?: string;
|
|
12
|
+
purchaseSendType: PurchaseSendType;
|
|
13
|
+
purchaseValueType: PurchaseValueType;
|
|
14
|
+
type: MarketingPlatform;
|
|
15
|
+
productIds: string[];
|
|
16
|
+
sendIp: SendIp;
|
|
17
|
+
pixelMeta?: {
|
|
18
|
+
id: string;
|
|
19
|
+
title?: string;
|
|
20
|
+
token: string;
|
|
21
|
+
}[];
|
|
22
|
+
pixelTikTok?: {
|
|
23
|
+
id: string;
|
|
24
|
+
title?: string;
|
|
25
|
+
token: string;
|
|
26
|
+
}[];
|
|
27
|
+
pixelGoogle?: {
|
|
28
|
+
id: string;
|
|
29
|
+
title?: string;
|
|
30
|
+
token: string;
|
|
31
|
+
customerId: string;
|
|
32
|
+
}[];
|
|
33
|
+
}
|
|
34
|
+
export declare namespace ICreatePixelDTO {
|
|
35
|
+
type Params = {
|
|
36
|
+
workspaceId: string;
|
|
37
|
+
data: CreatePixel;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export declare namespace IUpdatePixelDTO {
|
|
41
|
+
type Params = {
|
|
42
|
+
id: string;
|
|
43
|
+
workspaceId: string;
|
|
44
|
+
data: Partial<CreatePixel>;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export declare namespace IDeletePixelDTO {
|
|
48
|
+
type Params = {
|
|
49
|
+
id: string;
|
|
50
|
+
workspaceId: string;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export declare namespace IGetPixelDTO {
|
|
54
|
+
type Params = {
|
|
55
|
+
workSpaceId: string;
|
|
56
|
+
page: number;
|
|
57
|
+
pageSize: number;
|
|
58
|
+
filter?: string;
|
|
59
|
+
};
|
|
60
|
+
type Result = {
|
|
61
|
+
data: {
|
|
62
|
+
productIds: string[];
|
|
63
|
+
id: string;
|
|
64
|
+
code: string;
|
|
65
|
+
title: string;
|
|
66
|
+
createdAt: Date;
|
|
67
|
+
status: boolean;
|
|
68
|
+
type: MarketingPlatform;
|
|
69
|
+
sendLead: boolean;
|
|
70
|
+
sendLeadText: string | null;
|
|
71
|
+
addToCart: boolean;
|
|
72
|
+
addToCartText: string | null;
|
|
73
|
+
initiateCheckout: boolean;
|
|
74
|
+
initiateCheckoutDetection: InitiateCheckoutDetection;
|
|
75
|
+
initiateCheckoutDetectionText: string | null;
|
|
76
|
+
purchaseSendType: PurchaseSendType;
|
|
77
|
+
purchaseValueType: PurchaseValueType;
|
|
78
|
+
sendIp: SendIp;
|
|
79
|
+
}[];
|
|
80
|
+
meta: {
|
|
81
|
+
total: number;
|
|
82
|
+
totalPages: number;
|
|
83
|
+
page: number;
|
|
84
|
+
pageSize: number;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export declare namespace IGetOnePixelDTO {
|
|
89
|
+
type Params = {
|
|
90
|
+
id: string;
|
|
91
|
+
workSpaceId: string;
|
|
92
|
+
};
|
|
93
|
+
type Result = {
|
|
94
|
+
data: {
|
|
95
|
+
productIds: string[];
|
|
96
|
+
pixelTikTok: {
|
|
97
|
+
id: string;
|
|
98
|
+
title?: string;
|
|
99
|
+
token: string;
|
|
100
|
+
externalId: string;
|
|
101
|
+
}[];
|
|
102
|
+
pixelGoogle: {
|
|
103
|
+
select: {
|
|
104
|
+
id: true;
|
|
105
|
+
title?: string;
|
|
106
|
+
token: true;
|
|
107
|
+
customerId: true;
|
|
108
|
+
resourceName: true;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
pixelMeta: {
|
|
112
|
+
id: string;
|
|
113
|
+
title?: string;
|
|
114
|
+
token: string;
|
|
115
|
+
externalId: string;
|
|
116
|
+
}[];
|
|
117
|
+
id: string;
|
|
118
|
+
code: string;
|
|
119
|
+
title: string;
|
|
120
|
+
createdAt: Date;
|
|
121
|
+
status: boolean;
|
|
122
|
+
type: MarketingPlatform;
|
|
123
|
+
sendLead: boolean;
|
|
124
|
+
sendLeadText: string | null;
|
|
125
|
+
addToCart: boolean;
|
|
126
|
+
addToCartText: string | null;
|
|
127
|
+
initiateCheckout: boolean;
|
|
128
|
+
initiateCheckoutDetection: InitiateCheckoutDetection;
|
|
129
|
+
initiateCheckoutDetectionText: string | null;
|
|
130
|
+
purchaseSendType: PurchaseSendType;
|
|
131
|
+
purchaseValueType: PurchaseValueType;
|
|
132
|
+
sendIp: SendIp;
|
|
133
|
+
} | null;
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
export interface IPixelSdk {
|
|
137
|
+
Create(params: ICreatePixelDTO.Params): Promise<void>;
|
|
138
|
+
Update(params: IUpdatePixelDTO.Params): Promise<void>;
|
|
139
|
+
Delete(params: IDeletePixelDTO.Params): Promise<void>;
|
|
140
|
+
Get(params: IGetPixelDTO.Params): Promise<IGetPixelDTO.Result>;
|
|
141
|
+
GetOne(params: IGetOnePixelDTO.Params): Promise<IGetOnePixelDTO.Result>;
|
|
142
|
+
}
|
|
143
|
+
export {};
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Order } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Configuração de credenciais AWS para conexão com SQS
|
|
4
|
+
*/
|
|
5
|
+
export interface AWSConfig {
|
|
6
|
+
/**
|
|
7
|
+
* Região AWS onde a fila SQS está localizada
|
|
8
|
+
* Exemplo: "us-east-1", "sa-east-1"
|
|
9
|
+
*/
|
|
10
|
+
region: string;
|
|
11
|
+
/**
|
|
12
|
+
* Access Key ID da AWS
|
|
13
|
+
*/
|
|
14
|
+
accessKeyId: string;
|
|
15
|
+
/**
|
|
16
|
+
* Secret Access Key da AWS
|
|
17
|
+
*/
|
|
18
|
+
secretAccessKey: string;
|
|
19
|
+
/**
|
|
20
|
+
* URL da fila SQS
|
|
21
|
+
* Exemplo: "https://sqs.us-east-1.amazonaws.com/123456789012/my-queue"
|
|
22
|
+
*/
|
|
23
|
+
queueUrl: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Parâmetros para envio de mensagem
|
|
27
|
+
*/
|
|
28
|
+
export interface SendSaleParams {
|
|
29
|
+
/**
|
|
30
|
+
* Dados da venda a serem enviados
|
|
31
|
+
*/
|
|
32
|
+
workspaceId: string;
|
|
33
|
+
order: Order;
|
|
34
|
+
}
|
package/dist/config.js
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK para envio de vendas para fila AWS SQS
|
|
3
|
+
*
|
|
4
|
+
* Este pacote permite que aplicações clientes enviem vendas
|
|
5
|
+
* para o micro-serviço de pixels através de uma fila AWS SQS.
|
|
6
|
+
*/
|
|
7
|
+
export type { AWSConfig, SendSaleParams } from "./config";
|
|
8
|
+
export { PixelSDK } from "./Class";
|
|
9
|
+
export type { InitiateCheckoutDetection, MarketingPlatform, PurchaseEventType, PurchaseSendType, PurchaseValueType, SendIp, Order, } from "./types";
|
|
10
|
+
export { InitiateCheckoutDetectionEnum, PurchaseValueTypeEnum, MarketingPlatformEnum, PurchaseEventTypeEnum, PurchaseSendTypeEnum, SendIpEnum, } from "./types";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SDK para envio de vendas para fila AWS SQS
|
|
4
|
+
*
|
|
5
|
+
* Este pacote permite que aplicações clientes enviem vendas
|
|
6
|
+
* para o micro-serviço de pixels através de uma fila AWS SQS.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.SendIpEnum = exports.PurchaseSendTypeEnum = exports.PurchaseEventTypeEnum = exports.MarketingPlatformEnum = exports.PurchaseValueTypeEnum = exports.InitiateCheckoutDetectionEnum = exports.PixelSDK = void 0;
|
|
10
|
+
var Class_1 = require("./Class");
|
|
11
|
+
Object.defineProperty(exports, "PixelSDK", { enumerable: true, get: function () { return Class_1.PixelSDK; } });
|
|
12
|
+
var types_1 = require("./types");
|
|
13
|
+
Object.defineProperty(exports, "InitiateCheckoutDetectionEnum", { enumerable: true, get: function () { return types_1.InitiateCheckoutDetectionEnum; } });
|
|
14
|
+
Object.defineProperty(exports, "PurchaseValueTypeEnum", { enumerable: true, get: function () { return types_1.PurchaseValueTypeEnum; } });
|
|
15
|
+
Object.defineProperty(exports, "MarketingPlatformEnum", { enumerable: true, get: function () { return types_1.MarketingPlatformEnum; } });
|
|
16
|
+
Object.defineProperty(exports, "PurchaseEventTypeEnum", { enumerable: true, get: function () { return types_1.PurchaseEventTypeEnum; } });
|
|
17
|
+
Object.defineProperty(exports, "PurchaseSendTypeEnum", { enumerable: true, get: function () { return types_1.PurchaseSendTypeEnum; } });
|
|
18
|
+
Object.defineProperty(exports, "SendIpEnum", { enumerable: true, get: function () { return types_1.SendIpEnum; } });
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { AWSConfig, SendSaleParams } from "./config";
|
|
2
|
+
import type { Order } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Classe responsável por enviar vendas para a fila AWS SQS
|
|
5
|
+
*/
|
|
6
|
+
export declare class PixelSDK {
|
|
7
|
+
private sqs;
|
|
8
|
+
private queueUrl;
|
|
9
|
+
private appId;
|
|
10
|
+
private appToken;
|
|
11
|
+
/**
|
|
12
|
+
* Constrói uma instância do SDK com as credenciais AWS
|
|
13
|
+
* @param config Configuração AWS (credenciais e URL da fila)
|
|
14
|
+
*/
|
|
15
|
+
constructor(config: AWSConfig, appId: string, appToken: string);
|
|
16
|
+
/**
|
|
17
|
+
* Envia uma venda para a fila AWS SQS
|
|
18
|
+
* @param params Parâmetros contendo os dados da venda
|
|
19
|
+
* @throws {Error} Se houver erro ao enviar a mensagem para a fila
|
|
20
|
+
*/
|
|
21
|
+
sendSale(params: SendSaleParams): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Envia múltiplas vendas para a fila (usa batch quando possível)
|
|
24
|
+
* @param sales Array de dados de vendas
|
|
25
|
+
* @throws {Error} Se houver erro ao enviar as mensagens
|
|
26
|
+
*/
|
|
27
|
+
sendSales(workspaceId: string, orders: Order[]): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Função helper para criar uma instância do SDK e enviar uma venda
|
|
31
|
+
* Útil para uso direto sem precisar instanciar a classe
|
|
32
|
+
*
|
|
33
|
+
* @param config Configuração AWS
|
|
34
|
+
* @param sale Dados da venda
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* await sendSaleToQueue(
|
|
38
|
+
* {
|
|
39
|
+
* region: "us-east-1",
|
|
40
|
+
* accessKeyId: "AKIA...",
|
|
41
|
+
* secretAccessKey: "secret...",
|
|
42
|
+
* queueUrl: "https://sqs..."
|
|
43
|
+
* },
|
|
44
|
+
* {
|
|
45
|
+
* workspaceId: "123",
|
|
46
|
+
* app: { id: "app-id", token: "token" },
|
|
47
|
+
* order: { ... }
|
|
48
|
+
* }
|
|
49
|
+
* );
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function sendSaleToQueue(config: AWSConfig, workspaceId: string, appId: string, appToken: string, order: Order): Promise<void>;
|
package/dist/sendSale.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PixelSDK = void 0;
|
|
7
|
+
exports.sendSaleToQueue = sendSaleToQueue;
|
|
8
|
+
const aws_sdk_1 = __importDefault(require("aws-sdk"));
|
|
9
|
+
/**
|
|
10
|
+
* Classe responsável por enviar vendas para a fila AWS SQS
|
|
11
|
+
*/
|
|
12
|
+
class PixelSDK {
|
|
13
|
+
/**
|
|
14
|
+
* Constrói uma instância do SDK com as credenciais AWS
|
|
15
|
+
* @param config Configuração AWS (credenciais e URL da fila)
|
|
16
|
+
*/
|
|
17
|
+
constructor(config, appId, appToken) {
|
|
18
|
+
this.queueUrl = config.queueUrl;
|
|
19
|
+
this.appId = appId;
|
|
20
|
+
this.appToken = appToken;
|
|
21
|
+
this.sqs = new aws_sdk_1.default.SQS({
|
|
22
|
+
region: config.region,
|
|
23
|
+
credentials: {
|
|
24
|
+
accessKeyId: config.accessKeyId,
|
|
25
|
+
secretAccessKey: config.secretAccessKey,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Envia uma venda para a fila AWS SQS
|
|
31
|
+
* @param params Parâmetros contendo os dados da venda
|
|
32
|
+
* @throws {Error} Se houver erro ao enviar a mensagem para a fila
|
|
33
|
+
*/
|
|
34
|
+
async sendSale(params) {
|
|
35
|
+
const { workspaceId, order } = params;
|
|
36
|
+
try {
|
|
37
|
+
await this.sqs
|
|
38
|
+
.sendMessage({
|
|
39
|
+
QueueUrl: this.queueUrl,
|
|
40
|
+
MessageBody: JSON.stringify({
|
|
41
|
+
body: {
|
|
42
|
+
workspaceId,
|
|
43
|
+
order,
|
|
44
|
+
appId: this.appId,
|
|
45
|
+
appToken: this.appToken,
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
48
|
+
})
|
|
49
|
+
.promise();
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
const errorMessage = error instanceof Error ? error.message : "Erro desconhecido ao enviar venda";
|
|
53
|
+
throw new Error(`Falha ao enviar venda para a fila: ${errorMessage}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Envia múltiplas vendas para a fila (usa batch quando possível)
|
|
58
|
+
* @param sales Array de dados de vendas
|
|
59
|
+
* @throws {Error} Se houver erro ao enviar as mensagens
|
|
60
|
+
*/
|
|
61
|
+
async sendSales(workspaceId, orders) {
|
|
62
|
+
const promises = orders.map((order) => this.sendSale({ workspaceId, order }));
|
|
63
|
+
await Promise.all(promises);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.PixelSDK = PixelSDK;
|
|
67
|
+
/**
|
|
68
|
+
* Função helper para criar uma instância do SDK e enviar uma venda
|
|
69
|
+
* Útil para uso direto sem precisar instanciar a classe
|
|
70
|
+
*
|
|
71
|
+
* @param config Configuração AWS
|
|
72
|
+
* @param sale Dados da venda
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* await sendSaleToQueue(
|
|
76
|
+
* {
|
|
77
|
+
* region: "us-east-1",
|
|
78
|
+
* accessKeyId: "AKIA...",
|
|
79
|
+
* secretAccessKey: "secret...",
|
|
80
|
+
* queueUrl: "https://sqs..."
|
|
81
|
+
* },
|
|
82
|
+
* {
|
|
83
|
+
* workspaceId: "123",
|
|
84
|
+
* app: { id: "app-id", token: "token" },
|
|
85
|
+
* order: { ... }
|
|
86
|
+
* }
|
|
87
|
+
* );
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
async function sendSaleToQueue(config, workspaceId, appId, appToken, order) {
|
|
91
|
+
const sdk = new PixelSDK(config, appId, appToken);
|
|
92
|
+
await sdk.sendSale({ workspaceId, order });
|
|
93
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export type InitiateCheckoutDetection = "AUTOMATIC" | "CONTAINS_TEXT" | "CONTAINS_CSS" | "CONTAINS_URL";
|
|
2
|
+
export type PurchaseSendType = "SALES_APPROVED" | "SALES_APPROVED_AND_PENDING";
|
|
3
|
+
export type PurchaseEventType = "PURCHASE_PENDING" | "PURCHASE_COMPLETED";
|
|
4
|
+
export type SendIp = "IPV6_AND_IPV4" | "ONLY_IPV6" | "DONT_SEND";
|
|
5
|
+
export type MarketingPlatform = "GOOGLE" | "META" | "TIKTOK";
|
|
6
|
+
export type PurchaseValueType = "SALE_VALUE" | "COMMISSION";
|
|
7
|
+
export declare const InitiateCheckoutDetectionEnum: Record<InitiateCheckoutDetection, InitiateCheckoutDetection>;
|
|
8
|
+
export declare const PurchaseSendTypeEnum: Record<PurchaseSendType, PurchaseSendType>;
|
|
9
|
+
export declare const PurchaseValueTypeEnum: Record<PurchaseValueType, PurchaseValueType>;
|
|
10
|
+
export declare const SendIpEnum: Record<SendIp, SendIp>;
|
|
11
|
+
export declare const MarketingPlatformEnum: Record<MarketingPlatform, MarketingPlatform>;
|
|
12
|
+
export declare const PurchaseEventTypeEnum: Record<PurchaseEventType, PurchaseEventType>;
|
|
13
|
+
export interface CustomerData {
|
|
14
|
+
email: string;
|
|
15
|
+
externalId?: string;
|
|
16
|
+
firstName: string;
|
|
17
|
+
lastName: string;
|
|
18
|
+
phone?: string;
|
|
19
|
+
city?: string;
|
|
20
|
+
state?: string;
|
|
21
|
+
zipCode?: string;
|
|
22
|
+
country?: string;
|
|
23
|
+
ip?: string;
|
|
24
|
+
userAgent?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ProductData {
|
|
27
|
+
id: string;
|
|
28
|
+
title: string;
|
|
29
|
+
externalId: string;
|
|
30
|
+
quantity: number;
|
|
31
|
+
}
|
|
32
|
+
export interface Order {
|
|
33
|
+
dispatch: MarketingPlatform;
|
|
34
|
+
event: PurchaseEventType;
|
|
35
|
+
checkout: string;
|
|
36
|
+
orderId: string;
|
|
37
|
+
subscriptionId?: string;
|
|
38
|
+
fbc?: string;
|
|
39
|
+
fbp?: string;
|
|
40
|
+
fbclid?: string;
|
|
41
|
+
gclid?: string;
|
|
42
|
+
gbraid?: string;
|
|
43
|
+
wbraid?: string;
|
|
44
|
+
currency: string;
|
|
45
|
+
valueGross: number;
|
|
46
|
+
valueNet: number;
|
|
47
|
+
createdAt: Date;
|
|
48
|
+
customer: CustomerData;
|
|
49
|
+
products: ProductData[];
|
|
50
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PurchaseEventTypeEnum = exports.MarketingPlatformEnum = exports.SendIpEnum = exports.PurchaseValueTypeEnum = exports.PurchaseSendTypeEnum = exports.InitiateCheckoutDetectionEnum = void 0;
|
|
4
|
+
exports.InitiateCheckoutDetectionEnum = {
|
|
5
|
+
AUTOMATIC: "AUTOMATIC",
|
|
6
|
+
CONTAINS_TEXT: "CONTAINS_TEXT",
|
|
7
|
+
CONTAINS_CSS: "CONTAINS_CSS",
|
|
8
|
+
CONTAINS_URL: "CONTAINS_URL",
|
|
9
|
+
};
|
|
10
|
+
exports.PurchaseSendTypeEnum = {
|
|
11
|
+
SALES_APPROVED: "SALES_APPROVED",
|
|
12
|
+
SALES_APPROVED_AND_PENDING: "SALES_APPROVED_AND_PENDING",
|
|
13
|
+
};
|
|
14
|
+
exports.PurchaseValueTypeEnum = {
|
|
15
|
+
SALE_VALUE: "SALE_VALUE",
|
|
16
|
+
COMMISSION: "COMMISSION",
|
|
17
|
+
};
|
|
18
|
+
exports.SendIpEnum = {
|
|
19
|
+
IPV6_AND_IPV4: "IPV6_AND_IPV4",
|
|
20
|
+
ONLY_IPV6: "ONLY_IPV6",
|
|
21
|
+
DONT_SEND: "DONT_SEND",
|
|
22
|
+
};
|
|
23
|
+
exports.MarketingPlatformEnum = {
|
|
24
|
+
META: "META",
|
|
25
|
+
GOOGLE: "GOOGLE",
|
|
26
|
+
TIKTOK: "TIKTOK",
|
|
27
|
+
};
|
|
28
|
+
exports.PurchaseEventTypeEnum = {
|
|
29
|
+
PURCHASE_PENDING: "PURCHASE_PENDING",
|
|
30
|
+
PURCHASE_COMPLETED: "PURCHASE_COMPLETED",
|
|
31
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agenus-io/pixel-backend-sdk",
|
|
3
|
+
"version": "1.0.18",
|
|
4
|
+
"description": "SDK para envio de vendas para fila AWS SQS do micro-serviço de pixels",
|
|
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
|
+
"pixel",
|
|
13
|
+
"aws",
|
|
14
|
+
"sqs",
|
|
15
|
+
"sales",
|
|
16
|
+
"facebook",
|
|
17
|
+
"google",
|
|
18
|
+
"tiktok"
|
|
19
|
+
],
|
|
20
|
+
"author": "David",
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"aws-sdk": "^2.1692.0",
|
|
24
|
+
"axios": "^1.13.2"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^24.5.2",
|
|
28
|
+
"typescript": "^5.9.2"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"README.md"
|
|
33
|
+
]
|
|
34
|
+
}
|