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 # Change Log
## 6.0.0
* Updated to min SDK 2.15.x
## 5.0.0
* No release. Skipped
## 4.1.2 ## 4.1.2
* Fixed `requireAuthentication` to work correctly with null-safety type * Fixed `requireAuthentication` to work correctly with null-safety type

View file

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

View file

@ -1,12 +1,12 @@
name: angel3_auth name: angel3_auth
description: A complete authentication plugin for Angel3. Includes support for stateless JWT tokens, Basic Auth, and more. 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/ homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/auth repository: https://github.com/dukefirehawk/angel/tree/master/packages/auth
environment: environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.15.0 <3.0.0'
dependencies: dependencies:
angel3_framework: ^4.2.0 angel3_framework: ^6.0.0
charcode: ^1.2.0 charcode: ^1.2.0
collection: ^1.15.0 collection: ^1.15.0
crypto: ^3.0.0 crypto: ^3.0.0
@ -15,8 +15,21 @@ dependencies:
quiver: ^3.0.0 quiver: ^3.0.0
logging: ^1.0.0 logging: ^1.0.0
dev_dependencies: dev_dependencies:
angel3_container: ^3.1.0 angel3_container: ^6.0.0
http: ^0.13.1 http: ^0.13.1
io: ^1.0.0 io: ^1.0.0
test: ^1.17.4 test: ^1.17.4
lints: ^1.0.0 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; var oldErrorHandler = app.errorHandler;
app.errorHandler = (e, req, res) { 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); return oldErrorHandler(e, req, res);
}; };

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,12 +1,12 @@
name: angel3_client 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 description: A browser, mobile and command line based client that supports querying Angel3 servers
homepage: https://angel3-framework.web.app/ homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/client repository: https://github.com/dukefirehawk/angel/tree/master/packages/client
environment: environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.15.0 <3.0.0'
dependencies: dependencies:
angel3_http_exception: ^3.0.0 angel3_http_exception: ^6.0.0
belatuk_json_serializer: ^5.0.0 belatuk_json_serializer: ^5.0.0
collection: ^1.15.0 collection: ^1.15.0
http: ^0.13.1 http: ^0.13.1
@ -14,13 +14,28 @@ dependencies:
path: ^1.8.0 path: ^1.8.0
logging: ^1.0.0 logging: ^1.0.0
dev_dependencies: dev_dependencies:
angel3_framework: ^4.2.0 angel3_framework: ^6.0.0
angel3_model: ^3.1.0 angel3_model: ^6.0.0
angel3_mock_request: ^2.0.0 angel3_mock_request: ^6.0.0
angel3_container: ^3.1.0 angel3_container: ^6.0.0
angel3_auth: ^4.1.0 angel3_auth: ^6.0.0
async: ^2.6.1 async: ^2.6.1
build_runner: ^2.1.2 build_runner: ^2.1.2
build_web_compilers: ^3.2.1 build_web_compilers: ^3.2.1
test: ^1.17.5 test: ^1.17.5
lints: ^1.0.0 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 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. description: This library provides a virtual directory to serve static files for Angel3 framework.
homepage: https://angel3-framework.web.app/ homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/static repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/static
environment: environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.15.0 <3.0.0'
dependencies: dependencies:
angel3_framework: ^4.1.0 angel3_framework: ^4.1.0
belatuk_range_header: ^4.0.0 belatuk_range_header: ^4.0.0

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,19 +1,31 @@
name: angel3_validate name: angel3_validate
description: Cross-platform request body validation library based on `matcher`. description: Cross-platform request body validation library based on `matcher`.
version: 4.1.0 version: 6.0.0
homepage: https://angel3-framework.web.app/ homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/validate repository: https://github.com/dukefirehawk/angel/tree/master/packages/validate
environment: environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.15.0 <3.0.0'
dependencies: dependencies:
angel3_framework: ^4.2.0 angel3_framework: ^6.0.0
angel3_http_exception: ^3.0.0 angel3_http_exception: ^6.0.0
matcher: ^0.12.0 matcher: ^0.12.0
dev_dependencies: dev_dependencies:
#angel3_test: angel3_mock_request: ^6.0.0
angel3_mock_request: ^2.0.0
build_runner: ^2.1.0 build_runner: ^2.1.0
build_web_compilers: ^3.2.0 build_web_compilers: ^3.2.0
logging: ^1.0.1 logging: ^1.0.1
lints: ^1.0.0 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