Skip to content

Commit fa63c28

Browse files
committed
fix: 🐛 cache issue
- Include Metadata function included in Entry, Asset and Query. - Typedefination for sync result updated
1 parent e1e57f9 commit fa63c28

File tree

8 files changed

+57
-35
lines changed

8 files changed

+57
-35
lines changed

index.d.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export class Utils {
2222
export enum Region {
2323
US = "us",
2424
EU = "eu",
25-
AZURE_NA = "azure-na"
25+
AZURE_NA = "azure-na",
26+
AZURE_EU = "azure-eu"
2627
}
2728

2829
//Enum for Contentstack CachePolicy
@@ -37,11 +38,11 @@ export enum CachePolicy {
3738
// Sync Result
3839
export interface SyncResult {
3940
items: Array<any>;
40-
paginationToken?: string;
41-
syncToken?: string;
41+
pagination_token?: string;
42+
sync_token?: string;
4243
skip: number;
4344
limit: number;
44-
totalCount: number;
45+
total_count: number;
4546
}
4647

4748
// Contentstack Config
@@ -209,6 +210,9 @@ export class Entry {
209210
includeSchema(): this;
210211
includeReferenceContentTypeUID(): this;
211212
includeContentType(): this;
213+
/**
214+
* @deprecated since version 3.3.0
215+
*/
212216
includeOwner(): this;
213217
toJSON(): this;
214218
addParam(key: string, value: any): this;

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "contentstack",
3-
"version": "3.16.1",
3+
"version": "3.17.0",
44
"description": "Contentstack Javascript SDK",
55
"homepage": "https://www.contentstack.com/",
66
"author": {

src/core/contentstackregion.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const ContentstackRegion = {
22
EU: "eu",
33
US: "us",
4-
AZURE_NA: "azure-na"
4+
AZURE_NA: "azure-na",
5+
AZURE_EU: "azure-eu"
56
};
67

78
export default ContentstackRegion;

src/core/lib/request.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,19 @@ function fetchRetry(stack, queryParams, fetchOptions, resolve, reject, retryDela
124124
})
125125

126126
} else {
127+
const {status, statusText} = response
127128
data.then((json) => {
129+
const {error_message, error_code, errors} = json
130+
const errorDetails = { error_message, error_code, errors, status, statusText }
128131
if (fetchOptions.retryCondition && fetchOptions.retryCondition(response)) {
129-
onError(json)
132+
onError(errorDetails)
130133
} else {
131-
if (fetchOptions.debug) fetchOptions.logHandler('error', json);
132-
reject(json)
134+
if (fetchOptions.debug) fetchOptions.logHandler('error', errorDetails);
135+
reject(errorDetails)
133136
}
134137
}).catch(() => {
135-
if (fetchOptions.debug) fetchOptions.logHandler('error', {status: response.status, statusText: response.statusText});
136-
reject({status: response.status, statusText: response.statusText})
138+
if (fetchOptions.debug) fetchOptions.logHandler('error', {status, statusText});
139+
reject({status, statusText})
137140
});
138141
}
139142
}).catch((error) => {

src/core/lib/utils.js

+10-20
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,6 @@ export function sendRequest(queryObject, options) {
347347
if (err || !_data) {
348348
callback(true, resolve, reject);
349349
} else {
350-
const originalData = JSON.parse(JSON.stringify(_data));
351350
try {
352351

353352
const doesQueryRequestForReferences =
@@ -388,25 +387,16 @@ export function sendRequest(queryObject, options) {
388387
}
389388
} catch (error) {
390389
}
391-
392-
await self.provider.set(
393-
hashQuery,
394-
originalData,
395-
function (err) {
396-
try {
397-
398-
if (err) reject(err);
399-
if (!tojson)
400-
_data =
401-
resultWrapper(_data);
402-
return resolve(
403-
spreadResult(_data)
404-
);
405-
} catch (e) {
406-
return reject(e);
407-
}
408-
}
409-
);
390+
try {
391+
if (!tojson)
392+
_data =
393+
resultWrapper(_data);
394+
return resolve(
395+
spreadResult(_data)
396+
);
397+
} catch (e) {
398+
return reject(e);
399+
}
410400
}
411401
} catch (e) {
412402
return reject(e);

src/core/modules/assets.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,28 @@ export default class Assets {
8181

8282
/**
8383
* @method includeFallback
84-
* @memberOf Entry
84+
* @memberOf Asset
8585
* @description Include the fallback locale publish content, if specified locale content is not publish.
86-
* @example stack.ContentType(contentType_uid).Entry(entry_uid).includeFallback().fetch()
86+
* @example stack.ContentType(contentType_uid).Assets(assetUid).includeFallback().fetch()
8787
* @returns {Asset}
8888
* @instance
8989
*/
9090
includeFallback() {
9191
this._query['include_fallback'] = true;
9292
return this;
9393
}
94-
94+
/**
95+
* @method includeMetadata
96+
* @memberOf Asset
97+
* @description Include the metadata for getting metadata content for the asset.
98+
* @example stack.ContentType(contentType_uid).Assets(assetUid).includeMetadata().fetch()
99+
* @returns {Asset}
100+
* @instance
101+
*/
102+
includeMetadata() {
103+
this._query['include_metadata'] = true;
104+
return this;
105+
}
95106
/**
96107
* Fetches a particular asset based on the provided asset UID.
97108
* @memberOf Assets

src/core/modules/entry.js

+13
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,19 @@ export default class Entry {
257257
this._query['include_branch'] = true;
258258
return this;
259259
}
260+
261+
/**
262+
* @method includeMetadata
263+
* @memberOf Entry
264+
* @description Include the metadata for getting metadata content for the entry.
265+
* @example stack.ContentType(contentType_uid).Entry(entry_uid).includeMetadata().fetch()
266+
* @returns {Entry}
267+
* @instance
268+
*/
269+
includeMetadata() {
270+
this._query['include_metadata'] = true;
271+
return this;
272+
}
260273

261274
/**
262275
* @method includeContentType

0 commit comments

Comments
 (0)