feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
168
frontend/packages/arch/foundation-sdk/src/index.ts
Normal file
168
frontend/packages/arch/foundation-sdk/src/index.ts
Normal 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;
|
||||
30
frontend/packages/arch/foundation-sdk/src/types.ts
Normal file
30
frontend/packages/arch/foundation-sdk/src/types.ts
Normal 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';
|
||||
35
frontend/packages/arch/foundation-sdk/src/types/layout.ts
Normal file
35
frontend/packages/arch/foundation-sdk/src/types/layout.ts
Normal 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;
|
||||
}
|
||||
49
frontend/packages/arch/foundation-sdk/src/types/passport.ts
Normal file
49
frontend/packages/arch/foundation-sdk/src/types/passport.ts
Normal 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:删除账号时获取ticket(auth/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; //加密state,bind_type 为 4时使用
|
||||
};
|
||||
scope?: string;
|
||||
optionalScope?: string;
|
||||
}
|
||||
122
frontend/packages/arch/foundation-sdk/src/types/user.ts
Normal file
122
frontend/packages/arch/foundation-sdk/src/types/user.ts
Normal 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';
|
||||
Reference in New Issue
Block a user