Skip to content

Commit ab69228

Browse files
committed
Merge branch 'release/3.2.0'
2 parents f949047 + 285c426 commit ab69228

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+11404
-10430
lines changed

.DS_Store

6 KB
Binary file not shown.

09-06-2017.json

Lines changed: 0 additions & 1336 deletions
This file was deleted.

README.md

Lines changed: 172 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,172 @@
1-
[![Built.io Contentstack](https://contentstackdocs.built.io/static/images/logo.png)](https://www.built.io/products/contentstack/overview)
2-
# Javascript SDK for Built.io Contentstack
3-
## Prerequisite
4-
We recommend to use node.js version >=4.4.7 to use the Built.io Contentstack SDK.
5-
## Installation
6-
You might need administrator privileges to perform this installation.
7-
```bash
8-
$ npm install contentstack
9-
```
10-
To require the SDK module in your application use the following command.
11-
```bash
12-
$ import * as Contentstack from 'contentstack';
13-
```
14-
## Basic Structure
15-
The structure followed by SDK logically resembles the "Stack" structure on Built.io Contentstack. Once you have done the basic setup explained in the Installation section, you get a Built.io Contentstack object, which can be used to initialize different modules. The initialization process for each module is explained below.
16-
### Stack
17-
To initialize a Stack, you need to provide the required keys and values associated with them.
18-
```bash
19-
const Stack = Contentstack.Stack({"api_key":<<API_KEY>>,"access_token":<<ACCESS_TOKEN>>,"environment":<<ENVIRONMENT_NAME>>});
20-
```
21-
Let us take an example where we try to obtain all entries of the Content Type my_content_type.
22-
```bash
23-
const entry = Stack.ContentType(<<CONTENT_TYPE_UID>>).Query();
24-
entry
25-
//add query methods here
26-
.find()
27-
.then(function(data){
28-
//data will contain entries from the specified Content Type;
29-
},function(err){
30-
//displays a detailed error in case of failure;
31-
});
32-
```
33-
Let us take another example where we try to obtain only a specific entry from the Content Type my_content_type.
34-
```bash
35-
const entry = Stack.ContentType(<<CONTENT_TYPE_UID>>).Entry(<<ENTRY_UID>>);
36-
entry
37-
//add query methods here
38-
.fetch()
39-
.then(function(data){
40-
//data will contain the specified entry from the specified Content Type;
41-
},function(err){
42-
//displays a detailed error in case of failure;
43-
});
44-
```
45-
-----
46-
47-
## Links
48-
- [Website](https://www.built.io/products/contentstack/overview)
49-
- [Official Documentation](https://contentstackdocs.built.io/developer/javascript/quickstart)
50-
51-
### License
52-
Copyright © 2012-2017 [Built.io](https://www.built.io/). All Rights Reserved.
1+
[![Contentstack](https://www.contentstack.com/docs/static/images/contentstack.png)](https://www.contentstack.com/)
2+
## JavaScript SDK for Contentstack
3+
4+
Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest. [Read More](https://www.contentstack.com/).
5+
6+
Contentstack provides JavaScript SDK to build application on top of JavaScript. Given below is the detailed guide and helpful resources to get started with our JavaScript SDK.
7+
8+
The JavaScript SDK can also be used to create Node.js and React native applications.
9+
10+
### Prerequisite
11+
12+
You need Node.js version 4.4.7 or later installed to use the Contentstack JavaScript SDK.
13+
14+
### Setup and Installation
15+
16+
#### For JavaScript (Browser)
17+
18+
To use the JavaScript SDK, download it from [here](https://contentstack.com/docs/platforms/javascript-browser/javascript_sdk_latest) and include it in the &lt;script&gt; tag:
19+
20+
<script type="text/javascript" src="/path/to/contentstack.min.js"></script>;
21+
22+
To initialize the SDK, you will need to specify the API Key, Access Token, and Environment Name of your stack.
23+
24+
const Stack = Contentstack.Stack("api_key", "access_token", "environment_name");
25+
26+
#### For Node.js
27+
28+
Node.js uses the Javascript SDK to create apps. To use the JavaScript SDK, download it from [here](https://contentstack.com/docs/platforms/javascript-browser/javascript_sdk_latest), OR install it via npm:
29+
30+
npm -i contentstack
31+
32+
To import the SDK in your project, use the following command:
33+
34+
import contentstack from ‘contentstack’
35+
36+
To initialize the SDK, you will need to specify the API Key, Access Token, and Environment Name of your stack.
37+
38+
const Stack = Contentstack.Stack("api_key","access_token","environment_name");
39+
40+
#### For React Native
41+
42+
React Native uses the Javascript SDK to create apps. To use the JavaScript SDK, download it from [here](https://contentstack.com/docs/platforms/javascript-browser/javascript_sdk_latest), OR install ist via npm:
43+
44+
npm -i contentstack
45+
46+
To import the SDK in your project, use the following command:
47+
48+
import contentstack from `contentstack/react-native`
49+
50+
To initialize the SDK, you will need to specify the API Key, Access Token, and Environment Name of your stack.
51+
52+
const Stack = Contentstack.Stack("api_key", "access_token", "environment_name");
53+
54+
55+
### Key Concepts for using Contentstack
56+
57+
#### Stack
58+
59+
A stack is like a container that holds the content of your app. Learn more about [Stacks](https://www.contentstack.com/docs/guide/stack).
60+
61+
#### Content Type
62+
63+
Content type lets you define the structure or blueprint of a page or a section of your digital property. It is a form-like page that gives Content Managers an interface to input and upload content. [Read more](https://www.contentstack.com/docs/guide/content-types).
64+
65+
#### Entry
66+
67+
An entry is the actual piece of content created using one of the defined content types. Learn more about [Entries](https://www.contentstack.com/docs/guide/content-management#working-with-entries).
68+
69+
#### Asset
70+
71+
Assets refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded to Contentstack. These files can be used in multiple entries. Read more about [Assets](https://www.contentstack.com/docs/guide/content-management#working-with-assets).
72+
73+
#### Environment
74+
75+
A publishing environment corresponds to one or more deployment servers or a content delivery destination where the entries need to be published. Learn how to work with [Environments](https://www.contentstack.com/docs/guide/environments).
76+
77+
78+
79+
### Contentstack JavaScript SDK: 5-minute Quickstart
80+
81+
#### Initializing your SDK
82+
83+
You will need to specify the API key, Access token, and Environment Name of your stack to initialize the SDK:
84+
85+
const Stack = Contentstack.Stack("api_key", "access_token", "environment_name");
86+
87+
Once you have initialized the SDK, you can start getting content in your app.
88+
89+
90+
91+
#### Querying content from your stack
92+
93+
To get a single entry, you need to specify the content type as well as the ID of the entry.
94+
95+
const Query = Stack.ContentType('blog').Entry("blt123something");
96+
97+
Query.fetch()
98+
.then(function success(entry) {
99+
console.log(entry.get('title')); // Retrieve field value by providing a field's uid
100+
console.log(entry.toJSON()); // Convert the entry result object to JSON
101+
}, function error(err) {
102+
// err object
103+
});
104+
105+
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.
106+
107+
const Query = Stack.ContentType('blog').Query();
108+
109+
Query
110+
.where("title", "welcome")
111+
.includeSchema()
112+
.includeCount()
113+
.toJSON()
114+
.find()
115+
.then(function success(result) {
116+
// result is array where -
117+
// result[0] =&gt; entry objects
118+
// result[result.length-1] =&gt; entry objects count included only when .includeCount() is queried.
119+
// result[1] =&gt; schema of the content type is included when .includeSchema() is queried.
120+
}, function error(err) {
121+
// err object
122+
});
123+
124+
#### Cache Policies
125+
126+
You can set a cache policy on a stack and/or query object.
127+
128+
##### Setting a cache policy on a stack
129+
130+
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.
131+
132+
//Setting a cache policy on a stack
133+
Stack.setCachePolicy(Contentstack.CachePolicy.NETWORK_ELSE_CACHE)
134+
135+
##### Setting a cache policy on a query object
136+
137+
This option allows you to set/override a cache policy on a specific query object.
138+
139+
// setting a cache policy on a queryobject
140+
Query.setCachePolicy(Contentstack.CachePolicy.CACHE_THEN_NETWORK)
141+
142+
### Advanced Queries
143+
144+
You can query for content types, entries, assets and more using our JavaScript API Reference.
145+
146+
[JavaScript API Reference Doc](https://contentstack.com/docs/platforms/javascript-browser/api-reference)
147+
148+
### Working with Images
149+
150+
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.
151+
152+
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, https://images.contentstack.io/v3/assets/blteae40eb499811073/bltc5064f36b5855343/59e0c41ac0eddd140d5a8e3e/download?crop=300,400. There are several more parameters that you can use for your images.
153+
154+
[Read Image Delivery API documentation](https://www.contentstack.com/docs/apis/image-delivery-api/).
155+
156+
SDK functions for Image Delivery API coming soon.
157+
158+
### Helpful Links
159+
160+
- [Contentstack Website](https://www.contentstack.com)
161+
- [Official Documentation](https://contentstack.com/docs)
162+
- [Content Delivery API Docs](https://contentstack.com/docs/apis/content-delivery-api/)
163+
164+
### The MIT License (MIT)
165+
166+
Copyright © 2012-2017 [Built.io](https://www.built.io/). All Rights Reserved
167+
168+
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:
169+
170+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
171+
172+
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.

config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const config = {
66
urls: {
77
content_types: "/content_types/",
88
entries: "/entries/",
9+
assets: "/assets/",
910
environments: "/environments/"
1011
}
1112
};

csio-templates/tmpl/layout.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<h2 class="first-header ">Installation</h2>
3838
<div id="install_and_configure" class="subgroup">
3939
<h3>For Node.js</h3>
40-
<p>You need to install <a href="http://nodejs.org/" target="_blank">node.js</a> v0.10.22 or later to use the Built.io Contentstack SDK.</p>
40+
<p>You need to install <a href="http://nodejs.org/" target="_blank">node.js</a> v4.8.4 or later to use the Built.io Contentstack SDK.</p>
4141
<ol>
4242
<li>
4343
Run this command in a Terminal or Command Prompt&nbsp;to&nbsp;obtain and install the latest&nbsp;version of the&nbsp;Javascript SDK on your system.

dist/.DS_Store

6 KB
Binary file not shown.

0 commit comments

Comments
 (0)