Give the job tracker stores and fix the admin route guard

createCrudStore captures the places store's pattern and now backs
places, job applications and job references. JobApplications.vue no
longer calls gql() itself and is split into the applications table, the
references table and the add form, with the status vocabulary in
jobStatus.js.

api.js is a thin REST client that turns failures into an ApiError
carrying the backend's message; the admin views and Listening.vue use it
in place of raw axios and fetch.

The router guard waited on the home query's loaded flag, which is never
set when that query fails, so /admin and /cv/jobs could hang. It now
awaits a standalone me query owned by the auth store, and homeData gains
a settled flag for widgets that only need to know the fetch finished.

The Vite proxy targets are configurable through VITE_PROXY_*, and
build:js runs the Vite build without wasm-pack.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-12 14:39:19 +01:00
co-authored by Claude Opus 5.5
parent 71344a1f8d
commit d3f722d077
26 changed files with 1176 additions and 681 deletions
+76
View File
@@ -0,0 +1,76 @@
/**
* The REST half of the API client, beside graphql.js: a thin axios wrapper for
* the Go backend's JSON endpoints under /api (file uploads, admin tooling,
* OAuth starts — everything backend/README.md lists as "not GraphQL").
*
* It does two things a bare axios call does not:
* - prefixes `/api`, so callers name the route (`api.get("/admin/logs")`);
* - turns a failure into an ApiError whose `message` is the backend's
* `{"error": "..."}` body when there is one. Every handler reports errors
* in that shape, and each view used to dig it out of `err.response` itself.
*
* Resolves to the parsed response body, not the axios response.
*
* Auth is the same HTTP-only cookies graphql.js relies on; nothing here handles
* tokens.
*
* NOT for: the Python service's NDJSON streams (views/hotels/hotelsStream.js
* reads those incrementally with fetch) or the `/radio/stream` HEAD probe —
* neither is under /api nor answers with this error shape.
*/
import axios from "axios";
export class ApiError extends Error {
/**
* @param {string} message
* @param {number|undefined} status HTTP status; undefined when no response
* arrived at all (network down, backend restarting)
* @param {*} data the parsed error body, if any
*/
constructor(message, status, data) {
super(message);
this.name = "ApiError";
this.status = status;
this.data = data;
}
}
/**
* @param {string} method
* @param {string} path route below /api, with its leading slash
* @param {object} [options]
* @param {*} [options.body] JSON-serialisable body, or a FormData for
* multipart uploads (axios sets the boundary itself)
* @param {string} [options.fallback] message to use when the backend sent no
* `error` string — callers pass the sentence their UI shows
* Any other option (`headers`, `params`, `onUploadProgress`, `signal`, …) is
* handed to axios unchanged.
*/
async function request(method, path, { body, fallback, ...config } = {}) {
try {
const res = await axios.request({
method,
url: `/api${path}`,
data: body,
...config,
});
return res.data;
} catch (err) {
const data = err.response?.data;
const serverMessage = typeof data?.error === "string" ? data.error : "";
throw new ApiError(
serverMessage || fallback || err.message,
err.response?.status,
data,
);
}
}
export const api = {
get: (path, options) => request("get", path, options),
delete: (path, options) => request("delete", path, options),
post: (path, body, options) => request("post", path, { ...options, body }),
put: (path, body, options) => request("put", path, { ...options, body }),
patch: (path, body, options) => request("patch", path, { ...options, body }),
};