@salesforce/core 7.3.10 → 7.3.12-qa.0

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.
@@ -52,6 +52,7 @@ const stateAggregator_1 = require("../stateAggregator/stateAggregator");
52
52
  const filters_1 = require("../logger/filters");
53
53
  const messages_1 = require("../messages");
54
54
  const sfdcUrl_1 = require("../util/sfdcUrl");
55
+ const findSuggestion_1 = require("../util/findSuggestion");
55
56
  const connection_1 = require("./connection");
56
57
  const orgConfigProperties_1 = require("./orgConfigProperties");
57
58
  const org_1 = require("./org");
@@ -624,7 +625,17 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
624
625
  }
625
626
  // If a username with NO oauth options, ensure authorization already exist.
626
627
  else if (username && !authOptions && !(await this.stateAggregator.orgs.exists(username))) {
627
- throw messages.createError('namedOrgNotFound', [username]);
628
+ const likeName = (0, findSuggestion_1.findSuggestion)(username, [
629
+ ...(await this.stateAggregator.orgs.list()).map((f) => f.split('.json')[0]),
630
+ ...Object.keys(this.stateAggregator.aliases.getAll()),
631
+ ]);
632
+ throw sfError_1.SfError.create({
633
+ name: 'NamedOrgNotFoundError',
634
+ message: messages.getMessage('namedOrgNotFound', [username]),
635
+ actions: likeName === ''
636
+ ? undefined
637
+ : [`It looks like you mistyped the username or alias. Did you mean "${likeName}"?`],
638
+ });
628
639
  }
629
640
  else {
630
641
  await this.initAuthOptions(authOptions);
@@ -53,6 +53,7 @@ const getAncestorIds = async (scratchOrgInfo, projectJson, hubOrg) => {
53
53
  throw new sfError_1.SfError(messages.getMessage('Package2AncestorsIdsKeyNotSupportedError'), 'DeprecationError');
54
54
  }
55
55
  const packagesWithAncestors = (await projectJson.getPackageDirectories())
56
+ .filter(sfProject_1.isPackagingDirectory)
56
57
  // check that the package has any ancestor types (id or version)
57
58
  .filter((packageDir) => packageDir.ancestorId ?? packageDir.ancestorVersion);
58
59
  if (packagesWithAncestors.length === 0) {
@@ -1,40 +1,9 @@
1
1
  import { Dictionary, JsonMap, Nullable, Optional } from '@salesforce/ts-types';
2
+ import { PackageDir as PackageDirSchema, PackageDirDependency as PackageDirDependencySchema, ProjectJson as ProjectJsonSchema, PackagePackageDir } from '@salesforce/schemas';
2
3
  import { ConfigFile } from './config/configFile';
3
4
  import { ConfigContents } from './config/configStackTypes';
4
- export type PackageDirDependency = {
5
- [k: string]: unknown;
6
- package: string;
7
- versionNumber?: string;
8
- };
9
- export type PackageDir = {
10
- ancestorId?: string;
11
- ancestorVersion?: string;
12
- default?: boolean;
13
- definitionFile?: string;
14
- dependencies?: PackageDirDependency[];
15
- includeProfileUserLicenses?: boolean;
16
- package?: string;
17
- packageMetadataAccess?: {
18
- permissionSets: string | string[];
19
- permissionSetLicenses: string | string[];
20
- };
21
- path: string;
22
- postInstallScript?: string;
23
- postInstallUrl?: string;
24
- releaseNotesUrl?: string;
25
- scopeProfiles?: boolean;
26
- uninstallScript?: string;
27
- versionDescription?: string;
28
- versionName?: string;
29
- versionNumber?: string;
30
- unpackagedMetadata?: {
31
- path: string;
32
- };
33
- seedMetadata?: {
34
- path: string;
35
- };
36
- };
37
- export type NamedPackageDir = PackageDir & {
5
+ export type PackageDirDependency = PackageDirDependencySchema;
6
+ type NamedDirAdditions = {
38
7
  /**
39
8
  * The [normalized](https://nodejs.org/api/path.html#path_path_normalize_path) path used as the package name.
40
9
  */
@@ -44,20 +13,10 @@ export type NamedPackageDir = PackageDir & {
44
13
  */
45
14
  fullPath: string;
46
15
  };
47
- export type ProjectJson = ConfigContents & {
48
- packageDirectories: PackageDir[];
49
- namespace?: string;
50
- sourceApiVersion?: string;
51
- sfdcLoginUrl?: string;
52
- signupTargetLoginUrl?: string;
53
- oauthLocalPort?: number;
54
- plugins?: {
55
- [k: string]: unknown;
56
- };
57
- packageAliases?: {
58
- [k: string]: string;
59
- };
60
- };
16
+ export type PackageDir = PackageDirSchema;
17
+ export type NamedPackagingDir = PackagePackageDir & NamedDirAdditions;
18
+ export type NamedPackageDir = PackageDir & NamedDirAdditions;
19
+ export type ProjectJson = ConfigContents & ProjectJsonSchema;
61
20
  /**
62
21
  * The sfdx-project.json config object. This file determines if a folder is a valid sfdx project.
63
22
  *
@@ -358,3 +317,7 @@ export declare class SfProject {
358
317
  getPackageIdFromAlias(alias: string): Optional<string>;
359
318
  getAliasesFromPackageId(id: string): string[];
360
319
  }
320
+ /** differentiate between the Base PackageDir (path, maybe default) and the Packaging version (package and maybe a LOT of other fields) by whether is has the `package` property */
321
+ export declare const isPackagingDirectory: (packageDir: PackageDir) => packageDir is PackagePackageDir;
322
+ export declare const isNamedPackagingDirectory: (packageDir: NamedPackageDir) => packageDir is NamedPackagingDir;
323
+ export {};
package/lib/sfProject.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.SfProject = exports.SfProjectJson = void 0;
26
+ exports.isNamedPackagingDirectory = exports.isPackagingDirectory = exports.SfProject = exports.SfProjectJson = void 0;
27
27
  /*
28
28
  * Copyright (c) 2020, salesforce.com, inc.
29
29
  * All rights reserved.
@@ -282,16 +282,7 @@ class SfProjectJson extends configFile_1.ConfigFile {
282
282
  * @param packageDir
283
283
  */
284
284
  addPackageDirectory(packageDir) {
285
- // there is no notion of uniqueness in package directory entries
286
- // so an attempt of matching an existing entry is a bit convoluted
287
- // an entry w/o a package or id is considered a directory entry for which a package has yet to be created
288
- // so first attempt is to find a matching dir entry that where path is the same and id and package are not present
289
- // if that fails, then find a matching dir entry package is present and is same as the new entry
290
- const dirIndex = this.getContents().packageDirectories.findIndex((pd) => {
291
- const withId = pd;
292
- return ((withId.path === packageDir.path && !withId.id && !withId.package) ||
293
- (!!packageDir.package && packageDir.package === withId.package));
294
- });
285
+ const dirIndex = this.getContents().packageDirectories.findIndex(findPackageDir(packageDir));
295
286
  // merge new package dir with existing entry, if present
296
287
  const packageDirEntry = Object.assign({}, dirIndex > -1 ? this.getContents().packageDirectories[dirIndex] : packageDir, packageDir);
297
288
  const modifiedPackagesDirs = dirIndex > -1
@@ -301,6 +292,7 @@ class SfProjectJson extends configFile_1.ConfigFile {
301
292
  [...(this.getContents()?.packageDirectories ?? []), packageDirEntry];
302
293
  this.set('packageDirectories', modifiedPackagesDirs);
303
294
  }
295
+ // keep it because testSetup stubs it!
304
296
  // eslint-disable-next-line class-methods-use-this
305
297
  doesPackageExist(packagePath) {
306
298
  return fs.existsSync(packagePath);
@@ -520,7 +512,9 @@ class SfProject {
520
512
  */
521
513
  getPackageNameFromPath(path) {
522
514
  const packageDir = this.getPackageFromPath(path);
523
- return packageDir ? packageDir.package ?? packageDir.path : undefined;
515
+ if (!packageDir)
516
+ return undefined;
517
+ return (0, exports.isNamedPackagingDirectory)(packageDir) ? packageDir.package : packageDir.path;
524
518
  }
525
519
  /**
526
520
  * Returns the package directory.
@@ -664,4 +658,19 @@ class SfProject {
664
658
  }
665
659
  }
666
660
  exports.SfProject = SfProject;
661
+ /** differentiate between the Base PackageDir (path, maybe default) and the Packaging version (package and maybe a LOT of other fields) by whether is has the `package` property */
662
+ const isPackagingDirectory = (packageDir) => 'package' in packageDir && typeof packageDir.package === 'string';
663
+ exports.isPackagingDirectory = isPackagingDirectory;
664
+ const isNamedPackagingDirectory = (packageDir) => 'package' in packageDir && typeof packageDir.package === 'string';
665
+ exports.isNamedPackagingDirectory = isNamedPackagingDirectory;
666
+ /**
667
+ * there is no notion of uniqueness in package directory entries
668
+ * so an attempt of matching an existing entry is a bit convoluted
669
+ */
670
+ const findPackageDir = (target) => (potentialMatch) =>
671
+ // an entry w/o a package or id is considered a directory entry for which a package has yet to be created
672
+ // find a matching dir entry that where path is the same and id and package are not present
673
+ (potentialMatch.path === target.path && !('id' in potentialMatch) && !(0, exports.isPackagingDirectory)(potentialMatch)) ||
674
+ // if that fails, then find a matching dir entry package is present and is same as the new entry
675
+ ((0, exports.isPackagingDirectory)(target) && (0, exports.isPackagingDirectory)(potentialMatch) && target.package === potentialMatch.package);
667
676
  //# sourceMappingURL=sfProject.js.map
@@ -0,0 +1,7 @@
1
+ /**
2
+ * From the haystack, will find the closest value to the needle
3
+ *
4
+ * @param needle - what the user provided - find results similar to this
5
+ * @param haystack - possible results to search against
6
+ */
7
+ export declare const findSuggestion: (needle: string, haystack: string[]) => string;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.findSuggestion = void 0;
7
+ /*
8
+ * Copyright (c) 2023, salesforce.com, inc.
9
+ * All rights reserved.
10
+ * Licensed under the BSD 3-Clause license.
11
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
12
+ */
13
+ const fast_levenshtein_1 = __importDefault(require("fast-levenshtein"));
14
+ /**
15
+ * From the haystack, will find the closest value to the needle
16
+ *
17
+ * @param needle - what the user provided - find results similar to this
18
+ * @param haystack - possible results to search against
19
+ */
20
+ const findSuggestion = (needle, haystack) => {
21
+ // we'll use this array to keep track of which piece of hay is the closest to the users entered value.
22
+ // keys closer to the index 0 will be a closer guess than keys indexed further from 0
23
+ // an entry at 0 would be a direct match, an entry at 1 would be a single character off, etc.
24
+ const index = [];
25
+ haystack.map((hay) => {
26
+ index[fast_levenshtein_1.default.get(needle, hay)] = hay;
27
+ });
28
+ return index.find((item) => item !== undefined) ?? '';
29
+ };
30
+ exports.findSuggestion = findSuggestion;
31
+ //# sourceMappingURL=findSuggestion.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "7.3.10",
3
+ "version": "7.3.12-qa.0",
4
4
  "description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
5
5
  "main": "lib/index",
6
6
  "types": "lib/index.d.ts",
@@ -53,11 +53,12 @@
53
53
  ],
54
54
  "dependencies": {
55
55
  "@jsforce/jsforce-node": "^3.2.0",
56
- "@salesforce/kit": "^3.1.1",
56
+ "@salesforce/kit": "^3.1.2",
57
57
  "@salesforce/schemas": "^1.9.0",
58
58
  "@salesforce/ts-types": "^2.0.9",
59
59
  "ajv": "^8.15.0",
60
60
  "change-case": "^4.1.2",
61
+ "fast-levenshtein": "^3.0.0",
61
62
  "faye": "^1.4.0",
62
63
  "form-data": "^4.0.0",
63
64
  "js2xmlparser": "^4.0.1",
@@ -75,6 +76,7 @@
75
76
  "@salesforce/ts-sinon": "^1.4.19",
76
77
  "@types/benchmark": "^2.1.5",
77
78
  "@types/chai-string": "^1.4.5",
79
+ "@types/fast-levenshtein": "^0.0.4",
78
80
  "@types/jsonwebtoken": "9.0.6",
79
81
  "@types/proper-lockfile": "^4.1.4",
80
82
  "@types/semver": "^7.5.8",