@velocitycareerlabs/server-webwallet 1.25.0-dev-build.12642c864

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 (193) hide show
  1. package/.localdev.env +57 -0
  2. package/.standalone.env +22 -0
  3. package/LICENSE +248 -0
  4. package/README.md +11 -0
  5. package/jest.config.js +20 -0
  6. package/migrate-mongo.config.js +23 -0
  7. package/package.json +72 -0
  8. package/src/config/config.js +74 -0
  9. package/src/controllers/accounts/autohooks.js +28 -0
  10. package/src/controllers/accounts/controller.js +209 -0
  11. package/src/controllers/accounts/schemas/index.js +6 -0
  12. package/src/controllers/accounts/schemas/webwallet-accounts-request.schema.js +25 -0
  13. package/src/controllers/accounts/schemas/webwallet-accounts-response.schema.js +72 -0
  14. package/src/controllers/accounts/schemas/webwallet-accounts-update-request.schema.js +23 -0
  15. package/src/controllers/accounts/schemas/webwallet-test-personas-response.schema.js +110 -0
  16. package/src/controllers/consent/autohooks.js +14 -0
  17. package/src/controllers/consent/controller.js +91 -0
  18. package/src/controllers/consent/schemas/index.js +3 -0
  19. package/src/controllers/consent/schemas/webwallet-consent-response.schema.js +23 -0
  20. package/src/controllers/credentials/autohooks.js +36 -0
  21. package/src/controllers/credentials/controller.js +92 -0
  22. package/src/controllers/credentials/schemas/index.js +4 -0
  23. package/src/controllers/credentials/schemas/webwallet-credential-categories-response.schema.js +21 -0
  24. package/src/controllers/credentials/schemas/webwallet-credentials-response.schema.js +29 -0
  25. package/src/controllers/disclosures/autohooks.js +21 -0
  26. package/src/controllers/disclosures/controller.js +168 -0
  27. package/src/controllers/disclosures/schemas/index.js +7 -0
  28. package/src/controllers/disclosures/schemas/webwallet-accept-presentation-request-body.schema.js +28 -0
  29. package/src/controllers/disclosures/schemas/webwallet-accept-presentation-response.schema.js +16 -0
  30. package/src/controllers/disclosures/schemas/webwallet-get-disclosures-response.schema.js +18 -0
  31. package/src/controllers/disclosures/schemas/webwallet-get-presentation-request-query.schema.js +21 -0
  32. package/src/controllers/disclosures/schemas/webwallet-get-presentation-request-response.schema.js +16 -0
  33. package/src/controllers/feedback/autohooks.js +11 -0
  34. package/src/controllers/feedback/controller.js +48 -0
  35. package/src/controllers/issuing/common-schemas/index.js +10 -0
  36. package/src/controllers/issuing/common-schemas/webwallet-get-credential-manifest-query.schema.js +27 -0
  37. package/src/controllers/issuing/common-schemas/webwallet-get-credential-manifest-response.schema.js +31 -0
  38. package/src/controllers/issuing/deep-link/autohooks.js +51 -0
  39. package/src/controllers/issuing/deep-link/controller.js +192 -0
  40. package/src/controllers/issuing/deep-link/schemas/index.js +6 -0
  41. package/src/controllers/issuing/deep-link/schemas/webwallet-deep-link-accept-offers-request.schema.js +30 -0
  42. package/src/controllers/issuing/deep-link/schemas/webwallet-deep-link-accept-offers-response.schema.js +36 -0
  43. package/src/controllers/issuing/deep-link/schemas/webwallet-deep-link-offers-request.schema.js +28 -0
  44. package/src/controllers/issuing/deep-link/schemas/webwallet-deep-link-offers-response.schema.js +48 -0
  45. package/src/controllers/issuing/identity-credentials/autohooks.js +42 -0
  46. package/src/controllers/issuing/identity-credentials/controller.js +188 -0
  47. package/src/controllers/issuing/identity-credentials/schemas/index.js +6 -0
  48. package/src/controllers/issuing/identity-credentials/schemas/webwallet-identity-credentials-confirm-body.schema.js +20 -0
  49. package/src/controllers/issuing/identity-credentials/schemas/webwallet-identity-credentials-confirm-response.schema.js +37 -0
  50. package/src/controllers/issuing/identity-credentials/schemas/webwallet-identity-credentials-request-code-body.schema.js +14 -0
  51. package/src/controllers/issuing/identity-credentials/schemas/webwallet-identity-credentials-request-code-params.schema.js +19 -0
  52. package/src/controllers/linkedin/autohooks.js +16 -0
  53. package/src/controllers/linkedin/controller.js +276 -0
  54. package/src/controllers/linkedin/schemas/index.js +3 -0
  55. package/src/controllers/linkedin/schemas/webwallet-linkedin-me-response.schema.js +14 -0
  56. package/src/controllers/root/controller.js +29 -0
  57. package/src/entities/.gitkeep +0 -0
  58. package/src/entities/accounts/constants.js +5 -0
  59. package/src/entities/accounts/domains/extract-auth0-id-token-or-access-token.js +22 -0
  60. package/src/entities/accounts/domains/index.js +5 -0
  61. package/src/entities/accounts/domains/validate-account-permissions.js +36 -0
  62. package/src/entities/accounts/domains/validate-logo-size.js +25 -0
  63. package/src/entities/accounts/index.js +5 -0
  64. package/src/entities/accounts/repos/accounts.repo.js +63 -0
  65. package/src/entities/credentials/domains/index.js +3 -0
  66. package/src/entities/credentials/domains/offer-to-credential-mongo-dto.js +43 -0
  67. package/src/entities/credentials/index.js +6 -0
  68. package/src/entities/credentials/orchestrators/index.js +3 -0
  69. package/src/entities/credentials/orchestrators/load-additional-render-info.js +65 -0
  70. package/src/entities/credentials/repos/credentials.repo.js +132 -0
  71. package/src/entities/credentials/schemas/index.js +4 -0
  72. package/src/entities/credentials/schemas/webwallet-credential-response.schema.js +138 -0
  73. package/src/entities/credentials/schemas/webwallet-credentials-response.schemas.js +95 -0
  74. package/src/entities/credentials/schemas/webwallet-display-descriptor-response.schema.js +106 -0
  75. package/src/entities/disclosures/index.js +4 -0
  76. package/src/entities/disclosures/repos/disclosures.repo.js +31 -0
  77. package/src/entities/disclosures/schemas/index.js +10 -0
  78. package/src/entities/disclosures/schemas/webwallet-disclosure.schema.js +39 -0
  79. package/src/entities/disclosures/schemas/webwallet-presentation-request-field.schema.js +45 -0
  80. package/src/entities/disclosures/schemas/webwallet-presentation-request-filter.schema.js +30 -0
  81. package/src/entities/disclosures/schemas/webwallet-presentation-request-format.schema.js +36 -0
  82. package/src/entities/disclosures/schemas/webwallet-presentation-request-input-descriptors.schema.js +111 -0
  83. package/src/entities/disclosures/schemas/webwallet-presentation-request-schema.schema.js +14 -0
  84. package/src/entities/disclosures/schemas/webwallet-presentation-request-submission-requirements.schema.js +37 -0
  85. package/src/entities/disclosures/schemas/webwallet-presentation-request.schema.js +79 -0
  86. package/src/entities/index.js +6 -0
  87. package/src/entities/issuing/domain/constants.js +8 -0
  88. package/src/entities/issuing/domain/does-user-have-fresh-pending-verification.js +26 -0
  89. package/src/entities/issuing/domain/get-credentials-from-offers.js +18 -0
  90. package/src/entities/issuing/domain/index.js +5 -0
  91. package/src/entities/issuing/index.js +5 -0
  92. package/src/entities/issuing/orchestrators/build-issuing-input-credentials.js +35 -0
  93. package/src/entities/issuing/orchestrators/generate-offers-by-deep-link.js +74 -0
  94. package/src/entities/issuing/orchestrators/get-identity-issuer.js +35 -0
  95. package/src/entities/issuing/orchestrators/get-identity-offers-by-deeplink.js +74 -0
  96. package/src/entities/issuing/orchestrators/index.js +6 -0
  97. package/src/entities/issuing/schemas/index.js +9 -0
  98. package/src/entities/issuing/schemas/webwallet-credential-manifest.schema.js +198 -0
  99. package/src/errors/error-codes.js +12 -0
  100. package/src/fetchers/career-wallet/create-account-fetcher.js +7 -0
  101. package/src/fetchers/career-wallet/create-did-fetcher.js +17 -0
  102. package/src/fetchers/career-wallet/get-app-config.js +11 -0
  103. package/src/fetchers/career-wallet/get-consents.js +13 -0
  104. package/src/fetchers/career-wallet/get-credential-categories.js +7 -0
  105. package/src/fetchers/career-wallet/get-personas.js +7 -0
  106. package/src/fetchers/career-wallet/index.js +12 -0
  107. package/src/fetchers/career-wallet/post-consent.js +9 -0
  108. package/src/fetchers/career-wallet/send-feedback.js +14 -0
  109. package/src/fetchers/career-wallet/sign-fetcher.js +14 -0
  110. package/src/fetchers/career-wallet/verify-id-credential-confirm-code.js +19 -0
  111. package/src/fetchers/career-wallet/verify-id-credential-request-code.js +20 -0
  112. package/src/fetchers/index.js +4 -0
  113. package/src/fetchers/lib-api/get-credential-display-schema.js +12 -0
  114. package/src/fetchers/lib-api/index.js +3 -0
  115. package/src/fetchers/linkedin/create-linkedin-post.js +45 -0
  116. package/src/fetchers/linkedin/get-access-token.js +26 -0
  117. package/src/fetchers/linkedin/get-linkedin-user-email.js +13 -0
  118. package/src/fetchers/linkedin/get-linkedin-user-id.js +16 -0
  119. package/src/fetchers/linkedin/index.js +9 -0
  120. package/src/fetchers/linkedin/register-image-to-upload.js +30 -0
  121. package/src/fetchers/linkedin/revoke-linkedin-access.js +20 -0
  122. package/src/fetchers/linkedin/upload-image-to-linkedin.js +16 -0
  123. package/src/index.js +15 -0
  124. package/src/init-server.js +108 -0
  125. package/src/plugins/crypto-services/index.js +5 -0
  126. package/src/plugins/crypto-services/jwt-sign-service-impl.js +72 -0
  127. package/src/plugins/crypto-services/jwt-verify-service-impl.js +21 -0
  128. package/src/plugins/crypto-services/key-service-impl.js +28 -0
  129. package/src/plugins/fetch-errors-handler-plugin.js +64 -0
  130. package/src/plugins/index.js +4 -0
  131. package/src/plugins/vnf-sdk-plugin.js +53 -0
  132. package/src/standalone.js +8 -0
  133. package/test/accounts-controller.test.js +618 -0
  134. package/test/consent-controller.test.js +185 -0
  135. package/test/credentials-controller.test.js +307 -0
  136. package/test/crypro-services/jwt-sign-service-impl.test.js +83 -0
  137. package/test/crypro-services/jwt-verify-service-impl.test.js +27 -0
  138. package/test/crypro-services/key-service-impl.test.js +76 -0
  139. package/test/crypro-services/mocks/index.js +4 -0
  140. package/test/crypro-services/mocks/jwt-mock.js +15 -0
  141. package/test/crypro-services/mocks/public-jwk.js +14 -0
  142. package/test/disclosures-controller/disclosure-credentials.test.js +428 -0
  143. package/test/disclosures-controller/get-disclosures.test.js +169 -0
  144. package/test/disclosures-controller/mocks/get-credential-manifest.js +20 -0
  145. package/test/disclosures-controller/mocks/index.js +6 -0
  146. package/test/disclosures-controller/mocks/presentation-request.js +32 -0
  147. package/test/disclosures-controller/mocks/presentation-submission.js +21 -0
  148. package/test/disclosures-controller/mocks/submission-result.js +19 -0
  149. package/test/factories/accounts.js +25 -0
  150. package/test/factories/credentials.js +66 -0
  151. package/test/factories/disclosures.js +106 -0
  152. package/test/feedback-controller.test.js +125 -0
  153. package/test/fetch-errors-handler-plugin.test.js +97 -0
  154. package/test/filter-deleted-credentials-extension.test.js +82 -0
  155. package/test/helpers/.env.test +10 -0
  156. package/test/helpers/nock-consent-add.js +16 -0
  157. package/test/helpers/nock-consents-get.js +15 -0
  158. package/test/helpers/nock-feedback.js +9 -0
  159. package/test/helpers/nock-linkedin-access-token.js +9 -0
  160. package/test/helpers/nock-linkedin-email.js +15 -0
  161. package/test/helpers/nock-linkedin-image-register.js +28 -0
  162. package/test/helpers/nock-linkedin-me.js +13 -0
  163. package/test/helpers/nock-linkedin-post.js +37 -0
  164. package/test/helpers/nock-linkedin-revoke.js +9 -0
  165. package/test/helpers/nock-test-personas.js +13 -0
  166. package/test/helpers/webwallet-build-fastify.js +17 -0
  167. package/test/issuing-controller/issuing-by-deeplink-empty-offers.test.js +142 -0
  168. package/test/issuing-controller/issuing-by-deeplink-failed-offers.test.js +142 -0
  169. package/test/issuing-controller/issuing-by-deeplink.test.js +492 -0
  170. package/test/issuing-controller/issuing-identity-credentials.test.js +377 -0
  171. package/test/issuing-controller/mocks/accept-offers-response.js +90 -0
  172. package/test/issuing-controller/mocks/accepted-credentials.js +47 -0
  173. package/test/issuing-controller/mocks/credential-manifest-presentation.js +72 -0
  174. package/test/issuing-controller/mocks/credential-manifest.js +45 -0
  175. package/test/issuing-controller/mocks/identity-issuing/accept-offers.js +22 -0
  176. package/test/issuing-controller/mocks/identity-issuing/confirm-verification-code.js +5 -0
  177. package/test/issuing-controller/mocks/identity-issuing/get-app-config.js +52 -0
  178. package/test/issuing-controller/mocks/identity-issuing/get-organization.js +118 -0
  179. package/test/issuing-controller/mocks/identity-issuing/index.js +6 -0
  180. package/test/issuing-controller/mocks/index.js +6 -0
  181. package/test/issuing-controller/mocks/issuers.js +126 -0
  182. package/test/issuing-controller/mocks/offers.js +48 -0
  183. package/test/issuing-controller/mocks/schema.js +107 -0
  184. package/test/linkedin-controller.test.js +452 -0
  185. package/test/mocks/credential-categories.js +115 -0
  186. package/test/mocks/credentials.js +15 -0
  187. package/test/mocks/didjwk.js +25 -0
  188. package/test/mocks/index.js +7 -0
  189. package/test/mocks/issuers.js +88 -0
  190. package/test/mocks/jwk.js +53 -0
  191. package/test/mocks/schema.js +107 -0
  192. package/test/root.test.js +42 -0
  193. package/test/vcl-sdk-plugin.test.js +86 -0
@@ -0,0 +1,209 @@
1
+ const newError = require('http-errors');
2
+ const { find, map } = require('lodash/fp');
3
+ const {
4
+ VCLSignatureAlgorithm,
5
+ } = require('@velocitycareerlabs/vnf-nodejs-wallet-sdk');
6
+ const { createCareerWalletAccount, getPersonas } = require('../../fetchers');
7
+ const {
8
+ validateLogoSize,
9
+ getCredentialsFromOffers,
10
+ } = require('../../entities');
11
+
12
+ const accountsController = async (fastify) => {
13
+ fastify.post(
14
+ '/',
15
+ {
16
+ preValidation: fastify.verifyAccessToken(),
17
+ schema: fastify.autoSchema({
18
+ tags: ['webwallet'],
19
+ body: {
20
+ $ref: 'https://velocitycareerlabs.io/webwallet-accounts-request.schema.json',
21
+ },
22
+ response: {
23
+ 200: {
24
+ $ref: 'https://velocitycareerlabs.io/webwallet-accounts-response.schema.json',
25
+ },
26
+ '4xx': { $ref: 'error#' },
27
+ },
28
+ }),
29
+ },
30
+ async (req) => {
31
+ const { repos } = req;
32
+
33
+ const [existingAccount, personaVcs] = await Promise.all([
34
+ repos.accounts.findOne({
35
+ filter: { userId: req.user.sub },
36
+ }),
37
+ getPersonaVCs(req.body, req),
38
+ ]);
39
+ const initialCredentials = prepareCredentials(personaVcs);
40
+
41
+ if (existingAccount != null) {
42
+ return { account: existingAccount };
43
+ }
44
+
45
+ const {
46
+ account: {
47
+ id: careerWalletAccountId,
48
+ accountType,
49
+ id_token_sub: userId,
50
+ didKeyMetadatum = [],
51
+ },
52
+ access_token: accessToken,
53
+ } = await createCareerWalletAccount(req.body, req);
54
+
55
+ const accountDidData = await buildDidData(
56
+ didKeyMetadatum,
57
+ accessToken,
58
+ req
59
+ );
60
+ const initialCredentialsToInsert = getCredentialsFromOffers(
61
+ userId,
62
+ accountDidData.did,
63
+ initialCredentials
64
+ );
65
+ const [account] = await Promise.all([
66
+ repos.accounts.insert({
67
+ careerWalletAccountId,
68
+ accountType,
69
+ userId,
70
+ verificationInfo: {
71
+ createAccountMessageDisplayed: false,
72
+ },
73
+ ...accountDidData,
74
+ }),
75
+ insertInitialCredentials(initialCredentialsToInsert, req),
76
+ ]);
77
+
78
+ return { account };
79
+ }
80
+ );
81
+
82
+ fastify.patch(
83
+ '',
84
+ {
85
+ preValidation: [fastify.verifyAccessToken(), validateLogoSize],
86
+ schema: fastify.autoSchema({
87
+ tags: ['webwallet'],
88
+ params: {
89
+ type: 'object',
90
+ properties: {
91
+ id: { type: 'string' },
92
+ },
93
+ },
94
+ body: {
95
+ $ref: 'https://velocitycareerlabs.io/webwallet-accounts-update-request.schema.json',
96
+ },
97
+ response: {
98
+ 200: {
99
+ $ref: 'https://velocitycareerlabs.io/webwallet-accounts-response.schema.json',
100
+ },
101
+ '4xx': { $ref: 'error#' },
102
+ },
103
+ }),
104
+ },
105
+ async (req) => {
106
+ const { repos, user } = req;
107
+
108
+ /**
109
+ * @type {import('../../entities/accounts/repos/accounts.repo').Account}
110
+ */
111
+
112
+ const existingAccount = await repos.accounts.findOne({
113
+ filter: { userId: user.sub },
114
+ });
115
+
116
+ if (existingAccount == null) {
117
+ throw newError.NotFound('Account not found');
118
+ }
119
+
120
+ const account = await repos.accounts.update(
121
+ existingAccount._id,
122
+ req.body.account
123
+ );
124
+
125
+ return {
126
+ account,
127
+ };
128
+ }
129
+ );
130
+
131
+ fastify.get(
132
+ '/test-personas',
133
+ {
134
+ schema: fastify.autoSchema({
135
+ tags: ['webwallet'],
136
+ response: {
137
+ 200: {
138
+ type: 'array',
139
+ items: {
140
+ $ref: 'https://velocitycareerlabs.io/webwallet-test-persona-response.schema.json',
141
+ },
142
+ },
143
+ },
144
+ }),
145
+ },
146
+ async (req) => {
147
+ return getPersonas(req);
148
+ }
149
+ );
150
+ };
151
+
152
+ /**
153
+ * @param {import('../../entities/accounts/repos/accounts.repo').Account['didKeyMetadatum']} didKeyMetadatum
154
+ * @param {string} accessToken
155
+ * @param {import('fastify').FastifyRequest} context
156
+ * @returns {Promise<{did: string, didKeyMetadatum: import('../../entities/accounts/repos/accounts.repo').AccountDidKeyMetadatum[]}>}
157
+ */
158
+ const buildDidData = async (didKeyMetadatum, accessToken, context) => {
159
+ const { vclSdk } = context;
160
+
161
+ if (didKeyMetadatum.length) {
162
+ return {
163
+ did: didKeyMetadatum[0].did,
164
+ didKeyMetadatum,
165
+ };
166
+ }
167
+
168
+ const newDidKeyMetadatum = await vclSdk.generateDidJwk({
169
+ signatureAlgorithm: VCLSignatureAlgorithm.ES256,
170
+ remoteCryptoServicesToken: accessToken,
171
+ });
172
+
173
+ return {
174
+ did: newDidKeyMetadatum.did,
175
+ didKeyMetadatum: [newDidKeyMetadatum],
176
+ };
177
+ };
178
+
179
+ const prepareCredentials = map((vc) => ({
180
+ encodedJwt: vc.jwt_vc,
181
+ }));
182
+
183
+ const getPersonaVCs = async ({ personaEmail }, context) => {
184
+ if (personaEmail == null) {
185
+ return [];
186
+ }
187
+ let personas = [];
188
+ try {
189
+ personas = await getPersonas(context);
190
+ } catch (e) {
191
+ context.log.warn(e);
192
+ throw newError(502, 'failed to get personas');
193
+ }
194
+
195
+ const persona = find({ email: personaEmail }, personas);
196
+ if (persona == null) {
197
+ throw newError(400, 'unrecognized persona');
198
+ }
199
+ return persona.vcs;
200
+ };
201
+
202
+ const insertInitialCredentials = async (credentials, context) => {
203
+ if (credentials.length <= 0) {
204
+ return [];
205
+ }
206
+ return context.repos.credentials.insertMany(credentials);
207
+ };
208
+
209
+ module.exports = accountsController;
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ ...require('./webwallet-accounts-request.schema'),
3
+ ...require('./webwallet-accounts-response.schema'),
4
+ ...require('./webwallet-accounts-update-request.schema'),
5
+ ...require('./webwallet-test-personas-response.schema'),
6
+ };
@@ -0,0 +1,25 @@
1
+ const { accountTypes } = require('../../../entities');
2
+
3
+ const webWalletAccountsRequestSchema = {
4
+ $id: 'https://velocitycareerlabs.io/webwallet-accounts-request.schema.json',
5
+ title: 'webwallet-accounts-request',
6
+ description: 'the body of request to retrieve an account',
7
+ type: 'object',
8
+ properties: {
9
+ account: {
10
+ type: 'object',
11
+ properties: {
12
+ accountType: {
13
+ type: 'string',
14
+ enum: accountTypes,
15
+ },
16
+ id_token: { type: 'string' },
17
+ },
18
+ required: ['accountType', 'id_token'],
19
+ },
20
+ personaEmail: { type: 'string' },
21
+ },
22
+ required: ['account'],
23
+ };
24
+
25
+ module.exports = { webWalletAccountsRequestSchema };
@@ -0,0 +1,72 @@
1
+ const { accountTypes } = require('../../../entities');
2
+
3
+ const webWalletAccountsResponseSchema = {
4
+ $id: 'https://velocitycareerlabs.io/webwallet-accounts-response.schema.json',
5
+ title: 'webwallet-accounts-response',
6
+ description: 'the body of response for webwallet create account endpoint',
7
+ type: 'object',
8
+ properties: {
9
+ account: {
10
+ type: 'object',
11
+ properties: {
12
+ id: { type: 'string' },
13
+ userId: { type: 'string' },
14
+ accountType: {
15
+ type: 'string',
16
+ enum: accountTypes,
17
+ },
18
+ did: { type: 'string' },
19
+ careerWalletAccountId: { type: 'string' },
20
+ profileName: { type: 'string' },
21
+ logo: { type: 'string' },
22
+ verificationInfo: {
23
+ type: 'object',
24
+ properties: {
25
+ createAccountMessageDisplayed: { type: 'boolean' },
26
+ email: {
27
+ type: 'object',
28
+ properties: {
29
+ status: { type: 'string', enum: ['pending', 'verified'] },
30
+ codeSentTo: { type: 'string' },
31
+ codeSentAt: { type: 'string' },
32
+ },
33
+ required: ['status'],
34
+ },
35
+ phone: {
36
+ type: 'object',
37
+ properties: {
38
+ status: {
39
+ type: 'string',
40
+ enum: ['pending', 'verified', 'skipped'],
41
+ },
42
+ codeSentTo: { type: 'string' },
43
+ codeSentAt: { type: 'string' },
44
+ },
45
+ required: ['status'],
46
+ },
47
+ },
48
+ },
49
+ linkedin: {
50
+ type: 'object',
51
+ properties: {
52
+ tokenExpiresAt: { type: 'string' },
53
+ },
54
+ },
55
+ createdAt: { type: 'string' },
56
+ updatedAt: { type: 'string' },
57
+ },
58
+ required: [
59
+ 'id',
60
+ 'userId',
61
+ 'did',
62
+ 'careerWalletAccountId',
63
+ 'accountType',
64
+ 'createdAt',
65
+ 'updatedAt',
66
+ ],
67
+ },
68
+ },
69
+ required: ['account'],
70
+ };
71
+
72
+ module.exports = { webWalletAccountsResponseSchema };
@@ -0,0 +1,23 @@
1
+ const webWalletAccountsUpdateRequestSchema = {
2
+ $id: 'https://velocitycareerlabs.io/webwallet-accounts-update-request.schema.json',
3
+ title: 'webwallet-accounts-request',
4
+ description: 'the body of request to retrieve an account',
5
+ type: 'object',
6
+ properties: {
7
+ account: {
8
+ type: 'object',
9
+ properties: {
10
+ 'verificationInfo.createAccountMessageDisplayed': { type: 'boolean' },
11
+ 'verificationInfo.phone.status': {
12
+ type: 'string',
13
+ enum: ['pending', 'skipped'],
14
+ },
15
+ profileName: { type: 'string' },
16
+ logo: { type: 'string' },
17
+ },
18
+ },
19
+ },
20
+ required: ['account'],
21
+ };
22
+
23
+ module.exports = { webWalletAccountsUpdateRequestSchema };
@@ -0,0 +1,110 @@
1
+ const webwalletTestPersonasResponceSchema = {
2
+ title: 'persona',
3
+ $id: 'https://velocitycareerlabs.io/webwallet-test-persona-response.schema.json',
4
+ type: 'object',
5
+ properties: {
6
+ name: {
7
+ type: 'string',
8
+ description: 'The name persona',
9
+ },
10
+ email: {
11
+ type: 'string',
12
+ description: 'email of the persona',
13
+ },
14
+ image: {
15
+ type: 'string',
16
+ format: 'uri',
17
+ description: "uri of the persona's image",
18
+ },
19
+ vcs: {
20
+ type: 'array',
21
+ items: {
22
+ type: 'object',
23
+ properties: {
24
+ jwt_vc: {
25
+ type: 'string',
26
+ description: 'The verifiable credential encoded as a jwt',
27
+ },
28
+ type: {
29
+ type: 'array',
30
+ items: { type: 'string' },
31
+ description: 'The list of credential types',
32
+ },
33
+ output_descriptors: {
34
+ type: 'array',
35
+ items: {
36
+ type: 'object',
37
+ properties: {
38
+ id: {
39
+ type: 'string',
40
+ },
41
+ schema: {
42
+ type: 'array',
43
+ items: {
44
+ type: 'object',
45
+ properties: {
46
+ uri: {
47
+ type: 'string',
48
+ format: 'uri',
49
+ },
50
+ },
51
+ },
52
+ },
53
+ display: {
54
+ type: 'object',
55
+ additionalProperties: true,
56
+ },
57
+ },
58
+ required: ['id'],
59
+ },
60
+ },
61
+ },
62
+ required: ['type', 'jwt_vc'],
63
+ },
64
+ },
65
+ did: {
66
+ type: 'string',
67
+ description: 'The did of the persona',
68
+ },
69
+ kid: {
70
+ type: 'string',
71
+ description: 'The kid of the persona',
72
+ },
73
+ keyId: {
74
+ type: 'string',
75
+ description: 'The keyId of the persona',
76
+ },
77
+ publicJwk: {
78
+ description: 'The public jwk',
79
+ type: 'object',
80
+ properties: {
81
+ crv: {
82
+ type: 'string',
83
+ },
84
+ kid: {
85
+ type: 'string',
86
+ },
87
+ kty: {
88
+ type: 'string',
89
+ },
90
+ x: {
91
+ type: 'string',
92
+ },
93
+ y: {
94
+ type: 'string',
95
+ },
96
+ },
97
+ },
98
+ createdAt: {
99
+ type: 'string',
100
+ format: 'date-time',
101
+ },
102
+ updatedAt: {
103
+ type: 'string',
104
+ format: 'date-time',
105
+ },
106
+ },
107
+ required: ['name', 'email', 'vcs'],
108
+ };
109
+
110
+ module.exports = { webwalletTestPersonasResponceSchema };
@@ -0,0 +1,14 @@
1
+ const { oauthPlugin } = require('@velocitycareerlabs/auth');
2
+ const { webWalletConsentResponseSchema } = require('./schemas');
3
+
4
+ module.exports = async (fastify) => {
5
+ fastify
6
+ .addSchema(webWalletConsentResponseSchema)
7
+ .autoSchemaPreset({
8
+ tags: ['webwallet'],
9
+ })
10
+ .register(oauthPlugin, {
11
+ domain: fastify.config.auth0Domain,
12
+ audience: [fastify.config.auth0WebWalletAudience],
13
+ });
14
+ };
@@ -0,0 +1,91 @@
1
+ const newError = require('http-errors');
2
+ const {
3
+ postConsent,
4
+ getConsentLatest,
5
+ } = require('../../fetchers/career-wallet');
6
+ const { webWalletConsentResponseSchema } = require('./schemas');
7
+ const { WebWalletServerError } = require('../../errors/error-codes');
8
+
9
+ const consentController = async (fastify) => {
10
+ fastify.get(
11
+ '/',
12
+ {
13
+ preValidation: fastify.verifyAccessToken(),
14
+ schema: fastify.autoSchema({
15
+ tags: ['webwallet'],
16
+ response: {
17
+ 200: {
18
+ type: 'object',
19
+ properties: {
20
+ consent: webWalletConsentResponseSchema,
21
+ },
22
+ required: ['consent'],
23
+ },
24
+ '4xx': { $ref: 'error#' },
25
+ },
26
+ }),
27
+ },
28
+ async (req, reply) => {
29
+ const {
30
+ repos: { accounts },
31
+ user,
32
+ } = req;
33
+ const account = await accounts.findOne({
34
+ filter: { userId: user.sub },
35
+ });
36
+ if (!account) {
37
+ throw newError(404, 'Account not found', {
38
+ errorCode: WebWalletServerError,
39
+ });
40
+ }
41
+
42
+ const consents = await getConsentLatest(
43
+ account.careerWalletAccountId,
44
+ req
45
+ );
46
+ reply.status(200);
47
+ return consents;
48
+ }
49
+ );
50
+
51
+ fastify.post(
52
+ '/',
53
+ {
54
+ preValidation: fastify.verifyAccessToken(),
55
+ schema: fastify.autoSchema({
56
+ body: {
57
+ type: 'object',
58
+ properties: {
59
+ version: {
60
+ type: 'string',
61
+ pattern: '[0-9]+.[0-9]+',
62
+ },
63
+ },
64
+ required: ['version'],
65
+ },
66
+ response: {
67
+ 200: {
68
+ type: 'object',
69
+ properties: {
70
+ consent: webWalletConsentResponseSchema,
71
+ },
72
+ required: ['consent'],
73
+ },
74
+ '4xx': { $ref: 'error#' },
75
+ },
76
+ }),
77
+ },
78
+ async (req, reply) => {
79
+ const {
80
+ headers: { authorization },
81
+ body,
82
+ } = req;
83
+ const consents = await postConsent(body, authorization, req);
84
+
85
+ reply.status(200);
86
+ return consents;
87
+ }
88
+ );
89
+ };
90
+
91
+ module.exports = consentController;
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ ...require('./webwallet-consent-response.schema'),
3
+ };
@@ -0,0 +1,23 @@
1
+ const webWalletConsentResponseSchema = {
2
+ $id: 'https://velocitycareerlabs.io/webwallet-consent-response.schema.json',
3
+ title: 'webwallet-consent-response',
4
+ description: 'the body of response for webwallet get consent latest endpoint',
5
+ type: 'object',
6
+ properties: {
7
+ accountId: {
8
+ type: 'string',
9
+ },
10
+ version: {
11
+ type: 'string',
12
+ },
13
+ createdAt: {
14
+ type: 'string',
15
+ },
16
+ id: {
17
+ type: 'string',
18
+ },
19
+ },
20
+ required: ['accountId', 'version', 'createdAt', 'id'],
21
+ };
22
+
23
+ module.exports = { webWalletConsentResponseSchema };
@@ -0,0 +1,36 @@
1
+ const { oauthPlugin } = require('@velocitycareerlabs/auth');
2
+ const {
3
+ organizationProfileBaseSchema,
4
+ organizationProfileSchema,
5
+ addressSchema,
6
+ locationSchema,
7
+ } = require('@velocitycareerlabs/common-schemas');
8
+
9
+ const {
10
+ webWalletCredentialResponseSchema,
11
+ webWalletDisplayDescriptorResponseSchema,
12
+ } = require('../../entities');
13
+
14
+ const {
15
+ webWalletCredentialsResponseSchema,
16
+ webWalletCredentialCategoriesResponseSchema,
17
+ } = require('./schemas');
18
+
19
+ module.exports = async (fastify) => {
20
+ fastify
21
+ .addSchema(addressSchema)
22
+ .addSchema(locationSchema)
23
+ .addSchema(organizationProfileBaseSchema)
24
+ .addSchema(organizationProfileSchema)
25
+ .addSchema(webWalletDisplayDescriptorResponseSchema)
26
+ .addSchema(webWalletCredentialResponseSchema)
27
+ .addSchema(webWalletCredentialsResponseSchema)
28
+ .addSchema(webWalletCredentialCategoriesResponseSchema)
29
+ .autoSchemaPreset({
30
+ tags: ['webwallet'],
31
+ })
32
+ .register(oauthPlugin, {
33
+ domain: fastify.config.auth0Domain,
34
+ audience: [fastify.config.auth0WebWalletAudience],
35
+ });
36
+ };