diff --git a/packages/contracts/example/.gitkeep b/packages/contracts/example/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/packages/contracts/example/fabric_contracts_example.dart b/packages/contracts/example/fabric_contracts_example.dart deleted file mode 100644 index 255b101..0000000 --- a/packages/contracts/example/fabric_contracts_example.dart +++ /dev/null @@ -1,6 +0,0 @@ -import 'package:fabric_contracts/fabric_contracts.dart'; - -void main() { - var awesome = Awesome(); - print('awesome: ${awesome.isAwesome}'); -} diff --git a/packages/contracts/lib/fabric_contracts.dart b/packages/contracts/lib/contracts.dart similarity index 77% rename from packages/contracts/lib/fabric_contracts.dart rename to packages/contracts/lib/contracts.dart index b204c90..44cd577 100644 --- a/packages/contracts/lib/fabric_contracts.dart +++ b/packages/contracts/lib/contracts.dart @@ -3,6 +3,6 @@ /// More dartdocs go here. library; -export 'src/fabric_contracts_base.dart'; +// export 'src/fabric_contracts_base.dart'; // TODO: Export any libraries intended for clients of this package. diff --git a/packages/contracts/lib/src/auth/access/authorizable.dart b/packages/contracts/lib/src/auth/access/authorizable.dart new file mode 100644 index 0000000..d8cdf97 --- /dev/null +++ b/packages/contracts/lib/src/auth/access/authorizable.dart @@ -0,0 +1,9 @@ +abstract class Authorizable { + /// Determine if the entity has a given ability. + /// + /// [abilities] can be an Iterable or a String. + /// [arguments] can be a List or a dynamic type. + /// + /// Returns a boolean indicating if the entity has the given ability. + bool can(dynamic abilities, [List arguments = const []]); +} diff --git a/packages/contracts/lib/src/auth/access/gate.dart b/packages/contracts/lib/src/auth/access/gate.dart new file mode 100644 index 0000000..56035ab --- /dev/null +++ b/packages/contracts/lib/src/auth/access/gate.dart @@ -0,0 +1,51 @@ +// import 'package:meta/meta.dart'; + +abstract class Gate { + /// Determine if a given ability has been defined. + bool has(String ability); + + /// Define a new ability. + Gate define(String ability, dynamic callback); + + /// Define abilities for a resource. + Gate resource(String name, String className, [List? abilities]); + + /// Define a policy class for a given class type. + Gate policy(String className, String policy); + + /// Register a callback to run before all Gate checks. + Gate before(Function callback); + + /// Register a callback to run after all Gate checks. + Gate after(Function callback); + + /// Determine if all of the given abilities should be granted for the current user. + bool allows(dynamic ability, [dynamic arguments]); + + /// Determine if any of the given abilities should be denied for the current user. + bool denies(dynamic ability, [dynamic arguments]); + + /// Determine if all of the given abilities should be granted for the current user. + bool check(dynamic abilities, [dynamic arguments]); + + /// Determine if any one of the given abilities should be granted for the current user. + bool any(dynamic abilities, [dynamic arguments]); + + /// Determine if the given ability should be granted for the current user. + dynamic authorize(String ability, [dynamic arguments]); + + /// Inspect the user for the given ability. + dynamic inspect(String ability, [dynamic arguments]); + + /// Get the raw result from the authorization callback. + dynamic raw(String ability, [dynamic arguments]); + + /// Get a policy instance for a given class. + dynamic getPolicyFor(dynamic className); + + /// Get a guard instance for the given user. + Gate forUser(dynamic user); + + /// Get all of the defined abilities. + List abilities(); +} diff --git a/packages/contracts/lib/src/auth/authenticatable.dart b/packages/contracts/lib/src/auth/authenticatable.dart new file mode 100644 index 0000000..e69de29 diff --git a/packages/contracts/lib/src/auth/can_reset_password.dart b/packages/contracts/lib/src/auth/can_reset_password.dart new file mode 100644 index 0000000..e69de29 diff --git a/packages/contracts/lib/src/auth/factory.dart b/packages/contracts/lib/src/auth/factory.dart new file mode 100644 index 0000000..e69de29 diff --git a/packages/contracts/lib/src/auth/guard.dart b/packages/contracts/lib/src/auth/guard.dart new file mode 100644 index 0000000..e69de29 diff --git a/packages/contracts/lib/src/auth/middleware/authenticates_request.dart b/packages/contracts/lib/src/auth/middleware/authenticates_request.dart new file mode 100644 index 0000000..d2e3d2a --- /dev/null +++ b/packages/contracts/lib/src/auth/middleware/authenticates_request.dart @@ -0,0 +1,3 @@ +abstract class AuthenticatesRequests { + // Define abstract methods or properties if needed +} diff --git a/packages/contracts/lib/src/auth/must_verify_email.dart b/packages/contracts/lib/src/auth/must_verify_email.dart new file mode 100644 index 0000000..e69de29 diff --git a/packages/contracts/lib/src/auth/password_broker.dart b/packages/contracts/lib/src/auth/password_broker.dart new file mode 100644 index 0000000..e69de29 diff --git a/packages/contracts/lib/src/auth/password_broker_factory.dart b/packages/contracts/lib/src/auth/password_broker_factory.dart new file mode 100644 index 0000000..e69de29 diff --git a/packages/contracts/lib/src/auth/stateful_guard.dart b/packages/contracts/lib/src/auth/stateful_guard.dart new file mode 100644 index 0000000..e69de29 diff --git a/packages/contracts/lib/src/auth/supports_basic_auth.dart b/packages/contracts/lib/src/auth/supports_basic_auth.dart new file mode 100644 index 0000000..e69de29 diff --git a/packages/contracts/lib/src/auth/user_provider.dart b/packages/contracts/lib/src/auth/user_provider.dart new file mode 100644 index 0000000..e69de29 diff --git a/packages/contracts/lib/src/fabric_contracts_base.dart b/packages/contracts/lib/src/fabric_contracts_base.dart deleted file mode 100644 index e8a6f15..0000000 --- a/packages/contracts/lib/src/fabric_contracts_base.dart +++ /dev/null @@ -1,6 +0,0 @@ -// TODO: Put public facing types in this file. - -/// Checks if you are awesome. Spoiler: you are. -class Awesome { - bool get isAwesome => true; -} diff --git a/packages/contracts/test/.gitkeep b/packages/contracts/test/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/packages/contracts/test/fabric_contracts_test.dart b/packages/contracts/test/fabric_contracts_test.dart deleted file mode 100644 index 0e8fab0..0000000 --- a/packages/contracts/test/fabric_contracts_test.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:fabric_contracts/fabric_contracts.dart'; -import 'package:test/test.dart'; - -void main() { - group('A group of tests', () { - final awesome = Awesome(); - - setUp(() { - // Additional setup goes here. - }); - - test('First Test', () { - expect(awesome.isAwesome, isTrue); - }); - }); -}