Refactor: changing namespace, imports, re-branding
This commit is contained in:
parent
f4abaf2474
commit
2ea69f2cde
64 changed files with 179 additions and 171 deletions
|
@ -135,9 +135,9 @@
|
||||||
## 2.0.0
|
## 2.0.0
|
||||||
|
|
||||||
* Made `AuthStrategy` generic.
|
* Made `AuthStrategy` generic.
|
||||||
* `AngelAuth.strategies` is now a `Map<String, AuthStrategy<User>>`.
|
* `ProtevusAuth.strategies` is now a `Map<String, AuthStrategy<User>>`.
|
||||||
* Removed `AuthStrategy.canLogout`.
|
* Removed `AuthStrategy.canLogout`.
|
||||||
* Made `AngelAuthTokenCallback` generic.
|
* Made `ProtevusAuthTokenCallback` generic.
|
||||||
|
|
||||||
## 2.0.0-alpha
|
## 2.0.0-alpha
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ Ensure you have read the [User Guide](https://protevus-docs.dukefirehawk.com/gui
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
configureServer(Protevus app) async {
|
configureServer(Protevus app) async {
|
||||||
var auth = AngelAuth<User>(
|
var auth = ProtevusAuth<User>(
|
||||||
serializer: (user) => user.id ?? '',
|
serializer: (user) => user.id ?? '',
|
||||||
deserializer: (id) => fetchAUserByIdSomehow(id
|
deserializer: (id) => fetchAUserByIdSomehow(id
|
||||||
);
|
);
|
||||||
|
@ -58,7 +58,7 @@ A frequent use case within SPA's is opening OAuth login endpoints in a separate
|
||||||
configureServer(Protevus app) async {
|
configureServer(Protevus app) async {
|
||||||
var handler = auth.authenticate(
|
var handler = auth.authenticate(
|
||||||
'facebook',
|
'facebook',
|
||||||
AngelAuthOptions(callback: confirmPopupAuthentication()));
|
ProtevusAuthOptions(callback: confirmPopupAuthentication()));
|
||||||
app.get('/auth/facebook', handler);
|
app.get('/auth/facebook', handler);
|
||||||
|
|
||||||
// Use a comma to try multiple strategies!!!
|
// Use a comma to try multiple strategies!!!
|
||||||
|
|
|
@ -5,7 +5,7 @@ import 'package:protevus_framework/http.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
var app = Protevus();
|
var app = Protevus();
|
||||||
var auth = AngelAuth<User>(
|
var auth = ProtevusAuth<User>(
|
||||||
serializer: (user) => user.id ?? '',
|
serializer: (user) => user.id ?? '',
|
||||||
deserializer: (id) => fetchAUserByIdSomehow(id));
|
deserializer: (id) => fetchAUserByIdSomehow(id));
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ void main() async {
|
||||||
.findService('users')
|
.findService('users')
|
||||||
?.create({'username': 'jdoe1', 'password': 'password'});
|
?.create({'username': 'jdoe1', 'password': 'password'});
|
||||||
|
|
||||||
var auth = AngelAuth<User>(
|
var auth = ProtevusAuth<User>(
|
||||||
serializer: (u) => u.id ?? '',
|
serializer: (u) => u.id ?? '',
|
||||||
deserializer: (id) async =>
|
deserializer: (id) async =>
|
||||||
await app.findService('users')?.read(id) as User);
|
await app.findService('users')?.read(id) as User);
|
||||||
|
@ -88,7 +88,8 @@ void main() async {
|
||||||
|
|
||||||
app.post(
|
app.post(
|
||||||
'/login',
|
'/login',
|
||||||
auth.authenticate('local', AngelAuthOptions(callback: (req, res, token) {
|
auth.authenticate('local',
|
||||||
|
ProtevusAuthOptions(callback: (req, res, token) {
|
||||||
res
|
res
|
||||||
..write('Hello!')
|
..write('Hello!')
|
||||||
..close();
|
..close();
|
||||||
|
|
|
@ -7,13 +7,15 @@ import 'package:logging/logging.dart';
|
||||||
|
|
||||||
final Map<String, String> sampleUser = {'hello': 'world'};
|
final Map<String, String> sampleUser = {'hello': 'world'};
|
||||||
|
|
||||||
final AngelAuth<Map<String, String>> auth = AngelAuth<Map<String, String>>(
|
final ProtevusAuth<Map<String, String>> auth =
|
||||||
serializer: (user) async => '1337', deserializer: (id) async => sampleUser);
|
ProtevusAuth<Map<String, String>>(
|
||||||
|
serializer: (user) async => '1337',
|
||||||
|
deserializer: (id) async => sampleUser);
|
||||||
//var headers = <String, String>{'accept': 'application/json'};
|
//var headers = <String, String>{'accept': 'application/json'};
|
||||||
var localOpts = AngelAuthOptions<Map<String, String>>(
|
var localOpts = ProtevusAuthOptions<Map<String, String>>(
|
||||||
failureRedirect: '/failure', successRedirect: '/success');
|
failureRedirect: '/failure', successRedirect: '/success');
|
||||||
var localOpts2 =
|
var localOpts2 =
|
||||||
AngelAuthOptions<Map<String, String>>(canRespondWithJson: false);
|
ProtevusAuthOptions<Map<String, String>>(canRespondWithJson: false);
|
||||||
|
|
||||||
Future<Map<String, String>> verifier(String? username, String? password) async {
|
Future<Map<String, String>> verifier(String? username, String? password) async {
|
||||||
if (username == 'username' && password == 'password') {
|
if (username == 'username' && password == 'password') {
|
||||||
|
|
|
@ -3,15 +3,15 @@ import 'dart:async';
|
||||||
import 'package:protevus_framework/protevus_framework.dart';
|
import 'package:protevus_framework/protevus_framework.dart';
|
||||||
import 'auth_token.dart';
|
import 'auth_token.dart';
|
||||||
|
|
||||||
typedef AngelAuthCallback = FutureOr Function(
|
typedef ProtevusAuthCallback = FutureOr Function(
|
||||||
RequestContext req, ResponseContext res, String token);
|
RequestContext req, ResponseContext res, String token);
|
||||||
|
|
||||||
typedef AngelAuthTokenCallback<User> = FutureOr Function(
|
typedef ProtevusAuthTokenCallback<User> = FutureOr Function(
|
||||||
RequestContext req, ResponseContext res, AuthToken token, User user);
|
RequestContext req, ResponseContext res, AuthToken token, User user);
|
||||||
|
|
||||||
class AngelAuthOptions<User> {
|
class ProtevusAuthOptions<User> {
|
||||||
AngelAuthCallback? callback;
|
ProtevusAuthCallback? callback;
|
||||||
AngelAuthTokenCallback<User>? tokenCallback;
|
ProtevusAuthTokenCallback<User>? tokenCallback;
|
||||||
String? successRedirect;
|
String? successRedirect;
|
||||||
String? failureRedirect;
|
String? failureRedirect;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ class AngelAuthOptions<User> {
|
||||||
/// Works well with `Basic` authentication.
|
/// Works well with `Basic` authentication.
|
||||||
bool canRespondWithJson;
|
bool canRespondWithJson;
|
||||||
|
|
||||||
AngelAuthOptions(
|
ProtevusAuthOptions(
|
||||||
{this.callback,
|
{this.callback,
|
||||||
this.tokenCallback,
|
this.tokenCallback,
|
||||||
this.canRespondWithJson = true,
|
this.canRespondWithJson = true,
|
||||||
|
|
|
@ -10,8 +10,8 @@ import 'options.dart';
|
||||||
import 'strategy.dart';
|
import 'strategy.dart';
|
||||||
|
|
||||||
/// Handles authentication within an Protevus application.
|
/// Handles authentication within an Protevus application.
|
||||||
class AngelAuth<User> {
|
class ProtevusAuth<User> {
|
||||||
final _log = Logger('AngelAuth');
|
final _log = Logger('ProtevusAuth');
|
||||||
|
|
||||||
late Hmac _hs256;
|
late Hmac _hs256;
|
||||||
late int _jwtLifeSpan;
|
late int _jwtLifeSpan;
|
||||||
|
@ -78,7 +78,7 @@ class AngelAuth<User> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `jwtLifeSpan` - should be in *milliseconds*.
|
/// `jwtLifeSpan` - should be in *milliseconds*.
|
||||||
AngelAuth(
|
ProtevusAuth(
|
||||||
{String? jwtKey,
|
{String? jwtKey,
|
||||||
required this.serializer,
|
required this.serializer,
|
||||||
required this.deserializer,
|
required this.deserializer,
|
||||||
|
@ -101,11 +101,11 @@ class AngelAuth<User> {
|
||||||
/*
|
/*
|
||||||
if (serializer == null) {
|
if (serializer == null) {
|
||||||
throw StateError(
|
throw StateError(
|
||||||
'An `AngelAuth` plug-in was called without its `serializer` being set. All authentication will fail.');
|
'An `ProtevusAuth` plug-in was called without its `serializer` being set. All authentication will fail.');
|
||||||
}
|
}
|
||||||
if (deserializer == null) {
|
if (deserializer == null) {
|
||||||
throw StateError(
|
throw StateError(
|
||||||
'An `AngelAuth` plug-in was called without its `deserializer` being set. All authentication will fail.');
|
'An `ProtevusAuth` plug-in was called without its `deserializer` being set. All authentication will fail.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (app.container == null) {
|
if (app.container == null) {
|
||||||
|
@ -117,8 +117,8 @@ class AngelAuth<User> {
|
||||||
var appContainer = app.container;
|
var appContainer = app.container;
|
||||||
|
|
||||||
appContainer.registerSingleton(this);
|
appContainer.registerSingleton(this);
|
||||||
if (runtimeType != AngelAuth) {
|
if (runtimeType != ProtevusAuth) {
|
||||||
appContainer.registerSingleton(this, as: AngelAuth);
|
appContainer.registerSingleton(this, as: ProtevusAuth);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!appContainer.has<_AuthResult<User>>()) {
|
if (!appContainer.has<_AuthResult<User>>()) {
|
||||||
|
@ -128,7 +128,7 @@ class AngelAuth<User> {
|
||||||
var res = container.make<ResponseContext>();
|
var res = container.make<ResponseContext>();
|
||||||
//if (req == null || res == null) {
|
//if (req == null || res == null) {
|
||||||
// _log.warning('RequestContext or responseContext is null');
|
// _log.warning('RequestContext or responseContext is null');
|
||||||
// throw AngelHttpException.forbidden();
|
// throw ProtevusHttpException.forbidden();
|
||||||
//}
|
//}
|
||||||
|
|
||||||
var result = await _decodeJwt(req, res);
|
var result = await _decodeJwt(req, res);
|
||||||
|
@ -187,7 +187,7 @@ class AngelAuth<User> {
|
||||||
/// `makeAsync<User>`, or Protevus's injections directly:
|
/// `makeAsync<User>`, or Protevus's injections directly:
|
||||||
///
|
///
|
||||||
/// ```dart
|
/// ```dart
|
||||||
/// var auth = AngelAuth<User>(...);
|
/// var auth = ProtevusAuth<User>(...);
|
||||||
/// await app.configure(auth.configureServer);
|
/// await app.configure(auth.configureServer);
|
||||||
///
|
///
|
||||||
/// app.get('/hmm', (User user) async {
|
/// app.get('/hmm', (User user) async {
|
||||||
|
@ -355,9 +355,9 @@ class AngelAuth<User> {
|
||||||
/// or a `401 Not Authenticated` is thrown, if it is the last one.
|
/// or a `401 Not Authenticated` is thrown, if it is the last one.
|
||||||
///
|
///
|
||||||
/// Any other result is considered an authenticated user, and terminates the loop.
|
/// Any other result is considered an authenticated user, and terminates the loop.
|
||||||
RequestHandler authenticate(type, [AngelAuthOptions<User>? opt]) {
|
RequestHandler authenticate(type, [ProtevusAuthOptions<User>? opt]) {
|
||||||
return (RequestContext req, ResponseContext res) async {
|
return (RequestContext req, ResponseContext res) async {
|
||||||
var authOption = opt ?? AngelAuthOptions<User>();
|
var authOption = opt ?? ProtevusAuthOptions<User>();
|
||||||
|
|
||||||
var names = <String>[];
|
var names = <String>[];
|
||||||
|
|
||||||
|
@ -485,7 +485,7 @@ class AngelAuth<User> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Log an authenticated user out.
|
/// Log an authenticated user out.
|
||||||
RequestHandler logout([AngelAuthOptions<User>? options]) {
|
RequestHandler logout([ProtevusAuthOptions<User>? options]) {
|
||||||
return (RequestContext req, ResponseContext res) async {
|
return (RequestContext req, ResponseContext res) async {
|
||||||
if (req.container?.has<User>() == true) {
|
if (req.container?.has<User>() == true) {
|
||||||
var user = req.container?.make<User>();
|
var user = req.container?.make<User>();
|
||||||
|
|
|
@ -4,7 +4,7 @@ import 'package:http_parser/http_parser.dart';
|
||||||
import 'options.dart';
|
import 'options.dart';
|
||||||
|
|
||||||
/// Displays a default callback page to confirm authentication via popups.
|
/// Displays a default callback page to confirm authentication via popups.
|
||||||
AngelAuthCallback confirmPopupAuthentication({String eventName = 'token'}) {
|
ProtevusAuthCallback confirmPopupAuthentication({String eventName = 'token'}) {
|
||||||
return (req, ResponseContext res, String jwt) {
|
return (req, ResponseContext res, String jwt) {
|
||||||
var evt = json.encode(eventName);
|
var evt = json.encode(eventName);
|
||||||
var detail = json.encode({'detail': jwt});
|
var detail = json.encode({'detail': jwt});
|
||||||
|
|
|
@ -36,8 +36,8 @@ class LocalAuthStrategy<User> extends AuthStrategy<User> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<User?> authenticate(RequestContext req, ResponseContext res,
|
Future<User?> authenticate(RequestContext req, ResponseContext res,
|
||||||
[AngelAuthOptions? options]) async {
|
[ProtevusAuthOptions? options]) async {
|
||||||
var localOptions = options ?? AngelAuthOptions();
|
var localOptions = options ?? ProtevusAuthOptions();
|
||||||
User? verificationResult;
|
User? verificationResult;
|
||||||
|
|
||||||
if (allowBasic) {
|
if (allowBasic) {
|
||||||
|
@ -129,7 +129,7 @@ class LocalAuthStrategy<User> extends AuthStrategy<User> {
|
||||||
return verificationResult;
|
return verificationResult;
|
||||||
} else {
|
} else {
|
||||||
_log.info('Not authenticated');
|
_log.info('Not authenticated');
|
||||||
throw AngelHttpException.notAuthenticated();
|
throw ProtevusHttpException.notAuthenticated();
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,5 +6,5 @@ import 'options.dart';
|
||||||
abstract class AuthStrategy<User> {
|
abstract class AuthStrategy<User> {
|
||||||
/// Authenticates or rejects an incoming user.
|
/// Authenticates or rejects an incoming user.
|
||||||
FutureOr<User?> authenticate(RequestContext req, ResponseContext res,
|
FutureOr<User?> authenticate(RequestContext req, ResponseContext res,
|
||||||
[AngelAuthOptions<User>? options]);
|
[ProtevusAuthOptions<User>? options]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ class User extends Model {
|
||||||
void main() {
|
void main() {
|
||||||
late Protevus app;
|
late Protevus app;
|
||||||
late ProtevusHttp angelHttp;
|
late ProtevusHttp angelHttp;
|
||||||
AngelAuth<User> auth;
|
ProtevusAuth<User> auth;
|
||||||
http.Client? client;
|
http.Client? client;
|
||||||
HttpServer server;
|
HttpServer server;
|
||||||
String? url;
|
String? url;
|
||||||
|
@ -73,7 +73,7 @@ void main() {
|
||||||
.findService('users')
|
.findService('users')
|
||||||
?.create({'username': 'jdoe1', 'password': 'password'});
|
?.create({'username': 'jdoe1', 'password': 'password'});
|
||||||
|
|
||||||
auth = AngelAuth<User>(
|
auth = ProtevusAuth<User>(
|
||||||
serializer: (u) => u.id ?? '',
|
serializer: (u) => u.id ?? '',
|
||||||
deserializer: (id) async =>
|
deserializer: (id) async =>
|
||||||
await app.findService('users')?.read(id) as User);
|
await app.findService('users')?.read(id) as User);
|
||||||
|
@ -98,7 +98,7 @@ void main() {
|
||||||
app.post(
|
app.post(
|
||||||
'/login',
|
'/login',
|
||||||
auth.authenticate('local',
|
auth.authenticate('local',
|
||||||
AngelAuthOptions(callback: (req, res, token) {
|
ProtevusAuthOptions(callback: (req, res, token) {
|
||||||
res
|
res
|
||||||
..write('Hello!')
|
..write('Hello!')
|
||||||
..close();
|
..close();
|
||||||
|
|
|
@ -8,13 +8,15 @@ import 'package:http/http.dart' as http;
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
final AngelAuth<Map<String, String>> auth = AngelAuth<Map<String, String>>(
|
final ProtevusAuth<Map<String, String>> auth =
|
||||||
serializer: (user) async => '1337', deserializer: (id) async => sampleUser);
|
ProtevusAuth<Map<String, String>>(
|
||||||
|
serializer: (user) async => '1337',
|
||||||
|
deserializer: (id) async => sampleUser);
|
||||||
//var headers = <String, String>{'accept': 'application/json'};
|
//var headers = <String, String>{'accept': 'application/json'};
|
||||||
var localOpts = AngelAuthOptions<Map<String, String>>(
|
var localOpts = ProtevusAuthOptions<Map<String, String>>(
|
||||||
failureRedirect: '/failure', successRedirect: '/success');
|
failureRedirect: '/failure', successRedirect: '/success');
|
||||||
var localOpts2 =
|
var localOpts2 =
|
||||||
AngelAuthOptions<Map<String, String>>(canRespondWithJson: false);
|
ProtevusAuthOptions<Map<String, String>>(canRespondWithJson: false);
|
||||||
|
|
||||||
Map<String, String> sampleUser = {'hello': 'world'};
|
Map<String, String> sampleUser = {'hello': 'world'};
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ const Duration threeDays = Duration(days: 3);
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late Cookie defaultCookie;
|
late Cookie defaultCookie;
|
||||||
var auth = AngelAuth(
|
var auth = ProtevusAuth(
|
||||||
secureCookies: true,
|
secureCookies: true,
|
||||||
cookieDomain: 'SECURE',
|
cookieDomain: 'SECURE',
|
||||||
jwtLifeSpan: threeDays.inMilliseconds,
|
jwtLifeSpan: threeDays.inMilliseconds,
|
||||||
|
|
|
@ -71,4 +71,4 @@
|
||||||
|
|
||||||
## 1.0.2
|
## 1.0.2
|
||||||
|
|
||||||
Added `getParameters` to `AngelOAuth2Options`.
|
Added `getParameters` to `ProtevusOAuth2Options`.
|
||||||
|
|
|
@ -71,7 +71,7 @@ configureServer(Protevus app) {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Lastly, connect it to an `AngelAuth` instance, and wire it up to an `Protevus` server. Set up two routes:
|
Lastly, connect it to an `ProtevusAuth` instance, and wire it up to an `Protevus` server. Set up two routes:
|
||||||
|
|
||||||
1. Redirect users to the external provider
|
1. Redirect users to the external provider
|
||||||
2. Acts as a callback and handles an access code
|
2. Acts as a callback and handles an access code
|
||||||
|
@ -81,7 +81,7 @@ In the case of the callback route, you may want to display an HTML page that clo
|
||||||
```dart
|
```dart
|
||||||
configureServer(Protevus app) async {
|
configureServer(Protevus app) async {
|
||||||
// ...
|
// ...
|
||||||
var auth = AngelAuth<User>();
|
var auth = ProtevusAuth<User>();
|
||||||
auth.strategies['github'] = oauth2Strategy;
|
auth.strategies['github'] = oauth2Strategy;
|
||||||
|
|
||||||
// Redirect
|
// Redirect
|
||||||
|
@ -90,7 +90,7 @@ configureServer(Protevus app) async {
|
||||||
// Callback
|
// Callback
|
||||||
app.get('/auth/github/callback', auth.authenticate(
|
app.get('/auth/github/callback', auth.authenticate(
|
||||||
'github',
|
'github',
|
||||||
AngelAuthOptions(callback: confirmPopupAuthentication())
|
ProtevusAuthOptions(callback: confirmPopupAuthentication())
|
||||||
));
|
));
|
||||||
|
|
||||||
// Connect the plug-in!!!
|
// Connect the plug-in!!!
|
||||||
|
|
|
@ -47,7 +47,7 @@ void main() async {
|
||||||
var mappedUserService = userService.map(User.parse, User.serialize);
|
var mappedUserService = userService.map(User.parse, User.serialize);
|
||||||
|
|
||||||
// Set up the authenticator plugin.
|
// Set up the authenticator plugin.
|
||||||
var auth = AngelAuth<User>(
|
var auth = ProtevusAuth<User>(
|
||||||
serializer: (user) async => user.id ?? '',
|
serializer: (user) async => user.id ?? '',
|
||||||
deserializer: (id) => mappedUserService.read(id),
|
deserializer: (id) => mappedUserService.read(id),
|
||||||
jwtKey: 'oauth2 example secret',
|
jwtKey: 'oauth2 example secret',
|
||||||
|
@ -94,7 +94,7 @@ void main() async {
|
||||||
app.get(
|
app.get(
|
||||||
'/auth/github/callback',
|
'/auth/github/callback',
|
||||||
auth.authenticate('github',
|
auth.authenticate('github',
|
||||||
AngelAuthOptions(callback: (req, res, jwt) async {
|
ProtevusAuthOptions(callback: (req, res, jwt) async {
|
||||||
// In real-life, you might include a pop-up callback script.
|
// In real-life, you might include a pop-up callback script.
|
||||||
//
|
//
|
||||||
// Use `confirmPopupAuthentication`, which is bundled with
|
// Use `confirmPopupAuthentication`, which is bundled with
|
||||||
|
|
|
@ -47,7 +47,7 @@ class OAuth2Strategy<User> implements AuthStrategy<User> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FutureOr<User?> authenticate(RequestContext req, ResponseContext res,
|
FutureOr<User?> authenticate(RequestContext req, ResponseContext res,
|
||||||
[AngelAuthOptions<User>? options]) async {
|
[ProtevusAuthOptions<User>? options]) async {
|
||||||
if (options != null) {
|
if (options != null) {
|
||||||
var result = await authenticateCallback(req, res, options);
|
var result = await authenticateCallback(req, res, options);
|
||||||
if (result is User) {
|
if (result is User) {
|
||||||
|
@ -71,7 +71,7 @@ class OAuth2Strategy<User> implements AuthStrategy<User> {
|
||||||
|
|
||||||
/// The endpoint that is invoked by the third-party after successful authentication.
|
/// The endpoint that is invoked by the third-party after successful authentication.
|
||||||
Future<dynamic> authenticateCallback(RequestContext req, ResponseContext res,
|
Future<dynamic> authenticateCallback(RequestContext req, ResponseContext res,
|
||||||
[AngelAuthOptions? options]) async {
|
[ProtevusAuthOptions? options]) async {
|
||||||
var grant = _createGrant();
|
var grant = _createGrant();
|
||||||
grant.getAuthorizationUrl(this.options.redirectUri,
|
grant.getAuthorizationUrl(this.options.redirectUri,
|
||||||
scopes: this.options.scopes);
|
scopes: this.options.scopes);
|
||||||
|
|
|
@ -17,7 +17,7 @@ class _User {
|
||||||
void main() async {
|
void main() async {
|
||||||
var app = Protevus();
|
var app = Protevus();
|
||||||
var http = ProtevusHttp(app);
|
var http = ProtevusHttp(app);
|
||||||
var auth = AngelAuth<_User>(
|
var auth = ProtevusAuth<_User>(
|
||||||
jwtKey: 'AUTH_TWITTER_SECRET',
|
jwtKey: 'AUTH_TWITTER_SECRET',
|
||||||
allowCookie: false,
|
allowCookie: false,
|
||||||
serializer: (user) async => user.handle,
|
serializer: (user) async => user.handle,
|
||||||
|
@ -59,7 +59,7 @@ void main() async {
|
||||||
'/auth/twitter/callback',
|
'/auth/twitter/callback',
|
||||||
auth.authenticate(
|
auth.authenticate(
|
||||||
'twitter',
|
'twitter',
|
||||||
AngelAuthOptions(
|
ProtevusAuthOptions(
|
||||||
callback: (req, res, jwt) {
|
callback: (req, res, jwt) {
|
||||||
return res.redirect('/home?token=$jwt');
|
return res.redirect('/home?token=$jwt');
|
||||||
},
|
},
|
||||||
|
|
|
@ -119,7 +119,7 @@ class TwitterStrategy<User> extends AuthStrategy<User> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<User?> authenticate(RequestContext req, ResponseContext res,
|
Future<User?> authenticate(RequestContext req, ResponseContext res,
|
||||||
[AngelAuthOptions? options]) async {
|
[ProtevusAuthOptions? options]) async {
|
||||||
try {
|
try {
|
||||||
if (options != null) {
|
if (options != null) {
|
||||||
var result = await authenticateCallback(req, res, options);
|
var result = await authenticateCallback(req, res, options);
|
||||||
|
@ -145,8 +145,8 @@ class TwitterStrategy<User> extends AuthStrategy<User> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future authenticateCallback(
|
Future authenticateCallback(RequestContext req, ResponseContext res,
|
||||||
RequestContext req, ResponseContext res, AngelAuthOptions options) async {
|
ProtevusAuthOptions options) async {
|
||||||
try {
|
try {
|
||||||
if (req.queryParameters.containsKey('denied')) {
|
if (req.queryParameters.containsKey('denied')) {
|
||||||
throw TwitterAuthorizationException(
|
throw TwitterAuthorizationException(
|
||||||
|
|
2
packages/cache/README.md
vendored
2
packages/cache/README.md
vendored
|
@ -84,7 +84,7 @@ Some servers expect a reverse proxy or caching layer to support `PURGE` requests
|
||||||
Future configureServer(Protevus app) async {
|
Future configureServer(Protevus app) async {
|
||||||
app.addRoute('PURGE', '*', (req, res) {
|
app.addRoute('PURGE', '*', (req, res) {
|
||||||
if (req.ip != '127.0.0.1')
|
if (req.ip != '127.0.0.1')
|
||||||
throw AngelHttpException.forbidden();
|
throw ProtevusHttpException.forbidden();
|
||||||
return cache.purge(req.uri.path);
|
return cache.purge(req.uri.path);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@
|
||||||
|
|
||||||
## 2.0.1
|
## 2.0.1
|
||||||
|
|
||||||
* Change `BaseAngelClient` constructor to accept `dynamic` instead of `String` for `baseUrl.
|
* Change `BaseProtevusClient` constructor to accept `dynamic` instead of `String` for `baseUrl.
|
||||||
|
|
||||||
## 2.0.0
|
## 2.0.0
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ print(auth.data); // User object
|
||||||
Revive an existing jwt:
|
Revive an existing jwt:
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
Future<AngelAuthResult> reviveJwt(String jwt) {
|
Future<ProtevusAuthResult> reviveJwt(String jwt) {
|
||||||
return app.authenticate(credentials: {'token': jwt});
|
return app.authenticate(credentials: {'token': jwt});
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -6,11 +6,11 @@ import 'package:logging/logging.dart';
|
||||||
void main() async {
|
void main() async {
|
||||||
const Map<String, String> user = {'username': 'foo', 'password': 'bar'};
|
const Map<String, String> user = {'username': 'foo', 'password': 'bar'};
|
||||||
var localOpts =
|
var localOpts =
|
||||||
AngelAuthOptions<Map<String, String>>(canRespondWithJson: true);
|
ProtevusAuthOptions<Map<String, String>>(canRespondWithJson: true);
|
||||||
|
|
||||||
Protevus app = Protevus();
|
Protevus app = Protevus();
|
||||||
ProtevusHttp http = ProtevusHttp(app, useZone: false);
|
ProtevusHttp http = ProtevusHttp(app, useZone: false);
|
||||||
var auth = AngelAuth(
|
var auth = ProtevusAuth(
|
||||||
serializer: (_) async => 'baz', deserializer: (_) async => user);
|
serializer: (_) async => 'baz', deserializer: (_) async => user);
|
||||||
|
|
||||||
auth.strategies['local'] = LocalAuthStrategy((username, password) async {
|
auth.strategies['local'] = LocalAuthStrategy((username, password) async {
|
||||||
|
|
|
@ -42,7 +42,7 @@ ProtevusHttpException failure(Response response,
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class BaseProtevusClient extends Protevus {
|
abstract class BaseProtevusClient extends Protevus {
|
||||||
final _log = Logger('BaseAngelClient');
|
final _log = Logger('BaseProtevusClient');
|
||||||
final StreamController<ProtevusAuthResult> _onAuthenticated =
|
final StreamController<ProtevusAuthResult> _onAuthenticated =
|
||||||
StreamController<ProtevusAuthResult>();
|
StreamController<ProtevusAuthResult>();
|
||||||
final List<Service> _services = [];
|
final List<Service> _services = [];
|
||||||
|
|
|
@ -3,7 +3,7 @@ import 'package:test/test.dart';
|
||||||
import 'common.dart';
|
import 'common.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
var app = MockAngel();
|
var app = MockProtevus();
|
||||||
var todoService = app.service('api/todos');
|
var todoService = app.service('api/todos');
|
||||||
|
|
||||||
test('sets method,body,headers,path', () async {
|
test('sets method,body,headers,path', () async {
|
||||||
|
|
|
@ -6,7 +6,8 @@ import 'package:logging/logging.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
const Map<String, String> user = {'username': 'foo', 'password': 'bar'};
|
const Map<String, String> user = {'username': 'foo', 'password': 'bar'};
|
||||||
var localOpts = AngelAuthOptions<Map<String, String>>(canRespondWithJson: true);
|
var localOpts =
|
||||||
|
ProtevusAuthOptions<Map<String, String>>(canRespondWithJson: true);
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late Protevus app;
|
late Protevus app;
|
||||||
|
@ -16,7 +17,7 @@ void main() {
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
app = Protevus();
|
app = Protevus();
|
||||||
http = ProtevusHttp(app, useZone: false);
|
http = ProtevusHttp(app, useZone: false);
|
||||||
var auth = AngelAuth(
|
var auth = ProtevusAuth(
|
||||||
serializer: (_) async => 'baz', deserializer: (_) async => user);
|
serializer: (_) async => 'baz', deserializer: (_) async => user);
|
||||||
|
|
||||||
auth.strategies['local'] = LocalAuthStrategy(
|
auth.strategies['local'] = LocalAuthStrategy(
|
||||||
|
|
|
@ -8,13 +8,13 @@ import 'package:http/src/streamed_response.dart' as http;
|
||||||
Future<String> read(Stream<List<int>> stream) =>
|
Future<String> read(Stream<List<int>> stream) =>
|
||||||
stream.transform(utf8.decoder).join();
|
stream.transform(utf8.decoder).join();
|
||||||
|
|
||||||
class MockAngel extends BaseProtevusClient {
|
class MockProtevus extends BaseProtevusClient {
|
||||||
final SpecClient specClient = SpecClient();
|
final SpecClient specClient = SpecClient();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
get client => specClient;
|
get client => specClient;
|
||||||
|
|
||||||
MockAngel() : super(SpecClient(), 'http://localhost:3000');
|
MockProtevus() : super(SpecClient(), 'http://localhost:3000');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Stream<String> authenticateViaPopup(String url,
|
Stream<String> authenticateViaPopup(String url,
|
||||||
|
|
|
@ -38,7 +38,7 @@ A better IoC container for Protevus, ultimately allowing Protevus to be used wit
|
||||||
app.container.registerSingleton<SalesController>(SalesController());
|
app.container.registerSingleton<SalesController>(SalesController());
|
||||||
await app.mountController<SalesController>();
|
await app.mountController<SalesController>();
|
||||||
|
|
||||||
var http = AngelHttp(app);
|
var http = ProtevusHttp(app);
|
||||||
var server = await http.startServer('localhost', 3000);
|
var server = await http.startServer('localhost', 3000);
|
||||||
print("Protevus server listening at ${http.uri}");
|
print("Protevus server listening at ${http.uri}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
## 6.0.0
|
## 6.0.0
|
||||||
|
|
||||||
* Require Dart >= 2.16
|
* Require Dart >= 2.16
|
||||||
* [**Breaking**] `error` for `AngelHttpException` is no longer mandatory
|
* [**Breaking**] `error` for `ProtevusHttpException` is no longer mandatory
|
||||||
|
|
||||||
## 5.0.0
|
## 5.0.0
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
|
|
||||||
## 8.2.0
|
## 8.2.0
|
||||||
|
|
||||||
* Add `addResponseHeader` to `AngelHttp` to add headers to HTTP default response
|
* Add `addResponseHeader` to `ProtevusHttp` to add headers to HTTP default response
|
||||||
* Add `removeResponseHeader` to `AngelHttp` to remove headers from HTTP default response
|
* Add `removeResponseHeader` to `ProtevusHttp` to remove headers from HTTP default response
|
||||||
|
|
||||||
## 8.1.1
|
## 8.1.1
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@
|
||||||
|
|
||||||
## 2.1.1
|
## 2.1.1
|
||||||
|
|
||||||
* `AngelHttp.uri` now returns an empty `Uri` if the server is not listening.
|
* `ProtevusHttp.uri` now returns an empty `Uri` if the server is not listening.
|
||||||
|
|
||||||
## 2.1.0
|
## 2.1.0
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ therefore been bumped to `2.1.0`.
|
||||||
## 2.0.5-beta
|
## 2.0.5-beta
|
||||||
|
|
||||||
* Make `@Expose()` in `Controller` optional. <https://github.com/protevus-dart/protevus/issues/107>
|
* Make `@Expose()` in `Controller` optional. <https://github.com/protevus-dart/protevus/issues/107>
|
||||||
* Add `allowHttp1` to `AngelHttp2` constructors. <https://github.com/protevus-dart/protevus/issues/108>
|
* Add `allowHttp1` to `ProtevusHttp2` constructors. <https://github.com/protevus-dart/protevus/issues/108>
|
||||||
* Add `deserializeBody` and `decodeBody` to `RequestContext`. <https://github.com/protevus-dart/protevus/issues/109>
|
* Add `deserializeBody` and `decodeBody` to `RequestContext`. <https://github.com/protevus-dart/protevus/issues/109>
|
||||||
* Add `HostnameRouter`, which allows for routing based on hostname. <https://github.com/protevus-dart/protevus/issues/110>
|
* Add `HostnameRouter`, which allows for routing based on hostname. <https://github.com/protevus-dart/protevus/issues/110>
|
||||||
* Default to using `ThrowingReflector`, instead of `EmptyReflector`. This will give a more descriptive
|
* Default to using `ThrowingReflector`, instead of `EmptyReflector`. This will give a more descriptive
|
||||||
|
@ -189,7 +189,7 @@ See more: <https://github.com/protevus-dart/protevus/issues/106#issuecomment-499
|
||||||
handlers to run, even after the response was closed.
|
handlers to run, even after the response was closed.
|
||||||
* Add `RequestContext.shutdownHooks`.
|
* Add `RequestContext.shutdownHooks`.
|
||||||
* Call `RequestContext.close` in `Driver.sendResponse`.
|
* Call `RequestContext.close` in `Driver.sendResponse`.
|
||||||
* AngelConfigurer is now `FutureOr<void>`, instead of just `FutureOr`.
|
* ProtevusConfigurer is now `FutureOr<void>`, instead of just `FutureOr`.
|
||||||
* Use a `Container.has<Stopwatch>` check in `Driver.sendResponse`.
|
* Use a `Container.has<Stopwatch>` check in `Driver.sendResponse`.
|
||||||
* Remove unnecessary `new` and `const`.
|
* Remove unnecessary `new` and `const`.
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ handlers to run, even after the response was closed.
|
||||||
|
|
||||||
## 2.0.0-rc.10
|
## 2.0.0-rc.10
|
||||||
|
|
||||||
* Fix an error that prevented `AngelHttp2.custom` from working properly.
|
* Fix an error that prevented `ProtevusHttp2.custom` from working properly.
|
||||||
* Add `startSharedHttp2`.
|
* Add `startSharedHttp2`.
|
||||||
|
|
||||||
## 2.0.0-rc.9
|
## 2.0.0-rc.9
|
||||||
|
@ -246,7 +246,7 @@ the outputs of `before` events.
|
||||||
## 2.0.0-rc.0
|
## 2.0.0-rc.0
|
||||||
|
|
||||||
* Log a warning when no `reflector` is provided.
|
* Log a warning when no `reflector` is provided.
|
||||||
* Add `AngelEnvironment` class.
|
* Add `ProtevusEnvironment` class.
|
||||||
* Add `Protevus.environment`.
|
* Add `Protevus.environment`.
|
||||||
* Deprecated `app.isProduction` in favor of `app.environment.isProduction`.
|
* Deprecated `app.isProduction` in favor of `app.environment.isProduction`.
|
||||||
* Allow setting of `bodyAsObject`, `bodyAsMap`, or `bodyAsList` **exactly once**.
|
* Allow setting of `bodyAsObject`, `bodyAsMap`, or `bodyAsList` **exactly once**.
|
||||||
|
|
|
@ -38,7 +38,7 @@ void main() async {
|
||||||
var http1 = ProtevusHttp(app);
|
var http1 = ProtevusHttp(app);
|
||||||
var http2 = ProtevusHttp2(app, ctx);
|
var http2 = ProtevusHttp2(app, ctx);
|
||||||
|
|
||||||
// HTTP/1.x requests will fallback to `AngelHttp`
|
// HTTP/1.x requests will fallback to `ProtevusHttp`
|
||||||
http2.onHttp1.listen(http1.handleRequest);
|
http2.onHttp1.listen(http1.handleRequest);
|
||||||
|
|
||||||
var server = await http2.startServer('127.0.0.1', 3000);
|
var server = await http2.startServer('127.0.0.1', 3000);
|
||||||
|
|
|
@ -35,7 +35,7 @@ void main() async {
|
||||||
var http1 = ProtevusHttp(app);
|
var http1 = ProtevusHttp(app);
|
||||||
var http2 = ProtevusHttp2(app, ctx);
|
var http2 = ProtevusHttp2(app, ctx);
|
||||||
|
|
||||||
// HTTP/1.x requests will fallback to `AngelHttp`
|
// HTTP/1.x requests will fallback to `ProtevusHttp`
|
||||||
http2.onHttp1.listen(http1.handleRequest);
|
http2.onHttp1.listen(http1.handleRequest);
|
||||||
|
|
||||||
await http2.startServer('127.0.0.1', 3000);
|
await http2.startServer('127.0.0.1', 3000);
|
||||||
|
|
|
@ -54,7 +54,7 @@ void main() async {
|
||||||
var http1 = ProtevusHttp(app);
|
var http1 = ProtevusHttp(app);
|
||||||
var http2 = ProtevusHttp2(app, ctx);
|
var http2 = ProtevusHttp2(app, ctx);
|
||||||
|
|
||||||
// HTTP/1.x requests will fallback to `AngelHttp`
|
// HTTP/1.x requests will fallback to `ProtevusHttp`
|
||||||
http2.onHttp1.listen(http1.handleRequest);
|
http2.onHttp1.listen(http1.handleRequest);
|
||||||
|
|
||||||
var server = await http2.startServer('127.0.0.1', 3000);
|
var server = await http2.startServer('127.0.0.1', 3000);
|
||||||
|
|
|
@ -10,7 +10,7 @@ import 'core.dart';
|
||||||
|
|
||||||
/// Base driver class for Protevus implementations.
|
/// Base driver class for Protevus implementations.
|
||||||
///
|
///
|
||||||
/// Powers both AngelHttp and AngelHttp2.
|
/// Powers both ProtevusHttp and ProtevusHttp2.
|
||||||
abstract class Driver<
|
abstract class Driver<
|
||||||
Request,
|
Request,
|
||||||
Response,
|
Response,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
/// A constant instance of [AngelEnv].
|
/// A constant instance of [ProtevusEnv].
|
||||||
const ProtevusEnvironment angelEnv = ProtevusEnvironment();
|
const ProtevusEnvironment angelEnv = ProtevusEnvironment();
|
||||||
|
|
||||||
/// Queries the environment's `ANGEL_ENV` value.
|
/// Queries the environment's `ANGEL_ENV` value.
|
||||||
|
|
|
@ -96,7 +96,7 @@ class MapService extends Service<String?, Map<String, dynamic>> {
|
||||||
Future<Map<String, dynamic>> modify(String? id, Map<String, dynamic> data,
|
Future<Map<String, dynamic>> modify(String? id, Map<String, dynamic> data,
|
||||||
[Map<String, dynamic>? params]) {
|
[Map<String, dynamic>? params]) {
|
||||||
//if (data is! Map) {
|
//if (data is! Map) {
|
||||||
// throw AngelHttpException.badRequest(
|
// throw ProtevusHttpException.badRequest(
|
||||||
// message:
|
// message:
|
||||||
// 'MapService does not support `modify` with ${data.runtimeType}.');
|
// 'MapService does not support `modify` with ${data.runtimeType}.');
|
||||||
//}
|
//}
|
||||||
|
@ -119,7 +119,7 @@ class MapService extends Service<String?, Map<String, dynamic>> {
|
||||||
Future<Map<String, dynamic>> update(String? id, Map<String, dynamic> data,
|
Future<Map<String, dynamic>> update(String? id, Map<String, dynamic> data,
|
||||||
[Map<String, dynamic>? params]) {
|
[Map<String, dynamic>? params]) {
|
||||||
//if (data is! Map) {
|
//if (data is! Map) {
|
||||||
// throw AngelHttpException.badRequest(
|
// throw ProtevusHttpException.badRequest(
|
||||||
// message:
|
// message:
|
||||||
// 'MapService does not support `update` with ${data.runtimeType}.');
|
// 'MapService does not support `update` with ${data.runtimeType}.');
|
||||||
//}
|
//}
|
||||||
|
|
|
@ -111,7 +111,7 @@ class Service<Id, Data> extends Routable {
|
||||||
|
|
||||||
/// Retrieves the first object from the result of calling [index] with the given [params].
|
/// Retrieves the first object from the result of calling [index] with the given [params].
|
||||||
///
|
///
|
||||||
/// If the result of [index] is `null`, OR an empty [Iterable], a 404 `AngelHttpException` will be thrown.
|
/// If the result of [index] is `null`, OR an empty [Iterable], a 404 `ProtevusHttpException` will be thrown.
|
||||||
///
|
///
|
||||||
/// If the result is both non-null and NOT an [Iterable], it will be returned as-is.
|
/// If the result is both non-null and NOT an [Iterable], it will be returned as-is.
|
||||||
///
|
///
|
||||||
|
|
|
@ -206,7 +206,7 @@ class _ProtevusHttp2ServerSocket extends Stream<SecureSocket>
|
||||||
} else {
|
} else {
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
throw Exception(
|
throw Exception(
|
||||||
'AngelHttp2 does not support ${socket.selectedProtocol} as an ALPN protocol.');
|
'ProtevusHttp2 does not support ${socket.selectedProtocol} as an ALPN protocol.');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onDone: _ctrl.close,
|
onDone: _ctrl.close,
|
||||||
|
|
|
@ -3,19 +3,19 @@ import 'package:test/test.dart';
|
||||||
import 'common.dart';
|
import 'common.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
var throwsAnAngelHttpException =
|
var throwsAnProtevusHttpException =
|
||||||
throwsA(const IsInstanceOf<ProtevusHttpException>());
|
throwsA(const IsInstanceOf<ProtevusHttpException>());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
test('throw 404 on null', () {
|
test('throw 404 on null', () {
|
||||||
var service = AnonymousService(index: ([p]) => null);
|
var service = AnonymousService(index: ([p]) => null);
|
||||||
expect(() => service.findOne(), throwsAnAngelHttpException);
|
expect(() => service.findOne(), throwsAnProtevusHttpException);
|
||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
|
|
||||||
test('throw 404 on empty iterable', () {
|
test('throw 404 on empty iterable', () {
|
||||||
var service = AnonymousService(index: ([p]) => []);
|
var service = AnonymousService(index: ([p]) => []);
|
||||||
expect(() => service.findOne(), throwsAnAngelHttpException);
|
expect(() => service.findOne(), throwsAnProtevusHttpException);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('return first element of iterable', () async {
|
test('return first element of iterable', () async {
|
||||||
|
|
|
@ -154,7 +154,7 @@ void main() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group('handleAngelHttpException', () {
|
group('handleProtevusHttpException', () {
|
||||||
late Protevus app;
|
late Protevus app;
|
||||||
late ProtevusHttp http;
|
late ProtevusHttp http;
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ void main() {
|
||||||
return res.serialize(req.ip == InternetAddress.loopbackIPv4.address);
|
return res.serialize(req.ip == InternetAddress.loopbackIPv4.address);
|
||||||
});
|
});
|
||||||
|
|
||||||
var http = AngelHttp(app);
|
var http = ProtevusHttp(app);
|
||||||
|
|
||||||
test('receive a response', () async {
|
test('receive a response', () async {
|
||||||
var rq = MockHttpRequest('GET', uri.resolve('/foo'));
|
var rq = MockHttpRequest('GET', uri.resolve('/foo'));
|
||||||
|
|
|
@ -58,7 +58,7 @@ Future<Protevus> createServer() async {
|
||||||
app.get('/', (req, res) => {'hello': 'hot world!'});
|
app.get('/', (req, res) => {'hello': 'hot world!'});
|
||||||
app.get('/foo', (req, res) => Foo(bar: 'baz'));
|
app.get('/foo', (req, res) => Foo(bar: 'baz'));
|
||||||
|
|
||||||
app.fallback((req, res) => throw AngelHttpException.notFound());
|
app.fallback((req, res) => throw ProtevusHttpException.notFound());
|
||||||
|
|
||||||
app.encoders.addAll({
|
app.encoders.addAll({
|
||||||
'gzip': gzip.encoder,
|
'gzip': gzip.encoder,
|
||||||
|
|
|
@ -25,7 +25,7 @@ import 'package:protevus_framework/protevus_framework.dart';
|
||||||
import 'package:protevus_jael/protevus_jael.dart';
|
import 'package:protevus_jael/protevus_jael.dart';
|
||||||
import 'package:file/file.dart';
|
import 'package:file/file.dart';
|
||||||
|
|
||||||
AngelConfigurer myPlugin(FileSystem fileSystem) {
|
ProtevusConfigurer myPlugin(FileSystem fileSystem) {
|
||||||
return (Protevus app) async {
|
return (Protevus app) async {
|
||||||
// Connect Jael to your server...
|
// Connect Jael to your server...
|
||||||
await app.configure(
|
await app.configure(
|
||||||
|
@ -62,7 +62,7 @@ void main() async {
|
||||||
// Render the contents of views/index.jael
|
// Render the contents of views/index.jael
|
||||||
app.get('/', (res) => res.render('index', {'title': 'ESKETTIT'}));
|
app.get('/', (res) => res.render('index', {'title': 'ESKETTIT'}));
|
||||||
|
|
||||||
app.use(() => throw AngelHttpException.notFound());
|
app.use(() => throw ProtevusHttpException.notFound());
|
||||||
|
|
||||||
app.logger = Logger('protevus')
|
app.logger = Logger('protevus')
|
||||||
..onRecord.listen((rec) {
|
..onRecord.listen((rec) {
|
||||||
|
|
|
@ -18,7 +18,7 @@ import 'package:path/path.dart' as p;
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
var app = Protevus();
|
var app = Protevus();
|
||||||
var http = AngelHttp(app);
|
var http = ProtevusHttp(app);
|
||||||
var viewsDir = p.join(
|
var viewsDir = p.join(
|
||||||
p.dirname(
|
p.dirname(
|
||||||
p.fromUri(Platform.script),
|
p.fromUri(Platform.script),
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
## 6.0.1
|
## 6.0.1
|
||||||
|
|
||||||
* Fixed AngelHttpException error
|
* Fixed ProtevusHttpException error
|
||||||
* [Breaking] Renamed `error` to `authError` for `AuthorizationException`
|
* [Breaking] Renamed `error` to `authError` for `AuthorizationException`
|
||||||
|
|
||||||
## 6.0.0
|
## 6.0.0
|
||||||
|
|
|
@ -80,7 +80,7 @@ simply just not extend `Model`:
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
@Serializable
|
@Serializable
|
||||||
abstract class _ThisIsNotAnAngelModel {
|
abstract class _ThisIsNotAnProtevusModel {
|
||||||
@primaryKey
|
@primaryKey
|
||||||
String get username;
|
String get username;
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ import 'car.dart';
|
||||||
import 'car.orm.g.dart';
|
import 'car.orm.g.dart';
|
||||||
|
|
||||||
/// Returns an Protevus plug-in that connects to a database, and sets up a controller connected to it...
|
/// Returns an Protevus plug-in that connects to a database, and sets up a controller connected to it...
|
||||||
AngelConfigurer connectToCarsTable(QueryExecutor executor) {
|
ProtevusConfigurer connectToCarsTable(QueryExecutor executor) {
|
||||||
return (Protevus app) async {
|
return (Protevus app) async {
|
||||||
// Register the connection with Protevus's dependency injection system.
|
// Register the connection with Protevus's dependency injection system.
|
||||||
//
|
//
|
||||||
|
|
|
@ -45,5 +45,5 @@
|
||||||
|
|
||||||
## 2.0.0
|
## 2.0.0
|
||||||
|
|
||||||
* Dart2 + Angel2 update.
|
* Dart2 + Protevus2 update.
|
||||||
|
|
|
@ -283,7 +283,7 @@ class Runner {
|
||||||
|
|
||||||
await driver.startServer(args.options.hostname, args.options.port);
|
await driver.startServer(args.options.hostname, args.options.port);
|
||||||
|
|
||||||
// Only apply the headers to AngelHttp instance
|
// Only apply the headers to ProtevusHttp instance
|
||||||
if (driver is ProtevusHttp) {
|
if (driver is ProtevusHttp) {
|
||||||
driver.addResponseHeader(args.options.responseHeaders);
|
driver.addResponseHeader(args.options.responseHeaders);
|
||||||
driver.removeResponseHeader(args.options.removeResponseHeaders);
|
driver.removeResponseHeader(args.options.removeResponseHeaders);
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
## 6.0.1
|
## 6.0.1
|
||||||
|
|
||||||
* Fixed AngelHttpException error
|
* Fixed ProtevusHttpException error
|
||||||
|
|
||||||
## 6.0.0
|
## 6.0.0
|
||||||
|
|
||||||
|
|
|
@ -32,11 +32,11 @@ import 'package:file/local.dart';
|
||||||
void main() async {
|
void main() async {
|
||||||
var app = Protevus()..lazyParseBodies = true;
|
var app = Protevus()..lazyParseBodies = true;
|
||||||
var fs = const LocalFileSystem();
|
var fs = const LocalFileSystem();
|
||||||
var http = AngelHttp(app);
|
var http = ProtevusHttp(app);
|
||||||
|
|
||||||
app.responseFinalizers.add(inlineAssets(fs.directory('web')));
|
app.responseFinalizers.add(inlineAssets(fs.directory('web')));
|
||||||
|
|
||||||
app.use(() => throw AngelHttpException.notFound());
|
app.use(() => throw ProtevusHttpException.notFound());
|
||||||
|
|
||||||
var server = await http.startServer('127.0.0.1', 3000);
|
var server = await http.startServer('127.0.0.1', 3000);
|
||||||
print('Listening at http://${server.address.address}:${server.port}');
|
print('Listening at http://${server.address.address}:${server.port}');
|
||||||
|
@ -56,7 +56,7 @@ import 'package:file/local.dart';
|
||||||
void main() async {
|
void main() async {
|
||||||
var app = Protevus()..lazyParseBodies = true;
|
var app = Protevus()..lazyParseBodies = true;
|
||||||
var fs = const LocalFileSystem();
|
var fs = const LocalFileSystem();
|
||||||
var http = AngelHttp(app);
|
var http = ProtevusHttp(app);
|
||||||
|
|
||||||
var vDir = inlineAssets(
|
var vDir = inlineAssets(
|
||||||
VirtualDirectory(
|
VirtualDirectory(
|
||||||
|
@ -68,7 +68,7 @@ void main() async {
|
||||||
|
|
||||||
app.use(vDir.handleRequest);
|
app.use(vDir.handleRequest);
|
||||||
|
|
||||||
app.use(() => throw AngelHttpException.notFound());
|
app.use(() => throw ProtevusHttpException.notFound());
|
||||||
|
|
||||||
var server = await http.startServer('127.0.0.1', 3000);
|
var server = await http.startServer('127.0.0.1', 3000);
|
||||||
print('Listening at http://${server.address.address}:${server.port}');
|
print('Listening at http://${server.address.address}:${server.port}');
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
## 6.0.0-beta.2
|
## 6.0.0-beta.2
|
||||||
|
|
||||||
* Fixed AngelHttpException error
|
* Fixed ProtevusHttpException error
|
||||||
|
|
||||||
## 6.0.0-beta.1
|
## 6.0.0-beta.1
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@
|
||||||
## 2.1.0
|
## 2.1.0
|
||||||
|
|
||||||
* `pedantic` lints.
|
* `pedantic` lints.
|
||||||
* Add the `AngelShelf` driver class, which allows you to embed Protevus within shelf.
|
* Add the `ProtevusShelf` driver class, which allows you to embed Protevus within shelf.
|
||||||
|
|
||||||
## 2.0.0
|
## 2.0.0
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ Shelf interop with Protevus. This package lets you run `package:shelf` handlers
|
||||||
- [Usage](#usage)
|
- [Usage](#usage)
|
||||||
- [embedShelf](#embedshelf)
|
- [embedShelf](#embedshelf)
|
||||||
- [Communicating with Protevus with embedShelf](#communicating-with-protevus-with-embedshelf)
|
- [Communicating with Protevus with embedShelf](#communicating-with-protevus-with-embedshelf)
|
||||||
- [AngelShelf](#angelshelf)
|
- [ProtevusShelf](#angelshelf)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ import 'api/api.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
var app = Protevus();
|
var app = Protevus();
|
||||||
var http = AngelHttp(app);
|
var http = ProtevusHttp(app);
|
||||||
|
|
||||||
// Protevus routes on top
|
// Protevus routes on top
|
||||||
await app.mountController<ApiController>();
|
await app.mountController<ApiController>();
|
||||||
|
@ -70,24 +70,24 @@ handleRequest(shelf.Request request) {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### AngelShelf
|
### ProtevusShelf
|
||||||
|
|
||||||
Protevus brought about the generic `Driver` class, which is implemented by `AngelHttp`, `AngelHttp2`, `AngelGopher`, etc., and provides the core infrastructure for request handling in Protevus. `AngelShelf` is an implementation that wraps shelf requests and responses in their Protevus equivalents. Using it is as simple using as using `AngelHttp`, or any other driver:
|
Protevus brought about the generic `Driver` class, which is implemented by `ProtevusHttp`, `ProtevusHttp2`, `ProtevusGopher`, etc., and provides the core infrastructure for request handling in Protevus. `ProtevusShelf` is an implementation that wraps shelf requests and responses in their Protevus equivalents. Using it is as simple using as using `ProtevusHttp`, or any other driver:
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
// Create an AngelShelf driver.
|
// Create an ProtevusShelf driver.
|
||||||
// If we have startup hooks we want to run, we need to call
|
// If we have startup hooks we want to run, we need to call
|
||||||
// `startServer`. Otherwise, it can be omitted.
|
// `startServer`. Otherwise, it can be omitted.
|
||||||
// Of course, if you call `startServer`, know that to run
|
// Of course, if you call `startServer`, know that to run
|
||||||
// shutdown/cleanup logic, you need to call `close` eventually,
|
// shutdown/cleanup logic, you need to call `close` eventually,
|
||||||
// too.
|
// too.
|
||||||
var angelShelf = AngelShelf(app);
|
var angelShelf = ProtevusShelf(app);
|
||||||
await angelShelf.startServer();
|
await angelShelf.startServer();
|
||||||
|
|
||||||
await shelf_io.serve(angelShelf.handler, InternetAddress.loopbackIPv4, 8081);
|
await shelf_io.serve(angelShelf.handler, InternetAddress.loopbackIPv4, 8081);
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also use the `AngelShelf` driver as a shelf middleware - just use
|
You can also use the `ProtevusShelf` driver as a shelf middleware - just use
|
||||||
`angelShelf.middleware` instead of `angelShelf.handler`. When used as a middleware,
|
`angelShelf.middleware` instead of `angelShelf.handler`. When used as a middleware,
|
||||||
if the Protevus response context is still open after all handlers run (i.e. no routes were
|
if the Protevus response context is still open after all handlers run (i.e. no routes were
|
||||||
matched), the next shelf handler will be called.
|
matched), the next shelf handler will be called.
|
||||||
|
|
|
@ -40,7 +40,7 @@ void main() async {
|
||||||
app.fallback(vDir.handleRequest);
|
app.fallback(vDir.handleRequest);
|
||||||
|
|
||||||
// Start your server!!!
|
// Start your server!!!
|
||||||
await AngelHttp(app).startServer();
|
await ProtevusHttp(app).startServer();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,10 @@ Easily synchronize and scale WebSockets using [belatuk_pub_sub](<https://pub.dev
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
This package exposes `PubSubSynchronizationChannel`, which can simply be dropped into any `AngelWebSocket` constructor. Once you've set that up, instances of your application will automatically fire events in-sync. That's all you have to do to scale a real-time application with Protevus!
|
This package exposes `PubSubSynchronizationChannel`, which can simply be dropped into any `ProtevusWebSocket` constructor. Once you've set that up, instances of your application will automatically fire events in-sync. That's all you have to do to scale a real-time application with Protevus!
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
await app.configure(AngelWebSocket(
|
await app.configure(ProtevusWebSocket(
|
||||||
synchronizationChannel: PubSubSynchronizationChannel(
|
synchronizationChannel: PubSubSynchronizationChannel(
|
||||||
pub_sub.IsolateClient('<client-id>', adapter.receivePort.sendPort),
|
pub_sub.IsolateClient('<client-id>', adapter.receivePort.sendPort),
|
||||||
),
|
),
|
||||||
|
|
|
@ -102,4 +102,4 @@
|
||||||
## 1.1.0+1
|
## 1.1.0+1
|
||||||
|
|
||||||
* Dart 2/strong mode fixes.
|
* Dart 2/strong mode fixes.
|
||||||
* Pass a `useZone` flag to `AngelHttp` through `TestServer`.
|
* Pass a `useZone` flag to `ProtevusHttp` through `TestServer`.
|
||||||
|
|
|
@ -41,8 +41,8 @@ void test('foo', () async {
|
||||||
|
|
||||||
void test('error', () async {
|
void test('error', () async {
|
||||||
var res = await client.get('/error');
|
var res = await client.get('/error');
|
||||||
expect(res, isAngelHttpException());
|
expect(res, isProtevusHttpException());
|
||||||
expect(res, isAngelHttpException(statusCode: 404, message: ..., errors: [...])) // Optional
|
expect(res, isProtevusHttpException(statusCode: 404, message: ..., errors: [...])) // Optional
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -93,5 +93,5 @@
|
||||||
## 1.0.4
|
## 1.0.4
|
||||||
|
|
||||||
* `isNonEmptyString` trims strings.
|
* `isNonEmptyString` trims strings.
|
||||||
* `ValidationException` extends `AngelHttpException`.
|
* `ValidationException` extends `ProtevusHttpException`.
|
||||||
* Added `requireField` and `requireFields`.
|
* Added `requireField` and `requireFields`.
|
||||||
|
|
|
@ -260,7 +260,7 @@ main() {
|
||||||
|
|
||||||
`server.dart` exposes seven helper middleware:
|
`server.dart` exposes seven helper middleware:
|
||||||
|
|
||||||
- `validate(validator)`: Validates and filters `req.bodyAsMap`, and throws an `AngelHttpException.BadRequest` if data is invalid.
|
- `validate(validator)`: Validates and filters `req.bodyAsMap`, and throws an `ProtevusHttpException.BadRequest` if data is invalid.
|
||||||
- `validateEvent(validator)`: Sets `e.data` to the result of validation on a service event.
|
- `validateEvent(validator)`: Sets `e.data` to the result of validation on a service event.
|
||||||
- `validateQuery(validator)`: Same as `validate`, but operates on `req.query`.
|
- `validateQuery(validator)`: Same as `validate`, but operates on `req.query`.
|
||||||
- `autoParseBody(fields)`: Auto-parses numbers in `req.bodyAsMap`.
|
- `autoParseBody(fields)`: Auto-parses numbers in `req.bodyAsMap`.
|
||||||
|
|
|
@ -114,7 +114,7 @@ HookedServiceEventListener validateEvent(Validator validator,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Asynchronously apply a [validator], running any [AngelMatcher]s.
|
/// Asynchronously apply a [validator], running any [ProtevusMatcher]s.
|
||||||
Future<ValidationResult> asyncApplyValidator(
|
Future<ValidationResult> asyncApplyValidator(
|
||||||
Validator validator, Map data, Protevus app) async {
|
Validator validator, Map data, Protevus app) async {
|
||||||
var result = validator.check(data);
|
var result = validator.check(data);
|
||||||
|
@ -127,8 +127,9 @@ Future<ValidationResult> asyncApplyValidator(
|
||||||
var description = StringDescription("'$key': expected ");
|
var description = StringDescription("'$key': expected ");
|
||||||
|
|
||||||
for (var rule in validator.rules[key]!) {
|
for (var rule in validator.rules[key]!) {
|
||||||
if (rule is AngelMatcher) {
|
if (rule is ProtevusMatcher) {
|
||||||
var r = await rule.matchesWithAngel(value, key, result.data, {}, app);
|
var r =
|
||||||
|
await rule.matchesWithProtevus(value, key, result.data, {}, app);
|
||||||
|
|
||||||
if (!r) {
|
if (!r) {
|
||||||
errors.add(rule.describe(description).toString().trim());
|
errors.add(rule.describe(description).toString().trim());
|
||||||
|
|
|
@ -3,60 +3,61 @@ import 'package:protevus_framework/protevus_framework.dart';
|
||||||
import 'package:matcher/matcher.dart';
|
import 'package:matcher/matcher.dart';
|
||||||
import 'context_aware.dart';
|
import 'context_aware.dart';
|
||||||
|
|
||||||
/// Returns an [AngelMatcher] that uses an arbitrary function that returns
|
/// Returns an [ProtevusMatcher] that uses an arbitrary function that returns
|
||||||
/// true or false for the actual value.
|
/// true or false for the actual value.
|
||||||
///
|
///
|
||||||
/// Analogous to the synchronous [predicate] matcher.
|
/// Analogous to the synchronous [predicate] matcher.
|
||||||
AngelMatcher predicateWithAngel(
|
ProtevusMatcher predicateWithProtevus(
|
||||||
FutureOr<bool> Function(String, Object, Protevus) f,
|
FutureOr<bool> Function(String, Object, Protevus) f,
|
||||||
[String description = 'satisfies function']) =>
|
[String description = 'satisfies function']) =>
|
||||||
_PredicateWithAngel(f, description);
|
_PredicateWithProtevus(f, description);
|
||||||
|
|
||||||
/// Returns an [AngelMatcher] that applies an asynchronously-created [Matcher]
|
/// Returns an [ProtevusMatcher] that applies an asynchronously-created [Matcher]
|
||||||
/// to the input.
|
/// to the input.
|
||||||
///
|
///
|
||||||
/// Use this to match values against configuration, injections, etc.
|
/// Use this to match values against configuration, injections, etc.
|
||||||
AngelMatcher matchWithAngel(FutureOr<Matcher> Function(Object, Map, Protevus) f,
|
ProtevusMatcher matchWithProtevus(
|
||||||
|
FutureOr<Matcher> Function(Object, Map, Protevus) f,
|
||||||
[String description = 'satisfies asynchronously created matcher']) =>
|
[String description = 'satisfies asynchronously created matcher']) =>
|
||||||
_MatchWithAngel(f, description);
|
_MatchWithProtevus(f, description);
|
||||||
|
|
||||||
/// Calls [matchWithAngel] without the initial parameter.
|
/// Calls [matchWithProtevus] without the initial parameter.
|
||||||
AngelMatcher matchWithAngelBinary(
|
ProtevusMatcher matchWithProtevusBinary(
|
||||||
FutureOr<Matcher> Function(Map context, Protevus) f,
|
FutureOr<Matcher> Function(Map context, Protevus) f,
|
||||||
[String description = 'satisfies asynchronously created matcher']) =>
|
[String description = 'satisfies asynchronously created matcher']) =>
|
||||||
matchWithAngel((_, context, app) => f(context, app));
|
matchWithProtevus((_, context, app) => f(context, app));
|
||||||
|
|
||||||
/// Calls [matchWithAngel] without the initial two parameters.
|
/// Calls [matchWithProtevus] without the initial two parameters.
|
||||||
AngelMatcher matchWithAngelUnary(FutureOr<Matcher> Function(Protevus) f,
|
ProtevusMatcher matchWithProtevusUnary(FutureOr<Matcher> Function(Protevus) f,
|
||||||
[String description = 'satisfies asynchronously created matcher']) =>
|
[String description = 'satisfies asynchronously created matcher']) =>
|
||||||
matchWithAngelBinary((_, app) => f(app));
|
matchWithProtevusBinary((_, app) => f(app));
|
||||||
|
|
||||||
/// Calls [matchWithAngel] without any parameters.
|
/// Calls [matchWithProtevus] without any parameters.
|
||||||
AngelMatcher matchWithAngelNullary(FutureOr<Matcher> Function() f,
|
ProtevusMatcher matchWithProtevusNullary(FutureOr<Matcher> Function() f,
|
||||||
[String description = 'satisfies asynchronously created matcher']) =>
|
[String description = 'satisfies asynchronously created matcher']) =>
|
||||||
matchWithAngelUnary((_) => f());
|
matchWithProtevusUnary((_) => f());
|
||||||
|
|
||||||
/// Returns an [AngelMatcher] that represents [x].
|
/// Returns an [ProtevusMatcher] that represents [x].
|
||||||
///
|
///
|
||||||
/// If [x] is an [AngelMatcher], then it is returned, unmodified.
|
/// If [x] is an [ProtevusMatcher], then it is returned, unmodified.
|
||||||
AngelMatcher wrapAngelMatcher(x) {
|
ProtevusMatcher wrapProtevusMatcher(x) {
|
||||||
if (x is AngelMatcher) return x;
|
if (x is ProtevusMatcher) return x;
|
||||||
if (x is ContextAwareMatcher) return _WrappedAngelMatcher(x);
|
if (x is ContextAwareMatcher) return _WrappedProtevusMatcher(x);
|
||||||
return wrapAngelMatcher(wrapContextAwareMatcher(x));
|
return wrapProtevusMatcher(wrapContextAwareMatcher(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an [AngelMatcher] that asynchronously resolves a [feature], builds a [matcher], and executes it.
|
/// Returns an [ProtevusMatcher] that asynchronously resolves a [feature], builds a [matcher], and executes it.
|
||||||
AngelMatcher matchAsync(FutureOr<Matcher> Function(String, Object) matcher,
|
ProtevusMatcher matchAsync(FutureOr<Matcher> Function(String, Object) matcher,
|
||||||
FutureOr Function() feature,
|
FutureOr Function() feature,
|
||||||
[String description = 'satisfies asynchronously created matcher']) {
|
[String description = 'satisfies asynchronously created matcher']) {
|
||||||
return _MatchAsync(matcher, feature, description);
|
return _MatchAsync(matcher, feature, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an [AngelMatcher] that verifies that an item with the given [idField]
|
/// Returns an [ProtevusMatcher] that verifies that an item with the given [idField]
|
||||||
/// exists in the service at [servicePath], without throwing a `404` or returning `null`.
|
/// exists in the service at [servicePath], without throwing a `404` or returning `null`.
|
||||||
AngelMatcher idExistsInService(String servicePath,
|
ProtevusMatcher idExistsInService(String servicePath,
|
||||||
{String idField = 'id', String? description}) {
|
{String idField = 'id', String? description}) {
|
||||||
return predicateWithAngel(
|
return predicateWithProtevus(
|
||||||
(key, item, app) async {
|
(key, item, app) async {
|
||||||
try {
|
try {
|
||||||
var result = await app.findService(servicePath)?.read(item);
|
var result = await app.findService(servicePath)?.read(item);
|
||||||
|
@ -74,8 +75,8 @@ AngelMatcher idExistsInService(String servicePath,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An asynchronous [Matcher] that runs in the context of an [Protevus] app.
|
/// An asynchronous [Matcher] that runs in the context of an [Protevus] app.
|
||||||
abstract class AngelMatcher extends ContextAwareMatcher {
|
abstract class ProtevusMatcher extends ContextAwareMatcher {
|
||||||
Future<bool> matchesWithAngel(
|
Future<bool> matchesWithProtevus(
|
||||||
item, String key, Map context, Map matchState, Protevus app);
|
item, String key, Map context, Map matchState, Protevus app);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -84,34 +85,34 @@ abstract class AngelMatcher extends ContextAwareMatcher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _WrappedAngelMatcher extends AngelMatcher {
|
class _WrappedProtevusMatcher extends ProtevusMatcher {
|
||||||
final ContextAwareMatcher matcher;
|
final ContextAwareMatcher matcher;
|
||||||
|
|
||||||
_WrappedAngelMatcher(this.matcher);
|
_WrappedProtevusMatcher(this.matcher);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Description describe(Description description) =>
|
Description describe(Description description) =>
|
||||||
matcher.describe(description);
|
matcher.describe(description);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> matchesWithAngel(
|
Future<bool> matchesWithProtevus(
|
||||||
item, String key, Map context, Map matchState, Protevus app) async {
|
item, String key, Map context, Map matchState, Protevus app) async {
|
||||||
return matcher.matchesWithContext(item, key, context, matchState);
|
return matcher.matchesWithContext(item, key, context, matchState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MatchWithAngel extends AngelMatcher {
|
class _MatchWithProtevus extends ProtevusMatcher {
|
||||||
final FutureOr<Matcher> Function(Object, Map, Protevus) f;
|
final FutureOr<Matcher> Function(Object, Map, Protevus) f;
|
||||||
final String description;
|
final String description;
|
||||||
|
|
||||||
_MatchWithAngel(this.f, this.description);
|
_MatchWithProtevus(this.f, this.description);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Description describe(Description description) =>
|
Description describe(Description description) =>
|
||||||
description.add(this.description);
|
description.add(this.description);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> matchesWithAngel(
|
Future<bool> matchesWithProtevus(
|
||||||
item, String key, Map context, Map matchState, Protevus app) {
|
item, String key, Map context, Map matchState, Protevus app) {
|
||||||
return Future.sync(() => f(item as Object, context, app)).then((result) {
|
return Future.sync(() => f(item as Object, context, app)).then((result) {
|
||||||
return result.matches(item, matchState);
|
return result.matches(item, matchState);
|
||||||
|
@ -119,24 +120,24 @@ class _MatchWithAngel extends AngelMatcher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _PredicateWithAngel extends AngelMatcher {
|
class _PredicateWithProtevus extends ProtevusMatcher {
|
||||||
final FutureOr<bool> Function(String, Object, Protevus) predicate;
|
final FutureOr<bool> Function(String, Object, Protevus) predicate;
|
||||||
final String description;
|
final String description;
|
||||||
|
|
||||||
_PredicateWithAngel(this.predicate, this.description);
|
_PredicateWithProtevus(this.predicate, this.description);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Description describe(Description description) =>
|
Description describe(Description description) =>
|
||||||
description.add(this.description);
|
description.add(this.description);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> matchesWithAngel(
|
Future<bool> matchesWithProtevus(
|
||||||
item, String key, Map context, Map matchState, Protevus app) {
|
item, String key, Map context, Map matchState, Protevus app) {
|
||||||
return Future<bool>.sync(() => predicate(key, item as Object, app));
|
return Future<bool>.sync(() => predicate(key, item as Object, app));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MatchAsync extends AngelMatcher {
|
class _MatchAsync extends ProtevusMatcher {
|
||||||
final FutureOr<Matcher> Function(String, Object) matcher;
|
final FutureOr<Matcher> Function(String, Object) matcher;
|
||||||
final FutureOr Function() feature;
|
final FutureOr Function() feature;
|
||||||
final String description;
|
final String description;
|
||||||
|
@ -148,11 +149,11 @@ class _MatchAsync extends AngelMatcher {
|
||||||
description.add(this.description);
|
description.add(this.description);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> matchesWithAngel(
|
Future<bool> matchesWithProtevus(
|
||||||
item, String key, Map context, Map matchState, Protevus app) async {
|
item, String key, Map context, Map matchState, Protevus app) async {
|
||||||
var f = await feature();
|
var f = await feature();
|
||||||
var m = await matcher(key, f as Object);
|
var m = await matcher(key, f as Object);
|
||||||
var c = wrapAngelMatcher(m);
|
var c = wrapProtevusMatcher(m);
|
||||||
return await c.matchesWithAngel(item, key, context, matchState, app);
|
return await c.matchesWithProtevus(item, key, context, matchState, app);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
## 4.1.1
|
## 4.1.1
|
||||||
|
|
||||||
* Fixed issue with type casting
|
* Fixed issue with type casting
|
||||||
* Changed `app` parameter of `AngelWebSocket` to non-nullable
|
* Changed `app` parameter of `ProtevusWebSocket` to non-nullable
|
||||||
|
|
||||||
## 4.1.0
|
## 4.1.0
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@
|
||||||
|
|
||||||
* Dart 2 updates.
|
* Dart 2 updates.
|
||||||
* Added `handleClient`, which is nice for external implementations
|
* Added `handleClient`, which is nice for external implementations
|
||||||
that plug into `AngelWebSocket`.
|
that plug into `ProtevusWebSocket`.
|
||||||
|
|
||||||
## 1.1.1
|
## 1.1.1
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
||||||
[![License](https://img.shields.io/github/license/dart-backend/protevus)](https://github.com/dart-backend/protevus/tree/master/packages/websocket/LICENSE)
|
[![License](https://img.shields.io/github/license/dart-backend/protevus)](https://github.com/dart-backend/protevus/tree/master/packages/websocket/LICENSE)
|
||||||
|
|
||||||
WebSocket plugin for Protevus framework. This plugin broadcasts events from hooked services via WebSockets. In addition, it adds itself to the app's IoC container as `AngelWebSocket`, so that it can be used in controllers as well.
|
WebSocket plugin for Protevus framework. This plugin broadcasts events from hooked services via WebSockets. In addition, it adds itself to the app's IoC container as `ProtevusWebSocket`, so that it can be used in controllers as well.
|
||||||
|
|
||||||
WebSocket contexts are add to `req.properties` as `'socket'`.
|
WebSocket contexts are add to `req.properties` as `'socket'`.
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import "package:protevus_websocket/server.dart";
|
||||||
void main() async {
|
void main() async {
|
||||||
var app = Protevus();
|
var app = Protevus();
|
||||||
|
|
||||||
var ws = AngelWebSocket();
|
var ws = ProtevusWebSocket();
|
||||||
|
|
||||||
// This is a plug-in. It hooks all your services,
|
// This is a plug-in. It hooks all your services,
|
||||||
// to automatically broadcast events.
|
// to automatically broadcast events.
|
||||||
|
@ -56,7 +56,7 @@ import "package:protevus_websocket/server.dart";
|
||||||
@Expose("/")
|
@Expose("/")
|
||||||
class MyController extends WebSocketController {
|
class MyController extends WebSocketController {
|
||||||
// A reference to the WebSocket plug-in is required.
|
// A reference to the WebSocket plug-in is required.
|
||||||
MyController(AngelWebSocket ws):super(ws);
|
MyController(ProtevusWebSocket ws):super(ws);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onConnect(WebSocketContext socket) {
|
void onConnect(WebSocketContext socket) {
|
||||||
|
|
|
@ -274,7 +274,7 @@ class ProtevusWebSocket {
|
||||||
action.params['query'] is Map &&
|
action.params['query'] is Map &&
|
||||||
action.params['query']['jwt'] is String) {
|
action.params['query']['jwt'] is String) {
|
||||||
try {
|
try {
|
||||||
var auth = socket.request.container!.make<AngelAuth>();
|
var auth = socket.request.container!.make<ProtevusAuth>();
|
||||||
var jwt = action.params['query']['jwt'] as String;
|
var jwt = action.params['query']['jwt'] as String;
|
||||||
AuthToken token;
|
AuthToken token;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ void main() {
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
app = Protevus();
|
app = Protevus();
|
||||||
http = ProtevusHttp(app, useZone: false);
|
http = ProtevusHttp(app, useZone: false);
|
||||||
var auth = AngelAuth(
|
var auth = ProtevusAuth(
|
||||||
serializer: (_) async => 'baz', deserializer: (_) async => user);
|
serializer: (_) async => 'baz', deserializer: (_) async => user);
|
||||||
|
|
||||||
auth.strategies['local'] = LocalAuthStrategy(
|
auth.strategies['local'] = LocalAuthStrategy(
|
||||||
|
|
Loading…
Reference in a new issue