Socket
Socket
Sign inDemoInstall

contentful-management

Package Overview
Dependencies
Maintainers
4
Versions
578
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

contentful-management - npm Package Compare versions

Comparing version 1.3.0 to 1.3.1

29

dist/contentful-management.js

@@ -39,22 +39,13 @@ 'use strict';

/**
* Create a client instance
* @func
* @name createClient
* @memberof contentfulManagement
* @param {object} params - Client initialization parameters
* @prop {string} params.accessToken - Contentful CDA Access Token
* @prop {boolean=} params.insecure - Requests will be made over http instead of the default https (default: false)
* @prop {string=} params.host - API host (default: cda.contentful.com)
* @prop {object=} params.agent - Optional Node.js HTTP agent for proxying (see <a href="https://nodejs.org/api/http.html#http_class_http_agent">Node.js docs</a> and <a href="https://www.npmjs.com/package/https-proxy-agent">https-proxy-agent</a>)
* @prop {object=} params.headers - Optional additional headers
* @prop {number=} params.concurrency - Number of allowed concurrent requests. Changing this value is not recommended. (default: 6)
* @prop {number=} params.delay - Delay in milliseconds for waiting after hitting the allowed number of concurrent requests. Changing this value is not recommended. (default: 1000)
* @prop {number=} params.maxRetries - Maximum number of retries when a 429 is received (default: 5)
* @prop {boolean=} params.retryOnTooManyRequests - If we should retry on 429s (default: true)
* @returns {ContentfulClientAPI.ClientAPI}
* @typedef {ContentfulManagement} ContentfulManagement
* @property {function(params: {accessToken: string, insecure?: boolean, host?: string, agent?: Object, headers?: Object, concurrency?: number, delay?: number, maxRetries?: number, retryOnTooManyRequests?: boolean}): ClientAPI} createClient - Create a client instance, this is the entry point to the library
*
* @example
* const client = contentfulManagement.createClient({
* accessToken: 'myAccessToken'
* })
*/
* // require contentful-management
* var contentfulManagement = require('contentful-management')
* var client = contentfulManagement.createClient({
* // This is the access token for this space. Normally you get both ID and the token in the Contentful web app
* accessToken: 'YOUR_ACCESS_TOKEN'
* })
*/
function createClient(axios, params) {

@@ -61,0 +52,0 @@ params = (0, _defaults2.default)((0, _cloneDeep2.default)(params), {

@@ -19,2 +19,9 @@ 'use strict';

/**
* @typedef {ClientAPI} ClientAPI
* @property {function(id: string): Promise<Space>} getSpace - Gets a space with the spcified id
* @property {function(): Promise<SpaceCollection>} getSpaces - Gets a collection of spaces
* @property {function(data: {name: string}): Promise<Space>} createSpace - Creates a space
*/
/**
* Creates API object with methods to access functionality from Contentful's

@@ -28,42 +35,2 @@ * Management API

*/
/**
* Contentful Management API Client. Contains methods which allow access to
* any operations that can be performed with a management token.
* @namespace ContentfulClientAPI
*/
/**
* Types for meta information found across the different entities in Contentful
* @namespace Meta
*/
/**
* System metadata. See <a href="https://www.contentful.com/developers/docs/references/content-delivery-api/#/introduction/common-resource-attributes">Common Resource Attributes</a> for more details.
* @memberof Meta
* @typedef Sys
* @prop {string} type
* @prop {string} id
* @prop {Meta.Link} space
* @prop {string} createdAt
* @prop {string} updatedAt
* @prop {number} revision
*/
/**
* Link to another entity. See <a href="https://www.contentful.com/developers/docs/concepts/links/">Links</a> for more details.
* @memberof Meta
* @typedef Link
* @prop {string} type - type of this entity. Always link.
* @prop {string} id
* @prop {string} linkType - type of this link. If defined, either Entry or Asset
*/
/**
* @memberof ContentfulClientAPI
* @typedef {Object} ClientAPI
* @prop {function} getSpace
* @prop {function} getSpaces
* @prop {function} createSpace
*/
function createSpaceApi(_ref) {

@@ -77,4 +44,3 @@ var http = _ref.http;

* Gets all spaces
* @memberof ContentfulClientAPI
* @return {Promise<Space.SpaceCollection>} Promise for a collection of Spaces
* @memberof ClientAPI * @return {Promise<Space.SpaceCollection>} Promise for a collection of Spaces
* @example

@@ -93,3 +59,3 @@ * client.getSpaces()

* Gets a space
* @memberof ContentfulClientAPI
* @memberof ClientAPI
* @param {string} id - Space ID

@@ -109,3 +75,3 @@ * @return {Promise<Space.Space>} Promise for a Space

* Creates a space
* @memberof ContentfulClientAPI
* @memberof ClientAPI
* @see {Space.Space}

@@ -112,0 +78,0 @@ * @param {object} data - Object representation of the Space to be created

@@ -27,43 +27,199 @@ 'use strict';

/**
* @memberof ContentfulSpaceAPI
* @typedef {Object} ContentfulSpaceAPI
* @prop {function} delete
* @prop {function} update
* @prop {function} getContentType
* @prop {function} getContentTypes
* @prop {function} createContentType
* @prop {function} createContentTypeWithId
* @prop {function} getEntry
* @prop {function} getEntries
* @prop {function} createEntry
* @prop {function} createEntryWithId
* @prop {function} getAsset
* @prop {function} getAssets
* @prop {function} createAsset
* @prop {function} createAssetWithId
* @prop {function} getLocale
* @prop {function} getLocales
* @prop {function} createLocale
* @prop {function} getWebhook
* @prop {function} getWebhooks
* @prop {function} createWebhook
* @prop {function} createWebhookWithId
* @prop {function} getRole
* @prop {function} getRoles
* @prop {function} createRole
* @prop {function} createRoleWithId
* @prop {function} getSpaceMembership
* @prop {function} getSpaceMemberships
* @prop {function} createSpaceMembership
* @prop {function} createSpaceMembershipWithId
* @prop {function} getApiKey
* @prop {function} getApiKeys
* @prop {function} createApiKey
* @prop {function} createApiKeyWithId
* @typedef {Space} Space
* @property {Object} sys - System metadata
* @property {string} sys.id - Space id
* @property {string} sys.type - Entity type
* @property {string} name - Space name
* @property {function(): Promise} delete - Deletes the space
* @property {function(): Promise<Space>} update - Updates the space
* @property {function(id: string): Promise<ContentType>} getContentType - Get a contentType by id
* @property {function(): Promise<ContentTypeCollection>} getContentTypes - Gets a collection of contentTypes
* @property {function(data:{name: string, fields: Array}): Promise<ContentType>} createContentType - creates a ContentType
* @property {function(id: string, data: {name: string, fields: Array}): Promise<ContentType>} createContentTypeWithId - creates a ContentType with a specified id
* @property {function(id: string): Promise<Entry>} getEntry - Gets an Entry with a custom id
* @property {function(query:Object): Promise<EntryCollection>} getEntries - Gets a collection of entries
* @property {function(contentTypeId: string, data: {fields: Object}): Promise<Entry>} createEntry - Creates an Entry
* @property {function(contentTypeId: string, id: string, data: {fields: Object}): Promise<Entry>} createEntryWithId - Creates an Entry with a specified id
* @property {function(id: string, query: Object): Promise<Asset>} getAsset - Gets an asset by id
* @property {function(query: Object): Promise<AssetCollection>} getAssets - Gets a collection of assets
* @property {function(data: {fields: Object}): Promise<Asset>} createAsset - Creates an asset
* @property {function(id: string, data: {fields: Object}):Promise<Asset>} createAssetWithId - Creates an asset with the custom id
* @property {function(): Promise<Locale>} getLocale - Gets a locale
* @property {function(): Promise<LocaleCollection>} getLocales - Gets a collection of locales
* @property {function(data:{name: string, code: string}): Promise<Locale>} createLocale - Creates a Locale
* @property {function(id:string): Promise<webhook>} getWebhook - Gets a webhook
* @property {function(): Promise<WebhookCollection>} getWebhooks - Gets a collection of webhooks
* @property {function(data: Object): Promise<Webhook>} createWebhook - Creates a webhook
* @property {function(id: string, data: Object)} createWebhookWithId - Creates a webhook with a custom id
* @property {function(id: string): Promise<Role>} getRole - Gets a Role
* @property {function(): Promise<RoleCollection>} getRoles - Gets a collection of roles
* @property {function(data: Object): Promise<Role>} createRole - Creates a role
* @property {function(id: string, data: Object): Promise<Role>} createRoleWithId - Creates a Role with a custom id
* @property {function(id: string): Promise<SpaceMembership>} getSpaceMembership - Gets a space membership
* @property {function(): Promise<SpaceMembershipCollection>} getSpaceMemberships - Gets a space memnerships collection
* @property {function(data: Object): Promise<SpaceMembership>} createSpaceMembership - Creates a space membership
* @property {function(id: string, data: Object): Promise<SpaceMembership>} createSpaceMembershipWithId - Creates a space membership with a custom id
* @property {function(id: string): Promise<ApiKey>} getApiKey - Gets an api key
* @property {function(): Promise<ApiKeyCollection>} getApiKeys - Gets a collection of api keys
* @property {function(data: Object): Promise<ApiKey>} createApiKey - Creates an api key
* @property {function(id: string, data: Object): Promise<ApiKey>} createSpaceApi.createApiKeyWithId - Creates an api key with a custom id
* @property {function(): Object} toPlainObject - Returns this Space as a plain JS object
* @example
* // require contentful-management
* var contentfulManagement = require('contentful-management')
* var client = contentfulManagement.createClient({
* // This is the access token for this space. Normally you get both ID and the token in the Contentful web app
* accessToken: 'YOUR_ACCESS_TOKEN'
* })
*
* //================================================================================================
* // To get a space object you have two options:
* //
* // 1. by creating a new space
* //
* // var space = await client.createSpace({name: "My new space"})
* //
* // OR
* //
* // 2. Get an existing one by id
* //
* // var space = await client.getSpace('SPACE_ID')
* //================================================================================================
*
* // We'll pick option 2.
* //
* // A space object will be like so
* // {
* // "sys": {
* // "type": "Space",
* // "id": "cfexampleapi",
* // "version": 3,
* // "createdAt": "2015-05-18T11:29:46.809Z",
* // "createdBy": {
* // "sys": {
* // "type": "Link",
* // "linkType": "User",
* // "id": "4FLrUHftHW3v2BLi9fzfjU"
* // }
* // },
* // "updatedAt": "2015-05-18T11:29:46.809Z",
* // "updatedBy": {
* // "sys": {
* // "type": "Link",
* // "linkType": "User",
* // "id": "4FLrUHftHW3v2BLi9fzfjU"
* // }
* // }
* // },
* // "name": "Contentful Example API"
* // }
* var space = await client.getSpace('cfexampleapi')
*
* // Example Deleting a space
* space.delete()
* .catch(err => console.log(err))
*
* // Example updating a space
* space.name = 'Updated Space Name'
* space.update()
* .then(space => console.log(space.name) // `Updated Space Name`)
*
* // Example getting a contentType
* space.getContentType('contentTypeId')
* .then(contentType => console.log(contentType)) // @see {ContentType}
*
* // Example getting an editorInterface for a contentType
* // an editorInterface is a set of configuration that defines how a field look like
* // example singleLine, etc...
* space.getEditorInterfaceForContentType('contentTypeId')
* .then(editorInterface => console.log(editorInterface))
*
* // Example creating a contentType
* space.createContentType({name: 'Post', fields: []})
* .then(ct => console.log(ct))
*
* // Example Creating a contentType with a custom id
* space.createContentTypeWithId('post', {name: 'Post', fields: []})
* .then(ct => console.log(ct))
*
* // Example getting all entries form a space where contentType is `contentTypeId`
* // you can add more query params along with the content_type key, like 'limit':'1000', 'order':'sys.createdAt' and more
* // for more infos about the query check https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters
* space.getEntries({content_type: 'contentTypeId'})
* .then(entries => console.log(entries.items))
*
* // Example Creating an entry with a localized title field
* // you can fill in all the fields defined in the contentType with the id 'contentTypeId'
* // so if you have another field of type text for example called description, you can add 'description' in the fields object
* // that will be sent to the server
* space.createEntry('contentTypeId', {
* fields: {
* title: {
* 'en-US': 'english content',
* 'de-DE': 'german content'
* }
* }
* })
* .then(e => console.log(e))
*
* // Example getting an entry by id
* space.getEntry('entryId')
* .then(entity => console.log(entry))
*
* // Example getting assets
* space.getAssets()
* .then(response => console.log(response.items))
*
* // Example getting an asset
* space.getAsset('assetId')
* .then(asset => console.log(asset)) // @see {Asset}
*
* // Example creating an asset
* // After creation, call asset.processForLocale or asset.processForAllLocales to start asset processing.
* // After processing the upload property name will be replace by 'url'
* // if you want to create an asset with a custom id please use the space.createAssetWithId('id', data)
* space.createAsset(
* fields: {
* file: {
* 'en-US': {
* contentType: 'image/jpeg',
* fileName: 'filename_english.jpg',
* upload: 'http://example.com/filename_original_en.jpg'
* },
* 'de-DE': {
* contentType: 'image/jpeg',
* fileName: 'filename_german.jpg',
* upload: 'http://example.com/filename_original_de.jpg'
* }
* }
* }
* )
* .then(asset => asset.processForAllLocales())
*/
/**
* @typedef {SpaceCollection} SpaceCollection
* @property {number} total - Total amount of records in the server
* @property {number} skip - A starting point of the collection
* @property {number} limit - Amount of records in collection
* @property {Array<Space>} items - An array of spaces
* @property {function(): Object} toPlainObject - Returns this Space collection as a plain JS object
* @example
* // require contentful-management
* var contentfulManagement = require('contentful-management')
* var client = contentfulManagement.createClient({
* // This is the access token for this space. Normally you get both ID and the token in the Contentful web app
* accessToken: 'YOUR_ACCESS_TOKEN'
* })
*
* client.getSpaces()
* .then((spaceCollection) => {
* console.log(spaceCollection.items) // list of spaces @see {Space}
* })
*/
/**
* Creates API object with methods to access the Space API
* @private
* @param {Object} params - API initialization params
* @param {http: Object} params - API initialization params
* @prop {Object} http - HTTP client instance

@@ -73,8 +229,2 @@ * @prop {Object} entities - Object with wrapper methods for each kind of entity

*/
/**
* Contentful Space API. Contains methods to access any operations at a space
* level, such as creating and reading entities contained in a space.
* @namespace ContentfulSpaceAPI
*/
function createSpaceApi(_ref) {

@@ -133,6 +283,2 @@ var http = _ref.http;

* @return {Promise<Space.Space>} Promise for the updated space.
* @example
* space.name = 'Updated Space Name'
* space.update()
* .then(space => console.log(space))
*/

@@ -157,4 +303,2 @@ function updateSpace() {

* @example
* space.getContentType('contentTypeId')
* .then(contentType => console.log(contentType))
*/

@@ -202,3 +346,3 @@ function getContentType(id) {

* @memberof ContentfulSpaceAPI
* @see {ContentType.ContentType}
* @see {ContentType}
* @param {object} data - Object representation of the Content Type to be created

@@ -217,3 +361,3 @@ * @return {Promise<ContentType.ContentType>} Promise for the newly created Content Type

/**
* Creates a Content Type with a specific id
* Creates a Content Type with a custom id
* @memberof ContentfulSpaceAPI

@@ -304,3 +448,3 @@ * @see {ContentType.ContentType}

/**
* Creates a Entry with a specific id
* Creates a Entry with a custom id
* @memberof ContentfulSpaceAPI

@@ -406,3 +550,3 @@ * @see {Entry.Entry}

/**
* Creates a Asset with a specific id. After creation, call asset.processForLocale or asset.processForAllLocales to start asset processing.
* Creates a Asset with a custom id. After creation, call asset.processForLocale or asset.processForAllLocales to start asset processing.
* @memberof ContentfulSpaceAPI

@@ -529,3 +673,3 @@ * @see {Asset.Asset}

/**
* Creates a Webhook with a specific id
* Creates a Webhook with a custom id
* @memberof ContentfulSpaceAPI

@@ -592,3 +736,3 @@ * @see {Webhook.Webhook}

/**
* Creates a Space Membership with a specific id
* Creates a Space Membership with a custom id
* @memberof ContentfulSpaceAPI

@@ -655,3 +799,3 @@ * @see {SpaceMembership.SpaceMembership}

/**
* Creates a Role with a specific id
* Creates a Role with a custom id
* @memberof ContentfulSpaceAPI

@@ -718,3 +862,3 @@ * @see {Role.Role}

/**
* Creates a Api Key with a specific id
* Creates a Api Key with a custom id
* @memberof ContentfulSpaceAPI

@@ -721,0 +865,0 @@ * @see {ApiKey.ApiKey}

@@ -30,23 +30,72 @@ 'use strict';

/**
* @memberof ApiKey
* @typedef ApiKey
* @prop {Meta.Sys} sys - System metadata
* @prop {string} name
* @prop {string} description
* @prop {function(): Object} toPlainObject() - Returns this Api Key as a plain JS object
* @typedef {ApiKey} ApiKey
* @property {Object} sys - System metadata
* @property {string} name
* @property {string} description
* @property {function(): Promise<ApiKey>} update() - Sends an update to the server with any changes made to the object's properties
* @property {function(): Promise} delete() - Deletes this object on the server
* @property {function(): Object} toPlainObject - Returns this Api Key as a plain JS object
* @example
*
* // require contentful-management
* var contentfulManagement = require('contentful-management')
* var client = contentfulManagement.createClient({
* // This is the access token for this space. Normally you get both ID and the token in the Contentful web app
* accessToken: 'YOUR_ACCESS_TOKEN'
* })
*
* var space = await client.getSpace('SPACE_ID')
*
* //=======================================================================================================
* // You can get an ApiKey object by
* //
* // 1. Creating one
* //
* // var apiKey = await space.createApiKey({})
* //
* // OR
* //
* // 2. Get an existing one
* //
* // var apiKey = await space.getApiKey('API_KEY_ID')
* //=======================================================================================================
*
* // we'll use option 2
* var apiKey = await space.getApiKey('API_KEY_ID')
*
* // Example updating an APIKey
* apiKey.name = 'New name'
* apiKey.update()
* .then(apiKey => console.log(apiKey.name))
*
* // Example deleting an ApiKey
* apiKey.delete()
* .catch(err => console.log(err))
*
*/
/**
* @typedef {ApiKeyCollection} ApiKeyCollection
* @property {number} total - Total amount of records in the server
* @property {number} skip - A starting point of the collection
* @property {number} limit - Amount of records in collection
* @property {ApiKey[]} items - Array of ApiKey
* @property {function(): Object} toPlainObject - Returns this Api Key collection as a plain JS object
* @example
*
* // require contentful-management
* var contentfulManagement = require('contentful-management')
* var client = contentfulManagement.createClient({
* // This is the access token for this space. Normally you get both ID and the token in the Contentful web app
* accessToken: 'YOUR_ACCESS_TOKEN'
* })
*
* var space = await client.getSpace('SPACE_ID')
*
* //get all the api keys
* space.getApiKeys()
* .then(apiKeys => console.log(apiKeys.items))
*/
function createApiKeyApi(http) {
return {
/**
* Sends an update to the server with any changes made to the object's properties
* @memberof ApiKey
* @func update
* @return {Promise<ApiKey>} Object returned from the server with updated changes.
* @example
* apiKey.name = 'New name'
* apiKey.update()
* .then(apiKey => console.log(apiKey.name))
*/
update: (0, _instanceActions.createUpdateEntity)({

@@ -58,11 +107,2 @@ http: http,

/**
* Deletes this object on the server.
* @memberof ApiKey
* @func delete
* @return {Promise} Promise for the deletion. It contains no data, but the Promise error case should be handled.
* @example
* apiKey.delete()
* .catch(err => console.log(err))
*/
delete: (0, _instanceActions.createDeleteEntity)({

@@ -81,6 +121,2 @@ http: http,

*/
/**
* Api Key instances
* @namespace ApiKey
*/
function wrapApiKey(http, data) {

@@ -93,12 +129,2 @@ var apiKey = (0, _toPlainObject2.default)((0, _cloneDeep2.default)(data));

/**
* @memberof ApiKey
* @typedef ApiKeyCollection
* @prop {number} total
* @prop {number} skip
* @prop {number} limit
* @prop {Array<ApiKey.ApiKey>} items
* @prop {function(): Object} toPlainObject() - Returns this Api Key collection as a plain JS object
*/
/**
* @private

@@ -105,0 +131,0 @@ * @param {Object} http - HTTP client instance

@@ -42,6 +42,2 @@ 'use strict';

/**
* Asset instances
* @namespace Asset
*/
var ASSET_PROCESSING_CHECK_WAIT = 500;

@@ -51,18 +47,114 @@ var ASSET_PROCESSING_CHECK_RETRIES = 5;

/**
* @memberof Asset
* @typedef Asset
* @prop {Meta.Sys} sys - Standard system metadata with additional asset specific properties
* @prop {string=} sys.locale - If present, indicates the locale which this asset uses
* @prop {Object} fields - Object with content for each field
* @prop {string} fields.title - Title for this asset
* @prop {string} fields.description - Description for this asset
* @prop {Object} fields.file - File object for this asset
* @prop {Object} fields.file.fileName - Name for the file
* @prop {string} fields.file.contentType - Mime type for the file
* @prop {string=} fields.file.upload - Url where the file is available to be downloaded from, into the Contentful asset system. After the asset is processed this field is gone.
* @prop {string=} fields.file.url - Url where the file is available at the Contentful media asset system. This field won't be available until the asset is processed.
* @prop {Object} fields.file.details - Details for the file, depending on file type (example: image size in bytes, etc)
* @prop {function(): Object} toPlainObject() - Returns this Asset as a plain JS object
* @typedef {Asset} Asset
* @property {Object} sys - Standard system metadata with additional asset specific properties
* @property {string} sys.locale - If present, indicates the locale which this asset uses
* @property {Object} fields - Object with content for each field
* @property {string} fields.title - Title for this asset
* @property {string} fields.description - Description for this asset
* @property {Object} fields.file - File object for this asset
* @property {Object} fields.file.fileName - Name for the file
* @property {string} fields.file.contentType - Mime type for the file
* @property {string} fields.file.upload - Url where the file is available to be downloaded from, into the Contentful asset system. After the asset is processed this field is gone.
* @property {string} fields.file.url - Url where the file is available at the Contentful media asset system. This field won't be available until the asset is processed.
* @property {Object} fields.file.details - Details for the file, depending on file type (example: image size in bytes, etc)
* @property {boolean} isPublished - checks if the asset is published. A published asset might have unpublished changes (@see {Asset.isUpdated})
* @property {boolean} isUpdated - Checks if the asset is updated. This means the asset was previously published but has unpublished changes.
* @property {boolean} isArchived - Checks if asset is archived. This means it's not exposed to the Delivery/Preview APIs.
* @property {boolean} isDraft - Checks if the asset is in draft mode. This means it is not published.
* @property {function(): Promise<Asset>} update - Updates an asset
* @property {function(): Promise<Asset>} delete - Deletes an asset
* @property {function(): Promise<Asset>} publish - publish an asset
* @property {function(): Promise<Asset>} unPublish - unPublish an asset
* @property {function(): Promise<Asset>} archive - archive an asset
* @property {function(): Promise<Asset>} unArchive - unArchive an asset
* @property {function(locale: string, options: {processingCheckWait: number, processingCheckRetries: number}): Promise<Asset>} processForLocale - Triggers asset processing after an upload, for the file uploaded to a specific locale.
* @property {function(options: {processingCheckWait: number, processingCheckRetries: number}): Promise<Asset>} processForAllLocales - Triggers asset processing after an upload, for the files uploaded to all locales of an asset.
* @property {function(): Object} toPlainObject - Returns this Asset as a plain JS object
* @example
*
* // require contentful-management
* var contentfulManagement = require('contentful-management')
* var client = contentfulManagement.createClient({
* // This is the access token for this space. Normally you get both ID and the token in the Contentful web app
* accessToken: 'YOUR_ACCESS_TOKEN'
* })
*
* var space = await client.getSpace('SPACE_ID')
* var asset = await space.getAsset('ASSET_ID')
*
* // Example Creating an asset
* var createdAsset = await space.createAsset(
* fields: {
* file: {
* 'en-US': {
* contentType: 'image/jpeg',
* fileName: 'filename_english.jpg',
* upload: 'http://example.com/filename_original_en.jpg'
* },
* 'de-DE': {
* contentType: 'image/jpeg',
* fileName: 'filename_german.jpg',
* upload: 'http://example.com/filename_original_de.jpg'
* }
* }
* }
* )
*
* // Example Updating an asset
* asset.fields.title = 'My new Title'
* asset.update()
* .then(asset => console.log(asset.fields.name['en-US']))
*
* // Process an asset for a specific locale
* asset.processForLocale('en-US')
* .then(asset => console.log(asset.fields.file['en-US'].url))
*
* // Process Asset for all locales
* asset.processForAllLocales()
* .then(asset => console.log(asset.fields.file['en-US'].url, asset.fields.file['de-DE'].url))
*
* // Publish an asset
* asset.publish()
* .then(asset => console.log(asset.sys.publishedVersion))
*
* // Delete an asset
* asset.delete()
* .catch(err => console.log(err))
*
* // unPublish an asset
* asset.unpublish()
* .then(asset => console.log(asset.sys))
*
* // archive an asset
* asset.archive()
* .then(asset => console.log(asset.sys.archivedVersion))
*
* // unarchive an asset
* asset.unarchive()
* .then(asset => console.log(asset.sys))
*/
/**
* @typedef {AssetCollection} AssetCollection
* @property {number} total - Total amount of records in the server
* @property {number} skip - A starting point of the collection
* @property {number} limit - Amount of records in collection
* @property {Asset[]} items - an array of assets
* @property {function(): Object} toPlainObject - Returns this Asset collection as a plain JS object
* @example
*
* // require contentful-management
* var contentfulManagement = require('contentful-management')
* var client = contentfulManagement.createClient({
* // This is the access token for this space. Normally you get both ID and the token in the Contentful web app
* accessToken: 'YOUR_ACCESS_TOKEN'
* })
*
* let space = await client.getSpace('SPACE_ID')
* let assetCollection = await space.getAssets()
* console.log("the space contains ", assetCollection.items.length, " assets")
* assetCollection.items.forEach((asset) => {
* // do something with asset @link {Asset}
* })
*/
function createAssetApi(http) {

@@ -151,5 +243,2 @@ function checkIfAssetHasUrl(_ref) {

* @example
* contentType.fields.name['en-US'] = 'Blog Post'
* asset.update()
* .then(asset => console.log(asset.fields.name['en-US']))
*/

@@ -168,4 +257,2 @@ update: (0, _instanceActions.createUpdateEntity)({

* @example
* asset.delete()
* .catch(err => console.log(err))
*/

@@ -183,4 +270,2 @@ delete: (0, _instanceActions.createDeleteEntity)({

* @example
* asset.publish()
* .then(asset => console.log(asset.sys.publishedVersion))
*/

@@ -199,4 +284,2 @@ publish: (0, _instanceActions.createPublishEntity)({

* @example
* asset.unpublish()
* .then(asset => console.log(asset.sys))
*/

@@ -215,4 +298,2 @@ unpublish: (0, _instanceActions.createUnpublishEntity)({

* @example
* asset.archive()
* .then(asset => console.log(asset.sys.archivedVersion))
*/

@@ -231,4 +312,2 @@ archive: (0, _instanceActions.createArchiveEntity)({

* @example
* asset.unarchive()
* .then(asset => console.log(asset.sys))
*/

@@ -252,4 +331,2 @@ unarchive: (0, _instanceActions.createUnarchiveEntity)({

* @example
* asset.processForLocale('en-US')
* .then(asset => console.log(asset.fields.file['en-US'].url))
*/

@@ -320,12 +397,2 @@ processForLocale: processForLocale,

/**
* @memberof Asset
* @typedef AssetCollection
* @prop {number} total
* @prop {number} skip
* @prop {number} limit
* @prop {Array<Asset.Asset>} items
* @prop {function(): Object} toPlainObject() - Returns this Asset collection as a plain JS object
*/
/**
* @private

@@ -332,0 +399,0 @@ * @param {Object} http - HTTP client instance

@@ -36,12 +36,63 @@ 'use strict';

/**
* @memberof ContentType
* @typedef ContentType
* @prop {Meta.Sys} sys - System metadata
* @prop {string} name
* @prop {string} description
* @prop {string} displayField - Field used as the main display field for Entries
* @prop {Array<Field>} fields - All the fields contained in this Content Type
* @prop {function(): Object} toPlainObject() - Returns this Content Type as a plain JS object
* @typedef {ContentType} ContentType
* @property {Object} sys - System metadata
* @property {string} name - name of the contentType
* @property {string} description - description of the contentType
* @property {string} displayField - Field used as the main display field for Entries
* @property {Array<Field>} fields - All the fields contained in this Content Type
* @property {function(): Object} toPlainObject() - Returns this Content Type as a plain JS object
* @example
* // require contentful-management
* var contentfulManagement = require('contentful-management')
* var client = contentfulManagement.createClient({
* // This is the access token for this space. Normally you get both ID and the token in the Contentful web app
* accessToken: 'YOUR_ACCESS_TOKEN'
* })
*
* //=======================================================================================================
* // You can get an Entry object by
* //
* // 1. Creating one
* //
* // var contentType = await space.createContentType({name: 'Post', fields: []})
* //
* // OR
* //
* // 2. Get an existing one
* //
* // var contentType = await space.getContentType('contentTypeId')
* //=======================================================================================================
*
* // Example updating a ContentType
* contentType.name = 'New name'
* contentType.update()
* .then(contentType => console.log(contentType.name))
*
* //Example deleting a content type
* contentType.delete()
* .catch(err => console.log(err))
*/
/**
* @typedef {ContentTypeCollection} ContentTypeCollection
* @property {number} total - Total amount of records in the server
* @property {number} skip - A starting point of the collection
* @property {number} limit - Amount of records in collection
* @property {ContentType[]} items - An array of contentTypes
* @property {function(): Object} toPlainObject - Returns this Content Type collection as a plain JS object
* @example
*
* // require contentful-management
* var contentfulManagement = require('contentful-management')
* var client = contentfulManagement.createClient({
* // This is the access token for this space. Normally you get both ID and the token in the Contentful web app
* accessToken: 'YOUR_ACCESS_TOKEN'
* })
*
* var space = await client.getSpace('SPACE_ID')
* //Example getting contentTypes
* space.getContentTypes()
* .then(contentTypes => console.log(contentTypes.items))
*/
function createContentTypeApi(http) {

@@ -158,6 +209,2 @@ return {

*/
/**
* Content Type instances
* @namespace ContentType
*/
function wrapContentType(http, data) {

@@ -170,12 +217,2 @@ var contentType = (0, _toPlainObject2.default)((0, _cloneDeep2.default)(data));

/**
* @memberof ContentType
* @typedef ContentTypeCollection
* @prop {number} total
* @prop {number} skip
* @prop {number} limit
* @prop {Array<ContentType.ContentType>} items
* @prop {function(): Object} toPlainObject() - Returns this Content Type collection as a plain JS object
*/
/**
* @private

@@ -182,0 +219,0 @@ * @param {Object} http - HTTP client instance

@@ -35,5 +35,52 @@ 'use strict';

/**
* Editor Interface instances
* @namespace EditorInterface
* @typedef {Control} Control
* @property {string} widgetId - defines how the field will look like e.g. singleLine
* @property {string} fieldId - id of the field that this control is affecting
* @property {Object} settings - settings for the widget
*/
/**
* @typedef {EditorInterface} EditorInterface
* @property {Object} sys - System metadata
* @property {Control[]} controls - List of settings per field
* @property {function(): Promise<EditorInterface>} update - Sends an update to the server with any changes made to the object's properties
* @property {function(): Control} getControlForField - Gets a control for a specific field
* @property {function(): Object} toPlainObject() - Returns this Content Type as a plain JS object
* @example
*
* // require contentful-management
* var contentfulManagement = require('contentful-management')
* var client = contentfulManagement.createClient({
* // This is the access token for this space. Normally you get both ID and the token in the Contentful web app
* accessToken: 'YOUR_ACCESS_TOKEN'
* })
*
* // request our space from Contentful
* var space = await client.getSpace('SPACE_ID')
*
* //=======================================================================================================
* // web can get an editor interface in two ways
* // 1. request our ContentType from Contentful
* //
* // var contentType = await space.getContentType('CONTENT_TYPE_ID')
* //
* //1.1 Get the editorInterface through the ContentType
* //
* // var editorInterface = await contentType.getEditorInterface()
* //
* // OR
* //
* // 2. get an editor interface from the Space object right away
* //
* // var editorInterface = await space.getEditorInterfaceForContentType('CONTENT_TYPE_ID')
* //=======================================================================================================
*
* // we'll use option 2
*
* var editorInterface = await space.getEditorInterfaceForContentType('CONTENT_TYPE_ID')
*
* // Example Updating and editor interface
* editorInterface.controls[0] = { "fieldId": "title", "widgetId": "singleLine"}
* editorInterface.update()
* .then(editorInterface => console.log(editorInterface.controls))
*/

@@ -40,0 +87,0 @@ function createEditorInterfaceApi(http) {

@@ -30,66 +30,76 @@ 'use strict';

/**
* Types of fields found in an Entry
* @namespace EntryFields
* @typedef {Entry} Entry
* @property {Object} sys - Standard system metadata with additional entry specific properties
* @property {Object} sys.contentType - Content Type used by this Entry
* @property {string} sys.locale - If present, indicates the locale which this entry uses
* @property {Object} fields - Object with content for each field
* @property {boolean} isPublished - Checks if the entry is published. A published entry might have unpublished changes (@see {Entry.isUpdated})
* @property {boolean} isUpdated - Checks if the entry is updated. This means the entry was previously published but has unpublished changes.
* @property {boolean} isDraft - Checks if the entry is in draft mode. This means it is not published.
* @property {boolean} isArchived - Checks if entry is archived. This means it's not exposed to the Delivery/Preview APIs.
* @property {function(): Promise<Entry>} update - Updates an entry in the server
* @property {function(): Promise<Entry>} delete - Deletes an entry on the server
* @property {function(): Promise<Entry>} publish - Publishes an entry
* @property {function(): Promise<Entry>} unPublish - Un-publishes an entry
* @property {function(): Promise<Entry>} archive - Archives an entry
* @property {function(): Promise<Entry>} unArchive - Un-archives an entry
* @property {function(): Object} toPlainObject - Returns this Entry as a plain JS object
* @example
* // require contentful-management
* var contentfulManagement = require('contentful-management')
* var client = contentfulManagement.createClient({
* // This is the access token for this space. Normally you get both ID and the token in the Contentful web app
* accessToken: 'YOUR_ACCESS_TOKEN'
* })
*
* //=======================================================================================================
* // You can get an Entry object by
* //
* // 1. Creating one
* //
* // var entry = await space.createEntry({})
* //
* // OR
* //
* // 2. Get an existing one
* //
* // var entry = await space.getEntry('ENTRY_ID')
* //=======================================================================================================
*
* // Example updating an entry
* entry.fields.name['en-US'] = 'Blog Post'
* entry.update()
* .then(entry => console.log(entry.fields.name['en-US']))
*
* // Example deleting an entry
* entry.delete()
* .catch(err => console.log(err))
*
* // Example publish an entry
* entry.publish()
* .then(entry => console.log(entry.sys.publishedVersion))
*
* // Example unPublishing an entry
* entry.unpublish()
* .then(entry => console.log(entry.sys))
*
* // Example archiving an entry
* entry.archive()
* .then(entry => console.log(entry.sys.archivedVersion))
*
* // Example unarchiving an entry
* entry.unarchive()
* .then(entry => console.log(entry.sys))
*/
/**
* @memberof EntryFields
* @typedef Symbol
* @type string
* @typedef {EntryCollection} EntryCollection
* @property {number} total - Total amount of records in the server
* @property {number} skip - A starting point of the collection
* @property {number} limit - Amount of records in collection
* @property {Entry[]} items - array of entries
* @property {Array<Object>} errors - Array of errors that might occur when retrieving entries.
* @property {function(): Object} toPlainObject - Returns this Entry collection as a plain JS object
*/
/**
* @memberof EntryFields
* @typedef Text
* @type string
*/
/**
* @memberof EntryFields
* @typedef Integer
* @type number
*/
/**
* @memberof EntryFields
* @typedef Number
* @type number
*/
/**
* @memberof EntryFields
* @typedef Date
* @type string
*/
/**
* @memberof EntryFields
* @typedef Boolean
* @type boolean
*/
/**
* @memberof EntryFields
* @typedef Location
* @prop {string} lat - latitude
* @prop {string} lon - longitude
*/
/**
* A Field in an Entry can have one of the following types that can be defined in Contentful. See <a href="https://www.contentful.com/developers/docs/references/field-type/">Field Types</a> for more details.
* @memberof EntryFields
* @typedef Field
* @type EntryFields.Symbol | EntryFields.Text | EntryFields.Integer | EntryFields.Number | EntryFields.Date | EntryFields.Boolean | EntryFields.Location | Meta.Link | Array<EntryFields.Symbol|Meta.Link> | Object
*/
/**
* @memberof Entry
* @typedef Entry
* @prop {Meta.Sys} sys - Standard system metadata with additional entry specific properties
* @prop {Meta.Link} sys.contentType - Content Type used by this Entry
* @prop {string=} sys.locale - If present, indicates the locale which this entry uses
* @prop {Object<EntryFields.Field>} fields - Object with content for each field
* @prop {function(): Object} toPlainObject() - Returns this Entry as a plain JS object
*/
function createEntryApi(http) {

@@ -228,6 +238,2 @@ return {

*/
/**
* Entry instances
* @namespace Entry
*/
function wrapEntry(http, data) {

@@ -240,13 +246,2 @@ var entry = (0, _toPlainObject2.default)((0, _cloneDeep2.default)(data));

/**
* @memberof Entry
* @typedef EntryCollection
* @prop {number} total
* @prop {number} skip
* @prop {number} limit
* @prop {Array<Entry.Entry>} items
* @prop {Array<Object>=} errors - Array of errors that might occur when retrieving entries.
* @prop {function(): Object} toPlainObject() - Returns this Entry collection as a plain JS object
*/
/**
* Data is also mixed in with link getters if links exist and includes were requested

@@ -253,0 +248,0 @@ * @private

@@ -30,14 +30,22 @@ 'use strict';

/**
* @memberof Locale
* @typedef Locale
* @prop {Meta.Sys} sys - System metadata
* @prop {string} name
* @prop {string} code - Locale code (example: en-us)
* @prop {boolean} contentDeliveryApi - If the content under this locale should be available on the CDA (for public reading)
* @prop {boolean} contentManagementApi - If the content under this locale should be available on the CMA (for editing)
* @prop {boolean} default - If this is the default locale
* @prop {boolean} optional - If the locale needs to be filled in on entries or not
* @prop {function(): Object} toPlainObject() - Returns this Locale as a plain JS object
* @typedef {Locale} Locale
* @property {Object} sys - System metadata
* @property {string} name
* @property {string} code - Locale code (example: en-us)
* @property {boolean} contentDeliveryApi - If the content under this locale should be available on the CDA (for public reading)
* @property {boolean} contentManagementApi - If the content under this locale should be available on the CMA (for editing)
* @property {boolean} default - If this is the default locale
* @property {boolean} optional - If the locale needs to be filled in on entries or not
* @property {function(): Object} toPlainObject - Returns this Locale as a plain JS object
*/
/**
* @typedef {LocaleCollection} LocaleCollection
* @property {number} total - Total amount of records in the server
* @property {number} skip - A starting point of the collection
* @property {number} limit - Amount of records in collection
* @property {Array<Locale>} items - array of locales
* @property {function(): Object} toPlainObject - Returns this Locale collection as a plain JS object
*/
function createLocaleApi(http) {

@@ -98,12 +106,2 @@ return {

/**
* @memberof Locale
* @typedef LocaleCollection
* @prop {number} total
* @prop {number} skip
* @prop {number} limit
* @prop {Array<Locale.Locale>} items
* @prop {function(): Object} toPlainObject() - Returns this Locale collection as a plain JS object
*/
/**
* @private

@@ -110,0 +108,0 @@ * @param {Object} http - HTTP client instance

@@ -30,12 +30,22 @@ 'use strict';

/**
* See https://www.contentful.com/developers/docs/references/content-management-api/#/reference/roles/create-a-role
* @memberof Role
* @typedef Role
* @prop {Meta.Sys} sys - System metadata
* @prop {string} name
* @prop {object} permissions - Permissions for application sections
* @prop {object} policies
* @prop {function(): Object} toPlainObject() - Returns this Role as a plain JS object
* @see https://www.contentful.com/developers/docs/references/content-management-api/#/reference/roles/create-a-role
* @typedef {Role} Role
* @property {Object} sys - System metadata
* @property {string} name
* @property {Object} permissions - Permissions for application sections
* @property {Object} policies
* @property {function(): Prmise<Role>} update - Sends an update to the server with any changes made to the object's properties
* @property {function(): Prmise} delete - Deletes this object on the server.
* @property {function(): Object} toPlainObject - Returns this Role as a plain JS object
*/
/**
* @typedef {RoleCollection} RoleCollection
* @property {number} total - Total amount of records in the server
* @property {number} skip - A starting point of the collection
* @property {number} limit - Amount of records in collection
* @property {Role[]} items - an array of roles
* @property {function(): Object} toPlainObject - Returns this Role collection as a plain JS object
*/
function createRoleApi(http) {

@@ -93,12 +103,2 @@ return {

/**
* @memberof Role
* @typedef RoleCollection
* @prop {number} total
* @prop {number} skip
* @prop {number} limit
* @prop {Array<Role.Role>} items
* @prop {function(): Object} toPlainObject() - Returns this Role collection as a plain JS object
*/
/**
* @private

@@ -105,0 +105,0 @@ * @param {Object} http - HTTP client instance

@@ -30,11 +30,19 @@ 'use strict';

/**
* @memberof SpaceMembership
* @typedef SpaceMembership
* @prop {Meta.Sys} sys - System metadata
* @prop {string} name
* @prop {boolean} admin - User is an admin
* @prop {array} roles - Array of Role Links
* @prop {function(): Object} toPlainObject() - Returns this Space Membership as a plain JS object
* @typedef {SpaceMembership} SpaceMembership
* @property {Object} sys - System metadata
* @property {string} name
* @property {boolean} admin - User is an admin
* @property {Array} roles - Array of Role Links
* @property {function(): Object} toPlainObject - Returns this Space Membership as a plain JS object
*/
/**
* @typedef {SpaceMembershipCollection} SpaceMembershipCollection
* @property {number} total - Total amount of records in the server
* @property {number} skip - A starting point of the collection
* @property {number} limit - Amount of records in collection
* @property {Array<SpaceMembership.SpaceMembership>} items
* @property {function(): Object} toPlainObject() - Returns this Space Membership collection as a plain JS object
*/
function createSpaceMembershipApi(http) {

@@ -81,6 +89,2 @@ return {

*/
/**
* Space Membership instances
* @namespace SpaceMembership
*/
function wrapSpaceMembership(http, data) {

@@ -93,12 +97,2 @@ var spaceMembership = (0, _toPlainObject2.default)((0, _cloneDeep2.default)(data));

/**
* @memberof SpaceMembership
* @typedef SpaceMembershipCollection
* @prop {number} total
* @prop {number} skip
* @prop {number} limit
* @prop {Array<SpaceMembership.SpaceMembership>} items
* @prop {function(): Object} toPlainObject() - Returns this Space Membership collection as a plain JS object
*/
/**
* @private

@@ -105,0 +99,0 @@ * @param {Object} http - HTTP client instance

@@ -36,22 +36,2 @@ 'use strict';

/**
* @memberof Space
* @typedef Space
* @prop {Object} sys - System metadata
* @prop {string} sys.id - Space id
* @prop {string} sys.type - Entity type
* @prop {string} name - Space name
* @prop {function(): Object} toPlainObject() - Returns this Space as a plain JS object
*/
/**
* @memberof Space
* @typedef SpaceCollection
* @prop {number} total
* @prop {number} skip
* @prop {number} limit
* @prop {Array<Space.Space>} items
* @prop {function(): Object} toPlainObject() - Returns this Space collection as a plain JS object
*/
/**
* This method creates the API for the given space with all the methods for

@@ -58,0 +38,0 @@ * reading and creating other entities. It also passes down a clone of the

@@ -20,9 +20,7 @@ 'use strict';

/**
* Errors received from server requests
* @memberof ContentfulClientAPI
* @typedef ErrorResponse
* @prop {string} name - Error name. Usually refers to the sys.id returned on the
* @typedef {ErrorResponse} ErrorResponse
* @property {string} name - Error name. Usually refers to the sys.id returned on the
* error server response. If that's not available or is unknown, it defaults to
* the HTTP error code and status text.
* @prop {string} message - Stringified JSON object with request information,
* @property {string} message - Stringified JSON object with request information,
* HTTP response details and error details payload (if available). The `requestId`

@@ -29,0 +27,0 @@ * property is internal to Contentful and it can be used when contacting support

@@ -27,2 +27,5 @@ 'use strict';

/**
* @private
*/
function createUpdateEntity(_ref) {

@@ -46,2 +49,5 @@ var http = _ref.http,

/**
* @private
*/
function createDeleteEntity(_ref2) {

@@ -56,2 +62,5 @@ var http = _ref2.http,

/**
* @private
*/
function createPublishEntity(_ref3) {

@@ -73,2 +82,5 @@ var http = _ref3.http,

/**
* @private
*/
function createUnpublishEntity(_ref4) {

@@ -86,2 +98,5 @@ var http = _ref4.http,

/**
* @private
*/
function createArchiveEntity(_ref5) {

@@ -99,2 +114,5 @@ var http = _ref5.http,

/**
* @private
*/
function createUnarchiveEntity(_ref6) {

@@ -112,2 +130,5 @@ var http = _ref6.http,

/**
* @private
*/
function createPublishedChecker() {

@@ -119,2 +140,5 @@ return function () {

/**
* @private
*/
function createUpdatedChecker() {

@@ -128,2 +152,5 @@ return function () {

/**
* @private
*/
function createDraftChecker() {

@@ -135,2 +162,5 @@ return function () {

/**
* @private
*/
function createArchivedChecker() {

@@ -137,0 +167,0 @@ return function () {

@@ -15,3 +15,2 @@ // To understand why axios is vendored, check SETUP.md

}
module.exports = {

@@ -18,0 +17,0 @@ createClient: function (params) {

{
"name": "contentful-management",
"version": "1.3.0",
"version": "1.3.1",
"description": "Client for Contentful's Content Management API",

@@ -20,3 +20,3 @@ "homepage": "https://www.contentful.com/developers/documentation/content-management-api/",

"build:standalone": "webpack && webpack -p --output-filename contentful-management.min.js",
"docs:build": "jsdoc -r -c ./jsdoc.json dist",
"docs:build": "esdoc -c esdoc.json",
"docs:dev": "npm run build && npm run docs:build",

@@ -23,0 +23,0 @@ "docs:watch": "watchy -w lib npm run docs:dev",

@@ -1,1 +0,1 @@

module.exports = '1.3.0'
module.exports = '1.3.1'

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc