@salesforce/packaging 0.0.26 → 0.0.29
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/CHANGELOG.md +18 -0
- package/lib/interfaces/packagingInterfacesAndType.d.ts +11 -3
- package/lib/package/packageVersion.d.ts +3 -3
- package/lib/package/packageVersion.js +25 -4
- package/lib/package/packageVersionCreate.js +14 -10
- package/lib/package/packageVersionList.d.ts +5 -7
- package/lib/package/packageVersionList.js +20 -27
- package/lib/utils/packageUtils.d.ts +2 -1
- package/lib/utils/packageUtils.js +90 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.0.29](https://github.com/forcedotcom/packaging/compare/v0.0.28...v0.0.29) (2022-08-26)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
- add PackageVersion.update, NUTs ([af8a816](https://github.com/forcedotcom/packaging/commit/af8a8167d5fbcf7056f7b72db49e4e9f6ed0363f))
|
|
10
|
+
|
|
11
|
+
### [0.0.28](https://github.com/forcedotcom/packaging/compare/v0.0.27...v0.0.28) (2022-08-26)
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
- finish pvl, implement a few missing things ([9bb825c](https://github.com/forcedotcom/packaging/commit/9bb825c97b6cb8c8b9522ddcb5e5fb32e5653995))
|
|
16
|
+
|
|
17
|
+
### [0.0.27](https://github.com/forcedotcom/packaging/compare/v0.0.26...v0.0.27) (2022-08-26)
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
- fix validateDependencyValues ([e37ac1e](https://github.com/forcedotcom/packaging/commit/e37ac1e08f5d764aefa8cf04271c6e72a30d78ea))
|
|
22
|
+
|
|
5
23
|
### [0.0.26](https://github.com/forcedotcom/packaging/compare/v0.0.25...v0.0.26) (2022-08-25)
|
|
6
24
|
|
|
7
25
|
### Bug Fixes
|
|
@@ -147,17 +147,25 @@ export declare type PackageVersionCreateRequest = {
|
|
|
147
147
|
CalculateCodeCoverage: boolean;
|
|
148
148
|
SkipValidation: boolean;
|
|
149
149
|
};
|
|
150
|
-
export declare type
|
|
151
|
-
project: SfProject;
|
|
150
|
+
export declare type PackageVersionListOptions = {
|
|
152
151
|
orderBy: string;
|
|
153
152
|
modifiedLastDays: number;
|
|
154
153
|
createdLastDays: number;
|
|
155
154
|
packages: string[];
|
|
156
|
-
connection: Connection;
|
|
157
155
|
verbose: boolean;
|
|
158
156
|
concise: boolean;
|
|
159
157
|
isReleased: boolean;
|
|
160
158
|
};
|
|
159
|
+
export declare type PackageVersionUpdateOptions = {
|
|
160
|
+
InstallKey?: string;
|
|
161
|
+
VersionName?: string;
|
|
162
|
+
VersionDescription?: string;
|
|
163
|
+
Branch?: string;
|
|
164
|
+
Tag?: string;
|
|
165
|
+
};
|
|
166
|
+
export declare type ListPackageVersionOptions = PackageVersionListOptions & {
|
|
167
|
+
connection: Connection;
|
|
168
|
+
};
|
|
161
169
|
export declare type PackageSaveResult = SaveResult;
|
|
162
170
|
export declare type PackageVersionCreateRequestOptions = {
|
|
163
171
|
path: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Duration } from '@salesforce/kit';
|
|
2
|
-
import { PackageSaveResult, PackageVersionCreateOptions, PackageVersionCreateRequestResult, PackageVersionOptions, PackageVersionReportResult } from '../interfaces';
|
|
2
|
+
import { PackageSaveResult, PackageVersionCreateOptions, PackageVersionCreateRequestResult, PackageVersionListOptions, PackageVersionListResult, PackageVersionOptions, PackageVersionReportResult, PackageVersionUpdateOptions } from '../interfaces';
|
|
3
3
|
export declare class PackageVersion {
|
|
4
4
|
private options;
|
|
5
5
|
private readonly project;
|
|
@@ -56,10 +56,10 @@ export declare class PackageVersion {
|
|
|
56
56
|
}): Promise<PackageVersionCreateRequestResult>;
|
|
57
57
|
convert(): Promise<void>;
|
|
58
58
|
install(): Promise<void>;
|
|
59
|
-
list(): Promise<
|
|
59
|
+
list(options: PackageVersionListOptions): Promise<PackageVersionListResult[]>;
|
|
60
60
|
uninstall(): Promise<void>;
|
|
61
61
|
promote(id: string): Promise<PackageSaveResult>;
|
|
62
|
-
update(): Promise<
|
|
62
|
+
update(id: string, options: PackageVersionUpdateOptions): Promise<PackageSaveResult>;
|
|
63
63
|
private updateDeprecation;
|
|
64
64
|
private updateProjectWithPackageVersion;
|
|
65
65
|
}
|
|
@@ -13,6 +13,7 @@ const utils_1 = require("../utils");
|
|
|
13
13
|
const packageVersionCreate_1 = require("./packageVersionCreate");
|
|
14
14
|
const packageVersionReport_1 = require("./packageVersionReport");
|
|
15
15
|
const packageVersionCreateRequestReport_1 = require("./packageVersionCreateRequestReport");
|
|
16
|
+
const packageVersionList_1 = require("./packageVersionList");
|
|
16
17
|
core_1.Messages.importMessagesDirectory(__dirname);
|
|
17
18
|
class PackageVersion {
|
|
18
19
|
constructor(options) {
|
|
@@ -153,8 +154,8 @@ class PackageVersion {
|
|
|
153
154
|
install() {
|
|
154
155
|
return Promise.resolve(undefined);
|
|
155
156
|
}
|
|
156
|
-
list() {
|
|
157
|
-
return
|
|
157
|
+
async list(options) {
|
|
158
|
+
return (await (0, packageVersionList_1.listPackageVersions)({ ...options, ...{ connection: this.connection } })).records;
|
|
158
159
|
}
|
|
159
160
|
uninstall() {
|
|
160
161
|
return Promise.resolve(undefined);
|
|
@@ -166,8 +167,28 @@ class PackageVersion {
|
|
|
166
167
|
}
|
|
167
168
|
return await this.options.connection.tooling.update('Package2Version', { IsReleased: true, Id: id });
|
|
168
169
|
}
|
|
169
|
-
update() {
|
|
170
|
-
|
|
170
|
+
async update(id, options) {
|
|
171
|
+
// ID can be an 04t or 05i
|
|
172
|
+
(0, utils_1.validateId)([utils_1.BY_LABEL.SUBSCRIBER_PACKAGE_VERSION_ID, utils_1.BY_LABEL.PACKAGE_VERSION_ID], id);
|
|
173
|
+
// lookup the 05i ID, if needed
|
|
174
|
+
id = await (0, utils_1.getPackageVersionId)(id, this.connection);
|
|
175
|
+
const request = {
|
|
176
|
+
Id: id,
|
|
177
|
+
InstallKey: options.InstallKey,
|
|
178
|
+
Name: options.VersionName,
|
|
179
|
+
Description: options.VersionDescription,
|
|
180
|
+
Branch: options.Branch,
|
|
181
|
+
Tag: options.Tag,
|
|
182
|
+
};
|
|
183
|
+
// filter out any undefined values and their keys
|
|
184
|
+
Object.keys(request).forEach((key) => request[key] === undefined && delete request[key]);
|
|
185
|
+
const result = await this.connection.tooling.update('Package2Version', request);
|
|
186
|
+
if (!result.success) {
|
|
187
|
+
throw new Error(result.errors.join(', '));
|
|
188
|
+
}
|
|
189
|
+
// Use the 04t ID for the success message
|
|
190
|
+
result.id = await (0, utils_1.getSubscriberPackageVersionId)(id, this.connection);
|
|
191
|
+
return result;
|
|
171
192
|
}
|
|
172
193
|
async updateDeprecation(idOrAlias, IsDeprecated) {
|
|
173
194
|
const packageVersionId = (0, utils_1.getPackageIdFromAlias)(idOrAlias, this.project);
|
|
@@ -14,7 +14,6 @@ const core_1 = require("@salesforce/core");
|
|
|
14
14
|
const source_deploy_retrieve_1 = require("@salesforce/source-deploy-retrieve");
|
|
15
15
|
const scratchOrgSettingsGenerator_1 = require("@salesforce/core/lib/org/scratchOrgSettingsGenerator");
|
|
16
16
|
const xml2js = require("xml2js");
|
|
17
|
-
const scratchOrgInfoGenerator_1 = require("@salesforce/core/lib/org/scratchOrgInfoGenerator");
|
|
18
17
|
const uniqid_1 = require("../utils/uniqid");
|
|
19
18
|
const pkgUtils = require("../utils/packageUtils");
|
|
20
19
|
const versionNumber_1 = require("../utils/versionNumber");
|
|
@@ -75,19 +74,22 @@ class PackageVersionCreate {
|
|
|
75
74
|
// If valid 04t package, just return it to be used straight away.
|
|
76
75
|
if (dependency.subscriberPackageVersionId) {
|
|
77
76
|
pkgUtils.validateId(pkgUtils.BY_LABEL.SUBSCRIBER_PACKAGE_VERSION_ID, dependency.subscriberPackageVersionId);
|
|
77
|
+
return;
|
|
78
78
|
}
|
|
79
79
|
if (dependency.packageId && dependency.package) {
|
|
80
80
|
throw messages.createError('errorPackageAndPackageIdCollision', []);
|
|
81
81
|
}
|
|
82
|
+
const packageIdFromAlias = pkgUtils.getPackageIdFromAlias(dependency.packageId || dependency.package, this.project);
|
|
82
83
|
// If valid 04t package, just return it to be used straight away.
|
|
83
|
-
if (pkgUtils.validateIdNoThrow(pkgUtils.BY_LABEL.SUBSCRIBER_PACKAGE_VERSION_ID,
|
|
84
|
-
dependency.subscriberPackageVersionId =
|
|
84
|
+
if (pkgUtils.validateIdNoThrow(pkgUtils.BY_LABEL.SUBSCRIBER_PACKAGE_VERSION_ID, packageIdFromAlias)) {
|
|
85
|
+
dependency.subscriberPackageVersionId = packageIdFromAlias;
|
|
86
|
+
return;
|
|
85
87
|
}
|
|
86
|
-
if (!
|
|
88
|
+
if (!packageIdFromAlias || !dependency.versionNumber) {
|
|
87
89
|
throw messages.createError('errorDependencyPair', [JSON.stringify(dependency)]);
|
|
88
90
|
}
|
|
89
91
|
// Just override dependency.packageId value to the resolved alias.
|
|
90
|
-
dependency.packageId =
|
|
92
|
+
dependency.packageId = packageIdFromAlias;
|
|
91
93
|
pkgUtils.validateId(pkgUtils.BY_LABEL.PACKAGE_ID, dependency.packageId);
|
|
92
94
|
pkgUtils.validateVersionNumber(dependency.versionNumber, versionNumber_1.BuildNumberToken.LATEST_BUILD_NUMBER_TOKEN, versionNumber_1.BuildNumberToken.RELEASED_BUILD_NUMBER_TOKEN);
|
|
93
95
|
// Validate that the Package2 id exists on the server
|
|
@@ -96,7 +98,6 @@ class PackageVersionCreate {
|
|
|
96
98
|
if (!result.records || result.records.length !== 1) {
|
|
97
99
|
throw messages.createError('errorNoIdInHub', [dependency.packageId]);
|
|
98
100
|
}
|
|
99
|
-
return result;
|
|
100
101
|
}
|
|
101
102
|
/**
|
|
102
103
|
* A dependency in the workspace config file may be specified using either a subscriber package version id (04t)
|
|
@@ -206,7 +207,12 @@ class PackageVersionCreate {
|
|
|
206
207
|
SkipValidation: this.options.skipvalidation || false,
|
|
207
208
|
};
|
|
208
209
|
if (preserveFiles) {
|
|
209
|
-
|
|
210
|
+
const message = messages.getMessage('tempFileLocation', [packageVersTmpRoot]);
|
|
211
|
+
await core_1.Lifecycle.getInstance().emit('packageVersionCreate:preserveFiles', {
|
|
212
|
+
location: packageVersTmpRoot,
|
|
213
|
+
message,
|
|
214
|
+
});
|
|
215
|
+
logger.info(message);
|
|
210
216
|
return requestObject;
|
|
211
217
|
}
|
|
212
218
|
else {
|
|
@@ -279,9 +285,7 @@ class PackageVersionCreate {
|
|
|
279
285
|
// branch can be set via options or descriptor; option takes precedence
|
|
280
286
|
this.options.branch = this.options.branch ?? packageDescriptorJson.branch;
|
|
281
287
|
const resultValues = await Promise.all(!dependencies ? [] : dependencies.map((dependency) => this.retrieveSubscriberPackageVersionId(dependency)));
|
|
282
|
-
const ancestorId = await (0,
|
|
283
|
-
// TODO: investigate if it's ok to convert to ScratchOggInfoPayload
|
|
284
|
-
this.packageObject, this.options.project.getSfProjectJson(), await core_1.Org.create({ aliasOrUsername: this.options.connection.getUsername() }));
|
|
288
|
+
const ancestorId = await (0, utils_1.getAncestorId)(packageDescriptorJson, this.options.project, this.options.connection, this.options.versionnumber ?? packageDescriptorJson.versionNumber, this.options.skipancestorcheck);
|
|
285
289
|
// If dependencies exist, the resultValues array will contain the dependencies populated with a resolved
|
|
286
290
|
// subscriber pkg version id.
|
|
287
291
|
if (resultValues.length > 0) {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { SfProject } from '@salesforce/core';
|
|
2
1
|
import { QueryResult } from 'jsforce';
|
|
3
|
-
import { PackageVersionListResult,
|
|
2
|
+
import { PackageVersionListResult, ListPackageVersionOptions } from '../interfaces';
|
|
4
3
|
export declare const DEFAULT_ORDER_BY_FIELDS = "Package2Id, Branch, MajorVersion, MinorVersion, PatchVersion, BuildNumber";
|
|
5
|
-
export declare function listPackageVersions(options:
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function _getLastDays(paramName: string, lastDays: number): number;
|
|
4
|
+
export declare function listPackageVersions(options: ListPackageVersionOptions): Promise<QueryResult<PackageVersionListResult>>;
|
|
5
|
+
export declare function assembleQueryParts(select: string, where: string[], orderBy?: string): string;
|
|
6
|
+
export declare function constructWhere(packageIds: string[], createdLastDays: number, lastModLastDays: number, isReleased: boolean): string[];
|
|
7
|
+
export declare function validateDays(paramName: string, lastDays: number): number;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.validateDays = exports.constructWhere = exports.assembleQueryParts = exports.listPackageVersions = exports.DEFAULT_ORDER_BY_FIELDS = void 0;
|
|
10
10
|
const core_1 = require("@salesforce/core");
|
|
11
11
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
12
12
|
const utils_1 = require("../utils");
|
|
@@ -25,67 +25,60 @@ const VERBOSE_SELECT = 'SELECT Id, Package2Id, SubscriberPackageVersionId, Name,
|
|
|
25
25
|
exports.DEFAULT_ORDER_BY_FIELDS = 'Package2Id, Branch, MajorVersion, MinorVersion, PatchVersion, BuildNumber';
|
|
26
26
|
const logger = core_1.Logger.childFromRoot('packageVersionList');
|
|
27
27
|
async function listPackageVersions(options) {
|
|
28
|
-
return options.connection.tooling.query(
|
|
28
|
+
return options.connection.tooling.query(constructQuery(options));
|
|
29
29
|
}
|
|
30
30
|
exports.listPackageVersions = listPackageVersions;
|
|
31
|
-
function
|
|
31
|
+
function constructQuery(options) {
|
|
32
32
|
// construct custom WHERE clause, if applicable
|
|
33
|
-
const where =
|
|
34
|
-
|
|
35
|
-
where.push('IsReleased = true');
|
|
36
|
-
}
|
|
37
|
-
return _assembleQueryParts(options.verbose === true ? VERBOSE_SELECT : DEFAULT_SELECT, where, options.orderBy);
|
|
33
|
+
const where = constructWhere(options.packages, options.createdLastDays, options.modifiedLastDays, options.isReleased);
|
|
34
|
+
return assembleQueryParts(options.verbose === true ? VERBOSE_SELECT : DEFAULT_SELECT, where, options.orderBy);
|
|
38
35
|
}
|
|
39
|
-
|
|
40
|
-
function _assembleQueryParts(select, where, orderBy = exports.DEFAULT_ORDER_BY_FIELDS) {
|
|
36
|
+
function assembleQueryParts(select, where, orderBy) {
|
|
41
37
|
// construct ORDER BY clause
|
|
42
|
-
// TODO: validate given fields
|
|
43
38
|
const orderByPart = `ORDER BY ${orderBy ? orderBy : exports.DEFAULT_ORDER_BY_FIELDS}`;
|
|
44
39
|
const wherePart = where.length > 0 ? `WHERE ${where.join(' AND ')}` : '';
|
|
45
40
|
const query = `${select} ${wherePart} ${orderByPart}`;
|
|
46
41
|
logger.debug(query);
|
|
47
42
|
return query;
|
|
48
43
|
}
|
|
49
|
-
exports.
|
|
44
|
+
exports.assembleQueryParts = assembleQueryParts;
|
|
50
45
|
// construct custom WHERE clause parts
|
|
51
|
-
function
|
|
46
|
+
function constructWhere(packageIds, createdLastDays, lastModLastDays, isReleased) {
|
|
52
47
|
const where = [];
|
|
53
48
|
// filter on given package ids
|
|
54
|
-
if (
|
|
49
|
+
if (packageIds?.length > 0) {
|
|
55
50
|
// remove dups
|
|
56
|
-
const
|
|
57
|
-
// resolve any aliases
|
|
58
|
-
const packageIds = aliasesOrIds.map((idOrAlias) => (0, utils_1.getPackageIdFromAlias)(idOrAlias, project));
|
|
51
|
+
const uniquePackageIds = [...new Set(packageIds)];
|
|
59
52
|
// validate ids
|
|
60
|
-
|
|
53
|
+
uniquePackageIds.forEach((packageId) => {
|
|
61
54
|
(0, utils_1.validateId)(utils_1.BY_LABEL.PACKAGE_ID, packageId);
|
|
62
55
|
});
|
|
63
56
|
// stash where part
|
|
64
|
-
where.push(`Package2Id IN ('${
|
|
57
|
+
where.push(`Package2Id IN ('${uniquePackageIds.join("','")}')`);
|
|
65
58
|
}
|
|
66
59
|
// filter on created date, days ago: 0 for today, etc
|
|
67
60
|
if ((0, ts_types_1.isNumber)(createdLastDays)) {
|
|
68
|
-
createdLastDays =
|
|
61
|
+
createdLastDays = validateDays('createdlastdays', createdLastDays);
|
|
69
62
|
where.push(`CreatedDate = LAST_N_DAYS:${createdLastDays}`);
|
|
70
63
|
}
|
|
71
64
|
// filter on last mod date, days ago: 0 for today, etc
|
|
72
65
|
if ((0, ts_types_1.isNumber)(lastModLastDays)) {
|
|
73
|
-
lastModLastDays =
|
|
66
|
+
lastModLastDays = validateDays('modifiedlastdays', lastModLastDays);
|
|
74
67
|
where.push(`LastModifiedDate = LAST_N_DAYS:${lastModLastDays}`);
|
|
75
68
|
}
|
|
69
|
+
if (isReleased) {
|
|
70
|
+
where.push('IsReleased = true');
|
|
71
|
+
}
|
|
76
72
|
// exclude deleted
|
|
77
73
|
where.push('IsDeprecated = false');
|
|
78
74
|
return where;
|
|
79
75
|
}
|
|
80
|
-
exports.
|
|
81
|
-
function
|
|
82
|
-
if (isNaN(lastDays)) {
|
|
83
|
-
return 0;
|
|
84
|
-
}
|
|
76
|
+
exports.constructWhere = constructWhere;
|
|
77
|
+
function validateDays(paramName, lastDays) {
|
|
85
78
|
if (lastDays < 0) {
|
|
86
79
|
throw messages.createError('invalidDaysNumber', [paramName, `${lastDays}`]);
|
|
87
80
|
}
|
|
88
81
|
return lastDays;
|
|
89
82
|
}
|
|
90
|
-
exports.
|
|
83
|
+
exports.validateDays = validateDays;
|
|
91
84
|
//# sourceMappingURL=packageVersionList.js.map
|
|
@@ -2,7 +2,7 @@ import { Connection, NamedPackageDir, PackageDir, SfdcUrl, SfError, SfProject }
|
|
|
2
2
|
import { Duration } from '@salesforce/kit';
|
|
3
3
|
import { Many, Nullable } from '@salesforce/ts-types';
|
|
4
4
|
import { SaveError } from 'jsforce';
|
|
5
|
-
import { PackageType, PackageVersionCreateRequestResult, PackagingSObjects } from '../interfaces';
|
|
5
|
+
import { PackageDescriptorJson, PackageType, PackageVersionCreateRequestResult, PackagingSObjects } from '../interfaces';
|
|
6
6
|
export declare const VERSION_NUMBER_SEP = ".";
|
|
7
7
|
export declare type IdRegistryValue = {
|
|
8
8
|
prefix: string;
|
|
@@ -102,6 +102,7 @@ export declare function queryWithInConditionChunking<T = Record<string, unknown>
|
|
|
102
102
|
*/
|
|
103
103
|
export declare function getInClauseItemsCount(items: string[], startIndex: number, maxLength: number): number;
|
|
104
104
|
export declare function validateAncestorId(ancestorId: string, highestReleasedVersion: PackagingSObjects.Package2Version, explicitUseNoAncestor: boolean, isPatch: boolean, skipAncestorCheck: boolean, origSpecifiedAncestor: string): string;
|
|
105
|
+
export declare function getAncestorId(packageDescriptorJson: PackageDescriptorJson, project: SfProject, connection: Connection, versionNumberString: string, skipAncestorCheck: boolean): Promise<string>;
|
|
105
106
|
export declare function getAncestorIdHighestRelease(connection: Connection, packageId: string, versionNumberString: string, explicitUseHighestRelease: boolean, skipAncestorCheck: boolean): Promise<{
|
|
106
107
|
finalAncestorId: string;
|
|
107
108
|
highestReleasedVersion: PackagingSObjects.Package2Version;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.combineSaveErrors = exports.formatDate = exports.generatePackageAliasEntry = exports.pollForStatusWithInterval = exports.findOrCreatePackage = exports.getPackageAliasesFromId = exports.convertCamelCaseStringToSentence = exports.getPackageIdFromAlias = exports.getConfigPackageDirectory = exports.getConfigPackageDirectories = exports.getPackageVersionNumber = exports.concatVersion = exports.getAncestorIdHighestRelease = exports.validateAncestorId = exports.getInClauseItemsCount = exports.queryWithInConditionChunking = exports.getPackageVersionStrings = exports.getHasMetadataRemoved = exports.getContainerOptions = exports.getSubscriberPackageVersionId = exports.getPackageTypeBy04t = exports.getPackageType = exports.escapeInstallationKey = exports.getPackageVersionId = exports.applyErrorAction = exports.massageErrorMessage = exports.isErrorPackageNotAvailable = exports.isErrorFromSPVQueryRestriction = exports.validatePatchVersion = exports.validateVersionNumber = exports.validateIdNoThrow = exports.validateId = exports.BY_LABEL = exports.BY_PREFIX = exports.DEFAULT_PACKAGE_DIR = exports.POLL_INTERVAL_SECONDS = exports.SOQL_WHERE_CLAUSE_MAX_LENGTH = exports.INSTALL_URL_BASE = exports.VERSION_NUMBER_SEP = void 0;
|
|
3
|
+
exports.combineSaveErrors = exports.formatDate = exports.generatePackageAliasEntry = exports.pollForStatusWithInterval = exports.findOrCreatePackage = exports.getPackageAliasesFromId = exports.convertCamelCaseStringToSentence = exports.getPackageIdFromAlias = exports.getConfigPackageDirectory = exports.getConfigPackageDirectories = exports.getPackageVersionNumber = exports.concatVersion = exports.getAncestorIdHighestRelease = exports.getAncestorId = exports.validateAncestorId = exports.getInClauseItemsCount = exports.queryWithInConditionChunking = exports.getPackageVersionStrings = exports.getHasMetadataRemoved = exports.getContainerOptions = exports.getSubscriberPackageVersionId = exports.getPackageTypeBy04t = exports.getPackageType = exports.escapeInstallationKey = exports.getPackageVersionId = exports.applyErrorAction = exports.massageErrorMessage = exports.isErrorPackageNotAvailable = exports.isErrorFromSPVQueryRestriction = exports.validatePatchVersion = exports.validateVersionNumber = exports.validateIdNoThrow = exports.validateId = exports.BY_LABEL = exports.BY_PREFIX = exports.DEFAULT_PACKAGE_DIR = exports.POLL_INTERVAL_SECONDS = exports.SOQL_WHERE_CLAUSE_MAX_LENGTH = exports.INSTALL_URL_BASE = exports.VERSION_NUMBER_SEP = void 0;
|
|
4
4
|
/*
|
|
5
5
|
* Copyright (c) 2022, salesforce.com, inc.
|
|
6
6
|
* All rights reserved.
|
|
@@ -324,7 +324,9 @@ async function getPackageVersionStrings(subscriberPackageVersionIds, connection)
|
|
|
324
324
|
}
|
|
325
325
|
// remove any duplicate Ids
|
|
326
326
|
const ids = [...new Set(subscriberPackageVersionIds)];
|
|
327
|
-
const query =
|
|
327
|
+
const query = `SELECT SubscriberPackageVersionId, MajorVersion, MinorVersion, PatchVersion, BuildNumber FROM Package2Version WHERE SubscriberPackageVersionId IN (${ids
|
|
328
|
+
.map((id) => `'${id}'`)
|
|
329
|
+
.join(',')})`;
|
|
328
330
|
const records = await queryWithInConditionChunking(query, ids, '%IDS%', connection);
|
|
329
331
|
if (records && records.length > 0) {
|
|
330
332
|
results = new Map(records.map((record) => {
|
|
@@ -423,6 +425,92 @@ function validateAncestorId(ancestorId, highestReleasedVersion, explicitUseNoAnc
|
|
|
423
425
|
return ancestorId;
|
|
424
426
|
}
|
|
425
427
|
exports.validateAncestorId = validateAncestorId;
|
|
428
|
+
// eslint-disable-next-line complexity
|
|
429
|
+
async function getAncestorId(packageDescriptorJson, project, connection, versionNumberString, skipAncestorCheck) {
|
|
430
|
+
// If an id property is present, use it. Otherwise, look up the package id from the package property.
|
|
431
|
+
const packageId = packageDescriptorJson.id ?? getPackageIdFromAlias(packageDescriptorJson.package, project);
|
|
432
|
+
// No need to proceed if Unlocked
|
|
433
|
+
const packageType = await getPackageType(packageId, connection);
|
|
434
|
+
if (packageType === 'Unlocked') {
|
|
435
|
+
return '';
|
|
436
|
+
}
|
|
437
|
+
let ancestorId = '';
|
|
438
|
+
// ancestorID can be alias, 05i, or 04t;
|
|
439
|
+
// validate and convert to 05i, as needed
|
|
440
|
+
const versionNumber = versionNumber_1.VersionNumber.from(versionNumberString);
|
|
441
|
+
let origSpecifiedAncestor = packageDescriptorJson.ancestorId;
|
|
442
|
+
let highestReleasedVersion = null;
|
|
443
|
+
const explicitUseHighestRelease = packageDescriptorJson.ancestorId === versionNumber_1.BuildNumberToken.HIGHEST_VERSION_NUMBER_TOKEN ||
|
|
444
|
+
packageDescriptorJson.ancestorVersion === versionNumber_1.BuildNumberToken.HIGHEST_VERSION_NUMBER_TOKEN;
|
|
445
|
+
const explicitUseNoAncestor = packageDescriptorJson.ancestorId === versionNumber_1.BuildNumberToken.NONE_VERSION_NUMBER_TOKEN ||
|
|
446
|
+
packageDescriptorJson.ancestorVersion === versionNumber_1.BuildNumberToken.NONE_VERSION_NUMBER_TOKEN;
|
|
447
|
+
if ((explicitUseHighestRelease || explicitUseNoAncestor) &&
|
|
448
|
+
packageDescriptorJson.ancestorId &&
|
|
449
|
+
packageDescriptorJson.ancestorVersion) {
|
|
450
|
+
if (packageDescriptorJson.ancestorId !== packageDescriptorJson.ancestorVersion) {
|
|
451
|
+
// both ancestorId and ancestorVersion specified, HIGHEST and/or NONE are used, the values disagree
|
|
452
|
+
throw messages.createError('errorAncestorIdVersionHighestOrNoneMismatch', [
|
|
453
|
+
packageDescriptorJson.ancestorId,
|
|
454
|
+
packageDescriptorJson.ancestorVersion,
|
|
455
|
+
]);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
if (explicitUseNoAncestor && skipAncestorCheck) {
|
|
459
|
+
return '';
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
const result = await getAncestorIdHighestRelease(connection, packageId, versionNumberString, explicitUseHighestRelease, skipAncestorCheck);
|
|
463
|
+
if (result.finalAncestorId) {
|
|
464
|
+
return result.finalAncestorId;
|
|
465
|
+
}
|
|
466
|
+
highestReleasedVersion = result.highestReleasedVersion;
|
|
467
|
+
}
|
|
468
|
+
// at this point if explicitUseHighestRelease=true, we have returned the ancestorId or thrown an error
|
|
469
|
+
// highestReleasedVersion should be null only if skipAncestorCheck or if there is no existing released package version
|
|
470
|
+
if (!explicitUseNoAncestor && packageDescriptorJson.ancestorId) {
|
|
471
|
+
ancestorId = getPackageIdFromAlias(packageDescriptorJson.ancestorId, project);
|
|
472
|
+
validateId([exports.BY_LABEL.SUBSCRIBER_PACKAGE_VERSION_ID, exports.BY_LABEL.PACKAGE_VERSION_ID], ancestorId);
|
|
473
|
+
ancestorId = await getPackageVersionId(ancestorId, connection);
|
|
474
|
+
}
|
|
475
|
+
if (!explicitUseNoAncestor && packageDescriptorJson.ancestorVersion) {
|
|
476
|
+
const regNumbers = new RegExp('^[0-9]+$');
|
|
477
|
+
const versionNumber = packageDescriptorJson.ancestorVersion.split(exports.VERSION_NUMBER_SEP);
|
|
478
|
+
if (versionNumber.length < 3 ||
|
|
479
|
+
versionNumber.length > 4 ||
|
|
480
|
+
!versionNumber[0].match(regNumbers) ||
|
|
481
|
+
!versionNumber[1].match(regNumbers) ||
|
|
482
|
+
!versionNumber[2].match(regNumbers)) {
|
|
483
|
+
throw new Error(messages.getMessage('errorInvalidAncestorVersionFormat', [packageDescriptorJson.ancestorVersion]));
|
|
484
|
+
}
|
|
485
|
+
const query = 'SELECT Id, IsReleased FROM Package2Version ' +
|
|
486
|
+
`WHERE Package2Id = '${packageId}' AND MajorVersion = ${versionNumber[0]} AND MinorVersion = ${versionNumber[1]} AND PatchVersion = ${versionNumber[2]}`;
|
|
487
|
+
let queriedAncestorId;
|
|
488
|
+
const ancestorVersionResult = await connection.tooling.query(query);
|
|
489
|
+
if (!ancestorVersionResult || !ancestorVersionResult.totalSize) {
|
|
490
|
+
throw messages.createError('errorNoMatchingAncestor', [packageDescriptorJson.ancestorVersion, packageId]);
|
|
491
|
+
}
|
|
492
|
+
else {
|
|
493
|
+
const releasedAncestor = ancestorVersionResult.records.find((rec) => rec.IsReleased === true);
|
|
494
|
+
if (!releasedAncestor) {
|
|
495
|
+
throw messages.createError('errorAncestorNotReleased', [packageDescriptorJson.ancestorVersion]);
|
|
496
|
+
}
|
|
497
|
+
else {
|
|
498
|
+
queriedAncestorId = releasedAncestor.Id;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
// check for discrepancy between queried ancestorId and descriptor's ancestorId
|
|
502
|
+
if (Object.prototype.hasOwnProperty.call(packageDescriptorJson, 'ancestorId') && ancestorId !== queriedAncestorId) {
|
|
503
|
+
throw messages.createError('errorAncestorIdVersionMismatch', [
|
|
504
|
+
packageDescriptorJson.ancestorVersion,
|
|
505
|
+
packageDescriptorJson.ancestorId,
|
|
506
|
+
]);
|
|
507
|
+
}
|
|
508
|
+
ancestorId = queriedAncestorId;
|
|
509
|
+
origSpecifiedAncestor = packageDescriptorJson.ancestorVersion;
|
|
510
|
+
}
|
|
511
|
+
return validateAncestorId(ancestorId, highestReleasedVersion, explicitUseNoAncestor, versionNumber.patch !== '0', skipAncestorCheck, origSpecifiedAncestor);
|
|
512
|
+
}
|
|
513
|
+
exports.getAncestorId = getAncestorId;
|
|
426
514
|
async function getAncestorIdHighestRelease(connection, packageId, versionNumberString, explicitUseHighestRelease, skipAncestorCheck) {
|
|
427
515
|
const versionNumber = versionNumberString.split(exports.VERSION_NUMBER_SEP);
|
|
428
516
|
const isPatch = versionNumber[2] !== '0';
|