@wiztivi/dana-cli 0.0.14 → 0.0.16

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 (96) hide show
  1. package/README.md +4 -0
  2. package/bin/dana.js +1 -1
  3. package/dana_completion.sh +2 -0
  4. package/dist/bundle.min.js +2 -0
  5. package/dist/commands/addComponent/config/ComponentConfig.d.ts +1 -1
  6. package/dist/commands/addComponent/const/defaultConfig.d.ts +1 -1
  7. package/dist/commands/addComponent/const/navigationConst.d.ts +1 -1
  8. package/dist/commands/addComponent/createComponent.d.ts +1 -1
  9. package/dist/commands/addComponent/helper/ComponentHelper.d.ts +1 -1
  10. package/dist/commands/addDevice/deviceConfig/configTypes.d.ts +0 -9
  11. package/dist/commands/addDevice/deviceConfig/webosConfig.d.ts +1 -29
  12. package/dist/commands/addModule/add-module.d.ts +2 -0
  13. package/dist/commands/addModule/addModuleDefinition.d.ts +3 -0
  14. package/dist/commands/addModule/moduleConst.d.ts +10 -0
  15. package/dist/commands/authentication/AuthenticationManager.d.ts +9 -10
  16. package/dist/commands/authentication/helper/CodeArtifactHelper.d.ts +1 -1
  17. package/dist/commands/authentication/helper/CredentialsHelper.d.ts +7 -0
  18. package/dist/commands/authentication/helper/SPM.d.ts +17 -0
  19. package/dist/commands/createApp/const/createAppTasks.d.ts +3 -0
  20. package/dist/commands/createApp/const/templateConst.d.ts +9 -0
  21. package/dist/commands/createApp/createApp.d.ts +4 -3
  22. package/dist/commands/createApp/helpers/CreateAppHelper.d.ts +10 -13
  23. package/dist/commands/createApp/helpers/SetupChecker.d.ts +1 -1
  24. package/dist/commands/hooks/checkDanaProjectHook.d.ts +2 -0
  25. package/dist/commands/package/package.d.ts +2 -0
  26. package/dist/commands/package/packageDefinition.d.ts +3 -0
  27. package/dist/common/const/exitCodeConst.d.ts +4 -0
  28. package/dist/common/helpers/CreateArchiveHelper.d.ts +1 -0
  29. package/dist/common/helpers/CreateFileHelper.d.ts +7 -1
  30. package/dist/common/helpers/InputValidator.d.ts +1 -1
  31. package/dist/common/helpers/InstallHelper.d.ts +1 -1
  32. package/dist/common/helpers/UpdateFileHelper.d.ts +10 -1
  33. package/dist/common/helpers/UserInputGetter.d.ts +1 -1
  34. package/dist/common/helpers/stringHelper.d.ts +1 -1
  35. package/dist/common/types/helperTypes.d.ts +3 -3
  36. package/package.json +24 -13
  37. package/dist/commands/addComponent/addMenu/add-menu.js +0 -45
  38. package/dist/commands/addComponent/addMenu/addMenuDefinition.js +0 -16
  39. package/dist/commands/addComponent/addRail/add-rail.js +0 -42
  40. package/dist/commands/addComponent/addRail/addRailDefinition.js +0 -26
  41. package/dist/commands/addComponent/addScreen/add-screen.js +0 -33
  42. package/dist/commands/addComponent/addScreen/addScreenDefinition.js +0 -13
  43. package/dist/commands/addComponent/addScrollView/add-scrollView.js +0 -31
  44. package/dist/commands/addComponent/addScrollView/addScrollViewDefinition.js +0 -13
  45. package/dist/commands/addComponent/config/ComponentConfig.js +0 -140
  46. package/dist/commands/addComponent/config/componentTypes.js +0 -1
  47. package/dist/commands/addComponent/const/componentConst.js +0 -19
  48. package/dist/commands/addComponent/const/defaultConfig.js +0 -24
  49. package/dist/commands/addComponent/const/navigationConst.js +0 -30
  50. package/dist/commands/addComponent/createComponent.js +0 -41
  51. package/dist/commands/addComponent/helper/ComponentHelper.js +0 -77
  52. package/dist/commands/addDevice/add-device.js +0 -90
  53. package/dist/commands/addDevice/addDeviceDefinition.js +0 -11
  54. package/dist/commands/addDevice/deviceConfig/androidtvConfig.js +0 -116
  55. package/dist/commands/addDevice/deviceConfig/configTypes.js +0 -12
  56. package/dist/commands/addDevice/deviceConfig/deviceConfig.js +0 -33
  57. package/dist/commands/addDevice/deviceConfig/titanosConfig.js +0 -14
  58. package/dist/commands/addDevice/deviceConfig/tizenConfig.js +0 -51
  59. package/dist/commands/addDevice/deviceConfig/tvosConfig.js +0 -45
  60. package/dist/commands/addDevice/deviceConfig/vidaaConfig.js +0 -14
  61. package/dist/commands/addDevice/deviceConfig/webosConfig.js +0 -140
  62. package/dist/commands/addDevice/helper/addDeviceHelper.js +0 -88
  63. package/dist/commands/authentication/AuthenticationManager.js +0 -167
  64. package/dist/commands/authentication/authDefinition.js +0 -35
  65. package/dist/commands/authentication/authHook.js +0 -32
  66. package/dist/commands/authentication/authentConst.js +0 -6
  67. package/dist/commands/authentication/commands/get-packages-token.js +0 -30
  68. package/dist/commands/authentication/commands/login.js +0 -28
  69. package/dist/commands/authentication/commands/logout.js +0 -20
  70. package/dist/commands/authentication/commands/status.js +0 -36
  71. package/dist/commands/authentication/helper/CodeArtifactHelper.js +0 -46
  72. package/dist/commands/authentication/helper/CommandHelper.js +0 -8
  73. package/dist/commands/authentication/helper/CredentialsHelper.js +0 -80
  74. package/dist/commands/commandHelp/customHelp.js +0 -26
  75. package/dist/commands/completion/completion.js +0 -48
  76. package/dist/commands/completion/completionDefinition.js +0 -12
  77. package/dist/commands/createApp/const/setupConst.js +0 -14
  78. package/dist/commands/createApp/createApp.js +0 -92
  79. package/dist/commands/createApp/createAppDefinition.js +0 -17
  80. package/dist/commands/createApp/helpers/CreateAppHelper.js +0 -114
  81. package/dist/commands/createApp/helpers/SetupChecker.js +0 -90
  82. package/dist/common/commonConst.js +0 -1
  83. package/dist/common/const/deviceConst.js +0 -71
  84. package/dist/common/const/exitCodeConst.js +0 -8
  85. package/dist/common/helpers/CreateFileHelper.js +0 -95
  86. package/dist/common/helpers/InputValidator.js +0 -52
  87. package/dist/common/helpers/InstallHelper.js +0 -145
  88. package/dist/common/helpers/UpdateFileHelper.js +0 -140
  89. package/dist/common/helpers/UserInputGetter.js +0 -118
  90. package/dist/common/helpers/handlebarsHelper.js +0 -21
  91. package/dist/common/helpers/stringHelper.js +0 -18
  92. package/dist/common/translation/en.json +0 -68
  93. package/dist/common/translation/translation.js +0 -3
  94. package/dist/common/types/helperTypes.js +0 -12
  95. package/dist/index.js +0 -14
  96. package/dist/program.js +0 -37
