@@ -6,6 +6,7 @@ import { WidgetConfiguration } from '../schema/schemaParser/schemaParser';
66export const widgetApi = {
77 widgetPreviewRender : `${ AUTH_CONFIG . apiPath } /content/widget-templates/preview` ,
88 widgetTemplatePublish : `${ AUTH_CONFIG . apiPath } /content/widget-templates` ,
9+ widgetTemplateList : `${ AUTH_CONFIG . apiPath } /content/widget-templates` ,
910} ;
1011
1112interface WidgetPreviewRenderResponse {
@@ -65,3 +66,52 @@ export const publishWidget = (
6566 . then ( ( { data : { data } } ) => resolve ( data ) )
6667 . catch ( error => reject ( error ) ) ;
6768} ) ;
69+
70+ export const getWidgetTemplate = (
71+ name : string
72+ ) : Promise < string > => new Promise ( ( resolve , reject ) =>
73+ getAllTemplates ( )
74+ . then ( ( data ) => {
75+ const match = data . find (
76+ template => name === template . name ,
77+ ) ;
78+
79+ resolve ( match ?. uuid || '' ) ;
80+ } )
81+ . catch ( error => reject ( error ) ) )
82+
83+ export interface WidgetTemplateResult {
84+ name : string ;
85+ schema : any [ ] ;
86+ template : string ;
87+ storefront_api_query : string ;
88+ uuid : string ;
89+ kind : string ;
90+ date_created : string ;
91+ date_modified : string ;
92+ current_version_uuid : string ;
93+ icon_name : string ;
94+ }
95+
96+ const getAllTemplates = async ( page : number = 1 ) : Promise < WidgetTemplateResult [ ] > => {
97+ let listResults : WidgetTemplateResult [ ] = [ ] ;
98+ let done = false ;
99+
100+ while ( ! done ) {
101+ const { data } = ( await Axios ( {
102+ headers : {
103+ Accept : 'application/json' ,
104+ 'Content-Type' : 'application/json' ,
105+ 'X-Auth-Client' : AUTH_CONFIG . authId ,
106+ 'X-Auth-Token' : AUTH_CONFIG . authToken ,
107+ } ,
108+ url : `${ widgetApi . widgetTemplateList } ?limit=250&page=${ page } ` ,
109+ } ) ) . data ;
110+
111+ done = data . length === 0 ;
112+ page ++ ;
113+ listResults = listResults . concat ( data ) ;
114+ }
115+
116+ return listResults ;
117+ }
0 commit comments