UNPKG

kod-temp

Version:

Workano Communications SDK

78 lines (77 loc) 2.56 kB
import getApiClient from '../service/getApiClient'; export const FEATURES = ['chat', 'video', 'call_recording', 'fax', 'mobile_double_call', 'mobile_gsm', 'meeting', 'caller_id']; export const getScopeName = (featureName) => `enterprise.app.${featureName}`; const scopesToCheck = FEATURES.map(getScopeName); // Handle available features on the engine. class Features { _hasChat; _hasVideo; _hasCallRecording; _hasFax; _hasMobileDoubleCall; _hasMobileGsm; _hasMeeting; _hasCallerID; constructor() { this._hasChat = true; this._hasVideo = true; this._hasCallRecording = true; this._hasFax = true; this._hasMobileDoubleCall = true; this._hasMobileGsm = true; this._hasMeeting = true; this._hasCallerID = false; } async fetchAccess() { let response; try { response = await getApiClient().auth.getRestrictionPolicies(scopesToCheck); } catch (_) { // Noting to do because everything should be available even if the API is not available } if (!response) { return; } const { scopes, } = response; this._hasChat = this._hasFeatures(scopes, 'chat'); this._hasVideo = this._hasFeatures(scopes, 'video'); this._hasCallRecording = this._hasFeatures(scopes, 'call_recording'); this._hasFax = this._hasFeatures(scopes, 'fax'); this._hasMobileDoubleCall = this._hasFeatures(scopes, 'mobile_double_call'); this._hasMobileGsm = this._hasFeatures(scopes, 'mobile_gsm'); this._hasMeeting = this._hasFeatures(scopes, 'meeting'); this._hasCallerID = this._hasFeatures(scopes, 'caller_id'); } hasChat() { return this._hasChat; } hasVideo() { return this._hasVideo; } hasCallRecording() { return this._hasCallRecording; } hasFax() { return this._hasFax; } hasMobileDoubleCall() { return this._hasMobileDoubleCall; } hasMobileGsm() { return this._hasMobileGsm; } hasMeeting() { return this._hasMeeting; } hasCallerID() { return this._hasCallerID; } _hasFeatures(scopes, featureName) { const scopeName = getScopeName(featureName); if (!scopes || !(scopeName in scopes)) { // Assume that the feature is available if not present (available by default) return true; } return scopes[scopeName] === true; } } export default new Features();