feat: manually mirror opencoze's code from bytedance

Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
fanlv
2025-07-20 17:36:12 +08:00
commit 890153324f
14811 changed files with 1923430 additions and 0 deletions

View File

@@ -0,0 +1,168 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { type ReactNode, type FC } from 'react';
import {
type UserAuthInfo,
type UserLabel,
type BotSpace,
} from '@coze-arch/idl/developer_api';
import { type DropDownMenuItemItem } from '@coze-arch/coze-design';
export {
type OAuth2RedirectConfig,
type OAuth2StateType,
type UserInfo,
type UserConnectItem,
type ThemeType,
type LoginStatus,
type BackButtonProps,
type NavBtnProps,
} from './types';
import type {
LoginStatus,
ThemeType,
UserInfo,
BackButtonProps,
} from './types';
/**
* 获取当前主题
*/
export declare function useCurrentTheme(): ThemeType;
//------- Passport
/**
* 退出登录
*/
export declare function logoutOnly(): Promise<void>;
/**
* 上传用户头像
* @param file - 头像文件
* @returns web_uri - 头像文件对应的 url
*/
export declare function uploadAvatar(file: File): Promise<{ web_uri: string }>;
//-------
//------- User
/**
* 刷新用户信息
*/
export declare function refreshUserInfo(): Promise<void>;
/**
* 获取登录状态
* @returns LoginStatus - 检查中/已登录/未登录
*/
export declare function getLoginStatus(): LoginStatus;
/**
* 获取登录校验是否完成
* @returns boolean 登录校验是否完成
*/
export declare function getIsSettled(): boolean;
/**
* 获取是否登录,如需要获取真实登录状态,请配合 getIsSettled/useIsSettled 使用
* @deprecated - 推荐使用 getLoginStatus
* @returns boolean 是否登录
*/
export declare function getIsLogined(): boolean;
/**
* 获取用户信息
* @returns UserInfo | null - 用户信息
*/
export declare function getUserInfo(): UserInfo | null;
/**
* 获取用户三方授权信息
* @returns Promise<void>
*/
export declare function getUserAuthInfos(): Promise<void>;
/**
* 响应式获取登录状态
* @returns LoginStatus - 检查中/已登录/未登录
*/
export declare function useLoginStatus(): LoginStatus;
/**
* 响应式获取登录校验是否完成
* @returns boolean 登录校验是否完成
*/
export declare function useIsSettled(): boolean;
/**
* 响应式获取是否登录,如需要获取真实登录状态,请配合 getIsSettled/useIsSettled 使用
* @deprecated - 推荐使用 useLoginStatus
* @returns boolean 是否登录
*/
export declare function useIsLogined(): boolean;
/**
* 响应式获取用户信息
* @returns UserInfo | null - 用户信息
*/
export declare function useUserInfo(): UserInfo | null;
/**
* 响应式获取用户三方授权信息
* @returns UserAuthInfo[]
*/
export declare function useUserAuthInfo(): UserAuthInfo[];
/**
* 响应式获取用户用户标签
* @returns UserLabel
*/
export declare function useUserLabel(): UserLabel | null;
/**
* 订阅 UserAuthInfo 变化
* @param callback - 回调函数
*/
export declare function subscribeUserAuthInfos(
callback: (state: UserAuthInfo[], prev: UserAuthInfo[]) => void,
): () => void;
//------- layout组件
// eslint-disable-next-line @typescript-eslint/naming-convention
export declare const SideSheetMenu: FC;
// eslint-disable-next-line @typescript-eslint/naming-convention
export declare const BackButton: FC<BackButtonProps>;
//-------
export interface MenuItem {
label: string;
icon?: ReactNode;
url?: string;
menu?: Array<DropDownMenuItemItem>;
popover?: ReactNode;
renderType: 'link' | 'popover' | 'menu' | 'comp' | 'test-new-link';
comp?: React.JSX.Element;
}
/**
* 根据spaceId获取space信息
*/
export declare function useSpace(spaceId: string): BotSpace | undefined;

View File

@@ -0,0 +1,30 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export type ThemeType = 'dark' | 'light' | 'system';
export {
type OAuth2RedirectConfig,
type OAuth2StateType,
} from './types/passport';
export {
type UserInfo,
type UserConnectItem,
type LoginStatus,
} from './types/user';
export { BackButtonProps, NavBtnProps } from './types/layout';

View File

