@salesforce/packaging 0.0.4 → 0.0.7

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/lib/constants.d.ts +21 -0
  3. package/lib/constants.js +40 -0
  4. package/lib/interfaces/packagingInterfacesAndType.d.ts +85 -4
  5. package/lib/interfaces/packagingSObjects.d.ts +2 -1
  6. package/lib/interfaces/packagingSObjects.js +0 -6
  7. package/lib/package/index.d.ts +4 -1
  8. package/lib/package/index.js +7 -2
  9. package/lib/package/packageConvert.d.ts +11 -0
  10. package/lib/package/packageConvert.js +84 -0
  11. package/lib/package/packageCreate.d.ts +26 -0
  12. package/lib/package/packageCreate.js +115 -0
  13. package/lib/package/packageDelete.d.ts +3 -0
  14. package/lib/package/packageDelete.js +26 -0
  15. package/lib/package/packageProfileApi.d.ts +59 -0
  16. package/lib/package/packageProfileApi.js +278 -0
  17. package/lib/package/packageVersion.d.ts +25 -0
  18. package/lib/package/packageVersion.js +73 -0
  19. package/lib/package/packageVersionCreate.d.ts +68 -0
  20. package/lib/package/packageVersionCreate.js +758 -0
  21. package/lib/package/packageVersionCreateRequest.d.ts +4 -0
  22. package/lib/package/packageVersionCreateRequest.js +85 -0
  23. package/lib/package/packageVersionList.d.ts +4 -24
  24. package/lib/package/packageVersionList.js +4 -5
  25. package/lib/utils/index.d.ts +1 -0
  26. package/lib/utils/index.js +1 -0
  27. package/lib/utils/packageUtils.d.ts +15 -14
  28. package/lib/utils/packageUtils.js +77 -39
  29. package/lib/utils/srcDevUtils.d.ts +12 -0
  30. package/lib/utils/srcDevUtils.js +66 -0
  31. package/lib/utils/versionNumber.d.ts +1 -0
  32. package/lib/utils/versionNumber.js +10 -5
  33. package/messages/messages.md +49 -0
  34. package/package.json +11 -16
  35. package/lib/package/packageVersion2GP.d.ts +0 -17
  36. package/lib/package/packageVersion2GP.js +0 -46
  37. package/lib/package/packageVersionCreateRequestApi.d.ts +0 -17
  38. package/lib/package/packageVersionCreateRequestApi.js +0 -92
package/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
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.7](https://github.com/forcedotcom/packaging/compare/v0.0.6...v0.0.7) (2022-07-14)
6
+
7
+ ### Bug Fixes
8
+
9
+ - add package version create/delete to library ([7713d4d](https://github.com/forcedotcom/packaging/commit/7713d4dc7d25f2a381a6972e57f24c9fbdcbae05))
10
+
11
+ ### [0.0.6](https://github.com/forcedotcom/packaging/compare/v0.0.5...v0.0.6) (2022-07-08)
12
+
13
+ ### Bug Fixes
14
+
15
+ - add pkg create and delete apis ([dedc609](https://github.com/forcedotcom/packaging/commit/dedc609398da3aa2e23e9108b54a535a95e75bf8))
16
+ - add pkg create and delete apis ([a1e37e2](https://github.com/forcedotcom/packaging/commit/a1e37e28e7886c451364413d0a47f3bfbda2b822))
17
+ - bump version top 0.0.6 ([8d800f9](https://github.com/forcedotcom/packaging/commit/8d800f9264333362cfd0dae03c92d60f314aa098))
18
+
19
+ ### [0.0.5](https://github.com/forcedotcom/packaging/compare/v0.0.4...v0.0.5) (2022-07-06)
20
+
5
21
  ### [0.0.4](https://github.com/forcedotcom/packaging/compare/v0.0.3...v0.0.4) (2022-06-23)
6
22
 
7
23
  ### [0.0.3](https://github.com/forcedotcom/packaging/compare/v0.0.2-test-02...v0.0.3) (2022-06-16)
@@ -0,0 +1,21 @@
1
+ export declare const consts: {
2
+ DEFAULT_USER_DIR_MODE: string;
3
+ DEFAULT_USER_FILE_MODE: string;
4
+ DEFAULT_STREAM_TIMEOUT_MINUTES: number;
5
+ MIN_STREAM_TIMEOUT_MINUTES: number;
6
+ DEFAULT_SRC_WAIT_MINUTES: number;
7
+ DEFAULT_MDAPI_WAIT_MINUTES: number;
8
+ DEFAULT_MDAPI_RETRIEVE_WAIT_MINUTES: number;
9
+ DEFAULT_MDAPI_POLL_INTERVAL_MINUTES: number;
10
+ DEFAULT_MDAPI_POLL_INTERVAL_MILLISECONDS: number;
11
+ MIN_SRC_WAIT_MINUTES: number;
12
+ MIN_SRC_DEPLOY_WAIT_MINUTES: number;
13
+ WORKSPACE_CONFIG_FILENAME: string;
14
+ OLD_WORKSPACE_CONFIG_FILENAME: string;
15
+ DEFAULT_DEV_HUB_USERNAME: string;
16
+ DEFAULT_USERNAME: string;
17
+ ACKNOWLEDGED_USAGE_COLLECTION_FILENAME: string;
18
+ PACKAGE_VERSION_INFO_FILE_ZIP: string;
19
+ INSTANCE_URL_TOKEN: string;
20
+ PACKAGE2_DESCRIPTOR_FILE: string;
21
+ };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2022, 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.consts = void 0;
10
+ /* --------------------------------------------------------------------------------------------------------------------
11
+ * WARNING: This file has been deprecated and should now be considered locked against further changes. Its contents
12
+ * have been partially or wholly superseded by functionality included in the @salesforce/core npm package, and exists
13
+ * now to service prior uses in this repository only until they can be ported to use the new @salesforce/core library.
14
+ *
15
+ * If you need or want help deciding where to add new functionality or how to migrate to the new library, please
16
+ * contact the CLI team at alm-cli@salesforce.com.
17
+ * ----------------------------------------------------------------------------------------------------------------- */
18
+ exports.consts = {
19
+ DEFAULT_USER_DIR_MODE: '700',
20
+ DEFAULT_USER_FILE_MODE: '600',
21
+ DEFAULT_STREAM_TIMEOUT_MINUTES: 6,
22
+ MIN_STREAM_TIMEOUT_MINUTES: 2,
23
+ DEFAULT_SRC_WAIT_MINUTES: 33,
24
+ DEFAULT_MDAPI_WAIT_MINUTES: 0,
25
+ DEFAULT_MDAPI_RETRIEVE_WAIT_MINUTES: -1,
26
+ DEFAULT_MDAPI_POLL_INTERVAL_MINUTES: 0.1,
27
+ DEFAULT_MDAPI_POLL_INTERVAL_MILLISECONDS: 0.1 * 60 * 1000,
28
+ MIN_SRC_WAIT_MINUTES: 1,
29
+ MIN_SRC_DEPLOY_WAIT_MINUTES: 0,
30
+ WORKSPACE_CONFIG_FILENAME: 'sfdx-project.json',
31
+ OLD_WORKSPACE_CONFIG_FILENAME: 'sfdx-workspace.json',
32
+ DEFAULT_DEV_HUB_USERNAME: 'defaultdevhubusername',
33
+ DEFAULT_USERNAME: 'defaultusername',
34
+ ACKNOWLEDGED_USAGE_COLLECTION_FILENAME: 'acknowledgedUsageCollection.json',
35
+ PACKAGE_VERSION_INFO_FILE_ZIP: 'package-version-info.zip',
36
+ // tokens to be replaced on source:push
37
+ INSTANCE_URL_TOKEN: '__SFDX_INSTANCE_URL__',
38
+ PACKAGE2_DESCRIPTOR_FILE: 'package2-descriptor.json',
39
+ };
40
+ //# sourceMappingURL=constants.js.map
@@ -1,4 +1,7 @@
1
1
  import { Duration } from '@salesforce/kit';
2
+ import { Connection, SfProject } from '@salesforce/core';
3
+ import { SaveResult } from 'jsforce';
4
+ import { PackageProfileApi } from '../package/packageProfileApi';
2
5
  import { PackagingSObjects } from './packagingSObjects';
3
6
  import Package2VersionStatus = PackagingSObjects.Package2VersionStatus;
4
7
  export interface IPackage {
@@ -31,7 +34,7 @@ export interface IPackageVersion2GP {
31
34
  export declare type PackageOptions = Record<string, unknown>;
32
35
  export declare type PackageVersion2Options = Record<string, unknown>;
33
36
  export declare type PackageVersionOptions1GP = Record<string, unknown>;
34
- export declare type Package2VersionCreateRequestResult = {
37
+ export declare type PackageVersionCreateRequestResult = {
35
38
  Id: string;
36
39
  Status: Package2VersionStatus;
37
40
  Package2Id: string;
@@ -44,13 +47,13 @@ export declare type Package2VersionCreateRequestResult = {
44
47
  HasMetadataRemoved: boolean | null;
45
48
  CreatedBy: string;
46
49
  };
47
- export declare type Package2VersionCreateRequestError = {
50
+ export declare type PackageVersionCreateRequestError = {
48
51
  Message: string;
49
52
  };
50
- export declare type Package2VersionCreateEventData = {
53
+ export declare type PackageVersionCreateEventData = {
51
54
  id: string;
52
55
  packageUpdated?: boolean;
53
- package2VersionCreateRequestResult: Package2VersionCreateRequestResult;
56
+ packageVersionCreateRequestResult: PackageVersionCreateRequestResult;
54
57
  message?: string;
55
58
  timeRemaining?: Duration;
56
59
  };
@@ -89,3 +92,81 @@ export declare type PackageVersionListResult = {
89
92
  BuildDurationInSeconds?: number;
90
93
  HasMetadataRemoved?: boolean;
91
94
  };
95
+ export declare type PackageType = 'Managed' | 'Unlocked';
96
+ export declare type PackageCreateOptions = {
97
+ name: string;
98
+ description: string;
99
+ noNamespace: boolean;
100
+ orgDependent: boolean;
101
+ packageType: PackageType;
102
+ errorNotificationUsername: string;
103
+ path: string;
104
+ };
105
+ export declare type PackageVersionQueryOptions = {
106
+ project: SfProject;
107
+ orderBy: string;
108
+ modifiedLastDays: number;
109
+ createdLastDays: number;
110
+ packages: string[];
111
+ connection: Connection;
112
+ verbose: boolean;
113
+ concise: boolean;
114
+ isReleased: boolean;
115
+ };
116
+ export declare type PackageSaveResult = SaveResult;
117
+ export declare type PackageVersionCreateRequestOptions = {
118
+ path: string;
119
+ preserve: boolean;
120
+ definitionfile?: string;
121
+ codecoverage?: boolean;
122
+ branch?: string;
123
+ skipancestorcheck?: boolean;
124
+ };
125
+ export declare type MDFolderForArtifactOptions = {
126
+ packageName?: string;
127
+ sourceDir?: string;
128
+ outputDir?: string;
129
+ manifest?: string;
130
+ sourcePaths?: string[];
131
+ metadataPaths?: string[];
132
+ deploydir?: string;
133
+ };
134
+ export declare type PackageVersionOptions = {
135
+ connection: Connection;
136
+ project: SfProject;
137
+ };
138
+ export declare type PackageVersionCreateOptions = Partial<PackageVersionOptions & {
139
+ branch: string;
140
+ buildinstance: string;
141
+ codecoverage: boolean;
142
+ definitionfile: string;
143
+ installationkey: string;
144
+ installationkeybypass: boolean;
145
+ package: string;
146
+ path: string;
147
+ postinstallscript: string;
148
+ postinstallurl: string;
149
+ preserve: boolean;
150
+ releasenotesurl: string;
151
+ skipancestorcheck: boolean;
152
+ skipvalidation: boolean;
153
+ sourceorg: string;
154
+ tag: string;
155
+ uninstallscript: string;
156
+ validateschema: boolean;
157
+ versiondescription: string;
158
+ versionname: string;
159
+ versionnumber: string;
160
+ wait: Duration;
161
+ profileApi: PackageProfileApi;
162
+ }>;
163
+ export declare type PackageVersionCreateRequestQueryOptions = {
164
+ createdlastdays?: number;
165
+ connection?: Connection;
166
+ status?: string;
167
+ };
168
+ export declare type ProfileApiOptions = {
169
+ project: SfProject;
170
+ includeUserLicenses: boolean;
171
+ generateProfileInformation: boolean;
172
+ };
@@ -1,3 +1,4 @@
1
+ import { PackageType } from './packagingInterfacesAndType';
1
2
  export declare namespace PackagingSObjects {
2
3
  type Package2 = {
3
4
  Id: string;
@@ -11,7 +12,7 @@ export declare namespace PackagingSObjects {
11
12
  Name: string;
12
13
  Description: string;
13
14
  NamespacePrefix: string;
14
- ContainerOptions: string;
15
+ ContainerOptions: PackageType;
15
16
  IsDeprecated: boolean;
16
17
  IsOrgDependent: boolean;
17
18
  ConvertedFromPackageId: string;
@@ -1,12 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PackagingSObjects = 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
4
  var PackagingSObjects;
11
5
  (function (PackagingSObjects) {
12
6
  let Package2VersionStatus;
@@ -1,4 +1,7 @@
1
1
  export * from './package';
2
- export * from './packageVersion2GP';
2
+ export * from './packageVersion';
3
3
  export * from './packageList';
4
+ export * from './packageVersionCreateRequest';
4
5
  export { listPackageVersions } from './packageVersionList';
6
+ export { createPackage } from './packageCreate';
7
+ export { deletePackage } from './packageDelete';
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.listPackageVersions = void 0;
17
+ exports.deletePackage = exports.createPackage = exports.listPackageVersions = void 0;
18
18
  /*
19
19
  * Copyright (c) 2022, salesforce.com, inc.
20
20
  * All rights reserved.
@@ -22,8 +22,13 @@ exports.listPackageVersions = void 0;
22
22
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
23
23
  */
24
24
  __exportStar(require("./package"), exports);
25
- __exportStar(require("./packageVersion2GP"), exports);
25
+ __exportStar(require("./packageVersion"), exports);
26
26
  __exportStar(require("./packageList"), exports);
27
+ __exportStar(require("./packageVersionCreateRequest"), exports);
27
28
  var packageVersionList_1 = require("./packageVersionList");
28
29
  Object.defineProperty(exports, "listPackageVersions", { enumerable: true, get: function () { return packageVersionList_1.listPackageVersions; } });
30
+ var packageCreate_1 = require("./packageCreate");
31
+ Object.defineProperty(exports, "createPackage", { enumerable: true, get: function () { return packageCreate_1.createPackage; } });
32
+ var packageDelete_1 = require("./packageDelete");
33
+ Object.defineProperty(exports, "deletePackage", { enumerable: true, get: function () { return packageDelete_1.deletePackage; } });
29
34
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,11 @@
1
+ import { Connection, Org, SfProject } from '@salesforce/core';
2
+ import { Duration } from '@salesforce/kit';
3
+ import { PackageVersionCreateRequestResult } from '../interfaces';
4
+ declare type ConvertPackageOptions = {
5
+ installationKey: string;
6
+ installationKeyBypass: boolean;
7
+ wait: Duration;
8
+ buildInstance: string;
9
+ };
10
+ export declare function convertPackage(pkg: string, org: Org, connection: Connection, project: SfProject, options: ConvertPackageOptions): Promise<PackageVersionCreateRequestResult>;
11
+ export {};
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2022, 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.convertPackage = void 0;
10
+ const path = require("path");
11
+ const util = require("util");
12
+ const os = require("os");
13
+ const fs = require("fs");
14
+ const core_1 = require("@salesforce/core");
15
+ const kit_1 = require("@salesforce/kit");
16
+ const testSetup_1 = require("@salesforce/core/lib/testSetup");
17
+ const pkgUtils = require("../utils/packageUtils");
18
+ const constants_1 = require("../constants");
19
+ const srcDevUtil = require("../utils/srcDevUtils");
20
+ const packageVersionCreateRequest_1 = require("./packageVersionCreateRequest");
21
+ core_1.Messages.importMessagesDirectory(__dirname);
22
+ const messages = core_1.Messages.loadMessages('@salesforce/packaging', 'messages');
23
+ async function convertPackage(pkg, org, connection, project, options) {
24
+ let maxRetries = 0;
25
+ const branch = 'main';
26
+ if (options.wait) {
27
+ maxRetries = (60 / pkgUtils.POLL_INTERVAL_SECONDS) * options.wait.seconds;
28
+ }
29
+ const packageId = await pkgUtils.findOrCreatePackage(pkg, connection);
30
+ const request = await createPackageVersionCreateRequest(context, packageId);
31
+ const createResult = await connection.tooling.create('Package2VersionCreateRequest', request);
32
+ if (!createResult.success) {
33
+ const errStr = createResult.errors && createResult.errors.length ? createResult.errors.join(', ') : createResult.errors;
34
+ throw messages.createError('failedToCreatePVCRequest', [
35
+ createResult.id ? ` [${createResult.id}]` : '',
36
+ errStr.toString(),
37
+ ]);
38
+ }
39
+ let results;
40
+ if (options.wait) {
41
+ results = await pkgUtils.pollForStatusWithInterval(createResult.id, maxRetries, packageId, branch, project, connection, new kit_1.Duration(pkgUtils.POLL_INTERVAL_SECONDS, kit_1.Duration.Unit.SECONDS));
42
+ }
43
+ else {
44
+ results = await (0, packageVersionCreateRequest_1.byId)(packageId, connection);
45
+ }
46
+ return util.isArray(results) ? results[0] : results;
47
+ }
48
+ exports.convertPackage = convertPackage;
49
+ /**
50
+ * Convert the list of command line options to a JSON object that can be used to create an Package2VersionCreateRequest entity.
51
+ *
52
+ * @param context: command context
53
+ * @param packageId: package2 id to create a package version for
54
+ * @returns {{Package2Id: string, Package2VersionMetadata: *, Tag: *, Branch: number}}
55
+ * @private
56
+ */
57
+ async function createPackageVersionCreateRequest(context, packageId) {
58
+ const uniqueId = (0, testSetup_1.uniqid)({ template: `${packageId}-%s` });
59
+ const packageVersTmpRoot = path.join(os.tmpdir(), uniqueId);
60
+ const packageVersBlobDirectory = path.join(packageVersTmpRoot, 'package-version-info');
61
+ const packageVersBlobZipFile = path.join(packageVersTmpRoot, constants_1.consts.PACKAGE_VERSION_INFO_FILE_ZIP);
62
+ const packageDescriptorJson = {
63
+ id: packageId,
64
+ };
65
+ await fs.promises.mkdir(packageVersTmpRoot, { recursive: true });
66
+ await fs.promises.mkdir(packageVersBlobDirectory, { recursive: true });
67
+ await fs.promises.writeFile(path.join(packageVersBlobDirectory, constants_1.consts.PACKAGE2_DESCRIPTOR_FILE), JSON.stringify(packageDescriptorJson, undefined, 2));
68
+ // Zip the Version Info and package.zip files into another zip
69
+ await srcDevUtil.zipDir(packageVersBlobDirectory, packageVersBlobZipFile);
70
+ return createRequestObject(packageId, context, packageVersTmpRoot, packageVersBlobZipFile);
71
+ }
72
+ async function createRequestObject(packageId, options, packageVersTmpRoot, packageVersBlobZipFile) {
73
+ const zipFileBase64 = (await fs.promises.readFile(packageVersBlobZipFile)).toString('base64');
74
+ const requestObject = {
75
+ Package2Id: packageId,
76
+ VersionInfo: zipFileBase64,
77
+ InstallKey: options.installationkey,
78
+ Instance: options.buildinstance,
79
+ IsConversionRequest: true,
80
+ };
81
+ await fs.promises.unlink(packageVersTmpRoot);
82
+ return requestObject;
83
+ }
84
+ //# sourceMappingURL=packageConvert.js.map
@@ -0,0 +1,26 @@
1
+ import { Connection, NamedPackageDir, PackageDir, SfProject } from '@salesforce/core';
2
+ import { PackageCreateOptions, PackagingSObjects } from '../interfaces';
3
+ declare type Package2Request = Pick<PackagingSObjects.Package2, 'Name' | 'Description' | 'NamespacePrefix' | 'ContainerOptions' | 'IsOrgDependent' | 'PackageErrorUsername'>;
4
+ export declare function _createPackageRequestFromContext(project: SfProject, options: PackageCreateOptions): Package2Request;
5
+ /**
6
+ * Generate packageDirectory json entry for this package that can be written to sfdx-project.json
7
+ *
8
+ * @param project
9
+ * @param packageId the 0Ho id of the package to create the entry for
10
+ * @private
11
+ */
12
+ export declare function _generatePackageDirEntry(project: SfProject, options: PackageCreateOptions): PackageDir[] | NamedPackageDir[];
13
+ /**
14
+ * Generate package alias json entry for this package that can be written to sfdx-project.json
15
+ *
16
+ * @param context
17
+ * @param packageId the 0Ho id of the package to create the alias entry for
18
+ * @private
19
+ */
20
+ export declare function _generatePackageAliasEntry(project: SfProject, options: PackageCreateOptions, packageId: string): {
21
+ [key: string]: string;
22
+ };
23
+ export declare function createPackage(connection: Connection, project: SfProject, options: PackageCreateOptions): Promise<{
24
+ Id: string;
25
+ }>;
26
+ export {};
@@ -0,0 +1,115 @@
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.createPackage = exports._generatePackageAliasEntry = exports._generatePackageDirEntry = exports._createPackageRequestFromContext = void 0;
10
+ const core_1 = require("@salesforce/core");
11
+ const ts_types_1 = require("@salesforce/ts-types");
12
+ const pkgUtils = require("../utils/packageUtils");
13
+ core_1.Messages.importMessagesDirectory(__dirname);
14
+ const messages = core_1.Messages.loadMessages('@salesforce/packaging', 'messages');
15
+ function _createPackageRequestFromContext(project, options) {
16
+ const namespace = options.noNamespace ? '' : project.getSfProjectJson().getContents().namespace || '';
17
+ return {
18
+ Name: options.name,
19
+ Description: options.description,
20
+ NamespacePrefix: namespace,
21
+ ContainerOptions: options.packageType,
22
+ IsOrgDependent: options.orgDependent,
23
+ PackageErrorUsername: options.errorNotificationUsername,
24
+ };
25
+ }
26
+ exports._createPackageRequestFromContext = _createPackageRequestFromContext;
27
+ /**
28
+ * Generate packageDirectory json entry for this package that can be written to sfdx-project.json
29
+ *
30
+ * @param project
31
+ * @param packageId the 0Ho id of the package to create the entry for
32
+ * @private
33
+ */
34
+ function _generatePackageDirEntry(project, options) {
35
+ var _a, _b;
36
+ let packageDirs = project.getPackageDirectories();
37
+ if (!packageDirs) {
38
+ packageDirs = [];
39
+ }
40
+ // add an entry if it doesn't exist
41
+ // or update an existing entry if it matches path but has no package or id attribute (W-5092620)
42
+ let packageDir = project.getPackage(options.name) ||
43
+ project
44
+ .getPackageDirectories()
45
+ // TODO: I don't understand where id is coming from, because it is not in sfdx-project.json schema
46
+ .find((pd) => pd.path === options.path && !pd.id && !pd.package);
47
+ if (packageDir) {
48
+ // update existing entry
49
+ packageDir.package = options.name;
50
+ (_a = packageDir.versionName) !== null && _a !== void 0 ? _a : (packageDir.versionName = pkgUtils.DEFAULT_PACKAGE_DIR.versionName);
51
+ (_b = packageDir.versionNumber) !== null && _b !== void 0 ? _b : (packageDir.versionNumber = pkgUtils.DEFAULT_PACKAGE_DIR.versionNumber);
52
+ // set as default if this is the only entry or no other entry is the default
53
+ if (!Reflect.getOwnPropertyDescriptor(packageDir, 'default')) {
54
+ packageDir.default = !pkgUtils.getConfigPackageDirectory(packageDirs, 'default', true);
55
+ }
56
+ }
57
+ else {
58
+ // add new entry
59
+ packageDir = pkgUtils.DEFAULT_PACKAGE_DIR;
60
+ packageDir.package = options.name;
61
+ // set as default if this is the only entry or no other entry is the default
62
+ packageDir.default = !pkgUtils.getConfigPackageDirectory(packageDirs, 'default', true);
63
+ packageDir.path = options.path;
64
+ packageDirs.push(packageDir);
65
+ }
66
+ return packageDirs;
67
+ }
68
+ exports._generatePackageDirEntry = _generatePackageDirEntry;
69
+ /**
70
+ * Generate package alias json entry for this package that can be written to sfdx-project.json
71
+ *
72
+ * @param context
73
+ * @param packageId the 0Ho id of the package to create the alias entry for
74
+ * @private
75
+ */
76
+ function _generatePackageAliasEntry(project, options, packageId) {
77
+ const packageAliases = project.getSfProjectJson().getContents().packageAliases || {};
78
+ const packageName = options.name;
79
+ packageAliases[packageName] = packageId;
80
+ return packageAliases;
81
+ }
82
+ exports._generatePackageAliasEntry = _generatePackageAliasEntry;
83
+ async function createPackage(connection, project, options) {
84
+ // strip trailing slash from path param
85
+ options.path = options.path.replace(/\/$/, '');
86
+ const request = _createPackageRequestFromContext(project, options);
87
+ let packageId = null;
88
+ const createResult = await connection.tooling
89
+ .sobject('Package2')
90
+ .create(request)
91
+ .catch((err) => {
92
+ const error = (0, ts_types_1.isString)(err) ? err : err.message;
93
+ throw core_1.SfError.wrap(error);
94
+ });
95
+ if (!createResult.success) {
96
+ throw pkgUtils.combineSaveErrors('Package2', 'create', createResult.errors);
97
+ }
98
+ packageId = createResult.id;
99
+ const queryResult = await connection.tooling.query(`SELECT Id FROM Package2 WHERE Id='${packageId}'`);
100
+ if (!(queryResult === null || queryResult === void 0 ? void 0 : queryResult.records[0])) {
101
+ throw messages.createError('unableToFindPackageWithId', [packageId]);
102
+ }
103
+ const record = queryResult.records[0];
104
+ if (!process.env.SFDX_PROJECT_AUTOUPDATE_DISABLE_FOR_PACKAGE_CREATE) {
105
+ const packageDirectory = _generatePackageDirEntry(project, options);
106
+ const packageAliases = _generatePackageAliasEntry(project, options, record.Id);
107
+ const projectJson = project.getSfProjectJson();
108
+ projectJson.set('packageDirectories', packageDirectory);
109
+ projectJson.set('packageAliases', packageAliases);
110
+ await projectJson.write();
111
+ }
112
+ return { Id: record.Id };
113
+ }
114
+ exports.createPackage = createPackage;
115
+ //# sourceMappingURL=packageCreate.js.map
@@ -0,0 +1,3 @@
1
+ import { Connection, SfProject } from '@salesforce/core';
2
+ import { PackageSaveResult } from '../interfaces';
3
+ export declare function deletePackage(idOrAlias: string, project: SfProject, connection: Connection, undelete: boolean): Promise<PackageSaveResult>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2022, 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.deletePackage = void 0;
10
+ const pkgUtils = require("../utils/packageUtils");
11
+ const utils_1 = require("../utils");
12
+ async function deletePackage(idOrAlias, project, connection, undelete) {
13
+ const packageId = pkgUtils.getPackageIdFromAlias(idOrAlias, project);
14
+ pkgUtils.validateId(pkgUtils.BY_LABEL.PACKAGE_ID, packageId);
15
+ const request = {};
16
+ request.Id = packageId;
17
+ const isUndelete = undelete;
18
+ request.IsDeprecated = !isUndelete;
19
+ const updateResult = await connection.tooling.update('Package2', request);
20
+ if (!updateResult.success) {
21
+ throw (0, utils_1.combineSaveErrors)('Package2', 'update', updateResult.errors);
22
+ }
23
+ return updateResult;
24
+ }
25
+ exports.deletePackage = deletePackage;
26
+ //# sourceMappingURL=packageDelete.js.map
@@ -0,0 +1,59 @@
1
+ import { ConfigAggregator, SfProject } from '@salesforce/core';
2
+ import { AsyncCreatable } from '@salesforce/kit';
3
+ import { ProfileApiOptions } from '../interfaces';
4
+ export declare class PackageProfileApi extends AsyncCreatable<ProfileApiOptions> {
5
+ private options;
6
+ readonly profiles: ProfileInformation[];
7
+ apiVersion: string;
8
+ nodeEntities: {
9
+ name: string[];
10
+ childElement: string[];
11
+ parentElement: string[];
12
+ };
13
+ otherProfileSettings: {
14
+ name: string[];
15
+ childElement: string[];
16
+ parentElement: string[];
17
+ };
18
+ config: ConfigAggregator;
19
+ project: SfProject;
20
+ includeUserLicenses: boolean;
21
+ generateProfileInformation: boolean;
22
+ constructor(options: ProfileApiOptions);
23
+ init(): Promise<void>;
24
+ /**
25
+ * For any profile present in the workspace, this function generates a subset of data that only contains references
26
+ * to items in the manifest.
27
+ *
28
+ * @param destPath location of new profiles
29
+ * @param manifest
30
+ * @param excludedDirectories Directories to not include profiles from
31
+ */
32
+ generateProfiles(destPath: string, manifest: {
33
+ Package: {
34
+ types: string[];
35
+ };
36
+ }, excludedDirectories?: string[]): any[];
37
+ /**
38
+ * Filter out all profiles in the manifest and if any profiles exists in the workspace, add them to the manifest.
39
+ *
40
+ * @param typesArr array of objects { name[], members[] } that represent package types JSON.
41
+ * @param excludedDirectories Direcotires not to generate profiles for
42
+ */
43
+ filterAndGenerateProfilesForManifest(typesArr: any, excludedDirectories?: string[]): any;
44
+ getProfileInformation(): ProfileInformation[];
45
+ private copyNodes;
46
+ private findAllProfiles;
47
+ }
48
+ declare class ProfileInformation {
49
+ ProfileName: string;
50
+ ProfilePath: string;
51
+ IsPackaged: boolean;
52
+ settingsRemoved: string[];
53
+ constructor(ProfileName: string, ProfilePath: string, IsPackaged: boolean, settingsRemoved: string[]);
54
+ setIsPackaged(IsPackaged: boolean): void;
55
+ appendRemovedSetting(setting: string): void;
56
+ logDebug(): string;
57
+ logInfo(): string;
58
+ }
59
+ export {};