@friggframework/core 2.0.0--canary.667.a0620c7.0 → 2.0.0--canary.702.d5e6de1.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/CLAUDE.md +1 -41
- package/application/commands/README.md +11 -17
- package/application/commands/entity-commands.js +60 -18
- package/application/commands/integration-commands.js +0 -63
- package/database/documentdb-encryption-service.js +33 -2
- package/database/encryption/README.md +3 -3
- package/database/encryption/encryption-schema-registry.js +29 -109
- package/database/encryption/field-encryption-service.js +16 -13
- package/database/prisma.js +1 -10
- package/handlers/app-definition-loader.js +9 -2
- package/integrations/integration-router.js +22 -18
- package/integrations/repositories/integration-repository-documentdb.js +0 -32
- package/integrations/repositories/integration-repository-interface.js +0 -30
- package/integrations/repositories/integration-repository-mongo.js +0 -52
- package/integrations/repositories/integration-repository-postgres.js +0 -58
- package/integrations/use-cases/create-integration.js +19 -57
- package/jest-setup.js +2 -13
- package/jest-teardown.js +2 -5
- package/jest.config.js +0 -4
- package/modules/use-cases/get-entity-options-by-id.js +5 -7
- package/modules/use-cases/get-module.js +8 -29
- package/modules/use-cases/refresh-entity-options.js +5 -7
- package/modules/use-cases/test-module-auth.js +5 -7
- package/modules/utils/map-module-dto.js +3 -5
- package/package.json +8 -8
- package/queues/queuer-util.js +5 -6
- package/user/tests/doubles/test-user-repository.js +1 -1
- package/user/use-cases/get-user-from-bearer-token.js +2 -7
- package/database/encryption/ciphertext-format.js +0 -24
- package/integrations/use-cases/add-entities-to-integration.js +0 -92
- package/integrations/use-cases/remove-entities-from-integration.js +0 -70
- package/integrations/utils/assert-entity-ids-input.js +0 -42
- package/jest.db.config.js +0 -23
- package/modules/use-cases/create-entity-from-credential.js +0 -105
- package/modules/utils/find-module-definition.js +0 -23
- package/modules/utils/to-credential-id.js +0 -14
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
const { findNearestBackendPackageJson } = require('@friggframework/core/utils');
|
|
2
2
|
const path = require('node:path');
|
|
3
3
|
const fs = require('fs-extra');
|
|
4
|
+
const {
|
|
5
|
+
applyAppDefinitionDefaults,
|
|
6
|
+
} = require('@friggframework/schemas/app-definition');
|
|
4
7
|
const { resolveTelemetryConfig } = require('../telemetry/telemetry-config');
|
|
5
8
|
const { registerDeniedKeys } = require('../logs/denied-keys');
|
|
6
9
|
const {
|
|
@@ -33,7 +36,9 @@ function registerCredentialLogKeys(appDefinition, integrations) {
|
|
|
33
36
|
* @function loadAppDefinition
|
|
34
37
|
* @description Searches for the nearest backend package.json, loads the corresponding index.js file,
|
|
35
38
|
* and extracts the application definition containing integrations and user configuration.
|
|
36
|
-
*
|
|
39
|
+
* The defaults declared in the app-definition schema are applied first (ADR-051), so
|
|
40
|
+
* `userConfig` always holds a complete user config, also when the app omits `user`.
|
|
41
|
+
* @returns {{integrations: Array<object>, userConfig: object, adminScripts: Array<object>, reports: Array<object>, admin: object, telemetry: object, logging: object | null}} An object containing the application definition.
|
|
37
42
|
* @throws {Error} Throws error if backend package.json cannot be found.
|
|
38
43
|
* @throws {Error} Throws error if index.js file cannot be found in the backend directory.
|
|
39
44
|
* @example
|
|
@@ -53,7 +58,9 @@ function loadAppDefinition() {
|
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
const backendJsFile = require(backendFilePath);
|
|
56
|
-
|
|
61
|
+
// The one place schema defaults are applied at runtime (ADR-051): a
|
|
62
|
+
// default in app-definition.schema.json is the value core sees.
|
|
63
|
+
const appDefinition = applyAppDefinitionDefaults(backendJsFile.Definition);
|
|
57
64
|
|
|
58
65
|
const {
|
|
59
66
|
integrations = [],
|
|
@@ -42,9 +42,6 @@ const {
|
|
|
42
42
|
} = require('../modules/use-cases/get-entity-options-by-type');
|
|
43
43
|
const { TestModuleAuth } = require('../modules/use-cases/test-module-auth');
|
|
44
44
|
const { GetModule } = require('../modules/use-cases/get-module');
|
|
45
|
-
const {
|
|
46
|
-
CreateEntityFromCredential,
|
|
47
|
-
} = require('../modules/use-cases/create-entity-from-credential');
|
|
48
45
|
const {
|
|
49
46
|
GetEntityOptionsById,
|
|
50
47
|
} = require('../modules/use-cases/get-entity-options-by-id');
|
|
@@ -201,13 +198,6 @@ function createIntegrationRouter() {
|
|
|
201
198
|
getModulesDefinitionFromIntegrationClasses(integrationClasses),
|
|
202
199
|
});
|
|
203
200
|
|
|
204
|
-
const createEntityFromCredential = new CreateEntityFromCredential({
|
|
205
|
-
processAuthorizationCallback,
|
|
206
|
-
credentialRepository,
|
|
207
|
-
moduleDefinitions:
|
|
208
|
-
getModulesDefinitionFromIntegrationClasses(integrationClasses),
|
|
209
|
-
});
|
|
210
|
-
|
|
211
201
|
const router = express();
|
|
212
202
|
|
|
213
203
|
setIntegrationRoutes(router, authenticateUser, {
|
|
@@ -228,7 +218,6 @@ function createIntegrationRouter() {
|
|
|
228
218
|
getEntityOptionsById,
|
|
229
219
|
refreshEntityOptions,
|
|
230
220
|
processAuthorizationCallback,
|
|
231
|
-
createEntityFromCredential,
|
|
232
221
|
});
|
|
233
222
|
return router;
|
|
234
223
|
}
|
|
@@ -513,7 +502,6 @@ function setEntityRoutes(router, authenticateUser, useCases) {
|
|
|
513
502
|
getEntityOptionsById,
|
|
514
503
|
refreshEntityOptions,
|
|
515
504
|
processAuthorizationCallback,
|
|
516
|
-
createEntityFromCredential,
|
|
517
505
|
} = useCases;
|
|
518
506
|
|
|
519
507
|
router.route('/api/authorize').get(
|
|
@@ -578,19 +566,35 @@ function setEntityRoutes(router, authenticateUser, useCases) {
|
|
|
578
566
|
router.route('/api/entity').post(
|
|
579
567
|
catchAsyncError(async (req, res) => {
|
|
580
568
|
const user = await authenticateUser.execute(req);
|
|
569
|
+
const userId = user.getId();
|
|
581
570
|
const params = checkRequiredParams(req.body, [
|
|
582
571
|
'entityType',
|
|
583
572
|
'data',
|
|
584
573
|
]);
|
|
585
574
|
checkRequiredParams(req.body.data, ['credential_id']);
|
|
586
575
|
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
576
|
+
// May want to pass along the user ID as well so credential ID's can't be fished???
|
|
577
|
+
const credential = await getCredentialForUser.execute(
|
|
578
|
+
params.data.credential_id,
|
|
579
|
+
userId
|
|
580
|
+
);
|
|
581
|
+
|
|
582
|
+
if (!credential) {
|
|
583
|
+
throw Boom.badRequest('Invalid credential ID');
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
const module = await getModuleInstanceFromType.execute(
|
|
587
|
+
userId,
|
|
588
|
+
params.entityType
|
|
593
589
|
);
|
|
590
|
+
const entityDetails = await module.getEntityDetails(
|
|
591
|
+
module.api,
|
|
592
|
+
null,
|
|
593
|
+
null,
|
|
594
|
+
userId
|
|
595
|
+
);
|
|
596
|
+
|
|
597
|
+
res.json(await module.findOrCreateEntity(entityDetails));
|
|
594
598
|
})
|
|
595
599
|
);
|
|
596
600
|
|
|
@@ -164,38 +164,6 @@ class IntegrationRepositoryDocumentDB extends IntegrationRepositoryInterface {
|
|
|
164
164
|
return this._mapIntegration(created);
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
async addEntitiesToIntegration(integrationId, entityIds) {
|
|
168
|
-
const objectId = toObjectId(integrationId);
|
|
169
|
-
if (!objectId) return null;
|
|
170
|
-
const result = await updateOne(
|
|
171
|
-
this.prisma,
|
|
172
|
-
'Integration',
|
|
173
|
-
{ _id: objectId },
|
|
174
|
-
{
|
|
175
|
-
$addToSet: { entityIds: { $each: toObjectIdArray(entityIds) } },
|
|
176
|
-
$set: { updatedAt: { $date: new Date().toISOString() } },
|
|
177
|
-
}
|
|
178
|
-
);
|
|
179
|
-
if (!result?.n) return null;
|
|
180
|
-
return this.findIntegrationById(integrationId);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
async removeEntitiesFromIntegration(integrationId, entityIds) {
|
|
184
|
-
const objectId = toObjectId(integrationId);
|
|
185
|
-
if (!objectId) return null;
|
|
186
|
-
const result = await updateOne(
|
|
187
|
-
this.prisma,
|
|
188
|
-
'Integration',
|
|
189
|
-
{ _id: objectId },
|
|
190
|
-
{
|
|
191
|
-
$pullAll: { entityIds: toObjectIdArray(entityIds) },
|
|
192
|
-
$set: { updatedAt: { $date: new Date().toISOString() } },
|
|
193
|
-
}
|
|
194
|
-
);
|
|
195
|
-
if (!result?.n) return null;
|
|
196
|
-
return this.findIntegrationById(integrationId);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
167
|
async findIntegrationByUserId(userId) {
|
|
200
168
|
const objectId = toObjectId(userId);
|
|
201
169
|
if (!objectId) return null;
|
|
@@ -184,36 +184,6 @@ class IntegrationRepositoryInterface {
|
|
|
184
184
|
'Method findIntegrationsByEntityId must be implemented by subclass'
|
|
185
185
|
);
|
|
186
186
|
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Attach entities to an existing integration. Entities that are already
|
|
190
|
-
* attached are left as they are.
|
|
191
|
-
*
|
|
192
|
-
* @param {string|number} integrationId - Integration ID
|
|
193
|
-
* @param {Array<string|number>} entityIds - Entity IDs to attach
|
|
194
|
-
* @returns {Promise<Object|null>} Updated integration, or null when the integration does not exist
|
|
195
|
-
* @abstract
|
|
196
|
-
*/
|
|
197
|
-
async addEntitiesToIntegration(integrationId, entityIds) {
|
|
198
|
-
throw new Error(
|
|
199
|
-
'Method addEntitiesToIntegration must be implemented by subclass'
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Detach entities from an integration. Entities that are not attached
|
|
205
|
-
* are ignored; the entities themselves are not deleted.
|
|
206
|
-
*
|
|
207
|
-
* @param {string|number} integrationId - Integration ID
|
|
208
|
-
* @param {Array<string|number>} entityIds - Entity IDs to detach
|
|
209
|
-
* @returns {Promise<Object|null>} Updated integration, or null when the integration does not exist
|
|
210
|
-
* @abstract
|
|
211
|
-
*/
|
|
212
|
-
async removeEntitiesFromIntegration(integrationId, entityIds) {
|
|
213
|
-
throw new Error(
|
|
214
|
-
'Method removeEntitiesFromIntegration must be implemented by subclass'
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
187
|
}
|
|
218
188
|
|
|
219
189
|
module.exports = { IntegrationRepositoryInterface };
|
|
@@ -338,58 +338,6 @@ class IntegrationRepositoryMongo extends IntegrationRepositoryInterface {
|
|
|
338
338
|
};
|
|
339
339
|
}
|
|
340
340
|
|
|
341
|
-
/**
|
|
342
|
-
* Attach entities to an existing integration. Entities already attached
|
|
343
|
-
* are left as they are.
|
|
344
|
-
*
|
|
345
|
-
* @param {string} integrationId - Integration ID
|
|
346
|
-
* @param {Array<string>} entityIds - Entity IDs to attach
|
|
347
|
-
* @returns {Promise<Object|null>} Updated integration, or null when the integration does not exist
|
|
348
|
-
*/
|
|
349
|
-
async addEntitiesToIntegration(integrationId, entityIds) {
|
|
350
|
-
|
|
351
|
-
try {
|
|
352
|
-
await this.prisma.integration.update({
|
|
353
|
-
where: { id: integrationId },
|
|
354
|
-
data: {
|
|
355
|
-
entities: {
|
|
356
|
-
connect: entityIds.map((id) => ({ id })),
|
|
357
|
-
},
|
|
358
|
-
},
|
|
359
|
-
});
|
|
360
|
-
} catch (error) {
|
|
361
|
-
if (error.code === 'P2025') return null;
|
|
362
|
-
throw error;
|
|
363
|
-
}
|
|
364
|
-
return this.findIntegrationById(integrationId);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* Detach entities from an integration. Entities that are not attached
|
|
369
|
-
* are ignored. The entities themselves are not deleted.
|
|
370
|
-
*
|
|
371
|
-
* @param {string} integrationId - Integration ID
|
|
372
|
-
* @param {Array<string>} entityIds - Entity IDs to detach
|
|
373
|
-
* @returns {Promise<Object|null>} Updated integration, or null when the integration does not exist
|
|
374
|
-
*/
|
|
375
|
-
async removeEntitiesFromIntegration(integrationId, entityIds) {
|
|
376
|
-
|
|
377
|
-
try {
|
|
378
|
-
await this.prisma.integration.update({
|
|
379
|
-
where: { id: integrationId },
|
|
380
|
-
data: {
|
|
381
|
-
entities: {
|
|
382
|
-
disconnect: entityIds.map((id) => ({ id })),
|
|
383
|
-
},
|
|
384
|
-
},
|
|
385
|
-
});
|
|
386
|
-
} catch (error) {
|
|
387
|
-
if (error.code === 'P2025') return null;
|
|
388
|
-
throw error;
|
|
389
|
-
}
|
|
390
|
-
return this.findIntegrationById(integrationId);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
341
|
/**
|
|
394
342
|
* Find integration by user ID (returns single integration)
|
|
395
343
|
* Replaces: IntegrationModel.findOne({ user: userId }).populate('entities')
|
|
@@ -365,64 +365,6 @@ class IntegrationRepositoryPostgres extends IntegrationRepositoryInterface {
|
|
|
365
365
|
};
|
|
366
366
|
}
|
|
367
367
|
|
|
368
|
-
/**
|
|
369
|
-
* Attach entities to an existing integration. Entities already attached
|
|
370
|
-
* are left as they are.
|
|
371
|
-
*
|
|
372
|
-
* @param {string} integrationId - Integration ID (string from application layer)
|
|
373
|
-
* @param {Array<string>} entityIds - Entity IDs to attach
|
|
374
|
-
* @returns {Promise<Object|null>} Updated integration, or null when the integration does not exist
|
|
375
|
-
*/
|
|
376
|
-
async addEntitiesToIntegration(integrationId, entityIds) {
|
|
377
|
-
const intId = this._convertId(integrationId);
|
|
378
|
-
|
|
379
|
-
try {
|
|
380
|
-
await this.prisma.integration.update({
|
|
381
|
-
where: { id: intId },
|
|
382
|
-
data: {
|
|
383
|
-
entities: {
|
|
384
|
-
connect: entityIds.map((id) => ({
|
|
385
|
-
id: this._convertId(id),
|
|
386
|
-
})),
|
|
387
|
-
},
|
|
388
|
-
},
|
|
389
|
-
});
|
|
390
|
-
} catch (error) {
|
|
391
|
-
if (error.code === 'P2025') return null;
|
|
392
|
-
throw error;
|
|
393
|
-
}
|
|
394
|
-
return this.findIntegrationById(integrationId);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
/**
|
|
398
|
-
* Detach entities from an integration. Entities that are not attached
|
|
399
|
-
* are ignored. The entities themselves are not deleted.
|
|
400
|
-
*
|
|
401
|
-
* @param {string} integrationId - Integration ID (string from application layer)
|
|
402
|
-
* @param {Array<string>} entityIds - Entity IDs to detach
|
|
403
|
-
* @returns {Promise<Object|null>} Updated integration, or null when the integration does not exist
|
|
404
|
-
*/
|
|
405
|
-
async removeEntitiesFromIntegration(integrationId, entityIds) {
|
|
406
|
-
const intId = this._convertId(integrationId);
|
|
407
|
-
|
|
408
|
-
try {
|
|
409
|
-
await this.prisma.integration.update({
|
|
410
|
-
where: { id: intId },
|
|
411
|
-
data: {
|
|
412
|
-
entities: {
|
|
413
|
-
disconnect: entityIds.map((id) => ({
|
|
414
|
-
id: this._convertId(id),
|
|
415
|
-
})),
|
|
416
|
-
},
|
|
417
|
-
},
|
|
418
|
-
});
|
|
419
|
-
} catch (error) {
|
|
420
|
-
if (error.code === 'P2025') return null;
|
|
421
|
-
throw error;
|
|
422
|
-
}
|
|
423
|
-
return this.findIntegrationById(integrationId);
|
|
424
|
-
}
|
|
425
|
-
|
|
426
368
|
/**
|
|
427
369
|
* Find integration by user ID (returns single integration)
|
|
428
370
|
*
|
|
@@ -62,7 +62,7 @@ class CreateIntegration {
|
|
|
62
62
|
|
|
63
63
|
// A concurrent request may have created a matching row between the
|
|
64
64
|
// lookup above and this insert; re-check before any side effects run.
|
|
65
|
-
const survivor = await this.
|
|
65
|
+
const survivor = await this._findDuplicate(
|
|
66
66
|
userId,
|
|
67
67
|
config?.type,
|
|
68
68
|
entities
|
|
@@ -135,68 +135,30 @@ class CreateIntegration {
|
|
|
135
135
|
return mapIntegrationClassToIntegrationDTO(integrationInstance);
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
async
|
|
138
|
+
async _findDuplicate(userId, type, entityIds) {
|
|
139
139
|
const candidates =
|
|
140
140
|
await this.integrationRepository.findIntegrationsByUserId(userId);
|
|
141
|
-
const target =
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const entitySet = (integration) =>
|
|
157
|
-
new Set((integration.entitiesIds ?? []).map(String));
|
|
158
|
-
|
|
159
|
-
const exact = live.filter((integration) => {
|
|
160
|
-
const current = entitySet(integration);
|
|
141
|
+
const target = [...(entityIds ?? [])].map(String).sort();
|
|
142
|
+
|
|
143
|
+
const matches = candidates.filter((integration) => {
|
|
144
|
+
// An IN_DELETION row is either mid-teardown or a zombie left
|
|
145
|
+
// behind by a failed deleteIntegrationById call — never a live
|
|
146
|
+
// integration. Treating it as a duplicate would hand a reinstall
|
|
147
|
+
// attempt a row nothing will ever move out of IN_DELETION,
|
|
148
|
+
// silently discarded by the queue worker forever. Let a fresh
|
|
149
|
+
// create proceed instead; the zombie is cleaned up out-of-band,
|
|
150
|
+
// matching how teardown failures are already handled here.
|
|
151
|
+
if (integration.status === 'IN_DELETION') return false;
|
|
152
|
+
if (integration.config?.type !== type) return false;
|
|
153
|
+
const current = [...(integration.entitiesIds ?? [])]
|
|
154
|
+
.map(String)
|
|
155
|
+
.sort();
|
|
161
156
|
return (
|
|
162
|
-
current.
|
|
163
|
-
|
|
157
|
+
current.length === target.length &&
|
|
158
|
+
current.every((id, index) => id === target[index])
|
|
164
159
|
);
|
|
165
160
|
});
|
|
166
161
|
|
|
167
|
-
// Entities may have been attached after create (addEntitiesToIntegration),
|
|
168
|
-
// so a reconnect that sends the original entities must still find the
|
|
169
|
-
// integration that now holds them, instead of creating a second one
|
|
170
|
-
// that would share those entities.
|
|
171
|
-
const supersets = live.filter((integration) => {
|
|
172
|
-
const current = entitySet(integration);
|
|
173
|
-
return [...target].every((id) => current.has(id));
|
|
174
|
-
});
|
|
175
|
-
return { exact, supersets: target.size ? supersets : [] };
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
async _findDuplicate(userId, type, entityIds) {
|
|
179
|
-
const { exact, supersets } = await this._findMatches(
|
|
180
|
-
userId,
|
|
181
|
-
type,
|
|
182
|
-
entityIds
|
|
183
|
-
);
|
|
184
|
-
if (exact.length) return this._pickOldest(exact);
|
|
185
|
-
return supersets.length ? this._pickOldest(supersets) : null;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// After an insert the new row is itself an exact match, so the survivor
|
|
189
|
-
// is the oldest of every exact or superset match (the new row included):
|
|
190
|
-
// an older integration that already holds these entities always wins.
|
|
191
|
-
async _findSurvivor(userId, type, entityIds) {
|
|
192
|
-
const { exact, supersets } = await this._findMatches(
|
|
193
|
-
userId,
|
|
194
|
-
type,
|
|
195
|
-
entityIds
|
|
196
|
-
);
|
|
197
|
-
// supersets includes the exact matches; it is empty only for an
|
|
198
|
-
// empty entity set, where exact matching alone applies.
|
|
199
|
-
const matches = supersets.length ? supersets : exact;
|
|
200
162
|
return matches.length ? this._pickOldest(matches) : null;
|
|
201
163
|
}
|
|
202
164
|
|
package/jest-setup.js
CHANGED
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// MongoDB (as @friggframework/test's globalSetup does): nothing in the default
|
|
4
|
-
// suite talks to a live server, and a binary that failed to start used to stop
|
|
5
|
-
// every core suite from running. Suites that need a real database are
|
|
6
|
-
// `*.db.test.js` files, run by `npm run test:db` (see jest.db.config.js).
|
|
7
|
-
const { overrideEnvironment } = require('@friggframework/test');
|
|
8
|
-
|
|
9
|
-
module.exports = async function () {
|
|
10
|
-
if (!process.env.STAGE) {
|
|
11
|
-
overrideEnvironment({ STAGE: 'dev' });
|
|
12
|
-
}
|
|
13
|
-
};
|
|
1
|
+
const {globalSetup} = require('@friggframework/test');
|
|
2
|
+
module.exports = globalSetup;
|
package/jest-teardown.js
CHANGED
package/jest.config.js
CHANGED
|
@@ -20,8 +20,4 @@ module.exports = {
|
|
|
20
20
|
globalTeardown: './jest-teardown.js',
|
|
21
21
|
|
|
22
22
|
setupFilesAfterEnv: ['./logs/jest-logger-setup.js'],
|
|
23
|
-
|
|
24
|
-
// `*.db.test.js` suites talk to a real MongoDB replica set / PostgreSQL
|
|
25
|
-
// and run separately via `npm run test:db` (jest.db.config.js).
|
|
26
|
-
testPathIgnorePatterns: ['/node_modules/', '\\.db\\.test\\.js$'],
|
|
27
23
|
};
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
const { Module } = require('../module');
|
|
2
|
-
const {
|
|
3
|
-
findModuleDefinitionForEntity,
|
|
4
|
-
} = require('../utils/find-module-definition');
|
|
5
2
|
|
|
6
3
|
class GetEntityOptionsById {
|
|
7
4
|
/**
|
|
@@ -48,10 +45,11 @@ class GetEntityOptionsById {
|
|
|
48
45
|
}
|
|
49
46
|
|
|
50
47
|
const entityType = entity.moduleName;
|
|
51
|
-
const moduleDefinition =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
const moduleDefinition = this.moduleDefinitions.find((def) => {
|
|
49
|
+
const modelName =
|
|
50
|
+
Module.getEntityModelFromDefinition(def).modelName;
|
|
51
|
+
return entityType === modelName;
|
|
52
|
+
});
|
|
55
53
|
|
|
56
54
|
if (!moduleDefinition) {
|
|
57
55
|
throw new Error(
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
const { Module } = require('../module');
|
|
2
|
-
const {
|
|
3
|
-
findModuleDefinitionForEntity,
|
|
4
|
-
} = require('../utils/find-module-definition');
|
|
5
2
|
|
|
6
3
|
class GetModule {
|
|
7
4
|
constructor({ moduleRepository, moduleDefinitions }) {
|
|
@@ -45,10 +42,10 @@ class GetModule {
|
|
|
45
42
|
}
|
|
46
43
|
|
|
47
44
|
const entityType = entity.moduleName;
|
|
48
|
-
const moduleDefinition =
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
);
|
|
45
|
+
const moduleDefinition = this.moduleDefinitions.find((def) => {
|
|
46
|
+
const modelName = Module.getEntityModelFromDefinition(def).modelName;
|
|
47
|
+
return entityType === modelName;
|
|
48
|
+
});
|
|
52
49
|
|
|
53
50
|
if (!moduleDefinition) {
|
|
54
51
|
throw new Error(
|
|
@@ -62,33 +59,15 @@ class GetModule {
|
|
|
62
59
|
definition: moduleDefinition,
|
|
63
60
|
});
|
|
64
61
|
|
|
65
|
-
//
|
|
66
|
-
// the response names it and says whether it still works, as the v2
|
|
67
|
-
// entity DTO does.
|
|
68
|
-
const credential = module.credential;
|
|
69
|
-
const credentialId =
|
|
70
|
-
credential && typeof credential === 'object'
|
|
71
|
-
? credential.id
|
|
72
|
-
: credential;
|
|
73
|
-
const ownerId = module.entity.userId ?? module.entity.user;
|
|
62
|
+
// todo: this properties should be methods in the Module class
|
|
74
63
|
return {
|
|
75
64
|
id: module.entity.id,
|
|
76
65
|
name: module.entity.name,
|
|
77
66
|
moduleName: module.entity.moduleName,
|
|
78
|
-
|
|
79
|
-
credentialId === undefined || credentialId === null
|
|
80
|
-
? null
|
|
81
|
-
: String(credentialId),
|
|
82
|
-
authIsValid:
|
|
83
|
-
typeof credential?.authIsValid === 'boolean'
|
|
84
|
-
? credential.authIsValid
|
|
85
|
-
: null,
|
|
67
|
+
credential: module.credential,
|
|
86
68
|
externalId: module.entity.externalId,
|
|
87
|
-
userId:
|
|
88
|
-
|
|
89
|
-
? null
|
|
90
|
-
: String(ownerId),
|
|
91
|
-
};
|
|
69
|
+
userId: module.entity.user.toString(),
|
|
70
|
+
}
|
|
92
71
|
}
|
|
93
72
|
}
|
|
94
73
|
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
const { Module } = require('../module');
|
|
2
|
-
const {
|
|
3
|
-
findModuleDefinitionForEntity,
|
|
4
|
-
} = require('../utils/find-module-definition');
|
|
5
2
|
|
|
6
3
|
class RefreshEntityOptions {
|
|
7
4
|
/**
|
|
@@ -49,10 +46,11 @@ class RefreshEntityOptions {
|
|
|
49
46
|
}
|
|
50
47
|
|
|
51
48
|
const entityType = entity.moduleName;
|
|
52
|
-
const moduleDefinition =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
const moduleDefinition = this.moduleDefinitions.find((def) => {
|
|
50
|
+
const modelName =
|
|
51
|
+
Module.getEntityModelFromDefinition(def).modelName;
|
|
52
|
+
return entityType === modelName;
|
|
53
|
+
});
|
|
56
54
|
|
|
57
55
|
if (!moduleDefinition) {
|
|
58
56
|
throw new Error(
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
const { Module } = require('../module');
|
|
2
|
-
const {
|
|
3
|
-
findModuleDefinitionForEntity,
|
|
4
|
-
} = require('../utils/find-module-definition');
|
|
5
2
|
|
|
6
3
|
class TestModuleAuth {
|
|
7
4
|
/**
|
|
@@ -48,10 +45,11 @@ class TestModuleAuth {
|
|
|
48
45
|
}
|
|
49
46
|
|
|
50
47
|
const entityType = entity.moduleName;
|
|
51
|
-
const moduleDefinition =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
const moduleDefinition = this.moduleDefinitions.find((def) => {
|
|
49
|
+
const modelName =
|
|
50
|
+
Module.getEntityModelFromDefinition(def).modelName;
|
|
51
|
+
return entityType === modelName;
|
|
52
|
+
});
|
|
55
53
|
|
|
56
54
|
if (!moduleDefinition) {
|
|
57
55
|
throw new Error(
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const { toCredentialId } = require('./to-credential-id');
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* @param {import('../module').Module} moduleInstance
|
|
5
3
|
* Convert a Module domain instance to a plain DTO suitable for JSON responses.
|
|
@@ -12,9 +10,9 @@ function mapModuleClassToModuleDTO(moduleInstance) {
|
|
|
12
10
|
name: moduleInstance.name,
|
|
13
11
|
userId: moduleInstance.userId,
|
|
14
12
|
entity: moduleInstance.entity,
|
|
15
|
-
credentialId:
|
|
16
|
-
type: moduleInstance.getName()
|
|
13
|
+
credentialId: moduleInstance.credential?._id?.toString(),
|
|
14
|
+
type: moduleInstance.getName()
|
|
17
15
|
};
|
|
18
16
|
}
|
|
19
17
|
|
|
20
|
-
module.exports = { mapModuleClassToModuleDTO };
|
|
18
|
+
module.exports = { mapModuleClassToModuleDTO };
|
package/package.json
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/core",
|
|
3
|
+
"description": "",
|
|
3
4
|
"prettier": "@friggframework/prettier-config",
|
|
4
|
-
"version": "2.0.0--canary.
|
|
5
|
+
"version": "2.0.0--canary.702.d5e6de1.0",
|
|
5
6
|
"dependencies": {
|
|
6
7
|
"@aws-sdk/client-apigatewaymanagementapi": "^3.588.0",
|
|
7
8
|
"@aws-sdk/client-kms": "^3.588.0",
|
|
8
9
|
"@aws-sdk/client-lambda": "^3.714.0",
|
|
9
10
|
"@aws-sdk/client-s3": "^3.588.0",
|
|
10
|
-
"@aws-sdk/client-scheduler": "^3.
|
|
11
|
+
"@aws-sdk/client-scheduler": "^3.1153.0",
|
|
11
12
|
"@aws-sdk/client-sqs": "^3.588.0",
|
|
12
13
|
"@aws-sdk/client-ssm": "^3.588.0",
|
|
13
14
|
"@aws-sdk/s3-request-presigner": "^3.588.0",
|
|
15
|
+
"@friggframework/schemas": "2.0.0--canary.702.d5e6de1.0",
|
|
14
16
|
"@hapi/boom": "^10.0.1",
|
|
15
17
|
"@opentelemetry/api": "^1.9.1",
|
|
16
18
|
"@opentelemetry/context-async-hooks": "^2.9.0",
|
|
@@ -48,9 +50,9 @@
|
|
|
48
50
|
}
|
|
49
51
|
},
|
|
50
52
|
"devDependencies": {
|
|
51
|
-
"@friggframework/eslint-config": "2.0.0--canary.
|
|
52
|
-
"@friggframework/prettier-config": "2.0.0--canary.
|
|
53
|
-
"@friggframework/test": "2.0.0--canary.
|
|
53
|
+
"@friggframework/eslint-config": "2.0.0--canary.702.d5e6de1.0",
|
|
54
|
+
"@friggframework/prettier-config": "2.0.0--canary.702.d5e6de1.0",
|
|
55
|
+
"@friggframework/test": "2.0.0--canary.702.d5e6de1.0",
|
|
54
56
|
"@prisma/client": "^6.19.3",
|
|
55
57
|
"@types/lodash": "4.17.15",
|
|
56
58
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
@@ -68,7 +70,6 @@
|
|
|
68
70
|
"scripts": {
|
|
69
71
|
"lint:fix": "prettier --write --loglevel error . && eslint . --fix",
|
|
70
72
|
"test": "jest --passWithNoTests # TODO",
|
|
71
|
-
"test:db": "jest --config jest.db.config.js --runInBand",
|
|
72
73
|
"prisma:generate:mongo": "npx prisma generate --schema ./prisma-mongodb/schema.prisma",
|
|
73
74
|
"prisma:generate:postgres": "npx prisma generate --schema ./prisma-postgresql/schema.prisma",
|
|
74
75
|
"prisma:generate": "npm run prisma:generate:mongo && npm run prisma:generate:postgres",
|
|
@@ -87,9 +88,8 @@
|
|
|
87
88
|
"url": "https://github.com/friggframework/frigg/issues"
|
|
88
89
|
},
|
|
89
90
|
"homepage": "https://github.com/friggframework/frigg#readme",
|
|
90
|
-
"description": "",
|
|
91
91
|
"publishConfig": {
|
|
92
92
|
"access": "public"
|
|
93
93
|
},
|
|
94
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "d5e6de1068aabce0dfa8965a93bce40e05f50b7e"
|
|
95
95
|
}
|