Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [Unreleased]
## [0.11.2] - 2026-12-01

### Changed

- Bridge mode persistence now uses the shared `readStored` / `writeStored` helpers from `@merqo/ui`; stored values are unchanged.

### Fixed

Expand All @@ -23,6 +27,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

### Added

- Label designer: a "Match printer size" button on the printer size note rescales the whole design to the paired printer's label (positions, boxes and text size), and a rejected Width or Length change now says fields extend past the new size and what to do.
- Test labels: the cooldown is now 15 seconds and a refused re-print in the designer reads "Printer is busy, try again in Ns" instead of an error; the designer rechecks an offline printer every 15 seconds (plus a "Check again" button), re-saves once if the design changed mid-save, says when the saved design could not be used, and notes that Feie printers print the standard label. The test-print online check honours the virtual printer's longer window.
- Label design: a "Print test label" button in the designer that saves a changed design, then sends a sample order to the booth's printer (off with a reason when the booth has no printer or it is offline). A booth picker replaces the 404 for vendors with several booths. New fields and logos land in a free spot instead of on top of existing ones. The rendered preview stays visible until the design changes and no longer waits forever on a stalled request.

Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ payloads 90 days after printing and deletes expired bridge pairing codes.
for the security context). The Vercel build does not use
`output: "standalone"`; that config was dropped.

Dashboard form errors use the shared `FormError` from `@merqo/ui`. Shared shadcn primitives (`Badge`, `Button`, `Input`, `Label`, `Select`, `Switch`, `Tooltip`, `Alert`, `cn`) come from `@merqo/ui/primitives`.
Dashboard form errors use the shared `FormError` from `@merqo/ui`. The Bridge mode flag in `src/lib/bridge-mode.ts` persists through the shared `readStored` / `writeStored`. Shared shadcn primitives (`Badge`, `Button`, `Input`, `Label`, `Select`, `Switch`, `Tooltip`, `Alert`, `cn`) come from `@merqo/ui/primitives`.

The Overview fills the dashboard layout's full `max-w-7xl` width, shows three first-run steps (booth, printer, first label) until a label has printed (a step shows done only when every earlier step is done), refreshes itself on tab focus and every 30 seconds while visible, and every dashboard page header carries a short eyebrow (Overview: "Your booths"); the designer is reached from Printers, and a "Design your label" card appears once a booth has a printer but no label design. The first step always links to qkit: set the optional `NEXT_PUBLIC_QKIT_URL` (see `.env.example`) before building to point it elsewhere than `https://qkit.merqo.io`. The "Your booths" eyebrow appears only once a booth exists, and the label designer shows an empty state (not a 404) for a vendor with no booth printing.

Expand Down Expand Up @@ -127,6 +127,12 @@ and as a table from the `md` (768px) breakpoint up. An "All labels / Needs a boo
control (a client component, `src/app/dashboard/history/history-filter.tsx`) filters the list (`?unrouted=1` still deep-links to it), test prints
have no Reprint, and the copy says "labels" rather than "jobs".

In the sticker designer (`src/app/dashboard/printers/designer/`), when the
label size does not match the selected printer's media, the printer-fit notice
offers a "Match printer size" button that resizes the template to the printer
(`fitTemplateToSize` in `src/lib/sticker-fit.ts`). If fields extend past the new
edge the resize is refused with a specific message instead of a generic error.

