@friggframework/core 2.0.0--canary.490.7426521.0 → 2.0.0--canary.490.9a325b5.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.
@@ -1,29 +1,15 @@
1
1
  const { ObjectId } = require('mongodb');
2
- const { getNativeMongoClient } = require('../../database/mongodb-native-client');
3
- const { EncryptedCollection } = require('../../database/encrypted-collection-wrapper');
4
- const { FieldEncryptionService } = require('../../database/encryption/field-encryption-service');
5
- const { getEncryptedFields } = require('../../database/encryption/encryption-schema-registry');
6
- const { Cryptor } = require('../../encrypt/Cryptor');
2
+ const { BaseRepositoryDocumentDB } = require('../../database/repositories/base-repository-documentdb');
7
3
  const { CredentialRepositoryInterface } = require('./credential-repository-interface');
8
4
 
9
- /**
10
- * DocumentDB Credential Repository Adapter
11
- * Uses native MongoDB driver to avoid Prisma's $$REMOVE operator
12
- */
13
5
  class CredentialRepositoryDocumentDB extends CredentialRepositoryInterface {
14
6
  constructor() {
15
7
  super();
16
-
17
- const nativeClient = getNativeMongoClient();
18
- const collection = nativeClient.collection('Credential');
19
-
20
- const cryptor = new Cryptor({ shouldUseAws: !!process.env.KMS_KEY_ARN });
21
- const encryptionService = new FieldEncryptionService({
22
- cryptor,
23
- schema: { getEncryptedFields },
24
- });
25
-
26
- this.collection = new EncryptedCollection(collection, encryptionService, 'Credential');
8
+ this._base = new BaseRepositoryDocumentDB('Credential', 'Credential');
9
+ }
10
+
11
+ get collection() {
12
+ return this._base.collection;
27
13
  }
28
14
 
29
15
  async findCredentialById(id) {
@@ -4,24 +4,23 @@
4
4
  */
5
5
 
6
6
  const { isDocumentDB } = require('./utils/documentdb-compatibility');
7
- const { logger } = require('../logs');
8
7
 
9
8
  async function connectDatabase() {
10
9
  if (isDocumentDB()) {
11
- logger.info('Connecting to DocumentDB using native MongoDB driver...');
10
+ console.log('Connecting to DocumentDB using native MongoDB driver...');
12
11
  const { getNativeMongoClient } = require('./mongodb-native-client');
13
12
  const nativeClient = getNativeMongoClient();
14
13
  await nativeClient.connect();
15
- logger.info('✓ Native MongoDB client connected');
14
+ console.log('✓ Native MongoDB client connected');
16
15
 
17
16
  const { initializeMongoDBSchema } = require('./utils/mongodb-schema-init');
18
17
  await initializeMongoDBSchema();
19
- logger.info('✓ MongoDB schema initialized');
18
+ console.log('✓ MongoDB schema initialized');
20
19
  } else {
21
- logger.info('Connecting using Prisma...');
20
+ console.log('Connecting using Prisma...');
22
21
  const { connectPrisma } = require('./prisma');
23
22
  await connectPrisma();
24
- logger.info('✓ Prisma client connected');
23
+ console.log('✓ Prisma client connected');
25
24
  }
26
25
  }
27
26
 
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Base DocumentDB Repository
3
+ * Provides lazy-loaded encrypted collections for DocumentDB adapters
4
+ *
5
+ * Lazy loading pattern ensures:
6
+ * - Repositories can be instantiated at module load time
7
+ * - Collections are only accessed after native client connects
8
+ * - Compatible with eager loading pattern in routers
9
+ */
10
+
11
+ const { getNativeMongoClient } = require('../mongodb-native-client');
12
+ const { EncryptedCollection } = require('../encrypted-collection-wrapper');
13
+ const { FieldEncryptionService } = require('../encryption/field-encryption-service');
14
+ const { getEncryptedFields } = require('../encryption/encryption-schema-registry');
15
+ const { Cryptor } = require('../../encrypt/Cryptor');
16
+
17
+ class BaseRepositoryDocumentDB {
18
+ constructor(collectionName, modelName) {
19
+ this.collectionName = collectionName;
20
+ this.modelName = modelName;
21
+ this.nativeClient = getNativeMongoClient();
22
+ this._collection = null;
23
+ }
24
+
25
+ _getCollection() {
26
+ if (!this._collection) {
27
+ const collection = this.nativeClient.collection(this.collectionName);
28
+
29
+ const cryptor = new Cryptor({ shouldUseAws: !!process.env.KMS_KEY_ARN });
30
+ const encryptionService = new FieldEncryptionService({
31
+ cryptor,
32
+ schema: { getEncryptedFields },
33
+ });
34
+
35
+ this._collection = new EncryptedCollection(
36
+ collection,
37
+ encryptionService,
38
+ this.modelName
39
+ );
40
+ }
41
+ return this._collection;
42
+ }
43
+
44
+ get collection() {
45
+ return this._getCollection();
46
+ }
47
+ }
48
+
49
+ module.exports = { BaseRepositoryDocumentDB };
50
+
@@ -1,27 +1,17 @@
1
1
  const { ObjectId } = require('mongodb');
2
2
  const { getNativeMongoClient } = require('../mongodb-native-client');
3
- const { EncryptedCollection } = require('../encrypted-collection-wrapper');
4
- const { FieldEncryptionService } = require('../encryption/field-encryption-service');
5
- const { getEncryptedFields } = require('../encryption/encryption-schema-registry');
6
- const { Cryptor } = require('../../encrypt/Cryptor');
3
+ const { BaseRepositoryDocumentDB } = require('./base-repository-documentdb');
7
4
  const { HealthCheckRepositoryInterface } = require('./health-check-repository-interface');
8
5
 
9
6
  class HealthCheckRepositoryDocumentDB extends HealthCheckRepositoryInterface {
10
7
  constructor() {
11
8
  super();
12
-
13
- const nativeClient = getNativeMongoClient();
14
- this.nativeClient = nativeClient;
15
-
16
- const collection = nativeClient.collection('Credential');
17
-
18
- const cryptor = new Cryptor({ shouldUseAws: !!process.env.KMS_KEY_ARN });
19
- const encryptionService = new FieldEncryptionService({
20
- cryptor,
21
- schema: { getEncryptedFields },
22
- });
23
-
24
- this.collection = new EncryptedCollection(collection, encryptionService, 'Credential');
9
+ this._base = new BaseRepositoryDocumentDB('Credential', 'Credential');
10
+ this.nativeClient = getNativeMongoClient();
11
+ }
12
+
13
+ get collection() {
14
+ return this._base.collection;
25
15
  }
26
16
 
27
17
  async getDatabaseConnectionState() {
@@ -32,7 +32,14 @@ const {
32
32
  } = require('../use-cases/check-integrations-health-use-case');
33
33
 
34
34
  const router = Router();
35
- const healthCheckRepository = createHealthCheckRepository({ prismaClient: prisma });
35
+
36
+ let healthCheckRepository;
37
+ function getHealthCheckRepository() {
38
+ if (!healthCheckRepository) {
39
+ healthCheckRepository = createHealthCheckRepository({ prismaClient: prisma });
40
+ }
41
+ return healthCheckRepository;
42
+ }
36
43
 
37
44
  // Load integrations and create factories just like auth router does
38
45
  // This verifies the system can properly load integrations
@@ -55,15 +62,23 @@ try {
55
62
  integrationClasses = [];
56
63
  }
57
64
 
58
- const testEncryptionUseCase = new TestEncryptionUseCase({
59
- healthCheckRepository,
60
- });
61
- const checkDatabaseHealthUseCase = new CheckDatabaseHealthUseCase({
62
- healthCheckRepository,
63
- });
64
- const checkEncryptionHealthUseCase = new CheckEncryptionHealthUseCase({
65
- testEncryptionUseCase,
66
- });
65
+ function getTestEncryptionUseCase() {
66
+ return new TestEncryptionUseCase({
67
+ healthCheckRepository: getHealthCheckRepository(),
68
+ });
69
+ }
70
+
71
+ function getCheckDatabaseHealthUseCase() {
72
+ return new CheckDatabaseHealthUseCase({
73
+ healthCheckRepository: getHealthCheckRepository(),
74
+ });
75
+ }
76
+
77
+ function getCheckEncryptionHealthUseCase() {
78
+ return new CheckEncryptionHealthUseCase({
79
+ testEncryptionUseCase: getTestEncryptionUseCase(),
80
+ });
81
+ }
67
82
  const checkExternalApisHealthUseCase = new CheckExternalApisHealthUseCase();
68
83
  const checkIntegrationsHealthUseCase = new CheckIntegrationsHealthUseCase({
69
84
  moduleFactory,
@@ -418,7 +433,7 @@ router.get('/health/detailed', async (_req, res) => {
418
433
  }
419
434
 
420
435
  try {
421
- response.checks.database = await checkDatabaseHealthUseCase.execute();
436
+ response.checks.database = await getCheckDatabaseHealthUseCase().execute();
422
437
  if (response.checks.database.status === 'unhealthy') {
423
438
  response.status = 'unhealthy';
424
439
  }
@@ -433,7 +448,7 @@ router.get('/health/detailed', async (_req, res) => {
433
448
  }
434
449
 
435
450
  try {
436
- response.checks.encryption = await checkEncryptionHealthUseCase.execute();
451
+ response.checks.encryption = await getCheckEncryptionHealthUseCase().execute();
437
452
  if (response.checks.encryption.status === 'unhealthy') {
438
453
  response.status = 'unhealthy';
439
454
  }
@@ -496,7 +511,7 @@ router.get('/health/live', (_req, res) => {
496
511
  });
497
512
 
498
513
  router.get('/health/ready', async (_req, res) => {
499
- const dbHealth = await checkDatabaseHealthUseCase.execute();
514
+ const dbHealth = await getCheckDatabaseHealthUseCase().execute();
500
515
  const isDbReady = dbHealth.status === 'healthy';
501
516
 
502
517
  const integrationsHealth = checkIntegrationsHealthUseCase.execute();
@@ -1,25 +1,15 @@
1
1
  const { ObjectId } = require('mongodb');
2
- const { getNativeMongoClient } = require('../../database/mongodb-native-client');
3
- const { EncryptedCollection } = require('../../database/encrypted-collection-wrapper');
4
- const { FieldEncryptionService } = require('../../database/encryption/field-encryption-service');
5
- const { getEncryptedFields } = require('../../database/encryption/encryption-schema-registry');
6
- const { Cryptor } = require('../../encrypt/Cryptor');
2
+ const { BaseRepositoryDocumentDB } = require('../../database/repositories/base-repository-documentdb');
7
3
  const { IntegrationMappingRepositoryInterface } = require('./integration-mapping-repository-interface');
8
4
 
9
5
  class IntegrationMappingRepositoryDocumentDB extends IntegrationMappingRepositoryInterface {
10
6
  constructor() {
11
7
  super();
12
-
13
- const nativeClient = getNativeMongoClient();
14
- const collection = nativeClient.collection('IntegrationMapping');
15
-
16
- const cryptor = new Cryptor({ shouldUseAws: !!process.env.KMS_KEY_ARN });
17
- const encryptionService = new FieldEncryptionService({
18
- cryptor,
19
- schema: { getEncryptedFields },
20
- });
21
-
22
- this.collection = new EncryptedCollection(collection, encryptionService, 'IntegrationMapping');
8
+ this._base = new BaseRepositoryDocumentDB('IntegrationMapping', 'IntegrationMapping');
9
+ }
10
+
11
+ get collection() {
12
+ return this._base.collection;
23
13
  }
24
14
 
25
15
  async findMappingById(mappingId) {
@@ -1,25 +1,15 @@
1
1
  const { ObjectId } = require('mongodb');
2
- const { getNativeMongoClient } = require('../../database/mongodb-native-client');
3
- const { EncryptedCollection } = require('../../database/encrypted-collection-wrapper');
4
- const { FieldEncryptionService } = require('../../database/encryption/field-encryption-service');
5
- const { getEncryptedFields } = require('../../database/encryption/encryption-schema-registry');
6
- const { Cryptor } = require('../../encrypt/Cryptor');
2
+ const { BaseRepositoryDocumentDB } = require('../../database/repositories/base-repository-documentdb');
7
3
  const { IntegrationRepositoryInterface } = require('./integration-repository-interface');
8
4
 
9
5
  class IntegrationRepositoryDocumentDB extends IntegrationRepositoryInterface {
10
6
  constructor() {
11
7
  super();
12
-
13
- const nativeClient = getNativeMongoClient();
14
- const collection = nativeClient.collection('Integration');
15
-
16
- const cryptor = new Cryptor({ shouldUseAws: !!process.env.KMS_KEY_ARN });
17
- const encryptionService = new FieldEncryptionService({
18
- cryptor,
19
- schema: { getEncryptedFields },
20
- });
21
-
22
- this.collection = new EncryptedCollection(collection, encryptionService, 'Integration');
8
+ this._base = new BaseRepositoryDocumentDB('Integration', 'Integration');
9
+ }
10
+
11
+ get collection() {
12
+ return this._base.collection;
23
13
  }
24
14
 
25
15
  async findIntegrationById(id) {
@@ -1,25 +1,15 @@
1
1
  const { ObjectId } = require('mongodb');
2
- const { getNativeMongoClient } = require('../../database/mongodb-native-client');
3
- const { EncryptedCollection } = require('../../database/encrypted-collection-wrapper');
4
- const { FieldEncryptionService } = require('../../database/encryption/field-encryption-service');
5
- const { getEncryptedFields } = require('../../database/encryption/encryption-schema-registry');
6
- const { Cryptor } = require('../../encrypt/Cryptor');
2
+ const { BaseRepositoryDocumentDB } = require('../../database/repositories/base-repository-documentdb');
7
3
  const { ProcessRepositoryInterface } = require('./process-repository-interface');
8
4
 
9
5
  class ProcessRepositoryDocumentDB extends ProcessRepositoryInterface {
10
6
  constructor() {
11
7
  super();
12
-
13
- const nativeClient = getNativeMongoClient();
14
- const collection = nativeClient.collection('Process');
15
-
16
- const cryptor = new Cryptor({ shouldUseAws: !!process.env.KMS_KEY_ARN });
17
- const encryptionService = new FieldEncryptionService({
18
- cryptor,
19
- schema: { getEncryptedFields },
20
- });
21
-
22
- this.collection = new EncryptedCollection(collection, encryptionService, 'Process');
8
+ this._base = new BaseRepositoryDocumentDB('Process', 'Process');
9
+ }
10
+
11
+ get collection() {
12
+ return this._base.collection;
23
13
  }
24
14
 
25
15
  async createProcess(processData) {
@@ -1,25 +1,15 @@
1
1
  const { ObjectId } = require('mongodb');
2
- const { getNativeMongoClient } = require('../../database/mongodb-native-client');
3
- const { EncryptedCollection } = require('../../database/encrypted-collection-wrapper');
4
- const { FieldEncryptionService } = require('../../database/encryption/field-encryption-service');
5
- const { getEncryptedFields } = require('../../database/encryption/encryption-schema-registry');
6
- const { Cryptor } = require('../../encrypt/Cryptor');
2
+ const { BaseRepositoryDocumentDB } = require('../../database/repositories/base-repository-documentdb');
7
3
  const { ModuleRepositoryInterface } = require('./module-repository-interface');
8
4
 
9
5
  class ModuleRepositoryDocumentDB extends ModuleRepositoryInterface {
10
6
  constructor() {
11
7
  super();
12
-
13
- const nativeClient = getNativeMongoClient();
14
- const collection = nativeClient.collection('Entity');
15
-
16
- const cryptor = new Cryptor({ shouldUseAws: !!process.env.KMS_KEY_ARN });
17
- const encryptionService = new FieldEncryptionService({
18
- cryptor,
19
- schema: { getEncryptedFields },
20
- });
21
-
22
- this.collection = new EncryptedCollection(collection, encryptionService, 'Entity');
8
+ this._base = new BaseRepositoryDocumentDB('Entity', 'Entity');
9
+ }
10
+
11
+ get collection() {
12
+ return this._base.collection;
23
13
  }
24
14
 
25
15
  async findEntityById(entityId) {
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.490.7426521.0",
4
+ "version": "2.0.0--canary.490.9a325b5.0",
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--canary.490.7426521.0",
42
- "@friggframework/prettier-config": "2.0.0--canary.490.7426521.0",
43
- "@friggframework/test": "2.0.0--canary.490.7426521.0",
41
+ "@friggframework/eslint-config": "2.0.0--canary.490.9a325b5.0",
42
+ "@friggframework/prettier-config": "2.0.0--canary.490.9a325b5.0",
43
+ "@friggframework/test": "2.0.0--canary.490.9a325b5.0",
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": "742652114f13c2cc94d726ccdb65a5cc3609e943"
83
+ "gitHead": "9a325b566c69480371bc7cbf22e4a5c8cb173f13"
84
84
  }
@@ -1,25 +1,15 @@
1
1
  const { ObjectId } = require('mongodb');
2
- const { getNativeMongoClient } = require('../../database/mongodb-native-client');
3
- const { EncryptedCollection } = require('../../database/encrypted-collection-wrapper');
4
- const { FieldEncryptionService } = require('../../database/encryption/field-encryption-service');
5
- const { getEncryptedFields } = require('../../database/encryption/encryption-schema-registry');
6
- const { Cryptor } = require('../../encrypt/Cryptor');
2
+ const { BaseRepositoryDocumentDB } = require('../../database/repositories/base-repository-documentdb');
7
3
  const { SyncRepositoryInterface } = require('./sync-repository-interface');
8
4
 
9
5
  class SyncRepositoryDocumentDB extends SyncRepositoryInterface {
10
6
  constructor() {
11
7
  super();
12
-
13
- const nativeClient = getNativeMongoClient();
14
- const collection = nativeClient.collection('Sync');
15
-
16
- const cryptor = new Cryptor({ shouldUseAws: !!process.env.KMS_KEY_ARN });
17
- const encryptionService = new FieldEncryptionService({
18
- cryptor,
19
- schema: { getEncryptedFields },
20
- });
21
-
22
- this.collection = new EncryptedCollection(collection, encryptionService, 'Sync');
8
+ this._base = new BaseRepositoryDocumentDB('Sync', 'Sync');
9
+ }
10
+
11
+ get collection() {
12
+ return this._base.collection;
23
13
  }
24
14
 
25
15
  async getSyncObject(name, dataIdentifier, entity) {
@@ -1,10 +1,6 @@
1
1
  const { ObjectId } = require('mongodb');
2
2
  const bcrypt = require('bcryptjs');
3
- const { getNativeMongoClient } = require('../../database/mongodb-native-client');
4
- const { EncryptedCollection } = require('../../database/encrypted-collection-wrapper');
5
- const { FieldEncryptionService } = require('../../database/encryption/field-encryption-service');
6
- const { getEncryptedFields } = require('../../database/encryption/encryption-schema-registry');
7
- const { Cryptor } = require('../../encrypt/Cryptor');
3
+ const { BaseRepositoryDocumentDB } = require('../../database/repositories/base-repository-documentdb');
8
4
  const { TokenRepositoryInterface } = require('./token-repository-interface');
9
5
 
10
6
  const BCRYPT_ROUNDS = 10;
@@ -12,17 +8,11 @@ const BCRYPT_ROUNDS = 10;
12
8
  class TokenRepositoryDocumentDB extends TokenRepositoryInterface {
13
9
  constructor() {
14
10
  super();
15
-
16
- const nativeClient = getNativeMongoClient();
17
- const collection = nativeClient.collection('Token');
18
-
19
- const cryptor = new Cryptor({ shouldUseAws: !!process.env.KMS_KEY_ARN });
20
- const encryptionService = new FieldEncryptionService({
21
- cryptor,
22
- schema: { getEncryptedFields },
23
- });
24
-
25
- this.collection = new EncryptedCollection(collection, encryptionService, 'Token');
11
+ this._base = new BaseRepositoryDocumentDB('Token', 'Token');
12
+ }
13
+
14
+ get collection() {
15
+ return this._base.collection;
26
16
  }
27
17
 
28
18
  async createTokenWithExpire(userId, rawToken, minutes) {
@@ -1,10 +1,6 @@
1
1
  const { ObjectId } = require('mongodb');
2
2
  const bcrypt = require('bcryptjs');
3
- const { getNativeMongoClient } = require('../../database/mongodb-native-client');
4
- const { EncryptedCollection } = require('../../database/encrypted-collection-wrapper');
5
- const { FieldEncryptionService } = require('../../database/encryption/field-encryption-service');
6
- const { getEncryptedFields } = require('../../database/encryption/encryption-schema-registry');
7
- const { Cryptor } = require('../../encrypt/Cryptor');
3
+ const { BaseRepositoryDocumentDB } = require('../../database/repositories/base-repository-documentdb');
8
4
  const { UserRepositoryInterface } = require('./user-repository-interface');
9
5
  const { createTokenRepository } = require('../../token/repositories/token-repository-factory');
10
6
 
@@ -13,20 +9,14 @@ const BCRYPT_ROUNDS = 10;
13
9
  class UserRepositoryDocumentDB extends UserRepositoryInterface {
14
10
  constructor() {
15
11
  super();
16
-
17
- const nativeClient = getNativeMongoClient();
18
- const collection = nativeClient.collection('User');
19
-
20
- const cryptor = new Cryptor({ shouldUseAws: !!process.env.KMS_KEY_ARN });
21
- const encryptionService = new FieldEncryptionService({
22
- cryptor,
23
- schema: { getEncryptedFields },
24
- });
25
-
26
- this.collection = new EncryptedCollection(collection, encryptionService, 'User');
12
+ this._base = new BaseRepositoryDocumentDB('User', 'User');
27
13
  this.tokenRepository = createTokenRepository();
28
14
  }
29
15
 
16
+ get collection() {
17
+ return this._base.collection;
18
+ }
19
+
30
20
  async getSessionToken(token) {
31
21
  return await this.tokenRepository.getSessionToken(token);
32
22
  }
@@ -1,25 +1,15 @@
1
1
  const { ObjectId } = require('mongodb');
2
- const { getNativeMongoClient } = require('../../database/mongodb-native-client');
3
- const { EncryptedCollection } = require('../../database/encrypted-collection-wrapper');
4
- const { FieldEncryptionService } = require('../../database/encryption/field-encryption-service');
5
- const { getEncryptedFields } = require('../../database/encryption/encryption-schema-registry');
6
- const { Cryptor } = require('../../encrypt/Cryptor');
2
+ const { BaseRepositoryDocumentDB } = require('../../database/repositories/base-repository-documentdb');
7
3
  const { WebsocketConnectionRepositoryInterface } = require('./websocket-connection-repository-interface');
8
4
 
9
5
  class WebsocketConnectionRepositoryDocumentDB extends WebsocketConnectionRepositoryInterface {
10
6
  constructor() {
11
7
  super();
12
-
13
- const nativeClient = getNativeMongoClient();
14
- const collection = nativeClient.collection('WebsocketConnection');
15
-
16
- const cryptor = new Cryptor({ shouldUseAws: !!process.env.KMS_KEY_ARN });
17
- const encryptionService = new FieldEncryptionService({
18
- cryptor,
19
- schema: { getEncryptedFields },
20
- });
21
-
22
- this.collection = new EncryptedCollection(collection, encryptionService, 'WebsocketConnection');
8
+ this._base = new BaseRepositoryDocumentDB('WebsocketConnection', 'WebsocketConnection');
9
+ }
10
+
11
+ get collection() {
12
+ return this._base.collection;
23
13
  }
24
14
 
25
15
  async createConnection(connectionData) {