@zohocorporation/vault-cli 1.1.2

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 (102) hide show
  1. package/README.md +16 -0
  2. package/out/commands/add/add.const.js +6 -0
  3. package/out/commands/add/add.types.js +2 -0
  4. package/out/commands/add/add.util.js +35 -0
  5. package/out/commands/download/download.const.js +6 -0
  6. package/out/commands/download/download.types.js +2 -0
  7. package/out/commands/download/download.utils.js +35 -0
  8. package/out/commands/generate-password/generate-password.const.js +12 -0
  9. package/out/commands/generate-password/generate-password.types.js +2 -0
  10. package/out/commands/generate-password/generate-password.utils.js +58 -0
  11. package/out/commands/generate-template/generate-template.const.js +7 -0
  12. package/out/commands/generate-template/generate-template.types.js +2 -0
  13. package/out/commands/generate-template/generate-template.util.js +37 -0
  14. package/out/commands/get/get.const.js +8 -0
  15. package/out/commands/get/get.types.js +2 -0
  16. package/out/commands/get/get.utils.js +45 -0
  17. package/out/commands/get-default/get-default.const.js +5 -0
  18. package/out/commands/get-default/get-default.types.js +2 -0
  19. package/out/commands/get-default/get-default.utils.js +33 -0
  20. package/out/commands/list/list.const.js +7 -0
  21. package/out/commands/list/list.types.js +2 -0
  22. package/out/commands/list/list.utils.js +43 -0
  23. package/out/commands/lock/lock.action.js +13 -0
  24. package/out/commands/lock/lock.js +10 -0
  25. package/out/commands/lock/lock.utils.js +52 -0
  26. package/out/commands/login/login.action.js +22 -0
  27. package/out/commands/login/login.const.js +10 -0
  28. package/out/commands/login/login.help.js +12 -0
  29. package/out/commands/login/login.js +17 -0
  30. package/out/commands/login/login.types.js +5 -0
  31. package/out/commands/login/login.utils.js +307 -0
  32. package/out/commands/reset/reset.action.js +28 -0
  33. package/out/commands/reset/reset.help.js +8 -0
  34. package/out/commands/reset/reset.js +14 -0
  35. package/out/commands/reset/reset.utils.js +2 -0
  36. package/out/commands/search/search.action.js +30 -0
  37. package/out/commands/search/search.constants.js +14 -0
  38. package/out/commands/search/search.help.js +6 -0
  39. package/out/commands/search/search.js +26 -0
  40. package/out/commands/search/search.types.js +16 -0
  41. package/out/commands/search/search.utils.js +61 -0
  42. package/out/commands/set-default/set-default.const.js +6 -0
  43. package/out/commands/set-default/set-default.types.js +2 -0
  44. package/out/commands/set-default/set-default.utils.js +39 -0
  45. package/out/commands/unlock/unlock.action.js +23 -0
  46. package/out/commands/unlock/unlock.help.js +2 -0
  47. package/out/commands/unlock/unlock.js +12 -0
  48. package/out/commands/unlock/unlock.type.js +2 -0
  49. package/out/commands/unlock/unlock.utils.js +133 -0
  50. package/out/js/I18n/index.js +80 -0
  51. package/out/js/I18n/resources/CLI_I18N_en.js +173 -0
  52. package/out/js/I18n/resources/CLI_I18N_es.js +3 -0
  53. package/out/js/I18n/resources/CLI_I18N_fr.js +3 -0
  54. package/out/js/I18n/resources/CLI_I18N_nl.js +3 -0
  55. package/out/js/I18n/resources/CLI_I18N_pt.js +3 -0
  56. package/out/js/I18n/resources/CLI_I18N_zh.js +3 -0
  57. package/out/js/crypto/aes.js +225 -0
  58. package/out/js/crypto/index.js +139 -0
  59. package/out/js/crypto/rsa.js +1945 -0
  60. package/out/js/crypto/zohovault.js +671 -0
  61. package/out/js/logger/index.js +10 -0
  62. package/out/old/Add.js +590 -0
  63. package/out/old/Default.js +209 -0
  64. package/out/old/Download.js +69 -0
  65. package/out/old/Generate.js +171 -0
  66. package/out/old/Get.js +225 -0
  67. package/out/old/List.js +197 -0
  68. package/out/old/Login.js +287 -0
  69. package/out/old/Logout.js +21 -0
  70. package/out/old/PasswordGenerator.js +718 -0
  71. package/out/old/PasswordPolicies.js +21 -0
  72. package/out/old/PasswordTypes.js +33 -0
  73. package/out/old/Update.js +682 -0
  74. package/out/old/cmd/addcmd.js +59 -0
  75. package/out/old/cmd/downloadcmd.js +76 -0
  76. package/out/old/cmd/generate-passwordcmd.js +127 -0
  77. package/out/old/cmd/generate-templatecmd.js +59 -0
  78. package/out/old/cmd/get-defaultcmd.js +48 -0
  79. package/out/old/cmd/getcmd.js +57 -0
  80. package/out/old/cmd/listcmd.js +54 -0
  81. package/out/old/cmd/logoutcmd.js +31 -0
  82. package/out/old/cmd/set-default.js +75 -0
  83. package/out/old/cmd/updatecmd.js +44 -0
  84. package/out/old/index.js +580 -0
  85. package/out/util/configuration.util.js +103 -0
  86. package/out/util/consts.util.js +97 -0
  87. package/out/util/dbutils/db.types.js +2 -0
  88. package/out/util/dbutils/db.utils.js +164 -0
  89. package/out/util/dbutils/dbtable.utils.js +19 -0
  90. package/out/util/dev.utils.js +14 -0
  91. package/out/util/encryptionutil/encryption.uitl.js +108 -0
  92. package/out/util/index.util.js +341 -0
  93. package/out/util/keyringutil/keyring.util.js +57 -0
  94. package/out/util/loader/loader.interface.js +2 -0
  95. package/out/util/loader/transfer.loader.js +28 -0
  96. package/out/util/login.util.js +352 -0
  97. package/out/util/passwordtypes.util.js +91 -0
  98. package/out/util/print.util.js +4 -0
  99. package/out/util/search.util.js +359 -0
  100. package/out/util/types.util.js +7 -0
  101. package/out/zv.js +41 -0
  102. package/package.json +96 -0
