<commit_before>
///////// SAMPLE CODE ONLY /////////

const AWS = require('aws-sdk')
const util = require('util')
const { STATUS_CODES } = require('http')

const ddb = new AWS.DynamoDB.DocumentClient()

/// Environment Variables
const TABLE_NAME = (process.env.AWS_SAM_LOCAL) ? 'edge-blocking' : process.env.TABLE_NAME
const SESSION_ID_COOKIE_NAME = process.env.SESSION_ID_COOKIE_NAME
const OVER_LIMIT_COOKIE_NAME = process.env.OVER_LIMIT_COOKIE_NAME
const OVER_LIMIT_THRESHOLD = Number(process.env.OVER_LIMIT_THRESHOLD)
const OVER_LIMIT_TIMEOUT = Number(process.env.OVER_LIMIT_TIMEOUT)

///
function OverLimitError() {}
OverLimitError.prototype = Object.create(Error.prototype)
OverLimitError.constructor = OverLimitError

/**
 * Returns a response of "Too Many Requests"
 * @return {[type]}    429 response
 */
function rateLimit () {
  return {
    status: '429',
    statusDescription: STATUS_CODES['429'],
    headers: {
      'set-cookie': {
        'key': 'Set-Cookie',
        'value': `${OVER_LIMIT_COOKIE_NAME}=true; secure; path=/; max-age=${OVER_LIMIT_THRESHOLD * 60 * 60}`
      }
    }
  }
}


///
// const cookieParser = new RegExp(`${SESSION_ID_COOKIE_NAME}=([^\\s;]*);`)

/**
 * Retrieves the session id (as identified by SESSION_ID_COOKIE_NAME)
 * value from cookies in the request
 * @param  {[type]} request incoming http request
 * @return {[type]}         session id or null if not found
 */
function sessionIdFrom (request) {<commit_msg>Rework cookie regex to accomodate for session id as last cookie; check for match<commit_after>
///////// SAMPLE CODE ONLY /////////

const AWS = require('aws-sdk')
const util = require('util')
const { STATUS_CODES } = require('http')

AWS.config.update({ region: 'us-east-1' })
const ddb = new AWS.DynamoDB.DocumentClient()

/// Environment Variables
const TABLE_NAME = (process.env.AWS_SAM_LOCAL) ? 'edge-blocking' : process.env.TABLE_NAME
const SESSION_ID_COOKIE_NAME = process.env.SESSION_ID_COOKIE_NAME
const OVER_LIMIT_COOKIE_NAME = process.env.OVER_LIMIT_COOKIE_NAME
const OVER_LIMIT_THRESHOLD = Number(process.env.OVER_LIMIT_THRESHOLD)
const OVER_LIMIT_TIMEOUT = Number(process.env.OVER_LIMIT_TIMEOUT)

///
function OverLimitError() {}
OverLimitError.prototype = Object.create(Error.prototype)
OverLimitError.constructor = OverLimitError

/**
 * Returns a response of "Too Many Requests"
 * @return {[type]}    429 response
 */
function rateLimit () {
  return {
    status: '429',
    statusDescription: STATUS_CODES['429'],
    headers: {
      'set-cookie': [{
        'key': 'Set-Cookie',
        'value': `${OVER_LIMIT_COOKIE_NAME}=true; secure; path=/; max-age=${OVER_LIMIT_THRESHOLD * 60 * 60}`
      }]
    },
    body: ''
  }
}

/**
 * Retrieves the session id (as identified by SESSION_ID_COOKIE_NAME)
 * value from cookies in the request
 * @param  {[type]} request incoming http request
 * @return {[type]}         session id or null if not found
 */
function sessionIdFrom (request) {
{'fraction_non_alphanumeric': 0.13630229419703105, 'fraction_numerical': 0.009109311740890687, 'mean_word_length': 4.0770547945205475, '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': '1271905', 'n_tokens_mistral': 1012, 'n_tokens_neox': 984, 'n_words': 227}