@opensourcekd/ng-common-libs 2.0.3 → 2.0.5

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
@@ -79,9 +79,21 @@ declare const APP_CONFIG: {
79
79
  * Centralized configuration for Auth0 integration
80
80
  * Framework-agnostic - works with any JavaScript framework
81
81
  */
82
+ /**
83
+ * Auth0 configuration interface
84
+ */
85
+ interface Auth0ConfigOptions {
86
+ domain?: string;
87
+ clientId?: string;
88
+ redirectUri?: string;
89
+ logoutUri?: string;
90
+ audience?: string;
91
+ scope?: string;
92
+ connection?: string;
93
+ }
82
94
  /**
83
95
  * Auth0 client configuration
84
- * Override these values in your consuming application by setting them before importing AuthService
96
+ * Override these values in your consuming application using configureAuth0()
85
97
  *
86
98
  * Note: redirectUri defaults to window.location.origin (base URL without path).
87
99
  * Auth0 will redirect back to this URL after authentication.
@@ -95,6 +107,25 @@ declare const AUTH0_CONFIG: {
95
107
  scope: string;
96
108
  connection: string | undefined;
97
109
  };
110
+ /**
111
+ * Configure Auth0 settings
112
+ * Call this function early in your application (e.g., in app.config.ts or main.ts)
113
+ * to override the default Auth0 configuration values.
114
+ *
115
+ * @param config - Partial Auth0 configuration to override defaults
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * import { configureAuth0, APP_CONFIG } from '@opensourcekd/ng-common-libs';
120
+ *
121
+ * configureAuth0({
122
+ * domain: APP_CONFIG.auth0Domain,
123
+ * clientId: APP_CONFIG.auth0ClientId,
124
+ * audience: APP_CONFIG.apiUrl,
125
+ * });
126
+ * ```
127
+ */
128
+ declare function configureAuth0(config: Auth0ConfigOptions): void;
98
129
  /**
99
130
  * Storage configuration
100
131
  * Controls where sensitive data is stored
@@ -110,6 +141,12 @@ declare const STORAGE_KEYS: {
110
141
  ACCESS_TOKEN: string;
111
142
  USER_INFO: string;
112
143
  };
144
+ /**
145
+ * Reset AUTH0_CONFIG to default values
146
+ * Useful for testing
147
+ * @internal
148
+ */
149
+ declare function resetAuth0Config(): void;
113
150
  /**
114
151
  * Helper functions for storage operations
115
152
  * These work with both localStorage and sessionStorage
@@ -341,6 +378,32 @@ declare class AuthService {
341
378
  */
342
379
  private emitAuthEvent;
343
380
  }
381
+ /**
382
+ * Create AuthService instance using AUTH0_CONFIG
383
+ * Helper function for creating AuthService with default configuration from AUTH0_CONFIG
384
+ *
385
+ * Note: Make sure to call configureAuth0() before using this helper
386
+ *
387
+ * @param eventBus - EventBus instance for auth events
388
+ * @returns Configured AuthService instance
389
+ *
390
+ * @example
391
+ * ```typescript
392
+ * import { createAuthService, EventBus, configureAuth0, APP_CONFIG } from '@opensourcekd/ng-common-libs';
393
+ *
394
+ * // Configure Auth0 first
395
+ * configureAuth0({
396
+ * domain: APP_CONFIG.auth0Domain,
397
+ * clientId: APP_CONFIG.auth0ClientId,
398
+ * audience: APP_CONFIG.apiUrl,
399
+ * });
400
+ *
401
+ * // Create instances
402
+ * const eventBus = new EventBus();
403
+ * const authService = createAuthService(eventBus);
404
+ * ```
405
+ */
406
+ declare function createAuthService(eventBus: EventBus): AuthService;
344
407
 
345
- export { APP_CONFIG, AUTH0_CONFIG, AuthService, EventBus, STORAGE_CONFIG, STORAGE_KEYS, getStorageItem, removeStorageItem, setStorageItem };
346
- export type { AppState, Auth0Config, AuthorizationParams, CallbackResult, EventPayload, StorageConfig, StorageKeys, UserData, UserInfo };
408
+ export { APP_CONFIG, AUTH0_CONFIG, AuthService, EventBus, STORAGE_CONFIG, STORAGE_KEYS, configureAuth0, createAuthService, getStorageItem, removeStorageItem, resetAuth0Config, setStorageItem };
409
+ export type { AppState, Auth0Config, Auth0ConfigOptions, AuthorizationParams, CallbackResult, EventPayload, StorageConfig, StorageKeys, UserData, UserInfo };
package/dist/index.mjs CHANGED
@@ -74,9 +74,9 @@ class EventBus {
74
74
  * These values are replaced during build time with actual values from GitHub repository variables.
75
75
  */
76
76
  const APP_CONFIG = {
77
- auth0Domain: '',
78
- auth0ClientId: '',
79
- apiUrl: '',
77
+ auth0Domain: 'dev-26sow24tone5na8a.us.auth0.com',
78
+ auth0ClientId: 'EdkPy5co65jESIAT8T9SBy5X4cmeolhl',
79
+ apiUrl: 'https://noq8dav0ac.execute-api.us-east-1.amazonaws.com',
80
80
  };
81
81
 
82
82
  /**
@@ -86,20 +86,47 @@ const APP_CONFIG = {
86
86
  */
87
87
  /**
88
88
  * Auth0 client configuration
89
- * Override these values in your consuming application by setting them before importing AuthService
89
+ * Override these values in your consuming application using configureAuth0()
90
90
  *
91
91
  * Note: redirectUri defaults to window.location.origin (base URL without path).
92
92
  * Auth0 will redirect back to this URL after authentication.
93
93
  */
94
94
  const AUTH0_CONFIG = {
95
- domain: '', // Set in consuming app: process.env['NX_AUTH0_DOMAIN'] || 'your-domain.auth0.com'
96
- clientId: '', // Set in consuming app: process.env['NX_AUTH0_CLIENT_ID'] || 'your-client-id'
95
+ domain: '', // Set via configureAuth0() or process.env
96
+ clientId: '', // Set via configureAuth0() or process.env
97
97
  redirectUri: typeof window !== 'undefined' ? window.location.origin : '',
98
98
  logoutUri: typeof window !== 'undefined' ? window.location.origin : '',
99
- audience: '', // Optional: Set in consuming app if using API authorization
99
+ audience: '', // Optional: Set via configureAuth0()
100
100
  scope: 'openid profile email', // Default scopes
101
- connection: undefined, // Optional: Force specific connection (e.g., 'Username-Password-Authentication')
101
+ connection: undefined, // Optional: Force specific connection
102
102
  };
103
+ /**
104
+ * Configure Auth0 settings
105
+ * Call this function early in your application (e.g., in app.config.ts or main.ts)
106
+ * to override the default Auth0 configuration values.
107
+ *
108
+ * @param config - Partial Auth0 configuration to override defaults
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * import { configureAuth0, APP_CONFIG } from '@opensourcekd/ng-common-libs';
113
+ *
114
+ * configureAuth0({
115
+ * domain: APP_CONFIG.auth0Domain,
116
+ * clientId: APP_CONFIG.auth0ClientId,
117
+ * audience: APP_CONFIG.apiUrl,
118
+ * });
119
+ * ```
120
+ */
121
+ function configureAuth0(config) {
122
+ // Only update properties that are explicitly provided (not undefined)
123
+ Object.keys(config).forEach((key) => {
124
+ const configKey = key;
125
+ if (config[configKey] !== undefined) {
126
+ AUTH0_CONFIG[configKey] = config[configKey];
127
+ }
128
+ });
129
+ }
103
130
  /**
104
131
  * Storage configuration
105
132
  * Controls where sensitive data is stored
@@ -115,6 +142,20 @@ const STORAGE_KEYS = {
115
142
  ACCESS_TOKEN: 'auth0_access_token',
116
143
  USER_INFO: 'auth0_user_info',
117
144
  };
145
+ /**
146
+ * Reset AUTH0_CONFIG to default values
147
+ * Useful for testing
148
+ * @internal
149
+ */
150
+ function resetAuth0Config() {
151
+ AUTH0_CONFIG.domain = '';
152
+ AUTH0_CONFIG.clientId = '';
153
+ AUTH0_CONFIG.redirectUri = typeof window !== 'undefined' ? window.location.origin : '';
154
+ AUTH0_CONFIG.logoutUri = typeof window !== 'undefined' ? window.location.origin : '';
155
+ AUTH0_CONFIG.audience = '';
156
+ AUTH0_CONFIG.scope = 'openid profile email';
157
+ AUTH0_CONFIG.connection = undefined;
158
+ }
118
159
  /**
119
160
  * Helper functions for storage operations
120
161
  * These work with both localStorage and sessionStorage
@@ -586,6 +627,43 @@ class AuthService {
586
627
  console.log('[AuthService] Auth event emitted:', event.type);
587
628
  }
588
629
  }
630
+ /**
631
+ * Create AuthService instance using AUTH0_CONFIG
632
+ * Helper function for creating AuthService with default configuration from AUTH0_CONFIG
633
+ *
634
+ * Note: Make sure to call configureAuth0() before using this helper
635
+ *
636
+ * @param eventBus - EventBus instance for auth events
637
+ * @returns Configured AuthService instance
638
+ *
639
+ * @example
640
+ * ```typescript
641
+ * import { createAuthService, EventBus, configureAuth0, APP_CONFIG } from '@opensourcekd/ng-common-libs';
642
+ *
643
+ * // Configure Auth0 first
644
+ * configureAuth0({
645
+ * domain: APP_CONFIG.auth0Domain,
646
+ * clientId: APP_CONFIG.auth0ClientId,
647
+ * audience: APP_CONFIG.apiUrl,
648
+ * });
649
+ *
650
+ * // Create instances
651
+ * const eventBus = new EventBus();
652
+ * const authService = createAuthService(eventBus);
653
+ * ```
654
+ */
655
+ function createAuthService(eventBus) {
656
+ const auth0Config = {
657
+ domain: AUTH0_CONFIG.domain,
658
+ clientId: AUTH0_CONFIG.clientId,
659
+ redirectUri: AUTH0_CONFIG.redirectUri,
660
+ logoutUri: AUTH0_CONFIG.logoutUri,
661
+ audience: AUTH0_CONFIG.audience,
662
+ scope: AUTH0_CONFIG.scope,
663
+ connection: AUTH0_CONFIG.connection,
664
+ };
665
+ return new AuthService(auth0Config, eventBus, STORAGE_CONFIG, STORAGE_KEYS);
666
+ }
589
667
 
590
- export { APP_CONFIG, AUTH0_CONFIG, AuthService, EventBus, STORAGE_CONFIG, STORAGE_KEYS, getStorageItem$1 as getStorageItem, removeStorageItem$1 as removeStorageItem, setStorageItem$1 as setStorageItem };
668
+ 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 };
591
669
  //# sourceMappingURL=index.mjs.map