@sambath999/localize-token 12.1.2 → 12.1.4

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.
Files changed (35) hide show
  1. package/bundles/sambath999-localize-token.umd.js +1110 -1094
  2. package/bundles/sambath999-localize-token.umd.js.map +1 -1
  3. package/esm2015/localize-logindlg/localize-logindlg.component.js +343 -0
  4. package/esm2015/localize-logindlg/localize-logindlg.module.js +28 -0
  5. package/esm2015/localize-logindlg/localize-logindlg.service.js +37 -0
  6. package/esm2015/localize-logindlg/public-api.js +4 -0
  7. package/esm2015/localize-token/localize.api.service.js +152 -0
  8. package/esm2015/localize-token/localize.token.js +59 -0
  9. package/esm2015/localize-token/localize.token.module.js +14 -0
  10. package/esm2015/localize-token/localize.token.service.js +62 -0
  11. package/esm2015/localize-token/localize.token.storage.js +113 -0
  12. package/esm2015/localize-token/public-api.js +6 -0
  13. package/esm2015/public-api.js +3 -2
  14. package/fesm2015/sambath999-localize-token.js +420 -10
  15. package/fesm2015/sambath999-localize-token.js.map +1 -1
  16. package/localize-logindlg/localize-logindlg.component.d.ts +30 -0
  17. package/localize-logindlg/localize-logindlg.module.d.ts +2 -0
  18. package/localize-logindlg/localize-logindlg.service.d.ts +12 -0
  19. package/localize-logindlg/public-api.d.ts +3 -0
  20. package/{lib → localize-token}/localize.api.service.d.ts +4 -3
  21. package/localize-token/public-api.d.ts +5 -0
  22. package/package.json +11 -11
  23. package/public-api.d.ts +2 -1
  24. package/sambath999-localize-token.metadata.json +1 -1
  25. package/esm2015/lib/index.js +0 -6
  26. package/esm2015/lib/localize.api.service.js +0 -150
  27. package/esm2015/lib/localize.token.js +0 -59
  28. package/esm2015/lib/localize.token.module.js +0 -14
  29. package/esm2015/lib/localize.token.service.js +0 -62
  30. package/esm2015/lib/localize.token.storage.js +0 -101
  31. package/lib/index.d.ts +0 -5
  32. /package/{lib → localize-token}/localize.token.d.ts +0 -0
  33. /package/{lib → localize-token}/localize.token.module.d.ts +0 -0
  34. /package/{lib → localize-token}/localize.token.service.d.ts +0 -0
  35. /package/{lib → localize-token}/localize.token.storage.d.ts +0 -0
