@signageos/cli 2.3.1 → 2.4.0

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 (146) hide show
  1. package/README.md +54 -19
  2. package/dist/Applet/Build/appletBuildCommand.js +28 -72
  3. package/dist/Applet/Generate/Templates/CHANGELOG.md.template +7 -0
  4. package/dist/Applet/Generate/Templates/README.md.template +3 -0
  5. package/dist/Applet/Generate/Templates/rspack.config.mjs.template +12 -12
  6. package/dist/Applet/Generate/appletGenerateCommand.d.ts +23 -62
  7. package/dist/Applet/Generate/appletGenerateCommand.js +432 -365
  8. package/dist/Applet/Start/appletStartCommand.js +70 -132
  9. package/dist/Applet/Test/Upload/appletTestRunCommand.js +90 -178
  10. package/dist/Applet/Test/Upload/appletTestRunFacade.js +5 -29
  11. package/dist/Applet/Test/Upload/appletTestUploadCommand.js +99 -224
  12. package/dist/Applet/Test/Upload/appletTestUploadFacade.js +51 -105
  13. package/dist/Applet/Test/appletTestCommand.js +6 -36
  14. package/dist/Applet/Upload/appletUploadCommand.js +199 -305
  15. package/dist/Applet/Upload/appletUploadCommandHelper.js +129 -144
  16. package/dist/Applet/Upload/appletUploadFacade.d.ts +2 -2
  17. package/dist/Applet/Upload/appletUploadFacade.js +184 -265
  18. package/dist/Applet/Upload/appletUploadFacadeHelper.js +51 -55
  19. package/dist/Applet/appletCommand.d.ts +25 -157
  20. package/dist/Applet/appletCommand.js +9 -39
  21. package/dist/Applet/appletErrors.js +5 -24
  22. package/dist/Applet/appletFacade.js +122 -147
  23. package/dist/Applet/appletServerHelper.js +18 -55
  24. package/dist/Auth/loginCommand.d.ts +2 -2
  25. package/dist/Auth/loginCommand.js +105 -136
  26. package/dist/Cache/tmpCache.js +47 -16
  27. package/dist/Cli/helper.js +3 -5
  28. package/dist/Cli/packageVersion.js +99 -131
  29. package/dist/Command/Autocomplete/Install/installAutocompleteCommand.d.ts +10 -0
  30. package/dist/Command/Autocomplete/Install/installAutocompleteCommand.js +39 -0
  31. package/dist/Command/Autocomplete/Install/installAutocompleteCommand.ts +30 -0
  32. package/dist/Command/Autocomplete/Install/sos-completion.sh +63 -0
  33. package/dist/Command/Autocomplete/Uninstall/uninstallAutocompleteCommand.d.ts +8 -0
  34. package/dist/Command/Autocomplete/Uninstall/uninstallAutocompleteCommand.js +120 -0
  35. package/dist/Command/Autocomplete/autocompleteCommand.d.ts +22 -0
  36. package/dist/Command/Autocomplete/autocompleteCommand.js +32 -0
  37. package/dist/Command/autoComplete.d.ts +4 -0
  38. package/dist/Command/autoComplete.js +184 -0
  39. package/dist/Command/commandDefinition.d.ts +9 -9
  40. package/dist/Command/commandDefinition.js +1 -3
  41. package/dist/Command/commandProcessor.js +41 -131
  42. package/dist/Command/globalArgs.js +9 -8
  43. package/dist/CommandLine/IProgressBar.js +0 -1
  44. package/dist/CommandLine/progressBarFactory.d.ts +1 -1
  45. package/dist/CommandLine/progressBarFactory.js +42 -13
  46. package/dist/CustomScript/Generate/customScriptGenerateCommand.js +17 -56
  47. package/dist/CustomScript/Generate/customScriptGenerateFacade.js +94 -109
  48. package/dist/CustomScript/Upload/customScriptUploadCommand.js +44 -120
  49. package/dist/CustomScript/customScriptCommand.d.ts +1 -9
  50. package/dist/CustomScript/customScriptCommand.js +6 -36
  51. package/dist/CustomScript/customScriptFacade.d.ts +2 -2
  52. package/dist/CustomScript/customScriptFacade.js +187 -297
  53. package/dist/Device/Connect/connectCommand.js +73 -137
  54. package/dist/Device/Content/setContentCommand.js +33 -78
  55. package/dist/Device/PowerAction/powerActionCommand.js +22 -65
  56. package/dist/Device/deviceCommand.js +7 -37
  57. package/dist/Device/deviceFacade.js +71 -127
  58. package/dist/Emulator/IEmulator.js +0 -1
  59. package/dist/Emulator/createDomain.d.ts +0 -1
  60. package/dist/Emulator/createDomain.js +44 -14
  61. package/dist/Emulator/emulatorFacade.js +75 -133
  62. package/dist/Emulator/emulatorFactory.js +123 -126
  63. package/dist/Firmware/Upload/firmwareUploadCommand.js +133 -221
  64. package/dist/Firmware/Upload/firmwareUploadFacade.js +75 -112
  65. package/dist/Firmware/Upload/firmwareUploadHelper.js +38 -6
  66. package/dist/Firmware/firmwareCommand.js +5 -35
  67. package/dist/Lib/archive.js +56 -62
  68. package/dist/Lib/childProcess.js +37 -5
  69. package/dist/Lib/fileSystem.js +76 -87
  70. package/dist/Lib/git.d.ts +1 -1
  71. package/dist/Lib/git.js +58 -87
  72. package/dist/Organization/Get/organizationGetCommand.js +14 -50
  73. package/dist/Organization/List/organizationListCommand.js +12 -46
  74. package/dist/Organization/SetDefault/organizationSetDefaultCommand.js +18 -56
  75. package/dist/Organization/organizationCommand.js +7 -37
  76. package/dist/Organization/organizationFacade.js +102 -177
  77. package/dist/RunControl/runControlHelper.js +14 -64
  78. package/dist/Timer/wait.js +2 -3
  79. package/dist/Timing/List/timingListCommand.js +20 -62
  80. package/dist/Timing/timingCommand.js +5 -35
  81. package/dist/generalCommand.js +1 -2
  82. package/dist/helper.d.ts +4 -4
  83. package/dist/helper.js +61 -122
  84. package/dist/index.js +19 -46
  85. package/dist/parameters.js +17 -40
  86. package/package.json +52 -57
  87. package/dist/Applet/Build/appletBuildCommand.js.map +0 -1
  88. package/dist/Applet/Generate/appletGenerateCommand.js.map +0 -1
  89. package/dist/Applet/Start/appletStartCommand.js.map +0 -1
  90. package/dist/Applet/Test/Upload/appletTestRunCommand.js.map +0 -1
  91. package/dist/Applet/Test/Upload/appletTestRunFacade.js.map +0 -1
  92. package/dist/Applet/Test/Upload/appletTestUploadCommand.js.map +0 -1
  93. package/dist/Applet/Test/Upload/appletTestUploadFacade.js.map +0 -1
  94. package/dist/Applet/Test/appletTestCommand.js.map +0 -1
  95. package/dist/Applet/Upload/appletUploadCommand.js.map +0 -1
  96. package/dist/Applet/Upload/appletUploadCommandHelper.js.map +0 -1
  97. package/dist/Applet/Upload/appletUploadFacade.js.map +0 -1
  98. package/dist/Applet/Upload/appletUploadFacadeHelper.js.map +0 -1
  99. package/dist/Applet/appletCommand.js.map +0 -1
  100. package/dist/Applet/appletErrors.js.map +0 -1
  101. package/dist/Applet/appletFacade.js.map +0 -1
  102. package/dist/Applet/appletServerHelper.js.map +0 -1
  103. package/dist/Auth/loginCommand.js.map +0 -1
  104. package/dist/Cache/tmpCache.js.map +0 -1
  105. package/dist/Cli/helper.js.map +0 -1
  106. package/dist/Cli/packageVersion.js.map +0 -1
  107. package/dist/Command/commandDefinition.js.map +0 -1
  108. package/dist/Command/commandProcessor.js.map +0 -1
  109. package/dist/Command/globalArgs.js.map +0 -1
  110. package/dist/CommandLine/IProgressBar.js.map +0 -1
  111. package/dist/CommandLine/progressBarFactory.js.map +0 -1
  112. package/dist/CustomScript/Generate/customScriptGenerateCommand.js.map +0 -1
  113. package/dist/CustomScript/Generate/customScriptGenerateFacade.js.map +0 -1
  114. package/dist/CustomScript/Upload/customScriptUploadCommand.js.map +0 -1
  115. package/dist/CustomScript/customScriptCommand.js.map +0 -1
  116. package/dist/CustomScript/customScriptFacade.js.map +0 -1
  117. package/dist/Device/Connect/connectCommand.js.map +0 -1
  118. package/dist/Device/Content/setContentCommand.js.map +0 -1
  119. package/dist/Device/PowerAction/powerActionCommand.js.map +0 -1
  120. package/dist/Device/deviceCommand.js.map +0 -1
  121. package/dist/Device/deviceFacade.js.map +0 -1
  122. package/dist/Emulator/IEmulator.js.map +0 -1
  123. package/dist/Emulator/createDomain.js.map +0 -1
  124. package/dist/Emulator/emulatorFacade.js.map +0 -1
  125. package/dist/Emulator/emulatorFactory.js.map +0 -1
  126. package/dist/Firmware/Upload/firmwareUploadCommand.js.map +0 -1
  127. package/dist/Firmware/Upload/firmwareUploadFacade.js.map +0 -1
  128. package/dist/Firmware/Upload/firmwareUploadHelper.js.map +0 -1
  129. package/dist/Firmware/firmwareCommand.js.map +0 -1
  130. package/dist/Lib/archive.js.map +0 -1
  131. package/dist/Lib/childProcess.js.map +0 -1
  132. package/dist/Lib/fileSystem.js.map +0 -1
  133. package/dist/Lib/git.js.map +0 -1
  134. package/dist/Organization/Get/organizationGetCommand.js.map +0 -1
  135. package/dist/Organization/List/organizationListCommand.js.map +0 -1
  136. package/dist/Organization/SetDefault/organizationSetDefaultCommand.js.map +0 -1
  137. package/dist/Organization/organizationCommand.js.map +0 -1
  138. package/dist/Organization/organizationFacade.js.map +0 -1
  139. package/dist/RunControl/runControlHelper.js.map +0 -1
  140. package/dist/Timer/wait.js.map +0 -1
  141. package/dist/Timing/List/timingListCommand.js.map +0 -1
  142. package/dist/Timing/timingCommand.js.map +0 -1
  143. package/dist/generalCommand.js.map +0 -1
  144. package/dist/helper.js.map +0 -1
  145. package/dist/index.js.map +0 -1
  146. package/dist/parameters.js.map +0 -1
