Options
All
  • Public
  • Public/Protected
  • All
Menu

@salesforce/core

Index

Type aliases

ConfigContents

ConfigContents: Dictionary<ConfigValue>

The type of content a config stores.

ConfigEntry

ConfigEntry: [string, ConfigValue]

The type of entries in a config store defined by the key and value type of ConfigContents.

ConfigValue

ConfigValue: AnyJson

The allowed types stored in a config store.

ConnectionOptions

ConnectionOptions: AuthFields & object

Options for Connection.

DecipherCallback

DecipherCallback: function

Returns the intended type of the object to return. This is implementation specific.

param

A buffer containing the decrypted secret.

Type declaration

    • (buffer: Buffer): T
    • Parameters

      • buffer: Buffer

      Returns T

FieldValue

FieldValue: string | number | boolean

All possible field value types.

FsIfc

FsIfc: Pick<"fs", "statSync">

KeyChain

KeyChain: GenericUnixKeychainAccess | GenericWindowsKeychainAccess | KeychainAccess

LoaderFunction

LoaderFunction: function

A loader function to return messages.

param

The local set by the framework.

Type declaration

LoggerLevelValue

LoggerLevelValue: LoggerLevel | number

Any numeric Logger level.

RefreshFn

RefreshFn: function

A function to update a refresh token when the access token is expired.

Type declaration

    • (conn: Connection, callback: function): Promise<void>
    • Parameters

      • conn: Connection
      • callback: function
          • (err: Nullable<Error>, accessToken?: undefined | string, res?: undefined | object): Promise<void>
          • Parameters

            • err: Nullable<Error>
            • Optional accessToken: undefined | string
            • Optional res: undefined | object

            Returns Promise<void>

      Returns Promise<void>

Serializer

Serializer: function

A Bunyan Serializer function.

param

The input to be serialized. See Bunyan Serializers API

Type declaration

    • (input: any): any
    • Parameters

      • input: any

      Returns any

StreamProcessor

StreamProcessor: function

Function type for processing messages

Type declaration

Tokens

Tokens: Array<string | boolean | number | null | undefined>

UserFields

UserFields: object

Required fields type needed to represent a Salesforce User object.

See https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_user.htm

Type declaration

Variables

Const testSetup

testSetup: _testSetup = once(_testSetup)

Use to mock out different pieces of sfdx-core to make testing easier. This will mock out logging to a file, config file reading and writing, local and global path resolution, and http request using connection (soon).

// In a mocha tests
import testSetup from '@salesforce/core/lib/testSetup';

const $$ = testSetup();

describe(() => {
 it('test', () => {
   // Stub out your own method
   $$.SANDBOX.stub(MyClass.prototype, 'myMethod').returnsFake(() => {});

   // Set the contents that is used when aliases are read. Same for all config files.
   $$.configStubs.Aliases = { contents: { 'myTestAlias': 'user@company.com' } };

   // Will use the contents set above.
   const username = Aliases.fetch('myTestAlias');
   expect(username).to.equal('user@company.com');
 });
});

Const unexpectedResult

unexpectedResult: SfdxError = new SfdxError('This code was expected to fail', 'UnexpectedResult')

A pre-canned error for try/catch testing.

See shouldThrow

Functions

shouldThrow

  • shouldThrow(f: Promise<unknown>): Promise<never>
  • Use for this testing pattern: ` try { await call() assert.fail('this should never happen'); } catch (e) { ... }

    Just do this

    try { await shouldThrow(call()); // If this succeeds unexpectedResultError is thrown. } catch(e) { ... } `

    Parameters

    • f: Promise<unknown>

      The async function that is expected to throw.

    Returns Promise<never>

Object literals

Const REQUIRED_FIELDS

REQUIRED_FIELDS: object

A Map of Required Salesforce User fields.

alias

alias: string = "alias"

email

email: string = "email"

emailEncodingKey

emailEncodingKey: string = "emailEncodingKey"

id

id: string = "id"

languageLocaleKey

languageLocaleKey: string = "languageLocaleKey"

lastName

lastName: string = "lastName"

localeSidKey

localeSidKey: string = "localeSidKey"

profileId

profileId: string = "profileId"

timeZoneSidKey

timeZoneSidKey: string = "timeZoneSidKey"

username

username: string = "username"

Const SFDX_HTTP_HEADERS

SFDX_HTTP_HEADERS: object

content-type

content-type: string = "application/json"

user-agent

user-agent: string = clientId

Const fs

fs: object

DEFAULT_USER_DIR_MODE

DEFAULT_USER_DIR_MODE: string = "700"

The default file system mode to use when creating directories.

DEFAULT_USER_FILE_MODE

DEFAULT_USER_FILE_MODE: string = "600"

The default file system mode to use when creating files.

access

access: __promisify__ = promisify(fsLib.access)

Promisified version of fsLib.access.

constants

constants: constants = fsLib.constants

A convenience reference to https://nodejs.org/api/fsLib.html#fs_fs_constants to reduce the need to import multiple fs modules.

open

open: __promisify__ = promisify(fsLib.open)

Promisified version of fsLib.open.

readFile

readFile: __promisify__ = promisify(fsLib.readFile)

Promisified version of fsLib.readFile.

readdir

readdir: __promisify__ = promisify(fsLib.readdir)

Promisified version of fsLib.readdir.

rmdir

rmdir: __promisify__ = promisify(fsLib.rmdir)

Promisified version of fsLib.rmdir.

stat

stat: __promisify__ = promisify(fsLib.stat)

Promisified version of fsLib.stat.

unlink

unlink: __promisify__ = promisify(fsLib.unlink)

Promisified version of fsLib.unlink.

writeFile

writeFile: __promisify__ = promisify(fsLib.writeFile)

Promisified version of fsLib.writeFile.

mkdirp

  • mkdirp(folderPath: string, mode?: string | any): Promise<void>
  • Promisified version of mkdirp.

    Parameters

    • folderPath: string
    • Optional mode: string | any

    Returns Promise<void>

readJson

  • readJson(jsonPath: string, throwOnEmpty?: undefined | false | true): Promise<AnyJson>
  • Read a file and convert it to JSON. Returns the contents of the file as a JSON object

    Parameters

    • jsonPath: string

      The path of the file.

    • Optional throwOnEmpty: undefined | false | true

      Whether to throw an error if the JSON file is empty.

    Returns Promise<AnyJson>

readJsonMap

  • readJsonMap(jsonPath: string, throwOnEmpty?: undefined | false | true): Promise<JsonMap>
  • Read a file and convert it to JSON, throwing an error if the parsed contents are not a JsonMap.

    Parameters

    • jsonPath: string

      The path of the file.

    • Optional throwOnEmpty: undefined | false | true

      Whether to throw an error if the JSON file is empty.

    Returns Promise<JsonMap>

remove

  • remove(dirPath: string): Promise<void>
  • Deletes a folder recursively, removing all descending files and folders.

    Throws PathIsNullOrUndefined The path is not defined. Throws DirMissingOrNoAccess The folder or any sub-folder is missing or has no access.

    Parameters

    • dirPath: string

      The path to remove.

    Returns Promise<void>

traverseForFile

  • traverseForFile(dir: string, file: string): Promise<Optional<string>>
  • Searches a file path in an ascending manner (until reaching the filesystem root) for the first occurrence a specific file name. Resolves with the directory path containing the located file, or null if the file was not found.

    Parameters

    • dir: string

      The directory path in which to start the upward search.

    • file: string

      The file name to look for.

    Returns Promise<Optional<string>>

writeJson

  • writeJson(jsonPath: string, data: AnyJson): Promise<void>
  • Convert a JSON-compatible object to a string and write it to a file.

    Parameters

    • jsonPath: string

      The path of the file to write.

    • data: AnyJson

      The JSON object to write.

    Returns Promise<void>

Const sfdc

sfdc: object

findUpperCaseKeys

  • findUpperCaseKeys(data?: JsonMap, sectionBlacklist?: string[]): Optional<string>
  • Returns the first key within the object that has an upper case first letter.

    Parameters

    • Optional data: JsonMap

      The object in which to check key casing.

    • Default value sectionBlacklist: string[] = []

      properties in the object to exclude from the search. e.g. a blacklist of ["a"] and data of { "a": { "B" : "b"}} would ignore B because it is in the object value under a.

    Returns Optional<string>

isSalesforceDomain

  • isSalesforceDomain(urlString: string): boolean
  • Returns true if a provided URL contains a Salesforce owned domain.

    Parameters

    • urlString: string

      The URL to inspect.

    Returns boolean

trimTo15

  • trimTo15(id?: undefined | string): Optional<string>
  • Converts an 18 character Salesforce ID to 15 characters.

    Parameters

    • Optional id: undefined | string

      The id to convert.

    Returns Optional<string>

validateApiVersion

  • validateApiVersion(value: string): boolean
  • Tests whether an API version matches the format i.0.

    Parameters

    • value: string

      The API version as a string.

    Returns boolean

validateEmail

  • validateEmail(value: string): boolean
  • Tests whether an email matches the format `me@my.org`

    Parameters

    • value: string

      The email as a string.

    Returns boolean

validatePathDoesNotContainInvalidChars

  • validatePathDoesNotContainInvalidChars(value: string): boolean
  • Tests whether a path is in the correct format; the value doesn't include the characters "[", "]", "?", "<", ">", "?", "|"

    Parameters

    • value: string

      The path as a string.

    Returns boolean

validateSalesforceId

  • validateSalesforceId(value: string): boolean
  • Tests whether a Salesforce ID is in the correct format, a 15- or 18-character length string with only letters and numbers

    Parameters

    • value: string

      The ID as a string.

    Returns boolean