@friggframework/core 2.0.0--canary.490.dfd8df5.0 → 2.0.0--canary.490.1d4d68c.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.
- package/credential/repositories/credential-repository-factory.js +11 -13
- package/credential/repositories/{credential-repository-documentdb.js → credential-repository-mongodb-native.js} +4 -4
- package/database/repositories/health-check-repository-factory.js +10 -33
- package/database/repositories/{health-check-repository-documentdb.js → health-check-repository-mongodb-native.js} +4 -4
- package/integrations/repositories/integration-mapping-repository-factory.js +5 -30
- package/integrations/repositories/{integration-mapping-repository-documentdb.js → integration-mapping-repository-mongodb-native.js} +4 -4
- package/integrations/repositories/integration-repository-factory.js +11 -12
- package/integrations/repositories/{integration-repository-documentdb.js → integration-repository-mongodb-native.js} +12 -4
- package/integrations/repositories/process-repository-factory.js +5 -30
- package/integrations/repositories/{process-repository-documentdb.js → process-repository-mongodb-native.js} +4 -4
- package/modules/repositories/module-repository-factory.js +5 -11
- package/modules/repositories/{module-repository-documentdb.js → module-repository-mongodb-native.js} +4 -4
- package/package.json +5 -5
- package/syncs/repositories/sync-repository-factory.js +5 -11
- package/syncs/repositories/{sync-repository-documentdb.js → sync-repository-mongodb-native.js} +4 -4
- package/token/repositories/token-repository-factory.js +5 -11
- package/token/repositories/{token-repository-documentdb.js → token-repository-mongodb-native.js} +4 -4
- package/user/repositories/user-repository-factory.js +7 -32
- package/user/repositories/{user-repository-documentdb.js → user-repository-mongodb-native.js} +4 -4
- package/websocket/repositories/websocket-connection-repository-factory.js +5 -11
- package/websocket/repositories/{websocket-connection-repository-documentdb.js → websocket-connection-repository-mongodb-native.js} +4 -4
- package/credential/repositories/credential-repository-mongo.js +0 -311
- package/integrations/repositories/integration-mapping-repository-mongo.js +0 -165
- package/integrations/repositories/integration-repository-mongo.js +0 -307
- package/integrations/repositories/process-repository-mongo.js +0 -194
- package/modules/repositories/module-repository-mongo.js +0 -381
- package/syncs/repositories/sync-repository-mongo.js +0 -243
- package/token/repositories/token-repository-mongo.js +0 -216
- package/user/repositories/user-repository-mongo.js +0 -295
- package/websocket/repositories/websocket-connection-repository-mongo.js +0 -160
|
@@ -1,52 +1,27 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const { UserRepositoryMongoDBNative } = require('./user-repository-mongodb-native');
|
|
2
2
|
const { UserRepositoryPostgres } = require('./user-repository-postgres');
|
|
3
|
-
const
|
|
4
|
-
const { isDocumentDB } = require('../../database/utils/documentdb-compatibility');
|
|
5
|
-
const databaseConfig = require('../../database/config');
|
|
3
|
+
const config = require('../../database/config');
|
|
6
4
|
|
|
7
|
-
/**
|
|
8
|
-
* User Repository Factory
|
|
9
|
-
* Creates the appropriate repository adapter based on database type
|
|
10
|
-
*
|
|
11
|
-
* Database-specific implementations:
|
|
12
|
-
* - MongoDB: Uses String IDs (ObjectId), no conversion needed
|
|
13
|
-
* - PostgreSQL: Uses Int IDs, converts String ↔ Int
|
|
14
|
-
*
|
|
15
|
-
* All repository methods return String IDs regardless of database type,
|
|
16
|
-
* ensuring application layer consistency.
|
|
17
|
-
*
|
|
18
|
-
* Usage:
|
|
19
|
-
* ```javascript
|
|
20
|
-
* const repository = createUserRepository();
|
|
21
|
-
* const user = await repository.findUserById(id); // ID is string
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @returns {UserRepositoryInterface} Configured repository adapter
|
|
25
|
-
*/
|
|
26
5
|
function createUserRepository() {
|
|
27
|
-
|
|
28
|
-
return new UserRepositoryDocumentDB();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const dbType = databaseConfig.DB_TYPE;
|
|
6
|
+
const dbType = config.DB_TYPE;
|
|
32
7
|
|
|
33
8
|
switch (dbType) {
|
|
34
9
|
case 'mongodb':
|
|
35
|
-
|
|
10
|
+
case 'documentdb':
|
|
11
|
+
return new UserRepositoryMongoDBNative();
|
|
36
12
|
|
|
37
13
|
case 'postgresql':
|
|
38
14
|
return new UserRepositoryPostgres();
|
|
39
15
|
|
|
40
16
|
default:
|
|
41
17
|
throw new Error(
|
|
42
|
-
`Unsupported
|
|
18
|
+
`Unsupported database type: ${dbType}. Supported values: 'mongodb', 'documentdb', 'postgresql'`
|
|
43
19
|
);
|
|
44
20
|
}
|
|
45
21
|
}
|
|
46
22
|
|
|
47
23
|
module.exports = {
|
|
48
24
|
createUserRepository,
|
|
49
|
-
|
|
25
|
+
UserRepositoryMongoDBNative,
|
|
50
26
|
UserRepositoryPostgres,
|
|
51
|
-
UserRepositoryDocumentDB,
|
|
52
27
|
};
|
package/user/repositories/{user-repository-documentdb.js → user-repository-mongodb-native.js}
RENAMED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
const { ObjectId } = require('mongodb');
|
|
2
2
|
const bcrypt = require('bcryptjs');
|
|
3
|
-
const {
|
|
3
|
+
const { BaseRepositoryMongoDBNative } = require('../../database/repositories/base-repository-documentdb');
|
|
4
4
|
const { UserRepositoryInterface } = require('./user-repository-interface');
|
|
5
5
|
const { createTokenRepository } = require('../../token/repositories/token-repository-factory');
|
|
6
6
|
|
|
7
7
|
const BCRYPT_ROUNDS = 10;
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class UserRepositoryMongoDBNative extends UserRepositoryInterface {
|
|
10
10
|
constructor() {
|
|
11
11
|
super();
|
|
12
|
-
this._base = new
|
|
12
|
+
this._base = new BaseRepositoryMongoDBNative('User', 'User');
|
|
13
13
|
this.tokenRepository = createTokenRepository();
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -134,5 +134,5 @@ class UserRepositoryDocumentDB extends UserRepositoryInterface {
|
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
module.exports = {
|
|
137
|
+
module.exports = { UserRepositoryMongoDBNative };
|
|
138
138
|
|
|
@@ -1,33 +1,27 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const { WebsocketConnectionRepositoryMongoDBNative } = require('./websocket-connection-repository-mongodb-native');
|
|
2
2
|
const { WebsocketConnectionRepositoryPostgres } = require('./websocket-connection-repository-postgres');
|
|
3
|
-
const { WebsocketConnectionRepositoryDocumentDB } = require('./websocket-connection-repository-documentdb');
|
|
4
|
-
const { isDocumentDB } = require('../../database/utils/documentdb-compatibility');
|
|
5
3
|
const config = require('../../database/config');
|
|
6
4
|
|
|
7
5
|
function createWebsocketConnectionRepository() {
|
|
8
|
-
if (isDocumentDB()) {
|
|
9
|
-
return new WebsocketConnectionRepositoryDocumentDB();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
6
|
const dbType = config.DB_TYPE;
|
|
13
7
|
|
|
14
8
|
switch (dbType) {
|
|
15
9
|
case 'mongodb':
|
|
16
|
-
|
|
10
|
+
case 'documentdb':
|
|
11
|
+
return new WebsocketConnectionRepositoryMongoDBNative();
|
|
17
12
|
|
|
18
13
|
case 'postgresql':
|
|
19
14
|
return new WebsocketConnectionRepositoryPostgres();
|
|
20
15
|
|
|
21
16
|
default:
|
|
22
17
|
throw new Error(
|
|
23
|
-
`Unsupported database type: ${dbType}. Supported values: 'mongodb', 'postgresql'`
|
|
18
|
+
`Unsupported database type: ${dbType}. Supported values: 'mongodb', 'documentdb', 'postgresql'`
|
|
24
19
|
);
|
|
25
20
|
}
|
|
26
21
|
}
|
|
27
22
|
|
|
28
23
|
module.exports = {
|
|
29
24
|
createWebsocketConnectionRepository,
|
|
30
|
-
|
|
25
|
+
WebsocketConnectionRepositoryMongoDBNative,
|
|
31
26
|
WebsocketConnectionRepositoryPostgres,
|
|
32
|
-
WebsocketConnectionRepositoryDocumentDB,
|
|
33
27
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const { ObjectId } = require('mongodb');
|
|
2
|
-
const {
|
|
2
|
+
const { BaseRepositoryMongoDBNative } = require('../../database/repositories/base-repository-documentdb');
|
|
3
3
|
const { WebsocketConnectionRepositoryInterface } = require('./websocket-connection-repository-interface');
|
|
4
4
|
|
|
5
|
-
class
|
|
5
|
+
class WebsocketConnectionRepositoryMongoDBNative extends WebsocketConnectionRepositoryInterface {
|
|
6
6
|
constructor() {
|
|
7
7
|
super();
|
|
8
|
-
this._base = new
|
|
8
|
+
this._base = new BaseRepositoryMongoDBNative('WebsocketConnection', 'WebsocketConnection');
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
get collection() {
|
|
@@ -50,5 +50,5 @@ class WebsocketConnectionRepositoryDocumentDB extends WebsocketConnectionReposit
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
module.exports = {
|
|
53
|
+
module.exports = { WebsocketConnectionRepositoryMongoDBNative };
|
|
54
54
|
|
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
const { prisma } = require('../../database/prisma');
|
|
2
|
-
const {
|
|
3
|
-
CredentialRepositoryInterface,
|
|
4
|
-
} = require('./credential-repository-interface');
|
|
5
|
-
const { BaseRepositoryMongoDB } = require('../../database/repositories/base-repository-mongodb');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* MongoDB Credential Repository Adapter
|
|
9
|
-
* Handles OAuth credentials and API tokens persistence with MongoDB
|
|
10
|
-
*
|
|
11
|
-
* MongoDB-specific characteristics:
|
|
12
|
-
* - Uses String IDs (ObjectId)
|
|
13
|
-
* - No ID conversion needed (IDs are already strings)
|
|
14
|
-
* - Dynamic schema support via JSON field
|
|
15
|
-
*/
|
|
16
|
-
class CredentialRepositoryMongo extends CredentialRepositoryInterface {
|
|
17
|
-
constructor() {
|
|
18
|
-
super();
|
|
19
|
-
|
|
20
|
-
// Use MongoDB base repository for DocumentDB compatibility
|
|
21
|
-
const mongoBase = new BaseRepositoryMongoDB({ prismaClient: prisma });
|
|
22
|
-
this.prisma = mongoBase.prisma;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Find credential by ID
|
|
27
|
-
* Replaces: Credential.findById(id)
|
|
28
|
-
*
|
|
29
|
-
* @param {string} id - Credential ID
|
|
30
|
-
* @returns {Promise<Object|null>} Credential object or null
|
|
31
|
-
*/
|
|
32
|
-
async findCredentialById(id) {
|
|
33
|
-
const credential = await this.prisma.credential.findUnique({
|
|
34
|
-
where: { id },
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
if (!credential) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Extract data from JSON field
|
|
42
|
-
const data = credential.data || {};
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
_id: credential.id,
|
|
46
|
-
id: credential.id,
|
|
47
|
-
user: credential.userId,
|
|
48
|
-
userId: credential.userId,
|
|
49
|
-
externalId: credential.externalId,
|
|
50
|
-
authIsValid: credential.authIsValid,
|
|
51
|
-
...data, // Spread OAuth tokens from JSON field
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Update authentication status
|
|
57
|
-
* Replaces: Credential.updateOne({ _id: credentialId }, { $set: { authIsValid } })
|
|
58
|
-
*
|
|
59
|
-
* @param {string} credentialId - Credential ID
|
|
60
|
-
* @param {boolean} authIsValid - Authentication validity status
|
|
61
|
-
* @returns {Promise<Object>} Update result
|
|
62
|
-
*/
|
|
63
|
-
async updateAuthenticationStatus(credentialId, authIsValid) {
|
|
64
|
-
await this.prisma.credential.update({
|
|
65
|
-
where: { id: credentialId },
|
|
66
|
-
data: { authIsValid },
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
return { acknowledged: true, modifiedCount: 1 };
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Permanently remove a credential document
|
|
74
|
-
* Replaces: Credential.deleteOne({ _id: credentialId })
|
|
75
|
-
*
|
|
76
|
-
* @param {string} credentialId - Credential ID
|
|
77
|
-
* @returns {Promise<Object>} Deletion result
|
|
78
|
-
*/
|
|
79
|
-
async deleteCredentialById(credentialId) {
|
|
80
|
-
try {
|
|
81
|
-
await this.prisma.credential.delete({
|
|
82
|
-
where: { id: credentialId },
|
|
83
|
-
});
|
|
84
|
-
return { acknowledged: true, deletedCount: 1 };
|
|
85
|
-
} catch (error) {
|
|
86
|
-
if (error.code === 'P2025') {
|
|
87
|
-
// Record not found
|
|
88
|
-
return { acknowledged: true, deletedCount: 0 };
|
|
89
|
-
}
|
|
90
|
-
throw error;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Create or update credential matching identifiers
|
|
96
|
-
* Replaces: Credential.findOneAndUpdate(query, update, { upsert: true })
|
|
97
|
-
*
|
|
98
|
-
* @param {{identifiers: Object, details: Object}} credentialDetails
|
|
99
|
-
* @returns {Promise<Object>} The persisted credential
|
|
100
|
-
*/
|
|
101
|
-
async upsertCredential(credentialDetails) {
|
|
102
|
-
const { identifiers, details } = credentialDetails;
|
|
103
|
-
if (!identifiers)
|
|
104
|
-
throw new Error('identifiers required to upsert credential');
|
|
105
|
-
|
|
106
|
-
if (!identifiers.user && !identifiers.userId) {
|
|
107
|
-
throw new Error('user or userId required in identifiers');
|
|
108
|
-
}
|
|
109
|
-
if (!identifiers.externalId) {
|
|
110
|
-
throw new Error(
|
|
111
|
-
'externalId required in identifiers to prevent credential collision. ' +
|
|
112
|
-
'When multiple credentials exist for the same user, both userId and externalId ' +
|
|
113
|
-
'are needed to uniquely identify which credential to update.'
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Build where clause from identifiers
|
|
118
|
-
const where = this._convertIdentifiersToWhere(identifiers);
|
|
119
|
-
|
|
120
|
-
// Separate schema fields from dynamic OAuth data
|
|
121
|
-
const {
|
|
122
|
-
user,
|
|
123
|
-
userId,
|
|
124
|
-
externalId,
|
|
125
|
-
authIsValid,
|
|
126
|
-
|
|
127
|
-
...oauthData
|
|
128
|
-
} = details;
|
|
129
|
-
|
|
130
|
-
// Find existing credential
|
|
131
|
-
const existing = await this.prisma.credential.findFirst({ where });
|
|
132
|
-
|
|
133
|
-
if (existing) {
|
|
134
|
-
// Update existing - merge OAuth data into existing data JSON
|
|
135
|
-
const mergedData = { ...(existing.data || {}), ...oauthData };
|
|
136
|
-
|
|
137
|
-
const updated = await this.prisma.credential.update({
|
|
138
|
-
where: { id: existing.id },
|
|
139
|
-
data: {
|
|
140
|
-
userId: userId || user || existing.userId,
|
|
141
|
-
externalId:
|
|
142
|
-
externalId !== undefined
|
|
143
|
-
? externalId
|
|
144
|
-
: existing.externalId,
|
|
145
|
-
authIsValid:
|
|
146
|
-
authIsValid !== undefined
|
|
147
|
-
? authIsValid
|
|
148
|
-
: existing.authIsValid,
|
|
149
|
-
data: mergedData,
|
|
150
|
-
},
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
return {
|
|
154
|
-
id: updated.id,
|
|
155
|
-
externalId: updated.externalId,
|
|
156
|
-
userId: updated.userId,
|
|
157
|
-
authIsValid: updated.authIsValid,
|
|
158
|
-
...(updated.data || {}),
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Create new credential
|
|
163
|
-
// DocumentDB compatibility handled by BaseRepositoryMongoDB wrapper
|
|
164
|
-
const created = await this.prisma.credential.create({
|
|
165
|
-
data: {
|
|
166
|
-
userId: userId || user,
|
|
167
|
-
externalId,
|
|
168
|
-
authIsValid: authIsValid,
|
|
169
|
-
data: oauthData,
|
|
170
|
-
},
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
return {
|
|
174
|
-
id: created.id,
|
|
175
|
-
externalId: created.externalId,
|
|
176
|
-
userId: created.userId,
|
|
177
|
-
authIsValid: created.authIsValid,
|
|
178
|
-
...(created.data || {}),
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Find a credential by filter criteria
|
|
184
|
-
* Replaces: Credential.findOne(query)
|
|
185
|
-
*
|
|
186
|
-
* @param {Object} filter
|
|
187
|
-
* @param {string} [filter.userId] - User ID
|
|
188
|
-
* @param {string} [filter.externalId] - External ID
|
|
189
|
-
* @param {string} [filter.credentialId] - Credential ID
|
|
190
|
-
* @returns {Promise<Object|null>} Credential object or null if not found
|
|
191
|
-
*/
|
|
192
|
-
async findCredential(filter) {
|
|
193
|
-
const where = this._convertFilterToWhere(filter);
|
|
194
|
-
|
|
195
|
-
const credential = await this.prisma.credential.findFirst({
|
|
196
|
-
where,
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
if (!credential) {
|
|
200
|
-
return null;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const data = credential.data || {};
|
|
204
|
-
|
|
205
|
-
return {
|
|
206
|
-
id: credential.id,
|
|
207
|
-
userId: credential.userId,
|
|
208
|
-
externalId: credential.externalId,
|
|
209
|
-
authIsValid: credential.authIsValid,
|
|
210
|
-
access_token: data.access_token,
|
|
211
|
-
refresh_token: data.refresh_token,
|
|
212
|
-
domain: data.domain,
|
|
213
|
-
...data,
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Update a credential by ID
|
|
219
|
-
* Replaces: Credential.findByIdAndUpdate(credentialId, { $set: updates })
|
|
220
|
-
*
|
|
221
|
-
* @param {string} credentialId - Credential ID
|
|
222
|
-
* @param {Object} updates - Fields to update
|
|
223
|
-
* @returns {Promise<Object|null>} Updated credential object or null if not found
|
|
224
|
-
*/
|
|
225
|
-
async updateCredential(credentialId, updates) {
|
|
226
|
-
// Get existing credential to merge OAuth data
|
|
227
|
-
const existing = await this.prisma.credential.findUnique({
|
|
228
|
-
where: { id: credentialId },
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
if (!existing) {
|
|
232
|
-
return null;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// Separate schema fields from OAuth data
|
|
236
|
-
const {
|
|
237
|
-
user,
|
|
238
|
-
userId,
|
|
239
|
-
externalId,
|
|
240
|
-
authIsValid,
|
|
241
|
-
|
|
242
|
-
...oauthData
|
|
243
|
-
} = updates;
|
|
244
|
-
|
|
245
|
-
// Merge OAuth data with existing
|
|
246
|
-
const mergedData = { ...(existing.data || {}), ...oauthData };
|
|
247
|
-
|
|
248
|
-
const updated = await this.prisma.credential.update({
|
|
249
|
-
where: { id: credentialId },
|
|
250
|
-
data: {
|
|
251
|
-
userId: userId || user || existing.userId,
|
|
252
|
-
externalId:
|
|
253
|
-
externalId !== undefined ? externalId : existing.externalId,
|
|
254
|
-
authIsValid:
|
|
255
|
-
authIsValid !== undefined ? authIsValid : existing.authIsValid,
|
|
256
|
-
data: mergedData,
|
|
257
|
-
},
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
const data = updated.data || {};
|
|
261
|
-
|
|
262
|
-
return {
|
|
263
|
-
id: updated.id,
|
|
264
|
-
userId: updated.userId,
|
|
265
|
-
externalId: updated.externalId,
|
|
266
|
-
authIsValid: updated.authIsValid,
|
|
267
|
-
access_token: data.access_token,
|
|
268
|
-
refresh_token: data.refresh_token,
|
|
269
|
-
domain: data.domain,
|
|
270
|
-
...data,
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Convert identifiers to Prisma where clause
|
|
276
|
-
* @private
|
|
277
|
-
* @param {Object} identifiers - Identifier fields
|
|
278
|
-
* @returns {Object} Prisma where clause
|
|
279
|
-
*/
|
|
280
|
-
_convertIdentifiersToWhere(identifiers) {
|
|
281
|
-
const where = {};
|
|
282
|
-
|
|
283
|
-
if (identifiers._id) where.id = identifiers._id;
|
|
284
|
-
if (identifiers.id) where.id = identifiers.id;
|
|
285
|
-
if (identifiers.user) where.userId = identifiers.user;
|
|
286
|
-
if (identifiers.userId) where.userId = identifiers.userId;
|
|
287
|
-
if (identifiers.externalId) where.externalId = identifiers.externalId;
|
|
288
|
-
|
|
289
|
-
return where;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Convert filter to Prisma where clause
|
|
294
|
-
* @private
|
|
295
|
-
* @param {Object} filter - Filter criteria
|
|
296
|
-
* @returns {Object} Prisma where clause
|
|
297
|
-
*/
|
|
298
|
-
_convertFilterToWhere(filter) {
|
|
299
|
-
const where = {};
|
|
300
|
-
|
|
301
|
-
if (filter.credentialId) where.id = filter.credentialId;
|
|
302
|
-
if (filter.id) where.id = filter.id;
|
|
303
|
-
if (filter.user) where.userId = filter.user;
|
|
304
|
-
if (filter.userId) where.userId = filter.userId;
|
|
305
|
-
if (filter.externalId) where.externalId = filter.externalId;
|
|
306
|
-
|
|
307
|
-
return where;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
module.exports = { CredentialRepositoryMongo };
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
const { prisma } = require('../../database/prisma');
|
|
2
|
-
const {
|
|
3
|
-
IntegrationMappingRepositoryInterface,
|
|
4
|
-
} = require('./integration-mapping-repository-interface');
|
|
5
|
-
const { BaseRepositoryMongoDB } = require('../../database/repositories/base-repository-mongodb');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* MongoDB Integration Mapping Repository Adapter
|
|
9
|
-
* Handles persistence of integration mappings used for data transformation
|
|
10
|
-
*
|
|
11
|
-
* MongoDB-specific characteristics:
|
|
12
|
-
* - Uses String IDs (ObjectId)
|
|
13
|
-
* - No ID conversion needed (IDs are already strings)
|
|
14
|
-
* - mapping data stored in JSON field
|
|
15
|
-
*/
|
|
16
|
-
class IntegrationMappingRepositoryMongo extends IntegrationMappingRepositoryInterface {
|
|
17
|
-
constructor() {
|
|
18
|
-
super();
|
|
19
|
-
|
|
20
|
-
// Use MongoDB base repository for DocumentDB compatibility
|
|
21
|
-
const mongoBase = new BaseRepositoryMongoDB({ prismaClient: prisma });
|
|
22
|
-
this.prisma = mongoBase.prisma;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Convert any value to string (handles null/undefined)
|
|
27
|
-
* @private
|
|
28
|
-
* @param {*} value - Value to convert
|
|
29
|
-
* @returns {string|null|undefined} String value or null/undefined
|
|
30
|
-
*/
|
|
31
|
-
_toString(value) {
|
|
32
|
-
if (value === null || value === undefined) return value;
|
|
33
|
-
return String(value);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Find mapping by integration ID and source ID
|
|
38
|
-
* Replaces: IntegrationMapping.findBy(integrationId, sourceId)
|
|
39
|
-
*
|
|
40
|
-
* @param {string} integrationId - The integration ID
|
|
41
|
-
* @param {string} sourceId - The source ID for lookup
|
|
42
|
-
* @returns {Promise<Object|null>} The mapping object with string IDs or null
|
|
43
|
-
*/
|
|
44
|
-
async findMappingBy(integrationId, sourceId) {
|
|
45
|
-
return await this.prisma.integrationMapping.findFirst({
|
|
46
|
-
where: {
|
|
47
|
-
integrationId,
|
|
48
|
-
sourceId: this._toString(sourceId),
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Create or update a mapping
|
|
55
|
-
* Replaces: IntegrationMapping.upsert(integrationId, sourceId, mapping)
|
|
56
|
-
*
|
|
57
|
-
* @param {string} integrationId - The integration ID
|
|
58
|
-
* @param {string} sourceId - The source ID for lookup
|
|
59
|
-
* @param {Object} mapping - The mapping data
|
|
60
|
-
* @returns {Promise<Object>} The created or updated mapping document with string IDs
|
|
61
|
-
*/
|
|
62
|
-
async upsertMapping(integrationId, sourceId, mapping) {
|
|
63
|
-
return await this.prisma.integrationMapping.upsert({
|
|
64
|
-
where: {
|
|
65
|
-
integrationId_sourceId: {
|
|
66
|
-
integrationId,
|
|
67
|
-
sourceId: this._toString(sourceId),
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
update: {
|
|
71
|
-
mapping,
|
|
72
|
-
},
|
|
73
|
-
create: {
|
|
74
|
-
integrationId,
|
|
75
|
-
sourceId: this._toString(sourceId),
|
|
76
|
-
mapping,
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Find all mappings for an integration
|
|
83
|
-
* Replaces: IntegrationMapping.find({ integration: integrationId })
|
|
84
|
-
*
|
|
85
|
-
* @param {string} integrationId - The integration ID
|
|
86
|
-
* @returns {Promise<Array>} Array of mapping documents with string IDs
|
|
87
|
-
*/
|
|
88
|
-
async findMappingsByIntegration(integrationId) {
|
|
89
|
-
return await this.prisma.integrationMapping.findMany({
|
|
90
|
-
where: { integrationId },
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Delete a mapping by integration and source ID
|
|
96
|
-
* Replaces: IntegrationMapping.deleteOne({ integration, sourceId })
|
|
97
|
-
*
|
|
98
|
-
* @param {string} integrationId - The integration ID
|
|
99
|
-
* @param {string} sourceId - The source ID
|
|
100
|
-
* @returns {Promise<Object>} The deletion result
|
|
101
|
-
*/
|
|
102
|
-
async deleteMapping(integrationId, sourceId) {
|
|
103
|
-
try {
|
|
104
|
-
await this.prisma.integrationMapping.delete({
|
|
105
|
-
where: {
|
|
106
|
-
integrationId_sourceId: {
|
|
107
|
-
integrationId,
|
|
108
|
-
sourceId: this._toString(sourceId),
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
return { acknowledged: true, deletedCount: 1 };
|
|
113
|
-
} catch (error) {
|
|
114
|
-
if (error.code === 'P2025') {
|
|
115
|
-
// Record not found
|
|
116
|
-
return { acknowledged: true, deletedCount: 0 };
|
|
117
|
-
}
|
|
118
|
-
throw error;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Delete all mappings for an integration
|
|
124
|
-
* Replaces: IntegrationMapping.deleteMany({ integration: integrationId })
|
|
125
|
-
*
|
|
126
|
-
* @param {string} integrationId - The integration ID
|
|
127
|
-
* @returns {Promise<Object>} The deletion result
|
|
128
|
-
*/
|
|
129
|
-
async deleteMappingsByIntegration(integrationId) {
|
|
130
|
-
const result = await this.prisma.integrationMapping.deleteMany({
|
|
131
|
-
where: { integrationId },
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
return {
|
|
135
|
-
acknowledged: true,
|
|
136
|
-
deletedCount: result.count,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Find mapping by ID
|
|
142
|
-
* @param {string} id - Mapping ID
|
|
143
|
-
* @returns {Promise<Object|null>} Mapping object with string IDs or null
|
|
144
|
-
*/
|
|
145
|
-
async findMappingById(id) {
|
|
146
|
-
return await this.prisma.integrationMapping.findUnique({
|
|
147
|
-
where: { id },
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Update mapping by ID
|
|
153
|
-
* @param {string} id - Mapping ID
|
|
154
|
-
* @param {Object} updates - Fields to update
|
|
155
|
-
* @returns {Promise<Object>} Updated mapping object with string IDs
|
|
156
|
-
*/
|
|
157
|
-
async updateMapping(id, updates) {
|
|
158
|
-
return await this.prisma.integrationMapping.update({
|
|
159
|
-
where: { id },
|
|
160
|
-
data: updates,
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
module.exports = { IntegrationMappingRepositoryMongo };
|