@friggframework/core 2.0.0--canary.704.79d9a63.0 → 2.0.0--canary.680.daae24e.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.
Files changed (117) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/CLAUDE.md +0 -40
  3. package/application/commands/entity-commands.js +60 -18
  4. package/application/commands/integration-commands.js +18 -71
  5. package/application/index.js +6 -2
  6. package/credential/repositories/credential-repository-documentdb.js +34 -0
  7. package/credential/repositories/credential-repository-interface.js +15 -0
  8. package/credential/repositories/credential-repository-mongo.js +23 -0
  9. package/credential/repositories/credential-repository-postgres.js +28 -0
  10. package/credential/use-cases/credential-operations-for-user.js +117 -0
  11. package/credential/use-cases/reauthorize-credential-for-user.js +66 -0
  12. package/database/documentdb-encryption-service.js +9 -22
  13. package/database/documentdb-utils.js +1 -4
  14. package/database/encryption/README.md +78 -14
  15. package/database/encryption/documentdb-encryption-service.md +78 -1
  16. package/database/encryption/encryption-config.js +240 -0
  17. package/database/encryption/encryption-schema-registry.js +41 -12
  18. package/database/encryption/field-encryption-service.js +69 -5
  19. package/database/encryption/integration-mapping-encryption.js +1 -1
  20. package/database/encryption/test-support/fake-ciphertext.js +15 -0
  21. package/database/prisma.js +11 -36
  22. package/database/use-cases/check-encryption-health-use-case.js +43 -52
  23. package/errors/index.js +0 -4
  24. package/generated/prisma-mongodb/edge.js +20 -4
  25. package/generated/prisma-mongodb/index-browser.js +17 -1
  26. package/generated/prisma-mongodb/index.d.ts +1543 -95
  27. package/generated/prisma-mongodb/index.js +20 -4
  28. package/generated/prisma-mongodb/package.json +1 -1
  29. package/generated/prisma-mongodb/schema.prisma +27 -0
  30. package/generated/prisma-mongodb/wasm.js +20 -4
  31. package/generated/prisma-postgresql/edge.js +20 -4
  32. package/generated/prisma-postgresql/index-browser.js +17 -1
  33. package/generated/prisma-postgresql/index.d.ts +1570 -89
  34. package/generated/prisma-postgresql/index.js +20 -4
  35. package/generated/prisma-postgresql/package.json +1 -1
  36. package/generated/prisma-postgresql/schema.prisma +26 -0
  37. package/generated/prisma-postgresql/wasm.js +20 -4
  38. package/handlers/WEBHOOKS.md +0 -29
  39. package/handlers/app-definition-loader.js +19 -8
  40. package/handlers/app-handler-helpers.js +25 -3
  41. package/handlers/backend-utils.js +31 -25
  42. package/handlers/middleware/admin-auth.js +14 -1
  43. package/handlers/routers/auth.js +11 -3
  44. package/handlers/routers/health.js +11 -4
  45. package/handlers/workers/integration-defined-workers.js +5 -2
  46. package/index.js +4 -4
  47. package/integrations/index.js +0 -4
  48. package/integrations/integration-base.js +0 -29
  49. package/integrations/integration-router.js +16 -23
  50. package/integrations/repositories/integration-mapping-repository-documentdb.js +0 -50
  51. package/integrations/repositories/integration-mapping-repository-interface.js +0 -15
  52. package/integrations/repositories/integration-mapping-repository-mongo.js +0 -29
  53. package/integrations/repositories/integration-mapping-repository-postgres.js +0 -30
  54. package/integrations/repositories/integration-mapping-repository.js +0 -29
  55. package/integrations/repositories/integration-repository-documentdb.js +0 -32
  56. package/integrations/repositories/integration-repository-interface.js +0 -30
  57. package/integrations/repositories/integration-repository-mongo.js +1 -53
  58. package/integrations/repositories/integration-repository-postgres.js +0 -58
  59. package/integrations/repositories/process-repository-mongo.js +1 -1
  60. package/integrations/use-cases/create-integration.js +19 -57
  61. package/integrations/use-cases/integration-operations-for-user.js +225 -0
  62. package/integrations/utils/map-integration-dto.js +1 -15
  63. package/management-api/create-management-api-router.js +49 -0
  64. package/management-api/error-response.js +116 -0
  65. package/management-api/management-api-config.js +82 -0
  66. package/management-api/meta-router.js +57 -0
  67. package/management-api/openapi/build-openapi.js +144 -0
  68. package/management-api/openapi/components.js +368 -0
  69. package/management-api/openapi/v1-operations.js +83 -0
  70. package/management-api/openapi/v2-operations.js +252 -0
  71. package/management-api/route-registry.js +294 -0
  72. package/management-api/test-support/http-client.js +39 -0
  73. package/management-api/use-cases/get-management-api-meta.js +57 -0
  74. package/management-api/v1-deprecation.js +120 -0
  75. package/management-api/v2/create-v2-router.js +85 -0
  76. package/management-api/v2/dependencies.js +256 -0
  77. package/management-api/v2/dto.js +123 -0
  78. package/management-api/v2/handlers/authorization.js +93 -0
  79. package/management-api/v2/handlers/credentials.js +29 -0
  80. package/management-api/v2/handlers/entities.js +74 -0
  81. package/management-api/v2/handlers/integrations.js +125 -0
  82. package/management-api/v2/handlers/proxy.js +34 -0
  83. package/management-api/v2/request.js +54 -0
  84. package/management-api/v2/test-support/fake-dependencies.js +103 -0
  85. package/modules/domain/authorization-session.js +144 -0
  86. package/modules/entity-type-registry.js +311 -0
  87. package/modules/index.js +6 -0
  88. package/modules/proxy/proxy-errors.js +20 -0
  89. package/modules/proxy/proxy-path.js +179 -0
  90. package/modules/proxy/proxy-policy.js +248 -0
  91. package/modules/repositories/authorization-session-repository-documentdb.js +112 -0
  92. package/modules/repositories/authorization-session-repository-factory.js +31 -0
  93. package/modules/repositories/authorization-session-repository-interface.js +47 -0
  94. package/modules/repositories/authorization-session-repository-prisma.js +87 -0
  95. package/modules/requester/proxy-request.js +244 -0
  96. package/modules/requester/requester.js +27 -2
  97. package/modules/tests/doubles/in-memory-authorization-session-repository.js +45 -0
  98. package/modules/use-cases/entity-operations-for-user.js +125 -0
  99. package/modules/use-cases/entity-types.js +115 -0
  100. package/modules/use-cases/execute-entity-proxy-request.js +239 -0
  101. package/modules/use-cases/get-authorization-requirements.js +100 -0
  102. package/modules/use-cases/get-entity-module-for-user.js +86 -0
  103. package/modules/use-cases/multi-step-authorization.js +302 -0
  104. package/modules/utils/map-module-dto.js +3 -5
  105. package/package.json +5 -5
  106. package/prisma-mongodb/schema.prisma +27 -0
  107. package/prisma-postgresql/migrations/20261003000000_add_authorization_session/migration.sql +28 -0
  108. package/prisma-postgresql/schema.prisma +26 -0
  109. package/types/index.d.ts +1 -0
  110. package/types/modules/index.d.ts +58 -0
  111. package/user/tests/doubles/test-user-repository.js +1 -1
  112. package/user/use-cases/get-user-from-bearer-token.js +2 -7
  113. package/errors/mapping-already-exists-error.js +0 -14
  114. package/integrations/use-cases/add-entities-to-integration.js +0 -92
  115. package/integrations/use-cases/remove-entities-from-integration.js +0 -70
  116. package/integrations/utils/assert-entity-ids-input.js +0 -42
  117. package/modules/utils/to-credential-id.js +0 -14
