Skip to content

Feature/wasm support aws common #6140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 38 commits into
base: feature/wasm_support
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
3cb77d6
Migrated Sigv4 Example Project
tyllark Apr 28, 2025
07a9516
Migrate Amplify DB Common Dart
tyllark Apr 28, 2025
939a198
Migrate Example Common
tyllark Apr 28, 2025
6b7f0d8
Migrated Amplify Storage S3 Dart
tyllark Apr 28, 2025
ca8bb92
Migrated Amplify Storage S3 Dart Example Project
tyllark Apr 28, 2025
7992b1a
Migrated Amplify Auth Cognito Dart
tyllark Apr 28, 2025
308c463
Migrated Amplify Auth Cognito Dart Example Project
tyllark Apr 28, 2025
d62c288
Migrated Amplify Core
tyllark Apr 28, 2025
85e3274
Migrated Actions
tyllark Apr 28, 2025
d2a8415
Migrated Worker Bee E2E
tyllark Apr 28, 2025
963fd63
Migrated Worker Bee
tyllark Apr 28, 2025
44d7055
Migrated Template
tyllark Apr 28, 2025
95d8188
Pinned analyzer to 7.3.X
tyllark Apr 29, 2025
1108c94
Fixed Sigv4 Analyzer errors
tyllark Apr 29, 2025
a9e3aa2
Migrated aws_common
tyllark May 2, 2025
dddac4d
Migrated worker_bee
tyllark May 2, 2025
96aaec1
Migrated amplify_analytics_pinpoint_dart
tyllark May 2, 2025
98e68cc
Migrated amplify_secure_storage_dart
tyllark May 3, 2025
ee9cba5
Fixed compile time errors
tyllark May 3, 2025
8ed8306
Fixed compiler errors
tyllark May 3, 2025
cd4edb0
fixed compiler errors
tyllark May 3, 2025
3ff6f62
Migrated amplify_auth_cognito_dart
tyllark May 5, 2025
0826b04
fixed compiler errors
tyllark May 5, 2025
7f194d2
fixed compiler errors
tyllark May 5, 2025
e1680a5
fixed compiler errors
tyllark May 7, 2025
93c2d86
Migrated amplify_storage_s3 Example app
tyllark May 8, 2025
4d29a95
Removed extra IDBObjectStore parameters
tyllark May 8, 2025
17c8779
Fixed JS/Dart serialization for WebWorkers
tyllark May 8, 2025
ffbb6c4
chore(): fixed formatting errors
tyllark May 8, 2025
ace6766
chore(analytics): re-added value property instead of using a JSString
tyllark May 9, 2025
509e057
chore(): cleaned up header converting as jsify does not convert properly
tyllark May 9, 2025
b3a1061
chore(): fixed typo
tyllark May 10, 2025
9ef4cef
chore(): fixed formatting
tyllark May 10, 2025
b317734
Chore() updated HTTP Method to be upercase
tyllark May 13, 2025
36eaa2a
chore(): removed unused functions.
tyllark May 13, 2025
8b9ebfa
chore(test): added emailmfa attribute to first user sign up in test (…
ekjotmultani May 14, 2025
2ff5cdf
Merge branch 'feature/wasm_support' into feature/wasm_support_web_mig…
tyllark May 15, 2025
00e9aa7
Merge branch 'feature/wasm_support_web_migration' into feature/wasm_s…
tyllark May 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions actions/lib/src/node/actions/exec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import 'dart:convert';
import 'dart:js_interop';
//ignore: deprecated_member_use
import 'dart:js_util';

@JS()
external Exec get exec;
Expand Down Expand Up @@ -46,9 +44,14 @@ extension type Exec._(JSObject it) {
ignoreReturnCode: !failOnNonZeroExit,
);
try {
final exitCode = await promiseToFuture<int>(
_exec(commandLine, args.map((arg) => arg.toJS).toList().toJS, options),
);
final jsExitCode =
await _exec(
commandLine,
args.map((arg) => arg.toJS).toList().toJS,
options,
).toDart;

final exitCode = (jsExitCode as JSNumber).toDartInt;
return ExecResult(
exitCode: exitCode,
stdout: stdout.toString(),
Expand Down
8 changes: 7 additions & 1 deletion actions/lib/src/node/actions/http_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import 'dart:js_interop';

import 'package:web/web.dart';

@JS()
extension type HttpClient._(JSObject it) {
external HttpClient([
Expand All @@ -18,7 +20,11 @@ extension type HttpClient._(JSObject it) {
String requestUrl, {
Map<String, String> headers = const {},
}) async {
final jsHeaders = headers.jsify() as JSObject;
final jsHeaders = Headers();
for(final entry in headers.entries) {
jsHeaders.append(entry.key, entry.value);
}

final response = await _getJson(requestUrl, jsHeaders).toDart;
final result = response as TypedResponse<JSObject>;
if (result.statusCode != 200) {
Expand Down
1 change: 1 addition & 0 deletions actions/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies:
source_maps: ^0.10.12
stack_trace: ^1.10.0
stream_transform: ^2.1.0
web: ^1.1.1

dev_dependencies:
amplify_lints: ^3.0.0
Expand Down
3 changes: 1 addition & 2 deletions packages/amplify_core/lib/src/platform/platform_html.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

//ignore: deprecated_member_use
import 'dart:html';
import 'package:web/web.dart';

final RegExp _edgeRegex = RegExp(r'Edg/[\d\.]+');
final RegExp _operaRegex = RegExp(r'OPR/[\d\.]+');
Expand Down
1 change: 1 addition & 0 deletions packages/amplify_core/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies:
retry: ^3.1.0
stack_trace: ^1.10.0
uuid: ">=3.0.6 <5.0.0"
web: ^1.1.1

dev_dependencies:
amplify_lints: ">=3.1.1 <3.2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// SPDX-License-Identifier: Apache-2.0

import 'dart:async';
//ignore: deprecated_member_use
import 'dart:js_util';
import 'dart:js_interop';
import 'dart:js_interop_unsafe';

import 'package:amplify_analytics_pinpoint_dart/src/impl/analytics_client/event_client/queued_item_store/queued_item_store.dart';
import 'package:amplify_core/amplify_core.dart';
// ignore: implementation_imports
import 'package:aws_common/src/js/indexed_db.dart';
import 'package:collection/collection.dart';
import 'package:web/web.dart';

// TODO(kylechen): Consider merging/refactoring with existing 'amplify_secure_storage_web - _IndexedDBStorage' class
/// {@template amplify_analytics_pinpoint_dart.indexed_db_adapter}
Expand Down Expand Up @@ -39,36 +40,43 @@ class IndexedDbAdapter implements QueuedItemStore {
if (db == null) {
throw const InvalidStateException('IndexedDB is not available');
}
void onUpgradeNeeded(IDBVersionChangeEvent event) {
final database = event.target?.getProperty<IDBDatabase>('result'.toJS);
final objectStoreNames = database?.objectStoreNames;
if (!(objectStoreNames?.contains(storeName) ?? false)) {
database?.createObjectStore(
storeName,
IDBObjectStoreParameters(keyPath: 'id'.toJS, autoIncrement: true),
);
}
}

final openRequest = db.open(databaseName, 1)
..onupgradeneeded = (event) {
final database = event.target.result;
final objectStoreNames = database.objectStoreNames;
if (!objectStoreNames.contains(storeName)) {
database.createObjectStore(
storeName,
keyPath: 'id',
autoIncrement: true,
);
}
};
_database = await openRequest.future;
..onupgradeneeded = onUpgradeNeeded.toJS;

final result = await openRequest.future;
if (result.isA<IDBDatabase>()) {
result as IDBDatabase;
_database = result;
} else {
throw const InvalidStateException('IDBOpenDBRequest failed');
}
}

/// Returns a new [IDBObjectStore] instance after waiting for initialization
/// to complete.
IDBObjectStore _getObjectStore() {
final transaction = _database.transaction(
storeName,
mode: IDBTransactionMode.readwrite,
);
final transaction = _database.transaction(storeName.toJS, 'readwrite');
final store = transaction.objectStore(storeName);
return store;
}

@override
Future<void> addItem(String string) async {
await _databaseOpenEvent;
await _getObjectStore().push({'value': string}).future;
final item = JSObject()..setProperty('value'.toJS, string.toJS);

await _getObjectStore().add(item).future;
}

@override
Expand All @@ -77,14 +85,26 @@ class IndexedDbAdapter implements QueuedItemStore {

await _databaseOpenEvent;
final store = _getObjectStore();
final request = store.getAll(null, count);

late IDBRequest request;
if (count == null) {
request = store.getAll();
} else {
request = store.getAll(null, count);
}

await request.future;
final jsResult = request.result;
var result = <JSObject>[];
if (jsResult.isA<JSArray<JSObject>>()) {
jsResult as JSArray<JSObject>;
result = jsResult.toDart;
}

for (final elem in result) {
final id = elem.getProperty<JSNumber>('id'.toJS).toDartInt;
final string = elem.getProperty<JSString>('value'.toJS).toDart;

for (final elem in request.result) {
final value = elem as Object;
final id = getProperty<int>(value, 'id');
final string = getProperty<String>(value, 'value');
readValues.add(QueuedItem(id: id, value: string));
}
return readValues;
Expand All @@ -101,10 +121,8 @@ class IndexedDbAdapter implements QueuedItemStore {

final ranges = idsToDelete
.splitBetween((a, b) => b != a + 1)
.map((range) => IDBKeyRange.bound(range.first, range.last));
await Future.wait<void>(
ranges.map((range) => store.deleteByKeyRange(range).future),
);
.map((range) => IDBKeyRange.bound(range.first.toJS, range.last.toJS));
await Future.wait<void>(ranges.map((range) => store.delete(range).future));
}

/// Clear the database.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies:
smithy: ">=0.7.4 <0.8.0"
smithy_aws: ">=0.7.4 <0.8.0"
uuid: ">=3.0.6 <5.0.0"
web: ^1.1.1

dev_dependencies:
amplify_lints: ">=3.1.1 <3.2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void main() {
username: username,
password: password,
);

check(
resignInRes.nextStep.signInStep,
).equals(AuthSignInStep.confirmSignInWithOtpCode);
Expand Down Expand Up @@ -99,9 +100,18 @@ void main() {
username: username,
password: password,
);

check(
signInRes.nextStep.signInStep,
because: 'MFA is required so Cognito automatically enables SMS MFA',
because: 'MFA is required so Cognito will ask for MFA type',
).equals(AuthSignInStep.continueSignInWithMfaSelection);

final selectMfaRes = await Amplify.Auth.confirmSignIn(
confirmationValue: 'SMS',
);

check(
selectMfaRes.nextStep.signInStep,
).equals(AuthSignInStep.confirmSignInWithSmsMfaCode);

final confirmRes = await Amplify.Auth.confirmSignIn(
Expand Down Expand Up @@ -215,9 +225,18 @@ void main() {
username: username,
password: password,
);

check(
signInRes.nextStep.signInStep,
because: 'MFA is required so Cognito automatically enables SMS MFA',
because: 'MFA is required so Cognito prompts MFA type selection',
).equals(AuthSignInStep.continueSignInWithMfaSelection);

final selectMfaRes = await Amplify.Auth.confirmSignIn(
confirmationValue: 'SMS',
);

check(
selectMfaRes.nextStep.signInStep,
).equals(AuthSignInStep.confirmSignInWithSmsMfaCode);

final confirmRes = await Amplify.Auth.confirmSignIn(
Expand All @@ -227,44 +246,15 @@ void main() {

check(
await cognitoPlugin.fetchMfaPreference(),
because: 'MFA is required so Cognito automatically enables SMS MFA',
because:
'SMS MFA has been selected so Cognito fetches SMS as preferred',
).equals(
const UserMfaPreference(
enabled: {MfaType.sms},
preferred: MfaType.sms,
),
);

// Verify we can set SMS as preferred and forego selection.

{
await signOutUser(assertComplete: true);

final mfaCode = await getOtpCode(UserAttribute.phone(phoneNumber));
final signInRes = await Amplify.Auth.signIn(
username: username,
password: password,
);
check(
signInRes.nextStep.signInStep,
because: 'Preference is SMS MFA now',
).equals(AuthSignInStep.confirmSignInWithSmsMfaCode);
check(signInRes.nextStep.codeDeliveryDetails).isNotNull()
..has(
(d) => d.deliveryMedium,
'deliveryMedium',
).equals(DeliveryMedium.sms)
..has(
(d) => d.destination,
'destination',
).isNotNull().startsWith('+');

final confirmRes = await Amplify.Auth.confirmSignIn(
confirmationValue: await mfaCode.code,
);
check(confirmRes.nextStep.signInStep).equals(AuthSignInStep.done);
}

// Verify we can switch to EMAIL as preferred.

await cognitoPlugin.updateMfaPreference(email: MfaPreference.preferred);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies:
example_common:
path: ../../../example_common
qr: ^3.0.1
web: ^1.1.1

dev_dependencies:
amplify_api_dart: any
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

//ignore: deprecated_member_use
import 'dart:html';

import 'package:amplify_auth_cognito_dart/amplify_auth_cognito_dart.dart';
import 'package:amplify_core/amplify_core.dart';
import 'package:cognito_example/common.dart';
import 'package:example_common/example_common.dart';
import 'package:web/web.dart';

import 'app_component.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// TODO(dnys1): Migrate to `js_interop`.
library;

import 'dart:convert';
import 'dart:js_interop';

import 'package:amplify_auth_cognito_dart/src/asf/asf_device_info_collector.dart';
import 'package:amplify_auth_cognito_dart/src/asf/package_info.dart';
import 'package:async/async.dart';
import 'package:aws_common/aws_common.dart';
// ignore: implementation_imports
import 'package:aws_common/src/js/common.dart';
//ignore: deprecated_member_use
import 'package:js/js.dart';
import 'package:path/path.dart';
import 'package:web/web.dart';

/// {@template amplify_auth_cognito_dart.asf.asf_device_info_js}
/// The JS/Browser implementation of [NativeASFDeviceInfoCollector].
Expand Down Expand Up @@ -65,10 +62,10 @@ final class ASFDeviceInfoPlatform extends NativeASFDeviceInfoCollector {
window.navigator.userAgentData?.platform ?? window.navigator.platform;

@override
Future<int?> get screenHeightPixels async => window.screen.height?.toInt();
Future<int?> get screenHeightPixels async => window.screen.height;

@override
Future<int?> get screenWidthPixels async => window.screen.width?.toInt();
Future<int?> get screenWidthPixels async => window.screen.width;

@override
Future<String?> get thirdPartyDeviceId async => null;
Expand All @@ -81,34 +78,11 @@ String get _baseUrl {
return url.join(window.location.origin, basePath);
}

extension on Window {
external _Screen get screen;
external _Navigator get navigator;
}

@JS('Screen')
@staticInterop
class _Screen {}

extension on _Screen {
external double? get width;
external double? get height;
}

@JS('Navigator')
@staticInterop
class _Navigator {}

extension on _Navigator {
external String? get language;
external String? get platform;
extension _PropsNavigator on Navigator {
external _NavigatorUAData? get userAgentData;
}

@JS('NavigatorUAData')
@staticInterop
class _NavigatorUAData {}

extension on _NavigatorUAData {
extension type _NavigatorUAData._(JSObject _) implements JSObject {
external String? get platform;
}
Loading
Loading