@opensourcekd/ng-common-libs 2.0.6 → 2.0.8

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/index.d.ts CHANGED
@@ -419,6 +419,11 @@ declare class AuthService {
419
419
  * Emit authentication event for cross-application communication
420
420
  */
421
421
  private emitAuthEvent;
422
+ /**
423
+ * Clean up OAuth callback parameters from URL after successful authentication
424
+ * Removes 'code' and 'state' parameters while preserving other query parameters
425
+ */
426
+ private cleanupCallbackUrl;
422
427
  }
423
428
  /**
424
429
  * Create AuthService instance using AUTH0_CONFIG
@@ -447,5 +452,204 @@ declare class AuthService {
447
452
  */
448
453
  declare function createAuthService(eventBus: EventBus): AuthService;
449
454
 
450
- export { APP_CONFIG, AUTH0_CONFIG, AuthService, EventBus, STORAGE_CONFIG, STORAGE_KEYS, configureAuth0, createAuthService, getStorageItem, removeStorageItem, resetAuth0Config, setStorageItem };
451
- export type { AppState, Auth0Config, Auth0ConfigOptions, AuthServiceOptions, AuthorizationParams, CallbackResult, EventBusOptions, EventPayload, StorageConfig, StorageKeys, UserData, UserInfo };
455
+ /**
456
+ * OpenTelemetry severity levels
457
+ * Based on OpenTelemetry log data model
458
+ * @see https://opentelemetry.io/docs/specs/otel/logs/data-model/
459
+ */
460
+ declare enum LogSeverity {
461
+ TRACE = 1,
462
+ DEBUG = 5,
463
+ INFO = 9,
464
+ WARN = 13,
465
+ ERROR = 17,
466
+ FATAL = 21
467
+ }
468
+ /**
469
+ * OpenTelemetry log record attributes
470
+ * Structured key-value pairs for additional context
471
+ */
472
+ interface LogAttributes {
473
+ [key: string]: string | number | boolean | undefined | null;
474
+ }
475
+ /**
476
+ * OpenTelemetry log record
477
+ * Conforms to OTel log data model specification
478
+ */
479
+ interface LogRecord {
480
+ /** Timestamp in milliseconds since Unix epoch */
481
+ timestamp: number;
482
+ /** Severity level number */
483
+ severityNumber: LogSeverity;
484
+ /** Severity level text */
485
+ severityText: string;
486
+ /** Log message body */
487
+ body: string;
488
+ /** Structured attributes for additional context */
489
+ attributes?: LogAttributes;
490
+ /** Trace ID if available (for correlation) */
491
+ traceId?: string;
492
+ /** Span ID if available (for correlation) */
493
+ spanId?: string;
494
+ /** Resource attributes (e.g., service.name, deployment.environment) */
495
+ resource?: LogAttributes;
496
+ }
497
+ /**
498
+ * Logger options interface
499
+ */
500
+ interface LoggerOptions {
501
+ /** Logger identifier (e.g., service name, component name) */
502
+ name?: string;
503
+ /** Minimum severity level to log (logs below this level are ignored) */
504
+ minSeverity?: LogSeverity;
505
+ /** Resource attributes applied to all logs from this logger */
506
+ resource?: LogAttributes;
507
+ /** Whether to output logs to console (default: true) */
508
+ consoleOutput?: boolean;
509
+ }
510
+ /**
511
+ * Logger - OpenTelemetry-compliant structured logging
512
+ * Framework-agnostic implementation using RxJS for observability
513
+ *
514
+ * Conforms to OpenTelemetry log data model:
515
+ * - Structured logging with severity levels
516
+ * - Timestamp in milliseconds
517
+ * - Support for attributes and resource context
518
+ * - Observable log stream for integration with OTel exporters
519
+ *
520
+ * @example
521
+ * ```typescript
522
+ * // Create a logger instance
523
+ * const logger = new Logger({
524
+ * name: 'MyService',
525
+ * minSeverity: LogSeverity.INFO,
526
+ * resource: {
527
+ * 'service.name': 'my-app',
528
+ * 'deployment.environment': 'production'
529
+ * }
530
+ * });
531
+ *
532
+ * // Simple logging
533
+ * logger.info('User logged in');
534
+ * logger.error('Failed to fetch data');
535
+ *
536
+ * // Structured logging with attributes
537
+ * logger.info('User action', {
538
+ * userId: '123',
539
+ * action: 'purchase',
540
+ * amount: 99.99
541
+ * });
542
+ *
543
+ * // Subscribe to log stream (e.g., for sending to OTel collector)
544
+ * logger.getLogStream().subscribe(logRecord => {
545
+ * // Send to OTel exporter, custom backend, etc.
546
+ * console.log(JSON.stringify(logRecord));
547
+ * });
548
+ *
549
+ * // Log with trace correlation
550
+ * logger.info('Processing request',
551
+ * { requestId: 'abc-123' },
552
+ * { traceId: '1234...', spanId: '5678...' }
553
+ * );
554
+ * ```
555
+ */
556
+ declare class Logger {
557
+ private logSubject;
558
+ private name?;
559
+ private minSeverity;
560
+ private resource?;
561
+ private consoleOutput;
562
+ /**
563
+ * Create a new Logger instance
564
+ * @param options - Optional configuration for the logger
565
+ */
566
+ constructor(options?: LoggerOptions);
567
+ /**
568
+ * Get the logger name
569
+ * @returns The logger name if provided during initialization
570
+ */
571
+ getName(): string | undefined;
572
+ /**
573
+ * Get the observable log stream
574
+ * Subscribe to this to receive all log records emitted by this logger
575
+ * @returns Observable that emits LogRecord objects
576
+ */
577
+ getLogStream(): Observable<LogRecord>;
578
+ /**
579
+ * Emit a log record
580
+ * @param severity - Severity level
581
+ * @param severityText - Severity level text
582
+ * @param body - Log message
583
+ * @param attributes - Optional structured attributes
584
+ * @param context - Optional trace context (traceId, spanId)
585
+ */
586
+ private log;
587
+ /**
588
+ * Output log to console
589
+ * @param logRecord - The log record to output
590
+ */
591
+ private outputToConsole;
592
+ /**
593
+ * Log a TRACE level message
594
+ * @param body - Log message
595
+ * @param attributes - Optional structured attributes
596
+ * @param context - Optional trace context
597
+ */
598
+ trace(body: string, attributes?: LogAttributes, context?: {
599
+ traceId?: string;
600
+ spanId?: string;
601
+ }): void;
602
+ /**
603
+ * Log a DEBUG level message
604
+ * @param body - Log message
605
+ * @param attributes - Optional structured attributes
606
+ * @param context - Optional trace context
607
+ */
608
+ debug(body: string, attributes?: LogAttributes, context?: {
609
+ traceId?: string;
610
+ spanId?: string;
611
+ }): void;
612
+ /**
613
+ * Log an INFO level message
614
+ * @param body - Log message
615
+ * @param attributes - Optional structured attributes
616
+ * @param context - Optional trace context
617
+ */
618
+ info(body: string, attributes?: LogAttributes, context?: {
619
+ traceId?: string;
620
+ spanId?: string;
621
+ }): void;
622
+ /**
623
+ * Log a WARN level message
624
+ * @param body - Log message
625
+ * @param attributes - Optional structured attributes
626
+ * @param context - Optional trace context
627
+ */
628
+ warn(body: string, attributes?: LogAttributes, context?: {
629
+ traceId?: string;
630
+ spanId?: string;
631
+ }): void;
632
+ /**
633
+ * Log an ERROR level message
634
+ * @param body - Log message
635
+ * @param attributes - Optional structured attributes
636
+ * @param context - Optional trace context
637
+ */
638
+ error(body: string, attributes?: LogAttributes, context?: {
639
+ traceId?: string;
640
+ spanId?: string;
641
+ }): void;
642
+ /**
643
+ * Log a FATAL level message
644
+ * @param body - Log message
645
+ * @param attributes - Optional structured attributes
646
+ * @param context - Optional trace context
647
+ */
648
+ fatal(body: string, attributes?: LogAttributes, context?: {
649
+ traceId?: string;
650
+ spanId?: string;
651
+ }): void;
652
+ }
653
+
654
+ export { APP_CONFIG, AUTH0_CONFIG, AuthService, EventBus, LogSeverity, Logger, STORAGE_CONFIG, STORAGE_KEYS, configureAuth0, createAuthService, getStorageItem, removeStorageItem, resetAuth0Config, setStorageItem };
655
+ export type { AppState, Auth0Config, Auth0ConfigOptions, AuthServiceOptions, AuthorizationParams, CallbackResult, EventBusOptions, EventPayload, LogAttributes, LogRecord, LoggerOptions, StorageConfig, StorageKeys, UserData, UserInfo };
package/dist/index.mjs CHANGED
@@ -315,7 +315,7 @@ class AuthService {
315
315
  this.id = options?.id;
316
316
  this.userSubject = new BehaviorSubject(this.getUserInfoFromStorage());
317
317
  this.user$ = this.userSubject.asObservable();
318
- console.log("[AuthService] AuthService instance created (Auth0 client will be initialized on first use)");
318
+ console.log("[AuthService] AuthService instance created (Auth0 client will be initialized on first use, kd)");
319
319
  // Lazy initialization - Auth0 client will be initialized in ensureInitialized() on first use
320
320
  }
