@salesforce/packaging 5.0.13 → 5.0.15

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.
@@ -72,7 +72,16 @@ const messages = core_1.Messages.loadMessages('@salesforce/packaging', 'package_
72
72
  const POLL_INTERVAL_SECONDS = 30;
73
73
  async function findOrCreatePackage2(seedPackage, connection, project) {
74
74
  const query = `SELECT Id, Name FROM Package2 WHERE ConvertedFromPackageId = '${seedPackage}'`;
75
- const queryResult = (await connection.tooling.query(query)).records;
75
+ let queryResult;
76
+ try {
77
+ queryResult = (await connection.tooling.query(query)).records;
78
+ }
79
+ catch (e) {
80
+ if (isPackage2NotSupportedError(e)) {
81
+ throw messages.createError('convertPackagingNotEnabledOnOrg');
82
+ }
83
+ throw e;
84
+ }
76
85
  if (queryResult?.length > 1) {
77
86
  const ids = queryResult.map((r) => r.Id);
78
87
  throw messages.createError('errorMoreThanOnePackage2WithSeed', [ids.join(', ')]);
@@ -104,6 +113,9 @@ async function findOrCreatePackage2(seedPackage, connection, project) {
104
113
  };
105
114
  const createResult = await connection.tooling.create('Package2', request);
106
115
  if (!createResult.success) {
116
+ if (createResult.errors?.some((error) => isPackage2NotSupportedError(error))) {
117
+ throw messages.createError('convertPackagingNotEnabledOnOrg');
118
+ }
107
119
  throw pkgUtils.combineSaveErrors('Package2', 'create', createResult.errors);
108
120
  }
109
121
  if (project) {
@@ -366,4 +378,27 @@ async function addPackageAlias(project, packageName, packageId) {
366
378
  * @returns {boolean} if one of the values in status is found.
367
379
  */
368
380
  const isStatusEqualTo = (results, statuses = []) => (!results?.length ? false : statuses.some((status) => results[0].Status === status));
381
+ /**
382
+ * Detects the tooling-API error thrown when a Dev Hub does not have second-generation
383
+ * packaging enabled and the Package2 entity is therefore not accessible. The full server
384
+ * message may append custom-object WSDL boilerplate, so match on a substring (consistent
385
+ * with the handling in packageVersionRetrieve.ts).
386
+ *
387
+ * @param err the error thrown by a Package2 tooling call
388
+ * @returns true if the error indicates Package2 is not supported on the org
389
+ */
390
+ const isPackage2NotSupportedError = (err) => {
391
+ let msg;
392
+ if (err instanceof Error) {
393
+ msg = err.message;
394
+ }
395
+ else if (typeof err === 'object' && err !== null && 'message' in err) {
396
+ // jsforce SaveError objects are plain objects that carry a `message` field.
397
+ msg = String(err.message);
398
+ }
399
+ else {
400
+ msg = String(err);
401
+ }
402
+ return msg.includes("sObject type 'Package2' is not supported.");
403
+ };
369
404
  //# sourceMappingURL=packageConvert.js.map
@@ -56,6 +56,8 @@ const kit_1 = require("@salesforce/kit");
56
56
  const project_1 = require("@salesforce/core/project");
57
57
  const pkgUtils = __importStar(require("../utils/packageUtils"));
58
58
  const packageUtils_1 = require("../utils/packageUtils");
59
+ core_1.Messages.importMessagesDirectory(__dirname);
60
+ const messages = core_1.Messages.loadMessages('@salesforce/packaging', 'package_create');
59
61
  function createPackageRequestFromContext(project, options) {
60
62
  const namespace = options.noNamespace ? '' : project.getSfProjectJson().getContents().namespace ?? '';
61
63
  return {
@@ -97,10 +99,16 @@ async function createPackage(connection, project, options) {
97
99
  .sobject('Package2')
98
100
  .create(request)
99
101
  .catch((err) => {
102
+ if (isPackagingNotEnabledError(err)) {
103
+ throw messages.createError('createPackagingNotEnabledOnOrg');
104
+ }
100
105
  const error = err instanceof Error ? err : new Error(typeof err === 'string' ? err : 'Unknown error');
101
106
  throw core_1.SfError.wrap((0, packageUtils_1.applyErrorAction)((0, packageUtils_1.massageErrorMessage)(error)));
102
107
  });
103
108
  if (!createResult.success) {
109
+ if (createResult.errors?.some((error) => isPackagingNotEnabledError(error))) {
110
+ throw messages.createError('createPackagingNotEnabledOnOrg');
111
+ }
104
112
  throw pkgUtils.combineSaveErrors('Package2', 'create', createResult.errors);
105
113
  }
106
114
  if (!kit_1.env.getBoolean('SF_PROJECT_AUTOUPDATE_DISABLE_FOR_PACKAGE_CREATE')) {
@@ -116,4 +124,34 @@ const sanitizePackageCreateOptions = (options) => ({
116
124
  ...options,
117
125
  path: options.path.replace(/\/$/, ''),
118
126
  });
127
+ /**
128
+ * Detects the tooling-API error thrown when a Dev Hub does not have second-generation
129
+ * packaging enabled and the Package2 entity is therefore not accessible. The Package2
130
+ * create REST endpoint (connection.tooling.sobject('Package2').create) 404s with a
131
+ * NOT_FOUND / "The requested resource does not exist" error. (This differs from the SOQL
132
+ * path used by package convert, which instead reports "sObject type 'Package2' is not
133
+ * supported" -- but package create never issues a SOQL query, so that form cannot occur
134
+ * here.)
135
+ *
136
+ * @param err the error (or jsforce SaveError) thrown by a Package2 tooling call
137
+ * @returns true if the error indicates Package2 is not supported on the org
138
+ */
139
+ const isPackagingNotEnabledError = (err) => {
140
+ let name = '';
141
+ let msg;
142
+ if (err instanceof Error) {
143
+ name = err.name;
144
+ msg = err.message;
145
+ }
146
+ else if (typeof err === 'object' && err !== null) {
147
+ // jsforce SaveError objects are plain objects that carry `errorCode`/`statusCode` and `message`.
148
+ const e = err;
149
+ name = String(e.errorCode ?? e.statusCode ?? '');
150
+ msg = typeof e.message === 'string' ? e.message : '';
151
+ }
152
+ else {
153
+ msg = String(err);
154
+ }
155
+ return name === 'NOT_FOUND' && msg.includes('The requested resource does not exist');
156
+ };
119
157
  //# sourceMappingURL=packageCreate.js.map
@@ -1,3 +1,7 @@
1
1
  # unableToFindPackageWithId
2
2
 
3
3
  Unable to find Package with Id: "%s"
4
+
5
+ # createPackagingNotEnabledOnOrg
6
+
7
+ Can't create package. The Dev Hub you specified doesn't have the Second-Generation Managed Packages setting enabled. Enable this setting on your Dev Hub, and try again.
@@ -115,6 +115,10 @@ No subscriber package was found for seed id: %s
115
115
  Only one package in a Dev Hub is allowed per converted from first-generation package, but the following were found:
116
116
  %s
117
117
 
118
+ # convertPackagingNotEnabledOnOrg
119
+
120
+ Can't convert package. The Dev Hub you specified doesn't have the Second-Generation Managed Packages setting enabled. Enable this setting on your Dev Hub, and try again.
121
+
118
122
  # errorMissingPackageIdOrPath
119
123
 
120
124
  You must specify either a package ID or a package path to create a new package version.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/packaging",
3
- "version": "5.0.13",
3
+ "version": "5.0.15",
4
4
  "description": "Packaging library for the Salesforce packaging platform",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",