@mondaydotcomorg/monday-authorization 3.3.0-feature-bashanye-navigate-can-action-in-scope-to-graph-0a3cfd6 → 3.3.0-feature-bashanye-navigate-can-action-in-scope-to-graph-752f21a

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.
@@ -0,0 +1,42 @@
1
+ export enum RoleType {
2
+ CUSTOM = 'custom_role',
3
+ BASIC = 'basic_role',
4
+ }
5
+
6
+ export interface CustomRole {
7
+ id?: number;
8
+ name: string;
9
+ resourceType: string;
10
+ resourceId: number;
11
+ basicRoleId: number;
12
+ basicRoleType: RoleType;
13
+ }
14
+
15
+ export interface BasicRole {
16
+ id: number;
17
+ resourceType: string;
18
+ roleType: string;
19
+ name: string;
20
+ }
21
+
22
+ export interface RolesResponse {
23
+ customRoles: CustomRole[];
24
+ basicRoles?: BasicRole[];
25
+ }
26
+
27
+ export interface RoleCreateRequest {
28
+ name: string;
29
+ resourceType: string;
30
+ resourceId: number;
31
+ sourceRole: {
32
+ id: number;
33
+ type: RoleType;
34
+ };
35
+ }
36
+
37
+ export interface RoleUpdateRequest {
38
+ id: number;
39
+ updateAttributes: {
40
+ name: string;
41
+ };
42
+ }
@@ -0,0 +1,48 @@
1
+ export interface WorkspaceScope {
2
+ workspaceId: number;
3
+ }
4
+
5
+ export interface BoardScope {
6
+ boardId: number;
7
+ }
8
+
9
+ export interface PulseScope {
10
+ pulseId: number;
11
+ }
12
+
13
+ export interface AccountProductScope {
14
+ accountProductId: number;
15
+ }
16
+
17
+ export interface AccountScope {
18
+ accountId: number;
19
+ }
20
+
21
+ export type ScopeOptions = WorkspaceScope | BoardScope | PulseScope | AccountProductScope | AccountScope;
22
+
23
+ export interface Translation {
24
+ key: string;
25
+ [option: string]: string;
26
+ }
27
+
28
+ export enum PermitTechnicalReason {
29
+ NO_REASON = 0,
30
+ NOT_ELIGIBLE = 1,
31
+ BY_ROLE_IN_SCOPE = 2,
32
+ }
33
+
34
+ export interface ScopedActionPermit {
35
+ can: boolean;
36
+ reason: Translation;
37
+ technicalReason: PermitTechnicalReason;
38
+ }
39
+
40
+ export interface ScopedAction {
41
+ action: string;
42
+ scope: ScopeOptions;
43
+ }
44
+
45
+ export interface ScopedActionResponseObject {
46
+ scopedAction: ScopedAction;
47
+ permit: ScopedActionPermit;
48
+ }
@@ -0,0 +1,66 @@
1
+ import snakeCase from 'lodash/snakeCase.js';
2
+ import camelCase from 'lodash/camelCase.js';
3
+ import mapKeys from 'lodash/mapKeys.js';
4
+ import { ScopeOptions } from '../types/scoped-actions-contracts';
5
+ import { ResourceType, ResourceId } from '../types/graph-api.types';
6
+ import { logger } from '../authorization-internal-service';
7
+
8
+ export type CamelCase<S extends string> = S extends `${infer F}_${infer R}` ? `${F}${Capitalize<CamelCase<R>>}` : S;
9
+ export type CamelCaseKeys<T> = T extends object
10
+ ? { [K in keyof T as K extends string ? CamelCase<K> : K]: CamelCaseKeys<T[K]> }
11
+ : T;
12
+
13
+ /**
14
+ * Converts a scope object to resource type and resource ID
15
+ */
16
+ export function scopeToResource(scope: ScopeOptions): { resourceType: ResourceType; resourceId: ResourceId } {
17
+ logger.debug(
18
+ {
19
+ tag: 'authorization-utils',
20
+ scopeKeys: Object.keys(scope),
21
+ scopeValues: Object.values(scope),
22
+ },
23
+ '🔍 Utils Debug: Converting scope to resource'
24
+ );
25
+
26
+ if ('workspaceId' in scope) {
27
+ logger.debug({ tag: 'authorization-utils', resourceId: scope.workspaceId }, '🔍 Utils Debug: Mapped to workspace');
28
+ return { resourceType: 'workspace', resourceId: scope.workspaceId };
29
+ }
30
+ if ('boardId' in scope) {
31
+ logger.debug({ tag: 'authorization-utils', resourceId: scope.boardId }, '🔍 Utils Debug: Mapped to board');
32
+ return { resourceType: 'board', resourceId: scope.boardId };
33
+ }
34
+ if ('pulseId' in scope) {
35
+ logger.debug({ tag: 'authorization-utils', resourceId: scope.pulseId }, '🔍 Utils Debug: Mapped to pulse');
36
+ return { resourceType: 'pulse', resourceId: scope.pulseId };
37
+ }
38
+ if ('accountProductId' in scope) {
39
+ logger.debug(
40
+ { tag: 'authorization-utils', resourceId: scope.accountProductId },
41
+ '🔍 Utils Debug: Mapped to account_product'
42
+ );
43
+ return { resourceType: 'account_product', resourceId: scope.accountProductId };
44
+ }
45
+ if ('accountId' in scope) {
46
+ logger.debug({ tag: 'authorization-utils', resourceId: scope.accountId }, '🔍 Utils Debug: Mapped to account');
47
+ return { resourceType: 'account', resourceId: scope.accountId };
48
+ }
49
+
50
+ logger.debug({ tag: 'authorization-utils', scope }, '❌ Utils Debug: Unsupported scope provided');
51
+ throw new Error('Unsupported scope provided');
52
+ }
53
+
54
+ /**
55
+ * Converts object keys from snake_case to camelCase
56
+ */
57
+ export function toCamelCase<T extends object>(obj: T): CamelCaseKeys<T> {
58
+ return mapKeys(obj, (_, key) => camelCase(key)) as CamelCaseKeys<T>;
59
+ }
60
+
61
+ /**
62
+ * Converts object keys from camelCase to snake_case
63
+ */
64
+ export function toSnakeCase<T extends object>(obj: T): Record<string, any> {
65
+ return mapKeys(obj, (_, key) => snakeCase(key));
66
+ }