"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ResourceSettingType = exports.RoleSettingsDto = exports.ActionTypeByResourceType = exports.ActionTypeEnum = exports.RoleTypeEnum = exports.ResourceTypeEnum = exports.PrincipalTypeEnum = exports.AssignmentTypeEnum = exports.isGroupShareEntry = exports.isUserShareEntry = exports.PermissionEntityType = exports.PermissionedEntities = exports.RbacRole = exports.GroupRbacAction = exports.RbacAction = exports.OrganizationRbacAction = void 0;
var OrganizationRbacAction;
(function (OrganizationRbacAction) {
    OrganizationRbacAction["MANAGE"] = "manage";
})(OrganizationRbacAction || (exports.OrganizationRbacAction = OrganizationRbacAction = {}));
var RbacAction;
(function (RbacAction) {
    RbacAction["READ"] = "read";
    RbacAction["CREATE"] = "create";
    RbacAction["UPDATE"] = "update";
    RbacAction["DELETE"] = "delete";
    RbacAction["DEPLOY"] = "deploy";
    RbacAction["SHARE"] = "share";
    RbacAction["BUILD"] = "build";
    RbacAction["EXECUTE"] = "execute";
    RbacAction["RESET"] = "reset";
})(RbacAction || (exports.RbacAction = RbacAction = {}));
var GroupRbacAction;
(function (GroupRbacAction) {
    GroupRbacAction["READ"] = "read";
    GroupRbacAction["DELETE"] = "delete";
    GroupRbacAction["UPDATE"] = "update";
})(GroupRbacAction || (exports.GroupRbacAction = GroupRbacAction = {}));
var RbacRole;
(function (RbacRole) {
    RbacRole["VIEWER"] = "viewer";
    RbacRole["BUILDER"] = "builder";
    RbacRole["CONFIGURATOR"] = "configurator";
    RbacRole["OWNER"] = "owner";
    RbacRole["NONE"] = "none";
    RbacRole["EXECUTOR"] = "executor"; // for app api
})(RbacRole || (exports.RbacRole = RbacRole = {}));
// used when querying permissions (roles table)
var PermissionedEntities;
(function (PermissionedEntities) {
    PermissionedEntities["APPLICATION"] = "application";
    PermissionedEntities["APPLICATION_V2"] = "application_v2";
    PermissionedEntities["API_V3"] = "api_v3";
    PermissionedEntities["API"] = "api";
    PermissionedEntities["ORGANIZATION"] = "organization";
    /**
     * @deprecated The Datasource entity is being deprecated in favor of the Integration entity.
     */
    PermissionedEntities["DATASOURCE"] = "datasource";
    PermissionedEntities["INTEGRATION"] = "integration";
    PermissionedEntities["SECRET_STORE"] = "secret_store";
})(PermissionedEntities || (exports.PermissionedEntities = PermissionedEntities = {}));
// used in representation layer
var PermissionEntityType;
(function (PermissionEntityType) {
    PermissionEntityType["APPLICATION"] = "application";
    PermissionEntityType["APPLICATION_V2"] = "application_v2";
    PermissionEntityType["WORKFLOW"] = "workflow";
    PermissionEntityType["SCHEDULED_JOB"] = "scheduled_job";
    /**
     * @deprecated The Datasource entity is being deprecated in favor of the Integration entity.
     */
    PermissionEntityType["DATASOURCE"] = "datasource";
    PermissionEntityType["INTEGRATION"] = "integration";
})(PermissionEntityType || (exports.PermissionEntityType = PermissionEntityType = {}));
const isUserShareEntry = (shareEntry) => shareEntry.type === 'user';
exports.isUserShareEntry = isUserShareEntry;
const isGroupShareEntry = (shareEntry) => shareEntry.type === 'group';
exports.isGroupShareEntry = isGroupShareEntry;
// RBAC V2 lives below here
var AssignmentTypeEnum;
(function (AssignmentTypeEnum) {
    AssignmentTypeEnum["ROLE"] = "role";
    AssignmentTypeEnum["PERMISSION"] = "permission";
})(AssignmentTypeEnum || (exports.AssignmentTypeEnum = AssignmentTypeEnum = {}));
var PrincipalTypeEnum;
(function (PrincipalTypeEnum) {
    PrincipalTypeEnum["APPLICATION"] = "application";
    PrincipalTypeEnum["GROUP"] = "group";
    PrincipalTypeEnum["USER"] = "user";
    // ORGANIZATION = 'organization',
    // API_KEY = 'api_key'
})(PrincipalTypeEnum || (exports.PrincipalTypeEnum = PrincipalTypeEnum = {}));
var ResourceTypeEnum;
(function (ResourceTypeEnum) {
    ResourceTypeEnum["ACCESS_TOKENS"] = "access_tokens";
    ResourceTypeEnum["AGENTS"] = "agents";
    ResourceTypeEnum["AI_INFERENCE"] = "ai.inference";
    ResourceTypeEnum["APPLICATIONS"] = "apps";
    ResourceTypeEnum["APPLICATIONS_APIS"] = "apps.apis";
    ResourceTypeEnum["APPLICATIONS_PAGES"] = "apps.pages";
    ResourceTypeEnum["BILLING"] = "billing";
    ResourceTypeEnum["FOLDERS"] = "folders";
    ResourceTypeEnum["GROUPS"] = "groups";
    ResourceTypeEnum["GROUPS_MEMBERS"] = "groups.members";
    ResourceTypeEnum["INTEGRATIONS"] = "integrations";
    ResourceTypeEnum["INTEGRATIONS_DEFAULT_AI"] = "integrations.default_ai";
    ResourceTypeEnum["LOGS"] = "logs";
    ResourceTypeEnum["LOGS_STREAMS"] = "logs.streams";
    ResourceTypeEnum["ORGANIZATION"] = "org";
    // ORGANIZATION_REQUESTS = 'org.requests',
    ResourceTypeEnum["ORGANIZATION_USERS"] = "org.users";
    ResourceTypeEnum["ORG_KNOWLEDGE"] = "org_knowledge";
    ResourceTypeEnum["PROFILES"] = "profiles";
    ResourceTypeEnum["REPOSITORIES"] = "repos";
    ResourceTypeEnum["ROLES"] = "roles";
    ResourceTypeEnum["SCHEDULED_JOBS"] = "jobs";
    ResourceTypeEnum["SECRETS_STORES"] = "secrets_stores";
    ResourceTypeEnum["WORKFLOWS"] = "workflows";
})(ResourceTypeEnum || (exports.ResourceTypeEnum = ResourceTypeEnum = {}));
// TODO(@taha-au) proj:rbac Add back the commented out role types once they are implemented
// in the system.
var RoleTypeEnum;
(function (RoleTypeEnum) {
    RoleTypeEnum["APPLICATIONS"] = "apps";
    // GROUPS = 'groups',
    RoleTypeEnum["INTEGRATIONS"] = "integrations";
    RoleTypeEnum["ORGANIZATION"] = "org";
    // PROFILES = 'profiles',
    RoleTypeEnum["SCHEDULED_JOBS"] = "jobs";
    // SECRETS_STORES = 'secrets_stores',
    RoleTypeEnum["WORKFLOWS"] = "workflows";
})(RoleTypeEnum || (exports.RoleTypeEnum = RoleTypeEnum = {}));
var ActionTypeEnum;
(function (ActionTypeEnum) {
    ActionTypeEnum["BUILD"] = "build";
    ActionTypeEnum["CREATE"] = "create";
    ActionTypeEnum["DELETE"] = "delete";
    ActionTypeEnum["DEPLOY"] = "deploy";
    ActionTypeEnum["MANAGE"] = "manage";
    ActionTypeEnum["MANAGE_SCHEDULE"] = "manage_schedule";
    ActionTypeEnum["MANAGE_VISIBILITY"] = "manage_visibility";
    ActionTypeEnum["PREVIEW"] = "preview";
    ActionTypeEnum["READ"] = "read";
    ActionTypeEnum["RUN"] = "run";
    ActionTypeEnum["SHARE"] = "share";
    ActionTypeEnum["UPDATE"] = "update";
    ActionTypeEnum["VIEW"] = "view";
})(ActionTypeEnum || (exports.ActionTypeEnum = ActionTypeEnum = {}));
exports.ActionTypeByResourceType = {
    AGENTS: {
        READ: ActionTypeEnum.READ,
        MANAGE: ActionTypeEnum.MANAGE
    },
    AI_INFERENCE: {
        MANAGE: ActionTypeEnum.MANAGE
    },
    INTEGRATIONS_DEFAULT_AI: {
        MANAGE: ActionTypeEnum.MANAGE
    },
    BILLING: {
        MANAGE: ActionTypeEnum.MANAGE
    },
    WORKFLOWS: {
        DEPLOY: ActionTypeEnum.DEPLOY,
        DELETE: ActionTypeEnum.DELETE,
        CREATE: ActionTypeEnum.CREATE,
        UPDATE: ActionTypeEnum.UPDATE,
        SHARE: ActionTypeEnum.SHARE
    },
    SECRET_STORES: {
        DELETE: ActionTypeEnum.DELETE,
        CREATE: ActionTypeEnum.CREATE,
        UPDATE: ActionTypeEnum.UPDATE,
        SHARE: ActionTypeEnum.SHARE,
        BUILD: ActionTypeEnum.BUILD
    },
    ROLE_MEMBERS: {
        MANAGE: ActionTypeEnum.MANAGE,
        READ: ActionTypeEnum.READ
    },
    PROFILES: {
        MANAGE: ActionTypeEnum.MANAGE
    },
    ROLES: {
        READ: ActionTypeEnum.READ,
        MANAGE: ActionTypeEnum.MANAGE
    },
    REPOS: {
        READ: ActionTypeEnum.READ,
        MANAGE: ActionTypeEnum.MANAGE
    },
    GROUPS: {
        READ: ActionTypeEnum.READ,
        MANAGE: ActionTypeEnum.MANAGE
    },
    GROUP_MEMBERS: {
        READ: ActionTypeEnum.READ,
        MANAGE: ActionTypeEnum.MANAGE
    },
    ORGANIZATION: {
        MANAGE: ActionTypeEnum.MANAGE,
        READ: ActionTypeEnum.READ
    },
    ORGANIZATION_USERS: {
        READ: ActionTypeEnum.READ,
        MANAGE: ActionTypeEnum.MANAGE
    },
    ACCESS_TOKENS: {
        READ: ActionTypeEnum.READ,
        MANAGE: ActionTypeEnum.MANAGE
    },
    APPLICATIONS: {
        CREATE: ActionTypeEnum.CREATE,
        DELETE: ActionTypeEnum.DELETE,
        DEPLOY: ActionTypeEnum.DEPLOY,
        MANAGE_VISIBILITY: ActionTypeEnum.MANAGE_VISIBILITY,
        PREVIEW: ActionTypeEnum.PREVIEW,
        SHARE: ActionTypeEnum.SHARE,
        UPDATE: ActionTypeEnum.UPDATE,
        VIEW: ActionTypeEnum.VIEW
    },
    FOLDERS: {
        MANAGE: ActionTypeEnum.MANAGE
    },
    INTEGRATIONS: {
        CREATE: ActionTypeEnum.CREATE,
        DELETE: ActionTypeEnum.DELETE,
        BUILD: ActionTypeEnum.BUILD,
        SHARE: ActionTypeEnum.SHARE,
        UPDATE: ActionTypeEnum.UPDATE
    },
    LOGS: {
        READ: ActionTypeEnum.READ
    },
    LOGS_STREAMS: {
        MANAGE: ActionTypeEnum.MANAGE,
        READ: ActionTypeEnum.READ
    },
    SCHEDULED_JOBS: {
        CREATE: ActionTypeEnum.CREATE,
        DELETE: ActionTypeEnum.DELETE,
        DEPLOY: ActionTypeEnum.DEPLOY,
        MANAGE_SCHEDULE: ActionTypeEnum.MANAGE_SCHEDULE,
        RUN: ActionTypeEnum.RUN,
        SHARE: ActionTypeEnum.SHARE,
        UPDATE: ActionTypeEnum.UPDATE
    },
    ORG_KNOWLEDGE: {
        CREATE: ActionTypeEnum.CREATE,
        UPDATE: ActionTypeEnum.UPDATE,
        DELETE: ActionTypeEnum.DELETE
    }
};
class RoleSettingsDto {
    [RoleTypeEnum.ORGANIZATION];
    [RoleTypeEnum.APPLICATIONS];
    /*[RoleTypeEnum.GROUPS]?: {
      base?: string | null;
      creator?: string | null;
    };*/
    [RoleTypeEnum.INTEGRATIONS];
    [RoleTypeEnum.SCHEDULED_JOBS];
    [RoleTypeEnum.WORKFLOWS];
    constructor(defaultRoles) {
        for (const roleSetting of defaultRoles) {
            const roleType = roleSetting.roleType;
            const settingType = roleSetting.settingType;
            if (!this[roleType]) {
                this[roleType] = {};
            }
            this[roleType][settingType] = roleSetting.roleId;
        }
    }
}
exports.RoleSettingsDto = RoleSettingsDto;
var ResourceSettingType;
(function (ResourceSettingType) {
    ResourceSettingType["NEW_USER"] = "new_user";
    ResourceSettingType["BASE"] = "base";
    ResourceSettingType["CREATOR"] = "creator";
})(ResourceSettingType || (exports.ResourceSettingType = ResourceSettingType = {}));
//# sourceMappingURL=index.js.map