|
|
@@ -346,3 +346,57 @@ export function getFiles(branch, year, month, day, options) {
|
|
|
|
|
|
return apiFetch(`/api/files?${qs.toString()}`, { method: "GET", ...options });
|
|
|
}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Search delivery notes (RHL-024).
|
|
|
+ *
|
|
|
+ * Notes:
|
|
|
+ * - This endpoint is JSON and can be called via apiFetch.
|
|
|
+ * - Cursor is intentionally not stored in shareable URLs by default; the UI can keep it in state.
|
|
|
+ *
|
|
|
+ * @param {{
|
|
|
+ * q?: string|null,
|
|
|
+ * branch?: string|null,
|
|
|
+ * scope?: "branch"|"multi"|"all"|string|null,
|
|
|
+ * branches?: string[]|null,
|
|
|
+ * from?: string|null,
|
|
|
+ * to?: string|null,
|
|
|
+ * limit?: number|null,
|
|
|
+ * cursor?: string|null
|
|
|
+ * }} input
|
|
|
+ * @param {{ baseUrl?: string, fetchImpl?: typeof fetch }=} options
|
|
|
+ */
|
|
|
+export function search(input, options) {
|
|
|
+ const { q, branch, scope, branches, from, to, limit, cursor } = input || {};
|
|
|
+
|
|
|
+ const params = new URLSearchParams();
|
|
|
+
|
|
|
+ // Stable insertion order (helps debugging and makes URLs readable).
|
|
|
+ if (typeof q === "string" && q.trim()) params.set("q", q.trim());
|
|
|
+ if (typeof scope === "string" && scope.trim())
|
|
|
+ params.set("scope", scope.trim());
|
|
|
+ if (typeof branch === "string" && branch.trim())
|
|
|
+ params.set("branch", branch.trim());
|
|
|
+
|
|
|
+ if (Array.isArray(branches) && branches.length > 0) {
|
|
|
+ const cleaned = branches.map((b) => String(b).trim()).filter(Boolean);
|
|
|
+ if (cleaned.length > 0) params.set("branches", cleaned.join(","));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (typeof from === "string" && from.trim()) params.set("from", from.trim());
|
|
|
+ if (typeof to === "string" && to.trim()) params.set("to", to.trim());
|
|
|
+
|
|
|
+ if (limit !== undefined && limit !== null) {
|
|
|
+ const raw = String(limit).trim();
|
|
|
+ if (raw) params.set("limit", raw);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (typeof cursor === "string" && cursor.trim()) {
|
|
|
+ params.set("cursor", cursor.trim());
|
|
|
+ }
|
|
|
+
|
|
|
+ const qs = params.toString();
|
|
|
+ const path = qs ? `/api/search?${qs}` : "/api/search";
|
|
|
+
|
|
|
+ return apiFetch(path, { method: "GET", ...options });
|
|
|
+}
|