import type { AxiosRequestConfig } from 'axios' ; import { BackendError , BackendErrorLabel , HttpClient } from '../../http' ; import { InvalidAppLockTimeoutError } from './FeatureError' ; import type { FeatureAppLock , FeatureVideoCalling , FeatureConferenceCalling , FeatureDigitalSignature , FeatureLegalhold , FeatureSSO , FeatureFileSharing , FeatureSelfDeletingMessages , } from './Feature' ; import type { FeatureList } from './FeatureList' ; import { FeatureConversationGuestLink , FeatureLockedError } from '.' ; export class FeatureAPI { constructor ( private readonly client ) { } public static readonly URL = { APPLOCK : 'appLock' , CALLING_CONFERENCE : 'conferenceCalling' , CALLING_VIDEO : 'videoCalling' , SELF_DELETING_MESSAGES : 'selfDeletingMessages' , DIGITAL_SIGNATURES : 'digitalSignatures' , CONVERSATION_GUEST_LINKS : 'conversationGuestLinks' , FEATURE_CONFIGS : '/feature-configs' , FEATURES : 'features' , FILE_SHARING : 'fileSharing' , LEGAL_HOLD : 'legalhold' , SSO : 'sso' , TEAMS : '/teams' , } ; public async getAllFeatures ( ) { const config = { method : 'get' , url : FeatureAPI . URL . FEATURE_CONFIGS , } ; const response = await this . client . sendJSON < FeatureList > ( config ) ; return response . data ; } deprecated public async getAllTeamFeatures ( teamId ) { const config = { method : 'get' , url : `${ FeatureAPI . URL . TEAMS }/${ teamId }/${ FeatureAPI . URL . FEATURES }` , } ; const response = await this . client . sendJSON < FeatureList > ( config ) ; return response . data ; } public async getLegalholdFeature ( ) { const config = { method : 'get' , url : `${ FeatureAPI . URL . FEATURE_CONFIGS }/${ FeatureAPI . URL . LEGAL_HOLD }` , } ; const response = await this . client . sendJSON < FeatureLegalhold > ( config ) ; return response . data ; } public async getConversationGuestLinkFeature ( ) { const config = { method : 'get' , url : `${ FeatureAPI . URL . FEATURE_CONFIGS }/${ FeatureAPI . URL . CONVERSATION_GUEST_LINKS }` , } ; const response = await this . client . sendJSON < FeatureConversationGuestLink > ( config ) ; return response . data ; } public async putConversationGuestLinkFeature ( teamId , conversationGuestLinkFeature ) { const config = { data : conversationGuestLinkFeature , method : 'put' , url : `${ FeatureAPI . URL . TEAMS }/${ teamId }/${ FeatureAPI . URL . FEATURES }/${ FeatureAPI . URL . CONVERSATION_GUEST_LINKS }` , } ; try { const response = await this . client . sendJSON < FeatureConversationGuestLink > ( config ) ; return response . data ; } catch ( error ) { switch ( ( error as BackendError ) . label ) { case BackendErrorLabel . FEATURE_LOCKED : { throw new FeatureLockedError ( ( error as BackendError ) . message ) ; } } throw error ; } } public async getConferenceCallingFeature ( ) { const config = { method : 'get' , url : `${ FeatureAPI . URL . FEATURE_CONFIGS }/${ FeatureAPI . URL . CALLING_CONFERENCE }` , } ; const response = await this . client . sendJSON < FeatureConferenceCalling > ( config ) ; return response . data ; } public async putConferenceCallingFeature ( teamId , conferenceCallingFeature ) { const config = { data : conferenceCallingFeature , method : 'put' , url : `${ FeatureAPI . URL . TEAMS }/${ teamId }/${ FeatureAPI . URL . FEATURES }/${ FeatureAPI . URL . CALLING_CONFERENCE }` , } ; try { const response = await this . client . sendJSON < FeatureConferenceCalling > ( config ) ; return response . data ; } catch ( error ) { switch ( ( error as BackendError ) . label ) { case BackendErrorLabel . FEATURE_LOCKED : { throw new FeatureLockedError ( ( error as BackendError ) . message ) ; } } throw error ; } } public async getVideoCallingFeature ( ) { const config = { method : 'get' , url : `${ FeatureAPI . URL . FEATURE_CONFIGS }/${ FeatureAPI . URL . CALLING_VIDEO }` , } ; const response = await this . client . sendJSON < FeatureConferenceCalling > ( config ) ; return response . data ; } public async putVideoCallingFeature ( teamId , videoCallingFeature ) { const config = { data : videoCallingFeature , method : 'put' , url : `${ FeatureAPI . URL . TEAMS }/${ teamId }/${ FeatureAPI . URL . FEATURES }/${ FeatureAPI . URL . CALLING_VIDEO }` , } ; try { const response = await this . client . sendJSON < FeatureVideoCalling > ( config ) ; return response . data ; } catch ( error ) { switch ( ( error as BackendError ) . label ) { case BackendErrorLabel . FEATURE_LOCKED : { throw new FeatureLockedError ( ( error as BackendError ) . message ) ; } } throw error ; } } public async getSelfDeletingMessagesFeature ( ) { const config = { method : 'get' , url : `${ FeatureAPI . URL . FEATURE_CONFIGS }/${ FeatureAPI . URL . SELF_DELETING_MESSAGES }` , } ; const response = await this . client . sendJSON < FeatureSelfDeletingMessages > ( config ) ; return response . data ; } public async putSelfDeletingMessagesFeature ( teamId , selfDeleteingMessagesFeature ) { const config = { data : selfDeleteingMessagesFeature , method : 'put' , url : `${ FeatureAPI . URL . TEAMS }/${ teamId }/${ FeatureAPI . URL . FEATURES }/${ FeatureAPI . URL . SELF_DELETING_MESSAGES }` , } ; try { const response = await this . client . sendJSON < FeatureSelfDeletingMessages > ( config ) ; return response . data ; } catch ( error ) { switch ( ( error as BackendError ) . label ) { case BackendErrorLabel . FEATURE_LOCKED : { throw new FeatureLockedError ( ( error as BackendError ) . message ) ; } } throw error ; } } public async getFileSharingFeature ( ) { const config = { method : 'get' , url : `${ FeatureAPI . URL . FEATURE_CONFIGS }/${ FeatureAPI . URL . FILE_SHARING }` , } ; const response = await this . client . sendJSON < FeatureFileSharing > ( config ) ; return response . data ; } public async putFileSharingFeature ( teamId , fileSharingFeature ) { const config = { data : fileSharingFeature , method : 'put' , url : `${ FeatureAPI . URL . TEAMS }/${ teamId }/${ FeatureAPI . URL . FEATURES }/${ FeatureAPI . URL . FILE_SHARING }` , } ; try { const response = await this . client . sendJSON < FeatureFileSharing > ( config ) ; return response . data ; } catch ( error ) { switch ( ( error as BackendError ) . label ) { case BackendErrorLabel . FEATURE_LOCKED : { throw new FeatureLockedError ( ( error as BackendError ) . message ) ; } } throw error ; } } public async getSSOFeature ( ) { const config = { method : 'get' , url : `${ FeatureAPI . URL . FEATURE_CONFIGS }/${ FeatureAPI . URL . SSO }` , } ; const response = await this . client . sendJSON < FeatureSSO > ( config ) ; return response . data ; } public async getDigitalSignatureFeature ( teamId ) { const config = { method : 'get' , url : `${ FeatureAPI . URL . TEAMS }/${ teamId }/${ FeatureAPI . URL . FEATURES }/${ FeatureAPI . URL . DIGITAL_SIGNATURES }` , } ; const response = await this . client . sendJSON < FeatureDigitalSignature > ( config ) ; return response . data ; } public async getAppLockFeature ( ) { const config = { method : 'get' , url : `${ FeatureAPI . URL . FEATURE_CONFIGS }/${ FeatureAPI . URL . APPLOCK }` , } ; const response = await this . client . sendJSON < FeatureAppLock > ( config ) ; return response . data ; } public async putAppLockFeature ( teamId , appLockFeature ) { const config = { data : appLockFeature , method : 'put' , url : `${ FeatureAPI . URL . TEAMS }/${ teamId }/${ FeatureAPI . URL . FEATURES }/${ FeatureAPI . URL . APPLOCK }` , } ; try { const response = await this . client . sendJSON < FeatureAppLock > ( config ) ; return response . data ; } catch ( error ) { switch ( ( error as BackendError ) . label ) { case BackendErrorLabel . APP_LOCK_INVALID_TIMEOUT : { throw new InvalidAppLockTimeoutError ( ( error as BackendError ) . message ) ; } case BackendErrorLabel . FEATURE_LOCKED : { throw new FeatureLockedError ( ( error as BackendError ) . message ) ; } } throw error ; } } }