@fiado/api-invoker 4.20.0 → 4.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,10 @@
1
- import { IHttpRequest } from "@fiado/http-client";
2
- import { MilestonesByEventKeyDateRangeParams } from "@fiado/type-kit/bin/milestone-business/index.js";
1
+ import type { IHttpRequest } from "@fiado/http-client";
2
+ import { Milestone, MilestonesByEventKeyDateRangeParams } from "@fiado/type-kit/bin/milestone-business/index.js";
3
3
  import { IMilestoneBusinessApi } from "./interfaces/IMilestoneBusinessApi.js";
4
4
  export default class MilestoneBusinessApi implements IMilestoneBusinessApi {
5
5
  private httpRequest;
6
6
  private readonly baseUrl;
7
7
  constructor(httpRequest: IHttpRequest);
8
8
  listByEventKeyAndDateRange(eventKey: string, params: MilestonesByEventKeyDateRangeParams): Promise<any>;
9
+ listByDirectoryIds(directoryIds: string[]): Promise<Record<string, Milestone[]>>;
9
10
  }
@@ -11,6 +11,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
11
  return function (target, key) { decorator(target, key, paramIndex); }
12
12
  };
13
13
  import { inject, injectable } from "inversify";
14
+ import { MILESTONES_BY_DIRECTORY_IDS_MAX_BATCH, } from "@fiado/type-kit/bin/milestone-business/index.js";
14
15
  let MilestoneBusinessApi = class MilestoneBusinessApi {
15
16
  httpRequest;
16
17
  baseUrl = process.env.MILESTONE_BUSINESS_LAMBDA_URL || "";
@@ -31,6 +32,21 @@ let MilestoneBusinessApi = class MilestoneBusinessApi {
31
32
  const url = `${this.baseUrl}private/milestones/by-event-key?${queryParams.toString()}`;
32
33
  return await this.httpRequest.get(url);
33
34
  }
35
+ async listByDirectoryIds(directoryIds) {
36
+ // Dedup preservando el orden de aparición.
37
+ const uniqueIds = Array.from(new Set(directoryIds));
38
+ if (uniqueIds.length === 0)
39
+ return {};
40
+ const url = `${this.baseUrl}private/milestones/by-directory-ids`;
41
+ const merged = {};
42
+ // Chunking en lotes de MILESTONES_BY_DIRECTORY_IDS_MAX_BATCH (cap del endpoint batch).
43
+ for (let i = 0; i < uniqueIds.length; i += MILESTONES_BY_DIRECTORY_IDS_MAX_BATCH) {
44
+ const batch = uniqueIds.slice(i, i + MILESTONES_BY_DIRECTORY_IDS_MAX_BATCH);
45
+ const partial = await this.httpRequest.post(url, { directoryIds: batch });
46
+ Object.assign(merged, partial);
47
+ }
48
+ return merged;
49
+ }
34
50
  };
