@lenne.tech/ng-base 0.3.10 → 0.3.13

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 (28) hide show
  1. package/bundles/lenne.tech-ng-base-src-lib-base.umd.js +38 -27
  2. package/bundles/lenne.tech-ng-base-src-lib-base.umd.js.map +1 -1
  3. package/bundles/lenne.tech-ng-base.umd.js +38 -27
  4. package/bundles/lenne.tech-ng-base.umd.js.map +1 -1
  5. package/esm2015/lib/base/base.module.js +3 -2
  6. package/esm2015/lib/base/factories/apollo-options.factory.js +14 -24
  7. package/esm2015/lib/base/public-api.js +2 -1
  8. package/esm2015/lib/base/services/auth.service.js +9 -4
  9. package/esm2015/lib/base/services/ws.service.js +16 -0
  10. package/esm2015/src/lib/base/base.module.js +3 -2
  11. package/esm2015/src/lib/base/factories/apollo-options.factory.js +14 -24
  12. package/esm2015/src/lib/base/public-api.js +2 -1
  13. package/esm2015/src/lib/base/services/auth.service.js +9 -4
  14. package/esm2015/src/lib/base/services/ws.service.js +16 -0
  15. package/fesm2015/lenne.tech-ng-base-src-lib-base.js +35 -28
  16. package/fesm2015/lenne.tech-ng-base-src-lib-base.js.map +1 -1
  17. package/fesm2015/lenne.tech-ng-base.js +35 -28
  18. package/fesm2015/lenne.tech-ng-base.js.map +1 -1
  19. package/lib/base/factories/apollo-options.factory.d.ts +2 -1
  20. package/lib/base/public-api.d.ts +1 -0
  21. package/lib/base/services/auth.service.d.ts +3 -1
  22. package/lib/base/services/ws.service.d.ts +5 -0
  23. package/package.json +1 -1
  24. package/src/lib/base/factories/apollo-options.factory.d.ts +2 -1
  25. package/src/lib/base/lenne.tech-ng-base-src-lib-base.metadata.json +1 -1
  26. package/src/lib/base/public-api.d.ts +1 -0
  27. package/src/lib/base/services/auth.service.d.ts +3 -1
  28. package/src/lib/base/services/ws.service.d.ts +5 -0
@@ -488,6 +488,23 @@
488
488
  { type: undefined, decorators: [{ type: i0.Inject, args: [BASE_MODULE_CONFIG,] }] }
489
489
  ]; };
490
490
 
491
+ var WsService = /** @class */ (function () {
492
+ function WsService() {
493
+ }
494
+ WsService.prototype.reconnect = function () {
495
+ var _a, _b;
496
+ (_a = this.client) === null || _a === void 0 ? void 0 : _a.close();
497
+ (_b = this.client) === null || _b === void 0 ? void 0 : _b.connect();
498
+ };
499
+ return WsService;
500
+ }());
501
+ WsService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function WsService_Factory() { return new WsService(); }, token: WsService, providedIn: "root" });
502
+ WsService.decorators = [
503
+ { type: i0.Injectable, args: [{
504
+ providedIn: 'root',
505
+ },] }
506
+ ];
507
+
491
508
  /**
492
509
  * Authentication service
493
510
  */
@@ -495,9 +512,10 @@
495
512
  /**
496
513
  * Constructor
497
514
  */
498
- function AuthService(moduleConfig, storageService) {
515
+ function AuthService(moduleConfig, storageService, wsService) {
499
516
  this.moduleConfig = moduleConfig;
500
517
  this.storageService = storageService;
518
+ this.wsService = wsService;
501
519
  // Subjects
502
520
  this._currentUser = new rxjs.BehaviorSubject(null);
503
521
  this._token = new rxjs.BehaviorSubject(null);
@@ -543,6 +561,7 @@
543
561
  set: function (token) {
544
562
  this._token.next(token);
545
563
  this.storageService.save('token', token);
564
+ this.wsService.reconnect();
546
565
  },
547
566
  enumerable: false,
548
567
  configurable: true
@@ -556,7 +575,7 @@
556
575
  });
557
576
  return AuthService;
558
577
  }());
