<commit_before>// @flow
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise';
import { parseQueryResponse, getAuthedQueryFilter } from '../util/fetchUtils';

/**
 * on the server, we can proxy the API requests directly without making a
 * request to the server's own API proxy endpoint
 */
export default (request: HapiRequest) => (apiUrl, member) => (
	queries: Array<Query>
): Promise<ParsedQueryResponses> => {
	const authedQueries = getAuthedQueryFilter(member);
	const validQueries = queries.filter(authedQueries);
	return request
		.proxyApi$(validQueries)
		.map(responses => ({ responses })) // package the responses in object like the API proxy endpoint does
		.toPromise()
		.then(parseQueryResponse(validQueries));
};<commit_msg>use cookie for member on server, redux in browser<commit_after>// @flow
import querystring from 'querystring';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise';
import { parseQueryResponse, getAuthedQueryFilter } from '../util/fetchUtils';

const isProd = process.env.NODE_ENV === 'production';
const getCookieMember = memberCookie => {
	const memberObj = querystring.parse(memberCookie);
	memberObj.id = memberObj.id ? parseInt(memberObj.id, 10) : 0;
	return memberObj;
};
/**
 * on the server, we can proxy the API requests directly without making a
 * request to the server's own API proxy endpoint
 */
export default (request: HapiRequest) => () => (
	queries: Array<Query>
): Promise<ParsedQueryResponses> => {
	const member = getCookieMember(
		request.state[isProd ? 'MEETUP_MEMBER' : 'MEETUP_MEMBER_DEV']
	);
	const authedQueries = getAuthedQueryFilter(member);
	const validQueries = queries.filter(authedQueries);
	return request
		.proxyApi$(validQueries)
		.map(responses => ({ responses })) // package the responses in object like the API proxy endpoint does
		.toPromise()
		.then(parseQueryResponse(validQueries));
};
{'fraction_non_alphanumeric': 0.1221814368117462, 'fraction_numerical': 0.0015731515469323545, 'mean_word_length': 5.297029702970297, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2335', 'n_tokens_mistral': 586, 'n_tokens_neox': 569, 'n_words': 163}