@salesforce/packaging 0.0.3 → 0.0.6
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/constants.d.ts +21 -0
- package/lib/constants.js +40 -0
- package/lib/interfaces/packagingInterfacesAndType.d.ts +111 -0
- package/lib/interfaces/packagingSObjects.d.ts +2 -1
- package/lib/interfaces/packagingSObjects.js +0 -6
- package/lib/package/index.d.ts +4 -0
- package/lib/package/index.js +8 -0
- package/lib/package/packageConvert.d.ts +11 -0
- package/lib/package/packageConvert.js +78 -0
- package/lib/package/packageCreate.d.ts +26 -0
- package/lib/package/packageCreate.js +115 -0
- package/lib/package/packageDelete.d.ts +3 -0
- package/lib/package/packageDelete.js +26 -0
- package/lib/package/packageVersion.d.ts +8 -0
- package/lib/package/packageVersion.js +27 -0
- package/lib/package/packageVersionCreate.d.ts +70 -0
- package/lib/package/packageVersionCreate.js +781 -0
- package/lib/package/packageVersionCreateRequest.d.ts +4 -0
- package/lib/package/packageVersionCreateRequest.js +85 -0
- package/lib/package/packageVersionList.d.ts +9 -0
- package/lib/package/packageVersionList.js +91 -0
- package/lib/package/profileApi.d.ts +55 -0
- package/lib/package/profileApi.js +275 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +1 -0
- package/lib/utils/packageUtils.d.ts +7 -6
- package/lib/utils/packageUtils.js +51 -13
- package/lib/utils/srcDevUtils.d.ts +12 -0
- package/lib/utils/srcDevUtils.js +62 -0
- package/lib/utils/versionNumber.d.ts +1 -0
- package/lib/utils/versionNumber.js +5 -0
- package/messages/messages.md +17 -0
- package/package.json +10 -5
- package/lib/package/packageVersionCreateRequestApi.d.ts +0 -17
- package/lib/package/packageVersionCreateRequestApi.js +0 -92
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveCanonicalPackageProperty = exports.combineSaveErrors = exports.formatDate = exports.getSoqlWhereClauseMaxLength = exports.pollForStatusWithInterval = exports.findOrCreatePackage2 = exports.getPackageAliasesFromId = exports.convertCamelCaseStringToSentence = exports.getPackageIdFromAlias = exports.getConfigPackageDirectory = exports.getConfigPackageDirectories = exports.getPackage2VersionNumber = exports.concatVersion = exports.getAncestorIdHighestRelease = exports.validateAncestorId = exports.getAncestorId = exports.getInClauseItemsCount = exports.queryWithInConditionChunking = exports.getPackageVersionStrings = exports.getHasMetadataRemoved = exports.getContainerOptions = exports.getSubscriberPackageVersionId = exports.getPackage2TypeBy04t = exports.getPackage2Type = exports.getPackageVersionId = exports.applyErrorAction = exports.massageErrorMessage = exports.isErrorPackageNotAvailable = exports.isErrorFromSPVQueryRestriction = exports.validUrl = 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;
|
|
2
4
|
/*
|
|
3
5
|
* Copyright (c) 2022, salesforce.com, inc.
|
|
4
6
|
* All rights reserved.
|
|
5
7
|
* Licensed under the BSD 3-Clause license.
|
|
6
8
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
9
|
*/
|
|
8
|
-
|
|
9
|
-
exports.formatDate = exports.getSoqlWhereClauseMaxLength = exports.pollForStatusWithInterval = exports._getPackageVersionCreateRequestApi = exports.findOrCreatePackage2 = exports.getPackageAliasesFromId = exports.convertCamelCaseStringToSentence = exports.getPackageIdFromAlias = exports.getConfigPackageDirectory = exports.getConfigPackageDirectories = exports.getPackage2VersionNumber = exports.concatVersion = exports.getAncestorIdHighestRelease = exports.validateAncestorId = exports.getAncestorId = exports.getInClauseItemsCount = exports.queryWithInConditionChunking = exports.getPackageVersionStrings = exports.getHasMetadataRemoved = exports.getContainerOptions = exports.getSubscriberPackageVersionId = exports.getPackage2TypeBy04t = exports.getPackage2Type = exports.getPackageVersionId = exports.applyErrorAction = exports.massageErrorMessage = exports.isErrorPackageNotAvailable = exports.isErrorFromSPVQueryRestriction = exports.validUrl = 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;
|
|
10
|
+
const os = require("os");
|
|
10
11
|
const core_1 = require("@salesforce/core");
|
|
11
12
|
const kit_1 = require("@salesforce/kit");
|
|
12
13
|
const interfaces_1 = require("../interfaces");
|
|
13
|
-
const
|
|
14
|
+
const pvcr = require("../package/packageVersionCreateRequest");
|
|
14
15
|
const versionNumber_1 = require("./versionNumber");
|
|
15
16
|
var Package2VersionStatus = interfaces_1.PackagingSObjects.Package2VersionStatus;
|
|
16
17
|
core_1.Messages.importMessagesDirectory(__dirname);
|
|
@@ -282,7 +283,7 @@ async function getContainerOptions(package2Ids, connection) {
|
|
|
282
283
|
if (!package2Ids || package2Ids.length === 0) {
|
|
283
284
|
return new Map();
|
|
284
285
|
}
|
|
285
|
-
const query =
|
|
286
|
+
const query = "SELECT Id, ContainerOptions FROM Package2 WHERE Id IN ('%IDS%')";
|
|
286
287
|
const records = await queryWithInConditionChunking(query, package2Ids, '%IDS%', connection);
|
|
287
288
|
if (records && records.length > 0) {
|
|
288
289
|
return new Map(records.map((record) => [record.Id, record.ContainerOptions]));
|
|
@@ -618,13 +619,14 @@ exports.convertCamelCaseStringToSentence = convertCamelCaseStringToSentence;
|
|
|
618
619
|
* @returns an array of alias for the given id.
|
|
619
620
|
*/
|
|
620
621
|
function getPackageAliasesFromId(packageId, project) {
|
|
621
|
-
const packageAliases = project.getSfProjectJson().getContents().packageAliases || {};
|
|
622
|
+
const packageAliases = (project === null || project === void 0 ? void 0 : project.getSfProjectJson().getContents().packageAliases) || {};
|
|
622
623
|
// check for a matching alias
|
|
623
624
|
return Object.entries(packageAliases)
|
|
624
625
|
.filter((alias) => alias[1] === packageId)
|
|
625
626
|
.map((alias) => alias[0]);
|
|
626
627
|
}
|
|
627
628
|
exports.getPackageAliasesFromId = getPackageAliasesFromId;
|
|
629
|
+
// probably used by convert.
|
|
628
630
|
async function findOrCreatePackage2(seedPackage, connection) {
|
|
629
631
|
const query = `SELECT Id FROM Package2 WHERE ConvertedFromPackageId = '${seedPackage}'`;
|
|
630
632
|
const queryResult = await connection.tooling.query(query);
|
|
@@ -653,22 +655,17 @@ async function findOrCreatePackage2(seedPackage, connection) {
|
|
|
653
655
|
};
|
|
654
656
|
const createResult = await connection.tooling.create('Package2', request);
|
|
655
657
|
if (!createResult.success) {
|
|
656
|
-
throw
|
|
658
|
+
throw combineSaveErrors('Package2', 'create', createResult.errors);
|
|
657
659
|
}
|
|
658
660
|
return createResult.id;
|
|
659
661
|
}
|
|
660
662
|
exports.findOrCreatePackage2 = findOrCreatePackage2;
|
|
661
|
-
function
|
|
662
|
-
return new packageVersionCreateRequestApi_1.PackageVersionCreateRequestApi({ connection });
|
|
663
|
-
}
|
|
664
|
-
exports._getPackageVersionCreateRequestApi = _getPackageVersionCreateRequestApi;
|
|
665
|
-
async function pollForStatusWithInterval(context, id, retries, packageId, branch, withProject, connection, interval) {
|
|
663
|
+
async function pollForStatusWithInterval(id, retries, packageId, branch, withProject, connection, interval) {
|
|
666
664
|
let remainingRetries = retries;
|
|
667
665
|
const pollingClient = await core_1.PollingClient.create({
|
|
668
666
|
poll: async () => {
|
|
669
667
|
var _a;
|
|
670
|
-
const
|
|
671
|
-
const results = await pvcrApi.byId(id);
|
|
668
|
+
const results = await pvcr.byId(id, connection);
|
|
672
669
|
if (_isStatusEqualTo(results, [Package2VersionStatus.success, Package2VersionStatus.error])) {
|
|
673
670
|
// complete
|
|
674
671
|
if (_isStatusEqualTo(results, [Package2VersionStatus.success])) {
|
|
@@ -783,4 +780,45 @@ function formatDate(date) {
|
|
|
783
780
|
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
784
781
|
}
|
|
785
782
|
exports.formatDate = formatDate;
|
|
783
|
+
function combineSaveErrors(sObject, crudOperation, errors) {
|
|
784
|
+
const errorMessages = errors.map((error) => {
|
|
785
|
+
var _a;
|
|
786
|
+
const fieldsString = ((_a = error.fields) === null || _a === void 0 ? void 0 : _a.length) > 0 ? `Fields: [${error.fields.join(', ')}]` : '';
|
|
787
|
+
return `Error: ${error.errorCode} Message: ${error.message} ${fieldsString}`;
|
|
788
|
+
});
|
|
789
|
+
const sfError = messages.createError('errorDuringSObjectCRUDOperation', [
|
|
790
|
+
crudOperation,
|
|
791
|
+
sObject,
|
|
792
|
+
errorMessages.join(os.EOL),
|
|
793
|
+
]);
|
|
794
|
+
return sfError;
|
|
795
|
+
}
|
|
796
|
+
exports.combineSaveErrors = combineSaveErrors;
|
|
797
|
+
function resolveCanonicalPackageProperty(options) {
|
|
798
|
+
let canonicalPackageProperty;
|
|
799
|
+
if (!options.package) {
|
|
800
|
+
const packageValProp = this.getPackageValuePropertyFromDirectory(options.path, options);
|
|
801
|
+
options.package = packageValProp.packageValue;
|
|
802
|
+
canonicalPackageProperty = packageValProp.packageProperty;
|
|
803
|
+
}
|
|
804
|
+
else if (!options.path) {
|
|
805
|
+
canonicalPackageProperty = this.getPackagePropertyFromPackage(this.project.getPackageDirectories(), options);
|
|
806
|
+
options.path = this.getConfigPackageDirectoriesValue(this.project.getPackageDirectories(), 'path', canonicalPackageProperty, options.package, 'package', options);
|
|
807
|
+
}
|
|
808
|
+
else {
|
|
809
|
+
canonicalPackageProperty = this.getPackagePropertyFromPackage(this.project.getPackageDirectories(), options);
|
|
810
|
+
this.getConfigPackageDirectoriesValue(this.project.getPackageDirectories(), canonicalPackageProperty, 'path', options.path, 'path', options);
|
|
811
|
+
const expectedPackageId = this.getConfigPackageDirectoriesValue(this.packageDirs, canonicalPackageProperty, 'path', options.path, 'path', options);
|
|
812
|
+
// This will throw an error if the package id flag value doesn't match
|
|
813
|
+
// any of the :id values in the package dirs.
|
|
814
|
+
this.getConfigPackageDirectoriesValue(this.project.getPackageDirectories(), 'path', canonicalPackageProperty, options.package, 'package', options);
|
|
815
|
+
// This will throw an error if the package id flag value doesn't match
|
|
816
|
+
// the correct corresponding directory with that packageId.
|
|
817
|
+
if (options.package !== expectedPackageId) {
|
|
818
|
+
throw messages.createError('errorDirectoryIdMismatch', ['--path', options.path, '--package', options.package]);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
return canonicalPackageProperty;
|
|
822
|
+
}
|
|
823
|
+
exports.resolveCanonicalPackageProperty = resolveCanonicalPackageProperty;
|
|
786
824
|
//# sourceMappingURL=packageUtils.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zips directory to given zipfile.
|
|
3
|
+
*
|
|
4
|
+
* https://github.com/archiverjs/node-archiver
|
|
5
|
+
*
|
|
6
|
+
* @param dir to zip
|
|
7
|
+
* @param zipfile
|
|
8
|
+
* @param options
|
|
9
|
+
*/
|
|
10
|
+
export declare function zipDir(dir: string, zipfile: string, options?: {}): Promise<void>;
|
|
11
|
+
export declare function getElapsedTime(timer: [number, number]): string;
|
|
12
|
+
export declare function copyDir(src: string, dest: string): void;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.copyDir = exports.getElapsedTime = exports.zipDir = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (c) 2020, salesforce.com, inc.
|
|
6
|
+
* All rights reserved.
|
|
7
|
+
* Licensed under the BSD 3-Clause license.
|
|
8
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
9
|
+
*/
|
|
10
|
+
const path = require("path");
|
|
11
|
+
const os = require("os");
|
|
12
|
+
const fs = require("fs");
|
|
13
|
+
const path_1 = require("path");
|
|
14
|
+
const archiver = require("archiver");
|
|
15
|
+
const core_1 = require("@salesforce/core");
|
|
16
|
+
/**
|
|
17
|
+
* Zips directory to given zipfile.
|
|
18
|
+
*
|
|
19
|
+
* https://github.com/archiverjs/node-archiver
|
|
20
|
+
*
|
|
21
|
+
* @param dir to zip
|
|
22
|
+
* @param zipfile
|
|
23
|
+
* @param options
|
|
24
|
+
*/
|
|
25
|
+
async function zipDir(dir, zipfile, options = {}) {
|
|
26
|
+
const logger = core_1.Logger.childFromRoot('srcDevUtils#zipDir');
|
|
27
|
+
const file = path.parse(dir);
|
|
28
|
+
const outFile = zipfile || path.join(os.tmpdir() || '.', `${file.base}.zip`);
|
|
29
|
+
const output = fs.createWriteStream(outFile);
|
|
30
|
+
const timer = process.hrtime();
|
|
31
|
+
const archive = archiver('zip', options);
|
|
32
|
+
archive.on('finish', () => {
|
|
33
|
+
logger.debug(`${archive.pointer()} bytes written to ${outFile} using ${getElapsedTime(timer)}ms`);
|
|
34
|
+
// zip file returned once stream is closed, see 'close' listener below
|
|
35
|
+
});
|
|
36
|
+
archive.on('error', (err) => {
|
|
37
|
+
Promise.reject(err);
|
|
38
|
+
});
|
|
39
|
+
output.on('close', () => {
|
|
40
|
+
Promise.resolve(outFile);
|
|
41
|
+
});
|
|
42
|
+
archive.pipe(output);
|
|
43
|
+
archive.directory(dir, '');
|
|
44
|
+
return await archive.finalize();
|
|
45
|
+
}
|
|
46
|
+
exports.zipDir = zipDir;
|
|
47
|
+
function getElapsedTime(timer) {
|
|
48
|
+
const elapsed = process.hrtime(timer);
|
|
49
|
+
return (elapsed[0] * 1000 + elapsed[1] / 1000000).toFixed(3);
|
|
50
|
+
}
|
|
51
|
+
exports.getElapsedTime = getElapsedTime;
|
|
52
|
+
function copyDir(src, dest) {
|
|
53
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
54
|
+
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
55
|
+
entries.map((entry) => {
|
|
56
|
+
const srcPath = (0, path_1.join)(src, entry.name);
|
|
57
|
+
const destPath = (0, path_1.join)(dest, entry.name);
|
|
58
|
+
return entry.isDirectory() ? copyDir(srcPath, destPath) : fs.copyFileSync(srcPath, destPath);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
exports.copyDir = copyDir;
|
|
62
|
+
//# sourceMappingURL=srcDevUtils.js.map
|
|
@@ -51,6 +51,11 @@ class VersionNumber {
|
|
|
51
51
|
return `${this.major || '0'}.${this.minor || '0'}.${this.patch || '0'}.${this.build ? `${this.build}` : '0'}`;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
+
isbuildKeyword() {
|
|
55
|
+
return Object.values(BuildNumberToken)
|
|
56
|
+
.map((v) => v.toString())
|
|
57
|
+
.includes(this.build.toLowerCase());
|
|
58
|
+
}
|
|
54
59
|
}
|
|
55
60
|
exports.VersionNumber = VersionNumber;
|
|
56
61
|
//# sourceMappingURL=versionNumber.js.map
|
package/messages/messages.md
CHANGED
|
@@ -189,3 +189,20 @@ Can’t create package version. Specifying an ancestor is available only for sec
|
|
|
189
189
|
|
|
190
190
|
When calculating the number of items to be included in query "%s", when formatted, was too long.
|
|
191
191
|
The item was (truncated): %s with a length of %s. The maximum length of items, when formatted is %s.
|
|
192
|
+
|
|
193
|
+
# unableToFindPackageWithId
|
|
194
|
+
|
|
195
|
+
Unable to find Package with Id: "%s"
|
|
196
|
+
|
|
197
|
+
# errorDuringSObjectCRUDOperation
|
|
198
|
+
|
|
199
|
+
An error occurred during CRUD operation %s on entity %s.
|
|
200
|
+
%s
|
|
201
|
+
|
|
202
|
+
# errorNoMatchingPackageDirectory
|
|
203
|
+
|
|
204
|
+
The %s value [%s], doesn’t match the %s value in any packageDirectories specified in sfdx-project.json.
|
|
205
|
+
|
|
206
|
+
# errorDirectoryIdMismatch
|
|
207
|
+
|
|
208
|
+
The %s value, [%s], and %s value, [%s], were both found in sfdx-project.json but don’t match. If you supply both values, they must match the path and package values in one of the packageDirectories.,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/packaging",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "packing libraries to Salesforce packaging platform",
|
|
5
5
|
"main": "lib/exported",
|
|
6
6
|
"types": "lib/exported.d.ts",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"prepack": "sf-prepack",
|
|
20
20
|
"prepare": "sf-install",
|
|
21
21
|
"pretest": "sf-compile-test",
|
|
22
|
-
"test": "sf-test"
|
|
22
|
+
"test": "sf-test",
|
|
23
|
+
"test:nuts": "nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 600000 --parallel"
|
|
23
24
|
},
|
|
24
25
|
"keywords": [
|
|
25
26
|
"force",
|
|
@@ -34,9 +35,10 @@
|
|
|
34
35
|
"!lib/**/*.map"
|
|
35
36
|
],
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"@salesforce/core": "^3.
|
|
38
|
+
"@salesforce/core": "^3.23.4",
|
|
38
39
|
"@salesforce/kit": "^1.5.42",
|
|
39
40
|
"@salesforce/schemas": "^1.2.0",
|
|
41
|
+
"@salesforce/source-deploy-retrieve": "^6.2.0",
|
|
40
42
|
"@salesforce/ts-types": "^1.5.20",
|
|
41
43
|
"@types/graceful-fs": "^4.1.5",
|
|
42
44
|
"@types/mkdirp": "^1.0.2",
|
|
@@ -47,11 +49,14 @@
|
|
|
47
49
|
"debug": "^4.3.4",
|
|
48
50
|
"graceful-fs": "^4.2.10",
|
|
49
51
|
"js2xmlparser": "^4.0.2",
|
|
50
|
-
"jsforce": "
|
|
52
|
+
"jsforce": "beta",
|
|
51
53
|
"mkdirp": "1.0.4",
|
|
52
|
-
"ts-retry-promise": "^0.6.1"
|
|
54
|
+
"ts-retry-promise": "^0.6.1",
|
|
55
|
+
"xml2js": "^0.4.23",
|
|
56
|
+
"xmldom-sfdx-encoding": "^0.1.30"
|
|
53
57
|
},
|
|
54
58
|
"devDependencies": {
|
|
59
|
+
"@salesforce/cli-plugins-testkit": "^2.3.0",
|
|
55
60
|
"@salesforce/dev-config": "^3.0.1",
|
|
56
61
|
"@salesforce/dev-scripts": "^2.0.2",
|
|
57
62
|
"@salesforce/prettier-config": "^0.0.2",
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Connection } from '@salesforce/core';
|
|
2
|
-
import { Package2VersionCreateRequestResult } from '../interfaces';
|
|
3
|
-
declare type PackageVersionCreateRequestApiOptions = {
|
|
4
|
-
createdlastdays?: number;
|
|
5
|
-
connection?: Connection;
|
|
6
|
-
status?: string;
|
|
7
|
-
};
|
|
8
|
-
export declare class PackageVersionCreateRequestApi {
|
|
9
|
-
private options;
|
|
10
|
-
constructor(options: PackageVersionCreateRequestApiOptions);
|
|
11
|
-
list(options?: PackageVersionCreateRequestApiOptions): Promise<Package2VersionCreateRequestResult[]>;
|
|
12
|
-
byId(package2VersionCreateRequestId: any): Promise<Package2VersionCreateRequestResult[]>;
|
|
13
|
-
private _query;
|
|
14
|
-
private _queryErrors;
|
|
15
|
-
private _constructWhere;
|
|
16
|
-
}
|
|
17
|
-
export {};
|
|
@@ -1,92 +0,0 @@
|
|
|
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.PackageVersionCreateRequestApi = void 0;
|
|
10
|
-
// Node
|
|
11
|
-
const util = require("util");
|
|
12
|
-
// Local
|
|
13
|
-
const core_1 = require("@salesforce/core");
|
|
14
|
-
core_1.Messages.importMessagesDirectory(__dirname);
|
|
15
|
-
const messages = core_1.Messages.loadMessages('@salesforce/packaging', 'messages');
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
17
|
-
const packageUtils = require('../utils/packageUtils');
|
|
18
|
-
const STATUS_ERROR = 'Error';
|
|
19
|
-
const QUERY = 'SELECT Id, Status, Package2Id, Package2VersionId, Package2Version.SubscriberPackageVersionId, Tag, Branch, ' +
|
|
20
|
-
'CreatedDate, Package2Version.HasMetadataRemoved, CreatedById ' +
|
|
21
|
-
'FROM Package2VersionCreateRequest ' +
|
|
22
|
-
'%s' + // WHERE, if applicable
|
|
23
|
-
'ORDER BY CreatedDate';
|
|
24
|
-
const ERROR_QUERY = "SELECT Message FROM Package2VersionCreateRequestError WHERE ParentRequest.Id = '%s'";
|
|
25
|
-
const STATUSES = ['Queued', 'InProgress', 'Success', 'Error'];
|
|
26
|
-
class PackageVersionCreateRequestApi {
|
|
27
|
-
constructor(options) {
|
|
28
|
-
this.options = options;
|
|
29
|
-
}
|
|
30
|
-
list(options = {}) {
|
|
31
|
-
const whereClause = this._constructWhere();
|
|
32
|
-
return this._query(util.format(QUERY, whereClause));
|
|
33
|
-
}
|
|
34
|
-
async byId(package2VersionCreateRequestId) {
|
|
35
|
-
const results = await this._query(util.format(QUERY, `WHERE Id = '${package2VersionCreateRequestId}' `));
|
|
36
|
-
if (results && results.length === 1 && results[0].Status === STATUS_ERROR) {
|
|
37
|
-
results[0].Error = await this._queryErrors(package2VersionCreateRequestId);
|
|
38
|
-
}
|
|
39
|
-
return results;
|
|
40
|
-
}
|
|
41
|
-
async _query(query) {
|
|
42
|
-
const queryResult = await this.options.connection.tooling.query(query);
|
|
43
|
-
return (queryResult.records ? queryResult.records : []).map((record) => ({
|
|
44
|
-
Id: record.Id,
|
|
45
|
-
Status: record.Status,
|
|
46
|
-
Package2Id: record.Package2Id,
|
|
47
|
-
Package2VersionId: record.Package2VersionId,
|
|
48
|
-
SubscriberPackageVersionId: record.Package2Version != null ? record.Package2Version.SubscriberPackageVersionId : null,
|
|
49
|
-
Tag: record.Tag,
|
|
50
|
-
Branch: record.Branch,
|
|
51
|
-
Error: [],
|
|
52
|
-
CreatedDate: packageUtils.formatDate(new Date(record.CreatedDate)),
|
|
53
|
-
HasMetadataRemoved: record.Package2Version != null ? record.Package2Version.HasMetadataRemoved : null,
|
|
54
|
-
CreatedBy: record.CreatedById,
|
|
55
|
-
}));
|
|
56
|
-
}
|
|
57
|
-
async _queryErrors(package2VersionCreateRequestId) {
|
|
58
|
-
const errorResults = [];
|
|
59
|
-
const queryResult = await this.options.connection.tooling.query(util.format(ERROR_QUERY, package2VersionCreateRequestId));
|
|
60
|
-
if (queryResult.records) {
|
|
61
|
-
queryResult.records.forEach((record) => {
|
|
62
|
-
errorResults.push(record.Message);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
return errorResults;
|
|
66
|
-
}
|
|
67
|
-
_constructWhere() {
|
|
68
|
-
const where = [];
|
|
69
|
-
// filter on created date, days ago: 0 for today, etc
|
|
70
|
-
if (!util.isNullOrUndefined(this.options.createdlastdays)) {
|
|
71
|
-
if (this.options.createdlastdays < 0) {
|
|
72
|
-
throw new Error(messages.getMessage('invalidDaysNumber', ['createdlastdays', this.options.createdlastdays]));
|
|
73
|
-
}
|
|
74
|
-
where.push(`CreatedDate = LAST_N_DAYS:${this.options.createdlastdays}`);
|
|
75
|
-
}
|
|
76
|
-
// filter on errors
|
|
77
|
-
if (this.options.status) {
|
|
78
|
-
const foundStatus = STATUSES.find((status) => status.toLowerCase() === this.options.status.toLowerCase());
|
|
79
|
-
if (!foundStatus) {
|
|
80
|
-
const args = [this.options.status];
|
|
81
|
-
STATUSES.forEach((status) => {
|
|
82
|
-
args.push(status);
|
|
83
|
-
});
|
|
84
|
-
throw new Error(messages.getMessage('invalidStatus', args));
|
|
85
|
-
}
|
|
86
|
-
where.push(`Status = '${foundStatus}'`);
|
|
87
|
-
}
|
|
88
|
-
return where.length > 0 ? `WHERE ${where.join(' AND ')}` : '';
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
exports.PackageVersionCreateRequestApi = PackageVersionCreateRequestApi;
|
|
92
|
-
//# sourceMappingURL=packageVersionCreateRequestApi.js.map
|