@meacore/tauri-easy-updater 0.1.0 → 1.0.0

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.
package/dist/index.d.ts CHANGED
@@ -1,108 +1,224 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
1
+ import { U as UpdaterConfig, a as UpdaterState, b as UpdateInfo, D as DownloadResult, c as UpdateMode, P as PlatformSummary, I as InstallerFormat, d as PlatformManifestEntry, A as ArtifactInfo, e as UpdateManifest, f as UpdateChannel, g as UpdateProvider } from './types-DEGEuQ-i.js';
2
+ export { C as CheckUpdateIpcParams, h as DismissStorage, i as DownloadProgress, j as DownloadStage, M as ManifestArtifact, k as UpdaterError, l as UpdaterErrorCode, m as UpdaterStatus } from './types-DEGEuQ-i.js';
2
3
 
4
+ type UpdaterListener = (state: UpdaterState) => void;
3
5
  /**
4
- * Manifest structure used by the updater.
5
- */
6
- interface UpdateManifest {
7
- version: string;
8
- pub_date: string;
9
- notes: string;
10
- platforms: {
11
- [platform: string]: {
12
- url: string;
13
- };
14
- };
15
- }
16
- /**
17
- * Information about an available update exposed to the UI.
18
- */
19
- interface UpdateInfo {
20
- hasUpdate: boolean;
21
- currentVersion: string;
22
- latestVersion: string;
23
- downloadUrl: string;
24
- releaseNotes: string;
25
- pubDate: string;
26
- }
27
- /**
28
- * Provider interface used by the updater hook.
29
- */
30
- interface UpdateProvider {
31
- type: 'github' | 'http' | 's3';
32
- fetchManifest(): Promise<UpdateManifest>;
33
- }
34
- /**
35
- * Configuration options for the update checker hook.
6
+ * Framework-agnostic update manager supporting Tauri v2 native IPC (hybrid verified download +
7
+ * installer launch or safe browser open) and a hardened pure-JS web fallback.
8
+ *
9
+ * Works seamlessly with Vanilla JS, Vue, Svelte, Solid, Angular, or React (`useSyncExternalStore`).
36
10
  */
