-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdelete.ts
More file actions
86 lines (70 loc) · 2.47 KB
/
delete.ts
File metadata and controls
86 lines (70 loc) · 2.47 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
/*
* 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 {Flags, ux} from '@oclif/core';
import {EcdnCommand, formatApiError} from '../../../../utils/ecdn/index.js';
import {t, withDocs} from '../../../../i18n/index.js';
/**
* Response type for the delete command.
*/
interface DeleteOutput {
deleted: boolean;
webhookId: string;
}
/**
* Command to delete a Page Shield notification webhook.
*/
export default class EcdnPageShieldNotificationsDelete extends EcdnCommand<typeof EcdnPageShieldNotificationsDelete> {
static description = withDocs(
t('commands.ecdn.page-shield.notifications.delete.description', 'Delete a Page Shield notification webhook'),
'/cli/ecdn.html#b2c-ecdn-page-shield-notifications-delete',
);
static enableJsonFlag = true;
static examples = ['<%= config.bin %> <%= command.id %> --tenant-id zzxy_prd --webhook-id webhook_1234567890abcdef'];
static flags = {
...EcdnCommand.baseFlags,
'webhook-id': Flags.string({
description: t('flags.webhookId.description', 'Webhook ID to delete'),
required: true,
}),
};
async run(): Promise<DeleteOutput> {
// Prevent deletion in safe mode
this.assertDestructiveOperationAllowed('delete Page Shield webhook');
this.requireOAuthCredentials();
const webhookId = this.flags['webhook-id'];
if (!this.jsonEnabled()) {
this.log(
t('commands.ecdn.page-shield.notifications.delete.deleting', 'Deleting Page Shield webhook {{id}}...', {
id: webhookId,
}),
);
}
const client = this.getCdnZonesRwClient();
const organizationId = this.getOrganizationId();
const {error} = await client.DELETE('/organizations/{organizationId}/page-shield/notifications/{webhookId}', {
params: {
path: {organizationId, webhookId},
},
});
if (error) {
this.error(
t('commands.ecdn.page-shield.notifications.delete.error', 'Failed to delete Page Shield webhook: {{message}}', {
message: formatApiError(error),
}),
);
}
const output: DeleteOutput = {deleted: true, webhookId};
if (this.jsonEnabled()) {
return output;
}
ux.stdout(
t('commands.ecdn.page-shield.notifications.delete.success', 'Page Shield webhook {{id}} deleted successfully.', {
id: webhookId,
}),
);
return output;
}
}