@alwaysai/device-agent 0.0.12 → 0.0.13

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 (181) hide show
  1. package/lib/application-control/backup.d.ts.map +1 -1
  2. package/lib/application-control/backup.js +8 -2
  3. package/lib/application-control/backup.js.map +1 -1
  4. package/lib/application-control/config.d.ts +12 -4
  5. package/lib/application-control/config.d.ts.map +1 -1
  6. package/lib/application-control/config.js +59 -16
  7. package/lib/application-control/config.js.map +1 -1
  8. package/lib/application-control/environment-variables.d.ts.map +1 -1
  9. package/lib/application-control/environment-variables.js.map +1 -1
  10. package/lib/application-control/index.d.ts +4 -4
  11. package/lib/application-control/index.d.ts.map +1 -1
  12. package/lib/application-control/index.js +4 -3
  13. package/lib/application-control/index.js.map +1 -1
  14. package/lib/application-control/install.d.ts.map +1 -1
  15. package/lib/application-control/install.js +28 -14
  16. package/lib/application-control/install.js.map +1 -1
  17. package/lib/application-control/models.d.ts +7 -1
  18. package/lib/application-control/models.d.ts.map +1 -1
  19. package/lib/application-control/models.js +69 -39
  20. package/lib/application-control/models.js.map +1 -1
  21. package/lib/application-control/status.d.ts.map +1 -1
  22. package/lib/application-control/status.js +18 -14
  23. package/lib/application-control/status.js.map +1 -1
  24. package/lib/application-control/utils.d.ts +0 -2
  25. package/lib/application-control/utils.d.ts.map +1 -1
  26. package/lib/application-control/utils.js +7 -16
  27. package/lib/application-control/utils.js.map +1 -1
  28. package/lib/cloud-connection/app-install-status.d.ts +16 -0
  29. package/lib/cloud-connection/app-install-status.d.ts.map +1 -0
  30. package/lib/cloud-connection/app-install-status.js +53 -0
  31. package/lib/cloud-connection/app-install-status.js.map +1 -0
  32. package/lib/cloud-connection/bootstrap-provision.d.ts +2 -0
  33. package/lib/cloud-connection/bootstrap-provision.d.ts.map +1 -0
  34. package/lib/cloud-connection/bootstrap-provision.js +34 -0
  35. package/lib/cloud-connection/bootstrap-provision.js.map +1 -0
  36. package/lib/cloud-connection/device-agent-cloud-connection.d.ts +12 -34
  37. package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
  38. package/lib/cloud-connection/device-agent-cloud-connection.js +169 -385
  39. package/lib/cloud-connection/device-agent-cloud-connection.js.map +1 -1
  40. package/lib/cloud-connection/device-agent.d.ts.map +1 -1
  41. package/lib/cloud-connection/device-agent.js +22 -26
  42. package/lib/cloud-connection/device-agent.js.map +1 -1
  43. package/lib/cloud-connection/live-updates-handler.d.ts +34 -0
  44. package/lib/cloud-connection/live-updates-handler.d.ts.map +1 -0
  45. package/lib/cloud-connection/live-updates-handler.js +167 -0
  46. package/lib/cloud-connection/live-updates-handler.js.map +1 -0
  47. package/lib/cloud-connection/messages.d.ts +14 -0
  48. package/lib/cloud-connection/messages.d.ts.map +1 -0
  49. package/lib/cloud-connection/messages.js +38 -0
  50. package/lib/cloud-connection/messages.js.map +1 -0
  51. package/lib/cloud-connection/publisher.d.ts +14 -0
  52. package/lib/cloud-connection/publisher.d.ts.map +1 -0
  53. package/lib/cloud-connection/publisher.js +44 -0
  54. package/lib/cloud-connection/publisher.js.map +1 -0
  55. package/lib/cloud-connection/shadow-handler.d.ts +34 -0
  56. package/lib/cloud-connection/shadow-handler.d.ts.map +1 -0
  57. package/lib/cloud-connection/shadow-handler.js +94 -0
  58. package/lib/cloud-connection/shadow-handler.js.map +1 -0
  59. package/lib/cloud-connection/shadow.d.ts +16 -0
  60. package/lib/cloud-connection/shadow.d.ts.map +1 -0
  61. package/lib/cloud-connection/shadow.js +36 -0
  62. package/lib/cloud-connection/shadow.js.map +1 -0
  63. package/lib/device-control/device-control.d.ts.map +1 -1
  64. package/lib/device-control/device-control.js +1 -0
  65. package/lib/device-control/device-control.js.map +1 -1
  66. package/lib/docker/docker-cmd.js +1 -1
  67. package/lib/docker/docker-compose-cmd.d.ts.map +1 -1
  68. package/lib/docker/docker-compose-cmd.js +1 -1
  69. package/lib/docker/docker-compose-cmd.js.map +1 -1
  70. package/lib/endpoints.js +10 -10
  71. package/lib/endpoints.js.map +1 -1
  72. package/lib/environment.d.ts.map +1 -1
  73. package/lib/environment.js.map +1 -1
  74. package/lib/infrastructure/agent-config.d.ts +4 -14
  75. package/lib/infrastructure/agent-config.d.ts.map +1 -1
  76. package/lib/infrastructure/agent-config.js +22 -15
  77. package/lib/infrastructure/agent-config.js.map +1 -1
  78. package/lib/infrastructure/agent-config.test.js +26 -18
  79. package/lib/infrastructure/agent-config.test.js.map +1 -1
  80. package/lib/infrastructure/system-id.d.ts +2 -0
  81. package/lib/infrastructure/system-id.d.ts.map +1 -0
  82. package/lib/infrastructure/system-id.js +21 -0
  83. package/lib/infrastructure/system-id.js.map +1 -0
  84. package/lib/infrastructure/tokens-and-device-cfg.d.ts +4 -0
  85. package/lib/infrastructure/tokens-and-device-cfg.d.ts.map +1 -0
  86. package/lib/infrastructure/tokens-and-device-cfg.js +31 -0
  87. package/lib/infrastructure/tokens-and-device-cfg.js.map +1 -0
  88. package/lib/infrastructure/urls.d.ts.map +1 -1
  89. package/lib/infrastructure/urls.js +3 -3
  90. package/lib/infrastructure/urls.js.map +1 -1
  91. package/lib/root.d.ts.map +1 -1
  92. package/lib/root.js +2 -7
  93. package/lib/root.js.map +1 -1
  94. package/lib/subcommands/app/app.d.ts.map +1 -1
  95. package/lib/subcommands/app/app.js +62 -60
  96. package/lib/subcommands/app/app.js.map +1 -1
  97. package/lib/subcommands/app/index.js +2 -2
  98. package/lib/subcommands/device/clean.d.ts +2 -0
  99. package/lib/subcommands/device/clean.d.ts.map +1 -0
  100. package/lib/subcommands/device/clean.js +29 -0
  101. package/lib/subcommands/device/clean.js.map +1 -0
  102. package/lib/subcommands/device/device.d.ts.map +1 -1
  103. package/lib/subcommands/device/device.js +40 -27
  104. package/lib/subcommands/device/device.js.map +1 -1
  105. package/lib/subcommands/device/index.d.ts.map +1 -1
  106. package/lib/subcommands/device/index.js +2 -1
  107. package/lib/subcommands/device/index.js.map +1 -1
  108. package/lib/subcommands/get-model-package.js +5 -5
  109. package/lib/subcommands/index.js +1 -1
  110. package/lib/subcommands/login.js +8 -8
  111. package/lib/subcommands/login.js.map +1 -1
  112. package/lib/util/clean-certs.d.ts +2 -0
  113. package/lib/util/clean-certs.d.ts.map +1 -0
  114. package/lib/util/clean-certs.js +16 -0
  115. package/lib/util/clean-certs.js.map +1 -0
  116. package/lib/util/directories.d.ts +16 -15
  117. package/lib/util/directories.d.ts.map +1 -1
  118. package/lib/util/directories.js +45 -26
  119. package/lib/util/directories.js.map +1 -1
  120. package/lib/util/get-device-id.d.ts +1 -1
  121. package/lib/util/get-device-id.d.ts.map +1 -1
  122. package/lib/util/get-device-id.js +14 -19
  123. package/lib/util/get-device-id.js.map +1 -1
  124. package/lib/util/http-client.d.ts +1 -1
  125. package/lib/util/http-client.d.ts.map +1 -1
  126. package/lib/util/http-client.js +10 -8
  127. package/lib/util/http-client.js.map +1 -1
  128. package/lib/util/logger.d.ts.map +1 -1
  129. package/lib/util/logger.js +4 -5
  130. package/lib/util/logger.js.map +1 -1
  131. package/lib/util/run-in-dir.d.ts.map +1 -1
  132. package/lib/util/run-in-dir.js +1 -0
  133. package/lib/util/run-in-dir.js.map +1 -1
  134. package/package.json +17 -8
  135. package/src/application-control/backup.ts +8 -3
  136. package/src/application-control/config.ts +75 -13
  137. package/src/application-control/environment-variables.ts +3 -3
  138. package/src/application-control/index.ts +19 -6
  139. package/src/application-control/install.ts +52 -28
  140. package/src/application-control/models.ts +100 -56
  141. package/src/application-control/status.ts +26 -21
  142. package/src/application-control/utils.ts +9 -20
  143. package/src/cloud-connection/app-install-status.ts +62 -0
  144. package/src/cloud-connection/bootstrap-provision.ts +40 -0
  145. package/src/cloud-connection/device-agent-cloud-connection.ts +257 -528
  146. package/src/cloud-connection/device-agent.ts +31 -38
  147. package/src/cloud-connection/live-updates-handler.ts +226 -0
  148. package/src/cloud-connection/messages.ts +39 -0
  149. package/src/cloud-connection/publisher.ts +65 -0
  150. package/src/cloud-connection/shadow-handler.ts +154 -0
  151. package/src/cloud-connection/shadow.ts +50 -0
  152. package/src/device-control/device-control.ts +1 -0
  153. package/src/docker/docker-cmd.ts +1 -1
  154. package/src/docker/docker-compose-cmd.ts +5 -2
  155. package/src/endpoints.ts +9 -9
  156. package/src/environment.ts +8 -3
  157. package/src/infrastructure/agent-config.test.ts +34 -23
  158. package/src/infrastructure/agent-config.ts +33 -20
  159. package/src/infrastructure/system-id.ts +18 -0
  160. package/src/infrastructure/tokens-and-device-cfg.ts +39 -0
  161. package/src/infrastructure/urls.ts +4 -2
  162. package/src/root.ts +2 -8
  163. package/src/subcommands/app/app.ts +64 -62
  164. package/src/subcommands/app/index.ts +3 -3
  165. package/src/subcommands/device/clean.ts +26 -0
  166. package/src/subcommands/device/device.ts +66 -50
  167. package/src/subcommands/device/index.ts +2 -1
  168. package/src/subcommands/get-model-package.ts +5 -5
  169. package/src/subcommands/index.ts +1 -1
  170. package/src/subcommands/login.ts +8 -8
  171. package/src/util/clean-certs.ts +12 -0
  172. package/src/util/directories.ts +68 -52
  173. package/src/util/get-device-id.ts +16 -18
  174. package/src/util/http-client.ts +18 -13
  175. package/src/util/logger.ts +6 -6
  176. package/src/util/run-in-dir.ts +2 -1
  177. package/lib/infrastructure/certificates-and-tokens.d.ts +0 -6
  178. package/lib/infrastructure/certificates-and-tokens.d.ts.map +0 -1
  179. package/lib/infrastructure/certificates-and-tokens.js +0 -43
  180. package/lib/infrastructure/certificates-and-tokens.js.map +0 -1
  181. package/src/infrastructure/certificates-and-tokens.ts +0 -53
