Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// If it is an absolute url.
const url = getUrl(endpoint);
const options = { url, method };
if (jwt) {
options.headers = {
Authorization: `Bearer ${jwt}`,
};
}
if (body) {
if (method === 'GET' && body != null) {
// Convert body to ?x=y&b=a format
options.url += optionsToParameterizedUrl(decamelizeKeys(body));
} else {
options.data = decamelizeKeys(body);
}
}
const result = await axios(options);
const camelizedData = shouldCamelize
? camelizeKeys(result.data)
: result.data;
// Quickfix to prevent underscored dependencies from being camelized.
// Never store data as keys in the future.
if (
camelizedData &&
camelizedData.data &&
const url = getUrl(endpoint);
const options = { url, method };
if (jwt) {
options.headers = {
Authorization: `Bearer ${jwt}`,
};
}
if (body) {
if (method === 'GET' && body != null) {
// Convert body to ?x=y&b=a format
options.url += optionsToParameterizedUrl(decamelizeKeys(body));
} else {
options.data = decamelizeKeys(body);
}
}
const result = await axios(options);
return shouldCamelize ? camelizeKeys(result.data) : result.data;
});
humps.depascalize('helloWorldFooBar');
humps.camelizeKeys(someObject);
humps.pascalizeKeys(someObject);
humps.decamelizeKeys(someObject);
humps.depascalizeKeys(someObject);
humps.camelizeKeys(someObject, someOptions);
humps.pascalizeKeys(someObject, someOptions);
humps.decamelizeKeys(someObject, someOptions);
humps.depascalizeKeys(someObject, someOptions);
humps.camelizeKeys(someObject, someOptions2);
humps.pascalizeKeys(someObject, someOptions2);
humps.decamelizeKeys(someObject, someOptions2);
humps.depascalizeKeys(someObject, someOptions2);
humps.camelizeKeys(someObject, someOptions3);
humps.pascalizeKeys(someObject, someOptions3);
humps.decamelizeKeys(someObject, someOptions3);
humps.depascalizeKeys(someObject, someOptions3);
return new Promise(function(resolve, reject) {
var readyQueryParams;
if (queryParams) {
readyQueryParams = humps.decamelizeKeys(_.omit(queryParams, 'page'));
if (readyQueryParams.q instanceof Object) {
readyQueryParams.q = JSON.stringify(readyQueryParams.q);
}
}
request[method.toLowerCase()](url.resolve(_this.context.baseUrl, path))
.send(humps.decamelizeKeys(params))
.query(readyQueryParams)
.set('Accept', 'application/json')
.set('X-Authentication-Token', _this.context.authenticationToken)
.timeout(_this.context.timeout)
.then(function(response) {
if (_this.context.camelize) {
response.body = humps.camelizeKeys(response.body);
}
events.forEach(e => {
outStream.write(`${JSON.stringify(humps.decamelizeKeys(e))}\n`, 'utf8');
});
outStream.end();
return async function(conds, values, trx) {
try {
if (values.id) {
delete values.id;
}
let builder = knex(T)
.update(decamelizeKeys(values))
.where(decamelizeKeys(conds));
if (trx) {
builder.transacting(trx);
}
return builder;
} catch (e) {
log.error(`Error in ${T}.updateMultiCondition()`, e);
throw e;
}
};
}
export const createWorkspace = workspace => (
fetch('api/workspaces', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
credentials: 'include',
body: JSON.stringify(decamelizeKeys(workspace, { separator: '_' }))
}).then(response =>
response.json().then(json => ({ json, response }))
).then(({ json, response }) => {
if (!response.ok) {
throw json;
}
return json;
}).catch(errors => {
throw errors || ['Unknown workspace error!'];
})
);
export const requestBody = (record, key) =>
JSON.stringify(humps.decamelizeKeys({ [singular(key)]: record }, { split: /(?=[A-Z0-9])/ }))
export const signup = (userProps) => {
axios.defaults.headers.post['Content-Type'] = 'application/json'
axios.defaults.headers.post['Accepts'] = 'application/json'
userProps.passwordConfirmation = userProps.password
var userSignup = {
user: userProps
}
var request = axios.post('http://localhost:4000/v1/users.json', humps.decamelizeKeys(userSignup))
return {
type: SIGNUP,
payload: request
}
}
if (authenticate && authToken && userEmail) {
headers = {
...headers,
'Authorization': `Token token="${authToken}", email="${userEmail}"`
}
}
if (storeId && storeResource) {
url = `stores/${storeId}/${url}`
}
return axios({
method,
url,
baseURL: API_ROOT,
data: decamelizeKeys(data),
headers
})
.then(function (response) {
return camelizeKeys(response.data)
})
.catch(function (response) {
return Promise.reject(response)
})
}