@flowselections/floriday-authenticatie-module 1.0.20 → 1.0.21

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 (31) hide show
  1. package/dist-lib/components/settings/FlorydaySettingsCard.js +0 -3
  2. package/dist-lib/integrations/supabase/auth-middleware.d.ts +976 -179
  3. package/dist-lib/integrations/supabase/auth-middleware.d.ts.map +1 -1
  4. package/dist-lib/integrations/supabase/client.d.ts +976 -179
  5. package/dist-lib/integrations/supabase/client.d.ts.map +1 -1
  6. package/dist-lib/integrations/supabase/client.server.d.ts +976 -179
  7. package/dist-lib/integrations/supabase/client.server.d.ts.map +1 -1
  8. package/dist-lib/integrations/supabase/types.d.ts +994 -170
  9. package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
  10. package/dist-lib/lib/floricode.functions.d.ts +6833 -1254
  11. package/dist-lib/lib/floricode.functions.d.ts.map +1 -1
  12. package/dist-lib/lib/floriday-auction-letters.functions.d.ts +976 -179
  13. package/dist-lib/lib/floriday-auction-letters.functions.d.ts.map +1 -1
  14. package/dist-lib/lib/floriday-labels.functions.d.ts +976 -179
  15. package/dist-lib/lib/floriday-labels.functions.d.ts.map +1 -1
  16. package/dist-lib/lib/floriday-public.functions.d.ts +5852 -1070
  17. package/dist-lib/lib/floriday-public.functions.d.ts.map +1 -1
  18. package/dist-lib/lib/floriday-scopes.d.ts +0 -8
  19. package/dist-lib/lib/floriday-scopes.d.ts.map +1 -1
  20. package/dist-lib/lib/floriday-scopes.js +4 -28
  21. package/dist-lib/lib/floriday-stickers.functions.d.ts +976 -179
  22. package/dist-lib/lib/floriday-stickers.functions.d.ts.map +1 -1
  23. package/dist-lib/lib/floriday-sync.functions.d.ts +30431 -28430
  24. package/dist-lib/lib/floriday-sync.functions.d.ts.map +1 -1
  25. package/dist-lib/lib/floriday-sync.functions.js +62 -145
  26. package/dist-lib/lib/floriday-writes.functions.d.ts +5858 -1112
  27. package/dist-lib/lib/floriday-writes.functions.d.ts.map +1 -1
  28. package/dist-lib/lib/floriday.functions.d.ts +17624 -3278
  29. package/dist-lib/lib/floriday.functions.d.ts.map +1 -1
  30. package/dist-lib/lib/floriday.functions.js +47 -21
  31. package/package.json +2 -2
@@ -7,8 +7,34 @@
7
7
  // ============================================================================
8
8
  import { createServerFn } from "@tanstack/react-start";
9
9
  import { requireSupabaseAuth } from "../integrations/supabase/auth-middleware";
10
- import { FLORYDAY_AGREEMENT_PERMISSION_MESSAGE, FLORYDAY_CONTRACT_PERMISSION_MESSAGE, FLORYDAY_SALES_STRATEGY_PERMISSION_MESSAGE, } from "./floriday-scopes";
10
+ import { FLORYDAY_CONTRACT_PERMISSION_MESSAGE, FLORYDAY_SALES_STRATEGY_PERMISSION_MESSAGE, } from "./floriday-scopes";
11
11
  import { SUPPLIERS_API_VERSION, getActiveFlorydayCredentials, resolveFlorydayCronBaseUrl, syncFloridayEntityBySequence, } from "./floriday.functions";
12
+ // Chunked upsert met retry-op-statement-timeout. Voorkomt dat één trage batch
13
+ // een hele sync-run doet falen; zie .lovable/plan.md (verharding).
14
+ async function upsertInChunks(supabase, table, rows, onConflict, label, chunkSize = 200) {
15
+ if (rows.length === 0)
16
+ return;
17
+ const total = Math.ceil(rows.length / chunkSize);
18
+ for (let i = 0; i < rows.length; i += chunkSize) {
19
+ const chunk = rows.slice(i, i + chunkSize);
20
+ const idx = Math.floor(i / chunkSize) + 1;
21
+ let attempt = 0;
22
+ while (true) {
23
+ const { error } = await supabase
24
+ .from(table)
25
+ .upsert(chunk, { onConflict });
26
+ if (!error)
27
+ break;
28
+ const msg = String(error?.message ?? "");
29
+ const isTimeout = error?.code === "57014" || /statement timeout/i.test(msg);
30
+ if (!isTimeout || attempt >= 2) {
31
+ throw new Error(`${label} upsert: ${msg} (chunk ${idx}/${total}, size ${chunk.length})`);
32
+ }
33
+ attempt += 1;
34
+ await new Promise((r) => setTimeout(r, 250 * Math.pow(2, attempt - 1)));
35
+ }
36
+ }
37
+ }
12
38
  const now = () => new Date().toISOString();
13
39
  const RESOURCE_CONFIG = {
14
40
  "trade-items": {
@@ -34,11 +60,7 @@ const RESOURCE_CONFIG = {
34
60
  .filter(Boolean);
35
61
  if (rows.length === 0)
36
62
  return;
37
- const { error } = await supabase
38
- .from("floriday_trade_items_cache")
39
- .upsert(rows, { onConflict: "connection_id,floriday_id" });
40
- if (error)
41
- throw new Error(`trade-items upsert: ${error.message}`);
63
+ await upsertInChunks(supabase, "floriday_trade_items_cache", rows, "connection_id,floriday_id", "trade-items");
42
64
  },
43
65
  },
44
66
  "sales-orders": {
@@ -66,11 +88,7 @@ const RESOURCE_CONFIG = {
66
88
  .filter(Boolean);
67
89
  if (rows.length === 0)
68
90
  return;
69
- const { error } = await supabase
70
- .from("floriday_salesorders_cache")
71
- .upsert(rows, { onConflict: "connection_id,floriday_id" });
72
- if (error)
73
- throw new Error(`sales-orders upsert: ${error.message}`);
91
+ await upsertInChunks(supabase, "floriday_salesorders_cache", rows, "connection_id,floriday_id", "sales-orders");
74
92
  },
75
93
  },
76
94
  "customer-organizations": {
@@ -109,11 +127,7 @@ const RESOURCE_CONFIG = {
109
127
  .filter(Boolean);
110
128
  if (rows.length === 0)
111
129
  return;
112
- const { error } = await supabase
113
- .from("floriday_customers_cache")
114
- .upsert(rows, { onConflict: "organization_id" });
115
- if (error)
116
- throw new Error(`customer-organizations upsert: ${error.message}`);
130
+ await upsertInChunks(supabase, "floriday_customers_cache", rows, "organization_id", "customer-organizations");
117
131
  },
118
132
  },
119
133
  "carriers": {
@@ -144,11 +158,7 @@ const RESOURCE_CONFIG = {
144
158
  .filter(Boolean);
145
159
  if (rows.length === 0)
146
160
  return;
147
- const { error } = await supabase
148
- .from("floriday_carriers_cache")
149
- .upsert(rows, { onConflict: "organization_id" });
150
- if (error)
151
- throw new Error(`carriers upsert: ${error.message}`);
161
+ await upsertInChunks(supabase, "floriday_carriers_cache", rows, "organization_id", "carriers");
152
162
  },
153
163
  },
154
164
  "fulfillment-orders": {
@@ -184,11 +194,7 @@ const RESOURCE_CONFIG = {
184
194
  .filter(Boolean);
185
195
  if (rows.length === 0)
186
196
  return;
187
- const { error } = await supabase
188
- .from("floriday_fulfillment_orders_cache")
189
- .upsert(rows, { onConflict: "connection_id,floriday_id" });
190
- if (error)
191
- throw new Error(`fulfillment-orders upsert: ${error.message}`);
197
+ await upsertInChunks(supabase, "floriday_fulfillment_orders_cache", rows, "connection_id,floriday_id", "fulfillment-orders");
192
198
  },
193
199
  },
194
200
  "customer-stickers": {
@@ -218,11 +224,7 @@ const RESOURCE_CONFIG = {
218
224
  .filter(Boolean);
219
225
  if (rows.length === 0)
220
226
  return;
221
- const { error } = await supabase
222
- .from("floriday_customer_stickers_cache")
223
- .upsert(rows, { onConflict: "connection_id,floriday_id" });
224
- if (error)
225
- throw new Error(`customer-stickers upsert: ${error.message}`);
227
+ await upsertInChunks(supabase, "floriday_customer_stickers_cache", rows, "connection_id,floriday_id", "customer-stickers");
226
228
  },
227
229
  },
228
230
  "packings": {
@@ -251,11 +253,7 @@ const RESOURCE_CONFIG = {
251
253
  .filter(Boolean);
252
254
  if (rows.length === 0)
253
255
  return;
254
- const { error } = await supabase
255
- .from("floriday_packings_cache")
256
- .upsert(rows, { onConflict: "connection_id,floriday_id" });
257
- if (error)
258
- throw new Error(`packings upsert: ${error.message}`);
256
+ await upsertInChunks(supabase, "floriday_packings_cache", rows, "connection_id,floriday_id", "packings");
259
257
  },
260
258
  },
261
259
  "clock-supplies": {
@@ -291,11 +289,7 @@ const RESOURCE_CONFIG = {
291
289
  .filter(Boolean);
292
290
  if (rows.length === 0)
293
291
  return;
294
- const { error } = await supabase
295
- .from("floriday_clock_supplies_cache")
296
- .upsert(rows, { onConflict: "connection_id,floriday_id" });
297
- if (error)
298
- throw new Error(`clock-supplies upsert: ${error.message}`);
292
+ await upsertInChunks(supabase, "floriday_clock_supplies_cache", rows, "connection_id,floriday_id", "clock-supplies");
299
293
  },
300
294
  },
301
295
  "delivery-orders": {
@@ -328,11 +322,7 @@ const RESOURCE_CONFIG = {
328
322
  .filter(Boolean);
329
323
  if (rows.length === 0)
330
324
  return;
331
- const { error } = await supabase
332
- .from("floriday_delivery_orders_cache")
333
- .upsert(rows, { onConflict: "connection_id,floriday_id" });
334
- if (error)
335
- throw new Error(`delivery-orders upsert: ${error.message}`);
325
+ await upsertInChunks(supabase, "floriday_delivery_orders_cache", rows, "connection_id,floriday_id", "delivery-orders");
336
326
  },
337
327
  },
338
328
  "clock-presales": {
@@ -366,11 +356,7 @@ const RESOURCE_CONFIG = {
366
356
  .filter(Boolean);
367
357
  if (rows.length === 0)
368
358
  return;
369
- const { error } = await supabase
370
- .from("floriday_clock_presales_cache")
371
- .upsert(rows, { onConflict: "connection_id,floriday_id" });
372
- if (error)
373
- throw new Error(`clock-presales upsert: ${error.message}`);
359
+ await upsertInChunks(supabase, "floriday_clock_presales_cache", rows, "connection_id,floriday_id", "clock-presales");
374
360
  },
375
361
  },
376
362
  // Legacy resources (agreements, agreement-calloffs, trips, invoices) zijn
@@ -404,11 +390,7 @@ const RESOURCE_CONFIG = {
404
390
  .filter(Boolean);
405
391
  if (rows.length === 0)
406
392
  return;
407
- const { error } = await supabase
408
- .from("floriday_warehouses_cache")
409
- .upsert(rows, { onConflict: "connection_id,floriday_id" });
410
- if (error)
411
- throw new Error(`warehouses upsert: ${error.message}`);
393
+ await upsertInChunks(supabase, "floriday_warehouses_cache", rows, "connection_id,floriday_id", "warehouses");
412
394
  },
413
395
  },
