Updated auth, client and validate packages

This commit is contained in:
thomashii 2022-02-21 09:17:27 +08:00
parent 6db69d0fb1
commit 48a441cf77
17 changed files with 113 additions and 68 deletions

View file

@ -1,5 +1,13 @@
# Change Log
## 6.0.0
* Updated to min SDK 2.15.x
## 5.0.0
* No release. Skipped
## 4.1.2
* Fixed `requireAuthentication` to work correctly with null-safety type

View file

@ -107,13 +107,14 @@ class AngelAuth<User> {
throw StateError(
'An `AngelAuth` plug-in was called without its `deserializer` being set. All authentication will fail.');
}
*/
if (app.container == null) {
_log.severe('Angel3 container is null');
throw StateError(
'Angel.container is null. All authentication will fail.');
}
var appContainer = app.container!;
*/
var appContainer = app.container;
appContainer.registerSingleton(this);
if (runtimeType != AngelAuth) {

View file

@ -1,12 +1,12 @@
name: angel3_auth
description: A complete authentication plugin for Angel3. Includes support for stateless JWT tokens, Basic Auth, and more.
version: 4.1.2
version: 6.0.0
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/auth
environment:
sdk: '>=2.12.0 <3.0.0'
sdk: '>=2.15.0 <3.0.0'
dependencies:
angel3_framework: ^4.2.0
angel3_framework: ^6.0.0
charcode: ^1.2.0
collection: ^1.15.0
crypto: ^3.0.0
@ -15,8 +15,21 @@ dependencies:
quiver: ^3.0.0
logging: ^1.0.0
dev_dependencies:
angel3_container: ^3.1.0
angel3_container: ^6.0.0
http: ^0.13.1
io: ^1.0.0
test: ^1.17.4
lints: ^1.0.0
dependency_overrides:
angel3_container:
path: ../container/angel_container
angel3_framework:
path: ../framework
angel3_http_exception:
path: ../http_exception
angel3_model:
path: ../model
angel3_route:
path: ../route
angel3_mock_request:
path: ../mock_request

View file

@ -50,7 +50,7 @@ void main() {
var oldErrorHandler = app.errorHandler;
app.errorHandler = (e, req, res) {
app.logger?.severe(e.message, e, e.stackTrace ?? StackTrace.current);
app.logger.severe(e.message, e, e.stackTrace ?? StackTrace.current);
return oldErrorHandler(e, req, res);
};

View file

@ -1,5 +1,13 @@
# Change Log
## 6.0.0
* Updated to min SDK 2.15.x
## 5.0.0
* No release. Skipped
## 4.2.0
* Updated `package:build_runner`

View file

@ -33,10 +33,6 @@ abstract class Angel extends http.BaseClient {
Angel(baseUrl)
: baseUrl = baseUrl is Uri ? baseUrl : Uri.parse(baseUrl.toString());
/// Prefer to use [baseUrl] instead.
@deprecated
String get basePath => baseUrl.toString();
/// Fired whenever a WebSocket is successfully authenticated.
Stream<AngelAuthResult> get onAuthenticated;
@ -48,10 +44,7 @@ abstract class Angel extends http.BaseClient {
///
/// The given [credentials] are sent to server as-is; the request body is sent as JSON.
Future<AngelAuthResult> authenticate(
{required String type,
credentials,
String authEndpoint = '/auth',
@deprecated String reviveEndpoint = '/auth/token'});
{required String type, credentials, String authEndpoint = '/auth'});
/// Shorthand for authenticating via a JWT string.
Future<AngelAuthResult> reviveJwt(String token,
@ -87,7 +80,7 @@ abstract class Angel extends http.BaseClient {
/// You can pass a custom [deserializer], which is typically necessary in cases where
/// `dart:mirrors` does not exist.
Service<Id, Data> service<Id, Data>(String path,
{@deprecated Type? type, AngelDeserializer<Data>? deserializer});
{AngelDeserializer<Data>? deserializer});
//@override
//Future<http.Response> delete(url, {Map<String, String> headers});

View file

@ -1,4 +1 @@
@deprecated
library auth_types;
const String local = 'local', token = 'token';

View file

@ -1,6 +1,4 @@
import 'dart:async';
import 'dart:convert' show Encoding;
import 'package:angel3_http_exception/angel3_http_exception.dart';
import 'dart:convert';
import 'package:http/src/base_client.dart' as http;
import 'package:http/src/base_request.dart' as http;
@ -32,14 +30,14 @@ AngelHttpException failure(http.Response response,
if (v is Map && (v['is_error'] == true) || v['isError'] == true) {
return AngelHttpException.fromMap(v as Map);
} else {
return AngelHttpException(error,
return AngelHttpException(
message: message ??
'Unhandled exception while connecting to Angel backend.',
statusCode: response.statusCode,
stackTrace: stack);
}
} catch (e, st) {
return AngelHttpException(error ?? e,
return AngelHttpException(
message: message ??
'Angel backend did not return JSON - an error likely occurred.',
statusCode: response.statusCode,
@ -63,10 +61,7 @@ abstract class BaseAngelClient extends Angel {
@override
Future<AngelAuthResult> authenticate(
{String? type,
credentials,
String authEndpoint = '/auth',
@deprecated String reviveEndpoint = '/auth/token'}) async {
{String? type, credentials, String authEndpoint = '/auth'}) async {
type ??= 'token';
var segments = baseUrl.pathSegments
@ -258,10 +253,6 @@ class BaseAngelService<Id, Data> extends Service<Id, Data?> {
BaseAngelService(this.client, this.app, baseUrl, {this.deserializer})
: baseUrl = baseUrl is Uri ? baseUrl : Uri.parse(baseUrl.toString());
/// Use [baseUrl] instead.
@deprecated
String get basePath => baseUrl.toString();
Data? deserialize(x) {
return deserializer != null ? deserializer!(x) : x as Data?;
}
@ -296,12 +287,12 @@ class BaseAngelService<Id, Data> extends Service<Id, Data?> {
var v = json.decode(response.body) as List;
//var r = v.map(deserialize).toList();
var r = <Data>[];
v.forEach((element) {
for (var element in v) {
var a = deserialize(element);
if (a != null) {
r.add(a);
}
});
}
_onIndexed.add(r);
return r;
} catch (e, st) {

View file

@ -17,10 +17,7 @@ class Rest extends BaseAngelClient {
@override
Future<AngelAuthResult> authenticate(
{String? type,
credentials,
String authEndpoint = '/auth',
@deprecated String reviveEndpoint = '/auth/token'}) async {
{String? type, credentials, String authEndpoint = '/auth'}) async {
if (type == null || type == 'token') {
if (!window.localStorage.containsKey('token')) {
throw Exception(

View file

@ -1,12 +1,12 @@
name: angel3_client
version: 4.2.0
version: 6.0.0
description: A browser, mobile and command line based client that supports querying Angel3 servers
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/client
environment:
sdk: '>=2.12.0 <3.0.0'
sdk: '>=2.15.0 <3.0.0'
dependencies:
angel3_http_exception: ^3.0.0
angel3_http_exception: ^6.0.0
belatuk_json_serializer: ^5.0.0
collection: ^1.15.0
http: ^0.13.1
@ -14,13 +14,28 @@ dependencies:
path: ^1.8.0
logging: ^1.0.0
dev_dependencies:
angel3_framework: ^4.2.0
angel3_model: ^3.1.0
angel3_mock_request: ^2.0.0
angel3_container: ^3.1.0
angel3_auth: ^4.1.0
angel3_framework: ^6.0.0
angel3_model: ^6.0.0
angel3_mock_request: ^6.0.0
angel3_container: ^6.0.0
angel3_auth: ^6.0.0
async: ^2.6.1
build_runner: ^2.1.2
build_web_compilers: ^3.2.1
test: ^1.17.5
lints: ^1.0.0
dependency_overrides:
angel3_container:
path: ../container/angel_container
angel3_framework:
path: ../framework
angel3_http_exception:
path: ../http_exception
angel3_model:
path: ../model
angel3_route:
path: ../route
angel3_mock_request:
path: ../mock_request
angel3_auth:
path: ../auth

View file

@ -1,10 +1,10 @@
name: angel3_static
version: 4.1.0
version: 6.0.0
description: This library provides a virtual directory to serve static files for Angel3 framework.
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/static
environment:
sdk: '>=2.12.0 <3.0.0'
sdk: '>=2.15.0 <3.0.0'
dependencies:
angel3_framework: ^4.1.0
belatuk_range_header: ^4.0.0

View file

@ -1,10 +1,10 @@
name: angel3_test
version: 4.1.1
version: 6.0.0
description: Testing utility library for the Angel3 framework. Use with package:test.
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/test
environment:
sdk: '>=2.12.0 <3.0.0'
sdk: '>=2.15.0 <3.0.0'
dependencies:
angel3_client: ^4.1.0
angel3_framework: ^4.2.0

View file

@ -1,5 +1,13 @@
# Change Log
## 6.0.0
* Updated to min SDK 2.15.x
## 5.0.0
* No release. Skipped
## 4.1.0
* Updated linter to `package:lints`

View file

@ -1,6 +1,5 @@
import 'dart:async';
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_http_exception/angel3_http_exception.dart';
import 'package:matcher/matcher.dart';
import 'context_aware.dart';

View file

@ -69,10 +69,6 @@ final Matcher isUrl = predicate(
(dynamic value) => value is String && _url.hasMatch(value),
'a valid url, starting with http:// or https://');
/// Use [isUrl] instead.
@deprecated
final Matcher isurl = isUrl;
/// Enforces a minimum length on a string.
Matcher minLength(int length) => predicate(
(dynamic value) => value is String && value.length >= length,

View file

@ -325,7 +325,9 @@ class Validator extends Matcher {
/// Adds all given [rules].
void addRules(String key, Iterable<Matcher> rules) {
rules.forEach((rule) => addRule(key, rule));
for (var rule in rules) {
addRule(key, rule);
}
}
/// Removes a [rule].
@ -337,7 +339,9 @@ class Validator extends Matcher {
/// Removes all given [rules].
void removeRules(String key, Iterable<Matcher> rules) {
rules.forEach((rule) => removeRule(key, rule));
for (var rule in rules) {
removeRule(key, rule);
}
}
@override
@ -367,11 +371,13 @@ class ValidationResult {
/// This is empty if validation was successful.
List<String> get errors => List<String>.unmodifiable(_errors);
ValidationResult withData(Map<String, dynamic> data) =>
ValidationResult().._data.addAll(data).._errors.addAll(_errors);
ValidationResult withData(Map<String, dynamic> data) => ValidationResult()
.._data.addAll(data)
.._errors.addAll(_errors);
ValidationResult withErrors(Iterable<String> errors) =>
ValidationResult().._data.addAll(_data).._errors.addAll(errors);
ValidationResult withErrors(Iterable<String> errors) => ValidationResult()
.._data.addAll(_data)
.._errors.addAll(errors);
}
/// Occurs when user-provided data is invalid.
@ -385,7 +391,8 @@ class ValidationException extends AngelHttpException {
final String message;
ValidationException(this.message, {Iterable<String> errors = const []})
: super(FormatException(message),
: super(
message: message,
statusCode: 400,
errors: (errors).toSet().toList(),
stackTrace: StackTrace.current) {

View file

@ -1,19 +1,31 @@
name: angel3_validate
description: Cross-platform request body validation library based on `matcher`.
version: 4.1.0
version: 6.0.0
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/validate
environment:
sdk: '>=2.12.0 <3.0.0'
sdk: '>=2.15.0 <3.0.0'
dependencies:
angel3_framework: ^4.2.0
angel3_http_exception: ^3.0.0
angel3_framework: ^6.0.0
angel3_http_exception: ^6.0.0
matcher: ^0.12.0
dev_dependencies:
#angel3_test:
angel3_mock_request: ^2.0.0
angel3_mock_request: ^6.0.0
build_runner: ^2.1.0
build_web_compilers: ^3.2.0
logging: ^1.0.1
lints: ^1.0.0
test: ^1.17.4
test: ^1.17.4
dependency_overrides:
angel3_container:
path: ../container/angel_container
angel3_framework:
path: ../framework
angel3_http_exception:
path: ../http_exception
angel3_model:
path: ../model
angel3_route:
path: ../route
angel3_mock_request:
path: ../mock_request