@@ -1,88 +0,0 @@
1
- import { execSync } from "node:child_process";
2
- import { readFileSync } from "node:fs";
3
- import path from "node:path";
4
- import * as prompts from "@clack/prompts";
5
- import { DEFAULT_IMAGE_URL } from "../../createApp/const/setupConst.js";
6
- import ComponentHelper from "../../addComponent/helper/ComponentHelper.js";
7
- import { CredentialsHelper } from "../../authentication/helper/CredentialsHelper.js";
8
- import { createCodeArtifactClient } from "../../authentication/helper/CodeArtifactHelper.js";
9
- import { ListPackageVersionsCommand } from "@aws-sdk/client-codeartifact";
10
- import { DOMAIN, DOMAIN_OWNER } from "../../authentication/authentConst.js";
11
- import translation from "../../../common/translation/translation.js";
12
- import { maxSatisfying } from "semver";
13
- const AddDeviceHelper = class {
14
- /**
15
- * clean on error
16
- */
17
- static cleanOnError = () => {
18
- try {
19
- execSync(`git clean -d -f && git reset --hard head`);
20
- }
21
- catch {
22
- throw new Error("Files deletion failed. Delete changes manually.");
23
- }
24
- return "Changes successfully deleted.";
25
- };
26
- /**
27
- * Get installed devices from script list in package.json
28
- * We use script so we can get renderers for smartTv
29
- */
30
- static getInstalledDevices = (directory) => {
31
- const filepath = path.join(directory, "package.json");
32
- const jsonData = JSON.parse(readFileSync(filepath).toString());
33
- const installedDevices = [];
34
- for (const t of Object.keys(jsonData.scripts)) {
35
- if (t.includes("start:")) {
36
- const device = t.split(":")[1];
37
- installedDevices.push(device);
38
- }
39
- }
40
- return installedDevices;
41
- };
42
- /**
43
- * Get the app icon url
44
- */
45
- static getAppIcon = () => {
46
- return Promise.resolve(DEFAULT_IMAGE_URL);
47
- };
48
- static promptTextFactory = async ({ errorMessage, promptMessage, validationFunction, placeholder, initialValue, }) => {
49
- const result = (await prompts.text({
50
- message: promptMessage,
51
- placeholder,
52
- initialValue,
53
- validate: (value) => validationFunction(value, errorMessage),
54
- }));
55
- ComponentHelper.handleCancellation(result);
56
- return result;
57
- };
58
- static getLatestPackageVersion = async ({ packageName, repository, format, namespace, }) => {
59
- let packageVersion;
60
- try {
61
- const credentials = CredentialsHelper.get();
62
- const client = createCodeArtifactClient(credentials.aws);
63
- const command = new ListPackageVersionsCommand({
64
- package: packageName,
65
- domain: DOMAIN,
66
- domainOwner: DOMAIN_OWNER,
67
- repository,
68
- format,
69
- namespace,
70
- });
71
- const response = await client.send(command);
72
- const versionListArray = response.versions?.map((v) => v.version).filter(Boolean);
73
- // need to use semver-ts to avoid this error
74
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
75
- packageVersion = maxSatisfying(versionListArray, "*");
76
- if (packageVersion) {
77
- return packageVersion;
78
- }
79
- else {
80
- throw new Error(translation["command.device.version.error"]);
81
- }
82
- }
83
- catch (error) {
84
- throw new Error(error.message ?? translation["error.common.start.message"]);
85
- }
86
- };
87
- };
88
- export default AddDeviceHelper;
@@ -1,167 +0,0 @@
1
- import getPort from "get-port";
2
- import express from "express";
3
- import { CredentialsHelper } from "./helper/CredentialsHelper.js";
4
- import { log } from "@clack/prompts";
5
- import translation from "../../common/translation/translation.js";
6
- import open from "open";
7
- import jwt from "jsonwebtoken";
8
- import { createCodeArtifactClient, formatRepositoryString, getRepositoryEndpoint, } from "./helper/CodeArtifactHelper.js";
9
- import { GetAuthorizationTokenCommand } from "@aws-sdk/client-codeartifact";
10
- import { DOMAIN, DOMAIN_OWNER, DEFAULT_PORT_1, DEFAULT_PORT_2 } from "./authentConst.js";
11
- import { execSync } from "node:child_process";
12
- import fs from "node:fs";
13
- import path from "node:path";
14
- export class AuthenticationManager {
15
- static getAPIURL(organization) {
16
- return `https://api.${organization}.dana-framework.com`; // Or http://localhost:3001
17
- }
18
- static async login(organization, isRemote, userPort) {
19
- const app = express();
20
- app.disable("x-powered-by");
21
- const promise = new Promise((resolve, reject) => {
22
- const timeout = setTimeout(() => {
23
- reject(new Error("Login timed out."));
24
- }, 5 * 60 * 1000);
25
- app.get("/callback", (req, res) => {
26
- clearTimeout(timeout);
27
- try {
28
- if (req.query.error) {
29
- res.send("Login failed. Check the CLI for details.");
30
- return reject(new Error(req.query.error));
31
- }
32
- const token = JSON.parse(req.query.token);
33
- const awsCredentials = JSON.parse(req.query.aws);
34
- const creds = { aws: awsCredentials, dana: token, org: organization, isRemote, port: userPort };
35
- res.send("Login successful! You can close this window.");
36
- CredentialsHelper.store(creds, isRemote, userPort);
37
- resolve(creds);
38
- }
39
- catch (err) {
40
- res.send("Login failed. Check the CLI for details.");
41
- reject(err);
42
- }
43
- });
44
- });
45
- const defaultPortList = [DEFAULT_PORT_1, DEFAULT_PORT_2];
46
- const portList = userPort ? [userPort].concat(defaultPortList) : defaultPortList;
47
- const port = await getPort({ port: portList });
48
- const server = app.listen(port);
49
- if (isRemote) {
50
- log.info(translation["command.auth.remoteMode"] + `Port: ${port}`);
51
- log.info(translation["command.auth.accessBrowserUrl"] +
52
- ` ${AuthenticationManager.getAPIURL(organization)}/login?port=${port}`);
53
- }
54
- else {
55
- await open(`${AuthenticationManager.getAPIURL(organization)}/login?port=${port}`);
56
- }
57
- return promise.finally(() => {
58
- server.closeAllConnections();
59
- server.close();
60
- });
61
- }
62
- static async logout(organization, creds, isRemote) {
63
- const url = new URL(`${AuthenticationManager.getAPIURL(organization)}/logout`);
64
- if (creds?.id_token) {
65
- url.searchParams.append("id_token", creds.id_token);
66
- }
67
- if (creds?.refresh_token) {
68
- url.searchParams.append("refresh_token", creds.refresh_token);
69
- }
70
- if (isRemote) {
71
- log.info(translation["command.auth.remoteMode"]);
72
- log.info(translation["command.auth.accessBrowserUrl"] + `${url.toString()}`);
73
- }
74
- else {
75
- await open(url.toString());
76
- }
77
- CredentialsHelper.delete(organization);
78
- }
79
- static async refresh(organization, token, isRemote, port) {
80
- const data = await fetch(`${AuthenticationManager.getAPIURL(organization)}/login?refresh_token=${token}`);
81
- if (!data.ok) {
82
- return AuthenticationManager.login(organization, isRemote, port);
83
- }
84
- const refreshedCreds = (await data.json());
85
- const creds = {
86
- aws: refreshedCreds.aws,
87
- dana: {
88
- ...refreshedCreds.token,
89
- refresh_token: token,
90
- },
91
- org: organization,
92
- };
93
- CredentialsHelper.store(creds, isRemote, port);
94
- return creds;
95
- }
96
- static isTokenExpired(token) {
97
- const payload = jwt.decode(token);
98
- if (!payload.exp) {
99
- return true;
100
- }
101
- const expirationDate = new Date(payload.exp * 1000);
102
- return expirationDate <= new Date();
103
- }
104
- static async loginNPM(organization, credentials) {
105
- // Create CodeArtifact client with credentials
106
- const client = createCodeArtifactClient(credentials);
107
- // Get authorization token
108
- const tokenCommand = new GetAuthorizationTokenCommand({
109
- domain: DOMAIN,
110
- domainOwner: DOMAIN_OWNER,
111
- });
112
- const { authorizationToken, expiration } = await client.send(tokenCommand);
113
- if (!authorizationToken) {
114
- throw new Error("Authorization token not found");
115
- }
116
- // Get repository endpoint
117
- const repositoryEndpoint = await getRepositoryEndpoint({ organization, credentials, client, format: "npm" });
118
- // Configure npm with the repository and token
119
- execSync(`npm config set @dana:registry=${repositoryEndpoint}`);
120
- execSync(`npm config set //${repositoryEndpoint.replace(/^https?:\/\//, "")}:_authToken=${authorizationToken}`);
121
- return {
122
- token: authorizationToken,
123
- expiration,
124
- };
125
- }
126
- static async loginGradle(organization, credentials) {
127
- const client = createCodeArtifactClient(credentials);
128
- const tokenCommand = new GetAuthorizationTokenCommand({
129
- domain: DOMAIN,
130
- domainOwner: DOMAIN_OWNER,
131
- });
132
- const { authorizationToken, expiration } = await client.send(tokenCommand);
133
- if (!authorizationToken) {
134
- throw new Error("Authorization token not found");
135
- }
136
- const repository = formatRepositoryString(organization);
137
- if (!fs.existsSync(path.join(process.env.HOME, ".gradle"))) {
138
- fs.mkdirSync(path.join(process.env.HOME, ".gradle"));
139
- }
140
- const gradlePropertiesFilePath = path.join(process.env.HOME, ".gradle", "gradle.properties");
141
- const gradlePropertiesFile = fs.existsSync(gradlePropertiesFilePath)
142
- ? fs.readFileSync(gradlePropertiesFilePath, { encoding: "utf-8" })
143
- : "";
144
- const key = `dana.${repository}.token`;
145
- let replaced = false;
146
- let lastEmptyLine = 0;
147
- const lines = gradlePropertiesFile.split("\n").reduce((lines, line, index) => {
148
- if (line.startsWith(key + "=")) {
149
- line = `${key}=${authorizationToken}`;
150
- replaced = true;
151
- }
152
- else if (line === "" && index > lastEmptyLine) {
153
- lastEmptyLine = index;
154
- }
155
- lines.push(line);
156
- return lines;
157
- }, []);
158
- if (!replaced) {
159
- lines.splice(lastEmptyLine, 0, `${key}=${authorizationToken}`);
160
- }
161
- fs.writeFileSync(gradlePropertiesFilePath, lines.join("\n"));
162
- return {
163
- token: authorizationToken,
164
- expiration,
165
- };
166
- }
167
- }
@@ -1,35 +0,0 @@
1
- import { Command, Option } from "commander";
2
- import translation from "../../common/translation/translation.js";
3
- import login from "./commands/login.js";
4
- import { statusAction } from "./commands/status.js";
5
- import logout from "./commands/logout.js";
6
- import { getPackagesToken } from "./commands/get-packages-token.js";
7
- import { authHook } from "./authHook.js";
8
- const addAuthDefinition = () => {
9
- const command = new Command("auth").description(translation["command.auth.description"]);
10
- const loginCmd = new Command("login")
11
- .description(translation["command.auth.login.description"])
12
- .option("-o, --org <organization>", translation["command.auth.login.option.org"])
13
- .option("-r, --remote", translation["command.auth.login.option.remote"])
14
- .option("-p, --port <port>", translation["command.auth.login.option.port"])
15
- .action(login);
16
- command.addCommand(loginCmd);
17
- const logoutCmd = new Command("logout")
18
- .description(translation["command.auth.logout.description"])
19
- .option("-o, --org <organization>", translation["command.auth.login.option.org"])
20
- .action(logout);
21
- command.addCommand(logoutCmd);
22
- const statusCmd = new Command("status")
23
- .description(translation["command.auth.status.description"])
24
- .action(statusAction);
25
- command.addCommand(statusCmd);
26
- const getPackagesTokenCmd = new Command("get-packages-token")
27
- .description(translation["command.auth.get-packages-token.description"])
28
- .addOption(new Option("-t, --target <target>", "Packages target").makeOptionMandatory(true).choices(["android"]))
29
- .option("-o, --org <organization>", translation["command.auth.login.option.org"])
30
- .hook("preAction", authHook)
31
- .action(getPackagesToken);
32
- command.addCommand(getPackagesTokenCmd);
33
- return command;
34
- };
35
- export default addAuthDefinition;
@@ -1,32 +0,0 @@
1
- /*
2
- * Copyright (c) 2014-2025 Wiztivi - contact@wiztivi.com
3
- * All Rights Reserved
4
- *
5
- * All information contained herein is proprietary and confidential.
6
- * Dissemination of this information or reproduction of this file or material, via any medium is strictly forbidden unless
7
- * prior written permission is obtained from Wiztivi.
8
- * No warranty, explicit or implicit, provided.
9
- * This software MAY NOT be used, modified or rewritten without prior written permission from Wiztivi.
10
- *
11
- */
12
- import * as prompts from "@clack/prompts";
13
- import { CredentialsHelper } from "./helper/CredentialsHelper.js";
14
- import { AuthenticationManager } from "./AuthenticationManager.js";
15
- import { LOGIN_ERROR } from "../../common/const/exitCodeConst.js";
16
- export const authHook = async () => {
17
- const credentials = CredentialsHelper.get();
18
- try {
19
- if (!credentials.dana?.id_token || !credentials.dana?.refresh_token) {
20
- await AuthenticationManager.login(credentials.org, credentials.isRemote, credentials?.port);
21
- return;
22
- }
23
- if (AuthenticationManager.isTokenExpired(credentials.dana.id_token) ||
24
- (credentials.aws && new Date(credentials.aws.expiration) < new Date())) {
25
- await AuthenticationManager.refresh(credentials.org, credentials.dana.refresh_token, credentials.isRemote, credentials?.port);
26
- }
27
- }
28
- catch (error) {
29
- prompts.log.error(error.message);
30
- process.exit(LOGIN_ERROR);
31
- }
32
- };
@@ -1,6 +0,0 @@
1
- export const DOMAIN = "dana";
2
- export const DOMAIN_OWNER = "733912940672";
3
- export const REGION = "eu-central-1";
4
- export const DEFAULT_ORG = "public";
5
- export const DEFAULT_PORT_1 = 10032;
6
- export const DEFAULT_PORT_2 = 10064;
@@ -1,30 +0,0 @@
1
- import { CredentialsHelper } from "../helper/CredentialsHelper.js";
2
- import { createCodeArtifactClient } from "../helper/CodeArtifactHelper.js";
3
- import { GetAuthorizationTokenCommand } from "@aws-sdk/client-codeartifact";
4
- import * as prompts from "@clack/prompts";
5
- import { GET_PACKAGES_TOKEN_ERROR } from "../../../common/const/exitCodeConst.js";
6
- import { DOMAIN, DOMAIN_OWNER } from "../authentConst.js";
7
- const getAndroidToken = async (creds) => {
8
- const client = createCodeArtifactClient(creds);
9
- const command = new GetAuthorizationTokenCommand({
10
- domain: DOMAIN,
11
- domainOwner: DOMAIN_OWNER,
12
- });
13
- try {
14
- const result = await client.send(command);
15
- console.log(result.authorizationToken);
16
- }
17
- catch (error) {
18
- prompts.log.error(error.message);
19
- process.exit(GET_PACKAGES_TOKEN_ERROR);
20
- }
21
- };
22
- const getPackagesToken = async (options) => {
23
- const creds = CredentialsHelper.get(options.org);
24
- switch (options.target) {
25
- case "android":
26
- // authHook ensure credentials are valid
27
- return getAndroidToken(creds.aws);
28
- }
29
- };
30
- export { getPackagesToken };
@@ -1,28 +0,0 @@
1
- import * as prompts from "@clack/prompts";
2
- import colors from "picocolors";
3
- import { CredentialsHelper } from "../helper/CredentialsHelper.js";
4
- import { AuthenticationManager } from "../AuthenticationManager.js";
5
- import { handleError } from "../helper/CommandHelper.js";
6
- /*
7
- Login to DANA backend (with aws and cognito) and connect to npm codeartifact
8
- More info: https://github.com/wiztivi-rd/dana-cli/wiki/Login
9
- */
10
- const login = async ({ org, port, remote = false }) => {
11
- const credentials = CredentialsHelper.get(org);
12
- try {
13
- prompts.intro(`Login to organization ${credentials.org} ...`);
14
- const validCredentials = await AuthenticationManager.login(credentials.org, remote, port);
15
- prompts.outro(colors.green("✓") + ` Login successful`);
16
- const npmToken = await AuthenticationManager.loginNPM(credentials.org, validCredentials.aws);
17
- await AuthenticationManager.loginGradle(credentials.org, validCredentials.aws);
18
- let stepText = "Successfully logged in to npm repository.";
19
- if (npmToken.expiration) {
20
- stepText += `\nLogin expires in 12 hours at: ${npmToken.expiration.toLocaleString()}`;
21
- }
22
- prompts.log.step(stepText);
23
- }
24
- catch (error) {
25
- handleError(error);
26
- }
27
- };
28
- export default login;
@@ -1,20 +0,0 @@
1
- import * as prompts from "@clack/prompts";
2
- import colors from "picocolors";
3
- import { CredentialsHelper } from "../helper/CredentialsHelper.js";
4
- import { AuthenticationManager } from "../AuthenticationManager.js";
5
- import { handleError } from "../helper/CommandHelper.js";
6
- /*
7
- Logout from DANA backend
8
- */
9
- const logout = async ({ org }) => {
10
- const credentials = CredentialsHelper.get(org);
11
- try {
12
- prompts.intro(`Logout from ${credentials.org}...`);
13
- await AuthenticationManager.logout(credentials.org, credentials.dana, credentials.isRemote);
14
- prompts.outro(colors.green("✓") + ` Logout successful. You are now being logged out in your browser.`);
15
- }
16
- catch (error) {
17
- handleError(error);
18
- }
19
- };
20
- export default logout;
@@ -1,36 +0,0 @@
1
- import * as prompts from "@clack/prompts";
2
- import jwt from "jsonwebtoken";
3
- import colors from "picocolors";
4
- import { CredentialsHelper } from "../helper/CredentialsHelper.js";
5
- import translation from "../../../common/translation/translation.js";
6
- var LOGIN_STATUS;
7
- (function (LOGIN_STATUS) {
8
- LOGIN_STATUS[LOGIN_STATUS["LOGGED"] = 1] = "LOGGED";
9
- LOGIN_STATUS[LOGIN_STATUS["NOT_LOGGED"] = 2] = "NOT_LOGGED";
10
- LOGIN_STATUS[LOGIN_STATUS["TOKEN_EXPIRED"] = 3] = "TOKEN_EXPIRED";
11
- })(LOGIN_STATUS || (LOGIN_STATUS = {}));
12
- const status = () => {
13
- const credentials = CredentialsHelper.get();
14
- if (!credentials?.dana?.id_token) {
15
- prompts.log.error(`${translation["login.error.not_logged"]} ${translation["login.info.please_login"]}`);
16
- return LOGIN_STATUS.NOT_LOGGED;
17
- }
18
- const id_token = credentials.dana.id_token;
19
- const { given_name, family_name, email, exp } = jwt.decode(id_token);
20
- const expiration = exp && new Date(exp * 1000);
21
- if (expiration && new Date() > expiration) {
22
- prompts.log.error(`${translation["login.info.token_expired"]} ${translation["login.info.please_login"]}`);
23
- return LOGIN_STATUS.TOKEN_EXPIRED;
24
- }
25
- const expStr = expiration ? `\nToken expires on ${expiration.toUTCString()}` : "";
26
- prompts.log.success(`${translation["login.info.logged"]} ${colors.bold(credentials.org)}: ${colors.bold(given_name + " " + family_name)} (${email})${expStr}
27
- `);
28
- return LOGIN_STATUS.LOGGED;
29
- };
30
- /**
31
- * Sends void intentionally to be used a Commander acceptable command
32
- */
33
- const statusAction = () => {
34
- status();
35
- };
36
- export { LOGIN_STATUS, status, statusAction };
@@ -1,46 +0,0 @@
1
- /*
2
- * Copyright (c) 2014-2025 Wiztivi - contact@wiztivi.com
3
- * All Rights Reserved
4
- *
5
- * All information contained herein is proprietary and confidential.
6
- * Dissemination of this information or reproduction of this file or material, via any medium is strictly forbidden unless
7
- * prior written permission is obtained from Wiztivi.
8
- * No warranty, explicit or implicit, provided.
9
- * This software MAY NOT be used, modified or rewritten without prior written permission from Wiztivi.
10
- *
11
- */
12
- import { CodeartifactClient, GetRepositoryEndpointCommand } from "@aws-sdk/client-codeartifact";
13
- import { CredentialsHelper } from "./CredentialsHelper.js";
14
- import { DOMAIN, DOMAIN_OWNER, REGION } from "../authentConst.js";
15
- export const getRepositoryEndpoint = async ({ organization, credentials, client, format = "npm", }) => {
16
- const actualCredentials = credentials ?? CredentialsHelper.get()?.aws;
17
- if (!actualCredentials) {
18
- throw new Error("No valid credentials available.");
19
- }
20
- const actualClient = client ?? createCodeArtifactClient(actualCredentials);
21
- const repository = formatRepositoryString(organization);
22
- const endpointCommand = new GetRepositoryEndpointCommand({
23
- domain: DOMAIN,
24
- domainOwner: DOMAIN_OWNER,
25
- repository,
26
- format,
27
- });
28
- const { repositoryEndpoint } = await actualClient.send(endpointCommand);
29
- if (!repositoryEndpoint) {
30
- throw new Error("Repository endpoint not found");
31
- }
32
- return repositoryEndpoint;
33
- };
34
- export const createCodeArtifactClient = (credentials) => {
35
- return new CodeartifactClient({
36
- region: REGION,
37
- credentials: {
38
- accessKeyId: credentials.accessKeyId,
39
- secretAccessKey: credentials.secretAccessKey,
40
- sessionToken: credentials.sessionToken,
41
- },
42
- });
43
- };
44
- export const formatRepositoryString = (org) => {
45
- return `dana-${org}-repository`;
46
- };
@@ -1,8 +0,0 @@
1
- import * as prompts from "@clack/prompts";
2
- import colors from "picocolors";
3
- import translation from "../../../common/translation/translation.js";
4
- import { LOGIN_ERROR } from "../../../common/const/exitCodeConst.js";
5
- export const handleError = (error) => {
6
- prompts.outro(colors.red(error.message ?? translation["error.common.start.message"]));
7
- process.exit(LOGIN_ERROR);
8
- };
@@ -1,80 +0,0 @@
1
- import { existsSync, readFileSync, writeFileSync } from "node:fs";
2
- import { homedir } from "node:os";
3
- import path from "node:path";
4
- import { DEFAULT_ORG } from "../authentConst.js";
5
- export const CURRENT_DANA_JSON_VERSION = 2;
6
- export class CredentialsHelper {
7
- static filePath = path.join(homedir(), ".dana.json");
8
- static getConfig() {
9
- if (!existsSync(this.filePath)) {
10
- return null;
11
- }
12
- let config = JSON.parse(readFileSync(this.filePath, { encoding: "utf-8" }));
13
- const configVersion = config.version ?? 1;
14
- if (configVersion != CURRENT_DANA_JSON_VERSION) {
15
- config = CredentialsHelper.migrateConfig(config, configVersion);
16
- writeFileSync(this.filePath, JSON.stringify(config, null, 4));
17
- }
18
- return config;
19
- }
20
- static migrateConfig(config, from) {
21
- if (from === 1) {
22
- const v1 = config;
23
- return {
24
- lastUsedOrg: v1.org,
25
- credentials: {
26
- [v1.org]: {
27
- dana: v1.dana,
28
- aws: v1.aws,
29
- },
30
- },
31
- isRemote: false,
32
- version: CURRENT_DANA_JSON_VERSION,
33
- };
34
- }
35
- return config;
36
- }
37
- static store(credentials, isRemote, port) {
38
- let config = this.getConfig();
39
- config ??= {
40
- lastUsedOrg: credentials.org,
41
- credentials: {},
42
- version: CURRENT_DANA_JSON_VERSION,
43
- isRemote: false,
44
- };
45
- config.credentials ??= {};
46
- config.lastUsedOrg = credentials.org;
47
- if (port) {
48
- config.port = port;
49
- }
50
- config.isRemote = isRemote;
51
- config.credentials[credentials.org] = { aws: credentials.aws, dana: credentials.dana };
52
- writeFileSync(this.filePath, JSON.stringify(config, null, 4));
53
- }
54
- static get(org) {
55
- const config = this.getConfig();
56
- const organization = org ?? config?.lastUsedOrg ?? DEFAULT_ORG;
57
- const creds = {
58
- org: organization,
59
- isRemote: false,
60
- };
61
- if (config?.credentials?.[organization]?.aws) {
62
- creds.aws = config?.credentials[organization]?.aws;
63
- }
64
- if (config?.credentials?.[organization]?.dana) {
65
- creds.dana = config?.credentials[organization]?.dana;
66
- }
67
- if (config?.port) {
68
- creds.port = config.port;
69
- }
70
- creds.isRemote = !!config?.isRemote;
71
- return creds;
72
- }
73
- static delete(org) {
74
- const config = this.getConfig();
75
- if (config) {
76
- delete config.credentials[org];
77
- writeFileSync(this.filePath, JSON.stringify(config, null, 4));
78
- }
79
- }
80
- }
@@ -1,26 +0,0 @@
1
- import { PLATFORM_CONFIG } from "../../common/const/deviceConst.js";
2
- import translation from "../../common/translation/translation.js";
3
- const customHelp = (program) => {
4
- const commandList = " " +
5
- program.commands
6
- .map((cmd) => `${cmd.name()}: ${cmd.description()}`)
7
- .sort((a, b) => a.localeCompare(b))
8
- .join("\n ");
9
- const availableDevices = Object.values(PLATFORM_CONFIG)
10
- .map((el) => el.label)
11
- .sort((a, b) => a.localeCompare(b))
12
- .join(", ");
13
- return `
14
- DANA
15
- ===================
16
-
17
- ${translation["help.custom.commands"]}
18
- ${commandList}
19
-
20
-
21
- ${translation["help.custom.devices"]}
22
- ${availableDevices}
23
-
24
- `;
25
- };
26
- export default customHelp;
@@ -1,48 +0,0 @@
1
- /*
2
- * Copyright (c) 2014-2025 Wiztivi - contact@wiztivi.com
3
- * All Rights Reserved
4
- *
5
- * All information contained herein is proprietary and confidential.
6
- * Dissemination of this information or reproduction of this file or material, via any medium is strictly forbidden unless
7
- * prior written permission is obtained from Wiztivi.
8
- * No warranty, explicit or implicit, provided.
9
- * This software MAY NOT be used, modified or rewritten without prior written permission from Wiztivi.
10
- *
11
- */
12
- import { appendFileSync } from "node:fs";
13
- import path, { join } from "node:path";
14
- import { homedir } from "node:os";
15
- import translation from "../../common/translation/translation.js";
16
- import { COMMAND_ERROR } from "../../common/const/exitCodeConst.js";
17
- import * as prompts from "@clack/prompts";
18
- import colors from "picocolors";
19
- import { fileURLToPath } from "node:url";
20
- const BASH = "bash";
21
- const ZSH = "zsh";
22
- const completion = (shell) => {
23
- if (![BASH, ZSH].includes(shell)) {
24
- handleError(`Error: Shell must be either ${BASH} or ${ZSH}`);
25
- }
26
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
27
- const completionPath = join(__dirname, "../dana_completion.sh");
28
- const configFile = `.${shell}rc`;
29
- const configPath = join(homedir(), configFile);
30
- const headerString = `\n#${"=".repeat(25)}\n# Dana CLI completion`;
31
- const sourceString = `\nsource "${completionPath}"\n`;
32
- const sourceCommand = shell === ZSH
33
- ? `${headerString}\nautoload -U compinit\ncompinit ${sourceString}`
34
- : `${headerString}${sourceString}`;
35
- try {
36
- appendFileSync(configPath, sourceCommand);
37
- prompts.log.success(colors.green("✓") + translation["command.completion.success"] + ` ${configFile}`);
38
- prompts.log.info(`Run 'source ~/${configFile}' or restart your terminal`);
39
- }
40
- catch (error) {
41
- handleError(`Failed to install completion: ${error}`);
42
- }
43
- };
44
- const handleError = (message) => {
45
- prompts.log.error(message);
46
- process.exit(COMMAND_ERROR);
47
- };
48
- export default completion;