@friggframework/core 2.0.0--canary.744.95fdcc7.0 → 2.0.0--canary.744.7e3ee98.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.
|
@@ -66,10 +66,9 @@ class IntegrationRepositoryMongo extends IntegrationRepositoryInterface {
|
|
|
66
66
|
* @returns {Promise<Array>} Array of integration objects (possibly empty)
|
|
67
67
|
*/
|
|
68
68
|
async findIntegrations({ type, status } = {}) {
|
|
69
|
+
// Prisma's MongoDB connector has no JSON path filter, so a where on
|
|
70
|
+
// config.type throws. The type is filtered after the read.
|
|
69
71
|
const where = {};
|
|
70
|
-
if (type) {
|
|
71
|
-
where.config = { path: ['type'], equals: type };
|
|
72
|
-
}
|
|
73
72
|
if (status) {
|
|
74
73
|
where.status = status;
|
|
75
74
|
}
|
|
@@ -81,7 +80,9 @@ class IntegrationRepositoryMongo extends IntegrationRepositoryInterface {
|
|
|
81
80
|
},
|
|
82
81
|
});
|
|
83
82
|
|
|
84
|
-
return integrations
|
|
83
|
+
return integrations
|
|
84
|
+
.filter((integration) => !type || integration.config?.type === type)
|
|
85
|
+
.map((integration) => ({
|
|
85
86
|
id: integration.id,
|
|
86
87
|
entitiesIds: integration.entities.map((e) => e.id),
|
|
87
88
|
userId: integration.userId,
|
|
@@ -142,19 +142,28 @@ class OAuth2Requester extends Requester {
|
|
|
142
142
|
* string from the credential store. An unknown or unreadable expiry
|
|
143
143
|
* returns false: the 401 path handles that token.
|
|
144
144
|
*
|
|
145
|
+
* Only for a grant with a refresh token. The client_credentials grant is
|
|
146
|
+
* left out: getTokenFromClientCredentials() reports any failure,
|
|
147
|
+
* a 503 too, as invalid auth, which would disable a working credential.
|
|
148
|
+
*
|
|
145
149
|
* @returns {boolean}
|
|
146
150
|
*/
|
|
147
151
|
_isTokenExpiringSoon() {
|
|
148
152
|
if (!this.refreshBeforeExpiryMs) return false;
|
|
149
153
|
if (!this.accessTokenExpire) return false;
|
|
150
|
-
if (this.grant_type
|
|
151
|
-
|
|
152
|
-
}
|
|
154
|
+
if (this.grant_type === 'client_credentials') return false;
|
|
155
|
+
if (!this.refresh_token) return false;
|
|
153
156
|
const expiresAt = new Date(this.accessTokenExpire).getTime();
|
|
154
157
|
if (Number.isNaN(expiresAt)) return false;
|
|
155
158
|
return expiresAt - Date.now() <= this.refreshBeforeExpiryMs;
|
|
156
159
|
}
|
|
157
160
|
|
|
161
|
+
/** True when the URL, without its query, is `tokenUri`. */
|
|
162
|
+
_isTokenRequest(url) {
|
|
163
|
+
if (!this.tokenUri || typeof url !== 'string') return false;
|
|
164
|
+
return url.split('?')[0] === String(this.tokenUri).split('?')[0];
|
|
165
|
+
}
|
|
166
|
+
|
|
158
167
|
/**
|
|
159
168
|
* Sets OAuth tokens and calculates expiration times.
|
|
160
169
|
* Notifies delegates of token update via DLGT_TOKEN_UPDATE.
|
|
@@ -257,7 +257,7 @@ class Requester extends Delegate {
|
|
|
257
257
|
}
|
|
258
258
|
|
|
259
259
|
if (attempt === 0) {
|
|
260
|
-
await this._refreshIfExpiringSoon();
|
|
260
|
+
await this._refreshIfExpiringSoon(url);
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
options.headers = await this.addAuthHeaders(options.headers);
|
|
@@ -789,11 +789,18 @@ class Requester extends Delegate {
|
|
|
789
789
|
* A failure here does not fail the request. The request goes out with
|
|
790
790
|
* the current token, and the 401 path stays the fallback. After a
|
|
791
791
|
* failure, no proactive refresh runs for PROACTIVE_REFRESH_COOLDOWN_MS.
|
|
792
|
+
* The same cooldown applies after a refresh whose new token still
|
|
793
|
+
* expires inside the window (no `expires_in`, or a lifetime shorter
|
|
794
|
+
* than the window). Without it, every request would refresh.
|
|
792
795
|
* Concurrent callers share one refresh through _refreshAuthOnce().
|
|
796
|
+
*
|
|
797
|
+
* @param {string} url - The request URL. A call to the token endpoint
|
|
798
|
+
* itself never starts a proactive refresh.
|
|
793
799
|
*/
|
|
794
|
-
async _refreshIfExpiringSoon() {
|
|
800
|
+
async _refreshIfExpiringSoon(url) {
|
|
795
801
|
if (this._isInsideRefreshFlow()) return;
|
|
796
802
|
if (Date.now() < this._proactiveRefreshNotBefore) return;
|
|
803
|
+
if (this._isTokenRequest(url)) return;
|
|
797
804
|
if (!this._isTokenExpiringSoon()) return;
|
|
798
805
|
|
|
799
806
|
const tokenBefore = this.access_token;
|
|
@@ -810,7 +817,19 @@ class Requester extends Delegate {
|
|
|
810
817
|
}
|
|
811
818
|
);
|
|
812
819
|
}
|
|
813
|
-
if (refreshed)
|
|
820
|
+
if (refreshed) {
|
|
821
|
+
if (this._isTokenExpiringSoon()) {
|
|
822
|
+
this.logger.warn(
|
|
823
|
+
'The refreshed token expires inside the proactive refresh window',
|
|
824
|
+
{
|
|
825
|
+
eventName: `${this.logger.name}.proactive_refresh_window_too_long`,
|
|
826
|
+
}
|
|
827
|
+
);
|
|
828
|
+
this._proactiveRefreshNotBefore =
|
|
829
|
+
Date.now() + PROACTIVE_REFRESH_COOLDOWN_MS;
|
|
830
|
+
}
|
|
831
|
+
return;
|
|
832
|
+
}
|
|
814
833
|
|
|
815
834
|
this._proactiveRefreshNotBefore =
|
|
816
835
|
Date.now() + PROACTIVE_REFRESH_COOLDOWN_MS;
|
|
@@ -834,6 +853,18 @@ class Requester extends Delegate {
|
|
|
834
853
|
return false;
|
|
835
854
|
}
|
|
836
855
|
|
|
856
|
+
/**
|
|
857
|
+
* Hook: true when the URL is this requester's token endpoint. A token
|
|
858
|
+
* request (code exchange, client credentials) must not first refresh
|
|
859
|
+
* the old token.
|
|
860
|
+
*
|
|
861
|
+
* @param {string} _url
|
|
862
|
+
* @returns {boolean}
|
|
863
|
+
*/
|
|
864
|
+
_isTokenRequest(_url) {
|
|
865
|
+
return false;
|
|
866
|
+
}
|
|
867
|
+
|
|
837
868
|
/** True while this instance runs its own refresh. */
|
|
838
869
|
_isInsideRefreshFlow() {
|
|
839
870
|
return refreshContext.getStore()?.requester === this;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/core",
|
|
3
3
|
"prettier": "@friggframework/prettier-config",
|
|
4
|
-
"version": "2.0.0--canary.744.
|
|
4
|
+
"version": "2.0.0--canary.744.7e3ee98.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@aws-sdk/client-apigatewaymanagementapi": "^3.588.0",
|
|
7
7
|
"@aws-sdk/client-kms": "^3.588.0",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"@aws-sdk/client-sqs": "^3.588.0",
|
|
12
12
|
"@aws-sdk/client-ssm": "^3.588.0",
|
|
13
13
|
"@aws-sdk/s3-request-presigner": "^3.588.0",
|
|
14
|
-
"@friggframework/schemas": "2.0.0--canary.744.
|
|
14
|
+
"@friggframework/schemas": "2.0.0--canary.744.7e3ee98.0",
|
|
15
15
|
"@hapi/boom": "^10.0.1",
|
|
16
16
|
"@opentelemetry/api": "^1.9.1",
|
|
17
17
|
"@opentelemetry/context-async-hooks": "^2.9.0",
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@friggframework/eslint-config": "2.0.0--canary.744.
|
|
53
|
-
"@friggframework/prettier-config": "2.0.0--canary.744.
|
|
54
|
-
"@friggframework/test": "2.0.0--canary.744.
|
|
52
|
+
"@friggframework/eslint-config": "2.0.0--canary.744.7e3ee98.0",
|
|
53
|
+
"@friggframework/prettier-config": "2.0.0--canary.744.7e3ee98.0",
|
|
54
|
+
"@friggframework/test": "2.0.0--canary.744.7e3ee98.0",
|
|
55
55
|
"@prisma/client": "^6.19.3",
|
|
56
56
|
"@types/lodash": "4.17.15",
|
|
57
57
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
"publishConfig": {
|
|
94
94
|
"access": "public"
|
|
95
95
|
},
|
|
96
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "7e3ee98f0418c7247a4c166826c0b561eef27741"
|
|
97
97
|
}
|