@fiado/api-invoker 5.2.0 → 5.4.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.
@@ -1,6 +1,5 @@
1
- import { KycVerificationChangedV1 } from "@fiado/type-kit/bin/kyc/index.js";
2
- import { IRetailKycInboundPublisher } from "./interfaces/IRetailKycInboundPublisher.js";
1
+ import { IRetailKycInboundPublisher, RetailKycInboundMessage } from "./interfaces/IRetailKycInboundPublisher.js";
3
2
  export declare class RetailKycInboundPublisher implements IRetailKycInboundPublisher {
4
3
  private readonly RETAIL_KYC_INBOUND_QUEUE_URL;
5
- publish(message: KycVerificationChangedV1): Promise<void>;
4
+ publish(message: RetailKycInboundMessage): Promise<void>;
6
5
  }
@@ -11,8 +11,11 @@ let RetailKycInboundPublisher = class RetailKycInboundPublisher {
11
11
  async publish(message) {
12
12
  try {
13
13
  const client = new SQSClient();
14
- // Cola ESTÁNDAR (no FIFO): sin MessageGroupId/MessageDeduplicationId. La deduplicación
15
- // la hace el consumidor con la llave de negocio (directoryId + verificationId + status + result).
14
+ // Cola ESTÁNDAR (no FIFO): sin MessageGroupId/MessageDeduplicationId, y por lo tanto SIN
15
+ // orden garantizado. La deduplicación la hace el consumidor con la llave de negocio: el
16
+ // cierre por (directoryId + verificationId + status + result), la estación por
17
+ // (verificationId + step) — su escritura ya es idempotente. El reordenamiento lo resuelve
18
+ // el `occurredAt` de cada estación, no la cola.
16
19
  const sendMessageRequest = {
17
20
  QueueUrl: this.RETAIL_KYC_INBOUND_QUEUE_URL,
18
21
  MessageBody: JSON.stringify(message),
@@ -1,12 +1,22 @@
1
- import { KycVerificationChangedV1 } from "@fiado/type-kit/bin/kyc/index.js";
1
+ import { KycVerificationChangedV1, KycStepCompletedV1 } from "@fiado/type-kit/bin/kyc/index.js";
2
2
  /**
3
- * Publisher del resultado del KYC hacia `RetailKycInboundQueue`, que consume
4
- * `retail-wizard-business` (SureKeep F2).
3
+ * Todo lo que `RetailKycInboundQueue` transporta:
4
+ * - `KycVerificationChangedV1` — el CIERRE de la verificación, con el resultado consolidado.
5
+ * - `KycStepCompletedV1` — el resultado de UNA estación, en cuanto Metamap la cierra.
5
6
  *
6
- * Lo produce `kyc-metamap-webhook` cuando una verificación pasa a COMPLETED. Vive acá —y no como
7
- * SDK crudo en el webhook— porque la cola es COMPARTIDA cross-lambda: el estándar Fiado publica a una
8
- * cola compartida vía Publisher de `@fiado/api-invoker` (mismo patrón que `ITransactionPublisher`).
7
+ * Es una unión cerrada y no un `unknown` a propósito: el consumidor rutea por `eventType`, así que
8
+ * agregar un tipo acá obliga a tocar también el consumidor — que es exactamente la conversación que
9
+ * tiene que pasar antes de meter un mensaje nuevo en una cola compartida.
10
+ */
11
+ export type RetailKycInboundMessage = KycVerificationChangedV1 | KycStepCompletedV1;
12
+ /**
13
+ * Publisher del KYC hacia `RetailKycInboundQueue`, que consume `retail-wizard-business` (SureKeep F2).
14
+ *
15
+ * Lo produce `kyc-metamap-webhook`: el cierre cuando la verificación pasa a COMPLETED, y una estación
16
+ * por cada `step_completed`. Vive acá —y no como SDK crudo en el webhook— porque la cola es COMPARTIDA
17
+ * cross-lambda: el estándar Fiado publica a una cola compartida vía Publisher de `@fiado/api-invoker`
18
+ * (mismo patrón que `ITransactionPublisher`).
9
19
  */
10
20
  export interface IRetailKycInboundPublisher {
11
- publish(message: KycVerificationChangedV1): Promise<void>;
21
+ publish(message: RetailKycInboundMessage): Promise<void>;
12
22
  }
@@ -22,6 +22,7 @@ export default class LoanCreditBusinessApi implements ILoanCreditBusinessApi {
22
22
  quote(creditId: string, input: QuoteLoanCreditRequest, tenantId: string): Promise<StandardResponse<QuoteLoanCreditResponse>>;
23
23
  sign(creditId: string, input: SignLoanCreditRequest, tenantId: string): Promise<StandardResponse<SignLoanCreditResponse>>;
24
24
  activateCheck(creditId: string, input: ActivationCheckRequest, tenantId: string): Promise<StandardResponse<ActivationCheckResponse>>;
25
+ discard(creditId: string, tenantId: string): Promise<StandardResponse<LoanCreditResponse>>;
25
26
  getCredit(creditId: string, tenantId: string): Promise<StandardResponse<LoanCreditResponse>>;
26
27
  getBorrowerByRetailCustomer(retailCustomerId: string, tenantId: string): Promise<StandardResponse<LoanBorrowerResponse>>;
27
28
  upsertBorrower(input: UpsertLoanBorrowerRequest, tenantId: string): Promise<StandardResponse<LoanBorrowerResponse>>;
@@ -46,6 +46,10 @@ let LoanCreditBusinessApi = class LoanCreditBusinessApi {
46
46
  const url = `${this.baseUrl}/private/credits/${encodeURIComponent(creditId)}/activate-check?tenantId=${encodeURIComponent(tenantId)}`;
47
47
  return await this.httpRequest.post(url, input);
48
48
  }
49
+ async discard(creditId, tenantId) {
50
+ const url = `${this.baseUrl}/private/credits/${encodeURIComponent(creditId)}/discard?tenantId=${encodeURIComponent(tenantId)}`;
51
+ return await this.httpRequest.post(url, {});
52
+ }
49
53
  async getCredit(creditId, tenantId) {
50
54
  const url = `${this.baseUrl}/private/credits/${encodeURIComponent(creditId)}?tenantId=${encodeURIComponent(tenantId)}`;
51
55
  return await this.httpRequest.get(url);
@@ -42,6 +42,13 @@ export interface ILoanCreditBusinessApi {
42
42
  * el crédito pasa a `ACTIVE` (vencimientos +7d, ventana de cancelación 7d).
43
43
  */
44
44
  activateCheck(creditId: string, input: ActivationCheckRequest, tenantId: string): Promise<StandardResponse<ActivationCheckResponse>>;
45
+ /**
46
+ * Descarta un crédito PENDING_ACTIVATION → DISCARDED (compensación del wizard al cancelar la
47
+ * venta — sin esto el crédito huérfano bloquea al cliente vía un-crédito-vivo). Idempotente.
48
+ * `400 CREDIT_NOT_PENDING` si el crédito ya avanzó (ACTIVE/IN_ARREARS jamás se descartan) ·
49
+ * `404 CREDIT_NOT_FOUND`.
50
+ */
51
+ discard(creditId: string, tenantId: string): Promise<StandardResponse<LoanCreditResponse>>;
45
52
  /** Estado completo del crédito (checklist, status, términos). */
46
53
  getCredit(creditId: string, tenantId: string): Promise<StandardResponse<LoanCreditResponse>>;
47
54
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fiado/api-invoker",
3
- "version": "5.2.0",
3
+ "version": "5.4.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.212.0",
37
+ "@fiado/type-kit": "^3.221.0",
38
38
  "dotenv": "^16.4.7"
39
39
  },
40
40
  "peerDependencies": {
@@ -1,17 +1,19 @@
1
1
  import { SendMessageCommand, SendMessageRequest, SQSClient } from "@aws-sdk/client-sqs";
2
2
  import { injectable } from "inversify";
3
- import { KycVerificationChangedV1 } from "@fiado/type-kit/bin/kyc/index.js";
4
- import { IRetailKycInboundPublisher } from "./interfaces/IRetailKycInboundPublisher.js";
3
+ import { IRetailKycInboundPublisher, RetailKycInboundMessage } from "./interfaces/IRetailKycInboundPublisher.js";
5
4
 
6
5
  @injectable()
7
6
  export class RetailKycInboundPublisher implements IRetailKycInboundPublisher {
8
7
  private readonly RETAIL_KYC_INBOUND_QUEUE_URL = process.env.RETAIL_KYC_INBOUND_QUEUE_URL;
9
8
 
10
- async publish(message: KycVerificationChangedV1): Promise<void> {
9
+ async publish(message: RetailKycInboundMessage): Promise<void> {
11
10
  try {
12
11
  const client: SQSClient = new SQSClient();
13
- // Cola ESTÁNDAR (no FIFO): sin MessageGroupId/MessageDeduplicationId. La deduplicación
14
- // la hace el consumidor con la llave de negocio (directoryId + verificationId + status + result).
12
+ // Cola ESTÁNDAR (no FIFO): sin MessageGroupId/MessageDeduplicationId, y por lo tanto SIN
13
+ // orden garantizado. La deduplicación la hace el consumidor con la llave de negocio: el
14
+ // cierre por (directoryId + verificationId + status + result), la estación por
15
+ // (verificationId + step) — su escritura ya es idempotente. El reordenamiento lo resuelve
16
+ // el `occurredAt` de cada estación, no la cola.
15
17
  const sendMessageRequest: SendMessageRequest = {
16
18
  QueueUrl: this.RETAIL_KYC_INBOUND_QUEUE_URL,
17
19
  MessageBody: JSON.stringify(message),
@@ -1,13 +1,24 @@
1
- import { KycVerificationChangedV1 } from "@fiado/type-kit/bin/kyc/index.js";
1
+ import { KycVerificationChangedV1, KycStepCompletedV1 } from "@fiado/type-kit/bin/kyc/index.js";
2
2
 
3
3
  /**
4
- * Publisher del resultado del KYC hacia `RetailKycInboundQueue`, que consume
5
- * `retail-wizard-business` (SureKeep F2).
4
+ * Todo lo que `RetailKycInboundQueue` transporta:
5
+ * - `KycVerificationChangedV1` — el CIERRE de la verificación, con el resultado consolidado.
6
+ * - `KycStepCompletedV1` — el resultado de UNA estación, en cuanto Metamap la cierra.
6
7
  *
7
- * Lo produce `kyc-metamap-webhook` cuando una verificación pasa a COMPLETED. Vive acá —y no como
8
- * SDK crudo en el webhook— porque la cola es COMPARTIDA cross-lambda: el estándar Fiado publica a una
9
- * cola compartida vía Publisher de `@fiado/api-invoker` (mismo patrón que `ITransactionPublisher`).
8
+ * Es una unión cerrada y no un `unknown` a propósito: el consumidor rutea por `eventType`, así que
9
+ * agregar un tipo acá obliga a tocar también el consumidor — que es exactamente la conversación que
10
+ * tiene que pasar antes de meter un mensaje nuevo en una cola compartida.
11
+ */
12
+ export type RetailKycInboundMessage = KycVerificationChangedV1 | KycStepCompletedV1;
13
+
14
+ /**
15
+ * Publisher del KYC hacia `RetailKycInboundQueue`, que consume `retail-wizard-business` (SureKeep F2).
16
+ *
17
+ * Lo produce `kyc-metamap-webhook`: el cierre cuando la verificación pasa a COMPLETED, y una estación
18
+ * por cada `step_completed`. Vive acá —y no como SDK crudo en el webhook— porque la cola es COMPARTIDA
19
+ * cross-lambda: el estándar Fiado publica a una cola compartida vía Publisher de `@fiado/api-invoker`
20
+ * (mismo patrón que `ITransactionPublisher`).
10
21
  */
11
22
  export interface IRetailKycInboundPublisher {
12
- publish(message: KycVerificationChangedV1): Promise<void>;
23
+ publish(message: RetailKycInboundMessage): Promise<void>;
13
24
  }
@@ -70,6 +70,14 @@ export default class LoanCreditBusinessApi implements ILoanCreditBusinessApi {
70
70
  return await this.httpRequest.post(url, input);
71
71
  }
72
72
 
73
+ async discard(
74
+ creditId: string,
75
+ tenantId: string,
76
+ ): Promise<StandardResponse<LoanCreditResponse>> {
77
+ const url = `${this.baseUrl}/private/credits/${encodeURIComponent(creditId)}/discard?tenantId=${encodeURIComponent(tenantId)}`;
78
+ return await this.httpRequest.post(url, {});
79
+ }
80
+
73
81
  async getCredit(
74
82
  creditId: string,
75
83
  tenantId: string,
@@ -74,6 +74,17 @@ export interface ILoanCreditBusinessApi {
74
74
  tenantId: string,
75
75
  ): Promise<StandardResponse<ActivationCheckResponse>>;
76
76
 
77
+ /**
78
+ * Descarta un crédito PENDING_ACTIVATION → DISCARDED (compensación del wizard al cancelar la
79
+ * venta — sin esto el crédito huérfano bloquea al cliente vía un-crédito-vivo). Idempotente.
80
+ * `400 CREDIT_NOT_PENDING` si el crédito ya avanzó (ACTIVE/IN_ARREARS jamás se descartan) ·
81
+ * `404 CREDIT_NOT_FOUND`.
82
+ */
83
+ discard(
84
+ creditId: string,
85
+ tenantId: string,
86
+ ): Promise<StandardResponse<LoanCreditResponse>>;
87
+
77
88
  /** Estado completo del crédito (checklist, status, términos). */
78
89
  getCredit(
79
90
  creditId: string,