import type * as CSS_2 from 'csstype'; /** * @description SDK UI组件的外观配置。 * 控制主题、CSS变量、布局规则及显示设置。 * @template Props - 自定义外观属性类型,默认为 DefaultAppearanceProps。 */ declare interface Appearance = DefaultAppearanceProps> { theme?: Props['theme']; variables?: PartialSpeKey; rules?: PartialSpeKey>; displaySetting?: PartialSpeKey; layout?: Props['layout']; fonts?: FontSource[]; } /** * @description Get auth credentials */ export declare interface AuthConfig { clientId: string; token: string; country: string; } declare interface BaseAppearance> { appearance?: A; } /** * @description 内置基础的桥接事件映射类型 */ declare interface BaseBridgeEventMap = Record, SubmitReplay extends Record = Record, SubmitParams extends Record = Record, AppErrorCodes extends string = string, OpenModalConfig extends BaseOpenModalConfig = BaseOpenModalConfig> { error: ErrorPayload; /* Excluded from this release type: "OPENSDK@HANDSHAKE" */ /* Excluded from this release type: "OPENSDK@READY_HANDSHAKE" */ /* Excluded from this release type: "OPENSDK@UPDATE_CONFIG" */ /** * 更新配置时的回复事件,包含可能发生的错误信息。 * 如果 error 为 undefined,则表示没有错误发生。 */ "OPENSDK@UPDATE_CONFIG_REPLY": { /** * 更新配置时发生的错误,如果error为undefined,则表示没有错误发生 */ error?: ErrorPayload; } | undefined; /* Excluded from this release type: "OPENSDK@HANDSHAKE_ACK" */ /* Excluded from this release type: "OPENSDK@SUBMIT" */ /* Excluded from this release type: "OPENSDK@SUBMIT_REPLY" */ /* Excluded from this release type: "OPENSDK@OPEN_MODAL" */ /* Excluded from this release type: "OPENSDK@OPEN_MODAL_ERROR" */ /* Excluded from this release type: "OPENSDK@CLOSE_MODAL" */ /* Excluded from this release type: "OPENSDK@REDIRECT" */ /* Excluded from this release type: "OPENSDK@TRANSFER_MODAL_PORT" */ /* Excluded from this release type: "OPENSDK@TRANSFER_MODAL_APPEARANCE" */ /* Excluded from this release type: "OPENSDK@TRANSFER_MODAL_INITIALDATA" */ /* Excluded from this release type: "OPENSDK@TRANSFER_APP_PORT" */ /* Excluded from this release type: "OPENSDK@ERROR" */ /* Excluded from this release type: "OPENSDK@TRANSFER_RECEIVE_PORT" */ /* Excluded from this release type: "OPENSDK@TRANSFER_SEND_PORT" */ /* Excluded from this release type: "OPENSDK@MESSAGE" */ /* Excluded from this release type: "OPENSDK@HEIGHT_UPDATE" */ /* Excluded from this release type: "OPENSDK@DESTROY_ELEMENT" */ } declare interface BaseConfig { /** * @description 透传参数 */ targetOrigin: string; /** * @description 是否开启debug */ debug?: boolean; /** * @description 当前的环境 */ env: 'sandbox' | 'prod'; /** * @description 多语言 */ locale?: string; /* Excluded from this release type: version */ /* Excluded from this release type: colorScheme */ } /** * @description 基础组件/页面 */ declare abstract class BaseElement = BaseBridgeEventMap> { static elementType: string; /* Excluded from this release type: name */ /* Excluded from this release type: _elementMode */ /* Excluded from this release type: _isMainElement */ /* Excluded from this release type: config */ /* Excluded from this release type: bridge */ /* Excluded from this release type: hooks */ /* Excluded from this release type: iframe */ status: ElementStatus; /* Excluded from this release type: cachedSend */ /** Reuses the pending reply for concurrent submit calls. */ private submitPromise?; constructor(name: string, config: WithAppURL); /* Excluded from this release type: submit */ /* Excluded from this release type: setup */ /** Races merchant setup against destruction to stop the mount flow immediately. */ private _setup; /* Excluded from this release type: is */ /** * @param {HTMLElement} container */ mount(container: HTMLElement): Promise; /* Excluded from this release type: _mount */ /** * 更新webapp配置 * @param {Partial} newConfig */ updateConfig(newConfig: Partial): Promise; /** * 卸载元素 */ unmount(): void; /* Excluded from this release type: isSingleMode */ /** * 监听消息 */ on(event: T, handler: (payload: EventMap[T]) => void): void; /* Excluded from this release type: send */ /* Excluded from this release type: _addPort */ /* Excluded from this release type: _transferReceivePort */ /* Excluded from this release type: _transferSendPort */ /* Excluded from this release type: _submit */ destroy(): void; get isMainElement(): boolean; /** * 对于独立的input需要实现 */ protected abstract focus(): void; /** * 对于独立的input需要实现 */ protected abstract blur(): void; /** * 对于独立的input需要实现 */ protected abstract clear(): void; /* Excluded from this release type: _addHook */ } declare interface BaseElementAppConfig { /* Excluded from this release type: locale */ /* Excluded from this release type: env */ /* Excluded from this release type: merchantId */ [key: string]: any; } declare interface BaseElementConfig extends BaseConfig { /* Excluded from this release type: trackId */ appConfig: T; elementMode: ElementMode; } declare abstract class BaseFactory { /* Excluded from this release type: config */ /* Excluded from this release type: isInit */ /** * @description 当前版本号 * 用于日志上报 */ version: string; /* Excluded from this release type: elementMode */ /* Excluded from this release type: _elements */ /* Excluded from this release type: globalBridgeForWebApp */ /* Excluded from this release type: globalBridgeForModal */ /* Excluded from this release type: openModalHandle */ /* Excluded from this release type: elementClasses */ /** * @param config 配置 */ constructor(config: BaseFactoryConfig); protected openModal(payload: BaseBridgeEventMap['OPENSDK@OPEN_MODAL']): Promise; protected redirect(payload: BaseBridgeEventMap['OPENSDK@REDIRECT']): void | Promise; /* Excluded from this release type: canUseElements */ /** * @description 无需手动调用 */ init(): Promise; /* Excluded from this release type: generateElementKey */ /** * @description 更新工厂配置 locale debug env * @param config */ updateConfig(config: Partial): void; /** * @description 销毁所有元素实例 */ destroy(): void; /* Excluded from this release type: _generateElementKey */ /** * 创建element实例 * @param {string} elementType 类型 * @param {BaseElementConfig} options 选项 */ abstract createElement(elementType: string, options?: BaseElementAppConfig): BaseElement; /** * 获取element实例 * @param {string} elementType 类型 * @param {BaseElementConfig} options 选项 */ abstract getElement(elementType: string, options?: BaseElementAppConfig): BaseElement; /* Excluded from this release type: _createElement */ /* Excluded from this release type: _addElement */ /* Excluded from this release type: _removeElement */ /* Excluded from this release type: _getElement */ /* Excluded from this release type: _getElementSize */ } declare interface BaseFactoryConfig extends BaseConfig { /* Excluded from this release type: trackerCode */ } /** * @description 主元素,可以独立提交 */ declare abstract class BaseMainElement = BaseBridgeEventMap> extends BaseElement { /** * * @param name 名称 * @param appUrl webapp的url * @param config 透传配置 * @param defaultAppConfig 默认的app配置 */ constructor(name: string, appUrl: string, config: Config, defaultAppConfig?: Partial); /* Excluded from this release type: _submit */ } /** * @description 打开模态框的配置项。 * 包含显示选项、关闭行为、外观设置及初始化数据。 */ declare interface BaseOpenModalConfig { /** * 无需手动传递,app的唯一scope */ scope?: string; /** * @description 是否展示关闭按钮 */ showClose?: boolean; /** * @description 配合showClose使用,在加载完成后是否隐藏按钮 */ hideCloseWhenLoaded?: boolean; /** * @description 是否展示loading */ showLoading?: boolean; /** * @description 点击关闭按钮时的回调 */ onClose?: () => void; url: string; /** * @description 关闭时,是否需要告知webapp页面来进行关闭 链路为 modalApp 告知-> webapp 关闭-> sdk,默认为false,即直接在modal中进行关闭 modalApp 关闭-> sdk, */ closeConfirm?: boolean; /** * @description 需要同步的外观配置 */ appearance?: Appearance; /** * @description 需要传递的初始化数据 */ initialData?: Record; /** * @description 无需手动传递, 模态框的唯一标识 */ modalId?: string; } export declare const C_EVENT_RECEIVED: { READY: string; E_CHANNEL_S: string; }; export declare const C_EVENT_SEND: { AUTH_CHANNEL: string; CHANNEL_READY: string; CHANNEL_FAIL: string; }; /** * CSS 字体源 — 通过 标签加载外部 CSS(如 Google Fonts) */ declare interface CssFontSource { cssSrc: string; } /** * 自定义字体源 — 通过 @font-face 加载自托管字体 */ declare interface CustomFontSource { family: string; src: string; weight?: string; style?: string; unicodeRange?: string; } declare interface DefaultAppearanceProps { theme: string; variables: string; displaySetting: string; layout: string; rules: string; } declare const ELEMENT_TYPE: { ONBOARD: string; }; /** * @description 元素列表项类型 */ declare type ElementListItemType = iBaseElementClass | { ElementClass: iBaseElementClass; config?: Partial; }; declare type ElementMode = 'SINGLE' | 'GROUP'; declare type ElementStatus = 'initialized' | 'mounting' | 'mounted' | 'ready' | 'destroyed' | 'unmounted'; export declare type ElementTypes = keyof typeof ELEMENT_TYPE; declare interface ErrorPayload { source: ErrorSource; code: Code; message: string; reason: string; traceId?: string; stack?: string; } declare type ErrorSource = ErrorSource_2; declare type ErrorSource_2 = 'SDK_INTERNAL' | 'SDK_USAGE' | 'APP_RUNTIME' | 'SERVER_API' | 'SYSTEM'; declare type FontSource = CssFontSource | CustomFontSource; declare type GetI18nQueryParam = string | { /** * 多语言文案的 key */ id: string; /** * 多语言文案的默认值 */ dm?: string; /** * 多语言文案的默认值,defaultMessage 和 dm 只需要一个就行 * 推荐使用 dm * defaultMessage 是为了兼容中后台原来的开发习惯 */ defaultMessage?: string; }; declare type GlobalOptions = { i18n?: SimpleI18n; i18nPrefix: string; getDefaultMessage?: () => string; }; declare interface iBaseElementClass { new (name: string, config: BaseElementConfig): BaseElement; elementType: string; } export declare interface OnboardAppConfig { name?: string; /** * @description Theme configuration to pass to the onboard page */ theme?: Record; } /** * @description Onboard element app config type */ export declare interface OnboardAppConfig extends BaseAppearance, BaseElementAppConfig { } /** * @description Onboard element appearance type */ export declare type OnboardAppearance = PickAppearance<{ displaySetting: 'example1'; theme: WorldFirstTheme; variables: 'variable1'; }>; /** * @description Onboard element */ export declare class OnboardElement extends BaseMainElement { static elementType: string; /** * @description Element type */ private traceId; /** 当前 Element 是否命中了资源预加载 */ readonly isPreloaded: boolean; /** Auth 管理器,由 WorldFirstSDK 注入 */ private authManager; private channel; constructor(name: string, config: OnboardElementConfig); private logInfo; private logError; /** * Deliver MessageChannel port1 to Auth iframe via AuthManager. * AuthManager uses MessageChannel internally, no need to directly manipulate auth iframe DOM. */ private _deliverAuthPort; /** * Deliver MessageChannel port2 to Element iframe via Element bridge. */ private _deliverElementPort; /** * Override mount: create MessageChannel and concurrently deliver auth port and mount iframe. * * - port1 → Auth iframe (token server), delivered via postMessage * - port2 → current Element iframe (token client), delivered via bridge.send() * * Automatically closes channel when iframe is destroyed. */ mount(containerEle: HTMLElement): Promise; submit(): Promise>; protected focus(): void; protected blur(): void; protected clear(): void; } /** * @description Onboard element config type */ declare type OnboardElementConfig = BaseElementConfig; /** * @description Onboard element events */ export declare interface OnboardElementEvents extends WorldFirstBridgeEventMap { stepChange: { hasNext: boolean; hasPre: boolean; hasTemporaryStorage: boolean; hasSubmit: boolean; nodeId: string; /** * 是否是上一步 */ stepBack: boolean; }; updateTheme: Record; onboardSubmitResult: OnboardSubmitParams; } /** * @description submit params */ export declare interface OnboardSubmitParams { /** * @description Compatible with old version result field */ result?: 'success' | 'fail'; /** * @description Compatible with old version errorMessage field */ errorMessage?: string; } /** * @description OpenModal的返回值类型 */ declare type OpenModalHandle = { destroy: () => void; onLoadedSuccess: (onLoadSuccess: () => void) => void; getContentWindow: () => Window | null; }; declare class OpenSDKError extends Error { code: Code | OpenSDKInternalErrorCodes; name: string; /* Excluded from this release type: _openSDKErrorFlag */ source: ErrorSource; traceId?: string; /** * @description 用于存储原始错误信息的,给内部调试 */ reason: string; static isError(error: any): error is OpenSDKError; /** * @description 统一转换error为OpenSDKError */ static unificationError(error: unknown, source?: ErrorSource): OpenSDKError; static initConfig(config: Partial): void; constructor(_message: string | { message: string; params?: Record; }, code: Code | OpenSDKInternalErrorCodes, source: ErrorSource, _traceId?: string, serverAPIWithoutI18n?: boolean); toJSON(): ErrorPayload; } declare const OpenSDKInternalErrorCodes: { /** * @description 未知错误 */ readonly UNKNOWN_ERROR: "UNKNOWN_ERROR"; /** * @description 无端口错误,通常发生在模态通信中,SDK期望接收一个MessagePort但未收到 */ readonly NO_PORTS_ERROR: "NO_PORTS_ERROR"; /** * @description 非法的URL */ readonly INVALID_REDIRECT_URL: "INVALID_REDIRECT_URL"; }; declare type OpenSDKInternalErrorCodes = (typeof OpenSDKInternalErrorCodes)[keyof typeof OpenSDKInternalErrorCodes]; declare type PartialSpeKey = Partial : Record>; /** * @description 工具类型,仅从 Appearance 中拾取与 Props 类型匹配的属性。 * 返回受 Props 中存在的键约束的部分外观对象。 * @template Props - 要从 Appearance 中拾取的自定义外观属性类型。 */ declare type PickAppearance> = Partial, keyof Props extends infer k extends keyof Partial ? k : keyof Partial>>; declare interface PreLoadConfig { /** * @description Preloading config. Optional. * Pass the element types to use; SDK will preload corresponding resources. * Each value matches the type param of createElement, e.g. 'Onboard', 'Vaulting'. */ elements?: string[]; /** * @description Locale identifier, replaces {lang} placeholder in manifest resource URLs. * Supported values align with embeddedSDK VALID_LANGUAGES, e.g. 'zh-CN', 'en-US'. * Defaults to 'zh-CN' if not provided or unsupported. */ locale?: string; /** * @description Environment identifier, used to load manifest and preload pages from the correct environment. * - 'prod': production (default) * - other: non-prod, URL will auto-include ?env=xxx */ env?: 'sandbox' | 'prod'; /** * @description Regions to preload. * - not set: preload resources for all regions * - set: only preload resources for the specified regions */ regions?: Region[]; } /** * @description 用于收集所有其他元素的值 */ declare class ReceivePort { targetPorts: Array; name: string; constructor(name: string); addPort(port: readonly MessagePort[]): void; removePort(port: MessagePort): void; getValues(config?: { timeout: number; }): Promise | undefined>; } /** * @description 从webapp重定向到新URL的配置项。 * 支持浏览器重定向、app link唤端及schema唤端。 */ declare interface RedirectOption { /** * @description 浏览器重定向到兜底的url,通常在唤端失败时会走这个,或者你不需要唤端,只需要跳转到某个url */ url: string; /** * @description 唤端到url地址,http或https的地址 */ appLinkUrl?: string; /** * @description 唤端到schema地址, schema://的地址 */ schemaUrl?: string; /** * @description 重定向模式,默认为redirect */ mode?: 'redirect' | 'replace'; /** * @description 是否重定向后销毁实例,默认为true */ destroy?: boolean; } /** Region type */ declare type Region = 'CN' | 'US' | 'ROW'; /** * @description 其他元素,用于发送value到主元素 */ declare class SendPort = Record> { targetPort: MessagePort; name: string; constructor(name: string, port: MessagePort); /** * @description 用于监听发送消息节点 */ onSendRequest(fn: () => void): void; send(values?: T): void; } declare type SimpleI18n = { get(id: GetI18nQueryParam, variable?: Record, localeCode?: string): string; }; /** * @description Submit return type */ export declare interface SubmitResult { [key: string]: any; } declare type WithAppURL = T & { appUrl: string; isMainElement: boolean; }; /** * @description SDK element events map type */ export declare type WorldFirstBridgeEventMap = Record, SubmitParams extends Record = Record> = BaseBridgeEventMap; /** * @public * @description Load config type */ export declare type WorldFirstLoadConfig = WorldFirstSDKConfig; export declare class WorldFirstSDK extends BaseFactory { /** SDK version */ static version: string; private authManager; constructor(config: WorldFirstSDKConfig); /** * Update Auth config (can be called multiple times). * Derives region from authConfig.country → updates targetOrigin → notifies AuthManager. * AuthManager internally determines if origin changed: * - origin changed: destroy old iframe, create new iframe * - origin unchanged: only resend config via channel */ setAuth(authConfig: AuthConfig): void; /** * Implement BaseFactory's canUseElements abstract method * Returns the list of available element classes for this factory */ protected canUseElements(): Array; /** * Implement BaseElementsFactory's elements method * Create and return element collection * Currently not in use */ /** * Implement BaseElementsFactory's createElement method * Create a single element */ createElement(type: string, _options?: any): any; /** * Implement BaseElementsFactory's getElement method * Get a created element */ getElement(type: string, options?: any): any; destroy(): void; } /** * @description SDK config type */ export declare interface WorldFirstSDKConfig extends Omit, Omit { version?: string; authConfig?: AuthConfig; } /** * @description SDK Error */ export declare class WorldFirstSDKError extends OpenSDKError { name: string; } /** * @description SDK error codes */ declare const WorldFirstSDKErrorCodes: { readonly GENERATE_ELEMENT_KEY_FAILED: "GENERATE_ELEMENT_KEY_FAILED"; readonly ELEMENT_INIT_FAILED: "ELEMENT_INIT_FAILED"; readonly MOUNT_TIMEOUT: "MOUNT_TIMEOUT"; readonly MOUNT_MISSING_CONTAINER: "MOUNT_MISSING_CONTAINER"; readonly MOUNT_IFRAME_LOAD_ERROR: "MOUNT_IFRAME_LOAD_ERROR"; readonly MOUNT_NOT_MAINELEMENT_WITH_SINGLE_MODE: "MOUNT_NOT_MAINELEMENT_WITH_SINGLE_MODE"; readonly MOUNT_NOT_SUPPORT: "MOUNT_NOT_SUPPORT"; readonly MOUNT_INITIAL_FAILED: "MOUNT_INITIAL_FAILED"; readonly ELEMENT_INSTANCE_DESTROYED: "ELEMENT_INSTANCE_DESTROYED"; readonly ELEMENT_DEFINE_ERROR: "ELEMENT_DEFINE_ERROR"; readonly ELEMENT_ALREADY_REGISTERED: "ELEMENT_ALREADY_REGISTERED"; readonly CANNOT_CREATE_SAME_ELEMENT_TWICE: "CANNOT_CREATE_SAME_ELEMENT_TWICE"; readonly GROUPS_ONLY_ONE_MAIN_ELEMENT: "GROUPS_ONLY_ONE_MAIN_ELEMENT"; readonly GROUPS_NOT_FOUND_MAIN_ELEMENT: "GROUPS_NOT_FOUND_MAIN_ELEMENT"; readonly NOT_SUPPORT_ELEMENT: "NOT_SUPPORT_ELEMENT"; readonly NOT_SUPPORT_SUBMIT: "NOT_SUPPORT_SUBMIT"; readonly UPDATE_CONFIG_TIMEOUT: "UPDATE_CONFIG_TIMEOUT"; readonly UPDATE_CONFIG_NOT_READY: "UPDATE_CONFIG_NOT_READY"; readonly INVALID_MODAL_URL: "INVALID_MODAL_URL"; readonly LOAD_DEBUGGER_FAILED: "LOAD_DEBUGGER_FAILED"; }; declare type WorldFirstSDKErrorCodes = (typeof WorldFirstSDKErrorCodes)[keyof typeof WorldFirstSDKErrorCodes]; /** * @description SDK theme */ export declare type WorldFirstTheme = 'dark' | 'light'; export { }