• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wger-project / flutter / 30901196754

04 Aug 2026 10:34AM UTC coverage: 51.289% (-1.8%) from 53.103%
30901196754

Pull #1301

github

web-flow
Merge 5c77a99bf into e3affdd4f
Pull Request #1301: feat : implemented dynamic colour support

98 of 138 new or added lines in 24 files covered. (71.01%)

1088 existing lines in 87 files now uncovered.

11659 of 22732 relevant lines covered (51.29%)

5.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.12
/lib/powersync/api_client.dart
1
/*
2
 * This file is part of wger Workout Manager <https://github.com/wger-project>.
3
 * Copyright (c) 2020,  wger Team
4
 *
5
 * wger Workout Manager is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Affero General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU Affero General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Affero General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18

19
import 'dart:convert';
20
import 'dart:io';
21

22
import 'package:http/http.dart' as http;
23

24
/// Thin REST client used by the PowerSync connector.
25
///
26
/// In production the [http.Client] passed in is the project-wide
27
/// `AuthHttpClient`, which injects the right `Authorization` header
28
/// (`Bearer` for headless JWT, `Token` for legacy permanent tokens) and
29
/// runs pre-emptive refresh ahead of token expiry. This class itself
30
/// therefore stays auth-agnostic: it only sets `Content-Type` and lets
31
/// the client own everything else.
32
class ApiClient {
33
  late final uri = Uri.parse('$serverUrl/api/v2/upload-powersync-data');
12✔
34

35
  final String serverUrl;
36
  final http.Client _client;
37

38
  ApiClient(this.serverUrl, {http.Client? client}) : _client = client ?? http.Client();
3✔
39

40
  Map<String, String> getHeaders() {
3✔
41
    return {HttpHeaders.contentTypeHeader: 'application/json'};
3✔
42
  }
43

44
  /// Fetches a short-lived PowerSync JWT and its endpoint URL from the
45
  /// wger backend. The `Authorization` header for this request is set
46
  /// by the underlying `AuthHttpClient` based on the current auth state.
47
  Future<Map<String, dynamic>> getPowersyncToken() async {
1✔
48
    final response = await _client.get(
2✔
49
      Uri.parse('$serverUrl/api/v2/powersync-token'),
3✔
50
      headers: getHeaders(),
1✔
51
    );
52

53
    if (response.statusCode == 200) {
2✔
UNCOV
54
      return json.decode(response.body);
×
55
    }
56
    throw Exception('Failed to fetch token');
1✔
57
  }
58

59
  // Return the raw [http.Response] so the connector can inspect status and
60
  // body. The backend encodes permanent rejections as 200 + `{'error': ...}`
61
  // (a non-2xx would trigger PowerSync's retry loop). Infrastructure and
62
  // unhandled 5xx aren't part of that contract; the connector classifies and
63
  // retries those.
64
  Future<http.Response> upsert(Map<String, dynamic> record) {
2✔
65
    return _client.put(uri, headers: getHeaders(), body: json.encode(record));
10✔
66
  }
67

68
  Future<http.Response> update(Map<String, dynamic> record) {
1✔
69
    return _client.patch(uri, headers: getHeaders(), body: json.encode(record));
5✔
70
  }
71

72
  Future<http.Response> delete(Map<String, dynamic> record) {
1✔
73
    return _client.delete(uri, headers: getHeaders(), body: json.encode(record));
5✔
74
  }
75
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc