Initial commit: Node.js Example Pack for Attune

Includes:
- 3 Node.js actions (hello, http_example, read_counter)
- 1 counter trigger type
- 1 counter sensor (Node.js, keystore-backed, per-rule state)
- 1 example rule (count_and_log)
- package.json with node-fetch and amqplib
- README with full usage documentation
This commit is contained in:
2026-02-11 17:36:38 -06:00
commit 9072c93fe4
15 changed files with 1442 additions and 0 deletions

30
actions/hello.js Normal file
View File

@@ -0,0 +1,30 @@
#!/usr/bin/env node
/**
* Hello Action - Node.js Example Pack
*
* A minimal Node.js action that returns "Hello, Node.js".
* Demonstrates the basic structure of a Node.js action in Attune.
*
* When invoked via the Node.js wrapper, the `run` export is called
* with the action parameters as its argument.
*/
"use strict";
/**
* Return a simple greeting message.
* @param {object} params - Action parameters (unused).
* @returns {{ message: string }}
*/
function run(params) {
return { message: "Hello, Node.js" };
}
// Direct execution support (without the wrapper)
if (require.main === module) {
const result = run({});
process.stdout.write(JSON.stringify({ result, status: "success" }) + "\n");
process.exit(0);
}
module.exports = { run };

45
actions/hello.yaml Normal file
View File

@@ -0,0 +1,45 @@
# Hello Action
# Simple Node.js action that returns "Hello, Node.js"
ref: nodejs_example.hello
label: "Hello Node.js"
description: "A simple Node.js action that returns a greeting message"
enabled: true
# Runner type determines how the action is executed
runner_type: nodejs
# Entry point is the JavaScript file to execute
entry_point: hello.js
# Parameter delivery: stdin for secure parameter passing
parameter_delivery: stdin
parameter_format: json
# Output format: json (structured data parsing enabled)
output_format: json
# Action parameters schema (standard JSON Schema format)
parameters:
type: object
properties:
name:
type: string
description: "Optional name to include in greeting"
default: "Node.js"
# Output schema
output_schema:
type: object
properties:
message:
type: string
description: "The greeting message"
required:
- message
# Tags for categorization
tags:
- nodejs
- example
- greeting

26
actions/http_example.js Normal file
View File

@@ -0,0 +1,26 @@
#!/usr/bin/env node
/**
* HTTP Example Action - Node.js Example Pack
*
* Demonstrates using the `node-fetch` library to make an HTTP call to example.com.
* Receives parameters via the Node.js wrapper (stdin JSON with code_path).
*/
const fetch = require("node-fetch");
async function run(params) {
const url = params.url || "https://example.com";
const response = await fetch(url, { timeout: 10000 });
const text = await response.text();
return {
status_code: response.status,
url: response.url,
content_length: text.length,
snippet: text.slice(0, 500),
success: response.ok,
};
}
module.exports = { run };

65
actions/http_example.yaml Normal file
View File

@@ -0,0 +1,65 @@
# HTTP Example Action
# Demonstrates using node-fetch to make HTTP calls
ref: nodejs_example.http_example
label: "HTTP Example"
description: "Makes an HTTP GET request to example.com using the node-fetch library"
enabled: true
# Runner type
runner_type: nodejs
# Entry point
entry_point: http_example.js
# Parameter delivery: stdin for secure parameter passing
parameter_delivery: stdin
parameter_format: json
# Output format: json (structured data)
output_format: json
# Action parameters schema
parameters:
type: object
properties:
url:
type: string
description: "URL to request (defaults to https://example.com)"
default: "https://example.com"
method:
type: string
description: "HTTP method"
default: "GET"
enum:
- GET
- POST
- PUT
- DELETE
# Output schema
output_schema:
type: object
properties:
status_code:
type: integer
description: "HTTP response status code"
url:
type: string
description: "URL that was requested"
content_length:
type: integer
description: "Length of the response body in characters"
snippet:
type: string
description: "First 500 characters of the response body"
success:
type: boolean
description: "Whether the request succeeded (2xx status)"
# Tags for categorization
tags:
- http
- nodejs
- example
- fetch

30
actions/read_counter.js Normal file
View File

@@ -0,0 +1,30 @@
#!/usr/bin/env node
/**
* Read Counter Action - Node.js Example Pack
*
* Consumes a counter value (typically from the counter sensor trigger payload)
* and returns a formatted message containing the counter value.
*
* Parameters are delivered via stdin as JSON from the Node.js wrapper.
*/
"use strict";
/**
* @param {object} params
* @param {number} params.counter - The counter value from the trigger payload.
* @param {string} params.rule_ref - The rule reference the counter is scoped to.
* @returns {object} Formatted message and raw counter value.
*/
function run(params) {
const counter = params.counter !== undefined ? params.counter : 0;
const ruleRef = params.rule_ref || "unknown";
return {
message: `Counter value is ${counter} (from rule: ${ruleRef})`,
counter: counter,
rule_ref: ruleRef,
};
}
module.exports = { run };

58
actions/read_counter.yaml Normal file
View File

@@ -0,0 +1,58 @@
# Read Counter Action
# Consumes a counter value and returns a formatted message
ref: nodejs_example.read_counter
label: "Read Counter"
description: "Receives a counter value (typically from the counter trigger) and returns a formatted message containing it"
enabled: true
# Runner type
runner_type: nodejs
# Entry point
entry_point: read_counter.js
# Parameter delivery: stdin for secure parameter passing
parameter_delivery: stdin
parameter_format: json
# Output format: json (structured data)
output_format: json
# Action parameters schema
parameters:
type: object
properties:
counter:
type: integer
description: "The counter value to consume"
rule_ref:
type: string
description: "The rule reference the counter is scoped to"
default: ""
required:
- counter
# Output schema
output_schema:
type: object
properties:
message:
type: string
description: "Formatted message containing the counter value"
counter:
type: integer
description: "The counter value that was consumed"
rule_ref:
type: string
description: "The rule reference the counter is scoped to"
required:
- message
- counter
# Tags for categorization
tags:
- counter
- example
- nodejs
- consumer