UNPKG

@agility/content-fetch

Version:
115 lines (114 loc) 5.02 kB
import { Filter } from '../types/Filter'; import { FilterLogicOperator } from '../types/FilterLogicOperator'; import { SortDirection } from '../types/SortDirection'; import { ContentList } from '../types/ContentList'; import { ApiClientInstance } from '../types/Client'; /** * Retrieves a list of content items by reference name. * @memberof AgilityFetch.Client.Content * @param {Object} requestParams - The parameters for the API request. * @param {string} requestParams.referenceName - The unique reference name of the content list you wish to retrieve in the specified language. * @param {string} requestParams.locale - The locale code of the content you want to retrieve. * @param {string} requestParams.languageCode - DEPRECATED: Use locale instead - The language code of the content you want to retrieve. * @param {number} [requestParams.contentLinkDepth] - The depth, representing the levels in which you want linked content auto-resolved. Default is **1**. * @param {boolean} [requestParams.expandAllContentLinks] - Whether or not to expand entire linked content references, includings lists and items that are rendered in the CMS as Grid or Link. Default is **false** * @param {number} [requestParams.take] - The maximum number of items to retrieve in this request. Default is **10**. Maximum allowed is **250**. * @param {number} [requestParams.skip] - The number of items to skip from the list. Default is **0**. Used for implementing pagination. * @param {string} [requestParams.sort] - The field to sort the results by. Example **fields.title** or **properties.modified**. * @param {AgilityFetch.Types.SortDirection} [requestParams.direction] - The direction to sort the results by. * @param {Array.<AgilityFetch.Types.Filter>} [requestParams.filters] - The collection of filters to filter the results by. * @param {AgilityFetch.Types.FilterLogicOperator} [requestParams.filtersLogicOperator] - The logic operator to combine multiple filters. * @returns {Promise<AgilityFetch.Types.ContentList>} - Returns a list of content items. * @example * * import agility from '@agility/content-fetch' * * const api = agility.getApi({ * guid: 'ade6cf3c', * apiKey: 'defaultlive.201ffdd0841cacad5bb647e76547e918b0c9ecdb8b5ddb3cf92e9a79b03623cb', * }); * * api.getContentList({ * referenceName: 'posts', * locale: 'en-us', * take: 50, * skip: 0, * sort: 'properties.modified', * direction: api.types.SortDirections.ASC * }) * .then(function(contentList) { * console.log(contentList); * }) * .catch(function(error) { * console.log(error); * }); * * api.getContentList({ * referenceName: 'posts', * locale: 'en-us', * take: 50, * skip: 0, * filters: [ * {property: 'fields.title', operator: api.types.FilterOperators.EQUAL_TO, value: '"How this site works"'}, * {property: 'fields.details', operator: api.types.FilterOperators.LIKE, value: '"Lorem ipsum dolar"'} * ], * filtersLogicOperator: api.types.FilterLogicOperators.OR * }) * .then(function(contentList) { * console.log(contentList); * }) * .catch(function(error) { * console.log(error); * }); */ export interface ContentListRequestParams { /** * The unique reference name of the content list you wish to retrieve in the specified language. */ referenceName: string; /** * The locale code of the content you want to retrieve. */ locale?: string; /** * The language code of the content you want to retrieve. * DEPRECATED: Use locale instead. */ languageCode?: string; /** * The depth, representing the levels in which you want linked content auto-resolved. */ contentLinkDepth?: number; /** * Whether or not to expand entire linked content references, includings lists and items that are rendered in the CMS as Grid or Link. */ expandAllContentLinks?: boolean; /** * The number of items to retrieve in this request. Default is 10. Maximum allowed is 250. */ take?: number; /** * The number of items to skip from the list. Used for implementing pagination. */ skip?: number; /** * The field to sort the results by. Example fields.title or properties.modified. */ sort?: string; /** * The direction to sort the results by. */ direction?: SortDirection; /** * Option: you can provide a plain text filter string as opposed to an array of filters. This is useful if you have brackets in your filter expression. */ filterString?: string; /** * Provide an array of filters as opposed to a plain text filter string. * If you need advanced filering with brackets, use the filterString operator. */ filters?: Array<Filter>; filtersLogicOperator?: FilterLogicOperator; } declare function getContentList(this: ApiClientInstance, requestParams: ContentListRequestParams): Promise<ContentList>; export default getContentList;