@hkdigital/lib-core 0.4.14 → 0.4.16

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.
Files changed (40) hide show
  1. package/dist/auth/jwt/util.js +2 -0
  2. package/dist/auth/jwt.d.ts +1 -0
  3. package/dist/auth/jwt.js +1 -1
  4. package/dist/constants/bases.d.ts +1 -0
  5. package/dist/constants/bases.js +1 -0
  6. package/dist/constants/http.d.ts +2 -0
  7. package/dist/constants/http.js +2 -0
  8. package/dist/constants/mime.d.ts +4 -0
  9. package/dist/constants/mime.js +4 -0
  10. package/dist/constants/regexp.d.ts +3 -0
  11. package/dist/constants/regexp.js +3 -0
  12. package/dist/constants/states/drag.d.ts +1 -1
  13. package/dist/constants/states/drag.js +1 -1
  14. package/dist/constants/states/submit.d.ts +1 -1
  15. package/dist/constants/states/submit.js +1 -1
  16. package/dist/constants/states.d.ts +4 -0
  17. package/dist/constants/states.js +4 -0
  18. package/dist/constants/time.d.ts +1 -0
  19. package/dist/constants/time.js +1 -0
  20. package/dist/logging/README.md +5 -14
  21. package/dist/logging/internal/logger/Logger.d.ts +7 -3
  22. package/dist/logging/internal/logger/Logger.js +83 -25
  23. package/dist/logging/internal/logger/util.d.ts +13 -0
  24. package/dist/logging/internal/logger/util.js +47 -0
  25. package/dist/network/http/errors.js +2 -2
  26. package/dist/network/http/index.js +2 -2
  27. package/dist/network/http/mocks.js +2 -2
  28. package/dist/network/loaders/audio/mocks.js +1 -1
  29. package/dist/network/loaders/image/mocks.js +1 -1
  30. package/dist/network/states/NetworkLoader.svelte.js +1 -1
  31. package/dist/network/states/mocks.js +1 -1
  32. package/dist/services/README.md +2 -2
  33. package/dist/ui/components/drag-drop/Draggable.svelte +7 -7
  34. package/dist/util/is/events.d.ts +16 -0
  35. package/dist/util/is/events.js +25 -0
  36. package/dist/util/is/index.d.ts +1 -0
  37. package/dist/util/is/index.js +2 -0
  38. package/package.json +1 -1
  39. package/dist/constants/index.d.ts +0 -6
  40. package/dist/constants/index.js +0 -6
@@ -124,6 +124,8 @@ export function verify( token, secretOrPrivateKey, options=VERIFY_OPTIONS )
124
124
  }
125
125
  }
126
126
 
127
+ // Internals
128
+
127
129
  /**
128
130
  * Casts jsonwebtoken library errors to internal error types
129
131
  * @param {Error} error - The original jsonwebtoken error
@@ -1,3 +1,4 @@
1
+ export * from "./jwt/util.js";
1
2
  export * from "./jwt/generators.js";
2
3
  export * from "./jwt/errors.js";
3
4
  export * from "./jwt/constants.js";
package/dist/auth/jwt.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * verifying tokens, and generating secret keys.
7
7
  */
8
8
 
9
- export * from './jwt/core.js';
9
+ export * from './jwt/util.js';
10
10
  export * from './jwt/generators.js';
11
11
  export * from './jwt/errors.js';
12
12
  export * from './jwt/constants.js';
@@ -0,0 +1 @@
1
+ export * from "./bases/index.js";
@@ -0,0 +1 @@
1
+ export * from './bases/index.js';
@@ -0,0 +1,2 @@
1
+ export * from "./http/headers.js";
2
+ export * from "./http/methods.js";
@@ -0,0 +1,2 @@
1
+ export * from './http/headers.js';
2
+ export * from './http/methods.js';
@@ -0,0 +1,4 @@
1
+ export * from "./mime/application.js";
2
+ export * from "./mime/audio.js";
3
+ export * from "./mime/text.js";
4
+ export * from "./mime/image.js";
@@ -0,0 +1,4 @@
1
+ export * from './mime/application.js';
2
+ export * from './mime/audio.js';
3
+ export * from './mime/text.js';
4
+ export * from './mime/image.js';
@@ -0,0 +1,3 @@
1
+ export * from "./regexp/text.js";
2
+ export * from "./regexp/url.js";
3
+ export * from "./regexp/user.js";
@@ -0,0 +1,3 @@
1
+ export * from './regexp/text.js';
2
+ export * from './regexp/url.js';
3
+ export * from './regexp/user.js';
@@ -1,4 +1,4 @@
1
- export const IDLE: "idle";
1
+ export const DRAG_IDLE: "idle";
2
2
  export const DRAGGING: "dragging";