`/reset-password` shows its form only to the session a fresh reset link
created, within 15 minutes, through a signed recovery-window cookie set by
`/auth/callback`. Any other signed-in session gets the expired card. See
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "printkit",
"version": "0.11.1",
"version": "0.11.2",
"private": true,
"packageManager": "pnpm@11.10.0",
"engines": {
Expand Down
2 changes: 2 additions & 0 deletions src/app/dashboard/printers/designer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ The designer page carries the tab title "Label design", matching its heading.
A failed save shows its message through the shared `@merqo/ui` `FormError`.

`loading.tsx` is the route's skeleton, built from the shared `Skeleton`, using the page's `max-w-6xl` cap so the layout does not jump when data arrives; the shared skeleton pulses only when motion is allowed.

The printer size note offers "Match printer size" (not for Feie), which calls `fitTemplateToSize` from `src/lib/sticker-fit.ts` through the designer's `update()` so undo and saved status keep working. A Width or Length change that would push fields past the margins is refused with a message that names the cause and suggests Match printer size when a printer is paired.
14 changes: 12 additions & 2 deletions src/app/dashboard/printers/designer/printer-fit-notice.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { StickerTemplate } from "@/lib/sticker-template";
import { Button } from "@merqo/ui/primitives";

export type DesignerPrinter = {
model: string;
Expand All @@ -18,9 +19,11 @@ const close = (a: number, b: number) => Math.abs(a - b) < 0.05;
export function PrinterFitNotice({
printer,
template,
onMatch,
}: {
printer?: DesignerPrinter;
template: StickerTemplate;
onMatch?: () => void;
}) {
if (!printer) return null;
if (printer.connector === "vendor_cloud")
Expand All @@ -36,11 +39,18 @@ export function PrinterFitNotice({
)
return null;
return (
<p role="note" className="rounded-md border p-3 text-sm">
<div role="note" className="rounded-md border p-3 text-sm">
Your {printer.model} label is {printer.labelWidthMm} by{" "}
{printer.labelHeightMm} mm, but this sticker is {template.widthMm} by{" "}
{template.heightMm} mm. It will be scaled to fit the label and centered.
Set the sticker size to match for the sharpest print.
</p>
{onMatch && (
<div className="mt-2">
<Button type="button" variant="outline" size="sm" onClick={onMatch}>
Match printer size
</Button>
</div>
)}
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,66 @@ describe("sticker designer prototype", () => {
);
expect(screen.queryByRole("note")).not.toBeInTheDocument();
});
it("suggests Match printer size when a resize is rejected and a printer is paired", () => {
render(
<StickerDesigner
printer={{
model: "FP-N20W",
connector: "cloud_poll",
labelWidthMm: 50,
labelHeightMm: 30,
}}
/>,
);
fireEvent.change(screen.getByLabelText("Width (mm)"), {
target: { value: "20" },
});
fireEvent.blur(screen.getByLabelText("Width (mm)"));
expect(screen.getByRole("alert")).toHaveTextContent(
/Press "Match printer size"/,
);
});
it("fits the design to the printer label with Match printer size and saves it", async () => {
save.mockResolvedValueOnce({ ok: true });
render(
<StickerDesigner
locationId="booth"
printer={{
model: "FP-N20W",
connector: "cloud_poll",
labelWidthMm: 50,
labelHeightMm: 30,
}}
/>,
);
fireEvent.click(screen.getByRole("button", { name: "Match printer size" }));
expect(screen.queryByRole("note")).not.toBeInTheDocument();
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
expect(screen.getByLabelText("Width (mm)")).toHaveValue(50);
expect(screen.getByLabelText("Length (mm)")).toHaveValue(30);
fireEvent.click(screen.getByRole("button", { name: "Save design" }));
await waitFor(() =>
expect(save).toHaveBeenCalledWith(
"booth",
expect.objectContaining({ widthMm: 50, heightMm: 30 }),
),
);
});
it("offers no Match printer size button for a Feie printer", () => {
render(
<StickerDesigner
printer={{
model: "Feie",
connector: "vendor_cloud",
labelWidthMm: 40,
labelHeightMm: 30,
}}
/>,
);
expect(
screen.queryByRole("button", { name: "Match printer size" }),
).not.toBeInTheDocument();
});
it("says a Feie printer prints the standard label", () => {
render(
<StickerDesigner
Expand Down Expand Up @@ -101,7 +161,7 @@ describe("sticker designer prototype", () => {
});
fireEvent.blur(screen.getByLabelText("Width (mm)"));
expect(screen.getByRole("alert")).toHaveTextContent(
/outside the printable margins/i,
/fields extend past the new size.*move or shrink those fields first/i,
);
expect(screen.getByLabelText("Width (mm)")).toHaveValue(40);
fireEvent.click(screen.getByRole("button", { name: "Reset preview" }));
Expand Down
35 changes: 32 additions & 3 deletions src/app/dashboard/printers/designer/sticker-designer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { StickerSize } from "./sticker-size";
import { PrinterFitNotice, type DesignerPrinter } from "./printer-fit-notice";
import { AddFieldButtons } from "./add-field-buttons";
import { arrowDelta, clampPosition, type DragState } from "./sticker-move";
import { fitTemplateToSize } from "@/lib/sticker-fit";
import { names } from "./sticker-content";
import {
discardLogo,
Expand Down Expand Up @@ -78,9 +79,24 @@ export function StickerDesigner({
function update(next: StickerTemplate) {
const result = stickerTemplateSchema.safeParse(next);
if (!result.success) {
setError(
"The label or a field extends outside the printable margins. Adjust the field or use a larger label.",
const resized =
next.widthMm !== template.widthMm ||
next.heightMm !== template.heightMm;
const pastEdge = result.error.issues.some(
(issue) =>
issue.message === "Element extends outside printable margins",
);
let message =
"The label or a field extends outside the printable margins. Adjust the field or use a larger label.";
if (resized && pastEdge) {
const canMatch = printer && printer.connector !== "vendor_cloud";
message = `Some fields extend past the new size. ${
canMatch
? 'Press "Match printer size" to fit them, or move the fields first.'
: "Move or shrink those fields first."
}`;
}
setError(message);
return;
}
invalidate();
Expand Down Expand Up @@ -369,7 +385,20 @@ export function StickerDesigner({
</div>
</section>
<section aria-label="Sticker settings" className="space-y-6">
<PrinterFitNotice printer={printer} template={template} />
<PrinterFitNotice
printer={printer}
template={template}
onMatch={() =>
printer &&
update(
fitTemplateToSize(
template,
printer.labelWidthMm,
printer.labelHeightMm,
),
)
}
/>
<StickerSize template={template} onChange={update} />
<div>
<h2 className="text-base font-semibold">Fields</h2>
Expand Down
3 changes: 3 additions & 0 deletions src/lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ sinceHours = 72)` groups the window's events with the jobs queued or sent
time if unset, instead of silently reading `undefined`.
- `location-printer-summaries.ts` — reads active locations and batches minimal printer summaries, scoped by vendor and location IDs, for overview and printers pages.
- `bluetooth-support.ts`: `getBluetoothSupport(nav, ua)`: `supported`, `ios` (iPhone, iPad including the Mac-UA iPad, Chrome for iOS), `unsupported-browser` or `insecure-context`, for the Bridge page.
- `bridge-mode.ts`: `isBridgeModeEnabled()` / `setBridgeModeEnabled(enabled)`, the persisted Bridge mode flag (`printkit:bridge-mode`) via the shared `readStored` / `writeStored` from `@merqo/ui`.
- `rate-limit.ts`: `clientIp(headers)` picks `x-vercel-forwarded-for`, then `x-real-ip`, then the LAST `x-forwarded-for` hop (the first is client-spoofable) and returns null when none is set. `rateLimit(supabase, key, limit, windowSeconds)` runs the `check_rate_limit` RPC and fails open; `rateLimitStrict` is the same but fails closed (used for pairing). `tooManyRequests()` builds the 429 with `Retry-After: 60`; `enforceIpLimit` (pre-auth, `kit-ip`/`agent-ip` buckets, skipped when no IP) and `enforceKitLimit` (post-auth, `kit:<slug>`) wrap it for routes. Limits per 60 seconds: pairing 10 per IP (shared `pair:noip` bucket when no IP), CloudPRNT 120 per token, kit routes 300 per IP and 600 per kit, agent routes 240 per IP.

## Connectivity
Expand Down Expand Up @@ -276,3 +277,5 @@ The B1 calibration sample uses the shared label renderer at 40 mm across by 60 m
Limits and windows that nothing outside their module reads (`KIT_LIMIT`, `STUCK_AFTER_MS`, `HEALTH_ONLINE_MS`, `SEEN_WRITE_THROTTLE_MS`, `MAX_BATCH_LABELS`, `MAX_LOGOS`, `AUTH_NEXT_MAX_AGE`) are not exported, so `knip` flags any that gain an unused export again. `job-expiry.ts` is the one source for `JOB_EXPIRY_MS` and `CONFIRM_TIMEOUT_MS`; `job-dispatch.ts` imports them rather than re-exporting. `render-job.test.ts` covers the saved-design path, the default-layout fallback and the booth-name lookup.

- `sticker-design-status.ts` — `hasStickerDesign(supabase, vendorId)`: whether the vendor has an active label design; drives the Overview "Design your label" card and treats a read error as designed.

- `sticker-fit.ts` — `fitTemplateToSize`: rescales a sticker template to a new width and length (positions and boxes by the printable-area ratios, text by the smaller ratio, logos keep their aspect), rounded to 0.1 mm so the result still passes `stickerTemplateSchema`.
7 changes: 7 additions & 0 deletions src/lib/bridge-mode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ describe("bridge-mode", () => {
localStorage.setItem("printkit:bridge-mode", "not-json");
expect(isBridgeModeEnabled()).toBe(false);
});

it("reads values stored by the old string format", () => {
localStorage.setItem("printkit:bridge-mode", "true");
expect(isBridgeModeEnabled()).toBe(true);
localStorage.setItem("printkit:bridge-mode", "false");
expect(isBridgeModeEnabled()).toBe(false);
});
});
15 changes: 4 additions & 11 deletions src/lib/bridge-mode.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import { readStored, writeStored } from "@merqo/ui";

const KEY = "printkit:bridge-mode";

export function isBridgeModeEnabled(): boolean {
try {
return localStorage.getItem(KEY) === "true";
} catch {
return false;
}
return readStored(KEY) === true;
}

export function setBridgeModeEnabled(enabled: boolean): void {
try {
localStorage.setItem(KEY, enabled ? "true" : "false");
} catch {
// Storage unavailable (private mode, quota) — Bridge mode simply
// won't persist across reloads; not worth surfacing as an error here.
}
writeStored(KEY, enabled);
}
102 changes: 102 additions & 0 deletions src/lib/sticker-fit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { describe, expect, it } from "vitest";
import { fitTemplateToSize } from "./sticker-fit";
import {
defaultStickerTemplate,
stickerTemplateSchema,
type StickerTemplate,
} from "./sticker-template";

const logoPath =
"10000000-0000-4000-8000-000000000001/20000000-0000-4000-8000-000000000002/30000000-0000-4000-8000-000000000003.png";

const valid = (template: StickerTemplate) =>
stickerTemplateSchema.safeParse(template).success;

describe("fitTemplateToSize", () => {
it("turns the 40x60 default into a valid 50x30 template", () => {
const fitted = fitTemplateToSize(defaultStickerTemplate, 50, 30);
expect(fitted.widthMm).toBe(50);
expect(fitted.heightMm).toBe(30);
expect(valid(fitted)).toBe(true);
});

it("scales positions by the ratio of the printable areas", () => {
const fitted = fitTemplateToSize(defaultStickerTemplate, 80, 120);
const first = fitted.elements[0];
expect(first.xMm).toBeCloseTo(2 + (3 - 2) * (76 / 36), 1);
expect(first.widthMm).toBeCloseTo(24 * (76 / 36), 1);
expect(first.yMm).toBeCloseTo(2 + (3 - 2) * (116 / 56), 1);
expect(valid(fitted)).toBe(true);
});

it("scales text by the smaller ratio so it stays inside its box", () => {
const fitted = fitTemplateToSize(defaultStickerTemplate, 50, 30);
const scaled = fitted.elements[0];
expect(scaled.kind === "field" && scaled.fontSizeMm).toBeCloseTo(
6 * Math.min(46 / 36, 26 / 56),
1,
);
});

it("clamps font size to the schema minimum and maximum", () => {
const small = fitTemplateToSize(defaultStickerTemplate, 20, 20);
for (const element of small.elements)
if (element.kind === "field")
expect(element.fontSizeMm).toBeGreaterThanOrEqual(1.5);
const big = fitTemplateToSize(
{
...defaultStickerTemplate,
elements: [
{ ...defaultStickerTemplate.elements[0], fontSizeMm: 25 },
] as StickerTemplate["elements"],
},
200,
500,
);
const only = big.elements[0];
expect(only.kind === "field" && only.fontSizeMm).toBe(30);
expect(valid(big)).toBe(true);
});

it("keeps a logo's aspect ratio inside its scaled box", () => {
const template: StickerTemplate = {
...defaultStickerTemplate,
elements: [
{
id: "40000000-0000-4000-8000-000000000004",
kind: "logo",
path: logoPath,
xMm: 4,
yMm: 4,
widthMm: 20,
heightMm: 10,
},
],
};
const fitted = fitTemplateToSize(template, 100, 60);
const logo = fitted.elements[0];
expect(logo.widthMm / logo.heightMm).toBeCloseTo(2, 1);
expect(logo.widthMm).toBeLessThanOrEqual(20 * (96 / 36) + 0.01);
expect(logo.heightMm).toBeLessThanOrEqual(10.01);
expect(valid(fitted)).toBe(true);
});

it("never lets rounding push an element past the margin", () => {
for (const [w, h] of [
[43, 37],
[57.3, 31.7],
[20, 20],
[200, 500],
[33.3, 77.7],
])
expect(valid(fitTemplateToSize(defaultStickerTemplate, w, h))).toBe(true);
});

it("keeps ids and the margin", () => {
const fitted = fitTemplateToSize(defaultStickerTemplate, 50, 30);
expect(fitted.marginMm).toBe(2);
expect(fitted.elements.map((e) => e.id)).toEqual(
defaultStickerTemplate.elements.map((e) => e.id),
);
});
});
Loading
Loading