Skip to content

Commit

Permalink
feat: add more type defs
Browse files Browse the repository at this point in the history
  • Loading branch information
sosweetham committed May 22, 2024
1 parent 427cc81 commit fb3fc54
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 5 deletions.
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@cardboard-ink/cardboard-js",
"version": "1.0.4",
"version": "1.0.5",
"exports": "./src/index.ts"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class Cardboard {
grant_type,
})
);
return response.data;
return response.data as IGetToken;
}

/**
Expand All @@ -74,7 +74,7 @@ export class Cardboard {
grant_type,
})
);
return response.data;
return response.data as IGetToken;
}

/**
Expand Down Expand Up @@ -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;
}
}
166 changes: 166 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -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
}

Expand Down Expand Up @@ -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
}

0 comments on commit fb3fc54

Please sign in to comment.