Skip to content
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

fix: pong response & chunked upload #72

Merged
merged 3 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2024 Appwrite (https://appwrite.io) and individual contributors.
Copyright (c) 2025 Appwrite (https://appwrite.io) and individual contributors.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Add this to your package's `pubspec.yaml` file:

```yml
dependencies:
dart_appwrite: ^12.2.0
dart_appwrite: ^13.0.0
```

You can install packages from the command line:
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/account/update-mfa-challenge.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Client client = Client()

Account account = Account(client);

result = await account.updateMfaChallenge(
Session result = await account.updateMfaChallenge(
challengeId: '<CHALLENGE_ID>',
otp: '<OTP>',
);
4 changes: 2 additions & 2 deletions lib/services/account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class Account extends Service {
/// the flow, use
/// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge)
/// method.
Future updateMfaChallenge(
Future<models.Session> updateMfaChallenge(
{required String challengeId, required String otp}) async {
final String apiPath = '/account/mfa/challenge';

Expand All @@ -298,7 +298,7 @@ class Account extends Service {
final res = await client.call(HttpMethod.put,
path: apiPath, params: apiParams, headers: apiHeaders);

return res.data;
return models.Session.fromMap(res.data);
}

/// List factors
Expand Down
10 changes: 10 additions & 0 deletions lib/services/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ class Functions extends Service {

/// Rebuild deployment
///
/// Create a new build for an existing function deployment. This endpoint
/// allows you to rebuild a deployment with the updated function configuration,
/// including its entrypoint and build commands if they have been modified The
/// build process will be queued and executed asynchronously. The original
/// deployment's code will be preserved and used for the new build.
Future createBuild(
{required String functionId,
required String deploymentId,
Expand All @@ -389,6 +394,11 @@ class Functions extends Service {

/// Cancel deployment
///
/// Cancel an ongoing function deployment build. If the build is already in
/// progress, it will be stopped and marked as canceled. If the build hasn't
/// started yet, it will be marked as canceled without executing. You cannot
/// cancel builds that have already completed (status 'ready') or failed. The
/// response includes the final build status and details.
Future<models.Build> updateDeploymentBuild(
{required String functionId, required String deploymentId}) async {
final String apiPath =
Expand Down
12 changes: 9 additions & 3 deletions lib/services/messaging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ class Messaging extends Service {

/// Update email
///
/// Update an email message by its unique ID.
/// Update an email message by its unique ID. This endpoint only works on
/// messages that are in draft status. Messages that are already processing,
/// sent, or failed cannot be updated.
///
Future<models.Message> updateEmail(
{required String messageId,
Expand Down Expand Up @@ -173,7 +175,9 @@ class Messaging extends Service {

/// Update push notification
///
/// Update a push notification by its unique ID.
/// Update a push notification by its unique ID. This endpoint only works on
/// messages that are in draft status. Messages that are already processing,
/// sent, or failed cannot be updated.
///
Future<models.Message> updatePush(
{required String messageId,
Expand Down Expand Up @@ -264,7 +268,9 @@ class Messaging extends Service {

/// Update SMS
///
/// Update an email message by its unique ID.
/// Update an SMS message by its unique ID. This endpoint only works on
/// messages that are in draft status. Messages that are already processing,
/// sent, or failed cannot be updated.
///
Future<models.Message> updateSms(
{required String messageId,
Expand Down
4 changes: 2 additions & 2 deletions lib/services/users.dart
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ class Users extends Service {
/// Delete authenticator
///
/// Delete an authenticator app.
Future<models.User> deleteMfaAuthenticator(
Future deleteMfaAuthenticator(
{required String userId, required enums.AuthenticatorType type}) async {
final String apiPath = '/users/{userId}/mfa/authenticators/{type}'
.replaceAll('{userId}', userId)
Expand All @@ -521,7 +521,7 @@ class Users extends Service {
final res = await client.call(HttpMethod.delete,
path: apiPath, params: apiParams, headers: apiHeaders);

return models.User.fromMap(res.data);
return res.data;
}

/// List factors
Expand Down
3 changes: 3 additions & 0 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ abstract class Client {
/// Add headers that should be sent with all API calls.
Client addHeader(String key, String value);

/// Sends a "ping" request to Appwrite to verify connectivity.
Future<String> ping();

/// Upload a file in chunks.
Future<Response> chunkedUpload({
required String path,
Expand Down
3 changes: 3 additions & 0 deletions lib/src/client_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ abstract class ClientBase implements Client {
@override
ClientBase addHeader(String key, String value);

@override
Future<String> ping();

@override
Future<Response> call(
HttpMethod method, {
Expand Down
13 changes: 11 additions & 2 deletions lib/src/client_browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ClientBrowser extends ClientBase with ClientMixin {
'x-sdk-name': 'Dart',
'x-sdk-platform': 'server',
'x-sdk-language': 'dart',
'x-sdk-version': '12.2.0',
'x-sdk-version': '13.0.0',
'X-Appwrite-Response-Format': '1.6.0',
};

Expand Down Expand Up @@ -110,6 +110,15 @@ class ClientBrowser extends ClientBase with ClientMixin {
return this;
}

@override
Future<String> ping() async {
final String apiPath = '/ping';
final response = await call(HttpMethod.get,
path: apiPath, responseType: ResponseType.plain);

return response.data;
}

@override
Future<String?> webAuth(Uri url) async {
final request = http.Request('GET', url);
Expand Down Expand Up @@ -147,7 +156,7 @@ class ClientBrowser extends ClientBase with ClientMixin {
}

var offset = 0;
if (idParamName.isNotEmpty && params[idParamName] != 'unique()') {
if (idParamName.isNotEmpty) {
//make a request to check if a file already exists
try {
res = await call(
Expand Down
15 changes: 12 additions & 3 deletions lib/src/client_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class ClientIO extends ClientBase with ClientMixin {
'x-sdk-name': 'Dart',
'x-sdk-platform': 'server',
'x-sdk-language': 'dart',
'x-sdk-version': '12.2.0',
'x-sdk-version': '13.0.0',
'user-agent':
'AppwriteDartSDK/12.2.0 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})',
'AppwriteDartSDK/13.0.0 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})',
'X-Appwrite-Response-Format': '1.6.0',
};

Expand Down Expand Up @@ -123,6 +123,15 @@ class ClientIO extends ClientBase with ClientMixin {
return this;
}

@override
Future<String> ping() async {
final String apiPath = '/ping';
final response = await call(HttpMethod.get,
path: apiPath, responseType: ResponseType.plain);

return response.data;
}

@override
Future<Response> chunkedUpload({
required String path,
Expand Down Expand Up @@ -168,7 +177,7 @@ class ClientIO extends ClientBase with ClientMixin {
}

var offset = 0;
if (idParamName.isNotEmpty && params[idParamName] != 'unique()') {
if (idParamName.isNotEmpty) {
//make a request to check if a file already exists
try {
res = await call(
Expand Down
1 change: 1 addition & 0 deletions lib/src/enums/image_format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ enum ImageFormat {
gif(value: 'gif'),
png(value: 'png'),
webp(value: 'webp'),
heic(value: 'heic'),
avif(value: 'avif');

const ImageFormat({required this.value});
Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/attribute_enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class AttributeEnum implements Model {
array: map['array'],
$createdAt: map['\$createdAt'].toString(),
$updatedAt: map['\$updatedAt'].toString(),
elements: map['elements'] ?? [],
elements: List.from(map['elements'] ?? []),
format: map['format'].toString(),
xdefault: map['default']?.toString(),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/attribute_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AttributeList implements Model {
factory AttributeList.fromMap(Map<String, dynamic> map) {
return AttributeList(
total: map['total'],
attributes: map['attributes'] ?? [],
attributes: List.from(map['attributes'] ?? []),
);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/models/bucket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ class Bucket implements Model {
$id: map['\$id'].toString(),
$createdAt: map['\$createdAt'].toString(),
$updatedAt: map['\$updatedAt'].toString(),
$permissions: map['\$permissions'] ?? [],
$permissions: List.from(map['\$permissions'] ?? []),
fileSecurity: map['fileSecurity'],
name: map['name'].toString(),
enabled: map['enabled'],
maximumFileSize: map['maximumFileSize'],
allowedFileExtensions: map['allowedFileExtensions'] ?? [],
allowedFileExtensions: List.from(map['allowedFileExtensions'] ?? []),
compression: map['compression'].toString(),
encryption: map['encryption'],
antivirus: map['antivirus'],
Expand Down
4 changes: 2 additions & 2 deletions lib/src/models/collection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ class Collection implements Model {
$id: map['\$id'].toString(),
$createdAt: map['\$createdAt'].toString(),
$updatedAt: map['\$updatedAt'].toString(),
$permissions: map['\$permissions'] ?? [],
$permissions: List.from(map['\$permissions'] ?? []),
databaseId: map['databaseId'].toString(),
name: map['name'].toString(),
enabled: map['enabled'],
documentSecurity: map['documentSecurity'],
attributes: map['attributes'] ?? [],
attributes: List.from(map['attributes'] ?? []),
indexes: List<Index>.from(map['indexes'].map((p) => Index.fromMap(p))),
);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/src/models/document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Document implements Model {

/// Document permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).
final List<String> $permissions;

final Map<String, dynamic> data;

Document({
Expand All @@ -38,7 +39,7 @@ class Document implements Model {
$databaseId: map['\$databaseId'].toString(),
$createdAt: map['\$createdAt'].toString(),
$updatedAt: map['\$updatedAt'].toString(),
$permissions: map['\$permissions'] ?? [],
$permissions: List.from(map['\$permissions'] ?? []),
data: map,
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/execution.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Execution implements Model {
$id: map['\$id'].toString(),
$createdAt: map['\$createdAt'].toString(),
$updatedAt: map['\$updatedAt'].toString(),
$permissions: map['\$permissions'] ?? [],
$permissions: List.from(map['\$permissions'] ?? []),
functionId: map['functionId'].toString(),
trigger: map['trigger'].toString(),
status: map['status'].toString(),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class File implements Model {
bucketId: map['bucketId'].toString(),
$createdAt: map['\$createdAt'].toString(),
$updatedAt: map['\$updatedAt'].toString(),
$permissions: map['\$permissions'] ?? [],
$permissions: List.from(map['\$permissions'] ?? []),
name: map['name'].toString(),
signature: map['signature'].toString(),
mimeType: map['mimeType'].toString(),
Expand Down
6 changes: 3 additions & 3 deletions lib/src/models/function.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ class Func implements Model {
$id: map['\$id'].toString(),
$createdAt: map['\$createdAt'].toString(),
$updatedAt: map['\$updatedAt'].toString(),
execute: map['execute'] ?? [],
execute: List.from(map['execute'] ?? []),
name: map['name'].toString(),
enabled: map['enabled'],
live: map['live'],
logging: map['logging'],
runtime: map['runtime'].toString(),
deployment: map['deployment'].toString(),
scopes: map['scopes'] ?? [],
scopes: List.from(map['scopes'] ?? []),
vars: List<Variable>.from(map['vars'].map((p) => Variable.fromMap(p))),
events: map['events'] ?? [],
events: List.from(map['events'] ?? []),
schedule: map['schedule'].toString(),
timeout: map['timeout'],
entrypoint: map['entrypoint'].toString(),
Expand Down
4 changes: 2 additions & 2 deletions lib/src/models/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class Index implements Model {
type: map['type'].toString(),
status: map['status'].toString(),
error: map['error'].toString(),
attributes: map['attributes'] ?? [],
orders: map['orders'],
attributes: List.from(map['attributes'] ?? []),
orders: List.from(map['orders'] ?? []),
$createdAt: map['\$createdAt'].toString(),
$updatedAt: map['\$updatedAt'].toString(),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/membership.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Membership implements Model {
joined: map['joined'].toString(),
confirm: map['confirm'],
mfa: map['mfa'],
roles: map['roles'] ?? [],
roles: List.from(map['roles'] ?? []),
);
}

Expand Down
8 changes: 4 additions & 4 deletions lib/src/models/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ class Message implements Model {
$createdAt: map['\$createdAt'].toString(),
$updatedAt: map['\$updatedAt'].toString(),
providerType: map['providerType'].toString(),
topics: map['topics'] ?? [],
users: map['users'] ?? [],
targets: map['targets'] ?? [],
topics: List.from(map['topics'] ?? []),
users: List.from(map['users'] ?? []),
targets: List.from(map['targets'] ?? []),
scheduledAt: map['scheduledAt']?.toString(),
deliveredAt: map['deliveredAt']?.toString(),
deliveryErrors: map['deliveryErrors'],
deliveryErrors: List.from(map['deliveryErrors'] ?? []),
deliveredTotal: map['deliveredTotal'],
data: map['data'],
status: map['status'].toString(),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/mfa_recovery_codes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MfaRecoveryCodes implements Model {

factory MfaRecoveryCodes.fromMap(Map<String, dynamic> map) {
return MfaRecoveryCodes(
recoveryCodes: map['recoveryCodes'] ?? [],
recoveryCodes: List.from(map['recoveryCodes'] ?? []),
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/runtime.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Runtime implements Model {
base: map['base'].toString(),
image: map['image'].toString(),
logo: map['logo'].toString(),
supports: map['supports'] ?? [],
supports: List.from(map['supports'] ?? []),
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class Session implements Model {
countryCode: map['countryCode'].toString(),
countryName: map['countryName'].toString(),
current: map['current'],
factors: map['factors'] ?? [],
factors: List.from(map['factors'] ?? []),
secret: map['secret'].toString(),
mfaUpdatedAt: map['mfaUpdatedAt'].toString(),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/topic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Topic implements Model {
emailTotal: map['emailTotal'],
smsTotal: map['smsTotal'],
pushTotal: map['pushTotal'],
subscribe: map['subscribe'] ?? [],
subscribe: List.from(map['subscribe'] ?? []),
);
}

Expand Down
Loading