Skip to content

Commit b436c9b

Browse files
authored
Merge pull request #1 from contentstack/development
Initial release v1.0.0
2 parents 8ca6579 + 3c170eb commit b436c9b

Some content is hidden

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

41 files changed

+13041
-2
lines changed

.babel-preset.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var plugins = [
2+
'transform-object-rest-spread',
3+
'lodash',
4+
['inline-replace-variables', {
5+
// Inject version number into code
6+
'__VERSION__': require('./package.json').version
7+
}]
8+
]
9+
10+
11+
function babelConfig () {
12+
return plugins
13+
}
14+
module.exports = babelConfig

.babelrc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"presets": ["@babel/preset-env"],
3+
"plugins": [
4+
["@babel/plugin-transform-runtime", {
5+
"regenerator": true
6+
}]
7+
],
8+
"env": {
9+
"test": {
10+
"presets": [
11+
["@babel/env"]
12+
],
13+
"plugins": ["rewire"],
14+
"sourceMaps": "inline"
15+
},
16+
"es5": {
17+
"presets": [
18+
["@babel/env"]
19+
],
20+
"plugins": [
21+
"add-module-exports",
22+
"@babel/plugin-transform-runtime",
23+
"transform-es2015-modules-commonjs"
24+
]
25+
},
26+
"es-modules": {
27+
"presets": [
28+
["@babel/env", {
29+
"modules": false
30+
}]
31+
]
32+
}
33+
}
34+
}

.eslintrc.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module.exports = {
2+
// "env": {
3+
// "browser": true,
4+
// "amd": true
5+
// },
6+
"extends": "standard",
7+
// "globals": {
8+
// "Atomics": "readonly",
9+
// "SharedArrayBuffer": "readonly"
10+
// },
11+
// "parserOptions": {
12+
// "ecmaFeatures": {
13+
// "jsx": true
14+
// },
15+
// "ecmaVersion": 2015,
16+
// "sourceType": "module"
17+
// },
18+
'plugins': [
19+
'standard',
20+
'promise'
21+
],
22+
"rules": {
23+
}
24+
};

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Logs
22
logs
33
*.log
4+
*.DS_Store
45
npm-debug.log*
56
yarn-debug.log*
67
yarn-error.log*
@@ -35,10 +36,14 @@ build/Release
3536
# Dependency directories
3637
node_modules/
3738
jspm_packages/
39+
jsdocs/
40+
mochawesome-report/
41+
coverage/
42+
test/utility/dataFiles/
3843

3944
# TypeScript v1 declaration files
4045
typings/
41-
46+
tsconfig.json
4247
# Optional npm cache directory
4348
.npm
4449

.jsdoc.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"tags": {
3+
"allowUnknownTags": true,
4+
"dictionaries": ["jsdoc"]
5+
},
6+
"source": {
7+
"include": [
8+
"lib/contentstack.js",
9+
"lib/contentstackClient.js",
10+
"lib/user/index.js",
11+
"lib/organization/index.js",
12+
"lib/stack/index.js",
13+
"lib/stack/contentType/index.js",
14+
"lib/stack/globalField/index.js",
15+
"lib/query/index.js",
16+
"lib/stack/contentType/entry/index.js",
17+
"lib/stack/asset/index.js",
18+
"lib/stack/asset/folders/index.js",
19+
"lib/stack/bulkOperation/index.js",
20+
"lib/stack/extension/index.js",
21+
"lib/stack/release/index.js",
22+
"lib/stack/label/index.js",
23+
"lib/stack/locale/index.js",
24+
"lib/stack/environment/index.js",
25+
"lib/stack/deliveryToken/index.js",
26+
"lib/stack/roles/index.js",
27+
"lib/stack/webhook/index.js"
28+
],
29+
"excludePattern": "(node_modules/|jsdocs)"
30+
},
31+
"templates": {
32+
"cleverLinks": false,
33+
"monospaceLinks": true
34+
},
35+
"opts": {
36+
"destination": "./jsdocs/",
37+
"encoding": "utf8",
38+
"private": true,
39+
"recurse": true,
40+
"template": "./node_modules/docdash",
41+
"sort": false
42+
},
43+
"docdash": {
44+
"static": true,
45+
"sort": false
46+
}
47+
}

.npmignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
docs-config.json
2+
.idea/
3+
.git/
4+
test/
5+
reports/
6+
contentstack-templates/
7+
jsdocs/
8+
examples/
9+
mocktest.json
10+
Sample
11+
coverage/
12+
mochawesome-report/
13+
.nyc_output/
14+
typings
15+
webpack/
16+
tsconfig.json
17+
.jsdoc.json

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Changelog
2+
3+
## [v1.0.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.0.0) (2020-09-23)
4+
- Initial release for Contentstack CMA base JS management SDK

