Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// prevent IE from caching requests
thisReq.set('If-Modified-Since', 'Mon, 26 Jul 1997 05:00:00 GMT');
if (self._token) {
// do a localized data serialization process
let data = (thisReq as any)._data;
if (typeof data !== 'string') {
let contentType = thisReq.get('Content-Type');
// Parse out just the content type from the header (ignore the charset)
if (contentType) {
contentType = contentType.split(';')[0];
}
let serialize = superagent.serialize[contentType];
if (!serialize && /[\/+]json\b/.test(contentType)) {
serialize = superagent.serialize['application/json'];
}
if (serialize) {
data = serialize(data);
}
}
(thisReq as any)._data = data;
const urlDetails = url.parse(req.url);
let queryString: string | undefined;
const query: string[] = (req as any)._query;
const qs: { [key: string]: string } = (req as any).qs;
if (query && query.length > 0) {
// browser version
queryString = query.join('&');
(req as any)._query = [];
thisReq.set('BitGo-Auth-Version', '2.0');
// prevent IE from caching requests
thisReq.set('If-Modified-Since', 'Mon, 26 Jul 1997 05:00:00 GMT');
if (self._token) {
// do a localized data serialization process
let data = (thisReq as any)._data;
if (typeof data !== 'string') {
let contentType = thisReq.get('Content-Type');
// Parse out just the content type from the header (ignore the charset)
if (contentType) {
contentType = contentType.split(';')[0];
}
let serialize = superagent.serialize[contentType];
if (!serialize && /[\/+]json\b/.test(contentType)) {
serialize = superagent.serialize['application/json'];
}
if (serialize) {
data = serialize(data);
}
}
(thisReq as any)._data = data;
const urlDetails = url.parse(req.url);
let queryString: string | undefined;
const query: string[] = (req as any)._query;
const qs: { [key: string]: string } = (req as any).qs;
if (query && query.length > 0) {
// browser version
query = request.serializeObject(query);
this.url += ~this.url.indexOf('?')
? '&' + query
: '?' + query;
}
// initiate request
xhr.open(this.method, this.url, true);
// CORS
if (this._withCredentials) xhr.withCredentials = true;
// body
if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !isHost(data)) {
// serialize stuff
var serialize = request.serialize[this.getHeader('Content-Type')];
if (serialize) data = serialize(data);
}
// set header fields
for (var field in this.header) {
if (null == this.header[field]) continue;
xhr.setRequestHeader(field, this.header[field]);
}
// send stuff
this.emit('request', this);
xhr.send(data);
return this;
};
import debug from 'debug';
import agent from 'superagent';
import wrap from 'superagent-promise';
import clone from '../helpers/clone';
import Datastore from './datastore';
let SuperAgent;
const UUID = /[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}/;
// housekeeping for SuperAgent
const JSONAPI_MIME_TYPE = 'application/vnd.api+json';
const JSONPATCH_MIME_TYPE = 'application/vnd.api+json; ext=jsonpatch';
agent.serialize[JSONAPI_MIME_TYPE] = JSON.stringify;
agent.serialize[JSONPATCH_MIME_TYPE] = JSON.stringify;
// jscs:disable maximumLineLength
export const ERROR_UNKNOWN_MODEL = 'The model ${model} does not exist in this store.';
export const ERROR_NO_LINKED_PROPERTY = 'The model ${model} does not have a linked property ${property}.';
export const ERROR_CANNOT_ROOT_QUERY = 'Query cannot be fulfilled because "${model}":${id} cannot be associated with a "${nextModel}".';
export const ERROR_CANNOT_ROOT_OBJECT = 'Cannot root ${model}:${modelState} through ${parentModel}.';
export const ERROR_CANNOT_FIND_OBJECT = 'Could not find ${model}.';
export const ERROR_CANNOT_CREATE_OBJECT = 'Could not create ${model}:${modelState}.';
export const ERROR_CANNOT_UPDATE_OBJECT = 'Could not update ${model}:${modelState}.';
export const ERROR_CANNOT_DELETE_OBJECT = 'Could not delete ${model}:${modelState}.';
export const ERROR_SCHEMA_INCONSISTENCY = 'Internal inconsistency in schema ${model} url does not have ${model} as the final model.';
// jscs:enable maximumLineLength
const log = debug('elide:jsonapistore');
const logUrl = debug('elide:jsonapistore:url');
const MAX_BODY_TEXT_LENGTH = 1000;
'use strict';
import debug from 'debug';
import agent from 'superagent';
import wrap from 'superagent-promise';
import clone from '../helpers/clone';
import Datastore from './datastore';
let SuperAgent;
const UUID = /[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}/;
// housekeeping for SuperAgent
const JSONAPI_MIME_TYPE = 'application/vnd.api+json';
const JSONPATCH_MIME_TYPE = 'application/vnd.api+json; ext=jsonpatch';
agent.serialize[JSONAPI_MIME_TYPE] = JSON.stringify;
agent.serialize[JSONPATCH_MIME_TYPE] = JSON.stringify;
// jscs:disable maximumLineLength
export const ERROR_UNKNOWN_MODEL = 'The model ${model} does not exist in this store.';
export const ERROR_NO_LINKED_PROPERTY = 'The model ${model} does not have a linked property ${property}.';
export const ERROR_CANNOT_ROOT_QUERY = 'Query cannot be fulfilled because "${model}":${id} cannot be associated with a "${nextModel}".';
export const ERROR_CANNOT_ROOT_OBJECT = 'Cannot root ${model}:${modelState} through ${parentModel}.';
export const ERROR_CANNOT_FIND_OBJECT = 'Could not find ${model}.';
export const ERROR_CANNOT_CREATE_OBJECT = 'Could not create ${model}:${modelState}.';
export const ERROR_CANNOT_UPDATE_OBJECT = 'Could not update ${model}:${modelState}.';
export const ERROR_CANNOT_DELETE_OBJECT = 'Could not delete ${model}:${modelState}.';
export const ERROR_SCHEMA_INCONSISTENCY = 'Internal inconsistency in schema ${model} url does not have ${model} as the final model.';
// jscs:enable maximumLineLength
const log = debug('elide:jsonapistore');
const logUrl = debug('elide:jsonapistore:url');
enrollmentFormSubmitted(event) {
event.preventDefault();
// validate the password fields
if (this.state.password !== this.state.password2) {
this.setState({error: 'Password missmatch'});
return;
}
this.setState({enrolling: true, error:''});
superagent.post(config.enrollmentUrl)
.send(superagent.serialize['application/x-www-form-urlencoded']({username: this.state.username,
password: this.state.password,
email: this.state.email,
display_name: this.state.yourName})) //eslint-disable-line camelcase
.end((error, res) => {
this.setState({enrolling: false});
if (error) {
this.setState({error: error.toString()});
return;
}
let data;
try {
data = JSON.parse(res.text);
} catch (e) {
this.setState({error: 'Could not decode response data'});
return;
}
const superagent = require('superagent');
const bPromise = require('bluebird');
const App = require('../');
const JSONAPIContentType = 'application/vnd.api+json';
superagent.serialize[JSONAPIContentType] = JSON.stringify;
superagent.parse[JSONAPIContentType] = superagent.parse['application/json'];
exports.superagent = superagent;
exports.request = function(method, url) {
if (url.charAt(0) === '/') {
url = App.baseUrl + url;
}
var request = superagent(method, url)
.buffer(true)
.accept(JSONAPIContentType)
.type(JSONAPIContentType);
request.promise = function() {
return new bPromise(function(resolve, reject) {
request.end(function(err, res) {