@open-mercato/core 0.6.6-develop.6515.1.01911d00e2 → 0.6.6-develop.6519.1.bdc91fb755

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.
Files changed (86) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/modules/configs/lib/upgrade-actions.js +31 -1
  3. package/dist/modules/configs/lib/upgrade-actions.js.map +2 -2
  4. package/dist/modules/customers/ai-tools/activities-tasks-pack.js +11 -2
  5. package/dist/modules/customers/ai-tools/activities-tasks-pack.js.map +2 -2
  6. package/dist/modules/customers/api/companies/[id]/route.js +3 -2
  7. package/dist/modules/customers/api/companies/[id]/route.js.map +2 -2
  8. package/dist/modules/customers/api/dictionaries/context.js +4 -2
  9. package/dist/modules/customers/api/dictionaries/context.js.map +2 -2
  10. package/dist/modules/customers/api/interactions/conflicts/route.js +2 -1
  11. package/dist/modules/customers/api/interactions/conflicts/route.js.map +2 -2
  12. package/dist/modules/customers/api/interactions/counts/route.js +7 -2
  13. package/dist/modules/customers/api/interactions/counts/route.js.map +2 -2
  14. package/dist/modules/customers/api/people/[id]/route.js +3 -2
  15. package/dist/modules/customers/api/people/[id]/route.js.map +2 -2
  16. package/dist/modules/customers/cli.js +19 -0
  17. package/dist/modules/customers/cli.js.map +2 -2
  18. package/dist/modules/customers/commands/interactions.js +8 -3
  19. package/dist/modules/customers/commands/interactions.js.map +2 -2
  20. package/dist/modules/customers/commands/shared.js +2 -1
  21. package/dist/modules/customers/commands/shared.js.map +2 -2
  22. package/dist/modules/customers/components/DictionarySettings.js +5 -0
  23. package/dist/modules/customers/components/DictionarySettings.js.map +2 -2
  24. package/dist/modules/customers/components/DictionarySortSettings.js +5 -0
  25. package/dist/modules/customers/components/DictionarySortSettings.js.map +2 -2
  26. package/dist/modules/customers/components/detail/ActivitiesCard.js +3 -2
  27. package/dist/modules/customers/components/detail/ActivitiesCard.js.map +2 -2
  28. package/dist/modules/customers/components/detail/ActivityCard.js +2 -1
  29. package/dist/modules/customers/components/detail/ActivityCard.js.map +2 -2
  30. package/dist/modules/customers/components/detail/ActivityTimeline.js +3 -2
  31. package/dist/modules/customers/components/detail/ActivityTimeline.js.map +2 -2
  32. package/dist/modules/customers/components/detail/TaskDialog.js +3 -2
  33. package/dist/modules/customers/components/detail/TaskDialog.js.map +2 -2
  34. package/dist/modules/customers/components/detail/TaskForm.js +170 -69
  35. package/dist/modules/customers/components/detail/TaskForm.js.map +2 -2
  36. package/dist/modules/customers/components/detail/TasksSection.js +27 -4
  37. package/dist/modules/customers/components/detail/TasksSection.js.map +2 -2
  38. package/dist/modules/customers/components/detail/hooks/usePersonTasks.js.map +2 -2
  39. package/dist/modules/customers/data/enrichers.js +2 -2
  40. package/dist/modules/customers/data/enrichers.js.map +2 -2
  41. package/dist/modules/customers/data/validators.js +6 -2
  42. package/dist/modules/customers/data/validators.js.map +2 -2
  43. package/dist/modules/customers/lib/dictionaries.js +2 -1
  44. package/dist/modules/customers/lib/dictionaries.js.map +2 -2
  45. package/dist/modules/customers/lib/interactionProjection.js +2 -1
  46. package/dist/modules/customers/lib/interactionProjection.js.map +2 -2
  47. package/dist/modules/customers/lib/interactionStatus.js +24 -0
  48. package/dist/modules/customers/lib/interactionStatus.js.map +7 -0
  49. package/dist/modules/customers/lib/link-channel-message-handler.js +4 -5
  50. package/dist/modules/customers/lib/link-channel-message-handler.js.map +2 -2
  51. package/dist/modules/dictionaries/components/AppearanceSelector.js +7 -3
  52. package/dist/modules/dictionaries/components/AppearanceSelector.js.map +2 -2
  53. package/dist/modules/dictionaries/components/DictionaryEntriesEditor.js +1 -0
  54. package/dist/modules/dictionaries/components/DictionaryEntriesEditor.js.map +2 -2
  55. package/package.json +7 -7
  56. package/src/modules/configs/lib/upgrade-actions.ts +31 -1
  57. package/src/modules/customers/ai-tools/activities-tasks-pack.ts +12 -3
  58. package/src/modules/customers/api/companies/[id]/route.ts +3 -2
  59. package/src/modules/customers/api/dictionaries/context.ts +2 -0
  60. package/src/modules/customers/api/interactions/conflicts/route.ts +2 -1
  61. package/src/modules/customers/api/interactions/counts/route.ts +7 -2
  62. package/src/modules/customers/api/people/[id]/route.ts +3 -2
  63. package/src/modules/customers/cli.ts +19 -0
  64. package/src/modules/customers/commands/interactions.ts +8 -3
  65. package/src/modules/customers/commands/shared.ts +1 -0
  66. package/src/modules/customers/components/DictionarySettings.tsx +5 -0
  67. package/src/modules/customers/components/DictionarySortSettings.tsx +5 -0
  68. package/src/modules/customers/components/detail/ActivitiesCard.tsx +3 -2
  69. package/src/modules/customers/components/detail/ActivityCard.tsx +2 -1
  70. package/src/modules/customers/components/detail/ActivityTimeline.tsx +3 -2
  71. package/src/modules/customers/components/detail/TaskDialog.tsx +4 -1
  72. package/src/modules/customers/components/detail/TaskForm.tsx +218 -71
  73. package/src/modules/customers/components/detail/TasksSection.tsx +28 -2
  74. package/src/modules/customers/components/detail/hooks/usePersonTasks.ts +1 -0
  75. package/src/modules/customers/data/enrichers.ts +2 -7
  76. package/src/modules/customers/data/validators.ts +16 -2
  77. package/src/modules/customers/i18n/de.json +10 -0
  78. package/src/modules/customers/i18n/en.json +10 -0
  79. package/src/modules/customers/i18n/es.json +10 -0
  80. package/src/modules/customers/i18n/pl.json +10 -0
  81. package/src/modules/customers/lib/dictionaries.ts +1 -0
  82. package/src/modules/customers/lib/interactionProjection.ts +6 -2
  83. package/src/modules/customers/lib/interactionStatus.ts +30 -0
  84. package/src/modules/customers/lib/link-channel-message-handler.ts +4 -5
  85. package/src/modules/dictionaries/components/AppearanceSelector.tsx +10 -1
  86. package/src/modules/dictionaries/components/DictionaryEntriesEditor.tsx +1 -0
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/modules/customers/components/detail/TasksSection.tsx"],
4
- "sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport Link from 'next/link'\nimport { Loader2, Pencil, Trash2 } from 'lucide-react'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { IconButton } from '@open-mercato/ui/primitives/icon-button'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { LoadingMessage, TabEmptyState } from '@open-mercato/ui/backend/detail'\nimport { cn } from '@open-mercato/shared/lib/utils'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport type { InteractionSummary, SectionAction, TabEmptyStateConfig, TodoLinkSummary, Translator } from './types'\nimport { createTranslatorWithFallback } from '@open-mercato/shared/lib/i18n/translate'\nimport { formatDate, resolveTodoHref } from './utils'\nimport { formatDateTime } from '@open-mercato/shared/lib/time'\nimport { TimelineItemHeader } from './TimelineItemHeader'\nimport { TaskDialog } from './TaskDialog'\nimport { usePersonTasks, type TaskFormPayload } from './hooks/usePersonTasks'\nimport { useInteractions, type InteractionCreatePayload } from './hooks/useInteractions'\nimport { mapInteractionRecordToTodoSummary } from '../../lib/interactionCompatibility'\n\ntype GuardedMutationRunner = <T>(\n operation: () => Promise<T>,\n mutationPayload?: Record<string, unknown>,\n) => Promise<T>\n\ntype TasksSectionProps = {\n entityId: string | null\n initialTasks: TodoLinkSummary[]\n emptyLabel: string\n addActionLabel: string\n emptyState: TabEmptyStateConfig\n onActionChange?: (action: SectionAction | null) => void\n onLoadingChange?: (isLoading: boolean) => void\n onDataRefresh?: () => void\n translator?: Translator\n entityName?: string | null\n dialogContextKey?: string\n dialogContextFallback?: string\n /** When true, use the canonical interactions API instead of the legacy todos API. */\n useCanonicalInteractions?: boolean\n runGuardedMutation?: GuardedMutationRunner\n}\n\nconst RESERVED_TASK_CUSTOM_KEYS = new Set(['priority', 'description', 'due_at', 'dueAt'])\n\nfunction toTimestamp(value: string | null | undefined): number | null {\n if (!value) return null\n const timestamp = new Date(value).getTime()\n return Number.isNaN(timestamp) ? null : timestamp\n}\n\nfunction sortTaskSummaries(tasks: TodoLinkSummary[]): TodoLinkSummary[] {\n return [...tasks].sort((left, right) => {\n const leftDue = toTimestamp(left.dueAt)\n const rightDue = toTimestamp(right.dueAt)\n if (leftDue !== null || rightDue !== null) {\n if (leftDue === null) return 1\n if (rightDue === null) return -1\n if (leftDue !== rightDue) return leftDue - rightDue\n }\n const leftCreated = toTimestamp(left.createdAt) ?? 0\n const rightCreated = toTimestamp(right.createdAt) ?? 0\n if (leftCreated !== rightCreated) return rightCreated - leftCreated\n return left.id.localeCompare(right.id)\n })\n}\n\nfunction buildInitialFormValues(task: TodoLinkSummary | null): Record<string, unknown> | undefined {\n if (!task) return undefined\n const values: Record<string, unknown> = {\n title: task.title ?? '',\n is_done: task.isDone ?? false,\n description: task.description ?? '',\n priority: task.priority ?? '',\n scheduledAt: task.dueAt ?? '',\n }\n if (task.customValues) {\n for (const [key, value] of Object.entries(task.customValues)) {\n if (RESERVED_TASK_CUSTOM_KEYS.has(key)) continue\n const formKey = `cf_${key}`\n if (values[formKey] === undefined) values[formKey] = value\n }\n }\n return values\n}\n\nexport function TasksSection({\n entityId,\n initialTasks,\n emptyLabel,\n addActionLabel,\n emptyState,\n onActionChange,\n onLoadingChange,\n onDataRefresh,\n translator,\n entityName,\n dialogContextKey,\n dialogContextFallback,\n useCanonicalInteractions = false,\n runGuardedMutation,\n}: TasksSectionProps) {\n const tHook = useT()\n const fallbackTranslator = React.useMemo<Translator>(() => createTranslatorWithFallback(tHook), [tHook])\n const t: Translator = React.useMemo(() => translator ?? fallbackTranslator, [translator, fallbackTranslator])\n const runWriteMutation = React.useCallback(\n async <T,>(operation: () => Promise<T>, mutationPayload?: Record<string, unknown>): Promise<T> => {\n if (!runGuardedMutation) {\n return operation()\n }\n return runGuardedMutation(operation, mutationPayload)\n },\n [runGuardedMutation],\n )\n\n // Legacy path: usePersonTasks (default)\n const legacyResult = usePersonTasks({ entityId, initialTasks })\n\n // Canonical path: useInteractions with planned-status filter\n const canonicalResult = useInteractions({\n entityId: useCanonicalInteractions ? entityId : null,\n typeFilter: 'task',\n })\n\n // Map canonical interactions to the TodoLinkSummary shape used by the rendering below\n const canonicalTasks = React.useMemo<TodoLinkSummary[]>(\n () => (useCanonicalInteractions ? canonicalResult.interactions.map(mapInteractionRecordToTodoSummary) : []),\n [useCanonicalInteractions, canonicalResult.interactions],\n )\n\n const canonicalCreateTask = React.useCallback(\n async (payload: TaskFormPayload) => {\n if (!entityId) throw new Error('Task creation requires an entity id')\n const interactionPayload: InteractionCreatePayload = {\n entityId,\n interactionType: 'task',\n title: payload.base.title,\n status: payload.base.is_done ? 'done' : 'planned',\n priority: payload.base.priority ?? null,\n body: payload.base.description ?? null,\n scheduledAt: payload.base.scheduledAt ?? null,\n customValues: payload.custom,\n }\n await canonicalResult.createInteraction(interactionPayload)\n },\n [canonicalResult, entityId],\n )\n\n const canonicalUpdateTask = React.useCallback(\n async (task: TodoLinkSummary, payload: TaskFormPayload) => {\n await canonicalResult.updateInteraction(task.todoId, {\n title: payload.base.title,\n status: payload.base.is_done ? 'done' : 'planned',\n priority: payload.base.priority ?? null,\n body: payload.base.description ?? null,\n scheduledAt: payload.base.scheduledAt ?? null,\n customValues: payload.custom,\n })\n },\n [canonicalResult],\n )\n\n const canonicalToggleTask = React.useCallback(\n async (task: TodoLinkSummary, nextIsDone: boolean) => {\n if (nextIsDone) {\n await canonicalResult.completeInteraction(task.todoId)\n } else {\n // Reopen: set status back to planned via update\n await canonicalResult.updateInteraction(task.todoId, { status: 'planned' })\n }\n },\n [canonicalResult],\n )\n\n const canonicalUnlinkTask = React.useCallback(\n async (task: TodoLinkSummary) => {\n await canonicalResult.deleteInteraction(task.todoId)\n },\n [canonicalResult],\n )\n\n // Unified interface: pick the active data source based on the flag\n const tasks = useCanonicalInteractions ? canonicalTasks : legacyResult.tasks\n const isInitialLoading = useCanonicalInteractions ? canonicalResult.isInitialLoading : legacyResult.isInitialLoading\n const isLoadingMore = useCanonicalInteractions ? canonicalResult.isLoadingMore : legacyResult.isLoadingMore\n const isMutating = useCanonicalInteractions ? canonicalResult.isMutating : legacyResult.isMutating\n const hasMore = useCanonicalInteractions ? canonicalResult.hasMore : legacyResult.hasMore\n const loadMore = useCanonicalInteractions ? canonicalResult.loadMore : legacyResult.loadMore\n const refresh = useCanonicalInteractions ? canonicalResult.refresh : legacyResult.refresh\n const createTask = useCanonicalInteractions ? canonicalCreateTask : legacyResult.createTask\n const updateTask = useCanonicalInteractions ? canonicalUpdateTask : legacyResult.updateTask\n const toggleTask = useCanonicalInteractions ? canonicalToggleTask : legacyResult.toggleTask\n const unlinkTask = useCanonicalInteractions ? canonicalUnlinkTask : legacyResult.unlinkTask\n const pendingTaskId = useCanonicalInteractions ? canonicalResult.pendingId : legacyResult.pendingTaskId\n const error = useCanonicalInteractions ? canonicalResult.error : legacyResult.error\n const sortedTasks = React.useMemo(() => sortTaskSummaries(tasks), [tasks])\n\n const [dialogOpen, setDialogOpen] = React.useState(false)\n const [dialogMode, setDialogMode] = React.useState<'create' | 'edit'>('create')\n const [editingTask, setEditingTask] = React.useState<TodoLinkSummary | null>(null)\n const sentinelRef = React.useRef<HTMLDivElement | null>(null)\n\n const dialogContextMessage = React.useMemo(() => {\n if (!dialogContextKey || !entityName) return undefined\n return t(dialogContextKey, dialogContextFallback ?? 'This task will be linked to {{name}}', { name: entityName })\n }, [dialogContextFallback, dialogContextKey, entityName, t])\n\n const openCreateDialog = React.useCallback(() => {\n setEditingTask(null)\n setDialogMode('create')\n setDialogOpen(true)\n }, [])\n\n const openEditDialog = React.useCallback((task: TodoLinkSummary) => {\n setEditingTask(task)\n setDialogMode('edit')\n setDialogOpen(true)\n }, [])\n\n const closeDialog = React.useCallback(() => {\n setDialogOpen(false)\n setEditingTask(null)\n }, [])\n\n React.useEffect(() => {\n if (!onActionChange) return\n if (!entityId) {\n onActionChange(null)\n return\n }\n onActionChange({\n label: addActionLabel,\n onClick: openCreateDialog,\n disabled: isMutating,\n })\n return () => {\n onActionChange(null)\n }\n }, [addActionLabel, entityId, isMutating, onActionChange, openCreateDialog])\n\n React.useEffect(() => {\n if (!onLoadingChange) return\n onLoadingChange(isInitialLoading || isMutating)\n }, [isInitialLoading, isMutating, onLoadingChange])\n\n React.useEffect(() => {\n if (!hasMore) return\n if (typeof IntersectionObserver === 'undefined') return\n const el = sentinelRef.current\n if (!el) return\n\n const observer = new IntersectionObserver(\n (entries) => {\n if (entries.some((entry) => entry.isIntersecting)) {\n loadMore().catch(() => {})\n }\n },\n { rootMargin: '200px 0px 200px 0px' },\n )\n observer.observe(el)\n return () => {\n observer.disconnect()\n }\n }, [hasMore, loadMore])\n\n const handleCreate = React.useCallback(\n async (payload: TaskFormPayload) => {\n try {\n await runWriteMutation(\n () => createTask(payload),\n {\n entityId,\n title: payload.base.title,\n isDone: payload.base.is_done ?? undefined,\n },\n )\n flash(t('customers.people.detail.tasks.createSuccess', 'Task created'), 'success')\n await Promise.resolve(onDataRefresh?.())\n } catch (err) {\n const message = err instanceof Error ? err.message : t('customers.people.detail.tasks.error', 'Failed to create task')\n flash(message, 'error')\n throw err\n }\n },\n [createTask, entityId, onDataRefresh, runWriteMutation, t],\n )\n\n const handleUpdate = React.useCallback(\n async (task: TodoLinkSummary, payload: TaskFormPayload) => {\n try {\n await runWriteMutation(\n () => updateTask(task, payload),\n {\n id: task.id,\n todoId: task.todoId,\n title: payload.base.title,\n isDone: payload.base.is_done ?? undefined,\n },\n )\n flash(t('customers.people.detail.tasks.updateSuccess', 'Task updated'), 'success')\n await Promise.resolve(onDataRefresh?.())\n } catch (err) {\n const message =\n err instanceof Error ? err.message : t('customers.people.detail.tasks.updateError', 'Failed to update task')\n flash(message, 'error')\n throw err\n }\n },\n [onDataRefresh, runWriteMutation, t, updateTask],\n )\n\n const handleToggle = React.useCallback(\n async (task: TodoLinkSummary, nextIsDone: boolean) => {\n try {\n await runWriteMutation(\n () => toggleTask(task, nextIsDone),\n {\n id: task.id,\n todoId: task.todoId,\n isDone: nextIsDone,\n },\n )\n flash(\n nextIsDone\n ? t('customers.people.detail.tasks.completeSuccess', 'Task marked as done')\n : t('customers.people.detail.tasks.reopenSuccess', 'Task reopened'),\n 'success',\n )\n await Promise.resolve(onDataRefresh?.())\n } catch (err) {\n const message =\n err instanceof Error ? err.message : t('customers.people.detail.tasks.toggleError', 'Failed to update task status')\n flash(message, 'error')\n }\n },\n [onDataRefresh, runWriteMutation, t, toggleTask],\n )\n\n const handleDelete = React.useCallback(\n async (task: TodoLinkSummary) => {\n try {\n await runWriteMutation(\n () => unlinkTask(task),\n {\n id: task.id,\n todoId: task.todoId,\n },\n )\n flash(t('customers.people.detail.tasks.deleteSuccess', 'Task removed'), 'success')\n await Promise.resolve(onDataRefresh?.())\n await refresh()\n } catch (err) {\n const message =\n err instanceof Error ? err.message : t('customers.people.detail.tasks.deleteError', 'Failed to remove task')\n flash(message, 'error')\n }\n },\n [onDataRefresh, refresh, runWriteMutation, t, unlinkTask],\n )\n\n const handleCancel = React.useCallback(\n async (task: TodoLinkSummary) => {\n if (!useCanonicalInteractions) return\n try {\n await runWriteMutation(\n () => canonicalResult.cancelInteraction(task.todoId),\n { id: task.todoId },\n )\n flash(t('customers.people.detail.tasks.cancelSuccess', 'Task canceled'), 'success')\n await Promise.resolve(onDataRefresh?.())\n } catch (err) {\n const message =\n err instanceof Error ? err.message : t('customers.people.detail.tasks.cancelError', 'Failed to cancel task')\n flash(message, 'error')\n }\n },\n [canonicalResult, onDataRefresh, runWriteMutation, t, useCanonicalInteractions],\n )\n\n const renderTaskMeta = React.useCallback(\n (task: TodoLinkSummary) => {\n const meta: string[] = []\n if (task.status === 'canceled') {\n meta.push(t('customers.people.detail.tasks.status.canceled', 'Canceled'))\n }\n if (typeof task.priority === 'number') {\n meta.push(t('customers.people.detail.tasks.priorityLabel', 'Priority {{priority}}', { priority: task.priority }))\n }\n if (task.severity) {\n meta.push(\n t(\n `customers.people.detail.tasks.severity.${task.severity}`,\n task.severity.charAt(0).toUpperCase() + task.severity.slice(1),\n ),\n )\n }\n if (task.dueAt) {\n const dueLabel =\n formatDate(task.dueAt) ??\n formatDateTime(task.dueAt) ??\n t('customers.people.detail.tasks.dueLabel', 'Due {{date}}', { date: task.dueAt })\n meta.push(t('customers.people.detail.tasks.dueLabel', 'Due {{date}}', { date: dueLabel }))\n }\n return meta\n },\n [t],\n )\n\n const handleDialogSubmit = React.useCallback(\n async (payload: TaskFormPayload) => {\n if (dialogMode === 'edit' && editingTask) {\n await handleUpdate(editingTask, payload)\n } else {\n await handleCreate(payload)\n }\n },\n [dialogMode, editingTask, handleCreate, handleUpdate],\n )\n\n const hasTasks = sortedTasks.length > 0\n\n return (\n <div className=\"mt-0 space-y-6\">\n <div className=\"space-y-4\">\n {isInitialLoading ? (\n <LoadingMessage\n label={t('customers.people.detail.tasks.loading', 'Loading tasks\u2026')}\n className=\"border-0 bg-transparent p-0 py-8 justify-center\"\n />\n ) : null}\n\n {!isInitialLoading && !hasTasks ? (\n <TabEmptyState title={emptyState.title}>\n <Button asChild variant=\"outline\" size=\"sm\" className=\"mt-2\">\n <Link href=\"/backend/customer-tasks\">\n {t('customers.people.detail.tasks.viewAll', 'View all tasks')}\n </Link>\n </Button>\n </TabEmptyState>\n ) : null}\n\n {!isInitialLoading && hasTasks ? (\n <div className=\"space-y-4\">\n {error ? (\n <div className=\"rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-sm text-destructive\">\n {error}\n </div>\n ) : null}\n {sortedTasks.map((task) => {\n const todoHref = task.externalHref ?? resolveTodoHref(task.todoSource, task.todoId)\n const createdLabel = formatDateTime(task.createdAt) ?? emptyLabel\n const meta = renderTaskMeta(task)\n const title = task.title ?? t('customers.people.detail.tasks.untitled', 'Untitled task')\n const isDone = task.isDone === true\n const isCanceled = task.status === 'canceled'\n const checkboxId = `person-task-${task.id}`\n const isPendingToggle = pendingTaskId === task.todoId\n return (\n <article key={task.id} className=\"group space-y-3 rounded-lg border bg-card p-4 transition hover:border-border/70\">\n <div className=\"flex flex-wrap items-start justify-between gap-3\">\n <TimelineItemHeader\n title={\n <span className=\"inline-flex items-center gap-2\">\n <input\n id={checkboxId}\n type=\"checkbox\"\n checked={isDone}\n onChange={(event) => {\n const next = event.target.checked\n void handleToggle(task, next)\n }}\n disabled={isMutating || isPendingToggle || isCanceled}\n className=\"h-4 w-4 rounded border\"\n />\n <span\n className={cn(\n 'text-sm font-semibold',\n isDone ? 'line-through text-muted-foreground' : undefined,\n isCanceled ? 'text-muted-foreground' : undefined,\n )}\n >\n {title}\n </span>\n </span>\n }\n timestamp={task.createdAt}\n fallbackTimestampLabel={createdLabel}\n />\n <div className=\"flex items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100 focus-within:opacity-100\">\n <IconButton\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n onClick={() => openEditDialog(task)}\n disabled={isMutating}\n aria-label={t('ui.actions.edit', 'Edit')}\n >\n {isMutating && editingTask?.id === task.id && dialogMode === 'edit' ? (\n <Loader2 className=\"h-4 w-4 animate-spin\" />\n ) : (\n <Pencil className=\"h-4 w-4\" />\n )}\n </IconButton>\n <IconButton\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n onClick={() => handleDelete(task)}\n disabled={isMutating}\n aria-label={t('ui.actions.delete', 'Delete')}\n >\n {isMutating ? <Loader2 className=\"h-4 w-4 animate-spin text-destructive\" /> : <Trash2 className=\"h-4 w-4\" />}\n </IconButton>\n </div>\n </div>\n {meta.length ? (\n <div className=\"flex flex-wrap items-center gap-3 text-xs text-muted-foreground\">\n {meta.map((entry) => (\n <span key={`${task.id}-${entry}`} className=\"rounded bg-muted px-2 py-1 text-xs font-medium text-muted-foreground\">\n {entry}\n </span>\n ))}\n </div>\n ) : null}\n {task.description ? (\n <p className=\"text-sm text-muted-foreground whitespace-pre-wrap\">{task.description}</p>\n ) : null}\n <div className=\"flex flex-wrap items-center gap-3 text-xs\">\n {useCanonicalInteractions && !isDone && !isCanceled ? (\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n className=\"h-auto px-0 text-xs font-medium text-muted-foreground hover:bg-transparent hover:text-foreground\"\n onClick={() => void handleCancel(task)}\n disabled={isMutating || isPendingToggle}\n >\n {t('customers.people.detail.tasks.cancelAction', 'Cancel task')}\n </Button>\n ) : null}\n {todoHref ? (\n <Link href={todoHref} className=\"text-primary hover:underline\">\n {t('customers.people.detail.tasks.openTask', 'Open task')}\n </Link>\n ) : null}\n </div>\n </article>\n )\n })}\n <div ref={sentinelRef} />\n {hasMore ? (\n <div className=\"flex justify-center\">\n <Button type=\"button\" variant=\"outline\" size=\"sm\" onClick={() => loadMore().catch(() => {})} disabled={isLoadingMore}>\n {isLoadingMore ? (\n <>\n <Loader2 className=\"mr-2 h-4 w-4 animate-spin\" />\n {t('customers.people.detail.tasks.loadingMore', 'Loading\u2026')}\n </>\n ) : (\n t('customers.people.detail.tasks.loadMore', 'Load more')\n )}\n </Button>\n </div>\n ) : null}\n {isLoadingMore ? (\n <div className=\"flex justify-center text-xs text-muted-foreground\">\n <Loader2 className=\"mr-2 h-3 w-3 animate-spin\" />\n {t('customers.people.detail.tasks.loadingMore', 'Loading\u2026')}\n </div>\n ) : null}\n </div>\n ) : null}\n {!isInitialLoading && hasTasks ? (\n <div className=\"flex justify-center\">\n <Button asChild variant=\"outline\" size=\"sm\">\n <Link href=\"/backend/customer-tasks\">\n {t('customers.people.detail.tasks.viewAll', 'View all tasks')}\n </Link>\n </Button>\n </div>\n ) : null}\n </div>\n\n <TaskDialog\n open={dialogOpen}\n mode={dialogMode}\n onOpenChange={(next) => {\n if (!next) closeDialog()\n else setDialogOpen(true)\n }}\n initialValues={buildInitialFormValues(editingTask)}\n onSubmit={handleDialogSubmit}\n isSubmitting={isMutating}\n contextMessage={dialogContextMessage}\n />\n </div>\n )\n}\n\nexport default TasksSection\n"],
5
- "mappings": ";AA0aU,SAiIU,UAjIV,KAqCc,YArCd;AAxaV,YAAY,WAAW;AACvB,OAAO,UAAU;AACjB,SAAS,SAAS,QAAQ,cAAc;AACxC,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AACtB,SAAS,gBAAgB,qBAAqB;AAC9C,SAAS,UAAU;AACnB,SAAS,YAAY;AAEr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I,KAAK,aAAa;AAAA,QACtB,UACC,oBAAC,SAAI,WAAU,uBACb,8BAAC,UAAO,MAAK,UAAS,SAAQ,WAAU,MAAK,MAAK,SAAS,MAAM,SAAS,EAAE,MAAM,MAAM;AAAA,QAAC,CAAC,GAAG,UAAU,eACpG,0BACC,iCACE;AAAA,8BAAC,WAAQ,WAAU,6BAA4B;AAAA,UAC9C,EAAE,6CAA6C,eAAU;AAAA,WAC5D,IAEA,EAAE,0CAA0C,WAAW,GAE3D,GACF,IACE;AAAA,QACH,gBACC,qBAAC,SAAI,WAAU,qDACb;AAAA,8BAAC,WAAQ,WAAU,6BAA4B;AAAA,UAC9C,EAAE,6CAA6C,eAAU;AAAA,WAC5D,IACE;AAAA,SACN,IACE;AAAA,MACH,CAAC,oBAAoB,WACpB,oBAAC,SAAI,WAAU,uBACb,8BAAC,UAAO,SAAO,MAAC,SAAQ,WAAU,MAAK,MACrC,8BAAC,QAAK,MAAK,2BACR,YAAE,yCAAyC,gBAAgB,GAC9D,GACF,GACF,IACE;AAAA,OACN;AAAA,IAEA;AAAA,MAAC;AAAA;AAAA,QACC,MAAM;AAAA,QACN,MAAM;AAAA,QACN,cAAc,CAAC,SAAS;AACtB,cAAI,CAAC,KAAM,aAAY;AAAA,cAClB,eAAc,IAAI;AAAA,QACzB;AAAA,QACA,eAAe,uBAAuB,WAAW;AAAA,QACjD,UAAU;AAAA,QACV,cAAc;AAAA,QACd,gBAAgB;AAAA;AAAA,IAClB;AAAA,KACF;AAEJ;AAEA,IAAO,uBAAQ;",
4
+ "sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport Link from 'next/link'\nimport { Loader2, Pencil, Trash2 } from 'lucide-react'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { IconButton } from '@open-mercato/ui/primitives/icon-button'\nimport { StatusBadge, type StatusBadgeVariant } from '@open-mercato/ui/primitives/status-badge'\nimport { mapDictionaryColorToTone } from '@open-mercato/shared/lib/query/advanced-filter'\nimport { useOrganizationScopeVersion } from '@open-mercato/shared/lib/frontend/useOrganizationScope'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { LoadingMessage, TabEmptyState } from '@open-mercato/ui/backend/detail'\nimport { cn } from '@open-mercato/shared/lib/utils'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport type { InteractionSummary, SectionAction, TabEmptyStateConfig, TodoLinkSummary, Translator } from './types'\nimport { createTranslatorWithFallback } from '@open-mercato/shared/lib/i18n/translate'\nimport { formatDate, resolveTodoHref } from './utils'\nimport { formatDateTime } from '@open-mercato/shared/lib/time'\nimport { TimelineItemHeader } from './TimelineItemHeader'\nimport { TaskDialog } from './TaskDialog'\nimport { usePersonTasks, type TaskFormPayload } from './hooks/usePersonTasks'\nimport { useCustomerDictionary } from './hooks/useCustomerDictionary'\nimport { useInteractions, type InteractionCreatePayload } from './hooks/useInteractions'\nimport { mapInteractionRecordToTodoSummary } from '../../lib/interactionCompatibility'\n\ntype GuardedMutationRunner = <T>(\n operation: () => Promise<T>,\n mutationPayload?: Record<string, unknown>,\n) => Promise<T>\n\ntype TasksSectionProps = {\n entityId: string | null\n initialTasks: TodoLinkSummary[]\n emptyLabel: string\n addActionLabel: string\n emptyState: TabEmptyStateConfig\n onActionChange?: (action: SectionAction | null) => void\n onLoadingChange?: (isLoading: boolean) => void\n onDataRefresh?: () => void\n translator?: Translator\n entityName?: string | null\n dialogContextKey?: string\n dialogContextFallback?: string\n /** When true, use the canonical interactions API instead of the legacy todos API. */\n useCanonicalInteractions?: boolean\n runGuardedMutation?: GuardedMutationRunner\n}\n\nconst RESERVED_TASK_CUSTOM_KEYS = new Set(['priority', 'description', 'due_at', 'dueAt'])\n\nfunction toTimestamp(value: string | null | undefined): number | null {\n if (!value) return null\n const timestamp = new Date(value).getTime()\n return Number.isNaN(timestamp) ? null : timestamp\n}\n\nfunction sortTaskSummaries(tasks: TodoLinkSummary[]): TodoLinkSummary[] {\n return [...tasks].sort((left, right) => {\n const leftDue = toTimestamp(left.dueAt)\n const rightDue = toTimestamp(right.dueAt)\n if (leftDue !== null || rightDue !== null) {\n if (leftDue === null) return 1\n if (rightDue === null) return -1\n if (leftDue !== rightDue) return leftDue - rightDue\n }\n const leftCreated = toTimestamp(left.createdAt) ?? 0\n const rightCreated = toTimestamp(right.createdAt) ?? 0\n if (leftCreated !== rightCreated) return rightCreated - leftCreated\n return left.id.localeCompare(right.id)\n })\n}\n\nconst STATUS_BADGE_VARIANTS = new Set<StatusBadgeVariant>(['success', 'warning', 'error', 'info', 'neutral'])\n\nfunction coerceStatusBadgeVariant(tone: ReturnType<typeof mapDictionaryColorToTone>): StatusBadgeVariant {\n return tone && STATUS_BADGE_VARIANTS.has(tone as StatusBadgeVariant) ? (tone as StatusBadgeVariant) : 'neutral'\n}\n\nfunction buildInitialFormValues(task: TodoLinkSummary | null): Record<string, unknown> | undefined {\n if (!task) return undefined\n const values: Record<string, unknown> = {\n title: task.title ?? '',\n is_done: task.isDone ?? false,\n status: task.status ?? 'planned',\n description: task.description ?? '',\n priority: task.priority ?? '',\n scheduledAt: task.dueAt ?? '',\n }\n if (task.customValues) {\n for (const [key, value] of Object.entries(task.customValues)) {\n if (RESERVED_TASK_CUSTOM_KEYS.has(key)) continue\n const formKey = `cf_${key}`\n if (values[formKey] === undefined) values[formKey] = value\n }\n }\n return values\n}\n\nexport function TasksSection({\n entityId,\n initialTasks,\n emptyLabel,\n addActionLabel,\n emptyState,\n onActionChange,\n onLoadingChange,\n onDataRefresh,\n translator,\n entityName,\n dialogContextKey,\n dialogContextFallback,\n useCanonicalInteractions = false,\n runGuardedMutation,\n}: TasksSectionProps) {\n const tHook = useT()\n const fallbackTranslator = React.useMemo<Translator>(() => createTranslatorWithFallback(tHook), [tHook])\n const t: Translator = React.useMemo(() => translator ?? fallbackTranslator, [translator, fallbackTranslator])\n const runWriteMutation = React.useCallback(\n async <T,>(operation: () => Promise<T>, mutationPayload?: Record<string, unknown>): Promise<T> => {\n if (!runGuardedMutation) {\n return operation()\n }\n return runGuardedMutation(operation, mutationPayload)\n },\n [runGuardedMutation],\n )\n\n const scopeVersion = useOrganizationScopeVersion()\n const statusDictionary = useCustomerDictionary('interaction-statuses', scopeVersion)\n const statusMap = statusDictionary.data?.map ?? null\n\n // Legacy path: usePersonTasks (default)\n const legacyResult = usePersonTasks({ entityId, initialTasks })\n\n // Canonical path: useInteractions with planned-status filter\n const canonicalResult = useInteractions({\n entityId: useCanonicalInteractions ? entityId : null,\n typeFilter: 'task',\n })\n\n // Map canonical interactions to the TodoLinkSummary shape used by the rendering below\n const canonicalTasks = React.useMemo<TodoLinkSummary[]>(\n () => (useCanonicalInteractions ? canonicalResult.interactions.map(mapInteractionRecordToTodoSummary) : []),\n [useCanonicalInteractions, canonicalResult.interactions],\n )\n\n const canonicalCreateTask = React.useCallback(\n async (payload: TaskFormPayload) => {\n if (!entityId) throw new Error('Task creation requires an entity id')\n const interactionPayload: InteractionCreatePayload = {\n entityId,\n interactionType: 'task',\n title: payload.base.title,\n status: payload.base.status ?? (payload.base.is_done ? 'done' : 'planned'),\n priority: payload.base.priority ?? null,\n body: payload.base.description ?? null,\n scheduledAt: payload.base.scheduledAt ?? null,\n customValues: payload.custom,\n }\n await canonicalResult.createInteraction(interactionPayload)\n },\n [canonicalResult, entityId],\n )\n\n const canonicalUpdateTask = React.useCallback(\n async (task: TodoLinkSummary, payload: TaskFormPayload) => {\n await canonicalResult.updateInteraction(task.todoId, {\n title: payload.base.title,\n status: payload.base.status ?? (payload.base.is_done ? 'done' : 'planned'),\n priority: payload.base.priority ?? null,\n body: payload.base.description ?? null,\n scheduledAt: payload.base.scheduledAt ?? null,\n customValues: payload.custom,\n })\n },\n [canonicalResult],\n )\n\n const canonicalToggleTask = React.useCallback(\n async (task: TodoLinkSummary, nextIsDone: boolean) => {\n if (nextIsDone) {\n await canonicalResult.completeInteraction(task.todoId)\n } else {\n // Reopen: set status back to planned via update\n await canonicalResult.updateInteraction(task.todoId, { status: 'planned' })\n }\n },\n [canonicalResult],\n )\n\n const canonicalUnlinkTask = React.useCallback(\n async (task: TodoLinkSummary) => {\n await canonicalResult.deleteInteraction(task.todoId)\n },\n [canonicalResult],\n )\n\n // Unified interface: pick the active data source based on the flag\n const tasks = useCanonicalInteractions ? canonicalTasks : legacyResult.tasks\n const isInitialLoading = useCanonicalInteractions ? canonicalResult.isInitialLoading : legacyResult.isInitialLoading\n const isLoadingMore = useCanonicalInteractions ? canonicalResult.isLoadingMore : legacyResult.isLoadingMore\n const isMutating = useCanonicalInteractions ? canonicalResult.isMutating : legacyResult.isMutating\n const hasMore = useCanonicalInteractions ? canonicalResult.hasMore : legacyResult.hasMore\n const loadMore = useCanonicalInteractions ? canonicalResult.loadMore : legacyResult.loadMore\n const refresh = useCanonicalInteractions ? canonicalResult.refresh : legacyResult.refresh\n const createTask = useCanonicalInteractions ? canonicalCreateTask : legacyResult.createTask\n const updateTask = useCanonicalInteractions ? canonicalUpdateTask : legacyResult.updateTask\n const toggleTask = useCanonicalInteractions ? canonicalToggleTask : legacyResult.toggleTask\n const unlinkTask = useCanonicalInteractions ? canonicalUnlinkTask : legacyResult.unlinkTask\n const pendingTaskId = useCanonicalInteractions ? canonicalResult.pendingId : legacyResult.pendingTaskId\n const error = useCanonicalInteractions ? canonicalResult.error : legacyResult.error\n const sortedTasks = React.useMemo(() => sortTaskSummaries(tasks), [tasks])\n\n const [dialogOpen, setDialogOpen] = React.useState(false)\n const [dialogMode, setDialogMode] = React.useState<'create' | 'edit'>('create')\n const [editingTask, setEditingTask] = React.useState<TodoLinkSummary | null>(null)\n const sentinelRef = React.useRef<HTMLDivElement | null>(null)\n\n const dialogContextMessage = React.useMemo(() => {\n if (!dialogContextKey || !entityName) return undefined\n return t(dialogContextKey, dialogContextFallback ?? 'This task will be linked to {{name}}', { name: entityName })\n }, [dialogContextFallback, dialogContextKey, entityName, t])\n\n const openCreateDialog = React.useCallback(() => {\n setEditingTask(null)\n setDialogMode('create')\n setDialogOpen(true)\n }, [])\n\n const openEditDialog = React.useCallback((task: TodoLinkSummary) => {\n setEditingTask(task)\n setDialogMode('edit')\n setDialogOpen(true)\n }, [])\n\n const closeDialog = React.useCallback(() => {\n setDialogOpen(false)\n setEditingTask(null)\n }, [])\n\n React.useEffect(() => {\n if (!onActionChange) return\n if (!entityId) {\n onActionChange(null)\n return\n }\n onActionChange({\n label: addActionLabel,\n onClick: openCreateDialog,\n disabled: isMutating,\n })\n return () => {\n onActionChange(null)\n }\n }, [addActionLabel, entityId, isMutating, onActionChange, openCreateDialog])\n\n React.useEffect(() => {\n if (!onLoadingChange) return\n onLoadingChange(isInitialLoading || isMutating)\n }, [isInitialLoading, isMutating, onLoadingChange])\n\n React.useEffect(() => {\n if (!hasMore) return\n if (typeof IntersectionObserver === 'undefined') return\n const el = sentinelRef.current\n if (!el) return\n\n const observer = new IntersectionObserver(\n (entries) => {\n if (entries.some((entry) => entry.isIntersecting)) {\n loadMore().catch(() => {})\n }\n },\n { rootMargin: '200px 0px 200px 0px' },\n )\n observer.observe(el)\n return () => {\n observer.disconnect()\n }\n }, [hasMore, loadMore])\n\n const handleCreate = React.useCallback(\n async (payload: TaskFormPayload) => {\n try {\n await runWriteMutation(\n () => createTask(payload),\n {\n entityId,\n title: payload.base.title,\n isDone: payload.base.is_done ?? undefined,\n },\n )\n flash(t('customers.people.detail.tasks.createSuccess', 'Task created'), 'success')\n await Promise.resolve(onDataRefresh?.())\n } catch (err) {\n const message = err instanceof Error ? err.message : t('customers.people.detail.tasks.error', 'Failed to create task')\n flash(message, 'error')\n throw err\n }\n },\n [createTask, entityId, onDataRefresh, runWriteMutation, t],\n )\n\n const handleUpdate = React.useCallback(\n async (task: TodoLinkSummary, payload: TaskFormPayload) => {\n try {\n await runWriteMutation(\n () => updateTask(task, payload),\n {\n id: task.id,\n todoId: task.todoId,\n title: payload.base.title,\n isDone: payload.base.is_done ?? undefined,\n },\n )\n flash(t('customers.people.detail.tasks.updateSuccess', 'Task updated'), 'success')\n await Promise.resolve(onDataRefresh?.())\n } catch (err) {\n const message =\n err instanceof Error ? err.message : t('customers.people.detail.tasks.updateError', 'Failed to update task')\n flash(message, 'error')\n throw err\n }\n },\n [onDataRefresh, runWriteMutation, t, updateTask],\n )\n\n const handleToggle = React.useCallback(\n async (task: TodoLinkSummary, nextIsDone: boolean) => {\n try {\n await runWriteMutation(\n () => toggleTask(task, nextIsDone),\n {\n id: task.id,\n todoId: task.todoId,\n isDone: nextIsDone,\n },\n )\n flash(\n nextIsDone\n ? t('customers.people.detail.tasks.completeSuccess', 'Task marked as done')\n : t('customers.people.detail.tasks.reopenSuccess', 'Task reopened'),\n 'success',\n )\n await Promise.resolve(onDataRefresh?.())\n } catch (err) {\n const message =\n err instanceof Error ? err.message : t('customers.people.detail.tasks.toggleError', 'Failed to update task status')\n flash(message, 'error')\n }\n },\n [onDataRefresh, runWriteMutation, t, toggleTask],\n )\n\n const handleDelete = React.useCallback(\n async (task: TodoLinkSummary) => {\n try {\n await runWriteMutation(\n () => unlinkTask(task),\n {\n id: task.id,\n todoId: task.todoId,\n },\n )\n flash(t('customers.people.detail.tasks.deleteSuccess', 'Task removed'), 'success')\n await Promise.resolve(onDataRefresh?.())\n await refresh()\n } catch (err) {\n const message =\n err instanceof Error ? err.message : t('customers.people.detail.tasks.deleteError', 'Failed to remove task')\n flash(message, 'error')\n }\n },\n [onDataRefresh, refresh, runWriteMutation, t, unlinkTask],\n )\n\n const handleCancel = React.useCallback(\n async (task: TodoLinkSummary) => {\n if (!useCanonicalInteractions) return\n try {\n await runWriteMutation(\n () => canonicalResult.cancelInteraction(task.todoId),\n { id: task.todoId },\n )\n flash(t('customers.people.detail.tasks.cancelSuccess', 'Task canceled'), 'success')\n await Promise.resolve(onDataRefresh?.())\n } catch (err) {\n const message =\n err instanceof Error ? err.message : t('customers.people.detail.tasks.cancelError', 'Failed to cancel task')\n flash(message, 'error')\n }\n },\n [canonicalResult, onDataRefresh, runWriteMutation, t, useCanonicalInteractions],\n )\n\n const renderTaskMeta = React.useCallback(\n (task: TodoLinkSummary) => {\n const meta: string[] = []\n if (task.status === 'canceled') {\n meta.push(t('customers.people.detail.tasks.status.canceled', 'Canceled'))\n }\n if (typeof task.priority === 'number') {\n meta.push(t('customers.people.detail.tasks.priorityLabel', 'Priority {{priority}}', { priority: task.priority }))\n }\n if (task.severity) {\n meta.push(\n t(\n `customers.people.detail.tasks.severity.${task.severity}`,\n task.severity.charAt(0).toUpperCase() + task.severity.slice(1),\n ),\n )\n }\n if (task.dueAt) {\n const dueLabel =\n formatDate(task.dueAt) ??\n formatDateTime(task.dueAt) ??\n t('customers.people.detail.tasks.dueLabel', 'Due {{date}}', { date: task.dueAt })\n meta.push(t('customers.people.detail.tasks.dueLabel', 'Due {{date}}', { date: dueLabel }))\n }\n return meta\n },\n [t],\n )\n\n const handleDialogSubmit = React.useCallback(\n async (payload: TaskFormPayload) => {\n if (dialogMode === 'edit' && editingTask) {\n await handleUpdate(editingTask, payload)\n } else {\n await handleCreate(payload)\n }\n },\n [dialogMode, editingTask, handleCreate, handleUpdate],\n )\n\n const hasTasks = sortedTasks.length > 0\n\n return (\n <div className=\"mt-0 space-y-6\">\n <div className=\"space-y-4\">\n {isInitialLoading ? (\n <LoadingMessage\n label={t('customers.people.detail.tasks.loading', 'Loading tasks\u2026')}\n className=\"border-0 bg-transparent p-0 py-8 justify-center\"\n />\n ) : null}\n\n {!isInitialLoading && !hasTasks ? (\n <TabEmptyState title={emptyState.title}>\n <Button asChild variant=\"outline\" size=\"sm\" className=\"mt-2\">\n <Link href=\"/backend/customer-tasks\">\n {t('customers.people.detail.tasks.viewAll', 'View all tasks')}\n </Link>\n </Button>\n </TabEmptyState>\n ) : null}\n\n {!isInitialLoading && hasTasks ? (\n <div className=\"space-y-4\">\n {error ? (\n <div className=\"rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-sm text-destructive\">\n {error}\n </div>\n ) : null}\n {sortedTasks.map((task) => {\n const todoHref = task.externalHref ?? resolveTodoHref(task.todoSource, task.todoId)\n const createdLabel = formatDateTime(task.createdAt) ?? emptyLabel\n const meta = renderTaskMeta(task)\n const title = task.title ?? t('customers.people.detail.tasks.untitled', 'Untitled task')\n const isDone = task.isDone === true\n const isCanceled = task.status === 'canceled'\n const checkboxId = `person-task-${task.id}`\n const isPendingToggle = pendingTaskId === task.todoId\n return (\n <article key={task.id} className=\"group space-y-3 rounded-lg border bg-card p-4 transition hover:border-border/70\">\n <div className=\"flex flex-wrap items-start justify-between gap-3\">\n <TimelineItemHeader\n title={\n <span className=\"inline-flex items-center gap-2\">\n <input\n id={checkboxId}\n type=\"checkbox\"\n checked={isDone}\n onChange={(event) => {\n const next = event.target.checked\n void handleToggle(task, next)\n }}\n disabled={isMutating || isPendingToggle || isCanceled}\n className=\"h-4 w-4 rounded border\"\n />\n <span\n className={cn(\n 'text-sm font-semibold',\n isDone ? 'line-through text-muted-foreground' : undefined,\n isCanceled ? 'text-muted-foreground' : undefined,\n )}\n >\n {title}\n </span>\n {task.status ? (\n <StatusBadge\n variant={coerceStatusBadgeVariant(\n mapDictionaryColorToTone(statusMap?.[task.status]?.color ?? null),\n )}\n dot\n >\n {statusMap?.[task.status]?.label ?? task.status}\n </StatusBadge>\n ) : null}\n </span>\n }\n timestamp={task.createdAt}\n fallbackTimestampLabel={createdLabel}\n />\n <div className=\"flex items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100 focus-within:opacity-100\">\n <IconButton\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n onClick={() => openEditDialog(task)}\n disabled={isMutating}\n aria-label={t('ui.actions.edit', 'Edit')}\n >\n {isMutating && editingTask?.id === task.id && dialogMode === 'edit' ? (\n <Loader2 className=\"h-4 w-4 animate-spin\" />\n ) : (\n <Pencil className=\"h-4 w-4\" />\n )}\n </IconButton>\n <IconButton\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n onClick={() => handleDelete(task)}\n disabled={isMutating}\n aria-label={t('ui.actions.delete', 'Delete')}\n >\n {isMutating ? <Loader2 className=\"h-4 w-4 animate-spin text-destructive\" /> : <Trash2 className=\"h-4 w-4\" />}\n </IconButton>\n </div>\n </div>\n {meta.length ? (\n <div className=\"flex flex-wrap items-center gap-3 text-xs text-muted-foreground\">\n {meta.map((entry) => (\n <span key={`${task.id}-${entry}`} className=\"rounded bg-muted px-2 py-1 text-xs font-medium text-muted-foreground\">\n {entry}\n </span>\n ))}\n </div>\n ) : null}\n {task.description ? (\n <p className=\"text-sm text-muted-foreground whitespace-pre-wrap\">{task.description}</p>\n ) : null}\n <div className=\"flex flex-wrap items-center gap-3 text-xs\">\n {useCanonicalInteractions && !isDone && !isCanceled ? (\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n className=\"h-auto px-0 text-xs font-medium text-muted-foreground hover:bg-transparent hover:text-foreground\"\n onClick={() => void handleCancel(task)}\n disabled={isMutating || isPendingToggle}\n >\n {t('customers.people.detail.tasks.cancelAction', 'Cancel task')}\n </Button>\n ) : null}\n {todoHref ? (\n <Link href={todoHref} className=\"text-primary hover:underline\">\n {t('customers.people.detail.tasks.openTask', 'Open task')}\n </Link>\n ) : null}\n </div>\n </article>\n )\n })}\n <div ref={sentinelRef} />\n {hasMore ? (\n <div className=\"flex justify-center\">\n <Button type=\"button\" variant=\"outline\" size=\"sm\" onClick={() => loadMore().catch(() => {})} disabled={isLoadingMore}>\n {isLoadingMore ? (\n <>\n <Loader2 className=\"mr-2 h-4 w-4 animate-spin\" />\n {t('customers.people.detail.tasks.loadingMore', 'Loading\u2026')}\n </>\n ) : (\n t('customers.people.detail.tasks.loadMore', 'Load more')\n )}\n </Button>\n </div>\n ) : null}\n {isLoadingMore ? (\n <div className=\"flex justify-center text-xs text-muted-foreground\">\n <Loader2 className=\"mr-2 h-3 w-3 animate-spin\" />\n {t('customers.people.detail.tasks.loadingMore', 'Loading\u2026')}\n </div>\n ) : null}\n </div>\n ) : null}\n {!isInitialLoading && hasTasks ? (\n <div className=\"flex justify-center\">\n <Button asChild variant=\"outline\" size=\"sm\">\n <Link href=\"/backend/customer-tasks\">\n {t('customers.people.detail.tasks.viewAll', 'View all tasks')}\n </Link>\n </Button>\n </div>\n ) : null}\n </div>\n\n <TaskDialog\n open={dialogOpen}\n mode={dialogMode}\n onOpenChange={(next) => {\n if (!next) closeDialog()\n else setDialogOpen(true)\n }}\n initialValues={buildInitialFormValues(editingTask)}\n onSubmit={handleDialogSubmit}\n isSubmitting={isMutating}\n contextMessage={dialogContextMessage}\n useCanonicalInteractions={useCanonicalInteractions}\n />\n </div>\n )\n}\n\nexport default TasksSection\n"],
5
+ "mappings": ";AAybU,SA2IU,UA3IV,KAqCc,YArCd;AAvbV,YAAY,WAAW;AACvB,OAAO,UAAU;AACjB,SAAS,SAAS,QAAQ,cAAc;AACxC,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,mBAA4C;AACrD,SAAS,gCAAgC;AACzC,SAAS,mCAAmC;AAC5C,SAAS,aAAa;AACtB,SAAS,gBAAgB,qBAAqB;AAC9C,SAAS,UAAU;AACnB,SAAS,YAAY;AAErB,SAAS,oCAAoC;AAC7C,SAAS,YAAY,uBAAuB;AAC5C,SAAS,sBAAsB;AAC/B,SAAS,0BAA0B;AACnC,SAAS,kBAAkB;AAC3B,SAAS,sBAA4C;AACrD,SAAS,6BAA6B;AACtC,SAAS,uBAAsD;AAC/D,SAAS,yCAAyC;AAyBlD,MAAM,4BAA4B,oBAAI,IAAI,CAAC,YAAY,eAAe,UAAU,OAAO,CAAC;AAExF,SAAS,YAAY,OAAiD;AACpE,MAAI,CAAC,MAAO,QAAO;AACnB,QAAM,YAAY,IAAI,KAAK,KAAK,EAAE,QAAQ;AAC1C,SAAO,OAAO,MAAM,SAAS,IAAI,OAAO;AAC1C;AAEA,SAAS,kBAAkB,OAA6C;AACtE,SAAO,CAAC,GAAG,KAAK,EAAE,KAAK,CAAC,MAAM,UAAU;AACtC,UAAM,UAAU,YAAY,KAAK,KAAK;AACtC,UAAM,WAAW,YAAY,MAAM,KAAK;AACx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AAC,SAAI,KAAK,aAAa;AAAA,QACtB,UACC,oBAAC,SAAI,WAAU,uBACb,8BAAC,UAAO,MAAK,UAAS,SAAQ,WAAU,MAAK,MAAK,SAAS,MAAM,SAAS,EAAE,MAAM,MAAM;AAAA,QAAC,CAAC,GAAG,UAAU,eACpG,0BACC,iCACE;AAAA,8BAAC,WAAQ,WAAU,6BAA4B;AAAA,UAC9C,EAAE,6CAA6C,eAAU;AAAA,WAC5D,IAEA,EAAE,0CAA0C,WAAW,GAE3D,GACF,IACE;AAAA,QACH,gBACC,qBAAC,SAAI,WAAU,qDACb;AAAA,8BAAC,WAAQ,WAAU,6BAA4B;AAAA,UAC9C,EAAE,6CAA6C,eAAU;AAAA,WAC5D,IACE;AAAA,SACN,IACE;AAAA,MACH,CAAC,oBAAoB,WACpB,oBAAC,SAAI,WAAU,uBACb,8BAAC,UAAO,SAAO,MAAC,SAAQ,WAAU,MAAK,MACrC,8BAAC,QAAK,MAAK,2BACR,YAAE,yCAAyC,gBAAgB,GAC9D,GACF,GACF,IACE;AAAA,OACN;AAAA,IAEA;AAAA,MAAC;AAAA;AAAA,QACC,MAAM;AAAA,QACN,MAAM;AAAA,QACN,cAAc,CAAC,SAAS;AACtB,cAAI,CAAC,KAAM,aAAY;AAAA,cAClB,eAAc,IAAI;AAAA,QACzB;AAAA,QACA,eAAe,uBAAuB,WAAW;AAAA,QACjD,UAAU;AAAA,QACV,cAAc;AAAA,QACd,gBAAgB;AAAA,QAChB;AAAA;AAAA,IACF;AAAA,KACF;AAEJ;AAEA,IAAO,uBAAQ;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/modules/customers/components/detail/hooks/usePersonTasks.ts"],
4
- "sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport { apiCallOrThrow, readApiResultOrThrow, withScopedApiRequestHeaders } from '@open-mercato/ui/backend/utils/apiCall'\nimport { buildOptimisticLockHeader } from '@open-mercato/ui/backend/utils/optimisticLock'\nimport { resolveTodoApiPath } from '../utils'\nimport type { TodoLinkSummary } from '../types'\nimport { generateTempId } from '@open-mercato/core/modules/customers/lib/detailHelpers'\nimport { parseBooleanToken } from '@open-mercato/shared/lib/boolean'\nimport { CUSTOMER_INTERACTION_TASK_SOURCE } from '../../../lib/interactionCompatibility'\n\nconst DEFAULT_TODO_SOURCE = CUSTOMER_INTERACTION_TASK_SOURCE\n\ntype CustomerTodoRow = {\n id: string\n todoId: string\n todoSource: string\n todoTitle: string | null\n todoIsDone: boolean | null\n todoPriority: number | null\n todoSeverity: string | null\n todoDescription: string | null\n todoDueAt: string | null\n todoCustomValues: Record<string, unknown> | null\n todoOrganizationId: string | null\n todoUpdatedAt?: string | null\n organizationId: string\n tenantId: string\n createdAt: string\n}\n\ntype CustomerTodosResponse = {\n items: CustomerTodoRow[]\n total: number\n page: number\n pageSize: number\n totalPages: number\n}\n\nexport type TaskFormPayload = {\n base: {\n title: string\n is_done?: boolean\n description?: string | null\n priority?: number | null\n scheduledAt?: string | null\n }\n custom: Record<string, unknown>\n}\n\nexport type UsePersonTasksOptions = {\n entityId: string | null\n initialTasks?: TodoLinkSummary[]\n pageSize?: number\n}\n\nexport type UsePersonTasksResult = {\n tasks: TodoLinkSummary[]\n isInitialLoading: boolean\n isLoadingMore: boolean\n isMutating: boolean\n hasMore: boolean\n loadMore: () => Promise<void>\n refresh: () => Promise<void>\n createTask: (payload: TaskFormPayload) => Promise<void>\n updateTask: (task: TodoLinkSummary, payload: TaskFormPayload) => Promise<void>\n toggleTask: (task: TodoLinkSummary, nextIsDone: boolean) => Promise<void>\n unlinkTask: (task: TodoLinkSummary) => Promise<void>\n pendingTaskId: string | null\n totalCount: number\n error: string | null\n}\n\nfunction mapRowToSummary(row: CustomerTodoRow): TodoLinkSummary {\n return {\n id: row.id,\n todoId: row.todoId,\n todoSource: row.todoSource || DEFAULT_TODO_SOURCE,\n createdAt: row.createdAt,\n title: row.todoTitle ?? null,\n isDone: row.todoIsDone ?? null,\n status: row.todoIsDone ? 'done' : 'planned',\n priority: row.todoPriority ?? null,\n severity: row.todoSeverity ?? null,\n description: row.todoDescription ?? null,\n dueAt: row.todoDueAt ?? null,\n todoOrganizationId: row.todoOrganizationId ?? null,\n updatedAt: row.todoUpdatedAt ?? null,\n customValues: row.todoCustomValues ?? null,\n }\n}\n\nfunction mergeUnique(existing: TodoLinkSummary[], incoming: TodoLinkSummary[]): TodoLinkSummary[] {\n if (!existing.length) return incoming\n if (!incoming.length) return existing\n const byId = new Map<string, TodoLinkSummary>()\n const result: TodoLinkSummary[] = []\n for (const item of existing) {\n byId.set(item.id, item)\n result.push(item)\n }\n for (const item of incoming) {\n if (byId.has(item.id)) {\n const index = result.findIndex((entry) => entry.id === item.id)\n if (index !== -1) result[index] = item\n } else {\n byId.set(item.id, item)\n result.push(item)\n }\n }\n return result\n}\n\nfunction normalizeBoolean(value: unknown): boolean | undefined {\n if (value === null || value === undefined) return undefined\n if (typeof value === 'boolean') return value\n if (typeof value === 'string') {\n const parsed = parseBooleanToken(value)\n return parsed === null ? undefined : parsed\n }\n return undefined\n}\n\nfunction normalizeNumber(value: unknown): number | null | undefined {\n if (value === null || value === undefined || value === '') return undefined\n if (typeof value === 'number' && Number.isFinite(value)) return value\n if (typeof value === 'string') {\n const trimmed = value.trim()\n if (!trimmed.length) return undefined\n const parsed = Number(trimmed)\n if (!Number.isNaN(parsed)) return parsed\n }\n return null\n}\n\nfunction normalizeString(value: unknown): string | null | undefined {\n if (value === null || value === undefined) return undefined\n if (typeof value === 'string') {\n const trimmed = value.trim()\n return trimmed.length ? trimmed : null\n }\n return String(value)\n}\n\nfunction buildLegacyTaskCustomValues(\n payload: TaskFormPayload,\n options?: { includeEmptyFields?: boolean },\n): Record<string, unknown> {\n const includeEmptyFields = options?.includeEmptyFields === true\n const custom = { ...payload.custom }\n\n const assignValue = (key: string, value: unknown) => {\n if (value === undefined) return\n if (value === null) {\n if (includeEmptyFields) custom[key] = null\n return\n }\n custom[key] = value\n }\n\n assignValue('priority', payload.base.priority ?? null)\n assignValue('description', payload.base.description ?? null)\n assignValue('due_at', payload.base.scheduledAt ?? null)\n\n return custom\n}\n\nexport function usePersonTasks({\n entityId,\n initialTasks = [],\n pageSize = 20,\n}: UsePersonTasksOptions): UsePersonTasksResult {\n const [tasks, setTasks] = React.useState<TodoLinkSummary[]>(initialTasks)\n const [pageInfo, setPageInfo] = React.useState<{ page: number; totalPages: number; total: number }>({\n page: 1,\n totalPages: 1,\n total: initialTasks.length,\n })\n const [isInitialLoading, setIsInitialLoading] = React.useState<boolean>(() => Boolean(entityId))\n const [isLoadingMore, setIsLoadingMore] = React.useState(false)\n const [isMutating, setIsMutating] = React.useState(false)\n const [pendingTaskId, setPendingTaskId] = React.useState<string | null>(null)\n const [error, setError] = React.useState<string | null>(null)\n\n const mapResponse = React.useCallback((payload: CustomerTodosResponse) => {\n const mapped = Array.isArray(payload.items) ? payload.items.map(mapRowToSummary) : []\n setPageInfo({\n page: payload.page ?? 1,\n totalPages: payload.totalPages ?? 0,\n total: payload.total ?? mapped.length,\n })\n setError(null)\n return mapped\n }, [])\n\n const fetchPage = React.useCallback(\n async (page: number): Promise<CustomerTodosResponse> => {\n if (!entityId) {\n return {\n items: [],\n total: 0,\n page: 1,\n pageSize,\n totalPages: 1,\n }\n }\n const params = new URLSearchParams({\n page: String(page),\n pageSize: String(pageSize),\n entityId,\n })\n return readApiResultOrThrow<CustomerTodosResponse>(\n `/api/customers/todos?${params.toString()}`,\n undefined,\n { errorMessage: 'Failed to load tasks.' },\n )\n },\n [entityId, pageSize],\n )\n\n const refresh = React.useCallback(async () => {\n if (!entityId) {\n setTasks([])\n setPageInfo({ page: 1, totalPages: 1, total: 0 })\n return\n }\n setIsInitialLoading(true)\n try {\n const payload = await fetchPage(1)\n const mapped = mapResponse(payload)\n setTasks(mapped)\n } catch (err) {\n const message = err instanceof Error ? err.message : 'Failed to load tasks.'\n setError(message)\n throw err\n } finally {\n setIsInitialLoading(false)\n }\n }, [entityId, fetchPage, mapResponse])\n\n const loadMore = React.useCallback(async () => {\n if (!entityId) return\n if (isLoadingMore) return\n if (pageInfo.page >= pageInfo.totalPages) return\n setIsLoadingMore(true)\n try {\n const payload = await fetchPage(pageInfo.page + 1)\n const mapped = mapResponse(payload)\n setTasks((prev) => mergeUnique(prev, mapped))\n } catch (err) {\n const message = err instanceof Error ? err.message : 'Failed to load tasks.'\n setError(message)\n throw err\n } finally {\n setIsLoadingMore(false)\n }\n }, [entityId, fetchPage, isLoadingMore, mapResponse, pageInfo.page, pageInfo.totalPages])\n\n React.useEffect(() => {\n if (!entityId) {\n setTasks([])\n setPageInfo({ page: 1, totalPages: 1, total: 0 })\n setError(null)\n setIsInitialLoading(false)\n return\n }\n setTasks(initialTasks)\n setPageInfo({\n page: 1,\n totalPages: 1,\n total: initialTasks.length,\n })\n setError(null)\n let cancelled = false\n setIsInitialLoading(true)\n fetchPage(1)\n .then((payload) => {\n if (cancelled) return\n const mapped = mapResponse(payload)\n setTasks(mapped)\n })\n .catch((err) => {\n if (cancelled) return\n const message = err instanceof Error ? err.message : 'Failed to load tasks.'\n setError(message)\n })\n .finally(() => {\n if (!cancelled) setIsInitialLoading(false)\n })\n return () => {\n cancelled = true\n }\n }, [entityId, initialTasks, fetchPage, mapResponse])\n\n const createTask = React.useCallback(\n async ({ base, custom }: TaskFormPayload) => {\n if (!entityId) throw new Error('Task creation requires an entity id')\n setIsMutating(true)\n try {\n const customValues = buildLegacyTaskCustomValues({ base, custom })\n const payload: Record<string, unknown> = {\n entityId,\n title: base.title,\n }\n const normalizedDone = normalizeBoolean(base.is_done)\n if (normalizedDone !== undefined) payload.isDone = normalizedDone\n if (Object.keys(customValues).length) payload.todoCustom = customValues\n\n const response = await apiCallOrThrow<{ linkId?: string; todoId?: string }>(\n '/api/customers/todos',\n {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(payload),\n },\n { errorMessage: 'Failed to create task.' },\n )\n const body = response.result ?? {}\n const linkId = typeof body.linkId === 'string' && body.linkId.length ? body.linkId : generateTempId()\n const todoId = typeof body.todoId === 'string' && body.todoId.length ? body.todoId : generateTempId()\n const createdAt = new Date().toISOString()\n const persistedCustomValues = Object.keys(customValues).length ? { ...customValues } : null\n const priority = normalizeNumber(base.priority ?? customValues.priority)\n const severity = normalizeString(customValues.severity) ?? null\n const description = normalizeString(base.description ?? customValues.description) ?? null\n const newTask: TodoLinkSummary = {\n id: linkId,\n todoId,\n todoSource: DEFAULT_TODO_SOURCE,\n createdAt,\n title: base.title,\n isDone: normalizedDone ?? false,\n status: normalizedDone ? 'done' : 'planned',\n priority: priority === undefined ? null : priority,\n severity,\n description,\n dueAt: normalizeString(base.scheduledAt ?? customValues.due_at) ?? normalizeString(customValues.dueAt) ?? null,\n todoOrganizationId: null,\n customValues: persistedCustomValues,\n }\n setTasks((prev) => [newTask, ...prev])\n setPageInfo((prev) => ({\n page: 1,\n totalPages: prev.totalPages,\n total: prev.total + 1,\n }))\n await refresh()\n } finally {\n setIsMutating(false)\n }\n },\n [entityId, refresh],\n )\n\n const updateTask = React.useCallback(\n async (task: TodoLinkSummary, { base, custom }: TaskFormPayload) => {\n if (!task.todoId) throw new Error('Task is missing todo id')\n const apiPath = resolveTodoApiPath(task.todoSource || DEFAULT_TODO_SOURCE)\n if (!apiPath) throw new Error('Unsupported task source')\n setIsMutating(true)\n try {\n const customValues = buildLegacyTaskCustomValues({ base, custom }, { includeEmptyFields: true })\n const body: Record<string, unknown> = {\n id: task.todoId,\n linkId: task.id,\n }\n if (typeof base.title === 'string' && base.title.trim().length) {\n body.title = base.title.trim()\n }\n const normalizedDone = normalizeBoolean(base.is_done)\n if (normalizedDone !== undefined) body.is_done = normalizedDone\n if (Object.keys(customValues).length) {\n body.customFields = customValues\n }\n // Send the optimistic-lock header (task's loaded updatedAt) so a stale\n // edit \u2014 or an edit after the task was deleted in another tab \u2014 surfaces\n // the unified conflict bar (409) instead of silently overwriting or\n // returning a bare \"Interaction not found\" 404 (#2055).\n await withScopedApiRequestHeaders(\n buildOptimisticLockHeader(task.updatedAt ?? null),\n () => apiCallOrThrow(\n apiPath,\n {\n method: 'PUT',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(body),\n },\n { errorMessage: 'Failed to update task.' },\n ),\n )\n setTasks((prev) =>\n prev.map((item) => {\n if (item.id !== task.id) return item\n const nextCustomValues = { ...(item.customValues ?? {}) }\n for (const [key, value] of Object.entries(customValues)) {\n nextCustomValues[key] = value === undefined ? null : value\n }\n return {\n ...item,\n title: typeof base.title === 'string' && base.title.trim().length ? base.title.trim() : item.title,\n isDone: normalizedDone !== undefined ? normalizedDone : item.isDone,\n status: normalizedDone !== undefined ? (normalizedDone ? 'done' : 'planned') : item.status ?? null,\n priority:\n normalizeNumber(base.priority ?? customValues.priority) ??\n (base.priority === undefined && customValues.priority === undefined ? item.priority ?? null : null),\n severity:\n normalizeString(customValues.severity) ??\n (customValues.severity === undefined ? item.severity ?? null : null),\n description:\n normalizeString(base.description ?? customValues.description) ??\n (base.description === undefined && customValues.description === undefined ? item.description ?? null : null),\n dueAt:\n normalizeString(base.scheduledAt ?? customValues.due_at) ??\n normalizeString(customValues.dueAt) ??\n (base.scheduledAt === undefined && customValues.due_at === undefined && customValues.dueAt === undefined\n ? item.dueAt ?? null\n : null),\n customValues: Object.keys(nextCustomValues).length ? nextCustomValues : null,\n }\n }),\n )\n } finally {\n setIsMutating(false)\n }\n },\n [],\n )\n\n const toggleTask = React.useCallback(\n async (task: TodoLinkSummary, nextIsDone: boolean) => {\n if (!task.todoId) {\n throw new Error('Task is missing todo id')\n }\n const apiPath = resolveTodoApiPath(task.todoSource || DEFAULT_TODO_SOURCE)\n if (!apiPath) {\n throw new Error('Unsupported task source')\n }\n setPendingTaskId(task.todoId)\n try {\n await updateTask(task, { base: { title: task.title ?? '', is_done: nextIsDone }, custom: {} })\n } finally {\n setPendingTaskId(null)\n }\n },\n [updateTask],\n )\n\n const unlinkTask = React.useCallback(\n async (task: TodoLinkSummary) => {\n if (!task.id) throw new Error('Task link id missing')\n setIsMutating(true)\n try {\n await withScopedApiRequestHeaders(\n buildOptimisticLockHeader(task.updatedAt ?? null),\n () => apiCallOrThrow(\n '/api/customers/todos',\n {\n method: 'DELETE',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({ id: task.id }),\n },\n { errorMessage: 'Failed to remove task.' },\n ),\n )\n setTasks((prev) => prev.filter((item) => item.id !== task.id))\n setPageInfo((prev) => ({\n page: prev.page,\n totalPages: prev.totalPages,\n total: Math.max(0, prev.total - 1),\n }))\n } finally {\n setIsMutating(false)\n }\n },\n [],\n )\n\n const hasMore = entityId != null && pageInfo.page < pageInfo.totalPages\n\n return {\n tasks,\n isInitialLoading,\n isLoadingMore,\n isMutating,\n hasMore,\n loadMore,\n refresh,\n createTask,\n updateTask,\n toggleTask,\n unlinkTask,\n pendingTaskId,\n totalCount: pageInfo.total,\n error,\n }\n}\n"],
5
- "mappings": ";AAEA,YAAY,WAAW;AACvB,SAAS,gBAAgB,sBAAsB,mCAAmC;AAClF,SAAS,iCAAiC;AAC1C,SAAS,0BAA0B;AAEnC,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAClC,SAAS,wCAAwC;AAEjD,MAAM,sBAAsB;AA8D5B,SAAS,gBAAgB,KAAuC;AAC9D,SAAO;AAAA,IACL,IAAI,IAAI;AAAA,IACR,QAAQ,IAAI;AAAA,IACZ,YAAY,IAAI,cAAc;AAAA,IAC9B,WAAW,IAAI;AAAA,IACf,OAAO,IAAI,aAAa;AAAA,IACxB,QAAQ,IAAI,cAAc;AAAA,IAC1B,QAAQ,IAAI,aAAa,SAAS;AAAA,IAClC,UAAU,IAAI,gBAAgB;AAAA,IAC9B,UAAU,IAAI,gBAAgB;AAAA,IAC9B,aAAa,IAAI,mBAAmB;AAAA,IACpC,OAAO,IAAI,aAAa;AAAA,IACxB,oBAAoB,IAAI,sBAAsB;AAAA,IAC9C,WAAW,IAAI,iBAA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CAAC;AAAA,QACnC,EAAE;AAAA,MACJ,UAAE;AACA,sBAAc,KAAK;AAAA,MACrB;AAAA,IACF;AAAA,IACA,CAAC;AAAA,EACH;AAEA,QAAM,UAAU,YAAY,QAAQ,SAAS,OAAO,SAAS;AAE7D,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY,SAAS;AAAA,IACrB;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport { apiCallOrThrow, readApiResultOrThrow, withScopedApiRequestHeaders } from '@open-mercato/ui/backend/utils/apiCall'\nimport { buildOptimisticLockHeader } from '@open-mercato/ui/backend/utils/optimisticLock'\nimport { resolveTodoApiPath } from '../utils'\nimport type { TodoLinkSummary } from '../types'\nimport { generateTempId } from '@open-mercato/core/modules/customers/lib/detailHelpers'\nimport { parseBooleanToken } from '@open-mercato/shared/lib/boolean'\nimport { CUSTOMER_INTERACTION_TASK_SOURCE } from '../../../lib/interactionCompatibility'\n\nconst DEFAULT_TODO_SOURCE = CUSTOMER_INTERACTION_TASK_SOURCE\n\ntype CustomerTodoRow = {\n id: string\n todoId: string\n todoSource: string\n todoTitle: string | null\n todoIsDone: boolean | null\n todoPriority: number | null\n todoSeverity: string | null\n todoDescription: string | null\n todoDueAt: string | null\n todoCustomValues: Record<string, unknown> | null\n todoOrganizationId: string | null\n todoUpdatedAt?: string | null\n organizationId: string\n tenantId: string\n createdAt: string\n}\n\ntype CustomerTodosResponse = {\n items: CustomerTodoRow[]\n total: number\n page: number\n pageSize: number\n totalPages: number\n}\n\nexport type TaskFormPayload = {\n base: {\n title: string\n is_done?: boolean\n status?: string\n description?: string | null\n priority?: number | null\n scheduledAt?: string | null\n }\n custom: Record<string, unknown>\n}\n\nexport type UsePersonTasksOptions = {\n entityId: string | null\n initialTasks?: TodoLinkSummary[]\n pageSize?: number\n}\n\nexport type UsePersonTasksResult = {\n tasks: TodoLinkSummary[]\n isInitialLoading: boolean\n isLoadingMore: boolean\n isMutating: boolean\n hasMore: boolean\n loadMore: () => Promise<void>\n refresh: () => Promise<void>\n createTask: (payload: TaskFormPayload) => Promise<void>\n updateTask: (task: TodoLinkSummary, payload: TaskFormPayload) => Promise<void>\n toggleTask: (task: TodoLinkSummary, nextIsDone: boolean) => Promise<void>\n unlinkTask: (task: TodoLinkSummary) => Promise<void>\n pendingTaskId: string | null\n totalCount: number\n error: string | null\n}\n\nfunction mapRowToSummary(row: CustomerTodoRow): TodoLinkSummary {\n return {\n id: row.id,\n todoId: row.todoId,\n todoSource: row.todoSource || DEFAULT_TODO_SOURCE,\n createdAt: row.createdAt,\n title: row.todoTitle ?? null,\n isDone: row.todoIsDone ?? null,\n status: row.todoIsDone ? 'done' : 'planned',\n priority: row.todoPriority ?? null,\n severity: row.todoSeverity ?? null,\n description: row.todoDescription ?? null,\n dueAt: row.todoDueAt ?? null,\n todoOrganizationId: row.todoOrganizationId ?? null,\n updatedAt: row.todoUpdatedAt ?? null,\n customValues: row.todoCustomValues ?? null,\n }\n}\n\nfunction mergeUnique(existing: TodoLinkSummary[], incoming: TodoLinkSummary[]): TodoLinkSummary[] {\n if (!existing.length) return incoming\n if (!incoming.length) return existing\n const byId = new Map<string, TodoLinkSummary>()\n const result: TodoLinkSummary[] = []\n for (const item of existing) {\n byId.set(item.id, item)\n result.push(item)\n }\n for (const item of incoming) {\n if (byId.has(item.id)) {\n const index = result.findIndex((entry) => entry.id === item.id)\n if (index !== -1) result[index] = item\n } else {\n byId.set(item.id, item)\n result.push(item)\n }\n }\n return result\n}\n\nfunction normalizeBoolean(value: unknown): boolean | undefined {\n if (value === null || value === undefined) return undefined\n if (typeof value === 'boolean') return value\n if (typeof value === 'string') {\n const parsed = parseBooleanToken(value)\n return parsed === null ? undefined : parsed\n }\n return undefined\n}\n\nfunction normalizeNumber(value: unknown): number | null | undefined {\n if (value === null || value === undefined || value === '') return undefined\n if (typeof value === 'number' && Number.isFinite(value)) return value\n if (typeof value === 'string') {\n const trimmed = value.trim()\n if (!trimmed.length) return undefined\n const parsed = Number(trimmed)\n if (!Number.isNaN(parsed)) return parsed\n }\n return null\n}\n\nfunction normalizeString(value: unknown): string | null | undefined {\n if (value === null || value === undefined) return undefined\n if (typeof value === 'string') {\n const trimmed = value.trim()\n return trimmed.length ? trimmed : null\n }\n return String(value)\n}\n\nfunction buildLegacyTaskCustomValues(\n payload: TaskFormPayload,\n options?: { includeEmptyFields?: boolean },\n): Record<string, unknown> {\n const includeEmptyFields = options?.includeEmptyFields === true\n const custom = { ...payload.custom }\n\n const assignValue = (key: string, value: unknown) => {\n if (value === undefined) return\n if (value === null) {\n if (includeEmptyFields) custom[key] = null\n return\n }\n custom[key] = value\n }\n\n assignValue('priority', payload.base.priority ?? null)\n assignValue('description', payload.base.description ?? null)\n assignValue('due_at', payload.base.scheduledAt ?? null)\n\n return custom\n}\n\nexport function usePersonTasks({\n entityId,\n initialTasks = [],\n pageSize = 20,\n}: UsePersonTasksOptions): UsePersonTasksResult {\n const [tasks, setTasks] = React.useState<TodoLinkSummary[]>(initialTasks)\n const [pageInfo, setPageInfo] = React.useState<{ page: number; totalPages: number; total: number }>({\n page: 1,\n totalPages: 1,\n total: initialTasks.length,\n })\n const [isInitialLoading, setIsInitialLoading] = React.useState<boolean>(() => Boolean(entityId))\n const [isLoadingMore, setIsLoadingMore] = React.useState(false)\n const [isMutating, setIsMutating] = React.useState(false)\n const [pendingTaskId, setPendingTaskId] = React.useState<string | null>(null)\n const [error, setError] = React.useState<string | null>(null)\n\n const mapResponse = React.useCallback((payload: CustomerTodosResponse) => {\n const mapped = Array.isArray(payload.items) ? payload.items.map(mapRowToSummary) : []\n setPageInfo({\n page: payload.page ?? 1,\n totalPages: payload.totalPages ?? 0,\n total: payload.total ?? mapped.length,\n })\n setError(null)\n return mapped\n }, [])\n\n const fetchPage = React.useCallback(\n async (page: number): Promise<CustomerTodosResponse> => {\n if (!entityId) {\n return {\n items: [],\n total: 0,\n page: 1,\n pageSize,\n totalPages: 1,\n }\n }\n const params = new URLSearchParams({\n page: String(page),\n pageSize: String(pageSize),\n entityId,\n })\n return readApiResultOrThrow<CustomerTodosResponse>(\n `/api/customers/todos?${params.toString()}`,\n undefined,\n { errorMessage: 'Failed to load tasks.' },\n )\n },\n [entityId, pageSize],\n )\n\n const refresh = React.useCallback(async () => {\n if (!entityId) {\n setTasks([])\n setPageInfo({ page: 1, totalPages: 1, total: 0 })\n return\n }\n setIsInitialLoading(true)\n try {\n const payload = await fetchPage(1)\n const mapped = mapResponse(payload)\n setTasks(mapped)\n } catch (err) {\n const message = err instanceof Error ? err.message : 'Failed to load tasks.'\n setError(message)\n throw err\n } finally {\n setIsInitialLoading(false)\n }\n }, [entityId, fetchPage, mapResponse])\n\n const loadMore = React.useCallback(async () => {\n if (!entityId) return\n if (isLoadingMore) return\n if (pageInfo.page >= pageInfo.totalPages) return\n setIsLoadingMore(true)\n try {\n const payload = await fetchPage(pageInfo.page + 1)\n const mapped = mapResponse(payload)\n setTasks((prev) => mergeUnique(prev, mapped))\n } catch (err) {\n const message = err instanceof Error ? err.message : 'Failed to load tasks.'\n setError(message)\n throw err\n } finally {\n setIsLoadingMore(false)\n }\n }, [entityId, fetchPage, isLoadingMore, mapResponse, pageInfo.page, pageInfo.totalPages])\n\n React.useEffect(() => {\n if (!entityId) {\n setTasks([])\n setPageInfo({ page: 1, totalPages: 1, total: 0 })\n setError(null)\n setIsInitialLoading(false)\n return\n }\n setTasks(initialTasks)\n setPageInfo({\n page: 1,\n totalPages: 1,\n total: initialTasks.length,\n })\n setError(null)\n let cancelled = false\n setIsInitialLoading(true)\n fetchPage(1)\n .then((payload) => {\n if (cancelled) return\n const mapped = mapResponse(payload)\n setTasks(mapped)\n })\n .catch((err) => {\n if (cancelled) return\n const message = err instanceof Error ? err.message : 'Failed to load tasks.'\n setError(message)\n })\n .finally(() => {\n if (!cancelled) setIsInitialLoading(false)\n })\n return () => {\n cancelled = true\n }\n }, [entityId, initialTasks, fetchPage, mapResponse])\n\n const createTask = React.useCallback(\n async ({ base, custom }: TaskFormPayload) => {\n if (!entityId) throw new Error('Task creation requires an entity id')\n setIsMutating(true)\n try {\n const customValues = buildLegacyTaskCustomValues({ base, custom })\n const payload: Record<string, unknown> = {\n entityId,\n title: base.title,\n }\n const normalizedDone = normalizeBoolean(base.is_done)\n if (normalizedDone !== undefined) payload.isDone = normalizedDone\n if (Object.keys(customValues).length) payload.todoCustom = customValues\n\n const response = await apiCallOrThrow<{ linkId?: string; todoId?: string }>(\n '/api/customers/todos',\n {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(payload),\n },\n { errorMessage: 'Failed to create task.' },\n )\n const body = response.result ?? {}\n const linkId = typeof body.linkId === 'string' && body.linkId.length ? body.linkId : generateTempId()\n const todoId = typeof body.todoId === 'string' && body.todoId.length ? body.todoId : generateTempId()\n const createdAt = new Date().toISOString()\n const persistedCustomValues = Object.keys(customValues).length ? { ...customValues } : null\n const priority = normalizeNumber(base.priority ?? customValues.priority)\n const severity = normalizeString(customValues.severity) ?? null\n const description = normalizeString(base.description ?? customValues.description) ?? null\n const newTask: TodoLinkSummary = {\n id: linkId,\n todoId,\n todoSource: DEFAULT_TODO_SOURCE,\n createdAt,\n title: base.title,\n isDone: normalizedDone ?? false,\n status: normalizedDone ? 'done' : 'planned',\n priority: priority === undefined ? null : priority,\n severity,\n description,\n dueAt: normalizeString(base.scheduledAt ?? customValues.due_at) ?? normalizeString(customValues.dueAt) ?? null,\n todoOrganizationId: null,\n customValues: persistedCustomValues,\n }\n setTasks((prev) => [newTask, ...prev])\n setPageInfo((prev) => ({\n page: 1,\n totalPages: prev.totalPages,\n total: prev.total + 1,\n }))\n await refresh()\n } finally {\n setIsMutating(false)\n }\n },\n [entityId, refresh],\n )\n\n const updateTask = React.useCallback(\n async (task: TodoLinkSummary, { base, custom }: TaskFormPayload) => {\n if (!task.todoId) throw new Error('Task is missing todo id')\n const apiPath = resolveTodoApiPath(task.todoSource || DEFAULT_TODO_SOURCE)\n if (!apiPath) throw new Error('Unsupported task source')\n setIsMutating(true)\n try {\n const customValues = buildLegacyTaskCustomValues({ base, custom }, { includeEmptyFields: true })\n const body: Record<string, unknown> = {\n id: task.todoId,\n linkId: task.id,\n }\n if (typeof base.title === 'string' && base.title.trim().length) {\n body.title = base.title.trim()\n }\n const normalizedDone = normalizeBoolean(base.is_done)\n if (normalizedDone !== undefined) body.is_done = normalizedDone\n if (Object.keys(customValues).length) {\n body.customFields = customValues\n }\n // Send the optimistic-lock header (task's loaded updatedAt) so a stale\n // edit \u2014 or an edit after the task was deleted in another tab \u2014 surfaces\n // the unified conflict bar (409) instead of silently overwriting or\n // returning a bare \"Interaction not found\" 404 (#2055).\n await withScopedApiRequestHeaders(\n buildOptimisticLockHeader(task.updatedAt ?? null),\n () => apiCallOrThrow(\n apiPath,\n {\n method: 'PUT',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(body),\n },\n { errorMessage: 'Failed to update task.' },\n ),\n )\n setTasks((prev) =>\n prev.map((item) => {\n if (item.id !== task.id) return item\n const nextCustomValues = { ...(item.customValues ?? {}) }\n for (const [key, value] of Object.entries(customValues)) {\n nextCustomValues[key] = value === undefined ? null : value\n }\n return {\n ...item,\n title: typeof base.title === 'string' && base.title.trim().length ? base.title.trim() : item.title,\n isDone: normalizedDone !== undefined ? normalizedDone : item.isDone,\n status: normalizedDone !== undefined ? (normalizedDone ? 'done' : 'planned') : item.status ?? null,\n priority:\n normalizeNumber(base.priority ?? customValues.priority) ??\n (base.priority === undefined && customValues.priority === undefined ? item.priority ?? null : null),\n severity:\n normalizeString(customValues.severity) ??\n (customValues.severity === undefined ? item.severity ?? null : null),\n description:\n normalizeString(base.description ?? customValues.description) ??\n (base.description === undefined && customValues.description === undefined ? item.description ?? null : null),\n dueAt:\n normalizeString(base.scheduledAt ?? customValues.due_at) ??\n normalizeString(customValues.dueAt) ??\n (base.scheduledAt === undefined && customValues.due_at === undefined && customValues.dueAt === undefined\n ? item.dueAt ?? null\n : null),\n customValues: Object.keys(nextCustomValues).length ? nextCustomValues : null,\n }\n }),\n )\n } finally {\n setIsMutating(false)\n }\n },\n [],\n )\n\n const toggleTask = React.useCallback(\n async (task: TodoLinkSummary, nextIsDone: boolean) => {\n if (!task.todoId) {\n throw new Error('Task is missing todo id')\n }\n const apiPath = resolveTodoApiPath(task.todoSource || DEFAULT_TODO_SOURCE)\n if (!apiPath) {\n throw new Error('Unsupported task source')\n }\n setPendingTaskId(task.todoId)\n try {\n await updateTask(task, { base: { title: task.title ?? '', is_done: nextIsDone }, custom: {} })\n } finally {\n setPendingTaskId(null)\n }\n },\n [updateTask],\n )\n\n const unlinkTask = React.useCallback(\n async (task: TodoLinkSummary) => {\n if (!task.id) throw new Error('Task link id missing')\n setIsMutating(true)\n try {\n await withScopedApiRequestHeaders(\n buildOptimisticLockHeader(task.updatedAt ?? null),\n () => apiCallOrThrow(\n '/api/customers/todos',\n {\n method: 'DELETE',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({ id: task.id }),\n },\n { errorMessage: 'Failed to remove task.' },\n ),\n )\n setTasks((prev) => prev.filter((item) => item.id !== task.id))\n setPageInfo((prev) => ({\n page: prev.page,\n totalPages: prev.totalPages,\n total: Math.max(0, prev.total - 1),\n }))\n } finally {\n setIsMutating(false)\n }\n },\n [],\n )\n\n const hasMore = entityId != null && pageInfo.page < pageInfo.totalPages\n\n return {\n tasks,\n isInitialLoading,\n isLoadingMore,\n isMutating,\n hasMore,\n loadMore,\n refresh,\n createTask,\n updateTask,\n toggleTask,\n unlinkTask,\n pendingTaskId,\n totalCount: pageInfo.total,\n error,\n }\n}\n"],
5
+ "mappings": ";AAEA,YAAY,WAAW;AACvB,SAAS,gBAAgB,sBAAsB,mCAAmC;AAClF,SAAS,iCAAiC;AAC1C,SAAS,0BAA0B;AAEnC,SAAS,sBA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ACpD,oBAAc,IAAI;AACpB,UAAI;AACF,cAAM;AAAA,UACJ,0BAA0B,KAAK,aAAa,IAAI;AAAA,UAChD,MAAM;AAAA,YACJ;AAAA,YACA;AAAA,cACE,QAAQ;AAAA,cACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,cAC9C,MAAM,KAAK,UAAU,EAAE,IAAI,KAAK,GAAG,CAAC;AAAA,YACtC;AAAA,YACA,EAAE,cAAc,yBAAyB;AAAA,UAC3C;AAAA,QACF;AACE,iBAAS,CAAC,SAAS,KAAK,OAAO,CAAC,SAAS,KAAK,OAAO,KAAK,EAAE,CAAC;AAC7D,oBAAY,CAAC,UAAU;AAAA,UACrB,MAAM,KAAK;AAAA,UACX,YAAY,KAAK;AAAA,UACjB,OAAO,KAAK,IAAI,GAAG,KAAK,QAAQ,CAAC;AAAA,QACnC,EAAE;AAAA,MACJ,UAAE;AACA,sBAAc,KAAK;AAAA,MACrB;AAAA,IACF;AAAA,IACA,CAAC;AAAA,EACH;AAEA,QAAM,UAAU,YAAY,QAAQ,SAAS,OAAO,SAAS;AAE7D,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY,SAAS;AAAA,IACrB;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,8 +1,8 @@
1
1
  import { resolveKyselyClient } from "../lib/kysely.js";
