electron-incremental-update 2.0.0-beta.6 → 2.0.0-beta.7

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.
@@ -0,0 +1,134 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import { a as UpdateJSON, U as UpdateInfo, D as DownloadingInfo, I as IProvider, c as URLHandler } from './types-CItP6bL-.js';
3
+
4
+ declare const ErrorInfo: {
5
+ readonly download: "Download failed";
6
+ readonly validate: "Validate failed";
7
+ readonly param: "Missing params";
8
+ readonly network: "Network error";
9
+ };
10
+ declare class UpdaterError extends Error {
11
+ code: keyof typeof ErrorInfo;
12
+ constructor(msg: keyof typeof ErrorInfo, info: string);
13
+ }
14
+ type CheckResult<T extends UpdateJSON> = {
15
+ success: true;
16
+ data: Omit<T, 'beta'>;
17
+ } | {
18
+ success: false;
19
+ /**
20
+ * minimal version that can update
21
+ */
22
+ data: string;
23
+ } | {
24
+ success: false;
25
+ data: UpdaterError;
26
+ };
27
+ type DownloadResult = {
28
+ success: true;
29
+ } | {
30
+ success: false;
31
+ data: UpdaterError;
32
+ };
33
+ interface Logger {
34
+ info: (msg: string) => void;
35
+ debug: (msg: string) => void;
36
+ warn: (msg: string) => void;
37
+ error: (msg: string, e?: unknown) => void;
38
+ }
39
+ interface UpdaterOption {
40
+ /**
41
+ * public key of signature, which will be auto generated by plugin,
42
+ * generate by `selfsigned` if not set
43
+ */
44
+ SIGNATURE_CERT?: string;
45
+ /**
46
+ * whether to receive beta update
47
+ */
48
+ receiveBeta?: boolean;
49
+ logger?: Logger;
50
+ }
51
+
52
+ declare class Updater extends EventEmitter<{
53
+ 'checking': any;
54
+ 'update-available': [data: UpdateInfo];
55
+ 'update-unavailable': [reason: string];
56
+ 'error': [error: UpdaterError];
57
+ 'download-progress': [info: DownloadingInfo];
58
+ 'update-downloaded': any;
59
+ }> {
60
+ private CERT;
61
+ private info?;
62
+ private provider;
63
+ /**
64
+ * updater logger
65
+ */
66
+ logger?: Logger;
67
+ /**
68
+ * whether to receive beta update
69
+ */
70
+ receiveBeta?: boolean;
71
+ /**
72
+ * whether force update in DEV
73
+ */
74
+ forceUpdate?: boolean;
75
+ /**
76
+ * initialize incremental updater
77
+ * @param provider update provider
78
+ * @param option UpdaterOption
79
+ */
80
+ constructor(provider: IProvider, option?: UpdaterOption);
81
+ /**
82
+ * this function is used to parse download data.
83
+ * - if format is `'json'`
84
+ * - if data is `UpdateJSON`, return it
85
+ * - if data is string or absent, download URL data and return it
86
+ * - if format is `'buffer'`
87
+ * - if data is `Buffer`, return it
88
+ * - if data is string or absent, download URL data and return it
89
+ * @param format 'json' or 'buffer'
90
+ * @param data download URL or update json or buffer
91
+ */
92
+ private fetch;
93
+ /**
94
+ * handle error message and emit error event
95
+ */
96
+ private err;
97
+ /**
98
+ * check update info using default options
99
+ */
100
+ checkUpdate(): Promise<boolean>;
101
+ /**
102
+ * check update info using existing update json
103
+ * @param data existing update json
104
+ */
105
+ checkUpdate(data: UpdateJSON): Promise<boolean>;
106
+ /**
107
+ * download update using default options
108
+ */
109
+ downloadUpdate(): Promise<boolean>;
110
+ /**
111
+ * download update using existing `asar.gz` buffer and signature
112
+ * @param data existing `asar.gz` buffer
113
+ * @param info update info
114
+ */
115
+ downloadUpdate(data: Uint8Array, info: Omit<UpdateInfo, 'minimumVersion'>): Promise<boolean>;
116
+ /**
117
+ * quit App and install
118
+ */
119
+ quitAndInstall(): void;
120
+ /**
121
+ * setup provider URL handler
122
+ *
123
+ * @example
124
+ * updater.setURLHandler((url, isDownloadingAsar) => {
125
+ * if (isDownloadingAsar) {
126
+ * url.hostname = 'https://cdn.jsdelivr.net/gh'
127
+ * return url
128
+ * }
129
+ * })
130
+ */
131
+ setURLHandler(handler: URLHandler): void;
132
+ }
133
+
134
+ export { type CheckResult as C, type DownloadResult as D, ErrorInfo as E, type Logger as L, Updater as U, type UpdaterOption as a, UpdaterError as b };
@@ -0,0 +1,134 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import { a as UpdateJSON, U as UpdateInfo, D as DownloadingInfo, I as IProvider, c as URLHandler } from './types-CItP6bL-.cjs';
3
+
4
+ declare const ErrorInfo: {
5
+ readonly download: "Download failed";
6
+ readonly validate: "Validate failed";
7
+ readonly param: "Missing params";
8
+ readonly network: "Network error";
9
+ };
10
+ declare class UpdaterError extends Error {
11
+ code: keyof typeof ErrorInfo;
12
+ constructor(msg: keyof typeof ErrorInfo, info: string);
13
+ }
14
+ type CheckResult<T extends UpdateJSON> = {
15
+ success: true;
16
+ data: Omit<T, 'beta'>;
17
+ } | {
18
+ success: false;
19
+ /**
20
+ * minimal version that can update
21
+ */
22
+ data: string;
23
+ } | {
24
+ success: false;
25
+ data: UpdaterError;
26
+ };
27
+ type DownloadResult = {
28
+ success: true;
29
+ } | {
30
+ success: false;
31
+ data: UpdaterError;
32
+ };
33
+ interface Logger {
34
+ info: (msg: string) => void;
35
+ debug: (msg: string) => void;
36
+ warn: (msg: string) => void;
37
+ error: (msg: string, e?: unknown) => void;
38
+ }
39
+ interface UpdaterOption {
40
+ /**
41
+ * public key of signature, which will be auto generated by plugin,
42
+ * generate by `selfsigned` if not set
43
+ */
44
+ SIGNATURE_CERT?: string;
45
+ /**
46
+ * whether to receive beta update
47
+ */
48
+ receiveBeta?: boolean;
49
+ logger?: Logger;
50
+ }
51
+
52
+ declare class Updater extends EventEmitter<{
53
+ 'checking': any;
54
+ 'update-available': [data: UpdateInfo];
55
+ 'update-unavailable': [reason: string];
56
+ 'error': [error: UpdaterError];
57
+ 'download-progress': [info: DownloadingInfo];
58
+ 'update-downloaded': any;
59
+ }> {
60
+ private CERT;
61
+ private info?;
62
+ private provider;
63
+ /**
64
+ * updater logger
65
+ */
66
+ logger?: Logger;
67
+ /**
68
+ * whether to receive beta update
69
+ */
70
+ receiveBeta?: boolean;
71
+ /**
72
+ * whether force update in DEV
73
+ */
74
+ forceUpdate?: boolean;
75
+ /**
76
+ * initialize incremental updater
77
+ * @param provider update provider
78
+ * @param option UpdaterOption
79
+ */
80
+ constructor(provider: IProvider, option?: UpdaterOption);
81
+ /**
82
+ * this function is used to parse download data.
83
+ * - if format is `'json'`
84
+ * - if data is `UpdateJSON`, return it
85
+ * - if data is string or absent, download URL data and return it
86
+ * - if format is `'buffer'`
87
+ * - if data is `Buffer`, return it
88
+ * - if data is string or absent, download URL data and return it
89
+ * @param format 'json' or 'buffer'
90
+ * @param data download URL or update json or buffer
91
+ */
92
+ private fetch;
93
+ /**
94
+ * handle error message and emit error event
95
+ */
96
+ private err;
97
+ /**
98
+ * check update info using default options
99
+ */
100
+ checkUpdate(): Promise<boolean>;
101
+ /**
102
+ * check update info using existing update json
103
+ * @param data existing update json
104
+ */
105
+ checkUpdate(data: UpdateJSON): Promise<boolean>;
106
+ /**
107
+ * download update using default options
108
+ */
109
+ downloadUpdate(): Promise<boolean>;
110
+ /**
111
+ * download update using existing `asar.gz` buffer and signature
112
+ * @param data existing `asar.gz` buffer
113
+ * @param info update info
114
+ */
115
+ downloadUpdate(data: Uint8Array, info: Omit<UpdateInfo, 'minimumVersion'>): Promise<boolean>;
116
+ /**
117
+ * quit App and install
118
+ */
119
+ quitAndInstall(): void;
120
+ /**
121
+ * setup provider URL handler
122
+ *
123
+ * @example
124
+ * updater.setURLHandler((url, isDownloadingAsar) => {
125
+ * if (isDownloadingAsar) {
126
+ * url.hostname = 'https://cdn.jsdelivr.net/gh'
127
+ * return url
128
+ * }
129
+ * })
130
+ */
131
+ setURLHandler(handler: URLHandler): void;
132
+ }
133
+
134
+ export { type CheckResult as C, type DownloadResult as D, ErrorInfo as E, type Logger as L, Updater as U, type UpdaterOption as a, UpdaterError as b };
@@ -0,0 +1,78 @@
1
+ import { U as Updater, a as UpdaterOption, L as Logger } from './core-ZUlLHadf.cjs';
2
+ export { C as CheckResult, D as DownloadResult, E as ErrorInfo, b as UpdaterError } from './core-ZUlLHadf.cjs';
3
+ import { I as IProvider } from './types-CItP6bL-.cjs';
4
+ import 'node:events';
5
+ import '@subframe7536/type-utils';
6
+
7
+ type Promisable<T> = T | Promise<T>;
8
+ /**
9
+ * hooks on rename temp asar path to `${app.name}.asar`
10
+ * @param install `() => renameSync(tempAsarPath, appNameAsarPath)`
11
+ * @param tempAsarPath temp(updated) asar path
12
+ * @param appNameAsarPath `${app.name}.asar` path
13
+ * @param logger logger
14
+ * @default install(); logger.info(`update success!`)
15
+ */
16
+ type OnInstallFunction = (install: VoidFunction, tempAsarPath: string, appNameAsarPath: string, logger?: Logger) => Promisable<void>;
17
+ interface AppOption {
18
+ /**
19
+ * update provider
20
+ */
21
+ provider: IProvider;
22
+ /**
23
+ * updater options
24
+ */
25
+ updater?: (() => Promisable<Updater>) | UpdaterOption;
26
+ /**
27
+ * hooks on rename temp asar path to `${app.name}.asar`
28
+ */
29
+ onInstall?: OnInstallFunction;
30
+ /**
31
+ * hooks before app start up
32
+ * @param mainFilePath main file path of `${app.name}.asar`
33
+ * @param logger logger
34
+ */
35
+ beforeStart?: (mainFilePath: string, logger?: Logger) => Promisable<void>;
36
+ /**
37
+ * hooks on app start up error
38
+ * @param err installing or startup error
39
+ * @param logger logger
40
+ */
41
+ onStartError?: (err: unknown, logger?: Logger) => void;
42
+ }
43
+ /**
44
+ * utils for startuping with updater
45
+ * @param fn startup function
46
+ * @example
47
+ * // in electron/main/index.ts
48
+ * export default startupWithUpdater((updater) => {
49
+ * updater.checkUpdate()
50
+ * })
51
+ */
52
+ declare function startupWithUpdater(fn: (updater: Updater) => Promisable<void>): (updater: Updater) => Promisable<void>;
53
+ /**
54
+ * initialize app
55
+ * @example
56
+ * ```ts
57
+ * import { getGithubReleaseCdnGroup, initApp, parseGithubCdnURL } from 'electron-incremental-update'
58
+ * import { repository } from '../package.json'
59
+ *
60
+ * const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
61
+ * const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
62
+ *
63
+ * initApp({
64
+ * // can be updater option or function that return updater
65
+ * updater: {
66
+ * SIGNATURE_CERT: 'custom certificate',
67
+ * repository,
68
+ * updateJsonURL: parseGithubCdnURL(repository, jsonPrefix, 'version.json'),
69
+ * releaseAsarURL: parseGithubCdnURL(repository, asarPrefix, `download/latest/${app.name}.asar.gz`),
70
+ * receiveBeta: true,
71
+ * },
72
+ * onStart: console.log
73
+ * })
74
+ * ```
75
+ */
76
+ declare function initApp(appOptions: AppOption): Promise<void>;
77
+
78
+ export { type AppOption, Logger, Updater, UpdaterOption, initApp, startupWithUpdater };
@@ -0,0 +1,78 @@
1
+ import { U as Updater, a as UpdaterOption, L as Logger } from './core-DJdvtwvU.js';
2
+ export { C as CheckResult, D as DownloadResult, E as ErrorInfo, b as UpdaterError } from './core-DJdvtwvU.js';
3
+ import { I as IProvider } from './types-CItP6bL-.js';
4
+ import 'node:events';
5
+ import '@subframe7536/type-utils';
6
+
7
+ type Promisable<T> = T | Promise<T>;
8
+ /**
9
+ * hooks on rename temp asar path to `${app.name}.asar`
10
+ * @param install `() => renameSync(tempAsarPath, appNameAsarPath)`
11
+ * @param tempAsarPath temp(updated) asar path
12
+ * @param appNameAsarPath `${app.name}.asar` path
13
+ * @param logger logger
14
+ * @default install(); logger.info(`update success!`)
15
+ */
16
+ type OnInstallFunction = (install: VoidFunction, tempAsarPath: string, appNameAsarPath: string, logger?: Logger) => Promisable<void>;
17
+ interface AppOption {
18
+ /**
19
+ * update provider
20
+ */
21
+ provider: IProvider;
22
+ /**
23
+ * updater options
24
+ */
25
+ updater?: (() => Promisable<Updater>) | UpdaterOption;
26
+ /**
27
+ * hooks on rename temp asar path to `${app.name}.asar`
28
+ */
29
+ onInstall?: OnInstallFunction;
30
+ /**
31
+ * hooks before app start up
32
+ * @param mainFilePath main file path of `${app.name}.asar`
33
+ * @param logger logger
34
+ */
35
+ beforeStart?: (mainFilePath: string, logger?: Logger) => Promisable<void>;
36
+ /**
37
+ * hooks on app start up error
38
+ * @param err installing or startup error
39
+ * @param logger logger
40
+ */
41
+ onStartError?: (err: unknown, logger?: Logger) => void;
42
+ }
43
+ /**
44
+ * utils for startuping with updater
45
+ * @param fn startup function
46
+ * @example
47
+ * // in electron/main/index.ts
48
+ * export default startupWithUpdater((updater) => {
49
+ * updater.checkUpdate()
50
+ * })
51
+ */
52
+ declare function startupWithUpdater(fn: (updater: Updater) => Promisable<void>): (updater: Updater) => Promisable<void>;
53
+ /**
54
+ * initialize app
55
+ * @example
56
+ * ```ts
57
+ * import { getGithubReleaseCdnGroup, initApp, parseGithubCdnURL } from 'electron-incremental-update'
58
+ * import { repository } from '../package.json'
59
+ *
60
+ * const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
61
+ * const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
62
+ *
63
+ * initApp({
64
+ * // can be updater option or function that return updater
65
+ * updater: {
66
+ * SIGNATURE_CERT: 'custom certificate',
67
+ * repository,
68
+ * updateJsonURL: parseGithubCdnURL(repository, jsonPrefix, 'version.json'),
69
+ * releaseAsarURL: parseGithubCdnURL(repository, asarPrefix, `download/latest/${app.name}.asar.gz`),
70
+ * receiveBeta: true,
71
+ * },
72
+ * onStart: console.log
73
+ * })
74
+ * ```
75
+ */
76
+ declare function initApp(appOptions: AppOption): Promise<void>;
77
+
78
+ export { type AppOption, Logger, Updater, UpdaterOption, initApp, startupWithUpdater };
@@ -0,0 +1,76 @@
1
+ import { I as IProvider, d as defaultIsLowerVersion, a as UpdateJSON, U as UpdateInfo, D as DownloadingInfo, c as URLHandler, O as OnDownloading } from './types-CItP6bL-.cjs';
2
+ import { f as defaultVerifySignature, a as defaultUnzipFile } from './zip-DPF5IFkK.cjs';
3
+ import { Arrayable } from '@subframe7536/type-utils';
4
+
5
+ declare abstract class BaseProvider implements IProvider {
6
+ name: string;
7
+ isLowerVersion: typeof defaultIsLowerVersion;
8
+ verifySignaure: typeof defaultVerifySignature;
9
+ unzipFile: typeof defaultUnzipFile;
10
+ abstract downloadJSON(versionPath: string): Promise<UpdateJSON>;
11
+ abstract downloadAsar(name: string, info: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
12
+ }
13
+
14
+ interface GitHubProviderOptions {
15
+ /**
16
+ * github user name
17
+ */
18
+ username: string;
19
+ /**
20
+ * github repo name
21
+ */
22
+ repo: string;
23
+ /**
24
+ * github branch name that fetch version
25
+ * @default 'HEAD'
26
+ */
27
+ branch?: string;
28
+ /**
29
+ * extra headers
30
+ */
31
+ extraHeaders?: Record<string, string>;
32
+ /**
33
+ * custom url handler
34
+ *
35
+ * for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L40 public CDN links}
36
+ * @example
37
+ * (url, isDownloadAsar) => {
38
+ * if (isDownloadAsar) {
39
+ * url.hostname = 'mirror.ghproxy.com'
40
+ * url.pathname = 'https://github.com' + url.pathname
41
+ * return url
42
+ * }
43
+ * }
44
+ */
45
+ urlHandler?: URLHandler;
46
+ }
47
+ declare class GitHubProvider extends BaseProvider {
48
+ name: string;
49
+ private options;
50
+ /**
51
+ * Update Provider for Github repo
52
+ * - download update json from `https://raw.githubusercontent.com/{user}/{repo}/HEAD/{versionPath}`
53
+ * - download update asar from `https://github.com/{user}/{repo}/releases/download/v{version}/{name}-{version}.asar.gz`
54
+ *
55
+ * you can setup `urlHandler` in {@link GitHubProviderOptions} or `Updater` to modify url before request
56
+ * @param options provider options
57
+ */
58
+ constructor(options: GitHubProviderOptions);
59
+ get urlHandler(): URLHandler | undefined;
60
+ set urlHandler(handler: URLHandler);
61
+ private parseURL;
62
+ downloadJSON(versionPath: string): Promise<UpdateJSON>;
63
+ downloadAsar(name: string, info: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
64
+ }
65
+
66
+ declare function getHeader(response: Record<string, Arrayable<string>>, headerKey: any): any;
67
+ /**
68
+ * download json and parse UpdateJson
69
+ */
70
+ declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any>): Promise<UpdateJSON>;
71
+ /**
72
+ * download asar buffer, get total size from `Content-Length` header
73
+ */
74
+ declare function defaultDownloadAsar(url: string, headers: Record<string, any>, onDownloading?: OnDownloading): Promise<Buffer>;
75
+
76
+ export { BaseProvider, DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, defaultDownloadAsar, defaultDownloadUpdateJSON, getHeader };
@@ -0,0 +1,76 @@
1
+ import { I as IProvider, d as defaultIsLowerVersion, a as UpdateJSON, U as UpdateInfo, D as DownloadingInfo, c as URLHandler, O as OnDownloading } from './types-CItP6bL-.js';
2
+ import { f as defaultVerifySignature, a as defaultUnzipFile } from './zip-DPF5IFkK.js';
3
+ import { Arrayable } from '@subframe7536/type-utils';
4
+
5
+ declare abstract class BaseProvider implements IProvider {
6
+ name: string;
7
+ isLowerVersion: typeof defaultIsLowerVersion;
8
+ verifySignaure: typeof defaultVerifySignature;
9
+ unzipFile: typeof defaultUnzipFile;
10
+ abstract downloadJSON(versionPath: string): Promise<UpdateJSON>;
11
+ abstract downloadAsar(name: string, info: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
12
+ }
13
+
14
+ interface GitHubProviderOptions {
15
+ /**
16
+ * github user name
17
+ */
18
+ username: string;
19
+ /**
20
+ * github repo name
21
+ */
22
+ repo: string;
23
+ /**
24
+ * github branch name that fetch version
25
+ * @default 'HEAD'
26
+ */
27
+ branch?: string;
28
+ /**
29
+ * extra headers
30
+ */
31
+ extraHeaders?: Record<string, string>;
32
+ /**
33
+ * custom url handler
34
+ *
35
+ * for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L40 public CDN links}
36
+ * @example
37
+ * (url, isDownloadAsar) => {
38
+ * if (isDownloadAsar) {
39
+ * url.hostname = 'mirror.ghproxy.com'
40
+ * url.pathname = 'https://github.com' + url.pathname
41
+ * return url
42
+ * }
43
+ * }
44
+ */
45
+ urlHandler?: URLHandler;
46
+ }
47
+ declare class GitHubProvider extends BaseProvider {
48
+ name: string;
49
+ private options;
50
+ /**
51
+ * Update Provider for Github repo
52
+ * - download update json from `https://raw.githubusercontent.com/{user}/{repo}/HEAD/{versionPath}`
53
+ * - download update asar from `https://github.com/{user}/{repo}/releases/download/v{version}/{name}-{version}.asar.gz`
54
+ *
55
+ * you can setup `urlHandler` in {@link GitHubProviderOptions} or `Updater` to modify url before request
56
+ * @param options provider options
57
+ */
58
+ constructor(options: GitHubProviderOptions);
59
+ get urlHandler(): URLHandler | undefined;
60
+ set urlHandler(handler: URLHandler);
61
+ private parseURL;
62
+ downloadJSON(versionPath: string): Promise<UpdateJSON>;
63
+ downloadAsar(name: string, info: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
64
+ }
65
+
66
+ declare function getHeader(response: Record<string, Arrayable<string>>, headerKey: any): any;
67
+ /**
68
+ * download json and parse UpdateJson
69
+ */
70
+ declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any>): Promise<UpdateJSON>;
71
+ /**
72
+ * download asar buffer, get total size from `Content-Length` header
73
+ */
74
+ declare function defaultDownloadAsar(url: string, headers: Record<string, any>, onDownloading?: OnDownloading): Promise<Buffer>;
75
+
76
+ export { BaseProvider, DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, defaultDownloadAsar, defaultDownloadUpdateJSON, getHeader };
@@ -0,0 +1,104 @@
1
+ import { Promisable } from '@subframe7536/type-utils';
2
+
3
+ interface Version {
4
+ major: number;
5
+ minor: number;
6
+ patch: number;
7
+ stage: string;
8
+ stageVersion: number;
9
+ }
10
+ declare function parseVersion(version: string): Version;
11
+ declare function defaultIsLowerVersion(oldVer: string, newVer: string): boolean;
12
+ /**
13
+ * update info json
14
+ */
15
+ type UpdateInfo = {
16
+ signature: string;
17
+ minimumVersion: string;
18
+ version: string;
19
+ };
20
+ /**
21
+ * {@link UpdateInfo} with beta
22
+ */
23
+ type UpdateJSON = UpdateInfo & {
24
+ beta: UpdateInfo;
25
+ };
26
+ declare function isUpdateJSON(json: any): json is UpdateJSON;
27
+ declare function defaultVersionJsonGenerator(existingJson: UpdateJSON, signature: string, version: string, minimumVersion: string): UpdateJSON;
28
+
29
+ type URLHandler = (url: URL, isDownloadAsar: boolean) => Promisable<URL | string | undefined | null>;
30
+ type OnDownloading = (progress: DownloadingInfo) => void;
31
+ interface DownloadingInfo {
32
+ /**
33
+ * download delta
34
+ */
35
+ delta: number;
36
+ /**
37
+ * downloaded percent, 0 ~ 100
38
+ *
39
+ * If not `Content-Length` header, will be nagative
40
+ */
41
+ percent: number;
42
+ /**
43
+ * total size
44
+ *
45
+ * If not `Content-Length` header, will be -1
46
+ */
47
+ total: number;
48
+ /**
49
+ * downloaded size
50
+ */
51
+ transferred: number;
52
+ /**
53
+ * download speed, bytes per second
54
+ */
55
+ bps: number;
56
+ }
57
+ interface IProvider {
58
+ /**
59
+ * provider name
60
+ */
61
+ name: string;
62
+ /**
63
+ * custom url handler
64
+ *
65
+ * for Github, there are some {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 public CDN links}
66
+ */
67
+ urlHandler?: URLHandler;
68
+ onDownloading?: OnDownloading;
69
+ /**
70
+ * download update json
71
+ * @param versionPath parsed version path
72
+ */
73
+ downloadJSON: (versionPath: string) => Promise<UpdateJSON>;
74
+ /**
75
+ * download update asar
76
+ * @param name app name
77
+ * @param updateInfo existing update info
78
+ * @param onDownloading hook for on downloading
79
+ */
80
+ downloadAsar: (name: string, updateInfo: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void) => Promise<Buffer>;
81
+ /**
82
+ * compare version
83
+ * @param oldVer old version string
84
+ * @param newVer new version string
85
+ * @returns if version1 < version2
86
+ */
87
+ isLowerVersion: (oldVer: string, newVer: string) => boolean;
88
+ /**
89
+ * unzip file buffer
90
+ * @param buffer source buffer
91
+ */
92
+ unzipFile: (buffer: Buffer) => Promise<Buffer>;
93
+ /**
94
+ * verify asar signature
95
+ * @param buffer file buffer
96
+ * @param version target version
97
+ * @param signature signature
98
+ * @param cert certificate
99
+ * @returns if signature is valid, returns the version, otherwise returns `undefined`
100
+ */
101
+ verifySignaure: (buffer: Buffer, version: string, signature: string, cert: string) => Promisable<boolean>;
102
+ }
103
+
104
+ export { type DownloadingInfo as D, type IProvider as I, type OnDownloading as O, type UpdateInfo as U, type Version as V, type UpdateJSON as a, defaultVersionJsonGenerator as b, type URLHandler as c, defaultIsLowerVersion as d, isUpdateJSON as i, parseVersion as p };