@@ -1,68 +1,84 @@
1
1
  import {
2
+ AAI_DIR,
2
3
  DEVICE_TOKEN_FILE_NAME,
3
4
  LOCAL_AAI_CFG_DIR,
5
+ LOCAL_CERT_AND_KEY_DIR
6
+ } from 'alwaysai/lib/constants';
7
+ import { join } from 'path';
8
+ import { getSystemId } from '../infrastructure/system-id';
9
+ import * as path from 'path';
10
+
11
+ export const APP_ROOT = path.join(AAI_DIR, 'applications');
12
+
13
+ export const CREDENTIALS_FILE_PATH = join(
14
+ LOCAL_AAI_CFG_DIR,
15
+ DEVICE_TOKEN_FILE_NAME
16
+ );
17
+
18
+ export const AWS_ROOT_CERTIFICATE_FILE_NAME = 'AmazonRootCA1.pem';
19
+ export const AWS_ROOT_CERTIFICATE_FILE_PATH = join(
4
20
  LOCAL_CERT_AND_KEY_DIR,
5
- } from "alwaysai/lib/constants";
6
- import { join } from "path";
21
+ AWS_ROOT_CERTIFICATE_FILE_NAME
22
+ );
7
23
 
8
- export const BOOTSTRAP_DIR_NAME = "bootstrap-certificates";
9
- export const BOOTSTRAP_DEVICE_PRIVATE_KEY_FILE_NAME =
10
- "aai-claim-private-key_qa.pem.key";
11
- export const BOOTSTRAP_DEVICE_CERTIFICATE_FILE_NAME =
12
- "aai-claim-cert_qa.pem.crt";
13
- export const BOOTSTRAP_CLAIM_ID_FILE_NAME = "aai-claim-cert-id_qa.txt";
14
- export const AWS_ROOT_CERTIFICATE_FILE_NAME = "AmazonRootCA1.pem";
15
- export const CERTIFICATE_OWNERSHIP_TOKEN_FILE_NAME =
16
- "certificate-ownership-token.txt";
24
+ export const shortenSystemId = () => {
25
+ const id = getSystemId();
26
+ switch (id) {
27
+ case 'development':
28
+ return 'dev';
29
+ case 'qa':
30
+ return 'qa';
31
+ case 'production':
32
+ return 'prod';
33
+ }
34
+ };
17
35
 
