@salesforce/core-bundle 8.11.4 → 8.12.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.
package/lib/index.d.ts CHANGED
@@ -1612,6 +1612,10 @@ declare module '@salesforce/core-bundle/global' {
1612
1612
  * The preferred global folder in which state is stored.
1613
1613
  */
1614
1614
  static readonly STATE_FOLDER = ".sfdx";
1615
+ /**
1616
+ * Whether the code is running in a web browser.
1617
+ */
1618
+ static get isWeb(): boolean;
1615
1619
  /**
1616
1620
  * The full system path to the global sfdx state folder.
1617
1621
  *
@@ -4985,7 +4989,6 @@ declare module '@salesforce/core-bundle/stateAggregator/accessors/aliasAccessor'
4985
4989
  * if the file doesn't exist, create it empty
4986
4990
  */
4987
4991
  private readFileToAliasStore;
4988
- private saveAliasStoreToFile;
4989
4992
  }
4990
4993
  export const getFileLocation: () => string;
4991
4994
 
@@ -5172,6 +5175,7 @@ declare module '@salesforce/core-bundle/status/myDomainResolver' {
5172
5175
  * executing the dns loookup.
5173
5176
  */
5174
5177
  resolve(): Promise<string>;
5178
+ /** @deprecated there is nothing using this in forcedotcom, salesforcecli, or public github search */
5175
5179
  getCnames(): Promise<string[]>;
5176
5180
  /**
5177
5181
  * Used to initialize asynchronous components.
@@ -6298,6 +6302,7 @@ declare module '@salesforce/core-bundle/util/internal' {
6298
6302
 
6299
6303
  }
6300
6304
  declare module '@salesforce/core-bundle/util/lockRetryOptions' {
6305
+ import fs from 'node:fs';
6301
6306
  export const lockOptions: {
6302
6307
  stale: number;
6303
6308
  };
@@ -6307,6 +6312,7 @@ declare module '@salesforce/core-bundle/util/lockRetryOptions' {
6307
6312
  maxTimeout: number;
6308
6313
  factor: number;
6309
6314
  };
6315
+ fs: typeof fs;
6310
6316
  stale: number;
6311
6317
  };
6312
6318
 
@@ -6449,6 +6455,7 @@ declare module '@salesforce/core-bundle/util/structuredWriter' {
6449
6455
 
6450
6456
  }
6451
6457
  declare module '@salesforce/core-bundle/util/time' {
6458
+ /** using globalThis.performance instead importing from node:perf_hooks so it works in browser */
6452
6459
  export const nowBigInt: () => bigint;
6453
6460
 
6454
6461
  }
package/lib/index.js CHANGED
@@ -7218,6 +7218,12 @@ var require_global = __commonJS({
7218
7218
  * The preferred global folder in which state is stored.
7219
7219
  */
7220
7220
  static STATE_FOLDER = _Global.SFDX_STATE_FOLDER;
7221
+ /**
7222
+ * Whether the code is running in a web browser.
7223
+ */
7224
+ static get isWeb() {
7225
+ return "window" in globalThis;
7226
+ }
7221
7227
  /**
7222
7228
  * The full system path to the global sfdx state folder.
7223
7229
  *
@@ -7658,7 +7664,7 @@ var require_logger = __commonJS({
7658
7664
  * Gets the name of this logger.
7659
7665
  */
7660
7666
  getName() {
7661
- return this.pinoLogger.bindings().name ?? "";
7667
+ return (this.pinoLogger?.bindings ? this.pinoLogger.bindings().name : "") ?? "";
7662
7668
  }
7663
7669
  /**
7664
7670
  * Gets the current level of this logger.
@@ -7826,7 +7832,7 @@ var require_logger = __commonJS({
7826
7832
  // write to a rotating file
7827
7833
  target: "pino/file",
7828
7834
  options: {
7829
- destination: path.join(global_12.Global.SF_DIR, `sf-${rotator.get(logRotationPeriod) ?? rotator.get("1d")}.log`),
7835
+ destination: path.join(global_12.Global.SF_DIR, `sf-${(0, ts_types_1.ensureString)(rotator.get(logRotationPeriod)) ?? rotator.get("1d")}.log`),
7830
7836
  mkdir: true,
7831
7837
  level
7832
7838
  }
@@ -10344,12 +10350,18 @@ var require_retry_promise = __commonJS({
10344
10350
  var require_lockRetryOptions = __commonJS({
10345
10351
  "lib/util/lockRetryOptions.js"(exports2) {
10346
10352
  "use strict";
10353
+ var __importDefault3 = exports2 && exports2.__importDefault || function(mod) {
10354
+ return mod && mod.__esModule ? mod : { "default": mod };
10355
+ };
10347
10356
  Object.defineProperty(exports2, "__esModule", { value: true });
10348
10357
  exports2.lockRetryOptions = exports2.lockOptions = void 0;
10358
+ var node_fs_1 = __importDefault3(require("node:fs"));
10349
10359
  exports2.lockOptions = { stale: 1e4 };
10350
10360
  exports2.lockRetryOptions = {
10351
10361
  ...exports2.lockOptions,
10352
- retries: { retries: 10, maxTimeout: 1e3, factor: 2 }
10362
+ retries: { retries: 10, maxTimeout: 1e3, factor: 2 },
10363
+ fs: node_fs_1.default
10364
+ // lockfile supports injectable fs, which is needed for browser use
10353
10365
  };
10354
10366
  }
10355
10367
  });
@@ -10401,11 +10413,10 @@ var require_fileLocking = __commonJS({
10401
10413
  } catch (err) {
10402
10414
  throw sfError_12.SfError.wrap(err);
10403
10415
  }
10404
- const unlock = await (0, proper_lockfile_1.lock)(filePath, { ...lockRetryOptions_1.lockRetryOptions, realpath: false });
10416
+ const unlock = await (0, proper_lockfile_1.lock)(filePath, { ...lockRetryOptions_1.lockRetryOptions, realpath: false, fs });
10405
10417
  return {
10406
10418
  writeAndUnlock: async (data) => {
10407
- const logger = await logger_12.Logger.child("fileLocking.writeAndUnlock");
10408
- logger.debug(`Writing to file: ${filePath}`);
10419
+ (await logger_12.Logger.child("fileLocking.writeAndUnlock")).debug(`Writing to file: ${filePath}`);
10409
10420
  try {
10410
10421
  await fs.promises.writeFile(filePath, data);
10411
10422
  } finally {
@@ -10422,7 +10433,7 @@ var require_fileLocking = __commonJS({
10422
10433
  } catch (err) {
10423
10434
  throw sfError_12.SfError.wrap(err);
10424
10435
  }
10425
- const unlock = (0, proper_lockfile_1.lockSync)(filePath, { ...lockRetryOptions_1.lockOptions, realpath: false });
10436
+ const unlock = (0, proper_lockfile_1.lockSync)(filePath, { ...lockRetryOptions_1.lockOptions, realpath: false, fs });
10426
10437
  return {
10427
10438
  writeAndUnlock: (data) => {
10428
10439
  const logger = logger_12.Logger.childFromRoot("fileLocking.writeAndUnlock");
@@ -12319,7 +12330,7 @@ var require_package2 = __commonJS({
12319
12330
  "package.json"(exports2, module2) {
12320
12331
  module2.exports = {
12321
12332
  name: "@salesforce/core-bundle",
12322
- version: "8.11.4",
12333
+ version: "8.12.0",
12323
12334
  description: "Core libraries to interact with SFDX projects, orgs, and APIs.",
12324
12335
  main: "lib/index",
12325
12336
  types: "lib/index.d.ts",
@@ -12380,7 +12391,7 @@ var require_package2 = __commonJS({
12380
12391
  "@salesforce/ts-sinon": "^1.4.30",
12381
12392
  "@types/benchmark": "^2.1.5",
12382
12393
  "@types/fast-levenshtein": "^0.0.4",
12383
- "@types/jsonwebtoken": "9.0.7",
12394
+ "@types/jsonwebtoken": "9.0.9",
12384
12395
  "@types/proper-lockfile": "^4.1.4",
12385
12396
  "@types/semver": "^7.5.8",
12386
12397
  benchmark: "^2.1.4",
@@ -13183,6 +13194,9 @@ var require_keyChain = __commonJS({
13183
13194
  return keyChainImpl_1.keyChainImpl.generic_unix;
13184
13195
  }
13185
13196
  }
13197
+ } else if (platform === "browser") {
13198
+ logger.debug(`platform: ${platform}. Using generic keychain.`);
13199
+ return keyChainImpl_1.keyChainImpl.generic_unix;
13186
13200
  } else {
13187
13201
  throw messages.createError("unsupportedOperatingSystemError", [platform]);
13188
13202
  }
@@ -13633,8 +13647,7 @@ var require_time2 = __commonJS({
13633
13647
  "use strict";
13634
13648
  Object.defineProperty(exports2, "__esModule", { value: true });
13635
13649
  exports2.nowBigInt = void 0;
13636
- var node_perf_hooks_1 = require("node:perf_hooks");
13637
- var nowBigInt = () => BigInt((node_perf_hooks_1.performance.now() + node_perf_hooks_1.performance.timeOrigin) * 1e6);
13650
+ var nowBigInt = () => BigInt((globalThis.performance.now() + globalThis.performance.timeOrigin) * 1e6);
13638
13651
  exports2.nowBigInt = nowBigInt;
13639
13652
  }
13640
13653
  });
@@ -14285,7 +14298,7 @@ var require_configFile = __commonJS({
14285
14298
  async write() {
14286
14299
  const lockResponse = await (0, fileLocking_12.lockInit)(this.getPath());
14287
14300
  try {
14288
- const fileTimestamp = (await fs.promises.stat(this.getPath(), { bigint: true })).mtimeNs;
14301
+ const fileTimestamp = await getNsTimeStamp(this.getPath());
14289
14302
  const fileContents = (0, kit_1.parseJsonMap)(await fs.promises.readFile(this.getPath(), "utf8"), this.getPath());
14290
14303
  this.logAndMergeContents(fileTimestamp, fileContents);
14291
14304
  } catch (err) {
@@ -14303,7 +14316,7 @@ var require_configFile = __commonJS({
14303
14316
  writeSync() {
14304
14317
  const lockResponse = (0, fileLocking_12.lockInitSync)(this.getPath());
14305
14318
  try {
14306
- const fileTimestamp = fs.statSync(this.getPath(), { bigint: true }).mtimeNs;
14319
+ const fileTimestamp = getNsTimeStampSync(this.getPath());
14307
14320
  const fileContents = (0, kit_1.parseJsonMap)(fs.readFileSync(this.getPath(), "utf8"), this.getPath());
14308
14321
  this.logAndMergeContents(fileTimestamp, fileContents);
14309
14322
  } catch (err) {
@@ -14420,6 +14433,9 @@ var require_configFile = __commonJS({
14420
14433
  }
14421
14434
  };
14422
14435
  exports2.ConfigFile = ConfigFile;
14436
+ var getNsTimeStamp = async (filePath) => getNsTimeStampFromStatus(await fs.promises.stat(filePath, { bigint: true }));
14437
+ var getNsTimeStampSync = (filePath) => getNsTimeStampFromStatus(fs.statSync(filePath, { bigint: true }));
14438
+ var getNsTimeStampFromStatus = (stats) => stats.mtimeNs ?? BigInt(stats.mtimeMs) * BigInt(1e6);
14423
14439
  }
14424
14440
  });
14425
14441
 
@@ -15838,11 +15854,10 @@ var require_aliasAccessor = __commonJS({
15838
15854
  var node_path_1 = require("node:path");
15839
15855
  var node_os_1 = require("node:os");
15840
15856
  var promises_1 = require("node:fs/promises");
15841
- var proper_lockfile_1 = require_proper_lockfile();
15842
15857
  var kit_1 = require_lib2();
15843
15858
  var global_12 = require_global();
15844
15859
  var sfError_12 = require_sfError();
15845
- var lockRetryOptions_1 = require_lockRetryOptions();
15860
+ var fileLocking_12 = require_fileLocking();
15846
15861
  exports2.DEFAULT_GROUP = "orgs";
15847
15862
  exports2.FILENAME = "alias.json";
15848
15863
  var AliasAccessor = class extends kit_1.AsyncOptionalCreatable {
@@ -15916,18 +15931,20 @@ var require_aliasAccessor = __commonJS({
15916
15931
  * @param entity the aliasable entity that's being aliased
15917
15932
  */
15918
15933
  async setAndSave(alias, entity) {
15919
- await this.readFileToAliasStore(true);
15934
+ const lockResponse = await (0, fileLocking_12.lockInit)(this.fileLocation);
15935
+ await this.readFileToAliasStore();
15920
15936
  this.aliasStore.set(alias, getNameOf(entity));
15921
- return this.saveAliasStoreToFile();
15937
+ return lockResponse.writeAndUnlock(aliasStoreToRawFileContents(this.aliasStore));
15922
15938
  }
15923
15939
  /**
15924
15940
  * Unset the given alias(es). Writes to the file
15925
15941
  *
15926
15942
  */
15927
15943
  async unsetAndSave(alias) {
15928
- await this.readFileToAliasStore(true);
15944
+ const lockResponse = await (0, fileLocking_12.lockInit)(this.fileLocation);
15945
+ await this.readFileToAliasStore();
15929
15946
  this.aliasStore.delete(alias);
15930
- return this.saveAliasStoreToFile();
15947
+ return lockResponse.writeAndUnlock(aliasStoreToRawFileContents(this.aliasStore));
15931
15948
  }
15932
15949
  /**
15933
15950
  * Unset all the aliases for the given array of entity.
@@ -15935,9 +15952,10 @@ var require_aliasAccessor = __commonJS({
15935
15952
  * @param entity the aliasable entity for which you want to unset all aliases
15936
15953
  */
15937
15954
  async unsetValuesAndSave(aliasees) {
15938
- await this.readFileToAliasStore(true);
15955
+ const lockResponse = await (0, fileLocking_12.lockInit)(this.fileLocation);
15956
+ await this.readFileToAliasStore();
15939
15957
  (0, kit_1.ensureArray)(aliasees).flatMap((a) => this.getAll(a)).map((a) => this.aliasStore.delete(a));
15940
- return this.saveAliasStoreToFile();
15958
+ return lockResponse.writeAndUnlock(aliasStoreToRawFileContents(this.aliasStore));
15941
15959
  }
15942
15960
  /**
15943
15961
  * Returns true if the provided alias exists
@@ -15955,38 +15973,28 @@ var require_aliasAccessor = __commonJS({
15955
15973
  * go to the fileSystem and read the file, storing a copy in the class's store
15956
15974
  * if the file doesn't exist, create it empty
15957
15975
  */
15958
- async readFileToAliasStore(useLock = false) {
15959
- if (useLock) {
15960
- await (0, proper_lockfile_1.lock)(this.fileLocation, lockRetryOptions_1.lockRetryOptions);
15961
- }
15976
+ async readFileToAliasStore() {
15962
15977
  try {
15963
15978
  this.aliasStore = fileContentsRawToAliasStore(await (0, promises_1.readFile)(this.fileLocation, "utf-8"));
15964
15979
  } catch (e) {
15965
15980
  if (e instanceof Error && "code" in e && typeof e.code === "string" && ["ENOENT", "ENOTDIR"].includes(e.code)) {
15966
- this.aliasStore = /* @__PURE__ */ new Map();
15967
15981
  await (0, promises_1.mkdir)((0, node_path_1.dirname)(this.fileLocation), { recursive: true });
15968
- await this.saveAliasStoreToFile();
15969
- return;
15982
+ this.aliasStore = /* @__PURE__ */ new Map();
15983
+ return (0, promises_1.writeFile)(this.fileLocation, aliasStoreToRawFileContents(this.aliasStore));
15970
15984
  }
15971
- if (useLock)
15972
- return unlockIfLocked(this.fileLocation);
15973
15985
  throw e;
15974
15986
  }
15975
15987
  }
15976
- async saveAliasStoreToFile() {
15977
- await (0, promises_1.writeFile)(this.fileLocation, aliasStoreToRawFileContents(this.aliasStore));
15978
- return unlockIfLocked(this.fileLocation);
15979
- }
15980
15988
  };
15981
15989
  exports2.AliasAccessor = AliasAccessor;
15982
15990
  var getNameOf = (entity) => {
15983
15991
  if (typeof entity === "string")
15984
15992
  return entity;
15985
- const aliaseeName = entity.username;
15986
- if (!aliaseeName) {
15993
+ const { username } = entity;
15994
+ if (!username) {
15987
15995
  throw new sfError_12.SfError(`Invalid aliasee, it must contain a user or username property: ${JSON.stringify(entity)}`);
15988
15996
  }
15989
- return aliaseeName;
15997
+ return username;
15990
15998
  };
15991
15999
  var fileContentsRawToAliasStore = (contents) => {
15992
16000
  const fileContents = JSON.parse(contents);
@@ -15995,16 +16003,6 @@ var require_aliasAccessor = __commonJS({
15995
16003
  var aliasStoreToRawFileContents = (aliasStore) => JSON.stringify({ [exports2.DEFAULT_GROUP]: Object.fromEntries(Array.from(aliasStore.entries())) });
15996
16004
  var getFileLocation = () => (0, node_path_1.join)((0, node_os_1.homedir)(), global_12.Global.SFDX_STATE_FOLDER, exports2.FILENAME);
15997
16005
  exports2.getFileLocation = getFileLocation;
15998
- var unlockIfLocked = async (fileLocation) => {
15999
- try {
16000
- await (0, proper_lockfile_1.unlock)(fileLocation);
16001
- } catch (e) {
16002
- if (errorIsNotAcquired(e))
16003
- return;
16004
- throw e;
16005
- }
16006
- };
16007
- var errorIsNotAcquired = (e) => e instanceof Error && "code" in e && e.code === "ENOTACQUIRED";
16008
16006
  }
16009
16007
  });
16010
16008
 
@@ -83829,6 +83827,7 @@ var require_myDomainResolver = __commonJS({
83829
83827
  var kit_1 = require_lib2();
83830
83828
  var logger_12 = require_logger();
83831
83829
  var sfdcUrl_12 = require_sfdcUrl();
83830
+ var global_12 = require_global();
83832
83831
  var pollingClient_12 = require_pollingClient();
83833
83832
  var DNS_TIMEOUT = Math.max(3, new kit_1.Env().getNumber("SFDX_DNS_TIMEOUT", 3));
83834
83833
  var DNS_RETRY_FREQ = Math.max(1, new kit_1.Env().getNumber("SFDX_DNS_RETRY_FREQUENCY", 1));
@@ -83865,6 +83864,10 @@ var require_myDomainResolver = __commonJS({
83865
83864
  this.logger.debug("SF_DISABLE_DNS_CHECK set to true. Skipping DNS check...");
83866
83865
  return this.options.url.host;
83867
83866
  }
83867
+ if (global_12.Global.isWeb) {
83868
+ this.logger.debug("Web browser detected. Skipping DNS check...");
83869
+ return this.options.url.host;
83870
+ }
83868
83871
  const self2 = this;
83869
83872
  const pollingOptions = {
83870
83873
  async poll() {
@@ -83900,6 +83903,7 @@ var require_myDomainResolver = __commonJS({
83900
83903
  const client = await pollingClient_12.PollingClient.create(pollingOptions);
83901
83904
  return (0, ts_types_1.ensureString)(await client.subscribe());
83902
83905
  }
83906
+ /** @deprecated there is nothing using this in forcedotcom, salesforcecli, or public github search */
83903
83907
  async getCnames() {
83904
83908
  try {
83905
83909
  await this.resolve();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core-bundle",
3
- "version": "8.11.4",
3
+ "version": "8.12.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",
@@ -61,7 +61,7 @@
61
61
  "@salesforce/ts-sinon": "^1.4.30",
62
62
  "@types/benchmark": "^2.1.5",
63
63
  "@types/fast-levenshtein": "^0.0.4",
64
- "@types/jsonwebtoken": "9.0.7",
64
+ "@types/jsonwebtoken": "9.0.9",
65
65
  "@types/proper-lockfile": "^4.1.4",
66
66
  "@types/semver": "^7.5.8",
67
67
  "benchmark": "^2.1.4",