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

safe-global / safe-client-gateway / 13409143813

19 Feb 2025 09:15AM UTC coverage: 90.84% (-0.3%) from 91.123%
13409143813

push

github

iamacook
fix: add auth tests for invite/role changes and ensure active admin

2975 of 3600 branches covered (82.64%)

Branch coverage included in aggregate %.

10136 of 10833 relevant lines covered (93.57%)

525.81 hits per line

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

95.0
/src/datasources/network/network.module.ts
1
import { Global, Module } from '@nestjs/common';
104✔
2
import { IConfigurationService } from '@/config/configuration.service.interface';
104✔
3
import { FetchNetworkService } from '@/datasources/network/fetch.network.service';
104✔
4
import { NetworkService } from '@/datasources/network/network.service.interface';
104✔
5
import { NetworkResponse } from '@/datasources/network/entities/network.response.entity';
6
import {
104✔
7
  NetworkRequestError,
8
  NetworkResponseError,
9
} from '@/datasources/network/entities/network.error.entity';
10
import type { Raw } from '@/validation/entities/raw.entity';
11

12
export type FetchClient = <T>(
13
  url: string,
14
  options: RequestInit,
15
) => Promise<NetworkResponse<T>>;
16

17
/**
18
 * Use this factory to create a {@link FetchClient} instance
19
 * that can be used to make HTTP requests.
20
 */
21
function fetchClientFactory(
22
  configurationService: IConfigurationService,
23
): FetchClient {
24
  const requestTimeout = configurationService.getOrThrow<number>(
8✔
25
    'httpClient.requestTimeout',
26
  );
27

28
  return async <T>(
8✔
29
    url: string,
30
    options: RequestInit,
31
  ): Promise<NetworkResponse<T>> => {
32
    let urlObject: URL | null = null;
8✔
33
    let response: Response | null = null;
8✔
34

35
    try {
8✔
36
      urlObject = new URL(url);
8✔
37
      response = await fetch(url, {
6✔
38
        ...options,
39
        signal: AbortSignal.timeout(requestTimeout),
40
        keepalive: true,
41
      });
42
    } catch (error) {
43
      throw new NetworkRequestError(urlObject, error);
4✔
44
    }
45

46
    // We validate data so don't need worry about casting `null` response
47
    const data = (await response.json().catch(() => null)) as Raw<T>;
4✔
48

49
    if (!response.ok) {
2✔
50
      throw new NetworkResponseError(urlObject, response, data);
2✔
51
    }
52

53
    return {
×
54
      status: response.status,
55
      data,
56
    };
57
  };
58
}
59

60
/**
61
 * A {@link Global} Module which provides HTTP support via {@link NetworkService}
62
 * Feature Modules don't need to import this module directly in order to inject
63
 * the {@link NetworkService}.
64
 *
65
 * This module should be included in the "root" application module
66
 */
67
@Global()
68
@Module({
69
  providers: [
70
    {
71
      provide: 'FetchClient',
72
      useFactory: fetchClientFactory,
73
      inject: [IConfigurationService],
74
    },
75
    { provide: NetworkService, useClass: FetchNetworkService },
76
  ],
77
  exports: [NetworkService],
78
})
79
export class NetworkModule {}
104✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc