UNPKG

@mussnad/frappe-js-client

Version:

Next-generation TS/JS client for Frappe REST APIs, built on axios for robust, type-safe integration.

73 lines (72 loc) 2.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Permission = void 0; var axios_1 = require("../utils/axios"); var Permission = /** @class */ (function () { /** * 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') */ function Permission(appURL, axios, useToken, token, tokenType) { this.appURL = appURL; this.axios = axios; this.useToken = useToken !== null && useToken !== void 0 ? useToken : false; this.token = token; this.tokenType = tokenType !== null && tokenType !== void 0 ? tokenType : 'Bearer'; } /** * 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') * ``` */ Permission.prototype.hasPermission = function (doctype, docname, perm_type) { if (perm_type === void 0) { perm_type = 'read'; } return (0, axios_1.handleRequest)({ axios: this.axios, config: { url: '/api/method/frappe.client.has_permission', params: { doctype: doctype, docname: docname, perm_type: perm_type }, }, errorMessage: 'There was an error while checking the permission.', transformResponse: function (response) { return response.data.message; }, }); }; /** * 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') * ``` */ Permission.prototype.getDocPermissions = function (doctype, docname) { return (0, axios_1.handleRequest)({ axios: this.axios, config: { url: '/api/method/frappe.client.get_doc_permissions', params: { doctype: doctype, docname: docname }, }, errorMessage: 'There was an error while fetching the document permissions.', transformResponse: function (response) { return response.data.message; }, }); }; return Permission; }()); exports.Permission = Permission;