UNPKG

@stadium-ws/core

Version:

Build scalable realtime applications.

194 lines (189 loc) 5.02 kB
interface EventUser { id: string; displayName: string; userRoleId: string; meta: any; } interface EventAttachment { id: string; mimeType: string; fileName: string; url: string; description: string; size: number; } interface EventReaction { id: string; type: string; score: number; meta: any; user: EventUser; createdAt: string; } interface Event { id: string; type: number; channelId: string; user: EventUser; content?: string; attachments: EventAttachment[]; reactions: EventReaction[]; createdAt: string; updatedAt: string; meta: any; } interface UserRole { id: string; name: string; description: string; permissions: string[]; createdAt: string; updatedAt: string; meta: any; } interface User { id: string; displayName?: string; userRole: UserRole; userRoleId: string; createdAt: string; updatedAt: string; meta: any; } declare enum ChannelType { PUBLIC = "PUBLIC", PRIVATE = "PRIVATE", DIRECT = "DIRECT" } interface ChannelUser { id: string; displayName?: string; userRoleId: string; meta: any; } interface Channel { id: string; name: string; type: ChannelType; meta: any; onlineUserCount: number; userCount: number; eventCount: number; appId: string; creator: ChannelUser; createdAt: string; updatedAt: string; } interface Pagination { next?: number; } declare enum SortDirection { ASC = "asc", DESC = "desc" } interface CursorPagination { from?: number; limit?: number; direction?: SortDirection; } interface QueryGetChannelEvents extends CursorPagination { type?: number; } interface ReplyGetChannelEvents { events: Event[]; pagination: Pagination; } interface QueryGetUserRoles extends CursorPagination { } interface ReplyGetUserRoles { userRoles: UserRole[]; pagination: Pagination; } interface QueryGetUsers extends CursorPagination { } interface ReplyGetUsers { users: User[]; pagination: Pagination; } interface QueryGetChannels extends CursorPagination { } interface ReplyGetChannels { channels: Channel[]; pagination: Pagination; } interface ReplyGetChannelUsers { users: ChannelUser[]; pagination: Pagination; } interface CreateEvent { type: number; channelId: string; content?: string; userId?: string; meta?: any; attachments?: EventAttachment[]; } interface UpdateUser { displayName?: string; /** * The id of the user role, a user can't update his own user role. */ userRoleId?: string; isOnline?: boolean; meta?: any; } type EventName = 'eventCreate' | 'eventDelete' | 'eventUpdate' | 'eventReactionCreate' | 'eventReactionDelete' | 'channelUpdate' | 'channelUserAdded'; /** * TODO: * - Add socket authentication (which is required!) * - createUser * - addUserToChannel * - updateChannel * - onEvent? * - onChannelEvent? * - getChannelMessages * - getChannel * - createChannelEvent * - onNotification? * - registerUserDevice? for push notifications */ interface IStadiumConfig { clientId?: string; clientSecret?: string; apiUrl?: string; gatewayUrl?: string; } declare class Stadium { private apiUrl; private gatewayUrl; private readonly config; private requester; private accessToken?; private connection?; private emitter?; constructor(config?: IStadiumConfig); on(event: EventName, listener: (...args: any[]) => void): void; once(event: EventName, listener: (...args: any[]) => void): void; off(event: EventName, listener: (...args: any[]) => void): void; removeAllListeners(): void; createUser({ userRoleId, displayName, meta }: { userRoleId?: string; displayName?: string; meta?: any; }): Promise<User>; setUserToken(token: string): void; getMe(): Promise<User>; getChannel(channelId: string): Promise<Channel>; getChannelUsers(channelId: string): Promise<ReplyGetChannelUsers>; createEvent(options: CreateEvent): Promise<Event>; getChannelEvents(channelId: string, options: QueryGetChannelEvents): Promise<ReplyGetChannelEvents>; getUserRoles(options: QueryGetUserRoles): Promise<ReplyGetUserRoles>; getUsers(options: QueryGetUsers): Promise<ReplyGetUsers>; getChannels(options: QueryGetChannels): Promise<ReplyGetChannels>; private ensureAccessToken; updateUser: (userId: string, options: UpdateUser) => Promise<User>; private onEvent; connect(): Promise<void>; disconnect(): Promise<void>; } export { Channel, ChannelType, ChannelUser, CreateEvent, CursorPagination, Event, EventAttachment, EventReaction, EventUser, Pagination, QueryGetChannelEvents, QueryGetChannels, QueryGetUserRoles, QueryGetUsers, ReplyGetChannelEvents, ReplyGetChannelUsers, ReplyGetChannels, ReplyGetUserRoles, ReplyGetUsers, SortDirection, Stadium, UpdateUser, User, UserRole };