@fiado/api-invoker 1.0.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.
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # fiado-api-invoker
2
+
3
+
4
+
5
+ ## Configuración
6
+
7
+ 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
+ ## Uso
10
+
11
+ ```typescript
12
+ import { IHttpRequest, AxiosHttpRequest } from "@fiado/http-client";
13
+ import { IDirectoryApi } from "ruta/a/fiado-api-invoker/interfaces/IDirectoryApi";
14
+ import { DirectoryService } from "ruta/a/fiado-api-invoker/services/DirectoryService";
15
+
16
+ // Registro del cliente HTTP
17
+ container.bind<IHttpRequest>(IHttpRequest).to(AxiosHttpRequest);
18
+
19
+ // Registro de DirectoryService
20
+ container.bind<IDirectoryApi>(IDirectoryApi).to(DirectoryService);
21
+
22
+
23
+ //Uso de IDirectoryApi en Servicios del Proyecto
24
+
25
+ import { inject, injectable } from "inversify";
26
+ import { IDirectoryApi } from "ruta/a/fiado-api-invoker/interfaces/IDirectoryApi";
27
+
28
+ @injectable()
29
+ export class SomeService {
30
+ constructor(private directoryApi: IDirectoryApi) {}
31
+
32
+ public async fetchDirectoryDetails(directoryIds: string[]): Promise<void> {
33
+ try {
34
+ const details = await this.directoryApi.getByIds(directoryIds);
35
+ log.info(details);
36
+ // Tu lógica según sea necesario...
37
+ } catch (error) {
38
+ log.error("Error fetching directory details:", error);
39
+ }
40
+ }
41
+ }
42
+
43
+
@@ -0,0 +1,10 @@
1
+ import { IDirectoryApi } from "./interfaces/IDirectoryApi";
2
+ import { IHttpRequest } from "@fiado/http-client";
3
+ export declare class DirectoryService implements IDirectoryApi {
4
+ private httpRequest;
5
+ private readonly baseUrl;
6
+ constructor(httpRequest: IHttpRequest);
7
+ getByIds(ids: string[]): Promise<Array<{
8
+ [key: string]: any;
9
+ }>>;
10
+ }
@@ -0,0 +1,32 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DirectoryService = void 0;
13
+ const inversify_1 = require("inversify");
14
+ let DirectoryService = class DirectoryService {
15
+ constructor(httpRequest) {
16
+ this.httpRequest = httpRequest;
17
+ this.baseUrl = process.env.DIRECTORY_LAMBDA_URL || "";
18
+ }
19
+ async getByIds(ids) {
20
+ if (ids.length === 0) {
21
+ throw new Error("At least one directory ID is required.");
22
+ }
23
+ const queryParams = ids.map(id => `directoryId=${id}`).join('&');
24
+ const operationName = "getUserInfoByIds";
25
+ return await this.httpRequest.get(`${this.baseUrl}/`, { params: queryParams, headers: { 'operationName': operationName } });
26
+ }
27
+ };
28
+ exports.DirectoryService = DirectoryService;
29
+ exports.DirectoryService = DirectoryService = __decorate([
30
+ (0, inversify_1.injectable)(),
31
+ __metadata("design:paramtypes", [Object])
32
+ ], DirectoryService);
@@ -0,0 +1,2 @@
1
+ export * from './interfaces/IDirectoryApi';
2
+ export * from './DirectoryApi';
@@ -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/IDirectoryApi"), exports);
18
+ __exportStar(require("./DirectoryApi"), exports);
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Interfaz para el servicio Directory que permite operaciones sobre directorios.
3
+ */
4
+ export interface IDirectoryApi {
5
+ /**
6
+ * Obtiene una lista de directorios por sus IDs.
7
+ * @param ids Array de IDs de directorios (UUIDs) a buscar.
8
+ * @returns Una promesa que resuelve a un arreglo de objetos de directorio.
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
+ getByIds(ids: string[]): Promise<Array<{
13
+ [key: string]: any;
14
+ }>>;
15
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // IDirectoryService.ts
3
+ Object.defineProperty(exports, "__esModule", { value: true });
File without changes
File without changes
package/bin/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './directory';
package/bin/index.js ADDED
@@ -0,0 +1,17 @@
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("./directory"), exports);
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@fiado/api-invoker",
3
+ "version": "1.0.0",
4
+ "description": "Sirve como un puente entre diferentes funciones lambda, facilitando la comunicación entre ellas a traves de invocaciones http",
5
+ "main": "bin/index.js",
6
+ "types": "bin/index.d.ts",
7
+ "scripts": {
8
+ "test": "test",
9
+ "build": "tsc"
10
+ },
11
+ "keywords": [],
12
+ "author": "Fiado Inc",
13
+ "license": "ISC",
14
+ "dependencies": {
15
+ "@fiado/type-kit": "^1.0.16",
16
+ "inversify": "^6.0.2",
17
+ "reflect-metadata": "^0.2.1",
18
+ "typescript": "^5.4.3"
19
+ },
20
+ "devDependencies": {
21
+ }
22
+ }
@@ -0,0 +1,24 @@
1
+
2
+ import { injectable } from "inversify";
3
+ import { IDirectoryApi } from "./interfaces/IDirectoryApi";
4
+ import { IHttpRequest } from "@fiado/http-client";
5
+
6
+ @injectable()
7
+ export class DirectoryService implements IDirectoryApi {
8
+
9
+ private readonly baseUrl = process.env.DIRECTORY_LAMBDA_URL || "";
10
+
11
+ constructor(private httpRequest: IHttpRequest) { }
12
+
13
+ public async getByIds(ids: string[]): Promise<Array<{ [key: string]: any }>> {
14
+
15
+ if (ids.length === 0) {
16
+ throw new Error("At least one directory ID is required.")
17
+ }
18
+
19
+ const queryParams = ids.map(id => `directoryId=${id}`).join('&');
20
+ const operationName = "getUserInfoByIds";
21
+
22
+ return await this.httpRequest.get(`${this.baseUrl}/`, { params: queryParams, headers: { 'operationName': operationName } });
23
+ }
24
+ }
@@ -0,0 +1,3 @@
1
+
2
+ export * from './interfaces/IDirectoryApi';
3
+ export * from './DirectoryApi';
@@ -0,0 +1,15 @@
1
+ // IDirectoryService.ts
2
+
3
+ /**
4
+ * Interfaz para el servicio Directory que permite operaciones sobre directorios.
5
+ */
6
+ export interface IDirectoryApi {
7
+ /**
8
+ * Obtiene una lista de directorios por sus IDs.
9
+ * @param ids Array de IDs de directorios (UUIDs) a buscar.
10
+ * @returns Una promesa que resuelve a un arreglo de objetos de directorio.
11
+ * Puede devolver un arreglo vacío si no se encuentran coincidencias.
12
+ * @throws {Error} Lanza un error si los parámetros de entrada son inválidos.
13
+ */
14
+ getByIds(ids: string[]): Promise<Array<{[key: string]: any}>>;
15
+ }
File without changes
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+
2
+
3
+
4
+ export * from './directory';
5
+
6
+
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "esModuleInterop": true,
6
+ "skipLibCheck": true,
7
+ "forceConsistentCasingInFileNames": true,
8
+ "experimentalDecorators": true,
9
+ "emitDecoratorMetadata": true,
10
+ "outDir": "./bin",
11
+ "rootDir": "./src",
12
+ "moduleResolution": "node",
13
+ "declaration": true,
14
+ },
15
+ "include": [
16
+ "./src/**/*"
17
+ ],
18
+ "exclude": [
19
+ "node_modules"
20
+ ]
21
+ }