@flowdrop/flowdrop 1.0.0
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/LICENSE +21 -0
- package/README.md +252 -0
- package/dist/adapters/WorkflowAdapter.d.ts +167 -0
- package/dist/adapters/WorkflowAdapter.js +368 -0
- package/dist/adapters/agentspec/AgentSpecAdapter.d.ts +96 -0
- package/dist/adapters/agentspec/AgentSpecAdapter.js +626 -0
- package/dist/adapters/agentspec/agentAdapter.d.ts +59 -0
- package/dist/adapters/agentspec/agentAdapter.js +91 -0
- package/dist/adapters/agentspec/autoLayout.d.ts +34 -0
- package/dist/adapters/agentspec/autoLayout.js +127 -0
- package/dist/adapters/agentspec/componentTypeDefaults.d.ts +73 -0
- package/dist/adapters/agentspec/componentTypeDefaults.js +238 -0
- package/dist/adapters/agentspec/defaultNodeTypes.d.ts +53 -0
- package/dist/adapters/agentspec/defaultNodeTypes.js +561 -0
- package/dist/adapters/agentspec/index.d.ts +37 -0
- package/dist/adapters/agentspec/index.js +39 -0
- package/dist/adapters/agentspec/validator.d.ts +34 -0
- package/dist/adapters/agentspec/validator.js +169 -0
- package/dist/api/enhanced-client.d.ts +183 -0
- package/dist/api/enhanced-client.js +430 -0
- package/dist/components/App.svelte +981 -0
- package/dist/components/App.svelte.d.ts +54 -0
- package/dist/components/CanvasBanner.stories.svelte +29 -0
- package/dist/components/CanvasBanner.stories.svelte.d.ts +27 -0
- package/dist/components/CanvasBanner.svelte +57 -0
- package/dist/components/CanvasBanner.svelte.d.ts +8 -0
- package/dist/components/ConfigForm.svelte +1138 -0
- package/dist/components/ConfigForm.svelte.d.ts +44 -0
- package/dist/components/ConfigModal.svelte +188 -0
- package/dist/components/ConfigModal.svelte.d.ts +13 -0
- package/dist/components/ConfigPanel.stories.svelte +47 -0
- package/dist/components/ConfigPanel.stories.svelte.d.ts +27 -0
- package/dist/components/ConfigPanel.svelte +182 -0
- package/dist/components/ConfigPanel.svelte.d.ts +32 -0
- package/dist/components/ConnectionLine.svelte +32 -0
- package/dist/components/ConnectionLine.svelte.d.ts +3 -0
- package/dist/components/EdgeRefresher.svelte +41 -0
- package/dist/components/EdgeRefresher.svelte.d.ts +9 -0
- package/dist/components/FlowDropZone.svelte +83 -0
- package/dist/components/FlowDropZone.svelte.d.ts +13 -0
- package/dist/components/LoadingSpinner.stories.svelte +30 -0
- package/dist/components/LoadingSpinner.stories.svelte.d.ts +27 -0
- package/dist/components/LoadingSpinner.svelte +36 -0
- package/dist/components/LoadingSpinner.svelte.d.ts +8 -0
- package/dist/components/Logo.stories.svelte +22 -0
- package/dist/components/Logo.stories.svelte.d.ts +27 -0
- package/dist/components/Logo.svelte +102 -0
- package/dist/components/Logo.svelte.d.ts +26 -0
- package/dist/components/LogsSidebar.svelte +563 -0
- package/dist/components/LogsSidebar.svelte.d.ts +17 -0
- package/dist/components/MarkdownDisplay.stories.svelte +36 -0
- package/dist/components/MarkdownDisplay.stories.svelte.d.ts +27 -0
- package/dist/components/MarkdownDisplay.svelte +29 -0
- package/dist/components/MarkdownDisplay.svelte.d.ts +7 -0
- package/dist/components/Navbar.stories.svelte +53 -0
- package/dist/components/Navbar.stories.svelte.d.ts +27 -0
- package/dist/components/Navbar.svelte +726 -0
- package/dist/components/Navbar.svelte.d.ts +29 -0
- package/dist/components/NodeSidebar.svelte +762 -0
- package/dist/components/NodeSidebar.svelte.d.ts +9 -0
- package/dist/components/NodeStatusOverlay.stories.svelte +85 -0
- package/dist/components/NodeStatusOverlay.stories.svelte.d.ts +27 -0
- package/dist/components/NodeStatusOverlay.svelte +327 -0
- package/dist/components/NodeStatusOverlay.svelte.d.ts +11 -0
- package/dist/components/PipelineStatus.svelte +314 -0
- package/dist/components/PipelineStatus.svelte.d.ts +20 -0
- package/dist/components/PortCoordinateTracker.svelte +58 -0
- package/dist/components/PortCoordinateTracker.svelte.d.ts +12 -0
- package/dist/components/ReadOnlyDetails.svelte +170 -0
- package/dist/components/ReadOnlyDetails.svelte.d.ts +25 -0
- package/dist/components/SchemaForm.stories.svelte +116 -0
- package/dist/components/SchemaForm.stories.svelte.d.ts +27 -0
- package/dist/components/SchemaForm.svelte +536 -0
- package/dist/components/SchemaForm.svelte.d.ts +83 -0
- package/dist/components/SettingsModal.svelte +279 -0
- package/dist/components/SettingsModal.svelte.d.ts +23 -0
- package/dist/components/SettingsPanel.svelte +638 -0
- package/dist/components/SettingsPanel.svelte.d.ts +21 -0
- package/dist/components/StatusIcon.stories.svelte +60 -0
- package/dist/components/StatusIcon.stories.svelte.d.ts +27 -0
- package/dist/components/StatusIcon.svelte +119 -0
- package/dist/components/StatusIcon.svelte.d.ts +10 -0
- package/dist/components/StatusLabel.stories.svelte +17 -0
- package/dist/components/StatusLabel.stories.svelte.d.ts +27 -0
- package/dist/components/StatusLabel.svelte +33 -0
- package/dist/components/StatusLabel.svelte.d.ts +7 -0
- package/dist/components/ThemeToggle.stories.svelte +25 -0
- package/dist/components/ThemeToggle.stories.svelte.d.ts +27 -0
- package/dist/components/ThemeToggle.svelte +185 -0
- package/dist/components/ThemeToggle.svelte.d.ts +14 -0
- package/dist/components/UniversalNode.svelte +155 -0
- package/dist/components/UniversalNode.svelte.d.ts +15 -0
- package/dist/components/WorkflowEditor.svelte +1035 -0
- package/dist/components/WorkflowEditor.svelte.d.ts +23 -0
- package/dist/components/form/FormArray.svelte +1049 -0
- package/dist/components/form/FormArray.svelte.d.ts +22 -0
- package/dist/components/form/FormAutocomplete.svelte +1009 -0
- package/dist/components/form/FormAutocomplete.svelte.d.ts +25 -0
- package/dist/components/form/FormCheckboxGroup.stories.svelte +28 -0
- package/dist/components/form/FormCheckboxGroup.stories.svelte.d.ts +27 -0
- package/dist/components/form/FormCheckboxGroup.svelte +155 -0
- package/dist/components/form/FormCheckboxGroup.svelte.d.ts +17 -0
- package/dist/components/form/FormCodeEditor.svelte +458 -0
- package/dist/components/form/FormCodeEditor.svelte.d.ts +25 -0
- package/dist/components/form/FormField.svelte +417 -0
- package/dist/components/form/FormField.svelte.d.ts +29 -0
- package/dist/components/form/FormFieldLight.svelte +425 -0
- package/dist/components/form/FormFieldLight.svelte.d.ts +18 -0
- package/dist/components/form/FormFieldWrapper.stories.svelte +53 -0
- package/dist/components/form/FormFieldWrapper.stories.svelte.d.ts +27 -0
- package/dist/components/form/FormFieldWrapper.svelte +125 -0
- package/dist/components/form/FormFieldWrapper.svelte.d.ts +18 -0
- package/dist/components/form/FormFieldset.svelte +142 -0
- package/dist/components/form/FormFieldset.svelte.d.ts +11 -0
- package/dist/components/form/FormMarkdownEditor.svelte +752 -0
- package/dist/components/form/FormMarkdownEditor.svelte.d.ts +33 -0
- package/dist/components/form/FormNumberField.stories.svelte +36 -0
- package/dist/components/form/FormNumberField.stories.svelte.d.ts +27 -0
- package/dist/components/form/FormNumberField.svelte +112 -0
- package/dist/components/form/FormNumberField.svelte.d.ts +25 -0
- package/dist/components/form/FormRangeField.stories.svelte +31 -0
- package/dist/components/form/FormRangeField.stories.svelte.d.ts +27 -0
- package/dist/components/form/FormRangeField.svelte +246 -0
- package/dist/components/form/FormRangeField.svelte.d.ts +23 -0
- package/dist/components/form/FormSelect.stories.svelte +50 -0
- package/dist/components/form/FormSelect.stories.svelte.d.ts +27 -0
- package/dist/components/form/FormSelect.svelte +129 -0
- package/dist/components/form/FormSelect.svelte.d.ts +20 -0
- package/dist/components/form/FormTemplateEditor.svelte +825 -0
- package/dist/components/form/FormTemplateEditor.svelte.d.ts +41 -0
- package/dist/components/form/FormTextField.stories.svelte +30 -0
- package/dist/components/form/FormTextField.stories.svelte.d.ts +27 -0
- package/dist/components/form/FormTextField.svelte +91 -0
- package/dist/components/form/FormTextField.svelte.d.ts +19 -0
- package/dist/components/form/FormTextarea.stories.svelte +34 -0
- package/dist/components/form/FormTextarea.stories.svelte.d.ts +27 -0
- package/dist/components/form/FormTextarea.svelte +97 -0
- package/dist/components/form/FormTextarea.svelte.d.ts +21 -0
- package/dist/components/form/FormToggle.stories.svelte +30 -0
- package/dist/components/form/FormToggle.stories.svelte.d.ts +27 -0
- package/dist/components/form/FormToggle.svelte +126 -0
- package/dist/components/form/FormToggle.svelte.d.ts +19 -0
- package/dist/components/form/FormUISchemaRenderer.svelte +136 -0
- package/dist/components/form/FormUISchemaRenderer.svelte.d.ts +32 -0
- package/dist/components/form/index.d.ts +50 -0
- package/dist/components/form/index.js +54 -0
- package/dist/components/form/templateAutocomplete.d.ts +29 -0
- package/dist/components/form/templateAutocomplete.js +254 -0
- package/dist/components/form/types.d.ts +485 -0
- package/dist/components/form/types.js +73 -0
- package/dist/components/interrupt/ChoicePrompt.stories.svelte +52 -0
- package/dist/components/interrupt/ChoicePrompt.stories.svelte.d.ts +27 -0
- package/dist/components/interrupt/ChoicePrompt.svelte +401 -0
- package/dist/components/interrupt/ChoicePrompt.svelte.d.ts +23 -0
- package/dist/components/interrupt/ConfirmationPrompt.stories.svelte +71 -0
- package/dist/components/interrupt/ConfirmationPrompt.stories.svelte.d.ts +27 -0
- package/dist/components/interrupt/ConfirmationPrompt.svelte +292 -0
- package/dist/components/interrupt/ConfirmationPrompt.svelte.d.ts +25 -0
- package/dist/components/interrupt/FormPrompt.svelte +236 -0
- package/dist/components/interrupt/FormPrompt.svelte.d.ts +23 -0
- package/dist/components/interrupt/InterruptBubble.svelte +601 -0
- package/dist/components/interrupt/InterruptBubble.svelte.d.ts +16 -0
- package/dist/components/interrupt/ReviewPrompt.stories.svelte +67 -0
- package/dist/components/interrupt/ReviewPrompt.stories.svelte.d.ts +27 -0
- package/dist/components/interrupt/ReviewPrompt.svelte +861 -0
- package/dist/components/interrupt/ReviewPrompt.svelte.d.ts +23 -0
- package/dist/components/interrupt/TextInputPrompt.stories.svelte +47 -0
- package/dist/components/interrupt/TextInputPrompt.stories.svelte.d.ts +27 -0
- package/dist/components/interrupt/TextInputPrompt.svelte +346 -0
- package/dist/components/interrupt/TextInputPrompt.svelte.d.ts +23 -0
- package/dist/components/interrupt/index.d.ts +13 -0
- package/dist/components/interrupt/index.js +15 -0
- package/dist/components/layouts/MainLayout.svelte +718 -0
- package/dist/components/layouts/MainLayout.svelte.d.ts +62 -0
- package/dist/components/nodes/GatewayNode.stories.svelte +108 -0
- package/dist/components/nodes/GatewayNode.stories.svelte.d.ts +26 -0
- package/dist/components/nodes/GatewayNode.svelte +591 -0
- package/dist/components/nodes/GatewayNode.svelte.d.ts +15 -0
- package/dist/components/nodes/IdeaNode.stories.svelte +52 -0
- package/dist/components/nodes/IdeaNode.stories.svelte.d.ts +26 -0
- package/dist/components/nodes/IdeaNode.svelte +455 -0
- package/dist/components/nodes/IdeaNode.svelte.d.ts +24 -0
- package/dist/components/nodes/NotesNode.stories.svelte +76 -0
- package/dist/components/nodes/NotesNode.stories.svelte.d.ts +26 -0
- package/dist/components/nodes/NotesNode.svelte +378 -0
- package/dist/components/nodes/NotesNode.svelte.d.ts +24 -0
- package/dist/components/nodes/SimpleNode.stories.svelte +159 -0
- package/dist/components/nodes/SimpleNode.stories.svelte.d.ts +26 -0
- package/dist/components/nodes/SimpleNode.svelte +451 -0
- package/dist/components/nodes/SimpleNode.svelte.d.ts +25 -0
- package/dist/components/nodes/SquareNode.stories.svelte +82 -0
- package/dist/components/nodes/SquareNode.stories.svelte.d.ts +26 -0
- package/dist/components/nodes/SquareNode.svelte +407 -0
- package/dist/components/nodes/SquareNode.svelte.d.ts +25 -0
- package/dist/components/nodes/TerminalNode.stories.svelte +25 -0
- package/dist/components/nodes/TerminalNode.stories.svelte.d.ts +26 -0
- package/dist/components/nodes/TerminalNode.svelte +690 -0
- package/dist/components/nodes/TerminalNode.svelte.d.ts +25 -0
- package/dist/components/nodes/ToolNode.stories.svelte +189 -0
- package/dist/components/nodes/ToolNode.stories.svelte.d.ts +26 -0
- package/dist/components/nodes/ToolNode.svelte +471 -0
- package/dist/components/nodes/ToolNode.svelte.d.ts +36 -0
- package/dist/components/nodes/WorkflowNode.stories.svelte +55 -0
- package/dist/components/nodes/WorkflowNode.stories.svelte.d.ts +26 -0
- package/dist/components/nodes/WorkflowNode.svelte +571 -0
- package/dist/components/nodes/WorkflowNode.svelte.d.ts +15 -0
- package/dist/components/playground/ChatPanel.svelte +905 -0
- package/dist/components/playground/ChatPanel.svelte.d.ts +46 -0
- package/dist/components/playground/ExecutionLogs.svelte +488 -0
- package/dist/components/playground/ExecutionLogs.svelte.d.ts +14 -0
- package/dist/components/playground/InputCollector.svelte +444 -0
- package/dist/components/playground/InputCollector.svelte.d.ts +16 -0
- package/dist/components/playground/MessageBubble.stories.svelte +62 -0
- package/dist/components/playground/MessageBubble.stories.svelte.d.ts +27 -0
- package/dist/components/playground/MessageBubble.svelte +633 -0
- package/dist/components/playground/MessageBubble.svelte.d.ts +24 -0
- package/dist/components/playground/Playground.svelte +1075 -0
- package/dist/components/playground/Playground.svelte.d.ts +25 -0
- package/dist/components/playground/PlaygroundModal.svelte +220 -0
- package/dist/components/playground/PlaygroundModal.svelte.d.ts +25 -0
- package/dist/components/playground/SessionManager.svelte +538 -0
- package/dist/components/playground/SessionManager.svelte.d.ts +20 -0
- package/dist/config/agentSpecEndpoints.d.ts +70 -0
- package/dist/config/agentSpecEndpoints.js +65 -0
- package/dist/config/constants.d.ts +43 -0
- package/dist/config/constants.js +31 -0
- package/dist/config/defaultCategories.d.ts +7 -0
- package/dist/config/defaultCategories.js +126 -0
- package/dist/config/defaultPortConfig.d.ts +6 -0
- package/dist/config/defaultPortConfig.js +201 -0
- package/dist/config/endpoints.d.ts +160 -0
- package/dist/config/endpoints.js +146 -0
- package/dist/config/runtimeConfig.d.ts +47 -0
- package/dist/config/runtimeConfig.js +80 -0
- package/dist/core/index.d.ts +75 -0
- package/dist/core/index.js +92 -0
- package/dist/display/index.d.ts +29 -0
- package/dist/display/index.js +36 -0
- package/dist/editor/index.d.ts +95 -0
- package/dist/editor/index.js +138 -0
- package/dist/form/code.d.ts +101 -0
- package/dist/form/code.js +168 -0
- package/dist/form/fieldRegistry.d.ts +169 -0
- package/dist/form/fieldRegistry.js +152 -0
- package/dist/form/full.d.ts +56 -0
- package/dist/form/full.js +80 -0
- package/dist/form/index.d.ts +77 -0
- package/dist/form/index.js +91 -0
- package/dist/form/markdown.d.ts +69 -0
- package/dist/form/markdown.js +103 -0
- package/dist/helpers/nodeLayoutHelper.d.ts +14 -0
- package/dist/helpers/nodeLayoutHelper.js +19 -0
- package/dist/helpers/proximityConnect.d.ts +94 -0
- package/dist/helpers/proximityConnect.js +314 -0
- package/dist/helpers/workflowEditorHelper.d.ts +183 -0
- package/dist/helpers/workflowEditorHelper.js +595 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +64 -0
- package/dist/mocks/app-environment.d.ts +8 -0
- package/dist/mocks/app-environment.js +16 -0
- package/dist/mocks/app-forms.d.ts +2 -0
- package/dist/mocks/app-forms.js +22 -0
- package/dist/mocks/app-navigation.d.ts +5 -0
- package/dist/mocks/app-navigation.js +36 -0
- package/dist/mocks/app-stores.d.ts +14 -0
- package/dist/mocks/app-stores.js +26 -0
- package/dist/playground/index.d.ts +131 -0
- package/dist/playground/index.js +172 -0
- package/dist/playground/mount.d.ts +203 -0
- package/dist/playground/mount.js +235 -0
- package/dist/registry/BaseRegistry.d.ts +92 -0
- package/dist/registry/BaseRegistry.js +124 -0
- package/dist/registry/builtinFormats.d.ts +23 -0
- package/dist/registry/builtinFormats.js +70 -0
- package/dist/registry/builtinNodes.d.ts +77 -0
- package/dist/registry/builtinNodes.js +211 -0
- package/dist/registry/index.d.ts +8 -0
- package/dist/registry/index.js +12 -0
- package/dist/registry/nodeComponentRegistry.d.ts +276 -0
- package/dist/registry/nodeComponentRegistry.js +262 -0
- package/dist/registry/plugin.d.ts +215 -0
- package/dist/registry/plugin.js +249 -0
- package/dist/registry/workflowFormatRegistry.d.ts +122 -0
- package/dist/registry/workflowFormatRegistry.js +96 -0
- package/dist/schema/index.d.ts +23 -0
- package/dist/schema/index.js +23 -0
- package/dist/schemas/v1/workflow.schema.json +1078 -0
- package/dist/services/agentSpecExecutionService.d.ts +106 -0
- package/dist/services/agentSpecExecutionService.js +334 -0
- package/dist/services/api.d.ts +115 -0
- package/dist/services/api.js +214 -0
- package/dist/services/apiVariableService.d.ts +114 -0
- package/dist/services/apiVariableService.js +338 -0
- package/dist/services/autoSaveService.d.ts +112 -0
- package/dist/services/autoSaveService.js +227 -0
- package/dist/services/categoriesApi.d.ts +14 -0
- package/dist/services/categoriesApi.js +49 -0
- package/dist/services/draftStorage.d.ts +171 -0
- package/dist/services/draftStorage.js +299 -0
- package/dist/services/dynamicSchemaService.d.ts +108 -0
- package/dist/services/dynamicSchemaService.js +444 -0
- package/dist/services/globalSave.d.ts +69 -0
- package/dist/services/globalSave.js +248 -0
- package/dist/services/historyService.d.ts +208 -0
- package/dist/services/historyService.js +321 -0
- package/dist/services/interruptService.d.ts +133 -0
- package/dist/services/interruptService.js +280 -0
- package/dist/services/nodeExecutionService.d.ts +63 -0
- package/dist/services/nodeExecutionService.js +266 -0
- package/dist/services/playgroundService.d.ts +130 -0
- package/dist/services/playgroundService.js +321 -0
- package/dist/services/portConfigApi.d.ts +14 -0
- package/dist/services/portConfigApi.js +54 -0
- package/dist/services/settingsService.d.ts +92 -0
- package/dist/services/settingsService.js +196 -0
- package/dist/services/toastService.d.ts +156 -0
- package/dist/services/toastService.js +265 -0
- package/dist/services/variableService.d.ts +141 -0
- package/dist/services/variableService.js +463 -0
- package/dist/services/workflowStorage.d.ts +37 -0
- package/dist/services/workflowStorage.js +116 -0
- package/dist/settings/index.d.ts +25 -0
- package/dist/settings/index.js +33 -0
- package/dist/stores/categoriesStore.svelte.d.ts +32 -0
- package/dist/stores/categoriesStore.svelte.js +77 -0
- package/dist/stores/editorStateMachine.svelte.d.ts +42 -0
- package/dist/stores/editorStateMachine.svelte.js +132 -0
- package/dist/stores/historyStore.svelte.d.ts +136 -0
- package/dist/stores/historyStore.svelte.js +207 -0
- package/dist/stores/interruptStore.svelte.d.ts +179 -0
- package/dist/stores/interruptStore.svelte.js +346 -0
- package/dist/stores/playgroundStore.svelte.d.ts +230 -0
- package/dist/stores/playgroundStore.svelte.js +515 -0
- package/dist/stores/portCoordinateStore.svelte.d.ts +66 -0
- package/dist/stores/portCoordinateStore.svelte.js +186 -0
- package/dist/stores/settingsStore.svelte.d.ts +158 -0
- package/dist/stores/settingsStore.svelte.js +544 -0
- package/dist/stores/workflowStore.svelte.d.ts +260 -0
- package/dist/stores/workflowStore.svelte.js +649 -0
- package/dist/stories/CanvasDecorator.svelte +49 -0
- package/dist/stories/CanvasDecorator.svelte.d.ts +8 -0
- package/dist/stories/NodeDecorator.svelte +73 -0
- package/dist/stories/NodeDecorator.svelte.d.ts +8 -0
- package/dist/stories/utils.d.ts +93 -0
- package/dist/stories/utils.js +122 -0
- package/dist/styles/base.css +1300 -0
- package/dist/styles/toast.css +35 -0
- package/dist/styles/tokens.css +475 -0
- package/dist/svelte-app.d.ts +150 -0
- package/dist/svelte-app.js +295 -0
- package/dist/types/agentspec.d.ts +318 -0
- package/dist/types/agentspec.js +48 -0
- package/dist/types/auth.d.ts +263 -0
- package/dist/types/auth.js +229 -0
- package/dist/types/config.d.ts +151 -0
- package/dist/types/config.js +7 -0
- package/dist/types/events.d.ts +190 -0
- package/dist/types/events.js +30 -0
- package/dist/types/index.d.ts +1234 -0
- package/dist/types/index.js +27 -0
- package/dist/types/interrupt.d.ts +390 -0
- package/dist/types/interrupt.js +145 -0
- package/dist/types/interruptState.d.ts +211 -0
- package/dist/types/interruptState.js +308 -0
- package/dist/types/playground.d.ts +351 -0
- package/dist/types/playground.js +95 -0
- package/dist/types/settings.d.ts +189 -0
- package/dist/types/settings.js +97 -0
- package/dist/types/uischema.d.ts +144 -0
- package/dist/types/uischema.js +51 -0
- package/dist/utils/colors.d.ts +288 -0
- package/dist/utils/colors.js +548 -0
- package/dist/utils/config.d.ts +37 -0
- package/dist/utils/config.js +226 -0
- package/dist/utils/connections.d.ts +125 -0
- package/dist/utils/connections.js +414 -0
- package/dist/utils/errors.d.ts +28 -0
- package/dist/utils/errors.js +44 -0
- package/dist/utils/fetchWithAuth.d.ts +25 -0
- package/dist/utils/fetchWithAuth.js +34 -0
- package/dist/utils/handleIds.d.ts +35 -0
- package/dist/utils/handleIds.js +58 -0
- package/dist/utils/handlePositioning.d.ts +31 -0
- package/dist/utils/handlePositioning.js +35 -0
- package/dist/utils/icons.d.ts +106 -0
- package/dist/utils/icons.js +157 -0
- package/dist/utils/logger.d.ts +47 -0
- package/dist/utils/logger.js +72 -0
- package/dist/utils/nodeStatus.d.ts +53 -0
- package/dist/utils/nodeStatus.js +183 -0
- package/dist/utils/nodeTypes.d.ts +117 -0
- package/dist/utils/nodeTypes.js +244 -0
- package/dist/utils/nodeWrapper.d.ts +39 -0
- package/dist/utils/nodeWrapper.js +62 -0
- package/dist/utils/performanceUtils.d.ts +30 -0
- package/dist/utils/performanceUtils.js +108 -0
- package/dist/utils/sanitize.d.ts +19 -0
- package/dist/utils/sanitize.js +31 -0
- package/dist/utils/uischema.d.ts +52 -0
- package/dist/utils/uischema.js +88 -0
- package/dist/utils/validation.d.ts +29 -0
- package/dist/utils/validation.js +39 -0
- package/package.json +292 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side API service for FlowDrop
|
|
3
|
+
* Provides methods to interact with the backend APIs using configurable endpoints
|
|
4
|
+
*/
|
|
5
|
+
import { buildEndpointUrl, getEndpointMethod, getEndpointHeaders } from '../config/endpoints.js';
|
|
6
|
+
let endpointConfig = null;
|
|
7
|
+
/**
|
|
8
|
+
* Set the endpoint configuration at runtime
|
|
9
|
+
*/
|
|
10
|
+
export function setEndpointConfig(config) {
|
|
11
|
+
endpointConfig = config;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get the current endpoint configuration
|
|
15
|
+
*/
|
|
16
|
+
export function getEndpointConfig() {
|
|
17
|
+
return endpointConfig;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Generic API request helper with endpoint configuration
|
|
21
|
+
*/
|
|
22
|
+
async function apiRequest(endpointKey, endpointPath, params, options = {}) {
|
|
23
|
+
if (!endpointConfig) {
|
|
24
|
+
throw new Error('Endpoint configuration not set. Call setEndpointConfig() first.');
|
|
25
|
+
}
|
|
26
|
+
const url = buildEndpointUrl(endpointConfig, endpointPath, params);
|
|
27
|
+
const method = getEndpointMethod(endpointConfig, endpointKey);
|
|
28
|
+
const headers = getEndpointHeaders(endpointConfig, endpointKey);
|
|
29
|
+
const response = await fetch(url, {
|
|
30
|
+
method,
|
|
31
|
+
headers,
|
|
32
|
+
...options
|
|
33
|
+
});
|
|
34
|
+
// Check if response is JSON
|
|
35
|
+
const contentType = response.headers.get('content-type');
|
|
36
|
+
const isJson = contentType?.includes('application/json');
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
// Try to get error details
|
|
39
|
+
let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
|
|
40
|
+
if (isJson) {
|
|
41
|
+
try {
|
|
42
|
+
const data = await response.json();
|
|
43
|
+
errorMessage = data.error || data.message || errorMessage;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// Failed to parse JSON, use default error message
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
// Response is not JSON (probably HTML error page)
|
|
51
|
+
try {
|
|
52
|
+
const text = await response.text();
|
|
53
|
+
// Extract first 200 characters for debugging
|
|
54
|
+
const preview = text.substring(0, 200).trim();
|
|
55
|
+
errorMessage = `${errorMessage}. Server returned: ${preview}...`;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// Failed to read response text
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
throw new Error(errorMessage);
|
|
62
|
+
}
|
|
63
|
+
// Parse successful response
|
|
64
|
+
const data = await response.json();
|
|
65
|
+
return data;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Node API methods
|
|
69
|
+
*/
|
|
70
|
+
export const nodeApi = {
|
|
71
|
+
/**
|
|
72
|
+
* Get all node types with optional filtering
|
|
73
|
+
*/
|
|
74
|
+
async getNodes(options) {
|
|
75
|
+
if (!endpointConfig) {
|
|
76
|
+
throw new Error('Endpoint configuration not set');
|
|
77
|
+
}
|
|
78
|
+
const params = new URLSearchParams();
|
|
79
|
+
if (options?.category)
|
|
80
|
+
params.append('category', options.category);
|
|
81
|
+
if (options?.search)
|
|
82
|
+
params.append('search', options.search);
|
|
83
|
+
if (options?.limit)
|
|
84
|
+
params.append('limit', options.limit.toString());
|
|
85
|
+
if (options?.offset)
|
|
86
|
+
params.append('offset', options.offset.toString());
|
|
87
|
+
const response = await apiRequest('nodes.list', endpointConfig.endpoints.nodes.list + '?' + params.toString());
|
|
88
|
+
return response.data || [];
|
|
89
|
+
},
|
|
90
|
+
/**
|
|
91
|
+
* Get a specific node type by ID
|
|
92
|
+
*/
|
|
93
|
+
async getNode(id) {
|
|
94
|
+
if (!endpointConfig) {
|
|
95
|
+
throw new Error('Endpoint configuration not set');
|
|
96
|
+
}
|
|
97
|
+
const response = await apiRequest('nodes.get', endpointConfig.endpoints.nodes.get, { id });
|
|
98
|
+
if (!response.data) {
|
|
99
|
+
throw new Error('Node not found');
|
|
100
|
+
}
|
|
101
|
+
return response.data;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Workflow API methods
|
|
106
|
+
*/
|
|
107
|
+
export const workflowApi = {
|
|
108
|
+
/**
|
|
109
|
+
* Get all workflows with optional filtering
|
|
110
|
+
*/
|
|
111
|
+
async getWorkflows(options) {
|
|
112
|
+
if (!endpointConfig) {
|
|
113
|
+
throw new Error('Endpoint configuration not set');
|
|
114
|
+
}
|
|
115
|
+
const params = new URLSearchParams();
|
|
116
|
+
if (options?.search)
|
|
117
|
+
params.append('search', options.search);
|
|
118
|
+
if (options?.limit)
|
|
119
|
+
params.append('limit', options.limit.toString());
|
|
120
|
+
if (options?.offset)
|
|
121
|
+
params.append('offset', options.offset.toString());
|
|
122
|
+
const response = await apiRequest('workflows.list', endpointConfig.endpoints.workflows.list + '?' + params.toString());
|
|
123
|
+
return response.data || [];
|
|
124
|
+
},
|
|
125
|
+
/**
|
|
126
|
+
* Get a specific workflow by ID
|
|
127
|
+
*/
|
|
128
|
+
async getWorkflow(id) {
|
|
129
|
+
if (!endpointConfig) {
|
|
130
|
+
throw new Error('Endpoint configuration not set');
|
|
131
|
+
}
|
|
132
|
+
const response = await apiRequest('workflows.get', endpointConfig.endpoints.workflows.get, { id });
|
|
133
|
+
if (!response.data) {
|
|
134
|
+
throw new Error('Workflow not found');
|
|
135
|
+
}
|
|
136
|
+
return response.data;
|
|
137
|
+
},
|
|
138
|
+
/**
|
|
139
|
+
* Create a new workflow
|
|
140
|
+
*/
|
|
141
|
+
async createWorkflow(workflow) {
|
|
142
|
+
if (!endpointConfig) {
|
|
143
|
+
throw new Error('Endpoint configuration not set');
|
|
144
|
+
}
|
|
145
|
+
// Apply the consumer-provided payload transform (e.g. Drupal's label mapping).
|
|
146
|
+
// The default is the identity function — no CMS-specific logic in the core library.
|
|
147
|
+
const transform = endpointConfig.transformWorkflowPayload ?? ((w) => w);
|
|
148
|
+
const body = transform(workflow);
|
|
149
|
+
const response = await apiRequest('workflows.create', endpointConfig.endpoints.workflows.create, undefined, {
|
|
150
|
+
method: 'POST',
|
|
151
|
+
body: JSON.stringify(body)
|
|
152
|
+
});
|
|
153
|
+
if (!response.data) {
|
|
154
|
+
throw new Error('Failed to create workflow');
|
|
155
|
+
}
|
|
156
|
+
return response.data;
|
|
157
|
+
},
|
|
158
|
+
/**
|
|
159
|
+
* Update an existing workflow
|
|
160
|
+
*/
|
|
161
|
+
async updateWorkflow(id, workflow) {
|
|
162
|
+
if (!endpointConfig) {
|
|
163
|
+
throw new Error('Endpoint configuration not set');
|
|
164
|
+
}
|
|
165
|
+
// Apply the consumer-provided payload transform (e.g. Drupal's label mapping).
|
|
166
|
+
// The default is the identity function — no CMS-specific logic in the core library.
|
|
167
|
+
const transform = endpointConfig.transformWorkflowPayload ?? ((w) => w);
|
|
168
|
+
const body = transform(workflow);
|
|
169
|
+
const response = await apiRequest('workflows.update', endpointConfig.endpoints.workflows.update, { id }, {
|
|
170
|
+
method: 'PUT',
|
|
171
|
+
body: JSON.stringify(body)
|
|
172
|
+
});
|
|
173
|
+
if (!response.data) {
|
|
174
|
+
throw new Error('Failed to update workflow');
|
|
175
|
+
}
|
|
176
|
+
return response.data;
|
|
177
|
+
},
|
|
178
|
+
/**
|
|
179
|
+
* Delete a workflow
|
|
180
|
+
*/
|
|
181
|
+
async deleteWorkflow(id) {
|
|
182
|
+
if (!endpointConfig) {
|
|
183
|
+
throw new Error('Endpoint configuration not set');
|
|
184
|
+
}
|
|
185
|
+
await apiRequest('workflows.delete', endpointConfig.endpoints.workflows.delete, { id }, { method: 'DELETE' });
|
|
186
|
+
},
|
|
187
|
+
/**
|
|
188
|
+
* Save workflow (create or update)
|
|
189
|
+
*/
|
|
190
|
+
async saveWorkflow(workflow) {
|
|
191
|
+
// Check if this is an existing workflow by looking for a valid ID
|
|
192
|
+
// Valid IDs should not be a UUID (which indicates a new workflow)
|
|
193
|
+
const isExistingWorkflow = workflow.id &&
|
|
194
|
+
workflow.id.length > 0 &&
|
|
195
|
+
!workflow.id.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i);
|
|
196
|
+
if (isExistingWorkflow) {
|
|
197
|
+
// Update existing workflow
|
|
198
|
+
return this.updateWorkflow(workflow.id, workflow);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
// Create new workflow
|
|
202
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
203
|
+
const { id, ...workflowData } = workflow;
|
|
204
|
+
return this.createWorkflow(workflowData);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* Export the API service
|
|
210
|
+
*/
|
|
211
|
+
export const api = {
|
|
212
|
+
nodes: nodeApi,
|
|
213
|
+
workflows: workflowApi
|
|
214
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Variable Service
|
|
3
|
+
* Handles fetching template variable schemas from REST endpoints at runtime.
|
|
4
|
+
* Enables dynamic variable suggestions from backend APIs for template editors.
|
|
5
|
+
*
|
|
6
|
+
* @module services/apiVariableService
|
|
7
|
+
*/
|
|
8
|
+
import type { VariableSchema, ApiVariablesConfig, AuthProvider } from '../types/index.js';
|
|
9
|
+
/**
|
|
10
|
+
* Context for variable API requests
|
|
11
|
+
*/
|
|
12
|
+
interface VariableContext {
|
|
13
|
+
/** Workflow ID */
|
|
14
|
+
workflowId?: string;
|
|
15
|
+
/** Node instance ID */
|
|
16
|
+
nodeId: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Result of a variable schema fetch operation
|
|
20
|
+
*/
|
|
21
|
+
export interface ApiVariableResult {
|
|
22
|
+
/** Whether the fetch was successful */
|
|
23
|
+
success: boolean;
|
|
24
|
+
/** The fetched variable schema (if successful) */
|
|
25
|
+
schema?: VariableSchema;
|
|
26
|
+
/** Error message (if failed) */
|
|
27
|
+
error?: string;
|
|
28
|
+
/** Whether the schema was loaded from cache */
|
|
29
|
+
fromCache?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** Default cache TTL for variable data */
|
|
32
|
+
export declare const DEFAULT_VARIABLE_CACHE_TTL: number;
|
|
33
|
+
/**
|
|
34
|
+
* Replaces {workflowId} and {nodeId} placeholders in URL template.
|
|
35
|
+
*
|
|
36
|
+
* @param template - The URL template string
|
|
37
|
+
* @param context - The variable context with workflowId and nodeId
|
|
38
|
+
* @returns The resolved URL with placeholders replaced
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const url = "/api/variables/{workflowId}/{nodeId}";
|
|
43
|
+
* const context = { workflowId: "wf-123", nodeId: "node-456" };
|
|
44
|
+
* resolveEndpointUrl(url, context);
|
|
45
|
+
* // Returns "/api/variables/wf-123/node-456"
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare function resolveEndpointUrl(template: string, context: VariableContext): string;
|
|
49
|
+
/**
|
|
50
|
+
* Fetches variable schema from a backend API endpoint.
|
|
51
|
+
*
|
|
52
|
+
* @param workflowId - The workflow ID (optional)
|
|
53
|
+
* @param nodeId - The node instance ID
|
|
54
|
+
* @param config - The API variables configuration
|
|
55
|
+
* @param authProvider - Optional auth provider for auth headers
|
|
56
|
+
* @returns A promise that resolves to the variable schema result
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const config: ApiVariablesConfig = {
|
|
61
|
+
* endpoint: {
|
|
62
|
+
* url: "/api/variables/{workflowId}/{nodeId}",
|
|
63
|
+
* method: "GET"
|
|
64
|
+
* },
|
|
65
|
+
* cacheTtl: 300000
|
|
66
|
+
* };
|
|
67
|
+
*
|
|
68
|
+
* const result = await fetchVariableSchema("wf-123", "node-456", config);
|
|
69
|
+
* if (result.success && result.schema) {
|
|
70
|
+
* // Use the fetched variable schema
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function fetchVariableSchema(workflowId: string | undefined, nodeId: string, config: ApiVariablesConfig, authProvider?: AuthProvider): Promise<ApiVariableResult>;
|
|
75
|
+
/**
|
|
76
|
+
* Clears the variable schema cache.
|
|
77
|
+
* Can optionally clear only entries matching a specific pattern.
|
|
78
|
+
*
|
|
79
|
+
* @param pattern - Optional pattern to match cache keys (e.g., workflow ID or node ID)
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* // Clear all cache
|
|
84
|
+
* clearVariableCache();
|
|
85
|
+
*
|
|
86
|
+
* // Clear cache for a specific workflow
|
|
87
|
+
* clearVariableCache("wf-123");
|
|
88
|
+
*
|
|
89
|
+
* // Clear cache for a specific node
|
|
90
|
+
* clearVariableCache("node-456");
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare function clearVariableCache(pattern?: string): void;
|
|
94
|
+
/**
|
|
95
|
+
* Invalidates a specific variable cache entry.
|
|
96
|
+
*
|
|
97
|
+
* @param workflowId - The workflow ID (optional)
|
|
98
|
+
* @param nodeId - The node instance ID
|
|
99
|
+
*/
|
|
100
|
+
export declare function invalidateVariableCache(workflowId: string | undefined, nodeId: string): void;
|
|
101
|
+
/**
|
|
102
|
+
* Gets the current cache size (number of entries).
|
|
103
|
+
*
|
|
104
|
+
* @returns The number of cached variable schemas
|
|
105
|
+
*/
|
|
106
|
+
export declare function getVariableCacheSize(): number;
|
|
107
|
+
/**
|
|
108
|
+
* Gets all cache keys currently stored.
|
|
109
|
+
* Useful for debugging and monitoring.
|
|
110
|
+
*
|
|
111
|
+
* @returns Array of cache keys
|
|
112
|
+
*/
|
|
113
|
+
export declare function getVariableCacheKeys(): string[];
|
|
114
|
+
export {};
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Variable Service
|
|
3
|
+
* Handles fetching template variable schemas from REST endpoints at runtime.
|
|
4
|
+
* Enables dynamic variable suggestions from backend APIs for template editors.
|
|
5
|
+
*
|
|
6
|
+
* @module services/apiVariableService
|
|
7
|
+
*/
|
|
8
|
+
import { getEndpointConfig } from './api.js';
|
|
9
|
+
import { logger } from '../utils/logger.js';
|
|
10
|
+
import { DEFAULT_CACHE_TTL_MS } from '../config/constants.js';
|
|
11
|
+
/**
|
|
12
|
+
* Variable schema cache with TTL support
|
|
13
|
+
* Key format: `variables:{workflowId}:{nodeId}`
|
|
14
|
+
*/
|
|
15
|
+
const variableCache = new Map();
|
|
16
|
+
/** Default cache TTL for variable data */
|
|
17
|
+
export const DEFAULT_VARIABLE_CACHE_TTL = DEFAULT_CACHE_TTL_MS;
|
|
18
|
+
/**
|
|
19
|
+
* Replaces {workflowId} and {nodeId} placeholders in URL template.
|
|
20
|
+
*
|
|
21
|
+
* @param template - The URL template string
|
|
22
|
+
* @param context - The variable context with workflowId and nodeId
|
|
23
|
+
* @returns The resolved URL with placeholders replaced
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const url = "/api/variables/{workflowId}/{nodeId}";
|
|
28
|
+
* const context = { workflowId: "wf-123", nodeId: "node-456" };
|
|
29
|
+
* resolveEndpointUrl(url, context);
|
|
30
|
+
* // Returns "/api/variables/wf-123/node-456"
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function resolveEndpointUrl(template, context) {
|
|
34
|
+
let resolved = template;
|
|
35
|
+
// Replace {workflowId}
|
|
36
|
+
if (context.workflowId) {
|
|
37
|
+
resolved = resolved.replace(/\{workflowId\}/g, encodeURIComponent(context.workflowId));
|
|
38
|
+
}
|
|
39
|
+
// Replace {nodeId}
|
|
40
|
+
resolved = resolved.replace(/\{nodeId\}/g, encodeURIComponent(context.nodeId));
|
|
41
|
+
return resolved;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Generates a cache key for a variable schema based on the context.
|
|
45
|
+
*
|
|
46
|
+
* @param workflowId - The workflow ID (optional)
|
|
47
|
+
* @param nodeId - The node instance ID
|
|
48
|
+
* @returns A unique cache key string
|
|
49
|
+
*/
|
|
50
|
+
function generateVariableCacheKey(workflowId, nodeId) {
|
|
51
|
+
return `variables:${workflowId || 'unknown'}:${nodeId}`;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Checks if a cached variable schema is still valid (not expired).
|
|
55
|
+
*
|
|
56
|
+
* @param entry - The cache entry to check
|
|
57
|
+
* @param ttl - Time-to-live in milliseconds
|
|
58
|
+
* @returns True if the cache entry is still valid
|
|
59
|
+
*/
|
|
60
|
+
function isCacheValid(entry, ttl = DEFAULT_VARIABLE_CACHE_TTL) {
|
|
61
|
+
return Date.now() - entry.cachedAt < ttl;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Resolves template variables in request body.
|
|
65
|
+
* Recursively processes nested objects and arrays.
|
|
66
|
+
*
|
|
67
|
+
* @param body - The request body object
|
|
68
|
+
* @param context - The variable context
|
|
69
|
+
* @returns The body with template variables resolved
|
|
70
|
+
*/
|
|
71
|
+
function resolveBodyTemplates(body, context) {
|
|
72
|
+
const resolved = {};
|
|
73
|
+
for (const [key, value] of Object.entries(body)) {
|
|
74
|
+
if (typeof value === 'string') {
|
|
75
|
+
// Resolve template variables in string values
|
|
76
|
+
let resolvedValue = value;
|
|
77
|
+
if (context.workflowId) {
|
|
78
|
+
resolvedValue = resolvedValue.replace(/\{workflowId\}/g, encodeURIComponent(context.workflowId));
|
|
79
|
+
}
|
|
80
|
+
resolvedValue = resolvedValue.replace(/\{nodeId\}/g, encodeURIComponent(context.nodeId));
|
|
81
|
+
resolved[key] = resolvedValue;
|
|
82
|
+
}
|
|
83
|
+
else if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
84
|
+
// Recursively resolve nested objects
|
|
85
|
+
resolved[key] = resolveBodyTemplates(value, context);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
// Pass through other values as-is
|
|
89
|
+
resolved[key] = value;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return resolved;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Fetches variable schema from a backend API endpoint.
|
|
96
|
+
*
|
|
97
|
+
* @param workflowId - The workflow ID (optional)
|
|
98
|
+
* @param nodeId - The node instance ID
|
|
99
|
+
* @param config - The API variables configuration
|
|
100
|
+
* @param authProvider - Optional auth provider for auth headers
|
|
101
|
+
* @returns A promise that resolves to the variable schema result
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const config: ApiVariablesConfig = {
|
|
106
|
+
* endpoint: {
|
|
107
|
+
* url: "/api/variables/{workflowId}/{nodeId}",
|
|
108
|
+
* method: "GET"
|
|
109
|
+
* },
|
|
110
|
+
* cacheTtl: 300000
|
|
111
|
+
* };
|
|
112
|
+
*
|
|
113
|
+
* const result = await fetchVariableSchema("wf-123", "node-456", config);
|
|
114
|
+
* if (result.success && result.schema) {
|
|
115
|
+
* // Use the fetched variable schema
|
|
116
|
+
* }
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export async function fetchVariableSchema(workflowId, nodeId, config, authProvider) {
|
|
120
|
+
const endpoint = config.endpoint;
|
|
121
|
+
const context = { workflowId, nodeId };
|
|
122
|
+
// Generate cache key
|
|
123
|
+
const cacheKey = generateVariableCacheKey(workflowId, nodeId);
|
|
124
|
+
// Check cache first (if caching is enabled)
|
|
125
|
+
if (endpoint.cacheEnabled !== false) {
|
|
126
|
+
const cached = variableCache.get(cacheKey);
|
|
127
|
+
const ttl = config.cacheTtl ?? DEFAULT_VARIABLE_CACHE_TTL;
|
|
128
|
+
if (cached && isCacheValid(cached, ttl)) {
|
|
129
|
+
return {
|
|
130
|
+
success: true,
|
|
131
|
+
schema: cached.schema,
|
|
132
|
+
fromCache: true
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// Resolve the URL with template variables
|
|
137
|
+
let url = resolveEndpointUrl(endpoint.url, context);
|
|
138
|
+
// If URL is relative, prepend base URL from endpoint config
|
|
139
|
+
if (url.startsWith('/')) {
|
|
140
|
+
const currentConfig = getEndpointConfig();
|
|
141
|
+
if (currentConfig?.baseUrl) {
|
|
142
|
+
const baseUrl = currentConfig.baseUrl.replace(/\/$/, '');
|
|
143
|
+
url = `${baseUrl}${url}`;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// Prepare request options
|
|
147
|
+
const method = endpoint.method ?? 'GET';
|
|
148
|
+
const timeout = endpoint.timeout ?? 30000;
|
|
149
|
+
const headers = {
|
|
150
|
+
Accept: 'application/json',
|
|
151
|
+
'Content-Type': 'application/json',
|
|
152
|
+
...endpoint.headers
|
|
153
|
+
};
|
|
154
|
+
// Add auth headers from AuthProvider if available
|
|
155
|
+
if (authProvider) {
|
|
156
|
+
try {
|
|
157
|
+
const authHeaders = await authProvider.getAuthHeaders();
|
|
158
|
+
Object.assign(headers, authHeaders);
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
logger.warn('Failed to get auth headers:', error);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// Add auth headers from endpoint config as fallback
|
|
165
|
+
const currentConfig = getEndpointConfig();
|
|
166
|
+
if (currentConfig?.auth) {
|
|
167
|
+
if (currentConfig.auth.type === 'bearer' && currentConfig.auth.token) {
|
|
168
|
+
headers['Authorization'] = headers['Authorization'] ?? `Bearer ${currentConfig.auth.token}`;
|
|
169
|
+
}
|
|
170
|
+
else if (currentConfig.auth.type === 'api_key' && currentConfig.auth.apiKey) {
|
|
171
|
+
headers['X-API-Key'] = headers['X-API-Key'] ?? currentConfig.auth.apiKey;
|
|
172
|
+
}
|
|
173
|
+
else if (currentConfig.auth.type === 'custom' && currentConfig.auth.headers) {
|
|
174
|
+
Object.assign(headers, currentConfig.auth.headers);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
// Prepare fetch options
|
|
178
|
+
const fetchOptions = {
|
|
179
|
+
method,
|
|
180
|
+
headers,
|
|
181
|
+
signal: AbortSignal.timeout(timeout)
|
|
182
|
+
};
|
|
183
|
+
// Add body for non-GET requests
|
|
184
|
+
if (method !== 'GET' && endpoint.body) {
|
|
185
|
+
const resolvedBody = resolveBodyTemplates(endpoint.body, context);
|
|
186
|
+
fetchOptions.body = JSON.stringify(resolvedBody);
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
const response = await fetch(url, fetchOptions);
|
|
190
|
+
// Handle 404 as "no variables available"
|
|
191
|
+
if (response.status === 404) {
|
|
192
|
+
return {
|
|
193
|
+
success: true,
|
|
194
|
+
schema: { variables: {} },
|
|
195
|
+
fromCache: false
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
if (!response.ok) {
|
|
199
|
+
// Handle authentication errors
|
|
200
|
+
if (response.status === 401 || response.status === 403) {
|
|
201
|
+
if (authProvider?.onUnauthorized) {
|
|
202
|
+
const refreshed = await authProvider.onUnauthorized();
|
|
203
|
+
if (refreshed) {
|
|
204
|
+
// Retry with refreshed auth
|
|
205
|
+
return fetchVariableSchema(workflowId, nodeId, config, authProvider);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
success: false,
|
|
210
|
+
error: 'Authentication failed'
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const errorText = await response.text();
|
|
214
|
+
return {
|
|
215
|
+
success: false,
|
|
216
|
+
error: `HTTP ${response.status}: ${errorText || response.statusText}`
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
const data = await response.json();
|
|
220
|
+
// The response could be:
|
|
221
|
+
// 1. Direct VariableSchema: { variables: {...} }
|
|
222
|
+
// 2. Wrapped in { data: { variables: {...} } }
|
|
223
|
+
// 3. Wrapped in { schema: { variables: {...} } }
|
|
224
|
+
// 4. Wrapped in { success: true, data: { variables: {...} } }
|
|
225
|
+
let schema;
|
|
226
|
+
if (data.variables && typeof data.variables === 'object') {
|
|
227
|
+
// Direct VariableSchema
|
|
228
|
+
schema = data;
|
|
229
|
+
}
|
|
230
|
+
else if (data.data?.variables && typeof data.data.variables === 'object') {
|
|
231
|
+
// Wrapped in { data: ... }
|
|
232
|
+
schema = data.data;
|
|
233
|
+
}
|
|
234
|
+
else if (data.schema?.variables && typeof data.schema.variables === 'object') {
|
|
235
|
+
// Wrapped in { schema: ... }
|
|
236
|
+
schema = data.schema;
|
|
237
|
+
}
|
|
238
|
+
else if (data.success && data.data?.variables) {
|
|
239
|
+
// Wrapped in { success: true, data: ... }
|
|
240
|
+
schema = data.data;
|
|
241
|
+
}
|
|
242
|
+
if (!schema) {
|
|
243
|
+
return {
|
|
244
|
+
success: false,
|
|
245
|
+
error: 'Invalid variable schema format received from endpoint'
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
// Cache the schema (if caching is enabled)
|
|
249
|
+
if (endpoint.cacheEnabled !== false) {
|
|
250
|
+
variableCache.set(cacheKey, {
|
|
251
|
+
schema,
|
|
252
|
+
cachedAt: Date.now(),
|
|
253
|
+
cacheKey
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
success: true,
|
|
258
|
+
schema,
|
|
259
|
+
fromCache: false
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
// Handle specific error types
|
|
264
|
+
if (error instanceof Error) {
|
|
265
|
+
if (error.name === 'AbortError' || error.name === 'TimeoutError') {
|
|
266
|
+
return {
|
|
267
|
+
success: false,
|
|
268
|
+
error: `Request timed out after ${timeout}ms`
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
return {
|
|
272
|
+
success: false,
|
|
273
|
+
error: error.message
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
return {
|
|
277
|
+
success: false,
|
|
278
|
+
error: 'Unknown error occurred while fetching variable schema'
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Clears the variable schema cache.
|
|
284
|
+
* Can optionally clear only entries matching a specific pattern.
|
|
285
|
+
*
|
|
286
|
+
* @param pattern - Optional pattern to match cache keys (e.g., workflow ID or node ID)
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```typescript
|
|
290
|
+
* // Clear all cache
|
|
291
|
+
* clearVariableCache();
|
|
292
|
+
*
|
|
293
|
+
* // Clear cache for a specific workflow
|
|
294
|
+
* clearVariableCache("wf-123");
|
|
295
|
+
*
|
|
296
|
+
* // Clear cache for a specific node
|
|
297
|
+
* clearVariableCache("node-456");
|
|
298
|
+
* ```
|
|
299
|
+
*/
|
|
300
|
+
export function clearVariableCache(pattern) {
|
|
301
|
+
if (!pattern) {
|
|
302
|
+
variableCache.clear();
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
// Clear matching entries
|
|
306
|
+
for (const key of variableCache.keys()) {
|
|
307
|
+
if (key.includes(pattern)) {
|
|
308
|
+
variableCache.delete(key);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Invalidates a specific variable cache entry.
|
|
314
|
+
*
|
|
315
|
+
* @param workflowId - The workflow ID (optional)
|
|
316
|
+
* @param nodeId - The node instance ID
|
|
317
|
+
*/
|
|
318
|
+
export function invalidateVariableCache(workflowId, nodeId) {
|
|
319
|
+
const cacheKey = generateVariableCacheKey(workflowId, nodeId);
|
|
320
|
+
variableCache.delete(cacheKey);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Gets the current cache size (number of entries).
|
|
324
|
+
*
|
|
325
|
+
* @returns The number of cached variable schemas
|
|
326
|
+
*/
|
|
327
|
+
export function getVariableCacheSize() {
|
|
328
|
+
return variableCache.size;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Gets all cache keys currently stored.
|
|
332
|
+
* Useful for debugging and monitoring.
|
|
333
|
+
*
|
|
334
|
+
* @returns Array of cache keys
|
|
335
|
+
*/
|
|
336
|
+
export function getVariableCacheKeys() {
|
|
337
|
+
return Array.from(variableCache.keys());
|
|
338
|
+
}
|