@sudobility/entity_service 1.0.1

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 (72) hide show
  1. package/CLAUDE.md +124 -0
  2. package/dist/helpers/EntityHelper.cjs +234 -0
  3. package/dist/helpers/EntityHelper.d.ts +60 -0
  4. package/dist/helpers/EntityHelper.d.ts.map +1 -0
  5. package/dist/helpers/EntityHelper.js +234 -0
  6. package/dist/helpers/EntityHelper.js.map +1 -0
  7. package/dist/helpers/EntityMemberHelper.cjs +215 -0
  8. package/dist/helpers/EntityMemberHelper.d.ts +45 -0
  9. package/dist/helpers/EntityMemberHelper.d.ts.map +1 -0
  10. package/dist/helpers/EntityMemberHelper.js +215 -0
  11. package/dist/helpers/EntityMemberHelper.js.map +1 -0
  12. package/dist/helpers/InvitationHelper.cjs +251 -0
  13. package/dist/helpers/InvitationHelper.d.ts +59 -0
  14. package/dist/helpers/InvitationHelper.d.ts.map +1 -0
  15. package/dist/helpers/InvitationHelper.js +251 -0
  16. package/dist/helpers/InvitationHelper.js.map +1 -0
  17. package/dist/helpers/PermissionHelper.cjs +197 -0
  18. package/dist/helpers/PermissionHelper.d.ts +86 -0
  19. package/dist/helpers/PermissionHelper.d.ts.map +1 -0
  20. package/dist/helpers/PermissionHelper.js +197 -0
  21. package/dist/helpers/PermissionHelper.js.map +1 -0
  22. package/dist/helpers/index.cjs +15 -0
  23. package/dist/helpers/index.d.ts +8 -0
  24. package/dist/helpers/index.d.ts.map +1 -0
  25. package/dist/helpers/index.js +15 -0
  26. package/dist/helpers/index.js.map +1 -0
  27. package/dist/index.cjs +76 -0
  28. package/dist/index.d.ts +36 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +76 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/middleware/hono.cjs +148 -0
  33. package/dist/middleware/hono.d.ts +102 -0
  34. package/dist/middleware/hono.d.ts.map +1 -0
  35. package/dist/middleware/hono.js +148 -0
  36. package/dist/middleware/hono.js.map +1 -0
  37. package/dist/middleware/index.cjs +12 -0
  38. package/dist/middleware/index.d.ts +5 -0
  39. package/dist/middleware/index.d.ts.map +1 -0
  40. package/dist/middleware/index.js +12 -0
  41. package/dist/middleware/index.js.map +1 -0
  42. package/dist/migrations/001_add_entities.cjs +269 -0
  43. package/dist/migrations/001_add_entities.d.ts +29 -0
  44. package/dist/migrations/001_add_entities.d.ts.map +1 -0
  45. package/dist/migrations/001_add_entities.js +269 -0
  46. package/dist/migrations/001_add_entities.js.map +1 -0
  47. package/dist/migrations/index.cjs +10 -0
  48. package/dist/migrations/index.d.ts +5 -0
  49. package/dist/migrations/index.d.ts.map +1 -0
  50. package/dist/migrations/index.js +10 -0
  51. package/dist/migrations/index.js.map +1 -0
  52. package/dist/schema/entities.cjs +304 -0
  53. package/dist/schema/entities.d.ts +1047 -0
  54. package/dist/schema/entities.d.ts.map +1 -0
  55. package/dist/schema/entities.js +304 -0
  56. package/dist/schema/entities.js.map +1 -0
  57. package/dist/types/index.cjs +14 -0
  58. package/dist/types/index.d.ts +71 -0
  59. package/dist/types/index.d.ts.map +1 -0
  60. package/dist/types/index.js +14 -0
  61. package/dist/types/index.js.map +1 -0
  62. package/dist/utils/index.cjs +21 -0
  63. package/dist/utils/index.d.ts +5 -0
  64. package/dist/utils/index.d.ts.map +1 -0
  65. package/dist/utils/index.js +21 -0
  66. package/dist/utils/index.js.map +1 -0
  67. package/dist/utils/slug-generator.cjs +92 -0
  68. package/dist/utils/slug-generator.d.ts +41 -0
  69. package/dist/utils/slug-generator.d.ts.map +1 -0
  70. package/dist/utils/slug-generator.js +92 -0
  71. package/dist/utils/slug-generator.js.map +1 -0
  72. package/package.json +78 -0
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Entity Permission Helper Class
4
+ * @description Permission checking for entity operations
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.PermissionHelper = void 0;
8
+ const drizzle_orm_1 = require("drizzle-orm");
9
+ const types_1 = require("../types");
10
+ /**
11
+ * Helper class for entity permission checks.
12
+ */
13
+ class PermissionHelper {
14
+ constructor(config) {
15
+ this.config = config;
16
+ }
17
+ /**
18
+ * Get a user's role in an entity.
19
+ */
20
+ async getUserRole(entityId, userId) {
21
+ const results = await this.config.db
22
+ .select({ role: this.config.membersTable.role })
23
+ .from(this.config.membersTable)
24
+ .where((0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(this.config.membersTable.entity_id, entityId), (0, drizzle_orm_1.eq)(this.config.membersTable.user_id, userId)))
25
+ .limit(1);
26
+ if (results.length === 0) {
27
+ return null;
28
+ }
29
+ return results[0].role;
30
+ }
31
+ /**
32
+ * Get permissions for a role.
33
+ */
34
+ getPermissionsForRole(role) {
35
+ return types_1.ROLE_PERMISSIONS[role];
36
+ }
37
+ /**
38
+ * Get a user's permissions for an entity.
39
+ */
40
+ async getUserPermissions(entityId, userId) {
41
+ const role = await this.getUserRole(entityId, userId);
42
+ if (!role) {
43
+ return null;
44
+ }
45
+ return this.getPermissionsForRole(role);
46
+ }
47
+ /**
48
+ * Check if user is a member of an entity.
49
+ */
50
+ async isMember(entityId, userId) {
51
+ const role = await this.getUserRole(entityId, userId);
52
+ return role !== null;
53
+ }
54
+ /**
55
+ * Check if user is an admin of an entity.
56
+ */
57
+ async isAdmin(entityId, userId) {
58
+ const role = await this.getUserRole(entityId, userId);
59
+ return role === types_1.EntityRole.ADMIN;
60
+ }
61
+ /**
62
+ * Check if user is the owner of an entity.
63
+ */
64
+ async isOwner(entityId, userId) {
65
+ const results = await this.config.db
66
+ .select({ ownerUserId: this.config.entitiesTable.owner_user_id })
67
+ .from(this.config.entitiesTable)
68
+ .where((0, drizzle_orm_1.eq)(this.config.entitiesTable.id, entityId))
69
+ .limit(1);
70
+ if (results.length === 0) {
71
+ return false;
72
+ }
73
+ return results[0].ownerUserId === userId;
74
+ }
75
+ /**
76
+ * Check if user can view an entity.
77
+ */
78
+ async canViewEntity(entityId, userId) {
79
+ const permissions = await this.getUserPermissions(entityId, userId);
80
+ return permissions?.canViewEntity ?? false;
81
+ }
82
+ /**
83
+ * Check if user can edit an entity.
84
+ */
85
+ async canEditEntity(entityId, userId) {
86
+ const permissions = await this.getUserPermissions(entityId, userId);
87
+ return permissions?.canEditEntity ?? false;
88
+ }
89
+ /**
90
+ * Check if user can delete an entity.
91
+ */
92
+ async canDeleteEntity(entityId, userId) {
93
+ // First check if it's a personal entity (cannot be deleted)
94
+ const entity = await this.config.db
95
+ .select({ entityType: this.config.entitiesTable.entity_type })
96
+ .from(this.config.entitiesTable)
97
+ .where((0, drizzle_orm_1.eq)(this.config.entitiesTable.id, entityId))
98
+ .limit(1);
99
+ if (entity.length === 0) {
100
+ return false;
101
+ }
102
+ if (entity[0].entityType === types_1.EntityType.PERSONAL) {
103
+ return false;
104
+ }
105
+ const permissions = await this.getUserPermissions(entityId, userId);
106
+ return permissions?.canDeleteEntity ?? false;
107
+ }
108
+ /**
109
+ * Check if user can manage members.
110
+ */
111
+ async canManageMembers(entityId, userId) {
112
+ const permissions = await this.getUserPermissions(entityId, userId);
113
+ return permissions?.canManageMembers ?? false;
114
+ }
115
+ /**
116
+ * Check if user can invite members.
117
+ */
118
+ async canInviteMembers(entityId, userId) {
119
+ // Check if it's a personal entity (no invitations allowed)
120
+ const entity = await this.config.db
121
+ .select({ entityType: this.config.entitiesTable.entity_type })
122
+ .from(this.config.entitiesTable)
123
+ .where((0, drizzle_orm_1.eq)(this.config.entitiesTable.id, entityId))
124
+ .limit(1);
125
+ if (entity.length === 0) {
126
+ return false;
127
+ }
128
+ if (entity[0].entityType === types_1.EntityType.PERSONAL) {
129
+ return false;
130
+ }
131
+ const permissions = await this.getUserPermissions(entityId, userId);
132
+ return permissions?.canInviteMembers ?? false;
133
+ }
134
+ /**
135
+ * Check if user can create projects.
136
+ */
137
+ async canCreateProjects(entityId, userId) {
138
+ const permissions = await this.getUserPermissions(entityId, userId);
139
+ return permissions?.canCreateProjects ?? false;
140
+ }
141
+ /**
142
+ * Check if user can manage projects.
143
+ */
144
+ async canManageProjects(entityId, userId) {
145
+ const permissions = await this.getUserPermissions(entityId, userId);
146
+ return permissions?.canManageProjects ?? false;
147
+ }
148
+ /**
149
+ * Check if user can view projects.
150
+ */
151
+ async canViewProjects(entityId, userId) {
152
+ const permissions = await this.getUserPermissions(entityId, userId);
153
+ return permissions?.canViewProjects ?? false;
154
+ }
155
+ /**
156
+ * Check if user can manage API keys.
157
+ */
158
+ async canManageApiKeys(entityId, userId) {
159
+ const permissions = await this.getUserPermissions(entityId, userId);
160
+ return permissions?.canManageApiKeys ?? false;
161
+ }
162
+ /**
163
+ * Check if user can view API keys.
164
+ */
165
+ async canViewApiKeys(entityId, userId) {
166
+ const permissions = await this.getUserPermissions(entityId, userId);
167
+ return permissions?.canViewApiKeys ?? false;
168
+ }
169
+ /**
170
+ * Assert that a user has a specific permission.
171
+ * Throws an error if the user lacks the permission.
172
+ */
173
+ async assertPermission(entityId, userId, permission, errorMessage) {
174
+ const permissions = await this.getUserPermissions(entityId, userId);
175
+ if (!permissions) {
176
+ throw new Error(errorMessage ?? 'User is not a member of this entity');
177
+ }
178
+ if (!permissions[permission]) {
179
+ throw new Error(errorMessage ?? `User lacks permission: ${String(permission)}`);
180
+ }
181
+ }
182
+ /**
183
+ * Get the minimum role required for a permission.
184
+ */
185
+ getMinimumRoleForPermission(permission) {
186
+ // Check from lowest to highest privilege
187
+ const roles = [types_1.EntityRole.VIEWER, types_1.EntityRole.MANAGER, types_1.EntityRole.ADMIN];
188
+ for (const role of roles) {
189
+ if (types_1.ROLE_PERMISSIONS[role][permission]) {
190
+ return role;
191
+ }
192
+ }
193
+ return null;
194
+ }
195
+ }
196
+ exports.PermissionHelper = PermissionHelper;
197
+ //# sourceMappingURL=PermissionHelper.js.map
@@ -0,0 +1,86 @@
1
+ /**
2
+ * @fileoverview Entity Permission Helper Class
3
+ * @description Permission checking for entity operations
4
+ */
5
+ import { EntityRole, type EntityPermissions, type EntityHelperConfig } from '../types';
6
+ /**
7
+ * Helper class for entity permission checks.
8
+ */
9
+ export declare class PermissionHelper {
10
+ private readonly config;
11
+ constructor(config: EntityHelperConfig);
12
+ /**
13
+ * Get a user's role in an entity.
14
+ */
15
+ getUserRole(entityId: string, userId: string): Promise<EntityRole | null>;
16
+ /**
17
+ * Get permissions for a role.
18
+ */
19
+ getPermissionsForRole(role: EntityRole): EntityPermissions;
20
+ /**
21
+ * Get a user's permissions for an entity.
22
+ */
23
+ getUserPermissions(entityId: string, userId: string): Promise<EntityPermissions | null>;
24
+ /**
25
+ * Check if user is a member of an entity.
26
+ */
27
+ isMember(entityId: string, userId: string): Promise<boolean>;
28
+ /**
29
+ * Check if user is an admin of an entity.
30
+ */
31
+ isAdmin(entityId: string, userId: string): Promise<boolean>;
32
+ /**
33
+ * Check if user is the owner of an entity.
34
+ */
35
+ isOwner(entityId: string, userId: string): Promise<boolean>;
36
+ /**
37
+ * Check if user can view an entity.
38
+ */
39
+ canViewEntity(entityId: string, userId: string): Promise<boolean>;
40
+ /**
41
+ * Check if user can edit an entity.
42
+ */
43
+ canEditEntity(entityId: string, userId: string): Promise<boolean>;
44
+ /**
45
+ * Check if user can delete an entity.
46
+ */
47
+ canDeleteEntity(entityId: string, userId: string): Promise<boolean>;
48
+ /**
49
+ * Check if user can manage members.
50
+ */
51
+ canManageMembers(entityId: string, userId: string): Promise<boolean>;
52
+ /**
53
+ * Check if user can invite members.
54
+ */
55
+ canInviteMembers(entityId: string, userId: string): Promise<boolean>;
56
+ /**
57
+ * Check if user can create projects.
58
+ */
59
+ canCreateProjects(entityId: string, userId: string): Promise<boolean>;
60
+ /**
61
+ * Check if user can manage projects.
62
+ */
63
+ canManageProjects(entityId: string, userId: string): Promise<boolean>;
64
+ /**
65
+ * Check if user can view projects.
66
+ */
67
+ canViewProjects(entityId: string, userId: string): Promise<boolean>;
68
+ /**
69
+ * Check if user can manage API keys.
70
+ */
71
+ canManageApiKeys(entityId: string, userId: string): Promise<boolean>;
72
+ /**
73
+ * Check if user can view API keys.
74
+ */
75
+ canViewApiKeys(entityId: string, userId: string): Promise<boolean>;
76
+ /**
77
+ * Assert that a user has a specific permission.
78
+ * Throws an error if the user lacks the permission.
79
+ */
80
+ assertPermission(entityId: string, userId: string, permission: keyof EntityPermissions, errorMessage?: string): Promise<void>;
81
+ /**
82
+ * Get the minimum role required for a permission.
83
+ */
84
+ getMinimumRoleForPermission(permission: keyof EntityPermissions): EntityRole | null;
85
+ }
86
+ //# sourceMappingURL=PermissionHelper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PermissionHelper.d.ts","sourceRoot":"","sources":["../../src/helpers/PermissionHelper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,UAAU,EAGV,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACxB,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,qBAAa,gBAAgB;IACf,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,kBAAkB;IAEvD;;OAEG;IACG,WAAW,CACf,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAmB7B;;OAEG;IACH,qBAAqB,CAAC,IAAI,EAAE,UAAU,GAAG,iBAAiB;IAI1D;;OAEG;IACG,kBAAkB,CACtB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAQpC;;OAEG;IACG,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKlE;;OAEG;IACG,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKjE;;OAEG;IACG,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,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ACpB,OAAO,CAAC,IAAI,CAAC;IAchB;;OAEG;IACH,2BAA2B,CACzB,UAAU,EAAE,MAAM,iBAAiB,GAClC,UAAU,GAAG,IAAI;CAYrB"}
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Entity Permission Helper Class
4
+ * @description Permission checking for entity operations
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.PermissionHelper = void 0;
8
+ const drizzle_orm_1 = require("drizzle-orm");
9
+ const types_1 = require("../types");
10
+ /**
11
+ * Helper class for entity permission checks.
12
+ */
13
+ class PermissionHelper {
14
+ constructor(config) {
15
+ this.config = config;
16
+ }
17
+ /**
18
+ * Get a user's role in an entity.
19
+ */
20
+ async getUserRole(entityId, userId) {
21
+ const results = await this.config.db
22
+ .select({ role: this.config.membersTable.role })
23
+ .from(this.config.membersTable)
24
+ .where((0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(this.config.membersTable.entity_id, entityId), (0, drizzle_orm_1.eq)(this.config.membersTable.user_id, userId)))
25
+ .limit(1);
26
+ if (results.length === 0) {
27
+ return null;
28
+ }
29
+ return results[0].role;
30
+ }
31
+ /**
32
+ * Get permissions for a role.
33
+ */
34
+ getPermissionsForRole(role) {
35
+ return types_1.ROLE_PERMISSIONS[role];
36
+ }
37
+ /**
38
+ * Get a user's permissions for an entity.
39
+ */
40
+ async getUserPermissions(entityId, userId) {
41
+ const role = await this.getUserRole(entityId, userId);
42
+ if (!role) {
43
+ return null;
44
+ }
45
+ return this.getPermissionsForRole(role);
46
+ }
47
+ /**
48
+ * Check if user is a member of an entity.
49
+ */
50
+ async isMember(entityId, userId) {
51
+ const role = await this.getUserRole(entityId, userId);
52
+ return role !== null;
53
+ }
54
+ /**
55
+ * Check if user is an admin of an entity.
56
+ */
57
+ async isAdmin(entityId, userId) {
58
+ const role = await this.getUserRole(entityId, userId);
59
+ return role === types_1.EntityRole.ADMIN;
60
+ }
61
+ /**
62
+ * Check if user is the owner of an entity.
63
+ */
64
+ async isOwner(entityId, userId) {
65
+ const results = await this.config.db
66
+ .select({ ownerUserId: this.config.entitiesTable.owner_user_id })
67
+ .from(this.config.entitiesTable)
68
+ .where((0, drizzle_orm_1.eq)(this.config.entitiesTable.id, entityId))
69
+ .limit(1);
70
+ if (results.length === 0) {
71
+ return false;
72
+ }
73
+ return results[0].ownerUserId === userId;
74
+ }
75
+ /**
76
+ * Check if user can view an entity.
77
+ */
78
+ async canViewEntity(entityId, userId) {
79
+ const permissions = await this.getUserPermissions(entityId, userId);
80
+ return permissions?.canViewEntity ?? false;
81
+ }
82
+ /**
83
+ * Check if user can edit an entity.
84
+ */
85
+ async canEditEntity(entityId, userId) {
86
+ const permissions = await this.getUserPermissions(entityId, userId);
87
+ return permissions?.canEditEntity ?? false;
88
+ }
89
+ /**
90
+ * Check if user can delete an entity.
91
+ */
92
+ async canDeleteEntity(entityId, userId) {
93
+ // First check if it's a personal entity (cannot be deleted)
94
+ const entity = await this.config.db
95
+ .select({ entityType: this.config.entitiesTable.entity_type })
96
+ .from(this.config.entitiesTable)
97
+ .where((0, drizzle_orm_1.eq)(this.config.entitiesTable.id, entityId))
98
+ .limit(1);
99
+ if (entity.length === 0) {
100
+ return false;
101
+ }
102
+ if (entity[0].entityType === types_1.EntityType.PERSONAL) {
103
+ return false;
104
+ }
105
+ const permissions = await this.getUserPermissions(entityId, userId);
106
+ return permissions?.canDeleteEntity ?? false;
107
+ }
108
+ /**
109
+ * Check if user can manage members.
110
+ */
111
+ async canManageMembers(entityId, userId) {
112
+ const permissions = await this.getUserPermissions(entityId, userId);
113
+ return permissions?.canManageMembers ?? false;
114
+ }
115
+ /**
116
+ * Check if user can invite members.
117
+ */
118
+ async canInviteMembers(entityId, userId) {
119
+ // Check if it's a personal entity (no invitations allowed)
120
+ const entity = await this.config.db
121
+ .select({ entityType: this.config.entitiesTable.entity_type })
122
+ .from(this.config.entitiesTable)
123
+ .where((0, drizzle_orm_1.eq)(this.config.entitiesTable.id, entityId))
124
+ .limit(1);
125
+ if (entity.length === 0) {
126
+ return false;
127
+ }
128
+ if (entity[0].entityType === types_1.EntityType.PERSONAL) {
129
+ return false;
130
+ }
131
+ const permissions = await this.getUserPermissions(entityId, userId);
132
+ return permissions?.canInviteMembers ?? false;
133
+ }
134
+ /**
135
+ * Check if user can create projects.
136
+ */
137
+ async canCreateProjects(entityId, userId) {
138
+ const permissions = await this.getUserPermissions(entityId, userId);
139
+ return permissions?.canCreateProjects ?? false;
140
+ }
141
+ /**
142
+ * Check if user can manage projects.
143
+ */
144
+ async canManageProjects(entityId, userId) {
145
+ const permissions = await this.getUserPermissions(entityId, userId);
146
+ return permissions?.canManageProjects ?? false;
147
+ }
148
+ /**
149
+ * Check if user can view projects.
150
+ */
151
+ async canViewProjects(entityId, userId) {
152
+ const permissions = await this.getUserPermissions(entityId, userId);
153
+ return permissions?.canViewProjects ?? false;
154
+ }
155
+ /**
156
+ * Check if user can manage API keys.
157
+ */
158
+ async canManageApiKeys(entityId, userId) {
159
+ const permissions = await this.getUserPermissions(entityId, userId);
160
+ return permissions?.canManageApiKeys ?? false;
161
+ }
162
+ /**
163
+ * Check if user can view API keys.
164
+ */
165
+ async canViewApiKeys(entityId, userId) {
166
+ const permissions = await this.getUserPermissions(entityId, userId);
167
+ return permissions?.canViewApiKeys ?? false;
168
+ }
169
+ /**
170
+ * Assert that a user has a specific permission.
171
+ * Throws an error if the user lacks the permission.
172
+ */
173
+ async assertPermission(entityId, userId, permission, errorMessage) {
174
+ const permissions = await this.getUserPermissions(entityId, userId);
175
+ if (!permissions) {
176
+ throw new Error(errorMessage ?? 'User is not a member of this entity');
177
+ }
178
+ if (!permissions[permission]) {
179
+ throw new Error(errorMessage ?? `User lacks permission: ${String(permission)}`);
180
+ }
181
+ }
182
+ /**
183
+ * Get the minimum role required for a permission.
184
+ */
185
+ getMinimumRoleForPermission(permission) {
186
+ // Check from lowest to highest privilege
187
+ const roles = [types_1.EntityRole.VIEWER, types_1.EntityRole.MANAGER, types_1.EntityRole.ADMIN];
188
+ for (const role of roles) {
189
+ if (types_1.ROLE_PERMISSIONS[role][permission]) {
190
+ return role;
191
+ }
192
+ }
193
+ return null;
194
+ }
195
+ }
196
+ exports.PermissionHelper = PermissionHelper;
197
+ //# sourceMappingURL=PermissionHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PermissionHelper.js","sourceRoot":"","sources":["../../src/helpers/PermissionHelper.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6CAAsC;AACtC,oCAMkB;AAElB;;GAEG;AACH,MAAa,gBAAgB;IAC3B,YAA6B,MAA0B;QAA1B,WAAM,GAAN,MAAM,CAAoB;IAAG,CAAC;IAE3D;;OAEG;IACH,KAAK,CAAC,WAAW,CACf,QAAgB,EAChB,MAAc;QAEd,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,EAAE;aACjC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;aAC/C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC;aAC9B,KAAK,CACJ,IAAA,iBAAG,EACD,IAAA,gBAAE,EAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,QAAQ,CAAC,EAChD,IAAA,gBAAE,EAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAC7C,CACF;aACA,KAAK,CAAC,CAAC,CAAC,CAAC;QAEZ,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC,IAAkB,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,qBAAqB,CAAC,IAAgB;QACpC,OAAO,wBAAgB,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,kBA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ACJ,CAAC;IACH,CAAC;IAED;;OAEG;IACH,2BAA2B,CACzB,UAAmC;QAEnC,yCAAyC;QACzC,MAAM,KAAK,GAAG,CAAC,kBAAU,CAAC,MAAM,EAAE,kBAAU,CAAC,OAAO,EAAE,kBAAU,CAAC,KAAK,CAAC,CAAC;QAExE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,wBAAgB,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC;gBACvC,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAxOD,4CAwOC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Helper Exports
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PermissionHelper = exports.InvitationHelper = exports.EntityMemberHelper = exports.EntityHelper = void 0;
7
+ var EntityHelper_1 = require("./EntityHelper");
8
+ Object.defineProperty(exports, "EntityHelper", { enumerable: true, get: function () { return EntityHelper_1.EntityHelper; } });
9
+ var EntityMemberHelper_1 = require("./EntityMemberHelper");
10
+ Object.defineProperty(exports, "EntityMemberHelper", { enumerable: true, get: function () { return EntityMemberHelper_1.EntityMemberHelper; } });
11
+ var InvitationHelper_1 = require("./InvitationHelper");
12
+ Object.defineProperty(exports, "InvitationHelper", { enumerable: true, get: function () { return InvitationHelper_1.InvitationHelper; } });
13
+ var PermissionHelper_1 = require("./PermissionHelper");
14
+ Object.defineProperty(exports, "PermissionHelper", { enumerable: true, get: function () { return PermissionHelper_1.PermissionHelper; } });
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @fileoverview Helper Exports
3
+ */
4
+ export { EntityHelper } from './EntityHelper';
5
+ export { EntityMemberHelper } from './EntityMemberHelper';
6
+ export { InvitationHelper } from './InvitationHelper';
7
+ export { PermissionHelper } from './PermissionHelper';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Helper Exports
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PermissionHelper = exports.InvitationHelper = exports.EntityMemberHelper = exports.EntityHelper = void 0;
7
+ var EntityHelper_1 = require("./EntityHelper");
8
+ Object.defineProperty(exports, "EntityHelper", { enumerable: true, get: function () { return EntityHelper_1.EntityHelper; } });
9
+ var EntityMemberHelper_1 = require("./EntityMemberHelper");
10
+ Object.defineProperty(exports, "EntityMemberHelper", { enumerable: true, get: function () { return EntityMemberHelper_1.EntityMemberHelper; } });
11
+ var InvitationHelper_1 = require("./InvitationHelper");
12
+ Object.defineProperty(exports, "InvitationHelper", { enumerable: true, get: function () { return InvitationHelper_1.InvitationHelper; } });
13
+ var PermissionHelper_1 = require("./PermissionHelper");
14
+ Object.defineProperty(exports, "PermissionHelper", { enumerable: true, get: function () { return PermissionHelper_1.PermissionHelper; } });
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AAC3B,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AACzB,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA"}
package/dist/index.cjs ADDED
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Entity Service Library
4
+ * @description Shared backend library for multi-tenant entity/organization management
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import {
9
+ * createEntityHelpers,
10
+ * createEntityContextMiddleware,
11
+ * entities,
12
+ * entityMembers,
13
+ * entityInvitations,
14
+ * } from '@shapeshyft/entity-service';
15
+ *
16
+ * // Create helpers with your database config
17
+ * const helpers = createEntityHelpers({
18
+ * db: drizzleDb,
19
+ * entitiesTable: mySchema.entities,
20
+ * membersTable: mySchema.entityMembers,
21
+ * invitationsTable: mySchema.entityInvitations,
22
+ * usersTable: mySchema.users,
23
+ * });
24
+ *
25
+ * // Use in your routes
26
+ * const entity = await helpers.entity.getOrCreatePersonalEntity(userId, email);
27
+ * const members = await helpers.members.getMembers(entityId);
28
+ * ```
29
+ */
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.ROLE_PERMISSIONS = exports.InvitationStatus = exports.EntityRole = exports.EntityType = exports.rollbackEntityMigration = exports.runEntityMigration = exports.calculateInvitationExpiry = exports.validateSlug = exports.normalizeSlug = exports.generateInvitationToken = exports.generateEntitySlug = exports.createEntityHelpers = exports.createRequireRoleMiddleware = exports.createRequirePermissionMiddleware = exports.createEntityContextMiddleware = exports.PermissionHelper = exports.InvitationHelper = exports.EntityMemberHelper = exports.EntityHelper = exports.initEntityTables = exports.entityInvitations = exports.entityMembers = exports.entities = exports.createEntityInvitationsTablePublic = exports.createEntityInvitationsTable = exports.createEntityMembersTablePublic = exports.createEntityMembersTable = exports.createEntitiesTablePublic = exports.createEntitiesTable = void 0;
32
+ // Schema exports
33
+ var entities_1 = require("./schema/entities");
34
+ // Table factory functions
35
+ Object.defineProperty(exports, "createEntitiesTable", { enumerable: true, get: function () { return entities_1.createEntitiesTable; } });
36
+ Object.defineProperty(exports, "createEntitiesTablePublic", { enumerable: true, get: function () { return entities_1.createEntitiesTablePublic; } });
37
+ Object.defineProperty(exports, "createEntityMembersTable", { enumerable: true, get: function () { return entities_1.createEntityMembersTable; } });
38
+ Object.defineProperty(exports, "createEntityMembersTablePublic", { enumerable: true, get: function () { return entities_1.createEntityMembersTablePublic; } });
39
+ Object.defineProperty(exports, "createEntityInvitationsTable", { enumerable: true, get: function () { return entities_1.createEntityInvitationsTable; } });
40
+ Object.defineProperty(exports, "createEntityInvitationsTablePublic", { enumerable: true, get: function () { return entities_1.createEntityInvitationsTablePublic; } });
41
+ // Default tables (public schema)
42
+ Object.defineProperty(exports, "entities", { enumerable: true, get: function () { return entities_1.entities; } });
43
+ Object.defineProperty(exports, "entityMembers", { enumerable: true, get: function () { return entities_1.entityMembers; } });
44
+ Object.defineProperty(exports, "entityInvitations", { enumerable: true, get: function () { return entities_1.entityInvitations; } });
45
+ // Initialization
46
+ Object.defineProperty(exports, "initEntityTables", { enumerable: true, get: function () { return entities_1.initEntityTables; } });
47
+ // Helper exports
48
+ var helpers_1 = require("./helpers");
49
+ Object.defineProperty(exports, "EntityHelper", { enumerable: true, get: function () { return helpers_1.EntityHelper; } });
50
+ Object.defineProperty(exports, "EntityMemberHelper", { enumerable: true, get: function () { return helpers_1.EntityMemberHelper; } });
51
+ Object.defineProperty(exports, "InvitationHelper", { enumerable: true, get: function () { return helpers_1.InvitationHelper; } });
52
+ Object.defineProperty(exports, "PermissionHelper", { enumerable: true, get: function () { return helpers_1.PermissionHelper; } });
53
+ // Middleware exports
54
+ var middleware_1 = require("./middleware");
55
+ Object.defineProperty(exports, "createEntityContextMiddleware", { enumerable: true, get: function () { return middleware_1.createEntityContextMiddleware; } });
56
+ Object.defineProperty(exports, "createRequirePermissionMiddleware", { enumerable: true, get: function () { return middleware_1.createRequirePermissionMiddleware; } });
57
+ Object.defineProperty(exports, "createRequireRoleMiddleware", { enumerable: true, get: function () { return middleware_1.createRequireRoleMiddleware; } });
58
+ Object.defineProperty(exports, "createEntityHelpers", { enumerable: true, get: function () { return middleware_1.createEntityHelpers; } });
59
+ // Utility exports
60
+ var utils_1 = require("./utils");
61
+ Object.defineProperty(exports, "generateEntitySlug", { enumerable: true, get: function () { return utils_1.generateEntitySlug; } });
62
+ Object.defineProperty(exports, "generateInvitationToken", { enumerable: true, get: function () { return utils_1.generateInvitationToken; } });
63
+ Object.defineProperty(exports, "normalizeSlug", { enumerable: true, get: function () { return utils_1.normalizeSlug; } });
64
+ Object.defineProperty(exports, "validateSlug", { enumerable: true, get: function () { return utils_1.validateSlug; } });
65
+ Object.defineProperty(exports, "calculateInvitationExpiry", { enumerable: true, get: function () { return utils_1.calculateInvitationExpiry; } });
66
+ // Migration exports
67
+ var migrations_1 = require("./migrations");
68
+ Object.defineProperty(exports, "runEntityMigration", { enumerable: true, get: function () { return migrations_1.runEntityMigration; } });
69
+ Object.defineProperty(exports, "rollbackEntityMigration", { enumerable: true, get: function () { return migrations_1.rollbackEntityMigration; } });
70
+ // Type exports (re-exported from @sudobility/types)
71
+ var types_1 = require("./types");
72
+ Object.defineProperty(exports, "EntityType", { enumerable: true, get: function () { return types_1.EntityType; } });
73
+ Object.defineProperty(exports, "EntityRole", { enumerable: true, get: function () { return types_1.EntityRole; } });
74
+ Object.defineProperty(exports, "InvitationStatus", { enumerable: true, get: function () { return types_1.InvitationStatus; } });
75
+ Object.defineProperty(exports, "ROLE_PERMISSIONS", { enumerable: true, get: function () { return types_1.ROLE_PERMISSIONS; } });
76
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @fileoverview Entity Service Library
3
+ * @description Shared backend library for multi-tenant entity/organization management
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * import {
8
+ * createEntityHelpers,
9
+ * createEntityContextMiddleware,
10
+ * entities,
11
+ * entityMembers,
12
+ * entityInvitations,
13
+ * } from '@shapeshyft/entity-service';
14
+ *
15
+ * // Create helpers with your database config
16
+ * const helpers = createEntityHelpers({
17
+ * db: drizzleDb,
18
+ * entitiesTable: mySchema.entities,
19
+ * membersTable: mySchema.entityMembers,
20
+ * invitationsTable: mySchema.entityInvitations,
21
+ * usersTable: mySchema.users,
22
+ * });
23
+ *
24
+ * // Use in your routes
25
+ * const entity = await helpers.entity.getOrCreatePersonalEntity(userId, email);
26
+ * const members = await helpers.members.getMembers(entityId);
27
+ * ```
28
+ */
29
+ export { createEntitiesTable, createEntitiesTablePublic, createEntityMembersTable, createEntityMembersTablePublic, createEntityInvitationsTable, createEntityInvitationsTablePublic, entities, entityMembers, entityInvitations, type EntityRecord, type NewEntityRecord, type EntityMemberRecord, type NewEntityMemberRecord, type EntityInvitationRecord, type NewEntityInvitationRecord, initEntityTables, } from './schema/entities';
30
+ export { EntityHelper, EntityMemberHelper, InvitationHelper, PermissionHelper, } from './helpers';
31
+ export { createEntityContextMiddleware, createRequirePermissionMiddleware, createRequireRoleMiddleware, createEntityHelpers, type EntityContext, type EntityContextMiddlewareOptions, } from './middleware';
32
+ export { generateEntitySlug, generateInvitationToken, normalizeSlug, validateSlug, calculateInvitationExpiry, } from './utils';
33
+ export { runEntityMigration, rollbackEntityMigration, type MigrationConfig, } from './migrations';
34
+ export { EntityType, EntityRole, InvitationStatus, ROLE_PERMISSIONS, type Entity, type EntityWithRole, type EntityMember, type EntityMemberUser, type EntityInvitation, type EntityPermissions, type CreateEntityRequest, type UpdateEntityRequest, type InviteMemberRequest, type UpdateMemberRoleRequest, } from './types';
35
+ export type { EntityHelperConfig, InvitationHelperConfig, EntityOperationResult, ListEntitiesOptions, ListMembersOptions, ListInvitationsOptions, } from './types';
36
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAGH,OAAO,EAEL,mBAAmB,EACnB,yBAAyB,EACzB,wBAAwB,EACxB,8BAA8B,EAC9B,4BAA4B,EAC5B,kCAAkC,EAElC,QAAQ,EACR,aAAa,EACb,iBAAiB,EAEjB,KAAK,YAAY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