Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobgoerke committed Sep 22, 2024
1 parent b48ff7c commit 28f66f3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
{
"name": "@jakobgoerke/ac-infinity-client",
"version": "0.1.0",
"main": "src/index.ts",
"main": "./build/src",
"types": "./build/src/index.d.ts",
"repository": "git@github.com:jakobgoerke/ac-infinity-client.git",
"author": "revdev <mail@revdev.me>",
"license": "GPL-3.0-or-later",
"dependencies": {
"axios": "1.7.7",
"zod": "3.23.8"
},
"files": [
"build/package.json",
"build/src/**"
],
"devDependencies": {
"@jest/globals": "29.7.0",
"@tsconfig/node22": "22.0.0",
Expand Down
17 changes: 9 additions & 8 deletions src/AcInfinityClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios, { type HttpStatusCode, type AxiosInstance } from 'axios';
import axios, { type AxiosInstance } from 'axios';

import {
Controller,
Expand All @@ -24,7 +24,7 @@ export interface Response<T> {
}

export interface AuthParams {
username: string;
email: string;
password: string;
}

Expand All @@ -35,30 +35,31 @@ export interface GetDeviceParams {

class AcInfinityClientInstance {
constructor(args: AuthParams) {
const { username, password } = args;
const { email, password } = args;

this.username = username;
this.email = email;
this.password = password;

this.token = '';

this.api = axios.create({
timeout: 5000,
baseURL: 'http://www.acinfinityserver.com/api',
headers: {
'Content-Type': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
},
});
}

private api: AxiosInstance;
private token: string;
private username: string;
private email: string;
private password: string;

public async authenticate(): Promise<User> {
const response = await this.api.post<Response<User>>(Url.AUTH, {
username: this.username,
password: this.password,
appEmail: this.email,
appPasswordl: this.password,
});

const user = UserSchema.parse(response.data.data);
Expand Down
7 changes: 5 additions & 2 deletions tests/AcInfinityClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import mockAxios from './__mocks__/axios';

describe('AcInfintyClient', () => {
const authparams: AuthParams = {
username: 'test',
email: 'test',
password: 'test',
};

Expand All @@ -22,7 +22,10 @@ describe('AcInfintyClient', () => {
await AcInfinityClient.build(authparams);

// then
expect(mockAxios.post).toHaveBeenCalledWith(Url.AUTH, authparams);
expect(mockAxios.post).toHaveBeenCalledWith(Url.AUTH, {
appEmail: authparams.email,
appPasswordl: authparams.password,
});
expect(mockAxios.defaults.headers.common['token']).toBe(response.appId);
});

Expand Down
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"compilerOptions": {
"outDir": "build",
"resolveJsonModule": true,
"esModuleInterop": true
"esModuleInterop": true,
"declarationMap": true,
"declaration": true
}
}

0 comments on commit 28f66f3

Please sign in to comment.