forked from contentstack/contentstack-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.js.html
610 lines (565 loc) · 27.9 KB
/
stack.js.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>stack.js - Documentation</title>
<link rel="shortcut icon" href="./favicon.ico">
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="canonical" href="https://www.contentstack.com/docs/developers/platforms/javascript/api-reference/">
<link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-WGP99J7');</script>
<!-- End Google Tag Manager -->
</head>
<body>
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-WGP99J7" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Contentstack.html">Contentstack</a><ul class='methods'><li data-type='method'><a href="Contentstack.html#Stack">Stack</a></li></ul></li><li><a href="Stack.html">Stack</a><ul class='methods'><li data-type='method'><a href="Stack.html#setPort">setPort</a></li><li data-type='method'><a href="Stack.html#setProtocol">setProtocol</a></li><li data-type='method'><a href="Stack.html#setHost">setHost</a></li><li data-type='method'><a href="Stack.html#setCachePolicy">setCachePolicy</a></li><li data-type='method'><a href="Stack.html#setCacheProvider">setCacheProvider</a></li><li data-type='method'><a href="Stack.html#clearByQuery">clearByQuery</a></li><li data-type='method'><a href="Stack.html#clearByContentType">clearByContentType</a></li><li data-type='method'><a href="Stack.html#clearAll">clearAll</a></li><li data-type='method'><a href="Stack.html#getCacheProvider">getCacheProvider</a></li><li data-type='method'><a href="Stack.html#ContentType">ContentType</a></li><li data-type='method'><a href="Stack.html#Assets">Assets</a></li><li data-type='method'><a href="Stack.html#Query">Query</a></li><li data-type='method'><a href="Stack.html#getLastActivites">getLastActivites</a></li><li data-type='method'><a href="Stack.html#getContentTypes">getContentTypes</a></li><li data-type='method'><a href="Stack.html#sync">sync</a></li><li data-type='method'><a href="Stack.html#imageTransform">imageTransform</a></li></ul></li><li><a href="Assets.html">Assets</a><ul class='methods'><li data-type='method'><a href="Assets.html#toJSON">toJSON</a></li><li data-type='method'><a href="Assets.html#addParam">addParam</a></li><li data-type='method'><a href="Assets.html#fetch">fetch</a></li></ul></li><li><a href="Entry.html">Entry</a><ul class='methods'><li data-type='method'><a href="Entry.html#includeFallback">includeFallback</a></li><li data-type='method'><a href="Entry.html#only">only</a></li><li data-type='method'><a href="Entry.html#except">except</a></li><li data-type='method'><a href="Entry.html#includeReference">includeReference</a></li><li data-type='method'><a href="Entry.html#language">language</a></li><li data-type='method'><a href="Entry.html#addQuery">addQuery</a></li><li data-type='method'><a href="Entry.html#includeSchema">includeSchema</a></li><li data-type='method'><a href="Entry.html#includeReferenceContentTypeUid">includeReferenceContentTypeUid</a></li><li data-type='method'><a href="Entry.html#includeFallback">includeFallback</a></li><li data-type='method'><a href="Entry.html#includeContentType">includeContentType</a></li><li data-type='method'><a href="Entry.html#includeOwner">includeOwner</a></li><li data-type='method'><a href="Entry.html#toJSON">toJSON</a></li><li data-type='method'><a href="Entry.html#addParam">addParam</a></li><li data-type='method'><a href="Entry.html#fetch">fetch</a></li></ul></li><li><a href="Query.html">Query</a><ul class='methods'><li data-type='method'><a href="Query.html#lessThan">lessThan</a></li><li data-type='method'><a href="Query.html#lessThanOrEqualTo">lessThanOrEqualTo</a></li><li data-type='method'><a href="Query.html#greaterThan">greaterThan</a></li><li data-type='method'><a href="Query.html#greaterThanOrEqualTo">greaterThanOrEqualTo</a></li><li data-type='method'><a href="Query.html#notEqualTo">notEqualTo</a></li><li data-type='method'><a href="Query.html#containedIn">containedIn</a></li><li data-type='method'><a href="Query.html#notContainedIn">notContainedIn</a></li><li data-type='method'><a href="Query.html#exists">exists</a></li><li data-type='method'><a href="Query.html#notExists">notExists</a></li><li data-type='method'><a href="Query.html#ascending">ascending</a></li><li data-type='method'><a href="Query.html#descending">descending</a></li><li data-type='method'><a href="Query.html#beforeUid">beforeUid</a></li><li data-type='method'><a href="Query.html#afterUid">afterUid</a></li><li data-type='method'><a href="Query.html#skip">skip</a></li><li data-type='method'><a href="Query.html#limit">limit</a></li><li data-type='method'><a href="Query.html#or">or</a></li><li data-type='method'><a href="Query.html#and">and</a></li><li data-type='method'><a href="Query.html#where">where</a></li><li data-type='method'><a href="Query.html#count">count</a></li><li data-type='method'><a href="Query.html#query">query</a></li><li data-type='method'><a href="Query.html#referenceIn">referenceIn</a></li><li data-type='method'><a href="Query.html#referenceNotIn">referenceNotIn</a></li><li data-type='method'><a href="Query.html#tags">tags</a></li><li data-type='method'><a href="Query.html#includeReferenceContentTypeUid">includeReferenceContentTypeUid</a></li><li data-type='method'><a href="Query.html#includeCount">includeCount</a></li><li data-type='method'><a href="Query.html#addParam">addParam</a></li><li data-type='method'><a href="Query.html#getQuery">getQuery</a></li><li data-type='method'><a href="Query.html#regex">regex</a></li><li data-type='method'><a href="Query.html#search">search</a></li><li data-type='method'><a href="Query.html#find">find</a></li><li data-type='method'><a href="Query.html#findOne">findOne</a></li></ul></li><li><a href="Result.html">Result</a><ul class='methods'><li data-type='method'><a href="Result.html#toJSON">toJSON</a></li><li data-type='method'><a href="Result.html#get">get</a></li><li data-type='method'><a href="Result.html#getDownloadUrl">getDownloadUrl</a></li></ul></li></ul>
</nav>
<div id="main">
<h1 class="page-title">stack.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>import config from '../../config';
import * as Utils from './lib/utils';
import Entry from './modules/entry';
import Assets from './modules/assets';
import Query from './modules/query';
import Request from './lib/request';
import * as cache from './cache';
import CacheProvider from './cache-provider/index';
let errorRetry = [408, 429]
/**
* @class
Stack
* @description Initialize an instance of ‘Stack’
* @param api_key - Stack API Key.
* @param delivery_token - Stack Delivery token.
* @param environment - Stack Environment name.
* @param region - DB region for Stack.
* @param fetchOptions - Custom setting for the request.
* @param fetchOptions.timeout - Set timeout for the request.
* @param fetchOptions.retryLimit - The number of retries before failure. Default is 5
* @param fetchOptions.retryDelay - The number of ms to use for operation retries. Default is 300ms
* @param fetchOptions.retryCondition - A function to determine if the error can be retried. Default retry is on status codes 408, 429, and greter than equal to 500.
* @param fetchOptions.retryDelayOptions.base - The base number of milliseconds to use in the exponential backoff for operation retries.
* @param fetchOptions.retryDelayOptions.customBackoff - A custom function that accepts a retry count and error and returns the amount of time to delay in milliseconds.
* @example
* var Stack = Contentstack.Stack({
* 'api_key':'api_key',
* 'delivery_token':'delivery_token',
* 'environment':'environment_name',
* 'region': 'us',
* 'fetchOptions': {
*
* }
* });
*
* @example
* var Stack = Contentstack.Stack('api_key', 'access_token', 'environment', {
*
* });
*
* @example
* // For Setting the European Region:
* // If you want to set and use European region, refer to the code below:
* const Stack = Contentstack.Stack("api_key", "delivery_token", "environment_name", Contentstack.Region.EU);
*
* @returns {Stack}
* @instance
*/
export default class Stack {
constructor(...stack_arguments) {
this.fetchOptions = {
retryLimit: 5,
retryCondition: (error) => {
if (errorRetry.includes(error.status)) {
return true;
}
return false
}
};
this.config = Object.assign({}, config)
if(stack_arguments[0].region && stack_arguments[0].region !== undefined && stack_arguments[0].region !== "us") {
this.config['host'] = stack_arguments[0].region+"-"+"cdn.contentstack.com";
}
if (stack_arguments[0].fetchOptions && stack_arguments[0].fetchOptions !== undefined) {
this.fetchOptions = Object.assign(this.fetchOptions, stack_arguments[0].fetchOptions);
}
this.cachePolicy = CacheProvider.policies.IGNORE_CACHE;
this.provider = CacheProvider.providers('localstorage');
switch (stack_arguments.length) {
case 1:
if (typeof stack_arguments[0] === "object" && typeof stack_arguments[0].api_key === "string" && typeof stack_arguments[0].delivery_token === "string" && typeof stack_arguments[0].environment === "string") {
this.headers = {
api_key: stack_arguments[0].api_key,
access_token: stack_arguments[0].delivery_token
};
this.environment = stack_arguments[0].environment;
return this;
} else {
console.error("Kindly provide valid object parameters. The specified API Key, Delivery Token, or Environment Name is invalid.");
}
case 3:
if (typeof stack_arguments[0] === "string" && typeof stack_arguments[1] === "string" && typeof stack_arguments[2] === "string") {
this.headers = {
api_key: stack_arguments[0],
access_token: stack_arguments[1]
};
this.environment = stack_arguments[2];
return this;
} else {
console.error("Kindly provide valid string parameters.");
}
case 4:
if (typeof stack_arguments[0] === "string" && typeof stack_arguments[1] === "string" && typeof stack_arguments[2] === "string") {
this.headers = {
api_key: stack_arguments[0],
access_token: stack_arguments[1]
};
this.environment = stack_arguments[2];
} else {
console.error("Kindly provide valid string parameters.");
}
if (stack_arguments[3]) {
if(typeof stack_arguments[3] === "string" && stack_arguments[3] !== undefined && stack_arguments[3] !== "us") {
this.config['host'] = stack_arguments[3]+"-"+"cdn.contentstack.com";
} else if (typeof stack_arguments[3] === 'object') {
this.fetchOptions = Object.assign(this.fetchOptions, stack_arguments[3]);
}
}
return this;
case 5:
if (typeof stack_arguments[0] === "string" && typeof stack_arguments[1] === "string" && typeof stack_arguments[2] === "string") {
this.headers = {
api_key: stack_arguments[0],
access_token: stack_arguments[1]
};
this.environment = stack_arguments[2];
} else {
console.error("Kindly provide valid string parameters.");
}
if (stack_arguments[3]) {
if(typeof stack_arguments[3] === "string" && stack_arguments[3] !== undefined && stack_arguments[3] !== "us") {
this.config['host'] = stack_arguments[3]+"-"+"cdn.contentstack.com";
} else if (typeof stack_arguments[3] === 'object') {
this.fetchOptions = Object.assign(this.fetchOptions, stack_arguments[3]);
}
}
if (stack_arguments[4] && typeof stack_arguments[4] === 'object') {
this.fetchOptions = Object.assign(this.fetchOptions, stack_arguments[4]);
}
return this;
default:
console.error("Kindly provide valid parameters to initialize the Contentstack javascript-SDK Stack.");
}
}
/**
* @method setPort
* @memberOf Stack
* @description Sets the port of the host
* @param {Number} port - Port Number
* @return {Stack}
* @instance
* */
setPort(port) {
if (typeof port === "number") this.config.port = port;
return this;
}
/**
* @method setProtocol
* @memberOf Stack
* @description Sets the protocol for the host
* @param {String} protocol - http/https protocol
* @return {Stack}
* @instance
* */
setProtocol(protocol) {
if (typeof protocol === "string" && ~["https", "http"].indexOf(protocol)) this.config.protocol = protocol;
return this;
}
/**
* @method setHost
* @memberOf Stack
* @description Sets the host of the API server
* @param {String} host - valid ip or host
* @return {Stack}
* @instance
* */
setHost(host) {
if (typeof host === "string" && host) this.config.host = host;
return this;
}
/**
* @method setCachePolicy
* @memberOf Stack
* @description Allows you to set cache policies
* @param {Constant} [key=ONLY_NETWORK] - Cache policy to be applied on Stack or Query.
* @example
* Stack.setCachePolicy(Contentstack.CachePolicy.IGNORE_CACHE)
* Stack.setCachePolicy(Contentstack.CachePolicy.ONLY_NETWORK)
* Stack.setCachePolicy(Contentstack.CachePolicy.CACHE_ELSE_NETWORK)
* Stack.setCachePolicy(Contentstack.CachePolicy.NETWORK_ELSE_CACHE)
* Stack.setCachePolicy(Contentstack.CachePolicy.CACHE_THEN_NETWORK)
* @returns {Stack}
* @instance
*/
setCachePolicy(policy) {
if (typeof policy === 'number' && policy >= -1 && policy < 4) {
if (!this._query) {
this.cachePolicy = policy;
} else {
this.queryCachePolicy = policy;
}
} else {
console.error("Kindly provide the valid policy");
}
return this;
}
/**
* @method setCacheProvider
* @memberOf Stack
* @description Allows you to set an object of the cache provider
* @example
* Stack
* .setCacheProvider({
* get: function (key, callback) {
* // custom logic
* },
* set: function (key, value, callback) {
* // custom logic
* }
* });
* @returns {Stack}
* @instance
*/
setCacheProvider(provider) {
if (provider && typeof provider === 'object') {
this.provider = provider;
}
return this;
}
/**
* @method clearByQuery
* @memberOf Stack
* @description 'clearByQuery' function to clear the query from the cache.
* @example
* Stack.clearQuery(query, callback);
* @returns {Stack}
* @instance
*/
clearByQuery() {
if (this.provider && typeof this.provider.clearByQuery === 'function') {
return this.provider.clearByQuery.apply(this.provider, arguments);
}
}
/**
* @method clearByContentType
* @memberOf Stack
* @description 'clearByContentType' function to clear the query from the cache by specified content type.
* @example
* Stack.clearByContentType(content_type_uid, callback);
* Stack.clearByContentType(content_type_uid, language_uid, callback);
* @returns {Stack}
* @instance
*/
clearByContentType() {
if (this.provider && typeof this.provider.clearByContentType === 'function') {
return this.provider.clearByContentType.apply(this.provider, arguments);
}
}
/**
* @method clearAll
* @memberOf Stack
* @description 'clearAll' function to clear all the queries from cache.
* @example
* Stack.clearAll(callback);
* @returns {Stack}
* @instance
*/
clearAll() {
if (this.provider && typeof this.provider.clearAll === 'function') {
return this.provider.clearAll.apply(this.provider, arguments);
}
}
/**
* @method getCacheProvider
* @memberOf Stack
* @description Returns the currently set object of 'CacheProvider'
* @example Stack.getCacheProvider();
* @returns {object}
* @instance
*/
getCacheProvider() {
return this.provider;
}
/**
* @method ContentType
* @memberOf Stack
* @description Set the content type of which you want to retrieve the entries
* @param {String} [content_type_uid] - uid of the existing content type
* @example
* let data = Stack.ContentType('blog').Query().toJSON().find()
* data
* .then(function(result) {
* // 'result' content the list of entries of particular content type blog.
* }, function(error) {
* // error function
* })
* @returns {Stack}
* @instance
*/
ContentType(uid) {
if (uid && typeof uid === 'string') {
this.content_type_uid = uid;
this.type = "contentType";
}
return this;
}
/**
* @method Entry
* @memberOf ContentType
* @param {String} uid - uid of the entry
* @description An initializer is responsible for creating Entry object
* @returns {Entry}
* @instance
*/
Entry(uid) {
let entry = new Entry();
if (uid && typeof uid === "string") {
entry.entry_uid = uid;
}
return Utils.merge(entry, this);
}
/**
* @method fetch
* @memberOf ContentType
* @description This method returns the complete information of a specific content type.
* @example
* let single_contenttype = Stack.ContentType(content_type_uid).fetch()
* single_contenttype
* .then(function(result) {
* // 'result' is a single contentType information.
* }).catch((error) => {
* console.log(error)
* });
* @returns {promise}
* @instance
*/
fetch(fetchOptions) {
let result = {
method: 'POST',
headers: this.headers,
url: this.config.protocol + "://" + this.config.host + ':' + this.config.port + '/' + this.config.version + this.config.urls.content_types + this.content_type_uid,
body: {
_method: 'GET',
environment: this.environment
}
};
var options = Object.assign({}, this.fetchOptions, fetchOptions);
return Request(result, options);
}
/**
* @method Assets
* @memberOf Stack
* @param {String} uid - uid of the asset
* @description Retrieves all assets of a stack by default. To retrieve a single asset, specify its UID.
* @example
* // Retrieves all assets
* let data = Stack.Assets().Query().toJSON().find()
* data
* .then(function(result) {
* // All the asset with limit of 100
* // Use skip and limit functions to paginate
* // ‘result’ will display all assets present in stack
* }, function(error) {
* // error function
* })
*
* @example
* let data = Stack.Assets('bltsomething123').toJSON().fetch()
* data
* .then(function(result) {
* // ‘result’ is a single asset object of specified uid
* }, function(error) {
* // error function
* })
*
* @returns {Assets}
* @instance
*/
Assets(uid) {
this.type = 'asset';
if (uid && typeof uid === "string") {
let asset = new Assets();
asset.asset_uid = uid;
return Utils.merge(asset, this);
}
return this;
}
/**
* @method Query
* @memberOf Stack
* @description An initializer is responsible for creating Query object.Provides support for all search queries
* @returns {Query}
* @instance
*/
Query() {
let query = new Query();
return Utils.merge(query, this);
}
/**
* @method getLastActivites
* @memberOf Stack
* @description getLastActivites get all the ContentTypes whose last activity updated.
* @example Stack.getLastActivites()
* @example
* let data = Stack.getLastActivites().toJSON().fetch()
* data
* .then(function(result) {
* // 'result' is list of contentTypes whose last activity updated.
* }, function(error) {
* // error function
* })
* @returns {promise}
* @instance
*/
getLastActivities() {
let query = {
method: 'POST',
headers: this.headers,
url: this.config.protocol + "://" + this.config.host + ':' + this.config.port + '/' + this.config.version + this.config.urls.content_types,
body: {
_method: 'GET',
only_last_activity: true,
environment: this.environment
}
};
return Request(query, this.fetchOptions);
}
/**
* @method getContentTypes
* @memberOf Stack
* @param {String} param - Query on contentTypes
* @description This method returns comprehensive information of all the content types of a particular stack in your account.
* @example
* let data = Stack.getContentTypes({"include_global_field_schema": true})
* data
* .then(function(result) {
* // 'result' is list of contentTypes.
* }, function(error) {
* // error function
* })
* @returns {promise}
* @instance
*/
getContentTypes(param = {}) {
let query = {
method: 'POST',
headers: this.headers,
url: this.config.protocol + "://" + this.config.host + ':' + this.config.port + '/' + this.config.version + this.config.urls.content_types,
body: {
_method: 'GET',
environment: this.environment
}
};
if(param && param !== undefined) {
for( var key in param) {
query.body[key] = param[key]
}
}
return Request(query, this.fetchOptions);
}
/**
* @method sync
* @memberOf Stack
* @description Syncs your Contentstack data with your app and ensures that the data is always up-to-date by providing delta updates
* @param {object} params - params is an object that supports ‘locale’, ‘start_date’, ‘content_type_uid’, and ‘type’ queries.
* @example
* Stack.sync({'init': true}) // For initializing sync
* @example
* Stack.sync({'init': true, 'locale': 'en-us'}) //For initializing sync with entries of a specific locale
* @example
* Stack.sync({'init': true, 'start_date': '2018-10-22'}) //For initializing sync with entries published after a specific date
* @example
* Stack.sync({'init': true, 'content_type_uid': 'session'}) //For initializing sync with entries of a specific content type
* @example
* Stack.sync({'init': true, 'type': 'entry_published'}) //Use the type parameter to get a specific type of content.Supports 'asset_published', 'entry_published', 'asset_unpublished', 'entry_unpublished', 'asset_deleted', 'entry_deleted', 'content_type_deleted'.
* @example
* Stack.sync({'pagination_token': '<btlsomething>'}) // For fetching the next batch of entries using pagination token
* @example
* Stack.sync({'sync_token': '<btlsomething>'}) // For performing subsequent sync after initial sync
* @returns {promise}
* @instance
*/
sync(params, fetchOptions) {
this._query = {};
this._query = Object.assign(this._query, params);
this.requestParams = {
method: 'POST',
headers: this.headers,
url: this.config.protocol + "://" + this.config.host + ':' + this.config.port + '/' + this.config.version + this.config.urls.sync,
body: {
_method: 'GET',
query: this._query
}
}
var options = Object.assign({}, this.fetchOptions, fetchOptions);
return Utils.sendRequest(this, options);
}
/**
* @method imageTransform
* @memberOf Stack
* @description Performs transformations on images of mentioned url based on transformation parameters
* @param {String} url - Image url on which transformations need to be applied.
* @param {String} params - Object with transformation parameters
* @example
* Stack.imageTransform(imageURL, {height: 100, width: 200, disable: "upscale"});
* @example
* Stack.imageTransform(imageURL, {crop: "150,100"});
* @example
* Stack.imageTransform(imageURL, {format: "png", crop: "150,100"});
* @returns {string} [Image url with transformation parameters.]
* @instance
*/
imageTransform(url, params) {
if (url && typeof url === "string" && typeof params === "object" && params.length === undefined) {
let queryParams = [];
for (const operation in params) {
queryParams.push(operation + '=' + params[operation]);
}
url += (url.indexOf("?") <= -1) ? "?" + queryParams.join('&') : "&" + queryParams.join('&');
}
return url;
}
}</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
<div class="inner-content center">
<span class="copy-right"><a href="mailto:support@contentstack.com" target="_self">support@contentstack.com</a> | © 2016-2020 Contentstack. All rights reserved.</span>
</div>
</footer>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
</body>
</html>