diff --git a/.nvmrc b/.nvmrc index 790e110..ee09fac 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v20.10.0 +v20.11.1 diff --git a/README.md b/README.md index 546dc89..ee6fd8c 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ Creates an instance of `AWSWebCore` with the specified configuration. Initializes the AWSWebCore instance. -- `signedRequest(method: string, url: string, params?: Params, body?: Body, config?: AxiosRequestConfig): Promise>` +- `signedRequest(method: string, url: string, params?: Params, body?: Body, config?: AxiosRequestConfig): Promise>` Makes a signed HTTP request. @@ -196,7 +196,7 @@ Creates an instance of `AzureWebCore` with the specified configuration. Initializes the AzureWebCore instance. -- `signedRequest(method: string, url: string, params?: Params, body?: Body, config?: AxiosRequestConfig): Promise>` +- `signedRequest(method: string, url: string, params?: Params, body?: Body, config?: AxiosRequestConfig): Promise>` Makes a signed HTTP request. diff --git a/src/core/aws-web.core.ts b/src/core/aws-web.core.ts index 21bf016..f3af88b 100644 --- a/src/core/aws-web.core.ts +++ b/src/core/aws-web.core.ts @@ -1,6 +1,7 @@ import { AWSWebCoreState, Body, + HttpResponse, LemonCredentials, LemonKMS, LemonOAuthToken, @@ -12,7 +13,7 @@ import { } from '../types'; import { AWSStorageService, USE_X_LEMON_IDENTITY_KEY } from '../token-storage'; import { calcSignature, LoggerService } from '../utils'; -import { AxiosRequestConfig, AxiosResponse } from 'axios'; +import { AxiosRequestConfig } from 'axios'; import { AWSHttpRequestBuilder, HttpRequestBuilder } from '../http'; import AWS from 'aws-sdk/global.js'; @@ -87,15 +88,9 @@ export class AWSWebCore implements WebCoreService { * @param {Params} [params={}] - The request parameters. * @param {Body} body - The request body. * @param {AxiosRequestConfig} [config] - Additional Axios request configuration. - * @returns {Promise>} - The Axios response. + * @returns {Promise>} - The Axios response. */ - async request( - method: string, - url: string, - params: Params = {}, - body?: Body, - config?: AxiosRequestConfig - ): Promise> { + async request(method: string, url: string, params: Params = {}, body?: Body, config?: AxiosRequestConfig): Promise> { const builder = new HttpRequestBuilder({ method, baseURL: url, @@ -127,7 +122,7 @@ export class AWSWebCore implements WebCoreService { * @param {Params} [params={}] - The request parameters. * @param {Body} body - The request body. * @param {AxiosRequestConfig} [config] - Additional Axios request configuration. - * @returns {Promise>} - The Axios response. + * @returns {Promise>} - The Axios response. */ async signedRequest( method: string, @@ -135,7 +130,7 @@ export class AWSWebCore implements WebCoreService { params: Params = {}, body?: Body, config?: AxiosRequestConfig - ): Promise> { + ): Promise> { const builder = new AWSHttpRequestBuilder(this.tokenStorage, { method, baseURL: url, @@ -250,7 +245,7 @@ export class AWSWebCore implements WebCoreService { body = { ...body, domain }; } - const response: AxiosResponse = await this.signedRequest( + const response: HttpResponse = await this.signedRequest( 'POST', url ? url : `${this.config.oAuthEndpoint}/oauth/${cached.authId}/refresh`, {}, diff --git a/src/core/azure-web.core.ts b/src/core/azure-web.core.ts index 2da0f4e..33228f8 100644 --- a/src/core/azure-web.core.ts +++ b/src/core/azure-web.core.ts @@ -1,7 +1,7 @@ -import { AzureWebCoreState, Body, LemonOAuthToken, Params, WebCoreConfig, WebCoreService } from '../types'; +import { AzureWebCoreState, Body, HttpResponse, LemonOAuthToken, Params, WebCoreConfig, WebCoreService } from '../types'; import { AzureStorageService, USE_X_LEMON_IDENTITY_KEY } from '../token-storage'; import { LoggerService } from '../utils'; -import { AxiosRequestConfig, AxiosResponse } from 'axios'; +import { AxiosRequestConfig } from 'axios'; import { AzureHttpRequestBuilder, HttpRequestBuilder } from '../http'; /** @@ -58,15 +58,9 @@ export class AzureWebCore implements WebCoreService { * @param {Params} [params={}] - The request parameters. * @param {Body} body - The request body. * @param {AxiosRequestConfig} [config] - Additional Axios request configuration. - * @returns {Promise>} - The Axios response. + * @returns {Promise>} - The Axios response. */ - async request( - method: string, - url: string, - params: Params = {}, - body?: Body, - config?: AxiosRequestConfig - ): Promise> { + async request(method: string, url: string, params: Params = {}, body?: Body, config?: AxiosRequestConfig): Promise> { const builder = new HttpRequestBuilder({ method, baseURL: url, @@ -98,7 +92,7 @@ export class AzureWebCore implements WebCoreService { * @param {Params} [params={}] - The URL parameters for the request. * @param {Body} [body] - The request body. * @param {AxiosRequestConfig} [config] - Additional Axios request configuration. - * @returns {Promise>} - The Axios response. + * @returns {Promise>} - The Axios response. */ async signedRequest( method: string, @@ -106,7 +100,7 @@ export class AzureWebCore implements WebCoreService { params: Params = {}, body?: Body, config?: AxiosRequestConfig - ): Promise> { + ): Promise> { const builder = new AzureHttpRequestBuilder(this.tokenStorage, { method, baseURL: url, diff --git a/src/http/aws-http-request.builder.ts b/src/http/aws-http-request.builder.ts index 6892753..73964df 100644 --- a/src/http/aws-http-request.builder.ts +++ b/src/http/aws-http-request.builder.ts @@ -1,5 +1,5 @@ -import axios, { AxiosHeaders, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'; -import { Body, Headers, HttpRequestData, Params } from '../types'; +import axios, { AxiosHeaders, AxiosInstance, AxiosRequestConfig } from 'axios'; +import { Body, Headers, HttpRequestData, HttpResponse, Params } from '../types'; import { AWSStorageService, REGION_KEY, USE_X_LEMON_IDENTITY_KEY } from '../token-storage'; import AWS from 'aws-sdk/global.js'; import { sigV4Client } from '../vendor'; @@ -9,7 +9,7 @@ import { isEmptyObject, LoggerService } from '../utils'; * Class to build and execute HTTP requests with AWS signing * @example * ```ts - * const response: AxiosResponse = await new AWSHttpRequestBuilder({ + * const response: HttpResponse = await new AWSHttpRequestBuilder({ * method: 'GET', * baseURL: `https://api.lemoncloud.io/v1/oauth`, * }) @@ -115,10 +115,10 @@ export class AWSHttpRequestBuilder { /** * Executes the HTTP request. * @template T - * @returns {Promise>} - Promise containing the response. + * @returns {Promise>} - Promise containing the response. * @throws {Error} If an error occurs during the request. */ - async execute(): Promise> { + async execute(): Promise> { try { const signedClient = await this.getSignedClient(this.config.baseURL); const data: HttpRequestData = { diff --git a/src/http/azure-http-request.builder.ts b/src/http/azure-http-request.builder.ts index 493277a..dca4036 100644 --- a/src/http/azure-http-request.builder.ts +++ b/src/http/azure-http-request.builder.ts @@ -1,12 +1,12 @@ -import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'; -import { Body, Headers, Params } from '../types'; +import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'; +import { Body, Headers, HttpResponse, Params } from '../types'; import { AzureStorageService, USE_X_LEMON_IDENTITY_KEY } from '../token-storage'; /** * Class to build and execute HTTP requests with AWS signing * @example * ```ts - * const response: AxiosResponse = await new AzureHttpRequestBuilder({ + * const response: HttpResponse = await new AzureHttpRequestBuilder({ * method: 'GET', * baseURL: `https://api.lemoncloud.io/v1/oauth`, * }) @@ -110,10 +110,10 @@ export class AzureHttpRequestBuilder { /** * Executes the HTTP request. * @template T - * @returns {Promise>} - Promise containing the response. + * @returns {Promise>} - Promise containing the response. * @throws {Error} If an error occurs during the request. */ - async execute(): Promise> { + async execute(): Promise> { try { await this.addCodeParams(); await this.addBearerTokenToHeader(); diff --git a/src/http/http-request.builder.ts b/src/http/http-request.builder.ts index 1ec971f..b625f1d 100644 --- a/src/http/http-request.builder.ts +++ b/src/http/http-request.builder.ts @@ -1,11 +1,11 @@ -import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'; -import { Body, Headers, Params } from '../types'; +import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'; +import { Body, Headers, HttpResponse, Params } from '../types'; /** * Class to build and execute HTTP requests * @example * ```ts - * const response: AxiosResponse = await new HttpRequestBuilder({ + * const response: HttpResponse = await new HttpRequestBuilder({ * method: 'GET', * baseURL: `https://api.lemoncloud.io/v1/oauth`, * }) @@ -103,10 +103,10 @@ export class HttpRequestBuilder { /** * Executes the HTTP request * @template T - * @returns {Promise>} - Promise containing the response + * @returns {Promise>} - Promise containing the response * @throws {Error} If an error occurs during the request */ - async execute(): Promise> { + async execute(): Promise> { try { return await this.axiosInstance.request(this.config); } catch (error) { diff --git a/src/types/http.ts b/src/types/http.ts index b65edcb..22520f4 100644 --- a/src/types/http.ts +++ b/src/types/http.ts @@ -43,3 +43,12 @@ export interface HttpRequestData { */ body?: Body; } + +export interface HttpResponse { + data: T; + status: number; + statusText: string; + headers?: any; + config?: any; + request?: any; +}