mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
Refactor API calls to use new request structure
- Updated API.post and API.get calls across multiple components to use the new object structure for requests, including specifying `url`, `data`, and `headers` explicitly. - This change improves code readability and consistency in how API requests are made throughout the application.
This commit is contained in:
@@ -228,7 +228,8 @@ const LoginPage: () => JSX.Element = () => {
|
||||
selectedTwoFactorAuth.id?.toString() as string;
|
||||
|
||||
const result: HTTPErrorResponse | HTTPResponse<JSONObject> =
|
||||
await API.post(VERIFY_TWO_FACTOR_AUTH_API_URL, {
|
||||
await API.post({
|
||||
url: VERIFY_TWO_FACTOR_AUTH_API_URL,
|
||||
data: {
|
||||
...initialValues,
|
||||
code: code,
|
||||
|
||||
@@ -42,12 +42,12 @@ const LoginPage: () => JSX.Element = () => {
|
||||
try {
|
||||
// get sso config by email.
|
||||
const listResult: HTTPErrorResponse | HTTPResponse<JSONArray> =
|
||||
await API.get(
|
||||
URL.fromString(apiUrl.toString()).addQueryParam(
|
||||
await API.get({
|
||||
url: URL.fromString(apiUrl.toString()).addQueryParam(
|
||||
"email",
|
||||
email.toString(),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
if (listResult instanceof HTTPErrorResponse) {
|
||||
throw listResult;
|
||||
|
||||
@@ -54,9 +54,9 @@ const DashboardFooter: () => JSX.Element = () => {
|
||||
const fetchAppVersion: (appName: string) => Promise<JSONObject> = async (
|
||||
appName: string,
|
||||
): Promise<JSONObject> => {
|
||||
const response: HTTPResponse<JSONObject> = await API.get<JSONObject>(
|
||||
URL.fromString(`${HTTP_PROTOCOL}/${HOST}${appName}/version`),
|
||||
);
|
||||
const response: HTTPResponse<JSONObject> = await API.get<JSONObject>({
|
||||
url: URL.fromString(`${HTTP_PROTOCOL}/${HOST}${appName}/version`),
|
||||
});
|
||||
|
||||
if (response.data) {
|
||||
return response.data as JSONObject;
|
||||
|
||||
@@ -54,17 +54,19 @@ export default class SlackUtil extends WorkspaceBase {
|
||||
|
||||
const response: HTTPErrorResponse | HTTPResponse<JSONObject> =
|
||||
await API.post<JSONObject>(
|
||||
URL.fromString("https://slack.com/api/users.info"),
|
||||
{
|
||||
user: data.userId,
|
||||
},
|
||||
{
|
||||
Authorization: `Bearer ${data.authToken}`,
|
||||
["Content-Type"]: "application/x-www-form-urlencoded",
|
||||
},
|
||||
{
|
||||
retries: 3,
|
||||
exponentialBackoff: true,
|
||||
url: URL.fromString("https://slack.com/api/users.info"),
|
||||
data: {
|
||||
user: data.userId,
|
||||
},
|
||||
headers: {
|
||||
Authorization: `Bearer ${data.authToken}`,
|
||||
["Content-Type"]: "application/x-www-form-urlencoded",
|
||||
},
|
||||
options: {
|
||||
retries: 3,
|
||||
exponentialBackoff: true,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -93,15 +93,15 @@ const LogsViewer: FunctionComponent<ComponentProps> = (
|
||||
setServiceMap(services);
|
||||
|
||||
const attributeRepsonse: HTTPResponse<JSONObject> | HTTPErrorResponse =
|
||||
await API.post(
|
||||
URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
await API.post({
|
||||
url: URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
"/telemetry/logs/get-attributes",
|
||||
),
|
||||
{},
|
||||
{
|
||||
data: {},
|
||||
headers: {
|
||||
...ModelAPI.getCommonHeaders(),
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
if (attributeRepsonse instanceof HTTPErrorResponse) {
|
||||
throw attributeRepsonse;
|
||||
|
||||
@@ -111,11 +111,11 @@ const ModelList: <TBaseModel extends BaseModel>(
|
||||
};
|
||||
|
||||
if (props.overrideFetchApiUrl) {
|
||||
const result: HTTPResponse<JSONArray> = (await API.post(
|
||||
props.overrideFetchApiUrl,
|
||||
{},
|
||||
{},
|
||||
)) as HTTPResponse<JSONArray>;
|
||||
const result: HTTPResponse<JSONArray> = (await API.post({
|
||||
url: props.overrideFetchApiUrl,
|
||||
data: {},
|
||||
headers: {},
|
||||
})) as HTTPResponse<JSONArray>;
|
||||
|
||||
listResult = {
|
||||
data: BaseModel.fromJSONArray(
|
||||
|
||||
@@ -38,14 +38,14 @@ const DocumentationViewer: FunctionComponent<ComponentProps> = (
|
||||
if (props.documentationLink) {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
const body: HTTPResponse<any> = await API.get(
|
||||
new URL(HTTP_PROTOCOL, HOST, props.documentationLink),
|
||||
{},
|
||||
{
|
||||
const body: HTTPResponse<any> = await API.get({
|
||||
url: new URL(HTTP_PROTOCOL, HOST, props.documentationLink),
|
||||
data: {},
|
||||
headers: {
|
||||
Accept: "text/plain",
|
||||
"Content-Type": "text/plain",
|
||||
},
|
||||
);
|
||||
});
|
||||
setMarkdown(populateWithEnvVars((body.data as any).data.toString()));
|
||||
setIsLoading(false);
|
||||
} catch (err) {
|
||||
|
||||
@@ -54,9 +54,9 @@ const DashboardFooter: () => JSX.Element = () => {
|
||||
const fetchAppVersion: (appName: string) => Promise<JSONObject> = async (
|
||||
appName: string,
|
||||
): Promise<JSONObject> => {
|
||||
const response: HTTPResponse<JSONObject> = await API.get<JSONObject>(
|
||||
URL.fromString(`${HTTP_PROTOCOL}/${HOST}${appName}/version`),
|
||||
);
|
||||
const response: HTTPResponse<JSONObject> = await API.get<JSONObject>({
|
||||
url: URL.fromString(`${HTTP_PROTOCOL}/${HOST}${appName}/version`),
|
||||
});
|
||||
|
||||
if (response.data) {
|
||||
return response.data as JSONObject;
|
||||
|
||||
@@ -100,15 +100,15 @@ const MonitorStepElement: FunctionComponent<ComponentProps> = (
|
||||
|
||||
const fetchLogAttributes: PromiseVoidFunction = async (): Promise<void> => {
|
||||
const attributeRepsonse: HTTPResponse<JSONObject> | HTTPErrorResponse =
|
||||
await API.post(
|
||||
URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
await API.post({
|
||||
url: URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
"/telemetry/logs/get-attributes",
|
||||
),
|
||||
{},
|
||||
{
|
||||
data: {},
|
||||
headers: {
|
||||
...ModelAPI.getCommonHeaders(),
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
if (attributeRepsonse instanceof HTTPErrorResponse) {
|
||||
throw attributeRepsonse;
|
||||
@@ -122,15 +122,15 @@ const MonitorStepElement: FunctionComponent<ComponentProps> = (
|
||||
|
||||
const fetchSpanAttributes: PromiseVoidFunction = async (): Promise<void> => {
|
||||
const attributeRepsonse: HTTPResponse<JSONObject> | HTTPErrorResponse =
|
||||
await API.post(
|
||||
URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
await API.post({
|
||||
url: URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
"/telemetry/traces/get-attributes",
|
||||
),
|
||||
{},
|
||||
{
|
||||
data: {},
|
||||
headers: {
|
||||
...ModelAPI.getCommonHeaders(),
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
if (attributeRepsonse instanceof HTTPErrorResponse) {
|
||||
throw attributeRepsonse;
|
||||
|
||||
@@ -214,15 +214,15 @@ const DashboardHeader: FunctionComponent<ComponentProps> = (
|
||||
|
||||
if (projectId) {
|
||||
const response: HTTPResponse<JSONObject> | HTTPErrorResponse =
|
||||
await API.get<JSONObject>(
|
||||
URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
await API.get<JSONObject>({
|
||||
url: URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
`/${
|
||||
new OnCallDutyPolicy().crudApiPath
|
||||
}/current-on-duty-escalation-policies`,
|
||||
),
|
||||
{},
|
||||
ModelAPI.getCommonHeaders(),
|
||||
);
|
||||
data: {},
|
||||
headers: ModelAPI.getCommonHeaders(),
|
||||
});
|
||||
|
||||
if (response.isFailure()) {
|
||||
throw response;
|
||||
|
||||
@@ -130,9 +130,9 @@ const SlackIntegration: FunctionComponent<ComponentProps> = (
|
||||
|
||||
// fetch app manifest.
|
||||
const response: HTTPErrorResponse | HTTPResponse<JSONObject> =
|
||||
await API.get<JSONObject>(
|
||||
URL.fromString(`${HOME_URL.toString()}/api/slack/app-manifest`),
|
||||
);
|
||||
await API.get<JSONObject>({
|
||||
url: URL.fromString(`${HOME_URL.toString()}/api/slack/app-manifest`),
|
||||
});
|
||||
|
||||
if (response instanceof HTTPErrorResponse) {
|
||||
throw response;
|
||||
|
||||
@@ -69,15 +69,15 @@ const TraceTable: FunctionComponent<ComponentProps> = (
|
||||
setIsPageLoading(true);
|
||||
|
||||
const attributeRepsonse: HTTPResponse<JSONObject> | HTTPErrorResponse =
|
||||
await API.post(
|
||||
URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
await API.post({
|
||||
url: URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
"/telemetry/traces/get-attributes",
|
||||
),
|
||||
{},
|
||||
{
|
||||
data: {},
|
||||
headers: {
|
||||
...ModelAPI.getCommonHeaders(),
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
if (attributeRepsonse instanceof HTTPErrorResponse) {
|
||||
throw attributeRepsonse;
|
||||
|
||||
@@ -106,13 +106,12 @@ const WorkspaceNotificationRuleTable: FunctionComponent<ComponentProps> = (
|
||||
|
||||
// test rule
|
||||
const response: HTTPResponse<EmptyResponseData> | HTTPErrorResponse =
|
||||
await API.get(
|
||||
URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
await API.get({
|
||||
url: URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
`/workspace-notification-rule/test/${ruleId.toString()}`,
|
||||
),
|
||||
|
||||
{},
|
||||
);
|
||||
data: {},
|
||||
});
|
||||
if (response.isSuccess()) {
|
||||
setIsTestLoading(false);
|
||||
setShowTestModal(false);
|
||||
|
||||
@@ -64,11 +64,11 @@ const CopilotDocuementationPage: FunctionComponent<
|
||||
// http://localhost/docs/copilot/introduction
|
||||
|
||||
const documentation: HTTPErrorResponse | HTTPResponse<JSONObject> =
|
||||
(await API.get(
|
||||
URL.fromString(DOCS_URL.toString()).addRoute(
|
||||
(await API.get({
|
||||
url: URL.fromString(DOCS_URL.toString()).addRoute(
|
||||
"/as-markdown/copilot/introduction",
|
||||
),
|
||||
)) as HTTPErrorResponse | HTTPResponse<JSONObject>;
|
||||
})) as HTTPErrorResponse | HTTPResponse<JSONObject>;
|
||||
|
||||
if (documentation instanceof HTTPErrorResponse) {
|
||||
setError(API.getFriendlyMessage(documentation));
|
||||
|
||||
@@ -191,18 +191,17 @@ const Home: FunctionComponent<PageComponentProps> = (): ReactElement => {
|
||||
setVerificationLoading(true);
|
||||
setVerificationError("");
|
||||
|
||||
// test CallSMS config
|
||||
const response:
|
||||
| HTTPResponse<EmptyResponseData>
|
||||
| HTTPErrorResponse = await API.post(
|
||||
URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
| HTTPErrorResponse = await API.post({
|
||||
url: URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
`/user-two-factor-auth/validate`,
|
||||
),
|
||||
{
|
||||
data: {
|
||||
code: values["code"],
|
||||
id: selectedTwoFactorAuth.id?.toString(),
|
||||
},
|
||||
);
|
||||
});
|
||||
if (response.isSuccess()) {
|
||||
setShowVerificationModal(false);
|
||||
setVerificationError(null);
|
||||
|
||||
@@ -128,11 +128,11 @@ const MonitorView: FunctionComponent<PageComponentProps> = (): ReactElement => {
|
||||
setError("");
|
||||
|
||||
try {
|
||||
await API.get(
|
||||
URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
await API.get({
|
||||
url: URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
"/monitor/refresh-status/" + modelId.toString(),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
const monitorStatus: ListResult<MonitorStatusTimeline> =
|
||||
await ModelAPI.getList({
|
||||
|
||||
@@ -118,13 +118,12 @@ const Settings: FunctionComponent<ComponentProps> = (
|
||||
|
||||
// Fetch customer balance
|
||||
try {
|
||||
const balanceResponse: HTTPResponse<JSONObject> = await BaseAPI.get<JSONObject>(
|
||||
URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
const balanceResponse: HTTPResponse<JSONObject> = await BaseAPI.get<JSONObject>({
|
||||
url: URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
`/billing/customer-balance`,
|
||||
),
|
||||
undefined, // data
|
||||
ModelAPI.getCommonHeaders(), // headers
|
||||
);
|
||||
headers: ModelAPI.getCommonHeaders(), // headers
|
||||
});
|
||||
const balanceData: JSONObject = balanceResponse.data;
|
||||
setBalance(balanceData["balance"] as number);
|
||||
} catch (balanceErr) {
|
||||
@@ -143,13 +142,13 @@ const Settings: FunctionComponent<ComponentProps> = (
|
||||
try {
|
||||
setIsModalLoading(true);
|
||||
|
||||
const response: HTTPResponse<JSONObject> = await BaseAPI.post<JSONObject>(
|
||||
URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
const response: HTTPResponse<JSONObject> = await BaseAPI.post<JSONObject>({
|
||||
url: URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
`/billing-payment-methods/setup`,
|
||||
),
|
||||
{},
|
||||
ModelAPI.getCommonHeaders(),
|
||||
);
|
||||
data: {},
|
||||
headers: ModelAPI.getCommonHeaders(),
|
||||
});
|
||||
const data: JSONObject = response.data;
|
||||
|
||||
setSetupIntent(data["setupIntent"] as string);
|
||||
|
||||
@@ -59,18 +59,18 @@ const Settings: FunctionComponent<ComponentProps> = (
|
||||
try {
|
||||
setIsLoading(true);
|
||||
|
||||
const result: HTTPResponse<JSONObject> = await BaseAPI.post<JSONObject>(
|
||||
URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
const result: HTTPResponse<JSONObject> = await BaseAPI.post<JSONObject>({
|
||||
url: URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
`/billing-invoices/pay`,
|
||||
),
|
||||
{
|
||||
data: {
|
||||
data: {
|
||||
paymentProviderInvoiceId: invoiceId,
|
||||
paymentProviderCustomerId: customerId,
|
||||
},
|
||||
},
|
||||
ModelAPI.getCommonHeaders(),
|
||||
);
|
||||
headers: ModelAPI.getCommonHeaders(),
|
||||
});
|
||||
|
||||
if (result.isFailure()) {
|
||||
throw result;
|
||||
|
||||
@@ -311,15 +311,15 @@ const Settings: FunctionComponent<PageComponentProps> = (): ReactElement => {
|
||||
setIsRechargeBalanceLoading(true);
|
||||
try {
|
||||
const response: HTTPResponse<JSONObject> | HTTPErrorResponse =
|
||||
await API.post(
|
||||
URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
await API.post({
|
||||
url: URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
"/notification/recharge",
|
||||
),
|
||||
{
|
||||
data: {
|
||||
amount: item["amount"],
|
||||
projectId: ProjectUtil.getCurrentProjectId()!,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
if (response.isFailure()) {
|
||||
setRechargeBalanceError(API.getFriendlyMessage(response));
|
||||
|
||||
@@ -376,15 +376,15 @@ const StatusPageDelete: FunctionComponent<PageComponentProps> = (
|
||||
setError("");
|
||||
|
||||
const response: HTTPResponse<JSONObject> | HTTPErrorResponse =
|
||||
await API.get<JSONObject>(
|
||||
URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
await API.get<JSONObject>({
|
||||
url: URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
`/${
|
||||
new StatusPageDomain().crudApiPath
|
||||
}/verify-cname/${selectedStatusPageDomain?.id?.toString()}`,
|
||||
),
|
||||
{},
|
||||
ModelAPI.getCommonHeaders(),
|
||||
);
|
||||
data: {},
|
||||
headers: ModelAPI.getCommonHeaders(),
|
||||
});
|
||||
|
||||
if (response.isFailure()) {
|
||||
throw response;
|
||||
@@ -436,15 +436,15 @@ const StatusPageDelete: FunctionComponent<PageComponentProps> = (
|
||||
setError("");
|
||||
|
||||
const response: HTTPResponse<JSONObject> | HTTPErrorResponse =
|
||||
await API.get<JSONObject>(
|
||||
URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
await API.get<JSONObject>({
|
||||
url: URL.fromString(APP_API_URL.toString()).addRoute(
|
||||
`/${
|
||||
new StatusPageDomain().crudApiPath
|
||||
}/order-ssl/${selectedStatusPageDomain?.id?.toString()}`,
|
||||
),
|
||||
{},
|
||||
ModelAPI.getCommonHeaders(),
|
||||
);
|
||||
data: {},
|
||||
headers: ModelAPI.getCommonHeaders(),
|
||||
});
|
||||
|
||||
if (response.isFailure()) {
|
||||
throw response;
|
||||
|
||||
@@ -57,16 +57,16 @@ const StatusPageDelete: FunctionComponent<
|
||||
|
||||
// get status page id by hostname.
|
||||
const response: HTTPResponse<JSONObject> | HTTPErrorResponse =
|
||||
await API.post<JSONObject>(
|
||||
URL.fromString(STATUS_PAGE_API_URL.toString()).addRoute(
|
||||
await API.post<JSONObject>({
|
||||
url: URL.fromString(STATUS_PAGE_API_URL.toString()).addRoute(
|
||||
`/test-email-report`,
|
||||
),
|
||||
{
|
||||
data: {
|
||||
statusPageId: modelId.toString(),
|
||||
email: testEmail.email.toString(),
|
||||
},
|
||||
{},
|
||||
);
|
||||
headers: {},
|
||||
});
|
||||
|
||||
if (response instanceof HTTPErrorResponse) {
|
||||
setError(API.getFriendlyMessage(response));
|
||||
|
||||
@@ -314,14 +314,14 @@ const Delete: FunctionComponent<PageComponentProps> = (): ReactElement => {
|
||||
onRun={async (component: NodeDataProp) => {
|
||||
try {
|
||||
const result: HTTPErrorResponse | HTTPResponse<JSONObject> =
|
||||
await API.post(
|
||||
URL.fromString(WORKFLOW_URL.toString()).addRoute(
|
||||
await API.post({
|
||||
url: URL.fromString(WORKFLOW_URL.toString()).addRoute(
|
||||
"/manual/run/" + modelId.toString(),
|
||||
),
|
||||
{
|
||||
data: {
|
||||
data: component.arguments,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
if (result instanceof HTTPErrorResponse) {
|
||||
throw result;
|
||||
|
||||
@@ -93,17 +93,16 @@ class FetchListAndProbe {
|
||||
).addRoute("/monitor/list");
|
||||
|
||||
const result: HTTPResponse<JSONArray> | HTTPErrorResponse =
|
||||
await API.fetch<JSONArray>(
|
||||
HTTPMethod.POST,
|
||||
monitorListUrl,
|
||||
{
|
||||
await API.fetch<JSONArray>({
|
||||
method: HTTPMethod.POST,
|
||||
url: monitorListUrl,
|
||||
data: {
|
||||
...ProbeAPIRequest.getDefaultRequestBody(),
|
||||
limit: PROBE_MONITOR_FETCH_LIMIT || 100,
|
||||
},
|
||||
{},
|
||||
{},
|
||||
{ ...ProxyConfig.getRequestProxyAgents() },
|
||||
);
|
||||
headers: {},
|
||||
options: { ...ProxyConfig.getRequestProxyAgents() },
|
||||
});
|
||||
|
||||
logger.debug("Fetched monitor list");
|
||||
logger.debug(result);
|
||||
|
||||
@@ -57,17 +57,16 @@ class FetchMonitorTestAndProbe {
|
||||
).addRoute("/monitor-test/list");
|
||||
|
||||
const result: HTTPResponse<JSONArray> | HTTPErrorResponse =
|
||||
await API.fetch<JSONArray>(
|
||||
HTTPMethod.POST,
|
||||
monitorListUrl,
|
||||
{
|
||||
await API.fetch<JSONArray>({
|
||||
method: HTTPMethod.POST,
|
||||
url: monitorListUrl,
|
||||
data: {
|
||||
...ProbeAPIRequest.getDefaultRequestBody(),
|
||||
limit: 100,
|
||||
},
|
||||
{},
|
||||
{},
|
||||
{ ...ProxyConfig.getRequestProxyAgents() },
|
||||
);
|
||||
headers: {},
|
||||
options: { ...ProxyConfig.getRequestProxyAgents() },
|
||||
});
|
||||
|
||||
logger.debug("MONITOR TEST: Fetched monitor test list");
|
||||
logger.debug(result);
|
||||
|
||||
@@ -73,19 +73,18 @@ export default class Register {
|
||||
hostname: HOSTNAME,
|
||||
};
|
||||
|
||||
await API.fetch<JSONObject>(
|
||||
HTTPMethod.POST,
|
||||
URL.fromString(PROBE_INGEST_URL.toString()).addRoute(
|
||||
await API.fetch<JSONObject>({
|
||||
method: HTTPMethod.POST,
|
||||
url: URL.fromString(PROBE_INGEST_URL.toString()).addRoute(
|
||||
"/probe/status-report/offline",
|
||||
),
|
||||
{
|
||||
data: {
|
||||
...ProbeAPIRequest.getDefaultRequestBody(),
|
||||
statusReport: stausReport as any,
|
||||
},
|
||||
{},
|
||||
{},
|
||||
{ ...ProxyConfig.getRequestProxyAgents() },
|
||||
);
|
||||
headers: {},
|
||||
options: { ...ProxyConfig.getRequestProxyAgents() },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,19 +64,18 @@ export default class MonitorUtil {
|
||||
if (result) {
|
||||
// report this back to Probe API.
|
||||
|
||||
await API.fetch<JSONObject>(
|
||||
HTTPMethod.POST,
|
||||
URL.fromString(PROBE_INGEST_URL.toString()).addRoute(
|
||||
await API.fetch<JSONObject>({
|
||||
method: HTTPMethod.POST,
|
||||
url: URL.fromString(PROBE_INGEST_URL.toString()).addRoute(
|
||||
"/probe/response/monitor-test-ingest/" + monitorTest.id?.toString(),
|
||||
),
|
||||
{
|
||||
data: {
|
||||
...ProbeAPIRequest.getDefaultRequestBody(),
|
||||
probeMonitorResponse: result as any,
|
||||
},
|
||||
{},
|
||||
{},
|
||||
{ ...ProxyConfig.getRequestProxyAgents() },
|
||||
);
|
||||
headers: {},
|
||||
options: { ...ProxyConfig.getRequestProxyAgents() },
|
||||
});
|
||||
}
|
||||
|
||||
results.push(result);
|
||||
@@ -114,19 +113,18 @@ export default class MonitorUtil {
|
||||
if (result) {
|
||||
// report this back to Probe API.
|
||||
|
||||
await API.fetch<JSONObject>(
|
||||
HTTPMethod.POST,
|
||||
URL.fromString(PROBE_INGEST_URL.toString()).addRoute(
|
||||
await API.fetch<JSONObject>({
|
||||
method: HTTPMethod.POST,
|
||||
url: URL.fromString(PROBE_INGEST_URL.toString()).addRoute(
|
||||
"/probe/response/ingest",
|
||||
),
|
||||
{
|
||||
data: {
|
||||
...ProbeAPIRequest.getDefaultRequestBody(),
|
||||
probeMonitorResponse: result as any,
|
||||
},
|
||||
{},
|
||||
{},
|
||||
{ ...ProxyConfig.getRequestProxyAgents() },
|
||||
);
|
||||
headers: {},
|
||||
options: { ...ProxyConfig.getRequestProxyAgents() },
|
||||
});
|
||||
}
|
||||
|
||||
results.push(result);
|
||||
|
||||
@@ -60,18 +60,23 @@ export default class ApiMonitor {
|
||||
);
|
||||
|
||||
let startTime: [number, number] = process.hrtime();
|
||||
const fetchOptions: any = {
|
||||
method: requestType,
|
||||
url: url,
|
||||
headers: options.requestHeaders || undefined,
|
||||
options: {
|
||||
timeout: options.timeout?.toNumber() || 5000,
|
||||
doNotFollowRedirects: options.doNotFollowRedirects || false,
|
||||
...ProxyConfig.getRequestProxyAgents(),
|
||||
},
|
||||
};
|
||||
|
||||
if (options.requestBody) {
|
||||
fetchOptions.data = options.requestBody;
|
||||
}
|
||||
|
||||
let result: HTTPResponse<JSONObject> | HTTPErrorResponse =
|
||||
await API.fetch({
|
||||
method: requestType,
|
||||
url: url,
|
||||
data: options.requestBody,
|
||||
headers: options.requestHeaders || undefined,
|
||||
options: {
|
||||
timeout: options.timeout?.toNumber() || 5000,
|
||||
doNotFollowRedirects: options.doNotFollowRedirects || false,
|
||||
...ProxyConfig.getRequestProxyAgents(),
|
||||
},
|
||||
});
|
||||
await API.fetch(fetchOptions);
|
||||
|
||||
if (
|
||||
result.statusCode >= 400 &&
|
||||
|
||||
@@ -141,13 +141,13 @@ const DashboardMasterPage: FunctionComponent<ComponentProps> = (
|
||||
}
|
||||
}
|
||||
// get status page id by hostname.
|
||||
const response: HTTPResponse<JSONObject> = await API.post<JSONObject>(
|
||||
URL.fromString(STATUS_PAGE_API_URL.toString()).addRoute(`/domain`),
|
||||
{
|
||||
const response: HTTPResponse<JSONObject> = await API.post<JSONObject>({
|
||||
url: URL.fromString(STATUS_PAGE_API_URL.toString()).addRoute(`/domain`),
|
||||
data: {
|
||||
domain: Navigation.getHostname().toString(),
|
||||
},
|
||||
{},
|
||||
);
|
||||
headers: {},
|
||||
});
|
||||
|
||||
if (response.data && response.data["statusPageId"]) {
|
||||
return new ObjectID(response.data["statusPageId"] as string);
|
||||
@@ -166,13 +166,13 @@ const DashboardMasterPage: FunctionComponent<ComponentProps> = (
|
||||
|
||||
StatusPageUtil.setStatusPageId(id);
|
||||
|
||||
const response: HTTPResponse<JSONObject> = await API.post<JSONObject>(
|
||||
URL.fromString(STATUS_PAGE_API_URL.toString()).addRoute(
|
||||
const response: HTTPResponse<JSONObject> = await API.post<JSONObject>({
|
||||
url: URL.fromString(STATUS_PAGE_API_URL.toString()).addRoute(
|
||||
`/master-page/${id.toString()}`,
|
||||
),
|
||||
{},
|
||||
{},
|
||||
);
|
||||
data: {},
|
||||
headers: {},
|
||||
});
|
||||
|
||||
setMasterPageData(response.data);
|
||||
|
||||
|
||||
@@ -161,13 +161,13 @@ const Overview: FunctionComponent<PageComponentProps> = (
|
||||
const announcementId: string | undefined =
|
||||
Navigation.getLastParamAsObjectID().toString();
|
||||
|
||||
const response: HTTPResponse<JSONObject> = await API.post<JSONObject>(
|
||||
URL.fromString(STATUS_PAGE_API_URL.toString()).addRoute(
|
||||
const response: HTTPResponse<JSONObject> = await API.post<JSONObject>({
|
||||
url: URL.fromString(STATUS_PAGE_API_URL.toString()).addRoute(
|
||||
`/announcements/${id.toString()}/${announcementId}`,
|
||||
),
|
||||
{},
|
||||
API.getDefaultHeaders(StatusPageUtil.getStatusPageId()!),
|
||||
);
|
||||
data: {},
|
||||
headers: API.getDefaultHeaders(StatusPageUtil.getStatusPageId()!),
|
||||
});
|
||||
|
||||
if (!response.isSuccess()) {
|
||||
throw response;
|
||||
|
||||
@@ -69,13 +69,13 @@ const Overview: FunctionComponent<PageComponentProps> = (
|
||||
if (!id) {
|
||||
throw new BadDataException("Status Page ID is required");
|
||||
}
|
||||
const response: HTTPResponse<JSONObject> = await API.post<JSONObject>(
|
||||
URL.fromString(STATUS_PAGE_API_URL.toString()).addRoute(
|
||||
const response: HTTPResponse<JSONObject> = await API.post<JSONObject>({
|
||||
url: URL.fromString(STATUS_PAGE_API_URL.toString()).addRoute(
|
||||
`/announcements/${id.toString()}`,
|
||||
),
|
||||
{},
|
||||
API.getDefaultHeaders(StatusPageUtil.getStatusPageId()!),
|
||||
);
|
||||
data: {},
|
||||
headers: API.getDefaultHeaders(StatusPageUtil.getStatusPageId()!),
|
||||
});
|
||||
|
||||
if (!response.isSuccess()) {
|
||||
throw response;
|
||||
|
||||
@@ -266,13 +266,13 @@ const Detail: FunctionComponent<PageComponentProps> = (
|
||||
if (!id) {
|
||||
throw new BadDataException("Status Page ID is required");
|
||||
}
|
||||
const response: HTTPResponse<JSONObject> = await API.post<JSONObject>(
|
||||
URL.fromString(STATUS_PAGE_API_URL.toString()).addRoute(
|
||||
const response: HTTPResponse<JSONObject> = await API.post<JSONObject>({
|
||||
url: URL.fromString(STATUS_PAGE_API_URL.toString()).addRoute(
|
||||
`/incidents/${id.toString()}/${incidentId?.toString()}`,
|
||||
),
|
||||
{},
|
||||
API.getDefaultHeaders(StatusPageUtil.getStatusPageId()!),
|
||||
);
|
||||
data: {},
|
||||
headers: API.getDefaultHeaders(StatusPageUtil.getStatusPageId()!),
|
||||
});
|
||||
|
||||
if (!response.isSuccess()) {
|
||||
throw response;
|
||||
|
||||
@@ -83,13 +83,13 @@ const Overview: FunctionComponent<PageComponentProps> = (
|
||||
if (!id) {
|
||||
throw new BadDataException("Status Page ID is required");
|
||||
}
|
||||
const response: HTTPResponse<JSONObject> = await API.post<JSONObject>(
|
||||
URL.fromString(STATUS_PAGE_API_URL.toString()).addRoute(
|
||||
const response: HTTPResponse<JSONObject> = await API.post<JSONObject>({
|
||||
url: URL.fromString(STATUS_PAGE_API_URL.toString()).addRoute(
|
||||
`/incidents/${id.toString()}`,
|
||||
),
|
||||
{},
|
||||
API.getDefaultHeaders(StatusPageUtil.getStatusPageId()!),
|
||||
);
|
||||
data: {},
|
||||
headers: API.getDefaultHeaders(StatusPageUtil.getStatusPageId()!),
|
||||
});
|
||||
|
||||
if (!response.isSuccess()) {
|
||||
throw response;
|
||||
|
||||
@@ -139,13 +139,13 @@ const Overview: FunctionComponent<PageComponentProps> = (
|
||||
if (!id) {
|
||||
throw new BadDataException("Status Page ID is required");
|
||||
}
|
||||
const response: HTTPResponse<JSONObject> = await API.post<JSONObject>(
|
||||
URL.fromString(STATUS_PAGE_API_URL.toString()).addRoute(
|
||||
const response: HTTPResponse<JSONObject> = await API.post<JSONObject>({
|
||||
url: URL.fromString(STATUS_PAGE_API_URL.toString()).addRoute(
|
||||
`/overview/${id.toString()}`,
|
||||
),
|
||||
{},
|
||||
API.getDefaultHeaders(StatusPageUtil.getStatusPageId()!),
|
||||
);
|
||||
data: {},
|
||||
headers: API.getDefaultHeaders(StatusPageUtil.getStatusPageId()!),
|
||||
});
|
||||
|
||||
if (!response.isSuccess()) {
|
||||
throw response;
|
||||
|
||||
@@ -301,13 +301,13 @@ const Overview: FunctionComponent<PageComponentProps> = (
|
||||
const eventId: string | undefined =
|
||||
Navigation.getLastParamAsObjectID().toString();
|
||||
|
||||
const response: HTTPResponse<JSONObject> = await API.post<JSONObject>(
|
||||
URL.fromString(STATUS_PAGE_API_URL.toString()).addRoute(
|
||||
const response: HTTPResponse<JSONObject> = await API.post<JSONObject>({
|
||||
url: URL.fromString(STATUS_PAGE_API_URL.toString()).addRoute(
|
||||
`/scheduled-maintenance-events/${id.toString()}/${eventId}`,
|
||||
),
|
||||
{},
|
||||
API.getDefaultHeaders(StatusPageUtil.getStatusPageId()!),
|
||||
);
|
||||
data: {},
|
||||
headers: API.getDefaultHeaders(StatusPageUtil.getStatusPageId()!),
|
||||
});
|
||||
|
||||
if (!response.isSuccess()) {
|
||||
throw response;
|
||||
|
||||
@@ -151,13 +151,13 @@ const Overview: FunctionComponent<PageComponentProps> = (
|
||||
if (!id) {
|
||||
throw new BadDataException("Status Page ID is required");
|
||||
}
|
||||
const response: HTTPResponse<JSONObject> = await API.post<JSONObject>(
|
||||
URL.fromString(STATUS_PAGE_API_URL.toString()).addRoute(
|
||||
const response: HTTPResponse<JSONObject> = await API.post<JSONObject>({
|
||||
url: URL.fromString(STATUS_PAGE_API_URL.toString()).addRoute(
|
||||
`/scheduled-maintenance-events/${id.toString()}`,
|
||||
),
|
||||
{},
|
||||
API.getDefaultHeaders(StatusPageUtil.getStatusPageId()!),
|
||||
);
|
||||
data: {},
|
||||
headers: API.getDefaultHeaders(StatusPageUtil.getStatusPageId()!),
|
||||
});
|
||||
|
||||
if (!response.isSuccess()) {
|
||||
throw response;
|
||||
|
||||
Reference in New Issue
Block a user