Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-976 | Code Refactor of Handing the LOB API Key #1019

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ module.exports = {
await knex.schema.alterTable('letters', (table) => {
table.integer('letter_template_id').unsigned()
table.foreign('letter_template_id').references('letter_templates.id')
table
.enu('delivery_method', ['email', 'snail_mail'], {
useNative: true,
enumName: 'delivery_methods'
})
table.enu('delivery_method', ['email', 'snail_mail'], {
useNative: true,
enumName: 'delivery_methods'
})
table.string('email')
})

Expand Down
30 changes: 19 additions & 11 deletions server/db/seeds/development/02-seed-campaigns-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,20 @@ module.exports = {
name: 'Protect Caste Equity at Rutgers University',
cause: 'Civic Rights',
type: 'Grant',
page_url: 'https://rutgersaaup.org/wp-content/uploads/2024/08/Rutgers-Caste-Report-August-2024.pdf',
page_url:
'https://rutgersaaup.org/wp-content/uploads/2024/08/Rutgers-Caste-Report-August-2024.pdf',
letter_template_id: 2,
campaign_tagline:
'URGE RUTGERS TO PRIORITIZE CASTE EQUITY',
campaign_text: '<p>We applaud Rutgers University for taking a crucial step toward addressing caste inequity through the recent <strong><a href="https://rutgersaaup.org/wp-content/uploads/2024/08/Rutgers-Caste-Report-August-2024.pdf">University Task Force Report on Caste Discrimination in Higher Education and at Rutgers</strong> Global caste systems enforce discrimination through inherited social status. They are a systemic injustice that has long been overlooked in the United States, despite its prevalence in many American institutions including higher education. That is why the findings of this report are so crucial. By recommending to add caste as a protected category, Rutgers has an opportunity to lead the way in creating equitable spaces for all, especially for caste-oppressed faculty, students, and workers who experience this bias.</p><p>The testimonies presented in Rutgers’ task force report are a powerful reminder of the urgent need to address caste-based exclusion, harassment, and inequities in higher education. Caste is not an abstract concept; it is a harsh reality for millions. Caste discrimination spans across industries and includes bullying, harassment, bias, wage theft, sexual harassment, and even trafficking. Caste-oppressed individuals have also been denied rental housing upon the discovery of their caste identity. This issue has gained significant attention in New Jersey following <a href="https://www.npr.org/2021/06/03/1002547517/human-trafficking-allegations-thrust-caste-into-spotlight-for-american-hindus">human trafficking allegations</a> against the BAPS temples, where caste-oppressed workers were held against their will and paid just a dollar an hour under <a href="https://www.nytimes.com/2021/05/11/nyregion/nj-hindu-temple-india-baps.html">inhumane conditions</a></p><p>In New Jersey there are many communities who suffer caste discrimination in their communities from Africa, South Asia, Asia, and Indigenous residents of the state. Students, faculty and staff from these backgrounds must be able to access the campus as a place of learning and as a workplace free from discrimination and harm.</p><p>From workplace discrimination to campus bullying, the insidious impacts of caste privilege have been well-documented by marginalized communities, In our own 2016 report <a href="https://equalitylabs.wpengine.com/wp-content/uploads/2023/10/Caste_in_the_United_States_Report2018.pdf">Caste in the United States</a> we have found caste oppressed people face alarming discrimination and harassment with 1 in 4 facing physical and verbal assault, 1 in 3 education discrimination and 2 out 3 workplace discrimination.</p><p>As a U.S.-based civil rights group we urge Rutgers’ administration **to fully adopt the task force’s recommendations and implement robust enforcement mechanisms.** This includes education on caste equity for students, staff, and faculty and meaningful support for those who come forward with experiences of caste-based harm.</p><p>As Rutgers advances this work, we caution against narratives that dismiss caste protections as “anti-Hindu” or as targeting specific communities. Such arguments weaponize bad faith arguments and privilege to silence Dalit voices and maintain systems of oppression. Caste is found across multiple geographies and faiths and it must be addressed as its own system of exclusion. We believe in fostering dialogue that centers the experiences of the most vulnerable while rejecting extremist  rhetoric that masquerades falsely as a defense of cultural identity.</p><p>Rutgers’ initiative is part of a broader, necessary movement to confront caste oppression in the United States. We look forward to standing alongside other universities and institutions in their journey toward caste equity. Together, we can build communities where everyone can thrive with dignity and equal opportunity.</p><p>In solidarity,</p><p>Equality Labs</p>',
campaign_tagline: 'URGE RUTGERS TO PRIORITIZE CASTE EQUITY',
campaign_text:
'<p>We applaud Rutgers University for taking a crucial step toward addressing caste inequity through the recent <strong><a href="https://rutgersaaup.org/wp-content/uploads/2024/08/Rutgers-Caste-Report-August-2024.pdf">University Task Force Report on Caste Discrimination in Higher Education and at Rutgers</strong> Global caste systems enforce discrimination through inherited social status. They are a systemic injustice that has long been overlooked in the United States, despite its prevalence in many American institutions including higher education. That is why the findings of this report are so crucial. By recommending to add caste as a protected category, Rutgers has an opportunity to lead the way in creating equitable spaces for all, especially for caste-oppressed faculty, students, and workers who experience this bias.</p><p>The testimonies presented in Rutgers’ task force report are a powerful reminder of the urgent need to address caste-based exclusion, harassment, and inequities in higher education. Caste is not an abstract concept; it is a harsh reality for millions. Caste discrimination spans across industries and includes bullying, harassment, bias, wage theft, sexual harassment, and even trafficking. Caste-oppressed individuals have also been denied rental housing upon the discovery of their caste identity. This issue has gained significant attention in New Jersey following <a href="https://www.npr.org/2021/06/03/1002547517/human-trafficking-allegations-thrust-caste-into-spotlight-for-american-hindus">human trafficking allegations</a> against the BAPS temples, where caste-oppressed workers were held against their will and paid just a dollar an hour under <a href="https://www.nytimes.com/2021/05/11/nyregion/nj-hindu-temple-india-baps.html">inhumane conditions</a></p><p>In New Jersey there are many communities who suffer caste discrimination in their communities from Africa, South Asia, Asia, and Indigenous residents of the state. Students, faculty and staff from these backgrounds must be able to access the campus as a place of learning and as a workplace free from discrimination and harm.</p><p>From workplace discrimination to campus bullying, the insidious impacts of caste privilege have been well-documented by marginalized communities, In our own 2016 report <a href="https://equalitylabs.wpengine.com/wp-content/uploads/2023/10/Caste_in_the_United_States_Report2018.pdf">Caste in the United States</a> we have found caste oppressed people face alarming discrimination and harassment with 1 in 4 facing physical and verbal assault, 1 in 3 education discrimination and 2 out 3 workplace discrimination.</p><p>As a U.S.-based civil rights group we urge Rutgers’ administration **to fully adopt the task force’s recommendations and implement robust enforcement mechanisms.** This includes education on caste equity for students, staff, and faculty and meaningful support for those who come forward with experiences of caste-based harm.</p><p>As Rutgers advances this work, we caution against narratives that dismiss caste protections as “anti-Hindu” or as targeting specific communities. Such arguments weaponize bad faith arguments and privilege to silence Dalit voices and maintain systems of oppression. Caste is found across multiple geographies and faiths and it must be addressed as its own system of exclusion. We believe in fostering dialogue that centers the experiences of the most vulnerable while rejecting extremist  rhetoric that masquerades falsely as a defense of cultural identity.</p><p>Rutgers’ initiative is part of a broader, necessary movement to confront caste oppression in the United States. We look forward to standing alongside other universities and institutions in their journey toward caste equity. Together, we can build communities where everyone can thrive with dignity and equal opportunity.</p><p>In solidarity,</p><p>Equality Labs</p>',
supplemental_text:
'<p>Caste-oppressed students and staff deserve protection—yet Rutgers University continues to delay adopting crucial caste protections in its anti-discrimination policy. This hesitation comes after pressure from far-right nationalist groups that aim to erase the realities of caste-based harm.</p><p>In August 2024, the Rutgers Task Force on Caste Discrimination recommended adding caste as a protected category after collecting powerful testimony from affected community members. These recommendations are a critical step toward equity but remain stalled.</p><p>It’s time to demand action! Let’s ensure Rutgers doesn’t back down in the face of opposition. Flood the administration’s inboxes today and call for the immediate adoption of caste protections. Together, we can build a campus where no one has to endure caste discrimination.</p>',
representatives: JSON.stringify([
{
name: 'President Jonathan Holloway',
title: 'President, Rutgers University',
photoUrl: 'https://www.rutgers.edu/sites/default/files/styles/3x4_one_third_full_1024_1x/public/2020-07/pro_NR20HollowayJonathan1819.jpg?h=ef631461&itok=uRWXEI4G',
photoUrl:
'https://www.rutgers.edu/sites/default/files/styles/3x4_one_third_full_1024_1x/public/2020-07/pro_NR20HollowayJonathan1819.jpg?h=ef631461&itok=uRWXEI4G',
address_line1: '7 College Avenue',
address_line2: '2nd Floor',
address_city: 'New Brunswick',
Expand All @@ -119,7 +121,8 @@ module.exports = {
{
name: 'Anna (Enobong) Branch',
title: 'Senior Vice President for University Equity and Inclusion',
photoUrl: 'https://www.rutgers.edu/sites/default/files/styles/3x4_one_third_full_1024_1x/public/2020-09/pro_Ann_Branch.jpg?h=3dfac914&itok=rA6GxwC_',
photoUrl:
'https://www.rutgers.edu/sites/default/files/styles/3x4_one_third_full_1024_1x/public/2020-09/pro_Ann_Branch.jpg?h=3dfac914&itok=rA6GxwC_',
address_line1: '106 Sommerset Street',
address_line2: '7th Floor',
address_city: 'New Brunswick',
Expand All @@ -131,7 +134,8 @@ module.exports = {
{
name: 'Prabhas Moghe',
title: 'Executive Vice President for Academic Affairs at Rutgers',
photoUrl: 'https://www.rutgers.edu/sites/default/files/styles/max_width_embed_default_2x/public/2020-09/pro_Prabhas_Moghe.jpg?itok=dLd3TLhW',
photoUrl:
'https://www.rutgers.edu/sites/default/files/styles/max_width_embed_default_2x/public/2020-09/pro_Prabhas_Moghe.jpg?itok=dLd3TLhW',
address_line1: '7 College Avenue',
address_line2: '2nd Floor',
address_city: 'New Brunswick',
Expand All @@ -143,10 +147,14 @@ module.exports = {
]),
assets: JSON.stringify({
campaign_logo: 'https://i.imgur.com/0I80XGh.png',
campaign_background: 'https://media.assettype.com/freepressjournal/2024-09-04/i722yxsy/lg_NR15OldQueensGate0889_edit.jpg?rect=0%2C0%2C3900%2C2194&w=1200&auto=format%2Ccompress&ogImage=true',
'campaign-img-1': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ-yngrxizvU5kAZ3CP9-iQnn1OD14eXkpeXUYo96KOL6sg19Icwoes_JYlm_a61pzAcRE&usqp=CAU',
'campaign-img-2': 'https://images-prod.gothamist.com/images/GettyImages-1481222828.width-1000.jpg',
'campaign-img-3': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS2X0OYEKhzrxmyMymuEaqDUIq0jDakYX4i4jaqRI3AUs0svGfcNDbpdatY4WUD6LMPRqg&usqp=CAU'
campaign_background:
'https://media.assettype.com/freepressjournal/2024-09-04/i722yxsy/lg_NR15OldQueensGate0889_edit.jpg?rect=0%2C0%2C3900%2C2194&w=1200&auto=format%2Ccompress&ogImage=true',
'campaign-img-1':
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ-yngrxizvU5kAZ3CP9-iQnn1OD14eXkpeXUYo96KOL6sg19Icwoes_JYlm_a61pzAcRE&usqp=CAU',
'campaign-img-2':
'https://images-prod.gothamist.com/images/GettyImages-1481222828.width-1000.jpg',
'campaign-img-3':
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS2X0OYEKhzrxmyMymuEaqDUIq0jDakYX4i4jaqRI3AUs0svGfcNDbpdatY4WUD6LMPRqg&usqp=CAU'
})
}
])
Expand Down
71 changes: 25 additions & 46 deletions server/routes/api/lob.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,68 +393,47 @@ router.post('/addressVerification', async (req, res) => {

module.exports = router

const LOB_API_KEY = process.env.LOB_API_KEY
const DEPRECATED_LOB_KEY = process.env.LiveLob

// Temporary implementation for fallback with deprecation warnings
function getLobApiKey() {
const { LOB_API_KEY, LiveLob } = process.env
const lobApiKey = LOB_API_KEY || LiveLob

if (LiveLob) {
if (LOB_API_KEY) {
console.warn('Using "LOB_API_KEY" environment variable.')
console.warn(
'Please remove your deprecated "LiveLob" environment variable!'
)
} else {
console.warn('Expected "LOB_API_KEY" environment variable was not found.')
console.warn(
'Falling back to deprecated "LiveLob" environment variable....'
)
console.warn('Please update your environment to use the expected key!')
}
if (LOB_API_KEY) {
return LOB_API_KEY
}
if (DEPRECATED_LOB_KEY) {
console.warn(
'[DEPRECATION WARNING] Using deprecated "LiveLob" environment variable.'
)
console.warn('Please migrate to "LOB_API_KEY" as soon as possible.')

return DEPRECATED_LOB_KEY
}

return lobApiKey
throw new Error(
'Lob API key is missing. Please set the "LOB_API_KEY" environment variable.'
)
}

function handleLobError(error, res) {
let status = 500
let errorMessage = 'Whoops'
let errorMessage = 'Something went wrong.'

if (error) {
// error.response is from the `axios` package
// error._response is from the `lob` package
if (error.response || error._response) {
status = 502
const response = error.response || error._response

let lobStatus = null
let lobApiError = {}
if (response) {
status = response.status || 502
const lobError = response.data?.error || response.body?.error

// Handle Lob API errors from `axios` requests
if (error.response) {
lobStatus = error.response.status
lobApiError = error.response.data.error
if (lobError) {
errorMessage = lobError.message
}
// Handle Lob API errors from `lob` requests
else if (error._response) {
lobStatus = error._response.statusCode
lobApiError = error._response.body.error
}

if (process.env.NODE_ENV !== 'test') {
console.error(
`Lob API error (${lobStatus}): ${JSON.stringify(lobApiError)}`
)
}

// If the error is being blamed on the request...
// See: https://docs.lob.com/#errors
if ([400, 404, 422].includes(lobStatus)) {
status = 400
errorMessage = lobApiError.message
}
} else {
console.error(error)
}

console.error(`Lob API error: ${errorMessage}`)
}

return res.status(status).send({ error: errorMessage })
Expand Down
Loading