import { Emitter } from './utils/eventEmitter'; import { Favorite, File, User, CanvasRetrieve, CanvasSection } from '../../types/openapi'; import { PitcherOrg } from '../types/organization.types'; import { PitcherInstance } from '../types/instance.types'; import { PaginatedData } from '../types/paginatedData'; import { LaunchDarklyEnv } from '../types/launchDarkly.types'; import { CDP_EVENT_TYPE, CLIENT_TYPE } from '../constants/cdp.const'; export declare const PITCHER_EVENT: "PITCHER_EVENT"; export declare enum PitcherMessageType { REQUEST = "PITCHER_REQUEST", RESPONSE = "PITCHER_RESPONSE" } export declare enum PitcherResponseStatus { OK = "ok", ERROR = "error" } export interface PitcherMessage { type: typeof PITCHER_EVENT; request: { id: string; type: string; body?: Record; }; } type FetchMode = 'postmessage' | 'prefer-online'; export interface ApiOptions { errorLogger?: (p: any) => string | void; logLevel?: 'off' | 'info' | 'debug'; casing?: 'camel' | 'snake'; fetchMode?: FetchMode; } export interface OrgConfigResponse { auth0: { domain: string; issuer: string; audience: string; auth0_domain: string; web_client_id: string; region: 'us' | 'eu' | 'au'; }; segment: { web_write_key: string; }; region: 'us' | 'eu' | 'au'; auth0_tenant_region: 'us' | 'eu' | 'au'; datadog_region: 'us' | 'eu'; segment_region: 'us' | 'eu'; sentry_region: 'us' | 'eu'; } export interface PitcherEnv { mode: 'WEB' | 'IOS' | 'WINDOWS' | 'ANDROID'; pitcher: { token_claims: Record; organization: PitcherOrg; org_config?: OrgConfigResponse; instance: PitcherInstance; user: User; access_token: string; id_token: string; }; launch_darkly?: LaunchDarklyEnv; client_type?: (typeof CLIENT_TYPE)[keyof typeof CLIENT_TYPE]; crm_shape?: Record; state?: { active_file?: { id: File['id']; }; active_section_id?: CanvasSection['id']; active_canvas_id?: CanvasRetrieve['id']; canvas_correlation_id?: string; }; device_locale?: string; sync_badge_value?: number; } export interface PitcherAPI extends Emitter { request(type: string, body: any, callback: () => any): Promise; } export interface PitcherInterface extends Emitter { API: PitcherAPI; } export interface PitcherResponse { type: PitcherMessageType.RESPONSE; request: { id: string; type: string; body?: Record; }; response: { status: PitcherResponseStatus; body?: Record; }; } export interface OpenCanvasPitcherEvent { account_id?: string; account_name?: string; canvas_id?: string; edit_mode?: 'true' | 'false'; } export interface CreateAndOpenCanvasEvent { account_id?: string; } export interface StartCallPitcherEvent { account?: { id: string; name: string; }; contact_ids?: string[]; canvas_id?: string; edit_mode?: 'true' | 'false'; post_action?: string; post_action_path?: string; } export interface RouteChangedPitcherEvent { route_name: string; route_path: string; } export declare enum PitcherEventName { ENV_CHANGED = "env_changed", PHOTOS_CAPTURED = "photos_captured", GLOBAL_PHOTO_CAPTURED = "global_photo_captured", FILE_DOWNLOADED = "file_downloaded", FILE_UPLOAD_PROGRESS = "file_upload_progress", UPDATE_LOCATION = "update_location", CANVAS_UPDATED = "canvas_updated", CANVAS_UPDATED_SUCCESS = "canvas_updated_success", FILE_CLOSED = "file_closed", FILE_OPENED = "file_opened", APP_BACKGROUNDED = "app_backgrounded", APP_FOREGROUNDED = "app_foregrounded", NON_FILES_SYNC_FINISHED = "non_files_sync_finished", CONTENT_LIST_REFRESH_REQUESTED = "content_list_refresh_requested", NETWORK_CONNECTION_ESTABLISHED = "network_connection_established", NETWORK_CONNECTION_LOST = "network_connection_lost", ENTERED_FULLSCREEN = "entered_fullscreen", EXITED_FULLSCREEN = "exited_fullscreen", SUBMIT_POSTCALL_CLICKED = "submit_postcall_clicked", ANALYTICS_CAPTURED = "analytics_captured", OPEN_FOLDER_REQUESTED = "open_folder_requested", CANVAS_PAGE_NEXT_REQUESTED = "canvas_page_next_requested", CANVAS_PAGE_PREVIOUS_REQUESTED = "canvas_page_previous_requested", CANVAS_OPEN_REQUESTED = "canvas_open_requested", CANVAS_CLOSE_REQUESTED = "canvas_close_requested", ROUTE_CHANGE_REQUESTED = "route_change_requested", ITEM_SHAREBOX_STATUS_REQUESTED = "item_sharebox_status_requested", ITEM_SHAREBOX_STATUS_UPDATED = "item_sharebox_status_updated", ITEM_SHAREBOX_ADD_REQUESTED = "item_sharebox_add_requested", ITEM_SHAREBOX_ADD_COMPLETED = "item_sharebox_add_completed", SYNC_BADGE_VALUE_REPORTED = "sync_badge_value_reported" } export declare enum PitcherBroadcastedEventName { UI_SHOW_MODAL = "ui:show-modal", UI_HIDE_MODAL = "ui:hide-modal", FAVORITES_CHANGED = "favorites:changed", FILE_DOWNLOAD = "file:download", CANVAS_NEXT_BUTTON_CLICKED = "canvas_next_button_clicked",// NOTE: This event is separate from `CANVAS_PAGE_NEXT_REQUESTED` CANVAS_PREVIOUS_BUTTON_CLICKED = "canvas_previous_button_clicked",// NOTE: This event is separate from `CANVAS_PAGE_PREVIOUS_REQUESTED` CANVAS_OPENED = "canvas_opened", CANVAS_CLOSED = "canvas_closed", ROUTE_CHANGED = "route_changed" } export declare enum PitcherExternalEventName { CREATE_AND_OPEN_CANVAS = "create_and_open_canvas", OPEN_CANVAS = "open_canvas", START_CALL = "start_call" } /** * Base interface for update location actions. */ interface UpdateLocation { /** * The action to be performed. */ action: string; } /** * Represents a route in the location. */ export interface LocationRoute { /** * The path of the route. */ path: string; /** * The query parameters of the route. */ query: Record; /** * Indicates if the route is being restored. */ is_restoring: boolean; /** * Indicates if the route is mounted. */ is_mounted: boolean; /** * Indicates when application is still registered but not used right now. */ is_inactive: boolean; } /** * A record of location routes. */ export type LocationRoutes = Record; /** * Interface for the 'register' update location action. */ export interface UpdateLocationOnRegister extends UpdateLocation { /** * The action type. */ action: 'register'; /** * The child application identifier. */ child_app: string; /** * The parent application identifier (optional). */ parent_app?: string; /** * The path of the route (optional). */ path?: string; /** * The query parameters of the route (optional). */ query?: Record; } /** * Interface for the 'unregister' update location action. */ export interface UpdateLocationOnUnregister extends UpdateLocation { /** * The action type. */ action: 'unregister'; /** * The application identifier. */ app: string; } /** * Interface for the 'update' update location action. */ export interface UpdateLocationOnUpdate extends UpdateLocation { /** * The action type. */ action: 'update'; /** * The routes to be updated. */ routes: Record>; } /** * Interface for the 'mounted' update location action. */ export interface UpdateLocationOnMounted extends UpdateLocation { /** * The action type. */ action: 'mounted'; /** * The application identifier. */ app: string; } /** * Interface for the 'restore' update location action. */ export interface UpdateLocationOnRestore extends UpdateLocation { /** * The action type. */ action: 'restore'; /** * The routes to be restored. */ routes: Record>; } /** * Interface for the 'restore_completed' update location action. */ export interface UpdateLocationOnRestoreCompleted extends UpdateLocation { /** * The action type. */ action: 'restore_completed'; /** * The application identifier. */ app: string; /** * The path of the route. */ path: string; /** * The query parameters of the route. */ query: Record; } /** * Interface for the 'get_routes_request' update location action. */ export interface UpdateLocationOnGetRoutesRequest extends UpdateLocation { /** * The action type. */ action: 'get_routes_request'; /** * The application identifier. */ app: string; } /** * Interface for the 'get_routes_response' update location action. */ export interface UpdateLocationOnGetRoutesResponse extends UpdateLocation { /** * The action type. */ action: 'get_routes_response'; /** * The application identifier. */ app: string; /** * The routes in the response. */ routes: LocationRoutes; } /** * Union type for all update location pitcher events. */ export type UpdateLocationPitcherEvent = UpdateLocationOnUnregister | UpdateLocationOnRestore | UpdateLocationOnUpdate | UpdateLocationOnRegister | UpdateLocationOnRestoreCompleted | UpdateLocationOnMounted | UpdateLocationOnGetRoutesRequest | UpdateLocationOnGetRoutesResponse; export interface PitcherEventMap { [PitcherEventName.ENV_CHANGED]: PitcherEnv; /** * @see iOS-only */ [PitcherEventName.PHOTOS_CAPTURED]: void; /** * @see iOS-only */ [PitcherEventName.GLOBAL_PHOTO_CAPTURED]: { url: string; section_id?: string; }; /** * @see iOS-only */ [PitcherEventName.NON_FILES_SYNC_FINISHED]: { user_triggered: boolean; }; /** * @see iOS-only */ [PitcherEventName.CONTENT_LIST_REFRESH_REQUESTED]: void; /** * @see iOS-only */ [PitcherEventName.FILE_DOWNLOADED]: File; /** * @see iOS-only */ [PitcherEventName.NETWORK_CONNECTION_ESTABLISHED]: void; /** * @see iOS-only */ [PitcherEventName.NETWORK_CONNECTION_LOST]: void; /** * @see iOS-only */ [PitcherEventName.FILE_UPLOAD_PROGRESS]: { upload_uid: string; progress: number; }; /** * @see iOS-only */ [PitcherEventName.ANALYTICS_CAPTURED]: { type: (typeof CDP_EVENT_TYPE)[keyof typeof CDP_EVENT_TYPE]; payload: any; }; /** * @see WEB-only */ [PitcherEventName.ENTERED_FULLSCREEN]: void; /** * @see WEB-only */ [PitcherEventName.EXITED_FULLSCREEN]: void; [PitcherEventName.CANVAS_UPDATED]: Record; [PitcherEventName.CANVAS_UPDATED_SUCCESS]: Partial; [PitcherEventName.UPDATE_LOCATION]: UpdateLocationPitcherEvent; [PitcherEventName.FILE_CLOSED]: { file_id?: string; view_id?: string; }; [PitcherEventName.FILE_OPENED]: { file_id?: string; view_id?: string; }; [PitcherEventName.SUBMIT_POSTCALL_CLICKED]: void; [PitcherEventName.CANVAS_PAGE_NEXT_REQUESTED]: { canvas_id?: string; current_page_index?: number; }; [PitcherEventName.CANVAS_PAGE_PREVIOUS_REQUESTED]: { canvas_id?: string; current_page_index?: number; }; [PitcherEventName.CANVAS_OPEN_REQUESTED]: { canvas_id?: string; }; [PitcherEventName.CANVAS_CLOSE_REQUESTED]: { canvas_id?: string; }; /** * @see iOS-only */ [PitcherEventName.ROUTE_CHANGE_REQUESTED]: RouteChangedPitcherEvent; [PitcherEventName.ITEM_SHAREBOX_STATUS_REQUESTED]: { item_id: string; }; [PitcherEventName.ITEM_SHAREBOX_STATUS_UPDATED]: { item_id: string; is_in_sharebox: boolean; }; [PitcherEventName.ITEM_SHAREBOX_ADD_REQUESTED]: { item_id: string; }; [PitcherEventName.ITEM_SHAREBOX_ADD_COMPLETED]: { item_id: string; success: boolean; is_in_sharebox: boolean; error?: string; }; /** * @see iOS-only */ [PitcherEventName.SYNC_BADGE_VALUE_REPORTED]: { count: number; }; [PitcherBroadcastedEventName.UI_SHOW_MODAL]: void; [PitcherBroadcastedEventName.UI_HIDE_MODAL]: void; [PitcherBroadcastedEventName.FAVORITES_CHANGED]: { body: PaginatedData; }; [PitcherBroadcastedEventName.FILE_DOWNLOAD]: { body: File['id']; }; [PitcherBroadcastedEventName.CANVAS_NEXT_BUTTON_CLICKED]: { body: { current_page_index: number; canvas_id?: string; }; }; [PitcherBroadcastedEventName.CANVAS_PREVIOUS_BUTTON_CLICKED]: { body: { current_page_index: number; canvas_id?: string; }; }; [PitcherBroadcastedEventName.CANVAS_OPENED]: { body: { canvas_id: string; }; }; [PitcherBroadcastedEventName.CANVAS_CLOSED]: { body: { canvas_id: string; }; }; [PitcherBroadcastedEventName.ROUTE_CHANGED]: { body: { route_name: string; route_path: string; }; }; [PitcherExternalEventName.OPEN_CANVAS]: OpenCanvasPitcherEvent; [PitcherExternalEventName.START_CALL]: StartCallPitcherEvent; [PitcherExternalEventName.CREATE_AND_OPEN_CANVAS]: CreateAndOpenCanvasEvent; } export interface PitcherEvent { type: keyof PitcherEventMap; body: PitcherEventMap[keyof PitcherEventMap]; } export interface ApiEventMap { event: PitcherEvent; } export {};