import { U as UrlFieldExtractor, g as MetadataValue, P as PaginationCursor, f as JobLocation } from './provider-Ce-KxEDG.js'; /** * @jobo/scraper-sdk/runtime — Common Scraping Helpers * * Utility functions for common scraping patterns: URL manipulation, * data normalization, pagination, and defensive parsing. */ /** * Create an offset-based pagination cursor. * * @param offset — The offset value for the next page. * @returns A {@link PaginationCursor} with `type: "offset"`. * * @example * ```ts * return { listings, hasMore: true, nextCursor: offsetCursor(50) }; * ``` */ declare function offsetCursor(offset: number): PaginationCursor; /** * Create a page-number pagination cursor. * * @param page — The page number for the next page (1-indexed). * @returns A {@link PaginationCursor} with `type: "page"`. */ declare function pageCursor(page: number): PaginationCursor; /** * Create an opaque cursor-based pagination cursor. * * @param cursor — The opaque cursor string from the API response. * @returns A {@link PaginationCursor} with `type: "cursor"`. */ declare function cursorPagination(cursor: string): PaginationCursor; /** * Create a URL-based pagination cursor (next page URL). * * @param url — The full URL of the next page. * @returns A {@link PaginationCursor} with `type: "url"`. */ declare function urlCursor(url: string): PaginationCursor; /** * Parse the current page number from a cursor, defaulting to 1. * * @param cursor — The pagination cursor, or `undefined` for the first page. * @returns The page number as an integer. */ declare function currentPage(cursor?: PaginationCursor): number; /** * Parse the current offset from a cursor, defaulting to 0. * * @param cursor — The pagination cursor, or `undefined` for the first page. * @returns The offset as an integer. */ declare function currentOffset(cursor?: PaginationCursor): number; /** * Parse a raw location string into a {@link JobLocation} object. * * Handles common formats: * - `"San Francisco, CA"` → `{ text, city, state }` * - `"San Francisco, CA, US"` → `{ text, city, state, country }` * - `"Remote"` → `{ text, isRemote: true }` * - `"Remote (US)"` → `{ text, isRemote: true, country: "US" }` * - `"New York, NY 10001"` → `{ text, city, state, postalCode }` * * This is a best-effort parser. The platform's location pipeline will * further normalize and geocode the result. * * @param text — Raw location string as displayed on the page. * @returns A {@link JobLocation} with as many fields populated as possible. */ declare function parseLocation(text: string): JobLocation; /** * Parse multiple locations from a delimited string. * * Handles common multi-location formats: * - `"San Francisco, CA; New York, NY"` (semicolon-separated) * - `"San Francisco, CA | New York, NY"` (pipe-separated) * - `"San Francisco, CA / New York, NY"` (slash-separated) * * @param text — Raw multi-location string. * @param delimiter — Delimiter regex. Defaults to `; | /` with surrounding whitespace. * @returns Array of parsed {@link JobLocation} objects. */ declare function parseLocations(text: string, delimiter?: RegExp): JobLocation[]; /** * Safely extract a string value from an unknown data source. * Returns `undefined` if the value is null, undefined, or not a string. * * @param value — The value to extract. * @returns The string value, or `undefined`. */ declare function asString(value: unknown): string | undefined; /** * Safely extract a number value from an unknown data source. * * @param value — The value to extract. * @returns The number value, or `undefined` if not a valid number. */ declare function asNumber(value: unknown): number | undefined; /** * Safely extract an array of strings from an unknown data source. * * @param value — The value to extract. Can be a string (split by comma) or an array. * @returns Array of non-empty strings. */ declare function asStringArray(value: unknown): string[]; /** * Build a metadata map from key-value pairs, skipping null/undefined values. * * @param entries — Key-value pairs to include. * @returns A clean metadata map with only defined values. * * @example * ```ts * const meta = buildMeta( * ["employmentType", job.type], * ["department", job.dept], * ["salary", undefined], // skipped * ); * // → { employmentType: "Full-time", department: "Engineering" } * ``` */ declare function buildMeta(...entries: [string, MetadataValue | undefined][]): Record; /** * Attempt to parse a date string into an ISO 8601 string. * Returns `undefined` if the input cannot be parsed. * * Handles common formats: * - ISO 8601: `"2025-01-15T00:00:00Z"` * - US format: `"01/15/2025"`, `"January 15, 2025"` * - Relative: `"3 days ago"`, `"Posted yesterday"` * * @param dateStr — Raw date string from the ATS. * @returns ISO 8601 date string, or `undefined`. */ declare function parseDate(dateStr: string | null | undefined): string | undefined; /** * Deduplicate an array of listings by `externalId`. * The first occurrence of each ID is kept. * * @param listings — Array of listings that may contain duplicates. * @returns Deduplicated array. */ declare function deduplicateListings(listings: T[]): T[]; /** * Match a URL against a glob-style pattern. * Supports `*` (single path segment), `**` (any path), and `:param` (named segment). * * When the pattern does not contain `?`, query strings and fragments are * stripped from the URL before matching (mirrors C# UrlPatternMatcher). */ declare function matchesUrlPattern(url: string, pattern: string): boolean; /** Check if a URL matches any of the given patterns. */ declare function matchesAnyUrlPattern(url: string, patterns: string[]): boolean; /** * Extract a specific named parameter from a URL using a single glob-style template. * * When the template does not explicitly handle query parameters (i.e. contains * no `?`), query strings and fragments are stripped from the URL before matching. * This mirrors the C# `UrlPatternMatcher.NormalizeUrl` behaviour and prevents * tracking parameters like `?source=jobright` or `?utm_source=...` from * breaking otherwise valid extractions. */ declare function extractNamedParam(url: string, pattern: string, paramName: string): string | undefined; /** * Extract a named parameter from a URL by trying multiple glob-style templates. * Returns the first successful extraction. */ declare function extractParamFromUrl(url: string, patterns: string[], paramName: string): string | undefined; /** * Normalize extractor(s) to a flat array. * Accepts a single extractor, an array of extractors, or undefined. */ declare function toExtractorArray(v: UrlFieldExtractor | UrlFieldExtractor[] | undefined | null): UrlFieldExtractor[]; /** * Match a Simplify-style path pattern against a URL pathname and return * all named captures. Returns undefined if no match. * * Pattern syntax: * - `:paramName` — Named capture (one path segment) * - `*` — Wildcard (one unnamed path segment) * - `**` — Globstar (zero or more path segments) * - `(/*)` — Optional trailing path (zero or more segments at end) * * @param pathname — The URL pathname to match (e.g. `/acme/jobs/123`). * @param pattern — The path pattern (e.g. `/:companyId/jobs/:jobId(/*)`). * @param options — Optional extraction options. * @param options.segmentCharset — Custom character class for the target param capture. * @param options.targetParam — Which named param gets the custom charset (others use default). * @returns Map of param names to captured values, or undefined if no match. */ declare function matchPathPattern(pathname: string, pattern: string, options?: { segmentCharset?: string; targetParam?: string; }): Record | undefined; /** * Extract a field value from a URL using a single extractor definition. * * @param url — The full URL to extract from. * @param extractor — The extractor definition. * @param defaultParam — Default param name to look for in path captures (e.g. "companyId"). * @returns The extracted value, or undefined if extraction fails. */ declare function applyExtractor(url: string, extractor: UrlFieldExtractor, defaultParam: string): string | undefined; /** * Extract a field value from a URL by trying extractors in order. * Returns the first successful extraction. * * @param url — The full URL to extract from. * @param extractors — Array of extractor definitions (tried in order). * @param defaultParam — Default param name (e.g. "companyId" or "jobId"). * @returns The extracted value, or null if no extractor matches. */ declare function extractFieldFromUrl(url: string, extractors: UrlFieldExtractor[], defaultParam: string): string | undefined; /** * Build a canonical listing URL from a job/detail URL using extractors. * * For path-based extractors: reconstructs the URL using only the path up to * the companyId capture (strips trailing job-specific path). * * For query/subdomain extractors: returns the origin (scheme + host) as the * listing base. * * @param url — The full URL to derive the listing URL from. * @param extractors — The companyId extractors. * @returns The canonical listing URL, or null. */ declare function buildListingUrlFromExtractors(url: string, extractors: UrlFieldExtractor[]): string | null; /** * Result of extracting provider info from a URL using manifest patterns. * Pure pattern-matching — no HTTP requests or scraping. */ interface UrlExtractionResult { /** Whether the URL matches any of the provider's urlPatterns. */ urlPatternMatched: boolean; /** Extracted job ID from jobIdExtractor, or null. */ jobId: string | null; /** Extracted company ID from companyIdExtractor, or null. */ companyId: string | null; /** Canonical listing URL reconstructed from companyIdExtractor, or null. */ listingUrl: string | null; } /** * Extract provider info (companyId, jobId, listingUrl) from a URL using * structured extractors. Pure pattern-matching — no HTTP requests or scraping. * * @param url — The URL to extract from (e.g. a job listing URL). * @param urlPatterns — Glob patterns that identify the provider (from manifest `urlPatterns`). * @param companyIdExtractors — Structured extractors for company ID (from manifest `companyIdExtractor`). * @param jobIdExtractors — Structured extractors for job ID (from manifest `jobIdExtractor`). * @returns Extraction result with matched flag, companyId, jobId, and canonical listingUrl. * * @example * ```ts * const result = extractUrlInfo( * "https://jobs.ashbyhq.com/ramp/abc-def-123", * ["https://jobs.ashbyhq.com/**"], * [{ urlPattern: "/:companyId(/**)" }], * [{ urlPattern: "/:companyId/:jobId(/*)" }], * ); * // → { urlPatternMatched: true, companyId: "ramp", jobId: "abc-def-123", * // listingUrl: "https://jobs.ashbyhq.com/ramp" } * ``` */ declare function extractUrlInfo(url: string, urlPatterns: string[], companyIdExtractors: UrlFieldExtractor[], jobIdExtractors: UrlFieldExtractor[], excludeUrlPatterns?: string[]): UrlExtractionResult; /** * Extract a path segment from a URL by position (0-indexed from the path root). * * @param url — The URL to extract from. * @param index — The segment index (0 = first path segment). * @returns The path segment, or `undefined` if the index is out of bounds. * * @example * ```ts * extractPathSegment("https://boards.greenhouse.io/acme/jobs/123", 0); * // → "acme" * * extractPathSegment("https://boards.greenhouse.io/acme/jobs/123", 2); * // → "123" * ``` */ declare function extractPathSegment(url: string, index: number): string | undefined; /** * Build a URL from a base and path segments, with optional query parameters. * * @param base — Base URL (e.g. `"https://api.ats.com"`). * @param path — Path segments to join (e.g. `["v1", "jobs"]`). * @param params — Optional query parameters. * @returns The constructed URL string. * * @example * ```ts * buildUrl("https://api.ats.com", ["v1", "jobs"], { page: "2", limit: "20" }); * // → "https://api.ats.com/v1/jobs?page=2&limit=20" * ``` */ declare function buildUrl(base: string, path: string[], params?: Record): string; export { type UrlExtractionResult as U, applyExtractor as a, asNumber as b, asString as c, asStringArray as d, buildListingUrlFromExtractors as e, buildMeta as f, buildUrl as g, currentOffset as h, currentPage as i, cursorPagination as j, deduplicateListings as k, extractFieldFromUrl as l, extractNamedParam as m, extractParamFromUrl as n, extractPathSegment as o, extractUrlInfo as p, matchPathPattern as q, matchesAnyUrlPattern as r, matchesUrlPattern as s, offsetCursor as t, pageCursor as u, parseDate as v, parseLocation as w, parseLocations as x, toExtractorArray as y, urlCursor as z };