Edit page

util

Functions under util object

import util from 'digimaker/util'
const def = util.getDefinition('article')
FunctionreturnDescription
getRefreshTokenstringGet refresh token
setRefreshToken(token: string)voidSet refresh token. Typically used in login
setCookieKey(key string)Set cookie key typically for refresh tokenDefault cooke is 'refreshToken'
getCookieKeyGet cookie key
getViewSettingsViewSettingsType in DMInitGet view settings set in DMInit
getDefinition(contenttype:string)anyGet definition of a content type
getFields(definition:any)ArrayGet fields from a content type definition

fetchWithAuth

Fetch a request with internal access token. If access token expired, it automatically renew access token and refetch.

import {fetchWithAuth} from 'digimaker/util'
paramstypeDescription
urlstringCan be absolute url(with http:// or https://) or relative(eg. 'content/list')
requestObjrequest object(optional)For post: {method:'POST', body:JSON.stringify(dataObject)}
returndataJson objectformat: {error: false, data: {}}, if error is true, data will be the error object

Example:

import {fetchWithAuth} from 'digimaker/util'
//GET
fetchWithAuth('content/list/article?parent=3').then(data=>{
if(data.error===false){
setList(data.data)
}else{
//handle error
console.log(data.data);
}
}).catch(e=>throw e);
//POST
fetchWithAuth('content/create/article/3', {
method: 'POST',
body: JSON.stringify(dataObject),
}).then((data) => {
//handle
}).catch((e)=>{});

Basic usage