18
- export const DEVICE_PRIVATE_KEY_FILE_NAME = "aai-claim-private-key_qa.pem.key";
19
- export const DEVICE_CERTIFICATE_FILE_NAME = "aai-claim-cert_qa.pem.crt";
20
- export const DEVICE_CLAIM_ID_FILE_NAME = "aai-claim-cert-id_qa.txt";
36
+ export const BOOTSTRAP_DIR_NAME = 'bootstrap-certificates';
37
+ export const BOOTSTRAP_DEVICE_PRIVATE_KEY_FILE_NAME = () =>
38
+ `aai-claim-private-key_${shortenSystemId()}.pem.key`;
39
+ export const BOOTSTRAP_DEVICE_CERTIFICATE_FILE_NAME = () =>
40
+ `aai-claim-cert_${shortenSystemId()}.pem.crt`;
41
+ export const BOOTSTRAP_CLAIM_ID_FILE_NAME = () =>
42
+ `aai-claim-cert-id_${shortenSystemId()}.txt`;
43
+ export const CERTIFICATE_OWNERSHIP_TOKEN_FILE_NAME =
44
+ 'certificate-ownership-token.txt';
45
+ export const DEVICE_PRIVATE_KEY_FILE_NAME = () =>
46
+ `aai-claim-private-key_${shortenSystemId()}.pem.key`;
47
+ export const DEVICE_CERTIFICATE_FILE_NAME = () =>
48
+ `aai-claim-cert_${shortenSystemId()}.pem.crt`;
49
+ export const DEVICE_CLAIM_ID_FILE_NAME = () =>
50
+ `aai-claim-cert-id_${shortenSystemId()}.txt`;
21
51
 
