remove privacy builtin module

pull/95/head
dperolio 2 years ago
parent c109310157
commit 5fd2c080ec
No known key found for this signature in database
GPG Key ID: 4191689562D51409

BIN
.DS_Store vendored

Binary file not shown.

@ -1,44 +0,0 @@
import { getModule } from '@vizality/webpack';
import { Builtin } from '@vizality/entities';
let Analytics, Reporter, Sentry;
export default class Privacy extends Builtin {
start () {
Analytics = getModule('getSuperPropertiesBase64');
Reporter = getModule('submitLiveCrashReport');
Sentry = {
main: window.__SENTRY__.hub,
client: window.__SENTRY__.hub.getClient()
};
Analytics.__oldTrack = Analytics.track;
Analytics.track = () => void 0;
Reporter.__oldSubmitLiveCrashReport = Reporter.submitLiveCrashReport;
Reporter.submitLiveCrashReport = () => void 0;
Sentry.client.close();
Sentry.main.getScope().clear();
Sentry.main.__oldAddBreadcrumb = Sentry.main.addBreadcrumb;
Sentry.main.addBreadcrumb = () => void 0;
window.__oldConsole = window.console;
Object.assign(window.console, [ 'debug', 'info', 'warn', 'error', 'log', 'assert' ].forEach(method => {
if (window.console[method].__sentry_original__) {
window.console[method] = window.console[method].__sentry_original__;
} else if (window.console[method].__REACT_DEVTOOLS_ORIGINAL_METHOD__) {
window.console[method].__REACT_DEVTOOLS_ORIGINAL_METHOD__ = window.console[method].__REACT_DEVTOOLS_ORIGINAL_METHOD__.__sentry_original__;
}
}));
}
stop () {
Analytics.track = Analytics.__oldTrack;
Reporter.submitLiveCrashReport = Reporter.__oldSubmitLiveCrashReport;
Sentry.main.addBreadcrumb = Sentry.main.__oldAddBreadcrumb;
Sentry.client.getOptions().enabled = true;
window.console = window.__oldConsole;
}
}

