@attlaz/project-base
v1.3.1
Published
Runtime for writing and running Attlaz flows in a Node/TypeScript project: discovers @Flow handlers, runs the requested one, and reports the result back to Attlaz.
Downloads
978
Maintainers
Readme
Attlaz Javascript/Node Base Project
Attlaz is a cloud-based iPaas (Integration Platform as a Service), automation and data management platform.
@attlaz/project-base
Runtime for writing and running Attlaz flows in a Node/TypeScript project. You write flow handler classes; the package discovers them, runs the requested one, and reports the result back to Attlaz.
Install
npm install @attlaz/project-base attlaz-client
npm install -D typescriptYour flow code imports models/types (StorageItem, StorageType, …) from attlaz-client, so
declare it alongside @attlaz/project-base — npm dedupes the two to a single shared copy. Add
zod (npm install zod) only if you use argument validation, and @types/node (dev) if your
flows use Node APIs.
Set up your project
package.json — add the build script (and "type": "module"):
{
"type": "module",
"scripts": { "build": "attlaz-project-base generate && tsc" }
}tsconfig.json — ESM output with decorators enabled:
{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"target": "ESNext",
"rootDir": "./src",
"outDir": "./dist",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"strict": true
},
"include": ["src/**/*.ts"]
}.gitignore — the generated manifest is a build artifact:
src/flows.generated.tsWrite a flow
Decorate a class with @Flow. It can live anywhere under src/:
// src/GenerateInvoice.ts
import {Flow, FlowContext} from '@attlaz/project-base';
import {z} from 'zod'; // optional
@Flow({
flowId: '26RrQfqi1qRltZ8vAq3F6nJcwOL', // your Attlaz flow id
arguments: z.object({clientName: z.string()}), // optional
})
export class GenerateInvoice {
public async run(args: { clientName: string }, ctx: FlowContext): Promise<unknown> {
ctx.logger.info(`Generating invoice for ${args.clientName}`);
const sheetId = ctx.config.require('invoice_sheet_id'); // project config, from env
// use ctx.client (an authenticated @attlaz/client) to do the work
return {invoiceId: 123};
}
}ctx provides:
client— an authenticated@attlaz/clientinstance.logger— level-aware logging to the flow run log:ctx.logger.info('msg', { context })plusdebug/notice/warning/error/critical/alert/emergency. The optional context object is attached to the entry. (Locally, or if the log stream can't be resolved, logs fall back to stdout.)config— project configuration, backed by environment variables:ctx.config.require('key')(throws if unset),ctx.config.get('key'), plusgetNumber/getBoolean. A local.envis loaded automatically for development; in production the worker injects the values.request— flow id, run id, project environment, andlogStreamId.
The value you return becomes the flow run result. Omit arguments to receive the raw arguments
object (and skip the zod dependency entirely). Arguments are read from the flow run itself, so
large argument sets are handled transparently.
Build
npm run buildThis scans your @Flow classes into a manifest and compiles everything to dist/.
Run
On Attlaz, assign the Attlaz Node project run strategy to your code source and deploy — the
worker runs your flows. To run one locally (with api_endpoint, api_token, … set in the
environment, as the worker provides them):
node node_modules/@attlaz/project-base/dist/bin/cli.js flow:run <flowId> --arguments=<base64-json>