Skip to content

Commit fbefe9f

Browse files
authored
Merge pull request #48 from contentstack/embedded_objects
Embedded Items Feature support added
2 parents 180631c + ac79506 commit fbefe9f

File tree

9 files changed

+2005
-2285
lines changed

9 files changed

+2005
-2285
lines changed

.npmignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ examples/
1010
mocktest.json
1111
webpack
1212
typescript-html-report
13-
coverage
13+
webpack
14+
jest.config.js
15+
coverage

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11

2+
### Version: 3.13.0
3+
#### Date:
4+
5+
##### Update API:
6+
- [Query]: Added support for method includeEmbeddedItems
7+
- [Entry]: Added support for method includeEmbeddedItems
8+
29
### Version: 3.12.2
310
#### Date: Feb-19-2021
411

index.d.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
// Type definitions for contentstack 3.12.2
22
// Project: https://www.contentstack.com/
33
// Definitions by: Contentstack <https://github.com/contentstack>
4+
import { EntryEmbedable, Option, RenderOption } from '@contentstack/utils'
5+
6+
// Utils
7+
export class Utils {
8+
static render(option: {
9+
entry: EntryEmbedable| EntryEmbedable[],
10+
renderOption?: RenderOption,
11+
paths?: string[]
12+
}): void;
13+
static renderContent(content: (string | string[]), option: Option): (string| string[]);
14+
}
415

