@agenus-io/webhook-centralizer 1.0.4 → 1.0.5

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.
@@ -1,4 +1,4 @@
1
- import { ICreatePlatformDTO, IDeletePlatformDTO, IGetPlatformDTO, IGetPlatformWebhooksDTO, IUpdatePlatformDTO, IWebhookCentralizeSDK } from './interface';
1
+ import { ICreatePlatformDTO, IDeletePlatformDTO, IGetPlatformByTitleDTO, IGetPlatformDTO, IGetPlatformWebhooksDTO, IUpdatePlatformDTO, IWebhookCentralizeSDK } from './interface';
2
2
  /**
3
3
  * Classe responsável pela centralização de webhooks de plataformas de pagamento e envio de webhooks para o microserviço de webhooks
4
4
  */
@@ -13,8 +13,9 @@ export declare class WebhookCentralizerSDK implements IWebhookCentralizeSDK {
13
13
  */
14
14
  constructor(appId: string, appToken: string, environment?: "production" | "develop");
15
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>;
16
+ Update({ id, workSpaceId, ...data }: IUpdatePlatformDTO.Params): Promise<IUpdatePlatformDTO.Result>;
17
+ Delete({ id, workSpaceId }: IDeletePlatformDTO.Params): Promise<IDeletePlatformDTO.Result>;
18
18
  Get({ page, pageSize, filter, workSpaceId }: IGetPlatformDTO.Params): Promise<IGetPlatformDTO.Result>;
19
+ GetByTitle({ title, workSpaceId }: IGetPlatformByTitleDTO.Params): Promise<IGetPlatformByTitleDTO.Result>;
19
20
  GetWebhooks({ id, page, pageSize, filter, workSpaceId }: IGetPlatformWebhooksDTO.Params): Promise<IGetPlatformWebhooksDTO.Result>;
20
21
  }
@@ -66,7 +66,10 @@ class WebhookCentralizerSDK {
66
66
  else {
67
67
  console.log(error);
68
68
  }
69
- throw "Erro ao criar pixel";
69
+ return {
70
+ isError: true,
71
+ error: error,
72
+ };
70
73
  }
71
74
  }
72
75
  async Update({ id, workSpaceId, ...data }) {
@@ -76,7 +79,9 @@ class WebhookCentralizerSDK {
76
79
  secretToken: this.appToken,
77
80
  workSpaceId,
78
81
  };
79
- await axios_1.default.put(`${this.apiUrl}/platform/${id}`, { token, ...data });
82
+ const res = await axios_1.default.put(`${this.apiUrl}/platform/${id}`, { token, ...data });
83
+ const result = res.data;
84
+ return result;
80
85
  }
