Skip to content
Clone
9362a10
3889 lines 106.4 KB
/**
* Generated by orval 🍺
* Do not edit manually.
* auth
* 认证与账号服务:工作量证明、口令与验证码登录、二次验证、注册、口令重置、访问令牌与 SSH 公钥。
* OpenAPI spec version: 1.0.0
*/
import type {
AccessTokenCreateRequest,
AddMemberBody,
AppTokenRequest,
AssignRoleBody,
AuthAccessTokenListParams,
AuthOrganizationBanListParams,
AuthOrganizationDeleteParams,
AuthOrganizationInviteListParams,
AuthOrganizationMemberListParams,
AuthOrganizationMemberRemoveParams,
AuthSshKeyListParams,
BanMemberBody,
CheckPermissionBody,
CreateInviteBody,
CreateOrganizationBody,
CreateRoleBody,
EnvelopeAccessTokenCreateResponse,
EnvelopeAppTokenResponse,
EnvelopeBool,
EnvelopeChallengeResponse,
EnvelopeCreateInviteResponse,
EnvelopeHealthResponse,
EnvelopeLoginCodeResponse,
EnvelopeLogoutResponse,
EnvelopeMeResponse,
EnvelopeMemberSummary,
EnvelopeNoData,
EnvelopeOrganizationSummary,
EnvelopePasswordResetConfirmResponse,
EnvelopePasswordResetResponse,
EnvelopePermissionCheck,
EnvelopeReadinessResponse,
EnvelopeRedeemInviteResponse,
EnvelopeRegisterCodeResponse,
EnvelopeRoleSummary,
EnvelopeSshKeySummary,
EnvelopeTokenResponse,
EnvelopeUserLoginResponse,
EnvelopeUserRegisterResponse,
EnvelopeVecAccessTokenSummary,
EnvelopeVecInviteSummary,
EnvelopeVecMemberSummary,
EnvelopeVecOrganizationSummary,
EnvelopeVecRoleSummary,
EnvelopeVecSshKeySummary,
EnvelopeVecString,
LoginCodeRequest,
LoginCodeVerifyRequest,
LoginVerifyRequest,
PasswordResetConfirmRequest,
PasswordResetRequest,
ReasonBody,
RedeemInviteBody,
RegisterCodeRequest,
SetMemberRoleBody,
SetRolePermissionsBody,
SshKeyAddRequest,
TokenRequest,
TransferBody,
UpdateBanBody,
UpdateMemberBody,
UpdateOrganizationBody,
UpdateRoleBody,
UserLoginRequest,
UserRegisterRequest,
} from "./auth.schemas";
import { authClient } from "../../lib/jwtmanager/http";
export type authAccessTokenListResponse200 = {
data: EnvelopeVecAccessTokenSummary;
status: 200;
};
export type authAccessTokenListResponse401 = {
data: EnvelopeNoData;
status: 401;
};
export type authAccessTokenListResponse500 = {
data: EnvelopeNoData;
status: 500;
};
export type authAccessTokenListResponseSuccess =
authAccessTokenListResponse200 & {
headers: Headers;
};
export type authAccessTokenListResponseError = (
authAccessTokenListResponse401 | authAccessTokenListResponse500
) & {
headers: Headers;
};
export type authAccessTokenListResponse =
authAccessTokenListResponseSuccess | authAccessTokenListResponseError;
export const getAuthAccessTokenListUrl = (
params?: AuthAccessTokenListParams,
) => {
const normalizedParams = new URLSearchParams();
Object.entries(params || {}).forEach(([key, value]) => {
if (value !== undefined) {
normalizedParams.append(key, value === null ? "null" : String(value));
}
});
const stringifiedParams = normalizedParams.toString();
return stringifiedParams.length > 0
? `/api/v1/oauth/access-tokens?${stringifiedParams}`
: `/api/v1/oauth/access-tokens`;
};
/**
* 按创建时间倒序返回当前账号的令牌摘要,只给指纹与状态,不回吐令牌原文。分页参数由 `page` / `page_size` 控制。查询串不是合法分页参数或路径/方法不匹配时返回 400 / 404 由 actix-web 直接给出。
* @summary 列示访问令牌
*/
export const authAccessTokenList = async (
params?: AuthAccessTokenListParams,
options?: Parameters<typeof authClient>[1],
): Promise<authAccessTokenListResponse> => {
return authClient<authAccessTokenListResponse>(
getAuthAccessTokenListUrl(params),
{
...options,
method: "GET",
},
);
};
export type authAccessTokenCreateResponse200 = {
data: EnvelopeAccessTokenCreateResponse;
status: 200;
};
export type authAccessTokenCreateResponse400 = {
data: EnvelopeNoData;
status: 400;
};
export type authAccessTokenCreateResponse401 = {
data: EnvelopeNoData;
status: 401;
};
export type authAccessTokenCreateResponse429 = {
data: EnvelopeNoData;
status: 429;
};
export type authAccessTokenCreateResponse500 = {
data: EnvelopeNoData;
status: 500;
};
export type authAccessTokenCreateResponseSuccess =
authAccessTokenCreateResponse200 & {
headers: Headers;
};
export type authAccessTokenCreateResponseError = (
| authAccessTokenCreateResponse400
| authAccessTokenCreateResponse401
| authAccessTokenCreateResponse429
| authAccessTokenCreateResponse500
) & {
headers: Headers;
};
export type authAccessTokenCreateResponse =
authAccessTokenCreateResponseSuccess | authAccessTokenCreateResponseError;
export const getAuthAccessTokenCreateUrl = () => {
return `/api/v1/oauth/access-tokens`;
};
/**
* 名称 1~64 字符、备注最长 255 字符,`scope` 必须全部命中白名单(最多 32 项),`expires_in_secs` 取值 60 ~ 31536000(不填表示长期有效)。同一账号未吊销的令牌上限 50 个。签发成功记 `AccessKeyAdded` 审计事件。
* @summary 签发访问令牌
*/
export const authAccessTokenCreate = async (
accessTokenCreateRequest: AccessTokenCreateRequest,
options?: Parameters<typeof authClient>[1],
): Promise<authAccessTokenCreateResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authAccessTokenCreateResponse>(
getAuthAccessTokenCreateUrl(),
{
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(accessTokenCreateRequest),
},
);
};
export type authAccessTokenRevokeResponse200 = {
data: EnvelopeNoData;
status: 200;
};
export type authAccessTokenRevokeResponse401 = {
data: EnvelopeNoData;
status: 401;
};
export type authAccessTokenRevokeResponse500 = {
data: EnvelopeNoData;
status: 500;
};
export type authAccessTokenRevokeResponseSuccess =
authAccessTokenRevokeResponse200 & {
headers: Headers;
};
export type authAccessTokenRevokeResponseError = (
authAccessTokenRevokeResponse401 | authAccessTokenRevokeResponse500
) & {
headers: Headers;
};
export type authAccessTokenRevokeResponse =
authAccessTokenRevokeResponseSuccess | authAccessTokenRevokeResponseError;
export const getAuthAccessTokenRevokeUrl = (tokenId: string) => {
return `/api/v1/oauth/access-tokens/${tokenId}`;
};
/**
* 把令牌标记为已吊销,记录保留不硬删;重复调用幂等。令牌不存在或不属于当前账号返回 `access_token_not_found`(按 `errors.rs` 的归类为 401)。吊销成功记 `AccessKeyRemoved` 审计事件。
* @summary 吊销访问令牌
*/
export const authAccessTokenRevoke = async (
tokenId: string,
options?: Parameters<typeof authClient>[1],
): Promise<authAccessTokenRevokeResponse> => {
return authClient<authAccessTokenRevokeResponse>(
getAuthAccessTokenRevokeUrl(tokenId),
{
...options,
method: "DELETE",
},
);
};
export type authAppTokenIssueResponse200 = {
data: EnvelopeAppTokenResponse;
status: 200;
};
export type authAppTokenIssueResponse400 = {
data: EnvelopeNoData;
status: 400;
};
export type authAppTokenIssueResponse401 = {
data: EnvelopeNoData;
status: 401;
};
export type authAppTokenIssueResponse404 = {
data: EnvelopeNoData;
status: 404;
};
export type authAppTokenIssueResponse500 = {
data: EnvelopeNoData;
status: 500;
};
export type authAppTokenIssueResponse503 = {
data: EnvelopeNoData;
status: 503;
};
export type authAppTokenIssueResponseSuccess = authAppTokenIssueResponse200 & {
headers: Headers;
};
export type authAppTokenIssueResponseError = (
| authAppTokenIssueResponse400
| authAppTokenIssueResponse401
| authAppTokenIssueResponse404
| authAppTokenIssueResponse500
| authAppTokenIssueResponse503
) & {
headers: Headers;
};
export type authAppTokenIssueResponse =
authAppTokenIssueResponseSuccess | authAppTokenIssueResponseError;
export const getAuthAppTokenIssueUrl = () => {
return `/api/v1/oauth/app-tokens`;
};
/**
* 认证中心用 Ed25519 私钥签发 JWT(`alg=EdDSA`),`aud` 为目标 app 的 audience,`client_id` 为 app 标识。服务通过内部 gRPC authority 验签。`ttl_seconds` 取值 1 ~ 3600,不填或填 0 用默认 900。会话未绑定账号返回 `unauthenticated`(401);app 未在 `apps` 清单里返回 `app_not_found`(404);私钥未配置返回 `unavailable`(503)。
* @summary 签发内部应用令牌
*/
export const authAppTokenIssue = async (
appTokenRequest: AppTokenRequest,
options?: Parameters<typeof authClient>[1],
): Promise<authAppTokenIssueResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authAppTokenIssueResponse>(getAuthAppTokenIssueUrl(), {
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(appTokenRequest),
});
};
export type authChallengeResponse200 = {
data: EnvelopeChallengeResponse;
status: 200;
};
export type authChallengeResponse500 = {
data: EnvelopeNoData;
status: 500;
};
export type authChallengeResponseSuccess = authChallengeResponse200 & {
headers: Headers;
};
export type authChallengeResponseError = authChallengeResponse500 & {
headers: Headers;
};
export type authChallengeResponse =
authChallengeResponseSuccess | authChallengeResponseError;
export const getAuthChallengeUrl = () => {
return `/api/v1/oauth/challenge`;
};
/**
* 把挑战写进当前会话并返回。客户端需要为 `context` 找出一枚满足 `difficulty`(前导零比特数)的 nonce;`pow.v1` 算法与前端求解器一致。
* @summary 签发工作量证明挑战
*/
export const authChallenge = async (
options?: Parameters<typeof authClient>[1],
): Promise<authChallengeResponse> => {
return authClient<authChallengeResponse>(getAuthChallengeUrl(), {
...options,
method: "POST",
});
};
export type authLoginResponse200 = {
data: EnvelopeUserLoginResponse;
status: 200;
};
export type authLoginResponse400 = {
data: EnvelopeNoData;
status: 400;
};
export type authLoginResponse401 = {
data: EnvelopeNoData;
status: 401;
};
export type authLoginResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authLoginResponse429 = {
data: EnvelopeNoData;
status: 429;
};
export type authLoginResponse500 = {
data: EnvelopeNoData;
status: 500;
};
export type authLoginResponseSuccess = authLoginResponse200 & {
headers: Headers;
};
export type authLoginResponseError = (
| authLoginResponse400
| authLoginResponse401
| authLoginResponse403
| authLoginResponse429
| authLoginResponse500
) & {
headers: Headers;
};
export type authLoginResponse =
authLoginResponseSuccess | authLoginResponseError;
export const getAuthLoginUrl = () => {
return `/api/v1/oauth/login`;
};
/**
* 用口令登录。`identity` 可以是用户名、邮箱(大小写不敏感)或用户编号,`password_hash` 是客户端先算好的口令摘要,工作量证明的载荷必须是 `identity`。账号启用了多因子时返回 `mfa_required: true` 与 `challenge`,此时会话尚未绑定,需再调 `/api/v1/oauth/login/verify`。
* @summary 口令登录
*/
export const authLogin = async (
userLoginRequest: UserLoginRequest,
options?: Parameters<typeof authClient>[1],
): Promise<authLoginResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authLoginResponse>(getAuthLoginUrl(), {
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(userLoginRequest),
});
};
export type authLoginCodeResponse200 = {
data: EnvelopeLoginCodeResponse;
status: 200;
};
export type authLoginCodeResponse400 = {
data: EnvelopeNoData;
status: 400;
};
export type authLoginCodeResponse401 = {
data: EnvelopeNoData;
status: 401;
};
export type authLoginCodeResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authLoginCodeResponse429 = {
data: EnvelopeNoData;
status: 429;
};
export type authLoginCodeResponse500 = {
data: EnvelopeNoData;
status: 500;
};
export type authLoginCodeResponseSuccess = authLoginCodeResponse200 & {
headers: Headers;
};
export type authLoginCodeResponseError = (
| authLoginCodeResponse400
| authLoginCodeResponse401
| authLoginCodeResponse403
| authLoginCodeResponse429
| authLoginCodeResponse500
) & {
headers: Headers;
};
export type authLoginCodeResponse =
authLoginCodeResponseSuccess | authLoginCodeResponseError;
export const getAuthLoginCodeUrl = () => {
return `/api/v1/oauth/login/code`;
};
/**
* 向账号邮箱发送 6 位登录验证码,`expires_in_secs` 为有效期。工作量证明的载荷必须是 `email`。同一账号的发码间隔受 `email_code_rate_limit_secs` 限制。
* @summary 发送邮箱登录验证码
*/
export const authLoginCode = async (
loginCodeRequest: LoginCodeRequest,
options?: Parameters<typeof authClient>[1],
): Promise<authLoginCodeResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authLoginCodeResponse>(getAuthLoginCodeUrl(), {
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(loginCodeRequest),
});
};
export type authLoginCodeVerifyResponse200 = {
data: EnvelopeUserLoginResponse;
status: 200;
};
export type authLoginCodeVerifyResponse400 = {
data: EnvelopeNoData;
status: 400;
};
export type authLoginCodeVerifyResponse401 = {
data: EnvelopeNoData;
status: 401;
};
export type authLoginCodeVerifyResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authLoginCodeVerifyResponse429 = {
data: EnvelopeNoData;
status: 429;
};
export type authLoginCodeVerifyResponse500 = {
data: EnvelopeNoData;
status: 500;
};
export type authLoginCodeVerifyResponseSuccess =
authLoginCodeVerifyResponse200 & {
headers: Headers;
};
export type authLoginCodeVerifyResponseError = (
| authLoginCodeVerifyResponse400
| authLoginCodeVerifyResponse401
| authLoginCodeVerifyResponse403
| authLoginCodeVerifyResponse429
| authLoginCodeVerifyResponse500
) & {
headers: Headers;
};
export type authLoginCodeVerifyResponse =
authLoginCodeVerifyResponseSuccess | authLoginCodeVerifyResponseError;
export const getAuthLoginCodeVerifyUrl = () => {
return `/api/v1/oauth/login/code/verify`;
};
/**
* 用邮箱登录验证码换会话。工作量证明的载荷必须是 `email`。验证码一旦核对通过即作废,连续输错 `max_verify_attempts` 次后需重新申请。账号启用了多因子时返回 `mfa_required: true` 与 `challenge`。
* @summary 邮箱验证码换会话
*/
export const authLoginCodeVerify = async (
loginCodeVerifyRequest: LoginCodeVerifyRequest,
options?: Parameters<typeof authClient>[1],
): Promise<authLoginCodeVerifyResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authLoginCodeVerifyResponse>(getAuthLoginCodeVerifyUrl(), {
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(loginCodeVerifyRequest),
});
};
export type authLoginVerifyResponse200 = {
data: EnvelopeUserLoginResponse;
status: 200;
};
export type authLoginVerifyResponse400 = {
data: EnvelopeNoData;
status: 400;
};
export type authLoginVerifyResponse401 = {
data: EnvelopeNoData;
status: 401;
};
export type authLoginVerifyResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authLoginVerifyResponse429 = {
data: EnvelopeNoData;
status: 429;
};
export type authLoginVerifyResponse500 = {
data: EnvelopeNoData;
status: 500;
};
export type authLoginVerifyResponseSuccess = authLoginVerifyResponse200 & {
headers: Headers;
};
export type authLoginVerifyResponseError = (
| authLoginVerifyResponse400
| authLoginVerifyResponse401
| authLoginVerifyResponse403
| authLoginVerifyResponse429
| authLoginVerifyResponse500
) & {
headers: Headers;
};
export type authLoginVerifyResponse =
authLoginVerifyResponseSuccess | authLoginVerifyResponseError;
export const getAuthLoginVerifyUrl = () => {
return `/api/v1/oauth/login/verify`;
};
/**
* 用 6 位 TOTP 动态码或一枚未使用的恢复码完成二次验证并绑定会话。`challenge` 必须与 `/api/v1/oauth/login` 或 `/api/v1/oauth/login/code/verify` 返回的一致,挑战有效期 300 秒,同一动态码时间步不能重复使用,恢复码用掉即作废。
* @summary 二次验证换会话
*/
export const authLoginVerify = async (
loginVerifyRequest: LoginVerifyRequest,
options?: Parameters<typeof authClient>[1],
): Promise<authLoginVerifyResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authLoginVerifyResponse>(getAuthLoginVerifyUrl(), {
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(loginVerifyRequest),
});
};
export type authMeResponse200 = {
data: EnvelopeMeResponse;
status: 200;
};
export type authMeResponse401 = {
data: EnvelopeNoData;
status: 401;
};
export type authMeResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authMeResponse500 = {
data: EnvelopeNoData;
status: 500;
};
export type authMeResponseSuccess = authMeResponse200 & {
headers: Headers;
};
export type authMeResponseError = (
authMeResponse401 | authMeResponse403 | authMeResponse500
) & {
headers: Headers;
};
export type authMeResponse = authMeResponseSuccess | authMeResponseError;
export const getAuthMeUrl = () => {
return `/api/v1/oauth/me`;
};
/**
* 通过会话 Cookie 或 Bearer 访问令牌返回用户自述信息,含头像地址。Bearer 令牌需具备 profile、email、avatar 权限,并校验账号与会话状态。结果在服务端缓存 300 秒,每第 5 次访问回源刷新;登出与改密会主动失效该缓存。
* @summary 当前登录用户
*/
export const authMe = async (
options?: Parameters<typeof authClient>[1],
): Promise<authMeResponse> => {
return authClient<authMeResponse>(getAuthMeUrl(), {
...options,
method: "GET",
});
};
export type authPasswordResetRequestResponse200 = {
data: EnvelopePasswordResetResponse;
status: 200;
};
export type authPasswordResetRequestResponse400 = {
data: EnvelopeNoData;
status: 400;
};
export type authPasswordResetRequestResponse429 = {
data: EnvelopeNoData;
status: 429;
};
export type authPasswordResetRequestResponse500 = {
data: EnvelopeNoData;
status: 500;
};
export type authPasswordResetRequestResponseSuccess =
authPasswordResetRequestResponse200 & {
headers: Headers;
};
export type authPasswordResetRequestResponseError = (
| authPasswordResetRequestResponse400
| authPasswordResetRequestResponse429
| authPasswordResetRequestResponse500
) & {
headers: Headers;
};
export type authPasswordResetRequestResponse =
| authPasswordResetRequestResponseSuccess
| authPasswordResetRequestResponseError;
export const getAuthPasswordResetRequestUrl = () => {
return `/api/v1/oauth/password/reset`;
};
/**
* 校验工作量证明(payload = 邮箱的 UTF-8 字节)后,作废该用户其余未消费的重置令牌,签发新令牌(长度 `reset_token_bytes`,有效期 `reset_token_ttl_secs`),库内只存 `sha256_hex(token)` 且 `hash_key_id = "sha256-v1"`,同时把摘要写入缓存键 `auth:code:reset:{email}`,发信限流键 `auth:rate:reset:{email}`。
* @summary 申请密码重置
*/
export const authPasswordResetRequest = async (
passwordResetRequest: PasswordResetRequest,
options?: Parameters<typeof authClient>[1],
): Promise<authPasswordResetRequestResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authPasswordResetRequestResponse>(
getAuthPasswordResetRequestUrl(),
{
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(passwordResetRequest),
},
);
};
export type authPasswordResetResponse200 = {
data: EnvelopePasswordResetConfirmResponse;
status: 200;
};
export type authPasswordResetResponse400 = {
data: EnvelopeNoData;
status: 400;
};
export type authPasswordResetResponse429 = {
data: EnvelopeNoData;
status: 429;
};
export type authPasswordResetResponse500 = {
data: EnvelopeNoData;
status: 500;
};
export type authPasswordResetResponseSuccess = authPasswordResetResponse200 & {
headers: Headers;
};
export type authPasswordResetResponseError = (
| authPasswordResetResponse400
| authPasswordResetResponse429
| authPasswordResetResponse500
) & {
headers: Headers;
};
export type authPasswordResetResponse =
authPasswordResetResponseSuccess | authPasswordResetResponseError;
export const getAuthPasswordResetUrl = () => {
return `/api/v1/oauth/password/reset/confirm`;
};
/**
* 校验工作量证明(payload = `token` 的 UTF-8 字节)与缓存键 `auth:code:reset:{email}`(尝试上限 `max_verify_attempts`,错误计入 `invalid_email_code`)后,条件消费数据库令牌行(`consumed_at` 单次占用),Argon2 重哈希新口令,更新 `password_hash`/`password_updated_at`/`password_must_change`/`security_version + 1`,作废其余令牌并记 `PasswordChange` 审计事件。
* @summary 确认密码重置
*/
export const authPasswordReset = async (
passwordResetConfirmRequest: PasswordResetConfirmRequest,
options?: Parameters<typeof authClient>[1],
): Promise<authPasswordResetResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authPasswordResetResponse>(getAuthPasswordResetUrl(), {
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(passwordResetConfirmRequest),
});
};
export type authRegisterResponse200 = {
data: EnvelopeUserRegisterResponse;
status: 200;
};
export type authRegisterResponse400 = {
data: EnvelopeNoData;
status: 400;
};
export type authRegisterResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authRegisterResponse409 = {
data: EnvelopeNoData;
status: 409;
};
export type authRegisterResponse429 = {
data: EnvelopeNoData;
status: 429;
};
export type authRegisterResponse500 = {
data: EnvelopeNoData;
status: 500;
};
export type authRegisterResponseSuccess = authRegisterResponse200 & {
headers: Headers;
};
export type authRegisterResponseError = (
| authRegisterResponse400
| authRegisterResponse403
| authRegisterResponse409
| authRegisterResponse429
| authRegisterResponse500
) & {
headers: Headers;
};
export type authRegisterResponse =
authRegisterResponseSuccess | authRegisterResponseError;
export const getAuthRegisterUrl = () => {
return `/api/v1/oauth/register`;
};
/**
* 校验工作量证明(payload = 用户名的 UTF-8 字节)、用户名/展示名/出生日期/邮箱、邮箱验证码(键 `auth:code:register:{email}`,尝试上限 `max_verify_attempts`)后,Argon2 重哈希口令并创建用户与初始档案。成功后写会话(user_id、security_version、renew)并记审计事件。
* @summary 提交注册
*/
export const authRegister = async (
userRegisterRequest: UserRegisterRequest,
options?: Parameters<typeof authClient>[1],
): Promise<authRegisterResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authRegisterResponse>(getAuthRegisterUrl(), {
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(userRegisterRequest),
});
};
export type authRegisterCodeResponse200 = {
data: EnvelopeRegisterCodeResponse;
status: 200;
};
export type authRegisterCodeResponse400 = {
data: EnvelopeNoData;
status: 400;
};
export type authRegisterCodeResponse409 = {
data: EnvelopeNoData;
status: 409;
};
export type authRegisterCodeResponse429 = {
data: EnvelopeNoData;
status: 429;
};
export type authRegisterCodeResponse500 = {
data: EnvelopeNoData;
status: 500;
};
export type authRegisterCodeResponseSuccess = authRegisterCodeResponse200 & {
headers: Headers;
};
export type authRegisterCodeResponseError = (
| authRegisterCodeResponse400
| authRegisterCodeResponse409
| authRegisterCodeResponse429
| authRegisterCodeResponse500
) & {
headers: Headers;
};
export type authRegisterCodeResponse =
authRegisterCodeResponseSuccess | authRegisterCodeResponseError;
export const getAuthRegisterCodeUrl = () => {
return `/api/v1/oauth/register/code`;
};
/**
* 校验工作量证明(payload = 邮箱的 UTF-8 字节)与邮箱格式后,把 6 位验证码写入缓存并寄出。缓存键 `auth:code:register:{email}`,有效期由 `verify_code_ttl_secs` 决定,发码限流键 `auth:rate:register:{email}`。
* @summary 发送注册验证码
*/
export const authRegisterCode = async (
registerCodeRequest: RegisterCodeRequest,
options?: Parameters<typeof authClient>[1],
): Promise<authRegisterCodeResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authRegisterCodeResponse>(getAuthRegisterCodeUrl(), {
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(registerCodeRequest),
});
};
export type authLogoutResponse200 = {
data: EnvelopeLogoutResponse;
status: 200;
};
export type authLogoutResponse500 = {
data: EnvelopeNoData;
status: 500;
};
export type authLogoutResponseSuccess = authLogoutResponse200 & {
headers: Headers;
};
export type authLogoutResponseError = authLogoutResponse500 & {
headers: Headers;
};
export type authLogoutResponse =
authLogoutResponseSuccess | authLogoutResponseError;
export const getAuthLogoutUrl = () => {
return `/api/v1/oauth/session/logout`;
};
/**
* 销毁当前会话,并清掉该用户的 `/api/v1/oauth/me` 缓存。匿名调用同样成功,此时 `user_id` 为 `null`。
* @summary 登出
*/
export const authLogout = async (
options?: Parameters<typeof authClient>[1],
): Promise<authLogoutResponse> => {
return authClient<authLogoutResponse>(getAuthLogoutUrl(), {
...options,
method: "POST",
});
};
export type authTokenIssueResponse200 = {
data: EnvelopeTokenResponse;
status: 200;
};
export type authTokenIssueResponse400 = {
data: EnvelopeNoData;
status: 400;
};
export type authTokenIssueResponse401 = {
data: EnvelopeNoData;
status: 401;
};
export type authTokenIssueResponse404 = {
data: EnvelopeNoData;
status: 404;
};
export type authTokenIssueResponseSuccess = authTokenIssueResponse200 & {
headers: Headers;
};
export type authTokenIssueResponseError = (
| authTokenIssueResponse400
| authTokenIssueResponse401
| authTokenIssueResponse404
) & {
headers: Headers;
};
export type authTokenIssueResponse =
authTokenIssueResponseSuccess | authTokenIssueResponseError;
export const getAuthTokenIssueUrl = () => {
return `/api/v1/oauth/session/token`;
};
/**
* 认证中心用 Ed25519 私钥签发 JWT(`alg=EdDSA`),`aud` 固定为 `gitdata.ai`,`azp`(`app_id`)可选。服务通过内部 gRPC authority 验签。`ttl_seconds` 取值 1 ~ 3600,不填或填 0 用默认 900。
* @summary 用会话换取平台访问令牌
*/
export const authTokenIssue = async (
tokenRequest: TokenRequest,
options?: Parameters<typeof authClient>[1],
): Promise<authTokenIssueResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authTokenIssueResponse>(getAuthTokenIssueUrl(), {
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(tokenRequest),
});
};
export type authSshKeyListResponse200 = {
data: EnvelopeVecSshKeySummary;
status: 200;
};
export type authSshKeyListResponse401 = {
data: EnvelopeNoData;
status: 401;
};
export type authSshKeyListResponse500 = {
data: EnvelopeNoData;
status: 500;
};
export type authSshKeyListResponseSuccess = authSshKeyListResponse200 & {
headers: Headers;
};
export type authSshKeyListResponseError = (
authSshKeyListResponse401 | authSshKeyListResponse500
) & {
headers: Headers;
};
export type authSshKeyListResponse =
authSshKeyListResponseSuccess | authSshKeyListResponseError;
export const getAuthSshKeyListUrl = (params?: AuthSshKeyListParams) => {
const normalizedParams = new URLSearchParams();
Object.entries(params || {}).forEach(([key, value]) => {
if (value !== undefined) {
normalizedParams.append(key, value === null ? "null" : String(value));
}
});
const stringifiedParams = normalizedParams.toString();
return stringifiedParams.length > 0
? `/api/v1/oauth/ssh-keys?${stringifiedParams}`
: `/api/v1/oauth/ssh-keys`;
};
/**
* 按创建时间倒序返回当前账号的公钥,含已吊销与已过期的记录。分页参数由 `page` / `page_size` 控制。查询串不是合法分页参数时由 actix-web 直接返回 400。
* @summary 列示 SSH 公钥
*/
export const authSshKeyList = async (
params?: AuthSshKeyListParams,
options?: Parameters<typeof authClient>[1],
): Promise<authSshKeyListResponse> => {
return authClient<authSshKeyListResponse>(getAuthSshKeyListUrl(params), {
...options,
method: "GET",
});
};
export type authSshKeyAddResponse200 = {
data: EnvelopeSshKeySummary;
status: 200;
};
export type authSshKeyAddResponse400 = {
data: EnvelopeNoData;
status: 400;
};
export type authSshKeyAddResponse401 = {
data: EnvelopeNoData;
status: 401;
};
export type authSshKeyAddResponse409 = {
data: EnvelopeNoData;
status: 409;
};
export type authSshKeyAddResponse500 = {
data: EnvelopeNoData;
status: 500;
};
export type authSshKeyAddResponseSuccess = authSshKeyAddResponse200 & {
headers: Headers;
};
export type authSshKeyAddResponseError = (
| authSshKeyAddResponse400
| authSshKeyAddResponse401
| authSshKeyAddResponse409
| authSshKeyAddResponse500
) & {
headers: Headers;
};
export type authSshKeyAddResponse =
authSshKeyAddResponseSuccess | authSshKeyAddResponseError;
export const getAuthSshKeyAddUrl = () => {
return `/api/v1/oauth/ssh-keys`;
};
/**
* 名称 1~64 字符、备注最长 255 字符,公钥 32~8192 字节且必须是受支持的单行 OpenSSH 公钥,`expires_at` 必须晚于当前时间。重复公钥(指纹唯一)返回 `ssh_key_taken`。添加成功记 `PublicKeyAdded` 审计事件。
* @summary 添加 SSH 公钥
*/
export const authSshKeyAdd = async (
sshKeyAddRequest: SshKeyAddRequest,
options?: Parameters<typeof authClient>[1],
): Promise<authSshKeyAddResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authSshKeyAddResponse>(getAuthSshKeyAddUrl(), {
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(sshKeyAddRequest),
});
};
export type authSshKeyDeleteResponse200 = {
data: EnvelopeNoData;
status: 200;
};
export type authSshKeyDeleteResponse401 = {
data: EnvelopeNoData;
status: 401;
};
export type authSshKeyDeleteResponse404 = {
data: EnvelopeNoData;
status: 404;
};
export type authSshKeyDeleteResponse500 = {
data: EnvelopeNoData;
status: 500;
};
export type authSshKeyDeleteResponseSuccess = authSshKeyDeleteResponse200 & {
headers: Headers;
};
export type authSshKeyDeleteResponseError = (
| authSshKeyDeleteResponse401
| authSshKeyDeleteResponse404
| authSshKeyDeleteResponse500
) & {
headers: Headers;
};
export type authSshKeyDeleteResponse =
authSshKeyDeleteResponseSuccess | authSshKeyDeleteResponseError;
export const getAuthSshKeyDeleteUrl = (keyId: string) => {
return `/api/v1/oauth/ssh-keys/${keyId}`;
};
/**
* 把公钥标记为已吊销,记录保留不硬删;重复调用幂等。公钥不存在或不属于当前账号返回 `ssh_key_not_found`。吊销成功记 `PublicKeyRemoved` 审计事件,并递增 `security_version` 让该账号既有的访问令牌一并失效。`key_id` 不是合法 UUID 时由 actix-web 的路径提取器直接返回 400。
* @summary 吊销 SSH 公钥
*/
export const authSshKeyDelete = async (
keyId: string,
options?: Parameters<typeof authClient>[1],
): Promise<authSshKeyDeleteResponse> => {
return authClient<authSshKeyDeleteResponse>(getAuthSshKeyDeleteUrl(keyId), {
...options,
method: "DELETE",
});
};
export type authOrganizationListResponse200 = {
data: EnvelopeVecOrganizationSummary;
status: 200;
};
export type authOrganizationListResponse401 = {
data: EnvelopeNoData;
status: 401;
};
export type authOrganizationListResponseSuccess =
authOrganizationListResponse200 & {
headers: Headers;
};
export type authOrganizationListResponseError =
authOrganizationListResponse401 & {
headers: Headers;
};
export type authOrganizationListResponse =
authOrganizationListResponseSuccess | authOrganizationListResponseError;
export const getAuthOrganizationListUrl = () => {
return `/api/v1/organizations`;
};
/**
* 默认只返回 ACTIVE 组织;`include_archived=true` 时一并返回已归档组织。
* @summary 列示我加入的组织
*/
export const authOrganizationList = async (
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationListResponse> => {
return authClient<authOrganizationListResponse>(
getAuthOrganizationListUrl(),
{
...options,
method: "GET",
},
);
};
export type authOrganizationCreateResponse200 = {
data: EnvelopeOrganizationSummary;
status: 200;
};
export type authOrganizationCreateResponse401 = {
data: EnvelopeNoData;
status: 401;
};
export type authOrganizationCreateResponse409 = {
data: EnvelopeNoData;
status: 409;
};
export type authOrganizationCreateResponseSuccess =
authOrganizationCreateResponse200 & {
headers: Headers;
};
export type authOrganizationCreateResponseError = (
authOrganizationCreateResponse401 | authOrganizationCreateResponse409
) & {
headers: Headers;
};
export type authOrganizationCreateResponse =
authOrganizationCreateResponseSuccess | authOrganizationCreateResponseError;
export const getAuthOrganizationCreateUrl = () => {
return `/api/v1/organizations`;
};
/**
* 创建者自动成为 OWNER 并写入 owner/admin/member 三个内置角色。slug 全局唯一且只允许小写字母、数字与连字符。
* @summary 新建组织
*/
export const authOrganizationCreate = async (
createOrganizationBody: CreateOrganizationBody,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationCreateResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authOrganizationCreateResponse>(
getAuthOrganizationCreateUrl(),
{
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(createOrganizationBody),
},
);
};
export type authOrganizationInviteRedeemResponse200 = {
data: EnvelopeRedeemInviteResponse;
status: 200;
};
export type authOrganizationInviteRedeemResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationInviteRedeemResponse409 = {
data: EnvelopeNoData;
status: 409;
};
export type authOrganizationInviteRedeemResponseSuccess =
authOrganizationInviteRedeemResponse200 & {
headers: Headers;
};
export type authOrganizationInviteRedeemResponseError = (
| authOrganizationInviteRedeemResponse403
| authOrganizationInviteRedeemResponse409
) & {
headers: Headers;
};
export type authOrganizationInviteRedeemResponse =
| authOrganizationInviteRedeemResponseSuccess
| authOrganizationInviteRedeemResponseError;
export const getAuthOrganizationInviteRedeemUrl = () => {
return `/api/v1/organizations/invites/redeem`;
};
/**
* uses 递增与兑换记录写入同事务。定向邀请只能由目标用户兑换。
* @summary 兑换邀请
*/
export const authOrganizationInviteRedeem = async (
redeemInviteBody: RedeemInviteBody,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationInviteRedeemResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authOrganizationInviteRedeemResponse>(
getAuthOrganizationInviteRedeemUrl(),
{
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(redeemInviteBody),
},
);
};
export type authOrganizationGetResponse200 = {
data: EnvelopeOrganizationSummary;
status: 200;
};
export type authOrganizationGetResponse404 = {
data: EnvelopeNoData;
status: 404;
};
export type authOrganizationGetResponseSuccess =
authOrganizationGetResponse200 & {
headers: Headers;
};
export type authOrganizationGetResponseError =
authOrganizationGetResponse404 & {
headers: Headers;
};
export type authOrganizationGetResponse =
authOrganizationGetResponseSuccess | authOrganizationGetResponseError;
export const getAuthOrganizationGetUrl = (organizationId: string) => {
return `/api/v1/organizations/${organizationId}`;
};
/**
* @summary 组织详情
*/
export const authOrganizationGet = async (
organizationId: string,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationGetResponse> => {
return authClient<authOrganizationGetResponse>(
getAuthOrganizationGetUrl(organizationId),
{
...options,
method: "GET",
},
);
};
export type authOrganizationDeleteResponse200 = {
data: EnvelopeBool;
status: 200;
};
export type authOrganizationDeleteResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationDeleteResponse409 = {
data: EnvelopeNoData;
status: 409;
};
export type authOrganizationDeleteResponseSuccess =
authOrganizationDeleteResponse200 & {
headers: Headers;
};
export type authOrganizationDeleteResponseError = (
authOrganizationDeleteResponse403 | authOrganizationDeleteResponse409
) & {
headers: Headers;
};
export type authOrganizationDeleteResponse =
authOrganizationDeleteResponseSuccess | authOrganizationDeleteResponseError;
export const getAuthOrganizationDeleteUrl = (
organizationId: string,
params?: AuthOrganizationDeleteParams,
) => {
const normalizedParams = new URLSearchParams();
Object.entries(params || {}).forEach(([key, value]) => {
if (value !== undefined) {
normalizedParams.append(key, value === null ? "null" : String(value));
}
});
const stringifiedParams = normalizedParams.toString();
return stringifiedParams.length > 0
? `/api/v1/organizations/${organizationId}?${stringifiedParams}`
: `/api/v1/organizations/${organizationId}`;
};
/**
* 仍存在活跃成员且未指定 `force=true` 时返回 409。删除会清理成员、角色与邀请。
* @summary 删除组织
*/
export const authOrganizationDelete = async (
organizationId: string,
params?: AuthOrganizationDeleteParams,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationDeleteResponse> => {
return authClient<authOrganizationDeleteResponse>(
getAuthOrganizationDeleteUrl(organizationId, params),
{
...options,
method: "DELETE",
},
);
};
export type authOrganizationUpdateResponse200 = {
data: EnvelopeOrganizationSummary;
status: 200;
};
export type authOrganizationUpdateResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationUpdateResponse409 = {
data: EnvelopeNoData;
status: 409;
};
export type authOrganizationUpdateResponseSuccess =
authOrganizationUpdateResponse200 & {
headers: Headers;
};
export type authOrganizationUpdateResponseError = (
authOrganizationUpdateResponse403 | authOrganizationUpdateResponse409
) & {
headers: Headers;
};
export type authOrganizationUpdateResponse =
authOrganizationUpdateResponseSuccess | authOrganizationUpdateResponseError;
export const getAuthOrganizationUpdateUrl = (organizationId: string) => {
return `/api/v1/organizations/${organizationId}`;
};
/**
* 需要 `org.update`。`expected_version` 与当前 version 不一致时返回 409。
* @summary 修改组织
*/
export const authOrganizationUpdate = async (
organizationId: string,
updateOrganizationBody: UpdateOrganizationBody,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationUpdateResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authOrganizationUpdateResponse>(
getAuthOrganizationUpdateUrl(organizationId),
{
...options,
method: "PATCH",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(updateOrganizationBody),
},
);
};
export type authOrganizationArchiveResponse200 = {
data: EnvelopeOrganizationSummary;
status: 200;
};
export type authOrganizationArchiveResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationArchiveResponseSuccess =
authOrganizationArchiveResponse200 & {
headers: Headers;
};
export type authOrganizationArchiveResponseError =
authOrganizationArchiveResponse403 & {
headers: Headers;
};
export type authOrganizationArchiveResponse =
authOrganizationArchiveResponseSuccess | authOrganizationArchiveResponseError;
export const getAuthOrganizationArchiveUrl = (organizationId: string) => {
return `/api/v1/organizations/${organizationId}/archive`;
};
/**
* 需要 `org.archive`。归档后全部权限判定返回 false,可恢复。
* @summary 归档组织
*/
export const authOrganizationArchive = async (
organizationId: string,
reasonBody: ReasonBody,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationArchiveResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authOrganizationArchiveResponse>(
getAuthOrganizationArchiveUrl(organizationId),
{
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(reasonBody),
},
);
};
export type authOrganizationBanListResponse200 = {
data: EnvelopeVecMemberSummary;
status: 200;
};
export type authOrganizationBanListResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationBanListResponseSuccess =
authOrganizationBanListResponse200 & {
headers: Headers;
};
export type authOrganizationBanListResponseError =
authOrganizationBanListResponse403 & {
headers: Headers;
};
export type authOrganizationBanListResponse =
authOrganizationBanListResponseSuccess | authOrganizationBanListResponseError;
export const getAuthOrganizationBanListUrl = (
organizationId: string,
params?: AuthOrganizationBanListParams,
) => {
const normalizedParams = new URLSearchParams();
Object.entries(params || {}).forEach(([key, value]) => {
if (value !== undefined) {
normalizedParams.append(key, value === null ? "null" : String(value));
}
});
const stringifiedParams = normalizedParams.toString();
return stringifiedParams.length > 0
? `/api/v1/organizations/${organizationId}/bans?${stringifiedParams}`
: `/api/v1/organizations/${organizationId}/bans`;
};
/**
* 需要 `member.ban`。按封禁时间倒序。
* @summary 封禁列表
*/
export const authOrganizationBanList = async (
organizationId: string,
params?: AuthOrganizationBanListParams,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationBanListResponse> => {
return authClient<authOrganizationBanListResponse>(
getAuthOrganizationBanListUrl(organizationId, params),
{
...options,
method: "GET",
},
);
};
export type authOrganizationBanGetResponse200 = {
data: EnvelopeMemberSummary;
status: 200;
};
export type authOrganizationBanGetResponse404 = {
data: EnvelopeNoData;
status: 404;
};
export type authOrganizationBanGetResponseSuccess =
authOrganizationBanGetResponse200 & {
headers: Headers;
};
export type authOrganizationBanGetResponseError =
authOrganizationBanGetResponse404 & {
headers: Headers;
};
export type authOrganizationBanGetResponse =
authOrganizationBanGetResponseSuccess | authOrganizationBanGetResponseError;
export const getAuthOrganizationBanGetUrl = (
organizationId: string,
userId: number,
) => {
return `/api/v1/organizations/${organizationId}/bans/${userId}`;
};
/**
* 需要 `member.ban`。未封禁返回 404。
* @summary 封禁详情
*/
export const authOrganizationBanGet = async (
organizationId: string,
userId: number,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationBanGetResponse> => {
return authClient<authOrganizationBanGetResponse>(
getAuthOrganizationBanGetUrl(organizationId, userId),
{
...options,
method: "GET",
},
);
};
export type authOrganizationBanDeleteResponse200 = {
data: EnvelopeMemberSummary;
status: 200;
};
export type authOrganizationBanDeleteResponse404 = {
data: EnvelopeNoData;
status: 404;
};
export type authOrganizationBanDeleteResponseSuccess =
authOrganizationBanDeleteResponse200 & {
headers: Headers;
};
export type authOrganizationBanDeleteResponseError =
authOrganizationBanDeleteResponse404 & {
headers: Headers;
};
export type authOrganizationBanDeleteResponse =
| authOrganizationBanDeleteResponseSuccess
| authOrganizationBanDeleteResponseError;
export const getAuthOrganizationBanDeleteUrl = (
organizationId: string,
userId: number,
) => {
return `/api/v1/organizations/${organizationId}/bans/${userId}`;
};
/**
* 需要 `member.ban`。等价于按会籍 id 解封,便于按用户维度操作。
* @summary 按用户解封
*/
export const authOrganizationBanDelete = async (
organizationId: string,
userId: number,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationBanDeleteResponse> => {
return authClient<authOrganizationBanDeleteResponse>(
getAuthOrganizationBanDeleteUrl(organizationId, userId),
{
...options,
method: "DELETE",
},
);
};
export type authOrganizationBanUpdateResponse200 = {
data: EnvelopeMemberSummary;
status: 200;
};
export type authOrganizationBanUpdateResponse404 = {
data: EnvelopeNoData;
status: 404;
};
export type authOrganizationBanUpdateResponseSuccess =
authOrganizationBanUpdateResponse200 & {
headers: Headers;
};
export type authOrganizationBanUpdateResponseError =
authOrganizationBanUpdateResponse404 & {
headers: Headers;
};
export type authOrganizationBanUpdateResponse =
| authOrganizationBanUpdateResponseSuccess
| authOrganizationBanUpdateResponseError;
export const getAuthOrganizationBanUpdateUrl = (
organizationId: string,
userId: number,
) => {
return `/api/v1/organizations/${organizationId}/bans/${userId}`;
};
/**
* 需要 `member.ban`。改原因、到期时间与四个放行位;未封禁返回 404。
* @summary 更新封禁
*/
export const authOrganizationBanUpdate = async (
organizationId: string,
userId: number,
updateBanBody: UpdateBanBody,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationBanUpdateResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authOrganizationBanUpdateResponse>(
getAuthOrganizationBanUpdateUrl(organizationId, userId),
{
...options,
method: "PATCH",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(updateBanBody),
},
);
};
export type authOrganizationInviteListResponse200 = {
data: EnvelopeVecInviteSummary;
status: 200;
};
export type authOrganizationInviteListResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationInviteListResponseSuccess =
authOrganizationInviteListResponse200 & {
headers: Headers;
};
export type authOrganizationInviteListResponseError =
authOrganizationInviteListResponse403 & {
headers: Headers;
};
export type authOrganizationInviteListResponse =
| authOrganizationInviteListResponseSuccess
| authOrganizationInviteListResponseError;
export const getAuthOrganizationInviteListUrl = (
organizationId: string,
params?: AuthOrganizationInviteListParams,
) => {
const normalizedParams = new URLSearchParams();
Object.entries(params || {}).forEach(([key, value]) => {
if (value !== undefined) {
normalizedParams.append(key, value === null ? "null" : String(value));
}
});
const stringifiedParams = normalizedParams.toString();
return stringifiedParams.length > 0
? `/api/v1/organizations/${organizationId}/invites?${stringifiedParams}`
: `/api/v1/organizations/${organizationId}/invites`;
};
/**
* 需要 `invite.view`。不含 token 明文。
* @summary 列示邀请
*/
export const authOrganizationInviteList = async (
organizationId: string,
params?: AuthOrganizationInviteListParams,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationInviteListResponse> => {
return authClient<authOrganizationInviteListResponse>(
getAuthOrganizationInviteListUrl(organizationId, params),
{
...options,
method: "GET",
},
);
};
export type authOrganizationInviteCreateResponse200 = {
data: EnvelopeCreateInviteResponse;
status: 200;
};
export type authOrganizationInviteCreateResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationInviteCreateResponseSuccess =
authOrganizationInviteCreateResponse200 & {
headers: Headers;
};
export type authOrganizationInviteCreateResponseError =
authOrganizationInviteCreateResponse403 & {
headers: Headers;
};
export type authOrganizationInviteCreateResponse =
| authOrganizationInviteCreateResponseSuccess
| authOrganizationInviteCreateResponseError;
export const getAuthOrganizationInviteCreateUrl = (organizationId: string) => {
return `/api/v1/organizations/${organizationId}/invites`;
};
/**
* 需要 `invite.create`。明文 token 只在创建响应里返回一次,之后只存 sha256。
* @summary 创建邀请
*/
export const authOrganizationInviteCreate = async (
organizationId: string,
createInviteBody: CreateInviteBody,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationInviteCreateResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authOrganizationInviteCreateResponse>(
getAuthOrganizationInviteCreateUrl(organizationId),
{
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(createInviteBody),
},
);
};
export type authOrganizationInviteRevokeResponse200 = {
data: EnvelopeBool;
status: 200;
};
export type authOrganizationInviteRevokeResponse404 = {
data: EnvelopeNoData;
status: 404;
};
export type authOrganizationInviteRevokeResponseSuccess =
authOrganizationInviteRevokeResponse200 & {
headers: Headers;
};
export type authOrganizationInviteRevokeResponseError =
authOrganizationInviteRevokeResponse404 & {
headers: Headers;
};
export type authOrganizationInviteRevokeResponse =
| authOrganizationInviteRevokeResponseSuccess
| authOrganizationInviteRevokeResponseError;
export const getAuthOrganizationInviteRevokeUrl = (
organizationId: string,
inviteId: string,
) => {
return `/api/v1/organizations/${organizationId}/invites/${inviteId}`;
};
/**
* 需要 `invite.revoke`。已撤销的邀请再次撤销返回 false。
* @summary 撤销邀请
*/
export const authOrganizationInviteRevoke = async (
organizationId: string,
inviteId: string,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationInviteRevokeResponse> => {
return authClient<authOrganizationInviteRevokeResponse>(
getAuthOrganizationInviteRevokeUrl(organizationId, inviteId),
{
...options,
method: "DELETE",
},
);
};
export type authOrganizationLeaveResponse200 = {
data: EnvelopeBool;
status: 200;
};
export type authOrganizationLeaveResponse409 = {
data: EnvelopeNoData;
status: 409;
};
export type authOrganizationLeaveResponseSuccess =
authOrganizationLeaveResponse200 & {
headers: Headers;
};
export type authOrganizationLeaveResponseError =
authOrganizationLeaveResponse409 & {
headers: Headers;
};
export type authOrganizationLeaveResponse =
authOrganizationLeaveResponseSuccess | authOrganizationLeaveResponseError;
export const getAuthOrganizationLeaveUrl = (organizationId: string) => {
return `/api/v1/organizations/${organizationId}/leave`;
};
/**
* OWNER 必须先转移所有权,否则返回 409。
* @summary 退出组织
*/
export const authOrganizationLeave = async (
organizationId: string,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationLeaveResponse> => {
return authClient<authOrganizationLeaveResponse>(
getAuthOrganizationLeaveUrl(organizationId),
{
...options,
method: "POST",
},
);
};
export type authOrganizationMemberListResponse200 = {
data: EnvelopeVecMemberSummary;
status: 200;
};
export type authOrganizationMemberListResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationMemberListResponseSuccess =
authOrganizationMemberListResponse200 & {
headers: Headers;
};
export type authOrganizationMemberListResponseError =
authOrganizationMemberListResponse403 & {
headers: Headers;
};
export type authOrganizationMemberListResponse =
| authOrganizationMemberListResponseSuccess
| authOrganizationMemberListResponseError;
export const getAuthOrganizationMemberListUrl = (
organizationId: string,
params?: AuthOrganizationMemberListParams,
) => {
const normalizedParams = new URLSearchParams();
Object.entries(params || {}).forEach(([key, value]) => {
if (value !== undefined) {
normalizedParams.append(key, value === null ? "null" : String(value));
}
});
const stringifiedParams = normalizedParams.toString();
return stringifiedParams.length > 0
? `/api/v1/organizations/${organizationId}/members?${stringifiedParams}`
: `/api/v1/organizations/${organizationId}/members`;
};
/**
* 需要 `member.view`。默认只返回活跃成员。
* @summary 列示组织成员
*/
export const authOrganizationMemberList = async (
organizationId: string,
params?: AuthOrganizationMemberListParams,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationMemberListResponse> => {
return authClient<authOrganizationMemberListResponse>(
getAuthOrganizationMemberListUrl(organizationId, params),
{
...options,
method: "GET",
},
);
};
export type authOrganizationMemberAddResponse200 = {
data: EnvelopeMemberSummary;
status: 200;
};
export type authOrganizationMemberAddResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationMemberAddResponse404 = {
data: EnvelopeNoData;
status: 404;
};
export type authOrganizationMemberAddResponseSuccess =
authOrganizationMemberAddResponse200 & {
headers: Headers;
};
export type authOrganizationMemberAddResponseError = (
authOrganizationMemberAddResponse403 | authOrganizationMemberAddResponse404
) & {
headers: Headers;
};
export type authOrganizationMemberAddResponse =
| authOrganizationMemberAddResponseSuccess
| authOrganizationMemberAddResponseError;
export const getAuthOrganizationMemberAddUrl = (organizationId: string) => {
return `/api/v1/organizations/${organizationId}/members`;
};
/**
* 需要 `member.add`。已退出的会籍按复活处理,已封禁的返回 403。
* @summary 直接添加成员
*/
export const authOrganizationMemberAdd = async (
organizationId: string,
addMemberBody: AddMemberBody,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationMemberAddResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authOrganizationMemberAddResponse>(
getAuthOrganizationMemberAddUrl(organizationId),
{
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(addMemberBody),
},
);
};
export type authOrganizationMemberUpdateSelfResponse200 = {
data: EnvelopeMemberSummary;
status: 200;
};
export type authOrganizationMemberUpdateSelfResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationMemberUpdateSelfResponseSuccess =
authOrganizationMemberUpdateSelfResponse200 & {
headers: Headers;
};
export type authOrganizationMemberUpdateSelfResponseError =
authOrganizationMemberUpdateSelfResponse403 & {
headers: Headers;
};
export type authOrganizationMemberUpdateSelfResponse =
| authOrganizationMemberUpdateSelfResponseSuccess
| authOrganizationMemberUpdateSelfResponseError;
export const getAuthOrganizationMemberUpdateSelfUrl = (
organizationId: string,
) => {
return `/api/v1/organizations/${organizationId}/members/@me`;
};
/**
* 只允许修改自己的别名、头像与通知偏好;无需 `member.role.update`。
* @summary 更新自己的会籍资料
*/
export const authOrganizationMemberUpdateSelf = async (
organizationId: string,
updateMemberBody: UpdateMemberBody,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationMemberUpdateSelfResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authOrganizationMemberUpdateSelfResponse>(
getAuthOrganizationMemberUpdateSelfUrl(organizationId),
{
...options,
method: "PATCH",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(updateMemberBody),
},
);
};
export type authOrganizationMemberGetResponse200 = {
data: EnvelopeMemberSummary;
status: 200;
};
export type authOrganizationMemberGetResponse404 = {
data: EnvelopeNoData;
status: 404;
};
export type authOrganizationMemberGetResponseSuccess =
authOrganizationMemberGetResponse200 & {
headers: Headers;
};
export type authOrganizationMemberGetResponseError =
authOrganizationMemberGetResponse404 & {
headers: Headers;
};
export type authOrganizationMemberGetResponse =
| authOrganizationMemberGetResponseSuccess
| authOrganizationMemberGetResponseError;
export const getAuthOrganizationMemberGetUrl = (
organizationId: string,
memberId: string,
) => {
return `/api/v1/organizations/${organizationId}/members/${memberId}`;
};
/**
* 需要 `member.view`。包含别名、通知偏好与封禁附加信息。
* @summary 成员详情
*/
export const authOrganizationMemberGet = async (
organizationId: string,
memberId: string,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationMemberGetResponse> => {
return authClient<authOrganizationMemberGetResponse>(
getAuthOrganizationMemberGetUrl(organizationId, memberId),
{
...options,
method: "GET",
},
);
};
export type authOrganizationMemberRemoveResponse200 = {
data: EnvelopeBool;
status: 200;
};
export type authOrganizationMemberRemoveResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationMemberRemoveResponseSuccess =
authOrganizationMemberRemoveResponse200 & {
headers: Headers;
};
export type authOrganizationMemberRemoveResponseError =
authOrganizationMemberRemoveResponse403 & {
headers: Headers;
};
export type authOrganizationMemberRemoveResponse =
| authOrganizationMemberRemoveResponseSuccess
| authOrganizationMemberRemoveResponseError;
export const getAuthOrganizationMemberRemoveUrl = (
organizationId: string,
memberId: string,
params?: AuthOrganizationMemberRemoveParams,
) => {
const normalizedParams = new URLSearchParams();
Object.entries(params || {}).forEach(([key, value]) => {
if (value !== undefined) {
normalizedParams.append(key, value === null ? "null" : String(value));
}
});
const stringifiedParams = normalizedParams.toString();
return stringifiedParams.length > 0
? `/api/v1/organizations/${organizationId}/members/${memberId}?${stringifiedParams}`
: `/api/v1/organizations/${organizationId}/members/${memberId}`;
};
/**
* 需要 `member.remove`。OWNER 不能移除,需先转移所有权。会籍行保留用于复活。
* @summary 移除成员
*/
export const authOrganizationMemberRemove = async (
organizationId: string,
memberId: string,
params?: AuthOrganizationMemberRemoveParams,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationMemberRemoveResponse> => {
return authClient<authOrganizationMemberRemoveResponse>(
getAuthOrganizationMemberRemoveUrl(organizationId, memberId, params),
{
...options,
method: "DELETE",
},
);
};
export type authOrganizationMemberUpdateResponse200 = {
data: EnvelopeMemberSummary;
status: 200;
};
export type authOrganizationMemberUpdateResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationMemberUpdateResponse409 = {
data: EnvelopeNoData;
status: 409;
};
export type authOrganizationMemberUpdateResponseSuccess =
authOrganizationMemberUpdateResponse200 & {
headers: Headers;
};
export type authOrganizationMemberUpdateResponseError = (
| authOrganizationMemberUpdateResponse403
| authOrganizationMemberUpdateResponse409
) & {
headers: Headers;
};
export type authOrganizationMemberUpdateResponse =
| authOrganizationMemberUpdateResponseSuccess
| authOrganizationMemberUpdateResponseError;
export const getAuthOrganizationMemberUpdateUrl = (
organizationId: string,
memberId: string,
) => {
return `/api/v1/organizations/${organizationId}/members/${memberId}`;
};
/**
* 需要 `member.role.update`。修改别名、头像、通知偏好与免打扰;封禁中的会籍走封禁接口。
* @summary 更新成员资料
*/
export const authOrganizationMemberUpdate = async (
organizationId: string,
memberId: string,
updateMemberBody: UpdateMemberBody,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationMemberUpdateResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authOrganizationMemberUpdateResponse>(
getAuthOrganizationMemberUpdateUrl(organizationId, memberId),
{
...options,
method: "PATCH",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(updateMemberBody),
},
);
};
export type authOrganizationMemberBanResponse200 = {
data: EnvelopeMemberSummary;
status: 200;
};
export type authOrganizationMemberBanResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationMemberBanResponseSuccess =
authOrganizationMemberBanResponse200 & {
headers: Headers;
};
export type authOrganizationMemberBanResponseError =
authOrganizationMemberBanResponse403 & {
headers: Headers;
};
export type authOrganizationMemberBanResponse =
| authOrganizationMemberBanResponseSuccess
| authOrganizationMemberBanResponseError;
export const getAuthOrganizationMemberBanUrl = (
organizationId: string,
memberId: string,
) => {
return `/api/v1/organizations/${organizationId}/members/${memberId}/ban`;
};
/**
* 写 banned_at 并清空角色绑定与直挂权限。封禁优先于一切授权。
* @summary 封禁成员
*/
export const authOrganizationMemberBan = async (
organizationId: string,
memberId: string,
banMemberBody: BanMemberBody,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationMemberBanResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authOrganizationMemberBanResponse>(
getAuthOrganizationMemberBanUrl(organizationId, memberId),
{
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(banMemberBody),
},
);
};
export type authOrganizationMemberPermissionsResponse200 = {
data: EnvelopeVecString;
status: 200;
};
export type authOrganizationMemberPermissionsResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationMemberPermissionsResponseSuccess =
authOrganizationMemberPermissionsResponse200 & {
headers: Headers;
};
export type authOrganizationMemberPermissionsResponseError =
authOrganizationMemberPermissionsResponse403 & {
headers: Headers;
};
export type authOrganizationMemberPermissionsResponse =
| authOrganizationMemberPermissionsResponseSuccess
| authOrganizationMemberPermissionsResponseError;
export const getAuthOrganizationMemberPermissionsUrl = (
organizationId: string,
memberId: string,
) => {
return `/api/v1/organizations/${organizationId}/members/${memberId}/permissions`;
};
/**
* 整表替换语义。需要 `role.permission.update`,OWNER 不接受直挂覆盖。
* @summary 设置成员直挂权限
*/
export const authOrganizationMemberPermissions = async (
organizationId: string,
memberId: string,
setRolePermissionsBody: SetRolePermissionsBody,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationMemberPermissionsResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authOrganizationMemberPermissionsResponse>(
getAuthOrganizationMemberPermissionsUrl(organizationId, memberId),
{
...options,
method: "PUT",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(setRolePermissionsBody),
},
);
};
export type authOrganizationMemberRoleResponse200 = {
data: EnvelopeMemberSummary;
status: 200;
};
export type authOrganizationMemberRoleResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationMemberRoleResponse409 = {
data: EnvelopeNoData;
status: 409;
};
export type authOrganizationMemberRoleResponseSuccess =
authOrganizationMemberRoleResponse200 & {
headers: Headers;
};
export type authOrganizationMemberRoleResponseError = (
authOrganizationMemberRoleResponse403 | authOrganizationMemberRoleResponse409
) & {
headers: Headers;
};
export type authOrganizationMemberRoleResponse =
| authOrganizationMemberRoleResponseSuccess
| authOrganizationMemberRoleResponseError;
export const getAuthOrganizationMemberRoleUrl = (
organizationId: string,
memberId: string,
) => {
return `/api/v1/organizations/${organizationId}/members/${memberId}/role`;
};
/**
* 只接受 MEMBER 与 ADMIN。OWNER 只能通过转移所有权变更。
* @summary 改粗粒度角色
*/
export const authOrganizationMemberRole = async (
organizationId: string,
memberId: string,
setMemberRoleBody: SetMemberRoleBody,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationMemberRoleResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authOrganizationMemberRoleResponse>(
getAuthOrganizationMemberRoleUrl(organizationId, memberId),
{
...options,
method: "PATCH",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(setMemberRoleBody),
},
);
};
export type authOrganizationMemberUnbanResponse200 = {
data: EnvelopeMemberSummary;
status: 200;
};
export type authOrganizationMemberUnbanResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationMemberUnbanResponseSuccess =
authOrganizationMemberUnbanResponse200 & {
headers: Headers;
};
export type authOrganizationMemberUnbanResponseError =
authOrganizationMemberUnbanResponse403 & {
headers: Headers;
};
export type authOrganizationMemberUnbanResponse =
| authOrganizationMemberUnbanResponseSuccess
| authOrganizationMemberUnbanResponseError;
export const getAuthOrganizationMemberUnbanUrl = (
organizationId: string,
memberId: string,
) => {
return `/api/v1/organizations/${organizationId}/members/${memberId}/unban`;
};
/**
* 清空 banned_at。已清空的角色不会自动恢复。
* @summary 解封成员
*/
export const authOrganizationMemberUnban = async (
organizationId: string,
memberId: string,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationMemberUnbanResponse> => {
return authClient<authOrganizationMemberUnbanResponse>(
getAuthOrganizationMemberUnbanUrl(organizationId, memberId),
{
...options,
method: "POST",
},
);
};
export type authOrganizationPermissionCheckResponse200 = {
data: EnvelopePermissionCheck;
status: 200;
};
export type authOrganizationPermissionCheckResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationPermissionCheckResponseSuccess =
authOrganizationPermissionCheckResponse200 & {
headers: Headers;
};
export type authOrganizationPermissionCheckResponseError =
authOrganizationPermissionCheckResponse403 & {
headers: Headers;
};
export type authOrganizationPermissionCheckResponse =
| authOrganizationPermissionCheckResponseSuccess
| authOrganizationPermissionCheckResponseError;
export const getAuthOrganizationPermissionCheckUrl = (
organizationId: string,
) => {
return `/api/v1/organizations/${organizationId}/permissions/check`;
};
/**
* 拒绝不作为错误返回:`allowed=false` 附 `reason` 与 `matched_by`,便于调用方聚合。
* @summary 单权限判定
*/
export const authOrganizationPermissionCheck = async (
organizationId: string,
checkPermissionBody: CheckPermissionBody,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationPermissionCheckResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authOrganizationPermissionCheckResponse>(
getAuthOrganizationPermissionCheckUrl(organizationId),
{
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(checkPermissionBody),
},
);
};
export type authOrganizationRestoreResponse200 = {
data: EnvelopeOrganizationSummary;
status: 200;
};
export type authOrganizationRestoreResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationRestoreResponseSuccess =
authOrganizationRestoreResponse200 & {
headers: Headers;
};
export type authOrganizationRestoreResponseError =
authOrganizationRestoreResponse403 & {
headers: Headers;
};
export type authOrganizationRestoreResponse =
authOrganizationRestoreResponseSuccess | authOrganizationRestoreResponseError;
export const getAuthOrganizationRestoreUrl = (organizationId: string) => {
return `/api/v1/organizations/${organizationId}/restore`;
};
/**
* 仅 OWNER 或平台管理员可执行。
* @summary 恢复归档组织
*/
export const authOrganizationRestore = async (
organizationId: string,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationRestoreResponse> => {
return authClient<authOrganizationRestoreResponse>(
getAuthOrganizationRestoreUrl(organizationId),
{
...options,
method: "POST",
},
);
};
export type authOrganizationRoleListResponse200 = {
data: EnvelopeVecRoleSummary;
status: 200;
};
export type authOrganizationRoleListResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationRoleListResponseSuccess =
authOrganizationRoleListResponse200 & {
headers: Headers;
};
export type authOrganizationRoleListResponseError =
authOrganizationRoleListResponse403 & {
headers: Headers;
};
export type authOrganizationRoleListResponse =
| authOrganizationRoleListResponseSuccess
| authOrganizationRoleListResponseError;
export const getAuthOrganizationRoleListUrl = (organizationId: string) => {
return `/api/v1/organizations/${organizationId}/roles`;
};
/**
* 需要 `role.view`。含内置 owner/admin/member 三个系统角色。
* @summary 列示组织角色
*/
export const authOrganizationRoleList = async (
organizationId: string,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationRoleListResponse> => {
return authClient<authOrganizationRoleListResponse>(
getAuthOrganizationRoleListUrl(organizationId),
{
...options,
method: "GET",
},
);
};
export type authOrganizationRoleCreateResponse200 = {
data: EnvelopeRoleSummary;
status: 200;
};
export type authOrganizationRoleCreateResponse409 = {
data: EnvelopeNoData;
status: 409;
};
export type authOrganizationRoleCreateResponseSuccess =
authOrganizationRoleCreateResponse200 & {
headers: Headers;
};
export type authOrganizationRoleCreateResponseError =
authOrganizationRoleCreateResponse409 & {
headers: Headers;
};
export type authOrganizationRoleCreateResponse =
| authOrganizationRoleCreateResponseSuccess
| authOrganizationRoleCreateResponseError;
export const getAuthOrganizationRoleCreateUrl = (organizationId: string) => {
return `/api/v1/organizations/${organizationId}/roles`;
};
/**
* 需要 `role.create`。key 在组织内唯一,权限键必须在白名单内。
* @summary 新建角色
*/
export const authOrganizationRoleCreate = async (
organizationId: string,
createRoleBody: CreateRoleBody,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationRoleCreateResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authOrganizationRoleCreateResponse>(
getAuthOrganizationRoleCreateUrl(organizationId),
{
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(createRoleBody),
},
);
};
export type authOrganizationRoleAssignResponse200 = {
data: EnvelopeVecString;
status: 200;
};
export type authOrganizationRoleAssignResponse404 = {
data: EnvelopeNoData;
status: 404;
};
export type authOrganizationRoleAssignResponseSuccess =
authOrganizationRoleAssignResponse200 & {
headers: Headers;
};
export type authOrganizationRoleAssignResponseError =
authOrganizationRoleAssignResponse404 & {
headers: Headers;
};
export type authOrganizationRoleAssignResponse =
| authOrganizationRoleAssignResponseSuccess
| authOrganizationRoleAssignResponseError;
export const getAuthOrganizationRoleAssignUrl = (organizationId: string) => {
return `/api/v1/organizations/${organizationId}/roles/assign`;
};
/**
* 需要 `role.assign`。重复绑定幂等。
* @summary 绑定角色到成员
*/
export const authOrganizationRoleAssign = async (
organizationId: string,
assignRoleBody: AssignRoleBody,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationRoleAssignResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authOrganizationRoleAssignResponse>(
getAuthOrganizationRoleAssignUrl(organizationId),
{
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(assignRoleBody),
},
);
};
export type authOrganizationRoleUnassignResponse200 = {
data: EnvelopeVecString;
status: 200;
};
export type authOrganizationRoleUnassignResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationRoleUnassignResponseSuccess =
authOrganizationRoleUnassignResponse200 & {
headers: Headers;
};
export type authOrganizationRoleUnassignResponseError =
authOrganizationRoleUnassignResponse403 & {
headers: Headers;
};
export type authOrganizationRoleUnassignResponse =
| authOrganizationRoleUnassignResponseSuccess
| authOrganizationRoleUnassignResponseError;
export const getAuthOrganizationRoleUnassignUrl = (organizationId: string) => {
return `/api/v1/organizations/${organizationId}/roles/unassign`;
};
/**
* 需要 `role.assign`。系统角色不可解绑。
* @summary 解绑成员角色
*/
export const authOrganizationRoleUnassign = async (
organizationId: string,
assignRoleBody: AssignRoleBody,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationRoleUnassignResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authOrganizationRoleUnassignResponse>(
getAuthOrganizationRoleUnassignUrl(organizationId),
{
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(assignRoleBody),
},
);
};
export type authOrganizationRoleGetResponse200 = {
data: EnvelopeRoleSummary;
status: 200;
};
export type authOrganizationRoleGetResponse404 = {
data: EnvelopeNoData;
status: 404;
};
export type authOrganizationRoleGetResponseSuccess =
authOrganizationRoleGetResponse200 & {
headers: Headers;
};
export type authOrganizationRoleGetResponseError =
authOrganizationRoleGetResponse404 & {
headers: Headers;
};
export type authOrganizationRoleGetResponse =
authOrganizationRoleGetResponseSuccess | authOrganizationRoleGetResponseError;
export const getAuthOrganizationRoleGetUrl = (
organizationId: string,
roleId: string,
) => {
return `/api/v1/organizations/${organizationId}/roles/${roleId}`;
};
/**
* 需要 `role.view`。
* @summary 角色详情
*/
export const authOrganizationRoleGet = async (
organizationId: string,
roleId: string,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationRoleGetResponse> => {
return authClient<authOrganizationRoleGetResponse>(
getAuthOrganizationRoleGetUrl(organizationId, roleId),
{
...options,
method: "GET",
},
);
};
export type authOrganizationRoleDeleteResponse200 = {
data: EnvelopeBool;
status: 200;
};
export type authOrganizationRoleDeleteResponse409 = {
data: EnvelopeNoData;
status: 409;
};
export type authOrganizationRoleDeleteResponseSuccess =
authOrganizationRoleDeleteResponse200 & {
headers: Headers;
};
export type authOrganizationRoleDeleteResponseError =
authOrganizationRoleDeleteResponse409 & {
headers: Headers;
};
export type authOrganizationRoleDeleteResponse =
| authOrganizationRoleDeleteResponseSuccess
| authOrganizationRoleDeleteResponseError;
export const getAuthOrganizationRoleDeleteUrl = (
organizationId: string,
roleId: string,
) => {
return `/api/v1/organizations/${organizationId}/roles/${roleId}`;
};
/**
* 需要 `role.delete`。系统角色不可删;仍有成员绑定时返回 409。
* @summary 删除角色
*/
export const authOrganizationRoleDelete = async (
organizationId: string,
roleId: string,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationRoleDeleteResponse> => {
return authClient<authOrganizationRoleDeleteResponse>(
getAuthOrganizationRoleDeleteUrl(organizationId, roleId),
{
...options,
method: "DELETE",
},
);
};
export type authOrganizationRoleUpdateResponse200 = {
data: EnvelopeRoleSummary;
status: 200;
};
export type authOrganizationRoleUpdateResponse409 = {
data: EnvelopeNoData;
status: 409;
};
export type authOrganizationRoleUpdateResponseSuccess =
authOrganizationRoleUpdateResponse200 & {
headers: Headers;
};
export type authOrganizationRoleUpdateResponseError =
authOrganizationRoleUpdateResponse409 & {
headers: Headers;
};
export type authOrganizationRoleUpdateResponse =
| authOrganizationRoleUpdateResponseSuccess
| authOrganizationRoleUpdateResponseError;
export const getAuthOrganizationRoleUpdateUrl = (
organizationId: string,
roleId: string,
) => {
return `/api/v1/organizations/${organizationId}/roles/${roleId}`;
};
/**
* 需要 `role.update`。OWNER 系统角色不允许改 rank 与 default_role。
* @summary 修改角色
*/
export const authOrganizationRoleUpdate = async (
organizationId: string,
roleId: string,
updateRoleBody: UpdateRoleBody,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationRoleUpdateResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authOrganizationRoleUpdateResponse>(
getAuthOrganizationRoleUpdateUrl(organizationId, roleId),
{
...options,
method: "PATCH",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(updateRoleBody),
},
);
};
export type authOrganizationRoleJoinResponse200 = {
data: EnvelopeMemberSummary;
status: 200;
};
export type authOrganizationRoleJoinResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationRoleJoinResponseSuccess =
authOrganizationRoleJoinResponse200 & {
headers: Headers;
};
export type authOrganizationRoleJoinResponseError =
authOrganizationRoleJoinResponse403 & {
headers: Headers;
};
export type authOrganizationRoleJoinResponse =
| authOrganizationRoleJoinResponseSuccess
| authOrganizationRoleJoinResponseError;
export const getAuthOrganizationRoleJoinUrl = (
organizationId: string,
roleId: string,
) => {
return `/api/v1/organizations/${organizationId}/roles/${roleId}/join`;
};
/**
* 只允许 `self_assignable = true` 的非内置角色。
* @summary 自助加入角色
*/
export const authOrganizationRoleJoin = async (
organizationId: string,
roleId: string,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationRoleJoinResponse> => {
return authClient<authOrganizationRoleJoinResponse>(
getAuthOrganizationRoleJoinUrl(organizationId, roleId),
{
...options,
method: "POST",
},
);
};
export type authOrganizationRoleLeaveResponse200 = {
data: EnvelopeMemberSummary;
status: 200;
};
export type authOrganizationRoleLeaveResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationRoleLeaveResponseSuccess =
authOrganizationRoleLeaveResponse200 & {
headers: Headers;
};
export type authOrganizationRoleLeaveResponseError =
authOrganizationRoleLeaveResponse403 & {
headers: Headers;
};
export type authOrganizationRoleLeaveResponse =
| authOrganizationRoleLeaveResponseSuccess
| authOrganizationRoleLeaveResponseError;
export const getAuthOrganizationRoleLeaveUrl = (
organizationId: string,
roleId: string,
) => {
return `/api/v1/organizations/${organizationId}/roles/${roleId}/join`;
};
/**
* 只允许 `self_assignable = true` 的非内置角色;重复退出视为成功。
* @summary 自助退出角色
*/
export const authOrganizationRoleLeave = async (
organizationId: string,
roleId: string,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationRoleLeaveResponse> => {
return authClient<authOrganizationRoleLeaveResponse>(
getAuthOrganizationRoleLeaveUrl(organizationId, roleId),
{
...options,
method: "DELETE",
},
);
};
export type authOrganizationRolePermissionsResponse200 = {
data: EnvelopeRoleSummary;
status: 200;
};
export type authOrganizationRolePermissionsResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationRolePermissionsResponseSuccess =
authOrganizationRolePermissionsResponse200 & {
headers: Headers;
};
export type authOrganizationRolePermissionsResponseError =
authOrganizationRolePermissionsResponse403 & {
headers: Headers;
};
export type authOrganizationRolePermissionsResponse =
| authOrganizationRolePermissionsResponseSuccess
| authOrganizationRolePermissionsResponseError;
export const getAuthOrganizationRolePermissionsUrl = (
organizationId: string,
roleId: string,
) => {
return `/api/v1/organizations/${organizationId}/roles/${roleId}/permissions`;
};
/**
* 整体替换语义,是角色权限的唯一写入口。需要 `role.permission.update`。
* @summary 设置角色权限
*/
export const authOrganizationRolePermissions = async (
organizationId: string,
roleId: string,
setRolePermissionsBody: SetRolePermissionsBody,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationRolePermissionsResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authOrganizationRolePermissionsResponse>(
getAuthOrganizationRolePermissionsUrl(organizationId, roleId),
{
...options,
method: "PUT",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(setRolePermissionsBody),
},
);
};
export type authOrganizationTransferResponse200 = {
data: EnvelopeOrganizationSummary;
status: 200;
};
export type authOrganizationTransferResponse403 = {
data: EnvelopeNoData;
status: 403;
};
export type authOrganizationTransferResponse404 = {
data: EnvelopeNoData;
status: 404;
};
export type authOrganizationTransferResponseSuccess =
authOrganizationTransferResponse200 & {
headers: Headers;
};
export type authOrganizationTransferResponseError = (
authOrganizationTransferResponse403 | authOrganizationTransferResponse404
) & {
headers: Headers;
};
export type authOrganizationTransferResponse =
| authOrganizationTransferResponseSuccess
| authOrganizationTransferResponseError;
export const getAuthOrganizationTransferUrl = (organizationId: string) => {
return `/api/v1/organizations/${organizationId}/transfer`;
};
/**
* 目标必须是活跃成员。原 Owner 降为 ADMIN。
* @summary 转移 OWNER
*/
export const authOrganizationTransfer = async (
organizationId: string,
transferBody: TransferBody,
options?: Parameters<typeof authClient>[1],
): Promise<authOrganizationTransferResponse> => {
const getHeaders = (
h?: NonNullable<RequestInit["headers"]>,
): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(
h as Iterable<Iterable<string>>,
(entry) => Array.from(entry) as [string, string],
),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<
string | readonly string[] | undefined
>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return authClient<authOrganizationTransferResponse>(
getAuthOrganizationTransferUrl(organizationId),
{
...options,
method: "POST",
headers: {
"Content-Type": "application/json",
...getHeaders(options?.headers),
},
body: JSON.stringify(transferBody),
},
);
};
export type healthLiveResponse200 = {
data: EnvelopeHealthResponse;
status: 200;
};
export type healthLiveResponseSuccess = healthLiveResponse200 & {
headers: Headers;
};
export type healthLiveResponse = healthLiveResponseSuccess;
export const getHealthLiveUrl = () => {
return `/health`;
};
/**
* 只回答进程是否还在处理请求,不触碰任何外部依赖:数据库、Redis、RocketMQ 全都不可用时依然返回 200。用于区分「进程死了」和「依赖挂了」。
* @summary 存活探针
*/
export const healthLive = async (
options?: Parameters<typeof authClient>[1],
): Promise<healthLiveResponse> => {
return authClient<healthLiveResponse>(getHealthLiveUrl(), {
...options,
method: "GET",
});
};
export type healthReadyResponse200 = {
data: EnvelopeReadinessResponse;
status: 200;
};
export type healthReadyResponse503 = {
data: EnvelopeReadinessResponse;
status: 503;
};
export type healthReadyResponseSuccess = healthReadyResponse200 & {
headers: Headers;
};
export type healthReadyResponseError = healthReadyResponse503 & {
headers: Headers;
};
export type healthReadyResponse =
healthReadyResponseSuccess | healthReadyResponseError;
export const getHealthReadyUrl = () => {
return `/ready`;
};
/**
* 并发探测启动时必须连上的三个依赖——PostgreSQL、Redis、RocketMQ,全部可用返回 200,任一不可用返回 503 并在 `checks` 里标出是哪一项。单项探测上限 2 秒,失败细节只写日志,不进响应体。
* @summary 就绪探针
*/
export const healthReady = async (
options?: Parameters<typeof authClient>[1],
): Promise<healthReadyResponse> => {
return authClient<healthReadyResponse>(getHealthReadyUrl(), {
...options,
method: "GET",
});
};