@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/README.md +5 -0
- package/dist/index.cjs +89 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +66 -3
- package/dist/index.mjs +87 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -95,6 +95,10 @@ import {
|
|
|
95
95
|
AuthService,
|
|
96
96
|
EventBus,
|
|
97
97
|
|
|
98
|
+
// Helper Functions
|
|
99
|
+
configureAuth0,
|
|
100
|
+
createAuthService,
|
|
101
|
+
|
|
98
102
|
// Configuration
|
|
99
103
|
APP_CONFIG,
|
|
100
104
|
AUTH0_CONFIG,
|
|
@@ -111,6 +115,7 @@ import {
|
|
|
111
115
|
UserData,
|
|
112
116
|
EventPayload,
|
|
113
117
|
Auth0Config,
|
|
118
|
+
Auth0ConfigOptions,
|
|
114
119
|
StorageConfig,
|
|
115
120
|
StorageKeys,
|
|
116
121
|
AppState,
|
package/dist/index.cjs
CHANGED
|
@@ -76,9 +76,9 @@ class EventBus {
|
|
|
76
76
|
* These values are replaced during build time with actual values from GitHub repository variables.
|
|
77
77
|
*/
|
|
78
78
|
const APP_CONFIG = {
|
|
79
|
-
auth0Domain: '',
|
|
80
|
-
auth0ClientId: '',
|
|
81
|
-
apiUrl: '',
|
|
79
|
+
auth0Domain: 'dev-26sow24tone5na8a.us.auth0.com',
|
|
80
|
+
auth0ClientId: 'EdkPy5co65jESIAT8T9SBy5X4cmeolhl',
|
|
81
|
+
apiUrl: 'https://noq8dav0ac.execute-api.us-east-1.amazonaws.com',
|
|
82
82
|
};
|
|
83
83
|
|
|
84
84
|
/**
|
|
@@ -88,20 +88,47 @@ const APP_CONFIG = {
|
|
|
88
88
|
*/
|
|
89
89
|
/**
|
|
90
90
|
* Auth0 client configuration
|
|
91
|
-
* Override these values in your consuming application
|
|
91
|
+
* Override these values in your consuming application using configureAuth0()
|
|
92
92
|
*
|
|
93
93
|
* Note: redirectUri defaults to window.location.origin (base URL without path).
|
|
94
94
|
* Auth0 will redirect back to this URL after authentication.
|
|
95
95
|
*/
|
|
96
96
|
const AUTH0_CONFIG = {
|
|
97
|
-
domain: '', // Set
|
|
98
|
-
clientId: '', // Set
|
|
97
|
+
domain: '', // Set via configureAuth0() or process.env
|
|
98
|
+
clientId: '', // Set via configureAuth0() or process.env
|
|
99
99
|
redirectUri: typeof window !== 'undefined' ? window.location.origin : '',
|
|
100
100
|
logoutUri: typeof window !== 'undefined' ? window.location.origin : '',
|
|
101
|
-
audience: '', // Optional: Set
|
|
101
|
+
audience: '', // Optional: Set via configureAuth0()
|
|
102
102
|
scope: 'openid profile email', // Default scopes
|
|
103
|
-
connection: undefined, // Optional: Force specific connection
|
|
103
|
+
connection: undefined, // Optional: Force specific connection
|
|
104
104
|
};
|
|
105
|
+
/**
|
|
106
|
+
* Configure Auth0 settings
|
|
107
|
+
* Call this function early in your application (e.g., in app.config.ts or main.ts)
|
|
108
|
+
* to override the default Auth0 configuration values.
|
|
109
|
+
*
|
|
110
|
+
* @param config - Partial Auth0 configuration to override defaults
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* import { configureAuth0, APP_CONFIG } from '@opensourcekd/ng-common-libs';
|
|
115
|
+
*
|
|
116
|
+
* configureAuth0({
|
|
117
|
+
* domain: APP_CONFIG.auth0Domain,
|
|
118
|
+
* clientId: APP_CONFIG.auth0ClientId,
|
|
119
|
+
* audience: APP_CONFIG.apiUrl,
|
|
120
|
+
* });
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
function configureAuth0(config) {
|
|
124
|
+
// Only update properties that are explicitly provided (not undefined)
|
|
125
|
+
Object.keys(config).forEach((key) => {
|
|
126
|
+
const configKey = key;
|
|
127
|
+
if (config[configKey] !== undefined) {
|
|
128
|
+
AUTH0_CONFIG[configKey] = config[configKey];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
105
132
|
/**
|
|
106
133
|
* Storage configuration
|
|
107
134
|
* Controls where sensitive data is stored
|
|
@@ -117,6 +144,20 @@ const STORAGE_KEYS = {
|
|
|
117
144
|
ACCESS_TOKEN: 'auth0_access_token',
|
|
118
145
|
USER_INFO: 'auth0_user_info',
|
|
119
146
|
};
|
|
147
|
+
/**
|
|
148
|
+
* Reset AUTH0_CONFIG to default values
|
|
149
|
+
* Useful for testing
|
|
150
|
+
* @internal
|
|
151
|
+
*/
|
|
152
|
+
function resetAuth0Config() {
|
|
153
|
+
AUTH0_CONFIG.domain = '';
|
|
154
|
+
AUTH0_CONFIG.clientId = '';
|
|
155
|
+
AUTH0_CONFIG.redirectUri = typeof window !== 'undefined' ? window.location.origin : '';
|
|
156
|
+
AUTH0_CONFIG.logoutUri = typeof window !== 'undefined' ? window.location.origin : '';
|
|
157
|
+
AUTH0_CONFIG.audience = '';
|
|
158
|
+
AUTH0_CONFIG.scope = 'openid profile email';
|
|
159
|
+
AUTH0_CONFIG.connection = undefined;
|
|
160
|
+
}
|
|
120
161
|
/**
|
|
121
162
|
* Helper functions for storage operations
|
|
122
163
|
* These work with both localStorage and sessionStorage
|
|
@@ -588,6 +629,43 @@ class AuthService {
|
|
|
588
629
|
console.log('[AuthService] Auth event emitted:', event.type);
|
|
589
630
|
}
|
|
590
631
|
}
|
|
632
|
+
/**
|
|
633
|
+
* Create AuthService instance using AUTH0_CONFIG
|
|
634
|
+
* Helper function for creating AuthService with default configuration from AUTH0_CONFIG
|
|
635
|
+
*
|
|
636
|
+
* Note: Make sure to call configureAuth0() before using this helper
|
|
637
|
+
*
|
|
638
|
+
* @param eventBus - EventBus instance for auth events
|
|
639
|
+
* @returns Configured AuthService instance
|
|
640
|
+
*
|
|
641
|
+
* @example
|
|
642
|
+
* ```typescript
|
|
643
|
+
* import { createAuthService, EventBus, configureAuth0, APP_CONFIG } from '@opensourcekd/ng-common-libs';
|
|
644
|
+
*
|
|
645
|
+
* // Configure Auth0 first
|
|
646
|
+
* configureAuth0({
|
|
647
|
+
* domain: APP_CONFIG.auth0Domain,
|
|
648
|
+
* clientId: APP_CONFIG.auth0ClientId,
|
|
649
|
+
* audience: APP_CONFIG.apiUrl,
|
|
650
|
+
* });
|
|
651
|
+
*
|
|
652
|
+
* // Create instances
|
|
653
|
+
* const eventBus = new EventBus();
|
|
654
|
+
* const authService = createAuthService(eventBus);
|
|
655
|
+
* ```
|
|
656
|
+
*/
|
|
657
|
+
function createAuthService(eventBus) {
|
|
658
|
+
const auth0Config = {
|
|
659
|
+
domain: AUTH0_CONFIG.domain,
|
|
660
|
+
clientId: AUTH0_CONFIG.clientId,
|
|
661
|
+
redirectUri: AUTH0_CONFIG.redirectUri,
|
|
662
|
+
logoutUri: AUTH0_CONFIG.logoutUri,
|
|
663
|
+
audience: AUTH0_CONFIG.audience,
|
|
664
|
+
scope: AUTH0_CONFIG.scope,
|
|
665
|
+
connection: AUTH0_CONFIG.connection,
|
|
666
|
+
};
|
|
667
|
+
return new AuthService(auth0Config, eventBus, STORAGE_CONFIG, STORAGE_KEYS);
|
|
668
|
+
}
|
|
591
669
|
|
|
592
670
|
exports.APP_CONFIG = APP_CONFIG;
|
|
593
671
|
exports.AUTH0_CONFIG = AUTH0_CONFIG;
|
|
@@ -595,7 +673,10 @@ exports.AuthService = AuthService;
|
|
|
595
673
|
exports.EventBus = EventBus;
|
|
596
674
|
exports.STORAGE_CONFIG = STORAGE_CONFIG;
|
|
597
675
|
exports.STORAGE_KEYS = STORAGE_KEYS;
|
|
676
|
+
exports.configureAuth0 = configureAuth0;
|
|
677
|
+
exports.createAuthService = createAuthService;
|
|
598
678
|
exports.getStorageItem = getStorageItem$1;
|
|
599
679
|
exports.removeStorageItem = removeStorageItem$1;
|
|
680
|
+
exports.resetAuth0Config = resetAuth0Config;
|
|
600
681
|
exports.setStorageItem = setStorageItem$1;
|
|
601
682
|
//# sourceMappingURL=index.cjs.map
|