# contentful-sync-redis

> Keep an up-to-date copy of your Contentful space in Redis

Latest version **0.4.1** (published 2017-09-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install contentful-sync-redis
pnpm add contentful-sync-redis
yarn add contentful-sync-redis
bun add contentful-sync-redis
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.1 |
| Published | 2017-09-01 |
| First published | 2017-08-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Matt Dean |
| Maintainers | mattdean |
| Keywords | contentful, redis |

## Links

- npm: https://www.npmjs.com/package/contentful-sync-redis
- Repository: https://github.com/mattdean1/contentful-sync-redis
- Homepage: https://github.com/mattdean1/contentful-sync-redis#readme
- Issues: https://github.com/mattdean1/contentful-sync-redis/issues
- npm.io page: https://npm.io/package/contentful-sync-redis

## Dependencies (4)

- [debug](https://npm.io/package/debug.md) ^3.0.1
- [redis](https://npm.io/package/redis.md) ^2.8.0
- [bluebird](https://npm.io/package/bluebird.md) ^3.5.0
- [contentful](https://npm.io/package/contentful.md) ^4.6.1

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 0.4.1 (latest) — 2017-09-01
- 0.4.0 — 2017-09-01
- 0.3.6 — 2017-08-30
- 0.3.5 — 2017-08-29
- 0.3.4 — 2017-08-29
- 0.3.3 — 2017-08-29
- 0.3.2 — 2017-08-29
- 0.3.1 — 2017-08-29
- 0.2.1 — 2017-08-26
- 0.2.0 — 2017-08-26
- 0.1.1 — 2017-08-25
- 0.1.0 — 2017-08-25

## README

[![Build Status](https://travis-ci.org/mattdean1/contentful-sync-redis.svg?branch=master)](https://travis-ci.org/mattdean1/contentful-sync-redis)

# contentful-sync-redis

> Keep an up-to-date copy of your Contentful space in Redis

#### What does this package do?

- Keeps a copy of your Contentful space in Redis, using the [Contentful Sync API](https://www.contentful.com/developers/docs/concepts/sync/).
- Provides a helper function to resolve [Links](https://www.contentful.com/developers/docs/concepts/links/) inside your entries.

#### Why wouldn't I use the Contentful Javascript SDK?

The Contentful JS SDK is a only thin wrapper on top of their API, and it can be tedious to [implement the Sync API](https://www.contentful.com/developers/docs/javascript/tutorials/using-the-sync-api-with-js/) in every project.

# Install

```
npm install --save contentful-sync-redis
```

# Usage

```javascript
const ContentfulSyncRedis = require('contentful-sync-redis')
const cf = new ContentfulSyncRedis({ space: 'space_id', token: 'access_token' })
cf.getEntries()
	.then(entries => yourFunction(entries))
```

# API

### Initialisation

Initialise the module using the `new` operator, passing in the mandatory values for:

 - Contentful space ID
 - Contentful access token

 Optionally, also pass in:

  - Contentful API host
     - Default: `cdn.contentful.com`
- Redis URL
  - Default: `redis://localhost:6379`

```javascript
const ContentfulSyncRedis = require('contentful-sync-redis')
const cf = new ContentfulSyncRedis({
	space: 'string',
	token: 'string',
	contentfulHost: 'optionalString',
	redisHost: 'optionalString',
})
```

### Synchronisation

Perform the initial download of content to Redis - it's often worth calling this just after initialisation

```javascript
cf.sync() // returns an empty promise
```

### Getting Entries

Return all entries in the Contentful space, after making sure the cache is synced.

You can use this without calling `sync()` beforehand.

```javascript
cf.getEntries() // returns a promise containing the entries
```



### Get Entries and Resolve Links

A wrapper function that calls `getEntries` and then `resolveReferences`.

```javascript
cf.getResolvedEntries(entries) // returns a promise containing the resolved entries
```

### 

### Resolving Links

Dereferences links to other entries in your content and groups fields by locale. Pass in an array of entries.

```javascript
cf.resolveReferences(entries) // returns a promise containing the resolved entries
```

e.g.

```javascript
cf.resolveReferences([
	{
	  sys: { ... },
	  fields: {
	    title: {
	      "en-US": `Home`,
	    },
	    summary: {
	      "en-US": `This is the homepage, it talks about the site `,
	    },
	    sections: {
	      "en-US": [
	        {
	          sys: {
	            type: `Link`,
	            linkType: `Entry`,
	            id: `6Gz0vGZmAoSgOSAM2Ks4gW`,
	          },
	        },
	        {
	          sys: {
	            type: `Link`,
	            linkType: `Entry`,
	            id: `S9n6QORFyEeKEUaGS2Ym4`,
	          },
	        },
	      ],
	    },
	  },
	}
])
```

Returns a Promise which resolves to:
```javascript
{
  sys: { ... },
  fields: {
    "en-US": {
      title: `Home`,
      summary: `This is the homepage, it talks about the site `,
      sections: [
        {
          sys: { ... },
          fields: {
            "en-US": {
              title: `About us`,
              content: `Made by Matt Dean`,
            },
          },
        },
        {
          sys: { ... },
          fields: {
            "en-US": {
              title: `Introduction`,
              content: `Hi this is contentful-sync-redis`,
            },
          },
        },
      ],
    },
  },
}
```

Where 'sections' is a multi-reference field

###  Logging

See the [debug module](https://www.npmjs.com/package/debug). Use the package name (`contentful-sync-redis`) as the string in the environment variable.


# Release Map / Changelog

### MVP - 0.1

 - [x] Implement Sync API
 - [x] `resolveReferences` helper function
 - [x] Preview API supported

### 0.2

 - [x] Tests using Mocha
 - [x] CI integration using Travis
 - [x] Contribution guidelines

### 0.3

 - [x] Group fields by locale
 - [x] No longer configure Redis client using an environment variable

### 0.4

- [x] Add sugar function to get entries and resolve references with a single call

### 1.0

- [ ] Support old versions of Node using webpack

### Later releases / To do

- Plugin functionality to allow for other databases
- Support filtering content
- Support assets

# Contributions

All contributions welcome! Please feel free to open an issue/PR :smile:

---
_Source: https://npm.io/package/contentful-sync-redis · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
