refactor(actions): extract shared relay client for direct services

This commit is contained in:
2026-03-25 06:14:23 +00:00
parent 5e51c2eb97
commit 6fa7cf9375
12 changed files with 112 additions and 88 deletions
+10 -3
View File
@@ -1,6 +1,13 @@
# Actions Clients
This folder is reserved for extracted client wrappers from `actions/index.js` as part of the Priority 1 refactor plan.
This folder contains extracted client wrappers from `actions/index.js` as part of the Priority 1 refactor plan.
Phase 1 delivered core helper extraction and compatibility barrel support.
Client-level extraction (`relayClient`, `endpointClient`, `fileClient`, `notifyClient`) is planned for the next increment.
Current extracted clients:
- `relayClient` (shared hash-signing helper used by account/portal/document direct services)
- `endpointClient` (shared JSON request helpers for GET and generic axios config requests)
Notes:
- Core helper extraction and compatibility barrel support remain in place.
- Additional client extraction (`fileClient`, `notifyClient`) can be layered in incrementally without changing public exports from `actions/index.js`.
+11
View File
@@ -0,0 +1,11 @@
import axios from "axios";
export const getJson = async (url, config) => {
const response = await axios.get(url, config);
return response.data;
};
export const requestJson = async (config) => {
const response = await axios(config);
return response.data;
};
+2
View File
@@ -0,0 +1,2 @@
export * from "./relayClient";
export * from "./endpointClient";
+22
View File
@@ -0,0 +1,22 @@
import axios from "axios";
import { hashAPIPath } from "../core/hash";
export const buildHashedQueryUrl = async (queryUrl) => {
try {
const signRes = await axios.get(
"/api/endpoint/gethash_api?path=" + encodeURIComponent(queryUrl)
);
if (!signRes?.data?.hash) {
throw new Error("Hash signature unavailable");
}
return queryUrl + signRes.data.hash;
} catch (error) {
if (typeof window === "undefined" && process.env.HASHKEY) {
return queryUrl + hashAPIPath(queryUrl);
}
throw error;
}
};
+1
View File
@@ -5,4 +5,5 @@ export * from "./core/token";
export * from "./core/headers";
export * from "./core/guards";
export * from "./clients";
export * from "./services";
+1 -21
View File
@@ -1,27 +1,7 @@
import axios from "axios";
import { BASE_URL } from "../core/env";
import { consoleLogger } from "../core/logger";
import { hashAPIPath } from "../core/hash";
const buildHashedQueryUrl = async (queryUrl) => {
try {
const signRes = await axios.get(
"/api/endpoint/gethash_api?path=" + encodeURIComponent(queryUrl)
);
if (!signRes?.data?.hash) {
throw new Error("Hash signature unavailable");
}
return queryUrl + signRes.data.hash;
} catch (error) {
if (typeof window === "undefined" && process.env.HASHKEY) {
return queryUrl + hashAPIPath(queryUrl);
}
throw error;
}
};
import { buildHashedQueryUrl } from "../clients/relayClient";
export const getPersonalAccount = (contactid) => {
return axios
+14 -17
View File
@@ -1,11 +1,10 @@
import axios from "axios";
import { BASE_URL } from "../core/env";
import { logAndReturnResponse } from "./httpServiceUtils";
import { getJson } from "../clients/endpointClient";
export const getNewAppeals = async (searchString) => {
try {
const res = await axios.get(BASE_URL + "/api/admin/getnewappeals_api");
return res.data;
return await getJson(BASE_URL + "/api/admin/getnewappeals_api");
} catch (error) {
return logAndReturnResponse(error);
}
@@ -18,8 +17,8 @@ export const getNewAppealsPage = async (
fieldSort,
showNumberOfRecords
) => {
return axios
.get(
try {
return await getJson(
"/api/admin/getnewappeals_api?searchString=" +
searchString +
"&pageNumber=" +
@@ -30,11 +29,10 @@ export const getNewAppealsPage = async (
fieldSort +
"&showNumberOfRecords=" +
showNumberOfRecords
)
.then((res) => {
return res.data;
})
.catch(logAndReturnResponse);
);
} catch (error) {
return logAndReturnResponse(error);
}
};
export const getNewDocumentsPaged = async (
@@ -46,8 +44,8 @@ export const getNewDocumentsPaged = async (
documentOrigin,
selectedWeeks
) => {
return axios
.get(
try {
return await getJson(
"/api/admin/getlatestdocuments_api?pageNumber=" +
pageNumber +
"&orderby=" +
@@ -62,9 +60,8 @@ export const getNewDocumentsPaged = async (
selectedWeeks +
"&documentOrigin=" +
documentOrigin
)
.then((res) => {
return res.data;
})
.catch(logAndReturnResponse);
);
} catch (error) {
return logAndReturnResponse(error);
}
};
+1 -20
View File
@@ -2,26 +2,7 @@ import axios from "axios";
import { BASE_URL } from "../core/env";
import { consoleLogger } from "../core/logger";
import { hashAPIPath } from "../core/hash";
const buildHashedQueryUrl = async (queryUrl) => {
try {
const signRes = await axios.get(
"/api/endpoint/gethash_api?path=" + encodeURIComponent(queryUrl)
);
if (!signRes?.data?.hash) {
throw new Error("Hash signature unavailable");
}
return queryUrl + signRes.data.hash;
} catch (error) {
if (typeof window === "undefined" && process.env.HASHKEY) {
return queryUrl + hashAPIPath(queryUrl);
}
throw error;
}
};
import { buildHashedQueryUrl } from "../clients/relayClient";
export const getAwaitingSubmissionFromBlob = (containerName) => {
return axios
+2 -3
View File
@@ -1,5 +1,5 @@
import axios from "axios";
import { consoleLogger } from "../core/logger";
import { requestJson } from "../clients/endpointClient";
export const createCRMTask = async (formValues) => {
var queryUrl = "/api/endpoint/createcrmtask_api";
@@ -12,8 +12,7 @@ export const createCRMTask = async (formValues) => {
};
try {
const res = await axios(config);
return res.data;
return await requestJson(config);
} catch (error) {
consoleLogger(error);
}
+6 -3
View File
@@ -1,5 +1,5 @@
import axios from "axios";
import { consoleLogger } from "../core/logger";
import { requestJson } from "../clients/endpointClient";
export const sendEmail = async (
templateId,
@@ -15,8 +15,11 @@ export const sendEmail = async (
};
try {
const response = await axios.post("/api/email/notify", mailData);
return response.data;
return await requestJson({
method: "post",
url: "/api/email/notify",
data: mailData
});
} catch (error) {
consoleLogger(error);
throw error;
+1 -21
View File
@@ -1,27 +1,7 @@
import axios from "axios";
import { BASE_URL } from "../core/env";
import { consoleLogger } from "../core/logger";
import { hashAPIPath } from "../core/hash";
const buildHashedQueryUrl = async (queryUrl) => {
try {
const signRes = await axios.get(
"/api/endpoint/gethash_api?path=" + encodeURIComponent(queryUrl)
);
if (!signRes?.data?.hash) {
throw new Error("Hash signature unavailable");
}
return queryUrl + signRes.data.hash;
} catch (error) {
if (typeof window === "undefined" && process.env.HASHKEY) {
return queryUrl + hashAPIPath(queryUrl);
}
throw error;
}
};
import { buildHashedQueryUrl } from "../clients/relayClient";
export const getMyCases = (loggedInUserId) => {
return axios