@@ -8,6 +8,7 @@ export class BaseQuery extends Pagination {
8
8
9
9
protected _client ! : AxiosInstance ;
10
10
protected _urlPath ! : string ;
11
+ protected _variants ! : string ;
11
12
12
13
/**
13
14
* @method includeCount
@@ -16,7 +17,7 @@ export class BaseQuery extends Pagination {
16
17
* @example
17
18
* import contentstack from '@contentstack/delivery-sdk'
18
19
*
19
- * const stack = contentstack.Stack ({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
20
+ * const stack = contentstack.stack ({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
20
21
* const query = stack.contentType("contentTypeUid").entry().query();
21
22
* const result = await query.includeCount().find()
22
23
* // OR
@@ -37,7 +38,7 @@ export class BaseQuery extends Pagination {
37
38
* @example
38
39
* import contentstack from '@contentstack/delivery-sdk'
39
40
*
40
- * const stack = contentstack.Stack ({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
41
+ * const stack = contentstack.stack ({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
41
42
* const query = stack.contentType("contentTypeUid").entry().query();
42
43
* const result = await query.orderByAscending("field_uid").find()
43
44
* // OR
@@ -58,7 +59,7 @@ export class BaseQuery extends Pagination {
58
59
* @example
59
60
* import contentstack from '@contentstack/delivery-sdk'
60
61
*
61
- * const stack = contentstack.Stack ({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
62
+ * const stack = contentstack.stack ({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
62
63
* const query = stack.contentType("contentTypeUid").entry().query();
63
64
* const result = await query.orderByDescending("field_uid").find()
64
65
* // OR
@@ -79,7 +80,7 @@ export class BaseQuery extends Pagination {
79
80
* @example
80
81
* import contentstack from '@contentstack/delivery-sdk'
81
82
*
82
- * const stack = contentstack.Stack ({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
83
+ * const stack = contentstack.stack ({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
83
84
* const query = stack.contentType("contentTypeUid").entry().query();
84
85
* const result = await query.limit("limit_value").find()
85
86
* // OR
@@ -100,7 +101,7 @@ export class BaseQuery extends Pagination {
100
101
* @example
101
102
* import contentstack from '@contentstack/delivery-sdk'
102
103
*
103
- * const stack = contentstack.Stack ({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
104
+ * const stack = contentstack.stack ({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
104
105
* const query = stack.contentType("contentTypeUid").entry().query();
105
106
* const result = await query.skip("skip_value").find()
106
107
* // OR
@@ -123,7 +124,7 @@ export class BaseQuery extends Pagination {
123
124
* @example
124
125
* import contentstack from '@contentstack/delivery-sdk'
125
126
*
126
- * const stack = contentstack.Stack ({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
127
+ * const stack = contentstack.stack ({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
127
128
* const query = stack.contentType("contentTypeUid").entry().query();
128
129
* const result = await query.param("key", "value").find()
129
130
* // OR
@@ -144,7 +145,7 @@ export class BaseQuery extends Pagination {
144
145
* @example
145
146
* import contentstack from '@contentstack/delivery-sdk'
146
147
*
147
- * const stack = contentstack.Stack ({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
148
+ * const stack = contentstack.stack ({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
148
149
* const query = stack.contentType("contentTypeUid").entry().query();
149
150
* const result = await query.addParams({"key": "value"}).find()
150
151
* // OR
@@ -165,7 +166,7 @@ export class BaseQuery extends Pagination {
165
166
* @example
166
167
* import contentstack from '@contentstack/delivery-sdk'
167
168
*
168
- * const stack = contentstack.Stack ({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
169
+ * const stack = contentstack.stack ({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
169
170
* const query = stack.contentType("contentTypeUid").entry().query();
170
171
* const result = await query.removeParam("query_param_key").find()
171
172
* // OR
@@ -187,25 +188,37 @@ export class BaseQuery extends Pagination {
187
188
* @example
188
189
* import contentstack from '@contentstack/delivery-sdk'
189
190
*
190
- * const stack = contentstack.Stack ({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
191
+ * const stack = contentstack.stack ({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
191
192
* const result = await stack.asset().find();
192
193
* @example
193
194
* import contentstack from '@contentstack/delivery-sdk'
194
195
*
195
- * const stack = contentstack.Stack ({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
196
+ * const stack = contentstack.stack ({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
196
197
* const result = await stack.contentType("contentType1Uid").entry().query().find();
197
198
* @example
198
199
* import contentstack from '@contentstack/delivery-sdk'
199
200
*
200
- * const stack = contentstack.Stack ({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
201
+ * const stack = contentstack.stack ({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
201
202
* const result = await stack.asset(asset_uid).fetch();
202
203
*/
203
204
204
205
async find < T > ( ) : Promise < FindResponse < T > > {
205
206
let requestParams : { [ key : string ] : any } = this . _queryParams ;
206
- if ( Object . keys ( this . _parameters ) ) requestParams = { ...this . _queryParams , query : { ...this . _parameters } } ;
207
207
208
- const response = await getData ( this . _client , this . _urlPath , requestParams ) ;
208
+ if ( Object . keys ( this . _parameters ) . length > 0 ) {
209
+ requestParams = { ...this . _queryParams , query : { ...this . _parameters } } ;
210
+ }
211
+
212
+ const getRequestOptions : any = { params : requestParams } ;
213
+
214
+ if ( this . _variants ) {
215
+ getRequestOptions . headers = {
216
+ ...getRequestOptions . headers ,
217
+ 'x-cs-variant-uid' : this . _variants
218
+ } ;
219
+ }
220
+
221
+ const response = await getData ( this . _client , this . _urlPath , getRequestOptions ) ;
209
222
210
223
return response as FindResponse < T > ;
211
224
}
0 commit comments