Skip to content

Commit 133c43e

Browse files
Added SyncApi feature
1 parent e40d6a2 commit 133c43e

File tree

7 files changed

+67
-51
lines changed

7 files changed

+67
-51
lines changed

config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const config = {
22
protocol: "https",
3-
host: "dev-cdn.contentstack.io",
3+
host: "stag-cdn.contentstack.io",
44
port: 443,
55
version: "v3",
66
urls: {

dist/native-script/contentstack.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,14 @@ function sendRequest(queryObject) {
387387
}
388388
});
389389
return resolve(spreadResult(entries));
390-
} else {
391-
if (syncstack) {
392-
return resolve(syncstack);
393-
}
390+
}
394391

395-
if (!tojson) entries = resultWrapper(entries);
396-
return resolve(spreadResult(entries));
392+
if (Object.keys(syncstack).length) {
393+
return resolve(syncstack);
397394
}
395+
396+
if (!tojson) entries = resultWrapper(entries);
397+
return resolve(spreadResult(entries));
398398
} catch (e) {
399399
return reject({
400400
message: e.message
@@ -567,12 +567,12 @@ var Stack = function () {
567567
this.config = _config2.default;
568568
this.cachePolicy = _index2.default.policies.IGNORE_CACHE;
569569
this.provider = _index2.default.providers('localstorage');
570+
//this.sync_cdn_api_key = stack_arguments[0].sync_cdn_api_key;
570571

571572
for (var _len = arguments.length, stack_arguments = Array(_len), _key = 0; _key < _len; _key++) {
572573
stack_arguments[_key] = arguments[_key];
573574
}
574575

575-
this.web_ui_api_key = stack_arguments[0].web_ui_api_key;
576576
switch (stack_arguments.length) {
577577
case 1:
578578
if (_typeof(stack_arguments[0]) === "object" && typeof stack_arguments[0].api_key === "string" && typeof stack_arguments[0].access_token === "string" && typeof stack_arguments[0].environment === "string") {
@@ -854,19 +854,28 @@ var Stack = function () {
854854

855855
/**
856856
* @method sync
857-
* @description sync get all the sync data.
858-
* @example Stack.sync({'init': 'true'})
857+
* @description The Sync API takes care of syncing your Contentstack data with your app and ensures that the data is always up-to-date by providing delta updates. Contentstack’s iOS SDK supports Sync API, which you can use to build powerful apps. Read through to understand how to use the Sync API with Contentstack JavaScript SDK.
858+
* @param {object} params - params is an object which Supports locale, start_date, content_type_id queries.
859+
* @example
860+
* Stack.sync({'init': true}) // For initializing sync
861+
* @example
862+
* Stack.sync({'init': true, 'locale': 'en-us'}) //For initializing sync with entries of a specific locale
863+
* @example
864+
* Stack.sync({'init': 'true', 'start_date': '2018-10-22'}) //For initializing sync with entries published after a specific date
865+
* @example
866+
* Stack.sync({'init': 'true', 'content_type_id': 'session'}) //For initializing sync with entries of a specific content type
867+
* @example
868+
* Stack.sync({'pagination_token': '<btlsomething>'}) // For fetching the next batch of entries using pagination token
869+
* @example
870+
* Stack.sync({'sync_token': '<btlsomething>'}) // For performing subsequent sync after initial sync
859871
* @returns {object}
860-
* @ignore
861872
*/
862873

863874
}, {
864875
key: 'sync',
865876
value: function sync(params) {
866877
this._query = {};
867-
this["params"] = params;
868-
this._query['web_ui_api_key'] = this.web_ui_api_key;
869-
this._query = Object.assign(this._query, this.params);
878+
this._query = Object.assign(this._query, params);
870879
this.requestParams = {
871880
method: 'POST',
872881
headers: this.headers,
@@ -983,7 +992,6 @@ function Request(options) {
983992
method: 'GET',
984993
headers: headers
985994
}).then(function (response) {
986-
987995
if (response.ok && response.status === 200) {
988996
var data = response.json();
989997
resolve(data);
@@ -1962,7 +1970,7 @@ Object.defineProperty(exports, "__esModule", {
19621970
});
19631971
var config = {
19641972
protocol: "https",
1965-
host: "dev-new-api.contentstack.io",
1973+
host: "stag-cdn.contentstack.io",
19661974
port: 443,
19671975
version: "v3",
19681976
urls: {

dist/react-native/contentstack.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,14 @@ function sendRequest(queryObject) {
387387
}
388388
});
389389
return resolve(spreadResult(entries));
390-
} else {
391-
if (syncstack) {
392-
return resolve(syncstack);
393-
}
390+
}
394391

395-
if (!tojson) entries = resultWrapper(entries);
396-
return resolve(spreadResult(entries));
392+
if (Object.keys(syncstack).length) {
393+
return resolve(syncstack);
397394
}
395+
396+
if (!tojson) entries = resultWrapper(entries);
397+
return resolve(spreadResult(entries));
398398
} catch (e) {
399399
return reject({
400400
message: e.message
@@ -567,12 +567,12 @@ var Stack = function () {
567567
this.config = _config2.default;
568568
this.cachePolicy = _index2.default.policies.IGNORE_CACHE;
569569
this.provider = _index2.default.providers('localstorage');
570+
//this.sync_cdn_api_key = stack_arguments[0].sync_cdn_api_key;
570571

571572
for (var _len = arguments.length, stack_arguments = Array(_len), _key = 0; _key < _len; _key++) {
572573
stack_arguments[_key] = arguments[_key];
573574
}
574575

575-
this.web_ui_api_key = stack_arguments[0].web_ui_api_key;
576576
switch (stack_arguments.length) {
577577
case 1:
578578
if (_typeof(stack_arguments[0]) === "object" && typeof stack_arguments[0].api_key === "string" && typeof stack_arguments[0].access_token === "string" && typeof stack_arguments[0].environment === "string") {
@@ -854,19 +854,28 @@ var Stack = function () {
854854

855855
/**
856856
* @method sync
857-
* @description sync get all the sync data.
858-
* @example Stack.sync({'init': 'true'})
857+
* @description The Sync API takes care of syncing your Contentstack data with your app and ensures that the data is always up-to-date by providing delta updates. Contentstack’s iOS SDK supports Sync API, which you can use to build powerful apps. Read through to understand how to use the Sync API with Contentstack JavaScript SDK.
858+
* @param {object} params - params is an object which Supports locale, start_date, content_type_id queries.
859+
* @example
860+
* Stack.sync({'init': true}) // For initializing sync
861+
* @example
862+
* Stack.sync({'init': true, 'locale': 'en-us'}) //For initializing sync with entries of a specific locale
863+
* @example
864+
* Stack.sync({'init': 'true', 'start_date': '2018-10-22'}) //For initializing sync with entries published after a specific date
865+
* @example
866+
* Stack.sync({'init': 'true', 'content_type_id': 'session'}) //For initializing sync with entries of a specific content type
867+
* @example
868+
* Stack.sync({'pagination_token': '<btlsomething>'}) // For fetching the next batch of entries using pagination token
869+
* @example
870+
* Stack.sync({'sync_token': '<btlsomething>'}) // For performing subsequent sync after initial sync
859871
* @returns {object}
860-
* @ignore
861872
*/
862873

863874
}, {
864875
key: 'sync',
865876
value: function sync(params) {
866877
this._query = {};
867-
this["params"] = params;
868-
this._query['web_ui_api_key'] = this.web_ui_api_key;
869-
this._query = Object.assign(this._query, this.params);
878+
this._query = Object.assign(this._query, params);
870879
this.requestParams = {
871880
method: 'POST',
872881
headers: this.headers,
@@ -983,7 +992,6 @@ function Request(options) {
983992
method: 'GET',
984993
headers: headers
985994
}).then(function (response) {
986-
987995
if (response.ok && response.status === 200) {
988996
var data = response.json();
989997
resolve(data);
@@ -1962,7 +1970,7 @@ Object.defineProperty(exports, "__esModule", {
19621970
});
19631971
var config = {
19641972
protocol: "https",
1965-
host: "dev-new-api.contentstack.io",
1973+
host: "stag-cdn.contentstack.io",
19661974
port: 443,
19671975
version: "v3",
19681976
urls: {

dist/web/contentstack.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js-sdk-reference.zip

685 Bytes
Binary file not shown.

src/core/lib/request.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,14 @@ export default function Request(options) {
4242
queryParams = serialize(options.body);
4343
}
4444

45-
4645
fetch(url + '?' + queryParams, {
4746
method: 'GET',
4847
headers: headers
4948
})
5049
.then(function(response) {
51-
5250
if (response.ok && response.status === 200) {
5351
let data = response.json();
54-
resolve(data);
52+
resolve(data);
5553
} else {
5654
reject(response.statusText);
5755
}

src/core/lib/utils.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,15 @@ export function sendRequest(queryObject) {
264264
}
265265
return;
266266
}
267-
} else if(data.items) {
268-
syncstack = {
269-
items : data.items,
270-
pagination_token : data.pagination_token,
271-
sync_token : data.sync_token,
272-
total_count : data.total_count
273-
}
274-
} else {
267+
}
268+
else if(data.items) {
269+
syncstack = {
270+
items : data.items,
271+
pagination_token : data.pagination_token,
272+
sync_token : data.sync_token,
273+
total_count : data.total_count
274+
}
275+
} else {
275276
entries = data;
276277
}
277278

@@ -286,15 +287,16 @@ export function sendRequest(queryObject) {
286287
}
287288
});
288289
return resolve(spreadResult(entries));
289-
} else {
290-
if(syncstack) {
291-
return resolve(syncstack);
292-
}
290+
}
291+
292+
if(Object.keys(syncstack).length) {
293+
return resolve(syncstack);
294+
}
293295

294-
if (!tojson)
295-
entries = resultWrapper(entries);
296+
if (!tojson)
297+
entries = resultWrapper(entries);
296298
return resolve(spreadResult(entries));
297-
}
299+
298300
} catch (e) {
299301
return reject({
300302
message: e.message

0 commit comments

Comments
 (0)