@freshworks/react-native-freshdesk-sdk
Version:
React Native wrapper for Freshdesk Android and iOS SDKs
271 lines (245 loc) • 7.14 kB
text/typescript
/**
* Native error codes rejected on the promises returned by FreshdeskSDK methods.
* Read `error.code` (React Native's standard `NativeModule` rejection shape) and
* compare against this enum instead of matching the string literal directly.
*
* Coverage is not identical on both platforms — some codes are method-specific
* on Android and folded into a shared code on iOS, or vice versa. Codes marked
* (Android) / (iOS) are only ever rejected on that platform; unmarked codes can
* occur on either.
*/
export enum FreshdeskErrorCode {
/** initialize() timed out waiting for the native SDK to report ready. (Android) */
INIT_TIMEOUT = 'FRESHDESK_INIT_TIMEOUT',
/** initialize() threw before it could start. (Android) */
INIT_ERROR = 'FRESHDESK_INIT_ERROR',
/** initialize()'s config object was missing a required key or malformed. */
INVALID_CONFIG = 'FRESHDESK_INVALID_CONFIG',
/** A method other than initialize() was called before initialize() resolved. */
NOT_INITIALIZED = 'FRESHDESK_NOT_INITIALIZED',
/** initialize() resolved but the underlying native SDK isn't ready yet. (Android) */
NOT_READY = 'FRESHDESK_NOT_READY',
/** openSupport()/openKnowledgeBase()/openTopic() had no foreground Activity to attach to. (Android) */
NO_ACTIVITY = 'FRESHDESK_NO_ACTIVITY',
/** openSupport()/openKnowledgeBase()/openTopic() had no view controller to present from. (iOS) */
NO_VIEW_CONTROLLER = 'FRESHDESK_NO_VIEW_CONTROLLER',
/** openSupport()/openKnowledgeBase()/openTopic() failed to present the native UI. (Android) */
OPEN_ERROR = 'FRESHDESK_OPEN_ERROR',
/** trackEvent() failed. (Android) */
TRACK_ERROR = 'FRESHDESK_TRACK_ERROR',
/** setUserProperties() failed. */
USER_PROPERTIES_ERROR = 'FRESHDESK_USER_PROPERTIES_ERROR',
/** setTicketProperties() failed. (Android) */
TICKET_PROPERTIES_ERROR = 'FRESHDESK_TICKET_PROPERTIES_ERROR',
/** authenticateAndUpdate() failed. (Android) */
AUTH_ERROR = 'FRESHDESK_AUTH_ERROR',
/** dismiss() failed. (Android) */
DISMISS_ERROR = 'FRESHDESK_DISMISS_ERROR',
/** getUser() failed, or its response could not be parsed. */
USER_ERROR = 'FRESHDESK_USER_ERROR',
/** getUser()'s response could not be parsed. (iOS) */
USER_PARSE_ERROR = 'FRESHDESK_USER_PARSE_ERROR',
/** setContentConfiguration()'s JSON payload could not be parsed. */
CONFIG_PARSE_ERROR = 'FRESHDESK_CONFIG_PARSE_ERROR',
}
/**
* Freshdesk SDK Configuration
*/
export interface FreshdeskConfig {
/** Account token from Freshdesk portal */
token: string;
/** Host URL for your Freshdesk instance */
host: string;
/** SDK ID from Freshdesk portal */
sdkId: string;
/** Locale for localization (e.g., 'en', 'ar') */
locale?: string;
/** JWT token for authenticated users */
jwt?: string;
/** Enable debug logging (Android only) */
debugMode?: boolean;
}
/**
* User authentication states
*/
export enum UserState {
/** Default state */
UNDEFINED = 'undefined',
/** JWT passed is successfully authenticated or restored */
AUTHENTICATED = 'authenticated',
/** JWT passed has expired */
AUTH_EXPIRED = 'authExpired',
/** Invalid/Expired token is passed */
NOT_AUTHENTICATED = 'notAuthenticated',
/** Unique user identifier updated for a user */
IDENTIFIER_UPDATED = 'identifierUpdated',
/** JWT was not passed during init for an enforced JWT SDK linked Widget */
JWT_ABSENT = 'jwtAbsent',
}
/**
* Topic information for opening specific support topics
*/
export interface TopicInfo {
/** The name of the topic */
topicName: string;
/** The ID of the topic (optional) */
topicId?: string;
}
/**
* Event payload for unread count changes
*/
export interface UnreadCountEvent {
count: number;
}
/**
* Event payload for user state changes
*/
export interface UserStateEvent {
state: UserState;
}
/**
* Event payload for link handler
*/
export interface LinkPressedEvent {
url: string;
}
/**
* Event payload for user creation
*/
export interface UserCreatedEvent {
user: Record<string, unknown>;
}
/**
* Properties for setting user details
*/
export type UserProperties = Record<string, string | number | boolean>;
/**
* Properties for setting ticket details
*/
export type TicketProperties = Record<string, string | number | boolean>;
/**
* Event properties for tracking
*/
export type EventProperties = Record<string, string | number>;
/**
* Result of reset user operation
*/
export interface ResetUserResult {
success: boolean;
message?: string;
error?: string;
}
/**
* Channel response time configuration
*/
export interface ChannelResponseTimeUnit {
one?: string;
more?: string;
}
/**
* Channel response online configuration
*/
export interface ChannelResponseOnline {
defaultMessage?: string;
minutes?: ChannelResponseTimeUnit;
hours?: ChannelResponseTimeUnit;
}
/**
* Channel response configuration
*/
export interface ChannelResponseContent {
offline?: string;
online?: ChannelResponseOnline;
}
/**
* Ticket form content configuration
*/
export interface TicketFormContent {
title?: string;
submitBtnTitle?: string;
}
/**
* Header content configuration
*/
export interface HeaderContent {
chat?: string;
faq?: string;
faqMessageUs?: string;
faqNotAvailable?: string;
faqSearchNotAvailable?: string;
faqThankyou?: string;
faqUseful?: string;
faqNotUseful?: string;
channelResponse?: ChannelResponseContent;
ticketForm?: TicketFormContent;
typicallyRepliesFewMinsFallback?: string;
}
/**
* Placeholder content configuration
*/
export interface PlaceholderContent {
replyField?: string;
searchField?: string;
}
/**
* Privacy policy content configuration
*/
export interface PrivacyPolicyContent {
privacyPolicyMessage?: string;
privacyPolicyLinkText?: string;
privacyPolicyLink?: string;
}
/**
* Action content configuration
*/
export interface ActionContent {
tabChat?: string;
}
/**
* Content configuration for customizing SDK UI text
*/
export interface ContentConfiguration {
headers?: HeaderContent;
placeholders?: PlaceholderContent;
privacyPolicySetting?: PrivacyPolicyContent;
actions?: ActionContent;
additionalFields?: Record<string, unknown>;
}
/**
* User data returned from getUser
*/
export interface UserData {
[key: string]: unknown;
}
/**
* SDK version information
*/
export interface SDKVersion {
version: string;
}
/**
* Diagnostic check status returned by runDiagnostics
*/
export type DiagnosticStatus = 'pass' | 'warn' | 'fail' | 'skipped';
/**
* A single diagnostic check from runDiagnostics
*/
export interface DiagnosticCheck {
id: string;
status: DiagnosticStatus;
details: string;
fixHint: string;
}
/**
* Structured diagnostic report from runDiagnostics
*/
export interface DiagnosticReport {
overallStatus: DiagnosticStatus | string;
checks: DiagnosticCheck[];
prettyPrinted: string;
platform: 'ios' | 'android';
/** Which React Native architecture the native module is running under */
architecture?: 'old' | 'new';
/** Whether the native module was resolved as a TurboModule */
turboModule?: boolean;
}