This commit is contained in:
Carl-Gerhard Lindesvärd
2023-11-04 22:03:22 +01:00
parent 3431958c79
commit ce26b24c1b
2 changed files with 7 additions and 4 deletions

View File

@@ -4,7 +4,7 @@ import type {
ProfilePayload, ProfilePayload,
} from '@mixan/types'; } from '@mixan/types';
interface NewMixanOptions { export interface NewMixanOptions {
url: string; url: string;
clientId: string; clientId: string;
clientSecret: string; clientSecret: string;
@@ -16,7 +16,7 @@ interface NewMixanOptions {
getProfileId: () => string | null; getProfileId: () => string | null;
removeProfileId: () => void; removeProfileId: () => void;
} }
type MixanOptions = Required<NewMixanOptions>; export type MixanOptions = Required<NewMixanOptions>;
class Fetcher { class Fetcher {
private url: string; private url: string;
@@ -38,6 +38,8 @@ class Fetcher {
): Promise<PostResponse | null> { ): Promise<PostResponse | null> {
const url = `${this.url}${path}`; const url = `${this.url}${path}`;
this.logger(`Mixan request: ${url}`, JSON.stringify(data, null, 2)); this.logger(`Mixan request: ${url}`, JSON.stringify(data, null, 2));
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
return fetch(url, { return fetch(url, {
headers: { headers: {
['mixan-client-id']: this.clientId, ['mixan-client-id']: this.clientId,
@@ -46,6 +48,7 @@ class Fetcher {
}, },
method: 'POST', method: 'POST',
body: JSON.stringify(data ?? {}), body: JSON.stringify(data ?? {}),
keepalive: true,
...(options ?? {}), ...(options ?? {}),
}) })
.then(async (res) => { .then(async (res) => {
@@ -82,7 +85,7 @@ class Fetcher {
class Batcher<T> { class Batcher<T> {
queue: T[] = []; queue: T[] = [];
timer?: NodeJS.Timeout; timer?: ReturnType<typeof setTimeout>;
callback: (queue: T[]) => void; callback: (queue: T[]) => void;
maxBatchSize: number; maxBatchSize: number;
batchInterval: number; batchInterval: number;

View File

@@ -1,6 +1,6 @@
{ {
"compilerOptions": { "compilerOptions": {
"lib": ["ESNext"], "lib": ["ESNext", "DOM", "DOM.Iterable"],
"module": "esnext", "module": "esnext",
"target": "esnext", "target": "esnext",
"moduleResolution": "bundler", "moduleResolution": "bundler",