import { SDK_VERSION } from './norrix-telemetry';
export { SDK_VERSION };
export interface UpdateInfo {
    updateAvailable: boolean;
    platform?: string;
    version?: string;
    buildNumber?: string;
    releaseNotes?: string;
    url?: string;
    expiresAt?: string;
    timestamp?: Date;
    message?: any;
    requiresStoreUpdate?: boolean;
    compatibilityReason?: string;
    /**
     * If true, this update is a rollback to an older version.
     * The server marks an update as a rollback when the active update
     * is older than what the client currently has installed.
     */
    isRollback?: boolean;
    /**
     * Which of the client's requested tags matched this update.
     * Empty array if no tags were requested or this is a fallback update.
     */
    matchedTags?: string[];
    /**
     * Whether this update was selected based on tag matching.
     * False if this is a fallback to the default active update.
     */
    isTaggedUpdate?: boolean;
}
export declare enum SyncStatus {
    /**
     * The application is up to date.
     */
    UP_TO_DATE = "UP_TO_DATE",
    /**
     * An update is available, it has been downloaded, unzipped and copied to the deployment folder.
     * After the completion of the callback invoked with SyncStatus.UPDATE_INSTALLED, the application will be reloaded with the updated code and resources.
     */
    UPDATE_INSTALLED = "UPDATE_INSTALLED",
    /**
     * An optional update is available, but the user declined to install it. The update was not downloaded.
     */
    UPDATE_IGNORED = "UPDATE_IGNORED",
    /**
     * An error happened during the sync operation. This might be an error while communicating with the server, downloading or unziping the update.
     * The console logs should contain more information about what happened. No update has been applied in this case.
     */
    ERROR = "ERROR",
    /**
     * Returned if HMR is enabled and not overridden by the user.
     */
    SKIPPING_BECAUSE_HMR_ENABLED = "SKIPPING_BECAUSE_HMR_ENABLED",
    /**
     * There is an ongoing sync in progress, so this attempt to sync has been aborted.
     */
    IN_PROGRESS = "IN_PROGRESS",
    /**
     * Intermediate status - the plugin is about to check for updates.
     */
    CHECKING_FOR_UPDATE = "CHECKING_FOR_UPDATE",
    /**
     * Intermediate status - a user dialog is about to be displayed. This status will be reported only if user interaction is enabled.
     */
    AWAITING_USER_ACTION = "AWAITING_USER_ACTION",
    /**
     * Intermediate status - the update package is about to be downloaded.
     */
    DOWNLOADING_PACKAGE = "DOWNLOADING_PACKAGE",
    /**
     * Intermediate status - the update package is about to be installed.
     */
    INSTALLING_UPDATE = "INSTALLING_UPDATE",
    /**
     * Intermediate status - the native runtime is being recreated to load the installed update.
     */
    RELOADING_APP = "RELOADING_APP",
    /**
     * The installed update could not be loaded through the native soft reboot API.
     */
    RELOAD_FAILED = "RELOAD_FAILED"
}
type StatusCallback = (status: SyncStatus, data?: UpdateInfo) => void;
type DownloadProgressCallback = (progress: number) => void;
export type ApplyUpdateMode = 'soft-reboot' | 'process-restart' | 'next-launch';
export interface ApplyUpdateOptions {
    /**
     * How to activate the installed OTA.
     * - soft-reboot: recreate the NativeScript JS runtime in the current process.
     * - process-restart: use the existing restart-page/process-exit behavior.
     * - next-launch: leave the update installed and activate on the next cold launch.
     */
    mode?: ApplyUpdateMode;
    /**
     * When true, show the built-in confirmation dialog before applying now.
     * Defaults to `promptToRestartAfterInstall`.
     */
    prompt?: boolean;
    /**
     * When soft reboot is unavailable or fails to schedule, fall back to process restart.
     * Defaults to true.
     */
    fallbackToProcessRestart?: boolean;
}
export interface ApplyUpdateResult {
    applied: boolean;
    mode: ApplyUpdateMode;
    fallbackUsed?: boolean;
    message?: string;
}
/**
 * Details about a fingerprint mismatch between binary and update.
 */
export interface FingerprintMismatchDetails {
    /**
     * List of native plugins that differ between binary and update.
     */
    changedPlugins: Array<{
        name: string;
        binaryVersion?: string;
        updateVersion?: string;
    }>;
    /**
     * Whether the App_Resources hash differs.
     */
    appResourcesChanged: boolean;
    /**
     * Whether the NativeSource hash differs.
     */
    nativeSourcesChanged: boolean;
    /**
     * The raw compatibility reason string from the server.
     */
    rawReason: string;
}
/**
 * Callback to dynamically decide whether to allow a fingerprint mismatch.
 * Return true to allow the update, false to block it.
 */
