secure-role-guard 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +813 -0
  3. package/dist/adapters/express.d.mts +109 -0
  4. package/dist/adapters/express.d.ts +109 -0
  5. package/dist/adapters/express.js +122 -0
  6. package/dist/adapters/express.js.map +1 -0
  7. package/dist/adapters/express.mjs +118 -0
  8. package/dist/adapters/express.mjs.map +1 -0
  9. package/dist/adapters/index.d.mts +3 -0
  10. package/dist/adapters/index.d.ts +3 -0
  11. package/dist/adapters/index.js +181 -0
  12. package/dist/adapters/index.js.map +1 -0
  13. package/dist/adapters/index.mjs +171 -0
  14. package/dist/adapters/index.mjs.map +1 -0
  15. package/dist/adapters/nextjs.d.mts +140 -0
  16. package/dist/adapters/nextjs.d.ts +140 -0
  17. package/dist/adapters/nextjs.js +138 -0
  18. package/dist/adapters/nextjs.js.map +1 -0
  19. package/dist/adapters/nextjs.mjs +131 -0
  20. package/dist/adapters/nextjs.mjs.map +1 -0
  21. package/dist/core/index.d.mts +100 -0
  22. package/dist/core/index.d.ts +100 -0
  23. package/dist/core/index.js +132 -0
  24. package/dist/core/index.js.map +1 -0
  25. package/dist/core/index.mjs +125 -0
  26. package/dist/core/index.mjs.map +1 -0
  27. package/dist/index.d.mts +4 -0
  28. package/dist/index.d.ts +4 -0
  29. package/dist/index.js +238 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/index.mjs +222 -0
  32. package/dist/index.mjs.map +1 -0
  33. package/dist/react/index.d.mts +237 -0
  34. package/dist/react/index.d.ts +237 -0
  35. package/dist/react/index.js +177 -0
  36. package/dist/react/index.js.map +1 -0
  37. package/dist/react/index.mjs +167 -0
  38. package/dist/react/index.mjs.map +1 -0
  39. package/dist/types-CSUpaGsY.d.mts +76 -0
  40. package/dist/types-CSUpaGsY.d.ts +76 -0
  41. package/package.json +99 -0
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Secure Role Guard - Core Types
3
+ *
4
+ * Pure TypeScript type definitions for RBAC authorization.
5
+ * Zero dependencies, zero side effects.
6
+ */
7
+ /**
8
+ * Represents the current user's authorization context.
9
+ * This is the input shape provided by the consuming application.
10
+ *
11
+ * @example
12
+ * const user: UserContext = {
13
+ * userId: 'user-123',
14
+ * roles: ['admin', 'manager'],
15
+ * permissions: ['custom.permission'],
16
+ * meta: { tenantId: 'tenant-abc' }
17
+ * };
18
+ */
19
+ type UserContext = {
20
+ /** Optional unique identifier for the user */
21
+ readonly userId?: string;
22
+ /** Array of role names assigned to this user */
23
+ readonly roles?: readonly string[];
24
+ /** Array of direct permissions granted to this user (bypasses role lookup) */
25
+ readonly permissions?: readonly string[];
26
+ /** Optional metadata for tenant/org context or custom data */
27
+ readonly meta?: Readonly<Record<string, unknown>>;
28
+ };
29
+ /**
30
+ * Defines a mapping of role names to their granted permissions.
31
+ *
32
+ * @example
33
+ * const roles: RoleDefinition = {
34
+ * superadmin: ['*'],
35
+ * admin: ['user.read', 'user.update', 'user.delete'],
36
+ * viewer: ['user.read', 'report.view']
37
+ * };
38
+ */
39
+ type RoleDefinition = Readonly<Record<string, readonly string[]>>;
40
+ /**
41
+ * Immutable registry of role definitions.
42
+ * Created by the defineRoles() function.
43
+ */
44
+ type RoleRegistry = {
45
+ /** Get permissions for a specific role. Returns empty array if role not found. */
46
+ readonly getPermissions: (role: string) => readonly string[];
47
+ /** Check if a role exists in the registry */
48
+ readonly hasRole: (role: string) => boolean;
49
+ /** Get all registered role names */
50
+ readonly getRoleNames: () => readonly string[];
51
+ };
52
+ /**
53
+ * Configuration options for the permission engine.
54
+ */
55
+ type PermissionEngineConfig = {
56
+ /** The role registry to use for permission lookups */
57
+ readonly roleRegistry: RoleRegistry;
58
+ };
59
+ /**
60
+ * Result of a permission check.
61
+ * Simple boolean for now, but structured for future extensibility.
62
+ */
63
+ type PermissionCheckResult = {
64
+ readonly allowed: boolean;
65
+ /** Optional reason for debugging (only in development) */
66
+ readonly reason?: string;
67
+ };
68
+ /**
69
+ * Options for permission checking.
70
+ */
71
+ type PermissionCheckOptions = {
72
+ /** If true, any of the permissions being checked will grant access */
73
+ readonly anyOf?: boolean;
74
+ };
75
+
76
+ export type { PermissionEngineConfig as P, RoleDefinition as R, UserContext as U, RoleRegistry as a, PermissionCheckResult as b, PermissionCheckOptions as c };
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Secure Role Guard - Core Types
3
+ *
4
+ * Pure TypeScript type definitions for RBAC authorization.
5
+ * Zero dependencies, zero side effects.
6
+ */
7
+ /**
8
+ * Represents the current user's authorization context.
9
+ * This is the input shape provided by the consuming application.
10
+ *
11
+ * @example
12
+ * const user: UserContext = {
13
+ * userId: 'user-123',
14
+ * roles: ['admin', 'manager'],
15
+ * permissions: ['custom.permission'],
16
+ * meta: { tenantId: 'tenant-abc' }
17
+ * };
18
+ */
19
+ type UserContext = {
20
+ /** Optional unique identifier for the user */
21
+ readonly userId?: string;
22
+ /** Array of role names assigned to this user */
23
+ readonly roles?: readonly string[];
24
+ /** Array of direct permissions granted to this user (bypasses role lookup) */
25
+ readonly permissions?: readonly string[];
26
+ /** Optional metadata for tenant/org context or custom data */
27
+ readonly meta?: Readonly<Record<string, unknown>>;
28
+ };
29
+ /**
30
+ * Defines a mapping of role names to their granted permissions.
31
+ *
32
+ * @example
33
+ * const roles: RoleDefinition = {
34
+ * superadmin: ['*'],
35
+ * admin: ['user.read', 'user.update', 'user.delete'],
36
+ * viewer: ['user.read', 'report.view']
37
+ * };
38
+ */
39
+ type RoleDefinition = Readonly<Record<string, readonly string[]>>;
40
+ /**
41
+ * Immutable registry of role definitions.
42
+ * Created by the defineRoles() function.
43
+ */
44
+ type RoleRegistry = {
45
+ /** Get permissions for a specific role. Returns empty array if role not found. */
46
+ readonly getPermissions: (role: string) => readonly string[];
47
+ /** Check if a role exists in the registry */
48
+ readonly hasRole: (role: string) => boolean;
49
+ /** Get all registered role names */
50
+ readonly getRoleNames: () => readonly string[];
51
+ };
52
+ /**
53
+ * Configuration options for the permission engine.
54
+ */
55
+ type PermissionEngineConfig = {
56
+ /** The role registry to use for permission lookups */
57
+ readonly roleRegistry: RoleRegistry;
58
+ };
59
+ /**
60
+ * Result of a permission check.
61
+ * Simple boolean for now, but structured for future extensibility.
62
+ */
63
+ type PermissionCheckResult = {
64
+ readonly allowed: boolean;
65
+ /** Optional reason for debugging (only in development) */
66
+ readonly reason?: string;
67
+ };
68
+ /**
69
+ * Options for permission checking.
70
+ */
71
+ type PermissionCheckOptions = {
72
+ /** If true, any of the permissions being checked will grant access */
73
+ readonly anyOf?: boolean;
74
+ };
75
+
76
+ export type { PermissionEngineConfig as P, RoleDefinition as R, UserContext as U, RoleRegistry as a, PermissionCheckResult as b, PermissionCheckOptions as c };
package/package.json ADDED
@@ -0,0 +1,99 @@
1
+ {
2
+ "name": "secure-role-guard",
3
+ "version": "1.0.0",
4
+ "description": "Zero-vulnerability, framework-agnostic RBAC authorization library for React applications",
5
+ "author": "Sohel Rahaman",
6
+ "license": "MIT",
7
+ "keywords": [
8
+ "rbac",
9
+ "authorization",
10
+ "permissions",
11
+ "roles",
12
+ "react",
13
+ "nextjs",
14
+ "remix",
15
+ "gatsby",
16
+ "astro",
17
+ "express",
18
+ "security",
19
+ "access-control",
20
+ "enterprise"
21
+ ],
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/Sohel-Rahaman-Developer/secure-role-guard.git"
25
+ },
26
+ "homepage": "https://github.com/Sohel-Rahaman-Developer/secure-role-guard#readme",
27
+ "bugs": {
28
+ "url": "https://github.com/Sohel-Rahaman-Developer/secure-role-guard/issues"
29
+ },
30
+ "main": "./dist/index.js",
31
+ "module": "./dist/index.mjs",
32
+ "types": "./dist/index.d.ts",
33
+ "sideEffects": false,
34
+ "exports": {
35
+ ".": {
36
+ "types": "./dist/index.d.ts",
37
+ "import": "./dist/index.mjs",
38
+ "require": "./dist/index.js"
39
+ },
40
+ "./core": {
41
+ "types": "./dist/core/index.d.ts",
42
+ "import": "./dist/core/index.mjs",
43
+ "require": "./dist/core/index.js"
44
+ },
45
+ "./react": {
46
+ "types": "./dist/react/index.d.ts",
47
+ "import": "./dist/react/index.mjs",
48
+ "require": "./dist/react/index.js"
49
+ },
50
+ "./adapters": {
51
+ "types": "./dist/adapters/index.d.ts",
52
+ "import": "./dist/adapters/index.mjs",
53
+ "require": "./dist/adapters/index.js"
54
+ },
55
+ "./adapters/express": {
56
+ "types": "./dist/adapters/express.d.ts",
57
+ "import": "./dist/adapters/express.mjs",
58
+ "require": "./dist/adapters/express.js"
59
+ },
60
+ "./adapters/nextjs": {
61
+ "types": "./dist/adapters/nextjs.d.ts",
62
+ "import": "./dist/adapters/nextjs.mjs",
63
+ "require": "./dist/adapters/nextjs.js"
64
+ }
65
+ },
66
+ "files": [
67
+ "dist",
68
+ "README.md",
69
+ "LICENSE"
70
+ ],
71
+ "scripts": {
72
+ "build": "tsup",
73
+ "type-check": "tsc --noEmit",
74
+ "lint": "eslint src/",
75
+ "prepublishOnly": "npm run type-check && npm run build"
76
+ },
77
+ "peerDependencies": {
78
+ "react": ">=16.8.0"
79
+ },
80
+ "peerDependenciesMeta": {
81
+ "react": {
82
+ "optional": true
83
+ }
84
+ },
85
+ "devDependencies": {
86
+ "@eslint/js": "^9.0.0",
87
+ "@types/node": "^20.10.0",
88
+ "@types/react": "^18.2.0",
89
+ "eslint": "^9.0.0",
90
+ "eslint-plugin-security": "^3.0.0",
91
+ "react": "^18.2.0",
92
+ "tsup": "^8.0.0",
93
+ "typescript": "^5.3.0",
94
+ "typescript-eslint": "^8.0.0"
95
+ },
96
+ "engines": {
97
+ "node": ">=18.0.0"
98
+ }
99
+ }