UNPKG

@anthropic-ai/sdk

Version:
254 lines • 11.2 kB
import { APIResource } from "../../../core/resource.mjs"; import { BadRequestError, PermissionDeniedError } from "../../../core/error.mjs"; import { Page } from "../../../core/pagination.mjs"; import { buildHeaders } from "../../../internal/headers.mjs"; import { startApiCallSpan } from "../../../internal/tracing.mjs"; import { path } from "../../../internal/utils/path.mjs"; /** * The member is the organization's primary owner, whom no API key or token can * sign out. */ export var BetaCannotSignOutPrimaryOwnerError = /* @__PURE__ */ (() => { /** * The member is the organization's primary owner, whom no API key or token can * sign out. */ class BetaCannotSignOutPrimaryOwnerError extends BadRequestError { } /** @internal */ BetaCannotSignOutPrimaryOwnerError._errorName = 'BetaCannotSignOutPrimaryOwnerError'; return BetaCannotSignOutPrimaryOwnerError; })(); /** * The member is the user the API key or token belongs to. */ export var BetaCannotSignOutSelfError = /* @__PURE__ */ (() => { /** * The member is the user the API key or token belongs to. */ class BetaCannotSignOutSelfError extends BadRequestError { } /** @internal */ BetaCannotSignOutSelfError._errorName = 'BetaCannotSignOutSelfError'; return BetaCannotSignOutSelfError; })(); /** * The member has the `managed` role, and this API key or token cannot sign them * out. The error message says which keys and tokens can. */ export var BetaCannotSignOutManagedMemberError = /* @__PURE__ */ (() => { /** * The member has the `managed` role, and this API key or token cannot sign them * out. The error message says which keys and tokens can. */ class BetaCannotSignOutManagedMemberError extends PermissionDeniedError { } /** @internal */ BetaCannotSignOutManagedMemberError._errorName = 'BetaCannotSignOutManagedMemberError'; return BetaCannotSignOutManagedMemberError; })(); /** * The member is a membership admin, and the person the API key or token belongs to * is not allowed to sign out membership admins. */ export var BetaCannotSignOutMembershipAdminError = /* @__PURE__ */ (() => { /** * The member is a membership admin, and the person the API key or token belongs to * is not allowed to sign out membership admins. */ class BetaCannotSignOutMembershipAdminError extends PermissionDeniedError { } /** @internal */ BetaCannotSignOutMembershipAdminError._errorName = 'BetaCannotSignOutMembershipAdminError'; return BetaCannotSignOutMembershipAdminError; })(); /** * The member is an owner or has owner permissions, and this API key or token * cannot sign them out. In a Claude Enterprise organization, an API key with the * `write:members` scope can. */ export var BetaCannotSignOutOwnerError = /* @__PURE__ */ (() => { /** * The member is an owner or has owner permissions, and this API key or token * cannot sign them out. In a Claude Enterprise organization, an API key with the * `write:members` scope can. */ class BetaCannotSignOutOwnerError extends PermissionDeniedError { } /** @internal */ BetaCannotSignOutOwnerError._errorName = 'BetaCannotSignOutOwnerError'; return BetaCannotSignOutOwnerError; })(); /** * This OAuth token cannot sign out a membership admin or a member whose roles * grant owner, user management, or identity and access management. */ export var BetaCannotSignOutPrivilegedMemberError = /* @__PURE__ */ (() => { /** * This OAuth token cannot sign out a membership admin or a member whose roles * grant owner, user management, or identity and access management. */ class BetaCannotSignOutPrivilegedMemberError extends PermissionDeniedError { } /** @internal */ BetaCannotSignOutPrivilegedMemberError._errorName = 'BetaCannotSignOutPrivilegedMemberError'; return BetaCannotSignOutPrivilegedMemberError; })(); export var Users = /* @__PURE__ */ (() => { class Users extends APIResource { /** * Retrieve a member of the organization by user ID. * * @example * ```ts * const betaOrganizationUser = * await client.beta.organization.users.retrieve('user_id'); * ``` */ retrieve(userID, options) { return this._client.get(path `/v1/organizations/users/${userID}`, { ...options, __qualifiers: { beta: 'true' }, __span: startApiCallSpan(this._client, 'anthropic.organization.users.retrieve', options, { route: '/v1/organizations/users/{user_id}', attributes: { 'anthropic.organization.user.id': userID }, }), }); } /** * Update a member's organization role. * * @throws {SandboxEgressRestrictedError} * * @example * ```ts * const betaOrganizationUser = * await client.beta.organization.users.update('user_id', { * role: 'user', * }); * ``` */ update(userID, body, options) { return this._client.post(path `/v1/organizations/users/${userID}`, { body, ...options, __qualifiers: { beta: 'true' }, __span: startApiCallSpan(this._client, 'anthropic.organization.users.update', options, { route: '/v1/organizations/users/{user_id}', attributes: { 'anthropic.organization.user.id': userID }, }), }); } /** * List the organization's members. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const betaOrganizationUser of client.beta.organization.users.list()) { * // ... * } * ``` */ list(query = {}, options) { return this._client.getAPIList('/v1/organizations/users', (Page), { query, ...options, __qualifiers: { beta: 'true' }, __span: startApiCallSpan(this._client, 'anthropic.organization.users.list', options, { route: '/v1/organizations/users', queryParams: ['after_id', 'before_id', 'email', 'limit', 'roles'], }), }); } /** * Remove a member from the organization. * * @throws {CannotRemoveLastMemberError} * @throws {SandboxEgressRestrictedError} * @throws {ConcurrentMembershipChangeError} * * @example * ```ts * const user = await client.beta.organization.users.remove( * 'user_id', * ); * ``` */ remove(userID, options) { return this._client.delete(path `/v1/organizations/users/${userID}`, { ...options, __qualifiers: { beta: 'true' }, __span: startApiCallSpan(this._client, 'anthropic.organization.users.remove', options, { route: '/v1/organizations/users/{user_id}', attributes: { 'anthropic.organization.user.id': userID }, }), }); } /** * Sign a member out of Claude everywhere, without removing them from the * organization. This ends their sign-in sessions and removes their trusted devices * wherever they use Claude, including other organizations and individual plans. It * also ends the OAuth tokens issued to them for this organization, so apps such as * Claude Code must sign in again. * * A token can take up to an hour to stop working, though it almost always stops at * once. The member keeps their role and can sign in again right away. To keep them * out, remove them from the organization or, if your organization uses single * sign-on, block them in your identity provider. Signing out does not end API * keys, OAuth tokens that were not issued for this organization, or the member's * Claude Code cloud sessions and routines. * * You cannot sign out the organization's primary owner or the person your API key * or token acts for, and a request to sign out another owner, a member with owner * permissions, or a membership admin may be refused. A refused request returns a * `400` or `403` error that says why. If the request returns `503`, send it again * to finish; anything already ended stays ended. * * Every request must include the beta header * `anthropic-beta: admin-user-sign-out-2026-10-08`. A request without it returns * `400`. Sign-out is in beta for Claude Enterprise organizations. In an * organization where it is not enabled, a request returns `400` with `error_code` * `organization_not_enrolled_in_beta`. In a Claude Enterprise organization, an API * key needs the `write:members` scope; a key without it gets `403`. * * @throws {BetaCannotSignOutPrimaryOwnerError} * @throws {BetaCannotSignOutSelfError} * @throws {BetaOrganizationNotEnrolledInBetaError} * @throws {BetaCannotSignOutManagedMemberError} * @throws {BetaCannotSignOutMembershipAdminError} * @throws {BetaCannotSignOutOwnerError} * @throws {BetaCannotSignOutPrivilegedMemberError} * @throws {SandboxEgressRestrictedError} * * @example * ```ts * const betaOrganizationUser = * await client.beta.organization.users.signOut('user_id'); * ``` */ signOut(userID, params = {}, options) { const { betas } = params ?? {}; return this._client.post(path `/v1/organizations/users/${userID}/sign_out`, { ...options, headers: buildHeaders([ { 'anthropic-beta': [...(betas ?? []), 'admin-user-sign-out-2026-10-08'].toString() }, options?.headers, ]), __qualifiers: { beta: 'true' }, __span: startApiCallSpan(this._client, 'anthropic.organization.users.sign_out', options, { route: '/v1/organizations/users/{user_id}/sign_out', attributes: { 'anthropic.organization.user.id': userID }, }), }); } } Users.BetaCannotSignOutPrimaryOwnerError = BetaCannotSignOutPrimaryOwnerError; Users.BetaCannotSignOutSelfError = BetaCannotSignOutSelfError; Users.BetaCannotSignOutManagedMemberError = BetaCannotSignOutManagedMemberError; Users.BetaCannotSignOutMembershipAdminError = BetaCannotSignOutMembershipAdminError; Users.BetaCannotSignOutOwnerError = BetaCannotSignOutOwnerError; Users.BetaCannotSignOutPrivilegedMemberError = BetaCannotSignOutPrivilegedMemberError; return Users; })(); //# sourceMappingURL=users.mjs.map