3
3
  export const DRAG_PREVIEW: "drag-preview";
4
4
  export const DROPPING: "dropping";
@@ -1,5 +1,5 @@
1
1
  // Draggable states
2
- export const IDLE = 'idle'; // Not being dragged
2
+ export const DRAG_IDLE = 'idle'; // Not being dragged
3
3
  export const DRAGGING = 'dragging'; // Currently being dragged
4
4
  export const DRAG_PREVIEW = 'drag-preview'; // Mouse down, before drag
5
5
  export const DROPPING = 'dropping'; // Just dropped, animating
@@ -1,4 +1,4 @@
1
- export const IDLE: "idle";
1
+ export const SUBMIT_IDLE: "idle";
2
2
  export const SUBMITTING: "submitting";
3
3
  export const SUBMIT_OK: "submit-ok";
4
4
  export const SUBMIT_FAILED: "submit-failed";
@@ -1,4 +1,4 @@
1
- export const IDLE = 'idle';
1
+ export const SUBMIT_IDLE = 'idle';
2
2
  export const SUBMITTING = 'submitting';
3
3
  export const SUBMIT_OK = 'submit-ok';
4
4
  export const SUBMIT_FAILED = 'submit-failed';
@@ -0,0 +1,4 @@
1
+ export * from "./states/drag.js";
2
+ export * from "./states/drop.js";
3
+ export * from "./states/input.js";
4
+ export * from "./states/submit.js";
@@ -0,0 +1,4 @@
1
+ export * from './states/drag.js';
2
+ export * from './states/drop.js';
3
+ export * from './states/input.js';
4
+ export * from './states/submit.js';
@@ -0,0 +1 @@
1
+ export * from "./time/index.js";
@@ -0,0 +1 @@
1
+ export * from './time/index.js';
@@ -109,11 +109,9 @@ const logger = createClientLogger('client');
109
109
 
110
110
  /** @type {import('@sveltejs/kit').HandleClientError} */
