@verii/server-credentialagent 1.0.0 → 1.0.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verii/server-credentialagent",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Credential Agent application",
5
5
  "main": "src/index.js",
6
6
  "repository": "https://github.com/LFDT-Verii/core",
@@ -40,31 +40,31 @@
40
40
  "@fastify/view": "^11.0.0",
41
41
  "@spencejs/spence-factories": "^0.10.2",
42
42
  "@spencejs/spence-mongo-repos": "^0.10.2",
43
- "@verii/auth": "1.0.0",
44
- "@verii/base-contract-io": "1.0.0",
45
- "@verii/blockchain-functions": "1.0.0",
46
- "@verii/common-fetchers": "1.0.0",
47
- "@verii/common-functions": "1.0.0",
48
- "@verii/common-schemas": "1.0.0",
49
- "@verii/config": "1.0.0",
50
- "@verii/contract-permissions": "1.0.0",
51
- "@verii/crypto": "1.0.0",
52
- "@verii/csv-parser": "1.0.0",
53
- "@verii/db-kms": "1.0.0",
54
- "@verii/did-doc": "1.0.0",
55
- "@verii/fastify-plugins": "1.0.0",
56
- "@verii/jwt": "1.0.0",
57
- "@verii/metadata-registration": "1.0.0",
58
- "@verii/organizations-registry": "1.0.0",
59
- "@verii/request": "1.0.0",
60
- "@verii/rest-queries": "1.0.0",
61
- "@verii/server-provider": "1.0.0",
62
- "@verii/spencer-mongo-extensions": "1.0.0",
63
- "@verii/test-regexes": "1.0.0",
64
- "@verii/validation": "1.0.0",
65
- "@verii/vc-checks": "1.0.0",
66
- "@verii/verii-issuing": "1.0.0",
67
- "@verii/verii-verification": "1.0.0",
43
+ "@verii/auth": "1.0.1",
44
+ "@verii/base-contract-io": "1.0.1",
45
+ "@verii/blockchain-functions": "1.0.1",
46
+ "@verii/common-fetchers": "1.0.1",
47
+ "@verii/common-functions": "1.0.1",
48
+ "@verii/common-schemas": "1.0.1",
49
+ "@verii/config": "1.0.1",
50
+ "@verii/contract-permissions": "1.0.1",
51
+ "@verii/crypto": "1.0.1",
52
+ "@verii/csv-parser": "1.0.1",
53
+ "@verii/db-kms": "1.0.1",
54
+ "@verii/did-doc": "1.0.1",
55
+ "@verii/fastify-plugins": "1.0.1",
56
+ "@verii/jwt": "1.0.1",
57
+ "@verii/metadata-registration": "1.0.1",
58
+ "@verii/organizations-registry": "1.0.1",
59
+ "@verii/request": "1.0.1",
60
+ "@verii/rest-queries": "1.0.1",
61
+ "@verii/server-provider": "1.0.1",
62
+ "@verii/spencer-mongo-extensions": "1.0.1",
63
+ "@verii/test-regexes": "1.0.1",
64
+ "@verii/validation": "1.0.1",
65
+ "@verii/vc-checks": "1.0.1",
66
+ "@verii/verii-issuing": "1.0.1",
67
+ "@verii/verii-verification": "1.0.1",
68
68
  "ajv": "8.17.1",
69
69
  "canonicalize": "^2.1.0",
70
70
  "date-fns": "~3.6.0",
@@ -83,10 +83,10 @@
83
83
  },
84
84
  "devDependencies": {
85
85
  "@spencejs/spence-config": "0.10.2",
86
- "@verii/endpoints-organizations-registrar": "1.0.0",
87
- "@verii/sample-data": "1.0.0",
86
+ "@verii/endpoints-organizations-registrar": "1.0.1",
87
+ "@verii/sample-data": "1.0.1",
88
88
  "@verii/test-regexes": "0.5.0-build",
89
- "@verii/tests-helpers": "1.0.0",
89
+ "@verii/tests-helpers": "1.0.1",
90
90
  "cheerio": "1.1.2",
91
91
  "dotenv": "16.6.1",
92
92
  "eslint": "8.57.1",
@@ -107,5 +107,5 @@
107
107
  "prettier": "2.8.8",
108
108
  "qs": "6.14.0"
109
109
  },
110
- "gitHead": "cd16eb096562d76aed1a11a1adabcc34aa26324a"
110
+ "gitHead": "9d9c8078fa1081d2bbe4a0d489d1ac9eead80edb"
111
111
  }
