import type { EventMeta, SupportedEvent } from './meta.js'; import type { Client } from './client.js'; import { WorkerSearch } from './search.js'; import type { WorkerQuery } from './search.js'; /** Typed only where the library reads/writes; everything else passes through. */ export interface WorkerRecord { associateOID: string; [key: string]: unknown; } export type WorkerKey = string | { aoid: string; } | { ssn: string; }; export interface HireParams { givenName: string; familyName: string; /** YYYY-MM-DD */ birthDate: string; genderCode: string; ssn: string; lineOne: string; lineTwo?: string; cityName: string; stateCode: string; postalCode: string; /** YYYY-MM-DD */ hireDate: string; payrollGroupCode: string; /** Default "NEW". */ eventReasonCode?: string; } export interface RehireParams { associateOID: string; /** YYYY-MM-DD */ rehireDate: string; /** YYYY-MM-DD */ effectiveDate: string; /** Default "IMPORT". */ reasonCode?: string; } export interface TerminateParams { workAssignmentID: string; /** Lands in comment.commentCode.codeValue — a code, not free text. */ commentCode: string; /** YYYY-MM-DD. */ terminationDate: string; /** YYYY-MM-DD. Defaults to terminationDate. */ lastWorkedDate?: string; reasonCode: string; /** Default true. */ rehireEligibleIndicator?: boolean; /** Default true. */ severanceEligibleIndicator?: boolean; } export interface ChangeBaseRemunerationParams { associateOID: string; /** workAssignments[].itemID — filter primaryIndicator === true, never index 0 blindly. */ workAssignmentID: string; /** YYYY-MM-DD; chosen by the caller (usually next pay period start). Backdating does NOT auto-calculate retro pay. */ effectiveDate: string; /** H = hourly, D = daily, S = salary (pay-period rate). */ rateType: 'H' | 'D' | 'S'; amount: number; /** Default "USD". */ currencyCode?: string; /** Tenant Compensation Change Reasons code — validated against the event meta. */ eventReasonCode: string; } export interface ChangeLegalNameParams { associateOID: string; givenName: string; familyName: string; middleName?: string; /** YYYY-MM-DD */ effectiveDate: string; eventReasonCode?: string; } export interface ChangeCustomFieldStringParams { associateOID: string; /** The custom-field instance itemID on the worker record. */ itemID: string; stringValue: string; /** YYYY-MM-DD */ effectiveDate?: string; } export interface RequestLeaveAbsenceParams { associateOID: string; /** workAssignments[].itemID — omit if the event isn't scoped to a specific assignment. */ workAssignmentID?: string; /** YYYY-MM-DD */ startDate: string; /** YYYY-MM-DD */ expectedReturnDate?: string; /** Tenant leave-type code — validated against the event meta. */ leaveTypeCode: string; } export interface OnboardParams { /** Tenant onboarding template. */ onboardingTemplateCode: string; personal: { givenName: string; familyName: string; middleName?: string; /** YYYY-MM-DD */ birthDate?: string; /** Also mirrored into genderReportingDetails. */ genderCode?: string; raceCode?: string; raceIdentificationMethodCode?: string; ethnicityCode?: string; languageCode?: string; ssn?: string; address?: { lineOne: string; lineTwo?: string; cityName: string; stateCode: string; postalCode: string; /** Default "US". */ countryCode?: string; }; /** * 10-digit US phone number. A leading `+1` or `1` country-code prefix is * accepted and stripped; otherwise formatting is free-form (spaces, * dashes, parens — digits are extracted and split into 3-digit area + * remainder). Throws if what remains after stripping isn't exactly 10 * digits. */ homePhone?: string; /** Same format as `homePhone`. */ mobilePhone?: string; email?: string; }; worker: { /** YYYY-MM-DD */ hireDate: string; hireReasonCode?: string; jobCode?: string; workerTypeCode?: string; /** homeOrganizationalUnits BusinessUnit entry. */ businessUnitCode?: string; /** homeOrganizationalUnits HomeDepartment entry. */ homeDepartmentCode?: string; reportsToPositionID?: string; eeoClassificationCode?: string; eeocClassificationCode?: string; /** Default false. */ managementPositionIndicator?: boolean; }; payroll: { /** Plain string on the wire (recorded). */ payrollGroupCode: string; payCycleCode?: string; payrollScheduleGroupCode?: string; /** Tenant custom code fields (e.g. a DataControl entry) — passed through verbatim. */ customCodeFields?: Array<{ nameCode: string; code: string; }>; }; tax?: { federal?: { taxFilingStatusCode?: string; /** allowanceTypeCode Deductions. */ deductions?: number; /** allowanceTypeCode Dependents. */ dependents?: number; additionalTaxAmount?: number; /** Default false. */ multipleJobIndicator?: boolean; }; state?: { /** workedInJurisdiction instruction. */ workedInStateCode?: string; /** Second instruction, livedInJurisdiction. */ livedInStateCode?: string; taxFilingStatusCode?: string; taxAllowanceQuantity?: number; additionalTaxAmount?: number; }; }; /** Deep-merged over the generated applicantOnboarding object last — the * tenant escape hatch for anything not modeled above. Applied BEFORE * validation (the validated body is the final body). */ overrides?: Record; } export interface WorkerPhoto { /** From the response Content-Type header. */ contentType: string; bytes: Uint8Array; } export interface SetPhotoParams { associateOID: string; /** Image bytes, or a base64 string (decoded — the flow-step convention). */ image: Uint8Array | string; /** datafile part Content-Type. Default: sniffed from magic bytes (jpeg/png), else image/jpeg. */ contentType?: string; /** datafile part filename. Default "photo.jpg". */ filename?: string; } export declare class Worker { protected readonly client: Client; private readonly metaCache; /** event -> epoch ms of the last meta-fetch failure (Fix 3 negative cache). */ private readonly metaFailureAt; constructor(client: Client); /** Fetch (and cache) an event's metadata. Metas are tenant-level; cached (default 12 h). */ eventMeta(event: SupportedEvent | (string & {}), options?: { forceRefresh?: boolean; }): Promise; /** * Validated event pipeline — public escape hatch for any worker.* event. * Validates against cached meta (when client.validateEvents), POSTs, and on * an ADP 400 refreshes the meta once and re-validates to upgrade * stale-cache failures into readable errors. Never re-POSTs. Blocking issue * codes are per-event (`eventRoute`): `codeList` for the events family; * `codeList` + `required` for `applicant.onboard`. Live verification against * real tenant metas showed ADP overdeclares `required`/`readOnly`/`hidden`/ * `pattern`/`length` constraints on fields that battle-tested envelopes have * always sent successfully, while code-list checks (the original motivation: * tenant reason-code validation) produced no false positives. Those other * constraint types remain computable via `eventMeta` + `validateEnvelope` for * diagnostics — they are advisory only and never block. Envelopes are * validated as single-event payloads: multiple entries under `events[]` are * flattened together rather than validated independently per entry. */ postEvent(event: SupportedEvent | (string & {}), envelope: unknown): Promise; /** * Fetch one worker by key: aoid (string shorthand or { aoid }) or { ssn }. * If both keys are somehow present (plain JS), `ssn` wins. */ get(key: WorkerKey): Promise; /** Lazy search handle — fetches nothing until page()/pages()/all()/find(). */ search(query?: WorkerQuery): WorkerSearch; /** Worker photo, or null when none exists (404/204 are normal states). */ getPhoto(aoid: string): Promise; /** * Upload (replace) a worker's photo via the worker.photo.upload multipart * event. Preflight: the tenant meta's imageSize limit is enforced * client-side (fail-open when the meta is unavailable); actual resizing * belongs in the caller (see the README recipe). */ setPhoto(params: SetPhotoParams): Promise; hire(params: HireParams): Promise; rehire(params: RehireParams): Promise; terminate(params: TerminateParams): Promise; /** Envelope documented from prior research: this API family uses `amountValue` (not the legacy PUT's `amount`). */ changeBaseRemuneration(params: ChangeBaseRemunerationParams): Promise; /** DRAFT envelope — verify against the tenant's event meta before production (see live-meta test). */ changeLegalName(params: ChangeLegalNameParams): Promise; /** DRAFT envelope — verify against the tenant's event meta before production (see live-meta test). */ changeCustomFieldString(params: ChangeCustomFieldStringParams): Promise; /** Envelope rebuilt from the live tenant meta (see live-meta gate). */ requestLeaveAbsence(params: RequestLeaveAbsenceParams): Promise; /** * Onboard an applicant (Applicant Onboarding v2, POST /hcm/v2/applicant.onboard). * The body is validated against the tenant meta BEFORE posting — for this * event both `required` and `codeList` issues block (see eventRoute). * Envelope quirks follow the recorded production request verbatim: this * family uses {code} objects (communication nameCodes use codeValue), * governmentIDs use `id`, addresses use subdivisionCode, and * payrollGroupCode is a plain string. */ onboard(params: OnboardParams): Promise; }