TypeScript types for Pipedream components (sources and actions)
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Strongly typed interfaces for component triggers including timer-based execution, HTTP endpoints, and app webhooks.
Interface for timer-based component triggers with support for intervals and cron expressions.
/**
* Timer interface for scheduled component execution
*/
interface TimerInterface {
/** Always "$.interface.timer" for timer interfaces */
type: "$.interface.timer";
/** Default timer configuration (optional) */
default?: {
/** Interval in seconds between executions (optional) */
intervalSeconds?: number;
/** Cron expression for advanced scheduling (optional) */
cron?: string;
};
}
/**
* Event object passed to components triggered by timer interface
*/
interface TimerEvent {
/** Timestamp when the timer was triggered */
timestamp: number;
/** Configured interval in seconds (if using interval) */
interval_seconds?: number;
/** Configured cron expression (if using cron) */
cron?: string;
}Usage Examples:
import { PipedreamComponent, TimerInterface, TimerEvent } from "@pipedream/types";
// Simple interval timer (every 15 minutes)
const intervalComponent: PipedreamComponent = {
name: "Interval Timer Component",
version: "1.0.0",
props: {
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: 60 * 15 // 15 minutes
}
} as TimerInterface
},
async run(event: TimerEvent) {
console.log("Timer triggered at:", new Date(event.timestamp));
console.log("Interval:", event.interval_seconds, "seconds");
}
};
// Cron-based timer (daily at 9 AM)
const cronComponent: PipedreamComponent = {
name: "Cron Timer Component",
version: "1.0.0",
props: {
timer: {
type: "$.interface.timer",
default: {
cron: "0 9 * * *" // Daily at 9:00 AM
}
} as TimerInterface
},
async run(event: TimerEvent) {
console.log("Daily task triggered");
console.log("Cron expression:", event.cron);
}
};Interface for HTTP endpoint components that can receive and respond to HTTP requests.
/**
* HTTP interface for HTTP endpoint components
*/
interface HttpInterface {
/** Always "$.interface.http" for HTTP interfaces */
type: "$.interface.http";
/** Enable custom HTTP responses (optional) */
customResponse?: boolean;
/** HTTP response method (available at runtime) */
respond?: HttpRespondMethod;
}
/**
* Event object passed to components triggered by HTTP requests
*/
interface HttpEvent {
/** HTTP method (GET, POST, PUT, DELETE, etc.) */
method: string;
/** Request path */
path: string;
/** Query string parameters */
query: Record<string, any>;
/** Request headers */
headers: Record<string, string>;
/** Raw request body as string */
bodyRaw: string;
/** Parsed request body */
body: any;
}
/**
* Method for sending HTTP responses
*/
interface HttpRespondMethod {
(response: {
/** HTTP status code */
status: number;
/** Response headers (optional) */
headers?: Record<string, string>;
/** Response body (optional) */
body?: string | object | Buffer;
}): void;
}
/**
* HTTP endpoint information available in component context
*/
interface HttpEndpoint {
/** Generated endpoint URL */
endpoint: string;
}Usage Examples:
import { PipedreamComponent, HttpInterface, HttpEvent } from "@pipedream/types";
// Basic HTTP endpoint
const basicHttpComponent: PipedreamComponent = {
name: "Basic HTTP Component",
version: "1.0.0",
props: {
http: {
type: "$.interface.http"
} as HttpInterface
},
async run(event: HttpEvent) {
console.log(`Received ${event.method} request to ${event.path}`);
console.log("Query params:", event.query);
console.log("Body:", event.body);
// Emit the event
this.$emit(event, {
summary: `${event.method} ${event.path}`
});
}
};
// HTTP endpoint with custom response
const customResponseComponent: PipedreamComponent = {
name: "Custom Response Component",
version: "1.0.0",
props: {
http: {
type: "$.interface.http",
customResponse: true
} as HttpInterface
},
async run(event: HttpEvent) {
// Process the request
const result = await processData(event.body);
// Send custom response
this.http.respond({
status: 200,
headers: {
"Content-Type": "application/json",
"X-Custom-Header": "processed"
},
body: {
success: true,
data: result,
timestamp: new Date().toISOString()
}
});
// Also emit as event
this.$emit(result);
}
};
// Webhook endpoint with validation
const webhookComponent: PipedreamComponent = {
name: "Webhook Component",
version: "1.0.0",
props: {
http: {
type: "$.interface.http",
customResponse: true
} as HttpInterface,
webhookSecret: {
type: "string",
label: "Webhook Secret",
description: "Secret for webhook validation",
secret: true
}
},
async run(event: HttpEvent) {
// Validate webhook signature
const isValid = validateWebhookSignature(
event.bodyRaw,
event.headers['x-webhook-signature'],
this.webhookSecret
);
if (!isValid) {
this.http.respond({
status: 401,
body: { error: "Invalid signature" }
});
return;
}
// Process valid webhook
this.http.respond({
status: 200,
body: { received: true }
});
this.$emit(event.body, {
id: event.body.id || Date.now(),
summary: "Webhook received"
});
}
};Interface for app-specific webhook endpoints that listen to events from integrated apps.
/**
* App hook interface for app-specific webhooks
*/
interface AppHookInterface {
/** Always "$.interface.apphook" for app hook interfaces */
type: "$.interface.apphook";
/** Reference to the app prop that provides webhook functionality */
appProp: string;
/** Array of event names to listen for from the app */
eventNames: string[];
}Usage Example:
import { PipedreamComponent, AppHookInterface, PipedreamApp } from "@pipedream/types";
// GitHub app hook component
const githubHookComponent: PipedreamComponent = {
name: "GitHub Webhook Component",
version: "1.0.0",
props: {
github: {
type: "app",
app: "github"
} as PipedreamApp,
githubHook: {
type: "$.interface.apphook",
appProp: "github",
eventNames: ["push", "pull_request", "issues"]
} as AppHookInterface,
repository: {
type: "string",
propDefinition: ["github", "repository"]
}
},
async run(event) {
console.log("GitHub event received:", event.type);
console.log("Repository:", event.repository?.full_name);
// Handle different event types
switch (event.type) {
case "push":
this.$emit(event.payload, {
summary: `Push to ${event.repository.full_name}`
});
break;
case "pull_request":
this.$emit(event.payload, {
summary: `PR #${event.payload.number} ${event.payload.action}`
});
break;
case "issues":
this.$emit(event.payload, {
summary: `Issue #${event.payload.issue.number} ${event.payload.action}`
});
break;
}
}
};Components can use multiple interfaces, though this is less common:
const multiInterfaceComponent: PipedreamComponent = {
name: "Multi-Interface Component",
version: "1.0.0",
props: {
// Timer for periodic tasks
timer: {
type: "$.interface.timer",
default: { intervalSeconds: 3600 }
} as TimerInterface,
// HTTP for manual triggers
http: {
type: "$.interface.http"
} as HttpInterface,
// Database for state
db: "$.service.db"
},
async run(event) {
// Determine trigger type
if ('timestamp' in event) {
// Timer trigger
console.log("Scheduled execution");
} else if ('method' in event) {
// HTTP trigger
console.log("Manual trigger via HTTP");
}
// Common processing logic
await this.processData(event);
}
};When using interfaces, additional properties become available in the component context:
// Timer interface adds timer property
interface TimerComponentThis extends ComponentThis {
timer: {
type: "$.interface.timer";
};
}
// HTTP interface adds http property with endpoint and respond method
interface HttpComponentThis extends ComponentThis {
http: HttpEndpoint & {
respond: HttpRespondMethod;
};
}
// App hook interface adds the hook property
interface AppHookComponentThis extends ComponentThis {
[hookPropName: string]: {
type: "$.interface.apphook";
appProp: string;
eventNames: string[];
};
}Install with Tessl CLI
npx tessl i tessl/npm-pipedream--types