Skip to main content

fuse-confluence

Installation

npm i @appfire/fuse-confluence

Fuse Confluence (@appfire/fuse-confluence)

The @appfire/fuse-confluence package is a utility library for Confluence apps, encapsulating all the reusable functions required by different apps related to pages, spaces, comments, etc.

User resource

const userResource = new FuseConfluenceSDK().getUserResource();
// returns current user
const user = await userResource.getCurrentUser();
// return array of using matching the searchKey
const users = await userResource.getUsers(searchKey);
// to fetch multiple users by id. ids is a string with ids being comma separated.
const users = await userResource.getUsersByIds(ids);
// returns if a user is a Admin based on account ID
const isAdmin = await userResource.isAdmin(accountID);

Space resource

// Get All spaces in the wiki
const response = await fuseConfluenceSDK.getSpaceResources().getSpaces();
// Get Space Id of current space
const response = await fuseConfluenceSDK.getSpaceResources().getSpaceId();
// Set a property on the space
const response = await fuseConfluenceSDK
.getSpaceResources()
.setSpaceProperty(data.spaceId, {
key: data.propertyName,
value: data.propertyValue,
});
//Get Property on space by space id and property id
const response = await fuseConfluenceSDK
.getSpaceResources()
.getSpaceProperty(data.spaceId, data.propertyId);
//Get All Property on the space
const response = await fuseConfluenceSDK
.getSpaceResources()
.getSpaceProperties(data.spaceId);

Page Resource

//Get Current Page Id
const response = await fuseConfluenceSDK.getPage('').getPageID();

//get page properties using page id
const response = await fuseConfluenceSDK
.getPage(data.pageId)
.getPageProperties();

//set page property using pageId and propertyID

const response = await fuseConfluenceSDK
.getPage(data.pageId)
.getPageProperty(data.propertyId);

//Set Property to page

const response = await fuseConfluenceSDK.getPage(data.pageId).setPageProperty({
key: data.propertyName,
value: data.propertyValue,
});

//Search pageId using spaceId and page name
const response = await fuseConfluenceSDK
.getPage('')
.findPageId(data.spaceId, data.pageName);

Group Resource

//Get All groups
const response = await fuseConfluenceSDK.getGroupResource().getGroups();

Attachment Resource

//Get attachment on a page based on pageId.
const response = await fuseConfluenceSDK
.getPage(data.pageId)
.getAttachment(data.attachmentName)
.getContent('utf-8');

Convert To View Format

Converts from storage to view format. All web resources will be loaded and appended to the page as a result of this call.

contextId the context id to use when converting the view. This is normally the owning page and is required by the REST call. storageFormat the value to be converted. loadCss {boolean} Whether CSS loading needed or not. returns Promise the future promise of the result. This will be resolved only when the conversion completes successfully AND all CSS files have been loaded on the page. Note, that all JS files have not necessarily been loaded yet. The promise is resolved with the HTML value of the view format. If the conversion fails for any reason, an error message will be provided in the reject call.

const response = await fuseConfluenceSDK
.getConversionResource()
.convertToViewFormat(contextId, storageFormat, false);

Convert To Wiki Markup

Converts markup from 'wiki' to 'view' format.

contentId - The content id context to use when making REST calls. wiki - The wiki markup to convert. loadCss - Whether CSS loading needed or not.

@return {Promise} a promise object that will give the converted response.

const response = await fuseConfluenceSDK
.getConversionResource()
.convertWikiMarkup(contentId, wiki, false);

Decrypt data

Decrypt the data string passed in. 1st param is the data to to decrypted

kmsClint needs to be initialized and passed to this method( this needs to be from AWS SDK v3) encryptionAlgorithm can be also read EncryptionAlgorithmSpec from @aws-sdk/client-kms

const response = await fuseConfluenceSDK.getDecryptResource().decrypt(
{
password,
accessToken,
},
kmsClient,
key,
encryptionAlgorithm
);

DecryptData the data string passed in.

data param is the string/json to to decrypted

kmsClient needs to be initialized and passed to this method( this needs to be from AWS SDK v3) encryptionAlgorithm can be also read EncryptionAlgorithmSpec from @aws-sdk/client-kms

const response = await fuseConfluenceSDK
.getDecryptResource()
.decrypt(data, kmsClient, key, encryptionAlgorithm);

Get Cacheable macro params

Get the context object and then retrieve macro params

const response = await fuseConfluenceSDK
.getCacheableMacroResource()
.getCacheableMacroParams();

getMacroBody
Get macroBody this can be used on browser and backend both
```js
const response = await fuseConfluenceSDK
.getMacroResources()
.getMacroBody();

Append URL Params

Appends urlPrams to url
const response = await fuseConfluenceSDK
.appendUrlParams(url , urlParams);

The confluence-ref-app in fuse-sdk has most of the examples used.