@fiado/api-invoker 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.
- package/README.md +30 -10
- package/bin/container.config.d.ts +2 -2
- package/bin/container.config.js +4 -3
- package/package.json +1 -1
- package/src/container.config.ts +4 -5
package/README.md
CHANGED
|
@@ -1,43 +1,63 @@
|
|
|
1
1
|
# fiado-api-invoker
|
|
2
2
|
|
|
3
|
+
`fiado-api-invoker` es una librería diseñada para facilitar la invocación de APIs privadas de AWS Lambda a través de API Gateway dentro de la misma VPC. Esta librería simplifica el proceso de configuración y llamada a servicios, permitiendo a los desarrolladores centrarse en la lógica de negocio.
|
|
3
4
|
|
|
4
5
|
|
|
5
6
|
## Configuración
|
|
6
7
|
|
|
7
8
|
Antes de usar la librería, asegúrate de configurar la URL base del API Gateway privado que corresponda por ejemplo si vas a usar los servicios del Lambda `Directory` se puede hacer estableciendo la variable de entorno `DIRECTORY_LAMBDA_URL`.
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
|
|
11
|
+
## Instalación
|
|
12
|
+
|
|
13
|
+
npm install fiado-api-invoker @fiado/http-client
|
|
14
|
+
|
|
15
|
+
## Configuración del Contenedor de InversifyJS
|
|
10
16
|
|
|
11
17
|
```typescript
|
|
18
|
+
import { Container } from "inversify";
|
|
19
|
+
import { apiInvokerContainer } from '@fiado/api-invoker';
|
|
12
20
|
import { IHttpRequest, AxiosHttpRequest } from "@fiado/http-client";
|
|
13
|
-
|
|
14
|
-
|
|
21
|
+
|
|
22
|
+
// Crea el contenedor principal de tu aplicación
|
|
23
|
+
const container = new Container();
|
|
24
|
+
|
|
25
|
+
// Establece el contenedor de la biblioteca fiado-api-invoker como contenedor padre
|
|
26
|
+
// Esto permite que tu aplicación resuelva dependencias definidas en fiado-api-invoker
|
|
27
|
+
container.parent = apiInvokerContainer;
|
|
15
28
|
|
|
16
29
|
// Registro del cliente HTTP
|
|
17
|
-
container.bind<IHttpRequest>(IHttpRequest).to(AxiosHttpRequest);
|
|
30
|
+
container.bind<IHttpRequest>("IHttpRequest").to(AxiosHttpRequest);
|
|
31
|
+
|
|
32
|
+
// Exporta el contenedor para su uso en toda tu aplicación
|
|
33
|
+
export { container };
|
|
18
34
|
|
|
19
|
-
|
|
20
|
-
container.bind<IDirectoryApi>(IDirectoryApi).to(DirectoryService);
|
|
35
|
+
```
|
|
21
36
|
|
|
22
37
|
|
|
23
|
-
|
|
38
|
+
## Uso de IDirectoryApi en Servicios del Proyecto
|
|
24
39
|
|
|
40
|
+
Para utilizar `fiado-api-invoker`, necesitas configurar el contenedor de InversifyJS en tu aplicación. Aquí te mostramos cómo registrar las dependencias necesarias:
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
25
43
|
import { inject, injectable } from "inversify";
|
|
26
|
-
import { IDirectoryApi } from "
|
|
44
|
+
import { IDirectoryApi } from "fiado-api-invoker";
|
|
45
|
+
import { log } from "@fiado/logger";
|
|
27
46
|
|
|
28
47
|
@injectable()
|
|
29
48
|
export class SomeService {
|
|
30
|
-
constructor(private directoryApi: IDirectoryApi) {}
|
|
49
|
+
constructor(@inject("IDirectoryApi") private directoryApi: IDirectoryApi) {}
|
|
31
50
|
|
|
32
51
|
public async fetchDirectoryDetails(directoryIds: string[]): Promise<void> {
|
|
33
52
|
try {
|
|
34
53
|
const details = await this.directoryApi.getByIds(directoryIds);
|
|
35
54
|
log.info(details);
|
|
36
|
-
//
|
|
55
|
+
// Procesa los detalles según sea necesario...
|
|
37
56
|
} catch (error) {
|
|
38
57
|
log.error("Error fetching directory details:", error);
|
|
39
58
|
}
|
|
40
59
|
}
|
|
41
60
|
}
|
|
61
|
+
```
|
|
42
62
|
|
|
43
63
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const
|
|
1
|
+
import { ContainerModule } from "inversify";
|
|
2
|
+
export declare const apiInvokerBindings: ContainerModule;
|
package/bin/container.config.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.apiInvokerBindings = void 0;
|
|
4
4
|
const inversify_1 = require("inversify");
|
|
5
5
|
const directory_1 = require("./directory");
|
|
6
|
-
exports.
|
|
7
|
-
|
|
6
|
+
exports.apiInvokerBindings = new inversify_1.ContainerModule((bind) => {
|
|
7
|
+
bind("IDirectoryApi").to(directory_1.DirectoryApi);
|
|
8
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fiado/api-invoker",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Sirve como un puente entre diferentes funciones lambda, facilitando la comunicación entre ellas a traves de invocaciones http",
|
|
5
5
|
"main": "bin/index.js",
|
|
6
6
|
"types": "bin/index.d.ts",
|
package/src/container.config.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
2
|
+
import { ContainerModule, interfaces } from "inversify";
|
|
3
3
|
import { DirectoryApi, IDirectoryApi } from "./directory";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
apiInvokerContainer.bind<IDirectoryApi>("IDirectoryApi").to(DirectoryApi);
|
|
5
|
+
export const apiInvokerBindings = new ContainerModule((bind: interfaces.Bind) => {
|
|
6
|
+
bind<IDirectoryApi>("IDirectoryApi").to(DirectoryApi)
|
|
7
|
+
});
|