Skip to content

Web Support #44

Open
Open
@navaronbracke

Description

@navaronbracke

The extension types language feature is scheduled to ship in Dart 3.3, which is the next stable release for Q1 2024. This is currently available on the Flutter beta channel.

The Gigya SDK provides a web implementation as defined here

Proposal

Add support to the gigya_flutter_plugin using this API so that the plugin also works on the web.
Preferably this is done using Dart's JavaScript interop, which is the new way of implementing web specific functionality for plugins.

Methods

Services

  • InterruptionResolverFactory
  • OtpService
  • WebAuthenticationService

Other

  • use the new package:web instead of dart:html for accessing the window and such
    • Bump package:web to version 0.5.0
  • fixup the stub for Promise, which should have been a JSPromise from dart:js_interop
  • fix the generic type for JSArray / JSPromise (fix has landed upstream in the Dart SDK)
  • audit any missing thisArg arguments for callAsFunction() invocations (otherwise we'll run into type errors)
  • Add missing const to empty list literals, const <Foo>[]
  • Migrate existing bindings to extension types
    • We can also get rid of the helper class for the Response interop layer for our use case. The new extension types have access to the representation type. Thus we can have the 'overridden' methods redeclared, using the supertype for implementation purposes.
  • Migrate to using the explicit Javascript types (JSObject, JSFunction, JSPromise once the interop API is further along) Primitive types are still allowed (int, double, null, bool, String) See https://github.com/dart-lang/sdk/blob/main/sdk/lib/js_interop/js_interop.dart
  • Audit uses of // ignore_for_line / // ignore_for_file (There are 4~ uses, but these are needed to keep API variable names)
  • Audit whether the web implementation forwards the error details (errorCode, errorMessage, errorDetails) to GigyaError()
  • Remove exports in web/static_interop/response.dart
  • Remove the WebErrorCode enum (it only has one usage in the Dart implementation of the Web SDK, which is not what I expected it to have. Keeping it around probably is not worth it)
  • Run dart format on the web implementation sources (the formatter doesn't yet support extension types)
  • Replace dart:js_util, package:js, and dart:js imports with dart:js_interop and dart:js_interop_unsafe, as the former is now unsupported in dart2wasm
  • Replace uses of allowInterop(Function) with Function.toJS, as the latter is what the web compilers do for the Function type
  • Remove the redundant @staticInterop and @anonymous annotations, these are not needed for extension types

Nice to have

  • WASM support (see also the upcoming kIsWasm constant)
  • Fix the manual is checks for JS types. On the JS backends (dart2js, DDC, dart2wasm) these checks will always succeed due to an implementation detail. Instead we should use the new isA<T extends JSAny>() function from dart:js_interop. This new function is only available in Dart 3.4, so it will have to wait a little.
  • Support dynamically structured JS objects in the interop layer, using dartify()/ jsify() interop API's
    • context parameter
    • data parameter for get/set accountInfo
    • customButtons parameter (showScreenset)
    • customLang parameter (showScreenset)
    • Support global configuration, as defined here: https://help.sap.com/docs/SAP_CUSTOMER_DATA_CLOUD/8b8d6fffe113457094a17701f63e3d6a/415942c570b21014bbc5a10ce4041860.html
      • I think just documenting how to do this yourself is the better option, since initSdk() manually loads the Gigya script on-demand, which prevents uers from including the global config there. We should just tell users to add a <script> tag in the <head> of their index.html, which initializes window.__gigyaConf. We could also add a Dart API to set the configuration, but in my opinion this is not worth the effort.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions