@flowselections/logistiek-engine 1.0.11 → 1.0.12

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 (24) hide show
  1. package/dist-lib/integrations/supabase/auth-middleware.d.ts +1125 -189
  2. package/dist-lib/integrations/supabase/auth-middleware.d.ts.map +1 -1
  3. package/dist-lib/integrations/supabase/client.server.d.ts +1125 -189
  4. package/dist-lib/integrations/supabase/client.server.d.ts.map +1 -1
  5. package/dist-lib/integrations/supabase/moduleClient.d.ts +1125 -189
  6. package/dist-lib/integrations/supabase/moduleClient.d.ts.map +1 -1
  7. package/dist-lib/integrations/supabase/types.d.ts +1152 -185
  8. package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
  9. package/dist-lib/lib/floridayDocuments.functions.d.ts +3135 -327
  10. package/dist-lib/lib/floridayDocuments.functions.d.ts.map +1 -1
  11. package/dist-lib/lib/floridayDocuments.server.d.ts +14 -1
  12. package/dist-lib/lib/floridayDocuments.server.d.ts.map +1 -1
  13. package/dist-lib/lib/floridayDocuments.server.js +1 -1
  14. package/dist-lib/lib/floridayPush.functions.d.ts +1125 -189
  15. package/dist-lib/lib/floridayPush.functions.d.ts.map +1 -1
  16. package/dist-lib/lib/floridayPush.server.d.ts.map +1 -1
  17. package/dist-lib/lib/floridayPush.server.js +48 -6
  18. package/dist-lib/lib/loadCarrierPlanning.functions.d.ts +5225 -545
  19. package/dist-lib/lib/loadCarrierPlanning.functions.d.ts.map +1 -1
  20. package/dist-lib/lib/logisticsRecalcJob.functions.d.ts +2090 -218
  21. package/dist-lib/lib/logisticsRecalcJob.functions.d.ts.map +1 -1
  22. package/dist-lib/lib/logisticsRecalculate.functions.d.ts +1125 -189
  23. package/dist-lib/lib/logisticsRecalculate.functions.d.ts.map +1 -1
  24. package/package.json +1 -1
@@ -116,6 +116,21 @@ function isPermanent(status, message) {
116
116
  return true;
117
117
  return /validat|ongeldig|invalid|schema|not found|bestaat niet/i.test(message);
118
118
  }
119
+ /** Korte, stabiele foutcode om later op te kunnen filteren. */
120
+ function gatewayErrorCode(status, payloadOk) {
121
+ if (status === null)
122
+ return "unknown";
123
+ if (status >= 200 && status < 300)
124
+ return payloadOk === true ? "unknown" : "gateway_ok_unreadable";
125
+ if (status >= 500)
126
+ return "gateway_5xx";
127
+ if (status === 400 || status === 401 || status === 404 || status === 429) {
128
+ return `gateway_${status}`;
129
+ }
130
+ if (status >= 400)
131
+ return "gateway_4xx";
132
+ return "unknown";
133
+ }
119
134
  export async function runFloridayPushQueue(sb, opts = {}) {
120
135
  const limit = opts.limit ?? FLORIDAY_PUSH_BATCH;
121
136
  const deadlineAt = opts.deadlineAt ?? Date.now() + 10000;
@@ -148,6 +163,9 @@ export async function runFloridayPushQueue(sb, opts = {}) {
148
163
  let error = null;
149
164
  let sentHash = null;
150
165
  let fulfillmentOrderId = null;
166
+ let gatewayStatus = null;
167
+ let errorCode = null;
168
+ let response = null;
151
169
  try {
152
170
  const built = await buildFloridayPayload(sb, orderRef);
153
171
  if (!built) {
@@ -155,6 +173,7 @@ export async function runFloridayPushQueue(sb, opts = {}) {
155
173
  ok = false;
156
174
  permanent = true;
157
175
  error = "Order niet gevonden in de Engine.";
176
+ errorCode = "order_missing";
158
177
  }
159
178
  else if (built.hash === lastSentHash) {
160
179
  // Identieke stand: niets versturen, wel als geslaagd afronden.
@@ -163,22 +182,42 @@ export async function runFloridayPushQueue(sb, opts = {}) {
163
182
  out.skipped++;
164
183
  }
165
184
  else {
166
- const res = (await sendFlorydayFulfillmentOrder(sb, built.payload));
167
- ok = res?.ok === true;
185
+ const res = await sendFlorydayFulfillmentOrder(sb, built.payload);
186
+ gatewayStatus = typeof res?.status === "number" ? res.status : null;
187
+ // Nieuw contract: { status, payload: { ok, error, fulfillmentOrderId } }.
188
+ // Defensief: een oudere gatewayversie gaf ok/error op het hoogste niveau.
189
+ const payload = (res?.payload ?? null);
190
+ if (!payload && res && ("ok" in res || "error" in res)) {
191
+ console.warn("[floridayPush] gateway gaf de oude responsvorm terug (ok/error op hoofdniveau)");
192
+ }
193
+ const payloadOk = payload?.ok ?? res?.ok;
194
+ const payloadError = payload?.error ?? res?.error;
195
+ ok = payloadOk === true;
168
196
  sentHash = built.hash;
169
- fulfillmentOrderId = built.payload.fulfillmentOrderId;
197
+ fulfillmentOrderId =
198
+ payload?.fulfillmentOrderId ?? built.payload.fulfillmentOrderId ?? null;
199
+ response = {
200
+ ok: payloadOk ?? null,
201
+ error: payloadError ?? null,
202
+ fulfillmentOrderId: payload?.fulfillmentOrderId ?? null,
203
+ };
170
204
  if (!ok) {
171
- error = res?.error ?? "Floriday gaf geen bevestiging.";
172
- permanent = isPermanent(res?.status ?? null, error);
205
+ error =
206
+ payloadError && String(payloadError).length > 0
207
+ ? String(payloadError)
208
+ : `Floriday gaf geen bevestiging. (gatewaystatus ${gatewayStatus ?? "onbekend"})`;
209
+ errorCode = gatewayErrorCode(gatewayStatus, payloadOk);
210
+ permanent = isPermanent(gatewayStatus, error);
173
211
  }
174
212
  }
175
213
  }
176
214
  catch (e) {
177
215
  error = String(e?.message ?? e);
216
+ errorCode = errorCode ?? "unknown";
178
217
  permanent = isPermanent(null, error);
179
218
  }
180
219
  try {
181
- const { data: outcome } = await sb.rpc("logistics_floriday_finish_push", {
220
+ const { data: outcome } = await sb.rpc("logistics_floriday_finish_push_v2", {
182
221
  _id: id,
183
222
  _revision: revision,
184
223
  _ok: ok,
@@ -186,6 +225,9 @@ export async function runFloridayPushQueue(sb, opts = {}) {
186
225
  _fulfillment_order_id: fulfillmentOrderId,
187
226
  _sent_hash: sentHash,
188
227
  _permanent: permanent,
228
+ _gateway_status: gatewayStatus,
229
+ _error_code: errorCode,
230
+ _response: response,
189
231
  });
190
232
  const status = String(outcome ?? "");
191
233
  if (status === "sent")