@bedrock/kms-http 23.3.0 → 23.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/http.js CHANGED
@@ -107,21 +107,15 @@ bedrock.events.on('bedrock-express.configure.routes', app => {
107
107
  });
108
108
  }
109
109
 
110
- // FIXME: this is a high-latency call -- consider adding the meter
111
- // in parallel with inserting the keystore, optimistically presuming it
112
- // will be added; we could decide that the case of a missing/invalid
113
- // meter is a possible state we have to deal in other cases anyway
114
- // https://github.com/digitalbazaar/bedrock-kms-http/issues/57
115
-
116
- // add meter
117
- await meters.upsert({id: meterId, serviceType: SERVICE_TYPE});
118
-
119
110
  // create a keystore for the controller
120
111
  const random = await generateRandom();
121
112
  const id = helpers.getKeystoreId({localId: random, routes});
122
113
  const config = {id, meterId, ...req.body};
123
114
  const record = await keystores.insert({config});
124
115
  res.status(201).location(id).json(record.config);
116
+
117
+ // meter usage
118
+ reportOperationUsage({req, storage: storageCost.keystore});
125
119
  }));
126
120
 
127
121
  // get all keystores by controller query
@@ -278,7 +272,7 @@ bedrock.events.on('bedrock-express.configure.routes', app => {
278
272
  const {meterId} = keystore;
279
273
  const {meter: {disabled}} = await meters.hasAvailable({
280
274
  id: meterId, serviceType: SERVICE_TYPE,
281
- resources: {storage: cfg.storageCost.revocation}
275
+ resources: {storage: storageCost.revocation}
282
276
  });
283
277
  if(disabled) {
284
278
  // meter is disabled, do not allow storage
@@ -295,8 +289,8 @@ bedrock.events.on('bedrock-express.configure.routes', app => {
295
289
  // success, no response body
296
290
  res.status(204).end();
297
291
 
298
- // report revocation usage as operation usage
299
- reportOperationUsage({req});
292
+ // meter usage
293
+ reportOperationUsage({req, storage: storageCost.revocation});
300
294
  }));
301
295
  });
302
296
 
package/lib/metering.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
2
+ * Copyright (c) 2019-2026 Digital Bazaar, Inc.
3
3
  */
4
4
  import * as bedrock from '@bedrock/core';
5
5
  import * as brZCapStorage from '@bedrock/zcap-storage';
@@ -14,10 +14,10 @@ import {meters} from '@bedrock/meter-usage-reporter';
14
14
  export const SERVICE_TYPE = 'webkms';
15
15
  meters.setAggregator({serviceType: SERVICE_TYPE, handler: _aggregateUsage});
16
16
 
17
- export function reportOperationUsage({req}) {
17
+ export function reportOperationUsage({req, storage = 0}) {
18
18
  // do not wait for usage to be reported
19
19
  const {keystore, keystore: {meterId: id}} = req.webkms;
20
- meters.use({id, operations: 1}).catch(
20
+ meters.use({id, operations: 1, storage}).catch(
21
21
  error => logger.error(
22
22
  `Keystore (${keystore.id}) meter (${id}) usage error.`, {error}));
23
23
  }
package/lib/middleware.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Copyright (c) 2019-2025 Digital Bazaar, Inc. All rights reserved.
2
+ * Copyright (c) 2019-2026 Digital Bazaar, Inc.
3
3
  */
4
4
  import * as bedrock from '@bedrock/core';
5
5
  import * as brZCapStorage from '@bedrock/zcap-storage';
@@ -54,7 +54,7 @@ export function createKmsOperationMiddleware() {
54
54
  getRootController: getKeystoreController,
55
55
  getVerifier,
56
56
  inspectCapabilityChain,
57
- onError, onSuccess: reportOperationUsage, suiteFactory
57
+ onError, onSuccess, suiteFactory
58
58
  });
59
59
  }
60
60
 
@@ -220,6 +220,11 @@ function onError({error}) {
220
220
  }, error);
221
221
  }
222
222
 
223
+ function onSuccess({req, /*res, next, result,*/ operationType}) {
224
+ const storage = operationType === 'GenerateKeyOperation' ? 1 : 0;
225
+ reportOperationUsage({req, operations: 1, storage});
226
+ }
227
+
223
228
  // hook used to create suites for verifying zcap delegation chains
224
229
  async function suiteFactory() {
225
230
  return new Ed25519Signature2020();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrock/kms-http",
3
- "version": "23.3.0",
3
+ "version": "23.4.0",
4
4
  "type": "module",
5
5
  "description": "Bedrock KMS HTTP API",
6
6
  "main": "./lib/index.js",
@@ -39,18 +39,18 @@
39
39
  "ipaddr.js": "^2.5.0"
40
40
  },
41
41
  "peerDependencies": {
42
- "@bedrock/app-identity": "^4.0.0",
42
+ "@bedrock/app-identity": "^4.2.0",
43
43
  "@bedrock/core": "^6.3.0",
44
44
  "@bedrock/did-context": "^6.0.0",
45
- "@bedrock/did-io": "^10.4.0",
46
- "@bedrock/express": "^8.3.1",
47
- "@bedrock/jsonld-document-loader": "^5.2.0",
48
- "@bedrock/kms": "^16.0.0",
49
- "@bedrock/meter-usage-reporter": "^10.0.0",
45
+ "@bedrock/did-io": "^10.5.0",
46
+ "@bedrock/express": "^8.8.3",
47
+ "@bedrock/jsonld-document-loader": "^5.2.1",
48
+ "@bedrock/kms": "^16.2.0",
49
+ "@bedrock/meter-usage-reporter": "^10.3.5",
50
50
  "@bedrock/security-context": "^9.0.0",
51
- "@bedrock/validation": "^7.1.1",
51
+ "@bedrock/validation": "^7.3.0",
52
52
  "@bedrock/veres-one-context": "^16.0.0",
53
- "@bedrock/zcap-storage": "^9.3.0"
53
+ "@bedrock/zcap-storage": "^9.7.0"
54
54
  },
55
55
  "directories": {
56
56
  "lib": "./lib"