Skip to content

Commit 1003e08

Browse files
committed
RBAC/plugin updates
1 parent 157e9c5 commit 1003e08

8 files changed

Lines changed: 135 additions & 28 deletions

File tree

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
1-
import type { RBACPlugin } from "@trigger.dev/plugins";
1+
import type {
2+
Permission,
3+
Role,
4+
RoleBaseAccessController,
5+
RoleBasedAccessControlPlugin,
6+
} from "@trigger.dev/plugins";
27

3-
export function create(): RBACPlugin {
4-
return {
5-
type: "rbac",
6-
};
8+
export class RoleBaseAccessFallback implements RoleBasedAccessControlPlugin {
9+
async create() {
10+
return new RoleBaseAccessFallbackController();
11+
}
12+
}
13+
14+
const accountWildcard: Permission = {
15+
name: "*:account",
16+
description: "Full abilities for an account",
17+
};
18+
19+
const superWildcard: Permission = {
20+
name: "*:super",
21+
description: "Full abilities for a super user",
22+
};
23+
24+
const owner: Role = {
25+
name: "owner",
26+
description: "Full access to all features",
27+
permissions: [accountWildcard, superWildcard],
28+
};
29+
30+
const superAdmin: Role = {
31+
name: "super_admin",
32+
description: "Full access to all features and the ability to manage the Trigger.dev platform",
33+
permissions: [accountWildcard, superWildcard],
34+
};
35+
36+
class RoleBaseAccessFallbackController implements RoleBaseAccessController {
37+
async allPermissions(): Promise<Permission[]> {
38+
return [owner, superAdmin];
39+
}
40+
41+
async allRoles(): Promise<Role[]> {
42+
return [owner, superAdmin];
43+
}
744
}
Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
import type { RBACPlugin } from "@trigger.dev/plugins";
1+
import type {
2+
RoleBaseAccessController,
3+
RoleBasedAccessControlPlugin,
4+
PrismaClient,
5+
} from "@trigger.dev/plugins";
6+
import { RoleBaseAccessFallback } from "./fallback";
7+
export type { RoleBaseAccessController, RoleBasedAccessControlPlugin };
28

3-
export type { RBACPlugin };
4-
5-
type PluginModule = {
6-
create(): RBACPlugin | Promise<RBACPlugin>;
7-
};
8-
9-
export async function createRBACPlugin(): Promise<RBACPlugin> {
10-
try {
11-
// Installed in cloud deployments; absent in OSS
12-
// eslint-disable-next-line @typescript-eslint/no-require-imports
13-
const { create } = require("@triggerdotdev/plugin-rbac") as PluginModule;
14-
return create();
15-
} catch {
16-
// eslint-disable-next-line @typescript-eslint/no-require-imports
17-
const { create } = require("./fallback") as PluginModule;
18-
return create();
9+
class RoleBaseAccess implements RoleBasedAccessControlPlugin {
10+
async create(prisma: PrismaClient) {
11+
try {
12+
const moduleName = "@triggerdotdev/plugin-rbac";
13+
const module = await import(moduleName);
14+
const { create } = await module();
15+
return create(prisma);
16+
} catch {
17+
const fallback = new RoleBaseAccessFallback();
18+
return fallback.create();
19+
}
1920
}
2021
}
22+
23+
const plugin = new RoleBaseAccess();
24+
25+
export default plugin;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3+
"mainEntryPointFilePath": "<projectFolder>/dist/types/index.d.ts",
4+
"bundledPackages": ["@trigger.dev/database"],
5+
"compiler": {
6+
"tsconfigFilePath": "<projectFolder>/tsconfig.dts.json"
7+
},
8+
"dtsRollup": {
9+
"enabled": true,
10+
"untrimmedFilePath": "<projectFolder>/dist/index.d.ts",
11+
"alphaTrimmedFilePath": "",
12+
"betaTrimmedFilePath": "",
13+
"publicTrimmedFilePath": ""
14+
},
15+
"apiReport": { "enabled": false },
16+
"docModel": { "enabled": false },
17+
"tsdocMetadata": { "enabled": false },
18+
"messages": {
19+
"extractorMessageReporting": {
20+
"ae-forgotten-export": { "logLevel": "none" },
21+
"ae-missing-release-tag": { "logLevel": "none" }
22+
},
23+
"tsdocMessageReporting": {
24+
"default": { "logLevel": "none" }
25+
}
26+
}
27+
}

packages/plugins/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
],
1818
"scripts": {
1919
"clean": "rimraf dist .turbo",
20-
"build": "tsup",
21-
"dev": "tsup --watch --onSuccess 'npm unpublish @trigger.dev/plugins --registry http://localhost:4873 --force 2>/dev/null; pnpm publish --registry http://localhost:4873 --no-git-checks 2>/dev/null || true'",
20+
"build": "tsup && tsc -p tsconfig.dts.json && api-extractor run --local",
21+
"dev": "tsup --watch --onSuccess 'tsc -p tsconfig.dts.json && api-extractor run --local --quiet'",
2222
"typecheck": "tsc --noEmit"
2323
},
2424
"devDependencies": {
25+
"@microsoft/api-extractor": "^7.58.2",
26+
"@trigger.dev/database": "workspace:*",
2527
"@types/node": "^20.14.14",
2628
"rimraf": "6.0.1",
2729
"tsup": "^8.4.0",

packages/plugins/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
export type { RBACPlugin } from "./rbac.js";
1+
export type {
2+
RoleBasedAccessControlPlugin,
3+
RoleBaseAccessController,
4+
PrismaClient,
5+
Permission,
6+
Role,
7+
} from "./rbac.js";

packages/plugins/src/rbac.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1-
export interface RBACPlugin {
2-
readonly type: "rbac";
1+
import type { PrismaClient } from "@trigger.dev/database";
2+
3+
export type { PrismaClient };
4+
5+
export type Permission = {
6+
name: string;
7+
description: string;
8+
};
9+
10+
export type Role = {
11+
name: string;
12+
description: string;
13+
permissions: Permission[];
14+
};
15+
16+
export interface RoleBaseAccessController {
17+
allPermissions(): Promise<Permission[]>;
18+
allRoles(): Promise<Role[]>;
19+
}
20+
21+
export interface RoleBasedAccessControlPlugin {
22+
create(prisma: PrismaClient): RoleBaseAccessController | Promise<RoleBaseAccessController>;
323
}

packages/plugins/tsconfig.dts.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "../../.configs/tsconfig.base.json",
3+
"compilerOptions": {
4+
"declaration": true,
5+
"emitDeclarationOnly": true,
6+
"outDir": "dist/types",
7+
"rootDir": "src"
8+
},
9+
"include": ["./src/**/*.ts"]
10+
}

packages/plugins/tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { defineConfig } from "tsup";
33
export default defineConfig({
44
entry: ["src/index.ts"],
55
format: ["cjs", "esm"],
6-
dts: true,
6+
dts: false,
77
splitting: false,
88
sourcemap: true,
99
clean: true,

0 commit comments

Comments
 (0)