@@ -14,42 +14,65 @@ const { AgentType, Platform } = Constants.public.Enums;
1414
1515type PlatformAccountDataInput = TablesInsert < "PlatformAccount" > ;
1616
17- const accountValidator : ItemValidator < PlatformAccountDataInput > = ( account : any ) => {
17+ const accountValidator : ItemValidator < PlatformAccountDataInput > = (
18+ account : any ,
19+ ) => {
1820 if ( ! account || typeof account !== "object" )
1921 return "Invalid request body: expected a JSON object." ;
20- const { name, platform, account_local_id, write_permission, active, agent_type, metadata, dg_account } = account ;
22+ const {
23+ name,
24+ platform,
25+ account_local_id,
26+ write_permission,
27+ active,
28+ agent_type,
29+ metadata,
30+ dg_account,
31+ } = account ;
2132
2233 if ( ! name || typeof name !== "string" || name . trim ( ) === "" )
2334 return "Missing or invalid name" ;
2435 // This is not dry, to be rewritten with Drizzle/Zed.
25- if ( ! Platform . includes ( platform ) )
26- return "Missing or invalid platform" ;
36+ if ( ! Platform . includes ( platform ) ) return "Missing or invalid platform" ;
2737 if ( agent_type !== undefined && ! AgentType . includes ( agent_type ) )
2838 return "Invalid agent_type" ;
29- if ( write_permission !== undefined && typeof write_permission != ' boolean' )
39+ if ( write_permission !== undefined && typeof write_permission != " boolean" )
3040 return "write_permission must be boolean" ;
31- if ( active !== undefined && typeof active != ' boolean' )
41+ if ( active !== undefined && typeof active != " boolean" )
3242 return "active must be boolean" ;
3343 if ( metadata !== undefined ) {
34- if ( typeof metadata != ' string' )
35- return "metadata should be a JSON string" ;
36- else try {
37- JSON . parse ( metadata )
38- } catch ( error ) {
39- return "metadata should be a JSON string" ;
40- }
44+ if ( typeof metadata != " string" ) return "metadata should be a JSON string" ;
45+ else
46+ try {
47+ JSON . parse ( metadata ) ;
48+ } catch ( error ) {
49+ return "metadata should be a JSON string" ;
50+ }
4151 }
42- if ( ! account_local_id || typeof account_local_id != "string" || account_local_id . trim ( ) === "" )
52+ if (
53+ ! account_local_id ||
54+ typeof account_local_id != "string" ||
55+ account_local_id . trim ( ) === ""
56+ )
4357 return "Missing or invalid account_local_id" ;
4458 if ( dg_account != undefined ) {
4559 if ( typeof dg_account != "string" )
4660 return "dg_account should be a UUID string" ;
47- const uuidRegex = / ^ [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 12 } $ / i ;
48- if ( ! uuidRegex . test ( dg_account ) )
49- return "dg_account must be a valid UUID" ;
61+ const uuidRegex =
62+ / ^ [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 12 } $ / i ;
63+ if ( ! uuidRegex . test ( dg_account ) ) return "dg_account must be a valid UUID" ;
5064 }
51- const keys = [ 'name' , 'platform' , 'account_local_id' , 'write_permission' , 'active' , 'agent_type' , 'metadata' , 'dg_account' ] ;
52- if ( ! Object . keys ( account ) . every ( ( key ) => keys . includes ( key ) ) )
65+ const keys = [
66+ "name" ,
67+ "platform" ,
68+ "account_local_id" ,
69+ "write_permission" ,
70+ "active" ,
71+ "agent_type" ,
72+ "metadata" ,
73+ "dg_account" ,
74+ ] ;
75+ if ( ! Object . keys ( account ) . every ( ( key ) => keys . includes ( key ) ) )
5376 return "Invalid account object: extra keys" ;
5477 return null ;
5578} ;
0 commit comments