Skip to content

Commit b33178b

Browse files
WIP templates structure
1 parent 99173a2 commit b33178b

8 files changed

Lines changed: 131 additions & 0 deletions

File tree

templates/connector/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# {$APP_NAME} Stacksync Connector
2+
3+
## Overview
4+
5+
This application was auto-generated using the Stacksync CDK. It provides a custom Stacksync Connector which provide custom functionality inside Stacksync Workflows.
6+
7+
## Setup
8+
9+
This application should be managed via the Stacksync CLI. Please refer to the documentation on how to configure this tool.
10+
11+
Once the CLI is configured, run ${APP_NAME} locally using:
12+
13+
```bash
14+
stacksync dev
15+
```
16+
17+
To deploy:
18+
19+
```bash
20+
stacksync deploy
21+
```
22+
23+
Add additional modules to your project using:
24+
25+
```bash
26+
stacksync create module --name "[Module name]" --url "[url with API documentation]" --prompt "[Description of your module's functionality]"
27+
```
28+
29+
## Architecture
30+
31+
There are a number of key files and structures in this repository:
32+
33+
* The `stacksync.yml` file. This file defines most of your application's metadata and serves and a single point of reference for application configuration.
34+
* The `modules/` folder. This is where the definitions for your individual modules go.
35+
* Each module is expected to provide:
36+
* `schema.py`: Defines your app schema. See below for details.
37+
* `content.py`: Used to fetch dynamic field content if your module requires it.
38+
* `execute.py`: Your business logic that receives events from Stacksync Workflows.
39+
* `content.md`: A file used by Stacksync's AI agents. Should provide additional information about best practices for integrating your module into a workflow.
40+
41+
## `schema.py`
42+
43+
_This section is under construction._
44+
45+
## `content.py`
46+
47+
_This section is under construction._
48+
49+
## `execute.py`
50+
51+
_This section is under construction._
52+
53+
## `content.md`
54+
55+
_This section is under construction._

templates/connector/api_client.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import requests
2+
from stacksync_cdk.api_client import ApiClient
3+
from stacksync_cdk.schema_utils import to_schema
4+
5+
6+
class DummyCrmApiClient(ApiClient):
7+
def __init__(self, credentials: dict):
8+
super().__init__(credentials)
9+
10+
# The @ApiClient.returns_schema() decorator validates that the return
11+
# data is a valid Stacksync schema dict and logs instructive errors if it's not.
12+
@ApiClient.as_schema()
13+
def get_additional_fields(self, record_type: str):
14+
if not self.credentials:
15+
raise ValueError("No credentials provided")
16+
# Let's pretend there's an API endpoint for fetching fields from the CRM
17+
url = f"https://dummycrm.com/api/v1/fields/{record_type}"
18+
response = requests.get(url, headers=self.headers)
19+
# The to_schema() function converts a dict into a Stacksync schema dict.
20+
# It's takes a very generic/naive approach, so pre or post processing may be needed.
21+
return to_schema(response.json())
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Base input schema for the dummy CRM "create record" module.
2+
# See https://docs.stacksync.com/two-way-sync/developers/module-schema-reference
3+
metadata:
4+
workflows_module_schema_version: "1.0.0"
5+
6+
ui_options:
7+
ui_order:
8+
- name
9+
- description
10+
- type
11+
12+
fields:
13+
- id: name
14+
type: string
15+
label: Name
16+
description: Display name for the new record.
17+
validation:
18+
required: true
19+
ui_options:
20+
ui_widget: input
21+
22+
- id: description
23+
type: string
24+
label: Description
25+
description: Optional details shown on the record.
26+
ui_options:
27+
ui_widget: textarea
28+
29+
- id: type
30+
type: string
31+
label: Record type
32+
description: >-
33+
The type of record to create.
34+
choices:
35+
values: []
36+
content:
37+
type:
38+
- managed
39+
content_objects:
40+
- id: record_types
41+
ui_options:
42+
ui_widget: SelectWidget

templates/connector/modules/dummy_crm_create_record/content.py

Whitespace-only changes.

templates/connector/modules/dummy_crm_create_record/context.md

Whitespace-only changes.

templates/connector/modules/dummy_crm_create_record/execute.py

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from cdk.templates.connector import api_client
2+
from stacksync_cdk.schema_utils import load_schema
3+
4+
5+
def schema_handler(form_data: dict, credentials: str):
6+
schema = load_schema("base_schema.yml")
7+
8+
# If these fields are present, we can fetch additional fields from the API
9+
# and add them to the schema so the user can see them in the UI.
10+
if credentials and form_data.get("select_object"):
11+
additional_fields = api_client.get_additional_fields(form_data.get("select_object"))
12+
schema.add(additional_fields)
13+
return schema

templates/connector/stacksync.yml

Whitespace-only changes.

0 commit comments

Comments
 (0)