111
111
  export function handleError({ error, event }) {
112
- logger.error('Client error occurred', {
113
- message: error.message,
114
- stack: error.stack,
115
- url: event.url?.pathname,
116
- userAgent: navigator.userAgent
112
+ logger.error(error, {
113
+ url: event.url?.pathname,
114
+ userAgent: navigator.userAgent
117
115
  });
118
116
  }
119
117
 
@@ -126,19 +124,12 @@ export function init() {
126
124
 
127
125
  // Log unhandled errors
128
126
  window.addEventListener('error', (event) => {
129
- logger.error('Unhandled error', {
130
- message: event.error?.message || event.message,
131
- filename: event.filename,
132
- lineno: event.lineno,
133
- colno: event.colno
134
- });
127
+ logger.error(event, { url: window.location.pathname });
135
128
  });
136
129
 
137
130
  // Log unhandled promise rejections
138
131
  window.addEventListener('unhandledrejection', (event) => {
139
- logger.error('Unhandled promise rejection', {
140
- reason: event.reason
141
- });
132
+ logger.error(event, { url: window.location.pathname });
142
133
  });
143
134
  }
144
135
 
@@ -49,12 +49,16 @@ export default class Logger extends EventEmitter {
49
49
  /**
50
50
  * Log an error message
51
51
  *
52
- * @param {Error|string} originalErrorOrMessage
53
- * @param {Error} [originalError]
52
+ * @param {Error|ErrorEvent|PromiseRejectionEvent|string}
53
+ * originalErrorOrMessage
54
+ * @param {Error|Object} [originalErrorOrDetails]
55
+ * Error object (when first param is string) or details object
56
+ * @param {Object} [details]
57
+ * Additional context details (when using string + error pattern)
54
58
  *
55
59
  * @returns {boolean} True if the log was emitted
56
60
  */
57
- error(originalErrorOrMessage: Error | string, originalError?: Error, ...args: any[]): boolean;
61
+ error(originalErrorOrMessage: Error | ErrorEvent | PromiseRejectionEvent | string, originalErrorOrDetails?: Error | any, details?: any, ...args: any[]): boolean;
58
62
  /**
59
63
  * Create a child logger with additional context
60
64
  *
@@ -48,6 +48,13 @@ import { LoggerError } from '../../errors.js';
48
48
 
49
49
  import { toArray } from '../../../util/array/index.js';
50
50
 
51
+ import {
52
+ castErrorEventToDetailedError,
53
+ castPromiseRejectionToDetailedError
54
+ } from './util.js';
55
+
56
+ import * as is from '../../../util/is.js';
57
+
51
58
  /**
52
59
  * Logger class for consistent logging
53
60
  * @extends EventEmitter
@@ -126,41 +133,92 @@ export default class Logger extends EventEmitter {
126
133
  /**
127
134
  * Log an error message
128
135
  *
129
- * @param {Error|string} originalErrorOrMessage
130
- * @param {Error} [originalError]
136
+ * @param {Error|ErrorEvent|PromiseRejectionEvent|string}
137
+ * originalErrorOrMessage
138
+ * @param {Error|Object} [originalErrorOrDetails]
139
+ * Error object (when first param is string) or details object
140
+ * @param {Object} [details]
141
+ * Additional context details (when using string + error pattern)
131
142
  *
132
143
  * @returns {boolean} True if the log was emitted
133
144
  */
134
- error(originalErrorOrMessage, originalError) {
145
+ error(originalErrorOrMessage, originalErrorOrDetails, details) {
146
+ // Detection logic - set clear internal variables
147
+ let message;
148
+ let errorDetails;
149
+ let cause;
150
+
151
+ // Handle browser ErrorEvent
152
+ if (is.ErrorEvent(originalErrorOrMessage)) {
153
+ const errorEvent = /** @type {ErrorEvent} */ (originalErrorOrMessage);
154
+
155
+ message =
156
+ errorEvent.error?.message || errorEvent.message || 'Unknown error';
157
+
158
+ // Use provided details or auto-generate from event
159
+
160
+ errorDetails = originalErrorOrDetails || {
161
+ filename: errorEvent.filename,
162
+ lineno: errorEvent.lineno,
163
+ colno: errorEvent.colno,
164
+ type: 'ErrorEvent'
165
+ };
135
166
 
136
- if( originalErrorOrMessage instanceof Error )
137
- {
138
- // params: {error} originalErrorOrMessage
139
- const loggerError = new LoggerError(originalErrorOrMessage);
167
+ cause = errorEvent.error;
168
+ }
169
+ // Handle browser PromiseRejectionEvent
170
+ else if (is.PromiseRejectionEvent(originalErrorOrMessage)) {
171
+ const promiseRejectionEvent =
172
+ /** @type {PromiseRejectionEvent} */ (originalErrorOrMessage);
173
+
174
+ const reason = promiseRejectionEvent.reason;
140
175
 
141
- const message = originalErrorOrMessage.message;
176
+ if (reason instanceof Error) {
177
+ message = reason.message;
178
+ cause = reason;
179
+ } else {
180
+ message = String(reason);
181
+ cause = null;
182
+ }
142
183
 
143
- return this.#log(ERROR, message, loggerError);
184
+ // Use provided details or auto-generate from event
185
+ errorDetails = originalErrorOrDetails || {
186
+ type: 'PromiseRejectionEvent',
187
+ reasonType: typeof reason
188
+ };
189
+ }
190
+ // Handle regular Error
191
+ else if (originalErrorOrMessage instanceof Error) {
192
+ message = originalErrorOrMessage.message;
193
+ errorDetails = originalErrorOrDetails || null;
194
+ cause = originalErrorOrMessage;
195
+ }
196
+ // Handle string + Error pattern
197
+ else if (
198
+ typeof originalErrorOrMessage === 'string' &&
199
+ originalErrorOrDetails instanceof Error
200
+ ) {
201
+ message = originalErrorOrMessage;
202
+ errorDetails = details || null;
203
+ cause = originalErrorOrDetails;
144
204
  }
145
- else if( typeof originalErrorOrMessage === 'string' && originalError instanceof Error ) {
146
- // params: {string} message, {error} originalError
147
- const detailedError = new DetailedError(
148
- originalErrorOrMessage,
149
- null,
150
- originalError
151
- );
152
-
153
- return this.#log(ERROR, detailedError.message, detailedError);
205
+ // Handle string only
206
+ else if (typeof originalErrorOrMessage === 'string') {
207
+ message = originalErrorOrMessage;
208
+ errorDetails = originalErrorOrDetails || null;
209
+ cause = null;
154
210
  }
211
+ // Invalid parameters
155
212
  else {
156
- // wrong params
157
- const detailedError = new DetailedError(
158
- 'Invalid parameters supplied to Logger.error',
159
- toArray(arguments)
160
- );
161
-
162
- return this.#log(ERROR, detailedError.message, detailedError);
213
+ message = 'Invalid parameters supplied to Logger.error';
214
+ errorDetails = toArray(arguments);
215
+ cause = null;
163
216
  }
217
+
218
+ // Create consistent DetailedError for all cases
219
+ const detailedError = new DetailedError(message, errorDetails, cause);
220
+
221
+ return this.#log(ERROR, detailedError.message, detailedError);
164
222
  }
165
223
 
166
224
  /**
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Cast ErrorEvent to DetailedError
3
+ * @param {ErrorEvent} errorEvent - Browser ErrorEvent object
4
+ * @returns {DetailedError}
5
+ */
6
+ export function castErrorEventToDetailedError(errorEvent: ErrorEvent): DetailedError;
7
+ /**
8
+ * Cast PromiseRejectionEvent to DetailedError
9
+ * @param {PromiseRejectionEvent} rejectionEvent - Browser promise rejection
10
+ * @returns {DetailedError}
11
+ */
12
+ export function castPromiseRejectionToDetailedError(rejectionEvent: PromiseRejectionEvent): DetailedError;
13
+ import { DetailedError } from '../../../generic/errors/generic.js';
@@ -0,0 +1,47 @@
1
+ import { DetailedError } from '../../../generic/errors/generic.js';
2
+
3
+ /**
4
+ * Cast ErrorEvent to DetailedError
5
+ * @param {ErrorEvent} errorEvent - Browser ErrorEvent object
6
+ * @returns {DetailedError}
7
+ */
8
+ export function castErrorEventToDetailedError(errorEvent) {
9
+ const message = errorEvent.error?.message ||
10
+ errorEvent.message ||
11
+ 'Unknown error';
12
+
13
+ const details = {
14
+ filename: errorEvent.filename,
15
+ lineno: errorEvent.lineno,
16
+ colno: errorEvent.colno,
17
+ type: 'ErrorEvent'
18
+ };
19
+
20
+ return new DetailedError(message, details, errorEvent.error);
21
+ }
22
+
23
+ /**
24
+ * Cast PromiseRejectionEvent to DetailedError
25
+ * @param {PromiseRejectionEvent} rejectionEvent - Browser promise rejection
26
+ * @returns {DetailedError}
27
+ */
28
+ export function castPromiseRejectionToDetailedError(rejectionEvent) {
29
+ const reason = rejectionEvent.reason;
30
+ let message, cause;
31
+
32
+ if (reason instanceof Error) {
33
+ message = reason.message;
34
+ cause = reason;
35
+ } else {
36
+ message = String(reason);
37
+ cause = null;
38
+ }
39
+
40
+ const details = {
41
+ type: 'PromiseRejectionEvent',
42
+ reasonType: typeof reason
43
+ };
44
+
45
+ return new DetailedError(message, details, cause);
46
+ }
47
+
@@ -1,9 +1,9 @@
1
1
  import * as expect from '../../util/expect.js';
2
2
  import { DetailedError } from '../../generic/errors.js';
3
3
 
4
- import { CONTENT_TYPE } from '../../constants/http/index.js';
4
+ import { CONTENT_TYPE } from '../../constants/http.js';
5
5
 
6
- import { APPLICATION_JSON, TEXT_PLAIN } from '../../constants/mime/index.js';
6
+ import { APPLICATION_JSON, TEXT_PLAIN } from '../../constants/mime.js';
7
7
 
8
8
  /**
9
9
  * Try to get error information from the server error response
@@ -17,6 +17,6 @@ export * from './response.js';
17
17
  export * from './http-request.js';
18
18
  export * from './json-request.js';
19
19
 
20
- // import { CONTENT_TYPE, METHOD_GET, METHOD_POST } from '../../constants/http/index.js';
20
+ // import { CONTENT_TYPE, METHOD_GET, METHOD_POST } from '../../constants/http.js';
21
21
 
22
- // import { APPLICATION_JSON } from '../../constants/mime/index.js';
22
+ // import { APPLICATION_JSON } from '../../constants/mime.js';
@@ -1,6 +1,6 @@
1
- import { CONTENT_TYPE, CONTENT_LENGTH } from '../../constants/http/index.js';
1
+ import { CONTENT_TYPE, CONTENT_LENGTH } from '../../constants/http.js';
2
2
 
3
- import { OCTET_STREAM } from '../../constants/mime/index.js';
3
+ import { OCTET_STREAM } from '../../constants/mime.js';
4
4
 
5
5
  /**
6
6
  * Create a response value that can be used by a mocked fetch function
@@ -1,4 +1,4 @@
1
- import { CONTENT_TYPE, CONTENT_LENGTH } from '../../../constants/http/index.js';
1
+ import { CONTENT_TYPE, CONTENT_LENGTH } from '../../../constants/http.js';
2
2
 
3
3
  import { AUDIO_WAV } from '../../../constants/mime/audio.js';
4
4
 
@@ -1,4 +1,4 @@
1
- import { CONTENT_TYPE, CONTENT_LENGTH } from '../../../constants/http/index.js';
1
+ import { CONTENT_TYPE, CONTENT_LENGTH } from '../../../constants/http.js';
2
2
 
3
3
  import { IMAGE_PNG } from '../../../constants/mime/image.js';
4
4
 
@@ -1,4 +1,4 @@
1
- import { CONTENT_TYPE } from '../../constants/http/index.js';
1
+ import { CONTENT_TYPE } from '../../constants/http.js';
2
2
 
3
3
  import { LoadingStateMachine } from '../../state/classes.js';
4
4
 
@@ -1,4 +1,4 @@
1
- import { CONTENT_TYPE, CONTENT_LENGTH } from '../../constants/http/index.js';
1
+ import { CONTENT_TYPE, CONTENT_LENGTH } from '../../constants/http.js';
2
2
 
3
3
  import { OCTET_STREAM } from '../../constants/mime/application.js';
4
4
 
@@ -104,7 +104,7 @@ Manages multiple services with dependency resolution and coordinated lifecycle o
104
104
  ### Usage
105
105
 
106
106
  ```javascript
107
- import { ServiceManager } from '$lib/services/index.js';
107
+ import { ServiceManager } from '$hklib-core/services/index.js';
108
108
  import DatabaseService from './services/DatabaseService.js';
109
109
  import AuthService from './services/AuthService.js';
110
110
 
@@ -197,4 +197,4 @@ Services include comprehensive test suites demonstrating:
197
197
  - Health monitoring
198
198
  - Event emission
199
199
 
200
- Run tests with your project's test command to ensure service reliability.
200
+ Run tests with your project's test command to ensure service reliability.
@@ -6,7 +6,7 @@
6
6
  import { DragController } from './DragController.js';
7
7
  import { onDestroy } from 'svelte';
8
8
  import {
9
- IDLE,
9
+ DRAG_IDLE,
10
10
  DRAGGING,
11
11
  DRAG_PREVIEW,
12
12
  DROPPING
@@ -91,7 +91,7 @@
91
91
  let draggableElement;
92
92
 
93
93
  let dragTimeout = null;
94
- let currentState = $state(IDLE);
94
+ let currentState = $state(DRAG_IDLE);
95
95
 
96
96
  // Custom preview follower state
97
97
  let showPreview = $state(false);
@@ -112,7 +112,7 @@
112
112
 
113
113
  // Computed state object for CSS classes
114
114
  let stateObject = $derived({
115
- idle: currentState === IDLE,
115
+ idle: currentState === DRAG_IDLE,
116
116
  dragging: currentState === DRAGGING,
117
117
  'drag-preview': currentState === DRAG_PREVIEW,
118
118
  dropping: currentState === DROPPING,
@@ -295,10 +295,10 @@
295
295
 
296
296
  // Brief dropping state before returning to idle
297
297
  setTimeout(() => {
298
- currentState = IDLE;
298
+ currentState = DRAG_IDLE;
299
299
  }, 100);
300
300
  } else {
301
- currentState = IDLE;
301
+ currentState = DRAG_IDLE;
302
302
  }
303
303
 
304
304
  onDragEnd?.({ event, item, wasDropped });
@@ -321,7 +321,7 @@
321
321
  function handleMouseUp(event) {
322
322
  if (dragTimeout) {
323
323
  clearTimeout(dragTimeout);
324
- currentState = IDLE;
324
+ currentState = DRAG_IDLE;
325
325
  }
326
326
  }
327
327
 
@@ -456,7 +456,7 @@
456
456
 
457
457
  // Clean up
458
458
  touchDragging = false;
459
- currentState = IDLE;
459
+ currentState = DRAG_IDLE;
460
460
  showPreview = false;
461
461
  dragState.end(draggableId);
462
462
 
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Check if object is an ErrorEvent
3
+ *
4
+ * @param {any} obj
5
+ *
6
+ * @returns {boolean}
7
+ */
8
+ export function ErrorEvent(obj: any): boolean;
9
+ /**
10
+ * Check if object is a PromiseRejectionEvent
11
+ *
12
+ * @param {any} obj
13
+ *
14
+ * @returns {boolean}
15
+ */
16
+ export function PromiseRejectionEvent(obj: any): boolean;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Check if object is an ErrorEvent
3
+ *
4
+ * @param {any} obj
5
+ *
6
+ * @returns {boolean}
7
+ */
8
+ export function ErrorEvent(obj) {
9
+ return Boolean(obj &&
10
+ typeof obj === 'object' &&
11
+ obj.constructor?.name === 'ErrorEvent');
12
+ }
13
+
14
+ /**
15
+ * Check if object is a PromiseRejectionEvent
16
+ *
17
+ * @param {any} obj
18
+ *
19
+ * @returns {boolean}
20
+ */
21
+ export function PromiseRejectionEvent(obj) {
22
+ return Boolean(obj &&
23
+ typeof obj === 'object' &&
24
+ obj.constructor?.name === 'PromiseRejectionEvent');
25
+ }
@@ -68,3 +68,4 @@ export { argumentsCheck as arguments };
68
68
  * @returns {boolean} true if the value is an Arguments object
69
69
  */
70
70
  declare function argumentsCheck(value: any): boolean;
71
+ export { ErrorEvent, PromiseRejectionEvent } from "./events.js";
@@ -146,3 +146,5 @@ export function object(value) {
146
146
 
147
147
  return true;
148
148
  }
149
+
150
+ export { ErrorEvent, PromiseRejectionEvent } from './events.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-core",
3
- "version": "0.4.14",
3
+ "version": "0.4.16",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"
@@ -1,6 +0,0 @@
1
- export * as bases from "./bases/index.js";
2
- export * as http from "./http/index.js";
3
- export * as mime from "./mime/index.js";
4
- export * as regexp from "./regexp/index.js";
5
- export * as states from "./states/index.js";
6
- export * as time from "./time/index.js";
@@ -1,6 +0,0 @@
1
- export * as bases from './bases/index.js';
2
- export * as http from './http/index.js';
3
- export * as mime from './mime/index.js';
4
- export * as regexp from './regexp/index.js';
5
- export * as states from './states/index.js';
6
- export * as time from './time/index.js';