@bondsports/permissions 0.2.2 → 0.2.3

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 (2) hide show
  1. package/README.md +128 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # Permissions Package
2
+
3
+ This package centralizes and organizes all permissions used across the application into well-structured modules. It
4
+ ensures consistency between frontend and backend implementations, and will hopefully make it easier to find and use
5
+ permissions.
6
+
7
+ ## Features
8
+
9
+ - **Modular Organization:** Permissions are grouped into modules based on their functional domains (e.g., `calendar`,
10
+ `commerce`).
11
+ - **Strong Typing:** Permissions are defined as constant objects with TypeScript support for type safety.
12
+ - **Centralized Access:** All modules are aggregated in a single `permissions` object for convenient access.
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @bond-sports/permissions
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ All permissions are aggregated in a central permissions object, which can be imported for global access:
23
+
24
+ ```typescript
25
+ import permissions from '@bond-sports/permissions';
26
+
27
+ console.log(permissions.calendar.reservation.create); // Output: "calendar.reservation.create"
28
+ console.log(permissions.commerce.kiosk.view); // Output: "commerce.kiosk.view"
29
+ ```
30
+
31
+ ## Adding New Permissions
32
+
33
+ To add new permissions:
34
+
35
+ 1. Create or update the corresponding module file (e.g., calendar.ts for calendar-related permissions).
36
+ 2. Follow the structure:
37
+
38
+ ```typescript
39
+ const CalendarPermissions = {
40
+ reservation: {
41
+ create: 'calendar.reservation.create',
42
+ edit: 'calendar.reservation.edit',
43
+ },
44
+ slots: {
45
+ sessions: {
46
+ checkIn: 'calendar.slots.sessions.checkIn',
47
+ },
48
+ },
49
+ } as const;
50
+
51
+ export default CalendarPermissions;
52
+ ```
53
+
54
+ 3. Ensure the index.ts file imports the new module and updates the permissions object.
55
+
56
+ ## Example: Usage in Backend
57
+
58
+ Use permissions in backend services for access control:
59
+
60
+ ```typescript
61
+ import permissions from '@bond-sports/permissions';
62
+
63
+ // Example: Checking user permissions in a middleware
64
+ function hasPermission(userPermissions: string[], requiredPermission: string): boolean {
65
+ return userPermissions.includes(requiredPermission);
66
+ }
67
+
68
+ const userPermissions = ['calendar.reservation.create'];
69
+ const requiredPermission = permissions.calendar.reservation.create;
70
+
71
+ if (hasPermission(userPermissions, requiredPermission)) {
72
+ console.log('Permission granted');
73
+ } else {
74
+ console.log('Permission denied');
75
+ }
76
+ ```
77
+
78
+ ## Example: Usage in Frontend
79
+
80
+ Control UI components based on user permissions:
81
+
82
+ ```typescript jsx
83
+ import permissions from '@bond-sports/permissions';
84
+
85
+ function PermissionsWrapper({ requiredPermission, children, userPermissions }) {
86
+ if (userPermissions.includes(requiredPermission)) {
87
+ return <>{children}</>;
88
+ }
89
+ return null;
90
+ }
91
+
92
+ // Usage in a React component
93
+ <PermissionsWrapper
94
+ requiredPermission={permissions.commerce.kiosk.view}
95
+ userPermissions={['commerce.kiosk.view']}
96
+ >
97
+ <button>Access Kiosk</button>
98
+ </PermissionsWrapper>;
99
+ ```
100
+
101
+ ## Contributing
102
+
103
+ 1. Clone the repository and install dependencies:
104
+
105
+ ```bash
106
+ git clone git@github.com:Bond-Sports/permissions.git
107
+ ```
108
+
109
+ 2. Install the project dependencies:
110
+
111
+ ```bash
112
+ npm install
113
+ ```
114
+
115
+ 3. Add or modify permissions in the appropriate module files.
116
+
117
+ 4. Commit and push your changes:
118
+
119
+ ```bash
120
+ git commit -m "Add new permissions for [feature]"
121
+ git push
122
+ ```
123
+
124
+ ## Publishing
125
+
126
+ This package is automatically published when updates are pushed to specific branches (e.g., develop, staging, master)
127
+ via GitHub Actions.
128
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bondsports/permissions",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Bondsports internal permissions strings package",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {