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.
package/distTs/package.json
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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;
|