Skip to content

Commit 1b89f26

Browse files
authored
Merge branch 'master' into dependabot/npm_and_yarn/y18n-4.0.3
2 parents 7228b82 + a05dbcf commit 1b89f26

File tree

3 files changed

+101
-20
lines changed

3 files changed

+101
-20
lines changed

README.md

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![NPM](https://nodei.co/npm/kentico-kontent-nuxt-module.png?mini=true)](https://npmjs.org/package/kentico-kontent-nuxt-module)
44

55
# kentico-kontent-nuxt-module
6-
Add Kentico Kontent super power to your nuxt app
6+
Add Kentico Kontent super power to your nuxt app :fire:
77

88
## Features
99

@@ -20,7 +20,7 @@ npm i rxjs --save (because this is a peer dependency of the Kentico Kontent Deli
2020

2121
- Add `kentico-kontent-nuxt-module` to `modules` section of `nuxt.config.js`
2222

23-
```js
23+
```json
2424
/*
2525
** Nuxt.js modules
2626
*/
@@ -40,6 +40,9 @@ npm i rxjs --save (because this is a peer dependency of the Kentico Kontent Deli
4040
enableSecuredMode: true
4141
},
4242
```
43+
> Note: See [the client configuration section](https://github.com/Kentico/kontent-delivery-sdk-js/blob/master/DOCS.md#client-configuration) of the Kentico Kontent Delivery SDK for all available configuration options.
44+
45+
4346
- $deliveryClient is now globally available.
4447

4548
```javascript
@@ -53,6 +56,25 @@ npm i rxjs --save (because this is a peer dependency of the Kentico Kontent Deli
5356
### Note:
5457
By default Nuxt can only work with promises. Therefor you always use the "toPromise" method provided by the Kentico Kontent Delivery SDK! RxJs operator's are not supported at the moment.
5558

59+
# Typescript
60+
61+
Since version 7 the kentico-kontent-nuxt-module has typescript support!
62+
63+
Add the types to your "types" array in tsconfig.json after the @nuxt/types (Nuxt 2.9.0+) or @nuxt/vue-app entry
64+
65+
```json
66+
67+
{
68+
"compilerOptions": {
69+
"types": [
70+
"@nuxt/types",
71+
"kentico-kontent-nuxt-module"
72+
]
73+
}
74+
}
75+
76+
```
77+
5678
## Generating
5779
When using a static generated deployment you may need to use the [items-feed](https://docs.kontent.ai/reference/api-changelog#a-delivery-api-limitation) endpoint when generating your site (because the items endpoint has a rate limitation).
5880

@@ -68,6 +90,7 @@ When using a static generated deployment you may need to use the [items-feed](ht
6890
API calls can be "cached" (they will be stored in memory) client side via the "viaCache" method.
6991

7092
```javascript
93+
7194
const query = this.$deliveryClient.items().type('page');
7295
const cacheSeconds = 30;
7396
this.$deliveryClient.viaCache(query, cacheSeconds)
@@ -80,7 +103,7 @@ API calls can be "cached" (they will be stored in memory) client side via the "v
80103
If you need to customize the Kentico Kontent Delivery SDK by registering interceptors and changing global config, you have to create a nuxt plugin.
81104

82105
### nuxt.config.js
83-
```
106+
``` json
84107
{
85108
modules: [
86109
'kentico-kontent-nuxt-module',
@@ -93,7 +116,22 @@ If you need to customize the Kentico Kontent Delivery SDK by registering interce
93116
```
94117

95118
### plugins/kenticokontentNuxtModule.js
119+
120+
> Version >7.x.x
121+
122+
``` javascript
123+
export default function ({ store, $deliveryClient }) {
124+
$deliveryclient.deliveryClient.config.globalHeaders = (queryConfig) => {
125+
let headers = [];
126+
headers.push({header: 'Authorization', value: 'bearer ' + store.state.token });
127+
return headers;
128+
}
129+
}
96130
```
131+
132+
> Version <7.0.0
133+
134+
``` javascript
97135
export default function ({ store, $deliveryClient }) {
98136
$deliveryClient.config.globalHeaders = (queryConfig) => {
99137
let headers = [];
@@ -108,7 +146,35 @@ export default function ({ store, $deliveryClient }) {
108146
Type resolvers can also be registered by using a nuxt plugin:
109147

110148
### plugins/kenticokontentNuxtModule.js
149+
150+
> Version >7.x.x
151+
152+
``` javascript
153+
import { TypeResolver, ContentItem } from '@kentico/kontent-delivery';
154+
155+
class Page extends ContentItem {
156+
constructor() {
157+
super({
158+
richTextResolver: (item, context) => {
159+
// todo: implement
160+
},
161+
urlSlugResolver: (link, context) => {
162+
// todo: implement
163+
}
164+
});
165+
}
166+
}
167+
168+
export default function ({ store, app, $deliveryClient }) {
169+
$deliveryClient.deliveryClient.config.typeResolvers = [
170+
new TypeResolver('page', () => new Page())
171+
]
172+
}
111173
```
174+
175+
> Version <7.0.0
176+
177+
``` javascript
112178
import { TypeResolver, ContentItem } from '@kentico/kontent-delivery';
113179

114180
class Page extends ContentItem {

src/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Vue from 'vue'
22
import { resolve } from 'path'
33
import { Module, Plugin } from '@nuxt/types'
4-
import { ContentItem, DeliveryClient, IDeliveryClientConfig, MultipleItemQuery } from '@kentico/kontent-delivery'
4+
import { IDeliveryClientConfig } from '@kentico/kontent-delivery'
55
import defu from 'defu'
66
import { logger } from './utilties/logger'
77
import chalk from 'chalk'
@@ -21,16 +21,14 @@ export interface ModuleOptions extends RequireOne<IDeliveryClientConfig, 'projec
2121
const deliveryClientModule: Module<IDeliveryClientConfig> = function (moduleOptions) {
2222
const options = defu<ModuleOptions, IDeliveryClientConfig>(this.options.kenticokontent, moduleOptions)
2323

24-
console.log("Module is initializing...")
25-
2624
if (!options.projectId) {
2725
logger.error(`You need to provide ${chalk.yellow('projectId')} to set up Kentico Kontent. See 👉 https://github.com/Domitnator/kentico-kontent-nuxt-module for more info.`)
2826
return
2927
}
3028

3129
const runtimeDir = resolve(__dirname, 'runtime')
3230
this.nuxt.options.alias['~deliveryclientruntime'] = runtimeDir
33-
this.nuxt.options.build.transpile.push(runtimeDir, 'kentico-kontent-nuxt-module-ts')
31+
this.nuxt.options.build.transpile.push(runtimeDir, 'kentico-kontent-nuxt-module')
3432

3533
// Add configuration plugin
3634
this.addPlugin({
@@ -42,32 +40,34 @@ const deliveryClientModule: Module<IDeliveryClientConfig> = function (moduleOpti
4240
// Add plugin
4341
this.addPlugin({
4442
src: resolve(__dirname, './runtime/plugin.template.js'),
45-
fileName: 'deliveryclient/kentico-kontent-nuxt-module-ts.js',
43+
fileName: 'deliveryclient/kentico-kontent-nuxt-module.js',
4644
options
4745
})
4846
}
4947

5048
declare module '@nuxt/types' {
5149
interface Context {
52-
$deliveryclient: NuxtDeliveryClient;
50+
$deliveryclient: NuxtDeliveryClient
5351
}
5452

5553
interface NuxtAppOptions {
56-
$deliveryclient: NuxtDeliveryClient;
54+
$deliveryclient: NuxtDeliveryClient
5755
}
5856

5957
interface Configuration {
60-
deliveryclient?: IDeliveryClientConfig;
58+
deliveryclient?: IDeliveryClientConfig
6159
}
6260
}
6361

6462
declare module 'vue/types/vue' {
6563
interface Vue {
66-
$deliveryclient: NuxtDeliveryClient
64+
$deliveryclient: NuxtDeliveryClient;
6765
}
6866
}
6967

70-
const meta = require('../package.json')
68+
export { NuxtDeliveryClient }
69+
70+
export default deliveryClientModule
7171

72-
export { NuxtDeliveryClient, deliveryClientModule as default, meta };
72+
export const meta = require('../package.json')
7373

src/runtime/plugin.template.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { Plugin } from '@nuxt/types'
2-
import { DeliveryClient, ContentItem, MultipleItemQuery } from "@kentico/kontent-delivery"
32
import { NuxtDeliveryClient } from '~deliveryclientruntime/NuxtDeliveryClient'
4-
// import CacheService from "~deliveryclientruntime/cacheService"
53

64
// Default configuration
75
let config = {
86
kenticokontent: {
9-
projectId: ''
7+
projectId: '',
8+
globalQueryConfig: {}
109
}
1110
}
1211

@@ -40,11 +39,27 @@ declare module 'vuex/types/index' {
4039
}
4140

4241
const deliveryClientPlugin: Plugin = (context, inject) => {
43-
console.log('Initializing plugin')
44-
console.log('configuration:', config)
42+
var kcSourceHeader = { header: 'X-KC-SOURCE', value: 'kentico-kontent-nuxt-module' };
4543

44+
if(config.kenticokontent.globalQueryConfig){
45+
config.kenticokontent.globalQueryConfig = Object.assign({}, config.kenticokontent.globalQueryConfig, {
46+
customHeaders: [
47+
kcSourceHeader
48+
]
49+
});
50+
}
51+
else{
52+
config.kenticokontent = Object.assign({}, config.kenticokontent, {
53+
globalQueryConfig: {
54+
customHeaders: [
55+
kcSourceHeader
56+
]
57+
}
58+
});
59+
}
60+
4661
const deliveryClient = new NuxtDeliveryClient(config.kenticokontent);
47-
62+
4863
inject('deliveryclient', deliveryClient)
4964
}
5065

0 commit comments

Comments
 (0)