@o/native-hot-update 0.16.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +212 -0
  2. package/dist/cjs/createHotUpdater.cjs +224 -0
  3. package/dist/cjs/createHotUpdater.native.js +250 -0
  4. package/dist/cjs/createHotUpdater.native.js.map +1 -0
  5. package/dist/cjs/helpers.cjs +40 -0
  6. package/dist/cjs/helpers.native.js +43 -0
  7. package/dist/cjs/helpers.native.js.map +1 -0
  8. package/dist/cjs/index.cjs +31 -0
  9. package/dist/cjs/index.native.js +34 -0
  10. package/dist/cjs/index.native.js.map +1 -0
  11. package/dist/cjs/mmkv.cjs +34 -0
  12. package/dist/cjs/mmkv.native.js +43 -0
  13. package/dist/cjs/mmkv.native.js.map +1 -0
  14. package/dist/cjs/types.cjs +18 -0
  15. package/dist/cjs/types.native.js +21 -0
  16. package/dist/cjs/types.native.js.map +1 -0
  17. package/dist/esm/createHotUpdater.mjs +188 -0
  18. package/dist/esm/createHotUpdater.mjs.map +1 -0
  19. package/dist/esm/createHotUpdater.native.js +211 -0
  20. package/dist/esm/createHotUpdater.native.js.map +1 -0
  21. package/dist/esm/helpers.mjs +14 -0
  22. package/dist/esm/helpers.mjs.map +1 -0
  23. package/dist/esm/helpers.native.js +14 -0
  24. package/dist/esm/helpers.native.js.map +1 -0
  25. package/dist/esm/index.js +4 -0
  26. package/dist/esm/index.js.map +1 -0
  27. package/dist/esm/index.mjs +4 -0
  28. package/dist/esm/index.mjs.map +1 -0
  29. package/dist/esm/index.native.js +4 -0
  30. package/dist/esm/index.native.js.map +1 -0
  31. package/dist/esm/mmkv.mjs +9 -0
  32. package/dist/esm/mmkv.mjs.map +1 -0
  33. package/dist/esm/mmkv.native.js +15 -0
  34. package/dist/esm/mmkv.native.js.map +1 -0
  35. package/dist/esm/types.mjs +2 -0
  36. package/dist/esm/types.mjs.map +1 -0
  37. package/dist/esm/types.native.js +2 -0
  38. package/dist/esm/types.native.js.map +1 -0
  39. package/package.json +67 -0
  40. package/src/createHotUpdater.ts +250 -0
  41. package/src/helpers.ts +23 -0
  42. package/src/index.ts +6 -0
  43. package/src/mmkv.ts +20 -0
  44. package/src/types.ts +66 -0
package/src/helpers.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { HotUpdater } from '@hot-updater/react-native'
2
+
3
+ const INITIAL_OTA_ID = '00000000-0000-0000-0000-000000000000'
4
+
5
+ /**
6
+ * Get the currently applied OTA bundle ID.
7
+ * Returns null if running native build (no OTA applied).
8
+ */
9
+ export function getAppliedOta(): string | null {
10
+ const id = HotUpdater.getBundleId()
11
+ if (id === INITIAL_OTA_ID) return null
12
+ if (id === HotUpdater.getMinBundleId()) return null
13
+ return id
14
+ }
15
+
16
+ /**
17
+ * Get a short version of the OTA ID (last 12 characters).
18
+ * Returns null if running native build.
19
+ */
20
+ export function getShortOtaId(): string | null {
21
+ const fullId = getAppliedOta()
22
+ return fullId ? fullId.slice(-12) : null
23
+ }
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ // Re-export HotUpdater for app usage
2
+ export { HotUpdater, useHotUpdaterStore } from '@hot-updater/react-native'
3
+
4
+ // Package exports
5
+ export { createHotUpdater } from './createHotUpdater'
6
+ export type * from './types'
package/src/mmkv.ts ADDED
@@ -0,0 +1,20 @@
1
+ import type { HotUpdateStorage } from './types'
2
+ import type { MMKV } from 'react-native-mmkv'
3
+
4
+ /**
5
+ * Create a storage adapter for MMKV.
6
+ *
7
+ * @example
8
+ * import { MMKV } from 'react-native-mmkv'
9
+ * import { createMMKVStorage } from '@o/native-hot-update/mmkv'
10
+ *
11
+ * const mmkv = new MMKV({ id: 'hot-updater' })
12
+ * const storage = createMMKVStorage(mmkv)
13
+ */
14
+ export function createMMKVStorage(mmkv: MMKV): HotUpdateStorage {
15
+ return {
16
+ get: (key: string) => mmkv.getString(key),
17
+ set: (key: string, value: string) => mmkv.set(key, value),
18
+ delete: (key: string) => mmkv.delete(key),
19
+ }
20
+ }
package/src/types.ts ADDED
@@ -0,0 +1,66 @@
1
+ /** Simple key-value storage interface */
2
+ export interface HotUpdateStorage {
3
+ get(key: string): string | undefined
4
+ set(key: string, value: string): void
5
+ delete(key: string): void
6
+ }
7
+
8
+ export interface HotUpdaterConfig {
9
+ /** Storage for persisting update state */
10
+ storage: HotUpdateStorage
11
+ /** Update strategy (default: 'appVersion') */
12
+ updateStrategy?: 'appVersion' | 'fingerprint'
13
+ }
14
+
15
+ export interface UpdateInfo {
16
+ id: string
17
+ isCriticalUpdate: boolean
18
+ fileUrl: string | null
19
+ message: string | null
20
+ }
21
+
22
+ export interface HotUpdaterInstance {
23
+ /** React hook for automatic update checking */
24
+ useOtaUpdater: (options?: {
25
+ enabled?: boolean
26
+ onUpdateDownloaded?: (info: UpdateInfo) => void
27
+ onError?: (error: unknown) => void
28
+ }) => {
29
+ userClearedForAccess: boolean
30
+ progress: number
31
+ isUpdatePending: boolean
32
+ }
33
+
34
+ /** Manually check for updates (for dev/testing) */
35
+ checkForUpdate: (options?: {
36
+ channel?: string
37
+ isPreRelease?: boolean
38
+ }) => Promise<UpdateInfo | null>
39
+
40
+ /** Get currently applied OTA bundle ID (null if native) */
41
+ getAppliedOta: () => string | null
42
+
43
+ /** Get short version of OTA ID */
44
+ getShortOtaId: () => string | null
45
+
46
+ /** Check if update is pending (will apply on restart) */
47
+ getIsUpdatePending: () => boolean
48
+
49
+ /** Reload the app to apply update */
50
+ reload: () => void
51
+
52
+ /** Get current bundle ID */
53
+ getBundleId: () => string
54
+
55
+ /** Get minimum bundle ID (native build time) */
56
+ getMinBundleId: () => string
57
+
58
+ /** Get current channel */
59
+ getChannel: () => string
60
+
61
+ /** Clear crash history to allow retrying failed bundles */
62
+ clearCrashHistory: () => boolean
63
+
64
+ /** Get list of crashed bundle IDs */
65
+ getCrashHistory: () => string[]
66
+ }