UNPKG

userorbit-js

Version:

Userorbit js allows you to connect your application to Userorbit, display announcements, roadmap, collect feedback, show product tours, and more.

178 lines (161 loc) 5.17 kB
import { z } from 'zod'; declare type designConfigType = { width?: string; brandColor?: string; widgetPlacement?: string; initialState?: "open" | "closed"; layout?: string; embedSelector?: string; customCss?: string; keepChecklistAlive?: boolean; embedToggle?: boolean; allTasksOpen?: boolean; backgroundColor?: string; borderColor?: string; textColor?: string; inputColor?: string; inputBackgroundColor?: string; inputBorderColor?: string; showAuthor?: boolean; showProgress?: boolean; disableBranding?: boolean; nextButtonColor?: string; nextButtonTextColor?: string; nextButtonBorderColor?: string; nextButtonHoverColor?: string; secondaryButtonColor?: string; secondaryButtonTextColor?: string; secondaryButtonBorderColor?: string; secondaryButtonHoverColor?: string; progressBgColor?: string; progressColor?: string; overlayColor?: string; overlayColorOpacity?: string; borderRadius?: string; boxShadow?: string; borderWidth?: string; } | null; export declare interface OpenWidgetOptions { tab?: "feedback" | "roadmap" | "updates" | "help"; announcementId?: string; roadmapId?: string; topicId?: string; articleId?: string; showFeedbackForm?: boolean; modal?: boolean; compact?: boolean; position?: "bottom-right" | "bottom-left" | "top-right"; } declare type SurveyFormType = { id: string; title: string; createdAt?: Date | null; creator?: { name?: string; email?: string; avatarUrl?: string; } | null; publishedAt?: Date | null; type?: string; publish?: boolean; triggers?: any; questions: { id?: string; order?: number; title: string; subheader?: string | null; type: "text" | "rating" | "dropdown" | "multi-select"; configuration?: { upperBoundLabel?: string; lowerBoundLabel?: string; choices: string[]; scaleType?: "number" | "emoji" | "start"; required?: boolean; scaleRange?: string; progressButtonText?: string; progressButtonPosition?: string; }; }[]; configuration?: { welcome?: any | null; ending?: any | null; design?: designConfigType; targeting?: { trigger?: string; frequency?: string; urlTarget?: string; urlPattern?: string; userSegment?: any; audience?: string; delay?: number; } | null; } | null; }; declare type SurveyPreviewProps = Omit<TourProps, "tour" | "account"> & { survey: SurveyFormType; account: string; activeQuestion?: number; setActiveQuestion?: (idx: number) => void; attributes?: any; }; declare type TJsConfigInput = z.infer<typeof ZJsConfigInput>; declare type TJsTrackProperties = z.infer<typeof ZJsTrackProperties>; declare type TourProps = { product: any; attributes: any; tour: any; account: string; restart?: boolean; closePreview?: () => void; onTourComplete?: () => void; }; export declare type TUserorbitApp = typeof userorbit; declare const userorbit: { init: (initConfig: TJsConfigInput) => Promise<void>; setEmail: (email: string) => Promise<void>; setAttribute: (key: string, value: any) => Promise<void>; track: (name: string, properties?: TJsTrackProperties) => Promise<void>; logout: () => Promise<void>; reset: () => Promise<void>; registerRouteChange: () => Promise<void>; getApi: () => (url: string, body: any) => Promise<any>; triggerSurvey: (props: SurveyPreviewProps) => any; openWidget: (options?: OpenWidgetOptions) => Promise<void>; updateTheme: (theme: "light" | "dark") => Promise<void>; startSurvey: (id: string) => Promise<void>; startTour: (id: string) => Promise<void>; startChecklist: (id: string) => Promise<void>; }; declare const userorbitApp: TUserorbitApp; export default userorbitApp; declare const ZJsConfigInput = z.object({ accountId: z.string().cuid2(), apiHost: z.string().optional(), errorHandler: z.function().args(z.any()).returns(z.void()).optional(), widgetMountSelector: z.string().optional(), floatingWidget: z.boolean().optional(), userId: z.string().optional(), email: z.string().optional(), name: z.string().optional(), attributes: z.record(z.string()).optional(), theme: z.enum(["light", "dark"]).optional(), analytics: z .object({ enabled: z.boolean().optional(), }) .optional(), widget: z .object({ theme: z.enum(["light", "dark"]).optional(), }) .optional(), }); declare const ZJsTrackProperties = z.object({ hiddenFields: ZResponseHiddenFieldValue.optional(), }); export { } declare global { interface Window { userorbit: TUserorbitApp | undefined; } }