@fiado/api-invoker 5.14.0 → 5.15.0

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.
@@ -48,6 +48,7 @@ import TransactionAlertApi from "./riskProfile/api/TransactionAlertApi.js";
48
48
  import { DirectoriesApi } from "./directories/index.js";
49
49
  import CognitoConnectorApi from "./cognitoConnector/CognitoConnectorApi.js";
50
50
  import { ZendeskApi } from "./zendesk/index.js";
51
+ import ZendeskAlertsPublisher from "./zendesk/queue/ZendeskAlertsPublisher.js";
51
52
  import { BlackListApi } from "./blacklist/index.js";
52
53
  import { DeviceApi } from "./device/index.js";
53
54
  import { ObservationsApi } from "./observations/index.js";
@@ -182,6 +183,7 @@ export const apiInvokerBindings = new ContainerModule(({ bind }) => {
182
183
  bind("ICognitoConnectorApi").to(CognitoConnectorApi);
183
184
  bind("ICognitoV2Api").to(CognitoApi);
184
185
  bind("IZendeskApi").to(ZendeskApi);
186
+ bind("IZendeskAlertsPublisher").to(ZendeskAlertsPublisher);
185
187
  bind("IBlackListApi").to(BlackListApi);
186
188
  bind("IDeviceApi").to(DeviceApi);
187
189
  bind("IObservationsApi").to(ObservationsApi);
@@ -1,2 +1,4 @@
1
1
  export * from './interfaces/IZendeskApi.js';
2
2
  export * from './ZendeskApi.js';
3
+ export * from './queue/interfaces/IZendeskAlertsPublisher.js';
4
+ export { default as ZendeskAlertsPublisher } from './queue/ZendeskAlertsPublisher.js';
@@ -1,2 +1,4 @@
1
1
  export * from './interfaces/IZendeskApi.js';
2
2
  export * from './ZendeskApi.js';
3
+ export * from './queue/interfaces/IZendeskAlertsPublisher.js';
4
+ export { default as ZendeskAlertsPublisher } from './queue/ZendeskAlertsPublisher.js';
@@ -0,0 +1,9 @@
1
+ import { ZendeskInternalAlertRequest } from "@fiado/type-kit/bin/helpdesk/index.js";
2
+ import { SendProactiveMessageRequest } from "@fiado/type-kit/bin/zendeskMessaging/index.js";
3
+ import { IZendeskAlertsPublisher } from "./interfaces/IZendeskAlertsPublisher.js";
4
+ export default class ZendeskAlertsPublisher implements IZendeskAlertsPublisher {
5
+ private readonly ZENDESK_ALERTS_QUEUE;
6
+ createInternalNote(alert: ZendeskInternalAlertRequest): Promise<void>;
7
+ sendProactiveMessage(message: SendProactiveMessageRequest): Promise<void>;
8
+ private publish;
9
+ }
@@ -0,0 +1,37 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { injectable } from "inversify";
8
+ import { SendMessageCommand, SQSClient } from "@aws-sdk/client-sqs";
9
+ import { ZendeskAlertKind } from "@fiado/type-kit/bin/helpdesk/index.js";
10
+ let ZendeskAlertsPublisher = class ZendeskAlertsPublisher {
11
+ ZENDESK_ALERTS_QUEUE = process.env.ZENDESK_ALERTS_QUEUE;
12
+ async createInternalNote(alert) {
13
+ await this.publish({ kind: ZendeskAlertKind.INTERNAL_NOTE, payload: alert });
14
+ }
15
+ async sendProactiveMessage(message) {
16
+ await this.publish({ kind: ZendeskAlertKind.PROACTIVE_MESSAGE, payload: message });
17
+ }
18
+ async publish(message) {
19
+ try {
20
+ const client = new SQSClient();
21
+ const sendMessageRequest = {
22
+ QueueUrl: this.ZENDESK_ALERTS_QUEUE,
23
+ MessageBody: JSON.stringify(message)
24
+ };
25
+ const command = new SendMessageCommand(sendMessageRequest);
26
+ await client.send(command);
27
+ }
28
+ catch (error) {
29
+ const errorMessage = error instanceof Error ? error.message : String(error);
30
+ throw new Error(`Error publishing message to queue ${': ' + errorMessage}`);
31
+ }
32
+ }
33
+ };
34
+ ZendeskAlertsPublisher = __decorate([
35
+ injectable()
36
+ ], ZendeskAlertsPublisher);
37
+ export default ZendeskAlertsPublisher;
@@ -0,0 +1,15 @@
1
+ import { ZendeskInternalAlertRequest } from "@fiado/type-kit/bin/helpdesk/index.js";
2
+ import { SendProactiveMessageRequest } from "@fiado/type-kit/bin/zendeskMessaging/index.js";
3
+ /**
4
+ * Publica alertas hacia Zendesk sin pagar su latencia: el caller encola y sigue.
5
+ * Consume zendesk-business.
6
+ */
7
+ export interface IZendeskAlertsPublisher {
8
+ /** Nota interna sobre un usuario. Solo la ven los agentes. */
9
+ createInternalNote(alert: ZendeskInternalAlertRequest): Promise<void>;
10
+ /**
11
+ * Mensaje al chat del usuario. Si el usuario está esperando la respuesta ahora, conviene
12
+ * el endpoint síncrono `IZendeskApi.sendProactiveMessage`: acá el fallo no es inmediato.
13
+ */
14
+ sendProactiveMessage(message: SendProactiveMessageRequest): Promise<void>;
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fiado/api-invoker",
3
- "version": "5.14.0",
3
+ "version": "5.15.0",
4
4
  "description": "Sirve como un puente entre diferentes funciones lambda, facilitando la comunicación entre ellas a través de invocaciones http",
5
5
  "type": "module",
6
6
  "main": "bin/index.js",
@@ -34,7 +34,7 @@
34
34
  "@fiado/gateway-adapter": "^3.9.0",
35
35
  "@fiado/http-client": "^2.0.1",
36
36
  "@fiado/logger": "^1.1.3",
37
- "@fiado/type-kit": "^3.258.0",
37
+ "@fiado/type-kit": "^3.260.0",
38
38
  "dotenv": "^16.4.7"
39
39
  },
40
40
  "peerDependencies": {
@@ -75,6 +75,8 @@ import { DirectoriesApi, IDirectoriesApi } from "./directories/index.js";
75
75
  import { ICognitoConnectorApi, ICognitoV2Api } from "./cognitoConnector/index.js";
76
76
  import CognitoConnectorApi from "./cognitoConnector/CognitoConnectorApi.js";
77
77
  import { IZendeskApi, ZendeskApi } from "./zendesk/index.js";
78
+ import ZendeskAlertsPublisher from "./zendesk/queue/ZendeskAlertsPublisher.js";
79
+ import { IZendeskAlertsPublisher } from "./zendesk/queue/interfaces/IZendeskAlertsPublisher.js";
78
80
  import { BlackListApi, IBlackListApi } from "./blacklist/index.js";
79
81
  import { DeviceApi, IDeviceApi } from "./device/index.js";
80
82
  import { IObservationsApi, ObservationsApi } from "./observations/index.js";
@@ -247,6 +249,7 @@ export const apiInvokerBindings = new ContainerModule(({ bind }) => {
247
249
  bind<ICognitoConnectorApi>("ICognitoConnectorApi").to(CognitoConnectorApi);
248
250
  bind<ICognitoV2Api>("ICognitoV2Api").to(CognitoApi);
249
251
  bind<IZendeskApi>("IZendeskApi").to(ZendeskApi);
252
+ bind<IZendeskAlertsPublisher>("IZendeskAlertsPublisher").to(ZendeskAlertsPublisher);
250
253
  bind<IBlackListApi>("IBlackListApi").to(BlackListApi);
251
254
  bind<IDeviceApi>("IDeviceApi").to(DeviceApi);
252
255
  bind<IObservationsApi>("IObservationsApi").to(ObservationsApi);
@@ -1,3 +1,5 @@
1
1
 
2
2
  export * from './interfaces/IZendeskApi.js';
3
3
  export * from './ZendeskApi.js';
4
+ export * from './queue/interfaces/IZendeskAlertsPublisher.js';
5
+ export { default as ZendeskAlertsPublisher } from './queue/ZendeskAlertsPublisher.js';
@@ -0,0 +1,38 @@
1
+ import { injectable } from "inversify";
2
+ import { SendMessageCommand, SendMessageRequest, SQSClient } from "@aws-sdk/client-sqs";
3
+ import {
4
+ IZendeskAlertMessage,
5
+ ZendeskAlertKind,
6
+ ZendeskInternalAlertRequest
7
+ } from "@fiado/type-kit/bin/helpdesk/index.js";
8
+ import { SendProactiveMessageRequest } from "@fiado/type-kit/bin/zendeskMessaging/index.js";
9
+ import { IZendeskAlertsPublisher } from "./interfaces/IZendeskAlertsPublisher.js";
10
+
11
+ @injectable()
12
+ export default class ZendeskAlertsPublisher implements IZendeskAlertsPublisher {
13
+
14
+ private readonly ZENDESK_ALERTS_QUEUE = process.env.ZENDESK_ALERTS_QUEUE;
15
+
16
+ async createInternalNote(alert: ZendeskInternalAlertRequest): Promise<void> {
17
+ await this.publish({ kind: ZendeskAlertKind.INTERNAL_NOTE, payload: alert });
18
+ }
19
+
20
+ async sendProactiveMessage(message: SendProactiveMessageRequest): Promise<void> {
21
+ await this.publish({ kind: ZendeskAlertKind.PROACTIVE_MESSAGE, payload: message });
22
+ }
23
+
24
+ private async publish(message: IZendeskAlertMessage): Promise<void> {
25
+ try {
26
+ const client: SQSClient = new SQSClient();
27
+ const sendMessageRequest: SendMessageRequest = {
28
+ QueueUrl: this.ZENDESK_ALERTS_QUEUE,
29
+ MessageBody: JSON.stringify(message)
30
+ };
31
+ const command: SendMessageCommand = new SendMessageCommand(sendMessageRequest);
32
+ await client.send(command);
33
+ } catch (error) {
34
+ const errorMessage = error instanceof Error ? error.message : String(error);
35
+ throw new Error(`Error publishing message to queue ${': ' + errorMessage}`);
36
+ }
37
+ }
38
+ }
@@ -0,0 +1,17 @@
1
+ import { ZendeskInternalAlertRequest } from "@fiado/type-kit/bin/helpdesk/index.js";
2
+ import { SendProactiveMessageRequest } from "@fiado/type-kit/bin/zendeskMessaging/index.js";
3
+
4
+ /**
5
+ * Publica alertas hacia Zendesk sin pagar su latencia: el caller encola y sigue.
6
+ * Consume zendesk-business.
7
+ */
8
+ export interface IZendeskAlertsPublisher {
9
+ /** Nota interna sobre un usuario. Solo la ven los agentes. */
10
+ createInternalNote(alert: ZendeskInternalAlertRequest): Promise<void>;
11
+
12
+ /**
13
+ * Mensaje al chat del usuario. Si el usuario está esperando la respuesta ahora, conviene
14
+ * el endpoint síncrono `IZendeskApi.sendProactiveMessage`: acá el fallo no es inmediato.
15
+ */
16
+ sendProactiveMessage(message: SendProactiveMessageRequest): Promise<void>;
17
+ }