Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
dc-extensions-sdk
Advanced tools
[![Build Status](https://travis-ci.org/amplience/dc-extensions-sdk.svg?branch=master)](https://travis-ci.org/amplience/dc-extensions-sdk) [![npm version](https://badge.fury.io/js/dc-extensions-sdk.svg)](https://badge.fury.io/js/dc-extensions-sdk)
An SDK that enables the creation of Extensions for Dynamic Content. Extensions are custom form controls that can be used in the content editing form in the Dynamic Content App.
Using npm:
npm install dc-extensions-sdk --save
Using yarn:
yarn add dc-extensions-sdk
Using cdn:
<script src="https://unpkg.com/dc-extensions-sdk@^2"></script>
import { init } from 'dc-extensions-sdk';
async function initialize() {
const sdk = await init();
}
initialize();
or
const dcExtensionsSdk = require('dc-extensions-sdk');
async function initialize() {
const sdk = await dcExtensionsSdk.init();
}
initialize();
import { init } from 'dc-extensions-sdk';
import type { ContentFieldExtension } from 'dc-extensions-sdk';
// define the input field model
interface FieldModel {
title: string;
type: string;
control: string;
format: string;
minLength: number;
maxLength: number;
}
// define the installation config parameters
interface Parameters {
instance: {};
installation: {
configParam: string;
};
}
async function initialize() {
const sdk = await init<ContentFieldExtension<FieldModel, Parameters>>();
}
initialize();
import { init } from 'dc-extensions-sdk';
import type { DashboardExtension } from 'dc-extensions-sdk';
// define the installation config parameters
interface Parameters {
instance: {};
installation: {
configParam: string;
};
}
async function initialize() {
const sdk = await init<DashboardExtension<Parameters>>();
}
initialize();
import { init } from 'dc-extensions-sdk';
import type { ContentEditorExtension } from 'dc-extensions-sdk';
// define the installation config parameters
interface Parameters {
installation: {
configParam: string;
};
}
async function initialize() {
const sdk = await init<ContentEditorExtension<Parameters>>();
}
initialize();
You can configure your extension with the options object passed into the init function.
import { init } from 'dc-extensions-sdk';
const options = {
// enable useful behind-the-scenes info
debug: false,
// the max time to wait for a connection to establish
connectionTimeout: 4500,
};
async function initialize() {
const sdk = await init(options);
//..
}
initialize();
const fieldValue = await sdk.field.getValue();
console.log(fieldValue);
Note: The field model isn't updated when the form is in a read only state.
const sdk = await init();
await sdk.field.setValue('some value');
This will reset to the previously saved state or undefined
if the item hasn't been saved.
const sdk = await init();
await sdk.field.resetValue();
const sdk = await init();
const schema = sdk.field.schema;
Will evaluate the supplied model against the schema. Returns a boolean.
const sdk = await init();
const isValid = await sdk.field.isValid('some value');
Will evaluate the supplied model against the schema. Will either return an array of errors or undefined
.
const sdk = await init();
const errors = await sdk.field.validate('some value');
Use to fetch the Content Item that is currently being edited.
const sdk = await init();
const contentItem = await sdk.contentItem.getCurrent();
Example Content Item:
{
"id": "4801f662-de68-43d3-8864-52d2d9c10bf4",
"deliveryId": "4801f662-de68-43d3-8864-52d2d9c10bf4",
"locale": "en-GB",
"body": {
"_meta": {
"name": "hello-world",
"schema": "http://www.hello-world.com"
},
"helloWorld": "Test"
},
"label": "Hello World",
"version": 8
}
Use to get assets.
const sdk await init();
const asset = await sdk.assets.getById('123-456-789');
Example asset:
{
"srcName": "an-image.jpg",
"revisionNumber": 8,
"bucketID": "00000000-0000-0000-0000-000000000000",
"label": "an-image.jpg",
"mimeType": "image/jpeg",
"type": "image",
"userID": "00000000-0000-0000-0000-000000000000",
"thumbFile": "00000000-0000-0000-0000-000000000000",
"folderID": "00000000-0000-0000-0000-000000000000",
"file": "00000000-0000-0000-0000-000000000000",
"createdDate": 1683798022161,
"name": "an-image",
"subType": null,
"id": "00000000-0000-0000-0000-000000000000",
"thumbURL": "https://thumbs.amplience.net/r/00000000-0000-0000-0000-000000000000",
"publishStatus": "PUBLISHED",
"status": "active",
"timestamp": 1688563779803
}
This changes the height of the extension. It will measure the height of the application and change the container's height to fit. You can also force a height by specifying an integer value.
const sdk = await init();
sdk.frame.setHeight(); // measures height
sdk.frame.setHeight(300); // override height
While the application's height will be automatically set on load, your application's size might change over time. When this happens you can either trigger sdk.frame.setHeight();
or use the Auto Resizer.
The Auto Resizer will listen for any change to the DOM as well as window resizing. When it is triggered it will automatically resize the container’s height to the size of the extension.
NOTE: If your application dynamically loads images we suggest you attach a load event listener that will trigger sdk.frame.setHeight();
const sdk = await init();
// turn on the Auto Resizer
sdk.frame.startAutoResizer();
// turn off the Auto Resizer
sdk.frame.stopAutoResizer();
The available locales for the Content Item.
const sdk = await init();
const locales = sdk.locales;
console.log(locales);
Example:
{
"default": ["en-GB", "fr-FR"],
"available": [
{
"locale": "en-GB",
"language": "en",
"country": "GB",
"index": 0,
"selected": true
},
{
"locale": "fr-FR",
"language": "fr",
"country": "FR",
"index": 1,
"selected": false
}
]
}
These allow your component to be configurable. They can be defined in the JSON Schema (instance) or defined in the registry (installation), or both.
const sdk = await init();
console.log(sdk.params);
{
instance: {},
installation: {}
}
Use this to trigger an image or video browser.
const sdk = await init();
const image = await sdk.mediaLink.getImage();
const video = await sdk.mediaLink.getVideo();
Use this to trigger an content-item browser for including content-links. Include a list of schemas to browse for.
const sdk = await init();
const contentLink = await sdk.contentLink.get(['http://my.schema/carousel.json']);
Use this to trigger an content-item browser for including content references. Include a list of schemas to browse for.
const sdk = await init();
const contentReference = await sdk.contentReference.get(['http://my.schema/carousel.json']);
Use this to fetch the in-progress form model. This can change while the extension is open.
const sdk = await init();
const formModel = await sdk.form.getValue();
In some contexts in the form content is not editable and we provide a boolean value that specifies if content should not be editable if you want to react to these changes we give you a function to do so.
Note: The field model isn't updated when the form is in a read only state.
const input = document.querySelector('input');
const sdk = await init();
// the state is set on load of the form
console.log(sdk.form.readOnly);
sdk.form.onReadOnlyChange((readOnly) => {
if (readOnly) {
input.setAttribute('disabled', true);
} else {
input.removeAttribute('disabled');
}
});
The ApplicationNavigator
is exposed on the Dashboard
extension under the property applicationNavigator
.
For each of the open commands you can supply an additional options argument if you wish to only return the href. This maybe useful if you need to set the href directly on an anchor within your extension.
const sdk = await init();
const href = sdk.applicationNavigator.openEventsCalendar({ returnHref: true });
const anchor = window.document.getElementById('my-anchor');
anchor.setAttribute('href', href);
const sdk = await init();
sdk.applicationNavigator.openEventsCalendar();
const sdk = await init();
sdk.applicationNavigator.openEventsTimeline();
const sdk = await init();
sdk.applicationNavigator.openEventsList();
const sdk = await init();
sdk.applicationNavigator.openEvent({ id: 'EVENT_ID...' });
const sdk = await init();
sdk.applicationNavigator.openEdition({ id: 'EDITION_ID...', eventId: 'EVENT_ID...' });
const sdk = await init();
sdk.applicationNavigator.openContentLibrary();
const sdk = await init();
sdk.applicationNavigator.openContentItem({ id: 'CONTENT_ITEM_ID...' });
Fetching will give you the current model of the content item you're viewing.
const sdk = await init();
const model = await sdk.form.getValue();
Setting the model will return Error Report if there is any invalid content
const sdk = await init();
try {
await sdk.form.setValue({ title: 'hello world' });
} catch (errors) {
if (errors.length) {
console.log(errors);
}
}
You can validate an object against the schema and get the full error report back
const sdk = await init();
const errors = await sdk.form.validate({
title: 'hello world',
});
if (errors) {
console.log(errors);
}
Example:
[
{
errorCategory: 'DATA',
errorData: {
keyword: 'maxLength',
params: {
limit: 10,
},
},
errorSeverity: 'FATAL',
errorType: 'DATA_VALIDATION_ERROR',
message: 'should NOT be longer than 10 characters',
schema: {
id: 'https://simple-text.com',
originalId: 'https://simple-text.com',
location: {
pointer: '/properties/title/maxLength',
},
},
data: {
location: {
pointer: '/title',
},
},
},
];
A boolean value is returned showing whether the content is valid
const sdk = await init();
const isValid = await sdk.form.isValid({
title: 'hello world',
});
console.log(isValid); // false
For syncing your model with Dynamic Content on content changes outside the extension e.g delivery key change
const sdk = await init();
sdk.form.onModelChange((errors, model) => {
setErrors(errors);
setModel(model);
});
returns a unsubscribe function to unsubscribe call back
const unsubscribe = sdk.form.onModelChange((errors, model) => {
setErrors(errors);
setModel(model);
});
unsubscribe();
import { init } from 'dc-extensions-sdk';
import { DynamicContent } from 'dc-management-sdk-js';
const dcExtension = await init();
const dcManagement = new DynamicContent({}, {}, dcExtension.client);
const hubs = await dcManagement.hubs.list();
import { init } from 'dc-extensions-sdk';
const dcExtension = await init();
const users = await dcExtension.users.list();
console.log(users);
Example:
[
{
id: '7078e5e7-d5bf-4015-4832-b75fb6f60537',
firstName: 'Test',
lastName: 'User',
email: 'testuser@bigcontent.io',
}
]
2.4.0 (2024-05-15)
FAQs
[![Build Status](https://travis-ci.org/amplience/dc-extensions-sdk.svg?branch=master)](https://travis-ci.org/amplience/dc-extensions-sdk) [![npm version](https://badge.fury.io/js/dc-extensions-sdk.svg)](https://badge.fury.io/js/dc-extensions-sdk)
We found that dc-extensions-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 13 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.