@kontent-ai/delivery-sdk
Version:
Official Kontent.AI Delivery API SDK
115 lines • 4.13 kB
JavaScript
import { HttpService } from '@kontent-ai/core-sdk';
import { ElementQuery, ItemsFeedQuery, MultipleItemsQuery, MultipleTypeQuery, SingleItemQuery, SingleTypeQuery, TaxonomiesQuery, TaxonomyQuery, LanguagesQuery, InitializeSyncQuery, SyncChangesQuery, UsedInQuery } from '../query';
import { sdkInfo } from '../sdk-info.generated';
import { MappingService, QueryService } from '../services';
export class DeliveryClient {
/**
* Delivery client used to fetch data from Kontent.ai
* @constructor
* @param {IDeliveryClientConfig} config - The client configuration
*/
constructor(config) {
this.config = config;
if (!config) {
throw Error(`Delivery client configuration is not set`);
}
this.mappingService = new MappingService(config);
this.queryService = new QueryService(config, config.httpService ? config.httpService : new HttpService(), {
host: sdkInfo.host,
name: sdkInfo.name,
version: sdkInfo.version
}, this.mappingService);
}
/**
* Gets query for multiple languages
*/
languages() {
return new LanguagesQuery(this.config, this.queryService);
}
/**
* Gets query for multiple types
*/
types() {
return new MultipleTypeQuery(this.config, this.queryService);
}
/**
* Gets query for single type
* @param {string} typeCodename - Codename of the type to fetch
*/
type(typeCodename) {
return new SingleTypeQuery(this.config, this.queryService, typeCodename);
}
/**
* Gets query for multiple items
*/
items() {
return new MultipleItemsQuery(this.config, this.queryService);
}
/**
* Gets query for single item
* @param {string} codename - Codename of item to fetch
*/
item(codename) {
return new SingleItemQuery(this.config, this.queryService, codename);
}
/**
* Gets query for items feed. Executes single HTTP request only
*/
itemsFeed() {
return new ItemsFeedQuery(this.config, this.queryService);
}
/**
* Gets query for single taxonomy
* @param {string} codename - Codename of taxonomy to fetch
*/
taxonomy(codename) {
return new TaxonomyQuery(this.config, this.queryService, codename);
}
/**
* Gets query for multiple taxonomies
*/
taxonomies() {
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
*/
element(typeCodename, elementCodename) {
return new ElementQuery(this.config, this.queryService, typeCodename, elementCodename);
}
/**
* @deprecated Sync API v1 is deprecated and will be shut down by the end of this year.
* Please migrate to Sync API v2 using the `@kontent-ai/sync-sdk` package.
*
* For migration guidance and full documentation, visit:
* https://kontent.ai/learn/docs/apis/openapi/sync-api-v2/
*/
initializeSync() {
return new InitializeSyncQuery(this.config, this.queryService);
}
/**
* @deprecated Sync API v1 is deprecated and will be shut down by the end of this year.
* Please migrate to Sync API v2 using the `@kontent-ai/sync-sdk` package.
*
* For migration guidance and full documentation, visit:
* https://kontent.ai/learn/docs/apis/openapi/sync-api-v2/
*/
syncChanges() {
return new SyncChangesQuery(this.config, this.queryService);
}
/**
* Item listing of where an asset is used
*/
assetUsedIn(assetCodename) {
return new UsedInQuery(this.config, this.queryService, { entity: 'asset', codename: assetCodename });
}
/**
* Item listing of where a content item is used
*/
itemUsedIn(itemCodename) {
return new UsedInQuery(this.config, this.queryService, { entity: 'contentItem', codename: itemCodename });
}
}
//# sourceMappingURL=delivery-client.js.map