@ts-core/oauth 3.1.2 → 3.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.
@@ -24,9 +24,9 @@ export interface IOAuthDto {
24
24
  redirectUri: string;
25
25
  }
26
26
  export interface IOAuthPopUpDto {
27
- oauthError?: string;
28
- oauthCodeOrToken?: string;
29
- oauthErrorDescription?: string;
27
+ oAuthError?: string;
28
+ oAuthCodeOrToken?: string;
29
+ oAuthErrorDescription?: string;
30
30
  }
31
31
  export interface IOAuthToken {
32
32
  expiresIn: number;
package/cjs/OAuthBase.js CHANGED
@@ -37,15 +37,15 @@ class OAuthBase extends PopUpBase_1.PopUpBase {
37
37
  }
38
38
  parseMessageData(item) {
39
39
  return {
40
- codeOrToken: item.oauthCodeOrToken,
40
+ codeOrToken: item.oAuthCodeOrToken,
41
41
  redirectUri: this.getRedirectUri()
42
42
  };
43
43
  }
44
44
  isMessageError(item) {
45
- return !_.isNil(item.oauthError);
45
+ return !_.isNil(item.oAuthError);
46
46
  }
47
47
  parseMessageError(item) {
48
- return new common_1.ExtendedError(item.oauthError, item.oauthErrorDescription);
48
+ return new common_1.ExtendedError(item.oAuthError, item.oAuthErrorDescription);
49
49
  }
50
50
  getCode() {
51
51
  return __awaiter(this, void 0, void 0, function* () {
@@ -4,3 +4,4 @@ export declare class OAuthParser {
4
4
  static ERRORS: Array<string>;
5
5
  static parse(params: any, fragment?: string): IOAuthPopUpDto;
6
6
  }
7
+ export declare function mergeUrlParamsAndFragment(params: any, fragment?: string): Record<string, any>;
@@ -1,29 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OAuthParser = void 0;
3
+ exports.mergeUrlParamsAndFragment = exports.OAuthParser = void 0;
4
4
  const _ = require("lodash");
5
5
  class OAuthParser {
6
6
  static parse(params, fragment) {
7
- let item = new Object();
8
- _.forIn(params, (value, key) => item[key] = value);
9
- if (!_.isEmpty(fragment)) {
10
- new URLSearchParams(fragment).forEach((value, key) => item[key] = value);
11
- }
12
- let oauthError = null;
13
- let oauthCodeOrToken = null;
7
+ let item = mergeUrlParamsAndFragment(params, fragment);
8
+ let oAuthError = null;
9
+ let oAuthCodeOrToken = null;
14
10
  for (let key in item) {
15
11
  let value = item[key];
16
12
  if (OAuthParser.NAMES.includes(key)) {
17
- oauthCodeOrToken = value;
13
+ oAuthCodeOrToken = value;
18
14
  }
19
15
  else if (OAuthParser.ERRORS.includes(key)) {
20
- oauthError = value;
16
+ oAuthError = value;
21
17
  }
22
- if (!_.isEmpty(oauthCodeOrToken)) {
23
- return { oauthCodeOrToken };
18
+ if (!_.isEmpty(oAuthCodeOrToken)) {
19
+ return { oAuthCodeOrToken };
24
20
  }
25
- else if (!_.isEmpty(oauthError)) {
26
- return { oauthErrorDescription: item.error_description, oauthError };
21
+ else if (!_.isEmpty(oAuthError)) {
22
+ return { oAuthErrorDescription: item.error_description, oAuthError };
27
23
  }
28
24
  }
29
25
  ;
@@ -33,3 +29,12 @@ class OAuthParser {
33
29
  exports.OAuthParser = OAuthParser;
34
30
  OAuthParser.NAMES = ['code', 'access_token'];
35
31
  OAuthParser.ERRORS = ['error', 'error_description'];
32
+ function mergeUrlParamsAndFragment(params, fragment) {
33
+ let item = new Object();
34
+ _.forIn(params, (value, key) => item[key] = value);
35
+ if (!_.isEmpty(fragment)) {
36
+ new URLSearchParams(fragment).forEach((value, key) => item[key] = value);
37
+ }
38
+ return item;
39
+ }
40
+ exports.mergeUrlParamsAndFragment = mergeUrlParamsAndFragment;
@@ -2,6 +2,7 @@ import { PromiseHandler, ObservableData, LoggerWrapper, ILogger, ExtendedError }
2
2
  import { Observable, Subject } from "rxjs";
3
3
  export declare abstract class PopUpBase<U> extends LoggerWrapper {
4
4
  static ERROR_WINDOW_CLOSED: string;
5
+ static isWindowClosedError(error: any): boolean;
5
6
  popUpWidth: number;
6
7
  popUpHeight: number;
7
8
  popUpTarget: string;
package/cjs/PopUpBase.js CHANGED
@@ -14,6 +14,9 @@ const common_1 = require("@ts-core/common");
14
14
  const rxjs_1 = require("rxjs");
15
15
  const _ = require("lodash");
16
16
  class PopUpBase extends common_1.LoggerWrapper {
17
+ static isWindowClosedError(error) {
18
+ return !_.isNil(error) && error.code === PopUpBase.ERROR_WINDOW_CLOSED;
19
+ }
17
20
  constructor(logger, window) {
18
21
  super(logger);
19
22
  this.popUpCheckClose = () => {
@@ -10,5 +10,5 @@ const OAuthBrowserPropertiesSet = (item) => {
10
10
  };
11
11
  exports.OAuthBrowserPropertiesSet = OAuthBrowserPropertiesSet;
12
12
  function popUpMessageEventParser(event) {
13
- return !_.isNil(event.data.oauthError) || !_.isNil(event.data.oauthCodeOrToken) ? event.data : null;
13
+ return !_.isNil(event.data.oAuthError) || !_.isNil(event.data.oAuthCodeOrToken) ? event.data : null;
14
14
  }
@@ -31,11 +31,11 @@ const OAuthCordovaInAppBrowserPluginPropertiesSet = (item, redirectUri, method)
31
31
  try {
32
32
  data = yield method(item.state);
33
33
  if (_.isEmpty(data)) {
34
- data = { oauthError: OAuthBase_1.OAuthBase.ERROR_WINDOW_CLOSED };
34
+ data = { oAuthError: OAuthBase_1.OAuthBase.ERROR_WINDOW_CLOSED };
35
35
  }
36
36
  }
37
37
  catch (error) {
38
- data = { oauthError: error.toString() };
38
+ data = { oAuthError: error.toString() };
39
39
  }
40
40
  item.parse(data);
41
41
  });
@@ -24,9 +24,9 @@ export interface IOAuthDto {
24
24
  redirectUri: string;
25
25
  }
26
26
  export interface IOAuthPopUpDto {
27
- oauthError?: string;
28
- oauthCodeOrToken?: string;
29
- oauthErrorDescription?: string;
27
+ oAuthError?: string;
28
+ oAuthCodeOrToken?: string;
29
+ oAuthErrorDescription?: string;
30
30
  }
31
31
  export interface IOAuthToken {
32
32
  expiresIn: number;
package/esm/OAuthBase.js CHANGED
@@ -34,15 +34,15 @@ export class OAuthBase extends PopUpBase {
34
34
  }
35
35
  parseMessageData(item) {
36
36
  return {
37
- codeOrToken: item.oauthCodeOrToken,
37
+ codeOrToken: item.oAuthCodeOrToken,
38
38
  redirectUri: this.getRedirectUri()
39
39
  };
40
40
  }
41
41
  isMessageError(item) {
42
- return !_.isNil(item.oauthError);
42
+ return !_.isNil(item.oAuthError);
43
43
  }
44
44
  parseMessageError(item) {
45
- return new ExtendedError(item.oauthError, item.oauthErrorDescription);
45
+ return new ExtendedError(item.oAuthError, item.oAuthErrorDescription);
46
46
  }
47
47
  getCode() {
48
48
  return __awaiter(this, void 0, void 0, function* () {
@@ -4,3 +4,4 @@ export declare class OAuthParser {
4
4
  static ERRORS: Array<string>;
5
5
  static parse(params: any, fragment?: string): IOAuthPopUpDto;
6
6
  }
7
+ export declare function mergeUrlParamsAndFragment(params: any, fragment?: string): Record<string, any>;
@@ -1,26 +1,22 @@
1
1
  import * as _ from 'lodash';
2
2
  export class OAuthParser {
3
3
  static parse(params, fragment) {
4
- let item = new Object();
5
- _.forIn(params, (value, key) => item[key] = value);
6
- if (!_.isEmpty(fragment)) {
7
- new URLSearchParams(fragment).forEach((value, key) => item[key] = value);
8
- }
9
- let oauthError = null;
10
- let oauthCodeOrToken = null;
4
+ let item = mergeUrlParamsAndFragment(params, fragment);
5
+ let oAuthError = null;
6
+ let oAuthCodeOrToken = null;
11
7
  for (let key in item) {
12
8
  let value = item[key];
13
9
  if (OAuthParser.NAMES.includes(key)) {
14
- oauthCodeOrToken = value;
10
+ oAuthCodeOrToken = value;
15
11
  }
16
12
  else if (OAuthParser.ERRORS.includes(key)) {
17
- oauthError = value;
13
+ oAuthError = value;
18
14
  }
19
- if (!_.isEmpty(oauthCodeOrToken)) {
20
- return { oauthCodeOrToken };
15
+ if (!_.isEmpty(oAuthCodeOrToken)) {
16
+ return { oAuthCodeOrToken };
21
17
  }
22
- else if (!_.isEmpty(oauthError)) {
23
- return { oauthErrorDescription: item.error_description, oauthError };
18
+ else if (!_.isEmpty(oAuthError)) {
19
+ return { oAuthErrorDescription: item.error_description, oAuthError };
24
20
  }
25
21
  }
26
22
  ;
@@ -29,3 +25,11 @@ export class OAuthParser {
29
25
  }
30
26
  OAuthParser.NAMES = ['code', 'access_token'];
31
27
  OAuthParser.ERRORS = ['error', 'error_description'];
28
+ export function mergeUrlParamsAndFragment(params, fragment) {
29
+ let item = new Object();
30
+ _.forIn(params, (value, key) => item[key] = value);
31
+ if (!_.isEmpty(fragment)) {
32
+ new URLSearchParams(fragment).forEach((value, key) => item[key] = value);
33
+ }
34
+ return item;
35
+ }
@@ -2,6 +2,7 @@ import { PromiseHandler, ObservableData, LoggerWrapper, ILogger, ExtendedError }
2
2
  import { Observable, Subject } from "rxjs";
3
3
  export declare abstract class PopUpBase<U> extends LoggerWrapper {
4
4
  static ERROR_WINDOW_CLOSED: string;
5
+ static isWindowClosedError(error: any): boolean;
5
6
  popUpWidth: number;
6
7
  popUpHeight: number;
7
8
  popUpTarget: string;
package/esm/PopUpBase.js CHANGED
@@ -11,6 +11,9 @@ import { PromiseHandler, DateUtil, ObservableData, LoggerWrapper, ExtendedError
11
11
  import { filter, map, Subject } from "rxjs";
12
12
  import * as _ from 'lodash';
13
13
  export class PopUpBase extends LoggerWrapper {
14
+ static isWindowClosedError(error) {
15
+ return !_.isNil(error) && error.code === PopUpBase.ERROR_WINDOW_CLOSED;
16
+ }
14
17
  constructor(logger, window) {
15
18
  super(logger);
16
19
  this.popUpCheckClose = () => {
@@ -6,5 +6,5 @@ export const OAuthBrowserPropertiesSet = (item) => {
6
6
  item.isRejectWhenPopUpClosed = true;
7
7
  };
8
8
  function popUpMessageEventParser(event) {
9
- return !_.isNil(event.data.oauthError) || !_.isNil(event.data.oauthCodeOrToken) ? event.data : null;
9
+ return !_.isNil(event.data.oAuthError) || !_.isNil(event.data.oAuthCodeOrToken) ? event.data : null;
10
10
  }
@@ -28,11 +28,11 @@ export const OAuthCordovaInAppBrowserPluginPropertiesSet = (item, redirectUri, m
28
28
  try {
29
29
  data = yield method(item.state);
30
30
  if (_.isEmpty(data)) {
31
- data = { oauthError: OAuthBase.ERROR_WINDOW_CLOSED };
31
+ data = { oAuthError: OAuthBase.ERROR_WINDOW_CLOSED };
32
32
  }
33
33
  }
34
34
  catch (error) {
35
- data = { oauthError: error.toString() };
35
+ data = { oAuthError: error.toString() };
36
36
  }
37
37
  item.parse(data);
38
38
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-core/oauth",
3
- "version": "3.1.2",
3
+ "version": "3.1.4",
4
4
  "description": "Classes and utils for oauth",
5
5
  "main": "./cjs/public-api.js",
6
6
  "module": "./esm/public-api.js",