-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdelete.ts
More file actions
81 lines (64 loc) · 2.16 KB
/
delete.ts
File metadata and controls
81 lines (64 loc) · 2.16 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
/*
* 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} from '@oclif/core';
import {SlasClientCommand, formatApiError} from '../../../utils/slas/client.js';
import {t, withDocs} from '../../../i18n/index.js';
interface DeleteOutput {
clientId: string;
deleted: boolean;
}
export default class SlasClientDelete extends SlasClientCommand<typeof SlasClientDelete> {
static args = {
clientId: Args.string({
description: 'SLAS client ID to delete',
required: true,
}),
};
static description = withDocs(
t('commands.slas.client.delete.description', 'Delete a SLAS client'),
'/cli/slas.html#b2c-slas-client-delete',
);
static enableJsonFlag = true;
static examples = [
'<%= config.bin %> <%= command.id %> my-client-id --tenant-id abcd_123',
'<%= config.bin %> <%= command.id %> my-client-id --tenant-id abcd_123 --json',
];
static flags = {
...SlasClientCommand.baseFlags,
};
async run(): Promise<DeleteOutput> {
// Prevent deletion in safe mode
this.assertDestructiveOperationAllowed('delete SLAS client');
this.requireOAuthCredentials();
const tenantId = this.requireTenantId();
const {clientId} = this.args;
if (!this.jsonEnabled()) {
this.log(t('commands.slas.client.delete.deleting', 'Deleting SLAS client {{clientId}}...', {clientId}));
}
const slasClient = this.getSlasClient();
const {error, response} = await slasClient.DELETE('/tenants/{tenantId}/clients/{clientId}', {
params: {
path: {tenantId, clientId},
},
});
if (error) {
this.error(
t('commands.slas.client.delete.error', 'Failed to delete SLAS client: {{message}}', {
message: formatApiError(error, response),
}),
);
}
const output: DeleteOutput = {
clientId,
deleted: true,
};
if (this.jsonEnabled()) {
return output;
}
this.log(t('commands.slas.client.delete.success', 'SLAS client {{clientId}} deleted successfully.', {clientId}));
return output;
}
}