-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from pluralsh/klink/newsletter-signup
feat: Use Hubspot API for Newsletter signups
- Loading branch information
Showing
46 changed files
with
423 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,16 @@ | ||
Documentation site for [Plural](https://www.plural.sh/), the open-source, unified, application deployment platform that makes it easy to run open-source software on Kubernetes. Our marketplace has dozens of top tier applications ready to deploy. | ||
[![Netlify Status](https://api.netlify.com/api/v1/badges/58af7361-4aec-4e82-a963-7b192690851a/deploy-status)](https://app.netlify.com/sites/pluraldocs/deploys) | ||
|
||
Marketing site for [Plural](https://www.plural.sh/), the open-source, unified, application deployment platform that makes it easy to run open-source software on Kubernetes. Our marketplace has dozens of top tier applications ready to deploy. | ||
|
||
Built with [Next.js](https://nextjs.org/) and [Markdoc](https://markdoc.dev/). | ||
|
||
## Contributing | ||
|
||
### Running the docs locally | ||
### Running the site locally | ||
|
||
To run the docs locally, you'll need to have yarn and node as prerequisites. Then run the following commands: | ||
To run the site locally, you'll need to have yarn and node as prerequisites. Then run the following commands: | ||
|
||
```shell | ||
yarn # build the environment | ||
yarn dev # run docs locally | ||
yarn dev # run site locally | ||
``` | ||
|
||
### Adding a new document | ||
|
||
All content can be located under the [pages](/pages) directory. The directory structure directly informs the website URL structure, so consider that when placing your new document. | ||
|
||
All of our documents are in standard Markdown (.md) file format. If you are including an image, add it to [public/assets] using the same directory structure as pages. | ||
|
||
Finally, make sure to add your new document to the NavData.tsx file located [here](/src/NavData.tsx). | ||
|
||
### Updating structure | ||
|
||
If you are making any changes to the documentation structure or organization, you'll likely need to set up page redirects. These can be added in [next.config.js](next.config.js). Make sure to | ||
look for internal usages throughout all the documents on the site to make sure that there are no broken links. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { type NextRequest, NextResponse } from 'next/server' | ||
|
||
import { Client } from '@hubspot/api-client' | ||
import queryString from 'query-string' | ||
|
||
import { isValidEmail } from '@src/utils/text' | ||
|
||
const hubspotClient = new Client({ | ||
accessToken: process.env.HUBSPOT_API_SECRET, | ||
}) | ||
|
||
async function isCaptchaValid(captchaVal) { | ||
const postBody = queryString.stringify({ | ||
secret: process.env.SITE_RECAPTCHA_SECRET, | ||
response: captchaVal, | ||
}) | ||
const headers = new Headers({ | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
}) | ||
|
||
try { | ||
const res = await fetch('https://www.google.com/recaptcha/api/siteverify', { | ||
method: 'POST', | ||
headers, | ||
body: postBody, | ||
}) | ||
const response = await res.json() | ||
|
||
return response.success | ||
} catch (e) { | ||
return false | ||
} | ||
} | ||
|
||
async function setEmail(email) { | ||
const response = await hubspotClient.apiRequest({ | ||
method: 'POST', | ||
path: '/crm/v3/objects/contacts', | ||
body: { properties: { email } }, | ||
}) | ||
|
||
if (!response.ok) { | ||
try { | ||
const body = (await response.json()) as { | ||
category?: string | ||
message?: string | ||
} | ||
|
||
if (body?.category === 'CONFLICT') { | ||
const contactId = body.message?.match(/Existing ID:\s*(?<id>\d+)/) | ||
?.groups?.id | ||
|
||
if (!contactId) { | ||
return false | ||
} | ||
const patchRes = await hubspotClient.apiRequest({ | ||
method: 'PATCH', | ||
path: `/crm/v3/objects/contacts/${contactId}`, | ||
body: { properties: { email } }, | ||
}) | ||
|
||
if (patchRes.ok) { | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
} catch (e) { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} | ||
|
||
const ErrorResponse = (error: { | ||
type: 'form' | 'captcha' | 'hubspot' | ||
message: string | ||
}) => | ||
NextResponse.json( | ||
{ | ||
error, | ||
}, | ||
{ status: 500 } | ||
) | ||
|
||
export async function POST(req: NextRequest) { | ||
let formData: FormData | ||
|
||
try { | ||
formData = await req.formData() | ||
} catch (e) { | ||
return ErrorResponse({ type: 'form', message: `${e}` }) | ||
} | ||
const email = formData.get('email') | ||
|
||
if (!email || typeof email !== 'string') { | ||
return ErrorResponse({ | ||
type: 'form', | ||
message: 'Missing email address', | ||
}) | ||
} | ||
if (!isValidEmail(email)) { | ||
return ErrorResponse({ | ||
type: 'form', | ||
message: 'Invalid email address', | ||
}) | ||
} | ||
|
||
const validCaptcha = await isCaptchaValid( | ||
formData.get('g-recaptcha-response') | ||
) | ||
|
||
if (!validCaptcha) { | ||
return ErrorResponse({ type: 'captcha', message: 'Invalid captcha' }) | ||
} | ||
|
||
const success = setEmail(email) | ||
|
||
if (!success) { | ||
return ErrorResponse({ | ||
type: 'hubspot', | ||
message: 'Could not create contact', | ||
}) | ||
} | ||
|
||
return NextResponse.json({ success }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
/// <reference types="next/navigation-types/compat/navigation" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-91.1 KB
(78%)
public/images/cont-deploy/create-cluster-m.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-184 KB
(78%)
public/images/marketplace/png/stack-card-observability-lg@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-153 KB
(76%)
public/images/marketplace/png/stack-card-observability-sm@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-66.4 KB
(92%)
public/images/marketplace/png/stack-card-observability-xl@2x.png
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.