@salesforce/packaging 0.0.35 → 0.0.37
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 +12 -0
- package/lib/interfaces/packagingInterfacesAndType.d.ts +31 -1
- package/lib/interfaces/packagingInterfacesAndType.js +31 -1
- package/lib/package/package.d.ts +1 -1
- package/lib/package/package.js +3 -2
- package/lib/package/packageAncestry.d.ts +1 -1
- package/lib/package/packageAncestry.js +5 -5
- package/lib/package/packageConvert.d.ts +1 -0
- package/lib/package/packageConvert.js +122 -4
- package/lib/package/packageCreate.d.ts +3 -3
- package/lib/package/packageCreate.js +12 -11
- package/lib/package/packageInstall.d.ts +3 -2
- package/lib/package/packageInstall.js +50 -17
- package/lib/package/packageProfileApi.js +1 -1
- package/lib/package/packageUninstall.js +5 -3
- package/lib/package/packageVersion.d.ts +7 -0
- package/lib/package/packageVersion.js +34 -7
- package/lib/package/packageVersionCreate.d.ts +6 -0
- package/lib/package/packageVersionCreate.js +227 -21
- package/lib/package/packageVersionCreateRequest.js +8 -3
- package/lib/package/packageVersionList.js +1 -1
- package/lib/package/packageVersionReport.js +28 -2
- package/lib/package1/package1VersionCreate.js +3 -2
- package/lib/utils/packageUtils.d.ts +1 -37
- package/lib/utils/packageUtils.js +6 -397
- package/lib/utils/versionNumber.js +1 -1
- package/messages/package1_version_create.md +8 -0
- package/messages/package_ancestry.md +19 -0
- package/messages/package_create.md +3 -0
- package/messages/{package-install.md → package_install.md} +2 -2
- package/messages/package_uninstall.md +3 -0
- package/messages/package_version.md +3 -0
- package/messages/{packageVersionCreate.md → package_version_create.md} +35 -6
- package/messages/pkg_utils.md +93 -0
- package/messages/{profile-api.md → profile_api.md} +0 -0
- package/messages/version_number.md +15 -0
- package/package.json +2 -2
- package/messages/messages.md +0 -285
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
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.37](https://github.com/forcedotcom/packaging/compare/v0.0.36...v0.0.37) (2022-09-16)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
- move util functions with single ref ([e7117d3](https://github.com/forcedotcom/packaging/commit/e7117d3530ac56717796da3535394ca184d53643))
|
|
10
|
+
|
|
11
|
+
### [0.0.36](https://github.com/forcedotcom/packaging/compare/v0.0.35...v0.0.36) (2022-09-14)
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
- standardize event names across classes, methods, and events ([d97c231](https://github.com/forcedotcom/packaging/commit/d97c231928582dd092bf0ce225dffa3298cce8eb))
|
|
16
|
+
|
|
5
17
|
### [0.0.35](https://github.com/forcedotcom/packaging/compare/v0.0.34...v0.0.35) (2022-09-09)
|
|
6
18
|
|
|
7
19
|
### Bug Fixes
|
|
@@ -15,7 +15,7 @@ export interface IPackage {
|
|
|
15
15
|
install(pkgInstallCreateRequest: PackageInstallCreateRequest, options?: PackageInstallOptions): Promise<PackageInstallRequest>;
|
|
16
16
|
getInstallStatus(installRequestId: string): Promise<PackageInstallRequest>;
|
|
17
17
|
list(): Promise<QueryResult<PackagingSObjects.Package2>>;
|
|
18
|
-
uninstall(): Promise<
|
|
18
|
+
uninstall(id: string, wait: Duration): Promise<PackagingSObjects.SubscriberPackageVersionUninstallRequest>;
|
|
19
19
|
update(options: PackageUpdateOptions): Promise<PackageSaveResult>;
|
|
20
20
|
waitForPublish(subscriberPackageVersionKey: string, timeout: number | Duration, installationKey?: string): any;
|
|
21
21
|
getExternalSites(subscriberPackageVersionKey: string, installationKey?: string): any;
|
|
@@ -308,3 +308,33 @@ export interface AncestryRepresentationProducer {
|
|
|
308
308
|
addNode(node: AncestryRepresentationProducer): void;
|
|
309
309
|
produce<T>(): T | string | void;
|
|
310
310
|
}
|
|
311
|
+
export declare const PackageEvents: {
|
|
312
|
+
convert: {
|
|
313
|
+
success: string;
|
|
314
|
+
error: string;
|
|
315
|
+
progress: string;
|
|
316
|
+
};
|
|
317
|
+
install: {
|
|
318
|
+
warning: string;
|
|
319
|
+
presend: string;
|
|
320
|
+
postsend: string;
|
|
321
|
+
status: string;
|
|
322
|
+
'subscriber-status': string;
|
|
323
|
+
};
|
|
324
|
+
uninstall: string;
|
|
325
|
+
};
|
|
326
|
+
export declare const PackageVersionEvents: {
|
|
327
|
+
create: {
|
|
328
|
+
enqueued: string;
|
|
329
|
+
progress: string;
|
|
330
|
+
success: string;
|
|
331
|
+
error: string;
|
|
332
|
+
'timed-out': string;
|
|
333
|
+
'preserve-files': string;
|
|
334
|
+
};
|
|
335
|
+
};
|
|
336
|
+
export declare const Package1VersionEvents: {
|
|
337
|
+
create: {
|
|
338
|
+
progress: string;
|
|
339
|
+
};
|
|
340
|
+
};
|
|
@@ -6,8 +6,38 @@
|
|
|
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.PackageVersionCreateRequestResultInProgressStatuses = void 0;
|
|
9
|
+
exports.Package1VersionEvents = exports.PackageVersionEvents = exports.PackageEvents = exports.PackageVersionCreateRequestResultInProgressStatuses = void 0;
|
|
10
10
|
const packagingSObjects_1 = require("./packagingSObjects");
|
|
11
11
|
var Package2VersionStatus = packagingSObjects_1.PackagingSObjects.Package2VersionStatus;
|
|
12
12
|
exports.PackageVersionCreateRequestResultInProgressStatuses = Object.values(Package2VersionStatus).filter((status) => !['Queued', 'Success', 'Error'].includes(status));
|
|
13
|
+
exports.PackageEvents = {
|
|
14
|
+
convert: {
|
|
15
|
+
success: 'Package/convert-success',
|
|
16
|
+
error: 'Package/convert-error',
|
|
17
|
+
progress: 'Package/convert-in-progress',
|
|
18
|
+
},
|
|
19
|
+
install: {
|
|
20
|
+
warning: 'Package/install-warning',
|
|
21
|
+
presend: 'Package/install-presend',
|
|
22
|
+
postsend: 'Package/install-postsend',
|
|
23
|
+
status: 'Package/install-status',
|
|
24
|
+
'subscriber-status': 'Package/install-subscriber-status',
|
|
25
|
+
},
|
|
26
|
+
uninstall: 'Package/uninstall',
|
|
27
|
+
};
|
|
28
|
+
exports.PackageVersionEvents = {
|
|
29
|
+
create: {
|
|
30
|
+
enqueued: 'PackageVersion/create-enqueued',
|
|
31
|
+
progress: 'PackageVersion/create-in-progress',
|
|
32
|
+
success: 'PackageVersion/create-success',
|
|
33
|
+
error: 'PackageVersion/create-error',
|
|
34
|
+
'timed-out': 'PackageVersion/create-timed-out',
|
|
35
|
+
'preserve-files': 'PackageVersion/create-preserve-files',
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
exports.Package1VersionEvents = {
|
|
39
|
+
create: {
|
|
40
|
+
progress: 'Package1Version/create-progress',
|
|
41
|
+
},
|
|
42
|
+
};
|
|
13
43
|
//# sourceMappingURL=packagingInterfacesAndType.js.map
|
package/lib/package/package.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare class Package extends AsyncCreatable<PackageOptions> implements I
|
|
|
32
32
|
install(pkgInstallCreateRequest: PackageInstallCreateRequest, options?: PackageInstallOptions): Promise<PackageInstallRequest>;
|
|
33
33
|
getInstallStatus(installRequestId: string): Promise<PackageInstallRequest>;
|
|
34
34
|
list(): Promise<QueryResult<PackagingSObjects.Package2>>;
|
|
35
|
-
uninstall(): Promise<
|
|
35
|
+
uninstall(id: string, wait: Duration): Promise<PackagingSObjects.SubscriberPackageVersionUninstallRequest>;
|
|
36
36
|
/**
|
|
37
37
|
* Reports on the uninstall progress of a package.
|
|
38
38
|
*
|
package/lib/package/package.js
CHANGED
|
@@ -12,6 +12,7 @@ const kit_1 = require("@salesforce/kit");
|
|
|
12
12
|
const packageList_1 = require("./packageList");
|
|
13
13
|
const packageInstall_1 = require("./packageInstall");
|
|
14
14
|
const packageConvert_1 = require("./packageConvert");
|
|
15
|
+
const packageUninstall_1 = require("./packageUninstall");
|
|
15
16
|
const packagePrefixes = {
|
|
16
17
|
PackageId: '0Ho',
|
|
17
18
|
SubscriberPackageVersionId: '04t',
|
|
@@ -70,8 +71,8 @@ class Package extends kit_1.AsyncCreatable {
|
|
|
70
71
|
list() {
|
|
71
72
|
return (0, packageList_1.listPackages)(this.options.connection);
|
|
72
73
|
}
|
|
73
|
-
uninstall() {
|
|
74
|
-
return
|
|
74
|
+
async uninstall(id, wait) {
|
|
75
|
+
return await (0, packageUninstall_1.uninstallPackage)(id, this.options.connection, wait);
|
|
75
76
|
}
|
|
76
77
|
/**
|
|
77
78
|
* Reports on the uninstall progress of a package.
|
|
@@ -3,7 +3,7 @@ import { AsyncCreatable } from '@salesforce/kit';
|
|
|
3
3
|
import { Tree } from '@oclif/core/lib/cli-ux/styled/tree';
|
|
4
4
|
import { Attributes } from 'graphology-types';
|
|
5
5
|
import { AncestryRepresentationProducer, AncestryRepresentationProducerOptions, PackageAncestryNodeOptions, PackageAncestryOptions } from '../interfaces';
|
|
6
|
-
import { VersionNumber } from '../utils
|
|
6
|
+
import { VersionNumber } from '../utils';
|
|
7
7
|
/**
|
|
8
8
|
* A class that represents the package ancestry graph.
|
|
9
9
|
*/
|
|
@@ -26,17 +26,17 @@ const kit_1 = require("@salesforce/kit");
|
|
|
26
26
|
const tree_1 = require("@oclif/core/lib/cli-ux/styled/tree");
|
|
27
27
|
const graphology_traversal_1 = require("graphology-traversal");
|
|
28
28
|
const pkgUtils = require("../utils/packageUtils");
|
|
29
|
-
const
|
|
29
|
+
const utils_1 = require("../utils");
|
|
30
30
|
core_1.Messages.importMessagesDirectory(__dirname);
|
|
31
|
-
const messages = core_1.Messages.loadMessages('@salesforce/packaging', '
|
|
31
|
+
const messages = core_1.Messages.loadMessages('@salesforce/packaging', 'package_ancestry');
|
|
32
32
|
const SELECT_PACKAGE_VERSION = 'SELECT AncestorId, SubscriberPackageVersionId, MajorVersion, MinorVersion, PatchVersion, BuildNumber FROM Package2Version';
|
|
33
33
|
const SELECT_PACKAGE_CONTAINER_OPTIONS = 'SELECT ContainerOptions FROM Package2 ';
|
|
34
34
|
const SELECT_PACKAGE_VERSION_CONTAINER_OPTIONS = 'SELECT Package2ContainerOptions FROM SubscriberPackageVersion';
|
|
35
35
|
// Add this to query calls to only show released package versions in the output
|
|
36
36
|
const releasedOnlyFilter = ' AND IsReleased = true';
|
|
37
37
|
const sortAncestryNodeData = (a, b) => {
|
|
38
|
-
const aVersion = new
|
|
39
|
-
const bVersion = new
|
|
38
|
+
const aVersion = new utils_1.VersionNumber(a.options.node.MajorVersion, a.options.node.MinorVersion, a.options.node.PatchVersion, a.options.node.BuildNumber);
|
|
39
|
+
const bVersion = new utils_1.VersionNumber(b.options.node.MajorVersion, b.options.node.MinorVersion, b.options.node.PatchVersion, b.options.node.BuildNumber);
|
|
40
40
|
return aVersion.compareTo(bVersion);
|
|
41
41
|
};
|
|
42
42
|
/**
|
|
@@ -384,7 +384,7 @@ class PackageAncestryNode extends kit_1.AsyncCreatable {
|
|
|
384
384
|
_PackageAncestryNode_AncestorId.set(this, void 0);
|
|
385
385
|
_PackageAncestryNode_SubscriberPackageVersionId.set(this, void 0);
|
|
386
386
|
_PackageAncestryNode_depthCounter.set(this, void 0);
|
|
387
|
-
__classPrivateFieldSet(this, _PackageAncestryNode_version, new
|
|
387
|
+
__classPrivateFieldSet(this, _PackageAncestryNode_version, new utils_1.VersionNumber(this.options.MajorVersion, this.options.MinorVersion, this.options.PatchVersion, this.options.BuildNumber), "f");
|
|
388
388
|
__classPrivateFieldSet(this, _PackageAncestryNode_AncestorId, this.options.AncestorId, "f");
|
|
389
389
|
__classPrivateFieldSet(this, _PackageAncestryNode_SubscriberPackageVersionId, this.options.SubscriberPackageVersionId, "f");
|
|
390
390
|
__classPrivateFieldSet(this, _PackageAncestryNode_MajorVersion, typeof this.options.MajorVersion === 'number'
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Connection, SfProject } from '@salesforce/core';
|
|
2
2
|
import { PackagingSObjects, PackageVersionCreateRequestResult, ConvertPackageOptions } from '../interfaces';
|
|
3
|
+
export declare function findOrCreatePackage2(seedPackage: string, connection: Connection): Promise<string>;
|
|
3
4
|
export declare function convertPackage(pkg: string, connection: Connection, options: ConvertPackageOptions, project?: SfProject): Promise<PackageVersionCreateRequestResult>;
|
|
4
5
|
/**
|
|
5
6
|
* Convert the list of command line options to a JSON object that can be used to create an Package2VersionCreateRequest entity.
|
|
@@ -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.createPackageVersionCreateRequest = exports.convertPackage = void 0;
|
|
9
|
+
exports.createPackageVersionCreateRequest = exports.convertPackage = exports.findOrCreatePackage2 = void 0;
|
|
10
10
|
const path = require("path");
|
|
11
11
|
const os = require("os");
|
|
12
12
|
const fs = require("fs");
|
|
@@ -14,18 +14,58 @@ const core_1 = require("@salesforce/core");
|
|
|
14
14
|
const kit_1 = require("@salesforce/kit");
|
|
15
15
|
const uniqid_1 = require("../utils/uniqid");
|
|
16
16
|
const pkgUtils = require("../utils/packageUtils");
|
|
17
|
+
const interfaces_1 = require("../interfaces");
|
|
17
18
|
const constants_1 = require("../constants");
|
|
18
19
|
const srcDevUtil = require("../utils/srcDevUtils");
|
|
20
|
+
const utils_1 = require("../utils");
|
|
19
21
|
const packageVersionCreateRequest_1 = require("./packageVersionCreateRequest");
|
|
22
|
+
const pvcr = require("./packageVersionCreateRequest");
|
|
23
|
+
var Package2VersionStatus = interfaces_1.PackagingSObjects.Package2VersionStatus;
|
|
20
24
|
core_1.Messages.importMessagesDirectory(__dirname);
|
|
21
|
-
const messages = core_1.Messages.loadMessages('@salesforce/packaging', '
|
|
25
|
+
const messages = core_1.Messages.loadMessages('@salesforce/packaging', 'package_version_create');
|
|
26
|
+
async function findOrCreatePackage2(seedPackage, connection) {
|
|
27
|
+
const query = `SELECT Id FROM Package2 WHERE ConvertedFromPackageId = '${seedPackage}'`;
|
|
28
|
+
const queryResult = (await connection.tooling.query(query)).records;
|
|
29
|
+
if (queryResult?.length > 1) {
|
|
30
|
+
const ids = queryResult.map((r) => r.Id);
|
|
31
|
+
throw messages.createError('errorMoreThanOnePackage2WithSeed', [ids.join(', ')]);
|
|
32
|
+
}
|
|
33
|
+
if (queryResult?.length === 1) {
|
|
34
|
+
// return the package2 object
|
|
35
|
+
return queryResult[0].Id;
|
|
36
|
+
}
|
|
37
|
+
// Need to create a new Package2
|
|
38
|
+
const subQuery = `SELECT Name, Description, NamespacePrefix FROM SubscriberPackage WHERE Id = '${seedPackage}'`;
|
|
39
|
+
let subscriberResult;
|
|
40
|
+
try {
|
|
41
|
+
subscriberResult = await connection.singleRecordQuery(subQuery, {
|
|
42
|
+
tooling: true,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
throw messages.createError('errorNoSubscriberPackageRecord', [seedPackage]);
|
|
47
|
+
}
|
|
48
|
+
const request = {
|
|
49
|
+
Name: subscriberResult.Name,
|
|
50
|
+
Description: subscriberResult.Description,
|
|
51
|
+
NamespacePrefix: subscriberResult.NamespacePrefix,
|
|
52
|
+
ContainerOptions: 'Managed',
|
|
53
|
+
ConvertedFromPackageId: seedPackage,
|
|
54
|
+
};
|
|
55
|
+
const createResult = await connection.tooling.create('Package2', request);
|
|
56
|
+
if (!createResult.success) {
|
|
57
|
+
throw pkgUtils.combineSaveErrors('Package2', 'create', createResult.errors);
|
|
58
|
+
}
|
|
59
|
+
return createResult.id;
|
|
60
|
+
}
|
|
61
|
+
exports.findOrCreatePackage2 = findOrCreatePackage2;
|
|
22
62
|
async function convertPackage(pkg, connection, options, project) {
|
|
23
63
|
let maxRetries = 0;
|
|
24
64
|
const branch = 'main';
|
|
25
65
|
if (options.wait) {
|
|
26
66
|
maxRetries = (60 / pkgUtils.POLL_INTERVAL_SECONDS) * options.wait.minutes;
|
|
27
67
|
}
|
|
28
|
-
const packageId = await
|
|
68
|
+
const packageId = await findOrCreatePackage2(pkg, connection);
|
|
29
69
|
const request = await createPackageVersionCreateRequest({ installationkey: options.installationKey, buildinstance: options.buildInstance }, packageId);
|
|
30
70
|
// TODO: a lot of this is duplicated from PC, PVC, and PVCR.
|
|
31
71
|
const createResult = await connection.tooling.create('Package2VersionCreateRequest', request);
|
|
@@ -38,7 +78,7 @@ async function convertPackage(pkg, connection, options, project) {
|
|
|
38
78
|
}
|
|
39
79
|
let results;
|
|
40
80
|
if (options.wait) {
|
|
41
|
-
results = await
|
|
81
|
+
results = await pollForStatusWithInterval(createResult.id, maxRetries, packageId, branch, project, connection, new kit_1.Duration(pkgUtils.POLL_INTERVAL_SECONDS, kit_1.Duration.Unit.SECONDS));
|
|
42
82
|
}
|
|
43
83
|
else {
|
|
44
84
|
results = await (0, packageVersionCreateRequest_1.byId)(packageId, connection);
|
|
@@ -82,4 +122,82 @@ async function createRequestObject(packageId, options, packageVersTmpRoot, packa
|
|
|
82
122
|
await fs.promises.rm(packageVersTmpRoot, { recursive: true });
|
|
83
123
|
return requestObject;
|
|
84
124
|
}
|
|
125
|
+
async function pollForStatusWithInterval(id, retries, packageId, branch, withProject, connection, interval) {
|
|
126
|
+
let remainingRetries = retries;
|
|
127
|
+
const pollingClient = await core_1.PollingClient.create({
|
|
128
|
+
poll: async () => {
|
|
129
|
+
const results = await pvcr.byId(id, connection);
|
|
130
|
+
if (_isStatusEqualTo(results, [Package2VersionStatus.success, Package2VersionStatus.error])) {
|
|
131
|
+
// complete
|
|
132
|
+
if (_isStatusEqualTo(results, [Package2VersionStatus.success])) {
|
|
133
|
+
// update sfdx-project.json
|
|
134
|
+
let projectUpdated = false;
|
|
135
|
+
if (withProject && !process.env.SFDX_PROJECT_AUTOUPDATE_DISABLE_FOR_PACKAGE_VERSION_CREATE) {
|
|
136
|
+
projectUpdated = true;
|
|
137
|
+
const query = `SELECT MajorVersion, MinorVersion, PatchVersion, BuildNumber FROM Package2Version WHERE Id = '${results[0].Package2VersionId}'`;
|
|
138
|
+
const packageVersionVersionString = await connection.tooling
|
|
139
|
+
.query(query)
|
|
140
|
+
.then((pkgQueryResult) => {
|
|
141
|
+
const record = pkgQueryResult.records[0];
|
|
142
|
+
return `${record.MajorVersion}.${record.MinorVersion}.${record.PatchVersion}-${record.BuildNumber}`;
|
|
143
|
+
});
|
|
144
|
+
// TODO SfProjectJson.addPackageAlias
|
|
145
|
+
const newConfig = await (0, utils_1.generatePackageAliasEntry)(connection, withProject, results[0].SubscriberPackageVersionId, packageVersionVersionString, branch, packageId);
|
|
146
|
+
withProject.getSfProjectJson().set('packageAliases', newConfig);
|
|
147
|
+
await withProject.getSfProjectJson().write();
|
|
148
|
+
}
|
|
149
|
+
await core_1.Lifecycle.getInstance().emit(interfaces_1.PackageEvents.convert.success, {
|
|
150
|
+
id,
|
|
151
|
+
packageVersionCreateRequestResult: results[0],
|
|
152
|
+
projectUpdated,
|
|
153
|
+
});
|
|
154
|
+
return { completed: true, payload: results[0] };
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
let status = 'Unknown Error';
|
|
158
|
+
if (results?.length > 0 && results[0].Error.length > 0) {
|
|
159
|
+
const errors = [];
|
|
160
|
+
// for multiple errors, display one per line prefixed with (x)
|
|
161
|
+
if (results[0].Error.length > 1) {
|
|
162
|
+
results[0].Error.forEach((error) => {
|
|
163
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
164
|
+
errors.push(`(${errors.length + 1}) ${error}`);
|
|
165
|
+
});
|
|
166
|
+
errors.unshift(messages.getMessage('versionCreateFailedWithMultipleErrors'));
|
|
167
|
+
}
|
|
168
|
+
status = errors.length !== 0 ? errors.join('\n') : results[0].Error.join('\n');
|
|
169
|
+
}
|
|
170
|
+
await core_1.Lifecycle.getInstance().emit(interfaces_1.PackageEvents.convert.error, { id, status });
|
|
171
|
+
throw new core_1.SfError(status);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
const remainingTime = kit_1.Duration.seconds(interval.seconds * remainingRetries);
|
|
176
|
+
await core_1.Lifecycle.getInstance().emit(interfaces_1.PackageEvents.convert.progress, {
|
|
177
|
+
id,
|
|
178
|
+
packageVersionCreateRequestResult: results[0],
|
|
179
|
+
message: '',
|
|
180
|
+
timeRemaining: remainingTime,
|
|
181
|
+
});
|
|
182
|
+
const logger = core_1.Logger.childFromRoot('packageConvert');
|
|
183
|
+
logger.info(`Request in progress. Sleeping ${interval.seconds} seconds. Will wait a total of ${remainingTime.seconds} more seconds before timing out. Current Status='${(0, kit_1.camelCaseToTitleCase)(results[0]?.Status)}'`);
|
|
184
|
+
remainingRetries--;
|
|
185
|
+
return { completed: false, payload: results[0] };
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
frequency: kit_1.Duration.seconds(interval.seconds),
|
|
189
|
+
timeout: kit_1.Duration.seconds(interval.seconds * retries),
|
|
190
|
+
});
|
|
191
|
+
return pollingClient.subscribe();
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Return true if the queryResult.records[0].Status is equal to one of the values in statuses.
|
|
195
|
+
*
|
|
196
|
+
* @param results to examine
|
|
197
|
+
* @param statuses array of statuses to look for
|
|
198
|
+
* @returns {boolean} if one of the values in status is found.
|
|
199
|
+
*/
|
|
200
|
+
function _isStatusEqualTo(results, statuses) {
|
|
201
|
+
return results?.length <= 0 ? false : statuses?.some((status) => results[0].Status === status);
|
|
202
|
+
}
|
|
85
203
|
//# sourceMappingURL=packageConvert.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Connection, NamedPackageDir, PackageDir, SfProject } from '@salesforce/core';
|
|
2
2
|
import { PackageCreateOptions, PackagingSObjects } from '../interfaces';
|
|
3
3
|
declare type Package2Request = Pick<PackagingSObjects.Package2, 'Name' | 'Description' | 'NamespacePrefix' | 'ContainerOptions' | 'IsOrgDependent' | 'PackageErrorUsername'>;
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function createPackageRequestFromContext(project: SfProject, options: PackageCreateOptions): Package2Request;
|
|
5
5
|
/**
|
|
6
6
|
* Generate packageDirectory json entry for this package that can be written to sfdx-project.json
|
|
7
7
|
*
|
|
@@ -9,7 +9,7 @@ export declare function _createPackageRequestFromContext(project: SfProject, opt
|
|
|
9
9
|
* @param packageId the 0Ho id of the package to create the entry for
|
|
10
10
|
* @private
|
|
11
11
|
*/
|
|
12
|
-
export declare function
|
|
12
|
+
export declare function generatePackageDirEntry(project: SfProject, options: PackageCreateOptions): PackageDir[] | NamedPackageDir[];
|
|
13
13
|
/**
|
|
14
14
|
* Generate package alias json entry for this package that can be written to sfdx-project.json
|
|
15
15
|
*
|
|
@@ -17,7 +17,7 @@ export declare function _generatePackageDirEntry(project: SfProject, options: Pa
|
|
|
17
17
|
* @param packageId the 0Ho id of the package to create the alias entry for
|
|
18
18
|
* @private
|
|
19
19
|
*/
|
|
20
|
-
export declare function
|
|
20
|
+
export declare function generatePackageAliasEntry(project: SfProject, options: PackageCreateOptions, packageId: string): {
|
|
21
21
|
[key: string]: string;
|
|
22
22
|
};
|
|
23
23
|
export declare function createPackage(connection: Connection, project: SfProject, options: PackageCreateOptions): Promise<{
|
|
@@ -6,13 +6,13 @@
|
|
|
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.createPackage = exports.
|
|
9
|
+
exports.createPackage = exports.generatePackageAliasEntry = exports.generatePackageDirEntry = exports.createPackageRequestFromContext = void 0;
|
|
10
10
|
const core_1 = require("@salesforce/core");
|
|
11
11
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
12
12
|
const pkgUtils = require("../utils/packageUtils");
|
|
13
13
|
core_1.Messages.importMessagesDirectory(__dirname);
|
|
14
|
-
const messages = core_1.Messages.loadMessages('@salesforce/packaging', '
|
|
15
|
-
function
|
|
14
|
+
const messages = core_1.Messages.loadMessages('@salesforce/packaging', 'package_create');
|
|
15
|
+
function createPackageRequestFromContext(project, options) {
|
|
16
16
|
const namespace = options.noNamespace ? '' : project.getSfProjectJson().getContents().namespace || '';
|
|
17
17
|
return {
|
|
18
18
|
Name: options.name,
|
|
@@ -23,7 +23,7 @@ function _createPackageRequestFromContext(project, options) {
|
|
|
23
23
|
PackageErrorUsername: options.errorNotificationUsername,
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
exports.
|
|
26
|
+
exports.createPackageRequestFromContext = createPackageRequestFromContext;
|
|
27
27
|
/**
|
|
28
28
|
* Generate packageDirectory json entry for this package that can be written to sfdx-project.json
|
|
29
29
|
*
|
|
@@ -31,7 +31,8 @@ exports._createPackageRequestFromContext = _createPackageRequestFromContext;
|
|
|
31
31
|
* @param packageId the 0Ho id of the package to create the entry for
|
|
32
32
|
* @private
|
|
33
33
|
*/
|
|
34
|
-
function
|
|
34
|
+
function generatePackageDirEntry(project, options) {
|
|
35
|
+
// TODO: use SfProjectJson#addPackageDirectory for this maintenance
|
|
35
36
|
let packageDirs = project.getPackageDirectories();
|
|
36
37
|
if (!packageDirs) {
|
|
37
38
|
packageDirs = [];
|
|
@@ -64,7 +65,7 @@ function _generatePackageDirEntry(project, options) {
|
|
|
64
65
|
}
|
|
65
66
|
return packageDirs;
|
|
66
67
|
}
|
|
67
|
-
exports.
|
|
68
|
+
exports.generatePackageDirEntry = generatePackageDirEntry;
|
|
68
69
|
/**
|
|
69
70
|
* Generate package alias json entry for this package that can be written to sfdx-project.json
|
|
70
71
|
*
|
|
@@ -72,17 +73,17 @@ exports._generatePackageDirEntry = _generatePackageDirEntry;
|
|
|
72
73
|
* @param packageId the 0Ho id of the package to create the alias entry for
|
|
73
74
|
* @private
|
|
74
75
|
*/
|
|
75
|
-
function
|
|
76
|
+
function generatePackageAliasEntry(project, options, packageId) {
|
|
76
77
|
const packageAliases = project.getSfProjectJson().getContents().packageAliases || {};
|
|
77
78
|
const packageName = options.name;
|
|
78
79
|
packageAliases[packageName] = packageId;
|
|
79
80
|
return packageAliases;
|
|
80
81
|
}
|
|
81
|
-
exports.
|
|
82
|
+
exports.generatePackageAliasEntry = generatePackageAliasEntry;
|
|
82
83
|
async function createPackage(connection, project, options) {
|
|
83
84
|
// strip trailing slash from path param
|
|
84
85
|
options.path = options.path.replace(/\/$/, '');
|
|
85
|
-
const request =
|
|
86
|
+
const request = createPackageRequestFromContext(project, options);
|
|
86
87
|
let packageId = null;
|
|
87
88
|
const createResult = await connection.tooling
|
|
88
89
|
.sobject('Package2')
|
|
@@ -101,8 +102,8 @@ async function createPackage(connection, project, options) {
|
|
|
101
102
|
}
|
|
102
103
|
const record = queryResult.records[0];
|
|
103
104
|
if (!process.env.SFDX_PROJECT_AUTOUPDATE_DISABLE_FOR_PACKAGE_CREATE) {
|
|
104
|
-
const packageDirectory =
|
|
105
|
-
const packageAliases =
|
|
105
|
+
const packageDirectory = generatePackageDirEntry(project, options);
|
|
106
|
+
const packageAliases = generatePackageAliasEntry(project, options, record.Id);
|
|
106
107
|
const projectJson = project.getSfProjectJson();
|
|
107
108
|
projectJson.set('packageDirectories', packageDirectory);
|
|
108
109
|
projectJson.set('packageAliases', packageAliases);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Connection } from '@salesforce/core';
|
|
2
2
|
import { Optional } from '@salesforce/ts-types';
|
|
3
3
|
import { Duration } from '@salesforce/kit';
|
|
4
|
-
import { PackagingSObjects } from '../interfaces';
|
|
5
|
-
import { PackageInstallOptions, PackageInstallCreateRequest } from '../interfaces/packagingInterfacesAndType';
|
|
4
|
+
import { PackagingSObjects, PackageInstallOptions, PackageInstallCreateRequest } from '../interfaces';
|
|
6
5
|
import PackageInstallRequest = PackagingSObjects.PackageInstallRequest;
|
|
7
6
|
export declare function installPackage(connection: Connection, pkgInstallCreateRequest: PackageInstallCreateRequest, options?: PackageInstallOptions): Promise<PackageInstallRequest>;
|
|
8
7
|
/**
|
|
@@ -15,4 +14,6 @@ export declare function installPackage(connection: Connection, pkgInstallCreateR
|
|
|
15
14
|
*/
|
|
16
15
|
export declare function getExternalSites(connection: Connection, subscriberPackageVersionId: string, installationKey?: string): Promise<Optional<string[]>>;
|
|
17
16
|
export declare function getStatus(connection: Connection, installRequestId: string): Promise<PackageInstallRequest>;
|
|
17
|
+
export declare function isErrorFromSPVQueryRestriction(err: Error): boolean;
|
|
18
|
+
export declare function isErrorPackageNotAvailable(err: Error): boolean;
|
|
18
19
|
export declare function waitForPublish(connection: Connection, subscriberPackageVersionId: string, timeout: number | Duration, installationKey?: string): Promise<void>;
|
|
@@ -6,14 +6,15 @@
|
|
|
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.waitForPublish = exports.getStatus = exports.getExternalSites = exports.installPackage = void 0;
|
|
9
|
+
exports.waitForPublish = exports.isErrorPackageNotAvailable = exports.isErrorFromSPVQueryRestriction = exports.getStatus = exports.getExternalSites = exports.installPackage = void 0;
|
|
10
10
|
const core_1 = require("@salesforce/core");
|
|
11
11
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
12
12
|
const kit_1 = require("@salesforce/kit");
|
|
13
|
-
const
|
|
13
|
+
const utils_1 = require("../utils");
|
|
14
14
|
const constants_1 = require("../constants");
|
|
15
|
+
const interfaces_1 = require("../interfaces");
|
|
15
16
|
core_1.Messages.importMessagesDirectory(__dirname);
|
|
16
|
-
const installMsgs = core_1.Messages.loadMessages('@salesforce/packaging', '
|
|
17
|
+
const installMsgs = core_1.Messages.loadMessages('@salesforce/packaging', 'package_install');
|
|
17
18
|
let logger;
|
|
18
19
|
const getLogger = () => {
|
|
19
20
|
if (!logger) {
|
|
@@ -21,6 +22,26 @@ const getLogger = () => {
|
|
|
21
22
|
}
|
|
22
23
|
return logger;
|
|
23
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Given 04t the package type type (Managed, Unlocked, Locked(deprecated?))
|
|
27
|
+
*
|
|
28
|
+
* @param packageVersionId the 04t
|
|
29
|
+
* @param connection For tooling query
|
|
30
|
+
* @param installKey For tooling query, if an installation key is applicable to the package version it must be passed in the queries
|
|
31
|
+
* @throws Error with message when package2 cannot be found
|
|
32
|
+
*/
|
|
33
|
+
async function getPackageTypeBy04t(packageVersionId, connection, installKey) {
|
|
34
|
+
let query = `SELECT Package2ContainerOptions FROM SubscriberPackageVersion WHERE id ='${packageVersionId}'`;
|
|
35
|
+
if (installKey) {
|
|
36
|
+
const escapedInstallationKey = installKey.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
|
37
|
+
query += ` AND InstallationKey ='${escapedInstallationKey}'`;
|
|
38
|
+
}
|
|
39
|
+
const queryResult = await connection.tooling.query(query);
|
|
40
|
+
if (!queryResult || queryResult.records === null || queryResult.records.length === 0) {
|
|
41
|
+
throw installMsgs.createError('errorInvalidPackageId', [packageVersionId]);
|
|
42
|
+
}
|
|
43
|
+
return queryResult.records[0].Package2ContainerOptions;
|
|
44
|
+
}
|
|
24
45
|
async function installPackage(connection, pkgInstallCreateRequest, options) {
|
|
25
46
|
const defaults = {
|
|
26
47
|
ApexCompileType: 'all',
|
|
@@ -32,25 +53,25 @@ async function installPackage(connection, pkgInstallCreateRequest, options) {
|
|
|
32
53
|
};
|
|
33
54
|
const request = Object.assign({}, defaults, pkgInstallCreateRequest);
|
|
34
55
|
if (request.Password) {
|
|
35
|
-
request.Password = (0,
|
|
56
|
+
request.Password = (0, utils_1.escapeInstallationKey)(request.Password);
|
|
36
57
|
}
|
|
37
|
-
const pkgType = await
|
|
58
|
+
const pkgType = await getPackageTypeBy04t(request.SubscriberPackageVersionKey, connection, request.Password);
|
|
38
59
|
// Only unlocked packages can change the UpgradeType and ApexCompile options from the defaults.
|
|
39
60
|
if (pkgType !== 'Unlocked') {
|
|
40
61
|
if (request.UpgradeType !== defaults.UpgradeType) {
|
|
41
62
|
const msg = installMsgs.getMessage('upgradeTypeOnlyForUnlockedWarning');
|
|
42
|
-
await core_1.Lifecycle.getInstance().emit(
|
|
63
|
+
await core_1.Lifecycle.getInstance().emit(interfaces_1.PackageEvents.install.warning, msg);
|
|
43
64
|
delete request.UpgradeType;
|
|
44
65
|
}
|
|
45
66
|
if (request.ApexCompileType !== defaults.ApexCompileType) {
|
|
46
67
|
const msg = installMsgs.getMessage('apexCompileOnlyForUnlockedWarning');
|
|
47
|
-
await core_1.Lifecycle.getInstance().emit(
|
|
68
|
+
await core_1.Lifecycle.getInstance().emit(interfaces_1.PackageEvents.install.warning, msg);
|
|
48
69
|
delete request.ApexCompileType;
|
|
49
70
|
}
|
|
50
71
|
}
|
|
51
|
-
await core_1.Lifecycle.getInstance().emit(
|
|
72
|
+
await core_1.Lifecycle.getInstance().emit(interfaces_1.PackageEvents.install.presend, request);
|
|
52
73
|
const result = await connection.tooling.create('PackageInstallRequest', request);
|
|
53
|
-
await core_1.Lifecycle.getInstance().emit(
|
|
74
|
+
await core_1.Lifecycle.getInstance().emit(interfaces_1.PackageEvents.install.postsend, result);
|
|
54
75
|
const packageInstallRequestId = result.id;
|
|
55
76
|
if (!packageInstallRequestId) {
|
|
56
77
|
throw installMsgs.createError('packageInstallRequestError', [
|
|
@@ -78,7 +99,7 @@ async function getExternalSites(connection, subscriberPackageVersionId, installa
|
|
|
78
99
|
const queryNoKey = `SELECT RemoteSiteSettings, CspTrustedSites FROM SubscriberPackageVersion WHERE Id ='${subscriberPackageVersionId}'`;
|
|
79
100
|
let queryResult;
|
|
80
101
|
try {
|
|
81
|
-
const escapedInstallationKey = installationKey ? (0,
|
|
102
|
+
const escapedInstallationKey = installationKey ? (0, utils_1.escapeInstallationKey)(installationKey) : null;
|
|
82
103
|
const queryWithKey = `${queryNoKey} AND InstallationKey ='${escapedInstallationKey}'`;
|
|
83
104
|
getLogger().debug(`Checking package: [${subscriberPackageVersionId}] for external sites`);
|
|
84
105
|
queryResult = await connection.tooling.query(queryWithKey);
|
|
@@ -86,7 +107,7 @@ async function getExternalSites(connection, subscriberPackageVersionId, installa
|
|
|
86
107
|
catch (e) {
|
|
87
108
|
// First check for Implementation Restriction error that is enforced in 214, before it was possible to query
|
|
88
109
|
// against InstallationKey, otherwise surface the error.
|
|
89
|
-
if (e instanceof Error &&
|
|
110
|
+
if (e instanceof Error && isErrorFromSPVQueryRestriction(e)) {
|
|
90
111
|
queryResult = await connection.tooling.query(queryNoKey);
|
|
91
112
|
}
|
|
92
113
|
else {
|
|
@@ -132,7 +153,7 @@ async function pollStatus(connection, installRequestId, options) {
|
|
|
132
153
|
poll: async () => {
|
|
133
154
|
packageInstallRequest = await getStatus(connection, installRequestId);
|
|
134
155
|
getLogger().debug(installMsgs.getMessage('packageInstallPolling', [packageInstallRequest?.Status]));
|
|
135
|
-
await core_1.Lifecycle.getInstance().emit(
|
|
156
|
+
await core_1.Lifecycle.getInstance().emit(interfaces_1.PackageEvents.install.status, packageInstallRequest);
|
|
136
157
|
if (['SUCCESS', 'ERROR'].includes(packageInstallRequest?.Status)) {
|
|
137
158
|
return { completed: true, payload: packageInstallRequest };
|
|
138
159
|
}
|
|
@@ -158,6 +179,18 @@ async function pollStatus(connection, installRequestId, options) {
|
|
|
158
179
|
throw error;
|
|
159
180
|
}
|
|
160
181
|
}
|
|
182
|
+
// determines if error is from malformed SubscriberPackageVersion query
|
|
183
|
+
// this is in place to allow cli to run against app version 214, where SPV queries
|
|
184
|
+
// do not require installation key
|
|
185
|
+
function isErrorFromSPVQueryRestriction(err) {
|
|
186
|
+
return (err.name === 'MALFORMED_QUERY' &&
|
|
187
|
+
err.message.includes('Implementation restriction: You can only perform queries of the form Id'));
|
|
188
|
+
}
|
|
189
|
+
exports.isErrorFromSPVQueryRestriction = isErrorFromSPVQueryRestriction;
|
|
190
|
+
function isErrorPackageNotAvailable(err) {
|
|
191
|
+
return err.name === 'UNKNOWN_EXCEPTION' || err.name === 'PACKAGE_UNAVAILABLE';
|
|
192
|
+
}
|
|
193
|
+
exports.isErrorPackageNotAvailable = isErrorPackageNotAvailable;
|
|
161
194
|
async function waitForPublish(connection, subscriberPackageVersionId, timeout, installationKey) {
|
|
162
195
|
let queryResult;
|
|
163
196
|
const pollingOptions = {
|
|
@@ -166,18 +199,18 @@ async function waitForPublish(connection, subscriberPackageVersionId, timeout, i
|
|
|
166
199
|
poll: async () => {
|
|
167
200
|
const QUERY_NO_KEY = `SELECT Id, SubscriberPackageId, InstallValidationStatus FROM SubscriberPackageVersion WHERE Id ='${subscriberPackageVersionId}'`;
|
|
168
201
|
try {
|
|
169
|
-
const escapedInstallationKey = installationKey ? (0,
|
|
202
|
+
const escapedInstallationKey = installationKey ? (0, utils_1.escapeInstallationKey)(installationKey) : null;
|
|
170
203
|
const queryWithKey = `${QUERY_NO_KEY} AND InstallationKey ='${escapedInstallationKey}'`;
|
|
171
204
|
queryResult = await connection.tooling.query(queryWithKey);
|
|
172
205
|
}
|
|
173
206
|
catch (e) {
|
|
174
207
|
// Check first for Implementation Restriction error that is enforced in 214, before it was possible to query
|
|
175
208
|
// against InstallationKey, otherwise surface the error.
|
|
176
|
-
if (e instanceof Error &&
|
|
209
|
+
if (e instanceof Error && isErrorFromSPVQueryRestriction(e)) {
|
|
177
210
|
queryResult = await connection.tooling.query(QUERY_NO_KEY);
|
|
178
211
|
}
|
|
179
212
|
else {
|
|
180
|
-
if (e instanceof Error && !
|
|
213
|
+
if (e instanceof Error && !isErrorPackageNotAvailable(e)) {
|
|
181
214
|
throw e;
|
|
182
215
|
}
|
|
183
216
|
}
|
|
@@ -188,14 +221,14 @@ async function waitForPublish(connection, subscriberPackageVersionId, timeout, i
|
|
|
188
221
|
let installValidationStatus;
|
|
189
222
|
if (queryResult?.records?.length) {
|
|
190
223
|
installValidationStatus = queryResult.records[0].InstallValidationStatus;
|
|
191
|
-
await core_1.Lifecycle.getInstance().emit('
|
|
224
|
+
await core_1.Lifecycle.getInstance().emit(interfaces_1.PackageEvents.install['subscriber-status'], installValidationStatus);
|
|
192
225
|
if (!['PACKAGE_UNAVAILABLE', 'UNINSTALL_IN_PROGRESS'].includes(installValidationStatus)) {
|
|
193
226
|
return { completed: true, payload: queryResult };
|
|
194
227
|
}
|
|
195
228
|
}
|
|
196
229
|
const tokens = installValidationStatus ? [` Status = ${installValidationStatus}`] : [];
|
|
197
230
|
getLogger().debug(installMsgs.getMessage('publishWaitProgress', tokens));
|
|
198
|
-
await core_1.Lifecycle.getInstance().emit('
|
|
231
|
+
await core_1.Lifecycle.getInstance().emit(interfaces_1.PackageEvents.install['subscriber-status'], installValidationStatus);
|
|
199
232
|
return { completed: false, payload: queryResult };
|
|
200
233
|
},
|
|
201
234
|
};
|
|
@@ -14,7 +14,7 @@ const xmldom_1 = require("@xmldom/xmldom");
|
|
|
14
14
|
const core_1 = require("@salesforce/core");
|
|
15
15
|
const kit_1 = require("@salesforce/kit");
|
|
16
16
|
core_1.Messages.importMessagesDirectory(__dirname);
|
|
17
|
-
const profileApiMessages = core_1.Messages.loadMessages('@salesforce/packaging', '
|
|
17
|
+
const profileApiMessages = core_1.Messages.loadMessages('@salesforce/packaging', 'profile_api');
|
|
18
18
|
/*
|
|
19
19
|
* This class provides functions used to re-write .profiles in the workspace when creating a package2 version.
|
|
20
20
|
* All profiles found in the workspaces are extracted out and then re-written to only include metadata in the profile
|