@friggframework/core 2.0.0--canary.690.d043f23.0 → 2.0.0--canary.691.2fd013b.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 +0 -28
- package/README.md +0 -105
- package/application/commands/integration-commands.js +10 -20
- package/application/commands/scheduler-commands.js +7 -11
- package/application/commands/user-commands.js +5 -17
- package/application/index.js +2 -6
- package/core/Worker.js +7 -31
- package/core/create-handler.js +0 -9
- package/credential/repositories/credential-repository-documentdb.js +0 -34
- package/credential/repositories/credential-repository-interface.js +0 -15
- package/credential/repositories/credential-repository-mongo.js +0 -23
- package/credential/repositories/credential-repository-postgres.js +0 -28
- package/database/config.js +24 -48
- package/database/documentdb-utils.js +0 -2
- package/database/encryption/encryption-schema-registry.js +12 -93
- package/database/prisma.js +2 -4
- package/errors/index.js +4 -0
- package/errors/mapping-already-exists-error.js +14 -0
- package/generated/prisma-mongodb/edge.js +4 -43
- package/generated/prisma-mongodb/index-browser.js +1 -40
- package/generated/prisma-mongodb/index.d.ts +111 -4739
- package/generated/prisma-mongodb/index.js +4 -43
- package/generated/prisma-mongodb/package.json +1 -1
- package/generated/prisma-mongodb/schema.prisma +0 -92
- package/generated/prisma-mongodb/wasm.js +4 -43
- package/generated/prisma-postgresql/edge.js +4 -43
- package/generated/prisma-postgresql/index-browser.js +1 -40
- package/generated/prisma-postgresql/index.d.ts +33 -4966
- package/generated/prisma-postgresql/index.js +4 -43
- package/generated/prisma-postgresql/package.json +1 -1
- package/generated/prisma-postgresql/schema.prisma +0 -87
- package/generated/prisma-postgresql/wasm.js +4 -43
- package/handlers/WEBHOOKS.md +29 -0
- package/handlers/app-definition-loader.js +19 -118
- package/handlers/app-handler-helpers.js +3 -25
- package/handlers/backend-utils.js +25 -31
- package/handlers/middleware/admin-auth.js +1 -14
- package/handlers/routers/auth.js +10 -46
- package/handlers/routers/health.js +4 -11
- package/handlers/routers/integration-defined-routers.js +92 -144
- package/handlers/routers/integration-webhook-routers.js +64 -102
- package/handlers/workers/integration-defined-workers.js +2 -5
- package/index.js +3 -63
- package/infrastructure/scheduler/index.js +6 -19
- package/infrastructure/scheduler/scheduler-service-factory.js +7 -55
- package/integrations/index.js +0 -1
- package/integrations/integration-base.js +29 -0
- package/integrations/integration-router.js +96 -131
- package/integrations/repositories/integration-mapping-repository-documentdb.js +50 -0
- package/integrations/repositories/integration-mapping-repository-interface.js +15 -0
- package/integrations/repositories/integration-mapping-repository-mongo.js +29 -0
- package/integrations/repositories/integration-mapping-repository-postgres.js +30 -0
- package/integrations/repositories/integration-mapping-repository.js +29 -0
- package/integrations/repositories/integration-repository-documentdb.js +3 -35
- package/integrations/repositories/integration-repository-interface.js +1 -17
- package/integrations/repositories/integration-repository-mongo.js +77 -60
- package/integrations/repositories/integration-repository-postgres.js +76 -62
- package/integrations/repositories/process-repository-mongo.js +1 -1
- package/integrations/tests/doubles/test-integration-repository.js +1 -12
- package/integrations/use-cases/create-integration.js +20 -55
- package/integrations/use-cases/get-integrations-for-user.js +40 -80
- package/integrations/use-cases/index.js +1 -5
- package/integrations/utils/map-integration-dto.js +14 -43
- package/modules/index.js +0 -14
- package/modules/module-factory.js +0 -12
- package/modules/module.js +2 -53
- package/modules/repositories/module-repository-documentdb.js +6 -51
- package/modules/repositories/module-repository-interface.js +2 -19
- package/modules/repositories/module-repository-mongo.js +74 -67
- package/modules/repositories/module-repository-postgres.js +74 -66
- package/modules/repositories/module-repository.js +1 -2
- package/modules/requester/requester.js +2 -27
- package/modules/use-cases/get-entities-for-user.js +13 -26
- package/modules/use-cases/get-entity-options-by-id.js +4 -10
- package/modules/use-cases/get-entity-options-by-type.js +1 -1
- package/modules/use-cases/get-module-instance-from-type.js +1 -1
- package/modules/use-cases/get-module.js +4 -10
- package/modules/use-cases/process-authorization-callback.js +19 -53
- package/modules/use-cases/refresh-entity-options.js +4 -10
- package/modules/use-cases/test-module-auth.js +4 -10
- package/package.json +5 -6
- package/prisma-mongodb/schema.prisma +0 -92
- package/prisma-postgresql/schema.prisma +0 -87
- package/queues/index.js +0 -25
- package/types/index.d.ts +0 -2
- package/user/repositories/user-repository-documentdb.js +2 -27
- package/user/repositories/user-repository-interface.js +0 -18
- package/user/repositories/user-repository-mongo.js +0 -24
- package/user/repositories/user-repository-postgres.js +0 -18
- package/user/tests/doubles/test-user-repository.js +1 -1
- package/user/use-cases/authenticate-user.js +1 -7
- package/user/use-cases/get-user-from-adopter-jwt.js +124 -95
- package/user/use-cases/get-user-from-bearer-token.js +7 -2
- package/user/use-cases/get-user-from-x-frigg-headers.js +80 -83
- package/user/user.js +1 -64
- package/credential/use-cases/credential-operations-for-user.js +0 -202
- package/credential/use-cases/reauthorize-credential-for-user.js +0 -73
- package/database/organization-where.js +0 -18
- package/database/unique-violation.js +0 -25
- package/extensions/bootstrap-runner.js +0 -43
- package/extensions/extension-loader.js +0 -167
- package/extensions/index.js +0 -41
- package/extensions/initialize-app.js +0 -123
- package/extensions/route-mounter.js +0 -103
- package/extensions/schema-composer.js +0 -188
- package/infrastructure/scheduler/netlify-scheduler-adapter.js +0 -216
- package/infrastructure/scheduler/scheduled-job-repository.js +0 -118
- package/integrations/repositories/integration-not-found.js +0 -14
- package/integrations/use-cases/integration-operations-for-user.js +0 -256
- package/integrations/use-cases/resolve-integration-ownership.js +0 -177
- package/management-api/create-management-api-router.js +0 -49
- package/management-api/error-response.js +0 -116
- package/management-api/management-api-config.js +0 -151
- package/management-api/meta-router.js +0 -57
- package/management-api/openapi/build-openapi.js +0 -144
- package/management-api/openapi/components.js +0 -414
- package/management-api/openapi/v1-operations.js +0 -83
- package/management-api/openapi/v2-operations.js +0 -264
- package/management-api/route-registry.js +0 -294
- package/management-api/test-support/http-client.js +0 -39
- package/management-api/use-cases/get-management-api-meta.js +0 -57
- package/management-api/v1-deprecation.js +0 -120
- package/management-api/v2/create-v2-router.js +0 -85
- package/management-api/v2/dependencies.js +0 -281
- package/management-api/v2/dto.js +0 -143
- package/management-api/v2/handlers/authorization.js +0 -94
- package/management-api/v2/handlers/credentials.js +0 -33
- package/management-api/v2/handlers/entities.js +0 -77
- package/management-api/v2/handlers/integrations.js +0 -128
- package/management-api/v2/handlers/proxy.js +0 -34
- package/management-api/v2/request.js +0 -85
- package/management-api/v2/test-support/fake-dependencies.js +0 -103
- package/modules/domain/authorization-session.js +0 -144
- package/modules/entity-scope.js +0 -15
- package/modules/entity-type-registry.js +0 -311
- package/modules/proxy/proxy-bases.js +0 -169
- package/modules/proxy/proxy-errors.js +0 -31
- package/modules/proxy/proxy-path.js +0 -183
- package/modules/proxy/proxy-policy.js +0 -265
- package/modules/repositories/authorization-session-repository-documentdb.js +0 -112
- package/modules/repositories/authorization-session-repository-factory.js +0 -31
- package/modules/repositories/authorization-session-repository-interface.js +0 -47
- package/modules/repositories/authorization-session-repository-prisma.js +0 -87
- package/modules/repositories/entity-not-found.js +0 -18
- package/modules/requester/proxy-request.js +0 -245
- package/modules/scope-config.js +0 -192
- package/modules/scope-policy.js +0 -112
- package/modules/scope-resolution.js +0 -288
- package/modules/scope-visibility.js +0 -247
- package/modules/tests/doubles/in-memory-authorization-session-repository.js +0 -45
- package/modules/tests/doubles/ownership-matching.js +0 -18
- package/modules/use-cases/authorize-entity-for-user.js +0 -61
- package/modules/use-cases/create-entity-from-credential.js +0 -113
- package/modules/use-cases/entity-operations-for-user.js +0 -162
- package/modules/use-cases/entity-types.js +0 -139
- package/modules/use-cases/execute-entity-proxy-request.js +0 -331
- package/modules/use-cases/get-authorization-requirements.js +0 -100
- package/modules/use-cases/get-entity-module-for-user.js +0 -113
- package/modules/use-cases/manage-access.js +0 -21
- package/modules/use-cases/multi-step-authorization.js +0 -329
- package/prisma-postgresql/migrations/20261003000000_add_authorization_session/migration.sql +0 -28
- package/prisma-postgresql/migrations/20261015000000_add_organization_membership/migration.sql +0 -26
- package/prisma-postgresql/migrations/20261016000000_add_entity_integration_organization/migration.sql +0 -25
- package/prisma-postgresql/migrations/20261017000000_add_scheduled_job/migration.sql +0 -28
- package/providers/index.js +0 -13
- package/providers/resolve-provider.js +0 -93
- package/queues/providers/index.js +0 -11
- package/queues/providers/netlify-background-provider.js +0 -150
- package/queues/providers/qstash-queue-provider.js +0 -199
- package/queues/providers/sqs-queue-provider.js +0 -70
- package/queues/queue-client-interface.js +0 -55
- package/queues/queue-message-auth.js +0 -187
- package/queues/queue-provider-factory.js +0 -101
- package/queues/queue-provider.js +0 -65
- package/queues/sqs-queue-client.js +0 -81
- package/types/modules/index.d.ts +0 -214
- package/types/user/index.d.ts +0 -134
- package/user/adopter-jwt-config.js +0 -177
- package/user/adopter-jwt-errors.js +0 -59
- package/user/adopter-token-verifier.js +0 -122
- package/user/app-user-helpers.js +0 -97
- package/user/create-user-authentication.js +0 -64
- package/user/membership.js +0 -51
- package/user/repositories/organization-membership-record.js +0 -19
- package/user/repositories/organization-membership-repository-documentdb.js +0 -106
- package/user/repositories/organization-membership-repository-factory.js +0 -42
- package/user/repositories/organization-membership-repository-interface.js +0 -57
- package/user/repositories/organization-membership-repository-mongo.js +0 -13
- package/user/repositories/organization-membership-repository-postgres.js +0 -29
- package/user/repositories/organization-membership-repository-prisma.js +0 -81
- package/user/tests/doubles/adopter-jwt-fixtures.js +0 -220
- package/user/use-cases/ensure-organization-membership.js +0 -92
- package/user/use-cases/find-individual-users-by-organization.js +0 -54
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
const { toEntityDto, maskCredential } = require('../dto');
|
|
2
|
-
const { objectBody, requireFields, parseStep, optionalString } = require('../request');
|
|
3
|
-
|
|
4
|
-
/** The v2 body for a submitted step: masked records when complete. */
|
|
5
|
-
function toAuthorizationResponse(result) {
|
|
6
|
-
if (result.status !== 'complete') return result;
|
|
7
|
-
return {
|
|
8
|
-
status: 'complete',
|
|
9
|
-
entity: result.entity ? toEntityDto(result.entity) : null,
|
|
10
|
-
credential: result.credential ? maskCredential(result.credential) : null,
|
|
11
|
-
...(result.previousCredentialId && {
|
|
12
|
-
previousCredentialId: result.previousCredentialId,
|
|
13
|
-
}),
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Management API v2 authorization handlers (multi-step authorize and
|
|
19
|
-
* credential re-authorization), keyed by operationId.
|
|
20
|
-
*/
|
|
21
|
-
function createAuthorizationHandlers(useCases) {
|
|
22
|
-
const {
|
|
23
|
-
getAuthorizationStep,
|
|
24
|
-
submitAuthorizationStep,
|
|
25
|
-
getCredentialReauthorization,
|
|
26
|
-
reauthorizeCredentialForUser,
|
|
27
|
-
} = useCases;
|
|
28
|
-
|
|
29
|
-
const stepQuery = (req) => ({
|
|
30
|
-
step: parseStep(req.query.step),
|
|
31
|
-
sessionId: optionalString(req.query.sessionId, 'sessionId'),
|
|
32
|
-
state: optionalString(req.query.state, 'state'),
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const stepBody = (req) => {
|
|
36
|
-
const body = objectBody(req);
|
|
37
|
-
return {
|
|
38
|
-
body,
|
|
39
|
-
step: parseStep(body.step),
|
|
40
|
-
sessionId: optionalString(body.sessionId, 'sessionId'),
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
async getAuthorizationRequirements(req, res, user) {
|
|
46
|
-
const entityType = optionalString(req.query.entityType, 'entityType');
|
|
47
|
-
requireFields({ entityType }, ['entityType']);
|
|
48
|
-
res.json(
|
|
49
|
-
await getAuthorizationStep.execute({
|
|
50
|
-
user,
|
|
51
|
-
entityType,
|
|
52
|
-
...stepQuery(req),
|
|
53
|
-
})
|
|
54
|
-
);
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
async authorize(req, res, user) {
|
|
58
|
-
const { body, step, sessionId } = stepBody(req);
|
|
59
|
-
requireFields(body, ['entityType', 'data']);
|
|
60
|
-
const result = await submitAuthorizationStep.execute({
|
|
61
|
-
user,
|
|
62
|
-
entityType: optionalString(body.entityType, 'entityType'),
|
|
63
|
-
data: body.data,
|
|
64
|
-
step,
|
|
65
|
-
sessionId,
|
|
66
|
-
scope: optionalString(body.scope, 'scope'),
|
|
67
|
-
});
|
|
68
|
-
res.json(toAuthorizationResponse(result));
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
async getCredentialReauthorizeRequirements(req, res, user) {
|
|
72
|
-
res.json(
|
|
73
|
-
await getCredentialReauthorization.execute(
|
|
74
|
-
req.params.credentialId,
|
|
75
|
-
user,
|
|
76
|
-
stepQuery(req)
|
|
77
|
-
)
|
|
78
|
-
);
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
async reauthorizeCredential(req, res, user) {
|
|
82
|
-
const { body, step, sessionId } = stepBody(req);
|
|
83
|
-
requireFields(body, ['data']);
|
|
84
|
-
const result = await reauthorizeCredentialForUser.execute(
|
|
85
|
-
req.params.credentialId,
|
|
86
|
-
user,
|
|
87
|
-
{ data: body.data, step, sessionId }
|
|
88
|
-
);
|
|
89
|
-
res.json(toAuthorizationResponse(result));
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
module.exports = { createAuthorizationHandlers, toAuthorizationResponse };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
const { maskCredential } = require('../dto');
|
|
2
|
-
const { parseListFilters } = require('../request');
|
|
3
|
-
|
|
4
|
-
/** Management API v2 credential handlers, keyed by operationId. */
|
|
5
|
-
function createCredentialHandlers(useCases) {
|
|
6
|
-
const { listCredentialsForUser, getCredentialForUser, deleteCredentialForUser } =
|
|
7
|
-
useCases;
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
async listCredentials(req, res, user) {
|
|
11
|
-
const credentials = await listCredentialsForUser.execute(
|
|
12
|
-
user,
|
|
13
|
-
parseListFilters(req.query)
|
|
14
|
-
);
|
|
15
|
-
res.json({ credentials: credentials.map(maskCredential) });
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
async getCredential(req, res, user) {
|
|
19
|
-
res.json(
|
|
20
|
-
maskCredential(
|
|
21
|
-
await getCredentialForUser.execute(req.params.credentialId, user)
|
|
22
|
-
)
|
|
23
|
-
);
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
async deleteCredential(req, res, user) {
|
|
27
|
-
await deleteCredentialForUser.execute(req.params.credentialId, user);
|
|
28
|
-
res.status(204).end();
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
module.exports = { createCredentialHandlers };
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
const { toEntityDto } = require('../dto');
|
|
2
|
-
const { objectBody, parseStep, parseListFilters } = require('../request');
|
|
3
|
-
|
|
4
|
-
/** Management API v2 entity and entity-type handlers, keyed by operationId. */
|
|
5
|
-
function createEntityHandlers(useCases) {
|
|
6
|
-
const {
|
|
7
|
-
listEntitiesForUser,
|
|
8
|
-
getEntityForUser,
|
|
9
|
-
deleteEntityForUser,
|
|
10
|
-
testEntityAuthForUser,
|
|
11
|
-
getEntityOptionsForUser,
|
|
12
|
-
refreshEntityOptionsForUser,
|
|
13
|
-
listEntityTypes,
|
|
14
|
-
getEntityType,
|
|
15
|
-
getAuthorizationRequirements,
|
|
16
|
-
} = useCases;
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
async listEntities(req, res, user) {
|
|
20
|
-
const entities = await listEntitiesForUser.execute(
|
|
21
|
-
user,
|
|
22
|
-
parseListFilters(req.query)
|
|
23
|
-
);
|
|
24
|
-
res.json({ entities: entities.map(toEntityDto) });
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
async listEntityTypes(_req, res, user) {
|
|
28
|
-
res.json({ types: await listEntityTypes.execute({ user }) });
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
async getEntityType(req, res, user) {
|
|
32
|
-
res.json(await getEntityType.execute(req.params.entityType, { user }));
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
// Describes a step's requirements without starting an authorization
|
|
36
|
-
// session; GET /api/v2/authorize starts one.
|
|
37
|
-
async getEntityTypeRequirements(req, res, user) {
|
|
38
|
-
res.json(
|
|
39
|
-
await getAuthorizationRequirements.execute({
|
|
40
|
-
entityType: req.params.entityType,
|
|
41
|
-
step: parseStep(req.query.step),
|
|
42
|
-
userId: user.getId(),
|
|
43
|
-
})
|
|
44
|
-
);
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
async getEntity(req, res, user) {
|
|
48
|
-
res.json(toEntityDto(await getEntityForUser.execute(req.params.entityId, user)));
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
async deleteEntity(req, res, user) {
|
|
52
|
-
await deleteEntityForUser.execute(req.params.entityId, user);
|
|
53
|
-
res.status(204).end();
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
async testEntityAuth(req, res, user) {
|
|
57
|
-
const ok = await testEntityAuthForUser.execute(req.params.entityId, user);
|
|
58
|
-
res.json({ status: ok ? 'ok' : 'failed' });
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
async getEntityOptions(req, res, user) {
|
|
62
|
-
res.json(await getEntityOptionsForUser.execute(req.params.entityId, user));
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
async refreshEntityOptions(req, res, user) {
|
|
66
|
-
res.json(
|
|
67
|
-
await refreshEntityOptionsForUser.execute(
|
|
68
|
-
req.params.entityId,
|
|
69
|
-
user,
|
|
70
|
-
objectBody(req)
|
|
71
|
-
)
|
|
72
|
-
);
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
module.exports = { createEntityHandlers };
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
const { toIntegrationDto } = require('../dto');
|
|
2
|
-
const { objectBody, optionalString, parseListFilters } = require('../request');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Management API v2 integration handlers, keyed by registry operationId.
|
|
6
|
-
* Each takes (req, res, user) after authentication and only calls use cases.
|
|
7
|
-
*/
|
|
8
|
-
function createIntegrationHandlers(useCases) {
|
|
9
|
-
const {
|
|
10
|
-
getIntegrationsForUser,
|
|
11
|
-
getPossibleIntegrations,
|
|
12
|
-
createIntegrationForUser,
|
|
13
|
-
getIntegrationInstanceForUser,
|
|
14
|
-
updateIntegrationForUser,
|
|
15
|
-
removeIntegrationForUser,
|
|
16
|
-
sendIntegrationEventForUser,
|
|
17
|
-
runIntegrationActionForUser,
|
|
18
|
-
testIntegrationAuthForUser,
|
|
19
|
-
} = useCases;
|
|
20
|
-
|
|
21
|
-
const send = (req, user, event, payload) =>
|
|
22
|
-
sendIntegrationEventForUser.execute(
|
|
23
|
-
req.params.integrationId,
|
|
24
|
-
user,
|
|
25
|
-
event,
|
|
26
|
-
payload
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
async listIntegrations(req, res, user) {
|
|
31
|
-
const integrations = await getIntegrationsForUser.execute(
|
|
32
|
-
user,
|
|
33
|
-
parseListFilters(req.query)
|
|
34
|
-
);
|
|
35
|
-
res.json({ integrations: integrations.map(toIntegrationDto) });
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
async listIntegrationOptions(_req, res) {
|
|
39
|
-
res.json({ integrations: await getPossibleIntegrations.execute() });
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
async createIntegration(req, res, user) {
|
|
43
|
-
const { entities, config } = objectBody(req);
|
|
44
|
-
const integration = await createIntegrationForUser.execute(
|
|
45
|
-
{ entities, config },
|
|
46
|
-
user
|
|
47
|
-
);
|
|
48
|
-
res.status(201).json(toIntegrationDto(integration));
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
async getIntegration(req, res, user) {
|
|
52
|
-
const instance = await getIntegrationInstanceForUser.execute(
|
|
53
|
-
req.params.integrationId,
|
|
54
|
-
user
|
|
55
|
-
);
|
|
56
|
-
res.json(toIntegrationDto(instance));
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
async updateIntegration(req, res, user) {
|
|
60
|
-
const { config } = objectBody(req);
|
|
61
|
-
const integration = await updateIntegrationForUser.execute(
|
|
62
|
-
req.params.integrationId,
|
|
63
|
-
user,
|
|
64
|
-
config
|
|
65
|
-
);
|
|
66
|
-
res.json(toIntegrationDto(integration));
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
async deleteIntegration(req, res, user) {
|
|
70
|
-
await removeIntegrationForUser.execute(req.params.integrationId, user);
|
|
71
|
-
res.status(204).end();
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
async getIntegrationConfigOptions(req, res, user) {
|
|
75
|
-
res.json(await send(req, user, 'GET_CONFIG_OPTIONS'));
|
|
76
|
-
},
|
|
77
|
-
|
|
78
|
-
async refreshIntegrationConfigOptions(req, res, user) {
|
|
79
|
-
res.json(await send(req, user, 'REFRESH_CONFIG_OPTIONS', objectBody(req)));
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
async listIntegrationActions(req, res, user) {
|
|
83
|
-
const actionType = optionalString(req.query.actionType, 'actionType');
|
|
84
|
-
res.json(
|
|
85
|
-
await send(req, user, 'GET_USER_ACTIONS', actionType ? { actionType } : {})
|
|
86
|
-
);
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
async getIntegrationActionOptions(req, res, user) {
|
|
90
|
-
res.json(
|
|
91
|
-
await send(req, user, 'GET_USER_ACTION_OPTIONS', {
|
|
92
|
-
actionId: req.params.actionId,
|
|
93
|
-
data: objectBody(req),
|
|
94
|
-
})
|
|
95
|
-
);
|
|
96
|
-
},
|
|
97
|
-
|
|
98
|
-
async refreshIntegrationActionOptions(req, res, user) {
|
|
99
|
-
res.json(
|
|
100
|
-
await send(req, user, 'REFRESH_USER_ACTION_OPTIONS', {
|
|
101
|
-
actionId: req.params.actionId,
|
|
102
|
-
data: objectBody(req),
|
|
103
|
-
})
|
|
104
|
-
);
|
|
105
|
-
},
|
|
106
|
-
|
|
107
|
-
async runIntegrationAction(req, res, user) {
|
|
108
|
-
res.json(
|
|
109
|
-
await runIntegrationActionForUser.execute(
|
|
110
|
-
req.params.integrationId,
|
|
111
|
-
user,
|
|
112
|
-
req.params.actionId,
|
|
113
|
-
objectBody(req)
|
|
114
|
-
)
|
|
115
|
-
);
|
|
116
|
-
},
|
|
117
|
-
|
|
118
|
-
async testIntegrationAuth(req, res, user) {
|
|
119
|
-
const { ok, errors } = await testIntegrationAuthForUser.execute(
|
|
120
|
-
req.params.integrationId,
|
|
121
|
-
user
|
|
122
|
-
);
|
|
123
|
-
res.json(ok ? { status: 'ok' } : { status: 'failed', errors });
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
module.exports = { createIntegrationHandlers };
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
const { toV2ErrorBody } = require('../../error-response');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* POST /api/v2/entities/:entityId/proxy (ADR-052). The HTTP status follows the
|
|
5
|
-
* upstream status. Proxy failures answer in the api-proxy.schema.json error
|
|
6
|
-
* shape, which is also the v2 error shape plus `success` and `status`.
|
|
7
|
-
*/
|
|
8
|
-
function createProxyHandlers({ executeEntityProxyRequest }) {
|
|
9
|
-
return {
|
|
10
|
-
async proxyEntityRequest(req, res, user) {
|
|
11
|
-
try {
|
|
12
|
-
const result = await executeEntityProxyRequest.execute(
|
|
13
|
-
req.params.entityId,
|
|
14
|
-
user,
|
|
15
|
-
req.body
|
|
16
|
-
);
|
|
17
|
-
res.status(result.status).json(result.body);
|
|
18
|
-
} catch (error) {
|
|
19
|
-
if (!error?.isBoom || !error.data?.proxy) throw error;
|
|
20
|
-
const status = error.output.statusCode;
|
|
21
|
-
if (error.data.retryAfter) {
|
|
22
|
-
res.set('Retry-After', String(error.data.retryAfter));
|
|
23
|
-
}
|
|
24
|
-
res.status(status).json({
|
|
25
|
-
success: false,
|
|
26
|
-
status,
|
|
27
|
-
...toV2ErrorBody(error),
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
module.exports = { createProxyHandlers };
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
const Boom = require('@hapi/boom');
|
|
2
|
-
const { LIST_OWNERS } = require('../../modules/scope-visibility');
|
|
3
|
-
|
|
4
|
-
/** The JSON body as an object, or a 400 VALIDATION_ERROR. */
|
|
5
|
-
function objectBody(req) {
|
|
6
|
-
const body = req.body;
|
|
7
|
-
if (body === undefined || body === null || body === '') return {};
|
|
8
|
-
if (typeof body !== 'object' || Array.isArray(body)) {
|
|
9
|
-
throw Boom.badRequest('Request body must be a JSON object', {
|
|
10
|
-
code: 'VALIDATION_ERROR',
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
return body;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** Fields that must be present (non-empty) in the body. */
|
|
17
|
-
function requireFields(body, fields) {
|
|
18
|
-
const missing = fields.filter(
|
|
19
|
-
(field) =>
|
|
20
|
-
body[field] === undefined || body[field] === null || body[field] === ''
|
|
21
|
-
);
|
|
22
|
-
if (missing.length) {
|
|
23
|
-
throw Boom.badRequest(
|
|
24
|
-
`Missing required field${missing.length > 1 ? 's' : ''}: ${missing.join(', ')}`,
|
|
25
|
-
{ code: 'VALIDATION_ERROR', details: { missing } }
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
return body;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** A 1-based step number from a query or body value; 1 when absent. */
|
|
32
|
-
function parseStep(value) {
|
|
33
|
-
if (value === undefined || value === null || value === '') return 1;
|
|
34
|
-
const step = Number(value);
|
|
35
|
-
if (!Number.isInteger(step) || step < 1) {
|
|
36
|
-
throw Boom.badRequest('step must be a positive integer', {
|
|
37
|
-
code: 'INVALID_STEP',
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
return step;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** An optional string query/body value. */
|
|
44
|
-
function optionalString(value, name) {
|
|
45
|
-
if (value === undefined || value === null || value === '') return undefined;
|
|
46
|
-
if (typeof value !== 'string') {
|
|
47
|
-
throw Boom.badRequest(`${name} must be a string`, {
|
|
48
|
-
code: 'VALIDATION_ERROR',
|
|
49
|
-
details: { field: name },
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
return value;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const LIST_SCOPES = ['individual', 'organization'];
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* `?scope=individual|organization` and `?owner=me|org` on a list (ADR-056
|
|
59
|
-
* §3.4). Anything else is a 400.
|
|
60
|
-
*/
|
|
61
|
-
function parseListFilters(query = {}) {
|
|
62
|
-
const scope = optionalString(query.scope, 'scope');
|
|
63
|
-
const owner = optionalString(query.owner, 'owner');
|
|
64
|
-
if (scope !== undefined && !LIST_SCOPES.includes(scope)) {
|
|
65
|
-
throw Boom.badRequest(`scope must be one of ${LIST_SCOPES.join(', ')}`, {
|
|
66
|
-
code: 'VALIDATION_ERROR',
|
|
67
|
-
details: { field: 'scope' },
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
if (owner !== undefined && !Object.hasOwn(LIST_OWNERS, owner)) {
|
|
71
|
-
throw Boom.badRequest('owner must be me or org', {
|
|
72
|
-
code: 'VALIDATION_ERROR',
|
|
73
|
-
details: { field: 'owner' },
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
return { scope, owner };
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
module.exports = {
|
|
80
|
-
objectBody,
|
|
81
|
-
requireFields,
|
|
82
|
-
parseStep,
|
|
83
|
-
optionalString,
|
|
84
|
-
parseListFilters,
|
|
85
|
-
};
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
const Boom = require('@hapi/boom');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* In-memory doubles for every Management API v2 dependency. Each use case is
|
|
5
|
-
* a jest.fn() so a test can assert on calls or override one behaviour.
|
|
6
|
-
*/
|
|
7
|
-
function fakeV2Dependencies(overrides = {}) {
|
|
8
|
-
const user = { getId: () => 'user-1' };
|
|
9
|
-
const notFound = (code) => async () => {
|
|
10
|
-
throw Boom.notFound('not found', { code });
|
|
11
|
-
};
|
|
12
|
-
const fn = (impl) => ({ execute: jest.fn(impl) });
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
user,
|
|
16
|
-
config: { v1: true, proxy: { enable: false } },
|
|
17
|
-
authenticateUser: {
|
|
18
|
-
execute: jest.fn(async (req) => {
|
|
19
|
-
if (!req.headers.authorization) {
|
|
20
|
-
throw Boom.unauthorized('No valid authentication provided');
|
|
21
|
-
}
|
|
22
|
-
return user;
|
|
23
|
-
}),
|
|
24
|
-
},
|
|
25
|
-
getIntegrationsForUser: fn(async () => [
|
|
26
|
-
{ id: 'i1', entities: ['e1'], status: 'ENABLED', config: { type: 'sync' }, userActions: {} },
|
|
27
|
-
]),
|
|
28
|
-
getPossibleIntegrations: fn(async () => [{ type: 'sync', display: {} }]),
|
|
29
|
-
createIntegrationForUser: fn(async () => ({
|
|
30
|
-
id: 'i2', entities: ['e1'], status: 'ENABLED', config: { type: 'sync' },
|
|
31
|
-
})),
|
|
32
|
-
getIntegrationInstanceForUser: fn(async (id) => {
|
|
33
|
-
if (id !== 'i1') return notFound('INTEGRATION_NOT_FOUND')();
|
|
34
|
-
return { id: 'i1', entities: ['e1'], status: 'ENABLED', config: { type: 'sync' } };
|
|
35
|
-
}),
|
|
36
|
-
updateIntegrationForUser: fn(async (id, _user, config) => ({
|
|
37
|
-
id, entities: ['e1'], status: 'ENABLED', config,
|
|
38
|
-
})),
|
|
39
|
-
removeIntegrationForUser: fn(async () => undefined),
|
|
40
|
-
sendIntegrationEventForUser: fn(async (_id, _user, event, payload) => ({ event, payload })),
|
|
41
|
-
runIntegrationActionForUser: fn(async (_id, _user, actionId, payload) => ({ ran: actionId, payload })),
|
|
42
|
-
testIntegrationAuthForUser: fn(async () => ({ ok: true, errors: [] })),
|
|
43
|
-
|
|
44
|
-
listEntitiesForUser: fn(async () => [
|
|
45
|
-
{ id: 'e1', userId: 'user-1', moduleName: 'acme', name: 'Acme', externalId: 'x1', credential: { id: 'c1', authIsValid: true, access_token: 'secret' } },
|
|
46
|
-
]),
|
|
47
|
-
getEntityForUser: fn(async (id) => {
|
|
48
|
-
if (id !== 'e1') return notFound('ENTITY_NOT_FOUND')();
|
|
49
|
-
return { id: 'e1', userId: 'user-1', moduleName: 'acme', name: 'Acme', externalId: 'x1', credential: { id: 'c1', authIsValid: true, access_token: 'secret' } };
|
|
50
|
-
}),
|
|
51
|
-
deleteEntityForUser: fn(async () => undefined),
|
|
52
|
-
testEntityAuthForUser: fn(async () => true),
|
|
53
|
-
getEntityOptionsForUser: fn(async () => ({ jsonSchema: {} })),
|
|
54
|
-
refreshEntityOptionsForUser: fn(async (_id, _user, body) => ({ refreshed: body })),
|
|
55
|
-
listEntityTypes: fn(async () => [{ type: 'acme', name: 'Acme' }]),
|
|
56
|
-
getEntityType: fn(async (type) => {
|
|
57
|
-
if (type !== 'acme') return notFound('ENTITY_TYPE_NOT_FOUND')();
|
|
58
|
-
return { type: 'acme', name: 'Acme' };
|
|
59
|
-
}),
|
|
60
|
-
getAuthorizationRequirements: fn(async ({ step }) => ({
|
|
61
|
-
type: 'oauth2', data: { url: 'https://provider.example/authorize' }, step, totalSteps: 1, isMultiStep: false,
|
|
62
|
-
})),
|
|
63
|
-
listCredentialsForUser: fn(async () => [
|
|
64
|
-
{ id: 'c1', userId: 'user-1', type: 'acme', entityIds: ['e1'], authIsValid: true, access_token: 'ya29.secret-token-value-1234' },
|
|
65
|
-
]),
|
|
66
|
-
getCredentialForUser: fn(async (id) => {
|
|
67
|
-
if (id !== 'c1') return notFound('CREDENTIAL_NOT_FOUND')();
|
|
68
|
-
return { id: 'c1', userId: 'user-1', type: 'acme', entityIds: ['e1'], authIsValid: true, api_key: 'sk_live_abcdefghijkl9876' };
|
|
69
|
-
}),
|
|
70
|
-
deleteCredentialForUser: fn(async () => ({ id: 'c1', entityIds: ['e1'] })),
|
|
71
|
-
getAuthorizationStep: fn(async ({ entityType, step }) => {
|
|
72
|
-
if (entityType === 'nope') return notFound('ENTITY_TYPE_NOT_FOUND')();
|
|
73
|
-
return { type: 'email', data: {}, step, totalSteps: 2, isMultiStep: true, sessionId: 'sess-1' };
|
|
74
|
-
}),
|
|
75
|
-
submitAuthorizationStep: fn(async ({ step }) =>
|
|
76
|
-
step === 1
|
|
77
|
-
? { status: 'pending', step: 2, totalSteps: 2, sessionId: 'sess-1', requirements: { type: 'otp' } }
|
|
78
|
-
: {
|
|
79
|
-
status: 'complete',
|
|
80
|
-
entity: { id: 'e1', userId: 'user-1', moduleName: 'acme', credential: { id: 'c1', authIsValid: true } },
|
|
81
|
-
credential: { id: 'c1', userId: 'user-1', type: 'acme', entityIds: ['e1'], authIsValid: true, access_token: 'ya29.brand-new-token-0001' },
|
|
82
|
-
}
|
|
83
|
-
),
|
|
84
|
-
getCredentialReauthorization: fn(async (id, _user, { step }) => ({ type: 'oauth2', data: {}, step, totalSteps: 1 })),
|
|
85
|
-
reauthorizeCredentialForUser: fn(async () => ({
|
|
86
|
-
status: 'complete',
|
|
87
|
-
entity: { id: 'e1', userId: 'user-1', moduleName: 'acme' },
|
|
88
|
-
credential: { id: 'c2', userId: 'user-1', type: 'acme', entityIds: ['e1'], authIsValid: true },
|
|
89
|
-
previousCredentialId: 'c1',
|
|
90
|
-
})),
|
|
91
|
-
executeEntityProxyRequest: fn(async (entityId, _user, request) => {
|
|
92
|
-
if (request?.path === '/limited') {
|
|
93
|
-
throw Boom.tooManyRequests('The upstream API is rate limiting this account', {
|
|
94
|
-
code: 'RATE_LIMITED', proxy: true, expose: true, retryAfter: '30', details: { upstreamStatus: 429 },
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
return { status: 201, body: { success: true, status: 201, headers: {}, data: { id: 'new' } } };
|
|
98
|
-
}),
|
|
99
|
-
...overrides,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
module.exports = { fakeV2Dependencies };
|