Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

contentful

Package Overview
Dependencies
Maintainers
5
Versions
450
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

contentful - npm Package Compare versions

Comparing version 2.1.2 to 3.0.0

browser-dist/contentful.js

24

index.js

@@ -1,8 +0,20 @@

'use strict';
// To understand why axios is vendored, check SETUP.md
var axios = require('./vendor-node/axios')
var contentful
try {
module.exports = require('./index.es5.js');
} catch (e) {
require('babel/register')();
module.exports = require('./index.es6.js');
contentful = require('./dist/contentful').default
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') {
require('babel-register')
contentful = require('./lib/contentful').default
} else {
console.log(err)
process.exit(1)
}
}
module.exports = {
createClient: function (params) {
return contentful(axios, params)
}
}
{
"name": "contentful",
"description": "Client for Contentful's Content Delivery API",
"version": "2.1.2",
"homepage": "https://www.contentful.com/developers/documentation/content-delivery-api/",
"main": "index.js",
"browser": "index.es5.js",
"repository": "git@github.com:contentful/contentful.js.git",
"author": "Stephan Seidt <stephan@contentful.com>",
"repository": {
"type": "git",
"url": "https://github.com/contentful/contentful.js.git"
},
"version": "3.0.0",
"author": "Contentful <support@contentful.com>",
"license": "MIT",
"scripts": {
"clean": "rimraf dist && rimraf browser-dist && rimraf coverage && rimraf out",
"build": "npm run clean && babel lib --out-dir dist && npm run build:optimize",
"build:standalone": "npm run clean && webpack -p",
"build:optimize": "npm run build:standalone && ccjs browser-dist/contentful.js --compilation_level=ADVANCED_OPTIMIZATIONS > browser-dist/contentful.min.js",
"docs:build": "jsdoc -r -c jsdoc.json dist",
"docs:dev": "npm run build && npm run docs:build",
"docs:watch": "watchy -w lib,jsdoc-template npm run docs:dev",
"docs:publish": "npm run docs:build && ./publish-docs.sh",
"test:ci": "npm run test:cover && npm run test:integration && if [ \"$TRAVIS_NODE_VERSION\" = \"5.0\" ] ; then npm run test:browser-remote; fi",
"test:cover": "BABEL_ENV=test babel-node ./node_modules/istanbul/lib/cli.js cover test/runner",
"test:only": "BABEL_ENV=test babel-node ./test/runner",
"test:debug": "BABEL_ENV=test babel-node debug ./test/runner",
"test:integration": "babel-node ./test/integration/tests.js",
"test:browser-local": "BABEL_ENV=test ./node_modules/.bin/karma start karma.conf.local.js",
"test:browser-remote": "BABEL_ENV=test ./node_modules/.bin/karma start karma.conf.saucelabs.js",
"vendor:node": "rimraf vendor-node && mkdirp vendor-node && babel node_modules/axios/lib/ --out-dir vendor-node/",
"vendor:browser": "rimraf vendor-browser && mkdirp vendor-browser && babel node_modules/axios/dist/axios.js --out-file vendor-browser/axios.js",
"browser-coverage": "npm run test:cover && opener coverage/lcov-report/index.html",
"postinstall": "npm run vendor:node && npm run vendor:browser",
"prepublish": "in-publish && npm run build || not-in-publish",
"postpublish": "npm run docs:publish && npm run clean",
"pretest": "standard lib/*.js && standard lib/**/*.js",
"test": "npm run test:cover && npm run test:integration && npm run test:browser-local",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"browser": "./browser.js",
"files": [
"index.js",
"dist",
"browser-dist",
"vendor-browser",
"vendor-node"
],
"dependencies": {
"axios": "^0.8.1",
"contentful-resolve-response": "^0.1.2"
"babel-runtime": "^6.3.19",
"lodash": "^4.2.0"
},
"devDependencies": {
"babel": "^4.7.16",
"babelify": "^6.0.1",
"bluebird": "^2.0.0",
"browserify": "^9.0.6",
"buster": "~0.7.6",
"envify": "~1.0.1",
"exorcist": "^0.1.6",
"saucie": "^0.1.0",
"testem": "~0.6.2",
"uglifyify": "^3.0.1"
"axios": "^0.9.1",
"babel-cli": "^6.4.5",
"babel-eslint": "^5.0.0-beta8",
"babel-loader": "^6.2.2",
"babel-plugin-rewire": "^1.0.0-beta-5",
"babel-plugin-transform-flow-strip-types": "^6.4.0",
"babel-plugin-transform-runtime": "^6.4.3",
"babel-preset-es2015": "^6.3.13",
"babel-register": "^6.4.3",
"blue-tape": "^0.2.0",
"closurecompiler": "^1.5.2",
"coveralls": "^2.11.6",
"cz-conventional-changelog": "^1.1.5",
"in-publish": "^2.0.0",
"istanbul": "^1.0.0-alpha.2",
"jsdoc": "^3.4.0",
"json-loader": "^0.5.4",
"karma": "^0.13.21",
"karma-babel-preprocessor": "^6.0.1",
"karma-chrome-launcher": "^0.2.2",
"karma-sauce-launcher": "^0.3.0",
"karma-tap": "^1.0.3",
"karma-webpack": "^1.7.0",
"mkdirp": "^0.5.1",
"opener": "^1.4.1",
"require-all": "^2.0.0",
"rimraf": "^2.5.1",
"semantic-release": "^4.3.5",
"sinon": "^2.0.0-pre",
"standard": "^5.4.1",
"webpack": "^1.12.13"
},
"scripts": {
"bower-build": "browserify -s contentful --debug -t [ babelify --sourceMapRelative . ] -t uglifyify index.es6.js | exorcist dist/contentful.min.js.map > dist/contentful.min.js",
"prepublish": "babel index.es6.js -s -o index.es5.js; npm run bower-build",
"watch": "babel index.es6.js -s -w -o index.es5.js",
"prepare-browser-test": "browserify -d -t envify -x buster test/helper.js > test/bundle-helper.js",
"ci": "testem ci -P 6",
"test": "testem"
"standard": {
"parser": "babel-eslint"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
# contentful.js
Javascript client for [Contentful's](https://www.contentful.com) Content Delivery API:
[![npm](https://img.shields.io/npm/v/contentful.svg)](https://www.npmjs.com/package/contentful)
[![Build Status](https://travis-ci.org/contentful/contentful.js.svg?branch=master)](https://travis-ci.org/contentful/contentful.js)
[![Coverage Status](https://coveralls.io/repos/github/contentful/contentful.js/badge.svg?branch=master)](https://coveralls.io/github/contentful/contentful.js?branch=master)
[![Dependency Status](https://david-dm.org/contentful/contentful.js.svg)](https://david-dm.org/contentful/contentful.js)
[![devDependency Status](https://david-dm.org/contentful/contentful.js/dev-status.svg)](https://david-dm.org/contentful/contentful.js#info=devDependencies)
- [Documentation](#api)
- [Example Apps](http://contentful.github.io/contentful.js/example/)
- [Tests](https://github.com/contentful/contentful.js/tree/master/test/integration) running in node and browsers via [BrowserStack](http://browserstack.com)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
Supported browsers/environments:
Javascript SDK for [Contentful's](https://www.contentful.com) Content Delivery API.
- Chrome
- Firefox
- IE10
- node.js >= 0.8
# About
## Install
[Contentful](https://www.contentful.com) is a content management platform for web applications, mobile apps and connected devices. It allows you to create, edit & manage content in the cloud and publish it anywhere via a powerful API. Contentful offers tools for managing editorial teams and enabling cooperation between organizations.
In node, using [npm](http://npmjs.org):
## Features
``` sh
npm install contentful
```
- Content retrieval through Contentful's [Content Delivery API](https://www.contentful.com/developers/docs/references/content-delivery-api/).
- [Synchronization](https://www.contentful.com/developers/docs/concepts/sync/)
- [Localization support](https://www.contentful.com/developers/docs/concepts/locales/)
- [Link resolution](https://www.contentful.com/developers/docs/concepts/links/)
In a browser, using [bower](http://bower.io):
## Supported environments
``` sh
bower install contentful
# After installing, add this as a script tag:
# <script src="components/contentful/dist/contentful.min.js"></script>
```
Browsers and Node.js:
- Chrome
- Firefox
- IE11 / Edge
- node.js >= 0.10
Latest [contentful.min.js](https://raw.github.com/contentful/contentful.js/master/dist/contentful.min.js).
# Getting started
Note: The next minor version release of `dist/contentful.min.js` will
be much smaller. Please use a package manager to keep your JS
dependencies up to date and get the newest version right when it's
ready!
In order to get started with the Contentful JS SDK you'll need not only to install it, but also to get credentials which will allow you to have access to your content in Contentful.
## Promises
## Installation
contentful.js uses [axios](https://github.com/mzabriskie/axios) under the hood, which depends on a native ES6 Promise implementation to be supported. If your environment doesn't support ES6 Promises, you can [polyfill](https://github.com/jakearchibald/es6-promise#auto-polyfill) it.
In node, using [npm](http://npmjs.org):
## API
### createClient(opts) -> Client
``` js
// Don't require if you've already included contentful as a script tag
var contentful = require('contentful');
var client = contentful.createClient({
// ID of Space
space: 'cfexampleapi',
// A valid access token within the Space
accessToken: 'b4c0n73n7fu1',
// Enable or disable SSL. Enabled by default.
secure: true,
// Set an alternate hostname, default shown.
host: 'cdn.contentful.com',
// Resolve links to entries and assets
resolveLinks: true,
// Optional HTTP agent for Node's http module
agent: agentInstance
});
``` sh
npm install contentful
```
If you'd like to use contentful.js with an http proxy, look into [https-proxy-agent](https://www.npmjs.com/package/https-proxy-agent). If you pass down an agent through the relevant initialization option it gets passed down to axios and subsequently to Node's http module.
Or, if you'd like to use a standalone built file you can use the following script tag or just download it from [npmcdn](https://npmcdn.com), under the `browser-dist` directory:
### Client#space() -> SpacePromise
```js
client.space()
.then(function (space) {
console.log(space.name)
})
``` html
<script src="https://npmcdn.com/contentful@latest/browser-dist/contentful.min.js"></script>
```
Returns a promise for a Space object:
Using `contentful@latest` will always get you the latest version, but you can also specify a specific version number:
```js
{
"sys": {
"type": "Space",
"id": "cfexampleapi"
},
"name": "Contentful Example API",
"locales": [
{"code": "en-US", "name": "English"},
{"code": "tlh", "name": "Klingon"}
]
}
``` html
<script src="https://npmcdn.com/contentful@3.0.0/browser-dist/contentful.min.js"></script>
```
### Client#entry(id) -> EntryPromise
## Authentication
Get an entry by it's `sys.id`. Note that this example uses an entry created
with a human-readable ID via the [Content Management API][cma-entry-put].
Entries created in the [Contentful app][cf-app] will have auto-generated ID's.
To get content from Contentful, an app should authenticate with an with an OAuth bearer token.
Links to other entries are not resolved when using this call. If you'd like to have your links resolved automatically, you should use the `entries()` call with [search parameters](#search-examples)
You can create API keys using [Contentful's web interface](https://app.contentful.com). Go to the app, open the space that you want to access (top left corner lists all the spaces), and navigate to the APIs area. Open the API Keys section and create your first token. Done.
```js
client.entry('nyancat')
.then(function (entry) {
console.log(entry.id)
})
```
Don't forget to also get your Space ID.
Returns a promise for an Entry object:
For more information, check the Contentful's REST API reference on [Authentication](https://www.contentful.com/developers/docs/references/authentication/).
```js
{
"sys": {
"type": "Entry",
"id": "cat",
"space": {"sys": {"type": "Link", "linkType": "Space", "id": "example"}},
"contentType": {"sys": {"type": "Link", "linkType": "ContentType", "id": "cat"}},
"createdAt": "2013-03-26T00:13:37.123Z",
"updatedAt": "2013-03-26T00:13:37.123Z",
"revision": 1
},
"fields": {
"name": "Nyan cat",
"color": "Rainbow",
"nyan": true,
"birthday": "2011-04-02T00:00:00.000Z",
"diary": "Nyan cat has an epic rainbow trail.",
"likes": ["rainbows", "fish"],
"bestFriend": {"type": "Link", "linkType": "Entry", "id": "happycat"}
}
}
```
## Documentation/References
### Client#entries(query) -> EntryCollectionPromise
* [Contentful's JS SDK reference](https://contentful.github.io/contentful.js)
* From version 3.0.0 onwards, you can access documentation for a specific version by visiting https://contentful.github.io/contentful.js/contentful/VERSION
* For versions prior to 3.0.0, you can access documentation at https://github.com/contentful/contentful.js/tree/legacy
* Check the [Contentful for JavaScript](https://www.contentful.com/developers/docs/javascript/) page for Tutorials, Demo Apps, and more information on other ways of using JavaScript with Contentful
* [Contentful's CDA REST API reference](https://www.contentful.com/developers/docs/references/content-delivery-api/) for additional details on the Delivery API
Search & filter all of the entries in a space. The `query` parameter will be
added to the request querystring key-value pairs.
## Versioning
```js
client.entries({ content_type: 'cat' })
.then(function (entries) {
console.log('Total entries:', entries.total)
entries.forEach(function (entry) {
console.log(entry.id)
})
})
```
This project strictly follows [Semantic Versioning](http://semver.org/) by use of [semantic-release](https://github.com/semantic-release/semantic-release).
Returns a promise for a [collection][] of Entry objects, which is an array with 3 special properties:
This means that new versions are released automatically as fixes, features or breaking changes are released.
```js
[
"total": 2,
"skip": 0,
"limit": 100,
/* Each item in the array is a full Entry object as shown above */
]
```
You can check the changelog on the [releases](https://github.com/contentful/contentful.js/releases) page.
#### Search Examples
## Migration from contentful.js 2.x and older
These examples show some of the searching you can do by passing query params
to [`Client#entries`][client-entries]. Each
query parameter name must be a dot-separated property path followed by an
optional operator in square brackets. For example: `fields.name[ne]` means
"entries where `fields.name` is not-equal to ...". Full documentation of the
allowed query parameters & field operators can be found in
[our API Documentation][search-parameters].
contentful.js 3.x was a major rewrite, with some API changes. While the base functionality remains the same, some method names have changed, as well as some internal behaviors.
*Be aware that these search parameters are only applicable to `entries()` and not `entry()`
See the [migration guide](migration_from_2_x.md) for more information.
Search entries that have been updated since the 1st of January, 2013:
## Support
```js
client.entries({ 'sys.updatedAt[gte]': '2013-01-01T00:00:00Z' })
.then(function (entries) {
// ...
})
```
Please open an [issue](https://github.com/contentful/contentful.js/issues/new)
Retrieve a specific set of entries by their multiple `sys.id` using the inclusion operator:
## Contributing
```js
client.entries({ 'sys.id[in]': 'finn,jake' ] })
.then(function (entries) {
// ...
})
```
See [CONTRIBUTING.md](CONTRIBUTING.md)
Search for `cat` entries that have less than three lives left:
```js
client.entries({
'content_type': 'cat',
'fields.lives[lt]': 3
})
.then(function (entries) {
// ...
})
```
> Specifying the `content_type` query parameter is _required_ when querying on
> fields (such as `fields.lives` above). Note that `'cat'` is the content type
> **ID** and not it's name.
Full-text search for entries with "bacon" anywhere in their textual content:
```js
client.entries({ query: 'bacon' })
.then(function (entries) {
// ...
})
```
Full-text search for dogs with "bacon" specifically in the `description` field:
```js
client.entries({
'content_type': 'dog',
'fields.description[match]': 'bacon'
})
.then(function (entries) {
// ...
})
```
Get the 50 most recently created entries, and the next 50:
```js
client.entries({
order: '-sys.createdAt',
limit: 50
})
.then(function (entries) {
// ...
})
client.entries({
order: '-sys.createdAt',
skip: 50,
limit: 50
})
.then(function (entries) {
// ...
})
```
Getting localized entries:
```js
client.entries({
locale: 'es-ES'
})
.then(function (entries) {
// ...
})
```
See also: [Collections and pagination][collection].
### Client#asset(id) -> Asset
Get an asset by it's `sys.id`. Note that this example uses an entry created
with a human-readable ID via the [Content Management API][cma-asset-put].
Assets created in the [Contentful app][cf-app] will have auto-generated ID's.
```js
client.asset('nyancat')
.then(function (asset) {
console.log(asset.fields.file.url)
})
```
Returns a promise for an Asset object:
```js
{
"sys": {
"type": "Asset",
"id": "nyancat",
"space": {"sys": {"type": "Link", "linkType": "Space", "id": "example"}},
"createdAt": "2013-03-26T00:13:37.123Z",
"updatedAt": "2013-03-26T00:13:37.123Z",
"revision": 1
},
"fields": {
"title": "Nyan cat",
"description": "A typical picture of Nyancat including the famous rainbow trail.",
"file": {
"fileName": "nyancat.png",
"contentType": "image/png",
"details": {
"image": {
"width": 250,
"height": 250
},
"size": 12273
},
"url": "//images.contentful.com/cfexampleapi/4gp6taAwW4CmSgumq2ekUm/9da0cd1936871b8d72343e895a00d611/Nyan_cat_250px_frame.png"
}
}
}
```
### Client#assets(query) -> AssetCollectionPromise
Search & filter all of the assets in a space. The keys-value pairs from `query`
will be added to the request query string like [`Client#entries(query)`][client-entries].
See the [`Client#entries(query)` search examples](#search-examples) for more details.
```js
client.assets({ query: 'kitten' })
.then(function (assets) {
assets.forEach(function (asset) {
console.log(asset.fields.file.url)
})
})
```
Returns a promise for a [collection][] of Asset objects, which is an array with 3 special properties:
```js
[
"total": 2,
"skip": 0,
"limit": 100,
/* Each item in the array is a full Asset object as shown above */
]
```
### Client#contentType(id) -> ContentTypePromise
Get a content type by it's `sys.id`. Note that this example uses a content type
created with a human-readable ID via the [Content Management API][cma-ct-put].
Content types created in the [Contentful app][cf-app] will have auto-generated
ID's.
```js
client.contentType('cat')
.then(function (contentType) {
console.log(contentType.name)
})
```
Returns a promise for a ContentType object:
```js
{
"sys": {
"type": "ContentType",
"id": "cat"
},
"name": "Cat",
"description": "Meow.",
"fields": [
{"id": "name", "name": "Name", "type": "Text"},
{"id": "diary", "name": "Diary", "type": "Text"},
{"id": "likes", "name": "Likes", "type": "Array", "items": {"type": "Symbol"}},
{"id": "bestFriend", "name": "Best Friend", "type": "Link"},
{"id": "lifes", "name": "Lifes left", "type": "Integer"}
]
}
```
### Client#contentTypes() -> ContentTypeCollectionPromise
```js
client.contentTypes()
.then(function (contentTypes) {
contentTypes.forEach(function (contentType) {
console.log(contentType.name)
})
})
```
Returns a promise for a [collection][] of ContentType objects, which is an array with 3 special properties:
```js
{
"total": 3,
"skip": 0,
"limit": 100,
/* Each item in the array is a full ContentType object as shown above */
}
```
### Client#sync(opts) -> SyncResponse
Our [Sync API][sync-api] allows to keep a local copy of the data in your space
up to date by receiving delta updates.
There are two supported options, pass `{ initial: true }` to start a brand new
copy, or `{ nextSyncToken: syncToken }` resume syncing using a token returned in a
previous call to `sync`.
Here is an example of syncing some local store:
```js
// Assuming you have some wrapper around browser storage
var syncToken = storage.get('syncToken')
var entries = storage.get('entries')
client.sync(token ? {nextSyncToken: syncToken} : {initial: true})
.then(function(response){
response.items.forEach(function (entity) {
if(entity.sys.type === 'Entry'){
entries[entity.sys.id] = entity
}
if(entity.sys.type === 'DeletedEntry'){
delete entries[entity.sys.id]
}
})
storage.set('entries', entries)
storage.set('syncToken', data.nextSyncToken)
});
```
Each call to `sync` returns a SyncResponse object:
```
{
"sys": {
"type": "Array"
},
"total": 3,
"skip": 0,
"limit": 100,
"items": [
/* Each item in the array is either an Entry, Asset, DeletedEntry or DeletedAsset */
]
}
```
In addition the entries and assets, a sync response may contain deletion items:
```js
{
"sys": {
"type": "DeletedEntry",
"id": "cat",
"space": {"sys": {"type": "Link", "linkType": "Space", "id": "example"}},
"contentType": {"sys": {"type": "Link", "linkType": "ContentType", "id": "cat"}},
"createdAt": "2013-03-26T00:13:37.123Z",
"updatedAt": "2013-03-26T00:13:37.123Z"
},
}
```
```js
{
"sys": {
"type": "DeletedAsset",
"id": "nyancat",
"space": {"sys": {"type": "Link", "linkType": "Space", "id": "example"}},
"createdAt": "2013-03-26T00:13:37.123Z",
"updatedAt": "2013-03-26T00:13:37.123Z"
},
}
```
### Collections and pagination
Many methods return collections of resources. These collections are represented
as a JSON object containing items and pagination details:
```
{
"total": 1, // Total number of items matching the query
"skip": 0, // Offset into the result set represented by this response
"limit": 100, // Effective limit on # of items returned in this response
// Full representations of each item
}
```
The `entries` and `assets` methods both accept `limit`, `skip`, and `order` as
query parameters, allowing you to paginate through larger result sets. Note that
you should specify a stable `order` property (such as `order: 'sys.createdAt'`)
when paginating.
## License
MIT
[contentful]: http://www.contentful.com
[search-parameters]: http://docs.contentfulcda.apiary.io/#reference/search-parameters
[cma-entry-put]: http://docs.contentfulcma.apiary.io/#reference/entries/entry/create/update-an-entry
[cma-asset-put]: http://docs.contentfulcma.apiary.io/#reference/assets/asset/create/update-an-asset
[cma-ct-put]: http://docs.contentfulcma.apiary.io/#reference/content-types/content-type/create/update-a-content-type
[cf-app]: https://app.contentful.com
[sync-api]: http://docs.contentfulcda.apiary.io/#reference/synchronization
[collection]: #collections-and-pagination
[client-entries]: #cliententriesquery---entrycollectionpromise
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc