@salesforce/packaging 4.21.11 → 4.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/exported.d.ts +2 -0
- package/lib/exported.js +2 -0
- package/lib/interfaces/bundleInterfacesAndType.d.ts +9 -0
- package/lib/interfaces/bundleSObjects.d.ts +122 -0
- package/lib/interfaces/bundleSObjects.js +14 -0
- package/lib/package/index.d.ts +1 -0
- package/lib/package/index.js +1 -0
- package/lib/package/packageBundleInstalledList.d.ts +19 -0
- package/lib/package/packageBundleInstalledList.js +147 -0
- package/lib/package/packageBundleUninstall.d.ts +9 -0
- package/lib/package/packageBundleUninstall.js +167 -0
- package/messages/bundle_installed_list.md +3 -0
- package/messages/bundle_uninstall.md +12 -0
- package/package.json +3 -3
package/lib/exported.d.ts
CHANGED
|
@@ -5,3 +5,5 @@ export * from './utils';
|
|
|
5
5
|
export * from './package/packageBundle';
|
|
6
6
|
export * from './package/packageBundleVersionCreate';
|
|
7
7
|
export * from './package/packageBundleInstall';
|
|
8
|
+
export * from './package/packageBundleInstalledList';
|
|
9
|
+
export * from './package/packageBundleUninstall';
|
package/lib/exported.js
CHANGED
|
@@ -36,4 +36,6 @@ __exportStar(require("./utils"), exports);
|
|
|
36
36
|
__exportStar(require("./package/packageBundle"), exports);
|
|
37
37
|
__exportStar(require("./package/packageBundleVersionCreate"), exports);
|
|
38
38
|
__exportStar(require("./package/packageBundleInstall"), exports);
|
|
39
|
+
__exportStar(require("./package/packageBundleInstalledList"), exports);
|
|
40
|
+
__exportStar(require("./package/packageBundleUninstall"), exports);
|
|
39
41
|
//# sourceMappingURL=exported.js.map
|
|
@@ -30,4 +30,13 @@ export type BundleInstallOptions = {
|
|
|
30
30
|
frequency: Duration;
|
|
31
31
|
};
|
|
32
32
|
};
|
|
33
|
+
export type BundleUninstallOptions = {
|
|
34
|
+
connection: Connection;
|
|
35
|
+
project: SfProject;
|
|
36
|
+
PackageBundleVersion: string;
|
|
37
|
+
polling?: {
|
|
38
|
+
timeout: Duration;
|
|
39
|
+
frequency: Duration;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
33
42
|
export type BundleSaveResult = SaveResult;
|
|
@@ -110,6 +110,18 @@ export declare namespace BundleSObjects {
|
|
|
110
110
|
success = "Success",
|
|
111
111
|
error = "Error"
|
|
112
112
|
}
|
|
113
|
+
enum PkgBundleVersionUninstallReqStatus {
|
|
114
|
+
queued = "Queued",
|
|
115
|
+
inProgress = "InProgress",
|
|
116
|
+
success = "Success",
|
|
117
|
+
error = "Error"
|
|
118
|
+
}
|
|
119
|
+
enum PkgBundleVerCpntUnistlReqStatus {
|
|
120
|
+
queued = "Queued",
|
|
121
|
+
inProgress = "InProgress",
|
|
122
|
+
success = "Success",
|
|
123
|
+
error = "Error"
|
|
124
|
+
}
|
|
113
125
|
type PkgBundleVersionQueryRecord = {
|
|
114
126
|
Id: string;
|
|
115
127
|
RequestStatus: BundleSObjects.PkgBundleVersionCreateReqStatus;
|
|
@@ -147,4 +159,114 @@ export declare namespace BundleSObjects {
|
|
|
147
159
|
CreatedById: string;
|
|
148
160
|
Error?: string[];
|
|
149
161
|
} & Schema;
|
|
162
|
+
type PkgBundleVerUninstallReq = {
|
|
163
|
+
PackageBundleVersionId: string;
|
|
164
|
+
InstalledPkgBundleVersionId?: string;
|
|
165
|
+
ValidationError?: string;
|
|
166
|
+
};
|
|
167
|
+
type PkgBundleVerUninstallReqResult = PkgBundleVerUninstallReq & {
|
|
168
|
+
Id: string;
|
|
169
|
+
UninstallStatus: PkgBundleVersionUninstallReqStatus;
|
|
170
|
+
CreatedDate: string;
|
|
171
|
+
CreatedById: string;
|
|
172
|
+
Error?: string[];
|
|
173
|
+
};
|
|
174
|
+
type PkgBundleVerUninstallReqQueryRecord = {
|
|
175
|
+
Id: string;
|
|
176
|
+
UninstallStatus: PkgBundleVersionUninstallReqStatus;
|
|
177
|
+
PackageBundleVersionId: string;
|
|
178
|
+
InstalledPkgBundleVersionId?: string;
|
|
179
|
+
ValidationError?: string;
|
|
180
|
+
CreatedDate: string;
|
|
181
|
+
CreatedById: string;
|
|
182
|
+
Error?: string[];
|
|
183
|
+
} & Schema;
|
|
184
|
+
type PkgBundleVerCpntUnistlReqRecord = {
|
|
185
|
+
Id: string;
|
|
186
|
+
SequenceOrder: number;
|
|
187
|
+
UninstallStatus: PkgBundleVerCpntUnistlReqStatus;
|
|
188
|
+
PkgBundleVersionComponent?: {
|
|
189
|
+
Id: string;
|
|
190
|
+
};
|
|
191
|
+
Error?: string;
|
|
192
|
+
} & Schema;
|
|
193
|
+
type InstalledPackageBundleVersionComponent = {
|
|
194
|
+
ExpectedPackageName: string;
|
|
195
|
+
ExpectedPackageVersionNumber: string;
|
|
196
|
+
ActualPackageName: string;
|
|
197
|
+
ActualPackageVersionNumber: string;
|
|
198
|
+
};
|
|
199
|
+
type InstalledPackageBundleVersion = {
|
|
200
|
+
Id: string;
|
|
201
|
+
BundleName: string;
|
|
202
|
+
BundleId: string;
|
|
203
|
+
BundleVersionId: string;
|
|
204
|
+
BundleVersionName: string;
|
|
205
|
+
MajorVersion: number;
|
|
206
|
+
MinorVersion: number;
|
|
207
|
+
Description: string;
|
|
208
|
+
InstalledDate: string;
|
|
209
|
+
LastUpgradedDate: string;
|
|
210
|
+
Components: InstalledPackageBundleVersionComponent[];
|
|
211
|
+
};
|
|
212
|
+
type InstalledPackageBundleVersionQueryRecord = {
|
|
213
|
+
Id: string;
|
|
214
|
+
PackageBundleVersion: {
|
|
215
|
+
Id: string;
|
|
216
|
+
VersionName: string;
|
|
217
|
+
MajorVersion: number;
|
|
218
|
+
MinorVersion: number;
|
|
219
|
+
PackageBundle: {
|
|
220
|
+
Id: string;
|
|
221
|
+
BundleName: string;
|
|
222
|
+
Description: string;
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
InstalledDate: string;
|
|
226
|
+
LastUpgradedDate: string;
|
|
227
|
+
} & Schema;
|
|
228
|
+
type InstalledBundleRecord = {
|
|
229
|
+
Id: string;
|
|
230
|
+
PackageBundleId?: string;
|
|
231
|
+
PackageBundleVersionId?: string;
|
|
232
|
+
BundleName: string;
|
|
233
|
+
BundleVersionName: string;
|
|
234
|
+
MajorVersion: number;
|
|
235
|
+
MinorVersion: number;
|
|
236
|
+
CreatedDate?: string;
|
|
237
|
+
LastModifiedDate?: string;
|
|
238
|
+
} & Schema;
|
|
239
|
+
type InstallRequestRecord = {
|
|
240
|
+
Id: string;
|
|
241
|
+
} & Schema;
|
|
242
|
+
type BundleComponentInstallRecord = {
|
|
243
|
+
SubscriberPackageVersion: {
|
|
244
|
+
Id: string;
|
|
245
|
+
SubscriberPackageId: string;
|
|
246
|
+
MajorVersion: number;
|
|
247
|
+
MinorVersion: number;
|
|
248
|
+
PatchVersion: number;
|
|
249
|
+
BuildNumber: number;
|
|
250
|
+
};
|
|
251
|
+
InstalledComponent?: {
|
|
252
|
+
SubscriberPackage?: {
|
|
253
|
+
Name: string;
|
|
254
|
+
};
|
|
255
|
+
};
|
|
256
|
+
SequenceOrder: number;
|
|
257
|
+
} & Schema;
|
|
258
|
+
type InstalledPackageRecord = {
|
|
259
|
+
Id: string;
|
|
260
|
+
SubscriberPackageId: string;
|
|
261
|
+
SubscriberPackage: {
|
|
262
|
+
Name: string;
|
|
263
|
+
};
|
|
264
|
+
SubscriberPackageVersion: {
|
|
265
|
+
Id: string;
|
|
266
|
+
MajorVersion: number;
|
|
267
|
+
MinorVersion: number;
|
|
268
|
+
PatchVersion: number;
|
|
269
|
+
BuildNumber: number;
|
|
270
|
+
};
|
|
271
|
+
} & Schema;
|
|
150
272
|
}
|
|
@@ -17,5 +17,19 @@ var BundleSObjects;
|
|
|
17
17
|
PkgBundleVersionInstallReqStatus["success"] = "Success";
|
|
18
18
|
PkgBundleVersionInstallReqStatus["error"] = "Error";
|
|
19
19
|
})(PkgBundleVersionInstallReqStatus = BundleSObjects.PkgBundleVersionInstallReqStatus || (BundleSObjects.PkgBundleVersionInstallReqStatus = {}));
|
|
20
|
+
let PkgBundleVersionUninstallReqStatus;
|
|
21
|
+
(function (PkgBundleVersionUninstallReqStatus) {
|
|
22
|
+
PkgBundleVersionUninstallReqStatus["queued"] = "Queued";
|
|
23
|
+
PkgBundleVersionUninstallReqStatus["inProgress"] = "InProgress";
|
|
24
|
+
PkgBundleVersionUninstallReqStatus["success"] = "Success";
|
|
25
|
+
PkgBundleVersionUninstallReqStatus["error"] = "Error";
|
|
26
|
+
})(PkgBundleVersionUninstallReqStatus = BundleSObjects.PkgBundleVersionUninstallReqStatus || (BundleSObjects.PkgBundleVersionUninstallReqStatus = {}));
|
|
27
|
+
let PkgBundleVerCpntUnistlReqStatus;
|
|
28
|
+
(function (PkgBundleVerCpntUnistlReqStatus) {
|
|
29
|
+
PkgBundleVerCpntUnistlReqStatus["queued"] = "Queued";
|
|
30
|
+
PkgBundleVerCpntUnistlReqStatus["inProgress"] = "InProgress";
|
|
31
|
+
PkgBundleVerCpntUnistlReqStatus["success"] = "Success";
|
|
32
|
+
PkgBundleVerCpntUnistlReqStatus["error"] = "Error";
|
|
33
|
+
})(PkgBundleVerCpntUnistlReqStatus = BundleSObjects.PkgBundleVerCpntUnistlReqStatus || (BundleSObjects.PkgBundleVerCpntUnistlReqStatus = {}));
|
|
20
34
|
})(BundleSObjects || (exports.BundleSObjects = BundleSObjects = {}));
|
|
21
35
|
//# sourceMappingURL=bundleSObjects.js.map
|
package/lib/package/index.d.ts
CHANGED
package/lib/package/index.js
CHANGED
|
@@ -39,4 +39,5 @@ Object.defineProperty(exports, "VersionNumber", { enumerable: true, get: functio
|
|
|
39
39
|
__exportStar(require("./packageBundle"), exports);
|
|
40
40
|
__exportStar(require("./packageBundleVersion"), exports);
|
|
41
41
|
__exportStar(require("./packageBundleInstall"), exports);
|
|
42
|
+
__exportStar(require("./packageBundleUninstall"), exports);
|
|
42
43
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Connection } from '@salesforce/core';
|
|
2
|
+
import { BundleSObjects } from '../interfaces';
|
|
3
|
+
export declare class PackageBundleInstalledList {
|
|
4
|
+
/**
|
|
5
|
+
* Get all installed package bundles in the target org
|
|
6
|
+
*
|
|
7
|
+
* @param connection - Connection to the target org (where bundles are installed)
|
|
8
|
+
* @returns Array of installed bundle versions with their component packages
|
|
9
|
+
*/
|
|
10
|
+
static getInstalledBundles(connection: Connection): Promise<BundleSObjects.InstalledPackageBundleVersion[]>;
|
|
11
|
+
/**
|
|
12
|
+
* Get the component packages for a specific installed bundle
|
|
13
|
+
*
|
|
14
|
+
* @param connection - Connection to the target org
|
|
15
|
+
* @param installedBundleVersionId - The InstalledPackageBundleVersion ID
|
|
16
|
+
* @returns Array of components with expected and actual package versions
|
|
17
|
+
*/
|
|
18
|
+
private static getBundleComponents;
|
|
19
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PackageBundleInstalledList = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2026, Salesforce, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
const core_1 = require("@salesforce/core");
|
|
20
|
+
const bundleUtils_1 = require("../utils/bundleUtils");
|
|
21
|
+
core_1.Messages.importMessagesDirectory(__dirname);
|
|
22
|
+
const messages = core_1.Messages.loadMessages('@salesforce/packaging', 'bundle_installed_list');
|
|
23
|
+
class PackageBundleInstalledList {
|
|
24
|
+
/**
|
|
25
|
+
* Get all installed package bundles in the target org
|
|
26
|
+
*
|
|
27
|
+
* @param connection - Connection to the target org (where bundles are installed)
|
|
28
|
+
* @returns Array of installed bundle versions with their component packages
|
|
29
|
+
*/
|
|
30
|
+
static async getInstalledBundles(connection) {
|
|
31
|
+
try {
|
|
32
|
+
// Query InstalledPkgBundleVersion directly from the target org
|
|
33
|
+
// Note: PackageBundle and PackageBundleVersion are CROSSORGFOREIGNKEY fields
|
|
34
|
+
// Use CreatedDate and LastModifiedDate as proxies for InstalledDate and LastUpgradedDate
|
|
35
|
+
const query = 'SELECT Id, BundleName, BundleVersionName, MajorVersion, MinorVersion, ' +
|
|
36
|
+
'PackageBundleId, PackageBundleVersionId, CreatedDate, LastModifiedDate ' +
|
|
37
|
+
'FROM InstalledPkgBundleVersion ' +
|
|
38
|
+
'ORDER BY CreatedDate DESC';
|
|
39
|
+
const queryResult = await connection.autoFetchQuery(query, {
|
|
40
|
+
tooling: true,
|
|
41
|
+
});
|
|
42
|
+
if (!queryResult.records || queryResult.records.length === 0) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
// For each installed bundle, get component details
|
|
46
|
+
const installedBundles = await Promise.all(queryResult.records.map(async (record) => {
|
|
47
|
+
// Get component details from PkgBundleVersionComponentInstallReq
|
|
48
|
+
// We need to find the install request that corresponds to this installed bundle
|
|
49
|
+
const components = await PackageBundleInstalledList.getBundleComponents(connection, record.Id);
|
|
50
|
+
return {
|
|
51
|
+
Id: record.Id,
|
|
52
|
+
BundleName: record.BundleName,
|
|
53
|
+
BundleId: record.PackageBundleId ?? '',
|
|
54
|
+
BundleVersionId: record.PackageBundleVersionId ?? '',
|
|
55
|
+
BundleVersionName: record.BundleVersionName,
|
|
56
|
+
MajorVersion: record.MajorVersion,
|
|
57
|
+
MinorVersion: record.MinorVersion,
|
|
58
|
+
Description: '',
|
|
59
|
+
InstalledDate: record.CreatedDate ?? '',
|
|
60
|
+
LastUpgradedDate: record.LastModifiedDate ?? record.CreatedDate ?? '',
|
|
61
|
+
Components: components,
|
|
62
|
+
};
|
|
63
|
+
}));
|
|
64
|
+
// Filter out any null results
|
|
65
|
+
return installedBundles.filter((bundle) => bundle !== null);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
const error = err instanceof Error ? err : new Error(messages.getMessage('failedToGetInstalledBundles'));
|
|
69
|
+
throw core_1.SfError.wrap((0, bundleUtils_1.massageErrorMessage)(error));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get the component packages for a specific installed bundle
|
|
74
|
+
*
|
|
75
|
+
* @param connection - Connection to the target org
|
|
76
|
+
* @param installedBundleVersionId - The InstalledPackageBundleVersion ID
|
|
77
|
+
* @returns Array of components with expected and actual package versions
|
|
78
|
+
*/
|
|
79
|
+
static async getBundleComponents(connection, installedBundleVersionId) {
|
|
80
|
+
// First find the install request that created this installed bundle
|
|
81
|
+
const installRequestQuery = 'SELECT Id ' +
|
|
82
|
+
'FROM PkgBundleVersionInstallReq ' +
|
|
83
|
+
`WHERE InstalledPkgBundleVersionId = '${installedBundleVersionId}' ` +
|
|
84
|
+
'ORDER BY CreatedDate DESC LIMIT 1';
|
|
85
|
+
const installRequestResult = await connection.autoFetchQuery(installRequestQuery, {
|
|
86
|
+
tooling: true,
|
|
87
|
+
});
|
|
88
|
+
if (!installRequestResult.records || installRequestResult.records.length === 0) {
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
const installRequestId = installRequestResult.records[0].Id;
|
|
92
|
+
// Query expected packages from PkgBundleVerCpntIstlReq (abbreviated name)
|
|
93
|
+
// These have SubscriberPackageVersion as a foreign key showing what was expected
|
|
94
|
+
// Use InstalledComponent to get the actual package name from InstalledSubscriberPackage
|
|
95
|
+
const componentQuery = 'SELECT SubscriberPackageVersion.Id, SubscriberPackageVersion.SubscriberPackageId, ' +
|
|
96
|
+
'SubscriberPackageVersion.MajorVersion, SubscriberPackageVersion.MinorVersion, ' +
|
|
97
|
+
'SubscriberPackageVersion.PatchVersion, SubscriberPackageVersion.BuildNumber, ' +
|
|
98
|
+
'InstalledComponent.SubscriberPackage.Name, ' +
|
|
99
|
+
'SequenceOrder ' +
|
|
100
|
+
'FROM PkgBundleVerCpntIstlReq ' +
|
|
101
|
+
`WHERE PkgBundleVersionInstallReqId = '${installRequestId}' ` +
|
|
102
|
+
'ORDER BY SequenceOrder';
|
|
103
|
+
const componentResult = await connection.autoFetchQuery(componentQuery, {
|
|
104
|
+
tooling: true,
|
|
105
|
+
});
|
|
106
|
+
if (!componentResult.records || componentResult.records.length === 0) {
|
|
107
|
+
return [];
|
|
108
|
+
}
|
|
109
|
+
// Query actual installed packages from the org
|
|
110
|
+
const installedPackagesQuery = 'SELECT Id, SubscriberPackageId, SubscriberPackage.Name, SubscriberPackageVersion.Id, ' +
|
|
111
|
+
'SubscriberPackageVersion.MajorVersion, SubscriberPackageVersion.MinorVersion, ' +
|
|
112
|
+
'SubscriberPackageVersion.PatchVersion, SubscriberPackageVersion.BuildNumber ' +
|
|
113
|
+
'FROM InstalledSubscriberPackage ' +
|
|
114
|
+
'ORDER BY SubscriberPackageId';
|
|
115
|
+
const installedResult = await connection.autoFetchQuery(installedPackagesQuery, {
|
|
116
|
+
tooling: true,
|
|
117
|
+
});
|
|
118
|
+
// Create a map of actually installed packages by subscriber package ID
|
|
119
|
+
const installedMap = new Map();
|
|
120
|
+
if (installedResult.records) {
|
|
121
|
+
installedResult.records.forEach((pkg) => {
|
|
122
|
+
const versionNumber = `${pkg.SubscriberPackageVersion.MajorVersion}.${pkg.SubscriberPackageVersion.MinorVersion}.${pkg.SubscriberPackageVersion.PatchVersion}.${pkg.SubscriberPackageVersion.BuildNumber}`;
|
|
123
|
+
installedMap.set(pkg.SubscriberPackageId, {
|
|
124
|
+
name: pkg.SubscriberPackage.Name,
|
|
125
|
+
version: versionNumber,
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
// Compare expected vs actual
|
|
130
|
+
return componentResult.records.map((record) => {
|
|
131
|
+
// Expected (what the bundle was supposed to install)
|
|
132
|
+
const expectedVersion = `${record.SubscriberPackageVersion.MajorVersion}.${record.SubscriberPackageVersion.MinorVersion}.${record.SubscriberPackageVersion.PatchVersion}.${record.SubscriberPackageVersion.BuildNumber}`;
|
|
133
|
+
const expectedName = record.InstalledComponent?.SubscriberPackage?.Name ?? 'Unknown';
|
|
134
|
+
const subscriberPackageId = record.SubscriberPackageVersion.SubscriberPackageId;
|
|
135
|
+
// Actual (what's currently installed in the org)
|
|
136
|
+
const installed = installedMap.get(subscriberPackageId);
|
|
137
|
+
return {
|
|
138
|
+
ExpectedPackageName: expectedName,
|
|
139
|
+
ExpectedPackageVersionNumber: expectedVersion,
|
|
140
|
+
ActualPackageName: installed ? installed.name : 'Uninstalled',
|
|
141
|
+
ActualPackageVersionNumber: installed ? installed.version : 'N/A',
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.PackageBundleInstalledList = PackageBundleInstalledList;
|
|
147
|
+
//# sourceMappingURL=packageBundleInstalledList.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Connection, SfProject } from '@salesforce/core';
|
|
2
|
+
import { BundleSObjects, BundleUninstallOptions } from '../interfaces';
|
|
3
|
+
export declare class PackageBundleUninstall {
|
|
4
|
+
static getUninstallStatus(uninstallRequestId: string, connection: Connection): Promise<BundleSObjects.PkgBundleVerUninstallReqResult>;
|
|
5
|
+
static getUninstallStatuses(connection: Connection, status?: BundleSObjects.PkgBundleVersionUninstallReqStatus, createdLastDays?: number): Promise<BundleSObjects.PkgBundleVerUninstallReqResult[]>;
|
|
6
|
+
static uninstallBundle(connection: Connection, project: SfProject, options: BundleUninstallOptions): Promise<BundleSObjects.PkgBundleVerUninstallReqResult>;
|
|
7
|
+
private static parsePackageBundleVersionId;
|
|
8
|
+
private static pollUninstallStatus;
|
|
9
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PackageBundleUninstall = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2026, Salesforce, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
const core_1 = require("@salesforce/core");
|
|
20
|
+
const kit_1 = require("@salesforce/kit");
|
|
21
|
+
const interfaces_1 = require("../interfaces");
|
|
22
|
+
const bundleUtils_1 = require("../utils/bundleUtils");
|
|
23
|
+
core_1.Messages.importMessagesDirectory(__dirname);
|
|
24
|
+
const messages = core_1.Messages.loadMessages('@salesforce/packaging', 'bundle_uninstall');
|
|
25
|
+
const installMessages = core_1.Messages.loadMessages('@salesforce/packaging', 'bundle_install');
|
|
26
|
+
class PackageBundleUninstall {
|
|
27
|
+
static async getUninstallStatus(uninstallRequestId, connection) {
|
|
28
|
+
try {
|
|
29
|
+
const query = 'SELECT Id, UninstallStatus, PackageBundleVersionId, InstalledPkgBundleVersionId, ValidationError, ' +
|
|
30
|
+
'CreatedDate, CreatedById ' +
|
|
31
|
+
`FROM PkgBundleVerUninstallReq WHERE Id = '${uninstallRequestId}'`;
|
|
32
|
+
const queryResult = await connection.autoFetchQuery(query, {
|
|
33
|
+
tooling: true,
|
|
34
|
+
});
|
|
35
|
+
if (!queryResult.records || queryResult.records.length === 0) {
|
|
36
|
+
throw new Error(messages.getMessage('failedToGetPackageBundleUninstallStatus'));
|
|
37
|
+
}
|
|
38
|
+
const record = queryResult.records[0];
|
|
39
|
+
return {
|
|
40
|
+
Id: record.Id,
|
|
41
|
+
UninstallStatus: record.UninstallStatus,
|
|
42
|
+
PackageBundleVersionId: record.PackageBundleVersionId ?? '',
|
|
43
|
+
InstalledPkgBundleVersionId: record.InstalledPkgBundleVersionId ?? '',
|
|
44
|
+
ValidationError: record.ValidationError ?? '',
|
|
45
|
+
CreatedDate: record.CreatedDate ?? '',
|
|
46
|
+
CreatedById: record.CreatedById ?? '',
|
|
47
|
+
Error: record.Error,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
const error = err instanceof Error ? err : new Error(messages.getMessage('failedToGetPackageBundleUninstallStatus'));
|
|
52
|
+
throw core_1.SfError.wrap((0, bundleUtils_1.massageErrorMessage)(error));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
static async getUninstallStatuses(connection, status, createdLastDays) {
|
|
56
|
+
let query = 'SELECT Id, UninstallStatus, PackageBundleVersionId, InstalledPkgBundleVersionId, ValidationError, ' +
|
|
57
|
+
'CreatedDate, CreatedById ' +
|
|
58
|
+
'FROM PkgBundleVerUninstallReq';
|
|
59
|
+
if (status && createdLastDays) {
|
|
60
|
+
query += ` WHERE UninstallStatus = '${status}' AND CreatedDate = LAST_N_DAYS: ${createdLastDays}`;
|
|
61
|
+
}
|
|
62
|
+
else if (status) {
|
|
63
|
+
query += ` WHERE UninstallStatus = '${status}'`;
|
|
64
|
+
}
|
|
65
|
+
else if (createdLastDays) {
|
|
66
|
+
query += ` WHERE CreatedDate = LAST_N_DAYS: ${createdLastDays}`;
|
|
67
|
+
}
|
|
68
|
+
const queryResult = await connection.autoFetchQuery(query, {
|
|
69
|
+
tooling: true,
|
|
70
|
+
});
|
|
71
|
+
return queryResult.records.map((record) => ({
|
|
72
|
+
Id: record.Id,
|
|
73
|
+
UninstallStatus: record.UninstallStatus,
|
|
74
|
+
PackageBundleVersionId: record.PackageBundleVersionId ?? '',
|
|
75
|
+
InstalledPkgBundleVersionId: record.InstalledPkgBundleVersionId ?? '',
|
|
76
|
+
ValidationError: record.ValidationError ?? '',
|
|
77
|
+
CreatedDate: record.CreatedDate ?? '',
|
|
78
|
+
CreatedById: record.CreatedById ?? '',
|
|
79
|
+
Error: record.Error,
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
static async uninstallBundle(connection, project, options) {
|
|
83
|
+
const packageBundleVersionId = PackageBundleUninstall.parsePackageBundleVersionId(options.PackageBundleVersion, project);
|
|
84
|
+
const request = {
|
|
85
|
+
PackageBundleVersionId: packageBundleVersionId,
|
|
86
|
+
};
|
|
87
|
+
let uninstallResult;
|
|
88
|
+
try {
|
|
89
|
+
uninstallResult = await connection.tooling.sobject('PkgBundleVerUninstallReq').create(request);
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
const error = err instanceof Error
|
|
93
|
+
? err
|
|
94
|
+
: new Error(typeof err === 'string' ? err : messages.getMessage('failedToUninstallPackageBundle'));
|
|
95
|
+
throw core_1.SfError.wrap((0, bundleUtils_1.massageErrorMessage)(error));
|
|
96
|
+
}
|
|
97
|
+
if (!uninstallResult?.success) {
|
|
98
|
+
throw core_1.SfError.wrap((0, bundleUtils_1.massageErrorMessage)(new Error(messages.getMessage('failedToUninstallPackageBundle'))));
|
|
99
|
+
}
|
|
100
|
+
if (options.polling) {
|
|
101
|
+
return PackageBundleUninstall.pollUninstallStatus(uninstallResult.id, connection, options.polling);
|
|
102
|
+
}
|
|
103
|
+
// When not polling, query the actual status from the server to get accurate information
|
|
104
|
+
return PackageBundleUninstall.getUninstallStatus(uninstallResult.id, connection);
|
|
105
|
+
}
|
|
106
|
+
static parsePackageBundleVersionId(packageBundleVersion, project) {
|
|
107
|
+
// Check if it's already an ID (starts with appropriate prefix)
|
|
108
|
+
if (/^1Q8.{15}$/.test(packageBundleVersion)) {
|
|
109
|
+
return packageBundleVersion;
|
|
110
|
+
}
|
|
111
|
+
// Otherwise, treat it as an alias and resolve it from sfdx-project.json
|
|
112
|
+
const packageBundleVersionId = project.getPackageBundleIdFromAlias(packageBundleVersion);
|
|
113
|
+
if (!packageBundleVersionId) {
|
|
114
|
+
throw new core_1.SfError(installMessages.getMessage('noPackageBundleVersionFoundWithAlias', [packageBundleVersion]));
|
|
115
|
+
}
|
|
116
|
+
return packageBundleVersionId;
|
|
117
|
+
}
|
|
118
|
+
static async pollUninstallStatus(uninstallRequestId, connection, polling) {
|
|
119
|
+
if (polling.timeout?.milliseconds <= 0) {
|
|
120
|
+
return PackageBundleUninstall.getUninstallStatus(uninstallRequestId, connection);
|
|
121
|
+
}
|
|
122
|
+
let remainingWaitTime = polling.timeout;
|
|
123
|
+
const pollingClient = await core_1.PollingClient.create({
|
|
124
|
+
poll: async () => {
|
|
125
|
+
const report = await PackageBundleUninstall.getUninstallStatus(uninstallRequestId, connection);
|
|
126
|
+
switch (report.UninstallStatus) {
|
|
127
|
+
case interfaces_1.BundleSObjects.PkgBundleVersionUninstallReqStatus.queued:
|
|
128
|
+
case interfaces_1.BundleSObjects.PkgBundleVersionUninstallReqStatus.inProgress:
|
|
129
|
+
// Emit progress event for UI updates
|
|
130
|
+
await core_1.Lifecycle.getInstance().emit('bundle-uninstall-progress', { ...report, remainingWaitTime });
|
|
131
|
+
remainingWaitTime = kit_1.Duration.seconds(remainingWaitTime.seconds - polling.frequency.seconds);
|
|
132
|
+
return {
|
|
133
|
+
completed: false,
|
|
134
|
+
payload: report,
|
|
135
|
+
};
|
|
136
|
+
case interfaces_1.BundleSObjects.PkgBundleVersionUninstallReqStatus.success:
|
|
137
|
+
return { completed: true, payload: report };
|
|
138
|
+
case interfaces_1.BundleSObjects.PkgBundleVersionUninstallReqStatus.error:
|
|
139
|
+
return { completed: true, payload: report };
|
|
140
|
+
default:
|
|
141
|
+
await core_1.Lifecycle.getInstance().emit('bundle-uninstall-progress', { ...report, remainingWaitTime });
|
|
142
|
+
remainingWaitTime = kit_1.Duration.seconds(remainingWaitTime.seconds - polling.frequency.seconds);
|
|
143
|
+
return {
|
|
144
|
+
completed: false,
|
|
145
|
+
payload: report,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
frequency: polling.frequency,
|
|
150
|
+
timeout: polling.timeout,
|
|
151
|
+
});
|
|
152
|
+
try {
|
|
153
|
+
return await pollingClient.subscribe();
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
const report = await PackageBundleUninstall.getUninstallStatus(uninstallRequestId, connection);
|
|
157
|
+
if (err instanceof Error) {
|
|
158
|
+
const timeoutError = new core_1.SfError(messages.getMessage('uninstallTimedOut', [uninstallRequestId]), 'BundleUninstallTimeout');
|
|
159
|
+
timeoutError.setData({ UninstallRequestId: uninstallRequestId, ...report });
|
|
160
|
+
throw timeoutError;
|
|
161
|
+
}
|
|
162
|
+
throw err;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.PackageBundleUninstall = PackageBundleUninstall;
|
|
167
|
+
//# sourceMappingURL=packageBundleUninstall.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# failedToGetPackageBundleUninstallStatus
|
|
2
|
+
|
|
3
|
+
Failed to get package bundle uninstall status
|
|
4
|
+
|
|
5
|
+
# failedToUninstallPackageBundle
|
|
6
|
+
|
|
7
|
+
Failed to uninstall package bundle
|
|
8
|
+
|
|
9
|
+
# uninstallTimedOut
|
|
10
|
+
|
|
11
|
+
Uninstall request %s timed out while waiting for completion.
|
|
12
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/packaging",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.22.0",
|
|
4
4
|
"description": "Packaging library for the Salesforce packaging platform",
|
|
5
5
|
"main": "lib/exported",
|
|
6
6
|
"types": "lib/exported.d.ts",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@salesforce/core": "^8.27.1",
|
|
47
47
|
"@salesforce/kit": "^3.2.6",
|
|
48
48
|
"@salesforce/schemas": "^1.10.3",
|
|
49
|
-
"@salesforce/source-deploy-retrieve": "^12.31.
|
|
49
|
+
"@salesforce/source-deploy-retrieve": "^12.31.30",
|
|
50
50
|
"@salesforce/ts-types": "^2.0.12",
|
|
51
51
|
"@salesforce/types": "^1.7.1",
|
|
52
52
|
"fast-xml-parser": "^5.5.9",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"object-treeify": "^2"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@salesforce/cli-plugins-testkit": "^5.3.
|
|
61
|
+
"@salesforce/cli-plugins-testkit": "^5.3.49",
|
|
62
62
|
"@salesforce/dev-scripts": "^11.0.4",
|
|
63
63
|
"@types/globby": "^9.1.0",
|
|
64
64
|
"@types/jszip": "^3.4.1",
|