@posiwise/common-services 0.2.26 → 0.2.27

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.
@@ -2,24 +2,24 @@ import * as i0 from '@angular/core';
2
2
  import { DOCUMENT, Inject, Injectable, isDevMode, inject, NgModule, ViewEncapsulation } from '@angular/core';
3
3
  import * as i3 from '@angular/router';
4
4
  import { NavigationEnd } from '@angular/router';
5
- import * as i2 from '@posiwise/app-config-service';
5
+ import * as i1 from '@posiwise/app-config-service';
6
6
  import { AppConfigService } from '@posiwise/app-config-service';
7
- import * as i1$1 from '@angular/common/http';
7
+ import * as i1$2 from '@angular/common/http';
8
8
  import { HttpErrorResponse, HttpHeaders } from '@angular/common/http';
9
- import { throwError, of, BehaviorSubject, tap, timer } from 'rxjs';
10
- import { catchError, take, tap as tap$1, switchMap, map, mergeMap, distinctUntilChanged } from 'rxjs/operators';
9
+ import { throwError, of, BehaviorSubject, tap, timer, defer } from 'rxjs';
10
+ import { catchError, take, tap as tap$1, switchMap, map, mergeMap, distinctUntilChanged, retry, filter } from 'rxjs/operators';
11
11
  import { HelperService } from '@posiwise/helper-service';
12
- import * as i1 from 'ngx-toastr';
12
+ import * as i1$1 from 'ngx-toastr';
13
13
  import { CommonModule } from '@angular/common';
14
14
  import { getUser, SetUser, UserActionTypes, appReducers } from '@posiwise/app-store';
15
- import * as i1$2 from '@ngrx/effects';
15
+ import * as i1$3 from '@ngrx/effects';
16
16
  import { Actions, createEffect, ofType, EffectsModule } from '@ngrx/effects';
17
- import * as i3$1 from '@ngrx/store';
17
+ import * as i2 from '@ngrx/store';
18
18
  import { StoreModule } from '@ngrx/store';
19
19
  import { INTEGRATIONS_API_PREFIX, MAIN_API_PREFIX, PROJECT_PATH, USER_PATH, TOKEN_HEADER_KEY, NEWSLETTER_CONFIRMATION_PATH, NEWSLETTER_UNSUBSCRIBE_PATH, CAPTCHA_VALIDATION_PATH, SOCIAL_LOGIN_PATH, TOKEN_KEY, PERMISSION_NAMES, ADMIN_SUB_MENU_WHITELIST, AB_TEST_ACTIONS, GEO_PATH, PRODUCT_PATH, CONTACT_US_PATH, INCIDENTS_PATH, INCIDENTS_PATH_ADMIN, NEWSLETTERS_PATH, NEWSLETTER_SUBSCRIPTION_PATH, ADMIN_FAQS_PATH, FAQS_PATH, ORGANIZATIONS_PATH, GLOBAL_SUBSCRIPTION_CONFIGS_PATH, GLOBAL_CONFIGS_PATH, USER_LOGIN_NOTIFICATION, FEEDBACK_QUESTIONS_PATH, USER_FEEDBACKS_PATH, CUSTOMER_SUPPORT_PATH, ADMIN_TAG_PATH, ADMIN_TAG_CATEGORIES_PATH, ADMIN_PATH, QUALIFICATIONS_PATH, BRAIN_API_PREFIX, SOCKET_TYPE } from '@posiwise/common-utilities';
20
20
  import swal from 'sweetalert2';
21
21
  import moment from 'moment';
22
- import * as i1$3 from '@angular/platform-browser';
22
+ import * as i1$4 from '@angular/platform-browser';
23
23
  import cloneDeep from 'lodash/cloneDeep';
24
24
  import pickBy from 'lodash/pickBy';
25
25
  import * as i2$1 from 'ngx-cookie';
@@ -227,12 +227,12 @@ class GoogleAnalyticsService {
227
227
  this.subscription.unsubscribe();
228
228
  }
