@ts-core/oauth 3.0.21 → 3.0.23

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.
@@ -7,9 +7,9 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
7
7
  popUpWidth: number;
8
8
  popUpHeight: number;
9
9
  popUpTarget: string;
10
- popUpIsCheckClose: boolean;
11
10
  popUpMessageParser: IOAuthPopUpParser;
12
11
  redirectUri: string;
12
+ isRejectWhenPopUpClosed: boolean;
13
13
  protected http: TransportHttp;
14
14
  protected subject: Subject<ObservableData<OAuthEvent, Window>>;
15
15
  protected popUp: Window;
@@ -35,6 +35,7 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
35
35
  getToken(): Promise<IOAuthDto>;
36
36
  close(): void;
37
37
  destroy(): void;
38
+ protected get isPopUpOpened(): boolean;
38
39
  protected get popUpCheckCloseTimer(): any;
39
40
  protected set popUpCheckCloseTimer(value: any);
40
41
  get urlParams(): Map<string, string>;
package/cjs/OAuthBase.js CHANGED
@@ -19,7 +19,7 @@ class OAuthBase extends common_1.LoggerWrapper {
19
19
  this.applicationId = applicationId;
20
20
  this.window = window;
21
21
  this.popUpCheckClose = () => {
22
- if (_.isNil(this.popUp) || this.popUp.closed) {
22
+ if (!this.isPopUpOpened) {
23
23
  this.close();
24
24
  }
25
25
  };
@@ -32,8 +32,8 @@ class OAuthBase extends common_1.LoggerWrapper {
32
32
  this.popUpWidth = 430;
33
33
  this.popUpHeight = 520;
34
34
  this.popUpTarget = '_blank';
35
- this.popUpIsCheckClose = true;
36
35
  this.popUpMessageParser = this.browserInternalMessageHandler;
36
+ this.isRejectWhenPopUpClosed = true;
37
37
  this._urlParams = new Map();
38
38
  this.urlParams.set('state', common_1.RandomUtil.randomString());
39
39
  this.urlParams.set('display', 'popup');
@@ -41,19 +41,15 @@ class OAuthBase extends common_1.LoggerWrapper {
41
41
  open() {
42
42
  return __awaiter(this, void 0, void 0, function* () {
43
43
  if (!_.isNil(this.promise)) {
44
- if (!_.isNil(this.popUp) && !this.popUp.closed) {
45
- this.popUp.focus();
46
- }
44
+ this.popUpFocus();
47
45
  return this.promise.promise;
48
46
  }
49
47
  this.promise = common_1.PromiseHandler.create();
50
48
  this.popUp = this.popUpOpen();
51
- this.subject.next(new common_1.ObservableData(OAuthEvent.POPUP_OPENED, this.popUp));
52
49
  this.popUpFocus();
53
- if (this.popUpIsCheckClose) {
54
- this.popUpCheckCloseTimer = setInterval(this.popUpCheckClose, common_1.DateUtil.MILLISECONDS_SECOND / 10);
55
- }
56
50
  this.window.addEventListener('message', this.messageHandler, false);
51
+ this.subject.next(new common_1.ObservableData(OAuthEvent.POPUP_OPENED, this.popUp));
52
+ this.popUpCheckCloseTimer = setInterval(this.popUpCheckClose, common_1.DateUtil.MILLISECONDS_SECOND / 5);
57
53
  return this.promise.promise;
58
54
  });
59
55
  }
@@ -65,7 +61,7 @@ class OAuthBase extends common_1.LoggerWrapper {
65
61
  return item;
66
62
  }
67
63
  popUpFocus() {
68
- if (!_.isNil(this.popUp) && !this.popUp.closed) {
64
+ if (this.isPopUpOpened) {
69
65
  this.popUp.focus();
70
66
  }
71
67
  }
@@ -89,13 +85,13 @@ class OAuthBase extends common_1.LoggerWrapper {
89
85
  }
90
86
  if (!_.isEmpty(data.oAuthCodeOrToken)) {
91
87
  this.promise.resolve({ redirectUri: this.getRedirectUri(), codeOrToken: data.oAuthCodeOrToken });
88
+ this.promise = null;
92
89
  }
93
90
  if (!_.isEmpty(data.oAuthError)) {
94
91
  this.promise.reject(data.oAuthError);
92
+ this.promise = null;
95
93
  }
96
- if (!this.promise.isPending) {
97
- this.close();
98
- }
94
+ this.close();
99
95
  }
100
96
  getCode() {
101
97
  return __awaiter(this, void 0, void 0, function* () {
@@ -112,14 +108,13 @@ class OAuthBase extends common_1.LoggerWrapper {
112
108
  close() {
113
109
  this.window.removeEventListener('message', this.messageHandler, false);
114
110
  this.popUpCheckCloseTimer = null;
115
- if (!_.isNil(this.subject)) {
116
- this.subject.next(new common_1.ObservableData(OAuthEvent.POPUP_CLOSED, this.popUp));
117
- }
118
- if (!_.isNil(this.popUp)) {
119
- this.popUp.close();
120
- this.popUp = null;
111
+ if (_.isNil(this.popUp)) {
112
+ return;
121
113
  }
122
- if (!_.isNil(this.promise)) {
114
+ this.subject.next(new common_1.ObservableData(OAuthEvent.POPUP_CLOSED, this.popUp));
115
+ this.popUp.close();
116
+ this.popUp = null;
117
+ if (this.isRejectWhenPopUpClosed && !_.isNil(this.promise)) {
123
118
  this.promise.reject(OAuthBase.ERROR_WINDOW_CLOSED);
124
119
  this.promise = null;
125
120
  }
@@ -130,6 +125,10 @@ class OAuthBase extends common_1.LoggerWrapper {
130
125
  }
131
126
  super.destroy();
132
127
  this.close();
128
+ if (!_.isNil(this.promise)) {
129
+ this.promise.reject(OAuthBase.ERROR_WINDOW_CLOSED);
130
+ this.promise = null;
131
+ }
133
132
  if (!_.isNil(this.urlParams)) {
134
133
  this.urlParams.clear();
135
134
  this._urlParams = null;
@@ -143,6 +142,9 @@ class OAuthBase extends common_1.LoggerWrapper {
143
142
  this.subject = null;
144
143
  }
145
144
  }
145
+ get isPopUpOpened() {
146
+ return !_.isNil(this.popUp) && !this.popUp.closed;
147
+ }
146
148
  get popUpCheckCloseTimer() {
147
149
  return this._popUpCheckCloseTimer;
148
150
  }
@@ -14,7 +14,7 @@ const common_1 = require("@ts-core/common");
14
14
  const rxjs_1 = require("rxjs");
15
15
  const OAuthBackendPropertiesSet = (item, redirectUri, method, timeout = common_1.DateUtil.MILLISECONDS_SECOND) => {
16
16
  item.redirectUri = redirectUri;
17
- item.popUpIsCheckClose = false;
18
- item.popUpOpened.pipe((0, rxjs_1.delay)(timeout), (0, rxjs_1.takeUntil)(item.destroyed)).subscribe(() => __awaiter(void 0, void 0, void 0, function* () { return item.parsePopUpResult(yield method.call(this, item.state)); }));
17
+ item.isRejectWhenPopUpClosed = false;
18
+ item.popUpClosed.pipe((0, rxjs_1.delay)(timeout), (0, rxjs_1.takeUntil)(item.destroyed)).subscribe(() => __awaiter(void 0, void 0, void 0, function* () { return item.parsePopUpResult(yield method(item.state)); }));
19
19
  };
20
20
  exports.OAuthBackendPropertiesSet = OAuthBackendPropertiesSet;
@@ -4,9 +4,9 @@ exports.OAuthCordovaPropertiesSet = void 0;
4
4
  const OAuthParser_1 = require("../OAuthParser");
5
5
  const _ = require("lodash");
6
6
  const OAuthCordovaPropertiesSet = (item, packageName) => {
7
- item.popUpTarget = 'oauth:cordova';
8
7
  item.redirectUri = `${packageName}://oauth_callback`;
9
- item.popUpIsCheckClose = false;
8
+ item.isRejectWhenPopUpClosed = false;
9
+ item.popUpTarget = 'oauth:cordova';
10
10
  item.popUpMessageParser = cordovaPopUpMessageParser;
11
11
  };
12
12
  exports.OAuthCordovaPropertiesSet = OAuthCordovaPropertiesSet;
@@ -7,9 +7,9 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
7
7
  popUpWidth: number;
8
8
  popUpHeight: number;
9
9
  popUpTarget: string;
10
- popUpIsCheckClose: boolean;
11
10
  popUpMessageParser: IOAuthPopUpParser;
12
11
  redirectUri: string;
12
+ isRejectWhenPopUpClosed: boolean;
13
13
  protected http: TransportHttp;
14
14
  protected subject: Subject<ObservableData<OAuthEvent, Window>>;
15
15
  protected popUp: Window;
@@ -35,6 +35,7 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
35
35
  getToken(): Promise<IOAuthDto>;
36
36
  close(): void;
37
37
  destroy(): void;
38
+ protected get isPopUpOpened(): boolean;
38
39
  protected get popUpCheckCloseTimer(): any;
39
40
  protected set popUpCheckCloseTimer(value: any);
40
41
  get urlParams(): Map<string, string>;
package/esm/OAuthBase.js CHANGED
@@ -16,7 +16,7 @@ export class OAuthBase extends LoggerWrapper {
16
16
  this.applicationId = applicationId;
17
17
  this.window = window;
18
18
  this.popUpCheckClose = () => {
19
- if (_.isNil(this.popUp) || this.popUp.closed) {
19
+ if (!this.isPopUpOpened) {
20
20
  this.close();
21
21
  }
22
22
  };
@@ -29,8 +29,8 @@ export class OAuthBase extends LoggerWrapper {
29
29
  this.popUpWidth = 430;
30
30
  this.popUpHeight = 520;
31
31
  this.popUpTarget = '_blank';
32
- this.popUpIsCheckClose = true;
33
32
  this.popUpMessageParser = this.browserInternalMessageHandler;
33
+ this.isRejectWhenPopUpClosed = true;
34
34
  this._urlParams = new Map();
35
35
  this.urlParams.set('state', RandomUtil.randomString());
36
36
  this.urlParams.set('display', 'popup');
@@ -38,19 +38,15 @@ export class OAuthBase extends LoggerWrapper {
38
38
  open() {
39
39
  return __awaiter(this, void 0, void 0, function* () {
40
40
  if (!_.isNil(this.promise)) {
41
- if (!_.isNil(this.popUp) && !this.popUp.closed) {
42
- this.popUp.focus();
43
- }
41
+ this.popUpFocus();
44
42
  return this.promise.promise;
45
43
  }
46
44
  this.promise = PromiseHandler.create();
47
45
  this.popUp = this.popUpOpen();
48
- this.subject.next(new ObservableData(OAuthEvent.POPUP_OPENED, this.popUp));
49
46
  this.popUpFocus();
50
- if (this.popUpIsCheckClose) {
51
- this.popUpCheckCloseTimer = setInterval(this.popUpCheckClose, DateUtil.MILLISECONDS_SECOND / 10);
52
- }
53
47
  this.window.addEventListener('message', this.messageHandler, false);
48
+ this.subject.next(new ObservableData(OAuthEvent.POPUP_OPENED, this.popUp));
49
+ this.popUpCheckCloseTimer = setInterval(this.popUpCheckClose, DateUtil.MILLISECONDS_SECOND / 5);
54
50
  return this.promise.promise;
55
51
  });
56
52
  }
@@ -62,7 +58,7 @@ export class OAuthBase extends LoggerWrapper {
62
58
  return item;
63
59
  }
64
60
  popUpFocus() {
65
- if (!_.isNil(this.popUp) && !this.popUp.closed) {
61
+ if (this.isPopUpOpened) {
66
62
  this.popUp.focus();
67
63
  }
68
64
  }
@@ -86,13 +82,13 @@ export class OAuthBase extends LoggerWrapper {
86
82
  }
87
83
  if (!_.isEmpty(data.oAuthCodeOrToken)) {
88
84
  this.promise.resolve({ redirectUri: this.getRedirectUri(), codeOrToken: data.oAuthCodeOrToken });
85
+ this.promise = null;
89
86
  }
90
87
  if (!_.isEmpty(data.oAuthError)) {
91
88
  this.promise.reject(data.oAuthError);
89
+ this.promise = null;
92
90
  }
93
- if (!this.promise.isPending) {
94
- this.close();
95
- }
91
+ this.close();
96
92
  }
97
93
  getCode() {
98
94
  return __awaiter(this, void 0, void 0, function* () {
@@ -109,14 +105,13 @@ export class OAuthBase extends LoggerWrapper {
109
105
  close() {
110
106
  this.window.removeEventListener('message', this.messageHandler, false);
111
107
  this.popUpCheckCloseTimer = null;
112
- if (!_.isNil(this.subject)) {
113
- this.subject.next(new ObservableData(OAuthEvent.POPUP_CLOSED, this.popUp));
114
- }
115
- if (!_.isNil(this.popUp)) {
116
- this.popUp.close();
117
- this.popUp = null;
108
+ if (_.isNil(this.popUp)) {
109
+ return;
118
110
  }
119
- if (!_.isNil(this.promise)) {
111
+ this.subject.next(new ObservableData(OAuthEvent.POPUP_CLOSED, this.popUp));
112
+ this.popUp.close();
113
+ this.popUp = null;
114
+ if (this.isRejectWhenPopUpClosed && !_.isNil(this.promise)) {
120
115
  this.promise.reject(OAuthBase.ERROR_WINDOW_CLOSED);
121
116
  this.promise = null;
122
117
  }
@@ -127,6 +122,10 @@ export class OAuthBase extends LoggerWrapper {
127
122
  }
128
123
  super.destroy();
129
124
  this.close();
125
+ if (!_.isNil(this.promise)) {
126
+ this.promise.reject(OAuthBase.ERROR_WINDOW_CLOSED);
127
+ this.promise = null;
128
+ }
130
129
  if (!_.isNil(this.urlParams)) {
131
130
  this.urlParams.clear();
132
131
  this._urlParams = null;
@@ -140,6 +139,9 @@ export class OAuthBase extends LoggerWrapper {
140
139
  this.subject = null;
141
140
  }
142
141
  }
142
+ get isPopUpOpened() {
143
+ return !_.isNil(this.popUp) && !this.popUp.closed;
144
+ }
143
145
  get popUpCheckCloseTimer() {
144
146
  return this._popUpCheckCloseTimer;
145
147
  }
@@ -11,6 +11,6 @@ import { DateUtil } from '@ts-core/common';
11
11
  import { delay, takeUntil } from 'rxjs';
12
12
  export const OAuthBackendPropertiesSet = (item, redirectUri, method, timeout = DateUtil.MILLISECONDS_SECOND) => {
13
13
  item.redirectUri = redirectUri;
14
- item.popUpIsCheckClose = false;
15
- item.popUpOpened.pipe(delay(timeout), takeUntil(item.destroyed)).subscribe(() => __awaiter(void 0, void 0, void 0, function* () { return item.parsePopUpResult(yield method.call(this, item.state)); }));
14
+ item.isRejectWhenPopUpClosed = false;
15
+ item.popUpClosed.pipe(delay(timeout), takeUntil(item.destroyed)).subscribe(() => __awaiter(void 0, void 0, void 0, function* () { return item.parsePopUpResult(yield method(item.state)); }));
16
16
  };
@@ -1,9 +1,9 @@
1
1
  import { OAuthParser } from '../OAuthParser';
2
2
  import * as _ from 'lodash';
3
3
  export const OAuthCordovaPropertiesSet = (item, packageName) => {
4
- item.popUpTarget = 'oauth:cordova';
5
4
  item.redirectUri = `${packageName}://oauth_callback`;
6
- item.popUpIsCheckClose = false;
5
+ item.isRejectWhenPopUpClosed = false;
6
+ item.popUpTarget = 'oauth:cordova';
7
7
  item.popUpMessageParser = cordovaPopUpMessageParser;
8
8
  };
9
9
  function cordovaPopUpMessageParser(event) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-core/oauth",
3
- "version": "3.0.21",
3
+ "version": "3.0.23",
4
4
  "description": "Classes and utils for oauth",
5
5
  "main": "./cjs/public-api.js",
6
6
  "module": "./esm/public-api.js",