@ -6,33 +6,12 @@
* @namespace Util.Logger
*/
/**
* @typedef LoggerLabel
* @type {object}
* @property {string} text Text to show in the label
* @property {string} color Color string in any format (without alpha)
*/
import { getRandomColor, getContrastColor, blendColors, shadeColor } from './Color';
import { isArray, isEmptyArray, assertArray } from './Array';
import { isString, assertString } from './String';
import { assertObject } from './Object';
/** @private */
const _labels = [ 'Util', 'Logger' ];
const _log = (labels, ...message) => this.log({ labels, message });
const _warn = (labels, ...message) => this.warn({ labels, message });
const _error = (labels, ...message) => this.error({ labels, message });
/**
* Processes which type of console method to use.
* @private
* @param {any} type Type of console method
* @returns {('log'|'warn'|'error')} Type of console method to use
*/
const _parseType = type => {
return [ 'log', 'warn', 'error' ].find(t => t === type) || 'log';
};
/**
* Sets the maximum amount of badges that can be used in a single console message.
@ -42,7 +21,7 @@ export const MAX_LABELS_COUNT = 10;
/**
* Contains a list of modules and their color badge associations.
*/
export const MODULES = {
export const PRESET_LABELS = {
watcher: [ '#FFC600' ],
vizality: [ '#121321', '#ffffff' ],
compiler: [ '#38964e', '#c01b91' ],
@ -62,16 +41,121 @@ export const MODULES = {
classes: [ '#b68aff', '#f3523d' ]
};
/**
* Logs an informational message to dev tools console.
* @param {object} options Options for the console message
* @param {string} [options.type='log'] Type of console method to use
* @param {string} [options.badge='vizality://assets/images/logo.png'] Badge image URL
* @param {Array<string|object>} [options.labels=[]] Label texts or label objects. Limit of 10.
* @param {string} [options.labels.text] Label text
* @param {string} [options.labels.color] Label color
* @param {any} [options.message] Message to log
*/
export function log (options) {
try {
assertObject(options);
options.type = 'log';
return _handler(options);
} catch (err) {
return _error(_labels.concat('log'), err);
}
}
/**
* Logs a warning message to dev tools console.
* @param {object} options Options for the console message
* @param {string} [options.type='log'] Type of console method to use
* @param {string} [options.badge='vizality://assets/images/logo.png'] Badge image URL
* @param {Array<string|object>} [options.labels=[]] Label texts or label objects. Limit of 10.
* @param {string} [options.labels.text] Label text
* @param {string} [options.labels.color] Label color
* @param {any} [options.message] Message to log
*/
export function warn (options) {
try {
assertObject(options);
options.type = 'warn';
return _handler(options);
} catch (err) {
return _error(_labels.concat('warn'), err);
}
}
/**
* Logs an error message to dev tools console.
* @param {object} options Options for the console message
* @param {string} [options.type='log'] Type of console method to use
* @param {string} [options.badge='vizality://assets/images/logo.png'] Badge image URL
* @param {Array<string|object>} [options.labels=[]] Label texts or label objects. Limit of 10.
* @param {string} [options.labels.text] Label text
* @param {string} [options.labels.color] Label color
* @param {any} [options.message] Message to log
*/
export function error (options) {
try {
assertObject(options);
options.type = 'error';
return _handler(options);
} catch (err) {
return _error(_labels.concat('error'), err);
}
}
/**
* Logs a deprecation (warning) message to dev tools console.
* @param {object} options Options for the console message
* @param {string} [options.type='log'] Type of console method to use
* @param {string} [options.badge='vizality://assets/images/logo.png'] Badge image URL
* @param {Array<string|object>} [options.labels=[]] Label texts or label objects. Limit of 10.
* @param {string} [options.labels.text] Label text
* @param {string} [options.labels.color] Label color
* @param {any} [options.message] Message to log
*/
export function deprecate (options) {
try {
assertObject(options);
const { message } = options;
options.type = 'warn';
options.message = `Deprecation Notice: ${message}`;
return _handler(options);
} catch (err) {
return _error(_labels.concat('deprecate'), err);
}
}
/**
* Sends a stylized error message to console tuned to this file.
* @param {Array<string>} labels Label text
* @param {...any} message Message to log
* @returns {void}
* @private
*/
function _error (labels, ...message) {
return error({ labels, message });
}
/**
* Processes which type of console method to use.
* @param {any} type Type of console method to use
* @returns {('log'|'warn'|'error')}
* @private
*/
function _parseType (type) {
return [ 'log', 'warn', 'error' ].find(t => t === type) || 'log';
}
/**
* Outputs messages to console of varying types. Outputted messages contain a badge, label(s), and a message.
* @param {object} options Options for the console message
* @param {string} [options.type='log'] Type of console method to use
* @param {string} [options.badge='vizality://assets/images/logo.png'] Badge image URL
* @param {Array<string|LoggerLabel>} [options.labels] Label texts or label objects. Limit of 10.
* @param {...any} [options.message] Contents of the console message
* @param {Array<string|object>} [options.labels=[]] Label texts or label objects. Limit of 10.
* @param {string} [options.labels.text] Label text
* @param {string} [options.labels.color] Label color
* @param {any} [options.message] Message to log
* @private
*/
const _logHandler = options => {
function _handler (options) {
try {
assertObject(options);
let { type, badge, labels, message } = options;
@ -136,11 +220,11 @@ const _logHandler = options => {
*/
if (isString(label)) {
let color;
if ((index === 0 || index === 1) && MODULES[labels[0].toLowerCase()]) {
color = MODULES[labels[0].toLowerCase()][index];
} else if (index === 2 && MODULES[labels[0].toLowerCase()]) {
color = shadeColor(blendColors(MODULES[labels[0].toLowerCase()][0], processedLabels[index - 1]?.color, 0.5), -0.5);
} else if (index > 2 && MODULES[labels[0].toLowerCase()]) {
if ((index === 0 || index === 1) && PRESET_LABELS[labels[0].toLowerCase()]) {
color = PRESET_LABELS[labels[0].toLowerCase()][index];
} else if (index === 2 && PRESET_LABELS[labels[0].toLowerCase()]) {
color = shadeColor(blendColors(PRESET_LABELS[labels[0].toLowerCase()][0], processedLabels[index - 1]?.color, 0.5), -0.5);
} else if (index > 2 && PRESET_LABELS[labels[0].toLowerCase()]) {
color = shadeColor(processedLabels[index - 1]?.color, 0.2);
} else {
color = getRandomColor();
@ -166,7 +250,7 @@ const _logHandler = options => {
/**
*
*/
for (const label of processedLabels.slice(0, this.MAX_LABELS_COUNT)) {
for (const label of processedLabels.slice(0, MAX_LABELS_COUNT)) {
if (!label?.text || !label?.color) {
throw new Error('Each label must contain a valid text and color property.');
}
@ -188,76 +272,6 @@ const _logHandler = options => {
...message
);
} catch (err) {
return _error(_labels.concat('_logHandler'), err);
}
};
/**
* Logs an informational message to dev tools console.
* @param {object} options Options for the console message
* @param {string} [options.badge] Badge image URL
* @param {Array<string|LoggerLabel>} [options.labels] Label texts or label objects
* @param {...any} [options.message] Contents of the console message
*/
export const log = options => {
try {
assertObject(options);
options.type = 'log';
return _logHandler(options);
} catch (err) {
return _error(_labels.concat('log'), err);
}
};
/**
* Logs a warning message to dev tools console.
* @param {object} options Options for the console message
* @param {string} [options.badge] Badge image URL
* @param {Array<string|LoggerLabel>} [options.labels] Label texts or label objects
* @param {...any} [options.message] Contents of the console message
*/
export const warn = options => {
try {
assertObject(options);
options.type = 'warn';
return _logHandler(options);
} catch (err) {
return _error(_labels.concat('warn'), err);
}
};
/**
* Logs an error message to dev tools console.
* @param {object} options Options for the console message
* @param {string} [options.badge] Badge image URL
* @param {Array<string|LoggerLabel>} [options.labels] Label texts or label objects
* @param {...any} [options.message] Contents of the console message
*/
export const error = options => {
try {
assertObject(options);
options.type = 'error';
return _logHandler(options);
} catch (err) {
return _error(_labels.concat('error'), err);
return _error(_labels.concat('_handler'), err);
}
};
/**
* Logs a deprecation (warning) message to dev tools console.
* @param {object} options Options for the console message
* @param {string} [options.badge] Badge image URL
* @param {Array<string|LoggerLabel>} [options.labels] Label texts or label objects
* @param {...any} [options.message] Contents of the console message
*/
export const deprecate = options => {
try {
assertObject(options);
const { message } = options;
options.type = 'warn';
options.message = `Deprecation Notice: ${message}`;
return _logHandler(options);
} catch (err) {
return _error(_labels.concat('deprecate'), err);
}
};
}

Loading…
Cancel
Save