@cloudquery/plugin-config-ui-connector
Version:
Plugin configuration UI connector for CloudQuery Cloud App
278 lines (266 loc) • 10 kB
TypeScript
/**
* A library that is designed to establish communication between CloudQuery Cloud App form and Plugin UI
*
* @packageDocumentation
*/
/**
* Type of the message handler for the CloudQuery Cloud App form.
* @public
*/
export declare type FormMessageHandler = MessageHandler<FormMessageType, FormMessagePayload, PluginUiMessageType, PluginUiMessagePayload>;
/**
* Type representing the payload structure for form messages.
*
* @public
*/
export declare type FormMessagePayload = {
/**
* Payload for the 'init' message type.
*/
init: {
pluginVersion?: {
created_at: string;
published_at?: string;
name: string;
message: string;
draft: boolean;
retracted: boolean;
supported_targets: string[];
checksums: string[];
package_type: 'native' | 'docker';
spec_json_schema?: string;
connector_required?: boolean;
connector_types?: string[];
example_config: string;
ui_base_url?: string;
};
/** The initial values for the form */
initialValues: {
name: string;
displayName?: string;
migrateMode: 'forced' | 'safe' | undefined;
envs: Array<{
name: string;
value: string;
}>;
spec: Record<string, any> | undefined;
tables: string[] | undefined;
skipTables: string[] | undefined;
writeMode: 'append' | 'overwrite' | 'overwrite-delete-stale' | undefined;
connectorId?: string;
onboardingId?: string;
} | undefined;
/** Team name of the user */
teamName: string;
/** Outer app context for the plugin */
context: 'standalone' | 'wizard';
/** Rudderstack config */
rudderstackConfig?: {
dataPlaneUrl: string;
key: string;
};
/** Whether the destination is managed (using Neon) */
isManagedDestination?: boolean;
/** User information */
user: {
id: string;
email: string;
name: string;
};
/** Whether the form is disabled */
isDisabled?: boolean;
};
/**
* Payload for the 'auth_connector_result' message type.
* This message type is used to provide the current value of the auth connector parameters.
*/
auth_connector_result: Record<string, string>;
};
/**
* Type representing the possible CloudQuery Cloud App form message types to be sent.
* Extracts the types from the formMessageTypes array.
*
* @public
*/
export declare type FormMessageType = (typeof formMessageTypes)[number];
/**
* List of message types to be sent by the CloudQuery Cloud App form.
*
* @public
*/
export declare const formMessageTypes: readonly ["init", "auth_connector_result"];
/**
* This function is used to get the message handler to communicate with the CloudQuery Cloud App form.
*
* @public
*/
export declare function getPluginUiMessageHandler(): MessageHandler<"loaded" | "cancel" | "ready" | "go_to_previous_step" | "delete" | "submitted" | "show_toast", PluginUiMessagePayload, "init" | "auth_connector_result", FormMessagePayload>;
/**
* A class to handle sending and receiving messages between CloudQuery Cloud App form and the Plugin UI.
*
* @typeParam SendMessageType - A union of string literal types representing the possible message types for sending.
* @typeParam SendMessagePayload - An object type representing the payload structure for messages to be sent.
* @typeParam ReceiveMessageType - A union of string literal types representing the possible message types for receiving.
* @typeParam ReceiveMessagePayload - An object type representing the payload structure for messages to be received.
*
* @public
*/
export declare class MessageHandler<SendMessageType extends keyof SendMessagePayload, SendMessagePayload, ReceiveMessageType extends keyof ReceiveMessagePayload, ReceiveMessagePayload> {
private sendMessageWindow;
private callbacks;
private sendMessageTypes;
private receiveMessageTypes;
/**
* Constructs a new MessageHandler instance.
*
* @param sendMessageTypes - An array of allowed send message types.
* @param receiveMessageTypes - An array of allowed receive message types.
* @param sendMessageWindow - The window object to send messages to.
*/
constructor(sendMessageTypes: readonly SendMessageType[], receiveMessageTypes: readonly ReceiveMessageType[], sendMessageWindow: Window);
/**
* Sends a message to the specified window.
*
* @typeParam MessageType - The type of the message to be sent.
* @param type - The message type.
* @param payload - The payload associated with the message type.
* @throws Error - If the message type is not recognized.
*/
sendMessage<MessageType extends SendMessageType>(type: MessageType, ...payload: SendMessagePayload[MessageType] extends void ? [] : [SendMessagePayload[MessageType]]): void;
/**
* Subscribes to a specific message type and registers a callback to be invoked when that message is received.
*
* @typeParam MessageType - The type of the message to subscribe to.
* @param type - The message type.
* @param callback - The callback to be invoked with the message payload.
* @returns A function to unsubscribe from the message type.
* @throws Error - If the message type is not recognized.
*/
subscribeToMessage<MessageType extends ReceiveMessageType>(type: MessageType, callback: (payload: ReceiveMessagePayload[MessageType]) => void): () => void;
/**
* Subscribes to a specific message type and registers a callback to be invoked only once when that message is received.
*
* @typeParam MessageType - The type of the message to subscribe to.
* @param type - The message type.
* @param callback - The callback to be invoked with the message payload.
* @returns A function to unsubscribe from the message type.
*/
subscribeToMessageOnce<MessageType extends ReceiveMessageType>(type: MessageType, callback: (payload: ReceiveMessagePayload[MessageType]) => void): () => void;
/**
* Handles incoming messages and invokes the appropriate callbacks.
*
* @param event - The message event containing the data.
*/
private handleMessage;
}
/**
* Type of the message handler for the Plugin UI form.
* @public
*/
export declare type PluginUiMessageHandler = MessageHandler<PluginUiMessageType, PluginUiMessagePayload, FormMessageType, FormMessagePayload>;
/**
* Type representing the payload structure for Plugin UI messages.
*
* @public
*/
export declare type PluginUiMessagePayload = {
/**
* Payload for the 'ready' message type.
*/
ready: void;
/**
* Payload for the 'loaded' message type.
*/
loaded: void;
/**
* Payload for the 'go_to_previous_step' message type.
*/
go_to_previous_step: void;
/**
* Payload for the 'delete' message type.
*/
delete: void;
/**
* Payload for the 'cancel' message type.
*/
cancel: void;
/**
* Payload for the 'submitted' message type.
*/
submitted: {
submitPayload: {
name: string;
displayName?: string;
migrateMode?: 'forced' | 'safe';
envs: Array<{
name: string;
value: string;
}>;
spec: Record<string, any>;
tables?: string[];
skipTables?: string[];
writeMode?: 'append' | 'overwrite' | 'overwrite-delete-stale';
connectorId?: string;
onboardingId?: string;
};
resource: {
name: string;
display_name: string;
path: string;
version: string;
tables: string[];
skip_tables?: string[];
spec?: Record<string, any>;
env?: Array<{
name: string;
value: string;
}>;
last_update_source?: 'ui' | 'yaml';
updated_at: string;
created_at: string;
connector_id?: string;
onboarding_id?: string;
} | {
name: string;
display_name?: string;
path: string;
version: string;
write_mode?: 'append' | 'overwrite' | 'overwrite-delete-stale';
migrate_mode?: 'forced' | 'safe';
sync_group_id?: string;
spec?: Record<string, any>;
env?: Array<{
name: string;
value: string;
}>;
last_update_source?: 'ui' | 'yaml';
connector_id?: string;
transformers?: string[];
updated_at: string;
created_at: string;
onboarding_id?: string;
};
};
/**
* Payload for the 'show_toast' message type.
*/
show_toast: {
message: string;
type: 'blank' | 'success' | 'error';
duration?: number;
};
};
/**
* Type representing the possible Plugin UI message types to be sent.
* Extracts the types from the pluginUiMessageTypes array.
*
* @public
*/
export declare type PluginUiMessageType = (typeof pluginUiMessageTypes)[number];
/**
* List of message types to be sent by the Plugin UI.
*
* @public
*/
export declare const pluginUiMessageTypes: readonly ["loaded", "ready", "go_to_previous_step", "delete", "cancel", "submitted", "show_toast"];
export { }