@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
package/lib/util/directories.js
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SECURE_TUNNEL_BIN_PATH = exports.SECURE_TUNNEL_BIN_DIR = exports.SECURE_TUNNEL_BIN_NAME = exports.
|
|
3
|
+
exports.SECURE_TUNNEL_BIN_PATH = exports.SECURE_TUNNEL_BIN_DIR = exports.SECURE_TUNNEL_BIN_NAME = exports.shortenSystemId = exports.AWS_ROOT_CERTIFICATE_FILE_NAME = exports.AWS_ROOT_CERTIFICATE_FILE_PATH = exports.CREDENTIALS_FILE_PATH = exports.getDeviceAgentDockerComposePath = exports.getDeviceAgentConfigPath = exports.DEVICE_AGENT_CFG_DIR = exports.APP_ROOT = void 0;
|
|
4
|
+
const infrastructure_1 = require("alwaysai/lib/infrastructure");
|
|
4
5
|
const paths_1 = require("alwaysai/lib/paths");
|
|
5
6
|
const path_1 = require("path");
|
|
6
7
|
const system_id_1 = require("../infrastructure/system-id");
|
|
7
8
|
exports.APP_ROOT = (0, path_1.join)(paths_1.AAI_DIR, 'applications');
|
|
8
9
|
exports.DEVICE_AGENT_CFG_DIR = 'device-agent';
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
function getDeviceAgentConfigPath(baseDir) {
|
|
11
|
+
if (baseDir) {
|
|
12
|
+
return (0, path_1.join)(baseDir, (0, infrastructure_1.getDeviceConfigPath)(), exports.DEVICE_AGENT_CFG_DIR);
|
|
13
|
+
}
|
|
14
|
+
return (0, path_1.join)(paths_1.LOCAL_AAI_CFG_DIR, (0, infrastructure_1.getDeviceConfigPath)(), exports.DEVICE_AGENT_CFG_DIR);
|
|
15
|
+
}
|
|
16
|
+
exports.getDeviceAgentConfigPath = getDeviceAgentConfigPath;
|
|
17
|
+
function getDeviceAgentDockerComposePath(baseDir) {
|
|
18
|
+
return (0, path_1.join)(getDeviceAgentConfigPath(baseDir), paths_1.DOCKER_COMPOSE_FILE);
|
|
19
|
+
}
|
|
20
|
+
exports.getDeviceAgentDockerComposePath = getDeviceAgentDockerComposePath;
|
|
11
21
|
exports.CREDENTIALS_FILE_PATH = (0, path_1.join)(paths_1.LOCAL_AAI_CFG_DIR, paths_1.DEVICE_TOKEN_FILE_NAME);
|
|
12
|
-
|
|
13
|
-
exports.AWS_ROOT_CERTIFICATE_FILE_PATH =
|
|
22
|
+
const localDeviceCertificates = new infrastructure_1.LocalDeviceCertificates();
|
|
23
|
+
exports.AWS_ROOT_CERTIFICATE_FILE_PATH = localDeviceCertificates.getRootCertificateFilePath();
|
|
24
|
+
exports.AWS_ROOT_CERTIFICATE_FILE_NAME = localDeviceCertificates.getRootCertificateFileName();
|
|
14
25
|
const shortenSystemId = () => {
|
|
15
26
|
const id = (0, system_id_1.getSystemId)();
|
|
16
27
|
switch (id) {
|
|
@@ -20,36 +31,11 @@ const shortenSystemId = () => {
|
|
|
20
31
|
return 'qa';
|
|
21
32
|
case 'production':
|
|
22
33
|
return 'prod';
|
|
34
|
+
default:
|
|
35
|
+
return 'prod';
|
|
23
36
|
}
|
|
24
37
|
};
|
|
25
38
|
exports.shortenSystemId = shortenSystemId;
|
|
26
|
-
/*===================================================================
|
|
27
|
-
Bootstrap Certificates
|
|
28
|
-
===================================================================*/
|
|
29
|
-
exports.BOOTSTRAP_DIR_NAME = 'bootstrap-certificates';
|
|
30
|
-
const BOOTSTRAP_PRIVATE_KEY_FILE_NAME = () => `aai-claim-private-key_${(0, exports.shortenSystemId)()}.pem.key`;
|
|
31
|
-
exports.BOOTSTRAP_PRIVATE_KEY_FILE_NAME = BOOTSTRAP_PRIVATE_KEY_FILE_NAME;
|
|
32
|
-
const BOOTSTRAP_CERTIFICATE_FILE_NAME = () => `aai-claim-cert_${(0, exports.shortenSystemId)()}.pem.crt`;
|
|
33
|
-
exports.BOOTSTRAP_CERTIFICATE_FILE_NAME = BOOTSTRAP_CERTIFICATE_FILE_NAME;
|
|
34
|
-
const BOOTSTRAP_ID_FILE_NAME = () => `aai-claim-cert-id_${(0, exports.shortenSystemId)()}.txt`;
|
|
35
|
-
exports.BOOTSTRAP_ID_FILE_NAME = BOOTSTRAP_ID_FILE_NAME;
|
|
36
|
-
exports.CERTIFICATE_OWNERSHIP_TOKEN_FILE_NAME = 'certificate-ownership-token.txt';
|
|
37
|
-
const BOOTSTRAP_CERTIFICATES_DIR_PATH = () => (0, path_1.join)(paths_1.LOCAL_CERT_AND_KEY_DIR, exports.BOOTSTRAP_DIR_NAME);
|
|
38
|
-
exports.BOOTSTRAP_CERTIFICATES_DIR_PATH = BOOTSTRAP_CERTIFICATES_DIR_PATH;
|
|
39
|
-
const BOOTSTRAP_PRIVATE_KEY_FILE_PATH = () => (0, path_1.join)(paths_1.LOCAL_CERT_AND_KEY_DIR, exports.BOOTSTRAP_DIR_NAME, (0, exports.BOOTSTRAP_PRIVATE_KEY_FILE_NAME)());
|
|
40
|
-
exports.BOOTSTRAP_PRIVATE_KEY_FILE_PATH = BOOTSTRAP_PRIVATE_KEY_FILE_PATH;
|
|
41
|
-
const BOOTSTRAP_CERTIFICATE_FILE_PATH = () => (0, path_1.join)(paths_1.LOCAL_CERT_AND_KEY_DIR, exports.BOOTSTRAP_DIR_NAME, (0, exports.BOOTSTRAP_CERTIFICATE_FILE_NAME)());
|
|
42
|
-
exports.BOOTSTRAP_CERTIFICATE_FILE_PATH = BOOTSTRAP_CERTIFICATE_FILE_PATH;
|
|
43
|
-
const BOOTSTRAP_ID_FILE_PATH = () => (0, path_1.join)(paths_1.LOCAL_CERT_AND_KEY_DIR, exports.BOOTSTRAP_DIR_NAME, (0, exports.BOOTSTRAP_ID_FILE_NAME)());
|
|
44
|
-
exports.BOOTSTRAP_ID_FILE_PATH = BOOTSTRAP_ID_FILE_PATH;
|
|
45
|
-
/*===================================================================
|
|
46
|
-
Device Certificates
|
|
47
|
-
===================================================================*/
|
|
48
|
-
exports.DEVICE_PRIVATE_KEY_FILE_NAME = 'aai-device-private-key.pem.key';
|
|
49
|
-
exports.DEVICE_CERTIFICATE_FILE_NAME = 'aai-device-cert.pem.crt';
|
|
50
|
-
exports.DEVICE_ID_FILE_NAME = 'aai-device-cert-id.txt';
|
|
51
|
-
exports.DEVICE_PRIVATE_KEY_FILE_PATH = (0, path_1.join)(paths_1.LOCAL_CERT_AND_KEY_DIR, exports.DEVICE_PRIVATE_KEY_FILE_NAME);
|
|
52
|
-
exports.DEVICE_CERTIFICATE_FILE_PATH = (0, path_1.join)(paths_1.LOCAL_CERT_AND_KEY_DIR, exports.DEVICE_CERTIFICATE_FILE_NAME);
|
|
53
39
|
/*===================================================================
|
|
54
40
|
Secure Tunnel bin directory
|
|
55
41
|
===================================================================*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"directories.js","sourceRoot":"","sources":["../../src/util/directories.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"directories.js","sourceRoot":"","sources":["../../src/util/directories.ts"],"names":[],"mappings":";;;AAAA,gEAGqC;AACrC,8CAK4B;AAC5B,+BAA4B;AAC5B,2DAA0D;AAE7C,QAAA,QAAQ,GAAG,IAAA,WAAI,EAAC,eAAO,EAAE,cAAc,CAAC,CAAC;AAEzC,QAAA,oBAAoB,GAAG,cAAc,CAAC;AAEnD,SAAgB,wBAAwB,CAAC,OAAQ;IAC/C,IAAI,OAAO,EAAE;QACX,OAAO,IAAA,WAAI,EAAC,OAAO,EAAE,IAAA,oCAAmB,GAAE,EAAE,4BAAoB,CAAC,CAAC;KACnE;IACD,OAAO,IAAA,WAAI,EAAC,yBAAiB,EAAE,IAAA,oCAAmB,GAAE,EAAE,4BAAoB,CAAC,CAAC;AAC9E,CAAC;AALD,4DAKC;AAED,SAAgB,+BAA+B,CAAC,OAAQ;IACtD,OAAO,IAAA,WAAI,EAAC,wBAAwB,CAAC,OAAO,CAAC,EAAE,2BAAmB,CAAC,CAAC;AACtE,CAAC;AAFD,0EAEC;AAEY,QAAA,qBAAqB,GAAG,IAAA,WAAI,EACvC,yBAAiB,EACjB,8BAAsB,CACvB,CAAC;AAEF,MAAM,uBAAuB,GAAG,IAAI,wCAAuB,EAAE,CAAC;AACjD,QAAA,8BAA8B,GACzC,uBAAuB,CAAC,0BAA0B,EAAE,CAAC;AAC1C,QAAA,8BAA8B,GACzC,uBAAuB,CAAC,0BAA0B,EAAE,CAAC;AAEhD,MAAM,eAAe,GAAG,GAAG,EAAE;IAClC,MAAM,EAAE,GAAG,IAAA,uBAAW,GAAE,CAAC;IACzB,QAAQ,EAAE,EAAE;QACV,KAAK,aAAa;YAChB,OAAO,KAAK,CAAC;QACf,KAAK,IAAI;YACP,OAAO,IAAI,CAAC;QACd,KAAK,YAAY;YACf,OAAO,MAAM,CAAC;QAChB;YACE,OAAO,MAAM,CAAC;KACjB;AACH,CAAC,CAAC;AAZW,QAAA,eAAe,mBAY1B;AAEF;;qEAEqE;AACxD,QAAA,sBAAsB,GAAG,YAAY,CAAC;AACtC,QAAA,qBAAqB,GAAG,eAAe,CAAC;AACxC,QAAA,sBAAsB,GAAG,IAAA,WAAI,EACxC,eAAO,EACP,6BAAqB,EACrB,8BAAsB,CACvB,CAAC"}
|
package/lib/util/file.d.ts
CHANGED
|
@@ -4,4 +4,8 @@ export declare function pruneDir({ path, exclude, recurse }: {
|
|
|
4
4
|
exclude?: string[];
|
|
5
5
|
recurse?: boolean;
|
|
6
6
|
}): Promise<boolean>;
|
|
7
|
+
export declare function downloadToFile({ path, url }: {
|
|
8
|
+
path: string;
|
|
9
|
+
url: string;
|
|
10
|
+
}): Promise<void>;
|
|
7
11
|
//# sourceMappingURL=file.d.ts.map
|
package/lib/util/file.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/util/file.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/util/file.ts"],"names":[],"mappings":"AAOA,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,iBAU5C;AAED,wBAAsB,QAAQ,CAAC,EAC7B,IAAI,EACJ,OAAO,EACP,OAAO,EACR,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,oBAkDA;AAED,wBAAsB,cAAc,CAAC,EACnC,IAAI,EACJ,GAAG,EACJ,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb,iBAsEA"}
|
package/lib/util/file.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pruneDir = exports.safeRimraf = void 0;
|
|
3
|
+
exports.downloadToFile = exports.pruneDir = exports.safeRimraf = void 0;
|
|
4
4
|
const rimraf_1 = require("rimraf");
|
|
5
5
|
const logger_1 = require("../util/logger");
|
|
6
6
|
const promises_1 = require("fs/promises");
|
|
7
7
|
const path_1 = require("path");
|
|
8
|
+
const util_1 = require("alwaysai/lib/util");
|
|
9
|
+
const fs_1 = require("fs");
|
|
8
10
|
async function safeRimraf(path) {
|
|
9
11
|
logger_1.logger.debug(`Removing ${path}`);
|
|
10
12
|
try {
|
|
@@ -12,7 +14,7 @@ async function safeRimraf(path) {
|
|
|
12
14
|
}
|
|
13
15
|
catch (e) {
|
|
14
16
|
logger_1.logger.error(`Failed to remove ${path}. Please manually delete the file or directory.`);
|
|
15
|
-
logger_1.logger.debug(`Error removing ${path}
|
|
17
|
+
logger_1.logger.debug(`Error removing ${path}:\n${(0, util_1.stringifyError)(e)}`);
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
20
|
exports.safeRimraf = safeRimraf;
|
|
@@ -57,10 +59,69 @@ async function pruneDir({ path, exclude, recurse }) {
|
|
|
57
59
|
}
|
|
58
60
|
return canPruneParent;
|
|
59
61
|
}
|
|
60
|
-
catch (
|
|
61
|
-
logger_1.logger.error(`Error pruning directory ${path}
|
|
62
|
+
catch (e) {
|
|
63
|
+
logger_1.logger.error(`Error pruning directory ${path}!\n${(0, util_1.stringifyError)(e)}`);
|
|
62
64
|
return false;
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
exports.pruneDir = pruneDir;
|
|
68
|
+
async function downloadToFile({ path, url }) {
|
|
69
|
+
var _a;
|
|
70
|
+
const response = await fetch(url);
|
|
71
|
+
if (!response.ok) {
|
|
72
|
+
throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
|
|
73
|
+
}
|
|
74
|
+
const contentLength = response.headers.get('content-length');
|
|
75
|
+
const reader = (_a = response.body) === null || _a === void 0 ? void 0 : _a.getReader();
|
|
76
|
+
if (reader) {
|
|
77
|
+
const chunks = [];
|
|
78
|
+
const totalSize = contentLength ? parseInt(contentLength) : undefined;
|
|
79
|
+
const PROGRESS_PERC_LOG_INCREMENT = 5;
|
|
80
|
+
const BYTE_DOWNLOAD_LOG_INCREMENT = 5000000;
|
|
81
|
+
const [baseUrl, urlParams] = url.split('?');
|
|
82
|
+
const urlForLog = `${baseUrl}${(urlParams === null || urlParams === void 0 ? void 0 : urlParams.length) ? `...(${urlParams.length} more characters)` : ''}`;
|
|
83
|
+
let totalDownloadedBytes = 0;
|
|
84
|
+
let downloadedSize = 0;
|
|
85
|
+
let totalProgressPerc = 0;
|
|
86
|
+
// eslint-disable-next-line
|
|
87
|
+
while (true) {
|
|
88
|
+
const { done, value } = await reader.read();
|
|
89
|
+
if (done) {
|
|
90
|
+
logger_1.logger.info(`Download complete - ${urlForLog}`);
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
if (value) {
|
|
94
|
+
chunks.push(value);
|
|
95
|
+
downloadedSize += value.length;
|
|
96
|
+
if (totalSize) {
|
|
97
|
+
const progress = (downloadedSize / totalSize) * 100;
|
|
98
|
+
if (progress > totalProgressPerc + PROGRESS_PERC_LOG_INCREMENT) {
|
|
99
|
+
totalProgressPerc += PROGRESS_PERC_LOG_INCREMENT;
|
|
100
|
+
logger_1.logger.debug(`Download progress: ${progress.toFixed(2)}% - ${urlForLog}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
if (downloadedSize >
|
|
105
|
+
totalDownloadedBytes + BYTE_DOWNLOAD_LOG_INCREMENT) {
|
|
106
|
+
totalDownloadedBytes += BYTE_DOWNLOAD_LOG_INCREMENT;
|
|
107
|
+
logger_1.logger.debug(`Download progress: ${downloadedSize} total bytes - ${urlForLog}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
logger_1.logger.debug(`Writing downloaded chunks to file ${path}`);
|
|
113
|
+
const combinedSize = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
|
|
114
|
+
const combinedChunks = new Uint8Array(combinedSize);
|
|
115
|
+
let offset = 0;
|
|
116
|
+
for (const chunk of chunks) {
|
|
117
|
+
combinedChunks.set(chunk, offset);
|
|
118
|
+
offset += chunk.length;
|
|
119
|
+
}
|
|
120
|
+
(0, fs_1.writeFileSync)(path, combinedChunks);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
throw new Error('Unable to access response body when downloading file.');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.downloadToFile = downloadToFile;
|
|
66
127
|
//# sourceMappingURL=file.js.map
|
package/lib/util/file.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/util/file.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAChC,2CAAwC;AACxC,0CAA2D;AAC3D,+BAA4B;
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/util/file.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAChC,2CAAwC;A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,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAC1E,MAAM,cAAc,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,CAAC;QAEpD,IAAI,MAAM,GAAG,CAAC,CAAC;QACf,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;YAC1B,cAAc,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC;SACxB;QAED,IAAA,kBAAa,EAAC,IAAI,EAAE,cAAc,CAAC,CAAC;KACrC;SAAM;QACL,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;KAC1E;AACH,CAAC;AA5ED,wCA4EC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-device-id.d.ts","sourceRoot":"","sources":["../../src/util/get-device-id.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-device-id.d.ts","sourceRoot":"","sources":["../../src/util/get-device-id.ts"],"names":[],"mappings":"AAKA,wBAAgB,aAAa,WAc5B"}
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDeviceUuid = void 0;
|
|
4
4
|
const device_1 = require("alwaysai/lib/core/device");
|
|
5
|
+
const logger_1 = require("./logger");
|
|
6
|
+
const util_1 = require("alwaysai/lib/util");
|
|
7
|
+
const aai_error_1 = require("./aai-error");
|
|
5
8
|
function getDeviceUuid() {
|
|
6
9
|
const deviceCfgFile = (0, device_1.DeviceConfigFile)();
|
|
7
10
|
if (!deviceCfgFile.exists()) {
|
|
@@ -12,7 +15,10 @@ function getDeviceUuid() {
|
|
|
12
15
|
return cfg.deviceUuid;
|
|
13
16
|
}
|
|
14
17
|
catch (e) {
|
|
15
|
-
|
|
18
|
+
logger_1.logger.error(`Failed to read device configuration!\n${(0, util_1.stringifyError)(e)}`);
|
|
19
|
+
throw new aai_error_1.default('Failed to read device configuration', {
|
|
20
|
+
cause: deviceCfgFile.getErrors()
|
|
21
|
+
});
|
|
16
22
|
}
|
|
17
23
|
}
|
|
18
24
|
exports.getDeviceUuid = getDeviceUuid;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-device-id.js","sourceRoot":"","sources":["../../src/util/get-device-id.ts"],"names":[],"mappings":";;;AAAA,qDAA4D;
|
|
1
|
+
{"version":3,"file":"get-device-id.js","sourceRoot":"","sources":["../../src/util/get-device-id.ts"],"names":[],"mappings":";;;AAAA,qDAA4D;AAC5D,qCAAkC;AAClC,4CAAmD;AACnD,2CAAmC;AAEnC,SAAgB,aAAa;IAC3B,MAAM,aAAa,GAAG,IAAA,yBAAgB,GAAE,CAAC;IACzC,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,EAAE;QAC3B,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;KACpD;IACD,IAAI;QACF,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,EAAE,CAAC;QACjC,OAAO,GAAG,CAAC,UAAU,CAAC;KACvB;IAAC,OAAO,CAAC,EAAE;QACV,eAAM,CAAC,KAAK,CAAC,yCAAyC,IAAA,qBAAc,EAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC3E,MAAM,IAAI,mBAAQ,CAAC,qCAAqC,EAAE;YACxD,KAAK,EAAE,aAAa,CAAC,SAAS,EAAE;SACjC,CAAC,CAAC;KACJ;AACH,CAAC;AAdD,sCAcC"}
|
package/lib/util/http-client.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.microServiceHttpClient = exports.httpClient = void 0;
|
|
4
|
-
const node_fetch_1 = require("node-fetch");
|
|
5
4
|
const endpoints_1 = require("../endpoints");
|
|
6
5
|
const infrastructure_1 = require("alwaysai/lib/infrastructure");
|
|
7
6
|
const logger_1 = require("../util/logger");
|
|
7
|
+
const util_1 = require("alwaysai/lib/util");
|
|
8
8
|
async function httpClient(url, method, headers, data) {
|
|
9
9
|
const options = Object.assign({ method }, (data ? { body: data, headers } : { headers }));
|
|
10
10
|
try {
|
|
11
|
-
const response = await (
|
|
11
|
+
const response = await fetch(url, options);
|
|
12
12
|
const contentType = response.headers.get('content-type');
|
|
13
13
|
if (contentType === 'application/json') {
|
|
14
14
|
return await response.json();
|
|
@@ -18,7 +18,7 @@ async function httpClient(url, method, headers, data) {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
catch (e) {
|
|
21
|
-
logger_1.logger.error(`HTTP Client error for ${url}
|
|
21
|
+
logger_1.logger.error(`HTTP Client error for ${url}:\n${(0, util_1.stringifyError)(e)}`);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
exports.httpClient = httpClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-client.js","sourceRoot":"","sources":["../../src/util/http-client.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"http-client.js","sourceRoot":"","sources":["../../src/util/http-client.ts"],"names":[],"mappings":";;;AAAA,4CAAsD;AACtD,gEAAsE;AACtE,2CAAwC;AACxC,4CAAmD;AAE5C,KAAK,UAAU,UAAU,CAC9B,GAAW,EACX,MAAc,EACd,OAAY,EACZ,IAAa;IAEb,MAAM,OAAO,mBACX,MAAM,IACH,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAClD,CAAC;IACF,IAAI;QACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAC3C,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QACzD,IAAI,WAAW,KAAK,kBAAkB,EAAE;YACtC,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;SAC9B;QACD,IAAI,WAAY,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE;YACvC,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;SAC9B;KACF;IAAC,OAAO,CAAC,EAAE;QACV,eAAM,CAAC,KAAK,CAAC,yBAAyB,GAAG,MAAM,IAAA,qBAAc,EAAC,CAAC,CAAC,EAAE,CAAC,CAAC;KACrE;AACH,CAAC;AAtBD,gCAsBC;AAEM,KAAK,UAAU,sBAAsB,CAC1C,OAAe,EACf,IAAY,EACZ,MAAc,EACd,IAAa;IAEb,MAAM,QAAQ,GAAG,IAAA,kCAAsB,EAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACvD,MAAM,EAAE,wBAAwB,EAAE,GAAG,IAAA,wCAAuB,GAAE,CAAC;IAC/D,MAAM,mBAAmB,GAAG,MAAM,wBAAwB,EAAE,CAAC;IAC7D,OAAO,MAAM,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,mBAAmB,EAAE,IAAI,CAAC,CAAC;AACvE,CAAC;AAVD,wDAUC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwaysai/device-agent",
|
|
3
3
|
"description": "The alwaysAI Device Agent",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.1",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"publishConfig": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"engines": {
|
|
15
15
|
"npm": ">=7.0.0",
|
|
16
|
-
"node": ">=
|
|
16
|
+
"node": ">=18.0.0"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "tsc --project tsconfig.build.json",
|
|
@@ -34,44 +34,46 @@
|
|
|
34
34
|
"publish-provisioning:prod": "node ./scripts/publish-provisioning-scripts.js prod"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@alwaysai/alwayscli": "0.3.
|
|
38
|
-
"@alwaysai/app-configuration-schemas": "0.
|
|
39
|
-
"@alwaysai/config-nodejs": "0.3.
|
|
40
|
-
"@alwaysai/device-agent-schemas": "
|
|
37
|
+
"@alwaysai/alwayscli": "0.3.3",
|
|
38
|
+
"@alwaysai/app-configuration-schemas": "0.2.0",
|
|
39
|
+
"@alwaysai/config-nodejs": "0.3.3",
|
|
40
|
+
"@alwaysai/device-agent-schemas": "3.3.0",
|
|
41
41
|
"@carnesen/coded-error": "0.4.0",
|
|
42
42
|
"ajv": "8.11.0",
|
|
43
|
-
"alwaysai": "2.
|
|
43
|
+
"alwaysai": "2.6.1",
|
|
44
44
|
"amqplib": "0.10.3",
|
|
45
|
-
"aws-iot-device-sdk": "2.2.
|
|
46
|
-
"docker-compose": "0.24.
|
|
45
|
+
"aws-iot-device-sdk": "2.2.15",
|
|
46
|
+
"docker-compose": "0.24.8",
|
|
47
47
|
"lodash": "4.17.21",
|
|
48
|
-
"node-fetch": "2.6.1",
|
|
49
48
|
"node-os-utils": "1.3.7",
|
|
50
49
|
"rimraf": "4.4.0",
|
|
50
|
+
"serialize-error": "8.1.0",
|
|
51
51
|
"systeminformation": "5.21.13",
|
|
52
52
|
"uuid": "9.0.0",
|
|
53
53
|
"winston": "3.13.0",
|
|
54
54
|
"winston-daily-rotate-file": "5.0.0",
|
|
55
|
-
"yaml": "2.
|
|
55
|
+
"yaml": "2.5.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@alwaysai/eslint-config": "0.1.
|
|
58
|
+
"@alwaysai/eslint-config": "0.1.3",
|
|
59
59
|
"@alwaysai/tsconfig": "0.0.1",
|
|
60
60
|
"@types/amqplib": "0.10.5",
|
|
61
61
|
"@types/destroy": "1.0.0",
|
|
62
|
-
"@types/jest": "
|
|
63
|
-
"@types/node": "
|
|
62
|
+
"@types/jest": "29.1.2",
|
|
63
|
+
"@types/node": "18.11.9",
|
|
64
64
|
"@types/node-os-utils": "^1.3.4",
|
|
65
|
+
"@types/rimraf": "3.0.2",
|
|
65
66
|
"@types/sinon": "10.0.6",
|
|
67
|
+
"@types/tar": "6.1.2",
|
|
66
68
|
"@typescript-eslint/eslint-plugin": "^5.48.0",
|
|
67
69
|
"@typescript-eslint/parser": "^5.48.0",
|
|
68
|
-
"aws-sdk": "^2.
|
|
70
|
+
"aws-sdk": "^2.1663.0",
|
|
69
71
|
"cp-cli": "2.0.0",
|
|
70
72
|
"get-stream": "6.0.1",
|
|
71
|
-
"jest": "
|
|
73
|
+
"jest": "29.7.0",
|
|
72
74
|
"sinon": "12.0.1",
|
|
73
75
|
"tempy": "0.7.1",
|
|
74
|
-
"ts-jest": "
|
|
76
|
+
"ts-jest": "29.2.3",
|
|
75
77
|
"ts-mock-imports": "1.3.8",
|
|
76
78
|
"ts-node": "10.8.1",
|
|
77
79
|
"typescript": "4.6.4"
|
package/readme.md
CHANGED
|
@@ -28,7 +28,6 @@ change.
|
|
|
28
28
|
- [Control the application](#control-the-application)
|
|
29
29
|
- [Manage application models](#manage-application-models)
|
|
30
30
|
- [Update models to new version of the same model ID](#update-models-to-new-version-of-the-same-model-id)
|
|
31
|
-
- [Replace models for an application for new ID](#replace-models-for-an-application-for-new-id)
|
|
32
31
|
- [Manually download a model package](#manually-download-a-model-package)
|
|
33
32
|
- [Set and update environment variables](#set-and-update-environment-variables)
|
|
34
33
|
- [Device Cleaning and Uninstalling](#device-cleaning-and-uninstalling)
|
|
@@ -86,15 +85,18 @@ Provisioning the device performs the following:
|
|
|
86
85
|
Run the following command on the target device to provision it:
|
|
87
86
|
|
|
88
87
|
```bash
|
|
89
|
-
$ curl -fsSL https://artifacts.alwaysai.co/device-agent/provision.sh | bash -s -- --email <email> --password <password> [--device-name <device_name>]
|
|
88
|
+
$ curl -fsSL https://artifacts.alwaysai.co/device-agent/provision.sh | bash -s -- --email <email> --password <password> [--device-name <device_name>] [--pm2-overwrite] [--agent-tag <agent_tag>]
|
|
90
89
|
```
|
|
91
90
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
91
|
+
|
|
92
|
+
| Options | Details |
|
|
93
|
+
|:----------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
94
|
+
| --email | [REQUIRED] The email associated with your alwaysAI account. |
|
|
95
|
+
| --password | [REQUIRED] The password associated with your alwaysAI account |
|
|
96
|
+
| --device-name | [OPTIONAL] A device name to be associated with this device. It will be displayed on the devices page of the alwaysAI Dashboard. If a device name is not provided, one will be generated for you and logged to the console for reference. |
|
|
97
|
+
| --pm2-overwrite | [OPTIONAL] Overwrite any existing pm2 configuration with the latest provided by the script. The default behavior is to leave existing pm2 configurations as-is. |
|
|
98
|
+
| --agent-tag | [OPTIONAL] Select a specific release tag for the alwaysAI Device Agent. The default option is latest, which tracks the latest production release from alwaysAI. |
|
|
99
|
+
|
|
98
100
|
|
|
99
101
|
**Important note**: If your password contains one or more special characters and you receive an error message that your password does not match your username but you are sure that it is correctly entered, please try preceding every special character in your password with a backslash, and re-running the provisioning command. You can also reset your password at https://console.alwaysai.co/dashboard by logging out, navigating to the sign in page, and clicking '`Forgot Password?`'.
|
|
100
102
|
|
|
@@ -303,7 +305,6 @@ Subcommands:
|
|
|
303
305
|
app uninstall : Remove an alwaysAI app
|
|
304
306
|
app show-models : Show the application models
|
|
305
307
|
app add-model : Add a model to an alwaysAI app
|
|
306
|
-
app remove-model : Remove a model from an alwaysAI app
|
|
307
308
|
app get-all-envs : Get environment variables for an application
|
|
308
309
|
app set-env : Set environment variables for a service
|
|
309
310
|
app get-analytics-cfg : Get analytics configuration for an application
|
|
@@ -362,32 +363,11 @@ There are several ways to manage the models for your application.
|
|
|
362
363
|
#### Update models to new version of the same model ID
|
|
363
364
|
|
|
364
365
|
If a new version of a model is published for an existing model ID, and an
|
|
365
|
-
application is already configured to be using that model ID, updating
|
|
366
|
+
application is already configured to be using that model ID, updating the
|
|
366
367
|
new model can simply be done with:
|
|
367
368
|
|
|
368
369
|
```bash
|
|
369
|
-
$ aai-agent app
|
|
370
|
-
$ aai-agent app update-models --project <project_id>
|
|
371
|
-
$ aai-agent app start --project <project_id>
|
|
372
|
-
```
|
|
373
|
-
|
|
374
|
-
#### Replace models for an application for new ID
|
|
375
|
-
|
|
376
|
-
If you'd like to install an entirely new model to an application, replacing the
|
|
377
|
-
model the app was originally configured with, run the following command:
|
|
378
|
-
|
|
379
|
-
```bash
|
|
380
|
-
$ aai-agent app stop --project <project_id>
|
|
381
|
-
$ aai-agent app replace-models --project <project_id> --models <model_id_1> [<model_id_2> ...]
|
|
382
|
-
$ aai-agent app start --project <project_id>
|
|
383
|
-
```
|
|
384
|
-
|
|
385
|
-
If you plan on using this method, you can make your application source model ID
|
|
386
|
-
agnostic by providing the model ID to edgeIQ in the following way:
|
|
387
|
-
|
|
388
|
-
Select the first model in the config list:
|
|
389
|
-
```python
|
|
390
|
-
obj_detect = edgeiq.ObjectDetection(edgeiq._globals.MODEL_ID_LIST[0])
|
|
370
|
+
$ aai-agent app add-model --project <ProjectID> --model <ModelID> --version <ModelVersion>
|
|
391
371
|
```
|
|
392
372
|
|
|
393
373
|
#### Manually download a model package
|
|
@@ -6,13 +6,14 @@ import {
|
|
|
6
6
|
requireAppInstalled,
|
|
7
7
|
requireAppReady
|
|
8
8
|
} from './utils';
|
|
9
|
-
import { JsSpawner } from 'alwaysai/lib/util';
|
|
9
|
+
import { JsSpawner, stringifyError } from 'alwaysai/lib/util';
|
|
10
10
|
import { compose } from '../docker/docker-compose';
|
|
11
11
|
import { assign, merge } from 'lodash';
|
|
12
12
|
import { AppJsonFile } from 'alwaysai/lib/core/app';
|
|
13
13
|
import { AppConfig } from '@alwaysai/app-configuration-schemas';
|
|
14
14
|
import { isAppStarted, restartApp } from './status';
|
|
15
15
|
import { logger } from '../util/logger';
|
|
16
|
+
import AaiError from '../util/aai-error';
|
|
16
17
|
|
|
17
18
|
export async function readAppCfgFile(props: {
|
|
18
19
|
projectId: string;
|
|
@@ -27,11 +28,9 @@ export async function readAppCfgFile(props: {
|
|
|
27
28
|
try {
|
|
28
29
|
return appJson.read();
|
|
29
30
|
} catch (e) {
|
|
30
|
-
throw new Error
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}\n${appJson.getErrors()}`
|
|
34
|
-
);
|
|
31
|
+
throw new AaiError(`Error reading app config for ${projectId}`, {
|
|
32
|
+
cause: appJson.getErrors()
|
|
33
|
+
});
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
36
|
|
|
@@ -45,11 +44,9 @@ export async function writeAppCfgFile(props: {
|
|
|
45
44
|
try {
|
|
46
45
|
appJson.write(appCfg);
|
|
47
46
|
} catch (e) {
|
|
48
|
-
throw new Error
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}\n${appJson.getErrors()}`
|
|
52
|
-
);
|
|
47
|
+
throw new AaiError(`Error writing app config for ${projectId}`, {
|
|
48
|
+
cause: appJson.getErrors()
|
|
49
|
+
});
|
|
53
50
|
}
|
|
54
51
|
}
|
|
55
52
|
|
|
@@ -124,7 +121,7 @@ export async function writeDockerCompose(props: {
|
|
|
124
121
|
try {
|
|
125
122
|
await compose.config({ cwd: appDir, configAsString: composeOutput });
|
|
126
123
|
} catch (e) {
|
|
127
|
-
logger.error(
|
|
124
|
+
logger.error(stringifyError(e));
|
|
128
125
|
}
|
|
129
126
|
await spawner.writeFile('docker-compose.yaml', composeOutput);
|
|
130
127
|
}
|
|
@@ -91,6 +91,24 @@ describe('Test environment variable get and set', () => {
|
|
|
91
91
|
edgeiq: { TEST3: '5', TEST4: '6' }
|
|
92
92
|
});
|
|
93
93
|
});
|
|
94
|
+
test('get all envs with one service and one cleared env', async () => {
|
|
95
|
+
const compose = {
|
|
96
|
+
services: {
|
|
97
|
+
alwaysai: {
|
|
98
|
+
environment: ['TEST=', 'TEST2=2']
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
jest.mocked(readDockerCompose).mockResolvedValue(compose);
|
|
103
|
+
|
|
104
|
+
const envVars = await getAllEnvs({ projectId: projectId1 });
|
|
105
|
+
expect(jest.mocked(readDockerCompose)).toBeCalledWith({
|
|
106
|
+
projectId: projectId1
|
|
107
|
+
});
|
|
108
|
+
expect(envVars).toEqual({
|
|
109
|
+
alwaysai: { TEST: '', TEST2: '2' }
|
|
110
|
+
});
|
|
111
|
+
});
|
|
94
112
|
});
|
|
95
113
|
describe('Test setEnv()', () => {
|
|
96
114
|
test('Set one env', async () => {
|
|
@@ -126,7 +144,7 @@ describe('Test environment variable get and set', () => {
|
|
|
126
144
|
};
|
|
127
145
|
jest.mocked(readDockerCompose).mockResolvedValue(compose);
|
|
128
146
|
|
|
129
|
-
const envVars = { alwaysai: { TEST1: '2' } };
|
|
147
|
+
const envVars = { alwaysai: { TEST1: '2', TEST2: '2' } };
|
|
130
148
|
await setEnv({ projectId: projectId1, envVars });
|
|
131
149
|
expect(jest.mocked(readDockerCompose)).toBeCalledWith({
|
|
132
150
|
projectId: projectId1
|
|
@@ -152,7 +170,10 @@ describe('Test environment variable get and set', () => {
|
|
|
152
170
|
};
|
|
153
171
|
jest.mocked(readDockerCompose).mockResolvedValue(compose);
|
|
154
172
|
|
|
155
|
-
const envVars = {
|
|
173
|
+
const envVars = {
|
|
174
|
+
alwaysai: { TEST1: '2', TEST2: '4' },
|
|
175
|
+
other: { OTHER_TEST: '1' }
|
|
176
|
+
};
|
|
156
177
|
await setEnv({ projectId: projectId1, envVars });
|
|
157
178
|
expect(jest.mocked(readDockerCompose)).toBeCalledWith({
|
|
158
179
|
projectId: projectId1
|
|
@@ -171,7 +192,7 @@ describe('Test environment variable get and set', () => {
|
|
|
171
192
|
}
|
|
172
193
|
});
|
|
173
194
|
});
|
|
174
|
-
test('
|
|
195
|
+
test('Unset an envvar', async () => {
|
|
175
196
|
const environment = ['TEST1=1', 'TEST2=2'];
|
|
176
197
|
const compose = {
|
|
177
198
|
services: {
|
|
@@ -180,7 +201,7 @@ describe('Test environment variable get and set', () => {
|
|
|
180
201
|
};
|
|
181
202
|
jest.mocked(readDockerCompose).mockResolvedValue(compose);
|
|
182
203
|
|
|
183
|
-
const envVars = { alwaysai: { TEST1:
|
|
204
|
+
const envVars = { alwaysai: { TEST1: '', TEST2: '2' } };
|
|
184
205
|
await setEnv({ projectId: projectId1, envVars });
|
|
185
206
|
expect(jest.mocked(readDockerCompose)).toBeCalledWith({
|
|
186
207
|
projectId: projectId1
|
|
@@ -190,7 +211,7 @@ describe('Test environment variable get and set', () => {
|
|
|
190
211
|
dockerCompose: {
|
|
191
212
|
services: {
|
|
192
213
|
alwaysai: {
|
|
193
|
-
environment: ['TEST2=2']
|
|
214
|
+
environment: ['TEST1=', 'TEST2=2']
|
|
194
215
|
}
|
|
195
216
|
}
|
|
196
217
|
}
|
|
@@ -199,12 +220,12 @@ describe('Test environment variable get and set', () => {
|
|
|
199
220
|
});
|
|
200
221
|
describe('Test helpers', () => {
|
|
201
222
|
test('convertStringEnvsToKeyVal', () => {
|
|
202
|
-
const stringEnvs: string[] = ['TEST1=', 'TEST2=test2', 'TEST3=
|
|
223
|
+
const stringEnvs: string[] = ['TEST1=', 'TEST2=test2', 'TEST3='];
|
|
203
224
|
const envVars = convertStringEnvsToKeyVal(stringEnvs);
|
|
204
225
|
expect(envVars).toEqual({
|
|
205
226
|
TEST1: '',
|
|
206
227
|
TEST2: 'test2',
|
|
207
|
-
TEST3: '
|
|
228
|
+
TEST3: ''
|
|
208
229
|
});
|
|
209
230
|
});
|
|
210
231
|
});
|