-
Notifications
You must be signed in to change notification settings - Fork 3.5k
feat(triggers): add Greenhouse webhook triggers #3985
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,80 @@ | ||
| import crypto from 'crypto' | ||
| import { createLogger } from '@sim/logger' | ||
| import { NextResponse } from 'next/server' | ||
| import { safeCompare } from '@/lib/core/security/encryption' | ||
| import type { | ||
| EventMatchContext, | ||
| FormatInputContext, | ||
| FormatInputResult, | ||
| WebhookProviderHandler, | ||
| } from '@/lib/webhooks/providers/types' | ||
| import { createHmacVerifier } from '@/lib/webhooks/providers/utils' | ||
| import { isGreenhouseEventMatch } from '@/triggers/greenhouse/utils' | ||
|
|
||
| const logger = createLogger('WebhookProvider:Greenhouse') | ||
|
|
||
| /** | ||
| * Validates the Greenhouse HMAC-SHA256 signature. | ||
| * Greenhouse sends: `Signature: sha256 <hexdigest>` | ||
| */ | ||
| function validateGreenhouseSignature(secretKey: string, signature: string, body: string): boolean { | ||
| try { | ||
| if (!secretKey || !signature || !body) { | ||
| return false | ||
| } | ||
| const prefix = 'sha256 ' | ||
| if (!signature.startsWith(prefix)) { | ||
| return false | ||
| } | ||
| const providedDigest = signature.substring(prefix.length) | ||
| const computedDigest = crypto.createHmac('sha256', secretKey).update(body, 'utf8').digest('hex') | ||
| return safeCompare(computedDigest, providedDigest) | ||
| } catch { | ||
| logger.error('Error validating Greenhouse signature') | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| export const greenhouseHandler: WebhookProviderHandler = { | ||
| verifyAuth: createHmacVerifier({ | ||
| configKey: 'secretKey', | ||
| headerName: 'signature', | ||
| validateFn: validateGreenhouseSignature, | ||
| providerLabel: 'Greenhouse', | ||
| }), | ||
|
|
||
| async formatInput({ body }: FormatInputContext): Promise<FormatInputResult> { | ||
| const b = body as Record<string, unknown> | ||
| return { | ||
| input: { | ||
| action: b.action, | ||
| payload: b.payload || {}, | ||
| }, | ||
| } | ||
| }, | ||
|
|
||
| async matchEvent({ webhook, body, requestId, providerConfig }: EventMatchContext) { | ||
| const triggerId = providerConfig.triggerId as string | undefined | ||
| const b = body as Record<string, unknown> | ||
| const action = b.action as string | undefined | ||
|
|
||
| if (triggerId && triggerId !== 'greenhouse_webhook') { | ||
| if (!isGreenhouseEventMatch(triggerId, action || '')) { | ||
| logger.debug( | ||
| `[${requestId}] Greenhouse event mismatch for trigger ${triggerId}. Action: ${action}. Skipping execution.`, | ||
| { | ||
| webhookId: webhook.id, | ||
| triggerId, | ||
| receivedAction: action, | ||
| } | ||
| ) | ||
|
|
||
| return NextResponse.json({ | ||
| message: 'Event type does not match trigger configuration. Ignoring.', | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| return true | ||
| }, | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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,41 @@ | ||
| import { GreenhouseIcon } from '@/components/icons' | ||
| import { buildTriggerSubBlocks } from '@/triggers' | ||
| import { | ||
| buildCandidateHiredOutputs, | ||
| buildGreenhouseExtraFields, | ||
| greenhouseSetupInstructions, | ||
| greenhouseTriggerOptions, | ||
| } from '@/triggers/greenhouse/utils' | ||
| import type { TriggerConfig } from '@/triggers/types' | ||
|
|
||
| /** | ||
| * Greenhouse Candidate Hired Trigger | ||
| * | ||
| * This is the PRIMARY trigger - it includes the dropdown for selecting trigger type. | ||
| * Fires when a candidate is marked as hired in Greenhouse. | ||
| */ | ||
| export const greenhouseCandidateHiredTrigger: TriggerConfig = { | ||
| id: 'greenhouse_candidate_hired', | ||
| name: 'Greenhouse Candidate Hired', | ||
| provider: 'greenhouse', | ||
| description: 'Trigger workflow when a candidate is hired', | ||
| version: '1.0.0', | ||
| icon: GreenhouseIcon, | ||
|
|
||
| subBlocks: buildTriggerSubBlocks({ | ||
| triggerId: 'greenhouse_candidate_hired', | ||
| triggerOptions: greenhouseTriggerOptions, | ||
| includeDropdown: true, | ||
| setupInstructions: greenhouseSetupInstructions('Candidate Hired'), | ||
| extraFields: buildGreenhouseExtraFields('greenhouse_candidate_hired'), | ||
| }), | ||
|
|
||
| outputs: buildCandidateHiredOutputs(), | ||
|
|
||
| webhook: { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }, | ||
| } |
This file contains hidden or 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,39 @@ | ||
| import { GreenhouseIcon } from '@/components/icons' | ||
| import { buildTriggerSubBlocks } from '@/triggers' | ||
| import { | ||
| buildCandidateRejectedOutputs, | ||
| buildGreenhouseExtraFields, | ||
| greenhouseSetupInstructions, | ||
| greenhouseTriggerOptions, | ||
| } from '@/triggers/greenhouse/utils' | ||
| import type { TriggerConfig } from '@/triggers/types' | ||
|
|
||
| /** | ||
| * Greenhouse Candidate Rejected Trigger | ||
| * | ||
| * Fires when a candidate is rejected from a position. | ||
| */ | ||
| export const greenhouseCandidateRejectedTrigger: TriggerConfig = { | ||
| id: 'greenhouse_candidate_rejected', | ||
| name: 'Greenhouse Candidate Rejected', | ||
| provider: 'greenhouse', | ||
| description: 'Trigger workflow when a candidate is rejected', | ||
| version: '1.0.0', | ||
| icon: GreenhouseIcon, | ||
|
|
||
| subBlocks: buildTriggerSubBlocks({ | ||
| triggerId: 'greenhouse_candidate_rejected', | ||
| triggerOptions: greenhouseTriggerOptions, | ||
| setupInstructions: greenhouseSetupInstructions('Candidate Rejected'), | ||
| extraFields: buildGreenhouseExtraFields('greenhouse_candidate_rejected'), | ||
| }), | ||
|
|
||
| outputs: buildCandidateRejectedOutputs(), | ||
|
|
||
| webhook: { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }, | ||
| } |
This file contains hidden or 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,39 @@ | ||
| import { GreenhouseIcon } from '@/components/icons' | ||
| import { buildTriggerSubBlocks } from '@/triggers' | ||
| import { | ||
| buildCandidateStageChangeOutputs, | ||
| buildGreenhouseExtraFields, | ||
| greenhouseSetupInstructions, | ||
| greenhouseTriggerOptions, | ||
| } from '@/triggers/greenhouse/utils' | ||
| import type { TriggerConfig } from '@/triggers/types' | ||
|
|
||
| /** | ||
| * Greenhouse Candidate Stage Change Trigger | ||
| * | ||
| * Fires when a candidate moves to a different interview stage. | ||
| */ | ||
| export const greenhouseCandidateStageChangeTrigger: TriggerConfig = { | ||
| id: 'greenhouse_candidate_stage_change', | ||
| name: 'Greenhouse Candidate Stage Change', | ||
| provider: 'greenhouse', | ||
| description: 'Trigger workflow when a candidate changes interview stages', | ||
| version: '1.0.0', | ||
| icon: GreenhouseIcon, | ||
|
|
||
| subBlocks: buildTriggerSubBlocks({ | ||
| triggerId: 'greenhouse_candidate_stage_change', | ||
| triggerOptions: greenhouseTriggerOptions, | ||
| setupInstructions: greenhouseSetupInstructions('Candidate Stage Change'), | ||
| extraFields: buildGreenhouseExtraFields('greenhouse_candidate_stage_change'), | ||
| }), | ||
|
|
||
| outputs: buildCandidateStageChangeOutputs(), | ||
|
|
||
| webhook: { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }, | ||
| } |
This file contains hidden or 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,8 @@ | ||
| export { greenhouseCandidateHiredTrigger } from './candidate_hired' | ||
| export { greenhouseCandidateRejectedTrigger } from './candidate_rejected' | ||
| export { greenhouseCandidateStageChangeTrigger } from './candidate_stage_change' | ||
| export { greenhouseJobCreatedTrigger } from './job_created' | ||
| export { greenhouseJobUpdatedTrigger } from './job_updated' | ||
| export { greenhouseNewApplicationTrigger } from './new_application' | ||
| export { greenhouseOfferCreatedTrigger } from './offer_created' | ||
| export { greenhouseWebhookTrigger } from './webhook' |
This file contains hidden or 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,39 @@ | ||
| import { GreenhouseIcon } from '@/components/icons' | ||
| import { buildTriggerSubBlocks } from '@/triggers' | ||
| import { | ||
| buildGreenhouseExtraFields, | ||
| buildJobCreatedOutputs, | ||
| greenhouseSetupInstructions, | ||
| greenhouseTriggerOptions, | ||
| } from '@/triggers/greenhouse/utils' | ||
| import type { TriggerConfig } from '@/triggers/types' | ||
|
|
||
| /** | ||
| * Greenhouse Job Created Trigger | ||
| * | ||
| * Fires when a new job posting is created. | ||
| */ | ||
| export const greenhouseJobCreatedTrigger: TriggerConfig = { | ||
| id: 'greenhouse_job_created', | ||
| name: 'Greenhouse Job Created', | ||
| provider: 'greenhouse', | ||
| description: 'Trigger workflow when a new job is created', | ||
| version: '1.0.0', | ||
| icon: GreenhouseIcon, | ||
|
|
||
| subBlocks: buildTriggerSubBlocks({ | ||
| triggerId: 'greenhouse_job_created', | ||
| triggerOptions: greenhouseTriggerOptions, | ||
| setupInstructions: greenhouseSetupInstructions('Job Created'), | ||
| extraFields: buildGreenhouseExtraFields('greenhouse_job_created'), | ||
| }), | ||
|
|
||
| outputs: buildJobCreatedOutputs(), | ||
|
|
||
| webhook: { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }, | ||
| } |
This file contains hidden or 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,39 @@ | ||
| import { GreenhouseIcon } from '@/components/icons' | ||
| import { buildTriggerSubBlocks } from '@/triggers' | ||
| import { | ||
| buildGreenhouseExtraFields, | ||
| buildJobUpdatedOutputs, | ||
| greenhouseSetupInstructions, | ||
| greenhouseTriggerOptions, | ||
| } from '@/triggers/greenhouse/utils' | ||
| import type { TriggerConfig } from '@/triggers/types' | ||
|
|
||
| /** | ||
| * Greenhouse Job Updated Trigger | ||
| * | ||
| * Fires when a job posting is updated. | ||
| */ | ||
| export const greenhouseJobUpdatedTrigger: TriggerConfig = { | ||
| id: 'greenhouse_job_updated', | ||
| name: 'Greenhouse Job Updated', | ||
| provider: 'greenhouse', | ||
| description: 'Trigger workflow when a job is updated', | ||
| version: '1.0.0', | ||
| icon: GreenhouseIcon, | ||
|
|
||
| subBlocks: buildTriggerSubBlocks({ | ||
| triggerId: 'greenhouse_job_updated', | ||
| triggerOptions: greenhouseTriggerOptions, | ||
| setupInstructions: greenhouseSetupInstructions('Job Updated'), | ||
| extraFields: buildGreenhouseExtraFields('greenhouse_job_updated'), | ||
| }), | ||
|
|
||
| outputs: buildJobUpdatedOutputs(), | ||
|
|
||
| webhook: { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }, | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.