@digitalbazaar/ezcap-express 5.1.0 → 6.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @digitalbazaar/ezcap-express Changelog
2
2
 
3
+ ## 6.0.0 - 2022-03-01
4
+
5
+ ### Changed
6
+ - **BREAKING**: Better future proof conventional zcap API endpoints by
7
+ prefixing `/revocations` route with `/zcaps`.
8
+
3
9
  ## 5.1.0 - 2022-01-14
4
10
 
5
11
  ### Added
package/lib/revoke.js CHANGED
@@ -12,9 +12,9 @@ import {CapabilityDelegation} from '@digitalbazaar/zcap';
12
12
  * Authorizes a request to submit a zcap revocation.
13
13
  *
14
14
  * This middleware is opinionated; it MUST be attached to an endpoint that
15
- * terminates in `/revocations/:revocationId`. This to enable the middleware to
16
- * automatically generate expected values for running zcap checks and to
17
- * support a common, conventional revocation API pattern.
15
+ * terminates in `/zcaps/revocations/:revocationId`. This to enable the
16
+ * middleware to automatically generate expected values for running zcap checks
17
+ * and to support a common, conventional revocation API pattern.
18
18
  *
19
19
  * The pattern is in support of controlled objects on a service, aka
20
20
  * "service objects". Each object's controller is used to populate the root
@@ -25,17 +25,17 @@ import {CapabilityDelegation} from '@digitalbazaar/zcap';
25
25
  * Therefore, any route that matches an invocation target for a root zcap for
26
26
  * a service SHOULD attach this middleware to:
27
27
  *
28
- * `<serviceObjectId>/revocations/:revocationId`.
28
+ * `<serviceObjectId>/zcaps/revocations/:revocationId`.
29
29
  *
30
30
  * This middleware will compute `serviceObjectId` by combining the expected
31
31
  * host with the subpath from the request URL that occurs before
32
- * `/revocations/`. It assumes that the request URL will have this pattern
33
- * if the middleware code has been reached. IOW, `serviceObjectId` will
32
+ * `/zcaps/revocations/`. It assumes that the request URL will have this
33
+ * pattern if the middleware code has been reached. IOW, `serviceObjectId` will
34
34
  * be set using:
35
35
  *
36
- * `https://<expectedHost>/<URL subpath before "/revocations/">`.
36
+ * `https://<expectedHost>/<URL subpath before "/zcaps/revocations/">`.
37
37
  *
38
- * Note: This middleware does NOT support having `/revocations/` appear
38
+ * Note: This middleware does NOT support having `/zcaps/revocations/` appear
39
39
  * multiple places in the request URL.
40
40
  *
41
41
  * Attaching this middleware will enable any zcaps delegated from the service
@@ -44,7 +44,7 @@ import {CapabilityDelegation} from '@digitalbazaar/zcap';
44
44
  * supporting the invocation of a dynamically generated root zcap with an
45
45
  * invocation target of:
46
46
  *
47
- * `<serviceObjectId>/revocations/:revocationId`.
47
+ * `<serviceObjectId>/zcaps/revocations/:revocationId`.
48
48
  *
49
49
  * This middleware will set the `controller` of this root zcap to all
50
50
  * controllers in the to-be-revoked zcap's delegation chain, permitting any
@@ -53,9 +53,9 @@ import {CapabilityDelegation} from '@digitalbazaar/zcap';
53
53
  * not have `<serviceObjectId>` as its invocation target (or a prefix of it).
54
54
  * This ensures that the only zcaps that have been delegated from a root zcap
55
55
  * using the service object's ID as part of its invocation target can be
56
- * revoked at its `/revocations` route, i.e., other zcaps intended for other
57
- * service objects -- or entirely other services -- cannot be revoked via this
58
- * middleware.
56
+ * revoked at its `/zcaps/revocations` route, i.e., other zcaps intended for
57
+ * other service objects -- or entirely other services -- cannot be revoked via
58
+ * this middleware.
59
59
  *
60
60
  * This middleware will automatically generate two sets of expects values: one
61
61
  * for checking the invocation to revoke a capability and one for verifying the
