@@ -7,6 +7,12 @@ import { db } from "@ctrlplane/db/client";
77import * as schema from "@ctrlplane/db/schema" ;
88import { getClientFor } from "@ctrlplane/workspace-engine-sdk" ;
99
10+ const slugifyWorkflowName = ( name : string ) =>
11+ name
12+ . toLowerCase ( )
13+ . replace ( / [ ^ a - z 0 - 9 ] + / g, "-" )
14+ . replace ( / ^ - + | - + $ / g, "" ) ;
15+
1016const listWorkflows : AsyncTypedHandler <
1117 "/v1/workspaces/{workspaceId}/workflows" ,
1218 "get"
@@ -29,9 +35,10 @@ const listWorkflows: AsyncTypedHandler<
2935 . limit ( limit )
3036 . offset ( offset ) ;
3137
32- const items = rows . map ( ( { id, name, inputs, jobAgents } ) => ( {
38+ const items = rows . map ( ( { id, name, slug , inputs, jobAgents } ) => ( {
3339 id,
3440 name,
41+ slug,
3542 inputs,
3643 jobAgents,
3744 } ) ) ;
@@ -44,14 +51,15 @@ const createWorkflow: AsyncTypedHandler<
4451 "post"
4552> = async ( req , res ) => {
4653 const { workspaceId } = req . params ;
54+ const slug = req . body . slug ?? slugifyWorkflowName ( req . body . name ) ;
4755 const created = await db
4856 . insert ( schema . workflow )
49- . values ( { ...req . body , workspaceId } )
57+ . values ( { ...req . body , slug , workspaceId } )
5058 . returning ( )
5159 . then ( takeFirst ) ;
5260
5361 const { id, name, inputs, jobAgents } = created ;
54- res . status ( 201 ) . json ( { id, name, inputs, jobAgents } ) ;
62+ res . status ( 201 ) . json ( { id, name, slug , inputs, jobAgents } ) ;
5563} ;
5664
5765const getWorkflow : AsyncTypedHandler <
@@ -72,8 +80,8 @@ const getWorkflow: AsyncTypedHandler<
7280
7381 if ( workflow == null ) throw new NotFoundError ( "Workflow not found" ) ;
7482
75- const { id, name, inputs, jobAgents } = workflow ;
76- res . json ( { id, name, inputs, jobAgents } ) ;
83+ const { id, name, slug , inputs, jobAgents } = workflow ;
84+ res . json ( { id, name, slug , inputs, jobAgents } ) ;
7785} ;
7886
7987const updateWorkflow : AsyncTypedHandler <
@@ -95,8 +103,8 @@ const updateWorkflow: AsyncTypedHandler<
95103
96104 if ( updated == null ) throw new NotFoundError ( "Workflow not found" ) ;
97105
98- const { id, name, inputs, jobAgents } = updated ;
99- res . status ( 202 ) . json ( { id, name, inputs, jobAgents } ) ;
106+ const { id, name, slug , inputs, jobAgents } = updated ;
107+ res . status ( 202 ) . json ( { id, name, slug , inputs, jobAgents } ) ;
100108} ;
101109
102110const deleteWorkflow : AsyncTypedHandler <
@@ -117,8 +125,8 @@ const deleteWorkflow: AsyncTypedHandler<
117125
118126 if ( deleted == null ) throw new NotFoundError ( "Workflow not found" ) ;
119127
120- const { id, name, inputs, jobAgents } = deleted ;
121- res . status ( 202 ) . json ( { id, name, inputs, jobAgents } ) ;
128+ const { id, name, slug , inputs, jobAgents } = deleted ;
129+ res . status ( 202 ) . json ( { id, name, slug , inputs, jobAgents } ) ;
122130} ;
123131
124132const createWorkflowRun : AsyncTypedHandler <
0 commit comments