New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@gapi/ac

Package Overview
Dependencies
Maintainers
1
Versions
167
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gapi/ac

The @gapi/ac library is an access control utility designed for use in GraphQL applications. It helps developers manage permissions for different user roles, such as GUEST, USER, and ADMIN, across various GraphQL actions like queries, mutations, subscripti

latest
Source
npmnpm
Version
1.8.214
Version published
Weekly downloads
242
-68.12%
Maintainers
1
Weekly downloads
 
Created
Source

The @gapi/ac library is an access control utility designed for use in GraphQL applications. It helps developers manage permissions for different user roles, such as GUEST, USER, and ADMIN, across various GraphQL actions like queries, mutations, subscriptions, and events. It allows developers to define and enforce rules for which roles can access or manipulate specific resources in the system.

Key features include:

Role-based permissions: You can define access control based on user roles (like GUEST, USER, ADMIN) and control what actions they can perform. GraphQL-focused: Specifically built to handle permissioning in GraphQL, making it a natural fit for applications using this API standard. Filtering data: The library allows filtering data based on user roles, so different roles see only the data they are authorized to access. For example, an admin might have access to query a certain data field (status), while a regular user might have partial access, where some attributes of the response are filtered out based on the permission definitions.

import { AccessControl, Union } from '@gapi/ac';

enum GraphqlActions {
  query,
  mutation,
  subscription,
  event,
}

enum Roles {
  GUEST,
  USER,
  ADMIN,
}

interface IQuery {
  status: {
    status: number;
  };
}

const Permissions: Union<typeof Roles, IQuery, typeof GraphqlActions> = {
  GUEST: {
    status: {
      query: {
        enabled: false,
      },
    },
  },
  USER: {
    status: {
      query: {
        enabled: true,
        attributes: {
          status: false,
        },
      },
    },
  },
  ADMIN: {
    status: {
      query: {
        enabled: true,
      },
    },
  },
};

const ac = new AccessControl<
  typeof Roles,
  IQuery & ISubscription & IMutation,
  typeof GraphqlActions
>(Permissions);

const canAdminQueryStatus = ac.can('ADMIN', 'query', 'status');
const canAdminQueryStatus = ac.can('USER', 'query', 'status');

if (!canAdminQueryStatus) {
  throw new Error('You are not authorized');
}

const data = { status: 200 };
const filteredData = await ac.filter('USER', 'query', 'status')(data);
filteredData; // { status: null }

Keywords

graphql

FAQs

Package last updated on 27 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts