monkey-front-core 0.0.477 → 0.0.479

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.
@@ -3,7 +3,7 @@ import { Component, Input, NgModule, Pipe, ViewEncapsulation, Injectable, EventE
3
3
  import * as i1 from 'monkey-style-guide';
4
4
  import { MonkeyButtonModule, MonkeyModalModule, MonkeyIconModule, MonkeyInputModule, MonkeyRadioButtonModule, MonkeyOptionModule, MonkeyUtils, MonkeyStyleGuideModule, MonkeyStyleGuideModalService, MonkeyStyleGuideSettingsService, MonkeyStyleGuideSnackbarService } from 'monkey-style-guide';
5
5
  import * as i2 from '@angular/common';
6
- import { CommonModule, formatNumber, CurrencyPipe } from '@angular/common';
6
+ import { CommonModule, formatNumber, CurrencyPipe, registerLocaleData } from '@angular/common';
7
7
  import * as i1$1 from '@ngx-translate/core';
8
8
  import { TranslateModule, TranslateService } from '@ngx-translate/core';
9
9
  import * as moment_ from 'moment';
@@ -23,6 +23,9 @@ import * as i2$3 from '@ngrx/store';
23
23
  import { createAction, props, INIT, createReducer, on, createFeatureSelector, createSelector, Store, StoreModule } from '@ngrx/store';
24
24
  import { createEntityAdapter } from '@ngrx/entity';
25
25
  import { __decorate } from 'tslib';
26
+ import esCL from '@angular/common/locales/es-CL';
27
+ import esMX from '@angular/common/locales/es-MX';
28
+ import ptBr from '@angular/common/locales/pt';
26
29
  import { datadogRum } from '@datadog/browser-rum';
27
30
  import * as i1$5 from '@angular/service-worker';
28
31
  import { ServiceWorkerModule } from '@angular/service-worker';
@@ -3449,90 +3452,108 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImpor
3449
3452
  }]
3450
3453
  }], ctorParameters: function () { return []; } });
3451
3454
 
