@agenus-io/webhook-centralizer 1.0.1 → 1.0.3

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.
@@ -0,0 +1,20 @@
1
+ import { ICreatePlatformDTO, IDeletePlatformDTO, IGetPlatformDTO, IGetPlatformWebhooksDTO, IUpdatePlatformDTO, IWebhookCentralizeSDK } from './interface';
2
+ /**
3
+ * Classe responsável pela centralização de webhooks de plataformas de pagamento e envio de webhooks para o microserviço de webhooks
4
+ */
5
+ export declare class WebhookCentralizerSDK implements IWebhookCentralizeSDK {
6
+ private appId;
7
+ private appToken;
8
+ private apiUrl;
9
+ /**
10
+ * Constrói uma instância do SDK com as credenciais da aplicação
11
+ * @param appId ID da aplicação
12
+ * @param appToken Token da aplicação
13
+ */
14
+ constructor(appId: string, appToken: string, environment?: "production" | "develop");
15
+ Create({ workSpaceId, ...data }: ICreatePlatformDTO.Params): Promise<ICreatePlatformDTO.Result>;
16
+ Update({ id, workSpaceId, ...data }: IUpdatePlatformDTO.Params): Promise<void>;
17
+ Delete({ id, workSpaceId }: IDeletePlatformDTO.Params): Promise<void>;
18
+ Get({ page, pageSize, filter, workSpaceId }: IGetPlatformDTO.Params): Promise<IGetPlatformDTO.Result>;
19
+ GetWebhooks({ id, page, pageSize, filter, workSpaceId }: IGetPlatformWebhooksDTO.Params): Promise<IGetPlatformWebhooksDTO.Result>;
20
+ }
@@ -1,198 +1,159 @@
1
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
- // }
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
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.WebhookCentralizerSDK = void 0;
37
+ const axios_1 = __importStar(require("axios"));
38
+ /**
39
+ * Classe responsável pela centralização de webhooks de plataformas de pagamento e envio de webhooks para o microserviço de webhooks
40
+ */
41
+ class WebhookCentralizerSDK {
42
+ /**
43
+ * Constrói uma instância do SDK com as credenciais da aplicação
44
+ * @param appId ID da aplicação
45
+ * @param appToken Token da aplicação
46
+ */
47
+ constructor(appId, appToken, environment = "production") {
48
+ this.appId = appId;
49
+ this.appToken = appToken;
50
+ this.apiUrl = environment === "production" ? "http://localhost:3333" : "http://localhost:3333";
51
+ }
52
+ async Create({ workSpaceId, ...data }) {
53
+ try {
54
+ const token = {
55
+ appId: this.appId,
56
+ secretToken: this.appToken,
57
+ workSpaceId,
58
+ };
59
+ const response = await axios_1.default.post(`${this.apiUrl}/platform`, { token, ...data });
60
+ return response.data;
61
+ }
62
+ catch (error) {
63
+ if (error instanceof axios_1.AxiosError) {
64
+ console.log(error.response?.data);
65
+ }
66
+ else {
67
+ console.log(error);
68
+ }
69
+ throw "Erro ao criar pixel";
70
+ }
71
+ }
72
+ async Update({ id, workSpaceId, ...data }) {
73
+ try {
74
+ const token = {
75
+ appId: this.appId,
76
+ secretToken: this.appToken,
77
+ workSpaceId,
78
+ };
79
+ await axios_1.default.put(`${this.apiUrl}/platform/${id}`, { token, ...data });
80
+ }
81
+ catch (error) {
82
+ if (error instanceof axios_1.AxiosError) {
83
+ console.log(error.response?.data);
84
+ }
85
+ else {
86
+ console.log(error);
87
+ }
88
+ throw "Erro ao atualizar pixel";
89
+ }
90
+ }
91
+ async Delete({ id, workSpaceId }) {
92
+ try {
93
+ const token = {
94
+ appId: this.appId,
95
+ secretToken: this.appToken,
96
+ workSpaceId,
97
+ };
98
+ await axios_1.default.delete(`${this.apiUrl}/platform/${id}`, {
99
+ headers: { "app-id": token.appId, "app-secret-token": token.secretToken, "work-space-id": token.workSpaceId },
100
+ });
101
+ }
102
+ catch (error) {
103
+ if (error instanceof axios_1.AxiosError) {
104
+ console.log(error.response?.data);
105
+ }
106
+ else {
107
+ console.log(error);
108
+ }
109
+ throw "Erro ao deletar pixel";
110
+ }
111
+ }
112
+ async Get({ page, pageSize, filter, workSpaceId }) {
113
+ try {
114
+ const token = {
115
+ appId: this.appId,
116
+ secretToken: this.appToken,
117
+ workSpaceId,
118
+ };
119
+ const response = await axios_1.default.get(`${this.apiUrl}/platform`, {
120
+ headers: { "app-id": token.appId, "app-secret-token": token.secretToken, "work-space-id": token.workSpaceId },
121
+ params: { page, pageSize, filter },
122
+ });
123
+ return response.data;
124
+ }
125
+ catch (error) {
126
+ if (error instanceof axios_1.AxiosError) {
127
+ console.log(error.response?.data);
128
+ }
129
+ else {
130
+ console.log(error);
131
+ }
132
+ throw "Erro ao listar pixel";
133
+ }
134
+ }
135
+ async GetWebhooks({ id, page, pageSize, filter, workSpaceId }) {
136
+ try {
137
+ const token = {
138
+ appId: this.appId,
139
+ secretToken: this.appToken,
140
+ workSpaceId,
141
+ };
142
+ const response = await axios_1.default.get(`${this.apiUrl}/platform/${id}/webhooks`, {
143
+ headers: { "app-id": token.appId, "app-secret-token": token.secretToken, "work-space-id": token.workSpaceId },
144
+ params: { page, pageSize, filter },
145
+ });
146
+ return response.data;
147
+ }
148
+ catch (error) {
149
+ if (error instanceof axios_1.AxiosError) {
150
+ console.log(error.response?.data);
151
+ }
152
+ else {
153
+ console.log(error);
154
+ }
155
+ throw "Erro ao listar webhooks";
156
+ }
157
+ }
158
+ }
159
+ exports.WebhookCentralizerSDK = WebhookCentralizerSDK;
@@ -0,0 +1,100 @@
1
+ import { webhookCentralizerOrderStatus, webhookCentralizerPlatform } from './../types';
2
+ import { webhookCentralizerDispatchType } from '../types';
3
+ interface ICreatePlatformDTO {
4
+ title: string;
5
+ platformToken: string;
6
+ dispatchType: webhookCentralizerDispatchType;
7
+ type: webhookCentralizerPlatform;
8
+ apiToken?: string;
9
+ meta?: Record<string, any>;
10
+ slug?: string;
11
+ workSpaceId: string;
12
+ }
13
+ export declare namespace ICreatePlatformDTO {
14
+ type Params = ICreatePlatformDTO;
15
+ type Result = {
16
+ id: string;
17
+ };
18
+ }
19
+ export declare namespace IUpdatePlatformDTO {
20
+ type Params = {
21
+ id: string;
22
+ workSpaceId: string;
23
+ } & Partial<ICreatePlatformDTO>;
24
+ }
25
+ export declare namespace IDeletePlatformDTO {
26
+ type Params = {
27
+ id: string;
28
+ workSpaceId: string;
29
+ };
30
+ }
31
+ export declare namespace IGetPlatformDTO {
32
+ type Params = {
33
+ page: number;
34
+ pageSize: number;
35
+ filter?: string;
36
+ workSpaceId: string;
37
+ };
38
+ type Result = {
39
+ data: {
40
+ id: string;
41
+ title: string;
42
+ status: boolean;
43
+ dispatchType: webhookCentralizerDispatchType;
44
+ type: webhookCentralizerPlatform;
45
+ apiToken: string | null;
46
+ slug: string | null;
47
+ url: string;
48
+ meta: Record<string, any> | null;
49
+ createdAt: Date;
50
+ updatedAt: Date;
51
+ icon: {
52
+ id: string;
53
+ url: string;
54
+ size: number;
55
+ mimeType: string;
56
+ } | null;
57
+ amountAccepted: number;
58
+ amountRejected: number;
59
+ }[];
60
+ meta: {
61
+ total: number;
62
+ totalPages: number;
63
+ page: number;
64
+ pageSize: number;
65
+ };
66
+ };
67
+ }
68
+ export declare namespace IGetPlatformWebhooksDTO {
69
+ type Params = {
70
+ id: string;
71
+ page: number;
72
+ pageSize: number;
73
+ filter?: string;
74
+ status?: webhookCentralizerOrderStatus;
75
+ workSpaceId: string;
76
+ };
77
+ type Result = {
78
+ data: {
79
+ id: string;
80
+ status: webhookCentralizerOrderStatus;
81
+ createdAt: Date;
82
+ updatedAt: Date;
83
+ data: any;
84
+ };
85
+ meta: {
86
+ total: number;
87
+ totalPages: number;
88
+ page: number;
89
+ pageSize: number;
90
+ };
91
+ };
92
+ }
93
+ export interface IWebhookCentralizeSDK {
94
+ Create: (params: ICreatePlatformDTO.Params) => Promise<ICreatePlatformDTO.Result>;
95
+ Update: (params: IUpdatePlatformDTO.Params) => Promise<void>;
96
+ Delete: (params: IDeletePlatformDTO.Params) => Promise<void>;
97
+ Get: (params: IGetPlatformDTO.Params) => Promise<IGetPlatformDTO.Result>;
98
+ GetWebhooks: (params: IGetPlatformWebhooksDTO.Params) => Promise<IGetPlatformWebhooksDTO.Result>;
99
+ }
100
+ export {};
@@ -1,188 +1,2 @@
1
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
- // }
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,27 @@
1
+ export declare const WebhookCentralizerCreatePlatformSchema: import("zod").ZodObject<{
2
+ title: import("zod").ZodString;
3
+ platformToken: import("zod").ZodOptional<import("zod").ZodString>;
4
+ dispatchType: import("zod").ZodDefault<import("zod").ZodEnum<Record<import("../types").webhookCentralizerDispatchType, import("../types").webhookCentralizerDispatchType>>>;
5
+ type: import("zod").ZodEnum<Record<import("../types").webhookCentralizerPlatform, import("../types").webhookCentralizerPlatform>>;
6
+ apiToken: import("zod").ZodOptional<import("zod").ZodString>;
7
+ slug: import("zod").ZodOptional<import("zod").ZodString>;
8
+ }, import("zod/v4/core").$strip>;
9
+ export declare const WebhookCentralizerUpdatePlatformSchema: import("zod").ZodObject<{
10
+ title: import("zod").ZodOptional<import("zod").ZodString>;
11
+ platformToken: import("zod").ZodOptional<import("zod").ZodString>;
12
+ dispatchType: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodEnum<Record<import("../types").webhookCentralizerDispatchType, import("../types").webhookCentralizerDispatchType>>>>;
13
+ type: import("zod").ZodOptional<import("zod").ZodEnum<Record<import("../types").webhookCentralizerPlatform, import("../types").webhookCentralizerPlatform>>>;
14
+ apiToken: import("zod").ZodOptional<import("zod").ZodString>;
15
+ slug: import("zod").ZodOptional<import("zod").ZodOptional<import("zod").ZodString>>;
16
+ }, import("zod/v4/core").$strip>;
17
+ export declare const WebhookCentralizerGetPlatformsSchema: import("zod").ZodObject<{
18
+ page: import("zod").ZodDefault<import("zod").ZodCoercedNumber<unknown>>;
19
+ pageSize: import("zod").ZodDefault<import("zod").ZodCoercedNumber<unknown>>;
20
+ filter: import("zod").ZodOptional<import("zod").ZodString>;
21
+ }, import("zod/v4/core").$strip>;
22
+ export declare const WebhookCentralizerGetPlatformWebhooksSchema: import("zod").ZodObject<{
23
+ page: import("zod").ZodDefault<import("zod").ZodCoercedNumber<unknown>>;
24
+ status: import("zod").ZodOptional<import("zod").ZodEnum<Record<import("../types").webhookCentralizerOrderStatus, import("../types").webhookCentralizerOrderStatus>>>;
25
+ pageSize: import("zod").ZodDefault<import("zod").ZodCoercedNumber<unknown>>;
26
+ filter: import("zod").ZodOptional<import("zod").ZodString>;
27
+ }, import("zod/v4/core").$strip>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebhookCentralizerGetPlatformWebhooksSchema = exports.WebhookCentralizerGetPlatformsSchema = exports.WebhookCentralizerUpdatePlatformSchema = exports.WebhookCentralizerCreatePlatformSchema = void 0;
4
+ const config_1 = require("../config");
5
+ const types_1 = require("../types");
6
+ const zod_1 = require("../Utils/zod");
7
+ exports.WebhookCentralizerCreatePlatformSchema = config_1.zod.object({
8
+ title: (0, zod_1.stringField)().min(3),
9
+ platformToken: (0, zod_1.stringField)().optional(),
10
+ dispatchType: (0, zod_1.nativeEnumField)(types_1.WebhookCentralizerDispatchTypeEnum).default("WEBHOOK"),
11
+ type: (0, zod_1.nativeEnumField)(types_1.WebhookCentralizerPlatformEnum),
12
+ apiToken: (0, zod_1.stringField)().optional(),
13
+ slug: (0, zod_1.stringField)().optional(),
14
+ });
15
+ exports.WebhookCentralizerUpdatePlatformSchema = config_1.zod.object({
16
+ title: (0, zod_1.stringField)().min(3).optional(),
17
+ platformToken: (0, zod_1.stringField)().optional(),
18
+ dispatchType: (0, zod_1.nativeEnumField)(types_1.WebhookCentralizerDispatchTypeEnum).default("WEBHOOK").optional(),
19
+ type: (0, zod_1.nativeEnumField)(types_1.WebhookCentralizerPlatformEnum).optional(),
20
+ apiToken: (0, zod_1.stringField)().optional(),
21
+ slug: (0, zod_1.stringField)().optional().optional(),
22
+ });
23
+ exports.WebhookCentralizerGetPlatformsSchema = config_1.zod.object({
24
+ page: (0, zod_1.numberField)().default(1),
25
+ pageSize: (0, zod_1.numberField)().default(10),
26
+ filter: (0, zod_1.stringField)().optional(),
27
+ });
28
+ exports.WebhookCentralizerGetPlatformWebhooksSchema = config_1.zod.object({
29
+ page: (0, zod_1.numberField)().default(1),
30
+ status: (0, zod_1.nativeEnumField)(types_1.WebhookCentralizerStatusEnum).optional(),
31
+ pageSize: (0, zod_1.numberField)().default(10),
32
+ filter: (0, zod_1.stringField)().optional(),
33
+ });
@@ -0,0 +1,12 @@
1
+ import type { ZodRawShape, ZodTypeAny, z } from "zod";
2
+ export declare const stringField: () => z.ZodString;
3
+ export declare const booleanField: () => z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodBoolean>;
4
+ export declare const numberField: () => z.ZodCoercedNumber<unknown>;
5
+ export declare const dateField: () => z.ZodCoercedDate<unknown>;
6
+ export declare const objectField: <T extends ZodRawShape>(schema: T) => z.ZodPipe<z.ZodTransform<any, unknown>, z.ZodObject<{ -readonly [P in keyof T]: T[P]; }, z.core.$strip>>;
7
+ export declare const startDateField: () => z.ZodPipe<z.ZodCoercedDate<unknown>, z.ZodTransform<Date, Date>>;
8
+ export declare const endDateField: () => z.ZodPipe<z.ZodCoercedDate<unknown>, z.ZodTransform<Date, Date>>;
9
+ export declare const nativeEnumField: <T extends Record<string, string | number>>(values: T) => z.ZodEnum<T>;
10
+ export declare const enumField: <U extends string, T extends Readonly<[U, ...U[]]>>(values: T) => z.ZodEnum<{ [k_1 in T[number]]: k_1; } extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never>;
11
+ export declare const arrayField: <T extends ZodTypeAny>(schema: T) => z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodArray<T>>;
12
+ export declare const formDataField: <T extends ZodTypeAny>(schema: T) => z.ZodPipe<z.ZodTransform<any, unknown>, T>;
@@ -0,0 +1,59 @@
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.formDataField = exports.arrayField = exports.enumField = exports.nativeEnumField = exports.endDateField = exports.startDateField = exports.objectField = exports.dateField = exports.numberField = exports.booleanField = exports.stringField = void 0;
7
+ const config_1 = require("../config");
8
+ const dayjs_1 = __importDefault(require("dayjs"));
9
+ // funcionam tanto em um body/json, multipart-formdata, query params
10
+ const stringField = () => config_1.zod.string().trim();
11
+ exports.stringField = stringField;
12
+ const booleanField = () => config_1.zod.preprocess((value) => {
13
+ if (value === "true")
14
+ return true;
15
+ if (value === "false")
16
+ return false;
17
+ return value;
18
+ }, config_1.zod.boolean());
19
+ exports.booleanField = booleanField;
20
+ const numberField = () => config_1.zod.coerce.number();
21
+ exports.numberField = numberField;
22
+ const dateField = () => config_1.zod.coerce.date();
23
+ exports.dateField = dateField;
24
+ const objectField = (schema) => config_1.zod.preprocess((value) => {
25
+ if (typeof value === "string") {
26
+ try {
27
+ return JSON.parse(value.replace(/([a-zA-Z0-9_]+):/g, '"$1":'));
28
+ }
29
+ catch {
30
+ throw new Error("Formato de objeto inválido");
31
+ }
32
+ }
33
+ return value;
34
+ }, config_1.zod.object(schema));
35
+ exports.objectField = objectField;
36
+ const startDateField = () => config_1.zod.coerce.date().transform((date) => (0, dayjs_1.default)(date).startOf("day").add(1, "day").toDate());
37
+ exports.startDateField = startDateField;
38
+ const endDateField = () => config_1.zod.coerce.date().transform((date) => (0, dayjs_1.default)(date).endOf("day").add(1, "day").toDate());
39
+ exports.endDateField = endDateField;
40
+ const nativeEnumField = (values) => config_1.zod.nativeEnum(values);
41
+ exports.nativeEnumField = nativeEnumField;
42
+ const enumField = (values) => config_1.zod.enum(values);
43
+ exports.enumField = enumField;
44
+ const arrayField = (schema) => config_1.zod.preprocess((value) => {
45
+ if (typeof value === "string") {
46
+ return value.split(",");
47
+ }
48
+ return value;
49
+ }, config_1.zod.array(schema));
50
+ exports.arrayField = arrayField;
51
+ const formDataField = (schema) => config_1.zod
52
+ .preprocess((value) => {
53
+ if (typeof value === "string") {
54
+ return JSON.parse(value);
55
+ }
56
+ return value;
57
+ }, schema)
58
+ .describe("Enviar como JSON");
59
+ exports.formDataField = formDataField;
package/dist/config.d.ts CHANGED
@@ -0,0 +1,2 @@
1
+ import { z } from "zod";
2
+ export declare const zod: typeof z;
package/dist/config.js CHANGED
@@ -1,35 +1,7 @@
1
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
- // }
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.zod = void 0;
4
+ const zod_to_openapi_1 = require("@asteasolutions/zod-to-openapi");
5
+ const zod_1 = require("zod");
6
+ (0, zod_to_openapi_1.extendZodWithOpenApi)(zod_1.z);
7
+ exports.zod = zod_1.z;
package/dist/index.d.ts CHANGED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * SDK para centralização de webhooks focado atualmente em plataformas de pagamentos
3
+ *
4
+ * Este pacote permite que aplicações clientes centralizem e processem
5
+ * webhooks de plataformas de pagamento através de uma fila AWS SQS.
6
+ */
7
+ export { WebhookCentralizerSDK } from "./Class";
8
+ export type { webhookCentralizerDispatchType, webhookCentralizerPlatform, webhookCentralizerOrderStatus, WebhookCentralizerDispatchTypeEnum, WebhookCentralizerPlatformEnum, WebhookCentralizerStatusEnum, } from "./types";
9
+ export { WebhookCentralizerGetPlatformWebhooksSchema, WebhookCentralizerCreatePlatformSchema, WebhookCentralizerUpdatePlatformSchema, WebhookCentralizerGetPlatformsSchema, } from "./Schema";
package/dist/index.js CHANGED
@@ -1,26 +1,16 @@
1
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";
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
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.WebhookCentralizerGetPlatformsSchema = exports.WebhookCentralizerUpdatePlatformSchema = exports.WebhookCentralizerCreatePlatformSchema = exports.WebhookCentralizerGetPlatformWebhooksSchema = exports.WebhookCentralizerSDK = void 0;
10
+ var Class_1 = require("./Class");
11
+ Object.defineProperty(exports, "WebhookCentralizerSDK", { enumerable: true, get: function () { return Class_1.WebhookCentralizerSDK; } });
12
+ var Schema_1 = require("./Schema");
13
+ Object.defineProperty(exports, "WebhookCentralizerGetPlatformWebhooksSchema", { enumerable: true, get: function () { return Schema_1.WebhookCentralizerGetPlatformWebhooksSchema; } });
14
+ Object.defineProperty(exports, "WebhookCentralizerCreatePlatformSchema", { enumerable: true, get: function () { return Schema_1.WebhookCentralizerCreatePlatformSchema; } });
15
+ Object.defineProperty(exports, "WebhookCentralizerUpdatePlatformSchema", { enumerable: true, get: function () { return Schema_1.WebhookCentralizerUpdatePlatformSchema; } });
16
+ Object.defineProperty(exports, "WebhookCentralizerGetPlatformsSchema", { enumerable: true, get: function () { return Schema_1.WebhookCentralizerGetPlatformsSchema; } });
package/dist/types.d.ts CHANGED
@@ -0,0 +1,6 @@
1
+ export type webhookCentralizerDispatchType = "WEBHOOK" | "POST_BACK";
2
+ export type webhookCentralizerPlatform = "BEMONY" | "B4YOU" | "BRAIP" | "CARTPANDA" | "NUTRALINK" | "HOTMART" | "KIRVANO" | "KIWIFY" | "LAST_LINK" | "PAYT" | "DIGISTORE";
3
+ export type webhookCentralizerOrderStatus = "PENDING" | "PROCESSING" | "COMPLETED" | "FAILED";
4
+ export declare const WebhookCentralizerDispatchTypeEnum: Record<webhookCentralizerDispatchType, webhookCentralizerDispatchType>;
5
+ export declare const WebhookCentralizerPlatformEnum: Record<webhookCentralizerPlatform, webhookCentralizerPlatform>;
6
+ export declare const WebhookCentralizerStatusEnum: Record<webhookCentralizerOrderStatus, webhookCentralizerOrderStatus>;
package/dist/types.js CHANGED
@@ -1,78 +1,26 @@
1
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
- // }
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebhookCentralizerStatusEnum = exports.WebhookCentralizerPlatformEnum = exports.WebhookCentralizerDispatchTypeEnum = void 0;
4
+ exports.WebhookCentralizerDispatchTypeEnum = {
5
+ WEBHOOK: "WEBHOOK",
6
+ POST_BACK: "POST_BACK",
7
+ };
8
+ exports.WebhookCentralizerPlatformEnum = {
9
+ BEMONY: "BEMONY",
10
+ B4YOU: "B4YOU",
11
+ BRAIP: "BRAIP",
12
+ CARTPANDA: "CARTPANDA",
13
+ NUTRALINK: "NUTRALINK",
14
+ HOTMART: "HOTMART",
15
+ KIRVANO: "KIRVANO",
16
+ KIWIFY: "KIWIFY",
17
+ LAST_LINK: "LAST_LINK",
18
+ PAYT: "PAYT",
19
+ DIGISTORE: "DIGISTORE",
20
+ };
21
+ exports.WebhookCentralizerStatusEnum = {
22
+ PENDING: "PENDING",
23
+ PROCESSING: "PROCESSING",
24
+ COMPLETED: "COMPLETED",
25
+ FAILED: "FAILED",
26
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agenus-io/webhook-centralizer",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "SDK para centralização de webhooks focado atualmente em plataformas de pagamentos",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,8 +18,11 @@
18
18
  "email": "davidpimanta@gmail.com",
19
19
  "license": "ISC",
20
20
  "dependencies": {
21
+ "@asteasolutions/zod-to-openapi": "^8.4.0",
21
22
  "aws-sdk": "^2.1692.0",
22
- "axios": "^1.13.2"
23
+ "axios": "^1.13.2",
24
+ "dayjs": "^1.11.19",
25
+ "zod": "^4.3.5"
23
26
  },
24
27
  "devDependencies": {
25
28
  "@types/node": "^24.5.2",