From fb3fc54331b6b786319a9041688022316cdd1a39 Mon Sep 17 00:00:00 2001 From: SoSweetHam Date: Wed, 22 May 2024 20:45:57 +0530 Subject: [PATCH] feat: add more type defs --- jsr.json | 2 +- package.json | 2 +- src/index.ts | 6 +- src/types.ts | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 171 insertions(+), 5 deletions(-) diff --git a/jsr.json b/jsr.json index ba773a1..2295d35 100644 --- a/jsr.json +++ b/jsr.json @@ -1,5 +1,5 @@ { "name": "@cardboard-ink/cardboard-js", - "version": "1.0.4", + "version": "1.0.5", "exports": "./src/index.ts" } diff --git a/package.json b/package.json index a7acac1..4cf70e2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cardboard.js", - "version": "1.0.4", + "version": "1.0.5", "description": "JS/TS Wrapper for the CardBoard API", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/index.ts b/src/index.ts index 6f5f723..0cfeff5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -56,7 +56,7 @@ export class Cardboard { grant_type, }) ); - return response.data; + return response.data as IGetToken; } /** @@ -74,7 +74,7 @@ export class Cardboard { grant_type, }) ); - return response.data; + return response.data as IGetToken; } /** @@ -139,6 +139,6 @@ export class Cardboard { const response = await this._axios.get("users/@me", { headers: { authorization: `Bearer ${access_token}` }, }); - return response.data; + return response.data as GuildedUser; } } diff --git a/src/types.ts b/src/types.ts index 1653943..32b188c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,41 +1,169 @@ +/** + * @typedef {Object} IGetToken + * @property {string} access_token + * @property {string} token_type + * @property {number} expires_in + * @property {string} refresh_token + * @property {string} scope + */ export interface IGetToken { + /** + * The access token recieved from the initial token exchange + */ access_token: string; + /** + * The type of token recieved + */ token_type: string; + /** + * The time in seconds until the token expires + */ expires_in: number; + /** + * The refresh token recieved from the initial token exchange + */ refresh_token: string; + /** + * The scope of the token + */ scope: string; } +/** + * @typedef {Object} IGetUser + * @property {string} id + * @property {string} name + * @property {string} subdomain + * @property {Alias[]} aliases + * @property {string} avatar + * @property {string} banner + * @property {UserStatus} userStatus + * @property {any} moderationStatus + * @property {AboutInfo} aboutInfo + * @property {any} userTransientStatus + */ export interface GuildedUser { + /** + * The id of the user + */ id: string + /** + * The name of the user + */ name: string + /** + * The subdomain of the user + */ subdomain?: string + /** + * The aliases of the user + */ aliases?: Alias[] + /** + * The avatar of the user + */ avatar?: string + /** + * The banner of the user + */ banner?: string + /** + * The status of the user + */ userStatus?: UserStatus + /** + * The moderation status of the user + */ moderationStatus: any + /** + * The about info of the user + */ aboutInfo?: AboutInfo + /** + * The transient status of the user + */ userTransientStatus: any } +/** + * @typedef {Object} Alias + * @property {string} alias + * @property {string} discriminator + * @property {string} name + * @property {string} createdAt + * @property {string} userId + * @property {number} gameId + * @property {string} socialLinkSource + * @property {any} additionalInfo + * @property {string} editedAt + * @property {string} socialLinkHandle + * @property {any} playerInfo + */ export interface Alias { + /** + * The alias of the user + */ alias?: string + /** + * The discriminator of the user + */ discriminator?: string + /** + * The name of the user + */ name: string + /** + * The time the alias was created + */ createdAt: string + /** + * The id of the user + */ userId: string + /** + * The game id of the user + */ gameId: number + /** + * The source of the social link + */ socialLinkSource?: string + /** + * Additional info + */ additionalInfo: any + /** + * The time the alias was edited + */ editedAt: string + /** + * The social link handle + */ socialLinkHandle?: string + /** + * Extra player info + */ playerInfo: any } +/** + * @typedef {Object} UserStatus + * @property {Content} content + * @property {number} customReactionId + * @property {CustomReaction} customReaction + */ export interface UserStatus { + /** + * ReactJS Slate Object + */ content?: Content + /** + * The custom reaction id + */ customReactionId?: number + /** + * The custom reaction object + */ customReaction?: CustomReaction } @@ -72,16 +200,54 @@ export interface Lefe { object: string } +/** + * @typedef {Object} CustomReaction + * @property {number} id + * @property {string} name + * @property {string} png + * @property {string} webp + * @property {any} apng + * @property {number} teamId + */ export interface CustomReaction { + /** + * The id of the custom reaction + */ id: number + /** + * The name of the custom reaction + */ name: string + /** + * The png of the custom reaction + */ png: string + /** + * The webp of the custom reaction + */ webp: string + /** + * The apng of the custom reaction + */ apng: any + /** + * The team id of the custom reaction + */ teamId: number } +/** + * @typedef {Object} AboutInfo + * @property {string} bio + * @property {string} tagLine + */ export interface AboutInfo { + /** + * The bio of the user + */ bio?: string + /** + * The tagline of the user + */ tagLine?: string }