@posiwise/common-services 0.2.23 → 0.2.25

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 i1 from '@posiwise/app-config-service';
5
+ import * as i2 from '@posiwise/app-config-service';
6
6
  import { AppConfigService } from '@posiwise/app-config-service';
7
- import * as i1$2 from '@angular/common/http';
7
+ import * as i1$1 from '@angular/common/http';
8
8
  import { HttpErrorResponse, HttpHeaders } from '@angular/common/http';
9
9
  import { throwError, of, BehaviorSubject, tap, timer } from 'rxjs';
10
10
  import { catchError, take, tap as tap$1, switchMap, map, mergeMap, distinctUntilChanged } from 'rxjs/operators';
11
11
  import { HelperService } from '@posiwise/helper-service';
12
- import * as i1$1 from 'ngx-toastr';
12
+ import * as i1 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$3 from '@ngrx/effects';
15
+ import * as i1$2 from '@ngrx/effects';
16
16
  import { Actions, createEffect, ofType, EffectsModule } from '@ngrx/effects';
17
- import * as i2 from '@ngrx/store';
17
+ import * as i3$1 from '@ngrx/store';
18
18
  import { StoreModule } from '@ngrx/store';
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, SOCKET_TYPE, BRAIN_API_PREFIX } from '@posiwise/common-utilities';
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$4 from '@angular/platform-browser';
22
+ import * as i1$3 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: i1.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: i2.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: i1.AppConfigService }] });
235
+ }], ctorParameters: () => [{ type: i3.Router }, { type: ScriptLoaderService }, { type: i2.AppConfigService }] });
236
236
 
237
237
  class CustomToastService {
238
238
  constructor(toastr) {
@@ -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$1.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.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$1.ToastrService }] });
315
+ }], ctorParameters: () => [{ type: i1.ToastrService }] });
316
316
 
317
317
  /* eslint-disable @typescript-eslint/no-explicit-any */
318
318
  class BaseHttpService {
@@ -398,12 +398,12 @@ class BaseHttpService {
398
398
  this.toast.showToast(error);
399
399
  }
400
400
  }
401
- 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 }); }
401
+ 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 }); }
402
402
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: BaseHttpService }); }
403
403
  }
404
404
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: BaseHttpService, decorators: [{
405
405
  type: Injectable
406
- }], ctorParameters: () => [{ type: i1$2.HttpClient }, { type: i0.Injector }] });
406
+ }], ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i0.Injector }] });
407
407
 
408
408
  class IntegrationsApiHttpService extends BaseHttpService {
409
409
  constructor(http, injector) {
@@ -416,7 +416,7 @@ class IntegrationsApiHttpService extends BaseHttpService {
416
416
  : config?.['links']?.integrations_api;
417
417
  });
418
418
  }
419
- 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 }); }
419
+ 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 }); }
420
420
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: IntegrationsApiHttpService, providedIn: 'root' }); }
421
421
  }
422
422
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: IntegrationsApiHttpService, decorators: [{
@@ -424,7 +424,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
424
424
  args: [{
425
425
  providedIn: 'root'
426
426
  }]
427
- }], ctorParameters: () => [{ type: i1$2.HttpClient }, { type: i0.Injector }] });
427
+ }], ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i0.Injector }] });
428
428
 
429
429
  class LocalStorage {
430
430
  getItem$(key) {
@@ -464,7 +464,7 @@ class MainApiHttpService extends BaseHttpService {
464
464
  this.baseUrl = isDevMode() ? MAIN_API_PREFIX : config?.['links']?.main_api;
465
465
  });
466
466
  }
467
- 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 }); }
467
+ 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 }); }
468
468
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: MainApiHttpService, providedIn: 'root' }); }
469
469
  }
470
470
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: MainApiHttpService, decorators: [{
@@ -472,7 +472,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
472
472
  args: [{
473
473
  providedIn: 'root'
474
474
  }]
475
- }], ctorParameters: () => [{ type: i1$2.HttpClient }, { type: i0.Injector }] });
475
+ }], ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i0.Injector }] });
476
476
 
477
477
  /**
478
478
  * Secure Token Storage Service
@@ -803,6 +803,7 @@ class UserService {
803
803
  this.toast = toast;
804
804
  this.endpoint = USER_PATH;
805
805
  this.isTosModalOpen = false;
806
+ this.isSecondaryPaymentModalOpen = false;
806
807
  }
807
808
  getUserState() {
808
809
  return this.store.select(getUser);
@@ -814,8 +815,51 @@ class UserService {
814
815
  this.router.navigate(['settings/security']);
815
816
  }
816
817
  this.checkAndHandleTosAcceptance(data);
818
+ this.checkAndHandleSecondaryPayment(data);
817
819
  }));
818
820
  }
821
+ /**
822
+ * Hard-gate the user when their active product requires a Braintree
823
+ * (secondary) payment method and they don't have one registered yet.
824
+ * Pattern mirrors checkAndHandleTosAcceptance — a non-dismissable
825
+ * SweetAlert2 modal that takes the user to the update-payment route.
826
+ * See main-api ticket #922.
827
+ */
828
+ checkAndHandleSecondaryPayment(user) {
829
+ if (!user || this.isSecondaryPaymentModalOpen) {
830
+ return;
831
+ }
832
+ const status = user.payment_methods_status;
833
+ if (!status?.requires_secondary_payment) {
834
+ return;
835
+ }
836
+ const subId = status.failing_subscription_id;
837
+ const productId = status.failing_product_id;
838
+ if (!subId || !productId) {
839
+ return;
840
+ }
841
+ this.isSecondaryPaymentModalOpen = true;
842
+ swal.fire({
843
+ icon: 'warning',
844
+ title: 'Secondary payment method required',
845
+ html: 'Your subscription requires a backup payment method. Click <b>Add Now</b> to register a secondary card — you cannot continue using the app until this is set up.',
846
+ confirmButtonText: 'Add Now',
847
+ allowOutsideClick: false,
848
+ allowEscapeKey: false,
849
+ showCancelButton: false,
850
+ reverseButtons: false,
851
+ focusConfirm: true
852
+ }).then(() => {
853
+ this.isSecondaryPaymentModalOpen = false;
854
+ this.router.navigate([
855
+ '/account/subscriptions',
856
+ subId,
857
+ 'product',
858
+ productId,
859
+ 'update-payment'
860
+ ]);
861
+ });
862
+ }
819
863
  /**
820
864
  * Ensure the current user has accepted the latest Terms of Service for this domain.
821
865
  * If the domain has a newer TOS version than the user's accepted timestamp, a blocking
@@ -963,7 +1007,7 @@ class UserService {
963
1007
  refreshUserApiTokens() {
964
1008
  return this.api.get(`${this.endpoint}/refresh_user_api_tokens`);
965
1009
  }
966
- 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 }); }
1010
+ 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 }); }
967
1011
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: UserService, providedIn: 'root' }); }
968
1012
  }
969
1013
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: UserService, decorators: [{
@@ -971,7 +1015,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
971
1015
  args: [{
972
1016
  providedIn: 'root'
973
1017
  }]
974
- }], ctorParameters: () => [{ type: MainApiHttpService }, { type: i2.Store }, { type: i3.Router }, { type: i1.AppConfigService }, { type: ProfileService }, { type: CustomToastService }] });
1018
+ }], ctorParameters: () => [{ type: MainApiHttpService }, { type: i3$1.Store }, { type: i3.Router }, { type: i2.AppConfigService }, { type: ProfileService }, { type: CustomToastService }] });
975
1019
 
976
1020
  class AuthService {
977
1021
  constructor(localStorage, secureTokenStorage, router, http, userService, toastr, appConfigService, integrationsApi, document) {
@@ -1113,6 +1157,7 @@ class AuthService {
1113
1157
  }
1114
1158
  return this.http.delete('session', options).pipe(tap$1(() => {
1115
1159
  this.secureTokenStorage.clearTokens().subscribe();
1160
+ this.clearBrainChatStorage();
1116
1161
  // Reset Crisp session on logout so next visitor is anonymous again
1117
1162
  if (typeof window?.$crisp?.push === 'function') {
1118
1163
  window.$crisp.push(['do', 'session:reset']);
@@ -1123,6 +1168,25 @@ class AuthService {
1123
1168
  }
1124
1169
  }));
1125
1170
  }
1171
+ /**
1172
+ * Wipe every `pw-brain.*` localStorage key on logout so the next user
1173
+ * on a shared browser doesn't inherit the previous user's chat thread
1174
+ * (ticket #4167). Best-effort: private-browsing / quota throws are
1175
+ * swallowed so logout never breaks.
1176
+ */
1177
+ clearBrainChatStorage() {
1178
+ try {
1179
+ for (let i = localStorage.length - 1; i >= 0; i--) {
1180
+ const key = localStorage.key(i);
1181
+ if (key?.startsWith('pw-brain.')) {
1182
+ localStorage.removeItem(key);
1183
+ }
1184
+ }
1185
+ }
1186
+ catch {
1187
+ // ignored — best-effort cleanup
1188
+ }
1189
+ }
1126
1190
  /**
1127
1191
  * Clear all authentication tokens
1128
1192
  */
@@ -1330,12 +1394,12 @@ class AuthService {
1330
1394
  }
1331
1395
  });
1332
1396
  }
1333
- 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 }); }
1397
+ 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 }); }
1334
1398
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: AuthService }); }
1335
1399
  }
1336
1400
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: AuthService, decorators: [{
1337
1401
  type: Injectable
1338
- }], ctorParameters: () => [{ type: LocalStorage }, { type: SecureTokenStorageService }, { type: i3.Router }, { type: MainApiHttpService }, { type: UserService }, { type: CustomToastService }, { type: i1.AppConfigService }, { type: IntegrationsApiHttpService }, { type: Document, decorators: [{
1402
+ }], ctorParameters: () => [{ type: LocalStorage }, { type: SecureTokenStorageService }, { type: i3.Router }, { type: MainApiHttpService }, { type: UserService }, { type: CustomToastService }, { type: i2.AppConfigService }, { type: IntegrationsApiHttpService }, { type: Document, decorators: [{
1339
1403
  type: Inject,
1340
1404
  args: [DOCUMENT]
1341
1405
  }] }] });
@@ -1362,7 +1426,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
1362
1426
 
1363
1427
  class CommonServicesModule {
1364
1428
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: CommonServicesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
1365
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.6", ngImport: i0, type: CommonServicesModule, imports: [CommonModule, i1$3.EffectsRootModule, i2.StoreRootModule] }); }
1429
+ 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] }); }
1366
1430
  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)] }); }
1367
1431
  }
1368
1432
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: CommonServicesModule, decorators: [{
@@ -1402,7 +1466,7 @@ class SeoService {
1402
1466
  this.meta.updateTag({ name: 'twitter:description', content: description });
1403
1467
  this.meta.updateTag({ name: 'twitter:card', content: 'summary' });
1404
1468
  }
1405
- 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 }); }
1469
+ 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 }); }
1406
1470
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: SeoService, providedIn: 'root' }); }
1407
1471
  }
1408
1472
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: SeoService, decorators: [{
@@ -1410,7 +1474,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
1410
1474
  args: [{
1411
1475
  providedIn: 'root'
1412
1476
  }]
1413
- }], ctorParameters: () => [{ type: i1$4.Meta }, { type: i1$4.Title }] });
1477
+ }], ctorParameters: () => [{ type: i1$3.Meta }, { type: i1$3.Title }] });
1414
1478
 
1415
1479
  /**
1416
1480
  * Centralized feature flag evaluation service.
@@ -1868,7 +1932,7 @@ class AbTestService {
1868
1932
  ? this.injector.get(service)
1869
1933
  : this.injector.get(MainApiHttpService);
1870
1934
  }
1871
- 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 }); }
1935
+ 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 }); }
1872
1936
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: AbTestService, providedIn: 'root' }); }
1873
1937
  }
1874
1938
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: AbTestService, decorators: [{
@@ -1876,7 +1940,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
1876
1940
  args: [{
1877
1941
  providedIn: 'root'
1878
1942
  }]
1879
- }], ctorParameters: () => [{ type: i0.Injector }, { type: i1$2.HttpClient }] });
1943
+ }], ctorParameters: () => [{ type: i0.Injector }, { type: i1$1.HttpClient }] });
1880
1944
 
1881
1945
  class GeoService {
1882
1946
  constructor(api, cookieService) {
@@ -1980,8 +2044,8 @@ class SubscriptionService {
1980
2044
  toggleAdmin(id, data) {
1981
2045
  return this.api.put(`/subscriptions/${id}/toggle_admin`, data);
1982
2046
  }
1983
- updateSubscriptionAPIKey(id) {
1984
- return this.api.put(`/subscriptions/${id}/update_api_key`);
2047
+ updateSubscriptionAPIKey(id, productId) {
2048
+ return this.api.put(`/subscriptions/${id}/update_api_key`, { product_id: productId });
1985
2049
  }
1986
2050
  refreshApiTokens(id) {
1987
2051
  return this.api.get(`/subscriptions/${id}/refresh_api_tokens`);
@@ -1998,6 +2062,17 @@ class SubscriptionService {
1998
2062
  updateCardDetails(data, subscription_id) {
1999
2063
  return this.api.post(`/subscriptions/${subscription_id}/update_card`, data);
2000
2064
  }
2065
+ getPaymentMethods(subscriptionId) {
2066
+ return this.api.get(`/subscriptions/${subscriptionId}/payment_methods`);
2067
+ }
2068
+ getBraintreeClientToken(subscriptionId) {
2069
+ return this.api.get(`/subscriptions/${subscriptionId}/braintree_client_token`);
2070
+ }
2071
+ registerBraintreePaymentMethod(subscriptionId, paymentMethodNonce) {
2072
+ return this.api.post(`/subscriptions/${subscriptionId}/braintree_payment_method`, {
2073
+ payment_method_nonce: paymentMethodNonce
2074
+ });
2075
+ }
2001
2076
  getEnterpriseInsight(subscriptionId, starting_at, ending_at) {
2002
2077
  return this.api.getWithParams(`/subscriptions/${subscriptionId}/enterprise_analytics?type=summary`, { starting_at, ending_at });
2003
2078
  }
@@ -2242,7 +2317,7 @@ class AhoyService {
2242
2317
  this.toast.showToast(error);
2243
2318
  }
2244
2319
  }
2245
- 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 }); }
2320
+ 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 }); }
2246
2321
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: AhoyService, providedIn: 'root' }); }
2247
2322
  }
2248
2323
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: AhoyService, decorators: [{
@@ -2250,7 +2325,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
2250
2325
  args: [{
2251
2326
  providedIn: 'root'
2252
2327
  }]
2253
- }], ctorParameters: () => [{ type: i1$2.HttpClient }, { type: i0.Injector }] });
2328
+ }], ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i0.Injector }] });
2254
2329
 
2255
2330
  class CommonService {
2256
2331
  constructor(api) {
@@ -2903,7 +2978,7 @@ class McpJsonRpcService {
2903
2978
  return res.result;
2904
2979
  }));
2905
2980
  }
2906
- 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 }); }
2981
+ 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 }); }
2907
2982
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: McpJsonRpcService, providedIn: 'root' }); }
2908
2983
  }
2909
2984
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: McpJsonRpcService, decorators: [{
@@ -2911,7 +2986,99 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
2911
2986
  args: [{
2912
2987
  providedIn: 'root'
2913
2988
  }]
2914
- }], ctorParameters: () => [{ type: i1$2.HttpClient }, { type: i1.AppConfigService }, { type: i2.Store }] });
2989
+ }], ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i2.AppConfigService }, { type: i3$1.Store }] });
2990
+
2991
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2992
+ class MCPOrchestratorService {
2993
+ /**
2994
+ * Dev base — `BRAIN_API_PREFIX` = '/brain-api/v1/'. In prod the
2995
+ * orchestrator is reached via the API-gateway public hostname; we read
2996
+ * it from `links.brain_api` in app config (same convention as
2997
+ * `BrainApiHttpService`).
2998
+ */
2999
+ constructor(http, appConfigService, store) {
3000
+ this.http = http;
3001
+ this.appConfigService = appConfigService;
3002
+ this.store = store;
3003
+ }
3004
+ execute(body) {
3005
+ return this.post('mcp/execute', body);
3006
+ }
3007
+ interpret(body) {
3008
+ return this.post('mcp/interpret', body);
3009
+ }
3010
+ confirm(body) {
3011
+ return this.post('mcp/confirm', body);
3012
+ }
3013
+ post(path, body) {
3014
+ const base$ = isDevMode()
3015
+ ? of(BRAIN_API_PREFIX.replace(/\/$/, ''))
3016
+ : this.appConfigService.appConfig$.pipe(take(1), switchMap(c => {
3017
+ const url = c?.links?.['brain_api'];
3018
+ if (typeof url === 'string' && url.trim()) {
3019
+ return of(url.trim().replace(/\/$/, ''));
3020
+ }
3021
+ return throwError(() => new Error('Brain API is not configured: set links.brain_api in app configuration.'));
3022
+ }));
3023
+ return base$.pipe(switchMap(base => this.store.pipe(take(1), map((app) => this.pickApiCredentials(app.user?.currentUser ?? null)), switchMap(creds => {
3024
+ if (!creds) {
3025
+ 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.'));
3026
+ }
3027
+ return this.http.post(`${base}/${path}`, body, {
3028
+ headers: this.buildHeaders(creds)
3029
+ });
3030
+ }))));
3031
+ }
3032
+ /**
3033
+ * Pull `(token, userId, clientId?)` for the active session.
3034
+ *
3035
+ * `clientId` comes from `PermissionService.selectedSubscription` — the
3036
+ * canonical "currently-active subscription" on this frontend, set when
3037
+ * the user picks/lands on a subscription. Every other place in the
3038
+ * codebase that needs subscription context (mailbox, chatbox, search,
3039
+ * dashboard, admin lists) reads from the same static. Without it,
3040
+ * downstream MCP tools that require subscription scope (e.g.
3041
+ * `cloudolive-api.count_reconciled_account_inputs`) reject the call
3042
+ * with `McpError: This tool requires subscription context. Please
3043
+ * provide api_client_id parameter`.
3044
+ *
3045
+ * `api_client_id` does NOT live on the `User` interface — it's a
3046
+ * property of `Subscription` (`subscription.interface.ts`). Reading
3047
+ * from the user object would always return `undefined` and silently
3048
+ * drop the header.
3049
+ */
3050
+ pickApiCredentials(user) {
3051
+ if (!user) {
3052
+ return null;
3053
+ }
3054
+ const token = user.api_user_token ?? user.api_keys?.api_user_token;
3055
+ const userId = user.api_user_id ?? user.api_keys?.api_user_id;
3056
+ if (!token || !userId) {
3057
+ return null;
3058
+ }
3059
+ const clientId = PermissionService.selectedSubscription?.api_client_id;
3060
+ return { token, userId, clientId };
3061
+ }
3062
+ buildHeaders(creds) {
3063
+ let h = new HttpHeaders({
3064
+ 'Content-Type': 'application/json',
3065
+ 'X-API-USER-TOKEN': creds.token,
3066
+ 'X-API-USER-ID': creds.userId
3067
+ });
3068
+ if (creds.clientId) {
3069
+ h = h.set('X-API-CLIENT-ID', creds.clientId);
3070
+ }
3071
+ return h;
3072
+ }
3073
+ 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 }); }
3074
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: MCPOrchestratorService, providedIn: 'root' }); }
3075
+ }
3076
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: MCPOrchestratorService, decorators: [{
3077
+ type: Injectable,
3078
+ args: [{
3079
+ providedIn: 'root'
3080
+ }]
3081
+ }], ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i2.AppConfigService }, { type: i3$1.Store }] });
2915
3082
 
