@flowselections/floriday-voorraad 1.0.70 → 1.0.72

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.
@@ -36,9 +36,10 @@ describe("weekaanbod aanmaken (nagespeelde antwoorden 1.0.61)", () => {
36
36
  expect(d.label).toContain("Ongeldige prijs: Prijs te laag");
37
37
  });
38
38
  it("prijs alleen bij stuks en > 0", () => {
39
- expect(priceForRow({ sale_price: 0, unit: "stuks" })).toEqual({ ok: false, label: "Prijs ontbreekt" });
39
+ expect(priceForRow({ sale_price: 0, unit: "stuks" })).toEqual({ ok: false, label: "Prijs is 0 of lager" });
40
+ expect(priceForRow({ sale_price: -1, unit: "stuks" })).toEqual({ ok: false, label: "Prijs is 0 of lager" });
40
41
  expect(priceForRow({ sale_price: null, unit: "stuks" })).toEqual({ ok: false, label: "Prijs ontbreekt" });
41
- expect(priceForRow({ sale_price: 3, unit: "fust" })).toEqual({ ok: false, label: "Eenheid onduidelijk" });
42
+ expect(priceForRow({ sale_price: 3, unit: "fust" })).toEqual({ ok: false, label: "Eenheid is geen stuks (nu: fust)" });
42
43
  expect(priceForRow({ sale_price: 1.1, unit: "stuks" })).toEqual({ ok: true, price: 1.1 });
43
44
  });
44
45
  it("aanvraag volgens contract, week van de regel, geen packingConfigurationId", () => {
@@ -7,6 +7,7 @@ export type ReaderWeek = {
7
7
  tradeItemId: string;
8
8
  numberOfPieces: number;
9
9
  isAvailable: boolean;
10
+ basePricePerPiece: number | null;
10
11
  }>;
11
12
  error: string | null;
12
13
  rateLimited: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"base-supply-reader.server.d.ts","sourceRoot":"","sources":["../../src/lib/base-supply-reader.server.ts"],"names":[],"mappings":"AAuBA,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,GAAG,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,CAAC,CAAC;CAC3B,CAAC;AAEF,wEAAwE;AACxE,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,kBAAkB,CAAC,CA4CtE"}
@@ -31,6 +31,10 @@ function extractRows(data) {
31
31
  tradeItemId: String(r.tradeItemId),
32
32
  numberOfPieces: Number(r.numberOfPieces ?? 0) || 0,
33
33
  isAvailable: r.isAvailable !== false,
34
+ // WeeklyBaseSupply.basePricePerPiece is een Price { currency, value } (Suppliers API 2026v1).
35
+ basePricePerPiece: r.basePricePerPiece && Number.isFinite(Number(r.basePricePerPiece.value))
36
+ ? Number(r.basePricePerPiece.value)
37
+ : null,
34
38
  }));
35
39
  }
