@friggframework/core 2.0.0-next.6 → 2.0.0-next.60
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 +694 -0
- package/README.md +959 -50
- package/application/commands/README.md +451 -0
- package/application/commands/credential-commands.js +245 -0
- package/application/commands/entity-commands.js +336 -0
- package/application/commands/integration-commands.js +210 -0
- package/application/commands/user-commands.js +283 -0
- package/application/index.js +69 -0
- package/core/CLAUDE.md +690 -0
- package/core/Worker.js +8 -21
- package/core/create-handler.js +14 -7
- package/credential/repositories/credential-repository-documentdb.js +304 -0
- package/credential/repositories/credential-repository-factory.js +54 -0
- package/credential/repositories/credential-repository-interface.js +98 -0
- package/credential/repositories/credential-repository-mongo.js +269 -0
- package/credential/repositories/credential-repository-postgres.js +291 -0
- package/credential/repositories/credential-repository.js +302 -0
- package/credential/use-cases/get-credential-for-user.js +25 -0
- package/credential/use-cases/update-authentication-status.js +15 -0
- package/database/MONGODB_TRANSACTION_FIX.md +198 -0
- package/database/adapters/lambda-invoker.js +97 -0
- package/database/config.js +154 -0
- package/database/documentdb-encryption-service.js +330 -0
- package/database/documentdb-utils.js +136 -0
- package/database/encryption/README.md +839 -0
- package/database/encryption/documentdb-encryption-service.md +3575 -0
- package/database/encryption/encryption-schema-registry.js +268 -0
- package/database/encryption/field-encryption-service.js +226 -0
- package/database/encryption/logger.js +79 -0
- package/database/encryption/prisma-encryption-extension.js +222 -0
- package/database/index.js +61 -21
- package/database/models/WebsocketConnection.js +16 -10
- package/database/models/readme.md +1 -0
- package/database/prisma.js +182 -0
- package/database/repositories/health-check-repository-documentdb.js +134 -0
- package/database/repositories/health-check-repository-factory.js +48 -0
- package/database/repositories/health-check-repository-interface.js +82 -0
- package/database/repositories/health-check-repository-mongodb.js +89 -0
- package/database/repositories/health-check-repository-postgres.js +82 -0
- package/database/repositories/health-check-repository.js +108 -0
- package/database/repositories/migration-status-repository-s3.js +137 -0
- package/database/use-cases/check-database-health-use-case.js +29 -0
- package/database/use-cases/check-database-state-use-case.js +81 -0
- package/database/use-cases/check-encryption-health-use-case.js +83 -0
- package/database/use-cases/get-database-state-via-worker-use-case.js +61 -0
- package/database/use-cases/get-migration-status-use-case.js +93 -0
- package/database/use-cases/run-database-migration-use-case.js +139 -0
- package/database/use-cases/test-encryption-use-case.js +253 -0
- package/database/use-cases/trigger-database-migration-use-case.js +157 -0
- package/database/utils/mongodb-collection-utils.js +91 -0
- package/database/utils/mongodb-schema-init.js +106 -0
- package/database/utils/prisma-runner.js +477 -0
- package/database/utils/prisma-schema-parser.js +182 -0
- package/docs/PROCESS_MANAGEMENT_QUEUE_SPEC.md +517 -0
- package/encrypt/Cryptor.js +34 -168
- package/encrypt/index.js +1 -2
- package/encrypt/test-encrypt.js +0 -2
- package/errors/client-safe-error.js +26 -0
- package/errors/fetch-error.js +2 -1
- package/errors/index.js +2 -0
- package/generated/prisma-mongodb/client.d.ts +1 -0
- package/generated/prisma-mongodb/client.js +4 -0
- package/generated/prisma-mongodb/default.d.ts +1 -0
- package/generated/prisma-mongodb/default.js +4 -0
- package/generated/prisma-mongodb/edge.d.ts +1 -0
- package/generated/prisma-mongodb/edge.js +334 -0
- package/generated/prisma-mongodb/index-browser.js +316 -0
- package/generated/prisma-mongodb/index.d.ts +22903 -0
- package/generated/prisma-mongodb/index.js +359 -0
- package/generated/prisma-mongodb/package.json +183 -0
- package/generated/prisma-mongodb/query-engine-debian-openssl-3.0.x +0 -0
- package/generated/prisma-mongodb/query-engine-rhel-openssl-3.0.x +0 -0
- package/generated/prisma-mongodb/runtime/binary.d.ts +1 -0
- package/generated/prisma-mongodb/runtime/binary.js +289 -0
- package/generated/prisma-mongodb/runtime/edge-esm.js +34 -0
- package/generated/prisma-mongodb/runtime/edge.js +34 -0
- package/generated/prisma-mongodb/runtime/index-browser.d.ts +370 -0
- package/generated/prisma-mongodb/runtime/index-browser.js +16 -0
- package/generated/prisma-mongodb/runtime/library.d.ts +3977 -0
- package/generated/prisma-mongodb/runtime/react-native.js +83 -0
- package/generated/prisma-mongodb/runtime/wasm-compiler-edge.js +84 -0
- package/generated/prisma-mongodb/runtime/wasm-engine-edge.js +36 -0
- package/generated/prisma-mongodb/schema.prisma +360 -0
- package/generated/prisma-mongodb/wasm-edge-light-loader.mjs +4 -0
- package/generated/prisma-mongodb/wasm-worker-loader.mjs +4 -0
- package/generated/prisma-mongodb/wasm.d.ts +1 -0
- package/generated/prisma-mongodb/wasm.js +341 -0
- package/generated/prisma-postgresql/client.d.ts +1 -0
- package/generated/prisma-postgresql/client.js +4 -0
- package/generated/prisma-postgresql/default.d.ts +1 -0
- package/generated/prisma-postgresql/default.js +4 -0
- package/generated/prisma-postgresql/edge.d.ts +1 -0
- package/generated/prisma-postgresql/edge.js +356 -0
- package/generated/prisma-postgresql/index-browser.js +338 -0
- package/generated/prisma-postgresql/index.d.ts +25077 -0
- package/generated/prisma-postgresql/index.js +381 -0
- package/generated/prisma-postgresql/package.json +183 -0
- package/generated/prisma-postgresql/query-engine-debian-openssl-3.0.x +0 -0
- package/generated/prisma-postgresql/query-engine-rhel-openssl-3.0.x +0 -0
- package/generated/prisma-postgresql/query_engine_bg.js +2 -0
- package/generated/prisma-postgresql/query_engine_bg.wasm +0 -0
- package/generated/prisma-postgresql/runtime/binary.d.ts +1 -0
- package/generated/prisma-postgresql/runtime/binary.js +289 -0
- package/generated/prisma-postgresql/runtime/edge-esm.js +34 -0
- package/generated/prisma-postgresql/runtime/edge.js +34 -0
- package/generated/prisma-postgresql/runtime/index-browser.d.ts +370 -0
- package/generated/prisma-postgresql/runtime/index-browser.js +16 -0
- package/generated/prisma-postgresql/runtime/library.d.ts +3977 -0
- package/generated/prisma-postgresql/runtime/react-native.js +83 -0
- package/generated/prisma-postgresql/runtime/wasm-compiler-edge.js +84 -0
- package/generated/prisma-postgresql/runtime/wasm-engine-edge.js +36 -0
- package/generated/prisma-postgresql/schema.prisma +343 -0
- package/generated/prisma-postgresql/wasm-edge-light-loader.mjs +4 -0
- package/generated/prisma-postgresql/wasm-worker-loader.mjs +4 -0
- package/generated/prisma-postgresql/wasm.d.ts +1 -0
- package/generated/prisma-postgresql/wasm.js +363 -0
- package/handlers/WEBHOOKS.md +653 -0
- package/handlers/app-definition-loader.js +38 -0
- package/handlers/app-handler-helpers.js +56 -0
- package/handlers/backend-utils.js +186 -0
- package/handlers/database-migration-handler.js +227 -0
- package/handlers/integration-event-dispatcher.js +54 -0
- package/handlers/routers/HEALTHCHECK.md +342 -0
- package/handlers/routers/auth.js +15 -0
- package/handlers/routers/db-migration.handler.js +29 -0
- package/handlers/routers/db-migration.js +326 -0
- package/handlers/routers/health.js +516 -0
- package/handlers/routers/integration-defined-routers.js +45 -0
- package/handlers/routers/integration-webhook-routers.js +67 -0
- package/handlers/routers/user.js +63 -0
- package/handlers/routers/websocket.js +57 -0
- package/handlers/use-cases/check-external-apis-health-use-case.js +81 -0
- package/handlers/use-cases/check-integrations-health-use-case.js +44 -0
- package/handlers/workers/db-migration.js +352 -0
- package/handlers/workers/integration-defined-workers.js +27 -0
- package/index.js +77 -22
- package/integrations/WEBHOOK-QUICKSTART.md +151 -0
- package/integrations/index.js +12 -10
- package/integrations/integration-base.js +326 -55
- package/integrations/integration-router.js +374 -179
- package/integrations/options.js +1 -1
- package/integrations/repositories/integration-mapping-repository-documentdb.js +280 -0
- package/integrations/repositories/integration-mapping-repository-factory.js +57 -0
- package/integrations/repositories/integration-mapping-repository-interface.js +106 -0
- package/integrations/repositories/integration-mapping-repository-mongo.js +161 -0
- package/integrations/repositories/integration-mapping-repository-postgres.js +227 -0
- package/integrations/repositories/integration-mapping-repository.js +156 -0
- package/integrations/repositories/integration-repository-documentdb.js +210 -0
- package/integrations/repositories/integration-repository-factory.js +51 -0
- package/integrations/repositories/integration-repository-interface.js +127 -0
- package/integrations/repositories/integration-repository-mongo.js +303 -0
- package/integrations/repositories/integration-repository-postgres.js +352 -0
- package/integrations/repositories/process-repository-documentdb.js +243 -0
- package/integrations/repositories/process-repository-factory.js +53 -0
- package/integrations/repositories/process-repository-interface.js +90 -0
- package/integrations/repositories/process-repository-mongo.js +190 -0
- package/integrations/repositories/process-repository-postgres.js +217 -0
- package/integrations/tests/doubles/dummy-integration-class.js +83 -0
- package/integrations/tests/doubles/test-integration-repository.js +99 -0
- package/integrations/use-cases/create-integration.js +83 -0
- package/integrations/use-cases/create-process.js +128 -0
- package/integrations/use-cases/delete-integration-for-user.js +101 -0
- package/integrations/use-cases/find-integration-context-by-external-entity-id.js +72 -0
- package/integrations/use-cases/get-integration-for-user.js +78 -0
- package/integrations/use-cases/get-integration-instance-by-definition.js +67 -0
- package/integrations/use-cases/get-integration-instance.js +83 -0
- package/integrations/use-cases/get-integrations-for-user.js +88 -0
- package/integrations/use-cases/get-possible-integrations.js +27 -0
- package/integrations/use-cases/get-process.js +87 -0
- package/integrations/use-cases/index.js +19 -0
- package/integrations/use-cases/load-integration-context.js +71 -0
- package/integrations/use-cases/update-integration-messages.js +44 -0
- package/integrations/use-cases/update-integration-status.js +32 -0
- package/integrations/use-cases/update-integration.js +93 -0
- package/integrations/use-cases/update-process-metrics.js +201 -0
- package/integrations/use-cases/update-process-state.js +119 -0
- package/integrations/utils/map-integration-dto.js +37 -0
- package/jest-global-setup-noop.js +3 -0
- package/jest-global-teardown-noop.js +3 -0
- package/logs/logger.js +0 -4
- package/{module-plugin → modules}/entity.js +1 -1
- package/{module-plugin → modules}/index.js +0 -8
- package/modules/module-factory.js +56 -0
- package/modules/module.js +221 -0
- package/modules/repositories/module-repository-documentdb.js +307 -0
- package/modules/repositories/module-repository-factory.js +40 -0
- package/modules/repositories/module-repository-interface.js +129 -0
- package/modules/repositories/module-repository-mongo.js +377 -0
- package/modules/repositories/module-repository-postgres.js +426 -0
- package/modules/repositories/module-repository.js +316 -0
- package/modules/requester/api-key.js +52 -0
- package/{module-plugin → modules}/requester/requester.js +1 -0
- package/{module-plugin → modules}/test/mock-api/api.js +8 -3
- package/{module-plugin → modules}/test/mock-api/definition.js +12 -8
- package/modules/tests/doubles/test-module-factory.js +16 -0
- package/modules/tests/doubles/test-module-repository.js +39 -0
- package/modules/use-cases/get-entities-for-user.js +32 -0
- package/modules/use-cases/get-entity-options-by-id.js +71 -0
- package/modules/use-cases/get-entity-options-by-type.js +34 -0
- package/modules/use-cases/get-module-instance-from-type.js +31 -0
- package/modules/use-cases/get-module.js +74 -0
- package/modules/use-cases/process-authorization-callback.js +133 -0
- package/modules/use-cases/refresh-entity-options.js +72 -0
- package/modules/use-cases/test-module-auth.js +72 -0
- package/modules/utils/map-module-dto.js +18 -0
- package/package.json +82 -50
- package/prisma-mongodb/schema.prisma +360 -0
- package/prisma-postgresql/migrations/20250930193005_init/migration.sql +315 -0
- package/prisma-postgresql/migrations/20251006135218_init/migration.sql +9 -0
- package/prisma-postgresql/migrations/20251010000000_remove_unused_entity_reference_map/migration.sql +3 -0
- package/prisma-postgresql/migrations/20251112195422_update_user_unique_constraints/migration.sql +25 -0
- package/prisma-postgresql/migrations/migration_lock.toml +3 -0
- package/prisma-postgresql/schema.prisma +343 -0
- package/queues/queuer-util.js +27 -22
- package/syncs/manager.js +468 -443
- package/syncs/repositories/sync-repository-documentdb.js +240 -0
- package/syncs/repositories/sync-repository-factory.js +43 -0
- package/syncs/repositories/sync-repository-interface.js +109 -0
- package/syncs/repositories/sync-repository-mongo.js +239 -0
- package/syncs/repositories/sync-repository-postgres.js +319 -0
- package/syncs/sync.js +0 -1
- package/token/repositories/token-repository-documentdb.js +137 -0
- package/token/repositories/token-repository-factory.js +40 -0
- package/token/repositories/token-repository-interface.js +131 -0
- package/token/repositories/token-repository-mongo.js +219 -0
- package/token/repositories/token-repository-postgres.js +264 -0
- package/token/repositories/token-repository.js +219 -0
- package/types/core/index.d.ts +2 -2
- package/types/integrations/index.d.ts +2 -6
- package/types/module-plugin/index.d.ts +5 -59
- package/types/syncs/index.d.ts +0 -2
- package/user/repositories/user-repository-documentdb.js +441 -0
- package/user/repositories/user-repository-factory.js +52 -0
- package/user/repositories/user-repository-interface.js +201 -0
- package/user/repositories/user-repository-mongo.js +308 -0
- package/user/repositories/user-repository-postgres.js +360 -0
- package/user/tests/doubles/test-user-repository.js +72 -0
- package/user/use-cases/authenticate-user.js +127 -0
- package/user/use-cases/authenticate-with-shared-secret.js +48 -0
- package/user/use-cases/create-individual-user.js +61 -0
- package/user/use-cases/create-organization-user.js +47 -0
- package/user/use-cases/create-token-for-user-id.js +30 -0
- package/user/use-cases/get-user-from-adopter-jwt.js +149 -0
- package/user/use-cases/get-user-from-bearer-token.js +77 -0
- package/user/use-cases/get-user-from-x-frigg-headers.js +132 -0
- package/user/use-cases/login-user.js +122 -0
- package/user/user.js +125 -0
- package/utils/backend-path.js +38 -0
- package/utils/index.js +6 -0
- package/websocket/repositories/websocket-connection-repository-documentdb.js +119 -0
- package/websocket/repositories/websocket-connection-repository-factory.js +44 -0
- package/websocket/repositories/websocket-connection-repository-interface.js +106 -0
- package/websocket/repositories/websocket-connection-repository-mongo.js +156 -0
- package/websocket/repositories/websocket-connection-repository-postgres.js +196 -0
- package/websocket/repositories/websocket-connection-repository.js +161 -0
- package/database/models/State.js +0 -9
- package/database/models/Token.js +0 -70
- package/database/mongo.js +0 -45
- package/encrypt/Cryptor.test.js +0 -32
- package/encrypt/encrypt.js +0 -132
- package/encrypt/encrypt.test.js +0 -1069
- package/errors/base-error.test.js +0 -32
- package/errors/fetch-error.test.js +0 -79
- package/errors/halt-error.test.js +0 -11
- package/errors/validation-errors.test.js +0 -120
- package/integrations/create-frigg-backend.js +0 -31
- package/integrations/integration-factory.js +0 -251
- package/integrations/integration-mapping.js +0 -43
- package/integrations/integration-model.js +0 -46
- package/integrations/integration-user.js +0 -144
- package/integrations/test/integration-base.test.js +0 -144
- package/lambda/TimeoutCatcher.test.js +0 -68
- package/logs/logger.test.js +0 -76
- package/module-plugin/auther.js +0 -393
- package/module-plugin/credential.js +0 -22
- package/module-plugin/entity-manager.js +0 -70
- package/module-plugin/manager.js +0 -169
- package/module-plugin/module-factory.js +0 -61
- package/module-plugin/requester/api-key.js +0 -36
- package/module-plugin/requester/requester.test.js +0 -28
- package/module-plugin/test/auther.test.js +0 -97
- /package/{module-plugin → modules}/ModuleConstants.js +0 -0
- /package/{module-plugin → modules}/requester/basic.js +0 -0
- /package/{module-plugin → modules}/requester/oauth-2.js +0 -0
- /package/{module-plugin → modules}/test/mock-api/mocks/hubspot.js +0 -0
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
const bcrypt = require('bcryptjs');
|
|
2
|
-
const crypto = require('crypto');
|
|
3
|
-
const { get } = require('../assertions');
|
|
4
|
-
const { Token } = require('../database/models/Token');
|
|
5
|
-
const { IndividualUser } = require('../database/models/IndividualUser');
|
|
6
|
-
const { OrganizationUser } = require('../database/models/OrganizationUser');
|
|
7
|
-
const Boom = require('@hapi/boom');
|
|
8
|
-
|
|
9
|
-
class User {
|
|
10
|
-
static IndividualUser = IndividualUser;
|
|
11
|
-
static OrganizationUser = OrganizationUser;
|
|
12
|
-
static Token = Token;
|
|
13
|
-
static usePassword = false
|
|
14
|
-
static primary = User.IndividualUser;
|
|
15
|
-
static individualUserRequired = true;
|
|
16
|
-
static organizationUserRequired = false;
|
|
17
|
-
|
|
18
|
-
constructor() {
|
|
19
|
-
this.user = null;
|
|
20
|
-
this.individualUser = null;
|
|
21
|
-
this.organizationUser = null;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
getPrimaryUser() {
|
|
25
|
-
if (User.primary === User.OrganizationUser) {
|
|
26
|
-
return this.organizationUser;
|
|
27
|
-
}
|
|
28
|
-
return this.individualUser;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
getUserId() {
|
|
32
|
-
return this.getPrimaryUser()?.id;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
isLoggedIn() {
|
|
36
|
-
return Boolean(this.getUserId());
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async createUserToken(minutes) {
|
|
40
|
-
const rawToken = crypto.randomBytes(20).toString('hex');
|
|
41
|
-
const createdToken = await User.Token.createTokenWithExpire(this.getUserId(), rawToken, 120);
|
|
42
|
-
const tokenBuf = User.Token.createBase64BufferToken(createdToken, rawToken);
|
|
43
|
-
return tokenBuf;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
static async newUser(params={}) {
|
|
47
|
-
const user = new User();
|
|
48
|
-
const token = get(params, 'token', null);
|
|
49
|
-
if (token) {
|
|
50
|
-
const jsonToken = this.Token.getJSONTokenFromBase64BufferToken(token);
|
|
51
|
-
const sessionToken = await this.Token.validateAndGetTokenFromJSONToken(jsonToken);
|
|
52
|
-
if (this.primary === User.OrganizationUser) {
|
|
53
|
-
user.organizationUser = await this.OrganizationUser.findById(sessionToken.user);
|
|
54
|
-
} else {
|
|
55
|
-
user.individualUser = await this.IndividualUser.findById(sessionToken.user);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return user;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
static async createIndividualUser(params) {
|
|
62
|
-
const user = await this.newUser(params);
|
|
63
|
-
let hashword;
|
|
64
|
-
if (this.usePassword) {
|
|
65
|
-
hashword = get(params, 'password');
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const email = get(params, 'email', null);
|
|
69
|
-
const username = get(params, 'username', null);
|
|
70
|
-
if (!email && !username) {
|
|
71
|
-
throw Boom.badRequest('email or username is required');
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const appUserId = get(params, 'appUserId', null);
|
|
75
|
-
const organizationUserId = get(params, 'organizationUserId', null);
|
|
76
|
-
|
|
77
|
-
user.individualUser = await this.IndividualUser.create({
|
|
78
|
-
email,
|
|
79
|
-
username,
|
|
80
|
-
hashword,
|
|
81
|
-
appUserId,
|
|
82
|
-
organizationUser: organizationUserId,
|
|
83
|
-
});
|
|
84
|
-
return user;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
static async createOrganizationUser(params) {
|
|
88
|
-
const user = await this.newUser(params);
|
|
89
|
-
const name = get(params, 'name');
|
|
90
|
-
const appOrgId = get(params, 'appOrgId');
|
|
91
|
-
user.organizationUser = await this.OrganizationUser.create({
|
|
92
|
-
name,
|
|
93
|
-
appOrgId,
|
|
94
|
-
});
|
|
95
|
-
return user;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
static async loginUser(params) {
|
|
99
|
-
const user = await this.newUser(params);
|
|
100
|
-
|
|
101
|
-
if (this.usePassword){
|
|
102
|
-
const username = get(params, 'username');
|
|
103
|
-
const password = get(params, 'password');
|
|
104
|
-
|
|
105
|
-
const individualUser = await this.IndividualUser.findOne({username});
|
|
106
|
-
|
|
107
|
-
if (!individualUser) {
|
|
108
|
-
throw Boom.unauthorized('incorrect username or password');
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const isValid = await bcrypt.compareSync(password, individualUser.hashword);
|
|
112
|
-
if (!isValid) {
|
|
113
|
-
throw Boom.unauthorized('incorrect username or password');
|
|
114
|
-
}
|
|
115
|
-
user.individualUser = individualUser;
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
const appUserId = get(params, 'appUserId', null);
|
|
119
|
-
user.individualUser = await this.IndividualUser.getUserByAppUserId(
|
|
120
|
-
appUserId
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const appOrgId = get(params, 'appOrgId', null);
|
|
125
|
-
user.organizationUser = await this.OrganizationUser.getUserByAppOrgId(
|
|
126
|
-
appOrgId
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
if (this.individualUserRequired) {
|
|
130
|
-
if (!user.individualUser) {
|
|
131
|
-
throw Boom.unauthorized('user not found');
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (this.organizationUserRequired) {
|
|
136
|
-
if (!user.organizationUser) {
|
|
137
|
-
throw Boom.unauthorized(`org user ${appOrgId} not found`);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return user;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
module.exports = User;
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
const _ = require('lodash');
|
|
2
|
-
const { mongoose } = require('../../database/mongoose');
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const { IntegrationBase } = require("../integration-base");
|
|
5
|
-
const {Credential} = require('../../module-plugin/credential');
|
|
6
|
-
const {Entity} = require('../../module-plugin/entity');
|
|
7
|
-
const { IntegrationMapping } = require('../integration-mapping')
|
|
8
|
-
const {IntegrationModel} = require("../integration-model");
|
|
9
|
-
|
|
10
|
-
describe(`Should fully test the IntegrationBase Class`, () => {
|
|
11
|
-
let integrationRecord;
|
|
12
|
-
let userId;
|
|
13
|
-
const integration = new IntegrationBase;
|
|
14
|
-
|
|
15
|
-
beforeAll(async () => {
|
|
16
|
-
await mongoose.connect(process.env.MONGO_URI);
|
|
17
|
-
userId = new mongoose.Types.ObjectId();
|
|
18
|
-
const credential = await Credential.findOneAndUpdate(
|
|
19
|
-
{
|
|
20
|
-
user: this.userId,
|
|
21
|
-
},
|
|
22
|
-
{ $set: { user: this.userId } },
|
|
23
|
-
{
|
|
24
|
-
new: true,
|
|
25
|
-
upsert: true,
|
|
26
|
-
setDefaultsOnInsert: true,
|
|
27
|
-
}
|
|
28
|
-
);
|
|
29
|
-
const entity1 = await Entity.findOneAndUpdate(
|
|
30
|
-
{
|
|
31
|
-
user: this.userId,
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
$set: {
|
|
35
|
-
credential: credential.id,
|
|
36
|
-
user: userId,
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
new: true,
|
|
41
|
-
upsert: true,
|
|
42
|
-
setDefaultsOnInsert: true,
|
|
43
|
-
}
|
|
44
|
-
);
|
|
45
|
-
const entity2 = await Entity.findOneAndUpdate(
|
|
46
|
-
{
|
|
47
|
-
user: userId,
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
$set: {
|
|
51
|
-
credential: credential.id,
|
|
52
|
-
user: userId,
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
new: true,
|
|
57
|
-
upsert: true,
|
|
58
|
-
setDefaultsOnInsert: true,
|
|
59
|
-
}
|
|
60
|
-
);
|
|
61
|
-
integrationRecord = await IntegrationModel.create({
|
|
62
|
-
entities: [entity1, entity2],
|
|
63
|
-
user: userId
|
|
64
|
-
});
|
|
65
|
-
integration.record = integrationRecord;
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
afterAll(async () => {
|
|
69
|
-
await Entity.deleteMany();
|
|
70
|
-
await Credential.deleteMany();
|
|
71
|
-
await IntegrationMapping.deleteMany();
|
|
72
|
-
await IntegrationModel.deleteMany();
|
|
73
|
-
await mongoose.disconnect();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
beforeEach(() => {
|
|
77
|
-
integration.record = integrationRecord;
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
describe('getIntegrationMapping()', () => {
|
|
81
|
-
it('should return null if not found', async () => {
|
|
82
|
-
const mappings = await integration.getMapping('badId');
|
|
83
|
-
expect(mappings).to.be.null;
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('should return if valid ids', async () => {
|
|
87
|
-
await integration.upsertMapping('validId', {});
|
|
88
|
-
const mapping = await integration.getMapping('validId');
|
|
89
|
-
expect(mapping).to.eql({})
|
|
90
|
-
});
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
describe('upsertIntegrationMapping()', () => {
|
|
94
|
-
it('should throw error if sourceId is null', async () => {
|
|
95
|
-
try {
|
|
96
|
-
await integration.upsertMapping( null, {});
|
|
97
|
-
fail('should have thrown error')
|
|
98
|
-
} catch(err) {
|
|
99
|
-
expect(err.message).to.contain('sourceId must be set');
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('should return for empty mapping', async () => {
|
|
104
|
-
const mapping = await integration.upsertMapping( 'validId2', {});
|
|
105
|
-
expect(_.pick(mapping, ['integration', 'sourceId', 'mapping'])).to.eql({
|
|
106
|
-
integration: integrationRecord._id,
|
|
107
|
-
sourceId: 'validId2',
|
|
108
|
-
mapping: {}
|
|
109
|
-
})
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('should return for filled mapping', async () => {
|
|
113
|
-
const mapping = await integration.upsertMapping('validId3', {
|
|
114
|
-
name: 'someName',
|
|
115
|
-
value: 5
|
|
116
|
-
});
|
|
117
|
-
expect(_.pick(mapping, ['integration', 'sourceId', 'mapping'])).to.eql({
|
|
118
|
-
integration: integrationRecord._id,
|
|
119
|
-
sourceId: 'validId3',
|
|
120
|
-
mapping: {
|
|
121
|
-
name: 'someName',
|
|
122
|
-
value: 5
|
|
123
|
-
}
|
|
124
|
-
})
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('should allow upserting to same id', async () => {
|
|
128
|
-
await integration.upsertMapping('validId4', {});
|
|
129
|
-
const mapping = await integration.upsertMapping('validId4', {
|
|
130
|
-
name: 'trustMe',
|
|
131
|
-
thisWorks: true,
|
|
132
|
-
});
|
|
133
|
-
expect(_.pick(mapping, ['integration', 'sourceId', 'mapping'])).to.eql({
|
|
134
|
-
integration: integrationRecord._id,
|
|
135
|
-
sourceId: 'validId4',
|
|
136
|
-
mapping: {
|
|
137
|
-
name: 'trustMe',
|
|
138
|
-
thisWorks: true,
|
|
139
|
-
}
|
|
140
|
-
})
|
|
141
|
-
});
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
});
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
const { TimeoutCatcher } = require("./TimeoutCatcher");
|
|
2
|
-
|
|
3
|
-
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
4
|
-
|
|
5
|
-
describe("Time Sentinel", () => {
|
|
6
|
-
it("requires a positive wait time", () => {
|
|
7
|
-
try {
|
|
8
|
-
new TimeoutCatcher({
|
|
9
|
-
timeout: 1_000,
|
|
10
|
-
});
|
|
11
|
-
throw new Error("Expected error was not thrown");
|
|
12
|
-
} catch (error) {
|
|
13
|
-
expect(error).toHaveProperty(
|
|
14
|
-
"message",
|
|
15
|
-
"Wait time was not a positive number of milliseconds"
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("exits normally if the work is completed", async () => {
|
|
21
|
-
let cleanUpCalled = false;
|
|
22
|
-
const sentinel = new TimeoutCatcher({
|
|
23
|
-
cleanUp: () => (cleanUpCalled = true),
|
|
24
|
-
timeout: 3_000,
|
|
25
|
-
work: async () => {
|
|
26
|
-
await sleep(500);
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const didFinish = await sentinel.watch();
|
|
31
|
-
expect(didFinish).toEqual(true);
|
|
32
|
-
expect(cleanUpCalled).toEqual(false);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("terminates before time out if work runs long", async () => {
|
|
36
|
-
let cleanUpCalled = false;
|
|
37
|
-
const sentinel = new TimeoutCatcher({
|
|
38
|
-
cleanUp: () => (cleanUpCalled = true),
|
|
39
|
-
timeout: 3_000,
|
|
40
|
-
work: async () => {
|
|
41
|
-
await sleep(1_500);
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const didFinish = await sentinel.watch();
|
|
46
|
-
expect(didFinish).toEqual(false);
|
|
47
|
-
expect(cleanUpCalled).toEqual(true);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("rethrows unexpected errors", async () => {
|
|
51
|
-
let cleanUpCalled = false;
|
|
52
|
-
const sentinel = new TimeoutCatcher({
|
|
53
|
-
cleanUp: () => (cleanUpCalled = true),
|
|
54
|
-
timeout: 3_000,
|
|
55
|
-
work: async () => {
|
|
56
|
-
throw new Error("Spam spam spam spam");
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
await sentinel.watch();
|
|
62
|
-
throw new Error("Expected error did not occur");
|
|
63
|
-
} catch (error) {
|
|
64
|
-
expect(error).toHaveProperty("message", "Spam spam spam spam");
|
|
65
|
-
expect(cleanUpCalled).toEqual(false);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
});
|
package/logs/logger.test.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
const { debug, initDebugLog, flushDebugLog } = require('./logger');
|
|
2
|
-
const sinon = require('sinon');
|
|
3
|
-
const {
|
|
4
|
-
overrideEnvironment,
|
|
5
|
-
restoreEnvironment,
|
|
6
|
-
} = require('@friggframework/test');
|
|
7
|
-
|
|
8
|
-
/* eslint-disable no-console */
|
|
9
|
-
|
|
10
|
-
describe('Logger', () => {
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
sinon.stub(console, 'debug');
|
|
13
|
-
sinon.stub(console, 'error');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
afterEach(() => {
|
|
17
|
-
console.debug.restore();
|
|
18
|
-
console.error.restore();
|
|
19
|
-
restoreEnvironment();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('runs', () => {
|
|
23
|
-
initDebugLog('Test Event', { test: true });
|
|
24
|
-
debug('Add a message', 'or two', { or: 3 });
|
|
25
|
-
flushDebugLog(new Error());
|
|
26
|
-
|
|
27
|
-
expect(console.debug).toHaveProperty('callCount', 2);
|
|
28
|
-
expect(console.error).toHaveProperty('callCount', 1);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('logs immediately when environment variable set', () => {
|
|
32
|
-
overrideEnvironment({ DEBUG_VERBOSE: '1' });
|
|
33
|
-
|
|
34
|
-
debug('Add a message', 'or two', { or: 3 });
|
|
35
|
-
debug('And another');
|
|
36
|
-
|
|
37
|
-
expect(console.debug).toHaveProperty('callCount', 2);
|
|
38
|
-
expect(console.error).toHaveProperty('callCount', 0);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('is resilient to missing parameters', () => {
|
|
42
|
-
initDebugLog();
|
|
43
|
-
debug();
|
|
44
|
-
flushDebugLog();
|
|
45
|
-
|
|
46
|
-
expect(console.debug).toHaveProperty('callCount', 0);
|
|
47
|
-
expect(console.error).toHaveProperty('callCount', 1);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('outputs parent errors', () => {
|
|
51
|
-
initDebugLog();
|
|
52
|
-
|
|
53
|
-
const error = new Error();
|
|
54
|
-
error.cause = new Error();
|
|
55
|
-
error.cause.cause = new Error();
|
|
56
|
-
error.cause.cause.cause = new Error();
|
|
57
|
-
|
|
58
|
-
flushDebugLog(error);
|
|
59
|
-
|
|
60
|
-
expect(console.debug).toHaveProperty('callCount', 0);
|
|
61
|
-
expect(console.error).toHaveProperty('callCount', 7); // 1 + 2 for each cause
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('adds a debug message if more than 1 error encountered', () => {
|
|
65
|
-
initDebugLog();
|
|
66
|
-
flushDebugLog(new Error());
|
|
67
|
-
|
|
68
|
-
expect(console.debug).toHaveProperty('callCount', 0);
|
|
69
|
-
expect(console.error).toHaveProperty('callCount', 1);
|
|
70
|
-
|
|
71
|
-
flushDebugLog(new Error());
|
|
72
|
-
|
|
73
|
-
expect(console.debug).toHaveProperty('callCount', 1);
|
|
74
|
-
expect(console.error).toHaveProperty('callCount', 2);
|
|
75
|
-
});
|
|
76
|
-
});
|