@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/dist/index.js CHANGED
@@ -946,6 +946,30 @@ var Organizations = class {
946
946
  `/api/v1/organizations/${enc(id)}/directory/activity`
947
947
  );
948
948
  }
949
+ /**
950
+ * Every time your staff entered the organization or were refused, newest
951
+ * first: who, with which roles held at the Environment root, and why a
952
+ * refusal happened (`staff_entry_refused` while the organization's policy
953
+ * says `staff_entry: "refused"`).
954
+ *
955
+ * Paginated (20 per page by default, `take` up to 100), so this returns a
956
+ * `Paginator`. `kind` narrows to `entered` or `refused`; `q` searches who
957
+ * and the role names; `sort_by` is `created` (the default) or `actor`.
958
+ *
959
+ * ```ts
960
+ * for await (const entry of canopy.organizations.listStaffActivity(id)) { … }
961
+ * ```
962
+ */
963
+ listStaffActivity(id, query = {}) {
964
+ return paginate(
965
+ (params) => this.client.request(
966
+ "GET",
967
+ `/api/v1/organizations/${enc(id)}/staff-activity`,
968
+ { query: params }
969
+ ),
970
+ { ...query }
971
+ );
972
+ }
949
973
  /**
950
974
  * The groups the provider has pushed, each with its role mapping.
951
975
  *
@@ -1374,6 +1398,66 @@ var LocalAuthorizer = class {
1374
1398
  }
1375
1399
  return { roots, envWide: false, nodes, complete: true };
1376
1400
  }
1401
+ /**
1402
+ * Whether the identity holds the permission anywhere at or beneath a node,
1403
+ * and where: the question a menu inside an organization asks ("show
1404
+ * Invoices to someone who approves invoices for any team in Acme"), which
1405
+ * `app_wide` cannot answer because it covers the whole Environment.
1406
+ *
1407
+ * `roots` is `[subtreeRootId]` when a grant at the node or above it reaches
1408
+ * the whole subtree; otherwise the topmost granted nodes inside it, the
1409
+ * ones no other granted node inside it already covers. A list query filters
1410
+ * by "beneath one of these".
1411
+ *
1412
+ * **A read for menus and lists, never a guard.** Holding the permission
1413
+ * somewhere in the subtree says nothing about the record a write touches:
1414
+ * check the node the action writes to, with `evaluate`. No `scope` value
1415
+ * asks this question, on purpose.
1416
+ *
1417
+ * Computed from the same cached grant roots and tree a check uses. A grant
1418
+ * or a subtree root the readable hierarchy does not contain raises
1419
+ * `authorizer.hierarchy_incomplete`, as a check at such a node does.
1420
+ */
1421
+ async holdsAnywhereUnder(identityId, permission, subtreeRootId, subject = {}) {
1422
+ const now = this.now();
1423
+ const held = (await this.grantRootsFor(
1424
+ identityId,
1425
+ subject.principalType ?? "identity"
1426
+ )).get(permission) ?? [];
1427
+ const granted = new Set(
1428
+ held.filter((window) => inEffect(window, now)).map((w) => w.node)
1429
+ );
1430
+ const { parents } = await this.treeEntry();
1431
+ if (!parents.has(subtreeRootId)) {
1432
+ throw this.hierarchyIncomplete(subtreeRootId);
1433
+ }
1434
+ if (granted.size === 0) {
1435
+ return { held: false, roots: [] };
1436
+ }
1437
+ if (this.lineage(parents, subtreeRootId).some((n) => granted.has(n))) {
1438
+ return { held: true, roots: [subtreeRootId] };
1439
+ }
1440
+ const roots = [];
1441
+ for (const node of granted) {
1442
+ if (!parents.has(node)) {
1443
+ throw this.hierarchyIncomplete(node);
1444
+ }
1445
+ const above = this.lineage(parents, node).slice(1);
1446
+ if (above.includes(subtreeRootId) && !above.some((n) => granted.has(n))) {
1447
+ roots.push(node);
1448
+ }
1449
+ }
1450
+ return { held: roots.length > 0, roots };
1451
+ }
1452
+ /** The node and every ancestor up to the root, nearest first. */
1453
+ lineage(parents, nodeId) {
1454
+ const path = [];
1455
+ let depth = 0;
1456
+ for (let current = nodeId; current && depth < MAX_WALK_DEPTH; current = parents.get(current), depth += 1) {
1457
+ path.push(current);
1458
+ }
1459
+ return path;
1460
+ }
1377
1461
  /**
1378
1462
  * Every permission the identity holds at the node, by grant or by
1379
1463
  * inheritance: the list a screen renders its controls from, answered from
@@ -1801,7 +1885,8 @@ function orgContext(claims) {
1801
1885
  return {
1802
1886
  orgId: org_id,
1803
1887
  orgRoles: [...org_roles],
1804
- orgRoleIds: [...org_role_ids]
1888
+ orgRoleIds: [...org_role_ids],
1889
+ staff: claims.org_scope === "all"
1805
1890
  };
1806
1891
  }
1807
1892
  function decodeBase64Url(value) {