my-youtube-api 1.0.6 → 1.0.8
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.
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +12 -0
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/utils.ts +14 -0
package/dist/utils.d.ts
CHANGED
|
@@ -11,6 +11,11 @@ interface AccessTokenType {
|
|
|
11
11
|
* @returns true if valid, false otherwise.
|
|
12
12
|
*/
|
|
13
13
|
export declare function isValidAccessToken(accessToken: string | null): Promise<boolean>;
|
|
14
|
+
/**
|
|
15
|
+
* return true if token expire
|
|
16
|
+
* @param expires_at number in seconds
|
|
17
|
+
* */
|
|
18
|
+
export declare function isTokenExpiredOrExpiring(expires_at: number | null, thresholdInDays?: number): boolean;
|
|
14
19
|
/**
|
|
15
20
|
* Refreshes an expired access token using a valid refresh token
|
|
16
21
|
* @param valid_refresh_token - The refresh token obtained during initial OAuth2 authentication
|
package/dist/utils.js
CHANGED
|
@@ -19,6 +19,18 @@ export async function isValidAccessToken(accessToken) {
|
|
|
19
19
|
return false; // expired or invalid token
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* return true if token expire
|
|
24
|
+
* @param expires_at number in seconds
|
|
25
|
+
* */
|
|
26
|
+
export function isTokenExpiredOrExpiring(expires_at, thresholdInDays = 1) {
|
|
27
|
+
if (!expires_at || expires_at === 0)
|
|
28
|
+
return false;
|
|
29
|
+
const nowUnix = Math.floor(Date.now() / 1000);
|
|
30
|
+
const thresholdSeconds = thresholdInDays * 24 * 60 * 60;
|
|
31
|
+
//console.log((expires_at - nowUnix)/60/60/24 ,';;;;;;;;;;;;;;;;;;;;;;..........');
|
|
32
|
+
return expires_at - nowUnix < thresholdSeconds;
|
|
33
|
+
}
|
|
22
34
|
/**
|
|
23
35
|
* Refreshes an expired access token using a valid refresh token
|
|
24
36
|
* @param valid_refresh_token - The refresh token obtained during initial OAuth2 authentication
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -10,7 +10,7 @@ npm pack
|
|
|
10
10
|
in nextjs go to this package/"my-youtube-api-1.0.0.tgz"
|
|
11
11
|
*/
|
|
12
12
|
export * from "./errors/youtube-api-errors";
|
|
13
|
-
import { isValidAccessToken, fetchNewAccessToken } from './utils'
|
|
13
|
+
import { isValidAccessToken, fetchNewAccessToken,isTokenExpiredOrExpiring } from './utils'
|
|
14
14
|
|
|
15
15
|
export const createYoutubeVideoPoster = (access_token: string) => {
|
|
16
16
|
return new YoutubeVideoPoster(access_token);
|
package/src/utils.ts
CHANGED
|
@@ -28,6 +28,20 @@ export async function isValidAccessToken(accessToken: string | null): Promise<bo
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* return true if token expire
|
|
33
|
+
* @param expires_at number in seconds
|
|
34
|
+
* */
|
|
35
|
+
export function isTokenExpiredOrExpiring(expires_at: number | null, thresholdInDays = 1): boolean {
|
|
36
|
+
if (!expires_at || expires_at===0) return false;
|
|
37
|
+
|
|
38
|
+
const nowUnix = Math.floor(Date.now() / 1000);
|
|
39
|
+
const thresholdSeconds = thresholdInDays * 24 * 60 * 60;
|
|
40
|
+
//console.log((expires_at - nowUnix)/60/60/24 ,';;;;;;;;;;;;;;;;;;;;;;..........');
|
|
41
|
+
return expires_at - nowUnix < thresholdSeconds;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
31
45
|
|
|
32
46
|
/**
|
|
33
47
|
* Refreshes an expired access token using a valid refresh token
|