Skip to content

Commit 38b100c

Browse files
authored
[google_identity_services_web] Migrate all types to JSObject (#8053)
And cleanup other legacy JS-interop Also update tests so they pass with WebAssembly
1 parent 58d1e6b commit 38b100c

File tree

8 files changed

+50
-117
lines changed

8 files changed

+50
-117
lines changed

packages/google_identity_services_web/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.3.3
2+
3+
* Moves all the JavaScript types to extend `JSObject`.
4+
15
## 0.3.2
26

37
* Adds the `nonce` parameter to `loadWebSdk`.

packages/google_identity_services_web/example/integration_test/js_interop_id_test.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,24 @@ void main() async {
6161
utils.createExpectConfigValue(config as JSObject);
6262

6363
expectConfigValue('client_id', 'testing_1-2-3');
64-
expectConfigValue('auto_select', isFalse);
64+
expectConfigValue('auto_select', false);
6565
expectConfigValue('callback', utils.isAJs('function'));
6666
expectConfigValue('login_uri', 'https://www.example.com/login');
6767
expectConfigValue('native_callback', utils.isAJs('function'));
68-
expectConfigValue('cancel_on_tap_outside', isFalse);
69-
expectConfigValue('allowed_parent_origin', isA<JSArray<JSString>>());
68+
expectConfigValue('cancel_on_tap_outside', false);
69+
expectConfigValue(
70+
'allowed_parent_origin', <String>['allowed', 'another']);
7071
expectConfigValue('prompt_parent_id', 'some_dom_id');
7172
expectConfigValue('nonce', 's0m3_r4ndOM_vALu3');
7273
expectConfigValue('context', 'signin');
7374
expectConfigValue('state_cookie_domain', 'subdomain.example.com');
7475
expectConfigValue('ux_mode', 'popup');
75-
expectConfigValue(
76-
'allowed_parent_origin', <String>['allowed', 'another']);
7776
expectConfigValue(
7877
'intermediate_iframe_close_callback', utils.isAJs('function'));
79-
expectConfigValue('itp_support', isTrue);
78+
expectConfigValue('itp_support', true);
8079
expectConfigValue('login_hint', 'login-hint@example.com');
8180
expectConfigValue('hd', 'hd_value');
82-
expectConfigValue('use_fedcm_for_prompt', isTrue);
81+
expectConfigValue('use_fedcm_for_prompt', true);
8382
});
8483
});
8584

packages/google_identity_services_web/example/integration_test/js_interop_oauth_test.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ void main() async {
4343
expectConfigValue('client_id', 'testing_1-2-3');
4444
expectConfigValue('callback', utils.isAJs('function'));
4545
expectConfigValue('scope', 'one two three');
46-
expectConfigValue('include_granted_scopes', isTrue);
46+
expectConfigValue('include_granted_scopes', true);
4747
expectConfigValue('prompt', 'some-prompt');
48-
expectConfigValue('enable_granular_consent', isTrue);
48+
expectConfigValue('enable_granular_consent', true);
4949
expectConfigValue('login_hint', 'login-hint@example.com');
5050
expectConfigValue('hd', 'hd_value');
5151
expectConfigValue('state', 'some-state');
@@ -66,9 +66,9 @@ void main() async {
6666
utils.createExpectConfigValue(config as JSObject);
6767

6868
expectConfigValue('scope', 'one two three');
69-
expectConfigValue('include_granted_scopes', isTrue);
69+
expectConfigValue('include_granted_scopes', true);
7070
expectConfigValue('prompt', 'some-prompt');
71-
expectConfigValue('enable_granular_consent', isTrue);
71+
expectConfigValue('enable_granular_consent', true);
7272
expectConfigValue('login_hint', 'login-hint@example.com');
7373
expectConfigValue('state', 'some-state');
7474
});
@@ -93,15 +93,15 @@ void main() async {
9393
utils.createExpectConfigValue(config as JSObject);
9494

9595
expectConfigValue('scope', 'one two three');
96-
expectConfigValue('include_granted_scopes', isTrue);
96+
expectConfigValue('include_granted_scopes', true);
9797
expectConfigValue('redirect_uri', 'https://www.example.com/login');
9898
expectConfigValue('callback', utils.isAJs('function'));
9999
expectConfigValue('state', 'some-state');
100-
expectConfigValue('enable_granular_consent', isTrue);
100+
expectConfigValue('enable_granular_consent', true);
101101
expectConfigValue('login_hint', 'login-hint@example.com');
102102
expectConfigValue('hd', 'hd_value');
103103
expectConfigValue('ux_mode', 'popup');
104-
expectConfigValue('select_account', isTrue);
104+
expectConfigValue('select_account', true);
105105
expectConfigValue('error_callback', utils.isAJs('function'));
106106
});
107107
});

packages/google_identity_services_web/example/integration_test/utils.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ typedef ExpectConfigValueFn = void Function(String name, Object? matcher);
2323
/// Creates a [ExpectConfigValueFn] for the `config` [JSObject].
2424
ExpectConfigValueFn createExpectConfigValue(JSObject config) {
2525
return (String name, Object? matcher) {
26+
if (matcher is String) {
27+
matcher = matcher.toJS;
28+
} else if (matcher is bool) {
29+
matcher = matcher.toJS;
30+
} else if (matcher is List) {
31+
final List<Object?> old = matcher;
32+
matcher = isA<JSAny?>().having(
33+
(JSAny? p0) => (p0 as JSArray<JSAny>?)
34+
?.toDart
35+
.map((JSAny? e) => e.dartify())
36+
.toList(),
37+
'Array with matching values',
38+
old);
39+
}
2640
expect(config[name], matcher, reason: name);
2741
};
2842
}

packages/google_identity_services_web/lib/src/js_interop/google_accounts_id.dart

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ import 'shared.dart';
2020
external GoogleAccountsId get id;
2121

2222
/// The Dart definition of the `google.accounts.id` global.
23-
@JS()
24-
@staticInterop
25-
abstract class GoogleAccountsId {}
26-
27-
/// The `google.accounts.id` methods
28-
extension GoogleAccountsIdExtension on GoogleAccountsId {
23+
extension type GoogleAccountsId._(JSObject _) implements JSObject {
2924
/// An undocumented method.
3025
///
3126
/// Try it with 'debug'.
@@ -186,10 +181,7 @@ extension GoogleAccountsIdExtension on GoogleAccountsId {
186181
///
187182
/// Data type: IdConfiguration
188183
/// https://developers.google.com/identity/gsi/web/reference/js-reference#IdConfiguration
189-
@JS()
190-
@anonymous
191-
@staticInterop
192-
abstract class IdConfiguration {
184+
extension type IdConfiguration._(JSObject _) implements JSObject {
193185
/// Constructs a IdConfiguration object in JavaScript.
194186
factory IdConfiguration({
195187
/// Your application's client ID, which is found and created in the Google
@@ -355,12 +347,7 @@ typedef PromptMomentListenerFn = void Function(PromptMomentNotification moment);
355347
///
356348
/// Data type: PromptMomentNotification
357349
/// https://developers.google.com/identity/gsi/web/reference/js-reference#PromptMomentNotification
358-
@JS()
359-
@staticInterop
360-
abstract class PromptMomentNotification {}
361-
362-
/// The methods of the [PromptMomentNotification] data type:
363-
extension PromptMomentNotificationExtension on PromptMomentNotification {
350+
extension type PromptMomentNotification._(JSObject _) implements JSObject {
364351
/// Is this notification for a display moment?
365352
bool isDisplayMoment() => _isDisplayMoment().toDart;
366353
@JS('isDisplayMoment')
@@ -415,12 +402,7 @@ extension PromptMomentNotificationExtension on PromptMomentNotification {
415402
///
416403
/// Data type: CredentialResponse
417404
/// https://developers.google.com/identity/gsi/web/reference/js-reference#CredentialResponse
418-
@JS()
419-
@staticInterop
420-
abstract class CredentialResponse {}
421-
422-
/// The fields that are contained in the credential response object.
423-
extension CredentialResponseExtension on CredentialResponse {
405+
extension type CredentialResponse._(JSObject _) implements JSObject {
424406
/// The ClientID for this Credential.
425407
String? get client_id => _client_id?.toDart;
426408
@JS('client_id')
@@ -469,10 +451,7 @@ typedef CallbackFn = void Function(CredentialResponse credentialResponse);
469451
///
470452
/// Data type: GsiButtonConfiguration
471453
/// https://developers.google.com/identity/gsi/web/reference/js-reference#GsiButtonConfiguration
472-
@JS()
473-
@anonymous
474-
@staticInterop
475-
abstract class GsiButtonConfiguration {
454+
extension type GsiButtonConfiguration._(JSObject _) implements JSObject {
476455
/// Constructs an options object for the [renderButton] method.
477456
factory GsiButtonConfiguration({
478457
/// The button type.
@@ -535,12 +514,7 @@ abstract class GsiButtonConfiguration {
535514
}
536515

537516
/// The object passed as an optional parameter to `click_listener` function.
538-
@JS()
539-
@staticInterop
540-
abstract class GsiButtonData {}
541-
542-
/// The fields that are contained in the button data.
543-
extension GsiButtonDataExtension on GsiButtonData {
517+
extension type GsiButtonData._(JSObject _) implements JSObject {
544518
/// Nonce
545519
String? get nonce => _nonce?.toDart;
546520
@JS('nonce')
@@ -565,10 +539,7 @@ typedef GsiButtonClickListenerFn = void Function(GsiButtonData? gsiButtonData);
565539
///
566540
/// Data type: Credential
567541
/// https://developers.google.com/identity/gsi/web/reference/js-reference#type-Credential
568-
@JS()
569-
@anonymous
570-
@staticInterop
571-
abstract class Credential {
542+
extension type Credential._(JSObject _) implements JSObject {
572543
///
573544
factory Credential({
574545
required String id,
@@ -620,12 +591,7 @@ typedef RevocationResponseHandlerFn = void Function(
620591
///
621592
/// Data type: RevocationResponse
622593
/// https://developers.google.com/identity/gsi/web/reference/js-reference#RevocationResponse
623-
@JS()
624-
@staticInterop
625-
abstract class RevocationResponse {}
626-
627-
/// The fields that are contained in the [RevocationResponse] object.
628-
extension RevocationResponseExtension on RevocationResponse {
594+
extension type RevocationResponse._(JSObject _) implements JSObject {
629595
/// This field is a boolean value set to true if the revoke method call
630596
/// succeeded or false on failure.
631597
bool get successful => _successful.toDart;

packages/google_identity_services_web/lib/src/js_interop/google_accounts_oauth2.dart

Lines changed: 10 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
// * non_constant_identifier_names required to be able to use the same parameter
1010
// names as the underlying library.
1111

12-
@JS()
13-
library google_accounts_oauth2;
14-
1512
import 'dart:js_interop';
1613

1714
import 'shared.dart';
@@ -23,12 +20,7 @@ import 'shared.dart';
2320
external GoogleAccountsOauth2 get oauth2;
2421

2522
/// The Dart definition of the `google.accounts.oauth2` global.
26-
@JS()
27-
@staticInterop
28-
abstract class GoogleAccountsOauth2 {}
29-
30-
/// The `google.accounts.oauth2` methods
31-
extension GoogleAccountsOauth2Extension on GoogleAccountsOauth2 {
23+
extension type GoogleAccountsOauth2._(JSObject _) implements JSObject {
3224
/// Initializes and returns a code client, with the passed-in [config].
3325
///
3426
/// Method: google.accounts.oauth2.initCodeClient
@@ -97,10 +89,7 @@ extension GoogleAccountsOauth2Extension on GoogleAccountsOauth2 {
9789
///
9890
/// Data type: CodeClientConfig
9991
/// https://developers.google.com/identity/oauth2/web/reference/js-reference#CodeClientConfig
100-
@JS()
101-
@anonymous
102-
@staticInterop
103-
abstract class CodeClientConfig {
92+
extension type CodeClientConfig._(JSObject _) implements JSObject {
10493
/// Constructs a CodeClientConfig object in JavaScript.
10594
///
10695
/// The [callback] property must be a Dart function and not a JS function.
@@ -161,12 +150,7 @@ abstract class CodeClientConfig {
161150
///
162151
/// Data type: CodeClient
163152
/// https://developers.google.com/identity/oauth2/web/reference/js-reference#CodeClient
164-
@JS()
165-
@staticInterop
166-
abstract class CodeClient {}
167-
168-
/// The methods available on the [CodeClient].
169-
extension CodeClientExtension on CodeClient {
153+
extension type CodeClient._(JSObject _) implements JSObject {
170154
/// Starts the OAuth 2.0 Code UX flow.
171155
external void requestCode();
172156
}
@@ -175,12 +159,7 @@ extension CodeClientExtension on CodeClient {
175159
///
176160
/// Data type: CodeResponse
177161
/// https://developers.google.com/identity/oauth2/web/reference/js-reference#CodeResponse
178-
@JS()
179-
@staticInterop
180-
abstract class CodeResponse {}
181-
182-
/// The fields that are contained in the code response object.
183-
extension CodeResponseExtension on CodeResponse {
162+
extension type CodeResponse._(JSObject _) implements JSObject {
184163
/// The authorization code of a successful token response.
185164
String? get code => _code?.toDart;
186165
@JS('code')
@@ -223,10 +202,7 @@ typedef CodeClientCallbackFn = void Function(CodeResponse response);
223202
///
224203
/// Data type: TokenClientConfig
225204
/// https://developers.google.com/identity/oauth2/web/reference/js-reference#TokenClientConfig
226-
@JS()
227-
@anonymous
228-
@staticInterop
229-
abstract class TokenClientConfig {
205+
extension type TokenClientConfig._(JSObject _) implements JSObject {
230206
/// Constructs a TokenClientConfig object in JavaScript.
231207
///
232208
/// The [callback] property must be a Dart function and not a JS function.
@@ -281,12 +257,7 @@ abstract class TokenClientConfig {
281257
///
282258
/// Data type: TokenClient
283259
/// https://developers.google.com/identity/oauth2/web/reference/js-reference#TokenClient
284-
@JS()
285-
@staticInterop
286-
abstract class TokenClient {}
287-
288-
/// The methods available on the [TokenClient].
289-
extension TokenClientExtension on TokenClient {
260+
extension type TokenClient._(JSObject _) implements JSObject {
290261
/// Starts the OAuth 2.0 Code UX flow.
291262
void requestAccessToken([
292263
OverridableTokenClientConfig? overrideConfig,
@@ -308,10 +279,7 @@ extension TokenClientExtension on TokenClient {
308279
///
309280
/// Data type: OverridableTokenClientConfig
310281
/// https://developers.google.com/identity/oauth2/web/reference/js-reference#OverridableTokenClientConfig
311-
@JS()
312-
@anonymous
313-
@staticInterop
314-
abstract class OverridableTokenClientConfig {
282+
extension type OverridableTokenClientConfig._(JSObject _) implements JSObject {
315283
/// Constructs an OverridableTokenClientConfig object in JavaScript.
316284
factory OverridableTokenClientConfig({
317285
/// A list of scopes that identify the resources that your application could
@@ -396,12 +364,7 @@ abstract class OverridableTokenClientConfig {
396364
///
397365
/// Data type: TokenResponse
398366
/// https://developers.google.com/identity/oauth2/web/reference/js-reference#TokenResponse
399-
@JS()
400-
@staticInterop
401-
abstract class TokenResponse {}
402-
403-
/// The fields that are contained in the code response object.
404-
extension TokenResponseExtension on TokenResponse {
367+
extension type TokenResponse._(JSObject _) implements JSObject {
405368
/// The access token of a successful token response.
406369
String? get access_token => _access_token?.toDart;
407370
@JS('access_token')
@@ -465,12 +428,7 @@ typedef TokenClientCallbackFn = void Function(TokenResponse response);
465428
typedef ErrorCallbackFn = void Function(GoogleIdentityServicesError? error);
466429

467430
/// An error returned by `initTokenClient` or `initDataClient`.
468-
@JS()
469-
@staticInterop
470-
abstract class GoogleIdentityServicesError {}
471-
472-
/// Methods of the GoogleIdentityServicesError object.
473-
extension GoogleIdentityServicesErrorExtension on GoogleIdentityServicesError {
431+
extension type GoogleIdentityServicesError._(JSObject _) implements JSObject {
474432
/// The type of error
475433
GoogleIdentityServicesErrorType get type =>
476434
GoogleIdentityServicesErrorType.values.byName(_type.toDart);
@@ -492,12 +450,7 @@ typedef RevokeTokenDoneFn = void Function(TokenRevocationResponse response);
492450
///
493451
/// Data type: RevocationResponse
494452
/// https://developers.google.com/identity/oauth2/web/reference/js-reference#TokenResponse
495-
@JS()
496-
@staticInterop
497-
abstract class TokenRevocationResponse {}
498-
499-
/// The fields that are contained in the [TokenRevocationResponse] object.
500-
extension TokenRevocationResponseExtension on TokenRevocationResponse {
453+
extension type TokenRevocationResponse._(JSObject _) implements JSObject {
501454
/// This field is a boolean value set to true if the revoke method call
502455
/// succeeded or false on failure.
503456
bool get successful => _successful.toDart;

packages/google_identity_services_web/lib/src/js_interop/load_callback.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// Methods here are documented in the Google Identity authentication website,
66
// but they don't really belong to either the authentication nor authorization
77
// libraries.
8-
@JS()
9-
library id_load_callback;
108

119
import 'dart:js_interop';
1210

@@ -18,7 +16,6 @@ import 'shared.dart';
1816
*/
1917

2018
@JS('onGoogleLibraryLoad')
21-
@staticInterop
2219
external set _onGoogleLibraryLoad(JSFunction callback);
2320

2421
/// Method called after the Sign In With Google JavaScript library is loaded.

packages/google_identity_services_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: google_identity_services_web
22
description: A Dart JS-interop layer for Google Identity Services. Google's new sign-in SDK for Web that supports multiple types of credentials.
33
repository: https://github.com/flutter/packages/tree/main/packages/google_identity_services_web
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_identiy_services_web%22
5-
version: 0.3.2
5+
version: 0.3.3
66

77
environment:
88
sdk: ^3.4.0

0 commit comments

Comments
 (0)