@mussnad/frappe-js-client
Version:
Next-generation TS/JS client for Frappe REST APIs, built on axios for robust, type-safe integration.
52 lines (51 loc) • 2.18 kB
TypeScript
import { AxiosInstance } from 'axios';
import { HasPermissionResponse, PermissionType, Permissions } from './types';
export declare class Permission {
/** URL of the Frappe App instance */
private readonly appURL;
/** Axios instance for making HTTP requests */
readonly axios: AxiosInstance;
/** Whether to use token based authentication */
readonly useToken: boolean;
/** Function that returns the authentication token */
readonly token?: () => string;
/** Type of token to be used for authentication */
readonly tokenType?: 'Bearer' | 'token';
/**
* Creates a new FrappeClient instance.
*
* @param appURL - The URL of the Frappe App instance
* @param axios - The Axios instance for making HTTP requests
* @param useToken - Whether to use token based authentication
* @param token - Function that returns the authentication token
* @param tokenType - Type of token to use ('Bearer' or 'token')
*/
constructor(appURL: string, axios: AxiosInstance, useToken?: boolean, token?: () => string, tokenType?: 'Bearer' | 'token');
/**
* Checks if the user has permission to perform an action on a document.
*
* @param doctype - The name of the document type
* @param docname - The name of the document
* @param perm_type - The type of permission to check
* @returns A promise that resolves to a boolean indicating whether the user has permission
*
* @example
* ```typescript
* const permission = await permission.hasPermission('DocType', 'docname', 'read')
* ```
*/
hasPermission(doctype: string, docname: string, perm_type?: PermissionType): Promise<HasPermissionResponse>;
/**
* Fetches the permissions for a document.
*
* @param doctype - The name of the document type
* @param docname - The name of the document
* @returns A promise that resolves to an array of permissions
*
* @example
* ```typescript
* const permissions = await permission.getDocPermissions('DocType', 'docname')
* ```
*/
getDocPermissions(doctype: string, docname: string): Promise<Permissions>;
}