81
86
  catch (error) {
82
87
  if (error instanceof axios_1.AxiosError) {
@@ -85,7 +90,10 @@ class WebhookCentralizerSDK {
85
90
  else {
86
91
  console.log(error);
87
92
  }
88
- throw "Erro ao atualizar pixel";
93
+ return {
94
+ isError: true,
95
+ error: error,
96
+ };
89
97
  }
90
98
  }
91
99
  async Delete({ id, workSpaceId }) {
@@ -98,6 +106,9 @@ class WebhookCentralizerSDK {
98
106
  await axios_1.default.delete(`${this.apiUrl}/platform/${id}`, {
99
107
  headers: { "app-id": token.appId, "app-secret-token": token.secretToken, "work-space-id": token.workSpaceId },
100
108
  });
109
+ return {
110
+ isError: false,
111
+ };
101
112
  }
102
113
  catch (error) {
103
114
  if (error instanceof axios_1.AxiosError) {
@@ -106,7 +117,10 @@ class WebhookCentralizerSDK {
106
117
  else {
107
118
  console.log(error);
108
119
  }
109
- throw "Erro ao deletar pixel";
120
+ return {
121
+ isError: true,
122
+ error: error,
123
+ };
110
124
  }
111
125
  }
112
126
  async Get({ page, pageSize, filter, workSpaceId }) {
@@ -132,6 +146,29 @@ class WebhookCentralizerSDK {
132
146
  throw "Erro ao listar pixel";
133
147
  }
134
148
  }
149
+ async GetByTitle({ title, workSpaceId }) {
150
+ try {
151
+ const token = {
152
+ appId: this.appId,
153
+ secretToken: this.appToken,
154
+ workSpaceId,
155
+ };
156
+ const response = await axios_1.default.get(`${this.apiUrl}/platform/title`, {
157
+ headers: { "app-id": token.appId, "app-secret-token": token.secretToken, "work-space-id": token.workSpaceId },
158
+ params: { title },
159
+ });
160
+ return response.data;
161
+ }
162
+ catch (error) {
163
+ if (error instanceof axios_1.AxiosError) {
164
+ console.log(error.response?.data);
165
+ }
166
+ else {
167
+ console.log(error);
168
+ }
169
+ throw "Erro ao buscar plataforma por título";
170
+ }
171
+ }
135
172
  async GetWebhooks({ id, page, pageSize, filter, workSpaceId }) {
136
173
  try {
137
174
  const token = {
@@ -1,5 +1,6 @@
1
1
  import { webhookCentralizerOrderStatus, webhookCentralizerPlatform } from './../types';
2
2
  import { webhookCentralizerDispatchType } from '../types';
3
+ import { JsonValue } from 'aws-sdk/clients/appmesh';
3
4
  interface ICreatePlatformDTO {
4
5
  title: string;
5
6
  platformToken: string;
@@ -13,7 +14,9 @@ interface ICreatePlatformDTO {
13
14
  export declare namespace ICreatePlatformDTO {
14
15
  type Params = ICreatePlatformDTO;
15
16
  type Result = {
16
- id: string;
17
+ id?: string;
18
+ error?: any;
19
+ isError?: boolean;
17
20
  };
18
21
  }
19
22
  export declare namespace IUpdatePlatformDTO {
@@ -21,12 +24,20 @@ export declare namespace IUpdatePlatformDTO {
21
24
  id: string;
22
25
  workSpaceId: string;
23
26
  } & Partial<ICreatePlatformDTO>;
27
+ type Result = {
28
+ isError?: boolean;
29
+ error?: any;
30
+ };
24
31
  }
25
32
  export declare namespace IDeletePlatformDTO {
26
33
  type Params = {
27
34
  id: string;
28
35
  workSpaceId: string;
29
36
  };
37
+ type Result = {
38
+ isError?: boolean;
39
+ error?: any;
40
+ };
30
41
  }
31
42
  export declare namespace IGetPlatformDTO {
32
43
  type Params = {
@@ -90,11 +101,35 @@ export declare namespace IGetPlatformWebhooksDTO {
90
101
  };
91
102
  };
92
103
  }
104
+ export declare namespace IGetPlatformByTitleDTO {
105
+ type Params = {
106
+ title: string;
107
+ workSpaceId: string;
108
+ };
109
+ type Result = {
110
+ id: string;
111
+ title: string;
112
+ status: boolean;
113
+ dispatchType: webhookCentralizerDispatchType;
114
+ type: webhookCentralizerPlatform;
115
+ apiToken: string | null;
116
+ slug: string | null;
117
+ url: string;
118
+ platformSettingId: string;
119
+ appId: string;
120
+ workSpaceId: string;
121
+ meta: JsonValue | null;
122
+ createdAt: Date;
123
+ updatedAt: Date;
124
+ isDeleted: boolean;
125
+ };
126
+ }
93
127
  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>;
128
+ Create(data: ICreatePlatformDTO.Params): Promise<ICreatePlatformDTO.Result>;
129
+ Update(data: IUpdatePlatformDTO.Params): Promise<IUpdatePlatformDTO.Result>;
130
+ Delete(data: IDeletePlatformDTO.Params): Promise<IDeletePlatformDTO.Result>;
131
+ Get(data: IGetPlatformDTO.Params): Promise<IGetPlatformDTO.Result>;
132
+ GetWebhooks(data: IGetPlatformWebhooksDTO.Params): Promise<IGetPlatformWebhooksDTO.Result>;
133
+ GetByTitle(data: IGetPlatformByTitleDTO.Params): Promise<IGetPlatformByTitleDTO.Result>;
99
134
  }
100
135
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agenus-io/webhook-centralizer",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
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",