@@ -0,0 +1,341 @@
1
+ import os from "os";
2
+ import { DC, OS, SHARING } from "./consts.util.js";
3
+ import crypto from "crypto";
4
+ import { I18N } from "../js/I18n/index.js";
5
+ import axios from "axios";
6
+ import { Logger, LoggerShutdown } from "../js/logger/index.js";
7
+ import { writeFile } from "fs";
8
+ import chalk from "chalk";
9
+ import convert from "xml-js";
10
+ import { highlight } from "cli-highlight";
11
+ import YamlConverter from "js-yaml";
12
+ import Table from "cli-table3";
13
+ import { getCredentials, getDecryptedCredentials } from "./dbutils/db.utils.js";
14
+ import { generateWorkspaceHash } from "../commands/login/login.utils.js";
15
+ import { getConfig } from "./dev.utils.js";
16
+ import { MODE } from "./consts.util.js";
17
+ export const getOS = () => {
18
+ const choice = os.platform();
19
+ switch (choice) {
20
+ case "win32": return OS.WINDOWS;
21
+ case "darwin": return OS.MAC;
22
+ default: return OS.LINUX;
23
+ }
24
+ };
25
+ // export const isValidReadablePath = (path: string | undefined) => {
26
+ // return new Promise((resolve, _) => {
27
+ // if (!path || path === "") {
28
+ // resolve(false);
29
+ // }
30
+ // try {
31
+ // accessSync(path as string, constants.R_OK);
32
+ // resolve(true);
33
+ // } catch (err) {
34
+ // resolve(false);
35
+ // }
36
+ // })
37
+ // }
38
+ // export const isValidWritablePath = (path: string | undefined) => {
39
+ // return new Promise((resolve, _) => {
40
+ // if (!path || path === "") {
41
+ // resolve(false);
42
+ // }
43
+ // try {
44
+ // accessSync(path as string, constants.R_OK);
45
+ // resolve(true);
46
+ // } catch (err) {
47
+ // resolve(false);
48
+ // }
49
+ // })
50
+ // }
51
+ // export const isFileExist = (path: string) => {
52
+ // return new Promise((resolve, reject) => {
53
+ // try {
54
+ // if (existsSync(path)) {
55
+ // resolve(true);
56
+ // return;
57
+ // }
58
+ // resolve(false);
59
+ // } catch (err) {
60
+ // reject(new Error("Error while checking for file"));
61
+ // }
62
+ // })
63
+ // }
64
+ export const isMasterKeyExist = () => {
65
+ return new Promise(async (resolve, reject) => {
66
+ try {
67
+ const data = getCredentials(generateWorkspaceHash());
68
+ if (!data) {
69
+ resolve(false);
70
+ return;
71
+ }
72
+ const { hasmasterkey } = data;
73
+ if (!!hasmasterkey && hasmasterkey === "true") {
74
+ resolve(true);
75
+ return;
76
+ }
77
+ resolve(false);
78
+ }
79
+ catch (err) {
80
+ reject(new Error("Error while checking for master key"));
81
+ }
82
+ });
83
+ };
84
+ export const isConfigurationExist = () => {
85
+ return new Promise(async (resolve, reject) => {
86
+ try {
87
+ const data = getCredentials(generateWorkspaceHash());
88
+ resolve(!!data);
89
+ }
90
+ catch (err) {
91
+ resolve(false);
92
+ Logger.error(err);
93
+ // reject(new Error("Error while checking for configuration file"));
94
+ }
95
+ });
96
+ };
97
+ export const Utilities = {
98
+ getAccountsUrl: (dc) => {
99
+ const data = getConfig();
100
+ const { MODE: mode, ACCOUNTS_URL } = data;
101
+ if (mode === MODE.DEVELOPMENT) {
102
+ return ACCOUNTS_URL;
103
+ }
104
+ switch (dc) {
105
+ case DC.AU: return "https://accounts.zoho.com.au";
106
+ case DC.EU: return "https://accounts.zoho.eu";
107
+ case DC.IN: return "https://accounts.zoho.in";
108
+ case DC.CN: return "https://accounts.zoho.com.cn"; //No I18N
109
+ default: return "https://accounts.zoho.com";
110
+ }
111
+ },
112
+ sleep: (millis) => {
113
+ return new Promise(resolve => setTimeout(resolve, millis));
114
+ },
115
+ getVaultUrl: (dc) => {
116
+ const data = getConfig();
117
+ const { MODE: mode, VAULT_URL } = data;
118
+ if (mode === MODE.DEVELOPMENT) {
119
+ return VAULT_URL;
120
+ }
121
+ switch (dc) {
122
+ case DC.AU: return "https://vault.zoho.com.au";
123
+ case DC.EU: return "https://vault.zoho.eu";
124
+ case DC.IN: return "https://vault.zoho.in";
125
+ case DC.CN: return "https://vault.zoho.com.cn"; //No I18N
126
+ default: return "https://vault.zoho.com";
127
+ }
128
+ },
129
+ generateRandomToken: (n) => {
130
+ return crypto.randomBytes(n).toString("hex");
131
+ },
132
+ isTrusted: async () => {
133
+ const data = await getDecryptedCredentials(generateWorkspaceHash());
134
+ if (!data) {
135
+ return { status: false };
136
+ }
137
+ const { credentials: { masterkey } } = data;
138
+ if (masterkey === "" || masterkey.split(",").length !== 2) {
139
+ return { status: false };
140
+ }
141
+ return { status: true, masterKey: masterkey.split(",")[0] };
142
+ },
143
+ // isTrusted: () => {
144
+ // const prefix = ".";
145
+ // const masterKey = readFileSync(prefix + NAME.MASTER_KEY, "utf-8");
146
+ // if (masterKey === "" || masterKey.split(",").length !== 2) {
147
+ // return { status: false };
148
+ // } else {
149
+ // return { status: true, masterKey: masterKey.split(",")[0] };
150
+ // }
151
+ // },
152
+ writeToFile: (data, filename) => {
153
+ writeFile(filename, data, (err) => {
154
+ if (err !== null) {
155
+ Logger.error(err);
156
+ }
157
+ });
158
+ //fs.createWriteStream(filename).write(data, 'base64')
159
+ },
160
+ groupBy: (objectArray, property) => {
161
+ return objectArray.reduce((acc, obj) => {
162
+ const key = obj[property];
163
+ if (!acc.hasOwnProperty(key)) {
164
+ acc[key] = [];
165
+ }
166
+ acc[key]?.push(obj);
167
+ return acc;
168
+ }, {});
169
+ },
170
+ getSharingPrivilege: (level) => {
171
+ if (level === 10) {
172
+ return SHARING.MANAGE;
173
+ }
174
+ else if (level === 20) {
175
+ return SHARING.AUTOLOGIN;
176
+ }
177
+ else if (level === 30) {
178
+ return SHARING.VIEW;
179
+ }
180
+ else {
181
+ return SHARING.MODIFY;
182
+ }
183
+ },
184
+ // isConfigFolderExist: () => {
185
+ // try {
186
+ // const configFileName = readFileSync(NAME.CONFIGURATION_FILE_NAME);
187
+ // const folderExist = existsSync(configFileName);
188
+ // return folderExist;
189
+ // } catch (err) {
190
+ // return false;
191
+ // }
192
+ // },
193
+ isConfigured: () => {
194
+ try {
195
+ const data = getCredentials(generateWorkspaceHash());
196
+ if (!!data) {
197
+ return true;
198
+ }
199
+ }
200
+ catch (err) {
201
+ new Error("Error while checking for configuration file");
202
+ }
203
+ return false;
204
+ },
205
+ getHeader: (arr) => {
206
+ const header = new Set();
207
+ for (const item of arr) {
208
+ Object.keys(item).forEach(key => {
209
+ header.add(key);
210
+ });
211
+ }
212
+ return Array.from(header);
213
+ },
214
+ printTable: (secArr) => {
215
+ let head = Utilities.getHeader(secArr);
216
+ const colWidths = [];
217
+ for (let i = 0; i < head.length; i++) {
218
+ if (i == 0) {
219
+ colWidths.push(23);
220
+ }
221
+ else {
222
+ colWidths.push(20);
223
+ }
224
+ }
225
+ let table = new Table({
226
+ head,
227
+ style: { head: ['blue', 'bold'], border: ['grey'] },
228
+ colWidths,
229
+ wordWrap: true
230
+ });
231
+ secArr.forEach((secret) => {
232
+ const row = head.map(headerKey => secret[headerKey] || '');
233
+ table.push(row);
234
+ });
235
+ console.log(table.toString());
236
+ },
237
+ isValidOutFile: (fileName, output) => {
238
+ if (typeof fileName === 'boolean' || output === undefined || output === "" || fileName === undefined) {
239
+ return false;
240
+ }
241
+ const arr = fileName.split('.');
242
+ return arr.at(-1) === output;
243
+ },
244
+ printAsXML: (obj, outFile, output) => {
245
+ // Convert empty strings to empty text content to avoid self-closing tags
246
+ const processObj = (o) => {
247
+ if (typeof o === 'object' && o !== null) {
248
+ for (let key in o) {
249
+ if (o[key] === '') {
250
+ o[key] = { _text: '' };
251
+ }
252
+ else if (typeof o[key] === 'object' && o[key] !== null) {
253
+ processObj(o[key]);
254
+ }
255
+ }
256
+ }
257
+ return o;
258
+ };
259
+ const processedObj = processObj(JSON.parse(JSON.stringify(obj)));
260
+ let options = { compact: true, ignoreComment: true, spaces: 4, textKey: '_text' };
261
+ let result = convert.json2xml(JSON.stringify(processedObj), options);
262
+ if (Utilities.isValidOutFile(outFile, output)) {
263
+ Utilities.writeToFile(result, outFile);
264
+ console.log(chalk.green("File created and stored to location: " + outFile));
265
+ return;
266
+ }
267
+ console.log(highlight(result, { language: "xml", ignoreIllegals: true }));
268
+ },
269
+ printAsYAML: (obj, outFile, output) => {
270
+ const yamlOutPut = YamlConverter.dump(obj);
271
+ if (Utilities.isValidOutFile(outFile, output)) {
272
+ Utilities.writeToFile(yamlOutPut, outFile);
273
+ console.log(chalk.green("File created and stored to location: " + outFile));
274
+ return;
275
+ }
276
+ console.log(highlight(yamlOutPut, { language: "yaml", ignoreIllegals: true }));
277
+ },
278
+ printAsJSON: (obj, outFile, output) => {
279
+ if (Utilities.isValidOutFile(outFile, output)) {
280
+ Utilities.writeToFile(JSON.stringify(obj), outFile);
281
+ console.log(chalk.green("File created and stored to location: " + outFile));
282
+ return;
283
+ }
284
+ console.log(highlight(JSON.stringify(obj, null, 4), { language: "json", ignoreIllegals: true }));
285
+ }
286
+ };
287
+ export const _pull = (headers, URL, data, method) => {
288
+ const params = new URLSearchParams();
289
+ let i18nText = new I18N();
290
+ for (const key in data) {
291
+ params.append(key, data[key]);
292
+ }
293
+ switch (method) {
294
+ case "POST":
295
+ return axios.post(URL, params, { headers })
296
+ .catch(function (e) {
297
+ Logger.error(e);
298
+ LoggerShutdown(() => {
299
+ if (e.code === 'ENOTFOUND') {
300
+ console.log(i18nText.getI18nMsg("vault.error.checkConnectivity"));
301
+ }
302
+ else {
303
+ console.log(i18nText.getI18nMsg("vault.server.errorReaching"));
304
+ }
305
+ process.exit(1);
306
+ });
307
+ throw e;
308
+ });
309
+ case "PUT":
310
+ return axios.put(URL, params, { headers })
311
+ .catch(function (e) {
312
+ Logger.error(e);
313
+ LoggerShutdown(() => {
314
+ if (e.code === 'ENOTFOUND') {
315
+ console.log(i18nText.getI18nMsg("vault.error.checkConnectivity"));
316
+ }
317
+ else {
318
+ console.log(i18nText.getI18nMsg("vault.server.errorReaching"));
319
+ }
320
+ process.exit(1);
321
+ });
322
+ throw e;
323
+ });
324
+ default:
325
+ return axios.get(URL, { headers, params: params })
326
+ .catch(function (e) {
327
+ Logger.error(e);
328
+ LoggerShutdown(() => {
329
+ if (e.code === 'ENOTFOUND') {
330
+ console.log(i18nText.getI18nMsg("vault.error.checkConnectivity"));
331
+ }
332
+ else {
333
+ console.log(i18nText.getI18nMsg("vault.server.errorReaching"));
334
+ }
335
+ process.exit(1);
336
+ });
337
+ throw e;
338
+ });
339
+ }
340
+ };
341
+ //# sourceMappingURL=index.util.js.map
@@ -0,0 +1,57 @@
1
+ import { Entry } from "@napi-rs/keyring";
2
+ import { Logger } from "../../js/logger/index.js";
3
+ export const writeToKeyring = (data, attr, value) => {
4
+ return new Promise((resolve, reject) => {
5
+ try {
6
+ const entry = new Entry(attr, value);
7
+ try {
8
+ entry.deletePassword();
9
+ }
10
+ catch (deleteErr) {
11
+ Logger.error("Failed to delete existing keyring entry:", deleteErr);
12
+ }
13
+ entry.setPassword(data);
14
+ resolve(true);
15
+ }
16
+ catch (err) {
17
+ Logger.error(err);
18
+ reject(false);
19
+ }
20
+ });
21
+ };
22
+ export const readFromKeyring = (attr, value) => {
23
+ return new Promise((resolve, reject) => {
24
+ try {
25
+ const keys = process.env.zv_keys;
26
+ if (!!keys) {
27
+ resolve(keys);
28
+ return;
29
+ }
30
+ const entry = new Entry(attr, value);
31
+ const data = entry.getPassword();
32
+ if (!!data) {
33
+ process.env.zv_keys = data;
34
+ }
35
+ resolve(data);
36
+ }
37
+ catch (err) {
38
+ Logger.error(err);
39
+ reject(new Error("Failed to read from keyring"));
40
+ }
41
+ });
42
+ };
43
+ export const deleteFromKeyring = (attr, value) => {
44
+ return new Promise((reslove, reject) => {
45
+ try {
46
+ const entry = new Entry(attr, value);
47
+ entry.deletePassword();
48
+ delete process.env.zv_keys;
49
+ reslove(true);
50
+ }
51
+ catch (err) {
52
+ Logger.error(err);
53
+ reject(new Error("Cannot delete from keyring"));
54
+ }
55
+ });
56
+ };
57
+ //# sourceMappingURL=keyring.util.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=loader.interface.js.map
@@ -0,0 +1,28 @@
1
+ export class TransferLoader {
2
+ #loaderRef = null;
3
+ load() {
4
+ const spinner = {
5
+ "interval": 100,
6
+ "frames": [
7
+ " | ",
8
+ " / ",
9
+ " — ",
10
+ " \\ ",
11
+ ]
12
+ };
13
+ let frameIdx = 0;
14
+ const res = setInterval(() => {
15
+ process.stdout.write(`\r${spinner.frames[frameIdx]}`);
16
+ frameIdx = (frameIdx + 1) % spinner.frames.length;
17
+ }, spinner.interval);
18
+ this.#loaderRef = res;
19
+ }
20
+ stop() {
21
+ const loaderRef = this.#loaderRef;
22
+ if (loaderRef) {
23
+ clearInterval(loaderRef);
24
+ }
25
+ console.log("\n");
26
+ }
27
+ }
28
+ //# sourceMappingURL=transfer.loader.js.map