-
Notifications
You must be signed in to change notification settings - Fork 67
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
Add integrated fields endpoint for Greenhouse content #498
Draft
cometkim
wants to merge
1
commit into
main
Choose a base branch
from
greenhouse-if
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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 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 @@ | ||
/dist/ |
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,20 @@ | ||
{ | ||
"name": "prismic-if-greenhouse", | ||
"version": "0.0.0", | ||
"private": true, | ||
"type": "module", | ||
"main": "./dist/worker.js", | ||
"scripts": { | ||
"wrangler": "wrangler" | ||
}, | ||
"dependencies": { | ||
"greenhouse-jobboard-js": "^0.3.0", | ||
"worktop": "0.7.3" | ||
}, | ||
"devDependencies": { | ||
"@cloudflare/workers-types": "3.3.1", | ||
"@cloudflare/wrangler": "1.19.8", | ||
"esbuild": "0.14.22", | ||
"typescript": "4.5.5" | ||
} | ||
} |
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,103 @@ | ||
/// <reference types="@cloudflare/workers-types" /> | ||
|
||
import { Router } from 'worktop'; | ||
import * as CORS from 'worktop/cors'; | ||
import * as Cache from 'worktop/cache'; | ||
import { JobBoardClientV1 } from 'greenhouse-jobboard-js'; | ||
|
||
const API = new Router(); | ||
|
||
API.prepare = CORS.preflight(); | ||
|
||
const MAX_PER_PAGE = 50; | ||
|
||
API.add('GET', '/if/boards/:boardToken/jobs', async (req, res) => { | ||
const { boardToken } = req.params; | ||
const page = +(req.query.get('page') || 1); | ||
const offset = (page - 1) * MAX_PER_PAGE; | ||
|
||
const jobBoardClient = new JobBoardClientV1({ | ||
boardToken, | ||
client: jsonClient, | ||
}); | ||
|
||
const jobs = await jobBoardClient.getJobListWithContent(); | ||
const jobsSlice = jobs.slice(offset, MAX_PER_PAGE); | ||
|
||
const result: IntegrationFieldsFormat = { | ||
results_size: jobs.length, | ||
results: jobsSlice.map(job => ({ | ||
id: job.id.toString(), | ||
title: job.title, | ||
description: '', | ||
image_url: '', | ||
last_update: new Date(job.updated_at).getTime(), | ||
blob: job, | ||
})), | ||
}; | ||
|
||
res.send(200, result); | ||
}); | ||
|
||
API.add('GET', '/if/boards/:boardToken/departments', async (req, res) => { | ||
const { boardToken } = req.params; | ||
const page = +(req.query.get('page') || 1); | ||
const offset = (page - 1) * MAX_PER_PAGE; | ||
|
||
const jobBoardClient = new JobBoardClientV1({ | ||
boardToken, | ||
client: jsonClient, | ||
}); | ||
|
||
const departments = await jobBoardClient.getDepartmentList(); | ||
const leafDepartments = departments | ||
.filter(department => department.id !== 0) | ||
.filter(department => !department.child_ids.length); | ||
const departmentsSlice = leafDepartments.slice(offset, MAX_PER_PAGE); | ||
|
||
const result: IntegrationFieldsFormat = { | ||
results_size: leafDepartments.length, | ||
results: departmentsSlice.map(department => ({ | ||
id: department.id.toString(), | ||
title: department.name, | ||
description: '', | ||
image_url: '', | ||
last_update: Date.now(), | ||
blob: department, | ||
})), | ||
}; | ||
|
||
res.send(200, result); | ||
}); | ||
|
||
Cache.listen(API.run); | ||
|
||
type IntegrationFieldsFormat = { | ||
results_size: number, | ||
results: IntegrationFieldsItem[], | ||
}; | ||
|
||
type IntegrationFieldsItem = { | ||
id: string, | ||
title: string, | ||
description: string, | ||
image_url: string, | ||
last_update: number, | ||
blob: unknown, | ||
}; | ||
|
||
const jsonClient = { | ||
async get(url: URL) { | ||
try { | ||
const response = await fetch(url.toString()); | ||
const body = await response.json(); | ||
return body; | ||
} catch (cause) { | ||
throw new Error( | ||
`Failed to fetch the resource from job board: ${url.toString()}`, | ||
// @ts-ignore | ||
{ cause }, | ||
); | ||
} | ||
}, | ||
}; |
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,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["DOM.Iterable", "WebWorker", "ES2020"], | ||
"strict": true, | ||
"esModuleInterop": true, | ||
"downlevelIteration": true | ||
} | ||
} |
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,12 @@ | ||
name = 'prismic-if-greenhouse' | ||
type = 'javascript' | ||
compatibility_date = '2022-02-17' | ||
account_id = 'aad5c82543cd1f267b89737d0f56405e' | ||
usage_model = 'unbound' | ||
workers_dev = true | ||
|
||
[build] | ||
command = 'yarn esbuild src/worker.ts --bundle --outfile=dist/worker.js --format=esm' | ||
|
||
[build.upload] | ||
format = 'service-worker' |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
글로벌 공고를 필드에서 활용하려면 알려진 보드 토큰을 다 긁도록 수정이 필요함