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 @@

You may be looking for...

From 97334e2125c5dc53d8111df3da7a02367846aa40 Mon Sep 17 00:00:00 2001 From: Chris Zetter <253059100+zetter-rpf@users.noreply.github.com> Date: Thu, 26 Feb 2026 17:05:43 +0000 Subject: [PATCH 4/7] Set up scratch to use the new API routes As part of this I've passed the project id and api url as params into the iframe. I've used a seperate param to the existing api endpoint so it can be configured independently. This is useful for testing scratch locally in the editor UI without a dependency on the api project. --- .../Editor/Project/ScratchContainer.jsx | 18 +++++++- .../Editor/Project/ScratchContainer.test.js | 44 +++++++++++++++++++ src/containers/WebComponentLoader.jsx | 6 +++ src/containers/WebComponentLoader.test.js | 40 +++++++++++++++++ src/redux/EditorSlice.js | 4 ++ src/scratch.jsx | 9 ++-- src/web-component.js | 1 + webpack.config.js | 4 +- 8 files changed, 119 insertions(+), 7 deletions(-) create mode 100644 src/components/Editor/Project/ScratchContainer.test.js diff --git a/src/components/Editor/Project/ScratchContainer.jsx b/src/components/Editor/Project/ScratchContainer.jsx index bf6f5f2d9..4b3f909ef 100644 --- a/src/components/Editor/Project/ScratchContainer.jsx +++ b/src/components/Editor/Project/ScratchContainer.jsx @@ -1,9 +1,25 @@ import React from "react"; +import { useSelector } from "react-redux"; export default function ScratchContainer() { + const projectIdentifier = useSelector( + (state) => state.editor.project.identifier, + ); + const scratchApiEndpoint = useSelector( + (state) => state.editor.scratchApiEndpoint, + ); + + const queryParams = new URLSearchParams(); + queryParams.set("project_id", projectIdentifier); + queryParams.set("api_url", scratchApiEndpoint); + + const iframeSrcUrl = `${ + process.env.ASSETS_URL + }/scratch.html?${queryParams.toString()}`; + return (