<commit_before>import { Observable } from 'rxjs/Observable'
import { of } from 'rxjs/observable/of'
import { from } from 'rxjs/observable/from'
import { _catch } from 'rxjs/operator/catch'
import { concatMap } from 'rxjs/operator/concatMap'
import { map } from 'rxjs/operator/map'
import { filter } from 'rxjs/operator/filter'

const { Collection } = require('./ast.js')
const HorizonSocket = require('./socket.js')
const { log, logError, enableLogging } = require('./logging.js')
const { authEndpoint, TokenStorage, clearAuthTokens } = require('./auth')

const defaultHost = typeof window !== 'undefined' && window.location &&
        `${window.location.host}` || 'localhost:8181'
const defaultSecure = typeof window !== 'undefined' && window.location &&
        window.location.protocol === 'https:' || false

function Horizon({
  host = defaultHost,
  secure = defaultSecure,
  path = 'horizon',
  lazyWrites = false,
  authType = 'unauthenticated',
} = {}) {
  // If we're in a redirection from OAuth, store the auth token for
  // this user in localStorage.
  const tokenStorage = new TokenStorage({ authType, path })
  tokenStorage.setAuthFromQueryParams()

  const socket = new HorizonSocket(
    host, secure, path, ::tokenStorage.handshake)

  // Store whatever token we get back from the server when we get a
  // handshake response
  socket.handshake.subscribe({
    next(handshake) {
      tokenStorage.set(handshake.token)
    },
    error(err) {
      if (/JsonWebTokenError/.test(err.message)) {<commit_msg>Don't store unauthenticated tokens (#516)<commit_after>import { Observable } from 'rxjs/Observable'
import { of } from 'rxjs/observable/of'
import { from } from 'rxjs/observable/from'
import { _catch } from 'rxjs/operator/catch'
import { concatMap } from 'rxjs/operator/concatMap'
import { map } from 'rxjs/operator/map'
import { filter } from 'rxjs/operator/filter'

const { Collection } = require('./ast.js')
const HorizonSocket = require('./socket.js')
const { log, logError, enableLogging } = require('./logging.js')
const { authEndpoint, TokenStorage, clearAuthTokens } = require('./auth')

const defaultHost = typeof window !== 'undefined' && window.location &&
        `${window.location.host}` || 'localhost:8181'
const defaultSecure = typeof window !== 'undefined' && window.location &&
        window.location.protocol === 'https:' || false

function Horizon({
  host = defaultHost,
  secure = defaultSecure,
  path = 'horizon',
  lazyWrites = false,
  authType = 'unauthenticated',
} = {}) {
  // If we're in a redirection from OAuth, store the auth token for
  // this user in localStorage.
  const tokenStorage = new TokenStorage({ authType, path })
  tokenStorage.setAuthFromQueryParams()

  const socket = new HorizonSocket(
    host, secure, path, ::tokenStorage.handshake)

  // Store whatever token we get back from the server when we get a
  // handshake response
  socket.handshake.subscribe({
    next(handshake) {
      if (authType !== 'unauthenticated') {
        tokenStorage.set(handshake.token)
      }
    },
    error(err) {
      if (/JsonWebTokenError/.test(err.message)) {
{'fraction_non_alphanumeric': 0.13531669865642995, 'fraction_numerical': 0.0035188739603326936, 'mean_word_length': 3.9556259904912836, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5960714', 'n_tokens_mistral': 932, 'n_tokens_neox': 914, 'n_words': 257}