Types
All types are exported from @swiftpatch/react-native.
SwiftPatchUserConfig
Configuration passed to withSwiftPatch. Most apps need no config at all.
interface SwiftPatchUserConfig {
deploymentKey?: string; // Override native config deployment key
debug?: boolean; // Enable verbose logging (default: false)
onUpdate?: (update: ReleaseInfo) => void; // Callback when a new deploy is available
}
Usage:
// Zero config
export default withSwiftPatch(App);
// With options
export default withSwiftPatch(App, {
deploymentKey: 'dk_xxx',
debug: __DEV__,
onUpdate: (update) => console.log('New deploy!', update),
});
InstallMode
When to apply downloaded updates.
enum InstallMode {
IMMEDIATE = 'immediate', // Install and restart immediately
ON_NEXT_RESTART = 'onNextRestart', // Install on next app restart
ON_NEXT_RESUME = 'onNextResume', // Install when app resumes from background (default)
}
UpdateStatus
Current state of the update lifecycle.
enum UpdateStatus {
CHECKING = 'checking',
UP_TO_DATE = 'upToDate',
UPDATE_AVAILABLE = 'updateAvailable',
DOWNLOADING = 'downloading',
READY_TO_INSTALL = 'readyToInstall',
INSTALLING = 'installing',
RESTART_REQUIRED = 'restartRequired',
ERROR = 'error',
}
ReleaseInfo
An available update returned by checkForUpdate().
interface ReleaseInfo {
id: string; // Unique release ID
version: string; // Semantic version (e.g., "1.2.3")
releaseNote: string | null; // Release notes
isMandatory: boolean; // Whether this update is mandatory
bundleHash: string; // SHA-256 hash of the bundle
downloadUrl: string; // URL to the patch or full bundle
downloadSize: number; // Size in bytes
isPatch: boolean; // true = differential patch, false = full bundle
signature?: string; // JWT signature (if bundle signing enabled)
releasedAt: string; // ISO 8601 timestamp
}
BundleInfo
The currently installed bundle.
interface BundleInfo {
hash: string; // SHA-256 hash
version: string; // Version string
installedAt: string; // ISO 8601 timestamp
isOriginal: boolean; // true = stock bundle from the app binary
}
DownloadProgress
interface DownloadProgress {
downloadedBytes: number; // Bytes downloaded so far
totalBytes: number; // Total bytes to download
percentage: number; // Progress 0-100
}
SwiftPatchError
interface SwiftPatchError {
code: SwiftPatchErrorCode;
message: string;
details?: unknown;
}
SwiftPatchErrorCode
enum SwiftPatchErrorCode {
NETWORK_ERROR = 'NETWORK_ERROR',
DOWNLOAD_ERROR = 'DOWNLOAD_ERROR',
VERIFICATION_ERROR = 'VERIFICATION_ERROR',
PATCH_ERROR = 'PATCH_ERROR',
INSTALL_ERROR = 'INSTALL_ERROR',
CONFIG_ERROR = 'CONFIG_ERROR',
UNKNOWN_ERROR = 'UNKNOWN_ERROR',
}
SwiftPatchState
State from useSwiftPatch().
interface SwiftPatchState {
status: UpdateStatus;
downloadProgress: DownloadProgress | null;
currentBundle: BundleInfo | null;
availableUpdate: ReleaseInfo | null;
isRestartRequired: boolean;
error: SwiftPatchError | null;
lastCheckedAt: Date | null;
}
SwiftPatchActions
Actions from useSwiftPatch().
interface SwiftPatchActions {
checkForUpdate: () => Promise<ReleaseInfo | null>;
downloadUpdate: () => Promise<void>;
installUpdate: () => Promise<void>;
restart: () => void;
rollback: () => Promise<void>;
clearPendingUpdate: () => Promise<void>;
getCurrentBundle: () => Promise<BundleInfo | null>;
markMounted: () => void;
}
UseSwiftPatchReturn
Combined return type of useSwiftPatch().
type UseSwiftPatchReturn = SwiftPatchState & SwiftPatchActions;
UseSwiftPatchUpdateReturn
Return type of useSwiftPatchUpdate().
interface UseSwiftPatchUpdateReturn {
isRestartRequired: boolean;
newReleaseBundle: ReleaseInfo | null;
currentBundle: BundleInfo | null;
status: UpdateStatus;
restart: () => void;
}
UseSwiftPatchModalReturn
Return type of useSwiftPatchModal().
interface UseSwiftPatchModalReturn {
showModal: () => void;
hideModal: () => void;
isModalVisible: boolean;
}
NativeConfig
Configuration read from native files (Info.plist on iOS, strings.xml on Android).
interface NativeConfig {
projectId: string | null; // SwiftPatchProjectId
appToken: string | null; // SwiftPatchAppToken (starts with 'at_...')
appId: string | null; // SwiftPatchAppId
deploymentKey: string | null; // SwiftPatchDeploymentKey
serverUrl: string | null; // SwiftPatchServerUrl
publicKey: string | null; // SwiftPatchPublicKey
}
SwiftPatchEventType
Events emitted from the native layer.
enum SwiftPatchEventType {
DOWNLOAD_PROD_STARTED = 'DOWNLOAD_PROD_STARTED',
DOWNLOAD_PROD_COMPLETED = 'DOWNLOAD_PROD_COMPLETED',
DOWNLOAD_PROD_FAILED = 'DOWNLOAD_PROD_FAILED',
INSTALLED_PROD = 'INSTALLED_PROD',
ROLLBACK_PROD = 'ROLLBACK_PROD',
STABILIZE_PROD = 'STABILIZE_PROD',
CORRUPTION_PROD = 'CORRUPTION_PROD',
SYNC_ERROR = 'SYNC_ERROR',
VERSION_CHANGED = 'VERSION_CHANGED',
CRASH_DETECTED = 'CRASH_DETECTED',
}
SwiftPatchEvent
A queued SDK event.
interface SwiftPatchEvent {
id: string;
eventType: SwiftPatchEventType;
timestamp: number;
releaseHash?: string;
errorMessage?: string;
metadata?: Record<string, unknown>;
}
Internals
These types are used internally. They're exported for advanced use cases but may change without notice.
SwiftPatchConfig (Internal)
The full internal config. Most apps should use SwiftPatchUserConfig instead.
/** @internal */
interface SwiftPatchConfig {
appId?: string;
deploymentKey?: string;
serverUrl?: string;
checkOnResume?: boolean;
checkInterval?: number;
installMode?: InstallMode;
mandatoryInstallMode?: InstallMode;
debug?: boolean;
customHeaders?: Record<string, string>;
publicKey?: string;
autoStabilizeAfterLaunches?: number;
sdkPin?: string;
crashDetectionWindowMs?: number;
maxCrashesBeforeRollback?: number;
autoStagingInDev?: boolean;
onUpdate?: (update: ReleaseInfo) => void;
}
EnvironmentMode (Internal)
/** @internal */
enum EnvironmentMode {
PRODUCTION = 'PROD',
STAGING = 'STAGE',
}
SlotState (Internal)
Bundle slot states.
/** @internal */
enum SlotState {
DEFAULT_SLOT = 'DEFAULT_SLOT',
STABLE_SLOT = 'STABLE_SLOT',
NEW_SLOT = 'NEW_SLOT',
}
SlotMetadata (Internal)
/** @internal */
interface SlotMetadata {
environment: EnvironmentMode;
prod: {
currentSlot: SlotState;
newHash: string | null;
stableHash: string | null;
tempHash: string | null;
};
stage: {
newHash: string | null;
};
}