Skip to content
Merged
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
4 changes: 2 additions & 2 deletions apps/functions/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ACT_ID=""
AC_EVENT_KEY=""
BEEHIIV_API_KEY=""
BEEHIIV_PUBLICATION_ID=""
50 changes: 34 additions & 16 deletions apps/functions/general-opt-in.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import type { Handler, HandlerEvent, HandlerContext } from "@netlify/functions"
import { Event } from "./src/activeCampaign/Event"
import { configure } from "./src/configure"
import type { Handler, HandlerEvent } from "@netlify/functions"

const handler: Handler = async (event: HandlerEvent, context: HandlerContext) => {
// your server-side functionality
await configure()
const handler: Handler = async (event: HandlerEvent) => {
const { email } = JSON.parse(event.body || "{}")

if (!email) {
Expand All @@ -14,21 +10,43 @@ const handler: Handler = async (event: HandlerEvent, context: HandlerContext) =>
error: "Required properties not specified: email",
}),
}
} else {
const activeCampaignEvent = new Event<{}>({
email,
eventName: "generalOptIn",
})
}

await activeCampaignEvent.save()
const publicationId = process.env.BEEHIIV_PUBLICATION_ID
const apiKey = process.env.BEEHIIV_API_KEY

if (!publicationId || !apiKey) {
return {
statusCode: 201,
body: JSON.stringify({
success: true,
}),
statusCode: 500,
body: JSON.stringify({ error: "BeeHiiv not configured" }),
}
}

const response = await fetch(
`https://api.beehiiv.com/v2/publications/${publicationId}/subscriptions`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify({ email }),
},
)

if (!response.ok) {
const errorBody = await response.text()
console.error(`BeeHiiv API error: ${response.status} ${errorBody}`)
return {
statusCode: response.status,
body: JSON.stringify({ error: "Failed to subscribe" }),
}
}

return {
statusCode: 201,
body: JSON.stringify({ success: true }),
}
}

export { handler }
8 changes: 2 additions & 6 deletions apps/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
"author": "Dan Pickett",
"license": "NONE",
"private": true,
"dependencies": {
"got": "^13.0.0"
},
"devDependencies": {
"dotenv": "^16.3.1"
}
"dependencies": {},
"devDependencies": {}
}
47 changes: 0 additions & 47 deletions apps/functions/src/activeCampaign/Configuration.ts

This file was deleted.

84 changes: 0 additions & 84 deletions apps/functions/src/activeCampaign/Contact.ts

This file was deleted.

77 changes: 0 additions & 77 deletions apps/functions/src/activeCampaign/Event.ts

This file was deleted.

15 changes: 0 additions & 15 deletions apps/functions/src/configure.ts

This file was deleted.

24 changes: 0 additions & 24 deletions apps/functions/submission-created.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ Along with this helpful change, you can also circumvent mass assignment protecti

<script src="https://gist.github.com/974447.js?file=user_without_protection.rb"></script>

You should really only use without_protection if _you_ control the inputted attributes. It isn't something you'd want to have in a controller action, generally speaking.
You should really only use without*protection if \_you* control the inputted attributes. It isn't something you'd want to have in a controller action, generally speaking.

For more information on scoped mass assignment and additional attack vectors you should be securing against, [check out the edge Rails guide on security](https://edgeguides.rubyonrails.org/security.html)
4 changes: 1 addition & 3 deletions apps/gatsby/src/components/layout/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import { companyContactInformation } from "../../configuration/companyContactInf
import "./css/footer.css"
import { TrackingCodes } from "./TrackingCodes"
import { useBookCallModal } from "../book-call/hooks/useBookCallModal"
const OptInForm = lazy(() =>
import("../opt-in/OptInForm").then((m) => ({ default: m.OptInForm }))
)
const OptInForm = lazy(() => import("../opt-in/OptInForm").then((m) => ({ default: m.OptInForm })))
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { faEnvelope, faPhone, faSms } from "@fortawesome/free-solid-svg-icons"
import { UC_UI } from "../../services/UsercentricsService"
Expand Down
Loading
Loading