bdy 1.25.17-dev → 1.25.18-stage

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.25.17-dev",
4
+ "version": "1.25.18-stage",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "homepage": "https://buddy.works/docs/cli",
@@ -3,11 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const cliError_1 = __importDefault(require("../../cliError"));
7
6
  const utils_1 = require("../../utils");
8
7
  const texts_1 = require("../../texts");
9
8
  const input_1 = __importDefault(require("../../input"));
10
9
  const output_1 = __importDefault(require("../../output"));
10
+ const resolve_1 = require("./resolve");
11
11
  const commandDomainGet = (0, utils_1.newCommand)('get', texts_1.DESC_COMMAND_DOMAIN_GET, { requiredScopes: [utils_1.REST_API_SCOPE.DOMAIN_READ] });
12
12
  commandDomainGet.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
13
13
  commandDomainGet.option('--format <text|json>', texts_1.OPTION_FORMAT);
@@ -15,20 +15,7 @@ commandDomainGet.argument('<id|name>', texts_1.OPTION_COMMAND_DOMAIN_IDENTIFIER)
15
15
  commandDomainGet.action(async (name, options) => {
16
16
  const workspace = input_1.default.restApiWorkspace(options.workspace);
17
17
  const client = input_1.default.restApiTokenClient();
18
- let domain;
19
- try {
20
- domain = await client.getDomain(workspace, name);
21
- }
22
- catch {
23
- const response = await client.getDomains(workspace);
24
- domain = (response.domains || []).find((d) => d.name === name);
25
- if (domain) {
26
- domain = await client.getDomain(workspace, domain.id);
27
- }
28
- }
29
- if (!domain) {
30
- output_1.default.exitError(new cliError_1.default('not_found', texts_1.ERR_COMMAND_DOMAIN_NOT_FOUND, texts_1.HINT_DOMAIN_LIST));
31
- }
18
+ const domain = await (0, resolve_1.resolveDomain)(client, workspace, name, true);
32
19
  if (options.format === 'json') {
33
20
  output_1.default.json(domain);
34
21
  }
@@ -7,7 +7,7 @@ const utils_1 = require("../../utils");
7
7
  const texts_1 = require("../../texts");
8
8
  const input_1 = __importDefault(require("../../input"));
9
9
  const output_1 = __importDefault(require("../../output"));
10
- const cliError_1 = __importDefault(require("../../cliError"));
10
+ const resolve_1 = require("./resolve");
11
11
  const commandDomainOpen = (0, utils_1.newCommand)('open', texts_1.DESC_COMMAND_RESOURCE_OPEN, {
12
12
  requiredScopes: [utils_1.REST_API_SCOPE.DOMAIN_READ],
13
13
  examples: [{ description: 'Open a domain in Buddy', command: 'bdy domain open example.com' }],
@@ -18,18 +18,7 @@ commandDomainOpen.argument('<id|name>', texts_1.OPTION_COMMAND_DOMAIN_IDENTIFIER
18
18
  commandDomainOpen.action(async (name, options) => {
19
19
  const workspace = input_1.default.restApiWorkspace(options.workspace);
20
20
  const client = input_1.default.restApiTokenClient();
21
- let domain;
22
- try {
23
- domain = await client.getDomain(workspace, name);
24
- }
25
- catch {
26
- const response = await client.getDomains(workspace);
27
- const found = response.domains.find((item) => item.name === name);
28
- if (found)
29
- domain = await client.getDomain(workspace, found.id);
30
- }
31
- if (!domain)
32
- throw new cliError_1.default('not_found', texts_1.ERR_COMMAND_DOMAIN_NOT_FOUND, texts_1.HINT_DOMAIN_LIST);
21
+ const domain = await (0, resolve_1.resolveDomain)(client, workspace, name);
33
22
  await output_1.default.openUrl(domain.html_url, options.format === 'json');
34
23
  });
35
24
  exports.default = commandDomainOpen;
@@ -6,14 +6,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.resolveDomain = void 0;
7
7
  const cliError_1 = __importDefault(require("../../cliError"));
8
8
  const texts_1 = require("../../texts");
9
- // Domains are addressed by id in the API, but users know them by name. The
10
- // list is the only lookup by name, and it carries the id either way.
11
- const resolveDomain = async (client, workspace, idOrName) => {
12
- const { domains } = await client.getDomains(workspace);
13
- const domain = (domains || []).find((d) => d.name === idOrName || d.id === idOrName);
14
- if (!domain) {
15
- throw new cliError_1.default('not_found', texts_1.ERR_COMMAND_DOMAIN_NOT_FOUND, texts_1.HINT_DOMAIN_LIST);
9
+ const notFound = () => new cliError_1.default('not_found', texts_1.ERR_COMMAND_DOMAIN_NOT_FOUND, texts_1.HINT_DOMAIN_LIST);
10
+ // Domains are addressed by id in the API, but users know them by name. A name always has a
11
+ // dot and an id never does, so the argument says which it is: an id is fetched directly, and a
12
+ // name goes through the list, the only lookup by name. List items are short views, so `full`
13
+ // fetches the domain after a name lookup for callers that show more than its id and name.
14
+ const resolveDomain = async (client, workspace, idOrName, full = false) => {
15
+ if (!idOrName.includes('.')) {
16
+ try {
17
+ return await client.getDomain(workspace, idOrName);
18
+ }
19
+ catch (err) {
20
+ // Only a 404 means "no such domain"; anything else (auth, 5xx) is the real error.
21
+ if (cliError_1.default.details(err).code === 'not_found')
22
+ throw notFound();
23
+ throw err;
24
+ }
16
25
  }
17
- return domain;
26
+ const { domains } = await client.getDomains(workspace);
27
+ const domain = (domains || []).find((d) => d.name === idOrName);
28
+ if (!domain)
29
+ throw notFound();
30
+ return full ? await client.getDomain(workspace, domain.id) : domain;
18
31
  };
19
32
  exports.resolveDomain = resolveDomain;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.25.17-dev",
4
+ "version": "1.25.18-stage",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "homepage": "https://buddy.works/docs/cli",