321
321
  /**
@@ -441,6 +441,8 @@ class AuthService {
441
441
  }
442
442
  const token = await this.auth0Client.getTokenSilently();
443
443
  this.setToken(token);
444
+ // Clean up OAuth callback parameters from URL
445
+ this.cleanupCallbackUrl();
444
446
  console.log("[AuthService] Authentication successful");
445
447
  this.emitAuthEvent('login_success', { user, appState: result.appState });
446
448
  return { success: true, appState: result.appState };
@@ -663,6 +665,34 @@ class AuthService {
663
665
  this.eventBus.emit(event.type, event);
664
666
  console.log('[AuthService] Auth event emitted:', event.type);
665
667
  }
668
+ /**
669
+ * Clean up OAuth callback parameters from URL after successful authentication
670
+ * Removes 'code' and 'state' parameters while preserving other query parameters
671
+ */
672
+ cleanupCallbackUrl() {
673
+ try {
674
+ const url = new URL(window.location.href);
675
+ const params = new URLSearchParams(url.search);
676
+ // Check if OAuth params exist
677
+ const hasCode = params.has('code');
678
+ const hasState = params.has('state');
679
+ if (hasCode || hasState) {
680
+ // Remove OAuth callback parameters
681
+ params.delete('code');
682
+ params.delete('state');
683
+ // Construct new URL without OAuth params
684
+ const newSearch = params.toString();
685
+ const newUrl = `${url.pathname}${newSearch ? '?' + newSearch : ''}${url.hash}`;
686
+ // Replace URL without adding to browser history
687
+ window.history.replaceState({}, '', newUrl);
688
+ console.log('[AuthService] OAuth callback parameters cleaned from URL');
689
+ }
690
+ }
691
+ catch (error) {
692
+ console.warn('[AuthService] Failed to clean up callback URL:', error);
693
+ // Don't throw - URL cleanup is not critical for auth functionality
694
+ }
695
+ }
666
696
  }
