@@ -8,13 +8,15 @@ export class Entry {
88 private _contentTypeUid : string ;
99 private _entryUid : string ;
1010 private _urlPath : string ;
11+ protected _variants : string ;
1112 _queryParams : { [ key : string ] : string | number | string [ ] } = { } ;
1213
1314 constructor ( client : AxiosInstance , contentTypeUid : string , entryUid : string ) {
1415 this . _client = client ;
1516 this . _contentTypeUid = contentTypeUid ;
1617 this . _entryUid = entryUid ;
1718 this . _urlPath = `/content_types/${ this . _contentTypeUid } /entries/${ this . _entryUid } ` ;
19+ this . _variants = '' ;
1820 }
1921
2022 /**
@@ -47,9 +49,9 @@ export class Entry {
4749 */
4850 variants ( variants : string | string [ ] ) : Entry {
4951 if ( Array . isArray ( variants ) && variants . length > 0 ) {
50- this . _client . defaults . headers [ 'x-cs-variant-uid' ] = variants . join ( ',' ) ;
52+ this . _variants = variants . join ( ',' ) ;
5153 } else if ( typeof variants == 'string' && variants . length > 0 ) {
52- this . _client . defaults . headers [ 'x-cs-variant-uid' ] = variants ;
54+ this . _variants = variants ;
5355 }
5456
5557 return this ;
@@ -152,7 +154,15 @@ export class Entry {
152154 * const result = await stack.contentType(contentType_uid).entry(entry_uid).fetch();
153155 */
154156 async fetch < T > ( ) : Promise < T > {
155- const response = await getData ( this . _client , this . _urlPath , this . _queryParams ) ;
157+ const getRequestOptions : any = { params : this . _queryParams } ;
158+ if ( this . _variants ) {
159+ getRequestOptions . headers = {
160+ ...getRequestOptions . headers ,
161+ 'x-cs-variant-uid' : this . _variants
162+ } ;
163+ }
164+
165+ const response = await getData ( this . _client , this . _urlPath , getRequestOptions ) ;
156166
157167 if ( response . entry ) return response . entry as T ;
158168
0 commit comments