Migrated ShlinkApiClient from axios to fetch

This commit is contained in:
Alejandro Celaya
2022-11-14 23:06:06 +01:00
parent 16bee43f12
commit e5afe4f767
5 changed files with 111 additions and 144 deletions

View File

@@ -20,6 +20,7 @@ import {
import { orderToString } from '../../utils/helpers/ordering';
import { isRegularNotFound, parseApiError } from '../utils';
import { stringifyQuery } from '../../utils/helpers/query';
import { Fetch } from '../../utils/types';
const buildShlinkBaseUrl = (url: string, version: 2 | 3) => `${url}/rest/v${version}`;
const rejectNilProps = reject(isNil);
@@ -33,7 +34,7 @@ export class ShlinkApiClient {
private apiVersion: 2 | 3;
public constructor(
private readonly fetch: typeof window.fetch,
private readonly fetch: Fetch,
private readonly baseUrl: string,
private readonly apiKey: string,
) {

View File

@@ -1,6 +1,7 @@
import { hasServerData, ServerWithId } from '../../servers/data';
import { GetState } from '../../container/types';
import { ShlinkApiClient } from './ShlinkApiClient';
import { Fetch } from '../../utils/types';
const apiClients: Record<string, ShlinkApiClient> = {};
@@ -15,7 +16,7 @@ const getSelectedServerFromState = (getState: GetState): ServerWithId => {
return selectedServer;
};
export const buildShlinkApiClient = (fetch: typeof window.fetch) => (getStateOrSelectedServer: GetState | ServerWithId) => {
export const buildShlinkApiClient = (fetch: Fetch) => (getStateOrSelectedServer: GetState | ServerWithId) => {
const { url, apiKey } = isGetState(getStateOrSelectedServer)
? getSelectedServerFromState(getStateOrSelectedServer)
: getStateOrSelectedServer;

View File

@@ -1 +1,3 @@
export type MediaMatcher = (query: string) => MediaQueryList;
export type Fetch = typeof window.fetch;