Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getSandboxFiles = () => {
let options = {
url: `${this.appsEndpoint}/${this.vendor}/sandboxes/${this.sandbox}/${this.app}/${this.version}/files?list=true&_limit=1000`,
method: 'GET',
headers: {
Authorization: `token ${this.credentials.token}`,
Accept: this.acceptHeader,
'Content-Type': 'application/json',
'x-vtex-accept-snapshot': false
}
};
return request(options).then((response) => {
if (response.statusCode === 200) {
return JSON.parse(response.body).data.reduce((acc, file) => {
acc[file.path] = { hash: file.hash };
return acc;
}, {});
} else if (response.statusCode === 404) {
return void 0;
}
return console.error('Status:', response.statusCode);
});
}
}, (error, response, body) => {
let $ = cheerio.load(body);
let itemLink = $("#pbk-page").attr("src");
let index = item.label;
request({
uri: URL_HOST + itemLink,
jar: jar,
maxAttempts: 5,
retryDelay: 5000,
retryStrategy: request.RetryStrategies.HTTPOrNetworkError
}, (error, response, body) => {
this.setState((prevState, props) => {
return {
percent: prevState.percent + 1
};
},()=>{
cb()
});
function spotifyRequest(
params: string | { [key: string]: any },
url: string = API_URL,
method: string = 'POST',
) {
return request({
agent,
method,
uri: url,
form: params,
headers: {
'Authorization': `Basic ${authKey}`,
},
json: true,
fullResponse: false,
});
}
function getTemporaryToken() {
let deferred = Q.defer();
let requestOptions = {
uri: 'https://vtexid.vtex.com.br/api/vtexid/pub/authentication/start?callbackUrl='
};
request(requestOptions, (error, response, body) => {
if (error || response.statusCode !== 200 || response.statusCode >= 400) {
return deferred.reject(getErrorMessage(error, response, 'authenticating'));
}
try {
let token = JSON.parse(body).authenticationToken;
deferred.resolve(token);
} catch (err) {
return deferred.reject('Invalid JSON while getting token from VTEX ID');
}
});
return deferred.promise;
}
export function createWorkspace(credentials) {
let deferred = Q.defer();
let options = {
url: `http://workspaces.vtex.com/${credentials.account}/workspaces`,
method: 'POST',
headers: {
Authorization: `token ${credentials.token}`,
Accept: 'application/vnd.vtex.gallery.v0+json',
'Content-Type': 'application/json'
},
json: {
name: 'sb_' + credentials.email
}
};
request(options, (error, response) => {
if (error || !(response.statusCode === 201 || response.statusCode === 409)) {
return deferred.reject(getErrorMessage(error, response, 'creating workspace'));
}
return deferred.resolve(credentials);
});
return deferred.promise;
}
export function isTokenValid(credentials) {
let deferred = Q.defer();
let requestOptions = {
uri: 'https://vtexid.vtex.com.br/api/vtexid/pub/authenticated/user?authToken=' + (encodeURIComponent(credentials.token))
};
request(requestOptions, (error, response, body) => {
if (error || response.statusCode !== 200 || response.statusCode >= 400) {
return deferred.reject(getErrorMessage(error, response, 'authenticating'));
}
try {
let vtexIdUser = JSON.parse(body);
if (vtexIdUser === null) {
return deferred.resolve(false);
}
let user = vtexIdUser.user;
if (user !== null && user === credentials.email) {
return deferred.resolve(true);
}
} catch (err) {
return deferred.reject('Invalid JSON while getting token from VTEX ID');
}
Accept: this.acceptHeader,
'Content-Type': 'application/json',
'x-vtex-accept-snapshot': false
}
};
if (refresh) options.url += '?resync=true';
if (refresh) {
spinner = ora(chalk.blue('Synchronizing...'));
} else {
spinner = ora(chalk.blue('Changes detected, uploading...'));
}
spinner.start();
return request(options, (error, response) => {
spinner.stop();
if (error || response.statusCode !== 200 || response.statusCode >= 400) {
return this.changeSendError(error, response);
}
return this.changesSentSuccessfuly(response.body);
});
}
function getEmailAuthenticationToken(email, token, code) {
let deferred = Q.defer();
let options = {
url: 'https://vtexid.vtex.com.br/api/vtexid/pub/authentication/accesskey/' + ('validate?&login=' + email + '&accesskey=' + code) + ('&authenticationToken=' + token),
method: 'GET'
};
request(options, (error, response, body) => {
if (error || response.statusCode !== 200 || response.statusCode >= 400) {
return deferred.reject(getErrorMessage(error, response, 'authenticating'));
}
try {
let auth = JSON.parse(body);
if (auth.authStatus !== 'Success') {
deferred.reject(chalk.red('Authentication has failed with status ' + auth.authStatus));
}
return deferred.resolve(auth.authCookie.Value);
} catch (_error) {
return deferred.reject(chalk.red('Invalid JSON while authenticating with VTEX ID'));
}
});
return deferred.promise;