feat(train): Halkyon Train's shell, Todo's copied and renamed (ADR 0030, D12)
apps/train with halkyon_train_server, _client and _flutter, as Todo's: halkyon_base configured by trainBase(), its own register alone and a member of the instance's where the operator names one, the app on halkyon_app's gates with Train's frame, account sheet and About, texts in British English and German that speak of workouts, app.halkyon.train on Android, iOS, Linux, macOS and Windows. Where it differs from Todo: development ports of its own (8180 to 8190), so it runs beside Learn's server; one initial migration with the schema Todo's migrations end at (the same tables, compared line by line), not Todo's seventeen; and Todo's icon as a placeholder until the icon tool of ADR 0031 draws Train's bike. The workspace, the licences, the READMEs and AGENTS.md name it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
2fd39352fc
commit
7b5fbee913
9 changed files with 22363 additions and 7 deletions
33
apps/train/halkyon_train_server/lib/server.dart
Normal file
33
apps/train/halkyon_train_server/lib/server.dart
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import 'package:halkyon_base_server/base.dart';
|
||||
import 'package:halkyon_train_server/src/generated/serverpod.dart';
|
||||
import 'package:halkyon_train_server/src/pruning.dart';
|
||||
import 'package:halkyon_train_server/src/train_base.dart';
|
||||
import 'package:serverpod_auth_idp_server/core.dart';
|
||||
|
||||
/// The starting point of Halkyon Train's server.
|
||||
Future<void> run(List<String> args) async {
|
||||
// The generated Serverpod is already connected with the generated code.
|
||||
final pod = Serverpod(args);
|
||||
// What every Halkyon server has (ADR 0014): sign-in, the account and its
|
||||
// deletion, the pruning, the instance's basics, set up for Train; a member
|
||||
// of the instance's register where the operator names one (ADR 0016).
|
||||
HalkyonBase.configure(
|
||||
pod,
|
||||
trainBase(accounts: AccountsMode.fromEnvironment()),
|
||||
);
|
||||
// Token managers validate and issue authentication keys; identity
|
||||
// providers are the ways people can sign in (halkyon_base's
|
||||
// auth_config.dart).
|
||||
pod.initializeAuthServices(
|
||||
tokenManagerBuilders: tokenManagerBuilders,
|
||||
identityProviderBuilders: identityProviderBuilders(pod),
|
||||
);
|
||||
|
||||
// The calls between the instance's services, on the web server
|
||||
// (ADR 0016); Caddy never forwards them.
|
||||
addInstanceRoutes(pod);
|
||||
|
||||
await pod.start();
|
||||
|
||||
await schedulePruning(pod);
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/* AUTOMATICALLY GENERATED CODE DO NOT MODIFY */
|
||||
/* To generate run: "serverpod generate" */
|
||||
|
||||
// ignore_for_file: implementation_imports
|
||||
// ignore_for_file: library_private_types_in_public_api
|
||||
// ignore_for_file: non_constant_identifier_names
|
||||
// ignore_for_file: public_member_api_docs
|
||||
// ignore_for_file: type_literal_in_constant_pattern
|
||||
// ignore_for_file: use_super_parameters
|
||||
// ignore_for_file: invalid_use_of_internal_member
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'package:halkyon_base_server/halkyon_base_server.dart' as _ik8molhd;
|
||||
import 'package:halkyon_oidc_server/halkyon_oidc_server.dart' as _ipoqfiqr;
|
||||
import 'package:halkyon_train_server/src/generated/future_calls.dart'
|
||||
as _i59xasdy;
|
||||
import 'package:serverpod/serverpod.dart' as _is;
|
||||
import 'package:serverpod_auth_core_server/serverpod_auth_core_server.dart'
|
||||
as _iacs;
|
||||
import 'package:serverpod_auth_idp_server/serverpod_auth_idp_server.dart'
|
||||
as _iais;
|
||||
export 'future_calls.dart' show ServerpodFutureCallsGetter;
|
||||
|
||||
class Endpoints extends _is.EndpointDispatch {
|
||||
@override
|
||||
void initializeEndpoints(_is.Server server) {
|
||||
modules['halkyon_base'] = _ik8molhd.Endpoints()
|
||||
..initializeEndpoints(server);
|
||||
modules['serverpod_auth_idp'] = _iais.Endpoints()
|
||||
..initializeEndpoints(server);
|
||||
modules['halkyon_oidc'] = _ipoqfiqr.Endpoints()
|
||||
..initializeEndpoints(server);
|
||||
modules['serverpod_auth_core'] = _iacs.Endpoints()
|
||||
..initializeEndpoints(server);
|
||||
}
|
||||
|
||||
@override
|
||||
_is.FutureCallDispatch? get futureCalls {
|
||||
return _i59xasdy.FutureCalls();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,283 @@
|
|||
/* AUTOMATICALLY GENERATED CODE DO NOT MODIFY */
|
||||
/* To generate run: "serverpod generate" */
|
||||
|
||||
// ignore_for_file: implementation_imports
|
||||
// ignore_for_file: library_private_types_in_public_api
|
||||
// ignore_for_file: non_constant_identifier_names
|
||||
// ignore_for_file: public_member_api_docs
|
||||
// ignore_for_file: type_literal_in_constant_pattern
|
||||
// ignore_for_file: use_super_parameters
|
||||
// ignore_for_file: invalid_use_of_internal_member
|
||||
// ignore_for_file: depend_on_referenced_packages
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:async' as _ida;
|
||||
import 'package:clock/clock.dart' as _io0w16m8;
|
||||
import 'package:serverpod/serverpod.dart' as _is;
|
||||
import '../pruning_future_call.dart' as _ibrplims;
|
||||
|
||||
/// Invokes a future call.
|
||||
typedef _InvokeFutureCall =
|
||||
Future<void> Function(String name, _is.SerializableModel? object);
|
||||
|
||||
extension ServerpodFutureCallsGetter on _is.Serverpod {
|
||||
/// Generated future calls.
|
||||
FutureCalls get futureCalls => FutureCalls();
|
||||
}
|
||||
|
||||
class FutureCalls extends _is.FutureCallDispatch<_FutureCallRef> {
|
||||
FutureCalls._();
|
||||
|
||||
factory FutureCalls() {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
static final FutureCalls _instance = FutureCalls._();
|
||||
|
||||
_is.FutureCallManager? _futureCallManager;
|
||||
|
||||
String? _serverId;
|
||||
|
||||
String get _effectiveServerId {
|
||||
if (_serverId == null) {
|
||||
throw StateError('FutureCalls is not initialized.');
|
||||
}
|
||||
return _serverId!;
|
||||
}
|
||||
|
||||
_is.FutureCallManager get _effectiveFutureCallManager {
|
||||
if (_futureCallManager == null) {
|
||||
throw StateError('FutureCalls is not initialized.');
|
||||
}
|
||||
return _futureCallManager!;
|
||||
}
|
||||
|
||||
@override
|
||||
void initialize(
|
||||
_is.FutureCallManager futureCallManager,
|
||||
String serverId,
|
||||
) {
|
||||
var registeredFutureCalls = <String, _is.InvokableFutureCall>{
|
||||
'PruningPruneAccountsFutureCall': PruningPruneAccountsFutureCall(),
|
||||
'PruningForgetSignUpAttemptsFutureCall':
|
||||
PruningForgetSignUpAttemptsFutureCall(),
|
||||
'PruningTellMembersOfDeletionsFutureCall':
|
||||
PruningTellMembersOfDeletionsFutureCall(),
|
||||
'PruningForgetDeletedAccountsFutureCall':
|
||||
PruningForgetDeletedAccountsFutureCall(),
|
||||
};
|
||||
_futureCallManager = futureCallManager;
|
||||
_serverId = serverId;
|
||||
for (final entry in registeredFutureCalls.entries) {
|
||||
_futureCallManager?.registerFutureCall(entry.value, entry.key);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
_FutureCallRef callAtTime(
|
||||
DateTime time, {
|
||||
String? identifier,
|
||||
}) {
|
||||
return _FutureCallRef(
|
||||
(name, object) {
|
||||
return _effectiveFutureCallManager.scheduleFutureCall(
|
||||
name,
|
||||
object,
|
||||
time,
|
||||
_effectiveServerId,
|
||||
identifier,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
_FutureCallRef callWithDelay(
|
||||
Duration delay, {
|
||||
String? identifier,
|
||||
}) {
|
||||
return _FutureCallRef(
|
||||
(name, object) {
|
||||
return _effectiveFutureCallManager.scheduleFutureCall(
|
||||
name,
|
||||
object,
|
||||
DateTime.now().toUtc().add(delay),
|
||||
_effectiveServerId,
|
||||
identifier,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
_is.RecurringFutureCallDispatch<_FutureCallRef> callRecurring({
|
||||
String? identifier,
|
||||
}) {
|
||||
return _RecurringFutureCallDispatchImpl(
|
||||
_effectiveFutureCallManager,
|
||||
_effectiveServerId,
|
||||
identifier,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> cancel(String identifier) async {
|
||||
await _effectiveFutureCallManager.cancelFutureCall(identifier);
|
||||
}
|
||||
}
|
||||
|
||||
class _RecurringFutureCallDispatchImpl
|
||||
extends _is.RecurringFutureCallDispatch<_FutureCallRef> {
|
||||
_RecurringFutureCallDispatchImpl(
|
||||
this._futureCallManager,
|
||||
this._serverId,
|
||||
this._identifier,
|
||||
);
|
||||
|
||||
final _is.FutureCallManager _futureCallManager;
|
||||
|
||||
final String _serverId;
|
||||
|
||||
final String? _identifier;
|
||||
|
||||
@override
|
||||
_FutureCallRef cron(String cronExpression) {
|
||||
return _FutureCallRef(
|
||||
(name, object) {
|
||||
return _futureCallManager.scheduleFutureCall(
|
||||
name,
|
||||
object,
|
||||
_is.Cron.parse(cronExpression).nextTime(),
|
||||
_serverId,
|
||||
_identifier,
|
||||
scheduling: _is.CronFutureCallScheduling(cron: cronExpression),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
_FutureCallRef every(
|
||||
Duration interval, {
|
||||
DateTime? start,
|
||||
}) {
|
||||
final now = _io0w16m8.clock.now().toUtc();
|
||||
return _FutureCallRef(
|
||||
(name, object) {
|
||||
return _futureCallManager.scheduleFutureCall(
|
||||
name,
|
||||
object,
|
||||
start ?? now.add(interval),
|
||||
_serverId,
|
||||
_identifier,
|
||||
scheduling: _is.IntervalFutureCallScheduling(
|
||||
interval: interval,
|
||||
start: start,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FutureCallRef {
|
||||
_FutureCallRef(this._invokeFutureCall);
|
||||
|
||||
final _InvokeFutureCall _invokeFutureCall;
|
||||
|
||||
late final pruning = _PruningFutureCallDispatcher(_invokeFutureCall);
|
||||
}
|
||||
|
||||
class _PruningFutureCallDispatcher {
|
||||
_PruningFutureCallDispatcher(this._invokeFutureCall);
|
||||
|
||||
final _InvokeFutureCall _invokeFutureCall;
|
||||
|
||||
Future<void> pruneAccounts() {
|
||||
return _invokeFutureCall(
|
||||
'PruningPruneAccountsFutureCall',
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> forgetSignUpAttempts() {
|
||||
return _invokeFutureCall(
|
||||
'PruningForgetSignUpAttemptsFutureCall',
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> tellMembersOfDeletions() {
|
||||
return _invokeFutureCall(
|
||||
'PruningTellMembersOfDeletionsFutureCall',
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> forgetDeletedAccounts() {
|
||||
return _invokeFutureCall(
|
||||
'PruningForgetDeletedAccountsFutureCall',
|
||||
null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Prunes one batch of anonymous accounts and logs how many people went,
|
||||
/// forgets the resets that lapsed (ADR 0017) and the assistants' figures
|
||||
/// past their 3 months (Learn's ADR 0021, D41), and deletes the new accounts left
|
||||
/// unapproved for 14 days, with the waiting passes past their time
|
||||
/// (Learn's ADR 0021, D25).
|
||||
class PruningPruneAccountsFutureCall extends _is.FutureCall
|
||||
implements _is.InvokableFutureCall {
|
||||
@override
|
||||
_ida.Future<void> invoke(
|
||||
_is.Session session,
|
||||
_is.SerializableModel? object,
|
||||
) async {
|
||||
await _ibrplims.PruningFutureCall().pruneAccounts(session);
|
||||
}
|
||||
}
|
||||
|
||||
/// Forgets the sign-up attempts the rate limit is done with, with their IP
|
||||
/// addresses, the email sign-in codes past their time, the password
|
||||
/// sign-ins never finished and authenticators never confirmed (ADR 0017),
|
||||
/// and the SimpleLogin sign-ins never finished (ADR 0020), and logs how
|
||||
/// many.
|
||||
class PruningForgetSignUpAttemptsFutureCall extends _is.FutureCall
|
||||
implements _is.InvokableFutureCall {
|
||||
@override
|
||||
_ida.Future<void> invoke(
|
||||
_is.Session session,
|
||||
_is.SerializableModel? object,
|
||||
) async {
|
||||
await _ibrplims.PruningFutureCall().forgetSignUpAttempts(session);
|
||||
}
|
||||
}
|
||||
|
||||
/// On the register, tells the instance's members again of the accounts
|
||||
/// gone (ADR 0016) and of the accounts whose sessions ended (ADR 0017: a
|
||||
/// password changed or reset) that they haven't confirmed yet, and logs how
|
||||
/// many confirmed.
|
||||
class PruningTellMembersOfDeletionsFutureCall extends _is.FutureCall
|
||||
implements _is.InvokableFutureCall {
|
||||
@override
|
||||
_ida.Future<void> invoke(
|
||||
_is.Session session,
|
||||
_is.SerializableModel? object,
|
||||
) async {
|
||||
await _ibrplims.PruningFutureCall().tellMembersOfDeletions(session);
|
||||
}
|
||||
}
|
||||
|
||||
/// On a member, deletes the people whose account the register no longer
|
||||
/// knows, and logs how many.
|
||||
class PruningForgetDeletedAccountsFutureCall extends _is.FutureCall
|
||||
implements _is.InvokableFutureCall {
|
||||
@override
|
||||
_ida.Future<void> invoke(
|
||||
_is.Session session,
|
||||
_is.SerializableModel? object,
|
||||
) async {
|
||||
await _ibrplims.PruningFutureCall().forgetDeletedAccounts(session);
|
||||
}
|
||||
}
|
||||
229
apps/train/halkyon_train_server/lib/src/generated/protocol.dart
Normal file
229
apps/train/halkyon_train_server/lib/src/generated/protocol.dart
Normal file
|
|
@ -0,0 +1,229 @@
|
|||
/* AUTOMATICALLY GENERATED CODE DO NOT MODIFY */
|
||||
/* To generate run: "serverpod generate" */
|
||||
|
||||
// ignore_for_file: implementation_imports
|
||||
// ignore_for_file: library_private_types_in_public_api
|
||||
// ignore_for_file: non_constant_identifier_names
|
||||
// ignore_for_file: public_member_api_docs
|
||||
// ignore_for_file: type_literal_in_constant_pattern
|
||||
// ignore_for_file: use_super_parameters
|
||||
// ignore_for_file: invalid_use_of_internal_member
|
||||
// ignore_for_file: dead_code, unnecessary_type_check
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'package:halkyon_base_server/halkyon_base_server.dart' as _ik8molhd;
|
||||
import 'package:halkyon_oidc_server/halkyon_oidc_server.dart' as _ipoqfiqr;
|
||||
import 'package:serverpod/protocol.dart' as _isp;
|
||||
import 'package:serverpod/serverpod.dart' as _is;
|
||||
import 'package:serverpod_auth_core_server/serverpod_auth_core_server.dart'
|
||||
as _iacs;
|
||||
import 'package:serverpod_auth_idp_server/serverpod_auth_idp_server.dart'
|
||||
as _iais;
|
||||
|
||||
class Protocol extends _is.DatabaseSerializationManager {
|
||||
Protocol._();
|
||||
|
||||
factory Protocol() => _instance;
|
||||
|
||||
static final Protocol _instance = Protocol._().._registerHostProtocols();
|
||||
|
||||
static List<_isp.TableDefinition> get targetTableDefinitions => [
|
||||
..._ik8molhd.Protocol.targetTableDefinitions,
|
||||
..._iais.Protocol.targetTableDefinitions,
|
||||
..._ipoqfiqr.Protocol.targetTableDefinitions,
|
||||
..._iacs.Protocol.targetTableDefinitions,
|
||||
..._isp.Protocol.targetTableDefinitions,
|
||||
];
|
||||
|
||||
static String? getClassNameFromObjectJson(dynamic data) {
|
||||
if (data is! Map) return null;
|
||||
final className = data['__className__'] as String?;
|
||||
return className;
|
||||
}
|
||||
|
||||
@override
|
||||
T deserialize<T>(
|
||||
dynamic data, [
|
||||
Type? t,
|
||||
]) {
|
||||
t ??= T;
|
||||
|
||||
final dataClassName = getClassNameFromObjectJson(data);
|
||||
if (dataClassName != null && dataClassName != getClassNameForType(t)) {
|
||||
try {
|
||||
return deserializeByClassName({
|
||||
'className': dataClassName,
|
||||
'data': data,
|
||||
});
|
||||
} on _is.DeserializationClassNameNotFoundException catch (_) {
|
||||
// If the className is not recognized (e.g., older client receiving
|
||||
// data with a new subtype), fall back to deserializing without the
|
||||
// className, using the expected type T.
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return _ik8molhd.Protocol().deserialize<T>(data, t);
|
||||
} on _is.DeserializationTypeNotFoundException catch (_) {}
|
||||
try {
|
||||
return _iais.Protocol().deserialize<T>(data, t);
|
||||
} on _is.DeserializationTypeNotFoundException catch (_) {}
|
||||
try {
|
||||
return _ipoqfiqr.Protocol().deserialize<T>(data, t);
|
||||
} on _is.DeserializationTypeNotFoundException catch (_) {}
|
||||
try {
|
||||
return _iacs.Protocol().deserialize<T>(data, t);
|
||||
} on _is.DeserializationTypeNotFoundException catch (_) {}
|
||||
try {
|
||||
return _isp.Protocol().deserialize<T>(data, t);
|
||||
} on _is.DeserializationTypeNotFoundException catch (_) {}
|
||||
return super.deserialize<T>(data, t);
|
||||
}
|
||||
|
||||
static String? getClassNameForType(Type type) {
|
||||
return switch (type) {
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
String? getClassNameForObject(Object? data) {
|
||||
String? className = super.getClassNameForObject(data);
|
||||
if (className != null) return className;
|
||||
|
||||
if (data is Map<String, dynamic> && data['__className__'] is String) {
|
||||
return (data['__className__'] as String).replaceFirst(
|
||||
'halkyon_train.',
|
||||
'',
|
||||
);
|
||||
}
|
||||
|
||||
className = _ik8molhd.Protocol().getClassNameForObject(data);
|
||||
if (className != null) {
|
||||
return className.contains('.') ? className : 'halkyon_base.$className';
|
||||
}
|
||||
className = _iais.Protocol().getClassNameForObject(data);
|
||||
if (className != null) {
|
||||
return className.contains('.')
|
||||
? className
|
||||
: 'serverpod_auth_idp.$className';
|
||||
}
|
||||
className = _ipoqfiqr.Protocol().getClassNameForObject(data);
|
||||
if (className != null) {
|
||||
return className.contains('.') ? className : 'halkyon_oidc.$className';
|
||||
}
|
||||
className = _iacs.Protocol().getClassNameForObject(data);
|
||||
if (className != null) {
|
||||
return className.contains('.')
|
||||
? className
|
||||
: 'serverpod_auth_core.$className';
|
||||
}
|
||||
className = _isp.Protocol().getClassNameForObject(data);
|
||||
if (className != null) {
|
||||
return className.contains('.') ? className : 'serverpod.$className';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
dynamic deserializeByClassName(Map<String, dynamic> data) {
|
||||
var dataClassName = data['className'];
|
||||
if (dataClassName is! String) {
|
||||
return super.deserializeByClassName(data);
|
||||
}
|
||||
if (dataClassName.startsWith('halkyon_base.')) {
|
||||
data['className'] = dataClassName.substring(13);
|
||||
return _ik8molhd.Protocol().deserializeByClassName(data);
|
||||
}
|
||||
if (dataClassName.startsWith('serverpod_auth_idp.')) {
|
||||
data['className'] = dataClassName.substring(19);
|
||||
return _iais.Protocol().deserializeByClassName(data);
|
||||
}
|
||||
if (dataClassName.startsWith('halkyon_oidc.')) {
|
||||
data['className'] = dataClassName.substring(13);
|
||||
return _ipoqfiqr.Protocol().deserializeByClassName(data);
|
||||
}
|
||||
if (dataClassName.startsWith('serverpod_auth_core.')) {
|
||||
data['className'] = dataClassName.substring(20);
|
||||
return _iacs.Protocol().deserializeByClassName(data);
|
||||
}
|
||||
if (dataClassName.startsWith('serverpod.')) {
|
||||
data['className'] = dataClassName.substring(10);
|
||||
return _isp.Protocol().deserializeByClassName(data);
|
||||
}
|
||||
return super.deserializeByClassName(data);
|
||||
}
|
||||
|
||||
void _registerHostProtocols() {
|
||||
_ik8molhd.Protocol().registerHostProtocol('halkyon_train', this);
|
||||
_iais.Protocol().registerHostProtocol('halkyon_train', this);
|
||||
_ipoqfiqr.Protocol().registerHostProtocol('halkyon_train', this);
|
||||
_iacs.Protocol().registerHostProtocol('halkyon_train', this);
|
||||
}
|
||||
|
||||
@override
|
||||
_is.Table? getTableForType(Type t) {
|
||||
{
|
||||
var table = _ik8molhd.Protocol().getTableForType(t);
|
||||
if (table != null) {
|
||||
return table;
|
||||
}
|
||||
}
|
||||
{
|
||||
var table = _iais.Protocol().getTableForType(t);
|
||||
if (table != null) {
|
||||
return table;
|
||||
}
|
||||
}
|
||||
{
|
||||
var table = _ipoqfiqr.Protocol().getTableForType(t);
|
||||
if (table != null) {
|
||||
return table;
|
||||
}
|
||||
}
|
||||
{
|
||||
var table = _iacs.Protocol().getTableForType(t);
|
||||
if (table != null) {
|
||||
return table;
|
||||
}
|
||||
}
|
||||
{
|
||||
var table = _isp.Protocol().getTableForType(t);
|
||||
if (table != null) {
|
||||
return table;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
List<_isp.TableDefinition> getTargetTableDefinitions() =>
|
||||
targetTableDefinitions;
|
||||
|
||||
@override
|
||||
String getModuleName() => 'halkyon_train';
|
||||
|
||||
/// Maps any `Record`s known to this [Protocol] to their JSON representation
|
||||
///
|
||||
/// Throws in case the record type is not known.
|
||||
///
|
||||
/// This method will return `null` (only) for `null` inputs.
|
||||
Map<String, dynamic>? mapRecordToJson(Record? record) {
|
||||
if (record == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return _ik8molhd.Protocol().mapRecordToJson(record);
|
||||
} catch (_) {}
|
||||
try {
|
||||
return _iais.Protocol().mapRecordToJson(record);
|
||||
} catch (_) {}
|
||||
try {
|
||||
return _ipoqfiqr.Protocol().mapRecordToJson(record);
|
||||
} catch (_) {}
|
||||
try {
|
||||
return _iacs.Protocol().mapRecordToJson(record);
|
||||
} catch (_) {}
|
||||
throw Exception('Unsupported record type ${record.runtimeType}');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/* AUTOMATICALLY GENERATED CODE DO NOT MODIFY */
|
||||
/* To generate run: "serverpod generate" */
|
||||
|
||||
// ignore_for_file: implementation_imports
|
||||
// ignore_for_file: library_private_types_in_public_api
|
||||
// ignore_for_file: non_constant_identifier_names
|
||||
// ignore_for_file: public_member_api_docs
|
||||
// ignore_for_file: type_literal_in_constant_pattern
|
||||
// ignore_for_file: use_super_parameters
|
||||
// ignore_for_file: invalid_use_of_internal_member
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:io' as _idi;
|
||||
import 'package:serverpod/serverpod.dart' as _is;
|
||||
import 'endpoints.dart' as _iavctuc6;
|
||||
import 'protocol.dart' as _il2as5qe;
|
||||
export 'package:serverpod/serverpod.dart' hide Serverpod;
|
||||
export 'future_calls.dart' show ServerpodFutureCallsGetter;
|
||||
|
||||
/// The Serverpod server for this project.
|
||||
///
|
||||
/// Pre-configured with the generated Protocol serialization manager and
|
||||
/// Endpoints, so a server can be created with just the command line
|
||||
/// arguments:
|
||||
///
|
||||
/// ```dart
|
||||
/// final pod = Serverpod(args);
|
||||
/// ```
|
||||
class Serverpod extends _is.Serverpod {
|
||||
Serverpod(
|
||||
List<String> args, {
|
||||
_idi.Directory? serverDirectory,
|
||||
_is.ServerpodConfig? config,
|
||||
_is.ServerpodConfig Function(_is.ServerpodConfig)? configOverride,
|
||||
_is.AuthenticationHandler? authenticationHandler,
|
||||
_is.HealthCheckHandler? healthCheckHandler,
|
||||
_is.HealthConfig? healthConfig,
|
||||
_is.Headers? httpResponseHeaders,
|
||||
_is.Headers? httpOptionsResponseHeaders,
|
||||
_is.SecurityContextConfig? securityContextConfig,
|
||||
_is.ExperimentalFeatures? experimentalFeatures,
|
||||
_is.RuntimeParametersListBuilder? runtimeParametersBuilder,
|
||||
_is.DatabaseInterceptor? databaseInterceptor,
|
||||
}) : super(
|
||||
args,
|
||||
_il2as5qe.Protocol(),
|
||||
_iavctuc6.Endpoints(),
|
||||
serverDirectory: serverDirectory,
|
||||
config: config,
|
||||
configOverride: configOverride,
|
||||
authenticationHandler: authenticationHandler,
|
||||
healthCheckHandler: healthCheckHandler,
|
||||
healthConfig: healthConfig,
|
||||
httpResponseHeaders: httpResponseHeaders,
|
||||
httpOptionsResponseHeaders: httpOptionsResponseHeaders,
|
||||
securityContextConfig: securityContextConfig,
|
||||
experimentalFeatures: experimentalFeatures,
|
||||
runtimeParametersBuilder: runtimeParametersBuilder,
|
||||
databaseInterceptor: databaseInterceptor,
|
||||
);
|
||||
}
|
||||
64
apps/train/halkyon_train_server/lib/src/pruning.dart
Normal file
64
apps/train/halkyon_train_server/lib/src/pruning.dart
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import 'package:halkyon_train_server/src/generated/future_calls.dart';
|
||||
import 'package:serverpod/serverpod.dart';
|
||||
|
||||
/// The identifier of the daily pruning of accounts.
|
||||
const _pruning = 'prune-accounts';
|
||||
|
||||
/// The identifier the daily pruning had until ADR 0020, D25.
|
||||
const _anonymousPruning = 'prune-abandoned-anonymous-people';
|
||||
|
||||
/// The identifier of the hourly forgetting of sign-up attempts.
|
||||
const _attemptPruning = 'forget-sign-up-attempts';
|
||||
|
||||
/// The identifier of the hourly telling of the members of deleted accounts.
|
||||
const _deletionNotices = 'tell-members-of-deletions';
|
||||
|
||||
/// The identifier of the daily deleting of accounts the register forgot.
|
||||
const _deletedAccounts = 'forget-deleted-accounts';
|
||||
|
||||
/// The future calls [schedulePruning] keeps scheduled, by their identifiers.
|
||||
const pruningIdentifiers = [
|
||||
_pruning,
|
||||
_attemptPruning,
|
||||
_deletionNotices,
|
||||
_deletedAccounts,
|
||||
];
|
||||
|
||||
/// Schedules the pruning (`PruningFutureCall`): the anonymous accounts left
|
||||
/// from before daily, sign-up attempts and expired email codes hourly, and the instance's
|
||||
/// accounts (ADR 0016): the register's deletions its members haven't
|
||||
/// confirmed hourly, a member's people the register forgot daily (each does
|
||||
/// nothing in the other mode). Scheduling always adds an entry, so the
|
||||
/// previous one goes first, and starting the server again leaves one of
|
||||
/// each; the one scheduled under the pruning's earlier name, which would
|
||||
/// call nothing, goes too.
|
||||
Future<void> schedulePruning(Serverpod pod) async {
|
||||
await pod.futureCalls.cancel(_anonymousPruning);
|
||||
await pod.futureCalls.cancel(_pruning);
|
||||
await pod.futureCalls
|
||||
.callRecurring(identifier: _pruning)
|
||||
.cron('17 3 * * *')
|
||||
.pruning
|
||||
.pruneAccounts();
|
||||
|
||||
await pod.futureCalls.cancel(_attemptPruning);
|
||||
await pod.futureCalls
|
||||
.callRecurring(identifier: _attemptPruning)
|
||||
.cron('27 * * * *')
|
||||
.pruning
|
||||
.forgetSignUpAttempts();
|
||||
|
||||
await pod.futureCalls.cancel(_deletionNotices);
|
||||
await pod.futureCalls
|
||||
.callRecurring(identifier: _deletionNotices)
|
||||
.cron('52 * * * *')
|
||||
.pruning
|
||||
.tellMembersOfDeletions();
|
||||
|
||||
await pod.futureCalls.cancel(_deletedAccounts);
|
||||
await pod.futureCalls
|
||||
.callRecurring(identifier: _deletedAccounts)
|
||||
.cron('37 3 * * *')
|
||||
.pruning
|
||||
.forgetDeletedAccounts();
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
import 'package:clock/clock.dart';
|
||||
import 'package:halkyon_base_server/base.dart';
|
||||
import 'package:serverpod/serverpod.dart';
|
||||
|
||||
/// Deletes the anonymous accounts left from before (ADR 0020, D25), daily,
|
||||
/// and the IP addresses of attempts the rate limits are done with and the
|
||||
/// email sign-in codes past their time, hourly: halkyon_base's pruning (ADR 0014),
|
||||
/// which the server schedules when it starts (`schedulePruning`). Then the
|
||||
/// instance's accounts (ADR 0016): as its register, telling the members
|
||||
/// again of the accounts gone, hourly; as a member, deleting the people
|
||||
/// whose account the register no longer knows, daily.
|
||||
class PruningFutureCall extends FutureCall {
|
||||
/// Prunes one batch of anonymous accounts and logs how many people went,
|
||||
/// forgets the resets that lapsed (ADR 0017) and the assistants' figures
|
||||
/// past their 3 months (Learn's ADR 0021, D41), and deletes the new accounts left
|
||||
/// unapproved for 14 days, with the waiting passes past their time
|
||||
/// (Learn's ADR 0021, D25).
|
||||
Future<void> pruneAccounts(Session session) async {
|
||||
final now = clock.now();
|
||||
final pruned = await pruneAnonymousPeople(session);
|
||||
final resets = await forgetLapsedResets(session, now: now);
|
||||
final unapproved = await forgetUnapprovedSignUps(session, now: now);
|
||||
final figures = await forgetOldAssistantFigures(session, now: now);
|
||||
session.log(
|
||||
'Pruned $pruned anonymous people, $resets lapsed resets, '
|
||||
'$unapproved accounts never approved and $figures days of assistant '
|
||||
'figures.',
|
||||
);
|
||||
}
|
||||
|
||||
/// Forgets the sign-up attempts the rate limit is done with, with their IP
|
||||
/// addresses, the email sign-in codes past their time, the password
|
||||
/// sign-ins never finished and authenticators never confirmed (ADR 0017),
|
||||
/// and the SimpleLogin sign-ins never finished (ADR 0020), and logs how
|
||||
/// many.
|
||||
Future<void> forgetSignUpAttempts(Session session) async {
|
||||
final now = clock.now();
|
||||
final forgotten = await forgetOldSignUpAttempts(session, now: now);
|
||||
final codes = await forgetExpiredEmailCodes(session, now: now);
|
||||
final unfinished = await forgetUnconfirmedAuthenticators(
|
||||
session,
|
||||
now: now,
|
||||
);
|
||||
final simpleLogins = await forgetUnfinishedSimpleLogins(session, now: now);
|
||||
session.log(
|
||||
'Forgot $forgotten sign-up attempts, $codes email codes, '
|
||||
'$unfinished unfinished sign-ins and authenticators and '
|
||||
'$simpleLogins unfinished SimpleLogin sign-ins.',
|
||||
);
|
||||
}
|
||||
|
||||
/// On the register, tells the instance's members again of the accounts
|
||||
/// gone (ADR 0016) and of the accounts whose sessions ended (ADR 0017: a
|
||||
/// password changed or reset) that they haven't confirmed yet, and logs how
|
||||
/// many confirmed.
|
||||
Future<void> tellMembersOfDeletions(Session session) async {
|
||||
final confirmed = await deliverDeletionNotices(session);
|
||||
final ended = await deliverSessionNotices(session);
|
||||
session.log(
|
||||
'Members confirmed $confirmed deleted accounts and $ended accounts '
|
||||
'whose sessions ended.',
|
||||
);
|
||||
}
|
||||
|
||||
/// On a member, deletes the people whose account the register no longer
|
||||
/// knows, and logs how many.
|
||||
Future<void> forgetDeletedAccounts(Session session) async {
|
||||
final forgotten = await forgetPeopleTheRegisterForgot(session);
|
||||
session.log('Deleted $forgotten people the register no longer knows.');
|
||||
}
|
||||
}
|
||||
32
apps/train/halkyon_train_server/lib/src/train_base.dart
Normal file
32
apps/train/halkyon_train_server/lib/src/train_base.dart
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import 'package:halkyon_base_server/base.dart';
|
||||
|
||||
/// Where this project's source is published, which the instance names
|
||||
/// unless its operator sets `SOURCE_URL`. Both licences require offering it
|
||||
/// to the people who use the instance (AGPL-3.0-or-later for the app,
|
||||
/// SSPL-1.0 for the server).
|
||||
const upstreamSourceCodeUrl =
|
||||
'https://code.halkyon.app/project-halkyon/halkyon';
|
||||
|
||||
/// The oldest build of the app this server works with (the number after `+`
|
||||
/// in the app's version); apps below it are asked to update. Raise it in the
|
||||
/// commit that breaks older apps, to the build of the first that works again.
|
||||
const minimumAppBuild = 1;
|
||||
|
||||
/// How Halkyon Train sets halkyon_base up (ADR 0014), the module giving every
|
||||
/// Halkyon server its sign-in, the account and its deletion, the pruning and
|
||||
/// the instance's basics: the instance says it serves `train` (the app accepts
|
||||
/// only such an instance; never change it), sign-in mails name the app, and
|
||||
/// the instance names this project's source. Train keeps nothing of a person's
|
||||
/// yet, so it deletes nothing of its own with them. It holds the instance's
|
||||
/// register, or is a member of the one [accounts] names (ADR 0016; the
|
||||
/// server reads it from the operator's environment, `ACCOUNT_REGISTER_URL`).
|
||||
/// The server sets it up before it starts (`server.dart`), and so do its
|
||||
/// tests.
|
||||
HalkyonBase trainBase({AccountsMode accounts = const HoldsRegister()}) =>
|
||||
HalkyonBase(
|
||||
app: 'train',
|
||||
appName: 'Halkyon Train',
|
||||
upstreamSourceCodeUrl: upstreamSourceCodeUrl,
|
||||
minimumAppBuild: minimumAppBuild,
|
||||
accounts: accounts,
|
||||
);
|
||||
Loading…
Reference in a new issue