Skip to content

Commit 62590f7

Browse files
fix(docs): Change to jsdoc
1 parent c69b167 commit 62590f7

18 files changed

+7651
-837
lines changed

jsdoc.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"tags": {
3+
"allowUnknownTags": true
4+
},
5+
"source": {
6+
"include": [
7+
"lib/",
8+
"./README.md"
9+
]
10+
},
11+
"opts": {
12+
"encoding": "utf8",
13+
"template": "node_modules/contentful-sdk-jsdoc/jsdoc-template",
14+
"destination": "out/",
15+
"recurse": true,
16+
"verbose": true
17+
},
18+
"templates": {
19+
"cleverLinks": false,
20+
"monospaceLinks": false,
21+
"default": {
22+
"outputSourceFiles": true,
23+
"includeDate": false
24+
}
25+
},
26+
"docdash": {
27+
"static": false,
28+
"sort": true
29+
}
30+
}

lib/contentful-management.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,28 @@ import {createHttpClient, getUserAgentHeader} from 'contentful-sdk-core'
1111
import createContentfulApi from './create-contentful-api'
1212
import version from '../version'
1313
/**
14-
* @typedef {ContentfulManagement} ContentfulManagement
15-
* @property {function(params: {accessToken: string, insecure?: boolean, host?: string, hostUpload?: string, httpAgent?: Object, httpsAgent?: Object, headers?: Object, proxy?:Object, application?: string, integration?: string}, retryOnError?: boolean): ClientAPI} createClient - Create a client instance, this is the entry point to the library
16-
*
14+
* Create a client instance
15+
* @func
16+
* @name createClient
17+
* @memberof contentfulManagement
18+
* @param {object} params - Client initialization parameters
19+
* @prop {string=} params.accessToken - Contentful CDA Access Token
20+
* @prop {boolean=?} params.insecure - Requests will be made over http instead of the default https (default: false)
21+
* @prop {boolean=?} params.retryOnError - If we should retry on errors and 429 rate limit exceptions (default: true)
22+
* @prop {string=?} params.host - API host (default: cda.contentful.com)
23+
* @prop {string=?} params.hostUpload - direct file upload host (default : upload.contentful.com)
24+
* @prop {Object=?} params.httpAgent - 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>)
25+
* @prop {Object=?} params.httpsAgent - 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>)
26+
* @prop {Object=?} params.proxy - Optional Axios proxy (see <a href="https://github.com/mzabriskie/axios#request-config"> axios docs </a>)
27+
* @prop {object=?} params.headers - Optional additional headers
28+
* @prop {string=?} params.application - Application name and version e.g myApp/version
29+
* @prop {string=?} params.integration - Integration name and version e.g react/version
30+
* @returns {ContentfulClientAPI.ClientAPI}
1731
* @example
18-
* // require contentful-management
19-
* var contentfulManagement = require('contentful-management')
20-
* var client = contentfulManagement.createClient({
21-
* // This is the access token for this space. Normally you get both ID and the token in the Contentful web app
22-
* accessToken: 'YOUR_ACCESS_TOKEN'
32+
* const client = contentfulManagement.createClient({
33+
* accessToken: 'myAccessToken'
2334
* })
24-
*/
35+
*/
2536
export function createClient (params) {
2637
const defaultParameters = {
2738
defaultHostname: 'api.contentful.com',

lib/create-contentful-api.js

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,46 @@
1-
import errorHandler from './error-handler'
2-
import entities from './entities'
1+
/**
2+
* Contentful Management API Client. Contains methods which allow access to
3+
* any operations that can be performed with a management token.
4+
* @namespace ContentfulClientAPI
5+
*/
6+
7+
/**
8+
* Types for meta information found across the different entities in Contentful
9+
* @namespace Meta
10+
*/
11+
12+
/**
13+
* 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.
14+
* @memberof Meta
15+
* @typedef Sys
16+
* @prop {string} type
17+
* @prop {string} id
18+
* @prop {Meta.Link} space
19+
* @prop {string} createdAt
20+
* @prop {string} updatedAt
21+
* @prop {number} revision
22+
*/
323

424
/**
5-
* @typedef {ClientAPI} ClientAPI
6-
* @property {function(id: string): Promise<Space>} getSpace - Gets a space with the spcified id
7-
* @property {function(): Promise<SpaceCollection>} getSpaces - Gets a collection of spaces
8-
* @property {function(data: {name: string}): Promise<Space>} createSpace - Creates a space
9-
* @property {function(): Promise<OrganizationCollection>} getOrganizations - Gets a collection of Organizations
25+
* Link to another entity. See <a href="https://www.contentful.com/developers/docs/concepts/links/">Links</a> for more details.
26+
* @memberof Meta
27+
* @typedef Link
28+
* @prop {string} type - type of this entity. Always link.
29+
* @prop {string} id
30+
* @prop {string} linkType - type of this link. If defined, either Entry or Asset
1031
*/
1132

33+
/**
34+
* @memberof ContentfulClientAPI
35+
* @typedef {Object} ClientAPI
36+
* @prop {function} getSpace
37+
* @prop {function} getSpaces
38+
* @prop {function} createSpace
39+
*/
40+
41+
import errorHandler from './error-handler'
42+
import entities from './entities'
43+
1244
/**
1345
* Creates API object with methods to access functionality from Contentful's
1446
* Management API
@@ -24,10 +56,18 @@ export default function createClientApi ({ http }) {
2456

2557
/**
2658
* Gets all spaces
27-
* @memberof ClientAPI * @return {Promise<Space.SpaceCollection>} Promise for a collection of Spaces
59+
* @memberof ContentfulClientAPI
60+
* @return {Promise<Space.SpaceCollection>} Promise for a collection of Spaces
2861
* @example
62+
* const contentful = require('contentful-management')
63+
*
64+
* const client = contentful.createClient({
65+
* accessToken: '<content_management_api_key>'
66+
* })
67+
*
2968
* client.getSpaces()
30-
* .then(spaces => console.log(spaces.items))
69+
* .then((response) => console.log(response.items))
70+
* .catch(console.error)
3171
*/
3272
function getSpaces () {
3373
return http.get('')
@@ -36,12 +76,19 @@ export default function createClientApi ({ http }) {
3676

3777
/**
3878
* Gets a space
39-
* @memberof ClientAPI
79+
* @memberof ContentfulClientAPI
4080
* @param {string} id - Space ID
4181
* @return {Promise<Space.Space>} Promise for a Space
4282
* @example
43-
* client.getSpace('spaceid')
44-
* .then(space => console.log(space))
83+
* const contentful = require('contentful-management')
84+
*
85+
* const client = contentful.createClient({
86+
* accessToken: '<content_management_api_key>'
87+
* })
88+
*
89+
* client.getSpace('<space_id>')
90+
* .then((space) => console.log(space))
91+
* .catch(console.error)
4592
*/
4693
function getSpace (id) {
4794
return http.get(id)
@@ -50,14 +97,23 @@ export default function createClientApi ({ http }) {
5097

5198
/**
5299
* Creates a space
53-
* @memberof ClientAPI
100+
* @memberof ContentfulClientAPI
54101
* @see {Space.Space}
55102
* @param {object} data - Object representation of the Space to be created
56103
* @param {string=} organizationId - Organization ID, if the associated token can manage more than one organization.
57104
* @return {Promise<Space.Space>} Promise for the newly created Space
58105
* @example
59-
* client.createSpace({name: 'Space Name'})
60-
* .then(space => console.log(space))
106+
* const contentful = require('contentful-management')
107+
*
108+
* const client = contentful.createClient({
109+
* accessToken: '<content_management_api_key>'
110+
* })
111+
*
112+
* client.createSpace({
113+
* name: 'Name of new space'
114+
* })
115+
* .then((space) => console.log(space))
116+
* .catch(console.error)
61117
*/
62118
function createSpace (data, organizationId) {
63119
return http.post('', data, {
@@ -71,8 +127,11 @@ export default function createClientApi ({ http }) {
71127
* @memberof ClientAPI
72128
* @return {Promise<OrganizationCollection>} Promise for a collection of Organizations
73129
* @example
130+
* const contentful = require('contentful-management')
131+
*
74132
* space.getOrganizations()
75133
* .then(result => console.log(result.items))
134+
* .catch(console.error)
76135
*/
77136
function getOrganizations () {
78137
const baseURL = http.defaults.baseURL.replace('/spaces/', '/organizations/')

0 commit comments

Comments
 (0)