casbin / node-casbin

An authorization library that supports access control models like ACL, RBAC, ABAC in Node.js and Browser
https://casbin.org
Apache License 2.0
2.6k stars 217 forks source link

Class extends value undefined is not a constructor or null #317

Closed giovanni-bertoncelli closed 3 years ago

giovanni-bertoncelli commented 3 years ago

When importing casbin in a typescript project for Angular I get this error: image

For the Model class I've solved by importing like this:

import { Model } from "casbin/lib/esm/model";

But for newEnforcer there is no way to work around that issue. Am I missing something?

giovanni-bertoncelli commented 3 years ago

Angular version: 11.2.4 Typescript version: 4.1.5

hsluoyz commented 3 years ago

@Zxilly @Gabriel-403

Gabriel-403 commented 3 years ago

ok,i know

Zxilly commented 3 years ago

@giovanni-bertoncelli Could you please a minimal reproduce example? with JSFiddle or something else

giovanni-bertoncelli commented 3 years ago

Sadly I can't reproduce the issue online... this is the maximum I can get: https://codesandbox.io/s/casbin-angular-issue-qjosh?file=/src/typings.d.ts

giovanni-bertoncelli commented 3 years ago

I think I've found where the issue is: image The problem occurs when trying to access the "stream" API in csv-parse module. Is there any way to bypass that or avoid to use the csv-parse module?

giovanni-bertoncelli commented 3 years ago

https://github.com/adaltas/node-csv-parse/issues/288

Zxilly commented 3 years ago

We have a platform independent version at https://github.com/casbin/casbin.js/tree/v1, but it is still work in progress and not production ready

Zxilly commented 3 years ago

@giovanni-bertoncelli Do you think this can solve your problem? I an make a patch with this.

giovanni-bertoncelli commented 3 years ago

I see... Unfortunately casbin.js does not satisfy my requirements for frontend ACL enforcement since the RBAC model is way more complex than the package can handle. I'm trying to find a way around this in order to use casbin on Angular environment but by enforcing only rules given by the JWT. I let you know if there is some development 👍🏻

Zxilly commented 3 years ago

@giovanni-bertoncelli Plz view casbin.js at v1 branch. casbin.js is under a totally refactor and will have the exactly funtion like node-casbin, but platform independent.

Zxilly commented 3 years ago

@giovanni-bertoncelli We will later release it with something like casbin.js@next. If you do need it, I think we can move this forward asap.

giovanni-bertoncelli commented 3 years ago

Sorry I haven't noticed that you where talking about a new version, now I see :) Well, I'll be glad to try it. If you can make a @next tag in a short time that would be amazing!

giovanni-bertoncelli commented 3 years ago

@Zxilly In the meanwhile is there a way to install the v1 version? I've tried by running npm i casbin/casbin.js#v1 but it does not download correctly since it should build from scratch...

Zxilly commented 3 years ago

@giovanni-bertoncelli I have been working with another community member and a new version will be released within 24 hours

giovanni-bertoncelli commented 3 years ago

Ok thanks!

nodece commented 3 years ago

@giovanni-bertoncelli I looked at the online demo, it does work.

giovanni-bertoncelli commented 3 years ago

@nodece Yes, as I said I can't reproduce the issue online, probably for compilation configuration differences. The workaround is to redirect the "stream" package to the readable-stream one. I can close this issue and wait for the "@next" release of casbin.js...

giovanni-bertoncelli commented 3 years ago

I don't think using that package is a good idea since the last update is from 7 years ago. As I said, I've solved the issue with the redirect to "readable-stream" package. I'll close this now.

nodece commented 3 years ago

@giovanni-bertoncelli thanks for your suggestion, we will improve this.

giovanni-bertoncelli commented 3 years ago

Let me know when the new version will be released :)

nodece commented 3 years ago

@giovanni-bertoncelli Once the new version is released, I will ping you.

giovanni-bertoncelli commented 3 years ago

@nodece @Zxilly any news? :)

Zxilly commented 3 years ago

@ghaiklor We are removing the dependency on csv-parse.But we are still discussing on the implementation of some standards

giovanni-bertoncelli commented 3 years ago

Maybe this can be a valid alternative: https://www.papaparse.com/

nodece commented 3 years ago

Hello @giovanni-bertoncelli, casbin.js@next has been released on NPM, you can use yarn add casbin.js@next or npm install casbin.js@next --save to add this to your project, how to use:

import { newEnforcer, newModel, MemoryAdapter } from 'casbin.js';

const model = newModel(`
[request_definition]
r = sub, obj, act

[policy_definition]
p = sub, obj, act

[role_definition]
g = _, _

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act
`);

const adapter = new MemoryAdapter(`
p, alice, data1, read
p, bob, data2, write
p, data2_admin, data2, read
p, data2_admin, data2, write

g, alice, data2_admin
`);

const enforcer = await newEnforcer(model, adapter);