zavadil-ts-common 1.2.78 → 2.0.0

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 (29) hide show
  1. package/dist/index.d.ts +27 -23
  2. package/dist/index.esm.js +1 -1
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/oauth/OAuthRestClient.d.ts +9 -6
  7. package/dist/oauth/OAuthTokenManager.d.ts +11 -11
  8. package/dist/oauth/RestClientWithOAuth.d.ts +4 -4
  9. package/dist/oauth/tokenprovider/OAuthRefreshTokenProvider.d.ts +5 -0
  10. package/dist/oauth/tokenprovider/RefreshTokenProviderDefault.d.ts +14 -0
  11. package/dist/oauth/tokenprovider/RefreshTokenProviderLogin.d.ts +12 -0
  12. package/dist/oauth/tokenprovider/RefreshTokenProviderStorage.d.ts +10 -0
  13. package/dist/oauth/tokenprovider/RefreshTokenProviderUrl.d.ts +12 -0
  14. package/dist/util/NumberUtil.d.ts +2 -2
  15. package/dist/util/ObjectUtil.d.ts +1 -1
  16. package/package.json +1 -1
  17. package/src/oauth/OAuthRestClient.ts +20 -9
  18. package/src/oauth/OAuthTokenManager.ts +29 -29
  19. package/src/oauth/RestClientWithOAuth.ts +11 -11
  20. package/src/oauth/tokenprovider/OAuthRefreshTokenProvider.ts +6 -0
  21. package/src/oauth/tokenprovider/RefreshTokenProviderDefault.ts +52 -0
  22. package/src/oauth/tokenprovider/{IdTokenProviderLogin.ts → RefreshTokenProviderLogin.ts} +3 -3
  23. package/src/oauth/tokenprovider/{IdTokenProviderStorage.ts → RefreshTokenProviderStorage.ts} +9 -9
  24. package/src/oauth/tokenprovider/{IdTokenProviderUrl.ts → RefreshTokenProviderUrl.ts} +7 -7
  25. package/src/util/NumberUtil.ts +5 -1
  26. package/src/util/OAuthUtil.ts +2 -1
  27. package/src/util/ObjectUtil.ts +1 -1
  28. package/src/oauth/tokenprovider/IdTokenProviderDefault.ts +0 -52
  29. package/src/oauth/tokenprovider/OAuthIdTokenProvider.ts +0 -6
@@ -1,10 +1,11 @@
1
1
  import {TokenResponsePayloadBase} from "../oauth";
2
2
  import {StringUtil} from "./StringUtil";
3
+ import {ObjectUtil} from "./ObjectUtil";
3
4
 
4
5
  export class OAuthUtil {
5
6
 
6
7
  static isValidToken(token?: TokenResponsePayloadBase | null): boolean {
7
- return token !== undefined && token !== null && StringUtil.notBlank(token.token) && !OAuthUtil.isTokenExpired(token);
8
+ return ObjectUtil.notEmpty(token) && StringUtil.notBlank(token.token) && !OAuthUtil.isTokenExpired(token);
8
9
  }
9
10
 
10
11
  static isTokenExpired(token?: TokenResponsePayloadBase | null): boolean {
@@ -4,7 +4,7 @@ export class ObjectUtil {
4
4
  return obj === undefined || obj === null;
5
5
  }
6
6
 
7
- static notEmpty(obj: any) {
7
+ static notEmpty(obj: any): obj is object {
8
8
  return !ObjectUtil.isEmpty(obj);
9
9
  }
10
10
 
@@ -1,52 +0,0 @@
1
- import {OAuthIdTokenProvider} from "./OAuthIdTokenProvider";
2
- import {IdTokenPayload} from "../OAuthRestClient";
3
- import {IdTokenProviderLogin} from "./IdTokenProviderLogin";
4
- import {RestClientWithOAuth} from "../RestClientWithOAuth";
5
- import {IdTokenProviderUrl} from "./IdTokenProviderUrl";
6
- import {IdTokenProviderStorage} from "./IdTokenProviderStorage";
7
-
8
- export class IdTokenProviderDefault implements OAuthIdTokenProvider {
9
-
10
- login: IdTokenProviderLogin;
11
-
12
- url: IdTokenProviderUrl;
13
-
14
- storage: IdTokenProviderStorage;
15
-
16
- constructor(client: RestClientWithOAuth, tokenStorageKey?: string, tokenUrlName?: string) {
17
- this.login = new IdTokenProviderLogin(client, tokenUrlName);
18
- this.url = new IdTokenProviderUrl(client, tokenUrlName);
19
- this.storage = new IdTokenProviderStorage(tokenStorageKey);
20
- }
21
-
22
- getIdToken(): Promise<IdTokenPayload> {
23
- return this.url
24
- .getIdToken()
25
- .catch(
26
- (err) => {
27
- console.log("No token in url, loading from storage:", err);
28
- return this.storage
29
- .getIdToken()
30
- .catch(
31
- (err) => {
32
- console.log("No token in storage, redirecting to login page:", err);
33
- return this.login.getIdToken();
34
- }
35
- );
36
- }
37
- )
38
- .then(
39
- (t) => {
40
- console.log("Token found, saving to storage...");
41
- this.storage.saveIdTokenToLocalStorage(t);
42
- // redirect if token is in url
43
- return this.url.reset().then(() => t);
44
- }
45
- );
46
- }
47
-
48
- reset(): Promise<any> {
49
- return this.storage.reset().then(() => this.url.reset());
50
- }
51
-
52
- }
@@ -1,6 +0,0 @@
1
- import {IdTokenPayload} from "../OAuthRestClient";
2
-
3
- export interface OAuthIdTokenProvider {
4
- getIdToken(): Promise<IdTokenPayload>;
5
- reset(): Promise<any>;
6
- }