@friggframework/core 2.0.0--canary.522.cbd3d5a.0 → 2.0.0--canary.517.35ee143.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/CHANGELOG.md +67 -66
- package/CLAUDE.md +124 -148
- package/README.md +130 -165
- package/admin-scripts/index.js +16 -30
- package/admin-scripts/repositories/{admin-api-key-repository-documentdb.js → admin-process-repository-documentdb.js} +5 -5
- package/admin-scripts/repositories/{admin-api-key-repository-factory.js → admin-process-repository-factory.js} +15 -19
- package/admin-scripts/repositories/admin-process-repository-interface.js +150 -0
- package/admin-scripts/repositories/admin-process-repository-mongo.js +213 -0
- package/admin-scripts/repositories/admin-process-repository-postgres.js +251 -0
- package/admin-scripts/repositories/script-schedule-repository-factory.js +2 -6
- package/admin-scripts/repositories/script-schedule-repository-interface.js +14 -36
- package/admin-scripts/repositories/script-schedule-repository-mongo.js +13 -25
- package/admin-scripts/repositories/script-schedule-repository-postgres.js +13 -25
- package/application/commands/admin-script-commands.js +102 -266
- package/application/commands/integration-commands.js +6 -12
- package/application/index.js +3 -1
- package/assertions/get.js +4 -1
- package/associations/association.js +57 -59
- package/associations/model.js +41 -41
- package/core/CLAUDE.md +156 -222
- package/core/Worker.js +1 -5
- package/credential/repositories/credential-repository-documentdb.js +1 -71
- package/credential/repositories/credential-repository-interface.js +2 -8
- package/credential/repositories/credential-repository-mongo.js +4 -45
- package/credential/repositories/credential-repository-postgres.js +3 -44
- package/credential/repositories/credential-repository.js +4 -6
- package/credential/use-cases/get-credential-for-user.js +3 -21
- package/credential/use-cases/update-authentication-status.js +2 -5
- package/database/MONGODB_TRANSACTION_FIX.md +52 -72
- package/database/adapters/lambda-invoker.js +7 -8
- package/database/config.js +13 -15
- package/database/documentdb-encryption-service.js +13 -29
- package/database/documentdb-utils.js +12 -21
- package/database/encryption/README.md +36 -53
- package/database/encryption/encryption-schema-registry.js +9 -21
- package/database/encryption/field-encryption-service.js +4 -15
- package/database/encryption/logger.js +2 -3
- package/database/encryption/prisma-encryption-extension.js +8 -5
- package/database/index.js +2 -4
- package/database/models/IndividualUser.js +15 -15
- package/database/models/OrganizationUser.js +4 -6
- package/database/models/UserModel.js +2 -2
- package/database/models/WebsocketConnection.js +1 -4
- package/database/mongoose.js +2 -2
- package/database/prisma.js +14 -22
- package/database/repositories/health-check-repository-documentdb.js +7 -22
- package/database/repositories/health-check-repository-factory.js +3 -9
- package/database/repositories/health-check-repository-interface.js +5 -15
- package/database/repositories/health-check-repository-mongodb.js +6 -9
- package/database/repositories/health-check-repository-postgres.js +1 -1
- package/database/repositories/migration-status-repository-s3.js +5 -10
- package/database/use-cases/check-database-health-use-case.js +2 -3
- package/database/use-cases/check-database-state-use-case.js +7 -9
- package/database/use-cases/get-database-state-via-worker-use-case.js +12 -15
- package/database/use-cases/get-migration-status-use-case.js +2 -4
- package/database/use-cases/run-database-migration-use-case.js +9 -41
- package/database/use-cases/test-encryption-use-case.js +5 -4
- package/database/use-cases/trigger-database-migration-use-case.js +8 -9
- package/database/utils/mongodb-collection-utils.js +3 -11
- package/database/utils/mongodb-schema-init.js +4 -10
- package/database/utils/prisma-runner.js +74 -144
- package/database/utils/prisma-schema-parser.js +2 -2
- package/docs/PROCESS_MANAGEMENT_QUEUE_SPEC.md +80 -135
- package/encrypt/Cryptor.js +2 -8
- package/errors/fetch-error.js +1 -1
- package/generated/prisma-mongodb/edge.js +16 -59
- package/generated/prisma-mongodb/index-browser.js +12 -62
- package/generated/prisma-mongodb/index.d.ts +4850 -8136
- package/generated/prisma-mongodb/index.js +16 -59
- package/generated/prisma-mongodb/package.json +1 -1
- package/generated/prisma-mongodb/schema.prisma +33 -75
- package/generated/prisma-mongodb/wasm.js +16 -59
- package/generated/prisma-postgresql/edge.js +15 -59
- package/generated/prisma-postgresql/index-browser.js +11 -62
- package/generated/prisma-postgresql/index.d.ts +5963 -8930
- package/generated/prisma-postgresql/index.js +15 -59
- package/generated/prisma-postgresql/package.json +1 -1
- package/generated/prisma-postgresql/schema.prisma +33 -73
- package/generated/prisma-postgresql/wasm.js +15 -59
- package/handlers/WEBHOOKS.md +81 -104
- package/handlers/app-definition-loader.js +1 -1
- package/handlers/app-handler-helpers.js +2 -14
- package/handlers/backend-utils.js +1 -0
- package/handlers/database-migration-handler.js +45 -64
- package/handlers/middleware/admin-auth.js +53 -0
- package/handlers/routers/HEALTHCHECK.md +135 -170
- package/handlers/routers/auth.js +2 -23
- package/handlers/routers/db-migration.handler.js +3 -2
- package/handlers/routers/db-migration.js +33 -69
- package/handlers/routers/health.js +8 -23
- package/handlers/routers/integration-defined-routers.js +4 -4
- package/handlers/routers/integration-webhook-routers.js +7 -17
- package/handlers/routers/websocket.js +3 -9
- package/handlers/use-cases/check-integrations-health-use-case.js +6 -13
- package/handlers/workers/db-migration.js +26 -54
- package/index.js +9 -5
- package/integrations/WEBHOOK-QUICKSTART.md +14 -21
- package/integrations/index.js +0 -4
- package/integrations/integration-base.js +6 -9
- package/integrations/integration-router.js +146 -1817
- package/integrations/options.js +20 -47
- package/integrations/repositories/integration-repository-documentdb.js +24 -53
- package/integrations/repositories/integration-repository-factory.js +2 -6
- package/integrations/repositories/integration-repository-interface.js +9 -27
- package/integrations/repositories/integration-repository-postgres.js +3 -3
- package/integrations/repositories/process-repository-factory.js +1 -0
- package/integrations/repositories/process-repository-interface.js +5 -9
- package/integrations/repositories/process-repository-mongo.js +3 -7
- package/integrations/repositories/process-repository-postgres.js +2 -2
- package/integrations/tests/doubles/config-capturing-integration.js +8 -9
- package/integrations/tests/doubles/dummy-integration-class.js +8 -81
- package/integrations/tests/doubles/test-integration-repository.js +11 -51
- package/integrations/use-cases/create-integration.js +32 -36
- package/integrations/use-cases/create-process.js +9 -20
- package/integrations/use-cases/delete-integration-for-user.js +4 -5
- package/integrations/use-cases/get-integration-for-user.js +10 -25
- package/integrations/use-cases/get-integration-instance-by-definition.js +7 -13
- package/integrations/use-cases/get-integrations-for-user.js +1 -4
- package/integrations/use-cases/get-possible-integrations.js +1 -1
- package/integrations/use-cases/get-process.js +6 -5
- package/integrations/use-cases/index.js +1 -3
- package/integrations/use-cases/load-integration-context.js +5 -1
- package/integrations/use-cases/update-process-state.js +8 -10
- package/integrations/utils/map-integration-dto.js +3 -9
- package/jest-setup.js +1 -1
- package/jest-teardown.js +1 -1
- package/lambda/TimeoutCatcher.js +30 -32
- package/lambda/index.js +1 -1
- package/logs/index.js +3 -3
- package/modules/module.js +1 -3
- package/modules/repositories/module-repository-documentdb.js +48 -114
- package/modules/repositories/module-repository-interface.js +0 -13
- package/modules/repositories/module-repository-mongo.js +6 -46
- package/modules/repositories/module-repository-postgres.js +6 -48
- package/modules/repositories/module-repository.js +1 -34
- package/modules/requester/api-key.js +2 -0
- package/modules/requester/basic.js +1 -0
- package/modules/requester/oauth-2.js +2 -3
- package/modules/test/mock-api/definition.js +10 -15
- package/modules/test/mock-api/mocks/hubspot.js +36 -36
- package/modules/tests/doubles/test-module-factory.js +4 -10
- package/modules/tests/doubles/test-module-repository.js +1 -1
- package/modules/use-cases/get-entities-for-user.js +1 -1
- package/modules/use-cases/get-entity-options-by-id.js +6 -8
- package/modules/use-cases/get-module.js +9 -12
- package/modules/use-cases/process-authorization-callback.js +6 -12
- package/modules/use-cases/refresh-entity-options.js +6 -8
- package/modules/use-cases/test-module-auth.js +6 -8
- package/modules/utils/map-module-dto.js +2 -2
- package/package.json +5 -7
- package/prisma-mongodb/schema.prisma +33 -75
- package/prisma-postgresql/schema.prisma +33 -73
- package/queues/queuer-util.js +1 -5
- package/syncs/model.js +51 -51
- package/syncs/repositories/sync-repository-documentdb.js +19 -39
- package/syncs/repositories/sync-repository-interface.js +2 -6
- package/syncs/repositories/sync-repository-postgres.js +13 -19
- package/syncs/sync.js +100 -104
- package/token/repositories/token-repository-factory.js +3 -1
- package/types/assertions/index.d.ts +72 -72
- package/types/associations/index.d.ts +57 -57
- package/types/core/index.d.ts +53 -59
- package/types/database/index.d.ts +2 -2
- package/types/encrypt/index.d.ts +3 -3
- package/types/errors/index.d.ts +54 -61
- package/types/eslint-config/index.d.ts +40 -40
- package/types/integrations/index.d.ts +183 -185
- package/types/lambda/index.d.ts +26 -26
- package/types/logs/index.d.ts +4 -4
- package/types/module-plugin/index.d.ts +237 -239
- package/types/prettier-config/index.d.ts +5 -5
- package/types/syncs/index.d.ts +108 -102
- package/types/test-environment/index.d.ts +14 -14
- package/types/tsconfig.json +93 -95
- package/user/tests/doubles/test-user-repository.js +2 -5
- package/user/use-cases/authenticate-user.js +4 -2
- package/user/use-cases/authenticate-with-shared-secret.js +1 -1
- package/user/use-cases/create-individual-user.js +7 -8
- package/user/use-cases/create-organization-user.js +1 -1
- package/user/use-cases/create-token-for-user-id.js +1 -1
- package/user/use-cases/get-user-from-adopter-jwt.js +2 -0
- package/user/use-cases/get-user-from-bearer-token.js +3 -7
- package/user/use-cases/get-user-from-x-frigg-headers.js +11 -14
- package/user/use-cases/login-user.js +8 -8
- package/user/user.js +4 -18
- package/utils/backend-path.js +2 -2
- package/utils/index.js +1 -4
- package/websocket/repositories/websocket-connection-repository-documentdb.js +8 -21
- package/websocket/repositories/websocket-connection-repository-mongo.js +4 -8
- package/websocket/repositories/websocket-connection-repository-postgres.js +4 -8
- package/websocket/repositories/websocket-connection-repository.js +4 -8
- package/admin-scripts/repositories/admin-api-key-repository-interface.js +0 -121
- package/admin-scripts/repositories/admin-api-key-repository-mongo.js +0 -155
- package/admin-scripts/repositories/admin-api-key-repository-postgres.js +0 -189
- package/admin-scripts/repositories/script-execution-repository-documentdb.js +0 -21
- package/admin-scripts/repositories/script-execution-repository-factory.js +0 -55
- package/admin-scripts/repositories/script-execution-repository-interface.js +0 -193
- package/admin-scripts/repositories/script-execution-repository-mongo.js +0 -278
- package/admin-scripts/repositories/script-execution-repository-postgres.js +0 -320
- package/credential/credential-router.js +0 -262
- package/credential/use-cases/delete-credential-for-user.js +0 -50
- package/credential/use-cases/list-credentials-for-user.js +0 -31
- package/credential/use-cases/reauthorize-credential.js +0 -103
- package/handlers/routers/admin.js +0 -450
- package/handlers/routers/docs.js +0 -180
- package/handlers/routers/middleware/loadUser.js +0 -39
- package/handlers/routers/middleware/requireAdmin.js +0 -41
- package/handlers/routers/middleware/requireLoggedInUser.js +0 -19
- package/integrations/use-cases/execute-proxy-request.js +0 -564
- package/modules/domain/entities/AuthorizationSession.js +0 -131
- package/modules/domain/entities/index.js +0 -10
- package/modules/repositories/authorization-session-repository-factory.js +0 -55
- package/modules/repositories/authorization-session-repository-interface.js +0 -75
- package/modules/repositories/authorization-session-repository-mongo.js +0 -169
- package/modules/repositories/authorization-session-repository-postgres.js +0 -170
- package/modules/use-cases/delete-module-entity.js +0 -23
- package/modules/use-cases/get-authorization-requirements.js +0 -110
- package/modules/use-cases/get-module-entity-by-id.js +0 -16
- package/modules/use-cases/process-authorization-step.js +0 -160
- package/modules/use-cases/start-authorization-session.js +0 -86
- package/modules/use-cases/update-module-entity.js +0 -27
- package/openapi/openapi-spec-generator.js +0 -370
- package/openapi/openapi-v1.yaml +0 -1360
- package/openapi/openapi-v2.yaml +0 -1535
- package/user/use-cases/delete-user.js +0 -47
|
@@ -78,26 +78,6 @@ model Token {
|
|
|
78
78
|
@@index([expires])
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
/// Multi-step authorization session tracking
|
|
82
|
-
/// Supports OTP flows and multi-stage authentication (e.g., Nagaris)
|
|
83
|
-
model AuthorizationSession {
|
|
84
|
-
id Int @id @default(autoincrement())
|
|
85
|
-
sessionId String @unique
|
|
86
|
-
userId String
|
|
87
|
-
entityType String
|
|
88
|
-
currentStep Int @default(1)
|
|
89
|
-
maxSteps Int
|
|
90
|
-
stepData Json @default("{}")
|
|
91
|
-
expiresAt DateTime
|
|
92
|
-
completed Boolean @default(false)
|
|
93
|
-
createdAt DateTime @default(now())
|
|
94
|
-
updatedAt DateTime @updatedAt
|
|
95
|
-
|
|
96
|
-
@@index([sessionId])
|
|
97
|
-
@@index([userId, entityType])
|
|
98
|
-
@@index([expiresAt])
|
|
99
|
-
}
|
|
100
|
-
|
|
101
81
|
// ============================================================================
|
|
102
82
|
// CREDENTIAL & ENTITY MODELS
|
|
103
83
|
// ============================================================================
|
|
@@ -135,7 +115,6 @@ model Entity {
|
|
|
135
115
|
name String?
|
|
136
116
|
moduleName String?
|
|
137
117
|
externalId String?
|
|
138
|
-
isGlobal Boolean @default(false)
|
|
139
118
|
|
|
140
119
|
createdAt DateTime @default(now())
|
|
141
120
|
updatedAt DateTime @updatedAt
|
|
@@ -151,8 +130,6 @@ model Entity {
|
|
|
151
130
|
@@index([externalId])
|
|
152
131
|
@@index([moduleName])
|
|
153
132
|
@@index([credentialId])
|
|
154
|
-
@@index([isGlobal])
|
|
155
|
-
@@index([isGlobal, moduleName])
|
|
156
133
|
}
|
|
157
134
|
|
|
158
135
|
// ============================================================================
|
|
@@ -366,68 +343,51 @@ model WebsocketConnection {
|
|
|
366
343
|
}
|
|
367
344
|
|
|
368
345
|
// ============================================================================
|
|
369
|
-
// ADMIN
|
|
346
|
+
// ADMIN PROCESS MODELS
|
|
370
347
|
// ============================================================================
|
|
371
348
|
|
|
372
|
-
|
|
349
|
+
/// Admin process state machine
|
|
350
|
+
enum AdminProcessState {
|
|
373
351
|
PENDING
|
|
374
352
|
RUNNING
|
|
375
353
|
COMPLETED
|
|
376
354
|
FAILED
|
|
377
|
-
TIMEOUT
|
|
378
|
-
CANCELLED
|
|
379
355
|
}
|
|
380
356
|
|
|
381
|
-
|
|
357
|
+
/// Admin trigger types
|
|
358
|
+
enum AdminTrigger {
|
|
382
359
|
MANUAL
|
|
383
360
|
SCHEDULED
|
|
384
361
|
QUEUE
|
|
385
362
|
WEBHOOK
|
|
386
363
|
}
|
|
387
364
|
|
|
388
|
-
/// Admin
|
|
389
|
-
///
|
|
390
|
-
model
|
|
391
|
-
id
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
name String
|
|
395
|
-
scopes String[]
|
|
396
|
-
expiresAt DateTime?
|
|
397
|
-
createdBy String?
|
|
398
|
-
lastUsedAt DateTime?
|
|
399
|
-
isActive Boolean @default(true)
|
|
400
|
-
createdAt DateTime @default(now())
|
|
401
|
-
updatedAt DateTime @updatedAt
|
|
402
|
-
|
|
403
|
-
@@index([isActive])
|
|
404
|
-
}
|
|
365
|
+
/// Admin process tracking (like Process but without user/integration FK)
|
|
366
|
+
/// Used for: admin scripts, db migrations, system maintenance tasks
|
|
367
|
+
model AdminProcess {
|
|
368
|
+
id Int @id @default(autoincrement())
|
|
369
|
+
name String // e.g., "oauth-token-refresh", "db-migration-xyz"
|
|
370
|
+
type String // e.g., "ADMIN_SCRIPT", "DB_MIGRATION"
|
|
405
371
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
auditIpAddress String?
|
|
426
|
-
createdAt DateTime @default(now())
|
|
427
|
-
updatedAt DateTime @updatedAt
|
|
428
|
-
|
|
429
|
-
@@index([scriptName, createdAt(sort: Desc)])
|
|
430
|
-
@@index([status])
|
|
372
|
+
// State machine
|
|
373
|
+
state AdminProcessState @default(PENDING)
|
|
374
|
+
|
|
375
|
+
// Flexible storage (mirrors Process model pattern)
|
|
376
|
+
context Json @default("{}") // input, trigger, audit info, script version
|
|
377
|
+
results Json @default("{}") // output, logs, metrics, errors
|
|
378
|
+
|
|
379
|
+
// Hierarchy support - self-referential relation
|
|
380
|
+
parentProcessId Int?
|
|
381
|
+
parentProcess AdminProcess? @relation("AdminProcessHierarchy", fields: [parentProcessId], references: [id], onDelete: SetNull)
|
|
382
|
+
childProcesses AdminProcess[] @relation("AdminProcessHierarchy")
|
|
383
|
+
|
|
384
|
+
// Timestamps
|
|
385
|
+
createdAt DateTime @default(now())
|
|
386
|
+
updatedAt DateTime @updatedAt
|
|
387
|
+
|
|
388
|
+
@@index([name, createdAt(sort: Desc)])
|
|
389
|
+
@@index([state])
|
|
390
|
+
@@index([type])
|
|
431
391
|
}
|
|
432
392
|
|
|
433
393
|
/// Script scheduling configuration for hybrid scheduling (SQS + EventBridge)
|
|
@@ -440,9 +400,9 @@ model ScriptSchedule {
|
|
|
440
400
|
lastTriggeredAt DateTime?
|
|
441
401
|
nextTriggerAt DateTime?
|
|
442
402
|
|
|
443
|
-
// AWS EventBridge
|
|
444
|
-
|
|
445
|
-
|
|
403
|
+
// External Scheduler (e.g., AWS EventBridge Scheduler)
|
|
404
|
+
externalScheduleId String?
|
|
405
|
+
externalScheduleName String?
|
|
446
406
|
|
|
447
407
|
createdAt DateTime @default(now())
|
|
448
408
|
updatedAt DateTime @updatedAt
|
package/queues/queuer-util.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
const { v4: uuid } = require('uuid');
|
|
2
|
-
const {
|
|
3
|
-
SQSClient,
|
|
4
|
-
SendMessageCommand,
|
|
5
|
-
SendMessageBatchCommand,
|
|
6
|
-
} = require('@aws-sdk/client-sqs');
|
|
2
|
+
const { SQSClient, SendMessageCommand, SendMessageBatchCommand } = require('@aws-sdk/client-sqs');
|
|
7
3
|
|
|
8
4
|
const awsConfigOptions = () => {
|
|
9
5
|
const config = {};
|
package/syncs/model.js
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
const mongoose = require(
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
2
|
|
|
3
3
|
const schema = new mongoose.Schema({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
4
|
+
entities: [
|
|
5
|
+
{ type: mongoose.Schema.Types.ObjectId, ref: "Entity", required: true },
|
|
6
|
+
],
|
|
7
|
+
hash: { type: String, required: true },
|
|
8
|
+
name: { type: String, required: true },
|
|
9
|
+
dataIdentifiers: [
|
|
10
|
+
{
|
|
11
|
+
entity: {
|
|
12
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
13
|
+
ref: "Entity",
|
|
14
|
+
required: true,
|
|
15
|
+
},
|
|
16
|
+
id: { type: Object, required: true },
|
|
17
|
+
hash: { type: String, required: true },
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
schema.statics({
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
getSyncObject: async function (name, dataIdentifier, entity) {
|
|
24
|
+
// const syncList = await this.list({name:name,entities: {"$in": entities}, "entityIds.idHash":entityIdHash });
|
|
25
|
+
const syncList = await this.find({
|
|
26
|
+
name: name,
|
|
27
|
+
dataIdentifiers: { $elemMatch: { id: dataIdentifier, entity } },
|
|
28
|
+
});
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
if (syncList.length === 1) {
|
|
31
|
+
return syncList[0];
|
|
32
|
+
} else if (syncList.length === 0) {
|
|
33
|
+
return null;
|
|
34
|
+
} else {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`There are multiple sync objects with the name ${name}, for entities [${syncList[0].entities}] [${syncList[1].entities}]`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
addDataIdentifier: async function (id, dataIdentifier) {
|
|
42
|
+
return await this.update(
|
|
43
|
+
{ _id: id },
|
|
44
|
+
{},
|
|
45
|
+
{ dataIdentifiers: dataIdentifier }
|
|
46
|
+
);
|
|
47
|
+
},
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
getEntityObjIdForEntityIdFromObject: function (syncObj, entityId) {
|
|
50
|
+
for (let dataIdentifier of syncObj.dataIdentifiers) {
|
|
51
|
+
if (dataIdentifier.entity.toString() === entityId) {
|
|
52
|
+
return dataIdentifier.id;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
throw new Error(
|
|
56
|
+
`Sync object does not have DataIdentifier for entityId: ${entityId}`
|
|
57
|
+
);
|
|
58
|
+
},
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
const Sync = mongoose.models.Sync || mongoose.model(
|
|
61
|
+
const Sync = mongoose.models.Sync || mongoose.model("Sync", schema);
|
|
62
62
|
module.exports = { Sync };
|
|
@@ -69,9 +69,7 @@ class SyncRepositoryDocumentDB extends SyncRepositoryInterface {
|
|
|
69
69
|
$set: documentData,
|
|
70
70
|
}
|
|
71
71
|
);
|
|
72
|
-
const updated = await findOne(this.prisma, 'Sync', {
|
|
73
|
-
_id: existing._id,
|
|
74
|
-
});
|
|
72
|
+
const updated = await findOne(this.prisma, 'Sync', { _id: existing._id });
|
|
75
73
|
return this._mapSync(updated);
|
|
76
74
|
}
|
|
77
75
|
|
|
@@ -105,9 +103,7 @@ class SyncRepositoryDocumentDB extends SyncRepositoryInterface {
|
|
|
105
103
|
const doc = await findOne(this.prisma, 'Sync', { _id: syncObjectId });
|
|
106
104
|
if (!doc) return null;
|
|
107
105
|
|
|
108
|
-
const identifiers = Array.isArray(doc.dataIdentifiers)
|
|
109
|
-
? [...doc.dataIdentifiers]
|
|
110
|
-
: [];
|
|
106
|
+
const identifiers = Array.isArray(doc.dataIdentifiers) ? [...doc.dataIdentifiers] : [];
|
|
111
107
|
identifiers.push({
|
|
112
108
|
syncId: syncObjectId,
|
|
113
109
|
entityId: toObjectId(dataIdentifier.entity),
|
|
@@ -128,9 +124,7 @@ class SyncRepositoryDocumentDB extends SyncRepositoryInterface {
|
|
|
128
124
|
}
|
|
129
125
|
);
|
|
130
126
|
|
|
131
|
-
const updated = await findOne(this.prisma, 'Sync', {
|
|
132
|
-
_id: syncObjectId,
|
|
133
|
-
});
|
|
127
|
+
const updated = await findOne(this.prisma, 'Sync', { _id: syncObjectId });
|
|
134
128
|
return updated ? this._mapSync(updated) : null;
|
|
135
129
|
}
|
|
136
130
|
|
|
@@ -140,8 +134,7 @@ class SyncRepositoryDocumentDB extends SyncRepositoryInterface {
|
|
|
140
134
|
}
|
|
141
135
|
|
|
142
136
|
const entry = syncObj.dataIdentifiers.find(
|
|
143
|
-
(identifier) =>
|
|
144
|
-
fromObjectId(identifier.entityId) === String(entityId)
|
|
137
|
+
(identifier) => fromObjectId(identifier.entityId) === String(entityId)
|
|
145
138
|
);
|
|
146
139
|
|
|
147
140
|
if (entry) {
|
|
@@ -185,9 +178,7 @@ class SyncRepositoryDocumentDB extends SyncRepositoryInterface {
|
|
|
185
178
|
query.integrationId = toObjectId(filter.integrationId);
|
|
186
179
|
}
|
|
187
180
|
if (filter.entities) {
|
|
188
|
-
query.entityIds = (filter.entities || [])
|
|
189
|
-
.map((id) => toObjectId(id))
|
|
190
|
-
.filter(Boolean);
|
|
181
|
+
query.entityIds = (filter.entities || []).map((id) => toObjectId(id)).filter(Boolean);
|
|
191
182
|
delete query.entities;
|
|
192
183
|
}
|
|
193
184
|
return query;
|
|
@@ -199,11 +190,8 @@ class SyncRepositoryDocumentDB extends SyncRepositoryInterface {
|
|
|
199
190
|
prepared.integrationId = toObjectId(data.integrationId);
|
|
200
191
|
}
|
|
201
192
|
if (data.entities !== undefined || data.entityIds !== undefined) {
|
|
202
|
-
const list =
|
|
203
|
-
|
|
204
|
-
prepared.entityIds = (list || [])
|
|
205
|
-
.map((id) => toObjectId(id))
|
|
206
|
-
.filter(Boolean);
|
|
193
|
+
const list = data.entities !== undefined ? data.entities : data.entityIds;
|
|
194
|
+
prepared.entityIds = (list || []).map((id) => toObjectId(id)).filter(Boolean);
|
|
207
195
|
}
|
|
208
196
|
if (data.hash !== undefined) prepared.hash = data.hash;
|
|
209
197
|
if (data.name !== undefined) prepared.name = data.name;
|
|
@@ -211,17 +199,13 @@ class SyncRepositoryDocumentDB extends SyncRepositoryInterface {
|
|
|
211
199
|
if (data.results !== undefined) prepared.results = data.results;
|
|
212
200
|
if (timestamp) prepared.updatedAt = timestamp;
|
|
213
201
|
if (data.dataIdentifiers !== undefined) {
|
|
214
|
-
prepared.dataIdentifiers = (data.dataIdentifiers || []).map(
|
|
215
|
-
(identifier)
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
? new Date(identifier.createdAt)
|
|
222
|
-
: new Date(),
|
|
223
|
-
})
|
|
224
|
-
);
|
|
202
|
+
prepared.dataIdentifiers = (data.dataIdentifiers || []).map((identifier) => ({
|
|
203
|
+
syncId: toObjectId(identifier.syncId),
|
|
204
|
+
entityId: toObjectId(identifier.entityId),
|
|
205
|
+
idData: identifier.idData,
|
|
206
|
+
hash: identifier.hash,
|
|
207
|
+
createdAt: identifier.createdAt ? new Date(identifier.createdAt) : new Date(),
|
|
208
|
+
}));
|
|
225
209
|
}
|
|
226
210
|
return prepared;
|
|
227
211
|
}
|
|
@@ -230,9 +214,7 @@ class SyncRepositoryDocumentDB extends SyncRepositoryInterface {
|
|
|
230
214
|
if (!doc) return null;
|
|
231
215
|
return {
|
|
232
216
|
id: fromObjectId(doc._id),
|
|
233
|
-
integrationId: doc.integrationId
|
|
234
|
-
? fromObjectId(doc.integrationId)
|
|
235
|
-
: null,
|
|
217
|
+
integrationId: doc.integrationId ? fromObjectId(doc.integrationId) : null,
|
|
236
218
|
entities: Array.isArray(doc.entityIds)
|
|
237
219
|
? doc.entityIds.map((id) => fromObjectId(id))
|
|
238
220
|
: [],
|
|
@@ -243,12 +225,8 @@ class SyncRepositoryDocumentDB extends SyncRepositoryInterface {
|
|
|
243
225
|
name: doc.name ?? null,
|
|
244
226
|
dataIdentifiers: Array.isArray(doc.dataIdentifiers)
|
|
245
227
|
? doc.dataIdentifiers.map((identifier) => ({
|
|
246
|
-
syncId: identifier.syncId
|
|
247
|
-
|
|
248
|
-
: null,
|
|
249
|
-
entityId: identifier.entityId
|
|
250
|
-
? fromObjectId(identifier.entityId)
|
|
251
|
-
: null,
|
|
228
|
+
syncId: identifier.syncId ? fromObjectId(identifier.syncId) : null,
|
|
229
|
+
entityId: identifier.entityId ? fromObjectId(identifier.entityId) : null,
|
|
252
230
|
idData: identifier.idData,
|
|
253
231
|
hash: identifier.hash,
|
|
254
232
|
}))
|
|
@@ -258,3 +236,5 @@ class SyncRepositoryDocumentDB extends SyncRepositoryInterface {
|
|
|
258
236
|
}
|
|
259
237
|
|
|
260
238
|
module.exports = { SyncRepositoryDocumentDB };
|
|
239
|
+
|
|
240
|
+
|
|
@@ -56,9 +56,7 @@ class SyncRepositoryInterface {
|
|
|
56
56
|
* @abstract
|
|
57
57
|
*/
|
|
58
58
|
async addDataIdentifier(syncId, dataIdentifier) {
|
|
59
|
-
throw new Error(
|
|
60
|
-
'Method addDataIdentifier must be implemented by subclass'
|
|
61
|
-
);
|
|
59
|
+
throw new Error('Method addDataIdentifier must be implemented by subclass');
|
|
62
60
|
}
|
|
63
61
|
|
|
64
62
|
/**
|
|
@@ -71,9 +69,7 @@ class SyncRepositoryInterface {
|
|
|
71
69
|
* @abstract
|
|
72
70
|
*/
|
|
73
71
|
getEntityObjIdForEntityIdFromObject(syncObj, entityId) {
|
|
74
|
-
throw new Error(
|
|
75
|
-
'Method getEntityObjIdForEntityIdFromObject must be implemented by subclass'
|
|
76
|
-
);
|
|
72
|
+
throw new Error('Method getEntityObjIdForEntityIdFromObject must be implemented by subclass');
|
|
77
73
|
}
|
|
78
74
|
|
|
79
75
|
/**
|
|
@@ -46,26 +46,24 @@ class SyncRepositoryPostgres extends SyncRepositoryInterface {
|
|
|
46
46
|
...sync,
|
|
47
47
|
id: sync.id?.toString(),
|
|
48
48
|
integrationId: sync.integrationId?.toString(),
|
|
49
|
-
entities: sync.entities?.map(
|
|
49
|
+
entities: sync.entities?.map(e => ({
|
|
50
50
|
...e,
|
|
51
51
|
id: e.id?.toString(),
|
|
52
52
|
userId: e.userId?.toString(),
|
|
53
|
-
credentialId: e.credentialId?.toString()
|
|
53
|
+
credentialId: e.credentialId?.toString()
|
|
54
54
|
})),
|
|
55
|
-
dataIdentifiers: sync.dataIdentifiers?.map(
|
|
55
|
+
dataIdentifiers: sync.dataIdentifiers?.map(di => ({
|
|
56
56
|
...di,
|
|
57
57
|
id: di.id?.toString(),
|
|
58
58
|
syncId: di.syncId?.toString(),
|
|
59
59
|
entityId: di.entityId?.toString(),
|
|
60
|
-
entity: di.entity
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
: di.entity,
|
|
68
|
-
})),
|
|
60
|
+
entity: di.entity ? {
|
|
61
|
+
...di.entity,
|
|
62
|
+
id: di.entity.id?.toString(),
|
|
63
|
+
userId: di.entity.userId?.toString(),
|
|
64
|
+
credentialId: di.entity.credentialId?.toString()
|
|
65
|
+
} : di.entity
|
|
66
|
+
}))
|
|
69
67
|
};
|
|
70
68
|
}
|
|
71
69
|
|
|
@@ -125,9 +123,7 @@ class SyncRepositoryPostgres extends SyncRepositoryInterface {
|
|
|
125
123
|
// Convert IDs in syncData if present
|
|
126
124
|
const convertedData = { ...syncData };
|
|
127
125
|
if (convertedData.integrationId) {
|
|
128
|
-
convertedData.integrationId = this._convertId(
|
|
129
|
-
convertedData.integrationId
|
|
130
|
-
);
|
|
126
|
+
convertedData.integrationId = this._convertId(convertedData.integrationId);
|
|
131
127
|
}
|
|
132
128
|
|
|
133
129
|
if (existing) {
|
|
@@ -159,9 +155,7 @@ class SyncRepositoryPostgres extends SyncRepositoryInterface {
|
|
|
159
155
|
// Convert IDs in updates if present
|
|
160
156
|
const convertedUpdates = { ...updates };
|
|
161
157
|
if (convertedUpdates.integrationId) {
|
|
162
|
-
convertedUpdates.integrationId = this._convertId(
|
|
163
|
-
convertedUpdates.integrationId
|
|
164
|
-
);
|
|
158
|
+
convertedUpdates.integrationId = this._convertId(convertedUpdates.integrationId);
|
|
165
159
|
}
|
|
166
160
|
|
|
167
161
|
const updated = await this.prisma.sync.update({
|
|
@@ -247,7 +241,7 @@ class SyncRepositoryPostgres extends SyncRepositoryInterface {
|
|
|
247
241
|
},
|
|
248
242
|
},
|
|
249
243
|
});
|
|
250
|
-
return syncs.map(
|
|
244
|
+
return syncs.map(sync => this._convertSyncIds(sync));
|
|
251
245
|
}
|
|
252
246
|
|
|
253
247
|
/**
|