@atlassian/clientside-extensions-debug 3.1.2-test9-85e70efb → 4.0.0-5d495e8a-m8zwocnp
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/dist/cjs/__mocks__/debug-state.mock.js +14 -0
- package/dist/cjs/__mocks__/debug-state.mock.js.map +1 -0
- package/dist/cjs/__mocks__/debug-subjects.mock.js +8 -0
- package/dist/cjs/__mocks__/debug-subjects.mock.js.map +1 -0
- package/dist/cjs/debug-state.js +83 -37
- package/dist/cjs/debug-state.js.map +1 -1
- package/dist/cjs/debug-subjects.js +22 -14
- package/dist/cjs/debug-subjects.js.map +1 -1
- package/dist/cjs/debug.js +18 -24
- package/dist/cjs/debug.js.map +1 -1
- package/dist/cjs/index.js +21 -8
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/logger/console.js +48 -51
- package/dist/cjs/logger/console.js.map +1 -1
- package/dist/cjs/logger/default-logger.js +50 -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/__mocks__/debug-state.mock.js +7 -0
- package/dist/esm/__mocks__/debug-state.mock.js.map +1 -0
- package/dist/esm/__mocks__/debug-subjects.mock.js +4 -0
- package/dist/esm/__mocks__/debug-subjects.mock.js.map +1 -0
- package/dist/esm/debug-state.js +69 -34
- package/dist/esm/debug-state.js.map +1 -1
- package/dist/esm/debug-subjects.js +20 -14
- package/dist/esm/debug-subjects.js.map +1 -1
- package/dist/esm/debug.js +16 -24
- package/dist/esm/debug.js.map +1 -1
- package/dist/esm/index.js +7 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/logger/console.js +44 -49
- package/dist/esm/logger/console.js.map +1 -1
- 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/__mocks__/debug-state.mock.d.ts +8 -0
- package/dist/types/__mocks__/debug-state.mock.d.ts.map +1 -0
- package/dist/types/__mocks__/debug-subjects.mock.d.ts +5 -0
- package/dist/types/__mocks__/debug-subjects.mock.d.ts.map +1 -0
- package/dist/types/debug-state.d.ts +19 -9
- package/dist/types/debug-state.d.ts.map +1 -1
- package/dist/types/debug-subjects.d.ts +16 -5
- package/dist/types/debug-subjects.d.ts.map +1 -1
- package/dist/types/debug.d.ts +2 -24
- package/dist/types/debug.d.ts.map +1 -1
- package/dist/types/index.d.ts +8 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/logger/console.d.ts +2 -8
- package/dist/types/logger/console.d.ts.map +1 -1
- 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/debug-state-env.test.ts +18 -9
- package/lib/debug-state.test.ts +53 -3
- package/lib/debug-state.ts +66 -17
- package/lib/{debug-subject.test.ts → debug-subjects.test.ts} +14 -11
- package/lib/debug-subjects.ts +39 -14
- package/lib/debug.test.ts +49 -11
- package/lib/debug.ts +16 -34
- package/lib/index.ts +20 -8
- package/lib/logger/console.test.ts +240 -0
- package/lib/logger/console.ts +50 -68
- package/lib/logger/default-logger.ts +67 -0
- package/lib/logger/logger.ts +26 -0
- package/package.json +12 -9
- package/dist/tsconfig.cjs.tsbuildinfo +0 -7329
- package/dist/tsconfig.tsbuildinfo +0 -7329
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isDiscoveryEnabled = exports.isValidationEnabled = exports.isLoggingEnabled = exports.isDebugEnabled = exports.observeStateChange = void 0;
|
|
4
|
+
const observeStateChange = jest.fn();
|
|
5
|
+
exports.observeStateChange = observeStateChange;
|
|
6
|
+
const isDebugEnabled = jest.fn();
|
|
7
|
+
exports.isDebugEnabled = isDebugEnabled;
|
|
8
|
+
const isLoggingEnabled = jest.fn();
|
|
9
|
+
exports.isLoggingEnabled = isLoggingEnabled;
|
|
10
|
+
const isValidationEnabled = jest.fn();
|
|
11
|
+
exports.isValidationEnabled = isValidationEnabled;
|
|
12
|
+
const isDiscoveryEnabled = jest.fn();
|
|
13
|
+
exports.isDiscoveryEnabled = isDiscoveryEnabled;
|
|
14
|
+
//# sourceMappingURL=debug-state.mock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-state.mock.js","sourceRoot":"","sources":["../../../lib/__mocks__/debug-state.mock.ts"],"names":[],"mappings":";;;AAAA,MAAM,kBAAkB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAM5B,gDAAkB;AAL3B,MAAM,cAAc,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAKJ,wCAAc;AAJ3C,MAAM,gBAAgB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAIU,4CAAgB;AAH7D,MAAM,mBAAmB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAGyB,kDAAmB;AAFlF,MAAM,kBAAkB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAE+C,gDAAkB","sourcesContent":["const observeStateChange = jest.fn();\nconst isDebugEnabled = jest.fn();\nconst isLoggingEnabled = jest.fn();\nconst isValidationEnabled = jest.fn();\nconst isDiscoveryEnabled = jest.fn();\n\nexport { observeStateChange, isDebugEnabled, isLoggingEnabled, isValidationEnabled, isDiscoveryEnabled };\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerDebugSubject = exports.observeDebugSubject = void 0;
|
|
4
|
+
const observeDebugSubject = jest.fn();
|
|
5
|
+
exports.observeDebugSubject = observeDebugSubject;
|
|
6
|
+
const registerDebugSubject = jest.fn();
|
|
7
|
+
exports.registerDebugSubject = registerDebugSubject;
|
|
8
|
+
//# sourceMappingURL=debug-subjects.mock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-subjects.mock.js","sourceRoot":"","sources":["../../../lib/__mocks__/debug-subjects.mock.ts"],"names":[],"mappings":";;;AAAA,MAAM,mBAAmB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAG7B,kDAAmB;AAF5B,MAAM,oBAAoB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAET,oDAAoB","sourcesContent":["const observeDebugSubject = jest.fn();\nconst registerDebugSubject = jest.fn();\n\nexport { observeDebugSubject, registerDebugSubject };\n"]}
|
package/dist/cjs/debug-state.js
CHANGED
|
@@ -1,72 +1,94 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable no-underscore-dangle */
|
|
3
|
+
var _a;
|
|
3
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.setDiscoveryEnabled = exports.setValidationEnabled = exports.setLoggingEnabled = exports.setDebugEnabled = exports.isDiscoveryEnabled = exports.isValidationEnabled = exports.isLoggingEnabled = exports.isDebugEnabled = exports.observeStateChange = void 0;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
exports.setLogLevel = exports.setDiscoveryEnabled = exports.setValidationEnabled = exports.setLoggingEnabled = exports.setDebugEnabled = exports.getLogLevel = exports.isDiscoveryEnabled = exports.isValidationEnabled = exports.isLoggingEnabled = exports.isDebugEnabled = exports.observeStateChange = void 0;
|
|
6
|
+
const clientside_extensions_base_1 = require("@atlassian/clientside-extensions-base");
|
|
7
|
+
const debug_subjects_1 = require("./debug-subjects");
|
|
8
|
+
const logger_1 = require("./logger/logger");
|
|
9
|
+
var ClientExtensionDebugTypes;
|
|
10
|
+
(function (ClientExtensionDebugTypes) {
|
|
11
|
+
ClientExtensionDebugTypes["debug"] = "debug";
|
|
12
|
+
ClientExtensionDebugTypes["logging"] = "logging";
|
|
13
|
+
ClientExtensionDebugTypes["validation"] = "validation";
|
|
14
|
+
ClientExtensionDebugTypes["discovery"] = "discovery";
|
|
15
|
+
/** @since 2.1.0 */
|
|
16
|
+
ClientExtensionDebugTypes["logLevel"] = "logLevel";
|
|
17
|
+
})(ClientExtensionDebugTypes || (ClientExtensionDebugTypes = {}));
|
|
18
|
+
const defineDebugGlobal = (previousGlobal) => {
|
|
15
19
|
// initialize as boolean
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
const debugGlobal = Object.create(null);
|
|
21
|
+
const debugStates = {
|
|
18
22
|
debug: false,
|
|
19
23
|
logging: false,
|
|
20
24
|
validation: false,
|
|
21
25
|
discovery: false,
|
|
26
|
+
/** @since 2.1.0 */
|
|
27
|
+
// In dev mode we set default loglevel to INFO
|
|
28
|
+
logLevel: process.env.NODE_ENV === 'production' ? logger_1.LogLevel.error : logger_1.LogLevel.info,
|
|
22
29
|
};
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
const debugStateSubject = (0, debug_subjects_1.registerDebugSubject)("state" /* State */, () => new clientside_extensions_base_1.ReplaySubject(1));
|
|
31
|
+
const properties = {
|
|
25
32
|
debug: {
|
|
26
|
-
get
|
|
33
|
+
get() {
|
|
27
34
|
return debugStates.debug;
|
|
28
35
|
},
|
|
29
|
-
set
|
|
36
|
+
set(val) {
|
|
30
37
|
debugStates.debug = Boolean(val);
|
|
31
38
|
debugStateSubject.notify(debugStates);
|
|
32
39
|
},
|
|
33
40
|
},
|
|
34
41
|
logging: {
|
|
35
|
-
get
|
|
42
|
+
get() {
|
|
36
43
|
return debugStates.logging;
|
|
37
44
|
},
|
|
38
|
-
set
|
|
45
|
+
set(val) {
|
|
39
46
|
debugStates.logging = Boolean(val);
|
|
40
47
|
debugStateSubject.notify(debugStates);
|
|
41
48
|
},
|
|
42
49
|
},
|
|
43
50
|
validation: {
|
|
44
|
-
get
|
|
51
|
+
get() {
|
|
45
52
|
return debugStates.validation;
|
|
46
53
|
},
|
|
47
|
-
set
|
|
54
|
+
set(val) {
|
|
48
55
|
debugStates.validation = Boolean(val);
|
|
49
56
|
debugStateSubject.notify(debugStates);
|
|
50
57
|
},
|
|
51
58
|
},
|
|
52
59
|
discovery: {
|
|
53
|
-
get
|
|
60
|
+
get() {
|
|
54
61
|
return debugStates.discovery;
|
|
55
62
|
},
|
|
56
|
-
set
|
|
63
|
+
set(val) {
|
|
57
64
|
debugStates.discovery = Boolean(val);
|
|
58
65
|
debugStateSubject.notify(debugStates);
|
|
59
66
|
},
|
|
60
67
|
},
|
|
68
|
+
/** @since 2.1.0 */
|
|
69
|
+
logLevel: {
|
|
70
|
+
get() {
|
|
71
|
+
return debugStates.logLevel;
|
|
72
|
+
},
|
|
73
|
+
set(val) {
|
|
74
|
+
let level = String(val).toUpperCase();
|
|
75
|
+
// Handle runtime errors
|
|
76
|
+
if (!Object.values(logger_1.LogLevel).includes(level)) {
|
|
77
|
+
level = logger_1.LogLevel.info;
|
|
78
|
+
}
|
|
79
|
+
debugStates.logLevel = level;
|
|
80
|
+
debugStateSubject.notify(debugStates);
|
|
81
|
+
},
|
|
82
|
+
},
|
|
61
83
|
__initialized: { value: true, writable: false },
|
|
62
84
|
};
|
|
63
85
|
Object.defineProperties(debugGlobal, properties);
|
|
64
86
|
Object.defineProperty(window, '____c_p_d', {
|
|
65
87
|
configurable: true,
|
|
66
|
-
get
|
|
88
|
+
get() {
|
|
67
89
|
return debugGlobal;
|
|
68
90
|
},
|
|
69
|
-
set
|
|
91
|
+
set(val) {
|
|
70
92
|
// its a boolean
|
|
71
93
|
if (val === true || val === false) {
|
|
72
94
|
debugGlobal.debug = val;
|
|
@@ -80,41 +102,65 @@ var defineDebugGlobal = function (previousGlobal) {
|
|
|
80
102
|
if (typeof val !== 'object' || val === null) {
|
|
81
103
|
return;
|
|
82
104
|
}
|
|
83
|
-
|
|
105
|
+
const clientExtensionDebugKeys = Object.keys(ClientExtensionDebugTypes);
|
|
106
|
+
clientExtensionDebugKeys.forEach((key) => {
|
|
84
107
|
if (key in val) {
|
|
85
108
|
debugGlobal[key] = val[key];
|
|
86
109
|
}
|
|
87
110
|
});
|
|
88
111
|
},
|
|
89
112
|
});
|
|
113
|
+
// Now, we can use the previous value e.g. boolean, to set the value for all flags
|
|
90
114
|
window.____c_p_d = previousGlobal;
|
|
91
115
|
};
|
|
92
|
-
|
|
93
|
-
|
|
116
|
+
// Register global value only once
|
|
117
|
+
if (!('____c_p_d' in window) || !window.____c_p_d.__initialized) {
|
|
118
|
+
defineDebugGlobal((_a = window.____c_p_d) !== null && _a !== void 0 ? _a : process.env.NODE_ENV !== 'production');
|
|
94
119
|
}
|
|
95
|
-
|
|
96
|
-
exports.
|
|
120
|
+
const observeStateChange = (observer) => (0, debug_subjects_1.observeDebugSubject)("state" /* State */, observer);
|
|
121
|
+
exports.observeStateChange = observeStateChange;
|
|
122
|
+
const isDebugEnabled = () => {
|
|
97
123
|
return window.____c_p_d.debug;
|
|
98
124
|
};
|
|
99
|
-
exports.
|
|
125
|
+
exports.isDebugEnabled = isDebugEnabled;
|
|
126
|
+
const isLoggingEnabled = () => {
|
|
100
127
|
return window.____c_p_d.logging;
|
|
101
128
|
};
|
|
102
|
-
exports.
|
|
129
|
+
exports.isLoggingEnabled = isLoggingEnabled;
|
|
130
|
+
const isValidationEnabled = () => {
|
|
103
131
|
return window.____c_p_d.validation;
|
|
104
132
|
};
|
|
105
|
-
exports.
|
|
133
|
+
exports.isValidationEnabled = isValidationEnabled;
|
|
134
|
+
const isDiscoveryEnabled = () => {
|
|
106
135
|
return window.____c_p_d.discovery;
|
|
107
136
|
};
|
|
108
|
-
exports.
|
|
137
|
+
exports.isDiscoveryEnabled = isDiscoveryEnabled;
|
|
138
|
+
/** @since 2.1.0 */
|
|
139
|
+
const getLogLevel = () => {
|
|
140
|
+
const logLevel = window.____c_p_d.logLevel;
|
|
141
|
+
return logLevel !== null && logLevel !== void 0 ? logLevel : logger_1.LogLevel.info;
|
|
142
|
+
};
|
|
143
|
+
exports.getLogLevel = getLogLevel;
|
|
144
|
+
const setDebugEnabled = (value) => {
|
|
109
145
|
window.____c_p_d.debug = value;
|
|
110
146
|
};
|
|
111
|
-
exports.
|
|
147
|
+
exports.setDebugEnabled = setDebugEnabled;
|
|
148
|
+
const setLoggingEnabled = (value) => {
|
|
112
149
|
window.____c_p_d.logging = value;
|
|
113
150
|
};
|
|
114
|
-
exports.
|
|
151
|
+
exports.setLoggingEnabled = setLoggingEnabled;
|
|
152
|
+
const setValidationEnabled = (value) => {
|
|
115
153
|
window.____c_p_d.validation = value;
|
|
116
154
|
};
|
|
117
|
-
exports.
|
|
155
|
+
exports.setValidationEnabled = setValidationEnabled;
|
|
156
|
+
const setDiscoveryEnabled = (value) => {
|
|
118
157
|
window.____c_p_d.discovery = value;
|
|
119
158
|
};
|
|
159
|
+
exports.setDiscoveryEnabled = setDiscoveryEnabled;
|
|
160
|
+
/** @since 2.1.0 */
|
|
161
|
+
const setLogLevel = (value) => {
|
|
162
|
+
const level = value.toUpperCase();
|
|
163
|
+
window.____c_p_d.logLevel = level;
|
|
164
|
+
};
|
|
165
|
+
exports.setLogLevel = setLogLevel;
|
|
120
166
|
//# sourceMappingURL=debug-state.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug-state.js","sourceRoot":"","sources":["../../lib/debug-state.ts"],"names":[],"mappings":";AAAA,yCAAyC;;;AAEzC,oFAAgF;AAChF,mDAA6E;AAE7E,IAAK,sBAKJ;AALD,WAAK,sBAAsB;IACvB,yCAAe,CAAA;IACf,6CAAmB,CAAA;IACnB,mDAAyB,CAAA;IACzB,iDAAuB,CAAA;AAC3B,CAAC,EALI,sBAAsB,KAAtB,sBAAsB,QAK1B;AAgBD,IAAM,iBAAiB,GAAG,UAAC,cAAuB;IAC9C,wBAAwB;IACxB,IAAM,WAAW,GAAG,MAAM,CAAC,M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7C,MAAM,CAAC,SAAS,CAAC,QAAqB,GAAG,KAAK,CAAC;AACpD,CAAC,CAAC;AAJW,QAAA,WAAW,eAItB","sourcesContent":["/* eslint-disable no-underscore-dangle */\n\nimport type { Observer } from '@atlassian/clientside-extensions-base';\nimport { ReplaySubject } from '@atlassian/clientside-extensions-base';\nimport { DebugSubjects, observeDebugSubject, registerDebugSubject } from './debug-subjects';\nimport { LogLevel } from './logger/logger';\n\nenum ClientExtensionDebugTypes {\n debug = 'debug',\n logging = 'logging',\n validation = 'validation',\n discovery = 'discovery',\n /** @since 2.1.0 */\n logLevel = 'logLevel',\n}\n\ntype DebugTypeKeys = Exclude<keyof typeof ClientExtensionDebugTypes, 'logLevel'>;\n\nexport type ClientExtensionDebug = {\n [key in DebugTypeKeys]: boolean;\n} & {\n [ClientExtensionDebugTypes.logLevel]: LogLevel;\n};\n\nexport type ExposedClientExtensionDebug = { [key in keyof ClientExtensionDebug]: PropertyDescriptor } & {\n __initialized: PropertyDescriptor;\n};\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Window {\n // The global ____c_p_d is a primitive boolean value that holds additional properties\n // Due to historical name changes the \"p\" still represents the old \"plugin\" nomenclature\n ____c_p_d: ExposedClientExtensionDebug;\n }\n}\n\nconst defineDebugGlobal = (previousGlobal: unknown) => {\n // initialize as boolean\n const debugGlobal = Object.create(null);\n const debugStates: ClientExtensionDebug = {\n debug: false,\n logging: false,\n validation: false,\n discovery: false,\n /** @since 2.1.0 */\n // In dev mode we set default loglevel to INFO\n logLevel: process.env.NODE_ENV === 'production' ? LogLevel.error : LogLevel.info,\n };\n\n const debugStateSubject = registerDebugSubject(DebugSubjects.State, () => new ReplaySubject(1));\n\n const properties: ExposedClientExtensionDebug = {\n debug: {\n get() {\n return debugStates.debug;\n },\n set(val: unknown) {\n debugStates.debug = Boolean(val);\n debugStateSubject.notify(debugStates);\n },\n },\n logging: {\n get() {\n return debugStates.logging;\n },\n set(val: unknown) {\n debugStates.logging = Boolean(val);\n debugStateSubject.notify(debugStates);\n },\n },\n validation: {\n get() {\n return debugStates.validation;\n },\n set(val: unknown) {\n debugStates.validation = Boolean(val);\n debugStateSubject.notify(debugStates);\n },\n },\n discovery: {\n get() {\n return debugStates.discovery;\n },\n set(val: unknown) {\n debugStates.discovery = Boolean(val);\n debugStateSubject.notify(debugStates);\n },\n },\n /** @since 2.1.0 */\n logLevel: {\n get() {\n return debugStates.logLevel;\n },\n set(val: unknown) {\n let level = String(val).toUpperCase() as LogLevel;\n\n // Handle runtime errors\n if (!Object.values(LogLevel).includes(level)) {\n level = LogLevel.info;\n }\n\n debugStates.logLevel = level;\n debugStateSubject.notify(debugStates);\n },\n },\n __initialized: { value: true, writable: false },\n };\n Object.defineProperties(debugGlobal, properties);\n\n Object.defineProperty(window, '____c_p_d', {\n configurable: true, // needed for testing :(\n get() {\n return debugGlobal;\n },\n set(val) {\n // its a boolean\n if (val === true || val === false) {\n debugGlobal.debug = val;\n debugGlobal.logging = val;\n debugGlobal.validation = val;\n debugGlobal.discovery = val;\n return;\n }\n\n // we can handle booleans - like above\n // or objects (except null) and nothing else.\n if (typeof val !== 'object' || val === null) {\n return;\n }\n\n const clientExtensionDebugKeys = Object.keys(ClientExtensionDebugTypes) as (keyof ClientExtensionDebug)[];\n\n clientExtensionDebugKeys.forEach((key) => {\n if (key in val) {\n debugGlobal[key] = val[key];\n }\n });\n },\n });\n\n // Now, we can use the previous value e.g. boolean, to set the value for all flags\n window.____c_p_d = previousGlobal as ExposedClientExtensionDebug;\n};\n\n// Register global value only once\nif (!('____c_p_d' in window) || !window.____c_p_d.__initialized) {\n defineDebugGlobal(window.____c_p_d ?? process.env.NODE_ENV !== 'production');\n}\n\nexport const observeStateChange = (observer: Observer<ClientExtensionDebug>) =>\n observeDebugSubject<ClientExtensionDebug>(DebugSubjects.State, observer);\n\nexport const isDebugEnabled = () => {\n return window.____c_p_d.debug as boolean;\n};\n\nexport const isLoggingEnabled = () => {\n return window.____c_p_d.logging as boolean;\n};\n\nexport const isValidationEnabled = () => {\n return window.____c_p_d.validation as boolean;\n};\n\nexport const isDiscoveryEnabled = () => {\n return window.____c_p_d.discovery as boolean;\n};\n\n/** @since 2.1.0 */\nexport const getLogLevel = (): LogLevel => {\n const logLevel = window.____c_p_d.logLevel as LogLevel;\n\n return logLevel ?? LogLevel.info;\n};\n\nexport const setDebugEnabled = (value: boolean) => {\n (window.____c_p_d.debug as boolean) = value;\n};\n\nexport const setLoggingEnabled = (value: boolean) => {\n (window.____c_p_d.logging as boolean) = value;\n};\n\nexport const setValidationEnabled = (value: boolean) => {\n (window.____c_p_d.validation as boolean) = value;\n};\n\nexport const setDiscoveryEnabled = (value: boolean) => {\n (window.____c_p_d.discovery as boolean) = value;\n};\n\n/** @since 2.1.0 */\nexport const setLogLevel = (value: string) => {\n const level = value.toUpperCase() as LogLevel;\n\n (window.____c_p_d.logLevel as LogLevel) = level;\n};\n"]}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.observeDebugSubject = exports.registerDebugSubject = void 0;
|
|
4
|
-
|
|
5
|
-
var clientside_extensions_base_1 = require("@atlassian/clientside-extensions-base");
|
|
6
|
-
var defineSubjectGlobal = function () {
|
|
4
|
+
const defineSubjectGlobal = () => {
|
|
7
5
|
// initialize as boolean
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const subjectGlobal = Object.create(null);
|
|
7
|
+
const properties = {
|
|
10
8
|
__initialized: { value: true, writable: false },
|
|
11
9
|
subjects: {
|
|
12
10
|
value: subjectGlobal,
|
|
@@ -16,21 +14,31 @@ var defineSubjectGlobal = function () {
|
|
|
16
14
|
Object.defineProperties(subjectGlobal, properties);
|
|
17
15
|
window.____c_p_s = subjectGlobal;
|
|
18
16
|
};
|
|
19
|
-
if (!
|
|
17
|
+
if (!('____c_p_s' in window) || !window.____c_p_s.__initialized) {
|
|
20
18
|
defineSubjectGlobal();
|
|
21
19
|
}
|
|
22
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Registers a debug subject as singleton
|
|
22
|
+
*
|
|
23
|
+
* @param key
|
|
24
|
+
* @param subjectFactory
|
|
25
|
+
*/
|
|
26
|
+
const registerDebugSubject = (key, subjectFactory) => {
|
|
27
|
+
const debugSubjects = window.____c_p_s.subjects;
|
|
23
28
|
// good old singletons - ensure we do not register the same subject twice.
|
|
24
29
|
// we also can't fail as multiple instances might try to access the same, so instead we return the previously registered one.
|
|
25
|
-
if (!
|
|
26
|
-
|
|
30
|
+
if (!(key in debugSubjects)) {
|
|
31
|
+
debugSubjects[key] = subjectFactory();
|
|
27
32
|
}
|
|
28
|
-
return
|
|
33
|
+
return debugSubjects[key];
|
|
29
34
|
};
|
|
30
|
-
exports.
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
exports.registerDebugSubject = registerDebugSubject;
|
|
36
|
+
const observeDebugSubject = (key, observer) => {
|
|
37
|
+
const debugSubjects = window.____c_p_s.subjects;
|
|
38
|
+
if (!(key in debugSubjects)) {
|
|
39
|
+
throw new Error(`No subject registered for key: "${key}"`);
|
|
33
40
|
}
|
|
34
|
-
return
|
|
41
|
+
return debugSubjects[key].subscribe(observer);
|
|
35
42
|
};
|
|
43
|
+
exports.observeDebugSubject = observeDebugSubject;
|
|
36
44
|
//# sourceMappingURL=debug-subjects.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug-subjects.js","sourceRoot":"","sources":["../../lib/debug-subjects.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"debug-subjects.js","sourceRoot":"","sources":["../../lib/debug-subjects.ts"],"names":[],"mappings":";;;AAyBA,MAAM,mBAAmB,GAAG,GAAG,EAAE;IAC7B,wBAAwB;IACxB,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAE1C,MAAM,UAAU,GAAmC;QAC/C,aAAa,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE;QAC/C,QAAQ,EAAE;YACN,KAAK,EAAE,aAAa;YACpB,QAAQ,EAAE,KAAK;SAClB;KACJ,CAAC;IAEF,MAAM,CAAC,gBAAgB,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;IAEnD,MAAM,CAAC,SAAS,GAAG,aAAa,CAAC;AACrC,CAAC,CAAC;AAEF,IAAI,CAAC,CAAC,WAAW,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,aAAa,EAAE;IAC7D,mBAAmB,EAAE,CAAC;CACzB;AAID;;;;;GAKG;AACI,MAAM,oBAAoB,GAAG,CAChC,GAAkB,EAClB,cAAiC,EACtB,EAAE;IACb,MAAM,aAAa,GAAG,MAAM,CAAC,SAAS,CAAC,QAAyC,CAAC;IAEjF,0EAA0E;IAC1E,6HAA6H;IAC7H,IAAI,CAAC,CAAC,GAAG,IAAI,aAAa,CAAC,EAAE;QACzB,aAAa,CAAC,GAAG,CAAC,GAAG,cAAc,EAAE,CAAC;KACzC;IAED,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC;AAC9B,CAAC,CAAC;AAbW,QAAA,oBAAoB,wBAa/B;AAEK,MAAM,mBAAmB,GAAG,CAAc,GAAkB,EAAE,QAA+B,EAAE,EAAE;IACpG,MAAM,aAAa,GAAG,MAAM,CAAC,SAAS,CAAC,QAAkD,CAAC;IAE1F,IAAI,CAAC,CAAC,GAAG,IAAI,aAAa,CAAC,EAAE;QACzB,MAAM,IAAI,KAAK,CAAC,mCAAmC,GAAG,GAAG,CAAC,CAAC;KAC9D;IAED,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;AAClD,CAAC,CAAC;AARW,QAAA,mBAAmB,uBAQ9B","sourcesContent":["/* eslint-disable no-underscore-dangle */\nimport type { Observer, Subject } from '@atlassian/clientside-extensions-base';\n\ntype ExposedClientExtensionSubjects = {\n __initialized: PropertyDescriptor;\n subjects: PropertyDescriptor;\n};\n\nexport const enum DebugSubjects {\n Logger = 'logger',\n State = 'state',\n}\n\ntype DebugSubjectsMap<SubjectT> = {\n [key in DebugSubjects]: SubjectT;\n};\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Window {\n // Due to historical name changes the \"p\" still represents the old \"plugin\" nomenclature\n ____c_p_s: ExposedClientExtensionSubjects;\n }\n}\n\nconst defineSubjectGlobal = () => {\n // initialize as boolean\n const subjectGlobal = Object.create(null);\n\n const properties: ExposedClientExtensionSubjects = {\n __initialized: { value: true, writable: false },\n subjects: {\n value: subjectGlobal,\n writable: false,\n },\n };\n\n Object.defineProperties(subjectGlobal, properties);\n\n window.____c_p_s = subjectGlobal;\n};\n\nif (!('____c_p_s' in window) || !window.____c_p_s.__initialized) {\n defineSubjectGlobal();\n}\n\ntype UnpackPayloadType<SubjectType> = SubjectType extends Subject<infer U> ? U : never;\n\n/**\n * Registers a debug subject as singleton\n *\n * @param key\n * @param subjectFactory\n */\nexport const registerDebugSubject = <SubjectType extends Subject<PayloadType>, PayloadType = UnpackPayloadType<SubjectType>>(\n key: DebugSubjects,\n subjectFactory: () => SubjectType,\n): SubjectType => {\n const debugSubjects = window.____c_p_s.subjects as DebugSubjectsMap<SubjectType>;\n\n // good old singletons - ensure we do not register the same subject twice.\n // we also can't fail as multiple instances might try to access the same, so instead we return the previously registered one.\n if (!(key in debugSubjects)) {\n debugSubjects[key] = subjectFactory();\n }\n\n return debugSubjects[key];\n};\n\nexport const observeDebugSubject = <PayloadType>(key: DebugSubjects, observer: Observer<PayloadType>) => {\n const debugSubjects = window.____c_p_s.subjects as DebugSubjectsMap<Subject<PayloadType>>;\n\n if (!(key in debugSubjects)) {\n throw new Error(`No subject registered for key: \"${key}\"`);\n }\n\n return debugSubjects[key].subscribe(observer);\n};\n"]}
|
package/dist/cjs/debug.js
CHANGED
|
@@ -1,29 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.onDebug =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var onDebug = function (callback) {
|
|
22
|
-
if (debug_state_1.isDebugEnabled()) {
|
|
23
|
-
var payload = callback(LogLevel);
|
|
24
|
-
if (payload && debug_state_1.isLoggingEnabled()) {
|
|
25
|
-
debuggerSubject.notify(payload);
|
|
26
|
-
}
|
|
3
|
+
exports.onDebug = void 0;
|
|
4
|
+
const debug_state_1 = require("./debug-state");
|
|
5
|
+
const logger_1 = require("./logger/logger");
|
|
6
|
+
// eslint-disable-next-line import/prefer-default-export
|
|
7
|
+
const onDebug = (callback) => {
|
|
8
|
+
// Return early if both debug and logging is disabled
|
|
9
|
+
if (!(0, debug_state_1.isDebugEnabled)() || !(0, debug_state_1.isLoggingEnabled)()) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
let payload;
|
|
13
|
+
try {
|
|
14
|
+
payload = callback(logger_1.LogLevel);
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
// eslint-disable-next-line no-empty
|
|
18
|
+
}
|
|
19
|
+
if (payload) {
|
|
20
|
+
logger_1._loggerSubject.notify(payload);
|
|
27
21
|
}
|
|
28
22
|
};
|
|
29
23
|
exports.onDebug = onDebug;
|
package/dist/cjs/debug.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug.js","sourceRoot":"","sources":["../../lib/debug.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"debug.js","sourceRoot":"","sources":["../../lib/debug.ts"],"names":[],"mappings":";;;AAAA,+CAAiE;AAGjE,4CAA2D;AAE3D,wDAAwD;AACjD,MAAM,OAAO,GAAG,CAAC,QAAwB,EAAE,EAAE;IAChD,qDAAqD;IACrD,IAAI,CAAC,IAAA,4BAAc,GAAE,IAAI,CAAC,IAAA,8BAAgB,GAAE,EAAE;QAC1C,OAAO;KACV;IAED,IAAI,OAAkC,CAAC;IAEvC,IAAI;QACA,OAAO,GAAG,QAAQ,CAAC,iBAAQ,CAAC,CAAC;KAChC;IAAC,OAAO,CAAC,EAAE;QACR,oCAAoC;KACvC;IAED,IAAI,OAAO,EAAE;QACT,uBAAc,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;KAClC;AACL,CAAC,CAAC;AAjBW,QAAA,OAAO,WAiBlB","sourcesContent":["import { isDebugEnabled, isLoggingEnabled } from './debug-state';\n\nimport type { LoggerCallback, LoggerPayload } from './logger/logger';\nimport { _loggerSubject, LogLevel } from './logger/logger';\n\n// eslint-disable-next-line import/prefer-default-export\nexport const onDebug = (callback: LoggerCallback) => {\n // Return early if both debug and logging is disabled\n if (!isDebugEnabled() || !isLoggingEnabled()) {\n return;\n }\n\n let payload: LoggerPayload | undefined;\n\n try {\n payload = callback(LogLevel);\n } catch (e) {\n // eslint-disable-next-line no-empty\n }\n\n if (payload) {\n _loggerSubject.notify(payload);\n }\n};\n"]}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._deregisterDefaultLogger = void 0;
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
exports.
|
|
3
|
+
exports.observeStateChange = exports.setValidationEnabled = exports.setDiscoveryEnabled = exports.setLoggingEnabled = exports.setDebugEnabled = exports.isValidationEnabled = exports.isDiscoveryEnabled = exports.isLoggingEnabled = exports.isDebugEnabled = exports.consoleLogger = exports._deregisterDefaultLogger = exports.setLogger = exports.observeLogger = exports.LogLevel = exports.onDebug = void 0;
|
|
4
|
+
var debug_1 = require("./debug");
|
|
5
|
+
Object.defineProperty(exports, "onDebug", { enumerable: true, get: function () { return debug_1.onDebug; } });
|
|
6
|
+
var logger_1 = require("./logger/logger");
|
|
7
|
+
Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return logger_1.LogLevel; } });
|
|
8
|
+
var default_logger_1 = require("./logger/default-logger");
|
|
9
|
+
/** @deprecated in 2.1.0 */ Object.defineProperty(exports, "observeLogger", { enumerable: true, get: function () { return default_logger_1.observeLogger; } });
|
|
10
|
+
/** @since in 2.1.0 */ Object.defineProperty(exports, "setLogger", { enumerable: true, get: function () { return default_logger_1.setLogger; } });
|
|
11
|
+
Object.defineProperty(exports, "_deregisterDefaultLogger", { enumerable: true, get: function () { return default_logger_1._deregisterDefaultLogger; } });
|
|
12
|
+
var console_1 = require("./logger/console");
|
|
13
|
+
Object.defineProperty(exports, "consoleLogger", { enumerable: true, get: function () { return console_1.consoleLogger; } });
|
|
14
|
+
var debug_state_1 = require("./debug-state");
|
|
15
|
+
Object.defineProperty(exports, "isDebugEnabled", { enumerable: true, get: function () { return debug_state_1.isDebugEnabled; } });
|
|
16
|
+
Object.defineProperty(exports, "isLoggingEnabled", { enumerable: true, get: function () { return debug_state_1.isLoggingEnabled; } });
|
|
17
|
+
Object.defineProperty(exports, "isDiscoveryEnabled", { enumerable: true, get: function () { return debug_state_1.isDiscoveryEnabled; } });
|
|
18
|
+
Object.defineProperty(exports, "isValidationEnabled", { enumerable: true, get: function () { return debug_state_1.isValidationEnabled; } });
|
|
19
|
+
Object.defineProperty(exports, "setDebugEnabled", { enumerable: true, get: function () { return debug_state_1.setDebugEnabled; } });
|
|
20
|
+
Object.defineProperty(exports, "setLoggingEnabled", { enumerable: true, get: function () { return debug_state_1.setLoggingEnabled; } });
|
|
21
|
+
Object.defineProperty(exports, "setDiscoveryEnabled", { enumerable: true, get: function () { return debug_state_1.setDiscoveryEnabled; } });
|
|
22
|
+
Object.defineProperty(exports, "setValidationEnabled", { enumerable: true, get: function () { return debug_state_1.setValidationEnabled; } });
|
|
23
|
+
Object.defineProperty(exports, "observeStateChange", { enumerable: true, get: function () { return debug_state_1.observeStateChange; } });
|
|
11
24
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":";;;AAAA,iCAAkC;AAAzB,gGAAA,OAAO,OAAA;AAEhB,0CAA2C;AAAlC,kGAAA,QAAQ,OAAA;AAEjB,0DAIiC;AAH7B,2BAA2B,CAAC,+GAAA,aAAa,OAAA;AACzC,sBAAsB,CAAC,2GAAA,SAAS,OAAA;AAChC,0HAAA,wBAAwB,OAAA;AAG5B,4CAAwE;AAAxC,wGAAA,aAAa,OAAA;AAE7C,6CAUuB;AATnB,6GAAA,cAAc,OAAA;AACd,+GAAA,gBAAgB,OAAA;AAChB,iHAAA,kBAAkB,OAAA;AAClB,kHAAA,mBAAmB,OAAA;AACnB,8GAAA,eAAe,OAAA;AACf,gHAAA,iBAAiB,OAAA;AACjB,kHAAA,mBAAmB,OAAA;AACnB,mHAAA,oBAAoB,OAAA;AACpB,iHAAA,kBAAkB,OAAA","sourcesContent":["export { onDebug } from './debug';\nexport type { LoggerPayload } from './logger/logger';\nexport { LogLevel } from './logger/logger';\n\nexport {\n /** @deprecated in 2.1.0 */ observeLogger,\n /** @since in 2.1.0 */ setLogger,\n _deregisterDefaultLogger,\n} from './logger/default-logger';\n\nexport { /** @since in 2.1.0 */ consoleLogger } from './logger/console';\n\nexport {\n isDebugEnabled,\n isLoggingEnabled,\n isDiscoveryEnabled,\n isValidationEnabled,\n setDebugEnabled,\n setLoggingEnabled,\n setDiscoveryEnabled,\n setValidationEnabled,\n observeStateChange,\n} from './debug-state';\n"]}
|
|
@@ -1,68 +1,65 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
exports.consoleLogger = void 0;
|
|
4
|
+
const logger_1 = require("./logger");
|
|
5
|
+
const debug_state_1 = require("../debug-state");
|
|
6
|
+
const getLoggingFromLevel = (level) => {
|
|
5
7
|
switch (level) {
|
|
6
|
-
case
|
|
8
|
+
case logger_1.LogLevel.error:
|
|
7
9
|
return 'error';
|
|
8
|
-
case
|
|
10
|
+
case logger_1.LogLevel.debug:
|
|
9
11
|
return 'debug';
|
|
10
|
-
case
|
|
12
|
+
case logger_1.LogLevel.info:
|
|
11
13
|
return 'info';
|
|
12
|
-
case
|
|
13
|
-
|
|
14
|
-
case debug_1.LogLevel.warn:
|
|
14
|
+
case logger_1.LogLevel.warn:
|
|
15
|
+
case logger_1.LogLevel.deprecation:
|
|
15
16
|
return 'warn';
|
|
16
17
|
default:
|
|
17
18
|
return 'debug';
|
|
18
19
|
}
|
|
19
20
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
// Naive implementation but we can't use bitwise operators :(
|
|
22
|
+
const debugLevels = Object.values(logger_1.LogLevel);
|
|
23
|
+
const errorLevels = debugLevels.filter((level) => level !== logger_1.LogLevel.debug);
|
|
24
|
+
const warnLevels = errorLevels.filter((level) => level !== logger_1.LogLevel.error);
|
|
25
|
+
const deprecationLevels = warnLevels.filter((level) => level !== logger_1.LogLevel.warn);
|
|
26
|
+
const infoLevels = deprecationLevels.filter((level) => level !== logger_1.LogLevel.deprecation);
|
|
27
|
+
const levelsMap = {
|
|
28
|
+
[logger_1.LogLevel.debug]: debugLevels,
|
|
29
|
+
[logger_1.LogLevel.error]: errorLevels,
|
|
30
|
+
[logger_1.LogLevel.warn]: warnLevels,
|
|
31
|
+
[logger_1.LogLevel.deprecation]: deprecationLevels,
|
|
32
|
+
[logger_1.LogLevel.info]: infoLevels,
|
|
26
33
|
};
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
return
|
|
30
|
-
}
|
|
31
|
-
if (value === undefined) {
|
|
32
|
-
return 'undefined';
|
|
33
|
-
}
|
|
34
|
-
if (Array.isArray(value)) {
|
|
35
|
-
return value.join(', ');
|
|
34
|
+
function shouldDisplayLog(logLevel, eventLogLevel) {
|
|
35
|
+
if (logLevel === logger_1.LogLevel.debug) {
|
|
36
|
+
return true;
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
const levels = levelsMap[logLevel];
|
|
39
|
+
return Array.isArray(levels) ? levels.includes(eventLogLevel) : false;
|
|
40
|
+
}
|
|
41
|
+
// eslint-disable-next-line import/prefer-default-export
|
|
42
|
+
const consoleLogger = (payload) => {
|
|
43
|
+
const eventLogLevel = payload.level;
|
|
44
|
+
const logLevel = (0, debug_state_1.getLogLevel)();
|
|
45
|
+
if (!shouldDisplayLog(logLevel, eventLogLevel)) {
|
|
46
|
+
return;
|
|
39
47
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// Singleton workaround as this module may be executed more than once.
|
|
55
|
-
// We only ever want one global default logger, however.
|
|
56
|
-
if (window.____c_p_d_l_d) {
|
|
57
|
-
return window.____c_p_d_l_d;
|
|
48
|
+
const consoleKey = getLoggingFromLevel(eventLogLevel);
|
|
49
|
+
const deprecationWarning = payload.level === logger_1.LogLevel.deprecation
|
|
50
|
+
? `⚠️⚠️⚠️ DEPRECATION WARNING ⚠️⚠️⚠️
|
|
51
|
+
`
|
|
52
|
+
: '';
|
|
53
|
+
console[consoleKey](`${deprecationWarning}[Atlassian Client-side Extensions]: ${payload.message}`);
|
|
54
|
+
// Verbose logging
|
|
55
|
+
if (logLevel === logger_1.LogLevel.debug) {
|
|
56
|
+
console.groupCollapsed(' <click here for more details about above message>');
|
|
57
|
+
console.log({
|
|
58
|
+
components: payload.components,
|
|
59
|
+
meta: payload.meta,
|
|
60
|
+
});
|
|
61
|
+
console.groupEnd();
|
|
58
62
|
}
|
|
59
|
-
window.____c_p_d_l_d = debug_1.observeLogger(function (payload) {
|
|
60
|
-
var consoleKey = getLoggingFromLevel(payload.level);
|
|
61
|
-
// eslint-disable-next-line no-console
|
|
62
|
-
console[consoleKey]("[Atlassian Client-side Extensions]\n" + componentsToReadable(payload.components) + "\n\n" + payload.message + "\n\n" + metaToReadable(payload.meta) + "\n");
|
|
63
|
-
});
|
|
64
|
-
return window.____c_p_d_l_d;
|
|
65
63
|
};
|
|
66
|
-
|
|
67
|
-
exports.default = registerConsoleLogger;
|
|
64
|
+
exports.consoleLogger = consoleLogger;
|
|
68
65
|
//# sourceMappingURL=console.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console.js","sourceRoot":"","sources":["../../../lib/logger/console.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"console.js","sourceRoot":"","sources":["../../../lib/logger/console.ts"],"names":[],"mappings":";;;AACA,qCAAoC;AACpC,gDAA6C;AAK7C,MAAM,mBAAmB,GAAG,CAAC,KAAe,EAAoB,EAAE;IAC9D,QAAQ,KAAK,EAAE;QACX,KAAK,iBAAQ,CAAC,KAAK;YACf,OAAO,OAAO,CAAC;QACnB,KAAK,iBAAQ,CAAC,KAAK;YACf,OAAO,OAAO,CAAC;QACnB,KAAK,iBAAQ,CAAC,IAAI;YACd,OAAO,MAAM,CAAC;QAClB,KAAK,iBAAQ,CAAC,IAAI,CAAC;QACnB,KAAK,iBAAQ,CAAC,WAAW;YACrB,OAAO,MAAM,CAAC;QAClB;YACI,OAAO,OAAO,CAAC;KACtB;AACL,CAAC,CAAC;AAEF,6DAA6D;AAC7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CAAC,OAAsB,EAAE,EAAE;IACpD,MAAM,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC;IACpC,MAAM,QAAQ,GAAG,IAAA,yBAAW,GAAE,CAAC;IAE/B,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,aAAa,CAAC,EAAE;QAC5C,OAAO;KACV;IAED,MAAM,UAAU,GAAG,mBAAmB,CAAC,aAAa,CAAC,CAAC;IACtD,MAAM,kBAAkB,GACpB,OAAO,CAAC,KAAK,KAAK,iBAAQ,CAAC,WAAW;QAClC,CAAC,CAAC;CACb;QACW,CAAC,CAAC,EAAE,CAAC;IAEb,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,kBAAkB,uCAAuC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAEnG,kBAAkB;IAClB,IAAI,QAAQ,KAAK,iBAAQ,CAAC,KAAK,EAAE;QAC7B,OAAO,CAAC,cAAc,CAAC,qDAAqD,CAAC,CAAC;QAC9E,OAAO,CAAC,GAAG,CAAC;YACR,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,IAAI,EAAE,OAAO,CAAC,IAAI;SACrB,CAAC,CAAC;QACH,OAAO,CAAC,QAAQ,EAAE,CAAC;KACtB;AACL,CAAC,CAAC;AA1BW,QAAA,aAAa,iBA0BxB","sourcesContent":["import type { LoggerPayload } from './logger';\nimport { LogLevel } from './logger';\nimport { getLogLevel } from '../debug-state';\n\n// We need to pick the callable keys from the console object\ntype ConsoleLogsTypes = keyof Pick<typeof console, 'log' | 'warn' | 'error' | 'info' | 'debug'>;\n\nconst getLoggingFromLevel = (level: LogLevel): ConsoleLogsTypes => {\n switch (level) {\n case LogLevel.error:\n return 'error';\n case LogLevel.debug:\n return 'debug';\n case LogLevel.info:\n return 'info';\n case LogLevel.warn:\n case LogLevel.deprecation:\n return 'warn';\n default:\n return 'debug';\n }\n};\n\n// Naive implementation but we can't use bitwise operators :(\nconst debugLevels = Object.values(LogLevel);\nconst errorLevels = debugLevels.filter((level) => level !== LogLevel.debug);\nconst warnLevels = errorLevels.filter((level) => level !== LogLevel.error);\nconst deprecationLevels = warnLevels.filter((level) => level !== LogLevel.warn);\nconst infoLevels = deprecationLevels.filter((level) => level !== LogLevel.deprecation);\n\nconst levelsMap: { [key: string]: string[] } = {\n [LogLevel.debug]: debugLevels,\n [LogLevel.error]: errorLevels,\n [LogLevel.warn]: warnLevels,\n [LogLevel.deprecation]: deprecationLevels,\n [LogLevel.info]: infoLevels,\n};\n\nfunction shouldDisplayLog(logLevel: LogLevel, eventLogLevel: LogLevel) {\n if (logLevel === LogLevel.debug) {\n return true;\n }\n\n const levels = levelsMap[logLevel];\n\n return Array.isArray(levels) ? levels.includes(eventLogLevel) : false;\n}\n\n// eslint-disable-next-line import/prefer-default-export\nexport const consoleLogger = (payload: LoggerPayload) => {\n const eventLogLevel = payload.level;\n const logLevel = getLogLevel();\n\n if (!shouldDisplayLog(logLevel, eventLogLevel)) {\n return;\n }\n\n const consoleKey = getLoggingFromLevel(eventLogLevel);\n const deprecationWarning =\n payload.level === LogLevel.deprecation\n ? `⚠️⚠️⚠️ DEPRECATION WARNING ⚠️⚠️⚠️\n`\n : '';\n\n console[consoleKey](`${deprecationWarning}[Atlassian Client-side Extensions]: ${payload.message}`);\n\n // Verbose logging\n if (logLevel === LogLevel.debug) {\n console.groupCollapsed(' <click here for more details about above message>');\n console.log({\n components: payload.components,\n meta: payload.meta,\n });\n console.groupEnd();\n }\n};\n"]}
|