Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
92635d5
init
olivieropinotti Feb 4, 2025
467dbd8
Refactor and enhance Workflows CDK core modules
olivieropinotti Feb 5, 2025
46c2e46
fixes and cleanup
olivieropinotti Feb 5, 2025
698361c
fix
olivieropinotti Feb 5, 2025
1e8ae1e
Restructure project layout and update package configuration
olivieropinotti Feb 10, 2025
7366374
Enhance ModuleRouter with improved routing and error handling
olivieropinotti Feb 10, 2025
6fda51b
Update dependencies and Python version requirement
olivieropinotti Feb 10, 2025
835d00a
Refactor error handling and response management in core modules
olivieropinotti Feb 10, 2025
3daa375
Add PyYAML dependency to setup.py
olivieropinotti Feb 10, 2025
98edba9
Improve Sentry DSN validation and error handling
olivieropinotti Feb 10, 2025
b865871
Refactor logging and error handling in app module
olivieropinotti Feb 10, 2025
48b1aa0
Refactor router and dynamic routing modules
olivieropinotti Feb 13, 2025
298d353
fix app.py
olivieropinotti Feb 13, 2025
efa4194
Working Routing
olivieropinotti Feb 14, 2025
fb05f42
Enhance dynamic routing with comprehensive configuration and error ha…
olivieropinotti Feb 17, 2025
79d36f3
Refactor core modules with simplified imports and error handling
olivieropinotti Feb 17, 2025
1e18db4
Update README and dependencies for Workflows CDK v0.1.0
olivieropinotti Feb 17, 2025
6809ef5
Enhance route configuration in dynamic routing and logging
olivieropinotti Feb 18, 2025
a5cbfff
Add routes endpoint to dynamic routing module
olivieropinotti Feb 18, 2025
7d65bc1
Remove Sentry-related code from
olivieropinotti Feb 19, 2025
e6d46f0
Update dependencies to use flexible versions constraints
olivieropinotti Feb 19, 2025
0f76bb6
Refactor Sentry and error handling in dynamic routing
olivieropinotti Feb 19, 2025
fe6b7dc
Add request validation module/utils and integrate with dynamic routing
olivieropinotti Feb 19, 2025
1e8e0c4
Enhance validation module with improved JSON parsing and type validation
olivieropinotti Feb 19, 2025
f5dfacd
Refactor response handling with more flexible and concise error/succe…
olivieropinotti Feb 21, 2025
3aeaed9
Enhance dynamic routing configuration with flexible app settings
olivieropinotti Feb 21, 2025
75f643f
Add /schema route discovery and registration to dynamic routing + Fix…
olivieropinotti Feb 24, 2025
7c5a02c
Merge pull request #1 from stacksyncdata/dev
olivieropinotti Feb 24, 2025
57b1db5
Enhance Sentry error tracking with comprehensive event enrichment
olivieropinotti Feb 24, 2025
ef3f251
Refactor routes directory and Add CDK version retrieval
olivieropinotti Apr 2, 2025
5c05d8b
Add content response method to enhance response handling
olivieropinotti Apr 2, 2025
fe0bef5
Enhance dynamic routing with module metadata generation and environme…
olivieropinotti Apr 4, 2025
722f1a8
Update app configuration endpoint in dynamic routing
olivieropinotti Apr 4, 2025
db0d71f
Refactor Router class for improved app configuration handling
olivieropinotti Apr 4, 2025
9c81153
Refactor Router class to streamline routes directory handling
olivieropinotti Apr 4, 2025
478e801
Refactor dynamic routing and error handling in Router class
olivieropinotti Apr 7, 2025
a74756b
Enhance dynamic routing by replacing spaces with underscores in route…
olivieropinotti Apr 9, 2025
c2ca089
Merge branch 'dev' into prod
olivieropinotti Apr 10, 2025
f5976ed
Update Router class to enhance port and debug configuration handling
olivieropinotti Apr 10, 2025
bbae2d4
Merge branch 'dev' into prod
olivieropinotti Apr 10, 2025
68e0ee4
Refactor Router class to improve app configuration and add homepage r…
olivieropinotti Apr 15, 2025
ffb7aca
Merge branch 'dev' into prod
olivieropinotti Apr 15, 2025
85d470c
Merge tag 'v0.3.1' into dev
olivieropinotti Apr 15, 2025
21dc9ca
Merge tag 'v0.3.1' into prod
olivieropinotti Apr 15, 2025
da2dd8a
Enhance dynamic routing in Router class
olivieropinotti Apr 16, 2025
2f13ffe
Merge branch 'dev' into prod
olivieropinotti Apr 16, 2025
1696a85
quickfix
olivieropinotti May 21, 2025
6e34f67
Merge branch 'dev' into prod
olivieropinotti May 21, 2025
1372d32
Updates error handling in response formatting
olivieropinotti Jun 10, 2025
34bb5e0
Merge branch 'dev' into prod
olivieropinotti Jun 10, 2025
f5b1e79
Optimizes dynamic routing for serverless environments and fix memory …
olivieropinotti Jul 2, 2025
146c5eb
Merge pull request #4 from stacksyncdata/dev
aliyss Jul 2, 2025
a61b4e4
added module list func
mariocozta Jul 5, 2025
a2f9e04
re-added the original comments
mariocozta Jul 5, 2025
2c01f42
disabled_route_scan_for_underscored_dirs
mariocozta Jul 7, 2025
c691b10
Removed modules list func from diferent branch
mariocozta Jul 7, 2025
cadf56c
change the logic to ignore all dirs inside v1, v2, vX
mariocozta Jul 9, 2025
cb46fca
Merge branch 'add_module_list_to_homepage' into dev
AlexisFavre Jul 9, 2025
96d57bd
Merge branch 'disabled_route_scan_for_underscored_dirs' into dev
AlexisFavre Jul 9, 2025
d741d54
Merge branch 'dev' into prod
AlexisFavre Jul 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# .vscode
.vscode/
212 changes: 210 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,210 @@
# workflows-cdk
Workflows Connector Development Kit
# Workflows CDK

