Skip to content

Commit

Permalink
Merge pull request #93 from contentstack/fix/CS-36608-cache-issue
Browse files Browse the repository at this point in the history
fix: 🐛 cache issue
  • Loading branch information
uttamukkoji authored Mar 30, 2023
2 parents e1e57f9 + 90f66cf commit c0c965b
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 116 deletions.
12 changes: 8 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export class Utils {
export enum Region {
US = "us",
EU = "eu",
AZURE_NA = "azure-na"
AZURE_NA = "azure-na",
AZURE_EU = "azure-eu"
}

//Enum for Contentstack CachePolicy
Expand All @@ -37,11 +38,11 @@ export enum CachePolicy {
// Sync Result
export interface SyncResult {
items: Array<any>;
paginationToken?: string;
syncToken?: string;
pagination_token?: string;
sync_token?: string;
skip: number;
limit: number;
totalCount: number;
total_count: number;
}

// Contentstack Config
Expand Down Expand Up @@ -209,6 +210,9 @@ export class Entry {
includeSchema(): this;
includeReferenceContentTypeUID(): this;
includeContentType(): this;
/**
* @deprecated since version 3.3.0
*/
includeOwner(): this;
toJSON(): this;
addParam(key: string, value: any): this;
Expand Down
146 changes: 68 additions & 78 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "contentstack",
"version": "3.16.1",
"version": "3.17.0",
"description": "Contentstack Javascript SDK",
"homepage": "https://www.contentstack.com/",
"author": {
Expand Down Expand Up @@ -90,14 +90,14 @@
"request": "^2.88.2",
"string-replace-loader": "1.3.0",
"tap": "^16.3.4",
"tap-html": "^1.0.1",
"tap-html": "^1.1.0",
"tap-json": "1.0.0",
"tape": "4.8.0",
"terser-webpack-plugin": "^5.3.6",
"terser-webpack-plugin": "^5.3.7",
"ts-jest": "^27.1.5",
"typescript": "^4.9.5",
"uglify-js": "2.8.29",
"webpack": "^5.75.0",
"webpack": "^5.76.3",
"webpack-cli": "^4.10.0",
"webpack-md5-hash": "0.0.5",
"webpack-merge": "4.1.0",
Expand All @@ -108,6 +108,6 @@
"es6-promise": "^4.1.1",
"isomorphic-fetch": "^3.0.0",
"localStorage": "1.0.4",
"qs": "^6.11.0"
"qs": "^6.11.1"
}
}
3 changes: 2 additions & 1 deletion src/core/contentstackregion.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const ContentstackRegion = {
EU: "eu",
US: "us",
AZURE_NA: "azure-na"
AZURE_NA: "azure-na",
AZURE_EU: "azure-eu"
};

export default ContentstackRegion;
Expand Down
13 changes: 8 additions & 5 deletions src/core/lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,19 @@ function fetchRetry(stack, queryParams, fetchOptions, resolve, reject, retryDela
})

} else {
const {status, statusText} = response
data.then((json) => {
const {error_message, error_code, errors} = json
const errorDetails = { error_message, error_code, errors, status, statusText }
if (fetchOptions.retryCondition && fetchOptions.retryCondition(response)) {
onError(json)
onError(errorDetails)
} else {
if (fetchOptions.debug) fetchOptions.logHandler('error', json);
reject(json)
if (fetchOptions.debug) fetchOptions.logHandler('error', errorDetails);
reject(errorDetails)
}
}).catch(() => {
if (fetchOptions.debug) fetchOptions.logHandler('error', {status: response.status, statusText: response.statusText});
reject({status: response.status, statusText: response.statusText})
if (fetchOptions.debug) fetchOptions.logHandler('error', {status, statusText});
reject({status, statusText})
});
}
}).catch((error) => {
Expand Down
30 changes: 10 additions & 20 deletions src/core/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ export function sendRequest(queryObject, options) {
if (err || !_data) {
callback(true, resolve, reject);
} else {
const originalData = JSON.parse(JSON.stringify(_data));
try {

const doesQueryRequestForReferences =
Expand Down Expand Up @@ -388,25 +387,16 @@ export function sendRequest(queryObject, options) {
}
} catch (error) {
}

await self.provider.set(
hashQuery,
originalData,
function (err) {
try {

if (err) reject(err);
if (!tojson)
_data =
resultWrapper(_data);
return resolve(
spreadResult(_data)
);
} catch (e) {
return reject(e);
}
}
);
try {
if (!tojson)
_data =
resultWrapper(_data);
return resolve(
spreadResult(_data)
);
} catch (e) {
return reject(e);
}
}
} catch (e) {
return reject(e);
Expand Down
Loading

0 comments on commit c0c965b

Please sign in to comment.