@canopy-io/node 0.7.0 → 0.7.2

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,17 @@
1
1
  # @canopy-io/node
2
2
 
3
+ ## 0.7.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 66415c2: The NestJS README's first `CanopyModule.forRoot` example now includes the required `verify` option, and `@canopy-io/node`'s types are regenerated from the published spec, adding the `branding.view` and `branding.manage` API key scopes. No behaviour changes.
8
+
9
+ ## 0.7.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 221e502: `LocalAuthorizer` keeps its copy of the hierarchy in about 40% less memory: one id string per node instead of two. A parsed `GET /api/v1/nodes/parents` response holds each node id twice, as the node's own `id` and again in its children's `parent_node_id`, and the cache used to keep both copies. A 50,000-node hierarchy now costs about 4.6 MB rather than 7.4 MB. Answers are unchanged.
14
+
3
15
  ## 0.7.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -37,7 +37,8 @@ import { Canopy, isCanopyError } from "@canopy-io/node";
37
37
 
38
38
  const canopy = new Canopy({ apiKey: process.env.CANOPY_API_KEY });
39
39
 
40
- // The call every integrator makes on every request.
40
+ // A fresh decision from the API. On the request path, prefer LocalAuthorizer
41
+ // (below), which answers in-process.
41
42
  const { allowed } = await canopy.permissions.evaluate({
42
43
  identity_id: identityId,
43
44
  permission: "documents.read",
@@ -102,9 +103,10 @@ try {
102
103
  }
103
104
  ```
104
105
 
105
- Hosted Login tokens carry an audience, so name your client. Direct API tokens
106
- carry none and need no option — and a token that has an `aud` is refused
107
- rather than ignored when you have not said which client you are:
106
+ Hosted Login tokens carry an audience, your `client_id`, so name your client.
107
+ Direct API tokens carry none and need no option. A token that has an `aud` is
108
+ refused rather than ignored when you have not said which client you are, so a
109
+ token minted for another client is never accepted by accident:
108
110
 
109
111
  ```ts
110
112
  new TokenVerifier({ audience: process.env.CANOPY_OAUTH_CLIENT_ID });
package/dist/index.cjs CHANGED
@@ -1325,8 +1325,16 @@ var LocalAuthorizer = class {
1325
1325
  }
1326
1326
  const parents = /* @__PURE__ */ new Map();
1327
1327
  if (result.modified) {
1328
+ const ids = /* @__PURE__ */ new Map();
1328
1329
  for (const edge of result.data.items) {
1329
- parents.set(edge.id, edge.parent_node_id ?? null);
1330
+ ids.set(edge.id, edge.id);
1331
+ }
1332
+ for (const edge of result.data.items) {
1333
+ const parent = edge.parent_node_id ?? null;
1334
+ parents.set(
1335
+ edge.id,
1336
+ parent === null ? null : ids.get(parent) ?? parent
1337
+ );
1330
1338
  }
1331
1339
  }
1332
1340
  this.tree = {