@fontoxml/fontoxml-development-tools
Version:
Development tools for Fonto.
101 lines (90 loc) • 2.49 kB
JavaScript
const DEBUG_FILE_NAME = 'review-annotations-debug.json';
class DebugConfiguration {
_getDebuggingFile(cms, editSessionToken) {
if (!cms.existsSync(DEBUG_FILE_NAME)) {
return Promise.resolve({
isDebuggingEnabled: false,
});
}
return new Promise((resolve, reject) => {
cms.load(DEBUG_FILE_NAME, editSessionToken, (error, json) => {
if (error) {
reject(error);
return;
}
try {
const reviewAnnotationsDebug = JSON.parse(json);
resolve(reviewAnnotationsDebug);
} catch (error) {
reject(error);
}
});
});
}
getDebugConfigurationForAnnotationState(cms, editSessionToken) {
return this._getDebuggingFile(cms, editSessionToken).then(
(debugging) => {
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;
}
);
}
getDebugConfigurationForAnnotationGet(cms, editSessionToken) {
return this._getDebuggingFile(cms, editSessionToken).then(
(debugging) => {
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;
}
);
}
getTimeoutConfigForRoute(cms, editSessionToken, route, method) {
return this._getDebuggingFile(cms, editSessionToken).then(
(debugging) => {
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;
}
);
}
isDebuggingEnabled(cms, editSessionToken) {
return this._getDebuggingFile(cms, editSessionToken).then(
(debugging) => {
return !!debugging.debuggingEnabled;
}
);
}
}
export default DebugConfiguration;