UNPKG

@aurigma/design-atoms

Version:

Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.

94 lines 3.04 kB
import { isObject } from './Type'; import * as CcJson from "./Json"; var traceLogEnabled = false; var editorUrl = null; var id = null; var postLogInterval = null; var requests = []; var traceLogScope = ""; export function enableTraceLog(value, editorUrlParameter, scope, traceLogId) { traceLogEnabled = value; traceLogScope = scope; if (value) { var rnd = Math.random(); id = traceLogId ? traceLogId : rnd.toString(); // new Uuid().value; editorUrl = editorUrlParameter; window.addEventListener("error", onWindowError, true); console.log("TraceLog enabled for " + traceLogScope + " editorUrl: " + editorUrl); postLogInterval = setInterval(function () { return postLog(); }, 5000); } else { editorUrl = null; window.removeEventListener("error", onWindowError); if (postLogInterval) clearInterval(postLogInterval); } } function onWindowError(error) { //console.log("onWindowError", error); var message = CcJson.Json.parse(error); traceLog({ "window.onerror": true, error: message }); return false; } export function getTraceLogId() { return id; } export function traceLog(data, includeStackTrace) { if (includeStackTrace === void 0) { includeStackTrace = false; } try { if (!traceLogEnabled) return; if (editorUrl == null || editorUrl == undefined || editorUrl == "" || typeof editorUrl !== "string") return; var date = new Date(); var requestBody = {}; if (isObject(data)) { for (var t in data) { try { requestBody[t] = JSON.stringify(data[t]); } catch (e) { try { requestBody[t] = CcJson.Json.stringify(data[t]); } catch (e1) { requestBody[t] = "Unable to stringify: " + e1; } } } if (includeStackTrace) { var err = new Error(); requestBody["__stackTrace"] = err.stack; } requestBody["__time"] = date; } addLog(requestBody); } catch (ex) { console.error("Exception in traceLog", ex); } } function addLog(requestBody) { requests.push(requestBody); } function postLog() { try { if (requests.length == 0) return; fetch(editorUrl + "/api/frontendlog", { mode: 'cors', method: 'post', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ traceLogId: id, scope: traceLogScope, logs: requests }) }); requests = []; } catch (ex) { console.error("Error in traceLog:", ex); } } //# sourceMappingURL=TraceLog.js.map