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
2,127 changes: 2,127 additions & 0 deletions bun.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@amanullah/kick-api",
"version": "2.1.2",
"license": "MIT",
"exports": "./src/index.ts"
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,8 @@
"@semantic-release/npm",
"@semantic-release/github"
]
},
"dependencies": {
"vite": "^8.0.0"
}
}
17 changes: 10 additions & 7 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { KickClientConfig, OAuthAuthorizationParams, OAuthToken, OAuthTokenRequest } from "./types";
import { CategoriesModule } from "./modules/categories";
import { ChannelsModule } from "./modules/channels";
import { LivestreamsModule } from "./modules/livestreams";
import { ChatModule } from "./modules/chat";
import { KickOAuthError, createKickError, KickNetworkError } from "./errors";
import { randomBytes, createHash } from "crypto";
import { KickClientConfig, OAuthAuthorizationParams, OAuthToken, OAuthTokenRequest } from "./types.ts";
import { CategoriesModule } from "./modules/categories.ts";
import { UsersModule } from "./modules/users.ts";
import { ChannelsModule } from "./modules/channels.ts";
import { LivestreamsModule } from "./modules/livestreams.ts";
import { ChatModule } from "./modules/chat.ts";
import { KickOAuthError, createKickError, KickNetworkError } from "./errors.ts";
import { randomBytes, createHash } from "node:crypto";

export class KickClient {
private config: KickClientConfig;
private token: OAuthToken | null = null;
private tokenPromise: Promise<string> | null = null;

public readonly users: UsersModule;
public readonly categories: CategoriesModule;
public readonly channels: ChannelsModule;
public readonly livestreams: LivestreamsModule;
Expand All @@ -24,6 +26,7 @@ export class KickClient {
};

this.categories = new CategoriesModule(this);
this.users = new UsersModule(this);
this.channels = new ChannelsModule(this);
this.livestreams = new LivestreamsModule(this);
this.chat = new ChatModule(this);
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { KickClient } from "./client";
import { KickClient } from "./client.ts";

export type Client = Omit<KickClient, "request">;

export const client = KickClient as new (config: import("./types").KickClientConfig) => Client;
export const client = KickClient as new (config: import("./types.ts").KickClientConfig) => Client;

export * from "./types";
export * from "./errors";
export * from "./types.ts";
export * from "./errors.ts";
6 changes: 3 additions & 3 deletions src/modules/categories.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Category } from "../types";
import { KickBadRequestError } from "../errors";
import { KickClient } from "../client";
import type { Category } from "../types.ts";
import { KickBadRequestError } from "../errors.ts";
import type { KickClient } from "../client.ts";

export class CategoriesModule {
private readonly baseRoute = "/public/v1/categories";
Expand Down
6 changes: 3 additions & 3 deletions src/modules/channels.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Channel } from "../types";
import { KickClient } from "../client";
import { KickBadRequestError } from "../errors";
import type { Channel } from "../types.ts";
import { KickClient } from "../client.ts";
import { KickBadRequestError } from "../errors.ts";

export class ChannelsModule {
private readonly baseRoute = "/public/v1/channels";
Expand Down
6 changes: 3 additions & 3 deletions src/modules/chat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ChatMessageRequest, ChatMessageResponse } from "../types";
import { KickBadRequestError } from "../errors";
import { KickClient } from "../client";
import type { ChatMessageRequest, ChatMessageResponse } from "../types.ts";
import { KickBadRequestError } from "../errors.ts";
import { KickClient } from "../client.ts";

export class ChatModule {
private readonly baseRoute = "/public/v1/chat";
Expand Down
6 changes: 3 additions & 3 deletions src/modules/livestreams.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Livestream } from "../types";
import { KickClient } from "../client";
import { KickBadRequestError } from "../errors";
import type { Livestream } from "../types.ts";
import { KickClient } from "../client.ts";
import { KickBadRequestError } from "../errors.ts";

export class LivestreamsModule {
private readonly baseRoute = "/public/v1/livestreams";
Expand Down
38 changes: 38 additions & 0 deletions src/modules/users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { User } from "../types.ts";
import { KickClient } from "../client.ts";

export class UsersModule {
private readonly baseRoute = "/public/v1/users";

constructor(private client: KickClient) {}

/**
* Retrieve user information based on provided user IDs.
* If no user IDs are specified, the information for the
* currently authorised user will be returned by default.
*
* @param id - The ID of the user to retrieve
*
* @returns Promise that resolves to the user informations
*
* @example Get user by ID
* ```typescript
* const user = await client.users.getUser(123);
* console.log(user.username); // e.g., "john_doe"
* ```
*
* @example Get current user
* ```typescript
* const user = await client.users.getUser();
* console.log(user.username); // e.g., "john_doe"
* ```
*
* @throws {KickNotFoundError} When category with the given ID doesn't exist
* @throws {KickBadRequestError} When category ID is invalid
*
* @see https://docs.kick.com/apis/categories#get-category
*/
async getUser(id?: number): Promise<User> {
return await this.client.request<User>(id ? `${this.baseRoute}?id=${id}` : this.baseRoute);
}
}
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export interface User {
username: string;
slug: string;
bio?: string;
profile_picture: string | null;
email?: string;
country?: string;
state?: string;
city?: string;
Expand Down