@flowselections/floriday-afhandeling-module 1.0.15 → 1.0.17
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.
- package/dist-lib/components/afhandeling/LeveringenPage.d.ts.map +1 -1
- package/dist-lib/components/afhandeling/LeveringenPage.js +2 -2
- package/dist-lib/components/afhandeling/PickAgendaView.d.ts.map +1 -1
- package/dist-lib/components/afhandeling/PickAgendaView.js +2 -3
- package/dist-lib/components/afhandeling/WeekAgendaView.d.ts.map +1 -1
- package/dist-lib/components/afhandeling/WeekAgendaView.js +31 -17
- package/dist-lib/components/engine/CapaciteitsmaatregelenPage.d.ts +2 -0
- package/dist-lib/components/engine/CapaciteitsmaatregelenPage.d.ts.map +1 -0
- package/dist-lib/components/engine/CapaciteitsmaatregelenPage.js +40 -0
- package/dist-lib/components/engine/CapaciteitsmonitorPage.d.ts +2 -0
- package/dist-lib/components/engine/CapaciteitsmonitorPage.d.ts.map +1 -0
- package/dist-lib/components/engine/CapaciteitsmonitorPage.js +49 -0
- package/dist-lib/components/engine/FormulesPage.d.ts +2 -0
- package/dist-lib/components/engine/FormulesPage.d.ts.map +1 -0
- package/dist-lib/components/engine/FormulesPage.js +252 -0
- package/dist-lib/components/engine/PlaceholderPage.d.ts +6 -0
- package/dist-lib/components/engine/PlaceholderPage.d.ts.map +1 -0
- package/dist-lib/components/engine/PlaceholderPage.js +6 -0
- package/dist-lib/components/engine/StrategieenPage.d.ts +2 -0
- package/dist-lib/components/engine/StrategieenPage.d.ts.map +1 -0
- package/dist-lib/components/engine/StrategieenPage.js +80 -0
- package/dist-lib/components/pickstation/PickstationPage.d.ts.map +1 -1
- package/dist-lib/components/pickstation/PickstationPage.js +16 -4
- package/dist-lib/hooks/useOrderPlanning.d.ts.map +1 -1
- package/dist-lib/hooks/useOrderPlanning.js +37 -3
- package/dist-lib/index.d.ts.map +1 -1
- package/dist-lib/index.js +2 -1
- package/dist-lib/integrations/supabase/auth-middleware.d.ts +1496 -272
- package/dist-lib/integrations/supabase/auth-middleware.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/client.d.ts +1496 -272
- package/dist-lib/integrations/supabase/client.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/client.server.d.ts +1496 -272
- package/dist-lib/integrations/supabase/client.server.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/types.d.ts +1523 -266
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/lib/afhandelingSettings.functions.d.ts +2944 -496
- package/dist-lib/lib/afhandelingSettings.functions.d.ts.map +1 -1
- package/dist-lib/lib/ai-gateway.server.d.ts +2 -0
- package/dist-lib/lib/ai-gateway.server.d.ts.map +1 -0
- package/dist-lib/lib/ai-gateway.server.js +11 -0
- package/dist-lib/lib/authGateway.server.d.ts +16 -0
- package/dist-lib/lib/authGateway.server.d.ts.map +1 -0
- package/dist-lib/lib/authGateway.server.js +200 -0
- package/dist-lib/lib/carriers.functions.d.ts +7100 -980
- package/dist-lib/lib/carriers.functions.d.ts.map +1 -1
- package/dist-lib/lib/cartAssignments.functions.d.ts +7100 -980
- package/dist-lib/lib/cartAssignments.functions.d.ts.map +1 -1
- package/dist-lib/lib/cartControl.functions.d.ts +14630 -2390
- package/dist-lib/lib/cartControl.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday.functions.d.ts +1496 -272
- package/dist-lib/lib/floriday.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday.functions.js +41 -8
- package/dist-lib/lib/logisticsEngine/capacity.functions.d.ts +50282 -0
- package/dist-lib/lib/logisticsEngine/capacity.functions.d.ts.map +1 -0
- package/dist-lib/lib/logisticsEngine/capacity.functions.js +90 -0
- package/dist-lib/lib/logisticsEngine/config.d.ts +140 -0
- package/dist-lib/lib/logisticsEngine/config.d.ts.map +1 -0
- package/dist-lib/lib/logisticsEngine/config.js +488 -0
- package/dist-lib/lib/logisticsEngine/enginePickTime.d.ts +29 -0
- package/dist-lib/lib/logisticsEngine/enginePickTime.d.ts.map +1 -0
- package/dist-lib/lib/logisticsEngine/enginePickTime.js +136 -0
- package/dist-lib/lib/logisticsEngine/evaluate.functions.d.ts +12604 -0
- package/dist-lib/lib/logisticsEngine/evaluate.functions.d.ts.map +1 -0
- package/dist-lib/lib/logisticsEngine/evaluate.functions.js +104 -0
- package/dist-lib/lib/logisticsEngine/expression.d.ts +21 -0
- package/dist-lib/lib/logisticsEngine/expression.d.ts.map +1 -0
- package/dist-lib/lib/logisticsEngine/expression.js +263 -0
- package/dist-lib/lib/logisticsEngine/formulas.functions.d.ts +25164 -0
- package/dist-lib/lib/logisticsEngine/formulas.functions.d.ts.map +1 -0
- package/dist-lib/lib/logisticsEngine/formulas.functions.js +58 -0
- package/dist-lib/lib/logisticsEngine/safetyLayer.d.ts +83 -0
- package/dist-lib/lib/logisticsEngine/safetyLayer.d.ts.map +1 -0
- package/dist-lib/lib/logisticsEngine/safetyLayer.js +182 -0
- package/dist-lib/lib/logisticsEngine/strategies.functions.d.ts +100569 -0
- package/dist-lib/lib/logisticsEngine/strategies.functions.d.ts.map +1 -0
- package/dist-lib/lib/logisticsEngine/strategies.functions.js +176 -0
- package/dist-lib/lib/logisticsEngine/variables.d.ts +29 -0
- package/dist-lib/lib/logisticsEngine/variables.d.ts.map +1 -0
- package/dist-lib/lib/logisticsEngine/variables.js +144 -0
- package/dist-lib/lib/logisticsEngine/wizard.functions.d.ts +50288 -0
- package/dist-lib/lib/logisticsEngine/wizard.functions.d.ts.map +1 -0
- package/dist-lib/lib/logisticsEngine/wizard.functions.js +175 -0
- package/dist-lib/lib/pickstationI18n.d.ts +2 -0
- package/dist-lib/lib/pickstationI18n.d.ts.map +1 -1
- package/dist-lib/lib/pickstationI18n.js +12 -0
- package/dist-lib/lib/pickstationOrders.server.d.ts +5 -0
- package/dist-lib/lib/pickstationOrders.server.d.ts.map +1 -1
- package/dist-lib/lib/pickstationOrders.server.js +29 -0
- package/dist-lib/lib/pickstationTypes.d.ts +4 -0
- package/dist-lib/lib/pickstationTypes.d.ts.map +1 -1
- package/package.json +24 -4
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
2
|
+
export function createLovableAiGatewayProvider(lovableApiKey) {
|
|
3
|
+
return createOpenAICompatible({
|
|
4
|
+
name: "lovable",
|
|
5
|
+
baseURL: "https://ai.gateway.lovable.dev/v1",
|
|
6
|
+
headers: {
|
|
7
|
+
"Lovable-API-Key": lovableApiKey,
|
|
8
|
+
"X-Lovable-AIG-SDK": "vercel-ai-sdk",
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
}
|
|
@@ -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":"AAqFA,iFAAiF;AACjF,wBAAsB,0BAA0B,CAC9C,aAAa,EAAE,MAAM,EAAE,GACtB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CA6BhC;AA8CD;;;;;;;;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,200 @@
|
|
|
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
|
+
// Web Crypto (browser/Node 15+/Workers) — geen node:crypto, want dist-lib
|
|
11
|
+
// wordt ook in de client-bundle van consumer-shells opgenomen.
|
|
12
|
+
import { createClient } from "@supabase/supabase-js";
|
|
13
|
+
const GATEWAY_URL_FALLBACK = "https://floriday-authenticatie-module.lovable.app";
|
|
14
|
+
const LOG = "[auth-gateway]";
|
|
15
|
+
function gatewayBase() {
|
|
16
|
+
const raw = process.env.AUTH_GATEWAY_URL ??
|
|
17
|
+
process.env.VITE_AUTH_GATEWAY_URL ??
|
|
18
|
+
GATEWAY_URL_FALLBACK;
|
|
19
|
+
return raw.replace(/\/$/, "");
|
|
20
|
+
}
|
|
21
|
+
function getSupabase() {
|
|
22
|
+
const url = process.env.SUPABASE_URL ?? process.env.VITE_SUPABASE_URL;
|
|
23
|
+
const key = process.env.SUPABASE_PUBLISHABLE_KEY ?? process.env.VITE_SUPABASE_PUBLISHABLE_KEY;
|
|
24
|
+
if (!url || !key)
|
|
25
|
+
throw new Error("Supabase publishable env vars ontbreken");
|
|
26
|
+
return createClient(url, key, {
|
|
27
|
+
auth: { storage: undefined, persistSession: false, autoRefreshToken: false },
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
let cachedEnvironment = null;
|
|
31
|
+
async function getFloridayEnvironment() {
|
|
32
|
+
if (cachedEnvironment)
|
|
33
|
+
return cachedEnvironment;
|
|
34
|
+
try {
|
|
35
|
+
const supabase = getSupabase();
|
|
36
|
+
const { data, error } = await supabase
|
|
37
|
+
.from("floriday_settings")
|
|
38
|
+
.select("active_environment")
|
|
39
|
+
.eq("id", 1)
|
|
40
|
+
.maybeSingle();
|
|
41
|
+
if (error) {
|
|
42
|
+
console.warn(`${LOG} kon actieve Floriday-omgeving niet ophalen`, error.message);
|
|
43
|
+
}
|
|
44
|
+
cachedEnvironment = data?.active_environment ?? "live";
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
console.warn(`${LOG} kon actieve Floriday-omgeving niet ophalen`, e instanceof Error ? e.message : String(e));
|
|
48
|
+
cachedEnvironment = "live";
|
|
49
|
+
}
|
|
50
|
+
return cachedEnvironment;
|
|
51
|
+
}
|
|
52
|
+
/** Resolvt delivery-order-ids voor één sales-order via de SECURITY DEFINER RPC. */
|
|
53
|
+
async function resolveDeliveryOrderIds(salesOrderId) {
|
|
54
|
+
try {
|
|
55
|
+
const supabase = getSupabase();
|
|
56
|
+
const { data, error } = await supabase.rpc("pickstation_resolve_delivery_orders", {
|
|
57
|
+
p_sales_order_ids: [salesOrderId],
|
|
58
|
+
});
|
|
59
|
+
if (error) {
|
|
60
|
+
console.warn(`${LOG} delivery-order lookup mislukt`, error.message);
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
const ids = new Set();
|
|
64
|
+
for (const row of (data ?? [])) {
|
|
65
|
+
if (row.delivery_order_id)
|
|
66
|
+
ids.add(row.delivery_order_id);
|
|
67
|
+
}
|
|
68
|
+
return [...ids];
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
console.warn(`${LOG} delivery-order lookup exception`, e instanceof Error ? e.message : String(e));
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** Batch-variant — geeft per sales-order-id een set delivery-order-ids terug. */
|
|
76
|
+
export async function resolveDeliveryOrdersBatch(salesOrderIds) {
|
|
77
|
+
const out = new Map();
|
|
78
|
+
const unique = [...new Set(salesOrderIds.filter(Boolean))];
|
|
79
|
+
if (unique.length === 0)
|
|
80
|
+
return out;
|
|
81
|
+
try {
|
|
82
|
+
const supabase = getSupabase();
|
|
83
|
+
const { data, error } = await supabase.rpc("pickstation_resolve_delivery_orders", {
|
|
84
|
+
p_sales_order_ids: unique,
|
|
85
|
+
});
|
|
86
|
+
if (error) {
|
|
87
|
+
console.warn(`${LOG} batch delivery-order lookup mislukt`, error.message);
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
for (const row of (data ?? [])) {
|
|
91
|
+
if (!row.sales_order_id || !row.delivery_order_id)
|
|
92
|
+
continue;
|
|
93
|
+
const list = out.get(row.sales_order_id) ?? [];
|
|
94
|
+
if (!list.includes(row.delivery_order_id))
|
|
95
|
+
list.push(row.delivery_order_id);
|
|
96
|
+
out.set(row.sales_order_id, list);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
console.warn(`${LOG} batch delivery-order lookup exception`, e instanceof Error ? e.message : String(e));
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
async function signBody(secret, timestamp, body) {
|
|
105
|
+
const key = await globalThis.crypto.subtle.importKey("raw", new TextEncoder().encode(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
106
|
+
const sig = await globalThis.crypto.subtle.sign("HMAC", key, new TextEncoder().encode(`${timestamp}.${body}`));
|
|
107
|
+
return Array.from(new Uint8Array(sig))
|
|
108
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
109
|
+
.join("");
|
|
110
|
+
}
|
|
111
|
+
async function fetchPdfAsBase64(url) {
|
|
112
|
+
try {
|
|
113
|
+
const res = await fetch(url);
|
|
114
|
+
if (!res.ok) {
|
|
115
|
+
console.warn(`${LOG} PDF download mislukt`, { status: res.status, url });
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
const mime = res.headers.get("content-type") ?? "application/pdf";
|
|
119
|
+
const buf = new Uint8Array(await res.arrayBuffer());
|
|
120
|
+
let binary = "";
|
|
121
|
+
const chunk = 0x8000;
|
|
122
|
+
for (let i = 0; i < buf.length; i += chunk) {
|
|
123
|
+
binary += String.fromCharCode(...buf.subarray(i, i + chunk));
|
|
124
|
+
}
|
|
125
|
+
// btoa is available in the Workers runtime
|
|
126
|
+
const base64 = btoa(binary);
|
|
127
|
+
return { base64, mime };
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
130
|
+
console.warn(`${LOG} PDF download exception`, e instanceof Error ? e.message : String(e));
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Haalt de Floriday-afleverbrief PDF op voor een sales-order via de
|
|
136
|
+
* Authenticatie-module gateway. Retourneert null wanneer:
|
|
137
|
+
* - de secret niet geconfigureerd is
|
|
138
|
+
* - er (nog) geen delivery-order in de cache staat
|
|
139
|
+
* - de gateway een fout of geen URL teruggeeft
|
|
140
|
+
* - de PDF-download faalt
|
|
141
|
+
* Nooit throws — de pakbon-print moet altijd door kunnen gaan.
|
|
142
|
+
*/
|
|
143
|
+
export async function fetchDeliveryNotePdf(salesOrderId) {
|
|
144
|
+
const secret = process.env.AUTH_GATEWAY_HMAC_SECRET;
|
|
145
|
+
if (!secret) {
|
|
146
|
+
console.error(`${LOG} AUTH_GATEWAY_HMAC_SECRET ontbreekt — kan afleverbrief niet ophalen`);
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
if (!salesOrderId)
|
|
150
|
+
return null;
|
|
151
|
+
const deliveryOrderIds = await resolveDeliveryOrderIds(salesOrderId);
|
|
152
|
+
if (deliveryOrderIds.length === 0) {
|
|
153
|
+
return null; // nog geen delivery-order — normaal gedrag
|
|
154
|
+
}
|
|
155
|
+
if (deliveryOrderIds.length > 1) {
|
|
156
|
+
console.warn(`${LOG} meerdere delivery-orders voor sales-order ${salesOrderId} — pickstation prints alleen de eerste`);
|
|
157
|
+
}
|
|
158
|
+
const environment = await getFloridayEnvironment();
|
|
159
|
+
const payload = {
|
|
160
|
+
environment,
|
|
161
|
+
kind: "delivery-note",
|
|
162
|
+
salesOrderId,
|
|
163
|
+
deliveryOrderId: deliveryOrderIds[0],
|
|
164
|
+
};
|
|
165
|
+
const bodyStr = JSON.stringify(payload);
|
|
166
|
+
const timestamp = new Date().toISOString();
|
|
167
|
+
const signature = await signBody(secret, timestamp, bodyStr);
|
|
168
|
+
try {
|
|
169
|
+
const res = await fetch(`${gatewayBase()}/api/public/gateway/pdf`, {
|
|
170
|
+
method: "POST",
|
|
171
|
+
headers: {
|
|
172
|
+
"Content-Type": "application/json",
|
|
173
|
+
"X-Signature": signature,
|
|
174
|
+
"X-Timestamp": timestamp,
|
|
175
|
+
},
|
|
176
|
+
body: bodyStr,
|
|
177
|
+
});
|
|
178
|
+
const ct = res.headers.get("content-type") ?? "";
|
|
179
|
+
if (!ct.includes("application/json")) {
|
|
180
|
+
console.warn(`${LOG} gateway gaf geen JSON terug`, {
|
|
181
|
+
status: res.status,
|
|
182
|
+
contentType: ct,
|
|
183
|
+
});
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
const data = (await res.json());
|
|
187
|
+
if (!res.ok || !data?.ok || !data.url) {
|
|
188
|
+
console.warn(`${LOG} gateway respons niet OK`, {
|
|
189
|
+
status: res.status,
|
|
190
|
+
error: data?.error,
|
|
191
|
+
});
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
return await fetchPdfAsBase64(data.url);
|
|
195
|
+
}
|
|
196
|
+
catch (e) {
|
|
197
|
+
console.warn(`${LOG} gateway request exception`, e instanceof Error ? e.message : String(e));
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
}
|