Skip to content
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
9 changes: 7 additions & 2 deletions examples/edge_functions/integration_test/invoke_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ void main() {
});

testWidgets('every HTTP method reaches the function', (_) async {
for (final method in HttpMethod.values) {
// HEAD responses carry no body, so the echo function cannot report back
// which method it saw.
final methods = HttpMethod.values.where(
(method) => method != HttpMethod.head,
);
for (final method in methods) {
final response = await functions.invoke(
'echo',
method: method,
Expand All @@ -66,7 +71,7 @@ void main() {
? null
: {'value': 1},
);
expect(response.data['method'], method.name.toUpperCase());
expect(response.data['method'], method.value);
}
});

Expand Down
1 change: 1 addition & 0 deletions packages/functions_client/lib/functions_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ library;

export 'package:http/http.dart'
show ByteStream, MultipartFile, RequestAbortedException;
export 'package:supabase_common/supabase_common.dart' show HttpMethod;

export 'src/functions_client.dart';
export 'src/types.dart';
4 changes: 2 additions & 2 deletions packages/functions_client/lib/src/functions_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,15 @@ class FunctionsClient {

request =
http.AbortableMultipartRequest(
method.name.toUpperCase(),
method.value,
uri,
abortTrigger: abortSignal,
)
..fields.addAll(fields ?? {})
..files.addAll(files);
} else {
final bodyRequest = http.AbortableRequest(
method.name.toUpperCase(),
method.value,
uri,
abortTrigger: abortSignal,
);
Expand Down
8 changes: 0 additions & 8 deletions packages/functions_client/lib/src/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ import 'dart:typed_data';

import 'package:http/http.dart';

enum HttpMethod {
get,
post,
put,
delete,
patch,
}

class FunctionResponse {
/// The data returned by the function. Type depends on the header
/// `Content-Type`:
Expand Down
1 change: 1 addition & 0 deletions packages/functions_client/test/functions_dart_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'dart:typed_data';
import 'package:functions_client/src/functions_client.dart';
import 'package:functions_client/src/types.dart';
import 'package:http/http.dart';
import 'package:supabase_common/supabase_common.dart';
import 'package:test/test.dart';
import 'package:yet_another_json_isolate/yet_another_json_isolate.dart';

Expand Down
25 changes: 10 additions & 15 deletions packages/gotrue/lib/src/fetch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import 'package:http/http.dart';
import 'package:meta/meta.dart';
import 'package:supabase_common/supabase_common.dart';

@internal
enum RequestMethodType { get, post, put, patch, delete }

@internal
class GotrueFetch {
final Client? httpClient;
Expand Down Expand Up @@ -146,7 +143,7 @@ class GotrueFetch {

Future<dynamic> request(
String url,
RequestMethodType method, {
HttpMethod method, {
GotrueRequestOptions? options,
}) async {
final result = await requestWithResponse(url, method, options: options);
Expand All @@ -160,7 +157,7 @@ class GotrueFetch {
@internal
Future<({dynamic body, Response response})> requestWithResponse(
String url,
RequestMethodType method, {
HttpMethod method, {
GotrueRequestOptions? options,
}) async {
// Copy the maps before mutating them. Callers pass the client's shared
Expand Down Expand Up @@ -211,39 +208,37 @@ class GotrueFetch {
}

Future<Response> _handleRequest({
required RequestMethodType method,
required HttpMethod method,
required Uri uri,
required GotrueRequestOptions? options,
required Map<String, String> headers,
}) async {
final bodyStr = json.encode(options?.body ?? {});

if (method != RequestMethodType.get) {
if (method != HttpMethod.get && method != HttpMethod.head) {
headers['Content-Type'] = 'application/json';
}
Response response;
try {
response = await switch (method) {
RequestMethodType.get => (httpClient?.get ?? get)(
uri,
headers: headers,
),
RequestMethodType.post => (httpClient?.post ?? post)(
HttpMethod.get => (httpClient?.get ?? get)(uri, headers: headers),
HttpMethod.head => (httpClient?.head ?? head)(uri, headers: headers),
HttpMethod.post => (httpClient?.post ?? post)(
uri,
headers: headers,
body: bodyStr,
),
RequestMethodType.put => (httpClient?.put ?? put)(
HttpMethod.put => (httpClient?.put ?? put)(
uri,
headers: headers,
body: bodyStr,
),
RequestMethodType.patch => (httpClient?.patch ?? patch)(
HttpMethod.patch => (httpClient?.patch ?? patch)(
uri,
headers: headers,
body: bodyStr,
),
RequestMethodType.delete => (httpClient?.delete ?? delete)(
HttpMethod.delete => (httpClient?.delete ?? delete)(
uri,
headers: headers,
body: bodyStr,
Expand Down
16 changes: 8 additions & 8 deletions packages/gotrue/lib/src/gotrue_admin_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class GoTrueAdminApi {

await _fetch.request(
'$_url/logout',
RequestMethodType.post,
HttpMethod.post,
options: options,
);
}
Expand All @@ -115,7 +115,7 @@ class GoTrueAdminApi {
);
final response = await _fetch.request(
'$_url/admin/users',
RequestMethodType.post,
HttpMethod.post,
options: options,
);
return UserResponse.fromJson(response);
Expand All @@ -139,7 +139,7 @@ class GoTrueAdminApi {
);
await _fetch.request(
'$_url/admin/users/$id',
RequestMethodType.delete,
HttpMethod.delete,
options: options,
);
}
Expand Down Expand Up @@ -168,7 +168,7 @@ class GoTrueAdminApi {
);
final result = await _fetch.requestWithResponse(
'$_url/admin/users',
RequestMethodType.get,
HttpMethod.get,
options: options,
);
final body = result.body;
Expand Down Expand Up @@ -202,7 +202,7 @@ class GoTrueAdminApi {

final response = await _fetch.request(
'$_url/invite',
RequestMethodType.post,
HttpMethod.post,
options: fetchOptions,
);
return UserResponse.fromJson(response);
Expand Down Expand Up @@ -250,7 +250,7 @@ class GoTrueAdminApi {

final response = await _fetch.request(
'$_url/admin/generate_link',
RequestMethodType.post,
HttpMethod.post,
options: fetchOptions,
);
return GenerateLinkResponse.fromJson(response);
Expand All @@ -262,7 +262,7 @@ class GoTrueAdminApi {
final options = GotrueRequestOptions(headers: _headers);
final response = await _fetch.request(
'$_url/admin/users/$uid',
RequestMethodType.get,
HttpMethod.get,
options: options,
);
return UserResponse.fromJson(response);
Expand All @@ -278,7 +278,7 @@ class GoTrueAdminApi {
final options = GotrueRequestOptions(headers: _headers, body: body);
final response = await _fetch.request(
'$_url/admin/users/$uid',
RequestMethodType.put,
HttpMethod.put,
options: options,
);
return UserResponse.fromJson(response);
Expand Down
12 changes: 7 additions & 5 deletions packages/gotrue/lib/src/gotrue_admin_custom_providers_api.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:supabase_common/supabase_common.dart';

import 'fetch.dart';
import 'types/custom_oauth_provider.dart';
import 'types/fetch_options.dart';
Expand Down Expand Up @@ -29,7 +31,7 @@ class GoTrueAdminCustomProvidersApi {
}) async {
final data = await _fetch.request(
'$_url/admin/custom-providers',
RequestMethodType.get,
HttpMethod.get,
options: GotrueRequestOptions(
headers: _headers,
query: {
Expand Down Expand Up @@ -60,7 +62,7 @@ class GoTrueAdminCustomProvidersApi {
) async {
final data = await _fetch.request(
'$_url/admin/custom-providers',
RequestMethodType.post,
HttpMethod.post,
options: GotrueRequestOptions(
headers: _headers,
body: params.toJson(),
Expand All @@ -77,7 +79,7 @@ class GoTrueAdminCustomProvidersApi {
Future<CustomOAuthProvider> getProvider(String identifier) async {
final data = await _fetch.request(
'$_url/admin/custom-providers/$identifier',
RequestMethodType.get,
HttpMethod.get,
options: GotrueRequestOptions(
headers: _headers,
),
Expand All @@ -101,7 +103,7 @@ class GoTrueAdminCustomProvidersApi {
) async {
final data = await _fetch.request(
'$_url/admin/custom-providers/$identifier',
RequestMethodType.put,
HttpMethod.put,
options: GotrueRequestOptions(
headers: _headers,
body: params.toJson(),
Expand All @@ -118,7 +120,7 @@ class GoTrueAdminCustomProvidersApi {
Future<void> deleteProvider(String identifier) async {
await _fetch.request(
'$_url/admin/custom-providers/$identifier',
RequestMethodType.delete,
HttpMethod.delete,
options: GotrueRequestOptions(
headers: _headers,
noResolveJson: true,
Expand Down
7 changes: 4 additions & 3 deletions packages/gotrue/lib/src/gotrue_admin_mfa_api.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:supabase_common/supabase_common.dart';

import 'fetch.dart';
import 'helper.dart';
import 'types/fetch_options.dart';
import 'types/mfa.dart';

Expand All @@ -23,7 +24,7 @@ class GoTrueAdminMFAApi {

final data = await _fetch.request(
'$_url/admin/users/$userId/factors',
RequestMethodType.get,
HttpMethod.get,
options: GotrueRequestOptions(
headers: _headers,
),
Expand All @@ -43,7 +44,7 @@ class GoTrueAdminMFAApi {

final data = await _fetch.request(
'$_url/admin/users/$userId/factors/$factorId',
RequestMethodType.delete,
HttpMethod.delete,
options: GotrueRequestOptions(
headers: _headers,
),
Expand Down
17 changes: 9 additions & 8 deletions packages/gotrue/lib/src/gotrue_admin_oauth_api.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:meta/meta.dart';
import 'package:supabase_common/supabase_common.dart';

import 'fetch.dart';
import 'helper.dart';
import 'types/fetch_options.dart';
import 'types/types.dart';
import 'package:meta/meta.dart';

/// Response type for OAuth client operations.
/// Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
Expand Down Expand Up @@ -76,7 +77,7 @@ class GoTrueAdminOAuthApi {
}) async {
final data = await _fetch.request(
'$_url/admin/oauth/clients',
RequestMethodType.get,
HttpMethod.get,
options: GotrueRequestOptions(
headers: _headers,
query: {
Expand All @@ -99,7 +100,7 @@ class GoTrueAdminOAuthApi {
) async {
final data = await _fetch.request(
'$_url/admin/oauth/clients',
RequestMethodType.post,
HttpMethod.post,
options: GotrueRequestOptions(
headers: _headers,
body: params.toJson(),
Expand All @@ -119,7 +120,7 @@ class GoTrueAdminOAuthApi {

final data = await _fetch.request(
'$_url/admin/oauth/clients/$clientId',
RequestMethodType.get,
HttpMethod.get,
options: GotrueRequestOptions(
headers: _headers,
),
Expand All @@ -141,7 +142,7 @@ class GoTrueAdminOAuthApi {

final data = await _fetch.request(
'$_url/admin/oauth/clients/$clientId',
RequestMethodType.put,
HttpMethod.put,
options: GotrueRequestOptions(
headers: _headers,
body: params.toJson(),
Expand All @@ -161,7 +162,7 @@ class GoTrueAdminOAuthApi {

final data = await _fetch.request(
'$_url/admin/oauth/clients/$clientId',
RequestMethodType.delete,
HttpMethod.delete,
options: GotrueRequestOptions(
headers: _headers,
),
Expand All @@ -180,7 +181,7 @@ class GoTrueAdminOAuthApi {

final data = await _fetch.request(
'$_url/admin/oauth/clients/$clientId/regenerate_secret',
RequestMethodType.post,
HttpMethod.post,
options: GotrueRequestOptions(
headers: _headers,
),
Expand Down
6 changes: 3 additions & 3 deletions packages/gotrue/lib/src/gotrue_admin_passkey_api.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:meta/meta.dart';
import 'package:supabase_common/supabase_common.dart';

import 'fetch.dart';
import 'helper.dart';
import 'types/fetch_options.dart';
import 'types/passkey.dart';

Expand Down Expand Up @@ -32,7 +32,7 @@ class GoTrueAdminPasskeyApi {

final data = await _fetch.request(
'$_url/admin/users/$userId/passkeys',
RequestMethodType.get,
HttpMethod.get,
options: GotrueRequestOptions(
headers: _headers,
),
Expand All @@ -57,7 +57,7 @@ class GoTrueAdminPasskeyApi {

await _fetch.request(
'$_url/admin/users/$userId/passkeys/$passkeyId',
RequestMethodType.delete,
HttpMethod.delete,
options: GotrueRequestOptions(
headers: _headers,
),
Expand Down
Loading
Loading