@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.
Files changed (259) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +1 -0
  3. package/README.md +3 -0
  4. package/package.json +86 -0
  5. package/src/config/abi.json +1 -0
  6. package/src/config/config.js +261 -0
  7. package/src/controllers/consents/autohooks.js +6 -0
  8. package/src/controllers/consents/controller.js +106 -0
  9. package/src/controllers/consents/schemas/consent-response.schema.js +45 -0
  10. package/src/controllers/did-web-host/controller.js +64 -0
  11. package/src/controllers/groups/autohooks.js +10 -0
  12. package/src/controllers/groups/controller.js +172 -0
  13. package/src/controllers/groups/schemas/group.schema.json +22 -0
  14. package/src/controllers/groups/schemas/index.js +7 -0
  15. package/src/controllers/groups/schemas/modify-group.schema.json +25 -0
  16. package/src/controllers/image_upload/controller.js +48 -0
  17. package/src/controllers/invitations/controller.js +79 -0
  18. package/src/controllers/organizations/_did/autohooks.js +16 -0
  19. package/src/controllers/organizations/_did/controller.js +617 -0
  20. package/src/controllers/organizations/_did/invitations/_invitationId/autohooks.js +16 -0
  21. package/src/controllers/organizations/_did/invitations/_invitationId/controller.js +217 -0
  22. package/src/controllers/organizations/_did/invitations/controller.js +197 -0
  23. package/src/controllers/organizations/_did/keys/controller.js +141 -0
  24. package/src/controllers/organizations/_did/services/controller.js +195 -0
  25. package/src/controllers/organizations/_did/signatories/controller.js +63 -0
  26. package/src/controllers/organizations/autohooks.js +65 -0
  27. package/src/controllers/organizations/controller.js +322 -0
  28. package/src/controllers/organizations/full/controller.js +285 -0
  29. package/src/controllers/organizations/plugins.js +21 -0
  30. package/src/controllers/organizations/schemas/add-key-body.schema.json +35 -0
  31. package/src/controllers/organizations/schemas/create-did-service.schema.json +70 -0
  32. package/src/controllers/organizations/schemas/did-key.schema.json +178 -0
  33. package/src/controllers/organizations/schemas/full-organization.schema.json +35 -0
  34. package/src/controllers/organizations/schemas/index.js +33 -0
  35. package/src/controllers/organizations/schemas/invitationCodeProperty.schema.json +3 -0
  36. package/src/controllers/organizations/schemas/organization-ids.schema.json +34 -0
  37. package/src/controllers/organizations/schemas/organization-kyb-profile-creation.schema.json +26 -0
  38. package/src/controllers/organizations/schemas/organization-profile-creation.schema.json +20 -0
  39. package/src/controllers/organizations/schemas/organization-profile-update.schema.json +19 -0
  40. package/src/controllers/organizations/schemas/organization-profile-verifiable-credential.schema.json +25 -0
  41. package/src/controllers/organizations/schemas/organization-registry-service-response.schema.json +26 -0
  42. package/src/controllers/organizations/schemas/organization-service.schema.json +34 -0
  43. package/src/controllers/organizations/schemas/organization-verified-profile.schema.json +123 -0
  44. package/src/controllers/organizations/schemas/organization.search-profile.query-params.schema.json +50 -0
  45. package/src/controllers/organizations/schemas/organization.search.query-params.schema.json +42 -0
  46. package/src/controllers/reference/controller.js +103 -0
  47. package/src/controllers/resolve-did/controller.js +45 -0
  48. package/src/controllers/resolve-did/resolve-did.js +30 -0
  49. package/src/controllers/resolve-did/schemas/did-doc.schema.json +155 -0
  50. package/src/controllers/resolve-did/schemas/did-proof.schema.json +44 -0
  51. package/src/controllers/resolve-did/schemas/index.js +26 -0
  52. package/src/controllers/resolve-did/schemas/public-key.schema.json +173 -0
  53. package/src/controllers/resolve-kid/controller.js +76 -0
  54. package/src/controllers/resolve-kid/public-key-formats.js +8 -0
  55. package/src/controllers/service-types/controller.js +81 -0
  56. package/src/controllers/setup_image_upload/controller.js +99 -0
  57. package/src/controllers/signatories/controller.js +43 -0
  58. package/src/controllers/users/autohooks.js +10 -0
  59. package/src/controllers/users/controller.js +221 -0
  60. package/src/controllers/users/schemas/base-user.schema.json +55 -0
  61. package/src/controllers/users/schemas/index.js +4 -0
  62. package/src/controllers/users/schemas/modify-user.schema.js +17 -0
  63. package/src/controllers/users/schemas/user.schema.js +20 -0
  64. package/src/entities/groups/domain/constants.js +21 -0
  65. package/src/entities/groups/domain/index.js +19 -0
  66. package/src/entities/groups/factories/groups-factory.js +48 -0
  67. package/src/entities/groups/factories/index.js +17 -0
  68. package/src/entities/groups/index.js +19 -0
  69. package/src/entities/groups/repo.js +122 -0
  70. package/src/entities/images/domain/constant.js +11 -0
  71. package/src/entities/images/domain/index.js +3 -0
  72. package/src/entities/images/extension/activate.extension.js +35 -0
  73. package/src/entities/images/extension/deactivate.extension.js +27 -0
  74. package/src/entities/images/extension/find-by-url.extension.js +24 -0
  75. package/src/entities/images/extension/index.js +5 -0
  76. package/src/entities/images/factories/images-factory.js +43 -0
  77. package/src/entities/images/factories/index.js +17 -0
  78. package/src/entities/images/index.js +5 -0
  79. package/src/entities/images/repo.js +43 -0
  80. package/src/entities/images/schema/image-metadata.schema.js +58 -0
  81. package/src/entities/images/schema/index.js +3 -0
  82. package/src/entities/index.js +31 -0
  83. package/src/entities/invitations/domains/build-invitation-url.js +14 -0
  84. package/src/entities/invitations/domains/get-given-family-name-from-name.js +20 -0
  85. package/src/entities/invitations/domains/index.js +7 -0
  86. package/src/entities/invitations/domains/init-invitation-emails.js +17 -0
  87. package/src/entities/invitations/domains/is-invitation-expired.js +5 -0
  88. package/src/entities/invitations/domains/validate-invitee-email.js +18 -0
  89. package/src/entities/invitations/factories/index.js +17 -0
  90. package/src/entities/invitations/factories/invitations-factory.js +51 -0
  91. package/src/entities/invitations/index.js +6 -0
  92. package/src/entities/invitations/orchestrators/accept-invitation.js +24 -0
  93. package/src/entities/invitations/orchestrators/index.js +4 -0
  94. package/src/entities/invitations/orchestrators/send-email-invitee.js +36 -0
  95. package/src/entities/invitations/repo.js +37 -0
  96. package/src/entities/invitations/schemas/add-invitation-body.js +122 -0
  97. package/src/entities/invitations/schemas/get-invitation-response-body.js +20 -0
  98. package/src/entities/invitations/schemas/index.js +5 -0
  99. package/src/entities/invitations/schemas/invitation-response-item-body.js +61 -0
  100. package/src/entities/kms/factories/index.js +17 -0
  101. package/src/entities/kms/factories/kms-factory.js +31 -0
  102. package/src/entities/monitors/index.js +17 -0
  103. package/src/entities/monitors/orchestrators/index.js +17 -0
  104. package/src/entities/monitors/orchestrators/monitors.js +230 -0
  105. package/src/entities/oauth/domain/constants.js +23 -0
  106. package/src/entities/oauth/domain/index.js +5 -0
  107. package/src/entities/oauth/domain/roles.js +92 -0
  108. package/src/entities/oauth/domain/scopes.js +35 -0
  109. package/src/entities/oauth/index.js +4 -0
  110. package/src/entities/oauth/orchestrators/auth0-provisioner.js +293 -0
  111. package/src/entities/oauth/orchestrators/index.js +3 -0
  112. package/src/entities/organization-keys/domains/build-organization-key.js +50 -0
  113. package/src/entities/organization-keys/domains/constants.js +30 -0
  114. package/src/entities/organization-keys/domains/extract-verification-method-from-byo-did-document.js +38 -0
  115. package/src/entities/organization-keys/domains/find-key-by-purpose.js +6 -0
  116. package/src/entities/organization-keys/domains/index.js +10 -0
  117. package/src/entities/organization-keys/domains/jwk-to-hex-key-transformer.js +13 -0
  118. package/src/entities/organization-keys/domains/map-key-response.js +29 -0
  119. package/src/entities/organization-keys/domains/validate-non-custodial-key.js +11 -0
  120. package/src/entities/organization-keys/domains/validate-organization-key.js +42 -0
  121. package/src/entities/organization-keys/factories/index.js +17 -0
  122. package/src/entities/organization-keys/factories/organization-keys-factory.js +55 -0
  123. package/src/entities/organization-keys/index.js +5 -0
  124. package/src/entities/organization-keys/orchestrators/add-key-to-did-doc.js +19 -0
  125. package/src/entities/organization-keys/orchestrators/add-key.js +155 -0
  126. package/src/entities/organization-keys/orchestrators/add-operator-keys.js +46 -0
  127. package/src/entities/organization-keys/orchestrators/delete-key.js +93 -0
  128. package/src/entities/organization-keys/orchestrators/get-key.js +39 -0
  129. package/src/entities/organization-keys/orchestrators/index.js +24 -0
  130. package/src/entities/organization-keys/orchestrators/resolve-verification-method-byo-did.js +28 -0
  131. package/src/entities/organization-keys/repos/repo.js +48 -0
  132. package/src/entities/organization-services/adapters/index.js +21 -0
  133. package/src/entities/organization-services/adapters/init-provision-auth0-client-grants.js +44 -0
  134. package/src/entities/organization-services/adapters/init-provision-auth0-clients.js +56 -0
  135. package/src/entities/organization-services/adapters/update-blockchain-permissions-from-permitted-services.js +118 -0
  136. package/src/entities/organization-services/domains/activate-services.js +12 -0
  137. package/src/entities/organization-services/domains/build-organizations-services.js +38 -0
  138. package/src/entities/organization-services/domains/build-public-services.js +19 -0
  139. package/src/entities/organization-services/domains/constants.js +32 -0
  140. package/src/entities/organization-services/domains/extract-cao-service-refs.js +10 -0
  141. package/src/entities/organization-services/domains/extract-service-endpoint-did.js +10 -0
  142. package/src/entities/organization-services/domains/get-service-consent-type.js +16 -0
  143. package/src/entities/organization-services/domains/get-service-types-from-categories.js +18 -0
  144. package/src/entities/organization-services/domains/index.js +17 -0
  145. package/src/entities/organization-services/domains/is-new-node-operator-service.js +25 -0
  146. package/src/entities/organization-services/domains/is-service-category.js +31 -0
  147. package/src/entities/organization-services/domains/normalize-service-endpoint.js +6 -0
  148. package/src/entities/organization-services/domains/select-activated-services.js +8 -0
  149. package/src/entities/organization-services/domains/transform-profile-service.js +88 -0
  150. package/src/entities/organization-services/domains/validate-cao-service-refs.js +25 -0
  151. package/src/entities/organization-services/domains/validate-service-credential-type.js +47 -0
  152. package/src/entities/organization-services/domains/validate-service-endpoint.js +35 -0
  153. package/src/entities/organization-services/domains/validate-service-fields-by-service-type.js +37 -0
  154. package/src/entities/organization-services/domains/validate-service-id-uniqueness.js +19 -0
  155. package/src/entities/organization-services/domains/validate-service-key-purposes.js +56 -0
  156. package/src/entities/organization-services/domains/validate-service-type.js +12 -0
  157. package/src/entities/organization-services/domains/validate-service.js +80 -0
  158. package/src/entities/organization-services/domains/validate-services-for-delete.js +32 -0
  159. package/src/entities/organization-services/index.js +5 -0
  160. package/src/entities/organization-services/orchestrators/add-service.js +106 -0
  161. package/src/entities/organization-services/orchestrators/delete-service.js +142 -0
  162. package/src/entities/organization-services/orchestrators/get-service.js +36 -0
  163. package/src/entities/organization-services/orchestrators/index.js +8 -0
  164. package/src/entities/organization-services/orchestrators/init-add-service-to-organization.js +141 -0
  165. package/src/entities/organization-services/orchestrators/load-cao-service-refs.js +56 -0
  166. package/src/entities/organization-services/orchestrators/update-service.js +103 -0
  167. package/src/entities/organizations/adapters/index.js +6 -0
  168. package/src/entities/organizations/adapters/init-organization-registrar-emails.js +215 -0
  169. package/src/entities/organizations/adapters/init-send-activation-emails-to-caos.js +89 -0
  170. package/src/entities/organizations/adapters/send-email-invitation-accepted-to-inviter.js +70 -0
  171. package/src/entities/organizations/adapters/send-email-notifications.js +212 -0
  172. package/src/entities/organizations/domains/build-custodied-did-web.js +12 -0
  173. package/src/entities/organizations/domains/build-full-organization-response.js +40 -0
  174. package/src/entities/organizations/domains/build-organization-modifications-on-service-change.js +82 -0
  175. package/src/entities/organizations/domains/build-profile-vc-url.js +8 -0
  176. package/src/entities/organizations/domains/build-profile-verifiable-credential.js +36 -0
  177. package/src/entities/organizations/domains/build-public-profile.js +9 -0
  178. package/src/entities/organizations/domains/constants.js +54 -0
  179. package/src/entities/organizations/domains/index.js +17 -0
  180. package/src/entities/organizations/domains/organization-vc-checks.js +49 -0
  181. package/src/entities/organizations/domains/parse-profile-to-csv.js +41 -0
  182. package/src/entities/organizations/domains/prepare-profile-vc.js +28 -0
  183. package/src/entities/organizations/domains/profile-name-normalization.js +5 -0
  184. package/src/entities/organizations/domains/validate-byo-did-keys.js +28 -0
  185. package/src/entities/organizations/domains/validate-profile-name.js +48 -0
  186. package/src/entities/organizations/domains/validate-profile-website.js +17 -0
  187. package/src/entities/organizations/domains/validate-update-profile.js +11 -0
  188. package/src/entities/organizations/factories/index.js +17 -0
  189. package/src/entities/organizations/factories/organizations-factory.js +180 -0
  190. package/src/entities/organizations/index.js +6 -0
  191. package/src/entities/organizations/orchestrators/add-primary-permissions.js +28 -0
  192. package/src/entities/organizations/orchestrators/build-custodied-organization.js +92 -0
  193. package/src/entities/organizations/orchestrators/build-non-custodied-organization.js +83 -0
  194. package/src/entities/organizations/orchestrators/index.js +6 -0
  195. package/src/entities/organizations/orchestrators/init-create-organization.js +221 -0
  196. package/src/entities/organizations/orchestrators/init-provision-group.js +48 -0
  197. package/src/entities/organizations/orchestrators/verify-profile-website-unique.js +15 -0
  198. package/src/entities/organizations/repos/find-caos-extension.js +49 -0
  199. package/src/entities/organizations/repos/index.js +17 -0
  200. package/src/entities/organizations/repos/repo.js +156 -0
  201. package/src/entities/organizations/repos/search-by-aggregation-extension.js +128 -0
  202. package/src/entities/organizations/repos/transform-did-filter.js +13 -0
  203. package/src/entities/organizations/repos/transform-organization-filter.js +106 -0
  204. package/src/entities/registrar-consents/constants.js +10 -0
  205. package/src/entities/registrar-consents/factories/index.js +17 -0
  206. package/src/entities/registrar-consents/factories/registrar-consents-factory.js +38 -0
  207. package/src/entities/registrar-consents/index.js +3 -0
  208. package/src/entities/registrar-consents/repos/registrar-consent-repo-extension.js +55 -0
  209. package/src/entities/registrar-consents/repos/repo.js +31 -0
  210. package/src/entities/signatories/domain/constants.js +12 -0
  211. package/src/entities/signatories/domain/index.js +4 -0
  212. package/src/entities/signatories/domain/organization-emails.js +29 -0
  213. package/src/entities/signatories/factories/index.js +17 -0
  214. package/src/entities/signatories/factories/signatory-status-factory.js +53 -0
  215. package/src/entities/signatories/index.js +5 -0
  216. package/src/entities/signatories/orchestrators/approve-reminder.js +24 -0
  217. package/src/entities/signatories/orchestrators/index.js +6 -0
  218. package/src/entities/signatories/orchestrators/reject-reminder.js +17 -0
  219. package/src/entities/signatories/orchestrators/send-reminders.js +102 -0
  220. package/src/entities/signatories/orchestrators/validate-auth-code.js +56 -0
  221. package/src/entities/signatories/repos/index.js +3 -0
  222. package/src/entities/signatories/repos/repo.js +35 -0
  223. package/src/entities/signatories/repos/signatory-status-state-repo-extension.js +124 -0
  224. package/src/entities/users/domains/constants.js +40 -0
  225. package/src/entities/users/domains/index.js +4 -0
  226. package/src/entities/users/domains/user-registrar-emails.js +52 -0
  227. package/src/entities/users/index.js +4 -0
  228. package/src/entities/users/orchestrators/create-auth0-user.js +60 -0
  229. package/src/entities/users/orchestrators/get-or-create-auth0-user.js +63 -0
  230. package/src/entities/users/orchestrators/index.js +22 -0
  231. package/src/entities/users/orchestrators/user-management.js +157 -0
  232. package/src/fetchers/index.js +19 -0
  233. package/src/fetchers/monitoring/index.js +9 -0
  234. package/src/fetchers/monitoring/monitor-add-to-page-fetcher.js +18 -0
  235. package/src/fetchers/monitoring/monitor-create-fetcher.js +23 -0
  236. package/src/fetchers/monitoring/monitor-delete-fetcher.js +6 -0
  237. package/src/fetchers/monitoring/monitor-get-all-fetcher.js +6 -0
  238. package/src/fetchers/monitoring/section-create-fetcher.js +16 -0
  239. package/src/fetchers/monitoring/section-get-all-fetcher.js +6 -0
  240. package/src/fetchers/monitoring/service-version-fetcher.js +6 -0
  241. package/src/helpers/init-permissions-contract.js +48 -0
  242. package/src/index.js +23 -0
  243. package/src/init-server.js +91 -0
  244. package/src/organizations-registrar-endpoints.js +68 -0
  245. package/src/plugins/authorization.js +233 -0
  246. package/src/plugins/index.js +4 -0
  247. package/src/plugins/pubsub-plugin.js +82 -0
  248. package/src/subscribers/notify-caos.js +63 -0
  249. package/src/subscribers/notify-inviters.js +42 -0
  250. package/src/subscribers/notify-monitoring.js +40 -0
  251. package/src/subscribers/notify-signatory.js +51 -0
  252. package/src/subscribers/notify-support-and-groups.js +95 -0
  253. package/src/templates/invitee-invitation-email-body.hbs +13 -0
  254. package/src/templates/invitee-invitation-email-subject.hbs +1 -0
  255. package/src/templates/signatory-approval-email-body.hbs +92 -0
  256. package/src/templates/support-organization-created-body.hbs +17 -0
  257. package/src/templates/support-organization-created-subject.hbs +1 -0
  258. package/src/templates/support-signatory-max-reminders-reached-email-body.hbs +6 -0
  259. package/src/templates/support-signatory-max-reminders-reached-email-subject.hbs +1 -0
