Karbon Custom Logic Folder
Karbon provides a way to customize the display logic by storing custom logic in the karbon
folder. The file path and name must conform to certain conventions.
Currently, the following definitions are provided:
karbin/is-viewable.mjs
karbin/is-viewable.mjs
This file can be used to define the logic for determining whether a user can view paid content. It is particularly useful when using third-party payment providers as it provides additional checks to ensure that the user has the necessary permissions to view the content.
To define the logic, use export default defineIsViewable(...)
.
The defineIsViewable
function can be imported using import { defineIsViewable } from '@storipress/karbon/helper'
.
Type
interface Auth {
token: string
}
interface Meta {
/// article id
id: string
/// article plan
/// - `member`: required login
/// - `subscriber`: required paid plan
plan: 'member' | 'subscriber'
/// decrypt key
key: string
}
interface CallBackFnParameters {
auth: Auth
meta: Meta
/// helper to get full article
getArticle: () => Promise<Article>
}
declare function callBackFunction(parameters: CallBackFnParameters): Promise<boolean | { pass: boolean }>
declare function defineIsViewable(callBackFunction): typeof callBackFunction
Example
import { defineIsViewable } from '@storipress/karbon/helper'
export default defineIsViewable(async ({ auth }) => {
// The customLogic function can be used to define custom logic.
const isViewable: boolean = customLogic(auth.token)
return isViewable
})