Skip to content
This repository has been archived by the owner on Oct 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from WerdoxDev/release-0.3
Browse files Browse the repository at this point in the history
release 0.3
  • Loading branch information
WerdoxDev authored Jul 10, 2024
2 parents eb29f17 + dbffdce commit ea0a8b1
Show file tree
Hide file tree
Showing 59 changed files with 1,268 additions and 784 deletions.
457 changes: 0 additions & 457 deletions .eslintrc.json

This file was deleted.

5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tabWidth": 3,
"useTabs": false,
"printWidth": 135
}
Binary file modified bun.lockb
100755 → 100644
Binary file not shown.
34 changes: 34 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";

export default [
{ files: ["**/*.{js,mjs,cjs,ts}"] },
{ languageOptions: { globals: globals.browser } },
pluginJs.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
{
languageOptions: { parserOptions: { project: "tsconfig.json" } },
rules: {
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/no-unnecessary-type-assertion": "off",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-redundant-type-constituents": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
varsIgnorePattern: "^_[A-Za-z0-9]+$",
argsIgnorePattern: "^_[A-Za-z0-9]+$",
},
],
},
},
];
38 changes: 20 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
{
"name": "huginn-api",
"module": "index.ts",
"type": "module",
"scripts": {
"start": "bun --watch ./src/index.ts"
},
"devDependencies": {
"bun-types": "latest",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"eslint": "^8.52.0"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"jose": "^5.1.0"
}
"name": "huginn-api",
"module": "index.ts",
"type": "module",
"scripts": {
"start": "bun --watch ./src/index.ts"
},
"devDependencies": {
"@eslint/js": "^9.6.0",
"@types/bun": "^1.1.6",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"eslint": "^9.6.0",
"globals": "^15.7.0",
"typescript": "^5.5.3",
"typescript-eslint": "^7.15.0"
},
"dependencies": {
"eventemitter3": "^5.0.1",
"jose": "^5.6.2"
}
}
7 changes: 0 additions & 7 deletions src/account/account-api.ts

This file was deleted.

22 changes: 0 additions & 22 deletions src/account/account-delete-api.ts

This file was deleted.

26 changes: 0 additions & 26 deletions src/account/account-edit-api.ts

This file was deleted.

22 changes: 0 additions & 22 deletions src/account/account-get-user-api.ts

This file was deleted.

24 changes: 0 additions & 24 deletions src/account/account-login-api.ts

This file was deleted.

24 changes: 0 additions & 24 deletions src/account/account-register-api.ts

This file was deleted.

10 changes: 7 additions & 3 deletions src/user/auth-api.ts → src/apis/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ export class AuthAPI {
this.rest = rest;
}

public async login(body: APIPostLoginJSONBody) {
public async login(body: APIPostLoginJSONBody): Promise<APIPostLoginResult> {
return this.rest.post(Routes.login(), { body }) as Promise<APIPostLoginResult>;
}

public async register(body: APIPostRegisterJSONBody) {
public async register(body: APIPostRegisterJSONBody): Promise<APIPostRegisterResult> {
return this.rest.post(Routes.register(), { body }) as Promise<APIPostRegisterResult>;
}

public async refreshToken(body: APIPostRefreshTokenJSONBody) {
public async logout(): Promise<unknown> {
return this.rest.post(Routes.logout(), { auth: true });
}

public async refreshToken(body: APIPostRefreshTokenJSONBody): Promise<APIPostRefreshTokenResult> {
return this.rest.post(Routes.refreshToken(), { body }) as Promise<APIPostRefreshTokenResult>;
}
}
57 changes: 57 additions & 0 deletions src/apis/channel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {
APIDeleteDMChannelResult,
APIGetChannelByIdResult,
APIGetChannelMessagesResult,
APIGetMessageByIdResult,
APIGetUserChannelsResult,
APIPostDMChannelJSONBody,
APIPostDMChannelResult,
APIPostDefaultMessageJSONBody,
APIPostDefaultMessageResult,
} from "@shared/api-types";
import { Routes } from "@shared/routes";
import { Snowflake } from "@shared/snowflake";
import { REST } from "../rest/rest";

export class ChannelAPI {
private readonly rest: REST;

public constructor(rest: REST) {
this.rest = rest;
}

public async get(channelId: Snowflake): Promise<APIGetChannelByIdResult> {
return this.rest.get(Routes.channel(channelId), { auth: true }) as Promise<APIGetChannelByIdResult>;
}

public async getAll(): Promise<APIGetUserChannelsResult> {
return this.rest.get(Routes.userChannels(), { auth: true }) as Promise<APIGetUserChannelsResult>;
}

public async getMessage(channelId: Snowflake, messageId: Snowflake): Promise<APIGetMessageByIdResult> {
return this.rest.get(Routes.channelMessage(channelId, messageId), { auth: true }) as Promise<APIGetMessageByIdResult>;
}

public async getMessages(channelId: Snowflake, limit?: number): Promise<APIGetChannelMessagesResult> {
return this.rest.get(Routes.channelMessages(channelId), {
auth: true,
query: new URLSearchParams({ limit: limit?.toString() ?? "" }),
}) as Promise<APIGetChannelMessagesResult>;
}

public async createDM(body: APIPostDMChannelJSONBody): Promise<APIPostDMChannelResult> {
return this.rest.post(Routes.userChannels(), { body, auth: true }) as Promise<APIPostDMChannelResult>;
}

public async deleteDM(channelId: Snowflake): Promise<APIDeleteDMChannelResult> {
return this.rest.delete(Routes.channel(channelId), { auth: true }) as Promise<APIDeleteDMChannelResult>;
}

public async createMessage(channelId: Snowflake, body: APIPostDefaultMessageJSONBody): Promise<APIPostDefaultMessageResult> {
return this.rest.post(Routes.channelMessages(channelId), { body, auth: true }) as Promise<APIPostDefaultMessageResult>;
}

// public async typing(channelId: Snowflake) {
// return this.rest.post(Routes.channelTyping(channelId), { auth: true });
// }
}
2 changes: 1 addition & 1 deletion src/user/common-api.ts → src/apis/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class CommonAPI {
this.rest = rest;
}

public async uniqueUsername(body: APIPostUniqueUsernameJSONBody) {
public async uniqueUsername(body: APIPostUniqueUsernameJSONBody): Promise<APIPostUniqueUsernameResult> {
return this.rest.post(Routes.uniqueUsername(), { body }) as Promise<APIPostUniqueUsernameResult>;
}
}
32 changes: 32 additions & 0 deletions src/apis/relationship.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { APIGetUserRelationshipByIdResult, APIGetUserRelationshipsResult, APIPostRelationshipJSONBody } from "@shared/api-types";
import { Routes } from "@shared/routes";
import { Snowflake } from "@shared/snowflake";
import { REST } from "../rest/rest";

export class RelationshipAPI {
private readonly rest: REST;

public constructor(rest: REST) {
this.rest = rest;
}

public async get(userId: Snowflake): Promise<APIGetUserRelationshipByIdResult> {
return this.rest.get(Routes.userRelationship(userId), { auth: true }) as Promise<APIGetUserRelationshipByIdResult>;
}

public async getAll(): Promise<APIGetUserRelationshipsResult> {
return this.rest.get(Routes.userRelationships(), { auth: true }) as Promise<APIGetUserRelationshipsResult>;
}

public async createRelationship(body: APIPostRelationshipJSONBody): Promise<unknown> {
return this.rest.post(Routes.userRelationships(), { body, auth: true });
}

public async createRelationshipByUserId(userId: Snowflake): Promise<unknown> {
return this.rest.put(Routes.userRelationship(userId), { auth: true });
}

public async delete(userId: Snowflake): Promise<unknown> {
return this.rest.delete(Routes.userRelationship(userId), { auth: true });
}
}
17 changes: 6 additions & 11 deletions src/user/users-api.ts → src/apis/user.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { Snowflake } from "@shared/types";
import { REST } from "../rest/rest";
import { APIGetCurrentUserResult, APIGetUserResult, APIPatchCurrentUserJSONBody, APIPatchCurrentUserResult } from "@shared/api-types";
import { Routes } from "@shared/routes";
import {
APIGetCurrentUserResult,
APIGetUserResult,
APIPatchCurrentUserJSONBody,
APIPatchCurrentUserResult,
} from "@shared/api-types";
import { Snowflake } from "@shared/snowflake";
import { REST } from "../rest/rest";

export class UserAPI {
private readonly rest: REST;
Expand All @@ -15,15 +10,15 @@ export class UserAPI {
this.rest = rest;
}

public async get(userId: Snowflake) {
public async get(userId: Snowflake): Promise<APIGetUserResult> {
return this.rest.get(Routes.user(userId), { auth: true }) as Promise<APIGetUserResult>;
}

public async getCurrent() {
public async getCurrent(): Promise<APIGetCurrentUserResult> {
return this.rest.get(Routes.user("@me"), { auth: true }) as Promise<APIGetCurrentUserResult>;
}

public async edit(body: APIPatchCurrentUserJSONBody) {
public async edit(body: APIPatchCurrentUserJSONBody): Promise<APIPatchCurrentUserResult> {
return this.rest.patch(Routes.user("@me"), { body, auth: true }) as Promise<APIPatchCurrentUserResult>;
}
}
Loading

0 comments on commit ea0a8b1

Please sign in to comment.