2
2
  import { fetchStuckThresholdDays } from "../lib/stuckDeals.js";
3
+ import { TERMINAL_INTERACTION_STATUS_LIST } from "../lib/interactionStatus.js";
3
4
  const ENRICHER_TIMEOUT_MS = 2e3;
4
5
  const DAY_MS = 24 * 60 * 60 * 1e3;
5
- const TERMINAL_INTERACTION_STATUSES = ["done", "canceled", "completed"];
6
6
  function parseDate(value) {
7
7
  if (!value) return null;
8
8
  if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : value;
@@ -23,7 +23,7 @@ function stringArrayOrNull(value) {
23
23
  async function fetchOpenInteractionCounts(db, dealIds, organizationId, tenantId) {
24
24
  const map = /* @__PURE__ */ new Map();
25
25
  if (dealIds.size === 0) return map;
26
- const rows = await db.selectFrom("customer_interactions").select(["deal_id"]).select((eb) => eb.fn.countAll().as("count")).where("deal_id", "in", [...dealIds]).where("organization_id", "=", organizationId).where("tenant_id", "=", tenantId).where("deleted_at", "is", null).where("status", "not in", [...TERMINAL_INTERACTION_STATUSES]).groupBy("deal_id").execute();
26
+ const rows = await db.selectFrom("customer_interactions").select(["deal_id"]).select((eb) => eb.fn.countAll().as("count")).where("deal_id", "in", [...dealIds]).where("organization_id", "=", organizationId).where("tenant_id", "=", tenantId).where("deleted_at", "is", null).where("status", "not in", [...TERMINAL_INTERACTION_STATUS_LIST]).groupBy("deal_id").execute();
27
27
  for (const row of rows) {
28
28
  if (row.deal_id == null) continue;
29
29
  const count = typeof row.count === "number" ? row.count : Number(row.count);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/modules/customers/data/enrichers.ts"],
4
- "sourcesContent": ["import type { ResponseEnricher, EnricherContext } from '@open-mercato/shared/lib/crud/response-enricher'\nimport type { CustomerKysely } from '../lib/kysely'\nimport { resolveKyselyClient } from '../lib/kysely'\nimport { fetchStuckThresholdDays } from '../lib/stuckDeals'\n\ntype DealRecord = Record<string, unknown> & {\n id: string\n status?: string | null\n expected_close_at?: string | null\n created_at?: string | null\n}\n\ntype PipelineState = {\n openActivitiesCount: number\n daysInCurrentStage: number\n isStuck: boolean\n isOverdue: boolean\n}\n\nconst ENRICHER_TIMEOUT_MS = 2000\nconst DAY_MS = 24 * 60 * 60 * 1000\n// Mirror the canonical statuses defined in validators.ts (`interactionStatusValues`). The\n// canonical spelling is `canceled` (US, single L), not `cancelled` (UK). Misspelling this\n// here let canceled interactions slip into the open-activities count badge on the card.\n// We accept `completed` defensively too, even though `done` is the canonical \"completed\"\n// value in the validator, in case any legacy rows exist with the longer spelling.\nconst TERMINAL_INTERACTION_STATUSES = ['done', 'canceled', 'completed'] as const\n\nfunction parseDate(value: unknown): Date | null {\n if (!value) return null\n if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : value\n if (typeof value === 'string') {\n const date = new Date(value)\n return Number.isNaN(date.getTime()) ? null : date\n }\n return null\n}\n\nfunction diffDays(from: Date, to: Date): number {\n return Math.floor((to.getTime() - from.getTime()) / DAY_MS)\n}\n\n/** Coerce an unknown value to a non-empty string array, or null when absent/empty. */\nfunction stringArrayOrNull(value: unknown): string[] | null {\n if (!Array.isArray(value)) return null\n const strings = value.filter((entry): entry is string => typeof entry === 'string')\n return strings.length > 0 ? strings : null\n}\n\nasync function fetchOpenInteractionCounts(\n db: CustomerKysely,\n dealIds: Set<string>,\n organizationId: string,\n tenantId: string,\n): Promise<Map<string, number>> {\n const map = new Map<string, number>()\n if (dealIds.size === 0) return map\n const rows = await db\n .selectFrom('customer_interactions')\n .select(['deal_id'])\n .select((eb) => eb.fn.countAll().as('count'))\n .where('deal_id', 'in', [...dealIds])\n .where('organization_id', '=', organizationId)\n .where('tenant_id', '=', tenantId)\n .where('deleted_at', 'is', null)\n .where('status', 'not in', [...TERMINAL_INTERACTION_STATUSES])\n .groupBy('deal_id')\n .execute()\n for (const row of rows) {\n if (row.deal_id == null) continue\n const count = typeof row.count === 'number' ? row.count : Number(row.count)\n if (Number.isFinite(count)) map.set(row.deal_id, count)\n }\n return map\n}\n\nasync function fetchLatestStageTransitions(\n db: CustomerKysely,\n dealIds: Set<string>,\n organizationId: string,\n tenantId: string,\n): Promise<Map<string, Date>> {\n const map = new Map<string, Date>()\n if (dealIds.size === 0) return map\n const rows = await db\n .selectFrom('customer_deal_stage_transitions')\n .select(['deal_id'])\n .select((eb) => eb.fn.max('transitioned_at').as('last_transitioned_at'))\n .where('deal_id', 'in', [...dealIds])\n .where('organization_id', '=', organizationId)\n .where('tenant_id', '=', tenantId)\n .where('deleted_at', 'is', null)\n .groupBy('deal_id')\n .execute()\n for (const row of rows) {\n const parsed = parseDate(row.last_transitioned_at)\n if (parsed) map.set(row.deal_id, parsed)\n }\n return map\n}\n\nexport function buildPipelineState(\n record: DealRecord,\n openInteractionCounts: Map<string, number>,\n latestTransitions: Map<string, Date>,\n threshold: number,\n now: Date,\n today: Date,\n): PipelineState {\n const openActivitiesCount = openInteractionCounts.get(record.id) ?? 0\n const transitionAt =\n latestTransitions.get(record.id) ?? parseDate(record.created_at) ?? now\n const daysInCurrentStage = Math.max(0, diffDays(transitionAt, now))\n const expectedClose = parseDate(record.expected_close_at)\n const status = typeof record.status === 'string' ? record.status : null\n const isOverdue = status === 'open' && !!expectedClose && expectedClose < today\n const isStuck = daysInCurrentStage > threshold\n return { openActivitiesCount, daysInCurrentStage, isStuck, isOverdue }\n}\n\nconst dealPipelineEnricher: ResponseEnricher<DealRecord> = {\n id: 'customers.deal-pipeline-state',\n targetEntity: 'customers.deal',\n // No `features` gate: the deals list route already enforces `customers.deals.view`\n // at the route-metadata level (see api/deals/route.ts). Declaring `features` here\n // would silently disable the enricher in environments where `rbacService` resolves\n // to undefined or `getGrantedFeatures` throws \u2014 `hasRequiredFeatures` treats a\n // missing `userFeatures` as \"no access\", which made `_pipeline` disappear from\n // CI responses (TC-CRM-066) while keeping the local kanban working.\n priority: 10,\n timeout: ENRICHER_TIMEOUT_MS,\n critical: false,\n fallback: {\n _pipeline: {\n openActivitiesCount: 0,\n daysInCurrentStage: 0,\n isStuck: false,\n isOverdue: false,\n },\n },\n\n async enrichOne(record, context) {\n const enriched = await this.enrichMany!([record], context)\n return enriched[0]\n },\n\n async enrichMany(records, context: EnricherContext) {\n if (records.length === 0) return records\n\n const now = new Date()\n const today = new Date(now.getFullYear(), now.getMonth(), now.getDate())\n\n // `buildPipelineState` is pure on top of (record + maps + threshold). The record alone\n // is enough to compute `isOverdue` (status + expected_close_at) and a conservative\n // `daysInCurrentStage` (created_at fallback). When Kysely isn't available on this\n // EntityManager \u2014 test stubs, unusual driver wrappers, or a transient DB issue \u2014\n // we still ship the correct overdue flag and a zeroed activities count rather than\n // silently dropping `_pipeline`, which previously made the kanban think every deal\n // had no stuck/overdue state.\n const emptyCounts: Map<string, number> = new Map()\n const emptyTransitions: Map<string, Date> = new Map()\n const FALLBACK_THRESHOLD = 14\n\n const db = resolveKyselyClient(context.em)\n if (!db) {\n return records.map((record) => ({\n ...record,\n _pipeline: buildPipelineState(\n record,\n emptyCounts,\n emptyTransitions,\n FALLBACK_THRESHOLD,\n now,\n today,\n ),\n }))\n }\n\n const dealIds = new Set<string>()\n for (const record of records) {\n if (typeof record.id === 'string') dealIds.add(record.id)\n }\n if (dealIds.size === 0) {\n return records.map((record) => ({\n ...record,\n _pipeline: buildPipelineState(\n record,\n emptyCounts,\n emptyTransitions,\n FALLBACK_THRESHOLD,\n now,\n today,\n ),\n }))\n }\n\n const [openInteractionCounts, latestTransitions, threshold] = await Promise.all([\n fetchOpenInteractionCounts(db, dealIds, context.organizationId, context.tenantId),\n fetchLatestStageTransitions(db, dealIds, context.organizationId, context.tenantId),\n fetchStuckThresholdDays(db, context.organizationId, context.tenantId),\n ])\n\n return records.map((record) => ({\n ...record,\n _pipeline: buildPipelineState(\n record,\n openInteractionCounts,\n latestTransitions,\n threshold,\n now,\n today,\n ),\n }))\n },\n}\n\ntype PersonRecord = Record<string, unknown> & { id: string }\n\n/**\n * Adds `_privateEmailCount` to each Person \u2014 the number of that person's PRIVATE\n * email interactions authored by OTHER users (private emails the current viewer\n * cannot see). Backs the documented \"count of teammates' private emails\" badge\n * (see `apps/docs/docs/user-guide/customers-email.mdx`): a viewer learns an\n * exchange exists without seeing its content. The count-badge UI is a pending\n * follow-up; the field is populated here so the consumer can be wired without a\n * second pass. Owner/tenant scoped and fail-safe to 0 \u2014 never leaks content.\n */\nexport const privateEmailCountEnricher: ResponseEnricher<\n PersonRecord,\n { _privateEmailCount?: number }\n> = {\n id: 'customers.private-email-count',\n targetEntity: 'customers.person',\n features: ['customers.people.view'],\n priority: 30,\n timeout: 1500,\n fallback: { _privateEmailCount: 0 },\n critical: false,\n\n async enrichOne(record, context) {\n const enriched = await this.enrichMany!([record], context)\n return enriched[0]\n },\n\n async enrichMany(records, context: EnricherContext) {\n if (records.length === 0) return records\n\n const db = resolveKyselyClient(context.em)\n if (!db) {\n return records.map((record) => ({ ...record, _privateEmailCount: 0 }))\n }\n\n const userId = context.userId\n // Fail-safe to 0 when there is no real authoring user to exclude. An API-key\n // principal (`auth.sub = \"api_key:<id>\"`) is not a person, so the\n // `author_user_id != userId` exclusion below would match nothing and count\n // every private email \u2014 short-circuit it here.\n if (!userId || userId.startsWith('api_key:')) {\n return records.map((record) => ({ ...record, _privateEmailCount: 0 }))\n }\n\n const personIds = records\n .map((r) => r.id)\n .filter((id): id is string => typeof id === 'string' && id.length > 0)\n\n if (personIds.length === 0) {\n return records.map((record) => ({ ...record, _privateEmailCount: 0 }))\n }\n\n const rows = await (db as CustomerKysely)\n .selectFrom('customer_interactions')\n .select(['entity_id'])\n .select((eb) => eb.fn.countAll().as('count'))\n .where('tenant_id', '=', context.tenantId)\n .where('organization_id', '=', context.organizationId)\n .where('interaction_type', '=', 'email')\n .where('visibility', '=', 'private')\n .where('deleted_at', 'is', null)\n .where('entity_id', 'in', personIds)\n .where('author_user_id', '!=', userId)\n .groupBy('entity_id')\n .execute()\n\n const countMap = new Map<string, number>()\n for (const row of rows) {\n const personId = typeof row.entity_id === 'string' ? row.entity_id : null\n if (!personId) continue\n const count = typeof row.count === 'number' ? row.count : Number(row.count)\n if (Number.isFinite(count)) countMap.set(personId, count)\n }\n\n return records.map((record) => ({\n ...record,\n _privateEmailCount: countMap.get(record.id) ?? 0,\n }))\n },\n}\n\ntype InteractionRecord = Record<string, unknown> & {\n id: string\n interactionType?: string | null\n externalMessageId?: string | null\n}\n\ntype EmailIntegrationFields = {\n externalMessageId?: string | null\n rfcMessageId?: string | null\n fromAddress?: string | null\n toAddresses?: string[] | null\n ccAddresses?: string[] | null\n subject?: string | null\n inReplyTo?: string | null\n references?: string[] | null\n /** Current visibility of the interaction row, for the private/shared toggle. */\n currentVisibility?: 'private' | 'shared' | null\n /** True when the interaction's author is the requesting user \u2014 gates the toggle. */\n isAuthor?: boolean\n}\n\n/**\n * Enriches email-type customer interactions with MessageChannelLink metadata\n * so the ActivityCard widget can render Reply/Forward/visibility-toggle actions.\n *\n * For each interaction row where `interactionType === 'email'` and\n * `externalMessageId` is set (the MessageChannelLink UUID), the enricher fetches\n * the corresponding `MessageChannelLink` row and populates\n * `_integrations.email.*` from its `channel_metadata` column.\n *\n * Non-email rows and rows without an externalMessageId pass through unchanged.\n * Fail-safe: if the Kysely client is unavailable or the lookup fails, the records\n * are returned unmodified so the activity timeline still renders (without email\n * card actions).\n */\nexport const interactionEmailCardEnricher: ResponseEnricher<\n InteractionRecord,\n { _integrations?: { email?: EmailIntegrationFields } }\n> = {\n id: 'customers.interaction-email-card',\n // Must match the entity ID passed to applyResponseEnrichers in the interactions\n // GET route (api/interactions/route.ts line 539): 'customers.interaction'.\n targetEntity: 'customers.interaction',\n features: ['customers.interactions.view'],\n priority: 25,\n timeout: 1500,\n fallback: {},\n critical: false,\n\n async enrichOne(record, ctx) {\n const results = await this.enrichMany!([record], ctx)\n return results[0]\n },\n\n async enrichMany(records, ctx) {\n if (records.length === 0) return records\n\n // Fast path: skip the DB round-trip when no email rows with a link are present.\n const emailRecords = records.filter(\n (r) =>\n r.interactionType === 'email' &&\n typeof r.externalMessageId === 'string' &&\n r.externalMessageId.length > 0,\n )\n if (emailRecords.length === 0) return records\n\n const linkIds = Array.from(\n new Set(emailRecords.map((r) => r.externalMessageId as string)),\n )\n\n // message_channel_links is owned by communication_channels; its read-only\n // shape is declared in CustomerKyselyDb so this stays type-safe without\n // cross-module coupling. Mirrors privateEmailCountEnricher.\n const kysely = resolveKyselyClient(ctx.em)\n if (!kysely) {\n // Fail-safe: Kysely unavailable (test stubs, unusual driver wrappers).\n return records\n }\n\n let linkRows: Array<{ id: string; channel_metadata: unknown }>\n try {\n linkRows = await kysely\n .selectFrom('message_channel_links')\n .select(['id', 'channel_metadata'])\n .where('tenant_id', '=', ctx.tenantId)\n // Defense-in-depth org scope. `id IN linkIds` already binds the lookup\n // to this org's interactions, and `message_channel_links.organization_id`\n // is nullable, so we tolerate NULL to avoid dropping legitimate links.\n .where((eb) =>\n eb.or([\n eb('organization_id', '=', ctx.organizationId),\n eb('organization_id', 'is', null),\n ]),\n )\n .where('id', 'in', linkIds)\n .execute()\n } catch {\n // Fail-safe: unexpected DB error (missing table in test env, schema drift).\n return records\n }\n\n const byLinkId = new Map<string, EmailIntegrationFields>()\n for (const row of linkRows) {\n const meta = (row.channel_metadata ?? {}) as Record<string, unknown>\n const fields: EmailIntegrationFields = {\n externalMessageId: row.id,\n rfcMessageId: typeof meta.messageId === 'string' ? meta.messageId : null,\n fromAddress: typeof meta.from === 'string' ? meta.from : null,\n toAddresses: stringArrayOrNull(meta.to),\n ccAddresses: stringArrayOrNull(meta.cc),\n // bcc is intentionally NOT surfaced: BCC recipients are blind by design,\n // so exposing them to every teammate who can view a shared email would\n // leak the blind-copy list. Keep it out of the enriched response.\n subject: typeof meta.subject === 'string' ? meta.subject : null,\n inReplyTo: typeof meta.inReplyTo === 'string' ? meta.inReplyTo : null,\n references: stringArrayOrNull(meta.references),\n }\n byLinkId.set(row.id, fields)\n }\n\n const currentUserId = ctx.userId\n\n return records.map((r) => {\n if (\n r.interactionType !== 'email' ||\n typeof r.externalMessageId !== 'string' ||\n r.externalMessageId.length === 0\n ) {\n return r\n }\n const fields = byLinkId.get(r.externalMessageId)\n if (!fields) return r\n const visibility =\n r.visibility === 'private' || r.visibility === 'shared' ? r.visibility : null\n const authorUserId = typeof r.authorUserId === 'string' ? r.authorUserId : null\n const isAuthor = Boolean(currentUserId && authorUserId && authorUserId === currentUserId)\n // Fail-closed (defense-in-depth): never surface another user's PRIVATE\n // email metadata (subject/from/to/references), even if a consumer forgot\n // to apply the visibility filter upstream. v1 is strict owner-only (no\n // admin bypass \u2014 `customers.email.view_private` is inert until v2), so a\n // private row is enriched only for its author. The normal read paths\n // already drop these rows; this keeps the globally-registered enricher\n // safe-by-construction for any future consumer that opts into it.\n if (visibility === 'private' && !isAuthor) {\n return r\n }\n const existingIntegrations = (r._integrations ?? {}) as Record<string, unknown>\n return {\n ...r,\n _integrations: {\n ...existingIntegrations,\n email: {\n ...fields,\n currentVisibility: visibility,\n isAuthor,\n },\n },\n }\n })\n },\n}\n\nexport const enrichers: ResponseEnricher[] = [dealPipelineEnricher, privateEmailCountEnricher, interactionEmailCardEnricher]\n"],
5
- "mappings": "AAEA,SAAS,2BAA2B;AACpC,SAAS,+BAA+B;AAgBxC,MAAM,sBAAsB;AAC5B,MAAM,SAAS,KAAK,KAAK,KAAK;AAM9B,MAAM,gCAAgC,CAAC,QAAQ,YAAY,WAAW;AAEtE,SAAS,UAAU,OAA6B;AAC9C,MAAI,CAAC,MAAO,QAAO;AACnB,MAAI,iBAAiB,KAAM,QAAO,OAAO,MAAM,MAAM,QAAQ,CAAC,IAAI,OAAO;AACzE,MAAI,OAAO,UAAU,UAAU;AAC7B,UAAM,OAAO,IAAI,KAAK,KAAK;AAC3B,WAAO,OAAO,MAAM,KAAK,QAAQ,CAAC,IAAI,OAAO;AAAA,EAC/C;AACA,SAAO;AACT;AAEA,SAAS,SAAS,MAAY,IAAkB;AAC9C,SAAO,KAAK,OAAO,GAAG,QAAQ,IAAI,KAAK,QAAQ,KAAK,MAAM;AAC5D;AAGA,SAAS,kBAAkB,OAAiC;AAC1D,MAAI,CAAC,MAAM,QAAQ,KAAK,EAAG,QAAO;AAClC,QAAM,UAAU,MAAM,OAAO,CAAC,UAA2B,OAAO,UAAU,QAAQ;AAClF,SAAO,QAAQ,SAAS,IAAI,UAAU;AACxC;AAEA,eAAe,2BACb,IACA,SACA,gBACA,UAC8B;AAC9B,QAAM,MAAM,oBAAI,IAAoB;AACpC,MAAI,QAAQ,SAAS,EAAG,Q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;AAAA,UACb,GAAG;AAAA,UACH,OAAO;AAAA,YACL,GAAG;AAAA,YACH,mBAAmB;AAAA,YACnB;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAEO,MAAM,YAAgC,CAAC,sBAAsB,2BAA2B,4BAA4B;",
4
+ "sourcesContent": ["import type { ResponseEnricher, EnricherContext } from '@open-mercato/shared/lib/crud/response-enricher'\nimport type { CustomerKysely } from '../lib/kysely'\nimport { resolveKyselyClient } from '../lib/kysely'\nimport { fetchStuckThresholdDays } from '../lib/stuckDeals'\nimport { TERMINAL_INTERACTION_STATUS_LIST } from '../lib/interactionStatus'\n\ntype DealRecord = Record<string, unknown> & {\n id: string\n status?: string | null\n expected_close_at?: string | null\n created_at?: string | null\n}\n\ntype PipelineState = {\n openActivitiesCount: number\n daysInCurrentStage: number\n isStuck: boolean\n isOverdue: boolean\n}\n\nconst ENRICHER_TIMEOUT_MS = 2000\nconst DAY_MS = 24 * 60 * 60 * 1000\n\nfunction parseDate(value: unknown): Date | null {\n if (!value) return null\n if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : value\n if (typeof value === 'string') {\n const date = new Date(value)\n return Number.isNaN(date.getTime()) ? null : date\n }\n return null\n}\n\nfunction diffDays(from: Date, to: Date): number {\n return Math.floor((to.getTime() - from.getTime()) / DAY_MS)\n}\n\n/** Coerce an unknown value to a non-empty string array, or null when absent/empty. */\nfunction stringArrayOrNull(value: unknown): string[] | null {\n if (!Array.isArray(value)) return null\n const strings = value.filter((entry): entry is string => typeof entry === 'string')\n return strings.length > 0 ? strings : null\n}\n\nasync function fetchOpenInteractionCounts(\n db: CustomerKysely,\n dealIds: Set<string>,\n organizationId: string,\n tenantId: string,\n): Promise<Map<string, number>> {\n const map = new Map<string, number>()\n if (dealIds.size === 0) return map\n const rows = await db\n .selectFrom('customer_interactions')\n .select(['deal_id'])\n .select((eb) => eb.fn.countAll().as('count'))\n .where('deal_id', 'in', [...dealIds])\n .where('organization_id', '=', organizationId)\n .where('tenant_id', '=', tenantId)\n .where('deleted_at', 'is', null)\n .where('status', 'not in', [...TERMINAL_INTERACTION_STATUS_LIST])\n .groupBy('deal_id')\n .execute()\n for (const row of rows) {\n if (row.deal_id == null) continue\n const count = typeof row.count === 'number' ? row.count : Number(row.count)\n if (Number.isFinite(count)) map.set(row.deal_id, count)\n }\n return map\n}\n\nasync function fetchLatestStageTransitions(\n db: CustomerKysely,\n dealIds: Set<string>,\n organizationId: string,\n tenantId: string,\n): Promise<Map<string, Date>> {\n const map = new Map<string, Date>()\n if (dealIds.size === 0) return map\n const rows = await db\n .selectFrom('customer_deal_stage_transitions')\n .select(['deal_id'])\n .select((eb) => eb.fn.max('transitioned_at').as('last_transitioned_at'))\n .where('deal_id', 'in', [...dealIds])\n .where('organization_id', '=', organizationId)\n .where('tenant_id', '=', tenantId)\n .where('deleted_at', 'is', null)\n .groupBy('deal_id')\n .execute()\n for (const row of rows) {\n const parsed = parseDate(row.last_transitioned_at)\n if (parsed) map.set(row.deal_id, parsed)\n }\n return map\n}\n\nexport function buildPipelineState(\n record: DealRecord,\n openInteractionCounts: Map<string, number>,\n latestTransitions: Map<string, Date>,\n threshold: number,\n now: Date,\n today: Date,\n): PipelineState {\n const openActivitiesCount = openInteractionCounts.get(record.id) ?? 0\n const transitionAt =\n latestTransitions.get(record.id) ?? parseDate(record.created_at) ?? now\n const daysInCurrentStage = Math.max(0, diffDays(transitionAt, now))\n const expectedClose = parseDate(record.expected_close_at)\n const status = typeof record.status === 'string' ? record.status : null\n const isOverdue = status === 'open' && !!expectedClose && expectedClose < today\n const isStuck = daysInCurrentStage > threshold\n return { openActivitiesCount, daysInCurrentStage, isStuck, isOverdue }\n}\n\nconst dealPipelineEnricher: ResponseEnricher<DealRecord> = {\n id: 'customers.deal-pipeline-state',\n targetEntity: 'customers.deal',\n // No `features` gate: the deals list route already enforces `customers.deals.view`\n // at the route-metadata level (see api/deals/route.ts). Declaring `features` here\n // would silently disable the enricher in environments where `rbacService` resolves\n // to undefined or `getGrantedFeatures` throws \u2014 `hasRequiredFeatures` treats a\n // missing `userFeatures` as \"no access\", which made `_pipeline` disappear from\n // CI responses (TC-CRM-066) while keeping the local kanban working.\n priority: 10,\n timeout: ENRICHER_TIMEOUT_MS,\n critical: false,\n fallback: {\n _pipeline: {\n openActivitiesCount: 0,\n daysInCurrentStage: 0,\n isStuck: false,\n isOverdue: false,\n },\n },\n\n async enrichOne(record, context) {\n const enriched = await this.enrichMany!([record], context)\n return enriched[0]\n },\n\n async enrichMany(records, context: EnricherContext) {\n if (records.length === 0) return records\n\n const now = new Date()\n const today = new Date(now.getFullYear(), now.getMonth(), now.getDate())\n\n // `buildPipelineState` is pure on top of (record + maps + threshold). The record alone\n // is enough to compute `isOverdue` (status + expected_close_at) and a conservative\n // `daysInCurrentStage` (created_at fallback). When Kysely isn't available on this\n // EntityManager \u2014 test stubs, unusual driver wrappers, or a transient DB issue \u2014\n // we still ship the correct overdue flag and a zeroed activities count rather than\n // silently dropping `_pipeline`, which previously made the kanban think every deal\n // had no stuck/overdue state.\n const emptyCounts: Map<string, number> = new Map()\n const emptyTransitions: Map<string, Date> = new Map()\n const FALLBACK_THRESHOLD = 14\n\n const db = resolveKyselyClient(context.em)\n if (!db) {\n return records.map((record) => ({\n ...record,\n _pipeline: buildPipelineState(\n record,\n emptyCounts,\n emptyTransitions,\n FALLBACK_THRESHOLD,\n now,\n today,\n ),\n }))\n }\n\n const dealIds = new Set<string>()\n for (const record of records) {\n if (typeof record.id === 'string') dealIds.add(record.id)\n }\n if (dealIds.size === 0) {\n return records.map((record) => ({\n ...record,\n _pipeline: buildPipelineState(\n record,\n emptyCounts,\n emptyTransitions,\n FALLBACK_THRESHOLD,\n now,\n today,\n ),\n }))\n }\n\n const [openInteractionCounts, latestTransitions, threshold] = await Promise.all([\n fetchOpenInteractionCounts(db, dealIds, context.organizationId, context.tenantId),\n fetchLatestStageTransitions(db, dealIds, context.organizationId, context.tenantId),\n fetchStuckThresholdDays(db, context.organizationId, context.tenantId),\n ])\n\n return records.map((record) => ({\n ...record,\n _pipeline: buildPipelineState(\n record,\n openInteractionCounts,\n latestTransitions,\n threshold,\n now,\n today,\n ),\n }))\n },\n}\n\ntype PersonRecord = Record<string, unknown> & { id: string }\n\n/**\n * Adds `_privateEmailCount` to each Person \u2014 the number of that person's PRIVATE\n * email interactions authored by OTHER users (private emails the current viewer\n * cannot see). Backs the documented \"count of teammates' private emails\" badge\n * (see `apps/docs/docs/user-guide/customers-email.mdx`): a viewer learns an\n * exchange exists without seeing its content. The count-badge UI is a pending\n * follow-up; the field is populated here so the consumer can be wired without a\n * second pass. Owner/tenant scoped and fail-safe to 0 \u2014 never leaks content.\n */\nexport const privateEmailCountEnricher: ResponseEnricher<\n PersonRecord,\n { _privateEmailCount?: number }\n> = {\n id: 'customers.private-email-count',\n targetEntity: 'customers.person',\n features: ['customers.people.view'],\n priority: 30,\n timeout: 1500,\n fallback: { _privateEmailCount: 0 },\n critical: false,\n\n async enrichOne(record, context) {\n const enriched = await this.enrichMany!([record], context)\n return enriched[0]\n },\n\n async enrichMany(records, context: EnricherContext) {\n if (records.length === 0) return records\n\n const db = resolveKyselyClient(context.em)\n if (!db) {\n return records.map((record) => ({ ...record, _privateEmailCount: 0 }))\n }\n\n const userId = context.userId\n // Fail-safe to 0 when there is no real authoring user to exclude. An API-key\n // principal (`auth.sub = \"api_key:<id>\"`) is not a person, so the\n // `author_user_id != userId` exclusion below would match nothing and count\n // every private email \u2014 short-circuit it here.\n if (!userId || userId.startsWith('api_key:')) {\n return records.map((record) => ({ ...record, _privateEmailCount: 0 }))\n }\n\n const personIds = records\n .map((r) => r.id)\n .filter((id): id is string => typeof id === 'string' && id.length > 0)\n\n if (personIds.length === 0) {\n return records.map((record) => ({ ...record, _privateEmailCount: 0 }))\n }\n\n const rows = await (db as CustomerKysely)\n .selectFrom('customer_interactions')\n .select(['entity_id'])\n .select((eb) => eb.fn.countAll().as('count'))\n .where('tenant_id', '=', context.tenantId)\n .where('organization_id', '=', context.organizationId)\n .where('interaction_type', '=', 'email')\n .where('visibility', '=', 'private')\n .where('deleted_at', 'is', null)\n .where('entity_id', 'in', personIds)\n .where('author_user_id', '!=', userId)\n .groupBy('entity_id')\n .execute()\n\n const countMap = new Map<string, number>()\n for (const row of rows) {\n const personId = typeof row.entity_id === 'string' ? row.entity_id : null\n if (!personId) continue\n const count = typeof row.count === 'number' ? row.count : Number(row.count)\n if (Number.isFinite(count)) countMap.set(personId, count)\n }\n\n return records.map((record) => ({\n ...record,\n _privateEmailCount: countMap.get(record.id) ?? 0,\n }))\n },\n}\n\ntype InteractionRecord = Record<string, unknown> & {\n id: string\n interactionType?: string | null\n externalMessageId?: string | null\n}\n\ntype EmailIntegrationFields = {\n externalMessageId?: string | null\n rfcMessageId?: string | null\n fromAddress?: string | null\n toAddresses?: string[] | null\n ccAddresses?: string[] | null\n subject?: string | null\n inReplyTo?: string | null\n references?: string[] | null\n /** Current visibility of the interaction row, for the private/shared toggle. */\n currentVisibility?: 'private' | 'shared' | null\n /** True when the interaction's author is the requesting user \u2014 gates the toggle. */\n isAuthor?: boolean\n}\n\n/**\n * Enriches email-type customer interactions with MessageChannelLink metadata\n * so the ActivityCard widget can render Reply/Forward/visibility-toggle actions.\n *\n * For each interaction row where `interactionType === 'email'` and\n * `externalMessageId` is set (the MessageChannelLink UUID), the enricher fetches\n * the corresponding `MessageChannelLink` row and populates\n * `_integrations.email.*` from its `channel_metadata` column.\n *\n * Non-email rows and rows without an externalMessageId pass through unchanged.\n * Fail-safe: if the Kysely client is unavailable or the lookup fails, the records\n * are returned unmodified so the activity timeline still renders (without email\n * card actions).\n */\nexport const interactionEmailCardEnricher: ResponseEnricher<\n InteractionRecord,\n { _integrations?: { email?: EmailIntegrationFields } }\n> = {\n id: 'customers.interaction-email-card',\n // Must match the entity ID passed to applyResponseEnrichers in the interactions\n // GET route (api/interactions/route.ts line 539): 'customers.interaction'.\n targetEntity: 'customers.interaction',\n features: ['customers.interactions.view'],\n priority: 25,\n timeout: 1500,\n fallback: {},\n critical: false,\n\n async enrichOne(record, ctx) {\n const results = await this.enrichMany!([record], ctx)\n return results[0]\n },\n\n async enrichMany(records, ctx) {\n if (records.length === 0) return records\n\n // Fast path: skip the DB round-trip when no email rows with a link are present.\n const emailRecords = records.filter(\n (r) =>\n r.interactionType === 'email' &&\n typeof r.externalMessageId === 'string' &&\n r.externalMessageId.length > 0,\n )\n if (emailRecords.length === 0) return records\n\n const linkIds = Array.from(\n new Set(emailRecords.map((r) => r.externalMessageId as string)),\n )\n\n // message_channel_links is owned by communication_channels; its read-only\n // shape is declared in CustomerKyselyDb so this stays type-safe without\n // cross-module coupling. Mirrors privateEmailCountEnricher.\n const kysely = resolveKyselyClient(ctx.em)\n if (!kysely) {\n // Fail-safe: Kysely unavailable (test stubs, unusual driver wrappers).\n return records\n }\n\n let linkRows: Array<{ id: string; channel_metadata: unknown }>\n try {\n linkRows = await kysely\n .selectFrom('message_channel_links')\n .select(['id', 'channel_metadata'])\n .where('tenant_id', '=', ctx.tenantId)\n // Defense-in-depth org scope. `id IN linkIds` already binds the lookup\n // to this org's interactions, and `message_channel_links.organization_id`\n // is nullable, so we tolerate NULL to avoid dropping legitimate links.\n .where((eb) =>\n eb.or([\n eb('organization_id', '=', ctx.organizationId),\n eb('organization_id', 'is', null),\n ]),\n )\n .where('id', 'in', linkIds)\n .execute()\n } catch {\n // Fail-safe: unexpected DB error (missing table in test env, schema drift).\n return records\n }\n\n const byLinkId = new Map<string, EmailIntegrationFields>()\n for (const row of linkRows) {\n const meta = (row.channel_metadata ?? {}) as Record<string, unknown>\n const fields: EmailIntegrationFields = {\n externalMessageId: row.id,\n rfcMessageId: typeof meta.messageId === 'string' ? meta.messageId : null,\n fromAddress: typeof meta.from === 'string' ? meta.from : null,\n toAddresses: stringArrayOrNull(meta.to),\n ccAddresses: stringArrayOrNull(meta.cc),\n // bcc is intentionally NOT surfaced: BCC recipients are blind by design,\n // so exposing them to every teammate who can view a shared email would\n // leak the blind-copy list. Keep it out of the enriched response.\n subject: typeof meta.subject === 'string' ? meta.subject : null,\n inReplyTo: typeof meta.inReplyTo === 'string' ? meta.inReplyTo : null,\n references: stringArrayOrNull(meta.references),\n }\n byLinkId.set(row.id, fields)\n }\n\n const currentUserId = ctx.userId\n\n return records.map((r) => {\n if (\n r.interactionType !== 'email' ||\n typeof r.externalMessageId !== 'string' ||\n r.externalMessageId.length === 0\n ) {\n return r\n }\n const fields = byLinkId.get(r.externalMessageId)\n if (!fields) return r\n const visibility =\n r.visibility === 'private' || r.visibility === 'shared' ? r.visibility : null\n const authorUserId = typeof r.authorUserId === 'string' ? r.authorUserId : null\n const isAuthor = Boolean(currentUserId && authorUserId && authorUserId === currentUserId)\n // Fail-closed (defense-in-depth): never surface another user's PRIVATE\n // email metadata (subject/from/to/references), even if a consumer forgot\n // to apply the visibility filter upstream. v1 is strict owner-only (no\n // admin bypass \u2014 `customers.email.view_private` is inert until v2), so a\n // private row is enriched only for its author. The normal read paths\n // already drop these rows; this keeps the globally-registered enricher\n // safe-by-construction for any future consumer that opts into it.\n if (visibility === 'private' && !isAuthor) {\n return r\n }\n const existingIntegrations = (r._integrations ?? {}) as Record<string, unknown>\n return {\n ...r,\n _integrations: {\n ...existingIntegrations,\n email: {\n ...fields,\n currentVisibility: visibility,\n isAuthor,\n },\n },\n }\n })\n },\n}\n\nexport const enrichers: ResponseEnricher[] = [dealPipelineEnricher, privateEmailCountEnricher, interactionEmailCardEnricher]\n"],
5
+ "mappings": "AAEA,SAAS,2BAA2B;AACpC,SAAS,+BAA+B;AACxC,SAAS,wCAAwC;AAgBjD,MAAM,sBAAsB;AAC5B,MAAM,SAAS,KAAK,KAAK,KAAK;AAE9B,SAAS,UAAU,OAA6B;AAC9C,MAAI,CAAC,MAAO,QAAO;AACnB,MAAI,iBAAiB,KAAM,QAAO,OAAO,MAAM,MAAM,QAAQ,CAAC,IAAI,OAAO;AACzE,MAAI,OAAO,UAAU,UAAU;AA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AC,MAAM;AACxB,UACE,EAAE,oBAAoB,WACtB,OAAO,EAAE,sBAAsB,YAC/B,EAAE,kBAAkB,WAAW,GAC/B;AACA,eAAO;AAAA,MACT;AACA,YAAM,SAAS,SAAS,IAAI,EAAE,iBAAiB;AAC/C,UAAI,CAAC,OAAQ,QAAO;AACpB,YAAM,aACJ,EAAE,eAAe,aAAa,EAAE,eAAe,WAAW,EAAE,aAAa;AAC3E,YAAM,eAAe,OAAO,EAAE,iBAAiB,WAAW,EAAE,eAAe;AAC3E,YAAM,WAAW,QAAQ,iBAAiB,gBAAgB,iBAAiB,aAAa;AAQxF,UAAI,eAAe,aAAa,CAAC,UAAU;AACzC,eAAO;AAAA,MACT;AACA,YAAM,uBAAwB,EAAE,iBAAiB,CAAC;AAClD,aAAO;AAAA,QACL,GAAG;AAAA,QACH,eAAe;AAAA,UACb,GAAG;AAAA,UACH,OAAO;AAAA,YACL,GAAG;AAAA,YACH,mBAAmB;AAAA,YACnB;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAEO,MAAM,YAAgC,CAAC,sBAAsB,2BAA2B,4BAA4B;",
6
6
  "names": []
7
7
  }
@@ -315,7 +315,11 @@ const interactionCreateBaseSchema = scopedSchema.extend({
315
315
  interactionType: z.string().trim().min(1).max(100),
316
316
  title: z.string().trim().max(500).optional().nullable(),
317
317
  body: z.string().trim().max(1e4).optional().nullable(),
318
- status: z.enum(interactionStatusValues).optional().default("planned"),
318
+ // Lenient like `deal_status` (status: z.string().max(50)). The `interaction-statuses`
319
+ // dictionary drives the UI dropdown; the API accepts any string <=50 chars so existing
320
+ // rows, external writers, and the dispatch-crm MCP keep working. Open/terminal semantics
321
+ // live in lib/interactionStatus.ts, not in this validator.
322
+ status: z.string().max(50).optional().default("planned"),
319
323
  date: z.string().trim().min(1, ACTIVITY_DATE_REQUIRED_MESSAGE_KEY).optional(),
320
324
  time: z.string().trim().min(1, ACTIVITY_TIME_REQUIRED_MESSAGE_KEY).optional(),
321
325
  phoneNumber: interactionPhoneNumberSchema,
@@ -368,7 +372,7 @@ const interactionUpdateBaseSchema = z.object({
368
372
  interactionType: z.string().trim().min(1).max(100).optional(),
369
373
  title: z.string().trim().max(500).optional().nullable(),
370
374
  body: z.string().trim().max(1e4).optional().nullable(),
371
- status: z.enum(interactionStatusValues).optional(),
375
+ status: z.string().max(50).optional(),
372
376
  date: z.string().trim().min(1, ACTIVITY_DATE_REQUIRED_MESSAGE_KEY).optional(),
373
377
  time: z.string().trim().min(1, ACTIVITY_TIME_REQUIRED_MESSAGE_KEY).optional(),
374
378
  phoneNumber: interactionPhoneNumberSchema,