@salesforce/packaging 0.1.11 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/lib/constants.d.ts +3 -0
  2. package/lib/constants.js +4 -1
  3. package/lib/interfaces/packagingInterfacesAndType.d.ts +20 -13
  4. package/lib/interfaces/packagingSObjects.d.ts +1 -1
  5. package/lib/package/index.d.ts +1 -5
  6. package/lib/package/index.js +1 -10
  7. package/lib/package/package.d.ts +79 -32
  8. package/lib/package/package.js +159 -71
  9. package/lib/package/packageAncestry.d.ts +3 -1
  10. package/lib/package/packageAncestry.js +43 -25
  11. package/lib/package/packageConvert.js +2 -3
  12. package/lib/package/packageCreate.d.ts +2 -12
  13. package/lib/package/packageCreate.js +30 -53
  14. package/lib/package/packageDelete.js +4 -1
  15. package/lib/package/packageInstall.d.ts +7 -14
  16. package/lib/package/packageInstall.js +65 -148
  17. package/lib/package/packageInstalledList.js +8 -2
  18. package/lib/package/packageUninstall.d.ts +5 -1
  19. package/lib/package/packageUninstall.js +51 -41
  20. package/lib/package/packageVersion.d.ts +53 -6
  21. package/lib/package/packageVersion.js +139 -29
  22. package/lib/package/packageVersionCreate.d.ts +2 -2
  23. package/lib/package/packageVersionCreate.js +27 -25
  24. package/lib/package/packageVersionCreateRequest.js +15 -6
  25. package/lib/package/packageVersionCreateRequestReport.js +9 -3
  26. package/lib/package/packageVersionList.js +3 -1
  27. package/lib/package/packageVersionReport.js +1 -27
  28. package/lib/package/subscriberPackageVersion.d.ts +156 -0
  29. package/lib/package/subscriberPackageVersion.js +346 -0
  30. package/lib/utils/packageUtils.d.ts +10 -11
  31. package/lib/utils/packageUtils.js +35 -24
  32. package/messages/package.md +18 -2
  33. package/messages/package_version.md +12 -0
  34. package/messages/pkg_utils.md +5 -33
  35. package/messages/subscriber_package_version.md +19 -0
  36. package/package.json +3 -3
  37. package/lib/package/packageList.d.ts +0 -4
  38. package/lib/package/packageList.js +0 -19
@@ -1,3 +1,4 @@
1
+ import { Duration } from '@salesforce/kit';
1
2
  export declare const consts: {
2
3
  DEFAULT_USER_DIR_MODE: string;
3
4
  DEFAULT_USER_FILE_MODE: string;
@@ -20,4 +21,6 @@ export declare const consts: {
20
21
  PACKAGE2_DESCRIPTOR_FILE: string;
21
22
  PACKAGE_INSTALL_POLL_FREQUENCY: number;
22
23
  PACKAGE_INSTALL_POLL_TIMEOUT: number;
24
+ PACKAGE_PUBLISH_POLL_FREQUENCY: Duration;
25
+ PACKAGE_PUBLISH_POLL_TIMEOUT: Duration;
23
26
  };
package/lib/constants.js CHANGED
@@ -15,6 +15,7 @@ exports.consts = void 0;
15
15
  * If you need or want help deciding where to add new functionality or how to migrate to the new library, please
16
16
  * contact the CLI team at alm-cli@salesforce.com.
17
17
  * ----------------------------------------------------------------------------------------------------------------- */
18
+ const kit_1 = require("@salesforce/kit");
18
19
  exports.consts = {
19
20
  DEFAULT_USER_DIR_MODE: '700',
20
21
  DEFAULT_USER_FILE_MODE: '600',
@@ -37,6 +38,8 @@ exports.consts = {
37
38
  INSTANCE_URL_TOKEN: '__SFDX_INSTANCE_URL__',
38
39
  PACKAGE2_DESCRIPTOR_FILE: 'package2-descriptor.json',
39
40
  PACKAGE_INSTALL_POLL_FREQUENCY: 5000,
40
- PACKAGE_INSTALL_POLL_TIMEOUT: 5, // 5 minutes
41
+ PACKAGE_INSTALL_POLL_TIMEOUT: 5,
42
+ PACKAGE_PUBLISH_POLL_FREQUENCY: kit_1.Duration.milliseconds(0),
43
+ PACKAGE_PUBLISH_POLL_TIMEOUT: kit_1.Duration.milliseconds(0), // 0ms
41
44
  };
42
45
  //# sourceMappingURL=constants.js.map
@@ -1,25 +1,14 @@
1
1
  import { Duration } from '@salesforce/kit';
2
2
  import { Connection, NamedPackageDir, SfProject } from '@salesforce/core';
3
- import { QueryResult, SaveResult } from 'jsforce';
3
+ import { SaveResult } from 'jsforce';
4
4
  import { Attributes } from 'graphology-types';
5
+ import { Optional } from '@salesforce/ts-types';
5
6
  import { PackageProfileApi } from '../package/packageProfileApi';
6
7
  import { PackageAncestryNode } from '../package';
7
8
  import { PackagingSObjects } from './packagingSObjects';
8
9
  import Package2VersionStatus = PackagingSObjects.Package2VersionStatus;
9
10
  import PackageInstallRequest = PackagingSObjects.PackageInstallRequest;
10
11
  import MetadataPackageVersion = PackagingSObjects.MetadataPackageVersion;
11
- export interface IPackage {
12
- create(): Promise<void>;
13
- convert(pkgId: string, options: ConvertPackageOptions, project?: SfProject): Promise<PackageVersionCreateRequestResult>;
14
- delete(): Promise<void>;
15
- install(pkgInstallCreateRequest: PackageInstallCreateRequest, options?: PackageInstallOptions): Promise<PackageInstallRequest>;
16
- getInstallStatus(installRequestId: string): Promise<PackageInstallRequest>;
17
- list(): Promise<QueryResult<PackagingSObjects.Package2>>;
18
- uninstall(id: string, wait: Duration): Promise<PackagingSObjects.SubscriberPackageVersionUninstallRequest>;
19
- update(options: PackageUpdateOptions): Promise<PackageSaveResult>;
20
- waitForPublish(subscriberPackageVersionKey: string, timeout: number | Duration, installationKey?: string): any;
21
- getExternalSites(subscriberPackageVersionKey: string, installationKey?: string): any;
22
- }
23
12
  export interface IPackageVersion1GP {
24
13
  getPackageVersion(id: string): Promise<MetadataPackageVersion[]>;
25
14
  }
@@ -34,6 +23,8 @@ export interface IPackageVersion2GP {
34
23
  }
35
24
  export declare type PackageOptions = {
36
25
  connection: Connection;
26
+ project: SfProject;
27
+ packageAliasOrId: string;
37
28
  };
38
29
  export declare type PackageUpdateOptions = {
39
30
  Id: string;
@@ -178,6 +169,16 @@ export declare type PackageVersionCreateRequestOptions = {
178
169
  skipancestorcheck?: boolean;
179
170
  };
180
171
  export declare type PackageInstallOptions = {
172
+ /**
173
+ * The frequency to poll the org for package publish status. If providing a number
174
+ * it is interpreted in milliseconds.
175
+ */
176
+ publishFrequency?: number | Duration;
177
+ /**
178
+ * The amount of time to wait for package publish to complete. If providing a number
179
+ * it is interpreted in minutes.
180
+ */
181
+ publishTimeout?: number | Duration;
181
182
  /**
182
183
  * The frequency to poll the org for package installation status. If providing a number
183
184
  * it is interpreted in milliseconds.
@@ -209,6 +210,11 @@ export declare type PackageVersionOptions = {
209
210
  idOrAlias: string;
210
211
  project: SfProject;
211
212
  };
213
+ export declare type SubscriberPackageVersionOptions = {
214
+ connection: Connection;
215
+ aliasOrId: string;
216
+ password: Optional<string>;
217
+ };
212
218
  export declare type ConvertPackageOptions = {
213
219
  installationKey: string;
214
220
  definitionfile: string;
@@ -247,6 +253,7 @@ export declare type PackageVersionCreateRequestQueryOptions = {
247
253
  createdlastdays?: number;
248
254
  connection?: Connection;
249
255
  status?: 'Queued' | 'InProgress' | 'Success' | 'Error';
256
+ id?: string;
250
257
  };
251
258
  export declare type ProfileApiOptions = {
252
259
  project: SfProject;
@@ -151,7 +151,7 @@ export declare namespace PackagingSObjects {
151
151
  IsDeprecated: boolean;
152
152
  IsPasswordProtected: boolean;
153
153
  IsBeta: boolean;
154
- Package2ContainerOptions: string;
154
+ Package2ContainerOptions: PackageType;
155
155
  IsSecurityReviewed: boolean;
156
156
  IsOrgDependent: boolean;
157
157
  AppExchangePackageName: string;
@@ -1,12 +1,8 @@
1
1
  export * from './package';
2
2
  export * from './packageInstall';
3
3
  export * from './packageVersion';
4
- export * from './packageList';
5
4
  export * from './packageVersionCreateRequest';
6
- export { listPackageVersions } from './packageVersionList';
7
- export { createPackage } from './packageCreate';
8
- export { deletePackage } from './packageDelete';
9
- export { uninstallPackage } from './packageUninstall';
10
5
  export * from './packageInstalledList';
11
6
  export * from './packageVersionCreateRequestReport';
12
7
  export * from './packageAncestry';
8
+ export * from './subscriberPackageVersion';
@@ -14,7 +14,6 @@ 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.uninstallPackage = exports.deletePackage = exports.createPackage = exports.listPackageVersions = void 0;
18
17
  /*
19
18
  * Copyright (c) 2022, salesforce.com, inc.
20
19
  * All rights reserved.
@@ -24,17 +23,9 @@ exports.uninstallPackage = exports.deletePackage = exports.createPackage = expor
24
23
  __exportStar(require("./package"), exports);
25
24
  __exportStar(require("./packageInstall"), exports);
26
25
  __exportStar(require("./packageVersion"), exports);
27
- __exportStar(require("./packageList"), exports);
28
26
  __exportStar(require("./packageVersionCreateRequest"), exports);
29
- var packageVersionList_1 = require("./packageVersionList");
30
- Object.defineProperty(exports, "listPackageVersions", { enumerable: true, get: function () { return packageVersionList_1.listPackageVersions; } });
31
- var packageCreate_1 = require("./packageCreate");
32
- Object.defineProperty(exports, "createPackage", { enumerable: true, get: function () { return packageCreate_1.createPackage; } });
33
- var packageDelete_1 = require("./packageDelete");
34
- Object.defineProperty(exports, "deletePackage", { enumerable: true, get: function () { return packageDelete_1.deletePackage; } });
35
- var packageUninstall_1 = require("./packageUninstall");
36
- Object.defineProperty(exports, "uninstallPackage", { enumerable: true, get: function () { return packageUninstall_1.uninstallPackage; } });
37
27
  __exportStar(require("./packageInstalledList"), exports);
38
28
  __exportStar(require("./packageVersionCreateRequestReport"), exports);
39
29
  __exportStar(require("./packageAncestry"), exports);
30
+ __exportStar(require("./subscriberPackageVersion"), exports);
40
31
  //# sourceMappingURL=index.js.map
@@ -1,48 +1,95 @@
1
- import { SfProject } from '@salesforce/core';
2
- import { AsyncCreatable, Duration } from '@salesforce/kit';
3
- import { QueryResult } from 'jsforce';
4
- import { Optional } from '@salesforce/ts-types';
5
- import { IPackage, PackageOptions, PackagingSObjects, PackageInstallOptions, PackageInstallCreateRequest, PackageIdType, ConvertPackageOptions, PackageVersionCreateRequestResult, PackageSaveResult, PackageUpdateOptions } from '../interfaces';
6
- declare type PackageInstallRequest = PackagingSObjects.PackageInstallRequest;
1
+ import { Connection, SfProject } from '@salesforce/core';
2
+ import { ConvertPackageOptions, PackageCreateOptions, PackageOptions, PackageSaveResult, PackageType, PackageUpdateOptions, PackageVersionCreateRequestResult, PackageVersionListOptions, PackageVersionListResult, PackagingSObjects } from '../interfaces';
3
+ export declare const Package2Fields: string[];
7
4
  /**
8
5
  * Package class.
9
6
  *
10
7
  * This class provides the base implementation for a package.
8
+ * To create a new instance of a package, use the static async Package.create({connection, project, packageOrAliasId}) method.
11
9
  */
12
- export declare class Package extends AsyncCreatable<PackageOptions> implements IPackage {
10
+ export declare class Package {
13
11
  private options;
12
+ private readonly packageId;
13
+ private packageData;
14
14
  constructor(options: PackageOptions);
15
15
  /**
16
- * Given a Salesforce ID for a package resource and the type of resource,
17
- * ensures the ID is valid.
16
+ * Create a new package.
18
17
  *
19
- * Valid ID types and prefixes for packaging resources:
20
- * 1. package ID (0Ho)
21
- * 2. subscriber package version ID (04t)
22
- * 3. package install request ID (0Hf)
23
- * 4. package uninstall request ID (06y)
18
+ * @param connection - instance of Connection
19
+ * @param project - instance of SfProject
20
+ * @param options - options for creating a package - see PackageCreateOptions
21
+ * @returns Package
22
+ */
23
+ static create(connection: Connection, project: SfProject, options: PackageCreateOptions): Promise<{
24
+ Id: string;
25
+ }>;
26
+ /**
27
+ * Returns all the packages that are available in the org.
28
+ *
29
+ * @param connection
30
+ */
31
+ static list(connection: Connection): Promise<PackagingSObjects.Package2[]>;
32
+ /**
33
+ * Returns the package versions in the org.
34
+ * See {@link PackageVersionListOptions} for list options
35
+ *
36
+ * @param connection - connection to the org
37
+ * @param project - instance of SfProject
38
+ * @param options - see {@link PackageVersionListOptions}
39
+ */
40
+ static listVersions(connection: Connection, project: SfProject, options?: PackageVersionListOptions): Promise<PackageVersionListResult[]>;
41
+ /**
42
+ * Convert a 1st generation package to a 2nd generation package.
43
+ * See {@link ConvertPackageOptions} for conversion options.
44
+ *
45
+ * @param pkgId the 1GP package ID (033) of the package to convert
46
+ * @param connection
47
+ * @param options {@link ConvertPackageOptions}
48
+ * @param project
49
+ */
50
+ static convert(pkgId: string, connection: Connection, options: ConvertPackageOptions, project?: SfProject): Promise<PackageVersionCreateRequestResult>;
51
+ /**
52
+ * Returns the package ID of the package.
53
+ *
54
+ * @returns {string} package ID (0Ho)
55
+ */
56
+ getId(): string;
57
+ /**
58
+ * Returns the package type of the package.
59
+ *
60
+ * @returns {Promise<PackageType>}
61
+ */
62
+ getType(): Promise<PackageType>;
63
+ /**
64
+ * Returns the list of package versions for the package.
65
+ * See {@link PackageVersionListOptions} for list options
66
+ *
67
+ * @param options
68
+ * @returns {Promise<PackageVersionListResult[]>}
69
+ */
70
+ getPackageVersions(options?: PackageVersionListOptions): Promise<PackageVersionListResult[]>;
71
+ /**
72
+ * Deletes the package.
24
73
  *
25
- * @param id Salesforce ID for a specific package resource
26
- * @param type The type of package ID
27
74
  */
28
- static validateId(id: string, type: PackageIdType): void;
29
- convert(pkgId: string, options: ConvertPackageOptions, project?: SfProject): Promise<PackageVersionCreateRequestResult>;
30
- create(): Promise<void>;
31
- delete(): Promise<void>;
32
- install(pkgInstallCreateRequest: PackageInstallCreateRequest, options?: PackageInstallOptions): Promise<PackageInstallRequest>;
33
- getInstallStatus(installRequestId: string): Promise<PackageInstallRequest>;
34
- list(): Promise<QueryResult<PackagingSObjects.Package2>>;
35
- uninstall(id: string, wait: Duration): Promise<PackagingSObjects.SubscriberPackageVersionUninstallRequest>;
75
+ delete(): Promise<PackageSaveResult>;
36
76
  /**
37
- * Reports on the uninstall progress of a package.
77
+ * Un-Deletes the package.
38
78
  *
39
- * @param id the 06y package uninstall request id
40
79
  */
41
- uninstallReport(id: string): Promise<PackagingSObjects.SubscriberPackageVersionUninstallRequest>;
80
+ undelete(): Promise<PackageSaveResult>;
81
+ /**
82
+ * Updates the package using the values defined in the options.
83
+ * See {@link PackageUpdateOptions} for update options.
84
+ *
85
+ * @param options
86
+ */
42
87
  update(options: PackageUpdateOptions): Promise<PackageSaveResult>;
43
- getPackage(packageId: string): Promise<PackagingSObjects.Package2>;
44
- getExternalSites(subscriberPackageVersionId: string, installationKey?: string): Promise<Optional<string[]>>;
45
- waitForPublish(subscriberPackageVersionId: string, timeout: number | Duration, installationKey?: string): Promise<void>;
46
- protected init(): Promise<void>;
88
+ /**
89
+ * Returns the package data for the package.
90
+ *
91
+ * @param force force a refresh of the package data
92
+ */
93
+ getPackageData(force?: boolean): Promise<PackagingSObjects.Package2>;
94
+ private verifyAliasForId;
47
95
  }
48
- export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Package = void 0;
3
+ exports.Package = exports.Package2Fields = void 0;
4
4
  /*
5
5
  * Copyright (c) 2022, salesforce.com, inc.
6
6
  * All rights reserved.
@@ -8,11 +8,11 @@ exports.Package = void 0;
8
8
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
9
9
  */
10
10
  const core_1 = require("@salesforce/core");
11
- const kit_1 = require("@salesforce/kit");
12
- const packageList_1 = require("./packageList");
13
- const packageInstall_1 = require("./packageInstall");
11
+ const utils_1 = require("../utils");
12
+ const packageCreate_1 = require("./packageCreate");
14
13
  const packageConvert_1 = require("./packageConvert");
15
- const packageUninstall_1 = require("./packageUninstall");
14
+ const packageVersionList_1 = require("./packageVersionList");
15
+ const packageDelete_1 = require("./packageDelete");
16
16
  const packagePrefixes = {
17
17
  PackageId: '0Ho',
18
18
  SubscriberPackageVersionId: '04t',
@@ -21,99 +21,187 @@ const packagePrefixes = {
21
21
  };
22
22
  core_1.Messages.importMessagesDirectory(__dirname);
23
23
  const messages = core_1.Messages.loadMessages('@salesforce/packaging', 'package');
24
+ exports.Package2Fields = [
25
+ 'Id',
26
+ 'IsDeleted',
27
+ 'CreatedDate',
28
+ 'CreatedById',
29
+ 'LastModifiedDate',
30
+ 'LastModifiedById',
31
+ 'SystemModstamp',
32
+ 'SubscriberPackageId',
33
+ 'Name',
34
+ 'Description',
35
+ 'NamespacePrefix',
36
+ 'ContainerOptions',
37
+ 'IsDeprecated',
38
+ 'IsOrgDependent',
39
+ 'ConvertedFromPackageId',
40
+ 'PackageErrorUsername',
41
+ ];
24
42
  /**
25
43
  * Package class.
26
44
  *
27
45
  * This class provides the base implementation for a package.
46
+ * To create a new instance of a package, use the static async Package.create({connection, project, packageOrAliasId}) method.
28
47
  */
29
- class Package extends kit_1.AsyncCreatable {
48
+ class Package {
30
49
  constructor(options) {
31
- super(options);
32
50
  this.options = options;
51
+ let packageId = this.options.packageAliasOrId;
52
+ if (!packageId.startsWith(packagePrefixes.PackageId)) {
53
+ packageId = (0, utils_1.getPackageIdFromAlias)(this.options.packageAliasOrId, this.options.project);
54
+ if (packageId === this.options.packageAliasOrId) {
55
+ throw messages.createError('packageAliasNotFound', [this.options.packageAliasOrId]);
56
+ }
57
+ }
58
+ if (packageId.startsWith(packagePrefixes.PackageId)) {
59
+ this.packageId = packageId;
60
+ this.verifyAliasForId();
61
+ }
62
+ else {
63
+ throw messages.createError('invalidPackageId', [this.options.packageAliasOrId, packagePrefixes.PackageId]);
64
+ }
33
65
  }
34
66
  /**
35
- * Given a Salesforce ID for a package resource and the type of resource,
36
- * ensures the ID is valid.
67
+ * Create a new package.
37
68
  *
38
- * Valid ID types and prefixes for packaging resources:
39
- * 1. package ID (0Ho)
40
- * 2. subscriber package version ID (04t)
41
- * 3. package install request ID (0Hf)
42
- * 4. package uninstall request ID (06y)
43
- *
44
- * @param id Salesforce ID for a specific package resource
45
- * @param type The type of package ID
69
+ * @param connection - instance of Connection
70
+ * @param project - instance of SfProject
71
+ * @param options - options for creating a package - see PackageCreateOptions
72
+ * @returns Package
46
73
  */
47
- static validateId(id, type) {
48
- const prefix = packagePrefixes[type];
49
- if (!id.startsWith(prefix)) {
50
- throw messages.createError('invalidPackageId', [type, id, prefix]);
51
- }
52
- if (!core_1.sfdc.validateSalesforceId(id)) {
53
- throw messages.createError('invalidIdLength', [type, id]);
54
- }
74
+ static async create(connection, project, options) {
75
+ return (0, packageCreate_1.createPackage)(connection, project, options);
55
76
  }
56
- async convert(pkgId, options, project) {
57
- return await (0, packageConvert_1.convertPackage)(pkgId, this.options.connection, options, project);
77
+ /**
78
+ * Returns all the packages that are available in the org.
79
+ *
80
+ * @param connection
81
+ */
82
+ static async list(connection) {
83
+ return (await connection.tooling.query(`select ${exports.Package2Fields.toString()} from Package2`))?.records;
58
84
  }
59
- create() {
60
- return Promise.resolve(undefined);
85
+ /**
86
+ * Returns the package versions in the org.
87
+ * See {@link PackageVersionListOptions} for list options
88
+ *
89
+ * @param connection - connection to the org
90
+ * @param project - instance of SfProject
91
+ * @param options - see {@link PackageVersionListOptions}
92
+ */
93
+ static async listVersions(connection, project, options) {
94
+ // resolve/verify packages
95
+ const packages = options?.packages?.map((pkg) => {
96
+ const id = (0, utils_1.getPackageIdFromAlias)(pkg, project);
97
+ // validate ID
98
+ if (id.startsWith('0Ho')) {
99
+ (0, utils_1.validateId)(utils_1.BY_LABEL.PACKAGE_ID, id);
100
+ return id;
101
+ }
102
+ else {
103
+ throw messages.createError('errorInvalidPackageVersionId', [id]);
104
+ }
105
+ });
106
+ const opts = options || {};
107
+ opts.packages = packages || [];
108
+ return (await (0, packageVersionList_1.listPackageVersions)({ ...opts, ...{ connection } })).records;
61
109
  }
62
- delete() {
63
- return Promise.resolve(undefined);
110
+ /**
111
+ * Convert a 1st generation package to a 2nd generation package.
112
+ * See {@link ConvertPackageOptions} for conversion options.
113
+ *
114
+ * @param pkgId the 1GP package ID (033) of the package to convert
115
+ * @param connection
116
+ * @param options {@link ConvertPackageOptions}
117
+ * @param project
118
+ */
119
+ static async convert(pkgId, connection, options, project) {
120
+ return (0, packageConvert_1.convertPackage)(pkgId, connection, options, project);
64
121
  }
65
- async install(pkgInstallCreateRequest, options) {
66
- return (0, packageInstall_1.installPackage)(this.options.connection, pkgInstallCreateRequest, options);
122
+ /**
123
+ * Returns the package ID of the package.
124
+ *
125
+ * @returns {string} package ID (0Ho)
126
+ */
127
+ getId() {
128
+ return this.packageId;
67
129
  }
68
- async getInstallStatus(installRequestId) {
69
- return (0, packageInstall_1.getStatus)(this.options.connection, installRequestId);
130
+ /**
131
+ * Returns the package type of the package.
132
+ *
133
+ * @returns {Promise<PackageType>}
134
+ */
135
+ async getType() {
136
+ return (await this.getPackageData()).ContainerOptions;
70
137
  }
71
- list() {
72
- return (0, packageList_1.listPackages)(this.options.connection);
138
+ /**
139
+ * Returns the list of package versions for the package.
140
+ * See {@link PackageVersionListOptions} for list options
141
+ *
142
+ * @param options
143
+ * @returns {Promise<PackageVersionListResult[]>}
144
+ */
145
+ async getPackageVersions(options) {
146
+ const packageOptions = {
147
+ packages: [this.packageId],
148
+ };
149
+ return Package.listVersions(this.options.connection, this.options.project, {
150
+ ...packageOptions,
151
+ ...options,
152
+ });
73
153
  }
74
- async uninstall(id, wait) {
75
- return await (0, packageUninstall_1.uninstallPackage)(id, this.options.connection, wait);
154
+ /**
155
+ * Deletes the package.
156
+ *
157
+ */
158
+ async delete() {
159
+ return (0, packageDelete_1.deletePackage)(this.getId(), this.options.project, this.options.connection, false);
76
160
  }
77
161
  /**
78
- * Reports on the uninstall progress of a package.
162
+ * Un-Deletes the package.
79
163
  *
80
- * @param id the 06y package uninstall request id
81
164
  */
82
- async uninstallReport(id) {
83
- const result = (await this.options.connection.tooling.retrieve('SubscriberPackageVersionUninstallRequest', id));
84
- if (result.Status === 'Error') {
85
- const errorDetails = await this.options.connection.tooling.query(`SELECT Message FROM PackageVersionUninstallRequestError WHERE ParentRequest.Id = '${id}' ORDER BY Message`);
86
- const errors = [];
87
- errorDetails.records.forEach((record) => {
88
- errors.push(`(${errors.length + 1}) ${record.Message}`);
89
- });
90
- const errHeader = errors.length > 0 ? `\n=== Errors\n${errors.join('\n')}` : '';
91
- const err = messages.getMessage('defaultErrorMessage', [id, result.Id]);
92
- throw new core_1.SfError(`${err}${errHeader}`, 'UNINSTALL_ERROR', [messages.getMessage('action')]);
93
- }
94
- return result;
165
+ async undelete() {
166
+ return (0, packageDelete_1.deletePackage)(this.getId(), this.options.project, this.options.connection, true);
95
167
  }
168
+ /**
169
+ * Updates the package using the values defined in the options.
170
+ * See {@link PackageUpdateOptions} for update options.
171
+ *
172
+ * @param options
173
+ */
96
174
  async update(options) {
97
- // filter out any undefined values and their keys
98
- Object.keys(options).forEach((key) => options[key] === undefined && delete options[key]);
99
- const result = await this.options.connection.tooling.update('Package2', options);
100
- if (!result.success) {
101
- throw new core_1.SfError(result.errors.join(', '));
175
+ try {
176
+ // filter out any undefined values and their keys
177
+ Object.keys(options).forEach((key) => options[key] === undefined && delete options[key]);
178
+ const result = await this.options.connection.tooling.update('Package2', options);
179
+ if (!result.success) {
180
+ throw new core_1.SfError(result.errors.join(', '));
181
+ }
182
+ return result;
183
+ }
184
+ catch (err) {
185
+ throw (0, utils_1.applyErrorAction)((0, utils_1.massageErrorMessage)(err));
102
186
  }
103
- return result;
104
- }
105
- async getPackage(packageId) {
106
- const package2 = await this.options.connection.tooling.sobject('Package2').retrieve(packageId);
107
- return package2;
108
- }
109
- async getExternalSites(subscriberPackageVersionId, installationKey) {
110
- return (0, packageInstall_1.getExternalSites)(this.options.connection, subscriberPackageVersionId, installationKey);
111
187
  }
112
- async waitForPublish(subscriberPackageVersionId, timeout, installationKey) {
113
- return (0, packageInstall_1.waitForPublish)(this.options.connection, subscriberPackageVersionId, timeout, installationKey);
188
+ /**
189
+ * Returns the package data for the package.
190
+ *
191
+ * @param force force a refresh of the package data
192
+ */
193
+ async getPackageData(force = false) {
194
+ if (!this.packageData || force) {
195
+ this.packageData = (await this.options.connection.tooling
196
+ .sobject('Package2')
197
+ .retrieve(this.packageId));
198
+ }
199
+ return this.packageData;
114
200
  }
115
- init() {
116
- return Promise.resolve(undefined);
201
+ verifyAliasForId() {
202
+ if ((0, utils_1.getPackageAliasesFromId)(this.packageId, this.options.project).length === 0) {
203
+ throw new core_1.SfError(messages.getMessage('couldNotFindAliasForId', [this.packageId]));
204
+ }
117
205
  }
118
206
  }
119
207
  exports.Package = Package;
@@ -6,10 +6,11 @@ import { AncestryRepresentationProducer, AncestryRepresentationProducerOptions,
6
6
  import { VersionNumber } from '../utils';
7
7
  /**
8
8
  * A class that represents the package ancestry graph.
9
+ * Given a package Id (0Ho) or a package version Id (04t), it will build a graph of the package's ancestors.
9
10
  */
10
11
  export declare class PackageAncestry extends AsyncCreatable<PackageAncestryOptions> {
12
+ #private;
11
13
  private options;
12
- private _requestedPackageId;
13
14
  private graph;
14
15
  private roots;
15
16
  constructor(options: PackageAncestryOptions);
@@ -48,6 +49,7 @@ export declare class PackageAncestry extends AsyncCreatable<PackageAncestryOptio
48
49
  private buildAncestryTree;
49
50
  private getRoots;
50
51
  private findRootsForPackageVersion;
52
+ private validatePackageType;
51
53
  private getPackageVersion;
52
54
  private findRootsForPackage;
53
55
  private buildAncestryTreeFromRoots;