@canopy-io/node 0.14.0 → 0.15.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 +12 -0
- package/README.md +29 -0
- package/dist/index.cjs +86 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3192 -218
- package/dist/index.d.ts +3192 -218
- package/dist/index.js +86 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @canopy-io/node
|
|
2
2
|
|
|
3
|
+
## 0.15.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- e957aa1: `authorizer.holdsAnywhereUnder(identityId, permission, subtreeRootId)` answers whether the identity holds the permission at a node or anywhere beneath it, as `{ held, roots }`: `roots` is the subtree root alone when a grant at or above it reaches the whole subtree, otherwise the topmost granted nodes inside it. It is the question a menu inside an organization asks, which `app_wide` cannot, since that covers the whole Environment. It is a read for menus and lists, never a guard: a write still checks the node it writes to. It answers from the same cached grants and tree as a check, takes `{ principalType: "service" }` like the other reads, and raises `authorizer.hierarchy_incomplete` for a node the readable hierarchy does not contain. The conformance bundle gains the `holds-anywhere-under` vector, which the authorizer answers.
|
|
8
|
+
|
|
9
|
+
Your own staff (identities holding a role at the Environment root) carry `org_scope: "all"` on their tokens, now typed on `CanopyTokenClaims`. `orgContext(claims)` gains `staff`, true when a staff session is inside a customer's organization. `canopy.organizations.listStaffActivity(id, query)` pages through every staff entry into an organization and every refusal, filtered by `kind` (`entered` or `refused`), searched by `q`, sorted by `created` or `actor`.
|
|
10
|
+
|
|
11
|
+
The spec now has 176 operations. Generated types cover the staff activity, the organization policy's `staff_entry`, and an organization's own roles and integrations, which stay unwrapped like its other delegated administration routes.
|
|
12
|
+
|
|
13
|
+
In `@canopy-io/nestjs`, `scope: "org"` still evaluates only at the token's `org_id`. A staff token that has not entered an organization is denied with a message saying it enters with `switch-organization`; the guard never takes the organization from the route, since entering is what the customer's organization records and may refuse.
|
|
14
|
+
|
|
3
15
|
## 0.14.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -184,9 +184,17 @@ if (org) {
|
|
|
184
184
|
org.orgId; // the organization — also a hierarchy node id
|
|
185
185
|
org.orgRoles; // the roles held at its node, by name; [] for a member holding none there
|
|
186
186
|
org.orgRoleIds; // the same roles' ids, in the same order
|
|
187
|
+
org.staff; // true for your staff inside a customer's organization
|
|
187
188
|
}
|
|
188
189
|
```
|
|
189
190
|
|
|
191
|
+
Your own staff are identities holding a role at the Environment root. Their
|
|
192
|
+
tokens carry `org_scope: "all"`, and once one enters a customer's
|
|
193
|
+
organization `orgContext` answers with `staff: true` and the root roles as
|
|
194
|
+
`orgRoles`. The organization sees every entry in its staff activity
|
|
195
|
+
(`canopy.organizations.listStaffActivity(id)`) and can refuse staff
|
|
196
|
+
altogether, so say in your interface when a session is staff.
|
|
197
|
+
|
|
190
198
|
`null` is an ordinary answer: every token from an Environment without the
|
|
191
199
|
container on, and every identity that belongs to no organization yet. An empty
|
|
192
200
|
`orgRoles` is not: membership is admission, and a member may hold roles only
|
|
@@ -379,6 +387,27 @@ if (!access.complete) {
|
|
|
379
387
|
return db.reports.findMany({ where: { nodeId: { in: [...access.nodes] } } });
|
|
380
388
|
```
|
|
381
389
|
|
|
390
|
+
A menu inside an organization asks something narrower: does this person
|
|
391
|
+
hold the permission anywhere in it? `app_wide` cannot say, since it covers the
|
|
392
|
+
whole Environment, so a grant in another organization would show the menu
|
|
393
|
+
here too. `holdsAnywhereUnder` answers for one subtree, with `roots` as the
|
|
394
|
+
subtree root alone when a grant at or above it reaches all of it, and
|
|
395
|
+
otherwise the topmost granted nodes inside it:
|
|
396
|
+
|
|
397
|
+
```ts
|
|
398
|
+
const { held, roots } = await authorizer.holdsAnywhereUnder(
|
|
399
|
+
identityId,
|
|
400
|
+
"invoice.approve",
|
|
401
|
+
org.orgId,
|
|
402
|
+
);
|
|
403
|
+
|
|
404
|
+
// held: show the Invoices menu. roots: the teams whose invoices to list.
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
It is a read for menus and lists, never a guard: holding the permission
|
|
408
|
+
somewhere in Acme approves no particular invoice, so the write checks the
|
|
409
|
+
invoice's own node.
|
|
410
|
+
|
|
382
411
|
A list filtered this way is what to show; the write that follows still checks
|
|
383
412
|
its node. Canopy answers the same question fresh, for a process without the
|
|
384
413
|
authorizer, as `canopy.identities.accessibleNodes(id, { permission })`.
|
package/dist/index.cjs
CHANGED
|
@@ -948,6 +948,30 @@ var Organizations = class {
|
|
|
948
948
|
`/api/v1/organizations/${enc(id)}/directory/activity`
|
|
949
949
|
);
|
|
950
950
|
}
|
|
951
|
+
/**
|
|
952
|
+
* Every time your staff entered the organization or were refused, newest
|
|
953
|
+
* first: who, with which roles held at the Environment root, and why a
|
|
954
|
+
* refusal happened (`staff_entry_refused` while the organization's policy
|
|
955
|
+
* says `staff_entry: "refused"`).
|
|
956
|
+
*
|
|
957
|
+
* Paginated (20 per page by default, `take` up to 100), so this returns a
|
|
958
|
+
* `Paginator`. `kind` narrows to `entered` or `refused`; `q` searches who
|
|
959
|
+
* and the role names; `sort_by` is `created` (the default) or `actor`.
|
|
960
|
+
*
|
|
961
|
+
* ```ts
|
|
962
|
+
* for await (const entry of canopy.organizations.listStaffActivity(id)) { … }
|
|
963
|
+
* ```
|
|
964
|
+
*/
|
|
965
|
+
listStaffActivity(id, query = {}) {
|
|
966
|
+
return paginate(
|
|
967
|
+
(params) => this.client.request(
|
|
968
|
+
"GET",
|
|
969
|
+
`/api/v1/organizations/${enc(id)}/staff-activity`,
|
|
970
|
+
{ query: params }
|
|
971
|
+
),
|
|
972
|
+
{ ...query }
|
|
973
|
+
);
|
|
974
|
+
}
|
|
951
975
|
/**
|
|
952
976
|
* The groups the provider has pushed, each with its role mapping.
|
|
953
977
|
*
|
|
@@ -1376,6 +1400,66 @@ var LocalAuthorizer = class {
|
|
|
1376
1400
|
}
|
|
1377
1401
|
return { roots, envWide: false, nodes, complete: true };
|
|
1378
1402
|
}
|
|
1403
|
+
/**
|
|
1404
|
+
* Whether the identity holds the permission anywhere at or beneath a node,
|
|
1405
|
+
* and where: the question a menu inside an organization asks ("show
|
|
1406
|
+
* Invoices to someone who approves invoices for any team in Acme"), which
|
|
1407
|
+
* `app_wide` cannot answer because it covers the whole Environment.
|
|
1408
|
+
*
|
|
1409
|
+
* `roots` is `[subtreeRootId]` when a grant at the node or above it reaches
|
|
1410
|
+
* the whole subtree; otherwise the topmost granted nodes inside it, the
|
|
1411
|
+
* ones no other granted node inside it already covers. A list query filters
|
|
1412
|
+
* by "beneath one of these".
|
|
1413
|
+
*
|
|
1414
|
+
* **A read for menus and lists, never a guard.** Holding the permission
|
|
1415
|
+
* somewhere in the subtree says nothing about the record a write touches:
|
|
1416
|
+
* check the node the action writes to, with `evaluate`. No `scope` value
|
|
1417
|
+
* asks this question, on purpose.
|
|
1418
|
+
*
|
|
1419
|
+
* Computed from the same cached grant roots and tree a check uses. A grant
|
|
1420
|
+
* or a subtree root the readable hierarchy does not contain raises
|
|
1421
|
+
* `authorizer.hierarchy_incomplete`, as a check at such a node does.
|
|
1422
|
+
*/
|
|
1423
|
+
async holdsAnywhereUnder(identityId, permission, subtreeRootId, subject = {}) {
|
|
1424
|
+
const now = this.now();
|
|
1425
|
+
const held = (await this.grantRootsFor(
|
|
1426
|
+
identityId,
|
|
1427
|
+
subject.principalType ?? "identity"
|
|
1428
|
+
)).get(permission) ?? [];
|
|
1429
|
+
const granted = new Set(
|
|
1430
|
+
held.filter((window) => inEffect(window, now)).map((w) => w.node)
|
|
1431
|
+
);
|
|
1432
|
+
const { parents } = await this.treeEntry();
|
|
1433
|
+
if (!parents.has(subtreeRootId)) {
|
|
1434
|
+
throw this.hierarchyIncomplete(subtreeRootId);
|
|
1435
|
+
}
|
|
1436
|
+
if (granted.size === 0) {
|
|
1437
|
+
return { held: false, roots: [] };
|
|
1438
|
+
}
|
|
1439
|
+
if (this.lineage(parents, subtreeRootId).some((n) => granted.has(n))) {
|
|
1440
|
+
return { held: true, roots: [subtreeRootId] };
|
|
1441
|
+
}
|
|
1442
|
+
const roots = [];
|
|
1443
|
+
for (const node of granted) {
|
|
1444
|
+
if (!parents.has(node)) {
|
|
1445
|
+
throw this.hierarchyIncomplete(node);
|
|
1446
|
+
}
|
|
1447
|
+
const above = this.lineage(parents, node).slice(1);
|
|
1448
|
+
if (above.includes(subtreeRootId) && !above.some((n) => granted.has(n))) {
|
|
1449
|
+
roots.push(node);
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
return { held: roots.length > 0, roots };
|
|
1453
|
+
}
|
|
1454
|
+
/** The node and every ancestor up to the root, nearest first. */
|
|
1455
|
+
lineage(parents, nodeId) {
|
|
1456
|
+
const path = [];
|
|
1457
|
+
let depth = 0;
|
|
1458
|
+
for (let current = nodeId; current && depth < MAX_WALK_DEPTH; current = parents.get(current), depth += 1) {
|
|
1459
|
+
path.push(current);
|
|
1460
|
+
}
|
|
1461
|
+
return path;
|
|
1462
|
+
}
|
|
1379
1463
|
/**
|
|
1380
1464
|
* Every permission the identity holds at the node, by grant or by
|
|
1381
1465
|
* inheritance: the list a screen renders its controls from, answered from
|
|
@@ -1803,7 +1887,8 @@ function orgContext(claims) {
|
|
|
1803
1887
|
return {
|
|
1804
1888
|
orgId: org_id,
|
|
1805
1889
|
orgRoles: [...org_roles],
|
|
1806
|
-
orgRoleIds: [...org_role_ids]
|
|
1890
|
+
orgRoleIds: [...org_role_ids],
|
|
1891
|
+
staff: claims.org_scope === "all"
|
|
1807
1892
|
};
|
|
1808
1893
|
}
|
|
1809
1894
|
function decodeBase64Url(value) {
|