36
40
  async function callOnce(endpoint, secret, year, week) {
@@ -19,8 +19,10 @@ export type PriceCheck = {
19
19
  price: number;
20
20
  } | {
21
21
  ok: false;
22
- label: "Prijs ontbreekt" | "Eenheid onduidelijk";
22
+ label: string;
23
23
  };
24
+ /** M26: de werkelijke reden waarom een prijs niet bruikbaar is (of null als hij in orde is). */
25
+ export declare function priceProblem(salePrice: unknown, unit: unknown): string | null;
24
26
  /** Prijs per stuk excl. btw: alleen bij eenheid "stuks" en prijs > 0. */
25
27
  export declare function priceForRow(row: Pick<BaseSupplyRow, "sale_price" | "unit">): PriceCheck;
26
28
  /** ISO-weekjaar en ISO-week van een moment in Nederlandse tijd. */
@@ -1 +1 @@
1
- {"version":3,"file":"floriday-base-supply.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-base-supply.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,aAAa,GAAG;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM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IAAI,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,CAAC;AAEF,8EAA8E;AAC9E,wBAAgB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ,CAoCnF;AAED,2EAA2E;AAC3E,wBAAgB,YAAY,CAC1B,GAAG,EAAE,aAAa,EAClB,KAAK,EAAE,MAAM,EACb,WAAW,CAAC,EAAE,SAAS,GAAG,MAAM;;;;;;;;;;EAiBjC"}
@@ -3,15 +3,26 @@
3
3
  * wordt gebruikt door de server-route en door de tests met nagespeelde
4
4
  * antwoorden van Floriday-authenticatie 1.0.61.
5
5
  */
6
+ /** M26: de werkelijke reden waarom een prijs niet bruikbaar is (of null als hij in orde is). */
7
+ export function priceProblem(salePrice, unit) {
8
+ const u = String(unit ?? "").trim().toLowerCase();
9
+ if (u && u !== "stuks" && u !== "stuk")
10
+ return `Eenheid is geen stuks (nu: ${String(unit).trim()})`;
11
+ if (salePrice === null || salePrice === undefined || String(salePrice).trim() === "")
12
+ return "Prijs ontbreekt";
13
+ const p = Number(salePrice);
14
+ if (!Number.isFinite(p))
15
+ return "Prijs ontbreekt";
16
+ if (p <= 0)
17
+ return "Prijs is 0 of lager";
18
+ return null;
19
+ }
6
20
  /** Prijs per stuk excl. btw: alleen bij eenheid "stuks" en prijs > 0. */
7
21
  export function priceForRow(row) {
8
- const unit = String(row.unit ?? "").trim().toLowerCase();
9
- if (unit && unit !== "stuks" && unit !== "stuk")
10
- return { ok: false, label: "Eenheid onduidelijk" };
11
- const p = Number(row.sale_price);
12
- if (!Number.isFinite(p) || p <= 0)
13
- return { ok: false, label: "Prijs ontbreekt" };
14
- return { ok: true, price: Math.round(p * 1000) / 1000 };
22
+ const problem = priceProblem(row.sale_price, row.unit);
23
+ if (problem)
24
+ return { ok: false, label: problem };
25
+ return { ok: true, price: Math.round(Number(row.sale_price) * 1000) / 1000 };
15
26
  }
16
27
  /** ISO-weekjaar en ISO-week van een moment in Nederlandse tijd. */
17
28
  export function isoWeekAmsterdam(at = new Date()) {
@@ -17,7 +17,7 @@ export declare const enqueueTestStockPush: import("@tanstack/start-client-core")
17
17
  }, undefined, undefined, undefined>], (data: unknown) => {
18
18
  tradeItemId: string;
19
19
  }, Promise<{
20
- id: any;
20
+ id: string | null;
21
21
  numberOfPieces: number;
22
22
  }>>;
23
23
  //# sourceMappingURL=stock-sync.functions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stock-sync.functions.d.ts","sourceRoot":"","sources":["../../src/lib/stock-sync.functions.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,oBAAoB;;;;;;GA0B7B,CAAC;AAEL;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;GAuC7B,CAAC"}
1
+ {"version":3,"file":"stock-sync.functions.d.ts","sourceRoot":"","sources":["../../src/lib/stock-sync.functions.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,oBAAoB;;;;;;GA0B7B,CAAC;AAEL;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;GAuD7B,CAAC"}
@@ -69,5 +69,21 @@ export const enqueueTestStockPush = createServerFn({ method: "POST" })
69
69
  .maybeSingle();
70
70
  if (error)
71
71
  throw new Error(error.message);
72
- return { id: inserted?.id ?? null, numberOfPieces: pieces };
72
+ // M27: staat er al een open regel voor dit artikel en deze week, dan werkt de
73
+ // database die bij en komt er geen nieuwe rij terug; geef dan het id van die regel.
74
+ let id = inserted?.id ?? null;
75
+ if (!id) {
76
+ const { data: existing } = await admin
77
+ .from("floriday_continuous_stock_queue")
78
+ .select("id")
79
+ .eq("connection_id", stockRow.connection_id)
80
+ .eq("trade_item_id", data.tradeItemId)
81
+ .is("target_week", null)
82
+ .in("status", ["pending", "needs_base_supply", "skipped_no_price", "failed", "processing", "creating_base_supply"])
83
+ .order("updated_at", { ascending: false })
84
+ .limit(1)
85
+ .maybeSingle();
86
+ id = existing?.id ?? null;
87
+ }
88
+ return { id, numberOfPieces: pieces };
73
89
  });
@@ -1 +1 @@
1
- {"version":3,"file":"floriday-base-supply.d.ts","sourceRoot":"","sources":["../../src/server-hooks/floriday-base-supply.ts"],"names":[],"mappings":"AA2EA,yHAAyH;AACzH,wBAAsB,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAElF"}
1
+ {"version":3,"file":"floriday-base-supply.d.ts","sourceRoot":"","sources":["../../src/server-hooks/floriday-base-supply.ts"],"names":[],"mappings":"AAwGA,yHAAyH;AACzH,wBAAsB,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAElF"}
@@ -33,6 +33,27 @@ async function handle(request) {
33
33
  if (error)
34
34
  return json({ error: `claim: ${error.message}` }, 500);
35
35
  const summary = { processed: 0, done: 0, retry: 0, stop: 0, week_past: 0, no_price: 0 };
36
+ // M27: bestaande prijs in Floriday per week (alleen lezen, 1 GET per week per ronde).
37
+ const { readBaseSupplyWeeks } = await import("../lib/base-supply-reader.server.js");
38
+ const weekCache = new Map();
39
+ async function floridayPrice(year, week, tradeItemId) {
40
+ if (!year || !week)
41
+ return null;
42
+ const k = `${year}-${week}`;
43
+ if (!weekCache.has(k)) {
44
+ const m = new Map();
45
+ try {
46
+ const out = await readBaseSupplyWeeks([{ year, week }]);
47
+ for (const r of out.results[0]?.rows ?? [])
48
+ m.set(r.tradeItemId, r.basePricePerPiece);
49
+ }
50
+ catch {
51
+ /* lezen is optioneel; zonder antwoord geen melding over prijsaanpassing */
52
+ }
53
+ weekCache.set(k, m);
54
+ }
55
+ return weekCache.get(k).get(tradeItemId) ?? null;
56
+ }
36
57
  let first = true;
37
58
  for (const row of (rows ?? [])) {
38
59
  summary.processed++;
@@ -45,6 +66,7 @@ async function handle(request) {
45
66
  if (!first)
46
67
  await sleep(1000); // max 1 aanvraag per seconde
47
68
  first = false;
69
+ const previous = await floridayPrice(row.target_year, row.target_week, row.trade_item_id);
48
70
  let d;
49
71
  try {
50
72
  const { httpStatus, body } = await gatewaySupplyLineWeek(buildRequest(row, price.price, conn.environment));
@@ -53,10 +75,19 @@ async function handle(request) {
53
75
  catch (e) {
54
76
  d = { kind: "retry", label: "Floriday tijdelijk niet bereikbaar", error: String(e?.message ?? e) };
55
77
  }
78
+ let label = d.label;
79
+ const changed = d.kind === "done" &&
80
+ d.priceStatus === "sent" &&
81
+ previous != null &&
82
+ Math.abs(previous - price.price) > 0.0005;
83
+ if (changed) {
84
+ label = `Prijs in Floriday aangepast van € ${previous.toFixed(2)} naar € ${price.price.toFixed(2)}`;
85
+ await admin.from("floriday_continuous_stock_queue").update({ price_previous: previous }).eq("id", row.id);
86
+ }
56
87
  await admin.rpc("complete_floriday_base_supply", {
57
88
  p_id: row.id,
58
89
  p_kind: d.kind,
59
- p_label: d.label,
90
+ p_label: label,
60
91
  p_error: d.error ?? null,
61
92
  p_attempt_id: d.attemptId ?? null,
62
93
  p_outcome: d.outcome ?? null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowselections/floriday-voorraad",
3
- "version": "1.0.70",
3
+ "version": "1.0.72",
4
4
  "sideEffects": false,
5
5
  "type": "module",
6
6
  "main": "./dist-lib/index.js",