@@ -1,9 +1,18 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Injectable, NgModule } from '@angular/core';
2
+ import { Injectable, NgModule, Component, ViewEncapsulation, ChangeDetectorRef, Injector, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
3
3
  import { __awaiter } from 'tslib';
4
4
  import { BehaviorSubject } from 'rxjs';
5
5
  import * as jwt_decode from 'jwt-decode';
6
- import { HttpHeaders } from '@angular/common/http';
6
+ import * as i1 from '@angular/common/http';
7
+ import { HttpHeaders, HttpClient } from '@angular/common/http';
8
+ import { MessageService } from 'primeng/api';
9
+ import { DynamicDialogRef, DynamicDialogConfig, DialogService } from 'primeng/dynamicdialog';
10
+ import { CommonModule } from '@angular/common';
11
+ import { FormsModule } from '@angular/forms';
12
+ import { BrowserModule } from '@angular/platform-browser';
13
+ import { ToastModule } from 'primeng/toast';
14
+ import { ButtonModule } from 'primeng/button';
15
+ import { InputTextModule } from 'primeng/inputtext';
7
16
 
8
17
  /**
9
18
  * Assembly of @package ng2-cookies @see https://www.npmjs.com/package/ng2-cookies
@@ -63,7 +72,20 @@ class LocalizeTokenStorageHelper {
63
72
  }
64
73
  return cookies;
65
74
  }
66
- get defaultOptions() { return LocalizeToken.cookieOptions; }
75
+ get defaultOptions() {
76
+ const getMainDomain = (subdomain) => {
77
+ const parts = subdomain.split('.');
78
+ return parts.length > 2 ? parts.slice(-2).join('.') : subdomain;
79
+ };
80
+ const mainDomain = getMainDomain(window.location.hostname);
81
+ return {
82
+ path: '/',
83
+ domain: mainDomain,
84
+ secure: true,
85
+ // samesite: SameSiteType.strict,
86
+ expires: 1
87
+ };
88
+ }
67
89
  set(name, value, options) {
68
90
  options !== null && options !== void 0 ? options : (options = this.defaultOptions);
69
91
  const { expires, path, domain, secure, samesite } = options;
@@ -231,7 +253,8 @@ var EMethod;
231
253
  EMethod[EMethod["PATCH"] = 5] = "PATCH";
232
254
  })(EMethod || (EMethod = {}));
233
255
  class LocalizeApiService {
234
- constructor(localizeTokenService) {
256
+ constructor(httpClient, localizeTokenService) {
257
+ this.httpClient = httpClient;
235
258
  this.localizeTokenService = localizeTokenService;
236
259
  this.isRequestingSubject = new BehaviorSubject(false);
237
260
  this.isResolvedStartupSubject = new BehaviorSubject(false);
@@ -250,8 +273,7 @@ class LocalizeApiService {
250
273
  * Initialize the API service.
251
274
  * @param apiConfigs - The API configurations.
252
275
  */
253
- init(httpClient, apiConfigs) {
254
- this.httpClient = httpClient;
276
+ init(apiConfigs) {
255
277
  this.apiConfigs = apiConfigs;
256
278
  }
257
279
  base(baseUrl, path, method = EMethod.GET, value = null, isFormData = false, headers) {
@@ -295,7 +317,7 @@ class LocalizeApiService {
295
317
  processRequest(method, url, options) {
296
318
  return __awaiter(this, void 0, void 0, function* () {
297
319
  this.isRequestingSubject.next(true);
298
- const result = yield new Promise((resolve, reject) => { var _a; return (_a = this.httpClient) === null || _a === void 0 ? void 0 : _a.request(method, url, options).subscribe({ next: resolve, error: reject }); });
320
+ const result = yield new Promise((resolve, reject) => this.httpClient.request(method, url, options).subscribe({ next: resolve, error: reject }));
299
321
  this.isRequestingSubject.next(false);
300
322
  return result;
301
323
  });
@@ -310,7 +332,7 @@ class LocalizeApiService {
310
332
  this.localizeTokenService.isRevokingToken = true;
311
333
  const reqUrl = LocalizeToken.config.revokeTokenUrl;
312
334
  const reqHeaders = this.options().append(LocalizeToken.httpHeaders.X_REFRESH_TOKEN, `${this.localizeTokenService.refreshToken}`);
313
- const revokeToken = yield new Promise((resolve, reject) => { var _a; return (_a = this.httpClient) === null || _a === void 0 ? void 0 : _a.get(reqUrl, { headers: reqHeaders }).subscribe({ next: resolve, error: reject }); });
335
+ const revokeToken = yield new Promise((resolve, reject) => this.httpClient.get(reqUrl, { headers: reqHeaders }).subscribe({ next: resolve, error: reject }));
314
336
  if (revokeToken === null || revokeToken === void 0 ? void 0 : revokeToken.status) {
315
337
  this.localizeTokenService.accessToken = revokeToken.message;
316
338
  }
@@ -351,13 +373,14 @@ class LocalizeApiService {
351
373
  });
352
374
  }
353
375
  } //class
354
- LocalizeApiService.ɵprov = i0.ɵɵdefineInjectable({ factory: function LocalizeApiService_Factory() { return new LocalizeApiService(i0.ɵɵinject(LocalizeTokenService)); }, token: LocalizeApiService, providedIn: "root" });
376
+ LocalizeApiService.ɵprov = i0.ɵɵdefineInjectable({ factory: function LocalizeApiService_Factory() { return new LocalizeApiService(i0.ɵɵinject(i1.HttpClient), i0.ɵɵinject(LocalizeTokenService)); }, token: LocalizeApiService, providedIn: "root" });
355
377
  LocalizeApiService.decorators = [
356
378
  { type: Injectable, args: [{
357
379
  providedIn: 'root'
358
380
  },] }
359
381
  ];
360
382
  LocalizeApiService.ctorParameters = () => [
383
+ { type: HttpClient },
361
384
  { type: LocalizeTokenService }
362
385
  ];
363
386
 
@@ -372,9 +395,396 @@ LocalizeTokenModule.decorators = [
372
395
  },] }
373
396
  ];
