Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@mashroom-content/mashroom-content-api
Advanced tools
Plugin for Mashroom Server, a Microfrontend Integration Platform. Part of the Mashroom Content extension.
This plugin adds an API abstraction that allows you to retrieve and manage content from a Headless CMS in Mashroom plugins (e.g. Portal Apps). It allows it to transparently switch the Headless CMS/Content Provider.
If node_modules/@mashroom is configured as plugin path just add @mashroom-content/mashroom-content-api as dependency.
You can override the default config in your Mashroom config file like this:
{
"plugins": {
"Mashroom Content Services": {
"provider": "Mashroom Content Internal Storage Provider",
"cacheEnable": true,
"cacheTTLSec": 1800
},
"Mashroom Content Provider API": {
"path": "/content",
"uploadTmpDir": null
}
}
}
IMPORTANT NOTE: The Content API (and therefore the client service) has no security at all at the moment. So, to make sure that normal users cannot update and delete content you should add an ACL configuration like this:
{
"/content/**": {
"*": {
"allow": {
"roles": ["Administrator"]
}
},
"GET": {
"allow": "any"
}
}
}
On the Server side you can use the following new service accessible through pluginContext.services.content.service:
export interface MashroomContentService {
/**
* Configured image breakpoints
*/
imageBreakpoints: Array<number>;
/**
* Configured preferred image formats
*/
imagePreferredFormats: Array<MashroomContentAssetProcImageFormats>;
/**
* Search for content of given type. You can use skip and limit for pagination.
*
* May throw 'Invalid Filter' (as error message).
*/
searchContent<T>(req: Request, type: string, filter?: MashroomContentApiFilter<T>, locale?: string, status?: MashroomContentApiStatus,
sort?: MashroomContentApiSort<T>, limit?: number, skip?: number): Promise<MashroomContentApiContentSearchResult<T>>;
/**
* Get a specific content element identified by an ID.
* May throw 'Access Denied' or 'Not Found' (as error message).
*/
getContent<T>(req: Request, type: string, id: string, locale?: string, version?: number): Promise<MashroomContentApiContentWrapper<T>>;
/**
* Get all available versions of given content.
* May throw 'Access Denied' or 'Not Found' (as error message).
*/
getContentVersions<T>(req: Request, type: string, id: string, locale?: string): Promise<MashroomContentVersionsResult<T>>;
/**
* Insert content for given type.
* For most content providers the 'type' needs to be defined in the CMS backend first.
* May throw 'Access Denied' or 'Not Found' (as error message).
*/
insertContent<T>(req: Request, type: string, content: MashroomContentApiContentUpdateInsert<T>): Promise<MashroomContentApiContentWrapper<T>>;
/**
* Partially update content with given type and ID.
* This includes adding new localizations.
*
* May throw 'Access Denied' or 'Not Found' (as error message).
*/
updateContent<T>(req: Request, type: string, id: string, content: MashroomContentApiContentUpdateInsert<Partial<T>>): Promise<MashroomContentApiContentWrapper<T>>;
/**
* Remove content with given type and ID.
*
* May throw 'Access Denied' or 'Not Found' (as error message).
*/
removeContent(req: Request, type: string, id: string): Promise<void>;
/**
* Remove content parts (specific languages or versions).
*
* May throw 'Access Denied' or 'Not Found' (as error message).
*/
removeContentParts(req: Request, type: string, id: string, locales?: Array<string>, versions?: Array<number>): Promise<void>;
/**
* Upload an asset (image or video) to given path (if folders are supported by the provider).
* If a contentRef is given the asset URL will be linked to given content.
*
* Will return download URL for the created asset.
*/
uploadAsset(req: Request, file: Readable, meta: MashroomContentAssetMeta, path?: string, contentRef?: MashroomContentAssetContentRef): Promise<MashroomContentAsset>;
/**
* Search for existing assets.
*
* type can be something like image/png or just image
*/
searchAssets(req: Request, type?: string, titleContains?: string, limit?: number, skip?: number): Promise<MashroomContentAssetSearchResult>;
/**
* Remove given asset
*/
removeAsset(req: Request, id: string): Promise<void>;
}
On the client side you can use MashroomContentClientService like this:
const bootstrap: MashroomPortalAppPluginBootstrapFunction = async (portalAppHostElement, portalAppSetup, clientServices) => {
const {appConfig, user} = portalAppSetup;
const contentService: MashroomContentClientService = clientServices.contentService;
const result = await contentService.getContent('my-content', 'sdfjkld');
// ...
}
The interface:
export interface MashroomContentClientService {
/**
* Configured image breakpoints
*/
imageBreakpoints: Array<number>;
/**
* Configured preferred image formats
*/
imagePreferredFormats: Array<MashroomContentAssetProcImageFormats>;
/**
* Search for content of given type.
*/
searchContent<T>(type: string, filter?: MashroomContentApiFilter<T>, locale?: string, status?: MashroomContentApiStatus,
sort?: MashroomContentApiSort<T>, limit?: number, skip?: number): Promise<MashroomContentApiContentSearchResult<T>>;
/**
* Get a specific content element identified by an ID.
*/
getContent<T>(type: string, id: string, locale?: string, version?: number): Promise<MashroomContentApiContentWrapper<T>>;
/**
* Get all available versions of given content.
*/
getContentVersions<T>(type: string, id: string, locale?: string): Promise<MashroomContentVersionsResult<T>>;
/**
* Insert content for given type.
*/
insertContent<T>(type: string, content: MashroomContentApiContentUpdateInsert<T>): Promise<MashroomContentApiContentWrapper<T>>;
/**
* Partially update content with given type and ID.
* This includes adding new localizations.
*/
updateContent<T>(type: string, id: string, content: MashroomContentApiContentUpdateInsert<Partial<T>>): Promise<MashroomContentApiContentWrapper<T>>;
/**
* Remove content with given type and ID.
*/
removeContent(type: string, id: string): Promise<void>;
/**
* Remove content parts (specific languages or versions).
*/
removeContentParts(type: string, id: string, locales?: Array<string>, versions?: Array<number>): Promise<void>;
/**
* Upload an asset (image or video).
* If a contentRef is given the asset URL will be linked to given content.
*
* Will return download URL for the created asset.
*/
uploadAsset(file: File, path?: string, contentRef?: MashroomContentAssetContentRef): PromiseWithProgressAndCancel<MashroomContentAsset>;
/**
* Search for existing assets.
*
* type can be something like image/png or just image
*/
searchAssets(type?: string, titleContains?: string, limit?: number, skip?: number): Promise<MashroomContentAssetSearchResult>;
/**
* Remove given asset
*/
removeAsset(id: string): Promise<void>;
}
And you can directly use the REST API which is specified in spec/mashroom-content-api.yaml
To register a custom memory-cache-provider plugin add this to package.json:
{
"mashroom": {
"plugins": [
{
"name": "My Content Provider",
"type": "content-provider",
"bootstrap": "./dist/mashroom-bootstrap.js",
"defaultConfig": {
"myProperty": "test"
}
}
]
}
}
The bootstrap returns the provider:
import MashroomContentProviderInternalStorageImpl from './MashroomContentProviderInternalStorageImpl';
import type {MashroomContentProviderPluginBootstrapFunction} from '@mashroom-content/mashroom-content-api/type-definitions';
const bootstrap: MashroomContentProviderPluginBootstrapFunction = async (pluginName, pluginConfig, pluginContextHolder) => {
return new MyContentProvider();
};
export default bootstrap;
And the provider has to implement the following interface:
export interface MashroomContentProvider {
/**
* Search for content of given type.
*/
searchContent<T>(req: Request, type: string, filter?: MashroomContentApiFilter<T>, locale?: string, status?: MashroomContentApiStatus,
sort?: MashroomContentApiSort<T>, limit?: number, skip?: number): Promise<MashroomContentApiContentSearchResult<T>>;
/**
* Get a specific content element identified by an ID.
* May throw 'Access Denied' or 'Not Found' (as error message).
*/
getContent<T>(req: Request, type: string, id: string, locale?: string, version?: number): Promise<MashroomContentApiContentWrapper<T>>;
/**
* Get all available versions of given content.
* May throw 'Access Denied' or 'Not Found' (as error message).
*/
getContentVersions<T>(req: Request, type: string, id: string, locale?: string): Promise<MashroomContentVersionsResult<T>>;
/**
* Insert content for given type.
* For most content providers the 'type' needs to be defined in the CMS backend first.
* May throw 'Access Denied' or 'Not Found' (as error message).
*/
insertContent<T>(req: Request, type: string, content: MashroomContentApiContentUpdateInsert<T>): Promise<MashroomContentApiContentWrapper<T>>;
/**
* Partially update content with given type and ID.
* This includes adding new localizations.
*
* May throw 'Access Denied' or 'Not Found' (as error message).
*/
updateContent<T>(req: Request, type: string, id: string, content: MashroomContentApiContentUpdateInsert<Partial<T>>): Promise<MashroomContentApiContentWrapper<T>>;
/**
* Remove content with given type and ID.
* If locales or versions are given only specific translations or versions are removed.
*
* May throw 'Access Denied' or 'Not Found' (as error message).
*/
removeContent(req: Request, type: string, id: string): Promise<void>;
/**
* Remove content parts (specific languages or versions).
*
* May throw 'Access Denied' or 'Not Found' (as error message).
*/
removeContentParts(req: Request, type: string, id: string, locales?: Array<string>, versions?: Array<number>): Promise<void>;
/**
* Upload an asset (image or video) to given path (if folders are supported by the provider).
* The path can be ignored if folders are not supported.
* If a contentRef is given the asset URL should be linked to given content.
*
* Must return the download URL for the new asset. The URL will be translated if a corresponding URL proxy is set.
*/
uploadAsset(req: Request, file: Readable, meta: MashroomContentAssetMeta, path?: string, contentRef?: MashroomContentAssetContentRef): Promise<MashroomContentAsset>;
/**
* Search for existing assets.
* The provider should return the assets sorted by upload timestamp (desc).
*
* type can be something like image/png or just image
*/
searchAssets(req: Request, type?: string, titleContains?: string, limit?: number, skip?: number): Promise<MashroomContentAssetSearchResult>;
/**
* Remove given asset.
*
* May throw 'Access Denied' or 'Not Found' (as error message).
*/
removeAsset(req: Request, id: string): Promise<void>;
/**
* Get a list of asset URIs that need to be proxied (and rewritten in the content)
*/
getAssetProxies(): MashroomContentApiAssetProxyConfigs;
}
FAQs
Mashroom Content API
The npm package @mashroom-content/mashroom-content-api receives a total of 2 weekly downloads. As such, @mashroom-content/mashroom-content-api popularity was classified as not popular.
We found that @mashroom-content/mashroom-content-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.