@salesforce/packaging 0.0.13 → 0.0.14

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 CHANGED
@@ -2,6 +2,16 @@
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.14](https://github.com/forcedotcom/packaging/compare/v0.0.13...v0.0.14) (2022-08-05)
6
+
7
+ ### Bug Fixes
8
+
9
+ - adds package install ([97a821a](https://github.com/forcedotcom/packaging/commit/97a821af4e427b413e59c55143d5f17df0513dcc))
10
+ - adds some package install code ([f2fff8e](https://github.com/forcedotcom/packaging/commit/f2fff8e52a498c70230575b1ace3a6f303168ad4))
11
+ - enable install NUTs ([105250b](https://github.com/forcedotcom/packaging/commit/105250bbabe0185c04dab9cff2c9d17be4dd488f))
12
+ - export getStatus and add validateId function ([8a97c4a](https://github.com/forcedotcom/packaging/commit/8a97c4ac2a58ad7992f0d37f74fcf4662f754793))
13
+ - use install key ([457d777](https://github.com/forcedotcom/packaging/commit/457d7779f3e646f71b5faf1adc913094c524b74a))
14
+
5
15
  ### [0.0.13](https://github.com/forcedotcom/packaging/compare/v0.0.12...v0.0.13) (2022-08-05)
6
16
 
7
17
  ### Bug Fixes
@@ -18,4 +18,6 @@ export declare const consts: {
18
18
  PACKAGE_VERSION_INFO_FILE_ZIP: string;
19
19
  INSTANCE_URL_TOKEN: string;
20
20
  PACKAGE2_DESCRIPTOR_FILE: string;
21
+ PACKAGE_INSTALL_POLL_FREQUENCY: number;
22
+ PACKAGE_INSTALL_POLL_TIMEOUT: number;
21
23
  };
package/lib/constants.js CHANGED
@@ -36,5 +36,7 @@ exports.consts = {
36
36
  // tokens to be replaced on source:push
37
37
  INSTANCE_URL_TOKEN: '__SFDX_INSTANCE_URL__',
38
38
  PACKAGE2_DESCRIPTOR_FILE: 'package2-descriptor.json',
39
+ PACKAGE_INSTALL_POLL_FREQUENCY: 5000,
40
+ PACKAGE_INSTALL_POLL_TIMEOUT: 5, // 5 minutes
39
41
  };
40
42
  //# sourceMappingURL=constants.js.map
@@ -1,17 +1,21 @@
1
1
  import { Duration } from '@salesforce/kit';
2
2
  import { Connection, SfProject } from '@salesforce/core';
3
- import { SaveResult } from 'jsforce';
3
+ import { QueryResult, SaveResult } from 'jsforce';
4
4
  import { PackageProfileApi } from '../package/packageProfileApi';
5
5
  import { PackagingSObjects } from './packagingSObjects';
6
6
  import Package2VersionStatus = PackagingSObjects.Package2VersionStatus;
7
+ import PackageInstallRequest = PackagingSObjects.PackageInstallRequest;
7
8
  export interface IPackage {
8
9
  create(): Promise<void>;
9
10
  convert(): Promise<void>;
10
11
  delete(): Promise<void>;
11
- install(): Promise<void>;
12
- list(): Promise<void>;
12
+ install(pkgInstallCreateRequest: PackageInstallCreateRequest, options?: PackageInstallOptions): Promise<PackageInstallRequest>;
13
+ getInstallStatus(installRequestId: string): Promise<PackageInstallRequest>;
14
+ list(): Promise<QueryResult<PackagingSObjects.Package2>>;
13
15
  uninstall(): Promise<void>;
14
16
  update(): Promise<void>;
17
+ waitForPublish(subscriberPackageVersionKey: string, timeout: number | Duration, installationKey?: string): any;
18
+ getExternalSites(subscriberPackageVersionKey: string, installationKey?: string): any;
15
19
  }
16
20
  export interface IPackageVersion1GP {
17
21
  create(): Promise<void>;
@@ -31,7 +35,10 @@ export interface IPackageVersion2GP {
31
35
  uninstall(): Promise<void>;
32
36
  update(): Promise<void>;
33
37
  }
34
- export declare type PackageOptions = Record<string, unknown>;
38
+ export declare type PackageOptions = {
39
+ connection: Connection;
40
+ };
41
+ export declare type PackageIdType = 'PackageId' | 'SubscriberPackageVersionId' | 'PackageInstallRequestId' | 'PackageUninstallRequestId';
35
42
  export declare type PackageVersionOptions1GP = Record<string, unknown>;
36
43
  export declare type PackageVersionCreateRequestResult = {
37
44
  Id: string;
@@ -92,6 +99,7 @@ export declare type PackageVersionListResult = {
92
99
  BuildDurationInSeconds?: number;
93
100
  HasMetadataRemoved?: boolean;
94
101
  };
102
+ export declare type PackageInstallCreateRequest = Partial<Pick<PackageInstallRequest, 'ApexCompileType' | 'EnableRss' | 'NameConflictResolution' | 'PackageInstallSource' | 'Password' | 'SecurityType' | 'UpgradeType'>> & Pick<PackagingSObjects.PackageInstallRequest, 'SubscriberPackageVersionKey'>;
95
103
  export declare type Package1Display = {
96
104
  MetadataPackageVersionId: string;
97
105
  MetadataPackageId: string;
@@ -130,6 +138,18 @@ export declare type PackageVersionCreateRequestOptions = {
130
138
  branch?: string;
131
139
  skipancestorcheck?: boolean;
132
140
  };
141
+ export declare type PackageInstallOptions = {
142
+ /**
143
+ * The frequency to poll the org for package installation status. If providing a number
144
+ * it is interpreted in milliseconds.
145
+ */
146
+ pollingFrequency?: number | Duration;
147
+ /**
148
+ * The amount of time to wait for package installation to complete. If providing a number
149
+ * it is interpreted in minutes.
150
+ */
151
+ pollingTimeout?: number | Duration;
152
+ };
133
153
  export declare type MDFolderForArtifactOptions = {
134
154
  packageName?: string;
135
155
  sourceDir?: string;
@@ -1,3 +1,4 @@
1
+ import { Nullable } from '@salesforce/ts-types';
1
2
  import { PackageType } from './packagingInterfacesAndType';
2
3
  export declare namespace PackagingSObjects {
3
4
  type Package2 = {
@@ -118,6 +119,20 @@ export declare namespace PackagingSObjects {
118
119
  type SubscriberPackageDependencies = {
119
120
  ids: string[];
120
121
  };
122
+ type SubscriberPackageRemoteSiteSetting = {
123
+ secure: boolean;
124
+ url: string;
125
+ };
126
+ type SubscriberPackageRemoteSiteSettings = {
127
+ settings: SubscriberPackageRemoteSiteSetting[];
128
+ };
129
+ type SubscriberPackageCspTrustedSite = {
130
+ endpointUrl: string;
131
+ };
132
+ type SubscriberPackageCspTrustedSites = {
133
+ settings: SubscriberPackageCspTrustedSite[];
134
+ };
135
+ type InstallValidationStatus = 'NO_ERRORS_DETECTED' | 'BETA_INSTALL_INTO_PRODUCTION_ORG' | 'CANNOT_INSTALL_EARLIER_VERSION' | 'CANNOT_UPGRADE_BETA' | 'CANNOT_UPGRADE_UNMANAGED' | 'DEPRECATED_INSTALL_PACKAGE' | 'EXTENSIONS_ON_LOCAL_PACKAGES' | 'PACKAGE_NOT_INSTALLED' | 'PACKAGE_HAS_IN_DEV_EXTENSIONS' | 'INSTALL_INTO_DEV_ORG' | 'NO_ACCESS' | 'PACKAGING_DISABLED' | 'PACKAGING_NO_ACCESS' | 'PACKAGE_UNAVAILABLE' | 'UNINSTALL_IN_PROGRESS' | 'UNKNOWN_ERROR' | 'NAMESPACE_COLLISION';
121
136
  type SubscriberPackageVersion = {
122
137
  Id: string;
123
138
  SubscriberPackageId: string;
@@ -142,11 +157,11 @@ export declare namespace PackagingSObjects {
142
157
  AppExchangeLogoUrl: string;
143
158
  ReleaseNotesUrl: string;
144
159
  PostInstallUrl: string;
145
- RemoteSiteSettings: unknown;
146
- CspTrustedSites: unknown;
160
+ RemoteSiteSettings: SubscriberPackageRemoteSiteSettings;
161
+ CspTrustedSites: SubscriberPackageCspTrustedSites;
147
162
  Profiles: SubscriberPackageProfiles;
148
163
  Dependencies: SubscriberPackageDependencies;
149
- InstallValidationStatus: string;
164
+ InstallValidationStatus: InstallValidationStatus;
150
165
  };
151
166
  type SubscriberPackageVersionUninstallRequest = {
152
167
  Id: string;
@@ -170,6 +185,19 @@ export declare namespace PackagingSObjects {
170
185
  SubscriberPackageVersionId: string;
171
186
  Status: string;
172
187
  };
188
+ type SubscriberPackageInstallError = {
189
+ message: string;
190
+ };
191
+ type SubscriberPackageInstallErrors = {
192
+ errors: SubscriberPackageInstallError[];
193
+ };
194
+ type SubscriberPackageProfileMapping = {
195
+ source: string;
196
+ target: string;
197
+ };
198
+ type SubscriberPackageProfileMappings = {
199
+ profileMappings: SubscriberPackageProfileMapping[];
200
+ };
173
201
  type PackageInstallRequest = {
174
202
  Id: string;
175
203
  IsDeleted: boolean;
@@ -179,16 +207,16 @@ export declare namespace PackagingSObjects {
179
207
  LastModifiedById: string;
180
208
  SystemModstamp: number;
181
209
  SubscriberPackageVersionKey: string;
182
- NameConflictResolution: string;
183
- SecurityType: string;
210
+ NameConflictResolution: 'Block' | 'RenameMetadata';
211
+ SecurityType: 'Custom' | 'Full' | 'None';
184
212
  PackageInstallSource: string;
185
- ProfileMappings: unknown;
186
- Password: string;
213
+ ProfileMappings: Nullable<SubscriberPackageProfileMappings>;
214
+ Password: Nullable<string>;
187
215
  EnableRss: boolean;
188
- UpgradeType: string;
189
- ApexCompileType: string;
190
- Status: string;
191
- Errors: any[];
216
+ UpgradeType: Nullable<'delete-only' | 'deprecate-only' | 'mixed-mode'>;
217
+ ApexCompileType: Nullable<'all' | 'package'>;
218
+ Status: 'ERROR' | 'IN_PROGRESS' | 'SUCCESS' | 'UNKNOWN';
219
+ Errors: Nullable<SubscriberPackageInstallErrors>;
192
220
  };
193
221
  type PackageUploadRequest = {
194
222
  Id: string;
@@ -1,4 +1,5 @@
1
1
  export * from './package';
2
+ export * from './packageInstall';
2
3
  export * from './packageVersion';
3
4
  export * from './packageList';
4
5
  export * from './packageVersionCreateRequest';
@@ -22,6 +22,7 @@ exports.deletePackage = exports.createPackage = exports.listPackageVersions = vo
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("./packageInstall"), exports);
25
26
  __exportStar(require("./packageVersion"), exports);
26
27
  __exportStar(require("./packageList"), exports);
27
28
  __exportStar(require("./packageVersionCreateRequest"), exports);
@@ -1,5 +1,9 @@
1
- import { AsyncCreatable } from '@salesforce/kit';
2
- import { IPackage, PackageOptions } from '../interfaces';
1
+ import { AsyncCreatable, Duration } from '@salesforce/kit';
2
+ import { QueryResult } from 'jsforce';
3
+ import { Optional } from '@salesforce/ts-types';
4
+ import { IPackage, PackageOptions, PackagingSObjects } from '../interfaces';
5
+ import { PackageInstallOptions, PackageInstallCreateRequest, PackageIdType } from '../interfaces/packagingInterfacesAndType';
6
+ declare type PackageInstallRequest = PackagingSObjects.PackageInstallRequest;
3
7
  /**
4
8
  * Package class.
5
9
  *
@@ -8,12 +12,30 @@ import { IPackage, PackageOptions } from '../interfaces';
8
12
  export declare class Package extends AsyncCreatable<PackageOptions> implements IPackage {
9
13
  private options;
10
14
  constructor(options: PackageOptions);
15
+ /**
16
+ * Given a Salesforce ID for a package resource and the type of resource,
17
+ * ensures the ID is valid.
18
+ *
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)
24
+ *
25
+ * @param id Salesforce ID for a specific package resource
26
+ * @param type The type of package ID
27
+ */
28
+ static validateId(id: string, type: PackageIdType): void;
11
29
  convert(): Promise<void>;
12
30
  create(): Promise<void>;
13
31
  delete(): Promise<void>;
14
- install(): Promise<void>;
15
- list(): Promise<void>;
32
+ install(pkgInstallCreateRequest: PackageInstallCreateRequest, options?: PackageInstallOptions): Promise<PackageInstallRequest>;
33
+ getInstallStatus(installRequestId: string): Promise<PackageInstallRequest>;
34
+ list(): Promise<QueryResult<PackagingSObjects.Package2>>;
16
35
  uninstall(): Promise<void>;
17
36
  update(): Promise<void>;
37
+ getExternalSites(subscriberPackageVersionId: string, installationKey?: string): Promise<Optional<string[]>>;
38
+ waitForPublish(subscriberPackageVersionId: string, timeout: number | Duration, installationKey?: string): Promise<void>;
18
39
  protected init(): Promise<void>;
19
40
  }
41
+ export {};
@@ -7,18 +7,50 @@ exports.Package = void 0;
7
7
  * Licensed under the BSD 3-Clause license.
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
+ const core_1 = require("@salesforce/core");
10
11
  const kit_1 = require("@salesforce/kit");
12
+ const packageList_1 = require("./packageList");
13
+ const packageInstall_1 = require("./packageInstall");
14
+ const packagePrefixes = {
15
+ PackageId: '0Ho',
16
+ SubscriberPackageVersionId: '04t',
17
+ PackageInstallRequestId: '0Hf',
18
+ PackageUninstallRequestId: '06y',
19
+ };
20
+ core_1.Messages.importMessagesDirectory(__dirname);
21
+ const messages = core_1.Messages.loadMessages('@salesforce/packaging', 'package');
11
22
  /**
12
23
  * Package class.
13
24
  *
14
25
  * This class provides the base implementation for a package.
15
26
  */
16
27
  class Package extends kit_1.AsyncCreatable {
17
- // @ts-ignore
18
28
  constructor(options) {
19
29
  super(options);
20
30
  this.options = options;
21
31
  }
32
+ /**
33
+ * Given a Salesforce ID for a package resource and the type of resource,
34
+ * ensures the ID is valid.
35
+ *
36
+ * Valid ID types and prefixes for packaging resources:
37
+ * 1. package ID (0Ho)
38
+ * 2. subscriber package version ID (04t)
39
+ * 3. package install request ID (0Hf)
40
+ * 4. package uninstall request ID (06y)
41
+ *
42
+ * @param id Salesforce ID for a specific package resource
43
+ * @param type The type of package ID
44
+ */
45
+ static validateId(id, type) {
46
+ const prefix = packagePrefixes[type];
47
+ if (!id.startsWith(prefix)) {
48
+ throw messages.createError('invalidPackageId', [type, id, prefix]);
49
+ }
50
+ if (!core_1.sfdc.validateSalesforceId(id)) {
51
+ throw messages.createError('invalidIdLength', [type, id]);
52
+ }
53
+ }
22
54
  convert() {
23
55
  return Promise.resolve(undefined);
24
56
  }
@@ -28,11 +60,14 @@ class Package extends kit_1.AsyncCreatable {
28
60
  delete() {
29
61
  return Promise.resolve(undefined);
30
62
  }
31
- install() {
32
- return Promise.resolve(undefined);
63
+ async install(pkgInstallCreateRequest, options) {
64
+ return (0, packageInstall_1.installPackage)(this.options.connection, pkgInstallCreateRequest, options);
65
+ }
66
+ async getInstallStatus(installRequestId) {
67
+ return (0, packageInstall_1.getStatus)(this.options.connection, installRequestId);
33
68
  }
34
69
  list() {
35
- return Promise.resolve(undefined);
70
+ return (0, packageList_1.listPackages)(this.options.connection);
36
71
  }
37
72
  uninstall() {
38
73
  return Promise.resolve(undefined);
@@ -40,6 +75,12 @@ class Package extends kit_1.AsyncCreatable {
40
75
  update() {
41
76
  return Promise.resolve(undefined);
42
77
  }
78
+ async getExternalSites(subscriberPackageVersionId, installationKey) {
79
+ return (0, packageInstall_1.getExternalSites)(this.options.connection, subscriberPackageVersionId, installationKey);
80
+ }
81
+ async waitForPublish(subscriberPackageVersionId, timeout, installationKey) {
82
+ return (0, packageInstall_1.waitForPublish)(this.options.connection, subscriberPackageVersionId, timeout, installationKey);
83
+ }
43
84
  init() {
44
85
  return Promise.resolve(undefined);
45
86
  }
@@ -0,0 +1,18 @@
1
+ import { Connection } from '@salesforce/core';
2
+ import { Optional } from '@salesforce/ts-types';
3
+ import { Duration } from '@salesforce/kit';
4
+ import { PackagingSObjects } from '../interfaces';
5
+ import { PackageInstallOptions, PackageInstallCreateRequest } from '../interfaces/packagingInterfacesAndType';
6
+ import PackageInstallRequest = PackagingSObjects.PackageInstallRequest;
7
+ export declare function installPackage(connection: Connection, pkgInstallCreateRequest: PackageInstallCreateRequest, options?: PackageInstallOptions): Promise<PackageInstallRequest>;
8
+ /**
9
+ * Returns an array of RSS and CSP external sites for the package.
10
+ *
11
+ * @param connection The `Connection` object to the org.
12
+ * @param subscriberPackageVersionId The ID of the subscriber package version (begins with "04t")
13
+ * @param installationKey The installation key (if any) for the subscriber package version.
14
+ * @returns an array of RSS and CSP site URLs, or undefined if the package doesn't have any.
15
+ */
16
+ export declare function getExternalSites(connection: Connection, subscriberPackageVersionId: string, installationKey?: string): Promise<Optional<string[]>>;
17
+ export declare function getStatus(connection: Connection, installRequestId: string): Promise<PackageInstallRequest>;
18
+ export declare function waitForPublish(connection: Connection, subscriberPackageVersionId: string, timeout: number | Duration, installationKey?: string): Promise<void>;
@@ -0,0 +1,222 @@
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.waitForPublish = exports.getStatus = exports.getExternalSites = exports.installPackage = void 0;
10
+ const core_1 = require("@salesforce/core");
11
+ const ts_types_1 = require("@salesforce/ts-types");
12
+ const kit_1 = require("@salesforce/kit");
13
+ const packageUtils_1 = require("../utils/packageUtils");
14
+ const constants_1 = require("../constants");
15
+ core_1.Messages.importMessagesDirectory(__dirname);
16
+ const installMsgs = core_1.Messages.loadMessages('@salesforce/packaging', 'package-install');
17
+ let logger;
18
+ const getLogger = () => {
19
+ if (!logger) {
20
+ logger = core_1.Logger.childFromRoot('installPackage');
21
+ }
22
+ return logger;
23
+ };
24
+ async function installPackage(connection, pkgInstallCreateRequest, options) {
25
+ const defaults = {
26
+ ApexCompileType: 'all',
27
+ EnableRss: false,
28
+ NameConflictResolution: 'Block',
29
+ PackageInstallSource: 'U',
30
+ SecurityType: 'none',
31
+ UpgradeType: 'mixed-mode',
32
+ };
33
+ const request = Object.assign({}, defaults, pkgInstallCreateRequest);
34
+ if (request.Password) {
35
+ request.Password = (0, packageUtils_1.escapeInstallationKey)(request.Password);
36
+ }
37
+ const pkgType = await (0, packageUtils_1.getPackageTypeBy04t)(request.SubscriberPackageVersionKey, connection, request.Password);
38
+ // Only unlocked packages can change the UpgradeType and ApexCompile options from the defaults.
39
+ if (pkgType !== 'Unlocked') {
40
+ if (request.UpgradeType !== defaults.UpgradeType) {
41
+ const msg = installMsgs.getMessage('upgradeTypeOnlyForUnlockedWarning');
42
+ await core_1.Lifecycle.getInstance().emit('PackageInstallRequest:warning', msg);
43
+ delete request.UpgradeType;
44
+ }
45
+ if (request.ApexCompileType !== defaults.ApexCompileType) {
46
+ const msg = installMsgs.getMessage('apexCompileOnlyForUnlockedWarning');
47
+ await core_1.Lifecycle.getInstance().emit('PackageInstallRequest:warning', msg);
48
+ delete request.ApexCompileType;
49
+ }
50
+ }
51
+ await core_1.Lifecycle.getInstance().emit('PackageInstallRequest:presend', request);
52
+ const result = await connection.tooling.create('PackageInstallRequest', request);
53
+ await core_1.Lifecycle.getInstance().emit('PackageInstallRequest:postsend', result);
54
+ const packageInstallRequestId = result.id;
55
+ if (!packageInstallRequestId) {
56
+ throw installMsgs.createError('packageInstallRequestError', [
57
+ request.SubscriberPackageVersionKey,
58
+ result.errors.toString(),
59
+ ]);
60
+ }
61
+ if (options?.pollingTimeout == null) {
62
+ return getStatus(connection, packageInstallRequestId);
63
+ }
64
+ else {
65
+ return pollStatus(connection, packageInstallRequestId, options);
66
+ }
67
+ }
68
+ exports.installPackage = installPackage;
69
+ /**
70
+ * Returns an array of RSS and CSP external sites for the package.
71
+ *
72
+ * @param connection The `Connection` object to the org.
73
+ * @param subscriberPackageVersionId The ID of the subscriber package version (begins with "04t")
74
+ * @param installationKey The installation key (if any) for the subscriber package version.
75
+ * @returns an array of RSS and CSP site URLs, or undefined if the package doesn't have any.
76
+ */
77
+ async function getExternalSites(connection, subscriberPackageVersionId, installationKey) {
78
+ const installKey = (0, packageUtils_1.escapeInstallationKey)(installationKey);
79
+ const queryNoKey = `SELECT RemoteSiteSettings, CspTrustedSites FROM SubscriberPackageVersion WHERE Id ='${subscriberPackageVersionId}'`;
80
+ const queryWithKey = `SELECT RemoteSiteSettings, CspTrustedSites FROM SubscriberPackageVersion WHERE Id ='${subscriberPackageVersionId}' AND InstallationKey ='${installKey}'`;
81
+ let queryResult;
82
+ try {
83
+ getLogger().debug(`Checking package: [${subscriberPackageVersionId}] for external sites`);
84
+ queryResult = await connection.tooling.query(queryWithKey);
85
+ }
86
+ catch (e) {
87
+ // First check for Implementation Restriction error that is enforced in 214, before it was possible to query
88
+ // against InstallationKey, otherwise surface the error.
89
+ if (e instanceof Error && (0, packageUtils_1.isErrorFromSPVQueryRestriction)(e)) {
90
+ queryResult = await connection.tooling.query(queryNoKey);
91
+ }
92
+ else {
93
+ throw e;
94
+ }
95
+ }
96
+ if (queryResult?.records?.length > 0) {
97
+ const record = queryResult.records[0];
98
+ const rssUrls = record.RemoteSiteSettings.settings.map((rss) => rss.url);
99
+ const cspUrls = record.CspTrustedSites.settings.map((csp) => csp.endpointUrl);
100
+ const sites = [...rssUrls, ...cspUrls];
101
+ if (sites.length) {
102
+ return sites;
103
+ }
104
+ }
105
+ }
106
+ exports.getExternalSites = getExternalSites;
107
+ async function getStatus(connection, installRequestId) {
108
+ const result = await connection.tooling.retrieve('PackageInstallRequest', installRequestId);
109
+ return result;
110
+ }
111
+ exports.getStatus = getStatus;
112
+ // internal
113
+ async function pollStatus(connection, installRequestId, options) {
114
+ let packageInstallRequest;
115
+ const { pollingFrequency, pollingTimeout } = options;
116
+ let frequency;
117
+ if (pollingFrequency != null) {
118
+ frequency = (0, ts_types_1.isNumber)(pollingFrequency) ? kit_1.Duration.milliseconds(pollingFrequency) : pollingFrequency;
119
+ }
120
+ else {
121
+ frequency = kit_1.Duration.milliseconds(constants_1.consts.PACKAGE_INSTALL_POLL_FREQUENCY);
122
+ }
123
+ let timeout;
124
+ if (pollingTimeout != null) {
125
+ timeout = (0, ts_types_1.isNumber)(pollingTimeout) ? kit_1.Duration.minutes(pollingTimeout) : pollingTimeout;
126
+ }
127
+ else {
128
+ timeout = kit_1.Duration.minutes(constants_1.consts.PACKAGE_INSTALL_POLL_TIMEOUT);
129
+ }
130
+ const pollingOptions = {
131
+ frequency,
132
+ timeout,
133
+ poll: async () => {
134
+ packageInstallRequest = await getStatus(connection, installRequestId);
135
+ getLogger().debug(installMsgs.getMessage('packageInstallPolling', [packageInstallRequest?.Status]));
136
+ await core_1.Lifecycle.getInstance().emit('PackageInstallRequest:status', packageInstallRequest);
137
+ if (['SUCCESS', 'ERROR'].includes(packageInstallRequest?.Status)) {
138
+ return { completed: true, payload: packageInstallRequest };
139
+ }
140
+ return { completed: false };
141
+ },
142
+ };
143
+ const pollingClient = await core_1.PollingClient.create(pollingOptions);
144
+ try {
145
+ getLogger().debug(`Polling for PackageInstallRequest status. Package ID = ${installRequestId}`);
146
+ getLogger().debug(`Polling frequency (ms): ${pollingOptions.frequency.milliseconds}`);
147
+ getLogger().debug(`Polling timeout (min): ${pollingOptions.timeout.minutes}`);
148
+ await pollingClient.subscribe();
149
+ return packageInstallRequest;
150
+ }
151
+ catch (e) {
152
+ const errMsg = e instanceof Error ? e.message : (0, ts_types_1.isString)(e) ? e : 'polling timed out';
153
+ const error = new core_1.SfError(errMsg, 'PackageInstallTimeout');
154
+ error.setData(packageInstallRequest);
155
+ if (error.stack && e.stack) {
156
+ // add the original stack to this new error
157
+ error.stack += `\nDUE TO:\n${e.stack}`;
158
+ }
159
+ throw error;
160
+ }
161
+ }
162
+ async function waitForPublish(connection, subscriberPackageVersionId, timeout, installationKey) {
163
+ let queryResult;
164
+ const pollingOptions = {
165
+ frequency: kit_1.Duration.milliseconds(constants_1.consts.PACKAGE_INSTALL_POLL_FREQUENCY),
166
+ timeout: (0, ts_types_1.isNumber)(timeout) ? kit_1.Duration.minutes(timeout) : timeout,
167
+ poll: async () => {
168
+ const QUERY_NO_KEY = `SELECT Id, SubscriberPackageId, InstallValidationStatus FROM SubscriberPackageVersion WHERE Id ='${subscriberPackageVersionId}'`;
169
+ try {
170
+ const escapedInstallationKey = installationKey ? (0, packageUtils_1.escapeInstallationKey)(installationKey) : null;
171
+ const queryWithKey = `${QUERY_NO_KEY} AND InstallationKey ='${escapedInstallationKey}'`;
172
+ queryResult = await connection.tooling.query(queryWithKey);
173
+ }
174
+ catch (e) {
175
+ // Check first for Implementation Restriction error that is enforced in 214, before it was possible to query
176
+ // against InstallationKey, otherwise surface the error.
177
+ if (e instanceof Error && (0, packageUtils_1.isErrorFromSPVQueryRestriction)(e)) {
178
+ queryResult = await connection.tooling.query(QUERY_NO_KEY);
179
+ }
180
+ else {
181
+ if (e instanceof Error && !(0, packageUtils_1.isErrorPackageNotAvailable)(e)) {
182
+ throw e;
183
+ }
184
+ }
185
+ }
186
+ // Continue retrying if there is no record
187
+ // or for an InstallValidationStatus of PACKAGE_UNAVAILABLE (replication to the subscriber's instance has not completed)
188
+ // or for an InstallValidationStatus of UNINSTALL_IN_PROGRESS
189
+ let installValidationStatus;
190
+ if (queryResult?.records?.length) {
191
+ installValidationStatus = queryResult.records[0].InstallValidationStatus;
192
+ await core_1.Lifecycle.getInstance().emit('SubscriberPackageVersion:status', installValidationStatus);
193
+ if (!['PACKAGE_UNAVAILABLE', 'UNINSTALL_IN_PROGRESS'].includes(installValidationStatus)) {
194
+ return { completed: true, payload: queryResult };
195
+ }
196
+ }
197
+ const tokens = installValidationStatus ? [` Status = ${installValidationStatus}`] : [];
198
+ getLogger().debug(installMsgs.getMessage('publishWaitProgress', tokens));
199
+ await core_1.Lifecycle.getInstance().emit('SubscriberPackageVersion:status', installValidationStatus);
200
+ return { completed: false, payload: queryResult };
201
+ },
202
+ };
203
+ const pollingClient = await core_1.PollingClient.create(pollingOptions);
204
+ try {
205
+ getLogger().debug(`Polling for package availability in org. Package ID = ${subscriberPackageVersionId}`);
206
+ getLogger().debug(`Polling frequency (ms): ${pollingOptions.frequency.milliseconds}`);
207
+ getLogger().debug(`Polling timeout (min): ${pollingOptions.timeout.minutes}`);
208
+ await pollingClient.subscribe();
209
+ }
210
+ catch (e) {
211
+ // if polling timed out
212
+ const error = installMsgs.createError('subscriberPackageVersionNotPublished');
213
+ error.setData(queryResult);
214
+ if (error.stack && e.stack) {
215
+ // append the original stack to this new error
216
+ error.stack += `\nDUE TO:\n${e.stack}`;
217
+ }
218
+ throw error;
219
+ }
220
+ }
221
+ exports.waitForPublish = waitForPublish;
222
+ //# sourceMappingURL=packageInstall.js.map
@@ -1,6 +1,6 @@
1
1
  import { Connection, NamedPackageDir, PackageDir, SfdcUrl, SfError, SfProject } from '@salesforce/core';
2
2
  import { Duration } from '@salesforce/kit';
3
- import { Many } from '@salesforce/ts-types';
3
+ import { Many, Nullable } from '@salesforce/ts-types';
4
4
  import { SaveError } from 'jsforce';
5
5
  import { PackagingSObjects, PackageVersionCreateRequestResult, PackageVersionCreateOptions } from '../interfaces';
6
6
  export declare const VERSION_NUMBER_SEP = ".";
@@ -39,6 +39,7 @@ export declare function applyErrorAction(err: Error): Error;
39
39
  * @param connection For tooling query
40
40
  */
41
41
  export declare function getPackageVersionId(versionId: string, connection: Connection): Promise<string>;
42
+ export declare function escapeInstallationKey(key?: string): Nullable<string>;
42
43
  /**
43
44
  * Given 0Ho the package type type (Managed, Unlocked, Locked(deprecated?))
44
45
  *
@@ -55,7 +56,7 @@ export declare function getPackageType(packageId: string, connection: Connection
55
56
  * @param installKey For tooling query, if an installation key is applicable to the package version it must be passed in the queries
56
57
  * @throws Error with message when package2 cannot be found
57
58
  */
58
- export declare function getPackageTypeBy04t(packageVersionId: string, connection: Connection, installKey: string): Promise<string>;
59
+ export declare function getPackageTypeBy04t(packageVersionId: string, connection: Connection, installKey?: string): Promise<string>;
59
60
  /**
60
61
  * Given a package version ID (05i) or subscriber package version ID (04t), return the subscriber package version ID (04t)
61
62
  *
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveCanonicalPackageProperty = exports.combineSaveErrors = exports.formatDate = exports.getSoqlWhereClauseMaxLength = exports.pollForStatusWithInterval = exports.findOrCreatePackage = exports.getPackageAliasesFromId = exports.convertCamelCaseStringToSentence = exports.getPackageIdFromAlias = exports.getConfigPackageDirectory = exports.getConfigPackageDirectories = exports.getPackageVersionNumber = exports.concatVersion = exports.getAncestorIdHighestRelease = exports.validateAncestorId = exports.getAncestorId = exports.getInClauseItemsCount = exports.queryWithInConditionChunking = exports.getPackageVersionStrings = exports.getHasMetadataRemoved = exports.getContainerOptions = exports.getSubscriberPackageVersionId = exports.getPackageTypeBy04t = exports.getPackageType = 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;
3
+ exports.resolveCanonicalPackageProperty = exports.combineSaveErrors = exports.formatDate = exports.getSoqlWhereClauseMaxLength = exports.pollForStatusWithInterval = exports.findOrCreatePackage = exports.getPackageAliasesFromId = exports.convertCamelCaseStringToSentence = exports.getPackageIdFromAlias = exports.getConfigPackageDirectory = exports.getConfigPackageDirectories = exports.getPackageVersionNumber = exports.concatVersion = exports.getAncestorIdHighestRelease = exports.validateAncestorId = exports.getAncestorId = exports.getInClauseItemsCount = exports.queryWithInConditionChunking = exports.getPackageVersionStrings = exports.getHasMetadataRemoved = exports.getContainerOptions = exports.getSubscriberPackageVersionId = exports.getPackageTypeBy04t = exports.getPackageType = exports.escapeInstallationKey = 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;
4
4
  /*
5
5
  * Copyright (c) 2022, salesforce.com, inc.
6
6
  * All rights reserved.
@@ -211,6 +211,10 @@ async function getPackageVersionId(versionId, connection) {
211
211
  });
212
212
  }
213
213
  exports.getPackageVersionId = getPackageVersionId;
214
+ function escapeInstallationKey(key) {
215
+ return key ? key.replace(/\\/g, '\\\\').replace(/'/g, "\\'") : null;
216
+ }
217
+ exports.escapeInstallationKey = escapeInstallationKey;
214
218
  /**
215
219
  * Given 0Ho the package type type (Managed, Unlocked, Locked(deprecated?))
216
220
  *
@@ -5,8 +5,7 @@
5
5
  *
6
6
  * @param dir to zip
7
7
  * @param zipfile
8
- * @param options
9
8
  */
10
- export declare function zipDir(dir: string, zipfile: string, options?: {}): Promise<void>;
9
+ export declare function zipDir(dir: string, zipfile: string): Promise<void>;
11
10
  export declare function getElapsedTime(timer: [number, number]): string;
12
11
  export declare function copyDir(src: string, dest: string): void;
@@ -22,9 +22,8 @@ const pipeline = (0, util_1.promisify)(stream_1.pipeline);
22
22
  *
23
23
  * @param dir to zip
24
24
  * @param zipfile
25
- * @param options
26
25
  */
27
- async function zipDir(dir, zipfile, options = {}) {
26
+ async function zipDir(dir, zipfile) {
28
27
  const logger = core_1.Logger.childFromRoot('srcDevUtils#zipDir');
29
28
  const timer = process.hrtime();
30
29
  const globbyResult = await globby('**/*', { expandDirectories: true, cwd: dir });
@@ -0,0 +1,28 @@
1
+ # upgradeTypeOnlyForUnlockedWarning
2
+
3
+ WARNING: We ignored the upgradetype parameter when installing this package version. The upgradetype parameter is available only for unlocked package installations. Managed package upgrades always default to using the Mixed upgrade type.
4
+
5
+ # apexCompileOnlyForUnlockedWarning
6
+
7
+ WARNING: We ignored the apexcompile parameter when installing this package version. The apexcompile parameter is available only for installations of unlocked packages.
8
+
9
+ # packageInstallPolling
10
+
11
+ Waiting for the package install request to complete. Status = %s
12
+
13
+ # packageInstallRequestError
14
+
15
+ Failed to create PackageInstallRequest for: %s
16
+ Due to: %s
17
+
18
+ # publishWaitProgress
19
+
20
+ Waiting for the Subscriber Package Version ID to be published to the target org.%s
21
+
22
+ # subscriberPackageVersionNotPublished
23
+
24
+ The subscriber package version is not fully available.
25
+
26
+ # subscriberPackageVersionNotPublished.actions
27
+
28
+ If this is a recently created package version, try again in a few minutes or contact the package publisher.
@@ -0,0 +1,7 @@
1
+ # invalidPackageId
2
+
3
+ The %s: [%s] is invalid. It must start with "%s".
4
+
5
+ # invalidIdLength
6
+
7
+ The %s: [%s] is invalid. It must be either 15 or 18 characters.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/packaging",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "packing libraries to Salesforce packaging platform",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",
@@ -35,8 +35,8 @@
35
35
  "!lib/**/*.map"
36
36
  ],
37
37
  "dependencies": {
38
- "@salesforce/core": "^3.23.7",
39
- "@salesforce/kit": "^1.5.42",
38
+ "@salesforce/core": "^3.24.0",
39
+ "@salesforce/kit": "^1.5.44",
40
40
  "@salesforce/schemas": "^1.2.0",
41
41
  "@salesforce/source-deploy-retrieve": "^6.2.0",
42
42
  "@salesforce/ts-types": "^1.5.20",