1.5.1 • Published 2 years ago

accesscontrol-manager v1.5.1

Weekly downloads
10
License
MIT
Repository
github
Last release
2 years ago

accesscontrol-manager

Build Status npm npm

Clean and verify all your CRUD operations in one place.

Requirements

Installation

npm install --save accesscontrol-manager

Usage

const AccesscontrolManager = require('accesscontrol-manager')({
  //...options
})

let data = AccesscontrolManager.read({
  acl: acl, //AccessControl object
  user: user,
  query: () => [QUERYDATA],
  isOwnerFunc: () => true,
  resource: 'Movie',
})

Methods

MethodDescription
.create(options)Call on creation
.read(options)Call on read
.update(options)Call on update
.delete(options)Call on delete

Options

KeyTypeDescriptionScopeExample
resourceStringName of resourceall"Movie"
userObjectRequesting entity (User in most cases)all-
aclAccessControlScoped accesscontol objectallacl.can('admin')
queryFunctionFunction that returns Promise/Array/Object from storageread/update/delete() => DB.fetch("...")
dataArray/ObjectData to be created/updatedcreate/update-
isOwnerFuncFunction(doc, user)Function that resolves ownership of document and returns true/falseall(doc, user) => doc.owner === user.id
createFuncFunction(data, meta)Function that creates the new document. data has been filtered by AccessControl. Meta contains information about ownershipcreate(data, meta) => new Movie(data).save()
updateFuncFunction(doc, data, meta)Function that updates the document. doc is the document that is beeing updated. data has been filtered by AccessControl. Meta contains information about ownershipupdate(doc, data, meta) => { PartialUpate(doc, data); return doc.save() }
deleteFuncFunction(doc, meta)Function that deletes the document. doc is the document that is beeing deleted. Meta contains information about ownershipdelete(doc, meta) => doc.remove()
transformFunc or preTransformFuncFunction(data)Function that transforms the result before running it through the ACL filterall(data) => { data.someProp = 'test'; return data }
postTransformFuncFunction(data)Function that transforms the result after running it through the ACL filterall(data) => { data.someProp = 'test'; return data }
documentPathStringSelector(string) to extract data from query result. E.g. use this when working with paginationalldocs

License

The MIT License Copyright (c) Carsten Jacobsen

1.5.1

2 years ago

1.5.0

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

3 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.2.1

4 years ago

1.2.0

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago