@canopy-io/node 0.26.2 → 0.28.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 +22 -0
- package/README.md +37 -10
- package/dist/index.cjs +14 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +317 -199
- package/dist/index.d.ts +317 -199
- package/dist/index.js +14 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @canopy-io/node
|
|
2
2
|
|
|
3
|
+
## 0.28.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 30c915c: Follows Canopy's release that makes organizations, multi-factor authentication for end users, passkey sign-in and more than two social sign-in providers per Environment depend on the Account's plan. The generated types change as follows.
|
|
8
|
+
|
|
9
|
+
- The plan entitlements answer (`GET /api/v1/billing/entitlements`) adds `limits` (`social_providers`, the providers each Environment may count, or null for no limit) and `required_plans` (for each feature that is off and each limit that is a number, the lowest plan that lifts it, or null when none does). The feature map, here and in the usage answer, adds `organizations`, `mfa`, `passkey_sign_in` and `brand_removal`.
|
|
10
|
+
- The schema `MfaFactorResponseDto` is renamed `IdentityEnrolledFactorResponseDto` and adds `second_factor`, false for a passkey added only to sign in with. A caller naming the schema, for example `Schema<"MfaFactorResponseDto">`, names `IdentityEnrolledFactorResponseDto` instead. `mfa_enrolled` and `mfa_factor_count` on an identity's auth state now count second factors only, and `mfa_admin_reset_at` records only a reset that removed a factor.
|
|
11
|
+
- A social provider adds `holds_place`: a custom provider turned off by a change to its discovery URL or client still counts against the plan's limit until it is turned on again or saved with `enabled: false`.
|
|
12
|
+
- What the caller administers in an organization (`GET /api/v1/organizations/{id}/me`) adds `plan_includes_mfa`, `sso_in_use` and `directory_in_use`.
|
|
13
|
+
- The routes that now refuse on the plan say so in their existing responses: `403 plan_feature_unavailable` on creating an organization, switching the organizations container on, turning on or tightening MFA in the auth settings or an organization's policy, turning on passkey sign-in in the auth settings, importing an Environment and creating one with `copy_from`; `409 plan_limit_exceeded` on turning on a social provider past the limit and on creating an organization past the plan's organization limit. No operation or response status is added or removed.
|
|
14
|
+
- Reading, removing, turning off and unlinking SSO connections, domains, SCIM directories, tokens and group mappings, on the Account and in an organization, no longer refuse on the plan; adding, changing and turning them on still do. An organization's own administrator, signed in with their own token, is refused with `auth.not_available` rather than a plan refusal.
|
|
15
|
+
|
|
16
|
+
The README says which organization calls depend on the Account's plan and how the refusal names the plan.
|
|
17
|
+
|
|
18
|
+
## 0.27.0
|
|
19
|
+
|
|
20
|
+
### Minor Changes
|
|
21
|
+
|
|
22
|
+
- f1fca62: Types for the API as deployed with the embedded sign-in form: `direct_api_permissions_claim_enabled` on the sign-in settings, `hosted_product_name` and `hosted_logo` on the branding, and the embedded form's verification code screen in the branding preview. The SSO sign-in coverage list's `items` change shape, from Environment id strings to objects with `environment_id` and `apps_without_sso`; a caller reading the ids reads `item.environment_id` instead.
|
|
23
|
+
- eaee2f6: Follows Canopy's release that gives Direct API tokens an audience: a Direct API access token names the id of the Environment that issued it in `aud`, as a Hosted Login token names its OAuth client. `TokenVerifier`'s `audience` (and `verify.audience` in `CanopyModule`) now takes a list as well as one value, and accepts a token whose `aud` includes any of them, so one verifier with `[clientId, environmentId]` accepts both sign-in kinds of one Environment and refuses a token for another client. A verifier with no `audience` still refuses a token that carries `aud` (`token.audience_unverified`), and its message now names what to set for each sign-in kind; a token with no `aud` is still refused when an audience is set. Machine tokens are still held to `serviceAudience` alone.
|
|
24
|
+
|
|
3
25
|
## 0.26.2
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
# @canopy-io/node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Call [Canopy](https://canopy-io.com)'s API from your server, verify the access tokens Canopy issues, and answer permission checks in your own process.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Which package
|
|
6
|
+
|
|
7
|
+
- **A server in Node.js, or anywhere `fetch` runs:** this package.
|
|
8
|
+
- **A NestJS app:** [`@canopy-io/nestjs`](https://www.npmjs.com/package/@canopy-io/nestjs), which installs this one and turns a permission check into a decorator on the route.
|
|
9
|
+
- **A Next.js app:** [`@canopy-io/nextjs`](https://www.npmjs.com/package/@canopy-io/nextjs), which installs this one and signs people in on your server.
|
|
10
|
+
- **A single-page app with no backend:** [`@canopy-io/browser`](https://www.npmjs.com/package/@canopy-io/browser), or its React and Angular packages.
|
|
6
11
|
|
|
7
12
|
## Install
|
|
8
13
|
|
|
@@ -175,13 +180,28 @@ verifier keeps verifying with the keys it holds; only a verifier that has never
|
|
|
175
180
|
loaded a key set, or a token signed by a key it has never seen, answers
|
|
176
181
|
`token.jwks_unavailable`.
|
|
177
182
|
|
|
178
|
-
|
|
179
|
-
Direct API
|
|
180
|
-
|
|
181
|
-
token
|
|
183
|
+
Every person's token carries an audience: a Hosted Login token your
|
|
184
|
+
`client_id`, a Direct API token the id of the Environment that issued it. Name
|
|
185
|
+
the one your sign-in issues, or both, as a list, when one backend accepts
|
|
186
|
+
both; a token is accepted when its `aud` includes any of them. A token that
|
|
187
|
+
has an `aud` is refused rather than ignored when you have not said which
|
|
188
|
+
audience you are, so a token minted for another client is never accepted by
|
|
189
|
+
accident:
|
|
182
190
|
|
|
183
191
|
```ts
|
|
192
|
+
// Hosted Login
|
|
184
193
|
new TokenVerifier({ audience: process.env.CANOPY_OAUTH_CLIENT_ID });
|
|
194
|
+
|
|
195
|
+
// Direct API
|
|
196
|
+
new TokenVerifier({ audience: process.env.CANOPY_ENVIRONMENT_ID });
|
|
197
|
+
|
|
198
|
+
// Both
|
|
199
|
+
new TokenVerifier({
|
|
200
|
+
audience: [
|
|
201
|
+
process.env.CANOPY_OAUTH_CLIENT_ID ?? "",
|
|
202
|
+
process.env.CANOPY_ENVIRONMENT_ID ?? "",
|
|
203
|
+
],
|
|
204
|
+
});
|
|
185
205
|
```
|
|
186
206
|
|
|
187
207
|
Every Environment is its own issuer, so name yours:
|
|
@@ -278,6 +298,12 @@ The organizations themselves are wrapped on the client: provision a tenant,
|
|
|
278
298
|
manage its members and invitations, tighten its sign-in policy, bind its
|
|
279
299
|
identity provider, and set up its directory sync.
|
|
280
300
|
|
|
301
|
+
Some of this depends on the Account's plan: creating an organization, and
|
|
302
|
+
requiring a second factor or single sign-on in its policy. Where the plan
|
|
303
|
+
does not include one, the call is refused with `plan_feature_unavailable`,
|
|
304
|
+
and the error's `data.required_plan` names the plan that does. Everything
|
|
305
|
+
inside an organization that already exists works on every plan.
|
|
306
|
+
|
|
281
307
|
```ts
|
|
282
308
|
const acme = await canopy.organizations.create({ name: "Acme Corp" });
|
|
283
309
|
|
|
@@ -652,11 +678,12 @@ Writing a `fetch` call against a documented REST API is easy, and an LLM will do
|
|
|
652
678
|
**Zero runtime dependencies.**
|
|
653
679
|
The client is `fetch` and nothing else, so it runs unchanged on Node, in browsers, on Cloudflare Workers, and on Deno — and it adds no supply-chain surface to anything that installs it. CI fails if a runtime dependency appears.
|
|
654
680
|
|
|
655
|
-
##
|
|
681
|
+
## Learn more
|
|
656
682
|
|
|
657
|
-
[
|
|
658
|
-
|
|
659
|
-
|
|
683
|
+
- [SDKs and Libraries](https://canopy-io.com/docs/sdks-and-libraries)
|
|
684
|
+
- [Authorization caching](https://canopy-io.com/docs/authorization-caching)
|
|
685
|
+
- [API reference](https://canopy-io.com/docs/api-reference)
|
|
686
|
+
- [Changelog](./CHANGELOG.md): the package is pre-1.0, so a minor version may carry a breaking change. Read the entry before upgrading.
|
|
660
687
|
|
|
661
688
|
## License
|
|
662
689
|
|
package/dist/index.cjs
CHANGED
|
@@ -2467,9 +2467,16 @@ function decodeJsonSegment(segment, what) {
|
|
|
2467
2467
|
);
|
|
2468
2468
|
}
|
|
2469
2469
|
}
|
|
2470
|
+
function audienceList(audience) {
|
|
2471
|
+
if (audience === void 0) {
|
|
2472
|
+
return void 0;
|
|
2473
|
+
}
|
|
2474
|
+
const list = typeof audience === "string" ? [audience] : [...audience];
|
|
2475
|
+
return list.length > 0 ? list : void 0;
|
|
2476
|
+
}
|
|
2470
2477
|
var TokenVerifier = class {
|
|
2471
2478
|
issuer;
|
|
2472
|
-
|
|
2479
|
+
audiences;
|
|
2473
2480
|
serviceAudience;
|
|
2474
2481
|
jwksUri;
|
|
2475
2482
|
jwksCacheMaxAgeMs;
|
|
@@ -2489,7 +2496,7 @@ var TokenVerifier = class {
|
|
|
2489
2496
|
inFlight = null;
|
|
2490
2497
|
constructor(options = {}) {
|
|
2491
2498
|
this.issuer = resolveIssuer(options);
|
|
2492
|
-
this.
|
|
2499
|
+
this.audiences = audienceList(options.audience);
|
|
2493
2500
|
this.serviceAudience = options.serviceAudience;
|
|
2494
2501
|
this.jwksUri = options.jwksUri ?? `${this.issuer}/.well-known/jwks.json`;
|
|
2495
2502
|
this.jwksCacheMaxAgeMs = options.jwksCacheMaxAgeMs ?? DEFAULT_JWKS_CACHE_MAX_AGE_MS;
|
|
@@ -2659,19 +2666,20 @@ var TokenVerifier = class {
|
|
|
2659
2666
|
}
|
|
2660
2667
|
return;
|
|
2661
2668
|
}
|
|
2662
|
-
if (this.
|
|
2669
|
+
if (this.audiences === void 0) {
|
|
2663
2670
|
if (audiences.length > 0) {
|
|
2664
2671
|
throw new CanopyTokenError(
|
|
2665
2672
|
"token.audience_unverified",
|
|
2666
|
-
"Token carries an `aud` claim but the verifier has no `audience` configured. Set `audience` to your OAuth client id
|
|
2673
|
+
"Token carries an `aud` claim but the verifier has no `audience` configured. Set `audience` to your OAuth client id for Hosted Login tokens, to your Environment id for Direct API tokens, or to both, as a list, to accept either."
|
|
2667
2674
|
);
|
|
2668
2675
|
}
|
|
2669
2676
|
return;
|
|
2670
2677
|
}
|
|
2671
|
-
|
|
2678
|
+
const expected = this.audiences;
|
|
2679
|
+
if (!audiences.some((audience) => expected.includes(audience))) {
|
|
2672
2680
|
throw new CanopyTokenError(
|
|
2673
2681
|
"token.audience_mismatch",
|
|
2674
|
-
`Token audience does not include
|
|
2682
|
+
`Token audience does not include ${expected.map((audience) => `"${audience}"`).join(" or ")}.`
|
|
2675
2683
|
);
|
|
2676
2684
|
}
|
|
2677
2685
|
}
|