package/index.js CHANGED
@@ -57,14 +57,12 @@ const {
57
57
  HaltError,
58
58
  RequiredPropertyError,
59
59
  ParameterTypeError,
60
- MappingAlreadyExistsError,
61
60
  } = require('./errors/index');
62
61
  const {
63
62
  IntegrationBase,
64
63
  Options,
65
64
  createIntegrationRouter,
66
65
  checkRequiredParams,
67
- getModulesDefinitionFromIntegrationClasses,
68
66
  LoadIntegrationContextUseCase,
69
67
  } = require('./integrations/index');
70
68
  const {
@@ -100,6 +98,8 @@ const {
100
98
  Requester,
101
99
  ModuleConstants,
102
100
  ModuleFactory,
101
+ getEntityTypeRegistry,
102
+ EntityRegistryError,
103
103
  } = require('./modules/index');
104
104
  const application = require('./application');
105
105
  const utils = require('./utils');
@@ -145,14 +145,12 @@ module.exports = {
145
145
  HaltError,
146
146
  RequiredPropertyError,
147
147
  ParameterTypeError,
148
- MappingAlreadyExistsError,
149
148
 
150
149
  // integrations
151
150
  IntegrationBase,
152
151
  Options,
153
152
  checkRequiredParams,
154
153
  createIntegrationRouter,
155
- getModulesDefinitionFromIntegrationClasses,
156
154
  LoadIntegrationContextUseCase,
157
155
  CreateProcess,
158
156
  UpdateProcessState,
@@ -208,6 +206,8 @@ module.exports = {
208
206
  Requester,
209
207
  ModuleConstants,
210
208
  ModuleFactory,
209
+ getEntityTypeRegistry,
210
+ EntityRegistryError,
211
211
  // queues
212
212
  QueuerUtil,
213
213
 
@@ -4,9 +4,6 @@ const {
4
4
  createIntegrationRouter,
5
5
  checkRequiredParams,
6
6
  } = require('./integration-router');
7
- const {
8
- getModulesDefinitionFromIntegrationClasses,
9
- } = require('./utils/map-integration-dto');
10
7
  const {
11
8
  LoadIntegrationContextUseCase,
12
9
  } = require('./use-cases/load-integration-context');
@@ -21,7 +18,6 @@ module.exports = {
21
18
  Options,
22
19
  createIntegrationRouter,
23
20
  checkRequiredParams,
24
- getModulesDefinitionFromIntegrationClasses,
25
21
  LoadIntegrationContextUseCase,
26
22
  validateExtensionBinding,
27
23
  getExtensionRoutes,
@@ -457,35 +457,6 @@ class IntegrationBase {
457
457
  );
458
458
  }
459
459
 
460
- /**
461
- * Insert-only mapping write; usable as an atomic claim/lock row.
462
- * @throws {MappingAlreadyExistsError} If a mapping for sourceId exists
463
- */
464
- async createMapping(sourceId, mapping) {
465
- if (!sourceId) {
466
- throw new Error(`sourceId must be set`);
467
- }
468
- return await this.integrationMappingRepository.createMapping(
469
- this.id,
470
- sourceId,
471
- mapping
472
- );
473
- }
474
-
475
- /**
476
- * Deletes the mapping for sourceId. A missing mapping is not an error
477
- * (resolves with deletedCount 0).
478
- */
479
- async deleteMapping(sourceId) {
480
- if (!sourceId) {
481
- throw new Error(`sourceId must be set`);
482
- }
483
- return await this.integrationMappingRepository.deleteMapping(
484
- this.id,
485
- sourceId
486
- );
487
- }
488
-
489
460
  /**
490
461
  * CHILDREN CAN OVERRIDE THESE CONFIGURATION METHODS
491
462
  */
@@ -31,9 +31,6 @@ const {
31
31
  GetIntegrationInstance,
32
32
  } = require('./use-cases/get-integration-instance');
33
33
  const { UpdateIntegration } = require('./use-cases/update-integration');
34
- const {
35
- getModulesDefinitionFromIntegrationClasses,
36
- } = require('./utils/map-integration-dto');
37
34
  const {
38
35
  GetModuleInstanceFromType,
39
36
  } = require('../modules/use-cases/get-module-instance-from-type');
@@ -74,8 +71,13 @@ const {
74
71
  const log = getLogger('frigg.integrations');
75
72
 
76
73
  function createIntegrationRouter() {
77
- const { integrations: integrationClasses, userConfig } =
78
- loadAppDefinition();
74
+ // moduleDefinitions is the app registry's definitions (ADR-059), so
75
+ // /api/authorize and friends accept a type no integration binds.
76
+ const {
77
+ integrations: integrationClasses,
78
+ userConfig,
79
+ moduleDefinitions,
80
+ } = loadAppDefinition();
79
81
  const moduleRepository = createModuleRepository();
80
82
  const integrationRepository = createIntegrationRepository();
81
83
  const credentialRepository = createCredentialRepository();
@@ -108,8 +110,7 @@ function createIntegrationRouter() {
108
110
 
109
111
  const moduleFactory = new ModuleFactory({
110
112
  moduleRepository,
111
- moduleDefinitions:
112
- getModulesDefinitionFromIntegrationClasses(integrationClasses),
113
+ moduleDefinitions,
113
114
  });
114
115
  const deleteIntegrationForUser = new DeleteIntegrationForUser({
115
116
  integrationRepository,
@@ -136,8 +137,7 @@ function createIntegrationRouter() {
136
137
 
137
138
  const getEntitiesForUser = new GetEntitiesForUser({
138
139
  moduleRepository,
139
- moduleDefinitions:
140
- getModulesDefinitionFromIntegrationClasses(integrationClasses),
140
+ moduleDefinitions,
141
141
  });
142
142
 
143
143
  const getIntegrationInstance = new GetIntegrationInstance({
@@ -153,37 +153,31 @@ function createIntegrationRouter() {
153
153
  });
154
154
 
155
155
  const getModuleInstanceFromType = new GetModuleInstanceFromType({
156
- moduleDefinitions:
157
- getModulesDefinitionFromIntegrationClasses(integrationClasses),
156
+ moduleDefinitions,
158
157
  });
159
158
 
160
159
  const getEntityOptionsByType = new GetEntityOptionsByType({
161
- moduleDefinitions:
162
- getModulesDefinitionFromIntegrationClasses(integrationClasses),
160
+ moduleDefinitions,
163
161
  });
164
162
 
165
163
  const testModuleAuth = new TestModuleAuth({
166
164
  moduleRepository,
167
- moduleDefinitions:
168
- getModulesDefinitionFromIntegrationClasses(integrationClasses),
165
+ moduleDefinitions,
169
166
  });
170
167
 
171
168
  const getModule = new GetModule({
172
169
  moduleRepository,
173
- moduleDefinitions:
174
- getModulesDefinitionFromIntegrationClasses(integrationClasses),
170
+ moduleDefinitions,
175
171
  });
176
172
 
177
173
  const getEntityOptionsById = new GetEntityOptionsById({
178
174
  moduleRepository,
179
- moduleDefinitions:
180
- getModulesDefinitionFromIntegrationClasses(integrationClasses),
175
+ moduleDefinitions,
181
176
  });
182
177
 
183
178
  const refreshEntityOptions = new RefreshEntityOptions({
184
179
  moduleRepository,
185
- moduleDefinitions:
186
- getModulesDefinitionFromIntegrationClasses(integrationClasses),
180
+ moduleDefinitions,
187
181
  });
188
182
 
189
183
  const getPossibleIntegrations = new GetPossibleIntegrations({
@@ -194,8 +188,7 @@ function createIntegrationRouter() {
194
188
  moduleRepository,
195
189
  credentialRepository,
196
190
  integrationRepository,
197
- moduleDefinitions:
198
- getModulesDefinitionFromIntegrationClasses(integrationClasses),
191
+ moduleDefinitions,
199
192
  });
200
193
 
201
194
  const router = express();
@@ -1,5 +1,4 @@
1
1
  const { prisma } = require('../../database/prisma');
2
- const { MappingAlreadyExistsError } = require('../../errors');
3
2
  const {
4
3
  toObjectId,
5
4
  fromObjectId,
@@ -181,55 +180,6 @@ class IntegrationMappingRepositoryDocumentDB extends IntegrationMappingRepositor
181
180
  return this._mapMapping(decryptedMapping);
182
181
  }
183
182
 
184
- async createMapping(integrationId, sourceId, mapping) {
185
- const now = new Date();
186
- const encryptedDocument = await this.encryptionService.encryptFields(
187
- 'IntegrationMapping',
188
- {
189
- integrationId,
190
- sourceId:
191
- sourceId === null || sourceId === undefined
192
- ? null
193
- : String(sourceId),
194
- mapping,
195
- createdAt: now,
196
- updatedAt: now,
197
- }
198
- );
199
-
200
- let insertedId;
201
- try {
202
- insertedId = await insertOne(
203
- this.prisma,
204
- 'IntegrationMapping',
205
- encryptedDocument
206
- );
207
- } catch (error) {
208
- if (error.code === 11000) {
209
- throw new MappingAlreadyExistsError(integrationId, sourceId, {
210
- cause: error,
211
- });
212
- }
213
- throw error;
214
- }
215
-
216
- const created = await findOne(this.prisma, 'IntegrationMapping', {
217
- _id: insertedId,
218
- });
219
- if (!created) {
220
- throw new Error(
221
- 'Failed to create mapping: Document not found after insert. ' +
222
- 'This indicates a database consistency issue.'
223
- );
224
- }
225
- return this._mapMapping(
226
- await this.encryptionService.decryptFields(
227
- 'IntegrationMapping',
228
- created
229
- )
230
- );
231
- }
232
-
233
183
  async findMappingsByIntegration(integrationId) {
234
184
  const filter = {};
235
185
  if (integrationId) filter.integrationId = integrationId;
@@ -39,21 +39,6 @@ class IntegrationMappingRepositoryInterface {
39
39
  throw new Error('Method upsertMapping must be implemented by subclass');
40
40
  }
41
41
 
42
- /**
43
- * Insert a mapping, failing if one already exists for the
44
- * (integrationId, sourceId) pair. Atomic: usable as a claim/lock row.
45
- *
46
- * @param {string|number} integrationId - The integration ID
47
- * @param {string} sourceId - The source ID for lookup
48
- * @param {Object} mapping - The mapping data
49
- * @returns {Promise<Object>} The created mapping document
50
- * @throws {MappingAlreadyExistsError} If the pair already exists
51
- * @abstract
52
- */
53
- async createMapping(integrationId, sourceId, mapping) {
54
- throw new Error('createMapping must be implemented by subclass');
55
- }
56
-
57
42
  /**
58
43
  * Find all mappings for an integration
59
44
  *
@@ -1,5 +1,4 @@
1
1
  const { prisma } = require('../../database/prisma');
2
- const { MappingAlreadyExistsError } = require('../../errors');
3
2
  const {
4
3
  assertMappingWrittenUnencrypted,
5
4
  decryptQueriedMappings,
@@ -94,34 +93,6 @@ class IntegrationMappingRepositoryMongo extends IntegrationMappingRepositoryInte
94
93
  });
95
94
  }
96
95
 
97
- /**
98
- * Insert a mapping; fails if (integrationId, sourceId) already exists
99
- *
100
- * @param {string} integrationId - The integration ID
101
- * @param {string} sourceId - The source ID
102
- * @param {Object} mapping - The mapping data
103
- * @returns {Promise<Object>} The created mapping document
104
- * @throws {MappingAlreadyExistsError} If the pair already exists
105
- */
106
- async createMapping(integrationId, sourceId, mapping) {
107
- try {
108
- return await this.prisma.integrationMapping.create({
109
- data: {
110
- integrationId,
111
- sourceId: this._toString(sourceId),
112
- mapping,
113
- },
114
- });
115
- } catch (error) {
116
- if (error.code === 'P2002') {
117
- throw new MappingAlreadyExistsError(integrationId, sourceId, {
118
- cause: error,
119
- });
120
- }
121
- throw error;
122
- }
123
- }
124
-
125
96
  /**
126
97
  * Find all mappings for an integration
127
98
  * Replaces: IntegrationMapping.find({ integration: integrationId })
@@ -1,5 +1,4 @@
1
1
  const { prisma } = require('../../database/prisma');
2
- const { MappingAlreadyExistsError } = require('../../errors');
3
2
  const {
4
3
  assertMappingWrittenUnencrypted,
5
4
  decryptQueriedMappings,
@@ -151,35 +150,6 @@ class IntegrationMappingRepositoryPostgres extends IntegrationMappingRepositoryI
151
150
  return this._convertMappingIds(result);
152
151
  }
153
152
 
154
- /**
155
- * Insert a mapping; fails if (integrationId, sourceId) already exists
156
- *
157
- * @param {string} integrationId - The integration ID
158
- * @param {string} sourceId - The source ID
159
- * @param {Object} mapping - The mapping data
160
- * @returns {Promise<Object>} The created mapping document
161
- * @throws {MappingAlreadyExistsError} If the pair already exists
162
- */
163
- async createMapping(integrationId, sourceId, mapping) {
164
- try {
165
- const created = await this.prisma.integrationMapping.create({
166
- data: {
167
- integrationId: this._stringToInt(integrationId),
168
- sourceId: this._toString(sourceId),
169
- mapping,
170
- },
171
- });
172
- return this._convertMappingIds(created);
173
- } catch (error) {
174
- if (error.code === 'P2002') {
175
- throw new MappingAlreadyExistsError(integrationId, sourceId, {
176
- cause: error,
177
- });
178
- }
179
- throw error;
180
- }
181
- }
182
-
183
153
  /**
184
154
  * Find all mappings for an integration
185
155
  * Replaces: IntegrationMapping.find({ integration: integrationId })
@@ -1,5 +1,4 @@
1
1
  const { prisma } = require('../../database/prisma');
2
- const { MappingAlreadyExistsError } = require('../../errors');
3
2
  const {
4
3
  IntegrationMappingRepositoryInterface,
5
4
  } = require('./integration-mapping-repository-interface');
@@ -70,34 +69,6 @@ class IntegrationMappingRepository extends IntegrationMappingRepositoryInterface
70
69
  });
71
70
  }
72
71
 
73
- /**
74
- * Insert a mapping; fails if (integrationId, sourceId) already exists
75
- *
76
- * @param {string} integrationId - The integration ID
77
- * @param {string} sourceId - The source ID
78
- * @param {Object} mapping - The mapping data
79
- * @returns {Promise<Object>} The created mapping document
80
- * @throws {MappingAlreadyExistsError} If the pair already exists
81
- */
82
- async createMapping(integrationId, sourceId, mapping) {
83
- try {
84
- return await this.prisma.integrationMapping.create({
85
- data: {
86
- integrationId,
87
- sourceId,
88
- mapping,
89
- },
90
- });
91
- } catch (error) {
92
- if (error.code === 'P2002') {
93
- throw new MappingAlreadyExistsError(integrationId, sourceId, {
94
- cause: error,
95
- });
96
- }
97
- throw error;
98
- }
99
- }
100
-
101
72
  /**
102
73
  * Find all mappings for an integration
103
74
  * Replaces: IntegrationMapping.find({ integration: integrationId })
@@ -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')
@@ -471,7 +419,7 @@ class IntegrationRepositoryMongo extends IntegrationRepositoryInterface {
471
419
  for (const [key, value] of Object.entries(patch)) {
472
420
  $set[`config.${key}`] = value;
473
421
  }
474
- $set.updatedAt = { $date: new Date().toISOString() };
422
+ $set.updatedAt = new Date();
475
423
 
476
424
  const result = await this.prisma.$runCommandRaw({
477
425
  findAndModify: 'Integration',
@@ -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
  *
@@ -120,7 +120,7 @@ class ProcessRepositoryMongo extends ProcessRepositoryInterface {
120
120
  if (normalized.newState !== null) {
121
121
  $set.state = normalized.newState;
122
122
  }
123
- $set.updatedAt = { $date: new Date().toISOString() };
123
+ $set.updatedAt = new Date();
124
124
  update.$set = $set;
125
125
 
126
126
  if (Object.keys(normalized.pushSlice).length > 0) {