@flowselections/floriday-afhandeling-module 1.0.48 → 1.0.50

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.
Files changed (41) hide show
  1. package/dist-lib/components/afhandeling/AutoProcessStatus.d.ts.map +1 -1
  2. package/dist-lib/components/afhandeling/AutoProcessStatus.js +4 -1
  3. package/dist-lib/components/afhandeling/ControlePage.js +1 -1
  4. package/dist-lib/components/afhandeling/DagDetailDialog.d.ts.map +1 -1
  5. package/dist-lib/components/afhandeling/DagDetailDialog.js +12 -6
  6. package/dist-lib/components/afhandeling/NuVersturenButton.d.ts +5 -0
  7. package/dist-lib/components/afhandeling/NuVersturenButton.d.ts.map +1 -0
  8. package/dist-lib/components/afhandeling/NuVersturenButton.js +50 -0
  9. package/dist-lib/components/afhandeling/ScanControleView.js +1 -1
  10. package/dist-lib/components/afhandeling/VervoerdersPage.js +1 -1
  11. package/dist-lib/components/afhandeling/VerzetOrderDialog.js +1 -1
  12. package/dist-lib/components/afhandeling/WerkplekWaarschuwing.d.ts +9 -9
  13. package/dist-lib/components/afhandeling/WerkplekWaarschuwing.js +28 -28
  14. package/dist-lib/components/ui/responsive-dialog.js +1 -1
  15. package/dist-lib/hooks/usePickMode.d.ts +1 -1
  16. package/dist-lib/integrations/supabase/client.server.js +1 -1
  17. package/dist-lib/integrations/supabase/moduleClient.d.ts +4 -31315
  18. package/dist-lib/integrations/supabase/moduleClient.d.ts.map +1 -1
  19. package/dist-lib/integrations/supabase/types.d.ts +3518 -66
  20. package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
  21. package/dist-lib/lib/afhandelingSettings.functions.d.ts.map +1 -1
  22. package/dist-lib/lib/afhandelingSettings.functions.js +2 -1
  23. package/dist-lib/lib/authGateway.server.d.ts +2 -0
  24. package/dist-lib/lib/authGateway.server.d.ts.map +1 -1
  25. package/dist-lib/lib/authGateway.server.js +2 -2
  26. package/dist-lib/lib/cartAssignments.functions.d.ts +20 -3
  27. package/dist-lib/lib/cartAssignments.functions.d.ts.map +1 -1
  28. package/dist-lib/lib/cartAssignments.functions.js +48 -37
  29. package/dist-lib/lib/deliveryNotePrint.d.ts +33 -33
  30. package/dist-lib/lib/deliveryNotePrint.js +219 -219
  31. package/dist-lib/lib/floridayAutoProcess.d.ts +1 -1
  32. package/dist-lib/lib/floridayAutoProcess.d.ts.map +1 -1
  33. package/dist-lib/lib/floridayFulfillmentSend.server.d.ts +31 -0
  34. package/dist-lib/lib/floridayFulfillmentSend.server.d.ts.map +1 -0
  35. package/dist-lib/lib/floridayFulfillmentSend.server.js +75 -0
  36. package/dist-lib/lib/floridayLoading.functions.d.ts +91 -0
  37. package/dist-lib/lib/floridayLoading.functions.d.ts.map +1 -0
  38. package/dist-lib/lib/floridayLoading.functions.js +311 -0
  39. package/dist-lib/lib/logisticsEngine/capacity.js +1 -1
  40. package/dist-lib/lib/logisticsEngine/staffPlanning.js +1 -1
  41. package/package.json +2 -2
