@burdenoff/microfe-support 2026.902.1 → 2026.902.3
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/dist/generated/global-operations.d.ts +43 -0
- package/dist/generated/global-operations.js +131 -117
- package/dist/generated/global-operations.js.map +1 -1
- package/dist/generated/global-types.d.ts +25 -1
- package/dist/generated/global-types.js +1 -1
- package/dist/generated/global-types.js.map +1 -1
- package/dist/support/components/careers/BulkCandidateDialogs.d.ts +1 -0
- package/dist/support/components/careers/BulkCandidateDialogs.js +394 -267
- package/dist/support/components/careers/BulkCandidateDialogs.js.map +1 -1
- package/dist/support/components/careers/BulkOperationFeedback.d.ts +4 -1
- package/dist/support/components/careers/BulkOperationFeedback.js +32 -1
- package/dist/support/components/careers/BulkOperationFeedback.js.map +1 -1
- package/dist/support/constants/pipeline.js +3 -0
- package/dist/support/constants/pipeline.js.map +1 -1
- package/dist/support/pages/JobApplicationsPage.js +308 -291
- package/dist/support/pages/JobApplicationsPage.js.map +1 -1
- package/dist/support/utils/bulkCandidateOperations.d.ts +15 -0
- package/dist/support/utils/bulkCandidateOperations.js +19 -4
- package/dist/support/utils/bulkCandidateOperations.js.map +1 -1
- package/dist/support/utils/jobApplicationFilterParams.js +1 -0
- package/dist/support/utils/jobApplicationFilterParams.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bulkCandidateOperations.js","names":[],"sources":["../../../src/support/utils/bulkCandidateOperations.ts"],"sourcesContent":["export const BULK_CANDIDATE_REQUEST_LIMIT = 100;\n\nexport interface CandidateRoundPreview {\n id: string;\n roundConfigId: string | null;\n name: string;\n roundType: string;\n emailLogs: ReadonlyArray<{\n emailType: string;\n }>;\n}\n\nexport interface BulkCandidateTarget {\n id: string;\n jobPostingId: string | null;\n interviewRounds: ReadonlyArray<CandidateRoundPreview>;\n}\n\nexport interface CandidateTargetPage<TTarget extends { id: string }> {\n items: ReadonlyArray<TTarget>;\n total: number;\n hasMore: boolean;\n}\n\nexport type CandidateMaterializationErrorCode =\n | 'STALE_SCOPE'\n | 'TOTAL_DRIFT'\n | 'EMPTY_PAGE_WITH_MORE'\n | 'INVALID_PAGE_LENGTH'\n | 'UNIQUE_COUNT_MISMATCH'\n | 'MEMBERSHIP_DRIFT';\n\nexport class CandidateMaterializationError extends Error {\n constructor(\n public readonly code: CandidateMaterializationErrorCode,\n message: string\n ) {\n super(message);\n this.name = 'CandidateMaterializationError';\n }\n}\n\ninterface MaterializeCandidateTargetsOptions<TTarget extends { id: string }> {\n scopeKey: string;\n expectedTotal: number;\n fetchPage: (limit: number, offset: number) => Promise<CandidateTargetPage<TTarget>>;\n getCurrentScopeKey: () => string;\n pageSize?: number;\n}\n\nfunction assertCurrentScope(scopeKey: string, currentScopeKey: string): void {\n if (scopeKey !== currentScopeKey) {\n throw new CandidateMaterializationError(\n 'STALE_SCOPE',\n 'The application filters changed while candidates were loading.'\n );\n }\n}\n\nasync function materializeCandidateTargetPass<TTarget extends { id: string }>({\n scopeKey,\n expectedTotal,\n fetchPage,\n getCurrentScopeKey,\n pageSize,\n}: Required<MaterializeCandidateTargetsOptions<TTarget>>): Promise<TTarget[]> {\n const targetsById = new Map<string, TTarget>();\n let offset = 0;\n\n while (true) {\n assertCurrentScope(scopeKey, getCurrentScopeKey());\n const page = await fetchPage(pageSize, offset);\n assertCurrentScope(scopeKey, getCurrentScopeKey());\n\n if (page.total !== expectedTotal) {\n throw new CandidateMaterializationError(\n 'TOTAL_DRIFT',\n `The matching application total changed from ${expectedTotal} to ${page.total}. Refresh and select again.`\n );\n }\n\n const rawPageLength = page.items.length;\n if (rawPageLength > pageSize) {\n throw new CandidateMaterializationError(\n 'INVALID_PAGE_LENGTH',\n `The server returned ${rawPageLength} applications for a page limited to ${pageSize}.`\n );\n }\n if (page.hasMore && rawPageLength === 0) {\n throw new CandidateMaterializationError(\n 'EMPTY_PAGE_WITH_MORE',\n 'The server reported more applications but returned an empty page.'\n );\n }\n\n for (const target of page.items) {\n if (!targetsById.has(target.id)) {\n targetsById.set(target.id, target);\n }\n }\n\n offset += rawPageLength;\n\n if (!page.hasMore) {\n if (targetsById.size !== expectedTotal) {\n throw new CandidateMaterializationError(\n 'UNIQUE_COUNT_MISMATCH',\n `Expected ${expectedTotal} unique applications but loaded ${targetsById.size}. Refresh and select again.`\n );\n }\n return [...targetsById.values()];\n }\n\n if (offset >= expectedTotal) {\n throw new CandidateMaterializationError(\n 'TOTAL_DRIFT',\n 'The server reported more applications after the frozen total had already been loaded.'\n );\n }\n }\n}\n\n/**\n * Materializes a frozen application-filter scope without trusting cached pages.\n * Two independent passes must return the same ordered target snapshots. This\n * catches offset-page membership shifts while preserving the 100-item page cap.\n */\nexport async function materializeCandidateTargets<TTarget extends { id: string }>({\n scopeKey,\n expectedTotal,\n fetchPage,\n getCurrentScopeKey,\n pageSize = BULK_CANDIDATE_REQUEST_LIMIT,\n}: MaterializeCandidateTargetsOptions<TTarget>): Promise<TTarget[]> {\n if (!Number.isInteger(expectedTotal) || expectedTotal < 0) {\n throw new CandidateMaterializationError(\n 'TOTAL_DRIFT',\n 'The application total is invalid. Refresh the list and try again.'\n );\n }\n if (!Number.isInteger(pageSize) || pageSize <= 0) {\n throw new CandidateMaterializationError(\n 'INVALID_PAGE_LENGTH',\n 'The candidate page size must be a positive integer.'\n );\n }\n\n const options = {\n scopeKey,\n expectedTotal,\n fetchPage,\n getCurrentScopeKey,\n pageSize,\n };\n const firstPass = await materializeCandidateTargetPass(options);\n const secondPass = await materializeCandidateTargetPass(options);\n\n if (JSON.stringify(firstPass) !== JSON.stringify(secondPass)) {\n throw new CandidateMaterializationError(\n 'MEMBERSHIP_DRIFT',\n 'Matching applications changed while candidates were loading. Refresh and select again.'\n );\n }\n\n return secondPass;\n}\n\ninterface MaterializeCandidateTargetsByIdsOptions<TTarget extends { id: string }> {\n scopeKey: string;\n applicationIds: ReadonlyArray<string>;\n fetchChunkPage: (\n applicationIds: ReadonlyArray<string>,\n limit: number,\n offset: number\n ) => Promise<CandidateTargetPage<TTarget>>;\n getCurrentScopeKey: () => string;\n}\n\n/**\n * Revalidates selected candidates in bounded ID chunks. Each chunk is filtered\n * by both its IDs and the frozen list filter, so earlier mutations cannot make\n * later validation rescan or reinterpret the full result set.\n */\nexport async function materializeCandidateTargetsByIds<TTarget extends { id: string }>({\n scopeKey,\n applicationIds,\n fetchChunkPage,\n getCurrentScopeKey,\n}: MaterializeCandidateTargetsByIdsOptions<TTarget>): Promise<TTarget[]> {\n if (applicationIds.length === 0) return [];\n if (new Set(applicationIds).size !== applicationIds.length) {\n throw new CandidateMaterializationError(\n 'UNIQUE_COUNT_MISMATCH',\n 'Selected applications must have unique IDs.'\n );\n }\n\n const targetsById = new Map<string, TTarget>();\n for (const applicationIdChunk of chunkCandidateRequests(applicationIds)) {\n const targets = await materializeCandidateTargets({\n scopeKey,\n expectedTotal: applicationIdChunk.length,\n getCurrentScopeKey,\n fetchPage: (limit, offset) => fetchChunkPage(applicationIdChunk, limit, offset),\n });\n for (const target of targets) targetsById.set(target.id, target);\n }\n\n return applicationIds.map((applicationId) => {\n const target = targetsById.get(applicationId);\n if (!target) {\n throw new CandidateMaterializationError(\n 'UNIQUE_COUNT_MISMATCH',\n 'A selected application was not returned by its bounded validation query.'\n );\n }\n return target;\n });\n}\n\nexport interface CandidateSelectionState {\n mode: 'explicit' | 'all';\n explicitIds: ReadonlySet<string>;\n allTargetIds: ReadonlySet<string>;\n excludedIds: ReadonlySet<string>;\n}\n\nexport function createEmptyCandidateSelection(): CandidateSelectionState {\n return {\n mode: 'explicit',\n explicitIds: new Set<string>(),\n allTargetIds: new Set<string>(),\n excludedIds: new Set<string>(),\n };\n}\n\nexport function selectAllMaterializedCandidates(\n applicationIds: ReadonlyArray<string>\n): CandidateSelectionState {\n return {\n mode: 'all',\n explicitIds: new Set<string>(),\n allTargetIds: new Set(applicationIds),\n excludedIds: new Set<string>(),\n };\n}\n\nexport function getSelectedCandidateIds(selection: CandidateSelectionState): Set<string> {\n if (selection.mode === 'explicit') {\n return new Set(selection.explicitIds);\n }\n\n const selectedIds = new Set(selection.allTargetIds);\n for (const excludedId of selection.excludedIds) {\n selectedIds.delete(excludedId);\n }\n return selectedIds;\n}\n\nexport function getCandidateSelectionCount(selection: CandidateSelectionState): number {\n return getSelectedCandidateIds(selection).size;\n}\n\nexport function toggleCandidateSelection(\n selection: CandidateSelectionState,\n applicationId: string\n): CandidateSelectionState {\n if (selection.mode === 'all') {\n if (!selection.allTargetIds.has(applicationId)) {\n return selection;\n }\n const excludedIds = new Set(selection.excludedIds);\n if (excludedIds.has(applicationId)) {\n excludedIds.delete(applicationId);\n } else {\n excludedIds.add(applicationId);\n }\n return { ...selection, excludedIds };\n }\n\n const explicitIds = new Set(selection.explicitIds);\n if (explicitIds.has(applicationId)) {\n explicitIds.delete(applicationId);\n } else {\n explicitIds.add(applicationId);\n }\n return { ...selection, explicitIds };\n}\n\nexport function setVisibleCandidateSelection(\n selection: CandidateSelectionState,\n visibleApplicationIds: ReadonlyArray<string>,\n selected: boolean\n): CandidateSelectionState {\n if (selection.mode === 'all') {\n const excludedIds = new Set(selection.excludedIds);\n for (const applicationId of visibleApplicationIds) {\n if (!selection.allTargetIds.has(applicationId)) continue;\n if (selected) {\n excludedIds.delete(applicationId);\n } else {\n excludedIds.add(applicationId);\n }\n }\n return { ...selection, excludedIds };\n }\n\n const explicitIds = new Set(selection.explicitIds);\n for (const applicationId of visibleApplicationIds) {\n if (selected) {\n explicitIds.add(applicationId);\n } else {\n explicitIds.delete(applicationId);\n }\n }\n return { ...selection, explicitIds };\n}\n\nexport function getCandidateSelectionSummary(selection: CandidateSelectionState): string | null {\n const selectedCount = getCandidateSelectionCount(selection);\n if (selectedCount === 0) return null;\n\n if (selection.mode === 'all') {\n const totalCount = selection.allTargetIds.size;\n const excludedCount = totalCount - selectedCount;\n if (excludedCount === 0) {\n return `All ${totalCount} matching applications selected`;\n }\n return `${selectedCount} of ${totalCount} matching applications selected (${excludedCount} excluded)`;\n }\n\n return `${selectedCount} ${selectedCount === 1 ? 'application' : 'applications'} selected`;\n}\n\nexport interface ExactRoundPair {\n applicationId: string;\n roundId: string;\n target: BulkCandidateTarget;\n round: CandidateRoundPreview;\n}\n\nexport interface UnresolvedCandidateRound {\n target: BulkCandidateTarget;\n reason: 'MISSING' | 'AMBIGUOUS';\n}\n\nexport interface ExactRoundResolution {\n pairs: ExactRoundPair[];\n unresolved: UnresolvedCandidateRound[];\n}\n\n/** Resolve only concrete rounds with the requested config ID; never guess by name or type. */\nexport function resolveExactCandidateRounds(\n targets: ReadonlyArray<BulkCandidateTarget>,\n roundConfigId: string\n): ExactRoundResolution {\n const pairs: ExactRoundPair[] = [];\n const unresolved: UnresolvedCandidateRound[] = [];\n\n for (const target of targets) {\n const matches = target.interviewRounds.filter((round) => round.roundConfigId === roundConfigId);\n if (matches.length !== 1) {\n unresolved.push({\n target,\n reason: matches.length === 0 ? 'MISSING' : 'AMBIGUOUS',\n });\n continue;\n }\n\n const round = matches[0];\n pairs.push({ applicationId: target.id, roundId: round.id, target, round });\n }\n\n return { pairs, unresolved };\n}\n\nexport class CandidateChunkPreconditionError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'CandidateChunkPreconditionError';\n }\n}\n\nexport function assertCandidateChunkMatchesCurrentScope(\n applicationIds: ReadonlyArray<string>,\n currentTargets: ReadonlyArray<BulkCandidateTarget>,\n jobPostingId: string\n): void {\n const currentById = new Map(currentTargets.map((target) => [target.id, target]));\n\n for (const applicationId of applicationIds) {\n const target = currentById.get(applicationId);\n if (!target || target.jobPostingId !== jobPostingId) {\n throw new CandidateChunkPreconditionError(\n 'A selected application no longer matches the frozen filter and posting. No request was sent for this chunk.'\n );\n }\n }\n}\n\nexport function assertCandidateEmailChunkMatchesCurrentScope(\n items: ReadonlyArray<{ applicationId: string; roundId: string }>,\n currentTargets: ReadonlyArray<BulkCandidateTarget>,\n jobPostingId: string,\n roundConfigId: string\n): void {\n assertCandidateChunkMatchesCurrentScope(\n items.map((item) => item.applicationId),\n currentTargets,\n jobPostingId\n );\n\n const currentById = new Map(currentTargets.map((target) => [target.id, target]));\n for (const item of items) {\n const target = currentById.get(item.applicationId);\n const matchingRounds = target?.interviewRounds.filter(\n (round) => round.roundConfigId === roundConfigId\n );\n if (matchingRounds?.length !== 1 || matchingRounds[0]?.id !== item.roundId) {\n throw new CandidateChunkPreconditionError(\n 'A selected candidate round changed after preview. No request was sent for this chunk.'\n );\n }\n }\n}\n\nexport function chunkCandidateRequests<T>(\n items: ReadonlyArray<T>,\n chunkSize = BULK_CANDIDATE_REQUEST_LIMIT\n): T[][] {\n if (!Number.isInteger(chunkSize) || chunkSize <= 0) {\n throw new Error('Chunk size must be a positive integer.');\n }\n\n const chunks: T[][] = [];\n for (let index = 0; index < items.length; index += chunkSize) {\n chunks.push(items.slice(index, index + chunkSize));\n }\n return chunks;\n}\n\nexport interface SequentialExecutionProgress {\n processed: number;\n total: number;\n}\n\nexport interface SequentialExecutionResult<TItem, TAggregate> {\n aggregate: TAggregate;\n processedItems: TItem[];\n ambiguousItems: TItem[];\n notStartedItems: TItem[];\n error: unknown | null;\n}\n\ninterface ExecuteSequentialCandidateChunksOptions<TItem, TBatchResult, TAggregate> {\n items: ReadonlyArray<TItem>;\n initialAggregate: TAggregate;\n executeChunk: (chunk: ReadonlyArray<TItem>, chunkIndex: number) => Promise<TBatchResult>;\n mergeResult: (aggregate: TAggregate, result: TBatchResult) => TAggregate;\n onProgress?: (progress: SequentialExecutionProgress) => void;\n chunkSize?: number;\n}\n\n/**\n * Executes each request once and in order. A thrown transport/missing-data error\n * makes the current chunk ambiguous and prevents every later chunk from starting.\n */\nexport async function executeSequentialCandidateChunks<TItem, TBatchResult, TAggregate>({\n items,\n initialAggregate,\n executeChunk,\n mergeResult,\n onProgress,\n chunkSize = BULK_CANDIDATE_REQUEST_LIMIT,\n}: ExecuteSequentialCandidateChunksOptions<TItem, TBatchResult, TAggregate>): Promise<\n SequentialExecutionResult<TItem, TAggregate>\n> {\n const chunks = chunkCandidateRequests(items, chunkSize);\n const processedItems: TItem[] = [];\n let aggregate = initialAggregate;\n\n onProgress?.({ processed: 0, total: items.length });\n\n for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex += 1) {\n const chunk = chunks[chunkIndex];\n try {\n const result = await executeChunk(chunk, chunkIndex);\n aggregate = mergeResult(aggregate, result);\n processedItems.push(...chunk);\n onProgress?.({ processed: processedItems.length, total: items.length });\n } catch (error) {\n const failedBeforeMutation = error instanceof CandidateChunkPreconditionError;\n return {\n aggregate,\n processedItems,\n ambiguousItems: failedBeforeMutation ? [] : [...chunk],\n notStartedItems: failedBeforeMutation\n ? chunks.slice(chunkIndex).flat()\n : chunks.slice(chunkIndex + 1).flat(),\n error,\n };\n }\n }\n\n return {\n aggregate,\n processedItems,\n ambiguousItems: [],\n notStartedItems: [],\n error: null,\n };\n}\n\nexport type BulkOperationNotificationSeverity = 'success' | 'warning' | 'error';\n\nexport function getBulkOperationNotificationSeverity({\n succeeded,\n skipped,\n failed,\n ambiguous = false,\n}: {\n succeeded: number;\n skipped: number;\n failed: number;\n ambiguous?: boolean;\n}): BulkOperationNotificationSeverity {\n if (ambiguous) return 'error';\n if (failed > 0 && succeeded === 0 && skipped === 0) return 'error';\n if (failed > 0 || skipped > 0) return 'warning';\n return 'success';\n}\n\nexport interface CandidateEmailSuccess {\n applicationId: string;\n roundId: string;\n}\n\nexport interface CandidateEmailSkip {\n applicationId: string;\n roundId: string;\n reason: string;\n message: string;\n}\n\nexport interface CandidateEmailFailure {\n applicationId: string;\n roundId: string;\n message: string;\n}\n\nexport interface CandidateEmailAggregate {\n succeeded: CandidateEmailSuccess[];\n skipped: CandidateEmailSkip[];\n failed: CandidateEmailFailure[];\n}\n\nexport function createEmptyCandidateEmailAggregate(): CandidateEmailAggregate {\n return { succeeded: [], skipped: [], failed: [] };\n}\n\nfunction candidateRoundKey(applicationId: string, roundId: string): string {\n return `${applicationId}\\0${roundId}`;\n}\n\nfunction assertExactResultKeys(\n expectedKeys: ReadonlyArray<string>,\n actualKeys: ReadonlyArray<string>,\n operationLabel: string\n): void {\n const expected = new Set(expectedKeys);\n const actual = new Set(actualKeys);\n if (\n expected.size !== expectedKeys.length ||\n actual.size !== actualKeys.length ||\n expected.size !== actual.size ||\n [...expected].some((key) => !actual.has(key))\n ) {\n throw new Error(\n `${operationLabel} returned an incomplete, duplicate, or unexpected item result. The current chunk is ambiguous and later chunks were stopped.`\n );\n }\n}\n\nexport function assertCompleteCandidateEmailChunkResult(\n requested: ReadonlyArray<{ applicationId: string; roundId: string }>,\n result: CandidateEmailAggregate\n): void {\n assertExactResultKeys(\n requested.map((item) => candidateRoundKey(item.applicationId, item.roundId)),\n [\n ...result.succeeded.map((item) => candidateRoundKey(item.applicationId, item.roundId)),\n ...result.skipped.map((item) => candidateRoundKey(item.applicationId, item.roundId)),\n ...result.failed.map((item) => candidateRoundKey(item.applicationId, item.roundId)),\n ],\n 'The candidate email request'\n );\n}\n\nexport function aggregateCandidateEmailResult(\n aggregate: CandidateEmailAggregate,\n result: CandidateEmailAggregate\n): CandidateEmailAggregate {\n return {\n succeeded: [...aggregate.succeeded, ...result.succeeded],\n skipped: [...aggregate.skipped, ...result.skipped],\n failed: [...aggregate.failed, ...result.failed],\n };\n}\n\nexport interface EnsuredRoundSummary {\n id: string;\n applicationId: string;\n}\n\nexport interface EnsureRoundFailure {\n applicationId: string;\n code: string;\n message: string;\n}\n\nexport interface EnsureRoundAggregate {\n created: EnsuredRoundSummary[];\n alreadyPresent: EnsuredRoundSummary[];\n failed: EnsureRoundFailure[];\n}\n\nexport function createEmptyEnsureRoundAggregate(): EnsureRoundAggregate {\n return { created: [], alreadyPresent: [], failed: [] };\n}\n\nexport function assertCompleteEnsureRoundChunkResult(\n requestedApplicationIds: ReadonlyArray<string>,\n result: EnsureRoundAggregate\n): void {\n assertExactResultKeys(\n requestedApplicationIds,\n [\n ...result.created.map((item) => item.applicationId),\n ...result.alreadyPresent.map((item) => item.applicationId),\n ...result.failed.map((item) => item.applicationId),\n ],\n 'The add-to-round request'\n );\n}\n\nexport function aggregateEnsureRoundResult(\n aggregate: EnsureRoundAggregate,\n result: EnsureRoundAggregate\n): EnsureRoundAggregate {\n return {\n created: [...aggregate.created, ...result.created],\n alreadyPresent: [...aggregate.alreadyPresent, ...result.alreadyPresent],\n failed: [...aggregate.failed, ...result.failed],\n };\n}\n\nexport interface BulkCustomEmailSuccess {\n applicationId: string;\n email: string;\n}\n\nexport interface BulkCustomEmailFailureItem {\n applicationId: string;\n message: string;\n}\n\nexport interface BulkCustomEmailAggregate {\n succeeded: BulkCustomEmailSuccess[];\n failed: BulkCustomEmailFailureItem[];\n}\n\nexport function createEmptyBulkCustomEmailAggregate(): BulkCustomEmailAggregate {\n return { succeeded: [], failed: [] };\n}\n\nexport function assertCompleteBulkCustomEmailChunkResult(\n requestedApplicationIds: ReadonlyArray<string>,\n result: BulkCustomEmailAggregate\n): void {\n assertExactResultKeys(\n requestedApplicationIds,\n [\n ...result.succeeded.map((item) => item.applicationId),\n ...result.failed.map((item) => item.applicationId),\n ],\n 'The bulk custom email request'\n );\n}\n\nexport function aggregateBulkCustomEmailResult(\n aggregate: BulkCustomEmailAggregate,\n result: BulkCustomEmailAggregate\n): BulkCustomEmailAggregate {\n return {\n succeeded: [...aggregate.succeeded, ...result.succeeded],\n failed: [...aggregate.failed, ...result.failed],\n };\n}\n\nexport function hasCandidateEmailType(round: CandidateRoundPreview, emailType: string): boolean {\n return round.emailLogs.some((log) => log.emailType === emailType);\n}\n\nexport interface DuplicateNoticeSuccess {\n email: string;\n}\n\nexport interface DuplicateNoticeSkip {\n email: string;\n reason: string;\n message: string;\n}\n\nexport interface DuplicateNoticeFailure {\n email: string;\n message: string;\n}\n\nexport interface DuplicateNoticeAggregate {\n succeeded: DuplicateNoticeSuccess[];\n skipped: DuplicateNoticeSkip[];\n failed: DuplicateNoticeFailure[];\n}\n\nexport function createEmptyDuplicateNoticeAggregate(): DuplicateNoticeAggregate {\n return { succeeded: [], skipped: [], failed: [] };\n}\n\nexport function aggregateDuplicateNoticeResult(\n aggregate: DuplicateNoticeAggregate,\n result: DuplicateNoticeAggregate\n): DuplicateNoticeAggregate {\n return {\n succeeded: [...aggregate.succeeded, ...result.succeeded],\n skipped: [...aggregate.skipped, ...result.skipped],\n failed: [...aggregate.failed, ...result.failed],\n };\n}\n"],"mappings":"AAgCA,IAAa,IAAb,cAAmD,MAAM;CAErC;CADlB,YACE,GACA,GACA;EAEA,AADA,MAAM,CAAO,GAHG,KAAA,OAAA,GAIhB,KAAK,OAAO;CACd;AACF;AAUA,SAAS,EAAmB,GAAkB,GAA+B;CAC3E,IAAI,MAAa,GACf,MAAM,IAAI,EACR,eACA,gEACF;AAEJ;AAEA,eAAe,EAA+D,EAC5E,aACA,kBACA,cACA,uBACA,eAC4E;CAC5E,IAAM,oBAAc,IAAI,IAAqB,GACzC,IAAS;CAEb,SAAa;EACX,EAAmB,GAAU,EAAmB,CAAC;EACjD,IAAM,IAAO,MAAM,EAAU,GAAU,CAAM;EAG7C,IAFA,EAAmB,GAAU,EAAmB,CAAC,GAE7C,EAAK,UAAU,GACjB,MAAM,IAAI,EACR,eACA,+CAA+C,EAAc,MAAM,EAAK,MAAM,4BAChF;EAGF,IAAM,IAAgB,EAAK,MAAM;EACjC,IAAI,IAAgB,GAClB,MAAM,IAAI,EACR,uBACA,uBAAuB,EAAc,sCAAsC,EAAS,EACtF;EAEF,IAAI,EAAK,WAAW,MAAkB,GACpC,MAAM,IAAI,EACR,wBACA,mEACF;EAGF,KAAK,IAAM,KAAU,EAAK,OACxB,AAAK,EAAY,IAAI,EAAO,EAAE,KAC5B,EAAY,IAAI,EAAO,IAAI,CAAM;EAMrC,IAFA,KAAU,GAEN,CAAC,EAAK,SAAS;GACjB,IAAI,EAAY,SAAS,GACvB,MAAM,IAAI,EACR,yBACA,YAAY,EAAc,kCAAkC,EAAY,KAAK,4BAC/E;GAEF,OAAO,CA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,CAAC;EAAG,QAAQ,CAAC;CAAE;AAClD;AAEA,SAAgB,EACd,GACA,GAC0B;CAC1B,OAAO;EACL,WAAW,CAAC,GAAG,EAAU,WAAW,GAAG,EAAO,SAAS;EACvD,SAAS,CAAC,GAAG,EAAU,SAAS,GAAG,EAAO,OAAO;EACjD,QAAQ,CAAC,GAAG,EAAU,QAAQ,GAAG,EAAO,MAAM;CAChD;AACF"}
|
|
1
|
+
{"version":3,"file":"bulkCandidateOperations.js","names":[],"sources":["../../../src/support/utils/bulkCandidateOperations.ts"],"sourcesContent":["export const BULK_CANDIDATE_REQUEST_LIMIT = 100;\n\nexport interface CandidateRoundPreview {\n id: string;\n roundConfigId: string | null;\n name: string;\n roundType: string;\n emailLogs: ReadonlyArray<{\n emailType: string;\n }>;\n}\n\nexport interface BulkCandidateTarget {\n id: string;\n jobPostingId: string | null;\n interviewRounds: ReadonlyArray<CandidateRoundPreview>;\n}\n\nexport interface CandidateTargetPage<TTarget extends { id: string }> {\n items: ReadonlyArray<TTarget>;\n total: number;\n hasMore: boolean;\n}\n\nexport type CandidateMaterializationErrorCode =\n | 'STALE_SCOPE'\n | 'TOTAL_DRIFT'\n | 'EMPTY_PAGE_WITH_MORE'\n | 'INVALID_PAGE_LENGTH'\n | 'UNIQUE_COUNT_MISMATCH'\n | 'MEMBERSHIP_DRIFT';\n\nexport class CandidateMaterializationError extends Error {\n constructor(\n public readonly code: CandidateMaterializationErrorCode,\n message: string\n ) {\n super(message);\n this.name = 'CandidateMaterializationError';\n }\n}\n\ninterface MaterializeCandidateTargetsOptions<TTarget extends { id: string }> {\n scopeKey: string;\n expectedTotal: number;\n fetchPage: (limit: number, offset: number) => Promise<CandidateTargetPage<TTarget>>;\n getCurrentScopeKey: () => string;\n pageSize?: number;\n}\n\nfunction assertCurrentScope(scopeKey: string, currentScopeKey: string): void {\n if (scopeKey !== currentScopeKey) {\n throw new CandidateMaterializationError(\n 'STALE_SCOPE',\n 'The application filters changed while candidates were loading.'\n );\n }\n}\n\nasync function materializeCandidateTargetPass<TTarget extends { id: string }>({\n scopeKey,\n expectedTotal,\n fetchPage,\n getCurrentScopeKey,\n pageSize,\n}: Required<MaterializeCandidateTargetsOptions<TTarget>>): Promise<TTarget[]> {\n const targetsById = new Map<string, TTarget>();\n let offset = 0;\n\n while (true) {\n assertCurrentScope(scopeKey, getCurrentScopeKey());\n const page = await fetchPage(pageSize, offset);\n assertCurrentScope(scopeKey, getCurrentScopeKey());\n\n if (page.total !== expectedTotal) {\n throw new CandidateMaterializationError(\n 'TOTAL_DRIFT',\n `The matching application total changed from ${expectedTotal} to ${page.total}. Refresh and select again.`\n );\n }\n\n const rawPageLength = page.items.length;\n if (rawPageLength > pageSize) {\n throw new CandidateMaterializationError(\n 'INVALID_PAGE_LENGTH',\n `The server returned ${rawPageLength} applications for a page limited to ${pageSize}.`\n );\n }\n if (page.hasMore && rawPageLength === 0) {\n throw new CandidateMaterializationError(\n 'EMPTY_PAGE_WITH_MORE',\n 'The server reported more applications but returned an empty page.'\n );\n }\n\n for (const target of page.items) {\n if (!targetsById.has(target.id)) {\n targetsById.set(target.id, target);\n }\n }\n\n offset += rawPageLength;\n\n if (!page.hasMore) {\n if (targetsById.size !== expectedTotal) {\n throw new CandidateMaterializationError(\n 'UNIQUE_COUNT_MISMATCH',\n `Expected ${expectedTotal} unique applications but loaded ${targetsById.size}. Refresh and select again.`\n );\n }\n return [...targetsById.values()];\n }\n\n if (offset >= expectedTotal) {\n throw new CandidateMaterializationError(\n 'TOTAL_DRIFT',\n 'The server reported more applications after the frozen total had already been loaded.'\n );\n }\n }\n}\n\n/**\n * Materializes a frozen application-filter scope without trusting cached pages.\n * Two independent passes must return the same ordered target snapshots. This\n * catches offset-page membership shifts while preserving the 100-item page cap.\n */\nexport async function materializeCandidateTargets<TTarget extends { id: string }>({\n scopeKey,\n expectedTotal,\n fetchPage,\n getCurrentScopeKey,\n pageSize = BULK_CANDIDATE_REQUEST_LIMIT,\n}: MaterializeCandidateTargetsOptions<TTarget>): Promise<TTarget[]> {\n if (!Number.isInteger(expectedTotal) || expectedTotal < 0) {\n throw new CandidateMaterializationError(\n 'TOTAL_DRIFT',\n 'The application total is invalid. Refresh the list and try again.'\n );\n }\n if (!Number.isInteger(pageSize) || pageSize <= 0) {\n throw new CandidateMaterializationError(\n 'INVALID_PAGE_LENGTH',\n 'The candidate page size must be a positive integer.'\n );\n }\n\n const options = {\n scopeKey,\n expectedTotal,\n fetchPage,\n getCurrentScopeKey,\n pageSize,\n };\n const firstPass = await materializeCandidateTargetPass(options);\n const secondPass = await materializeCandidateTargetPass(options);\n\n if (JSON.stringify(firstPass) !== JSON.stringify(secondPass)) {\n throw new CandidateMaterializationError(\n 'MEMBERSHIP_DRIFT',\n 'Matching applications changed while candidates were loading. Refresh and select again.'\n );\n }\n\n return secondPass;\n}\n\ninterface MaterializeCandidateTargetsByIdsOptions<TTarget extends { id: string }> {\n scopeKey: string;\n applicationIds: ReadonlyArray<string>;\n fetchChunkPage: (\n applicationIds: ReadonlyArray<string>,\n limit: number,\n offset: number\n ) => Promise<CandidateTargetPage<TTarget>>;\n getCurrentScopeKey: () => string;\n}\n\n/**\n * Revalidates selected candidates in bounded ID chunks. Each chunk is filtered\n * by both its IDs and the frozen list filter, so earlier mutations cannot make\n * later validation rescan or reinterpret the full result set.\n */\nexport async function materializeCandidateTargetsByIds<TTarget extends { id: string }>({\n scopeKey,\n applicationIds,\n fetchChunkPage,\n getCurrentScopeKey,\n}: MaterializeCandidateTargetsByIdsOptions<TTarget>): Promise<TTarget[]> {\n if (applicationIds.length === 0) return [];\n if (new Set(applicationIds).size !== applicationIds.length) {\n throw new CandidateMaterializationError(\n 'UNIQUE_COUNT_MISMATCH',\n 'Selected applications must have unique IDs.'\n );\n }\n\n const targetsById = new Map<string, TTarget>();\n for (const applicationIdChunk of chunkCandidateRequests(applicationIds)) {\n const targets = await materializeCandidateTargets({\n scopeKey,\n expectedTotal: applicationIdChunk.length,\n getCurrentScopeKey,\n fetchPage: (limit, offset) => fetchChunkPage(applicationIdChunk, limit, offset),\n });\n for (const target of targets) targetsById.set(target.id, target);\n }\n\n return applicationIds.map((applicationId) => {\n const target = targetsById.get(applicationId);\n if (!target) {\n throw new CandidateMaterializationError(\n 'UNIQUE_COUNT_MISMATCH',\n 'A selected application was not returned by its bounded validation query.'\n );\n }\n return target;\n });\n}\n\nexport interface CandidateSelectionState {\n mode: 'explicit' | 'all';\n explicitIds: ReadonlySet<string>;\n allTargetIds: ReadonlySet<string>;\n excludedIds: ReadonlySet<string>;\n}\n\nexport function createEmptyCandidateSelection(): CandidateSelectionState {\n return {\n mode: 'explicit',\n explicitIds: new Set<string>(),\n allTargetIds: new Set<string>(),\n excludedIds: new Set<string>(),\n };\n}\n\nexport function selectAllMaterializedCandidates(\n applicationIds: ReadonlyArray<string>\n): CandidateSelectionState {\n return {\n mode: 'all',\n explicitIds: new Set<string>(),\n allTargetIds: new Set(applicationIds),\n excludedIds: new Set<string>(),\n };\n}\n\nexport function getSelectedCandidateIds(selection: CandidateSelectionState): Set<string> {\n if (selection.mode === 'explicit') {\n return new Set(selection.explicitIds);\n }\n\n const selectedIds = new Set(selection.allTargetIds);\n for (const excludedId of selection.excludedIds) {\n selectedIds.delete(excludedId);\n }\n return selectedIds;\n}\n\nexport function getCandidateSelectionCount(selection: CandidateSelectionState): number {\n return getSelectedCandidateIds(selection).size;\n}\n\nexport function toggleCandidateSelection(\n selection: CandidateSelectionState,\n applicationId: string\n): CandidateSelectionState {\n if (selection.mode === 'all') {\n if (!selection.allTargetIds.has(applicationId)) {\n return selection;\n }\n const excludedIds = new Set(selection.excludedIds);\n if (excludedIds.has(applicationId)) {\n excludedIds.delete(applicationId);\n } else {\n excludedIds.add(applicationId);\n }\n return { ...selection, excludedIds };\n }\n\n const explicitIds = new Set(selection.explicitIds);\n if (explicitIds.has(applicationId)) {\n explicitIds.delete(applicationId);\n } else {\n explicitIds.add(applicationId);\n }\n return { ...selection, explicitIds };\n}\n\nexport function setVisibleCandidateSelection(\n selection: CandidateSelectionState,\n visibleApplicationIds: ReadonlyArray<string>,\n selected: boolean\n): CandidateSelectionState {\n if (selection.mode === 'all') {\n const excludedIds = new Set(selection.excludedIds);\n for (const applicationId of visibleApplicationIds) {\n if (!selection.allTargetIds.has(applicationId)) continue;\n if (selected) {\n excludedIds.delete(applicationId);\n } else {\n excludedIds.add(applicationId);\n }\n }\n return { ...selection, excludedIds };\n }\n\n const explicitIds = new Set(selection.explicitIds);\n for (const applicationId of visibleApplicationIds) {\n if (selected) {\n explicitIds.add(applicationId);\n } else {\n explicitIds.delete(applicationId);\n }\n }\n return { ...selection, explicitIds };\n}\n\nexport function getCandidateSelectionSummary(selection: CandidateSelectionState): string | null {\n const selectedCount = getCandidateSelectionCount(selection);\n if (selectedCount === 0) return null;\n\n if (selection.mode === 'all') {\n const totalCount = selection.allTargetIds.size;\n const excludedCount = totalCount - selectedCount;\n if (excludedCount === 0) {\n return `All ${totalCount} matching applications selected`;\n }\n return `${selectedCount} of ${totalCount} matching applications selected (${excludedCount} excluded)`;\n }\n\n return `${selectedCount} ${selectedCount === 1 ? 'application' : 'applications'} selected`;\n}\n\nexport interface ExactRoundPair {\n applicationId: string;\n roundId: string;\n target: BulkCandidateTarget;\n round: CandidateRoundPreview;\n}\n\nexport interface UnresolvedCandidateRound {\n target: BulkCandidateTarget;\n reason: 'MISSING' | 'AMBIGUOUS';\n}\n\nexport interface ExactRoundResolution {\n pairs: ExactRoundPair[];\n unresolved: UnresolvedCandidateRound[];\n}\n\n/** Resolve only concrete rounds with the requested config ID; never guess by name or type. */\nexport function resolveExactCandidateRounds(\n targets: ReadonlyArray<BulkCandidateTarget>,\n roundConfigId: string\n): ExactRoundResolution {\n const pairs: ExactRoundPair[] = [];\n const unresolved: UnresolvedCandidateRound[] = [];\n\n for (const target of targets) {\n const matches = target.interviewRounds.filter((round) => round.roundConfigId === roundConfigId);\n if (matches.length !== 1) {\n unresolved.push({\n target,\n reason: matches.length === 0 ? 'MISSING' : 'AMBIGUOUS',\n });\n continue;\n }\n\n const round = matches[0];\n pairs.push({ applicationId: target.id, roundId: round.id, target, round });\n }\n\n return { pairs, unresolved };\n}\n\nexport class CandidateChunkPreconditionError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'CandidateChunkPreconditionError';\n }\n}\n\nexport function assertCandidateChunkMatchesCurrentScope(\n applicationIds: ReadonlyArray<string>,\n currentTargets: ReadonlyArray<BulkCandidateTarget>,\n jobPostingId: string\n): void {\n const currentById = new Map(currentTargets.map((target) => [target.id, target]));\n\n for (const applicationId of applicationIds) {\n const target = currentById.get(applicationId);\n if (!target || target.jobPostingId !== jobPostingId) {\n throw new CandidateChunkPreconditionError(\n 'A selected application no longer matches the frozen filter and posting. No request was sent for this chunk.'\n );\n }\n }\n}\n\nexport function assertCandidateEmailChunkMatchesCurrentScope(\n items: ReadonlyArray<{ applicationId: string; roundId: string }>,\n currentTargets: ReadonlyArray<BulkCandidateTarget>,\n jobPostingId: string,\n roundConfigId: string\n): void {\n assertCandidateChunkMatchesCurrentScope(\n items.map((item) => item.applicationId),\n currentTargets,\n jobPostingId\n );\n\n const currentById = new Map(currentTargets.map((target) => [target.id, target]));\n for (const item of items) {\n const target = currentById.get(item.applicationId);\n const matchingRounds = target?.interviewRounds.filter(\n (round) => round.roundConfigId === roundConfigId\n );\n if (matchingRounds?.length !== 1 || matchingRounds[0]?.id !== item.roundId) {\n throw new CandidateChunkPreconditionError(\n 'A selected candidate round changed after preview. No request was sent for this chunk.'\n );\n }\n }\n}\n\nexport function chunkCandidateRequests<T>(\n items: ReadonlyArray<T>,\n chunkSize = BULK_CANDIDATE_REQUEST_LIMIT\n): T[][] {\n if (!Number.isInteger(chunkSize) || chunkSize <= 0) {\n throw new Error('Chunk size must be a positive integer.');\n }\n\n const chunks: T[][] = [];\n for (let index = 0; index < items.length; index += chunkSize) {\n chunks.push(items.slice(index, index + chunkSize));\n }\n return chunks;\n}\n\nexport interface SequentialExecutionProgress {\n processed: number;\n total: number;\n}\n\nexport interface SequentialExecutionResult<TItem, TAggregate> {\n aggregate: TAggregate;\n processedItems: TItem[];\n ambiguousItems: TItem[];\n notStartedItems: TItem[];\n error: unknown | null;\n}\n\ninterface ExecuteSequentialCandidateChunksOptions<TItem, TBatchResult, TAggregate> {\n items: ReadonlyArray<TItem>;\n initialAggregate: TAggregate;\n executeChunk: (chunk: ReadonlyArray<TItem>, chunkIndex: number) => Promise<TBatchResult>;\n mergeResult: (aggregate: TAggregate, result: TBatchResult) => TAggregate;\n onProgress?: (progress: SequentialExecutionProgress) => void;\n chunkSize?: number;\n}\n\n/**\n * Executes each request once and in order. A thrown transport/missing-data error\n * makes the current chunk ambiguous and prevents every later chunk from starting.\n */\nexport async function executeSequentialCandidateChunks<TItem, TBatchResult, TAggregate>({\n items,\n initialAggregate,\n executeChunk,\n mergeResult,\n onProgress,\n chunkSize = BULK_CANDIDATE_REQUEST_LIMIT,\n}: ExecuteSequentialCandidateChunksOptions<TItem, TBatchResult, TAggregate>): Promise<\n SequentialExecutionResult<TItem, TAggregate>\n> {\n const chunks = chunkCandidateRequests(items, chunkSize);\n const processedItems: TItem[] = [];\n let aggregate = initialAggregate;\n\n onProgress?.({ processed: 0, total: items.length });\n\n for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex += 1) {\n const chunk = chunks[chunkIndex];\n try {\n const result = await executeChunk(chunk, chunkIndex);\n aggregate = mergeResult(aggregate, result);\n processedItems.push(...chunk);\n onProgress?.({ processed: processedItems.length, total: items.length });\n } catch (error) {\n const failedBeforeMutation = error instanceof CandidateChunkPreconditionError;\n return {\n aggregate,\n processedItems,\n ambiguousItems: failedBeforeMutation ? [] : [...chunk],\n notStartedItems: failedBeforeMutation\n ? chunks.slice(chunkIndex).flat()\n : chunks.slice(chunkIndex + 1).flat(),\n error,\n };\n }\n }\n\n return {\n aggregate,\n processedItems,\n ambiguousItems: [],\n notStartedItems: [],\n error: null,\n };\n}\n\nexport type BulkOperationNotificationSeverity = 'success' | 'warning' | 'error';\n\nexport function getBulkOperationNotificationSeverity({\n succeeded,\n skipped,\n failed,\n ambiguous = false,\n}: {\n succeeded: number;\n skipped: number;\n failed: number;\n ambiguous?: boolean;\n}): BulkOperationNotificationSeverity {\n if (ambiguous) return 'error';\n if (failed > 0 && succeeded === 0 && skipped === 0) return 'error';\n if (failed > 0 || skipped > 0) return 'warning';\n return 'success';\n}\n\nexport interface CandidateEmailSuccess {\n applicationId: string;\n roundId: string;\n}\n\nexport interface CandidateEmailSkip {\n applicationId: string;\n roundId: string;\n reason: string;\n message: string;\n}\n\nexport interface CandidateEmailFailure {\n applicationId: string;\n roundId: string;\n message: string;\n}\n\nexport interface CandidateEmailAggregate {\n succeeded: CandidateEmailSuccess[];\n skipped: CandidateEmailSkip[];\n failed: CandidateEmailFailure[];\n}\n\nexport function createEmptyCandidateEmailAggregate(): CandidateEmailAggregate {\n return { succeeded: [], skipped: [], failed: [] };\n}\n\nfunction candidateRoundKey(applicationId: string, roundId: string): string {\n return `${applicationId}\\0${roundId}`;\n}\n\nfunction assertExactResultKeys(\n expectedKeys: ReadonlyArray<string>,\n actualKeys: ReadonlyArray<string>,\n operationLabel: string\n): void {\n const expected = new Set(expectedKeys);\n const actual = new Set(actualKeys);\n if (\n expected.size !== expectedKeys.length ||\n actual.size !== actualKeys.length ||\n expected.size !== actual.size ||\n [...expected].some((key) => !actual.has(key))\n ) {\n throw new Error(\n `${operationLabel} returned an incomplete, duplicate, or unexpected item result. The current chunk is ambiguous and later chunks were stopped.`\n );\n }\n}\n\nexport function assertCompleteCandidateEmailChunkResult(\n requested: ReadonlyArray<{ applicationId: string; roundId: string }>,\n result: CandidateEmailAggregate\n): void {\n assertExactResultKeys(\n requested.map((item) => candidateRoundKey(item.applicationId, item.roundId)),\n [\n ...result.succeeded.map((item) => candidateRoundKey(item.applicationId, item.roundId)),\n ...result.skipped.map((item) => candidateRoundKey(item.applicationId, item.roundId)),\n ...result.failed.map((item) => candidateRoundKey(item.applicationId, item.roundId)),\n ],\n 'The candidate email request'\n );\n}\n\nexport function aggregateCandidateEmailResult(\n aggregate: CandidateEmailAggregate,\n result: CandidateEmailAggregate\n): CandidateEmailAggregate {\n return {\n succeeded: [...aggregate.succeeded, ...result.succeeded],\n skipped: [...aggregate.skipped, ...result.skipped],\n failed: [...aggregate.failed, ...result.failed],\n };\n}\n\nexport interface EnsuredRoundSummary {\n id: string;\n applicationId: string;\n}\n\nexport interface EnsureRoundFailure {\n applicationId: string;\n code: string;\n message: string;\n}\n\nexport interface EnsureRoundAggregate {\n created: EnsuredRoundSummary[];\n alreadyPresent: EnsuredRoundSummary[];\n failed: EnsureRoundFailure[];\n}\n\nexport function createEmptyEnsureRoundAggregate(): EnsureRoundAggregate {\n return { created: [], alreadyPresent: [], failed: [] };\n}\n\nexport function assertCompleteEnsureRoundChunkResult(\n requestedApplicationIds: ReadonlyArray<string>,\n result: EnsureRoundAggregate\n): void {\n assertExactResultKeys(\n requestedApplicationIds,\n [\n ...result.created.map((item) => item.applicationId),\n ...result.alreadyPresent.map((item) => item.applicationId),\n ...result.failed.map((item) => item.applicationId),\n ],\n 'The add-to-round request'\n );\n}\n\nexport function aggregateEnsureRoundResult(\n aggregate: EnsureRoundAggregate,\n result: EnsureRoundAggregate\n): EnsureRoundAggregate {\n return {\n created: [...aggregate.created, ...result.created],\n alreadyPresent: [...aggregate.alreadyPresent, ...result.alreadyPresent],\n failed: [...aggregate.failed, ...result.failed],\n };\n}\n\nexport interface BulkCustomEmailSuccess {\n applicationId: string;\n email: string;\n}\n\nexport interface BulkCustomEmailFailureItem {\n applicationId: string;\n message: string;\n}\n\nexport interface BulkCustomEmailAggregate {\n succeeded: BulkCustomEmailSuccess[];\n failed: BulkCustomEmailFailureItem[];\n}\n\nexport function createEmptyBulkCustomEmailAggregate(): BulkCustomEmailAggregate {\n return { succeeded: [], failed: [] };\n}\n\nexport function assertCompleteBulkCustomEmailChunkResult(\n requestedApplicationIds: ReadonlyArray<string>,\n result: BulkCustomEmailAggregate\n): void {\n assertExactResultKeys(\n requestedApplicationIds,\n [\n ...result.succeeded.map((item) => item.applicationId),\n ...result.failed.map((item) => item.applicationId),\n ],\n 'The bulk custom email request'\n );\n}\n\nexport function aggregateBulkCustomEmailResult(\n aggregate: BulkCustomEmailAggregate,\n result: BulkCustomEmailAggregate\n): BulkCustomEmailAggregate {\n return {\n succeeded: [...aggregate.succeeded, ...result.succeeded],\n failed: [...aggregate.failed, ...result.failed],\n };\n}\n\nexport interface BulkStatusUpdateSuccess {\n applicationId: string;\n status: string;\n}\n\nexport interface BulkStatusUpdateFailureItem {\n applicationId: string;\n message: string;\n}\n\nexport interface BulkStatusUpdateAggregate {\n succeeded: BulkStatusUpdateSuccess[];\n failed: BulkStatusUpdateFailureItem[];\n}\n\nexport function createEmptyBulkStatusUpdateAggregate(): BulkStatusUpdateAggregate {\n return { succeeded: [], failed: [] };\n}\n\nexport function assertCompleteBulkStatusUpdateChunkResult(\n requestedApplicationIds: ReadonlyArray<string>,\n result: BulkStatusUpdateAggregate\n): void {\n assertExactResultKeys(\n requestedApplicationIds,\n [\n ...result.succeeded.map((item) => item.applicationId),\n ...result.failed.map((item) => item.applicationId),\n ],\n 'The bulk status update request'\n );\n}\n\nexport function aggregateBulkStatusUpdateResult(\n aggregate: BulkStatusUpdateAggregate,\n result: BulkStatusUpdateAggregate\n): BulkStatusUpdateAggregate {\n return {\n succeeded: [...aggregate.succeeded, ...result.succeeded],\n failed: [...aggregate.failed, ...result.failed],\n };\n}\n\nexport function hasCandidateEmailType(round: CandidateRoundPreview, emailType: string): boolean {\n return round.emailLogs.some((log) => log.emailType === emailType);\n}\n\nexport interface DuplicateNoticeSuccess {\n email: string;\n}\n\nexport interface DuplicateNoticeSkip {\n email: string;\n reason: string;\n message: string;\n}\n\nexport interface DuplicateNoticeFailure {\n email: string;\n message: string;\n}\n\nexport interface DuplicateNoticeAggregate {\n succeeded: DuplicateNoticeSuccess[];\n skipped: DuplicateNoticeSkip[];\n failed: DuplicateNoticeFailure[];\n}\n\nexport function createEmptyDuplicateNoticeAggregate(): DuplicateNoticeAggregate {\n return { succeeded: [], skipped: [], failed: [] };\n}\n\nexport function aggregateDuplicateNoticeResult(\n aggregate: DuplicateNoticeAggregate,\n result: DuplicateNoticeAggregate\n): DuplicateNoticeAggregate {\n return {\n succeeded: [...aggregate.succeeded, ...result.succeeded],\n skipped: [...aggregate.skipped, ...result.skipped],\n failed: [...aggregate.failed, ...result.failed],\n };\n}\n"],"mappings":"AAgCA,IAAa,IAAb,cAAmD,MAAM;CAErC;CADlB,YACE,GACA,GACA;EAEA,AADA,MAAM,CAAO,GAHG,KAAA,OAAA,GAIhB,KAAK,OAAO;CACd;AACF;AAUA,SAAS,EAAmB,GAAkB,GAA+B;CAC3E,IAAI,MAAa,GACf,MAAM,IAAI,EACR,eACA,gEACF;AAEJ;AAEA,eAAe,EAA+D,EAC5E,aACA,kBACA,cACA,uBACA,eAC4E;CAC5E,IAAM,oBAAc,IAAI,IAAqB,GACzC,IAAS;CAEb,SAAa;EACX,EAAmB,GAAU,EAAmB,CAAC;EACjD,IAAM,IAAO,MAAM,EAAU,GAAU,CAAM;EAG7C,IAFA,EAAmB,GAAU,EAAmB,CAAC,GAE7C,EAAK,UAAU,GACjB,MAAM,IAAI,EACR,eACA,+CAA+C,EAAc,MAAM,EAAK,MAAM,4BAChF;EAGF,IAAM,IAAgB,EAAK,MAAM;EACjC,IAAI,IAAgB,GAClB,MAAM,IAAI,EACR,uBACA,uBAAuB,EAAc,sCAAsC,EAAS,EACtF;EAEF,IAAI,EAAK,WAAW,MAAkB,GACpC,MAAM,IAAI,EACR,wBACA,mEACF;EAGF,KAAK,IAAM,KAAU,EAAK,OACxB,AAAK,EAAY,IAAI,EAAO,EAAE,KAC5B,EAAY,IAAI,EAAO,IAAI,CAAM;EAMrC,IAFA,KAAU,GAEN,CAAC,EAAK,SAAS;GACjB,IAAI,EAAY,SAAS,GACvB,MAAM,IAAI,EACR,yBACA,YAAY,EAAc,kCAAkC,EAAY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AAG,EAAO,UAAU,KAAK,MAAS,EAAK,aAAa,GACpD,GAAG,EAAO,OAAO,KAAK,MAAS,EAAK,aAAa,CACnD,GACA,gCACF;AACF;AAEA,SAAgB,EACd,GACA,GAC2B;CAC3B,OAAO;EACL,WAAW,CAAC,GAAG,EAAU,WAAW,GAAG,EAAO,SAAS;EACvD,QAAQ,CAAC,GAAG,EAAU,QAAQ,GAAG,EAAO,MAAM;CAChD;AACF;AAEA,SAAgB,EAAsB,GAA8B,GAA4B;CAC9F,OAAO,EAAM,UAAU,MAAM,MAAQ,EAAI,cAAc,CAAS;AAClE;AAuBA,SAAgB,IAAgE;CAC9E,OAAO;EAAE,WAAW,CAAC;EAAG,SAAS,CAAC;EAAG,QAAQ,CAAC;CAAE;AAClD;AAEA,SAAgB,EACd,GACA,GAC0B;CAC1B,OAAO;EACL,WAAW,CAAC,GAAG,EAAU,WAAW,GAAG,EAAO,SAAS;EACvD,SAAS,CAAC,GAAG,EAAU,SAAS,GAAG,EAAO,OAAO;EACjD,QAAQ,CAAC,GAAG,EAAU,QAAQ,GAAG,EAAO,MAAM;CAChD;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jobApplicationFilterParams.js","names":[],"sources":["../../../src/support/utils/jobApplicationFilterParams.ts"],"sourcesContent":["import {\n ConfiguredRoundState,\n InterviewRoundStatus,\n JobApplicationStatus,\n} from '../../generated/global-types';\n\n/**\n * URL-backed filter state for the Career → Job Applications list (BOFF-7068).\n *\n * The list unmounts whenever a reviewer opens a submission, so component state\n * cannot survive the round trip. The query string can: both the row link and\n * the detail page's \"Back to Applications\" button already forward\n * `location.search` verbatim, so filters parked here come back for free — and\n * they also survive a refresh and can be shared as a link.\n *\n * Everything is parsed defensively. A hand-edited or stale URL must never reach\n * the GraphQL variables with an unknown enum value, and must never produce a\n * combination the UI cannot render.\n */\n\nexport type JobApplicationViewMode = 'list' | 'kanban';\n\nexport interface JobApplicationFilterState {\n search: string;\n statuses: JobApplicationStatus[];\n roundStatuses: InterviewRoundStatus[];\n productId: string;\n jobPostingId: string;\n roundConfigId: string;\n configuredRoundState: ConfiguredRoundState | '';\n duplicateEmail: boolean;\n assignmentOwnerEmail: string;\n interviewerId: string;\n}\n\n/** Query-string key for each filter. Short names keep shared links readable. */\nexport const JOB_APPLICATION_FILTER_PARAM_KEYS = {\n search: 'q',\n statuses: 'status',\n roundStatuses: 'stage',\n productId: 'product',\n jobPostingId: 'posting',\n roundConfigId: 'round',\n configuredRoundState: 'roundState',\n duplicateEmail: 'dupes',\n assignmentOwnerEmail: 'owner',\n interviewerId: 'interviewer',\n} as const satisfies Record<keyof JobApplicationFilterState, string>;\n\n/** View mode and filter-panel disclosure are presentation, not filters. */\nexport const JOB_APPLICATION_VIEW_PARAM_KEY = 'view';\nexport const JOB_APPLICATION_FILTERS_OPEN_PARAM_KEY = 'filters';\n\nexport const EMPTY_JOB_APPLICATION_FILTERS: JobApplicationFilterState = {\n search: '',\n statuses: [],\n roundStatuses: [],\n productId: '',\n jobPostingId: '',\n roundConfigId: '',\n configuredRoundState: '',\n duplicateEmail: false,\n assignmentOwnerEmail: '',\n interviewerId: '',\n};\n\n/**\n * Free text goes straight into GraphQL variables, so cap it. Nobody searches\n * with 4 KB of text; a URL that claims otherwise was not typed by a user.\n */\nconst MAX_TEXT_LENGTH = 200;\n/** Identifiers are UUIDs in practice — this is only an upper sanity bound. */\nconst MAX_ID_LENGTH = 128;\n\nconst STATUS_ORDER = [\n JobApplicationStatus.New,\n JobApplicationStatus.Screening,\n JobApplicationStatus.Shortlisted,\n JobApplicationStatus.Interview,\n JobApplicationStatus.Hired,\n JobApplicationStatus.Rejected,\n JobApplicationStatus.Archived,\n] as const;\n\nconst ROUND_STATUS_ORDER = [\n InterviewRoundStatus.Scheduled,\n InterviewRoundStatus.AwaitingSubmission,\n InterviewRoundStatus.Submitted,\n InterviewRoundStatus.Completed,\n InterviewRoundStatus.Passed,\n InterviewRoundStatus.Failed,\n InterviewRoundStatus.NoShow,\n InterviewRoundStatus.Cancelled,\n] as const;\n\nconst CONFIGURED_ROUND_STATES = Object.values(ConfiguredRoundState);\n\n/**\n * The bound applied to every free-text filter, exported so a caller that has to\n * predict what serialization will write (the debounced inputs) uses this rule\n * rather than a second copy of it.\n */\nexport function normalizeJobApplicationFilterText(value: string): string {\n return value.trim().slice(0, MAX_TEXT_LENGTH);\n}\n\nfunction readText(raw: string | null, maxLength: number): string {\n return (raw ?? '').trim().slice(0, maxLength);\n}\n\n/**\n * Parses a comma-separated enum list, dropping anything unrecognised and\n * de-duplicating. Values come back in `allowed` order rather than URL order so\n * that two URLs selecting the same set serialize identically — which keeps the\n * page's query-scope key (and therefore Apollo's cache key) stable.\n */\nfunction readEnumList<T extends string>(raw: string | null, allowed: readonly T[]): T[] {\n if (!raw) return [];\n const requested = new Set(raw.split(',').map((piece) => piece.trim().toUpperCase()));\n return allowed.filter((value) => requested.has(value));\n}\n\n/**\n * Applies the dependency rules the filter UI enforces through its own controls,\n * so a URL can never describe a state the panel could not have produced:\n * round/duplicate filters need a posting, an assignment state needs a round,\n * and \"missing this round\" is incompatible with round-stage chips.\n */\nfunction normalizeJobApplicationFilters(\n state: JobApplicationFilterState\n): JobApplicationFilterState {\n // Bounds live here rather than only in the parse path: a value committed from\n // a control (a 500-character paste into the search box) is serialized without\n // ever passing through `parseJobApplicationFilters`, and an uncapped value\n // written to the query string rides on into history, detail links and shared\n // URLs even though the parse that follows would clamp it.\n const jobPostingId = state.jobPostingId.trim().slice(0, MAX_ID_LENGTH);\n const roundConfigId = jobPostingId ? state.roundConfigId.trim().slice(0, MAX_ID_LENGTH) : '';\n const configuredRoundState = roundConfigId ? state.configuredRoundState : '';\n const roundStatuses =\n configuredRoundState === ConfiguredRoundState.Missing ? [] : state.roundStatuses;\n\n return {\n ...state,\n search: normalizeJobApplicationFilterText(state.search),\n assignmentOwnerEmail: normalizeJobApplicationFilterText(state.assignmentOwnerEmail),\n productId: state.productId.trim().slice(0, MAX_ID_LENGTH),\n interviewerId: state.interviewerId.trim().slice(0, MAX_ID_LENGTH),\n jobPostingId,\n roundConfigId,\n configuredRoundState,\n roundStatuses,\n duplicateEmail: jobPostingId ? state.duplicateEmail : false,\n };\n}\n\nexport function parseJobApplicationFilters(params: URLSearchParams): JobApplicationFilterState {\n const keys = JOB_APPLICATION_FILTER_PARAM_KEYS;\n\n const configuredRoundStateRaw = readText(params.get(keys.configuredRoundState), MAX_ID_LENGTH);\n const configuredRoundState =\n CONFIGURED_ROUND_STATES.find((state) => state === configuredRoundStateRaw.toUpperCase()) ?? '';\n\n return normalizeJobApplicationFilters({\n search: readText(params.get(keys.search), MAX_TEXT_LENGTH),\n statuses: readEnumList(params.get(keys.statuses), STATUS_ORDER),\n roundStatuses: readEnumList(params.get(keys.roundStatuses), ROUND_STATUS_ORDER),\n productId: readText(params.get(keys.productId), MAX_ID_LENGTH),\n jobPostingId: readText(params.get(keys.jobPostingId), MAX_ID_LENGTH),\n roundConfigId: readText(params.get(keys.roundConfigId), MAX_ID_LENGTH),\n configuredRoundState,\n duplicateEmail: params.get(keys.duplicateEmail) === '1',\n assignmentOwnerEmail: readText(params.get(keys.assignmentOwnerEmail), MAX_TEXT_LENGTH),\n interviewerId: readText(params.get(keys.interviewerId), MAX_ID_LENGTH),\n });\n}\n\n/**\n * Serializes to `{ key: value | null }`, where `null` means \"remove this key\".\n * Inactive filters are removed rather than written as empty values so a list\n * with nothing applied has a clean URL.\n */\nexport function serializeJobApplicationFilters(\n state: JobApplicationFilterState\n): Record<string, string | null> {\n const keys = JOB_APPLICATION_FILTER_PARAM_KEYS;\n const normalized = normalizeJobApplicationFilters(state);\n\n return {\n [keys.search]: normalized.search || null,\n [keys.statuses]: normalized.statuses.length > 0 ? normalized.statuses.join(',') : null,\n [keys.roundStatuses]:\n normalized.roundStatuses.length > 0 ? normalized.roundStatuses.join(',') : null,\n [keys.productId]: normalized.productId || null,\n [keys.jobPostingId]: normalized.jobPostingId || null,\n [keys.roundConfigId]: normalized.roundConfigId || null,\n [keys.configuredRoundState]: normalized.configuredRoundState || null,\n [keys.duplicateEmail]: normalized.duplicateEmail ? '1' : null,\n [keys.assignmentOwnerEmail]: normalized.assignmentOwnerEmail || null,\n [keys.interviewerId]: normalized.interviewerId || null,\n };\n}\n\n/**\n * Writes the filter state onto `current`, leaving every unrelated key\n * (`org`, `workspace`, `project`, `view`, …) exactly as it was.\n */\nexport function applyJobApplicationFilters(\n current: URLSearchParams,\n state: JobApplicationFilterState\n): URLSearchParams {\n const next = new URLSearchParams(current);\n for (const [key, value] of Object.entries(serializeJobApplicationFilters(state))) {\n if (value === null) next.delete(key);\n else next.set(key, value);\n }\n return next;\n}\n\n/** Drops every filter key and nothing else — context params and view survive. */\nexport function clearJobApplicationFilters(current: URLSearchParams): URLSearchParams {\n const next = new URLSearchParams(current);\n for (const key of Object.values(JOB_APPLICATION_FILTER_PARAM_KEYS)) next.delete(key);\n return next;\n}\n\n/**\n * Number of filters shown inside the filter panel that are currently applied —\n * drives the count badge on the Filters button. The search box sits outside the\n * panel and is visible on its own, so it is deliberately not counted here.\n */\nexport function countActiveJobApplicationFilters(state: JobApplicationFilterState): number {\n const normalized = normalizeJobApplicationFilters(state);\n return (\n (normalized.statuses.length > 0 ? 1 : 0) +\n (normalized.roundStatuses.length > 0 ? 1 : 0) +\n (normalized.productId ? 1 : 0) +\n (normalized.jobPostingId ? 1 : 0) +\n (normalized.roundConfigId ? 1 : 0) +\n (normalized.configuredRoundState ? 1 : 0) +\n (normalized.duplicateEmail ? 1 : 0) +\n (normalized.assignmentOwnerEmail ? 1 : 0) +\n (normalized.interviewerId ? 1 : 0)\n );\n}\n\n/** True when anything at all narrows the list, including the search box. */\nexport function hasActiveJobApplicationFilters(state: JobApplicationFilterState): boolean {\n return countActiveJobApplicationFilters(state) > 0 || state.search.length > 0;\n}\n\nexport function parseJobApplicationViewMode(raw: string | null): JobApplicationViewMode {\n return raw === 'kanban' ? 'kanban' : 'list';\n}\n\n/**\n * fe-libs' `ActiveContextProvider` writes `org`/`workspace`/`project` with a raw\n * `history.replaceState`, which `BrowserRouter` never observes — so React\n * Router's snapshot of the query string can be missing params that really are\n * in the address bar. Writing that snapshot back would silently strip the\n * active context from the URL.\n *\n * The address bar is therefore the base, and the router snapshot only\n * contributes keys the address bar lacks (which is how the MemoryRouter used by\n * standalone mode and by tests keeps working, since there `window.location`\n * never moves).\n */\nexport function mergeSearchParams(\n routerParams: URLSearchParams,\n windowSearch: string\n): URLSearchParams {\n const merged = new URLSearchParams(windowSearch);\n for (const [key, value] of routerParams.entries()) {\n if (!merged.has(key)) merged.set(key, value);\n }\n return merged;\n}\n\n/**\n * Identity of the active support context as one comparable string. Filters are\n * only meaningful inside a single org/workspace/product, so this key is what\n * both the list page and `JobApplicationFilterContextGuard` compare to decide\n * whether the URL-persisted filters still belong to the context on screen.\n */\nexport function buildSupportContextKey(\n organizationId: string | undefined,\n workspaceId: string | undefined,\n productId: string | undefined\n): string {\n return `${organizationId ?? ''}|${workspaceId ?? ''}|${productId ?? ''}`;\n}\n\n/**\n * True when every axis that changed went from empty to a value — the shell\n * finishing its context resolution, not the reviewer switching context.\n *\n * The distinction matters because the shell hands the microfrontend\n * `activeContext.workspaceId ?? ''`, and `??` does not catch the empty string,\n * so a microfrontend that mounts before the context settles observes\n * `'' -> id`. Treated as a switch, that would strip the filters off a\n * deep-linked or refreshed URL before the reviewer ever saw them.\n *\n * Only a fill counts: an axis moving between two non-empty values, or being\n * emptied, is a genuine switch and must still clear the filters.\n */\nexport function isSupportContextHydration(previousKey: string, nextKey: string): boolean {\n const previous = previousKey.split('|');\n const next = nextKey.split('|');\n // Differing arity means one side is not a key this module built, so it cannot\n // be read as a fill — fall through to the switch path, which clears.\n if (previous.length !== next.length) return false;\n return previous.every((value, index) => value === next[index] || value === '');\n}\n"],"mappings":";;AAoCA,IAAa,IAAoC;CAC/C,QAAQ;CACR,UAAU;CACV,eAAe;CACf,WAAW;CACX,cAAc;CACd,eAAe;CACf,sBAAsB;CACtB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,OADI,EAAS,WAAW,EAAK,UACtB,EAAS,OAAO,GAAO,MAAU,MAAU,EAAK,MAAU,MAAU,EAAE;AAC/E"}
|
|
1
|
+
{"version":3,"file":"jobApplicationFilterParams.js","names":[],"sources":["../../../src/support/utils/jobApplicationFilterParams.ts"],"sourcesContent":["import {\n ConfiguredRoundState,\n InterviewRoundStatus,\n JobApplicationStatus,\n} from '../../generated/global-types';\n\n/**\n * URL-backed filter state for the Career → Job Applications list (BOFF-7068).\n *\n * The list unmounts whenever a reviewer opens a submission, so component state\n * cannot survive the round trip. The query string can: both the row link and\n * the detail page's \"Back to Applications\" button already forward\n * `location.search` verbatim, so filters parked here come back for free — and\n * they also survive a refresh and can be shared as a link.\n *\n * Everything is parsed defensively. A hand-edited or stale URL must never reach\n * the GraphQL variables with an unknown enum value, and must never produce a\n * combination the UI cannot render.\n */\n\nexport type JobApplicationViewMode = 'list' | 'kanban';\n\nexport interface JobApplicationFilterState {\n search: string;\n statuses: JobApplicationStatus[];\n roundStatuses: InterviewRoundStatus[];\n productId: string;\n jobPostingId: string;\n roundConfigId: string;\n configuredRoundState: ConfiguredRoundState | '';\n duplicateEmail: boolean;\n assignmentOwnerEmail: string;\n interviewerId: string;\n}\n\n/** Query-string key for each filter. Short names keep shared links readable. */\nexport const JOB_APPLICATION_FILTER_PARAM_KEYS = {\n search: 'q',\n statuses: 'status',\n roundStatuses: 'stage',\n productId: 'product',\n jobPostingId: 'posting',\n roundConfigId: 'round',\n configuredRoundState: 'roundState',\n duplicateEmail: 'dupes',\n assignmentOwnerEmail: 'owner',\n interviewerId: 'interviewer',\n} as const satisfies Record<keyof JobApplicationFilterState, string>;\n\n/** View mode and filter-panel disclosure are presentation, not filters. */\nexport const JOB_APPLICATION_VIEW_PARAM_KEY = 'view';\nexport const JOB_APPLICATION_FILTERS_OPEN_PARAM_KEY = 'filters';\n\nexport const EMPTY_JOB_APPLICATION_FILTERS: JobApplicationFilterState = {\n search: '',\n statuses: [],\n roundStatuses: [],\n productId: '',\n jobPostingId: '',\n roundConfigId: '',\n configuredRoundState: '',\n duplicateEmail: false,\n assignmentOwnerEmail: '',\n interviewerId: '',\n};\n\n/**\n * Free text goes straight into GraphQL variables, so cap it. Nobody searches\n * with 4 KB of text; a URL that claims otherwise was not typed by a user.\n */\nconst MAX_TEXT_LENGTH = 200;\n/** Identifiers are UUIDs in practice — this is only an upper sanity bound. */\nconst MAX_ID_LENGTH = 128;\n\nconst STATUS_ORDER = [\n JobApplicationStatus.New,\n JobApplicationStatus.Screening,\n JobApplicationStatus.Shortlisted,\n JobApplicationStatus.Interview,\n JobApplicationStatus.Hired,\n JobApplicationStatus.Rejected,\n JobApplicationStatus.EmailSent,\n JobApplicationStatus.Archived,\n] as const;\n\nconst ROUND_STATUS_ORDER = [\n InterviewRoundStatus.Scheduled,\n InterviewRoundStatus.AwaitingSubmission,\n InterviewRoundStatus.Submitted,\n InterviewRoundStatus.Completed,\n InterviewRoundStatus.Passed,\n InterviewRoundStatus.Failed,\n InterviewRoundStatus.NoShow,\n InterviewRoundStatus.Cancelled,\n] as const;\n\nconst CONFIGURED_ROUND_STATES = Object.values(ConfiguredRoundState);\n\n/**\n * The bound applied to every free-text filter, exported so a caller that has to\n * predict what serialization will write (the debounced inputs) uses this rule\n * rather than a second copy of it.\n */\nexport function normalizeJobApplicationFilterText(value: string): string {\n return value.trim().slice(0, MAX_TEXT_LENGTH);\n}\n\nfunction readText(raw: string | null, maxLength: number): string {\n return (raw ?? '').trim().slice(0, maxLength);\n}\n\n/**\n * Parses a comma-separated enum list, dropping anything unrecognised and\n * de-duplicating. Values come back in `allowed` order rather than URL order so\n * that two URLs selecting the same set serialize identically — which keeps the\n * page's query-scope key (and therefore Apollo's cache key) stable.\n */\nfunction readEnumList<T extends string>(raw: string | null, allowed: readonly T[]): T[] {\n if (!raw) return [];\n const requested = new Set(raw.split(',').map((piece) => piece.trim().toUpperCase()));\n return allowed.filter((value) => requested.has(value));\n}\n\n/**\n * Applies the dependency rules the filter UI enforces through its own controls,\n * so a URL can never describe a state the panel could not have produced:\n * round/duplicate filters need a posting, an assignment state needs a round,\n * and \"missing this round\" is incompatible with round-stage chips.\n */\nfunction normalizeJobApplicationFilters(\n state: JobApplicationFilterState\n): JobApplicationFilterState {\n // Bounds live here rather than only in the parse path: a value committed from\n // a control (a 500-character paste into the search box) is serialized without\n // ever passing through `parseJobApplicationFilters`, and an uncapped value\n // written to the query string rides on into history, detail links and shared\n // URLs even though the parse that follows would clamp it.\n const jobPostingId = state.jobPostingId.trim().slice(0, MAX_ID_LENGTH);\n const roundConfigId = jobPostingId ? state.roundConfigId.trim().slice(0, MAX_ID_LENGTH) : '';\n const configuredRoundState = roundConfigId ? state.configuredRoundState : '';\n const roundStatuses =\n configuredRoundState === ConfiguredRoundState.Missing ? [] : state.roundStatuses;\n\n return {\n ...state,\n search: normalizeJobApplicationFilterText(state.search),\n assignmentOwnerEmail: normalizeJobApplicationFilterText(state.assignmentOwnerEmail),\n productId: state.productId.trim().slice(0, MAX_ID_LENGTH),\n interviewerId: state.interviewerId.trim().slice(0, MAX_ID_LENGTH),\n jobPostingId,\n roundConfigId,\n configuredRoundState,\n roundStatuses,\n duplicateEmail: jobPostingId ? state.duplicateEmail : false,\n };\n}\n\nexport function parseJobApplicationFilters(params: URLSearchParams): JobApplicationFilterState {\n const keys = JOB_APPLICATION_FILTER_PARAM_KEYS;\n\n const configuredRoundStateRaw = readText(params.get(keys.configuredRoundState), MAX_ID_LENGTH);\n const configuredRoundState =\n CONFIGURED_ROUND_STATES.find((state) => state === configuredRoundStateRaw.toUpperCase()) ?? '';\n\n return normalizeJobApplicationFilters({\n search: readText(params.get(keys.search), MAX_TEXT_LENGTH),\n statuses: readEnumList(params.get(keys.statuses), STATUS_ORDER),\n roundStatuses: readEnumList(params.get(keys.roundStatuses), ROUND_STATUS_ORDER),\n productId: readText(params.get(keys.productId), MAX_ID_LENGTH),\n jobPostingId: readText(params.get(keys.jobPostingId), MAX_ID_LENGTH),\n roundConfigId: readText(params.get(keys.roundConfigId), MAX_ID_LENGTH),\n configuredRoundState,\n duplicateEmail: params.get(keys.duplicateEmail) === '1',\n assignmentOwnerEmail: readText(params.get(keys.assignmentOwnerEmail), MAX_TEXT_LENGTH),\n interviewerId: readText(params.get(keys.interviewerId), MAX_ID_LENGTH),\n });\n}\n\n/**\n * Serializes to `{ key: value | null }`, where `null` means \"remove this key\".\n * Inactive filters are removed rather than written as empty values so a list\n * with nothing applied has a clean URL.\n */\nexport function serializeJobApplicationFilters(\n state: JobApplicationFilterState\n): Record<string, string | null> {\n const keys = JOB_APPLICATION_FILTER_PARAM_KEYS;\n const normalized = normalizeJobApplicationFilters(state);\n\n return {\n [keys.search]: normalized.search || null,\n [keys.statuses]: normalized.statuses.length > 0 ? normalized.statuses.join(',') : null,\n [keys.roundStatuses]:\n normalized.roundStatuses.length > 0 ? normalized.roundStatuses.join(',') : null,\n [keys.productId]: normalized.productId || null,\n [keys.jobPostingId]: normalized.jobPostingId || null,\n [keys.roundConfigId]: normalized.roundConfigId || null,\n [keys.configuredRoundState]: normalized.configuredRoundState || null,\n [keys.duplicateEmail]: normalized.duplicateEmail ? '1' : null,\n [keys.assignmentOwnerEmail]: normalized.assignmentOwnerEmail || null,\n [keys.interviewerId]: normalized.interviewerId || null,\n };\n}\n\n/**\n * Writes the filter state onto `current`, leaving every unrelated key\n * (`org`, `workspace`, `project`, `view`, …) exactly as it was.\n */\nexport function applyJobApplicationFilters(\n current: URLSearchParams,\n state: JobApplicationFilterState\n): URLSearchParams {\n const next = new URLSearchParams(current);\n for (const [key, value] of Object.entries(serializeJobApplicationFilters(state))) {\n if (value === null) next.delete(key);\n else next.set(key, value);\n }\n return next;\n}\n\n/** Drops every filter key and nothing else — context params and view survive. */\nexport function clearJobApplicationFilters(current: URLSearchParams): URLSearchParams {\n const next = new URLSearchParams(current);\n for (const key of Object.values(JOB_APPLICATION_FILTER_PARAM_KEYS)) next.delete(key);\n return next;\n}\n\n/**\n * Number of filters shown inside the filter panel that are currently applied —\n * drives the count badge on the Filters button. The search box sits outside the\n * panel and is visible on its own, so it is deliberately not counted here.\n */\nexport function countActiveJobApplicationFilters(state: JobApplicationFilterState): number {\n const normalized = normalizeJobApplicationFilters(state);\n return (\n (normalized.statuses.length > 0 ? 1 : 0) +\n (normalized.roundStatuses.length > 0 ? 1 : 0) +\n (normalized.productId ? 1 : 0) +\n (normalized.jobPostingId ? 1 : 0) +\n (normalized.roundConfigId ? 1 : 0) +\n (normalized.configuredRoundState ? 1 : 0) +\n (normalized.duplicateEmail ? 1 : 0) +\n (normalized.assignmentOwnerEmail ? 1 : 0) +\n (normalized.interviewerId ? 1 : 0)\n );\n}\n\n/** True when anything at all narrows the list, including the search box. */\nexport function hasActiveJobApplicationFilters(state: JobApplicationFilterState): boolean {\n return countActiveJobApplicationFilters(state) > 0 || state.search.length > 0;\n}\n\nexport function parseJobApplicationViewMode(raw: string | null): JobApplicationViewMode {\n return raw === 'kanban' ? 'kanban' : 'list';\n}\n\n/**\n * fe-libs' `ActiveContextProvider` writes `org`/`workspace`/`project` with a raw\n * `history.replaceState`, which `BrowserRouter` never observes — so React\n * Router's snapshot of the query string can be missing params that really are\n * in the address bar. Writing that snapshot back would silently strip the\n * active context from the URL.\n *\n * The address bar is therefore the base, and the router snapshot only\n * contributes keys the address bar lacks (which is how the MemoryRouter used by\n * standalone mode and by tests keeps working, since there `window.location`\n * never moves).\n */\nexport function mergeSearchParams(\n routerParams: URLSearchParams,\n windowSearch: string\n): URLSearchParams {\n const merged = new URLSearchParams(windowSearch);\n for (const [key, value] of routerParams.entries()) {\n if (!merged.has(key)) merged.set(key, value);\n }\n return merged;\n}\n\n/**\n * Identity of the active support context as one comparable string. Filters are\n * only meaningful inside a single org/workspace/product, so this key is what\n * both the list page and `JobApplicationFilterContextGuard` compare to decide\n * whether the URL-persisted filters still belong to the context on screen.\n */\nexport function buildSupportContextKey(\n organizationId: string | undefined,\n workspaceId: string | undefined,\n productId: string | undefined\n): string {\n return `${organizationId ?? ''}|${workspaceId ?? ''}|${productId ?? ''}`;\n}\n\n/**\n * True when every axis that changed went from empty to a value — the shell\n * finishing its context resolution, not the reviewer switching context.\n *\n * The distinction matters because the shell hands the microfrontend\n * `activeContext.workspaceId ?? ''`, and `??` does not catch the empty string,\n * so a microfrontend that mounts before the context settles observes\n * `'' -> id`. Treated as a switch, that would strip the filters off a\n * deep-linked or refreshed URL before the reviewer ever saw them.\n *\n * Only a fill counts: an axis moving between two non-empty values, or being\n * emptied, is a genuine switch and must still clear the filters.\n */\nexport function isSupportContextHydration(previousKey: string, nextKey: string): boolean {\n const previous = previousKey.split('|');\n const next = nextKey.split('|');\n // Differing arity means one side is not a key this module built, so it cannot\n // be read as a fill — fall through to the switch path, which clears.\n if (previous.length !== next.length) return false;\n return previous.every((value, index) => value === next[index] || value === '');\n}\n"],"mappings":";;AAoCA,IAAa,IAAoC;CAC/C,QAAQ;CACR,UAAU;CACV,eAAe;CACf,WAAW;CACX,cAAc;CACd,eAAe;CACf,sBAAsB;CACtB,gBAAgB;CAChB,sBAAsB;CACtB,eAAe;AACjB,GAGa,IAAiC,QACjC,IAAyC,WAmBhD,IAAkB,KAElB,IAAgB,KAEhB,IAAe;CACnB,EAAqB;CACrB,EAAqB;CACrB,EAAqB;CACrB,EAAqB;CACrB,EAAqB;CACrB,EAAqB;CACrB,EAAqB;CACrB,EAAqB;AACvB,GAEM,IAAqB;CACzB,EAAqB;CACrB,EAAqB;CACrB,EAAqB;CACrB,EAAqB;CACrB,EAAqB;CACrB,EAAqB;CACrB,EAAqB;CACrB,EAAqB;AACvB,GAEM,IAA0B,OAAO,OAAO,CAAoB;AAOlE,SAAgB,EAAkC,GAAuB;CACvE,OAAO,EAAM,KAAK,CAAC,CAAC,MAAM,GAAG,CAAe;AAC9C;AAEA,SAAS,EAAS,GAAoB,GAA2B;CAC/D,QAAQ,KAAO,GAAA,CAAI,KAAK,CAAC,CAAC,MAAM,GAAG,CAAS;AAC9C;AAQA,SAAS,EAA+B,GA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