bdy 1.16.21-dev → 1.16.22-dev

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 (39) hide show
  1. package/distTs/package.json +1 -1
  2. package/distTs/src/api/client.js +289 -60
  3. package/distTs/src/command/login.js +24 -13
  4. package/distTs/src/command/logout.js +18 -0
  5. package/distTs/src/command/package/download.js +1 -3
  6. package/distTs/src/command/package/list.js +1 -3
  7. package/distTs/src/command/package/publish.js +1 -3
  8. package/distTs/src/command/pipeline/run.js +1 -3
  9. package/distTs/src/command/project/list.js +1 -3
  10. package/distTs/src/command/project/set.js +1 -3
  11. package/distTs/src/command/sandbox/cp.js +1 -3
  12. package/distTs/src/command/sandbox/create.js +1 -3
  13. package/distTs/src/command/sandbox/destroy.js +1 -3
  14. package/distTs/src/command/sandbox/endpoint/add.js +1 -3
  15. package/distTs/src/command/sandbox/endpoint/delete.js +4 -4
  16. package/distTs/src/command/sandbox/endpoint/get.js +1 -3
  17. package/distTs/src/command/sandbox/endpoint/list.js +1 -3
  18. package/distTs/src/command/sandbox/exec/command.js +1 -3
  19. package/distTs/src/command/sandbox/exec/kill.js +1 -3
  20. package/distTs/src/command/sandbox/exec/list.js +1 -3
  21. package/distTs/src/command/sandbox/exec/logs.js +1 -3
  22. package/distTs/src/command/sandbox/exec/status.js +1 -3
  23. package/distTs/src/command/sandbox/get.js +5 -4
  24. package/distTs/src/command/sandbox/list.js +1 -3
  25. package/distTs/src/command/sandbox/restart.js +1 -3
  26. package/distTs/src/command/sandbox/snapshot/create.js +1 -3
  27. package/distTs/src/command/sandbox/snapshot/delete.js +1 -3
  28. package/distTs/src/command/sandbox/snapshot/get.js +5 -4
  29. package/distTs/src/command/sandbox/snapshot/list.js +1 -3
  30. package/distTs/src/command/sandbox/start.js +1 -3
  31. package/distTs/src/command/sandbox/status.js +2 -4
  32. package/distTs/src/command/sandbox/stop.js +1 -3
  33. package/distTs/src/command/whoami.js +5 -1
  34. package/distTs/src/command/workspace/list.js +1 -3
  35. package/distTs/src/command/workspace/set.js +1 -3
  36. package/distTs/src/input.js +16 -2
  37. package/distTs/src/tunnel/cfg.js +24 -5
  38. package/distTs/src/visualTest/server.js +1 -0
  39. package/package.json +1 -1
@@ -7,7 +7,6 @@ const utils_1 = require("../../utils");
7
7
  const texts_1 = require("../../texts");
8
8
  const output_1 = __importDefault(require("../../output"));
9
9
  const input_1 = __importDefault(require("../../input"));
10
- const client_1 = __importDefault(require("../../api/client"));
11
10
  const commandSandboxStop = (0, utils_1.newCommand)('stop', texts_1.DESC_COMMAND_SANDBOX_STOP);
12
11
  commandSandboxStop.option('--token <token>', texts_1.OPTION_REST_API_TOKEN);
13
12
  commandSandboxStop.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
@@ -18,11 +17,10 @@ commandSandboxStop.option('--wait', texts_1.OPTION_SANDBOX_WAIT);
18
17
  commandSandboxStop.option('--wait-timeout <seconds>', texts_1.OPTION_SANDBOX_WAIT_TIMEOUT, '300');
19
18
  commandSandboxStop.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
