@@ -105,8 +105,8 @@ <h3>Properties</h3>
105105</ script >
106106
107107< script type ="text/x-red " data-help-name ="aws-sdk ">
108- < p > AWS SDK</ p >
109- < p > You can extend this flow by connecting it to your AWS using the AWS SDK node . Refer to < a href = "https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/index.html" target = "_blank" > AWS api documents . < / a > < / p>
108+ < p > AWS SDK v2 </ p >
109+ < p > You can extend this flow by connecting it to your AWS using the AWS SDK v2 node . Refer to < a href = "https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/index.html" target = "_blank" > AWS api documents . < / a > < / p>
110110 < h3 > Properties</ h3 >
111111< dl class = "message-properties" >
112112 < dt > Name</ dt >
@@ -123,6 +123,49 @@ <h3>Properties</h3>
123123
124124</ script >
125125
126+ < script type ="text/x-red " data-template-name ="aws-sdk-v3 ">
127+ < div class = "form-row" >
128+ < label for = "node-input-name" > < i class = "fa fa-tag" > </ i > Name</ label >
129+ < input type = "text" id = "node-input-name" placeholder = "Name" > </ input >
130+ </ div >
131+ < div class = "form-row" >
132+ < label for = "node-input-config" > < i class = "fa fa-user" > </ i > AWS Config</ label >
133+ < select type = "text" id = "node-input-config" > < / select >
134+ </ div >
135+ < div class = "form-row" >
136+ < label for = "node-input-client" > < i class = "fa fa-cog" > </ i > Service</ label >
137+ < select type = "text" id = "node-input-client" > < / select >
138+ </ div >
139+ < div class = "form-row" >
140+ < label for = "node-input-operation" > < i class = "fa fa-wrench" > </ i > Command</ label >
141+ < select type = "text" id = "node-input-operation" > < / select >
142+ </ div >
143+ < div class = "form-row" >
144+ < label for = "node-input-params" > < i class = "fa fa-code" > </ i > Params</ label >
145+ < input type = "hidden" id = "node-input-params" value = "{}" autofocus = "autofocus" / >
146+ < input type = "hidden" id = "node-input-noerr" />
147+ < div class = "form-row node-text-editor-row" > < div style = "height: 250px; min-height:150px;" class = "node-text-editor" id = "node-input-param-editor" > </ div > < / d i v >
148+ </div >
149+ </ script >
150+
151+ < script type ="text/x-red " data-help-name ="aws-sdk-v3 ">
152+ < p > AWS SDK v3</ p >
153+ < p > You can extend this flow by connecting it to your AWS using the AWS SDK v3 node . Refer to < a href = "https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/index.html" target = "_blank" > AWS api documents . < / a > < / p>
154+ < h3 > Properties</ h3 >
155+ < dl class = "message-properties" >
156+ < dt > Name</ dt >
157+ < dd > You can tag or describe this aws - sdk - v3 . < / d d >
158+ < dt > AWS Config < span class = "property-type" > required</ span > </ dt >
159+ < dd > Choose a AWS Config Node . < / d d >
160+ < dt > Service < span class = "property-type" > required</ span > </ dt >
161+ < dd > Choose a AWS Service < / d d >
162+ < dt > Command < span class = "property-type" > required</ span > </ dt >
163+ < dd > Choose a AWS Command . < / d d >
164+ < dt > Params < span class = "property-type" > optional</ span > </ dt >
165+ < dd > Insert a params of method . refer to each method description on AWS api documents . It 's a JSON string. You can use <a href="http://mustache.github.io/mustache.5.html" target="_blank">mustache</a> templates.</dd>
166+ </dl >
167+ </ script >
168+
126169< script type ="text/javascript ">
127170 RED . nodes . registerType ( 'aws-config' , {
128171 category : 'Samsung AutomationStudio' ,
@@ -167,13 +210,13 @@ <h3>Properties</h3>
167210 } ,
168211 inputs : 1 ,
169212 outputs : 1 ,
170- paletteLabel : "AWS SDK" ,
213+ paletteLabel : "AWS SDK v2 " ,
171214 icon : "aws.png" ,
172215 align : "right" ,
173216 label : function ( ) {
174217 if ( this . name ) return this . name ;
175218 if ( this . service && this . operation ) return this . service + "." + this . operation ;
176- return "AWS SDK" ;
219+ return "AWS SDK v2 " ;
177220 } ,
178221 oneditprepare : function ( ) {
179222 var NODE = this ;
@@ -235,6 +278,165 @@ <h3>Properties</h3>
235278 this . editor . resize ( ) ;
236279 }
237280 } ) ;
281+
282+ let allClientsData = null ;
283+ async function loadAWSClientsData ( ) {
284+ if ( allClientsData ) {
285+ return allClientsData ;
286+ }
287+
288+ allClientsData = await $ . ajax ( {
289+ url : 'icons/node-red-contrib-samsung-automation-studio-nodes/aws_sdk_v3_clients.json' ,
290+ dataType : 'json' ,
291+ } )
292+
293+ return allClientsData ;
294+ }
295+
296+ function removeClientSuffix ( clientName ) {
297+ if ( clientName . endsWith ( "Client" ) ) {
298+ return clientName . slice ( 0 , - 6 ) ;
299+ }
300+ return clientName ;
301+ }
302+
303+ RED . nodes . registerType ( 'aws-sdk-v3' , {
304+ category : 'Samsung AutomationStudio' ,
305+ color : '#FF9900' ,
306+ defaults : {
307+ config : {
308+ value : '' , required : true ,
309+ validate : function ( val ) {
310+ var isValidAwsConfig = false ;
311+ RED . nodes . eachNode ( function ( node ) {
312+ if ( node . id == val ) {
313+ isValidAwsConfig = true
314+ }
315+ } )
316+ return ! ! val && isValidAwsConfig
317+ }
318+ } ,
319+ name : { value : '' } ,
320+ client : { value : '' , required : true } ,
321+ operation : { value : '' , required : true } ,
322+ params : { value : '{}' }
323+ } ,
324+ inputs : 1 ,
325+ outputs : 1 ,
326+ paletteLabel : "AWS SDK v3" ,
327+ icon : "aws.png" ,
328+ align : "right" ,
329+ label : function ( ) {
330+ if ( this . name ) return this . name ;
331+ if ( this . operation ) return this . operation ;
332+ return "AWS SDK v3" ;
333+ } ,
334+ oneditprepare : function ( ) {
335+ var NODE = this ;
336+ $ ( "#node-input-config" ) . html ( '' ) ;
337+ RED . nodes . eachNode ( function ( node ) {
338+ if ( node . name && node . region && node . type == 'aws-config' ) {
339+ $ ( "#node-input-config" ) . append ( $ ( "<option></option>" ) . val ( node . id ) . text ( node . name + " (" + node . id + ")" ) ) ;
340+ }
341+ } ) ;
342+
343+ console . log ( "data : " ) ;
344+ loadAWSClientsData ( ) . then ( ( data ) => {
345+ console . log ( "data : " , data ) ;
346+ const clientEl = $ ( '#node-input-client' ) ;
347+ const operationEl = $ ( '#node-input-operation' ) ;
348+
349+ const initialClient = NODE . client || null ;
350+ const initialOperation = NODE . operation || null ;
351+
352+ clientEl . on ( 'change' , ( e ) => {
353+ const selectedClient = e . target . value ;
354+ const commands = data [ selectedClient ] . commands ;
355+
356+ operationEl . empty ( ) ;
357+
358+ if ( Array . isArray ( commands ) ) {
359+ commands . forEach ( command => {
360+ operationEl . append (
361+ $ ( '<option></option>' )
362+ . val ( command )
363+ . text ( command )
364+ ) ;
365+ } ) ;
366+
367+ if ( initialClient === selectedClient && initialOperation ) {
368+ operationEl . val ( initialOperation ) ;
369+ }
370+ }
371+ } ) ;
372+
373+ Object . keys ( data ) . forEach ( packageName => {
374+ clientEl . append (
375+ $ ( '<option></option>' )
376+ . val ( packageName )
377+ . text ( removeClientSuffix ( data [ packageName ] . client ) )
378+ ) ;
379+ } ) ;
380+
381+ if ( initialClient && data [ initialClient ] ) {
382+ clientEl . val ( initialClient ) ;
383+ }
384+
385+ clientEl . trigger ( 'change' ) ;
386+ } ) ;
387+
388+ $ ( "#node-input-config" ) . val ( NODE . config ) ;
389+ this . editor = RED . editor . createEditor ( {
390+ id : 'node-input-param-editor' ,
391+ mode : 'ace/mode/mustache' ,
392+ value : $ ( "#node-input-params" ) . val ( ) ,
393+ globals : {
394+ msg : true ,
395+ context : true ,
396+ RED : true ,
397+ util : true ,
398+ flow : true ,
399+ global : true ,
400+ console : true ,
401+ Buffer : true ,
402+ setTimeout : true ,
403+ clearTimeout : true ,
404+ setInterval : true ,
405+ clearInterval : true
406+ }
407+ } ) ;
408+ this . editor . focus ( ) ;
409+ } ,
410+ oneditsave : function ( ) {
411+ var annot = this . editor . getSession ( ) . getAnnotations ( ) ;
412+ this . noerr = 0 ;
413+ $ ( "#node-input-noerr" ) . val ( 0 ) ;
414+ for ( var k = 0 ; k < annot . length ; k ++ ) {
415+ if ( annot [ k ] . type === "error" ) {
416+ $ ( "#node-input-noerr" ) . val ( annot . length ) ;
417+ this . noerr = annot . length ;
418+ }
419+ }
420+ $ ( "#node-input-params" ) . val ( this . editor . getValue ( ) ) ;
421+ this . editor . destroy ( ) ;
422+ delete this . editor ;
423+ } ,
424+ oneditcancel : function ( ) {
425+ this . editor . destroy ( ) ;
426+ delete this . editor ;
427+ } ,
428+ oneditresize : function ( size ) {
429+ var rows = $ ( "#dialog-form>div:not(.node-text-editor-row)" ) ;
430+ var height = $ ( "#dialog-form" ) . height ( ) ;
431+ for ( var i = 0 ; i < rows . size ( ) ; i ++ ) {
432+ height -= $ ( rows [ i ] ) . outerHeight ( true ) ;
433+ }
434+ var editorRow = $ ( "#dialog-form>div.node-text-editor-row" ) ;
435+ height -= ( parseInt ( editorRow . css ( "marginTop" ) ) + parseInt ( editorRow . css ( "marginBottom" ) ) ) ;
436+ $ ( ".node-text-editor" ) . css ( "height" , height + "px" ) ;
437+ this . editor . resize ( ) ;
438+ }
439+ } ) ;
238440</ script >
239441
240442
0 commit comments