35
51
  MilestoneBusinessApi = __decorate([
36
52
  injectable(),
@@ -1,8 +1,15 @@
1
- import { MilestonesByEventKeyDateRangeParams } from "@fiado/type-kit/bin/milestone-business/index.js";
1
+ import { Milestone, MilestonesByEventKeyDateRangeParams } from "@fiado/type-kit/bin/milestone-business/index.js";
2
2
  export interface IMilestoneBusinessApi {
3
3
  /**
4
4
  * Lista milestones por eventKey filtrados por rango de eventDate.
5
5
  * Usado por el flujo de cálculo de comisiones (eventKey=HomeAzul para USA, HomeRosa para MEX).
6
6
  */
7
7
  listByEventKeyAndDateRange(eventKey: string, params: MilestonesByEventKeyDateRangeParams): Promise<any>;
8
+ /**
9
+ * Devuelve, por cada directoryId, el array COMPLETO de milestones (mapa
10
+ * directoryId -> Milestone[]). Hace POST a `private/milestones/by-directory-ids`.
11
+ * Parte la lista en lotes de 100 (cap del endpoint batch), deduplica los ids
12
+ * y mergea los mapas parciales. Una sola llamada por lote (evita N+1).
13
+ */
14
+ listByDirectoryIds(directoryIds: string[]): Promise<Record<string, Milestone[]>>;
8
15
  }
@@ -0,0 +1,11 @@
1
+ import { IHttpRequest } from "@fiado/http-client";
2
+ import { ConnectorSendMessageRequest, ConnectorSendMessageResponse } from "@fiado/type-kit/bin/twilioConnector/index.js";
3
+ import { ITwilioConnectorApi } from "./interfaces/ITwilioConnectorApi.js";
4
+ type FiadoApiResponse<T> = import("@fiado/type-kit/bin/apiResponse/dtos/FiadoApiResponse.js").default<T>;
5
+ export default class TwilioConnectorApi implements ITwilioConnectorApi {
6
+ private httpRequest;
7
+ private readonly baseUrl;
8
+ constructor(httpRequest: IHttpRequest);
9
+ send(request: ConnectorSendMessageRequest): Promise<FiadoApiResponse<ConnectorSendMessageResponse>>;
10
+ }
11
+ export {};
@@ -0,0 +1,30 @@
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
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { inject, injectable } from "inversify";
14
+ let TwilioConnectorApi = class TwilioConnectorApi {
15
+ httpRequest;
16
+ baseUrl = process.env.TWILIO_CONNECTOR_LAMBDA_URL || "";
17
+ constructor(httpRequest) {
18
+ this.httpRequest = httpRequest;
19
+ }
20
+ async send(request) {
21
+ const url = `${this.baseUrl}/messages/send`;
22
+ return await this.httpRequest.post(url, request, { operationName: "privateSendMessage" });
23
+ }
24
+ };
25
+ TwilioConnectorApi = __decorate([
26
+ injectable(),
27
+ __param(0, inject("IHttpRequest")),
28
+ __metadata("design:paramtypes", [Object])
29
+ ], TwilioConnectorApi);
30
+ export default TwilioConnectorApi;
@@ -0,0 +1,11 @@
1
+ import { ConnectorSendMessageRequest, ConnectorSendMessageResponse } from "@fiado/type-kit/bin/twilioConnector/index.js";
2
+ type FiadoApiResponse<T> = import("@fiado/type-kit/bin/apiResponse/dtos/FiadoApiResponse.js").default<T>;
3
+ export interface ITwilioConnectorApi {
4
+ /**
5
+ * Envia un mensaje ya resuelto al twilio-connector (POST /messages/send).
6
+ * messages-business resuelve plantilla, remitente y `secretRef` desde el
7
+ * `senderConfig` del `(tenant, channel)`; el connector solo transmite a Twilio.
8
+ */
9
+ send(request: ConnectorSendMessageRequest): Promise<FiadoApiResponse<ConnectorSendMessageResponse>>;
10
+ }
11
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from "./api/interfaces/ITwilioConnectorApi.js";
2
+ export { default as TwilioConnectorApi } from "./api/TwilioConnectorApi.js";
@@ -0,0 +1,2 @@
1
+ export * from "./api/interfaces/ITwilioConnectorApi.js";
2
+ export { default as TwilioConnectorApi } from "./api/TwilioConnectorApi.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fiado/api-invoker",
3
- "version": "4.20.0",
3
+ "version": "4.20.1",
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",
@@ -1,6 +1,11 @@
1
1
  import { inject, injectable } from "inversify";
2
- import { IHttpRequest } from "@fiado/http-client";
3
- import { MilestonesByEventKeyDateRangeParams } from "@fiado/type-kit/bin/milestone-business/index.js";
2
+ import type { IHttpRequest } from "@fiado/http-client";
3
+ import {
4
+ Milestone,
5
+ MilestonesByEventKeyDateRangeParams,
6
+ MilestonesByDirectoryIdsResponse,
7
+ MILESTONES_BY_DIRECTORY_IDS_MAX_BATCH,
8
+ } from "@fiado/type-kit/bin/milestone-business/index.js";
4
9
  import { IMilestoneBusinessApi } from "./interfaces/IMilestoneBusinessApi.js";
5
10
 
6
11
  @injectable()
@@ -23,4 +28,22 @@ export default class MilestoneBusinessApi implements IMilestoneBusinessApi {
23
28
  const url = `${this.baseUrl}private/milestones/by-event-key?${queryParams.toString()}`;
24
29
  return await this.httpRequest.get(url);
25
30
  }
31
+
32
+ async listByDirectoryIds(directoryIds: string[]): Promise<Record<string, Milestone[]>> {
33
+ // Dedup preservando el orden de aparición.
34
+ const uniqueIds = Array.from(new Set(directoryIds));
35
+ if (uniqueIds.length === 0) return {};
36
+
37
+ const url = `${this.baseUrl}private/milestones/by-directory-ids`;
38
+ const merged: Record<string, Milestone[]> = {};
39
+
40
+ // Chunking en lotes de MILESTONES_BY_DIRECTORY_IDS_MAX_BATCH (cap del endpoint batch).
41
+ for (let i = 0; i < uniqueIds.length; i += MILESTONES_BY_DIRECTORY_IDS_MAX_BATCH) {
42
+ const batch = uniqueIds.slice(i, i + MILESTONES_BY_DIRECTORY_IDS_MAX_BATCH);
43
+ const partial = await this.httpRequest.post<MilestonesByDirectoryIdsResponse>(url, { directoryIds: batch });
44
+ Object.assign(merged, partial);
45
+ }
46
+
47
+ return merged;
48
+ }
26
49
  }
@@ -1,4 +1,4 @@
1
- import { MilestonesByEventKeyDateRangeParams } from "@fiado/type-kit/bin/milestone-business/index.js";
1
+ import { Milestone, MilestonesByEventKeyDateRangeParams } from "@fiado/type-kit/bin/milestone-business/index.js";
2
2
 
3
3
  export interface IMilestoneBusinessApi {
4
4
  /**
@@ -6,4 +6,12 @@ export interface IMilestoneBusinessApi {
6
6
  * Usado por el flujo de cálculo de comisiones (eventKey=HomeAzul para USA, HomeRosa para MEX).
7
7
  */
8
8
  listByEventKeyAndDateRange(eventKey: string, params: MilestonesByEventKeyDateRangeParams): Promise<any>;
9
+
10
+ /**
11
+ * Devuelve, por cada directoryId, el array COMPLETO de milestones (mapa
12
+ * directoryId -> Milestone[]). Hace POST a `private/milestones/by-directory-ids`.
13
+ * Parte la lista en lotes de 100 (cap del endpoint batch), deduplica los ids
14
+ * y mergea los mapas parciales. Una sola llamada por lote (evita N+1).
15
+ */
16
+ listByDirectoryIds(directoryIds: string[]): Promise<Record<string, Milestone[]>>;
9
17
  }
@@ -0,0 +1,18 @@
1
+ import { inject, injectable } from "inversify";
2
+ import { IHttpRequest } from "@fiado/http-client";
3
+ import { ConnectorSendMessageRequest, ConnectorSendMessageResponse } from "@fiado/type-kit/bin/twilioConnector/index.js";
4
+ import { ITwilioConnectorApi } from "./interfaces/ITwilioConnectorApi.js";
5
+
6
+ type FiadoApiResponse<T> = import("@fiado/type-kit/bin/apiResponse/dtos/FiadoApiResponse.js").default<T>;
7
+
8
+ @injectable()
9
+ export default class TwilioConnectorApi implements ITwilioConnectorApi {
10
+ private readonly baseUrl = process.env.TWILIO_CONNECTOR_LAMBDA_URL || "";
11
+
12
+ constructor(@inject("IHttpRequest") private httpRequest: IHttpRequest) {}
13
+
14
+ async send(request: ConnectorSendMessageRequest): Promise<FiadoApiResponse<ConnectorSendMessageResponse>> {
15
+ const url = `${this.baseUrl}/messages/send`;
16
+ return await this.httpRequest.post(url, request, { operationName: "privateSendMessage" });
17
+ }
18
+ }
@@ -0,0 +1,12 @@
1
+ import { ConnectorSendMessageRequest, ConnectorSendMessageResponse } from "@fiado/type-kit/bin/twilioConnector/index.js";
2
+
3
+ type FiadoApiResponse<T> = import("@fiado/type-kit/bin/apiResponse/dtos/FiadoApiResponse.js").default<T>;
4
+
5
+ export interface ITwilioConnectorApi {
6
+ /**
7
+ * Envia un mensaje ya resuelto al twilio-connector (POST /messages/send).
8
+ * messages-business resuelve plantilla, remitente y `secretRef` desde el
9
+ * `senderConfig` del `(tenant, channel)`; el connector solo transmite a Twilio.
10
+ */
11
+ send(request: ConnectorSendMessageRequest): Promise<FiadoApiResponse<ConnectorSendMessageResponse>>;
12
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./api/interfaces/ITwilioConnectorApi.js";
2
+ export { default as TwilioConnectorApi } from "./api/TwilioConnectorApi.js";