UNPKG

3.26 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright (c) 2020, salesforce.com, inc.
4 * All rights reserved.
5 * Licensed under the BSD 3-Clause license.
6 * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7 */
8Object.defineProperty(exports, "__esModule", { value: true });
9exports.sfdc = void 0;
10const kit_1 = require("@salesforce/kit");
11const ts_types_1 = require("@salesforce/ts-types");
12const sfdcUrl_1 = require("./sfdcUrl");
13exports.sfdc = {
14 /**
15 * Converts an 18 character Salesforce ID to 15 characters.
16 *
17 * @param id The id to convert.
18 */
19 trimTo15: (id) => {
20 if (id && id.length && id.length > 15) {
21 id = id.substring(0, 15);
22 }
23 return id;
24 },
25 /**
26 * Tests whether an API version matches the format `i.0`.
27 *
28 * @param value The API version as a string.
29 */
30 validateApiVersion: (value) => {
31 return value == null || /^[1-9]\d\.0$/.test(value);
32 },
33 /**
34 * Tests whether an email matches the format `me@my.org`
35 *
36 * @param value The email as a string.
37 */
38 validateEmail: (value) => {
39 return /^[^.][^@]*@[^.]+(\.[^.\s]+)+$/.test(value);
40 },
41 /**
42 * Tests whether a Salesforce ID is in the correct format, a 15- or 18-character length string with only letters and numbers
43 *
44 * @param value The ID as a string.
45 */
46 validateSalesforceId: (value) => {
47 return /[a-zA-Z0-9]{18}|[a-zA-Z0-9]{15}/.test(value) && (value.length === 15 || value.length === 18);
48 },
49 /**
50 * Tests whether a path is in the correct format; the value doesn't include the characters "[", "]", "?", "<", ">", "?", "|"
51 *
52 * @param value The path as a string.
53 */
54 validatePathDoesNotContainInvalidChars: (value) => {
55 // eslint-disable-next-line no-useless-escape
56 return !/[\["\?<>\|\]]+/.test(value);
57 },
58 /**
59 * Returns the first key within the object that has an upper case first letter.
60 *
61 * @param data The object in which to check key casing.
62 * @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`.
63 */
64 findUpperCaseKeys: (data, sectionBlocklist = []) => {
65 let key;
66 (0, kit_1.findKey)(data, (val, k) => {
67 if (k.substr(0, 1) === k.substr(0, 1).toUpperCase()) {
68 key = k;
69 }
70 else if ((0, ts_types_1.isJsonMap)(val)) {
71 if (sectionBlocklist.includes(k)) {
72 return key;
73 }
74 key = exports.sfdc.findUpperCaseKeys((0, ts_types_1.asJsonMap)(val));
75 }
76 return key;
77 });
78 return key;
79 },
80 /**
81 * Tests whether a given string is an access token
82 *
83 * @param value
84 */
85 matchesAccessToken: (value) => {
86 return /^(00D\w{12,15})![.\w]*$/.test(value);
87 },
88 /**
89 * Tests whether a given url is an internal Salesforce domain
90 *
91 * @param url
92 */
93 isInternalUrl: (url) => new sfdcUrl_1.SfdcUrl(url).isInternalUrl(),
94};
95//# sourceMappingURL=sfdc.js.map
\No newline at end of file