@flowselections/floriday-afhandeling-module 1.0.15 → 1.0.16

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 (91) hide show
  1. package/dist-lib/components/afhandeling/LeveringenPage.d.ts.map +1 -1
  2. package/dist-lib/components/afhandeling/LeveringenPage.js +2 -2
  3. package/dist-lib/components/afhandeling/PickAgendaView.d.ts.map +1 -1
  4. package/dist-lib/components/afhandeling/PickAgendaView.js +2 -3
  5. package/dist-lib/components/afhandeling/WeekAgendaView.d.ts.map +1 -1
  6. package/dist-lib/components/afhandeling/WeekAgendaView.js +31 -17
  7. package/dist-lib/components/engine/CapaciteitsmaatregelenPage.d.ts +2 -0
  8. package/dist-lib/components/engine/CapaciteitsmaatregelenPage.d.ts.map +1 -0
  9. package/dist-lib/components/engine/CapaciteitsmaatregelenPage.js +40 -0
  10. package/dist-lib/components/engine/CapaciteitsmonitorPage.d.ts +2 -0
  11. package/dist-lib/components/engine/CapaciteitsmonitorPage.d.ts.map +1 -0
  12. package/dist-lib/components/engine/CapaciteitsmonitorPage.js +49 -0
  13. package/dist-lib/components/engine/FormulesPage.d.ts +2 -0
  14. package/dist-lib/components/engine/FormulesPage.d.ts.map +1 -0
  15. package/dist-lib/components/engine/FormulesPage.js +255 -0
  16. package/dist-lib/components/engine/PlaceholderPage.d.ts +6 -0
  17. package/dist-lib/components/engine/PlaceholderPage.d.ts.map +1 -0
  18. package/dist-lib/components/engine/PlaceholderPage.js +6 -0
  19. package/dist-lib/components/engine/StrategieenPage.d.ts +2 -0
  20. package/dist-lib/components/engine/StrategieenPage.d.ts.map +1 -0
  21. package/dist-lib/components/engine/StrategieenPage.js +80 -0
  22. package/dist-lib/components/pickstation/PickstationPage.d.ts.map +1 -1
  23. package/dist-lib/components/pickstation/PickstationPage.js +16 -4
  24. package/dist-lib/hooks/useOrderPlanning.d.ts.map +1 -1
  25. package/dist-lib/hooks/useOrderPlanning.js +37 -3
  26. package/dist-lib/index.d.ts.map +1 -1
  27. package/dist-lib/index.js +2 -1
  28. package/dist-lib/integrations/supabase/auth-middleware.d.ts +1340 -164
  29. package/dist-lib/integrations/supabase/auth-middleware.d.ts.map +1 -1
  30. package/dist-lib/integrations/supabase/client.d.ts +1340 -164
  31. package/dist-lib/integrations/supabase/client.d.ts.map +1 -1
  32. package/dist-lib/integrations/supabase/client.server.d.ts +1340 -164
  33. package/dist-lib/integrations/supabase/client.server.d.ts.map +1 -1
  34. package/dist-lib/integrations/supabase/types.d.ts +1469 -262
  35. package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
  36. package/dist-lib/lib/afhandelingSettings.functions.d.ts +2862 -510
  37. package/dist-lib/lib/afhandelingSettings.functions.d.ts.map +1 -1
  38. package/dist-lib/lib/ai-gateway.server.d.ts +2 -0
  39. package/dist-lib/lib/ai-gateway.server.d.ts.map +1 -0
  40. package/dist-lib/lib/ai-gateway.server.js +11 -0
  41. package/dist-lib/lib/authGateway.server.d.ts +16 -0
  42. package/dist-lib/lib/authGateway.server.d.ts.map +1 -0
  43. package/dist-lib/lib/authGateway.server.js +195 -0
  44. package/dist-lib/lib/carriers.functions.d.ts +6645 -765
  45. package/dist-lib/lib/carriers.functions.d.ts.map +1 -1
  46. package/dist-lib/lib/cartAssignments.functions.d.ts +6645 -765
  47. package/dist-lib/lib/cartAssignments.functions.d.ts.map +1 -1
  48. package/dist-lib/lib/cartControl.functions.d.ts +13290 -1530
  49. package/dist-lib/lib/cartControl.functions.d.ts.map +1 -1
  50. package/dist-lib/lib/floriday.functions.d.ts +1340 -164
  51. package/dist-lib/lib/floriday.functions.d.ts.map +1 -1
  52. package/dist-lib/lib/floriday.functions.js +41 -8
  53. package/dist-lib/lib/logisticsEngine/capacity.functions.d.ts +50090 -0
  54. package/dist-lib/lib/logisticsEngine/capacity.functions.d.ts.map +1 -0
  55. package/dist-lib/lib/logisticsEngine/capacity.functions.js +90 -0
  56. package/dist-lib/lib/logisticsEngine/config.d.ts +140 -0
  57. package/dist-lib/lib/logisticsEngine/config.d.ts.map +1 -0
  58. package/dist-lib/lib/logisticsEngine/config.js +488 -0
  59. package/dist-lib/lib/logisticsEngine/enginePickTime.d.ts +29 -0
  60. package/dist-lib/lib/logisticsEngine/enginePickTime.d.ts.map +1 -0
  61. package/dist-lib/lib/logisticsEngine/enginePickTime.js +136 -0
  62. package/dist-lib/lib/logisticsEngine/evaluate.functions.d.ts +12556 -0
  63. package/dist-lib/lib/logisticsEngine/evaluate.functions.d.ts.map +1 -0
  64. package/dist-lib/lib/logisticsEngine/evaluate.functions.js +104 -0
  65. package/dist-lib/lib/logisticsEngine/expression.d.ts +21 -0
  66. package/dist-lib/lib/logisticsEngine/expression.d.ts.map +1 -0
  67. package/dist-lib/lib/logisticsEngine/expression.js +263 -0
  68. package/dist-lib/lib/logisticsEngine/formulas.functions.d.ts +25068 -0
  69. package/dist-lib/lib/logisticsEngine/formulas.functions.d.ts.map +1 -0
  70. package/dist-lib/lib/logisticsEngine/formulas.functions.js +58 -0
  71. package/dist-lib/lib/logisticsEngine/safetyLayer.d.ts +83 -0
  72. package/dist-lib/lib/logisticsEngine/safetyLayer.d.ts.map +1 -0
  73. package/dist-lib/lib/logisticsEngine/safetyLayer.js +182 -0
  74. package/dist-lib/lib/logisticsEngine/strategies.functions.d.ts +100185 -0
  75. package/dist-lib/lib/logisticsEngine/strategies.functions.d.ts.map +1 -0
  76. package/dist-lib/lib/logisticsEngine/strategies.functions.js +176 -0
  77. package/dist-lib/lib/logisticsEngine/variables.d.ts +29 -0
  78. package/dist-lib/lib/logisticsEngine/variables.d.ts.map +1 -0
  79. package/dist-lib/lib/logisticsEngine/variables.js +144 -0
  80. package/dist-lib/lib/logisticsEngine/wizard.functions.d.ts +50096 -0
  81. package/dist-lib/lib/logisticsEngine/wizard.functions.d.ts.map +1 -0
  82. package/dist-lib/lib/logisticsEngine/wizard.functions.js +175 -0
  83. package/dist-lib/lib/pickstationI18n.d.ts +2 -0
  84. package/dist-lib/lib/pickstationI18n.d.ts.map +1 -1
  85. package/dist-lib/lib/pickstationI18n.js +12 -0
  86. package/dist-lib/lib/pickstationOrders.server.d.ts +5 -0
  87. package/dist-lib/lib/pickstationOrders.server.d.ts.map +1 -1
  88. package/dist-lib/lib/pickstationOrders.server.js +29 -0
  89. package/dist-lib/lib/pickstationTypes.d.ts +4 -0
  90. package/dist-lib/lib/pickstationTypes.d.ts.map +1 -1
  91. package/package.json +6 -4
