Skip to content

Commit d26c01c

Browse files
authored
release(cloud_auth): v0.3.4 (#417)
- fix: Database checks in debug mode - perf: Improve efficiency of several DB operations - chore: Bump Dart SDK constraint to `^3.7.0` - chore: Reformat with Dart 3.7
1 parent c3674a3 commit d26c01c

File tree

66 files changed

+31197
-22293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+31197
-22293
lines changed

services/celest_cloud_auth/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
## NEXT
1+
## 0.3.4
22

33
- fix: Database checks in debug mode
44
- perf: Improve efficiency of several DB operations
5+
- chore: Bump Dart SDK constraint to `^3.7.0`
6+
- chore: Reformat with Dart 3.7
57

68
## 0.3.3
79

services/celest_cloud_auth/example/example.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ Future<void> main() async {
1616
final database = CloudAuthDatabase.memory();
1717
final cloudAuth = await CelestCloudAuth.create(database: database);
1818

19-
final router = Router()
20-
..get('/test/hello', () => Response.ok('Hello, world!'))
21-
..mount('/v1alpha1/auth', cloudAuth.handler);
19+
final router =
20+
Router()
21+
..get('/test/hello', () => Response.ok('Hello, world!'))
22+
..mount('/v1alpha1/auth', cloudAuth.handler);
2223
final handler = const Pipeline()
2324
.addMiddleware(logRequests())
2425
.addMiddleware(cloudAuth.middleware.call)
@@ -37,10 +38,7 @@ final exampleProject = ResolvedProject(
3738
environmentId: 'production',
3839
sdkConfig: SdkConfiguration(
3940
celest: Version(1, 0, 0),
40-
dart: Sdk(
41-
type: SdkType.dart,
42-
version: Version(3, 5, 0),
43-
),
41+
dart: Sdk(type: SdkType.dart, version: Version(3, 5, 0)),
4442
),
4543
apis: {
4644
AuthenticationService.api.apiId: AuthenticationService.api,

services/celest_cloud_auth/lib/celest_cloud_auth.dart

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ export 'package:celest_cloud_auth/src/users/users_service.dart';
2828

2929
/// The Celest authentication and authorization service.
3030
final class CelestCloudAuth {
31-
CelestCloudAuth._({
32-
required this.db,
33-
required this.cryptoKeys,
34-
}) {
31+
CelestCloudAuth._({required this.db, required this.cryptoKeys}) {
3532
celest.context.put(contextKey, this);
3633
}
3734

@@ -77,10 +74,7 @@ final class CelestCloudAuth {
7774
if (emailProvider != null) {
7875
celest.context.put(contextKeyEmailOtpProvider, emailProvider);
7976
}
80-
return CelestCloudAuth._(
81-
db: database,
82-
cryptoKeys: cryptoKeys,
83-
);
77+
return CelestCloudAuth._(db: database, cryptoKeys: cryptoKeys);
8478
}
8579

8680
@visibleForTesting
@@ -93,22 +87,19 @@ final class CelestCloudAuth {
9387
db: db,
9488
rootKey: rootKey,
9589
);
96-
return CelestCloudAuth._(
97-
db: db,
98-
cryptoKeys: cryptoKeys,
99-
);
90+
return CelestCloudAuth._(db: db, cryptoKeys: cryptoKeys);
10091
}
10192

10293
/// An authorization middleware which can be added to a Shelf pipeline.
10394
AuthorizationMiddleware get middleware => AuthorizationMiddleware(
104-
issuer: context.rootEntity,
105-
routeMap: routeMap,
106-
corks: corks,
107-
cryptoKeys: cryptoKeys,
108-
users: users,
109-
db: db,
110-
authorizer: authorizer,
111-
);
95+
issuer: context.rootEntity,
96+
routeMap: routeMap,
97+
corks: corks,
98+
cryptoKeys: cryptoKeys,
99+
users: users,
100+
db: db,
101+
authorizer: authorizer,
102+
);
112103

113104
@visibleForTesting
114105
final CloudAuthDatabaseMixin db;
@@ -124,18 +115,18 @@ final class CelestCloudAuth {
124115

125116
@visibleForTesting
126117
CorksRepository get corks => CorksRepository(
127-
issuer: context.rootEntity,
128-
db: db,
129-
cryptoKeys: cryptoKeys,
130-
);
118+
issuer: context.rootEntity,
119+
db: db,
120+
cryptoKeys: cryptoKeys,
121+
);
131122

132123
@visibleForTesting
133124
SessionsRepository get sessions => SessionsRepository(
134-
corks: corks,
135-
db: db,
136-
cryptoKeys: cryptoKeys,
137-
users: users,
138-
);
125+
corks: corks,
126+
db: db,
127+
cryptoKeys: cryptoKeys,
128+
users: users,
129+
);
139130

140131
@visibleForTesting
141132
UsersRepository get users => UsersRepository(db: db);
@@ -147,16 +138,16 @@ final class CelestCloudAuth {
147138
@visibleForTesting
148139
late final AuthenticationService authenticationService =
149140
AuthenticationService(
150-
issuer: context.rootEntity,
151-
routeMap: routeMap,
152-
otp: otp,
153-
authorizer: authorizer,
154-
corks: corks,
155-
cryptoKeys: cryptoKeys,
156-
db: db,
157-
sessions: sessions,
158-
users: users,
159-
);
141+
issuer: context.rootEntity,
142+
routeMap: routeMap,
143+
otp: otp,
144+
authorizer: authorizer,
145+
corks: corks,
146+
cryptoKeys: cryptoKeys,
147+
db: db,
148+
sessions: sessions,
149+
users: users,
150+
);
160151

161152
@visibleForTesting
162153
late final UsersService usersService = UsersService(
@@ -170,12 +161,13 @@ final class CelestCloudAuth {
170161
);
171162

172163
Handler get handler {
173-
final pipeline =
174-
const Pipeline().addMiddleware(const CloudExceptionMiddleware().call);
175-
final cascade = Cascade(statusCodes: [HttpStatus.notFound])
176-
.add(authenticationService.handler)
177-
.add(usersService.handler)
178-
.handler;
164+
final pipeline = const Pipeline().addMiddleware(
165+
const CloudExceptionMiddleware().call,
166+
);
167+
final cascade =
168+
Cascade(
169+
statusCodes: [HttpStatus.notFound],
170+
).add(authenticationService.handler).add(usersService.handler).handler;
179171
return pipeline.addHandler(cascade);
180172
}
181173

services/celest_cloud_auth/lib/src/authentication/authentication_model.dart

Lines changed: 43 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ sealed class AuthenticationFactor {
1818
AuthenticationFactorEmailOtp.fromProto(proto.emailOtp),
1919
pb.AuthenticationFactor_Factor.smsOtp =>
2020
AuthenticationFactorSmsOtp.fromProto(proto.smsOtp),
21-
final unknown => throw ArgumentError.value(
21+
final unknown =>
22+
throw ArgumentError.value(
2223
unknown,
2324
'factor',
2425
'Invalid AuthenticationFactor. Expected one of: emailOtp, smsOtp',
@@ -27,13 +28,13 @@ sealed class AuthenticationFactor {
2728
}
2829

2930
pb.AuthenticationFactor toProto() => switch (this) {
30-
final AuthenticationFactorEmailOtp emailOtp => pb.AuthenticationFactor(
31-
emailOtp: emailOtp.toValueProto(),
32-
),
33-
final AuthenticationFactorSmsOtp smsOtp => pb.AuthenticationFactor(
34-
smsOtp: smsOtp.toValueProto(),
35-
),
36-
};
31+
final AuthenticationFactorEmailOtp emailOtp => pb.AuthenticationFactor(
32+
emailOtp: emailOtp.toValueProto(),
33+
),
34+
final AuthenticationFactorSmsOtp smsOtp => pb.AuthenticationFactor(
35+
smsOtp: smsOtp.toValueProto(),
36+
),
37+
};
3738

3839
GeneratedMessage toValueProto();
3940

@@ -42,10 +43,7 @@ sealed class AuthenticationFactor {
4243
}
4344

4445
final class AuthenticationFactorEmailOtp extends AuthenticationFactor {
45-
const AuthenticationFactorEmailOtp({
46-
required this.email,
47-
this.code,
48-
});
46+
const AuthenticationFactorEmailOtp({required this.email, this.code});
4947

5048
factory AuthenticationFactorEmailOtp.fromProto(
5149
pb.AuthenticationFactorEmailOtp emailOtp,
@@ -66,17 +64,11 @@ final class AuthenticationFactorEmailOtp extends AuthenticationFactor {
6664

6765
@override
6866
pb.AuthenticationFactorEmailOtp toValueProto() =>
69-
pb.AuthenticationFactorEmailOtp(
70-
email: email,
71-
code: code,
72-
);
67+
pb.AuthenticationFactorEmailOtp(email: email, code: code);
7368
}
7469

7570
final class AuthenticationFactorSmsOtp extends AuthenticationFactor {
76-
const AuthenticationFactorSmsOtp({
77-
required this.phoneNumber,
78-
this.code,
79-
});
71+
const AuthenticationFactorSmsOtp({required this.phoneNumber, this.code});
8072

8173
factory AuthenticationFactorSmsOtp.fromProto(
8274
pb.AuthenticationFactorSmsOtp smsOtp,
@@ -96,10 +88,8 @@ final class AuthenticationFactorSmsOtp extends AuthenticationFactor {
9688
final String? code;
9789

9890
@override
99-
pb.AuthenticationFactorSmsOtp toValueProto() => pb.AuthenticationFactorSmsOtp(
100-
phoneNumber: phoneNumber,
101-
code: code,
102-
);
91+
pb.AuthenticationFactorSmsOtp toValueProto() =>
92+
pb.AuthenticationFactorSmsOtp(phoneNumber: phoneNumber, code: code);
10393
}
10494

10595
final class SessionClient {
@@ -122,20 +112,17 @@ final class SessionClient {
122112
final SessionCallbacks callbacks;
123113

124114
pb.SessionClient toProto() => pb.SessionClient(
125-
clientId: clientId,
126-
clientType: clientType,
127-
callbacks: callbacks.toProto(),
128-
);
115+
clientId: clientId,
116+
clientType: clientType,
117+
callbacks: callbacks.toProto(),
118+
);
129119

130120
@override
131121
String toString() => toProto().toString();
132122
}
133123

134124
final class SessionCallbacks {
135-
const SessionCallbacks({
136-
required this.successUri,
137-
this.errorUri,
138-
});
125+
const SessionCallbacks({required this.successUri, this.errorUri});
139126

140127
factory SessionCallbacks.fromProto(pb.SessionCallbacks callbacks) {
141128
return SessionCallbacks(
@@ -149,9 +136,9 @@ final class SessionCallbacks {
149136
final Uri? errorUri;
150137

151138
pb.SessionCallbacks toProto() => pb.SessionCallbacks(
152-
successUri: successUri.toString(),
153-
errorUri: errorUri?.toString(),
154-
);
139+
successUri: successUri.toString(),
140+
errorUri: errorUri?.toString(),
141+
);
155142

156143
@override
157144
String toString() => toProto().toString();
@@ -196,22 +183,24 @@ final class SessionStateSuccess extends SessionState {
196183

197184
@override
198185
pb.AuthenticationSuccess toProto() => pb.AuthenticationSuccess(
199-
identityToken: cork.toString(),
200-
user: user.toProto(),
201-
isNewUser: isNewUser,
202-
);
186+
identityToken: cork.toString(),
187+
user: user.toProto(),
188+
isNewUser: isNewUser,
189+
);
203190
}
204191

205192
sealed class SessionStateNextStep extends SessionState {
206193
const SessionStateNextStep();
207194

208195
factory SessionStateNextStep.fromProto(pb.AuthenticationStep proto) {
209196
return switch (proto.whichStep()) {
210-
pb.AuthenticationStep_Step.needsProof =>
211-
SessionStateNeedsProof.fromProto(proto.needsProof),
197+
pb.AuthenticationStep_Step.needsProof => SessionStateNeedsProof.fromProto(
198+
proto.needsProof,
199+
),
212200
pb.AuthenticationStep_Step.pendingConfirmation =>
213201
SessionStatePendingConfirmation.fromProto(proto.pendingConfirmation),
214-
final unknown => throw ArgumentError.value(
202+
final unknown =>
203+
throw ArgumentError.value(
215204
unknown,
216205
'step',
217206
'Invalid AuthenticationStep. Expected one of: needsProof, pendingConfirmation',
@@ -221,14 +210,14 @@ sealed class SessionStateNextStep extends SessionState {
221210

222211
@override
223212
pb.AuthenticationStep toProto() => switch (this) {
224-
final SessionStateNeedsProof needsProof => pb.AuthenticationStep(
225-
needsProof: needsProof.toValueProto(),
226-
),
227-
final SessionStatePendingConfirmation pendingConfirmation =>
228-
pb.AuthenticationStep(
229-
pendingConfirmation: pendingConfirmation.toValueProto(),
230-
),
231-
};
213+
final SessionStateNeedsProof needsProof => pb.AuthenticationStep(
214+
needsProof: needsProof.toValueProto(),
215+
),
216+
final SessionStatePendingConfirmation pendingConfirmation =>
217+
pb.AuthenticationStep(
218+
pendingConfirmation: pendingConfirmation.toValueProto(),
219+
),
220+
};
232221

233222
@override
234223
void apply(pb.Session session) {
@@ -237,9 +226,7 @@ sealed class SessionStateNextStep extends SessionState {
237226
}
238227

239228
final class SessionStateNeedsProof extends SessionStateNextStep {
240-
const SessionStateNeedsProof({
241-
required this.factor,
242-
});
229+
const SessionStateNeedsProof({required this.factor});
243230
factory SessionStateNeedsProof.fromProto(pb.AuthenticationFactor proto) {
244231
return SessionStateNeedsProof(
245232
factor: AuthenticationFactor.fromProto(proto),
@@ -291,8 +278,8 @@ final class Session {
291278
this.clientInfo,
292279
this.ipAddress,
293280
this.externalSessionId,
294-
}) : parent = parent ?? context.rootEntity,
295-
sessionId = TypeId<Session>.decode(sessionId);
281+
}) : parent = parent ?? context.rootEntity,
282+
sessionId = TypeId<Session>.decode(sessionId);
296283

297284
const Session._({
298285
required this.parent,
@@ -323,9 +310,7 @@ final class Session {
323310
final String? ipAddress;
324311
final String? externalSessionId;
325312

326-
pb.Session toProto({
327-
String? sessionToken,
328-
}) {
313+
pb.Session toProto({String? sessionToken}) {
329314
final session = pb.Session(
330315
parent: parent?.id,
331316
sessionId: sessionId.encoded,

0 commit comments

Comments
 (0)