@friggframework/core 2.0.0-next.68 → 2.0.0-next.69
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.
|
@@ -111,8 +111,7 @@ class CredentialRepositoryPostgres extends CredentialRepositoryInterface {
|
|
|
111
111
|
if (!identifiers)
|
|
112
112
|
throw new Error('identifiers required to upsert credential');
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
if (!identifiers.userId && !identifiers.user) {
|
|
114
|
+
if (!identifiers.userId) {
|
|
116
115
|
throw new Error('userId required in identifiers');
|
|
117
116
|
}
|
|
118
117
|
if (!identifiers.externalId) {
|
|
@@ -155,7 +154,7 @@ class CredentialRepositoryPostgres extends CredentialRepositoryInterface {
|
|
|
155
154
|
|
|
156
155
|
const created = await this.prisma.credential.create({
|
|
157
156
|
data: {
|
|
158
|
-
// Use userId from where clause
|
|
157
|
+
// Use userId from where clause
|
|
159
158
|
userId: where.userId,
|
|
160
159
|
externalId,
|
|
161
160
|
authIsValid: authIsValid,
|
|
@@ -259,11 +258,8 @@ class CredentialRepositoryPostgres extends CredentialRepositoryInterface {
|
|
|
259
258
|
const where = {};
|
|
260
259
|
|
|
261
260
|
if (identifiers.id) where.id = this._convertId(identifiers.id);
|
|
262
|
-
// Support both userId (preferred) and user (legacy) for backward compatibility
|
|
263
261
|
if (identifiers.userId)
|
|
264
262
|
where.userId = this._convertId(identifiers.userId);
|
|
265
|
-
else if (identifiers.user)
|
|
266
|
-
where.userId = this._convertId(identifiers.user);
|
|
267
263
|
if (identifiers.externalId) where.externalId = identifiers.externalId;
|
|
268
264
|
|
|
269
265
|
return where;
|
|
@@ -46,7 +46,6 @@ class CredentialRepository extends CredentialRepositoryInterface {
|
|
|
46
46
|
return {
|
|
47
47
|
_id: credential.id,
|
|
48
48
|
id: credential.id,
|
|
49
|
-
user: credential.userId,
|
|
50
49
|
userId: credential.userId,
|
|
51
50
|
externalId: credential.externalId,
|
|
52
51
|
authIsValid: credential.authIsValid,
|
|
@@ -105,18 +104,24 @@ class CredentialRepository extends CredentialRepositoryInterface {
|
|
|
105
104
|
if (!identifiers)
|
|
106
105
|
throw new Error('identifiers required to upsert credential');
|
|
107
106
|
|
|
107
|
+
if (!identifiers.userId) {
|
|
108
|
+
throw new Error('userId required in identifiers');
|
|
109
|
+
}
|
|
110
|
+
if (!identifiers.externalId) {
|
|
111
|
+
throw new Error(
|
|
112
|
+
'externalId required in identifiers to prevent credential collision. ' +
|
|
113
|
+
'When multiple credentials exist for the same user, both userId and externalId ' +
|
|
114
|
+
'are needed to uniquely identify which credential to update.'
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
108
118
|
// Build where clause from identifiers
|
|
109
119
|
const where = this._convertIdentifiersToWhere(identifiers);
|
|
110
120
|
|
|
121
|
+
const { externalId } = identifiers;
|
|
122
|
+
|
|
111
123
|
// Separate schema fields from dynamic OAuth data
|
|
112
|
-
const {
|
|
113
|
-
user,
|
|
114
|
-
userId,
|
|
115
|
-
externalId,
|
|
116
|
-
authIsValid,
|
|
117
|
-
|
|
118
|
-
...oauthData
|
|
119
|
-
} = details;
|
|
124
|
+
const { authIsValid, ...oauthData } = details;
|
|
120
125
|
|
|
121
126
|
// Find existing credential
|
|
122
127
|
const existing = await this.prisma.credential.findFirst({ where });
|
|
@@ -128,11 +133,8 @@ class CredentialRepository extends CredentialRepositoryInterface {
|
|
|
128
133
|
const updated = await this.prisma.credential.update({
|
|
129
134
|
where: { id: existing.id },
|
|
130
135
|
data: {
|
|
131
|
-
userId:
|
|
132
|
-
externalId:
|
|
133
|
-
externalId !== undefined
|
|
134
|
-
? externalId
|
|
135
|
-
: existing.externalId,
|
|
136
|
+
userId: existing.userId,
|
|
137
|
+
externalId: existing.externalId,
|
|
136
138
|
authIsValid:
|
|
137
139
|
authIsValid !== undefined
|
|
138
140
|
? authIsValid
|
|
@@ -153,10 +155,9 @@ class CredentialRepository extends CredentialRepositoryInterface {
|
|
|
153
155
|
// Create new credential
|
|
154
156
|
const created = await this.prisma.credential.create({
|
|
155
157
|
data: {
|
|
156
|
-
userId: userId
|
|
158
|
+
userId: where.userId,
|
|
157
159
|
externalId,
|
|
158
160
|
authIsValid: authIsValid,
|
|
159
|
-
|
|
160
161
|
data: oauthData,
|
|
161
162
|
},
|
|
162
163
|
});
|
|
@@ -225,11 +226,10 @@ class CredentialRepository extends CredentialRepositoryInterface {
|
|
|
225
226
|
|
|
226
227
|
// Separate schema fields from OAuth data
|
|
227
228
|
const {
|
|
228
|
-
user,
|
|
229
229
|
userId,
|
|
230
230
|
externalId,
|
|
231
231
|
authIsValid,
|
|
232
|
-
|
|
232
|
+
|
|
233
233
|
...oauthData
|
|
234
234
|
} = updates;
|
|
235
235
|
|
|
@@ -239,7 +239,7 @@ class CredentialRepository extends CredentialRepositoryInterface {
|
|
|
239
239
|
const updated = await this.prisma.credential.update({
|
|
240
240
|
where: { id: credentialId },
|
|
241
241
|
data: {
|
|
242
|
-
userId: userId ||
|
|
242
|
+
userId: userId || existing.userId,
|
|
243
243
|
externalId:
|
|
244
244
|
externalId !== undefined ? externalId : existing.externalId,
|
|
245
245
|
authIsValid:
|
|
@@ -273,7 +273,6 @@ class CredentialRepository extends CredentialRepositoryInterface {
|
|
|
273
273
|
|
|
274
274
|
if (identifiers._id) where.id = identifiers._id;
|
|
275
275
|
if (identifiers.id) where.id = identifiers.id;
|
|
276
|
-
if (identifiers.user) where.userId = identifiers.user;
|
|
277
276
|
if (identifiers.userId) where.userId = identifiers.userId;
|
|
278
277
|
if (identifiers.externalId) where.externalId = identifiers.externalId;
|
|
279
278
|
|
|
@@ -291,7 +290,6 @@ class CredentialRepository extends CredentialRepositoryInterface {
|
|
|
291
290
|
|
|
292
291
|
if (filter.credentialId) where.id = filter.credentialId;
|
|
293
292
|
if (filter.id) where.id = filter.id;
|
|
294
|
-
if (filter.user) where.userId = filter.user;
|
|
295
293
|
if (filter.userId) where.userId = filter.userId;
|
|
296
294
|
if (filter.externalId) where.externalId = filter.externalId;
|
|
297
295
|
|
|
@@ -279,6 +279,15 @@ class OAuth2Requester extends Requester {
|
|
|
279
279
|
*/
|
|
280
280
|
async refreshAuth() {
|
|
281
281
|
try {
|
|
282
|
+
console.log('[OAuth2Requester.refreshAuth] Starting token refresh', {
|
|
283
|
+
grant_type: this.grant_type,
|
|
284
|
+
has_refresh_token: !!this.refresh_token,
|
|
285
|
+
has_client_id: !!this.client_id,
|
|
286
|
+
has_client_secret: !!this.client_secret,
|
|
287
|
+
has_token_uri: !!this.tokenUri,
|
|
288
|
+
tokenUri: this.tokenUri,
|
|
289
|
+
});
|
|
290
|
+
|
|
282
291
|
if (this.grant_type !== 'client_credentials') {
|
|
283
292
|
await this.refreshAccessToken({
|
|
284
293
|
refresh_token: this.refresh_token,
|
|
@@ -286,8 +295,15 @@ class OAuth2Requester extends Requester {
|
|
|
286
295
|
} else {
|
|
287
296
|
await this.getTokenFromClientCredentials();
|
|
288
297
|
}
|
|
298
|
+
console.log('[OAuth2Requester.refreshAuth] Token refresh succeeded');
|
|
289
299
|
return true;
|
|
290
|
-
} catch {
|
|
300
|
+
} catch (error) {
|
|
301
|
+
console.error('[OAuth2Requester.refreshAuth] Token refresh failed', {
|
|
302
|
+
error_message: error?.message,
|
|
303
|
+
error_name: error?.name,
|
|
304
|
+
response_status: error?.response?.status,
|
|
305
|
+
response_data: error?.response?.data,
|
|
306
|
+
});
|
|
291
307
|
await this.notify(this.DLGT_INVALID_AUTH);
|
|
292
308
|
return false;
|
|
293
309
|
}
|
|
@@ -20,7 +20,7 @@ const Definition = {
|
|
|
20
20
|
getEntityDetails: async function (api, callbackParams, tokenResponse, userId) {
|
|
21
21
|
const userDetails = await api.getUserDetails();
|
|
22
22
|
return {
|
|
23
|
-
identifiers: { externalId: userDetails.portalId,
|
|
23
|
+
identifiers: { externalId: userDetails.portalId, userId },
|
|
24
24
|
details: { name: userDetails.hub_domain },
|
|
25
25
|
}
|
|
26
26
|
},
|
|
@@ -33,7 +33,7 @@ const Definition = {
|
|
|
33
33
|
getCredentialDetails: async function (api, userId) {
|
|
34
34
|
const userDetails = await api.getUserDetails();
|
|
35
35
|
return {
|
|
36
|
-
identifiers: { externalId: userDetails.portalId,
|
|
36
|
+
identifiers: { externalId: userDetails.portalId, userId },
|
|
37
37
|
details: {}
|
|
38
38
|
};
|
|
39
39
|
},
|
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-next.
|
|
4
|
+
"version": "2.0.0-next.69",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@aws-sdk/client-apigatewaymanagementapi": "^3.588.0",
|
|
7
7
|
"@aws-sdk/client-kms": "^3.588.0",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@friggframework/eslint-config": "2.0.0-next.
|
|
42
|
-
"@friggframework/prettier-config": "2.0.0-next.
|
|
43
|
-
"@friggframework/test": "2.0.0-next.
|
|
41
|
+
"@friggframework/eslint-config": "2.0.0-next.69",
|
|
42
|
+
"@friggframework/prettier-config": "2.0.0-next.69",
|
|
43
|
+
"@friggframework/test": "2.0.0-next.69",
|
|
44
44
|
"@prisma/client": "^6.17.0",
|
|
45
45
|
"@types/lodash": "4.17.15",
|
|
46
46
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"publishConfig": {
|
|
81
81
|
"access": "public"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "018c93f98b5f14786d016a4f621adef10ad27597"
|
|
84
84
|
}
|