README.md

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,113 @@
1-
# contentstack-management-javascript
1+
[![Contentstack](https://www.contentstack.com/docs/static/images/contentstack.png)](https://www.contentstack.com/)
2+
3+
## Contentstack Management JavaScript SDK
4+
5+
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. All you have to do is build your application frontend, and Contentstack will take care of the rest. [Read More](https://www.contentstack.com/).
6+
7+
This SDK uses the [Content Management API](https://www.contentstack.com/docs/developers/apis/content-management-api/) (CMA). The CMA is used to manage the content of your Contentstack account. This includes creating, updating, deleting, and fetching content of your account. To use the CMA, you will need to authenticate your users with a [Management Token](https://www.contentstack.com/docs/developers/create-tokens/about-management-tokens) or an [Authtoken](https://www.contentstack.com/docs/developers/apis/content-management-api/#how-to-get-authtoken). Read more about it in [Authentication](https://www.contentstack.com/docs/developers/apis/content-management-api/#authentication).
8+
9+
Note: By using CMA, you can execute GET requests for fetching content. However, we strongly recommend that you always use the [Content Delivery API](https://www.contentstack.com/docs/developers/apis/content-delivery-api/) to deliver content to your web or mobile properties.
10+
11+
### Prerequisite
12+
13+
You need Node.js version 10 or above installed on your machine to use the Contentstack JavaScript CMA SDK.
14+
15+
### Installation
16+
#### Node
17+
Install it via npm:
18+
```bash
19+
npm i @contentstack/management
20+
```
21+
To import the SDK, use the following command:
22+
```
23+
import contentstack from ‘@contentstack/management’
24+
25+
contentstackClient = contentstack.client()
26+
```
27+
28+
### Authentication
29+
To use this SDK, you need to authenticate your users by using the Authtoken, credentials, or Management Token (stack-level token).
30+
### Authtoken
31+
An [Authtoken](https://www.contentstack.com/docs/developers/create-tokens/types-of-tokens/#authentication-tokens-authtokens-) is a read-write token used to make authorized CMA requests, and it is a **user-specific** token.
32+
```
33+
contentstackClient = contentstack.client({ authtoken: 'AUTHTOKEN' })
34+
```
35+
### Login
36+
To Login to Contentstack by using credentials, you can use the following lines of code:
37+
```
38+
contentstackClient.login({ email: 'EMAIL', password: 'PASSWORD'})
39+
.then((response) => {
40+
console.log(response.notice)
41+
console.log(response.user)
42+
})
43+
```
44+
45+
### Management Token
46+
[Management Tokens](https://www.contentstack.com/docs/developers/create-tokens/about-management-tokens/) are **stack-level** tokens, with no users attached to them.
47+
```
48+
contentstackClient.stack({ api_key: 'API_KEY', management_token: 'MANAGEMENT_TOKEN' })
49+
.fetch()
50+
.then((stack) => {
51+
console.log(stack)
52+
})
53+
```
54+
### Contentstack Management JavaScript SDK: 5-minute Quickstart
55+
#### Initializing Your SDK:
56+
To use the JavaScript CMA SDK, you need to first initialize it. To do this, use the following code:
57+
```
58+
import contentstack from ‘@contentstack/management’
59+
60+
var contentstackClient = contentstack.client({ authtoken: 'AUTHTOKEN' })
61+
```
62+
#### Fetch Stack Detail
63+
Use the following lines of code to fetch your stack detail using this SDK:
64+
```
65+
contentstackClient.stack({ api_key: 'API_KEY' })
66+
.fetch()
67+
.then((stack) => {
68+
console.log(stack)
69+
})
70+
```
71+
72+
#### Create Entry
73+
To create an entry in a specific content type of a stack, use the following lines of code:
74+
```
75+
var entry = {
76+
title: 'Sample Entry',
77+
url: '/sampleEntry'
78+
}
79+
80+
contentstackClient.stack({ api_key: 'API_KEY' }).contentType('CONTENT_TYPE_UID').entry().create({ entry })
81+
.then((entry) => {
82+
console.log(entry)
83+
})
84+
```
85+
86+
#### Create Asset
87+
The following lines of code can be used to upload assets to your stack:
88+
```
89+
var asset = {
90+
upload: 'path/to/file',
91+
title: 'Asset Title'
92+
}
93+
94+
contentstackClient.stack({ api_key: 'API_KEY' }).asset().create({ asset })
95+
.then((asset) => {
96+
console.log(asset)
97+
})
98+
```
99+
100+
### Helpful Links
101+
102+
- [Contentstack Website](https://www.contentstack.com/)
103+
- [Official Documentation](https://contentstack.com/docs)
104+
- [Content Management API Docs](https://www.contentstack.com/docs/developers/apis/content-management-api)
105+
106+
### The MIT License (MIT)
107+
Copyright © 2012-2020 [Contentstack](https://www.contentstack.com/). All Rights Reserved
108+
109+
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:
110+
111+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
112+
113+
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.

0 commit comments

Comments
 (0)