3455
+ /* eslint-disable no-console */
3452
3456
  class MonkeyEcxi18nConfigService extends MonkeyEcxCommonsService {
3453
- constructor(monkeyecxService, translateService, monkeyecxCookieStorageService, monkeyecxErrorConfigService) {
3454
- super(monkeyecxService);
3457
+ constructor(monkeyecxService, tokenStorage, translateService, monkeyecxErrorConfigService) {
3458
+ super(monkeyecxService, tokenStorage);
3455
3459
  this.translateService = translateService;
3456
- this.monkeyecxCookieStorageService = monkeyecxCookieStorageService;
3457
3460
  this.monkeyecxErrorConfigService = monkeyecxErrorConfigService;
3458
- this.translateService.addLangs(['pt-BR', 'en-US']);
3459
- this.translateService.setDefaultLang('pt-BR');
3460
- this.translateService.use('pt-BR');
3461
- }
3462
- apply(params, environment, change = false) {
3463
- this.applyInternal(environment, params, change);
3464
- this.applyExternal(params, environment, change);
3465
- }
3466
- async applyInternal(environment, params = {}, change = false) {
3467
- const { monkeyecxService, monkeyecxErrorConfigService, monkeyecxCookieStorageService } = this;
3468
- let lang = '';
3469
- let i18n = { lang: '' };
3461
+ }
3462
+ async loadAuth(environment, lang) {
3470
3463
  try {
3471
- if (!change) {
3472
- const cookie = monkeyecxCookieStorageService.getCookie('monkey-app-locale');
3473
- if (cookie) {
3474
- i18n = JSON.parse(atob(cookie));
3475
- }
3476
- }
3477
- else {
3478
- i18n = {
3479
- lang: params?.i18n?.lang
3480
- };
3481
- }
3464
+ const url = MonkeyEcxUtils.replaceVariables(environment.urli18nAssets, {
3465
+ name: 'auth',
3466
+ lang
3467
+ });
3468
+ const resp = await this.monkeyecxService?.get(url).pipe(take(1)).toPromise();
3469
+ this.translateService.setTranslation(lang, resp.data, true);
3482
3470
  }
3483
3471
  catch (e) {
3484
- // not to do
3472
+ console.error(`loadAuth i18n ${lang} not found!`);
3473
+ this.monkeyecxErrorConfigService.apply('i18n');
3485
3474
  }
3486
- lang = i18n?.lang || `${environment?.lang || 'pt-BR'}`;
3475
+ }
3476
+ async loadAlerts(environment, lang) {
3487
3477
  try {
3488
- const currenti18n = await monkeyecxService
3489
- ?.get(`${environment.localAssets}/i18n/${lang}.json`)
3490
- .pipe(take(1))
3491
- .toPromise();
3492
- const { data } = currenti18n;
3493
- this.translateService.setTranslation('pt-BR', data, true);
3494
- this.translateService.setTranslation(lang, data, true);
3495
- this.translateService.use(lang);
3478
+ const url = MonkeyEcxUtils.replaceVariables(environment.urli18nAssets, {
3479
+ name: 'alerts',
3480
+ lang
3481
+ });
3482
+ const resp = await this.monkeyecxService?.get(url).pipe(take(1)).toPromise();
3483
+ this.translateService.setTranslation(lang, resp.data, true);
3496
3484
  }
3497
- catch (err) {
3498
- console.error(`i18n ${lang} not found!`);
3499
- monkeyecxErrorConfigService.apply('i18n');
3500
- throwError(err);
3485
+ catch (e) {
3486
+ console.error(`loadAlerts i18n ${lang} not found!`);
3487
+ this.monkeyecxErrorConfigService.apply('i18n');
3501
3488
  }
3489
+ }
3490
+ async loadShared(environment, lang) {
3502
3491
  try {
3503
- const pathName = ['alerts', 'auth', 'register', 'shared'];
3504
- const services = pathName?.map((name) => {
3505
- const url = MonkeyEcxUtils.replaceVariables(environment.urli18nAssets, {
3506
- name, lang
3507
- });
3508
- return monkeyecxService
3509
- ?.get(url)
3510
- .pipe(take(1))
3511
- .toPromise();
3492
+ const url = MonkeyEcxUtils.replaceVariables(environment.urli18nAssets, {
3493
+ name: 'shared',
3494
+ lang
3512
3495
  });
3513
- const externali18nData = await Promise.all(services);
3514
- externali18nData?.forEach((config) => {
3515
- const { data } = config;
3516
- this.translateService.setTranslation('pt-BR', data, true);
3517
- this.translateService.setTranslation(lang, data, true);
3496
+ const resp = await this.monkeyecxService?.get(url).pipe(take(1)).toPromise();
3497
+ this.translateService.setTranslation(lang, resp.data, true);
3498
+ }
3499
+ catch (e) {
3500
+ console.error(`loadShared i18n ${lang} not found!`);
3501
+ this.monkeyecxErrorConfigService.apply('i18n');
3502
+ }
3503
+ }
3504
+ async loadRegister(environment, lang) {
3505
+ try {
3506
+ const url = MonkeyEcxUtils.replaceVariables(environment.urli18nAssets, {
3507
+ name: 'register',
3508
+ lang
3518
3509
  });
3510
+ const resp = await this.monkeyecxService?.get(url).pipe(take(1)).toPromise();
3511
+ this.translateService.setTranslation(lang, resp.data, true);
3519
3512
  }
3520
- catch (err) {
3521
- // not to do
3513
+ catch (e) {
3514
+ console.error(`loadRegister i18n ${lang} not found!`);
3515
+ this.monkeyecxErrorConfigService.apply('i18n');
3516
+ }
3517
+ }
3518
+ async loadInternal(environment, lang) {
3519
+ try {
3520
+ const url = `${environment.localAssets}/i18n/${lang}.json`;
3521
+ const resp = await this.monkeyecxService?.get(url).pipe(take(1)).toPromise();
3522
+ this.translateService.setTranslation(lang, resp.data, true);
3523
+ }
3524
+ catch (e) {
3525
+ console.error(`loadInternal i18n ${lang} not found!`);
3526
+ this.monkeyecxErrorConfigService.apply('i18n');
3522
3527
  }
3523
3528
  }
3524
- async applyExternal(params, environment, change = false) {
3525
- const { monkeyecxCookieStorageService, monkeyecxErrorConfigService, monkeyecxService } = this;
3526
- let { i18n } = params;
3527
- const cookie = monkeyecxCookieStorageService.getCookie('monkey-app-locale');
3528
- if (cookie && !change) {
3529
- i18n = JSON.parse(atob(cookie));
3529
+ async apply(environment) {
3530
+ let lang = environment?.locale?.lang || 'pt-BR';
3531
+ try {
3532
+ const me = await this.tokenStorage?.getMe();
3533
+ lang = me?.locale || lang;
3534
+ }
3535
+ catch (e) {
3536
+ // not to do
3537
+ }
3538
+ if (lang === 'es-CL') {
3539
+ registerLocaleData(esCL);
3540
+ }
3541
+ else if (lang === 'es-MX') {
3542
+ registerLocaleData(esMX);
3530
3543
  }
3531
3544
  else {
3532
- monkeyecxCookieStorageService.setCookie('monkey-app-locale', btoa(JSON.stringify(i18n)), environment);
3545
+ registerLocaleData(ptBr);
3533
3546
  }
3547
+ await this.loadAuth(environment, lang);
3548
+ await this.loadInternal(environment, lang);
3549
+ this.loadAlerts(environment, lang);
3550
+ this.loadShared(environment, lang);
3551
+ this.loadRegister(environment, lang);
3552
+ this.translateService.setDefaultLang(lang);
3553
+ this.translateService.use(lang);
3554
+ }
3555
+ applyExternal(params, lang) {
3534
3556
  try {
3535
- const lang = `${i18n?.lang || 'pt-BR'}`;
3536
3557
  const currentExternali18n = params?.externali18n?.[`${lang}`];
3537
3558
  let data = {};
3538
3559
  if (currentExternali18n) {
@@ -3540,53 +3561,22 @@ class MonkeyEcxi18nConfigService extends MonkeyEcxCommonsService {
3540
3561
  EXTERNAL: currentExternali18n
3541
3562
  };
3542
3563
  }
3543
- this.translateService.setTranslation('pt-BR', data, true);
3544
- this.translateService.setTranslation(`${lang}`, data, true);
3545
- this.translateService.use(`${lang}`);
3546
- }
3547
- catch (err) {
3548
- console.error(`i18n ${i18n?.lang} not found!`);
3549
- monkeyecxErrorConfigService.apply('i18n');
3550
- throwError(err);
3551
- }
3552
- try {
3553
- const externali18nPaths = params?.i18n?.paths || [];
3554
- const services = externali18nPaths?.map((url) => {
3555
- return monkeyecxService?.get(`${url}/${i18n?.lang}.json`).pipe(take(1)).toPromise();
3556
- });
3557
- if (!services?.length)
3558
- return;
3559
- const externali18nData = await Promise.all(services);
3560
- externali18nData?.forEach((config) => {
3561
- const { lang } = config;
3562
- const { data } = config;
3563
- this.translateService.setTranslation('pt-BR', data, true);
3564
- this.translateService.setTranslation(lang, data, true);
3565
- });
3564
+ this.translateService.setTranslation(lang, data, true);
3566
3565
  }
3567
- catch (err) {
3568
- // not to do
3566
+ catch (e) {
3567
+ console.error(`loadExternal i18n ${lang} not found!`);
3568
+ this.monkeyecxErrorConfigService.apply('i18n');
3569
3569
  }
3570
3570
  }
3571
3571
  }
3572
- MonkeyEcxi18nConfigService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxi18nConfigService, deps: [{ token: MonkeyEcxService }, { token: i1$1.TranslateService }, { token: MonkeyEcxCookieStorageService }, { token: MonkeyEcxErrorConfigService }], target: i0.ɵɵFactoryTarget.Injectable });
3572
+ MonkeyEcxi18nConfigService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxi18nConfigService, deps: [{ token: MonkeyEcxService }, { token: MonkeyEcxTokenStorageService }, { token: i1$1.TranslateService }, { token: MonkeyEcxErrorConfigService }], target: i0.ɵɵFactoryTarget.Injectable });
3573
3573
  MonkeyEcxi18nConfigService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxi18nConfigService, providedIn: 'root' });
3574
- __decorate([
3575
- MonkeyEcxCoreService({
3576
- httpResponse: {
3577
- httpCodeIgnore: [404]
3578
- },
3579
- requestInProgress: {
3580
- showProgress: false
3581
- }
3582
- })
3583
- ], MonkeyEcxi18nConfigService.prototype, "applyInternal", null);
3584
3574
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxi18nConfigService, decorators: [{
3585
3575
  type: Injectable,
3586
3576
  args: [{
3587
3577
  providedIn: 'root'
3588
3578
  }]
3589
- }], ctorParameters: function () { return [{ type: MonkeyEcxService }, { type: i1$1.TranslateService }, { type: MonkeyEcxCookieStorageService }, { type: MonkeyEcxErrorConfigService }]; }, propDecorators: { applyInternal: [] } });
3579
+ }], ctorParameters: function () { return [{ type: MonkeyEcxService }, { type: MonkeyEcxTokenStorageService }, { type: i1$1.TranslateService }, { type: MonkeyEcxErrorConfigService }]; } });
3590
3580
 
