@canopy-io/node 0.19.0 → 0.21.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 +8 -0
- package/dist/index.cjs +12 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23190 -9294
- package/dist/index.d.ts +23190 -9294
- package/dist/index.js +12 -0
- 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.21.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a7fda0b: An `environmentId` option on the client sends `X-Canopy-Environment`, so an account API key can reach the routes that act in an Environment; `RequestOptions.environmentId` names another Environment for one call, or `null` none. The generated types cover the management API: Applications and Environments with their settings, single sign-on, the auth domain and SCIM, administrator roles, grants and administrators, billing reads, the Account and account webhooks (298 operations, up from 201). The skill's choosing, node and mistakes references say which key goes where and how to provision an Environment with an account key.
|
|
8
|
+
|
|
9
|
+
## 0.20.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 1326269: `TokenVerifier.verify<TCustom>()` returns `CanopyTokenClaims & TCustom`, so an Environment's custom claims (a `plan` mapped from metadata, say) read typed off the verified token: `verify<{ plan?: "free" | "pro" }>(token)`. `custom_claims_overflow` is named on the claims: true when the mapped claims did not all fit, in which case a missing one is unknown rather than unset. The generated types cover `GET` and `PUT /api/v1/token-claims`, the Environment's mapping (`token_claims.view` / `token_claims.manage`).
|
|
14
|
+
|
|
3
15
|
## 0.19.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -216,6 +216,14 @@ Tokens also carry `amr`, how the session was proven (`pwd`, `otp` or `sso`,
|
|
|
216
216
|
plus `mfa` once a second factor was verified), so a backend can insist on
|
|
217
217
|
`claims.amr?.includes("mfa")` before a sensitive action.
|
|
218
218
|
|
|
219
|
+
An Environment can map custom claims onto the token (a `plan` copied from the
|
|
220
|
+
identity's or organization's metadata). Name them to `verify` to read them
|
|
221
|
+
typed, each optional: `verifier.verify<{ plan?: "free" | "pro" }>(token)`. A
|
|
222
|
+
value that is not stored is left off the token, and so is one that did not fit
|
|
223
|
+
the token's size limit, which `claims.custom_claims_overflow` reports; treat an
|
|
224
|
+
absent claim as not set, and read the value from the API when the token says
|
|
225
|
+
it overflowed.
|
|
226
|
+
|
|
219
227
|
The organizations themselves are wrapped on the client: provision a tenant,
|
|
220
228
|
manage its members and invitations, tighten its sign-in policy, bind its
|
|
221
229
|
identity provider, and set up its directory sync.
|
package/dist/index.cjs
CHANGED
|
@@ -119,6 +119,7 @@ var CanopyClient = class {
|
|
|
119
119
|
maxBackoffMs;
|
|
120
120
|
authHeaders;
|
|
121
121
|
extraHeaders;
|
|
122
|
+
environmentId;
|
|
122
123
|
fetchImpl;
|
|
123
124
|
constructor(options = {}) {
|
|
124
125
|
if (!options.apiKey && !options.accessToken) {
|
|
@@ -131,6 +132,7 @@ var CanopyClient = class {
|
|
|
131
132
|
this.maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
132
133
|
this.maxBackoffMs = options.maxBackoffMs ?? DEFAULT_MAX_BACKOFF_MS;
|
|
133
134
|
this.extraHeaders = options.headers ?? {};
|
|
135
|
+
this.environmentId = options.environmentId;
|
|
134
136
|
this.fetchImpl = options.fetch ?? globalThis.fetch;
|
|
135
137
|
if (typeof this.fetchImpl !== "function") {
|
|
136
138
|
throw new TypeError(
|
|
@@ -264,6 +266,10 @@ var CanopyClient = class {
|
|
|
264
266
|
if (options.body !== void 0) {
|
|
265
267
|
headers["Content-Type"] = "application/json";
|
|
266
268
|
}
|
|
269
|
+
const environmentId = options.environmentId === void 0 ? this.environmentId : options.environmentId;
|
|
270
|
+
if (environmentId) {
|
|
271
|
+
headers["X-Canopy-Environment"] = environmentId;
|
|
272
|
+
}
|
|
267
273
|
Object.assign(headers, options.headers, this.authHeaders);
|
|
268
274
|
const init = { method, headers, signal: controller.signal };
|
|
269
275
|
if (options.body !== void 0) {
|
|
@@ -2319,6 +2325,12 @@ var TokenVerifier = class {
|
|
|
2319
2325
|
*
|
|
2320
2326
|
* Order matters: the signature is checked before any claim is believed, so
|
|
2321
2327
|
* nothing downstream ever reads an unverified payload.
|
|
2328
|
+
*
|
|
2329
|
+
* `TCustom` names the Environment's custom claims, so they read typed off
|
|
2330
|
+
* the result: `verify<{ plan?: "free" | "pro" }>(token)`. It is a
|
|
2331
|
+
* declaration, not a check: a custom claim is absent when its value is not
|
|
2332
|
+
* stored, or when it did not fit (`custom_claims_overflow`), so keep each
|
|
2333
|
+
* one optional.
|
|
2322
2334
|
*/
|
|
2323
2335
|
async verify(token, options = {}) {
|
|
2324
2336
|
const parts = token.split(".");
|