@friggframework/core 2.0.0-next.54 → 2.0.0-next.56
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/application/commands/credential-commands.js +1 -1
- package/core/create-handler.js +12 -0
- package/credential/repositories/credential-repository-documentdb.js +81 -77
- package/credential/repositories/credential-repository-mongo.js +16 -54
- package/credential/repositories/credential-repository-postgres.js +14 -41
- package/credential/use-cases/get-credential-for-user.js +7 -3
- package/database/encryption/README.md +126 -21
- package/database/encryption/encryption-schema-registry.js +83 -2
- package/errors/client-safe-error.js +26 -0
- package/errors/fetch-error.js +2 -1
- package/errors/index.js +2 -0
- package/integrations/integration-router.js +6 -6
- package/integrations/repositories/integration-mapping-repository-documentdb.js +178 -33
- package/integrations/repositories/integration-repository-documentdb.js +21 -0
- package/integrations/repositories/process-repository-documentdb.js +143 -41
- package/modules/requester/api-key.js +24 -8
- package/package.json +5 -5
- package/token/repositories/token-repository-documentdb.js +20 -8
- package/token/repositories/token-repository-mongo.js +10 -3
- package/token/repositories/token-repository-postgres.js +10 -3
- package/user/repositories/user-repository-documentdb.js +177 -37
- package/user/repositories/user-repository-mongo.js +3 -2
- package/user/repositories/user-repository-postgres.js +3 -2
- package/user/use-cases/login-user.js +1 -1
|
@@ -12,74 +12,167 @@ const {
|
|
|
12
12
|
const {
|
|
13
13
|
IntegrationMappingRepositoryInterface,
|
|
14
14
|
} = require('./integration-mapping-repository-interface');
|
|
15
|
-
|
|
15
|
+
const {
|
|
16
|
+
DocumentDBEncryptionService,
|
|
17
|
+
} = require('../../database/documentdb-encryption-service');
|
|
16
18
|
class IntegrationMappingRepositoryDocumentDB extends IntegrationMappingRepositoryInterface {
|
|
17
19
|
constructor() {
|
|
18
20
|
super();
|
|
19
21
|
this.prisma = prisma;
|
|
22
|
+
this.encryptionService = new DocumentDBEncryptionService();
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
async findMappingBy(integrationId, sourceId) {
|
|
23
26
|
const filter = this._compositeFilter(integrationId, sourceId);
|
|
24
27
|
const doc = await findOne(this.prisma, 'IntegrationMapping', filter);
|
|
25
|
-
|
|
28
|
+
if (!doc) return null;
|
|
29
|
+
|
|
30
|
+
const decryptedMapping = await this.encryptionService.decryptFields(
|
|
31
|
+
'IntegrationMapping',
|
|
32
|
+
doc
|
|
33
|
+
);
|
|
34
|
+
return this._mapMapping(decryptedMapping);
|
|
26
35
|
}
|
|
27
36
|
|
|
28
37
|
async upsertMapping(integrationId, sourceId, mapping) {
|
|
29
38
|
const filter = this._compositeFilter(integrationId, sourceId);
|
|
30
|
-
const existing = await findOne(
|
|
39
|
+
const existing = await findOne(
|
|
40
|
+
this.prisma,
|
|
41
|
+
'IntegrationMapping',
|
|
42
|
+
filter
|
|
43
|
+
);
|
|
31
44
|
const now = new Date();
|
|
32
45
|
|
|
33
46
|
if (existing) {
|
|
47
|
+
const decryptedExisting =
|
|
48
|
+
await this.encryptionService.decryptFields(
|
|
49
|
+
'IntegrationMapping',
|
|
50
|
+
existing
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const updateDocument = {
|
|
54
|
+
mapping,
|
|
55
|
+
updatedAt: now,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const encryptedUpdate = await this.encryptionService.encryptFields(
|
|
59
|
+
'IntegrationMapping',
|
|
60
|
+
{ mapping: updateDocument.mapping }
|
|
61
|
+
);
|
|
62
|
+
|
|
34
63
|
await updateOne(
|
|
35
64
|
this.prisma,
|
|
36
65
|
'IntegrationMapping',
|
|
37
66
|
{ _id: existing._id },
|
|
38
67
|
{
|
|
39
68
|
$set: {
|
|
40
|
-
mapping,
|
|
41
|
-
updatedAt:
|
|
69
|
+
mapping: encryptedUpdate.mapping,
|
|
70
|
+
updatedAt: updateDocument.updatedAt,
|
|
42
71
|
},
|
|
43
72
|
}
|
|
44
73
|
);
|
|
45
|
-
|
|
46
|
-
|
|
74
|
+
|
|
75
|
+
const updated = await findOne(this.prisma, 'IntegrationMapping', {
|
|
76
|
+
_id: existing._id,
|
|
77
|
+
});
|
|
78
|
+
if (!updated) {
|
|
79
|
+
console.error(
|
|
80
|
+
'[IntegrationMappingRepositoryDocumentDB] Mapping not found after update',
|
|
81
|
+
{
|
|
82
|
+
mappingId: fromObjectId(existing._id),
|
|
83
|
+
integrationId,
|
|
84
|
+
sourceId,
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
throw new Error(
|
|
88
|
+
'Failed to update mapping: Document not found after update. ' +
|
|
89
|
+
'This indicates a database consistency issue.'
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
const decryptedMapping = await this.encryptionService.decryptFields(
|
|
93
|
+
'IntegrationMapping',
|
|
94
|
+
updated
|
|
95
|
+
);
|
|
96
|
+
return this._mapMapping(decryptedMapping);
|
|
47
97
|
}
|
|
48
98
|
|
|
49
|
-
const
|
|
50
|
-
integrationId:
|
|
51
|
-
sourceId:
|
|
99
|
+
const plainDocument = {
|
|
100
|
+
integrationId: integrationId,
|
|
101
|
+
sourceId:
|
|
102
|
+
sourceId === null || sourceId === undefined
|
|
103
|
+
? null
|
|
104
|
+
: String(sourceId),
|
|
52
105
|
mapping,
|
|
53
106
|
createdAt: now,
|
|
54
107
|
updatedAt: now,
|
|
55
108
|
};
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
109
|
+
|
|
110
|
+
const encryptedDocument = await this.encryptionService.encryptFields(
|
|
111
|
+
'IntegrationMapping',
|
|
112
|
+
plainDocument
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const insertedId = await insertOne(
|
|
116
|
+
this.prisma,
|
|
117
|
+
'IntegrationMapping',
|
|
118
|
+
encryptedDocument
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const created = await findOne(this.prisma, 'IntegrationMapping', {
|
|
122
|
+
_id: insertedId,
|
|
123
|
+
});
|
|
124
|
+
if (!created) {
|
|
125
|
+
console.error(
|
|
126
|
+
'[IntegrationMappingRepositoryDocumentDB] Mapping not found after insert',
|
|
127
|
+
{
|
|
128
|
+
insertedId: fromObjectId(insertedId),
|
|
129
|
+
integrationId,
|
|
130
|
+
sourceId,
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
throw new Error(
|
|
134
|
+
'Failed to create mapping: Document not found after insert. ' +
|
|
135
|
+
'This indicates a database consistency issue.'
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
const decryptedMapping = await this.encryptionService.decryptFields(
|
|
139
|
+
'IntegrationMapping',
|
|
140
|
+
created
|
|
141
|
+
);
|
|
142
|
+
return this._mapMapping(decryptedMapping);
|
|
59
143
|
}
|
|
60
144
|
|
|
61
145
|
async findMappingsByIntegration(integrationId) {
|
|
62
146
|
const filter = {};
|
|
63
|
-
|
|
64
|
-
if (integrationObjectId) filter.integrationId = integrationObjectId;
|
|
147
|
+
if (integrationId) filter.integrationId = integrationId;
|
|
65
148
|
const docs = await findMany(this.prisma, 'IntegrationMapping', filter);
|
|
66
|
-
|
|
149
|
+
|
|
150
|
+
const decryptedDocs = await Promise.all(
|
|
151
|
+
docs.map((doc) =>
|
|
152
|
+
this.encryptionService.decryptFields('IntegrationMapping', doc)
|
|
153
|
+
)
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
return decryptedDocs.map((doc) => this._mapMapping(doc));
|
|
67
157
|
}
|
|
68
158
|
|
|
69
159
|
async deleteMapping(integrationId, sourceId) {
|
|
70
160
|
const filter = this._compositeFilter(integrationId, sourceId);
|
|
71
|
-
const result = await deleteOne(
|
|
161
|
+
const result = await deleteOne(
|
|
162
|
+
this.prisma,
|
|
163
|
+
'IntegrationMapping',
|
|
164
|
+
filter
|
|
165
|
+
);
|
|
72
166
|
const deleted = result?.n ?? 0;
|
|
73
167
|
return { acknowledged: true, deletedCount: deleted };
|
|
74
168
|
}
|
|
75
169
|
|
|
76
170
|
async deleteMappingsByIntegration(integrationId) {
|
|
77
|
-
|
|
78
|
-
if (!integrationObjectId) {
|
|
171
|
+
if (!integrationId) {
|
|
79
172
|
return { acknowledged: true, deletedCount: 0 };
|
|
80
173
|
}
|
|
81
174
|
const result = await deleteMany(this.prisma, 'IntegrationMapping', {
|
|
82
|
-
integrationId:
|
|
175
|
+
integrationId: integrationId,
|
|
83
176
|
});
|
|
84
177
|
const deleted = result?.n ?? 0;
|
|
85
178
|
return { acknowledged: true, deletedCount: deleted };
|
|
@@ -88,32 +181,84 @@ class IntegrationMappingRepositoryDocumentDB extends IntegrationMappingRepositor
|
|
|
88
181
|
async findMappingById(id) {
|
|
89
182
|
const objectId = toObjectId(id);
|
|
90
183
|
if (!objectId) return null;
|
|
91
|
-
const doc = await findOne(this.prisma, 'IntegrationMapping', {
|
|
92
|
-
|
|
184
|
+
const doc = await findOne(this.prisma, 'IntegrationMapping', {
|
|
185
|
+
_id: objectId,
|
|
186
|
+
});
|
|
187
|
+
if (!doc) return null;
|
|
188
|
+
|
|
189
|
+
const decryptedMapping = await this.encryptionService.decryptFields(
|
|
190
|
+
'IntegrationMapping',
|
|
191
|
+
doc
|
|
192
|
+
);
|
|
193
|
+
return this._mapMapping(decryptedMapping);
|
|
93
194
|
}
|
|
94
195
|
|
|
95
196
|
async updateMapping(id, updates) {
|
|
96
197
|
const objectId = toObjectId(id);
|
|
97
198
|
if (!objectId) return null;
|
|
199
|
+
|
|
200
|
+
const existing = await findOne(this.prisma, 'IntegrationMapping', {
|
|
201
|
+
_id: objectId,
|
|
202
|
+
});
|
|
203
|
+
if (!existing) return null;
|
|
204
|
+
|
|
205
|
+
const decryptedExisting = await this.encryptionService.decryptFields(
|
|
206
|
+
'IntegrationMapping',
|
|
207
|
+
existing
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
const mergedMapping =
|
|
211
|
+
updates.mapping !== undefined
|
|
212
|
+
? updates.mapping
|
|
213
|
+
: decryptedExisting.mapping;
|
|
214
|
+
|
|
215
|
+
const updateDocument = {
|
|
216
|
+
...updates,
|
|
217
|
+
updatedAt: new Date(),
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
if (mergedMapping !== undefined) {
|
|
221
|
+
const encryptedUpdate = await this.encryptionService.encryptFields(
|
|
222
|
+
'IntegrationMapping',
|
|
223
|
+
{ mapping: mergedMapping }
|
|
224
|
+
);
|
|
225
|
+
updateDocument.mapping = encryptedUpdate.mapping;
|
|
226
|
+
}
|
|
227
|
+
|
|
98
228
|
await updateOne(
|
|
99
229
|
this.prisma,
|
|
100
230
|
'IntegrationMapping',
|
|
101
231
|
{ _id: objectId },
|
|
102
232
|
{
|
|
103
|
-
$set:
|
|
104
|
-
...updates,
|
|
105
|
-
updatedAt: new Date(),
|
|
106
|
-
},
|
|
233
|
+
$set: updateDocument,
|
|
107
234
|
}
|
|
108
235
|
);
|
|
109
|
-
|
|
110
|
-
|
|
236
|
+
|
|
237
|
+
const updated = await findOne(this.prisma, 'IntegrationMapping', {
|
|
238
|
+
_id: objectId,
|
|
239
|
+
});
|
|
240
|
+
if (!updated) {
|
|
241
|
+
console.error(
|
|
242
|
+
'[IntegrationMappingRepositoryDocumentDB] Mapping not found after update',
|
|
243
|
+
{
|
|
244
|
+
mappingId: fromObjectId(objectId),
|
|
245
|
+
}
|
|
246
|
+
);
|
|
247
|
+
throw new Error(
|
|
248
|
+
'Failed to update mapping: Document not found after update. ' +
|
|
249
|
+
'This indicates a database consistency issue.'
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
const decryptedMapping = await this.encryptionService.decryptFields(
|
|
253
|
+
'IntegrationMapping',
|
|
254
|
+
updated
|
|
255
|
+
);
|
|
256
|
+
return this._mapMapping(decryptedMapping);
|
|
111
257
|
}
|
|
112
258
|
|
|
113
259
|
_compositeFilter(integrationId, sourceId) {
|
|
114
260
|
const filter = {};
|
|
115
|
-
|
|
116
|
-
if (integrationObjectId) filter.integrationId = integrationObjectId;
|
|
261
|
+
if (integrationId) filter.integrationId = integrationId;
|
|
117
262
|
if (sourceId !== undefined) {
|
|
118
263
|
filter.sourceId = sourceId === null ? null : String(sourceId);
|
|
119
264
|
}
|
|
@@ -123,13 +268,13 @@ class IntegrationMappingRepositoryDocumentDB extends IntegrationMappingRepositor
|
|
|
123
268
|
_mapMapping(doc) {
|
|
124
269
|
return {
|
|
125
270
|
id: fromObjectId(doc?._id),
|
|
126
|
-
integrationId:
|
|
271
|
+
integrationId: doc?.integrationId ?? null,
|
|
127
272
|
sourceId: doc?.sourceId ?? null,
|
|
128
273
|
mapping: doc?.mapping ?? null,
|
|
274
|
+
createdAt: doc?.createdAt,
|
|
275
|
+
updatedAt: doc?.updatedAt,
|
|
129
276
|
};
|
|
130
277
|
}
|
|
131
278
|
}
|
|
132
279
|
|
|
133
280
|
module.exports = { IntegrationMappingRepositoryDocumentDB };
|
|
134
|
-
|
|
135
|
-
|
|
@@ -127,6 +127,17 @@ class IntegrationRepositoryDocumentDB extends IntegrationRepositoryInterface {
|
|
|
127
127
|
};
|
|
128
128
|
const insertedId = await insertOne(this.prisma, 'Integration', document);
|
|
129
129
|
const created = await findOne(this.prisma, 'Integration', { _id: insertedId });
|
|
130
|
+
if (!created) {
|
|
131
|
+
console.error('[IntegrationRepositoryDocumentDB] Integration not found after insert', {
|
|
132
|
+
insertedId: fromObjectId(insertedId),
|
|
133
|
+
userId,
|
|
134
|
+
config,
|
|
135
|
+
});
|
|
136
|
+
throw new Error(
|
|
137
|
+
'Failed to create integration: Document not found after insert. ' +
|
|
138
|
+
'This indicates a database consistency issue.'
|
|
139
|
+
);
|
|
140
|
+
}
|
|
130
141
|
return this._mapIntegration(created);
|
|
131
142
|
}
|
|
132
143
|
|
|
@@ -157,6 +168,16 @@ class IntegrationRepositoryDocumentDB extends IntegrationRepositoryInterface {
|
|
|
157
168
|
}
|
|
158
169
|
);
|
|
159
170
|
const updated = await findOne(this.prisma, 'Integration', { _id: objectId });
|
|
171
|
+
if (!updated) {
|
|
172
|
+
console.error('[IntegrationRepositoryDocumentDB] Integration not found after update', {
|
|
173
|
+
integrationId: fromObjectId(objectId),
|
|
174
|
+
config,
|
|
175
|
+
});
|
|
176
|
+
throw new Error(
|
|
177
|
+
'Failed to update integration: Document not found after update. ' +
|
|
178
|
+
'This indicates a database consistency issue.'
|
|
179
|
+
);
|
|
180
|
+
}
|
|
160
181
|
return this._mapIntegration(updated);
|
|
161
182
|
}
|
|
162
183
|
|
|
@@ -8,17 +8,23 @@ const {
|
|
|
8
8
|
updateOne,
|
|
9
9
|
deleteOne,
|
|
10
10
|
} = require('../../database/documentdb-utils');
|
|
11
|
-
const {
|
|
11
|
+
const {
|
|
12
|
+
ProcessRepositoryInterface,
|
|
13
|
+
} = require('./process-repository-interface');
|
|
14
|
+
const {
|
|
15
|
+
DocumentDBEncryptionService,
|
|
16
|
+
} = require('../../database/documentdb-encryption-service');
|
|
12
17
|
|
|
13
18
|
class ProcessRepositoryDocumentDB extends ProcessRepositoryInterface {
|
|
14
19
|
constructor() {
|
|
15
20
|
super();
|
|
16
21
|
this.prisma = prisma;
|
|
22
|
+
this.encryptionService = new DocumentDBEncryptionService();
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
async create(processData) {
|
|
20
26
|
const now = new Date();
|
|
21
|
-
const
|
|
27
|
+
const plainDocument = {
|
|
22
28
|
userId: toObjectId(processData.userId),
|
|
23
29
|
integrationId: toObjectId(processData.integrationId),
|
|
24
30
|
name: processData.name,
|
|
@@ -26,45 +32,127 @@ class ProcessRepositoryDocumentDB extends ProcessRepositoryInterface {
|
|
|
26
32
|
state: processData.state || 'INITIALIZING',
|
|
27
33
|
context: processData.context || {},
|
|
28
34
|
results: processData.results || {},
|
|
29
|
-
childProcesses: (processData.childProcesses || [])
|
|
30
|
-
|
|
35
|
+
childProcesses: (processData.childProcesses || [])
|
|
36
|
+
.map((id) => toObjectId(id))
|
|
37
|
+
.filter(Boolean),
|
|
38
|
+
parentProcessId: processData.parentProcessId
|
|
39
|
+
? toObjectId(processData.parentProcessId)
|
|
40
|
+
: null,
|
|
31
41
|
createdAt: now,
|
|
32
42
|
updatedAt: now,
|
|
33
43
|
};
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
44
|
+
|
|
45
|
+
const encryptedDocument = await this.encryptionService.encryptFields(
|
|
46
|
+
'Process',
|
|
47
|
+
plainDocument
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const insertedId = await insertOne(
|
|
51
|
+
this.prisma,
|
|
52
|
+
'Process',
|
|
53
|
+
encryptedDocument
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const created = await findOne(this.prisma, 'Process', {
|
|
57
|
+
_id: insertedId,
|
|
58
|
+
});
|
|
59
|
+
if (!created) {
|
|
60
|
+
console.error(
|
|
61
|
+
'[ProcessRepositoryDocumentDB] Process not found after insert',
|
|
62
|
+
{
|
|
63
|
+
insertedId: fromObjectId(insertedId),
|
|
64
|
+
processData: {
|
|
65
|
+
userId: processData.userId,
|
|
66
|
+
integrationId: processData.integrationId,
|
|
67
|
+
name: processData.name,
|
|
68
|
+
type: processData.type,
|
|
69
|
+
},
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
throw new Error(
|
|
73
|
+
'Failed to create process: Document not found after insert. ' +
|
|
74
|
+
'This indicates a database consistency issue.'
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
const decryptedProcess = await this.encryptionService.decryptFields(
|
|
78
|
+
'Process',
|
|
79
|
+
created
|
|
80
|
+
);
|
|
81
|
+
return this._mapProcess(decryptedProcess);
|
|
37
82
|
}
|
|
38
83
|
|
|
39
84
|
async findById(processId) {
|
|
40
85
|
const objectId = toObjectId(processId);
|
|
41
86
|
if (!objectId) return null;
|
|
42
87
|
const doc = await findOne(this.prisma, 'Process', { _id: objectId });
|
|
43
|
-
|
|
88
|
+
if (!doc) return null;
|
|
89
|
+
|
|
90
|
+
const decryptedProcess = await this.encryptionService.decryptFields(
|
|
91
|
+
'Process',
|
|
92
|
+
doc
|
|
93
|
+
);
|
|
94
|
+
return this._mapProcess(decryptedProcess);
|
|
44
95
|
}
|
|
45
96
|
|
|
46
97
|
async update(processId, updates) {
|
|
47
98
|
const objectId = toObjectId(processId);
|
|
48
99
|
if (!objectId) return null;
|
|
100
|
+
|
|
101
|
+
const existing = await findOne(this.prisma, 'Process', {
|
|
102
|
+
_id: objectId,
|
|
103
|
+
});
|
|
104
|
+
if (!existing) return null;
|
|
105
|
+
|
|
49
106
|
const updatePayload = {};
|
|
50
107
|
if (updates.state !== undefined) updatePayload.state = updates.state;
|
|
51
|
-
if (updates.context !== undefined)
|
|
52
|
-
|
|
108
|
+
if (updates.context !== undefined)
|
|
109
|
+
updatePayload.context = updates.context;
|
|
110
|
+
if (updates.results !== undefined)
|
|
111
|
+
updatePayload.results = updates.results;
|
|
53
112
|
if (updates.childProcesses !== undefined) {
|
|
54
|
-
updatePayload.childProcesses = (updates.childProcesses || [])
|
|
113
|
+
updatePayload.childProcesses = (updates.childProcesses || [])
|
|
114
|
+
.map((id) => toObjectId(id))
|
|
115
|
+
.filter(Boolean);
|
|
55
116
|
}
|
|
56
117
|
if (updates.parentProcessId !== undefined) {
|
|
57
|
-
updatePayload.parentProcessId = updates.parentProcessId
|
|
118
|
+
updatePayload.parentProcessId = updates.parentProcessId
|
|
119
|
+
? toObjectId(updates.parentProcessId)
|
|
120
|
+
: null;
|
|
58
121
|
}
|
|
59
122
|
updatePayload.updatedAt = new Date();
|
|
123
|
+
|
|
124
|
+
const encryptedUpdate = await this.encryptionService.encryptFields(
|
|
125
|
+
'Process',
|
|
126
|
+
updatePayload
|
|
127
|
+
);
|
|
128
|
+
|
|
60
129
|
await updateOne(
|
|
61
130
|
this.prisma,
|
|
62
131
|
'Process',
|
|
63
132
|
{ _id: objectId },
|
|
64
|
-
{ $set:
|
|
133
|
+
{ $set: encryptedUpdate }
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
const updated = await findOne(this.prisma, 'Process', {
|
|
137
|
+
_id: objectId,
|
|
138
|
+
});
|
|
139
|
+
if (!updated) {
|
|
140
|
+
console.error(
|
|
141
|
+
'[ProcessRepositoryDocumentDB] Process not found after update',
|
|
142
|
+
{
|
|
143
|
+
processId: fromObjectId(objectId),
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
throw new Error(
|
|
147
|
+
'Failed to update process: Document not found after update. ' +
|
|
148
|
+
'This indicates a database consistency issue.'
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
const decryptedProcess = await this.encryptionService.decryptFields(
|
|
152
|
+
'Process',
|
|
153
|
+
updated
|
|
65
154
|
);
|
|
66
|
-
|
|
67
|
-
return updated ? this._mapProcess(updated) : null;
|
|
155
|
+
return this._mapProcess(decryptedProcess);
|
|
68
156
|
}
|
|
69
157
|
|
|
70
158
|
async findByIntegrationAndType(integrationId, type) {
|
|
@@ -76,30 +164,36 @@ class ProcessRepositoryDocumentDB extends ProcessRepositoryInterface {
|
|
|
76
164
|
const docs = await findMany(this.prisma, 'Process', filter, {
|
|
77
165
|
sort: { createdAt: -1 },
|
|
78
166
|
});
|
|
79
|
-
|
|
167
|
+
|
|
168
|
+
const decryptedDocs = await Promise.all(
|
|
169
|
+
docs.map((doc) =>
|
|
170
|
+
this.encryptionService.decryptFields('Process', doc)
|
|
171
|
+
)
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
return decryptedDocs.map((doc) => this._mapProcess(doc));
|
|
80
175
|
}
|
|
81
176
|
|
|
82
|
-
async findActiveProcesses(
|
|
177
|
+
async findActiveProcesses(
|
|
178
|
+
integrationId,
|
|
179
|
+
excludeStates = ['COMPLETED', 'ERROR']
|
|
180
|
+
) {
|
|
83
181
|
const integrationObjectId = toObjectId(integrationId);
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
pipeline,
|
|
100
|
-
cursor: {},
|
|
101
|
-
}).then((res) => res?.cursor?.firstBatch || []);
|
|
102
|
-
return docs.map((doc) => this._mapProcess(doc));
|
|
182
|
+
const filter = {
|
|
183
|
+
integrationId: integrationObjectId,
|
|
184
|
+
state: { $nin: excludeStates },
|
|
185
|
+
};
|
|
186
|
+
const docs = await findMany(this.prisma, 'Process', filter, {
|
|
187
|
+
sort: { createdAt: -1 },
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const decryptedDocs = await Promise.all(
|
|
191
|
+
docs.map((doc) =>
|
|
192
|
+
this.encryptionService.decryptFields('Process', doc)
|
|
193
|
+
)
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
return decryptedDocs.map((doc) => this._mapProcess(doc));
|
|
103
197
|
}
|
|
104
198
|
|
|
105
199
|
async findByName(name) {
|
|
@@ -109,7 +203,13 @@ class ProcessRepositoryDocumentDB extends ProcessRepositoryInterface {
|
|
|
109
203
|
{ name },
|
|
110
204
|
{ sort: { createdAt: -1 } }
|
|
111
205
|
);
|
|
112
|
-
|
|
206
|
+
if (!doc) return null;
|
|
207
|
+
|
|
208
|
+
const decryptedProcess = await this.encryptionService.decryptFields(
|
|
209
|
+
'Process',
|
|
210
|
+
doc
|
|
211
|
+
);
|
|
212
|
+
return this._mapProcess(decryptedProcess);
|
|
113
213
|
}
|
|
114
214
|
|
|
115
215
|
async deleteById(processId) {
|
|
@@ -128,8 +228,12 @@ class ProcessRepositoryDocumentDB extends ProcessRepositoryInterface {
|
|
|
128
228
|
state: doc?.state ?? null,
|
|
129
229
|
context: doc?.context ?? {},
|
|
130
230
|
results: doc?.results ?? {},
|
|
131
|
-
childProcesses: (doc?.childProcesses || []).map((id) =>
|
|
132
|
-
|
|
231
|
+
childProcesses: (doc?.childProcesses || []).map((id) =>
|
|
232
|
+
fromObjectId(id)
|
|
233
|
+
),
|
|
234
|
+
parentProcessId: doc?.parentProcessId
|
|
235
|
+
? fromObjectId(doc.parentProcessId)
|
|
236
|
+
: null,
|
|
133
237
|
createdAt: doc?.createdAt ? new Date(doc.createdAt) : null,
|
|
134
238
|
updatedAt: doc?.updatedAt ? new Date(doc.updatedAt) : null,
|
|
135
239
|
};
|
|
@@ -137,5 +241,3 @@ class ProcessRepositoryDocumentDB extends ProcessRepositoryInterface {
|
|
|
137
241
|
}
|
|
138
242
|
|
|
139
243
|
module.exports = { ProcessRepositoryDocumentDB };
|
|
140
|
-
|
|
141
|
-
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { Requester } = require('./requester');
|
|
2
|
+
const { get } = require('../../assertions');
|
|
2
3
|
const { ModuleConstants } = require('../ModuleConstants');
|
|
3
4
|
|
|
4
5
|
|
|
@@ -9,27 +10,42 @@ class ApiKeyRequester extends Requester {
|
|
|
9
10
|
constructor(params) {
|
|
10
11
|
super(params);
|
|
11
12
|
this.requesterType = 'apiKey';
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
// Use snake_case convention consistent with OAuth2Requester and BasicAuthRequester
|
|
15
|
+
this.api_key_name = get(params, 'api_key_name', 'key');
|
|
16
|
+
this.api_key = get(params, 'api_key', null);
|
|
17
|
+
|
|
18
|
+
// Backward compatibility: support old naming convention
|
|
19
|
+
if (!this.api_key && params.API_KEY_VALUE) {
|
|
20
|
+
this.api_key = params.API_KEY_VALUE;
|
|
21
|
+
}
|
|
22
|
+
if (!this.api_key_name && params.API_KEY_NAME) {
|
|
23
|
+
this.api_key_name = params.API_KEY_NAME;
|
|
24
|
+
}
|
|
14
25
|
}
|
|
15
26
|
|
|
16
27
|
async addAuthHeaders(headers) {
|
|
17
|
-
if (this.
|
|
18
|
-
headers[this.
|
|
28
|
+
if (this.api_key) {
|
|
29
|
+
headers[this.api_key_name] = this.api_key;
|
|
19
30
|
}
|
|
20
31
|
return headers;
|
|
21
32
|
}
|
|
22
33
|
|
|
23
34
|
isAuthenticated() {
|
|
24
35
|
return (
|
|
25
|
-
this.
|
|
26
|
-
this.
|
|
27
|
-
this.
|
|
36
|
+
this.api_key !== null &&
|
|
37
|
+
this.api_key !== undefined &&
|
|
38
|
+
typeof this.api_key === 'string' &&
|
|
39
|
+
this.api_key.trim().length > 0
|
|
28
40
|
);
|
|
29
41
|
}
|
|
30
42
|
|
|
31
43
|
setApiKey(api_key) {
|
|
32
|
-
this.
|
|
44
|
+
this.api_key = api_key;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
setApiKeyName(api_key_name) {
|
|
48
|
+
this.api_key_name = api_key_name;
|
|
33
49
|
}
|
|
34
50
|
}
|
|
35
51
|
|
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.56",
|
|
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.56",
|
|
42
|
+
"@friggframework/prettier-config": "2.0.0-next.56",
|
|
43
|
+
"@friggframework/test": "2.0.0-next.56",
|
|
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": "5551318d5c45913810a6b03a5ea19c72b5c4cb2f"
|
|
84
84
|
}
|