mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-11 00:06:06 +00:00
* feat: add Azure Event Grid triggers (EE)
Introduces a new enterprise trigger kind `azure` that supports three
modes via a single unified trigger type:
- basic_push: Azure Event Grid basic — custom topics, system topics
(Storage, Resource Manager, Key Vault, etc.), domains (push only)
- namespace_push: Event Grid Namespace topics (CloudEvents over HTTP push)
- namespace_pull: Event Grid Namespace topics (HTTP pull with lock-token
ack/reject for dead-lettering)
Auth uses a Service Principal resource (tenant_id, client_id,
client_secret, subscription_id). Subscriptions are created in
CloudEvents 1.0 schema so the push webhook handler and the pull listener
share one payload parser.
Backend
- New crate `windmill-trigger-azure` (OSS stubs + EE impl symlinked from
windmill-ee-private)
- Migration `azure_trigger` table with CHECK constraints enforcing
mode/columns coherence
- `TriggerKind::Azure`, `JobTriggerKind::Azure`,
`DeployedObject::AzureTrigger` variants
- Push route `/api/azure/w/{workspace}/*path` handles classic
Event Grid SubscriptionValidation handshake and CloudEvents 1.0
abuse-protection OPTIONS handshake
- Optional inbound JWT validation (audience check only for v1)
- Feature flag `azure_trigger` propagated through windmill-api,
windmill-store (resource helper), and added to ee_core
Frontend
- `triggers/azure/` editor with mode toggle (basic/namespace-push/
namespace-pull) and per-mode config (topic ARM id / namespace +
topic name / subscription / filters / push auth / pull options)
- Registered in icon map, display names, save functions, badge,
wrapper, editor, add-trigger menu
OpenAPI
- `AzureTrigger`, `AzureTriggerData`, `AzureMode`,
`AzureSubscriptionMode`, `AzureDeliveryConfig`, `TestAzureConnection`
schemas; `/azure_triggers/*` endpoints; client regenerated
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore: update ee-repo-ref to eaa7c3a9cb37a9ccc93f10a2535d929365acd2d8
This commit updates the EE repository reference after PR #541 was merged in windmill-ee-private.
Previous ee-repo-ref: 9689014e8c12c36c1059fd8fa5758d550b8b8bc9
New ee-repo-ref: eaa7c3a9cb37a9ccc93f10a2535d929365acd2d8
Automated by sync-ee-ref workflow.
* feat(azure-trigger): secret-auth push, ARM discovery, capture isolation, CLI + parity
Frontend:
- Split mode selector into Namespace/Basic + Pull/Push
- ARM resource dropdowns (namespaces, Basic topics, namespace topics)
populated from the service principal; cascade with stale-selection
reset on SP / edition change
- Remove stale authenticate toggle + audience input (server-managed
push_auth_config has replaced them)
- Azure listing page: "Create from template" button; "Also delete Azure
subscription" toggle in the delete modal; simplified trigger label
falling back to path
- AzureCapture.svelte: "Test subscription name" with -wm-capture suffix
- CompareWorkspaces.svelte: wire Azure for fork/compare
- Drop Trigger-deployed/event-loss warning (capture subscription is
isolated with -wm-capture)
Backend:
- Shared-secret push auth (see EE crate for detail)
- JSONB push_auth_config column (renamed from delivery_config), #[serde(skip)]
so clients/CLI/exports never see it
- Drop redundant enabled column; mode supersedes
- Azure capture infra: AzureTriggerConfig + set_azure_trigger_config +
azure_payload route + TriggerKind::Azure arm; PT15M queue TTL on
capture subscriptions so they bound storage after tab close
- Granular ACLs, users offboarding, trash, git-sync deployed-object:
all include azure_trigger
CLI:
- Add azure to TRIGGER_TYPES, pushObj dispatch, getTypeStrFromPath,
trigger commands (get/update/create/list/template), sync delete
switch + regex; e2e test for `trigger new --kind azure`
- system_prompts: SCHEMA_MAPPINGS + schema_names include AzureTrigger;
auto-generated/* regenerated
Skill:
- .claude/skills/adding-a-trigger/ checklist covering every file that
needs editing when wiring a new trigger type (learned from this PR)
ee-repo-ref bumped to b0e490cbf3724b7b64c6a5b010e3bdf24acd873c.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(azure-trigger): ci — ShareModal Kind + regenerated system_prompts
- frontend/src/lib/components/ShareModal.svelte: add 'azure_trigger'
to the Kind type so the listing page's "Permissions" action compiles
(ts2345 — caught by npm_check on CI, missed by fast-check locally).
- system_prompts/auto-generated/: regenerate to drop the stale
delivery_config / AzureDeliveryConfig fields from the Azure schema
(check-freshness on CI).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* refactor(azure-trigger): use workspace constant_time_eq crate
Drop hand-rolled constant-time compare in favour of the workspace
constant_time_eq crate (same one used by http_trigger_auth).
ee-repo-ref bumped to 9659382d47286e7f7f66d01b6f5dd8d4ed34848b.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(azure-trigger): pass placeholder + disabled via inputProps
`TextInput`'s `placeholder` and `disabled` go through its `inputProps`
prop — CI's `npm run check` caught the stale top-level passing that
`npm run check:fast` missed. Align with the DefaultEmailConfigSection
pattern.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(azure-trigger): correct LATEST_GIT_SYNC_SCRIPT_PATH version to 28213
The hub deploy of the azure-aware sync-script is version 28213, not
28214. Backend was pinning a non-existent hub script, which broke the
git_sync_e2e suite (every deploy's sync step 404'd).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(azure-trigger): add azure_triggers to token scope selector + skill
- windmill-api/src/token.rs: `build_trigger_scope_domains` was missing
`("azure_triggers", "Azure Event Grid")`, so the CreateToken UI's scope
selector didn't surface azure_triggers:read/write. Backend already had
`ScopeDomain::AzureTriggers` wired (scopes.rs), this just exposes it.
- .claude/skills/adding-a-trigger/SKILL.md: capture both scope-related
files under the hardcoded-arrays section so future triggers don't miss
the UI surface.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs(adding-a-trigger-skill): clarify token.rs scope effect
Not a regression — nothing was working before. Skipping TRIGGER_DOMAINS
just means the scope works via API/CLI but has no UI checkbox.
* docs(adding-a-trigger-skill): trim token.rs bullet
* fix(azure-trigger): regen openapi-deref + swap textarea for TextInput
- Run build_openapi.sh to regenerate openapi-deref.{yaml,json} with the
12 azure_triggers paths + schemas. These files are served by the
runtime (include_str! in windmill-api/src/lib.rs) to external SDK
consumers; without this regen the new endpoints wouldn't be advertised.
- Replace the raw <textarea> for event type filters with the
design-system TextInput in textarea mode (frontend/CLAUDE.md bans raw
HTML elements).
Addresses cubic + claude PR review items.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
424 lines
14 KiB
TypeScript
424 lines
14 KiB
TypeScript
import { colors } from "@cliffy/ansi/colors";
|
|
import * as Diff from "diff";
|
|
import * as log from "./core/log.ts";
|
|
import * as path from "node:path";
|
|
import { sep as SEP } from "node:path";
|
|
import { stringify as yamlStringify } from "yaml";
|
|
import { yamlParseContent } from "./utils/yaml.ts";
|
|
import { pushApp } from "./commands/app/app.ts";
|
|
import { pushFolder } from "./commands/folder/folder.ts";
|
|
import { pushFlow } from "./commands/flow/flow.ts";
|
|
import { pushResource } from "./commands/resource/resource.ts";
|
|
import { pushResourceType } from "./commands/resource-type/resource-type.ts";
|
|
import { pushVariable } from "./commands/variable/variable.ts";
|
|
import { yamlOptions } from "./commands/sync/sync.ts";
|
|
import { showDiffs } from "./core/conf.ts";
|
|
import { deepEqual, isFileResource, isFilesetResource, isWorkspaceDependencies, readTextFileSync } from "./utils/utils.ts";
|
|
import { pushSchedule } from "./commands/schedule/schedule.ts";
|
|
import { pushWorkspaceUser } from "./commands/user/user.ts";
|
|
import { pushGroup } from "./commands/user/user.ts";
|
|
import { pushWorkspaceDependencies } from "./commands/dependencies/dependencies.ts";
|
|
import { pushWorkspaceSettings, pushWorkspaceKey } from "./core/settings.ts";
|
|
import { pushTrigger, pushNativeTrigger } from "./commands/trigger/trigger.ts";
|
|
import { pushRawApp } from "./commands/app/raw_apps.ts";
|
|
import type { PermissionedAsContext } from "./core/permissioned_as.ts";
|
|
import {
|
|
isFlowPath,
|
|
isAppPath,
|
|
isRawAppPath,
|
|
extractResourceName,
|
|
buildFolderPath,
|
|
isScriptModulePath,
|
|
} from "./utils/resource_folders.ts";
|
|
|
|
export interface DifferenceCreate {
|
|
type: "CREATE";
|
|
path: (string | number)[];
|
|
value: any;
|
|
}
|
|
|
|
export interface DifferenceRemove {
|
|
type: "REMOVE";
|
|
path: (string | number)[];
|
|
oldValue: any;
|
|
}
|
|
|
|
export interface DifferenceChange {
|
|
type: "CHANGE";
|
|
path: (string | number)[];
|
|
value: any;
|
|
oldValue: any;
|
|
}
|
|
|
|
export type Difference = DifferenceCreate | DifferenceRemove | DifferenceChange;
|
|
|
|
export const TRIGGER_TYPES = [
|
|
"http",
|
|
"websocket",
|
|
"kafka",
|
|
"nats",
|
|
"postgres",
|
|
"mqtt",
|
|
"sqs",
|
|
"gcp",
|
|
"azure",
|
|
"email",
|
|
] as const;
|
|
|
|
export const NATIVE_TRIGGER_SERVICES = ["nextcloud"] as const;
|
|
export type NativeTriggerService = (typeof NATIVE_TRIGGER_SERVICES)[number];
|
|
|
|
export type GlobalOptions = {
|
|
baseUrl: string | undefined;
|
|
workspace: string | undefined;
|
|
token: string | undefined;
|
|
configDir: string | undefined;
|
|
};
|
|
|
|
export function isSuperset(
|
|
subset: Record<string, any>,
|
|
superset: Record<string, any>
|
|
): boolean {
|
|
return Object.keys(subset).every((key) => {
|
|
const eq = deepEqual(subset[key], superset[key]);
|
|
if (!eq && showDiffs) {
|
|
const sub = subset[key];
|
|
const supers = superset[key];
|
|
if (!supers) {
|
|
log.info(`Key ${key} not found in remote`);
|
|
} else {
|
|
log.info(`Found diff for ${key}:`);
|
|
showDiff(
|
|
yamlStringify(sub, yamlOptions),
|
|
yamlStringify(supers, yamlOptions)
|
|
);
|
|
}
|
|
}
|
|
return eq;
|
|
});
|
|
}
|
|
|
|
export function showDiff(local: string, remote: string) {
|
|
let finalString = "";
|
|
if (local?.length > 20000 || remote?.length > 20000) {
|
|
log.info("Diff too large to display");
|
|
return;
|
|
}
|
|
|
|
for (const part of Diff.diffLines(local ?? "", remote ?? "")) {
|
|
if (part.removed) {
|
|
// print red if removed without newline
|
|
finalString += `\x1b[31m${part.value}\x1b[0m`;
|
|
} else if (part.added) {
|
|
// print green if added
|
|
finalString += `\x1b[32m${part.value}\x1b[0m`;
|
|
} else {
|
|
let lines = part.value.split("\n");
|
|
|
|
if (lines.length > 4) {
|
|
lines = lines.slice(0, 2);
|
|
lines.push("...");
|
|
lines = lines.concat(part.value.split("\n").slice(-2));
|
|
}
|
|
// print white if unchanged
|
|
finalString += `\x1b[37m${lines.join("\n")}\x1b[0m`;
|
|
}
|
|
}
|
|
log.info(finalString);
|
|
}
|
|
|
|
export function showConflict(path: string, local: string, remote: string) {
|
|
log.info(colors.yellow(`- ${path}`));
|
|
showDiff(local, remote);
|
|
log.info("\x1b[31mlocal\x1b[31m - \x1b[32mremote\x1b[32m");
|
|
log.info("\n");
|
|
}
|
|
|
|
/**
|
|
* Pushes an object to the workspace server based on its type
|
|
* @param workspace - The workspace ID to push to
|
|
* @param p - The server path (base path for branch-specific items)
|
|
* @param befObj - The previous object state (for updates)
|
|
* @param newObj - The new object state to push
|
|
* @param plainSecrets - Whether to store secrets in plain text
|
|
* @param alreadySynced - Array to track already synced items
|
|
* @param message - Optional commit/update message
|
|
* @param originalLocalPath - The original local file path (used for branch-specific resource file resolution)
|
|
*/
|
|
export async function pushObj(
|
|
workspace: string,
|
|
p: string,
|
|
befObj: any,
|
|
newObj: any,
|
|
plainSecrets: boolean,
|
|
alreadySynced: string[],
|
|
message?: string,
|
|
originalLocalPath?: string,
|
|
permissionedAsContext?: PermissionedAsContext
|
|
) {
|
|
const typeEnding = getTypeStrFromPath(p);
|
|
|
|
if (typeEnding === "app") {
|
|
const appName = extractResourceName(p, "app");
|
|
if (!appName) {
|
|
throw new Error(`Could not extract app name from path: ${p}`);
|
|
}
|
|
await pushApp(workspace, appName, buildFolderPath(appName, "app"), message, permissionedAsContext);
|
|
} else if (typeEnding === "raw_app") {
|
|
const rawAppName = extractResourceName(p, "raw_app");
|
|
if (!rawAppName) {
|
|
throw new Error(`Could not extract raw app name from path: ${p}`);
|
|
}
|
|
await pushRawApp(workspace, rawAppName, buildFolderPath(rawAppName, "raw_app"), message);
|
|
} else if (typeEnding === "folder") {
|
|
await pushFolder(workspace, p, befObj, newObj);
|
|
} else if (typeEnding === "variable") {
|
|
await pushVariable(workspace, p, befObj, newObj, plainSecrets);
|
|
} else if (typeEnding === "flow") {
|
|
const flowName = extractResourceName(p, "flow");
|
|
if (!flowName) {
|
|
throw new Error(`Could not extract flow name from path: ${p}`);
|
|
}
|
|
await pushFlow(workspace, flowName, buildFolderPath(flowName, "flow"), message, permissionedAsContext);
|
|
} else if (typeEnding === "resource") {
|
|
if (!alreadySynced.includes(p)) {
|
|
alreadySynced.push(p);
|
|
await pushResource(workspace, p, befObj, newObj, originalLocalPath || p);
|
|
}
|
|
} else if (typeEnding === "resource-type") {
|
|
await pushResourceType(workspace, p, befObj, newObj);
|
|
} else if (typeEnding === "schedule") {
|
|
await pushSchedule(workspace, p, befObj, newObj, permissionedAsContext);
|
|
} else if (typeEnding === "http_trigger") {
|
|
await pushTrigger("http", workspace, p, befObj, newObj, permissionedAsContext);
|
|
} else if (typeEnding === "websocket_trigger") {
|
|
await pushTrigger("websocket", workspace, p, befObj, newObj, permissionedAsContext);
|
|
} else if (typeEnding === "kafka_trigger") {
|
|
await pushTrigger("kafka", workspace, p, befObj, newObj, permissionedAsContext);
|
|
} else if (typeEnding === "nats_trigger") {
|
|
await pushTrigger("nats", workspace, p, befObj, newObj, permissionedAsContext);
|
|
} else if (typeEnding === "postgres_trigger") {
|
|
await pushTrigger("postgres", workspace, p, befObj, newObj, permissionedAsContext);
|
|
} else if (typeEnding === "mqtt_trigger") {
|
|
await pushTrigger("mqtt", workspace, p, befObj, newObj, permissionedAsContext);
|
|
} else if (typeEnding === "sqs_trigger") {
|
|
await pushTrigger("sqs", workspace, p, befObj, newObj, permissionedAsContext);
|
|
} else if (typeEnding === "gcp_trigger") {
|
|
await pushTrigger("gcp", workspace, p, befObj, newObj, permissionedAsContext);
|
|
} else if (typeEnding === "azure_trigger") {
|
|
await pushTrigger("azure", workspace, p, befObj, newObj, permissionedAsContext);
|
|
} else if (typeEnding === "email_trigger") {
|
|
await pushTrigger("email", workspace, p, befObj, newObj, permissionedAsContext);
|
|
} else if (typeEnding === "native_trigger") {
|
|
await pushNativeTrigger(workspace, p, befObj, newObj);
|
|
} else if (typeEnding === "user") {
|
|
await pushWorkspaceUser(workspace, p, befObj, newObj);
|
|
} else if (typeEnding === "group") {
|
|
await pushGroup(workspace, p, befObj, newObj);
|
|
} else if (typeEnding === "workspace_dependencies") {
|
|
await pushWorkspaceDependencies(workspace, p, befObj, newObj);
|
|
} else if (typeEnding === "settings") {
|
|
await pushWorkspaceSettings(workspace, p, befObj, newObj);
|
|
} else if (typeEnding === "encryption_key") {
|
|
await pushWorkspaceKey(workspace, p, befObj, newObj);
|
|
} else {
|
|
throw new Error(
|
|
`The item ${p} has an unrecognized type ending ${typeEnding}`
|
|
);
|
|
}
|
|
}
|
|
|
|
export function parseFromPath(p: string, content: string): any {
|
|
return isWorkspaceDependencies(p)
|
|
? content
|
|
: p.endsWith(".yaml")
|
|
? yamlParseContent(p, content)
|
|
: p.endsWith(".json")
|
|
? JSON.parse(content)
|
|
: content;
|
|
}
|
|
export function parseFromFile(p: string): any {
|
|
if (p.endsWith(".json")) {
|
|
return JSON.parse(readTextFileSync(p));
|
|
} else if (p.endsWith(".yaml") || p.endsWith(".yml")) {
|
|
return yamlParseContent(p, readTextFileSync(p));
|
|
} else {
|
|
throw new Error("Could not read file " + p);
|
|
}
|
|
}
|
|
export function getTypeStrFromPath(
|
|
p: string
|
|
):
|
|
| "script"
|
|
| "variable"
|
|
| "flow"
|
|
| "resource"
|
|
| "resource-type"
|
|
| "folder"
|
|
| "app"
|
|
| "raw_app"
|
|
| "schedule"
|
|
| "http_trigger"
|
|
| "websocket_trigger"
|
|
| "kafka_trigger"
|
|
| "nats_trigger"
|
|
| "postgres_trigger"
|
|
| "mqtt_trigger"
|
|
| "sqs_trigger"
|
|
| "gcp_trigger"
|
|
| "azure_trigger"
|
|
| "email_trigger"
|
|
| "native_trigger"
|
|
| "user"
|
|
| "group"
|
|
| "settings"
|
|
| "encryption_key"
|
|
| "workspace_dependencies" {
|
|
if (isScriptModulePath(p)) {
|
|
return "script";
|
|
}
|
|
if (isFlowPath(p)) {
|
|
return "flow";
|
|
}
|
|
if (isAppPath(p)) {
|
|
return "app";
|
|
}
|
|
if (isRawAppPath(p)) {
|
|
return "raw_app";
|
|
}
|
|
if (p.startsWith("dependencies" + SEP)) {
|
|
return "workspace_dependencies";
|
|
}
|
|
if (isFileResource(p) || isFilesetResource(p)) {
|
|
return "resource";
|
|
}
|
|
const parsed = path.parse(p);
|
|
if (
|
|
parsed.ext == ".go" ||
|
|
parsed.ext == ".ts" ||
|
|
parsed.ext == ".sh" ||
|
|
parsed.ext == ".py" ||
|
|
parsed.ext == ".sql" ||
|
|
parsed.ext == ".gql" ||
|
|
parsed.ext == ".ps1" ||
|
|
parsed.ext == ".js" ||
|
|
parsed.ext == ".php" ||
|
|
parsed.ext == ".rs" ||
|
|
parsed.ext == ".cs" ||
|
|
parsed.ext == ".nu" ||
|
|
parsed.ext == ".java" ||
|
|
parsed.ext == ".rb" ||
|
|
parsed.ext == ".r" ||
|
|
// for related places search: ADD_NEW_LANG
|
|
(parsed.ext == ".yml" && parsed.name.split(".").pop() == "playbook")
|
|
) {
|
|
return "script";
|
|
}
|
|
// Match folder.meta (base) or folder.<branch>.meta (branch-specific)
|
|
if (parsed.name === "folder.meta" || /^folder\.[^.]+\.meta$/.test(parsed.name)) {
|
|
return "folder";
|
|
}
|
|
// Match settings (base) or settings.<branch> (branch-specific)
|
|
if (parsed.name === "settings" || /^settings\.[^.]+$/.test(parsed.name)) {
|
|
return "settings";
|
|
}
|
|
// Match encryption_key (base) or encryption_key.<branch> (branch-specific)
|
|
if (parsed.name === "encryption_key" || /^encryption_key\.[^.]+$/.test(parsed.name)) {
|
|
return "encryption_key";
|
|
}
|
|
|
|
const typeEnding = parsed.name.split(".").at(-1);
|
|
// Check for native trigger: {service}_native_trigger pattern
|
|
if (typeEnding?.endsWith("_native_trigger")) {
|
|
return "native_trigger";
|
|
}
|
|
if (
|
|
typeEnding === "script" ||
|
|
typeEnding === "variable" ||
|
|
typeEnding === "resource" ||
|
|
typeEnding === "resource-type" ||
|
|
typeEnding === "app" ||
|
|
typeEnding === "schedule" ||
|
|
typeEnding === "http_trigger" ||
|
|
typeEnding === "websocket_trigger" ||
|
|
typeEnding === "kafka_trigger" ||
|
|
typeEnding === "nats_trigger" ||
|
|
typeEnding === "postgres_trigger" ||
|
|
typeEnding === "mqtt_trigger" ||
|
|
typeEnding === "sqs_trigger" ||
|
|
typeEnding === "gcp_trigger" ||
|
|
typeEnding === "azure_trigger" ||
|
|
typeEnding === "email_trigger" ||
|
|
typeEnding === "user" ||
|
|
typeEnding === "group" ||
|
|
typeEnding === "settings" ||
|
|
typeEnding === "encryption_key"
|
|
) {
|
|
return typeEnding;
|
|
} else {
|
|
throw new Error("Could not infer type of path " + JSON.stringify(parsed));
|
|
}
|
|
}
|
|
|
|
export function removeType(str: string, type: string) {
|
|
// Normalize path for cross-platform compatibility and convert to forward slashes for API consistency
|
|
const normalizedStr = path.normalize(str).replaceAll(SEP, "/");
|
|
|
|
if (
|
|
normalizedStr.endsWith("." + type + ".yaml") ||
|
|
normalizedStr.endsWith("." + type + ".json")
|
|
) {
|
|
return normalizedStr.slice(0, normalizedStr.length - type.length - 6);
|
|
}
|
|
// Accept clean paths without the type suffix (e.g. "f/folder/name" instead of "f/folder/name.schedule.yaml")
|
|
if (normalizedStr.includes("." + type)) {
|
|
log.debug(`Path '${str}' contains '.${type}' but doesn't end with '.${type}.(yaml|json)' — treating as clean path`);
|
|
}
|
|
return normalizedStr;
|
|
}
|
|
|
|
/**
|
|
* Extracts native trigger info from a path like:
|
|
* u/admin/script.flow.12345.nextcloud_native_trigger.json
|
|
* Returns { scriptPath: "u/admin/script", isFlow: true, externalId: "12345", serviceName: "nextcloud" }
|
|
*/
|
|
export function extractNativeTriggerInfo(p: string): {
|
|
scriptPath: string;
|
|
isFlow: boolean;
|
|
externalId: string;
|
|
serviceName: string;
|
|
} | null {
|
|
// Remove extension (.json or .yaml)
|
|
const normalizedPath = path.normalize(p).replaceAll(SEP, "/");
|
|
const withoutExt = normalizedPath.replace(/\.(json|yaml)$/, "");
|
|
|
|
// Match pattern: {script_path}.{flow|script}.{external_id}.{service}_native_trigger
|
|
const match = withoutExt.match(/^(.+)\.(flow|script)\.([^.]+)\.(\w+)_native_trigger$/);
|
|
if (!match) {
|
|
return null;
|
|
}
|
|
|
|
return {
|
|
scriptPath: match[1],
|
|
isFlow: match[2] === "flow",
|
|
externalId: match[3],
|
|
serviceName: match[4],
|
|
};
|
|
}
|
|
|
|
export function removePathPrefix(str: string, prefix: string) {
|
|
// Normalize paths for cross-platform compatibility and convert to forward slashes for API consistency
|
|
const normalizedStr = path.normalize(str).replaceAll(SEP, "/");
|
|
const normalizedPrefix = path.normalize(prefix).replaceAll(SEP, "/");
|
|
|
|
// Handle exact match case
|
|
if (normalizedStr === normalizedPrefix) {
|
|
return "";
|
|
}
|
|
|
|
if (!normalizedStr.startsWith(normalizedPrefix + "/")) {
|
|
throw new Error(str + " does not start with " + prefix);
|
|
}
|
|
return normalizedStr.slice(normalizedPrefix.length + 1);
|
|
}
|