@chrisdothtml/job-scraper 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +71 -0
- package/dist/cache.d.ts +64 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +146 -0
- package/dist/cache.js.map +1 -0
- package/dist/companies.d.ts +89 -0
- package/dist/companies.d.ts.map +1 -0
- package/dist/companies.js +244 -0
- package/dist/companies.js.map +1 -0
- package/dist/companies.seed.d.ts +9 -0
- package/dist/companies.seed.d.ts.map +1 -0
- package/dist/companies.seed.js +455 -0
- package/dist/companies.seed.js.map +1 -0
- package/dist/constants.d.ts +8 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +14 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +69 -0
- package/dist/index.js.map +1 -0
- package/dist/paths.d.ts +16 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +17 -0
- package/dist/paths.js.map +1 -0
- package/dist/platform/browser.d.ts +3 -0
- package/dist/platform/browser.d.ts.map +1 -0
- package/dist/platform/browser.js +103 -0
- package/dist/platform/browser.js.map +1 -0
- package/dist/platform/node.d.ts +3 -0
- package/dist/platform/node.d.ts.map +1 -0
- package/dist/platform/node.js +106 -0
- package/dist/platform/node.js.map +1 -0
- package/dist/platform/types.d.ts +46 -0
- package/dist/platform/types.d.ts.map +1 -0
- package/dist/platform/types.js +2 -0
- package/dist/platform/types.js.map +1 -0
- package/dist/resolve.d.ts +89 -0
- package/dist/resolve.d.ts.map +1 -0
- package/dist/resolve.js +379 -0
- package/dist/resolve.js.map +1 -0
- package/dist/scrapers/AshbyScraper.d.ts +16 -0
- package/dist/scrapers/AshbyScraper.d.ts.map +1 -0
- package/dist/scrapers/AshbyScraper.js +207 -0
- package/dist/scrapers/AshbyScraper.js.map +1 -0
- package/dist/scrapers/GitHubScraper.d.ts +8 -0
- package/dist/scrapers/GitHubScraper.d.ts.map +1 -0
- package/dist/scrapers/GitHubScraper.js +61 -0
- package/dist/scrapers/GitHubScraper.js.map +1 -0
- package/dist/scrapers/GoogleScraper.d.ts +8 -0
- package/dist/scrapers/GoogleScraper.d.ts.map +1 -0
- package/dist/scrapers/GoogleScraper.js +83 -0
- package/dist/scrapers/GoogleScraper.js.map +1 -0
- package/dist/scrapers/GreenhouseScraper.d.ts +28 -0
- package/dist/scrapers/GreenhouseScraper.d.ts.map +1 -0
- package/dist/scrapers/GreenhouseScraper.js +68 -0
- package/dist/scrapers/GreenhouseScraper.js.map +1 -0
- package/dist/scrapers/LeverScraper.d.ts +13 -0
- package/dist/scrapers/LeverScraper.d.ts.map +1 -0
- package/dist/scrapers/LeverScraper.js +58 -0
- package/dist/scrapers/LeverScraper.js.map +1 -0
- package/dist/scrapers/NetflixScraper.d.ts +8 -0
- package/dist/scrapers/NetflixScraper.d.ts.map +1 -0
- package/dist/scrapers/NetflixScraper.js +60 -0
- package/dist/scrapers/NetflixScraper.js.map +1 -0
- package/dist/scrapers/NvidiaScraper.d.ts +8 -0
- package/dist/scrapers/NvidiaScraper.d.ts.map +1 -0
- package/dist/scrapers/NvidiaScraper.js +61 -0
- package/dist/scrapers/NvidiaScraper.js.map +1 -0
- package/dist/scrapers/RipplingScraper.d.ts +10 -0
- package/dist/scrapers/RipplingScraper.d.ts.map +1 -0
- package/dist/scrapers/RipplingScraper.js +64 -0
- package/dist/scrapers/RipplingScraper.js.map +1 -0
- package/dist/scrapers/Scraper.d.ts +134 -0
- package/dist/scrapers/Scraper.d.ts.map +1 -0
- package/dist/scrapers/Scraper.js +224 -0
- package/dist/scrapers/Scraper.js.map +1 -0
- package/dist/scrapers/ShopifyScraper.d.ts +16 -0
- package/dist/scrapers/ShopifyScraper.d.ts.map +1 -0
- package/dist/scrapers/ShopifyScraper.js +104 -0
- package/dist/scrapers/ShopifyScraper.js.map +1 -0
- package/dist/scrapers/SmartRecruitersScraper.d.ts +13 -0
- package/dist/scrapers/SmartRecruitersScraper.d.ts.map +1 -0
- package/dist/scrapers/SmartRecruitersScraper.js +66 -0
- package/dist/scrapers/SmartRecruitersScraper.js.map +1 -0
- package/dist/scrapers/UberScraper.d.ts +14 -0
- package/dist/scrapers/UberScraper.d.ts.map +1 -0
- package/dist/scrapers/UberScraper.js +94 -0
- package/dist/scrapers/UberScraper.js.map +1 -0
- package/dist/scrapers/WorkableScraper.d.ts +12 -0
- package/dist/scrapers/WorkableScraper.d.ts.map +1 -0
- package/dist/scrapers/WorkableScraper.js +67 -0
- package/dist/scrapers/WorkableScraper.js.map +1 -0
- package/dist/scrapers/WorkdayScraper.d.ts +14 -0
- package/dist/scrapers/WorkdayScraper.d.ts.map +1 -0
- package/dist/scrapers/WorkdayScraper.js +85 -0
- package/dist/scrapers/WorkdayScraper.js.map +1 -0
- package/dist/scrapers/index.d.ts +41 -0
- package/dist/scrapers/index.d.ts.map +1 -0
- package/dist/scrapers/index.js +46 -0
- package/dist/scrapers/index.js.map +1 -0
- package/dist/search.d.ts +75 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +225 -0
- package/dist/search.js.map +1 -0
- package/dist/sniff.d.ts +43 -0
- package/dist/sniff.d.ts.map +1 -0
- package/dist/sniff.js +124 -0
- package/dist/sniff.js.map +1 -0
- package/dist/utils/misc.d.ts +15 -0
- package/dist/utils/misc.d.ts.map +1 -0
- package/dist/utils/misc.js +31 -0
- package/dist/utils/misc.js.map +1 -0
- package/package.json +70 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { createScraper, resolveCompany, resolveJob, } from "./resolve.js";
|
|
2
|
+
import {} from "./scrapers/Scraper.js";
|
|
3
|
+
export { clearCache, configureCache, CorsError, getCacheConfig, HttpError, } from "./cache.js";
|
|
4
|
+
export { seedCompanies } from "./companies.seed.js";
|
|
5
|
+
export { addCompanyDomain, clearCompaniesCache, findCompany, findCompanyByDomain, isBoardDomain, listCompanies, loadCompanies, mergeRegistry, normalizeCompanyName, normalizeDomain, registerCompany, } from "./companies.js";
|
|
6
|
+
export { cacheDir, companiesFile, dataDir } from "./paths.js";
|
|
7
|
+
export { boardHints, companyNameCandidates, companyNameFromUrl, createScraper, jobIdFromUrl, parseJobUrl, resolveCompany, resolveJob, UnresolvedCompanyError, } from "./resolve.js";
|
|
8
|
+
export { discoverableScrapers, getScraper, isScraperName, Scraper, scraperNames, scrapers, } from "./scrapers/index.js";
|
|
9
|
+
export { JobNotFoundError } from "./scrapers/Scraper.js";
|
|
10
|
+
export { canSearch, clearSearchCache, configureSearch, getSearchConfig, searchForBoards, searchForBoardsBatch, } from "./search.js";
|
|
11
|
+
export { findBoardsInPage, findNamesInPage, sniffBoards, sniffPage, } from "./sniff.js";
|
|
12
|
+
export { time } from "./utils/misc.js";
|
|
13
|
+
/**
|
|
14
|
+
* Lists every job a company currently has posted.
|
|
15
|
+
*
|
|
16
|
+
* Accepts a company name, a careers board URL, or an explicit
|
|
17
|
+
* `{ scraper, slug }` pair. When only a name is given and the company isn't
|
|
18
|
+
* in the registry yet, the known job boards are probed for a matching slug;
|
|
19
|
+
* a match is remembered for next time.
|
|
20
|
+
*
|
|
21
|
+
* @throws {UnresolvedCompanyError} when no scraper serves the company
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* await listCompanyJobs('Airbnb');
|
|
25
|
+
* await listCompanyJobs('https://jobs.ashbyhq.com/zapier');
|
|
26
|
+
* await listCompanyJobs({ company: 'Ramp', scraper: 'GreenhouseScraper' });
|
|
27
|
+
*/
|
|
28
|
+
export async function listCompanyJobs(input) {
|
|
29
|
+
const company = await resolveCompany(input);
|
|
30
|
+
const scraper = createScraper(company);
|
|
31
|
+
try {
|
|
32
|
+
return await scraper.getJobsList();
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
scraper.dispose();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Fetches a single job posting, including its full content.
|
|
40
|
+
*
|
|
41
|
+
* Takes either a job posting URL, or a company (name, or explicit
|
|
42
|
+
* scraper/slug) plus the job's `id`.
|
|
43
|
+
*
|
|
44
|
+
* @throws {UnresolvedCompanyError} when no scraper serves the company
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* await fetchJob('https://job-boards.greenhouse.io/airbnb/jobs/7712345');
|
|
48
|
+
* await fetchJob({ company: 'Airbnb', id: '7712345' });
|
|
49
|
+
*/
|
|
50
|
+
export async function fetchJob(input) {
|
|
51
|
+
const options = typeof input === 'string'
|
|
52
|
+
? URL.canParse(input)
|
|
53
|
+
? { url: input }
|
|
54
|
+
: { company: input }
|
|
55
|
+
: input;
|
|
56
|
+
const resolved = await resolveJob(options);
|
|
57
|
+
const id = options.id ?? resolved.jobId;
|
|
58
|
+
if (!id) {
|
|
59
|
+
throw new TypeError(`No job id given, and none could be read from '${options.url ?? ''}'`);
|
|
60
|
+
}
|
|
61
|
+
const scraper = createScraper(resolved);
|
|
62
|
+
try {
|
|
63
|
+
return await scraper.getJob(id);
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
scraper.dispose();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,cAAc,EACd,UAAU,GAEX,MAAM,cAAc,CAAC;AACtB,OAAO,EAA4B,MAAM,uBAAuB,CAAC;AAEjE,OAAO,EACL,UAAU,EACV,cAAc,EACd,SAAS,EACT,cAAc,EACd,SAAS,GAEV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,aA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C,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE;YAChB,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE;QACtB,CAAC,CAAC,KAAK,CAAC;IACZ,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,CAAC;IAC3C,MAAM,EAAE,GAAG,OAAO,CAAC,EAAE,IAAI,QAAQ,CAAC,KAAK,CAAC;IAExC,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,MAAM,IAAI,SAAS,CACjB,iDAAiD,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,CACtE,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IACxC,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAClC,CAAC;YAAS,CAAC;QACT,OAAO,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;AACH,CAAC"}
|
package/dist/paths.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where this package keeps its mutable state: the company registry, the HTTP
|
|
3
|
+
* response cache, and search accounting.
|
|
4
|
+
*
|
|
5
|
+
* It lives in the user's home directory rather than the working directory so
|
|
6
|
+
* that every project on the machine shares it: a company should only need
|
|
7
|
+
* discovering once, and a board fetched by one project shouldn't be fetched
|
|
8
|
+
* again by the next. Override with `JOB_SCRAPER_DATA_DIR`.
|
|
9
|
+
*
|
|
10
|
+
* Node only. Browsers have no filesystem, so there these are just the names
|
|
11
|
+
* the same state goes by (the Cache API cache, and `localStorage` keys).
|
|
12
|
+
*/
|
|
13
|
+
export declare const dataDir: string;
|
|
14
|
+
export declare const cacheDir: string;
|
|
15
|
+
export declare const companiesFile: string;
|
|
16
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,OAAO,EAAE,MAAyB,CAAC;AAEhD,eAAO,MAAM,QAAQ,EAAE,MAA0B,CAAC;AAClD,eAAO,MAAM,aAAa,EAAE,MAA+B,CAAC"}
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { platform } from '#platform';
|
|
2
|
+
/**
|
|
3
|
+
* Where this package keeps its mutable state: the company registry, the HTTP
|
|
4
|
+
* response cache, and search accounting.
|
|
5
|
+
*
|
|
6
|
+
* It lives in the user's home directory rather than the working directory so
|
|
7
|
+
* that every project on the machine shares it: a company should only need
|
|
8
|
+
* discovering once, and a board fetched by one project shouldn't be fetched
|
|
9
|
+
* again by the next. Override with `JOB_SCRAPER_DATA_DIR`.
|
|
10
|
+
*
|
|
11
|
+
* Node only. Browsers have no filesystem, so there these are just the names
|
|
12
|
+
* the same state goes by (the Cache API cache, and `localStorage` keys).
|
|
13
|
+
*/
|
|
14
|
+
export const dataDir = platform.dataDir;
|
|
15
|
+
export const cacheDir = platform.cacheDir;
|
|
16
|
+
export const companiesFile = platform.companiesFile;
|
|
17
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,OAAO,GAAW,QAAQ,CAAC,OAAO,CAAC;AAEhD,MAAM,CAAC,MAAM,QAAQ,GAAW,QAAQ,CAAC,QAAQ,CAAC;AAClD,MAAM,CAAC,MAAM,aAAa,GAAW,QAAQ,CAAC,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/platform/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAsB,MAAM,YAAY,CAAC;AAmG/D,eAAO,MAAM,QAAQ,EAAE,QAgCtB,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {} from "./types.js";
|
|
2
|
+
const scope = globalThis;
|
|
3
|
+
// in browsers the "paths" are a key prefix rather than a directory: the
|
|
4
|
+
// cache dir names the Cache API cache, and files are `localStorage` keys
|
|
5
|
+
const dataDir = 'job-scraper';
|
|
6
|
+
// writes `localStorage` couldn't take (missing, blocked, or full), so state
|
|
7
|
+
// still carries this session, just not a reload. Only those keys are read
|
|
8
|
+
// from here: everything else comes from `localStorage`, so another tab's
|
|
9
|
+
// writes are never shadowed by a stale copy of our own
|
|
10
|
+
const unpersisted = new Map();
|
|
11
|
+
// stamped on every stored response, since the Cache API keeps no write time
|
|
12
|
+
const CACHED_AT = 'x-job-scraper-cached-at';
|
|
13
|
+
// Cache API keys must be http(s) requests; a reserved TLD guarantees it
|
|
14
|
+
// never collides with a real one
|
|
15
|
+
function cacheKey(key) {
|
|
16
|
+
return `https://job-scraper.invalid/?${encodeURIComponent(key)}`;
|
|
17
|
+
}
|
|
18
|
+
const responseCache = {
|
|
19
|
+
async get(dir, key, ttl) {
|
|
20
|
+
if (!scope.caches)
|
|
21
|
+
return null;
|
|
22
|
+
try {
|
|
23
|
+
const cache = await scope.caches.open(dir);
|
|
24
|
+
const hit = await cache.match(cacheKey(key));
|
|
25
|
+
if (!hit)
|
|
26
|
+
return null;
|
|
27
|
+
// a missing stamp reads as NaN, which fails the check: treat as stale
|
|
28
|
+
const age = Math.max(0, Date.now() - Number(hit.headers.get(CACHED_AT)));
|
|
29
|
+
if (!(age < ttl))
|
|
30
|
+
return null;
|
|
31
|
+
const headers = new Headers(hit.headers);
|
|
32
|
+
headers.delete(CACHED_AT);
|
|
33
|
+
return new Response(await hit.arrayBuffer(), {
|
|
34
|
+
status: hit.status,
|
|
35
|
+
statusText: hit.statusText,
|
|
36
|
+
headers,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
async put(dir, key, { body, status, statusText, headers }) {
|
|
44
|
+
if (!scope.caches)
|
|
45
|
+
return;
|
|
46
|
+
try {
|
|
47
|
+
const cache = await scope.caches.open(dir);
|
|
48
|
+
const stamped = new Headers(headers);
|
|
49
|
+
stamped.set(CACHED_AT, String(Date.now()));
|
|
50
|
+
await cache.put(cacheKey(key), new Response(body, { status, statusText, headers: stamped }));
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// a full or unavailable cache just means the next request refetches
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
async clear(dir) {
|
|
57
|
+
if (!scope.caches)
|
|
58
|
+
return 0;
|
|
59
|
+
try {
|
|
60
|
+
const cache = await scope.caches.open(dir);
|
|
61
|
+
const count = (await cache.keys()).length;
|
|
62
|
+
await scope.caches.delete(dir);
|
|
63
|
+
return count;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
export const platform = {
|
|
71
|
+
enforcesCors: true,
|
|
72
|
+
// there's no environment to read; configure via `configureCache` and co.
|
|
73
|
+
env: () => undefined,
|
|
74
|
+
dataDir,
|
|
75
|
+
cacheDir: `${dataDir}/cache`,
|
|
76
|
+
companiesFile: `${dataDir}/companies.json`,
|
|
77
|
+
dataFile: (name) => `${dataDir}/${name}`,
|
|
78
|
+
async readText(file) {
|
|
79
|
+
if (unpersisted.has(file))
|
|
80
|
+
return unpersisted.get(file);
|
|
81
|
+
try {
|
|
82
|
+
return scope.localStorage?.getItem(file) ?? null;
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
async writeText(file, contents) {
|
|
89
|
+
try {
|
|
90
|
+
if (!scope.localStorage)
|
|
91
|
+
throw new Error('No localStorage');
|
|
92
|
+
scope.localStorage.setItem(file, contents);
|
|
93
|
+
unpersisted.delete(file);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
unpersisted.set(file, contents);
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
responseCache,
|
|
100
|
+
// only reached from unbuilt sources, which have no baked-in version
|
|
101
|
+
sourceVersion: () => '0.0.0-source',
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/platform/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqC,MAAM,YAAY,CAAC;AAoB/D,MAAM,KAAK,GAAG,UAGb,CAAC;AAEF,wEAAwE;AACxE,yEAAyE;AACzE,MAAM,OAAO,GAAG,aAAa,CAAC;AAE9B,4EAA4E;AAC5E,0EAA0E;AAC1E,yEAAyE;AACzE,uDAAuD;AACvD,MAAM,WAAW,GAAG,IAAI,GAAG,EAAkB,CAAC;AAE9C,4EAA4E;AAC5E,MAAM,SAAS,GAAG,yBAAyB,CAAC;AAE5C,wEAAwE;AACxE,iCAAiC;AACjC,SAAS,QAAQ,CAAC,GAAW;IAC3B,OAAO,gCAAgC,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC;AACnE,CAAC;AAED,MAAM,aAAa,GAAkB;IACnC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG;QACrB,IAAI,CAAC,KAAK,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC;QAE/B,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC3C,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;YAC7C,IAAI,CAAC,GAAG;gBAAE,OAAO,IAAI,CAAC;Y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AAC,iBAAiB,CAAC,CAAC;YAC5D,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YAC3C,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC;QAAC,MAAM,CAAC;YACP,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;IAED,aAAa;IACb,oEAAoE;IACpE,aAAa,EAAE,GAAG,EAAE,CAAC,cAAc;CACpC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/platform/node.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,QAAQ,EAAsB,MAAM,YAAY,CAAC;AAqF/D,eAAO,MAAM,QAAQ,EAAE,QA8BtB,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fsSync from 'node:fs';
|
|
3
|
+
import fs from 'node:fs/promises';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import process from 'node:process';
|
|
7
|
+
import {} from "./types.js";
|
|
8
|
+
// read on access rather than at import, so that whatever imports this first
|
|
9
|
+
// (`constants.ts`, say) doesn't pin the data dir before a caller sets it
|
|
10
|
+
function dataDir() {
|
|
11
|
+
return path.resolve(process.env.JOB_SCRAPER_DATA_DIR || path.join(os.homedir(), '.job-scraper'));
|
|
12
|
+
}
|
|
13
|
+
const ensured = new Set();
|
|
14
|
+
/** Creates a directory once per process; safe to call on every write */
|
|
15
|
+
async function ensureDir(dir) {
|
|
16
|
+
if (!ensured.has(dir)) {
|
|
17
|
+
await fs.mkdir(dir, { recursive: true });
|
|
18
|
+
ensured.add(dir);
|
|
19
|
+
}
|
|
20
|
+
return dir;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Writes a file atomically. The data dir is shared across every project on
|
|
24
|
+
* the machine, so two processes can be writing the registry at once; a
|
|
25
|
+
* temp-then-rename keeps a reader from ever seeing a half-written file.
|
|
26
|
+
*/
|
|
27
|
+
async function writeFileAtomic(filePath, contents) {
|
|
28
|
+
await ensureDir(path.dirname(filePath));
|
|
29
|
+
const temp = `${filePath}.${process.pid}.tmp`;
|
|
30
|
+
await fs.writeFile(temp, contents);
|
|
31
|
+
await fs.rename(temp, filePath);
|
|
32
|
+
}
|
|
33
|
+
function cacheFilePath(dir, key) {
|
|
34
|
+
const hash = crypto.createHash('sha256').update(key).digest('hex');
|
|
35
|
+
return path.join(dir, hash + '.json');
|
|
36
|
+
}
|
|
37
|
+
const responseCache = {
|
|
38
|
+
async get(dir, key, ttl) {
|
|
39
|
+
const file = cacheFilePath(dir, key);
|
|
40
|
+
try {
|
|
41
|
+
const { mtimeMs } = await fs.stat(file);
|
|
42
|
+
// `mtimeMs` carries sub-millisecond precision that `Date.now()`
|
|
43
|
+
// truncates, so a just-written entry can read as slightly negative age;
|
|
44
|
+
// clamping keeps `ttl: 0` meaning "always stale" rather than "always
|
|
45
|
+
// fresh"
|
|
46
|
+
const age = Math.max(0, Date.now() - mtimeMs);
|
|
47
|
+
if (age >= ttl)
|
|
48
|
+
return null;
|
|
49
|
+
const cached = JSON.parse(await fs.readFile(file, 'utf8'));
|
|
50
|
+
return new Response(Buffer.from(cached.body, 'base64'), {
|
|
51
|
+
status: cached.status,
|
|
52
|
+
statusText: cached.statusText,
|
|
53
|
+
headers: cached.headers,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
async put(dir, key, { body, ...res }) {
|
|
61
|
+
await ensureDir(dir);
|
|
62
|
+
const payload = { ...res, body: Buffer.from(body).toString('base64') };
|
|
63
|
+
await fs.writeFile(cacheFilePath(dir, key), JSON.stringify(payload));
|
|
64
|
+
},
|
|
65
|
+
async clear(dir) {
|
|
66
|
+
try {
|
|
67
|
+
const files = await fs.readdir(dir);
|
|
68
|
+
const cached = files.filter((file) => file.endsWith('.json'));
|
|
69
|
+
await Promise.all(cached.map((file) => fs.rm(path.join(dir, file))));
|
|
70
|
+
return cached.length;
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
export const platform = {
|
|
78
|
+
enforcesCors: false,
|
|
79
|
+
env: (name) => process.env[name],
|
|
80
|
+
get dataDir() {
|
|
81
|
+
return dataDir();
|
|
82
|
+
},
|
|
83
|
+
get cacheDir() {
|
|
84
|
+
return path.join(dataDir(), 'cache');
|
|
85
|
+
},
|
|
86
|
+
get companiesFile() {
|
|
87
|
+
return path.join(dataDir(), 'companies.json');
|
|
88
|
+
},
|
|
89
|
+
dataFile: (name) => path.join(dataDir(), name),
|
|
90
|
+
async readText(file) {
|
|
91
|
+
try {
|
|
92
|
+
return await fs.readFile(file, 'utf8');
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
writeText: writeFileAtomic,
|
|
99
|
+
responseCache,
|
|
100
|
+
sourceVersion() {
|
|
101
|
+
// the same depth from both `src/platform` and `dist/platform`
|
|
102
|
+
const pkgFile = path.resolve(import.meta.dirname, '../../package.json');
|
|
103
|
+
return JSON.parse(fsSync.readFileSync(pkgFile, 'utf8')).version;
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/platform/node.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,MAAM,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAA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jB,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACzC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,SAAS,EAAE,eAAe;IAC1B,aAAa;IAEb,aAAa;QACX,8DAA8D;QAC9D,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC;QACxE,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IAClE,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everything the core needs from the runtime it's running in. `#platform`
|
|
3
|
+
* resolves to the Node or the browser implementation by export condition (see
|
|
4
|
+
* `imports` in package.json), which is what keeps every `node:` import out of
|
|
5
|
+
* a browser bundle. Both implement this one interface, so there's one set of
|
|
6
|
+
* types for both.
|
|
7
|
+
*/
|
|
8
|
+
export interface Platform {
|
|
9
|
+
/**
|
|
10
|
+
* Whether the runtime enforces CORS, i.e. whether a fetch rejecting with a
|
|
11
|
+
* `TypeError` can mean a board refused a cross-origin request
|
|
12
|
+
*/
|
|
13
|
+
readonly enforcesCors: boolean;
|
|
14
|
+
/** Reads a setting from the environment. Always unset in browsers */
|
|
15
|
+
env(name: string): string | undefined;
|
|
16
|
+
readonly dataDir: string;
|
|
17
|
+
readonly cacheDir: string;
|
|
18
|
+
readonly companiesFile: string;
|
|
19
|
+
/** Where a named piece of state (`search-usage.json`, say) is kept */
|
|
20
|
+
dataFile(name: string): string;
|
|
21
|
+
/** Reads a small text document, e.g. the registry. Null when there's none */
|
|
22
|
+
readText(file: string): Promise<string | null>;
|
|
23
|
+
/** Replaces a small text document whole */
|
|
24
|
+
writeText(file: string, contents: string): Promise<void>;
|
|
25
|
+
readonly responseCache: ResponseCache;
|
|
26
|
+
/** The package.json version. Only consulted by unbuilt sources */
|
|
27
|
+
sourceVersion(): string;
|
|
28
|
+
}
|
|
29
|
+
export interface CachedResponse {
|
|
30
|
+
status: number;
|
|
31
|
+
statusText: string;
|
|
32
|
+
headers: [string, string][];
|
|
33
|
+
body: ArrayBuffer;
|
|
34
|
+
}
|
|
35
|
+
/** Where `cachedFetch` keeps response bodies */
|
|
36
|
+
export interface ResponseCache {
|
|
37
|
+
/**
|
|
38
|
+
* The response stored under `key` in `dir`, or null when there's none or
|
|
39
|
+
* it's at least `ttl` milliseconds old
|
|
40
|
+
*/
|
|
41
|
+
get(dir: string, key: string, ttl: number): Promise<Response | null>;
|
|
42
|
+
put(dir: string, key: string, res: CachedResponse): Promise<void>;
|
|
43
|
+
/** Deletes every response in `dir`. Returns how many were removed */
|
|
44
|
+
clear(dir: string): Promise<number>;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/platform/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,WAAW,QAAQ;IACvB;;;OAGG;IACH,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,qEAAqE;IACrE,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,sEAAsE;IACtE,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,6EAA6E;IAC7E,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC/C,2CAA2C;IAC3C,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzD,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,kEAAkE;IAClE,aAAa,IAAI,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IAC5B,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,gDAAgD;AAChD,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;IACrE,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClE,qEAAqE;IACrE,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACrC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/platform/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { type Company } from './companies.ts';
|
|
2
|
+
import { type ScraperName } from './scrapers/index.ts';
|
|
3
|
+
import { type Scraper } from './scrapers/Scraper.ts';
|
|
4
|
+
/** Thrown when no scraper in this package can serve the requested company */
|
|
5
|
+
export declare class UnresolvedCompanyError extends Error {
|
|
6
|
+
input: string;
|
|
7
|
+
/**
|
|
8
|
+
* Whether the browser blocked any board or page tried along the way (see
|
|
9
|
+
* `CorsError`). When it did, the company may well resolve from Node,
|
|
10
|
+
* which doesn't enforce CORS.
|
|
11
|
+
*/
|
|
12
|
+
blocked: boolean;
|
|
13
|
+
constructor(input: string, message?: string,
|
|
14
|
+
/**
|
|
15
|
+
* Whether the browser blocked any board or page tried along the way (see
|
|
16
|
+
* `CorsError`). When it did, the company may well resolve from Node,
|
|
17
|
+
* which doesn't enforce CORS.
|
|
18
|
+
*/
|
|
19
|
+
blocked?: boolean);
|
|
20
|
+
}
|
|
21
|
+
export interface CompanyInput {
|
|
22
|
+
/** Company name, e.g. `"Airbnb"` or `"apollo.io"` */
|
|
23
|
+
company?: string;
|
|
24
|
+
/** A careers board or job posting URL */
|
|
25
|
+
url?: string;
|
|
26
|
+
/** Skip resolution and use this scraper */
|
|
27
|
+
scraper?: ScraperName;
|
|
28
|
+
/** Skip slug discovery and use this board slug */
|
|
29
|
+
slug?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Whether to fall back to a web search when slug guessing fails.
|
|
32
|
+
* Defaults to on when a SerpApi key is configured.
|
|
33
|
+
*/
|
|
34
|
+
search?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* How many real postings a board needs before discovery will register it,
|
|
37
|
+
* placeholders like "Test UAT" not counting. Guessing a slug proves a board
|
|
38
|
+
* exists, not that the company uses it; plenty keep a forgotten trial
|
|
39
|
+
* account on a board they never moved to. Only applies to boards found by
|
|
40
|
+
* probing or search; a URL or registry entry is trusted as is.
|
|
41
|
+
* @default 3
|
|
42
|
+
*/
|
|
43
|
+
minJobs?: number;
|
|
44
|
+
}
|
|
45
|
+
export interface ResolvedCompany extends Company {
|
|
46
|
+
/** True when the company was resolved by probing rather than looked up */
|
|
47
|
+
discovered: boolean;
|
|
48
|
+
}
|
|
49
|
+
/** A resolved company plus the job id, when the input pointed at one posting */
|
|
50
|
+
export interface ResolvedJob extends ResolvedCompany {
|
|
51
|
+
jobId: string | null;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Turns loose input (a company name, a URL, an explicit scraper) into a
|
|
55
|
+
* concrete company record. Companies found by probing are added to the
|
|
56
|
+
* registry so the next call is a plain lookup.
|
|
57
|
+
*/
|
|
58
|
+
export declare function resolveCompany(input: CompanyInput | string): Promise<ResolvedCompany>;
|
|
59
|
+
/**
|
|
60
|
+
* Like `resolveCompany`, but also recovers the job id when the input was a
|
|
61
|
+
* job posting URL.
|
|
62
|
+
*/
|
|
63
|
+
export declare function resolveJob(input: CompanyInput | string): Promise<ResolvedJob>;
|
|
64
|
+
/**
|
|
65
|
+
* Alternate readings of a company name. A careers domain or page title names
|
|
66
|
+
* the site rather than the company, so `pinterestcareers` has to be allowed
|
|
67
|
+
* to mean `pinterest`, otherwise a company already in the registry is missed
|
|
68
|
+
* purely because the link went through its own careers site.
|
|
69
|
+
*/
|
|
70
|
+
export declare function companyNameCandidates(name: string): string[];
|
|
71
|
+
/** Boards named by a URL's own tracking params, e.g. `?gh_jid=` for Greenhouse */
|
|
72
|
+
export declare function boardHints(url: URL): ScraperName[];
|
|
73
|
+
/**
|
|
74
|
+
* Best-effort company name from a careers URL hosted on the company's own
|
|
75
|
+
* domain, e.g. `https://careers.acme.com/...` -> `acme`.
|
|
76
|
+
*/
|
|
77
|
+
export declare function companyNameFromUrl(url: URL): string | null;
|
|
78
|
+
/** Best-effort job id from a URL no scraper claimed */
|
|
79
|
+
export declare function jobIdFromUrl(url: URL): string | null;
|
|
80
|
+
/** Builds the scraper instance for a resolved company */
|
|
81
|
+
export declare function createScraper(company: Company): Scraper;
|
|
82
|
+
/**
|
|
83
|
+
* Asks each scraper whether it recognizes the URL. Returns the board it
|
|
84
|
+
* belongs to, plus the job id when the URL addresses a single posting.
|
|
85
|
+
*/
|
|
86
|
+
export declare function parseJobUrl(input: string, only?: ScraperName): (ResolvedJob & {
|
|
87
|
+
discovered: false;
|
|
88
|
+
}) | null;
|
|
89
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AACA,OA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