516
//Enum for Contentstack Region
617
export enum Region {
@@ -137,8 +148,8 @@ export class Entry {
137148
includeReference(...val: string[]): this;
138149
language(language_code: string): this;
139150
addQuery(key: string, value: string): this;
151+
includeEmbeddedItems(): this;
140152
includeFallback(): this;
141-
142153
/**
143154
* @deprecated since verion 3.3.0
144155
*/

package-lock.json

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

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "contentstack",
3-
"version": "3.12.2",
3+
"version": "3.13.0",
44
"description": "Contentstack Javascript SDK",
55
"homepage": "https://www.contentstack.com/",
66
"author": {
@@ -10,7 +10,7 @@
1010
"main": "dist/node/contentstack.js",
1111
"browser": "dist/web/contentstack.js",
1212
"types": "./index.d.ts",
13-
"_id": "contentstack@3.12.2",
13+
"_id": "contentstack@3.13.0",
1414
"scripts": {
1515
"test": "npm run test:e2e && npm run test:typescript",
1616
"test:e2e": "istanbul cover tape test/index.js | tap-html --out ./tap-html.html",
@@ -20,8 +20,9 @@
2020
"buildweb": "webpack -p --config webpack/webpack.web.js",
2121
"buildreactnative": "webpack --config webpack/webpack.react-native.js",
2222
"buildnativescript": "webpack --config webpack/webpack.nativescript.js",
23-
"buildall": "NODE_ENV=production&&npm run buildnode&npm run buildweb&npm run buildreactnative&npm run buildnativescript",
24-
"generate-docs": "node_modules/.bin/jsdoc --configure docs-config.json --verbose"
23+
"build": "NODE_ENV=production && npm run buildnode && npm run buildweb && npm run buildreactnative && npm run buildnativescript",
24+
"generate-docs": "node_modules/.bin/jsdoc --configure docs-config.json --verbose",
25+
"prepare": "npm run build"
2526
},
2627
"repository": {
2728
"type": "git",
@@ -51,14 +52,14 @@
5152
],
5253
"dist": {
5354
"shasum": "a328ed07240476a26b31a23261355dc929e1da63",
54-
"tarball": "https://registry.npmjs.org/contentstack/-/contentstack-3.12.2.tgz"
55+
"tarball": "https://registry.npmjs.org/contentstack/-/contentstack-3.13.0.tgz"
5556
},
5657
"license": "MIT",
5758
"directories": {},
58-
"_resolved": "https://registry.npmjs.org/contentstack/-/contentstack-3.12.2.tgz",
59+
"_resolved": "https://registry.npmjs.org/contentstack/-/contentstack-3.13.0.tgz",
5960
"_npmOperationalInternal": {
6061
"host": "packages-18-east.internal.npmjs.com",
61-
"tmp": "tmp/contentstack-3.12.2.tgz_1477830884275_0.9869455888401717"
62+
"tmp": "tmp/contentstack-3.13.0.tgz_1477830884275_0.9869455888401717"
6263
},
6364
"devDependencies": {
6465
"@types/jest": "^26.0.13",
@@ -95,6 +96,7 @@
9596
"webpack-merge": "4.1.0"
9697
},
9798
"dependencies": {
99+
"@contentstack/utils": "1.0.0",
98100
"es6-promise": "4.1.1",
99101
"localStorage": "1.0.3",
100102
"node-fetch": "^2.6.1"

src/core/contentstack.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Stack from "./stack";
22
import CacheProvider from './cache-provider/index';
33
import ContentstackRegion from "./contentstackregion";
4-
4+
import {render , renderContent} from '@contentstack/utils';
55

66
/**
77
* @class
@@ -25,6 +25,26 @@ class Contentstack {
2525
*/
2626
this.CachePolicy = CacheProvider.policies;
2727
this.Region = ContentstackRegion;
28+
29+
this.Utils = {
30+
/**
31+
* @memberof Contentstack
32+
* @description Renders embedded objects in Rich text from Entry or Multiple Entry Object.
33+
*
34+
* @param {EntryEmbedable| EntryEmbedable[]} entry - Objects that contains RTE with embedded objects
35+
* @param {string[]} keyPaths - Key paths for RTE contents in Entry object
36+
* @param {RenderOption?} renderOption - Optional render options to render content
37+
*/
38+
render,
39+
/**
40+
* @memberof Contentstack
41+
* @description Renders embedded objects in Rich text from String or String of array.
42+
* @param {string | string[]} content - RTE content to render
43+
* @param {EntryEmbedable} options.entry - Entry object containing embedded objects
44+
* @param {RenderOption?} options.renderOption - Optional render options to render content
45+
*/
46+
renderContent
47+
}
2848
}
2949
/**
3050

src/core/lib/utils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Request from './request';
22
import Result from '../modules/result';
3+
import config from '../../../config';
34
/**
45
* @method addSpread
56
* @description method to add the spread.
@@ -237,7 +238,9 @@ export function sendRequest(queryObject, options) {
237238
let tojson = (typeof self.tojson !== 'undefined') ? self.tojson : false;
238239
let isSingle = (self.entry_uid || self.singleEntry || self.asset_uid) ? true : false;
239240
let hashQuery = getHash(parseQueryFromParams(self, isSingle, tojson));
240-
241+
if (queryObject.requestParams.url.includes(config.urls.sync)) {
242+
cachePolicy = -1;
243+
}
241244
/**
242245
for new api v3
243246
*/

src/core/modules/entry.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,19 @@ export default class Entry {
184184
}
185185
}
186186

187+
/**
188+
* @method includeEmbeddedItems
189+
* @memberOf Entry
190+
* @description Include Embedded Objects (Entries and Assets) along with entry/entries details.
191+
* @example Stack.ContentType("contentType_uid").Entry("entry_uid").includeEmbeddedObjects().fetch()
192+
* @returns {Entry}
193+
* @instance
194+
*/
195+
includeEmbeddedItems() {
196+
this._query['include_embedded_items'] = ["BASE"];
197+
return this;
198+
}
199+
187200
/**
188201
* @method includeSchema
189202
* @memberOf Entry

src/core/stack.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Entry from './modules/entry';
44
import Assets from './modules/assets';
55
import Query from './modules/query';
66
import Request from './lib/request';
7-
import * as cache from './cache';
87
import CacheProvider from './cache-provider/index';
98
let errorRetry = [408, 429]
109

@@ -20,7 +19,7 @@ let errorRetry = [408, 429]
2019
* @param fetchOptions.timeout - Set timeout for the request.
2120
* @param fetchOptions.retryLimit - The number of retries before failure. Default is 5
2221
* @param fetchOptions.retryDelay - The number of ms to use for operation retries. Default is 300ms
23-
* @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.
22+
* @param fetchOptions.retryCondition - A function to determine if the error can be retried. Default retry is on status codes 408, 429.
2423
* @param fetchOptions.retryDelayOptions.base - The base number of milliseconds to use in the exponential backoff for operation retries.
2524
* @param fetchOptions.retryDelayOptions.customBackoff - A custom function that accepts a retry count and error and returns the amount of time to delay in milliseconds.
2625
* @example

0 commit comments

Comments
 (0)