From edd96f50bd770c14fe03f21324b58fa2eb9aacf5 Mon Sep 17 00:00:00 2001 From: Chris Zetter <253059100+zetter-rpf@users.noreply.github.com> Date: Tue, 24 Feb 2026 16:14:48 +0000 Subject: [PATCH 1/7] Make naming of api call handler arguments clearer Before it call the third argument 'headers' when they are not headers, but a config object that may have a headers key. --- src/utils/apiCallHandler.js | 42 +++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/utils/apiCallHandler.js b/src/utils/apiCallHandler.js index 5b1dab933..7c7c09c11 100644 --- a/src/utils/apiCallHandler.js +++ b/src/utils/apiCallHandler.js @@ -4,26 +4,24 @@ import omit from "lodash/omit"; const ApiCallHandler = ({ reactAppApiEndpoint }) => { const host = reactAppApiEndpoint; - const get = async (url, headers) => { - return await axios.get(url, headers); + const get = async (url, config) => { + return await axios.get(url, config); }; - const post = async (url, body, headers) => { - return await axios.post(url, body, headers); + const post = async (url, body, config) => { + return await axios.post(url, body, config); }; - const put = async (url, body, headers) => { - return await axios.put(url, body, headers); + const put = async (url, body, config) => { + return await axios.put(url, body, config); }; const headers = (accessToken) => { - let headersHash; if (accessToken) { - headersHash = { Accept: "application/json", Authorization: accessToken }; + return { Accept: "application/json", Authorization: accessToken }; } else { - headersHash = { Accept: "application/json" }; + return { Accept: "application/json" }; } - return { headers: headersHash }; }; const createOrUpdateProject = async (projectWithUserId, accessToken) => { @@ -32,36 +30,34 @@ const ApiCallHandler = ({ reactAppApiEndpoint }) => { return await post( `${host}/api/projects`, { project }, - headers(accessToken), + { headers: headers(accessToken) }, ); } else { return await put( `${host}/api/projects/${project.identifier}`, { project }, - headers(accessToken), + { headers: headers(accessToken) }, ); } }; const deleteProject = async (identifier, accessToken) => { - return await axios.delete( - `${host}/api/projects/${identifier}`, - headers(accessToken), - ); + return await axios.delete(`${host}/api/projects/${identifier}`, { + headers: headers(accessToken), + }); }; const loadRemix = async (projectIdentifier, accessToken) => { - return await get( - `${host}/api/projects/${projectIdentifier}/remix`, - headers(accessToken), - ); + return await get(`${host}/api/projects/${projectIdentifier}/remix`, { + headers: headers(accessToken), + }); }; const createRemix = async (project, accessToken) => { return await post( `${host}/api/projects/${project.identifier}/remix`, { project }, - headers(accessToken), + { headers: headers(accessToken) }, ); }; @@ -69,7 +65,7 @@ const ApiCallHandler = ({ reactAppApiEndpoint }) => { const queryString = locale ? `?locale=${locale}` : ""; return await get( `${host}/api/projects/${projectIdentifier}${queryString}`, - headers(accessToken), + { headers: headers(accessToken) }, ); }; @@ -77,7 +73,7 @@ const ApiCallHandler = ({ reactAppApiEndpoint }) => { const queryString = locale ? `?locale=${locale}` : ""; return await get( `${host}/api/projects/${assetsIdentifier}/images${queryString}`, - headers(accessToken), + { headers: headers(accessToken) }, ); }; From 1d86e0fc22df0ba92f918591b791ee1caa3d10d4 Mon Sep 17 00:00:00 2001 From: Chris Zetter <253059100+zetter-rpf@users.noreply.github.com> Date: Thu, 26 Feb 2026 16:10:35 +0000 Subject: [PATCH 2/7] Allow the setting of cookies when loading projects This is to allow us to drop a cookie that can be used to authorize requests made by Scratch. Using withCredentials allows cookies to be set in the request response. --- src/utils/apiCallHandler.js | 2 +- src/utils/apiCallHandler.test.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/apiCallHandler.js b/src/utils/apiCallHandler.js index 7c7c09c11..550978f7b 100644 --- a/src/utils/apiCallHandler.js +++ b/src/utils/apiCallHandler.js @@ -65,7 +65,7 @@ const ApiCallHandler = ({ reactAppApiEndpoint }) => { const queryString = locale ? `?locale=${locale}` : ""; return await get( `${host}/api/projects/${projectIdentifier}${queryString}`, - { headers: headers(accessToken) }, + { headers: headers(accessToken), withCredentials: true }, ); }; diff --git a/src/utils/apiCallHandler.test.js b/src/utils/apiCallHandler.test.js index aff8cf0c7..d478e73fa 100644 --- a/src/utils/apiCallHandler.test.js +++ b/src/utils/apiCallHandler.test.js @@ -105,7 +105,7 @@ describe("Testing project API calls", () => { await readProject(projectIdentifier); expect(axios.get).toHaveBeenCalledWith( `${host}/api/projects/${projectIdentifier}`, - defaultHeaders, + { ...defaultHeaders, withCredentials: true }, ); }); @@ -117,7 +117,7 @@ describe("Testing project API calls", () => { await readProject(projectIdentifier, locale); expect(axios.get).toHaveBeenCalledWith( `${host}/api/projects/${projectIdentifier}?locale=${locale}`, - defaultHeaders, + { ...defaultHeaders, withCredentials: true }, ); }); @@ -128,7 +128,7 @@ describe("Testing project API calls", () => { await readProject(projectIdentifier, null, accessToken); expect(axios.get).toHaveBeenCalledWith( `${host}/api/projects/${projectIdentifier}`, - authHeaders, + { ...authHeaders, withCredentials: true }, ); }); From 8cc8625fce1146d841833f90bf51d76a9f0df41c Mon Sep 17 00:00:00 2001 From: Chris Zetter <253059100+zetter-rpf@users.noreply.github.com> Date: Thu, 26 Feb 2026 16:32:08 +0000 Subject: [PATCH 3/7] Make the test page work whatever the host I made set up my projects locally to be served from *.rpfdev.com and this was a small thing that caused me some confusing by sending me back to the wrong host. --- public/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/index.html b/public/index.html index 1dbfdf1f4..af22667d6 100644 --- a/public/index.html +++ b/public/index.html @@ -1,4 +1,4 @@