374
397
 
398
+ class LocalizeLogindlgComponent {
399
+ constructor(messageService, cdt, dlgRef, dlgConfig, tokenService, httpClient) {
400
+ this.messageService = messageService;
401
+ this.cdt = cdt;
402
+ this.dlgRef = dlgRef;
403
+ this.dlgConfig = dlgConfig;
404
+ this.tokenService = tokenService;
405
+ this.httpClient = httpClient;
406
+ this.messageKey = "$login-dlg";
407
+ this.loading = false;
408
+ this.success = false;
409
+ this.clickLogout = () => { var _a; return (_a = this.logout) === null || _a === void 0 ? void 0 : _a.call(this); };
410
+ this.decodeToken = this.tokenService.decodeRefreshToken;
411
+ this.config = LocalizeToken.config;
412
+ this.loginConfig = this.dlgConfig.data.loginConfig;
413
+ }
414
+ ngOnInit() {
415
+ this.dlgConfig.closable = false;
416
+ this.logout = this.loginConfig.logoutFunc;
417
+ this.loginUrl = this.loginConfig.loginUrl;
418
+ if (!this.decodeToken) {
419
+ this.messageService.add({
420
+ key: this.messageKey,
421
+ severity: "error",
422
+ summary: "Token is invalid",
423
+ });
424
+ setTimeout(() => { var _a; return (_a = this.logout) === null || _a === void 0 ? void 0 : _a.call(this); }, 2000);
425
+ }
426
+ }
427
+ ngAfterViewInit() {
428
+ this.cdt.detectChanges();
429
+ }
430
+ clickLogin() {
431
+ return __awaiter(this, void 0, void 0, function* () {
432
+ if (!this.isValidPassword) {
433
+ this.messageService.add({
434
+ key: this.messageKey,
435
+ severity: "error",
436
+ summary: "Password is required and must be at least 6 characters",
437
+ });
438
+ }
439
+ this.loading = true;
440
+ const loginRes = yield this.login();
441
+ if (!(loginRes === null || loginRes === void 0 ? void 0 : loginRes.status)) {
442
+ this.messageService.add({
443
+ key: this.messageKey,
444
+ severity: "error",
445
+ summary: loginRes.message,
446
+ });
447
+ this.loading = false;
448
+ return;
449
+ }
450
+ this.tokenService.accessToken = loginRes.tokens.accessToken;
451
+ LocalizeToken.storage.set(this.config.refreshTokenName, loginRes.tokens.refreshToken);
452
+ this.success = true;
453
+ setTimeout(() => this.dlgRef.close(true), 2000);
454
+ });
455
+ }
456
+ login() {
457
+ var _a;
458
+ return __awaiter(this, void 0, void 0, function* () {
459
+ const path = (_a = this.loginUrl) !== null && _a !== void 0 ? _a : "/api/auth/login";
460
+ const response = yield new Promise((resolve, reject) => this.httpClient
461
+ .post(path, { password: this.password.trim() }, { headers: this.getHeaders() })
462
+ .subscribe({ next: resolve, error: reject }));
463
+ return response;
464
+ });
465
+ }
466
+ getHeaders() {
467
+ var _a, _b;
468
+ return {
469
+ [LocalizeToken.httpHeaders.X_REFRESH_TOKEN]: (_a = LocalizeToken.storage.get(this.config.refreshTokenName)) !== null && _a !== void 0 ? _a : "",
470
+ [LocalizeToken.httpHeaders.X_TENANT]: (_b = LocalizeToken.storage.get(this.config.tenantTokenName)) !== null && _b !== void 0 ? _b : "",
471
+ };
472
+ }
473
+ get isValidPassword() {
474
+ return this.password && this.password.trim().length >= 6;
475
+ }
476
+ }
477
+ LocalizeLogindlgComponent.decorators = [
478
+ { type: Component, args: [{
479
+ template: `<p-toast key="$login-dlg" position="top-center"></p-toast>
480
+ <div id="login-dlg-wrap">
481
+ <div id="login-dlg-header">
482
+ <div id="login-logo" class="p-mb-2"></div>
483
+ <h3 *ngIf="!success">Your session is expired! <br> Please login again to continue.</h3>
484
+ <h3 *ngIf="success" style="color:green !important;">You haved successfully logged in.</h3>
485
+ </div>
486
+ <div id="login-dlg-content">
487
+ <ng-container *ngIf="!success">
488
+ <div class="login-dlg-elm">
489
+ <div class="p-inputgroup">
490
+ <span class="p-inputgroup-addon">
491
+ <i class="material-icons-round">person</i>
492
+ </span>
493
+ <input disabled pInputText type="text" placeholder="Username" [value]="decodeToken?.email" />
494
+ </div>
495
+ </div>
496
+
497
+ <div class="login-dlg-elm">
498
+ <div class="p-inputgroup">
499
+ <span class="p-inputgroup-addon">
500
+ <i class="material-icons-round">lock</i>
501
+ </span>
502
+ <input (keydown.enter)="clickLogin()" pInputText type="password" placeholder="Password" [(ngModel)]="password"
503
+ autofocus />
504
+ </div>
505
+ </div>
506
+ <div class="login-dlg-elm">
507
+ <button style="width: 100%;" pButton type="button" label="Login" (click)="clickLogin()"
508
+ [disabled]="!password || loading"></button>
509
+ </div>
510
+
511
+ <div class="login-dlg-elm" style="display:flex;align-items: center;user-select: none;">
512
+ <span>No, I want to login with another user.</span>
513
+ <button class="p-button-text" pButton type="button" label="Logout" (click)="clickLogout()"></button>
514
+ </div>
515
+ </ng-container>
516
+
517
+ <ng-container *ngIf="success">
518
+ <div style="margin-top:35px;"></div>
519
+ <div class="check-animation-wrap">
520
+ <div class="check-main-container">
521
+ <div class="check-container">
522
+ <div class="check-background">
523
+ <svg viewBox="0 0 65 51" fill="none" xmlns="http://www.w3.org/2000/svg">
524
+ <path d="M7 25L27.3077 44L58.5 7" stroke="white" stroke-width="13" stroke-linecap="round"
525
+ stroke-linejoin="round"></path>
526
+ </svg>
527
+ </div>
528
+ </div>
529
+ </div>
530
+ </div>
531
+ </ng-container>
532
+ </div>
533
+ </div>`,
534
+ selector: "app-localize-logindlg",
535
+ providers: [MessageService],
536
+ encapsulation: ViewEncapsulation.None,
537
+ styles: [`#login-dlg-wrap {
538
+ width: 100%;
539
+ max-width: 400px;
540
+ margin: 0 auto;
541
+ padding: 30px;
542
+ }
543
+
544
+ .login-dlg-elm {
545
+ margin-top: 1rem;
546
+ }
547
+
548
+ #login-dlg-header {
549
+ display: flex;
550
+ flex-direction: column;
551
+ align-items: center;
552
+ justify-content: center;
553
+ }
554
+
555
+ #login-dlg-header h3 {
556
+ font-weight: bold;
557
+ font-size: 0.9rem;
558
+ color: orange;
559
+ text-align: center;
560
+ }
561
+
562
+ #login-logo {
563
+ height: 40px;
564
+ width: 40px;
565
+ background: url("/assets/images/logo-300px.png") no-repeat;
566
+ background-size: contain;
567
+ }
568
+
569
+ #login-dlg-content .p-inputgroup {
570
+ height: 45px;
571
+ }
572
+
573
+ #login-dlg-content .p-inputgroup .p-inputgroup-addon {
574
+ height: 45px;
575
+ border-radius: 15px 0 0 15px;
576
+ width: 50px;
577
+ }
578
+
579
+ #login-dlg-content .p-inputgroup .p-inputgroup-addon * {
580
+ font-size: 1rem;
581
+ }
582
+
583
+ #login-dlg-content .p-inputgroup input {
584
+ height: 45px;
585
+ border-radius: 0 15px 15px 0;
586
+ }
587
+
588
+ #login-dlg-content button {
589
+ height: 45px;
590
+ border-radius: 15px;
591
+ }
592
+
593
+ /*check animation block*/
594
+
595
+ .check-animation-wrap {
596
+ top: 0;
597
+ left: 0;
598
+ position: absolute;
599
+ display: flex;
600
+ flex-direction: column;
601
+ align-items: center;
602
+ justify-content: center;
603
+ width: 100%;
604
+ height: calc(100% - 200px);
605
+ min-height: 400px;
606
+ }
607
+
608
+ .check-main-container {
609
+ width: 100%;
610
+ height: 100vh;
611
+ display: flex;
612
+ flex-flow: column;
613
+ justify-content: center;
614
+ align-items: center;
615
+ }
616
+
617
+ .check-container {
618
+ width: 6.25rem;
619
+ height: 7.5rem;
620
+ display: flex;
621
+ flex-flow: column;
622
+ align-items: center;
623
+ justify-content: space-between;
624
+ }
625
+
626
+ .check-container .check-background {
627
+ width: 100%;
628
+ height: calc(100% - 1.25rem);
629
+ background: linear-gradient(to bottom right, #5de593, #41d67c);
630
+ box-shadow: 0px 0px 0px 65px rgba(255, 255, 255, 0.25) inset, 0px 0px 0px 65px rgba(255, 255, 255, 0.25) inset;
631
+ transform: scale(0.84);
632
+ border-radius: 50%;
633
+ animation: animateContainer 0.75s ease-out forwards 0.75s;
634
+ display: flex;
635
+ align-items: center;
636
+ justify-content: center;
637
+ opacity: 0;
638
+ }
639
+
640
+ .check-container .check-background svg {
641
+ width: 65%;
642
+ transform: translateY(0.25rem);
643
+ stroke-dasharray: 80;
644
+ stroke-dashoffset: 80;
645
+ animation: animateCheck 0.35s forwards 1.25s ease-out;
646
+ min-width: auto !important;
647
+ }
648
+
649
+ .check-container .check-shadow {
650
+ bottom: calc(-15% - 5px);
651
+ left: 0;
652
+ border-radius: 50%;
653
+ background: radial-gradient(closest-side, rgba(73, 218, 131, 1), transparent);
654
+ animation: animateShadow 0.75s ease-out forwards 0.75s;
655
+ }
656
+
657
+ @keyframes animateContainer {
658
+ 0% {
659
+ opacity: 0;
660
+ transform: scale(0);
661
+ box-shadow: 0px 0px 0px 65px rgba(255, 255, 255, 0.25) inset, 0px 0px 0px 65px rgba(255, 255, 255, 0.25) inset;
662
+ }
663
+
664
+ 25% {
665
+ opacity: 1;
666
+ transform: scale(0.9);
667
+ box-shadow: 0px 0px 0px 65px rgba(255, 255, 255, 0.25) inset, 0px 0px 0px 65px rgba(255, 255, 255, 0.25) inset;
668
+ }
669
+
670
+ 43.75% {
671
+ transform: scale(1.15);
672
+ box-shadow: 0px 0px 0px 43.334px rgba(255, 255, 255, 0.25) inset, 0px 0px 0px 65px rgba(255, 255, 255, 0.25) inset;
673
+ }
674
+
675
+ 62.5% {
676
+ transform: scale(1);
677
+ box-shadow: 0px 0px 0px 0px rgba(255, 255, 255, 0.25) inset, 0px 0px 0px 21.667px rgba(255, 255, 255, 0.25) inset;
678
+ }
679
+
680
+ 81.25% {
681
+ box-shadow: 0px 0px 0px 0px rgba(255, 255, 255, 0.25) inset, 0px 0px 0px 0px rgba(255, 255, 255, 0.25) inset;
682
+ }
683
+
684
+ 100% {
685
+ opacity: 1;
686
+ box-shadow: 0px 0px 0px 0px rgba(255, 255, 255, 0.25) inset, 0px 0px 0px 0px rgba(255, 255, 255, 0.25) inset;
687
+ }
688
+ }
689
+
690
+ @keyframes animateCheck {
691
+ from {
692
+ stroke-dashoffset: 80;
693
+ }
694
+
695
+ to {
696
+ stroke-dashoffset: 0;
697
+ }
698
+ }
699
+
700
+ @keyframes animateShadow {
701
+ 0% {
702
+ opacity: 0;
703
+ width: 100%;
704
+ height: 15%;
705
+ }
706
+
707
+ 25% {
708
+ opacity: 0.25;
709
+ }
710
+
711
+ 43.75% {
712
+ width: 40%;
713
+ height: 7%;
714
+ opacity: 0.35;
715
+ }
716
+
717
+ 100% {
718
+ width: 85%;
719
+ height: 15%;
720
+ opacity: 0.25;
721
+ }
722
+ }`]
723
+ },] }
724
+ ];
725
+ LocalizeLogindlgComponent.ctorParameters = () => [
726
+ { type: MessageService },
727
+ { type: ChangeDetectorRef },
728
+ { type: DynamicDialogRef },
729
+ { type: DynamicDialogConfig },
730
+ { type: LocalizeTokenService },
731
+ { type: HttpClient }
732
+ ];
733
+
734
+ class LocalizeLogindlgService {
735
+ constructor(injector) {
736
+ this.injector = injector;
737
+ }
738
+ openLoginDialog(loginConfig, config) {
739
+ return __awaiter(this, void 0, void 0, function* () {
740
+ config !== null && config !== void 0 ? config : (config = {
741
+ header: 'Login',
742
+ height: '650px',
743
+ style: { 'max-width': '400px', width: '100%', 'height': '650px' },
744
+ });
745
+ config.data = Object.assign(Object.assign({}, config.data || {}), { loginConfig });
746
+ const dialogService = this.injector.get(DialogService);
747
+ const dialog = dialogService.open(LocalizeLogindlgComponent, config);
748
+ yield new Promise((resolve) => dialog.onClose.subscribe(res => {
749
+ if (res) {
750
+ resolve();
751
+ }
752
+ }));
753
+ });
754
+ }
755
+ }
756
+ LocalizeLogindlgService.ɵprov = i0.ɵɵdefineInjectable({ factory: function LocalizeLogindlgService_Factory() { return new LocalizeLogindlgService(i0.ɵɵinject(i0.INJECTOR)); }, token: LocalizeLogindlgService, providedIn: "root" });
757
+ LocalizeLogindlgService.decorators = [
758
+ { type: Injectable, args: [{
759
+ providedIn: 'root'
760
+ },] }
761
+ ];
762
+ LocalizeLogindlgService.ctorParameters = () => [
763
+ { type: Injector }
764
+ ];
765
+
766
+ class LocalizeLogindlgModule {
767
+ }
768
+ LocalizeLogindlgModule.decorators = [
769
+ { type: NgModule, args: [{
770
+ declarations: [LocalizeLogindlgComponent],
771
+ exports: [LocalizeLogindlgComponent],
772
+ imports: [
773
+ CommonModule,
774
+ ToastModule,
775
+ InputTextModule,
776
+ BrowserModule,
777
+ FormsModule,
778
+ ButtonModule,
779
+ ],
780
+ providers: [LocalizeLogindlgService],
781
+ schemas: [CUSTOM_ELEMENTS_SCHEMA],
782
+ },] }
783
+ ];
784
+
375
785
  /**
376
786
  * Generated bundle index. Do not edit.
377
787
  */
378
788
 
379
- export { EMethod, ISameSiteType, LocalizeApiService, LocalizeToken, LocalizeTokenModule, LocalizeTokenService, LocalizeTokenStorageHelper, waitFor, waitUntil };
789
+ export { EMethod, ISameSiteType, LocalizeApiService, LocalizeLogindlgComponent, LocalizeLogindlgModule, LocalizeLogindlgService, LocalizeToken, LocalizeTokenModule, LocalizeTokenService, LocalizeTokenStorageHelper, waitFor, waitUntil };
380
790
  //# sourceMappingURL=sambath999-localize-token.js.map