@aakash58/chatbot 1.0.56 → 1.0.58

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.
@@ -348,6 +348,8 @@ class MessageService {
348
348
  STORAGE_PREFIX = 'doohbot_messages_';
349
349
  // API service (optional)
350
350
  apiService = inject(ChatbotApiService, { optional: true });
351
+ // User context for backend proxy mode
352
+ userContext;
351
353
  // API state signals
352
354
  isLoadingApi = signal(false, ...(ngDevMode ? [{ debugName: "isLoadingApi" }] : []));
353
355
  apiError = signal(null, ...(ngDevMode ? [{ debugName: "apiError" }] : []));
@@ -375,6 +377,19 @@ class MessageService {
375
377
  getCurrentContextKey() {
376
378
  return this.currentContextKey();
377
379
  }
380
+ /**
381
+ * Set user context for backend proxy mode
382
+ * This allows tracking which user sent each message
383
+ */
384
+ setUserContext(context) {
385
+ this.userContext = context;
386
+ }
387
+ /**
388
+ * Get current user context
389
+ */
390
+ getUserContext() {
391
+ return this.userContext;
392
+ }
378
393
  /**
379
394
  * Clear messages for current context
380
395
  */
@@ -661,6 +676,11 @@ const appConst = {
661
676
  };
662
677
 
663
678
  class DoohbotInput {
679
+ username = '';
680
+ password = '';
681
+ authToken;
682
+ DOOHBOT_API_URL;
683
+ skipAuthentication;
664
684
  // inputs
665
685
  userAvatarUrl = appConst.USER_AVATAR;
666
686
  // Application Constants Text
@@ -1378,21 +1398,72 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.14", ngImpo
1378
1398
  }]
1379
1399
  }], ctorParameters: () => [{ type: HttpService }] });
1380
1400
 
1401
+ class CryptoHelperService {
1402
+ encoder = new TextEncoder();
1403
+ decoder = new TextDecoder();
1404
+ secretKey = ''; // Will be set by AuthService
1405
+ setSecretKey(key) {
1406
+ this.secretKey = key;
1407
+ }
1408
+ async getKey() {
1409
+ const salt = this.encoder.encode('fixed_salt'); // Keep constant
1410
+ const baseKey = await crypto.subtle.importKey('raw', this.encoder.encode(this.secretKey), 'PBKDF2', false, ['deriveKey']);
1411
+ return crypto.subtle.deriveKey({
1412
+ name: 'PBKDF2',
1413
+ salt,
1414
+ iterations: 100000,
1415
+ hash: 'SHA-256',
1416
+ }, baseKey, { name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']);
1417
+ }
1418
+ async encrypt(value) {
1419
+ if (!value)
1420
+ return null;
1421
+ const key = await this.getKey();
1422
+ const iv = crypto.getRandomValues(new Uint8Array(12));
1423
+ const encrypted = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, key, this.encoder.encode(value));
1424
+ const merged = new Uint8Array(iv.length + encrypted.byteLength);
1425
+ merged.set(iv, 0);
1426
+ merged.set(new Uint8Array(encrypted), iv.length);
1427
+ return btoa(String.fromCharCode(...merged));
1428
+ }
1429
+ async decrypt(value) {
1430
+ if (!value)
1431
+ return null;
1432
+ const raw = Uint8Array.from(atob(value), (c) => c.charCodeAt(0));
1433
+ const iv = raw.slice(0, 12);
1434
+ const data = raw.slice(12);
1435
+ const key = await this.getKey();
1436
+ const decrypted = await crypto.subtle.decrypt({ name: 'AES-GCM', iv }, key, data);
1437
+ return this.decoder.decode(decrypted);
1438
+ }
1439
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.14", ngImport: i0, type: CryptoHelperService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1440
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.14", ngImport: i0, type: CryptoHelperService, providedIn: 'root' });
1441
+ }
1442
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.14", ngImport: i0, type: CryptoHelperService, decorators: [{
1443
+ type: Injectable,
1444
+ args: [{
1445
+ providedIn: 'root',
1446
+ }]
1447
+ }] });
1448
+
1381
1449
  class AuthService {
1382
1450
  router;
1383
1451
  http;
1452
+ cryptoHelper;
1384
1453
  apiUrl;
1385
1454
  storageKey;
1386
1455
  secretKey;
1387
1456
  companyCode;
1388
1457
  jwtHelper = new JwtHelperService();
1389
- constructor(router, http) {
1458
+ constructor(router, http, cryptoHelper) {
1390
1459
  this.router = router;
1391
1460
  this.http = http;
1461
+ this.cryptoHelper = cryptoHelper;
1392
1462
  this.apiUrl = `${AppConst?.data?.apiBaseUrl}${AppConst?.data?.apiSegment}`;
1393
1463
  this.storageKey = AppConst?.data?.storageKey;
1394
1464
  this.secretKey = AppConst?.data?.secretKey;
1395
1465
  this.companyCode = AppConst?.data?.companyCode;
1466
+ this.cryptoHelper.setSecretKey(this.secretKey);
1396
1467
  }
1397
1468
  logout() {
1398
1469
  const url = `${this.apiUrl}Account/Logout`;
@@ -1508,7 +1579,7 @@ class AuthService {
1508
1579
  getUserId() {
1509
1580
  return this.getLocalStorage('user_id') || 0;
1510
1581
  }
1511
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.14", ngImport: i0, type: AuthService, deps: [{ token: i1$4.Router }, { token: i1$3.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1582
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.14", ngImport: i0, type: AuthService, deps: [{ token: i1$4.Router }, { token: i1$3.HttpClient }, { token: CryptoHelperService }], target: i0.ɵɵFactoryTarget.Injectable });
1512
1583
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.14", ngImport: i0, type: AuthService, providedIn: 'root' });
1513
1584
  }
1514
1585
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.14", ngImport: i0, type: AuthService, decorators: [{
@@ -1516,7 +1587,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.14", ngImpo
1516
1587
  args: [{
1517
1588
  providedIn: 'root',
1518
1589
  }]
1519
- }], ctorParameters: () => [{ type: i1$4.Router }, { type: i1$3.HttpClient }] });
1590
+ }], ctorParameters: () => [{ type: i1$4.Router }, { type: i1$3.HttpClient }, { type: CryptoHelperService }] });
1520
1591
 
