@stackframe/stack-shared 2.7.7 → 2.7.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/CHANGELOG.md +8 -0
- package/dist/sessions.d.ts +3 -7
- package/dist/sessions.js +11 -22
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/dist/sessions.d.ts
CHANGED
|
@@ -73,9 +73,9 @@ export declare class InternalSession {
|
|
|
73
73
|
/**
|
|
74
74
|
* Fetches new tokens that are, at the time of fetching, guaranteed to be valid.
|
|
75
75
|
*
|
|
76
|
-
* The newly generated tokens are
|
|
76
|
+
* The newly generated tokens are short-lived, so it's good practice not to rely on their validity (if possible). However, this function is useful in some cases where you only want to pass access tokens to a service, and you want to make sure said access token has the longest possible lifetime.
|
|
77
77
|
*
|
|
78
|
-
* In most cases, you should prefer `getOrFetchLikelyValidTokens
|
|
78
|
+
* In most cases, you should prefer `getOrFetchLikelyValidTokens`.
|
|
79
79
|
*
|
|
80
80
|
* @returns null if the session is known to be invalid, or new tokens otherwise (which, at the time of fetching, are guaranteed to be valid).
|
|
81
81
|
*/
|
|
@@ -95,11 +95,7 @@ export declare class InternalSession {
|
|
|
95
95
|
*/
|
|
96
96
|
private _getPotentiallyInvalidAccessTokenIfAvailable;
|
|
97
97
|
/**
|
|
98
|
-
*
|
|
99
|
-
*/
|
|
100
|
-
private _getOrFetchPotentiallyInvalidAccessToken;
|
|
101
|
-
/**
|
|
102
|
-
* You should prefer `_getOrFetchAccessToken` in almost all cases.
|
|
98
|
+
* You should prefer `_getOrFetchPotentiallyInvalidAccessToken` in almost all cases.
|
|
103
99
|
*
|
|
104
100
|
* @returns A newly fetched access token (never read from cache), or null if the session either does not represent a user or the session is invalid.
|
|
105
101
|
*/
|
package/dist/sessions.js
CHANGED
|
@@ -10,7 +10,7 @@ export class AccessToken {
|
|
|
10
10
|
}
|
|
11
11
|
get expiresAt() {
|
|
12
12
|
const { exp } = jose.decodeJwt(this.token);
|
|
13
|
-
if (
|
|
13
|
+
if (exp === undefined)
|
|
14
14
|
return new Date(8640000000000000); // max date value
|
|
15
15
|
return new Date(exp * 1000);
|
|
16
16
|
}
|
|
@@ -107,9 +107,9 @@ export class InternalSession {
|
|
|
107
107
|
/**
|
|
108
108
|
* Fetches new tokens that are, at the time of fetching, guaranteed to be valid.
|
|
109
109
|
*
|
|
110
|
-
* The newly generated tokens are
|
|
110
|
+
* The newly generated tokens are short-lived, so it's good practice not to rely on their validity (if possible). However, this function is useful in some cases where you only want to pass access tokens to a service, and you want to make sure said access token has the longest possible lifetime.
|
|
111
111
|
*
|
|
112
|
-
* In most cases, you should prefer `getOrFetchLikelyValidTokens
|
|
112
|
+
* In most cases, you should prefer `getOrFetchLikelyValidTokens`.
|
|
113
113
|
*
|
|
114
114
|
* @returns null if the session is known to be invalid, or new tokens otherwise (which, at the time of fetching, are guaranteed to be valid).
|
|
115
115
|
*/
|
|
@@ -133,30 +133,17 @@ export class InternalSession {
|
|
|
133
133
|
* @returns An access token, which may be expired or expire soon, or null if it is known to be invalid.
|
|
134
134
|
*/
|
|
135
135
|
_getPotentiallyInvalidAccessTokenIfAvailable() {
|
|
136
|
-
const accessToken = this._accessToken.get();
|
|
137
|
-
if (accessToken && !accessToken.isExpired())
|
|
138
|
-
return accessToken;
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* @returns An access token (cached if possible), or null if the session either does not represent a user or the session is invalid.
|
|
143
|
-
*/
|
|
144
|
-
async _getOrFetchPotentiallyInvalidAccessToken() {
|
|
145
136
|
if (!this._refreshToken)
|
|
146
137
|
return null;
|
|
147
138
|
if (this.isKnownToBeInvalid())
|
|
148
139
|
return null;
|
|
149
|
-
const
|
|
150
|
-
if (
|
|
151
|
-
return
|
|
152
|
-
|
|
153
|
-
if (!this._refreshPromise) {
|
|
154
|
-
this._refreshAndSetRefreshPromise(this._refreshToken);
|
|
155
|
-
}
|
|
156
|
-
return await this._refreshPromise;
|
|
140
|
+
const accessToken = this._accessToken.get();
|
|
141
|
+
if (accessToken && !accessToken.isExpired())
|
|
142
|
+
return accessToken;
|
|
143
|
+
return null;
|
|
157
144
|
}
|
|
158
145
|
/**
|
|
159
|
-
* You should prefer `
|
|
146
|
+
* You should prefer `_getOrFetchPotentiallyInvalidAccessToken` in almost all cases.
|
|
160
147
|
*
|
|
161
148
|
* @returns A newly fetched access token (never read from cache), or null if the session either does not represent a user or the session is invalid.
|
|
162
149
|
*/
|
|
@@ -165,7 +152,9 @@ export class InternalSession {
|
|
|
165
152
|
return null;
|
|
166
153
|
if (this._knownToBeInvalid.get())
|
|
167
154
|
return null;
|
|
168
|
-
|
|
155
|
+
if (!this._refreshPromise) {
|
|
156
|
+
this._refreshAndSetRefreshPromise(this._refreshToken);
|
|
157
|
+
}
|
|
169
158
|
return await this._refreshPromise;
|
|
170
159
|
}
|
|
171
160
|
_refreshAndSetRefreshPromise(refreshToken) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackframe/stack-shared",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.8",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"oauth4webapi": "^2.10.3",
|
|
52
52
|
"semver": "^7.6.3",
|
|
53
53
|
"uuid": "^9.0.1",
|
|
54
|
-
"@stackframe/stack-sc": "2.7.
|
|
54
|
+
"@stackframe/stack-sc": "2.7.8"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@sentry/nextjs": "^8.40.0",
|