@wvb/config 0.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/CHANGELOG.md +1 -0
- package/README.md +1 -0
- package/dist/index-Da62rQR9.d.mts +108 -0
- package/dist/index-cK1sn_xk.d.cts +108 -0
- package/dist/index.cjs +8 -0
- package/dist/index.d.cts +142 -0
- package/dist/index.d.mts +142 -0
- package/dist/index.mjs +7 -0
- package/dist/remote/index.cjs +81 -0
- package/dist/remote/index.d.cts +2 -0
- package/dist/remote/index.d.mts +2 -0
- package/dist/remote/index.mjs +80 -0
- package/package.json +50 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Changelog
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @wvb/config
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
|
|
3
|
+
//#region src/remote/deployer.d.ts
|
|
4
|
+
interface RemoteDeployParams {
|
|
5
|
+
bundleName: string;
|
|
6
|
+
version: string;
|
|
7
|
+
channel?: string;
|
|
8
|
+
}
|
|
9
|
+
interface BaseRemoteDeployer {
|
|
10
|
+
deploy(params: RemoteDeployParams): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/remote/integrity.d.ts
|
|
14
|
+
type IntegrityAlgorithm = "sha256" | "sha384" | "sha512";
|
|
15
|
+
interface IntegrityMakeConfig {
|
|
16
|
+
algorithm?: IntegrityAlgorithm;
|
|
17
|
+
}
|
|
18
|
+
type IntegrityMakeFn = (params: {
|
|
19
|
+
data: Buffer;
|
|
20
|
+
}) => Promise<string>;
|
|
21
|
+
type IntegrityMaker = IntegrityMakeConfig | IntegrityMakeFn;
|
|
22
|
+
declare function makeIntegrity(maker: IntegrityMaker, data: Buffer): Promise<string>;
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/remote/signature.d.ts
|
|
25
|
+
type SignatureAlgorithm = "ecdsa" | "ed25519" | "rsa-pkcs1-v1.5" | "rsa-pss";
|
|
26
|
+
type SignatureEcdsaCurve = "p256" | "p384";
|
|
27
|
+
type SignatureHash = "sha256" | "sha384" | "sha512";
|
|
28
|
+
type SigningKeyFormat = "raw" | "pkcs8" | "spki" | "jwk";
|
|
29
|
+
type SignatureSigningKeyConfig = {
|
|
30
|
+
format: "jwk";
|
|
31
|
+
data: JsonWebKey;
|
|
32
|
+
} | {
|
|
33
|
+
format: Exclude<SigningKeyFormat, "jwk">;
|
|
34
|
+
data: Buffer;
|
|
35
|
+
};
|
|
36
|
+
type SignatureSignConfig = {
|
|
37
|
+
algorithm: "ecdsa";
|
|
38
|
+
curve: SignatureEcdsaCurve;
|
|
39
|
+
hash: SignatureHash;
|
|
40
|
+
key: SignatureSigningKeyConfig;
|
|
41
|
+
} | {
|
|
42
|
+
algorithm: "rsa-pkcs1-v1.5";
|
|
43
|
+
hash: SignatureHash;
|
|
44
|
+
key: SignatureSigningKeyConfig;
|
|
45
|
+
} | {
|
|
46
|
+
algorithm: "rsa-pss";
|
|
47
|
+
hash: SignatureHash;
|
|
48
|
+
saltLength?: number;
|
|
49
|
+
key: SignatureSigningKeyConfig;
|
|
50
|
+
} | {
|
|
51
|
+
algorithm: Exclude<SignatureAlgorithm, "ecdsa" | "rsa-pkcs1-v1.5" | "rsa-pss">;
|
|
52
|
+
key: SignatureSigningKeyConfig;
|
|
53
|
+
};
|
|
54
|
+
type SignatureSignFn = (params: {
|
|
55
|
+
message: Buffer;
|
|
56
|
+
}) => Promise<string>;
|
|
57
|
+
type SignatureSigner = SignatureSignConfig | SignatureSignFn;
|
|
58
|
+
declare function signSignature(signer: SignatureSigner, message: Buffer): Promise<string>;
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/remote/uploader.d.ts
|
|
61
|
+
interface RemoteUploadParams {
|
|
62
|
+
bundle: Buffer;
|
|
63
|
+
bundleName: string;
|
|
64
|
+
version: string;
|
|
65
|
+
force?: boolean;
|
|
66
|
+
integrity?: string;
|
|
67
|
+
signature?: string;
|
|
68
|
+
}
|
|
69
|
+
interface RemoteUploadProgress {
|
|
70
|
+
/** Number of bytes successfully transferred so far */
|
|
71
|
+
loaded?: number;
|
|
72
|
+
/** Total payload size in byres */
|
|
73
|
+
total?: number;
|
|
74
|
+
/** 1-based multipart part index currently being uploaded */
|
|
75
|
+
part?: number;
|
|
76
|
+
}
|
|
77
|
+
interface BaseRemoteUploader {
|
|
78
|
+
_onUploadProgress?: (progress: RemoteUploadProgress) => void;
|
|
79
|
+
upload(params: RemoteUploadParams): Promise<void>;
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/remote/remote.d.ts
|
|
83
|
+
interface RemoteConfig {
|
|
84
|
+
/**
|
|
85
|
+
* Endpoint to remote server.
|
|
86
|
+
*/
|
|
87
|
+
endpoint?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Name of the bundle to be used in remote.
|
|
90
|
+
*/
|
|
91
|
+
bundleName?: string;
|
|
92
|
+
uploader?: BaseRemoteUploader;
|
|
93
|
+
deployer?: BaseRemoteDeployer;
|
|
94
|
+
integrity?: boolean | IntegrityMakeConfig;
|
|
95
|
+
signature?: SignatureSignConfig;
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/remote/types.d.ts
|
|
99
|
+
interface RemoteBundleDeployment {
|
|
100
|
+
/** The name of the bundle */
|
|
101
|
+
name: string;
|
|
102
|
+
/** Current deployed version of the bundle */
|
|
103
|
+
version?: string;
|
|
104
|
+
/** Versions deployed in each channel */
|
|
105
|
+
channels?: Record<string, string>;
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
export { IntegrityMakeFn as _, RemoteUploadProgress as a, BaseRemoteDeployer as b, SignatureHash as c, SignatureSigner as d, SignatureSigningKeyConfig as f, IntegrityMakeConfig as g, IntegrityAlgorithm as h, RemoteUploadParams as i, SignatureSignConfig as l, signSignature as m, RemoteConfig as n, SignatureAlgorithm as o, SigningKeyFormat as p, BaseRemoteUploader as r, SignatureEcdsaCurve as s, RemoteBundleDeployment as t, SignatureSignFn as u, IntegrityMaker as v, RemoteDeployParams as x, makeIntegrity as y };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
|
|
3
|
+
//#region src/remote/deployer.d.ts
|
|
4
|
+
interface RemoteDeployParams {
|
|
5
|
+
bundleName: string;
|
|
6
|
+
version: string;
|
|
7
|
+
channel?: string;
|
|
8
|
+
}
|
|
9
|
+
interface BaseRemoteDeployer {
|
|
10
|
+
deploy(params: RemoteDeployParams): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/remote/integrity.d.ts
|
|
14
|
+
type IntegrityAlgorithm = "sha256" | "sha384" | "sha512";
|
|
15
|
+
interface IntegrityMakeConfig {
|
|
16
|
+
algorithm?: IntegrityAlgorithm;
|
|
17
|
+
}
|
|
18
|
+
type IntegrityMakeFn = (params: {
|
|
19
|
+
data: Buffer;
|
|
20
|
+
}) => Promise<string>;
|
|
21
|
+
type IntegrityMaker = IntegrityMakeConfig | IntegrityMakeFn;
|
|
22
|
+
declare function makeIntegrity(maker: IntegrityMaker, data: Buffer): Promise<string>;
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/remote/signature.d.ts
|
|
25
|
+
type SignatureAlgorithm = "ecdsa" | "ed25519" | "rsa-pkcs1-v1.5" | "rsa-pss";
|
|
26
|
+
type SignatureEcdsaCurve = "p256" | "p384";
|
|
27
|
+
type SignatureHash = "sha256" | "sha384" | "sha512";
|
|
28
|
+
type SigningKeyFormat = "raw" | "pkcs8" | "spki" | "jwk";
|
|
29
|
+
type SignatureSigningKeyConfig = {
|
|
30
|
+
format: "jwk";
|
|
31
|
+
data: JsonWebKey;
|
|
32
|
+
} | {
|
|
33
|
+
format: Exclude<SigningKeyFormat, "jwk">;
|
|
34
|
+
data: Buffer;
|
|
35
|
+
};
|
|
36
|
+
type SignatureSignConfig = {
|
|
37
|
+
algorithm: "ecdsa";
|
|
38
|
+
curve: SignatureEcdsaCurve;
|
|
39
|
+
hash: SignatureHash;
|
|
40
|
+
key: SignatureSigningKeyConfig;
|
|
41
|
+
} | {
|
|
42
|
+
algorithm: "rsa-pkcs1-v1.5";
|
|
43
|
+
hash: SignatureHash;
|
|
44
|
+
key: SignatureSigningKeyConfig;
|
|
45
|
+
} | {
|
|
46
|
+
algorithm: "rsa-pss";
|
|
47
|
+
hash: SignatureHash;
|
|
48
|
+
saltLength?: number;
|
|
49
|
+
key: SignatureSigningKeyConfig;
|
|
50
|
+
} | {
|
|
51
|
+
algorithm: Exclude<SignatureAlgorithm, "ecdsa" | "rsa-pkcs1-v1.5" | "rsa-pss">;
|
|
52
|
+
key: SignatureSigningKeyConfig;
|
|
53
|
+
};
|
|
54
|
+
type SignatureSignFn = (params: {
|
|
55
|
+
message: Buffer;
|
|
56
|
+
}) => Promise<string>;
|
|
57
|
+
type SignatureSigner = SignatureSignConfig | SignatureSignFn;
|
|
58
|
+
declare function signSignature(signer: SignatureSigner, message: Buffer): Promise<string>;
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/remote/uploader.d.ts
|
|
61
|
+
interface RemoteUploadParams {
|
|
62
|
+
bundle: Buffer;
|
|
63
|
+
bundleName: string;
|
|
64
|
+
version: string;
|
|
65
|
+
force?: boolean;
|
|
66
|
+
integrity?: string;
|
|
67
|
+
signature?: string;
|
|
68
|
+
}
|
|
69
|
+
interface RemoteUploadProgress {
|
|
70
|
+
/** Number of bytes successfully transferred so far */
|
|
71
|
+
loaded?: number;
|
|
72
|
+
/** Total payload size in byres */
|
|
73
|
+
total?: number;
|
|
74
|
+
/** 1-based multipart part index currently being uploaded */
|
|
75
|
+
part?: number;
|
|
76
|
+
}
|
|
77
|
+
interface BaseRemoteUploader {
|
|
78
|
+
_onUploadProgress?: (progress: RemoteUploadProgress) => void;
|
|
79
|
+
upload(params: RemoteUploadParams): Promise<void>;
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/remote/remote.d.ts
|
|
83
|
+
interface RemoteConfig {
|
|
84
|
+
/**
|
|
85
|
+
* Endpoint to remote server.
|
|
86
|
+
*/
|
|
87
|
+
endpoint?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Name of the bundle to be used in remote.
|
|
90
|
+
*/
|
|
91
|
+
bundleName?: string;
|
|
92
|
+
uploader?: BaseRemoteUploader;
|
|
93
|
+
deployer?: BaseRemoteDeployer;
|
|
94
|
+
integrity?: boolean | IntegrityMakeConfig;
|
|
95
|
+
signature?: SignatureSignConfig;
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/remote/types.d.ts
|
|
99
|
+
interface RemoteBundleDeployment {
|
|
100
|
+
/** The name of the bundle */
|
|
101
|
+
name: string;
|
|
102
|
+
/** Current deployed version of the bundle */
|
|
103
|
+
version?: string;
|
|
104
|
+
/** Versions deployed in each channel */
|
|
105
|
+
channels?: Record<string, string>;
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
export { IntegrityMakeFn as _, RemoteUploadProgress as a, BaseRemoteDeployer as b, SignatureHash as c, SignatureSigner as d, SignatureSigningKeyConfig as f, IntegrityMakeConfig as g, IntegrityAlgorithm as h, RemoteUploadParams as i, SignatureSignConfig as l, signSignature as m, RemoteConfig as n, SignatureAlgorithm as o, SigningKeyFormat as p, BaseRemoteUploader as r, SignatureEcdsaCurve as s, RemoteBundleDeployment as t, SignatureSignFn as u, IntegrityMaker as v, RemoteDeployParams as x, makeIntegrity as y };
|
package/dist/index.cjs
ADDED
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { n as RemoteConfig } from "./index-cK1sn_xk.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/builtin.d.ts
|
|
4
|
+
type RemoteBundleMatches = string | RegExp | Array<string | RegExp> | ((info: {
|
|
5
|
+
name: string;
|
|
6
|
+
version: string;
|
|
7
|
+
}) => boolean | Promise<boolean>);
|
|
8
|
+
interface BuiltinConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Directory path where to download builtin bundles from remote.
|
|
11
|
+
* @default ".wvb/builtin"
|
|
12
|
+
*/
|
|
13
|
+
outDir?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Patterns to which bundles should be included from remote bundles.
|
|
16
|
+
*/
|
|
17
|
+
include?: RemoteBundleMatches;
|
|
18
|
+
/**
|
|
19
|
+
* Patterns to which bundles should be excluded from remote bundles.
|
|
20
|
+
*/
|
|
21
|
+
exclude?: RemoteBundleMatches;
|
|
22
|
+
/**
|
|
23
|
+
* Clean up builtin directory before the operation.
|
|
24
|
+
* @default true
|
|
25
|
+
*/
|
|
26
|
+
clean?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Concurrency of the download bundles.
|
|
29
|
+
*/
|
|
30
|
+
concurrency?: number;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/create.d.ts
|
|
34
|
+
type IgnoreConfig = Array<string | RegExp> | ((file: string) => boolean | Promise<boolean>);
|
|
35
|
+
type HeadersConfig = Record<string, HeadersInit> | Array<[string, HeadersInit]> | ((file: string) => HeadersInit | null | undefined | Promise<HeadersInit | null | undefined>);
|
|
36
|
+
/**
|
|
37
|
+
* Webview Bundle create config.
|
|
38
|
+
*/
|
|
39
|
+
interface CreateConfig {
|
|
40
|
+
/**
|
|
41
|
+
* Overwrite out-file if file is already exists
|
|
42
|
+
* @default true
|
|
43
|
+
*/
|
|
44
|
+
overwrite?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Ignore patterns which exclude files from the bundle.
|
|
47
|
+
*/
|
|
48
|
+
ignore?: IgnoreConfig;
|
|
49
|
+
/**
|
|
50
|
+
* Headers to set for each files in the Webview Bundle.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* {
|
|
54
|
+
* "*.html": {
|
|
55
|
+
* "cache-control": "max-age=3600",
|
|
56
|
+
* },
|
|
57
|
+
* "*.js": ["cache-control", "max-age=0"]
|
|
58
|
+
* }
|
|
59
|
+
*/
|
|
60
|
+
headers?: HeadersConfig;
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/extract.d.ts
|
|
64
|
+
interface ExtractConfig {
|
|
65
|
+
/**
|
|
66
|
+
* Webview Bundle file to use for extracting.
|
|
67
|
+
* If not provided, the file at the "outFile" path is used by default.
|
|
68
|
+
*/
|
|
69
|
+
file?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Path to extract Webview Bundle files.
|
|
72
|
+
* If not provided, will use Webview Bundle file name as directory.
|
|
73
|
+
*/
|
|
74
|
+
outDir?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Clean up extracted files if out directory already exists.
|
|
77
|
+
* @default false
|
|
78
|
+
*/
|
|
79
|
+
clean?: boolean;
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/serve.d.ts
|
|
83
|
+
interface ServeConfig {
|
|
84
|
+
/**
|
|
85
|
+
* Webview Bundle file to use for serving with http server.
|
|
86
|
+
* If not provided, the file at the "outFile" path is used by default.
|
|
87
|
+
*/
|
|
88
|
+
file?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Specify a port number on which to start the http server.
|
|
91
|
+
* @default 4312
|
|
92
|
+
*/
|
|
93
|
+
port?: number;
|
|
94
|
+
/**
|
|
95
|
+
* Disable log output.
|
|
96
|
+
*/
|
|
97
|
+
silent?: boolean;
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/config.d.ts
|
|
101
|
+
type ConfigInputFnObj = () => Config;
|
|
102
|
+
type ConfigInputFnPromise = () => Promise<Config>;
|
|
103
|
+
type ConfigInputFn = () => Config | Promise<Config>;
|
|
104
|
+
type ConfigInput = Config | Promise<Config> | ConfigInputFnObj | ConfigInputFnPromise | ConfigInputFn;
|
|
105
|
+
declare function defineConfig(config: Config): Config;
|
|
106
|
+
declare function defineConfig(config: Promise<Config>): Promise<Config>;
|
|
107
|
+
declare function defineConfig(config: ConfigInputFnObj): ConfigInputFnObj;
|
|
108
|
+
declare function defineConfig(config: ConfigInputFnPromise): ConfigInputFnPromise;
|
|
109
|
+
declare function defineConfig(config: ConfigInputFn): ConfigInputFn;
|
|
110
|
+
declare function defineConfig(config: ConfigInput): ConfigInput;
|
|
111
|
+
interface Config {
|
|
112
|
+
/**
|
|
113
|
+
* Project root directory. Can be an absolute path, or a path relative
|
|
114
|
+
* from the current file.
|
|
115
|
+
* @default process.cwd()
|
|
116
|
+
*/
|
|
117
|
+
root?: string;
|
|
118
|
+
/**
|
|
119
|
+
* Path to the source directory.
|
|
120
|
+
*
|
|
121
|
+
* All files under this directory will be included in the Webview Bundle.
|
|
122
|
+
* Use "create.ignore" to exclude files you don't want to pack.
|
|
123
|
+
*/
|
|
124
|
+
srcDir?: string;
|
|
125
|
+
/**
|
|
126
|
+
* Directory that out-file should be created.
|
|
127
|
+
* @default ".wvb"
|
|
128
|
+
*/
|
|
129
|
+
outDir?: string;
|
|
130
|
+
/**
|
|
131
|
+
* Outfile name to create Webview Bundle archive.
|
|
132
|
+
* If not provided, default to name field in "package.json" with normalized.
|
|
133
|
+
*/
|
|
134
|
+
outFile?: string;
|
|
135
|
+
create?: CreateConfig;
|
|
136
|
+
extract?: ExtractConfig;
|
|
137
|
+
remote?: RemoteConfig;
|
|
138
|
+
serve?: ServeConfig;
|
|
139
|
+
builtin?: BuiltinConfig;
|
|
140
|
+
}
|
|
141
|
+
//#endregion
|
|
142
|
+
export { type BuiltinConfig, type Config, type ConfigInput, type ConfigInputFn, type ConfigInputFnObj, type ConfigInputFnPromise, type CreateConfig, type ExtractConfig, type HeadersConfig, type IgnoreConfig, type RemoteBundleMatches, type ServeConfig, defineConfig };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { n as RemoteConfig } from "./index-Da62rQR9.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/builtin.d.ts
|
|
4
|
+
type RemoteBundleMatches = string | RegExp | Array<string | RegExp> | ((info: {
|
|
5
|
+
name: string;
|
|
6
|
+
version: string;
|
|
7
|
+
}) => boolean | Promise<boolean>);
|
|
8
|
+
interface BuiltinConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Directory path where to download builtin bundles from remote.
|
|
11
|
+
* @default ".wvb/builtin"
|
|
12
|
+
*/
|
|
13
|
+
outDir?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Patterns to which bundles should be included from remote bundles.
|
|
16
|
+
*/
|
|
17
|
+
include?: RemoteBundleMatches;
|
|
18
|
+
/**
|
|
19
|
+
* Patterns to which bundles should be excluded from remote bundles.
|
|
20
|
+
*/
|
|
21
|
+
exclude?: RemoteBundleMatches;
|
|
22
|
+
/**
|
|
23
|
+
* Clean up builtin directory before the operation.
|
|
24
|
+
* @default true
|
|
25
|
+
*/
|
|
26
|
+
clean?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Concurrency of the download bundles.
|
|
29
|
+
*/
|
|
30
|
+
concurrency?: number;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/create.d.ts
|
|
34
|
+
type IgnoreConfig = Array<string | RegExp> | ((file: string) => boolean | Promise<boolean>);
|
|
35
|
+
type HeadersConfig = Record<string, HeadersInit> | Array<[string, HeadersInit]> | ((file: string) => HeadersInit | null | undefined | Promise<HeadersInit | null | undefined>);
|
|
36
|
+
/**
|
|
37
|
+
* Webview Bundle create config.
|
|
38
|
+
*/
|
|
39
|
+
interface CreateConfig {
|
|
40
|
+
/**
|
|
41
|
+
* Overwrite out-file if file is already exists
|
|
42
|
+
* @default true
|
|
43
|
+
*/
|
|
44
|
+
overwrite?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Ignore patterns which exclude files from the bundle.
|
|
47
|
+
*/
|
|
48
|
+
ignore?: IgnoreConfig;
|
|
49
|
+
/**
|
|
50
|
+
* Headers to set for each files in the Webview Bundle.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* {
|
|
54
|
+
* "*.html": {
|
|
55
|
+
* "cache-control": "max-age=3600",
|
|
56
|
+
* },
|
|
57
|
+
* "*.js": ["cache-control", "max-age=0"]
|
|
58
|
+
* }
|
|
59
|
+
*/
|
|
60
|
+
headers?: HeadersConfig;
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/extract.d.ts
|
|
64
|
+
interface ExtractConfig {
|
|
65
|
+
/**
|
|
66
|
+
* Webview Bundle file to use for extracting.
|
|
67
|
+
* If not provided, the file at the "outFile" path is used by default.
|
|
68
|
+
*/
|
|
69
|
+
file?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Path to extract Webview Bundle files.
|
|
72
|
+
* If not provided, will use Webview Bundle file name as directory.
|
|
73
|
+
*/
|
|
74
|
+
outDir?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Clean up extracted files if out directory already exists.
|
|
77
|
+
* @default false
|
|
78
|
+
*/
|
|
79
|
+
clean?: boolean;
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/serve.d.ts
|
|
83
|
+
interface ServeConfig {
|
|
84
|
+
/**
|
|
85
|
+
* Webview Bundle file to use for serving with http server.
|
|
86
|
+
* If not provided, the file at the "outFile" path is used by default.
|
|
87
|
+
*/
|
|
88
|
+
file?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Specify a port number on which to start the http server.
|
|
91
|
+
* @default 4312
|
|
92
|
+
*/
|
|
93
|
+
port?: number;
|
|
94
|
+
/**
|
|
95
|
+
* Disable log output.
|
|
96
|
+
*/
|
|
97
|
+
silent?: boolean;
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/config.d.ts
|
|
101
|
+
type ConfigInputFnObj = () => Config;
|
|
102
|
+
type ConfigInputFnPromise = () => Promise<Config>;
|
|
103
|
+
type ConfigInputFn = () => Config | Promise<Config>;
|
|
104
|
+
type ConfigInput = Config | Promise<Config> | ConfigInputFnObj | ConfigInputFnPromise | ConfigInputFn;
|
|
105
|
+
declare function defineConfig(config: Config): Config;
|
|
106
|
+
declare function defineConfig(config: Promise<Config>): Promise<Config>;
|
|
107
|
+
declare function defineConfig(config: ConfigInputFnObj): ConfigInputFnObj;
|
|
108
|
+
declare function defineConfig(config: ConfigInputFnPromise): ConfigInputFnPromise;
|
|
109
|
+
declare function defineConfig(config: ConfigInputFn): ConfigInputFn;
|
|
110
|
+
declare function defineConfig(config: ConfigInput): ConfigInput;
|
|
111
|
+
interface Config {
|
|
112
|
+
/**
|
|
113
|
+
* Project root directory. Can be an absolute path, or a path relative
|
|
114
|
+
* from the current file.
|
|
115
|
+
* @default process.cwd()
|
|
116
|
+
*/
|
|
117
|
+
root?: string;
|
|
118
|
+
/**
|
|
119
|
+
* Path to the source directory.
|
|
120
|
+
*
|
|
121
|
+
* All files under this directory will be included in the Webview Bundle.
|
|
122
|
+
* Use "create.ignore" to exclude files you don't want to pack.
|
|
123
|
+
*/
|
|
124
|
+
srcDir?: string;
|
|
125
|
+
/**
|
|
126
|
+
* Directory that out-file should be created.
|
|
127
|
+
* @default ".wvb"
|
|
128
|
+
*/
|
|
129
|
+
outDir?: string;
|
|
130
|
+
/**
|
|
131
|
+
* Outfile name to create Webview Bundle archive.
|
|
132
|
+
* If not provided, default to name field in "package.json" with normalized.
|
|
133
|
+
*/
|
|
134
|
+
outFile?: string;
|
|
135
|
+
create?: CreateConfig;
|
|
136
|
+
extract?: ExtractConfig;
|
|
137
|
+
remote?: RemoteConfig;
|
|
138
|
+
serve?: ServeConfig;
|
|
139
|
+
builtin?: BuiltinConfig;
|
|
140
|
+
}
|
|
141
|
+
//#endregion
|
|
142
|
+
export { type BuiltinConfig, type Config, type ConfigInput, type ConfigInputFn, type ConfigInputFnObj, type ConfigInputFnPromise, type CreateConfig, type ExtractConfig, type HeadersConfig, type IgnoreConfig, type RemoteBundleMatches, type ServeConfig, defineConfig };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
let node_buffer = require("node:buffer");
|
|
2
|
+
|
|
3
|
+
//#region src/remote/integrity.ts
|
|
4
|
+
async function makeIntegrity(maker, data) {
|
|
5
|
+
if (typeof maker === "function") return maker({ data });
|
|
6
|
+
const alg = maker?.algorithm ?? "sha256";
|
|
7
|
+
const hash = await crypto.subtle.digest({ name: hashAlg$1(alg) }, new Uint8Array(data));
|
|
8
|
+
return `${alg}:${node_buffer.Buffer.from(hash).toString("hex")}`;
|
|
9
|
+
}
|
|
10
|
+
function hashAlg$1(rasHash) {
|
|
11
|
+
switch (rasHash) {
|
|
12
|
+
case "sha256": return "SHA-256";
|
|
13
|
+
case "sha384": return "SHA-384";
|
|
14
|
+
case "sha512": return "SHA-512";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/remote/signature.ts
|
|
20
|
+
async function signSignature(signer, message) {
|
|
21
|
+
if (typeof signer === "function") return signer({ message });
|
|
22
|
+
const { key } = signer;
|
|
23
|
+
const signingKey = key.format === "jwk" ? await crypto.subtle.importKey(key.format, key.data, importKeyAlg(signer), true, ["sign"]) : await crypto.subtle.importKey(key.format, new Uint8Array(key.data), importKeyAlg(signer), true, ["sign"]);
|
|
24
|
+
const signed = await crypto.subtle.sign(signAlg(signer), signingKey, new Uint8Array(message));
|
|
25
|
+
return node_buffer.Buffer.from(signed).toString("base64");
|
|
26
|
+
}
|
|
27
|
+
function importKeyAlg(config) {
|
|
28
|
+
switch (config.algorithm) {
|
|
29
|
+
case "ecdsa": return {
|
|
30
|
+
name: "ECDSA",
|
|
31
|
+
namedCurve: ecdsaCurveName(config.curve)
|
|
32
|
+
};
|
|
33
|
+
case "ed25519": return { name: "Ed25519" };
|
|
34
|
+
case "rsa-pkcs1-v1.5": return {
|
|
35
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
36
|
+
hash: hashAlg(config.hash)
|
|
37
|
+
};
|
|
38
|
+
case "rsa-pss": return {
|
|
39
|
+
name: "RSA-PSS",
|
|
40
|
+
hash: hashAlg(config.hash)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function ecdsaCurveName(curve) {
|
|
45
|
+
switch (curve) {
|
|
46
|
+
case "p256": return "P-256";
|
|
47
|
+
case "p384": return "P-384";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function hashAlg(hash) {
|
|
51
|
+
switch (hash) {
|
|
52
|
+
case "sha256": return "SHA-256";
|
|
53
|
+
case "sha384": return "SHA-384";
|
|
54
|
+
case "sha512": return "SHA-512";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function getDefaultSaltLength(hash) {
|
|
58
|
+
switch (hash) {
|
|
59
|
+
case "sha256": return 32;
|
|
60
|
+
case "sha384": return 48;
|
|
61
|
+
case "sha512": return 64;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function signAlg(config) {
|
|
65
|
+
switch (config.algorithm) {
|
|
66
|
+
case "ecdsa": return {
|
|
67
|
+
name: "ECDSA",
|
|
68
|
+
hash: hashAlg(config.hash)
|
|
69
|
+
};
|
|
70
|
+
case "ed25519": return { name: "Ed25519" };
|
|
71
|
+
case "rsa-pkcs1-v1.5": return { name: "RSASSA-PKCS1-v1_5" };
|
|
72
|
+
case "rsa-pss": return {
|
|
73
|
+
name: "RSA-PSS",
|
|
74
|
+
saltLength: config.saltLength ?? getDefaultSaltLength(config.hash)
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
exports.makeIntegrity = makeIntegrity;
|
|
81
|
+
exports.signSignature = signSignature;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { _ as IntegrityMakeFn, a as RemoteUploadProgress, b as BaseRemoteDeployer, c as SignatureHash, d as SignatureSigner, f as SignatureSigningKeyConfig, g as IntegrityMakeConfig, h as IntegrityAlgorithm, i as RemoteUploadParams, l as SignatureSignConfig, m as signSignature, n as RemoteConfig, o as SignatureAlgorithm, p as SigningKeyFormat, r as BaseRemoteUploader, s as SignatureEcdsaCurve, t as RemoteBundleDeployment, u as SignatureSignFn, v as IntegrityMaker, x as RemoteDeployParams, y as makeIntegrity } from "../index-cK1sn_xk.cjs";
|
|
2
|
+
export { BaseRemoteDeployer, BaseRemoteUploader, IntegrityAlgorithm, IntegrityMakeConfig, IntegrityMakeFn, IntegrityMaker, RemoteBundleDeployment, RemoteConfig, RemoteDeployParams, RemoteUploadParams, RemoteUploadProgress, SignatureAlgorithm, SignatureEcdsaCurve, SignatureHash, SignatureSignConfig, SignatureSignFn, SignatureSigner, SignatureSigningKeyConfig, SigningKeyFormat, makeIntegrity, signSignature };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { _ as IntegrityMakeFn, a as RemoteUploadProgress, b as BaseRemoteDeployer, c as SignatureHash, d as SignatureSigner, f as SignatureSigningKeyConfig, g as IntegrityMakeConfig, h as IntegrityAlgorithm, i as RemoteUploadParams, l as SignatureSignConfig, m as signSignature, n as RemoteConfig, o as SignatureAlgorithm, p as SigningKeyFormat, r as BaseRemoteUploader, s as SignatureEcdsaCurve, t as RemoteBundleDeployment, u as SignatureSignFn, v as IntegrityMaker, x as RemoteDeployParams, y as makeIntegrity } from "../index-Da62rQR9.mjs";
|
|
2
|
+
export { BaseRemoteDeployer, BaseRemoteUploader, IntegrityAlgorithm, IntegrityMakeConfig, IntegrityMakeFn, IntegrityMaker, RemoteBundleDeployment, RemoteConfig, RemoteDeployParams, RemoteUploadParams, RemoteUploadProgress, SignatureAlgorithm, SignatureEcdsaCurve, SignatureHash, SignatureSignConfig, SignatureSignFn, SignatureSigner, SignatureSigningKeyConfig, SigningKeyFormat, makeIntegrity, signSignature };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
|
|
3
|
+
//#region src/remote/integrity.ts
|
|
4
|
+
async function makeIntegrity(maker, data) {
|
|
5
|
+
if (typeof maker === "function") return maker({ data });
|
|
6
|
+
const alg = maker?.algorithm ?? "sha256";
|
|
7
|
+
const hash = await crypto.subtle.digest({ name: hashAlg$1(alg) }, new Uint8Array(data));
|
|
8
|
+
return `${alg}:${Buffer.from(hash).toString("hex")}`;
|
|
9
|
+
}
|
|
10
|
+
function hashAlg$1(rasHash) {
|
|
11
|
+
switch (rasHash) {
|
|
12
|
+
case "sha256": return "SHA-256";
|
|
13
|
+
case "sha384": return "SHA-384";
|
|
14
|
+
case "sha512": return "SHA-512";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/remote/signature.ts
|
|
20
|
+
async function signSignature(signer, message) {
|
|
21
|
+
if (typeof signer === "function") return signer({ message });
|
|
22
|
+
const { key } = signer;
|
|
23
|
+
const signingKey = key.format === "jwk" ? await crypto.subtle.importKey(key.format, key.data, importKeyAlg(signer), true, ["sign"]) : await crypto.subtle.importKey(key.format, new Uint8Array(key.data), importKeyAlg(signer), true, ["sign"]);
|
|
24
|
+
const signed = await crypto.subtle.sign(signAlg(signer), signingKey, new Uint8Array(message));
|
|
25
|
+
return Buffer.from(signed).toString("base64");
|
|
26
|
+
}
|
|
27
|
+
function importKeyAlg(config) {
|
|
28
|
+
switch (config.algorithm) {
|
|
29
|
+
case "ecdsa": return {
|
|
30
|
+
name: "ECDSA",
|
|
31
|
+
namedCurve: ecdsaCurveName(config.curve)
|
|
32
|
+
};
|
|
33
|
+
case "ed25519": return { name: "Ed25519" };
|
|
34
|
+
case "rsa-pkcs1-v1.5": return {
|
|
35
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
36
|
+
hash: hashAlg(config.hash)
|
|
37
|
+
};
|
|
38
|
+
case "rsa-pss": return {
|
|
39
|
+
name: "RSA-PSS",
|
|
40
|
+
hash: hashAlg(config.hash)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function ecdsaCurveName(curve) {
|
|
45
|
+
switch (curve) {
|
|
46
|
+
case "p256": return "P-256";
|
|
47
|
+
case "p384": return "P-384";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function hashAlg(hash) {
|
|
51
|
+
switch (hash) {
|
|
52
|
+
case "sha256": return "SHA-256";
|
|
53
|
+
case "sha384": return "SHA-384";
|
|
54
|
+
case "sha512": return "SHA-512";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function getDefaultSaltLength(hash) {
|
|
58
|
+
switch (hash) {
|
|
59
|
+
case "sha256": return 32;
|
|
60
|
+
case "sha384": return 48;
|
|
61
|
+
case "sha512": return 64;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function signAlg(config) {
|
|
65
|
+
switch (config.algorithm) {
|
|
66
|
+
case "ecdsa": return {
|
|
67
|
+
name: "ECDSA",
|
|
68
|
+
hash: hashAlg(config.hash)
|
|
69
|
+
};
|
|
70
|
+
case "ed25519": return { name: "Ed25519" };
|
|
71
|
+
case "rsa-pkcs1-v1.5": return { name: "RSASSA-PKCS1-v1_5" };
|
|
72
|
+
case "rsa-pss": return {
|
|
73
|
+
name: "RSA-PSS",
|
|
74
|
+
saltLength: config.saltLength ?? getDefaultSaltLength(config.hash)
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
export { makeIntegrity, signSignature };
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wvb/config",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Configuration for webview bundle",
|
|
5
|
+
"homepage": "https://github.com/webview-bundle/webview-bundle",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/webview-bundle/webview-bundle/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": {
|
|
11
|
+
"name": "Seokju Na",
|
|
12
|
+
"email": "seokju.me@gmail.com",
|
|
13
|
+
"url": "https://github.com/seokju-na"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/webview-bundle/webview-bundle",
|
|
18
|
+
"directory": "packages/config"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md",
|
|
23
|
+
"CHANGELOG.md"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"main": "./dist/index.mjs",
|
|
27
|
+
"types": "./dist/index.d.mts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"import": "./dist/index.mjs",
|
|
31
|
+
"require": "./dist/index.cjs"
|
|
32
|
+
},
|
|
33
|
+
"./remote": {
|
|
34
|
+
"import": "./dist/remote/index.mjs",
|
|
35
|
+
"require": "./dist/remote/index.cjs"
|
|
36
|
+
},
|
|
37
|
+
"./package.json": "./package.json"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"prepack": "yarn build",
|
|
41
|
+
"build": "tsdown",
|
|
42
|
+
"typecheck": "tsc --noEmit"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "22.19.3",
|
|
46
|
+
"tsdown": "0.20.1",
|
|
47
|
+
"typescript": "5.9.3",
|
|
48
|
+
"vitest": "4.0.15"
|
|
49
|
+
}
|
|
50
|
+
}
|