Skip to content

Commit cd0d7c0

Browse files
committed
fix: 🐛 node fetch issue resolved
1 parent 5b84a4d commit cd0d7c0

10 files changed

Lines changed: 51 additions & 39 deletions

File tree

package-lock.json

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

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "contentstack",
3-
"version": "3.13.0",
3+
"version": "3.13.1",
44
"description": "Contentstack Javascript SDK",
55
"homepage": "https://www.contentstack.com/",
66
"author": {
@@ -22,7 +22,8 @@
2222
"buildnativescript": "webpack --config webpack/webpack.nativescript.js",
2323
"build": "NODE_ENV=production && npm run buildnode && npm run buildweb && npm run buildreactnative && npm run buildnativescript",
2424
"generate-docs": "node_modules/.bin/jsdoc --configure docs-config.json --verbose",
25-
"prepare": "npm run build"
25+
"prepare": "npm run build",
26+
"pretest": "npm run build"
2627
},
2728
"repository": {
2829
"type": "git",
@@ -99,7 +100,7 @@
99100
"dependencies": {
100101
"@contentstack/utils": "1.0.0",
101102
"es6-promise": "4.1.1",
102-
"localStorage": "1.0.3",
103-
"node-fetch": "^2.6.1"
103+
"isomorphic-fetch": "^3.0.0",
104+
"localStorage": "1.0.3"
104105
}
105106
}

src/core/lib/request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async function safeParseJSON(response) {
6161
const body = await response.text();
6262
}
6363
function fetchRetry(url, headers, retryDelay = 300, retryLimit = 5, fetchOptions, resolve, reject) {
64-
var option = Object.assign({
64+
var option = Utils.mergeDeep({
6565
method: 'GET',
6666
headers: headers,
6767
timeout: 30000,

src/core/lib/utils.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,7 @@ export function sendRequest(queryObject, options) {
238238
let tojson = (typeof self.tojson !== 'undefined') ? self.tojson : false;
239239
let isSingle = (self.entry_uid || self.singleEntry || self.asset_uid) ? true : false;
240240
let hashQuery = getHash(parseQueryFromParams(self, isSingle, tojson));
241-
if (queryObject.requestParams.url.includes(config.urls.sync)) {
242-
cachePolicy = -1;
243-
}
241+
244242
/**
245243
for new api v3
246244
*/

src/core/modules/assets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export default class Assets {
118118
query: this._query
119119
}
120120
}
121-
var options = Object.assign({}, this.fetchOptions, fetchOptions);
121+
var options = Utils.mergeDeep({}, this.fetchOptions, fetchOptions);
122122
return Utils.sendRequest(this, options);
123123
} else {
124124
console.error("Kindly provide an asset uid. e.g. .Assets('bltsomething123')");

src/core/modules/entry.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ export default class Entry {
341341
query: this._query
342342
}
343343
};
344-
var options = Object.assign({}, this.fetchOptions, fetchOptions);
344+
var options = Utils.mergeDeep({}, this.fetchOptions, fetchOptions);
345345
return Utils.sendRequest(this, options);
346346
} else {
347347
console.error("Kindly provide an entry uid. e.g. .Entry('bltsomething123')");

src/core/modules/query.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ export default class Query extends Entry {
757757
query: this._query
758758
}
759759
};
760-
var options = Object.assign({}, this.fetchOptions, fetchOptions);
760+
var options = Utils.mergeDeep({}, this.fetchOptions, fetchOptions);
761761
return Utils.sendRequest(this, options);
762762
}
763763

@@ -790,7 +790,7 @@ export default class Query extends Entry {
790790
query: this._query
791791
}
792792
};
793-
var options = Object.assign({}, this.fetchOptions);
793+
var options = Utils.mergeDeep({}, this.fetchOptions);
794794
return Utils.sendRequest(this, options);
795795
}
796796

src/core/stack.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ export default class Stack {
5757
return false
5858
}
5959
};
60-
this.config = Object.assign({}, config)
60+
this.config = Utils.mergeDeep({}, config)
6161

6262
if(stack_arguments[0].region && stack_arguments[0].region !== undefined && stack_arguments[0].region !== "us") {
6363
this.config['host'] = stack_arguments[0].region+"-"+"cdn.contentstack.com";
6464
}
6565

