@nu-art/permissions-backend 0.401.9 → 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.
Files changed (50) hide show
  1. package/PermissionKey_BE.d.ts +9 -6
  2. package/PermissionKey_BE.js +20 -9
  3. package/RequirePermission.d.ts +21 -0
  4. package/RequirePermission.js +47 -0
  5. package/_entity/permission-access-level/ModuleBE_PermissionAccessLevelDB.d.ts +5 -9
  6. package/_entity/permission-access-level/ModuleBE_PermissionAccessLevelDB.js +1 -7
  7. package/_entity/permission-access-level/module-pack.d.ts +1 -1
  8. package/_entity/permission-access-level/module-pack.js +2 -2
  9. package/_entity/permission-api/ModuleBE_PermissionAPIDB.d.ts +6 -8
  10. package/_entity/permission-api/ModuleBE_PermissionAPIDB.js +4 -4
  11. package/_entity/permission-api/module-pack.d.ts +1 -1
  12. package/_entity/permission-api/module-pack.js +2 -2
  13. package/_entity/permission-domain/ModuleBE_PermissionDomainDB.d.ts +4 -10
  14. package/_entity/permission-domain/ModuleBE_PermissionDomainDB.js +1 -4
  15. package/_entity/permission-domain/module-pack.d.ts +1 -1
  16. package/_entity/permission-domain/module-pack.js +2 -2
  17. package/_entity/permission-group/ModuleBE_PermissionGroupDB.d.ts +5 -7
  18. package/_entity/permission-group/ModuleBE_PermissionGroupDB.js +10 -7
  19. package/_entity/permission-group/module-pack.d.ts +1 -1
  20. package/_entity/permission-group/module-pack.js +2 -2
  21. package/_entity/permission-project/ModuleBE_PermissionProjectDB.d.ts +4 -6
  22. package/_entity/permission-project/ModuleBE_PermissionProjectDB.js +1 -1
  23. package/_entity/permission-project/module-pack.d.ts +1 -1
  24. package/_entity/permission-project/module-pack.js +2 -2
  25. package/_entity/permission-user/ModuleBE_PermissionUserAPI.d.ts +4 -3
  26. package/_entity/permission-user/ModuleBE_PermissionUserAPI.js +63 -10
  27. package/_entity/permission-user/ModuleBE_PermissionUserDB.d.ts +13 -16
  28. package/_entity/permission-user/ModuleBE_PermissionUserDB.js +38 -25
  29. package/core/external-api-paths.d.ts +13 -0
  30. package/core/external-api-paths.js +13 -0
  31. package/core/function-permission-registry.d.ts +25 -0
  32. package/core/function-permission-registry.js +50 -0
  33. package/core/utils.d.ts +4 -4
  34. package/core/utils.js +7 -7
  35. package/index.d.ts +5 -0
  36. package/index.js +5 -0
  37. package/modules/ModuleBE_Permissions.d.ts +10 -4
  38. package/modules/ModuleBE_Permissions.js +365 -264
  39. package/modules/ModuleBE_PermissionsAssert.d.ts +20 -3
  40. package/modules/ModuleBE_PermissionsAssert.js +271 -205
  41. package/modules/consts.d.ts +2 -2
  42. package/modules/consts.js +5 -5
  43. package/modules/index.d.ts +1 -0
  44. package/modules/index.js +1 -0
  45. package/package.json +14 -12
  46. package/permissions-wire.d.ts +46 -0
  47. package/permissions-wire.js +47 -0
  48. package/permissions.d.ts +0 -1
  49. package/permissions.js +30 -37
  50. package/types.d.ts +3 -3
