Skip to content

Commit 15ec4ab

Browse files
Merge branch 'packagingDistribution/packageBundles' into t/packaging-distribution/W-18927681/Package-Bundle-Install
2 parents 38f6500 + 0c7ecaa commit 15ec4ab

9 files changed

Lines changed: 263 additions & 20 deletions

File tree

command-snapshot.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@
9797
"flags": ["api-version", "flags-dir", "json", "loglevel", "package-install-request-id", "target-org", "verbose"],
9898
"plugin": "@salesforce/plugin-packaging"
9999
},
100+
{
101+
"alias": [],
102+
"command": "package:bundle:delete",
103+
"flagAliases": ["apiversion", "noprompt", "target-hub-org", "targetdevhubusername"],
104+
"flagChars": ["b", "n", "v"],
105+
"flags": ["api-version", "bundle", "flags-dir", "json", "loglevel", "no-prompt", "target-dev-hub"],
106+
"plugin": "@salesforce/plugin-packaging"
107+
},
100108
{
101109
"alias": [],
102110
"command": "package:bundle:list",
@@ -145,9 +153,9 @@
145153
{
146154
"alias": [],
147155
"command": "package:bundle:version:create:report",
148-
"flagAliases": ["apiversion", "packagecreaterequestid", "target-hub-org", "targetdevhubusername"],
156+
"flagAliases": ["apiversion", "bundleversioncreaterequestid", "target-hub-org", "targetdevhubusername"],
149157
"flagChars": ["i", "v"],
150-
"flags": ["api-version", "flags-dir", "json", "loglevel", "package-create-request-id", "target-dev-hub"],
158+
"flags": ["api-version", "bundle-version-create-request-id", "flags-dir", "json", "loglevel", "target-dev-hub"],
151159
"plugin": "@salesforce/plugin-packaging"
152160
},
153161
{

messages/bundle_version_create_report.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Use this command to check the status of a package bundle version creation reques
1616

1717
<%= config.bin %> force:package:bundle:version:create:report -i 0Ho0x0000000000000
1818

19-
# flags.package-create-request-id.summary
19+
# flags.bundle-version-create-request-id.summary
2020

2121
The ID of the package bundle version creation request to report on.
2222

@@ -28,11 +28,11 @@ ID
2828

2929
Status
3030

31-
# package-bundle-id
31+
# bundle-id
3232

3333
Package Bundle ID
3434

35-
# package-bundle-version-id
35+
# bundle-version-id
3636

3737
Package Bundle Version ID
3838

messages/package_bundle_delete.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# summary
2+
3+
Delete a package bundle.
4+
5+
# description
6+
7+
Specify the ID or alias of the package bundle you want to delete.
8+
9+
Delete package bundles. Before you delete a package bundle, first delete all associated package bundle versions.
10+
11+
# examples
12+
13+
- Delete a package bundle using its alias from your default Dev Hub org:
14+
15+
<%= config.bin %> <%= command.id %> --bundle "Your Bundle Alias"
16+
17+
- Delete a package bundle using its ID from the specified Dev Hub org:
18+
19+
<%= config.bin %> <%= command.id %> --bundle 1Fl... --target-dev-hub devhub@example.com
20+
21+
# flags.bundle.summary
22+
23+
ID (starts with 1Fl) or alias of the package bundle to delete.
24+
25+
# flags.no-prompt.summary
26+
27+
Don't prompt before deleting the package bundle.
28+
29+
# prompt-delete
30+
31+
Deleted package bundles can't be recovered.
32+
33+
Do you want to continue? (y/n)
34+
35+
# prompt-delete-deny
36+
37+
The request to delete this package bundle was canceled
38+
39+
# humanSuccess
40+
41+
Successfully deleted the package bundle %s.
42+
43+
# humanError
44+
45+
Failed to delete the package bundle.

messages/package_delete.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ Delete unlocked and second-generation managed packages. Before you delete a pack
2222

2323
ID (starts with 0Ho) or alias of the package to delete.
2424

25-
# flags.undelete.summary
25+
# flags.no-prompt.summary
2626

27-
Undelete a deleted package.
27+
Don't prompt before deleting the package.
2828

29-
# flags.no-prompt.summary
29+
# flags.undelete.summary
3030

31-
Don’t prompt before deleting the package.
31+
Undelete a deleted package.
3232

3333
# prompt-delete
3434

35-
Deleted packages cant be recovered.
35+
Deleted packages can't be recovered.
3636

3737
Do you want to continue? (y/n)
3838

schemas/package-bundle-delete.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$ref": "#/definitions/BundleSaveResult",
4+
"definitions": {
5+
"BundleSaveResult": {
6+
"$ref": "#/definitions/SaveResult"
7+
},
8+
"SaveResult": {
9+
"anyOf": [
10+
{
11+
"type": "object",
12+
"properties": {
13+
"success": {
14+
"type": "boolean",
15+
"const": true
16+
},
17+
"id": {
18+
"type": "string"
19+
},
20+
"errors": {
21+
"type": "array",
22+
"items": {
23+
"not": {}
24+
}
25+
}
26+
},
27+
"required": ["success", "id", "errors"],
28+
"additionalProperties": false
29+
},
30+
{
31+
"type": "object",
32+
"properties": {
33+
"success": {
34+
"type": "boolean",
35+
"const": false
36+
},
37+
"id": {
38+
"not": {}
39+
},
40+
"errors": {
41+
"type": "array",
42+
"items": {
43+
"$ref": "#/definitions/SaveError"
44+
}
45+
}
46+
},
47+
"required": ["success", "errors"],
48+
"additionalProperties": false
49+
}
50+
]
51+
},
52+
"SaveError": {
53+
"type": "object",
54+
"properties": {
55+
"errorCode": {
56+
"type": "string"
57+
},
58+
"message": {
59+
"type": "string"
60+
},
61+
"fields": {
62+
"type": "array",
63+
"items": {
64+
"type": "string"
65+
}
66+
}
67+
},
68+
"required": ["errorCode", "message"],
69+
"additionalProperties": false
70+
}
71+
}
72+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2022, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
import { Flags, loglevel, orgApiVersionFlagWithDeprecations, SfCommand } from '@salesforce/sf-plugins-core';
9+
import { Messages } from '@salesforce/core/messages';
10+
import { PackageBundle, BundleSaveResult } from '@salesforce/packaging';
11+
import { requiredHubFlag } from '../../../utils/hubFlag.js';
12+
13+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
14+
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_bundle_delete');
15+
16+
export class PackageBundleDeleteCommand extends SfCommand<BundleSaveResult> {
17+
public static readonly summary = messages.getMessage('summary');
18+
public static readonly description = messages.getMessage('description');
19+
public static readonly examples = messages.getMessages('examples');
20+
public static readonly requiresProject = true;
21+
public static readonly flags = {
22+
loglevel,
23+
'target-dev-hub': requiredHubFlag,
24+
'api-version': orgApiVersionFlagWithDeprecations,
25+
'no-prompt': Flags.boolean({
26+
char: 'n',
27+
deprecateAliases: true,
28+
aliases: ['noprompt'],
29+
summary: messages.getMessage('flags.no-prompt.summary'),
30+
}),
31+
bundle: Flags.string({
32+
char: 'b',
33+
summary: messages.getMessage('flags.bundle.summary'),
34+
required: true,
35+
}),
36+
};
37+
38+
public async run(): Promise<BundleSaveResult> {
39+
const { flags } = await this.parse(PackageBundleDeleteCommand);
40+
const message = messages.getMessage('prompt-delete');
41+
const accepted = flags['no-prompt'] || flags.json ? true : await this.confirm({ message });
42+
if (!accepted) {
43+
throw messages.createError('prompt-delete-deny');
44+
}
45+
46+
const connection = flags['target-dev-hub'].getConnection(flags['api-version']);
47+
const result = await PackageBundle.delete(connection, this.project!, flags.bundle);
48+
this.display(result);
49+
return result;
50+
}
51+
52+
private display(result: BundleSaveResult): void {
53+
this.log();
54+
if ((result as { success: boolean }).success) {
55+
this.logSuccess(messages.getMessage('humanSuccess', [(result as { id: string }).id]));
56+
} else {
57+
this.error(messages.getMessage('humanError'));
58+
}
59+
}
60+
}

src/commands/package/bundle/version/create/report.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ export class PackageBundleVersionCreateReportCommand extends SfCommand<ReportCom
2626
'target-dev-hub': requiredHubFlag,
2727
'api-version': orgApiVersionFlagWithDeprecations,
2828
// eslint-disable-next-line sf-plugin/id-flag-suggestions
29-
'package-create-request-id': Flags.salesforceId({
29+
'bundle-version-create-request-id': Flags.salesforceId({
3030
length: 'both',
3131
deprecateAliases: true,
32-
aliases: ['packagecreaterequestid'],
32+
aliases: ['bundleversioncreaterequestid'],
3333
char: 'i',
34-
summary: messages.getMessage('flags.package-create-request-id.summary'),
34+
summary: messages.getMessage('flags.bundle-version-create-request-id.summary'),
3535
required: true,
3636
}),
3737
};
3838

3939
public async run(): Promise<ReportCommandResult> {
4040
const { flags } = await this.parse(PackageBundleVersionCreateReportCommand);
4141
const result = await PackageBundleVersionCreate.getCreateStatus(
42-
flags['package-create-request-id'],
42+
flags['bundle-version-create-request-id'],
4343
flags['target-dev-hub'].getConnection(flags['api-version'])
4444
);
4545
this.display(result);
@@ -57,11 +57,11 @@ export class PackageBundleVersionCreateReportCommand extends SfCommand<ReportCom
5757
value: camelCaseToTitleCase(record.RequestStatus),
5858
},
5959
{
60-
name: messages.getMessage('package-bundle-id'),
60+
name: messages.getMessage('bundle-id'),
6161
value: record.PackageBundleId,
6262
},
6363
{
64-
name: messages.getMessage('package-bundle-version-id'),
64+
name: messages.getMessage('bundle-version-id'),
6565
value: record.PackageBundleVersionId,
6666
},
6767
{
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2022, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
9+
import { expect } from 'chai';
10+
11+
describe('bundle create/delete', () => {
12+
let session: TestSession;
13+
let bundleName: string;
14+
before(async () => {
15+
session = await TestSession.create({
16+
devhubAuthStrategy: 'AUTO',
17+
project: { name: 'bundleCreateDelete' },
18+
});
19+
});
20+
21+
after(async () => {
22+
await session?.clean();
23+
});
24+
describe('create/delete - human results', () => {
25+
before(async () => {
26+
bundleName = `test-bundle-${Date.now()}`;
27+
});
28+
it('should create a bundle - human readable results', () => {
29+
const command = `package:bundle:create --name ${bundleName} -v ${session.hubOrg.username}`;
30+
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;
31+
expect(output).to.contain('Ids');
32+
expect(output).to.match(/Bundle Id\s+?|1Fl/);
33+
});
34+
it('should delete a bundle - human readable results', () => {
35+
const command = `package:bundle:delete -b ${bundleName} -v ${session.hubOrg.username} --no-prompt`;
36+
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;
37+
expect(output).to.contain('Successfully deleted the package bundle');
38+
});
39+
});
40+
describe('create/delete - json results', () => {
41+
before(async () => {
42+
bundleName = `test-bundle-${Date.now()}`;
43+
});
44+
it('should create a bundle - json results', () => {
45+
const command = `package:bundle:create --name ${bundleName} -v ${session.hubOrg.username} --json`;
46+
const output = execCmd<{ Id: string }>(command, { ensureExitCode: 0 }).jsonOutput;
47+
expect(output?.status).to.equal(0);
48+
expect(output?.result).to.have.property('Id');
49+
expect(output?.result?.Id).to.match(/1Fl.{12,15}/);
50+
});
51+
it('should delete a bundle - json results', () => {
52+
const command = `package:bundle:delete -b ${bundleName} -v ${session.hubOrg.username} --json`;
53+
const output = execCmd<{ id: string; success: boolean; errors: [] }>(command, { ensureExitCode: 0 }).jsonOutput;
54+
expect(output?.result?.id).to.match(/1Fl.{12,15}/);
55+
expect(output?.result?.success).to.be.true;
56+
});
57+
});
58+
});

test/commands/bundle/bundleVersionCreateReport.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('package:bundle:version:create:report - tests', () => {
5151
getCreateStatusStub.resolves(mockResult);
5252

5353
const cmd = new PackageBundleVersionCreateReportCommand(
54-
['--package-create-request-id', requestId, '--target-dev-hub', testOrg.username],
54+
['--bundle-version-create-request-id', requestId, '--target-dev-hub', testOrg.username],
5555
config
5656
);
5757

@@ -83,7 +83,7 @@ describe('package:bundle:version:create:report - tests', () => {
8383
getCreateStatusStub.resolves(mockResult);
8484

8585
const cmd = new PackageBundleVersionCreateReportCommand(
86-
['-i', requestId, '--target-dev-hub', testOrg.username],
86+
['--bundle-version-create-request-id', requestId, '--target-dev-hub', testOrg.username],
8787
config
8888
);
8989

@@ -108,7 +108,7 @@ describe('package:bundle:version:create:report - tests', () => {
108108

109109
it('should throw error when target-dev-hub flag is missing', async () => {
110110
const requestId = '0Ho0x0000000000000';
111-
const cmd = new PackageBundleVersionCreateReportCommand(['--package-create-request-id', requestId], config);
111+
const cmd = new PackageBundleVersionCreateReportCommand(['--bundle-version-create-request-id', requestId], config);
112112

113113
try {
114114
await cmd.run();
@@ -125,7 +125,7 @@ describe('package:bundle:version:create:report - tests', () => {
125125
getCreateStatusStub.rejects(new Error(errorMessage));
126126

127127
const cmd = new PackageBundleVersionCreateReportCommand(
128-
['--package-create-request-id', requestId, '--target-dev-hub', testOrg.username],
128+
['--bundle-version-create-request-id', requestId, '--target-dev-hub', testOrg.username],
129129
config
130130
);
131131

0 commit comments

Comments
 (0)