type FingerprintMismatchCallback = (details: FingerprintMismatchDetails) => boolean | Promise<boolean>;
export interface UpdateConfig {
    /**
     * Base URL for your Norrix OTA update server.
     * Used to build the check-for-update and download endpoints.
     */
    updateUrl: string;
    /**
     * If true, the SDK will automatically call `checkForUpdates()`
     * when `NorrixUpdates` is constructed.
     */
    checkForUpdatesOnLaunch?: boolean;
    /**
     * If true and an update is available (and allowed), the SDK will
     * automatically download it and install the update without the
     * host app needing to call these methods manually.
     * The update will be activated the next time the app is launched.
     * You can also auto prompt the user to restart with:
     * promptToRestartAfterInstall
     */
    installUpdatesAutomatically?: boolean;
    /**
     * When the server flags an update as `requiresStoreUpdate`, this
     * option lets you override that and still apply it over-the-air.
     * If false (default), such updates are ignored for OTA installs.
     * Warning: use this only if you are sure the update is compatible
     * with the existing store binary.
     *
     * For granular control, use `allowedDependencyOverrides` instead.
     */
    allowStoreUpdateOverride?: boolean;
    /**
     * List of specific native plugin names that are safe to allow OTA
     * updates for, even when their versions change. This provides granular
     * control over which dependencies can be overridden.
     *
     * When a fingerprint mismatch occurs:
     * - If ALL changed plugins are in this list, the update is allowed
     * - If ANY changed plugin is NOT in this list, the update is blocked
     * - App_Resources and NativeSource changes are controlled separately
     *
     * Example: ['@nativescript/core', '@mycompany/js-only-plugin']
     */
    allowedDependencyOverrides?: string[];
    /**
     * If true, allow OTA updates even when App_Resources hash differs.
     * Use with extreme caution - App_Resources contain native configuration.
     * Default: false
     */
    allowAppResourcesOverride?: boolean;
    /**
     * If true, allow OTA updates even when NativeSource hash differs.
     * Use with extreme caution - NativeSource contains native code.
     * Default: false
     */
    allowNativeSourcesOverride?: boolean;
    /**
     * Advanced: Callback invoked when a fingerprint mismatch is detected
     * and granular overrides are configured. Return true to allow the
     * update, false to block it.
     *
     * This callback is called AFTER checking allowedDependencyOverrides,
     * allowAppResourcesOverride, and allowNativeSourcesOverride. It gives
     * you final say over whether to allow the update.
     */
    onFingerprintMismatch?: FingerprintMismatchCallback;
    /**
     * Callback invoked whenever the sync status changes (for example
     * when checking, downloading, installing, or when an error occurs).
     */
    statusCallback?: StatusCallback;
    /**
     * Callback invoked with download progress (0-100) while the OTA
     * package is being unzipped / installed.
     */
    downloadProgressCallback?: DownloadProgressCallback;
    /**
     * If true (default is false), the SDK will prompt the end user with a
     * confirmation dialog before restarting the app after a successful
     * OTA install. When false, the OTA update will activate the next
     * time the app is restarted.
     */
    promptToRestartAfterInstall?: boolean;
    /**
     * How automatically installed updates should be activated when the user
     * chooses to apply them now. Defaults to `soft-reboot`.
     */
    applyUpdateMode?: ApplyUpdateMode;
    /**
     * When true (default), a failed or unsupported soft reboot falls back to
     * the existing restart-page/process-exit behavior.
     */
    fallbackToProcessRestart?: boolean;
    /**
     * If true (default is true), the SDK will report telemetry events
     * to the Norrix server for OTA efficacy tracking. Events include:
     * - Check for updates
     * - Download started/completed
     * - Install started/completed
     * - App launch with OTA active
     * - Store update prompts and user responses
     *
     * Telemetry helps you understand OTA adoption rates and identify issues.
     * Set to false to disable telemetry reporting.
     */
    enableTelemetry?: boolean;
    /**
     * Your Norrix organization ID. Used to customize the restart page
     * shown to users after an OTA update is installed.
     * Get this from your Norrix dashboard.
     */
    orgId?: string;
    /**
     * If true (default is true), the SDK will open a restart page after
     * the app closes to help users relaunch the app automatically.
     * The restart page (restart.norrix.net) opens in the browser and
     * redirects back to your app using the bundle ID URL scheme.
     * Set to false to disable this behavior.
     */
    useRestartPage?: boolean;
    /**
     * Tags to filter updates by. When specified, the SDK will only
     * apply updates that have at least one matching tag.
     *
     * Use cases:
     * - A/B testing: `tags: ['experiment-new-checkout']`
     * - User segments: `tags: ['beta-testers', 'premium-users']`
     * - Feature flags: `tags: ['feature-dark-mode']`
     */
    tags?: string[];
    /**
     * When true, ALL specified tags must be present on an update
     * for it to match (AND logic). Default is false (OR logic).
     */
    requireAllTags?: boolean;
    /**
     * When true and no tagged update is found, fall back to the
     * default active update. When false, skip updates entirely
     * if no matching tags found.
     *
     * Default: true
     */
    allowUntaggedFallback?: boolean;
}
export declare class NorrixUpdates {
    private config;
    private bundleId;
    private currentVersion;
    private currentBuild;
    private statusCallback?;
    private downloadProgressCallback?;
    private updateInProgress?;
    constructor(config: UpdateConfig);
    /**
     * Parse the compatibility reason from the server to extract mismatch details.
     * The server returns reasons like:
     * - "Plugin version mismatch: @nativescript/core (9.0.3 -> 9.0.5)"
     * - "App_Resources hash differs"
     * - "NativeSource hash differs"
     *
     * @param compatibilityReason The raw reason string from the server
     * @returns Parsed mismatch details
     */
    private _parseMismatchDetails;
    /**
     * Determine if an update with a fingerprint mismatch should be allowed
     * based on the granular override configuration.
     *
     * @param update The update info from the server
     * @returns true if the update should be allowed, false otherwise
     */
    private _shouldAllowMismatchedUpdate;
    /**
     * Utility to get the current native binary fingerprint hash.
     *
     * The fingerprint is the immutable identity of the native binary, baked in
     * at build time. It reads from:
     * - iOS: Info.plist -> NorrixFingerprintHash
     * - Android: BuildConfig.norrixFingerprintHash
     *
     * This is the single source of truth for fingerprint validation. OTA updates
     * cannot modify this value since it's embedded in the native binary.
     *
     * For backward compatibility, if the native fingerprint is not found, we
     * fall back to reading from the assets file (for older builds).
     *
     * @returns fingerprint hash for the native binary
     */
    getCurrentFingerprintHash(): string | undefined;
    /**
     * Get the current configuration (deployment target) from native resources.
     *
     * This identifies which environment (e.g., 'stg', 'prod', 'dev') the binary
     * was built for. OTA updates should only be applied if they match the
     * binary's configuration to prevent staging updates from being applied
     * to production apps (or vice versa).
     *
     * Note: The native resource keys remain `NorrixNxConfiguration` (iOS) and `norrixNxConfiguration` (Android)
     * for backward compatibility with existing deployed apps.
     *
     * @returns configuration string for the native binary (e.g., 'stg', 'prod'), or undefined
     */
    getCurrentConfiguration(): string | undefined;
    /**
     * @deprecated Use getCurrentConfiguration() instead. This method is kept for backward compatibility.
     */
    getCurrentNxConfiguration(): string | undefined;
    /**
     * Check for available updates from the server.
     */
    checkForUpdates(): Promise<UpdateInfo>;
    /**
     * Full sync operation: check for updates, download, and install if available.
     *
     * This method respects the `installUpdatesAutomatically` config option.
     * Use this method when you want the SDK to handle the full update flow,
     * for example on app resume or when the user triggers a manual check.
     *
     * @returns The update info from the server
     */
    sync(): Promise<UpdateInfo>;
    /**
     * Download an update from the server.
     */
    downloadUpdate(update: UpdateInfo): Promise<boolean>;
    /**
     * Utility to clear all OTA updates and prompt user to close app.
     * This will reset the app back to the original binary installed version.
     */
    resetAllOTAs(): void;
    /**
     * Apply a downloaded update.
     * By default, this preserves the current behavior: installed updates activate
     * on the next cold launch unless promptToRestartAfterInstall or an explicit
     * apply mode is provided. Passing true keeps the legacy process-restart path.
     */
    applyUpdate(closeAppNowOrOptions?: boolean | ApplyUpdateOptions): Promise<ApplyUpdateResult>;
    private softRebootApp;
    private requestNativeScriptReload;
    private getNativeScriptRuntimeApi;
    private prepareNativeBundleForReload;
    private getRestartBaseUrl;
    /**
     * Utility to close the app.
     * Useful when handling updates that require a restart with user prompts.
     * When useRestartPage is enabled (default), opens a restart page that
     * helps users automatically relaunch the app.
     */
    closeAppNow(): void;
    private _getPlatform;
}
//# sourceMappingURL=norrix-updates.d.ts.map