Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BREAK] API updates #569

Draft
wants to merge 13 commits into
base: alpha
Choose a base branch
from
12 changes: 0 additions & 12 deletions src/definition/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,6 @@ export abstract class App implements IApp {
return this.info.nameSlug;
}

/**
* Gets the username of this App's app user.
*
* @return {string} the username of the app user
*
* @deprecated This method will be removed in the next major version.
* Please use read.getUserReader().getAppUser() instead.
*/
public getAppUserUsername(): string {
return `${ this.info.nameSlug }.bot`;
}

/**
* Get the ID of this App, please see <link> for how to obtain an ID for your App.
*
Expand Down
10 changes: 0 additions & 10 deletions src/definition/IApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ export interface IApp {
*/
getNameSlug(): string;

/**
* Gets the username of this App's app user.
*
* @return {string} the username of the app user
*
* @deprecated This method will be removed in the next major version.
* Please use read.getAppUser instead.
*/
getAppUserUsername(): string;

/**
* Get the ID of this App, please see <link> for how to obtain an ID for your App.
*
Expand Down
14 changes: 1 addition & 13 deletions src/definition/accessors/ILivechatRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,10 @@ export interface ILivechatRead {
/**
* Gets online status of the livechat.
* @param departmentId (optional) the id of the livechat department
* @deprecated use `isOnlineAsync` instead
*/
isOnline(departmentId?: string): boolean;
/**
* Gets online status of the livechat.
* @param departmentId (optional) the id of the livechat department
*/
isOnlineAsync(departmentId?: string): Promise<boolean>;
isOnline(departmentId?: string): Promise<boolean>;
getDepartmentsEnabledWithAgents(): Promise<Array<IDepartment>>;
getLivechatRooms(visitor: IVisitor, departmentId?: string): Promise<Array<ILivechatRoom>>;
/**
* @deprecated This method does not adhere to the conversion practices applied
* elsewhere in the Apps-Engine and will be removed in the next major version.
* Prefer the alternative methods to fetch visitors.
*/
getLivechatVisitors(query: object): Promise<Array<IVisitor>>;
getLivechatVisitorById(id: string): Promise<IVisitor | undefined>;
getLivechatVisitorByEmail(email: string): Promise<IVisitor | undefined>;
getLivechatVisitorByToken(token: string): Promise<IVisitor | undefined>;
Expand Down
22 changes: 0 additions & 22 deletions src/definition/accessors/IRoomBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,6 @@ export interface IRoomBuilder {
*/
getCreator(): IUser;

/**
* Adds a user to the room, these are by username until further notice.
*
* @param username the user's username to add to the room
* @deprecated in favor of `addMemberToBeAddedByUsername`. This method will be removed on version 2.0.0
*/
addUsername(username: string): IRoomBuilder;

/**
* Sets the usernames of who are joined to the room.
*
* @param usernames the list of usernames
* @deprecated in favor of `setMembersByUsernames`. This method will be removed on version 2.0.0
*/
setUsernames(usernames: Array<string>): IRoomBuilder;

/**
* Gets the usernames of users in the room.
* @deprecated in favor of `getMembersUsernames`. This method will be removed on version 2.0.0
*/
getUsernames(): Array<string>;

/**
* Adds a member to the room by username
*
Expand Down
7 changes: 7 additions & 0 deletions src/definition/accessors/IRoomRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ export interface IRoomRead {
*/
getDirectByUsernames(usernames: Array<string>): Promise<IRoom>;

/**
* Gets a direct room with all user ids
* @param userIds all user ids belonging to the direct room
* @returns the room
*/
getDirectByUserIds(userIds: Array<string>): Promise<IRoom>;

/**
* Get a list of the moderators of a given room
*
Expand Down
2 changes: 1 addition & 1 deletion src/definition/accessors/IUserRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface IUserRead {
/**
* Gets the app user of this app.
*/
getAppUser(appId?: string): Promise<IUser | undefined>;
getAppUser(): Promise<IUser | undefined>;

/**
* Gets the user's badge count (unread messages count).
Expand Down
19 changes: 0 additions & 19 deletions src/definition/livechat/ILivechatRoomClosedHandler.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/definition/livechat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { IDepartment } from './IDepartment';
import { ILivechatEventContext } from './ILivechatEventContext';
import { ILivechatMessage } from './ILivechatMessage';
import { ILivechatRoom } from './ILivechatRoom';
import { ILivechatRoomClosedHandler } from './ILivechatRoomClosedHandler';
import { ILivechatTransferData } from './ILivechatTransferData';
import { ILivechatTransferEventContext, LivechatTransferEventType } from './ILivechatTransferEventContext';
import { IPostLivechatAgentAssigned } from './IPostLivechatAgentAssigned';
Expand All @@ -27,7 +26,6 @@ export {
IPostLivechatRoomClosed,
IPostLivechatRoomSaved,
IPostLivechatRoomTransferred,
ILivechatRoomClosedHandler,
ILivechatTransferData,
ILivechatTransferEventContext,
IDepartment,
Expand Down
4 changes: 0 additions & 4 deletions src/definition/metadata/AppInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ export enum AppInterface {
// Livechat
IPostLivechatRoomStarted = 'IPostLivechatRoomStarted',
IPostLivechatRoomClosed = 'IPostLivechatRoomClosed',
/**
* @deprecated please use the AppMethod.EXECUTE_POST_LIVECHAT_ROOM_CLOSED method
*/
ILivechatRoomClosedHandler = 'ILivechatRoomClosedHandler',
IPostLivechatAgentAssigned = 'IPostLivechatAgentAssigned',
IPostLivechatAgentUnassigned = 'IPostLivechatAgentUnassigned',
IPostLivechatRoomTransferred = 'IPostLivechatRoomTransferred',
Expand Down
4 changes: 0 additions & 4 deletions src/definition/rooms/IRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ export interface IRoom {
slugifiedName: string;
type: RoomType;
creator: IUser;
/**
* @deprecated usernames will be removed on version 2.0.0
*/
usernames: Array<string>;
userIds?: Array<string>;
isDefault?: boolean;
isReadOnly?: boolean;
Expand Down
5 changes: 2 additions & 3 deletions src/server/AppManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,6 @@ export class AppManager {
undoSteps.push(() => this.removeAppUser(app));
} catch (err) {
aff.setAppUserError({
username: app.getAppUserUsername(),
message: 'Failed to create an app user for this app.',
});

Expand Down Expand Up @@ -973,7 +972,7 @@ export class AppManager {
}

private async createAppUser(appInfo: IAppInfo): Promise<string> {
const appUser = await (this.bridges.getUserBridge() as IInternalUserBridge & UserBridge).getAppUser(appInfo.id);
const appUser = await (this.bridges.getUserBridge() as IInternalUserBridge & UserBridge).getAppUser();

if (appUser) {
return appUser.id;
Expand All @@ -997,7 +996,7 @@ export class AppManager {
}

private async removeAppUser(app: ProxiedApp): Promise<boolean> {
const appUser = await (this.bridges.getUserBridge() as IInternalUserBridge & UserBridge).getAppUser(app.getID());
const appUser = await (this.bridges.getUserBridge() as IInternalUserBridge & UserBridge).getAppUser();

if (!appUser) {
return true;
Expand Down
4 changes: 0 additions & 4 deletions src/server/ProxiedApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@ export class ProxiedApp implements IApp {
return this.app.getNameSlug();
}

public getAppUserUsername(): string {
return this.app.getAppUserUsername();
}

public getID(): string {
return this.app.getID();
}
Expand Down
21 changes: 1 addition & 20 deletions src/server/accessors/LivechatRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,10 @@ import { LivechatBridge } from '../bridges/LivechatBridge';
export class LivechatRead implements ILivechatRead {
constructor(private readonly livechatBridge: LivechatBridge, private readonly appId: string) { }

/**
* @deprecated please use the `isOnlineAsync` method instead.
* In the next major, this method will be `async`
*/
public isOnline(departmentId?: string): boolean {
console.warn('The `LivechatRead.isOnline` method is deprecated and won\'t behave as intended. Please use `LivechatRead.isOnlineAsync` instead');

public isOnline(departmentId?: string): Promise<boolean> {
return this.livechatBridge.doIsOnline(departmentId, this.appId);
}

public isOnlineAsync(departmentId?: string): Promise<boolean> {
return this.livechatBridge.doIsOnlineAsync(departmentId, this.appId);
}

public getDepartmentsEnabledWithAgents(): Promise<Array<IDepartment>> {
return this.livechatBridge.doFindDepartmentsEnabledWithAgents(this.appId);
}
Expand All @@ -29,15 +19,6 @@ export class LivechatRead implements ILivechatRead {
return this.livechatBridge.doFindRooms(visitor, departmentId, this.appId);
}

/**
* @deprecated This method does not adhere to the conversion practices applied
* elsewhere in the Apps-Engine and will be removed in the next major version.
* Prefer the alternative methods to fetch visitors.
*/
public getLivechatVisitors(query: object): Promise<Array<IVisitor>> {
return this.livechatBridge.doFindVisitors(query, this.appId);
}

public getLivechatVisitorById(id: string): Promise<IVisitor | undefined> {
return this.livechatBridge.doFindVisitorById(id, this.appId);
}
Expand Down
27 changes: 0 additions & 27 deletions src/server/accessors/RoomBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,6 @@ export class RoomBuilder implements IRoomBuilder {
return this.room.creator;
}

/**
* @deprecated
*/
public addUsername(username: string): IRoomBuilder {
this.addMemberToBeAddedByUsername(username);
return this;
}

/**
* @deprecated
*/
public setUsernames(usernames: Array<string>): IRoomBuilder {
this.setMembersToBeAddedByUsernames(usernames);
return this;
}

/**
* @deprecated
*/
public getUsernames(): Array<string> {
const usernames = this.getMembersToBeAddedUsernames();
if (usernames && usernames.length > 0) {
return usernames;
}
return this.room.usernames || [];
}

public addMemberToBeAddedByUsername(username: string): IRoomBuilder {
this.members.push(username);
return this;
Expand Down
4 changes: 4 additions & 0 deletions src/server/accessors/RoomRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export class RoomRead implements IRoomRead {
return this.roomBridge.doGetDirectByUsernames(usernames, this.appId);
}

public getDirectByUserIds(userIds: Array<string>): Promise<IRoom> {
return this.roomBridge.doGetDirectByUserIds(userIds, this.appId);
}

public getModerators(roomId: string): Promise<Array<IUser>> {
return this.roomBridge.doGetModerators(roomId, this.appId);
}
Expand Down
4 changes: 2 additions & 2 deletions src/server/accessors/UserRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export class UserRead implements IUserRead {
return this.userBridge.doGetByUsername(username, this.appId);
}

public getAppUser(appId: string = this.appId): Promise<IUser | undefined> {
return this.userBridge.doGetAppUser(appId);
public getAppUser(): Promise<IUser | undefined> {
return this.userBridge.doGetAppUser(this.appId);
}

public getUserUnreadMessageCount(uid: string): Promise<number> {
Expand Down
2 changes: 1 addition & 1 deletion src/server/bridges/IInternalUserBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IUser, IUserCreationOptions } from '../../definition/users';

export interface IInternalUserBridge {
create(data: Partial<IUser>, appId: string, options?: IUserCreationOptions): Promise<string>;
getAppUser(appId?: string): Promise<IUser | undefined>;
getAppUser(): Promise<IUser | undefined>;
remove(user: IUser, appId: string): Promise<boolean>;
getActiveUserCount(): Promise<number>;
}
27 changes: 2 additions & 25 deletions src/server/bridges/LivechatBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,12 @@ type LivechatMultiplePermissions = keyof Pick<
>;

export abstract class LivechatBridge extends BaseBridge {
public doIsOnline(departmentId?: string, appId?: string): boolean {
public async doIsOnline(departmentId?: string, appId?: string): Promise<boolean> {
if (this.hasReadPermission(appId, 'livechat-status')) {
return this.isOnline(departmentId, appId);
}
}

public async doIsOnlineAsync(departmentId?: string, appId?: string): Promise<boolean> {
if (this.hasReadPermission(appId, 'livechat-status')) {
return this.isOnlineAsync(departmentId, appId);
}
}

public async doCreateMessage(message: ILivechatMessage, appId: string): Promise<string> {
if (this.hasWritePermission(appId, 'livechat-message')) {
return this.createMessage(message, appId);
Expand All @@ -75,12 +69,6 @@ export abstract class LivechatBridge extends BaseBridge {
}
}

public async doFindVisitors(query: object, appId: string): Promise<Array<IVisitor>> {
if (this.hasReadPermission(appId, 'livechat-visitor')) {
return this.findVisitors(query, appId);
}
}

public async doFindVisitorById(id: string, appId: string): Promise<IVisitor | undefined> {
if (this.hasReadPermission(appId, 'livechat-visitor')) {
return this.findVisitorById(id, appId);
Expand Down Expand Up @@ -153,22 +141,11 @@ export abstract class LivechatBridge extends BaseBridge {
}
}

/**
* @deprecated please use the `isOnlineAsync` method instead.
* In the next major, this method will be `async`
*/
protected abstract isOnline(departmentId?: string, appId?: string): boolean;
protected abstract isOnlineAsync(departmentId?: string, appId?: string): Promise<boolean>;
protected abstract isOnline(departmentId?: string, appId?: string): Promise<boolean>;
protected abstract createMessage(message: ILivechatMessage, appId: string): Promise<string>;
protected abstract getMessageById(messageId: string, appId: string): Promise<ILivechatMessage>;
protected abstract updateMessage(message: ILivechatMessage, appId: string): Promise<void>;
protected abstract createVisitor(visitor: IVisitor, appId: string): Promise<string>;
/**
* @deprecated This method does not adhere to the conversion practices applied
* elsewhere in the Apps-Engine and will be removed in the next major version.
* Prefer other methods that fetch visitors.
*/
protected abstract findVisitors(query: object, appId: string): Promise<Array<IVisitor>>;
protected abstract findVisitorById(id: string, appId: string): Promise<IVisitor | undefined>;
protected abstract findVisitorByEmail(email: string, appId: string): Promise<IVisitor | undefined>;
protected abstract findVisitorByToken(token: string, appId: string): Promise<IVisitor | undefined>;
Expand Down
7 changes: 7 additions & 0 deletions src/server/bridges/RoomBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export abstract class RoomBridge extends BaseBridge {
}
}

public async doGetDirectByUserIds(userIds: Array<string>, appId: string): Promise<IRoom | undefined> {
if (this.hasReadPermission(appId)) {
return this.getDirectByUserIds(userIds, appId);
}
}

public async doGetDirectByUsernames(usernames: Array<string>, appId: string): Promise<IRoom | undefined> {
if (this.hasReadPermission(appId)) {
return this.getDirectByUsernames(usernames, appId);
Expand Down Expand Up @@ -97,6 +103,7 @@ export abstract class RoomBridge extends BaseBridge {
protected abstract getCreatorById(roomId: string, appId: string): Promise<IUser | undefined>;
protected abstract getCreatorByName(roomName: string, appId: string): Promise<IUser | undefined>;
protected abstract getDirectByUsernames(usernames: Array<string>, appId: string): Promise<IRoom | undefined>;
protected abstract getDirectByUserIds(userIds: Array<string>, appId: string): Promise<IRoom | undefined>;
protected abstract getMembers(roomId: string, appId: string): Promise<Array<IUser>>;
protected abstract update(room: IRoom, members: Array<string>, appId: string): Promise<void>;
protected abstract createDiscussion(
Expand Down
Loading