@flowselections/floriday-verkoop-module 1.0.125 → 1.0.127
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/lib/cart-replan.functions.d.ts +3 -58
- package/dist-lib/lib/cart-replan.functions.d.ts.map +1 -1
- package/dist-lib/lib/cart-replan.functions.js +3 -364
- package/dist-lib/lib/cart-replan.server.d.ts +67 -0
- package/dist-lib/lib/cart-replan.server.d.ts.map +1 -0
- package/dist-lib/lib/cart-replan.server.js +367 -0
- package/dist-lib/lib/create-order.functions.d.ts.map +1 -1
- package/dist-lib/lib/create-order.functions.js +8 -2
- package/dist-lib/lib/cron/salesorders-sync.server.d.ts +20 -0
- package/dist-lib/lib/cron/salesorders-sync.server.d.ts.map +1 -0
- package/dist-lib/lib/cron/salesorders-sync.server.js +104 -0
- package/dist-lib/lib/cron/sync-salesorders.js +1 -1
- package/dist-lib/lib/engine-wake.server.d.ts +3 -1
- package/dist-lib/lib/engine-wake.server.d.ts.map +1 -1
- package/dist-lib/lib/engine-wake.server.js +16 -14
- package/dist-lib/lib/floriday-mirror.functions.d.ts +1 -19
- package/dist-lib/lib/floriday-mirror.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-mirror.functions.js +6 -1475
- package/dist-lib/lib/floriday-mirror.server.d.ts +20 -0
- package/dist-lib/lib/floriday-mirror.server.d.ts.map +1 -0
- package/dist-lib/lib/floriday-mirror.server.js +1475 -0
- package/dist-lib/lib/module-version.d.ts +1 -1
- package/dist-lib/lib/module-version.js +1 -1
- package/dist-lib/lib/order-buffers.functions.d.ts +0 -2
- package/dist-lib/lib/order-buffers.functions.d.ts.map +1 -1
- package/dist-lib/lib/order-buffers.functions.js +0 -10
- package/dist-lib/lib/order-buffers.server.d.ts +3 -0
- package/dist-lib/lib/order-buffers.server.d.ts.map +1 -0
- package/dist-lib/lib/order-buffers.server.js +11 -0
- package/dist-lib/lib/order-cancel.server.d.ts +2 -0
- package/dist-lib/lib/order-cancel.server.d.ts.map +1 -1
- package/dist-lib/lib/order-cancel.server.js +1 -1
- package/dist-lib/lib/order-item-packing.functions.js +1 -1
- package/dist-lib/lib/salesorders-list.functions.d.ts.map +1 -1
- package/dist-lib/lib/salesorders-list.functions.js +7 -5
- package/dist-lib/lib/salesorders.functions.d.ts +0 -14
- package/dist-lib/lib/salesorders.functions.d.ts.map +1 -1
- package/dist-lib/lib/salesorders.functions.js +4 -102
- package/package.json +3 -2
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
// Server-only: karindeling-helpers (geneutraliseerd; planning is van de
|
|
2
|
+
// Logistiek Engine). Alleen dynamisch geïmporteerd vanuit createServerFn-
|
|
3
|
+
// handlers in cart-replan.functions.ts.
|
|
4
|
+
import { productNameForStorage } from "./product-name.js";
|
|
5
|
+
import { CART_PLANNER_VERSION, planCarts, } from "./cart-planner.js";
|
|
6
|
+
import { resolveBufferForOrderInternal } from "./order-buffers.server.js";
|
|
7
|
+
export async function replanBufferInternal(bufferId) {
|
|
8
|
+
return replanScopeInternal({ bufferId });
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Plant karren voor een scope: een Engine-buffer (bufferId) óf één losse order
|
|
12
|
+
* (orderId) wanneer de Engine zegt dat er niet gebufferd wordt.
|
|
13
|
+
*/
|
|
14
|
+
export async function replanScopeInternal(scope) {
|
|
15
|
+
const { supabaseAdmin } = await import("../integrations/supabase/client.server.js");
|
|
16
|
+
const bufferId = scope.bufferId ?? null;
|
|
17
|
+
const soloOrderId = bufferId ? null : (scope.orderId ?? null);
|
|
18
|
+
if (!bufferId && !soloOrderId)
|
|
19
|
+
throw new Error("replanScopeInternal: geen scope");
|
|
20
|
+
let ordersQuery = supabaseAdmin
|
|
21
|
+
.from("orders")
|
|
22
|
+
.select("id, order_number, custom_fields, plan_locked_at")
|
|
23
|
+
.is("deleted_at", null);
|
|
24
|
+
ordersQuery = bufferId
|
|
25
|
+
? ordersQuery.eq("buffer_id", bufferId)
|
|
26
|
+
: ordersQuery.eq("id", soloOrderId);
|
|
27
|
+
const { data: orders } = await ordersQuery;
|
|
28
|
+
const orderRows = (orders ?? []);
|
|
29
|
+
const orderIds = orderRows.map((o) => o.id);
|
|
30
|
+
const orderNumberById = new Map();
|
|
31
|
+
for (const o of orderRows) {
|
|
32
|
+
if (o.order_number)
|
|
33
|
+
orderNumberById.set(o.id, String(o.order_number));
|
|
34
|
+
}
|
|
35
|
+
if (orderRows.some((o) => o.plan_locked_at)) {
|
|
36
|
+
return {
|
|
37
|
+
ok: true,
|
|
38
|
+
bufferId,
|
|
39
|
+
orderIds,
|
|
40
|
+
cartsCreated: 0,
|
|
41
|
+
replacedManualCount: 0,
|
|
42
|
+
usedFloridayPacking: false,
|
|
43
|
+
warnings: ["plan_locked"],
|
|
44
|
+
blockedItems: [],
|
|
45
|
+
skipped: "locked",
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
// Items van alle orders in de buffer.
|
|
49
|
+
const { data: items, error: itErr } = await supabaseAdmin
|
|
50
|
+
.from("order_items")
|
|
51
|
+
.select("id, order_id, product_id, product_name, quantity, plants_per_crate, crates_per_layer, layers_per_cart, products(plants_per_crate, crates_per_layer, layers_per_cart)")
|
|
52
|
+
.in("order_id", orderIds.length > 0 ? orderIds : ["00000000-0000-0000-0000-000000000000"])
|
|
53
|
+
.is("quarantined_at", null);
|
|
54
|
+
if (itErr)
|
|
55
|
+
throw new Error(itErr.message);
|
|
56
|
+
// Onbekend blijft onbekend: geen ?? 1. De planner blokkeert regels
|
|
57
|
+
// zonder (volledige) belading in plaats van 1×1×1 te plannen.
|
|
58
|
+
const pos = (v) => {
|
|
59
|
+
if (v === null || v === undefined)
|
|
60
|
+
return null;
|
|
61
|
+
const n = Number(v);
|
|
62
|
+
return Number.isFinite(n) && n > 0 ? Math.round(n) : null;
|
|
63
|
+
};
|
|
64
|
+
/** Een bron telt alleen als álle drie de velden gevuld zijn (> 0). */
|
|
65
|
+
const completeSource = (plants_per_crate, crates_per_layer, layers_per_cart) => {
|
|
66
|
+
const a = pos(plants_per_crate);
|
|
67
|
+
const b = pos(crates_per_layer);
|
|
68
|
+
const c = pos(layers_per_cart);
|
|
69
|
+
return a && b && c ? { plants_per_crate: a, crates_per_layer: b, layers_per_cart: c } : null;
|
|
70
|
+
};
|
|
71
|
+
// Beladingbron per order: custom_fields.floriday_packing bevat de belading
|
|
72
|
+
// zoals die in Floriday op de order staat. Dat zijn de packing-VELDEN
|
|
73
|
+
// (pieces_per_package / packages_per_layer / layers_per_load_carrier) —
|
|
74
|
+
// géén voorgekauwde karrenlijst; de karindeling rekenen we zelf.
|
|
75
|
+
const floridayByOrder = new Map();
|
|
76
|
+
const loadCarrierByOrder = new Map();
|
|
77
|
+
for (const o of orderRows) {
|
|
78
|
+
const fp = (o.custom_fields ?? {})?.floriday_packing ?? null;
|
|
79
|
+
if (!fp)
|
|
80
|
+
continue;
|
|
81
|
+
const bel = completeSource(fp.pieces_per_package, fp.packages_per_layer, fp.layers_per_load_carrier);
|
|
82
|
+
if (bel)
|
|
83
|
+
floridayByOrder.set(o.id, bel);
|
|
84
|
+
const lc = typeof fp.load_carrier === "string" ? fp.load_carrier.trim() : "";
|
|
85
|
+
if (lc)
|
|
86
|
+
loadCarrierByOrder.set(o.id, lc.toUpperCase());
|
|
87
|
+
}
|
|
88
|
+
// ── Ladingdragerprofiel ────────────────────────────────────────────────
|
|
89
|
+
// Vertrouw NIET op de kolomdefault 'trolley' van order_carts: die verbergt
|
|
90
|
+
// dat er geen profielkeuze is gemaakt. Zonder profiel plannen we niet.
|
|
91
|
+
const { data: carrierProfiles } = await supabaseAdmin
|
|
92
|
+
.from("load_carrier_types")
|
|
93
|
+
.select("id, code, name, layers_per_carrier, is_active, is_default");
|
|
94
|
+
const activeProfiles = (carrierProfiles ?? []).filter((p) => p.is_active);
|
|
95
|
+
const defaultProfile = activeProfiles.find((p) => p.is_default) ??
|
|
96
|
+
activeProfiles.find((p) => String(p.code).toLowerCase() === "trolley") ??
|
|
97
|
+
null;
|
|
98
|
+
/** Floriday-ladingdragercode → code in load_carrier_types. */
|
|
99
|
+
const CARRIER_CODE_MAP = {
|
|
100
|
+
DANISH_TROLLEY: ["danish_container", "danish_trolley"],
|
|
101
|
+
DANISH_TROLLEY_NON_CC_RFID: ["danish_container"],
|
|
102
|
+
DANISH_TROLLEY_WATER_TRAY: ["danish_container"],
|
|
103
|
+
ONE_THIRD_DANISH_TROLLEY: ["danish_container"],
|
|
104
|
+
AUCTION_TROLLEY: ["auction_trolley", "trolley"],
|
|
105
|
+
EURO_TROLLEY: ["euro_rolcontainer", "trolley"],
|
|
106
|
+
ROLL_CONTAINER: ["euro_rolcontainer"],
|
|
107
|
+
EURO_PALLET: ["euro_pallet", "pallet"],
|
|
108
|
+
HT_EURO_PALLET: ["euro_pallet", "pallet"],
|
|
109
|
+
PALLET: ["pallet"],
|
|
110
|
+
BLOCK_PALLET: ["pallet"],
|
|
111
|
+
NONE: ["loose"],
|
|
112
|
+
};
|
|
113
|
+
const profileFor = (loadCarrier) => {
|
|
114
|
+
if (!loadCarrier)
|
|
115
|
+
return defaultProfile;
|
|
116
|
+
const direct = activeProfiles.find((p) => String(p.code).toUpperCase() === loadCarrier.toUpperCase());
|
|
117
|
+
if (direct)
|
|
118
|
+
return direct;
|
|
119
|
+
for (const code of CARRIER_CODE_MAP[loadCarrier.toUpperCase()] ?? []) {
|
|
120
|
+
const hit = activeProfiles.find((p) => String(p.code).toLowerCase() === code);
|
|
121
|
+
if (hit)
|
|
122
|
+
return hit;
|
|
123
|
+
}
|
|
124
|
+
return defaultProfile;
|
|
125
|
+
};
|
|
126
|
+
let usedFloridayPacking = false;
|
|
127
|
+
const inputs = (items ?? []).map((it) => {
|
|
128
|
+
const prod = it.products ?? {};
|
|
129
|
+
// Volgorde: orderregel → floriday_packing → product. Niet coalescen per
|
|
130
|
+
// veld: een half-Floriday/half-orderregel-belading is geen belading.
|
|
131
|
+
const fromFloriday = floridayByOrder.get(it.order_id) ?? null;
|
|
132
|
+
const orderLineBel = completeSource(it.plants_per_crate, it.crates_per_layer, it.layers_per_cart);
|
|
133
|
+
const bel = orderLineBel ??
|
|
134
|
+
fromFloriday ??
|
|
135
|
+
completeSource(prod.plants_per_crate, prod.crates_per_layer, prod.layers_per_cart);
|
|
136
|
+
if (orderLineBel == null && fromFloriday != null)
|
|
137
|
+
usedFloridayPacking = true;
|
|
138
|
+
const loadCarrier = loadCarrierByOrder.get(it.order_id) ?? null;
|
|
139
|
+
// layers_per_cart = LEAST(profiel, bron) — identiek aan logistics_plan_buffer_sql.
|
|
140
|
+
const profileLayers = pos(profileFor(loadCarrier)?.layers_per_carrier);
|
|
141
|
+
const layers = bel?.layers_per_cart != null && profileLayers != null
|
|
142
|
+
? Math.min(bel.layers_per_cart, profileLayers)
|
|
143
|
+
: (bel?.layers_per_cart ?? null);
|
|
144
|
+
return {
|
|
145
|
+
order_item_id: it.id,
|
|
146
|
+
product_id: it.product_id,
|
|
147
|
+
product_name: productNameForStorage(it.product_name),
|
|
148
|
+
plants: Math.max(0, Number(it.quantity ?? 0)),
|
|
149
|
+
plants_per_crate: bel?.plants_per_crate ?? null,
|
|
150
|
+
crates_per_layer: bel?.crates_per_layer ?? null,
|
|
151
|
+
layers_per_cart: layers,
|
|
152
|
+
load_carrier: loadCarrier,
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
// Item → order-map voor het toewijzen van cart.order_id bij homogene karren.
|
|
156
|
+
const itemToOrder = new Map();
|
|
157
|
+
for (const it of items ?? []) {
|
|
158
|
+
itemToOrder.set(it.id, it.order_id);
|
|
159
|
+
}
|
|
160
|
+
// Nummering én delete-scope liggen altijd op bufferniveau als de order een
|
|
161
|
+
// buffer heeft; order-scope is uitsluitend terugval. Wissen én wegschrijven
|
|
162
|
+
// gebeuren verderop in ÉÉN transactie via public.replace_order_carts, zodat
|
|
163
|
+
// een mislukte replan de bestaande indeling laat staan.
|
|
164
|
+
if (!bufferId) {
|
|
165
|
+
console.warn("[cart-replan] geen buffer voor order %s — nummering en delete vallen terug op order-scope", soloOrderId);
|
|
166
|
+
}
|
|
167
|
+
let replacedManualCount = 0;
|
|
168
|
+
// De karindeling wordt hier altijd zelf gerekend. custom_fields.floriday_packing
|
|
169
|
+
// levert alleen de belading-VELDEN (pieces_per_package / packages_per_layer /
|
|
170
|
+
// layers_per_load_carrier) — de mirror schrijft nooit een voorgekauwde
|
|
171
|
+
// carts-array, dus die tak bestaat bewust niet meer.
|
|
172
|
+
const plannedCarts = [];
|
|
173
|
+
const warnings = [];
|
|
174
|
+
let blockedItems = [];
|
|
175
|
+
{
|
|
176
|
+
const [{ data: settings }, { data: overrides }] = await Promise.all([
|
|
177
|
+
supabaseAdmin.from("cart_planning_settings").select("*").eq("id", 1).maybeSingle(),
|
|
178
|
+
supabaseAdmin.from("cart_planning_product_overrides").select("product_id, never_mix"),
|
|
179
|
+
]);
|
|
180
|
+
const neverMix = new Set((overrides ?? [])
|
|
181
|
+
.filter((o) => o.never_mix && o.product_id)
|
|
182
|
+
.map((o) => o.product_id));
|
|
183
|
+
// Ladingdrager is een HARDE partitie: één planner-run per load_carrier.
|
|
184
|
+
// Items zonder load_carrier (lokale orders) vormen hun eigen partitie op
|
|
185
|
+
// het defaultprofiel.
|
|
186
|
+
const partitions = new Map();
|
|
187
|
+
for (const input of inputs) {
|
|
188
|
+
const key = input.load_carrier ?? "";
|
|
189
|
+
const list = partitions.get(key);
|
|
190
|
+
if (list)
|
|
191
|
+
list.push(input);
|
|
192
|
+
else
|
|
193
|
+
partitions.set(key, [input]);
|
|
194
|
+
}
|
|
195
|
+
const allBlocked = [];
|
|
196
|
+
let nextCartNumber = 1;
|
|
197
|
+
for (const [key, partitionInputs] of partitions) {
|
|
198
|
+
const profile = profileFor(key || null);
|
|
199
|
+
if (!profile) {
|
|
200
|
+
// Geen actief profiel én geen 'trolley': niet plannen, wel blokkeren.
|
|
201
|
+
for (const i of partitionInputs) {
|
|
202
|
+
allBlocked.push({
|
|
203
|
+
order_item_id: i.order_item_id,
|
|
204
|
+
product_id: i.product_id,
|
|
205
|
+
product_name: productNameForStorage(i.product_name),
|
|
206
|
+
reason: "geen_belading",
|
|
207
|
+
missing: ["load_carrier_profile"],
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
warnings.push(`Geen actief ladingdragerprofiel gevonden${key ? ` voor ${key}` : ""} — karindeling overgeslagen.`);
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
const result = planCarts(partitionInputs, {
|
|
214
|
+
maxPartySharePerLayerPct: settings?.max_party_share_per_layer_pct ?? 50,
|
|
215
|
+
maxBeladingenPerLayer: settings?.max_beladingen_per_layer ?? 2,
|
|
216
|
+
neverMixProductIds: neverMix,
|
|
217
|
+
startCartNumber: nextCartNumber,
|
|
218
|
+
});
|
|
219
|
+
for (const cart of result.carts) {
|
|
220
|
+
nextCartNumber = Math.max(nextCartNumber, cart.cart_number + 1);
|
|
221
|
+
plannedCarts.push({ cart, profile });
|
|
222
|
+
}
|
|
223
|
+
warnings.push(...result.warnings);
|
|
224
|
+
allBlocked.push(...result.blocked);
|
|
225
|
+
}
|
|
226
|
+
const result = { blocked: allBlocked };
|
|
227
|
+
// Regels zonder (volledige) belading: NOOIT karren maken. Meld de
|
|
228
|
+
// blokkade aan de logistiek-engine zodat die zichtbaar wordt in
|
|
229
|
+
// logistics_plan_queue / logistics_events / logistics_decisions.
|
|
230
|
+
if (result.blocked.length > 0) {
|
|
231
|
+
const blockedOrderIds = [
|
|
232
|
+
...new Set(result.blocked
|
|
233
|
+
.map((b) => itemToOrder.get(b.order_item_id))
|
|
234
|
+
.filter((v) => !!v)),
|
|
235
|
+
];
|
|
236
|
+
blockedItems = result.blocked.map((b) => ({
|
|
237
|
+
order_item_id: b.order_item_id,
|
|
238
|
+
order_id: itemToOrder.get(b.order_item_id) ?? null,
|
|
239
|
+
product_name: productNameForStorage(b.product_name),
|
|
240
|
+
reason: b.reason,
|
|
241
|
+
missing: b.missing,
|
|
242
|
+
}));
|
|
243
|
+
if (blockedOrderIds.length > 0) {
|
|
244
|
+
const FIELD_LABELS = {
|
|
245
|
+
plants_per_crate: "planten per fust",
|
|
246
|
+
crates_per_layer: "fusten per laag",
|
|
247
|
+
layers_per_cart: "lagen per kar",
|
|
248
|
+
};
|
|
249
|
+
const nummers = blockedOrderIds
|
|
250
|
+
.map((id) => orderNumberById.get(id) ?? id.slice(0, 8))
|
|
251
|
+
.join(", ");
|
|
252
|
+
const velden = [
|
|
253
|
+
...new Set(blockedItems.flatMap((b) => b.missing)),
|
|
254
|
+
]
|
|
255
|
+
.map((f) => FIELD_LABELS[f] ?? f)
|
|
256
|
+
.join(", ");
|
|
257
|
+
const reason = `Karindeling geblokkeerd voor order(s) ${nummers}: ` +
|
|
258
|
+
`${blockedItems.length} orderregel(s) zonder volledige belading` +
|
|
259
|
+
(velden ? ` (ontbreekt: ${velden})` : "") + ".";
|
|
260
|
+
// Geen eigen blokkade of mail meer (koppelprompt 22): de Engine
|
|
261
|
+
// beslist zelf en meldt een definitieve blokkade.
|
|
262
|
+
warnings.push(reason);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// Payload voor public.replace_order_carts. LET OP: de sleutels hieronder
|
|
267
|
+
// moeten gelijk lopen met de sleutellijsten in die SQL-functie; ontbreekt er
|
|
268
|
+
// één, dan gooit de database een fout in plaats van stil NULL te schrijven.
|
|
269
|
+
const cartPayload = plannedCarts.map(({ cart, profile }) => {
|
|
270
|
+
// Bepaal cart.order_id: null bij mix van orders, anders die ene order.
|
|
271
|
+
const orderIdsOnCart = new Set();
|
|
272
|
+
for (const i of cart.items) {
|
|
273
|
+
const oid = itemToOrder.get(i.order_item_id);
|
|
274
|
+
if (oid)
|
|
275
|
+
orderIdsOnCart.add(oid);
|
|
276
|
+
}
|
|
277
|
+
const singleOrderId = orderIdsOnCart.size === 1 ? [...orderIdsOnCart][0] : null;
|
|
278
|
+
return {
|
|
279
|
+
order_id: singleOrderId,
|
|
280
|
+
buffer_id: bufferId,
|
|
281
|
+
cart_number: cart.cart_number,
|
|
282
|
+
is_auto: true,
|
|
283
|
+
is_complete: cart.is_complete,
|
|
284
|
+
source: usedFloridayPacking ? "floriday" : "auto",
|
|
285
|
+
occupancy_pct: cart.occupancy_pct,
|
|
286
|
+
total_layers_used: cart.total_layers_used,
|
|
287
|
+
// Profiel expliciet meegeven; nooit leunen op de kolomdefault.
|
|
288
|
+
carrier_type: profile.code,
|
|
289
|
+
carrier_type_id: profile.id,
|
|
290
|
+
max_layers: profile.layers_per_carrier ?? null,
|
|
291
|
+
algorithm_version: CART_PLANNER_VERSION,
|
|
292
|
+
items: cart.items.map((i) => ({
|
|
293
|
+
order_item_id: i.order_item_id,
|
|
294
|
+
product_id: i.product_id,
|
|
295
|
+
product_name: productNameForStorage(i.product_name),
|
|
296
|
+
crates: Math.max(1, Math.round(i.crates)),
|
|
297
|
+
plants_per_crate: i.plants_per_crate,
|
|
298
|
+
crates_per_layer: i.crates_per_layer,
|
|
299
|
+
layers_per_cart: i.layers_per_cart,
|
|
300
|
+
layer_fraction: i.layer_fraction,
|
|
301
|
+
layer_share_pct: i.layer_share_pct,
|
|
302
|
+
})),
|
|
303
|
+
};
|
|
304
|
+
});
|
|
305
|
+
// Delete + inserts in één transactie: faalt er iets, dan blijft de oude
|
|
306
|
+
// karindeling staan in plaats van een lege buffer achter te laten.
|
|
307
|
+
const { data: replaceRes, error: replaceErr } = await supabaseAdmin.rpc("replace_order_carts", {
|
|
308
|
+
p_buffer_id: bufferId,
|
|
309
|
+
p_order_id: bufferId ? null : soloOrderId,
|
|
310
|
+
p_carts: cartPayload,
|
|
311
|
+
});
|
|
312
|
+
if (replaceErr)
|
|
313
|
+
throw new Error(replaceErr.message);
|
|
314
|
+
const cartsCreated = Number(replaceRes?.carts_written ?? 0);
|
|
315
|
+
const itemsWritten = Number(replaceRes?.items_written ?? 0);
|
|
316
|
+
replacedManualCount = Number(replaceRes?.replaced_manual_count ?? 0);
|
|
317
|
+
// Controleer dat de database daadwerkelijk heeft weggeschreven wat de
|
|
318
|
+
// planner opleverde. Nul karren mag, maar alleen als de planner er ook nul
|
|
319
|
+
// opleverde — niet als gevolg van een fout.
|
|
320
|
+
const expectedItems = cartPayload.reduce((n, c) => n + c.items.length, 0);
|
|
321
|
+
if (cartsCreated !== cartPayload.length || itemsWritten !== expectedItems) {
|
|
322
|
+
throw new Error(`Karindeling niet volledig weggeschreven: ${cartsCreated}/${cartPayload.length} karren, ` +
|
|
323
|
+
`${itemsWritten}/${expectedItems} artikelen.`);
|
|
324
|
+
}
|
|
325
|
+
// Weer ingedeeld: eerdere blokkademeldingen wissen, zodat een latere
|
|
326
|
+
// blokkade opnieuw gemaild mag worden.
|
|
327
|
+
if (cartsCreated > 0) {
|
|
328
|
+
const plannedOrderIds = Array.from(new Set(Array.from(itemToOrder.values()).filter((v) => !!v)));
|
|
329
|
+
const { clearOrderBlockNotifications } = await import("./order-block-mail.server.js");
|
|
330
|
+
await clearOrderBlockNotifications(plannedOrderIds);
|
|
331
|
+
}
|
|
332
|
+
return {
|
|
333
|
+
ok: true,
|
|
334
|
+
bufferId,
|
|
335
|
+
orderIds,
|
|
336
|
+
cartsCreated,
|
|
337
|
+
replacedManualCount,
|
|
338
|
+
usedFloridayPacking,
|
|
339
|
+
warnings,
|
|
340
|
+
blockedItems,
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
export async function replanOrderInternal(orderId) {
|
|
344
|
+
// Vraag het bufferbesluit aan de Engine en plan die scope opnieuw.
|
|
345
|
+
const bufferId = await resolveBufferForOrderInternal(orderId);
|
|
346
|
+
const res = await replanScopeInternal({ bufferId, orderId });
|
|
347
|
+
return {
|
|
348
|
+
ok: res.ok,
|
|
349
|
+
orderId,
|
|
350
|
+
cartsCreated: res.cartsCreated,
|
|
351
|
+
replacedManualCount: res.replacedManualCount,
|
|
352
|
+
usedFloridayPacking: res.usedFloridayPacking,
|
|
353
|
+
warnings: res.warnings,
|
|
354
|
+
blockedItems: res.blockedItems,
|
|
355
|
+
skipped: res.skipped,
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
export async function replanOrderCartsFromCron(orderId) {
|
|
359
|
+
return replanOrderInternal(orderId);
|
|
360
|
+
}
|
|
361
|
+
// ─── Queue drain (aangeroepen door pg_cron elke minuut) ─────────────────────
|
|
362
|
+
// Karplanning is eigendom van de Logistiek Engine (runCartPlanRequests draait
|
|
363
|
+
// daar elke minuut). Deze drain is bewust geneutraliseerd zodat de Verkoop-
|
|
364
|
+
// module nooit zelf een indeelronde start.
|
|
365
|
+
export async function drainCartReplanQueue(_limit = 50) {
|
|
366
|
+
return { ok: true, processed: 0, failed: 0, results: [] };
|
|
367
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-order.functions.d.ts","sourceRoot":"","sources":["../../src/lib/create-order.functions.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,2BAA2B;;;;;;GA+CpC,CAAC;AAIL,eAAO,MAAM,2BAA2B;;;;0CAElB,OAAO;;;;GAoDzB,CAAC;AAWL,eAAO,MAAM,0BAA0B;;;;;;YA+D7B,MAAM;iBACD,MAAM;sBACD,MAAM,GAAG,IAAI;cACrB,MAAM;oBACA,MAAM,GAAG,IAAI;0BACP,MAAM,GAAG,IAAI;0BACb,MAAM,GAAG,IAAI;yBACd,MAAM,GAAG,IAAI;wBACd,MAAM;wBACN,MAAM;yBACL,MAAM;kBACb,OAAO;gBACT,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS;;GAkSpD,CAAC;AAGL,eAAO,MAAM,kCAAkC;;;;0CAEzB,OAAO;;;;;;;;;;;;;;;;;;;;;;GAkDzB,CAAC;AAKL,eAAO,MAAM,qBAAqB;;;;;;YAoBI,MAAM;;;GAIxC,CAAC;AAGL,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;GAanC,CAAC;AASL,eAAO,MAAM,8BAA8B;;;;8CAEjB,OAAO;;;;GAU7B,CAAC;AASL,eAAO,MAAM,mBAAmB;;;;;;;;0BAgBuB,MAAM;0BAAoB,MAAM;yBAAmB,MAAM;;;GA8C5G,CAAC;AAGL,eAAO,MAAM,kBAAkB;;;;;;GAU3B,CAAC;AAkFL,eAAO,MAAM,iBAAiB;;;;8CAEJ,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"create-order.functions.d.ts","sourceRoot":"","sources":["../../src/lib/create-order.functions.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,2BAA2B;;;;;;GA+CpC,CAAC;AAIL,eAAO,MAAM,2BAA2B;;;;0CAElB,OAAO;;;;GAoDzB,CAAC;AAWL,eAAO,MAAM,0BAA0B;;;;;;YA+D7B,MAAM;iBACD,MAAM;sBACD,MAAM,GAAG,IAAI;cACrB,MAAM;oBACA,MAAM,GAAG,IAAI;0BACP,MAAM,GAAG,IAAI;0BACb,MAAM,GAAG,IAAI;yBACd,MAAM,GAAG,IAAI;wBACd,MAAM;wBACN,MAAM;yBACL,MAAM;kBACb,OAAO;gBACT,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS;;GAkSpD,CAAC;AAGL,eAAO,MAAM,kCAAkC;;;;0CAEzB,OAAO;;;;;;;;;;;;;;;;;;;;;;GAkDzB,CAAC;AAKL,eAAO,MAAM,qBAAqB;;;;;;YAoBI,MAAM;;;GAIxC,CAAC;AAGL,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;GAanC,CAAC;AASL,eAAO,MAAM,8BAA8B;;;;8CAEjB,OAAO;;;;GAU7B,CAAC;AASL,eAAO,MAAM,mBAAmB;;;;;;;;0BAgBuB,MAAM;0BAAoB,MAAM;yBAAmB,MAAM;;;GA8C5G,CAAC;AAGL,eAAO,MAAM,kBAAkB;;;;;;GAU3B,CAAC;AAkFL,eAAO,MAAM,iBAAiB;;;;8CAEJ,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aA4RL,MAAM;;;;GAK9B,CAAC;AAKL,eAAO,MAAM,gBAAgB;;;;8CAEH,OAAO;;;;;;;GAc7B,CAAC;AAQL,eAAO,MAAM,gBAAgB;;;;8CAEH,OAAO;;;;;;GAoG7B,CAAC;AAEL;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;;;8CAER,OAAO;;;;GAyB7B,CAAC;AAgDL,eAAO,MAAM,oBAAoB;;;;8CAEP,OAAO;;;aA2JG,MAAM;iBACQ,MAAM,GAAG,IAAI;kBACX,MAAM;;YAEnB,MAAM,GAAG,IAAI;;;;YAmB7B,MAAM;mBACS,MAAM,GAAG,IAAI;qBACT,MAAM;;cAErB,MAAM,GAAG,IAAI;;;;;;;GASpC,CAAC;AAIL,eAAO,MAAM,gBAAgB;;;;8CAEH,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyR7B,CAAC;AAKL,eAAO,MAAM,kBAAkB;;;;8CAEL,OAAO;;;;;;;;WAUM,MAAM;YAAU,MAAM,GAAG,IAAI;WAahE,CAAC;AAOL,eAAO,MAAM,2BAA2B;;;;8CAEd,OAAO;;;;gBAIgC,MAAM,EAAE;GAoCrE,CAAC"}
|
|
@@ -974,8 +974,10 @@ export const createManualOrder = createServerFn({ method: "POST" })
|
|
|
974
974
|
console.warn("[createManualOrder] engine-event faalde:", err);
|
|
975
975
|
}
|
|
976
976
|
try {
|
|
977
|
+
const { getRequest } = await import("@tanstack/react-start/server");
|
|
978
|
+
const reqUrl = getRequest()?.url;
|
|
977
979
|
const { wakeEnginePlanNow } = await import("./engine-wake.server.js");
|
|
978
|
-
wakeEnginePlanNow([order.id], "aanmaken");
|
|
980
|
+
wakeEnginePlanNow([order.id], reqUrl ? new URL(reqUrl).origin : null, "aanmaken");
|
|
979
981
|
}
|
|
980
982
|
catch (err) {
|
|
981
983
|
console.warn("[createManualOrder] engine wekken faalde:", err);
|
|
@@ -997,10 +999,12 @@ export const cancelLocalOrder = createServerFn({ method: "POST" })
|
|
|
997
999
|
.parse(input))
|
|
998
1000
|
.handler(async ({ data, context }) => {
|
|
999
1001
|
const { cancelLocalOrderInternal } = await import("./order-cancel.server.js");
|
|
1002
|
+
const { requestOrigin } = await import("./engine-wake.server.js");
|
|
1000
1003
|
return await cancelLocalOrderInternal({
|
|
1001
1004
|
orderId: data.orderId,
|
|
1002
1005
|
reason: data.reason ?? null,
|
|
1003
1006
|
userId: context.userId,
|
|
1007
|
+
origin: await requestOrigin(),
|
|
1004
1008
|
});
|
|
1005
1009
|
});
|
|
1006
1010
|
// ─── Verwijderen van een lokale bestelling ────────────────────────────────
|
|
@@ -1619,8 +1623,10 @@ export const updateLocalOrder = createServerFn({ method: "POST" })
|
|
|
1619
1623
|
console.warn("[updateLocalOrder] engine-event faalde:", err);
|
|
1620
1624
|
}
|
|
1621
1625
|
try {
|
|
1626
|
+
const { getRequest } = await import("@tanstack/react-start/server");
|
|
1627
|
+
const reqUrl = getRequest()?.url;
|
|
1622
1628
|
const { wakeEnginePlanNow } = await import("./engine-wake.server.js");
|
|
1623
|
-
wakeEnginePlanNow([data.orderId], "bewerken");
|
|
1629
|
+
wakeEnginePlanNow([data.orderId], reqUrl ? new URL(reqUrl).origin : null, "bewerken");
|
|
1624
1630
|
}
|
|
1625
1631
|
catch (err) {
|
|
1626
1632
|
console.warn("[updateLocalOrder] engine wekken faalde:", err);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare function runSalesOrdersMirror(mirrorLimit: number): Promise<{
|
|
2
|
+
ok: boolean;
|
|
3
|
+
mirrorOk: boolean;
|
|
4
|
+
mirrored: number;
|
|
5
|
+
}>;
|
|
6
|
+
export declare function runSalesOrdersSyncFromCron(): Promise<{
|
|
7
|
+
ok: boolean;
|
|
8
|
+
mirrorOk: boolean;
|
|
9
|
+
mirrored: number;
|
|
10
|
+
processed: number;
|
|
11
|
+
fullRun: boolean;
|
|
12
|
+
since: string | null;
|
|
13
|
+
watermarkAdvanced: boolean;
|
|
14
|
+
maintenance: Record<string, unknown>;
|
|
15
|
+
blockAlerts: {
|
|
16
|
+
mailed: number;
|
|
17
|
+
closed: number;
|
|
18
|
+
};
|
|
19
|
+
}>;
|
|
20
|
+
//# sourceMappingURL=salesorders-sync.server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"salesorders-sync.server.d.ts","sourceRoot":"","sources":["../../../src/lib/cron/salesorders-sync.server.ts"],"names":[],"mappings":"AAOA,wBAAsB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;IACvE,EAAE,EAAE,OAAO,CAAC;IACZ,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC,CAaD;AAkCD,wBAAsB,0BAA0B;;;;;;;;;;;;;GAmD/C"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// Server-only: minuutronde (cron) en spiegelen uit floriday_salesorders_cache.
|
|
2
|
+
// Alleen geïmporteerd door de cronroute en (dynamisch) door createServerFn-
|
|
3
|
+
// handlers. Nooit vanuit een scherm of een .functions.ts-topniveau importeren.
|
|
4
|
+
// Ophalen bij Floriday doet uitsluitend de Authenticatie-module (cursor
|
|
5
|
+
// "sales-orders", zelfde tabel floriday_salesorders_cache). Deze module
|
|
6
|
+
// spiegelt alleen nog uit die gedeelde cache naar de lokale orders.
|
|
7
|
+
export async function runSalesOrdersMirror(mirrorLimit) {
|
|
8
|
+
let mirrorOk = true;
|
|
9
|
+
let mirrored = 0;
|
|
10
|
+
try {
|
|
11
|
+
const { mirrorFloridayOrdersFromCron } = await import("../floriday-mirror.server.js");
|
|
12
|
+
const m = (await mirrorFloridayOrdersFromCron(mirrorLimit));
|
|
13
|
+
mirrorOk = m?.ok !== false;
|
|
14
|
+
mirrored = Number(m?.created ?? 0) + Number(m?.updated ?? 0) || 0;
|
|
15
|
+
}
|
|
16
|
+
catch (mirrorErr) {
|
|
17
|
+
mirrorOk = false;
|
|
18
|
+
console.error("[floriday-mirror] failed", mirrorErr);
|
|
19
|
+
}
|
|
20
|
+
return { ok: mirrorOk, mirrorOk, mirrored };
|
|
21
|
+
}
|
|
22
|
+
const MIRROR_CRON_LIMIT = 500;
|
|
23
|
+
const SYNC_KEY = "salesorders-mirror";
|
|
24
|
+
/** Onderhoud zonder handwerk: index herbouwen als die leeg is (max 1×/uur), cron vastleggen (max 1×/uur). */
|
|
25
|
+
async function runMaintenance(supabaseAdmin, nowMs) {
|
|
26
|
+
const { dueAgain, REBUILD_EVERY_MS, ENSURE_CRON_EVERY_MS } = await import("../sync-watermark.js");
|
|
27
|
+
const out = {};
|
|
28
|
+
const { data: rows } = await supabaseAdmin
|
|
29
|
+
.from("verkoop_sync_state")
|
|
30
|
+
.select("key, rebuilt_at, ensure_cron_at")
|
|
31
|
+
.in("key", ["fulfillment-index", "cron"]);
|
|
32
|
+
const byKey = new Map((rows ?? []).map((r) => [r.key, r]));
|
|
33
|
+
try {
|
|
34
|
+
const { count, error } = await supabaseAdmin
|
|
35
|
+
.from("verkoop_fulfillment_index")
|
|
36
|
+
.select("sales_order_id", { count: "exact", head: true });
|
|
37
|
+
if (error)
|
|
38
|
+
throw new Error(error.message);
|
|
39
|
+
if ((count ?? 0) === 0 && dueAgain(byKey.get("fulfillment-index")?.rebuilt_at, nowMs, REBUILD_EVERY_MS)) {
|
|
40
|
+
const { data, error: rErr } = await supabaseAdmin.rpc("verkoop_fulfillment_index_rebuild");
|
|
41
|
+
if (rErr)
|
|
42
|
+
throw new Error(rErr.message);
|
|
43
|
+
out.indexRebuild = data;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
out.indexError = e.message;
|
|
48
|
+
}
|
|
49
|
+
if (dueAgain(byKey.get("cron")?.ensure_cron_at, nowMs, ENSURE_CRON_EVERY_MS)) {
|
|
50
|
+
const { data, error } = await supabaseAdmin.rpc("verkoop_ensure_cron");
|
|
51
|
+
out.ensureCron = error ? { ok: false, error: error.message } : data;
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
export async function runSalesOrdersSyncFromCron() {
|
|
56
|
+
const { supabaseAdmin } = await import("../../integrations/supabase/client.server.js");
|
|
57
|
+
const { planMirrorRun, nextSyncState } = await import("../sync-watermark.js");
|
|
58
|
+
const nowMs = Date.now();
|
|
59
|
+
const startedAt = new Date(nowMs).toISOString();
|
|
60
|
+
const maintenance = await runMaintenance(supabaseAdmin, nowMs);
|
|
61
|
+
const { data: stateRow, error: stErr } = await supabaseAdmin
|
|
62
|
+
.from("verkoop_sync_state")
|
|
63
|
+
.select("last_seen_at, full_run_at")
|
|
64
|
+
.eq("key", SYNC_KEY)
|
|
65
|
+
.maybeSingle();
|
|
66
|
+
// Stand niet leesbaar: volledige ronde (veilig), watermerk blijft staan.
|
|
67
|
+
const run = stErr ? { full: true, since: null } : planMirrorRun(stateRow ?? null, nowMs);
|
|
68
|
+
let mirrorOk = true;
|
|
69
|
+
let mirrored = 0;
|
|
70
|
+
let processed = 0;
|
|
71
|
+
let skipped;
|
|
72
|
+
try {
|
|
73
|
+
const { mirrorFloridayOrdersFromCron } = await import("../floriday-mirror.server.js");
|
|
74
|
+
const m = (await mirrorFloridayOrdersFromCron(MIRROR_CRON_LIMIT, run.since));
|
|
75
|
+
mirrorOk = m?.ok !== false;
|
|
76
|
+
mirrored = Number(m?.inserted ?? 0) + Number(m?.updated ?? 0) || 0;
|
|
77
|
+
processed = Number(m?.processed ?? 0) || 0;
|
|
78
|
+
skipped = m?.skipped_reason;
|
|
79
|
+
}
|
|
80
|
+
catch (mirrorErr) {
|
|
81
|
+
mirrorOk = false;
|
|
82
|
+
console.error("[floriday-mirror] failed", mirrorErr);
|
|
83
|
+
}
|
|
84
|
+
const next = !stErr && !skipped ? nextSyncState(run, { ok: mirrorOk, processed }, MIRROR_CRON_LIMIT, startedAt) : null;
|
|
85
|
+
if (next) {
|
|
86
|
+
await supabaseAdmin
|
|
87
|
+
.from("verkoop_sync_state")
|
|
88
|
+
.upsert({ key: SYNC_KEY, ...next, updated_at: new Date().toISOString() }, { onConflict: "key" });
|
|
89
|
+
}
|
|
90
|
+
// Blokkade-alarm alleen op basis van de Engine (koppelprompt 22).
|
|
91
|
+
const { checkDefinitiveBlocks } = await import("../engine-block-alerts.server.js");
|
|
92
|
+
const alerts = await checkDefinitiveBlocks();
|
|
93
|
+
return {
|
|
94
|
+
ok: mirrorOk,
|
|
95
|
+
mirrorOk,
|
|
96
|
+
mirrored,
|
|
97
|
+
processed,
|
|
98
|
+
fullRun: run.full,
|
|
99
|
+
since: run.since,
|
|
100
|
+
watermarkAdvanced: Boolean(next),
|
|
101
|
+
maintenance,
|
|
102
|
+
blockAlerts: { mailed: alerts.mailed, closed: alerts.closed },
|
|
103
|
+
};
|
|
104
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { runSalesOrdersSyncFromCron } from "
|
|
1
|
+
import { runSalesOrdersSyncFromCron } from "./salesorders-sync.server.js";
|
|
2
2
|
const LOCK_KEY = "verkoop:salesorders-sync";
|
|
3
3
|
const LOCK_SECONDS = 600;
|
|
4
4
|
export async function syncSalesOrdersCron(request, _supabase) {
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export declare function wakeEnginePlanNow(orderIds: string[], reason: string): void;
|
|
1
|
+
export declare function wakeEnginePlanNow(orderIds: string[], origin: string | null, reason: string): void;
|
|
2
|
+
/** Origin van de lopende aanvraag; alleen aanroepen binnen een server-handler. */
|
|
3
|
+
export declare function requestOrigin(): Promise<string | null>;
|
|
2
4
|
//# sourceMappingURL=engine-wake.server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine-wake.server.d.ts","sourceRoot":"","sources":["../../src/lib/engine-wake.server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"engine-wake.server.d.ts","sourceRoot":"","sources":["../../src/lib/engine-wake.server.ts"],"names":[],"mappings":"AAiDA,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CA8BjG;AAED,kFAAkF;AAClF,wBAAsB,aAAa,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAQ5D"}
|
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
// Contract met de Logistiek Engine: POST <eigen origin van de aanvraag>
|
|
4
4
|
// /api/public/hooks/logistics-plan-now met body {"order_ids":[...]} en header
|
|
5
5
|
// x-logistics-key = module_runtime_config 'logistics_tick_apikey'.
|
|
6
|
-
// - Geen host in de code: de origin
|
|
6
|
+
// - Geen host in de code: de aanroeper geeft de origin van de binnenkomende
|
|
7
|
+
// aanvraag mee (opgehaald in de createServerFn-handler met een dynamische
|
|
8
|
+
// import). Geen statische import van @tanstack/react-start/server: dit
|
|
9
|
+
// bestand kan in de clientgraaf belanden en dat breekt de clientbuild.
|
|
7
10
|
// - Fail closed: geen origin of geen sleutel → niets versturen, alleen loggen.
|
|
8
11
|
// - Nooit blokkerend: time-out 3 s, niet wachten op het antwoord; 404 (oude
|
|
9
12
|
// Engine), fout of time-out geeft alleen een logregel. De pg_net-wek van de
|
|
10
13
|
// Engine blijft het vangnet.
|
|
11
|
-
import { getRequest } from "@tanstack/react-start/server";
|
|
12
14
|
const HOOK_PATH = "/api/public/hooks/logistics-plan-now";
|
|
13
15
|
const TIMEOUT_MS = 3000;
|
|
14
16
|
const KEY_TTL_MS = 5 * 60000;
|
|
@@ -28,15 +30,6 @@ async function readTickKey() {
|
|
|
28
30
|
keyCache = { at: Date.now(), value };
|
|
29
31
|
return value;
|
|
30
32
|
}
|
|
31
|
-
function currentOrigin() {
|
|
32
|
-
try {
|
|
33
|
-
const req = getRequest();
|
|
34
|
-
return req?.url ? new URL(req.url).origin : null;
|
|
35
|
-
}
|
|
36
|
-
catch {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
33
|
/** Probeert waitUntil van de runtime; anders gewoon niet wachten. */
|
|
41
34
|
async function keepAlive(p) {
|
|
42
35
|
try {
|
|
@@ -52,12 +45,10 @@ async function keepAlive(p) {
|
|
|
52
45
|
}
|
|
53
46
|
void p;
|
|
54
47
|
}
|
|
55
|
-
export function wakeEnginePlanNow(orderIds, reason) {
|
|
48
|
+
export function wakeEnginePlanNow(orderIds, origin, reason) {
|
|
56
49
|
const ids = Array.from(new Set(orderIds.filter(Boolean)));
|
|
57
50
|
if (!ids.length)
|
|
58
51
|
return;
|
|
59
|
-
// Origin direct (binnen de aanvraag) bepalen.
|
|
60
|
-
const origin = currentOrigin();
|
|
61
52
|
const run = (async () => {
|
|
62
53
|
try {
|
|
63
54
|
const key = await readTickKey();
|
|
@@ -88,3 +79,14 @@ export function wakeEnginePlanNow(orderIds, reason) {
|
|
|
88
79
|
})();
|
|
89
80
|
void keepAlive(run);
|
|
90
81
|
}
|
|
82
|
+
/** Origin van de lopende aanvraag; alleen aanroepen binnen een server-handler. */
|
|
83
|
+
export async function requestOrigin() {
|
|
84
|
+
try {
|
|
85
|
+
const { getRequest } = await import("@tanstack/react-start/server");
|
|
86
|
+
const req = getRequest();
|
|
87
|
+
return req?.url ? new URL(req.url).origin : null;
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -1,21 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
ok: boolean;
|
|
3
|
-
processed: number;
|
|
4
|
-
inserted: number;
|
|
5
|
-
updated: number;
|
|
6
|
-
skipped: number;
|
|
7
|
-
unchanged?: number;
|
|
8
|
-
failed: number;
|
|
9
|
-
enqueued?: number;
|
|
10
|
-
/** Per gewijzigde order welke velden echt veranderden. */
|
|
11
|
-
changes?: {
|
|
12
|
-
order_id: string;
|
|
13
|
-
fields: string[];
|
|
14
|
-
}[];
|
|
15
|
-
errors: string[];
|
|
16
|
-
skipped_reason?: string;
|
|
17
|
-
}
|
|
18
|
-
export declare function mirrorFloridayOrdersFromCron(limit?: number, since?: string | null): Promise<MirrorResult>;
|
|
1
|
+
import type { MirrorResult } from "./floriday-mirror.server.js";
|
|
19
2
|
export declare const mirrorFloridayOrders: import("@tanstack/start-client-core").OptionalFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
|
|
20
3
|
supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
|
|
21
4
|
userId: string;
|
|
@@ -23,5 +6,4 @@ export declare const mirrorFloridayOrders: import("@tanstack/start-client-core")
|
|
|
23
6
|
}, undefined, undefined, undefined>], (input: unknown) => {
|
|
24
7
|
limit?: number | undefined;
|
|
25
8
|
}, Promise<MirrorResult>>;
|
|
26
|
-
export {};
|
|
27
9
|
//# sourceMappingURL=floriday-mirror.functions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"floriday-mirror.functions.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-mirror.functions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"floriday-mirror.functions.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-mirror.functions.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,eAAO,MAAM,oBAAoB;;;;8CAEP,OAAO;;yBAM7B,CAAC"}
|