@atom8n/permissions 0.45.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 (59) hide show
  1. package/dist/build.tsbuildinfo +1 -0
  2. package/dist/constants.ee.d.ts +58 -0
  3. package/dist/constants.ee.js +71 -0
  4. package/dist/constants.ee.js.map +1 -0
  5. package/dist/index.d.ts +16 -0
  6. package/dist/index.js +48 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/public-api-permissions.ee.d.ts +8 -0
  9. package/dist/public-api-permissions.ee.js +117 -0
  10. package/dist/public-api-permissions.ee.js.map +1 -0
  11. package/dist/roles/all-roles.d.ts +3 -0
  12. package/dist/roles/all-roles.js +56 -0
  13. package/dist/roles/all-roles.js.map +1 -0
  14. package/dist/roles/role-maps.ee.d.ts +11 -0
  15. package/dist/roles/role-maps.ee.js +35 -0
  16. package/dist/roles/role-maps.ee.js.map +1 -0
  17. package/dist/roles/scopes/credential-sharing-scopes.ee.d.ts +3 -0
  18. package/dist/roles/scopes/credential-sharing-scopes.ee.js +12 -0
  19. package/dist/roles/scopes/credential-sharing-scopes.ee.js.map +1 -0
  20. package/dist/roles/scopes/global-scopes.ee.d.ts +5 -0
  21. package/dist/roles/scopes/global-scopes.ee.js +161 -0
  22. package/dist/roles/scopes/global-scopes.ee.js.map +1 -0
  23. package/dist/roles/scopes/project-scopes.ee.d.ts +6 -0
  24. package/dist/roles/scopes/project-scopes.ee.js +130 -0
  25. package/dist/roles/scopes/project-scopes.ee.js.map +1 -0
  26. package/dist/roles/scopes/workflow-sharing-scopes.ee.d.ts +3 -0
  27. package/dist/roles/scopes/workflow-sharing-scopes.ee.js +21 -0
  28. package/dist/roles/scopes/workflow-sharing-scopes.ee.js.map +1 -0
  29. package/dist/schemas.ee.d.ts +48 -0
  30. package/dist/schemas.ee.js +61 -0
  31. package/dist/schemas.ee.js.map +1 -0
  32. package/dist/scope-information.d.ts +4 -0
  33. package/dist/scope-information.js +31 -0
  34. package/dist/scope-information.js.map +1 -0
  35. package/dist/types.ee.d.ts +59 -0
  36. package/dist/types.ee.js +13 -0
  37. package/dist/types.ee.js.map +1 -0
  38. package/dist/utilities/combine-scopes.ee.d.ts +2 -0
  39. package/dist/utilities/combine-scopes.ee.js +16 -0
  40. package/dist/utilities/combine-scopes.ee.js.map +1 -0
  41. package/dist/utilities/get-global-scopes.ee.d.ts +2 -0
  42. package/dist/utilities/get-global-scopes.ee.js +6 -0
  43. package/dist/utilities/get-global-scopes.ee.js.map +1 -0
  44. package/dist/utilities/get-resource-permissions.ee.d.ts +10 -0
  45. package/dist/utilities/get-resource-permissions.ee.js +19 -0
  46. package/dist/utilities/get-resource-permissions.ee.js.map +1 -0
  47. package/dist/utilities/get-role-scopes.ee.d.ts +4 -0
  48. package/dist/utilities/get-role-scopes.ee.js +27 -0
  49. package/dist/utilities/get-role-scopes.ee.js.map +1 -0
  50. package/dist/utilities/has-global-scope.ee.d.ts +2 -0
  51. package/dist/utilities/has-global-scope.ee.js +11 -0
  52. package/dist/utilities/has-global-scope.ee.js.map +1 -0
  53. package/dist/utilities/has-scope.ee.d.ts +2 -0
  54. package/dist/utilities/has-scope.ee.js +14 -0
  55. package/dist/utilities/has-scope.ee.js.map +1 -0
  56. package/dist/utilities/static-roles-with-scope.ee.d.ts +2 -0
  57. package/dist/utilities/static-roles-with-scope.ee.js +13 -0
  58. package/dist/utilities/static-roles-with-scope.ee.js.map +1 -0
  59. package/package.json +30 -0
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getResourcePermissions = void 0;
4
+ const constants_ee_1 = require("../constants.ee");
5
+ const getResourcePermissions = (resourceScopes = []) => Object.keys(constants_ee_1.RESOURCES).reduce((permissions, key) => ({
6
+ ...permissions,
7
+ [key]: resourceScopes.reduce((resourcePermissions, scope) => {
8
+ const [prefix, suffix] = scope.split(':');
9
+ if (prefix === key) {
10
+ return {
11
+ ...resourcePermissions,
12
+ [suffix]: true,
13
+ };
14
+ }
15
+ return resourcePermissions;
16
+ }, {}),
17
+ }), {});
18
+ exports.getResourcePermissions = getResourcePermissions;
19
+ //# sourceMappingURL=get-resource-permissions.ee.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-resource-permissions.ee.js","sourceRoot":"","sources":["../../src/utilities/get-resource-permissions.ee.ts"],"names":[],"mappings":";;;AAAA,kDAA4C;AAarC,MAAM,sBAAsB,GAAG,CAAC,iBAA0B,EAAE,EAAqB,EAAE,CACzF,MAAM,CAAC,IAAI,CAAC,wBAAS,CAAC,CAAC,MAAM,CAC5B,CAAC,WAAW,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;IACtB,GAAG,WAAW;IACd,CAAC,GAAG,CAAC,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC,mBAAmB,EAAE,KAAK,EAAE,EAAE;QAC3D,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAoC,CAAC;QAE7E,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;YACpB,OAAO;gBACN,GAAG,mBAAmB;gBACtB,CAAC,MAAM,CAAC,EAAE,IAAI;aACd,CAAC;QACH,CAAC;QAED,OAAO,mBAAmB,CAAC;IAC5B,CAAC,EAAE,EAAE,CAAC;CACN,CAAC,EACF,EAAuB,CACvB,CAAC;AAlBU,QAAA,sBAAsB,0BAkBhC"}
@@ -0,0 +1,4 @@
1
+ import type { AllRoleTypes, AuthPrincipal, Resource, Scope } from '../types.ee';
2
+ export declare const COMBINED_ROLE_MAP: Record<AllRoleTypes, Scope[]>;
3
+ export declare function getRoleScopes(role: AllRoleTypes, filters?: Resource[]): Scope[];
4
+ export declare function getAuthPrincipalScopes(user: AuthPrincipal, filters?: Resource[]): Scope[];
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.COMBINED_ROLE_MAP = void 0;
4
+ exports.getRoleScopes = getRoleScopes;
5
+ exports.getAuthPrincipalScopes = getAuthPrincipalScopes;
6
+ const role_maps_ee_1 = require("../roles/role-maps.ee");
7
+ exports.COMBINED_ROLE_MAP = Object.fromEntries(Object.values(role_maps_ee_1.ALL_ROLE_MAPS).flatMap((o) => Object.entries(o)));
8
+ function getRoleScopes(role, filters) {
9
+ let scopes = exports.COMBINED_ROLE_MAP[role];
10
+ if (filters) {
11
+ scopes = scopes.filter((s) => filters.includes(s.split(':')[0]));
12
+ }
13
+ return scopes;
14
+ }
15
+ function getAuthPrincipalScopes(user, filters) {
16
+ if (!user.role) {
17
+ const e = new Error('AuthPrincipal does not have a role defined');
18
+ console.error('AuthPrincipal does not have a role defined', e);
19
+ throw e;
20
+ }
21
+ let scopes = user.role.scopes.map((s) => s.slug);
22
+ if (filters) {
23
+ scopes = scopes.filter((s) => filters.includes(s.split(':')[0]));
24
+ }
25
+ return scopes;
26
+ }
27
+ //# sourceMappingURL=get-role-scopes.ee.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-role-scopes.ee.js","sourceRoot":"","sources":["../../src/utilities/get-role-scopes.ee.ts"],"names":[],"mappings":";;;AAeA,sCAMC;AAQD,wDAWC;AAxCD,wDAAsD;AAGzC,QAAA,iBAAiB,GAAG,MAAM,CAAC,WAAW,CAClD,MAAM,CAAC,MAAM,CAAC,4BAAa,CAAC,CAAC,OAAO,CAAC,CAAC,CAA0B,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CACtD,CAAC;AAUnC,SAAgB,aAAa,CAAC,IAAkB,EAAE,OAAoB;IACrE,IAAI,MAAM,GAAG,yBAAiB,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,OAAO,EAAE,CAAC;QACb,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAa,CAAC,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC;AAQD,SAAgB,sBAAsB,CAAC,IAAmB,EAAE,OAAoB;IAC/E,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QAChB,MAAM,CAAC,GAAG,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAClE,OAAO,CAAC,KAAK,CAAC,4CAA4C,EAAE,CAAC,CAAC,CAAC;QAC/D,MAAM,CAAC,CAAC;IACT,CAAC;IACD,IAAI,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACjD,IAAI,OAAO,EAAE,CAAC;QACb,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAa,CAAC,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { AuthPrincipal, Scope, ScopeOptions } from '../types.ee';
2
+ export declare const hasGlobalScope: (principal: AuthPrincipal, scope: Scope | Scope[], scopeOptions?: ScopeOptions) => boolean;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasGlobalScope = void 0;
4
+ const has_scope_ee_1 = require("./has-scope.ee");
5
+ const get_role_scopes_ee_1 = require("./get-role-scopes.ee");
6
+ const hasGlobalScope = (principal, scope, scopeOptions) => {
7
+ const global = (0, get_role_scopes_ee_1.getAuthPrincipalScopes)(principal);
8
+ return (0, has_scope_ee_1.hasScope)(scope, { global }, undefined, scopeOptions);
9
+ };
10
+ exports.hasGlobalScope = hasGlobalScope;
11
+ //# sourceMappingURL=has-global-scope.ee.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-global-scope.ee.js","sourceRoot":"","sources":["../../src/utilities/has-global-scope.ee.ts"],"names":[],"mappings":";;;AAAA,iDAA0C;AAE1C,6DAA8D;AAOvD,MAAM,cAAc,GAAG,CAC7B,SAAwB,EACxB,KAAsB,EACtB,YAA2B,EACjB,EAAE;IACZ,MAAM,MAAM,GAAG,IAAA,2CAAsB,EAAC,SAAS,CAAC,CAAC;IACjD,OAAO,IAAA,uBAAQ,EAAC,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;AAC7D,CAAC,CAAC;AAPW,QAAA,cAAc,kBAOzB"}
@@ -0,0 +1,2 @@
1
+ import type { Scope, ScopeLevels, ScopeOptions, MaskLevels } from '../types.ee';
2
+ export declare const hasScope: (scope: Scope | Scope[], userScopes: ScopeLevels, masks?: MaskLevels, options?: ScopeOptions) => boolean;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasScope = void 0;
4
+ const combine_scopes_ee_1 = require("./combine-scopes.ee");
5
+ const hasScope = (scope, userScopes, masks, options = { mode: 'oneOf' }) => {
6
+ if (!Array.isArray(scope))
7
+ scope = [scope];
8
+ const userScopeSet = (0, combine_scopes_ee_1.combineScopes)(userScopes, masks);
9
+ return options.mode === 'allOf'
10
+ ? !!scope.length && scope.every((s) => userScopeSet.has(s))
11
+ : scope.some((s) => userScopeSet.has(s));
12
+ };
13
+ exports.hasScope = hasScope;
14
+ //# sourceMappingURL=has-scope.ee.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-scope.ee.js","sourceRoot":"","sources":["../../src/utilities/has-scope.ee.ts"],"names":[],"mappings":";;;AAAA,2DAAoD;AAU7C,MAAM,QAAQ,GAAG,CACvB,KAAsB,EACtB,UAAuB,EACvB,KAAkB,EAClB,UAAwB,EAAE,IAAI,EAAE,OAAO,EAAE,EAC/B,EAAE;IACZ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,KAAK,GAAG,CAAC,KAAK,CAAC,CAAC;IAC3C,MAAM,YAAY,GAAG,IAAA,iCAAa,EAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IACtD,OAAO,OAAO,CAAC,IAAI,KAAK,OAAO;QAC9B,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC3D,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3C,CAAC,CAAC;AAXW,QAAA,QAAQ,YAWnB"}
@@ -0,0 +1,2 @@
1
+ import type { RoleNamespace, Scope } from '../types.ee';
2
+ export declare function staticRolesWithScope(namespace: RoleNamespace, scopes: Scope | Scope[]): string[];
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.staticRolesWithScope = staticRolesWithScope;
4
+ const role_maps_ee_1 = require("../roles/role-maps.ee");
5
+ function staticRolesWithScope(namespace, scopes) {
6
+ if (!Array.isArray(scopes)) {
7
+ scopes = [scopes];
8
+ }
9
+ return Object.keys(role_maps_ee_1.ALL_ROLE_MAPS[namespace]).filter((k) => {
10
+ return scopes.every((s) => role_maps_ee_1.ALL_ROLE_MAPS[namespace][k].includes(s));
11
+ });
12
+ }
13
+ //# sourceMappingURL=static-roles-with-scope.ee.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"static-roles-with-scope.ee.js","sourceRoot":"","sources":["../../src/utilities/static-roles-with-scope.ee.ts"],"names":[],"mappings":";;AAYA,oDAWC;AAvBD,wDAAsD;AAYtD,SAAgB,oBAAoB,CAAC,SAAwB,EAAE,MAAuB;IACrF,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,MAAM,GAAG,CAAC,MAAM,CAAC,CAAC;IACnB,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,4BAAa,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;QACzD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAEvB,4BAAa,CAAC,SAAS,CAAS,CAAC,CAAC,CAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CAC7D,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@atom8n/permissions",
3
+ "version": "0.45.0",
4
+ "scripts": {
5
+ "clean": "rimraf dist .turbo",
6
+ "dev": "pnpm watch",
7
+ "typecheck": "tsc --noEmit",
8
+ "build": "tsc -p tsconfig.build.json",
9
+ "format": "biome format --write .",
10
+ "format:check": "biome ci .",
11
+ "lint": "eslint . --quiet",
12
+ "lint:fix": "eslint . --fix",
13
+ "watch": "tsc -p tsconfig.build.json --watch",
14
+ "test": "jest",
15
+ "test:unit": "jest",
16
+ "test:dev": "jest --watch"
17
+ },
18
+ "main": "dist/index.js",
19
+ "module": "src/index.ts",
20
+ "types": "dist/index.d.ts",
21
+ "files": [
22
+ "dist/**/*"
23
+ ],
24
+ "dependencies": {
25
+ "zod": "catalog:"
26
+ },
27
+ "devDependencies": {
28
+ "@atom8n/typescript-config": "1.3.0"
29
+ }
30
+ }