@bubblewrap/core 1.13.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/LICENSE +203 -0
  2. package/README.md +63 -0
  3. package/dist/index.d.ts +17 -0
  4. package/dist/index.js +56 -0
  5. package/dist/lib/BufferedLog.d.ts +20 -0
  6. package/dist/lib/BufferedLog.js +83 -0
  7. package/dist/lib/Config.d.ts +9 -0
  8. package/dist/lib/Config.js +50 -0
  9. package/dist/lib/DigitalAssetLinks.d.ts +3 -0
  10. package/dist/lib/DigitalAssetLinks.js +37 -0
  11. package/dist/lib/FetchUtils.d.ts +17 -0
  12. package/dist/lib/FetchUtils.js +79 -0
  13. package/dist/lib/GooglePlay.d.ts +41 -0
  14. package/dist/lib/GooglePlay.js +92 -0
  15. package/dist/lib/GradleWrapper.d.ts +31 -0
  16. package/dist/lib/GradleWrapper.js +62 -0
  17. package/dist/lib/ImageHelper.d.ts +37 -0
  18. package/dist/lib/ImageHelper.js +112 -0
  19. package/dist/lib/Log.d.ts +88 -0
  20. package/dist/lib/Log.js +114 -0
  21. package/dist/lib/Result.d.ts +46 -0
  22. package/dist/lib/Result.js +97 -0
  23. package/dist/lib/ShortcutInfo.d.ts +32 -0
  24. package/dist/lib/ShortcutInfo.js +84 -0
  25. package/dist/lib/TwaGenerator.d.ts +39 -0
  26. package/dist/lib/TwaGenerator.js +362 -0
  27. package/dist/lib/TwaManifest.d.ts +234 -0
  28. package/dist/lib/TwaManifest.js +384 -0
  29. package/dist/lib/androidSdk/AndroidSdkTools.d.ts +87 -0
  30. package/dist/lib/androidSdk/AndroidSdkTools.js +226 -0
  31. package/dist/lib/errors/ValidatePathError.d.ts +9 -0
  32. package/dist/lib/errors/ValidatePathError.js +16 -0
  33. package/dist/lib/features/AppsFlyerFeature.d.ts +8 -0
  34. package/dist/lib/features/AppsFlyerFeature.js +70 -0
  35. package/dist/lib/features/EmptyFeature.d.ts +28 -0
  36. package/dist/lib/features/EmptyFeature.js +44 -0
  37. package/dist/lib/features/Feature.d.ts +120 -0
  38. package/dist/lib/features/Feature.js +17 -0
  39. package/dist/lib/features/FeatureManager.d.ts +36 -0
  40. package/dist/lib/features/FeatureManager.js +137 -0
  41. package/dist/lib/features/FirstRunFlagFeature.d.ts +8 -0
  42. package/dist/lib/features/FirstRunFlagFeature.js +43 -0
  43. package/dist/lib/features/LocationDelegationFeature.d.ts +7 -0
  44. package/dist/lib/features/LocationDelegationFeature.js +32 -0
  45. package/dist/lib/features/PlayBillingFeature.d.ts +7 -0
  46. package/dist/lib/features/PlayBillingFeature.js +53 -0
  47. package/dist/lib/jdk/JarSigner.d.ts +13 -0
  48. package/dist/lib/jdk/JarSigner.js +55 -0
  49. package/dist/lib/jdk/JdkHelper.d.ts +55 -0
  50. package/dist/lib/jdk/JdkHelper.js +127 -0
  51. package/dist/lib/jdk/KeyTool.d.ts +57 -0
  52. package/dist/lib/jdk/KeyTool.js +136 -0
  53. package/dist/lib/mock/MockLog.d.ts +37 -0
  54. package/dist/lib/mock/MockLog.js +70 -0
  55. package/dist/lib/types/WebManifest.d.ts +44 -0
  56. package/dist/lib/types/WebManifest.js +17 -0
  57. package/dist/lib/util.d.ts +82 -0
  58. package/dist/lib/util.js +279 -0
  59. package/dist/lib/wrappers/svg2img.d.ts +14 -0
  60. package/dist/lib/wrappers/svg2img.js +39 -0
  61. package/package.json +58 -0
  62. package/template_project/app/.gitignore +1 -0
  63. package/template_project/app/build.gradle +211 -0
  64. package/template_project/app/src/main/AndroidManifest.xml +204 -0
  65. package/template_project/app/src/main/java/Application.java +35 -0
  66. package/template_project/app/src/main/java/DelegationService.java +18 -0
  67. package/template_project/app/src/main/java/LauncherActivity.java +62 -0
  68. package/template_project/app/src/main/res/drawable-anydpi/shortcut_legacy_background.xml +25 -0
  69. package/template_project/app/src/main/res/drawable-anydpi/shortcut_monochrome.xml +27 -0
  70. package/template_project/app/src/main/res/drawable-anydpi-v26/shortcut_maskable.xml +32 -0
  71. package/template_project/app/src/main/res/drawable-anydpi-v26/shortcut_monochrome.xml +26 -0
  72. package/template_project/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +33 -0
  73. package/template_project/app/src/main/res/values/colors.xml +18 -0
  74. package/template_project/app/src/main/res/values/strings.xml +50 -0
  75. package/template_project/app/src/main/res/xml/filepaths.xml +18 -0
  76. package/template_project/app/src/main/res/xml/shortcuts.xml +16 -0
  77. package/template_project/build.gradle +42 -0
  78. package/template_project/enable-debug.sh +27 -0
  79. package/template_project/gradle/wrapper/gradle-wrapper.jar +0 -0
  80. package/template_project/gradle/wrapper/gradle-wrapper.properties +5 -0
  81. package/template_project/gradle.properties +14 -0
  82. package/template_project/gradlew +188 -0
  83. package/template_project/gradlew.bat +100 -0
  84. package/template_project/settings.gradle +1 -0
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2020 Google Inc. All Rights Reserved.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ImageHelper = void 0;
19
+ const path = require("path");
20
+ const fs = require("fs");
21
+ const Jimp = require("jimp");
22
+ const FetchUtils_1 = require("./FetchUtils");
23
+ const util_1 = require("util");
24
+ const svg2img_1 = require("./wrappers/svg2img");
25
+ // fs.promises is marked as experimental. This should be replaced when stable.
26
+ const fsMkDir = util_1.promisify(fs.mkdir);
27
+ class ImageHelper {
28
+ async saveIcon(icon, size, fileName, backgroundColor) {
29
+ const image = await Jimp.read(icon.data);
30
+ // Jimp creates artifacts when upscaling images that have an alpha channel. This happens
31
+ // because even when a pixel is fully transparent the RGB part of the color still gets blended
32
+ // with other pixels. To avoid this, we apply the RGB part of `backgroundColor` to transparent
33
+ // pixels so they are blended with that color instead and match a background.
34
+ // See https://github.com/GoogleChromeLabs/bubblewrap/issues/488#issuecomment-806560923.
35
+ if (backgroundColor && image.hasAlpha()) {
36
+ // The replacement colour is the same as the background colour, but fully transparent.
37
+ const replacementColor = ((backgroundColor.rgbNumber() << 8) & 0xFFFFFF00) >>> 0;
38
+ // Iterate over the pixels, check for fully transparent ones and replace with
39
+ // replacementColor.
40
+ for (let y = 0; y < image.getHeight(); y++) {
41
+ for (let x = 0; x < image.getWidth(); x++) {
42
+ const color = image.getPixelColour(x, y);
43
+ // Apply replacement color if the pixel is fully transparent.
44
+ if ((color & 0xFF) === 0) {
45
+ image.setPixelColour(replacementColor, x, y);
46
+ }
47
+ }
48
+ }
49
+ }
50
+ image.resize(size, size);
51
+ await image.writeAsync(fileName);
52
+ }
53
+ /**
54
+ * Generate a file for the given icon inside targetDir.
55
+ *
56
+ * @param {Object} icon Object containing the original URL and the icon image data.
57
+ * @param {string} targetDir Path to the directory the image will be saved in.
58
+ * @param {Object} iconDef Icon definitions specifying the size the icon should be exported as.
59
+ */
60
+ async generateIcon(icon, targetDir, iconDef, backgroundColor) {
61
+ const destFile = path.join(targetDir, iconDef.dest);
62
+ await fsMkDir(path.dirname(destFile), { recursive: true });
63
+ return await this.saveIcon(icon, iconDef.size, destFile, backgroundColor);
64
+ }
65
+ /**
66
+ * Set the color of a monochrome icon to be the theme color.
67
+ *
68
+ * @param {Object} icon Original monochrome icon to use.
69
+ * @param {Color} themeColor Color to use for the icon.
70
+ * @returns New image data.
71
+ */
72
+ async monochromeFilter(icon, themeColor) {
73
+ const image = await Jimp.read(icon.data);
74
+ image.color([
75
+ // Set all pixels to black/0
76
+ { apply: 'red', params: [-255] },
77
+ { apply: 'green', params: [-255] },
78
+ { apply: 'blue', params: [-255] },
79
+ // Add to channels using theme color
80
+ { apply: 'red', params: [themeColor.red()] },
81
+ { apply: 'green', params: [themeColor.green()] },
82
+ { apply: 'blue', params: [themeColor.blue()] },
83
+ ]);
84
+ return { url: icon.url, data: image };
85
+ }
86
+ /**
87
+ * Fetches an Icon.
88
+ *
89
+ * @param {string} iconUrl the URL to fetch the icon from.
90
+ * @returns an Object containing the original URL and the icon image data.
91
+ */
92
+ async fetchIcon(iconUrl) {
93
+ const response = await FetchUtils_1.fetchUtils.fetch(iconUrl);
94
+ if (response.status !== 200) {
95
+ throw new Error(`Failed to download icon ${iconUrl}. Responded with status ${response.status}`);
96
+ }
97
+ const contentType = response.headers.get('content-type');
98
+ if (!(contentType === null || contentType === void 0 ? void 0 : contentType.startsWith('image/'))) {
99
+ throw new Error(`Received icon "${iconUrl}" with invalid Content-Type.` +
100
+ ` Responded with Content-Type "${contentType}"`);
101
+ }
102
+ let body = await response.arrayBuffer();
103
+ if (contentType.startsWith('image/svg')) {
104
+ body = await svg2img_1.svg2img(iconUrl);
105
+ }
106
+ return {
107
+ url: iconUrl,
108
+ data: await Jimp.read(Buffer.from(body)),
109
+ };
110
+ }
111
+ }
112
+ exports.ImageHelper = ImageHelper;
@@ -0,0 +1,88 @@
1
+ /**
2
+ * An interface for loggers.
3
+ */
4
+ export interface Log {
5
+ /**
6
+ * Prints a debug message to the Log. Message is ignored if the Log is not set to verbose.
7
+ * @param message the message the be printed.
8
+ * @param args extra arguments for the console.
9
+ */
10
+ debug(message: string, ...args: string[]): void;
11
+ /**
12
+ * Prints an info message to the Log. Message is ignored if the Log is not set to verbose.
13
+ * @param message The message the be printed.
14
+ * @param args Extra arguments for the console.
15
+ */
16
+ info(message: string, ...args: string[]): void;
17
+ /**
18
+ * Prints an warning message to the Log. Message is ignored if the Log is not set to verbose.
19
+ * @param message The message the be printed.
20
+ * @param args Extra arguments for the console.
21
+ */
22
+ warn(message: string, ...args: string[]): void;
23
+ /**
24
+ * Prints an error message to the Log. Message is ignored if the Log is not set to verbose.
25
+ * @param message The message the be printed.
26
+ * @param args Extra arguments for the console.
27
+ */
28
+ error(message: string, ...args: string[]): void;
29
+ setVerbose(verbose: boolean): void;
30
+ }
31
+ /**
32
+ * An utility class to print nice Log messages.
33
+ */
34
+ export declare class ConsoleLog implements Log {
35
+ private tag;
36
+ private prefix;
37
+ private output;
38
+ /**
39
+ * The verbosity of the Log. "debug" messages are ignored if verbose is set to false.
40
+ */
41
+ verbose: boolean;
42
+ /**
43
+ * Creates a new Log instance
44
+ * @param tag The tag used when logging. Printed at the beggining of a log message.
45
+ * @param verbose If the Log is verbose. Debug messages are only printed on verbose logs.
46
+ * @param output Where to output the log messages.
47
+ */
48
+ constructor(tag?: string, verbose?: boolean, output?: Console);
49
+ /**
50
+ * Prints a debug message to the Log. Message is ignored if the Log is not set to verbose.
51
+ * @param message The message the be printed.
52
+ * @param args Extra arguments for the console.
53
+ */
54
+ debug(message: string, ...args: string[]): void;
55
+ /**
56
+ * Prints an info message to the Log. Message is ignored if the Log is not set to verbose.
57
+ * @param message The message the be printed.
58
+ * @param args Extra arguments for the console.
59
+ */
60
+ info(message: string, ...args: string[]): void;
61
+ /**
62
+ * Prints an warning message to the Log. Message is ignored if the Log is not set to verbose.
63
+ * @param message The message the be printed.
64
+ * @param args Extra arguments for the console.
65
+ */
66
+ warn(message: string, ...args: string[]): void;
67
+ /**
68
+ * Prints an error message to the Log. Message is ignored if the Log is not set to verbose.
69
+ * @param message The message the be printed.
70
+ * @param args Extra arguments for the console.
71
+ */
72
+ error(message: string, ...args: string[]): void;
73
+ /**
74
+ * Sets the verbose.
75
+ * @param verbose The verbose value to set.
76
+ */
77
+ setVerbose(verbose: boolean): void;
78
+ /**
79
+ * Creates a new Log using the same output and verbositity of the current Log.
80
+ * @param newTag The tag the be used on the new Log instance.
81
+ */
82
+ newLog(newTag: string): ConsoleLog;
83
+ private log;
84
+ private inverse;
85
+ private dim;
86
+ private yellow;
87
+ private red;
88
+ }
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2019 Google Inc. All Rights Reserved.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ConsoleLog = void 0;
19
+ ;
20
+ /**
21
+ * An utility class to print nice Log messages.
22
+ */
23
+ class ConsoleLog {
24
+ /**
25
+ * Creates a new Log instance
26
+ * @param tag The tag used when logging. Printed at the beggining of a log message.
27
+ * @param verbose If the Log is verbose. Debug messages are only printed on verbose logs.
28
+ * @param output Where to output the log messages.
29
+ */
30
+ constructor(tag = '', verbose = false, output = console) {
31
+ this.tag = tag;
32
+ this.verbose = verbose;
33
+ this.prefix = this.inverse(tag);
34
+ this.output = output;
35
+ }
36
+ /**
37
+ * Prints a debug message to the Log. Message is ignored if the Log is not set to verbose.
38
+ * @param message The message the be printed.
39
+ * @param args Extra arguments for the console.
40
+ */
41
+ debug(message, ...args) {
42
+ if (!this.verbose) {
43
+ return;
44
+ }
45
+ this.log(this.output.log, this.dim(message), ...args);
46
+ }
47
+ /**
48
+ * Prints an info message to the Log. Message is ignored if the Log is not set to verbose.
49
+ * @param message The message the be printed.
50
+ * @param args Extra arguments for the console.
51
+ */
52
+ info(message, ...args) {
53
+ this.log(this.output.log, message, ...args);
54
+ }
55
+ /**
56
+ * Prints an warning message to the Log. Message is ignored if the Log is not set to verbose.
57
+ * @param message The message the be printed.
58
+ * @param args Extra arguments for the console.
59
+ */
60
+ warn(message, ...args) {
61
+ this.log(this.output.warn, this.yellow('WARNING ' + message), ...args);
62
+ }
63
+ /**
64
+ * Prints an error message to the Log. Message is ignored if the Log is not set to verbose.
65
+ * @param message The message the be printed.
66
+ * @param args Extra arguments for the console.
67
+ */
68
+ error(message, ...args) {
69
+ this.output.error('\n');
70
+ this.log(this.output.error, this.red('ERROR ' + message), ...args);
71
+ this.output.error('\n');
72
+ }
73
+ /**
74
+ * Sets the verbose.
75
+ * @param verbose The verbose value to set.
76
+ */
77
+ setVerbose(verbose) {
78
+ this.verbose = verbose;
79
+ }
80
+ /**
81
+ * Creates a new Log using the same output and verbositity of the current Log.
82
+ * @param newTag The tag the be used on the new Log instance.
83
+ */
84
+ newLog(newTag) {
85
+ if (this.tag) {
86
+ newTag = this.tag + ' ' + newTag;
87
+ }
88
+ return new ConsoleLog(newTag, this.verbose, this.output);
89
+ }
90
+ log(fn, message, ...args) {
91
+ if (this.prefix) {
92
+ message = this.prefix + ' ' + message;
93
+ }
94
+ if (args) {
95
+ fn(...[message].concat(args));
96
+ }
97
+ else {
98
+ fn(message);
99
+ }
100
+ }
101
+ inverse(input) {
102
+ return `\x1b[7m${input}\x1b[0m`;
103
+ }
104
+ dim(input) {
105
+ return `\x1b[36m${input}\x1b[0m`;
106
+ }
107
+ yellow(input) {
108
+ return `\x1b[33m${input}\x1b[0m`;
109
+ }
110
+ red(input) {
111
+ return `\x1b[31m${input}\x1b[0m`;
112
+ }
113
+ }
114
+ exports.ConsoleLog = ConsoleLog;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * While throwing exceptions show be used to handle truly exception cases, `Result<V, E>` can be
3
+ * used to handle cases where failures are expected, therefore not really exceptions.
4
+ *
5
+ * The outcome can be verified with `Result.isOk()`:
6
+ * ```
7
+ * const result = someMethod();
8
+ * if (result.isOk()) {
9
+ * const value = result.unwrap();
10
+ * ...
11
+ * }
12
+ * ```
13
+ */
14
+ export declare class Result<V, E extends Error> {
15
+ private _result;
16
+ private constructor();
17
+ /**
18
+ * Creates a new `ok` Result, with the outcome `value`.
19
+ */
20
+ static ok<V>(value: V): Result<V, any>;
21
+ /**
22
+ * Creates a new `error` Result, with the outcome `error`.
23
+ */
24
+ static error<E extends Error>(error: E): Result<any, E>;
25
+ /**
26
+ * Returns the value if this result is `ok`. Otherwise, throws `E`.
27
+ */
28
+ unwrap(): V;
29
+ /**
30
+ * If the result is an Error, returns `defaultValue`. Otherwise returns the result value.
31
+ */
32
+ unwrapOr(defaultValue: V): V;
33
+ /**
34
+ * If the result is an Error, returns the `Error` instance without throwing. Otherwise,
35
+ * throws an Exception.
36
+ */
37
+ unwrapError(): E;
38
+ /**
39
+ * @returns `true` if the result is `ok`. `false` if it is an `Error`.
40
+ */
41
+ isOk(): boolean;
42
+ /**
43
+ * @returns `true` if the result is an `Error`. `false` if the result is `ok`.
44
+ */
45
+ isError(): boolean;
46
+ }
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2020 Google Inc. All Rights Reserved.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.Result = void 0;
19
+ /**
20
+ * While throwing exceptions show be used to handle truly exception cases, `Result<V, E>` can be
21
+ * used to handle cases where failures are expected, therefore not really exceptions.
22
+ *
23
+ * The outcome can be verified with `Result.isOk()`:
24
+ * ```
25
+ * const result = someMethod();
26
+ * if (result.isOk()) {
27
+ * const value = result.unwrap();
28
+ * ...
29
+ * }
30
+ * ```
31
+ */
32
+ class Result {
33
+ constructor(result) {
34
+ this._result = result;
35
+ }
36
+ /**
37
+ * Creates a new `ok` Result, with the outcome `value`.
38
+ */
39
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
+ static ok(value) {
41
+ return new Result({
42
+ type: 'ok',
43
+ value: value,
44
+ });
45
+ }
46
+ /**
47
+ * Creates a new `error` Result, with the outcome `error`.
48
+ */
49
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
+ static error(error) {
51
+ return new Result({
52
+ type: 'error',
53
+ error: error,
54
+ });
55
+ }
56
+ /**
57
+ * Returns the value if this result is `ok`. Otherwise, throws `E`.
58
+ */
59
+ unwrap() {
60
+ if (this._result.type === 'error') {
61
+ throw this._result.error;
62
+ }
63
+ return this._result.value;
64
+ }
65
+ /**
66
+ * If the result is an Error, returns `defaultValue`. Otherwise returns the result value.
67
+ */
68
+ unwrapOr(defaultValue) {
69
+ if (this._result.type === 'error') {
70
+ return defaultValue;
71
+ }
72
+ return this._result.value;
73
+ }
74
+ /**
75
+ * If the result is an Error, returns the `Error` instance without throwing. Otherwise,
76
+ * throws an Exception.
77
+ */
78
+ unwrapError() {
79
+ if (this._result.type === 'error') {
80
+ return this._result.error;
81
+ }
82
+ throw new Error('Expected result to be "ok", but it is "error"');
83
+ }
84
+ /**
85
+ * @returns `true` if the result is `ok`. `false` if it is an `Error`.
86
+ */
87
+ isOk() {
88
+ return this._result.type === 'ok';
89
+ }
90
+ /**
91
+ * @returns `true` if the result is an `Error`. `false` if the result is `ok`.
92
+ */
93
+ isError() {
94
+ return this._result.type === 'error';
95
+ }
96
+ }
97
+ exports.Result = Result;