667
697
  /**
668
698
  * Create AuthService instance using AUTH0_CONFIG
@@ -702,5 +732,209 @@ function createAuthService(eventBus) {
702
732
  return new AuthService(auth0Config, eventBus, STORAGE_CONFIG, STORAGE_KEYS);
703
733
  }
704
734
 
705
- export { APP_CONFIG, AUTH0_CONFIG, AuthService, EventBus, STORAGE_CONFIG, STORAGE_KEYS, configureAuth0, createAuthService, getStorageItem$1 as getStorageItem, removeStorageItem$1 as removeStorageItem, resetAuth0Config, setStorageItem$1 as setStorageItem };
735
+ /**
736
+ * OpenTelemetry severity levels
737
+ * Based on OpenTelemetry log data model
738
+ * @see https://opentelemetry.io/docs/specs/otel/logs/data-model/
739
+ */
740
+ var LogSeverity;
741
+ (function (LogSeverity) {
742
+ LogSeverity[LogSeverity["TRACE"] = 1] = "TRACE";
743
+ LogSeverity[LogSeverity["DEBUG"] = 5] = "DEBUG";
744
+ LogSeverity[LogSeverity["INFO"] = 9] = "INFO";
745
+ LogSeverity[LogSeverity["WARN"] = 13] = "WARN";
746
+ LogSeverity[LogSeverity["ERROR"] = 17] = "ERROR";
747
+ LogSeverity[LogSeverity["FATAL"] = 21] = "FATAL";
748
+ })(LogSeverity || (LogSeverity = {}));
749
+ /**
750
+ * Logger - OpenTelemetry-compliant structured logging
751
+ * Framework-agnostic implementation using RxJS for observability
752
+ *
753
+ * Conforms to OpenTelemetry log data model:
754
+ * - Structured logging with severity levels
755
+ * - Timestamp in milliseconds
756
+ * - Support for attributes and resource context
757
+ * - Observable log stream for integration with OTel exporters
758
+ *
759
+ * @example
760
+ * ```typescript
761
+ * // Create a logger instance
762
+ * const logger = new Logger({
763
+ * name: 'MyService',
764
+ * minSeverity: LogSeverity.INFO,
765
+ * resource: {
766
+ * 'service.name': 'my-app',
767
+ * 'deployment.environment': 'production'
768
+ * }
769
+ * });
770
+ *
771
+ * // Simple logging
772
+ * logger.info('User logged in');
773
+ * logger.error('Failed to fetch data');
774
+ *
775
+ * // Structured logging with attributes
776
+ * logger.info('User action', {
777
+ * userId: '123',
778
+ * action: 'purchase',
779
+ * amount: 99.99
780
+ * });
781
+ *
782
+ * // Subscribe to log stream (e.g., for sending to OTel collector)
783
+ * logger.getLogStream().subscribe(logRecord => {
784
+ * // Send to OTel exporter, custom backend, etc.
785
+ * console.log(JSON.stringify(logRecord));
786
+ * });
787
+ *
788
+ * // Log with trace correlation
789
+ * logger.info('Processing request',
790
+ * { requestId: 'abc-123' },
791
+ * { traceId: '1234...', spanId: '5678...' }
792
+ * );
793
+ * ```
794
+ */
795
+ class Logger {
796
+ logSubject = new Subject();
797
+ name;
798
+ minSeverity;
799
+ resource;
800
+ consoleOutput;
801
+ /**
802
+ * Create a new Logger instance
803
+ * @param options - Optional configuration for the logger
804
+ */
805
+ constructor(options) {
806
+ this.name = options?.name;
807
+ this.minSeverity = options?.minSeverity ?? LogSeverity.TRACE;
808
+ this.resource = options?.resource;
809
+ this.consoleOutput = options?.consoleOutput ?? true;
810
+ }
811
+ /**
812
+ * Get the logger name
813
+ * @returns The logger name if provided during initialization
814
+ */
815
+ getName() {
816
+ return this.name;
817
+ }
818
+ /**
819
+ * Get the observable log stream
820
+ * Subscribe to this to receive all log records emitted by this logger
821
+ * @returns Observable that emits LogRecord objects
822
+ */
823
+ getLogStream() {
824
+ return this.logSubject.asObservable();
825
+ }
826
+ /**
827
+ * Emit a log record
828
+ * @param severity - Severity level
829
+ * @param severityText - Severity level text
830
+ * @param body - Log message
831
+ * @param attributes - Optional structured attributes
832
+ * @param context - Optional trace context (traceId, spanId)
833
+ */
834
+ log(severity, severityText, body, attributes, context) {
835
+ // Check if we should log based on minimum severity
836
+ if (severity < this.minSeverity) {
837
+ return;
838
+ }
839
+ const logRecord = {
840
+ timestamp: Date.now(),
841
+ severityNumber: severity,
842
+ severityText,
843
+ body,
844
+ attributes,
845
+ traceId: context?.traceId,
846
+ spanId: context?.spanId,
847
+ resource: this.resource
848
+ };
849
+ // Emit to observable stream
850
+ this.logSubject.next(logRecord);
851
+ // Console output if enabled
852
+ if (this.consoleOutput) {
853
+ this.outputToConsole(logRecord);
854
+ }
855
+ }
856
+ /**
857
+ * Output log to console
858
+ * @param logRecord - The log record to output
859
+ */
860
+ outputToConsole(logRecord) {
861
+ const prefix = this.name ? `[${this.name}]` : '';
862
+ const message = `${prefix} ${logRecord.body}`;
863
+ const meta = logRecord.attributes;
864
+ switch (logRecord.severityNumber) {
865
+ case LogSeverity.TRACE:
866
+ case LogSeverity.DEBUG:
867
+ console.debug(message, meta);
868
+ break;
869
+ case LogSeverity.INFO:
870
+ console.info(message, meta);
871
+ break;
872
+ case LogSeverity.WARN:
873
+ console.warn(message, meta);
874
+ break;
875
+ case LogSeverity.ERROR:
876
+ case LogSeverity.FATAL:
877
+ console.error(message, meta);
878
+ break;
879
+ default:
880
+ console.log(message, meta);
881
+ }
882
+ }
883
+ /**
884
+ * Log a TRACE level message
885
+ * @param body - Log message
886
+ * @param attributes - Optional structured attributes
887
+ * @param context - Optional trace context
888
+ */
889
+ trace(body, attributes, context) {
890
+ this.log(LogSeverity.TRACE, 'TRACE', body, attributes, context);
891
+ }
892
+ /**
893
+ * Log a DEBUG level message
894
+ * @param body - Log message
895
+ * @param attributes - Optional structured attributes
896
+ * @param context - Optional trace context
897
+ */
898
+ debug(body, attributes, context) {
899
+ this.log(LogSeverity.DEBUG, 'DEBUG', body, attributes, context);
900
+ }
901
+ /**
902
+ * Log an INFO level message
903
+ * @param body - Log message
904
+ * @param attributes - Optional structured attributes
905
+ * @param context - Optional trace context
906
+ */
907
+ info(body, attributes, context) {
908
+ this.log(LogSeverity.INFO, 'INFO', body, attributes, context);
909
+ }
910
+ /**
911
+ * Log a WARN level message
912
+ * @param body - Log message
913
+ * @param attributes - Optional structured attributes
914
+ * @param context - Optional trace context
915
+ */
916
+ warn(body, attributes, context) {
917
+ this.log(LogSeverity.WARN, 'WARN', body, attributes, context);
918
+ }
919
+ /**
920
+ * Log an ERROR level message
921
+ * @param body - Log message
922
+ * @param attributes - Optional structured attributes
923
+ * @param context - Optional trace context
924
+ */
925
+ error(body, attributes, context) {
926
+ this.log(LogSeverity.ERROR, 'ERROR', body, attributes, context);
927
+ }
928
+ /**
929
+ * Log a FATAL level message
930
+ * @param body - Log message
931
+ * @param attributes - Optional structured attributes
932
+ * @param context - Optional trace context
933
+ */
934
+ fatal(body, attributes, context) {
935
+ this.log(LogSeverity.FATAL, 'FATAL', body, attributes, context);
936
+ }
937
+ }
938
+
939
+ export { APP_CONFIG, AUTH0_CONFIG, AuthService, EventBus, LogSeverity, Logger, STORAGE_CONFIG, STORAGE_KEYS, configureAuth0, createAuthService, getStorageItem$1 as getStorageItem, removeStorageItem$1 as removeStorageItem, resetAuth0Config, setStorageItem$1 as setStorageItem };
706
940
  //# sourceMappingURL=index.mjs.map