Skip to content

Commit 751c5bf

Browse files
authored
Merge pull request #48 from contentstack/embedded_objects
Embedded Items Feature support added
2 parents c096e07 + ed43fd8 commit 751c5bf

35 files changed

+3100
-2573
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

contentstack-templates/tmpl/layout.tmpl

Lines changed: 83 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -106,37 +106,41 @@
106106
<p>Once you have initialized the SDK, you can start getting content in your app.</p>
107107
<h4><a id="Querying_content_from_your_stack_90"></a>Querying content from your stack</h4>
108108
<p>To get a single entry, you need to specify the content type as well as the ID of the entry.</p>
109-
<pre class="prettyprint"><code>const Query = Stack.ContentType('blog').Entry("blt123something");
109+
<pre class="prettyprint"><code>const Stack = Contentstack.Stack("stack_api_key", "delivery_token", "environment_name");
110110

111-
Query.fetch()
112-
.then(function success(entry) {
113-
console.log(entry.get('title')); // Retrieve field value by providing a field's uid
114-
console.log(entry.toJSON()); // Convert the entry result object to JSON
115-
}, function error(err) {
116-
// err object
117-
});
111+
const Query = Stack.ContentType('blog').Entry("blt123something");
112+
113+
Query.fetch()
114+
.then(function success(entry) {
115+
console.log(entry.get('title')); // Retrieve field value by providing a field's uid
116+
console.log(entry.toJSON()); // Convert the entry result object to JSON
117+
}, function error(err) {
118+
// err object
119+
});
118120
</code></pre>
119121
<p class="note"><strong>Note</strong>: We have a method on query for a specific language. For example, consider the following query:
120122
<pre class="prettyprint"><code>Stack.ContentType(type).Query().language('fr-fr').toJSON().find()</code></pre>
121123
It will provide all entries of a content type published on the French locale.</p>
122124
<p>To retrieve multiple entries of a content type, you need to specify the content type uid. You can also specify search parameters to filter results.</p>
123-
<pre class="prettyprint"><code>const Query = Stack.ContentType('blog').Query();
124-
125-
Query
126-
.where("title", "welcome")
127-
.includeSchema()
128-
.includeCount()
129-
.toJSON()
130-
.find()
131-
.then(function success(result) {
132-
// result is array where -
133-
// result[0] =&amp;gt; entry objects
134-
// result[result.length-1] =&amp;gt; entry objects count included only when .includeCount() is queried.
135-
// result[1] =&amp;gt; schema of the content type is included when .includeSchema() is queried.
136-
}, function error(err) {
137-
// err object
138-
});
139-
</code></pre>
125+
<pre class="prettyprint"><code>const Stack = Contentstack.Stack("stack_api_key", "delivery_token", "environment_name");
126+
127+
const Query = Stack.ContentType('blog').Query();
128+
129+
Query
130+
.where("title", "welcome")
131+
.includeSchema()
132+
.includeCount()
133+
.toJSON()
134+
.find()
135+
.then(function success(result) {
136+
// result is array where -
137+
// result[0] =&amp;gt; entry objects
138+
// result[result.length-1] =&amp;gt; entry objects count included only when .includeCount() is queried.
139+
// result[1] =&amp;gt; schema of the content type is included when .includeSchema() is queried.
140+
}, function error(err) {
141+
// err object
142+
});
143+
</code></pre>
140144
<p class="note"><strong>Note:</strong> Currently, the JavaScript SDK does not support multiple content types referencing in a single query. For more information on how to query entries and assets, refer the <a href="/docs/developers/apis/content-delivery-api/#queries">Queries</a> section of our Content Delivery API documentation.</p>
141145

142146
<h4><a id="Paginating_Responses"></a>Paginating Responses</h4>
@@ -146,51 +150,55 @@ It will provide all entries of a content type published on the French locale.</p
146150
let blogQuery = Stack.ContentType('example').Query();
147151
let data = blogQuery.skip(20).limit(20).find()
148152
data.then(function(result) {
149-
// result is array where -
150-
// result[0] =&amp;gt; entry objects
151-
},function (error) {
152-
// error function
153-
})</code></pre>
153+
// result is array where -
154+
// result[0] =&amp;gt; entry objects
155+
},function (error) {
156+
// error function
157+
})</code></pre>
154158

155159
<h4><a id="Querying_content_from_your_stack_90"></a>Querying Assets from your stack</h4>
156160
<p>To get a single asset, you need to specify the UID of the asset.</p>
157-
<pre class="prettyprint"><code>const Asset = Stack.Asset("blt123something");
161+
<pre class="prettyprint"><code>const Stack = Contentstack.Stack("stack_api_key", "delivery_token", "environment_name");
162+
163+
const Asset = Stack.Asset("blt123something");
158164

159-
Asset.fetch()
160-
.then(function success(asset) {
161-
console.log(asset.get('title')); // Retrieve field value by providing a field's uid
162-
console.log(asset.toJSON()); // Convert the entry result object to JSON
163-
}, function error(err) {
164-
// err object
165-
});
165+
Asset.fetch()
166+
.then(function success(asset) {
167+
console.log(asset.get('title')); // Retrieve field value by providing a field's uid
168+
console.log(asset.toJSON()); // Convert the entry result object to JSON
169+
}, function error(err) {
170+
// err object
171+
});
166172
</code></pre>
167173
<p>To retrieve multiple assets. You can also specify search parameters to filter results.</p>
168-
<pre class="prettyprint"><code>const Query = Stack.Asset().Query();
174+
<pre class="prettyprint"><code>const Stack = Contentstack.Stack("stack_api_key", "delivery_token", "environment_name");
169175

