@plutoxyz/frame-js
Version:
SDK for integrating with Pluto Frame
78 lines (77 loc) • 2.15 kB
TypeScript
export declare enum PromptTypeKey {
TEXT = "text",
PASSWORD = "password",
CODE = "code",
NUMBER_CODE = "number_code",
SELECT = "select",
CHECKBOX = "checkbox",
LOGIN = "login",
INFO = "info"
}
export type PromptTextType = {
min_length?: number;
max_length?: number;
value?: string;
placeholder?: string;
};
export type PromptPasswordType = {};
export type PromptCodeType = {
length?: number;
};
export type PromptNumberCodeType = {
length?: number;
};
export type PromptCheckboxType = {
options: string[];
multiple?: boolean;
selected?: string[];
min?: number;
max?: number;
};
export type PromptSelectType = {
options: string[];
selected?: string[];
};
export declare enum LoginProviderID {
CREDENTIALS = "credentials",
GOOGLE = "google"
}
export interface LoginProvider {
id: LoginProviderID;
label: string;
}
export interface PromptLoginType {
providers: LoginProvider[];
}
export type PromptInfoType = {
checkbox_label?: string;
checkbox_required?: boolean;
};
export type PromptTypeMap = {
[PromptTypeKey.TEXT]: PromptTextType;
[PromptTypeKey.PASSWORD]: PromptPasswordType;
[PromptTypeKey.CODE]: PromptCodeType;
[PromptTypeKey.NUMBER_CODE]: PromptNumberCodeType;
[PromptTypeKey.SELECT]: PromptSelectType;
[PromptTypeKey.CHECKBOX]: PromptCheckboxType;
[PromptTypeKey.LOGIN]: PromptLoginType;
[PromptTypeKey.INFO]: PromptInfoType;
};
export type PromptType<T extends PromptTypeKey = PromptTypeKey> = PromptTypeMap[T];
export type PromptRequest<T extends PromptTypeKey = PromptTypeKey> = {
key: string;
label: string;
description?: string;
required?: boolean;
type: T;
attributes: PromptType<T>;
error?: string;
};
/**
* Validates whether a prompt value is valid based on the prompt type and attributes
*/
export declare function isPromptValueValid(prompt: PromptRequest, value: any): boolean;
/**
* Initializes default values for an array of prompts based on their types and attributes
*/
export declare function initializePromptValues(prompts: PromptRequest[]): string[];