<commit_before>import fetch from 'isomorphic-fetch'

let BASE_URL = ''

if (process.env.NODE_ENV === 'test') {
  BASE_URL = 'http://localhost'
} else {
  BASE_URL = ((host) => `http://${host}:12336`)(document.location.hostname)
}

export const Auth = {

  current: () => fetch(
    `${BASE_URL}/auth`, {
      credentials: 'include'
    }
  ),

  signIn: (email, encp) => fetch(
    `${BASE_URL}/auth`, {
      headers: { email, encp },
      credentials: 'include'
    }
  ),

  signOut: () => fetch(
    `${BASE_URL}/auth`, {
      method: 'DELETE',
      credentials: 'include'
    }
  )

}

export const Invoice = {

  getOne: (invoiceId) => fetch(
    `${BASE_URL}/invoices/${invoiceId}?_embed=items`, {
      credentials: 'include'
    }
  ),

  getAll: (userId) => fetch(
    `${BASE_URL}/invoices?userId=${userId}&_embed=items`, {
      credentials: 'include'
    }
  ),

  create: (data) => fetch(
    `${BASE_URL}/invoices`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data),
      credentials: 'include'
    }
  ),

  update: (invoiceId, data) => fetch(
    `${BASE_URL}/invoices/${invoiceId}`, {
      method: 'PUT',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data),
      credentials: 'include'
    }
  ),

  merge: (invoiceId, data) => fetch(
    `${BASE_URL}/invoices/${invoiceId}`, {
      method: 'PATCH',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data),
      credentials: 'include'
    }
  ),

  delete: (invoiceId) => fetch(
    `${BASE_URL}/invoices/${invoiceId}`, {
      method: 'DELETE',
      credentials: 'include'
    }
  )

}

export const InvoiceItem = {

  create: (invoiceId, data) => fetch(
    `${BASE_URL}/invoices/${invoiceId}/items`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data),
      credentials: 'include'
    }
  ),

  update: (invoiceId, invoiceItemId, data) => fetch(
    `${BASE_URL}/invoices/${invoiceId}/items/${invoiceItemId}`, {
      method: 'PUT',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data),
      credentials: 'include'
    }
  ),

  delete: (invoiceId, invoiceItemId) => fetch(
    `${BASE_URL}/invoices/${invoiceId}/items/${invoiceItemId}`, {
      method: 'DELETE',
      credentials: 'include'
    }
  )

}

export const User = {

  getOne: (userId) => fetch(
    `${BASE_URL}/users/${userId}`, {
      credentials: 'include'
    }
  ),

  getAll: () => fetch(
    `${BASE_URL}/users`, {
      credentials: 'include'
    }
  ),

  create: (data, encp) => fetch(
    `${BASE_URL}/users`, {
      method: 'POST',
      headers: {
        encp,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data),
      credentials: 'include'
    }
  ),

  update: (userId, data) => fetch(
    `${BASE_URL}/users/${userId}`, {
      method: 'PUT',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data),
      credentials: 'include'
    }
  ),

  merge: (userId, data) => fetch(
    `${BASE_URL}/users/${userId}`, {
      method: 'PATCH',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data),
      credentials: 'include'
    }
  ),

  delete: (userId) => fetch(
    `${BASE_URL}/users/${userId}`, {
      method: 'DELETE',
      credentials: 'include'
    }
  ),

  updateUserPassword: (userId, newPassword, currentPassword) => fetch(
    `${BASE_URL}/users/${userId}`, {
      method: 'PATCH',
      headers: {
        'encp': <PASSWORD>Password,
        'encp-old': currentPassword
      },
      credentials: 'include'
    }
  )

}
<commit_msg>Add invoice item merge functionality to the API.<commit_after>import fetch from 'isomorphic-fetch'

let BASE_URL = ''

if (process.env.NODE_ENV === 'test') {
  BASE_URL = 'http://localhost'
} else {
  BASE_URL = ((host) => `http://${host}:12336`)(document.location.hostname)
}

