UNPKG

@open-social-protocol/osp-plugin-api-types

Version:
124 lines (96 loc) 3.2 kB
import type { IContract, ICoder, ERC20ApproveUtils, ERC721ApproveUtils, ERC1155ApproveUtils } from "./contract"; import type { TPluginInfo, PageType, PageMode, TCreatePluginInfo } from './templates' import type { AddressAndABI, TManifest } from './manifest' import { OspApis } from "./ospContracts/OspApis"; export type AppEventNameType = "onInitializing" | "onInteractiveView"; export type ENVType = "dev" | "beta" | "pre" | "prod" export type ChainType = "0x14a34" | "0x2105" | "0x15eb" | "0xcc" export type tokenApproveUtils = { ERC20ApproveUtils: ERC20ApproveUtils, ERC721ApproveUtils: ERC721ApproveUtils, ERC1155ApproveUtils: ERC1155ApproveUtils } export type TOspInfoSandbox = { eoaAddress?: string; idToken?: string; } export type TPluginOspInfo = { appId: string; env: ENVType; chainId: ChainType; accessToken?: string; idToken?: string; isAASigner: boolean; hasSigner: boolean; feedInfo?: { profileId: string; contentId: string; postId: string; }, tribeInfo?: { id: string; handle: string; }, userInfo?: { address: string; handle: string; profileId: string; }, pluginManifest: TManifest; } & TOspInfoSandbox & Record<string, any>; export type TPluginUrlParams = { type: PageType; mode: PageMode; ospInfo: TPluginOspInfo, } export interface ContractGroup { [key: string]: IContract } export interface PluginAPI { readonly urlParams: [key: string, value: string] readonly type: PageType, readonly mode: PageMode, readonly abis: AddressAndABI[], readonly uiApi: UIAPI, readonly ospInfo: TPluginOspInfo, // these is null when ospInfo.userInfo is null, it means the user is not login readonly contracts?: ContractGroup, readonly ospContracts?: OspApis, readonly tokenApproveUtils?: tokenApproveUtils readonly coder: ICoder // web and pwd and app support, but not support in node createOspPostData(payload: TCreatePluginInfo): void onEvent(type: AppEventNameType, callback: (event: unknown) => void): void // node env only setPreviewData(data: TPluginTemplate): void openURL(url?: string, target?: string, features?: string) } export interface ClientStorageAPI { getAsync(key: string): Promise<unknown | undefined>; setAsync(key: string, value: unknown): Promise<void>; deleteAsync(key: string): Promise<void>; keysAsync(): Promise<string[]>; } export interface UIPostMessageOptions { origin?: string; } export interface OnMessageProperties { origin: string; } declare type MessageEventHandler = ( pluginMessage: unknown, props: OnMessageProperties ) => void; interface UIAPI { postMessage(pluginMessage: unknown): void onMessage(onMessage: MessageEventHandler | undefined): void // todo showUI(height: number): void resizeUI(height: number): void closeUI(message?: string): void toast(options: IPluginToast): void } export interface IPluginToast { type: "success" | "warning" | "error"; text?: string; autoHide?: boolean; visibilityTime?: number; swipeable?: boolean; }