@atlassian/clientside-extensions-debug 2.4.0-69e0f9e-kugbhrvw
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +30 -0
- package/README.md +7 -0
- package/dist/cjs/debug-state-env.test.js +63 -0
- package/dist/cjs/debug-state-env.test.js.map +1 -0
- package/dist/cjs/debug-state.js +155 -0
- package/dist/cjs/debug-state.js.map +1 -0
- package/dist/cjs/debug-state.test.js +66 -0
- package/dist/cjs/debug-state.test.js.map +1 -0
- package/dist/cjs/debug-subjects.js +42 -0
- package/dist/cjs/debug-subjects.js.map +1 -0
- package/dist/cjs/debug-subjects.test.js +35 -0
- package/dist/cjs/debug-subjects.test.js.map +1 -0
- package/dist/cjs/debug.js +23 -0
- package/dist/cjs/debug.js.map +1 -0
- package/dist/cjs/debug.test.js +75 -0
- package/dist/cjs/debug.test.js.map +1 -0
- package/dist/cjs/index.js +23 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/logger/console.js +64 -0
- package/dist/cjs/logger/console.js.map +1 -0
- package/dist/cjs/logger/console.test.js +200 -0
- package/dist/cjs/logger/console.test.js.map +1 -0
- package/dist/cjs/logger/default-logger.js +48 -0
- package/dist/cjs/logger/default-logger.js.map +1 -0
- package/dist/cjs/logger/logger.js +16 -0
- package/dist/cjs/logger/logger.js.map +1 -0
- package/dist/esm/debug-state-env.test.js +42 -0
- package/dist/esm/debug-state-env.test.js.map +1 -0
- package/dist/esm/debug-state.js +152 -0
- package/dist/esm/debug-state.js.map +1 -0
- package/dist/esm/debug-state.test.js +63 -0
- package/dist/esm/debug-state.test.js.map +1 -0
- package/dist/esm/debug-subjects.js +39 -0
- package/dist/esm/debug-subjects.js.map +1 -0
- package/dist/esm/debug-subjects.test.js +33 -0
- package/dist/esm/debug-subjects.test.js.map +1 -0
- package/dist/esm/debug.js +20 -0
- package/dist/esm/debug.js.map +1 -0
- package/dist/esm/debug.test.js +73 -0
- package/dist/esm/debug.test.js.map +1 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/logger/console.js +61 -0
- package/dist/esm/logger/console.js.map +1 -0
- package/dist/esm/logger/console.test.js +198 -0
- package/dist/esm/logger/console.test.js.map +1 -0
- package/dist/esm/logger/default-logger.js +46 -0
- package/dist/esm/logger/default-logger.js.map +1 -0
- package/dist/esm/logger/logger.js +14 -0
- package/dist/esm/logger/logger.js.map +1 -0
- package/dist/types/debug-state-env.test.d.ts +2 -0
- package/dist/types/debug-state-env.test.d.ts.map +1 -0
- package/dist/types/debug-state.d.ts +41 -0
- package/dist/types/debug-state.d.ts.map +1 -0
- package/dist/types/debug-state.test.d.ts +2 -0
- package/dist/types/debug-state.test.d.ts.map +1 -0
- package/dist/types/debug-subjects.d.ts +25 -0
- package/dist/types/debug-subjects.d.ts.map +1 -0
- package/dist/types/debug-subjects.test.d.ts +2 -0
- package/dist/types/debug-subjects.test.d.ts.map +1 -0
- package/dist/types/debug.d.ts +3 -0
- package/dist/types/debug.d.ts.map +1 -0
- package/dist/types/debug.test.d.ts +2 -0
- package/dist/types/debug.test.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/logger/console.d.ts +3 -0
- package/dist/types/logger/console.d.ts.map +1 -0
- package/dist/types/logger/console.test.d.ts +2 -0
- package/dist/types/logger/console.test.d.ts.map +1 -0
- package/dist/types/logger/default-logger.d.ts +25 -0
- package/dist/types/logger/default-logger.d.ts.map +1 -0
- package/dist/types/logger/logger.d.ts +20 -0
- package/dist/types/logger/logger.d.ts.map +1 -0
- package/lib/__mocks__/debug-state.mock.ts +7 -0
- package/lib/__mocks__/debug-subjects.mock.ts +4 -0
- package/lib/debug-state-env.test.ts +53 -0
- package/lib/debug-state.test.ts +87 -0
- package/lib/debug-state.ts +198 -0
- package/lib/debug-subjects.test.ts +40 -0
- package/lib/debug-subjects.ts +78 -0
- package/lib/debug.test.ts +95 -0
- package/lib/debug.ts +24 -0
- package/lib/index.ts +23 -0
- package/lib/logger/console.test.ts +240 -0
- package/lib/logger/console.ts +73 -0
- package/lib/logger/default-logger.ts +67 -0
- package/lib/logger/logger.ts +26 -0
- package/package.json +80 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { consoleLogger } from './console';
|
|
2
|
+
import { observeDebugSubject } from '../debug-subjects';
|
|
3
|
+
import { _loggerSubject } from './logger';
|
|
4
|
+
/**
|
|
5
|
+
* We need to keep and expose the "observeLogger" function for a legacy reason.
|
|
6
|
+
* It should be removed in CSEv3
|
|
7
|
+
*
|
|
8
|
+
* @deprecated
|
|
9
|
+
*/
|
|
10
|
+
export const observeLogger = (observer) => {
|
|
11
|
+
return observeDebugSubject("logger" /* Logger */, observer);
|
|
12
|
+
};
|
|
13
|
+
const registerConsoleLogger = () => {
|
|
14
|
+
// Singleton workaround as this module may be executed more than once.
|
|
15
|
+
// We only ever want one global default logger, however.
|
|
16
|
+
if (window.____c_p_d_l_d !== undefined) {
|
|
17
|
+
return window.____c_p_d_l_d;
|
|
18
|
+
}
|
|
19
|
+
window.____c_p_d_l_d = observeLogger(consoleLogger);
|
|
20
|
+
return window.____c_p_d_l_d;
|
|
21
|
+
};
|
|
22
|
+
const deregisterLogger = () => {
|
|
23
|
+
if (window.____c_p_d_l_d === undefined) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
window.____c_p_d_l_d.unsubscribe();
|
|
27
|
+
};
|
|
28
|
+
export const defaultLogger = registerConsoleLogger();
|
|
29
|
+
/**
|
|
30
|
+
* Added in CSE 2.1.0
|
|
31
|
+
*
|
|
32
|
+
* @param logger
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export const setLogger = (logger) => {
|
|
36
|
+
if (typeof logger !== 'function') {
|
|
37
|
+
throw new Error(`Client-side Extension: The provided logger needs to be a function`);
|
|
38
|
+
}
|
|
39
|
+
deregisterLogger();
|
|
40
|
+
_loggerSubject.prune();
|
|
41
|
+
observeDebugSubject("logger" /* Logger */, logger);
|
|
42
|
+
};
|
|
43
|
+
const deregisterDefaultLogger = () => defaultLogger.unsubscribe();
|
|
44
|
+
// @VisibleForTesting
|
|
45
|
+
export { deregisterDefaultLogger as _deregisterDefaultLogger };
|
|
46
|
+
//# sourceMappingURL=default-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-logger.js","sourceRoot":"","sources":["../../../lib/logger/default-logger.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAiB,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAEvE,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAS1C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,QAAiC,EAAgB,EAAE;IAC7E,OAAO,mBAAmB,wBAAsC,QAAQ,CAAC,CAAC;AAC9E,CAAC,CAAC;AAEF,MAAM,qBAAqB,GAAG,GAAiB,EAAE;IAC7C,sEAAsE;IACtE,wDAAwD;IACxD,IAAI,MAAM,CAAC,aAAa,KAAK,SAAS,EAAE;QACpC,OAAO,MAAM,CAAC,aAAa,CAAC;KAC/B;IAED,MAAM,CAAC,aAAa,GAAG,aAAa,CAAC,aAAa,CAAC,CAAC;IAEpD,OAAO,MAAM,CAAC,aAAa,CAAC;AAChC,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG,GAAS,EAAE;IAChC,IAAI,MAAM,CAAC,aAAa,KAAK,SAAS,EAAE;QACpC,OAAO;KACV;IAED,MAAM,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;AACvC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,qBAAqB,EAAE,CAAC;AAErD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,MAA+B,EAAQ,EAAE;IAC/D,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE;QAC9B,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;KACxF;IAED,gBAAgB,EAAE,CAAC;IACnB,cAAc,CAAC,KAAK,EAAE,CAAC;IAEvB,mBAAmB,wBAAsC,MAAM,CAAC,CAAC;AACrE,CAAC,CAAC;AAEF,MAAM,uBAAuB,GAAG,GAAG,EAAE,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;AAElE,qBAAqB;AACrB,OAAO,EAAE,uBAAuB,IAAI,wBAAwB,EAAE,CAAC","sourcesContent":["/* eslint-disable no-underscore-dangle */\nimport type { Observer, Subscription } from '@atlassian/clientside-extensions-base';\nimport { consoleLogger } from './console';\nimport { DebugSubjects, observeDebugSubject } from '../debug-subjects';\nimport type { LoggerPayload } from './logger';\nimport { _loggerSubject } from './logger';\n\ndeclare global {\n interface Window {\n // clientside extension default logging deregister\n ____c_p_d_l_d?: Subscription;\n }\n}\n\n/**\n * We need to keep and expose the \"observeLogger\" function for a legacy reason.\n * It should be removed in CSEv3\n *\n * @deprecated\n */\nexport const observeLogger = (observer: Observer<LoggerPayload>): Subscription => {\n return observeDebugSubject<LoggerPayload>(DebugSubjects.Logger, observer);\n};\n\nconst registerConsoleLogger = (): Subscription => {\n // Singleton workaround as this module may be executed more than once.\n // We only ever want one global default logger, however.\n if (window.____c_p_d_l_d !== undefined) {\n return window.____c_p_d_l_d;\n }\n\n window.____c_p_d_l_d = observeLogger(consoleLogger);\n\n return window.____c_p_d_l_d;\n};\n\nconst deregisterLogger = (): void => {\n if (window.____c_p_d_l_d === undefined) {\n return;\n }\n\n window.____c_p_d_l_d.unsubscribe();\n};\n\nexport const defaultLogger = registerConsoleLogger();\n\n/**\n * Added in CSE 2.1.0\n *\n * @param logger\n * @public\n */\nexport const setLogger = (logger: Observer<LoggerPayload>): void => {\n if (typeof logger !== 'function') {\n throw new Error(`Client-side Extension: The provided logger needs to be a function`);\n }\n\n deregisterLogger();\n _loggerSubject.prune();\n\n observeDebugSubject<LoggerPayload>(DebugSubjects.Logger, logger);\n};\n\nconst deregisterDefaultLogger = () => defaultLogger.unsubscribe();\n\n// @VisibleForTesting\nexport { deregisterDefaultLogger as _deregisterDefaultLogger };\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ReplaySubject } from '@atlassian/clientside-extensions-base';
|
|
2
|
+
import { registerDebugSubject } from '../debug-subjects';
|
|
3
|
+
export var LogLevel;
|
|
4
|
+
(function (LogLevel) {
|
|
5
|
+
LogLevel["debug"] = "DEBUG";
|
|
6
|
+
LogLevel["error"] = "ERROR";
|
|
7
|
+
LogLevel["warn"] = "WARN";
|
|
8
|
+
LogLevel["deprecation"] = "DEPRECATION";
|
|
9
|
+
LogLevel["info"] = "INFO";
|
|
10
|
+
})(LogLevel || (LogLevel = {}));
|
|
11
|
+
const loggerSubject = registerDebugSubject("logger" /* Logger */, () => new ReplaySubject(20));
|
|
12
|
+
// Exported for internal use only
|
|
13
|
+
export { loggerSubject as _loggerSubject };
|
|
14
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../lib/logger/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,EAAiB,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAExE,MAAM,CAAN,IAAY,QAMX;AAND,WAAY,QAAQ;IAChB,2BAAe,CAAA;IACf,2BAAe,CAAA;IACf,yBAAa,CAAA;IACb,uCAA2B,CAAA;IAC3B,yBAAa,CAAA;AACjB,CAAC,EANW,QAAQ,KAAR,QAAQ,QAMnB;AAaD,MAAM,aAAa,GAAG,oBAAoB,wBAAuB,GAAG,EAAE,CAAC,IAAI,aAAa,CAAgB,EAAE,CAAC,CAAC,CAAC;AAE7G,iCAAiC;AACjC,OAAO,EAAE,aAAa,IAAI,cAAc,EAAE,CAAC","sourcesContent":["import { ReplaySubject } from '@atlassian/clientside-extensions-base';\nimport { DebugSubjects, registerDebugSubject } from '../debug-subjects';\n\nexport enum LogLevel {\n debug = 'DEBUG', // Logs all the things\n error = 'ERROR',\n warn = 'WARN',\n deprecation = 'DEPRECATION',\n info = 'INFO', // The lowest level\n}\n\nexport type LoggerCallback = (levels: typeof LogLevel) => LoggerPayload;\n\nexport type LoggerPayload = {\n level: LogLevel;\n message: string;\n components?: string | string[];\n meta?: {\n [key: string]: unknown;\n };\n};\n\nconst loggerSubject = registerDebugSubject(DebugSubjects.Logger, () => new ReplaySubject<LoggerPayload>(20));\n\n// Exported for internal use only\nexport { loggerSubject as _loggerSubject };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-state-env.test.d.ts","sourceRoot":"","sources":["../../lib/debug-state-env.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Observer } from '@atlassian/clientside-extensions-base';
|
|
2
|
+
import { LogLevel } from './logger/logger';
|
|
3
|
+
declare enum ClientExtensionDebugTypes {
|
|
4
|
+
debug = "debug",
|
|
5
|
+
logging = "logging",
|
|
6
|
+
validation = "validation",
|
|
7
|
+
discovery = "discovery",
|
|
8
|
+
/** @since 2.1.0 */
|
|
9
|
+
logLevel = "logLevel"
|
|
10
|
+
}
|
|
11
|
+
declare type DebugTypeKeys = Exclude<keyof typeof ClientExtensionDebugTypes, 'logLevel'>;
|
|
12
|
+
export declare type ClientExtensionDebug = {
|
|
13
|
+
[key in DebugTypeKeys]: boolean;
|
|
14
|
+
} & {
|
|
15
|
+
[ClientExtensionDebugTypes.logLevel]: LogLevel;
|
|
16
|
+
};
|
|
17
|
+
export declare type ExposedClientExtensionDebug = {
|
|
18
|
+
[key in keyof ClientExtensionDebug]: PropertyDescriptor;
|
|
19
|
+
} & {
|
|
20
|
+
__initialized: PropertyDescriptor;
|
|
21
|
+
};
|
|
22
|
+
declare global {
|
|
23
|
+
interface Window {
|
|
24
|
+
____c_p_d: ExposedClientExtensionDebug;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export declare const observeStateChange: (observer: Observer<ClientExtensionDebug>) => import("@atlassian/clientside-extensions-base").Subscription;
|
|
28
|
+
export declare const isDebugEnabled: () => boolean;
|
|
29
|
+
export declare const isLoggingEnabled: () => boolean;
|
|
30
|
+
export declare const isValidationEnabled: () => boolean;
|
|
31
|
+
export declare const isDiscoveryEnabled: () => boolean;
|
|
32
|
+
/** @since 2.1.0 */
|
|
33
|
+
export declare const getLogLevel: () => LogLevel;
|
|
34
|
+
export declare const setDebugEnabled: (value: boolean) => void;
|
|
35
|
+
export declare const setLoggingEnabled: (value: boolean) => void;
|
|
36
|
+
export declare const setValidationEnabled: (value: boolean) => void;
|
|
37
|
+
export declare const setDiscoveryEnabled: (value: boolean) => void;
|
|
38
|
+
/** @since 2.1.0 */
|
|
39
|
+
export declare const setLogLevel: (value: string) => void;
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=debug-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-state.d.ts","sourceRoot":"","sources":["../../lib/debug-state.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAC;AAGtE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,aAAK,yBAAyB;IAC1B,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,SAAS,cAAc;IACvB,mBAAmB;IACnB,QAAQ,aAAa;CACxB;AAED,aAAK,aAAa,GAAG,OAAO,CAAC,MAAM,OAAO,yBAAyB,EAAE,UAAU,CAAC,CAAC;AAEjF,oBAAY,oBAAoB,GAAG;KAC9B,GAAG,IAAI,aAAa,GAAG,OAAO;CAClC,GAAG;IACA,CAAC,yBAAyB,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CAClD,CAAC;AAEF,oBAAY,2BAA2B,GAAG;KAAG,GAAG,IAAI,MAAM,oBAAoB,GAAG,kBAAkB;CAAE,GAAG;IACpG,aAAa,EAAE,kBAAkB,CAAC;CACrC,CAAC;AAEF,OAAO,CAAC,MAAM,CAAC;IAEX,UAAU,MAAM;QAGZ,SAAS,EAAE,2BAA2B,CAAC;KAC1C;CACJ;AAmHD,eAAO,MAAM,kBAAkB,aAAc,QAAQ,CAAC,oBAAoB,CAAC,iEACC,CAAC;AAE7E,eAAO,MAAM,cAAc,eAE1B,CAAC;AAEF,eAAO,MAAM,gBAAgB,eAE5B,CAAC;AAEF,eAAO,MAAM,mBAAmB,eAE/B,CAAC;AAEF,eAAO,MAAM,kBAAkB,eAE9B,CAAC;AAEF,mBAAmB;AACnB,eAAO,MAAM,WAAW,QAAO,QAI9B,CAAC;AAEF,eAAO,MAAM,eAAe,UAAW,OAAO,SAE7C,CAAC;AAEF,eAAO,MAAM,iBAAiB,UAAW,OAAO,SAE/C,CAAC;AAEF,eAAO,MAAM,oBAAoB,UAAW,OAAO,SAElD,CAAC;AAEF,eAAO,MAAM,mBAAmB,UAAW,OAAO,SAEjD,CAAC;AAEF,mBAAmB;AACnB,eAAO,MAAM,WAAW,UAAW,MAAM,SAIxC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-state.test.d.ts","sourceRoot":"","sources":["../../lib/debug-state.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Observer, Subject } from '@atlassian/clientside-extensions-base';
|
|
2
|
+
declare type ExposedClientExtensionSubjects = {
|
|
3
|
+
__initialized: PropertyDescriptor;
|
|
4
|
+
subjects: PropertyDescriptor;
|
|
5
|
+
};
|
|
6
|
+
export declare const enum DebugSubjects {
|
|
7
|
+
Logger = "logger",
|
|
8
|
+
State = "state"
|
|
9
|
+
}
|
|
10
|
+
declare global {
|
|
11
|
+
interface Window {
|
|
12
|
+
____c_p_s: ExposedClientExtensionSubjects;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
declare type UnpackPayloadType<SubjectType> = SubjectType extends Subject<infer U> ? U : never;
|
|
16
|
+
/**
|
|
17
|
+
* Registers a debug subject as singleton
|
|
18
|
+
*
|
|
19
|
+
* @param key
|
|
20
|
+
* @param subjectFactory
|
|
21
|
+
*/
|
|
22
|
+
export declare const registerDebugSubject: <SubjectType extends Subject<PayloadType>, PayloadType = UnpackPayloadType<SubjectType>>(key: DebugSubjects, subjectFactory: () => SubjectType) => SubjectType;
|
|
23
|
+
export declare const observeDebugSubject: <PayloadType>(key: DebugSubjects, observer: Observer<PayloadType>) => import("@atlassian/clientside-extensions-base").Subscription;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=debug-subjects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-subjects.d.ts","sourceRoot":"","sources":["../../lib/debug-subjects.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,uCAAuC,CAAC;AAE/E,aAAK,8BAA8B,GAAG;IAClC,aAAa,EAAE,kBAAkB,CAAC;IAClC,QAAQ,EAAE,kBAAkB,CAAC;CAChC,CAAC;AAEF,0BAAkB,aAAa;IAC3B,MAAM,WAAW;IACjB,KAAK,UAAU;CAClB;AAMD,OAAO,CAAC,MAAM,CAAC;IAEX,UAAU,MAAM;QAEZ,SAAS,EAAE,8BAA8B,CAAC;KAC7C;CACJ;AAuBD,aAAK,iBAAiB,CAAC,WAAW,IAAI,WAAW,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAEvF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,gGACxB,aAAa,mDAYrB,CAAC;AAEF,eAAO,MAAM,mBAAmB,qBAAsB,aAAa,kGAQlE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-subjects.test.d.ts","sourceRoot":"","sources":["../../lib/debug-subjects.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../lib/debug.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAiB,MAAM,iBAAiB,CAAC;AAIrE,eAAO,MAAM,OAAO,aAAc,cAAc,SAiB/C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.test.d.ts","sourceRoot":"","sources":["../../lib/debug.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { onDebug } from './debug';
|
|
2
|
+
export type { LoggerPayload } from './logger/logger';
|
|
3
|
+
export { LogLevel } from './logger/logger';
|
|
4
|
+
export {
|
|
5
|
+
/** @deprecated in 2.1.0 */ observeLogger,
|
|
6
|
+
/** @since in 2.1.0 */ setLogger, _deregisterDefaultLogger, } from './logger/default-logger';
|
|
7
|
+
export { /** @since in 2.1.0 */ consoleLogger } from './logger/console';
|
|
8
|
+
export { isDebugEnabled, isLoggingEnabled, isDiscoveryEnabled, isValidationEnabled, setDebugEnabled, setLoggingEnabled, setDiscoveryEnabled, setValidationEnabled, observeStateChange, } from './debug-state';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO;AACH,2BAA2B,CAAC,aAAa;AACzC,sBAAsB,CAAC,SAAS,EAChC,wBAAwB,GAC3B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,sBAAsB,CAAC,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAExE,OAAO,EACH,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,GACrB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../../lib/logger/console.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AA8C9C,eAAO,MAAM,aAAa,YAAa,aAAa,SA0BnD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.test.d.ts","sourceRoot":"","sources":["../../../lib/logger/console.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Observer, Subscription } from '@atlassian/clientside-extensions-base';
|
|
2
|
+
import type { LoggerPayload } from './logger';
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
____c_p_d_l_d?: Subscription;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* We need to keep and expose the "observeLogger" function for a legacy reason.
|
|
10
|
+
* It should be removed in CSEv3
|
|
11
|
+
*
|
|
12
|
+
* @deprecated
|
|
13
|
+
*/
|
|
14
|
+
export declare const observeLogger: (observer: Observer<LoggerPayload>) => Subscription;
|
|
15
|
+
export declare const defaultLogger: Subscription;
|
|
16
|
+
/**
|
|
17
|
+
* Added in CSE 2.1.0
|
|
18
|
+
*
|
|
19
|
+
* @param logger
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export declare const setLogger: (logger: Observer<LoggerPayload>) => void;
|
|
23
|
+
declare const deregisterDefaultLogger: () => void;
|
|
24
|
+
export { deregisterDefaultLogger as _deregisterDefaultLogger };
|
|
25
|
+
//# sourceMappingURL=default-logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-logger.d.ts","sourceRoot":"","sources":["../../../lib/logger/default-logger.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAGpF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAG9C,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QAEZ,aAAa,CAAC,EAAE,YAAY,CAAC;KAChC;CACJ;AAED;;;;;GAKG;AACH,eAAO,MAAM,aAAa,aAAc,QAAQ,CAAC,aAAa,CAAC,KAAG,YAEjE,CAAC;AAsBF,eAAO,MAAM,aAAa,cAA0B,CAAC;AAErD;;;;;GAKG;AACH,eAAO,MAAM,SAAS,WAAY,QAAQ,CAAC,aAAa,CAAC,KAAG,IAS3D,CAAC;AAEF,QAAA,MAAM,uBAAuB,YAAoC,CAAC;AAGlE,OAAO,EAAE,uBAAuB,IAAI,wBAAwB,EAAE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ReplaySubject } from '@atlassian/clientside-extensions-base';
|
|
2
|
+
export declare enum LogLevel {
|
|
3
|
+
debug = "DEBUG",
|
|
4
|
+
error = "ERROR",
|
|
5
|
+
warn = "WARN",
|
|
6
|
+
deprecation = "DEPRECATION",
|
|
7
|
+
info = "INFO"
|
|
8
|
+
}
|
|
9
|
+
export declare type LoggerCallback = (levels: typeof LogLevel) => LoggerPayload;
|
|
10
|
+
export declare type LoggerPayload = {
|
|
11
|
+
level: LogLevel;
|
|
12
|
+
message: string;
|
|
13
|
+
components?: string | string[];
|
|
14
|
+
meta?: {
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
declare const loggerSubject: ReplaySubject<LoggerPayload>;
|
|
19
|
+
export { loggerSubject as _loggerSubject };
|
|
20
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../lib/logger/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAGtE,oBAAY,QAAQ;IAChB,KAAK,UAAU;IACf,KAAK,UAAU;IACf,IAAI,SAAS;IACb,WAAW,gBAAgB;IAC3B,IAAI,SAAS;CAChB;AAED,oBAAY,cAAc,GAAG,CAAC,MAAM,EAAE,OAAO,QAAQ,KAAK,aAAa,CAAC;AAExE,oBAAY,aAAa,GAAG;IACxB,KAAK,EAAE,QAAQ,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC/B,IAAI,CAAC,EAAE;QACH,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KAC1B,CAAC;CACL,CAAC;AAEF,QAAA,MAAM,aAAa,8BAAyF,CAAC;AAG7G,OAAO,EAAE,aAAa,IAAI,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const observeStateChange = jest.fn();
|
|
2
|
+
const isDebugEnabled = jest.fn();
|
|
3
|
+
const isLoggingEnabled = jest.fn();
|
|
4
|
+
const isValidationEnabled = jest.fn();
|
|
5
|
+
const isDiscoveryEnabled = jest.fn();
|
|
6
|
+
|
|
7
|
+
export { observeStateChange, isDebugEnabled, isLoggingEnabled, isValidationEnabled, isDiscoveryEnabled };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/* eslint-disable no-underscore-dangle */
|
|
2
|
+
import { LogLevel } from './logger/logger';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Using async imports in order to test process.env.NODE_ENV usage in module
|
|
6
|
+
* https://stackoverflow.com/a/48042799
|
|
7
|
+
*/
|
|
8
|
+
describe('debug-state initialization', () => {
|
|
9
|
+
const ORIGINAL_NODE_ENV = process.env.NODE_ENV;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
// reset NODE_ENV to whatever it was.
|
|
13
|
+
process.env.NODE_ENV = ORIGINAL_NODE_ENV;
|
|
14
|
+
// reset cache of loaded modules. This will ensure that the module is re-initialized
|
|
15
|
+
// with the new NODE_ENV value
|
|
16
|
+
delete window.____c_p_d;
|
|
17
|
+
jest.resetModules();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should be set to FALSE if process.env.NODE_ENV is "production"', async () => {
|
|
21
|
+
process.env.NODE_ENV = 'production';
|
|
22
|
+
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
24
|
+
const debugStateModule = await import('./debug-state');
|
|
25
|
+
|
|
26
|
+
expect(window.____c_p_d.__initialized).toBe(true);
|
|
27
|
+
|
|
28
|
+
expect(window.____c_p_d.debug).toBe(false);
|
|
29
|
+
expect(window.____c_p_d.logging).toBe(false);
|
|
30
|
+
expect(window.____c_p_d.validation).toBe(false);
|
|
31
|
+
expect(window.____c_p_d.discovery).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should set the default log level to "ERROR" if process.env.NODE_ENV is "production"', async () => {
|
|
35
|
+
process.env.NODE_ENV = 'production';
|
|
36
|
+
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
38
|
+
await import('./debug-state');
|
|
39
|
+
|
|
40
|
+
expect(window.____c_p_d.__initialized).toBe(true);
|
|
41
|
+
expect(window.____c_p_d.logLevel).toBe(LogLevel.error);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should be set the default log level to "INFO" if process.env.NODE_ENV is different than "production"', async () => {
|
|
45
|
+
process.env.NODE_ENV = 'development';
|
|
46
|
+
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
48
|
+
await import('./debug-state');
|
|
49
|
+
|
|
50
|
+
expect(window.____c_p_d.__initialized).toBe(true);
|
|
51
|
+
expect(window.____c_p_d.logLevel).toBe(LogLevel.info);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/* eslint-disable no-underscore-dangle, jest/no-standalone-expect */
|
|
2
|
+
import cases from 'jest-in-case';
|
|
3
|
+
import type { ExposedClientExtensionDebug } from './debug-state';
|
|
4
|
+
import { isDebugEnabled, isDiscoveryEnabled, isLoggingEnabled, isValidationEnabled, getLogLevel, setLogLevel } from './debug-state';
|
|
5
|
+
import { LogLevel } from './logger/logger';
|
|
6
|
+
|
|
7
|
+
describe('debug utils', () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
(window.____c_p_d as unknown) = false;
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
cases(
|
|
13
|
+
'should be active if respective flag is set to TRUE',
|
|
14
|
+
(opts) => {
|
|
15
|
+
expect(opts.isUtil()).toBe(false);
|
|
16
|
+
|
|
17
|
+
// switch flag to TRUE
|
|
18
|
+
(window.____c_p_d as unknown) = { [opts.key]: true };
|
|
19
|
+
|
|
20
|
+
expect(opts.isUtil()).toBe(true);
|
|
21
|
+
|
|
22
|
+
// switch ALL false
|
|
23
|
+
(window.____c_p_d as unknown) = false;
|
|
24
|
+
|
|
25
|
+
expect(opts.isUtil()).toBe(false);
|
|
26
|
+
|
|
27
|
+
// switch ALL true
|
|
28
|
+
(window.____c_p_d as unknown) = true;
|
|
29
|
+
|
|
30
|
+
expect(opts.isUtil()).toBe(true);
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
isDebugEnabled: { isUtil: isDebugEnabled, key: 'debug' },
|
|
34
|
+
isLoggingEnabled: { isUtil: isLoggingEnabled, key: 'logging' },
|
|
35
|
+
isValidationEnabled: { isUtil: isValidationEnabled, key: 'validation' },
|
|
36
|
+
isDiscoveryEnabled: { isUtil: isDiscoveryEnabled, key: 'discovery' },
|
|
37
|
+
},
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
describe('log levels', () => {
|
|
41
|
+
let prevDebugState: ExposedClientExtensionDebug;
|
|
42
|
+
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
prevDebugState = window.____c_p_d;
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
afterEach(() => {
|
|
48
|
+
window.____c_p_d = prevDebugState;
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should allow to change the default log level using utils', () => {
|
|
52
|
+
expect(getLogLevel()).toBe(LogLevel.info);
|
|
53
|
+
|
|
54
|
+
setLogLevel(LogLevel.debug);
|
|
55
|
+
|
|
56
|
+
expect(getLogLevel()).toBe(LogLevel.debug);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should allow to change log level using global variable', () => {
|
|
60
|
+
// Change with enum
|
|
61
|
+
(window.____c_p_d.logLevel as LogLevel) = LogLevel.error;
|
|
62
|
+
expect(getLogLevel()).toBe(LogLevel.error);
|
|
63
|
+
|
|
64
|
+
// Change with string value
|
|
65
|
+
(window.____c_p_d.logLevel as string) = 'warn';
|
|
66
|
+
expect(getLogLevel()).toBe(LogLevel.warn);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('should fallback to a default "INFO" level when using unsupported runtime value', () => {
|
|
70
|
+
(window.____c_p_d.logLevel as string) = 'show-me-all-the-things';
|
|
71
|
+
|
|
72
|
+
expect(getLogLevel()).toBe(LogLevel.info);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('compatibility mode', () => {
|
|
77
|
+
it('should fallback to a default "INFO" level when "logLevel" property is missing e.g. CSE < 2.1.0', () => {
|
|
78
|
+
Object.defineProperty(window, '____c_p_d', {
|
|
79
|
+
value: {},
|
|
80
|
+
configurable: true,
|
|
81
|
+
writable: true,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
expect(getLogLevel()).toBe(LogLevel.info);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/* eslint-disable no-underscore-dangle */
|
|
2
|
+
|
|
3
|
+
import type { Observer } from '@atlassian/clientside-extensions-base';
|
|
4
|
+
import { ReplaySubject } from '@atlassian/clientside-extensions-base';
|
|
5
|
+
import { DebugSubjects, observeDebugSubject, registerDebugSubject } from './debug-subjects';
|
|
6
|
+
import { LogLevel } from './logger/logger';
|
|
7
|
+
|
|
8
|
+
enum ClientExtensionDebugTypes {
|
|
9
|
+
debug = 'debug',
|
|
10
|
+
logging = 'logging',
|
|
11
|
+
validation = 'validation',
|
|
12
|
+
discovery = 'discovery',
|
|
13
|
+
/** @since 2.1.0 */
|
|
14
|
+
logLevel = 'logLevel',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type DebugTypeKeys = Exclude<keyof typeof ClientExtensionDebugTypes, 'logLevel'>;
|
|
18
|
+
|
|
19
|
+
export type ClientExtensionDebug = {
|
|
20
|
+
[key in DebugTypeKeys]: boolean;
|
|
21
|
+
} & {
|
|
22
|
+
[ClientExtensionDebugTypes.logLevel]: LogLevel;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type ExposedClientExtensionDebug = { [key in keyof ClientExtensionDebug]: PropertyDescriptor } & {
|
|
26
|
+
__initialized: PropertyDescriptor;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
declare global {
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
31
|
+
interface Window {
|
|
32
|
+
// The global ____c_p_d is a primitive boolean value that holds additional properties
|
|
33
|
+
// Due to historical name changes the "p" still represents the old "plugin" nomenclature
|
|
34
|
+
____c_p_d: ExposedClientExtensionDebug;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const defineDebugGlobal = (previousGlobal: unknown) => {
|
|
39
|
+
// initialize as boolean
|
|
40
|
+
const debugGlobal = Object.create(null);
|
|
41
|
+
const debugStates: ClientExtensionDebug = {
|
|
42
|
+
debug: false,
|
|
43
|
+
logging: false,
|
|
44
|
+
validation: false,
|
|
45
|
+
discovery: false,
|
|
46
|
+
/** @since 2.1.0 */
|
|
47
|
+
// In dev mode we set default loglevel to INFO
|
|
48
|
+
logLevel: process.env.NODE_ENV === 'production' ? LogLevel.error : LogLevel.info,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const debugStateSubject = registerDebugSubject(DebugSubjects.State, () => new ReplaySubject(1));
|
|
52
|
+
|
|
53
|
+
const properties: ExposedClientExtensionDebug = {
|
|
54
|
+
debug: {
|
|
55
|
+
get() {
|
|
56
|
+
return debugStates.debug;
|
|
57
|
+
},
|
|
58
|
+
set(val: unknown) {
|
|
59
|
+
debugStates.debug = Boolean(val);
|
|
60
|
+
debugStateSubject.notify(debugStates);
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
logging: {
|
|
64
|
+
get() {
|
|
65
|
+
return debugStates.logging;
|
|
66
|
+
},
|
|
67
|
+
set(val: unknown) {
|
|
68
|
+
debugStates.logging = Boolean(val);
|
|
69
|
+
debugStateSubject.notify(debugStates);
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
validation: {
|
|
73
|
+
get() {
|
|
74
|
+
return debugStates.validation;
|
|
75
|
+
},
|
|
76
|
+
set(val: unknown) {
|
|
77
|
+
debugStates.validation = Boolean(val);
|
|
78
|
+
debugStateSubject.notify(debugStates);
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
discovery: {
|
|
82
|
+
get() {
|
|
83
|
+
return debugStates.discovery;
|
|
84
|
+
},
|
|
85
|
+
set(val: unknown) {
|
|
86
|
+
debugStates.discovery = Boolean(val);
|
|
87
|
+
debugStateSubject.notify(debugStates);
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
/** @since 2.1.0 */
|
|
91
|
+
logLevel: {
|
|
92
|
+
get() {
|
|
93
|
+
return debugStates.logLevel;
|
|
94
|
+
},
|
|
95
|
+
set(val: unknown) {
|
|
96
|
+
let level = String(val).toUpperCase() as LogLevel;
|
|
97
|
+
|
|
98
|
+
// Handle runtime errors
|
|
99
|
+
if (!Object.values(LogLevel).includes(level)) {
|
|
100
|
+
level = LogLevel.info;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
debugStates.logLevel = level;
|
|
104
|
+
debugStateSubject.notify(debugStates);
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
__initialized: { value: true, writable: false },
|
|
108
|
+
};
|
|
109
|
+
Object.defineProperties(debugGlobal, properties);
|
|
110
|
+
|
|
111
|
+
Object.defineProperty(window, '____c_p_d', {
|
|
112
|
+
configurable: true, // needed for testing :(
|
|
113
|
+
get() {
|
|
114
|
+
return debugGlobal;
|
|
115
|
+
},
|
|
116
|
+
set(val) {
|
|
117
|
+
// its a boolean
|
|
118
|
+
if (val === true || val === false) {
|
|
119
|
+
debugGlobal.debug = val;
|
|
120
|
+
debugGlobal.logging = val;
|
|
121
|
+
debugGlobal.validation = val;
|
|
122
|
+
debugGlobal.discovery = val;
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// we can handle booleans - like above
|
|
127
|
+
// or objects (except null) and nothing else.
|
|
128
|
+
if (typeof val !== 'object' || val === null) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const clientExtensionDebugKeys = Object.keys(ClientExtensionDebugTypes) as (keyof ClientExtensionDebug)[];
|
|
133
|
+
|
|
134
|
+
clientExtensionDebugKeys.forEach((key) => {
|
|
135
|
+
if (key in val) {
|
|
136
|
+
debugGlobal[key] = val[key];
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// Now, we can use the previous value e.g. boolean, to set the value for all flags
|
|
143
|
+
window.____c_p_d = previousGlobal as ExposedClientExtensionDebug;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// Register global value only once
|
|
147
|
+
if (!('____c_p_d' in window) || !window.____c_p_d.__initialized) {
|
|
148
|
+
defineDebugGlobal(window.____c_p_d ?? process.env.NODE_ENV !== 'production');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export const observeStateChange = (observer: Observer<ClientExtensionDebug>) =>
|
|
152
|
+
observeDebugSubject<ClientExtensionDebug>(DebugSubjects.State, observer);
|
|
153
|
+
|
|
154
|
+
export const isDebugEnabled = () => {
|
|
155
|
+
return window.____c_p_d.debug as boolean;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export const isLoggingEnabled = () => {
|
|
159
|
+
return window.____c_p_d.logging as boolean;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export const isValidationEnabled = () => {
|
|
163
|
+
return window.____c_p_d.validation as boolean;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export const isDiscoveryEnabled = () => {
|
|
167
|
+
return window.____c_p_d.discovery as boolean;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/** @since 2.1.0 */
|
|
171
|
+
export const getLogLevel = (): LogLevel => {
|
|
172
|
+
const logLevel = window.____c_p_d.logLevel as LogLevel;
|
|
173
|
+
|
|
174
|
+
return logLevel ?? LogLevel.info;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
export const setDebugEnabled = (value: boolean) => {
|
|
178
|
+
(window.____c_p_d.debug as boolean) = value;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
export const setLoggingEnabled = (value: boolean) => {
|
|
182
|
+
(window.____c_p_d.logging as boolean) = value;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
export const setValidationEnabled = (value: boolean) => {
|
|
186
|
+
(window.____c_p_d.validation as boolean) = value;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export const setDiscoveryEnabled = (value: boolean) => {
|
|
190
|
+
(window.____c_p_d.discovery as boolean) = value;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
/** @since 2.1.0 */
|
|
194
|
+
export const setLogLevel = (value: string) => {
|
|
195
|
+
const level = value.toUpperCase() as LogLevel;
|
|
196
|
+
|
|
197
|
+
(window.____c_p_d.logLevel as LogLevel) = level;
|
|
198
|
+
};
|