@thejob/pages-client
v1.0.1
Published
Typed TypeScript/JavaScript client for the thejob-page-service HTTP API.
Readme
@thejob/pages-client
Typed client for the thejob-page-service HTTP API. One method per endpoint.
import { PagesClient } from '@thejob/pages-client';
const pages = new PagesClient({
baseUrl: process.env.PAGE_SERVICE_URL!,
apiKey: process.env.PAGE_SERVICE_API_KEY, // backend-to-backend
});
const { results, total } = await pages.listPages({
filter: { status: ['published'], type: ['company'] },
limit: 6,
});total is the count for the FILTER, not the number of rows returned, so a digest
showing six cards under "1,198 companies" stays honest when limit changes.
The filter is nested, unlike jobs/users
This is the one place this client differs from @thejob/jobs-client and
@thejob/users-client, and it is worth knowing before you hand-build a URL.
Those services read facets from the top level. page-service reads them from a
filter[...] wrapper and splits each value on commas:
{ filter: { status: ['published', 'draft'] } } -> ?filter[status]=published,draftThe client owns that encoding. Two consequences you would otherwise hit:
- Never send a nested array.
filter[status][0]=publishedmakes the service's greedy/^filter\[(.+)\]$/read the field name asstatus][0, which used to mean 200 OK with zero rows and no error. The service now rejects it with a 400, and this client never produces it. - A filter value cannot contain a comma. The service splits unconditionally with no escape convention, so the client throws rather than let a value shred into terms that match nothing.
Facets
The vocabulary is PageFilterSchema in @thejob/schema — the same declaration
page-service validates incoming keys against, so a facet cannot exist on one side
and not the other. An unknown key is a 400 that lists what is supported.
Two traps the schema now closes, both verified against production data:
- The field is
type, notpageType. The enum constant is namedPageType, which makespageTypethe obvious guess; it exists on 0 of 1,449 documents. categoriesis not filterable.PageSchemadeclares an array of strings, but pages store{ id, name }objects, so a string comparison matches nothing. It is left out rather than shipped as a facet that silently returns nobody.
featuredMarkets is stored LOWERCASE (in, se, ww). Send it lowercase.
Auth
apiKey sends x-api-key (backend-to-backend). token sends
Authorization: Bearer for routes behind requireUser / requireAdmin.
Any non-2xx throws PagesClientError, carrying status and the parsed body.
