@verii/endpoints-organizations-registrar 1.0.0-pre.1752076816
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/LICENSE +202 -0
- package/NOTICE +1 -0
- package/README.md +3 -0
- package/package.json +86 -0
- package/src/config/abi.json +1 -0
- package/src/config/config.js +261 -0
- package/src/controllers/consents/autohooks.js +6 -0
- package/src/controllers/consents/controller.js +106 -0
- package/src/controllers/consents/schemas/consent-response.schema.js +45 -0
- package/src/controllers/did-web-host/controller.js +64 -0
- package/src/controllers/groups/autohooks.js +10 -0
- package/src/controllers/groups/controller.js +172 -0
- package/src/controllers/groups/schemas/group.schema.json +22 -0
- package/src/controllers/groups/schemas/index.js +7 -0
- package/src/controllers/groups/schemas/modify-group.schema.json +25 -0
- package/src/controllers/image_upload/controller.js +48 -0
- package/src/controllers/invitations/controller.js +79 -0
- package/src/controllers/organizations/_did/autohooks.js +16 -0
- package/src/controllers/organizations/_did/controller.js +617 -0
- package/src/controllers/organizations/_did/invitations/_invitationId/autohooks.js +16 -0
- package/src/controllers/organizations/_did/invitations/_invitationId/controller.js +217 -0
- package/src/controllers/organizations/_did/invitations/controller.js +197 -0
- package/src/controllers/organizations/_did/keys/controller.js +141 -0
- package/src/controllers/organizations/_did/services/controller.js +195 -0
- package/src/controllers/organizations/_did/signatories/controller.js +63 -0
- package/src/controllers/organizations/autohooks.js +65 -0
- package/src/controllers/organizations/controller.js +322 -0
- package/src/controllers/organizations/full/controller.js +285 -0
- package/src/controllers/organizations/plugins.js +21 -0
- package/src/controllers/organizations/schemas/add-key-body.schema.json +35 -0
- package/src/controllers/organizations/schemas/create-did-service.schema.json +70 -0
- package/src/controllers/organizations/schemas/did-key.schema.json +178 -0
- package/src/controllers/organizations/schemas/full-organization.schema.json +35 -0
- package/src/controllers/organizations/schemas/index.js +33 -0
- package/src/controllers/organizations/schemas/invitationCodeProperty.schema.json +3 -0
- package/src/controllers/organizations/schemas/organization-ids.schema.json +34 -0
- package/src/controllers/organizations/schemas/organization-kyb-profile-creation.schema.json +26 -0
- package/src/controllers/organizations/schemas/organization-profile-creation.schema.json +20 -0
- package/src/controllers/organizations/schemas/organization-profile-update.schema.json +19 -0
- package/src/controllers/organizations/schemas/organization-profile-verifiable-credential.schema.json +25 -0
- package/src/controllers/organizations/schemas/organization-registry-service-response.schema.json +26 -0
- package/src/controllers/organizations/schemas/organization-service.schema.json +34 -0
- package/src/controllers/organizations/schemas/organization-verified-profile.schema.json +123 -0
- package/src/controllers/organizations/schemas/organization.search-profile.query-params.schema.json +50 -0
- package/src/controllers/organizations/schemas/organization.search.query-params.schema.json +42 -0
- package/src/controllers/reference/controller.js +103 -0
- package/src/controllers/resolve-did/controller.js +45 -0
- package/src/controllers/resolve-did/resolve-did.js +30 -0
- package/src/controllers/resolve-did/schemas/did-doc.schema.json +155 -0
- package/src/controllers/resolve-did/schemas/did-proof.schema.json +44 -0
- package/src/controllers/resolve-did/schemas/index.js +26 -0
- package/src/controllers/resolve-did/schemas/public-key.schema.json +173 -0
- package/src/controllers/resolve-kid/controller.js +76 -0
- package/src/controllers/resolve-kid/public-key-formats.js +8 -0
- package/src/controllers/service-types/controller.js +81 -0
- package/src/controllers/setup_image_upload/controller.js +99 -0
- package/src/controllers/signatories/controller.js +43 -0
- package/src/controllers/users/autohooks.js +10 -0
- package/src/controllers/users/controller.js +221 -0
- package/src/controllers/users/schemas/base-user.schema.json +55 -0
- package/src/controllers/users/schemas/index.js +4 -0
- package/src/controllers/users/schemas/modify-user.schema.js +17 -0
- package/src/controllers/users/schemas/user.schema.js +20 -0
- package/src/entities/groups/domain/constants.js +21 -0
- package/src/entities/groups/domain/index.js +19 -0
- package/src/entities/groups/factories/groups-factory.js +48 -0
- package/src/entities/groups/factories/index.js +17 -0
- package/src/entities/groups/index.js +19 -0
- package/src/entities/groups/repo.js +122 -0
- package/src/entities/images/domain/constant.js +11 -0
- package/src/entities/images/domain/index.js +3 -0
- package/src/entities/images/extension/activate.extension.js +35 -0
- package/src/entities/images/extension/deactivate.extension.js +27 -0
- package/src/entities/images/extension/find-by-url.extension.js +24 -0
- package/src/entities/images/extension/index.js +5 -0
- package/src/entities/images/factories/images-factory.js +43 -0
- package/src/entities/images/factories/index.js +17 -0
- package/src/entities/images/index.js +5 -0
- package/src/entities/images/repo.js +43 -0
- package/src/entities/images/schema/image-metadata.schema.js +58 -0
- package/src/entities/images/schema/index.js +3 -0
- package/src/entities/index.js +31 -0
- package/src/entities/invitations/domains/build-invitation-url.js +14 -0
- package/src/entities/invitations/domains/get-given-family-name-from-name.js +20 -0
- package/src/entities/invitations/domains/index.js +7 -0
- package/src/entities/invitations/domains/init-invitation-emails.js +17 -0
- package/src/entities/invitations/domains/is-invitation-expired.js +5 -0
- package/src/entities/invitations/domains/validate-invitee-email.js +18 -0
- package/src/entities/invitations/factories/index.js +17 -0
- package/src/entities/invitations/factories/invitations-factory.js +51 -0
- package/src/entities/invitations/index.js +6 -0
- package/src/entities/invitations/orchestrators/accept-invitation.js +24 -0
- package/src/entities/invitations/orchestrators/index.js +4 -0
- package/src/entities/invitations/orchestrators/send-email-invitee.js +36 -0
- package/src/entities/invitations/repo.js +37 -0
- package/src/entities/invitations/schemas/add-invitation-body.js +122 -0
- package/src/entities/invitations/schemas/get-invitation-response-body.js +20 -0
- package/src/entities/invitations/schemas/index.js +5 -0
- package/src/entities/invitations/schemas/invitation-response-item-body.js +61 -0
- package/src/entities/kms/factories/index.js +17 -0
- package/src/entities/kms/factories/kms-factory.js +31 -0
- package/src/entities/monitors/index.js +17 -0
- package/src/entities/monitors/orchestrators/index.js +17 -0
- package/src/entities/monitors/orchestrators/monitors.js +230 -0
- package/src/entities/oauth/domain/constants.js +23 -0
- package/src/entities/oauth/domain/index.js +5 -0
- package/src/entities/oauth/domain/roles.js +92 -0
- package/src/entities/oauth/domain/scopes.js +35 -0
- package/src/entities/oauth/index.js +4 -0
- package/src/entities/oauth/orchestrators/auth0-provisioner.js +293 -0
- package/src/entities/oauth/orchestrators/index.js +3 -0
- package/src/entities/organization-keys/domains/build-organization-key.js +50 -0
- package/src/entities/organization-keys/domains/constants.js +30 -0
- package/src/entities/organization-keys/domains/extract-verification-method-from-byo-did-document.js +38 -0
- package/src/entities/organization-keys/domains/find-key-by-purpose.js +6 -0
- package/src/entities/organization-keys/domains/index.js +10 -0
- package/src/entities/organization-keys/domains/jwk-to-hex-key-transformer.js +13 -0
- package/src/entities/organization-keys/domains/map-key-response.js +29 -0
- package/src/entities/organization-keys/domains/validate-non-custodial-key.js +11 -0
- package/src/entities/organization-keys/domains/validate-organization-key.js +42 -0
- package/src/entities/organization-keys/factories/index.js +17 -0
- package/src/entities/organization-keys/factories/organization-keys-factory.js +55 -0
- package/src/entities/organization-keys/index.js +5 -0
- package/src/entities/organization-keys/orchestrators/add-key-to-did-doc.js +19 -0
- package/src/entities/organization-keys/orchestrators/add-key.js +155 -0
- package/src/entities/organization-keys/orchestrators/add-operator-keys.js +46 -0
- package/src/entities/organization-keys/orchestrators/delete-key.js +93 -0
- package/src/entities/organization-keys/orchestrators/get-key.js +39 -0
- package/src/entities/organization-keys/orchestrators/index.js +24 -0
- package/src/entities/organization-keys/orchestrators/resolve-verification-method-byo-did.js +28 -0
- package/src/entities/organization-keys/repos/repo.js +48 -0
- package/src/entities/organization-services/adapters/index.js +21 -0
- package/src/entities/organization-services/adapters/init-provision-auth0-client-grants.js +44 -0
- package/src/entities/organization-services/adapters/init-provision-auth0-clients.js +56 -0
- package/src/entities/organization-services/adapters/update-blockchain-permissions-from-permitted-services.js +118 -0
- package/src/entities/organization-services/domains/activate-services.js +12 -0
- package/src/entities/organization-services/domains/build-organizations-services.js +38 -0
- package/src/entities/organization-services/domains/build-public-services.js +19 -0
- package/src/entities/organization-services/domains/constants.js +32 -0
- package/src/entities/organization-services/domains/extract-cao-service-refs.js +10 -0
- package/src/entities/organization-services/domains/extract-service-endpoint-did.js +10 -0
- package/src/entities/organization-services/domains/get-service-consent-type.js +16 -0
- package/src/entities/organization-services/domains/get-service-types-from-categories.js +18 -0
- package/src/entities/organization-services/domains/index.js +17 -0
- package/src/entities/organization-services/domains/is-new-node-operator-service.js +25 -0
- package/src/entities/organization-services/domains/is-service-category.js +31 -0
- package/src/entities/organization-services/domains/normalize-service-endpoint.js +6 -0
- package/src/entities/organization-services/domains/select-activated-services.js +8 -0
- package/src/entities/organization-services/domains/transform-profile-service.js +88 -0
- package/src/entities/organization-services/domains/validate-cao-service-refs.js +25 -0
- package/src/entities/organization-services/domains/validate-service-credential-type.js +47 -0
- package/src/entities/organization-services/domains/validate-service-endpoint.js +35 -0
- package/src/entities/organization-services/domains/validate-service-fields-by-service-type.js +37 -0
- package/src/entities/organization-services/domains/validate-service-id-uniqueness.js +19 -0
- package/src/entities/organization-services/domains/validate-service-key-purposes.js +56 -0
- package/src/entities/organization-services/domains/validate-service-type.js +12 -0
- package/src/entities/organization-services/domains/validate-service.js +80 -0
- package/src/entities/organization-services/domains/validate-services-for-delete.js +32 -0
- package/src/entities/organization-services/index.js +5 -0
- package/src/entities/organization-services/orchestrators/add-service.js +106 -0
- package/src/entities/organization-services/orchestrators/delete-service.js +142 -0
- package/src/entities/organization-services/orchestrators/get-service.js +36 -0
- package/src/entities/organization-services/orchestrators/index.js +8 -0
- package/src/entities/organization-services/orchestrators/init-add-service-to-organization.js +141 -0
- package/src/entities/organization-services/orchestrators/load-cao-service-refs.js +56 -0
- package/src/entities/organization-services/orchestrators/update-service.js +103 -0
- package/src/entities/organizations/adapters/index.js +6 -0
- package/src/entities/organizations/adapters/init-organization-registrar-emails.js +215 -0
- package/src/entities/organizations/adapters/init-send-activation-emails-to-caos.js +89 -0
- package/src/entities/organizations/adapters/send-email-invitation-accepted-to-inviter.js +70 -0
- package/src/entities/organizations/adapters/send-email-notifications.js +212 -0
- package/src/entities/organizations/domains/build-custodied-did-web.js +12 -0
- package/src/entities/organizations/domains/build-full-organization-response.js +40 -0
- package/src/entities/organizations/domains/build-organization-modifications-on-service-change.js +82 -0
- package/src/entities/organizations/domains/build-profile-vc-url.js +8 -0
- package/src/entities/organizations/domains/build-profile-verifiable-credential.js +36 -0
- package/src/entities/organizations/domains/build-public-profile.js +9 -0
- package/src/entities/organizations/domains/constants.js +54 -0
- package/src/entities/organizations/domains/index.js +17 -0
- package/src/entities/organizations/domains/organization-vc-checks.js +49 -0
- package/src/entities/organizations/domains/parse-profile-to-csv.js +41 -0
- package/src/entities/organizations/domains/prepare-profile-vc.js +28 -0
- package/src/entities/organizations/domains/profile-name-normalization.js +5 -0
- package/src/entities/organizations/domains/validate-byo-did-keys.js +28 -0
- package/src/entities/organizations/domains/validate-profile-name.js +48 -0
- package/src/entities/organizations/domains/validate-profile-website.js +17 -0
- package/src/entities/organizations/domains/validate-update-profile.js +11 -0
- package/src/entities/organizations/factories/index.js +17 -0
- package/src/entities/organizations/factories/organizations-factory.js +180 -0
- package/src/entities/organizations/index.js +6 -0
- package/src/entities/organizations/orchestrators/add-primary-permissions.js +28 -0
- package/src/entities/organizations/orchestrators/build-custodied-organization.js +92 -0
- package/src/entities/organizations/orchestrators/build-non-custodied-organization.js +83 -0
- package/src/entities/organizations/orchestrators/index.js +6 -0
- package/src/entities/organizations/orchestrators/init-create-organization.js +221 -0
- package/src/entities/organizations/orchestrators/init-provision-group.js +48 -0
- package/src/entities/organizations/orchestrators/verify-profile-website-unique.js +15 -0
- package/src/entities/organizations/repos/find-caos-extension.js +49 -0
- package/src/entities/organizations/repos/index.js +17 -0
- package/src/entities/organizations/repos/repo.js +156 -0
- package/src/entities/organizations/repos/search-by-aggregation-extension.js +128 -0
- package/src/entities/organizations/repos/transform-did-filter.js +13 -0
- package/src/entities/organizations/repos/transform-organization-filter.js +106 -0
- package/src/entities/registrar-consents/constants.js +10 -0
- package/src/entities/registrar-consents/factories/index.js +17 -0
- package/src/entities/registrar-consents/factories/registrar-consents-factory.js +38 -0
- package/src/entities/registrar-consents/index.js +3 -0
- package/src/entities/registrar-consents/repos/registrar-consent-repo-extension.js +55 -0
- package/src/entities/registrar-consents/repos/repo.js +31 -0
- package/src/entities/signatories/domain/constants.js +12 -0
- package/src/entities/signatories/domain/index.js +4 -0
- package/src/entities/signatories/domain/organization-emails.js +29 -0
- package/src/entities/signatories/factories/index.js +17 -0
- package/src/entities/signatories/factories/signatory-status-factory.js +53 -0
- package/src/entities/signatories/index.js +5 -0
- package/src/entities/signatories/orchestrators/approve-reminder.js +24 -0
- package/src/entities/signatories/orchestrators/index.js +6 -0
- package/src/entities/signatories/orchestrators/reject-reminder.js +17 -0
- package/src/entities/signatories/orchestrators/send-reminders.js +102 -0
- package/src/entities/signatories/orchestrators/validate-auth-code.js +56 -0
- package/src/entities/signatories/repos/index.js +3 -0
- package/src/entities/signatories/repos/repo.js +35 -0
- package/src/entities/signatories/repos/signatory-status-state-repo-extension.js +124 -0
- package/src/entities/users/domains/constants.js +40 -0
- package/src/entities/users/domains/index.js +4 -0
- package/src/entities/users/domains/user-registrar-emails.js +52 -0
- package/src/entities/users/index.js +4 -0
- package/src/entities/users/orchestrators/create-auth0-user.js +60 -0
- package/src/entities/users/orchestrators/get-or-create-auth0-user.js +63 -0
- package/src/entities/users/orchestrators/index.js +22 -0
- package/src/entities/users/orchestrators/user-management.js +157 -0
- package/src/fetchers/index.js +19 -0
- package/src/fetchers/monitoring/index.js +9 -0
- package/src/fetchers/monitoring/monitor-add-to-page-fetcher.js +18 -0
- package/src/fetchers/monitoring/monitor-create-fetcher.js +23 -0
- package/src/fetchers/monitoring/monitor-delete-fetcher.js +6 -0
- package/src/fetchers/monitoring/monitor-get-all-fetcher.js +6 -0
- package/src/fetchers/monitoring/section-create-fetcher.js +16 -0
- package/src/fetchers/monitoring/section-get-all-fetcher.js +6 -0
- package/src/fetchers/monitoring/service-version-fetcher.js +6 -0
- package/src/helpers/init-permissions-contract.js +48 -0
- package/src/index.js +23 -0
- package/src/init-server.js +91 -0
- package/src/organizations-registrar-endpoints.js +68 -0
- package/src/plugins/authorization.js +233 -0
- package/src/plugins/index.js +4 -0
- package/src/plugins/pubsub-plugin.js +82 -0
- package/src/subscribers/notify-caos.js +63 -0
- package/src/subscribers/notify-inviters.js +42 -0
- package/src/subscribers/notify-monitoring.js +40 -0
- package/src/subscribers/notify-signatory.js +51 -0
- package/src/subscribers/notify-support-and-groups.js +95 -0
- package/src/templates/invitee-invitation-email-body.hbs +13 -0
- package/src/templates/invitee-invitation-email-subject.hbs +1 -0
- package/src/templates/signatory-approval-email-body.hbs +92 -0
- package/src/templates/support-organization-created-body.hbs +17 -0
- package/src/templates/support-organization-created-subject.hbs +1 -0
- package/src/templates/support-signatory-max-reminders-reached-email-body.hbs +6 -0
- package/src/templates/support-signatory-max-reminders-reached-email-subject.hbs +1 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
const { isEmpty } = require('lodash/fp');
|
|
2
|
+
const newError = require('http-errors');
|
|
3
|
+
const { nanoid } = require('nanoid/non-secure');
|
|
4
|
+
const { addSeconds } = require('date-fns/fp');
|
|
5
|
+
const {
|
|
6
|
+
verifyUserOrganizationWriteAuthorized,
|
|
7
|
+
} = require('../../../../../plugins/authorization');
|
|
8
|
+
const { initGetOrCreateAuth0User } = require('../../../../../entities/users');
|
|
9
|
+
const {
|
|
10
|
+
RegistrarScopes,
|
|
11
|
+
getInvitationResponseBodySchema,
|
|
12
|
+
buildInvitationUrl,
|
|
13
|
+
initSendEmailInvitee,
|
|
14
|
+
validateInviteeEmail,
|
|
15
|
+
} = require('../../../../../entities');
|
|
16
|
+
|
|
17
|
+
const invitationController = async (fastify) => {
|
|
18
|
+
const sendEmailToInvitee = initSendEmailInvitee(fastify);
|
|
19
|
+
|
|
20
|
+
const getOrCreateAuth0User = initGetOrCreateAuth0User(fastify);
|
|
21
|
+
|
|
22
|
+
fastify.get(
|
|
23
|
+
'/',
|
|
24
|
+
{
|
|
25
|
+
onRequest: fastify.verifyAccessToken([
|
|
26
|
+
RegistrarScopes.ReadOrganizations,
|
|
27
|
+
RegistrarScopes.AdminOrganizations,
|
|
28
|
+
]),
|
|
29
|
+
preHandler: [verifyUserOrganizationWriteAuthorized],
|
|
30
|
+
schema: fastify.autoSchema({
|
|
31
|
+
security: [
|
|
32
|
+
{
|
|
33
|
+
RegistrarOAuth2: [
|
|
34
|
+
RegistrarScopes.ReadOrganizations,
|
|
35
|
+
RegistrarScopes.AdminOrganizations,
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
response: {
|
|
40
|
+
200: getInvitationResponseBodySchema,
|
|
41
|
+
},
|
|
42
|
+
}),
|
|
43
|
+
},
|
|
44
|
+
async (req) => {
|
|
45
|
+
const {
|
|
46
|
+
params: { did, invitationId },
|
|
47
|
+
repos,
|
|
48
|
+
} = req;
|
|
49
|
+
await repos.organizations.findOneByDid(did, {
|
|
50
|
+
_id: 1,
|
|
51
|
+
});
|
|
52
|
+
const invitation = await repos.invitations.findOne({
|
|
53
|
+
filter: {
|
|
54
|
+
_id: invitationId,
|
|
55
|
+
inviterDid: did,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
if (isEmpty(invitation)) {
|
|
60
|
+
throw newError(404, 'Invitation not found', {
|
|
61
|
+
errorCode: 'invitation_not_found',
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
invitation,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
fastify.put(
|
|
72
|
+
'/',
|
|
73
|
+
{
|
|
74
|
+
onRequest: fastify.verifyAccessToken([
|
|
75
|
+
RegistrarScopes.WriteOrganizations,
|
|
76
|
+
RegistrarScopes.AdminOrganizations,
|
|
77
|
+
]),
|
|
78
|
+
preHandler: [verifyUserOrganizationWriteAuthorized],
|
|
79
|
+
schema: fastify.autoSchema({
|
|
80
|
+
security: [
|
|
81
|
+
{
|
|
82
|
+
RegistrarOAuth2: [
|
|
83
|
+
RegistrarScopes.WriteOrganizations,
|
|
84
|
+
RegistrarScopes.AdminOrganizations,
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
body: {
|
|
89
|
+
type: 'object',
|
|
90
|
+
properties: {
|
|
91
|
+
inviteeEmail: {
|
|
92
|
+
type: 'string',
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
required: ['inviteeEmail'],
|
|
96
|
+
},
|
|
97
|
+
response: {
|
|
98
|
+
200: getInvitationResponseBodySchema,
|
|
99
|
+
},
|
|
100
|
+
}),
|
|
101
|
+
},
|
|
102
|
+
async (req) => {
|
|
103
|
+
const {
|
|
104
|
+
body: { inviteeEmail },
|
|
105
|
+
params: { did, invitationId },
|
|
106
|
+
config: { registrarResendInvitationTtl },
|
|
107
|
+
repos,
|
|
108
|
+
} = req;
|
|
109
|
+
const inviterOrganization = await repos.organizations.findOneByDid(did);
|
|
110
|
+
validateInviteeEmail(inviteeEmail);
|
|
111
|
+
|
|
112
|
+
const code = nanoid(16);
|
|
113
|
+
const expiresAt = addSeconds(registrarResendInvitationTtl, new Date());
|
|
114
|
+
const invitationUrl = buildInvitationUrl({ code }, req);
|
|
115
|
+
|
|
116
|
+
const invitation = await repos.invitations.findOne({
|
|
117
|
+
filter: {
|
|
118
|
+
_id: invitationId,
|
|
119
|
+
inviterDid: did,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
if (isEmpty(invitation)) {
|
|
124
|
+
throw newError(404, 'Invitation not found', {
|
|
125
|
+
errorCode: 'invitation_not_found',
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const { ticket } = await getOrCreateAuth0User(
|
|
130
|
+
inviteeEmail,
|
|
131
|
+
invitation.keyIndividuals.adminGivenName,
|
|
132
|
+
invitation.keyIndividuals.adminFamilyName,
|
|
133
|
+
req
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
await repos.invitations.update(invitation._id, {
|
|
137
|
+
code,
|
|
138
|
+
inviteeEmail,
|
|
139
|
+
invitationUrl,
|
|
140
|
+
expiresAt,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const messageCode = await sendEmailToInvitee(
|
|
144
|
+
{
|
|
145
|
+
inviteeEmail,
|
|
146
|
+
inviterOrganization,
|
|
147
|
+
ticket,
|
|
148
|
+
code,
|
|
149
|
+
},
|
|
150
|
+
req
|
|
151
|
+
);
|
|
152
|
+
return {
|
|
153
|
+
invitation: {
|
|
154
|
+
...invitation,
|
|
155
|
+
code,
|
|
156
|
+
expiresAt,
|
|
157
|
+
invitationUrl,
|
|
158
|
+
inviteeEmail,
|
|
159
|
+
},
|
|
160
|
+
messageCode,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
fastify.delete(
|
|
166
|
+
'/',
|
|
167
|
+
{
|
|
168
|
+
onRequest: fastify.verifyAccessToken([
|
|
169
|
+
RegistrarScopes.WriteOrganizations,
|
|
170
|
+
RegistrarScopes.AdminOrganizations,
|
|
171
|
+
]),
|
|
172
|
+
preHandler: [verifyUserOrganizationWriteAuthorized],
|
|
173
|
+
schema: fastify.autoSchema({
|
|
174
|
+
security: [
|
|
175
|
+
{
|
|
176
|
+
RegistrarOAuth2: [
|
|
177
|
+
RegistrarScopes.WriteOrganizations,
|
|
178
|
+
RegistrarScopes.AdminOrganizations,
|
|
179
|
+
],
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
response: {
|
|
183
|
+
204: { type: 'null' },
|
|
184
|
+
},
|
|
185
|
+
}),
|
|
186
|
+
},
|
|
187
|
+
async (req, rep) => {
|
|
188
|
+
const {
|
|
189
|
+
params: { did, invitationId },
|
|
190
|
+
repos,
|
|
191
|
+
user,
|
|
192
|
+
} = req;
|
|
193
|
+
await repos.organizations.findOneByDid(did, { _id: 1 });
|
|
194
|
+
const deletedAt = new Date();
|
|
195
|
+
const invitation = await repos.invitations.findOne({
|
|
196
|
+
filter: {
|
|
197
|
+
_id: invitationId,
|
|
198
|
+
inviterDid: did,
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
if (isEmpty(invitation)) {
|
|
203
|
+
throw newError(404, 'Invitation not found', {
|
|
204
|
+
errorCode: 'invitation_not_found',
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
await repos.invitations.update(invitation._id, {
|
|
209
|
+
deletedAt,
|
|
210
|
+
deletedBy: user.sub,
|
|
211
|
+
});
|
|
212
|
+
return rep.status(204).send();
|
|
213
|
+
}
|
|
214
|
+
);
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
module.exports = invitationController;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
const { find, forEach, isEmpty } = require('lodash/fp');
|
|
2
|
+
const { addSeconds } = require('date-fns/fp');
|
|
3
|
+
const newError = require('http-errors');
|
|
4
|
+
const { nanoid } = require('nanoid/non-secure');
|
|
5
|
+
const { initTransformToFinder } = require('@verii/rest-queries');
|
|
6
|
+
const { tableRegistry } = require('@spencejs/spence-mongo-repos');
|
|
7
|
+
const {
|
|
8
|
+
verifyUserOrganizationWriteAuthorized,
|
|
9
|
+
} = require('../../../../plugins/authorization');
|
|
10
|
+
const { initGetOrCreateAuth0User } = require('../../../../entities/users');
|
|
11
|
+
const {
|
|
12
|
+
RegistrarScopes,
|
|
13
|
+
initSendEmailInvitee,
|
|
14
|
+
invitationResponseItemBodySchema,
|
|
15
|
+
isCaoService,
|
|
16
|
+
addInvitationBodySchema,
|
|
17
|
+
buildInvitationUrl,
|
|
18
|
+
validateInviteeEmail,
|
|
19
|
+
validateInviteeService,
|
|
20
|
+
buildReferenceCaoServices,
|
|
21
|
+
extractCaoServiceRefs,
|
|
22
|
+
} = require('../../../../entities');
|
|
23
|
+
const { registeredCredentialTypesPreHandler } = require('../../plugins');
|
|
24
|
+
|
|
25
|
+
const invitationsController = async (fastify) => {
|
|
26
|
+
const transformToFinder = initTransformToFinder(
|
|
27
|
+
await tableRegistry.invitations()
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const getOrCreateAuth0User = initGetOrCreateAuth0User(fastify);
|
|
31
|
+
const sendEmailToInvitee = initSendEmailInvitee(fastify);
|
|
32
|
+
|
|
33
|
+
fastify.post(
|
|
34
|
+
'/',
|
|
35
|
+
{
|
|
36
|
+
onRequest: fastify.verifyAccessToken([
|
|
37
|
+
RegistrarScopes.WriteOrganizations,
|
|
38
|
+
RegistrarScopes.AdminOrganizations,
|
|
39
|
+
]),
|
|
40
|
+
preHandler: [
|
|
41
|
+
verifyUserOrganizationWriteAuthorized,
|
|
42
|
+
registeredCredentialTypesPreHandler,
|
|
43
|
+
],
|
|
44
|
+
schema: fastify.autoSchema({
|
|
45
|
+
security: [
|
|
46
|
+
{
|
|
47
|
+
RegistrarOAuth2: [
|
|
48
|
+
RegistrarScopes.WriteOrganizations,
|
|
49
|
+
RegistrarScopes.AdminOrganizations,
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
body: addInvitationBodySchema,
|
|
54
|
+
response: {
|
|
55
|
+
200: {
|
|
56
|
+
type: 'object',
|
|
57
|
+
properties: {
|
|
58
|
+
invitation: invitationResponseItemBodySchema,
|
|
59
|
+
messageCode: { type: 'string' },
|
|
60
|
+
},
|
|
61
|
+
required: ['invitation'],
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
}),
|
|
65
|
+
},
|
|
66
|
+
async (req) => {
|
|
67
|
+
const {
|
|
68
|
+
params: { did },
|
|
69
|
+
body,
|
|
70
|
+
repos,
|
|
71
|
+
config: { registrarInvitationTtl },
|
|
72
|
+
user,
|
|
73
|
+
} = req;
|
|
74
|
+
const { inviteeEmail, inviteeService, inviteeProfile, keyIndividuals } =
|
|
75
|
+
body;
|
|
76
|
+
|
|
77
|
+
// validate inviter
|
|
78
|
+
const inviterOrganization = await repos.organizations.findOneByDid(did);
|
|
79
|
+
const caoService = find(isCaoService, inviterOrganization.services);
|
|
80
|
+
if (isEmpty(caoService)) {
|
|
81
|
+
throw newError(400, 'CAO service does not exist', {
|
|
82
|
+
errorCode: 'invitations_not_supported',
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// validate invitation details
|
|
87
|
+
validateInviteeEmail(inviteeEmail);
|
|
88
|
+
|
|
89
|
+
const caoServiceRefs = await buildReferenceCaoServices({
|
|
90
|
+
caoServiceIds: extractCaoServiceRefs(inviteeService),
|
|
91
|
+
caoOrganizations: [inviterOrganization],
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
forEach(
|
|
95
|
+
(service) => validateInviteeService(service, caoServiceRefs, req),
|
|
96
|
+
inviteeService
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
// create auth0 user
|
|
100
|
+
const { ticket } = await getOrCreateAuth0User(
|
|
101
|
+
inviteeEmail,
|
|
102
|
+
keyIndividuals.adminGivenName,
|
|
103
|
+
keyIndividuals.adminFamilyName,
|
|
104
|
+
req
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
// send invitation to user
|
|
108
|
+
const code = nanoid(16);
|
|
109
|
+
const expiresAt = addSeconds(registrarInvitationTtl, new Date());
|
|
110
|
+
const invitation = await repos.invitations.insert({
|
|
111
|
+
invitationUrl: buildInvitationUrl({ code }, req),
|
|
112
|
+
inviterDid: did,
|
|
113
|
+
inviteeEmail,
|
|
114
|
+
inviteeService,
|
|
115
|
+
inviteeProfile,
|
|
116
|
+
keyIndividuals,
|
|
117
|
+
code,
|
|
118
|
+
expiresAt,
|
|
119
|
+
createdBy: user.sub,
|
|
120
|
+
updatedBy: user.sub,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const messageCode = await sendEmailToInvitee(
|
|
124
|
+
{
|
|
125
|
+
inviteeEmail,
|
|
126
|
+
inviterOrganization,
|
|
127
|
+
ticket,
|
|
128
|
+
code,
|
|
129
|
+
},
|
|
130
|
+
req
|
|
131
|
+
);
|
|
132
|
+
return {
|
|
133
|
+
invitation,
|
|
134
|
+
messageCode,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
fastify.get(
|
|
140
|
+
'/',
|
|
141
|
+
{
|
|
142
|
+
onRequest: fastify.verifyAccessToken([
|
|
143
|
+
RegistrarScopes.ReadOrganizations,
|
|
144
|
+
RegistrarScopes.AdminOrganizations,
|
|
145
|
+
]),
|
|
146
|
+
preHandler: [verifyUserOrganizationWriteAuthorized],
|
|
147
|
+
schema: fastify.autoSchema({
|
|
148
|
+
security: [
|
|
149
|
+
{
|
|
150
|
+
RegistrarOAuth2: [
|
|
151
|
+
RegistrarScopes.ReadOrganizations,
|
|
152
|
+
RegistrarScopes.AdminOrganizations,
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
querystring: {
|
|
157
|
+
$ref: 'https://velocitynetwork.foundation/schemas/page-query.schema.json#',
|
|
158
|
+
},
|
|
159
|
+
response: {
|
|
160
|
+
200: {
|
|
161
|
+
type: 'object',
|
|
162
|
+
properties: {
|
|
163
|
+
invitations: {
|
|
164
|
+
type: 'array',
|
|
165
|
+
items: {
|
|
166
|
+
type: 'object',
|
|
167
|
+
properties: invitationResponseItemBodySchema.properties,
|
|
168
|
+
required: invitationResponseItemBodySchema.required,
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
required: ['invitations'],
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
}),
|
|
176
|
+
},
|
|
177
|
+
async (req) => {
|
|
178
|
+
const {
|
|
179
|
+
params: { did },
|
|
180
|
+
query: { page, sort = [] },
|
|
181
|
+
repos,
|
|
182
|
+
} = req;
|
|
183
|
+
await repos.organizations.findOneByDid(did, { _id: 1 });
|
|
184
|
+
const filter = transformToFinder({
|
|
185
|
+
filter: { inviterDid: did },
|
|
186
|
+
page,
|
|
187
|
+
sort,
|
|
188
|
+
});
|
|
189
|
+
const invitations = await repos.invitations.find(filter);
|
|
190
|
+
return {
|
|
191
|
+
invitations,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
);
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
module.exports = invitationsController;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Velocity Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
const {
|
|
18
|
+
verifyUserOrganizationWriteAuthorized,
|
|
19
|
+
verifyUserOrganizationReadAuthorized,
|
|
20
|
+
} = require('../../../../plugins/authorization');
|
|
21
|
+
const {
|
|
22
|
+
addKey,
|
|
23
|
+
deleteKey,
|
|
24
|
+
getKey,
|
|
25
|
+
RegistrarScopes,
|
|
26
|
+
} = require('../../../../entities');
|
|
27
|
+
|
|
28
|
+
const keysController = async (fastify) => {
|
|
29
|
+
fastify
|
|
30
|
+
.post(
|
|
31
|
+
'/',
|
|
32
|
+
{
|
|
33
|
+
onRequest: fastify.verifyAccessToken([
|
|
34
|
+
RegistrarScopes.AdminOrganizations,
|
|
35
|
+
RegistrarScopes.WriteOrganizations,
|
|
36
|
+
]),
|
|
37
|
+
preHandler: [verifyUserOrganizationWriteAuthorized],
|
|
38
|
+
schema: fastify.autoSchema({
|
|
39
|
+
security: [
|
|
40
|
+
{
|
|
41
|
+
RegistrarOAuth2: [
|
|
42
|
+
RegistrarScopes.WriteOrganizations,
|
|
43
|
+
RegistrarScopes.AdminOrganizations,
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
body: { $ref: 'https://velocitycareerlabs.io/add-key-body.json#' },
|
|
48
|
+
response: {
|
|
49
|
+
201: {
|
|
50
|
+
type: 'object',
|
|
51
|
+
properties: {
|
|
52
|
+
key: {
|
|
53
|
+
$ref: 'did-key#',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
required: ['key'],
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
}),
|
|
60
|
+
},
|
|
61
|
+
async (req, reply) => {
|
|
62
|
+
const response = await addKey(req.params.did, req.body, req);
|
|
63
|
+
reply.code(201);
|
|
64
|
+
return response;
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
.get(
|
|
68
|
+
'/:kid',
|
|
69
|
+
{
|
|
70
|
+
onRequest: fastify.verifyAccessToken([
|
|
71
|
+
RegistrarScopes.AdminOrganizations,
|
|
72
|
+
RegistrarScopes.ReadOrganizations,
|
|
73
|
+
]),
|
|
74
|
+
preHandler: [verifyUserOrganizationReadAuthorized],
|
|
75
|
+
schema: fastify.autoSchema({
|
|
76
|
+
security: [
|
|
77
|
+
{
|
|
78
|
+
RegistrarOAuth2: [
|
|
79
|
+
RegistrarScopes.ReadOrganizations,
|
|
80
|
+
RegistrarScopes.AdminOrganizations,
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
response: {
|
|
85
|
+
200: {
|
|
86
|
+
type: 'object',
|
|
87
|
+
properties: {
|
|
88
|
+
key: {
|
|
89
|
+
$ref: 'did-key#',
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
required: ['key'],
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
}),
|
|
96
|
+
},
|
|
97
|
+
async (req) => {
|
|
98
|
+
const { params } = req;
|
|
99
|
+
return getKey(params.did, params.kid, req);
|
|
100
|
+
}
|
|
101
|
+
)
|
|
102
|
+
.delete(
|
|
103
|
+
'/:keyId',
|
|
104
|
+
{
|
|
105
|
+
onRequest: fastify.verifyAccessToken([
|
|
106
|
+
RegistrarScopes.AdminOrganizations,
|
|
107
|
+
RegistrarScopes.WriteOrganizations,
|
|
108
|
+
]),
|
|
109
|
+
preHandler: [verifyUserOrganizationWriteAuthorized],
|
|
110
|
+
schema: fastify.autoSchema({
|
|
111
|
+
security: [
|
|
112
|
+
{
|
|
113
|
+
RegistrarOAuth2: [
|
|
114
|
+
RegistrarScopes.WriteOrganizations,
|
|
115
|
+
RegistrarScopes.AdminOrganizations,
|
|
116
|
+
],
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
params: {
|
|
120
|
+
type: 'object',
|
|
121
|
+
properties: {
|
|
122
|
+
keyId: { type: 'string' },
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
response: {
|
|
126
|
+
204: {
|
|
127
|
+
type: 'null',
|
|
128
|
+
},
|
|
129
|
+
...fastify.BadRequestResponse,
|
|
130
|
+
},
|
|
131
|
+
}),
|
|
132
|
+
},
|
|
133
|
+
async (req, reply) => {
|
|
134
|
+
await deleteKey(req.params.did, req.params.keyId, req);
|
|
135
|
+
reply.code(204);
|
|
136
|
+
return {};
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
module.exports = keysController;
|