@xrmforge/devkit 0.7.13 → 0.7.15

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.
@@ -1,67 +1,67 @@
1
- /**
2
- * Structured logger for D365 form scripts.
3
- * This is the ONLY file allowed to use console.* directly.
4
- */
5
-
6
- /** Logger interface for structured logging with namespace prefix. */
7
- export interface Logger {
8
- debug(message: string, data?: unknown): void;
9
- info(message: string, data?: unknown): void;
10
- warn(message: string, data?: unknown): void;
11
- error(message: string, data?: unknown): void;
12
- }
13
-
14
- const DEBUG_STORAGE_KEY = '{{namespace}}.debug'.toLowerCase();
15
-
16
- /** Check if the current host is a dev/test environment. */
17
- function isDebugHost(): boolean {
18
- try {
19
- const url = Xrm.Utility.getGlobalContext().getClientUrl() ?? '';
20
- if (url.includes('-dev') || url.includes('-test')) return true;
21
- } catch {
22
- /* ignore */
23
- }
24
- return false;
25
- }
26
-
27
- /** Check if debug mode is enabled via localStorage. */
28
- function isDebugStorage(): boolean {
29
- try {
30
- return window?.localStorage?.getItem(DEBUG_STORAGE_KEY) === '1';
31
- } catch {
32
- return false;
33
- }
34
- }
35
-
36
- /**
37
- * Create a namespaced logger instance.
38
- *
39
- * Debug messages are only shown in dev/test environments or when
40
- * localStorage key is set to '1'.
41
- *
42
- * @param namespace - Prefix for all log messages (e.g. 'MyApp.Account')
43
- */
44
- export function createLogger(namespace: string): Logger {
45
- const prefix = `[${namespace}]`;
46
- const debugEnabled = isDebugHost() || isDebugStorage();
47
-
48
- return {
49
- debug(message, data) {
50
- if (!debugEnabled) return;
51
- if (data !== undefined) console.debug(prefix, message, data);
52
- else console.debug(prefix, message);
53
- },
54
- info(message, data) {
55
- if (data !== undefined) console.info(prefix, message, data);
56
- else console.info(prefix, message);
57
- },
58
- warn(message, data) {
59
- if (data !== undefined) console.warn(prefix, message, data);
60
- else console.warn(prefix, message);
61
- },
62
- error(message, data) {
63
- if (data !== undefined) console.error(prefix, message, data);
64
- else console.error(prefix, message);
65
- },
66
- };
67
- }
1
+ /**
2
+ * Structured logger for D365 form scripts.
3
+ * This is the ONLY file allowed to use console.* directly.
4
+ */
5
+
6
+ /** Logger interface for structured logging with namespace prefix. */
7
+ export interface Logger {
8
+ debug(message: string, data?: unknown): void;
9
+ info(message: string, data?: unknown): void;
10
+ warn(message: string, data?: unknown): void;
11
+ error(message: string, data?: unknown): void;
12
+ }
13
+
14
+ const DEBUG_STORAGE_KEY = '{{namespace}}.debug'.toLowerCase();
15
+
16
+ /** Check if the current host is a dev/test environment. */
17
+ function isDebugHost(): boolean {
18
+ try {
19
+ const url = Xrm.Utility.getGlobalContext().getClientUrl() ?? '';
20
+ if (url.includes('-dev') || url.includes('-test')) return true;
21
+ } catch {
22
+ /* ignore */
23
+ }
24
+ return false;
25
+ }
26
+
27
+ /** Check if debug mode is enabled via localStorage. */
28
+ function isDebugStorage(): boolean {
29
+ try {
30
+ return window?.localStorage?.getItem(DEBUG_STORAGE_KEY) === '1';
31
+ } catch {
32
+ return false;
33
+ }
34
+ }
35
+
36
+ /**
37
+ * Create a namespaced logger instance.
38
+ *
39
+ * Debug messages are only shown in dev/test environments or when
40
+ * localStorage key is set to '1'.
41
+ *
42
+ * @param namespace - Prefix for all log messages (e.g. 'MyApp.Account')
43
+ */
44
+ export function createLogger(namespace: string): Logger {
45
+ const prefix = `[${namespace}]`;
46
+ const debugEnabled = isDebugHost() || isDebugStorage();
47
+
48
+ return {
49
+ debug(message, data) {
50
+ if (!debugEnabled) return;
51
+ if (data !== undefined) console.debug(prefix, message, data);
52
+ else console.debug(prefix, message);
53
+ },
54
+ info(message, data) {
55
+ if (data !== undefined) console.info(prefix, message, data);
56
+ else console.info(prefix, message);
57
+ },
58
+ warn(message, data) {
59
+ if (data !== undefined) console.warn(prefix, message, data);
60
+ else console.warn(prefix, message);
61
+ },
62
+ error(message, data) {
63
+ if (data !== undefined) console.error(prefix, message, data);
64
+ else console.error(prefix, message);
65
+ },
66
+ };
67
+ }