22
52
  export function getPrivateKeyFilePath() {
23
- return join(LOCAL_CERT_AND_KEY_DIR, DEVICE_PRIVATE_KEY_FILE_NAME);
53
+ return join(LOCAL_CERT_AND_KEY_DIR, DEVICE_PRIVATE_KEY_FILE_NAME());
24
54
  }
25
55
 
26
56
  export function getCertificateFilePath() {
27
- return join(LOCAL_CERT_AND_KEY_DIR, DEVICE_CERTIFICATE_FILE_NAME);
57
+ return join(LOCAL_CERT_AND_KEY_DIR, DEVICE_CERTIFICATE_FILE_NAME());
28
58
  }
29
59
 
30
- export function getRootCertificateFilePath() {
31
- return join(LOCAL_CERT_AND_KEY_DIR, AWS_ROOT_CERTIFICATE_FILE_NAME);
32
- }
60
+ export const BOOTSTRAP_CERTIFICATES_DIR_PATH = () =>
61
+ join(LOCAL_CERT_AND_KEY_DIR, BOOTSTRAP_DIR_NAME);
62
+ export const DEVICE_CLAIM_ID_FILE_PATH = () =>
63
+ join(LOCAL_CERT_AND_KEY_DIR, DEVICE_TOKEN_FILE_NAME);
33
64
 
