parent
4452cb071d
commit
c4d0ec6be0
|
|
@ -1,4 +1,6 @@
|
||||||
import {
|
import {
|
||||||
|
ApiClientError,
|
||||||
|
ApiError,
|
||||||
ApiResponse,
|
ApiResponse,
|
||||||
LibreCcmApiClient,
|
LibreCcmApiClient,
|
||||||
} from "@libreccm/ccm-apiclient-commons";
|
} from "@libreccm/ccm-apiclient-commons";
|
||||||
|
|
@ -21,10 +23,9 @@ export class ConfigurationApiClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getConfigurations(): Promise<ConfigurationInfo[]> {
|
async getConfigurations(): Promise<ConfigurationInfo[]> {
|
||||||
|
const url = `${this.#CONFIGURATION_API_PREFIX}/`;
|
||||||
try {
|
try {
|
||||||
const response: ApiResponse = await this.#apiClient.get(
|
const response: ApiResponse = await this.#apiClient.get(url);
|
||||||
`${this.#CONFIGURATION_API_PREFIX}/`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const result: Record<
|
const result: Record<
|
||||||
|
|
@ -36,19 +37,29 @@ export class ConfigurationApiClient {
|
||||||
buildConfigurationInfoFromRecord(record)
|
buildConfigurationInfoFromRecord(record)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
throw `Failed to retrieve configuration info:
|
throw new ApiError(
|
||||||
${response.status} ${response.statusText}`;
|
response.status,
|
||||||
|
response.statusText,
|
||||||
|
"get",
|
||||||
|
`Failed to retrieve configuration info`,
|
||||||
|
url
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw `Failed to retrieve configuration info: ${err}`;
|
if (err instanceof ApiError) {
|
||||||
|
throw err;
|
||||||
|
} else {
|
||||||
|
throw new ApiClientError(
|
||||||
|
`Failed to retrieve configuration info: ${err}`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getConfiguration(confName: string): Promise<ConfigurationInfo> {
|
async getConfiguration(confName: string): Promise<ConfigurationInfo> {
|
||||||
|
const url = `${this.#CONFIGURATION_API_PREFIX}/${confName}`;
|
||||||
try {
|
try {
|
||||||
const response: ApiResponse = await this.#apiClient.get(
|
const response: ApiResponse = await this.#apiClient.get(url);
|
||||||
`${this.#CONFIGURATION_API_PREFIX}/${confName}`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const result: Record<
|
const result: Record<
|
||||||
|
|
@ -58,53 +69,78 @@ export class ConfigurationApiClient {
|
||||||
|
|
||||||
return buildConfigurationInfoFromRecord(result);
|
return buildConfigurationInfoFromRecord(result);
|
||||||
} else {
|
} else {
|
||||||
throw `Failed to get configuration info for
|
throw new ApiError(
|
||||||
configuration ${confName}:
|
response.status,
|
||||||
${response.status} ${response.statusText}`;
|
response.statusText,
|
||||||
|
"get",
|
||||||
|
`Failed to get configuration info for configuration ${confName}`,
|
||||||
|
url
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw `Failed to get configuration info for
|
if (err instanceof ApiError) {
|
||||||
configuration ${confName}: ${err}`;
|
throw err;
|
||||||
|
} else {
|
||||||
|
throw new ApiClientError(
|
||||||
|
`Failed to get configuration info for configuration ${confName}: ${err}`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSettings(confName: string): Promise<Record<string, unknown>> {
|
async getSettings(confName: string): Promise<Record<string, unknown>> {
|
||||||
|
const url = `${this.#CONFIGURATION_API_PREFIX}/${confName}/settings`;
|
||||||
try {
|
try {
|
||||||
const response: ApiResponse = await this.#apiClient.get(
|
const response: ApiResponse = await this.#apiClient.get(url);
|
||||||
`${this.#CONFIGURATION_API_PREFIX}/${confName}/settings`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return (await response.json()) as Record<string, unknown>;
|
return (await response.json()) as Record<string, unknown>;
|
||||||
} else {
|
} else {
|
||||||
throw `Failed to get settings of
|
throw new ApiError(
|
||||||
configuration ${confName}:
|
response.status,
|
||||||
${response.status} ${response.statusText}`;
|
response.statusText,
|
||||||
|
"get",
|
||||||
|
`Failed to get settings of configuration ${confName}`,
|
||||||
|
url
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw `Failed to get settings of
|
if (err instanceof ApiError) {
|
||||||
configuration ${confName}: ${err}`;
|
throw err;
|
||||||
|
} else {
|
||||||
|
throw new ApiClientError(
|
||||||
|
`Failed to get settings of configuration ${confName}: ${err}`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSetting(confName: string, setting: string): Promise<unknown> {
|
async getSetting(confName: string, setting: string): Promise<unknown> {
|
||||||
|
const url = `${
|
||||||
|
this.#CONFIGURATION_API_PREFIX
|
||||||
|
}/${confName}/settings/${setting}`;
|
||||||
try {
|
try {
|
||||||
const response: ApiResponse = await this.#apiClient.get(
|
const response: ApiResponse = await this.#apiClient.get(url);
|
||||||
`${
|
|
||||||
this.#CONFIGURATION_API_PREFIX
|
|
||||||
}/${confName}/settings/${setting}`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return await response.json();
|
return await response.json();
|
||||||
} else {
|
} else {
|
||||||
throw `Failed to get setting ${setting} of
|
throw new ApiError(
|
||||||
configuration ${confName}:
|
response.status,
|
||||||
${response.status} ${response.statusText}`;
|
response.statusText,
|
||||||
|
"get",
|
||||||
|
`Failed to get setting ${setting} of configuration ${confName}`,
|
||||||
|
url
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw `Failed to get setting ${setting} of
|
if (err instanceof ApiError) {
|
||||||
configuration ${confName}: ${err}`;
|
throw err;
|
||||||
|
} else {
|
||||||
|
throw new ApiClientError(
|
||||||
|
`Failed to get setting ${setting} of configuration ${confName}: ${err}`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,24 +149,34 @@ export class ConfigurationApiClient {
|
||||||
setting: string,
|
setting: string,
|
||||||
value: unknown
|
value: unknown
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
const url = `${
|
||||||
|
this.#CONFIGURATION_API_PREFIX
|
||||||
|
}/${confName}/settings/${setting}`;
|
||||||
try {
|
try {
|
||||||
const response: ApiResponse = await this.#apiClient.put(
|
const response: ApiResponse = await this.#apiClient.put(
|
||||||
`${
|
url,
|
||||||
this.#CONFIGURATION_API_PREFIX
|
|
||||||
}/${confName}/settings/${setting}`,
|
|
||||||
value as RequestBody
|
value as RequestBody
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
throw `Failed to update setting ${setting} of
|
throw new ApiError(
|
||||||
configuration ${confName}:
|
response.status,
|
||||||
${response.status} ${response.statusText}`;
|
response.statusText,
|
||||||
|
"put",
|
||||||
|
`Failed to update setting ${setting} of configuration ${confName}`,
|
||||||
|
url
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw `Failed to update setting ${setting} of
|
if (err instanceof ApiError) {
|
||||||
configuration ${confName}: ${err}`;
|
throw err;
|
||||||
|
} else {
|
||||||
|
throw new ApiClientError(
|
||||||
|
`Failed to update setting ${setting} of configuration ${confName}: ${err}`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue