Home
Softono
n8n-kit

n8n-kit

Open source MIT TypeScript
24
Stars
3
Forks
11
Issues
1
Watchers
1 week
Last Commit

About n8n-kit

Generate and deploy n8n workflows using code.

Platforms

Web Self-hosted

Languages

TypeScript

n8n-kit

Code quality npm downloads n8n

[!WARNING]
This project is currently in alpha stage. APIs may change and some features are still under development.\ If you use this package, pin the version to a specific version in your package.json file.

Build n8n workflows using TypeScript code and deploy them using the CLI.

This is not an official n8n package.

Packages:

npm install @vahor/n8n-kit @vahor/n8n-kit-cli

[!NOTE] The n8n version shown in the badge indicates the version this library was built against. Most nodes will work with lower n8n versions, but some newer nodes might not be available. For best compatibility, we recommend using the indicated n8n version or using a previous version of this library if you're on an older n8n version.

Example

Find more examples in the examples folder

Example workflow

const app = new App();

const nasaCredentials = Credentials.byId({
    name: "nasaApi",
    id: "credential-id",
});

new Workflow(app, "my-workflow", {
    active: true,
    name: "NASA Example",
    definition: [
        new StickyNote("note", {
            position: [0, 0],
            parameters: {
                content:
                    "## Setup required\n\nYou need to create a NASA account and create credentials, and create a bin with Postbin and enter the ID - see [the documentation](https://docs.n8n.io/try-it-out/longer-introduction/)",
                height: 120,
                width: 600,
            },
        }),

        Chain.start(
            new ScheduleTrigger("schedule-trigger", {
                label: "Schedule trigger",
                parameters: {
                    rule: {
                        interval: [
                            {
                                field: "weeks",
                                triggerAtDay: [1],
                                triggerAtHour: 9,
                                weeksInterval: 1,
                            },
                        ],
                    },
                },
            }),
        )
            .next(
                new Nasa("nasa", {
                    nasaApiCredentials: nasaCredentials,
                    parameters: {
                        resource: "donkiSolarFlare",
                        additionalFields: {
                            startDate: expr`{{ $today.minus(1, 'day') }}`,
                        },
                    },
                }),
            )
            .next(({ $ }) =>
                new If("if", {
                    parameters: {
                        conditions: {
                            combinator: "and",
                            conditions: [
                                {
                                    operator: {
                                        type: "string",
                                        operation: "contains",
                                    },
                                    leftValue: $("json.classType"),
                                    rightValue: "C",
                                },
                            ],
                        },
                    },
                })
                    .true(
                        new PostBin("PostBin(true)", {
                            parameters: {
                                resource: "request",
                                binId: "1741914338605-0907339996192",
                                binContent: expr`There was a solar flare of class ${$("json.classType")}`,
                                operation: "send",
                            },
                        }),
                    )
                    .false(
                        new PostBin("PostBin(false)", {
                            parameters: {
                                resource: "request",
                                binId: "1741914338605-0907339996192",
                                binContent: expr`There was a solar flare of class ${$("json.classType")}`,
                                operation: "send",
                            },
                        }),
                    ),
            ),
    ],
});

export { app };

Limitations

  • Generated Graph Layout:
    • No mid-graph direction changes.
    • No way to set node execution priority (n8n runs nodes top-to-bottom)
    • Workaround: Deploy the workflow once, then edit the workflow in n8n. With the --merge option, node positions won't be overwritten.
  • Credentials: Must be defined in n8n first, then referenced via Credentials.byId() (no API endpoint available)
  • Folders: The cli will deploy workflow to the root folder. You can still organize them manually once deployed. (no API endpoint available)

Have ideas for improvements? Open an issue or Suggest a Pull Request

License

MIT

Credits

n8n nodes are automatically generated based on the code of the official n8n node repository.\ Workflows chaining is inspired by aws-cdk-lib stepfunctions.