Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@agility/content-fetch",
"version": "0.4.5",
"version": "0.4.6",
"description": "JavaScript library for the Agility Fetch API (node and browser)",
"main": "dist/agility-content-fetch.node.js",
"scripts": {
Expand Down
10 changes: 9 additions & 1 deletion src/api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import getSitemapNested from './methods/getSitemapNested'
import getContentItem from './methods/getContentItem'
import getContentList from './methods/getContentList'
import getPage from './methods/getPage'
import FilterOperators from './types/FilterOperator'
import FilterLogicOperators from './types/FilterLogicOperator'
import SortDirections from './types/SortDirection'

const defaultConfig = {
baseUrl: null,
Expand Down Expand Up @@ -73,7 +76,12 @@ export default function createClient(userConfig) {
getSitemapNested: getSitemapNested,
getContentItem: getContentItem,
getContentList: getContentList,
getPage: getPage
getPage: getPage,
types: {
FilterOperators: FilterOperators,
FilterLogicOperators: FilterLogicOperators,
SortDirections: SortDirections
}
}

}
26 changes: 22 additions & 4 deletions src/methods/getContentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {buildPathUrl, buildRequestUrlPath, buildAuthHeader } from '../utils'
* @param {number} [requestParams.take] - The maximum number of items to retrieve in this request. Default is **10**. Maximum allowed is **50**.
* @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.created*.
* @param {string} [requestParams.direction] - The direction to sort the results by. Default is **asc**. Valid values are **asc**, **desc**.
* @param {Array} [requestParams.filters] - The collection of filters to filter the results by. A filter object contains properties called **property**, **operator**, **value**. Operators can be **eq** Equal To, **ne** Not Equal To, **gt** Greater Than, **gte** Greater Than or Equal To, **lt * @param {Array} [requestParams.filters] - The collection of filters to filter the results by. A filter object contains properties called **property**, **operator**, **value**. Operators can be **eq** Equal To, **ne** Not Equal To, **gt** Greater Than, **gte** Greater Than or Equal To, **lt** Less Than, **lte** Less Than or Equal To, **like** Like (string only)
* @param (string) [requestParams.filtersLogicOperator] - The logic operator to combine multiple filters. **AND** (default), **OR**.
* @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
*
Expand All @@ -28,7 +28,25 @@ import {buildPathUrl, buildRequestUrlPath, buildAuthHeader } from '../utils'
* take: 50,
* skip: 0,
* sort: 'properties.created',
* direction: 'asc'
* direction: api.types.SortDirections.ASC
* })
* .then(function(contentList) {
* console.log(contentList);
* })
* .catch(function(error) {
* console.log(error);
* });
*
* api.getContentList({
* referenceName: 'posts',
* languageCode: 'en-us',
* take: 50,
* skip: 0,
* filters: [
* {property: 'properties.versionID', operator: api.types.FilterOperators.EQUAL_TO, value: '40'},
* {property: 'properties.referenceName', operator: api.types.FilterOperators.LIKE, value: 'posts'}
* ],
* filtersLogicOperator: api.types.FilterLogicOperators.OR
* })
* .then(function(contentList) {
* console.log(contentList);
Expand Down
13 changes: 13 additions & 0 deletions src/types/Filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Defines a **Filter** for filtering lists.
* @typedef Filter
* @memberof AgilityFetch.Types
* @property {string} property - The property to filter the request on.
* @property {AgilityFetch.Types.FilterOperator} operator - The operator to use for the filter.
* @property {string} value - The value to compare for the property.
*/





21 changes: 21 additions & 0 deletions src/types/FilterLogicOperator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Defines a FilterLogicOperator - Refer to {@link AgilityFetch.Types.FilterLogicOperators} Enum for available Logic Operators.
* @typedef {string} FilterLogicOperator
* @memberOf AgilityFetch.Types
*/

/**
* Enum of FilterLogicOperators.
* @enum {FilterLogicOperator} FilterLogicOperators
* @memberOf AgilityFetch.Types
* @default AND
* @readonly
*/
const FilterLogicOperators = {
/** And */
AND: "and",
/** Or */
OR: "or"
};

export default FilterLogicOperators;
30 changes: 30 additions & 0 deletions src/types/FilterOperator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Defines a FilterOperator - Refer to {@link AgilityFetch.Types.FilterOperators} Enum for available Operators.
* @typedef {string} FilterOperator
* @memberOf AgilityFetch.Types
*/

/**
* Enum of FilterOperators.
* @enum {FilterOperator} FilterOperators
* @memberOf AgilityFetch.Types
* @readonly
*/
const FilterOperators = {
/** Equal To */
EQUAL_TO: "eq",
/** Not Equal To */
NOT_EQUAL_TO: "ne",
/** Less Than */
LESS_THAN: "lt",
/** Less Than or Equal To */
LESS_THAN_OR_EQUAL_TO: "lte",
/** Greater Than */
GREATER_THAN: "gt",
/** Greater Than or Equal To */
GREATER_THAN_OR_EQUAL_TO: "gte",
/** Like (string only) */
LIKE: "like"
};

export default FilterOperators;
21 changes: 21 additions & 0 deletions src/types/SortDirection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Defines a Sort Direction - Refer to {@link AgilityFetch.Types.SortDirections} Enum for available Sort Directions.
* @typedef {string} SortDirection
* @memberOf AgilityFetch.Types
*/

/**
* Enum of SortDirections.
* @enum {SortDirection} SortDirections
* @memberOf AgilityFetch.Types
* @default ASC
* @readonly
*/
const SortDirections = {
/** Ascending */
ASC: "asc",
/** Descending */
DESC: "desc",
};

export default SortDirections;
13 changes: 6 additions & 7 deletions test/getContentList.tests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import chai from 'chai'
const assert = chai.assert;
const expect = chai.expect;

import { createApiClient, createPreviewApiClient, createCatchedApiClient } from './apiClients.config'

/*
Expand Down Expand Up @@ -190,7 +189,7 @@ describe('getContentList:', function() {
referenceName: 'posts',
languageCode: 'en-us',
sort: 'properties.versionID',
direction: 'desc'
direction: api.types.SortDirections.DESC
})
.then(function(contentList) {
assert.strictEqual(contentList.items[0].contentID, 16);
Expand All @@ -206,7 +205,7 @@ describe('getContentList:', function() {
api.getContentList({
referenceName: 'posts',
languageCode: 'en-us',
filters: [{operator: 'eq', value: '40'}]
filters: [{operator: api.types.FilterOperators.EQUAL_TO, value: '40'}]
})
.then(function(contentList) {
done();
Expand Down Expand Up @@ -238,7 +237,7 @@ describe('getContentList:', function() {
api.getContentList({
referenceName: 'posts',
languageCode: 'en-us',
filters: [{property: 'properties.versionID', operator: 'eq'}]
filters: [{property: 'properties.versionID', operator: api.types.FilterOperators.EQUAL_TO}]
})
.then(function(contentList) {
done();
Expand Down Expand Up @@ -285,8 +284,8 @@ describe('getContentList:', function() {
api.getContentList({
referenceName: 'posts',
languageCode: 'en-us',
filters: [{property: 'properties.versionID', operator: 'eq', value: '40'}, {property: 'properties.referenceName', operator: 'like', value: 'posts'}],
filtersLogicOperator: 'OR'
filters: [{property: 'properties.versionID', operator: api.types.FilterOperators.EQUAL_TO, value: '40'}, {property: 'properties.referenceName', operator: api.types.FilterOperators.LIKE, value: 'posts'}],
filtersLogicOperator: api.types.FilterLogicOperators.OR
})
.then(function(contentList) {
assert.strictEqual(contentList.items[0].contentID, 15);
Expand All @@ -301,7 +300,7 @@ describe('getContentList:', function() {
api.getContentList({
referenceName: 'posts',
languageCode: 'en-us',
filters: [{property: 'properties.versionID', operator: 'eq', value: '40'}, {property: 'properties.referenceName', operator: 'like', value: 'posts'}]
filters: [{property: 'properties.versionID', operator: api.types.FilterOperators.EQUAL_TO, value: '40'}, {property: 'properties.referenceName', operator: api.types.FilterOperators.LIKE, value: 'posts'}]
})
.then(function(contentList) {
assert.strictEqual(contentList.items[0].contentID, 16);
Expand Down