@canopy-io/node 0.19.0 → 0.20.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.d.cts CHANGED
@@ -1511,7 +1511,7 @@ interface paths {
1511
1511
  post: operations["ApiOrganizationsController_createOrganization"];
1512
1512
  /**
1513
1513
  * Delete every organization
1514
- * @description Deletes every live organization in the Environment the way the single delete does: memberships and every assignment beneath each organization are removed, pending invitations bound to the organization or its tree are revoked, and each organization is soft-deleted with its subtree. Member identities are untouched. This is the step before switching the container off. Responds `204 No Content`, requires the `hierarchy.manage` permission, and emits `organization.deleted_all` with the counts.
1514
+ * @description Deletes every live organization in the Environment the way the single delete does: memberships and every assignment beneath each organization are removed, pending invitations bound to the organization or its tree are revoked, and each organization is soft-deleted with its subtree. Member identities are untouched. This is the step before switching the container off, so unlike the other organization routes it does not require the organizations plan feature: an account that has moved to a plan without it can still empty the container and switch it off. Responds `204 No Content`, requires the `hierarchy.manage` permission, and emits `organization.deleted_all` with the counts.
1515
1515
  */
1516
1516
  delete: operations["ApiOrganizationsController_deleteAllOrganizations"];
1517
1517
  options?: never;
@@ -2995,6 +2995,30 @@ interface paths {
2995
2995
  patch: operations["ApiBrandingController_updateBranding"];
2996
2996
  trace?: never;
2997
2997
  };
2998
+ "/api/v1/token-claims": {
2999
+ parameters: {
3000
+ query?: never;
3001
+ header?: never;
3002
+ path?: never;
3003
+ cookie?: never;
3004
+ };
3005
+ /**
3006
+ * Get an Environment's custom token claims
3007
+ * @description Returns the custom claims the Environment adds to its identity tokens: for each, the claim's name, the stored fact it is read from (`source`) and the tokens it goes on (`access`, `id`), in the order they are added, with the Environment's `version` to send back as `If-Match`. An empty list means no custom claims.
3008
+ */
3009
+ get: operations["ApiTokenClaimsController_getTokenClaims"];
3010
+ /**
3011
+ * Replace an Environment's custom token claims
3012
+ * @description Replaces the custom claims the Environment adds to its identity tokens with the list sent; an empty list removes them all. Each entry names the claim, its `source` (`identity.metadata.<path>`, `organization.metadata.<path>`, or a built-in identity or organization field) and the tokens it goes on. At most 20 entries. Every access token minted after the save carries them, Hosted Login and the Direct API alike, and the ID token those marked `id`; a session picks the change up at its next refresh. A value missing for the person is left out of the token. Send the Environment's `version` in `If-Match` to refuse a stale save: a mismatch answers `409 version_mismatch`, and without the header the check is skipped. Emits `environment.token_claims_updated` with the list before and after.
3013
+ */
3014
+ put: operations["ApiTokenClaimsController_replaceTokenClaims"];
3015
+ post?: never;
3016
+ delete?: never;
3017
+ options?: never;
3018
+ head?: never;
3019
+ patch?: never;
3020
+ trace?: never;
3021
+ };
2998
3022
  "/api/v1/webhooks": {
2999
3023
  parameters: {
3000
3024
  query?: never;
@@ -5660,6 +5684,56 @@ interface components {
5660
5684
  /** @description Absolute https URL of the customer's privacy policy, linked as "Privacy" in the hosted pages' footer. Null hides it. */
5661
5685
  privacy_url?: string | null;
5662
5686
  };
5687
+ TokenClaimEntryResponseDto: {
5688
+ /**
5689
+ * @description The claim's name on the token: letters, digits, `_`, `-`, `.`, `:` and `/`, at most 64 characters. A name the JWT or OpenID Connect standards define, or one Canopy sets (`type`, the `*_id` and `*_slug` claims, `permissions`, anything starting `org_` or `mcp_`), is refused.
5690
+ * @example plan
5691
+ */
5692
+ claim: string;
5693
+ /**
5694
+ * @description Where the value comes from: `identity.metadata.<path>` or `organization.metadata.<path>` (dotted keys, at most 5), or one of `identity.email`, `identity.email_verified`, `identity.first_name`, `identity.last_name`, `identity.external_id`, `organization.name`, `organization.slug`, `organization.external_id`. An `organization.*` source reads the organization the session acts in.
5695
+ * @example identity.metadata.plan
5696
+ */
5697
+ source: string;
5698
+ /**
5699
+ * @description The tokens the claim goes on: `access`, `id`, or both. The ID token is issued by Hosted Login only.
5700
+ * @example [
5701
+ * "access",
5702
+ * "id"
5703
+ * ]
5704
+ */
5705
+ tokens: ("access" | "id")[];
5706
+ };
5707
+ TokenClaimsResponseDto: {
5708
+ /** @description The Environment's version. Send it as `If-Match` on the next `PUT` to refuse a stale save; any change to the Environment advances it. */
5709
+ version: number;
5710
+ /** @description The mapping, in the order claims are added to a token. Empty when the Environment adds none. */
5711
+ claims: components["schemas"]["TokenClaimEntryResponseDto"][];
5712
+ };
5713
+ TokenClaimEntryDto: {
5714
+ /**
5715
+ * @description The claim's name on the token: letters, digits, `_`, `-`, `.`, `:` and `/`, at most 64 characters. A name the JWT or OpenID Connect standards define, or one Canopy sets (`type`, the `*_id` and `*_slug` claims, `permissions`, anything starting `org_` or `mcp_`), is refused.
5716
+ * @example plan
5717
+ */
5718
+ claim: string;
5719
+ /**
5720
+ * @description Where the value comes from: `identity.metadata.<path>` or `organization.metadata.<path>` (dotted keys, at most 5), or one of `identity.email`, `identity.email_verified`, `identity.first_name`, `identity.last_name`, `identity.external_id`, `organization.name`, `organization.slug`, `organization.external_id`. An `organization.*` source reads the organization the session acts in.
5721
+ * @example identity.metadata.plan
5722
+ */
5723
+ source: string;
5724
+ /**
5725
+ * @description The tokens the claim goes on: `access`, `id`, or both. The ID token is issued by Hosted Login only.
5726
+ * @example [
5727
+ * "access",
5728
+ * "id"
5729
+ * ]
5730
+ */
5731
+ tokens: ("access" | "id")[];
5732
+ };
5733
+ ReplaceTokenClaimsDto: {
5734
+ /** @description The whole mapping, in the order claims are added to a token, at most 20 entries. An empty list removes every custom claim. */
5735
+ claims: components["schemas"]["TokenClaimEntryDto"][];
5736
+ };
5663
5737
  WebhookCreatedResponseDto: {
5664
5738
  id: string;
5665
5739
  /** @enum {string} */
@@ -5953,7 +6027,7 @@ interface components {
5953
6027
  */
5954
6028
  access_mode: "scoped" | "full_access";
5955
6029
  /** @description Permission scopes this key is authorized for, each one the platform offers (`GET .../api-keys/scopes`). Required and must be non-empty when `access_mode` is `scoped`. Must be omitted when `access_mode` is `full_access`. */
5956
- scopes?: ("hierarchy.view" | "hierarchy.manage" | "rbac.view_roles" | "rbac.manage_roles" | "rbac.view_assignments" | "rbac.manage_assignments" | "permissions.evaluate" | "deny.view" | "deny.manage" | "identity.view" | "identity.manage" | "api_key.view" | "api_key.manage" | "webhook.view" | "webhook.manage" | "oauth_client.view" | "oauth_client.manage" | "audit.view" | "branding.view" | "branding.manage")[];
6030
+ scopes?: ("hierarchy.view" | "hierarchy.manage" | "rbac.view_roles" | "rbac.manage_roles" | "rbac.view_assignments" | "rbac.manage_assignments" | "permissions.evaluate" | "deny.view" | "deny.manage" | "identity.view" | "identity.manage" | "api_key.view" | "api_key.manage" | "webhook.view" | "webhook.manage" | "oauth_client.view" | "oauth_client.manage" | "audit.view" | "branding.view" | "branding.manage" | "token_claims.view" | "token_claims.manage")[];
5957
6031
  /** @description Expiration date (ISO 8601). Omit for no expiration. */
5958
6032
  expires_at?: string;
5959
6033
  };
@@ -16160,7 +16234,7 @@ interface operations {
16160
16234
  "application/json": components["schemas"]["ErrorResponseDto"];
16161
16235
  };
16162
16236
  };
16163
- /** @description This token is not authorized for this endpoint (wrong principal type — e.g., admin token on identity-only endpoint, or vice versa) */
16237
+ /** @description The caller may not manage this organization, or an organization administrator signed in as an identity sets `metadata` or `external_id`, which only the developer's backend or a Console administrator sets (`organization.developer_field`). Also a caller without the permissions the route needs */
16164
16238
  403: {
16165
16239
  headers: {
16166
16240
  [name: string]: unknown;
@@ -16171,10 +16245,10 @@ interface operations {
16171
16245
  * "error": {
16172
16246
  * "statusCode": 403,
16173
16247
  * "code": null,
16174
- * "message": "This token is not authorized for this endpoint (wrong principal type — e.g., admin token on identity-only endpoint, or vice versa)",
16248
+ * "message": "The caller may not manage this organization, or an organization administrator signed in as an identity sets `metadata` or `external_id`, which only the developer's backend or a Console administrator sets (`organization.developer_field`). Also a caller without the permissions the route needs",
16175
16249
  * "timestamp": "2026-04-20T12:00:00.000Z",
16176
- * "path": "/api/v1/organizations",
16177
- * "method": "GET"
16250
+ * "path": "/api/v1/organizations/{id}",
16251
+ * "method": "PATCH"
16178
16252
  * }
16179
16253
  * }
16180
16254
  */
@@ -27755,6 +27829,204 @@ interface operations {
27755
27829
  };
27756
27830
  };
27757
27831
  };
27832
+ ApiTokenClaimsController_getTokenClaims: {
27833
+ parameters: {
27834
+ query?: never;
27835
+ header?: never;
27836
+ path?: never;
27837
+ cookie?: never;
27838
+ };
27839
+ requestBody?: never;
27840
+ responses: {
27841
+ /** @description The custom claims mapping */
27842
+ 200: {
27843
+ headers: {
27844
+ [name: string]: unknown;
27845
+ };
27846
+ content: {
27847
+ "application/json": {
27848
+ data: components["schemas"]["TokenClaimsResponseDto"];
27849
+ };
27850
+ };
27851
+ };
27852
+ /** @description The request sent both an `X-API-Key` and an `Authorization` header; send one */
27853
+ 400: {
27854
+ headers: {
27855
+ [name: string]: unknown;
27856
+ };
27857
+ content: {
27858
+ /**
27859
+ * @example {
27860
+ * "error": {
27861
+ * "statusCode": 400,
27862
+ * "code": null,
27863
+ * "message": "The request sent both an `X-API-Key` and an `Authorization` header; send one",
27864
+ * "timestamp": "2026-04-20T12:00:00.000Z",
27865
+ * "path": "/api/v1/token-claims",
27866
+ * "method": "GET"
27867
+ * }
27868
+ * }
27869
+ */
27870
+ "application/json": components["schemas"]["ErrorResponseDto"];
27871
+ };
27872
+ };
27873
+ /** @description Invalid or expired token */
27874
+ 401: {
27875
+ headers: {
27876
+ [name: string]: unknown;
27877
+ };
27878
+ content: {
27879
+ /**
27880
+ * @example {
27881
+ * "error": {
27882
+ * "statusCode": 401,
27883
+ * "code": null,
27884
+ * "message": "Invalid or expired token",
27885
+ * "timestamp": "2026-04-20T12:00:00.000Z",
27886
+ * "path": "/api/v1/token-claims",
27887
+ * "method": "GET"
27888
+ * }
27889
+ * }
27890
+ */
27891
+ "application/json": components["schemas"]["ErrorResponseDto"];
27892
+ };
27893
+ };
27894
+ /** @description The bearer token is not an admin or platform token, or the caller lacks the permission this operation checks: a scoped API key without that scope, an admin without the Account capability that covers it, or, for a node-scoped check, a node outside this Environment */
27895
+ 403: {
27896
+ headers: {
27897
+ [name: string]: unknown;
27898
+ };
27899
+ content: {
27900
+ /**
27901
+ * @example {
27902
+ * "error": {
27903
+ * "statusCode": 403,
27904
+ * "code": null,
27905
+ * "message": "The bearer token is not an admin or platform token, or the caller lacks the permission this operation checks: a scoped API key without that scope, an admin without the Account capability that covers it, or, for a node-scoped check, a node outside this Environment",
27906
+ * "timestamp": "2026-04-20T12:00:00.000Z",
27907
+ * "path": "/api/v1/token-claims",
27908
+ * "method": "GET"
27909
+ * }
27910
+ * }
27911
+ */
27912
+ "application/json": components["schemas"]["ErrorResponseDto"];
27913
+ };
27914
+ };
27915
+ };
27916
+ };
27917
+ ApiTokenClaimsController_replaceTokenClaims: {
27918
+ parameters: {
27919
+ query?: never;
27920
+ header?: {
27921
+ /** @description Optimistic-lock version of the resource. Send the `version` field returned on read; the server rejects with 409 if the row has changed since. */
27922
+ "If-Match"?: string;
27923
+ };
27924
+ path?: never;
27925
+ cookie?: never;
27926
+ };
27927
+ requestBody: {
27928
+ content: {
27929
+ "application/json": components["schemas"]["ReplaceTokenClaimsDto"];
27930
+ };
27931
+ };
27932
+ responses: {
27933
+ /** @description The custom claims mapping, as saved */
27934
+ 200: {
27935
+ headers: {
27936
+ [name: string]: unknown;
27937
+ };
27938
+ content: {
27939
+ "application/json": {
27940
+ data: components["schemas"]["TokenClaimsResponseDto"];
27941
+ };
27942
+ };
27943
+ };
27944
+ /** @description The request failed validation, or an entry is refused: a name the JWT or OpenID Connect standards or Canopy already set (`token_claims.reserved_name`), a source outside the allowed fields (`token_claims.source_invalid`), or a name twice on the same token (`token_claims.duplicate_name`), with `error.data` naming the entry's `index` and its `field`; or the request sent both an `X-API-Key` and an `Authorization` header */
27945
+ 400: {
27946
+ headers: {
27947
+ [name: string]: unknown;
27948
+ };
27949
+ content: {
27950
+ /**
27951
+ * @example {
27952
+ * "error": {
27953
+ * "statusCode": 400,
27954
+ * "code": null,
27955
+ * "message": "The request failed validation, or an entry is refused: a name the JWT or OpenID Connect standards or Canopy already set (`token_claims.reserved_name`), a source outside the allowed fields (`token_claims.source_invalid`), or a name twice on the same token (`token_claims.duplicate_name`), with `error.data` naming the entry's `index` and its `field`; or the request sent both an `X-API-Key` and an `Authorization` header",
27956
+ * "timestamp": "2026-04-20T12:00:00.000Z",
27957
+ * "path": "/api/v1/token-claims",
27958
+ * "method": "PUT"
27959
+ * }
27960
+ * }
27961
+ */
27962
+ "application/json": components["schemas"]["ErrorResponseDto"];
27963
+ };
27964
+ };
27965
+ /** @description Invalid or expired token */
27966
+ 401: {
27967
+ headers: {
27968
+ [name: string]: unknown;
27969
+ };
27970
+ content: {
27971
+ /**
27972
+ * @example {
27973
+ * "error": {
27974
+ * "statusCode": 401,
27975
+ * "code": null,
27976
+ * "message": "Invalid or expired token",
27977
+ * "timestamp": "2026-04-20T12:00:00.000Z",
27978
+ * "path": "/api/v1/token-claims",
27979
+ * "method": "GET"
27980
+ * }
27981
+ * }
27982
+ */
27983
+ "application/json": components["schemas"]["ErrorResponseDto"];
27984
+ };
27985
+ };
27986
+ /** @description The bearer token is not an admin or platform token, or the caller lacks the permission this operation checks: a scoped API key without that scope, an admin without the Account capability that covers it, or, for a node-scoped check, a node outside this Environment */
27987
+ 403: {
27988
+ headers: {
27989
+ [name: string]: unknown;
27990
+ };
27991
+ content: {
27992
+ /**
27993
+ * @example {
27994
+ * "error": {
27995
+ * "statusCode": 403,
27996
+ * "code": null,
27997
+ * "message": "The bearer token is not an admin or platform token, or the caller lacks the permission this operation checks: a scoped API key without that scope, an admin without the Account capability that covers it, or, for a node-scoped check, a node outside this Environment",
27998
+ * "timestamp": "2026-04-20T12:00:00.000Z",
27999
+ * "path": "/api/v1/token-claims",
28000
+ * "method": "GET"
28001
+ * }
28002
+ * }
28003
+ */
28004
+ "application/json": components["schemas"]["ErrorResponseDto"];
28005
+ };
28006
+ };
28007
+ /** @description The Environment changed since the version named in `If-Match` was read (`version_mismatch`); the current mapping is in `error.data.current` */
28008
+ 409: {
28009
+ headers: {
28010
+ [name: string]: unknown;
28011
+ };
28012
+ content: {
28013
+ /**
28014
+ * @example {
28015
+ * "error": {
28016
+ * "statusCode": 409,
28017
+ * "code": null,
28018
+ * "message": "The Environment changed since the version named in `If-Match` was read (`version_mismatch`); the current mapping is in `error.data.current`",
28019
+ * "timestamp": "2026-04-20T12:00:00.000Z",
28020
+ * "path": "/api/v1/token-claims",
28021
+ * "method": "PUT"
28022
+ * }
28023
+ * }
28024
+ */
28025
+ "application/json": components["schemas"]["ErrorResponseDto"];
28026
+ };
28027
+ };
28028
+ };
28029
+ };
27758
28030
  ApiWebhooksController_list: {
27759
28031
  parameters: {
27760
28032
  query?: {
@@ -31734,7 +32006,10 @@ interface TokenVerifierOptions {
31734
32006
  * The claims Canopy puts in an access token.
31735
32007
  *
31736
32008
  * Named claims are the ones the API guarantees; the index signature keeps
31737
- * anything added later reachable without a version bump.
32009
+ * anything added later reachable without a version bump. The Environment's
32010
+ * custom claims (a `plan` copied from the identity's metadata, say) arrive
32011
+ * through it too; name them to {@link TokenVerifier.verify} to read them
32012
+ * typed.
31738
32013
  */
31739
32014
  interface CanopyTokenClaims {
31740
32015
  /**
@@ -31806,6 +32081,14 @@ interface CanopyTokenClaims {
31806
32081
  * the session is inside an organization.
31807
32082
  */
31808
32083
  org_scope?: "all";
32084
+ /**
32085
+ * True when the Environment's custom claims did not all fit on this token:
32086
+ * they are added in the mapping's order within a size limit, and the ones
32087
+ * past it are left out. A missing custom claim is then "unknown", not
32088
+ * "not set"; read it from the API (the identity's or organization's
32089
+ * metadata) instead of treating the token as complete.
32090
+ */
32091
+ custom_claims_overflow?: boolean;
31809
32092
  [claim: string]: unknown;
31810
32093
  }
31811
32094
  /** What one call to {@link TokenVerifier.verify} may widen. */
@@ -31886,8 +32169,14 @@ declare class TokenVerifier {
31886
32169
  *
31887
32170
  * Order matters: the signature is checked before any claim is believed, so
31888
32171
  * nothing downstream ever reads an unverified payload.
32172
+ *
32173
+ * `TCustom` names the Environment's custom claims, so they read typed off
32174
+ * the result: `verify<{ plan?: "free" | "pro" }>(token)`. It is a
32175
+ * declaration, not a check: a custom claim is absent when its value is not
32176
+ * stored, or when it did not fit (`custom_claims_overflow`), so keep each
32177
+ * one optional.
31889
32178
  */
31890
- verify(token: string, options?: VerifyCallOptions): Promise<CanopyTokenClaims>;
32179
+ verify<TCustom extends object = object>(token: string, options?: VerifyCallOptions): Promise<CanopyTokenClaims & TCustom>;
31891
32180
  /** Everything checked after the signature is known good. */
31892
32181
  private assertClaims;
31893
32182
  /**