Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz Source: /opt/alga-psa on psa.joliet.tech
113 lines
3.1 KiB
TypeScript
113 lines
3.1 KiB
TypeScript
import { ZodSchema } from 'zod';
|
|
import type { RetryPolicy } from '../types';
|
|
import type { ExpressionContext } from '../expressionEngine';
|
|
|
|
export type ActionId = string;
|
|
|
|
export type ActionIdempotency =
|
|
| { mode: 'engineProvided' }
|
|
| { mode: 'actionProvided'; key: (input: any, ctx: ActionContext) => string };
|
|
|
|
export type ActionUI = {
|
|
label: string;
|
|
description?: string;
|
|
category?: string;
|
|
icon?: string;
|
|
};
|
|
|
|
export type ActionDef<I, O> = {
|
|
id: ActionId;
|
|
version: number;
|
|
inputSchema: ZodSchema<I>;
|
|
outputSchema: ZodSchema<O>;
|
|
sideEffectful: boolean;
|
|
retryHint?: RetryPolicy;
|
|
idempotency: ActionIdempotency;
|
|
ui?: ActionUI;
|
|
examples?: Record<string, unknown>;
|
|
handler: (input: I, ctx: ActionContext) => Promise<O>;
|
|
};
|
|
|
|
export type ActionContext = {
|
|
runId: string;
|
|
stepPath: string;
|
|
stepConfig?: unknown;
|
|
expressionContext?: ExpressionContext;
|
|
tenantId?: string | null;
|
|
idempotencyKey: string;
|
|
attempt: number;
|
|
logger?: { info: (msg: string, meta?: unknown) => void; warn: (msg: string, meta?: unknown) => void; error: (msg: string, meta?: unknown) => void };
|
|
nowIso: () => string;
|
|
env: Record<string, unknown>;
|
|
knex?: any;
|
|
};
|
|
|
|
export type ActionMeta = {
|
|
id: string;
|
|
version: number;
|
|
sideEffectful: boolean;
|
|
retryHint?: RetryPolicy;
|
|
idempotency: { mode: 'engineProvided' | 'actionProvided' };
|
|
ui?: ActionUI;
|
|
inputSchema: ZodSchema<any>;
|
|
outputSchema: ZodSchema<any>;
|
|
examples?: Record<string, unknown>;
|
|
};
|
|
|
|
export class ActionRegistry {
|
|
private actions = new Map<string, ActionDef<any, any>>();
|
|
|
|
register<I, O>(def: ActionDef<I, O>): void {
|
|
if (!def.id || !def.version) {
|
|
throw new Error('ActionRegistry.register requires id and version');
|
|
}
|
|
if (!def.inputSchema || !def.outputSchema) {
|
|
throw new Error(`Action ${def.id}@${def.version} must include inputSchema and outputSchema`);
|
|
}
|
|
if (def.sideEffectful && !def.idempotency) {
|
|
throw new Error(`Action ${def.id}@${def.version} must define idempotency strategy`);
|
|
}
|
|
|
|
const key = this.key(def.id, def.version);
|
|
if (this.actions.has(key)) {
|
|
throw new Error(`ActionRegistry already has ${key}`);
|
|
}
|
|
this.actions.set(key, def);
|
|
}
|
|
|
|
get(id: string, version: number): ActionDef<any, any> | undefined {
|
|
return this.actions.get(this.key(id, version));
|
|
}
|
|
|
|
list(): ActionMeta[] {
|
|
return Array.from(this.actions.values()).map((action) => ({
|
|
id: action.id,
|
|
version: action.version,
|
|
sideEffectful: action.sideEffectful,
|
|
retryHint: action.retryHint,
|
|
idempotency: { mode: action.idempotency.mode },
|
|
ui: action.ui,
|
|
inputSchema: action.inputSchema,
|
|
outputSchema: action.outputSchema,
|
|
examples: action.examples
|
|
}));
|
|
}
|
|
|
|
listById(id: string): ActionDef<any, any>[] {
|
|
return Array.from(this.actions.values()).filter((action) => action.id === id);
|
|
}
|
|
|
|
private key(id: string, version: number): string {
|
|
return `${id}@${version}`;
|
|
}
|
|
}
|
|
|
|
let registryInstance: ActionRegistry | null = null;
|
|
|
|
export function getActionRegistryV2(): ActionRegistry {
|
|
if (!registryInstance) {
|
|
registryInstance = new ActionRegistry();
|
|
}
|
|
return registryInstance;
|
|
}
|