Skip to content

Commit 93686e9

Browse files
committed
convert reset password response & arguments to extension types
1 parent deb5f2a commit 93686e9

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
import 'package:js/js.dart';
1+
import 'dart:js_interop';
22

3-
/// This class represents the parameters for the `Accounts.resetPassword` method.
3+
/// This extension type represents the parameters for the `Accounts.resetPassword` method.
44
@JS()
55
@anonymous
66
@staticInterop
7-
class ResetPasswordParameters {
7+
extension type ResetPasswordParameters._(JSObject _) implements JSObject {
88
/// Create a new [ResetPasswordParameters] instance.
99
external factory ResetPasswordParameters({
1010
String? email,
11-
bool ignoreInterruptions,
11+
bool? ignoreInterruptions,
1212
String? lang,
1313
String? loginID,
1414
String? newPassword,
1515
String? passwordResetToken,
1616
String? secretAnswer,
1717
String? securityFields,
18+
// TODO: this parameter is not documented in the list at
19+
// https://help.sap.com/docs/SAP_CUSTOMER_DATA_CLOUD/8b8d6fffe113457094a17701f63e3d6a/c21d4e0445b84a779af1ad4868902c21.html#parameters
20+
bool? sendEmail,
1821
});
1922
}
Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,27 @@
11
import 'dart:js_interop';
22

3+
import '../models/emails.dart';
34
import 'response.dart';
45

5-
// TODO: fix the extension type
6-
// - String? time
7-
// - Emails? emails
8-
// - String? UID -> fix the JS annotation
9-
10-
/// The static interop class for the Gigya Reset Password API response.
6+
/// The extension type for the Gigya Reset Password API response.
117
///
128
/// See also: https://help.sap.com/docs/SAP_CUSTOMER_DATA_CLOUD/8b8d6fffe113457094a17701f63e3d6a/c21d4e0445b84a779af1ad4868902c21.html#response-data
139
@JS()
1410
@anonymous
1511
@staticInterop
16-
class ResetPasswordResponse extends Response {}
17-
18-
/// This extension defines the static interop definition
19-
/// for the [ResetPasswordResponse] class.
20-
extension ResetPasswordResponseExtension on ResetPasswordResponse {
21-
@JS('emails')
22-
external Object? get _emails;
23-
12+
extension type ResetPasswordResponse(Response baseResponse) {
2413
/// The email addresses belonging to the user.
25-
Map<String, dynamic> get emails {
26-
if (_emails.isUndefinedOrNull) {
27-
return const <String, dynamic>{};
28-
}
29-
30-
return (dartify(_emails) as Map<Object?, Object?>).cast<String, dynamic>();
31-
}
14+
external Emails? get emails;
3215

3316
/// The token that should be used for the password reset in the password reset email.
3417
///
35-
/// This is null if the email is sent by the Gigya SDK.
18+
/// This is null if `ResetPasswordParameters.sendEmail` was `false`.
3619
external String? get passwordResetToken;
3720

21+
/// The time of the response, in ISO 8601 format,
22+
/// i.e. 2021-02-06T22:05:47.706Z.
23+
external String? get time;
24+
3825
/// The secret question for the password reset.
3926
///
4027
/// This is null if there is no security verification failure.
@@ -43,6 +30,16 @@ extension ResetPasswordResponseExtension on ResetPasswordResponse {
4330
/// The UID of the user whose password was changed.
4431
///
4532
/// This is null if the password was not changed yet.
46-
@JS('UID')
47-
external String? get uid;
33+
external String? get UID; // ignore: non_constant_identifier_names
34+
35+
/// Convert this response to a [Map].
36+
Map<String, dynamic> toMap() {
37+
return <String, dynamic>{
38+
'emails': emails?.toMap(),
39+
'passwordResetToken': passwordResetToken,
40+
'time': time,
41+
'secretQuestion': secretQuestion,
42+
'UID': UID,
43+
};
44+
}
4845
}

0 commit comments

Comments
 (0)