@friggframework/core 2.0.0--canary.730.f2ba24a.0 → 2.0.0--canary.656.6eb85ab.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +14 -42
- package/application/commands/README.md +11 -17
- package/application/commands/entity-commands.js +60 -18
- package/application/commands/integration-commands.js +0 -63
- package/core/CLAUDE.md +3 -1
- package/core/create-handler.js +3 -0
- package/core/index.js +6 -0
- package/core/invocation-deadline.js +91 -0
- package/core/invocation-scope.js +30 -24
- package/database/documentdb-encryption-service.js +33 -2
- package/database/documentdb-utils.js +1 -4
- package/database/encryption/README.md +3 -3
- package/database/encryption/encryption-schema-registry.js +29 -109
- package/database/encryption/field-encryption-service.js +16 -55
- package/database/encryption/prisma-encryption-extension.js +9 -6
- package/database/prisma.js +1 -10
- package/encrypt/Cryptor.js +38 -90
- package/errors/fetch-error.js +11 -18
- package/errors/index.js +2 -4
- package/errors/rate-limit-error.js +45 -0
- package/handlers/WEBHOOKS.md +0 -29
- package/handlers/app-definition-loader.js +2 -9
- package/handlers/app-handler-helpers.js +1 -12
- package/handlers/backend-utils.js +2 -1
- package/handlers/workers/integration-defined-workers.js +2 -0
- package/index.js +18 -2
- package/infrastructure/scheduler/eventbridge-scheduler-adapter.js +13 -67
- package/integrations/integration-base.js +9 -52
- package/integrations/integration-router.js +22 -30
- package/integrations/repositories/integration-mapping-repository-documentdb.js +0 -50
- package/integrations/repositories/integration-mapping-repository-interface.js +0 -15
- package/integrations/repositories/integration-mapping-repository-mongo.js +0 -29
- package/integrations/repositories/integration-mapping-repository-postgres.js +0 -30
- package/integrations/repositories/integration-mapping-repository.js +0 -29
- package/integrations/repositories/integration-repository-documentdb.js +0 -32
- package/integrations/repositories/integration-repository-interface.js +0 -30
- package/integrations/repositories/integration-repository-mongo.js +1 -53
- package/integrations/repositories/integration-repository-postgres.js +0 -58
- package/integrations/repositories/process-repository-mongo.js +1 -1
- package/integrations/use-cases/create-integration.js +19 -57
- package/integrations/use-cases/delete-integration-for-user.js +11 -8
- package/integrations/use-cases/get-integration-instance.js +12 -12
- package/integrations/use-cases/update-integration.js +12 -12
- package/jest-setup.js +2 -13
- package/jest-teardown.js +2 -5
- package/jest.config.js +0 -4
- package/logs/serialize.js +15 -0
- package/modules/requester/rate-limit/index.js +4 -0
- package/modules/requester/rate-limit/parsers.js +245 -0
- package/modules/requester/rate-limit/policy.js +304 -0
- package/modules/requester/requester.js +187 -9
- package/modules/use-cases/get-entity-options-by-id.js +5 -7
- package/modules/use-cases/get-module.js +8 -29
- package/modules/use-cases/process-authorization-callback.js +27 -78
- package/modules/use-cases/refresh-entity-options.js +5 -7
- package/modules/use-cases/test-module-auth.js +5 -7
- package/modules/utils/map-module-dto.js +3 -5
- package/package.json +7 -10
- package/queues/queuer-util.js +5 -6
- package/token/repositories/token-repository-documentdb.js +1 -13
- package/token/repositories/token-repository-mongo.js +1 -13
- package/token/repositories/token-repository-postgres.js +1 -13
- package/types/core/index.d.ts +33 -0
- package/types/errors/index.d.ts +47 -0
- package/types/module-plugin/index.d.ts +43 -0
- package/user/tests/doubles/test-user-repository.js +1 -1
- package/user/use-cases/authenticate-user.js +7 -23
- package/user/use-cases/get-user-from-bearer-token.js +2 -7
- package/database/encryption/ciphertext-format.js +0 -24
- package/errors/mapping-already-exists-error.js +0 -14
- package/integrations/use-cases/add-entities-to-integration.js +0 -92
- package/integrations/use-cases/remove-entities-from-integration.js +0 -70
- package/integrations/utils/assert-entity-ids-input.js +0 -42
- package/jest.db.config.js +0 -23
- package/modules/use-cases/create-entity-from-credential.js +0 -105
- package/modules/utils/find-module-definition.js +0 -23
- package/modules/utils/to-credential-id.js +0 -14
package/jest.db.config.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Database integration suites (`*.db.test.js`).
|
|
3
|
-
*
|
|
4
|
-
* These talk to real databases instead of mocking Prisma, so they are kept
|
|
5
|
-
* out of the default `npm test` run and executed with `npm run test:db`.
|
|
6
|
-
* They need generated Prisma clients (`npm run prisma:generate`) and:
|
|
7
|
-
* - a MongoDB replica set (Prisma requires one for MongoDB writes):
|
|
8
|
-
* FRIGG_TEST_MONGODB_URL, default
|
|
9
|
-
* mongodb://localhost:27017/frigg?replicaSet=rs0
|
|
10
|
-
* - PostgreSQL with the prisma-postgresql migrations applied:
|
|
11
|
-
* FRIGG_TEST_POSTGRES_URL, default
|
|
12
|
-
* postgresql://postgres:postgres@localhost:5432/frigg?schema=public
|
|
13
|
-
* The repository parity suites skip themselves unless their own URLs are
|
|
14
|
-
* set (INTEGRATION_ENTITIES_PARITY_* / QUERY_MAPPINGS_PARITY_*).
|
|
15
|
-
*/
|
|
16
|
-
const base = require('./jest.config');
|
|
17
|
-
|
|
18
|
-
module.exports = {
|
|
19
|
-
...base,
|
|
20
|
-
coverageThreshold: undefined,
|
|
21
|
-
testMatch: ['**/*.db.test.js'],
|
|
22
|
-
testPathIgnorePatterns: ['/node_modules/'],
|
|
23
|
-
};
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
const Boom = require('@hapi/boom');
|
|
2
|
-
const { Module } = require('../module');
|
|
3
|
-
|
|
4
|
-
const sameId = (a, b) =>
|
|
5
|
-
a !== undefined &&
|
|
6
|
-
a !== null &&
|
|
7
|
-
b !== undefined &&
|
|
8
|
-
b !== null &&
|
|
9
|
-
String(a) === String(b);
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Creates (or finds) the entity for a credential the caller already holds:
|
|
13
|
-
* the v1 `POST /api/entity`.
|
|
14
|
-
*
|
|
15
|
-
* The module is built with the stored credential loaded, so the API can call
|
|
16
|
-
* the provider and a token refresh during `getEntityDetails` updates that
|
|
17
|
-
* credential. Persistence reuses `ProcessAuthorizationCallback.findOrCreateEntity`,
|
|
18
|
-
* the same find-or-create (and credential repointing) the authorization flow
|
|
19
|
-
* uses, so the two paths cannot drift.
|
|
20
|
-
*/
|
|
21
|
-
class CreateEntityFromCredential {
|
|
22
|
-
/**
|
|
23
|
-
* @param {Object} params
|
|
24
|
-
* @param {import('./process-authorization-callback').ProcessAuthorizationCallback} params.processAuthorizationCallback
|
|
25
|
-
* @param {Object} params.credentialRepository
|
|
26
|
-
* @param {Array<Object>} params.moduleDefinitions
|
|
27
|
-
* @param {Function} [params.createModule] - builds a Module; injectable for tests
|
|
28
|
-
*/
|
|
29
|
-
constructor({
|
|
30
|
-
processAuthorizationCallback,
|
|
31
|
-
credentialRepository,
|
|
32
|
-
moduleDefinitions,
|
|
33
|
-
createModule,
|
|
34
|
-
}) {
|
|
35
|
-
this.processAuthorizationCallback = processAuthorizationCallback;
|
|
36
|
-
this.credentialRepository = credentialRepository;
|
|
37
|
-
this.moduleDefinitions = moduleDefinitions || [];
|
|
38
|
-
this.createModule = createModule || ((params) => new Module(params));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @param {Object} params
|
|
43
|
-
* @param {Object} params.user - authenticated User
|
|
44
|
-
* @param {string} params.entityType
|
|
45
|
-
* @param {string} params.credentialId
|
|
46
|
-
* @returns {Promise<Object>} the persisted entity
|
|
47
|
-
*/
|
|
48
|
-
async execute({ user, entityType, credentialId }) {
|
|
49
|
-
const userId = user?.getId?.();
|
|
50
|
-
if (userId === undefined || userId === null) {
|
|
51
|
-
throw Boom.unauthorized('No authenticated user');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const definition = this.moduleDefinitions.find(
|
|
55
|
-
(def) => def && def.moduleName === entityType
|
|
56
|
-
);
|
|
57
|
-
if (!definition) {
|
|
58
|
-
throw Boom.badRequest(`Unknown entity type ${entityType}`, {
|
|
59
|
-
code: 'ENTITY_TYPE_NOT_FOUND',
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const credential =
|
|
64
|
-
await this.credentialRepository.findCredentialById(credentialId);
|
|
65
|
-
// A missing credential and someone else's get the same answer, so
|
|
66
|
-
// credential ids cannot be probed.
|
|
67
|
-
if (!credential || !sameId(credential.userId, userId)) {
|
|
68
|
-
throw Boom.badRequest('Invalid credential ID', {
|
|
69
|
-
code: 'INVALID_CREDENTIAL',
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// The repository returns the tokens flat; a Module reads them from
|
|
74
|
-
// `credential.data`.
|
|
75
|
-
const { id, userId: ownerId, externalId, authIsValid, ...data } =
|
|
76
|
-
credential;
|
|
77
|
-
const module = this.createModule({
|
|
78
|
-
userId,
|
|
79
|
-
definition,
|
|
80
|
-
entity: {
|
|
81
|
-
credential: { id, userId: ownerId, externalId, authIsValid, data },
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const entityDetails =
|
|
86
|
-
await definition.requiredAuthMethods.getEntityDetails(
|
|
87
|
-
module.api,
|
|
88
|
-
null,
|
|
89
|
-
null,
|
|
90
|
-
userId
|
|
91
|
-
);
|
|
92
|
-
Object.assign(
|
|
93
|
-
entityDetails.details,
|
|
94
|
-
module.apiParamsFromEntity(module.api)
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
return this.processAuthorizationCallback.findOrCreateEntity(
|
|
98
|
-
entityDetails,
|
|
99
|
-
definition.moduleName,
|
|
100
|
-
credential.id
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
module.exports = { CreateEntityFromCredential };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The API module definition a stored entity belongs to.
|
|
3
|
-
*
|
|
4
|
-
* Entities are persisted with `moduleName` set to the definition's
|
|
5
|
-
* `moduleName` (see ProcessAuthorizationCallback.findOrCreateEntity). A
|
|
6
|
-
* definition's legacy `modelName` is accepted as well, for entities written
|
|
7
|
-
* before the two were the same.
|
|
8
|
-
*
|
|
9
|
-
* @param {Array<Object>} moduleDefinitions
|
|
10
|
-
* @param {Object} entity - entity record with a `moduleName`
|
|
11
|
-
* @returns {Object|undefined}
|
|
12
|
-
*/
|
|
13
|
-
function findModuleDefinitionForEntity(moduleDefinitions, entity) {
|
|
14
|
-
const entityType = entity?.moduleName;
|
|
15
|
-
if (!entityType) return undefined;
|
|
16
|
-
return (moduleDefinitions || []).find(
|
|
17
|
-
(def) =>
|
|
18
|
-
def &&
|
|
19
|
-
(def.moduleName === entityType || def.modelName === entityType)
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
module.exports = { findModuleDefinitionForEntity };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resolve the credential id from an entity's or module's `credential`, which
|
|
3
|
-
* repositories return as the decrypted credential object (or a bare id).
|
|
4
|
-
* @param {Object|string|number|null|undefined} credential
|
|
5
|
-
* @returns {string|null}
|
|
6
|
-
*/
|
|
7
|
-
function toCredentialId(credential) {
|
|
8
|
-
if (credential && typeof credential === 'object') {
|
|
9
|
-
return credential.id?.toString() ?? null;
|
|
10
|
-
}
|
|
11
|
-
return credential?.toString() ?? null;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
module.exports = { toCredentialId };
|