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

wger-project / flutter / 30579654902

30 Jul 2026 08:32PM UTC coverage: 53.103% (-2.8%) from 55.93%
30579654902

push

github

web-flow
Merge pull request #1227 from wger-project/default-weight-profile

Default weight profile

18 of 20 new or added lines in 8 files covered. (90.0%)

672 existing lines in 83 files now uncovered.

12039 of 22671 relevant lines covered (53.1%)

5.23 hits per line

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

88.24
/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');
8✔
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 {
2✔
48
    final response = await _client.get(
4✔
49
      Uri.parse('$serverUrl/api/v2/powersync-token'),
6✔
50
      headers: getHeaders(),
2✔
51
    );
52

53
    if (response.statusCode == 200) {
4✔
54
      return json.decode(response.body);
2✔
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) {
1✔
65
    return _client.put(uri, headers: getHeaders(), body: json.encode(record));
5✔
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

UNCOV
72
  Future<http.Response> delete(Map<String, dynamic> record) {
×
UNCOV
73
    return _client.delete(uri, headers: getHeaders(), body: json.encode(record));
×
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