414
396
  "delivery-locations": {
@@ -437,11 +419,7 @@ const RESOURCE_CONFIG = {
437
419
  .filter(Boolean);
438
420
  if (rows.length === 0)
439
421
  return;
440
- const { error } = await supabase
441
- .from("floriday_delivery_locations_cache")
442
- .upsert(rows, { onConflict: "connection_id,floriday_id" });
443
- if (error)
444
- throw new Error(`delivery-locations upsert: ${error.message}`);
422
+ await upsertInChunks(supabase, "floriday_delivery_locations_cache", rows, "connection_id,floriday_id", "delivery-locations");
445
423
  },
446
424
  },
447
425
  "contracts": {
@@ -469,11 +447,7 @@ const RESOURCE_CONFIG = {
469
447
  .filter(Boolean);
470
448
  if (rows.length === 0)
471
449
  return;
472
- const { error } = await supabase
473
- .from("floriday_contracts_cache")
474
- .upsert(rows, { onConflict: "connection_id,floriday_id" });
475
- if (error)
476
- throw new Error(`contracts upsert: ${error.message}`);
450
+ await upsertInChunks(supabase, "floriday_contracts_cache", rows, "connection_id,floriday_id", "contracts");
477
451
  },
478
452
  },
479
453
  "blanket-orders": {
@@ -501,11 +475,7 @@ const RESOURCE_CONFIG = {
501
475
  .filter(Boolean);
502
476
  if (rows.length === 0)
503
477
  return;
504
- const { error } = await supabase
505
- .from("floriday_blanket_orders_cache")
506
- .upsert(rows, { onConflict: "connection_id,floriday_id" });
507
- if (error)
508
- throw new Error(`blanket-orders upsert: ${error.message}`);
478
+ await upsertInChunks(supabase, "floriday_blanket_orders_cache", rows, "connection_id,floriday_id", "blanket-orders");
509
479
  },
510
480
  },
511
481
  // ── Stamdata voor productformulieren (centraal voor andere modules) ────
@@ -519,17 +489,22 @@ const RESOURCE_CONFIG = {
519
489
  "sales-strategies": makeSimpleSeq("sales-strategies", "sales-strategies", "floriday_sales_strategies_cache", ["salesStrategyId"], { maxSequencePath: "/sales-strategies/sync/max-sequence-number" }),
520
490
  "base-items": makeSimpleSeq("base-items", "base-items", "floriday_base_items_cache", ["baseItemId"]),
521
491
  "contract-trade-item-groups": makeSimpleSeq("contract-trade-item-groups", "contract-trade-item-groups", "floriday_contract_trade_item_groups_cache", ["contractTradeItemGroupId"]),
522
- // Agreements + agreement-calloffs (klantspecifieke contractprijzen).
523
- // Vereist scope `agreement:read` — zie floriday-scopes.ts.
524
- "agreements": {
492
+ // Agreements + agreement-calloffs zijn verwijderd: Floriday Suppliers API
493
+ // 2026v1 kent deze endpoints niet meer (404 route-not-found). Klant-
494
+ // specifieke prijs-/leveringsafspraken komen via /contracts en
495
+ // /customer-offers.
496
+ // Handelsinstellingen per klant (accepteert directe orders, contracten,
497
+ // transportkosten, FSI-eisen etc.). Endpoint: /trade-settings/customer/sync
498
+ // — geen aparte scope nodig; werkt met standaardtoken.
499
+ "trade-settings-customers": {
525
500
  kind: "sequence",
526
- entityType: "agreements",
527
- maxSequenceEndpoint: `/${SUPPLIERS_API_VERSION}/agreements/current-max-sequence`,
528
- bySequenceEndpointBase: `/${SUPPLIERS_API_VERSION}/agreements/sync`,
501
+ entityType: "trade-settings-customers",
502
+ maxSequenceEndpoint: `/${SUPPLIERS_API_VERSION}/trade-settings/customer/sync/0`,
503
+ bySequenceEndpointBase: `/${SUPPLIERS_API_VERSION}/trade-settings/customer/sync`,
529
504
  upsert: async (supabase, connectionId, items) => {
530
505
  const rows = items
531
506
  .map((item) => {
532
- const fid = item?.agreementId ?? item?.id ?? null;
507
+ const fid = item?.customerOrganizationId ?? null;
533
508
  if (!fid)
534
509
  return null;
535
510
  return {
@@ -537,55 +512,15 @@ const RESOURCE_CONFIG = {
537
512
  floriday_id: String(fid),
538
513
  sequence_number: Number(item?.sequenceNumber ?? 0),
539
514
  is_deleted: Boolean(item?.isDeleted),
540
- buyer_organization_id: item?.buyerOrganizationId ?? null,
541
- status: item?.status ?? null,
542
- valid_from: item?.validFrom ?? item?.periodStart ?? null,
543
- valid_until: item?.validUntil ?? item?.periodEnd ?? null,
544
- data: item,
545
- fetched_at: now(),
546
- };
547
- })
548
- .filter(Boolean);
549
- if (rows.length === 0)
550
- return;
551
- const { error } = await supabase
552
- .from("floriday_agreements_cache")
553
- .upsert(rows, { onConflict: "connection_id,floriday_id" });
554
- if (error)
555
- throw new Error(`agreements upsert: ${error.message}`);
556
- },
557
- },
558
- "agreement-calloffs": {
559
- kind: "sequence",
560
- entityType: "agreement-calloffs",
561
- maxSequenceEndpoint: `/${SUPPLIERS_API_VERSION}/agreement-calloffs/current-max-sequence`,
562
- bySequenceEndpointBase: `/${SUPPLIERS_API_VERSION}/agreement-calloffs/sync`,
563
- upsert: async (supabase, connectionId, items) => {
564
- const rows = items
565
- .map((item) => {
566
- const fid = item?.agreementCalloffId ?? item?.id ?? null;
567
- if (!fid)
568
- return null;
569
- return {
570
- connection_id: connectionId,
571
- floriday_id: String(fid),
572
- sequence_number: Number(item?.sequenceNumber ?? 0),
573
- is_deleted: Boolean(item?.isDeleted),
574
- agreement_id: item?.agreementId ?? null,
575
- delivery_date: item?.deliveryDate ?? null,
576
- status: item?.status ?? null,
577
515
  data: item,
578
516
  fetched_at: now(),
517
+ updated_at: now(),
579
518
  };
580
519
  })
581
520
  .filter(Boolean);
582
521
  if (rows.length === 0)
583
522
  return;
584
- const { error } = await supabase
585
- .from("floriday_agreement_calloffs_cache")
586
- .upsert(rows, { onConflict: "connection_id,floriday_id" });
587
- if (error)
588
- throw new Error(`agreement-calloffs upsert: ${error.message}`);
523
+ await upsertInChunks(supabase, "floriday_trade_settings_customers_cache", rows, "connection_id,floriday_id", "trade-settings-customers");
589
524
  },
590
525
  },
591
526
  // NB: `trade-item-classifications` is GEEN Floriday Suppliers-resource (2026v1
@@ -621,11 +556,7 @@ function makeSimpleSeq(entityType, apiPath, table, idFields, opts) {
621
556
  .filter(Boolean);
622
557
  if (rows.length === 0)
623
558
  return;
624
- const { error } = await supabase
625
- .from(table)
626
- .upsert(rows, { onConflict: "connection_id,floriday_id" });
627
- if (error)
628
- throw new Error(`${entityType} upsert: ${error.message}`);
559
+ await upsertInChunks(supabase, table, rows, "connection_id,floriday_id", entityType);
629
560
  },
630
561
  };
631
562
  }
@@ -686,9 +617,6 @@ async function runSyncHandler(context, environment, resource) {
686
617
  if (resource === "sales-strategies" && policyDenied) {
687
618
  message = FLORYDAY_SALES_STRATEGY_PERMISSION_MESSAGE;
688
619
  }
689
- else if ((resource === "agreements" || resource === "agreement-calloffs") && policyDenied) {
690
- message = FLORYDAY_AGREEMENT_PERMISSION_MESSAGE;
691
- }
692
620
  else if (isContractResource && policyDenied) {
693
621
  message = FLORYDAY_CONTRACT_PERMISSION_MESSAGE;
694
622
  }
@@ -867,15 +795,10 @@ const SCHEDULER_SPECS = {
867
795
  path: "/api/public/cron/sync-floriday-contract-trade-item-groups",
868
796
  jobname: "floriday-contract-trade-item-groups-sync-hourly",
869
797
  },
870
- "agreements": {
871
- rpc: "schedule_floriday_agreements_sync",
872
- path: "/api/public/cron/sync-floriday-agreements",
873
- jobname: "floriday-agreements-sync-hourly",
874
- },
875
- "agreement-calloffs": {
876
- rpc: "schedule_floriday_agreement_calloffs_sync",
877
- path: "/api/public/cron/sync-floriday-agreement-calloffs",
878
- jobname: "floriday-agreement-calloffs-sync-hourly",
798
+ "trade-settings-customers": {
799
+ rpc: "schedule_floriday_trade_settings_customers_sync",
800
+ path: "/api/public/cron/sync-floriday-trade-settings-customers",
801
+ jobname: "floriday-trade-settings-customers-sync-hourly",
879
802
  },
880
803
  };
881
804
  export async function scheduleFlorydayResourceSyncInternal(supabase, resource) {
@@ -983,14 +906,8 @@ export const syncFlorydayContractTradeItemGroups = createServerFn({ method: "POS
983
906
  .middleware([requireSupabaseAuth])
984
907
  .inputValidator(envValidator)
985
908
  .handler(async ({ data, context }) => runSyncHandler(context, data.environment, "contract-trade-item-groups"));
986
- export const syncFlorydayAgreements = createServerFn({ method: "POST" })
987
- .middleware([requireSupabaseAuth])
988
- .inputValidator(envValidator)
989
- .handler(async ({ data, context }) => runSyncHandler(context, data.environment, "agreements"));
990
- export const syncFlorydayAgreementCalloffs = createServerFn({ method: "POST" })
991
- .middleware([requireSupabaseAuth])
992
- .inputValidator(envValidator)
993
- .handler(async ({ data, context }) => runSyncHandler(context, data.environment, "agreement-calloffs"));
909
+ // syncFlorydayAgreements + syncFlorydayAgreementCalloffs zijn verwijderd:
910
+ // Suppliers API 2026v1 kent /agreements en /agreement-calloffs niet meer.
994
911
  // Opmerking: `trade-item-classifications` is verwijderd als sync-resource. De
995
912
  // Floriday Suppliers API (2026v1) kent dit endpoint niet (404 op
996
913
  // /current-max-sequence). Classificatie-data leeft in de Swagger-enums en