@@ -1,11 +1,13 @@
1
- import { MemKey_ServerApi, ModuleBE_BaseDB, Storm, } from '@nu-art/thunderstorm-backend';
2
- import { DBDef_PermissionUser } from '@nu-art/permissions-shared';
3
- import { _keys, ApiException, asOptionalArray, batchAction, batchActionParallel, dbObjectToId, exists, filterDuplicates, filterInstances, filterKeys, flatArray, JwtTools, merge, Year } from '@nu-art/ts-common';
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 {
10
+ defaultPermissionGroups;
9
11
  constructor() {
10
12
  super(DBDef_PermissionUser);
11
13
  }
@@ -14,11 +16,14 @@ export class ModuleBE_PermissionUserDB_Class extends ModuleBE_BaseDB {
14
16
  priority: 200,
15
17
  processor: async () => {
16
18
  const accounts = await ModuleBE_AccountDB.query.where({});
17
- const permissionsUser = await this.query.all(accounts.map(dbObjectToId));
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);
18
22
  const usersToUpsert = [];
19
23
  const usersToDelete = [];
20
24
  permissionsUser.forEach((user, index) => {
21
25
  if (exists(user)) {
26
+ // Same 1:1 design: account id and permission user id are the same value.
22
27
  if (!exists(accounts.find(account => account._id === user._id)))
23
28
  usersToDelete.push(user);
24
29
  return;
@@ -31,7 +36,8 @@ export class ModuleBE_PermissionUserDB_Class extends ModuleBE_BaseDB {
31
36
  await this.set.all(usersToUpsert);
32
37
  await this.delete.all(usersToDelete);
33
38
  // This stage updates the rtdb's config- which is why it's last. Changing the rtdb's config kills the server.
34
- const serviceAccounts = flatArray(dispatcher_collectServiceAccounts.dispatchModule());
39
+ const provider = getServiceAccountsProvider();
40
+ const serviceAccounts = provider ? await provider() : [];
35
41
  await this.createSystemServiceAccount(serviceAccounts);
36
42
  }
37
43
  };
@@ -42,9 +48,6 @@ export class ModuleBE_PermissionUserDB_Class extends ModuleBE_BaseDB {
42
48
  async __onNewUserRegistered(account, transaction) {
43
49
  await this.insertIfNotExist(account, transaction);
44
50
  }
45
- __onAccountDeleted = async (account, transaction) => {
46
- await this.delete.unique(account._id, transaction);
47
- };
48
51
  // protected async canDeleteDocument(transaction: FirestoreTransaction, dbInstances: DB_PermissionUser[]) {
49
52
  // const conflicts: DB_PermissionUser[] = [];
50
53
  // const accounts = await ModuleBE_AccountDB.query.custom(_EmptyQuery);
@@ -76,18 +79,25 @@ export class ModuleBE_PermissionUserDB_Class extends ModuleBE_BaseDB {
76
79
  //todo check for duplications in data
77
80
  }
78
81
  async postWriteProcessing(data, actionType) {
79
- const deleted = asOptionalArray(data.deleted) ?? [];
80
- const updated = asOptionalArray(data.updated) ?? [];
81
- const beforeIds = (asOptionalArray(data.before) ?? []).map(before => before?._id);
82
- const accountIdToInvalidate = filterDuplicates(filterInstances([...deleted, ...updated].map(i => i?._id))).filter(id => beforeIds.includes(id));
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));
83
87
  await this.rotateSession(accountIdToInvalidate);
84
88
  }
85
89
  insertIfNotExist = async (uiAccount, transaction) => {
86
90
  const create = async (transaction) => {
87
- const defaultPermissionGroups = await this.getDefaultPermissionGroups();
91
+ const defaultPermissionGroups = ModuleBE_PermissionUserDB.defaultPermissionGroups ? await ModuleBE_PermissionUserDB.defaultPermissionGroups() : [];
92
+ const permissionGroups = ModuleBE_PermissionUserDB.defaultPermissionGroups
93
+ ? filterInstances(await ModuleBE_PermissionGroupDB.query.all(defaultPermissionGroups.map(item => item.groupId)))
94
+ : [];
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;
88
98
  const permissionsUserToCreate = {
89
- _id: uiAccount._id,
90
- groups: defaultPermissionGroups.map(group => ({ groupId: group._id })),
99
+ _id: permissionUserId,
100
+ groups: permissionGroups.map(group => ({ groupId: group._id })),
91
101
  _auditorId: MemKey_AccountId.get()
92
102
  };
93
103
  return ModuleBE_PermissionUserDB.create.item(permissionsUserToCreate, transaction);
@@ -97,7 +107,9 @@ export class ModuleBE_PermissionUserDB_Class extends ModuleBE_BaseDB {
97
107
  async assignPermissions(body) {
98
108
  if (!body.targetAccountIds.length)
99
109
  throw new ApiException(400, `Asked to modify permissions but provided no users to modify permissions of.`);
100
- const usersToGiveTo = filterInstances(await this.query.all(body.targetAccountIds));
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));
101
113
  // console.log('assignPermissions target accounts ');
102
114
  // console.log(await this.query.custom(_EmptyQuery));
103
115
  if (!usersToGiveTo.length || usersToGiveTo.length !== body.targetAccountIds.length) {
@@ -135,10 +147,11 @@ export class ModuleBE_PermissionUserDB_Class extends ModuleBE_BaseDB {
135
147
  });
136
148
  await this.set.multi(usersToUpdate);
137
149
  }
138
- getDefaultPermissionGroups = async () => {
139
- if (!this.config.defaultPermissionGroupIds?.length)
140
- return [];
141
- return ModuleBE_PermissionGroupDB.query.where({ _id: { $in: this.config.defaultPermissionGroupIds } });
150
+ setDefaultPermissionGroups = (groupsGetter) => {
151
+ this.defaultPermissionGroups = groupsGetter;
152
+ };
153
+ clearDefaultPermissionGroups = () => {
154
+ delete this.defaultPermissionGroups;
142
155
  };
143
156
  /**
144
157
  * The system requires to perform action, which in other cases can also be done by a human.
@@ -151,7 +164,7 @@ export class ModuleBE_PermissionUserDB_Class extends ModuleBE_BaseDB {
151
164
  this.logInfoBold('Creating Service Accounts: ', serviceAccounts);
152
165
  // @ts-ignore
153
166
  const tokenCreator = ModuleBE_AccountDB.token.create;
154
- const envConfigRef = Storm.getInstance().getGlobalEnvConfigRef();
167
+ const envConfigRef = getGlobalEnvConfigRef();
155
168
  const updatedConfig = {};
156
169
  //Run over all service accounts
157
170
  for (const serviceAccount of serviceAccounts) {
@@ -170,9 +183,9 @@ export class ModuleBE_PermissionUserDB_Class extends ModuleBE_BaseDB {
170
183
  this.logInfo('NOTICE: querySafeAccount failed, creating accounts');
171
184
  account = await ModuleBE_AccountDB.account.create(accountsToRequest);
172
185
  }
173
- // Assign permissions groups to service account
186
+ // Assign permissions groups to service account; permission user _id is 1:1 with account _id
174
187
  const permissionsUser = await ModuleBE_PermissionUserDB.query.uniqueAssert({ _id: account._id });
175
- permissionsUser.groups = serviceAccount.groupIds?.map(groupId => ({ groupId })) || [];
188
+ permissionsUser.groups = serviceAccount.groupIds?.map(gid => ({ groupId: toPermissionGroupId(gid) })) || [];
176
189
  await ModuleBE_PermissionUserDB.set.item(permissionsUser);
177
190
  //Service accounts are only allowed to have one session... but this isn't the defined place to be a cop about it
178
191
  const sessions = await ModuleBE_AccountDB.account.getSessions(account);
@@ -198,7 +211,7 @@ export class ModuleBE_PermissionUserDB_Class extends ModuleBE_BaseDB {
198
211
  })
199
212
  };
200
213
  }
201
- if (_keys(updatedConfig).length > 0)
214
+ if (_keys(updatedConfig).length > 0 && envConfigRef)
202
215
  MemKey_ServerApi.get().addPostCallAction(async () => {
203
216
  const currentConfig = await envConfigRef.get({});
204
217
  await envConfigRef.set(merge(currentConfig, updatedConfig));
@@ -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, UniqueId } from '@nu-art/ts-common';
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: UniqueId, namespace: string, permutations: string[]) => DefaultDef_Package;
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: UniqueId) => { [key in Key]: PermissionKey_BE<string>; };
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._id]: DefaultAccessLevel_Read.name,
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(newDomainId, preDBAccessLevels);
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
  */