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

@permify/node-permify

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

@permify/node-permify

Node Client of Permify

unpublished
latest
Source
npmnpm
Version
2.1.0
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Permify Node.js Client

npm Twitter URL

Use Permify in server-side Node.js Projects.

Install

npm install @permify/node-permify

Usage

To get started, create Permify client using your Workspace id and API private key:

with require

const Permify = require("@permify/node-permify");

const permifyClient = new Permify.Client("workspace_id", "private_token");

with import

import { Client as PermifyClient } from "@permify/node-permify";

const permifyClient = new PermifyClient("workspace_id", "private_token");

Create Group

In order to start using Permify you need to have at least one group entity which is part of your workspace. This method creates a group entity in Permify.

const payload = {
    //If your app is a multi-tenant, id represents your group or tenant's id.
    //If your app is not multi-tenant or haven't got group entity,
    //Give any kind of identier value in here to create one.
    id: 'test_cs1234utg',
    
    //Name of the group
    name: 'test_name'
}

permifyClient.createGroup(payload)
    .then((group) => {
        console.log(group)
    })
    .catch((error) => {
        console.log(error.response)
    });

Create User

This method creates a user entity in Permify. You need a group, which the created user must belong.

const payload = {
    //Id of the user to be created in your app
    id: "id",

    //id of group
    group_id: "group id",

    // name of the user
    name: "name",

    // photo url of the user
    photo: "",

    // role names array
    role_names: [],

    // custom attributes
    attributes: {}
};

permifyClient.createUser(payload).then((user) => {
        console.log(user)
    })
    .catch((error) => {
        console.log(error.response)
    });

Create Role

This method creates a role entity in Permify.

permifyClient.createRole('group_id', {name: 'test_role'})
    .then((role) => {
        console.log(role)
    })
    .catch((error) => {
        console.log(error.response)
    });

Create Rule

This method creates a rule entity in Permify.

Sample Rules

Is the user senior?

user.attributes.tenure > 8

Is the user manager?

"manager" in user.roles

Is the user admin?

"admin" in user.roles

Is the user the owner of the resource?

user.id == resource.attributes.owner_id
const payload = {
    // name of rule
    name: "name",

    // conditions
    conditions: []
};

permifyClient.createRule(payload).then((rule) => {
        console.log(rule)
    })
    .catch((error) => {
        console.log(error.response.data)
    });

Create Option

This method creates a option entity in Permify.

const payload = {
    // name of option
    name: "name",

    // rule names
    rule_names: []
};

permifyClient.createOption(payload).then((option) => {
        console.log(option)
    })
    .catch((error) => {
        console.log(error.response.data)
    });

Create Policy

This method creates a policy entity in Permify.

const payload = {
    // name of policy
    name: "name",

    // rule names
    option_names: []
};

permifyClient.createPolicy(payload).then((policy) => {
        console.log(policy)
    })
    .catch((error) => {
        console.log(error.response.data)
    });

IsAuthorized

This method returns a decision about whether the user is authorized for this action with the given parameters.

Parameters

  • PolicyName (mandatory)

Custom Permify Policy name.

  • UserID (optional)

Id of the User

  • ResourceID (optional)

Id of the Resource, mandatory if any resource used or accessed when creating Rule/Rules.

  • ResourceType (optional)

Type or name of the Resource, mandatory if any resource used or accessed when creating Rule/Rules.

const payload = {
    // name of policy
    policy_name: "policy name",
    
    // id of user
    user_id: "user id",
    
    // resource (optional)
    resource_id: "resource id",
    resource_type: "resource type"
};
permifyClient.isAuthorized(payload)
    .then((rule) => {
        if(rule.data.allow){
            // action
        }
    })
    .catch((error) => {
        console.log(error.response)
    });

For more information on how to use the Permify API, please refer to the Permify API Reference.

Permify Documentation

See more

FAQs

Package last updated on 21 Mar 2022

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