2916
3083
  class WebsocketService {
2917
3084
  constructor(appConfigService, authService) {
@@ -2924,7 +3091,7 @@ class WebsocketService {
2924
3091
  this.webSocket$ = this.webSocketSubject.asObservable().pipe(distinctUntilChanged());
2925
3092
  });
2926
3093
  }
2927
- 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 }); }
3094
+ 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 }); }
2928
3095
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: WebsocketService, providedIn: 'root' }); }
2929
3096
  }
2930
3097
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: WebsocketService, decorators: [{
@@ -2932,7 +3099,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
2932
3099
  args: [{
2933
3100
  providedIn: 'root'
2934
3101
  }]
2935
- }], ctorParameters: () => [{ type: i1.AppConfigService }, { type: AuthService }] });
3102
+ }], ctorParameters: () => [{ type: i2.AppConfigService }, { type: AuthService }] });
2936
3103
 
2937
3104
  class NotificationService {
2938
3105
  constructor(api, toastrService, socketService) {
@@ -3480,7 +3647,7 @@ class SentryErrorHandler {
3480
3647
  console.error(error, e);
3481
3648
  }
3482
3649
  }
3483
- 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 }); }
3650
+ 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 }); }
3484
3651
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: SentryErrorHandler, providedIn: 'root' }); }
3485
3652
  }
