UNPKG

@salesforce/core

Version:

Core libraries to interact with SFDX projects, orgs, and APIs.

100 lines 3.99 kB
"use strict"; /* * Copyright (c) 2020, salesforce.com, inc. * All rights reserved. * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ Object.defineProperty(exports, "__esModule", { value: true }); exports.matchesAccessToken = exports.sfdxAuthUrlRegex = exports.accessTokenRegex = exports.findUpperCaseKeys = exports.validatePathDoesNotContainInvalidChars = exports.validateSalesforceId = exports.isInternalUrl = exports.validateEmail = exports.validateApiVersion = exports.trimTo15 = void 0; const kit_1 = require("@salesforce/kit"); const ts_types_1 = require("@salesforce/ts-types"); function trimTo15(id) { if (!id) { return undefined; } if (id.length && id.length > 15) { id = id.substring(0, 15); } return id; } exports.trimTo15 = trimTo15; /** * Tests whether an API version matches the format `i.0`. * * @param value The API version as a string. */ const validateApiVersion = (value) => value == null || /^[1-9]\d\.0$/.test(value); exports.validateApiVersion = validateApiVersion; /** * Tests whether an email matches the format `me@my.org` * * @param value The email as a string. */ const validateEmail = (value) => /^[^.][^@]*@[^.]+(\.[^.\s]+)+$/.test(value); exports.validateEmail = validateEmail; /** * * @deprecated use `new SfdcUrl(url).isInternalUrl()` * Tests whether a given url is an internal Salesforce domain * * @param url */ const isInternalUrl = (url) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires const SfdcUrl = require('./sfdcUrl'); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call return new SfdcUrl(url).isInternalUrl(); }; exports.isInternalUrl = isInternalUrl; /** * Tests whether a Salesforce ID is in the correct format, a 15- or 18-character length string with only letters and numbers * * @param value The ID as a string. */ const validateSalesforceId = (value) => /[a-zA-Z0-9]{18}|[a-zA-Z0-9]{15}/.test(value) && (value.length === 15 || value.length === 18); exports.validateSalesforceId = validateSalesforceId; /** * Tests whether a path is in the correct format; the value doesn't include the characters "[", "]", "?", "<", ">", "?", "|" * * @param value The path as a string. */ const validatePathDoesNotContainInvalidChars = (value) => // eslint-disable-next-line no-useless-escape !/[\["\?<>\|\]]+/.test(value); exports.validatePathDoesNotContainInvalidChars = validatePathDoesNotContainInvalidChars; /** * @deprecated * // TODO: move this to a module-scope function in sfProject * Returns the first key within the object that has an upper case first letter. * * @param data The object in which to check key casing. * @param sectionBlocklist properties in the object to exclude from the search. e.g. a blocklist of `["a"]` and data of `{ "a": { "B" : "b"}}` would ignore `B` because it is in the object value under `a`. */ const findUpperCaseKeys = (data, sectionBlocklist = []) => { let key; (0, kit_1.findKey)(data, (val, k) => { if (/^[A-Z]/.test(k)) { key = k; } else if ((0, ts_types_1.isJsonMap)(val)) { if (sectionBlocklist.includes(k)) { return key; } key = (0, exports.findUpperCaseKeys)((0, ts_types_1.asJsonMap)(val)); } return key; }); return key; }; exports.findUpperCaseKeys = findUpperCaseKeys; exports.accessTokenRegex = /(00D\w{12,15})![.\w]*/; exports.sfdxAuthUrlRegex = /force:\/\/([a-zA-Z0-9._-]+):([a-zA-Z0-9._-]*):([a-zA-Z0-9._-]+={0,2})@([a-zA-Z0-9._-]+)/; /** * Tests whether a given string is an access token * * @param value */ const matchesAccessToken = (value) => exports.accessTokenRegex.test(value); exports.matchesAccessToken = matchesAccessToken; //# sourceMappingURL=sfdc.js.map