feat: Update to the new SDK

This commit is contained in:
Khaled Garbaya
2018-04-19 15:53:02 +02:00
committed by Khaled Garbaya
parent 1baef21340
commit 8a2b7dc649
33 changed files with 27 additions and 17 deletions

6
app.js
View File

@@ -16,7 +16,7 @@ const breadcrumb = require('./lib/breadcrumb')
const { updateCookie } = require('./lib/cookies') const { updateCookie } = require('./lib/cookies')
const settings = require('./lib/settings') const settings = require('./lib/settings')
const routes = require('./routes/index') const routes = require('./routes/index')
const { getSpace } = require('./services/contentful') const { getSpace, getLocales } = require('./services/contentful')
const { catchErrors } = require('./handlers/errorHandlers') const { catchErrors } = require('./handlers/errorHandlers')
const SETTINGS_NAME = 'theExampleAppSettings' const SETTINGS_NAME = 'theExampleAppSettings'
@@ -97,12 +97,12 @@ app.use(catchErrors(async function (request, response, next) {
// Catch misconfigured space credentials and display settings page // Catch misconfigured space credentials and display settings page
try { try {
const space = await getSpace() const space = await getSpace()
const locales = await getLocales()
// Update credentials in cookie when space connection is successful // Update credentials in cookie when space connection is successful
updateCookie(response, SETTINGS_NAME, response.locals.settings) updateCookie(response, SETTINGS_NAME, response.locals.settings)
// Get available locales from space // Get available locales from space
response.locals.locales = space.locales response.locals.locales = locales
const defaultLocale = response.locals.locales const defaultLocale = response.locals.locales
.find((locale) => locale.default) .find((locale) => locale.default)

0
i18n/locales/de-DE.json Normal file → Executable file
View File

0
i18n/locales/en-US.json Normal file → Executable file
View File

14
package-lock.json generated
View File

@@ -1488,13 +1488,13 @@
"dev": true "dev": true
}, },
"contentful": { "contentful": {
"version": "5.1.2", "version": "6.0.0",
"resolved": "https://registry.npmjs.org/contentful/-/contentful-5.1.2.tgz", "resolved": "https://registry.npmjs.org/contentful/-/contentful-6.0.0.tgz",
"integrity": "sha512-grkUVBMeZpedgBKuJyVJ7ErQz9f7pDchrR2ue9uWtdL+dpje77dUP27s8BKpmf7t9mx+Y+XJeVsuz2AM99D95w==", "integrity": "sha512-jvYShGAc4pCZUa8jdnXvVQS77v7MJN3qHuJhbvWPV6P5EMnRBR22+ltZOzoc3Zntt5jH7rpgsZQe2MjNH/phvw==",
"requires": { "requires": {
"@contentful/axios": "0.18.0", "@contentful/axios": "0.18.0",
"contentful-resolve-response": "1.1.4", "contentful-resolve-response": "1.1.4",
"contentful-sdk-core": "5.0.3", "contentful-sdk-core": "6.0.0-beta1",
"json-stringify-safe": "5.0.1", "json-stringify-safe": "5.0.1",
"lodash": "4.17.5" "lodash": "4.17.5"
} }
@@ -1508,9 +1508,9 @@
} }
}, },
"contentful-sdk-core": { "contentful-sdk-core": {
"version": "5.0.3", "version": "6.0.0-beta1",
"resolved": "https://registry.npmjs.org/contentful-sdk-core/-/contentful-sdk-core-5.0.3.tgz", "resolved": "https://registry.npmjs.org/contentful-sdk-core/-/contentful-sdk-core-6.0.0-beta1.tgz",
"integrity": "sha512-qY8MtGD51rRsvBTtddqztomMAfTQxlepxZE3QR38LfQcZGEEqaMRs+Isn0YNVY6bdNiAzUfOza9Q9gg9uI30iA==", "integrity": "sha512-X2+pusbgKqgdRzGEZcv5FmA7CkahRtsZXA1ZT/qKjNjal++BhBa4oP0WDSmBZXMl57lZ/LWxca15tpotMEHdYw==",
"requires": { "requires": {
"lodash": "4.17.5", "lodash": "4.17.5",
"qs": "6.5.1" "qs": "6.5.1"

View File

@@ -24,7 +24,7 @@
}, },
"dependencies": { "dependencies": {
"body-parser": "^1.18.2", "body-parser": "^1.18.2",
"contentful": "^5.1.2", "contentful": "^6.0.0",
"cookie-parser": "~1.4.3", "cookie-parser": "~1.4.3",
"dotenv": "^5.0.0", "dotenv": "^5.0.0",
"execa": "^0.9.0", "execa": "^0.9.0",

0
public/fonts/roboto-bold-webfont.woff Normal file → Executable file
View File

0
public/fonts/roboto-bold-webfont.woff2 Normal file → Executable file
View File

0
public/fonts/roboto-bolditalic-webfont.woff Normal file → Executable file
View File

0
public/fonts/roboto-bolditalic-webfont.woff2 Normal file → Executable file
View File

0
public/fonts/roboto-italic-webfont.woff Normal file → Executable file
View File

0
public/fonts/roboto-italic-webfont.woff2 Normal file → Executable file
View File

0
public/fonts/roboto-medium-webfont.woff Normal file → Executable file
View File

0
public/fonts/roboto-medium-webfont.woff2 Normal file → Executable file
View File

0
public/fonts/roboto-mediumitalic-webfont.woff Normal file → Executable file
View File

0
public/fonts/roboto-mediumitalic-webfont.woff2 Normal file → Executable file
View File

0
public/fonts/roboto-regular-webfont.woff Normal file → Executable file
View File

0
public/fonts/roboto-regular-webfont.woff2 Normal file → Executable file
View File

0
public/icons/icons.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

0
public/images/badge-app-store.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 6.0 KiB

After

Width:  |  Height:  |  Size: 6.0 KiB

0
public/images/badge-google-play.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 7.6 KiB

0
public/images/contentful-logo.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

0
public/images/icon-android.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

0
public/images/icon-dotnet.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

0
public/images/icon-java.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

0
public/images/icon-javascript.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 885 B

After

Width:  |  Height:  |  Size: 885 B

0
public/images/icon-nodejs.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

0
public/images/icon-php.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

0
public/images/icon-python.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

0
public/images/icon-ruby.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 7.5 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

0
public/images/icon-swift.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

0
public/images/the-example-app-logo-dotnet.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 756 B

After

Width:  |  Height:  |  Size: 756 B

View File

@@ -51,6 +51,16 @@ module.exports.getSpace = throwOnEmptyResult('Space', (api = 'cda') => {
return getClient(api).getSpace() return getClient(api).getSpace()
}) })
/**
* Get the environment locales
* @param api - string - the api to use, cda or cap. Default: 'cda'
* @returns {undefined}
*/
module.exports.getLocales = throwOnEmptyResult('Environment', (api = 'cda') => {
return getClient(api).getLocales()
.then((response) => response.items)
})
/** /**
* Gets an entry. Used to detect the `Draft` or `Pending Changes` state * Gets an entry. Used to detect the `Draft` or `Pending Changes` state
* @param entryId - string - the entry id * @param entryId - string - the entry id

View File

@@ -1,6 +1,6 @@
doctype html doctype html
html html(lang='en')
head head(role='header')
title= helpers.formatMetaTitle(title, currentLocale.code) title= helpers.formatMetaTitle(title, currentLocale.code)
link(rel='stylesheet', href='/stylesheets/style.css') link(rel='stylesheet', href='/stylesheets/style.css')
meta(name='viewport' content='width=device-width, initial-scale=1') meta(name='viewport' content='width=device-width, initial-scale=1')
@@ -22,9 +22,9 @@ html
link(rel='mask-icon' href='/safari-pinned-tab.svg' color='#4a90e2') link(rel='mask-icon' href='/safari-pinned-tab.svg' color='#4a90e2')
meta(name='theme-color' content='#ffffff') meta(name='theme-color' content='#ffffff')
body body
main.main main.main(role='main')
.main__header .main__header
header.header header.header(role='banner')
.header__upper-wrapper .header__upper-wrapper
.header__upper.layout-centered .header__upper.layout-centered
.header__upper-title .header__upper-title
@@ -78,7 +78,7 @@ html
.header__logo .header__logo
a.header__logo-link(href=`/${queryString}`) a.header__logo-link(href=`/${queryString}`)
img(src='/images/the-example-app-logo-nodejs.svg' alt=translate('logoAlt', currentLocale.code)) img(src='/images/the-example-app-logo-nodejs.svg' alt=translate('logoAlt', currentLocale.code))
nav.header__navigation.main-navigation nav.header__navigation.main-navigation(role='navigation')
ul ul
li li
a(href=`/${queryString}` class=(currentPath === '/'? 'active' : '')) #{translate('homeLabel', currentLocale.code)} a(href=`/${queryString}` class=(currentPath === '/'? 'active' : '')) #{translate('homeLabel', currentLocale.code)}
@@ -91,7 +91,7 @@ html
.layout-centered .layout-centered
footer.footer footer.footer
.footer__upper .footer__upper
nav.footer__navigation.main-navigation nav.footer__navigation.main-navigation(role='navigation')
ul ul
li li
a(href=`/${queryString}` class=(currentPath === '/'? 'active' : '')) #{translate('homeLabel', currentLocale.code)} a(href=`/${queryString}` class=(currentPath === '/'? 'active' : '')) #{translate('homeLabel', currentLocale.code)}