3.1.0 • Published 6 years ago

kentico-cloud-delivery-typescript-sdk v3.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

Kentico Cloud Delivery JavaScript / TypeScript SDK

npm version Build Status npm Forums Coverage Status Known Vulnerabilities

A client library for retrieving content from Kentico Cloud that supports JavaScript and TypeScript.

Node.js support

Visit GitHub repository to see how you can use this SDK in Node.js environment.

Quick start

npm i kentico-cloud-delivery-typescript-sdk --save

TypeScript (ES6)

import { ContentItem, Fields,TypeResolver,DeliveryClient,DeliveryClientConfig } from 'kentico-cloud-delivery-typescript-sdk';

/**
 * This is optional, but it is considered a best practice to define your models
 * so you can leverage intellisense and so that you can extend your models with 
 * additional properties / methods.
 */
export class Movie extends ContentItem {
  public title: Fields.TextField;
}

/**
 * Type resolvers make sure instance of proper class is created for your content types.
 * If you don't use any custom models, return an empty array.
 */
let typeResolvers: TypeResolver[] = [
    new TypeResolver('movie', () => new Movie()),
];

/**
 * Create new instance of Delivery Client
 */
var deliveryClient = new DeliveryClient(
  new DeliveryClientConfig('projectId', typeResolvers)
);

/**
 * Get typed data from Cloud (note that the 'Movie' has to be registered in your type resolvers)
 */
deliveryClient.items<Movie>()
  .type('movie')
  .get()
  .subscribe(response => {
    console.log(response);
    // you can access strongly types properties
    console.log(response.items[0].title.text);
});

/**
 * Get data without having custom models 
 */
deliveryClient.items<ContentItem>()
  .type('movie')
  .get()
  .subscribe(response => {
    console.log(response);
    // you can access properties same way as with strongly typed models, but note
    // that you don't get any intellisense and the underlying object 
    // instance is of 'ContentItem' type
    console.log(response.items[0].title.text);
});

JavaScript (CommonJS)

var KenticoCloud = require('kentico-cloud-delivery-typescript-sdk');

/**
 * This is optional, but it is considered a best practice to define your models
 * so that you can leverage intellisense and extend your models with 
 * additional methods.
 */
class Movie extends KenticoCloud.ContentItem {
    constructor() {
        super();
    }
}

/**
 * Type resolvers make sure instance of proper class is created for your content types.
 * If you don't use any custom classes, return an empty array.
 */
var typeResolvers = [
    new KenticoCloud.TypeResolver('movie', () => new Movie()),
];

/**
 * Delivery client configuration object
 */
var config = new KenticoCloud.DeliveryClientConfig(projectId, typeResolvers);

/**
 * Create new instance of Delivery Client
 */
var deliveryClient = new KenticoCloud.DeliveryClient(config);

/**
 * Fetch all items of 'movie' type and given parameters from Kentico Cloud.
 * Important note: SDK will convert items to your type if you registered it. For example,
 * in this case the objects will be of 'Movie' type we defined above. 
 * If you don't use custom models, 'ContentItem' object instances will be returned.
 */
deliveryClient.items()
    .type('movie')
    .get()
    .subscribe(response => console.log(response));

Testing

Note: You need to have Firefox installed in order to run tests via Karma.

  • Use npm test to run all tests.
  • Use npm run dev-test to run developer tests created in dev-test folder. Use this for your testing purposes.

Scripts

  • Use npm run build to generate definitions & dist from the contents of lib folder.
  • Use npm run coveralls to push coverage data directly to https://coveralls.io. Can be executed only after runningnpm test.
  • Use update-sdk-info to run update SDK information by looking into package.json & writing it to a specialized file. This is picked up by delivery clients and used for identifying current SDK & version in request headers.

Publishing

In order to publish SDK first run one of following tasks to increase version & update sdk info file:

  • npm run new-patch
  • npm run new-minor
  • npm run new-major

And then run (note that tests and necessary scripts are automatically executed using the prepublishOnly script):

  • npm run publish

Feedback & Contribution

Feedback & Contributions are welcomed. Feel free to take/start an issue & submit PR.

4.0.0-beta.7

6 years ago

4.0.0-beta.6

6 years ago

4.0.0-beta.5

6 years ago

4.0.0-beta.4

6 years ago

4.0.0-beta.3

6 years ago

4.0.0-beta.2

6 years ago

4.0.0-beta.1

6 years ago

3.1.0

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.7.8

6 years ago

2.7.7

6 years ago

2.7.6

6 years ago

2.7.5

6 years ago

2.7.4

6 years ago

2.7.3

6 years ago

2.7.2

6 years ago

2.7.1

6 years ago

2.7.0

6 years ago

2.6.2

6 years ago

2.6.1

6 years ago

2.6.0

6 years ago

2.5.3

6 years ago

2.5.2

6 years ago

2.5.1

6 years ago

2.5.0

6 years ago

2.4.2

6 years ago

2.4.1

6 years ago

2.4.0

6 years ago

2.3.7

6 years ago

2.3.6

6 years ago

2.3.5

6 years ago

2.3.4

6 years ago

2.3.3

6 years ago

2.3.2

6 years ago

2.3.1

6 years ago

2.3.0

6 years ago

2.2.3

6 years ago

2.2.2

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.2

6 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.7.0

7 years ago

1.6.0

7 years ago

1.5.12

7 years ago

1.5.11

7 years ago

1.5.10

7 years ago

1.5.9

7 years ago

1.5.8

7 years ago

1.5.6

7 years ago

1.5.5

7 years ago

1.5.4

7 years ago

1.5.3

7 years ago

1.5.2

7 years ago

1.5.1

7 years ago

1.5.0

7 years ago

1.4.0

7 years ago

1.3.5

7 years ago

1.3.4

7 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.5

7 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago