@flowselections/pick-schermen-kwekers 1.0.55 → 1.0.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=pick156.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pick156.test.d.ts","sourceRoot":"","sources":["../../../src/lib/__tests__/pick156.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+ vi.mock("@flowselections/core", () => ({ supabase: { rpc: vi.fn() } }));
3
+ import { isPrintBlocked, parseDocumentChoice, parseStationDocumentChoice } from "../pick156.js";
4
+ describe("automatische documentkeuze 1.0.56", () => {
5
+ it("ok=false blokkeert alleen een nieuwe print, met de reden", () => {
6
+ const c = parseDocumentChoice({ ok: false, layout_id: null, reden: "Geen layout voor deze klant" });
7
+ expect(c).toMatchObject({ state: "blocked", reden: "Geen layout voor deze klant" });
8
+ expect(isPrintBlocked(c, false)).toBe(true);
9
+ });
10
+ it("herprint blijft altijd mogelijk", () => {
11
+ expect(isPrintBlocked(parseDocumentChoice({ ok: false, reden: "x" }), true)).toBe(false);
12
+ });
13
+ it("ok=true blokkeert niet", () => {
14
+ expect(isPrintBlocked(parseDocumentChoice({ ok: true, layout_id: "L" }), false)).toBe(false);
15
+ });
16
+ it("onleesbaar antwoord of geen toegang = onbekend, niet blokkeren", () => {
17
+ expect(parseDocumentChoice("rommel").state).toBe("unknown");
18
+ const c = parseStationDocumentChoice({ toegang: false, reden: "niet_in_wachtrij_station" });
19
+ expect(c.state).toBe("unknown");
20
+ expect(isPrintBlocked(c, false)).toBe(false);
21
+ });
22
+ it("openbaar omhulsel geeft het Engine-resultaat door", () => {
23
+ expect(parseStationDocumentChoice({ toegang: true, resultaat: { ok: false, reden: "r" } }).state).toBe("blocked");
24
+ });
25
+ });
@@ -0,0 +1,28 @@
1
+ export declare const DOCUMENT_AUTO_TEXT = "Het document wordt automatisch bepaald uit de order.";
2
+ export declare const DOCUMENT_CHOICE_UNKNOWN = "Documentcontrole onbekend";
3
+ export declare const DOCUMENT_BLOCKED_FALLBACK = "Voor deze order kan dit document nu niet worden gemaakt.";
4
+ export type DocumentChoice = {
5
+ state: "ok";
6
+ layoutId: string | null;
7
+ } | {
8
+ state: "blocked";
9
+ reden: string;
10
+ raw: string | null;
11
+ } | {
12
+ state: "none";
13
+ } | {
14
+ state: "unknown";
15
+ };
16
+ /** Leest het antwoord { ok, layout_id, reden }. Onbekende vorm = unknown (printen niet blokkeren). */
17
+ export declare function parseDocumentChoice(raw: unknown): DocumentChoice;
18
+ /** Omhulsel van pickstation_document_for_order: { toegang, resultaat }. */
19
+ export declare function parseStationDocumentChoice(raw: unknown): DocumentChoice;
20
+ /** Alleen een nieuwe (eerste) print wordt tegengehouden; herprint blijft altijd mogelijk. */
21
+ export declare function isPrintBlocked(choice: DocumentChoice | null | undefined, isReprint: boolean): boolean;
22
+ export declare function fetchDocumentChoice(params: {
23
+ queueItemId: string;
24
+ payload: unknown;
25
+ documentType: string;
26
+ slug: string | null;
27
+ }): Promise<DocumentChoice>;
28
+ //# sourceMappingURL=pick156.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pick156.d.ts","sourceRoot":"","sources":["../../src/lib/pick156.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,kBAAkB,yDAAyD,CAAC;AACzF,eAAO,MAAM,uBAAuB,8BAA8B,CAAC;AACnE,eAAO,MAAM,yBAAyB,6DAA6D,CAAC;AAEpG,MAAM,MAAM,cAAc,GACtB;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GACxC;IAAE,KAAK,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GACvD;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GACjB;IAAE,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC;AAMzB,sGAAsG;AACtG,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,cAAc,CAMhE;AAED,2EAA2E;AAC3E,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,OAAO,GAAG,cAAc,CAKvE;AAED,6FAA6F;AAC7F,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,GAAG,SAAS,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO,CAErG;AAOD,wBAAsB,mBAAmB,CAAC,MAAM,EAAE;IAChD,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB,GAAG,OAAO,CAAC,cAAc,CAAC,CAiB1B"}
@@ -0,0 +1,57 @@
1
+ // Pickschermen 1.0.56: het document wordt automatisch bepaald uit de order
2
+ // (logistics_document_for_order). Alleen lezen; de Engine kiest bij het printen zelf.
3
+ import { supabase } from "@flowselections/core";
4
+ const db = supabase;
5
+ export const DOCUMENT_AUTO_TEXT = "Het document wordt automatisch bepaald uit de order.";
6
+ export const DOCUMENT_CHOICE_UNKNOWN = "Documentcontrole onbekend";
7
+ export const DOCUMENT_BLOCKED_FALLBACK = "Voor deze order kan dit document nu niet worden gemaakt.";
8
+ const rec = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : null;
9
+ const txt = (v) => (typeof v === "string" && v.trim() ? v.trim() : null);
10
+ /** Leest het antwoord { ok, layout_id, reden }. Onbekende vorm = unknown (printen niet blokkeren). */
11
+ export function parseDocumentChoice(raw) {
12
+ const r = rec(raw);
13
+ if (!r || typeof r["ok"] !== "boolean")
14
+ return { state: "unknown" };
15
+ if (r["ok"] === true)
16
+ return { state: "ok", layoutId: txt(r["layout_id"]) };
17
+ const reden = txt(r["reden"]);
18
+ return { state: "blocked", reden: reden ?? DOCUMENT_BLOCKED_FALLBACK, raw: reden };
19
+ }
20
+ /** Omhulsel van pickstation_document_for_order: { toegang, resultaat }. */
21
+ export function parseStationDocumentChoice(raw) {
22
+ const r = rec(raw);
23
+ if (!r || r["toegang"] !== true)
24
+ return { state: "unknown" };
25
+ if (r["resultaat"] == null)
26
+ return { state: "none" };
27
+ return parseDocumentChoice(r["resultaat"]);
28
+ }
29
+ /** Alleen een nieuwe (eerste) print wordt tegengehouden; herprint blijft altijd mogelijk. */
30
+ export function isPrintBlocked(choice, isReprint) {
31
+ return !isReprint && choice?.state === "blocked";
32
+ }
33
+ function orderIdOf(payload) {
34
+ const p = rec(payload);
35
+ return p ? txt(p["orderId"]) ?? txt(p["order_id"]) : null;
36
+ }
37
+ export async function fetchDocumentChoice(params) {
38
+ if (params.slug) {
39
+ const { data, error } = await db.rpc("pickstation_document_for_order", {
40
+ p_slug: params.slug,
41
+ p_queue_item_id: params.queueItemId,
42
+ });
43
+ if (error)
44
+ throw new Error(error.message);
45
+ return parseStationDocumentChoice(data);
46
+ }
47
+ const orderId = orderIdOf(params.payload);
48
+ if (!orderId || !params.documentType)
49
+ return { state: "none" };
50
+ const { data, error } = await db.rpc("logistics_document_for_order", {
51
+ p_order_id: orderId,
52
+ p_documenttype: params.documentType,
53
+ });
54
+ if (error)
55
+ throw new Error(error.message);
56
+ return parseDocumentChoice(data);
57
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowselections/pick-schermen-kwekers",
3
- "version": "1.0.55",
3
+ "version": "1.0.57",
4
4
  "flowselections": {
5
5
  "moduleId": "pick-schermen",
6
6
  "pages": [