kentico-cloud-delivery
Version:
Official Kentico Cloud Delivery SDK
77 lines • 3.31 kB
JavaScript
import { HttpService } from 'kentico-cloud-core';
import { getParserAdapter } from '../parser/parser-adapter';
import { ElementQuery, MultipleItemQuery, MultipleTypeQuery, SingleItemQuery, SingleTypeQuery, TaxonomiesQuery, TaxonomyQuery, } from '../query';
import { sdkInfo } from '../sdk-info.generated';
import { MappingService, QueryService } from '../services';
var DeliveryClient = /** @class */ (function () {
/**
* Delivery client used to fetch data from Kentico Cloud
* @constructor
* @param {IDeliveryClientConfig} config - The client configuration
*/
function DeliveryClient(config) {
this.config = config;
if (!config) {
throw Error("Delivery client configuration is not set");
}
this.mappingService = new MappingService(config, getParserAdapter());
this.queryService = new QueryService(config, config.httpService ? config.httpService : new HttpService({
requestInterceptor: config.httpInterceptors && config.httpInterceptors.requestInterceptor ? config.httpInterceptors.requestInterceptor : undefined,
responseInterceptor: config.httpInterceptors && config.httpInterceptors.responseInterceptor ? config.httpInterceptors.responseInterceptor : undefined,
}), {
host: sdkInfo.host,
name: sdkInfo.name,
version: sdkInfo.version
}, this.mappingService);
}
/**
* Gets query for multiple types
*/
DeliveryClient.prototype.types = function () {
return new MultipleTypeQuery(this.config, this.queryService);
};
/**
* Gets query for single type
* @param {string} typeCodename - Codename of the type to fetch
*/
DeliveryClient.prototype.type = function (typeCodename) {
return new SingleTypeQuery(this.config, this.queryService, typeCodename);
};
/**
* Gets query for multiple items
*/
DeliveryClient.prototype.items = function () {
return new MultipleItemQuery(this.config, this.queryService);
};
/**
* Gets query for single item
* @param {string} codename - Codename of item to fetch
*/
DeliveryClient.prototype.item = function (codename) {
return new SingleItemQuery(this.config, this.queryService, codename);
};
/**
* Gets query for single taxonomy
* @param {string} codename - Codename of taxonomy to fetch
*/
DeliveryClient.prototype.taxonomy = function (codename) {
return new TaxonomyQuery(this.config, this.queryService, codename);
};
/**
* Gets query for multiple taxonomies
*/
DeliveryClient.prototype.taxonomies = function () {
return new TaxonomiesQuery(this.config, this.queryService);
};
/**
* Gets query for an element within a type
* @param {string} typeCodename - Codename of the type
* @param {string} elementCodename - Codename of the element
*/
DeliveryClient.prototype.element = function (typeCodename, elementCodename) {
return new ElementQuery(this.config, this.queryService, typeCodename, elementCodename);
};
return DeliveryClient;
}());
export { DeliveryClient };
//# sourceMappingURL=delivery-client.js.map