@xiboplayer/utils 0.1.3 → 0.3.0

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/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # @xiboplayer/utils
2
+
3
+ **Shared utilities for all XiboPlayer SDK packages.**
4
+
5
+ ## Overview
6
+
7
+ Foundation utilities used across the SDK:
8
+
9
+ - **Logger** — structured logging with configurable levels (`DEBUG`, `INFO`, `WARNING`, `ERROR`) and per-module tags
10
+ - **EventEmitter** — lightweight pub/sub event system
11
+ - **fetchWithRetry** — HTTP fetch with exponential backoff, jitter, and configurable retries
12
+ - **CMS REST client** — JSON API client with ETag caching
13
+ - **Config** — hardware key management and IndexedDB-backed configuration
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @xiboplayer/utils
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ```javascript
24
+ import { createLogger, EventEmitter, fetchWithRetry } from '@xiboplayer/utils';
25
+
26
+ const log = createLogger('my-module');
27
+ log.info('Starting...');
28
+ log.debug('Detailed info');
29
+
30
+ const emitter = new EventEmitter();
31
+ emitter.on('event', (data) => console.log(data));
32
+
33
+ const response = await fetchWithRetry(url, { retries: 3 });
34
+ ```
35
+
36
+ ## Exports
37
+
38
+ | Export | Description |
39
+ |--------|-------------|
40
+ | `createLogger(tag)` | Create a tagged logger instance |
41
+ | `EventEmitter` | Pub/sub event emitter |
42
+ | `fetchWithRetry(url, opts)` | Fetch with exponential backoff |
43
+ | `Config` | Hardware key and IndexedDB config management |
44
+
45
+ ---
46
+
47
+ **Part of the [XiboPlayer SDK](https://github.com/linuxnow/xiboplayer)**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiboplayer/utils",
3
- "version": "0.1.3",
3
+ "version": "0.3.0",
4
4
  "description": "Shared utilities for Xibo Player packages",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  // @xiboplayer/utils - Shared utilities
2
+ import pkg from '../package.json' with { type: 'json' };
3
+ export const VERSION = pkg.version;
2
4
  export { createLogger, setLogLevel, getLogLevel, isDebug, applyCmsLogLevel, mapCmsLogLevel, registerLogSink, unregisterLogSink, LOG_LEVELS } from './logger.js';
3
5
  export { EventEmitter } from './event-emitter.js';
4
6
  export { config } from './config.js';
package/src/logger.js CHANGED
@@ -7,7 +7,10 @@
7
7
  * 1. URL param ?logLevel=DEBUG
8
8
  * 2. localStorage xibo_log_level
9
9
  * 3. CMS setting via RegisterDisplay (call applyCmsLogLevel())
10
- * 4. Default: DEBUG on localhost, INFO in production
10
+ * 4. Default: WARNING (production-safe)
11
+ *
12
+ * For development, pass ?logLevel=DEBUG in the URL.
13
+ * Electron's --dev flag does this automatically.
11
14
  *
12
15
  * Loggers created without an explicit level are REACTIVE — they follow
13
16
  * the global level at call time, so setLogLevel() affects all of them.
@@ -93,7 +96,7 @@ class Logger {
93
96
 
94
97
  // Global log level configuration
95
98
  const globalConfig = {
96
- level: LOG_LEVELS.INFO, // Default: INFO and above
99
+ level: LOG_LEVELS.WARNING, // Default: WARNING (production-safe)
97
100
 
98
101
  setGlobalLevel(level) {
99
102
  if (typeof level === 'string') {
@@ -114,6 +117,8 @@ const globalConfig = {
114
117
  let hasLocalOverride = false;
115
118
 
116
119
  // Set global level from environment or localStorage
120
+ // Default: WARNING (production-safe). Use ?logLevel=DEBUG for development,
121
+ // or let the CMS override via applyCmsLogLevel().
117
122
  if (typeof window !== 'undefined') {
118
123
  const urlParams = new URLSearchParams(window.location.search);
119
124
  const urlLevel = urlParams.get('logLevel');
@@ -125,12 +130,8 @@ if (typeof window !== 'undefined') {
125
130
  } else if (storageLevel) {
126
131
  globalConfig.setGlobalLevel(storageLevel);
127
132
  hasLocalOverride = true;
128
- } else if (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') {
129
- // Development mode - debug logging
130
- globalConfig.setGlobalLevel('DEBUG');
131
133
  } else {
132
- // Production mode - INFO by default (CMS can override later)
133
- globalConfig.setGlobalLevel('INFO');
134
+ globalConfig.setGlobalLevel('WARNING');
134
135
  }
135
136
  }
136
137
 
@@ -33,13 +33,13 @@ describe('Logger', () => {
33
33
  });
34
34
 
35
35
  describe('Logger Creation', () => {
36
- it('should create logger with default INFO level', () => {
36
+ it('should create logger with default WARNING level', () => {
37
37
  const logger = createLogger('TestModule');
38
38
 
39
39
  expect(logger.name).toBe('TestModule');
40
40
  // When no explicit level is given, logger follows global level (useGlobal=true)
41
41
  // so logger.level is undefined — check getEffectiveLevel() instead
42
- expect(logger.getEffectiveLevel()).toBeLessThanOrEqual(LOG_LEVELS.INFO);
42
+ expect(logger.getEffectiveLevel()).toBeLessThanOrEqual(LOG_LEVELS.WARNING);
43
43
  });
44
44
 
45
45
  it('should create logger with custom level', () => {
package/docs/README.md DELETED
@@ -1,61 +0,0 @@
1
- # @xiboplayer/utils Documentation
2
-
3
- **Shared utilities for all Xibo Player packages.**
4
-
5
- ## Overview
6
-
7
- Common utilities:
8
-
9
- - **Logger** - Structured logging
10
- - **EventEmitter** - Pub/sub event bus
11
- - **Config** - Configuration management
12
- - **Helpers** - Utility functions
13
-
14
- ## Installation
15
-
16
- ```bash
17
- npm install @xiboplayer/utils
18
- ```
19
-
20
- ## Usage
21
-
22
- ```javascript
23
- import { Logger, EventEmitter } from '@xiboplayer/utils';
24
-
25
- // Logger
26
- const log = new Logger('MyModule');
27
- log.info('Message', { data: 123 });
28
-
29
- // EventEmitter
30
- const emitter = new EventEmitter();
31
- emitter.on('event', (data) => console.log(data));
32
- emitter.emit('event', { foo: 'bar' });
33
- ```
34
-
35
- ## API Reference
36
-
37
- ### Logger
38
-
39
- ```javascript
40
- logger.debug(message, data)
41
- logger.info(message, data)
42
- logger.warn(message, data)
43
- logger.error(message, data)
44
- ```
45
-
46
- ### EventEmitter
47
-
48
- ```javascript
49
- emitter.on(event, callback)
50
- emitter.once(event, callback)
51
- emitter.off(event, callback)
52
- emitter.emit(event, data)
53
- ```
54
-
55
- ## Dependencies
56
-
57
- None (zero dependencies)
58
-
59
- ---
60
-
61
- **Package Version**: 1.0.0