electron-incremental-update 0.7.7 → 0.7.8

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.
@@ -31,7 +31,14 @@ var verify = (buffer, signature2, cert) => {
31
31
  }
32
32
  };
33
33
 
34
+ // src/updateJson.ts
35
+ function isUpdateJSON(json) {
36
+ const is = (j) => "signature" in j && "version" in j && "size" in j && "minimumVersion" in j;
37
+ return is(json) && "beta" in json && is(json.beta);
38
+ }
39
+
34
40
  export {
35
41
  signature,
36
- verify
42
+ verify,
43
+ isUpdateJSON
37
44
  };
@@ -20,9 +20,20 @@ function getEntryVersion() {
20
20
  function getProductVersion(name) {
21
21
  return app.isPackaged ? readFileSync(join(getProductAsarPath(name), "version"), "utf-8") : getEntryVersion();
22
22
  }
23
+ var NoSuchNativeModuleError = class extends Error {
24
+ moduleName;
25
+ constructor(moduleName) {
26
+ super(`no such native module: ${moduleName}`);
27
+ this.moduleName = moduleName;
28
+ }
29
+ };
23
30
  function requireNative(packageName) {
24
31
  const path = app.isPackaged ? join(app.getAppPath(), "node_modules", packageName) : packageName;
25
- return __require(path);
32
+ try {
33
+ return __require(path);
34
+ } catch (error) {
35
+ throw new NoSuchNativeModuleError(packageName);
36
+ }
26
37
  }
27
38
  function parseGithubCdnURL(repository, cdnPrefix, relativeFilePath) {
28
39
  if (!repository.startsWith("https://github.com/")) {
@@ -114,12 +125,25 @@ function handleUnexpectedErrors(callback) {
114
125
  process.on("uncaughtException", listener);
115
126
  process.on("unhandledRejection", listener);
116
127
  }
128
+ function parseVersion(version) {
129
+ const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
130
+ const match = semver.exec(version);
131
+ if (!match) {
132
+ throw new TypeError(`invalid version: ${version}`);
133
+ }
134
+ const [major, minor, patch] = match.slice(1, 4).map(Number);
135
+ if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
136
+ throw new TypeError(`invalid version: ${version}`);
137
+ }
138
+ return { major, minor, patch, stage: match[4] };
139
+ }
117
140
 
118
141
  export {
119
142
  __require,
120
143
  getProductAsarPath,
121
144
  getEntryVersion,
122
145
  getProductVersion,
146
+ NoSuchNativeModuleError,
123
147
  requireNative,
124
148
  parseGithubCdnURL,
125
149
  getGithubFileCdnGroup,
@@ -128,5 +152,6 @@ export {
128
152
  waitAppReady,
129
153
  unzipFile,
130
154
  zipFile,
131
- handleUnexpectedErrors
155
+ handleUnexpectedErrors,
156
+ parseVersion
132
157
  };
package/dist/index.d.mts CHANGED
@@ -1,33 +1,47 @@
1
1
  import { Buffer } from 'node:buffer';
2
+ import { U as UpdateJSON } from './updateJson-7e45d9e1.js';
2
3
 
3
- type CheckResultType = Omit<UpdateJSON, 'signature'> | undefined | Error;
4
- type InstallResult = true | Error;
4
+ declare class MinimumVersionError extends Error {
5
+ currentVersion: string;
6
+ minVersion: string;
7
+ constructor(version: string, minimumVersion: string);
8
+ }
9
+ declare class VerifyFailedError extends Error {
10
+ signature: string;
11
+ cert: string;
12
+ constructor(signature: string, cert: string);
13
+ }
14
+ /**
15
+ * Creates an updater based on the provided options
16
+ */
17
+ declare function createUpdater(updaterOptions: UpdaterOption): Updater;
18
+
19
+ type CheckResultType = {
20
+ size: number;
21
+ version: string;
22
+ } | undefined | Error | MinimumVersionError | TypeError;
23
+ type DownloadResult = true | Error | VerifyFailedError | TypeError;
5
24
  type UpdateEvents = {
6
25
  downloading: [progress: number];
7
26
  downloadBuffer: [buffer: Buffer];
8
27
  debug: [msg: string | Error];
9
28
  };
10
- type UpdateJSON = {
11
- signature: string;
12
- version: string;
13
- size: number;
14
- };
15
- type MaybeArray<T> = T extends undefined | null | never ? [] : T extends any[] ? T['length'] extends 1 ? [data: T[0]] : T : [data: T];
16
- interface TypedUpdater<T extends Record<string | symbol, MaybeArray<any>>, Event extends Exclude<keyof T, number> = Exclude<keyof T, number>> {
17
- removeAllListeners<E extends Event>(event?: E): this;
18
- listeners<E extends Event>(eventName: E): Function[];
19
- eventNames(): (Event)[];
20
- on<E extends Event>(eventName: E, listener: (...data: MaybeArray<T[E]>) => void): this;
21
- once<E extends Event>(eventName: E, listener: (...data: MaybeArray<T[E]>) => void): this;
22
- emit<E extends Event>(eventName: E, ...args: MaybeArray<T[E]>): boolean;
23
- off<E extends Event>(eventName: E, listener: (...args: MaybeArray<T[E]>) => void): this;
29
+ type Evt = Exclude<keyof UpdateEvents, number>;
30
+ interface Updater {
31
+ removeAllListeners<E extends Evt>(event?: E): this;
32
+ listeners<E extends Evt>(eventName: E): Function[];
33
+ eventNames(): Evt[];
34
+ on<E extends Evt>(eventName: E, listener: (...data: UpdateEvents[E]) => void): this;
35
+ once<E extends Evt>(eventName: E, listener: (...data: UpdateEvents[E]) => void): this;
36
+ emit<E extends Evt>(eventName: E, ...args: UpdateEvents[E]): boolean;
37
+ off<E extends Evt>(eventName: E, listener: (...args: UpdateEvents[E]) => void): this;
24
38
  /**
25
39
  * check update info
26
40
  * @param data update json url
27
41
  * @returns
28
42
  * - `{size: number, version: string}`: available
29
43
  * - `false`: unavailable
30
- * - `Error`: fail
44
+ * - `Error`: fail ({@link MinimumVersionError} or other)
31
45
  */
32
46
  checkUpdate(data?: string | UpdateJSON): Promise<CheckResultType>;
33
47
  /**
@@ -38,15 +52,60 @@ interface TypedUpdater<T extends Record<string | symbol, MaybeArray<any>>, Event
38
52
  * @param sig signature
39
53
  * @returns
40
54
  * - `true`: success
41
- * - `Error`: fail
55
+ * - `Error`: fail ({@link VerifyFailedError} or other)
42
56
  */
43
- download(data?: string | Buffer, sig?: string): Promise<InstallResult>;
44
- debugMode: boolean;
57
+ download(data?: string | Buffer, sig?: string): Promise<DownloadResult>;
58
+ debug: boolean;
45
59
  productName: string;
60
+ receiveBeta: boolean;
46
61
  }
47
- type FunctionVerifySignature = (buffer: Buffer, signature: string, cert: string) => string | false;
48
- type FunctionCompareVersion = (oldVersion: string, newVersion: string) => boolean;
49
- type Updater = TypedUpdater<UpdateEvents>;
62
+ type FunctionVerifySignature = (buffer: Buffer, signature: string, cert: string) => string | false | Promise<string | false>;
63
+ type FunctionCompareVersion = (oldVersion: string, newVersion: string) => boolean | Promise<boolean>;
64
+ type FunctionDownloadBuffer = (url: string, updater: Updater, headers: Record<string, any>) => Promise<Buffer>;
65
+ type FunctionDownloadJSON = (url: string, updater: Updater, headers: Record<string, any>) => Promise<UpdateJSON>;
66
+ type UpdaterOverrideFunctions = {
67
+ /**
68
+ * custom version compare function {@link FunctionCompareVersion}
69
+ * @param oldVersion old version string
70
+ * @param newVersion new version string
71
+ * @returns whether oldVersion < newVersion
72
+ */
73
+ compareVersion?: FunctionCompareVersion;
74
+ /**
75
+ * custom verify signature function {@link FunctionVerifySignature}
76
+ * @param buffer file buffer
77
+ * @param signature signature
78
+ * @param cert certificate
79
+ */
80
+ verifySignaure?: FunctionVerifySignature;
81
+ /**
82
+ * custom download JSON function
83
+ * @param url download url
84
+ * @param updater updater, to trigger events
85
+ * @param header download header
86
+ * @returns `UpdateJSON`
87
+ */
88
+ downloadJSON?: FunctionDownloadJSON;
89
+ /**
90
+ * custom download buffer function
91
+ * @param url download url
92
+ * @param updater updater, to trigger events
93
+ * @param header download header
94
+ * @returns `Buffer`
95
+ */
96
+ downloadBuffer?: FunctionDownloadBuffer;
97
+ };
98
+ type UpdaterDownloadConfig = {
99
+ /**
100
+ * download user agent
101
+ * @default 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36'
102
+ */
103
+ userAgent?: string;
104
+ /**
105
+ * extra download header, `accept` and `user-agent` is set by default
106
+ */
107
+ extraHeader?: Record<string, string>;
108
+ };
50
109
  interface UpdaterOption {
51
110
  /**
52
111
  * public key of signature, which will be auto generated by plugin
@@ -93,56 +152,14 @@ interface UpdaterOption {
93
152
  * whether to enable debug listener
94
153
  */
95
154
  debug?: boolean;
96
- overrideFunctions?: {
97
- /**
98
- * custom version compare function {@link FunctionCompareVersion}
99
- * @param oldVersion old version string
100
- * @param newVersion new version string
101
- * @returns whether oldVersion < newVersion
102
- */
103
- compareVersion?: FunctionCompareVersion;
104
- /**
105
- * custom verify signature function {@link FunctionVerifySignature}
106
- * @param buffer file buffer
107
- * @param signature signature
108
- * @param cert certificate
109
- */
110
- verifySignaure?: FunctionVerifySignature;
111
- /**
112
- * custom download JSON function
113
- * @param url download url
114
- * @param updater updater, to trigger events
115
- * @param header download header
116
- * @returns `UpdateJSON`
117
- */
118
- downloadJSON?: (url: string, updater: Updater, headers: Record<string, any>) => Promise<UpdateJSON>;
119
- /**
120
- * custom download buffer function
121
- * @param url download url
122
- * @param updater updater, to trigger events
123
- * @param header download header
124
- * @returns `Buffer`
125
- */
126
- downloadBuffer?: (url: string, updater: Updater, headers: Record<string, any>) => Promise<Buffer>;
127
- };
128
- downloadConfig?: {
129
- /**
130
- * download user agent
131
- * @default 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36'
132
- */
133
- userAgent?: string;
134
- /**
135
- * extra download header, `accept` and `user-agent` is set by default
136
- */
137
- extraHeader?: Record<string, string>;
138
- };
155
+ /**
156
+ * whether to receive beta update
157
+ */
158
+ receiveBeta?: boolean;
159
+ overrideFunctions?: UpdaterOverrideFunctions;
160
+ downloadConfig?: UpdaterDownloadConfig;
139
161
  }
140
162
 
141
- /**
142
- * Creates an updater based on the provided options
143
- */
144
- declare function createUpdater(updaterOptions: UpdaterOption): Updater;
145
-
146
163
  type AppOption = {
147
164
  /**
148
165
  * path of electron output dist when in development
@@ -194,4 +211,4 @@ type SetUpdater = {
194
211
  */
195
212
  declare function initApp(appOptions?: AppOption): SetUpdater;
196
213
 
197
- export { AppOption, FunctionCompareVersion, FunctionVerifySignature, StartupWithUpdater, UpdateJSON, Updater, UpdaterOption, createUpdater, initApp };
214
+ export { AppOption, FunctionCompareVersion, FunctionVerifySignature, MinimumVersionError, StartupWithUpdater, Updater, UpdaterOption, VerifyFailedError, createUpdater, initApp };
package/dist/index.d.ts CHANGED
@@ -1,33 +1,47 @@
1
1
  import { Buffer } from 'node:buffer';
2
+ import { U as UpdateJSON } from './updateJson-7e45d9e1.js';
2
3
 
3
- type CheckResultType = Omit<UpdateJSON, 'signature'> | undefined | Error;
4
- type InstallResult = true | Error;
4
+ declare class MinimumVersionError extends Error {
5
+ currentVersion: string;
6
+ minVersion: string;
7
+ constructor(version: string, minimumVersion: string);
8
+ }
9
+ declare class VerifyFailedError extends Error {
10
+ signature: string;
11
+ cert: string;
12
+ constructor(signature: string, cert: string);
13
+ }
14
+ /**
15
+ * Creates an updater based on the provided options
16
+ */
17
+ declare function createUpdater(updaterOptions: UpdaterOption): Updater;
18
+
19
+ type CheckResultType = {
20
+ size: number;
21
+ version: string;
22
+ } | undefined | Error | MinimumVersionError | TypeError;
23
+ type DownloadResult = true | Error | VerifyFailedError | TypeError;
5
24
  type UpdateEvents = {
6
25
  downloading: [progress: number];
7
26
  downloadBuffer: [buffer: Buffer];
8
27
  debug: [msg: string | Error];
9
28
  };
10
- type UpdateJSON = {
11
- signature: string;
12
- version: string;
13
- size: number;
14
- };
15
- type MaybeArray<T> = T extends undefined | null | never ? [] : T extends any[] ? T['length'] extends 1 ? [data: T[0]] : T : [data: T];
16
- interface TypedUpdater<T extends Record<string | symbol, MaybeArray<any>>, Event extends Exclude<keyof T, number> = Exclude<keyof T, number>> {
17
- removeAllListeners<E extends Event>(event?: E): this;
18
- listeners<E extends Event>(eventName: E): Function[];
19
- eventNames(): (Event)[];
20
- on<E extends Event>(eventName: E, listener: (...data: MaybeArray<T[E]>) => void): this;
21
- once<E extends Event>(eventName: E, listener: (...data: MaybeArray<T[E]>) => void): this;
22
- emit<E extends Event>(eventName: E, ...args: MaybeArray<T[E]>): boolean;
23
- off<E extends Event>(eventName: E, listener: (...args: MaybeArray<T[E]>) => void): this;
29
+ type Evt = Exclude<keyof UpdateEvents, number>;
30
+ interface Updater {
31
+ removeAllListeners<E extends Evt>(event?: E): this;
32
+ listeners<E extends Evt>(eventName: E): Function[];
33
+ eventNames(): Evt[];
34
+ on<E extends Evt>(eventName: E, listener: (...data: UpdateEvents[E]) => void): this;
35
+ once<E extends Evt>(eventName: E, listener: (...data: UpdateEvents[E]) => void): this;
36
+ emit<E extends Evt>(eventName: E, ...args: UpdateEvents[E]): boolean;
37
+ off<E extends Evt>(eventName: E, listener: (...args: UpdateEvents[E]) => void): this;
24
38
  /**
25
39
  * check update info
26
40
  * @param data update json url
27
41
  * @returns
28
42
  * - `{size: number, version: string}`: available
29
43
  * - `false`: unavailable
30
- * - `Error`: fail
44
+ * - `Error`: fail ({@link MinimumVersionError} or other)
31
45
  */
32
46
  checkUpdate(data?: string | UpdateJSON): Promise<CheckResultType>;
33
47
  /**
@@ -38,15 +52,60 @@ interface TypedUpdater<T extends Record<string | symbol, MaybeArray<any>>, Event
38
52
  * @param sig signature
39
53
  * @returns
40
54
  * - `true`: success
41
- * - `Error`: fail
55
+ * - `Error`: fail ({@link VerifyFailedError} or other)
42
56
  */
43
- download(data?: string | Buffer, sig?: string): Promise<InstallResult>;
44
- debugMode: boolean;
57
+ download(data?: string | Buffer, sig?: string): Promise<DownloadResult>;
58
+ debug: boolean;
45
59
  productName: string;
60
+ receiveBeta: boolean;
46
61
  }
47
- type FunctionVerifySignature = (buffer: Buffer, signature: string, cert: string) => string | false;
48
- type FunctionCompareVersion = (oldVersion: string, newVersion: string) => boolean;
49
- type Updater = TypedUpdater<UpdateEvents>;
62
+ type FunctionVerifySignature = (buffer: Buffer, signature: string, cert: string) => string | false | Promise<string | false>;
63
+ type FunctionCompareVersion = (oldVersion: string, newVersion: string) => boolean | Promise<boolean>;
64
+ type FunctionDownloadBuffer = (url: string, updater: Updater, headers: Record<string, any>) => Promise<Buffer>;
65
+ type FunctionDownloadJSON = (url: string, updater: Updater, headers: Record<string, any>) => Promise<UpdateJSON>;
66
+ type UpdaterOverrideFunctions = {
67
+ /**
68
+ * custom version compare function {@link FunctionCompareVersion}
69
+ * @param oldVersion old version string
70
+ * @param newVersion new version string
71
+ * @returns whether oldVersion < newVersion
72
+ */
73
+ compareVersion?: FunctionCompareVersion;
74
+ /**
75
+ * custom verify signature function {@link FunctionVerifySignature}
76
+ * @param buffer file buffer
77
+ * @param signature signature
78
+ * @param cert certificate
79
+ */
80
+ verifySignaure?: FunctionVerifySignature;
81
+ /**
82
+ * custom download JSON function
83
+ * @param url download url
84
+ * @param updater updater, to trigger events
85
+ * @param header download header
86
+ * @returns `UpdateJSON`
87
+ */
88
+ downloadJSON?: FunctionDownloadJSON;
89
+ /**
90
+ * custom download buffer function
91
+ * @param url download url
92
+ * @param updater updater, to trigger events
93
+ * @param header download header
94
+ * @returns `Buffer`
95
+ */
96
+ downloadBuffer?: FunctionDownloadBuffer;
97
+ };
98
+ type UpdaterDownloadConfig = {
99
+ /**
100
+ * download user agent
101
+ * @default 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36'
102
+ */
103
+ userAgent?: string;
104
+ /**
105
+ * extra download header, `accept` and `user-agent` is set by default
106
+ */
107
+ extraHeader?: Record<string, string>;
108
+ };
50
109
  interface UpdaterOption {
51
110
  /**
52
111
  * public key of signature, which will be auto generated by plugin
@@ -93,56 +152,14 @@ interface UpdaterOption {
93
152
  * whether to enable debug listener
94
153
  */
95
154
  debug?: boolean;
96
- overrideFunctions?: {
97
- /**
98
- * custom version compare function {@link FunctionCompareVersion}
99
- * @param oldVersion old version string
100
- * @param newVersion new version string
101
- * @returns whether oldVersion < newVersion
102
- */
103
- compareVersion?: FunctionCompareVersion;
104
- /**
105
- * custom verify signature function {@link FunctionVerifySignature}
106
- * @param buffer file buffer
107
- * @param signature signature
108
- * @param cert certificate
109
- */
110
- verifySignaure?: FunctionVerifySignature;
111
- /**
112
- * custom download JSON function
113
- * @param url download url
114
- * @param updater updater, to trigger events
115
- * @param header download header
116
- * @returns `UpdateJSON`
117
- */
118
- downloadJSON?: (url: string, updater: Updater, headers: Record<string, any>) => Promise<UpdateJSON>;
119
- /**
120
- * custom download buffer function
121
- * @param url download url
122
- * @param updater updater, to trigger events
123
- * @param header download header
124
- * @returns `Buffer`
125
- */
126
- downloadBuffer?: (url: string, updater: Updater, headers: Record<string, any>) => Promise<Buffer>;
127
- };
128
- downloadConfig?: {
129
- /**
130
- * download user agent
131
- * @default 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36'
132
- */
133
- userAgent?: string;
134
- /**
135
- * extra download header, `accept` and `user-agent` is set by default
136
- */
137
- extraHeader?: Record<string, string>;
138
- };
155
+ /**
156
+ * whether to receive beta update
157
+ */
158
+ receiveBeta?: boolean;
159
+ overrideFunctions?: UpdaterOverrideFunctions;
160
+ downloadConfig?: UpdaterDownloadConfig;
139
161
  }
140
162
 
141
- /**
142
- * Creates an updater based on the provided options
143
- */
144
- declare function createUpdater(updaterOptions: UpdaterOption): Updater;
145
-
146
163
  type AppOption = {
147
164
  /**
148
165
  * path of electron output dist when in development
@@ -194,4 +211,4 @@ type SetUpdater = {
194
211
  */
195
212
  declare function initApp(appOptions?: AppOption): SetUpdater;
196
213
 
197
- export { AppOption, FunctionCompareVersion, FunctionVerifySignature, StartupWithUpdater, UpdateJSON, Updater, UpdaterOption, createUpdater, initApp };
214
+ export { AppOption, FunctionCompareVersion, FunctionVerifySignature, MinimumVersionError, StartupWithUpdater, Updater, UpdaterOption, VerifyFailedError, createUpdater, initApp };
package/dist/index.js CHANGED
@@ -20,6 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
+ MinimumVersionError: () => MinimumVersionError,
24
+ VerifyFailedError: () => VerifyFailedError,
23
25
  createUpdater: () => createUpdater,
24
26
  initApp: () => initApp
25
27
  });
@@ -68,6 +70,9 @@ function getProductAsarPath(name) {
68
70
  function getEntryVersion() {
69
71
  return import_electron.app.getVersion();
70
72
  }
73
+ function getProductVersion(name) {
74
+ return import_electron.app.isPackaged ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8") : getEntryVersion();
75
+ }
71
76
  function waitAppReady(duration = 1e3) {
72
77
  return new Promise((resolve2, reject) => {
73
78
  const timeout = setTimeout(() => {
@@ -95,17 +100,28 @@ async function unzipFile(gzipPath, targetFilePath) {
95
100
  });
96
101
  });
97
102
  }
103
+ function parseVersion(version) {
104
+ const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
105
+ const match = semver.exec(version);
106
+ if (!match) {
107
+ throw new TypeError(`invalid version: ${version}`);
108
+ }
109
+ const [major, minor, patch] = match.slice(1, 4).map(Number);
110
+ if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
111
+ throw new TypeError(`invalid version: ${version}`);
112
+ }
113
+ return { major, minor, patch, stage: match[4] };
114
+ }
98
115
 
99
- // src/updater/defaultFunctions.ts
100
- var import_node_buffer2 = require("buffer");
101
- var import_electron2 = require("electron");
102
-
103
- // src/updater/types.ts
116
+ // src/updateJson.ts
104
117
  function isUpdateJSON(json) {
105
- return "signature" in json && "version" in json && "size" in json;
118
+ const is = (j) => "signature" in j && "version" in j && "size" in j && "minimumVersion" in j;
119
+ return is(json) && "beta" in json && is(json.beta);
106
120
  }
107
121
 
108
122
  // src/updater/defaultFunctions.ts
123
+ var import_node_buffer2 = require("buffer");
124
+ var import_electron2 = require("electron");
109
125
  async function downloadJSONDefault(url, updater, headers) {
110
126
  await waitAppReady();
111
127
  return new Promise((resolve2, reject) => {
@@ -168,20 +184,6 @@ async function downloadBufferDefault(url, updater, headers) {
168
184
  });
169
185
  }
170
186
  var compareVersionDefault = (oldVersion, newVersion) => {
171
- if (!oldVersion || !newVersion || typeof oldVersion !== "string" || typeof newVersion !== "string") {
172
- throw new TypeError("invalid version");
173
- }
174
- const parseVersion = (version) => {
175
- const [versionNumber, stage] = version.split("-", 2);
176
- if (!versionNumber || !versionNumber.includes(".")) {
177
- throw new TypeError("invalid version");
178
- }
179
- const [major, minor, patch] = versionNumber.split(".").map(Number);
180
- if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
181
- throw new TypeError("invalid version");
182
- }
183
- return { major, minor, patch, stage };
184
- };
185
187
  const oldV = parseVersion(oldVersion);
186
188
  const newV = parseVersion(newVersion);
187
189
  if (oldV.major < newV.major || oldV.major === newV.major && oldV.minor < newV.minor || oldV.major === newV.major && oldV.minor === newV.minor && oldV.patch < newV.patch) {
@@ -194,6 +196,24 @@ var compareVersionDefault = (oldVersion, newVersion) => {
194
196
  };
195
197
 
196
198
  // src/updater/index.ts
199
+ var MinimumVersionError = class extends Error {
200
+ currentVersion;
201
+ minVersion;
202
+ constructor(version, minimumVersion) {
203
+ super(`current entry version is ${version}, less than the minimumVersion ${minimumVersion}`);
204
+ this.currentVersion = version;
205
+ this.minVersion = minimumVersion;
206
+ }
207
+ };
208
+ var VerifyFailedError = class extends Error {
209
+ signature;
210
+ cert;
211
+ constructor(signature, cert) {
212
+ super("verify failed, invalid signature or certificate");
213
+ this.signature = signature;
214
+ this.cert = cert;
215
+ }
216
+ };
197
217
  function createUpdater(updaterOptions) {
198
218
  const {
199
219
  SIGNATURE_CERT,
@@ -202,6 +222,7 @@ function createUpdater(updaterOptions) {
202
222
  releaseAsarURL: _release,
203
223
  updateJsonURL: _update,
204
224
  debug = false,
225
+ receiveBeta = false,
205
226
  downloadConfig: { extraHeader, userAgent } = {},
206
227
  overrideFunctions: {
207
228
  compareVersion,
@@ -219,11 +240,15 @@ function createUpdater(updaterOptions) {
219
240
  function log(msg) {
220
241
  debug && updater.emit("debug", msg);
221
242
  }
222
- function needUpdate(version2) {
223
- const currentVersion = getEntryVersion();
224
- log(`check update: current version is ${currentVersion}, new version is ${version2}`);
225
- const _compare = compareVersion ?? compareVersionDefault;
226
- return _compare(currentVersion, version2);
243
+ async function needUpdate(version2, minVersion) {
244
+ const compare = compareVersion ?? compareVersionDefault;
245
+ const productVersion = getProductVersion(productName);
246
+ const entryVersion = getEntryVersion();
247
+ if (await compare(entryVersion, minVersion)) {
248
+ throw new MinimumVersionError(entryVersion, minVersion);
249
+ }
250
+ log(`check update: current version is ${productVersion}, new version is ${version2}`);
251
+ return await compare(productVersion, version2);
227
252
  }
228
253
  async function parseData(format, data, version2) {
229
254
  if ((0, import_node_fs2.existsSync)(tmpFilePath)) {
@@ -238,7 +263,7 @@ function createUpdater(updaterOptions) {
238
263
  if (format === "json" && isUpdateJSON(data) || format === "buffer" && import_node_buffer3.Buffer.isBuffer(data)) {
239
264
  return data;
240
265
  } else {
241
- throw new Error(`invalid type at format '${format}': ${data}`);
266
+ throw new TypeError(`invalid type at format '${format}': ${data}`);
242
267
  }
243
268
  } else if (["string", "undefined"].includes(typeof data)) {
244
269
  const ua = userAgent || "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36";
@@ -278,16 +303,29 @@ function createUpdater(updaterOptions) {
278
303
  }
279
304
  return ret;
280
305
  } else {
281
- throw new Error(`invalid type at format '${format}': ${data}`);
306
+ throw new TypeError(`invalid type at format '${format}': ${data}`);
282
307
  }
283
308
  }
284
309
  updater.productName = productName;
285
- updater.debugMode = debug;
310
+ updater.debug = debug;
311
+ updater.receiveBeta = receiveBeta;
286
312
  updater.checkUpdate = async (data) => {
287
313
  try {
288
- const { signature: _sig, size, version: _ver } = await parseData("json", data);
314
+ let {
315
+ signature: _sig,
316
+ size,
317
+ version: _ver,
318
+ minimumVersion,
319
+ beta
320
+ } = await parseData("json", data);
321
+ if (receiveBeta) {
322
+ _ver = beta.version;
323
+ _sig = beta.signature;
324
+ minimumVersion = beta.minimumVersion;
325
+ size = beta.size;
326
+ }
289
327
  log(`checked version: ${_ver}, size: ${size}, signature: ${_sig}`);
290
- if (!needUpdate(_ver)) {
328
+ if (!await needUpdate(_ver, minimumVersion)) {
291
329
  log(`update unavailable: ${_ver}`);
292
330
  return void 0;
293
331
  } else {
@@ -310,9 +348,9 @@ function createUpdater(updaterOptions) {
310
348
  const buffer = await parseData("buffer", data, version);
311
349
  log("verify start");
312
350
  const _verify = verifySignaure ?? verify;
313
- const _ver = _verify(buffer, _sig, SIGNATURE_CERT);
351
+ const _ver = await _verify(buffer, _sig, SIGNATURE_CERT);
314
352
  if (!_ver) {
315
- throw new Error("verify failed, invalid signature");
353
+ throw new VerifyFailedError(_sig, SIGNATURE_CERT);
316
354
  }
317
355
  log("verify success");
318
356
  log(`write to ${gzipPath}`);
@@ -374,6 +412,8 @@ function initApp(appOptions) {
374
412
  }
375
413
  // Annotate the CommonJS export names for ESM import in node:
376
414
  0 && (module.exports = {
415
+ MinimumVersionError,
416
+ VerifyFailedError,
377
417
  createUpdater,
378
418
  initApp
379
419
  });