170-
Query
171-
.limit(20)
172-
.toJSON()
173-
.find()
174-
.then(function success(result) {
175-
// result is array where -
176-
// result[0] =&amp;gt; asset objects
177-
}, function error(err) {
178-
// err object
179-
});
180-
</code></pre>
176+
const Query = Stack.Asset().Query();
177+
178+
Query
179+
.limit(20)
180+
.toJSON()
181+
.find()
182+
.then(function success(result) {
183+
// result is array where -
184+
// result[0] =&amp;gt; asset objects
185+
}, function error(err) {
186+
// err object
187+
});
188+
</code></pre>
181189

182190

183191
<h4><a id="Cache_Policies_123"></a>Cache Policies</h4>
184192
<p>You can set a cache policy on a stack and/or query object.</p>
185193
<h5><a id="Setting_a_cache_policy_on_a_stack_127"></a>Setting a cache policy on a stack</h5>
186194
<p>This option allows you to globalize a cache policy. This means the cache policy you set will be applied to all the query objects of the stack.</p>
187195
<pre class="prettyprint"><code>//Setting a cache policy on a stack
188-
Stack.setCachePolicy(Contentstack.CachePolicy.NETWORK_ELSE_CACHE)
196+
Stack.setCachePolicy(Contentstack.CachePolicy.NETWORK_ELSE_CACHE)
189197
</code></pre>
190198
<h5><a id="Setting_a_cache_policy_on_a_query_object_134"></a>Setting a cache policy on a query object</h5>
191199
<p>This option allows you to set/override a cache policy on a specific query object.</p>
192200
<pre class="prettyprint"><code>// setting a cache policy on a queryobject
193-
Query.setCachePolicy(Contentstack.CachePolicy.CACHE_THEN_NETWORK)
201+
Query.setCachePolicy(Contentstack.CachePolicy.CACHE_THEN_NETWORK)
194202
</code></pre>
195203
<h3><a id="Advanced_Queries_141"></a>Advanced Queries</h3>
196204
<p>You can query for content types, entries, assets and more using our JavaScript API Reference.</p>
@@ -199,15 +207,36 @@ data.then(function(result) {
199207
<p>We have introduced Image Delivery APIs that let you retrieve images and then manipulate and optimize them for your digital properties. It lets you perform a host of other actions such as crop, trim, resize, rotate, overlay, and so on.</p>
200208
<p>For example, if you want to crop an image (with width as 300 and height as 400), you simply need to append query parameters at the end of the image URL, such as, <a href=" https://images.contentstack.io/v3/assets/blteae40eb499811073/bltc5064f36b5855343/59e0c41ac0eddd140d5a8e3e/owl.jpg?crop=300,400"> https://images.contentstack.io/v3/assets/blteae40eb499811073/bltc5064f36b5855343/59e0c41ac0eddd140d5a8e3e/owl.jpg?crop=300,400</a>. There are several more parameters that you can use for your images.</p>
201209
<p><a href="https://www.contentstack.com/docs/apis/image-delivery-api/">Read Image Delivery API documentation</a>.</p>
202-
<p>SDK functions for Image Delivery API coming soon.</p>
210+
211+
<h5><a id="Following_are_Image_Delivery_API_examples_203"></a>Following are Image Delivery API examples</h5>
212+
<p>Following are Image Delivery API examples.</p>
213+
<pre class="prettyprint"><code>
214+
// Set the quality 100
215+
const Stack = Contentstack.Stack("stack_api_key", "delivery_token", "environment_name");
216+
217+
const imageUrl = Stack.imageTransform(imageUrl, {
218+
'quality': 100
219+
})
220+
</code></pre>
221+
<pre class="prettyprint"><code>
222+
// set the quality to 100, auto optimization, width and height
223+
const Stack = Contentstack.Stack("stack_api_key", "delivery_token", "environment_name");
224+
225+
const imageUrl = Stack.imageTransform(imageUrl, {
226+
'quality': 100,
227+
'auto': 'webp',
228+
'width': 100,
229+
'height': 100
230+
})
231+
</code></pre>
203232
<h3><a id="Helpful_Links_157"></a>Helpful Links</h3>
204233
<ul>
205234
<li><a href="https://www.contentstack.com">Contentstack Website</a></li>
206235
<li><a href="https://www.contentstack.com/docs">Official Documentation</a></li>
207236
<li><a href="https://www.contentstack.com/docs/apis/content-delivery-api/">Content Delivery API Docs</a></li>
208237
</ul>
209238
<h3><a id="The_MIT_License_MIT_163"></a>The MIT License (MIT)</h3>
210-
<p>Copyright © 2016-2020 <a href="https://www.contentstack.com">Contentstack</a>. All Rights Reserved</p>
239+
<p>Copyright © 2016-2021 <a href="https://www.contentstack.com">Contentstack</a>. All Rights Reserved</p>
211240
<p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:</p>
212241
<p>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</p>
213242
<p>THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>

0 commit comments

Comments
 (0)