@@ -74,7 +74,7 @@ import {CapabilityDelegation} from '@digitalbazaar/zcap';
74
74
  * // with an "id" of `revocationId`; RZ2's controller will be populated
75
75
  * // using all controllers from Z2's chain, enabling any controller in that
76
76
  * // zcap's chain to invoke RZ2 to revoke Z2
77
- * `<serviceObjectId>/revocations/<revocationId>`,
77
+ * `<serviceObjectId>/zcaps/revocations/<revocationId>`,
78
78
  * ],
79
79
  * action: 'write'
80
80
  * .
@@ -124,7 +124,8 @@ export function authorizeZcapRevocation({
124
124
  host: expectedHost,
125
125
  rootInvocationTarget: [
126
126
  serviceObjectId,
127
- `${serviceObjectId}/revocations/${encodeURIComponent(revocationId)}`
127
+ `${serviceObjectId}/zcaps/revocations/` +
128
+ encodeURIComponent(revocationId)
128
129
  ]
129
130
  };
130
131
  }
@@ -150,11 +151,11 @@ export function authorizeZcapRevocation({
150
151
  return [
151
152
  asyncHandler(async function(req, res, next) {
152
153
  // ensure middleware is attached to opinionated route
153
- if(!req.originalUrl.includes('/revocations/') ||
154
+ if(!req.originalUrl.includes('/zcaps/revocations/') ||
154
155
  !req.params.revocationId) {
155
156
  const error = new Error(
156
157
  'Revocation middleware must be attached to a route ending in ' +
157
- '"/revocations/:revocationId".');
158
+ '"/zcaps/revocations/:revocationId".');
158
159
  error.httpStatusCode = 500;
159
160
  return helpers.handleError({res, error, onError});
160
161
  }
@@ -266,8 +267,8 @@ function _wrapGetRootController({expectedHost, getRootController}) {
266
267
  }) {
267
268
  const serviceObjectId = _parseServiceObjectId({req, expectedHost});
268
269
  const {revocationId} = req.params;
269
- const zcapSpecificRootTarget =
270
- `${serviceObjectId}/revocations/${encodeURIComponent(revocationId)}`;
270
+ const zcapSpecificRootTarget = `${serviceObjectId}/zcaps/revocations/` +
271
+ encodeURIComponent(revocationId);
271
272
 
272
273
  // if `rootInvocationTarget` doesn't match the zcap-specific root
273
274
  // invocation target, then use user-provided `getRootController` to provide
@@ -294,9 +295,9 @@ function _wrapGetRootController({expectedHost, getRootController}) {
294
295
  root -> A -> B
295
296
 
296
297
  Any zcap controller in the chain of B may invoke a root zcap with an
297
- `invocationTarget` of `<baseUrl>/revocations/<ID of B>` (and an ID of
298
- `urn:zcap:root:encodeURIComponent(<baseUrl>/revocations/<ID of B>)`). This
299
- means that `root`, `A`, or `B` may revoke `B`.
298
+ `invocationTarget` of `<baseUrl>/zcaps/revocations/<ID of B>` (and an ID of
299
+ `urn:zcap:root:encodeURIComponent(<baseUrl>/zcaps/revocations/<ID of B>)`).
300
+ This means that `root`, `A`, or `B` may revoke `B`.
300
301
 
301
302
  As long no other zcap in the chain of `B` (e.g., `A`) has already been
302
303
  revoked, then `B` will be revoked and stored as a revocation (storage must
@@ -328,8 +329,8 @@ function _getCapabilityControllers({capability}) {
328
329
  }
329
330
 
330
331
  function _parseServiceObjectId({req, expectedHost}) {
331
- // `serviceObjectId` is full URL prior to `/revocations/`
332
- const idx = req.originalUrl.indexOf('/revocations/');
332
+ // `serviceObjectId` is full URL prior to `/zcaps/revocations/`
333
+ const idx = req.originalUrl.indexOf('/zcaps/revocations/');
333
334
  const path = req.originalUrl.substring(0, idx);
334
335
  return `https://${expectedHost}${path}`;
335
336
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalbazaar/ezcap-express",
3
- "version": "5.1.0",
3
+ "version": "6.0.0",
4
4
  "main": "lib",
5
5
  "module": "main.js",
6
6
  "repository": {