export const Auth = {

  current: () => fetch(
    `${BASE_URL}/auth`, {
      credentials: 'include'
    }
  ),

  signIn: (email, encp) => fetch(
    `${BASE_URL}/auth`, {
      headers: { email, encp },
      credentials: 'include'
    }
  ),

  signOut: () => fetch(
    `${BASE_URL}/auth`, {
      method: 'DELETE',
      credentials: 'include'
    }
  )

}

export const Invoice = {

  getOne: (invoiceId) => fetch(
    `${BASE_URL}/invoices/${invoiceId}?_embed=items`, {
      credentials: 'include'
    }
  ),

  getAll: (userId) => fetch(
    `${BASE_URL}/invoices?userId=${userId}&_embed=items`, {
      credentials: 'include'
    }
  ),

  create: (data) => fetch(
    `${BASE_URL}/invoices`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data),
      credentials: 'include'
    }
  ),

  update: (invoiceId, data) => fetch(
    `${BASE_URL}/invoices/${invoiceId}`, {
      method: 'PUT',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data),
      credentials: 'include'
    }
  ),

  merge: (invoiceId, data) => fetch(
    `${BASE_URL}/invoices/${invoiceId}`, {
      method: 'PATCH',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data),
      credentials: 'include'
    }
  ),

  delete: (invoiceId) => fetch(
    `${BASE_URL}/invoices/${invoiceId}`, {
      method: 'DELETE',
      credentials: 'include'
    }
  )

}

export const InvoiceItem = {

  create: (invoiceId, data) => fetch(
    `${BASE_URL}/invoices/${invoiceId}/items`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data),
      credentials: 'include'
    }
  ),

  update: (invoiceId, invoiceItemId, data) => fetch(
    `${BASE_URL}/invoices/${invoiceId}/items/${invoiceItemId}`, {
      method: 'PUT',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data),
      credentials: 'include'
    }
  ),

  merge: (invoiceId, invoiceItemId, data) => fetch(
    `${BASE_URL}/invoices/${invoiceId}/items/${invoiceItemId}`, {
      method: 'PATCH',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data),
      credentials: 'include'
    }
  ),

  delete: (invoiceId, invoiceItemId) => fetch(
    `${BASE_URL}/invoices/${invoiceId}/items/${invoiceItemId}`, {
      method: 'DELETE',
      credentials: 'include'
    }
  )

}

export const User = {

  getOne: (userId) => fetch(
    `${BASE_URL}/users/${userId}`, {
      credentials: 'include'
    }
  ),

  getAll: () => fetch(
    `${BASE_URL}/users`, {
      credentials: 'include'
    }
  ),

  create: (data, encp) => fetch(
    `${BASE_URL}/users`, {
      method: 'POST',
      headers: {
        encp,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data),
      credentials: 'include'
    }
  ),

  update: (userId, data) => fetch(
    `${BASE_URL}/users/${userId}`, {
      method: 'PUT',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data),
      credentials: 'include'
    }
  ),

  merge: (userId, data) => fetch(
    `${BASE_URL}/users/${userId}`, {
      method: 'PATCH',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data),
      credentials: 'include'
    }
  ),

  delete: (userId) => fetch(
    `${BASE_URL}/users/${userId}`, {
      method: 'DELETE',
      credentials: 'include'
    }
  ),

  updateUserPassword: (userId, newPassword, currentPassword) => fetch(
    `${BASE_URL}/users/${userId}`, {
      method: 'PATCH',
      headers: {
        'encp': newPassword,
        'encp-old': currentPassword
      },
      credentials: 'include'
    }
  )

}

{'fraction_non_alphanumeric': 0.18564449455092072, 'fraction_numerical': 0.0012526619065514218, 'mean_word_length': 2.4325021496130694, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 45, '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': '4248933', 'n_tokens_mistral': 2711, 'n_tokens_neox': 2787, 'n_words': 472}