-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdelete.ts
More file actions
83 lines (69 loc) · 2.22 KB
/
delete.ts
File metadata and controls
83 lines (69 loc) · 2.22 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
/*
* 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 {AmCommand} from '@salesforce/b2c-tooling-sdk/cli';
import {t} from '../../../i18n/index.js';
/**
* Command to delete an Account Manager user.
*/
export default class UserDelete extends AmCommand<typeof UserDelete> {
static args = {
login: Args.string({
description: 'User login (email)',
required: true,
}),
};
static description = t('commands.user.delete.description', 'Delete an Account Manager user');
static enableJsonFlag = true;
static examples = [
'<%= config.bin %> <%= command.id %> user@example.com',
'<%= config.bin %> <%= command.id %> user@example.com --purge',
];
static flags = {
purge: Flags.boolean({
description: 'Purge the user completely (hard delete). User must be in DELETED state first.',
default: false,
}),
};
async run(): Promise<void> {
// Prevent deletion in safe mode
this.assertDestructiveOperationAllowed('delete user');
const {login} = this.args;
const {purge} = this.flags;
this.log(t('commands.user.delete.fetching', 'Fetching user {{login}}...', {login}));
const user = await this.accountManagerClient.findUserByLogin(login);
if (!user) {
this.error(t('commands.user.delete.notFound', 'User {{login}} not found', {login}));
}
if (!user.id) {
this.error(t('commands.user.delete.noId', 'User does not have an ID'));
}
if (purge) {
this.log(
t('commands.user.delete.purging', 'Purging user {{login}}...', {
login,
}),
);
await this.accountManagerClient.purgeUser(user.id);
} else {
this.log(
t('commands.user.delete.deleting', 'Deleting user {{login}}...', {
login,
}),
);
await this.accountManagerClient.deleteUser(user.id);
}
if (this.jsonEnabled()) {
return;
}
this.log(
t('commands.user.delete.success', 'User {{login}} {{action}} successfully.', {
login,
action: purge ? 'purged' : 'deleted',
}),
);
}
}