34
- export function getCredentialsFilePath() {
35
- return join(LOCAL_AAI_CFG_DIR, DEVICE_TOKEN_FILE_NAME);
36
- }
65
+ export const BOOTSTRAP_DEVICE_PRIVATE_KEY_FILE_PATH = () =>
66
+ join(
67
+ LOCAL_CERT_AND_KEY_DIR,
68
+ BOOTSTRAP_DIR_NAME,
69
+ BOOTSTRAP_DEVICE_PRIVATE_KEY_FILE_NAME()
70
+ );
37
71
 
38
- export const BOOTSTRAP_CERTIFICATES_DIR_PATH = join(
39
- LOCAL_CERT_AND_KEY_DIR,
40
- BOOTSTRAP_DIR_NAME
41
- );
42
- export const DEVICE_CLAIM_ID_FILE_PATH = join(
43
- LOCAL_CERT_AND_KEY_DIR,
44
- DEVICE_TOKEN_FILE_NAME
45
- );
46
-
47
- export const BOOTSTRAP_DEVICE_PRIVATE_KEY_FILE_PATH = join(
48
- LOCAL_CERT_AND_KEY_DIR,
49
- BOOTSTRAP_DIR_NAME,
50
- BOOTSTRAP_DEVICE_PRIVATE_KEY_FILE_NAME
51
- );
52
-
53
- export const BOOTSTRAP_DEVICE_CERTIFICATE_FILE_PATH = join(
54
- LOCAL_CERT_AND_KEY_DIR,
55
- BOOTSTRAP_DIR_NAME,
56
- BOOTSTRAP_DEVICE_CERTIFICATE_FILE_NAME
57
- );
72
+ export const BOOTSTRAP_DEVICE_CERTIFICATE_FILE_PATH = () =>
73
+ join(
74
+ LOCAL_CERT_AND_KEY_DIR,
75
+ BOOTSTRAP_DIR_NAME,
76
+ BOOTSTRAP_DEVICE_CERTIFICATE_FILE_NAME()
77
+ );
58
78
 
59
- export const BOOTSTRAP_CLAIM_ID_FILE_PATH = join(
60
- LOCAL_CERT_AND_KEY_DIR,
61
- BOOTSTRAP_DIR_NAME,
62
- BOOTSTRAP_CLAIM_ID_FILE_NAME
63
- );
64
-
65
- export const AWS_ROOT_CERTIFICATE_FILE_PATH = join(
66
- LOCAL_CERT_AND_KEY_DIR,
67
- AWS_ROOT_CERTIFICATE_FILE_NAME
68
- );
79
+ export const BOOTSTRAP_CLAIM_ID_FILE_PATH = () =>
80
+ join(
81
+ LOCAL_CERT_AND_KEY_DIR,
82
+ BOOTSTRAP_DIR_NAME,
83
+ BOOTSTRAP_CLAIM_ID_FILE_NAME()
84
+ );
@@ -1,22 +1,20 @@
1
- import { getCredentialsFilePath } from '../util/directories';
2
- import { CliTerseError } from '@alwaysai/alwayscli';
3
- import { ConfigFile } from '@alwaysai/config-nodejs';
4
- import * as t from 'io-ts';
1
+ import { DeviceConfigFile } from 'alwaysai/lib/core/device';
5
2
 
