Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ lib/

package-lock.json
yarn-error.log
.cursor/
2 changes: 1 addition & 1 deletion src/HttpClient/middlewares/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export const cacheMiddleware = ({ type, storage, asyncSet }: CacheOptions) => {
if (cachedEtag && validateStatus(response.status as number)) {
ctx.config.headers = {
...ctx.config.headers,
'if-none-match': cachedEtag
'if-none-match': cachedEtag,
}
ctx.config.validateStatus = validateStatus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jest.mock('../../../HttpClient/agents', () => ({
}))

describe('HttpAgentSingleton', () => {
let recordedGaugeCalls: Map<string, Array<{ value: number; attributes?: any }>>
let recordedGaugeCalls: Map<string, { value: number; attributes?: any }[]>

beforeEach(() => {
// Reset call tracking
Expand Down
2 changes: 1 addition & 1 deletion src/HttpClient/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export interface InstanceOptions {
* @memberof InstanceOptions
*/
params?: Record<string, string>
middlewares?: Array<Middleware<MiddlewareContext>>
middlewares?: Middleware<MiddlewareContext>[]
verbose?: boolean
name?: string
serverTimings?: Record<string, string>
Expand Down
216 changes: 104 additions & 112 deletions src/axios.d.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
declare module 'axios/index' {}

declare module 'axios' {
export interface AxiosTransformer {
(data: any, headers?: any): any;
}
export type AxiosTransformer = (data: any, headers?: any) => any

export interface AxiosAdapter {
(config: AxiosRequestConfig): AxiosPromise<any>;
}
export type AxiosAdapter = (config: AxiosRequestConfig) => AxiosPromise<any>

export interface AxiosBasicCredentials {
username: string;
password: string;
username: string
password: string
}

export interface AxiosProxyConfig {
host: string;
port: number;
host: string
port: number
auth?: {
username: string;
password: string;
};
protocol?: string;
}
protocol?: string
}

export type Method =
Expand All @@ -33,87 +29,87 @@ declare module 'axios' {
| 'put' | 'PUT'
| 'patch' | 'PATCH'
| 'link' | 'LINK'
| 'unlink' | 'UNLINK';
| 'unlink' | 'UNLINK'

export type ResponseType =
| 'arraybuffer'
| 'blob'
| 'document'
| 'json'
| 'text'
| 'stream';
| 'stream'

// Tipos de cabeçalho
export type RawAxiosRequestHeaders = Record<string, any>;
export type RawAxiosResponseHeaders = Record<string, any>;
export type RawAxiosRequestHeaders = Record<string, any>
export type RawAxiosResponseHeaders = Record<string, any>
export interface AxiosHeaders extends Record<string, any> {
set(headerName: string, value: string): AxiosHeaders;
get(headerName: string): string | undefined;
delete(headerName: string): boolean;
clear(): AxiosHeaders;
toJSON(): Record<string, any>;
[key: string]: any;
set(headerName: string, value: string): AxiosHeaders
get(headerName: string): string | undefined
delete(headerName: string): boolean
clear(): AxiosHeaders
toJSON(): Record<string, any>
[key: string]: any
}

export interface AxiosRequestConfig {
url?: string;
method?: Method;
baseURL?: string;
transformRequest?: AxiosTransformer | AxiosTransformer[];
transformResponse?: AxiosTransformer | AxiosTransformer[];
headers?: RawAxiosRequestHeaders;
params?: any;
paramsSerializer?: (params: any) => string;
data?: any;
timeout?: number;
timeoutErrorMessage?: string;
withCredentials?: boolean;
adapter?: AxiosAdapter;
auth?: AxiosBasicCredentials;
responseType?: ResponseType;
responseEncoding?: string;
xsrfCookieName?: string;
xsrfHeaderName?: string;
onUploadProgress?: (progressEvent: any) => void;
onDownloadProgress?: (progressEvent: any) => void;
maxContentLength?: number;
maxBodyLength?: number;
validateStatus?: (status: number) => boolean;
maxRedirects?: number;
socketPath?: string | null;
httpAgent?: any;
httpsAgent?: any;
proxy?: AxiosProxyConfig | false;
cancelToken?: CancelToken;
decompress?: boolean;
transitional?: any;
signal?: any;
insecureHTTPParser?: boolean;
[key: string]: any; // Para permitir qualquer propriedade adicional
url?: string
method?: Method
baseURL?: string
transformRequest?: AxiosTransformer | AxiosTransformer[]
transformResponse?: AxiosTransformer | AxiosTransformer[]
headers?: RawAxiosRequestHeaders
params?: any
paramsSerializer?: (params: any) => string
data?: any
timeout?: number
timeoutErrorMessage?: string
withCredentials?: boolean
adapter?: AxiosAdapter
auth?: AxiosBasicCredentials
responseType?: ResponseType
responseEncoding?: string
xsrfCookieName?: string
xsrfHeaderName?: string
onUploadProgress?: (progressEvent: any) => void
onDownloadProgress?: (progressEvent: any) => void
maxContentLength?: number
maxBodyLength?: number
validateStatus?: (status: number) => boolean
maxRedirects?: number
socketPath?: string | null
httpAgent?: any
httpsAgent?: any
proxy?: AxiosProxyConfig | false
cancelToken?: CancelToken
decompress?: boolean
transitional?: any
signal?: any
insecureHTTPParser?: boolean
[key: string]: any // Para permitir qualquer propriedade adicional
}

export interface InternalAxiosRequestConfig extends AxiosRequestConfig {
headers: AxiosHeaders | RawAxiosRequestHeaders;
[key: string]: any; // Para permitir propriedades adicionais como 'tracing'
headers: AxiosHeaders | RawAxiosRequestHeaders
[key: string]: any // Para permitir propriedades adicionais como 'tracing'
}

export interface AxiosResponse<T = any> {
data: T;
status: number;
statusText: string;
headers: RawAxiosResponseHeaders;
config: AxiosRequestConfig;
request?: any;
data: T
status: number
statusText: string
headers: RawAxiosResponseHeaders
config: AxiosRequestConfig
request?: any
}

// Define AxiosError como uma classe para fazer instanceof funcionar
export class AxiosError<T = any> extends Error {
config: AxiosRequestConfig;
code?: string;
request?: any;
response?: AxiosResponse<T>;
isAxiosError: boolean;
status?: number;
config: AxiosRequestConfig
code?: string
request?: any
response?: AxiosResponse<T>
isAxiosError: boolean
status?: number

constructor(
message?: string,
Expand All @@ -123,7 +119,7 @@ declare module 'axios' {
response?: AxiosResponse<T>
);

toJSON(): object;
toJSON(): object

// Métodos estáticos para criar instâncias de AxiosError
static from<T = any>(
Expand All @@ -133,76 +129,72 @@ declare module 'axios' {
request?: any,
response?: AxiosResponse<T>,
customProps?: Record<string, any>
): AxiosError<T>;
): AxiosError<T>
}

export interface AxiosPromise<T = any> extends Promise<AxiosResponse<T>> {
}

export interface CancelStatic {
new (message?: string): Cancel;
}
export type CancelStatic = new (message?: string) => Cancel

export interface Cancel {
message: string;
message: string
}

export interface Canceler {
(message?: string): void;
}
export type Canceler = (message?: string) => void

export interface CancelTokenStatic {
new (executor: (cancel: Canceler) => void): CancelToken;
source(): CancelTokenSource;
new (executor: (cancel: Canceler) => void): CancelToken
source(): CancelTokenSource
}

export interface CancelToken {
promise: Promise<Cancel>;
reason?: Cancel;
throwIfRequested(): void;
promise: Promise<Cancel>
reason?: Cancel
throwIfRequested(): void
}

export interface CancelTokenSource {
token: CancelToken;
cancel: Canceler;
token: CancelToken
cancel: Canceler
}

export interface AxiosInterceptorManager<V> {
use(onFulfilled?: (value: V) => V | Promise<V>, onRejected?: (error: any) => any): number;
eject(id: number): void;
clear(): void;
use(onFulfilled?: (value: V) => V | Promise<V>, onRejected?: (error: any) => any): number
eject(id: number): void
clear(): void
}

export interface AxiosInstance {
(config: AxiosRequestConfig): AxiosPromise;
(url: string, config?: AxiosRequestConfig): AxiosPromise;
defaults: AxiosRequestConfig;
(config: AxiosRequestConfig): AxiosPromise
(url: string, config?: AxiosRequestConfig): AxiosPromise
defaults: AxiosRequestConfig
interceptors: {
request: AxiosInterceptorManager<AxiosRequestConfig>;
response: AxiosInterceptorManager<AxiosResponse>;
};
getUri(config?: AxiosRequestConfig): string;
request<T = any, R = AxiosResponse<T>>(config: AxiosRequestConfig): Promise<R>;
get<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
delete<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
head<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
options<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
post<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
put<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
patch<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
}
getUri(config?: AxiosRequestConfig): string
request<T = any, R = AxiosResponse<T>>(config: AxiosRequestConfig): Promise<R>
get<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>
delete<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>
head<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>
options<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>
post<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>
put<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>
patch<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>
}

export interface AxiosStatic extends AxiosInstance {
create(config?: AxiosRequestConfig): AxiosInstance;
Cancel: CancelStatic;
CancelToken: CancelTokenStatic;
isCancel(value: any): boolean;
all<T>(values: (T | Promise<T>)[]): Promise<T[]>;
spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
isAxiosError(payload: any): payload is AxiosError;
create(config?: AxiosRequestConfig): AxiosInstance
Cancel: CancelStatic
CancelToken: CancelTokenStatic
isCancel(value: any): boolean
all<T>(values: (T | Promise<T>)[]): Promise<T[]>
spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R
isAxiosError(payload: any): payload is AxiosError
}

const axios: AxiosStatic;
const axios: AxiosStatic

export const AxiosError: {
new <T = any>(
Expand Down Expand Up @@ -231,7 +223,7 @@ declare module 'axios' {
response?: AxiosResponse<T>,
customProps?: Record<string, any>
): AxiosError<T>;
};
}

export default axios;
export default axios
}
2 changes: 1 addition & 1 deletion src/caches/MultilayeredCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class MultilayeredCache <K, V> implements CacheLayer<K, V>{
private hits = 0
private total = 0

constructor (private caches: Array<CacheLayer<K, V>>) {}
constructor (private caches: CacheLayer<K, V>[]) {}

public get = async (key: K, fetcher?: () => Promise<FetchResult<V>>): Promise<V | void> => {
let value: V | void = undefined
Expand Down
6 changes: 3 additions & 3 deletions src/clients/apps/MessagesGraphQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IOContext } from '../../service/worker/runtime/typings'
import { AppGraphQLClient } from './AppGraphQLClient'

export interface IndexedByFrom {
messages: Array<Omit<Message, 'from'>>
messages: Omit<Message, 'from'>[]
from: string
}

Expand Down Expand Up @@ -82,9 +82,9 @@ export class MessagesGraphQL extends AppGraphQLClient {
public translateV2 (args: TranslateInput, tracingConfig?: RequestTracingConfig) {
const { indexedByFrom, ...rest } = args

const allMessages: Array<{from: string, message: Omit<Message, 'from'>}> = indexedByFrom.reduce((acc, {from, messages}) => {
const allMessages: {from: string, message: Omit<Message, 'from'>}[] = indexedByFrom.reduce((acc, {from, messages}) => {
return acc.concat(messages.map(message => ({from, message})))
}, [] as Array<{from: string, message: Omit<Message, 'from'>}>)
}, [] as {from: string, message: Omit<Message, 'from'>}[])

const batchedMessages = splitEvery(MAX_BATCH_SIZE, allMessages)
const metric = 'messages-translate-v2'
Expand Down
2 changes: 1 addition & 1 deletion src/clients/apps/catalogGraphQL/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ export interface Product {
supplierId?: string
showWithoutStock: boolean
score?: number
salesChannel?: Array<{ id: string }>
salesChannel?: { id: string }[]
}
Loading