A powerful CDK (Connector Development Kit) for building Stacksync Workflows Connectors with Python and Flask.

## Features

- 🚀 Automatic route discovery and registration file based (like in Next.js!)
- 🔒 Built-in error handling and Sentry integration
- 📦 Standardized request/response handling
- 🛠️ Error management with standardized error handling
- 🔄 Environment-aware configuration

## Installation

```bash
pip install workflows-cdk
```

## Quick Start

1. Create a new project directory:

```bash
mkdir my-workflow-connector
cd my-workflow-connector
```

2. Install the required dependencies:

```bash
pip install workflows-cdk flask pyyaml
```

3. Create the basic project structure:

```
my-workflow-connector/
├── main.py
├── app_config.yaml
├── requirements.txt
└── routes/
└── hello/
└── v1/
└── route.py
```

4. Set up your `app_config.yaml`:

```yaml
app_settings:
app_type: "example"
app_name: "My Workflow Connector"
app_description: "A simple workflow connector"
sentry_dsn: "your-sentry-dsn" # Optional
cors_origins: ["*"]
routes_directory: "routes"
debug: true
host: "0.0.0.0"
port: 2005
```

5. Create your `main.py`:

```python
from flask import Flask
from workflows_cdk import Router

# Create Flask app
app = Flask("my-workflow-connector")

# Initialize router with configuration
router = Router(app)

# Run the app
if __name__ == "__main__":
router.run_app(app)
```

6. Create your first route in `routes/send_message/v1/route.py`:

```python
from workflows_cdk import Request, Response, ManagedError
from main import router

@router.route("/execute", methods=["POST"])
def execute():
"""Execute the send message action."""
request = Request(flask_request)
data = request.data

name = data.get("name", "World")
return Response.success(data={
"message": f"Hello, {name}!"
})
```

## Core Components

### Router

The `Router` class is the heart of the CDK, providing:

- Automatic route discovery based on file system structure
- Built-in error handling and Sentry integration
- CORS configuration
- Health check endpoints
- API documentation

### Request

The `Request` class wraps Flask's request object, providing:

- Easy access to request data and credentials
- Automatic JSON parsing
- Type-safe access to common properties

### Response

The `Response` class provides standardized response formatting:

- Success responses with optional metadata
- Error responses with appropriate status codes
- Environment-aware error details
- Sentry integration

### ManagedError

The `ManagedError` class provides structured error handling:

- Type-safe error creation
- Automatic Sentry reporting
- Environment-aware error details
- Common error types (validation, not found, unauthorized, etc.)

## Project Structure

Recommended project structure for a workflow connector:

```
my-workflow-connector/
├── main.py # Application entry point
├── app_config.yaml # Application configuration
├── requirements.txt # Python dependencies
├── README.md # Project documentation
├── Dockerfile # Container configuration
├── .env # Environment variables
└── routes/ # Route modules
└── action_name/ # Group routes by action
├── v1/ # Version 1 of the action
│ ├── route.py # Route implementation
│ └── schema.json # JSON Schema for validation
└── v2/ # Version 2 of the action
├── route.py
└── schema.json
```

## Error Handling

The CDK provides comprehensive error handling:

```python
from workflows_cdk import ManagedError

# Validation error
raise ManagedError.validation_error(
error="Invalid input",
data={"field": "email"}
)

# Not found error
raise ManagedError.not_found(
resource="User",
identifier="123"
)

# Authorization error
raise ManagedError.unauthorized(
message="Invalid API key"
)

# Server error
raise ManagedError.server_error(
error="Database connection failed"
)
```

## Response Formatting

Standardized response formatting:

```python
from workflows_cdk import Response

# Success response
return Response.success(
data={"result": "ok"},
message="Operation completed",
metadata={"timestamp": "2024-02-17"}
)

# Error response
return Response.error(
error="Something went wrong",
status_code=400
)
```

## License

This project is licensed under the Stacksync Connector License (SCL) v1.0.
10 changes: 10 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
flask
werkzeug
pyopenssl==24.1.0
flask-cors>=4.0.0
python-dotenv>=1.0.0
gunicorn==22.0.0
authlib==1.1.0
sentry-sdk[Flask]
pydantic>=2.0.0
pyyaml>=6.0.0
30 changes: 30 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
Setup configuration for workflows-cdk package.
"""

from setuptools import find_packages, setup


setup(
name="workflows_cdk",
version="0.1.0",
description="A CDK for developing Stacksync Workflows Connectors",
author="Stacksync",
author_email="oliviero@stacksync.com",
install_requires=[
# Core dependencies
"flask",
"werkzeug==2.2",
"pyopenssl==24.1.0",
"flask-cors>=4.0.0",
"python-dotenv>=1.0.0",
"gunicorn==22.0.0",
"sentry-sdk[Flask]",
"pydantic>=2.0.0",
"pyyaml>=6.0.0"
],
python_requires=">=3.10",
packages=find_packages(where="src"),
package_dir={"": "src"},
include_package_data=True,
)
2 changes: 2 additions & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .workflows_cdk import *

Loading