229
229
  }
230
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: GoogleAnalyticsService, deps: [{ token: i3.Router }, { token: ScriptLoaderService }, { token: i2.AppConfigService }], target: i0.ɵɵFactoryTarget.Injectable }); }
230
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: GoogleAnalyticsService, deps: [{ token: i3.Router }, { token: ScriptLoaderService }, { token: i1.AppConfigService }], target: i0.ɵɵFactoryTarget.Injectable }); }
231
231
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: GoogleAnalyticsService }); }
232
232
  }
233
233
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: GoogleAnalyticsService, decorators: [{
234
234
  type: Injectable
235
- }], ctorParameters: () => [{ type: i3.Router }, { type: ScriptLoaderService }, { type: i2.AppConfigService }] });
235
+ }], ctorParameters: () => [{ type: i3.Router }, { type: ScriptLoaderService }, { type: i1.AppConfigService }] });
236
236
 
237
237
  class CustomToastService {
238
238
  constructor(toastr) {
@@ -240,13 +240,13 @@ class CustomToastService {
240
240
  }
241
241
  success(message, title = '', options = {}) {
242
242
  if (message) {
243
- this.toastr.success(message, title, { ...options, timeOut: 10000 });
243
+ this.toastr.success(message, title, { ...options, timeOut: 5000 });
244
244
  }
245
245
  }
246
246
  error(message, title = '', options = {}) {
247
247
  options = {
248
248
  ...options,
249
- timeOut: 20000
249
+ timeOut: 8000
250
250
  };
251
251
  if (message) {
252
252
  this.toastr.error(message, title, options);
@@ -254,7 +254,7 @@ class CustomToastService {
254
254
  }
255
255
  info(message, title = '', options = {}) {
256
256
  // disable auto timeout, toast would close on click (to disable auto timeout please use this attribute disableTimeOut:true in options)
257
- options = { ...options, timeOut: 30000, enableHtml: true };
257
+ options = { ...options, timeOut: 5000, enableHtml: true };
258
258
  if (message) {
259
259
  this.toastr.info(`<div class="d-flex align-items-center">
260
260
  <i class="fa fa-info-circle" aria-hidden="true"></i>
@@ -264,7 +264,7 @@ class CustomToastService {
264
264
  }
265
265
  warning(message, title = '', options = {}) {
266
266
  // disable auto timeout, toast would close on click (to disable auto timeout please use this attribute disableTimeOut:true in options)
267
- options = { ...options, timeOut: 30000 };
267
+ options = { ...options, timeOut: 6000 };
268
268
  if (message) {
269
269
  this.toastr.warning(message, title, options);
270
270
  }
@@ -304,7 +304,7 @@ class CustomToastService {
304
304
  this.error(message);
305
305
  }
306
306
  }
307
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: CustomToastService, deps: [{ token: i1.ToastrService }], target: i0.ɵɵFactoryTarget.Injectable }); }
307
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: CustomToastService, deps: [{ token: i1$1.ToastrService }], target: i0.ɵɵFactoryTarget.Injectable }); }
308
308
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: CustomToastService, providedIn: 'root' }); }
309
309
  }
310
310
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: CustomToastService, decorators: [{
@@ -312,7 +312,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
312
312
  args: [{
313
313
  providedIn: 'root'
314
314
  }]
315
- }], ctorParameters: () => [{ type: i1.ToastrService }] });
315
+ }], ctorParameters: () => [{ type: i1$1.ToastrService }] });
316
316
 
317
317
  /* eslint-disable @typescript-eslint/no-explicit-any */
318
318
  class BaseHttpService {
@@ -404,12 +404,12 @@ class BaseHttpService {
404
404
  this.toast.showToast(error);
405
405
  }
406
406
  }
407
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: BaseHttpService, deps: [{ token: i1$1.HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
407
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: BaseHttpService, deps: [{ token: i1$2.HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
408
408
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: BaseHttpService }); }
409
409
  }
410
410
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: BaseHttpService, decorators: [{
411
411
  type: Injectable
412
- }], ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i0.Injector }] });
412
+ }], ctorParameters: () => [{ type: i1$2.HttpClient }, { type: i0.Injector }] });
413
413
 
414
414
  class IntegrationsApiHttpService extends BaseHttpService {
415
415
  constructor(http, injector) {
@@ -422,7 +422,7 @@ class IntegrationsApiHttpService extends BaseHttpService {
422
422
  : config?.['links']?.integrations_api;
423
423
  });
424
424
  }
425
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: IntegrationsApiHttpService, deps: [{ token: i1$1.HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
425
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: IntegrationsApiHttpService, deps: [{ token: i1$2.HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
426
426
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: IntegrationsApiHttpService, providedIn: 'root' }); }
427
427
  }
428
428
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: IntegrationsApiHttpService, decorators: [{
@@ -430,7 +430,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
430
430
  args: [{
431
431
  providedIn: 'root'
432
432
  }]
433
- }], ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i0.Injector }] });
433
+ }], ctorParameters: () => [{ type: i1$2.HttpClient }, { type: i0.Injector }] });
434
434
 
435
435
  class LocalStorage {
436
436
  getItem$(key) {
@@ -470,7 +470,7 @@ class MainApiHttpService extends BaseHttpService {
470
470
  this.baseUrl = isDevMode() ? MAIN_API_PREFIX : config?.['links']?.main_api;
471
471
  });
472
472
  }
473
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: MainApiHttpService, deps: [{ token: i1$1.HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
473
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: MainApiHttpService, deps: [{ token: i1$2.HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
474
474
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: MainApiHttpService, providedIn: 'root' }); }
475
475
  }
476
476
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: MainApiHttpService, decorators: [{
@@ -478,7 +478,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
478
478
  args: [{
479
479
  providedIn: 'root'
480
480
  }]
481
- }], ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i0.Injector }] });
481
+ }], ctorParameters: () => [{ type: i1$2.HttpClient }, { type: i0.Injector }] });
482
482
 
483
483
  /**
484
484
  * Secure Token Storage Service
@@ -1013,7 +1013,7 @@ class UserService {
1013
1013
  refreshUserApiTokens() {
1014
1014
  return this.api.get(`${this.endpoint}/refresh_user_api_tokens`);
1015
1015
  }
1016
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: UserService, deps: [{ token: MainApiHttpService }, { token: i3$1.Store }, { token: i3.Router }, { token: i2.AppConfigService }, { token: ProfileService }, { token: CustomToastService }], target: i0.ɵɵFactoryTarget.Injectable }); }
1016
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: UserService, deps: [{ token: MainApiHttpService }, { token: i2.Store }, { token: i3.Router }, { token: i1.AppConfigService }, { token: ProfileService }, { token: CustomToastService }], target: i0.ɵɵFactoryTarget.Injectable }); }
1017
1017
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: UserService, providedIn: 'root' }); }
1018
1018
  }
1019
1019
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: UserService, decorators: [{
@@ -1021,7 +1021,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
1021
1021
  args: [{
1022
1022
  providedIn: 'root'
1023
1023
  }]
1024
- }], ctorParameters: () => [{ type: MainApiHttpService }, { type: i3$1.Store }, { type: i3.Router }, { type: i2.AppConfigService }, { type: ProfileService }, { type: CustomToastService }] });
1024
+ }], ctorParameters: () => [{ type: MainApiHttpService }, { type: i2.Store }, { type: i3.Router }, { type: i1.AppConfigService }, { type: ProfileService }, { type: CustomToastService }] });
1025
1025
 
1026
1026
  class AuthService {
1027
1027
  constructor(localStorage, secureTokenStorage, router, http, userService, toastr, appConfigService, integrationsApi, document) {
@@ -1400,12 +1400,12 @@ class AuthService {
1400
1400
  }
1401
1401
  });
1402
1402
  }
1403
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: AuthService, deps: [{ token: LocalStorage }, { token: SecureTokenStorageService }, { token: i3.Router }, { token: MainApiHttpService }, { token: UserService }, { token: CustomToastService }, { token: i2.AppConfigService }, { token: IntegrationsApiHttpService }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable }); }
1403
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: AuthService, deps: [{ token: LocalStorage }, { token: SecureTokenStorageService }, { token: i3.Router }, { token: MainApiHttpService }, { token: UserService }, { token: CustomToastService }, { token: i1.AppConfigService }, { token: IntegrationsApiHttpService }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable }); }
1404
1404
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: AuthService }); }
1405
1405
  }
1406
1406
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: AuthService, decorators: [{
1407
1407
  type: Injectable
1408
- }], ctorParameters: () => [{ type: LocalStorage }, { type: SecureTokenStorageService }, { type: i3.Router }, { type: MainApiHttpService }, { type: UserService }, { type: CustomToastService }, { type: i2.AppConfigService }, { type: IntegrationsApiHttpService }, { type: Document, decorators: [{
1408
+ }], ctorParameters: () => [{ type: LocalStorage }, { type: SecureTokenStorageService }, { type: i3.Router }, { type: MainApiHttpService }, { type: UserService }, { type: CustomToastService }, { type: i1.AppConfigService }, { type: IntegrationsApiHttpService }, { type: Document, decorators: [{
1409
1409
  type: Inject,
1410
1410
  args: [DOCUMENT]
1411
1411
  }] }] });
@@ -1432,7 +1432,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
1432
1432
 
1433
1433
  class CommonServicesModule {
1434
1434
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: CommonServicesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
1435
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.6", ngImport: i0, type: CommonServicesModule, imports: [CommonModule, i1$2.EffectsRootModule, i3$1.StoreRootModule] }); }
1435
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.6", ngImport: i0, type: CommonServicesModule, imports: [CommonModule, i1$3.EffectsRootModule, i2.StoreRootModule] }); }
1436
1436
  static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: CommonServicesModule, providers: [AuthService], imports: [CommonModule, EffectsModule.forRoot([UserEffects]), StoreModule.forRoot(appReducers)] }); }
1437
1437
  }
1438
1438
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: CommonServicesModule, decorators: [{
@@ -1472,7 +1472,7 @@ class SeoService {
1472
1472
  this.meta.updateTag({ name: 'twitter:description', content: description });
1473
1473
  this.meta.updateTag({ name: 'twitter:card', content: 'summary' });
1474
1474
  }
1475
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: SeoService, deps: [{ token: i1$3.Meta }, { token: i1$3.Title }], target: i0.ɵɵFactoryTarget.Injectable }); }
1475
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: SeoService, deps: [{ token: i1$4.Meta }, { token: i1$4.Title }], target: i0.ɵɵFactoryTarget.Injectable }); }
1476
1476
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: SeoService, providedIn: 'root' }); }
1477
1477
  }
1478
1478
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: SeoService, decorators: [{
@@ -1480,7 +1480,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
1480
1480
  args: [{
1481
1481
  providedIn: 'root'
1482
1482
  }]
1483
- }], ctorParameters: () => [{ type: i1$3.Meta }, { type: i1$3.Title }] });
1483
+ }], ctorParameters: () => [{ type: i1$4.Meta }, { type: i1$4.Title }] });
1484
1484
 
1485
1485
  /**
1486
1486
  * Centralized feature flag evaluation service.
@@ -1938,7 +1938,7 @@ class AbTestService {
1938
1938
  ? this.injector.get(service)
1939
1939
  : this.injector.get(MainApiHttpService);
1940
1940
  }
1941
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: AbTestService, deps: [{ token: i0.Injector }, { token: i1$1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
1941
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: AbTestService, deps: [{ token: i0.Injector }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
1942
1942
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: AbTestService, providedIn: 'root' }); }
1943
1943
  }
1944
1944
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: AbTestService, decorators: [{
@@ -1946,7 +1946,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
1946
1946
  args: [{
1947
1947
  providedIn: 'root'
1948
1948
  }]
1949
- }], ctorParameters: () => [{ type: i0.Injector }, { type: i1$1.HttpClient }] });
1949
+ }], ctorParameters: () => [{ type: i0.Injector }, { type: i1$2.HttpClient }] });
1950
1950
 
1951
1951
  class GeoService {
1952
1952
  constructor(api, cookieService) {
@@ -2329,7 +2329,7 @@ class AhoyService {
2329
2329
  this.toast.showToast(error);
2330
2330
  }
2331
2331
  }
2332
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: AhoyService, deps: [{ token: i1$1.HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
2332
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: AhoyService, deps: [{ token: i1$2.HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
2333
2333
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: AhoyService, providedIn: 'root' }); }
2334
2334
  }
2335
2335
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: AhoyService, decorators: [{
@@ -2337,7 +2337,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
2337
2337
  args: [{
2338
2338
  providedIn: 'root'
2339
2339
  }]
2340
- }], ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i0.Injector }] });
2340
+ }], ctorParameters: () => [{ type: i1$2.HttpClient }, { type: i0.Injector }] });
2341
2341
 
2342
2342
  class CommonService {
2343
2343
  constructor(api) {
@@ -2990,7 +2990,7 @@ class McpJsonRpcService {
2990
2990
  return res.result;
2991
2991
  }));
2992
2992
  }
2993
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: McpJsonRpcService, deps: [{ token: i1$1.HttpClient }, { token: i2.AppConfigService }, { token: i3$1.Store }], target: i0.ɵɵFactoryTarget.Injectable }); }
2993
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: McpJsonRpcService, deps: [{ token: i1$2.HttpClient }, { token: i1.AppConfigService }, { token: i2.Store }], target: i0.ɵɵFactoryTarget.Injectable }); }
2994
2994
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: McpJsonRpcService, providedIn: 'root' }); }
2995
2995
  }
2996
2996
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: McpJsonRpcService, decorators: [{
@@ -2998,7 +2998,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
2998
2998
  args: [{
2999
2999
  providedIn: 'root'
3000
3000
  }]
3001
- }], ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i2.AppConfigService }, { type: i3$1.Store }] });
3001
+ }], ctorParameters: () => [{ type: i1$2.HttpClient }, { type: i1.AppConfigService }, { type: i2.Store }] });
3002
3002
 
3003
3003
  /* eslint-disable @typescript-eslint/no-explicit-any */
3004
3004
  class MCPOrchestratorService {
@@ -3034,7 +3034,7 @@ class MCPOrchestratorService {
3034
3034
  }));
3035
3035
  return base$.pipe(switchMap(base => this.store.pipe(take(1), map((app) => this.pickApiCredentials(app.user?.currentUser ?? null)), switchMap(creds => {
3036
3036
  if (!creds) {
3037
- return throwError(() => new Error('PosiWise Brain needs API credentials. Go to /account/details to set or rotate your API keys, then open the active subscription from /account/subscriptions to refresh its credentials.'));
3037
+ return throwError(() => new Error('The assistant needs API credentials. Go to /account/details to set or rotate your API keys, then open the active subscription from /account/subscriptions to refresh its credentials.'));
3038
3038
  }
3039
3039
  return this.http.post(`${base}/${path}`, body, {
3040
3040
  headers: this.buildHeaders(creds)
@@ -3082,7 +3082,7 @@ class MCPOrchestratorService {
3082
3082
  }
3083
3083
  return h;
3084
3084
  }
3085
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: MCPOrchestratorService, deps: [{ token: i1$1.HttpClient }, { token: i2.AppConfigService }, { token: i3$1.Store }], target: i0.ɵɵFactoryTarget.Injectable }); }
3085
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: MCPOrchestratorService, deps: [{ token: i1$2.HttpClient }, { token: i1.AppConfigService }, { token: i2.Store }], target: i0.ɵɵFactoryTarget.Injectable }); }
3086
3086
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: MCPOrchestratorService, providedIn: 'root' }); }
3087
3087
  }
3088
3088
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: MCPOrchestratorService, decorators: [{
@@ -3090,7 +3090,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
3090
3090
  args: [{
3091
3091
  providedIn: 'root'
3092
3092
  }]
3093
- }], ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i2.AppConfigService }, { type: i3$1.Store }] });
3093
+ }], ctorParameters: () => [{ type: i1$2.HttpClient }, { type: i1.AppConfigService }, { type: i2.Store }] });
3094
3094
 
3095
3095
  class WebsocketService {
3096
3096
  constructor(appConfigService, authService) {
@@ -3103,7 +3103,7 @@ class WebsocketService {
3103
3103
  this.webSocket$ = this.webSocketSubject.asObservable().pipe(distinctUntilChanged());
3104
3104
  });
3105
3105
  }
3106
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: WebsocketService, deps: [{ token: i2.AppConfigService }, { token: AuthService }], target: i0.ɵɵFactoryTarget.Injectable }); }
3106
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: WebsocketService, deps: [{ token: i1.AppConfigService }, { token: AuthService }], target: i0.ɵɵFactoryTarget.Injectable }); }
3107
3107
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: WebsocketService, providedIn: 'root' }); }
3108
3108
  }
3109
3109
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: WebsocketService, decorators: [{
@@ -3111,7 +3111,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
3111
3111
  args: [{
3112
3112
  providedIn: 'root'
3113
3113
  }]
3114
- }], ctorParameters: () => [{ type: i2.AppConfigService }, { type: AuthService }] });
3114
+ }], ctorParameters: () => [{ type: i1.AppConfigService }, { type: AuthService }] });
3115
3115
 
3116
3116
  class NotificationService {
3117
3117
  constructor(api, toastrService, socketService) {
@@ -3172,6 +3172,97 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
3172
3172
  }]
3173
3173
  }], ctorParameters: () => [{ type: MainApiHttpService }, { type: CustomToastService }, { type: WebsocketService }] });
3174
3174
 
3175
+ /**
3176
+ * Server→client push channel for the Posiwise Brain chat panel (ticket #45).
3177
+ *
3178
+ * Opens a WebSocket to `GET /brain-api/v1/ws`. brain-api subscribes the socket
3179
+ * to the user's Redis channel and forwards every message published via
3180
+ * `POST /brain-api/v1/ws/push` as a JSON frame. Mirrors the existing
3181
+ * `WebsocketService` (main-api Faye socket) in spirit, but talks to brain-api
3182
+ * and authenticates with the same user-token credentials the
3183
+ * `MCPOrchestratorService` sends as headers.
3184
+ *
3185
+ * Auth: a WebSocket upgrade can't carry custom headers from the browser, so
3186
+ * the three credential values are bundled into a single base64'd JSON
3187
+ * `session_token` query param. brain-api decodes it back into the headers its
3188
+ * canonical authenticator expects (close code 4401 if missing/invalid).
3189
+ *
3190
+ * Reconnect: nginx ingress cuts idle upstream connections at ~60s, and this
3191
+ * channel is mostly idle, so the stream auto-reconnects with a fixed backoff.
3192
+ * Each reconnect re-resolves credentials (via `defer`) so a rotated token is
3193
+ * picked up rather than replayed.
3194
+ */
3195
+ const RECONNECT_DELAY_MS = 5_000;
3196
+ const BRAIN_MESSAGE_EVENT = 'brain_message';
3197
+ class BrainSocketService {
3198
+ constructor(appConfigService, store) {
3199
+ this.appConfigService = appConfigService;
3200
+ this.store = store;
3201
+ }
3202
+ /**
3203
+ * Hot stream of assistant messages pushed by the server. Subscribe when the
3204
+ * chat panel mounts; unsubscribe (via `takeUntil`) when it tears down.
3205
+ */
3206
+ messages$() {
3207
+ return defer(() => this.buildSocketUrl$().pipe(switchMap(url => webSocket(url)))).pipe(retry({ delay: () => timer(RECONNECT_DELAY_MS) }), filter((frame) => !!frame && frame.event === BRAIN_MESSAGE_EVENT), map(frame => ({ id: frame.id, text: frame.data?.text ?? '' })), filter(message => !!message.text));
3208
+ }
3209
+ buildSocketUrl$() {
3210
+ return this.wsBase$().pipe(switchMap(base => this.store.pipe(take(1), map((app) => this.pickApiCredentials(app.user?.currentUser ?? null)), switchMap(creds => creds
3211
+ ? of(`${base}?session_token=${this.encodeBundle(creds)}`)
3212
+ : throwError(() => new Error('Brain socket needs API credentials.'))))));
3213
+ }
3214
+ /** Absolute `ws(s)://…/brain-api/v1/ws` base, dev (same-origin) or prod (links). */
3215
+ wsBase$() {
3216
+ if (isDevMode()) {
3217
+ const scheme = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
3218
+ const path = `${BRAIN_API_PREFIX.replace(/\/$/, '')}/ws`;
3219
+ return of(`${scheme}//${window.location.host}${path}`);
3220
+ }
3221
+ return this.appConfigService.appConfig$.pipe(take(1), switchMap(c => {
3222
+ const url = c?.links?.['brain_api'];
3223
+ if (typeof url === 'string' && url.trim()) {
3224
+ const wsBase = url.trim().replace(/\/$/, '').replace(/^http/, 'ws');
3225
+ return of(`${wsBase}/ws`);
3226
+ }
3227
+ return throwError(() => new Error('Brain API is not configured: set links.brain_api in app configuration.'));
3228
+ }));
3229
+ }
3230
+ /**
3231
+ * Same credential resolution as `MCPOrchestratorService.pickApiCredentials`
3232
+ * — token/userId from the active user, clientId from the active subscription.
3233
+ */
3234
+ pickApiCredentials(user) {
3235
+ if (!user) {
3236
+ return null;
3237
+ }
3238
+ const token = user.api_user_token ?? user.api_keys?.api_user_token;
3239
+ const userId = user.api_user_id ?? user.api_keys?.api_user_id;
3240
+ if (!token || !userId) {
3241
+ return null;
3242
+ }
3243
+ const clientId = PermissionService.selectedSubscription?.api_client_id;
3244
+ return { token, userId, clientId };
3245
+ }
3246
+ encodeBundle(creds) {
3247
+ const bundle = {
3248
+ api_user_token: creds.token,
3249
+ api_user_id: creds.userId
3250
+ };
3251
+ if (creds.clientId) {
3252
+ bundle['api_client_id'] = creds.clientId;
3253
+ }
3254
+ return encodeURIComponent(btoa(JSON.stringify(bundle)));
3255
+ }
3256
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: BrainSocketService, deps: [{ token: i1.AppConfigService }, { token: i2.Store }], target: i0.ɵɵFactoryTarget.Injectable }); }
3257
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: BrainSocketService, providedIn: 'root' }); }
3258
+ }
3259
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: BrainSocketService, decorators: [{
3260
+ type: Injectable,
3261
+ args: [{
3262
+ providedIn: 'root'
3263
+ }]
3264
+ }], ctorParameters: () => [{ type: i1.AppConfigService }, { type: i2.Store }] });
3265
+
3175
3266
  class DataService {
3176
3267
  constructor() {
3177
3268
  this.messageSource = new BehaviorSubject(0);
@@ -3659,7 +3750,7 @@ class SentryErrorHandler {
3659
3750
  console.error(error, e);
3660
3751
  }
3661
3752
  }
3662
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: SentryErrorHandler, deps: [{ token: i2.AppConfigService }], target: i0.ɵɵFactoryTarget.Injectable }); }
3753
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: SentryErrorHandler, deps: [{ token: i1.AppConfigService }], target: i0.ɵɵFactoryTarget.Injectable }); }
3663
3754
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: SentryErrorHandler, providedIn: 'root' }); }
3664
3755
  }
3665
3756
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: SentryErrorHandler, decorators: [{
@@ -3667,7 +3758,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
3667
3758
  args: [{
3668
3759
  providedIn: 'root'
3669
3760
  }]
3670
- }], ctorParameters: () => [{ type: i2.AppConfigService }] });
3761
+ }], ctorParameters: () => [{ type: i1.AppConfigService }] });
3671
3762
 
3672
3763
  class LogoCacheService {
3673
3764
  constructor() {
@@ -3783,7 +3874,7 @@ class BrainApiHttpService extends BaseHttpService {
3783
3874
  this.baseUrl = isDevMode() ? BRAIN_API_PREFIX : config?.['links']['brain_api'] ?? '';
3784
3875
  });
3785
3876
  }
3786
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: BrainApiHttpService, deps: [{ token: i1$1.HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
3877
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: BrainApiHttpService, deps: [{ token: i1$2.HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
3787
3878
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: BrainApiHttpService, providedIn: 'root' }); }
3788
3879
  }
3789
3880
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: BrainApiHttpService, decorators: [{
@@ -3791,7 +3882,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
3791
3882
  args: [{
3792
3883
  providedIn: 'root'
3793
3884
  }]
3794
- }], ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i0.Injector }] });
3885
+ }], ctorParameters: () => [{ type: i1$2.HttpClient }, { type: i0.Injector }] });
3795
3886
 
3796
3887
  class BrainApiService {
3797
3888
  constructor(api) {
@@ -3818,5 +3909,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
3818
3909
  * Generated bundle index. Do not edit.
3819
3910
  */
3820
3911
 
3821
- export { AbTestService, AhoyService, AuthService, BaseHttpService, BrainApiHttpService, BrainApiService, CommonService, CommonServicesModule, CustomPreloadingStrategy, CustomToastService, DashboardService, DataService, FeatureFlagService, FormHelperService, GeoService, GoogleAnalyticsService, GroupService, HopscotchService, IntegrationsApiHttpService, LinkService, LocalStorage, LogoCacheService, MCPOrchestratorService, MailBoxService, MainApiHttpService, McpJsonRpcService, NgbDateCustomParserFormatter, NotificationService, NumberPickerService, PermissionService, PrimeNgHelper, ProductService, ProfileService, QualificationService, ScriptLoaderService, SecureTokenStorageService, SentryErrorHandler, SeoService, SubscriptionService, TagService, TipsService, UserEffects, UserService, ValidationService, WebsocketService, WindowService };
3912
+ export { AbTestService, AhoyService, AuthService, BaseHttpService, BrainApiHttpService, BrainApiService, BrainSocketService, CommonService, CommonServicesModule, CustomPreloadingStrategy, CustomToastService, DashboardService, DataService, FeatureFlagService, FormHelperService, GeoService, GoogleAnalyticsService, GroupService, HopscotchService, IntegrationsApiHttpService, LinkService, LocalStorage, LogoCacheService, MCPOrchestratorService, MailBoxService, MainApiHttpService, McpJsonRpcService, NgbDateCustomParserFormatter, NotificationService, NumberPickerService, PermissionService, PrimeNgHelper, ProductService, ProfileService, QualificationService, ScriptLoaderService, SecureTokenStorageService, SentryErrorHandler, SeoService, SubscriptionService, TagService, TipsService, UserEffects, UserService, ValidationService, WebsocketService, WindowService };
3822
3913
  //# sourceMappingURL=posiwise-common-services.mjs.map