Skip to main content

fuse-utils

What is this repository for?

This repository is a client library for profiles, Macro Security and Allow List. This Library has methods for CRUDL Operation related to profiles, allowlist and macro security using datastore 2.0.

Example: a github profile which can be used to read a markdown file content from a github repository

Features

  • Profiles
    • Create/Read/Update/Delete/fetch the profile entities.
  • Proxy
    • The Proxy SDK can be used to read the content using a profile or a URL from the upstream
  • Allow-list
    • The ability to create/read/update/delete/fetch the Allowlist.

Installation

pnpm i @appfire/fuse-utils

Profiles Usage

Initialize FuseProfilesSDK we can create profiles using the FuseProfilesSDK

const profileClient = new FuseProfilesSDK(productType, appKey);

Props

type ProfileType {
productType: 'Confluence' | 'Jira' | 'Monday';
appKey: string;
}

pass in the Profile type data to the create/update operations for profile in datastore

{
profileName: string;
password?: string;
type: ProfileType;
user?: string;
url?: string;
requestHeaders?: string;
accessToken?: string;
urlParameters?: string;
};

Using the Proxy Library to fetch the content from upstream

Using Proxy to fetch Profile content

new FuseProxySDK("Confluence", "org.swift.confluence.refapp")
.getDataFromProfile({ profile: "myworkgithub" });
returns the content as a string

Using the URL directly to fetch content from the upstream

new FuseProxySDK("Confluence",'org.swift.confluence.refapp');
.getDataFromProfile({url:"https://appfire.com"})

Allow list Usage

initialise allowlist class

const allowList = new FuseAllowListSDK(
"Confluence", // App type like Confluence/Jira/Monday
"org.swift.confluence.refapp", // appkey
);

List Allow List

allowList.list();
{
"baseUrl": "https://akshaysaraf21.atlassian.net/wiki",
"org.swift.confluence.html": [ // appkey that holds the list
{
"type": "domain-name",
"expression": "https://www.google.com"
},
{
"type": "domain-name",
"expression": "https://www.youtube.com"
}
]
}

returns promise when resolved returns list of all persisted allowlist on the app.

Add/ Update/ Delete Allow List

// performs all the three orations on allowlist
const request = {
baseUrl: "https://akshaysaraf21.atlassian.net/wiki",
appKey: "org.swift.confluence.refapp",
whiteLists: [ // Array of list to be added
{ expression: "https://www.youtube.com", type: "domain-name" },
],
updatedRecords: [
{
expression: "https://www.google.com",
type: "domain-name",
prevType: "exact-match",
}, // type will be the new type and the prevType is the type before updating this record.
],
deletedRecords: [ // add all the records that need to be deleted as part of this method call
{ expression: "https://www.youtube.com", type: "domain-name" },
],
};

type and prev-type are can be one of (domain-name, exact-match, wildcard-expr, regular-expr)

Macro security Usage

Initialize Macro security class

const macroUtils = new FuseMacroSecurity(productType, appKey);

Props

type ProfileType {
productType: 'Confluence' | 'Jira' | 'Monday';
appKey: string;
}

Register Macro

macroUtils.register(request);

example request :

const request = {
macroKey: "org.swift.confluence.refapp",
paramKey: "allowSameOrigin",
paramName: "",
paramValue: {
trustedGroups: [],
trustedSpaces: {
"~712020f215bcfc9ccc48cdb8c7e43ccb6b7663": "tarun.dabhi",
},
trustedUsers: ["712020:f215bcfc-9ccc-48cd-b8c7-e43ccb6b7663"],
},
};
Note: Request will change according to users need, the given one above is just an example.

List all the restrictions for the macro

Once registered we can list all the available restrictions inside that using list() method, below is the example to get the restrictions

macroUtils.list();

This returns promise when resolved returns list of all persisted restrictions on the macro.

Create/Update restrictions for the macro

const request = {
macroKey: "org.swift.confluence.refapp",
paramKey: "allowSameOrigin",
paramName: "",
paramValue: {
trustedGroups: [],
trustedSpaces: {
"~712020f215bcfc9ccc48cdb8c7e43ccb6b7663": "akshay.saraf",
},
trustedUsers: ["712020:f215bcfc-9ccc-48cd-b8c7-e43ccb6b7663"],
},
};
return macroUtils.create(request);

For create and update the method will be same i.e. create()

Delete restrictions for the macro

macroUtils.delete("org.swift.confluence.refapp", "allowScriptAccess");

Fetching the restrictions, which can be used by an app to verify macro usage

###### Signatures

  • macroSecurityClient.getRestrictions(spaceKey, pageId, macroKey, pageMode)
Parameters
  • spaceKey Indicates the key name of a space
  • pageId Id of the page
  • macroKey macro-key on which restrictions need to be identified,
  • pageMode (edit,view)
Returns

RestrictionsResponse — The response has information if a macro key is allowed on not for the pageId and spaceKey in a specific pageMode

{
"macroKey": "sql-query",
"parameters": {
"dataSource": {
"awsDbProfile": {
"access": true,
"message": "Access granted."
},
"access": true,
"message": "Access granted."
}
}
}
    const responseData = await macroSecurityClient.getRestrictions({
spaceKey: "RAT",
pageId: '58523650',
macroKey: 'currentuser',
pageMode: 'edit'
});

Contribution guidelines

  • Writing tests
  • Based on type of changes (Major, Minor, and Patch) use changeset to update package versions. for more information please check here

Who do I talk to?