testIntegrationConnection method

Future<OrgIntegrationModel> testIntegrationConnection({
  1. required String orgId,
  2. required String provider,
})

Forces a live round-trip with the provider (auth.test / users/me / users/me) and returns the refreshed row. On failure the server flips status to 'degraded' and records last_error.

Implementation

Future<OrgIntegrationModel> testIntegrationConnection({
  required String orgId,
  required String provider,
}) async {
  final response = await _client.functions.invoke(
    'integrations-test',
    body: {'org_id': orgId, 'provider': provider},
  );
  if (response.status != 200) {
    throw StateError(
      'testConnection failed (${response.status}): ${response.data}',
    );
  }
  final row = response.data?['integration'] as Map<String, dynamic>?;
  if (row == null) {
    throw StateError('testConnection returned no integration');
  }
  return OrgIntegrationModel.fromJson(row);
}