This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ts
45 lines (40 loc) · 1.68 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { RemoteConfigParams } from '../../common/types/remote-config.types';
import { EnvironmentTypes } from '../../common/types/sdk-options.types';
import { doRequest } from '../../common/utils';
import { RemoteConfig } from './types';
export default class RemoteConfigService {
static REMOTE_CONFIG_BASE_URL: string = 'https://remote-config.superviz.com/sdk';
/**
* @function getRemoteConfig
* @description Retrieves the remote configuration for the specified environment.
* @param environment
The environment to retrieve the remote configuration for. Defaults to EnvironmentTypes.PROD.
* @returns A Promise that resolves with the remote configuration object.
*/
static async getRemoteConfig(
environment: EnvironmentTypes = EnvironmentTypes.PROD,
): Promise<RemoteConfig> {
const { version } = await import('../../../.version.js');
if (environment === EnvironmentTypes.LOCAL) {
const { remoteConfig } = await import('../../../.remote-config.js');
return remoteConfig;
}
const remoteConfigParams: RemoteConfigParams = {
version,
environment,
};
const url = this.createUrl(remoteConfigParams);
return doRequest(url, 'GET', null) as Promise<RemoteConfig>;
}
/**
* @function createUrl
* @description
Creates a URL for fetching remote configuration
data based on the provided version and environment.
* @param {RemoteConfigParams} params - The parameters for creating the URL.
* @returns {string} The URL for fetching remote configuration data.
*/
static createUrl({ version, environment }: RemoteConfigParams) {
return `${this.REMOTE_CONFIG_BASE_URL}/${version}?env=${environment}`;
}
}