@salesforce/core 7.3.10 → 7.3.12

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.
@@ -1,5 +1,7 @@
1
1
  import { AnyJson } from '@salesforce/ts-types';
2
- type callback = (data: any) => Promise<void>;
2
+ export type callback = (data: any) => Promise<void>;
3
+ type ListenerMap = Map<string, callback>;
4
+ export type UniqueListenerMap = Map<string, ListenerMap>;
3
5
  /**
4
6
  * An asynchronous event listener and emitter that follows the singleton pattern. The singleton pattern allows lifecycle
5
7
  * events to be emitted from deep within a library and still be consumed by any other library or tool. It allows other
@@ -92,4 +94,5 @@ export declare class Lifecycle {
92
94
  */
93
95
  emit<T = AnyJson>(eventName: string, data: T): Promise<void>;
94
96
  }
97
+ export declare const cloneUniqueListeners: (uniqueListeners: UniqueListenerMap) => UniqueListenerMap;
95
98
  export {};
@@ -29,7 +29,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
29
29
  return result;
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.Lifecycle = void 0;
32
+ exports.cloneUniqueListeners = exports.Lifecycle = void 0;
33
33
  const semver_1 = require("semver");
34
34
  // needed for TS to not put everything inside /lib/src
35
35
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -102,8 +102,8 @@ class Lifecycle {
102
102
  (0, semver_1.compare)(global.salesforceCoreLifecycle.version(), Lifecycle.staticVersion()) === -1) {
103
103
  const oldInstance = global.salesforceCoreLifecycle;
104
104
  // use the newer version and transfer any listeners from the old version
105
- // object spread keeps them from being references
106
- global.salesforceCoreLifecycle = new Lifecycle({ ...oldInstance.listeners }, oldInstance.uniqueListeners);
105
+ // object spread and the clone fn keep them from being references
106
+ global.salesforceCoreLifecycle = new Lifecycle({ ...oldInstance.listeners }, (0, exports.cloneUniqueListeners)(oldInstance.uniqueListeners));
107
107
  // clean up any listeners on the old version
108
108
  Object.keys(oldInstance.listeners).map((eventName) => {
109
109
  oldInstance.removeAllListeners(eventName);
@@ -232,4 +232,7 @@ class Lifecycle {
232
232
  }
233
233
  }
234
234
  exports.Lifecycle = Lifecycle;
235
+ const cloneListeners = (listeners) => new Map(Array.from(listeners.entries()));
236
+ const cloneUniqueListeners = (uniqueListeners) => new Map(Array.from(uniqueListeners.entries()).map(([key, value]) => [key, cloneListeners(value)]));
237
+ exports.cloneUniqueListeners = cloneUniqueListeners;
235
238
  //# sourceMappingURL=lifecycleEvents.js.map
@@ -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);
@@ -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",
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",