@aakash58/chatbot 1.1.4 → 1.1.6
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/fesm2022/aakash58-chatbot.mjs +40 -13
- package/fesm2022/aakash58-chatbot.mjs.map +1 -1
- package/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -117,6 +117,7 @@ class Logger {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
class AppConst {
|
|
120
|
+
static appBaseUrl = environment.apiBaseUrl;
|
|
120
121
|
static data;
|
|
121
122
|
config$ = new ReplaySubject(1);
|
|
122
123
|
constructor() { }
|
|
@@ -575,7 +576,6 @@ class AuthService {
|
|
|
575
576
|
}
|
|
576
577
|
else {
|
|
577
578
|
if (!silent) {
|
|
578
|
-
SnackbarUtils.error('Federated login failed.');
|
|
579
579
|
this.authError.set('Federated login failed.');
|
|
580
580
|
}
|
|
581
581
|
this.isLoggingIn.set(false);
|
|
@@ -585,7 +585,6 @@ class AuthService {
|
|
|
585
585
|
catch (error) {
|
|
586
586
|
Logger.error('Federated login failed:', error);
|
|
587
587
|
if (!silent) {
|
|
588
|
-
SnackbarUtils.error('An error occurred during federated login.');
|
|
589
588
|
this.authError.set('An error occurred during federated login.');
|
|
590
589
|
}
|
|
591
590
|
this.isLoggingIn.set(false);
|
|
@@ -598,7 +597,7 @@ class AuthService {
|
|
|
598
597
|
async login(credentials, silent = false) {
|
|
599
598
|
this.isLoggingIn.set(true);
|
|
600
599
|
if (!silent) {
|
|
601
|
-
this.authError.set(null);
|
|
600
|
+
this.authError.set(null); //TODO
|
|
602
601
|
this.authSuccess.set(null);
|
|
603
602
|
}
|
|
604
603
|
try {
|
|
@@ -625,7 +624,6 @@ class AuthService {
|
|
|
625
624
|
catch (error) {
|
|
626
625
|
Logger.error('Login failed:', error);
|
|
627
626
|
if (!silent) {
|
|
628
|
-
SnackbarUtils.error('An error occurred during login.');
|
|
629
627
|
this.authError.set('An error occurred during login.');
|
|
630
628
|
}
|
|
631
629
|
this.isLoggingIn.set(false);
|
|
@@ -991,7 +989,7 @@ class ThemeService {
|
|
|
991
989
|
this.updateActiveTheme(mode);
|
|
992
990
|
// Update primary color globally
|
|
993
991
|
this.applyPrimaryColorToGlobal(primaryColor);
|
|
994
|
-
});
|
|
992
|
+
}, { allowSignalWrites: true });
|
|
995
993
|
}
|
|
996
994
|
applyPrimaryColorToGlobal(color) {
|
|
997
995
|
const root = document.documentElement;
|
|
@@ -4265,39 +4263,44 @@ class LicenseService {
|
|
|
4265
4263
|
* Returns the key for 'doohbot' or null if not found.
|
|
4266
4264
|
*/
|
|
4267
4265
|
resolveTenantLicenseKey(appBaseUrl) {
|
|
4266
|
+
// Extract current URL parts
|
|
4268
4267
|
const hostname = window.location.hostname;
|
|
4269
4268
|
const protocol = window.location.protocol;
|
|
4270
|
-
const port = window.location.port ?
|
|
4269
|
+
const port = window.location.port ? `:${window.location.port}` : '';
|
|
4271
4270
|
const currentUrl = `${protocol}//${hostname}${port}`;
|
|
4271
|
+
// Use provided appBaseUrl or fallback to AppConst
|
|
4272
4272
|
const finalAppBaseUrl = appBaseUrl || AppConst.data?.appBaseUrl;
|
|
4273
4273
|
// Resolve tenancy name
|
|
4274
4274
|
let tenancyName = null;
|
|
4275
|
-
|
|
4275
|
+
// Try extracting tenant from URL pattern if {TENANCY_NAME} is present
|
|
4276
|
+
if (finalAppBaseUrl?.includes('{TENANCY_NAME}')) {
|
|
4276
4277
|
const pattern = finalAppBaseUrl.replace('{TENANCY_NAME}', '(.*?)');
|
|
4277
4278
|
const regex = new RegExp(pattern);
|
|
4278
4279
|
const match = currentUrl.match(regex);
|
|
4279
|
-
tenancyName = match
|
|
4280
|
+
tenancyName = match?.[1] ?? null;
|
|
4280
4281
|
}
|
|
4281
4282
|
if (!tenancyName) {
|
|
4282
|
-
//
|
|
4283
|
+
// use first subdomain part as tenancy name
|
|
4283
4284
|
const parts = hostname.split('.');
|
|
4284
4285
|
if (parts.length > 2)
|
|
4285
4286
|
tenancyName = parts[0];
|
|
4286
4287
|
}
|
|
4288
|
+
// If still not resolved, log and exit
|
|
4287
4289
|
if (!tenancyName) {
|
|
4288
4290
|
Logger.log('[LicenseService] Could not resolve tenancy name.');
|
|
4289
4291
|
return null;
|
|
4290
4292
|
}
|
|
4291
4293
|
Logger.log(`[LicenseService] Detected tenant: ${tenancyName}`);
|
|
4292
|
-
// Lookup license key in registry
|
|
4294
|
+
// Lookup license key in registry ===
|
|
4293
4295
|
const reg = this.registry();
|
|
4294
4296
|
if (!reg)
|
|
4295
4297
|
return null;
|
|
4296
4298
|
const searchKey = `tenant:${tenancyName}`;
|
|
4297
|
-
const
|
|
4298
|
-
|
|
4299
|
+
const tenantLicenses = reg.subjectLicenses.get(searchKey);
|
|
4300
|
+
// Return the 'doohbot' license if it exists
|
|
4301
|
+
if (tenantLicenses?.['doohbot']) {
|
|
4299
4302
|
Logger.log(`[LicenseService] Found key for tenant: ${tenancyName}`);
|
|
4300
|
-
return
|
|
4303
|
+
return tenantLicenses['doohbot'];
|
|
4301
4304
|
}
|
|
4302
4305
|
return null;
|
|
4303
4306
|
}
|
|
@@ -4411,6 +4414,10 @@ class Doohbot extends DoohbotInput {
|
|
|
4411
4414
|
if (this.isAuthenticated()) {
|
|
4412
4415
|
this.initializeUI();
|
|
4413
4416
|
}
|
|
4417
|
+
else if (this.config.authToken) {
|
|
4418
|
+
//! Auto-authenticate if authToken is provided on startup
|
|
4419
|
+
this.onFederatedLogin(this.config.authToken);
|
|
4420
|
+
}
|
|
4414
4421
|
}
|
|
4415
4422
|
initializeUI() {
|
|
4416
4423
|
// Apply theme
|
|
@@ -4446,6 +4453,10 @@ class Doohbot extends DoohbotInput {
|
|
|
4446
4453
|
buttonStyle: this.buttonStyle || this.config.buttonStyle,
|
|
4447
4454
|
});
|
|
4448
4455
|
}
|
|
4456
|
+
// Handle dynamic authToken updates
|
|
4457
|
+
if (this.config.authToken && !this.isAuthenticated()) {
|
|
4458
|
+
this.onFederatedLogin(this.config.authToken);
|
|
4459
|
+
}
|
|
4449
4460
|
}
|
|
4450
4461
|
if (changes['buttonStyle'] && this.buttonStyle) {
|
|
4451
4462
|
this.personalization.setDeveloperDefaults({ buttonStyle: this.buttonStyle });
|
|
@@ -4474,6 +4485,22 @@ class Doohbot extends DoohbotInput {
|
|
|
4474
4485
|
}
|
|
4475
4486
|
this.authService.login(credentials, false);
|
|
4476
4487
|
}
|
|
4488
|
+
onFederatedLogin(token) {
|
|
4489
|
+
// Try to resolve Key from Subdomain
|
|
4490
|
+
let autoKey = this.licenseService.resolveTenantLicenseKey();
|
|
4491
|
+
// Fallback to Config Input
|
|
4492
|
+
if (!autoKey) {
|
|
4493
|
+
autoKey = this.config.licenseKey || '';
|
|
4494
|
+
}
|
|
4495
|
+
if (autoKey) {
|
|
4496
|
+
this.authService.setLicenseKey(autoKey);
|
|
4497
|
+
}
|
|
4498
|
+
this.authService.federatedLogin({
|
|
4499
|
+
accessToken: token,
|
|
4500
|
+
rememberMe: true,
|
|
4501
|
+
license: autoKey,
|
|
4502
|
+
});
|
|
4503
|
+
}
|
|
4477
4504
|
performLogout() {
|
|
4478
4505
|
DialogUtils.confirmLogout(this.dialogService).subscribe((confirmed) => {
|
|
4479
4506
|
if (confirmed) {
|