3591
3581
  class MonkeyEcxLogsConfigService {
3592
3582
  apply(params, configBootstrap, environment, identifyCode) {
@@ -3913,19 +3903,18 @@ class MonkeyEcxConfigService extends MonkeyEcxCommonsService {
3913
3903
  this.configBootstrapSubject$ = new BehaviorSubject({});
3914
3904
  }
3915
3905
  async getSettings(monkeyecxCode, configBootstrap, callback, environment, identifyCode) {
3916
- const { monkeyecxSecurityConsoleConfigService, monkeyecxServiceWorkerConfigService, monkeyecxMaintenanceConfigService, monkeyStyleGuideSettingsService, monkeyecxi18nConfigService, monkeyGTMConfigService, getWhiteLabel } = this;
3906
+ const { monkeyecxSecurityConsoleConfigService, monkeyecxServiceWorkerConfigService, monkeyecxMaintenanceConfigService, monkeyStyleGuideSettingsService, monkeyGTMConfigService, getWhiteLabel } = this;
3917
3907
  monkeyecxServiceWorkerConfigService.apply(configBootstrap);
3918
3908
  monkeyecxMaintenanceConfigService.apply(configBootstrap);
3919
3909
  monkeyecxSecurityConsoleConfigService.apply();
3920
3910
  monkeyGTMConfigService.apply(environment);
3921
- await monkeyecxi18nConfigService.applyInternal(environment);
3922
3911
  const url = `${environment.urlAssets}/${monkeyecxCode.toLowerCase()}`;
3923
3912
  monkeyStyleGuideSettingsService.bootstrap(`${url}/monkey-style-guide-settings.json`, getWhiteLabel.bind(this, configBootstrap, callback, environment, identifyCode, url));
3924
3913
  }
3925
3914
  getWhiteLabel(configBootstrap, callback, environment, identifyCode, url) {
3926
3915
  const { monkeyecxService, configSubject$, monkeyecxLogsConfigService, monkeyecxErrorConfigService, monkeyEcxFeatureToggleService, monkeyecxi18nConfigService, monkeyEcxAlertsConfigService } = this;
3927
3916
  monkeyecxService?.get(`${url}/white-label.json`)?.subscribe(async (config) => {
3928
- await monkeyecxi18nConfigService.applyExternal(config, environment);
3917
+ monkeyecxi18nConfigService.applyExternal(config, environment);
3929
3918
  monkeyecxLogsConfigService.apply(config, configBootstrap, environment, identifyCode);
3930
3919
  monkeyEcxFeatureToggleService.apply(configSubject$, environment);
3931
3920
  monkeyEcxAlertsConfigService.apply(config);
@@ -3939,7 +3928,8 @@ class MonkeyEcxConfigService extends MonkeyEcxCommonsService {
3939
3928
  });
3940
3929
  }
3941
3930
  init(callback, environment, identifyCode, monkeyecxCode) {
3942
- const { monkeyecxService, configBootstrapSubject$, monkeyecxErrorConfigService } = this;
3931
+ const { monkeyecxService, configBootstrapSubject$, monkeyecxErrorConfigService, monkeyecxi18nConfigService } = this;
3932
+ monkeyecxi18nConfigService.apply(environment);
3943
3933
  monkeyecxService
3944
3934
  ?.get(`${environment.bootstrapAssets}`, {
3945
3935
  observe: 'response'