3486
3653
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: SentryErrorHandler, decorators: [{
@@ -3488,7 +3655,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
3488
3655
  args: [{
3489
3656
  providedIn: 'root'
3490
3657
  }]
3491
- }], ctorParameters: () => [{ type: i1.AppConfigService }] });
3658
+ }], ctorParameters: () => [{ type: i2.AppConfigService }] });
3492
3659
 
3493
3660
  class LogoCacheService {
3494
3661
  constructor() {
@@ -3604,7 +3771,7 @@ class BrainApiHttpService extends BaseHttpService {
3604
3771
  this.baseUrl = isDevMode() ? BRAIN_API_PREFIX : config?.['links']['brain_api'] ?? '';
3605
3772
  });
3606
3773
  }
3607
- 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 }); }
3774
+ 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 }); }
3608
3775
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: BrainApiHttpService, providedIn: 'root' }); }
3609
3776
  }
3610
3777
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: BrainApiHttpService, decorators: [{
@@ -3612,7 +3779,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
3612
3779
  args: [{
3613
3780
  providedIn: 'root'
3614
3781
  }]
3615
- }], ctorParameters: () => [{ type: i1$2.HttpClient }, { type: i0.Injector }] });
3782
+ }], ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i0.Injector }] });
3616
3783
 
3617
3784
  class BrainApiService {
3618
3785
  constructor(api) {
@@ -3639,5 +3806,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImpor
3639
3806
  * Generated bundle index. Do not edit.
3640
3807
  */
3641
3808
 
3642
- export { AbTestService, AhoyService, AuthService, BaseHttpService, BrainApiHttpService, BrainApiService, CommonService, CommonServicesModule, CustomPreloadingStrategy, CustomToastService, DashboardService, DataService, FeatureFlagService, FormHelperService, GeoService, GoogleAnalyticsService, GroupService, HopscotchService, IntegrationsApiHttpService, LinkService, LocalStorage, LogoCacheService, MailBoxService, MainApiHttpService, McpJsonRpcService, NgbDateCustomParserFormatter, NotificationService, NumberPickerService, PermissionService, PrimeNgHelper, ProductService, ProfileService, QualificationService, ScriptLoaderService, SecureTokenStorageService, SentryErrorHandler, SeoService, SubscriptionService, TagService, TipsService, UserEffects, UserService, ValidationService, WebsocketService, WindowService };
3809
+ 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 };
3643
3810
  //# sourceMappingURL=posiwise-common-services.mjs.map