@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
@@ -1,70 +0,0 @@
1
- const {
2
- assertEntityIdsInput,
3
- integrationNotFound,
4
- loadIntegration,
5
- } = require('../utils/assert-entity-ids-input');
6
-
7
- /**
8
- * Detaches entities from an integration. Entities that are not attached are
9
- * ignored, and detached entities are not deleted. Every module the
10
- * integration holds must keep at least one entity, so the integration can
11
- * still hydrate each of its modules.
12
- * @class RemoveEntitiesFromIntegration
13
- */
14
- class RemoveEntitiesFromIntegration {
15
- /**
16
- * @param {Object} params
17
- * @param {import('../repositories/integration-repository-interface').IntegrationRepositoryInterface} params.integrationRepository
18
- * @param {import('../../modules/repositories/module-repository-interface').ModuleRepositoryInterface} params.moduleRepository
19
- */
20
- constructor({ integrationRepository, moduleRepository }) {
21
- this.integrationRepository = integrationRepository;
22
- this.moduleRepository = moduleRepository;
23
- }
24
-
25
- /**
26
- * @param {string} integrationId
27
- * @param {string[]} entityIds
28
- * @returns {Promise<Object>} The updated integration record.
29
- */
30
- async execute(integrationId, entityIds) {
31
- assertEntityIdsInput(integrationId, entityIds);
32
-
33
- const integration = await loadIntegration(
34
- this.integrationRepository,
35
- integrationId
36
- );
37
-
38
- const removing = new Set(entityIds.map(String));
39
- const attached = await this.moduleRepository.findEntitiesByIds(
40
- integration.entitiesIds ?? []
41
- );
42
- const emptied = [...new Set(attached.map((e) => e.moduleName))].filter(
43
- (moduleName) =>
44
- !attached.some(
45
- (e) =>
46
- e.moduleName === moduleName &&
47
- !removing.has(String(e.id))
48
- )
49
- );
50
- if (emptied.length > 0) {
51
- const error = new Error(
52
- `Removing these entities would leave no entity for module(s): ${emptied.join(
53
- ', '
54
- )}`
55
- );
56
- error.code = 'LAST_ENTITY_OF_MODULE';
57
- throw error;
58
- }
59
-
60
- const updated =
61
- await this.integrationRepository.removeEntitiesFromIntegration(
62
- integrationId,
63
- entityIds
64
- );
65
- if (!updated) throw integrationNotFound(integrationId);
66
- return updated;
67
- }
68
- }
69
-
70
- module.exports = { RemoveEntitiesFromIntegration };
@@ -1,42 +0,0 @@
1
- /**
2
- * Throws INVALID_INTEGRATION_DATA unless an integration id and a non-empty
3
- * list of entity ids are given.
4
- * @param {string} integrationId
5
- * @param {string[]} entityIds
6
- */
7
- function assertEntityIdsInput(integrationId, entityIds) {
8
- if (!integrationId || !Array.isArray(entityIds) || entityIds.length === 0) {
9
- const error = new Error(
10
- 'integrationId and a non-empty entityIds array are required'
11
- );
12
- error.code = 'INVALID_INTEGRATION_DATA';
13
- throw error;
14
- }
15
- }
16
-
17
- function integrationNotFound(integrationId) {
18
- const error = new Error(`Integration ${integrationId} not found`);
19
- error.code = 'INTEGRATION_NOT_FOUND';
20
- return error;
21
- }
22
-
23
- /**
24
- * Loads an integration, mapping the repositories' "not found" error to
25
- * INTEGRATION_NOT_FOUND. Any other failure (connection, invalid id) is
26
- * rethrown unchanged.
27
- * @param {Object} integrationRepository
28
- * @param {string} integrationId
29
- * @returns {Promise<Object>} The integration record.
30
- */
31
- async function loadIntegration(integrationRepository, integrationId) {
32
- try {
33
- return await integrationRepository.findIntegrationById(integrationId);
34
- } catch (error) {
35
- if (/^Integration with id .* not found$/.test(error?.message)) {
36
- throw integrationNotFound(integrationId);
37
- }
38
- throw error;
39
- }
40
- }
41
-
42
- module.exports = { assertEntityIdsInput, integrationNotFound, loadIntegration };
@@ -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 };