1521
1592
  class Doohbot extends DoohbotInput {
1522
1593
  elementRef;
@@ -1532,6 +1603,7 @@ class Doohbot extends DoohbotInput {
1532
1603
  enableResize = false;
1533
1604
  primaryColor;
1534
1605
  apiConfig;
1606
+ userContext; // User context for backend proxy mode
1535
1607
  // @Input() theme: 'light' | 'dark' = 'light';
1536
1608
  isFullScreen = false;
1537
1609
  isChatOpen = signal(false, ...(ngDevMode ? [{ debugName: "isChatOpen" }] : []));
@@ -1609,10 +1681,10 @@ class Doohbot extends DoohbotInput {
1609
1681
  }
1610
1682
  loginUser() {
1611
1683
  let param = {
1612
- // username: this.config.username,
1613
- // password: this.config.password,
1684
+ username: this.config.username || AppConst.data?.username,
1685
+ password: this.config.password || AppConst.data?.password,
1614
1686
  };
1615
- this.accountService.login();
1687
+ this.accountService.login(param);
1616
1688
  }
1617
1689
  updateCssVariables() {
1618
1690
  const host = this.elementRef.nativeElement;
@@ -1733,7 +1805,7 @@ class Doohbot extends DoohbotInput {
1733
1805
  }
1734
1806
  }
1735
1807
  }
1736
- }, ...(ngDevMode ? [{ debugName: "markAsReadEffect" }] : []));
1808
+ }, ...(ngDevMode ? [{ debugName: "markAsReadEffect", allowSignalWrites: true }] : [{ allowSignalWrites: true }]));
1737
1809
  unreadCount = computed(() => {
1738
1810
  if (this.isChatOpen()) {
1739
1811
  return 0;
@@ -1782,7 +1854,7 @@ class Doohbot extends DoohbotInput {
1782
1854
  }
1783
1855
  }
1784
1856
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.14", ngImport: i0, type: Doohbot, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: AccountService }, { token: AuthService }], target: i0.ɵɵFactoryTarget.Component });
1785
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.14", type: Doohbot, isStandalone: true, selector: "app-doohbot", inputs: { config: "config", platformTenant: "platformTenant", subTenant: "subTenant", agent: "agent", buttonStyle: "buttonStyle", enableDrag: "enableDrag", enableResize: "enableResize", primaryColor: "primaryColor", apiConfig: "apiConfig" }, providers: [
1857
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.14", type: Doohbot, isStandalone: true, selector: "app-doohbot", inputs: { config: "config", platformTenant: "platformTenant", subTenant: "subTenant", agent: "agent", buttonStyle: "buttonStyle", enableDrag: "enableDrag", enableResize: "enableResize", primaryColor: "primaryColor", apiConfig: "apiConfig", userContext: "userContext" }, providers: [
1786
1858
  AppConst,
1787
1859
  {
1788
1860
  provide: APP_INITIALIZER,
@@ -1821,6 +1893,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.14", ngImpo
1821
1893
  type: Input
1822
1894
  }], apiConfig: [{
1823
1895
  type: Input
1896
+ }], userContext: [{
1897
+ type: Input
1824
1898
  }], chatWindowRef: [{
1825
1899
  type: ViewChild,
1826
1900
  args: [ChatWindowComponent, { read: ElementRef }]