6666
if (stack_arguments[0].fetchOptions && stack_arguments[0].fetchOptions !== undefined) {
67-
this.fetchOptions = Object.assign(this.fetchOptions, stack_arguments[0].fetchOptions);
67+
this.fetchOptions = Utils.mergeDeep(this.fetchOptions, stack_arguments[0].fetchOptions);
6868
}
6969

7070
this.cachePolicy = CacheProvider.policies.IGNORE_CACHE;
@@ -107,7 +107,7 @@ export default class Stack {
107107
if(typeof stack_arguments[3] === "string" && stack_arguments[3] !== undefined && stack_arguments[3] !== "us") {
108108
this.config['host'] = stack_arguments[3]+"-"+"cdn.contentstack.com";
109109
} else if (typeof stack_arguments[3] === 'object') {
110-
this.fetchOptions = Object.assign(this.fetchOptions, stack_arguments[3]);
110+
this.fetchOptions = Utils.mergeDeep(this.fetchOptions, stack_arguments[3]);
111111
}
112112
}
113113
return this;
@@ -126,11 +126,11 @@ export default class Stack {
126126
if(typeof stack_arguments[3] === "string" && stack_arguments[3] !== undefined && stack_arguments[3] !== "us") {
127127
this.config['host'] = stack_arguments[3]+"-"+"cdn.contentstack.com";
128128
} else if (typeof stack_arguments[3] === 'object') {
129-
this.fetchOptions = Object.assign(this.fetchOptions, stack_arguments[3]);
129+
this.fetchOptions = Utils.mergeDeep(this.fetchOptions, stack_arguments[3]);
130130
}
131131
}
132132
if (stack_arguments[4] && typeof stack_arguments[4] === 'object') {
133-
this.fetchOptions = Object.assign(this.fetchOptions, stack_arguments[4]);
133+
this.fetchOptions = Utils.mergeDeep(this.fetchOptions, stack_arguments[4]);
134134
}
135135
return this;
136136
default:
@@ -353,7 +353,7 @@ export default class Stack {
353353
environment: this.environment
354354
}
355355
};
356-
var options = Object.assign({}, this.fetchOptions, fetchOptions);
356+
var options = Utils.mergeDeep({}, this.fetchOptions, fetchOptions);
357357
return Request(result, options);
358358
}
359359

@@ -497,7 +497,7 @@ export default class Stack {
497497

498498
sync(params, fetchOptions) {
499499
this._query = {};
500-
this._query = Object.assign(this._query, params);
500+
this._query = Utils.mergeDeep(this._query, params);
501501
this.requestParams = {
502502
method: 'POST',
503503
headers: this.headers,
@@ -507,7 +507,7 @@ export default class Stack {
507507
query: this._query
508508
}
509509
}
510-
var options = Object.assign({}, this.fetchOptions, fetchOptions);
510+
var options = Utils.mergeDeep({}, this.fetchOptions, fetchOptions);
511511
return Utils.sendRequest(this, options);
512512
}
513513

src/runtime/web/http.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import ES6Promise from 'es6-promise';
2-
import fetch from 'node-fetch';
3-
2+
import fetch from 'isomorphic-fetch';
43
ES6Promise.polyfill();
54

65
export default fetch;

src/runtime/web/localstorage.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
// export default window.localStorage;
1+
export default window.localStorage;
22

3-
let webLocalStoreage = function (){
4-
try {
5-
var storage = window.localStorage
6-
// x = '__storage_test__';
7-
// storage.setItem(x, x);
8-
// storage.removeItem(x);
9-
return storage;
10-
} catch(e) {
11-
return null
12-
}
13-
};
3+
// let webLocalStoreage = function (){
4+
// try {
5+
// var storage = window.localStorage
6+
// // x = '__storage_test__';
7+
// // storage.setItem(x, x);
8+
// // storage.removeItem(x);
9+
// return storage;
10+
// } catch(e) {
11+
// return null
12+
// }
13+
// };
1414

15-
export default webLocalStoreage();
15+
// export default webLocalStoreage();
1616

0 commit comments

Comments
 (0)