mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-14 10:34:06 +02:00
# Description of Changes ## What & why This PR introduces the **Stirling developer portal** — a new control-plane frontend that sits alongside the existing PDF editor — plus the shared design system and workspace structure needed to host both apps in one frontend. The portal is the parent product surface: where users connect sources, compose pipelines, wire agents, and manage usage / billing / infrastructure, with the PDF editor as one capability inside it. This PR lays the **foundation** — workspace reshape, design system, app shell, navigation, and a mock-driven home — rather than wiring real backends (those surfaces are placeholders for follow-up phases). ## What's in this PR **1. Frontend repo reshape (`frontend/src/` → `frontend/editor/`)** The existing editor app moved under `frontend/editor/`, so `editor`, `portal`, and `shared` are siblings in one workspace. All references were updated accordingly: `LICENSE`, `.dockerignore`, `.gitignore`, build/sign shell scripts, the GH language-check script, the Taskfile, and Docker config. **No editor source logic changed — path references only.** **2. New shared design system (`frontend/shared/`)** - **Design tokens** in `tokens.css` as the single runtime source of truth (light/dark, category accents, gradients). `tokens.ts` now holds only the `Tier` type — the old JS palette mirror was removed (nothing consumed it and it had drifted). - ~30 framework-light **components** (Card, Button, Input, Select, Tabs, Modal, Drawer, Toast, MetricCard, StatusBadge, Skeleton, EmptyState, …) with Storybook stories. - **Typed data catalogues**: `endpoints.ts` (10 verticals / 64 endpoints) and `ops.ts`. **3. New developer portal app (`frontend/portal/`)** - App shell: `Header`, `Sidebar`, `AssistantPanel`, search modal, notifications, tier switcher, theme toggle, MSW toggle. - **Tier-aware** home (free / pay-as-you-go / enterprise): KPI strip, 30-day usage chart, onboarding checklist, quick actions, recent activity, region health, product grid, and a curated **"Popular use cases"** teaser. - **Documents** view hosting the full, tab-filterable endpoint catalogue. - Placeholder views for Sources / Pipelines / Agents / Editor / Infrastructure / Usage & Billing / Developer Docs / Settings (follow-up phases). - **MSW-mocked** API layer: `api/*` issues real `fetch`, intercepted by mocks in dev/Storybook; pointing at a real backend is just a matter of not registering MSW. `react-router` URLs; Tier / View / UI contexts. **4. Tooling & guardrails** - ESLint extended to `portal` + `shared`, with **layering-boundary rules**: `shared/` may depend only on third-party packages and itself (no `@app` / `@portal` / `@core` / `@proprietary` / Tauri), so it stays cleanly extractable into a standalone package later. - `dpdm` circular-dependency check now walks editor + portal + shared (the old glob matched only 2 files). - New **devDependencies only** — Storybook (+ a11y/docs/themes addons), MSW. No runtime dependencies added. - New tasks: `frontend:dev:portal`, `frontend:build:portal`. ## Testing done locally - `tsc` for both `portal` and `shared` projects — clean - `eslint --max-warnings=0` across the whole frontend — clean - `dpdm` circular-dependency check — no cycles - Editor builds clean: `vite build editor --mode core` (✓ built, only the pre-existing >500 kB chunk-size advisory) - Editor runs in dev (core mode) with **zero console errors**; portal runs in dev across all three tiers ## Notes for reviewers - The change is overwhelmingly **additive**: `shared/` and `portal/` are brand-new; the existing editor is path-reference changes only. - The portal is intentionally **mock-driven** at this stage — real backends and the remaining views land in follow-up phases. --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### Translations (if applicable) - [ ] I ran [`scripts/counter_translation.py`](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/docs/counter_translation.md) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have run `task check` to verify linters, typechecks, and tests pass - [x] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#7-testing) for more details. --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
350 lines
9.0 KiB
JavaScript
350 lines
9.0 KiB
JavaScript
/* eslint-disable */
|
|
/* tslint:disable */
|
|
|
|
/**
|
|
* Mock Service Worker.
|
|
* @see https://github.com/mswjs/msw
|
|
* - Please do NOT modify this file.
|
|
*/
|
|
|
|
const PACKAGE_VERSION = "2.14.6";
|
|
const INTEGRITY_CHECKSUM = "4db4a41e972cec1b64cc569c66952d82";
|
|
const IS_MOCKED_RESPONSE = Symbol("isMockedResponse");
|
|
const activeClientIds = new Set();
|
|
|
|
addEventListener("install", function () {
|
|
self.skipWaiting();
|
|
});
|
|
|
|
addEventListener("activate", function (event) {
|
|
event.waitUntil(self.clients.claim());
|
|
});
|
|
|
|
addEventListener("message", async function (event) {
|
|
const clientId = Reflect.get(event.source || {}, "id");
|
|
|
|
if (!clientId || !self.clients) {
|
|
return;
|
|
}
|
|
|
|
const client = await self.clients.get(clientId);
|
|
|
|
if (!client) {
|
|
return;
|
|
}
|
|
|
|
const allClients = await self.clients.matchAll({
|
|
type: "window",
|
|
});
|
|
|
|
switch (event.data) {
|
|
case "KEEPALIVE_REQUEST": {
|
|
sendToClient(client, {
|
|
type: "KEEPALIVE_RESPONSE",
|
|
});
|
|
break;
|
|
}
|
|
|
|
case "INTEGRITY_CHECK_REQUEST": {
|
|
sendToClient(client, {
|
|
type: "INTEGRITY_CHECK_RESPONSE",
|
|
payload: {
|
|
packageVersion: PACKAGE_VERSION,
|
|
checksum: INTEGRITY_CHECKSUM,
|
|
},
|
|
});
|
|
break;
|
|
}
|
|
|
|
case "MOCK_ACTIVATE": {
|
|
activeClientIds.add(clientId);
|
|
|
|
sendToClient(client, {
|
|
type: "MOCKING_ENABLED",
|
|
payload: {
|
|
client: {
|
|
id: client.id,
|
|
frameType: client.frameType,
|
|
},
|
|
},
|
|
});
|
|
break;
|
|
}
|
|
|
|
case "CLIENT_CLOSED": {
|
|
activeClientIds.delete(clientId);
|
|
|
|
const remainingClients = allClients.filter((client) => {
|
|
return client.id !== clientId;
|
|
});
|
|
|
|
// Unregister itself when there are no more clients
|
|
if (remainingClients.length === 0) {
|
|
self.registration.unregister();
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
|
|
addEventListener("fetch", function (event) {
|
|
const requestInterceptedAt = Date.now();
|
|
|
|
// Bypass navigation requests.
|
|
if (event.request.mode === "navigate") {
|
|
return;
|
|
}
|
|
|
|
// Opening the DevTools triggers the "only-if-cached" request
|
|
// that cannot be handled by the worker. Bypass such requests.
|
|
if (
|
|
event.request.cache === "only-if-cached" &&
|
|
event.request.mode !== "same-origin"
|
|
) {
|
|
return;
|
|
}
|
|
|
|
// Bypass all requests when there are no active clients.
|
|
// Prevents the self-unregistered worked from handling requests
|
|
// after it's been terminated (still remains active until the next reload).
|
|
if (activeClientIds.size === 0) {
|
|
return;
|
|
}
|
|
|
|
const requestId = crypto.randomUUID();
|
|
event.respondWith(handleRequest(event, requestId, requestInterceptedAt));
|
|
});
|
|
|
|
/**
|
|
* @param {FetchEvent} event
|
|
* @param {string} requestId
|
|
* @param {number} requestInterceptedAt
|
|
*/
|
|
async function handleRequest(event, requestId, requestInterceptedAt) {
|
|
const client = await resolveMainClient(event);
|
|
const requestCloneForEvents = event.request.clone();
|
|
const response = await getResponse(
|
|
event,
|
|
client,
|
|
requestId,
|
|
requestInterceptedAt,
|
|
);
|
|
|
|
// Send back the response clone for the "response:*" life-cycle events.
|
|
// Ensure MSW is active and ready to handle the message, otherwise
|
|
// this message will pend indefinitely.
|
|
if (client && activeClientIds.has(client.id)) {
|
|
const serializedRequest = await serializeRequest(requestCloneForEvents);
|
|
|
|
// Clone the response so both the client and the library could consume it.
|
|
const responseClone = response.clone();
|
|
|
|
sendToClient(
|
|
client,
|
|
{
|
|
type: "RESPONSE",
|
|
payload: {
|
|
isMockedResponse: IS_MOCKED_RESPONSE in response,
|
|
request: {
|
|
id: requestId,
|
|
...serializedRequest,
|
|
},
|
|
response: {
|
|
type: responseClone.type,
|
|
status: responseClone.status,
|
|
statusText: responseClone.statusText,
|
|
headers: Object.fromEntries(responseClone.headers.entries()),
|
|
body: responseClone.body,
|
|
},
|
|
},
|
|
},
|
|
responseClone.body ? [serializedRequest.body, responseClone.body] : [],
|
|
);
|
|
}
|
|
|
|
return response;
|
|
}
|
|
|
|
/**
|
|
* Resolve the main client for the given event.
|
|
* Client that issues a request doesn't necessarily equal the client
|
|
* that registered the worker. It's with the latter the worker should
|
|
* communicate with during the response resolving phase.
|
|
* @param {FetchEvent} event
|
|
* @returns {Promise<Client | undefined>}
|
|
*/
|
|
async function resolveMainClient(event) {
|
|
const client = await self.clients.get(event.clientId);
|
|
|
|
if (activeClientIds.has(event.clientId)) {
|
|
return client;
|
|
}
|
|
|
|
if (client?.frameType === "top-level") {
|
|
return client;
|
|
}
|
|
|
|
const allClients = await self.clients.matchAll({
|
|
type: "window",
|
|
});
|
|
|
|
return allClients
|
|
.filter((client) => {
|
|
// Get only those clients that are currently visible.
|
|
return client.visibilityState === "visible";
|
|
})
|
|
.find((client) => {
|
|
// Find the client ID that's recorded in the
|
|
// set of clients that have registered the worker.
|
|
return activeClientIds.has(client.id);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @param {FetchEvent} event
|
|
* @param {Client | undefined} client
|
|
* @param {string} requestId
|
|
* @param {number} requestInterceptedAt
|
|
* @returns {Promise<Response>}
|
|
*/
|
|
async function getResponse(event, client, requestId, requestInterceptedAt) {
|
|
// Clone the request because it might've been already used
|
|
// (i.e. its body has been read and sent to the client).
|
|
const requestClone = event.request.clone();
|
|
|
|
function passthrough() {
|
|
// Cast the request headers to a new Headers instance
|
|
// so the headers can be manipulated with.
|
|
const headers = new Headers(requestClone.headers);
|
|
|
|
// Remove the "accept" header value that marked this request as passthrough.
|
|
// This prevents request alteration and also keeps it compliant with the
|
|
// user-defined CORS policies.
|
|
const acceptHeader = headers.get("accept");
|
|
if (acceptHeader) {
|
|
const values = acceptHeader.split(",").map((value) => value.trim());
|
|
const filteredValues = values.filter(
|
|
(value) => value !== "msw/passthrough",
|
|
);
|
|
|
|
if (filteredValues.length > 0) {
|
|
headers.set("accept", filteredValues.join(", "));
|
|
} else {
|
|
headers.delete("accept");
|
|
}
|
|
}
|
|
|
|
return fetch(requestClone, { headers });
|
|
}
|
|
|
|
// Bypass mocking when the client is not active.
|
|
if (!client) {
|
|
return passthrough();
|
|
}
|
|
|
|
// Bypass initial page load requests (i.e. static assets).
|
|
// The absence of the immediate/parent client in the map of the active clients
|
|
// means that MSW hasn't dispatched the "MOCK_ACTIVATE" event yet
|
|
// and is not ready to handle requests.
|
|
if (!activeClientIds.has(client.id)) {
|
|
return passthrough();
|
|
}
|
|
|
|
// Notify the client that a request has been intercepted.
|
|
const serializedRequest = await serializeRequest(event.request);
|
|
const clientMessage = await sendToClient(
|
|
client,
|
|
{
|
|
type: "REQUEST",
|
|
payload: {
|
|
id: requestId,
|
|
interceptedAt: requestInterceptedAt,
|
|
...serializedRequest,
|
|
},
|
|
},
|
|
[serializedRequest.body],
|
|
);
|
|
|
|
switch (clientMessage.type) {
|
|
case "MOCK_RESPONSE": {
|
|
return respondWithMock(clientMessage.data);
|
|
}
|
|
|
|
case "PASSTHROUGH": {
|
|
return passthrough();
|
|
}
|
|
}
|
|
|
|
return passthrough();
|
|
}
|
|
|
|
/**
|
|
* @param {Client} client
|
|
* @param {any} message
|
|
* @param {Array<Transferable>} transferrables
|
|
* @returns {Promise<any>}
|
|
*/
|
|
function sendToClient(client, message, transferrables = []) {
|
|
return new Promise((resolve, reject) => {
|
|
const channel = new MessageChannel();
|
|
|
|
channel.port1.onmessage = (event) => {
|
|
if (event.data && event.data.error) {
|
|
return reject(event.data.error);
|
|
}
|
|
|
|
resolve(event.data);
|
|
};
|
|
|
|
client.postMessage(message, [
|
|
channel.port2,
|
|
...transferrables.filter(Boolean),
|
|
]);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @param {Response} response
|
|
* @returns {Response}
|
|
*/
|
|
function respondWithMock(response) {
|
|
// Setting response status code to 0 is a no-op.
|
|
// However, when responding with a "Response.error()", the produced Response
|
|
// instance will have status code set to 0. Since it's not possible to create
|
|
// a Response instance with status code 0, handle that use-case separately.
|
|
if (response.status === 0) {
|
|
return Response.error();
|
|
}
|
|
|
|
const mockedResponse = new Response(response.body, response);
|
|
|
|
Reflect.defineProperty(mockedResponse, IS_MOCKED_RESPONSE, {
|
|
value: true,
|
|
enumerable: true,
|
|
});
|
|
|
|
return mockedResponse;
|
|
}
|
|
|
|
/**
|
|
* @param {Request} request
|
|
*/
|
|
async function serializeRequest(request) {
|
|
return {
|
|
url: request.url,
|
|
mode: request.mode,
|
|
method: request.method,
|
|
headers: Object.fromEntries(request.headers.entries()),
|
|
cache: request.cache,
|
|
credentials: request.credentials,
|
|
destination: request.destination,
|
|
integrity: request.integrity,
|
|
redirect: request.redirect,
|
|
referrer: request.referrer,
|
|
referrerPolicy: request.referrerPolicy,
|
|
body: await request.arrayBuffer(),
|
|
keepalive: request.keepalive,
|
|
};
|
|
}
|