37
- interface UpdaterConfig {
38
- currentVersion: string;
39
- provider: UpdateProvider;
11
+ declare class UpdaterClient {
12
+ private readonly config;
13
+ private readonly storage;
14
+ private readonly listeners;
15
+ private state;
16
+ private inFlightCheck;
17
+ private activeDownloadId;
18
+ private pollTimer;
19
+ private unlistenProgress;
20
+ private disposed;
21
+ constructor(config?: UpdaterConfig);
22
+ /** Returns the current immutable state snapshot. */
23
+ getState(): UpdaterState;
24
+ /** Subscribes to state transitions. Returns an unsubscribe function. */
25
+ subscribe(listener: UpdaterListener): () => void;
26
+ /** Starts periodic update checks (`intervalMs > 0`). */
27
+ startPolling(intervalMs: number): void;
28
+ /** Stops periodic update checks. */
29
+ stopPolling(): void;
30
+ /** Releases timers and Tauri event listeners. */
31
+ dispose(): void;
40
32
  /**
41
- * Whether to check for updates on startup.
42
- * @default true
33
+ * Checks for an available update. Concurrent calls share the same in-flight promise.
43
34
  */
44
- checkOnStartup?: boolean;
35
+ check(): Promise<UpdateInfo | null>;
36
+ private performCheck;
37
+ private fetchUpdateInfo;
45
38
  /**
46
- * Interval in milliseconds between automatic checks.
47
- * `0` means only check on startup or when `checkNow` is called.
48
- * @default 0
39
+ * Downloads and verifies the currently available update inside Tauri (streaming + SHA-256/Ed25519).
49
40
  */
50
- checkIntervalMs?: number;
41
+ download(overrideInfo?: UpdateInfo): Promise<DownloadResult>;
51
42
  /**
52
- * When true, suppresses UI-driven side effects from errors.
53
- * Errors are still exposed via the hook return value.
54
- * @default false
43
+ * Cancels an active in-app download cleanly.
44
+ */
45
+ cancelDownload(): Promise<boolean>;
46
+ /**
47
+ * Launches the previously downloaded & verified installer (anti-TOCTOU re-verified in Rust).
48
+ */
49
+ install(downloadId?: string): Promise<void>;
50
+ /**
51
+ * Opens the verified HTTPS update URL in the user's default browser (lightweight mode).
55
52
  */
56
- silent?: boolean;
53
+ openDownloadUrl(urlOverride?: string): Promise<void>;
54
+ /**
55
+ * Applies the available update according to the configured `mode` (`hybrid`, `download`, or `browser`).
56
+ */
57
+ applyUpdate(modeOverride?: UpdateMode): Promise<void>;
58
+ /**
59
+ * Dismisses the currently available update for this session.
60
+ * Ignored if the update is `mandatory`.
61
+ */
62
+ dismiss(): void;
63
+ private attachProgressListener;
64
+ private detachProgressListener;
65
+ private readDismissedVersion;
66
+ private writeDismissedVersion;
67
+ private setState;
57
68
  }
69
+ /**
70
+ * Convenience factory for creating a framework-agnostic `UpdaterClient`.
71
+ */
72
+ declare function createUpdaterClient(config?: UpdaterConfig): UpdaterClient;
58
73
 
59
74
  /**
60
- * Returns the current platform identifier used in update manifests.
61
- *
62
- * Values:
63
- * - "windows-x86_64"
64
- * - "darwin-x86_64"
65
- * - "darwin-aarch64"
66
- * - "linux-x86_64"
75
+ * Returns `true` when executing inside a Tauri v2 WebView.
76
+ */
77
+ declare function isTauriRuntime(): boolean;
78
+ /**
79
+ * Normalizes OS strings from Tauri, Node, or browser user agents into
80
+ * manifest OS keys (`windows`, `darwin`, `linux`).
67
81
  *
68
- * If called outside a Tauri context (e.g. SSR), it resolves to an empty string.
82
+ * Properly maps `'Darwin'`, `'macos'`, `'macOS'` -> `'darwin'` (fixing v0.1 bug).
83
+ */
84
+ declare function normalizeOs(os: string): string;
85
+ /**
86
+ * Normalizes architecture strings into canonical manifest keys (`x86_64`, `aarch64`).
87
+ */
88
+ declare function normalizeArch(arch: string): string;
89
+ /**
90
+ * Infers an installer format from a URL or filename.
91
+ */
92
+ declare function inferInstallerFormat(urlOrFilename: string): InstallerFormat | null;
93
+ /**
94
+ * Queries the current host platform summary from the Tauri v2 plugin,
95
+ * falling back to safe browser/navigator heuristics outside Tauri.
96
+ */
97
+ declare function getPlatformSummary(): Promise<PlatformSummary | null>;
98
+ /**
99
+ * Returns the canonical current platform key (e.g. `darwin-aarch64`, `windows-x86_64`, `linux-x86_64`),
100
+ * or an empty string in SSR environments.
69
101
  */
70
102
  declare function getCurrentPlatform(): Promise<string>;
103
+ /**
104
+ * Selects the matching platform entry from a manifest, including `darwin-universal` fallback on macOS.
105
+ */
106
+ declare function selectPlatformFromManifest(manifest: UpdateManifest, platformKey: string): {
107
+ key: string;
108
+ entry: PlatformManifestEntry;
109
+ } | null;
110
+ /**
111
+ * Resolves the primary artifact and complete artifacts list from a manifest platform entry,
112
+ * honoring `preferredFormat` when present.
113
+ */
114
+ declare function resolveArtifactsFromPlatform(entry: PlatformManifestEntry, preferredFormat?: InstallerFormat): {
115
+ primary: ArtifactInfo;
116
+ all: ArtifactInfo[];
117
+ };
71
118
 
119
+ interface ParsedSemver {
120
+ major: number;
121
+ minor: number;
122
+ patch: number;
123
+ prerelease: string[];
124
+ build: string | null;
125
+ }
72
126
  /**
73
- * Returns true if `latest` represents a strictly newer version than `current`.
74
- *
75
- * - Handles an optional `v` prefix (e.g. `v1.2.3`).
76
- * - Supports prerelease segments (e.g. `1.2.3-beta.1`).
77
- * - Falls back to `false` if parsing fails.
127
+ * Strictly parses a SemVer 2.0.0 version string (with optional leading `v`/`V`).
128
+ * Supports multi-hyphen prereleases (`1.0.0-rc-1.2`) and build metadata (`1.0.0+build.42`).
129
+ * Rejects malformed inputs (`1..0`, `-1.0.0`, `01.0.0`, empty strings).
130
+ */
131
+ declare function parseSemver(input: string): ParsedSemver | null;
132
+ /**
133
+ * Compares two SemVer 2.0.0 versions per spec (build metadata ignored in precedence).
134
+ * Returns `1` if `a > b`, `-1` if `a < b`, `0` if equal, or `null` if either is invalid.
135
+ */
136
+ declare function compareSemver(a: string, b: string): -1 | 0 | 1 | null;
137
+ /**
138
+ * Returns `true` if `latest` is strictly newer than `current`.
139
+ * Returns `false` if either version fails strict SemVer 2.0.0 parsing.
78
140
  */
79
141
  declare function isNewerVersion(latest: string, current: string): boolean;
142
+ /**
143
+ * Returns `true` if `current` is strictly older than `minVersion`.
144
+ */
145
+ declare function isBelowMinVersion(current: string, minVersion: string): boolean;
146
+
147
+ /**
148
+ * Returns `true` if `rawUrl` is a safe remote URL (`https:` by default, no credentials,
149
+ * no control characters or shell metacharacters).
150
+ */
151
+ declare function isSafeRemoteUrl(rawUrl: string, allowInsecureHttp?: boolean): boolean;
152
+ /**
153
+ * Validates `rawUrl` and throws a typed `UpdaterError` on unsafe schemes or syntax.
154
+ */
155
+ declare function assertSafeRemoteUrl(rawUrl: string, allowInsecureHttp?: boolean): string;
156
+ /**
157
+ * Validates a GitHub owner or repository name to prevent path traversal or query injection.
158
+ */
159
+ declare function assertValidGitHubIdent(value: string, fieldName: string): void;
160
+ /**
161
+ * Runtime schema validator for update manifests received over the network.
162
+ */
163
+ declare function validateManifest(data: unknown, allowInsecureHttp?: boolean): UpdateManifest;
164
+ /**
165
+ * Performs `fetch` with an explicit `AbortController` timeout.
166
+ */
167
+ declare function fetchWithTimeout(url: string, init?: RequestInit, timeoutMs?: number): Promise<Response>;
80
168
 
81
169
  interface GitHubProviderConfig {
82
170
  owner: string;
83
171
  repo: string;
172
+ /**
173
+ * Asset name for the JSON update manifest attached to the release.
174
+ * @default "update-manifest.json"
175
+ */
84
176
  manifestAssetName?: string;
85
177
  /**
86
- * If true, falls back to the GitHub Releases API when the manifest
87
- * asset is not found.
178
+ * If true, falls back to the GitHub Releases API when the manifest asset is missing (404).
88
179
  * @default true
89
180
  */
90
181
  fallbackToReleaseApi?: boolean;
182
+ /**
183
+ * Release channel (`stable` | `beta` | `alpha` | custom).
184
+ * @default "stable"
185
+ */
186
+ channel?: UpdateChannel;
187
+ /**
188
+ * Preferred installer format when multiple formats exist for the current OS.
189
+ */
190
+ preferredFormat?: InstallerFormat;
191
+ /**
192
+ * Timeout in milliseconds for pure-JS fallback fetches.
193
+ * @default 15000
194
+ */
195
+ timeoutMs?: number;
91
196
  }
92
197
  /**
93
- * Creates an update provider backed by GitHub Releases.
94
- *
95
- * It tries to download a manifest asset first and, if not found,
96
- * optionally falls back to the Releases API.
198
+ * Creates a GitHub Releases update provider with full Tauri v2 IPC forwarding
199
+ * and hardened pure-JS fallback.
97
200
  */
98
201
  declare function createGitHubProvider(config: GitHubProviderConfig): UpdateProvider;
99
202
 
100
203
  interface HttpProviderConfig {
101
204
  manifestUrl: string;
102
205
  headers?: Record<string, string>;
206
+ channel?: UpdateChannel;
207
+ preferredFormat?: InstallerFormat;
208
+ /**
209
+ * Allow plain `http://` URLs for local development only.
210
+ * @default false
211
+ */
212
+ allowInsecureHttp?: boolean;
213
+ /**
214
+ * Timeout in milliseconds for pure-JS fallback fetches.
215
+ * @default 15000
216
+ */
217
+ timeoutMs?: number;
103
218
  }
104
219
  /**
105
- * Creates a generic HTTP(S) update provider backed by a direct manifest URL.
220
+ * Creates a generic HTTPS update provider backed by a direct JSON manifest URL.
221
+ * Forwards `headers`, `channel`, and `preferredFormat` to the Rust plugin.
106
222
  */
107
223
  declare function createHttpProvider(config: HttpProviderConfig): UpdateProvider;
108
224
 
@@ -110,45 +226,18 @@ interface S3ProviderConfig {
110
226
  bucketUrl: string;
111
227
  /**
112
228
  * Path to the manifest inside the bucket.
113
- * @default "latest/update-manifest.json"
229
+ * Defaults to `"latest/update-manifest.json"` for `stable` or `"<channel>/update-manifest.json"`.
114
230
  */
115
231
  manifestPath?: string;
232
+ channel?: UpdateChannel;
233
+ preferredFormat?: InstallerFormat;
234
+ headers?: Record<string, string>;
235
+ allowInsecureHttp?: boolean;
236
+ timeoutMs?: number;
116
237
  }
117
238
  /**
118
- * Creates a provider that resolves a manifest served from S3-like storage.
239
+ * Creates a provider for update manifests hosted on S3, Cloudflare R2, or CloudFront.
119
240
  */
120
241
  declare function createS3Provider(config: S3ProviderConfig): UpdateProvider;
121
242
 
122
- /**
123
- * React hook that checks for updates using the configured provider and the Tauri plugin.
124
- */
125
- declare function useUpdateChecker(config: UpdaterConfig): {
126
- updateInfo: UpdateInfo | null;
127
- isChecking: boolean;
128
- error: Error | null;
129
- checkNow: () => Promise<void>;
130
- dismiss: () => void;
131
- isDismissed: boolean;
132
- };
133
-
134
- type Theme$1 = 'light' | 'dark' | 'auto';
135
- interface UpdateBannerProps {
136
- updateInfo: UpdateInfo;
137
- onDismiss: () => void;
138
- position?: 'top' | 'bottom';
139
- theme?: Theme$1;
140
- className?: string;
141
- }
142
- declare function UpdateBanner(props: UpdateBannerProps): react_jsx_runtime.JSX.Element;
143
-
144
- type Theme = 'light' | 'dark' | 'auto';
145
- interface UpdateModalProps {
146
- updateInfo: UpdateInfo;
147
- onDismiss: () => void;
148
- appName?: string;
149
- theme?: Theme;
150
- className?: string;
151
- }
152
- declare function UpdateModal(props: UpdateModalProps): react_jsx_runtime.JSX.Element;
153
-
154
- export { type GitHubProviderConfig, type HttpProviderConfig, type S3ProviderConfig, UpdateBanner, type UpdateBannerProps, type UpdateInfo, type UpdateManifest, UpdateModal, type UpdateModalProps, type UpdateProvider, type UpdaterConfig, createGitHubProvider, createHttpProvider, createS3Provider, getCurrentPlatform, isNewerVersion, useUpdateChecker };
243
+ export { ArtifactInfo, DownloadResult, type GitHubProviderConfig, type HttpProviderConfig, InstallerFormat, type ParsedSemver, PlatformManifestEntry, PlatformSummary, type S3ProviderConfig, UpdateChannel, UpdateInfo, UpdateManifest, UpdateMode, UpdateProvider, UpdaterClient, UpdaterConfig, type UpdaterListener, UpdaterState, assertSafeRemoteUrl, assertValidGitHubIdent, compareSemver, createGitHubProvider, createHttpProvider, createS3Provider, createUpdaterClient, fetchWithTimeout, getCurrentPlatform, getPlatformSummary, inferInstallerFormat, isBelowMinVersion, isNewerVersion, isSafeRemoteUrl, isTauriRuntime, normalizeArch, normalizeOs, parseSemver, resolveArtifactsFromPlatform, selectPlatformFromManifest, validateManifest };