mirror of
https://github.com/stoatchat/javascript-client-api.git
synced 2026-07-20 20:15:34 -04:00
Start writing Typescript defns.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Attachment ID
|
||||
* @minLength 1
|
||||
* @maxLength 128
|
||||
*/
|
||||
export type AttachmentId = string;
|
||||
|
||||
export type AttachmentMetadata = (
|
||||
{ type: 'File' } |
|
||||
{ type: 'Text' } |
|
||||
{ type: 'Audio' } |
|
||||
{ type: 'Image', width: number, height: number } |
|
||||
{ type: 'Video', width: number, height: number }
|
||||
);
|
||||
|
||||
/**
|
||||
* Attachment tag
|
||||
*/
|
||||
export type AttachmentTag = 'attachments' | 'avatars' | 'backgrounds' | 'icons' | 'banners';
|
||||
|
||||
export type Attachment = {
|
||||
_id: AttachmentId
|
||||
|
||||
tag: AttachmentTag
|
||||
|
||||
/**
|
||||
* File size (in bytes)
|
||||
*/
|
||||
size: number
|
||||
|
||||
/**
|
||||
* File name
|
||||
*/
|
||||
filename: string
|
||||
|
||||
/**
|
||||
* Metadata
|
||||
*/
|
||||
metadata: AttachmentMetadata
|
||||
|
||||
/**
|
||||
* Content type
|
||||
*/
|
||||
content_type: string,
|
||||
};
|
||||
@@ -0,0 +1,212 @@
|
||||
import type { Attachment } from "./Autumn"
|
||||
import type { Id, Nonce } from "./_common"
|
||||
import type { Embed } from "./January"
|
||||
|
||||
/**
|
||||
* Last message sent in channel
|
||||
*/
|
||||
export type LastMessage = {
|
||||
/**
|
||||
* Message ID
|
||||
*/
|
||||
_id: Id
|
||||
|
||||
/**
|
||||
* Author ID
|
||||
*/
|
||||
author: Id
|
||||
|
||||
/**
|
||||
* Short content of message
|
||||
* @maxLength 128
|
||||
*/
|
||||
short: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Saved Messages channel has only one participant, the user who created it.
|
||||
*/
|
||||
export type SavedMessagesChannel = {
|
||||
/**
|
||||
* Channel Id
|
||||
*/
|
||||
_id: Id
|
||||
|
||||
channel_type: 'SavedMessages'
|
||||
|
||||
/**
|
||||
* User Id
|
||||
*/
|
||||
user: Id
|
||||
}
|
||||
|
||||
export type DirectMessageChannel = {
|
||||
/**
|
||||
* Channel Id
|
||||
*/
|
||||
_id: Id
|
||||
|
||||
channel_type: 'DirectMessage'
|
||||
|
||||
/**
|
||||
* Whether this DM is active
|
||||
*/
|
||||
active: boolean
|
||||
|
||||
/**
|
||||
* List of user IDs who are participating in this DM
|
||||
*/
|
||||
recipients: Id[]
|
||||
|
||||
last_message: LastMessage
|
||||
}
|
||||
|
||||
export type GroupChannel = {
|
||||
/**
|
||||
* Channel Id
|
||||
*/
|
||||
_id: Id,
|
||||
|
||||
channel_type: 'Group',
|
||||
|
||||
/**
|
||||
* List of user IDs who are participating in this group
|
||||
*/
|
||||
recipients: Id[],
|
||||
|
||||
/**
|
||||
* Group name
|
||||
*/
|
||||
name: string,
|
||||
|
||||
/**
|
||||
* User ID of group owner
|
||||
*/
|
||||
owner: Id,
|
||||
|
||||
/**
|
||||
* Group description
|
||||
*/
|
||||
description?: string,
|
||||
|
||||
last_message: LastMessage,
|
||||
|
||||
/**
|
||||
* Group icon
|
||||
*/
|
||||
icon?: Attachment,
|
||||
|
||||
/**
|
||||
* Permissions given to group members
|
||||
*/
|
||||
permissions?: number
|
||||
}
|
||||
|
||||
export type ServerChannel = {
|
||||
/**
|
||||
* Channel Id
|
||||
*/
|
||||
_id: Id
|
||||
|
||||
/**
|
||||
* Server Id
|
||||
*/
|
||||
server: Id
|
||||
|
||||
/**
|
||||
* Channel name
|
||||
*/
|
||||
name: string
|
||||
|
||||
/**
|
||||
* Channel description
|
||||
*/
|
||||
description: string
|
||||
|
||||
icon?: Attachment
|
||||
|
||||
/**
|
||||
* Permissions given to all users
|
||||
*/
|
||||
default_permissions?: number
|
||||
|
||||
/**
|
||||
* Permissions given to roles
|
||||
*/
|
||||
role_permissions?: {
|
||||
[key: string]: number
|
||||
}
|
||||
}
|
||||
|
||||
export type TextChannel = ServerChannel & {
|
||||
channel_type: 'TextChannel'
|
||||
|
||||
last_message: string
|
||||
}
|
||||
|
||||
export type VoiceChannel = ServerChannel & {
|
||||
channel_type: 'VoiceChannel'
|
||||
}
|
||||
|
||||
export type Channel = (SavedMessagesChannel | DirectMessageChannel | GroupChannel | TextChannel | VoiceChannel) & { nonce?: string }
|
||||
|
||||
export type Message = {
|
||||
/**
|
||||
* Message Id
|
||||
*/
|
||||
_id: Id
|
||||
|
||||
nonce?: Nonce
|
||||
|
||||
/**
|
||||
* Channel Id
|
||||
*/
|
||||
channel: Id
|
||||
|
||||
/**
|
||||
* Author Id
|
||||
*/
|
||||
author: Id
|
||||
|
||||
/**
|
||||
* Message content, can be an object *only* if sent by the system user.
|
||||
*/
|
||||
content: string | SystemMessage
|
||||
|
||||
/**
|
||||
* Message attachments
|
||||
*/
|
||||
attachments?: Attachment[]
|
||||
|
||||
/**
|
||||
* Unix timestamp of when message was last edited
|
||||
*/
|
||||
edited?: { $date: string }
|
||||
|
||||
/**
|
||||
* Message link embeds
|
||||
*/
|
||||
embeds?: Embed[]
|
||||
|
||||
/**
|
||||
* Array of user IDs mentioned in message
|
||||
*/
|
||||
mentions?: Id[]
|
||||
|
||||
/**
|
||||
* Array of message IDs replied to
|
||||
*/
|
||||
replies?: Id[]
|
||||
}
|
||||
|
||||
export type SystemMessage =
|
||||
| { type: "text"; content: string }
|
||||
| { type: "user_added"; id: Id; by: Id }
|
||||
| { type: "user_remove"; id: Id; by: Id }
|
||||
| { type: "user_joined"; id: Id }
|
||||
| { type: "user_left"; id: Id }
|
||||
| { type: "user_kicked"; id: Id }
|
||||
| { type: "user_banned"; id: Id }
|
||||
| { type: "channel_renamed"; name: string, by: Id }
|
||||
| { type: "channel_description_changed"; by: Id }
|
||||
| { type: "channel_icon_changed"; by: Id };
|
||||
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* An embedded image
|
||||
*/
|
||||
export type EmbedImage = {
|
||||
url: string
|
||||
|
||||
width: number
|
||||
|
||||
height: number
|
||||
|
||||
size: 'Large' | 'Preview'
|
||||
}
|
||||
|
||||
/**
|
||||
* An embedded video
|
||||
*/
|
||||
export type EmbedVideo = {
|
||||
url: string
|
||||
|
||||
width: number
|
||||
|
||||
height: number
|
||||
}
|
||||
|
||||
/**
|
||||
* A special 3rd party embed
|
||||
*/
|
||||
export type EmbedSpecial = (
|
||||
{ type: 'None' } |
|
||||
{ type: 'YouTube', id: string } |
|
||||
{ type: 'Twitch', content_type: 'Channel' | 'Video' | 'Clip', id: string } |
|
||||
{ type: 'Spotify', content_type: string, id: string } |
|
||||
{ type: 'Soundcloud' } |
|
||||
{ type: 'Bandcamp', content_type: 'Album' | 'Track', id: string }
|
||||
)
|
||||
|
||||
/**
|
||||
* Message embed
|
||||
*/
|
||||
export type Embed = (
|
||||
{
|
||||
type: 'None'
|
||||
} | {
|
||||
type: 'Website'
|
||||
|
||||
url?: string
|
||||
|
||||
special?: EmbedSpecial
|
||||
|
||||
title?: string
|
||||
|
||||
description?: string
|
||||
|
||||
image?: EmbedImage
|
||||
|
||||
video?: EmbedVideo
|
||||
|
||||
site_name?: string
|
||||
|
||||
icon_url?: string
|
||||
|
||||
color?: string
|
||||
} | ({
|
||||
type: 'Image'
|
||||
} & EmbedImage)
|
||||
);
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
import type { Attachment } from './Autumn';
|
||||
import type { Id } from './_common';
|
||||
|
||||
/**
|
||||
* Your relationship with the user
|
||||
*/
|
||||
export enum RelationshipStatus {
|
||||
None = "None",
|
||||
User = "User",
|
||||
Friend = "Friend",
|
||||
Outgoing = "Outgoing",
|
||||
Incoming = "Incoming",
|
||||
Blocked = "Blocked",
|
||||
BlockedOther = "BlockedOther"
|
||||
}
|
||||
|
||||
export type Relationship = {
|
||||
/**
|
||||
* Other user's ID
|
||||
*/
|
||||
_id: Id
|
||||
|
||||
status: Relationship
|
||||
};
|
||||
|
||||
/**
|
||||
* User presence
|
||||
*/
|
||||
export enum Presence {
|
||||
Online = "Online",
|
||||
Idle = "Idle",
|
||||
Busy = "Busy",
|
||||
Invisible = "Invisible"
|
||||
}
|
||||
|
||||
export type Status = {
|
||||
/**
|
||||
* Custom status text
|
||||
* @minLength 1
|
||||
* @maxLength 128
|
||||
*/
|
||||
text?: string
|
||||
|
||||
presence?: Presence
|
||||
}
|
||||
|
||||
export enum Badges {
|
||||
Developer = 1,
|
||||
Translator = 2,
|
||||
Supporter = 4,
|
||||
ResponsibleDisclosure = 8,
|
||||
RevoltTeam = 16,
|
||||
EarlyAdopter = 256,
|
||||
}
|
||||
|
||||
export interface User {
|
||||
/**
|
||||
* User ID
|
||||
*/
|
||||
_id: Id
|
||||
|
||||
/**
|
||||
* @minLength 2
|
||||
* @maxLength 32
|
||||
* @pattern ^[a-zA-Z0-9_.]+$
|
||||
*/
|
||||
username: string
|
||||
|
||||
avatar?: Attachment
|
||||
|
||||
/**
|
||||
* Relationships with other known users
|
||||
* Only present if fetching self
|
||||
*/
|
||||
relations?: Relationship[]
|
||||
|
||||
/**
|
||||
* Bitfield of user's badges
|
||||
*/
|
||||
badges?: number
|
||||
|
||||
status?: Status
|
||||
|
||||
/**
|
||||
* Relationship to user
|
||||
*/
|
||||
relationship?: Relationship
|
||||
|
||||
/**
|
||||
* Whether the user is online
|
||||
*/
|
||||
online?: boolean
|
||||
}
|
||||
|
||||
export interface Profile {
|
||||
/**
|
||||
* @minLength 0
|
||||
* @maxLength 2000
|
||||
*/
|
||||
content?: string
|
||||
|
||||
background?: Attachment
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Id
|
||||
* @pattern [0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}
|
||||
*/
|
||||
export type Id = string;
|
||||
|
||||
/**
|
||||
* Nonce value, prefer to use ULIDs here for better feature support.
|
||||
* @minLength 1
|
||||
* @maxLength 36
|
||||
*/
|
||||
export type Nonce = string;
|
||||
Reference in New Issue
Block a user