20
19
  commandSandboxStop.action(async (identifier, options) => {
21
- const token = input_1.default.restApiToken(options.token);
22
20
  const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
23
21
  const workspace = input_1.default.restApiWorkspace(options.workspace);
24
22
  const project = input_1.default.restApiProject(options.project);
25
- const client = new client_1.default(baseUrl, token);
23
+ const client = input_1.default.restApiTokenClient(baseUrl, options.token);
26
24
  const result = await client.listSandboxes(workspace, project);
27
25
  const sandboxes = result.sandboxes || [];
28
26
  const found = sandboxes.find((s) => s.identifier === identifier);
@@ -27,13 +27,17 @@ const tryGetEmail = async (client) => {
27
27
  const commandWhoami = (0, utils_1.newCommand)('whoami', texts_1.DESC_COMMAND_WHOAMI);
28
28
  commandWhoami.action(async () => {
29
29
  const token = cfg_1.default.getApiToken();
30
+ const refreshToken = cfg_1.default.getApiRefreshApiToken();
31
+ const clientId = cfg_1.default.getApiClientId();
32
+ const clientSecret = cfg_1.default.getApiClientSecret();
33
+ const clientToken = cfg_1.default.getApiClientToken();
30
34
  const workspace = cfg_1.default.getWorkspace();
31
35
  const project = cfg_1.default.getProject();
32
36
  const baseUrl = input_1.default.restApiBaseUrl();
33
37
  if (!token) {
34
38
  output_1.default.exitError(texts_1.ERR_WHOAMI_LOGOUT);
35
39
  }
36
- const client = new client_1.default(baseUrl, token);
40
+ const client = new client_1.default(baseUrl, token, refreshToken, clientId, clientSecret, clientToken);
37
41
  const user = await client.getInvoker();
38
42
  if (!user) {
39
43
  output_1.default.exitError(texts_1.ERR_WHOAMI_LOGOUT);
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const output_1 = __importDefault(require("../../output"));
7
- const client_1 = __importDefault(require("../../api/client"));
8
7
  const texts_1 = require("../../texts");
9
8
  const utils_1 = require("../../utils");
10
9
  const input_1 = __importDefault(require("../../input"));
@@ -14,9 +13,8 @@ commandWorkspaceList.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
14
13
  commandWorkspaceList.option('--region <region>', texts_1.OPTION_REST_API_REGION);
15
14
  commandWorkspaceList.alias('ls');
16
15
  commandWorkspaceList.action(async (options) => {
17
- const token = input_1.default.restApiToken(options.token);
18
16
  const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
19
- const client = new client_1.default(baseUrl, token);
17
+ const client = input_1.default.restApiTokenClient(baseUrl, options.token);
20
18
  const response = await client.getWorkspaces();
21
19
  if (!response.workspaces || response.workspaces.length === 0) {
22
20
  output_1.default.normal('No workspaces found.');
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const cfg_1 = __importDefault(require("../../tunnel/cfg"));
7
7
  const output_1 = __importDefault(require("../../output"));
8
- const client_1 = __importDefault(require("../../api/client"));
9
8
  const texts_1 = require("../../texts");
10
9
  const utils_1 = require("../../utils");
11
10
  const input_1 = __importDefault(require("../../input"));
@@ -16,9 +15,8 @@ commandWorkspaceSet.option('--region <region>', texts_1.OPTION_REST_API_REGION);
16
15
  commandWorkspaceSet.argument('[workspace]', texts_1.ARG_COMMAND_WORKSPACE);
17
16
  commandWorkspaceSet.action(async (workspaceDomain, options) => {
18
17
  output_1.default.handleSignals();
19
- const token = input_1.default.restApiToken(options.token);
20
18
  const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
21
- const client = new client_1.default(baseUrl, token);
19
+ const client = input_1.default.restApiTokenClient(baseUrl, options.token);
22
20
  const response = await client.getWorkspaces();
23
21
  if (!response.workspaces || response.workspaces.length === 0) {
24
22
  output_1.default.exitError(texts_1.ERR_LOGIN_NO_WORKSPACES);
@@ -47,6 +47,7 @@ const texts_1 = require("./texts");
47
47
  const tunnel_1 = require("./types/tunnel");
48
48
  const node_path_1 = __importStar(require("node:path"));
49
49
  const cfg_1 = __importDefault(require("./tunnel/cfg"));
50
+ const client_1 = __importDefault(require("./api/client"));
50
51
  class Input {
51
52
  static timeout(timeout) {
52
53
  const t = parseInt(timeout, 10);
@@ -300,14 +301,27 @@ class Input {
300
301
  }
301
302
  static restApiToken(token) {
302
303
  let t = process.env.BUDDY_TOKEN;
304
+ let rf = '';
305
+ let cid = '';
306
+ let cs = '';
307
+ let ct = '';
303
308
  if (token)
304
309
  t = token;
305
- if (!t)
310
+ if (!t) {
306
311
  t = cfg_1.default.getApiToken();
312
+ rf = cfg_1.default.getApiRefreshApiToken();
313
+ cid = cfg_1.default.getApiClientId();
314
+ cs = cfg_1.default.getApiClientSecret();
315
+ ct = cfg_1.default.getApiClientToken();
316
+ }
307
317
  if (!t) {
308
318
  output_1.default.exitError(texts_1.ERR_REST_API_TOKEN);
309
319
  }
310
- return t;
320
+ return { token: t, refreshToken: rf, clientId: cid, clientSecret: cs, clientToken: ct };
321
+ }
322
+ static restApiTokenClient(baseUrl, token) {
323
+ const { token: t, refreshToken, clientId, clientToken, clientSecret } = this.restApiToken(token);
324
+ return new client_1.default(baseUrl, t, refreshToken, clientId, clientSecret, clientToken);
311
325
  }
312
326
  static pipelineRunPriority(priority) {
313
327
  if (!priority)
@@ -30,7 +30,7 @@ class Cfg {
30
30
  throw new Error((0, texts_1.ERR_CANT_CREATE_DIR_IN_HOME)('.bdy'));
31
31
  }
32
32
  try {
33
- (0, fs_1.chmodSync)(this.dir, 0o777);
33
+ (0, fs_1.chmodSync)(this.dir, 0o700);
34
34
  }
35
35
  catch {
36
36
  // do nothing
@@ -44,7 +44,7 @@ class Cfg {
44
44
  throw new Error((0, texts_1.ERR_CANT_CREATE_DIR_IN_HOME)('.bdy/cfg.json'));
45
45
  }
46
46
  try {
47
- (0, fs_1.chmodSync)(this.file, 0o666);
47
+ (0, fs_1.chmodSync)(this.file, 0o600);
48
48
  }
49
49
  catch {
50
50
  // do nothing
@@ -172,14 +172,23 @@ class Cfg {
172
172
  this.json.apiToken = token;
173
173
  this.save();
174
174
  }
175
- setApiClient(clientId, clientSecret) {
176
- if (!clientId || !clientSecret) {
175
+ setApiRefreshToken(token) {
176
+ if (!token)
177
+ delete this.json.apiRefreshToken;
178
+ else
179
+ this.json.apiRefreshToken = token;
180
+ this.save();
181
+ }
182
+ setApiClient(clientId, clientSecret, clientToken) {
183
+ if (!clientId || !clientSecret || !clientToken) {
177
184
  delete this.json.apiClientId;
178
185
  delete this.json.apiClientSecret;
186
+ delete this.json.apiClientToken;
179
187
  }
180
188
  else {
181
189
  this.json.apiClientId = clientId;
182
190
  this.json.apiClientSecret = clientSecret;
191
+ this.json.apiClientToken = clientToken;
183
192
  }
184
193
  this.save();
185
194
  }
@@ -203,12 +212,18 @@ class Cfg {
203
212
  getApiToken() {
204
213
  return this.json.apiToken || '';
205
214
  }
215
+ getApiRefreshApiToken() {
216
+ return this.json.apiRefreshToken || '';
217
+ }
206
218
  getApiClientId() {
207
219
  return this.json.apiClientId || '';
208
220
  }
209
221
  getApiClientSecret() {
210
222
  return this.json.apiClientSecret || '';
211
223
  }
224
+ getApiClientToken() {
225
+ return this.json.apiClientToken || '';
226
+ }
212
227
  getTokenHost() {
213
228
  const token = this.getToken();
214
229
  if (!token) {
@@ -251,6 +266,10 @@ class Cfg {
251
266
  }
252
267
  clearLogin() {
253
268
  delete this.json.apiToken;
269
+ delete this.json.apiRefreshToken;
270
+ delete this.json.apiClientId;
271
+ delete this.json.apiClientSecret;
272
+ delete this.json.apiClientToken;
254
273
  delete this.json.workspace;
255
274
  delete this.json.project;
256
275
  delete this.json.baseUrl;
@@ -297,7 +316,7 @@ class Cfg {
297
316
  throw new Error((0, texts_1.ERR_CANT_CREATE_DIR_IN_HOME)('.bdy/cfg.json'));
298
317
  }
299
318
  try {
300
- (0, fs_1.chmodSync)(this.file, 0o666);
319
+ (0, fs_1.chmodSync)(this.file, 0o600);
301
320
  }
302
321
  catch {
303
322
  // do nothing
@@ -37,6 +37,7 @@ async function getParseDom() {
37
37
  function prepareSnapshotPlugin(data) {
38
38
  try {
39
39
  const validatedData = schemas_1.snapshotSchema.parse(data);
40
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
40
41
  const { version, ...snapshot } = validatedData;
41
42
  const cookies = snapshot.cookies.map((cookie) => {
42
43
  if (cookie.domain) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.16.21-dev",
4
+ "version": "1.16.22-dev",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {