@fiado/api-invoker 1.0.5 → 1.0.7
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 +8 -7
- package/bin/container.config.js +2 -0
- package/bin/directory/DirectoryApi.js +7 -2
- package/bin/identity/IdentityApi.d.ts +10 -0
- package/bin/identity/IdentityApi.js +35 -0
- package/bin/identity/index.d.ts +2 -0
- package/bin/identity/index.js +18 -0
- package/bin/identity/interfaces/IIdentityApi.d.ts +15 -0
- package/bin/identity/interfaces/IIdentityApi.js +2 -0
- package/bin/index.d.ts +1 -0
- package/bin/index.js +1 -0
- package/package.json +7 -2
- package/src/container.config.ts +4 -1
- package/src/directory/DirectoryApi.ts +4 -2
- package/src/identity/IdentityApi.ts +23 -0
- package/src/identity/index.ts +4 -0
- package/src/identity/interfaces/IIdentityApi.ts +14 -0
- package/src/index.ts +3 -0
package/README.md
CHANGED
|
@@ -9,22 +9,22 @@ Antes de usar la librería, asegúrate de configurar la URL base del API Gateway
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
## Instalación
|
|
12
|
-
|
|
13
|
-
npm install fiado-api-invoker @fiado/http-client
|
|
12
|
+
```bash
|
|
13
|
+
`npm install fiado-api-invoker @fiado/http-client`
|
|
14
|
+
```
|
|
14
15
|
|
|
15
16
|
## Configuración del Contenedor de InversifyJS
|
|
16
17
|
|
|
17
18
|
```typescript
|
|
18
19
|
import { Container } from "inversify";
|
|
19
|
-
import { apiInvokerContainer } from '@fiado/api-invoker';
|
|
20
20
|
import { IHttpRequest, AxiosHttpRequest } from "@fiado/http-client";
|
|
21
|
+
import { apiInvokerContainer } from '@fiado/api-invoker';
|
|
21
22
|
|
|
22
23
|
// Crea el contenedor principal de tu aplicación
|
|
23
24
|
const container = new Container();
|
|
24
25
|
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
container.parent = apiInvokerContainer;
|
|
26
|
+
// Aplica las configuraciones de vinculación de fiado-gateway-adapter al contenedor
|
|
27
|
+
container.load(gatewayAdapterBindings);
|
|
28
28
|
|
|
29
29
|
// Registro del cliente HTTP
|
|
30
30
|
container.bind<IHttpRequest>("IHttpRequest").to(AxiosHttpRequest);
|
|
@@ -32,6 +32,7 @@ container.bind<IHttpRequest>("IHttpRequest").to(AxiosHttpRequest);
|
|
|
32
32
|
// Exporta el contenedor para su uso en toda tu aplicación
|
|
33
33
|
export { container };
|
|
34
34
|
|
|
35
|
+
|
|
35
36
|
```
|
|
36
37
|
|
|
37
38
|
|
|
@@ -52,7 +53,7 @@ export class SomeService {
|
|
|
52
53
|
try {
|
|
53
54
|
const details = await this.directoryApi.getByIds(directoryIds);
|
|
54
55
|
log.info(details);
|
|
55
|
-
|
|
56
|
+
|
|
56
57
|
} catch (error) {
|
|
57
58
|
log.error("Error fetching directory details:", error);
|
|
58
59
|
}
|
package/bin/container.config.js
CHANGED
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.apiInvokerBindings = void 0;
|
|
4
4
|
const inversify_1 = require("inversify");
|
|
5
5
|
const directory_1 = require("./directory");
|
|
6
|
+
const IdentityApi_1 = require("./identity/IdentityApi");
|
|
6
7
|
exports.apiInvokerBindings = new inversify_1.ContainerModule((bind) => {
|
|
7
8
|
bind("IDirectoryApi").to(directory_1.DirectoryApi);
|
|
9
|
+
bind("IIdentityApi").to(IdentityApi_1.IdentityApi);
|
|
8
10
|
});
|
|
@@ -11,9 +11,14 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
14
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
18
|
exports.DirectoryApi = void 0;
|
|
16
19
|
const inversify_1 = require("inversify");
|
|
20
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
21
|
+
dotenv_1.default.config();
|
|
17
22
|
let DirectoryApi = class DirectoryApi {
|
|
18
23
|
constructor(httpRequest) {
|
|
19
24
|
this.httpRequest = httpRequest;
|
|
@@ -23,9 +28,9 @@ let DirectoryApi = class DirectoryApi {
|
|
|
23
28
|
if (ids.length === 0) {
|
|
24
29
|
throw new Error("At least one directory ID is required.");
|
|
25
30
|
}
|
|
26
|
-
const
|
|
31
|
+
const url = `${this.baseUrl}?${ids.map(id => `directoryId=${encodeURIComponent(id)}`).join('&')}`;
|
|
27
32
|
const operationName = "getUserInfoByIds";
|
|
28
|
-
return await this.httpRequest.
|
|
33
|
+
return await this.httpRequest.post(`${this.baseUrl}`, {}, { 'operationName': operationName });
|
|
29
34
|
}
|
|
30
35
|
};
|
|
31
36
|
exports.DirectoryApi = DirectoryApi;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IIdentityApi } from "./interfaces/IIdentityApi";
|
|
2
|
+
import { IHttpRequest } from "@fiado/http-client";
|
|
3
|
+
export declare class IdentityApi implements IIdentityApi {
|
|
4
|
+
private httpRequest;
|
|
5
|
+
private readonly baseUrl;
|
|
6
|
+
constructor(httpRequest: IHttpRequest);
|
|
7
|
+
getPeopleByIds(ids: string[]): Promise<{
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}[]>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.IdentityApi = void 0;
|
|
16
|
+
const inversify_1 = require("inversify");
|
|
17
|
+
let IdentityApi = class IdentityApi {
|
|
18
|
+
constructor(httpRequest) {
|
|
19
|
+
this.httpRequest = httpRequest;
|
|
20
|
+
this.baseUrl = process.env.IDENTITY_LAMBDA_URL || "";
|
|
21
|
+
}
|
|
22
|
+
async getPeopleByIds(ids) {
|
|
23
|
+
if (ids.length === 0) {
|
|
24
|
+
throw new Error("At least one identity ID is required.");
|
|
25
|
+
}
|
|
26
|
+
const url = `${this.baseUrl}identities/people?${ids.map(id => `peopleId=${encodeURIComponent(id)}`).join('&')}`;
|
|
27
|
+
return await this.httpRequest.post(`${this.baseUrl}`, {});
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.IdentityApi = IdentityApi;
|
|
31
|
+
exports.IdentityApi = IdentityApi = __decorate([
|
|
32
|
+
(0, inversify_1.injectable)(),
|
|
33
|
+
__param(0, (0, inversify_1.inject)("IHttpRequest")),
|
|
34
|
+
__metadata("design:paramtypes", [Object])
|
|
35
|
+
], IdentityApi);
|
package/bin/identity/index.d.ts
CHANGED
package/bin/identity/index.js
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./interfaces/IIdentityApi"), exports);
|
|
18
|
+
__exportStar(require("./IdentityApi"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interfaz para el servicio Directory que permite operaciones sobre directorios.
|
|
3
|
+
*/
|
|
4
|
+
export interface IIdentityApi {
|
|
5
|
+
/**
|
|
6
|
+
* Obtiene una lista de people por sus IDs.
|
|
7
|
+
* @param ids Array de IDs de peopleId (UUIDs) a buscar.
|
|
8
|
+
* @returns Una promesa que resuelve a un arreglo de objetos de people.
|
|
9
|
+
* Puede devolver un arreglo vacío si no se encuentran coincidencias.
|
|
10
|
+
* @throws {Error} Lanza un error si los parámetros de entrada son inválidos.
|
|
11
|
+
*/
|
|
12
|
+
getPeopleByIds(ids: string[]): Promise<Array<{
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}>>;
|
|
15
|
+
}
|
package/bin/index.d.ts
CHANGED
package/bin/index.js
CHANGED
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./directory"), exports);
|
|
18
|
+
__exportStar(require("./identity"), exports);
|
|
18
19
|
__exportStar(require("./container.config"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fiado/api-invoker",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
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",
|
|
@@ -12,11 +12,16 @@
|
|
|
12
12
|
"author": "Fiado Inc",
|
|
13
13
|
"license": "ISC",
|
|
14
14
|
"dependencies": {
|
|
15
|
+
"@fiado/api-invoker": "^1.0.5",
|
|
16
|
+
"@fiado/gateway-adapter": "^1.0.30",
|
|
17
|
+
"@fiado/http-client": "^1.0.1",
|
|
15
18
|
"@fiado/type-kit": "^1.0.16",
|
|
19
|
+
"dotenv": "^16.4.5",
|
|
16
20
|
"inversify": "^6.0.2",
|
|
17
21
|
"reflect-metadata": "^0.2.1",
|
|
18
22
|
"typescript": "^5.4.3"
|
|
19
23
|
},
|
|
20
24
|
"devDependencies": {
|
|
25
|
+
"@types/node": "^20.12.7"
|
|
21
26
|
}
|
|
22
|
-
}
|
|
27
|
+
}
|
package/src/container.config.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
import { ContainerModule, interfaces } from "inversify";
|
|
3
3
|
import { DirectoryApi, IDirectoryApi } from "./directory";
|
|
4
|
+
import { IIdentityApi } from "./identity/interfaces/IIdentityApi";
|
|
5
|
+
import { IdentityApi } from "./identity/IdentityApi";
|
|
4
6
|
|
|
5
7
|
export const apiInvokerBindings = new ContainerModule((bind: interfaces.Bind) => {
|
|
6
|
-
bind<IDirectoryApi>("IDirectoryApi").to(DirectoryApi)
|
|
8
|
+
bind<IDirectoryApi>("IDirectoryApi").to(DirectoryApi);
|
|
9
|
+
bind<IIdentityApi>("IIdentityApi").to(IdentityApi);
|
|
7
10
|
});
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import { inject, injectable } from "inversify";
|
|
3
3
|
import { IDirectoryApi } from "./interfaces/IDirectoryApi";
|
|
4
4
|
import { IHttpRequest } from "@fiado/http-client";
|
|
5
|
+
import dotenv from 'dotenv';
|
|
6
|
+
dotenv.config();
|
|
5
7
|
|
|
6
8
|
@injectable()
|
|
7
9
|
export class DirectoryApi implements IDirectoryApi {
|
|
@@ -16,9 +18,9 @@ export class DirectoryApi implements IDirectoryApi {
|
|
|
16
18
|
throw new Error("At least one directory ID is required.")
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
const
|
|
21
|
+
const url = `${this.baseUrl}?${ids.map(id => `directoryId=${encodeURIComponent(id)}`).join('&')}`;
|
|
20
22
|
const operationName = "getUserInfoByIds";
|
|
21
23
|
|
|
22
|
-
return await this.httpRequest.
|
|
24
|
+
return await this.httpRequest.post(`${this.baseUrl}`, {}, { 'operationName': operationName } );
|
|
23
25
|
}
|
|
24
26
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { inject, injectable } from "inversify";
|
|
2
|
+
import { IIdentityApi } from "./interfaces/IIdentityApi";
|
|
3
|
+
import { IHttpRequest } from "@fiado/http-client";
|
|
4
|
+
|
|
5
|
+
@injectable()
|
|
6
|
+
export class IdentityApi implements IIdentityApi {
|
|
7
|
+
|
|
8
|
+
private readonly baseUrl = process.env.IDENTITY_LAMBDA_URL || "";
|
|
9
|
+
|
|
10
|
+
constructor(@inject("IHttpRequest") private httpRequest: IHttpRequest) { }
|
|
11
|
+
|
|
12
|
+
async getPeopleByIds(ids: string[]): Promise<{ [key: string]: any; }[]> {
|
|
13
|
+
|
|
14
|
+
if (ids.length === 0) {
|
|
15
|
+
throw new Error("At least one identity ID is required.")
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const url = `${this.baseUrl}identities/people?${ids.map(id => `peopleId=${encodeURIComponent(id)}`).join('&')}`;
|
|
19
|
+
|
|
20
|
+
return await this.httpRequest.post(`${this.baseUrl}`, {} );
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/identity/index.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Interfaz para el servicio Directory que permite operaciones sobre directorios.
|
|
4
|
+
*/
|
|
5
|
+
export interface IIdentityApi {
|
|
6
|
+
/**
|
|
7
|
+
* Obtiene una lista de people por sus IDs.
|
|
8
|
+
* @param ids Array de IDs de peopleId (UUIDs) a buscar.
|
|
9
|
+
* @returns Una promesa que resuelve a un arreglo de objetos de people.
|
|
10
|
+
* Puede devolver un arreglo vacío si no se encuentran coincidencias.
|
|
11
|
+
* @throws {Error} Lanza un error si los parámetros de entrada son inválidos.
|
|
12
|
+
*/
|
|
13
|
+
getPeopleByIds(ids: string[]): Promise<Array<{[key: string]: any}>>;
|
|
14
|
+
}
|