Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getSchemaStoreMatchingSchemas() {
return xhr({ url: JSON_SCHEMASTORE_URL }).then(response => {
const languageSettings = {
schemas: []
};
// Parse the schema store catalog as JSON
const schemas = JSON.parse(response.responseText);
for (const schemaIndex in schemas.schemas) {
const schema = schemas.schemas[schemaIndex];
if (schema && schema.fileMatch) {
for (const fileMatch in schema.fileMatch) {
const currFileMatch = schema.fileMatch[fileMatch];
// If the schema is for files with a YAML extension, save the schema association
if (currFileMatch.indexOf('.yml') !== -1 || currFileMatch.indexOf('.yaml') !== -1) {
languageSettings.schemas.push({ uri: schema.url, fileMatch: [currFileMatch] });
protected async resovleSchema(url: string): Promise {
const uri = URI.parse(url);
if (uri.scheme === 'file') {
return new Promise((resolve, reject) => {
// eslint-disable-next-line security/detect-non-literal-fs-filename
fs.readFile(uri.fsPath, 'UTF-8', (err, result) => {
err ? reject('') : resolve(result.toString());
});
});
}
try {
const response = await xhr({ url, followRedirects: 5 });
return response.responseText;
} catch (error) {
return Promise.reject(error.responseText || getErrorStatusDescription(error.status) || error.toString());
}
}
protected async resovleSchema(url: string): Promise {
const uri = URI.parse(url);
if (uri.scheme === 'file') {
return new Promise((resolve, reject) => {
// eslint-disable-next-line security/detect-non-literal-fs-filename
fs.readFile(uri.fsPath, 'UTF-8', (err, result) => {
err ? reject('') : resolve(result.toString());
});
});
}
try {
const response = await xhr({ url, followRedirects: 5 });
return response.responseText;
} catch (error) {
return Promise.reject(error.responseText || getErrorStatusDescription(error.status) || error.toString());
}
}
async resovleSchema(url) {
const uri = vscode_uri_1.default.parse(url);
if (uri.scheme === 'file') {
return new Promise((resolve, reject) => {
fs.readFile(uri.fsPath, 'UTF-8', (err, result) => {
err ? reject('') : resolve(result.toString());
});
});
}
try {
const response = await request_light_1.xhr({ url, followRedirects: 5 });
return response.responseText;
} catch (error) {
return Promise.reject(
error.responseText || request_light_1.getErrorStatusDescription(error.status) || error.toString()
);
}
}
// protected resolveCompletion(item: CompletionItem): Thenable {
protected async resolveSchema(url: string): Promise {
const uri = URI.parse(url);
if (uri.scheme === 'file') {
return new Promise((resolve, reject) => {
// eslint-disable-next-line security/detect-non-literal-fs-filename
readFile(uri.fsPath, 'UTF-8', (err, result) => {
err ? reject('') : resolve(result.toString());
});
});
}
try {
const response = await xhr({ url, followRedirects: 5 });
return response.responseText;
} catch (error) {
return Promise.reject(error.responseText || getErrorStatusDescription(error.status) || error.toString());
}
}
export default async (
uri: string,
options: XHROptions = {}
): Promise => {
try {
const response = await xhr(
Object.assign(
{
url: uri,
followRedirects: 5,
headers: { "Accept-Encoding": "gzip, deflate" }
},
options
)
)
return response.responseText
} catch (error) {
sendException(error)
return (
error.responseText ||
getErrorStatusDescription(error.status) ||
error.toString()
const batchRequestUrl = batchUrlElements.join('/');
const options: XHROptions = {
type: 'POST',
url: batchRequestUrl,
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
Authorization: `OAuth ${orgInfo.accessToken}`,
'User-Agent': 'salesforcedx-extension',
'Sforce-Call-Options': `client=${CLIENT_ID}`,
},
data: JSON.stringify(batchRequest),
};
try {
const response: XHRResponse = await xhr(options);
const batchResponse = JSON.parse(response.responseText) as BatchResponse;
const fetchedObjects: SObject[] = [];
let i = nextToProcess;
for (const sr of batchResponse.results) {
if (sr.result instanceof Array) {
if (sr.result[0].errorCode && sr.result[0].message) {
notifications.writeLog(`Error: ${sr.result[0].message} - ${types[i]}`);
}
}
i++;
fetchedObjects.push(sr.result);
}
return Promise.resolve(fetchedObjects);
} catch (error) {
const xhrResponse: XHRResponse = error;
return Promise.reject(xhrResponse.responseText);