6
- export function getDeviceId() {
7
- const path = getCredentialsFilePath();
8
- const codec = t.type({
9
- deviceId: t.union([t.string, t.undefined]),
10
- });
11
- const credentialsJsonFile = ConfigFile({
12
- path,
13
- codec,
14
- });
15
- const config = credentialsJsonFile.readIfExists();
16
- if (!config || !config.deviceId) {
17
- throw new CliTerseError(
18
- 'Invalid device credentials! Please ensure you are using the device agent on a valid device.',
3
+ export function getDeviceUuid() {
4
+ const deviceCfgFile = DeviceConfigFile();
5
+ if (!deviceCfgFile.exists()) {
6
+ throw new Error('Device configuration not found!');
7
+ }
8
+ try {
9
+ const cfg = deviceCfgFile.read();
10
+ return cfg.deviceUuid;
11
+ } catch (err) {
12
+ throw new Error(
13
+ `Failed to read device configuration: ${JSON.stringify(
14
+ deviceCfgFile.getErrors(),
15
+ null,
16
+ 2
17
+ )}`
19
18
  );
20
19
  }
21
- return config.deviceId;
22
20
  }
@@ -1,25 +1,30 @@
1
- import fetch from "node-fetch";
2
- import { serviceEndpointBuilder } from "../endpoints";
3
- import { CliAuthenticationClient } from "alwaysai/lib/infrastructure";
1
+ import fetch from 'node-fetch';
2
+ import { serviceEndpointBuilder } from '../endpoints';
3
+ import { CliAuthenticationClient } from 'alwaysai/lib/infrastructure';
4
+ import { logger } from '../util/logger';
4
5
 
5
6
  export async function httpClient(
6
7
  url: string,
7
8
  method: string,
8
- data?: string,
9
- headers?: object
9
+ headers: any,
10
+ data?: string
10
11
  ) {
11
- const options = { method, ...(data ? { body: data } : {}) };
12
+ const options = {
13
+ method,
14
+ ...(data ? { body: data, headers } : { headers })
15
+ };
12
16
  try {
13
17
  const response = await fetch(url, options);
14
- const code = response.status;
15
-
16
- const contentType = response.headers.get("content-type");
17
- if (contentType === "application/json") {
18
+ const contentType = response.headers.get('content-type');
19
+ if (contentType === 'application/json') {
18
20
  return await response.json();
19
- } else if (contentType!.includes("text/plain")) {
21
+ }
22
+ if (contentType!.includes('text/plain')) {
20
23
  return await response.text();
21
24
  }
22
- } catch (e) {}
25
+ } catch (e) {
26
+ logger.error(`HTTP Client error for ${url}: ${e}`);
27
+ }
23
28
  }
24
29
 
25
30
  export async function microServiceHttpClient(
@@ -31,5 +36,5 @@ export async function microServiceHttpClient(
31
36
  const endpoint = serviceEndpointBuilder(service, path);
32
37
  const { getIdAuthorizationHeader } = CliAuthenticationClient();
33
38
  const authorizationHeader = await getIdAuthorizationHeader();
34
- return await httpClient(endpoint, method, data);
39
+ return await httpClient(endpoint, method, authorizationHeader, data);
35
40
  }
@@ -5,24 +5,24 @@ import { AAI_DIR } from 'alwaysai/lib/constants';
5
5
  import { ALWAYSAI_LOG_LEVEL, ALWAYSAI_LOG_TO_CONSOLE } from '../environment';
6
6
 
7
7
  const LOG_LEVEL = ALWAYSAI_LOG_LEVEL || 'info';
8
+
8
9
  const transports = ALWAYSAI_LOG_TO_CONSOLE
9
10
  ? [new winston.transports.Console({ level: LOG_LEVEL })]
10
11
  : [
11
12
  new winston.transports.DailyRotateFile({
12
13
  filename: path.join(AAI_DIR, 'agent-logs', 'agent-logs.txt'),
13
14
  maxSize: '5m',
14
- maxFiles: '2d',
15
- }),
15
+ maxFiles: '2d'
16
+ })
16
17
  ];
17
18
 
18
19
  export const logger = winston.createLogger({
19
20
  level: LOG_LEVEL,
20
21
  format: winston.format.combine(
22
+ winston.format.colorize(),
21
23
  winston.format.errors({ stack: true }),
22
24
  winston.format.splat(),
23
- winston.format.simple(),
25
+ winston.format.simple()
24
26
  ),
25
- transports,
27
+ transports
26
28
  });
27
-
28
- logger.info(`Initialized logger with log level: ${LOG_LEVEL}`);
@@ -1,7 +1,8 @@
1
+ // eslint-disable-next-line
1
2
  export async function runInDir<T extends any[], R extends any>(
2
3
  func: (...args: T) => R,
3
4
  args: T,
4
- dir: string,
5
+ dir: string
5
6
  ) {
6
7
  const origCwd = process.cwd();
7
8
  let out: R;
@@ -1,6 +0,0 @@
1
- import { Spawner } from "alwaysai/lib/util";
2
- export declare function getTargetHardwareUuid(spawner: Spawner): Promise<string>;
3
- export declare function writeCertificateAndToken(props: {
4
- deviceUuid: string;
5
- }): Promise<void>;
6
- //# sourceMappingURL=certificates-and-tokens.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"certificates-and-tokens.d.ts","sourceRoot":"","sources":["../../src/infrastructure/certificates-and-tokens.ts"],"names":[],"mappings":"AAUA,OAAO,EAEL,OAAO,EAGR,MAAM,mBAAmB,CAAC;AAI3B,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,OAAO,mBAW3D;AAGD,wBAAsB,wBAAwB,CAAC,KAAK,EAAE;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,iBAmB3E"}
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.writeCertificateAndToken = exports.getTargetHardwareUuid = void 0;
4
- const device_1 = require("alwaysai/lib/components/device");
5
- const user_1 = require("alwaysai/lib/components/user");
6
- const constants_1 = require("alwaysai/lib/constants");
7
- const project_1 = require("alwaysai/lib/core/project");
8
- const util_1 = require("alwaysai/lib/util");
9
- const logger_1 = require("../util/logger");
10
- // NOTE: This is reimplemented from the CLI to work for local checks
11
- async function getTargetHardwareUuid(spawner) {
12
- if (await spawner.exists("/var/lib/dbus/machine-id")) {
13
- return await spawner.run({
14
- exe: "cat",
15
- args: ["/var/lib/dbus/machine-id"],
16
- });
17
- }
18
- if (await spawner.exists("/etc/machine-id")) {
19
- return await spawner.run({ exe: "cat", args: ["/etc/machine-id"] });
20
- }
21
- return await spawner.run({ exe: "hostname" });
22
- }
23
- exports.getTargetHardwareUuid = getTargetHardwareUuid;
24
- // NOTE: This closely follows the flow of deviceCheckAndUpdateComponent in the CLI
25
- async function writeCertificateAndToken(props) {
26
- const { deviceUuid } = props;
27
- await (0, user_1.checkUserIsLoggedInComponent)({ yes: true });
28
- if (!(await (0, project_1.checkPaidPlan)())) {
29
- throw new Error(`This action only supported for Enterprise alwaysAI accounts!`);
30
- }
31
- const tokens = {
32
- deviceId: deviceUuid,
33
- accessToken: "",
34
- refreshToken: "",
35
- idToken: "",
36
- };
37
- const tokenSpawner = (0, util_1.JsSpawner)({ path: constants_1.LOCAL_AAI_CFG_DIR });
38
- await (0, util_1.writeTokens)({ spawner: tokenSpawner, tokens });
39
- await (0, device_1.writeOrUpdateDeviceCfgFile)({ spawner: tokenSpawner });
40
- logger_1.logger.info("Updated tokens and certificate");
41
- }
42
- exports.writeCertificateAndToken = writeCertificateAndToken;
43
- //# sourceMappingURL=certificates-and-tokens.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"certificates-and-tokens.js","sourceRoot":"","sources":["../../src/infrastructure/certificates-and-tokens.ts"],"names":[],"mappings":";;;AAAA,2DAGwC;AACxC,uDAA4E;AAC5E,sDAGgC;AAChC,uDAA0D;AAC1D,4CAK2B;AAC3B,2CAAwC;AAExC,oEAAoE;AAC7D,KAAK,UAAU,qBAAqB,CAAC,OAAgB;IAC1D,IAAI,MAAM,OAAO,CAAC,MAAM,CAAC,0BAA0B,CAAC,EAAE;QACpD,OAAO,MAAM,OAAO,CAAC,GAAG,CAAC;YACvB,GAAG,EAAE,KAAK;YACV,IAAI,EAAE,CAAC,0BAA0B,CAAC;SACnC,CAAC,CAAC;KACJ;IACD,IAAI,MAAM,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,EAAE;QAC3C,OAAO,MAAM,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC;KACrE;IACD,OAAO,MAAM,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,CAAC;AAChD,CAAC;AAXD,sDAWC;AAED,kFAAkF;AAC3E,KAAK,UAAU,wBAAwB,CAAC,KAA6B;IAC1E,MAAM,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;IAC7B,MAAM,IAAA,mCAA4B,EAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;IAClD,IAAI,CAAC,CAAC,MAAM,IAAA,uBAAa,GAAE,CAAC,EAAE;QAC5B,MAAM,IAAI,KAAK,CACb,8DAA8D,CAC/D,CAAC;KACH;IACD,MAAM,MAAM,GAAiB;QAC3B,QAAQ,EAAE,UAAU;QACpB,WAAW,EAAE,EAAE;QACf,YAAY,EAAE,EAAE;QAChB,OAAO,EAAE,EAAE;KACZ,CAAC;IACF,MAAM,YAAY,GAAG,IAAA,gBAAS,EAAC,EAAE,IAAI,EAAE,6BAAiB,EAAE,CAAC,CAAC;IAC5D,MAAM,IAAA,kBAAW,EAAC,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,CAAC;IACrD,MAAM,IAAA,mCAA0B,EAAC,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,CAAC;IAE5D,eAAM,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;AAChD,CAAC;AAnBD,4DAmBC"}
@@ -1,53 +0,0 @@
1
- import {
2
- DeviceTokens,
3
- writeOrUpdateDeviceCfgFile,
4
- } from "alwaysai/lib/components/device";
5
- import { checkUserIsLoggedInComponent } from "alwaysai/lib/components/user";
6
- import {
7
- LOCAL_AAI_CFG_DIR,
8
- LOCAL_CERT_AND_KEY_DIR,
9
- } from "alwaysai/lib/constants";
10
- import { checkPaidPlan } from "alwaysai/lib/core/project";
11
- import {
12
- JsSpawner,
13
- Spawner,
14
- writeCertificate,
15
- writeTokens,
16
- } from "alwaysai/lib/util";
17
- import { logger } from "../util/logger";
18
-
19
- // NOTE: This is reimplemented from the CLI to work for local checks
20
- export async function getTargetHardwareUuid(spawner: Spawner) {
21
- if (await spawner.exists("/var/lib/dbus/machine-id")) {
22
- return await spawner.run({
23
- exe: "cat",
24
- args: ["/var/lib/dbus/machine-id"],
25
- });
26
- }
27
- if (await spawner.exists("/etc/machine-id")) {
28
- return await spawner.run({ exe: "cat", args: ["/etc/machine-id"] });
29
- }
30
- return await spawner.run({ exe: "hostname" });
31
- }
32
-
33
- // NOTE: This closely follows the flow of deviceCheckAndUpdateComponent in the CLI
34
- export async function writeCertificateAndToken(props: { deviceUuid: string }) {
35
- const { deviceUuid } = props;
36
- await checkUserIsLoggedInComponent({ yes: true });
37
- if (!(await checkPaidPlan())) {
38
- throw new Error(
39
- `This action only supported for Enterprise alwaysAI accounts!`
40
- );
41
- }
42
- const tokens: DeviceTokens = {
43
- deviceId: deviceUuid,
44
- accessToken: "",
45
- refreshToken: "",
46
- idToken: "",
47
- };
48
- const tokenSpawner = JsSpawner({ path: LOCAL_AAI_CFG_DIR });
49
- await writeTokens({ spawner: tokenSpawner, tokens });
50
- await writeOrUpdateDeviceCfgFile({ spawner: tokenSpawner });
51
-
52
- logger.info("Updated tokens and certificate");
53
- }