@salesforce/packaging 0.1.11 → 0.1.13
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/constants.d.ts +3 -0
- package/lib/constants.js +4 -1
- package/lib/interfaces/packagingInterfacesAndType.d.ts +20 -13
- package/lib/interfaces/packagingSObjects.d.ts +1 -1
- package/lib/package/index.d.ts +1 -5
- package/lib/package/index.js +1 -10
- package/lib/package/package.d.ts +79 -32
- package/lib/package/package.js +159 -71
- package/lib/package/packageAncestry.d.ts +3 -1
- package/lib/package/packageAncestry.js +43 -25
- package/lib/package/packageConvert.js +2 -3
- package/lib/package/packageCreate.d.ts +2 -12
- package/lib/package/packageCreate.js +30 -53
- package/lib/package/packageDelete.js +4 -1
- package/lib/package/packageInstall.d.ts +7 -14
- package/lib/package/packageInstall.js +65 -148
- package/lib/package/packageInstalledList.js +8 -2
- package/lib/package/packageUninstall.d.ts +5 -1
- package/lib/package/packageUninstall.js +51 -41
- package/lib/package/packageVersion.d.ts +53 -6
- package/lib/package/packageVersion.js +139 -29
- package/lib/package/packageVersionCreate.d.ts +2 -2
- package/lib/package/packageVersionCreate.js +27 -25
- package/lib/package/packageVersionCreateRequest.js +15 -6
- package/lib/package/packageVersionCreateRequestReport.js +9 -3
- package/lib/package/packageVersionList.js +3 -1
- package/lib/package/packageVersionReport.js +1 -27
- package/lib/package/subscriberPackageVersion.d.ts +156 -0
- package/lib/package/subscriberPackageVersion.js +346 -0
- package/lib/utils/packageUtils.d.ts +10 -11
- package/lib/utils/packageUtils.js +35 -24
- package/messages/package.md +18 -2
- package/messages/package_version.md +12 -0
- package/messages/pkg_utils.md +5 -33
- package/messages/subscriber_package_version.md +19 -0
- package/package.json +3 -3
- package/lib/package/packageList.d.ts +0 -4
- package/lib/package/packageList.js +0 -19
|
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.byId = exports.list = void 0;
|
|
10
10
|
const util = require("util");
|
|
11
11
|
const core_1 = require("@salesforce/core");
|
|
12
|
+
const utils_1 = require("../utils");
|
|
12
13
|
core_1.Messages.importMessagesDirectory(__dirname);
|
|
13
14
|
const messages = core_1.Messages.loadMessages('@salesforce/packaging', 'package_version_create');
|
|
14
15
|
const STATUS_ERROR = 'Error';
|
|
@@ -16,7 +17,7 @@ const QUERY = 'SELECT Id, Status, Package2Id, Package2VersionId, Package2Version
|
|
|
16
17
|
'CreatedDate, Package2Version.HasMetadataRemoved, CreatedById ' +
|
|
17
18
|
'FROM Package2VersionCreateRequest ' +
|
|
18
19
|
'%s' + // WHERE, if applicable
|
|
19
|
-
'ORDER BY CreatedDate';
|
|
20
|
+
'ORDER BY CreatedDate desc';
|
|
20
21
|
const ERROR_QUERY = "SELECT Message FROM Package2VersionCreateRequestError WHERE ParentRequest.Id = '%s'";
|
|
21
22
|
function formatDate(date) {
|
|
22
23
|
const pad = (num) => {
|
|
@@ -25,20 +26,25 @@ function formatDate(date) {
|
|
|
25
26
|
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
26
27
|
}
|
|
27
28
|
async function list(options) {
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
try {
|
|
30
|
+
const whereClause = _constructWhere(options);
|
|
31
|
+
return await query(util.format(QUERY, whereClause), options.connection);
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
throw (0, utils_1.applyErrorAction)((0, utils_1.massageErrorMessage)(err));
|
|
35
|
+
}
|
|
30
36
|
}
|
|
31
37
|
exports.list = list;
|
|
32
38
|
async function byId(packageVersionCreateRequestId, connection) {
|
|
33
|
-
const results = await
|
|
39
|
+
const results = await query(util.format(QUERY, `WHERE Id = '${packageVersionCreateRequestId}' `), connection);
|
|
34
40
|
if (results && results.length === 1 && results[0].Status === STATUS_ERROR) {
|
|
35
41
|
results[0].Error = await _queryErrors(packageVersionCreateRequestId, connection);
|
|
36
42
|
}
|
|
37
43
|
return results;
|
|
38
44
|
}
|
|
39
45
|
exports.byId = byId;
|
|
40
|
-
async function
|
|
41
|
-
const queryResult = await connection.
|
|
46
|
+
async function query(query, connection) {
|
|
47
|
+
const queryResult = await connection.autoFetchQuery(query, { tooling: true });
|
|
42
48
|
return (queryResult.records ? queryResult.records : []).map((record) => ({
|
|
43
49
|
Id: record.Id,
|
|
44
50
|
Status: record.Status,
|
|
@@ -65,6 +71,9 @@ async function _queryErrors(packageVersionCreateRequestId, connection) {
|
|
|
65
71
|
}
|
|
66
72
|
function _constructWhere(options) {
|
|
67
73
|
const where = [];
|
|
74
|
+
if (options?.id) {
|
|
75
|
+
where.push(`Id = '${options.id}'`);
|
|
76
|
+
}
|
|
68
77
|
// filter on created date, days ago: 0 for today, etc
|
|
69
78
|
if (options?.createdlastdays) {
|
|
70
79
|
if (options.createdlastdays < 0) {
|
|
@@ -8,11 +8,17 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.getCreatePackageVersionCreateRequestReport = void 0;
|
|
10
10
|
const pkgUtils = require("../utils/packageUtils");
|
|
11
|
+
const packageUtils_1 = require("../utils/packageUtils");
|
|
11
12
|
const packageVersionCreateRequest_1 = require("./packageVersionCreateRequest");
|
|
12
13
|
async function getCreatePackageVersionCreateRequestReport(options) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
try {
|
|
15
|
+
pkgUtils.validateId(pkgUtils.BY_LABEL.PACKAGE_VERSION_CREATE_REQUEST_ID, options.createPackageVersionRequestId);
|
|
16
|
+
const results = await (0, packageVersionCreateRequest_1.byId)(options.createPackageVersionRequestId, options.connection);
|
|
17
|
+
return results[0];
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
throw (0, packageUtils_1.applyErrorAction)((0, packageUtils_1.massageErrorMessage)(err));
|
|
21
|
+
}
|
|
16
22
|
}
|
|
17
23
|
exports.getCreatePackageVersionCreateRequestReport = getCreatePackageVersionCreateRequestReport;
|
|
18
24
|
//# sourceMappingURL=packageVersionCreateRequestReport.js.map
|
|
@@ -31,7 +31,9 @@ const getLogger = () => {
|
|
|
31
31
|
return logger;
|
|
32
32
|
};
|
|
33
33
|
async function listPackageVersions(options) {
|
|
34
|
-
return options.connection.
|
|
34
|
+
return options.connection.autoFetchQuery(constructQuery(options), {
|
|
35
|
+
tooling: true,
|
|
36
|
+
});
|
|
35
37
|
}
|
|
36
38
|
exports.listPackageVersions = listPackageVersions;
|
|
37
39
|
function constructQuery(options) {
|
|
@@ -33,32 +33,6 @@ const getLogger = () => {
|
|
|
33
33
|
}
|
|
34
34
|
return logger;
|
|
35
35
|
};
|
|
36
|
-
/**
|
|
37
|
-
* Given a list of subscriber package version IDs (04t), return the associated version strings (e.g., Major.Minor.Patch.Build)
|
|
38
|
-
*
|
|
39
|
-
* @return Map of subscriberPackageVersionId to versionString
|
|
40
|
-
* @param subscriberPackageVersionIds
|
|
41
|
-
* @param connection For tooling query
|
|
42
|
-
*/
|
|
43
|
-
async function getPackageVersionStrings(subscriberPackageVersionIds, connection) {
|
|
44
|
-
let results = new Map();
|
|
45
|
-
if (!subscriberPackageVersionIds || subscriberPackageVersionIds.length === 0) {
|
|
46
|
-
return results;
|
|
47
|
-
}
|
|
48
|
-
// remove any duplicate Ids
|
|
49
|
-
const ids = [...new Set(subscriberPackageVersionIds)];
|
|
50
|
-
const query = `SELECT SubscriberPackageVersionId, MajorVersion, MinorVersion, PatchVersion, BuildNumber FROM Package2Version WHERE SubscriberPackageVersionId IN (${ids
|
|
51
|
-
.map((id) => `'${id}'`)
|
|
52
|
-
.join(',')})`;
|
|
53
|
-
const records = await pkgUtils.queryWithInConditionChunking(query, ids, '%IDS%', connection);
|
|
54
|
-
if (records && records.length > 0) {
|
|
55
|
-
results = new Map(records.map((record) => {
|
|
56
|
-
const version = pkgUtils.concatVersion(record.MajorVersion, record.MinorVersion, record.PatchVersion, record.BuildNumber);
|
|
57
|
-
return [record.SubscriberPackageVersionId, version];
|
|
58
|
-
}));
|
|
59
|
-
}
|
|
60
|
-
return results;
|
|
61
|
-
}
|
|
62
36
|
async function getPackageVersionReport(options) {
|
|
63
37
|
getLogger().debug(`entering getPackageVersionReport(${util.inspect(options, { depth: null })})`);
|
|
64
38
|
const queryResult = await options.connection.tooling.query(util.format(options.verbose ? QUERY_VERBOSE : QUERY, options.packageVersionId));
|
|
@@ -71,7 +45,7 @@ async function getPackageVersionReport(options) {
|
|
|
71
45
|
record.AncestorVersion = null;
|
|
72
46
|
if (record.AncestorId) {
|
|
73
47
|
// lookup AncestorVersion value
|
|
74
|
-
const ancestorVersionMap = await getPackageVersionStrings([record.AncestorId], options.connection);
|
|
48
|
+
const ancestorVersionMap = await pkgUtils.getPackageVersionStrings([record.AncestorId], options.connection);
|
|
75
49
|
record.AncestorVersion = ancestorVersionMap.get(record.AncestorId);
|
|
76
50
|
}
|
|
77
51
|
else {
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { Connection } from '@salesforce/core';
|
|
2
|
+
import { Duration } from '@salesforce/kit';
|
|
3
|
+
import { Optional } from '@salesforce/ts-types';
|
|
4
|
+
import { PackageInstallCreateRequest, PackageInstallOptions, PackageType, PackagingSObjects, SubscriberPackageVersionOptions } from '../interfaces';
|
|
5
|
+
import { VersionNumber } from '../utils';
|
|
6
|
+
export declare const SubscriberPackageVersionFields: string[];
|
|
7
|
+
/**
|
|
8
|
+
* A class that represents a SubscriberPackageVersion
|
|
9
|
+
*/
|
|
10
|
+
export declare class SubscriberPackageVersion {
|
|
11
|
+
private options;
|
|
12
|
+
private readonly password;
|
|
13
|
+
private readonly connection;
|
|
14
|
+
private readonly id;
|
|
15
|
+
private data;
|
|
16
|
+
constructor(options: SubscriberPackageVersionOptions);
|
|
17
|
+
/**
|
|
18
|
+
* Fetches the status of a package version install request and will wait for the install to complete, if requested
|
|
19
|
+
* Package Version install emits the following events:
|
|
20
|
+
* - PackageEvents.install['subscriber-status']
|
|
21
|
+
*
|
|
22
|
+
* @param connection
|
|
23
|
+
* @param packageInstallRequestOrId
|
|
24
|
+
* @param installationKey
|
|
25
|
+
* @param options
|
|
26
|
+
*/
|
|
27
|
+
static installStatus(connection: Connection, packageInstallRequestOrId: string | PackagingSObjects.PackageInstallRequest, installationKey?: string, options?: PackageInstallOptions): Promise<PackagingSObjects.PackageInstallRequest>;
|
|
28
|
+
/**
|
|
29
|
+
* Reports on the progress of a package version uninstall.
|
|
30
|
+
*
|
|
31
|
+
* @param id the 06y package version uninstall request id
|
|
32
|
+
* @param connection
|
|
33
|
+
*/
|
|
34
|
+
static uninstallStatus(id: string, connection: Connection): Promise<PackagingSObjects.SubscriberPackageVersionUninstallRequest>;
|
|
35
|
+
/**
|
|
36
|
+
* Retrieves the package version create request.
|
|
37
|
+
*
|
|
38
|
+
* @param installRequestId
|
|
39
|
+
* @param connection
|
|
40
|
+
*/
|
|
41
|
+
static getInstallRequest(installRequestId: string, connection: Connection): Promise<PackagingSObjects.PackageInstallRequest>;
|
|
42
|
+
/**
|
|
43
|
+
* Get the package version ID for this SubscriberPackageVersion.
|
|
44
|
+
*
|
|
45
|
+
* @returns The SubscriberPackageVersion Id (04t).
|
|
46
|
+
*/
|
|
47
|
+
getId(): Promise<string>;
|
|
48
|
+
/**
|
|
49
|
+
* Get the package type for this SubscriberPackageVersion.
|
|
50
|
+
*
|
|
51
|
+
* @returns {PackageType} The package type.
|
|
52
|
+
*/
|
|
53
|
+
getPackageType(): Promise<PackageType>;
|
|
54
|
+
/**
|
|
55
|
+
* Get the password passed in the constructor
|
|
56
|
+
*
|
|
57
|
+
* @returns {string} the password
|
|
58
|
+
*/
|
|
59
|
+
getPassword(): Optional<string>;
|
|
60
|
+
/**
|
|
61
|
+
* Get the subscriber package Id (033) for this SubscriberPackageVersion.
|
|
62
|
+
*
|
|
63
|
+
* @returns {string} The subscriber package Id.
|
|
64
|
+
*/
|
|
65
|
+
getSubscriberPackageId(): Promise<string>;
|
|
66
|
+
/**
|
|
67
|
+
* Get a VersionNumber instance for this SubscriberPackageVersion.
|
|
68
|
+
*
|
|
69
|
+
* @returns {VersionNumber} The version number.
|
|
70
|
+
*/
|
|
71
|
+
getVersionNumber(): Promise<VersionNumber>;
|
|
72
|
+
/**
|
|
73
|
+
* Is the package a managed package?
|
|
74
|
+
*/
|
|
75
|
+
isManaged(): Promise<boolean>;
|
|
76
|
+
/**
|
|
77
|
+
* Is the SubscriberPackageVersion deprecated?
|
|
78
|
+
*
|
|
79
|
+
* @returns {boolean} True if the SubscriberPackageVersion is deprecated.
|
|
80
|
+
*/
|
|
81
|
+
isDeprecated(): Promise<boolean>;
|
|
82
|
+
/**
|
|
83
|
+
* Is the SubscriberPackageVersion password protected?
|
|
84
|
+
*
|
|
85
|
+
* @returns {boolean} True if the SubscriberPackageVersion is password protected.
|
|
86
|
+
*/
|
|
87
|
+
isPasswordProtected(): Promise<boolean>;
|
|
88
|
+
/**
|
|
89
|
+
* Is the SubscriberPackageVersion org dependent?
|
|
90
|
+
*
|
|
91
|
+
* @returns {boolean} True if the SubscriberPackageVersion is org dependent.
|
|
92
|
+
*/
|
|
93
|
+
isOrgDependent(): Promise<boolean>;
|
|
94
|
+
/**
|
|
95
|
+
* Return remote site settings for the SubscriberPackageVersion.
|
|
96
|
+
*
|
|
97
|
+
* @returns {RemoteSiteSettings} The remote site settings.
|
|
98
|
+
*/
|
|
99
|
+
getRemoteSiteSettings(): Promise<PackagingSObjects.SubscriberPackageRemoteSiteSettings>;
|
|
100
|
+
/**
|
|
101
|
+
* Return CSP trusted sites for the SubscriberPackageVersion.
|
|
102
|
+
*
|
|
103
|
+
* @returns {CspTrustedSites} The CSP trusted sites.
|
|
104
|
+
*/
|
|
105
|
+
getCspTrustedSites(): Promise<PackagingSObjects.SubscriberPackageCspTrustedSites>;
|
|
106
|
+
/**
|
|
107
|
+
* Get the installation validation status for the SubscriberPackageVersion.
|
|
108
|
+
*
|
|
109
|
+
* @returns {InstallationValidationStatus} The installation validation status.
|
|
110
|
+
*/
|
|
111
|
+
getInstallValidationStatus(): Promise<PackagingSObjects.InstallValidationStatus>;
|
|
112
|
+
/**
|
|
113
|
+
* Get the SubscriberPackageVersion SObject data for this SubscriberPackageVersion.
|
|
114
|
+
*
|
|
115
|
+
* @param force - force a refresh of the subscriber package version data.
|
|
116
|
+
* @returns {PackagingSObjects.SubscriberPackageVersion} SObject data.
|
|
117
|
+
*/
|
|
118
|
+
getData(options?: {
|
|
119
|
+
force?: boolean;
|
|
120
|
+
includeHighCostFields?: boolean;
|
|
121
|
+
}): Promise<PackagingSObjects.SubscriberPackageVersion>;
|
|
122
|
+
/**
|
|
123
|
+
* Installs a package version in a subscriber org.
|
|
124
|
+
*
|
|
125
|
+
* Package Version install emits the following events:
|
|
126
|
+
* - PackageEvents.install.warning
|
|
127
|
+
* - PackageEvents.install.presend
|
|
128
|
+
* - PackageEvents.install.postsend
|
|
129
|
+
* - PackageEvents.install['subscriber-status']
|
|
130
|
+
*
|
|
131
|
+
* @param pkgInstallCreateRequest
|
|
132
|
+
* @param options
|
|
133
|
+
*/
|
|
134
|
+
install(pkgInstallCreateRequest: PackageInstallCreateRequest, options?: PackageInstallOptions): Promise<PackagingSObjects.PackageInstallRequest>;
|
|
135
|
+
/**
|
|
136
|
+
* Uninstalls a package version from a subscriber org.
|
|
137
|
+
*
|
|
138
|
+
* @param frequency
|
|
139
|
+
* @param wait
|
|
140
|
+
*/
|
|
141
|
+
uninstall(frequency?: Duration, wait?: Duration): Promise<PackagingSObjects.SubscriberPackageVersionUninstallRequest>;
|
|
142
|
+
/**
|
|
143
|
+
* Returns an array of RSS and CSP external sites for the package.
|
|
144
|
+
*
|
|
145
|
+
* @param installationKey The installation key (if any) for the subscriber package version.
|
|
146
|
+
* @returns an array of RSS and CSP site URLs, or undefined if the package doesn't have any.
|
|
147
|
+
*/
|
|
148
|
+
getExternalSites(): Promise<Optional<string[]>>;
|
|
149
|
+
/**
|
|
150
|
+
* Return a field value from the SubscriberPackageVersion SObject using the field name.
|
|
151
|
+
*
|
|
152
|
+
* @param field
|
|
153
|
+
*/
|
|
154
|
+
getField<T>(field: string): Promise<T>;
|
|
155
|
+
private getFieldsForQuery;
|
|
156
|
+
}
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2020, salesforce.com, inc.
|
|
4
|
+
* All rights reserved.
|
|
5
|
+
* Licensed under the BSD 3-Clause license.
|
|
6
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.SubscriberPackageVersion = exports.SubscriberPackageVersionFields = void 0;
|
|
10
|
+
const core_1 = require("@salesforce/core");
|
|
11
|
+
const kit_1 = require("@salesforce/kit");
|
|
12
|
+
const utils_1 = require("../utils");
|
|
13
|
+
const packageInstall_1 = require("./packageInstall");
|
|
14
|
+
const packageUninstall_1 = require("./packageUninstall");
|
|
15
|
+
core_1.Messages.importMessagesDirectory(__dirname);
|
|
16
|
+
const messages = core_1.Messages.loadMessages('@salesforce/packaging', 'subscriber_package_version');
|
|
17
|
+
// these fields have been identified as requiring additional serverside resources in order to calculate their values
|
|
18
|
+
// and are therefore not returned by default
|
|
19
|
+
// these will require additional queries to retrieve
|
|
20
|
+
const highCostQueryFields = [
|
|
21
|
+
'AppExchangeDescription',
|
|
22
|
+
'AppExchangeLogoUrl',
|
|
23
|
+
'AppExchangePackageName',
|
|
24
|
+
'AppExchangePublisherName',
|
|
25
|
+
'CspTrustedSite',
|
|
26
|
+
'Dependencies',
|
|
27
|
+
'PostInstallUrl',
|
|
28
|
+
'ReleaseNotesUrl',
|
|
29
|
+
'RemoteSiteSettings',
|
|
30
|
+
// 'InstallValidationStatus', // This requires extra resources on the server, but is commonly used, so let it load as part of the default query
|
|
31
|
+
'Profiles',
|
|
32
|
+
];
|
|
33
|
+
exports.SubscriberPackageVersionFields = [
|
|
34
|
+
'AppExchangeDescription',
|
|
35
|
+
'AppExchangeLogoUrl',
|
|
36
|
+
'AppExchangePackageName',
|
|
37
|
+
'AppExchangePublisherName',
|
|
38
|
+
'BuildNumber',
|
|
39
|
+
'CspTrustedSites',
|
|
40
|
+
'Dependencies',
|
|
41
|
+
'Description',
|
|
42
|
+
'Id',
|
|
43
|
+
'InstallValidationStatus',
|
|
44
|
+
'IsBeta',
|
|
45
|
+
'IsDeprecated',
|
|
46
|
+
'IsManaged',
|
|
47
|
+
'IsOrgDependent',
|
|
48
|
+
'IsPasswordProtected',
|
|
49
|
+
'IsSecurityReviewed',
|
|
50
|
+
'MajorVersion',
|
|
51
|
+
'MinorVersion',
|
|
52
|
+
'Name',
|
|
53
|
+
'Package2ContainerOptions',
|
|
54
|
+
'PatchVersion',
|
|
55
|
+
'PostInstallUrl',
|
|
56
|
+
'Profiles',
|
|
57
|
+
'PublisherName',
|
|
58
|
+
'ReleaseNotesUrl',
|
|
59
|
+
'ReleaseState',
|
|
60
|
+
'RemoteSiteSettings',
|
|
61
|
+
'SubscriberPackageId',
|
|
62
|
+
];
|
|
63
|
+
let logger;
|
|
64
|
+
const getLogger = () => {
|
|
65
|
+
if (!logger) {
|
|
66
|
+
logger = core_1.Logger.childFromRoot('subscriberPackageVersion');
|
|
67
|
+
}
|
|
68
|
+
return logger;
|
|
69
|
+
};
|
|
70
|
+
const allZeroesInstallOptions = {
|
|
71
|
+
pollingFrequency: kit_1.Duration.minutes(0),
|
|
72
|
+
pollingTimeout: kit_1.Duration.minutes(0),
|
|
73
|
+
publishFrequency: kit_1.Duration.minutes(0),
|
|
74
|
+
publishTimeout: kit_1.Duration.minutes(0),
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* A class that represents a SubscriberPackageVersion
|
|
78
|
+
*/
|
|
79
|
+
class SubscriberPackageVersion {
|
|
80
|
+
constructor(options) {
|
|
81
|
+
this.options = options;
|
|
82
|
+
this.connection = this.options.connection;
|
|
83
|
+
if (!this.options?.aliasOrId) {
|
|
84
|
+
throw messages.createError('errorInvalidAliasOrId', [this.options?.aliasOrId]);
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
const project = core_1.SfProject.getInstance();
|
|
88
|
+
this.id = project.getPackageIdFromAlias(this.options.aliasOrId) || this.options.aliasOrId;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
const err = error.message;
|
|
92
|
+
getLogger().debug(err);
|
|
93
|
+
this.id = this.options.aliasOrId;
|
|
94
|
+
}
|
|
95
|
+
// validate ID
|
|
96
|
+
if (!this.id.startsWith('04t') || !core_1.sfdc.validateSalesforceId(this.id)) {
|
|
97
|
+
throw messages.createError('errorInvalidAliasOrId', [this.options.aliasOrId]);
|
|
98
|
+
}
|
|
99
|
+
this.password = this.options.password;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Fetches the status of a package version install request and will wait for the install to complete, if requested
|
|
103
|
+
* Package Version install emits the following events:
|
|
104
|
+
* - PackageEvents.install['subscriber-status']
|
|
105
|
+
*
|
|
106
|
+
* @param connection
|
|
107
|
+
* @param packageInstallRequestOrId
|
|
108
|
+
* @param installationKey
|
|
109
|
+
* @param options
|
|
110
|
+
*/
|
|
111
|
+
static async installStatus(connection, packageInstallRequestOrId, installationKey, options) {
|
|
112
|
+
const id = typeof packageInstallRequestOrId === 'string' ? packageInstallRequestOrId : packageInstallRequestOrId.Id;
|
|
113
|
+
const packageInstallRequest = await (0, packageInstall_1.getStatus)(connection, id);
|
|
114
|
+
const pollingTimeout = (0, utils_1.numberToDuration)(options.pollingTimeout) ?? kit_1.Duration.milliseconds(0);
|
|
115
|
+
if (pollingTimeout.milliseconds <= 0) {
|
|
116
|
+
return packageInstallRequest;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
await (0, packageInstall_1.waitForPublish)(connection, packageInstallRequest.SubscriberPackageVersionKey, options?.publishFrequency || 0, options?.publishTimeout || 0, installationKey);
|
|
120
|
+
return (0, packageInstall_1.pollStatus)(connection, id, options);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Reports on the progress of a package version uninstall.
|
|
125
|
+
*
|
|
126
|
+
* @param id the 06y package version uninstall request id
|
|
127
|
+
* @param connection
|
|
128
|
+
*/
|
|
129
|
+
static async uninstallStatus(id, connection) {
|
|
130
|
+
if (!id.startsWith('06y') || !core_1.sfdc.validateSalesforceId(id)) {
|
|
131
|
+
throw messages.createError('packageVersionUninstallRequestIdInvalid', [id]);
|
|
132
|
+
}
|
|
133
|
+
const result = (await connection.tooling.retrieve('SubscriberPackageVersionUninstallRequest', id));
|
|
134
|
+
if (result.Status === 'Error') {
|
|
135
|
+
const errorDetails = await (0, packageUninstall_1.getUninstallErrors)(connection, id);
|
|
136
|
+
const errors = errorDetails.map((record, index) => `(${index + 1}) ${record.Message}`);
|
|
137
|
+
const errHeader = errors.length > 0 ? `\n=== Errors\n${errors.join('\n')}` : '';
|
|
138
|
+
const err = messages.getMessage('defaultErrorMessage', [id, result.Id]);
|
|
139
|
+
throw new core_1.SfError(`${err}${errHeader}`, 'UNINSTALL_ERROR', [messages.getMessage('action')]);
|
|
140
|
+
}
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Retrieves the package version create request.
|
|
145
|
+
*
|
|
146
|
+
* @param installRequestId
|
|
147
|
+
* @param connection
|
|
148
|
+
*/
|
|
149
|
+
static async getInstallRequest(installRequestId, connection) {
|
|
150
|
+
if (!installRequestId.startsWith('0Hf') || !core_1.sfdc.validateSalesforceId(installRequestId)) {
|
|
151
|
+
throw messages.createError('packageVersionInstallRequestIdInvalid', [installRequestId]);
|
|
152
|
+
}
|
|
153
|
+
const installRequest = await (0, packageInstall_1.getStatus)(connection, installRequestId);
|
|
154
|
+
if (!installRequest) {
|
|
155
|
+
throw messages.createError('packageVersionInstallRequestNotFound', [installRequestId]);
|
|
156
|
+
}
|
|
157
|
+
return installRequest;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Get the package version ID for this SubscriberPackageVersion.
|
|
161
|
+
*
|
|
162
|
+
* @returns The SubscriberPackageVersion Id (04t).
|
|
163
|
+
*/
|
|
164
|
+
getId() {
|
|
165
|
+
return Promise.resolve(this.id);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Get the package type for this SubscriberPackageVersion.
|
|
169
|
+
*
|
|
170
|
+
* @returns {PackageType} The package type.
|
|
171
|
+
*/
|
|
172
|
+
async getPackageType() {
|
|
173
|
+
return this.getField('Package2ContainerOptions');
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Get the password passed in the constructor
|
|
177
|
+
*
|
|
178
|
+
* @returns {string} the password
|
|
179
|
+
*/
|
|
180
|
+
getPassword() {
|
|
181
|
+
return this.password;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Get the subscriber package Id (033) for this SubscriberPackageVersion.
|
|
185
|
+
*
|
|
186
|
+
* @returns {string} The subscriber package Id.
|
|
187
|
+
*/
|
|
188
|
+
async getSubscriberPackageId() {
|
|
189
|
+
return this.getField('SubscriberPackageId');
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Get a VersionNumber instance for this SubscriberPackageVersion.
|
|
193
|
+
*
|
|
194
|
+
* @returns {VersionNumber} The version number.
|
|
195
|
+
*/
|
|
196
|
+
async getVersionNumber() {
|
|
197
|
+
const majorVersion = await this.getField('MajorVersion');
|
|
198
|
+
const minorVersion = await this.getField('MinorVersion');
|
|
199
|
+
const patchVersion = await this.getField('PatchVersion');
|
|
200
|
+
const buildNumber = await this.getField('BuildNumber');
|
|
201
|
+
return new utils_1.VersionNumber(majorVersion, minorVersion, patchVersion, buildNumber);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Is the package a managed package?
|
|
205
|
+
*/
|
|
206
|
+
async isManaged() {
|
|
207
|
+
return this.getField('IsManaged');
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Is the SubscriberPackageVersion deprecated?
|
|
211
|
+
*
|
|
212
|
+
* @returns {boolean} True if the SubscriberPackageVersion is deprecated.
|
|
213
|
+
*/
|
|
214
|
+
async isDeprecated() {
|
|
215
|
+
return this.getField('IsDeprecated');
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Is the SubscriberPackageVersion password protected?
|
|
219
|
+
*
|
|
220
|
+
* @returns {boolean} True if the SubscriberPackageVersion is password protected.
|
|
221
|
+
*/
|
|
222
|
+
async isPasswordProtected() {
|
|
223
|
+
return this.getField('IsPasswordProtected');
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Is the SubscriberPackageVersion org dependent?
|
|
227
|
+
*
|
|
228
|
+
* @returns {boolean} True if the SubscriberPackageVersion is org dependent.
|
|
229
|
+
*/
|
|
230
|
+
async isOrgDependent() {
|
|
231
|
+
return this.getField('IsOrgDependent');
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Return remote site settings for the SubscriberPackageVersion.
|
|
235
|
+
*
|
|
236
|
+
* @returns {RemoteSiteSettings} The remote site settings.
|
|
237
|
+
*/
|
|
238
|
+
async getRemoteSiteSettings() {
|
|
239
|
+
return this.getField('RemoteSiteSettings');
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Return CSP trusted sites for the SubscriberPackageVersion.
|
|
243
|
+
*
|
|
244
|
+
* @returns {CspTrustedSites} The CSP trusted sites.
|
|
245
|
+
*/
|
|
246
|
+
async getCspTrustedSites() {
|
|
247
|
+
return this.getField('CspTrustedSites');
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Get the installation validation status for the SubscriberPackageVersion.
|
|
251
|
+
*
|
|
252
|
+
* @returns {InstallationValidationStatus} The installation validation status.
|
|
253
|
+
*/
|
|
254
|
+
async getInstallValidationStatus() {
|
|
255
|
+
return this.getField('InstallValidationStatus');
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Get the SubscriberPackageVersion SObject data for this SubscriberPackageVersion.
|
|
259
|
+
*
|
|
260
|
+
* @param force - force a refresh of the subscriber package version data.
|
|
261
|
+
* @returns {PackagingSObjects.SubscriberPackageVersion} SObject data.
|
|
262
|
+
*/
|
|
263
|
+
async getData(options = { force: false, includeHighCostFields: false }) {
|
|
264
|
+
if (!this.data || options.force || options.includeHighCostFields) {
|
|
265
|
+
const queryFields = this.getFieldsForQuery(options);
|
|
266
|
+
if (queryFields.length === 0) {
|
|
267
|
+
return this.data;
|
|
268
|
+
}
|
|
269
|
+
try {
|
|
270
|
+
const queryNoKey = `SELECT ${queryFields.toString()} FROM SubscriberPackageVersion WHERE Id ='${await this.getId()}'`;
|
|
271
|
+
const escapedInstallationKey = this.password ? (0, utils_1.escapeInstallationKey)(this.password) : null;
|
|
272
|
+
const queryWithKey = `${queryNoKey} AND InstallationKey ='${escapedInstallationKey}'`;
|
|
273
|
+
this.data = await this.connection.singleRecordQuery(queryWithKey, {
|
|
274
|
+
tooling: true,
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
catch (err) {
|
|
278
|
+
throw messages.createError('errorInvalidIdNoRecordFound', [this.options.aliasOrId], undefined, err);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return this.data;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Installs a package version in a subscriber org.
|
|
285
|
+
*
|
|
286
|
+
* Package Version install emits the following events:
|
|
287
|
+
* - PackageEvents.install.warning
|
|
288
|
+
* - PackageEvents.install.presend
|
|
289
|
+
* - PackageEvents.install.postsend
|
|
290
|
+
* - PackageEvents.install['subscriber-status']
|
|
291
|
+
*
|
|
292
|
+
* @param pkgInstallCreateRequest
|
|
293
|
+
* @param options
|
|
294
|
+
*/
|
|
295
|
+
async install(pkgInstallCreateRequest, options = allZeroesInstallOptions) {
|
|
296
|
+
try {
|
|
297
|
+
// before starting the install, check to see if the package version is available for install
|
|
298
|
+
await (0, packageInstall_1.waitForPublish)(this.connection, await this.getId(), options.publishFrequency, options.publishTimeout, pkgInstallCreateRequest.Password);
|
|
299
|
+
const pkgVersionInstallRequest = await (0, packageInstall_1.createPackageInstallRequest)(this.connection, pkgInstallCreateRequest, await this.getPackageType());
|
|
300
|
+
return SubscriberPackageVersion.installStatus(this.connection, pkgVersionInstallRequest.Id, pkgInstallCreateRequest.Password, options);
|
|
301
|
+
}
|
|
302
|
+
catch (e) {
|
|
303
|
+
throw (0, utils_1.applyErrorAction)((0, utils_1.massageErrorMessage)(e));
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Uninstalls a package version from a subscriber org.
|
|
308
|
+
*
|
|
309
|
+
* @param frequency
|
|
310
|
+
* @param wait
|
|
311
|
+
*/
|
|
312
|
+
async uninstall(frequency = kit_1.Duration.milliseconds(0), wait = kit_1.Duration.milliseconds(0)) {
|
|
313
|
+
return await (0, packageUninstall_1.uninstallPackage)(await this.getId(), this.connection, frequency, wait);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Returns an array of RSS and CSP external sites for the package.
|
|
317
|
+
*
|
|
318
|
+
* @param installationKey The installation key (if any) for the subscriber package version.
|
|
319
|
+
* @returns an array of RSS and CSP site URLs, or undefined if the package doesn't have any.
|
|
320
|
+
*/
|
|
321
|
+
async getExternalSites() {
|
|
322
|
+
getLogger().debug(`Checking package: [${await this.getId()}] for external sites`);
|
|
323
|
+
const remoteSiteSettings = await this.getRemoteSiteSettings();
|
|
324
|
+
const cspTrustedSites = await this.getCspTrustedSites();
|
|
325
|
+
const rssUrls = remoteSiteSettings?.settings ? remoteSiteSettings.settings?.map((rss) => rss.url) : [];
|
|
326
|
+
const cspUrls = cspTrustedSites?.settings ? cspTrustedSites?.settings.map((csp) => csp.endpointUrl) : [];
|
|
327
|
+
const sites = [...rssUrls, ...cspUrls];
|
|
328
|
+
return sites.length > 0 ? sites : undefined;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Return a field value from the SubscriberPackageVersion SObject using the field name.
|
|
332
|
+
*
|
|
333
|
+
* @param field
|
|
334
|
+
*/
|
|
335
|
+
async getField(field) {
|
|
336
|
+
if (!this.data || !Reflect.has(this.data, field)) {
|
|
337
|
+
await this.getData({ includeHighCostFields: highCostQueryFields.includes(field) });
|
|
338
|
+
}
|
|
339
|
+
return Reflect.get(this.data || {}, field);
|
|
340
|
+
}
|
|
341
|
+
getFieldsForQuery(options) {
|
|
342
|
+
return exports.SubscriberPackageVersionFields.filter((field) => !highCostQueryFields.includes(field) || options.includeHighCostFields);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
exports.SubscriberPackageVersion = SubscriberPackageVersion;
|
|
346
|
+
//# sourceMappingURL=subscriberPackageVersion.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Connection, NamedPackageDir, PackageDir, SfdcUrl, SfError, SfProject } from '@salesforce/core';
|
|
2
2
|
import { Many, Nullable } from '@salesforce/ts-types';
|
|
3
3
|
import { SaveError } from 'jsforce';
|
|
4
|
+
import { Duration } from '@salesforce/kit';
|
|
4
5
|
import { PackageType, PackagingSObjects } from '../interfaces';
|
|
5
6
|
export declare const VERSION_NUMBER_SEP = ".";
|
|
6
7
|
export declare type IdRegistryValue = {
|
|
@@ -26,6 +27,7 @@ export declare function validateId(idObj: Many<IdRegistryValue>, value: string):
|
|
|
26
27
|
export declare function getSourceApiVersion(project: SfProject): string;
|
|
27
28
|
export declare function validateIdNoThrow(idObj: Many<IdRegistryValue>, value: any): IdRegistryValue | false;
|
|
28
29
|
export declare function applyErrorAction(err: Error): Error;
|
|
30
|
+
export declare function massageErrorMessage(err: Error): Error;
|
|
29
31
|
/**
|
|
30
32
|
* Given a subscriber package version ID (04t) or package version ID (05i), return the package version ID (05i)
|
|
31
33
|
*
|
|
@@ -34,14 +36,6 @@ export declare function applyErrorAction(err: Error): Error;
|
|
|
34
36
|
*/
|
|
35
37
|
export declare function getPackageVersionId(versionId: string, connection: Connection): Promise<string>;
|
|
36
38
|
export declare function escapeInstallationKey(key?: string): Nullable<string>;
|
|
37
|
-
/**
|
|
38
|
-
* Given 0Ho the package type type (Managed, Unlocked, Locked(deprecated?))
|
|
39
|
-
*
|
|
40
|
-
* @param packageId the 0Ho
|
|
41
|
-
* @param connection For tooling query
|
|
42
|
-
* @throws Error with message when package2 cannot be found
|
|
43
|
-
*/
|
|
44
|
-
export declare function getPackageType(packageId: string, connection: Connection): Promise<PackageType>;
|
|
45
39
|
/**
|
|
46
40
|
* Get the ContainerOptions for the specified Package2 (0Ho) IDs.
|
|
47
41
|
*
|
|
@@ -113,8 +107,13 @@ export declare function getPackageAliasesFromId(packageId: string, project: SfPr
|
|
|
113
107
|
* @param packageId the 0Ho id
|
|
114
108
|
* @private
|
|
115
109
|
*/
|
|
116
|
-
export declare function generatePackageAliasEntry(connection: Connection, project: SfProject, packageVersionId: string, packageVersionNumber: string, branch: string, packageId: string): Promise<
|
|
117
|
-
[p: string]: string;
|
|
118
|
-
}>;
|
|
110
|
+
export declare function generatePackageAliasEntry(connection: Connection, project: SfProject, packageVersionId: string, packageVersionNumber: string, branch: string, packageId: string): Promise<[string, string]>;
|
|
119
111
|
export declare function formatDate(date: Date): string;
|
|
120
112
|
export declare function combineSaveErrors(sObject: string, crudOperation: string, errors: SaveError[]): SfError;
|
|
113
|
+
/**
|
|
114
|
+
* Returns a Duration object from param duration when it is a number, otherwise return itself
|
|
115
|
+
*
|
|
116
|
+
* @param duration = number to be converted to a Duration or Duration object
|
|
117
|
+
* @param unit = (Default Duration.Unit.MILLISECONDS) Duration unit of number - See @link {Duration.Unit} for valid values
|
|
118
|
+
*/
|
|
119
|
+
export declare function numberToDuration(duration: number | Duration, unit?: Duration.Unit): Duration;
|