π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
feat(nocodb): add nocodb utils
Ramesh Mane61a904f0d9c7
diff --git a/packages/nocodb/src/utils/extensionUtils.ts b/packages/nocodb/src/utils/extensionUtils.tsnew file mode 100644index 0000000000..fa066d6b17--- /dev/null+++ b/packages/nocodb/src/utils/extensionUtils.ts@@ -0,0 +1,50 @@+import * as fs from 'fs';+import * as path from 'path';++// Extensions Root+const rootPath = path.resolve(+ __dirname,+ '..',+ '..',+ '..',+ 'nc-gui',+ 'extensions',+);++/**+ * Get the root path of the extensions+ * @returns The root path of the extensions+ */+export function getExtensionRootPath() {+ return rootPath;+}++/**+ * Get the minimum access role of an extension+ * @param extensionEntry The entry of the extension+ * @param fallbackRole The fallback role if the extension does not have a minAccessRole+ * @returns The minimum access role of the extension+ */+export function getExtensionMinAccessRole(+ extensionEntry: string,+ fallbackRole: string = 'creator',+) {+ // If no extension entry is provided, return the fallback role+ if (!extensionEntry) return fallbackRole;++ // Get the manifest path of the extension+ const manifestPath = path.resolve(+ getExtensionRootPath(),+ extensionEntry,+ 'manifest.json',+ );++ // Try to get the minAccessRole from the manifest+ try {+ const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));+ return manifest?.minAccessRole || fallbackRole;+ } catch {+ // If the manifest is not found, return the fallback role+ return fallbackRole;+ }+}