@@ -0,0 +1,23 @@
1
+ const createMonitor = async (
2
+ { monitorType, url, pronounceableName, requiredKeyword },
3
+ { betterUptimeFetch }
4
+ ) => {
5
+ const payload = {
6
+ monitor_type: monitorType,
7
+ url,
8
+ pronounceable_name: pronounceableName,
9
+ email: true,
10
+ sms: true,
11
+ call: false,
12
+ check_frequency: 5,
13
+ };
14
+ if (requiredKeyword) {
15
+ payload.required_keyword = requiredKeyword;
16
+ }
17
+
18
+ return betterUptimeFetch.post('monitors', { json: payload }).json();
19
+ };
20
+
21
+ module.exports = {
22
+ createMonitor,
23
+ };
@@ -0,0 +1,6 @@
1
+ const deleteMonitor = async ({ monitorId }, { betterUptimeFetch }) =>
2
+ betterUptimeFetch.delete(`monitors/${monitorId}`);
3
+
4
+ module.exports = {
5
+ deleteMonitor,
6
+ };
@@ -0,0 +1,6 @@
1
+ const getAllMonitors = async ({ betterUptimeFetch }) =>
2
+ betterUptimeFetch.get('monitors').json();
3
+
4
+ module.exports = {
5
+ getAllMonitors,
6
+ };
@@ -0,0 +1,16 @@
1
+ const createSection = async (
2
+ { orgName, statusPageId },
3
+ { betterUptimeFetch }
4
+ ) => {
5
+ const payload = {
6
+ name: orgName,
7
+ position: 0,
8
+ };
9
+ return betterUptimeFetch
10
+ .post(`status-pages/${statusPageId}/sections`, { json: payload })
11
+ .json();
12
+ };
13
+
14
+ module.exports = {
15
+ createSection,
16
+ };
@@ -0,0 +1,6 @@
1
+ const getAllSections = async (statusPageId, { betterUptimeFetch }) =>
2
+ betterUptimeFetch.get(`status-pages/${statusPageId}/sections`).json();
3
+
4
+ module.exports = {
5
+ getAllSections,
6
+ };
@@ -0,0 +1,6 @@
1
+ const serviceVersion = async (url, { serviceVersionFetch }) =>
2
+ serviceVersionFetch.get(url);
3
+
4
+ module.exports = {
5
+ serviceVersion,
6
+ };
@@ -0,0 +1,48 @@
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 { initPermissions } = require('@verii/contract-permissions');
18
+ const { hexFromJwk } = require('@verii/jwt');
19
+ const { ObjectId } = require('mongodb');
20
+ const { KeyPurposes } = require('@verii/crypto');
21
+
22
+ const initPermissionsContract = async (organization, context) => {
23
+ const { repos } = context;
24
+ const permissionsKey = await repos.organizationKeys.findOne({
25
+ filter: {
26
+ organizationId: new ObjectId(organization._id),
27
+ purposes: KeyPurposes.PERMISSIONING,
28
+ },
29
+ });
30
+ return initPermissionsContractByKeyId(permissionsKey.kmsKeyId, context);
31
+ };
32
+
33
+ const initPermissionsContractByKeyId = async (keyId, context) => {
34
+ const { config, rpcProvider, withKmsKey } = context;
35
+
36
+ return withKmsKey(keyId, ({ privateJwk }) =>
37
+ initPermissions(
38
+ {
39
+ privateKey: hexFromJwk(privateJwk, true),
40
+ contractAddress: config.permissionsContractAddress,
41
+ rpcProvider,
42
+ },
43
+ context
44
+ )
45
+ );
46
+ };
47
+
48
+ module.exports = { initPermissionsContractByKeyId, initPermissionsContract };
package/src/index.js ADDED
@@ -0,0 +1,23 @@
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
+ module.exports = {
18
+ ...require('./entities'),
19
+ ...require('./config/config'),
20
+ ...require('./fetchers'),
21
+ ...require('./plugins'),
22
+ ...require('./organizations-registrar-endpoints'),
23
+ };
@@ -0,0 +1,91 @@
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
+
18
+ const { validationPlugin } = require('@verii/validation');
19
+ const { corsPlugin, requestPlugin } = require('@verii/fastify-plugins');
20
+ const { sendEmailPlugin } = require('@verii/aws-clients');
21
+ const {
22
+ authenticateVnfClientPlugin,
23
+ rpcProviderPlugin,
24
+ } = require('@verii/base-contract-io');
25
+ const { oauthPlugin } = require('@verii/auth');
26
+ const credentialTypesRepoPlugin = require('@verii/endpoints-credential-types-registrar/src/entities/credential-types/repos/repo');
27
+ const {
28
+ organizationRegistrarEndpoints,
29
+ } = require('./organizations-registrar-endpoints');
30
+
31
+ const initServer = (server) => {
32
+ if (!server.config.isTest) {
33
+ server
34
+ .register(oauthPlugin, {
35
+ domain: server.config.auth0Domain,
36
+ audience: [
37
+ server.config.registrarApiAudience,
38
+ server.config.oauthAudienceTokenApi,
39
+ ],
40
+ })
41
+ .register(authenticateVnfClientPlugin);
42
+ }
43
+
44
+ return server
45
+ .register(rpcProviderPlugin)
46
+ .register(corsPlugin, {
47
+ wildcardRoutes: ['/api/v0.6/organizations/search-profiles'],
48
+ })
49
+ .register(sendEmailPlugin)
50
+ .register(validationPlugin, {
51
+ ajv: server.config.validationPluginAjvOptions,
52
+ })
53
+ .addHook('preValidation', async (req) => {
54
+ req.getDocValidator = server.getDocValidator;
55
+ })
56
+ .register(requestPlugin, {
57
+ name: 'fineractFetch',
58
+ options: {
59
+ ...server.config,
60
+ clientId: server.config.auth0ClientId,
61
+ clientSecret: server.config.auth0ClientSecret,
62
+ tokensEndpoint: server.config.vnfOAuthTokensEndpoint,
63
+ audience: server.config.oauthAudienceFineractApi,
64
+ scopes: server.config.oauthScopesFineractApi,
65
+ prefixUrl: server.config.fineractUrl,
66
+ customHeaders: {
67
+ 'fineract-platform-tenantid': 'default',
68
+ },
69
+ },
70
+ })
71
+ .register(requestPlugin, {
72
+ name: 'betterUptimeFetch',
73
+ options: {
74
+ ...server.config,
75
+ requestTimeout: server.config.requestTimeoutBetterUptimeFetch,
76
+ bearerToken: server.config.monitoringApiToken,
77
+ prefixUrl: server.config.monitoringApiBaseUrl,
78
+ },
79
+ })
80
+ .register(requestPlugin, {
81
+ name: 'serviceVersionFetch',
82
+ options: {
83
+ ...server.config,
84
+ requestTimeout: server.config.requestTimeoutBetterUptimeFetch,
85
+ },
86
+ })
87
+ .register(credentialTypesRepoPlugin)
88
+ .register(organizationRegistrarEndpoints);
89
+ };
90
+
91
+ module.exports = { initServer };
@@ -0,0 +1,68 @@
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 AutoLoad = require('@fastify/autoload');
18
+ const fp = require('fastify-plugin');
19
+ const path = require('path');
20
+ const fastifyView = require('@fastify/view');
21
+ const handlebars = require('handlebars');
22
+ const { pubsubPlugin } = require('./plugins/pubsub-plugin');
23
+
24
+ const organizationRegistrarEndpoints = async (fastify) =>
25
+ fastify
26
+ .register(AutoLoad, {
27
+ dir: path.join(__dirname, 'entities'),
28
+ indexPattern: /.*repo(\.ts|\.js|\.cjs|\.mjs)$/,
29
+ scriptPattern: /.*repo(\.ts|\.js|\.cjs|\.mjs)$/,
30
+ })
31
+ .register(AutoLoad, {
32
+ dir: path.join(__dirname, 'controllers'),
33
+ indexPattern: /^.*controller(\.ts|\.js|\.cjs|\.mjs)$/,
34
+ scriptPattern: /.*controller(\.ts|\.js|\.cjs|\.mjs)$/,
35
+ routeParams: true,
36
+ autoHooks: true,
37
+ cascadeHooks: true,
38
+ options: { prefix: '/api/v0.6' },
39
+ })
40
+ .register(pubsubPlugin)
41
+ .register(AutoLoad, {
42
+ dir: path.join(__dirname, 'subscribers'),
43
+ })
44
+ .register(fastifyView, {
45
+ engine: {
46
+ handlebars,
47
+ },
48
+ root: path.join(__dirname, 'templates'),
49
+ includeViewExtension: true,
50
+ })
51
+ .addHook('preHandler', async (req) => {
52
+ req.sendSupportEmail = (subject, message) =>
53
+ fastify.sendEmail({
54
+ subject,
55
+ message,
56
+ sender: fastify.config.registrarSupportEmail,
57
+ recipients: [fastify.config.registrarSupportEmail],
58
+ replyTo: fastify.config.registrarSupportEmail,
59
+ html: true,
60
+ });
61
+ })
62
+ .addHook('preHandler', async (req) => {
63
+ req.renderTemplate = fastify.view;
64
+ });
65
+
66
+ module.exports = {
67
+ organizationRegistrarEndpoints: fp(organizationRegistrarEndpoints),
68
+ };
@@ -0,0 +1,233 @@
1
+ const { includes } = require('lodash/fp');
2
+ const newError = require('http-errors');
3
+ const {
4
+ RegistrarScopes,
5
+ GroupErrorMessages,
6
+ UserErrorMessages,
7
+ VNF_GROUP_ID_CLAIM,
8
+ hasAdminOrganizationScope,
9
+ hasWriteOrganizationScope,
10
+ hasReadOrganizationScope,
11
+ hasAdminUsersScope,
12
+ hasReadUsersScope,
13
+ hasWriteUsersScope,
14
+ } = require('../entities');
15
+
16
+ // eslint-disable-next-line complexity
17
+ const verifyUserOrganizationWriteAuthorized = async (ctx) => {
18
+ const { method, params, user } = ctx;
19
+ if (hasAdminOrganizationScope(user)) {
20
+ return true;
21
+ }
22
+ if (!hasWriteOrganizationScope(user)) {
23
+ throw new newError.Forbidden(
24
+ UserErrorMessages.MISSING_REQUIRED_SCOPES_TEMPLATE({
25
+ requiredScopes: [
26
+ RegistrarScopes.WriteOrganizations,
27
+ RegistrarScopes.AdminOrganizations,
28
+ ],
29
+ })
30
+ );
31
+ }
32
+
33
+ if (params?.did) {
34
+ const orgGroup = await loadGroupByDid(params.did, ctx);
35
+ validateUserGroupIdClaim(user, orgGroup, params.did);
36
+ await syncGroupClientAdmins(user, orgGroup, ctx);
37
+ decorateScope({ dids: [params.did], groupId: orgGroup.groupId }, ctx);
38
+ return true;
39
+ }
40
+
41
+ if (user[VNF_GROUP_ID_CLAIM] != null) {
42
+ const userGroup = await loadGroupByUserClaim(user, ctx);
43
+ await syncGroupClientAdmins(user, userGroup, ctx);
44
+ decorateScope(
45
+ {
46
+ dids: method === 'POST' ? ['new'] : userGroup.dids,
47
+ groupId: userGroup.groupId,
48
+ },
49
+ ctx
50
+ );
51
+ return true;
52
+ }
53
+
54
+ decorateScope({ dids: ['new'], groupId: 'new' }, ctx);
55
+ return true;
56
+ };
57
+
58
+ const verifyUserOrganizationReadAuthorized = async (ctx) => {
59
+ const { user, params } = ctx;
60
+ if (hasAdminOrganizationScope(user)) {
61
+ return true;
62
+ }
63
+ if (!hasReadOrganizationScope(user)) {
64
+ throw new newError.Forbidden(
65
+ UserErrorMessages.MISSING_REQUIRED_SCOPES_TEMPLATE({
66
+ requiredScopes: [
67
+ RegistrarScopes.ReadOrganizations,
68
+ RegistrarScopes.AdminOrganizations,
69
+ ],
70
+ })
71
+ );
72
+ }
73
+
74
+ if (params?.did) {
75
+ const orgGroup = await loadGroupByDid(params.did, ctx);
76
+ validateUserGroupIdClaim(user, orgGroup, params.did);
77
+ await syncGroupClientAdmins(user, orgGroup, ctx);
78
+ decorateScope({ groupId: orgGroup.groupId, dids: [params.did] }, ctx);
79
+ return true;
80
+ }
81
+
82
+ validateUserGroupIdClaim(user);
83
+ const userGroup = await loadGroupByUserClaim(user, ctx);
84
+ await syncGroupClientAdmins(user, userGroup, ctx);
85
+ decorateScope(userGroup, ctx);
86
+ return true;
87
+ };
88
+
89
+ const verifyAuthorizedWriteUsers = async (ctx) => {
90
+ const { user, method, params } = ctx;
91
+
92
+ if (hasAdminUsersScope(user)) {
93
+ return true;
94
+ }
95
+
96
+ if (isParamIdYourself(user, params)) {
97
+ decorateScope({ userId: user.sub }, ctx);
98
+ return true;
99
+ }
100
+
101
+ if (!hasWriteUsersScope(user)) {
102
+ throw new newError.Forbidden(
103
+ UserErrorMessages.MISSING_REQUIRED_SCOPES_TEMPLATE({
104
+ user,
105
+ requiredScopes: [
106
+ RegistrarScopes.WriteUsers,
107
+ RegistrarScopes.AdminUsers,
108
+ ],
109
+ })
110
+ );
111
+ }
112
+
113
+ validateUserGroupIdClaim(user);
114
+ const group = await loadGroupByUserClaim(user, ctx);
115
+ validateUserIsGroupClientAdmin(user, group);
116
+
117
+ decorateScope(
118
+ {
119
+ ...group,
120
+ userId: isCreateMethod(method, params?.id) ? 'new' : params.id,
121
+ },
122
+ ctx
123
+ );
124
+ return true;
125
+ };
126
+ const verifyAuthorizedReadUsers = async (ctx) => {
127
+ const { user, params } = ctx;
128
+ if (hasAdminUsersScope(user)) {
129
+ return true;
130
+ }
131
+
132
+ if (isParamIdYourself(user, params)) {
133
+ decorateScope({ userId: user.sub }, ctx);
134
+ return true;
135
+ }
136
+
137
+ if (!hasReadUsersScope(user)) {
138
+ throw new newError.Forbidden(
139
+ UserErrorMessages.MISSING_REQUIRED_SCOPES_TEMPLATE({
140
+ requiredScopes: [RegistrarScopes.ReadUsers, RegistrarScopes.AdminUsers],
141
+ })
142
+ );
143
+ }
144
+
145
+ validateUserGroupIdClaim(user);
146
+ const group = await loadGroupByUserClaim(user, ctx);
147
+
148
+ decorateScope({ ...group, userId: params.id }, ctx);
149
+ return true;
150
+ };
151
+
152
+ const validateUserGroupIdClaim = (user, orgGroup, orgDid) => {
153
+ if (!user[VNF_GROUP_ID_CLAIM]) {
154
+ throw new newError.NotFound(
155
+ UserErrorMessages.USER_MUST_HAVE_GROUP_CLAIM({ user })
156
+ );
157
+ }
158
+ if (orgGroup != null && user[VNF_GROUP_ID_CLAIM] !== orgGroup.groupId) {
159
+ throw new newError.NotFound(
160
+ UserErrorMessages.USER_CANNOT_ACCESS_ORGANIZATION_GROUP({
161
+ user,
162
+ group: orgGroup,
163
+ did: orgDid,
164
+ })
165
+ );
166
+ }
167
+ };
168
+
169
+ const validateUserIsGroupClientAdmin = (user, group) => {
170
+ if (!includes(user.sub, group.clientAdminIds)) {
171
+ throw new newError.Forbidden(
172
+ UserErrorMessages.USER_NOT_GROUP_CLIENT_ADMIN({
173
+ user,
174
+ group,
175
+ })
176
+ );
177
+ }
178
+ };
179
+
180
+ const loadGroupByDid = async (did, { repos }) => {
181
+ const group = await repos.groups.findGroupByDid(did);
182
+ if (group == null) {
183
+ throw new newError.NotFound(
184
+ GroupErrorMessages.ORGANIZATION_GROUP_NOT_FOUND({ did })
185
+ );
186
+ }
187
+ return group;
188
+ };
189
+
190
+ const loadGroupByUserClaim = async (user, { repos }) => {
191
+ try {
192
+ return await repos.groups.findGroupByGroupId(user[VNF_GROUP_ID_CLAIM]);
193
+ } catch (ex) {
194
+ if (ex.status === 404) {
195
+ throw new newError.Forbidden(
196
+ UserErrorMessages.USER_INVALID_GROUP_CLAIM({ user })
197
+ );
198
+ }
199
+ throw ex;
200
+ }
201
+ };
202
+
203
+ const syncGroupClientAdmins = async (user, group, { repos, log }) => {
204
+ try {
205
+ if (!includes(user.sub, group.clientAdminIds)) {
206
+ await repos.groups.addUserToGroupClientAdmins(group.groupId, user.sub);
207
+ }
208
+ } catch (e) {
209
+ log.warn(e);
210
+ }
211
+ };
212
+
213
+ const isParamIdYourself = (user, params) =>
214
+ params?.id != null && params.id === user.sub;
215
+
216
+ const isCreateMethod = (method, paramId) => method === 'POST' && !paramId;
217
+
218
+ const decorateScope = ({ dids, groupId, userId }, ctx) => {
219
+ // eslint-disable-next-line better-mutation/no-mutation
220
+ ctx.scope = {
221
+ ...ctx.scope,
222
+ dids: dids ?? ctx.scope?.dids,
223
+ groupId: groupId ?? ctx.scope?.groupId,
224
+ userId: userId ?? ctx.scope?.userId,
225
+ };
226
+ };
227
+
228
+ module.exports = {
229
+ verifyUserOrganizationWriteAuthorized,
230
+ verifyUserOrganizationReadAuthorized,
231
+ verifyAuthorizedWriteUsers,
232
+ verifyAuthorizedReadUsers,
233
+ };
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ ...require('./authorization'),
3
+ ...require('./pubsub-plugin'),
4
+ };
@@ -0,0 +1,82 @@
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
+
18
+ const fp = require('fastify-plugin');
19
+ const { subscribe: spenceSubscribe } = require('@spencejs/spence-events');
20
+ const { setSelectedContext } = require('@spencejs/spence-events/src/events');
21
+
22
+ const pubsubPlugin = async (fastify) => {
23
+ setSelectedContext([
24
+ 'user',
25
+ 'traceId',
26
+ 'repos',
27
+ 'kms',
28
+ 'betterUptimeFetch',
29
+ 'secureMessagesFetch',
30
+ 'serviceVersionFetch',
31
+ 'getDocValidator',
32
+ 'headers',
33
+ 'renderTemplate',
34
+ ]);
35
+
36
+ const baseContext = {
37
+ config: fastify.config,
38
+ user: null,
39
+ log: null,
40
+ repos: null,
41
+ kms: null,
42
+ serviceVersionFetch: null,
43
+ secureMessagesFetch: null,
44
+ betterUptimeFetch: null,
45
+ getDocValidator: null,
46
+ headers: null,
47
+ };
48
+
49
+ const pubsub = (subscriberName) => ({
50
+ subscribe(topic, eventName, subscriber) {
51
+ spenceSubscribe(topic, eventName, async (event) => {
52
+ const context = structuredClone(baseContext);
53
+ context.user = event.meta.user;
54
+ context.log = fastify.log.child({
55
+ msgId: event.meta.id,
56
+ traceId: event.meta.traceId,
57
+ });
58
+ context.repos = event.meta.repos;
59
+ context.serviceVersionFetch = event.meta.serviceVersionFetch;
60
+ context.secureMessagesFetch = event.meta.secureMessagesFetch;
61
+ context.betterUptimeFetch = event.meta.betterUptimeFetch;
62
+ context.getDocValidator = event.meta.getDocValidator;
63
+ context.renderTemplate = event.meta.renderTemplate;
64
+ context.headers = event.meta.headers;
65
+ context.kms = event.meta.kms;
66
+
67
+ try {
68
+ await subscriber(event, context);
69
+ } catch (error) {
70
+ const message = `subscriber named ${subscriberName} failed`;
71
+ context.log.error({ err: error, event, subscriberName }, message);
72
+ fastify.sendError(error, { message, event, subscriberName });
73
+ }
74
+ });
75
+ return this;
76
+ },
77
+ });
78
+
79
+ fastify.decorate('pubsub', pubsub);
80
+ };
81
+
82
+ module.exports = { pubsubPlugin: fp(pubsubPlugin) };
@@ -0,0 +1,63 @@
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 { initSendActivationEmailsToCAOs } = require('../entities');
18
+
19
+ const notifyCaos = async (fastify) => {
20
+ const sendActivationEmailsToCAOs = initSendActivationEmailsToCAOs(fastify);
21
+
22
+ const eventHandler = (
23
+ {
24
+ payload: {
25
+ organization,
26
+ addedServices,
27
+ activatedServiceIds,
28
+ caoServiceRefs,
29
+ },
30
+ },
31
+ context
32
+ ) =>
33
+ sendActivationEmailsToCAOs(
34
+ organization,
35
+ addedServices,
36
+ activatedServiceIds,
37
+ caoServiceRefs,
38
+ context
39
+ );
40
+
41
+ fastify
42
+ .pubsub('notifyCaos')
43
+ .subscribe('organizations', 'created', eventHandler)
44
+ .subscribe('services', 'added', eventHandler)
45
+ .subscribe(
46
+ 'services',
47
+ 'activated',
48
+ (
49
+ { payload: { organization, activatedServiceIds, caoServiceRefs } },
50
+ context
51
+ ) => {
52
+ sendActivationEmailsToCAOs(
53
+ organization,
54
+ organization.services,
55
+ activatedServiceIds,
56
+ caoServiceRefs,
57
+ context
58
+ );
59
+ }
60
+ );
61
+ };
62
+
63
+ module.exports = notifyCaos;