@develit-services/rbac 0.0.2 → 0.1.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.
@@ -1,362 +0,0 @@
1
- 'use strict';
2
-
3
- const zod = require('zod');
4
-
5
- const TEST_SCOPES = [
6
- "test.read",
7
- "test.edit",
8
- "test.delete",
9
- "test.{jwt.organizationId}.read",
10
- "test.{jwt.user.rawUserMetaData.organizationId}.read",
11
- "test.{jwt.user.rawUserMetaData.organizationId}.edit",
12
- "test.{param.resourceId}.read",
13
- "test.organization.{jwt.user.rawUserMetaData.organizationId}.resource.{jwt.user.rawUserMetaData.organizationId}.read",
14
- "test.organization.{jwt.user.rawUserMetaData.organizationId}.branch.{jwt.userData.organizationBranchId}.read",
15
- "test.{invalid}.scope",
16
- "test.{}.scope",
17
- "test.{jwt.}.scope",
18
- "test.{.key}.scope"
19
- ];
20
- const SCOPES = [
21
- "tickets.read",
22
- "tickets.{jwt.user.rawUserMetaData.organizationId}.read",
23
- "tickets.create",
24
- "tickets.edit",
25
- "tickets.delete",
26
- "tickets.archive",
27
- "tickets.automations.pause",
28
- "tickets.automations.resume",
29
- "tickets.dependencies.read",
30
- "tickets.dependencies.create",
31
- "tickets.dependencies.edit",
32
- "tickets.dependencies.delete",
33
- "tickets.confirmation.send",
34
- "tickets.confirmation.download",
35
- "tickets.payments.create",
36
- "tickets.payments.read",
37
- "tickets.payments.edit",
38
- "tickets.payments.delete",
39
- "tickets.payments.confirmation.send",
40
- "tickets.payments.confirmation.download",
41
- "tickets.logs.read",
42
- "tickets.logs.create",
43
- "tickets.logs.delete",
44
- "users.read",
45
- "users.create",
46
- "users.edit",
47
- "users.delete",
48
- "users.archive",
49
- "users.password.reset.send",
50
- "users.permissions.read",
51
- "users.permissions.assign",
52
- "users.permissions.delete",
53
- "users.2fa.enable",
54
- "users.2fa.disable",
55
- "users.logs.read",
56
- "users.logs.create",
57
- "users.logs.delete",
58
- "traders.read",
59
- "traders.create",
60
- "traders.edit",
61
- "traders.delete",
62
- "traders.logs",
63
- "clients.read",
64
- "organization.{jwt.user.rawUserMetaData.organizationId}.clients.read",
65
- "clients.create",
66
- "clients.edit",
67
- "clients.delete",
68
- "clients.pin.read",
69
- // read client pin
70
- "clients.pin.edit",
71
- // edit client pin
72
- "clients.limits.read",
73
- // read client limits
74
- "clients.limits.edit",
75
- // edit client limits
76
- "clients.trader.assign",
77
- "clients.trader.edit",
78
- "clients.logs.read",
79
- "clients.logs.create",
80
- "clients.logs.delete",
81
- "roles.read",
82
- "roles.create",
83
- "roles.edit",
84
- "roles.delete",
85
- "roles.permissions.assign",
86
- // assign permissions to roles
87
- "roles.permissions.delete",
88
- // delete permissions from roles
89
- "roles.logs.read",
90
- "roles.logs.create",
91
- "roles.logs.delete",
92
- "roles.users.read",
93
- // read users assigned to roles
94
- "accounts.read",
95
- "accounts.create",
96
- "accounts.edit",
97
- "accounts.delete",
98
- "accounts.archive",
99
- "accounts.balance",
100
- "accounts.identifiers.create",
101
- "accounts.identifiers.read",
102
- "accounts.identifiers.edit",
103
- "accounts.identifiers.delete",
104
- "accounts.transactions.read",
105
- "accounts.logs.read",
106
- "accounts.logs.create",
107
- "accounts.logs.delete",
108
- ...TEST_SCOPES
109
- ];
110
- const LABELED_SCOPES = [
111
- { label: "Zobrazit tiket", value: "tickets.read" },
112
- { label: "Vytvo\u0159it tiket", value: "tickets.create" },
113
- { label: "Upravit tiket", value: "tickets.edit" },
114
- { label: "Smazat tiket", value: "tickets.delete" },
115
- { label: "Archivovat tiket", value: "tickets.archive" },
116
- {
117
- label: "Pozastavit automatizaci tiketu",
118
- value: "tickets.automations.pause"
119
- },
120
- { label: "Obnovit automatizaci tiketu", value: "tickets.automations.resume" },
121
- { label: "Zobrazit z\xE1vislosti tiket\u016F", value: "tickets.dependencies.read" },
122
- { label: "Vytvo\u0159it z\xE1vislosti tiket\u016F", value: "tickets.dependencies.create" },
123
- { label: "Upravit z\xE1vislosti tiket\u016F", value: "tickets.dependencies.edit" },
124
- { label: "Smazat z\xE1vislosti tiket\u016F", value: "tickets.dependencies.delete" },
125
- { label: "Poslat potvrzen\xED tiketu", value: "tickets.confirmation.send" },
126
- {
127
- label: "St\xE1hnout potvrzen\xED tiketu",
128
- value: "tickets.confirmation.download"
129
- },
130
- { label: "Vytvo\u0159it platbu tiketu", value: "tickets.payments.create" },
131
- { label: "Zobrazit platby tiketu", value: "tickets.payments.read" },
132
- { label: "Upravit platby tiketu", value: "tickets.payments.edit" },
133
- { label: "Smazat platby tiketu", value: "tickets.payments.delete" },
134
- {
135
- label: "Poslat potvrzen\xED platby tiketu",
136
- value: "tickets.payments.confirmation.send"
137
- },
138
- {
139
- label: "St\xE1hnout potvrzen\xED platby tiketu",
140
- value: "tickets.payments.confirmation.download"
141
- },
142
- { label: "Zobrazit logy tiketu", value: "tickets.logs.read" },
143
- { label: "Vytvo\u0159it logy tiketu", value: "tickets.logs.create" },
144
- { label: "Smazat logy tiketu", value: "tickets.logs.delete" },
145
- { label: "Zobrazit obchodn\xEDky", value: "traders.read" },
146
- { label: "Vytvo\u0159it obchodn\xEDky", value: "traders.create" },
147
- { label: "Upravit obchodn\xEDky", value: "traders.edit" },
148
- { label: "Smazat obchodn\xEDky", value: "traders.delete" },
149
- { label: "Logy obchodn\xEDk\u016F", value: "traders.logs" },
150
- { label: "Zobrazit klienty", value: "clients.read" },
151
- { label: "Vytvo\u0159it klienty", value: "clients.create" },
152
- { label: "Upravit klienty", value: "clients.edit" },
153
- { label: "Smazat klienty", value: "clients.delete" },
154
- { label: "Zobrazit PIN klienta", value: "clients.pin.read" },
155
- { label: "Upravit PIN klienta", value: "clients.pin.edit" },
156
- { label: "Zobrazit limity klienta", value: "clients.limits.read" },
157
- { label: "Upravit limity klienta", value: "clients.limits.edit" },
158
- { label: "P\u0159i\u0159adit obchodn\xEDka klientovi", value: "clients.trader.assign" },
159
- { label: "Upravit obchodn\xEDka klienta", value: "clients.trader.edit" },
160
- { label: "Zobrazit logy klient\u016F", value: "clients.logs.read" },
161
- { label: "Vytvo\u0159it logy klient\u016F", value: "clients.logs.create" },
162
- { label: "Smazat logy klient\u016F", value: "clients.logs.delete" },
163
- { label: "Zobrazit u\u017Eivatele", value: "users.read" },
164
- { label: "Vytvo\u0159it u\u017Eivatele", value: "users.create" },
165
- { label: "Upravit u\u017Eivatele", value: "users.edit" },
166
- { label: "Smazat u\u017Eivatele", value: "users.delete" },
167
- { label: "Archivovat u\u017Eivatele", value: "users.archive" },
168
- { label: "Poslat reset hesla", value: "users.password.reset.send" },
169
- { label: "Zobrazit opr\xE1vn\u011Bn\xED u\u017Eivatel\u016F", value: "users.permissions.read" },
170
- { label: "P\u0159i\u0159adit opr\xE1vn\u011Bn\xED u\u017Eivatel\u016Fm", value: "users.permissions.assign" },
171
- { label: "Odebrat opr\xE1vn\u011Bn\xED u\u017Eivatel\u016Fm", value: "users.permissions.delete" },
172
- { label: "Povolit 2FA u\u017Eivatel\u016Fm", value: "users.2fa.enable" },
173
- { label: "Zak\xE1zat 2FA u\u017Eivatel\u016Fm", value: "users.2fa.disable" },
174
- { label: "Zobrazit logy u\u017Eivatel\u016F", value: "users.logs.read" },
175
- { label: "Vytvo\u0159it logy u\u017Eivatel\u016F", value: "users.logs.create" },
176
- { label: "Smazat logy u\u017Eivatel\u016F", value: "users.logs.delete" },
177
- { label: "Zobrazit role", value: "roles.read" },
178
- { label: "Vytvo\u0159it role", value: "roles.create" },
179
- { label: "Upravit role", value: "roles.edit" },
180
- { label: "Smazat role", value: "roles.delete" },
181
- { label: "P\u0159i\u0159adit opr\xE1vn\u011Bn\xED rol\xEDm", value: "roles.permissions.assign" },
182
- { label: "Odebrat opr\xE1vn\u011Bn\xED rol\xEDm", value: "roles.permissions.delete" },
183
- { label: "Zobrazit logy rol\xED", value: "roles.logs.read" },
184
- { label: "Vytvo\u0159it logy rol\xED", value: "roles.logs.create" },
185
- { label: "Smazat logy rol\xED", value: "roles.logs.delete" },
186
- { label: "Zobrazit u\u017Eivatele p\u0159i\u0159azen\xE9 k rol\xEDm", value: "roles.users.read" },
187
- { label: "Zobrazit \xFA\u010Dty", value: "accounts.read" },
188
- { label: "Vytvo\u0159it \xFA\u010Dty", value: "accounts.create" },
189
- { label: "Upravit \xFA\u010Dty", value: "accounts.edit" },
190
- { label: "Smazat \xFA\u010Dty", value: "accounts.delete" },
191
- { label: "Archivovat \xFA\u010Dty", value: "accounts.archive" },
192
- { label: "Zobrazit z\u016Fstatek \xFA\u010Dtu", value: "accounts.balance" },
193
- {
194
- label: "Vytvo\u0159it identifik\xE1tory \xFA\u010Dtu",
195
- value: "accounts.identifiers.create"
196
- },
197
- { label: "Zobrazit identifik\xE1tory \xFA\u010Dtu", value: "accounts.identifiers.read" },
198
- { label: "Upravit identifik\xE1tory \xFA\u010Dtu", value: "accounts.identifiers.edit" },
199
- { label: "Smazat identifik\xE1tory \xFA\u010Dtu", value: "accounts.identifiers.delete" },
200
- { label: "Zobrazit transakce \xFA\u010Dtu", value: "accounts.transactions.read" },
201
- { label: "Zobrazit logy \xFA\u010Dt\u016F", value: "accounts.logs.read" },
202
- { label: "Vytvo\u0159it logy \xFA\u010Dt\u016F", value: "accounts.logs.create" },
203
- { label: "Smazat logy \xFA\u010Dt\u016F", value: "accounts.logs.delete" }
204
- ];
205
-
206
- const assignRoleToUserInputSchema = zod.z.object({
207
- userId: zod.z.uuid(),
208
- roleId: zod.z.uuid()
209
- });
210
-
211
- const assignRolesToUserInputSchema = zod.z.object({
212
- userId: zod.z.uuid(),
213
- roles: zod.z.array(zod.z.uuid())
214
- });
215
-
216
- const createRoleInputSchema = zod.z.object({
217
- name: zod.z.string()
218
- });
219
-
220
- const deleteRoleInputSchema = zod.z.object({
221
- id: zod.z.uuid()
222
- });
223
-
224
- const getUserPermissionsInputSchema = zod.z.object({
225
- userId: zod.z.uuid()
226
- });
227
-
228
- const grantScopeToRoleInputSchema = zod.z.object({
229
- roleId: zod.z.uuid(),
230
- scope: zod.z.enum(SCOPES),
231
- resourceId: zod.z.string().optional()
232
- });
233
-
234
- const grantScopeToUserInputSchema = zod.z.object({
235
- userId: zod.z.uuid(),
236
- scope: zod.z.enum(SCOPES),
237
- resourceId: zod.z.string().optional()
238
- });
239
-
240
- const grantScopesToUserInputSchema = zod.z.object({
241
- userId: zod.z.uuid(),
242
- scopes: zod.z.array(
243
- zod.z.object({
244
- scope: zod.z.enum(SCOPES),
245
- resourceId: zod.z.string().optional()
246
- })
247
- )
248
- });
249
-
250
- const revokeRoleFromUserInputSchema = zod.z.object({
251
- userId: zod.z.uuid(),
252
- roleId: zod.z.uuid()
253
- });
254
-
255
- const revokeScopeFromRoleInputSchema = zod.z.object({
256
- roleId: zod.z.uuid(),
257
- scope: zod.z.enum(SCOPES),
258
- resourceId: zod.z.string().optional()
259
- });
260
-
261
- const revokeScopeFromUserInputSchema = zod.z.object({
262
- userId: zod.z.uuid(),
263
- scope: zod.z.enum(SCOPES),
264
- resourceId: zod.z.string().optional()
265
- });
266
-
267
- const updateRoleInputSchema = zod.z.object({
268
- id: zod.z.uuid(),
269
- name: zod.z.string()
270
- });
271
-
272
- const userDataSchema = zod.z.object({
273
- referenceId: zod.z.string(),
274
- email: zod.z.string().optional(),
275
- role: zod.z.string().optional()
276
- });
277
- const jwtPayloadSchema = zod.z.object({
278
- sub: zod.z.string(),
279
- user: zod.z.object({
280
- id: zod.z.uuid(),
281
- createdAt: zod.z.date().nullable(),
282
- updatedAt: zod.z.date().nullable(),
283
- deletedAt: zod.z.date().nullable(),
284
- role: zod.z.string(),
285
- email: zod.z.email(),
286
- rawAppMetaData: zod.z.any(),
287
- rawUserMetaData: zod.z.any(),
288
- isSuperAdmin: zod.z.boolean().default(false),
289
- isSsoUser: zod.z.boolean().default(false),
290
- lastSignInAt: zod.z.date().nullable().optional(),
291
- emailConfirmedAt: zod.z.date().nullable().optional(),
292
- confirmationSentAt: zod.z.date().nullable().optional(),
293
- recoverySentAt: zod.z.date().nullable().optional(),
294
- emailChangeToken: zod.z.string().nullable().optional(),
295
- emailChangeSentAt: zod.z.date().nullable().optional(),
296
- isBanned: zod.z.boolean().default(false).nullable().optional()
297
- }),
298
- iat: zod.z.number(),
299
- exp: zod.z.number(),
300
- userData: userDataSchema.optional()
301
- });
302
-
303
- const accessRequestSchema = zod.z.object({
304
- scope: zod.z.enum(SCOPES),
305
- // 'exchange-offices.{jwt.exchangeOfficeId}.read'
306
- resourceId: zod.z.string().optional(),
307
- // '123'
308
- resourcePath: zod.z.string().optional()
309
- // 'exchange-offices.333.read' - only needed for scopes with placeholders
310
- });
311
- const verifyAccessInputSchema = zod.z.object({
312
- userId: zod.z.uuid(),
313
- accessRequests: zod.z.array(accessRequestSchema),
314
- jwt: jwtPayloadSchema.extend({
315
- createdAt: zod.z.coerce.date().nullable().optional(),
316
- updatedAt: zod.z.coerce.date().nullable().optional(),
317
- deletedAt: zod.z.coerce.date().nullable().optional(),
318
- lastSignInAt: zod.z.coerce.date().nullable().optional(),
319
- emailConfirmedAt: zod.z.coerce.date().nullable().optional(),
320
- confirmationSentAt: zod.z.coerce.date().nullable().optional(),
321
- recoverySentAt: zod.z.coerce.date().nullable().optional(),
322
- emailChangeSentAt: zod.z.coerce.date().nullable().optional(),
323
- user: jwtPayloadSchema.shape.user.extend({
324
- createdAt: zod.z.coerce.date().nullable().optional(),
325
- updatedAt: zod.z.coerce.date().nullable().optional(),
326
- lastSignInAt: zod.z.coerce.date().nullable().optional(),
327
- emailConfirmedAt: zod.z.coerce.date().nullable().optional()
328
- })
329
- }).optional()
330
- });
331
-
332
- const verifyScopeInputSchema = zod.z.object({
333
- scopes: zod.z.array(zod.z.string()),
334
- resourceId: zod.z.string().optional(),
335
- jwt: zod.z.object({
336
- sub: zod.z.uuid(),
337
- rbac: zod.z.object({
338
- roles: zod.z.array(zod.z.string()).optional()
339
- })
340
- })
341
- });
342
- const verifyScopeOutputSchema = zod.z.object({
343
- isVerified: zod.z.boolean().default(false)
344
- });
345
-
346
- exports.LABELED_SCOPES = LABELED_SCOPES;
347
- exports.SCOPES = SCOPES;
348
- exports.assignRoleToUserInputSchema = assignRoleToUserInputSchema;
349
- exports.assignRolesToUserInputSchema = assignRolesToUserInputSchema;
350
- exports.createRoleInputSchema = createRoleInputSchema;
351
- exports.deleteRoleInputSchema = deleteRoleInputSchema;
352
- exports.getUserPermissionsInputSchema = getUserPermissionsInputSchema;
353
- exports.grantScopeToRoleInputSchema = grantScopeToRoleInputSchema;
354
- exports.grantScopeToUserInputSchema = grantScopeToUserInputSchema;
355
- exports.grantScopesToUserInputSchema = grantScopesToUserInputSchema;
356
- exports.revokeRoleFromUserInputSchema = revokeRoleFromUserInputSchema;
357
- exports.revokeScopeFromRoleInputSchema = revokeScopeFromRoleInputSchema;
358
- exports.revokeScopeFromUserInputSchema = revokeScopeFromUserInputSchema;
359
- exports.updateRoleInputSchema = updateRoleInputSchema;
360
- exports.verifyAccessInputSchema = verifyAccessInputSchema;
361
- exports.verifyScopeInputSchema = verifyScopeInputSchema;
362
- exports.verifyScopeOutputSchema = verifyScopeOutputSchema;