@taskforcehq/taskforce 0.3.169 → 0.3.300
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -21
- package/dist/Taskforce.module.css +3394 -5981
- package/dist/TaskforceCore.CategoryFallback.test.js +5 -2
- package/dist/TaskforceCore.filter-persistence.test.js +402 -0
- package/dist/TaskforceCore.js +388 -71
- package/dist/TaskforceCore.routing.test.js +311 -0
- package/dist/TaskforceCore.test.js +3344 -615
- package/dist/TaskforceWidget.js +3 -2
- package/dist/__tests__/localizationCatalogs.test.js +48 -31
- package/dist/__tests__/workflowSimulation.test.js +2 -2
- package/dist/annotatedAttachments/AnnotatedAttachmentSessionStore.d.ts +60 -0
- package/dist/annotatedAttachments/AnnotatedAttachmentSessionStore.js +324 -0
- package/dist/annotatedAttachments/AnnotatedAttachmentSessionStore.test.js +278 -0
- package/dist/annotatedAttachments/payload.d.ts +2 -0
- package/dist/annotatedAttachments/payload.js +54 -0
- package/dist/annotatedAttachments/payload.test.js +67 -0
- package/dist/annotatedAttachments/service.d.ts +49 -0
- package/dist/annotatedAttachments/service.js +121 -0
- package/dist/annotatedAttachments/types.d.ts +86 -0
- package/dist/cli.js +74 -25
- package/dist/compat/deploymentCompat.d.ts +12 -0
- package/dist/compat/deploymentCompat.js +43 -0
- package/dist/compat/workspaceSyncCompat.d.ts +6 -0
- package/dist/compat/workspaceSyncCompat.js +79 -0
- package/dist/compat/workspaceSyncCompat.test.js +87 -0
- package/dist/components/features/AgentsModule.d.ts +5 -0
- package/dist/components/features/AgentsModule.js +131 -0
- package/dist/components/features/AgentsModule.test.js +102 -0
- package/dist/components/features/AnnotatedAttachmentWorkspace.d.ts +24 -0
- package/dist/components/features/AnnotatedAttachmentWorkspace.js +1942 -0
- package/dist/components/features/AnnotatedAttachmentWorkspace.test.js +2831 -0
- package/dist/components/features/DocumentGenerateModal.js +8 -16
- package/dist/components/features/DocumentIndex.d.ts +3 -4
- package/dist/components/features/DocumentIndex.js +22 -10
- package/dist/components/features/DocumentViewer.d.ts +6 -2
- package/dist/components/features/DocumentViewer.js +1000 -18
- package/dist/components/features/DocumentWorkspace.d.ts +40 -2
- package/dist/components/features/DocumentWorkspace.js +96 -16
- package/dist/components/features/DocumentWorkspace.test.js +1202 -0
- package/dist/components/features/InitiativesModule.d.ts +22 -0
- package/dist/components/features/InitiativesModule.js +33 -0
- package/dist/components/features/TaskSettings.d.ts +41 -32
- package/dist/components/features/TaskSettings.js +798 -313
- package/dist/components/features/TaskSettings.test.js +1221 -47
- package/dist/components/features/WorkflowsModule.d.ts +27 -0
- package/dist/components/features/WorkflowsModule.js +21 -0
- package/dist/components/features/documentWorkspaceFilters.d.ts +10 -0
- package/dist/components/features/documentWorkspaceFilters.js +11 -0
- package/dist/components/features/settings/CategoryManager.d.ts +2 -0
- package/dist/components/features/settings/CategoryManager.js +15 -8
- package/dist/components/features/settings/PriorityManager.d.ts +18 -0
- package/dist/components/features/settings/PriorityManager.js +51 -0
- package/dist/components/features/settings/TaxonomyEditor.d.ts +2 -1
- package/dist/components/features/settings/TaxonomyEditor.js +41 -18
- package/dist/components/features/settings/TaxonomyLibraryManager.d.ts +26 -0
- package/dist/components/features/settings/TaxonomyLibraryManager.js +301 -0
- package/dist/components/features/settings/TaxonomyLibraryManager.test.js +141 -0
- package/dist/components/features/settings/TaxonomyManager.d.ts +35 -12
- package/dist/components/features/settings/TaxonomyManager.js +59 -27
- package/dist/components/features/settings/TypeManager.d.ts +11 -0
- package/dist/components/features/settings/TypeManager.js +48 -11
- package/dist/components/features/settings/{WorkflowEditorPrototype.d.ts → WorkflowEditor.d.ts} +2 -2
- package/dist/components/features/settings/{WorkflowEditorPrototype.js → WorkflowEditor.js} +3 -3
- package/dist/components/task/TaskActionHeader.d.ts +12 -2
- package/dist/components/task/TaskActionHeader.js +64 -8
- package/dist/components/task/TaskActionHeader.test.js +73 -0
- package/dist/components/task/TaskCard.d.ts +14 -16
- package/dist/components/task/TaskCard.js +144 -174
- package/dist/components/task/TaskCard.test.js +416 -64
- package/dist/components/task/TaskContextUpload.d.ts +6 -5
- package/dist/components/task/TaskContextUpload.js +199 -64
- package/dist/components/task/TaskContextUpload.test.js +331 -14
- package/dist/components/task/TaskForm.d.ts +23 -29
- package/dist/components/task/TaskForm.js +348 -169
- package/dist/components/task/TaskForm.test.js +419 -23
- package/dist/components/task/TaskKanban.d.ts +20 -21
- package/dist/components/task/TaskKanban.js +176 -316
- package/dist/components/task/TaskKanban.planning-drop.test.js +93 -0
- package/dist/components/task/TaskList.d.ts +22 -11
- package/dist/components/task/TaskList.js +98 -12
- package/dist/components/task/TaskList.test.js +206 -7
- package/dist/components/task/TaskReferenceBadge.d.ts +12 -0
- package/dist/components/task/TaskReferenceBadge.js +5 -0
- package/dist/components/task/TaskStatusActions.d.ts +12 -0
- package/dist/components/task/TaskStatusActions.js +18 -0
- package/dist/components/task/TaskStatusActions.test.js +45 -0
- package/dist/components/ui/ImageReferenceBadge.d.ts +12 -0
- package/dist/components/ui/ImageReferenceBadge.js +5 -0
- package/dist/components/ui/LevelSelector.d.ts +2 -1
- package/dist/components/ui/LevelSelector.js +2 -2
- package/dist/components/ui/Markdown.d.ts +1 -2
- package/dist/components/ui/Markdown.js +2 -13
- package/dist/components/ui/Modal.d.ts +3 -2
- package/dist/components/ui/Modal.js +4 -3
- package/dist/components/ui/MultiSelectFilter.d.ts +3 -1
- package/dist/components/ui/MultiSelectFilter.js +2 -2
- package/dist/components/ui/ReferenceBadgeButton.d.ts +13 -0
- package/dist/components/ui/ReferenceBadgeButton.js +6 -0
- package/dist/components/ui/TaxonomyDropdown.d.ts +7 -1
- package/dist/components/ui/TaxonomyDropdown.js +58 -23
- package/dist/components/ui/TopNoticeLayer.d.ts +7 -0
- package/dist/components/ui/TopNoticeLayer.js +14 -0
- package/dist/components/ui/TopNoticeLayer.test.js +25 -0
- package/dist/components/views/AppShellHeader.d.ts +13 -0
- package/dist/components/views/AppShellHeader.js +19 -0
- package/dist/components/views/AppShellHeader.test.js +21 -0
- package/dist/components/views/PlanComparisonPage.d.ts +73 -0
- package/dist/components/views/PlanComparisonPage.js +196 -0
- package/dist/components/views/PlanComparisonPage.test.js +251 -0
- package/dist/components/views/PlansPage.d.ts +14 -0
- package/dist/components/views/PlansPage.js +355 -0
- package/dist/components/views/StandaloneLayout.d.ts +2 -2
- package/dist/components/views/StandaloneLayout.js +2212 -1194
- package/dist/components/views/WidgetView.d.ts +2 -2
- package/dist/components/views/WidgetView.js +149 -43
- package/dist/components/views/chrome/WorkspaceChromeSections.d.ts +57 -0
- package/dist/components/views/chrome/WorkspaceChromeSections.js +38 -0
- package/dist/components/views/chrome/WorkspaceChromeSections.test.js +54 -0
- package/dist/components/views/chrome/workspaceChrome.d.ts +31 -0
- package/dist/components/views/chrome/workspaceChrome.js +108 -0
- package/dist/components/views/chrome/workspaceChrome.test.js +52 -0
- package/dist/components/views/panels/DocumentFilterToolbar.d.ts +10 -0
- package/dist/components/views/panels/DocumentFilterToolbar.js +7 -0
- package/dist/components/views/panels/DocumentFilterToolbar.test.js +19 -0
- package/dist/components/views/panels/FilterToolbar.d.ts +66 -0
- package/dist/components/views/panels/FilterToolbar.js +21 -0
- package/dist/components/views/panels/FilterToolbar.test.d.ts +1 -0
- package/dist/components/views/panels/FilterToolbar.test.js +45 -0
- package/dist/components/views/panels/FilterToolbarControls.d.ts +46 -0
- package/dist/components/views/panels/FilterToolbarControls.js +61 -0
- package/dist/components/views/panels/PlanningDrawer.d.ts +115 -0
- package/dist/components/views/panels/PlanningDrawer.js +220 -0
- package/dist/components/views/panels/ScheduleSidebar.d.ts +52 -0
- package/dist/components/views/panels/ScheduleSidebar.js +127 -0
- package/dist/components/views/panels/scheduleUtils.d.ts +14 -0
- package/dist/components/views/panels/scheduleUtils.js +79 -0
- package/dist/components/views/teamManagementAccess.d.ts +6 -0
- package/dist/components/views/teamManagementAccess.js +18 -0
- package/dist/components/views/teamManagementAccess.test.d.ts +1 -0
- package/dist/components/views/teamManagementAccess.test.js +44 -0
- package/dist/config/clientDeployment.d.ts +2 -0
- package/dist/config/clientDeployment.js +13 -0
- package/dist/config/cloudEnvironment.d.ts +15 -0
- package/dist/config/cloudEnvironment.js +60 -0
- package/dist/config/deployment.d.ts +20 -0
- package/dist/config/deployment.js +67 -0
- package/dist/config/deployment.test.d.ts +1 -0
- package/dist/config/deployment.test.js +88 -0
- package/dist/config/envSchema.js +36 -8
- package/dist/config/envSchema.test.js +28 -0
- package/dist/core/AiProfileService.d.ts +66 -0
- package/dist/core/AiProfileService.js +320 -0
- package/dist/core/AiProfileService.test.d.ts +1 -0
- package/dist/core/AiProfileService.test.js +164 -0
- package/dist/core/AiProfiles.test.d.ts +1 -0
- package/dist/core/AiProfiles.test.js +449 -0
- package/dist/core/AttachmentLinkService.d.ts +15 -0
- package/dist/core/AttachmentLinkService.js +157 -0
- package/dist/core/AuthTokenService.d.ts +44 -0
- package/dist/core/AuthTokenService.js +207 -0
- package/dist/core/CreatedBy.test.js +134 -6
- package/dist/core/DeletedTaskLifecycleService.d.ts +33 -0
- package/dist/core/DeletedTaskLifecycleService.js +158 -0
- package/dist/core/DeletedTaskTrash.test.d.ts +1 -0
- package/dist/core/DeletedTaskTrash.test.js +104 -0
- package/dist/core/EntitlementsPolicy.test.js +78 -5
- package/dist/core/GlobalSettingsService.d.ts +16 -0
- package/dist/core/GlobalSettingsService.js +370 -0
- package/dist/core/JsonBackupRuntime.test.d.ts +1 -0
- package/dist/core/JsonBackupRuntime.test.js +155 -0
- package/dist/core/McpTokenService.d.ts +118 -0
- package/dist/core/McpTokenService.js +921 -0
- package/dist/core/PlanEntitlementService.d.ts +201 -0
- package/dist/core/PlanEntitlementService.js +1442 -0
- package/dist/core/PlanVersionPolicy.test.d.ts +1 -0
- package/dist/core/PlanVersionPolicy.test.js +178 -0
- package/dist/core/PlanningEntities.test.d.ts +1 -0
- package/dist/core/PlanningEntities.test.js +95 -0
- package/dist/core/ScheduleFields.test.js +15 -19
- package/dist/core/SignupMonetizationSettings.test.d.ts +1 -0
- package/dist/core/SignupMonetizationSettings.test.js +159 -0
- package/dist/core/Stats.test.d.ts +1 -0
- package/dist/core/Stats.test.js +36 -0
- package/dist/core/SyncReconciliationService.d.ts +93 -0
- package/dist/core/SyncReconciliationService.js +406 -0
- package/dist/core/SystemAdmin.test.js +578 -13
- package/dist/core/TaskActivityService.d.ts +21 -0
- package/dist/core/TaskActivityService.js +130 -0
- package/dist/core/TaskAttachmentsCanonical.test.d.ts +1 -0
- package/dist/core/TaskAttachmentsCanonical.test.js +306 -0
- package/dist/core/TaskAuditTimeline.test.d.ts +1 -0
- package/dist/core/TaskAuditTimeline.test.js +132 -0
- package/dist/core/TaskTaxonomyValidation.test.js +338 -15
- package/dist/core/Taskforce.d.ts +930 -183
- package/dist/core/Taskforce.ids.test.js +252 -0
- package/dist/core/Taskforce.js +3848 -2532
- package/dist/core/Taskforce.mcpAuth.test.d.ts +1 -0
- package/dist/core/Taskforce.mcpAuth.test.js +343 -0
- package/dist/core/Taskforce.realtimeMutation.test.js +57 -2
- package/dist/core/TaxonomySettingsService.d.ts +18 -0
- package/dist/core/TaxonomySettingsService.js +162 -0
- package/dist/core/WorkspaceDelete.test.js +32 -13
- package/dist/core/WorkspaceLifecycleService.d.ts +11 -0
- package/dist/core/WorkspaceLifecycleService.js +88 -0
- package/dist/core/WorkspacePermissions.test.js +95 -0
- package/dist/core/WorkspacePlanMode.test.js +114 -1
- package/dist/core/WorkspacePreferenceService.d.ts +41 -0
- package/dist/core/WorkspacePreferenceService.js +246 -0
- package/dist/core/WorkspaceSyncSettings.test.d.ts +1 -0
- package/dist/core/WorkspaceSyncSettings.test.js +65 -0
- package/dist/core/__tests__/TaskAttachmentsCanonical.test.d.ts +1 -0
- package/dist/core/__tests__/TaskAttachmentsCanonical.test.js +212 -0
- package/dist/core/shared.d.ts +36 -0
- package/dist/core/shared.js +128 -0
- package/dist/core/types.d.ts +614 -0
- package/dist/core/types.js +27 -0
- package/dist/documentReviews/DocumentReviewCommentStore.d.ts +56 -0
- package/dist/documentReviews/DocumentReviewCommentStore.js +230 -0
- package/dist/documentReviews/DocumentReviewSessionStore.d.ts +52 -0
- package/dist/documentReviews/DocumentReviewSessionStore.js +193 -0
- package/dist/documentReviews/DocumentReviewSessionStore.test.d.ts +1 -0
- package/dist/documentReviews/DocumentReviewSessionStore.test.js +127 -0
- package/dist/documentReviews/service.d.ts +68 -0
- package/dist/documentReviews/service.js +210 -0
- package/dist/documentReviews/types.d.ts +58 -0
- package/dist/documentReviews/types.js +1 -0
- package/dist/hooks/auth/useAuthGuardPolicy.d.ts +2 -0
- package/dist/hooks/auth/useAuthGuardPolicy.js +1 -0
- package/dist/hooks/tasks/useCurrentTaskRelations.d.ts +15 -0
- package/dist/hooks/tasks/useCurrentTaskRelations.js +37 -0
- package/dist/hooks/tasks/useTaskActions.d.ts +3 -0
- package/dist/hooks/tasks/useTaskActions.js +2 -0
- package/dist/hooks/tasks/useTaskEditorNavigation.d.ts +65 -0
- package/dist/hooks/tasks/useTaskEditorNavigation.js +235 -0
- package/dist/hooks/tasks/useTaskFilters.d.ts +2 -0
- package/dist/hooks/tasks/useTaskFilters.js +2 -0
- package/dist/hooks/tasks/useTaskFormActions.d.ts +58 -0
- package/dist/hooks/tasks/useTaskFormActions.js +365 -0
- package/dist/hooks/tasks/useTaskRelationships.d.ts +16 -0
- package/dist/hooks/tasks/useTaskRelationships.js +64 -0
- package/dist/hooks/ui/useResourceExport.d.ts +19 -0
- package/dist/hooks/ui/useResourceExport.js +84 -0
- package/dist/hooks/ui/useSettingsModel.d.ts +203 -0
- package/dist/hooks/ui/useSettingsModel.js +125 -0
- package/dist/hooks/ui/useSettingsPersistence.d.ts +36 -0
- package/dist/hooks/ui/useSettingsPersistence.js +254 -0
- package/dist/hooks/ui/useSettingsTaxonomyManagement.d.ts +119 -0
- package/dist/hooks/ui/useSettingsTaxonomyManagement.js +536 -0
- package/dist/hooks/ui/useUiNotice.d.ts +1 -0
- package/dist/hooks/ui/useUiNotice.js +1 -0
- package/dist/hooks/ui/useWorkflowTemplates.d.ts +37 -0
- package/dist/hooks/ui/useWorkflowTemplates.js +111 -0
- package/dist/hooks/ui/useZenMode.d.ts +5 -0
- package/dist/hooks/ui/useZenMode.js +32 -0
- package/dist/hooks/useFilterSort.d.ts +60 -0
- package/dist/hooks/useFilterSort.js +362 -0
- package/dist/hooks/useFilterSort.test.d.ts +1 -0
- package/dist/hooks/useFilterSort.test.js +333 -0
- package/dist/hooks/useRealtimeSync.d.ts +1 -0
- package/dist/hooks/useRealtimeSync.js +24 -9
- package/dist/hooks/useRealtimeSync.test.js +28 -1
- package/dist/hooks/useSyncOrchestrator.aiProfiles.test.d.ts +1 -0
- package/dist/hooks/useSyncOrchestrator.aiProfiles.test.js +34 -0
- package/dist/hooks/useSyncOrchestrator.d.ts +65 -103
- package/dist/hooks/useSyncOrchestrator.js +1538 -670
- package/dist/hooks/useSyncOrchestrator.retry-closure.test.js +700 -174
- package/dist/hooks/useTaskData.d.ts +35 -0
- package/dist/hooks/useTaskData.js +239 -0
- package/dist/hooks/useTaskData.test.d.ts +1 -0
- package/dist/hooks/useTaskData.test.js +119 -0
- package/dist/hooks/useTaskMutations.d.ts +46 -0
- package/dist/hooks/useTaskMutations.js +472 -0
- package/dist/hooks/useTaskMutations.test.d.ts +1 -0
- package/dist/hooks/useTaskMutations.test.js +80 -0
- package/dist/hooks/useTaskforce.contract.test.d.ts +1 -0
- package/dist/hooks/useTaskforce.contract.test.js +7 -0
- package/dist/hooks/useTaskforce.d.ts +260 -295
- package/dist/hooks/useTaskforce.js +1954 -2623
- package/dist/hooks/useTaskforce.priority-filters.test.js +6 -11
- package/dist/hooks/useTaskforce.sync-behavior.test.d.ts +1 -0
- package/dist/hooks/useTaskforce.sync-behavior.test.js +1120 -0
- package/dist/hooks/useUiNotice.d.ts +16 -0
- package/dist/hooks/useUiNotice.js +49 -0
- package/dist/hooks/useWorkspaceSyncController.d.ts +23 -46
- package/dist/hooks/useWorkspaceSyncController.js +280 -461
- package/dist/hooks/useWorkspaceSyncController.test.js +106 -199
- package/dist/hooks/workspace/useTaskforceApiRouting.d.ts +8 -0
- package/dist/hooks/workspace/useTaskforceApiRouting.js +91 -0
- package/dist/hooks/workspace/useTaskforceApiRouting.test.d.ts +1 -0
- package/dist/hooks/workspace/useTaskforceApiRouting.test.js +60 -0
- package/dist/hooks/workspace/useWorkspaceSyncController.d.ts +1 -0
- package/dist/hooks/workspace/useWorkspaceSyncController.js +1 -0
- package/dist/hooks/workspace/workspaceLocalState.d.ts +30 -0
- package/dist/hooks/workspace/workspaceLocalState.js +101 -0
- package/dist/localization/locales/en-US.d.ts +1 -8
- package/dist/localization/locales/en-US.js +4 -11
- package/dist/localization/locales/es-419.js +2 -9
- package/dist/localization/locales/pt-BR.js +2 -9
- package/dist/localization/localizationCatalogs.test.d.ts +1 -0
- package/dist/localization/localizationCatalogs.test.js +37 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +9 -15
- package/dist/mcp/clientIntegrations.d.ts +33 -0
- package/dist/mcp/clientIntegrations.js +199 -0
- package/dist/mcp/clientIntegrations.test.d.ts +1 -0
- package/dist/mcp/clientIntegrations.test.js +110 -0
- package/dist/mcp/index.d.ts +2 -0
- package/dist/mcp/index.js +2 -0
- package/dist/mcp/optionResolution.test.js +6 -2
- package/dist/mcp/runtime.d.ts +120 -0
- package/dist/mcp/runtime.js +5668 -0
- package/dist/mcp/runtime.test.d.ts +1 -0
- package/dist/mcp/runtime.test.js +3293 -0
- package/dist/mcp/server.js +2 -1793
- package/dist/mcp/structuredCommentValidation.test.d.ts +1 -0
- package/dist/{__tests__ → mcp}/structuredCommentValidation.test.js +1 -1
- package/dist/mcp/structuredDocValidation.js +1 -2
- package/dist/mcp/structuredDocValidation.test.d.ts +1 -0
- package/dist/{__tests__ → mcp}/structuredDocValidation.test.js +9 -4
- package/dist/mcp/toolRegistry.d.ts +570 -0
- package/dist/mcp/toolRegistry.js +90 -0
- package/dist/mcp/toolRegistry.test.d.ts +1 -0
- package/dist/mcp/toolRegistry.test.js +30 -0
- package/dist/migrations/billingSchemaParity.test.js +111 -0
- package/dist/migrations/taskSchemaMigrations.d.ts +5 -0
- package/dist/migrations/taskSchemaMigrations.js +681 -39
- package/dist/migrations/taskSchemaMigrations.test.d.ts +1 -0
- package/dist/migrations/taskSchemaMigrations.test.js +210 -0
- package/dist/plugins/vite.js +13 -7
- package/dist/public/apple-touch-icon.png +0 -0
- package/dist/public/archive/phoenix/apple-touch-icon.png +0 -0
- package/dist/public/archive/phoenix/favicon.ico +0 -0
- package/dist/public/archive/phoenix/site.webmanifest +1 -0
- package/dist/public/favicon-96x96.png +0 -0
- package/dist/public/favicon.ico +0 -0
- package/dist/public/favicon.svg +17 -0
- package/dist/public/site.webmanifest +21 -1
- package/dist/public/web-app-manifest-192x192.png +0 -0
- package/dist/public/web-app-manifest-512x512.png +0 -0
- package/dist/releaseVersion.test.d.ts +1 -0
- package/dist/{__tests__/releaseVersion.test.js → releaseVersion.test.js} +1 -1
- package/dist/resources/templates/WORKFLOW_V2_POLICY.md +1 -1
- package/dist/resources/templates/workflow-sources/workflowDocs.mjs +62 -52
- package/dist/resources/templates/workflows/collaborate.yaml +11 -5
- package/dist/resources/templates/workflows/do.yaml +8 -2
- package/dist/resources/templates/workflows/evaluate.yaml +13 -7
- package/dist/resources/templates/workflows/execute.yaml +40 -23
- package/dist/resources/templates/workflows/plan.yaml +15 -8
- package/dist/resources/templates/workflows/review.yaml +14 -8
- package/dist/runtime/appGateDefinitions.d.ts +32 -0
- package/dist/runtime/appGateDefinitions.js +32 -0
- package/dist/runtime/appGates.d.ts +29 -0
- package/dist/runtime/appGates.js +53 -0
- package/dist/runtime/appGates.test.d.ts +1 -0
- package/dist/runtime/appGates.test.js +42 -0
- package/dist/runtime/migrationFlags.d.ts +1 -0
- package/dist/runtime/migrationFlags.js +1 -0
- package/dist/server/annotatedAttachmentsRoutes.test.d.ts +1 -0
- package/dist/server/annotatedAttachmentsRoutes.test.js +473 -0
- package/dist/server/auth.js +14 -2
- package/dist/server/auth.test.js +21 -1
- package/dist/server/cors.js +11 -5
- package/dist/server/cors.test.js +6 -0
- package/dist/server/documentReviewRoutes.test.d.ts +1 -0
- package/dist/server/documentReviewRoutes.test.js +157 -0
- package/dist/server/index.cookieProxy.test.js +46 -1
- package/dist/server/index.d.ts +20 -0
- package/dist/server/index.js +168 -41
- package/dist/server/index.rateLimit.test.js +6 -0
- package/dist/server/index.test.js +133 -2
- package/dist/server/mockStripe.d.ts +72 -0
- package/dist/server/mockStripe.js +357 -0
- package/dist/server/realtimeSyncWs.js +4 -0
- package/dist/server/routes/admin.d.ts +114 -0
- package/dist/server/routes/admin.js +2226 -0
- package/dist/server/routes/annotatedAttachments.d.ts +24 -0
- package/dist/server/routes/annotatedAttachments.js +235 -0
- package/dist/server/routes/auth.d.ts +61 -0
- package/dist/server/routes/auth.js +1296 -0
- package/dist/server/{routes.billing.d.ts → routes/billing.d.ts} +3 -2
- package/dist/server/routes/billing.js +2001 -0
- package/dist/server/routes/billing.test.d.ts +1 -0
- package/dist/server/routes/billing.test.js +1631 -0
- package/dist/server/routes/documentReviews.d.ts +11 -0
- package/dist/server/routes/documentReviews.js +191 -0
- package/dist/server/routes/documents.d.ts +118 -0
- package/dist/server/routes/documents.js +1113 -0
- package/dist/server/routes/resources.d.ts +25 -0
- package/dist/server/routes/resources.js +225 -0
- package/dist/server/routes/shared.d.ts +35 -0
- package/dist/server/routes/shared.js +305 -0
- package/dist/server/routes/shared.test.d.ts +1 -0
- package/dist/server/routes/shared.test.js +32 -0
- package/dist/server/{routes.sync.d.ts → routes/sync.d.ts} +5 -5
- package/dist/server/routes/sync.integration.test.d.ts +1 -0
- package/dist/server/routes/sync.integration.test.js +2003 -0
- package/dist/server/routes/sync.js +3143 -0
- package/dist/server/routes/tasks.d.ts +72 -0
- package/dist/server/routes/tasks.js +1252 -0
- package/dist/server/routes/workspaces.d.ts +32 -0
- package/dist/server/routes/workspaces.js +307 -0
- package/dist/server/routes.d.ts +8 -9
- package/dist/server/routes.js +968 -4092
- package/dist/server/routes.test.js +9043 -2415
- package/dist/server/runtimeMode.d.ts +1 -1
- package/dist/server/runtimeMode.js +3 -18
- package/dist/server/runtimeMode.test.js +3 -3
- package/dist/server/securityHeaders.d.ts +1 -1
- package/dist/server/securityHeaders.js +65 -6
- package/dist/server/securityHeaders.test.js +40 -2
- package/dist/services/templateEngine.test.d.ts +1 -0
- package/dist/{__tests__ → services}/templateEngine.test.js +1 -1
- package/dist/services/templates.test.d.ts +1 -0
- package/dist/{__tests__ → services}/templates.test.js +1 -1
- package/dist/services/workflowDocumentFixtures.test.d.ts +1 -0
- package/dist/{__tests__ → services}/workflowDocumentFixtures.test.js +4 -4
- package/dist/services/workflowExportMatrix.test.d.ts +1 -0
- package/dist/{__tests__ → services}/workflowExportMatrix.test.js +1 -1
- package/dist/services/workflowExportSnapshots.test.d.ts +1 -0
- package/dist/services/workflowGeneration.test.d.ts +1 -0
- package/dist/services/workflowSimulation.test.d.ts +1 -0
- package/dist/services/workflowSimulation.test.js +113 -0
- package/dist/services/workflowV2Policy.test.d.ts +1 -0
- package/dist/{__tests__ → services}/workflowV2Policy.test.js +2 -2
- package/dist/shared/aiProfileSurfaceType.d.ts +9 -0
- package/dist/shared/aiProfileSurfaceType.js +49 -0
- package/dist/shared/customTaxonomyLibrary.d.ts +11 -0
- package/dist/shared/customTaxonomyLibrary.js +276 -0
- package/dist/shared/customTaxonomyLibrary.test.d.ts +1 -0
- package/dist/shared/customTaxonomyLibrary.test.js +20 -0
- package/dist/shared/taxonomyCatalog.d.ts +19 -0
- package/dist/shared/taxonomyCatalog.js +36 -0
- package/dist/shared/taxonomyDefaults.d.ts +29 -0
- package/dist/shared/taxonomyDefaults.js +26 -0
- package/dist/shared/taxonomyLibrary.d.ts +15 -0
- package/dist/shared/taxonomyLibrary.js +98 -0
- package/dist/shared/taxonomyLibrary.test.d.ts +1 -0
- package/dist/shared/taxonomyLibrary.test.js +26 -0
- package/dist/shared/taxonomyState.d.ts +36 -0
- package/dist/shared/taxonomyState.js +73 -0
- package/dist/shared/taxonomyState.test.d.ts +1 -0
- package/dist/shared/taxonomyState.test.js +71 -0
- package/dist/shared/workflowDefaults.d.ts +9 -0
- package/dist/shared/workflowDefaults.js +11 -0
- package/dist/storage/documentIntegrity.d.ts +2 -0
- package/dist/storage/documentIntegrity.js +34 -17
- package/dist/storage/documentPurge.d.ts +2 -1
- package/dist/storage/documentPurge.js +35 -8
- package/dist/storage/index.d.ts +4 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/objectStorage.d.ts +1 -1
- package/dist/storage/objectStorageClient.d.ts +6 -4
- package/dist/storage/objectStorageClient.js +77 -29
- package/dist/storage/objectStorageClient.test.d.ts +1 -0
- package/dist/storage/objectStorageClient.test.js +57 -0
- package/dist/storage/objectStorageConfig.js +3 -1
- package/dist/storage/objectStorageConfig.test.d.ts +1 -0
- package/dist/storage/objectStorageConfig.test.js +38 -0
- package/dist/storage/postgresAdapter.d.ts +5 -0
- package/dist/storage/postgresAdapter.js +2 -2
- package/dist/storage/postgresAdapter.test.d.ts +1 -0
- package/dist/storage/postgresAdapter.test.js +29 -0
- package/dist/storage/taskAssetStore.d.ts +7 -4
- package/dist/storage/taskAssetStore.js +65 -60
- package/dist/storage/workspaceAssetStore.d.ts +122 -0
- package/dist/storage/workspaceAssetStore.js +496 -0
- package/dist/storage/workspaceAssetStore.test.d.ts +1 -0
- package/dist/storage/workspaceAssetStore.test.js +501 -0
- package/dist/sync/cloudSyncApi.d.ts +33 -2
- package/dist/sync/cloudSyncApi.js +37 -15
- package/dist/sync/cloudSyncApi.test.js +60 -3
- package/dist/sync/index.d.ts +2 -0
- package/dist/sync/index.js +3 -0
- package/dist/sync/syncService.d.ts +25 -0
- package/dist/sync/syncService.js +184 -16
- package/dist/sync/syncService.test.js +289 -25
- package/dist/sync/workspaceRepair.d.ts +114 -0
- package/dist/sync/workspaceRepair.js +566 -0
- package/dist/sync/workspaceSyncModel.d.ts +230 -2
- package/dist/sync/workspaceSyncModel.js +456 -17
- package/dist/sync/workspaceSyncModel.test.js +642 -0
- package/dist/sync/workspaceSyncState.d.ts +12 -0
- package/dist/sync/workspaceSyncState.js +12 -0
- package/dist/sync/workspaceSyncSurface.d.ts +33 -0
- package/dist/sync/workspaceSyncSurface.js +74 -0
- package/dist/types.d.ts +143 -18
- package/dist/types.js +9 -24
- package/dist/ui/assets/AgentsModule-TVmCgizS.js +1 -0
- package/dist/ui/assets/AnnotatedAttachmentWorkspace-BaS2VwIr.css +1 -0
- package/dist/ui/assets/AnnotatedAttachmentWorkspace-CAyhnPeR.js +3 -0
- package/dist/ui/assets/DocumentWorkspace-BOCw5e4D.js +250 -0
- package/dist/ui/assets/DocumentWorkspace-C_8T8oz-.css +1 -0
- package/dist/ui/assets/InitiativesModule-CN0r02Oi.js +1 -0
- package/dist/ui/assets/PlansPage-BlVC_lRq.css +1 -0
- package/dist/ui/assets/PlansPage-FcQSNLZd.js +1 -0
- package/dist/ui/assets/TaskSettings-BwB9NtmJ.css +1 -0
- package/dist/ui/assets/TaskSettings-Cw5zYD1L.js +8 -0
- package/dist/ui/assets/WorkflowsModule-CY9R2zPB.js +5 -0
- package/dist/ui/assets/index-Bzqy5QGm.js +6 -0
- package/dist/ui/assets/index-DxRiI3tY.css +1 -0
- package/dist/ui/assets/vendor-dnd-DRzYolkg.js +5 -0
- package/dist/ui/assets/{vendor-icons-ZFG3SGwo.js → vendor-icons-QZyhEwgT.js} +1 -1
- package/dist/ui/assets/{vendor-markdown-CKYkQHfj.js → vendor-markdown-BUxTU7dS.js} +1 -1
- package/dist/ui/assets/vendor-react-CKJs5o3c.js +61 -0
- package/dist/ui/assets/vendor-router-BbWMxlnO.js +3 -0
- package/dist/ui/branding/logos/logo.png +0 -0
- package/dist/ui/branding/logos/logo_dark.svg +27 -0
- package/dist/ui/branding/logos/logo_favicon.svg +35 -0
- package/dist/ui/branding/logos/logo_light.svg +27 -0
- package/dist/ui/favicon/apple-touch-icon.png +0 -0
- package/dist/ui/favicon/archive/phoenix/apple-touch-icon.png +0 -0
- package/dist/ui/favicon/archive/phoenix/favicon.ico +0 -0
- package/dist/ui/favicon/archive/phoenix/site.webmanifest +1 -0
- package/dist/ui/favicon/favicon-96x96.png +0 -0
- package/dist/ui/favicon/favicon.ico +0 -0
- package/dist/ui/favicon/favicon.svg +17 -0
- package/dist/ui/favicon/site.webmanifest +21 -1
- package/dist/ui/favicon/web-app-manifest-192x192.png +0 -0
- package/dist/ui/favicon/web-app-manifest-512x512.png +0 -0
- package/dist/ui/index.html +10 -7
- package/dist/ui/product/screen_01.png +0 -0
- package/dist/ui/product/screen_02.png +0 -0
- package/dist/ui/product/screen_03.png +0 -0
- package/dist/utils/annotatedAttachments.d.ts +20 -0
- package/dist/utils/annotatedAttachments.js +74 -0
- package/dist/utils/annotatedAttachments.test.d.ts +1 -0
- package/dist/utils/annotatedAttachments.test.js +108 -0
- package/dist/utils/assignees.d.ts +26 -0
- package/dist/utils/assignees.js +132 -0
- package/dist/utils/canonicalAssetKind.d.ts +16 -0
- package/dist/utils/canonicalAssetKind.js +39 -0
- package/dist/utils/canonicalAssetKind.test.d.ts +1 -0
- package/dist/utils/canonicalAssetKind.test.js +24 -0
- package/dist/utils/coalescedRefresh.d.ts +5 -0
- package/dist/utils/coalescedRefresh.js +16 -0
- package/dist/utils/coalescedRefresh.test.d.ts +1 -0
- package/dist/utils/coalescedRefresh.test.js +30 -0
- package/dist/utils/constants.d.ts +16 -3
- package/dist/utils/constants.icons.test.js +2 -1
- package/dist/utils/constants.js +70 -13
- package/dist/utils/contextAssetEvents.d.ts +7 -0
- package/dist/utils/contextAssetEvents.js +6 -0
- package/dist/utils/contextFiles.d.ts +14 -3
- package/dist/utils/contextFiles.js +40 -8
- package/dist/utils/documentManagerApi.d.ts +6 -0
- package/dist/utils/documentManagerApi.js +19 -0
- package/dist/utils/documentNames.d.ts +24 -0
- package/dist/utils/documentNames.js +91 -0
- package/dist/utils/documentReferences.d.ts +9 -0
- package/dist/utils/documentReferences.js +11 -0
- package/dist/utils/entityReferences.d.ts +9 -0
- package/dist/utils/entityReferences.js +32 -0
- package/dist/utils/imageReferences.d.ts +9 -0
- package/dist/utils/imageReferences.js +11 -0
- package/dist/utils/planParser.d.ts +2 -2
- package/dist/utils/planParser.js +11 -11
- package/dist/utils/planParser.test.d.ts +1 -0
- package/dist/{__tests__ → utils}/planParser.test.js +22 -22
- package/dist/utils/planningReferences.d.ts +17 -0
- package/dist/utils/planningReferences.js +30 -0
- package/dist/utils/planningReferences.test.d.ts +1 -0
- package/dist/utils/planningReferences.test.js +17 -0
- package/dist/utils/taskActivity.d.ts +9 -0
- package/dist/utils/taskActivity.js +147 -0
- package/dist/utils/taskActivity.test.d.ts +1 -0
- package/dist/utils/taskActivity.test.js +34 -0
- package/dist/utils/taskDraftDefaults.d.ts +21 -0
- package/dist/utils/taskDraftDefaults.js +40 -0
- package/dist/utils/taskDraftDefaults.test.d.ts +1 -0
- package/dist/utils/taskDraftDefaults.test.js +34 -0
- package/dist/utils/taskNormalization.d.ts +25 -0
- package/dist/utils/taskNormalization.js +161 -0
- package/dist/utils/taskNormalization.test.d.ts +1 -0
- package/dist/utils/taskNormalization.test.js +158 -0
- package/dist/utils/taskReferences.d.ts +5 -0
- package/dist/utils/taskReferences.js +11 -0
- package/dist/utils/taskforceApiClient.d.ts +2 -0
- package/dist/utils/taskforceApiClient.js +101 -3
- package/dist/utils/taskforceApiClient.test.d.ts +1 -0
- package/dist/utils/taskforceApiClient.test.js +44 -0
- package/dist/utils/taxonomyFilterOptions.d.ts +2 -0
- package/dist/utils/taxonomyFilterOptions.js +17 -0
- package/dist/utils/taxonomyFormDefaults.d.ts +3 -0
- package/dist/utils/taxonomyFormDefaults.js +28 -0
- package/dist/utils/taxonomyFormDefaults.test.d.ts +1 -0
- package/dist/utils/taxonomyFormDefaults.test.js +63 -0
- package/dist/utils/taxonomyLifecycle.d.ts +3 -0
- package/dist/utils/taxonomyLifecycle.js +17 -0
- package/dist/utils/taxonomySorting.d.ts +7 -0
- package/dist/utils/taxonomySorting.js +74 -0
- package/dist/utils/theme.d.ts +15 -0
- package/dist/utils/theme.js +23 -0
- package/dist/utils/uiNotice.d.ts +7 -0
- package/dist/utils/uiNotice.js +6 -0
- package/dist/utils/uiNotice.test.d.ts +1 -0
- package/dist/utils/uiNotice.test.js +18 -0
- package/dist/utils/workspaceIdentity.d.ts +14 -0
- package/dist/utils/workspaceIdentity.js +21 -0
- package/dist/utils/workspaceIdentity.test.js +30 -1
- package/dist/utils/workspaceSyncPresentation.d.ts +20 -0
- package/dist/utils/workspaceSyncPresentation.js +21 -0
- package/dist/utils/workspaceSyncPresentation.test.d.ts +1 -0
- package/dist/utils/workspaceSyncPresentation.test.js +36 -0
- package/package.json +28 -23
- package/scripts/bootstrap-playwright-auth.mjs +155 -0
- package/scripts/check-compat-boundaries.mjs +41 -0
- package/scripts/check-env.ts +9 -2
- package/scripts/debug-login.mjs +32 -0
- package/scripts/migrate-planning-model.ts +233 -0
- package/scripts/migrate-task-data-assets.mjs +408 -0
- package/scripts/playwright-auth.sh +11 -0
- package/scripts/run-dev-proxy.sh +2 -0
- package/scripts/update-homebrew-formula.sh +20 -3
- package/scripts/with-esbuild.sh +11 -0
- package/src/resources/templates/WORKFLOW_V2_POLICY.md +1 -1
- package/src/resources/templates/workflow-sources/workflowDocs.mjs +62 -52
- package/src/resources/templates/workflows/collaborate.yaml +11 -5
- package/src/resources/templates/workflows/do.yaml +8 -2
- package/src/resources/templates/workflows/evaluate.yaml +13 -7
- package/src/resources/templates/workflows/execute.yaml +40 -23
- package/src/resources/templates/workflows/plan.yaml +15 -8
- package/src/resources/templates/workflows/review.yaml +14 -8
- package/dist/TaskforceScreenshot.d.ts +0 -11
- package/dist/TaskforceScreenshot.js +0 -113
- package/dist/compat/priorityCompat.d.ts +0 -2
- package/dist/compat/priorityCompat.js +0 -24
- package/dist/components/features/settings/TaxonomyManager 2.d.ts +0 -52
- package/dist/components/features/settings/TaxonomyManager 2.js +0 -75
- package/dist/components/task/TaskKanban 2.d.ts +0 -76
- package/dist/components/task/TaskKanban 2.js +0 -1004
- package/dist/components/task/TaskScreenshotSection.d.ts +0 -15
- package/dist/components/task/TaskScreenshotSection.js +0 -22
- package/dist/components/views/StandaloneLayout 2.d.ts +0 -8
- package/dist/components/views/StandaloneLayout 2.js +0 -1660
- package/dist/core/InitiativeTemplates.test.js +0 -50
- package/dist/core/ParentLifecycle.test.js +0 -98
- package/dist/migrations/clientMigrations.d.ts +0 -9
- package/dist/migrations/clientMigrations.js +0 -74
- package/dist/migrations/flags.d.ts +0 -6
- package/dist/migrations/flags.js +0 -8
- package/dist/migrations/taskMigrations.d.ts +0 -71
- package/dist/migrations/taskMigrations.js +0 -236
- package/dist/migrations/taskMigrations.test.js +0 -34
- package/dist/server/routes.billing.js +0 -991
- package/dist/server/routes.billing.test.js +0 -387
- package/dist/server/routes.sync.integration.test.js +0 -470
- package/dist/server/routes.sync.js +0 -1141
- package/dist/soak/syncSoakHarness.d.ts +0 -6
- package/dist/soak/syncSoakHarness.js +0 -10
- package/dist/ui/assets/index-0W5vyCpn.css +0 -1
- package/dist/ui/assets/index-MCZuNNfn.js +0 -23
- package/dist/ui/assets/logo_white_01-0Vx-iIIv.png +0 -0
- package/dist/ui/assets/vendor-dnd-BI1K77C1.js +0 -5
- package/dist/ui/assets/vendor-react-DdIDsh7f.js +0 -9
- package/dist/ui/assets/vendor-router-BtiNU7Dl.js +0 -3
- package/dist/utils/taskHierarchy.d.ts +0 -4
- package/dist/utils/taskHierarchy.js +0 -69
- package/dist/utils/taskHierarchy.test.js +0 -38
- package/dist/utils/taskParenting.d.ts +0 -3
- package/dist/utils/taskParenting.js +0 -24
- package/dist/utils/taskParenting.test.js +0 -21
- package/dist/utils/taskRelations.d.ts +0 -6
- package/dist/utils/taskRelations.js +0 -24
- package/dist/utils/taskRelations.test.js +0 -34
- package/scripts/check-compat-boundaries.js +0 -48
- /package/dist/{__tests__/planParser.test.d.ts → TaskforceCore.filter-persistence.test.d.ts} +0 -0
- /package/dist/{__tests__/releaseVersion.test.d.ts → TaskforceCore.routing.test.d.ts} +0 -0
- /package/dist/{__tests__/structuredCommentValidation.test.d.ts → annotatedAttachments/AnnotatedAttachmentSessionStore.test.d.ts} +0 -0
- /package/dist/{__tests__/structuredDocValidation.test.d.ts → annotatedAttachments/payload.test.d.ts} +0 -0
- /package/dist/{__tests__/templateEngine.test.d.ts → annotatedAttachments/types.js} +0 -0
- /package/dist/{__tests__/templates.test.d.ts → compat/workspaceSyncCompat.test.d.ts} +0 -0
- /package/dist/{__tests__/workflowDocumentFixtures.test.d.ts → components/features/AgentsModule.test.d.ts} +0 -0
- /package/dist/{__tests__/workflowExportMatrix.test.d.ts → components/features/AnnotatedAttachmentWorkspace.test.d.ts} +0 -0
- /package/dist/{__tests__/workflowExportSnapshots.test.d.ts → components/features/DocumentWorkspace.test.d.ts} +0 -0
- /package/dist/{__tests__/workflowGeneration.test.d.ts → components/features/settings/TaxonomyLibraryManager.test.d.ts} +0 -0
- /package/dist/{__tests__/workflowV2Policy.test.d.ts → components/task/TaskActionHeader.test.d.ts} +0 -0
- /package/dist/{core/InitiativeTemplates.test.d.ts → components/task/TaskKanban.planning-drop.test.d.ts} +0 -0
- /package/dist/{core/ParentLifecycle.test.d.ts → components/task/TaskStatusActions.test.d.ts} +0 -0
- /package/dist/{migrations/taskMigrations.test.d.ts → components/ui/TopNoticeLayer.test.d.ts} +0 -0
- /package/dist/{server/routes.billing.test.d.ts → components/views/AppShellHeader.test.d.ts} +0 -0
- /package/dist/{server/routes.sync.integration.test.d.ts → components/views/PlanComparisonPage.test.d.ts} +0 -0
- /package/dist/{utils/taskHierarchy.test.d.ts → components/views/chrome/WorkspaceChromeSections.test.d.ts} +0 -0
- /package/dist/{utils/taskParenting.test.d.ts → components/views/chrome/workspaceChrome.test.d.ts} +0 -0
- /package/dist/{utils/taskRelations.test.d.ts → components/views/panels/DocumentFilterToolbar.test.d.ts} +0 -0
- /package/dist/public/{android-chrome-192x192.png → archive/phoenix/android-chrome-192x192.png} +0 -0
- /package/dist/public/{android-chrome-512x512.png → archive/phoenix/android-chrome-512x512.png} +0 -0
- /package/dist/public/{favicon-16x16.png → archive/phoenix/favicon-16x16.png} +0 -0
- /package/dist/public/{favicon-32x32.png → archive/phoenix/favicon-32x32.png} +0 -0
- /package/dist/public/{favicon.png → archive/phoenix/favicon.png} +0 -0
- /package/dist/{__tests__ → services}/workflowExportSnapshots.test.js +0 -0
- /package/dist/{__tests__ → services}/workflowGeneration.test.js +0 -0
- /package/dist/ui/favicon/{android-chrome-192x192.png → archive/phoenix/android-chrome-192x192.png} +0 -0
- /package/dist/ui/favicon/{android-chrome-512x512.png → archive/phoenix/android-chrome-512x512.png} +0 -0
- /package/dist/ui/favicon/{favicon-16x16.png → archive/phoenix/favicon-16x16.png} +0 -0
- /package/dist/ui/favicon/{favicon-32x32.png → archive/phoenix/favicon-32x32.png} +0 -0
- /package/dist/ui/favicon/{favicon.png → archive/phoenix/favicon.png} +0 -0
|
@@ -0,0 +1,1296 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth route module.
|
|
3
|
+
*
|
|
4
|
+
* Handles authentication, session management, email verification, password reset,
|
|
5
|
+
* invite flows, account status, and workspace-level team/user administration.
|
|
6
|
+
*
|
|
7
|
+
* Routes registered here:
|
|
8
|
+
* GET /api/taskforce/auth/runtime-config
|
|
9
|
+
* GET /api/taskforce/auth/session
|
|
10
|
+
* GET /api/taskforce/auth/admin-session
|
|
11
|
+
* POST /api/taskforce/auth/profile
|
|
12
|
+
* POST /api/taskforce/auth/login
|
|
13
|
+
* POST /api/taskforce/auth/register
|
|
14
|
+
* POST /api/taskforce/auth/verify-email/request
|
|
15
|
+
* POST /api/taskforce/auth/verify-email/confirm
|
|
16
|
+
* POST /api/taskforce/auth/password-reset/request
|
|
17
|
+
* POST /api/taskforce/auth/password-reset/confirm
|
|
18
|
+
* POST /api/taskforce/auth/invite/inspect
|
|
19
|
+
* POST /api/taskforce/auth/invite/accept
|
|
20
|
+
* POST /api/taskforce/auth/invite/join
|
|
21
|
+
* POST /api/taskforce/auth/logout
|
|
22
|
+
* GET /api/taskforce/account/access-status
|
|
23
|
+
* GET /api/taskforce/account/entitlements
|
|
24
|
+
* GET /api/taskforce/account/plan-preview
|
|
25
|
+
* GET /api/taskforce/auth/workspace-members
|
|
26
|
+
* GET /api/taskforce/workspace/assignee-options
|
|
27
|
+
* GET /api/taskforce/admin/users
|
|
28
|
+
* POST /api/taskforce/admin/users/invite
|
|
29
|
+
* PATCH /api/taskforce/admin/users/:id/role
|
|
30
|
+
* PATCH /api/taskforce/admin/users/:id/permission-mode
|
|
31
|
+
* PATCH /api/taskforce/admin/users/:id/disable
|
|
32
|
+
* POST /api/taskforce/admin/users/:id/invite/revoke
|
|
33
|
+
* DELETE /api/taskforce/admin/users/:id
|
|
34
|
+
* GET /api/taskforce/admin/workspace-audit-logs
|
|
35
|
+
*/
|
|
36
|
+
import { parseJsonBody } from '../routes.js';
|
|
37
|
+
import { hasValidSession, createClearSessionCookie, createSessionTokenCookie, resolveRequestAccess, resolveSessionCookieAttributesForRequest, } from '../auth.js';
|
|
38
|
+
import { resolveEffectiveEmailConfig, sendEmail } from '../email.js';
|
|
39
|
+
import { resolveDeploymentConfig } from '../../config/deployment.js';
|
|
40
|
+
import { resolveRuntimeModeContract } from '../../shared/runtimeContract.js';
|
|
41
|
+
import { resolveErrorStatusCode } from './shared.js';
|
|
42
|
+
// === SECTION: Registration ===
|
|
43
|
+
export function registerAuthRoutes(deps) {
|
|
44
|
+
const { addRoute, core, context, requestWorkspaceId, requestUserId, ensureAppAccess, ensureAuthenticatedUser, ensureWorkspaceAdminRole, ensureCloudPlanData, requireCloudRuntime, auditAuthAction, resolveAdminRequestActor, shouldExposeDevAuthTokens, resolveRuntimeConfigBaseUrl, resolvePublicAuthBaseUrl, } = deps;
|
|
45
|
+
// === SECTION: Email delivery helpers ===
|
|
46
|
+
const getEmailConfig = () => {
|
|
47
|
+
if (context.authConfig?.runtimeMode !== 'cloud') {
|
|
48
|
+
return resolveEffectiveEmailConfig(process.env, { provider: 'console' });
|
|
49
|
+
}
|
|
50
|
+
const globalSettings = core.getGlobalSettings();
|
|
51
|
+
return resolveEffectiveEmailConfig(process.env, globalSettings.email || null);
|
|
52
|
+
};
|
|
53
|
+
const getAuthBehavior = () => {
|
|
54
|
+
const globalSettings = core.getGlobalSettings();
|
|
55
|
+
const authSettings = globalSettings.auth || {};
|
|
56
|
+
const authRateLimitMaxRequestsRaw = Number(authSettings.authRateLimitMaxRequests);
|
|
57
|
+
const authRateLimitWindowMsRaw = Number(authSettings.authRateLimitWindowMs);
|
|
58
|
+
const signupSettings = core.getSignupMonetizationSettings();
|
|
59
|
+
return {
|
|
60
|
+
allowSelfRegistration: authSettings.allowSelfRegistration !== false,
|
|
61
|
+
requireVerifiedEmail: authSettings.requireVerifiedEmail !== false,
|
|
62
|
+
defaultNewUserBetaAccess: authSettings.defaultNewUserBetaAccess === true,
|
|
63
|
+
authRateLimitEnabled: authSettings.authRateLimitEnabled !== false,
|
|
64
|
+
authRateLimitMaxRequests: Number.isFinite(authRateLimitMaxRequestsRaw) && authRateLimitMaxRequestsRaw >= 1
|
|
65
|
+
? Math.floor(authRateLimitMaxRequestsRaw)
|
|
66
|
+
: 10,
|
|
67
|
+
authRateLimitWindowMs: Number.isFinite(authRateLimitWindowMsRaw) && authRateLimitWindowMsRaw >= 1000
|
|
68
|
+
? Math.floor(authRateLimitWindowMsRaw)
|
|
69
|
+
: 15 * 60_000,
|
|
70
|
+
signupMonetizationStrategy: signupSettings.strategy,
|
|
71
|
+
defaultSignupPlanVersionId: signupSettings.defaultSignupPlanVersionId
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
const getSiteBehavior = () => {
|
|
75
|
+
const globalSettings = core.getGlobalSettings();
|
|
76
|
+
const siteSettings = globalSettings.site || {};
|
|
77
|
+
return {
|
|
78
|
+
showRunTaskforceLocally: siteSettings.showRunTaskforceLocally !== false,
|
|
79
|
+
pricingPageEnabled: siteSettings.pricingPageEnabled !== false
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
const logAuthLink = (kind, email, token, req) => {
|
|
83
|
+
const base = resolvePublicAuthBaseUrl(req);
|
|
84
|
+
const urlPath = kind === 'verify-email'
|
|
85
|
+
? `/login?mode=verify&token=${encodeURIComponent(token)}`
|
|
86
|
+
: `/login?mode=reset&token=${encodeURIComponent(token)}`;
|
|
87
|
+
console.info(`[Taskforce Auth] ${kind} email=${email} link=${base}${urlPath}`);
|
|
88
|
+
};
|
|
89
|
+
const deliverAuthEmail = async (kind, email, token, req) => {
|
|
90
|
+
const base = resolvePublicAuthBaseUrl(req);
|
|
91
|
+
const urlPath = kind === 'verify-email'
|
|
92
|
+
? `/login?mode=verify&token=${encodeURIComponent(token)}`
|
|
93
|
+
: `/login?mode=reset&token=${encodeURIComponent(token)}`;
|
|
94
|
+
const link = `${base}${urlPath}`;
|
|
95
|
+
logAuthLink(kind, email, token, req);
|
|
96
|
+
const subject = kind === 'verify-email'
|
|
97
|
+
? 'Verify your Taskforce account'
|
|
98
|
+
: 'Reset your Taskforce password';
|
|
99
|
+
const text = kind === 'verify-email'
|
|
100
|
+
? `Welcome to Taskforce.\n\nVerify your email by opening this link:\n${link}\n\nIf you did not create an account, you can ignore this message.`
|
|
101
|
+
: `Reset your Taskforce password using this link:\n${link}\n\nIf you did not request this reset, you can ignore this message.`;
|
|
102
|
+
const result = await sendEmail({
|
|
103
|
+
to: email,
|
|
104
|
+
subject,
|
|
105
|
+
text
|
|
106
|
+
}, getEmailConfig());
|
|
107
|
+
if (result.ok) {
|
|
108
|
+
console.info(`[Taskforce Auth Email] kind=${kind} provider=${result.provider} to=${email} messageId=${result.messageId || '-'}`);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
console.warn(`[Taskforce Auth Email] kind=${kind} provider=${result.provider} to=${email} error=${result.error || 'unknown'}`);
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
};
|
|
115
|
+
const deliverInviteEmail = async (email, token, req, meta) => {
|
|
116
|
+
const base = resolvePublicAuthBaseUrl(req);
|
|
117
|
+
const link = `${base}/login?mode=invite&token=${encodeURIComponent(token)}`;
|
|
118
|
+
const subject = `You are invited to ${meta.workspaceName} on Taskforce`;
|
|
119
|
+
const text = `You have been invited to Taskforce.\n\nWorkspace: ${meta.workspaceName}\nInvited by: ${meta.inviterEmailOrLabel}\n\nAccept your invite and set your password:\n${link}\n\nIf you did not expect this invite, you can ignore this message.`;
|
|
120
|
+
const result = await sendEmail({
|
|
121
|
+
to: email,
|
|
122
|
+
subject,
|
|
123
|
+
text
|
|
124
|
+
}, getEmailConfig());
|
|
125
|
+
if (result.ok) {
|
|
126
|
+
console.info(`[Taskforce Auth Email] kind=invite provider=${result.provider} to=${email} messageId=${result.messageId || '-'}`);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
console.warn(`[Taskforce Auth Email] kind=invite provider=${result.provider} to=${email} error=${result.error || 'unknown'}`);
|
|
130
|
+
}
|
|
131
|
+
return result;
|
|
132
|
+
};
|
|
133
|
+
// === SECTION: Runtime config and session ===
|
|
134
|
+
// GET /api/taskforce/auth/runtime-config - Runtime URL hints for client endpoint resolution.
|
|
135
|
+
// This route intentionally lives under /api/taskforce/auth/* so it remains reachable before sign-in.
|
|
136
|
+
addRoute('GET', '/api/taskforce/auth/runtime-config', async (req, res) => {
|
|
137
|
+
const requestBaseUrl = resolveRuntimeConfigBaseUrl(req);
|
|
138
|
+
const deployment = resolveDeploymentConfig(process.env, { requestBaseUrl });
|
|
139
|
+
const runtimeContract = resolveRuntimeModeContract(context.authConfig?.runtimeMode || 'local');
|
|
140
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
141
|
+
res.end(JSON.stringify({
|
|
142
|
+
success: true,
|
|
143
|
+
config: {
|
|
144
|
+
cloudEnvironment: deployment.cloudEnvironment,
|
|
145
|
+
cloudBaseUrl: deployment.cloudBaseUrl || null,
|
|
146
|
+
cloudMcpBaseUrl: deployment.cloudMcpBaseUrl || null,
|
|
147
|
+
baseUrl: deployment.baseUrl || null,
|
|
148
|
+
apiBaseUrl: deployment.apiBaseUrl || null,
|
|
149
|
+
cloudAuthBaseUrl: deployment.cloudAuthBaseUrl || null,
|
|
150
|
+
wsBaseUrl: deployment.wsBaseUrl || null,
|
|
151
|
+
cloudAuthViaLocalProxy: deployment.cloudAuthViaLocalProxy,
|
|
152
|
+
runtimeMode: runtimeContract.runtimeMode,
|
|
153
|
+
authSource: runtimeContract.authSource,
|
|
154
|
+
workspaceMode: runtimeContract.workspaceMode,
|
|
155
|
+
workspaceSwitchingEnabled: runtimeContract.workspaceSwitchingEnabled
|
|
156
|
+
}
|
|
157
|
+
}));
|
|
158
|
+
});
|
|
159
|
+
addRoute('GET', '/api/taskforce/public/site-config', async (_req, res) => {
|
|
160
|
+
const siteBehavior = getSiteBehavior();
|
|
161
|
+
res.writeHead(200, {
|
|
162
|
+
'Content-Type': 'application/json',
|
|
163
|
+
'Cross-Origin-Resource-Policy': 'cross-origin'
|
|
164
|
+
});
|
|
165
|
+
res.end(JSON.stringify({
|
|
166
|
+
success: true,
|
|
167
|
+
config: siteBehavior
|
|
168
|
+
}));
|
|
169
|
+
});
|
|
170
|
+
addRoute('GET', '/api/taskforce/public/site-config-script', async (_req, res) => {
|
|
171
|
+
const siteBehavior = getSiteBehavior();
|
|
172
|
+
const payload = JSON.stringify(siteBehavior).replace(/</g, '\\u003c');
|
|
173
|
+
res.writeHead(200, {
|
|
174
|
+
'Content-Type': 'application/javascript; charset=utf-8',
|
|
175
|
+
'Cache-Control': 'no-store',
|
|
176
|
+
'Cross-Origin-Resource-Policy': 'cross-origin'
|
|
177
|
+
});
|
|
178
|
+
res.end(`window.__TASKFORCE_SITE_CONFIG__ = ${payload};`);
|
|
179
|
+
});
|
|
180
|
+
// GET /api/taskforce/auth/session - Return current auth/session state
|
|
181
|
+
addRoute('GET', '/api/taskforce/auth/session', async (req, res) => {
|
|
182
|
+
const authConfig = context.authConfig;
|
|
183
|
+
const access = authConfig ? resolveRequestAccess(req, authConfig) : null;
|
|
184
|
+
const authenticated = Boolean(authConfig && hasValidSession(req, authConfig));
|
|
185
|
+
let role = access?.role || authConfig?.defaultRole || 'member';
|
|
186
|
+
let workspaceId = String(access?.workspaceId || authConfig?.defaultWorkspaceId || '').trim();
|
|
187
|
+
let userId = access?.userId || 'anonymous';
|
|
188
|
+
let email = null;
|
|
189
|
+
let displayName = null;
|
|
190
|
+
let betaAccess = true;
|
|
191
|
+
if (authenticated && access?.userId) {
|
|
192
|
+
betaAccess = core.getUserBetaAccess(access.userId);
|
|
193
|
+
const resolved = core.resolveUserAccess(access.userId, workspaceId, role);
|
|
194
|
+
if (resolved) {
|
|
195
|
+
role = resolved.role;
|
|
196
|
+
workspaceId = resolved.workspaceId;
|
|
197
|
+
userId = resolved.userId;
|
|
198
|
+
betaAccess = resolved.betaAccess;
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
workspaceId = 'default';
|
|
202
|
+
role = authConfig?.defaultRole || 'member';
|
|
203
|
+
}
|
|
204
|
+
const identity = core.resolveUserIdentity(userId);
|
|
205
|
+
email = identity?.email || null;
|
|
206
|
+
displayName = identity?.displayName || null;
|
|
207
|
+
}
|
|
208
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
209
|
+
res.end(JSON.stringify({
|
|
210
|
+
authenticated,
|
|
211
|
+
userId,
|
|
212
|
+
workspaceId,
|
|
213
|
+
role,
|
|
214
|
+
email,
|
|
215
|
+
displayName,
|
|
216
|
+
betaAccess
|
|
217
|
+
}));
|
|
218
|
+
});
|
|
219
|
+
// GET /api/taskforce/auth/admin-session - Return global admin auth/session state
|
|
220
|
+
addRoute('GET', '/api/taskforce/auth/admin-session', async (req, res) => {
|
|
221
|
+
const actor = resolveAdminRequestActor(req);
|
|
222
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
223
|
+
res.end(JSON.stringify({
|
|
224
|
+
authenticated: actor.authenticated,
|
|
225
|
+
userId: actor.userId,
|
|
226
|
+
systemRole: actor.systemRole
|
|
227
|
+
}));
|
|
228
|
+
});
|
|
229
|
+
addRoute('POST', '/api/taskforce/auth/profile', async (req, res) => {
|
|
230
|
+
if (!requireCloudRuntime(res, 'Authentication'))
|
|
231
|
+
return;
|
|
232
|
+
if (!ensureAuthenticatedUser(req)) {
|
|
233
|
+
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
234
|
+
res.end(JSON.stringify({ success: false, error: 'Authentication required.' }));
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const userId = String(requestUserId(req) || '').trim();
|
|
238
|
+
if (!userId || userId === 'anonymous') {
|
|
239
|
+
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
240
|
+
res.end(JSON.stringify({ success: false, error: 'Authentication required.' }));
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const body = await parseJsonBody(req);
|
|
244
|
+
try {
|
|
245
|
+
const updated = core.updateUserDisplayName(userId, String(body?.displayName || ''));
|
|
246
|
+
if (!updated) {
|
|
247
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
248
|
+
res.end(JSON.stringify({ success: false, error: 'User not found.', code: 'USER_NOT_FOUND' }));
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
auditAuthAction(req, 'auth-profile-updated', {
|
|
252
|
+
userId,
|
|
253
|
+
displayName: updated.displayName || null
|
|
254
|
+
});
|
|
255
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
256
|
+
res.end(JSON.stringify({
|
|
257
|
+
success: true,
|
|
258
|
+
profile: {
|
|
259
|
+
userId: updated.userId,
|
|
260
|
+
email: updated.email,
|
|
261
|
+
displayName: updated.displayName || null
|
|
262
|
+
}
|
|
263
|
+
}));
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
const statusCode = resolveErrorStatusCode(error, 400);
|
|
267
|
+
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
268
|
+
res.end(JSON.stringify({ success: false, error: String(error?.message || 'Unable to update profile.'), code: error?.code }));
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
// === SECTION: Login and register ===
|
|
272
|
+
// POST /api/taskforce/auth/login - Exchange email/password for secure session cookie
|
|
273
|
+
addRoute('POST', '/api/taskforce/auth/login', async (req, res) => {
|
|
274
|
+
if (!requireCloudRuntime(res, 'Authentication'))
|
|
275
|
+
return;
|
|
276
|
+
const authConfig = context.authConfig;
|
|
277
|
+
if (!authConfig) {
|
|
278
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
279
|
+
res.end(JSON.stringify({ success: false, error: 'Auth context unavailable.' }));
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
if (!authConfig.enabled) {
|
|
283
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
284
|
+
res.end(JSON.stringify({ success: false, error: 'Auth is not enabled.' }));
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const body = await parseJsonBody(req);
|
|
288
|
+
const email = String(body?.email || '').trim().toLowerCase();
|
|
289
|
+
const password = String(body?.password || '');
|
|
290
|
+
const requestedWorkspaceId = String(body?.workspaceId || '').trim();
|
|
291
|
+
const workspaceIdCandidate = requestedWorkspaceId;
|
|
292
|
+
// Login must not be blocked when the user has zero workspaces. Use reserved "default"
|
|
293
|
+
// as transient session scope until setup creates/switches to a real workspace.
|
|
294
|
+
const workspaceId = workspaceIdCandidate || 'default';
|
|
295
|
+
// Password flow (preferred)
|
|
296
|
+
if (email && password) {
|
|
297
|
+
const authBehavior = getAuthBehavior();
|
|
298
|
+
let authResult = core.authenticatePasswordUserDetailed({
|
|
299
|
+
email,
|
|
300
|
+
password,
|
|
301
|
+
workspaceId,
|
|
302
|
+
fallbackRole: authConfig.defaultRole,
|
|
303
|
+
requireVerifiedEmail: authBehavior.requireVerifiedEmail
|
|
304
|
+
});
|
|
305
|
+
if (authBehavior.requireVerifiedEmail && (!authResult.ok || !authResult.access) && authResult.code === 'EMAIL_NOT_VERIFIED') {
|
|
306
|
+
const bootstrapEmail = String(process.env.TASKFORCE_BOOTSTRAP_ADMIN_EMAIL || '').trim().toLowerCase();
|
|
307
|
+
const bootstrapPassword = String(process.env.TASKFORCE_BOOTSTRAP_ADMIN_PASSWORD || '');
|
|
308
|
+
if (bootstrapEmail && bootstrapPassword && email === bootstrapEmail && password === bootstrapPassword) {
|
|
309
|
+
core.markEmailVerified(email);
|
|
310
|
+
authResult = core.authenticatePasswordUserDetailed({
|
|
311
|
+
email,
|
|
312
|
+
password,
|
|
313
|
+
workspaceId,
|
|
314
|
+
fallbackRole: authConfig.defaultRole,
|
|
315
|
+
requireVerifiedEmail: authBehavior.requireVerifiedEmail
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (!authResult.ok || !authResult.access) {
|
|
320
|
+
auditAuthAction(req, 'auth-login-failed', {
|
|
321
|
+
email,
|
|
322
|
+
workspaceId,
|
|
323
|
+
code: authResult.code || 'INVALID_CREDENTIALS'
|
|
324
|
+
});
|
|
325
|
+
if (authResult.code === 'EMAIL_NOT_VERIFIED') {
|
|
326
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
327
|
+
res.end(JSON.stringify({ success: false, error: 'Email not verified.', code: 'EMAIL_NOT_VERIFIED' }));
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
331
|
+
res.end(JSON.stringify({ success: false, error: 'Invalid email/password.' }));
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
let access = authResult.access;
|
|
335
|
+
const resolvedWorkspaceId = core.resolvePreferredUserWorkspaceId(access.userId, {
|
|
336
|
+
preferredWorkspaceId: requestedWorkspaceId || null,
|
|
337
|
+
persistedWorkspaceId: access.workspaceId || null
|
|
338
|
+
});
|
|
339
|
+
if (resolvedWorkspaceId && resolvedWorkspaceId !== access.workspaceId) {
|
|
340
|
+
const resolvedAccess = core.resolveUserAccess(access.userId, resolvedWorkspaceId, access.role);
|
|
341
|
+
if (resolvedAccess) {
|
|
342
|
+
access = {
|
|
343
|
+
userId: resolvedAccess.userId,
|
|
344
|
+
workspaceId: resolvedAccess.workspaceId,
|
|
345
|
+
role: resolvedAccess.role
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
const cookie = createSessionTokenCookie(`pwd:${access.userId}`, authConfig, {
|
|
350
|
+
role: access.role,
|
|
351
|
+
workspaceId: access.workspaceId,
|
|
352
|
+
userId: access.userId,
|
|
353
|
+
...resolveSessionCookieAttributesForRequest(req, authConfig)
|
|
354
|
+
});
|
|
355
|
+
auditAuthAction(req, 'auth-login-success', {
|
|
356
|
+
email,
|
|
357
|
+
userId: access.userId,
|
|
358
|
+
workspaceId: access.workspaceId,
|
|
359
|
+
role: access.role
|
|
360
|
+
});
|
|
361
|
+
res.setHeader('Set-Cookie', cookie);
|
|
362
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
363
|
+
res.end(JSON.stringify({ success: true, method: 'password' }));
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
367
|
+
res.end(JSON.stringify({ success: false, error: 'Email and password are required.' }));
|
|
368
|
+
});
|
|
369
|
+
// POST /api/taskforce/auth/register - Create account and exchange for secure session cookie
|
|
370
|
+
addRoute('POST', '/api/taskforce/auth/register', async (req, res) => {
|
|
371
|
+
if (!requireCloudRuntime(res, 'Authentication'))
|
|
372
|
+
return;
|
|
373
|
+
const authConfig = context.authConfig;
|
|
374
|
+
if (!authConfig) {
|
|
375
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
376
|
+
res.end(JSON.stringify({ success: false, error: 'Auth context unavailable.' }));
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
if (!authConfig.enabled) {
|
|
380
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
381
|
+
res.end(JSON.stringify({ success: false, error: 'Auth is not enabled.' }));
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
const body = await parseJsonBody(req);
|
|
385
|
+
const email = String(body?.email || '').trim().toLowerCase();
|
|
386
|
+
const password = String(body?.password || '');
|
|
387
|
+
const displayName = String(body?.displayName || email.split('@')[0] || email).trim();
|
|
388
|
+
const workspaceIdInput = typeof body?.workspaceId === 'string'
|
|
389
|
+
? body.workspaceId.trim()
|
|
390
|
+
: '';
|
|
391
|
+
const selectedPlanVersionId = typeof body?.planVersionId === 'string'
|
|
392
|
+
? body.planVersionId.trim()
|
|
393
|
+
: '';
|
|
394
|
+
const authBehavior = getAuthBehavior();
|
|
395
|
+
if (!authBehavior.allowSelfRegistration) {
|
|
396
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
397
|
+
res.end(JSON.stringify({ success: false, error: 'Self-registration is currently disabled.' }));
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
if (!email || !password) {
|
|
401
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
402
|
+
res.end(JSON.stringify({ success: false, error: 'Email and password are required.' }));
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
try {
|
|
406
|
+
const hasRequestedWorkspace = Boolean(workspaceIdInput && workspaceIdInput.toLowerCase() !== 'default');
|
|
407
|
+
const role = hasRequestedWorkspace
|
|
408
|
+
? (core.hasWorkspaceAdmin(workspaceIdInput) ? 'member' : 'owner')
|
|
409
|
+
: 'member';
|
|
410
|
+
const created = core.registerPasswordUser({
|
|
411
|
+
email,
|
|
412
|
+
password,
|
|
413
|
+
workspaceId: hasRequestedWorkspace ? workspaceIdInput : undefined,
|
|
414
|
+
planVersionId: selectedPlanVersionId || undefined,
|
|
415
|
+
displayName,
|
|
416
|
+
role,
|
|
417
|
+
betaAccess: authBehavior.defaultNewUserBetaAccess
|
|
418
|
+
});
|
|
419
|
+
const sessionWorkspaceId = created.workspaceId || '';
|
|
420
|
+
const cookie = createSessionTokenCookie(`pwd:${created.userId}`, authConfig, {
|
|
421
|
+
role: created.role,
|
|
422
|
+
workspaceId: sessionWorkspaceId,
|
|
423
|
+
userId: created.userId,
|
|
424
|
+
...resolveSessionCookieAttributesForRequest(req, authConfig)
|
|
425
|
+
});
|
|
426
|
+
let emailSent = true;
|
|
427
|
+
let emailError;
|
|
428
|
+
let verificationToken;
|
|
429
|
+
if (authBehavior.requireVerifiedEmail) {
|
|
430
|
+
const verification = core.requestEmailVerification({ email });
|
|
431
|
+
verificationToken = verification.token || null;
|
|
432
|
+
if (verification.token) {
|
|
433
|
+
const delivery = await deliverAuthEmail('verify-email', email, verification.token, req);
|
|
434
|
+
emailSent = delivery.ok;
|
|
435
|
+
emailError = delivery.error;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
auditAuthAction(req, 'auth-register-success', {
|
|
439
|
+
email,
|
|
440
|
+
userId: created.userId,
|
|
441
|
+
workspaceId: created.workspaceId || null,
|
|
442
|
+
role: created.role,
|
|
443
|
+
emailSent
|
|
444
|
+
});
|
|
445
|
+
res.setHeader('Set-Cookie', cookie);
|
|
446
|
+
res.writeHead(201, { 'Content-Type': 'application/json' });
|
|
447
|
+
res.end(JSON.stringify({
|
|
448
|
+
success: true,
|
|
449
|
+
method: 'password',
|
|
450
|
+
role: created.role,
|
|
451
|
+
workspaceSetupRequired: !created.workspaceId,
|
|
452
|
+
planSelectionRequired: created.planSelectionRequired === true,
|
|
453
|
+
verificationRequired: authBehavior.requireVerifiedEmail,
|
|
454
|
+
emailSent,
|
|
455
|
+
emailError,
|
|
456
|
+
verificationToken: authBehavior.requireVerifiedEmail && shouldExposeDevAuthTokens()
|
|
457
|
+
? (verificationToken || null)
|
|
458
|
+
: undefined
|
|
459
|
+
}));
|
|
460
|
+
}
|
|
461
|
+
catch (error) {
|
|
462
|
+
const statusCode = Number(error?.statusCode || 400);
|
|
463
|
+
const message = String(error?.message || 'Unable to register');
|
|
464
|
+
auditAuthAction(req, 'auth-register-failed', {
|
|
465
|
+
email,
|
|
466
|
+
workspaceId: workspaceIdInput || null,
|
|
467
|
+
code: error?.code || 'REGISTER_FAILED',
|
|
468
|
+
statusCode
|
|
469
|
+
});
|
|
470
|
+
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
471
|
+
res.end(JSON.stringify({ success: false, error: message, code: error?.code }));
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
// === SECTION: Email verification ===
|
|
475
|
+
// POST /api/taskforce/auth/verify-email/request - Request new verification email/token
|
|
476
|
+
addRoute('POST', '/api/taskforce/auth/verify-email/request', async (req, res) => {
|
|
477
|
+
if (!requireCloudRuntime(res, 'Authentication'))
|
|
478
|
+
return;
|
|
479
|
+
const body = await parseJsonBody(req);
|
|
480
|
+
const email = String(body?.email || '').trim().toLowerCase();
|
|
481
|
+
if (!email) {
|
|
482
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
483
|
+
res.end(JSON.stringify({ success: false, error: 'Email is required.' }));
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
try {
|
|
487
|
+
let emailSent = true;
|
|
488
|
+
let emailError;
|
|
489
|
+
const verification = core.requestEmailVerification({ email });
|
|
490
|
+
if (verification.token) {
|
|
491
|
+
const delivery = await deliverAuthEmail('verify-email', email, verification.token, req);
|
|
492
|
+
emailSent = delivery.ok;
|
|
493
|
+
emailError = delivery.error;
|
|
494
|
+
}
|
|
495
|
+
auditAuthAction(req, 'auth-verify-request', {
|
|
496
|
+
email,
|
|
497
|
+
emailSent
|
|
498
|
+
});
|
|
499
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
500
|
+
res.end(JSON.stringify({
|
|
501
|
+
success: true,
|
|
502
|
+
emailSent,
|
|
503
|
+
emailError,
|
|
504
|
+
verificationToken: shouldExposeDevAuthTokens() ? (verification.token || null) : undefined
|
|
505
|
+
}));
|
|
506
|
+
}
|
|
507
|
+
catch (error) {
|
|
508
|
+
auditAuthAction(req, 'auth-verify-request-failed', {
|
|
509
|
+
email,
|
|
510
|
+
statusCode: resolveErrorStatusCode(error, 400)
|
|
511
|
+
});
|
|
512
|
+
res.writeHead(resolveErrorStatusCode(error, 400), { 'Content-Type': 'application/json' });
|
|
513
|
+
res.end(JSON.stringify({ success: false, error: String(error?.message || 'Unable to request verification') }));
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
// POST /api/taskforce/auth/verify-email/confirm - Verify email using one-time token
|
|
517
|
+
addRoute('POST', '/api/taskforce/auth/verify-email/confirm', async (req, res) => {
|
|
518
|
+
if (!requireCloudRuntime(res, 'Authentication'))
|
|
519
|
+
return;
|
|
520
|
+
const body = await parseJsonBody(req);
|
|
521
|
+
const token = String(body?.token || '').trim();
|
|
522
|
+
if (!token) {
|
|
523
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
524
|
+
res.end(JSON.stringify({ success: false, error: 'Token is required.' }));
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
const verified = core.verifyEmailWithToken(token);
|
|
528
|
+
if (!verified) {
|
|
529
|
+
auditAuthAction(req, 'auth-verify-confirm-failed', {
|
|
530
|
+
tokenProvided: true
|
|
531
|
+
});
|
|
532
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
533
|
+
res.end(JSON.stringify({ success: false, error: 'Invalid or expired token.' }));
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
auditAuthAction(req, 'auth-verify-confirm-success', {
|
|
537
|
+
tokenProvided: true
|
|
538
|
+
});
|
|
539
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
540
|
+
res.end(JSON.stringify({ success: true }));
|
|
541
|
+
});
|
|
542
|
+
// === SECTION: Password reset ===
|
|
543
|
+
// POST /api/taskforce/auth/password-reset/request - Request password reset token
|
|
544
|
+
addRoute('POST', '/api/taskforce/auth/password-reset/request', async (req, res) => {
|
|
545
|
+
if (!requireCloudRuntime(res, 'Authentication'))
|
|
546
|
+
return;
|
|
547
|
+
const body = await parseJsonBody(req);
|
|
548
|
+
const email = String(body?.email || '').trim().toLowerCase();
|
|
549
|
+
if (!email) {
|
|
550
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
551
|
+
res.end(JSON.stringify({ success: false, error: 'Email is required.' }));
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
try {
|
|
555
|
+
let emailSent = true;
|
|
556
|
+
let emailError;
|
|
557
|
+
const reset = core.requestPasswordReset({ email });
|
|
558
|
+
if (reset.token) {
|
|
559
|
+
const delivery = await deliverAuthEmail('password-reset', email, reset.token, req);
|
|
560
|
+
emailSent = delivery.ok;
|
|
561
|
+
emailError = delivery.error;
|
|
562
|
+
}
|
|
563
|
+
auditAuthAction(req, 'auth-password-reset-request', {
|
|
564
|
+
email,
|
|
565
|
+
emailSent
|
|
566
|
+
});
|
|
567
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
568
|
+
res.end(JSON.stringify({
|
|
569
|
+
success: true,
|
|
570
|
+
emailSent,
|
|
571
|
+
emailError,
|
|
572
|
+
resetToken: shouldExposeDevAuthTokens() ? (reset.token || null) : undefined
|
|
573
|
+
}));
|
|
574
|
+
}
|
|
575
|
+
catch (error) {
|
|
576
|
+
auditAuthAction(req, 'auth-password-reset-request-failed', {
|
|
577
|
+
email,
|
|
578
|
+
statusCode: resolveErrorStatusCode(error, 400)
|
|
579
|
+
});
|
|
580
|
+
res.writeHead(resolveErrorStatusCode(error, 400), { 'Content-Type': 'application/json' });
|
|
581
|
+
res.end(JSON.stringify({ success: false, error: String(error?.message || 'Unable to request password reset') }));
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
// POST /api/taskforce/auth/password-reset/confirm - Reset password using one-time token
|
|
585
|
+
addRoute('POST', '/api/taskforce/auth/password-reset/confirm', async (req, res) => {
|
|
586
|
+
if (!requireCloudRuntime(res, 'Authentication'))
|
|
587
|
+
return;
|
|
588
|
+
const body = await parseJsonBody(req);
|
|
589
|
+
const token = String(body?.token || '').trim();
|
|
590
|
+
const password = String(body?.password || '');
|
|
591
|
+
if (!token || !password) {
|
|
592
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
593
|
+
res.end(JSON.stringify({ success: false, error: 'Token and password are required.' }));
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
try {
|
|
597
|
+
const updated = core.resetPasswordWithToken({ token, password });
|
|
598
|
+
if (!updated) {
|
|
599
|
+
auditAuthAction(req, 'auth-password-reset-confirm-failed', {
|
|
600
|
+
tokenProvided: true
|
|
601
|
+
});
|
|
602
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
603
|
+
res.end(JSON.stringify({ success: false, error: 'Invalid or expired token.' }));
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
auditAuthAction(req, 'auth-password-reset-confirm-success', {
|
|
607
|
+
tokenProvided: true
|
|
608
|
+
});
|
|
609
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
610
|
+
res.end(JSON.stringify({ success: true }));
|
|
611
|
+
}
|
|
612
|
+
catch (error) {
|
|
613
|
+
auditAuthAction(req, 'auth-password-reset-confirm-failed', {
|
|
614
|
+
tokenProvided: true,
|
|
615
|
+
statusCode: resolveErrorStatusCode(error, 400)
|
|
616
|
+
});
|
|
617
|
+
res.writeHead(resolveErrorStatusCode(error, 400), { 'Content-Type': 'application/json' });
|
|
618
|
+
res.end(JSON.stringify({ success: false, error: String(error?.message || 'Unable to reset password') }));
|
|
619
|
+
}
|
|
620
|
+
});
|
|
621
|
+
// === SECTION: Invite flows ===
|
|
622
|
+
// POST /api/taskforce/auth/invite/inspect - Inspect invite acceptance token
|
|
623
|
+
addRoute('POST', '/api/taskforce/auth/invite/inspect', async (req, res) => {
|
|
624
|
+
if (!requireCloudRuntime(res, 'Authentication'))
|
|
625
|
+
return;
|
|
626
|
+
const body = await parseJsonBody(req);
|
|
627
|
+
const token = String(body?.token || '').trim();
|
|
628
|
+
if (!token) {
|
|
629
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
630
|
+
res.end(JSON.stringify({ success: false, error: 'Token is required.' }));
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
const details = core.inspectInviteAcceptance(token);
|
|
634
|
+
if (details.state === 'missing' || details.state === 'used' || details.state === 'expired' || details.state === 'revoked') {
|
|
635
|
+
auditAuthAction(req, details.state === 'expired' ? 'auth-invite-opened-expired' : 'auth-invite-opened-invalid', {
|
|
636
|
+
state: details.state
|
|
637
|
+
});
|
|
638
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
639
|
+
res.end(JSON.stringify({ success: false, state: details.state, error: 'Invalid or expired invite token.' }));
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
auditAuthAction(req, 'auth-invite-opened', {
|
|
643
|
+
userId: details.userId,
|
|
644
|
+
email: details.email,
|
|
645
|
+
workspaceId: details.workspaceId,
|
|
646
|
+
inviteeKind: details.inviteeKind,
|
|
647
|
+
passwordRequired: details.passwordRequired === true
|
|
648
|
+
});
|
|
649
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
650
|
+
res.end(JSON.stringify({
|
|
651
|
+
success: true,
|
|
652
|
+
state: details.state,
|
|
653
|
+
email: details.email,
|
|
654
|
+
workspaceId: details.workspaceId,
|
|
655
|
+
inviteeKind: details.inviteeKind,
|
|
656
|
+
passwordRequired: details.passwordRequired === true
|
|
657
|
+
}));
|
|
658
|
+
});
|
|
659
|
+
// POST /api/taskforce/auth/invite/accept - Accept invite token and set password
|
|
660
|
+
addRoute('POST', '/api/taskforce/auth/invite/accept', async (req, res) => {
|
|
661
|
+
if (!requireCloudRuntime(res, 'Authentication'))
|
|
662
|
+
return;
|
|
663
|
+
const authConfig = context.authConfig;
|
|
664
|
+
if (!authConfig) {
|
|
665
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
666
|
+
res.end(JSON.stringify({ success: false, error: 'Auth context unavailable.' }));
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
if (!authConfig.enabled) {
|
|
670
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
671
|
+
res.end(JSON.stringify({ success: false, error: 'Auth is not enabled.' }));
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
const body = await parseJsonBody(req);
|
|
675
|
+
const token = String(body?.token || '').trim();
|
|
676
|
+
const password = String(body?.password || '');
|
|
677
|
+
if (!token || !password) {
|
|
678
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
679
|
+
res.end(JSON.stringify({ success: false, error: 'Token and password are required.' }));
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
try {
|
|
683
|
+
const accepted = core.acceptInviteWithToken({ token, password });
|
|
684
|
+
const cookie = createSessionTokenCookie(`pwd:${accepted.userId}`, authConfig, {
|
|
685
|
+
role: accepted.role,
|
|
686
|
+
workspaceId: accepted.workspaceId,
|
|
687
|
+
userId: accepted.userId,
|
|
688
|
+
...resolveSessionCookieAttributesForRequest(req, authConfig)
|
|
689
|
+
});
|
|
690
|
+
res.setHeader('Set-Cookie', cookie);
|
|
691
|
+
auditAuthAction(req, 'auth-invite-accepted', {
|
|
692
|
+
userId: accepted.userId,
|
|
693
|
+
email: accepted.email,
|
|
694
|
+
workspaceId: accepted.workspaceId,
|
|
695
|
+
role: accepted.role
|
|
696
|
+
});
|
|
697
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
698
|
+
res.end(JSON.stringify({ success: true, workspaceId: accepted.workspaceId }));
|
|
699
|
+
}
|
|
700
|
+
catch (error) {
|
|
701
|
+
const statusCode = resolveErrorStatusCode(error, 400);
|
|
702
|
+
auditAuthAction(req, error?.code === 'INVITE_TOKEN_EXPIRED' ? 'auth-invite-accept-expired' : 'auth-invite-accept-failed', {
|
|
703
|
+
code: error?.code || 'INVITE_ACCEPT_FAILED',
|
|
704
|
+
statusCode
|
|
705
|
+
});
|
|
706
|
+
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
707
|
+
res.end(JSON.stringify({ success: false, error: String(error?.message || 'Unable to accept invite'), code: error?.code }));
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
// POST /api/taskforce/auth/invite/join - Accept invite token for existing authenticated users.
|
|
711
|
+
addRoute('POST', '/api/taskforce/auth/invite/join', async (req, res) => {
|
|
712
|
+
if (!requireCloudRuntime(res, 'Authentication'))
|
|
713
|
+
return;
|
|
714
|
+
const authConfig = context.authConfig;
|
|
715
|
+
if (!authConfig) {
|
|
716
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
717
|
+
res.end(JSON.stringify({ success: false, error: 'Auth context unavailable.' }));
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
if (!authConfig.enabled) {
|
|
721
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
722
|
+
res.end(JSON.stringify({ success: false, error: 'Auth is not enabled.' }));
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
const access = resolveRequestAccess(req, authConfig);
|
|
726
|
+
if (!access.authenticated || !access.userId || access.userId === 'anonymous') {
|
|
727
|
+
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
728
|
+
res.end(JSON.stringify({ success: false, error: 'Authentication required.', code: 'AUTH_REQUIRED' }));
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
const body = await parseJsonBody(req);
|
|
732
|
+
const token = String(body?.token || '').trim();
|
|
733
|
+
if (!token) {
|
|
734
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
735
|
+
res.end(JSON.stringify({ success: false, error: 'Token is required.', code: 'TOKEN_REQUIRED' }));
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
try {
|
|
739
|
+
const accepted = core.joinInviteWithAuthenticatedUser({ token, userId: access.userId });
|
|
740
|
+
const sessionId = String(access.sessionId || `pwd:${accepted.userId}`).trim() || `pwd:${accepted.userId}`;
|
|
741
|
+
const cookie = createSessionTokenCookie(sessionId, authConfig, {
|
|
742
|
+
role: accepted.role,
|
|
743
|
+
workspaceId: accepted.workspaceId,
|
|
744
|
+
userId: accepted.userId,
|
|
745
|
+
...resolveSessionCookieAttributesForRequest(req, authConfig)
|
|
746
|
+
});
|
|
747
|
+
res.setHeader('Set-Cookie', cookie);
|
|
748
|
+
auditAuthAction(req, 'auth-invite-joined', {
|
|
749
|
+
userId: accepted.userId,
|
|
750
|
+
email: accepted.email,
|
|
751
|
+
workspaceId: accepted.workspaceId,
|
|
752
|
+
role: accepted.role
|
|
753
|
+
});
|
|
754
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
755
|
+
res.end(JSON.stringify({ success: true, workspaceId: accepted.workspaceId }));
|
|
756
|
+
}
|
|
757
|
+
catch (error) {
|
|
758
|
+
const statusCode = resolveErrorStatusCode(error, 400);
|
|
759
|
+
auditAuthAction(req, 'auth-invite-join-failed', {
|
|
760
|
+
code: error?.code || 'INVITE_JOIN_FAILED',
|
|
761
|
+
statusCode
|
|
762
|
+
});
|
|
763
|
+
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
764
|
+
res.end(JSON.stringify({ success: false, error: String(error?.message || 'Unable to join invite'), code: error?.code }));
|
|
765
|
+
}
|
|
766
|
+
});
|
|
767
|
+
// === SECTION: Logout ===
|
|
768
|
+
// POST /api/taskforce/auth/logout - Clear auth session cookie
|
|
769
|
+
addRoute('POST', '/api/taskforce/auth/logout', async (req, res) => {
|
|
770
|
+
if (!requireCloudRuntime(res, 'Authentication'))
|
|
771
|
+
return;
|
|
772
|
+
const authConfig = context.authConfig;
|
|
773
|
+
if (!authConfig) {
|
|
774
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
775
|
+
res.end(JSON.stringify({ success: false, error: 'Auth context unavailable.' }));
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
const cookieName = authConfig.sessionCookieName || 'taskforce_session';
|
|
779
|
+
const attrs = resolveSessionCookieAttributesForRequest(req, authConfig);
|
|
780
|
+
const sameSite = attrs.sameSite || 'Lax';
|
|
781
|
+
const securePart = attrs.secure ? '; Secure' : '';
|
|
782
|
+
const clearBase = `${cookieName}=; Path=/; HttpOnly; SameSite=${sameSite}; Max-Age=0${securePart}`;
|
|
783
|
+
const hostRaw = String(req.headers['x-forwarded-host'] || req.headers.host || '').trim();
|
|
784
|
+
const host = hostRaw.split(',')[0]?.trim().split(':')[0]?.trim().toLowerCase() || '';
|
|
785
|
+
const domains = new Set();
|
|
786
|
+
if (authConfig.sessionCookieDomain)
|
|
787
|
+
domains.add(authConfig.sessionCookieDomain);
|
|
788
|
+
if (host) {
|
|
789
|
+
domains.add(host);
|
|
790
|
+
const parts = host.split('.').filter(Boolean);
|
|
791
|
+
if (parts.length >= 2) {
|
|
792
|
+
const parent = `.${parts.slice(-2).join('.')}`;
|
|
793
|
+
domains.add(parent);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
const clearCookies = [createClearSessionCookie(authConfig, attrs), clearBase];
|
|
797
|
+
for (const domain of domains) {
|
|
798
|
+
clearCookies.push(`${clearBase}; Domain=${domain}`);
|
|
799
|
+
}
|
|
800
|
+
res.setHeader('Set-Cookie', [...new Set(clearCookies)]);
|
|
801
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
802
|
+
res.end(JSON.stringify({ success: true }));
|
|
803
|
+
});
|
|
804
|
+
// === SECTION: Account access and entitlements ===
|
|
805
|
+
// GET /api/taskforce/account/access-status - Resolve whether the signed-in account can enter the app or must pick a plan first.
|
|
806
|
+
addRoute('GET', '/api/taskforce/account/access-status', async (req, res) => {
|
|
807
|
+
if (!ensureAuthenticatedUser(req)) {
|
|
808
|
+
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
809
|
+
res.end(JSON.stringify({ error: 'Authentication required.' }));
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
try {
|
|
813
|
+
const userId = requestUserId(req);
|
|
814
|
+
const payload = core.getAccountAccessStatus(userId);
|
|
815
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
816
|
+
res.end(JSON.stringify(payload));
|
|
817
|
+
}
|
|
818
|
+
catch (error) {
|
|
819
|
+
const statusCode = resolveErrorStatusCode(error, 400);
|
|
820
|
+
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
821
|
+
res.end(JSON.stringify({ error: String(error?.message || 'Unable to resolve account access status'), code: error?.code, details: error?.details }));
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
// GET /api/taskforce/account/entitlements - Resolve effective plan/features for the active workspace.
|
|
825
|
+
addRoute('GET', '/api/taskforce/account/entitlements', async (req, res) => {
|
|
826
|
+
if (!ensureAuthenticatedUser(req)) {
|
|
827
|
+
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
828
|
+
res.end(JSON.stringify({ error: 'Authentication required.' }));
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
try {
|
|
832
|
+
const wid = requestWorkspaceId(req);
|
|
833
|
+
const userId = requestUserId(req);
|
|
834
|
+
const payload = core.getAccountEntitlementsPayload({ userId, workspaceId: wid });
|
|
835
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
836
|
+
res.end(JSON.stringify(payload));
|
|
837
|
+
}
|
|
838
|
+
catch (error) {
|
|
839
|
+
if (error?.code === 'ENTITLEMENT_NOT_FOUND') {
|
|
840
|
+
const access = core.getAccountAccessStatus(requestUserId(req));
|
|
841
|
+
if (access.gate === 'plan_selection_required') {
|
|
842
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
843
|
+
res.end(JSON.stringify({
|
|
844
|
+
error: access.message,
|
|
845
|
+
code: 'PLAN_SELECTION_REQUIRED',
|
|
846
|
+
details: {
|
|
847
|
+
gate: access.gate,
|
|
848
|
+
planSelectionRequired: access.planSelectionRequired,
|
|
849
|
+
canAccessPlans: access.canAccessPlans
|
|
850
|
+
}
|
|
851
|
+
}));
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
const statusCode = resolveErrorStatusCode(error, 400);
|
|
856
|
+
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
857
|
+
res.end(JSON.stringify({ error: String(error?.message || 'Unable to resolve entitlements'), code: error?.code, details: error?.details }));
|
|
858
|
+
}
|
|
859
|
+
});
|
|
860
|
+
// GET /api/taskforce/account/plan-preview - Read-only payload for upgrade/support CTAs.
|
|
861
|
+
addRoute('GET', '/api/taskforce/account/plan-preview', async (req, res) => {
|
|
862
|
+
if (!ensureCloudPlanData(req, res))
|
|
863
|
+
return;
|
|
864
|
+
if (!ensureAuthenticatedUser(req)) {
|
|
865
|
+
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
866
|
+
res.end(JSON.stringify({ error: 'Authentication required.' }));
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
try {
|
|
870
|
+
const wid = requestWorkspaceId(req);
|
|
871
|
+
const userId = requestUserId(req);
|
|
872
|
+
const payload = core.getAccountEntitlementsPayload({ userId, workspaceId: wid });
|
|
873
|
+
const canInvite = Boolean(payload?.features?.['collaboration.invites']?.allowed);
|
|
874
|
+
const seatUsage = payload.seatUsage || { used: 0, limit: null, remaining: null };
|
|
875
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
876
|
+
res.end(JSON.stringify({
|
|
877
|
+
currentPlan: payload.planId,
|
|
878
|
+
state: payload.state,
|
|
879
|
+
seatUsage,
|
|
880
|
+
upgradeHints: canInvite
|
|
881
|
+
? []
|
|
882
|
+
: ['Team management requires a TEAM plan in active/trialing/grace state.'],
|
|
883
|
+
supportLink: 'mailto:support@taskforcehq.ai'
|
|
884
|
+
}));
|
|
885
|
+
}
|
|
886
|
+
catch (error) {
|
|
887
|
+
const statusCode = resolveErrorStatusCode(error, 400);
|
|
888
|
+
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
889
|
+
res.end(JSON.stringify({ error: String(error?.message || 'Unable to build plan preview'), code: error?.code, details: error?.details }));
|
|
890
|
+
}
|
|
891
|
+
});
|
|
892
|
+
// === SECTION: Workspace team management (workspace admin) ===
|
|
893
|
+
// GET /api/taskforce/auth/workspace-members - Auth-backed workspace member list for local runtime identity hydration.
|
|
894
|
+
addRoute('GET', '/api/taskforce/auth/workspace-members', async (req, res) => {
|
|
895
|
+
if (!ensureAppAccess(req, res))
|
|
896
|
+
return;
|
|
897
|
+
if (context.authConfig?.runtimeMode === 'cloud' && context.authConfig?.enabled && !ensureAuthenticatedUser(req)) {
|
|
898
|
+
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
899
|
+
res.end(JSON.stringify({ error: 'Authentication required.' }));
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
const wid = requestWorkspaceId(req);
|
|
903
|
+
const users = core.listWorkspaceUsers(wid);
|
|
904
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
905
|
+
res.end(JSON.stringify({ users }));
|
|
906
|
+
});
|
|
907
|
+
// GET /api/taskforce/workspace/assignee-options - Read active workspace humans and registered AI collaborators for task assignee selection.
|
|
908
|
+
addRoute('GET', '/api/taskforce/workspace/assignee-options', async (req, res) => {
|
|
909
|
+
if (!ensureAppAccess(req, res))
|
|
910
|
+
return;
|
|
911
|
+
if (context.authConfig?.runtimeMode === 'cloud' && context.authConfig?.enabled && !ensureAuthenticatedUser(req)) {
|
|
912
|
+
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
913
|
+
res.end(JSON.stringify({ error: 'Authentication required.' }));
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
const wid = requestWorkspaceId(req);
|
|
917
|
+
const includeProfileToken = context.authConfig?.enabled !== true || ensureWorkspaceAdminRole(req);
|
|
918
|
+
const workspaceUsers = core
|
|
919
|
+
.listWorkspaceUsers(wid)
|
|
920
|
+
.filter((user) => String(user.status || '').trim().toLowerCase() === 'active' && user.disabled !== true)
|
|
921
|
+
.map((user) => ({
|
|
922
|
+
value: user.userId,
|
|
923
|
+
label: String(user.displayName || user.email || user.userId).trim() || user.userId,
|
|
924
|
+
icon: 'User',
|
|
925
|
+
color: '#22c55e',
|
|
926
|
+
kind: 'member',
|
|
927
|
+
userId: user.userId,
|
|
928
|
+
email: user.email,
|
|
929
|
+
displayName: user.displayName ?? null,
|
|
930
|
+
status: user.status,
|
|
931
|
+
disabled: user.disabled === true
|
|
932
|
+
}));
|
|
933
|
+
const aiProfiles = core
|
|
934
|
+
.listAiProfiles(wid)
|
|
935
|
+
.map((profile) => ({
|
|
936
|
+
value: profile.id,
|
|
937
|
+
label: profile.name,
|
|
938
|
+
...(includeProfileToken ? { profileToken: profile.profileToken } : {}),
|
|
939
|
+
username: profile.username,
|
|
940
|
+
icon: profile.icon,
|
|
941
|
+
color: profile.color,
|
|
942
|
+
kind: 'agent',
|
|
943
|
+
description: profile.description ?? null,
|
|
944
|
+
role: profile.role ?? null,
|
|
945
|
+
provider: profile.provider ?? null,
|
|
946
|
+
model: profile.model ?? null,
|
|
947
|
+
surfaceType: profile.surfaceType ?? null,
|
|
948
|
+
createdAt: profile.createdAt,
|
|
949
|
+
updatedAt: profile.updatedAt,
|
|
950
|
+
lastActiveAt: profile.lastActiveAt ?? null
|
|
951
|
+
}));
|
|
952
|
+
const assignees = [...workspaceUsers, ...aiProfiles];
|
|
953
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
954
|
+
res.end(JSON.stringify({ assignees }));
|
|
955
|
+
});
|
|
956
|
+
// POST /api/taskforce/workspace/ai-profiles/merge - Merge a duplicate AI profile into another, reassigning all references.
|
|
957
|
+
addRoute('POST', '/api/taskforce/workspace/ai-profiles/merge', async (req, res) => {
|
|
958
|
+
if (!ensureWorkspaceAdminRole(req)) {
|
|
959
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
960
|
+
res.end(JSON.stringify({ error: 'Forbidden: owner or admin role required.' }));
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
const body = await parseJsonBody(req);
|
|
964
|
+
const wid = requestWorkspaceId(req);
|
|
965
|
+
const keepId = String(body.keepId || '').trim();
|
|
966
|
+
const mergeId = String(body.mergeId || '').trim();
|
|
967
|
+
if (!keepId || !mergeId) {
|
|
968
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
969
|
+
res.end(JSON.stringify({ error: 'keepId and mergeId are required.' }));
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
try {
|
|
973
|
+
const profile = core.mergeAiProfiles({ workspaceId: wid, keepId, mergeId });
|
|
974
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
975
|
+
res.end(JSON.stringify({ profile }));
|
|
976
|
+
}
|
|
977
|
+
catch (err) {
|
|
978
|
+
const status = err?.statusCode ?? 500;
|
|
979
|
+
res.writeHead(status, { 'Content-Type': 'application/json' });
|
|
980
|
+
res.end(JSON.stringify({ error: err?.message ?? 'Merge failed.' }));
|
|
981
|
+
}
|
|
982
|
+
});
|
|
983
|
+
// GET /api/taskforce/admin/users - List workspace users for team management.
|
|
984
|
+
addRoute('GET', '/api/taskforce/admin/users', async (req, res) => {
|
|
985
|
+
if (!ensureWorkspaceAdminRole(req)) {
|
|
986
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
987
|
+
res.end(JSON.stringify({ error: 'Forbidden: owner or admin role required.' }));
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
990
|
+
const wid = requestWorkspaceId(req);
|
|
991
|
+
const gate = core.evaluateFeatureAccess({
|
|
992
|
+
userId: requestUserId(req),
|
|
993
|
+
workspaceId: wid,
|
|
994
|
+
featureKey: 'collaboration.team_management'
|
|
995
|
+
});
|
|
996
|
+
if (!gate.allowed) {
|
|
997
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
998
|
+
res.end(JSON.stringify({ error: 'Team management is unavailable for this account entitlement.', code: gate.reasonCode }));
|
|
999
|
+
return;
|
|
1000
|
+
}
|
|
1001
|
+
const users = core.listWorkspaceUsers(wid);
|
|
1002
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
1003
|
+
res.end(JSON.stringify({ users }));
|
|
1004
|
+
});
|
|
1005
|
+
// POST /api/taskforce/admin/users/invite - Invite a user into a workspace.
|
|
1006
|
+
addRoute('POST', '/api/taskforce/admin/users/invite', async (req, res) => {
|
|
1007
|
+
if (!ensureWorkspaceAdminRole(req)) {
|
|
1008
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
1009
|
+
res.end(JSON.stringify({ error: 'Forbidden: owner or admin role required.' }));
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
const body = await parseJsonBody(req);
|
|
1013
|
+
const wid = String(body?.workspaceId || requestWorkspaceId(req)).trim() || 'default';
|
|
1014
|
+
const email = String(body?.email || '').trim().toLowerCase();
|
|
1015
|
+
const role = String(body?.role || 'member').trim().toLowerCase();
|
|
1016
|
+
const permissionMode = String(body?.permissionMode || 'read-write').trim().toLowerCase();
|
|
1017
|
+
if (!email || !email.includes('@')) {
|
|
1018
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
1019
|
+
res.end(JSON.stringify({ error: 'Valid email is required.' }));
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
const inviteGate = core.evaluateFeatureAccess({
|
|
1023
|
+
userId: requestUserId(req),
|
|
1024
|
+
workspaceId: wid,
|
|
1025
|
+
featureKey: 'collaboration.invites'
|
|
1026
|
+
});
|
|
1027
|
+
if (!inviteGate.allowed) {
|
|
1028
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
1029
|
+
res.end(JSON.stringify({ error: 'Invites are unavailable for this account entitlement.', code: inviteGate.reasonCode }));
|
|
1030
|
+
return;
|
|
1031
|
+
}
|
|
1032
|
+
try {
|
|
1033
|
+
const invited = core.inviteWorkspaceUser({
|
|
1034
|
+
workspaceId: wid,
|
|
1035
|
+
email,
|
|
1036
|
+
role: role === 'owner' || role === 'admin' ? role : 'member'
|
|
1037
|
+
});
|
|
1038
|
+
if (role === 'member') {
|
|
1039
|
+
core.setWorkspaceUserPermissionMode(invited.userId, wid, permissionMode === 'read-only' ? 'read-only' : 'read-write');
|
|
1040
|
+
}
|
|
1041
|
+
const inviteToken = core.requestInviteAcceptance({ userId: invited.userId, workspaceId: wid });
|
|
1042
|
+
let inviteEmailSent = true;
|
|
1043
|
+
let inviteEmailError = null;
|
|
1044
|
+
if (inviteToken.token) {
|
|
1045
|
+
const workspace = core.getWorkspaceProfile(wid);
|
|
1046
|
+
const actorIdentity = core.resolveUserIdentity(requestUserId(req));
|
|
1047
|
+
const inviterEmailOrLabel = String(actorIdentity?.email || requestUserId(req) || 'Taskforce').trim();
|
|
1048
|
+
const delivery = await deliverInviteEmail(email, inviteToken.token, req, {
|
|
1049
|
+
workspaceName: String(workspace?.name || wid),
|
|
1050
|
+
inviterEmailOrLabel
|
|
1051
|
+
});
|
|
1052
|
+
inviteEmailSent = delivery.ok;
|
|
1053
|
+
inviteEmailError = delivery.ok ? null : String(delivery.error || 'INVITE_EMAIL_FAILED');
|
|
1054
|
+
}
|
|
1055
|
+
auditAuthAction(req, 'invite-user', {
|
|
1056
|
+
workspaceId: wid,
|
|
1057
|
+
invitedUserId: invited.userId,
|
|
1058
|
+
email,
|
|
1059
|
+
role,
|
|
1060
|
+
permissionMode: role === 'member' ? (permissionMode === 'read-only' ? 'read-only' : 'read-write') : 'read-write',
|
|
1061
|
+
inviteEmailSent
|
|
1062
|
+
});
|
|
1063
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
1064
|
+
res.end(JSON.stringify({
|
|
1065
|
+
success: true,
|
|
1066
|
+
user: core.listWorkspaceUsers(wid).find((item) => item.userId === invited.userId) || invited,
|
|
1067
|
+
inviteEmailSent,
|
|
1068
|
+
inviteEmailError
|
|
1069
|
+
}));
|
|
1070
|
+
}
|
|
1071
|
+
catch (error) {
|
|
1072
|
+
const statusCode = resolveErrorStatusCode(error, 400);
|
|
1073
|
+
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
1074
|
+
res.end(JSON.stringify({ error: String(error?.message || 'Unable to invite user'), code: error?.code, details: error?.details }));
|
|
1075
|
+
}
|
|
1076
|
+
});
|
|
1077
|
+
// PATCH /api/taskforce/admin/users/:id/role - Update workspace role for a user.
|
|
1078
|
+
addRoute('PATCH', '/api/taskforce/admin/users/:id/role', async (req, res, params) => {
|
|
1079
|
+
if (!ensureWorkspaceAdminRole(req)) {
|
|
1080
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
1081
|
+
res.end(JSON.stringify({ error: 'Forbidden: owner or admin role required.' }));
|
|
1082
|
+
return;
|
|
1083
|
+
}
|
|
1084
|
+
const body = await parseJsonBody(req);
|
|
1085
|
+
const wid = String(body?.workspaceId || requestWorkspaceId(req)).trim() || 'default';
|
|
1086
|
+
const role = String(body?.role || '').trim().toLowerCase();
|
|
1087
|
+
if (role !== 'owner' && role !== 'admin' && role !== 'member') {
|
|
1088
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
1089
|
+
res.end(JSON.stringify({ error: 'role must be owner, admin, or member' }));
|
|
1090
|
+
return;
|
|
1091
|
+
}
|
|
1092
|
+
const gate = core.evaluateFeatureAccess({
|
|
1093
|
+
userId: requestUserId(req),
|
|
1094
|
+
workspaceId: wid,
|
|
1095
|
+
featureKey: 'collaboration.team_management'
|
|
1096
|
+
});
|
|
1097
|
+
if (!gate.allowed) {
|
|
1098
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
1099
|
+
res.end(JSON.stringify({ error: 'Team management is unavailable for this account entitlement.', code: gate.reasonCode }));
|
|
1100
|
+
return;
|
|
1101
|
+
}
|
|
1102
|
+
try {
|
|
1103
|
+
const success = core.updateWorkspaceUserRole(params.id, wid, role);
|
|
1104
|
+
if (!success) {
|
|
1105
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
1106
|
+
res.end(JSON.stringify({ error: 'User membership not found.' }));
|
|
1107
|
+
return;
|
|
1108
|
+
}
|
|
1109
|
+
auditAuthAction(req, 'update-workspace-user-role', { workspaceId: wid, targetUserId: params.id, role });
|
|
1110
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
1111
|
+
res.end(JSON.stringify({ success: true }));
|
|
1112
|
+
}
|
|
1113
|
+
catch (error) {
|
|
1114
|
+
const statusCode = resolveErrorStatusCode(error, 400);
|
|
1115
|
+
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
1116
|
+
res.end(JSON.stringify({ error: String(error?.message || 'Unable to update role'), code: error?.code }));
|
|
1117
|
+
}
|
|
1118
|
+
});
|
|
1119
|
+
// PATCH /api/taskforce/admin/users/:id/permission-mode - Update member permission mode.
|
|
1120
|
+
addRoute('PATCH', '/api/taskforce/admin/users/:id/permission-mode', async (req, res, params) => {
|
|
1121
|
+
if (!ensureWorkspaceAdminRole(req)) {
|
|
1122
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
1123
|
+
res.end(JSON.stringify({ error: 'Forbidden: owner or admin role required.' }));
|
|
1124
|
+
return;
|
|
1125
|
+
}
|
|
1126
|
+
const body = await parseJsonBody(req);
|
|
1127
|
+
const wid = String(body?.workspaceId || requestWorkspaceId(req)).trim() || 'default';
|
|
1128
|
+
const mode = String(body?.mode || '').trim().toLowerCase();
|
|
1129
|
+
if (mode !== 'read-only' && mode !== 'read-write') {
|
|
1130
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
1131
|
+
res.end(JSON.stringify({ error: 'mode must be read-only or read-write' }));
|
|
1132
|
+
return;
|
|
1133
|
+
}
|
|
1134
|
+
const gate = core.evaluateFeatureAccess({
|
|
1135
|
+
userId: requestUserId(req),
|
|
1136
|
+
workspaceId: wid,
|
|
1137
|
+
featureKey: 'collaboration.team_management'
|
|
1138
|
+
});
|
|
1139
|
+
if (!gate.allowed) {
|
|
1140
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
1141
|
+
res.end(JSON.stringify({ error: 'Team management is unavailable for this account entitlement.', code: gate.reasonCode }));
|
|
1142
|
+
return;
|
|
1143
|
+
}
|
|
1144
|
+
try {
|
|
1145
|
+
const success = core.setWorkspaceUserPermissionMode(params.id, wid, mode);
|
|
1146
|
+
if (!success) {
|
|
1147
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
1148
|
+
res.end(JSON.stringify({ error: 'User membership not found.' }));
|
|
1149
|
+
return;
|
|
1150
|
+
}
|
|
1151
|
+
auditAuthAction(req, 'update-workspace-user-permission-mode', { workspaceId: wid, targetUserId: params.id, mode });
|
|
1152
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
1153
|
+
res.end(JSON.stringify({ success: true }));
|
|
1154
|
+
}
|
|
1155
|
+
catch (error) {
|
|
1156
|
+
const statusCode = resolveErrorStatusCode(error, 400);
|
|
1157
|
+
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
1158
|
+
res.end(JSON.stringify({ error: String(error?.message || 'Unable to update permission mode'), code: error?.code }));
|
|
1159
|
+
}
|
|
1160
|
+
});
|
|
1161
|
+
// PATCH /api/taskforce/admin/users/:id/disable - Disable or reactivate a workspace user.
|
|
1162
|
+
addRoute('PATCH', '/api/taskforce/admin/users/:id/disable', async (req, res, params) => {
|
|
1163
|
+
if (!ensureWorkspaceAdminRole(req)) {
|
|
1164
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
1165
|
+
res.end(JSON.stringify({ error: 'Forbidden: owner or admin role required.' }));
|
|
1166
|
+
return;
|
|
1167
|
+
}
|
|
1168
|
+
const body = await parseJsonBody(req);
|
|
1169
|
+
const wid = String(body?.workspaceId || requestWorkspaceId(req)).trim() || 'default';
|
|
1170
|
+
const disabled = body?.disabled === true;
|
|
1171
|
+
const gate = core.evaluateFeatureAccess({
|
|
1172
|
+
userId: requestUserId(req),
|
|
1173
|
+
workspaceId: wid,
|
|
1174
|
+
featureKey: 'collaboration.team_management'
|
|
1175
|
+
});
|
|
1176
|
+
if (!gate.allowed) {
|
|
1177
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
1178
|
+
res.end(JSON.stringify({ error: 'Team management is unavailable for this account entitlement.', code: gate.reasonCode }));
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
try {
|
|
1182
|
+
const success = core.setWorkspaceUserDisabled(params.id, wid, disabled);
|
|
1183
|
+
if (!success) {
|
|
1184
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
1185
|
+
res.end(JSON.stringify({ error: 'User membership not found.' }));
|
|
1186
|
+
return;
|
|
1187
|
+
}
|
|
1188
|
+
auditAuthAction(req, 'set-workspace-user-disabled', { workspaceId: wid, targetUserId: params.id, disabled });
|
|
1189
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
1190
|
+
res.end(JSON.stringify({ success: true }));
|
|
1191
|
+
}
|
|
1192
|
+
catch (error) {
|
|
1193
|
+
const statusCode = resolveErrorStatusCode(error, 400);
|
|
1194
|
+
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
1195
|
+
res.end(JSON.stringify({ error: String(error?.message || 'Unable to update disabled state'), code: error?.code }));
|
|
1196
|
+
}
|
|
1197
|
+
});
|
|
1198
|
+
// POST /api/taskforce/admin/users/:id/invite/revoke - Revoke invite acceptance token.
|
|
1199
|
+
addRoute('POST', '/api/taskforce/admin/users/:id/invite/revoke', async (req, res, params) => {
|
|
1200
|
+
if (!ensureWorkspaceAdminRole(req)) {
|
|
1201
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
1202
|
+
res.end(JSON.stringify({ error: 'Forbidden: owner or admin role required.' }));
|
|
1203
|
+
return;
|
|
1204
|
+
}
|
|
1205
|
+
const body = await parseJsonBody(req);
|
|
1206
|
+
const wid = String(body?.workspaceId || requestWorkspaceId(req)).trim() || 'default';
|
|
1207
|
+
const gate = core.evaluateFeatureAccess({
|
|
1208
|
+
userId: requestUserId(req),
|
|
1209
|
+
workspaceId: wid,
|
|
1210
|
+
featureKey: 'collaboration.team_management'
|
|
1211
|
+
});
|
|
1212
|
+
if (!gate.allowed) {
|
|
1213
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
1214
|
+
res.end(JSON.stringify({ error: 'Team management is unavailable for this account entitlement.', code: gate.reasonCode }));
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
const revoked = core.revokeInviteAcceptanceForUser(params.id);
|
|
1218
|
+
auditAuthAction(req, 'revoke-invite', { workspaceId: wid, targetUserId: params.id, revoked: revoked.revoked });
|
|
1219
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
1220
|
+
res.end(JSON.stringify({ success: true, revoked: revoked.revoked }));
|
|
1221
|
+
});
|
|
1222
|
+
// DELETE /api/taskforce/admin/users/:id - Remove workspace membership.
|
|
1223
|
+
addRoute('DELETE', '/api/taskforce/admin/users/:id', async (req, res, params) => {
|
|
1224
|
+
if (!ensureWorkspaceAdminRole(req)) {
|
|
1225
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
1226
|
+
res.end(JSON.stringify({ error: 'Forbidden: owner or admin role required.' }));
|
|
1227
|
+
return;
|
|
1228
|
+
}
|
|
1229
|
+
const reqUrl = new URL(req.url || '/api/taskforce/admin/users/:id', 'http://localhost');
|
|
1230
|
+
const wid = String(reqUrl.searchParams.get('workspaceId') || requestWorkspaceId(req)).trim() || 'default';
|
|
1231
|
+
const gate = core.evaluateFeatureAccess({
|
|
1232
|
+
userId: requestUserId(req),
|
|
1233
|
+
workspaceId: wid,
|
|
1234
|
+
featureKey: 'collaboration.team_management'
|
|
1235
|
+
});
|
|
1236
|
+
if (!gate.allowed) {
|
|
1237
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
1238
|
+
res.end(JSON.stringify({ error: 'Team management is unavailable for this account entitlement.', code: gate.reasonCode }));
|
|
1239
|
+
return;
|
|
1240
|
+
}
|
|
1241
|
+
try {
|
|
1242
|
+
const success = core.removeWorkspaceUser(params.id, wid);
|
|
1243
|
+
if (!success) {
|
|
1244
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
1245
|
+
res.end(JSON.stringify({ error: 'User membership not found.' }));
|
|
1246
|
+
return;
|
|
1247
|
+
}
|
|
1248
|
+
auditAuthAction(req, 'remove-workspace-user', { workspaceId: wid, targetUserId: params.id });
|
|
1249
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
1250
|
+
res.end(JSON.stringify({ success: true }));
|
|
1251
|
+
}
|
|
1252
|
+
catch (error) {
|
|
1253
|
+
const statusCode = resolveErrorStatusCode(error, 400);
|
|
1254
|
+
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
1255
|
+
res.end(JSON.stringify({ error: String(error?.message || 'Unable to remove user'), code: error?.code }));
|
|
1256
|
+
}
|
|
1257
|
+
});
|
|
1258
|
+
// GET /api/taskforce/admin/workspace-audit-logs - Read workspace-scoped admin audit events for team management.
|
|
1259
|
+
addRoute('GET', '/api/taskforce/admin/workspace-audit-logs', async (req, res) => {
|
|
1260
|
+
if (!ensureWorkspaceAdminRole(req)) {
|
|
1261
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
1262
|
+
res.end(JSON.stringify({ error: 'Forbidden: owner or admin role required.' }));
|
|
1263
|
+
return;
|
|
1264
|
+
}
|
|
1265
|
+
const wid = requestWorkspaceId(req);
|
|
1266
|
+
const gate = core.evaluateFeatureAccess({
|
|
1267
|
+
userId: requestUserId(req),
|
|
1268
|
+
workspaceId: wid,
|
|
1269
|
+
featureKey: 'collaboration.team_management'
|
|
1270
|
+
});
|
|
1271
|
+
if (!gate.allowed) {
|
|
1272
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
1273
|
+
res.end(JSON.stringify({ error: 'Team management is unavailable for this account entitlement.', code: gate.reasonCode }));
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
1276
|
+
const reqUrl = new URL(req.url || '/api/taskforce/admin/workspace-audit-logs', 'http://localhost');
|
|
1277
|
+
const limitRaw = Number(reqUrl.searchParams.get('limit') || '100');
|
|
1278
|
+
const offsetRaw = Number(reqUrl.searchParams.get('offset') || '0');
|
|
1279
|
+
const limit = Number.isFinite(limitRaw) ? Math.max(1, Math.min(500, Math.floor(limitRaw))) : 100;
|
|
1280
|
+
const offset = Number.isFinite(offsetRaw) ? Math.max(0, Math.floor(offsetRaw)) : 0;
|
|
1281
|
+
const events = core.listAdminAuditLogs(wid, limit, offset).map((event) => ({
|
|
1282
|
+
id: event.id,
|
|
1283
|
+
action: event.action,
|
|
1284
|
+
actorUserId: event.actorUserId,
|
|
1285
|
+
actorRole: event.actorRole,
|
|
1286
|
+
workspaceId: event.workspaceId,
|
|
1287
|
+
details: event.details,
|
|
1288
|
+
createdAt: event.ts
|
|
1289
|
+
}));
|
|
1290
|
+
const total = core.countAdminAuditLogs(wid);
|
|
1291
|
+
const page = Math.floor(offset / limit) + 1;
|
|
1292
|
+
const pages = Math.max(1, Math.ceil(total / limit));
|
|
1293
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
1294
|
+
res.end(JSON.stringify({ events, workspaceId: wid, limit, offset, total, page, pages }));
|
|
1295
|
+
});
|
|
1296
|
+
}
|