99 * @see zephyr-xpack-internal for runtime plugin implementation
1010 */
1111
12- /* eslint-disable @typescript-eslint/no-explicit-any */
1312/* eslint-disable no-var */
1413
1514/** Zephyr manifest structure for runtime updates */
1615export interface ZephyrRuntimeManifest {
16+ /** Semantic version of the manifest format */
1717 version : string ;
18+ /** Unix timestamp when manifest was generated */
1819 timestamp : number ;
20+ /** Map of remote module names to their resolved URLs */
1921 dependencies ?: Record < string , string > ;
22+ /** Additional manifest metadata */
2023 [ key : string ] : unknown ;
2124}
2225
@@ -26,29 +29,94 @@ export type ZephyrManifestChangeCallback = (
2629 oldManifest : ZephyrRuntimeManifest | null
2730) => void ;
2831
32+ /**
33+ * Configuration options for creating the Zephyr runtime plugin.
34+ * Passed to createZephyrRuntimePlugin from zephyr-xpack-internal.
35+ */
36+ export interface ZephyrRuntimePluginOptions {
37+ /** URL endpoint to fetch the manifest from (e.g., '/zephyr-manifest.json') */
38+ manifestUrl : string ;
39+ /** Polling interval in milliseconds for checking manifest updates (optional) */
40+ pollInterval ?: number ;
41+ /** Whether to automatically apply updates when manifest changes (optional) */
42+ autoUpdate ?: boolean ;
43+ }
44+
45+ /**
46+ * Interface for the Zephyr runtime plugin instance.
47+ * Created by zephyr-xpack-internal's createZephyrRuntimePlugin function.
48+ *
49+ * Note: The actual implementation is in zephyr-xpack-internal which is an
50+ * optional peer dependency. If not installed, runtime features will be
51+ * disabled but the app will continue to work.
52+ */
53+ export interface ZephyrRuntimePlugin {
54+ /** Manually fetch and apply the latest manifest */
55+ refresh ( ) : Promise < void > ;
56+ /** Get the current manifest */
57+ getManifest ( ) : ZephyrRuntimeManifest | null ;
58+ /** Register a callback for manifest changes */
59+ onManifestChange ( callback : ZephyrManifestChangeCallback ) : ( ) => void ;
60+ /** Start polling for manifest updates */
61+ startPolling ( interval ?: number ) : void ;
62+ /** Stop polling for manifest updates */
63+ stopPolling ( ) : void ;
64+ /** Check if the plugin is initialized */
65+ isInitialized ( ) : boolean ;
66+ }
67+
2968declare global {
3069 /**
31- * Zephyr runtime plugin instance - created by zephyr-xpack-internal. Used for OTA
32- * updates and remote module resolution.
70+ * Zephyr runtime plugin instance - created by zephyr-xpack-internal.
71+ * Used for OTA updates and remote module resolution.
72+ *
73+ * This global is set by the code injected by zephyr-transformer.ts
74+ * when the app starts. It will be undefined if:
75+ * - zephyr-xpack-internal is not installed
76+ * - The runtime plugin failed to initialize
77+ * - The code hasn't been executed yet
3378 */
34- var __ZEPHYR_RUNTIME_PLUGIN__ : unknown | undefined ;
79+ var __ZEPHYR_RUNTIME_PLUGIN__ : ZephyrRuntimePlugin | undefined ;
3580
3681 /**
37- * Zephyr runtime plugin singleton tracker. Prevents multiple initializations in the
38- * same runtime.
82+ * Zephyr runtime plugin singleton tracker.
83+ * Prevents multiple initializations in the same runtime.
84+ * Set to the same instance as __ZEPHYR_RUNTIME_PLUGIN__ after initialization.
3985 */
40- var __ZEPHYR_RUNTIME_PLUGIN_INSTANCE__ : unknown | undefined ;
86+ var __ZEPHYR_RUNTIME_PLUGIN_INSTANCE__ : ZephyrRuntimePlugin | undefined ;
4187
4288 /**
43- * Optional callback invoked when the manifest changes. Can be set by application code
44- * to react to OTA updates.
89+ * Optional callback invoked when the manifest changes.
90+ * Can be set by application code to react to OTA updates.
91+ *
92+ * @example
93+ * ```typescript
94+ * global.__ZEPHYR_MANIFEST_CHANGED__ = (newManifest, oldManifest) => {
95+ * console.log('Manifest updated:', newManifest.version);
96+ * // Trigger app reload or notify user
97+ * };
98+ * ```
4599 */
46100 var __ZEPHYR_MANIFEST_CHANGED__ : ZephyrManifestChangeCallback | undefined ;
47101
102+ /**
103+ * Module Federation global config set by Metro bundler.
104+ * Used by zephyrCommandWrapper to access the MF configuration.
105+ */
106+ var __METRO_FEDERATION_CONFIG :
107+ | {
108+ name : string ;
109+ filename ?: string ;
110+ remotes ?: Record < string , string > ;
111+ exposes ?: Record < string , string > ;
112+ shared ?: Record < string , unknown > ;
113+ }
114+ | undefined ;
115+
48116 // Browser/Web environment support (for React Native Web)
49117 interface Window {
50- __ZEPHYR_RUNTIME_PLUGIN__ ?: unknown ;
51- __ZEPHYR_RUNTIME_PLUGIN_INSTANCE__ ?: unknown ;
118+ __ZEPHYR_RUNTIME_PLUGIN__ ?: ZephyrRuntimePlugin ;
119+ __ZEPHYR_RUNTIME_PLUGIN_INSTANCE__ ?: ZephyrRuntimePlugin ;
52120 __ZEPHYR_MANIFEST_CHANGED__ ?: ZephyrManifestChangeCallback ;
53121 }
54122}
0 commit comments