@@ -0,0 +1,16 @@
1
+ /** Batch-variant — geeft per sales-order-id een set delivery-order-ids terug. */
2
+ export declare function resolveDeliveryOrdersBatch(salesOrderIds: string[]): Promise<Map<string, string[]>>;
3
+ /**
4
+ * Haalt de Floriday-afleverbrief PDF op voor een sales-order via de
5
+ * Authenticatie-module gateway. Retourneert null wanneer:
6
+ * - de secret niet geconfigureerd is
7
+ * - er (nog) geen delivery-order in de cache staat
8
+ * - de gateway een fout of geen URL teruggeeft
9
+ * - de PDF-download faalt
10
+ * Nooit throws — de pakbon-print moet altijd door kunnen gaan.
11
+ */
12
+ export declare function fetchDeliveryNotePdf(salesOrderId: string): Promise<{
13
+ base64: string;
14
+ mime: string;
15
+ } | null>;
16
+ //# sourceMappingURL=authGateway.server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authGateway.server.d.ts","sourceRoot":"","sources":["../../src/lib/authGateway.server.ts"],"names":[],"mappings":"AAoFA,iFAAiF;AACjF,wBAAsB,0BAA0B,CAC9C,aAAa,EAAE,MAAM,EAAE,GACtB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CA6BhC;AAgCD;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CACxC,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CAqElD"}
@@ -0,0 +1,195 @@
1
+ // Server-only helper: HMAC-getekende call naar de Authenticatie-module gateway
2
+ // om een Floriday-afleverbrief (delivery note / logistic-labels PDF) op te halen
3
+ // vanuit een publieke Pickstation-route (geen Supabase-sessie beschikbaar).
4
+ //
5
+ // Signature schema (moet identiek zijn in de Authenticatie-module):
6
+ // message = `${timestamp}.${JSON.stringify(body)}`
7
+ // signature = hex(HMAC-SHA256(AUTH_GATEWAY_HMAC_SECRET, message))
8
+ // headers = { "X-Signature": signature, "X-Timestamp": timestamp }
9
+ // Timestamp = ISO 8601 UTC, ±5 min venster.
10
+ import { createHmac } from "node:crypto";
11
+ import { createClient } from "@supabase/supabase-js";
12
+ const GATEWAY_URL_FALLBACK = "https://floriday-authenticatie-module.lovable.app";
13
+ const LOG = "[auth-gateway]";
14
+ function gatewayBase() {
15
+ const raw = process.env.AUTH_GATEWAY_URL ??
16
+ process.env.VITE_AUTH_GATEWAY_URL ??
17
+ GATEWAY_URL_FALLBACK;
18
+ return raw.replace(/\/$/, "");
19
+ }
20
+ function getSupabase() {
21
+ const url = process.env.SUPABASE_URL ?? process.env.VITE_SUPABASE_URL;
22
+ const key = process.env.SUPABASE_PUBLISHABLE_KEY ?? process.env.VITE_SUPABASE_PUBLISHABLE_KEY;
23
+ if (!url || !key)
24
+ throw new Error("Supabase publishable env vars ontbreken");
25
+ return createClient(url, key, {
26
+ auth: { storage: undefined, persistSession: false, autoRefreshToken: false },
27
+ });
28
+ }
29
+ let cachedEnvironment = null;
30
+ async function getFloridayEnvironment() {
31
+ if (cachedEnvironment)
32
+ return cachedEnvironment;
33
+ try {
34
+ const supabase = getSupabase();
35
+ const { data, error } = await supabase
36
+ .from("floriday_settings")
37
+ .select("active_environment")
38
+ .eq("id", 1)
39
+ .maybeSingle();
40
+ if (error) {
41
+ console.warn(`${LOG} kon actieve Floriday-omgeving niet ophalen`, error.message);
42
+ }
43
+ cachedEnvironment = data?.active_environment ?? "live";
44
+ }
45
+ catch (e) {
46
+ console.warn(`${LOG} kon actieve Floriday-omgeving niet ophalen`, e instanceof Error ? e.message : String(e));
47
+ cachedEnvironment = "live";
48
+ }
49
+ return cachedEnvironment;
50
+ }
51
+ /** Resolvt delivery-order-ids voor één sales-order via de SECURITY DEFINER RPC. */
52
+ async function resolveDeliveryOrderIds(salesOrderId) {
53
+ try {
54
+ const supabase = getSupabase();
55
+ const { data, error } = await supabase.rpc("pickstation_resolve_delivery_orders", {
56
+ p_sales_order_ids: [salesOrderId],
57
+ });
58
+ if (error) {
59
+ console.warn(`${LOG} delivery-order lookup mislukt`, error.message);
60
+ return [];
61
+ }
62
+ const ids = new Set();
63
+ for (const row of (data ?? [])) {
64
+ if (row.delivery_order_id)
65
+ ids.add(row.delivery_order_id);
66
+ }
67
+ return [...ids];
68
+ }
69
+ catch (e) {
70
+ console.warn(`${LOG} delivery-order lookup exception`, e instanceof Error ? e.message : String(e));
71
+ return [];
72
+ }
73
+ }
74
+ /** Batch-variant — geeft per sales-order-id een set delivery-order-ids terug. */
75
+ export async function resolveDeliveryOrdersBatch(salesOrderIds) {
76
+ const out = new Map();
77
+ const unique = [...new Set(salesOrderIds.filter(Boolean))];
78
+ if (unique.length === 0)
79
+ return out;
80
+ try {
81
+ const supabase = getSupabase();
82
+ const { data, error } = await supabase.rpc("pickstation_resolve_delivery_orders", {
83
+ p_sales_order_ids: unique,
84
+ });
85
+ if (error) {
86
+ console.warn(`${LOG} batch delivery-order lookup mislukt`, error.message);
87
+ return out;
88
+ }
89
+ for (const row of (data ?? [])) {
90
+ if (!row.sales_order_id || !row.delivery_order_id)
91
+ continue;
92
+ const list = out.get(row.sales_order_id) ?? [];
93
+ if (!list.includes(row.delivery_order_id))
94
+ list.push(row.delivery_order_id);
95
+ out.set(row.sales_order_id, list);
96
+ }
97
+ }
98
+ catch (e) {
99
+ console.warn(`${LOG} batch delivery-order lookup exception`, e instanceof Error ? e.message : String(e));
100
+ }
101
+ return out;
102
+ }
103
+ function signBody(secret, timestamp, body) {
104
+ return createHmac("sha256", secret).update(`${timestamp}.${body}`).digest("hex");
105
+ }
106
+ async function fetchPdfAsBase64(url) {
107
+ try {
108
+ const res = await fetch(url);
109
+ if (!res.ok) {
110
+ console.warn(`${LOG} PDF download mislukt`, { status: res.status, url });
111
+ return null;
112
+ }
113
+ const mime = res.headers.get("content-type") ?? "application/pdf";
114
+ const buf = new Uint8Array(await res.arrayBuffer());
115
+ let binary = "";
116
+ const chunk = 0x8000;
117
+ for (let i = 0; i < buf.length; i += chunk) {
118
+ binary += String.fromCharCode(...buf.subarray(i, i + chunk));
119
+ }
120
+ // btoa is available in the Workers runtime
121
+ const base64 = btoa(binary);
122
+ return { base64, mime };
123
+ }
124
+ catch (e) {
125
+ console.warn(`${LOG} PDF download exception`, e instanceof Error ? e.message : String(e));
126
+ return null;
127
+ }
128
+ }
129
+ /**
130
+ * Haalt de Floriday-afleverbrief PDF op voor een sales-order via de
131
+ * Authenticatie-module gateway. Retourneert null wanneer:
132
+ * - de secret niet geconfigureerd is
133
+ * - er (nog) geen delivery-order in de cache staat
134
+ * - de gateway een fout of geen URL teruggeeft
135
+ * - de PDF-download faalt
136
+ * Nooit throws — de pakbon-print moet altijd door kunnen gaan.
137
+ */
138
+ export async function fetchDeliveryNotePdf(salesOrderId) {
139
+ const secret = process.env.AUTH_GATEWAY_HMAC_SECRET;
140
+ if (!secret) {
141
+ console.error(`${LOG} AUTH_GATEWAY_HMAC_SECRET ontbreekt — kan afleverbrief niet ophalen`);
142
+ return null;
143
+ }
144
+ if (!salesOrderId)
145
+ return null;
146
+ const deliveryOrderIds = await resolveDeliveryOrderIds(salesOrderId);
147
+ if (deliveryOrderIds.length === 0) {
148
+ return null; // nog geen delivery-order — normaal gedrag
149
+ }
150
+ if (deliveryOrderIds.length > 1) {
151
+ console.warn(`${LOG} meerdere delivery-orders voor sales-order ${salesOrderId} — pickstation prints alleen de eerste`);
152
+ }
153
+ const environment = await getFloridayEnvironment();
154
+ const payload = {
155
+ environment,
156
+ kind: "delivery-note",
157
+ salesOrderId,
158
+ deliveryOrderId: deliveryOrderIds[0],
159
+ };
160
+ const bodyStr = JSON.stringify(payload);
161
+ const timestamp = new Date().toISOString();
162
+ const signature = signBody(secret, timestamp, bodyStr);
163
+ try {
164
+ const res = await fetch(`${gatewayBase()}/api/public/gateway/pdf`, {
165
+ method: "POST",
166
+ headers: {
167
+ "Content-Type": "application/json",
168
+ "X-Signature": signature,
169
+ "X-Timestamp": timestamp,
170
+ },
171
+ body: bodyStr,
172
+ });
173
+ const ct = res.headers.get("content-type") ?? "";
174
+ if (!ct.includes("application/json")) {
175
+ console.warn(`${LOG} gateway gaf geen JSON terug`, {
176
+ status: res.status,
177
+ contentType: ct,
178
+ });
179
+ return null;
180
+ }
181
+ const data = (await res.json());
182
+ if (!res.ok || !data?.ok || !data.url) {
183
+ console.warn(`${LOG} gateway respons niet OK`, {
184
+ status: res.status,
185
+ error: data?.error,
186
+ });
187
+ return null;
188
+ }
189
+ return await fetchPdfAsBase64(data.url);
190
+ }
191
+ catch (e) {
192
+ console.warn(`${LOG} gateway request exception`, e instanceof Error ? e.message : String(e));
193
+ return null;
194
+ }
195
+ }