Class: ContentDeliveryClient

Class: ContentDeliveryClient

ContentDeliveryClient

Client object to interact with content published in Oracle Content Management:
  • Read the published content items
  • Render published content using named content layouts

Constructor

new ContentDeliveryClient(args) → {ContentDeliveryClient}

Parameters:
Name Type Description
args ClientParameters A JavaScript object containing the parameters to create the content delivery client instance.
Returns:
Type
ContentDeliveryClient

Methods

expandMacros(fieldValue) → {string}

Expand Content Macros.
Content item fields can contain macros that reference other content items. For example, a Rich Text field can have links to digital assets.
If a field that you want to render can contain macros, you can use this utility function to expand the macros. Expand macros are supported in Large Text fields, which work with rich text, but not in Text fields, which contain plain text. This method supports expanding the macro CEC_DIGITAL_ASSET into a rendition URL for a digital asset. If the asset GUID is followed by ",true" then the URL will be a download URL.

Parameters:
Name Type Description
fieldValue string A field value that may contain macros.
Returns:
The "fieldValue" string with all macros expanded.
Type
string
Examples
// embed an image asset:
contentClient.expandMacros(
'<img src="[!--$CEC_DIGITAL_ASSET--]CONTABC123[/!--$CEC_DIGITAL_ASSET--]"/>');
// A download link:
contentClient.expandMacros(
'<a href="[!--$CEC_DIGITAL_ASSET--]CONTABC123,true[/!--$CEC_DIGITAL_ASSET--]">Download</a>');

getInfo() → {ContentInfo}

Retrieves the values stored as part of the client object and used on each call.
Once created, these values are immutable for the client instance.
Returns:
The information the SDK is using to retrieve content from Oracle Content Management.
Type
ContentInfo
Example
// get the information on the server and the state used by calls to this client
console.log(contentClient.getInfo());

getItem(args) → {Promise}

Get a single item given its ID or SLUG.
The ID can be found in the search results.
Parameters:
Name Type Description
args object A JavaScript object containing the "getItem" parameters.
Properties
Name Type Attributes Description
id string <optional>
The ID of the content item to return.
The ID or SLUG must be specified.
slug string <optional>
The SLUG of the content item to return, used instead of id.
The ID or SLUG must be specified.
language string <optional>
The language locale variant of the content item to return.
version string <optional>
The version of the asset to return. Should only be used when calling getItem in a preview, not a delivery context. Ignored if language is specified
beforeSend function <optional>
A callback passing in the xhr (browser) or options (node) object before making the REST call.
Returns:
A JavaScript Promise object that can be used to retrieve the data after the call has completed.
Type
Promise
Example
// Getting item by ID
contentPromise = contentClient.getItem({
    'id': contentId
});


// Getting item by SLUG
contentPromise = contentClient.getItem({
    'slug': contentSlug
});

// handle the result
contentPromise.then(
    function (result) {
        console.log(result);
    },
    function (error) {
        console.log(error);
    }
);

getItems(args) → {Promise}

Get a list of items based on their IDs.
Parameters:
Name Type Description
args object A JavaScript object containing the "getItems" parameters.
Properties
Name Type Attributes Default Description
ids array <optional>
[] Restrict results to the list of requested items.
language string The language locale variant of the content items to return.
beforeSend function <optional>
A callback passing in the xhr (browser) or options (node) object before making the REST call.
fields string <optional>
'ALL' Any additional properties in the "args" object will be added to the query string parameters; for example, "fields".
Returns:
A JavaScript Promise object that can be used to retrieve the data after the call has completed.
Type
Promise
Examples
// get all items
contentClient.getItems().then(function (items) {
    console.log(items);
});
// get all items and order by type and name
contentClient.getItems().then(function (data) {
    // sort by type and then by name
    console.log(data.items.sort(function (a, b) {
        if (a.type.localeCompare(b.type) !== 0) {
            return a.type.localeCompare(b.type);
        } else {
            return a.name.localeCompare(b.name);
        }
    }));
});

getLayoutInfo(args) → {Promise}

Retrieve metadata information about the content layout.
Note: This method isn't supported if the Content Delivery SDK is used in NodeJS.
Parameters:
Name Type Description
args object A JavaScript object containing the "getLayoutInfo" parameters.
Properties
Name Type Description
layout string Name of the layout in the component catalog for Oracle Content Management.
Returns:
JavaScript Promise object that is resolved when the metadata for the layout is retrieved.
Type
Promise
Example
// get the Content REST API versions supported by the content layout
contentClient.getLayoutInfo({
    'layout': contentLayout
}).then(
    function (layoutInfo) {
        // determine the content versions supported by the layout
        console.log('Content versions supported: ' + layoutInfo.contentVersion)
    },
    function (error) {
        console.log('Error getting data: ' + error);
    }
);

getRenditionURL(args) → {string}

Get the native URL to render an image asset.
Parameters:
Name Type Description
args object A JavaScript object containing the "getRenditionURL" parameters.
Properties
Name Type Attributes Default Description
id string The ID of the image asset. One of 'id' or 'slug' must be provided for the function to return a URL.
slug string The slug of the image asset. One of 'id' or 'slug' must be provided for the function to return a URL.
type string <optional>
'native' The name of the desired rendition
format string <optional>
The desired format. Required for non-native renditions but ignored for native. For image assets the value should be 'jpg' or 'webp'.
download boolean <optional>
Pass true to add &download=true or false for &download=false. This flag will force a content-disposition of 'attachment' or 'inline'. If unspecified, the content server will choose a disposition based on the type of asset.
Returns:
A fully qualified URL to the published image asset.
Type
string
Examples
//get the native rendition URL for this client
contentClient.getRenditionURL({
    id: 'CONTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA1'
});
 
