@nu-art/permissions-backend 0.401.8 → 0.500.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.
- package/PermissionKey_BE.d.ts +9 -6
- package/PermissionKey_BE.js +20 -9
- package/RequirePermission.d.ts +21 -0
- package/RequirePermission.js +47 -0
- package/_entity/permission-access-level/ModuleBE_PermissionAccessLevelDB.d.ts +5 -9
- package/_entity/permission-access-level/ModuleBE_PermissionAccessLevelDB.js +1 -7
- package/_entity/permission-access-level/module-pack.d.ts +1 -1
- package/_entity/permission-access-level/module-pack.js +2 -2
- package/_entity/permission-api/ModuleBE_PermissionAPIDB.d.ts +6 -8
- package/_entity/permission-api/ModuleBE_PermissionAPIDB.js +4 -4
- package/_entity/permission-api/module-pack.d.ts +1 -1
- package/_entity/permission-api/module-pack.js +2 -2
- package/_entity/permission-domain/ModuleBE_PermissionDomainDB.d.ts +4 -10
- package/_entity/permission-domain/ModuleBE_PermissionDomainDB.js +1 -4
- package/_entity/permission-domain/module-pack.d.ts +1 -1
- package/_entity/permission-domain/module-pack.js +2 -2
- package/_entity/permission-group/ModuleBE_PermissionGroupDB.d.ts +5 -7
- package/_entity/permission-group/ModuleBE_PermissionGroupDB.js +10 -7
- package/_entity/permission-group/module-pack.d.ts +1 -1
- package/_entity/permission-group/module-pack.js +2 -2
- package/_entity/permission-project/ModuleBE_PermissionProjectDB.d.ts +4 -6
- package/_entity/permission-project/ModuleBE_PermissionProjectDB.js +1 -1
- package/_entity/permission-project/module-pack.d.ts +1 -1
- package/_entity/permission-project/module-pack.js +2 -2
- package/_entity/permission-user/ModuleBE_PermissionUserAPI.d.ts +4 -3
- package/_entity/permission-user/ModuleBE_PermissionUserAPI.js +63 -10
- package/_entity/permission-user/ModuleBE_PermissionUserDB.d.ts +8 -10
- package/_entity/permission-user/ModuleBE_PermissionUserDB.js +33 -18
- package/core/external-api-paths.d.ts +13 -0
- package/core/external-api-paths.js +13 -0
- package/core/function-permission-registry.d.ts +25 -0
- package/core/function-permission-registry.js +50 -0
- package/core/utils.d.ts +4 -4
- package/core/utils.js +7 -7
- package/index.d.ts +5 -0
- package/index.js +5 -0
- package/modules/ModuleBE_Permissions.d.ts +10 -4
- package/modules/ModuleBE_Permissions.js +365 -264
- package/modules/ModuleBE_PermissionsAssert.d.ts +20 -3
- package/modules/ModuleBE_PermissionsAssert.js +271 -205
- package/modules/consts.d.ts +2 -2
- package/modules/consts.js +5 -5
- package/modules/index.d.ts +1 -0
- package/modules/index.js +1 -0
- package/package.json +13 -12
- package/permissions-wire.d.ts +46 -0
- package/permissions-wire.js +47 -0
- package/permissions.js +29 -31
- package/types.d.ts +3 -3
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { ModuleBE_BaseDB } from '@nu-art/db-api-backend';
|
|
2
|
+
import { MemKey_ServerApi } from '@nu-art/http-server';
|
|
3
|
+
import { DBDef_PermissionUser, toPermissionGroupId } from '@nu-art/permissions-shared';
|
|
4
|
+
import { getGlobalEnvConfigRef, getServiceAccountsProvider } from '../../permissions-wire.js';
|
|
5
|
+
import { _keys, ApiException, batchAction, batchActionParallel, dbObjectToId, exists, filterDuplicates, filterInstances, filterKeys, JwtTools, merge, Year } from '@nu-art/ts-common';
|
|
4
6
|
import { ModuleBE_PermissionGroupDB } from '../permission-group/ModuleBE_PermissionGroupDB.js';
|
|
5
7
|
import { MemKey_AccountId, ModuleBE_AccountDB, ModuleBE_SessionDB } from '@nu-art/user-account-backend';
|
|
6
8
|
import { MemKey_UserPermissions } from '../../consts.js';
|
|
7
|
-
import { dispatcher_collectServiceAccounts } from '@nu-art/thunderstorm-backend/modules/_tdb/service-accounts';
|
|
8
9
|
export class ModuleBE_PermissionUserDB_Class extends ModuleBE_BaseDB {
|
|
9
10
|
defaultPermissionGroups;
|
|
10
11
|
constructor() {
|
|
@@ -12,14 +13,17 @@ export class ModuleBE_PermissionUserDB_Class extends ModuleBE_BaseDB {
|
|
|
12
13
|
}
|
|
13
14
|
__performProjectSetup() {
|
|
14
15
|
return {
|
|
15
|
-
priority:
|
|
16
|
+
priority: 200,
|
|
16
17
|
processor: async () => {
|
|
17
18
|
const accounts = await ModuleBE_AccountDB.query.where({});
|
|
18
|
-
|
|
19
|
+
// Permission user _id is 1:1 with account _id; query.all expects permission user ids.
|
|
20
|
+
const permissionUserIds = accounts.map(dbObjectToId);
|
|
21
|
+
const permissionsUser = await this.query.all(permissionUserIds);
|
|
19
22
|
const usersToUpsert = [];
|
|
20
23
|
const usersToDelete = [];
|
|
21
24
|
permissionsUser.forEach((user, index) => {
|
|
22
25
|
if (exists(user)) {
|
|
26
|
+
// Same 1:1 design: account id and permission user id are the same value.
|
|
23
27
|
if (!exists(accounts.find(account => account._id === user._id)))
|
|
24
28
|
usersToDelete.push(user);
|
|
25
29
|
return;
|
|
@@ -32,7 +36,8 @@ export class ModuleBE_PermissionUserDB_Class extends ModuleBE_BaseDB {
|
|
|
32
36
|
await this.set.all(usersToUpsert);
|
|
33
37
|
await this.delete.all(usersToDelete);
|
|
34
38
|
// This stage updates the rtdb's config- which is why it's last. Changing the rtdb's config kills the server.
|
|
35
|
-
const
|
|
39
|
+
const provider = getServiceAccountsProvider();
|
|
40
|
+
const serviceAccounts = provider ? await provider() : [];
|
|
36
41
|
await this.createSystemServiceAccount(serviceAccounts);
|
|
37
42
|
}
|
|
38
43
|
};
|
|
@@ -74,10 +79,11 @@ export class ModuleBE_PermissionUserDB_Class extends ModuleBE_BaseDB {
|
|
|
74
79
|
//todo check for duplications in data
|
|
75
80
|
}
|
|
76
81
|
async postWriteProcessing(data, actionType) {
|
|
77
|
-
const deleted =
|
|
78
|
-
const updated =
|
|
79
|
-
const
|
|
80
|
-
const
|
|
82
|
+
const deleted = data.deleted ? (Array.isArray(data.deleted) ? data.deleted : [data.deleted]) : [];
|
|
83
|
+
const updated = data.updated ? (Array.isArray(data.updated) ? data.updated : [data.updated]) : [];
|
|
84
|
+
const before = data.before ? (Array.isArray(data.before) ? data.before : [data.before]) : [];
|
|
85
|
+
const beforeIds = before.map(b => b._id);
|
|
86
|
+
const accountIdToInvalidate = filterDuplicates(filterInstances([...deleted, ...updated].map(i => i._id))).filter(id => beforeIds.includes(id));
|
|
81
87
|
await this.rotateSession(accountIdToInvalidate);
|
|
82
88
|
}
|
|
83
89
|
insertIfNotExist = async (uiAccount, transaction) => {
|
|
@@ -87,8 +93,10 @@ export class ModuleBE_PermissionUserDB_Class extends ModuleBE_BaseDB {
|
|
|
87
93
|
? filterInstances(await ModuleBE_PermissionGroupDB.query.all(defaultPermissionGroups.map(item => item.groupId)))
|
|
88
94
|
: [];
|
|
89
95
|
this.logInfo(`Received ${defaultPermissionGroups.length} groups to assign, ${permissionGroups.length} of which exist`);
|
|
96
|
+
// Permission user _id is 1:1 with account _id (design); cast required across brands.
|
|
97
|
+
const permissionUserId = uiAccount._id;
|
|
90
98
|
const permissionsUserToCreate = {
|
|
91
|
-
_id:
|
|
99
|
+
_id: permissionUserId,
|
|
92
100
|
groups: permissionGroups.map(group => ({ groupId: group._id })),
|
|
93
101
|
_auditorId: MemKey_AccountId.get()
|
|
94
102
|
};
|
|
@@ -99,7 +107,9 @@ export class ModuleBE_PermissionUserDB_Class extends ModuleBE_BaseDB {
|
|
|
99
107
|
async assignPermissions(body) {
|
|
100
108
|
if (!body.targetAccountIds.length)
|
|
101
109
|
throw new ApiException(400, `Asked to modify permissions but provided no users to modify permissions of.`);
|
|
102
|
-
|
|
110
|
+
// Permission user id is 1:1 with account id (design); cast required across brands.
|
|
111
|
+
const permissionUserIds = body.targetAccountIds;
|
|
112
|
+
const usersToGiveTo = filterInstances(await this.query.all(permissionUserIds));
|
|
103
113
|
// console.log('assignPermissions target accounts ');
|
|
104
114
|
// console.log(await this.query.custom(_EmptyQuery));
|
|
105
115
|
if (!usersToGiveTo.length || usersToGiveTo.length !== body.targetAccountIds.length) {
|
|
@@ -154,7 +164,7 @@ export class ModuleBE_PermissionUserDB_Class extends ModuleBE_BaseDB {
|
|
|
154
164
|
this.logInfoBold('Creating Service Accounts: ', serviceAccounts);
|
|
155
165
|
// @ts-ignore
|
|
156
166
|
const tokenCreator = ModuleBE_AccountDB.token.create;
|
|
157
|
-
const envConfigRef =
|
|
167
|
+
const envConfigRef = getGlobalEnvConfigRef();
|
|
158
168
|
const updatedConfig = {};
|
|
159
169
|
//Run over all service accounts
|
|
160
170
|
for (const serviceAccount of serviceAccounts) {
|
|
@@ -173,9 +183,9 @@ export class ModuleBE_PermissionUserDB_Class extends ModuleBE_BaseDB {
|
|
|
173
183
|
this.logInfo('NOTICE: querySafeAccount failed, creating accounts');
|
|
174
184
|
account = await ModuleBE_AccountDB.account.create(accountsToRequest);
|
|
175
185
|
}
|
|
176
|
-
// Assign permissions groups to service account
|
|
186
|
+
// Assign permissions groups to service account; permission user _id is 1:1 with account _id
|
|
177
187
|
const permissionsUser = await ModuleBE_PermissionUserDB.query.uniqueAssert({ _id: account._id });
|
|
178
|
-
permissionsUser.groups = serviceAccount.groupIds?.map(
|
|
188
|
+
permissionsUser.groups = serviceAccount.groupIds?.map(gid => ({ groupId: toPermissionGroupId(gid) })) || [];
|
|
179
189
|
await ModuleBE_PermissionUserDB.set.item(permissionsUser);
|
|
180
190
|
//Service accounts are only allowed to have one session... but this isn't the defined place to be a cop about it
|
|
181
191
|
const sessions = await ModuleBE_AccountDB.account.getSessions(account);
|
|
@@ -201,7 +211,7 @@ export class ModuleBE_PermissionUserDB_Class extends ModuleBE_BaseDB {
|
|
|
201
211
|
})
|
|
202
212
|
};
|
|
203
213
|
}
|
|
204
|
-
if (_keys(updatedConfig).length > 0)
|
|
214
|
+
if (_keys(updatedConfig).length > 0 && envConfigRef)
|
|
205
215
|
MemKey_ServerApi.get().addPostCallAction(async () => {
|
|
206
216
|
const currentConfig = await envConfigRef.get({});
|
|
207
217
|
await envConfigRef.set(merge(currentConfig, updatedConfig));
|
|
@@ -220,7 +230,12 @@ export class ModuleBE_PermissionUserDB_Class extends ModuleBE_BaseDB {
|
|
|
220
230
|
return isExpired ? undefined : session;
|
|
221
231
|
})));
|
|
222
232
|
//TODO END
|
|
223
|
-
|
|
233
|
+
this.logWarning(`#### Rotating ${validSessions.length} Sessions! ####`);
|
|
234
|
+
await batchAction(validSessions, 500, async (sessions) => {
|
|
235
|
+
await this.runTransaction(async (t) => {
|
|
236
|
+
await Promise.all(sessions.map(session => ModuleBE_SessionDB._session.rotate.reissue.bySession(session, t)));
|
|
237
|
+
});
|
|
238
|
+
});
|
|
224
239
|
}
|
|
225
240
|
}
|
|
226
241
|
export const ModuleBE_PermissionUserDB = new ModuleBE_PermissionUserDB_Class();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path strings for external APIs referenced in permission domains.
|
|
3
|
+
* Replaces imports from thunderstorm-shared (ApiDef_ActionProcessing, ApiDef_CollectionActions, ApiDef_SyncEnv).
|
|
4
|
+
* Update these if the corresponding v2 packages change their routes.
|
|
5
|
+
*/
|
|
6
|
+
export declare const Path_ActionProcessor_List = "v1/action-processor/list";
|
|
7
|
+
export declare const Path_ActionProcessor_Execute = "v1/action-processor/execute";
|
|
8
|
+
export declare const Path_CollectionActions_UpgradeAll = "v1/collection-actions/upgrade/all";
|
|
9
|
+
export declare const Path_SyncEnv_FetchBackupMetadata = "v1/sync-env/fetch-backup-metadata";
|
|
10
|
+
export declare const Path_SyncEnv_CreateBackup = "v1/sync-env/create-backup-v2";
|
|
11
|
+
export declare const Path_SyncEnv_SyncFromEnvBackup = "v1/sync-env/fetch-from-env-v2";
|
|
12
|
+
export declare const Path_SyncEnv_SyncFirebaseFromBackup = "v1/sync-env/fetch-firebase-backup";
|
|
13
|
+
export declare const Path_SyncEnv_SyncToEnv = "v1/sync-env/sync-to-env";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path strings for external APIs referenced in permission domains.
|
|
3
|
+
* Replaces imports from thunderstorm-shared (ApiDef_ActionProcessing, ApiDef_CollectionActions, ApiDef_SyncEnv).
|
|
4
|
+
* Update these if the corresponding v2 packages change their routes.
|
|
5
|
+
*/
|
|
6
|
+
export const Path_ActionProcessor_List = 'v1/action-processor/list';
|
|
7
|
+
export const Path_ActionProcessor_Execute = 'v1/action-processor/execute';
|
|
8
|
+
export const Path_CollectionActions_UpgradeAll = 'v1/collection-actions/upgrade/all';
|
|
9
|
+
export const Path_SyncEnv_FetchBackupMetadata = 'v1/sync-env/fetch-backup-metadata';
|
|
10
|
+
export const Path_SyncEnv_CreateBackup = 'v1/sync-env/create-backup-v2';
|
|
11
|
+
export const Path_SyncEnv_SyncFromEnvBackup = 'v1/sync-env/fetch-from-env-v2';
|
|
12
|
+
export const Path_SyncEnv_SyncFirebaseFromBackup = 'v1/sync-env/fetch-firebase-backup';
|
|
13
|
+
export const Path_SyncEnv_SyncToEnv = 'v1/sync-env/sync-to-env';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { PermissionScope } from '@nu-art/permissions-shared';
|
|
2
|
+
export type FunctionPermissionDef = {
|
|
3
|
+
id: string;
|
|
4
|
+
scopeKey: string;
|
|
5
|
+
value: string;
|
|
6
|
+
/** Set on server load when domains/levels are created from registry. */
|
|
7
|
+
domainId?: string;
|
|
8
|
+
/** Set on server load when domains/levels are created from registry. */
|
|
9
|
+
levelId?: string;
|
|
10
|
+
/** Numeric level value for assert (user level >= required). Set on server load. */
|
|
11
|
+
levelValue?: number;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Registers a function permission (scope + value). Called from @RequirePermission decorator init.
|
|
15
|
+
* Returns the same def if (scopeKey, value) was already registered (stable id).
|
|
16
|
+
*/
|
|
17
|
+
export declare function registerFunctionPermission(scope: PermissionScope, value: string): FunctionPermissionDef;
|
|
18
|
+
/**
|
|
19
|
+
* Returns all registered function permissions for server load (create domains/levels in DB).
|
|
20
|
+
*/
|
|
21
|
+
export declare function getRegisteredFunctionPermissions(): FunctionPermissionDef[];
|
|
22
|
+
/**
|
|
23
|
+
* Returns the def for a given (scopeKey, value), or undefined if not registered.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getFunctionPermissionDef(scopeKey: string, value: string): FunctionPermissionDef | undefined;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Permissions management system, define access level for each of
|
|
3
|
+
* your server apis, and restrict users by giving them access levels
|
|
4
|
+
*
|
|
5
|
+
* Copyright (C) 2020 Adam van der Kruk aka TacB0sS
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { md5 } from '@nu-art/ts-common';
|
|
20
|
+
const registry = new Map();
|
|
21
|
+
function compositeKey(scopeKey, value) {
|
|
22
|
+
return `${scopeKey}\0${value}`;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Registers a function permission (scope + value). Called from @RequirePermission decorator init.
|
|
26
|
+
* Returns the same def if (scopeKey, value) was already registered (stable id).
|
|
27
|
+
*/
|
|
28
|
+
export function registerFunctionPermission(scope, value) {
|
|
29
|
+
const scopeKey = scope.key;
|
|
30
|
+
const key = compositeKey(scopeKey, value);
|
|
31
|
+
const existing = registry.get(key);
|
|
32
|
+
if (existing)
|
|
33
|
+
return existing;
|
|
34
|
+
const id = md5(`function-permission/${scopeKey}/${value}`);
|
|
35
|
+
const def = { id, scopeKey, value };
|
|
36
|
+
registry.set(key, def);
|
|
37
|
+
return def;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns all registered function permissions for server load (create domains/levels in DB).
|
|
41
|
+
*/
|
|
42
|
+
export function getRegisteredFunctionPermissions() {
|
|
43
|
+
return [...registry.values()];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns the def for a given (scopeKey, value), or undefined if not registered.
|
|
47
|
+
*/
|
|
48
|
+
export function getFunctionPermissionDef(scopeKey, value) {
|
|
49
|
+
return registry.get(compositeKey(scopeKey, value));
|
|
50
|
+
}
|
package/core/utils.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { TypedMap
|
|
2
|
-
import { DefaultDef_Group, PreDBAccessLevel } from '@nu-art/permissions-shared';
|
|
1
|
+
import { TypedMap } from '@nu-art/ts-common';
|
|
2
|
+
import { DatabaseDef_PermissionDomain, DefaultDef_Group, PreDBAccessLevel } from '@nu-art/permissions-shared';
|
|
3
3
|
import { PermissionKey_BE } from '../PermissionKey_BE.js';
|
|
4
4
|
import { DefaultDef_Domain, DefaultDef_Package } from '../types.js';
|
|
5
|
-
export declare const Permissions_abTest: (seed:
|
|
5
|
+
export declare const Permissions_abTest: (seed: string, namespace: string, permutations: string[]) => DefaultDef_Package;
|
|
6
6
|
/**
|
|
7
7
|
* Generate automatic BE permission keys for a domain
|
|
8
8
|
* @param accessLevels the relevant access levels to generate keys for
|
|
9
9
|
* @param keyByLevelMapper the key name mapper by access level name
|
|
10
10
|
* @param domainId the domain id to apply in the resolver
|
|
11
11
|
*/
|
|
12
|
-
export declare const generatePermissionKeys: <Key extends string | number | symbol>(accessLevels: PreDBAccessLevel[], keyByLevelMapper: TypedMap<string>, domainId:
|
|
12
|
+
export declare const generatePermissionKeys: <Key extends string | number | symbol>(accessLevels: PreDBAccessLevel[], keyByLevelMapper: TypedMap<string>, domainId: DatabaseDef_PermissionDomain["id"]) => { [key in Key]: PermissionKey_BE<string>; };
|
|
13
13
|
/**
|
|
14
14
|
* Automatic generator for domain default definitions,
|
|
15
15
|
* @param key MUST NEVER CHANGE! the key is the "key" to uniqueness of the entire permission decleration
|
package/core/utils.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { _values, md5 } from '@nu-art/ts-common';
|
|
2
|
-
import { CreateDefaultAccessLevels, DefaultAccessLevel_NoAccess, DefaultAccessLevel_Read } from '@nu-art/permissions-shared';
|
|
2
|
+
import { CreateDefaultAccessLevels, DefaultAccessLevel_NoAccess, DefaultAccessLevel_Read, toPermissionDomainId, toPermissionGroupId } from '@nu-art/permissions-shared';
|
|
3
3
|
import { defaultValueResolverV2, PermissionKey_BE } from '../PermissionKey_BE.js';
|
|
4
4
|
export const Permissions_abTest = (seed, namespace, permutations) => {
|
|
5
5
|
const domains = permutations.map(permutation => {
|
|
6
6
|
const name = `${namespace}/${permutation}`;
|
|
7
7
|
const domain = {
|
|
8
|
-
_id: md5(`${seed}${name}`),
|
|
8
|
+
_id: toPermissionDomainId(md5(`${seed}${name}`)),
|
|
9
9
|
namespace: name,
|
|
10
10
|
permissionKeys: permutations.map(permutation => {
|
|
11
11
|
const initialDataResolver = () => defaultValueResolverV2(domain._id, DefaultAccessLevel_Read.name);
|
|
@@ -19,11 +19,11 @@ export const Permissions_abTest = (seed, namespace, permutations) => {
|
|
|
19
19
|
const name = `${namespace}/${permutation}`;
|
|
20
20
|
const domain = domains[index];
|
|
21
21
|
const group = {
|
|
22
|
-
_id: md5(`${domain._id}/${name}`),
|
|
22
|
+
_id: toPermissionGroupId(md5(`${domain._id}/${name}`)),
|
|
23
23
|
name,
|
|
24
24
|
uiLabel: name,
|
|
25
25
|
accessLevels: {
|
|
26
|
-
[domain.
|
|
26
|
+
[domain.namespace]: DefaultAccessLevel_Read.name,
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
29
|
return group;
|
|
@@ -60,9 +60,9 @@ export const generatePermissionKeys = (accessLevels, keyByLevelMapper, domainId)
|
|
|
60
60
|
*/
|
|
61
61
|
export const generateDomainDefaults = (key, namespace, preDBAccessLevels, permissionKeysByLevel, dbNames) => {
|
|
62
62
|
// Generate the new domain id
|
|
63
|
-
const newDomainId = md5(`domain/${key}`);
|
|
63
|
+
const newDomainId = toPermissionDomainId(md5(`domain/${key}`));
|
|
64
64
|
// Get all default db ready access levels using the provided ones
|
|
65
|
-
const accessLevels = CreateDefaultAccessLevels(
|
|
65
|
+
const accessLevels = CreateDefaultAccessLevels(md5(`domain/${key}`), preDBAccessLevels);
|
|
66
66
|
const keyDefinitions = generatePermissionKeys(preDBAccessLevels, permissionKeysByLevel, newDomainId);
|
|
67
67
|
return {
|
|
68
68
|
domain: {
|
|
@@ -73,7 +73,7 @@ export const generateDomainDefaults = (key, namespace, preDBAccessLevels, permis
|
|
|
73
73
|
dbNames
|
|
74
74
|
},
|
|
75
75
|
groups: accessLevels.map(accessLevel => ({
|
|
76
|
-
_id: md5(`${key}/${accessLevel.name}`),
|
|
76
|
+
_id: toPermissionGroupId(md5(`${key}/${accessLevel.name}`)),
|
|
77
77
|
name: `${namespace}/${accessLevel.name}`,
|
|
78
78
|
uiLabel: `${namespace}/${accessLevel.name}`,
|
|
79
79
|
accessLevels: {
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
export * from './consts.js';
|
|
1
2
|
export * from './core/module-pack.js';
|
|
3
|
+
export * from './permissions-wire.js';
|
|
4
|
+
export * from './core/function-permission-registry.js';
|
|
5
|
+
export * from './RequirePermission.js';
|
|
2
6
|
export * from './modules/index.js';
|
|
7
|
+
export * from './permissions.js';
|
|
3
8
|
export * from './_entity.js';
|
|
4
9
|
export * from './types.js';
|
package/index.js
CHANGED
|
@@ -16,7 +16,12 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
+
export * from './consts.js';
|
|
19
20
|
export * from './core/module-pack.js';
|
|
21
|
+
export * from './permissions-wire.js';
|
|
22
|
+
export * from './core/function-permission-registry.js';
|
|
23
|
+
export * from './RequirePermission.js';
|
|
20
24
|
export * from './modules/index.js';
|
|
25
|
+
export * from './permissions.js';
|
|
21
26
|
export * from './_entity.js';
|
|
22
27
|
export * from './types.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Module, TypedMap } from '@nu-art/ts-common';
|
|
2
|
+
import type { PerformProjectSetup } from '@nu-art/permissions-shared';
|
|
2
3
|
import { DB_PermissionGroup, DB_PermissionProject, DefaultDef_Group, SessionData_Permissions } from '@nu-art/permissions-shared';
|
|
3
4
|
import { BaseSessionClaims, CollectSessionData } from '@nu-art/user-account-backend';
|
|
4
|
-
import { PerformProjectSetup } from '@nu-art/thunderstorm-backend/modules/action-processor/Action_SetupProject';
|
|
5
5
|
import { DefaultDef_Project } from '../types.js';
|
|
6
6
|
export interface CollectPermissionsProjects {
|
|
7
7
|
__collectPermissionsProjects(): DefaultDef_Project;
|
|
@@ -16,13 +16,19 @@ export declare const PermissionGroups_Permissions: DefaultDef_Group[];
|
|
|
16
16
|
export declare const PermissionProject_Permissions: DefaultDef_Project;
|
|
17
17
|
declare class ModuleBE_Permissions_Class extends Module implements CollectSessionData<SessionData_Permissions>, PerformProjectSetup {
|
|
18
18
|
protected init(): void;
|
|
19
|
+
toggleStrictMode(_params?: unknown): Promise<void>;
|
|
20
|
+
createProject(_params?: unknown): Promise<void>;
|
|
19
21
|
__collectSessionData(data: BaseSessionClaims): Promise<SessionData_Permissions>;
|
|
20
22
|
getUserPermissionMap: (userGroups: DB_PermissionGroup[]) => Promise<TypedMap<number>>;
|
|
21
|
-
toggleStrictMode: () => Promise<void>;
|
|
22
23
|
__performProjectSetup(): {
|
|
23
24
|
priority: number;
|
|
24
25
|
processor: () => Promise<void>;
|
|
25
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* Creates domains and access levels from the function-permission registry (populated by @RequirePermission decorators).
|
|
29
|
+
* New (scopeKey, value) pairs get domains/levels created; not assigned to anyone until explicitly assigned.
|
|
30
|
+
*/
|
|
31
|
+
private createDomainsAndLevelsFromFunctionPermissionRegistry;
|
|
26
32
|
createPermissionProjects(projects: DefaultDef_Project[]): Promise<void>;
|
|
27
33
|
/**
|
|
28
34
|
* Creates All the DB_PermissionProject
|
|
@@ -53,8 +59,8 @@ declare class ModuleBE_Permissions_Class extends Module implements CollectSessio
|
|
|
53
59
|
*/
|
|
54
60
|
private createGroups;
|
|
55
61
|
/**
|
|
56
|
-
* Creates All the DB_PermissionApi
|
|
57
|
-
*
|
|
62
|
+
* Creates All the DB_PermissionApi (path-based).
|
|
63
|
+
* @deprecated API collection deprecated; use function-based permissions and @RequirePermission. Domains/levels from function-permission registry instead.
|
|
58
64
|
* @param projects - predefined permissions projects
|
|
59
65
|
* @param domainNameToLevelNameToDBAccessLevel
|
|
60
66
|
*/
|