@@ -8,37 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
11
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.killAppletServerIfRunningAndForceOption = exports.HOT_RELOAD_OPTION = exports.FORWARD_SERVER_URL_OPTION = exports.DETACH_PROCESS_OPTION = exports.SERVER_FORCE_OPTION = exports.SERVER_PORT_OPTION = exports.SERVER_PUBLIC_URL_OPTION = void 0;
40
- var log_1 = require("@signageos/sdk/dist/Console/log");
41
- var parameters_1 = require("../parameters");
12
+ exports.HOT_RELOAD_OPTION = exports.FORWARD_SERVER_URL_OPTION = exports.DETACH_PROCESS_OPTION = exports.SERVER_FORCE_OPTION = exports.SERVER_PORT_OPTION = exports.SERVER_PUBLIC_URL_OPTION = void 0;
13
+ exports.killAppletServerIfRunningAndForceOption = killAppletServerIfRunningAndForceOption;
14
+ const log_1 = require("@signageos/sdk/dist/Console/log");
15
+ const parameters_1 = require("../parameters");
42
16
  exports.SERVER_PUBLIC_URL_OPTION = {
43
17
  name: 'server-public-url',
44
18
  type: String,
@@ -69,34 +43,23 @@ exports.FORWARD_SERVER_URL_OPTION = {
69
43
  exports.HOT_RELOAD_OPTION = {
70
44
  name: 'hot-reload',
71
45
  type: Boolean,
72
- description: "Enable hot reload and build of applet",
46
+ description: `Enable hot reload and build of applet`,
73
47
  defaultValue: false,
74
48
  };
75
49
  function killAppletServerIfRunningAndForceOption(dev, options, appletUid, appletVersion, appletPort) {
76
- return __awaiter(this, void 0, void 0, function () {
77
- var force, runningAppletPort;
78
- return __generator(this, function (_a) {
79
- switch (_a.label) {
80
- case 0:
81
- if (!appletUid || !appletVersion) {
82
- return [2 /*return*/];
83
- }
84
- force = options[exports.SERVER_FORCE_OPTION.name];
85
- return [4 /*yield*/, dev.applet.serve.getRunningPort(appletUid, appletVersion)];
86
- case 1:
87
- runningAppletPort = _a.sent();
88
- if (!(runningAppletPort && runningAppletPort !== appletPort)) return [3 /*break*/, 4];
89
- if (!!force) return [3 /*break*/, 2];
90
- (0, log_1.log)('warning', "Applet server is already running on port ".concat(runningAppletPort, ". Use --force to kill the running server and start a new one."));
91
- return [3 /*break*/, 4];
92
- case 2: return [4 /*yield*/, dev.applet.serve.killRunningServer(appletUid, appletVersion)];
93
- case 3:
94
- _a.sent();
95
- _a.label = 4;
96
- case 4: return [2 /*return*/];
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ if (!appletUid || !appletVersion) {
52
+ return;
53
+ }
54
+ const force = options[exports.SERVER_FORCE_OPTION.name];
55
+ const runningAppletPort = yield dev.applet.serve.getRunningPort(appletUid, appletVersion);
56
+ if (runningAppletPort && runningAppletPort !== appletPort) {
57
+ if (!force) {
58
+ (0, log_1.log)('warning', `Applet server is already running on port ${runningAppletPort}. Use --force to kill the running server and start a new one.`);
97
59
  }
98
- });
60
+ else {
61
+ yield dev.applet.serve.killRunningServer(appletUid, appletVersion);
62
+ }
63
+ }
99
64
  });
100
65
  }
101
- exports.killAppletServerIfRunningAndForceOption = killAppletServerIfRunningAndForceOption;
102
- //# sourceMappingURL=appletServerHelper.js.map
@@ -14,8 +14,8 @@ declare const OPTION_LIST: readonly [{
14
14
  * Only one from auth0 and legacy authentication can be active at the moment
15
15
  */
16
16
  export declare const getIsAuth0OrLegacyEnabled: (options: any) => {
17
- isAuth0Enabled?: boolean | undefined;
18
- isLegacyEnabled?: boolean | undefined;
17
+ isAuth0Enabled?: boolean;
18
+ isLegacyEnabled?: boolean;
19
19
  };
20
20
  export declare const login: {
21
21
  name: "login";
@@ -1,15 +1,37 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
10
26
  };
11
- return __assign.apply(this, arguments);
12
- };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
13
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -19,48 +41,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19
41
  step((generator = generator.apply(thisArg, _arguments || [])).next());
20
42
  });
21
43
  };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
44
+ var __importDefault = (this && this.__importDefault) || function (mod) {
45
+ return (mod && mod.__esModule) ? mod : { "default": mod };
48
46
  };
49
47
  Object.defineProperty(exports, "__esModule", { value: true });
50
48
  exports.login = exports.getIsAuth0OrLegacyEnabled = void 0;
51
- var chalk_1 = require("chalk");
52
- var prompts = require("prompts");
53
- var Debug = require("debug");
54
- var os = require("os");
55
- var apiVersions_1 = require("@signageos/sdk/dist/RestApi/apiVersions");
56
- var log_1 = require("@signageos/sdk/dist/Console/log");
57
- var sosControlHelper_1 = require("@signageos/sdk/dist/SosHelper/sosControlHelper");
58
- var helper_1 = require("../helper");
59
- var runControlHelper_1 = require("../RunControl/runControlHelper");
60
- var parameters_1 = require("../parameters");
61
- var commandDefinition_1 = require("../Command/commandDefinition");
62
- var debug = Debug('@signageos/cli:Auth:login');
63
- var OPTION_LIST = [{ name: 'username', type: String, description: "Username or e-mail used for ".concat(parameters_1.parameters.boxHost) }];
49
+ const chalk_1 = __importDefault(require("chalk"));
50
+ const prompts_1 = __importDefault(require("prompts"));
51
+ const debug_1 = __importDefault(require("debug"));
52
+ const os = __importStar(require("os"));
53
+ const apiVersions_1 = require("@signageos/sdk/dist/RestApi/apiVersions");
54
+ const log_1 = require("@signageos/sdk/dist/Console/log");
55
+ const sosControlHelper_1 = require("@signageos/sdk/dist/SosHelper/sosControlHelper");
56
+ const helper_1 = require("../helper");
57
+ const runControlHelper_1 = require("../RunControl/runControlHelper");
58
+ const parameters_1 = require("../parameters");
59
+ const commandDefinition_1 = require("../Command/commandDefinition");
60
+ const Debug = (0, debug_1.default)('@signageos/cli:Auth:login');
61
+ const OPTION_LIST = [{ name: 'username', type: String, description: `Username or e-mail used for ${parameters_1.parameters.boxHost}` }];
64
62
  /**
65
63
  * To explicitly enable auth0 authentication add flag --auth0-enabled to command line options
66
64
  * { _unknown: [ '--auth0-enabled' ], command: [ 'login' ] }
@@ -70,9 +68,9 @@ var OPTION_LIST = [{ name: 'username', type: String, description: "Username or e
70
68
  *
71
69
  * Only one from auth0 and legacy authentication can be active at the moment
72
70
  */
73
- var getIsAuth0OrLegacyEnabled = function (options) {
71
+ const getIsAuth0OrLegacyEnabled = (options) => {
74
72
  var _a, _b;
75
- var queryParams = {};
73
+ const queryParams = {};
76
74
  if ((_a = options._unknown) === null || _a === void 0 ? void 0 : _a.includes('--auth0-enabled')) {
77
75
  queryParams.isAuth0Enabled = true;
78
76
  }
@@ -90,97 +88,68 @@ exports.login = (0, commandDefinition_1.createCommandDefinition)({
90
88
  description: 'Login account using username & password',
91
89
  optionList: OPTION_LIST,
92
90
  commands: [],
93
- run: function (options) {
94
- return __awaiter(this, void 0, void 0, function () {
95
- var identification, response, password, config, apiUrl, authQueryParams, _a, tokenId, apiSecurityToken, name;
96
- return __generator(this, function (_b) {
97
- switch (_b.label) {
98
- case 0:
99
- identification = options.username;
100
- if (!!identification) return [3 /*break*/, 2];
101
- return [4 /*yield*/, prompts({
102
- type: 'text',
103
- name: 'username',
104
- message: "Type your username or e-mail used for ".concat(parameters_1.parameters.boxHost),
105
- })];
106
- case 1:
107
- response = _b.sent();
108
- identification = response.username;
109
- _b.label = 2;
110
- case 2:
111
- if (!identification) {
112
- throw new Error('Missing argument --username <string>');
113
- }
114
- return [4 /*yield*/, prompts({
115
- type: 'password',
116
- name: 'password',
117
- message: "Type your password used for ".concat(parameters_1.parameters.boxHost),
118
- })];
119
- case 3:
120
- password = (_b.sent()).password;
121
- return [4 /*yield*/, (0, runControlHelper_1.loadConfig)()];
122
- case 4:
123
- config = _b.sent();
124
- apiUrl = (0, helper_1.getApiUrl)(config);
125
- authQueryParams = (0, exports.getIsAuth0OrLegacyEnabled)(options);
126
- return [4 /*yield*/, getOrCreateApiSecurityToken(__assign({ identification: identification, password: password, apiUrl: apiUrl }, authQueryParams))];
127
- case 5:
128
- _a = _b.sent(), tokenId = _a.id, apiSecurityToken = _a.securityToken, name = _a.name;
129
- return [4 /*yield*/, (0, runControlHelper_1.saveConfig)({
130
- apiUrl: apiUrl !== parameters_1.parameters.apiUrl ? apiUrl : undefined,
131
- identification: tokenId,
132
- apiSecurityToken: apiSecurityToken,
133
- })];
134
- case 6:
135
- _b.sent();
136
- (0, log_1.log)('info', "User ".concat(chalk_1.default.green(identification), " has been logged in with token \"").concat(name, "\". Credentials are stored in ").concat(chalk_1.default.blue((0, sosControlHelper_1.getConfigFilePath)())));
137
- return [2 /*return*/];
138
- }
91
+ run(options) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ let identification = options.username;
94
+ if (!identification) {
95
+ const response = yield (0, prompts_1.default)({
96
+ type: 'text',
97
+ name: 'username',
98
+ message: `Type your username or e-mail used for ${parameters_1.parameters.boxHost}`,
99
+ });
100
+ identification = response.username;
101
+ }
102
+ if (!identification) {
103
+ throw new Error('Missing argument --username <string>');
104
+ }
105
+ const { password } = yield (0, prompts_1.default)({
106
+ type: 'password',
107
+ name: 'password',
108
+ message: `Type your password used for ${parameters_1.parameters.boxHost}`,
109
+ });
110
+ const config = yield (0, runControlHelper_1.loadConfig)();
111
+ const apiUrl = (0, helper_1.getApiUrl)(config);
112
+ const authQueryParams = (0, exports.getIsAuth0OrLegacyEnabled)(options);
113
+ const { id: tokenId, securityToken: apiSecurityToken, name, } = yield getOrCreateApiSecurityToken(Object.assign({ identification,
114
+ password,
115
+ apiUrl }, authQueryParams));
116
+ yield (0, runControlHelper_1.saveConfig)({
117
+ apiUrl: apiUrl !== parameters_1.parameters.apiUrl ? apiUrl : undefined,
118
+ identification: tokenId,
119
+ apiSecurityToken,
139
120
  });
121
+ (0, log_1.log)('info', `User ${chalk_1.default.green(identification)} has been logged in with token "${name}". Credentials are stored in ${chalk_1.default.blue((0, sosControlHelper_1.getConfigFilePath)())}`);
140
122
  });
141
123
  },
142
124
  });
143
125
  function getOrCreateApiSecurityToken(_a) {
144
- var identification = _a.identification, password = _a.password, apiUrl = _a.apiUrl, isAuth0Enabled = _a.isAuth0Enabled, isLegacyEnabled = _a.isLegacyEnabled;
145
- return __awaiter(this, void 0, void 0, function () {
146
- var ACCOUNT_SECURITY_TOKEN_RESOURCE, options, tokenName, query, responseOfPost, bodyOfPost, _b, _c;
147
- return __generator(this, function (_d) {
148
- switch (_d.label) {
149
- case 0:
150
- ACCOUNT_SECURITY_TOKEN_RESOURCE = 'account/security-token';
151
- options = {
152
- url: apiUrl,
153
- auth: { clientId: undefined, secret: undefined },
154
- version: apiVersions_1.ApiVersions.V1,
155
- };
156
- tokenName = generateTokenName();
157
- query = __assign(__assign({ identification: identification, password: password, name: tokenName }, (isAuth0Enabled !== undefined ? { isAuth0AuthenticationEnabled: isAuth0Enabled } : {})), (isLegacyEnabled !== undefined ? { isLegacyAuthenticationEnabled: isLegacyEnabled } : {}));
158
- return [4 /*yield*/, (0, helper_1.postResource)(options, ACCOUNT_SECURITY_TOKEN_RESOURCE, query)];
159
- case 1:
160
- responseOfPost = _d.sent();
161
- _c = (_b = JSON).parse;
162
- return [4 /*yield*/, responseOfPost.text()];
163
- case 2:
164
- bodyOfPost = _c.apply(_b, [_d.sent(), helper_1.deserializeJSON]);
165
- debug('POST security-token response', bodyOfPost);
166
- if (responseOfPost.status === 201) {
167
- return [2 /*return*/, bodyOfPost];
168
- }
169
- else if (responseOfPost.status === 403) {
170
- throw new Error("Incorrect username or password");
171
- }
172
- else {
173
- throw new Error('Unknown error: ' + (bodyOfPost && bodyOfPost.message ? bodyOfPost.message : responseOfPost.status));
174
- }
175
- return [2 /*return*/];
176
- }
177
- });
126
+ return __awaiter(this, arguments, void 0, function* ({ identification, password, apiUrl, isAuth0Enabled, isLegacyEnabled, }) {
127
+ const ACCOUNT_SECURITY_TOKEN_RESOURCE = 'account/security-token';
128
+ const options = {
129
+ url: apiUrl,
130
+ auth: { clientId: undefined, secret: undefined },
131
+ version: apiVersions_1.ApiVersions.V1,
132
+ };
133
+ const tokenName = generateTokenName();
134
+ const query = Object.assign(Object.assign({ identification,
135
+ password, name: tokenName }, (isAuth0Enabled !== undefined ? { isAuth0AuthenticationEnabled: isAuth0Enabled } : {})), (isLegacyEnabled !== undefined ? { isLegacyAuthenticationEnabled: isLegacyEnabled } : {}));
136
+ const responseOfPost = yield (0, helper_1.postResource)(options, ACCOUNT_SECURITY_TOKEN_RESOURCE, query);
137
+ const bodyOfPost = JSON.parse(yield responseOfPost.text(), helper_1.deserializeJSON);
138
+ Debug('POST security-token response', bodyOfPost);
139
+ if (responseOfPost.status === 201) {
140
+ return bodyOfPost;
141
+ }
142
+ else if (responseOfPost.status === 403) {
143
+ throw new Error(`Incorrect username or password`);
144
+ }
145
+ else {
146
+ throw new Error('Unknown error: ' + (bodyOfPost && bodyOfPost.message ? bodyOfPost.message : responseOfPost.status));
147
+ }
178
148
  });
179
149
  }
180
150
  function generateTokenName() {
181
- var hostname = os.hostname();
182
- var shortHostname = hostname.split('.')[0];
183
- var userInfo = os.userInfo();
184
- return "".concat(userInfo.username, "@").concat(shortHostname);
151
+ const hostname = os.hostname();
152
+ const shortHostname = hostname.split('.')[0];
153
+ const userInfo = os.userInfo();
154
+ return `${userInfo.username}@${shortHostname}`;
185
155
  }
186
- //# sourceMappingURL=loginCommand.js.map
@@ -1,42 +1,73 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateCacheValue = exports.getCachedValue = void 0;
4
- var os = require("os");
5
- var fs = require("fs-extra");
6
- var path = require("path");
7
- var SOS_CACHE_DIR = 'sos-cache';
8
- var TMP_BASE_PATH = path.join(os.tmpdir(), SOS_CACHE_DIR);
36
+ exports.getCachedValue = getCachedValue;
37
+ exports.updateCacheValue = updateCacheValue;
38
+ const os = __importStar(require("os"));
39
+ const fs = __importStar(require("fs-extra"));
40
+ const path = __importStar(require("path"));
41
+ const SOS_CACHE_DIR = 'sos-cache';
42
+ const TMP_BASE_PATH = path.join(os.tmpdir(), SOS_CACHE_DIR);
9
43
  function getCachedValue(key) {
10
44
  try {
11
45
  fs.ensureDirSync(TMP_BASE_PATH);
12
- var cacheValuePath = path.join(TMP_BASE_PATH, key);
13
- var cachedValue = JSON.parse(fs.readFileSync(cacheValuePath).toString());
46
+ const cacheValuePath = path.join(TMP_BASE_PATH, key);
47
+ const cachedValue = JSON.parse(fs.readFileSync(cacheValuePath).toString());
14
48
  if (hasExpired(cachedValue.expireAt)) {
15
49
  return null;
16
50
  }
17
51
  return cachedValue.value;
18
52
  }
19
- catch (error) {
53
+ catch (_a) {
20
54
  return null;
21
55
  }
22
56
  }
23
- exports.getCachedValue = getCachedValue;
24
57
  function updateCacheValue(key, value, options) {
25
58
  try {
26
59
  fs.ensureDirSync(TMP_BASE_PATH);
27
- var cacheValuePath = path.join(TMP_BASE_PATH, key);
28
- var cachedValue = {
29
- value: value,
60
+ const cacheValuePath = path.join(TMP_BASE_PATH, key);
61
+ const cachedValue = {
62
+ value,
30
63
  expireAt: new Date().valueOf() + options.expireInMs,
31
64
  };
32
65
  fs.writeFileSync(cacheValuePath, JSON.stringify(cachedValue));
33
66
  }
34
- catch (error) {
67
+ catch (_a) {
35
68
  // skip caching
36
69
  }
37
70
  }
38
- exports.updateCacheValue = updateCacheValue;
39
71
  function hasExpired(expireAt) {
40
72
  return new Date().valueOf() > expireAt;
41
73
  }
42
- //# sourceMappingURL=tmpCache.js.map
@@ -1,13 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPackageVersion = exports.getPackageName = void 0;
4
- var parameters_1 = require("../parameters");
3
+ exports.getPackageName = getPackageName;
4
+ exports.getPackageVersion = getPackageVersion;
5
+ const parameters_1 = require("../parameters");
5
6
  function getPackageName() {
6
7
  return parameters_1.parameters.name;
7
8
  }
8
- exports.getPackageName = getPackageName;
9
9
  function getPackageVersion() {
10
10
  return parameters_1.parameters.version;
11
11
  }
12
- exports.getPackageVersion = getPackageVersion;
13
- //# sourceMappingURL=helper.js.map