@alwaysai/device-agent 1.5.0 → 2.0.1
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/lib/application-control/config.d.ts.map +1 -1
- package/lib/application-control/config.js +8 -3
- package/lib/application-control/config.js.map +1 -1
- package/lib/application-control/environment-variables.d.ts +5 -5
- package/lib/application-control/environment-variables.d.ts.map +1 -1
- package/lib/application-control/environment-variables.js +25 -38
- package/lib/application-control/environment-variables.js.map +1 -1
- package/lib/application-control/environment-variables.test.js +27 -7
- package/lib/application-control/environment-variables.test.js.map +1 -1
- package/lib/application-control/index.d.ts +4 -4
- package/lib/application-control/index.d.ts.map +1 -1
- package/lib/application-control/index.js +1 -4
- package/lib/application-control/index.js.map +1 -1
- package/lib/application-control/install.d.ts +4 -1
- package/lib/application-control/install.d.ts.map +1 -1
- package/lib/application-control/install.js +24 -8
- package/lib/application-control/install.js.map +1 -1
- package/lib/application-control/models.d.ts +0 -11
- package/lib/application-control/models.d.ts.map +1 -1
- package/lib/application-control/models.js +5 -54
- package/lib/application-control/models.js.map +1 -1
- package/lib/application-control/utils.d.ts +0 -4
- package/lib/application-control/utils.d.ts.map +1 -1
- package/lib/application-control/utils.js +12 -22
- package/lib/application-control/utils.js.map +1 -1
- package/lib/cloud-connection/base-message-handler.d.ts +27 -0
- package/lib/cloud-connection/base-message-handler.d.ts.map +1 -0
- package/lib/cloud-connection/base-message-handler.js +72 -0
- package/lib/cloud-connection/base-message-handler.js.map +1 -0
- package/lib/cloud-connection/bootstrap-provision.js +3 -2
- package/lib/cloud-connection/bootstrap-provision.js.map +1 -1
- package/lib/cloud-connection/connection-manager.d.ts +21 -0
- package/lib/cloud-connection/connection-manager.d.ts.map +1 -0
- package/lib/cloud-connection/connection-manager.js +158 -0
- package/lib/cloud-connection/connection-manager.js.map +1 -0
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts +9 -30
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
- package/lib/cloud-connection/device-agent-cloud-connection.js +69 -508
- package/lib/cloud-connection/device-agent-cloud-connection.js.map +1 -1
- package/lib/cloud-connection/device-agent-message-handler.d.ts +22 -0
- package/lib/cloud-connection/device-agent-message-handler.d.ts.map +1 -0
- package/lib/cloud-connection/device-agent-message-handler.js +357 -0
- package/lib/cloud-connection/device-agent-message-handler.js.map +1 -0
- package/lib/cloud-connection/device-agent.d.ts.map +1 -1
- package/lib/cloud-connection/device-agent.js +11 -9
- package/lib/cloud-connection/device-agent.js.map +1 -1
- package/lib/cloud-connection/live-updates-handler.d.ts +19 -28
- package/lib/cloud-connection/live-updates-handler.d.ts.map +1 -1
- package/lib/cloud-connection/live-updates-handler.js +60 -172
- package/lib/cloud-connection/live-updates-handler.js.map +1 -1
- package/lib/cloud-connection/live-updates-handler.test.js +71 -165
- package/lib/cloud-connection/live-updates-handler.test.js.map +1 -1
- package/lib/cloud-connection/message-dispatcher.d.ts +10 -0
- package/lib/cloud-connection/message-dispatcher.d.ts.map +1 -0
- package/lib/cloud-connection/message-dispatcher.js +27 -0
- package/lib/cloud-connection/message-dispatcher.js.map +1 -0
- package/lib/cloud-connection/passthrough-handler.d.ts +4 -1
- package/lib/cloud-connection/passthrough-handler.d.ts.map +1 -1
- package/lib/cloud-connection/passthrough-handler.js +30 -11
- package/lib/cloud-connection/passthrough-handler.js.map +1 -1
- package/lib/cloud-connection/shadow-handler.d.ts +11 -3
- package/lib/cloud-connection/shadow-handler.d.ts.map +1 -1
- package/lib/cloud-connection/shadow-handler.js +133 -28
- package/lib/cloud-connection/shadow-handler.js.map +1 -1
- package/lib/cloud-connection/shadow-handler.test.js +45 -57
- package/lib/cloud-connection/shadow-handler.test.js.map +1 -1
- package/lib/cloud-connection/shadow.d.ts.map +1 -1
- package/lib/cloud-connection/shadow.js +2 -1
- package/lib/cloud-connection/shadow.js.map +1 -1
- package/lib/cloud-connection/transaction-manager.d.ts +12 -3
- package/lib/cloud-connection/transaction-manager.d.ts.map +1 -1
- package/lib/cloud-connection/transaction-manager.js +29 -28
- package/lib/cloud-connection/transaction-manager.js.map +1 -1
- package/lib/cloud-connection/transaction-manager.test.js +46 -5
- package/lib/cloud-connection/transaction-manager.test.js.map +1 -1
- package/lib/device-control/device-control.d.ts +8 -8
- package/lib/device-control/device-control.d.ts.map +1 -1
- package/lib/device-control/device-control.js +95 -71
- package/lib/device-control/device-control.js.map +1 -1
- package/lib/docker/docker-compose.d.ts.map +1 -1
- package/lib/docker/docker-compose.js +2 -1
- package/lib/docker/docker-compose.js.map +1 -1
- package/lib/infrastructure/agent-config.d.ts +2 -1
- package/lib/infrastructure/agent-config.d.ts.map +1 -1
- package/lib/infrastructure/agent-config.js +7 -7
- package/lib/infrastructure/agent-config.js.map +1 -1
- package/lib/infrastructure/agent-config.test.js +3 -1
- package/lib/infrastructure/agent-config.test.js.map +1 -1
- package/lib/infrastructure/config-check-utility.d.ts +6 -0
- package/lib/infrastructure/config-check-utility.d.ts.map +1 -0
- package/lib/infrastructure/config-check-utility.js +67 -0
- package/lib/infrastructure/config-check-utility.js.map +1 -0
- package/lib/infrastructure/config-check-utility.test.d.ts +2 -0
- package/lib/infrastructure/config-check-utility.test.d.ts.map +1 -0
- package/lib/infrastructure/config-check-utility.test.js +109 -0
- package/lib/infrastructure/config-check-utility.test.js.map +1 -0
- package/lib/infrastructure/device-certificate.d.ts +10 -0
- package/lib/infrastructure/device-certificate.d.ts.map +1 -0
- package/lib/infrastructure/device-certificate.js +47 -0
- package/lib/infrastructure/device-certificate.js.map +1 -0
- package/lib/infrastructure/device-certificate.test.d.ts +2 -0
- package/lib/infrastructure/device-certificate.test.d.ts.map +1 -0
- package/lib/infrastructure/device-certificate.test.js +24 -0
- package/lib/infrastructure/device-certificate.test.js.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-file.test.d.ts +2 -0
- package/lib/infrastructure/legacy-migration/legacy-file.test.d.ts.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-file.test.js +61 -0
- package/lib/infrastructure/legacy-migration/legacy-file.test.js.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-files.d.ts +75 -0
- package/lib/infrastructure/legacy-migration/legacy-files.d.ts.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-files.js +75 -0
- package/lib/infrastructure/legacy-migration/legacy-files.js.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.d.ts +6 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.d.ts.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.js +149 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.js.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.test.d.ts +2 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.test.d.ts.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.test.js +226 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.test.js.map +1 -0
- package/lib/infrastructure/require-files-present-ready.test.d.ts +2 -0
- package/lib/infrastructure/require-files-present-ready.test.d.ts.map +1 -0
- package/lib/infrastructure/require-files-present-ready.test.js +44 -0
- package/lib/infrastructure/require-files-present-ready.test.js.map +1 -0
- package/lib/infrastructure/required-config-checks.d.ts +2 -0
- package/lib/infrastructure/required-config-checks.d.ts.map +1 -0
- package/lib/infrastructure/required-config-checks.js +30 -0
- package/lib/infrastructure/required-config-checks.js.map +1 -0
- package/lib/infrastructure/tokens-and-device-cfg.d.ts.map +1 -1
- package/lib/infrastructure/tokens-and-device-cfg.js +11 -8
- package/lib/infrastructure/tokens-and-device-cfg.js.map +1 -1
- package/lib/jobs/job-handler.d.ts +23 -0
- package/lib/jobs/job-handler.d.ts.map +1 -0
- package/lib/jobs/job-handler.js +131 -0
- package/lib/jobs/job-handler.js.map +1 -0
- package/lib/local-connection/rabbitmq-connection.d.ts.map +1 -1
- package/lib/local-connection/rabbitmq-connection.js +14 -14
- package/lib/local-connection/rabbitmq-connection.js.map +1 -1
- package/lib/secure-tunneling/secure-tunnel-message-handler.d.ts +8 -0
- package/lib/secure-tunneling/secure-tunnel-message-handler.d.ts.map +1 -0
- package/lib/secure-tunneling/secure-tunnel-message-handler.js +42 -0
- package/lib/secure-tunneling/secure-tunnel-message-handler.js.map +1 -0
- package/lib/secure-tunneling/secure-tunneling.d.ts +9 -9
- package/lib/secure-tunneling/secure-tunneling.d.ts.map +1 -1
- package/lib/secure-tunneling/secure-tunneling.js +21 -16
- package/lib/secure-tunneling/secure-tunneling.js.map +1 -1
- package/lib/secure-tunneling/secure-tunneling.test.js +11 -13
- package/lib/secure-tunneling/secure-tunneling.test.js.map +1 -1
- package/lib/subcommands/app/analytics.d.ts.map +1 -1
- package/lib/subcommands/app/analytics.js +1 -2
- package/lib/subcommands/app/analytics.js.map +1 -1
- package/lib/subcommands/app/env-vars.d.ts +4 -0
- package/lib/subcommands/app/env-vars.d.ts.map +1 -1
- package/lib/subcommands/app/env-vars.js +52 -6
- package/lib/subcommands/app/env-vars.js.map +1 -1
- package/lib/subcommands/app/index.d.ts.map +1 -1
- package/lib/subcommands/app/index.js +1 -3
- package/lib/subcommands/app/index.js.map +1 -1
- package/lib/subcommands/app/models.d.ts +0 -11
- package/lib/subcommands/app/models.d.ts.map +1 -1
- package/lib/subcommands/app/models.js +2 -58
- package/lib/subcommands/app/models.js.map +1 -1
- package/lib/subcommands/app/shadow.d.ts.map +1 -1
- package/lib/subcommands/app/shadow.js +6 -5
- package/lib/subcommands/app/shadow.js.map +1 -1
- package/lib/subcommands/app/version.d.ts +2 -0
- package/lib/subcommands/app/version.d.ts.map +1 -1
- package/lib/subcommands/app/version.js +16 -6
- package/lib/subcommands/app/version.js.map +1 -1
- package/lib/subcommands/config.d.ts +2 -0
- package/lib/subcommands/config.d.ts.map +1 -0
- package/lib/subcommands/config.js +39 -0
- package/lib/subcommands/config.js.map +1 -0
- package/lib/subcommands/device/clean.d.ts +1 -1
- package/lib/subcommands/device/clean.d.ts.map +1 -1
- package/lib/subcommands/device/clean.js +23 -13
- package/lib/subcommands/device/clean.js.map +1 -1
- package/lib/subcommands/device/index.d.ts.map +1 -1
- package/lib/subcommands/device/index.js +3 -1
- package/lib/subcommands/device/index.js.map +1 -1
- package/lib/subcommands/device/init.js +8 -8
- package/lib/subcommands/device/init.js.map +1 -1
- package/lib/subcommands/device/migrate.d.ts +2 -0
- package/lib/subcommands/device/migrate.d.ts.map +1 -0
- package/lib/subcommands/device/migrate.js +24 -0
- package/lib/subcommands/device/migrate.js.map +1 -0
- package/lib/subcommands/device/refresh.d.ts.map +1 -1
- package/lib/subcommands/device/refresh.js +1 -0
- package/lib/subcommands/device/refresh.js.map +1 -1
- package/lib/subcommands/index.d.ts +1 -1
- package/lib/subcommands/index.d.ts.map +1 -1
- package/lib/subcommands/index.js +3 -1
- package/lib/subcommands/index.js.map +1 -1
- package/lib/subcommands/rabbitmq-connection.d.ts +1 -1
- package/lib/subcommands/rabbitmq-connection.d.ts.map +1 -1
- package/lib/util/aai-error.d.ts +12 -0
- package/lib/util/aai-error.d.ts.map +1 -0
- package/lib/util/aai-error.js +11 -0
- package/lib/util/aai-error.js.map +1 -0
- package/lib/util/aws-regions.d.ts +2 -0
- package/lib/util/aws-regions.d.ts.map +1 -0
- package/lib/util/{cloud-mode-ready.js → aws-regions.js} +2 -20
- package/lib/util/aws-regions.js.map +1 -0
- package/lib/util/check-for-updates.d.ts.map +1 -1
- package/lib/util/check-for-updates.js +5 -28
- package/lib/util/check-for-updates.js.map +1 -1
- package/lib/util/clean-certs.d.ts.map +1 -1
- package/lib/util/clean-certs.js +5 -4
- package/lib/util/clean-certs.js.map +1 -1
- package/lib/util/directories.d.ts +4 -18
- package/lib/util/directories.d.ts.map +1 -1
- package/lib/util/directories.js +18 -32
- package/lib/util/directories.js.map +1 -1
- package/lib/util/file.d.ts +4 -0
- package/lib/util/file.d.ts.map +1 -1
- package/lib/util/file.js +65 -4
- package/lib/util/file.js.map +1 -1
- package/lib/util/get-device-id.d.ts.map +1 -1
- package/lib/util/get-device-id.js +7 -1
- package/lib/util/get-device-id.js.map +1 -1
- package/lib/util/http-client.js +3 -3
- package/lib/util/http-client.js.map +1 -1
- package/package.json +19 -17
- package/readme.md +12 -32
- package/src/application-control/config.ts +9 -12
- package/src/application-control/environment-variables.test.ts +28 -7
- package/src/application-control/environment-variables.ts +42 -59
- package/src/application-control/index.ts +3 -16
- package/src/application-control/install.ts +39 -13
- package/src/application-control/models.ts +6 -87
- package/src/application-control/utils.ts +10 -25
- package/src/cloud-connection/base-message-handler.ts +118 -0
- package/src/cloud-connection/bootstrap-provision.ts +7 -7
- package/src/cloud-connection/connection-manager.ts +187 -0
- package/src/cloud-connection/device-agent-cloud-connection.ts +130 -723
- package/src/cloud-connection/device-agent-message-handler.ts +642 -0
- package/src/cloud-connection/device-agent.ts +16 -7
- package/src/cloud-connection/live-updates-handler.test.ts +121 -189
- package/src/cloud-connection/live-updates-handler.ts +105 -232
- package/src/cloud-connection/message-dispatcher.ts +33 -0
- package/src/cloud-connection/passthrough-handler.ts +55 -18
- package/src/cloud-connection/shadow-handler.test.ts +45 -57
- package/src/cloud-connection/shadow-handler.ts +224 -54
- package/src/cloud-connection/shadow.ts +4 -1
- package/src/cloud-connection/transaction-manager.test.ts +68 -6
- package/src/cloud-connection/transaction-manager.ts +69 -41
- package/src/device-control/device-control.ts +102 -70
- package/src/docker/docker-compose.ts +3 -2
- package/src/infrastructure/agent-config.test.ts +6 -2
- package/src/infrastructure/agent-config.ts +8 -7
- package/src/infrastructure/config-check-utility.test.ts +154 -0
- package/src/infrastructure/config-check-utility.ts +77 -0
- package/src/infrastructure/device-certificate.test.ts +40 -0
- package/src/infrastructure/device-certificate.ts +58 -0
- package/src/infrastructure/legacy-migration/legacy-file.test.ts +88 -0
- package/src/infrastructure/legacy-migration/legacy-files.ts +101 -0
- package/src/infrastructure/legacy-migration/legacy-migration.test.ts +396 -0
- package/src/infrastructure/legacy-migration/legacy-migration.ts +229 -0
- package/src/infrastructure/require-files-present-ready.test.ts +53 -0
- package/src/infrastructure/required-config-checks.ts +33 -0
- package/src/infrastructure/tokens-and-device-cfg.ts +12 -10
- package/src/jobs/job-handler.ts +146 -0
- package/src/local-connection/rabbitmq-connection.ts +22 -17
- package/src/secure-tunneling/secure-tunnel-message-handler.ts +56 -0
- package/src/secure-tunneling/secure-tunneling.test.ts +20 -22
- package/src/secure-tunneling/secure-tunneling.ts +41 -29
- package/src/subcommands/app/analytics.ts +2 -4
- package/src/subcommands/app/env-vars.ts +72 -9
- package/src/subcommands/app/index.ts +3 -11
- package/src/subcommands/app/models.ts +5 -81
- package/src/subcommands/app/shadow.ts +6 -5
- package/src/subcommands/app/version.ts +23 -6
- package/src/subcommands/config.ts +42 -0
- package/src/subcommands/device/clean.ts +31 -17
- package/src/subcommands/device/index.ts +3 -1
- package/src/subcommands/device/init.ts +11 -11
- package/src/subcommands/device/migrate.ts +20 -0
- package/src/subcommands/device/refresh.ts +1 -0
- package/src/subcommands/index.ts +3 -1
- package/src/util/aai-error.ts +20 -0
- package/src/util/{cloud-mode-ready.ts → aws-regions.ts} +0 -24
- package/src/util/check-for-updates.ts +14 -30
- package/src/util/clean-certs.ts +8 -4
- package/src/util/directories.ts +23 -67
- package/src/util/file.ts +83 -3
- package/src/util/get-device-id.ts +7 -7
- package/src/util/http-client.ts +2 -2
- package/lib/util/cloud-mode-ready.d.ts +0 -3
- package/lib/util/cloud-mode-ready.d.ts.map +0 -1
- package/lib/util/cloud-mode-ready.js.map +0 -1
- package/lib/util/download-file.d.ts +0 -6
- package/lib/util/download-file.d.ts.map +0 -1
- package/lib/util/download-file.js +0 -25
- package/lib/util/download-file.js.map +0 -1
- package/lib/util/fetch-with-timeout.d.ts +0 -4
- package/lib/util/fetch-with-timeout.d.ts.map +0 -1
- package/lib/util/fetch-with-timeout.js +0 -30
- package/lib/util/fetch-with-timeout.js.map +0 -1
- package/lib/util/parsing.d.ts +0 -2
- package/lib/util/parsing.d.ts.map +0 -1
- package/lib/util/parsing.js +0 -17
- package/lib/util/parsing.js.map +0 -1
- package/src/util/download-file.ts +0 -25
- package/src/util/fetch-with-timeout.ts +0 -35
- package/src/util/parsing.ts +0 -11
|
@@ -1,35 +1,15 @@
|
|
|
1
1
|
import { logger } from '../util/logger';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
JsSpawner,
|
|
4
|
+
getLatestVersionFromNpm,
|
|
5
|
+
stringifyError
|
|
6
|
+
} from 'alwaysai/lib/util';
|
|
3
7
|
import * as path from 'path';
|
|
4
|
-
import { get } from 'https';
|
|
5
8
|
|
|
6
9
|
const appPrompt =
|
|
7
10
|
'Please restart the Device Agent or reboot the device to update. ';
|
|
8
11
|
const updatePrompt = `A new version of the Device Agent is available! \n\n`;
|
|
9
12
|
|
|
10
|
-
function getLatestVersion(packageName: string): Promise<string> {
|
|
11
|
-
return new Promise<string>((resolve, reject) => {
|
|
12
|
-
const url = `https://registry.npmjs.org/${packageName}/latest`;
|
|
13
|
-
|
|
14
|
-
get(url, (res) => {
|
|
15
|
-
let data = '';
|
|
16
|
-
res.on('data', (chunk) => {
|
|
17
|
-
data += chunk;
|
|
18
|
-
});
|
|
19
|
-
res.on('end', () => {
|
|
20
|
-
try {
|
|
21
|
-
const latestPackage = JSON.parse(data);
|
|
22
|
-
resolve(latestPackage.version);
|
|
23
|
-
} catch (error) {
|
|
24
|
-
reject(error);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}).on('error', (error) => {
|
|
28
|
-
reject(error);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
13
|
export async function getDeviceAgentVersion(): Promise<string> {
|
|
34
14
|
let daVersion = '';
|
|
35
15
|
try {
|
|
@@ -39,7 +19,9 @@ export async function getDeviceAgentVersion(): Promise<string> {
|
|
|
39
19
|
const parsed = JSON.parse(output);
|
|
40
20
|
daVersion = parsed.version;
|
|
41
21
|
} catch (e) {
|
|
42
|
-
logger.error(
|
|
22
|
+
logger.error(
|
|
23
|
+
`Could not retrieve the Device Agent version!\n${stringifyError(e)}`
|
|
24
|
+
);
|
|
43
25
|
}
|
|
44
26
|
return daVersion;
|
|
45
27
|
}
|
|
@@ -52,8 +34,10 @@ function constructPrompt(props: { currentVer: string; latestVer: string }) {
|
|
|
52
34
|
|
|
53
35
|
export async function checkForUpdatesAndPrompt() {
|
|
54
36
|
try {
|
|
55
|
-
logger.debug('Checking for updates...');
|
|
56
|
-
const latestVersion = await
|
|
37
|
+
logger.debug('Checking for available Device Agent updates...');
|
|
38
|
+
const latestVersion = await getLatestVersionFromNpm(
|
|
39
|
+
'@alwaysai/device-agent'
|
|
40
|
+
);
|
|
57
41
|
const version = await getDeviceAgentVersion();
|
|
58
42
|
if (version !== latestVersion) {
|
|
59
43
|
logger.warn(
|
|
@@ -63,7 +47,7 @@ export async function checkForUpdatesAndPrompt() {
|
|
|
63
47
|
})
|
|
64
48
|
);
|
|
65
49
|
}
|
|
66
|
-
} catch (
|
|
67
|
-
logger.error(`Could not check for updates
|
|
50
|
+
} catch (e) {
|
|
51
|
+
logger.error(`Could not check for updates!\n${stringifyError(e)}`);
|
|
68
52
|
}
|
|
69
53
|
}
|
package/src/util/clean-certs.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LOCAL_CERT_AND_KEY_DIR,
|
|
3
|
+
LocalDeviceCertificates
|
|
4
|
+
} from 'alwaysai/lib/infrastructure';
|
|
1
5
|
import { JsSpawner } from 'alwaysai/lib/util';
|
|
6
|
+
import { getBootstrapCertificateDirectoryPath } from '../infrastructure/device-certificate';
|
|
2
7
|
import { logger } from '../util/logger';
|
|
3
|
-
import { LOCAL_CERT_AND_KEY_DIR } from 'alwaysai/lib/paths';
|
|
4
|
-
import { BOOTSTRAP_CERTIFICATES_DIR_PATH } from '../util/directories';
|
|
5
8
|
|
|
6
9
|
export const rmBootstrapCertsAndClose = async () => {
|
|
10
|
+
const deviceCertificates = new LocalDeviceCertificates();
|
|
7
11
|
const spawner = JsSpawner();
|
|
8
|
-
await spawner.rimraf(
|
|
9
|
-
await spawner.rimraf(
|
|
12
|
+
await spawner.rimraf(getBootstrapCertificateDirectoryPath());
|
|
13
|
+
await spawner.rimraf(deviceCertificates.getCertificateDirectoryPath());
|
|
10
14
|
logger.error('Could not provision device. Try again.');
|
|
11
15
|
process.exit(1);
|
|
12
16
|
};
|
package/src/util/directories.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LocalDeviceCertificates,
|
|
3
|
+
getDeviceConfigPath
|
|
4
|
+
} from 'alwaysai/lib/infrastructure';
|
|
1
5
|
import {
|
|
2
6
|
AAI_DIR,
|
|
3
7
|
DEVICE_TOKEN_FILE_NAME,
|
|
4
8
|
DOCKER_COMPOSE_FILE,
|
|
5
|
-
LOCAL_AAI_CFG_DIR
|
|
6
|
-
LOCAL_CERT_AND_KEY_DIR
|
|
9
|
+
LOCAL_AAI_CFG_DIR
|
|
7
10
|
} from 'alwaysai/lib/paths';
|
|
8
11
|
import { join } from 'path';
|
|
9
12
|
import { getSystemId } from '../infrastructure/system-id';
|
|
@@ -11,25 +14,28 @@ import { getSystemId } from '../infrastructure/system-id';
|
|
|
11
14
|
export const APP_ROOT = join(AAI_DIR, 'applications');
|
|
12
15
|
|
|
13
16
|
export const DEVICE_AGENT_CFG_DIR = 'device-agent';
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
|
|
18
|
+
export function getDeviceAgentConfigPath(baseDir?) {
|
|
19
|
+
if (baseDir) {
|
|
20
|
+
return join(baseDir, getDeviceConfigPath(), DEVICE_AGENT_CFG_DIR);
|
|
21
|
+
}
|
|
22
|
+
return join(LOCAL_AAI_CFG_DIR, getDeviceConfigPath(), DEVICE_AGENT_CFG_DIR);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function getDeviceAgentDockerComposePath(baseDir?) {
|
|
26
|
+
return join(getDeviceAgentConfigPath(baseDir), DOCKER_COMPOSE_FILE);
|
|
27
|
+
}
|
|
22
28
|
|
|
23
29
|
export const CREDENTIALS_FILE_PATH = join(
|
|
24
30
|
LOCAL_AAI_CFG_DIR,
|
|
25
31
|
DEVICE_TOKEN_FILE_NAME
|
|
26
32
|
);
|
|
27
33
|
|
|
28
|
-
|
|
29
|
-
export const AWS_ROOT_CERTIFICATE_FILE_PATH =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
);
|
|
34
|
+
const localDeviceCertificates = new LocalDeviceCertificates();
|
|
35
|
+
export const AWS_ROOT_CERTIFICATE_FILE_PATH =
|
|
36
|
+
localDeviceCertificates.getRootCertificateFilePath();
|
|
37
|
+
export const AWS_ROOT_CERTIFICATE_FILE_NAME =
|
|
38
|
+
localDeviceCertificates.getRootCertificateFileName();
|
|
33
39
|
|
|
34
40
|
export const shortenSystemId = () => {
|
|
35
41
|
const id = getSystemId();
|
|
@@ -40,61 +46,11 @@ export const shortenSystemId = () => {
|
|
|
40
46
|
return 'qa';
|
|
41
47
|
case 'production':
|
|
42
48
|
return 'prod';
|
|
49
|
+
default:
|
|
50
|
+
return 'prod';
|
|
43
51
|
}
|
|
44
52
|
};
|
|
45
53
|
|
|
46
|
-
/*===================================================================
|
|
47
|
-
Bootstrap Certificates
|
|
48
|
-
===================================================================*/
|
|
49
|
-
|
|
50
|
-
export const BOOTSTRAP_DIR_NAME = 'bootstrap-certificates';
|
|
51
|
-
export const BOOTSTRAP_PRIVATE_KEY_FILE_NAME = () =>
|
|
52
|
-
`aai-claim-private-key_${shortenSystemId()}.pem.key`;
|
|
53
|
-
export const BOOTSTRAP_CERTIFICATE_FILE_NAME = () =>
|
|
54
|
-
`aai-claim-cert_${shortenSystemId()}.pem.crt`;
|
|
55
|
-
export const BOOTSTRAP_ID_FILE_NAME = () =>
|
|
56
|
-
`aai-claim-cert-id_${shortenSystemId()}.txt`;
|
|
57
|
-
export const CERTIFICATE_OWNERSHIP_TOKEN_FILE_NAME =
|
|
58
|
-
'certificate-ownership-token.txt';
|
|
59
|
-
|
|
60
|
-
export const BOOTSTRAP_CERTIFICATES_DIR_PATH = () =>
|
|
61
|
-
join(LOCAL_CERT_AND_KEY_DIR, BOOTSTRAP_DIR_NAME);
|
|
62
|
-
|
|
63
|
-
export const BOOTSTRAP_PRIVATE_KEY_FILE_PATH = () =>
|
|
64
|
-
join(
|
|
65
|
-
LOCAL_CERT_AND_KEY_DIR,
|
|
66
|
-
BOOTSTRAP_DIR_NAME,
|
|
67
|
-
BOOTSTRAP_PRIVATE_KEY_FILE_NAME()
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
export const BOOTSTRAP_CERTIFICATE_FILE_PATH = () =>
|
|
71
|
-
join(
|
|
72
|
-
LOCAL_CERT_AND_KEY_DIR,
|
|
73
|
-
BOOTSTRAP_DIR_NAME,
|
|
74
|
-
BOOTSTRAP_CERTIFICATE_FILE_NAME()
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
export const BOOTSTRAP_ID_FILE_PATH = () =>
|
|
78
|
-
join(LOCAL_CERT_AND_KEY_DIR, BOOTSTRAP_DIR_NAME, BOOTSTRAP_ID_FILE_NAME());
|
|
79
|
-
|
|
80
|
-
/*===================================================================
|
|
81
|
-
Device Certificates
|
|
82
|
-
===================================================================*/
|
|
83
|
-
|
|
84
|
-
export const DEVICE_PRIVATE_KEY_FILE_NAME = 'aai-device-private-key.pem.key';
|
|
85
|
-
export const DEVICE_CERTIFICATE_FILE_NAME = 'aai-device-cert.pem.crt';
|
|
86
|
-
export const DEVICE_ID_FILE_NAME = 'aai-device-cert-id.txt';
|
|
87
|
-
|
|
88
|
-
export const DEVICE_PRIVATE_KEY_FILE_PATH = join(
|
|
89
|
-
LOCAL_CERT_AND_KEY_DIR,
|
|
90
|
-
DEVICE_PRIVATE_KEY_FILE_NAME
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
export const DEVICE_CERTIFICATE_FILE_PATH = join(
|
|
94
|
-
LOCAL_CERT_AND_KEY_DIR,
|
|
95
|
-
DEVICE_CERTIFICATE_FILE_NAME
|
|
96
|
-
);
|
|
97
|
-
|
|
98
54
|
/*===================================================================
|
|
99
55
|
Secure Tunnel bin directory
|
|
100
56
|
===================================================================*/
|
package/src/util/file.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { rimraf } from 'rimraf';
|
|
|
2
2
|
import { logger } from '../util/logger';
|
|
3
3
|
import { readdir, stat, unlink, rmdir } from 'fs/promises';
|
|
4
4
|
import { join } from 'path';
|
|
5
|
+
import { stringifyError } from 'alwaysai/lib/util';
|
|
6
|
+
import { writeFileSync } from 'fs';
|
|
5
7
|
|
|
6
8
|
export async function safeRimraf(path: string) {
|
|
7
9
|
logger.debug(`Removing ${path}`);
|
|
@@ -11,7 +13,7 @@ export async function safeRimraf(path: string) {
|
|
|
11
13
|
logger.error(
|
|
12
14
|
`Failed to remove ${path}. Please manually delete the file or directory.`
|
|
13
15
|
);
|
|
14
|
-
logger.debug(`Error removing ${path}
|
|
16
|
+
logger.debug(`Error removing ${path}:\n${stringifyError(e)}`);
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
19
|
|
|
@@ -69,8 +71,86 @@ export async function pruneDir({
|
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
73
|
return canPruneParent;
|
|
72
|
-
} catch (
|
|
73
|
-
logger.error(`Error pruning directory ${path}
|
|
74
|
+
} catch (e) {
|
|
75
|
+
logger.error(`Error pruning directory ${path}!\n${stringifyError(e)}`);
|
|
74
76
|
return false;
|
|
75
77
|
}
|
|
76
78
|
}
|
|
79
|
+
|
|
80
|
+
export async function downloadToFile({
|
|
81
|
+
path,
|
|
82
|
+
url
|
|
83
|
+
}: {
|
|
84
|
+
path: string;
|
|
85
|
+
url: string;
|
|
86
|
+
}) {
|
|
87
|
+
const response = await fetch(url);
|
|
88
|
+
|
|
89
|
+
if (!response.ok) {
|
|
90
|
+
throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const contentLength = response.headers.get('content-length');
|
|
94
|
+
const reader = response.body?.getReader();
|
|
95
|
+
|
|
96
|
+
if (reader) {
|
|
97
|
+
const chunks: Uint8Array[] = [];
|
|
98
|
+
const totalSize = contentLength ? parseInt(contentLength) : undefined;
|
|
99
|
+
|
|
100
|
+
const PROGRESS_PERC_LOG_INCREMENT = 5;
|
|
101
|
+
const BYTE_DOWNLOAD_LOG_INCREMENT = 5_000_000;
|
|
102
|
+
const [baseUrl, urlParams] = url.split('?');
|
|
103
|
+
const urlForLog = `${baseUrl}${
|
|
104
|
+
urlParams?.length ? `...(${urlParams.length} more characters)` : ''
|
|
105
|
+
}`;
|
|
106
|
+
let totalDownloadedBytes = 0;
|
|
107
|
+
let downloadedSize = 0;
|
|
108
|
+
let totalProgressPerc = 0;
|
|
109
|
+
|
|
110
|
+
// eslint-disable-next-line
|
|
111
|
+
while (true) {
|
|
112
|
+
const { done, value } = await reader.read();
|
|
113
|
+
if (done) {
|
|
114
|
+
logger.info(`Download complete - ${urlForLog}`);
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
if (value) {
|
|
118
|
+
chunks.push(value);
|
|
119
|
+
downloadedSize += value.length;
|
|
120
|
+
if (totalSize) {
|
|
121
|
+
const progress = (downloadedSize / totalSize) * 100;
|
|
122
|
+
if (progress > totalProgressPerc + PROGRESS_PERC_LOG_INCREMENT) {
|
|
123
|
+
totalProgressPerc += PROGRESS_PERC_LOG_INCREMENT;
|
|
124
|
+
logger.debug(
|
|
125
|
+
`Download progress: ${progress.toFixed(2)}% - ${urlForLog}`
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
if (
|
|
130
|
+
downloadedSize >
|
|
131
|
+
totalDownloadedBytes + BYTE_DOWNLOAD_LOG_INCREMENT
|
|
132
|
+
) {
|
|
133
|
+
totalDownloadedBytes += BYTE_DOWNLOAD_LOG_INCREMENT;
|
|
134
|
+
logger.debug(
|
|
135
|
+
`Download progress: ${downloadedSize} total bytes - ${urlForLog}`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
logger.debug(`Writing downloaded chunks to file ${path}`);
|
|
143
|
+
const combinedSize = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
|
|
144
|
+
const combinedChunks = new Uint8Array(combinedSize);
|
|
145
|
+
|
|
146
|
+
let offset = 0;
|
|
147
|
+
for (const chunk of chunks) {
|
|
148
|
+
combinedChunks.set(chunk, offset);
|
|
149
|
+
offset += chunk.length;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
writeFileSync(path, combinedChunks);
|
|
153
|
+
} else {
|
|
154
|
+
throw new Error('Unable to access response body when downloading file.');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { DeviceConfigFile } from 'alwaysai/lib/core/device';
|
|
2
|
+
import { logger } from './logger';
|
|
3
|
+
import { stringifyError } from 'alwaysai/lib/util';
|
|
4
|
+
import AaiError from './aai-error';
|
|
2
5
|
|
|
3
6
|
export function getDeviceUuid() {
|
|
4
7
|
const deviceCfgFile = DeviceConfigFile();
|
|
@@ -9,12 +12,9 @@ export function getDeviceUuid() {
|
|
|
9
12
|
const cfg = deviceCfgFile.read();
|
|
10
13
|
return cfg.deviceUuid;
|
|
11
14
|
} catch (e) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
2
|
|
17
|
-
)}`
|
|
18
|
-
);
|
|
15
|
+
logger.error(`Failed to read device configuration!\n${stringifyError(e)}`);
|
|
16
|
+
throw new AaiError('Failed to read device configuration', {
|
|
17
|
+
cause: deviceCfgFile.getErrors()
|
|
18
|
+
});
|
|
19
19
|
}
|
|
20
20
|
}
|
package/src/util/http-client.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import fetch from 'node-fetch';
|
|
2
1
|
import { serviceEndpointBuilder } from '../endpoints';
|
|
3
2
|
import { CliAuthenticationClient } from 'alwaysai/lib/infrastructure';
|
|
4
3
|
import { logger } from '../util/logger';
|
|
4
|
+
import { stringifyError } from 'alwaysai/lib/util';
|
|
5
5
|
|
|
6
6
|
export async function httpClient(
|
|
7
7
|
url: string,
|
|
@@ -23,7 +23,7 @@ export async function httpClient(
|
|
|
23
23
|
return await response.text();
|
|
24
24
|
}
|
|
25
25
|
} catch (e) {
|
|
26
|
-
logger.error(`HTTP Client error for ${url}
|
|
26
|
+
logger.error(`HTTP Client error for ${url}:\n${stringifyError(e)}`);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cloud-mode-ready.d.ts","sourceRoot":"","sources":["../../src/util/cloud-mode-ready.ts"],"names":[],"mappings":"AAuCA,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAExD;AAED,wBAAgB,cAAc,YAe7B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cloud-mode-ready.js","sourceRoot":"","sources":["../../src/util/cloud-mode-ready.ts"],"names":[],"mappings":";;;AAAA,2BAAgC;AAChC,qDAI6B;AAE7B,MAAM,iBAAiB,GAAG;IACxB,sCAAsC;IACtC,2CAA2C;IAC3C,4CAA4C;IAC5C,4CAA4C;IAC5C,4CAA4C;IAC5C,4CAA4C;IAC5C,yCAAyC;IACzC,gDAAgD;IAChD,6CAA6C;IAC7C,8CAA8C;IAC9C,gDAAgD;IAChD,sCAAsC;IACtC,wCAAwC;IACxC,kCAAkC;IAClC,iCAAiC;IACjC,wCAAwC;IACxC,qCAAqC;IACrC,sCAAsC;IACtC,kCAAkC;IAClC,kCAAkC;IAClC,mCAAmC;IACnC,uCAAuC;IACvC,yCAAyC;IACzC,uCAAuC;IACvC,2CAA2C;IAC3C,iCAAiC;IACjC,qCAAqC;IACrC,0CAA0C;IAC1C,WAAW,CAAC,mBAAmB;CAChC,CAAC;AAEF,SAAgB,gBAAgB,CAAC,MAAc;IAC7C,OAAO,iBAAiB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC5C,CAAC;AAFD,4CAEC;AAED,SAAgB,cAAc;IAC5B,IAAI,KAAK,GAAG,IAAI,CAAC;IACjB,MAAM,aAAa,GAAG;QACpB,0CAA4B;QAC5B,0CAA4B;QAC5B,4CAA8B;KAC/B,CAAC;IAEF,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE;QAChC,IAAI,CAAC,IAAA,eAAU,EAAC,IAAI,CAAC,EAAE;YACrB,KAAK,GAAG,KAAK,CAAC;YACd,MAAM;SACP;KACF;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAfD,wCAeC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"download-file.d.ts","sourceRoot":"","sources":["../../src/util/download-file.ts"],"names":[],"mappings":"AAIA,wBAAsB,YAAY,CAAC,KAAK,EAAE;IACxC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBhB"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.downloadFile = void 0;
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const fetch_with_timeout_1 = require("./fetch-with-timeout");
|
|
6
|
-
const logger_1 = require("./logger");
|
|
7
|
-
async function downloadFile(props) {
|
|
8
|
-
const { url, path, errorMessage } = props;
|
|
9
|
-
logger_1.logger.debug(`Downloading package from ${url}`);
|
|
10
|
-
let response;
|
|
11
|
-
try {
|
|
12
|
-
response = await (0, fetch_with_timeout_1.fetchWithTimeout)(url);
|
|
13
|
-
}
|
|
14
|
-
catch (e) {
|
|
15
|
-
const errorBody = e.type === 'aborted' ? e : await e.response.text();
|
|
16
|
-
throw new Error(`${errorMessage}: Error=${e}\n${errorBody}`);
|
|
17
|
-
}
|
|
18
|
-
const stream = response.body.pipe(fs.createWriteStream(path));
|
|
19
|
-
await new Promise((resolve, reject) => {
|
|
20
|
-
stream.on('finish', resolve);
|
|
21
|
-
stream.on('error', reject);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
exports.downloadFile = downloadFile;
|
|
25
|
-
//# sourceMappingURL=download-file.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"download-file.js","sourceRoot":"","sources":["../../src/util/download-file.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACzB,6DAAwD;AACxD,qCAAkC;AAE3B,KAAK,UAAU,YAAY,CAAC,KAIlC;IACC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;IAC1C,eAAM,CAAC,KAAK,CAAC,4BAA4B,GAAG,EAAE,CAAC,CAAC;IAChD,IAAI,QAAa,CAAC;IAClB,IAAI;QACF,QAAQ,GAAG,MAAM,IAAA,qCAAgB,EAAC,GAAG,CAAC,CAAC;KACxC;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,SAAS,GAAG,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QACrE,MAAM,IAAI,KAAK,CAAC,GAAG,YAAY,WAAW,CAAC,KAAK,SAAS,EAAE,CAAC,CAAC;KAC9D;IAED,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9D,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACpC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC7B,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;AACL,CAAC;AApBD,oCAoBC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-with-timeout.d.ts","sourceRoot":"","sources":["../../src/util/fetch-with-timeout.ts"],"names":[],"mappings":"AAmBA,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAO,gBAanC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchWithTimeout = void 0;
|
|
4
|
-
const node_fetch_1 = require("node-fetch");
|
|
5
|
-
class HTTPResponseError extends Error {
|
|
6
|
-
constructor(response) {
|
|
7
|
-
super(`HTTP Error Response: ${response.status} ${response.statusText}`);
|
|
8
|
-
this.response = response;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
const checkStatus = (response) => {
|
|
12
|
-
if (response.ok) {
|
|
13
|
-
// response.status >= 200 && response.status < 300
|
|
14
|
-
return response;
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
throw new HTTPResponseError(response);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
async function fetchWithTimeout(url, options = {}) {
|
|
21
|
-
//time (ms)
|
|
22
|
-
const { timeout = 60000 } = options;
|
|
23
|
-
const controller = new AbortController();
|
|
24
|
-
const id = setTimeout(() => controller.abort(), timeout);
|
|
25
|
-
const response = await (0, node_fetch_1.default)(url, Object.assign(Object.assign({}, options), { signal: controller.signal }));
|
|
26
|
-
clearTimeout(id);
|
|
27
|
-
return checkStatus(response);
|
|
28
|
-
}
|
|
29
|
-
exports.fetchWithTimeout = fetchWithTimeout;
|
|
30
|
-
//# sourceMappingURL=fetch-with-timeout.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-with-timeout.js","sourceRoot":"","sources":["../../src/util/fetch-with-timeout.ts"],"names":[],"mappings":";;;AAAA,2CAAmC;AAEnC,MAAM,iBAAkB,SAAQ,KAAK;IAEnC,YAAY,QAAQ;QAClB,KAAK,CAAC,wBAAwB,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;QACxE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAED,MAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,EAAE;IAC/B,IAAI,QAAQ,CAAC,EAAE,EAAE;QACf,kDAAkD;QAClD,OAAO,QAAQ,CAAC;KACjB;SAAM;QACL,MAAM,IAAI,iBAAiB,CAAC,QAAQ,CAAC,CAAC;KACvC;AACH,CAAC,CAAC;AAEK,KAAK,UAAU,gBAAgB,CACpC,GAAW,EACX,UAAgC,EAAE;IAElC,WAAW;IACX,MAAM,EAAE,OAAO,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAEpC,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;IACzD,MAAM,QAAQ,GAAG,MAAM,IAAA,oBAAS,EAAC,GAAG,kCAC/B,OAAO,KACV,MAAM,EAAE,UAAU,CAAC,MAAM,IACzB,CAAC;IACH,YAAY,CAAC,EAAE,CAAC,CAAC;IACjB,OAAO,WAAW,CAAC,QAAQ,CAAC,CAAC;AAC/B,CAAC;AAfD,4CAeC"}
|
package/lib/util/parsing.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parsing.d.ts","sourceRoot":"","sources":["../../src/util/parsing.ts"],"names":[],"mappings":"AAAA,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,QAUtE"}
|
package/lib/util/parsing.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.replaceFalseyWithNull = void 0;
|
|
4
|
-
function replaceFalseyWithNull(object, recurse) {
|
|
5
|
-
if (typeof object === 'string' || object instanceof String)
|
|
6
|
-
return;
|
|
7
|
-
object &&
|
|
8
|
-
Object.keys(object).forEach((key) => {
|
|
9
|
-
if (recurse) {
|
|
10
|
-
replaceFalseyWithNull(object[key], recurse);
|
|
11
|
-
}
|
|
12
|
-
if (!object[key])
|
|
13
|
-
object[key] = null;
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
exports.replaceFalseyWithNull = replaceFalseyWithNull;
|
|
17
|
-
//# sourceMappingURL=parsing.js.map
|
package/lib/util/parsing.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parsing.js","sourceRoot":"","sources":["../../src/util/parsing.ts"],"names":[],"mappings":";;;AAAA,SAAgB,qBAAqB,CAAC,MAAc,EAAE,OAAiB;IACrE,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,YAAY,MAAM;QAAE,OAAO;IAEnE,MAAM;QACJ,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,GAAW,EAAE,EAAE;YAC1C,IAAI,OAAO,EAAE;gBACX,qBAAqB,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;aAC7C;YACD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;gBAAE,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;QACvC,CAAC,CAAC,CAAC;AACP,CAAC;AAVD,sDAUC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import { fetchWithTimeout } from './fetch-with-timeout';
|
|
3
|
-
import { logger } from './logger';
|
|
4
|
-
|
|
5
|
-
export async function downloadFile(props: {
|
|
6
|
-
url: string;
|
|
7
|
-
path: string;
|
|
8
|
-
errorMessage: string;
|
|
9
|
-
}): Promise<void> {
|
|
10
|
-
const { url, path, errorMessage } = props;
|
|
11
|
-
logger.debug(`Downloading package from ${url}`);
|
|
12
|
-
let response: any;
|
|
13
|
-
try {
|
|
14
|
-
response = await fetchWithTimeout(url);
|
|
15
|
-
} catch (e) {
|
|
16
|
-
const errorBody = e.type === 'aborted' ? e : await e.response.text();
|
|
17
|
-
throw new Error(`${errorMessage}: Error=${e}\n${errorBody}`);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const stream = response.body.pipe(fs.createWriteStream(path));
|
|
21
|
-
await new Promise((resolve, reject) => {
|
|
22
|
-
stream.on('finish', resolve);
|
|
23
|
-
stream.on('error', reject);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import nodeFetch from 'node-fetch';
|
|
2
|
-
|
|
3
|
-
class HTTPResponseError extends Error {
|
|
4
|
-
public response;
|
|
5
|
-
constructor(response) {
|
|
6
|
-
super(`HTTP Error Response: ${response.status} ${response.statusText}`);
|
|
7
|
-
this.response = response;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const checkStatus = (response) => {
|
|
12
|
-
if (response.ok) {
|
|
13
|
-
// response.status >= 200 && response.status < 300
|
|
14
|
-
return response;
|
|
15
|
-
} else {
|
|
16
|
-
throw new HTTPResponseError(response);
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export async function fetchWithTimeout(
|
|
21
|
-
url: string,
|
|
22
|
-
options: { timeout?: number } = {}
|
|
23
|
-
) {
|
|
24
|
-
//time (ms)
|
|
25
|
-
const { timeout = 60000 } = options;
|
|
26
|
-
|
|
27
|
-
const controller = new AbortController();
|
|
28
|
-
const id = setTimeout(() => controller.abort(), timeout);
|
|
29
|
-
const response = await nodeFetch(url, {
|
|
30
|
-
...options,
|
|
31
|
-
signal: controller.signal
|
|
32
|
-
});
|
|
33
|
-
clearTimeout(id);
|
|
34
|
-
return checkStatus(response);
|
|
35
|
-
}
|
package/src/util/parsing.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export function replaceFalseyWithNull(object: object, recurse?: boolean) {
|
|
2
|
-
if (typeof object === 'string' || object instanceof String) return;
|
|
3
|
-
|
|
4
|
-
object &&
|
|
5
|
-
Object.keys(object).forEach((key: string) => {
|
|
6
|
-
if (recurse) {
|
|
7
|
-
replaceFalseyWithNull(object[key], recurse);
|
|
8
|
-
}
|
|
9
|
-
if (!object[key]) object[key] = null;
|
|
10
|
-
});
|
|
11
|
-
}
|