Skip to content
Open
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
7 changes: 4 additions & 3 deletions packages/api/src/EmbeddedChatApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ import {
RocketChatAuth,
ApiError,
} from "@embeddedchat/auth";
import { Message, ActionData, UiInteractionData } from "./types";

// mutliple typing status can come at the same time they should be processed in order.
let typingHandlerLock = 0;
export default class EmbeddedChatApi {
host: string;
rid: string;
rcClient: Rocketchat;
onMessageCallbacks: ((message: any) => void)[];
onMessageCallbacks: ((message: Message) => void)[];
onMessageDeleteCallbacks: ((messageId: string) => void)[];
onTypingStatusCallbacks: ((users: string[]) => void)[];
onActionTriggeredCallbacks: ((data: any) => void)[];
onUiInteractionCallbacks: ((data: any) => void)[];
onActionTriggeredCallbacks: ((data: ActionData) => void)[];
onUiInteractionCallbacks: ((data: UiInteractionData) => void)[];
typingUsers: string[];
auth: RocketChatAuth;

Expand Down
10 changes: 5 additions & 5 deletions packages/api/src/cloneArray.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Deep Cloning upto 2 levels
* @param {*} array
* @returns
* Deep Cloning up to 2 levels
* @param array - Array to clone
* @returns Cloned array
*/
const cloneArray = (array: any[]) => {
const cloneArray = <T extends Record<string, unknown>>(array: T[]): T[] => {
const newArray = [...array].map((item) =>
typeof item === "object" ? { ...item } : item
typeof item === "object" && item !== null ? ({ ...item } as T) : item
);
return newArray;
};
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as EmbeddedChatApi } from "./EmbeddedChatApi";
export * from "./types";
59 changes: 59 additions & 0 deletions packages/api/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Type definitions for EmbeddedChat API
* Issue #1265: Replace 'any' types with proper TypeScript types
*/

export interface User {
_id: string;
username: string;
name?: string;
status?: string;
statusText?: string;
avatarETag?: string;
}

export interface MessageUser {
_id: string;
username: string;
name?: string;
}

export interface Attachment {
title?: string;
description?: string;
title_link?: string;
image_url?: string;
audio_url?: string;
video_url?: string;
type?: string;
[key: string]: unknown;
}

export interface Message {
_id: string;
rid: string;
msg: string;
ts: Date | string;
u: MessageUser;
attachments?: Attachment[];
mentions?: MessageUser[];
channels?: string[];
editedBy?: MessageUser;
editedAt?: Date | string;
[key: string]: unknown; // Allow additional fields from RocketChat
}

export interface ActionData {
actionId: string;
value?: string;
blockId?: string;
appId?: string;
[key: string]: unknown;
}

export interface UiInteractionData {
type: string;
triggerId?: string;
payload?: unknown;
[key: string]: unknown;
}
4 changes: 2 additions & 2 deletions packages/auth/src/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export class ApiError extends Error {
response: Response,
message?: string | undefined,
options?: ErrorOptions | undefined,
...other: any[]
...other: unknown[]
) {
super(message, options, ...(other as []));
this.response = response;
Expand All @@ -30,7 +30,7 @@ export class Api {
async request(
method: string = "GET",
endpoint: string,
data: any,
data: unknown,
config: RequestInit
) {
const url = new URL(endpoint, this.baseUrl).toString();
Expand Down
6 changes: 4 additions & 2 deletions packages/auth/src/RocketChatAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { IRocketChatAuthOptions } from "./IRocketChatAuthOptions";
import { Api, ApiError } from "./Api";
import loginWithRocketChatOAuth from "./loginWithRocketChatOAuth";
import handleSecureLogin from "./handleSecureLogin";
import { CurrentUser } from "./types";

class RocketChatAuth {
host: string;
api: Api;
currentUser: any;
currentUser: CurrentUser | null;
lastFetched: Date;
authListeners: ((user: object | null) => void)[] = [];
authListeners: ((user: CurrentUser | null) => void)[] = [];
deleteToken: () => Promise<void>;
saveToken: (token: string) => Promise<void>;
getToken: () => Promise<string>;
Expand Down
1 change: 1 addition & 0 deletions packages/auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from "./auth";
export { default as RocketChatAuth } from "./RocketChatAuth";
export * from "./IRocketChatAuthOptions";
export { ApiError } from "./Api";
export * from "./types";
23 changes: 23 additions & 0 deletions packages/auth/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Type definitions for RocketChat Authentication
* Issue #1265: Replace 'any' types with proper TypeScript types
*/

export interface AuthToken {
authToken: string;
userId: string;
}

export interface CurrentUser {
_id: string;
username: string;
name?: string;
status?: string;
statusConnection?: string;
utcOffset?: number;
active?: boolean;
roles?: string[];
emails?: Array<{ address: string; verified: boolean }>;
authToken?: string;
[key: string]: unknown; // Allow additional fields
}
19 changes: 15 additions & 4 deletions packages/rc-app/lib/getCallbackContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,26 @@ interface ICredentials {
serviceName: string;
}

interface CallbackConfig {
success: boolean;
error?: string;
origin?: string;
credentials?: {
accessToken: string;
expiresIn: number;
serviceName: string;
};
}

export const getCallbackContent = async (
read: IRead,
credentials: ICredentials | null,
origin: string,
error
error?: string
) => {
const { accessToken, expiresIn = 3600, serviceName } = credentials || {};
const isAllowed = await isAllowedOrigin(read, origin);
let config: any = {};
let config: CallbackConfig;
if (error) {
config = {
success: false,
Expand All @@ -31,9 +42,9 @@ export const getCallbackContent = async (
success: true,
origin,
credentials: {
accessToken,
accessToken: accessToken!,
expiresIn,
serviceName,
serviceName: serviceName!,
},
};
}
Expand Down