@@ -1,219 +1,219 @@
1
- // Client-side helpers voor het ophalen en printen van Floriday-afleverbrieven
2
- // via de gateway-endpoints van de Authenticatie-module.
3
- // De Authenticatie-module accepteert een Supabase Bearer-token en stuurt
4
- // CORS-headers, dus we bellen direct cross-origin — geen eigen proxy nodig.
5
- import { printPdfBase64 } from "../components/pickstation/printDocuments";
6
- import { supabase } from "../integrations/supabase/moduleClient";
7
- import { resolveGatewayBaseClient } from "./gatewayBase";
8
- let floridayEnvironmentPromise = null;
9
- async function getFloridayEnvironment() {
10
- floridayEnvironmentPromise ?? (floridayEnvironmentPromise = Promise.resolve(supabase.from("floriday_settings").select("active_environment").eq("id", 1).maybeSingle()).then(({ data, error }) => {
11
- if (error) {
12
- console.warn("[delivery-note-print] active Floriday environment ophalen mislukt", error);
13
- }
14
- return data?.active_environment ?? "live";
15
- }));
16
- return floridayEnvironmentPromise;
17
- }
18
- async function getAccessToken() {
19
- const { data } = await supabase.auth.getSession();
20
- const token = data.session?.access_token;
21
- if (!token) {
22
- throw new Error("Niet ingelogd — kan afleverbrief niet ophalen.");
23
- }
24
- return token;
25
- }
26
- async function postJson(path, body) {
27
- const token = await getAccessToken();
28
- const base = resolveGatewayBaseClient();
29
- const res = await fetch(`${base}${path}`, {
30
- method: "POST",
31
- headers: {
32
- "Content-Type": "application/json",
33
- Authorization: `Bearer ${token}`,
34
- },
35
- body: JSON.stringify(body),
36
- });
37
- const ct = res.headers.get("content-type") ?? "";
38
- if (!ct.includes("application/json")) {
39
- throw new Error(`Gateway onbereikbaar (HTTP ${res.status}) — ontving ${ct || "onbekend content-type"}.`);
40
- }
41
- const text = await res.text();
42
- let data = null;
43
- try {
44
- data = text ? JSON.parse(text) : null;
45
- }
46
- catch {
47
- data = { ok: false, error: text };
48
- }
49
- return { status: res.status, data: data };
50
- }
51
- /**
52
- * Zoekt delivery-order IDs in de lokale cache voor een gegeven sales-order.
53
- * De gateway kan een delivery-note alleen genereren als er een delivery-order bestaat;
54
- * door hier eerst zelf te resolven omzeilen we de "Geen delivery-order beschikbaar" fout
55
- * wanneer de gateway de koppeling nog niet ziet.
56
- */
57
- async function resolveDeliveryOrderIds(salesOrderId) {
58
- const { data, error } = await supabase
59
- .from("floriday_delivery_orders_cache")
60
- .select("floriday_id, data")
61
- .contains("data", { fulfillmentRequests: [{ salesOrderId }] });
62
- if (error) {
63
- console.warn("[delivery-note-print] delivery-order lookup mislukt", error);
64
- return [];
65
- }
66
- const ids = new Set();
67
- for (const row of (data ?? [])) {
68
- const d = row.data;
69
- if (d?.isDeleted)
70
- continue;
71
- if (d?.fulfillmentRequests?.some((f) => f.salesOrderId === salesOrderId)) {
72
- ids.add(row.floriday_id);
73
- }
74
- }
75
- return [...ids];
76
- }
77
- /** Haalt de signed URL van een enkele afleverbrief op. */
78
- export async function fetchDeliveryNoteUrl(salesOrderId) {
79
- const environment = await getFloridayEnvironment();
80
- const deliveryOrderIds = await resolveDeliveryOrderIds(salesOrderId);
81
- if (deliveryOrderIds.length > 1) {
82
- throw new Error("Deze verkooporder heeft meerdere afleverbrieven — gebruik de dag-print om ze samen af te drukken.");
83
- }
84
- const payload = {
85
- environment,
86
- kind: "delivery-note",
87
- salesOrderId,
88
- };
89
- if (deliveryOrderIds[0])
90
- payload.deliveryOrderId = deliveryOrderIds[0];
91
- const { status, data } = await postJson("/api/public/gateway/pdf", payload);
92
- if (status === 409) {
93
- throw new Error("Deze verkooporder heeft meerdere afleverbrieven — gebruik de dag-print om ze samen af te drukken.");
94
- }
95
- if (!data?.ok || !data.url) {
96
- throw new Error(data?.error ?? `Afleverbrief ophalen mislukt (HTTP ${status})`);
97
- }
98
- return data.url;
99
- }
100
- /** Print een PDF vanaf een (signed) URL via de printwachtrij. */
101
- export async function printPdfFromUrl(url, opties) {
102
- const res = await fetch(url);
103
- if (!res.ok)
104
- throw new Error(`PDF download mislukt (HTTP ${res.status})`);
105
- const buf = new Uint8Array(await res.arrayBuffer());
106
- let binary = "";
107
- const chunk = 0x8000;
108
- for (let i = 0; i < buf.length; i += chunk) {
109
- binary += String.fromCharCode(...buf.subarray(i, i + chunk));
110
- }
111
- const base64 = btoa(binary);
112
- await printPdfBase64(base64, {
113
- documenttype: "afleverbrief",
114
- documentnaam: opties.documentnaam,
115
- isHerprint: opties.isHerprint,
116
- papierformaat: "A4",
117
- });
118
- }
119
- /** Haal en print één afleverbrief. */
120
- export async function printDeliveryNote(salesOrderId, opties) {
121
- const url = await fetchDeliveryNoteUrl(salesOrderId);
122
- await printPdfFromUrl(url, {
123
- documentnaam: opties?.documentnaam ?? `AFL-${salesOrderId}`,
124
- isHerprint: opties?.isHerprint,
125
- });
126
- }
127
- /** Maximaal aantal afleverbrieven in één samengevoegde printopdracht. */
128
- const CHUNK_SIZE = 25;
129
- /** Boven deze payloadgrootte (bytes) wordt de chunk gehalveerd. */
130
- const MAX_PAYLOAD_BYTES = 5 * 1024 * 1024;
131
- function base64Bytes(b64) {
132
- return Math.floor((b64.length * 3) / 4);
133
- }
134
- function vandaagIso() {
135
- return new Date().toISOString().slice(0, 10);
136
- }
137
- /**
138
- * Print meerdere afleverbrieven als samengevoegde PDF's van maximaal 25 stuks.
139
- * Te grote opdrachten worden automatisch verder opgeknipt.
140
- */
141
- export async function printDeliveryNotesMerged(items, opties) {
142
- const valid = items.filter((i) => i.salesOrderId || i.deliveryOrderId || i.fulfillmentOrderId);
143
- const summary = { total: valid.length, success: 0, failed: [] };
144
- if (valid.length === 0)
145
- return summary;
146
- const environment = await getFloridayEnvironment();
147
- // Verrijk items met deliveryOrderId uit de lokale cache waar mogelijk,
148
- // zodat de gateway niet meer op salesOrderId hoeft te zoeken.
149
- const enriched = [];
150
- for (const it of valid) {
151
- if (it.deliveryOrderId || it.fulfillmentOrderId || !it.salesOrderId) {
152
- enriched.push(it);
153
- continue;
154
- }
155
- const ids = await resolveDeliveryOrderIds(it.salesOrderId);
156
- if (ids.length === 0) {
157
- enriched.push(it);
158
- }
159
- else {
160
- for (const doId of ids)
161
- enriched.push({ ...it, deliveryOrderId: doId });
162
- }
163
- }
164
- const dag = vandaagIso();
165
- let deel = 0;
166
- const printChunk = async (chunk) => {
167
- if (chunk.length === 0)
168
- return;
169
- const { status, data } = await postJson("/api/public/gateway/pdf/bulk-merged", {
170
- environment,
171
- items: chunk.map((it) => ({
172
- id: it.id,
173
- ...(it.salesOrderId ? { salesOrderId: it.salesOrderId } : {}),
174
- ...(it.deliveryOrderId ? { deliveryOrderId: it.deliveryOrderId } : {}),
175
- ...(it.fulfillmentOrderId ? { fulfillmentOrderId: it.fulfillmentOrderId } : {}),
176
- })),
177
- });
178
- if (!data?.ok || !data.pdfBase64) {
179
- const err = data?.error ?? `HTTP ${status}`;
180
- for (const it of chunk)
181
- summary.failed.push({ id: it.id, error: err });
182
- return;
183
- }
184
- // Te grote samengevoegde PDF: halveren en opnieuw opvragen.
185
- if (chunk.length > 1 && base64Bytes(data.pdfBase64) > MAX_PAYLOAD_BYTES) {
186
- const half = Math.ceil(chunk.length / 2);
187
- await printChunk(chunk.slice(0, half));
188
- await printChunk(chunk.slice(half));
189
- return;
190
- }
191
- deel += 1;
192
- const documentnaam = chunk.length === 1
193
- ? `AFL-${chunk[0].salesOrderId ?? chunk[0].deliveryOrderId ?? chunk[0].id}`
194
- : `AFL-${dag}-deel-${deel}`;
195
- try {
196
- await printPdfBase64(data.pdfBase64, {
197
- documenttype: "afleverbrief",
198
- documentnaam,
199
- isHerprint: opties?.isHerprint,
200
- papierformaat: "A4",
201
- });
202
- }
203
- catch (e) {
204
- const msg = e instanceof Error ? e.message : "Printen mislukt";
205
- for (const it of chunk)
206
- summary.failed.push({ id: it.id, error: msg });
207
- return;
208
- }
209
- summary.success += data.success ?? chunk.length;
210
- for (const r of data.results ?? []) {
211
- if (!r.ok)
212
- summary.failed.push({ id: r.id, error: r.error ?? "onbekende fout" });
213
- }
214
- };
215
- for (let i = 0; i < enriched.length; i += CHUNK_SIZE) {
216
- await printChunk(enriched.slice(i, i + CHUNK_SIZE));
217
- }
218
- return summary;
219
- }
1
+ // Client-side helpers voor het ophalen en printen van Floriday-afleverbrieven
2
+ // via de gateway-endpoints van de Authenticatie-module.
3
+ // De Authenticatie-module accepteert een Supabase Bearer-token en stuurt
4
+ // CORS-headers, dus we bellen direct cross-origin — geen eigen proxy nodig.
5
+ import { printPdfBase64 } from "../components/pickstation/printDocuments";
6
+ import { supabase } from "../integrations/supabase/moduleClient";
7
+ import { resolveGatewayBaseClient } from "./gatewayBase";
8
+ let floridayEnvironmentPromise = null;
9
+ async function getFloridayEnvironment() {
10
+ floridayEnvironmentPromise ?? (floridayEnvironmentPromise = Promise.resolve(supabase.from("floriday_settings").select("active_environment").eq("id", 1).maybeSingle()).then(({ data, error }) => {
11
+ if (error) {
12
+ console.warn("[delivery-note-print] active Floriday environment ophalen mislukt", error);
13
+ }
14
+ return data?.active_environment ?? "live";
15
+ }));
16
+ return floridayEnvironmentPromise;
17
+ }
18
+ async function getAccessToken() {
19
+ const { data } = await supabase.auth.getSession();
20
+ const token = data.session?.access_token;
21
+ if (!token) {
22
+ throw new Error("Niet ingelogd — kan afleverbrief niet ophalen.");
23
+ }
24
+ return token;
25
+ }
26
+ async function postJson(path, body) {
27
+ const token = await getAccessToken();
28
+ const base = resolveGatewayBaseClient();
29
+ const res = await fetch(`${base}${path}`, {
30
+ method: "POST",
31
+ headers: {
32
+ "Content-Type": "application/json",
33
+ Authorization: `Bearer ${token}`,
34
+ },
35
+ body: JSON.stringify(body),
36
+ });
37
+ const ct = res.headers.get("content-type") ?? "";
38
+ if (!ct.includes("application/json")) {
39
+ throw new Error(`Gateway onbereikbaar (HTTP ${res.status}) — ontving ${ct || "onbekend content-type"}.`);
40
+ }
41
+ const text = await res.text();
42
+ let data = null;
43
+ try {
44
+ data = text ? JSON.parse(text) : null;
45
+ }
46
+ catch {
47
+ data = { ok: false, error: text };
48
+ }
49
+ return { status: res.status, data: data };
50
+ }
51
+ /**
52
+ * Zoekt delivery-order IDs in de lokale cache voor een gegeven sales-order.
53
+ * De gateway kan een delivery-note alleen genereren als er een delivery-order bestaat;
54
+ * door hier eerst zelf te resolven omzeilen we de "Geen delivery-order beschikbaar" fout
55
+ * wanneer de gateway de koppeling nog niet ziet.
56
+ */
57
+ async function resolveDeliveryOrderIds(salesOrderId) {
58
+ const { data, error } = await supabase
59
+ .from("floriday_delivery_orders_cache")
60
+ .select("floriday_id, data")
61
+ .contains("data", { fulfillmentRequests: [{ salesOrderId }] });
62
+ if (error) {
63
+ console.warn("[delivery-note-print] delivery-order lookup mislukt", error);
64
+ return [];
65
+ }
66
+ const ids = new Set();
67
+ for (const row of (data ?? [])) {
68
+ const d = row.data;
69
+ if (d?.isDeleted)
70
+ continue;
71
+ if (d?.fulfillmentRequests?.some((f) => f.salesOrderId === salesOrderId)) {
72
+ ids.add(row.floriday_id);
73
+ }
74
+ }
75
+ return [...ids];
76
+ }
77
+ /** Haalt de signed URL van een enkele afleverbrief op. */
78
+ export async function fetchDeliveryNoteUrl(salesOrderId) {
79
+ const environment = await getFloridayEnvironment();
80
+ const deliveryOrderIds = await resolveDeliveryOrderIds(salesOrderId);
81
+ if (deliveryOrderIds.length > 1) {
82
+ throw new Error("Deze verkooporder heeft meerdere afleverbrieven — gebruik de dag-print om ze samen af te drukken.");
83
+ }
84
+ const payload = {
85
+ environment,
86
+ kind: "delivery-note",
87
+ salesOrderId,
88
+ };
89
+ if (deliveryOrderIds[0])
90
+ payload.deliveryOrderId = deliveryOrderIds[0];
91
+ const { status, data } = await postJson("/api/public/gateway/pdf", payload);
92
+ if (status === 409) {
93
+ throw new Error("Deze verkooporder heeft meerdere afleverbrieven — gebruik de dag-print om ze samen af te drukken.");
94
+ }
95
+ if (!data?.ok || !data.url) {
96
+ throw new Error(data?.error ?? `Afleverbrief ophalen mislukt (HTTP ${status})`);
97
+ }
98
+ return data.url;
99
+ }
100
+ /** Print een PDF vanaf een (signed) URL via de printwachtrij. */
101
+ export async function printPdfFromUrl(url, opties) {
102
+ const res = await fetch(url);
103
+ if (!res.ok)
104
+ throw new Error(`PDF download mislukt (HTTP ${res.status})`);
105
+ const buf = new Uint8Array(await res.arrayBuffer());
106
+ let binary = "";
107
+ const chunk = 0x8000;
108
+ for (let i = 0; i < buf.length; i += chunk) {
109
+ binary += String.fromCharCode(...buf.subarray(i, i + chunk));
110
+ }
111
+ const base64 = btoa(binary);
112
+ await printPdfBase64(base64, {
113
+ documenttype: "afleverbrief",
114
+ documentnaam: opties.documentnaam,
115
+ isHerprint: opties.isHerprint,
116
+ papierformaat: "A4",
117
+ });
118
+ }
119
+ /** Haal en print één afleverbrief. */
120
+ export async function printDeliveryNote(salesOrderId, opties) {
121
+ const url = await fetchDeliveryNoteUrl(salesOrderId);
122
+ await printPdfFromUrl(url, {
123
+ documentnaam: opties?.documentnaam ?? `AFL-${salesOrderId}`,
124
+ isHerprint: opties?.isHerprint,
125
+ });
126
+ }
127
+ /** Maximaal aantal afleverbrieven in één samengevoegde printopdracht. */
128
+ const CHUNK_SIZE = 25;
129
+ /** Boven deze payloadgrootte (bytes) wordt de chunk gehalveerd. */
130
+ const MAX_PAYLOAD_BYTES = 5 * 1024 * 1024;
131
+ function base64Bytes(b64) {
132
+ return Math.floor((b64.length * 3) / 4);
133
+ }
134
+ function vandaagIso() {
135
+ return new Date().toISOString().slice(0, 10);
136
+ }
137
+ /**
138
+ * Print meerdere afleverbrieven als samengevoegde PDF's van maximaal 25 stuks.
139
+ * Te grote opdrachten worden automatisch verder opgeknipt.
140
+ */
141
+ export async function printDeliveryNotesMerged(items, opties) {
142
+ const valid = items.filter((i) => i.salesOrderId || i.deliveryOrderId || i.fulfillmentOrderId);
143
+ const summary = { total: valid.length, success: 0, failed: [] };
144
+ if (valid.length === 0)
145
+ return summary;
146
+ const environment = await getFloridayEnvironment();
147
+ // Verrijk items met deliveryOrderId uit de lokale cache waar mogelijk,
148
+ // zodat de gateway niet meer op salesOrderId hoeft te zoeken.
149
+ const enriched = [];
150
+ for (const it of valid) {
151
+ if (it.deliveryOrderId || it.fulfillmentOrderId || !it.salesOrderId) {
152
+ enriched.push(it);
153
+ continue;
154
+ }
155
+ const ids = await resolveDeliveryOrderIds(it.salesOrderId);
156
+ if (ids.length === 0) {
157
+ enriched.push(it);
158
+ }
159
+ else {
160
+ for (const doId of ids)
161
+ enriched.push({ ...it, deliveryOrderId: doId });
162
+ }
163
+ }
164
+ const dag = vandaagIso();
165
+ let deel = 0;
166
+ const printChunk = async (chunk) => {
167
+ if (chunk.length === 0)
168
+ return;
169
+ const { status, data } = await postJson("/api/public/gateway/pdf/bulk-merged", {
170
+ environment,
171
+ items: chunk.map((it) => ({
172
+ id: it.id,
173
+ ...(it.salesOrderId ? { salesOrderId: it.salesOrderId } : {}),
174
+ ...(it.deliveryOrderId ? { deliveryOrderId: it.deliveryOrderId } : {}),
175
+ ...(it.fulfillmentOrderId ? { fulfillmentOrderId: it.fulfillmentOrderId } : {}),
176
+ })),
177
+ });
178
+ if (!data?.ok || !data.pdfBase64) {
179
+ const err = data?.error ?? `HTTP ${status}`;
180
+ for (const it of chunk)
181
+ summary.failed.push({ id: it.id, error: err });
182
+ return;
183
+ }
184
+ // Te grote samengevoegde PDF: halveren en opnieuw opvragen.
185
+ if (chunk.length > 1 && base64Bytes(data.pdfBase64) > MAX_PAYLOAD_BYTES) {
186
+ const half = Math.ceil(chunk.length / 2);
187
+ await printChunk(chunk.slice(0, half));
188
+ await printChunk(chunk.slice(half));
189
+ return;
190
+ }
191
+ deel += 1;
192
+ const documentnaam = chunk.length === 1
193
+ ? `AFL-${chunk[0].salesOrderId ?? chunk[0].deliveryOrderId ?? chunk[0].id}`
194
+ : `AFL-${dag}-deel-${deel}`;
195
+ try {
196
+ await printPdfBase64(data.pdfBase64, {
197
+ documenttype: "afleverbrief",
198
+ documentnaam,
199
+ isHerprint: opties?.isHerprint,
200
+ papierformaat: "A4",
201
+ });
202
+ }
203
+ catch (e) {
204
+ const msg = e instanceof Error ? e.message : "Printen mislukt";
205
+ for (const it of chunk)
206
+ summary.failed.push({ id: it.id, error: msg });
207
+ return;
208
+ }
209
+ summary.success += data.success ?? chunk.length;
210
+ for (const r of data.results ?? []) {
211
+ if (!r.ok)
212
+ summary.failed.push({ id: r.id, error: r.error ?? "onbekende fout" });
213
+ }
214
+ };
215
+ for (let i = 0; i < enriched.length; i += CHUNK_SIZE) {
216
+ await printChunk(enriched.slice(i, i + CHUNK_SIZE));
217
+ }
218
+ return summary;
219
+ }
@@ -1,4 +1,4 @@
1
- export type AutoProcessStep = "waiting" | "waiting_for_commit" | "waiting_for_delivery_order" | "ready_to_fulfill" | "acknowledging" | "creating_delivery_order" | "sending_fulfillment" | "generating_delivery_note" | "done" | "error";
1
+ export type AutoProcessStep = "waiting" | "waiting_for_commit" | "waiting_for_delivery_order" | "ready_to_fulfill" | "waiting_for_afhandeling" | "acknowledging" | "creating_delivery_order" | "sending_fulfillment" | "generating_delivery_note" | "done" | "error";
2
2
  export interface AutoProcessStatusRow {
3
3
  salesOrderId: string;
4
4
  status: AutoProcessStep;
@@ -1 +1 @@
1
- {"version":3,"file":"floridayAutoProcess.d.ts","sourceRoot":"","sources":["../../src/lib/floridayAutoProcess.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,oBAAoB,GACpB,4BAA4B,GAC5B,kBAAkB,GAClB,eAAe,GACf,yBAAyB,GACzB,qBAAqB,GACrB,0BAA0B,GAC1B,MAAM,GACN,OAAO,CAAC;AAEZ,MAAM,WAAW,oBAAoB;IACnC,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AASD;;;;GAIG;AACH,wBAAsB,qBAAqB,CACzC,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,mBAAmB,CAAC,CAsB9B;AAED;;GAEG;AACH,wBAAsB,wBAAwB,CAC5C,aAAa,EAAE,MAAM,EAAE,GACtB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAqC5C"}
1
+ {"version":3,"file":"floridayAutoProcess.d.ts","sourceRoot":"","sources":["../../src/lib/floridayAutoProcess.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,oBAAoB,GACpB,4BAA4B,GAC5B,kBAAkB,GAClB,yBAAyB,GACzB,eAAe,GACf,yBAAyB,GACzB,qBAAqB,GACrB,0BAA0B,GAC1B,MAAM,GACN,OAAO,CAAC;AAEZ,MAAM,WAAW,oBAAoB;IACnC,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AASD;;;;GAIG;AACH,wBAAsB,qBAAqB,CACzC,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,mBAAmB,CAAC,CAsB9B;AAED;;GAEG;AACH,wBAAsB,wBAAwB,CAC5C,aAAa,EAAE,MAAM,EAAE,GACtB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAqC5C"}
@@ -0,0 +1,31 @@
1
+ export interface GatewayResult {
2
+ httpStatus: number;
3
+ body: any;
4
+ }
5
+ export interface FulfillmentRequestStatus {
6
+ fulfillmentRequestId: string;
7
+ deliveryOrderId: string | null;
8
+ fulfillmentOrderIds: string[];
9
+ }
10
+ export interface FulfillmentOrderStatus {
11
+ fulfillmentOrderId: string;
12
+ status: string | null;
13
+ deliveryNoteReady: boolean | null;
14
+ }
15
+ export interface SalesOrderStatus {
16
+ salesOrderId: string;
17
+ found: boolean;
18
+ salesOrderStatus: string | null;
19
+ floridayStage: string | null;
20
+ fulfillmentRequests: FulfillmentRequestStatus[];
21
+ fulfillmentOrders: FulfillmentOrderStatus[];
22
+ }
23
+ /**
24
+ * Statusoverzicht (Floriday-authenticatie 1.0.64), in porties van maximaal 100.
25
+ * Exact contract per order: salesOrderId, found, salesOrderStatus, floridayStage,
26
+ * fulfillmentRequests[] { fulfillmentRequestId, deliveryOrderId, fulfillmentOrderIds },
27
+ * fulfillmentOrders[] { fulfillmentOrderId, status, deliveryNoteReady }.
28
+ */
29
+ export declare function fetchFulfillmentStatus(salesOrderIds: string[]): Promise<Map<string, SalesOrderStatus>>;
30
+ export declare function sendFulfillmentOrder(payload: Record<string, unknown>): Promise<GatewayResult>;
31
+ //# sourceMappingURL=floridayFulfillmentSend.server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"floridayFulfillmentSend.server.d.ts","sourceRoot":"","sources":["../../src/lib/floridayFulfillmentSend.server.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,GAAG,CAAC;CACX;AA4BD,MAAM,WAAW,wBAAwB;IACvC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,mBAAmB,EAAE,MAAM,EAAE,CAAC;CAC/B;AACD,MAAM,WAAW,sBAAsB;IACrC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,iBAAiB,EAAE,OAAO,GAAG,IAAI,CAAC;CACnC;AACD,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,OAAO,CAAC;IACf,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,mBAAmB,EAAE,wBAAwB,EAAE,CAAC;IAChD,iBAAiB,EAAE,sBAAsB,EAAE,CAAC;CAC7C;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAgC5G;AAED,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,CAEnG"}
@@ -0,0 +1,75 @@
1
+ // Server-only: getekende aanroepen naar Floriday-authenticatie (>= 1.0.64) voor stap 3.
2
+ // - fulfillment-order/status { salesOrderIds } → fulfillmentRequestId + deliveryOrderId per order
3
+ // - fulfillment-order/send { deliveryOrderId, ... } → belading (enige route voor belading)
4
+ // Adres en geheim komen uit de omgeving; ontbreken ze, dan volgt een fout (fail closed).
5
+ import { resolveGatewayBaseServer } from "./gatewayBase.server";
6
+ import { getFloridayGatewaySecret } from "./centralSecrets.server";
7
+ import { signBody } from "./authGateway.server";
8
+ async function signedPost(path, payload) {
9
+ const secret = await getFloridayGatewaySecret(); // throws als het ontbreekt
10
+ const base = await resolveGatewayBaseServer(); // throws als het ontbreekt
11
+ const bodyStr = JSON.stringify(payload);
12
+ const timestamp = new Date().toISOString();
13
+ const signature = await signBody(secret, timestamp, bodyStr);
14
+ const res = await fetch(`${base}/api/public/gateway/${path}`, {
15
+ method: "POST",
16
+ headers: {
17
+ "Content-Type": "application/json",
18
+ "x-floriday-timestamp": timestamp,
19
+ "x-floriday-signature": signature,
20
+ // Zelfde handtekening onder de oudere kopnamen, voor de bestaande gateway-routes.
21
+ "X-Timestamp": timestamp,
22
+ "X-Signature": signature,
23
+ },
24
+ body: bodyStr,
25
+ });
26
+ const ct = res.headers.get("content-type") ?? "";
27
+ const body = ct.includes("application/json") ? await res.json().catch(() => null) : null;
28
+ return { httpStatus: res.status, body };
29
+ }
30
+ const arr = (v) => (Array.isArray(v) ? v : []);
31
+ const str = (v) => (typeof v === "string" && v ? v : null);
32
+ /**
33
+ * Statusoverzicht (Floriday-authenticatie 1.0.64), in porties van maximaal 100.
34
+ * Exact contract per order: salesOrderId, found, salesOrderStatus, floridayStage,
35
+ * fulfillmentRequests[] { fulfillmentRequestId, deliveryOrderId, fulfillmentOrderIds },
36
+ * fulfillmentOrders[] { fulfillmentOrderId, status, deliveryNoteReady }.
37
+ */
38
+ export async function fetchFulfillmentStatus(salesOrderIds) {
39
+ const out = new Map();
40
+ const ids = [...new Set(salesOrderIds.filter(Boolean))];
41
+ for (let i = 0; i < ids.length; i += 100) {
42
+ const r = await signedPost("fulfillment-order/status", { salesOrderIds: ids.slice(i, i + 100) });
43
+ if (r.httpStatus >= 400 || !r.body) {
44
+ throw new Error(`Statusoverzicht van Floriday-authenticatie mislukt (HTTP ${r.httpStatus}${r.body?.code ? `, ${r.body.code}` : ""}).`);
45
+ }
46
+ const rows = Array.isArray(r.body) ? r.body : r.body.orders;
47
+ if (!Array.isArray(rows))
48
+ throw new Error("Statusoverzicht heeft geen lijst met orders.");
49
+ for (const row of rows) {
50
+ const so = str(row?.salesOrderId);
51
+ if (!so)
52
+ continue;
53
+ out.set(so, {
54
+ salesOrderId: so,
55
+ found: row.found === true,
56
+ salesOrderStatus: str(row.salesOrderStatus),
57
+ floridayStage: str(row.floridayStage),
58
+ fulfillmentRequests: arr(row.fulfillmentRequests).map((x) => ({
59
+ fulfillmentRequestId: str(x?.fulfillmentRequestId) ?? "",
60
+ deliveryOrderId: str(x?.deliveryOrderId),
61
+ fulfillmentOrderIds: arr(x?.fulfillmentOrderIds).map(str).filter((y) => !!y),
62
+ })).filter((x) => x.fulfillmentRequestId),
63
+ fulfillmentOrders: arr(row.fulfillmentOrders).map((x) => ({
64
+ fulfillmentOrderId: str(x?.fulfillmentOrderId) ?? "",
65
+ status: str(x?.status),
66
+ deliveryNoteReady: typeof x?.deliveryNoteReady === "boolean" ? x.deliveryNoteReady : null,
67
+ })).filter((x) => x.fulfillmentOrderId),
68
+ });
69
+ }
70
+ }
71
+ return out;
72
+ }
73
+ export async function sendFulfillmentOrder(payload) {
74
+ return signedPost("fulfillment-order/send", payload);
75
+ }
@@ -0,0 +1,91 @@
1
+ export interface LoadingItem {
2
+ loadCarrierItemId: string;
3
+ orderRef: string;
4
+ salesOrderId: string | null;
5
+ fulfillmentRequestId: string | null;
6
+ numberOfPackages: number;
7
+ sortIndex: number;
8
+ }
9
+ export interface LoadingCarrier {
10
+ loadCarrierReference: string;
11
+ cartLabel: string;
12
+ sortIndex: number;
13
+ shared: boolean;
14
+ items: LoadingItem[];
15
+ }
16
+ export interface OrderCheck {
17
+ orderRef: string;
18
+ salesOrderId: string | null;
19
+ pickStatus: string | null;
20
+ controlled: boolean;
21
+ cartsTotal: number;
22
+ cartsControlled: number;
23
+ deliveryOrderId: string | null;
24
+ autoStatus: string | null;
25
+ }
26
+ export interface LoadingShipment {
27
+ fulfillmentOrderId: string;
28
+ deliveryOrderId: string | null;
29
+ orderRefs: string[];
30
+ salesOrderIds: string[];
31
+ carriers: LoadingCarrier[];
32
+ /** Uit fulfillmentOrders[] van het statusoverzicht; null = nog niet bekend. */
33
+ floridayStatus: string | null;
34
+ deliveryNoteReady: boolean | null;
35
+ }
36
+ export interface LoadingAttempt {
37
+ fulfillmentOrderId: string;
38
+ step: string;
39
+ code: string | null;
40
+ message: string | null;
41
+ createdAt: string;
42
+ }
43
+ export interface LoadingPreview {
44
+ fulfillmentOrderId: string | null;
45
+ orderRefs: string[];
46
+ carriers: LoadingCarrier[];
47
+ cartCount: number;
48
+ lineCount: number;
49
+ orders: OrderCheck[];
50
+ shipments: LoadingShipment[];
51
+ lastAttempts: LoadingAttempt[];
52
+ /** Redenen waarom nog niet verstuurd mag worden; leeg = klaar. */
53
+ blockers: string[];
54
+ canSend: boolean;
55
+ }
56
+ export interface SendResult {
57
+ ok: boolean;
58
+ results: {
59
+ fulfillmentOrderId: string;
60
+ code: string;
61
+ httpStatus: number | null;
62
+ message: string;
63
+ deliveryNote: string;
64
+ }[];
65
+ }
66
+ /** Stelt de belading samen en toont de controles. Verstuurt niets. */
67
+ export declare const prepareFloridayLoading: import("@tanstack/start-client-core").RequiredFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
68
+ supabase: import("../integrations/supabase/auth-middleware").AuthedSupabaseClient;
69
+ userId: string;
70
+ claims: import("@supabase/auth-js").JwtPayload;
71
+ }, undefined, undefined, undefined>], (d: {
72
+ orderRef: string;
73
+ }) => {
74
+ orderRef: string;
75
+ }, Promise<LoadingPreview>>;
76
+ /**
77
+ * "Nu versturen": bouwt de belading opnieuw op (zelfde vaste kenmerken), controleert
78
+ * alles nogmaals op de server en verstuurt via fulfillment-order/send. Na acceptatie
79
+ * (created / already_fulfilled) volgt de verzendbrief via de Logistieke Engine. Elke poging komt in
80
+ * floriday_loading_attempts. Herhalen gebruikt altijd dezelfde fulfillmentOrderId.
81
+ */
82
+ export declare const sendFloridayLoading: import("@tanstack/start-client-core").RequiredFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
83
+ supabase: import("../integrations/supabase/auth-middleware").AuthedSupabaseClient;
84
+ userId: string;
85
+ claims: import("@supabase/auth-js").JwtPayload;
86
+ }, undefined, undefined, undefined>], (d: {
87
+ orderRef: string;
88
+ }) => {
89
+ orderRef: string;
90
+ }, Promise<SendResult>>;
91
+ //# sourceMappingURL=floridayLoading.functions.d.ts.map