@@ -0,0 +1,35 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export interface BackButtonProps {
onClickBack: () => void;
}
/** 导航栏自定义按钮属性 */
export interface NavBtnProps {
// 必填Nav.Item导航组件唯一key路由匹配时高亮
navKey: string;
//按钮图标
icon?: React.ReactNode;
// 按钮名称
label: string | React.ReactNode;
// 后缀节点
suffix?: string | React.ReactNode;
// 仅在左侧导航栏默认模式中展示
onlyShowInDefault?: boolean;
// 按钮点击回调
onClick: (e: React.MouseEvent) => void;
}

View File

@@ -0,0 +1,49 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* 代表OAuth2回调的access_token的用途目前有
* 1.login登陆时进行用户中台三方登陆auth/login
* 2. delete_account删除账号时获取ticketauth/authorize
* 3. oauth: 发布三方平台是时获取用户授权
*/
export type OAuth2StateType = 'login' | 'delete_account' | 'oauth';
export interface OAuth2RedirectConfig {
/**
* 最终的OAuth2鉴权信息将作为路由参数跳转这个参数指定目标路由地址注意在目标路由上使用
* useAuthLoginDataRouteFromOAuth2来提取路由参数并转换成用户中台三方登陆服务authLogin的参数
* 默认值为当前路径名称即不传navigatePath参数时当前路由一定要注册useAuthLoginDataRouteFromOAuth2才有效
*/
navigatePath?: string;
/**
* OAuth2回调后拿到的鉴权信息的使用场景用于在一些路由组件中区分不符合对应场景的不能用于消费
*/
type: OAuth2StateType;
/**
* 传递给OAuth2服务器的state字段会在回调时传回用于恢复网页状态
*/
extra?: {
// @ts-expect-error -- linter-disable-autofix
origin?: string;
[x: string]: string; // 用于安全监测
// @ts-expect-error -- linter-disable-autofix
encrypt_state?: string; //加密statebind_type 为 4时使用
};
scope?: string;
optionalScope?: string;
}

View File

@@ -0,0 +1,122 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export interface UserConnectItem {
platform: string;
profile_image_url: string;
expired_time: number;
expires_in: number;
platform_screen_name: string;
user_id: number;
platform_uid: string;
sec_platform_uid: string;
platform_app_id: number;
modify_time: number;
access_token: string;
open_id: string;
}
export interface UserInfo {
app_id: number;
/**
* @deprecated 会因为溢出丢失精度,使用 user_id_str
*/
user_id: number;
user_id_str: string;
odin_user_type: number;
name: string;
screen_name: string;
avatar_url: string;
user_verified: boolean;
email?: string;
email_collected: boolean;
expend_attrs?: Record<string, unknown>;
phone_collected: boolean;
verified_content: string;
verified_agency: string;
is_blocked: number;
is_blocking: number;
bg_img_url: string;
gender: number;
media_id: number;
user_auth_info: string;
industry: string;
area: string;
can_be_found_by_phone: number;
mobile: string;
birthday: string;
description: string;
status: number;
new_user: number;
first_login_app: number;
session_key: string;
is_recommend_allowed: number;
recommend_hint_message: string;
followings_count: number;
followers_count: number;
visit_count_recent: number;
skip_edit_profile: number;
is_manual_set_user_info: boolean;
device_id: number;
country_code: number;
has_password: number;
share_to_repost: number;
user_decoration: string;
user_privacy_extend: number;
old_user_id: number;
old_user_id_str: string;
sec_user_id: string;
sec_old_user_id: string;
vcd_account: number;
vcd_relation: number;
can_bind_visitor_account: boolean;
is_visitor_account: boolean;
is_only_bind_ins: boolean;
user_device_record_status: number;
is_kids_mode: number;
source: string;
is_employee: boolean;
passport_enterprise_user_type: number;
need_device_create: number;
need_ttwid_migration: number;
user_auth_status: number;
user_safe_mobile_2fa: string;
safe_mobile_country_code: number;
lite_user_info_string: string;
lite_user_info_demotion: number;
app_user_info: {
user_unique_name?: string;
};
need_check_bind_status: boolean;
bui_audit_info?: {
// TODO 这里的类型定义需要再明确一点更好
audit_info: {
user_unique_name?: string;
avatar_url?: string;
name?: string;
[key: string]: unknown;
}; // Record<string, unknown>;
// int值。1审核中2审核通过3审核不通过
audit_status: 1 | 2 | 3;
details: Record<string, unknown>;
is_auditing: boolean;
last_update_time: number;
unpass_reason: string;
};
locale?: 'zh-CN' | 'en-US';
}
export type LoginStatus = 'settling' | 'not_login' | 'logined';