559
- AuthService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function AuthService_Factory() { return new AuthService(i0__namespace.ɵɵinject(BASE_MODULE_CONFIG), i0__namespace.ɵɵinject(StorageService)); }, token: AuthService, providedIn: "root" });
578
+ AuthService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function AuthService_Factory() { return new AuthService(i0__namespace.ɵɵinject(BASE_MODULE_CONFIG), i0__namespace.ɵɵinject(StorageService), i0__namespace.ɵɵinject(WsService)); }, token: AuthService, providedIn: "root" });
560
579
  AuthService.decorators = [
561
580
  { type: i0.Injectable, args: [{
562
581
  providedIn: 'root',
@@ -564,13 +583,14 @@
564
583
  ];
565
584
  AuthService.ctorParameters = function () { return [
566
585
  { type: undefined, decorators: [{ type: i0.Inject, args: [BASE_MODULE_CONFIG,] }] },
567
- { type: StorageService }
586
+ { type: StorageService },
587
+ { type: WsService }
568
588
  ]; };
569
589
 
570
590
  /**
571
591
  * Factory for apollo-angular options
572
592
  */
573
- function apolloOptionsFactory(baseModuleConfig, httpLink, authService) {
593
+ function apolloOptionsFactory(baseModuleConfig, httpLink, authService, wsService) {
574
594
  var links = [];
575
595
  var defaultUrl = 'api.' + window.location.href + '/graphql';
576
596
  var http = httpLink.create({
@@ -588,27 +608,17 @@
588
608
  return forward(operation);
589
609
  });
590
610
  if (baseModuleConfig.wsUrl) {
591
- var wsClient = void 0;
592
- if (localStorage) {
593
- var token = authService.token || null;
594
- wsClient = new ws.WebSocketLink({
595
- uri: baseModuleConfig.wsUrl,
596
- options: {
597
- reconnect: true,
598
- connectionParams: {
599
- Authorization: 'Bearer ' + token,
600
- },
601
- },
602
- });
603
- }
604
- else {
605
- wsClient = new ws.WebSocketLink({
606
- uri: baseModuleConfig.wsUrl,
607
- options: {
608
- reconnect: true,
609
- },
610
- });
611
- }
611
+ var wsLink = new ws.WebSocketLink({
612
+ uri: baseModuleConfig.wsUrl,
613
+ options: {
614
+ reconnect: true,
615
+ connectionParams: function () { return ({
616
+ Authorization: authService.token ? 'Bearer ' + authService.token : undefined,
617
+ }); },
618
+ },
619
+ });
620
+ // Set client for reconnection on logout/login
621
+ wsService.client = wsLink.subscriptionClient;
612
622
  // using the ability to split links, you can send data to each link
613
623
  // depending on what kind of operation is being sent
614
624
  links.push(core.split(
@@ -618,7 +628,7 @@
618
628
  // @ts-ignore
619
629
  var _b = utilities.getMainDefinition(query), kind = _b.kind, operation = _b.operation;
620
630
  return kind === 'OperationDefinition' && operation === 'subscription';
621
- }, wsClient, core.concat(authMiddleware, http)));
631
+ }, wsLink, core.concat(authMiddleware, http)));
622
632
  }
623
633
  else {
624
634
  links.push(http);
@@ -1562,7 +1572,7 @@
1562
1572
  providers.push({
1563
1573
  provide: i1$1.APOLLO_OPTIONS,
1564
1574
  useFactory: apolloOptionsFactory,
1565
- deps: [BASE_MODULE_CONFIG, http.HttpLink, AuthService],
1575
+ deps: [BASE_MODULE_CONFIG, http.HttpLink, AuthService, WsService],
1566
1576
  });
1567
1577
  }
1568
1578
  else if (config.logging) {
@@ -3133,6 +3143,7 @@
3133
3143
  exports.ScrollService = ScrollService;
3134
3144
  exports.Standard = Standard;
3135
3145
  exports.StorageService = StorageService;
3146
+ exports.WsService = WsService;
3136
3147
  exports.apolloOptionsFactory = apolloOptionsFactory;
3137
3148
 
3138
3149
  Object.defineProperty(exports, '__esModule', { value: true });