Skip to content

Commit 7ef1362

Browse files
committed
fix test
1 parent 02dfc3a commit 7ef1362

File tree

51 files changed

+84
-70
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+84
-70
lines changed

Sources/Auth/AuthClient.swift

+5-3
Original file line numberDiff line numberDiff line change
@@ -1122,10 +1122,12 @@ public final class AuthClient: Sendable {
11221122

11231123
if let jwt {
11241124
request.headerFields[.authorization] = "Bearer \(jwt)"
1125+
let (data, _) = try await api.execute(for: request, from: nil)
1126+
return try configuration.decoder.decode(User.self, from: data)
1127+
} else {
1128+
let (data, _) = try await api.authorizedExecute(for: request, from: nil)
1129+
return try configuration.decoder.decode(User.self, from: data)
11251130
}
1126-
1127-
let (data, _) = try await api.authorizedExecute(for: request, from: nil)
1128-
return try configuration.decoder.decode(User.self, from: data)
11291131
}
11301132

11311133
/// Updates user data, if there is a logged in user.

Sources/Auth/AuthClientConfiguration.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ extension AuthClient {
8383
},
8484
autoRefreshToken: Bool = AuthClient.Configuration.defaultAutoRefreshToken
8585
) {
86-
let headers = headers.merging(with: Configuration.defaultHeaders)
86+
let headers = Configuration.defaultHeaders.merging(headers) { $1 }
8787

8888
self.url = url ?? defaultAuthURL
8989
self.headers = headers

Sources/Auth/Internal/APIClient.swift

+2-5
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,9 @@ struct APIClient: Sendable {
3535
func execute(
3636
for request: HTTPRequest,
3737
from bodyData: Data?
38-
) async throws -> (
39-
Data,
40-
HTTPResponse
41-
) {
38+
) async throws -> (Data, HTTPResponse) {
4239
var request = request
43-
request.headerFields = HTTPFields(configuration.headers).merging(with: request.headerFields)
40+
request.headerFields = request.headerFields.merging(configuration.headers) { $1 }
4441

4542
if request.headerFields[.apiVersionHeaderName] == nil {
4643
request.headerFields[.apiVersionHeaderName] = apiVersions[._20240101]!.name.rawValue

Sources/Functions/FunctionsClient.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,12 @@ public final class FunctionsClient: Sendable {
236236
url: url
237237
.appendingPathComponent(functionName)
238238
.appendingQueryItems(options.query),
239-
headerFields: mutableState.headers.merging(with: options.headers)
239+
headerFields: mutableState.headers.merging(options.headers) { $1 }
240240
)
241+
242+
if options.body != nil && request.headerFields[.contentType] == nil {
243+
request.headerFields[.contentType] = "application/json"
244+
}
241245

242246
if let region = options.region ?? region {
243247
request.headerFields[.xRegion] = region

Sources/Functions/Types.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public struct FunctionInvokeOptions: Sendable {
6565
}
6666

6767
self.method = method
68-
self.headers = defaultHeaders.merging(with: headers)
68+
self.headers = defaultHeaders.merging(headers) { $1 }
6969
self.region = region
7070
self.query = query
7171
}

Sources/Helpers/HTTP/HTTPClient.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ package actor HTTPClient: HTTPClientType {
3232
_ request: HTTPRequest,
3333
_ bodyData: Data?
3434
) async throws -> (Data, HTTPResponse) {
35-
var next: @Sendable (HTTPRequest, Data?) async throws -> (Data, HTTPResponse) = {
36-
return try await self.fetch($0, $1)
35+
var next: @Sendable (HTTPRequest, Data?) async throws -> (Data, HTTPResponse) = { request, bodyData in
36+
var request = request
37+
if bodyData != nil && request.headerFields[.contentType] == nil {
38+
request.headerFields[.contentType] = "application/json"
39+
}
40+
return try await self.fetch(request, bodyData)
3741
}
3842

3943
for interceptor in interceptors.reversed() {

Sources/Helpers/HTTP/HTTPFields.swift

+11-7
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@ extension HTTPFields {
99
return .init(keyValues, uniquingKeysWith: { $1 })
1010
}
1111

12-
package mutating func merge(with other: Self) {
13-
for field in other {
14-
self[field.name] = field.value
15-
}
12+
package mutating func merge(
13+
_ other: Self,
14+
uniquingKeysWith combine: (String, String) throws -> String
15+
) rethrows {
16+
self = try self.merging(other, uniquingKeysWith: combine)
1617
}
17-
18-
package func merging(with other: Self) -> Self {
18+
19+
package func merging(
20+
_ other: Self,
21+
uniquingKeysWith combine: (String, String) throws -> String
22+
) rethrows -> HTTPFields {
1923
var copy = self
2024

2125
for field in other {
22-
copy[field.name] = field.value
26+
copy[field.name] = try combine(self[field.name] ?? "", field.value)
2327
}
2428

2529
return copy

Sources/Helpers/HTTP/LoggerInterceptor.swift

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ package struct LoggerInterceptor: HTTPClientInterceptor {
3131
)
3232

3333
do {
34+
var request = request
35+
if bodyData != nil && request.headerFields[.contentType] == nil {
36+
request.headerFields[.contentType] = "application/json"
37+
}
3438
let (data, response) = try await next(request, bodyData)
3539
logger.verbose(
3640
"""

Sources/PostgREST/PostgrestBuilder.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public class PostgrestBuilder: @unchecked Sendable {
102102
options: FetchOptions,
103103
decode: (Data) throws -> T
104104
) async throws -> PostgrestResponse<T> {
105-
let request = mutableState.withValue {
105+
let (request, bodyData) = mutableState.withValue {
106106
$0.fetchOptions = options
107107

108108
if $0.fetchOptions.head {
@@ -130,10 +130,10 @@ public class PostgrestBuilder: @unchecked Sendable {
130130
}
131131
}
132132

133-
return $0.request
133+
return ($0.request, $0.bodyData)
134134
}
135135

136-
let (data, response) = try await http.send(request, nil)
136+
let (data, response) = try await http.send(request, bodyData)
137137

138138
guard 200..<300 ~= response.status.code else {
139139
if let error = try? configuration.decoder.decode(PostgrestError.self, from: data) {

Sources/PostgREST/PostgrestClient.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public final class PostgrestClient: Sendable {
7272
public init(configuration: Configuration) {
7373
_configuration = LockIsolated(configuration)
7474
_configuration.withValue {
75-
$0.headers.merge(with: Configuration.defaultHeaders)
75+
$0.headers.merge(Configuration.defaultHeaders) { l, _ in l }
7676
}
7777
}
7878

Sources/Realtime/PhoenixTransport.swift

-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ open class URLSessionTransport: NSObject, PhoenixTransport, URLSessionWebSocketD
201201
var request = URLRequest(url: url)
202202

203203
for (key, value) in headers {
204-
guard let value = value as? String else { continue }
205204
request.addValue(value, forHTTPHeaderField: key)
206205
}
207206

Sources/Storage/StorageApi.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class StorageApi: @unchecked Sendable {
3535
from bodyData: Data?
3636
) async throws -> (Data, HTTPResponse) {
3737
var request = request
38-
request.headerFields = configuration.headers.merging(with: request.headerFields)
38+
request.headerFields = configuration.headers.merging(request.headerFields) { $1 }
3939

4040
let (data, response) = try await http.send(request, bodyData)
4141

Sources/Storage/StorageFileApi.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public class StorageFileApi: StorageApi, @unchecked Sendable {
8080
options: FileOptions?
8181
) async throws -> FileUploadResponse {
8282
let options = options ?? defaultFileOptions
83-
var headers = options.headers.map { HTTPFields($0) } ?? HTTPFields()
83+
var headers = options.headers ?? HTTPFields()
8484

8585
if method == .post {
8686
headers[.xUpsert] = "\(options.upsert)"
@@ -647,7 +647,7 @@ public class StorageFileApi: StorageApi, @unchecked Sendable {
647647
options: FileOptions?
648648
) async throws -> SignedURLUploadResponse {
649649
let options = options ?? defaultFileOptions
650-
var headers = options.headers.map { HTTPFields($0) } ?? HTTPFields()
650+
var headers = options.headers ?? HTTPFields()
651651

652652
headers[.xUpsert] = "\(options.upsert)"
653653
headers[.duplex] = options.duplex

Sources/Supabase/SupabaseClient.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public final class SupabaseClient: Sendable {
174174
.authorization: "Bearer \(supabaseKey)",
175175
.apiKey: supabaseKey,
176176
]
177-
self.headers = headers.merging(with: options.global.headers)
177+
self.headers = options.global.headers.merging(headers) { $1 }
178178

179179
// default storage key uses the supabase project ref as a namespace
180180
let defaultStorageKey = "sb-\(supabaseURL.host!.split(separator: ".")[0])-auth-token"
@@ -209,7 +209,7 @@ public final class SupabaseClient: Sendable {
209209
)
210210

211211
var realtimeOptions = options.realtime
212-
realtimeOptions.headers.merge(with: self.headers)
212+
realtimeOptions.headers.merge(self.headers) { $1 }
213213
if realtimeOptions.logger == nil {
214214
realtimeOptions.logger = options.global.logger
215215
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
curl \
22
--request DELETE \
3-
--header "Apikey: dummy.api.key" \
43
--header "Content-Type: application/json" \
54
--header "X-Client-Info: gotrue-swift/x.y.z" \
65
--header "X-Supabase-Api-Version: 2024-01-01" \
6+
--header "apiKey: dummy.api.key" \
77
--data "{\"should_soft_delete\":false}" \
88
"http://localhost:54321/auth/v1/admin/users/E621E1F8-C36C-495A-93FC-0C247A3E6E5F"
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
curl \
2-
--header "Apikey: dummy.api.key" \
32
--header "Authorization: Bearer accesstoken" \
43
--header "X-Client-Info: gotrue-swift/x.y.z" \
54
--header "X-Supabase-Api-Version: 2024-01-01" \
5+
--header "apiKey: dummy.api.key" \
66
"http://localhost:54321/auth/v1/user/identities/authorize?extra_key=extra_value&provider=github&redirect_to=https://supabase.com&scopes=user:email&skip_http_redirect=true"
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
curl \
22
--request POST \
3-
--header "Apikey: dummy.api.key" \
43
--header "Authorization: Bearer accesstoken" \
54
--header "X-Client-Info: gotrue-swift/x.y.z" \
65
--header "X-Supabase-Api-Version: 2024-01-01" \
6+
--header "apiKey: dummy.api.key" \
77
"http://localhost:54321/auth/v1/factors/123/challenge"
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
curl \
22
--request POST \
3-
--header "Apikey: dummy.api.key" \
43
--header "Authorization: Bearer accesstoken" \
54
--header "Content-Type: application/json" \
65
--header "X-Client-Info: gotrue-swift/x.y.z" \
76
--header "X-Supabase-Api-Version: 2024-01-01" \
7+
--header "apiKey: dummy.api.key" \
88
--data "{\"channel\":\"whatsapp\"}" \
99
"http://localhost:54321/auth/v1/factors/123/challenge"
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
curl \
22
--request POST \
3-
--header "Apikey: dummy.api.key" \
43
--header "Authorization: Bearer accesstoken" \
54
--header "Content-Type: application/json" \
65
--header "X-Client-Info: gotrue-swift/x.y.z" \
76
--header "X-Supabase-Api-Version: 2024-01-01" \
7+
--header "apiKey: dummy.api.key" \
88
--data "{\"factor_type\":\"totp\",\"friendly_name\":\"test\",\"issuer\":\"supabase.com\"}" \
99
"http://localhost:54321/auth/v1/factors"
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
curl \
22
--request POST \
3-
--header "Apikey: dummy.api.key" \
43
--header "Authorization: Bearer accesstoken" \
54
--header "Content-Type: application/json" \
65
--header "X-Client-Info: gotrue-swift/x.y.z" \
76
--header "X-Supabase-Api-Version: 2024-01-01" \
7+
--header "apiKey: dummy.api.key" \
88
--data "{\"factor_type\":\"phone\",\"friendly_name\":\"test\",\"phone\":\"+1 202-918-2132\"}" \
99
"http://localhost:54321/auth/v1/factors"
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
curl \
22
--request POST \
3-
--header "Apikey: dummy.api.key" \
43
--header "Authorization: Bearer accesstoken" \
54
--header "Content-Type: application/json" \
65
--header "X-Client-Info: gotrue-swift/x.y.z" \
76
--header "X-Supabase-Api-Version: 2024-01-01" \
7+
--header "apiKey: dummy.api.key" \
88
--data "{\"factor_type\":\"totp\",\"friendly_name\":\"test\",\"issuer\":\"supabase.com\"}" \
99
"http://localhost:54321/auth/v1/factors"
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
curl \
22
--request DELETE \
3-
--header "Apikey: dummy.api.key" \
43
--header "Authorization: Bearer accesstoken" \
54
--header "X-Client-Info: gotrue-swift/x.y.z" \
65
--header "X-Supabase-Api-Version: 2024-01-01" \
6+
--header "apiKey: dummy.api.key" \
77
"http://localhost:54321/auth/v1/factors/123"
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
curl \
22
--request POST \
3-
--header "Apikey: dummy.api.key" \
43
--header "Authorization: Bearer accesstoken" \
54
--header "Content-Type: application/json" \
65
--header "X-Client-Info: gotrue-swift/x.y.z" \
76
--header "X-Supabase-Api-Version: 2024-01-01" \
7+
--header "apiKey: dummy.api.key" \
88
--data "{\"challenge_id\":\"123\",\"code\":\"123456\",\"factor_id\":\"123\"}" \
99
"http://localhost:54321/auth/v1/factors/123/verify"
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
curl \
2-
--header "Apikey: dummy.api.key" \
32
--header "Authorization: Bearer accesstoken" \
43
--header "X-Client-Info: gotrue-swift/x.y.z" \
54
--header "X-Supabase-Api-Version: 2024-01-01" \
5+
--header "apiKey: dummy.api.key" \
66
"http://localhost:54321/auth/v1/reauthenticate"
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
curl \
22
--request POST \
3-
--header "Apikey: dummy.api.key" \
43
--header "Content-Type: application/json" \
54
--header "X-Client-Info: gotrue-swift/x.y.z" \
65
--header "X-Supabase-Api-Version: 2024-01-01" \
6+
--header "apiKey: dummy.api.key" \
77
--data "{\"refresh_token\":\"refresh-token\"}" \
88
"http://localhost:54321/auth/v1/token?grant_type=refresh_token"
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
curl \
22
--request POST \
3-
--header "Apikey: dummy.api.key" \
43
--header "Content-Type: application/json" \
54
--header "X-Client-Info: gotrue-swift/x.y.z" \
65
--header "X-Supabase-Api-Version: 2024-01-01" \
6+
--header "apiKey: dummy.api.key" \
77
--data "{\"email\":\"[email protected]\",\"gotrue_meta_security\":{\"captcha_token\":\"captcha-token\"},\"type\":\"email_change\"}" \
88
"http://localhost:54321/auth/v1/resend?redirect_to=https://supabase.com"
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
curl \
22
--request POST \
3-
--header "Apikey: dummy.api.key" \
43
--header "Content-Type: application/json" \
54
--header "X-Client-Info: gotrue-swift/x.y.z" \
65
--header "X-Supabase-Api-Version: 2024-01-01" \
6+
--header "apiKey: dummy.api.key" \
77
--data "{\"gotrue_meta_security\":{\"captcha_token\":\"captcha-token\"},\"phone\":\"+1 202-918-2132\",\"type\":\"phone_change\"}" \
88
"http://localhost:54321/auth/v1/resend"
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
curl \
22
--request POST \
3-
--header "Apikey: dummy.api.key" \
43
--header "Content-Type: application/json" \
54
--header "X-Client-Info: gotrue-swift/x.y.z" \
65
--header "X-Supabase-Api-Version: 2024-01-01" \
6+
--header "apiKey: dummy.api.key" \
77
--data "{\"email\":\"[email protected]\",\"gotrue_meta_security\":{\"captcha_token\":\"captcha-token\"}}" \
88
"http://localhost:54321/auth/v1/recover?redirect_to=https://supabase.com"
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
curl \
2-
--header "Apikey: dummy.api.key" \
32
--header "Authorization: bearer accesstoken" \
43
--header "X-Client-Info: gotrue-swift/x.y.z" \
54
--header "X-Supabase-Api-Version: 2024-01-01" \
5+
--header "apiKey: dummy.api.key" \
66
"http://localhost:54321/auth/v1/user"
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
curl \
22
--request POST \
3-
--header "Apikey: dummy.api.key" \
43
--header "Content-Type: application/json" \
54
--header "X-Client-Info: gotrue-swift/x.y.z" \
65
--header "X-Supabase-Api-Version: 2024-01-01" \
6+
--header "apiKey: dummy.api.key" \
77
--data "{\"refresh_token\":\"dummy-refresh-token\"}" \
88
"http://localhost:54321/auth/v1/token?grant_type=refresh_token"
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
curl \
2-
--header "Apikey: dummy.api.key" \
32
--header "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjo0ODUyMTYzNTkzLCJzdWIiOiJmMzNkM2VjOS1hMmVlLTQ3YzQtODBlMS01YmQ5MTlmM2Q4YjgiLCJlbWFpbCI6ImhpQGJpbmFyeXNjcmFwaW5nLmNvIiwicGhvbmUiOiIiLCJhcHBfbWV0YWRhdGEiOnsicHJvdmlkZXIiOiJlbWFpbCIsInByb3ZpZGVycyI6WyJlbWFpbCJdfSwidXNlcl9tZXRhZGF0YSI6e30sInJvbGUiOiJhdXRoZW50aWNhdGVkIn0.UiEhoahP9GNrBKw_OHBWyqYudtoIlZGkrjs7Qa8hU7I" \
43
--header "X-Client-Info: gotrue-swift/x.y.z" \
54
--header "X-Supabase-Api-Version: 2024-01-01" \
5+
--header "apiKey: dummy.api.key" \
66
"http://localhost:54321/auth/v1/user"
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
curl \
22
--request POST \
3-
--header "Apikey: dummy.api.key" \
43
--header "Content-Type: application/json" \
54
--header "X-Client-Info: gotrue-swift/x.y.z" \
65
--header "X-Supabase-Api-Version: 2024-01-01" \
6+
--header "apiKey: dummy.api.key" \
77
--data "{\"data\":{\"custom_key\":\"custom_value\"},\"gotrue_meta_security\":{\"captcha_token\":\"captcha-token\"}}" \
88
"http://localhost:54321/auth/v1/signup"

0 commit comments

Comments
 (0)