@@ -1,4 +1,3 @@
1
- const { omit } = require('lodash/fp');
2
1
  const newAgentDisclosureSchema = require('./new-agent-disclosure.schema.json');
3
2
 
4
3
  const updateAgentDisclosureSchema = {
@@ -7,7 +6,7 @@ const updateAgentDisclosureSchema = {
7
6
  title: 'update-agent-disclosure',
8
7
  description: 'Slightly modified from new-agent-disclosure',
9
8
  properties: {
10
- ...omit(['feed'], newAgentDisclosureSchema.properties),
9
+ ...newAgentDisclosureSchema.properties,
11
10
  setIssuingDefault: {
12
11
  type: 'boolean',
13
12
  },
@@ -29,6 +29,7 @@ const DisclosureErrors = {
29
29
  PRESENTATION_DEFINITION_GROUP_IF_SUBMISSION_REQUIREMENTS:
30
30
  'presentationDefinition input_descriptors[*].group is required when submission_requirements are sent',
31
31
  ISSUING_FEED_NOT_SUPPORTED: 'Issuing feeds are not supported',
32
+ FEED_PROPERTY_CANNOT_BE_MODIFIED: 'feed property cannot be modified',
32
33
  };
33
34
 
34
35
  module.exports = { DisclosureErrors };
@@ -29,7 +29,7 @@ const validateDisclosure = (
29
29
  validateVendorEndpoint(disclosure);
30
30
  validateCommercialEntity(disclosure, verifiedProfile);
31
31
  validatePresentationDefinition(disclosure);
32
- validateFeed(disclosure);
32
+ validateFeed(disclosure, context);
33
33
  };
34
34
 
35
35
  module.exports = {
@@ -2,15 +2,26 @@ const newError = require('http-errors');
2
2
  const { DisclosureErrors } = require('./errors');
3
3
  const { ConfigurationType } = require('./constants');
4
4
 
5
- const validateFeed = (disclosure) => {
5
+ const validateFeed = (disclosure, context) => {
6
6
  const { configurationType, feed } = disclosure;
7
7
  if (configurationType === ConfigurationType.ISSUING && feed === true) {
8
8
  throw newError(400, DisclosureErrors.ISSUING_FEED_NOT_SUPPORTED, {
9
9
  errorCode: 'issuing_feed_not_supported',
10
10
  });
11
11
  }
12
+ if (
13
+ context.method === 'PUT' &&
14
+ isFeedModified(context.disclosure, disclosure)
15
+ ) {
16
+ throw newError(400, DisclosureErrors.FEED_PROPERTY_CANNOT_BE_MODIFIED, {
17
+ errorCode: 'feed_property_cannot_be_modified',
18
+ });
19
+ }
12
20
  };
13
21
 
22
+ const isFeedModified = (existing, modified) =>
23
+ (!existing.feed && modified.feed) || (existing.feed && !modified.feed);
24
+
14
25
  module.exports = {
15
26
  validateFeed,
16
27
  };
@@ -2834,8 +2834,7 @@ describe('disclosures management', () => {
2834
2834
  await persistDisclosure({
2835
2835
  tenant,
2836
2836
  configurationType: ConfigurationType.INSPECTION,
2837
- identificationMethods: ['verifiable_presentation'],
2838
- vendorEndpoint: 'receive-applicant',
2837
+ vendorEndpoint: VendorEndpoint.RECEIVE_CHECKED_CREDENTIALS,
2839
2838
  })
2840
2839
  );
2841
2840
  const response = await fastify.injectJson({
@@ -2867,8 +2866,7 @@ describe('disclosures management', () => {
2867
2866
  await persistDisclosure({
2868
2867
  tenant,
2869
2868
  configurationType: ConfigurationType.INSPECTION,
2870
- identificationMethods: ['verifiable_presentation'],
2871
- vendorEndpoint: 'receive-applicant',
2869
+ vendorEndpoint: VendorEndpoint.RECEIVE_CHECKED_CREDENTIALS,
2872
2870
  })
2873
2871
  );
2874
2872
  const response = await fastify.injectJson({
@@ -2894,53 +2892,90 @@ describe('disclosures management', () => {
2894
2892
  );
2895
2893
  });
2896
2894
 
2897
- it('should 200 and update the disclosure with identificationMethods set to [verifiable_presentation]', async () => {
2895
+ it('should 400 if the feed property is modified', async () => {
2896
+ const disclosure = await persistDisclosure({
2897
+ feed: true,
2898
+ tenant,
2899
+ configurationType: ConfigurationType.INSPECTION,
2900
+ vendorEndpoint: VendorEndpoint.RECEIVE_CHECKED_CREDENTIALS,
2901
+ });
2898
2902
  const updatePayload = _.flow(
2899
2903
  _.omit(['createdAt', 'updatedAt', '_id']),
2900
- _.set('identificationMethods', ['verifiable_presentation'])
2901
- )(disclosures.a);
2904
+ _.set('description', 'new description'),
2905
+ _.set('feed', false)
2906
+ )(disclosure);
2902
2907
 
2903
2908
  const response = await fastify.injectJson({
2904
2909
  method: 'PUT',
2905
- url: `${disclosureUrl(tenant)}/${disclosures.a._id}`,
2910
+ url: `${disclosureUrl(tenant)}/${disclosure._id}`,
2911
+ payload: updatePayload,
2912
+ });
2913
+
2914
+ expect(response.statusCode).toEqual(400);
2915
+ expect(response.json).toEqual(
2916
+ errorResponseMatcher({
2917
+ error: 'Bad Request',
2918
+ errorCode: 'feed_property_cannot_be_modified',
2919
+ message: 'feed property cannot be modified',
2920
+ statusCode: 400,
2921
+ })
2922
+ );
2923
+ });
2924
+
2925
+ it('should 200 and update the disclosure', async () => {
2926
+ const disclosure = await persistDisclosure({
2927
+ tenant,
2928
+ configurationType: ConfigurationType.INSPECTION,
2929
+ vendorEndpoint: VendorEndpoint.RECEIVE_CHECKED_CREDENTIALS,
2930
+ });
2931
+
2932
+ const updatePayload = _.flow(
2933
+ _.omit(['createdAt', 'updatedAt', '_id']),
2934
+ _.set('description', 'new description')
2935
+ )(disclosure);
2936
+
2937
+ const response = await fastify.injectJson({
2938
+ method: 'PUT',
2939
+ url: `${disclosureUrl(tenant)}/${disclosure._id}`,
2906
2940
  payload: updatePayload,
2907
2941
  });
2908
2942
 
2909
2943
  expect(response.statusCode).toEqual(200);
2910
2944
  expect(response.json).toEqual({
2945
+ ..._.omit(['_id'], disclosure),
2911
2946
  ...updatePayload,
2947
+ id: disclosure._id,
2912
2948
  identificationMethods: ['verifiable_presentation'],
2913
- sendPushOnVerification: false,
2914
2949
  feed: false,
2915
- id: expect.stringMatching(OBJECT_ID_FORMAT),
2916
- createdAt: expect.stringMatching(ISO_DATETIME_FORMAT),
2917
2950
  updatedAt: expect.stringMatching(ISO_DATETIME_FORMAT),
2918
2951
  });
2919
2952
 
2920
2953
  const dbResult = await mongoDb()
2921
2954
  .collection('disclosures')
2922
2955
  .findOne({ _id: new ObjectId(response.json.id) });
2923
- expect(mongoify(dbResult)).toEqual({
2924
- ...updatePayload,
2925
- identificationMethods: ['verifiable_presentation'],
2926
- sendPushOnVerification: false,
2927
- _id: new ObjectId(response.json.id),
2928
- tenantId: new ObjectId(tenant._id),
2929
- deactivationDate: expect.any(Date),
2930
- createdAt: expect.any(Date),
2931
- updatedAt: expect.any(Date),
2932
- });
2956
+ expect(mongoify(dbResult)).toEqual(
2957
+ mongoify({
2958
+ ...disclosure,
2959
+ ...updatePayload,
2960
+ tenantId: tenant._id,
2961
+ feed: false,
2962
+ identificationMethods: ['verifiable_presentation'],
2963
+ updatedAt: expect.any(Date),
2964
+ })
2965
+ );
2933
2966
  });
2934
2967
 
2935
- it('should 200 and strip the feed property', async () => {
2968
+ it('should 200 and update the feed disclosure', async () => {
2936
2969
  const disclosure = await persistDisclosure({
2937
- description: 'feedTrueTest',
2938
- feed: true,
2939
2970
  tenant,
2971
+ feed: true,
2972
+ configurationType: ConfigurationType.INSPECTION,
2973
+ vendorEndpoint: VendorEndpoint.RECEIVE_CHECKED_CREDENTIALS,
2940
2974
  });
2975
+
2941
2976
  const updatePayload = _.flow(
2942
2977
  _.omit(['createdAt', 'updatedAt', '_id']),
2943
- _.set('feed', false)
2978
+ _.set('description', 'new description')
2944
2979
  )(disclosure);
2945
2980
 
2946
2981
  const response = await fastify.injectJson({
@@ -2951,29 +2986,25 @@ describe('disclosures management', () => {
2951
2986
 
2952
2987
  expect(response.statusCode).toEqual(200);
2953
2988
  expect(response.json).toEqual({
2989
+ ..._.omit(['_id'], disclosure),
2954
2990
  ...updatePayload,
2991
+ id: disclosure._id,
2955
2992
  identificationMethods: ['verifiable_presentation'],
2956
- sendPushOnVerification: false,
2957
- feed: true,
2958
- id: expect.stringMatching(OBJECT_ID_FORMAT),
2959
- createdAt: expect.stringMatching(ISO_DATETIME_FORMAT),
2960
2993
  updatedAt: expect.stringMatching(ISO_DATETIME_FORMAT),
2961
2994
  });
2962
2995
 
2963
2996
  const dbResult = await mongoDb()
2964
2997
  .collection('disclosures')
2965
2998
  .findOne({ _id: new ObjectId(response.json.id) });
2966
- expect(mongoify(dbResult)).toEqual({
2967
- ...updatePayload,
2968
- feed: true,
2969
- identificationMethods: ['verifiable_presentation'],
2970
- sendPushOnVerification: false,
2971
- _id: new ObjectId(response.json.id),
2972
- tenantId: new ObjectId(tenant._id),
2973
- deactivationDate: expect.any(Date),
2974
- createdAt: expect.any(Date),
2975
- updatedAt: expect.any(Date),
2976
- });
2999
+ expect(mongoify(dbResult)).toEqual(
3000
+ mongoify({
3001
+ ...disclosure,
3002
+ ...updatePayload,
3003
+ tenantId: tenant._id,
3004
+ identificationMethods: ['verifiable_presentation'],
3005
+ updatedAt: expect.any(Date),
3006
+ })
3007
+ );
2977
3008
  });
2978
3009
  });
2979
3010
 
@@ -3157,6 +3188,7 @@ describe('disclosures management', () => {
3157
3188
  expect(mongoify(dbResult)).toEqual({
3158
3189
  ...updatePayload,
3159
3190
  identificationMethods: ['verifiable_presentation'],
3191
+ feed: false,
3160
3192
  sendPushOnVerification: false,
3161
3193
  _id: new ObjectId(response.json.id),
3162
3194
  tenantId: new ObjectId(tenant._id),
@@ -3252,6 +3284,7 @@ describe('disclosures management', () => {
3252
3284
  ..._.omit(['_id'], payload),
3253
3285
  identificationMethods: ['verifiable_presentation'],
3254
3286
  sendPushOnVerification: false,
3287
+ feed: false,
3255
3288
  _id: new ObjectId(response.json.id),
3256
3289
  tenantId: new ObjectId(tenant._id),
3257
3290
  types: [{ type: 'EmailV1.0' }, { type: 'PhoneV1.0' }],
@@ -3388,6 +3421,7 @@ describe('disclosures management', () => {
3388
3421
  ...updatePayload,
3389
3422
  identificationMethods: ['preauth'],
3390
3423
  sendPushOnVerification: false,
3424
+ feed: false,
3391
3425
  _id: new ObjectId(response.json.id),
3392
3426
  tenantId: new ObjectId(tenant._id),
3393
3427
  deactivationDate: expect.any(Date),
@@ -3460,6 +3494,7 @@ describe('disclosures management', () => {
3460
3494
  .findOne({ _id: new ObjectId(disclosure._id) });
3461
3495
  expect(mongoify(updatedDisclosure)).toEqual({
3462
3496
  ...payload,
3497
+ feed: false,
3463
3498
  _id: expect.any(ObjectId),
3464
3499
  tenantId: expect.any(ObjectId),
3465
3500
  identificationMethods: ['verifiable_presentation'],
@@ -3507,6 +3542,7 @@ describe('disclosures management', () => {
3507
3542
  .findOne({ _id: new ObjectId(disclosure._id) });
3508
3543
  expect(mongoify(updatedDisclosure)).toEqual({
3509
3544
  ...payload,
3545
+ feed: false,
3510
3546
  _id: expect.any(ObjectId),
3511
3547
  tenantId: expect.any(ObjectId),
3512
3548
  identificationMethods: ['verifiable_presentation'],