//get the Thumbnail rendition URL for an image in JPEG format
contentClient.getRenditionURL({
    id: 'CONTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA1',
    type: 'Thumbnail',
    format: 'jpg'
});
 
//get the native rendition URL, to be rendered inline
contentClient.getRenditionURL({
    id: 'CONTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA1',
    download: false
});
 
//get the native rendition URL by slug, to be rendered inline
contentClient.getRenditionURL({
    slug: 'pageBanner,
    download: false
});

getTaxonomies(params) → {Promise}

Get taxonomies for the channel.
All arguments are passed through to the Content Delivery REST API call.
Parameters:
Name Type Description
params object A JavaScript object containing the "getTaxonomies" parameters.
Returns:
A JavaScript Promise object that can be used to retrieve the data after the call has completed.
Type
Promise
Example
// get all taxonomies
client.getTaxonomies().then(function (topLevelItem) {
     console.log(topLevelItem);
     return topLevelItem;
}, function (xhr, status, error) {
     console.log(xhr.responseText);
});

loadContentLayout(args) → {Promise}

Require in the requested content layout Note: This method isn't supported if the Content Delivery SDK is used in NodeJS.
Parameters:
Name Type Description
args object A JavaScript object containing the "renderItem" parameters.
Properties
Name Type Description
layout string Name of the layout to use to render the component.
Returns:
JavaScript Promise object that is resolved when the layout JavaScript is loaded
Type
Promise

queryItems(args) → {Promise}

Get a list of items based on SCIM search criteria.
All arguments are passed through to the Content Delivery REST API call.
Parameters:
Name Type Description
args object A JavaScript object containing the "queryItems" parameters.
Properties
Name Type Attributes Default Description
q string <optional>
'' An SCIM query string to restrict results.
fields string <optional>
'' A list of fields to include for each item returned.
offset number <optional>
Return results starting at this number in the results.
limit number <optional>
Limit the number of items returned.
orderBy array | string <optional>
[] The order by which results should be returned.
beforeSend function <optional>
A callback passing in the xhr (browser) or options (node) object before making the REST call.
Returns:
A JavaScript Promise object that can be used to retrieve the data after the call has completed.
Type
Promise
Example
// get all items and order by type and name
contentClient.queryItems({
    'q': '(type eq "' + contentType + '")',
    'fields': 'ALL'
}).then(function (items) {
    console.log(items);
});

queryTaxonomyCategories(args) → {Promise}

Get categories for the specified taxonomy.
All arguments are passed through to the Content Delivery REST API call.
Parameters:
Name Type Description
args object A JavaScript object containing the "queryTaxonomyCategories" parameters.
Properties
Name Type Description
id string The ID of the taxonomy.
Returns:
A JavaScript Promise object that can be used to retrieve the data after the call has completed.
Type
Promise
Example
// get all categories for a taxonomy
client.queryTaxonomyCategories({
     'id': taxonomyId,
     'q': '(name eq "' + categoryName + '")',
}).then(function (topLevelItem) {
     console.log(topLevelItem);
     return topLevelItem;
});

renderItem(args) → {Promise}

Render the given data or content item using the named layout in the given container.
Note: This method isn't supported if the Content Delivery SDK is used in NodeJS.
Parameters:
Name Type Description
args object A JavaScript object containing the "renderItem" parameters.
Properties
Name Type Description
data object JSON data to use to render.
layout string Name of the layout to use to render the component.
container DOMElement Container DOMElement to append to.
Returns:
JavaScript Promise object that is resolved when the layout is loaded and rendered into the container.
Type
Promise
Examples
// render the item into the DOM element with a custom content layout expecting data
compatible with Oracle Content Management Sites
contentClient.getItem({
    'id': contentId
}).then(
    function (contentItemData) {
        // now the data is retrieved, render the layout
        contentClient.renderItem({
            'data': {
                contentItemData: contentItemData,
                scsData {
                    contentClient: contentClient
                }
            },
            'layout': contentLayout,
            'container': document.getElementById(containerDivId)
        }).then(
            function () {
                // render complete
                console.log('layout added to the page');
            },
            function (error) {
                console.log('error rendering layout onto the page: ' + JSON.stringify(error));
            }
        );
    },
    function (error) {
        console.log('Error getting data: ' + error);
    }
);
// render the item into the DOM element with a custom content layout expecting custom data
contentClient.getItem({
    'id': contentId
}).then(
    function (data) {
        // now the data is retrieved, render the layout
        contentClient.renderItem({
            'data': data,
            'layout': contentLayout,
            'container': document.getElementById(containerDivId)
        }).then(
            function () {
                // render complete
                console.log('layout added to the page');
            },
            function (error) {
                console.log('error rendering layout onto the page: ' + JSON.stringify(error));
            }
        );
    },
    function (error) {
        console.log('Error getting data: ' + error);
    }
);