@agent-native/dispatch 0.1.1
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 +220 -0
- package/dist/actions/approve-dispatch-change.d.ts +3 -0
- package/dist/actions/approve-dispatch-change.d.ts.map +1 -0
- package/dist/actions/approve-dispatch-change.js +11 -0
- package/dist/actions/approve-dispatch-change.js.map +1 -0
- package/dist/actions/approve-vault-request.d.ts +3 -0
- package/dist/actions/approve-vault-request.d.ts.map +1 -0
- package/dist/actions/approve-vault-request.js +16 -0
- package/dist/actions/approve-vault-request.js.map +1 -0
- package/dist/actions/create-link-token.d.ts +3 -0
- package/dist/actions/create-link-token.d.ts.map +1 -0
- package/dist/actions/create-link-token.js +11 -0
- package/dist/actions/create-link-token.js.map +1 -0
- package/dist/actions/create-vault-grant.d.ts +3 -0
- package/dist/actions/create-vault-grant.d.ts.map +1 -0
- package/dist/actions/create-vault-grant.js +14 -0
- package/dist/actions/create-vault-grant.js.map +1 -0
- package/dist/actions/create-vault-secret.d.ts +3 -0
- package/dist/actions/create-vault-secret.d.ts.map +1 -0
- package/dist/actions/create-vault-secret.js +20 -0
- package/dist/actions/create-vault-secret.js.map +1 -0
- package/dist/actions/create-workspace-resource-grant.d.ts +3 -0
- package/dist/actions/create-workspace-resource-grant.d.ts.map +1 -0
- package/dist/actions/create-workspace-resource-grant.js +14 -0
- package/dist/actions/create-workspace-resource-grant.js.map +1 -0
- package/dist/actions/create-workspace-resource.d.ts +3 -0
- package/dist/actions/create-workspace-resource.d.ts.map +1 -0
- package/dist/actions/create-workspace-resource.js +24 -0
- package/dist/actions/create-workspace-resource.js.map +1 -0
- package/dist/actions/delete-destination.d.ts +3 -0
- package/dist/actions/delete-destination.d.ts.map +1 -0
- package/dist/actions/delete-destination.js +11 -0
- package/dist/actions/delete-destination.js.map +1 -0
- package/dist/actions/delete-vault-secret.d.ts +3 -0
- package/dist/actions/delete-vault-secret.d.ts.map +1 -0
- package/dist/actions/delete-vault-secret.js +11 -0
- package/dist/actions/delete-vault-secret.js.map +1 -0
- package/dist/actions/delete-workspace-resource.d.ts +3 -0
- package/dist/actions/delete-workspace-resource.d.ts.map +1 -0
- package/dist/actions/delete-workspace-resource.js +11 -0
- package/dist/actions/delete-workspace-resource.js.map +1 -0
- package/dist/actions/deny-vault-request.d.ts +3 -0
- package/dist/actions/deny-vault-request.d.ts.map +1 -0
- package/dist/actions/deny-vault-request.js +12 -0
- package/dist/actions/deny-vault-request.js.map +1 -0
- package/dist/actions/get-app-creation-settings.d.ts +3 -0
- package/dist/actions/get-app-creation-settings.d.ts.map +1 -0
- package/dist/actions/get-app-creation-settings.js +10 -0
- package/dist/actions/get-app-creation-settings.js.map +1 -0
- package/dist/actions/get-dispatch-settings.d.ts +3 -0
- package/dist/actions/get-dispatch-settings.d.ts.map +1 -0
- package/dist/actions/get-dispatch-settings.js +10 -0
- package/dist/actions/get-dispatch-settings.js.map +1 -0
- package/dist/actions/get-workspace-info.d.ts +3 -0
- package/dist/actions/get-workspace-info.d.ts.map +1 -0
- package/dist/actions/get-workspace-info.js +10 -0
- package/dist/actions/get-workspace-info.js.map +1 -0
- package/dist/actions/grant-vault-secrets-to-app.d.ts +3 -0
- package/dist/actions/grant-vault-secrets-to-app.d.ts.map +1 -0
- package/dist/actions/grant-vault-secrets-to-app.js +19 -0
- package/dist/actions/grant-vault-secrets-to-app.js.map +1 -0
- package/dist/actions/index.d.ts +9 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +101 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/actions/list-connected-agents.d.ts +3 -0
- package/dist/actions/list-connected-agents.d.ts.map +1 -0
- package/dist/actions/list-connected-agents.js +79 -0
- package/dist/actions/list-connected-agents.js.map +1 -0
- package/dist/actions/list-destinations.d.ts +3 -0
- package/dist/actions/list-destinations.d.ts.map +1 -0
- package/dist/actions/list-destinations.js +10 -0
- package/dist/actions/list-destinations.js.map +1 -0
- package/dist/actions/list-dispatch-approvals.d.ts +3 -0
- package/dist/actions/list-dispatch-approvals.d.ts.map +1 -0
- package/dist/actions/list-dispatch-approvals.js +10 -0
- package/dist/actions/list-dispatch-approvals.js.map +1 -0
- package/dist/actions/list-dispatch-audit.d.ts +3 -0
- package/dist/actions/list-dispatch-audit.d.ts.map +1 -0
- package/dist/actions/list-dispatch-audit.js +12 -0
- package/dist/actions/list-dispatch-audit.js.map +1 -0
- package/dist/actions/list-dispatch-overview.d.ts +3 -0
- package/dist/actions/list-dispatch-overview.d.ts.map +1 -0
- package/dist/actions/list-dispatch-overview.js +17 -0
- package/dist/actions/list-dispatch-overview.js.map +1 -0
- package/dist/actions/list-integrations-catalog.d.ts +3 -0
- package/dist/actions/list-integrations-catalog.d.ts.map +1 -0
- package/dist/actions/list-integrations-catalog.js +10 -0
- package/dist/actions/list-integrations-catalog.js.map +1 -0
- package/dist/actions/list-linked-identities.d.ts +3 -0
- package/dist/actions/list-linked-identities.d.ts.map +1 -0
- package/dist/actions/list-linked-identities.js +10 -0
- package/dist/actions/list-linked-identities.js.map +1 -0
- package/dist/actions/list-vault-audit.d.ts +3 -0
- package/dist/actions/list-vault-audit.d.ts.map +1 -0
- package/dist/actions/list-vault-audit.js +15 -0
- package/dist/actions/list-vault-audit.js.map +1 -0
- package/dist/actions/list-vault-grants.d.ts +3 -0
- package/dist/actions/list-vault-grants.d.ts.map +1 -0
- package/dist/actions/list-vault-grants.js +13 -0
- package/dist/actions/list-vault-grants.js.map +1 -0
- package/dist/actions/list-vault-requests.d.ts +3 -0
- package/dist/actions/list-vault-requests.d.ts.map +1 -0
- package/dist/actions/list-vault-requests.js +15 -0
- package/dist/actions/list-vault-requests.js.map +1 -0
- package/dist/actions/list-vault-secret-options.d.ts +3 -0
- package/dist/actions/list-vault-secret-options.d.ts.map +1 -0
- package/dist/actions/list-vault-secret-options.js +19 -0
- package/dist/actions/list-vault-secret-options.js.map +1 -0
- package/dist/actions/list-vault-secrets.d.ts +3 -0
- package/dist/actions/list-vault-secrets.d.ts.map +1 -0
- package/dist/actions/list-vault-secrets.js +25 -0
- package/dist/actions/list-vault-secrets.js.map +1 -0
- package/dist/actions/list-workspace-apps.d.ts +3 -0
- package/dist/actions/list-workspace-apps.d.ts.map +1 -0
- package/dist/actions/list-workspace-apps.js +24 -0
- package/dist/actions/list-workspace-apps.js.map +1 -0
- package/dist/actions/list-workspace-resource-grants.d.ts +3 -0
- package/dist/actions/list-workspace-resource-grants.d.ts.map +1 -0
- package/dist/actions/list-workspace-resource-grants.js +13 -0
- package/dist/actions/list-workspace-resource-grants.js.map +1 -0
- package/dist/actions/list-workspace-resources.d.ts +3 -0
- package/dist/actions/list-workspace-resources.d.ts.map +1 -0
- package/dist/actions/list-workspace-resources.js +15 -0
- package/dist/actions/list-workspace-resources.js.map +1 -0
- package/dist/actions/navigate.d.ts +16 -0
- package/dist/actions/navigate.d.ts.map +1 -0
- package/dist/actions/navigate.js +55 -0
- package/dist/actions/navigate.js.map +1 -0
- package/dist/actions/reject-dispatch-change.d.ts +3 -0
- package/dist/actions/reject-dispatch-change.d.ts.map +1 -0
- package/dist/actions/reject-dispatch-change.js +12 -0
- package/dist/actions/reject-dispatch-change.js.map +1 -0
- package/dist/actions/request-vault-secret.d.ts +3 -0
- package/dist/actions/request-vault-secret.d.ts.map +1 -0
- package/dist/actions/request-vault-secret.js +15 -0
- package/dist/actions/request-vault-secret.js.map +1 -0
- package/dist/actions/revoke-vault-grant.d.ts +3 -0
- package/dist/actions/revoke-vault-grant.d.ts.map +1 -0
- package/dist/actions/revoke-vault-grant.js +11 -0
- package/dist/actions/revoke-vault-grant.js.map +1 -0
- package/dist/actions/revoke-workspace-resource-grant.d.ts +3 -0
- package/dist/actions/revoke-workspace-resource-grant.d.ts.map +1 -0
- package/dist/actions/revoke-workspace-resource-grant.js +11 -0
- package/dist/actions/revoke-workspace-resource-grant.js.map +1 -0
- package/dist/actions/send-platform-message.d.ts +3 -0
- package/dist/actions/send-platform-message.d.ts.map +1 -0
- package/dist/actions/send-platform-message.js +73 -0
- package/dist/actions/send-platform-message.js.map +1 -0
- package/dist/actions/set-app-creation-settings.d.ts +3 -0
- package/dist/actions/set-app-creation-settings.d.ts.map +1 -0
- package/dist/actions/set-app-creation-settings.js +18 -0
- package/dist/actions/set-app-creation-settings.js.map +1 -0
- package/dist/actions/set-dispatch-approval-policy.d.ts +3 -0
- package/dist/actions/set-dispatch-approval-policy.d.ts.map +1 -0
- package/dist/actions/set-dispatch-approval-policy.js +19 -0
- package/dist/actions/set-dispatch-approval-policy.js.map +1 -0
- package/dist/actions/start-workspace-app-creation.d.ts +3 -0
- package/dist/actions/start-workspace-app-creation.d.ts.map +1 -0
- package/dist/actions/start-workspace-app-creation.js +31 -0
- package/dist/actions/start-workspace-app-creation.js.map +1 -0
- package/dist/actions/sync-vault-to-app.d.ts +3 -0
- package/dist/actions/sync-vault-to-app.d.ts.map +1 -0
- package/dist/actions/sync-vault-to-app.js +13 -0
- package/dist/actions/sync-vault-to-app.js.map +1 -0
- package/dist/actions/sync-workspace-resources-to-all.d.ts +3 -0
- package/dist/actions/sync-workspace-resources-to-all.d.ts.map +1 -0
- package/dist/actions/sync-workspace-resources-to-all.js +9 -0
- package/dist/actions/sync-workspace-resources-to-all.js.map +1 -0
- package/dist/actions/sync-workspace-resources-to-app.d.ts +3 -0
- package/dist/actions/sync-workspace-resources-to-app.d.ts.map +1 -0
- package/dist/actions/sync-workspace-resources-to-app.js +11 -0
- package/dist/actions/sync-workspace-resources-to-app.js.map +1 -0
- package/dist/actions/update-vault-secret.d.ts +3 -0
- package/dist/actions/update-vault-secret.d.ts.map +1 -0
- package/dist/actions/update-vault-secret.js +12 -0
- package/dist/actions/update-vault-secret.js.map +1 -0
- package/dist/actions/update-workspace-resource.d.ts +3 -0
- package/dist/actions/update-workspace-resource.d.ts.map +1 -0
- package/dist/actions/update-workspace-resource.js +18 -0
- package/dist/actions/update-workspace-resource.js.map +1 -0
- package/dist/actions/upsert-destination.d.ts +3 -0
- package/dist/actions/upsert-destination.d.ts.map +1 -0
- package/dist/actions/upsert-destination.js +26 -0
- package/dist/actions/upsert-destination.js.map +1 -0
- package/dist/actions/view-screen.d.ts +11 -0
- package/dist/actions/view-screen.d.ts.map +1 -0
- package/dist/actions/view-screen.js +68 -0
- package/dist/actions/view-screen.js.map +1 -0
- package/dist/components/agents-panel.d.ts +16 -0
- package/dist/components/agents-panel.d.ts.map +1 -0
- package/dist/components/agents-panel.js +64 -0
- package/dist/components/agents-panel.js.map +1 -0
- package/dist/components/app-keys-popover.d.ts +11 -0
- package/dist/components/app-keys-popover.d.ts.map +1 -0
- package/dist/components/app-keys-popover.js +84 -0
- package/dist/components/app-keys-popover.js.map +1 -0
- package/dist/components/create-app-popover.d.ts +24 -0
- package/dist/components/create-app-popover.d.ts.map +1 -0
- package/dist/components/create-app-popover.js +188 -0
- package/dist/components/create-app-popover.js.map +1 -0
- package/dist/components/dispatch-shell.d.ts +13 -0
- package/dist/components/dispatch-shell.d.ts.map +1 -0
- package/dist/components/dispatch-shell.js +15 -0
- package/dist/components/dispatch-shell.js.map +1 -0
- package/dist/components/index.d.ts +12 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +12 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/layout/Header.d.ts +5 -0
- package/dist/components/layout/Header.d.ts.map +1 -0
- package/dist/components/layout/Header.js +34 -0
- package/dist/components/layout/Header.js.map +1 -0
- package/dist/components/layout/HeaderActions.d.ts +18 -0
- package/dist/components/layout/HeaderActions.d.ts.map +1 -0
- package/dist/components/layout/HeaderActions.js +52 -0
- package/dist/components/layout/HeaderActions.js.map +1 -0
- package/dist/components/layout/Layout.d.ts +8 -0
- package/dist/components/layout/Layout.d.ts.map +1 -0
- package/dist/components/layout/Layout.js +70 -0
- package/dist/components/layout/Layout.js.map +1 -0
- package/dist/components/messaging-setup-panel.d.ts +2 -0
- package/dist/components/messaging-setup-panel.d.ts.map +1 -0
- package/dist/components/messaging-setup-panel.js +300 -0
- package/dist/components/messaging-setup-panel.js.map +1 -0
- package/dist/components/ui/accordion.d.ts +8 -0
- package/dist/components/ui/accordion.d.ts.map +1 -0
- package/dist/components/ui/accordion.js +14 -0
- package/dist/components/ui/accordion.js.map +1 -0
- package/dist/components/ui/alert-dialog.d.ts +21 -0
- package/dist/components/ui/alert-dialog.d.ts.map +1 -0
- package/dist/components/ui/alert-dialog.js +27 -0
- package/dist/components/ui/alert-dialog.js.map +1 -0
- package/dist/components/ui/alert.d.ts +9 -0
- package/dist/components/ui/alert.d.ts.map +1 -0
- package/dist/components/ui/alert.js +23 -0
- package/dist/components/ui/alert.js.map +1 -0
- package/dist/components/ui/aspect-ratio.d.ts +4 -0
- package/dist/components/ui/aspect-ratio.d.ts.map +1 -0
- package/dist/components/ui/aspect-ratio.js +4 -0
- package/dist/components/ui/aspect-ratio.js.map +1 -0
- package/dist/components/ui/avatar.d.ts +7 -0
- package/dist/components/ui/avatar.d.ts.map +1 -0
- package/dist/components/ui/avatar.js +12 -0
- package/dist/components/ui/avatar.js.map +1 -0
- package/dist/components/ui/badge.d.ts +10 -0
- package/dist/components/ui/badge.d.ts.map +1 -0
- package/dist/components/ui/badge.js +21 -0
- package/dist/components/ui/badge.js.map +1 -0
- package/dist/components/ui/breadcrumb.d.ts +20 -0
- package/dist/components/ui/breadcrumb.d.ts.map +1 -0
- package/dist/components/ui/breadcrumb.js +24 -0
- package/dist/components/ui/breadcrumb.js.map +1 -0
- package/dist/components/ui/button.d.ts +12 -0
- package/dist/components/ui/button.d.ts.map +1 -0
- package/dist/components/ui/button.js +34 -0
- package/dist/components/ui/button.js.map +1 -0
- package/dist/components/ui/calendar.d.ts +9 -0
- package/dist/components/ui/calendar.d.ts.map +1 -0
- package/dist/components/ui/calendar.js +41 -0
- package/dist/components/ui/calendar.js.map +1 -0
- package/dist/components/ui/card.d.ts +9 -0
- package/dist/components/ui/card.d.ts.map +1 -0
- package/dist/components/ui/card.js +17 -0
- package/dist/components/ui/card.js.map +1 -0
- package/dist/components/ui/carousel.d.ts +19 -0
- package/dist/components/ui/carousel.d.ts.map +1 -0
- package/dist/components/ui/carousel.js +99 -0
- package/dist/components/ui/carousel.js.map +1 -0
- package/dist/components/ui/chart.d.ts +80 -0
- package/dist/components/ui/chart.d.ts.map +1 -0
- package/dist/components/ui/chart.js +131 -0
- package/dist/components/ui/chart.js.map +1 -0
- package/dist/components/ui/checkbox.d.ts +5 -0
- package/dist/components/ui/checkbox.d.ts.map +1 -0
- package/dist/components/ui/checkbox.js +9 -0
- package/dist/components/ui/checkbox.js.map +1 -0
- package/dist/components/ui/collapsible.d.ts +6 -0
- package/dist/components/ui/collapsible.d.ts.map +1 -0
- package/dist/components/ui/collapsible.js +6 -0
- package/dist/components/ui/collapsible.js.map +1 -0
- package/dist/components/ui/command.d.ts +83 -0
- package/dist/components/ui/command.d.ts.map +1 -0
- package/dist/components/ui/command.js +29 -0
- package/dist/components/ui/command.js.map +1 -0
- package/dist/components/ui/context-menu.d.ts +28 -0
- package/dist/components/ui/context-menu.d.ts.map +1 -0
- package/dist/components/ui/context-menu.js +34 -0
- package/dist/components/ui/context-menu.js.map +1 -0
- package/dist/components/ui/dialog.d.ts +20 -0
- package/dist/components/ui/dialog.d.ts.map +1 -0
- package/dist/components/ui/dialog.js +23 -0
- package/dist/components/ui/dialog.js.map +1 -0
- package/dist/components/ui/drawer.d.ts +23 -0
- package/dist/components/ui/drawer.d.ts.map +1 -0
- package/dist/components/ui/drawer.js +23 -0
- package/dist/components/ui/drawer.js.map +1 -0
- package/dist/components/ui/dropdown-menu.d.ts +28 -0
- package/dist/components/ui/dropdown-menu.d.ts.map +1 -0
- package/dist/components/ui/dropdown-menu.js +36 -0
- package/dist/components/ui/dropdown-menu.js.map +1 -0
- package/dist/components/ui/form.d.ts +24 -0
- package/dist/components/ui/form.d.ts.map +1 -0
- package/dist/components/ui/form.js +63 -0
- package/dist/components/ui/form.js.map +1 -0
- package/dist/components/ui/hover-card.d.ts +7 -0
- package/dist/components/ui/hover-card.d.ts.map +1 -0
- package/dist/components/ui/hover-card.js +10 -0
- package/dist/components/ui/hover-card.js.map +1 -0
- package/dist/components/ui/input-otp.d.ts +35 -0
- package/dist/components/ui/input-otp.d.ts.map +1 -0
- package/dist/components/ui/input-otp.js +19 -0
- package/dist/components/ui/input-otp.js.map +1 -0
- package/dist/components/ui/input.d.ts +4 -0
- package/dist/components/ui/input.d.ts.map +1 -0
- package/dist/components/ui/input.js +9 -0
- package/dist/components/ui/input.js.map +1 -0
- package/dist/components/ui/label.d.ts +6 -0
- package/dist/components/ui/label.d.ts.map +1 -0
- package/dist/components/ui/label.js +10 -0
- package/dist/components/ui/label.js.map +1 -0
- package/dist/components/ui/menubar.d.ts +29 -0
- package/dist/components/ui/menubar.d.ts.map +1 -0
- package/dist/components/ui/menubar.js +41 -0
- package/dist/components/ui/menubar.js.map +1 -0
- package/dist/components/ui/navigation-menu.d.ts +13 -0
- package/dist/components/ui/navigation-menu.d.ts.map +1 -0
- package/dist/components/ui/navigation-menu.js +25 -0
- package/dist/components/ui/navigation-menu.js.map +1 -0
- package/dist/components/ui/pagination.d.ts +29 -0
- package/dist/components/ui/pagination.d.ts.map +1 -0
- package/dist/components/ui/pagination.js +24 -0
- package/dist/components/ui/pagination.js.map +1 -0
- package/dist/components/ui/popover.d.ts +7 -0
- package/dist/components/ui/popover.d.ts.map +1 -0
- package/dist/components/ui/popover.js +10 -0
- package/dist/components/ui/popover.js.map +1 -0
- package/dist/components/ui/progress.d.ts +5 -0
- package/dist/components/ui/progress.d.ts.map +1 -0
- package/dist/components/ui/progress.js +8 -0
- package/dist/components/ui/progress.js.map +1 -0
- package/dist/components/ui/radio-group.d.ts +6 -0
- package/dist/components/ui/radio-group.d.ts.map +1 -0
- package/dist/components/ui/radio-group.js +15 -0
- package/dist/components/ui/radio-group.js.map +1 -0
- package/dist/components/ui/resizable.d.ts +8 -0
- package/dist/components/ui/resizable.d.ts.map +1 -0
- package/dist/components/ui/resizable.js +9 -0
- package/dist/components/ui/resizable.js.map +1 -0
- package/dist/components/ui/scroll-area.d.ts +6 -0
- package/dist/components/ui/scroll-area.d.ts.map +1 -0
- package/dist/components/ui/scroll-area.js +12 -0
- package/dist/components/ui/scroll-area.js.map +1 -0
- package/dist/components/ui/select.d.ts +14 -0
- package/dist/components/ui/select.d.ts.map +1 -0
- package/dist/components/ui/select.js +27 -0
- package/dist/components/ui/select.js.map +1 -0
- package/dist/components/ui/separator.d.ts +5 -0
- package/dist/components/ui/separator.d.ts.map +1 -0
- package/dist/components/ui/separator.js +8 -0
- package/dist/components/ui/separator.js.map +1 -0
- package/dist/components/ui/sheet.d.ts +26 -0
- package/dist/components/ui/sheet.d.ts.map +1 -0
- package/dist/components/ui/sheet.js +37 -0
- package/dist/components/ui/sheet.js.map +1 -0
- package/dist/components/ui/sidebar.d.ts +67 -0
- package/dist/components/ui/sidebar.d.ts.map +1 -0
- package/dist/components/ui/sidebar.js +233 -0
- package/dist/components/ui/sidebar.js.map +1 -0
- package/dist/components/ui/skeleton.d.ts +3 -0
- package/dist/components/ui/skeleton.d.ts.map +1 -0
- package/dist/components/ui/skeleton.js +7 -0
- package/dist/components/ui/skeleton.js.map +1 -0
- package/dist/components/ui/slider.d.ts +5 -0
- package/dist/components/ui/slider.d.ts.map +1 -0
- package/dist/components/ui/slider.js +8 -0
- package/dist/components/ui/slider.js.map +1 -0
- package/dist/components/ui/sonner.d.ts +5 -0
- package/dist/components/ui/sonner.d.ts.map +1 -0
- package/dist/components/ui/sonner.js +25 -0
- package/dist/components/ui/sonner.js.map +1 -0
- package/dist/components/ui/spinner.d.ts +3 -0
- package/dist/components/ui/spinner.d.ts.map +1 -0
- package/dist/components/ui/spinner.js +7 -0
- package/dist/components/ui/spinner.js.map +1 -0
- package/dist/components/ui/switch.d.ts +5 -0
- package/dist/components/ui/switch.d.ts.map +1 -0
- package/dist/components/ui/switch.js +8 -0
- package/dist/components/ui/switch.js.map +1 -0
- package/dist/components/ui/table.d.ts +11 -0
- package/dist/components/ui/table.d.ts.map +1 -0
- package/dist/components/ui/table.js +21 -0
- package/dist/components/ui/table.js.map +1 -0
- package/dist/components/ui/tabs.d.ts +8 -0
- package/dist/components/ui/tabs.d.ts.map +1 -0
- package/dist/components/ui/tabs.js +13 -0
- package/dist/components/ui/tabs.js.map +1 -0
- package/dist/components/ui/textarea.d.ts +6 -0
- package/dist/components/ui/textarea.d.ts.map +1 -0
- package/dist/components/ui/textarea.js +9 -0
- package/dist/components/ui/textarea.js.map +1 -0
- package/dist/components/ui/toast.d.ts +16 -0
- package/dist/components/ui/toast.d.ts.map +1 -0
- package/dist/components/ui/toast.js +34 -0
- package/dist/components/ui/toast.js.map +1 -0
- package/dist/components/ui/toaster.d.ts +2 -0
- package/dist/components/ui/toaster.d.ts.map +1 -0
- package/dist/components/ui/toaster.js +10 -0
- package/dist/components/ui/toaster.js.map +1 -0
- package/dist/components/ui/toggle-group.d.ts +13 -0
- package/dist/components/ui/toggle-group.d.ts.map +1 -0
- package/dist/components/ui/toggle-group.js +21 -0
- package/dist/components/ui/toggle-group.js.map +1 -0
- package/dist/components/ui/toggle.d.ts +13 -0
- package/dist/components/ui/toggle.d.ts.map +1 -0
- package/dist/components/ui/toggle.js +26 -0
- package/dist/components/ui/toggle.js.map +1 -0
- package/dist/components/ui/tooltip.d.ts +8 -0
- package/dist/components/ui/tooltip.d.ts.map +1 -0
- package/dist/components/ui/tooltip.js +11 -0
- package/dist/components/ui/tooltip.js.map +1 -0
- package/dist/components/ui/use-toast.d.ts +3 -0
- package/dist/components/ui/use-toast.d.ts.map +1 -0
- package/dist/components/ui/use-toast.js +3 -0
- package/dist/components/ui/use-toast.js.map +1 -0
- package/dist/config.d.ts +33 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +7 -0
- package/dist/config.js.map +1 -0
- package/dist/db/index.d.ts +7 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +10 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/migrations.d.ts +5 -0
- package/dist/db/migrations.d.ts.map +1 -0
- package/dist/db/migrations.js +166 -0
- package/dist/db/migrations.js.map +1 -0
- package/dist/db/schema.d.ts +2344 -0
- package/dist/db/schema.d.ts.map +1 -0
- package/dist/db/schema.js +148 -0
- package/dist/db/schema.js.map +1 -0
- package/dist/hooks/use-mobile.d.ts +2 -0
- package/dist/hooks/use-mobile.d.ts.map +1 -0
- package/dist/hooks/use-mobile.js +16 -0
- package/dist/hooks/use-mobile.js.map +1 -0
- package/dist/hooks/use-navigation-state.d.ts +6 -0
- package/dist/hooks/use-navigation-state.d.ts.map +1 -0
- package/dist/hooks/use-navigation-state.js +129 -0
- package/dist/hooks/use-navigation-state.js.map +1 -0
- package/dist/hooks/use-toast.d.ts +45 -0
- package/dist/hooks/use-toast.d.ts.map +1 -0
- package/dist/hooks/use-toast.js +127 -0
- package/dist/hooks/use-toast.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +2 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/routes/index.d.ts +32 -0
- package/dist/routes/index.d.ts.map +1 -0
- package/dist/routes/index.js +51 -0
- package/dist/routes/index.js.map +1 -0
- package/dist/routes/pages/_index.d.ts +15 -0
- package/dist/routes/pages/_index.d.ts.map +1 -0
- package/dist/routes/pages/_index.js +42 -0
- package/dist/routes/pages/_index.js.map +1 -0
- package/dist/routes/pages/agents.d.ts +5 -0
- package/dist/routes/pages/agents.d.ts.map +1 -0
- package/dist/routes/pages/agents.js +12 -0
- package/dist/routes/pages/agents.js.map +1 -0
- package/dist/routes/pages/approval.d.ts +5 -0
- package/dist/routes/pages/approval.d.ts.map +1 -0
- package/dist/routes/pages/approval.js +47 -0
- package/dist/routes/pages/approval.js.map +1 -0
- package/dist/routes/pages/approvals.d.ts +5 -0
- package/dist/routes/pages/approvals.d.ts.map +1 -0
- package/dist/routes/pages/approvals.js +48 -0
- package/dist/routes/pages/approvals.js.map +1 -0
- package/dist/routes/pages/apps.$appId.d.ts +5 -0
- package/dist/routes/pages/apps.$appId.d.ts.map +1 -0
- package/dist/routes/pages/apps.$appId.js +31 -0
- package/dist/routes/pages/apps.$appId.js.map +1 -0
- package/dist/routes/pages/apps.d.ts +5 -0
- package/dist/routes/pages/apps.d.ts.map +1 -0
- package/dist/routes/pages/apps.js +42 -0
- package/dist/routes/pages/apps.js.map +1 -0
- package/dist/routes/pages/audit.d.ts +5 -0
- package/dist/routes/pages/audit.d.ts.map +1 -0
- package/dist/routes/pages/audit.js +11 -0
- package/dist/routes/pages/audit.js.map +1 -0
- package/dist/routes/pages/destinations.d.ts +5 -0
- package/dist/routes/pages/destinations.d.ts.map +1 -0
- package/dist/routes/pages/destinations.js +80 -0
- package/dist/routes/pages/destinations.js.map +1 -0
- package/dist/routes/pages/identities.d.ts +5 -0
- package/dist/routes/pages/identities.d.ts.map +1 -0
- package/dist/routes/pages/identities.js +18 -0
- package/dist/routes/pages/identities.js.map +1 -0
- package/dist/routes/pages/integrations.d.ts +5 -0
- package/dist/routes/pages/integrations.d.ts.map +1 -0
- package/dist/routes/pages/integrations.js +46 -0
- package/dist/routes/pages/integrations.js.map +1 -0
- package/dist/routes/pages/messaging.d.ts +5 -0
- package/dist/routes/pages/messaging.d.ts.map +1 -0
- package/dist/routes/pages/messaging.js +10 -0
- package/dist/routes/pages/messaging.js.map +1 -0
- package/dist/routes/pages/new-app.d.ts +5 -0
- package/dist/routes/pages/new-app.d.ts.map +1 -0
- package/dist/routes/pages/new-app.js +10 -0
- package/dist/routes/pages/new-app.js.map +1 -0
- package/dist/routes/pages/overview.d.ts +5 -0
- package/dist/routes/pages/overview.d.ts.map +1 -0
- package/dist/routes/pages/overview.js +225 -0
- package/dist/routes/pages/overview.js.map +1 -0
- package/dist/routes/pages/team.d.ts +5 -0
- package/dist/routes/pages/team.d.ts.map +1 -0
- package/dist/routes/pages/team.js +10 -0
- package/dist/routes/pages/team.js.map +1 -0
- package/dist/routes/pages/tools.$id.d.ts +2 -0
- package/dist/routes/pages/tools.$id.d.ts.map +1 -0
- package/dist/routes/pages/tools.$id.js +6 -0
- package/dist/routes/pages/tools.$id.js.map +1 -0
- package/dist/routes/pages/tools._index.d.ts +2 -0
- package/dist/routes/pages/tools._index.d.ts.map +1 -0
- package/dist/routes/pages/tools._index.js +6 -0
- package/dist/routes/pages/tools._index.js.map +1 -0
- package/dist/routes/pages/vault.d.ts +5 -0
- package/dist/routes/pages/vault.d.ts.map +1 -0
- package/dist/routes/pages/vault.js +131 -0
- package/dist/routes/pages/vault.js.map +1 -0
- package/dist/routes/pages/workspace.d.ts +5 -0
- package/dist/routes/pages/workspace.d.ts.map +1 -0
- package/dist/routes/pages/workspace.js +149 -0
- package/dist/routes/pages/workspace.js.map +1 -0
- package/dist/server/index.d.ts +44 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +68 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/lib/app-creation-store.d.ts +102 -0
- package/dist/server/lib/app-creation-store.d.ts.map +1 -0
- package/dist/server/lib/app-creation-store.js +780 -0
- package/dist/server/lib/app-creation-store.js.map +1 -0
- package/dist/server/lib/dispatch-integrations.d.ts +10 -0
- package/dist/server/lib/dispatch-integrations.d.ts.map +1 -0
- package/dist/server/lib/dispatch-integrations.js +105 -0
- package/dist/server/lib/dispatch-integrations.js.map +1 -0
- package/dist/server/lib/dispatch-store.d.ts +313 -0
- package/dist/server/lib/dispatch-store.d.ts.map +1 -0
- package/dist/server/lib/dispatch-store.js +669 -0
- package/dist/server/lib/dispatch-store.js.map +1 -0
- package/dist/server/lib/env-config.d.ts +3 -0
- package/dist/server/lib/env-config.d.ts.map +1 -0
- package/dist/server/lib/env-config.js +43 -0
- package/dist/server/lib/env-config.js.map +1 -0
- package/dist/server/lib/pre-auth-routing.d.ts +2 -0
- package/dist/server/lib/pre-auth-routing.d.ts.map +1 -0
- package/dist/server/lib/pre-auth-routing.js +128 -0
- package/dist/server/lib/pre-auth-routing.js.map +1 -0
- package/dist/server/lib/vault-store.d.ts +270 -0
- package/dist/server/lib/vault-store.d.ts.map +1 -0
- package/dist/server/lib/vault-store.js +554 -0
- package/dist/server/lib/vault-store.js.map +1 -0
- package/dist/server/lib/workspace-resources-store.d.ts +165 -0
- package/dist/server/lib/workspace-resources-store.d.ts.map +1 -0
- package/dist/server/lib/workspace-resources-store.js +310 -0
- package/dist/server/lib/workspace-resources-store.js.map +1 -0
- package/dist/server/plugins/agent-chat.d.ts +3 -0
- package/dist/server/plugins/agent-chat.d.ts.map +1 -0
- package/dist/server/plugins/agent-chat.js +36 -0
- package/dist/server/plugins/agent-chat.js.map +1 -0
- package/dist/server/plugins/auth.d.ts +9 -0
- package/dist/server/plugins/auth.d.ts.map +1 -0
- package/dist/server/plugins/auth.js +30 -0
- package/dist/server/plugins/auth.js.map +1 -0
- package/dist/server/plugins/core-routes.d.ts +3 -0
- package/dist/server/plugins/core-routes.d.ts.map +1 -0
- package/dist/server/plugins/core-routes.js +6 -0
- package/dist/server/plugins/core-routes.js.map +1 -0
- package/dist/server/plugins/db.d.ts +3 -0
- package/dist/server/plugins/db.d.ts.map +1 -0
- package/dist/server/plugins/db.js +6 -0
- package/dist/server/plugins/db.js.map +1 -0
- package/dist/server/plugins/integrations.d.ts +8 -0
- package/dist/server/plugins/integrations.d.ts.map +1 -0
- package/dist/server/plugins/integrations.js +51 -0
- package/dist/server/plugins/integrations.js.map +1 -0
- package/package.json +103 -0
- package/src/actions/approve-dispatch-change.ts +11 -0
- package/src/actions/approve-vault-request.ts +23 -0
- package/src/actions/create-link-token.ts +12 -0
- package/src/actions/create-vault-grant.ts +15 -0
- package/src/actions/create-vault-secret.ts +21 -0
- package/src/actions/create-workspace-resource-grant.ts +15 -0
- package/src/actions/create-workspace-resource.ts +29 -0
- package/src/actions/delete-destination.ts +11 -0
- package/src/actions/delete-vault-secret.ts +12 -0
- package/src/actions/delete-workspace-resource.ts +12 -0
- package/src/actions/deny-vault-request.ts +12 -0
- package/src/actions/get-app-creation-settings.ts +11 -0
- package/src/actions/get-dispatch-settings.ts +10 -0
- package/src/actions/get-workspace-info.ts +11 -0
- package/src/actions/grant-vault-secrets-to-app.ts +20 -0
- package/src/actions/index.ts +102 -0
- package/src/actions/list-connected-agents.ts +103 -0
- package/src/actions/list-destinations.ts +10 -0
- package/src/actions/list-dispatch-approvals.ts +10 -0
- package/src/actions/list-dispatch-audit.ts +12 -0
- package/src/actions/list-dispatch-overview.ts +18 -0
- package/src/actions/list-integrations-catalog.ts +11 -0
- package/src/actions/list-linked-identities.ts +10 -0
- package/src/actions/list-vault-audit.ts +16 -0
- package/src/actions/list-vault-grants.ts +14 -0
- package/src/actions/list-vault-requests.ts +16 -0
- package/src/actions/list-vault-secret-options.ts +20 -0
- package/src/actions/list-vault-secrets.ts +26 -0
- package/src/actions/list-workspace-apps.ts +25 -0
- package/src/actions/list-workspace-resource-grants.ts +14 -0
- package/src/actions/list-workspace-resources.ts +16 -0
- package/src/actions/navigate.ts +55 -0
- package/src/actions/reject-dispatch-change.ts +12 -0
- package/src/actions/request-vault-secret.ts +16 -0
- package/src/actions/revoke-vault-grant.ts +11 -0
- package/src/actions/revoke-workspace-resource-grant.ts +15 -0
- package/src/actions/send-platform-message.ts +96 -0
- package/src/actions/set-app-creation-settings.ts +19 -0
- package/src/actions/set-dispatch-approval-policy.ts +24 -0
- package/src/actions/start-workspace-app-creation.ts +33 -0
- package/src/actions/sync-vault-to-app.ts +14 -0
- package/src/actions/sync-workspace-resources-to-all.ts +10 -0
- package/src/actions/sync-workspace-resources-to-app.ts +12 -0
- package/src/actions/update-vault-secret.ts +12 -0
- package/src/actions/update-workspace-resource.ts +19 -0
- package/src/actions/upsert-destination.ts +29 -0
- package/src/actions/view-screen.ts +78 -0
- package/src/components/agents-panel.tsx +262 -0
- package/src/components/app-keys-popover.tsx +231 -0
- package/src/components/create-app-popover.tsx +423 -0
- package/src/components/dispatch-shell.tsx +53 -0
- package/src/components/index.ts +11 -0
- package/src/components/layout/Header.tsx +69 -0
- package/src/components/layout/HeaderActions.tsx +84 -0
- package/src/components/layout/Layout.tsx +243 -0
- package/src/components/messaging-setup-panel.tsx +666 -0
- package/src/components/ui/accordion.tsx +56 -0
- package/src/components/ui/alert-dialog.tsx +139 -0
- package/src/components/ui/alert.tsx +59 -0
- package/src/components/ui/aspect-ratio.tsx +5 -0
- package/src/components/ui/avatar.tsx +48 -0
- package/src/components/ui/badge.tsx +37 -0
- package/src/components/ui/breadcrumb.tsx +115 -0
- package/src/components/ui/button.tsx +57 -0
- package/src/components/ui/calendar.tsx +68 -0
- package/src/components/ui/card.tsx +86 -0
- package/src/components/ui/carousel.tsx +260 -0
- package/src/components/ui/chart.tsx +375 -0
- package/src/components/ui/checkbox.tsx +28 -0
- package/src/components/ui/collapsible.tsx +9 -0
- package/src/components/ui/command.tsx +154 -0
- package/src/components/ui/context-menu.tsx +198 -0
- package/src/components/ui/dialog.tsx +120 -0
- package/src/components/ui/drawer.tsx +116 -0
- package/src/components/ui/dropdown-menu.tsx +198 -0
- package/src/components/ui/form.tsx +177 -0
- package/src/components/ui/hover-card.tsx +27 -0
- package/src/components/ui/input-otp.tsx +69 -0
- package/src/components/ui/input.tsx +22 -0
- package/src/components/ui/label.tsx +24 -0
- package/src/components/ui/menubar.tsx +235 -0
- package/src/components/ui/navigation-menu.tsx +128 -0
- package/src/components/ui/pagination.tsx +121 -0
- package/src/components/ui/popover.tsx +29 -0
- package/src/components/ui/progress.tsx +26 -0
- package/src/components/ui/radio-group.tsx +42 -0
- package/src/components/ui/resizable.tsx +43 -0
- package/src/components/ui/scroll-area.tsx +46 -0
- package/src/components/ui/select.tsx +158 -0
- package/src/components/ui/separator.tsx +29 -0
- package/src/components/ui/sheet.tsx +139 -0
- package/src/components/ui/sidebar.tsx +778 -0
- package/src/components/ui/skeleton.tsx +15 -0
- package/src/components/ui/slider.tsx +26 -0
- package/src/components/ui/sonner.tsx +58 -0
- package/src/components/ui/spinner.tsx +17 -0
- package/src/components/ui/switch.tsx +27 -0
- package/src/components/ui/table.tsx +117 -0
- package/src/components/ui/tabs.tsx +53 -0
- package/src/components/ui/textarea.tsx +23 -0
- package/src/components/ui/toast.tsx +127 -0
- package/src/components/ui/toaster.tsx +33 -0
- package/src/components/ui/toggle-group.tsx +59 -0
- package/src/components/ui/toggle.tsx +43 -0
- package/src/components/ui/tooltip.tsx +28 -0
- package/src/components/ui/use-toast.ts +3 -0
- package/src/config.ts +35 -0
- package/src/db/index.ts +12 -0
- package/src/db/migrations.ts +165 -0
- package/src/db/schema.ts +160 -0
- package/src/hooks/use-mobile.tsx +21 -0
- package/src/hooks/use-navigation-state.ts +132 -0
- package/src/hooks/use-toast.ts +188 -0
- package/src/index.ts +19 -0
- package/src/lib/utils.ts +1 -0
- package/src/routes/index.ts +51 -0
- package/src/routes/pages/_index.tsx +51 -0
- package/src/routes/pages/agents.tsx +23 -0
- package/src/routes/pages/approval.tsx +243 -0
- package/src/routes/pages/approvals.tsx +157 -0
- package/src/routes/pages/apps.$appId.tsx +134 -0
- package/src/routes/pages/apps.tsx +163 -0
- package/src/routes/pages/audit.tsx +41 -0
- package/src/routes/pages/destinations.tsx +253 -0
- package/src/routes/pages/identities.tsx +91 -0
- package/src/routes/pages/integrations.tsx +278 -0
- package/src/routes/pages/messaging.tsx +17 -0
- package/src/routes/pages/new-app.tsx +17 -0
- package/src/routes/pages/overview.tsx +792 -0
- package/src/routes/pages/team.tsx +23 -0
- package/src/routes/pages/tools.$id.tsx +5 -0
- package/src/routes/pages/tools._index.tsx +5 -0
- package/src/routes/pages/vault.tsx +617 -0
- package/src/routes/pages/workspace.tsx +598 -0
- package/src/server/index.ts +78 -0
- package/src/server/lib/app-creation-store.ts +996 -0
- package/src/server/lib/dispatch-integrations.ts +125 -0
- package/src/server/lib/dispatch-store.ts +889 -0
- package/src/server/lib/env-config.ts +44 -0
- package/src/server/lib/pre-auth-routing.ts +150 -0
- package/src/server/lib/vault-store.ts +811 -0
- package/src/server/lib/workspace-resources-store.ts +445 -0
- package/src/server/plugins/agent-chat.ts +36 -0
- package/src/server/plugins/auth.ts +34 -0
- package/src/server/plugins/core-routes.ts +6 -0
- package/src/server/plugins/db.ts +6 -0
- package/src/server/plugins/integrations.ts +59 -0
|
@@ -0,0 +1,889 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import { and, desc, eq, isNull, or } from "drizzle-orm";
|
|
3
|
+
import { getOrgSetting, putOrgSetting } from "@agent-native/core/settings";
|
|
4
|
+
import {
|
|
5
|
+
getRequestUserEmail,
|
|
6
|
+
getRequestOrgId,
|
|
7
|
+
} from "@agent-native/core/server";
|
|
8
|
+
import { getDb, schema } from "../../db/index.js";
|
|
9
|
+
|
|
10
|
+
export const SHARED_DISPATCH_OWNER = "dispatch@shared";
|
|
11
|
+
const APPROVAL_POLICY_KEY = "dispatch-approval-policy";
|
|
12
|
+
|
|
13
|
+
// ─── /link rate limiting ──────────────────────────────────────────────────
|
|
14
|
+
//
|
|
15
|
+
// Failed `/link <token>` attempts are rate-limited per `(platform, externalUserId)`
|
|
16
|
+
// to deter token brute-force after the H5 entropy bump. The window /
|
|
17
|
+
// threshold are tuned so legitimate retries (typo, expired token) don't
|
|
18
|
+
// trip the limit, while a scripted attacker burns out their per-account
|
|
19
|
+
// budget quickly.
|
|
20
|
+
//
|
|
21
|
+
// State is process-local: works for the single-node dispatch deployment
|
|
22
|
+
// we ship today. TODO: move to a SQL-backed counter table when dispatch
|
|
23
|
+
// is sharded across multiple regions / processes — otherwise an
|
|
24
|
+
// attacker can scale around the limit by hammering more than one node.
|
|
25
|
+
const LINK_FAIL_WINDOW_MS = 5 * 60 * 1000;
|
|
26
|
+
const LINK_FAIL_BLOCK_MS = 30 * 60 * 1000;
|
|
27
|
+
const LINK_FAIL_THRESHOLD = 5;
|
|
28
|
+
|
|
29
|
+
interface LinkFailureState {
|
|
30
|
+
failures: number[]; // unix-ms timestamps of recent failures within the window
|
|
31
|
+
blockedUntil: number; // unix-ms; 0 if not currently blocked
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const _linkFailureMap = new Map<string, LinkFailureState>();
|
|
35
|
+
|
|
36
|
+
function linkFailureKey(
|
|
37
|
+
platform: string,
|
|
38
|
+
externalUserId: string | null | undefined,
|
|
39
|
+
): string {
|
|
40
|
+
return `${platform}::${externalUserId ?? ""}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function getLinkFailureState(key: string): LinkFailureState {
|
|
44
|
+
let state = _linkFailureMap.get(key);
|
|
45
|
+
if (!state) {
|
|
46
|
+
state = { failures: [], blockedUntil: 0 };
|
|
47
|
+
_linkFailureMap.set(key, state);
|
|
48
|
+
}
|
|
49
|
+
return state;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function isLinkAttemptBlocked(
|
|
53
|
+
platform: string,
|
|
54
|
+
externalUserId: string | null | undefined,
|
|
55
|
+
): { blocked: true; retryAfterMs: number } | { blocked: false } {
|
|
56
|
+
if (!externalUserId) return { blocked: false };
|
|
57
|
+
const key = linkFailureKey(platform, externalUserId);
|
|
58
|
+
const state = _linkFailureMap.get(key);
|
|
59
|
+
if (!state) return { blocked: false };
|
|
60
|
+
const nowMs = Date.now();
|
|
61
|
+
if (state.blockedUntil > nowMs) {
|
|
62
|
+
return { blocked: true, retryAfterMs: state.blockedUntil - nowMs };
|
|
63
|
+
}
|
|
64
|
+
return { blocked: false };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function recordLinkFailure(
|
|
68
|
+
platform: string,
|
|
69
|
+
externalUserId: string | null | undefined,
|
|
70
|
+
): void {
|
|
71
|
+
if (!externalUserId) return;
|
|
72
|
+
const key = linkFailureKey(platform, externalUserId);
|
|
73
|
+
const state = getLinkFailureState(key);
|
|
74
|
+
const nowMs = Date.now();
|
|
75
|
+
// Drop expired failure timestamps before counting.
|
|
76
|
+
state.failures = state.failures.filter(
|
|
77
|
+
(ts) => nowMs - ts < LINK_FAIL_WINDOW_MS,
|
|
78
|
+
);
|
|
79
|
+
state.failures.push(nowMs);
|
|
80
|
+
if (state.failures.length >= LINK_FAIL_THRESHOLD) {
|
|
81
|
+
state.blockedUntil = nowMs + LINK_FAIL_BLOCK_MS;
|
|
82
|
+
state.failures = [];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function clearLinkFailures(
|
|
87
|
+
platform: string,
|
|
88
|
+
externalUserId: string | null | undefined,
|
|
89
|
+
): void {
|
|
90
|
+
if (!externalUserId) return;
|
|
91
|
+
_linkFailureMap.delete(linkFailureKey(platform, externalUserId));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 429-style error returned when /link attempts are rate-limited. The
|
|
96
|
+
* adapter layer can branch on `code === "LINK_RATE_LIMITED"` to send a
|
|
97
|
+
* platform-appropriate message back to the user.
|
|
98
|
+
*/
|
|
99
|
+
export class LinkRateLimitError extends Error {
|
|
100
|
+
readonly code = "LINK_RATE_LIMITED";
|
|
101
|
+
constructor(public readonly retryAfterMs: number) {
|
|
102
|
+
super(
|
|
103
|
+
`Too many failed link attempts. Try again in ${Math.ceil(retryAfterMs / 60_000)} minute(s).`,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface DispatchApprovalPolicy {
|
|
109
|
+
enabled: boolean;
|
|
110
|
+
approverEmails: string[];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface DispatchDestinationInput {
|
|
114
|
+
id?: string;
|
|
115
|
+
name: string;
|
|
116
|
+
platform: string;
|
|
117
|
+
destination: string;
|
|
118
|
+
threadRef?: string | null;
|
|
119
|
+
notes?: string | null;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
type DispatchApprovalRequest =
|
|
123
|
+
typeof schema.dispatchApprovalRequests.$inferSelect;
|
|
124
|
+
|
|
125
|
+
export function currentOwnerEmail(): string {
|
|
126
|
+
const email = getRequestUserEmail();
|
|
127
|
+
if (!email) throw new Error("no authenticated user");
|
|
128
|
+
return email;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function currentOrgId(): string | null {
|
|
132
|
+
return getRequestOrgId() || null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Caller-supplied access context for dispatch operations that work by
|
|
137
|
+
* id (destinations, etc.). Looking up a row by id alone is unsafe —
|
|
138
|
+
* UUIDs are not authorization. A row matches the ctx if either the
|
|
139
|
+
* caller owns it or it lives in the caller's active org.
|
|
140
|
+
*/
|
|
141
|
+
export interface DispatchCtx {
|
|
142
|
+
ownerEmail: string;
|
|
143
|
+
orgId: string | null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function requireDispatchCtx(): DispatchCtx {
|
|
147
|
+
return { ownerEmail: currentOwnerEmail(), orgId: currentOrgId() };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function ctxScope<T extends { ownerEmail: any; orgId: any }>(
|
|
151
|
+
table: T,
|
|
152
|
+
ctx: DispatchCtx,
|
|
153
|
+
) {
|
|
154
|
+
if (!ctx.orgId) {
|
|
155
|
+
return and(eq(table.ownerEmail, ctx.ownerEmail), isNull(table.orgId));
|
|
156
|
+
}
|
|
157
|
+
return or(eq(table.ownerEmail, ctx.ownerEmail), eq(table.orgId, ctx.orgId));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function id() {
|
|
161
|
+
return crypto.randomUUID();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function now() {
|
|
165
|
+
return Date.now();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function safeJson(value: unknown) {
|
|
169
|
+
return JSON.stringify(value ?? null);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export async function getApprovalPolicy(): Promise<DispatchApprovalPolicy> {
|
|
173
|
+
const orgId = currentOrgId();
|
|
174
|
+
if (!orgId) return { enabled: false, approverEmails: [] };
|
|
175
|
+
const raw = await getOrgSetting(orgId, APPROVAL_POLICY_KEY);
|
|
176
|
+
return {
|
|
177
|
+
enabled: raw?.enabled === true,
|
|
178
|
+
approverEmails: Array.isArray(raw?.approverEmails)
|
|
179
|
+
? raw.approverEmails.filter(
|
|
180
|
+
(value): value is string => typeof value === "string",
|
|
181
|
+
)
|
|
182
|
+
: [],
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async function applyApprovalPolicy(
|
|
187
|
+
input: DispatchApprovalPolicy,
|
|
188
|
+
actor = currentOwnerEmail(),
|
|
189
|
+
) {
|
|
190
|
+
const orgId = currentOrgId();
|
|
191
|
+
if (!orgId) {
|
|
192
|
+
throw new Error(
|
|
193
|
+
"Dispatch approval settings require an active organization",
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
await putOrgSetting(orgId, APPROVAL_POLICY_KEY, {
|
|
197
|
+
enabled: input.enabled,
|
|
198
|
+
approverEmails: input.approverEmails,
|
|
199
|
+
});
|
|
200
|
+
await recordAudit({
|
|
201
|
+
action: "settings.updated",
|
|
202
|
+
targetType: "dispatch-settings",
|
|
203
|
+
targetId: APPROVAL_POLICY_KEY,
|
|
204
|
+
summary: input.enabled
|
|
205
|
+
? "Enabled approval flow for durable dispatch changes"
|
|
206
|
+
: "Disabled approval flow for durable dispatch changes",
|
|
207
|
+
metadata: input,
|
|
208
|
+
actor,
|
|
209
|
+
});
|
|
210
|
+
return getApprovalPolicy();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export async function setApprovalPolicy(input: DispatchApprovalPolicy) {
|
|
214
|
+
const current = await getApprovalPolicy();
|
|
215
|
+
if (!current.enabled) {
|
|
216
|
+
return applyApprovalPolicy(input);
|
|
217
|
+
}
|
|
218
|
+
return createApprovalRequest({
|
|
219
|
+
changeType: "approval-policy.update",
|
|
220
|
+
targetType: "dispatch-settings",
|
|
221
|
+
targetId: APPROVAL_POLICY_KEY,
|
|
222
|
+
summary: input.enabled
|
|
223
|
+
? "Update dispatch approval policy"
|
|
224
|
+
: "Disable dispatch approval policy",
|
|
225
|
+
payload: input,
|
|
226
|
+
beforeValue: current,
|
|
227
|
+
afterValue: input,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export async function recordAudit(input: {
|
|
232
|
+
action: string;
|
|
233
|
+
targetType: string;
|
|
234
|
+
targetId?: string | null;
|
|
235
|
+
summary: string;
|
|
236
|
+
metadata?: unknown;
|
|
237
|
+
actor?: string;
|
|
238
|
+
ownerEmail?: string;
|
|
239
|
+
orgId?: string | null;
|
|
240
|
+
}) {
|
|
241
|
+
const db = getDb();
|
|
242
|
+
const timestamp = now();
|
|
243
|
+
await db.insert(schema.dispatchAuditEvents).values({
|
|
244
|
+
id: id(),
|
|
245
|
+
ownerEmail: input.ownerEmail || currentOwnerEmail(),
|
|
246
|
+
orgId: input.orgId !== undefined ? input.orgId : currentOrgId(),
|
|
247
|
+
actor: input.actor || currentOwnerEmail(),
|
|
248
|
+
action: input.action,
|
|
249
|
+
targetType: input.targetType,
|
|
250
|
+
targetId: input.targetId || null,
|
|
251
|
+
summary: input.summary,
|
|
252
|
+
metadata: input.metadata ? safeJson(input.metadata) : null,
|
|
253
|
+
createdAt: timestamp,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export async function listAuditEvents(limit = 50) {
|
|
258
|
+
const db = getDb();
|
|
259
|
+
const orgId = currentOrgId();
|
|
260
|
+
return db
|
|
261
|
+
.select()
|
|
262
|
+
.from(schema.dispatchAuditEvents)
|
|
263
|
+
.where(
|
|
264
|
+
and(
|
|
265
|
+
eq(schema.dispatchAuditEvents.ownerEmail, currentOwnerEmail()),
|
|
266
|
+
orgId
|
|
267
|
+
? eq(schema.dispatchAuditEvents.orgId, orgId)
|
|
268
|
+
: isNull(schema.dispatchAuditEvents.orgId),
|
|
269
|
+
),
|
|
270
|
+
)
|
|
271
|
+
.orderBy(desc(schema.dispatchAuditEvents.createdAt))
|
|
272
|
+
.limit(limit);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export async function listDestinations() {
|
|
276
|
+
const db = getDb();
|
|
277
|
+
const orgId = currentOrgId();
|
|
278
|
+
return db
|
|
279
|
+
.select()
|
|
280
|
+
.from(schema.dispatchDestinations)
|
|
281
|
+
.where(
|
|
282
|
+
and(
|
|
283
|
+
eq(schema.dispatchDestinations.ownerEmail, currentOwnerEmail()),
|
|
284
|
+
orgId
|
|
285
|
+
? eq(schema.dispatchDestinations.orgId, orgId)
|
|
286
|
+
: isNull(schema.dispatchDestinations.orgId),
|
|
287
|
+
),
|
|
288
|
+
)
|
|
289
|
+
.orderBy(desc(schema.dispatchDestinations.updatedAt));
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export async function getDestinationById(
|
|
293
|
+
destinationId: string,
|
|
294
|
+
ctx: DispatchCtx = requireDispatchCtx(),
|
|
295
|
+
) {
|
|
296
|
+
const db = getDb();
|
|
297
|
+
const [row] = await db
|
|
298
|
+
.select()
|
|
299
|
+
.from(schema.dispatchDestinations)
|
|
300
|
+
.where(
|
|
301
|
+
and(
|
|
302
|
+
eq(schema.dispatchDestinations.id, destinationId),
|
|
303
|
+
ctxScope(schema.dispatchDestinations, ctx),
|
|
304
|
+
),
|
|
305
|
+
)
|
|
306
|
+
.limit(1);
|
|
307
|
+
return row ?? null;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
async function applyDestinationUpsert(
|
|
311
|
+
input: DispatchDestinationInput,
|
|
312
|
+
actor = currentOwnerEmail(),
|
|
313
|
+
ctx: DispatchCtx = requireDispatchCtx(),
|
|
314
|
+
) {
|
|
315
|
+
const db = getDb();
|
|
316
|
+
const timestamp = now();
|
|
317
|
+
const destinationId = input.id || id();
|
|
318
|
+
const existing = input.id ? await getDestinationById(input.id, ctx) : null;
|
|
319
|
+
|
|
320
|
+
if (existing) {
|
|
321
|
+
await db
|
|
322
|
+
.update(schema.dispatchDestinations)
|
|
323
|
+
.set({
|
|
324
|
+
name: input.name,
|
|
325
|
+
platform: input.platform,
|
|
326
|
+
destination: input.destination,
|
|
327
|
+
threadRef: input.threadRef || null,
|
|
328
|
+
notes: input.notes || null,
|
|
329
|
+
updatedAt: timestamp,
|
|
330
|
+
})
|
|
331
|
+
.where(
|
|
332
|
+
and(
|
|
333
|
+
eq(schema.dispatchDestinations.id, destinationId),
|
|
334
|
+
ctxScope(schema.dispatchDestinations, ctx),
|
|
335
|
+
),
|
|
336
|
+
);
|
|
337
|
+
} else {
|
|
338
|
+
await db.insert(schema.dispatchDestinations).values({
|
|
339
|
+
id: destinationId,
|
|
340
|
+
ownerEmail: ctx.ownerEmail,
|
|
341
|
+
orgId: ctx.orgId,
|
|
342
|
+
name: input.name,
|
|
343
|
+
platform: input.platform,
|
|
344
|
+
destination: input.destination,
|
|
345
|
+
threadRef: input.threadRef || null,
|
|
346
|
+
notes: input.notes || null,
|
|
347
|
+
createdBy: actor,
|
|
348
|
+
createdAt: timestamp,
|
|
349
|
+
updatedAt: timestamp,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
await recordAudit({
|
|
354
|
+
actor,
|
|
355
|
+
action: existing ? "destination.updated" : "destination.created",
|
|
356
|
+
targetType: "destination",
|
|
357
|
+
targetId: destinationId,
|
|
358
|
+
summary: `${existing ? "Updated" : "Created"} ${input.platform} destination ${input.name}`,
|
|
359
|
+
metadata: input,
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
return getDestinationById(destinationId, ctx);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
async function applyDestinationDelete(
|
|
366
|
+
destinationId: string,
|
|
367
|
+
actor = currentOwnerEmail(),
|
|
368
|
+
ctx: DispatchCtx = requireDispatchCtx(),
|
|
369
|
+
) {
|
|
370
|
+
const db = getDb();
|
|
371
|
+
const existing = await getDestinationById(destinationId, ctx);
|
|
372
|
+
if (!existing) {
|
|
373
|
+
throw new Error("Destination not found");
|
|
374
|
+
}
|
|
375
|
+
await db
|
|
376
|
+
.delete(schema.dispatchDestinations)
|
|
377
|
+
.where(
|
|
378
|
+
and(
|
|
379
|
+
eq(schema.dispatchDestinations.id, destinationId),
|
|
380
|
+
ctxScope(schema.dispatchDestinations, ctx),
|
|
381
|
+
),
|
|
382
|
+
);
|
|
383
|
+
await recordAudit({
|
|
384
|
+
actor,
|
|
385
|
+
action: "destination.deleted",
|
|
386
|
+
targetType: "destination",
|
|
387
|
+
targetId: destinationId,
|
|
388
|
+
summary: `Deleted ${existing.platform} destination ${existing.name}`,
|
|
389
|
+
metadata: existing,
|
|
390
|
+
});
|
|
391
|
+
return existing;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
async function notifyApprovers(requestId: string, summary: string) {
|
|
395
|
+
const policy = await getApprovalPolicy();
|
|
396
|
+
const apiKey = process.env.SENDGRID_API_KEY;
|
|
397
|
+
const from = process.env.SENDGRID_FROM_EMAIL;
|
|
398
|
+
const appUrl = process.env.APP_URL;
|
|
399
|
+
if (!apiKey || !from || !appUrl || policy.approverEmails.length === 0) return;
|
|
400
|
+
|
|
401
|
+
await fetch("https://api.sendgrid.com/v3/mail/send", {
|
|
402
|
+
method: "POST",
|
|
403
|
+
headers: {
|
|
404
|
+
Authorization: `Bearer ${apiKey}`,
|
|
405
|
+
"Content-Type": "application/json",
|
|
406
|
+
},
|
|
407
|
+
body: JSON.stringify({
|
|
408
|
+
personalizations: [
|
|
409
|
+
{
|
|
410
|
+
to: policy.approverEmails.map((email) => ({ email })),
|
|
411
|
+
subject: "Dispatch approval requested",
|
|
412
|
+
},
|
|
413
|
+
],
|
|
414
|
+
from: { email: from },
|
|
415
|
+
content: [
|
|
416
|
+
{
|
|
417
|
+
type: "text/plain",
|
|
418
|
+
value: `${summary}\n\nReview it here: ${appUrl}/approvals`,
|
|
419
|
+
},
|
|
420
|
+
],
|
|
421
|
+
custom_args: { requestId },
|
|
422
|
+
}),
|
|
423
|
+
}).catch(() => {});
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
async function createApprovalRequest(input: {
|
|
427
|
+
changeType: string;
|
|
428
|
+
targetType: string;
|
|
429
|
+
targetId?: string | null;
|
|
430
|
+
summary: string;
|
|
431
|
+
payload: unknown;
|
|
432
|
+
beforeValue?: unknown;
|
|
433
|
+
afterValue?: unknown;
|
|
434
|
+
}) {
|
|
435
|
+
const db = getDb();
|
|
436
|
+
const timestamp = now();
|
|
437
|
+
const requestId = id();
|
|
438
|
+
await db.insert(schema.dispatchApprovalRequests).values({
|
|
439
|
+
id: requestId,
|
|
440
|
+
ownerEmail: currentOwnerEmail(),
|
|
441
|
+
orgId: currentOrgId(),
|
|
442
|
+
changeType: input.changeType,
|
|
443
|
+
targetType: input.targetType,
|
|
444
|
+
targetId: input.targetId || null,
|
|
445
|
+
status: "pending",
|
|
446
|
+
summary: input.summary,
|
|
447
|
+
payload: safeJson(input.payload),
|
|
448
|
+
beforeValue:
|
|
449
|
+
input.beforeValue === undefined ? null : safeJson(input.beforeValue),
|
|
450
|
+
afterValue:
|
|
451
|
+
input.afterValue === undefined ? null : safeJson(input.afterValue),
|
|
452
|
+
requestedBy: currentOwnerEmail(),
|
|
453
|
+
reviewedBy: null,
|
|
454
|
+
reviewedAt: null,
|
|
455
|
+
createdAt: timestamp,
|
|
456
|
+
updatedAt: timestamp,
|
|
457
|
+
});
|
|
458
|
+
await recordAudit({
|
|
459
|
+
action: "approval.requested",
|
|
460
|
+
targetType: input.targetType,
|
|
461
|
+
targetId: input.targetId || requestId,
|
|
462
|
+
summary: input.summary,
|
|
463
|
+
metadata: input,
|
|
464
|
+
});
|
|
465
|
+
await notifyApprovers(requestId, input.summary);
|
|
466
|
+
return getApprovalRequest(requestId);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
export async function upsertDestination(input: DispatchDestinationInput) {
|
|
470
|
+
const policy = await getApprovalPolicy();
|
|
471
|
+
if (policy.enabled) {
|
|
472
|
+
const existing = input.id ? await getDestinationById(input.id) : null;
|
|
473
|
+
return createApprovalRequest({
|
|
474
|
+
changeType: "destination.upsert",
|
|
475
|
+
targetType: "destination",
|
|
476
|
+
targetId: input.id || null,
|
|
477
|
+
summary: `${existing ? "Update" : "Create"} ${input.platform} destination ${input.name}`,
|
|
478
|
+
payload: input,
|
|
479
|
+
beforeValue: existing,
|
|
480
|
+
afterValue: input,
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
return applyDestinationUpsert(input);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
export async function deleteDestination(destinationId: string) {
|
|
487
|
+
const policy = await getApprovalPolicy();
|
|
488
|
+
const existing = await getDestinationById(destinationId);
|
|
489
|
+
if (!existing) {
|
|
490
|
+
throw new Error("Destination not found");
|
|
491
|
+
}
|
|
492
|
+
if (policy.enabled) {
|
|
493
|
+
return createApprovalRequest({
|
|
494
|
+
changeType: "destination.delete",
|
|
495
|
+
targetType: "destination",
|
|
496
|
+
targetId: destinationId,
|
|
497
|
+
summary: `Delete ${existing.platform} destination ${existing.name}`,
|
|
498
|
+
payload: { id: destinationId },
|
|
499
|
+
beforeValue: existing,
|
|
500
|
+
afterValue: null,
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
return applyDestinationDelete(destinationId);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
export async function listApprovalRequests() {
|
|
507
|
+
const db = getDb();
|
|
508
|
+
const orgId = currentOrgId();
|
|
509
|
+
return db
|
|
510
|
+
.select()
|
|
511
|
+
.from(schema.dispatchApprovalRequests)
|
|
512
|
+
.where(
|
|
513
|
+
and(
|
|
514
|
+
eq(schema.dispatchApprovalRequests.ownerEmail, currentOwnerEmail()),
|
|
515
|
+
orgId
|
|
516
|
+
? eq(schema.dispatchApprovalRequests.orgId, orgId)
|
|
517
|
+
: isNull(schema.dispatchApprovalRequests.orgId),
|
|
518
|
+
),
|
|
519
|
+
)
|
|
520
|
+
.orderBy(desc(schema.dispatchApprovalRequests.updatedAt));
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
async function getApprovalRequest(
|
|
524
|
+
requestId: string,
|
|
525
|
+
ctx: DispatchCtx = requireDispatchCtx(),
|
|
526
|
+
) {
|
|
527
|
+
const db = getDb();
|
|
528
|
+
const [row] = await db
|
|
529
|
+
.select()
|
|
530
|
+
.from(schema.dispatchApprovalRequests)
|
|
531
|
+
.where(
|
|
532
|
+
and(
|
|
533
|
+
eq(schema.dispatchApprovalRequests.id, requestId),
|
|
534
|
+
ctxScope(schema.dispatchApprovalRequests, ctx),
|
|
535
|
+
),
|
|
536
|
+
)
|
|
537
|
+
.limit(1);
|
|
538
|
+
return row ?? null;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
async function applyApprovedRequest(request: DispatchApprovalRequest) {
|
|
542
|
+
const payload = JSON.parse(request.payload);
|
|
543
|
+
const requestCtx = {
|
|
544
|
+
ownerEmail: request.ownerEmail,
|
|
545
|
+
orgId: request.orgId,
|
|
546
|
+
};
|
|
547
|
+
if (request.changeType === "destination.upsert") {
|
|
548
|
+
return applyDestinationUpsert(
|
|
549
|
+
payload,
|
|
550
|
+
request.reviewedBy || currentOwnerEmail(),
|
|
551
|
+
requestCtx,
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
if (request.changeType === "destination.delete") {
|
|
555
|
+
return applyDestinationDelete(
|
|
556
|
+
payload.id,
|
|
557
|
+
request.reviewedBy || currentOwnerEmail(),
|
|
558
|
+
requestCtx,
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
if (request.changeType === "approval-policy.update") {
|
|
562
|
+
return applyApprovalPolicy(
|
|
563
|
+
payload,
|
|
564
|
+
request.reviewedBy || currentOwnerEmail(),
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
throw new Error(`Unsupported approval request type: ${request.changeType}`);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
export async function approveRequest(requestId: string) {
|
|
571
|
+
const db = getDb();
|
|
572
|
+
const ctx = requireDispatchCtx();
|
|
573
|
+
const request = await getApprovalRequest(requestId, ctx);
|
|
574
|
+
if (!request) throw new Error("Approval request not found");
|
|
575
|
+
if (request.status !== "pending") {
|
|
576
|
+
throw new Error("Only pending approvals can be approved");
|
|
577
|
+
}
|
|
578
|
+
const timestamp = now();
|
|
579
|
+
await db
|
|
580
|
+
.update(schema.dispatchApprovalRequests)
|
|
581
|
+
.set({
|
|
582
|
+
status: "approved",
|
|
583
|
+
reviewedBy: currentOwnerEmail(),
|
|
584
|
+
reviewedAt: timestamp,
|
|
585
|
+
updatedAt: timestamp,
|
|
586
|
+
})
|
|
587
|
+
.where(eq(schema.dispatchApprovalRequests.id, requestId));
|
|
588
|
+
const updated = await getApprovalRequest(requestId, ctx);
|
|
589
|
+
if (!updated) throw new Error("Approval request disappeared");
|
|
590
|
+
await applyApprovedRequest(updated);
|
|
591
|
+
await recordAudit({
|
|
592
|
+
action: "approval.approved",
|
|
593
|
+
targetType: updated.targetType,
|
|
594
|
+
targetId: requestId,
|
|
595
|
+
summary: `Approved ${updated.summary}`,
|
|
596
|
+
metadata: updated,
|
|
597
|
+
});
|
|
598
|
+
return updated;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
export async function rejectRequest(requestId: string, reason?: string | null) {
|
|
602
|
+
const db = getDb();
|
|
603
|
+
const request = await getApprovalRequest(requestId);
|
|
604
|
+
if (!request) throw new Error("Approval request not found");
|
|
605
|
+
if (request.status !== "pending") {
|
|
606
|
+
throw new Error("Only pending approvals can be rejected");
|
|
607
|
+
}
|
|
608
|
+
const timestamp = now();
|
|
609
|
+
await db
|
|
610
|
+
.update(schema.dispatchApprovalRequests)
|
|
611
|
+
.set({
|
|
612
|
+
status: "rejected",
|
|
613
|
+
reviewedBy: currentOwnerEmail(),
|
|
614
|
+
reviewedAt: timestamp,
|
|
615
|
+
updatedAt: timestamp,
|
|
616
|
+
})
|
|
617
|
+
.where(eq(schema.dispatchApprovalRequests.id, requestId));
|
|
618
|
+
await recordAudit({
|
|
619
|
+
action: "approval.rejected",
|
|
620
|
+
targetType: request.targetType,
|
|
621
|
+
targetId: requestId,
|
|
622
|
+
summary: `Rejected ${request.summary}`,
|
|
623
|
+
metadata: { request, reason: reason || null },
|
|
624
|
+
});
|
|
625
|
+
return getApprovalRequest(requestId);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
export async function createLinkToken(platform: string) {
|
|
629
|
+
const db = getDb();
|
|
630
|
+
const timestamp = now();
|
|
631
|
+
// 16 bytes = 128 bits of entropy. Previous size was 4 bytes (32 bits,
|
|
632
|
+
// ~4.29 billion keyspace) which is brute-forceable in well under an
|
|
633
|
+
// hour given a 7-day expiry and no rate limiting on /link attempts.
|
|
634
|
+
// Old 8-hex-char tokens minted before this change continue to verify
|
|
635
|
+
// until they expire; we don't migrate retroactively. See
|
|
636
|
+
// /tmp/security-audit/07-webhooks.md (H5).
|
|
637
|
+
const token = crypto.randomBytes(16).toString("hex");
|
|
638
|
+
const recordId = id();
|
|
639
|
+
const owner = currentOwnerEmail();
|
|
640
|
+
await db.insert(schema.dispatchLinkTokens).values({
|
|
641
|
+
id: recordId,
|
|
642
|
+
token,
|
|
643
|
+
ownerEmail: owner,
|
|
644
|
+
orgId: currentOrgId(),
|
|
645
|
+
platform,
|
|
646
|
+
createdBy: owner,
|
|
647
|
+
expiresAt: timestamp + 7 * 24 * 60 * 60 * 1000,
|
|
648
|
+
claimedAt: null,
|
|
649
|
+
claimedByExternalUserId: null,
|
|
650
|
+
claimedByExternalUserName: null,
|
|
651
|
+
createdAt: timestamp,
|
|
652
|
+
updatedAt: timestamp,
|
|
653
|
+
});
|
|
654
|
+
await recordAudit({
|
|
655
|
+
action: "identity.link-token-created",
|
|
656
|
+
targetType: "link-token",
|
|
657
|
+
targetId: recordId,
|
|
658
|
+
summary: `Created ${platform} link token for ${owner}`,
|
|
659
|
+
metadata: { token, platform },
|
|
660
|
+
});
|
|
661
|
+
return {
|
|
662
|
+
token,
|
|
663
|
+
command: `/link ${token}`,
|
|
664
|
+
platform,
|
|
665
|
+
expiresAt: timestamp + 7 * 24 * 60 * 60 * 1000,
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
export async function listIdentityState() {
|
|
670
|
+
const db = getDb();
|
|
671
|
+
const owner = currentOwnerEmail();
|
|
672
|
+
const orgId = currentOrgId();
|
|
673
|
+
const filters = and(
|
|
674
|
+
eq(schema.dispatchIdentityLinks.ownerEmail, owner),
|
|
675
|
+
orgId
|
|
676
|
+
? eq(schema.dispatchIdentityLinks.orgId, orgId)
|
|
677
|
+
: isNull(schema.dispatchIdentityLinks.orgId),
|
|
678
|
+
);
|
|
679
|
+
const tokenFilters = and(
|
|
680
|
+
eq(schema.dispatchLinkTokens.ownerEmail, owner),
|
|
681
|
+
orgId
|
|
682
|
+
? eq(schema.dispatchLinkTokens.orgId, orgId)
|
|
683
|
+
: isNull(schema.dispatchLinkTokens.orgId),
|
|
684
|
+
);
|
|
685
|
+
const [links, tokens] = await Promise.all([
|
|
686
|
+
db
|
|
687
|
+
.select()
|
|
688
|
+
.from(schema.dispatchIdentityLinks)
|
|
689
|
+
.where(filters)
|
|
690
|
+
.orderBy(desc(schema.dispatchIdentityLinks.updatedAt)),
|
|
691
|
+
db
|
|
692
|
+
.select()
|
|
693
|
+
.from(schema.dispatchLinkTokens)
|
|
694
|
+
.where(tokenFilters)
|
|
695
|
+
.orderBy(desc(schema.dispatchLinkTokens.updatedAt)),
|
|
696
|
+
]);
|
|
697
|
+
return { links, tokens };
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
export async function resolveLinkedOwner(
|
|
701
|
+
platform: string,
|
|
702
|
+
externalUserId?: string | null,
|
|
703
|
+
options: {
|
|
704
|
+
orgId?: string | null;
|
|
705
|
+
allowAnyOrgFallback?: boolean;
|
|
706
|
+
} = {},
|
|
707
|
+
) {
|
|
708
|
+
if (!externalUserId) return null;
|
|
709
|
+
const db = getDb();
|
|
710
|
+
const orgId = options.orgId !== undefined ? options.orgId : currentOrgId();
|
|
711
|
+
const rows = await db
|
|
712
|
+
.select()
|
|
713
|
+
.from(schema.dispatchIdentityLinks)
|
|
714
|
+
.where(
|
|
715
|
+
and(
|
|
716
|
+
eq(schema.dispatchIdentityLinks.platform, platform),
|
|
717
|
+
eq(schema.dispatchIdentityLinks.externalUserId, externalUserId),
|
|
718
|
+
orgId
|
|
719
|
+
? eq(schema.dispatchIdentityLinks.orgId, orgId)
|
|
720
|
+
: isNull(schema.dispatchIdentityLinks.orgId),
|
|
721
|
+
),
|
|
722
|
+
)
|
|
723
|
+
.orderBy(desc(schema.dispatchIdentityLinks.updatedAt))
|
|
724
|
+
.limit(1);
|
|
725
|
+
if (rows[0]?.ownerEmail) return rows[0].ownerEmail;
|
|
726
|
+
|
|
727
|
+
if (!options.allowAnyOrgFallback || orgId) return null;
|
|
728
|
+
|
|
729
|
+
// Webhook processors run outside a normal request/org context. A linked
|
|
730
|
+
// Slack/Telegram identity may still be scoped to an org, so fall back to any
|
|
731
|
+
// org only when every matching link resolves to the same owner.
|
|
732
|
+
const fallbackRows = await db
|
|
733
|
+
.select()
|
|
734
|
+
.from(schema.dispatchIdentityLinks)
|
|
735
|
+
.where(
|
|
736
|
+
and(
|
|
737
|
+
eq(schema.dispatchIdentityLinks.platform, platform),
|
|
738
|
+
eq(schema.dispatchIdentityLinks.externalUserId, externalUserId),
|
|
739
|
+
),
|
|
740
|
+
)
|
|
741
|
+
.orderBy(desc(schema.dispatchIdentityLinks.updatedAt))
|
|
742
|
+
.limit(25);
|
|
743
|
+
const owners = new Set(fallbackRows.map((row) => row.ownerEmail));
|
|
744
|
+
return owners.size === 1 ? fallbackRows[0]?.ownerEmail || null : null;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
export async function consumeLinkToken(input: {
|
|
748
|
+
platform: string;
|
|
749
|
+
token: string;
|
|
750
|
+
externalUserId?: string | null;
|
|
751
|
+
externalUserName?: string | null;
|
|
752
|
+
}) {
|
|
753
|
+
if (!input.externalUserId) {
|
|
754
|
+
throw new Error("Linking requires a platform user id");
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
// Rate-limit failed attempts per (platform, externalUserId). Once
|
|
758
|
+
// tripped, all further attempts are short-circuited until the block
|
|
759
|
+
// window passes — including the lookup, so an attacker can't probe
|
|
760
|
+
// for valid tokens during the block.
|
|
761
|
+
const blockState = isLinkAttemptBlocked(input.platform, input.externalUserId);
|
|
762
|
+
if (blockState.blocked) {
|
|
763
|
+
throw new LinkRateLimitError(blockState.retryAfterMs);
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
const db = getDb();
|
|
767
|
+
const tokenRows = await db
|
|
768
|
+
.select()
|
|
769
|
+
.from(schema.dispatchLinkTokens)
|
|
770
|
+
.where(
|
|
771
|
+
and(
|
|
772
|
+
eq(schema.dispatchLinkTokens.platform, input.platform),
|
|
773
|
+
eq(schema.dispatchLinkTokens.token, input.token),
|
|
774
|
+
),
|
|
775
|
+
)
|
|
776
|
+
.orderBy(desc(schema.dispatchLinkTokens.createdAt))
|
|
777
|
+
.limit(2);
|
|
778
|
+
if (tokenRows.length > 1) {
|
|
779
|
+
recordLinkFailure(input.platform, input.externalUserId);
|
|
780
|
+
throw new Error("Link token is ambiguous. Create a fresh token and retry.");
|
|
781
|
+
}
|
|
782
|
+
const tokenRow = tokenRows[0];
|
|
783
|
+
if (!tokenRow) {
|
|
784
|
+
recordLinkFailure(input.platform, input.externalUserId);
|
|
785
|
+
throw new Error("Link token not found");
|
|
786
|
+
}
|
|
787
|
+
if (tokenRow.claimedAt) {
|
|
788
|
+
recordLinkFailure(input.platform, input.externalUserId);
|
|
789
|
+
throw new Error("Link token has already been claimed");
|
|
790
|
+
}
|
|
791
|
+
if (tokenRow.expiresAt < now()) {
|
|
792
|
+
recordLinkFailure(input.platform, input.externalUserId);
|
|
793
|
+
throw new Error("Link token has expired");
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
const timestamp = now();
|
|
797
|
+
const [existing] = await db
|
|
798
|
+
.select()
|
|
799
|
+
.from(schema.dispatchIdentityLinks)
|
|
800
|
+
.where(
|
|
801
|
+
and(
|
|
802
|
+
eq(schema.dispatchIdentityLinks.platform, input.platform),
|
|
803
|
+
eq(schema.dispatchIdentityLinks.externalUserId, input.externalUserId),
|
|
804
|
+
tokenRow.orgId
|
|
805
|
+
? eq(schema.dispatchIdentityLinks.orgId, tokenRow.orgId)
|
|
806
|
+
: isNull(schema.dispatchIdentityLinks.orgId),
|
|
807
|
+
),
|
|
808
|
+
)
|
|
809
|
+
.limit(1);
|
|
810
|
+
|
|
811
|
+
if (existing) {
|
|
812
|
+
await db
|
|
813
|
+
.update(schema.dispatchIdentityLinks)
|
|
814
|
+
.set({
|
|
815
|
+
ownerEmail: tokenRow.ownerEmail,
|
|
816
|
+
orgId: tokenRow.orgId,
|
|
817
|
+
externalUserName: input.externalUserName || null,
|
|
818
|
+
linkedBy: tokenRow.createdBy,
|
|
819
|
+
updatedAt: timestamp,
|
|
820
|
+
})
|
|
821
|
+
.where(eq(schema.dispatchIdentityLinks.id, existing.id));
|
|
822
|
+
} else {
|
|
823
|
+
await db.insert(schema.dispatchIdentityLinks).values({
|
|
824
|
+
id: id(),
|
|
825
|
+
ownerEmail: tokenRow.ownerEmail,
|
|
826
|
+
orgId: tokenRow.orgId,
|
|
827
|
+
platform: input.platform,
|
|
828
|
+
externalUserId: input.externalUserId,
|
|
829
|
+
externalUserName: input.externalUserName || null,
|
|
830
|
+
linkedBy: tokenRow.createdBy,
|
|
831
|
+
createdAt: timestamp,
|
|
832
|
+
updatedAt: timestamp,
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
await db
|
|
837
|
+
.update(schema.dispatchLinkTokens)
|
|
838
|
+
.set({
|
|
839
|
+
claimedAt: timestamp,
|
|
840
|
+
claimedByExternalUserId: input.externalUserId,
|
|
841
|
+
claimedByExternalUserName: input.externalUserName || null,
|
|
842
|
+
updatedAt: timestamp,
|
|
843
|
+
})
|
|
844
|
+
.where(eq(schema.dispatchLinkTokens.id, tokenRow.id));
|
|
845
|
+
|
|
846
|
+
// Successful claim — reset the rate-limit budget so subsequent
|
|
847
|
+
// links from this external user start fresh.
|
|
848
|
+
clearLinkFailures(input.platform, input.externalUserId);
|
|
849
|
+
|
|
850
|
+
await recordAudit({
|
|
851
|
+
actor: tokenRow.createdBy,
|
|
852
|
+
ownerEmail: tokenRow.ownerEmail,
|
|
853
|
+
orgId: tokenRow.orgId,
|
|
854
|
+
action: "identity.linked",
|
|
855
|
+
targetType: "identity-link",
|
|
856
|
+
targetId: input.externalUserId,
|
|
857
|
+
summary: `Linked ${input.platform} user ${input.externalUserName || input.externalUserId}`,
|
|
858
|
+
metadata: input,
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
return tokenRow.ownerEmail;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
export async function listOverview() {
|
|
865
|
+
const [destinations, approvals, identities, audit, settings] =
|
|
866
|
+
await Promise.all([
|
|
867
|
+
listDestinations(),
|
|
868
|
+
listApprovalRequests(),
|
|
869
|
+
listIdentityState(),
|
|
870
|
+
listAuditEvents(12),
|
|
871
|
+
getApprovalPolicy(),
|
|
872
|
+
]);
|
|
873
|
+
|
|
874
|
+
return {
|
|
875
|
+
counts: {
|
|
876
|
+
destinations: destinations.length,
|
|
877
|
+
pendingApprovals: approvals.filter((item) => item.status === "pending")
|
|
878
|
+
.length,
|
|
879
|
+
linkedIdentities: identities.links.length,
|
|
880
|
+
activeTokens: identities.tokens.filter(
|
|
881
|
+
(item) => !item.claimedAt && item.expiresAt > now(),
|
|
882
|
+
).length,
|
|
883
|
+
},
|
|
884
|
+
recentDestinations: destinations.slice(0, 5),
|
|
885
|
+
recentApprovals: approvals.slice(0, 5),
|
|
886
|
+
recentAudit: audit.slice(0, 8),
|
|
887
|
+
settings,
|
|
888
|
+
};
|
|
889
|
+
}
|