UNPKG

@fontoxml/fontoxml-development-tools

Version:

Development tools for Fonto.

90 lines (76 loc) 2.32 kB
const DEBUG_FILE_NAME = 'review-annotations-debug.json'; class DebugConfiguration { async _getDebuggingFile(cms, editSessionToken) { let fileLock; try { fileLock = await cms.acquireLock(DEBUG_FILE_NAME); const json = await cms.getFileWithoutHistory( DEBUG_FILE_NAME, editSessionToken, fileLock, ); if (json === null) { return { isDebuggingEnabled: false, }; } const reviewAnnotationsDebug = JSON.parse(json); return reviewAnnotationsDebug; } finally { fileLock?.release(); } } async getDebugConfigurationForAnnotationState(cms, editSessionToken) { const debugging = await this._getDebuggingFile(cms, editSessionToken); const isDebuggingOn = debugging.debuggingEnabled; if (!isDebuggingOn) { return null; } const foundHttpStatusCode = debugging.configuration && debugging.configuration.find( (element) => element.route === '/review/state', ); if (!foundHttpStatusCode || !foundHttpStatusCode.errorState) { return null; } return foundHttpStatusCode.errorState.code; } async getDebugConfigurationForAnnotationGet(cms, editSessionToken) { const debugging = await this._getDebuggingFile(cms, editSessionToken); const isDebuggingOn = debugging.debuggingEnabled; if (!isDebuggingOn) { return null; } const foundHttpStatusCode = debugging.configuration && debugging.configuration.find( (element) => element.route === '/review/annotation/get', ); if (!foundHttpStatusCode || !foundHttpStatusCode.errorState) { return null; } return foundHttpStatusCode.errorState.code; } async getTimeoutConfigForRoute(cms, editSessionToken, route, method) { const debugging = await this._getDebuggingFile(cms, editSessionToken); const isDebuggingOn = debugging.debuggingEnabled; if (!isDebuggingOn) { return null; } const timeoutConfig = debugging.configuration && debugging.configuration.find( (element) => element.route === route && element.method === method, ); if (!timeoutConfig) { return null; } return !!timeoutConfig.errorState.shouldTriggerTimeout; } async isDebuggingEnabled(cms, editSessionToken) { const debugging = await this._getDebuggingFile(cms, editSessionToken); return !!debugging.debuggingEnabled; } } export default DebugConfiguration;