@fiado/api-invoker 5.44.0 → 5.46.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,7 +1,7 @@
1
1
  import { IAccountPagoConfiadoApi } from "./interfaces/IAccountPagoConfiadoApi.js";
2
- import { AccountCreateRequest, AccountCreateResponse, AccountUpdateBalanceRequest, AccountUpdateRequest, GetAccountResponse, GetAccountResponseList } from "@fiado/type-kit/bin/account/index.js";
2
+ import { AccountCreateRequest, AccountCreateResponse, AccountUpdateBalanceRequest, AccountUpdateRequest, CollectDebitRequest, CollectDebitResponse, GetAccountResponse, GetAccountResponseList } from "@fiado/type-kit/bin/account/index.js";
3
3
  import { ApiGatewayResponse } from "@fiado/gateway-adapter";
4
- import { IHttpRequest } from "@fiado/http-client";
4
+ import type { IHttpRequest } from "@fiado/http-client";
5
5
  import { Provider } from "@fiado/type-kit/bin/provider/index.js";
6
6
  export default class AccountPagoConfiadoApi implements IAccountPagoConfiadoApi {
7
7
  private httpRequest;
@@ -11,6 +11,7 @@ export default class AccountPagoConfiadoApi implements IAccountPagoConfiadoApi {
11
11
  createAccount(provider: Provider, data: AccountCreateRequest): Promise<ApiGatewayResponse<AccountCreateResponse>>;
12
12
  getAccountByDirectoryId(directoryId: string): Promise<ApiGatewayResponse<GetAccountResponse[]>>;
13
13
  updateAccountBalance(accountId: string, params: AccountUpdateBalanceRequest): Promise<ApiGatewayResponse<Boolean>>;
14
+ collectDebit(accountId: string, request: CollectDebitRequest): Promise<ApiGatewayResponse<CollectDebitResponse>>;
14
15
  update(directoryId: string, data: AccountUpdateRequest): Promise<ApiGatewayResponse<void>>;
15
16
  updateByAccountNumber(accountNumber: string, data: AccountUpdateRequest): Promise<ApiGatewayResponse<void>>;
16
17
  getAccountByAccountNumber(accountNumber: string): Promise<ApiGatewayResponse<void>>;
@@ -33,6 +33,10 @@ let AccountPagoConfiadoApi = class AccountPagoConfiadoApi {
33
33
  const url = `${this.baseUrl}${accountId}/balance`;
34
34
  return await this.httpRequest.put(url, params);
35
35
  }
36
+ async collectDebit(accountId, request) {
37
+ const url = `${this.baseUrl}accounts/${accountId}/collect-debit`;
38
+ return await this.httpRequest.post(url, request);
39
+ }
36
40
  async update(directoryId, data) {
37
41
  const url = `${this.baseUrl}users/${directoryId}`;
38
42
  return await this.httpRequest.put(url, data);
@@ -1,10 +1,22 @@
1
- import { AccountCreateRequest, AccountCreateResponse, AccountUpdateBalanceRequest, AccountUpdateRequest, GetAccountResponse, GetAccountResponseList } from "@fiado/type-kit/bin/account/index.js";
1
+ import { AccountCreateRequest, AccountCreateResponse, AccountUpdateBalanceRequest, AccountUpdateRequest, CollectDebitRequest, CollectDebitResponse, GetAccountResponse, GetAccountResponseList } from "@fiado/type-kit/bin/account/index.js";
2
2
  import { ApiGatewayResponse } from "@fiado/gateway-adapter";
3
3
  import { Provider } from "@fiado/type-kit/bin/provider/index.js";
4
4
  export interface IAccountPagoConfiadoApi {
5
5
  createAccount(provider: Provider, data: AccountCreateRequest): Promise<ApiGatewayResponse<AccountCreateResponse>>;
6
6
  getAccountByDirectoryId(directoryId: string, provider: string): Promise<ApiGatewayResponse<GetAccountResponse[]>>;
7
7
  updateAccountBalance(accountId: string, params: AccountUpdateBalanceRequest): Promise<ApiGatewayResponse<Boolean>>;
8
+ /**
9
+ * Debita el saldo disponible de la cuenta para cobrar una deuda, en una sola operación que lleva
10
+ * la condición de fondos consigo: entre comprobar el saldo y descontarlo no cabe otra escritura,
11
+ * de modo que dos cobros simultáneos no pueden sobregirar la cuenta.
12
+ *
13
+ * Idempotente por `executionId`: reintentar el mismo intento de cobro devuelve el resultado del
14
+ * primero en vez de volver a debitar. Saldo insuficiente NO es un error — responde 200 con
15
+ * `result: NONE`, y quien cobra decide si buscar el dinero en otra fuente.
16
+ *
17
+ * Backend: POST /accounts/{accountId}/collect-debit (privado VPC).
18
+ */
19
+ collectDebit(accountId: string, request: CollectDebitRequest): Promise<ApiGatewayResponse<CollectDebitResponse>>;
8
20
  update(directoryId: string, data: AccountUpdateRequest): Promise<ApiGatewayResponse<void>>;
9
21
  updateByAccountNumber(accountNumber: string, data: AccountUpdateRequest): Promise<ApiGatewayResponse<void>>;
10
22
  getAccountByAccountNumber(accountNumber: string): Promise<ApiGatewayResponse<void>>;
@@ -1,5 +1,5 @@
1
1
  import type { IHttpRequest } from "@fiado/http-client";
2
- import { CollectRequest, CollectResponse, RegisterCollectibleRequest } from "@fiado/type-kit/bin/collection/index.js";
2
+ import { CollectRequest, CollectResponse, DeregisterChargeResponse } from "@fiado/type-kit/bin/collection/index.js";
3
3
  import { ICollectionEngineApi } from "./interfaces/ICollectionEngineApi.js";
4
4
  type FiadoApiResponse<T> = import("@fiado/type-kit/bin/apiResponse/dtos/FiadoApiResponse.js").default<T>;
5
5
  /**
@@ -11,7 +11,6 @@ export default class CollectionEngineApi implements ICollectionEngineApi {
11
11
  private readonly baseUrl;
12
12
  constructor(httpRequest: IHttpRequest);
13
13
  collect(request: CollectRequest): Promise<FiadoApiResponse<CollectResponse>>;
14
- registerCollectible(request: RegisterCollectibleRequest): Promise<FiadoApiResponse<boolean>>;
15
- deregister(ownerRef: string, productId: string, chargeId: string): Promise<FiadoApiResponse<boolean>>;
14
+ deregister(domain: string, chargeId: string): Promise<FiadoApiResponse<DeregisterChargeResponse>>;
16
15
  }
17
16
  export {};
@@ -25,13 +25,13 @@ let CollectionEngineApi = class CollectionEngineApi {
25
25
  const url = `${this.baseUrl}collection/collect`;
26
26
  return await this.httpRequest.post(url, request);
27
27
  }
28
- async registerCollectible(request) {
29
- const url = `${this.baseUrl}collection/register`;
30
- return await this.httpRequest.post(url, request);
31
- }
32
- async deregister(ownerRef, productId, chargeId) {
33
- const url = `${this.baseUrl}collection/deregister`;
34
- return await this.httpRequest.post(url, { ownerRef, productId, chargeId });
28
+ async deregister(domain, chargeId) {
29
+ // `chargeId` lleva separadores `#` en todos los dominios (`SALE#42#INSTALLMENT#3`): sin
30
+ // escapar, el navegador o el cliente HTTP lo tratan como fragmento y el motor recibe la
31
+ // parte anterior al primer `#`, o sea otro cargo.
32
+ const url = `${this.baseUrl}collection/domains/${encodeURIComponent(domain)}`
33
+ + `/charges/${encodeURIComponent(chargeId)}/deregister`;
34
+ return await this.httpRequest.post(url, {});
35
35
  }
36
36
  };
37
37
  CollectionEngineApi = __decorate([
@@ -1,30 +1,40 @@
1
- import { CollectRequest, CollectResponse, RegisterCollectibleRequest } from "@fiado/type-kit/bin/collection/index.js";
1
+ import { CollectRequest, CollectResponse, DeregisterChargeResponse } from "@fiado/type-kit/bin/collection/index.js";
2
2
  type FiadoApiResponse<T> = import("@fiado/type-kit/bin/apiResponse/dtos/FiadoApiResponse.js").default<T>;
3
3
  /**
4
4
  * Cliente para invocar los endpoints privados del lambda `collection-engine-business`.
5
5
  *
6
6
  * Los endpoints viven bajo `COLLECTION_ENGINE_LAMBDA_URL` (API Gateway privado / VPC).
7
- * El motor es agnóstico de proveedores/cuentas — los dominios (une-credit,
8
- * surekeep-retail, etc.) sólo hablan el contrato genérico de `PendingCharge`.
7
+ * El motor es agnóstico de proveedores y cuentas: el dominio dice QUÉ se debe y el motor
8
+ * decide de dónde cobrarlo según la config del producto.
9
+ *
10
+ * El alta explícita de un cargo cobrable (`registerCollectible`) todavía no existe en el
11
+ * motor: hoy `collect` crea el intent si no lo había, derivando su identidad de
12
+ * `domain#chargeId`. El método se reincorporará cuando el motor exponga la ruta.
9
13
  */
10
14
  export interface ICollectionEngineApi {
11
15
  /**
12
- * Cobro on-demand síncrono. El dominio pide al motor que intente cobrar
13
- * un cargo puntual (fuera del barrido normal de la cascada).
16
+ * Cobro on-demand síncrono. El dominio manda el cargo ya resuelto y el motor recorre la
17
+ * cascada de fuentes configurada para el producto. Idempotente por `domain#chargeId`:
18
+ * repetir la llamada sobre un cargo ya cobrado devuelve el resultado anterior sin volver
19
+ * a mover dinero.
20
+ *
14
21
  * Backend: POST /collection/collect (privado VPC).
15
22
  */
16
23
  collect(request: CollectRequest): Promise<FiadoApiResponse<CollectResponse>>;
17
24
  /**
18
- * Alta de un cargo cobrable en el índice del motor. Lo invoca el dominio
19
- * dueño cuando nace una deuda cobrable (installment, cuota, etc.).
20
- * Backend: POST /collection/register (privado VPC).
21
- */
22
- registerCollectible(request: RegisterCollectibleRequest): Promise<FiadoApiResponse<boolean>>;
23
- /**
24
- * Baja de un cargo del índice del motor (equivalente a cancelar el intent
25
- * en curso). Lo invoca el dominio dueño cuando el cargo deja de ser cobrable.
26
- * Backend: POST /collection/deregister (privado VPC).
25
+ * Baja de un cargo: detiene los reintentos de un cobro que el dominio castigó, condonó o
26
+ * reestructuró. Sin esto, un cargo sin fondos se reintenta indefinidamente.
27
+ *
28
+ * Identifica el cobro por `domain` y `chargeId`, que es la llave con la que el motor lo
29
+ * registró. Es idempotente: dar de baja un cargo ya terminal devuelve `ALREADY_TERMINAL`
30
+ * sin alterarlo.
31
+ *
32
+ * Un cargo desconocido responde 404, y el cliente HTTP lo propaga como excepción — no llega
33
+ * como envelope con `code`. El dominio debe atraparlo si un cargo ya inexistente es un caso
34
+ * esperado de su flujo.
35
+ *
36
+ * Backend: POST /collection/domains/{domain}/charges/{chargeId}/deregister (privado VPC).
27
37
  */
28
- deregister(ownerRef: string, productId: string, chargeId: string): Promise<FiadoApiResponse<boolean>>;
38
+ deregister(domain: string, chargeId: string): Promise<FiadoApiResponse<DeregisterChargeResponse>>;
29
39
  }
30
40
  export {};
@@ -280,7 +280,7 @@ export const apiInvokerBindings = new ContainerModule(({ bind }) => {
280
280
  // El productor necesita WEBHOOK_BUSINESS_QUEUE_URL y sqs:SendMessage sobre la cola.
281
281
  bind("IWebhookBusinessPublisher").to(WebhookBusinessPublisher);
282
282
  bind("ICentralPaymentsWebhookApi").to(CentralPaymentsWebhookApi);
283
- // Collection engine — motor de cobro central multitenant (collect/registerCollectible/deregister)
283
+ // Collection engine — motor de cobro central multitenant (collect/deregister)
284
284
  bind("ICollectionEngineApi").to(CollectionEngineApi);
285
285
  // Domain callback — el motor notifica al dominio dueño del cargo (applyCollectionResult)
286
286
  bind("IDomainCallbackApi").to(DomainCallbackApi);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fiado/api-invoker",
3
- "version": "5.44.0",
3
+ "version": "5.46.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.360.0",
37
+ "@fiado/type-kit": "^3.368.0",
38
38
  "dotenv": "^16.4.7"
39
39
  },
40
40
  "peerDependencies": {
@@ -1,8 +1,8 @@
1
1
  import {IAccountPagoConfiadoApi} from "./interfaces/IAccountPagoConfiadoApi.js";
2
- import {AccountCreateRequest, AccountCreateResponse, AccountUpdateBalanceRequest, AccountUpdateRequest, GetAccountResponse, GetAccountResponseList} from "@fiado/type-kit/bin/account/index.js";
2
+ import {AccountCreateRequest, AccountCreateResponse, AccountUpdateBalanceRequest, AccountUpdateRequest, CollectDebitRequest, CollectDebitResponse, GetAccountResponse, GetAccountResponseList} from "@fiado/type-kit/bin/account/index.js";
3
3
  import {ApiGatewayResponse} from "@fiado/gateway-adapter";
4
4
  import {inject, injectable} from "inversify";
5
- import {IHttpRequest} from "@fiado/http-client";
5
+ import type {IHttpRequest} from "@fiado/http-client";
6
6
  import { Provider } from "@fiado/type-kit/bin/provider/index.js";
7
7
 
8
8
  @injectable()
@@ -31,6 +31,11 @@ export default class AccountPagoConfiadoApi implements IAccountPagoConfiadoApi {
31
31
  return await this.httpRequest.put(url,params);
32
32
  }
33
33
 
34
+ async collectDebit(accountId: string, request: CollectDebitRequest): Promise<ApiGatewayResponse<CollectDebitResponse>> {
35
+ const url = `${this.baseUrl}accounts/${accountId}/collect-debit`;
36
+ return await this.httpRequest.post(url, request);
37
+ }
38
+
34
39
  async update(directoryId: string, data: AccountUpdateRequest): Promise<ApiGatewayResponse<void>> {
35
40
  const url = `${this.baseUrl}users/${directoryId}`;
36
41
  return await this.httpRequest.put(url, data);
@@ -1,11 +1,4 @@
1
- import {
2
- AccountCreateRequest,
3
- AccountCreateResponse,
4
- AccountUpdateBalanceRequest,
5
- AccountUpdateRequest,
6
- GetAccountResponse,
7
- GetAccountResponseList
8
- } from "@fiado/type-kit/bin/account/index.js";
1
+ import {AccountCreateRequest, AccountCreateResponse, AccountUpdateBalanceRequest, AccountUpdateRequest, CollectDebitRequest, CollectDebitResponse, GetAccountResponse, GetAccountResponseList} from "@fiado/type-kit/bin/account/index.js";
9
2
  import { ApiGatewayResponse } from "@fiado/gateway-adapter";
10
3
  import { Provider } from "@fiado/type-kit/bin/provider/index.js";
11
4
 
@@ -17,6 +10,19 @@ export interface IAccountPagoConfiadoApi {
17
10
 
18
11
  updateAccountBalance(accountId: string, params: AccountUpdateBalanceRequest): Promise<ApiGatewayResponse<Boolean>>;
19
12
 
13
+ /**
14
+ * Debita el saldo disponible de la cuenta para cobrar una deuda, en una sola operación que lleva
15
+ * la condición de fondos consigo: entre comprobar el saldo y descontarlo no cabe otra escritura,
16
+ * de modo que dos cobros simultáneos no pueden sobregirar la cuenta.
17
+ *
18
+ * Idempotente por `executionId`: reintentar el mismo intento de cobro devuelve el resultado del
19
+ * primero en vez de volver a debitar. Saldo insuficiente NO es un error — responde 200 con
20
+ * `result: NONE`, y quien cobra decide si buscar el dinero en otra fuente.
21
+ *
22
+ * Backend: POST /accounts/{accountId}/collect-debit (privado VPC).
23
+ */
24
+ collectDebit(accountId: string, request: CollectDebitRequest): Promise<ApiGatewayResponse<CollectDebitResponse>>;
25
+
20
26
  update(directoryId: string, data: AccountUpdateRequest): Promise<ApiGatewayResponse<void>>;
21
27
 
22
28
  updateByAccountNumber(accountNumber: string, data: AccountUpdateRequest): Promise<ApiGatewayResponse<void>>;
@@ -3,7 +3,7 @@ import type { IHttpRequest } from "@fiado/http-client";
3
3
  import {
4
4
  CollectRequest,
5
5
  CollectResponse,
6
- RegisterCollectibleRequest,
6
+ DeregisterChargeResponse,
7
7
  } from "@fiado/type-kit/bin/collection/index.js";
8
8
  import { ICollectionEngineApi } from "./interfaces/ICollectionEngineApi.js";
9
9
 
@@ -26,13 +26,12 @@ export default class CollectionEngineApi implements ICollectionEngineApi {
26
26
  return await this.httpRequest.post(url, request);
27
27
  }
28
28
 
29
- async registerCollectible(request: RegisterCollectibleRequest): Promise<FiadoApiResponse<boolean>> {
30
- const url = `${this.baseUrl}collection/register`;
31
- return await this.httpRequest.post(url, request);
32
- }
33
-
34
- async deregister(ownerRef: string, productId: string, chargeId: string): Promise<FiadoApiResponse<boolean>> {
35
- const url = `${this.baseUrl}collection/deregister`;
36
- return await this.httpRequest.post(url, { ownerRef, productId, chargeId });
29
+ async deregister(domain: string, chargeId: string): Promise<FiadoApiResponse<DeregisterChargeResponse>> {
30
+ // `chargeId` lleva separadores `#` en todos los dominios (`SALE#42#INSTALLMENT#3`): sin
31
+ // escapar, el navegador o el cliente HTTP lo tratan como fragmento y el motor recibe la
32
+ // parte anterior al primer `#`, o sea otro cargo.
33
+ const url = `${this.baseUrl}collection/domains/${encodeURIComponent(domain)}`
34
+ + `/charges/${encodeURIComponent(chargeId)}/deregister`;
35
+ return await this.httpRequest.post(url, {});
37
36
  }
38
37
  }
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  CollectRequest,
3
3
  CollectResponse,
4
- RegisterCollectibleRequest,
4
+ DeregisterChargeResponse,
5
5
  } from "@fiado/type-kit/bin/collection/index.js";
6
6
 
7
7
  type FiadoApiResponse<T> = import("@fiado/type-kit/bin/apiResponse/dtos/FiadoApiResponse.js").default<T>;
@@ -10,29 +10,38 @@ type FiadoApiResponse<T> = import("@fiado/type-kit/bin/apiResponse/dtos/FiadoApi
10
10
  * Cliente para invocar los endpoints privados del lambda `collection-engine-business`.
11
11
  *
12
12
  * Los endpoints viven bajo `COLLECTION_ENGINE_LAMBDA_URL` (API Gateway privado / VPC).
13
- * El motor es agnóstico de proveedores/cuentas — los dominios (une-credit,
14
- * surekeep-retail, etc.) sólo hablan el contrato genérico de `PendingCharge`.
13
+ * El motor es agnóstico de proveedores y cuentas: el dominio dice QUÉ se debe y el motor
14
+ * decide de dónde cobrarlo según la config del producto.
15
+ *
16
+ * El alta explícita de un cargo cobrable (`registerCollectible`) todavía no existe en el
17
+ * motor: hoy `collect` crea el intent si no lo había, derivando su identidad de
18
+ * `domain#chargeId`. El método se reincorporará cuando el motor exponga la ruta.
15
19
  */
16
20
  export interface ICollectionEngineApi {
17
21
 
18
22
  /**
19
- * Cobro on-demand síncrono. El dominio pide al motor que intente cobrar
20
- * un cargo puntual (fuera del barrido normal de la cascada).
23
+ * Cobro on-demand síncrono. El dominio manda el cargo ya resuelto y el motor recorre la
24
+ * cascada de fuentes configurada para el producto. Idempotente por `domain#chargeId`:
25
+ * repetir la llamada sobre un cargo ya cobrado devuelve el resultado anterior sin volver
26
+ * a mover dinero.
27
+ *
21
28
  * Backend: POST /collection/collect (privado VPC).
22
29
  */
23
30
  collect(request: CollectRequest): Promise<FiadoApiResponse<CollectResponse>>;
24
31
 
25
32
  /**
26
- * Alta de un cargo cobrable en el índice del motor. Lo invoca el dominio
27
- * dueño cuando nace una deuda cobrable (installment, cuota, etc.).
28
- * Backend: POST /collection/register (privado VPC).
29
- */
30
- registerCollectible(request: RegisterCollectibleRequest): Promise<FiadoApiResponse<boolean>>;
31
-
32
- /**
33
- * Baja de un cargo del índice del motor (equivalente a cancelar el intent
34
- * en curso). Lo invoca el dominio dueño cuando el cargo deja de ser cobrable.
35
- * Backend: POST /collection/deregister (privado VPC).
33
+ * Baja de un cargo: detiene los reintentos de un cobro que el dominio castigó, condonó o
34
+ * reestructuró. Sin esto, un cargo sin fondos se reintenta indefinidamente.
35
+ *
36
+ * Identifica el cobro por `domain` y `chargeId`, que es la llave con la que el motor lo
37
+ * registró. Es idempotente: dar de baja un cargo ya terminal devuelve `ALREADY_TERMINAL`
38
+ * sin alterarlo.
39
+ *
40
+ * Un cargo desconocido responde 404, y el cliente HTTP lo propaga como excepción — no llega
41
+ * como envelope con `code`. El dominio debe atraparlo si un cargo ya inexistente es un caso
42
+ * esperado de su flujo.
43
+ *
44
+ * Backend: POST /collection/domains/{domain}/charges/{chargeId}/deregister (privado VPC).
36
45
  */
37
- deregister(ownerRef: string, productId: string, chargeId: string): Promise<FiadoApiResponse<boolean>>;
46
+ deregister(domain: string, chargeId: string): Promise<FiadoApiResponse<DeregisterChargeResponse>>;
38
47
  }
@@ -195,7 +195,7 @@ import { IKycVerificationsBusinessApi, KycVerificationsBusinessApi } from "./kyc
195
195
  // Webhook business — publisher de la cola compartida de entrega de eventos a suscriptores externos
196
196
  import { IWebhookBusinessPublisher, WebhookBusinessPublisher } from "./webhook-business/index.js";
197
197
  import { ICentralPaymentsWebhookApi, CentralPaymentsWebhookApi } from "./central-payments-webhook/index.js";
198
- // Collection engine — cliente del motor de cobro central (collect/registerCollectible/deregister)
198
+ // Collection engine — cliente del motor de cobro central (collect/deregister)
199
199
  import { ICollectionEngineApi } from "./collection-engine/index.js";
200
200
  import CollectionEngineApi from "./collection-engine/api/CollectionEngineApi.js";
201
201
  // Domain callback — cliente genérico que usa el motor para notificar a cualquier dominio
@@ -374,7 +374,7 @@ export const apiInvokerBindings = new ContainerModule(({ bind }) => {
374
374
  bind<IWebhookBusinessPublisher>("IWebhookBusinessPublisher").to(WebhookBusinessPublisher);
375
375
  bind<ICentralPaymentsWebhookApi>("ICentralPaymentsWebhookApi").to(CentralPaymentsWebhookApi);
376
376
 
377
- // Collection engine — motor de cobro central multitenant (collect/registerCollectible/deregister)
377
+ // Collection engine — motor de cobro central multitenant (collect/deregister)
378
378
  bind<ICollectionEngineApi>("ICollectionEngineApi").to(CollectionEngineApi);
379
379
 
380
380
  // Domain callback — el motor notifica al dominio dueño del cargo (applyCollectionResult)