Skip to content

Commit

Permalink
Merge pull request #693 from atsign-foundation/fix_pubscore_issue
Browse files Browse the repository at this point in the history
chore: change pub score url in readme
  • Loading branch information
sitaram-kalluri committed Sep 8, 2022
2 parents 80247b3 + 4974f12 commit 74c219d
Show file tree
Hide file tree
Showing 52 changed files with 210 additions and 110 deletions.
2 changes: 1 addition & 1 deletion at_client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Now for some internet optimism.

[![pub package](https://img.shields.io/pub/v/at_client)](https://pub.dev/packages/at_client) [![pub points](https://badges.bar/at_client/pub%20points)](https://pub.dev/packages/at_client/score) [![build status](https://github.com/atsign-foundation/at_client_sdk/actions/workflows/at_client_sdk.yaml/badge.svg?branch=trunk)](https://github.com/atsign-foundation/at_client_sdk/actions/workflows/at_client_sdk.yaml) [![gitHub license](https://img.shields.io/badge/license-BSD3-blue.svg)](./LICENSE)
[![pub package](https://img.shields.io/pub/v/at_client)](https://pub.dev/packages/at_client) [![pub points](https://img.shields.io/badge/dynamic/json?url=https://pub.dev/api/packages/at_client/score&label=pub%20score&query=grantedPoints)](https://pub.dev/packages/at_client/score) [![build status](https://github.com/atsign-foundation/at_client_sdk/actions/workflows/at_client_sdk.yaml/badge.svg?branch=trunk)](https://github.com/atsign-foundation/at_client_sdk/actions/workflows/at_client_sdk.yaml) [![gitHub license](https://img.shields.io/badge/license-BSD3-blue.svg)](./LICENSE)

# at_client

Expand Down
6 changes: 6 additions & 0 deletions at_client/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Files and directories created by pub.
.dart_tool/
.packages

# Conventional directory for build output.
build/
3 changes: 3 additions & 0 deletions at_client/example/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0

- at_client package example.
13 changes: 13 additions & 0 deletions at_client/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<img width=250px src="https://atsign.dev/assets/img/atPlatform_logo_gray.svg?sanitize=true">

### Now for a little internet optimism

# at_client_example library

The at_client package is an interface between the Client SDK and the cloud secondary.

## Give it a try

This package includes a sample code in
the [example](https://github.com/atsign-foundation/at_client_sdk/blob/trunk/at_client/example/bin/example.dart)
directory for usage of the at_client library.
30 changes: 30 additions & 0 deletions at_client/example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.

# linter:
# rules:
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
25 changes: 25 additions & 0 deletions at_client/example/bin/example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:at_client/at_client.dart';

/// The example below demonstrates on initializing the [AtClientManager]
/// and getting [AtClient] and [NotificationService] instances.
void main() async {
final atSign = '@alice🛠';
final namespace = '.wavi';
final atClientPreference = AtClientPreference();
// Initializing AtClientManager instance
await AtClientManager.getInstance()
.setCurrentAtSign(atSign, namespace, atClientPreference);

// Getting the AtClient instance
AtClient atClient = AtClientManager.getInstance().atClient;
// Storing value to keystore
atClient.put(
AtKey.public('phone', namespace: namespace).build(), '+91 8908901234');

// Getting the NotificationService instance
NotificationService notificationService =
AtClientManager.getInstance().notificationService;
// Invoking the notify method
notificationService.notify(NotificationParams.forUpdate(
AtKey.shared('phone', namespace: namespace).build()));
}
16 changes: 16 additions & 0 deletions at_client/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: at_client_example
description: An example application to demostrate the at_client package usage.
version: 1.0.0

environment:
sdk: '>=2.14.4 <3.0.0'


dependencies:
at_utils: ^3.0.11
at_commons: ^3.0.25
at_lookup: ^3.0.30
at_client: ^3.0.37

dev_dependencies:
lints: ^1.0.0
25 changes: 15 additions & 10 deletions at_client/lib/src/client/at_client_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ class AtClientImpl implements AtClient {
@Deprecated("Use [create]")
AtClientImpl(
// ignore: no_leading_underscores_for_local_identifiers
String _atSign, String? namespace, AtClientPreference preference) {
String _atSign,
String? namespace,
AtClientPreference preference) {
currentAtSign = AtUtils.formatAtSign(_atSign);
_preference = preference;
_namespace = namespace;
Expand Down Expand Up @@ -260,7 +262,8 @@ class AtClientImpl implements AtClient {
..one = atKey
..two = (getResponse);
// Transform the response and return
var atValue = await GetResponseTransformer(this).transform(getResponseTuple);
var atValue =
await GetResponseTransformer(this).transform(getResponseTuple);
return atValue;
} on AtException catch (e) {
var exceptionScenario = (secondary is LocalSecondary)
Expand Down Expand Up @@ -626,7 +629,9 @@ class AtClientImpl implements AtClient {
var encryptionKey = _encryptionService!.generateFileEncryptionKey();
var key = TextConstants.fileTransferKey + Uuid().v4();
var fileStatus = await _uploadFiles(key, files, encryptionKey);
// ignore: prefer_interpolation_to_compose_strings
var fileUrl = TextConstants.fileBinURL + 'archive/' + key + '/zip';

return shareFiles(
sharedWithAtSigns, key, fileUrl, encryptionKey, fileStatus);
}
Expand Down Expand Up @@ -705,9 +710,8 @@ class AtClientImpl implements AtClient {

// storing sent files in a a directory.
if (preference?.downloadPath != null) {
var sentFilesDirectory = await Directory(preference!.downloadPath! +
Platform.pathSeparator +
'sent-files')
var sentFilesDirectory = await Directory(
'${preference!.downloadPath!}${Platform.pathSeparator}sent-files')
.create();
await File(file.path).copy(sentFilesDirectory.path +
Platform.pathSeparator +
Expand Down Expand Up @@ -804,7 +808,8 @@ class AtClientImpl implements AtClient {
// validate sharedWith atSign
AtUtils.fixAtSign(notificationParams.atKey.sharedWith!);
// Check if sharedWith AtSign exists
await AtClientValidation().isAtSignExists(AtClientManager.getInstance().secondaryAddressFinder!,
await AtClientValidation().isAtSignExists(
AtClientManager.getInstance().secondaryAddressFinder!,
notificationParams.atKey.sharedWith!,
_preference!.rootDomain,
_preference!.rootPort);
Expand Down Expand Up @@ -858,8 +863,8 @@ class AtClientImpl implements AtClient {
if (notificationParams.atKey.sharedWith != null &&
notificationParams.atKey.sharedWith != currentAtSign) {
try {
final atKeyEncryption = AtKeyEncryptionManager().get(
notificationParams.atKey, currentAtSign!);
final atKeyEncryption = AtKeyEncryptionManager()
.get(notificationParams.atKey, currentAtSign!);
builder.value = await atKeyEncryption.encrypt(
notificationParams.atKey, notificationParams.value!);
} on KeyNotFoundException catch (e) {
Expand All @@ -871,8 +876,8 @@ class AtClientImpl implements AtClient {
if (notificationParams.atKey.sharedWith == null ||
notificationParams.atKey.sharedWith == currentAtSign) {
try {
final atKeyEncryption = AtKeyEncryptionManager().get(
notificationParams.atKey, currentAtSign!);
final atKeyEncryption = AtKeyEncryptionManager()
.get(notificationParams.atKey, currentAtSign!);
builder.value = await atKeyEncryption.encrypt(
notificationParams.atKey, notificationParams.value!);
} on KeyNotFoundException catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion at_client/lib/src/client/remote_secondary.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import 'dart:io';

import 'package:at_client/src/client/secondary.dart';
import 'package:at_client/src/manager/at_client_manager.dart';
import 'package:at_client/src/preference/at_client_preference.dart';
import 'package:at_client/src/preference/at_client_config.dart';
import 'package:at_client/src/preference/at_client_preference.dart';
import 'package:at_client/src/util/at_client_util.dart';
import 'package:at_commons/at_builders.dart';
import 'package:at_commons/at_commons.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:at_client/at_client.dart';
import 'package:at_client/src/decryption_service/decryption.dart';
import 'package:at_client/src/encryption_service/abstract_atkey_encryption.dart';
import 'package:at_commons/at_commons.dart';
import 'package:at_utils/at_logger.dart';

/// Class responsible for decrypting the value of key shared to other atSign's
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:at_client/at_client.dart';
import 'package:at_client/src/decryption_service/decryption.dart';
import 'package:at_client/src/response/default_response_parser.dart';
import 'package:at_commons/at_commons.dart';

/// Class responsible for decrypting the value of self key's
/// Example:
Expand Down
4 changes: 3 additions & 1 deletion at_client/lib/src/key_stream/key_stream_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:at_client/at_client.dart'
show AtClient, AtClientManager, AtNotification;
import 'package:at_client/src/listener/at_sign_change_listener.dart';
import 'package:at_client/src/listener/switch_at_sign_event.dart';
// ignore: unused_shown_name
import 'package:at_commons/at_commons.dart' show AtException, AtKey, AtValue;
import 'package:at_utils/at_logger.dart';

Expand Down Expand Up @@ -97,8 +98,9 @@ abstract class KeyStreamMixin<T> implements Stream<T> {
.subscribe(shouldDecrypt: true, regex: regex)
.listen(_notificationListener);

if (disposeOnAtsignChange)
if (disposeOnAtsignChange) {
_atClientManager.listenToAtSignChange(KeyStreamDisposeListener(this));
}
}

/// A function that preloads this Stream with keys that match [regex], [sharedBy], and [sharedWith].
Expand Down
1 change: 1 addition & 0 deletions at_client/lib/src/listener/connectivity_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ConnectivityListener {
/// Listen to [InternetConnectionChecker.onStatusChange] and returns Stream<True> whenever
/// internet connection is online. Returns Stream<False> if internet connection is lost.
Stream<bool> subscribe() {
// ignore: no_leading_underscores_for_local_identifiers
final _controller = StreamController<bool>();
_listener = InternetConnectionChecker().onStatusChange.listen((status) {
switch (status) {
Expand Down
1 change: 1 addition & 0 deletions at_client/lib/src/manager/at_client_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class AtClientManager {
return _singleton;
}

// ignore: no_leading_underscores_for_local_identifiers
AtClientManager(_atSign);

void setSecondaryAddressFinder(
Expand Down
9 changes: 7 additions & 2 deletions at_client/lib/src/manager/sync_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ class SyncManager {

SyncManager(this._atSign);

void init(String atSign, AtClientPreference preference,
RemoteSecondary? _remoteSecondary, LocalSecondary? _localSecondary) {
void init(
String atSign,
AtClientPreference preference,
// ignore: no_leading_underscores_for_local_identifiers
RemoteSecondary? _remoteSecondary,
// ignore: no_leading_underscores_for_local_identifiers
LocalSecondary? _localSecondary) {
_atSign = atSign;
_preference = preference;
this._localSecondary = _localSecondary;
Expand Down
4 changes: 3 additions & 1 deletion at_client/lib/src/preference/at_client_preference.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ class AtClientPreference {
String? pathToCerts;

// TODO Remove this in next major version
@Deprecated("namespace presence will become mandatory in next major version of the SDK")
@Deprecated(
"namespace presence will become mandatory in next major version of the SDK")

/// [AtClient.put] uses this parameter to decide whether to check for presence of a namespace in the
/// string representation of the AtKey.
/// * When set to true, keys such as public:foo@alice or @bob:foo@alice will be rejected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:at_client/src/response/response.dart';
import 'package:at_utils/at_logger.dart';

class NotificationResponseParser extends DefaultResponseParser {
// ignore: unused_field
final _logger = AtSignLogger('NotificationResponseParser');
Future<List<AtNotification>> getAtNotifications(AtResponse response) async {
final notificationList = <AtNotification>[];
Expand Down
3 changes: 3 additions & 0 deletions at_client/lib/src/service/encryption_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class EncryptionService {
/// Throws [IllegalArgumentException] if encrypted value is null.
/// Throws [KeyNotFoundException] if encryption keys are not found.
Future<String> decrypt(String encryptedValue, String sharedBy) async {
// ignore: unnecessary_null_comparison
if (encryptedValue == null || encryptedValue.isEmpty) {
throw IllegalArgumentException(
'Decryption failed. Encrypted value is null');
Expand Down Expand Up @@ -242,6 +243,7 @@ class EncryptionService {
return;
}
var selfKeys = await atClient.getAtKeys(sharedBy: currentAtSign);
// ignore: avoid_function_literals_in_foreach_calls
selfKeys.forEach((atKey) async {
var key = atKey.key!;
if (!(key.startsWith(AT_PKAM_PRIVATE_KEY) ||
Expand Down Expand Up @@ -526,6 +528,7 @@ class EncryptionService {
Future<File> decryptFileInChunks(
File encryptedFile, String fileDecryptionKey, int chunkSize) async {
var chunkedStream = ChunkedStreamReader(encryptedFile.openRead());
// ignore: unused_local_variable
var startTime = DateTime.now();
final length = encryptedFile.lengthSync();
final fileName = encryptedFile.uri.pathSegments.last;
Expand Down
2 changes: 2 additions & 0 deletions at_client/lib/src/service/file_transfer_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class FileTransferService {
List<int> file, String container, String fileName) async {
try {
var response = await http.post(
// ignore: prefer_interpolation_to_compose_strings
Uri.parse(TextConstants.fileBinURL + '$container/' + fileName),
body: file,
);
Expand All @@ -23,6 +24,7 @@ class FileTransferService {
File file, String container, String fileName) async {
try {
var postUri =
// ignore: prefer_interpolation_to_compose_strings
Uri.parse(TextConstants.fileBinURL + '$container/' + fileName);
final streamedRequest = http.StreamedRequest('POST', postUri);

Expand Down
1 change: 0 additions & 1 deletion at_client/lib/src/service/sync_service.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:at_client/src/listener/sync_progress_listener.dart';
import 'package:at_client/src/service/sync/sync_conflict.dart';
import 'package:at_client/src/service/sync/sync_status.dart';

abstract class SyncService {
Expand Down
15 changes: 4 additions & 11 deletions at_client/lib/src/service/sync_service_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,20 @@ import 'dart:convert';

import 'package:at_client/at_client.dart';
import 'package:at_client/src/decryption_service/decryption_manager.dart';
import 'package:at_client/src/manager/at_client_manager.dart';
import 'package:at_client/src/client/at_client_spec.dart';
import 'package:at_client/src/client/remote_secondary.dart';
import 'package:at_client/src/listener/at_sign_change_listener.dart';
import 'package:at_client/src/listener/switch_at_sign_event.dart';
import 'package:at_client/src/listener/sync_progress_listener.dart';
import 'package:at_client/src/response/default_response_parser.dart';
import 'package:at_client/src/response/json_utils.dart';
import 'package:at_client/src/service/notification_service_impl.dart';
import 'package:at_client/src/service/sync/sync_conflict.dart';
import 'package:at_client/src/service/sync/sync_request.dart';
import 'package:at_client/src/service/sync/sync_result.dart';
import 'package:at_client/src/service/sync_service.dart';
import 'package:at_client/src/service/sync/sync_status.dart';
import 'package:at_client/src/util/network_util.dart';
import 'package:at_client/src/util/sync_util.dart';
import 'package:at_commons/at_builders.dart';
import 'package:at_commons/at_commons.dart';
import 'package:at_lookup/at_lookup.dart';
import 'package:at_persistence_secondary_server/at_persistence_secondary_server.dart';
import 'package:at_utils/at_utils.dart';
import 'package:cron/cron.dart';
import 'package:at_client/src/service/notification_service.dart';
import 'package:meta/meta.dart';

///A [SyncService] object is used to ensure data in local secondary(e.g mobile device) and cloud secondary are in sync.
Expand Down Expand Up @@ -94,7 +85,8 @@ class SyncServiceImpl implements SyncService, AtSignChangeListener {
void _scheduleSyncRun() {
_cron = Cron();

_cron.schedule(Schedule.parse('*/$_syncRunIntervalSeconds * * * * *'), () async {
_cron.schedule(Schedule.parse('*/$_syncRunIntervalSeconds * * * * *'),
() async {
try {
await processSyncRequests();
} on Exception catch (e, trace) {
Expand Down Expand Up @@ -419,7 +411,7 @@ class SyncServiceImpl implements SyncService, AtSignChangeListener {
var cause = (e is AtException) ? e.getTraceMessage() : e.toString();
_logger.severe(
'exception syncing entry to local $serverCommitEntry - $cause');
} on Error catch(e) {
} on Error catch (e) {
_logger.severe(
'error syncing entry to local $serverCommitEntry - ${e.toString()}');
}
Expand Down Expand Up @@ -641,6 +633,7 @@ class SyncServiceImpl implements SyncService, AtSignChangeListener {
///Throws [AtLookUpException] if secondary is not reachable
Future<int> _getServerCommitId({RemoteSecondary? remoteSecondary}) async {
remoteSecondary ??= _remoteSecondary;
// ignore: no_leading_underscores_for_local_identifiers
var _serverCommitId = await syncUtil.getLatestServerCommitId(
remoteSecondary, _atClient.getPreferences()!.syncRegex);
// If server commit id is null, set to -1;
Expand Down
2 changes: 2 additions & 0 deletions at_client/lib/src/stream/file_transfer_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class FileTransferObject {
..sharedStatus = json['sharedStatus']
..error = json['error'];
} catch (error) {
// ignore: prefer_interpolation_to_compose_strings
print('FileTransferObject.fromJson error: ' + error.toString());
}
return null;
Expand Down Expand Up @@ -80,6 +81,7 @@ class FileStatus {
size: json['size'],
error: json['error']);
} catch (error) {
// ignore: prefer_interpolation_to_compose_strings
print('FileStatus.fromJson error: ' + error.toString());
}
return null;
Expand Down
Loading

0 comments on commit 74c219d

Please sign in to comment.