@b613/utils
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -13,3 +13,3 @@ import type { Trace } from './trace/trace.node.js'; | ||
export type Options<AdditionalOptions extends Record<string, any> = never> = RequestInit & { | ||
logger?(message: string, type: string): void; | ||
logger?: Trace; | ||
beforeEach?: <T extends Record<string, any>>(method: Method, path: string, request: RequestOptions<T> & Partial<AdditionalOptions>) => void; | ||
@@ -51,35 +51,5 @@ }; | ||
*/ | ||
export declare function createClient<AdditionalOptions extends Record<string, any> = never>(baseUrl: string, { trace, ...options }?: Options<AdditionalOptions> & { | ||
trace?: Trace; | ||
}): { | ||
options: { | ||
/** A string indicating how the request will interact with the browser's cache to set request's cache. */ | ||
cache?: RequestCache; | ||
/** A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's credentials. */ | ||
credentials?: RequestCredentials; | ||
/** A Headers object, an object literal, or an array of two-item arrays to set request's headers. */ | ||
headers?: HeadersInit; | ||
/** A cryptographic hash of the resource to be fetched by request. Sets request's integrity. */ | ||
integrity?: string; | ||
/** A boolean to set request's keepalive. */ | ||
keepalive?: boolean; | ||
/** A string to indicate whether the request will use CORS, or will be restricted to same-origin URLs. Sets request's mode. */ | ||
mode?: RequestMode; | ||
/** A string indicating whether request follows redirects, results in an error upon encountering a redirect, or returns the redirect (in an opaque fashion). Sets request's redirect. */ | ||
redirect?: RequestRedirect; | ||
/** A string whose value is a same-origin URL, "about:client", or the empty string, to set request's referrer. */ | ||
referrer?: string; | ||
/** A referrer policy to set request's referrerPolicy. */ | ||
referrerPolicy?: ReferrerPolicy; | ||
/** An AbortSignal to set request's signal. */ | ||
signal?: AbortSignal | null; | ||
/** Can only be null. Used to disassociate request from any Window. */ | ||
window?: null; | ||
logger?(message: string, type: string): void; | ||
beforeEach?: <T extends Record<string, any>>(method: Method, path: string, request: RequestInit & { | ||
params?: T; | ||
data?: any; | ||
} & Partial<AdditionalOptions>) => void; | ||
}; | ||
export declare function createClient<AdditionalOptions extends Record<string, any> = never>(baseUrl: string, options?: Options<AdditionalOptions>): { | ||
options: Options<AdditionalOptions>; | ||
execute<T>(method: Method, path: string, request?: RequestOptions & Partial<AdditionalOptions>): Promise<T>; | ||
}; |
@@ -14,3 +14,3 @@ /* eslint-disable max-len */ | ||
*/ | ||
export function createClient(baseUrl, { trace, ...options } = {}) { | ||
export function createClient(baseUrl, options = {}) { | ||
const mainHeaders = options.headers ?? {}; | ||
@@ -37,3 +37,8 @@ return { | ||
if (options.logger) { | ||
options.logger(`${method} ${url} ${response.status}`, 'HTTP'); | ||
if (response.status < 400) { | ||
options.logger.info(`${method} ${url} ${response.status}`, 'HTTP'); | ||
} | ||
else { | ||
options.logger.error(`${method} ${url} ${response.status}`, 'HTTP'); | ||
} | ||
} | ||
@@ -49,5 +54,2 @@ if (contentType?.includes('application/json')) { | ||
} | ||
if (trace) { | ||
trace.info(`${method} ${url} ${response.status}`); | ||
} | ||
if (response.ok) { | ||
@@ -54,0 +56,0 @@ return contentBody; |
{ | ||
"name": "@b613/utils", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Set of utility methods for common operations", | ||
@@ -148,3 +148,4 @@ "license": "MIT", | ||
"node": ">=18.16.0" | ||
} | ||
}, | ||
"packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610" | ||
} |
@@ -30,3 +30,3 @@ /* eslint-disable max-len */ | ||
> = RequestInit & { | ||
logger?(message: string, type: string): void; | ||
logger?: Trace; | ||
beforeEach?: <T extends Record<string, any>>( | ||
@@ -76,3 +76,3 @@ method: Method, | ||
AdditionalOptions extends Record<string, any> = never | ||
>(baseUrl: string, { trace, ...options }: Options<AdditionalOptions> & { trace?: Trace; } = {}) { | ||
>(baseUrl: string, options: Options<AdditionalOptions> = {}) { | ||
const mainHeaders = options.headers ?? {}; | ||
@@ -110,3 +110,7 @@ | ||
if (options.logger) { | ||
options.logger(`${method} ${url} ${response.status}`, 'HTTP'); | ||
if (response.status < 400) { | ||
options.logger.info(`${method} ${url} ${response.status}`, 'HTTP'); | ||
} else { | ||
options.logger.error(`${method} ${url} ${response.status}`, 'HTTP'); | ||
} | ||
} | ||
@@ -122,6 +126,2 @@ | ||
if (trace) { | ||
trace.info(`${method} ${url} ${response.status}`); | ||
} | ||
if (response.ok) { | ||
@@ -128,0 +128,0 @@ return contentBody; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1
226648
4502