-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathlist.ts
More file actions
164 lines (142 loc) · 5.14 KB
/
list.ts
File metadata and controls
164 lines (142 loc) · 5.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* Copyright (c) 2025, Salesforce, Inc.
* SPDX-License-Identifier: Apache-2
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
*/
import {Args, Flags} from '@oclif/core';
import {OdsCommand, TableRenderer} from '@salesforce/b2c-tooling-sdk/cli';
import {getApiErrorMessage, type OdsComponents} from '@salesforce/b2c-tooling-sdk';
import {t, withDocs} from '../../../i18n/index.js';
type SandboxAliasModel = OdsComponents['schemas']['SandboxAliasModel'];
/**
* Command to list sandbox aliases.
*/
export default class SandboxAliasList extends OdsCommand<typeof SandboxAliasList> {
static aliases = ['ods:alias:list'];
static args = {
sandboxId: Args.string({
description: 'Sandbox ID (UUID or realm-instance, e.g., abcd-123)',
required: true,
}),
};
static description = withDocs(
t('commands.sandbox.alias.list.description', 'List all hostname aliases for a sandbox'),
'/cli/sandbox.html#b2c-sandbox-alias-list',
);
static enableJsonFlag = true;
static examples = [
'<%= config.bin %> <%= command.id %> abc12345-1234-1234-1234-abc123456789',
'<%= config.bin %> <%= command.id %> zzzv-123',
'<%= config.bin %> <%= command.id %> zzzv-123 --alias-id some-alias-uuid',
'<%= config.bin %> <%= command.id %> zzzv-123 --json',
];
static flags = {
'alias-id': Flags.string({
description: 'Specific alias ID to retrieve (if omitted, lists all aliases)',
required: false,
}),
};
async run(): Promise<SandboxAliasModel | SandboxAliasModel[]> {
const {sandboxId} = this.args;
const {'alias-id': aliasId} = this.flags;
const resolvedSandboxId = await this.resolveSandboxId(sandboxId);
// If alias ID provided, get specific alias; otherwise list all
if (aliasId) {
return this.showAlias(resolvedSandboxId, aliasId);
}
return this.listAllAliases(resolvedSandboxId);
}
private async listAllAliases(sandboxId: string): Promise<SandboxAliasModel[]> {
this.log(
t('commands.sandbox.alias.list.fetching', 'Fetching aliases for sandbox {{sandboxId}}...', {
sandboxId: this.args.sandboxId,
}),
);
const result = await this.odsClient.GET('/sandboxes/{sandboxId}/aliases', {
params: {
path: {sandboxId},
},
});
if (!result.data?.data) {
const message = getApiErrorMessage(result.error, result.response);
this.error(
t('commands.sandbox.alias.list.error', 'Failed to fetch aliases: {{message}}', {
message,
}),
);
}
const aliases = (result.data?.data ?? []) as SandboxAliasModel[];
if (!this.jsonEnabled()) {
if (aliases.length === 0) {
this.log(t('commands.sandbox.alias.list.no_aliases', 'No aliases found'));
} else {
this.log(t('commands.sandbox.alias.list.count', 'Found {{count}} alias(es):', {count: aliases.length}));
const columns = {
id: {
header: 'Alias ID',
get: (row: SandboxAliasModel) => row.id || '-',
},
name: {
header: 'Hostname',
get: (row: SandboxAliasModel) => row.name,
},
status: {
header: 'Status',
get: (row: SandboxAliasModel) => row.status || '-',
},
unique: {
header: 'Unique',
get: (row: SandboxAliasModel) => (row.unique ? 'Yes' : 'No'),
},
domainVerificationRecord: {
header: 'Verification Record',
get: (row: SandboxAliasModel) => row.domainVerificationRecord || '-',
},
};
const table = new TableRenderer(columns);
table.render(aliases, ['id', 'name', 'status', 'unique', 'domainVerificationRecord']);
}
}
return aliases;
}
private async showAlias(sandboxId: string, aliasId: string): Promise<SandboxAliasModel> {
this.log(
t('commands.sandbox.alias.list.fetching_one', 'Fetching alias {{aliasId}} for sandbox {{sandboxId}}...', {
aliasId,
sandboxId,
}),
);
const result = await this.odsClient.GET('/sandboxes/{sandboxId}/aliases/{sandboxAliasId}', {
params: {
path: {sandboxId, sandboxAliasId: aliasId},
},
});
if (!result.data?.data) {
const message = getApiErrorMessage(result.error, result.response);
this.error(
t('commands.sandbox.alias.list.error_one', 'Failed to fetch alias: {{message}}', {
message,
}),
);
}
const alias = result.data.data as SandboxAliasModel;
if (!this.jsonEnabled()) {
this.log('');
this.log(t('commands.sandbox.alias.list.alias_details', 'Alias Details:'));
this.log('─'.repeat(60));
this.log(`ID: ${alias.id}`);
this.log(`Name: ${alias.name}`);
this.log(`Status: ${alias.status}`);
if (alias.unique) {
this.log(`Unique: ${alias.unique}`);
}
if (alias.domainVerificationRecord) {
this.log(`Verification Record: ${alias.domainVerificationRecord}`);
}
if (alias.registration) {
this.log(`Registration URL: ${alias.registration}`);
}
}
return alias;
}
}