@flowselections/floriday-authenticatie-module 1.0.22 → 1.0.24

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 (47) hide show
  1. package/dist-lib/components/settings/FloricodeSettingsCard.js +1 -1
  2. package/dist-lib/integrations/supabase/auth-middleware.d.ts +385 -3
  3. package/dist-lib/integrations/supabase/auth-middleware.d.ts.map +1 -1
  4. package/dist-lib/integrations/supabase/client.d.ts +385 -3
  5. package/dist-lib/integrations/supabase/client.d.ts.map +1 -1
  6. package/dist-lib/integrations/supabase/client.server.d.ts +385 -3
  7. package/dist-lib/integrations/supabase/client.server.d.ts.map +1 -1
  8. package/dist-lib/integrations/supabase/client.server.js +1 -0
  9. package/dist-lib/integrations/supabase/types.d.ts +389 -3
  10. package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
  11. package/dist-lib/lib/central-auth.server.d.ts +34 -0
  12. package/dist-lib/lib/central-auth.server.d.ts.map +1 -0
  13. package/dist-lib/lib/central-auth.server.js +105 -0
  14. package/dist-lib/lib/floricode-credentials.server.d.ts.map +1 -1
  15. package/dist-lib/lib/floricode-credentials.server.js +94 -26
  16. package/dist-lib/lib/floricode.functions.d.ts +2758 -83
  17. package/dist-lib/lib/floricode.functions.d.ts.map +1 -1
  18. package/dist-lib/lib/floricode.functions.js +13 -0
  19. package/dist-lib/lib/floriday-auction-letters.functions.d.ts +385 -3
  20. package/dist-lib/lib/floriday-auction-letters.functions.d.ts.map +1 -1
  21. package/dist-lib/lib/floriday-labels.functions.d.ts +385 -3
  22. package/dist-lib/lib/floriday-labels.functions.d.ts.map +1 -1
  23. package/dist-lib/lib/floriday-public.functions.d.ts +2310 -18
  24. package/dist-lib/lib/floriday-public.functions.d.ts.map +1 -1
  25. package/dist-lib/lib/floriday-stickers.functions.d.ts +385 -3
  26. package/dist-lib/lib/floriday-stickers.functions.d.ts.map +1 -1
  27. package/dist-lib/lib/floriday-sync.functions.d.ts +12493 -651
  28. package/dist-lib/lib/floriday-sync.functions.d.ts.map +1 -1
  29. package/dist-lib/lib/floriday-sync.functions.js +2 -1
  30. package/dist-lib/lib/floriday-writes.functions.d.ts +2310 -18
  31. package/dist-lib/lib/floriday-writes.functions.d.ts.map +1 -1
  32. package/dist-lib/lib/floriday.functions.d.ts +7322 -321
  33. package/dist-lib/lib/floriday.functions.d.ts.map +1 -1
  34. package/dist-lib/lib/floriday.functions.js +33 -35
  35. package/dist-lib/lib/gateway/cache-tables.d.ts +2 -0
  36. package/dist-lib/lib/gateway/cache-tables.d.ts.map +1 -0
  37. package/dist-lib/lib/gateway/cache-tables.js +27 -0
  38. package/dist-lib/lib/gateway/cached-list.d.ts +15 -0
  39. package/dist-lib/lib/gateway/cached-list.d.ts.map +1 -0
  40. package/dist-lib/lib/gateway/cached-list.js +35 -0
  41. package/dist-lib/lib/gateway/index.d.ts +4 -0
  42. package/dist-lib/lib/gateway/index.d.ts.map +1 -0
  43. package/dist-lib/lib/gateway/index.js +3 -0
  44. package/dist-lib/lib/gateway/shared.d.ts +2 -0
  45. package/dist-lib/lib/gateway/shared.d.ts.map +1 -0
  46. package/dist-lib/lib/gateway/shared.js +3 -0
  47. package/package.json +6 -2
@@ -93,7 +93,8 @@ function toPublic(row) {
93
93
  }
94
94
  // ─── Reusable internals (importable by other server fns) ────────────────────
95
95
  export async function getActiveFlorydayCredentials(supabase, env) {
96
- const { data, error } = await supabase
96
+ const { supabaseAdmin } = await import("../integrations/supabase/client.server");
97
+ const { data, error } = await supabaseAdmin
97
98
  .from("floriday_connections")
98
99
  .select("*")
99
100
  .eq("environment", env)
@@ -104,6 +105,7 @@ export async function getActiveFlorydayCredentials(supabase, env) {
104
105
  return data;
105
106
  }
106
107
  export async function getFlorydayAccessToken(supabase, env, options = {}) {
108
+ const { supabaseAdmin } = await import("../integrations/supabase/client.server");
107
109
  const row = await getActiveFlorydayCredentials(supabase, env);
108
110
  if (!row)
109
111
  throw new Error(`Geen actieve Floriday-koppeling voor ${env}`);
@@ -117,7 +119,7 @@ export async function getFlorydayAccessToken(supabase, env, options = {}) {
117
119
  // Concurrency-guard: vlak voor de tokenrequest opnieuw lezen — een parallelle worker
118
120
  // kan zojuist een fresh token hebben geschreven en dan hoeven we niet nóg eens te refreshen.
119
121
  if (canReuseStoredToken && !options.forceRefresh) {
120
- const { data: fresh } = await supabase
122
+ const { data: fresh } = await supabaseAdmin
121
123
  .from("floriday_connections")
122
124
  .select("access_token, token_expires_at")
123
125
  .eq("id", row.id)
@@ -127,32 +129,20 @@ export async function getFlorydayAccessToken(supabase, env, options = {}) {
127
129
  return fresh.access_token;
128
130
  }
129
131
  }
130
- let json;
132
+ let accessToken;
131
133
  let newExpiresAt;
132
134
  try {
133
- const tokenRes = await fetch(FLORYDAY_ENDPOINTS[env].tokenUrl, {
134
- method: "POST",
135
- headers: {
136
- "Content-Type": "application/x-www-form-urlencoded",
137
- Accept: "application/json",
138
- },
139
- body: new URLSearchParams({
140
- grant_type: "client_credentials",
141
- client_id: deepSanitizeCredential(row.client_id),
142
- client_secret: deepSanitizeCredential(row.client_secret),
143
- scope: requestedScope,
144
- }).toString(),
145
- });
146
- const text = await tokenRes.text();
147
- if (!tokenRes.ok) {
148
- throw createFlorydayTokenError(tokenRes.status, text, requestedScope);
135
+ const { getFlorydayTokenFromCentral } = await import("./central-auth.server");
136
+ const result = await getFlorydayTokenFromCentral(env, requestedScope);
137
+ if (!result.ok) {
138
+ throw createFlorydayTokenError(result.raw.status, result.raw.body, requestedScope);
149
139
  }
150
- json = JSON.parse(text);
151
- newExpiresAt = new Date(now + json.expires_in * 1000).toISOString();
140
+ accessToken = result.access_token;
141
+ newExpiresAt = result.expires_at;
152
142
  if (canReuseStoredToken) {
153
- await supabase
143
+ await supabaseAdmin
154
144
  .from("floriday_connections")
155
- .update({ access_token: json.access_token, token_expires_at: newExpiresAt })
145
+ .update({ access_token: accessToken, token_expires_at: newExpiresAt })
156
146
  .eq("id", row.id);
157
147
  }
158
148
  // Best-effort logging (faalt nooit hard).
@@ -172,7 +162,7 @@ export async function getFlorydayAccessToken(supabase, env, options = {}) {
172
162
  }).then(() => undefined, () => undefined);
173
163
  throw e;
174
164
  }
175
- return json.access_token;
165
+ return accessToken;
176
166
  }
177
167
  function createFlorydayTokenError(status, body, scope) {
178
168
  const normalized = body.toLowerCase();
@@ -194,6 +184,7 @@ function createFlorydayTokenError(status, body, scope) {
194
184
  return new Error(`Floriday token-aanvraag mislukt [${status}]: ${body.slice(0, 300)}`);
195
185
  }
196
186
  async function fetchAndStoreFlorydayOrganizationName(supabase, env, connectionId) {
187
+ const { supabaseAdmin } = await import("../integrations/supabase/client.server");
197
188
  try {
198
189
  // Stap 1: bepaal de eigen organizationId via trade-settings.
199
190
  const tsRes = await florydayFetch(supabase, env, `/${SUPPLIERS_API_VERSION}/trade-settings/supplier/current-organization`);
@@ -219,7 +210,7 @@ async function fetchAndStoreFlorydayOrganizationName(supabase, env, connectionId
219
210
  if (!name)
220
211
  return null;
221
212
  // Lees huidige rij om gln_code niet te overschrijven als die al gezet is.
222
- const { data: existing } = await supabase
213
+ const { data: existing } = await supabaseAdmin
223
214
  .from("floriday_connections")
224
215
  .select("gln_code")
225
216
  .eq("id", connectionId)
@@ -228,7 +219,7 @@ async function fetchAndStoreFlorydayOrganizationName(supabase, env, connectionId
228
219
  if (gln && !existing?.gln_code) {
229
220
  update.gln_code = gln;
230
221
  }
231
- await supabase.from("floriday_connections").update(update).eq("id", connectionId);
222
+ await supabaseAdmin.from("floriday_connections").update(update).eq("id", connectionId);
232
223
  return name;
233
224
  }
234
225
  catch (e) {
@@ -311,7 +302,8 @@ export async function florydayFetch(supabase, pathOrEnv, pathOrInit, maybeInit =
311
302
  export const listFlorydayConnections = createServerFn({ method: "GET" })
312
303
  .middleware([requireSupabaseAuth])
313
304
  .handler(async ({ context }) => {
314
- const { data, error } = await context.supabase
305
+ const { supabaseAdmin } = await import("../integrations/supabase/client.server");
306
+ const { data, error } = await supabaseAdmin
315
307
  .from("floriday_connections")
316
308
  .select("*")
317
309
  .order("environment", { ascending: true });
@@ -322,7 +314,8 @@ export const listFlorydayConnections = createServerFn({ method: "GET" })
322
314
  export const getFlorydayTokenHealth = createServerFn({ method: "GET" })
323
315
  .middleware([requireSupabaseAuth])
324
316
  .handler(async ({ context }) => {
325
- const { data: conns } = await context.supabase
317
+ const { supabaseAdmin } = await import("../integrations/supabase/client.server");
318
+ const { data: conns } = await supabaseAdmin
326
319
  .from("floriday_connections")
327
320
  .select("id, environment, token_expires_at, is_active")
328
321
  .eq("is_active", true);
@@ -345,8 +338,9 @@ export const forceRefreshFlorydayToken = createServerFn({ method: "POST" })
345
338
  return input;
346
339
  })
347
340
  .handler(async ({ data, context }) => {
341
+ const { supabaseAdmin } = await import("../integrations/supabase/client.server");
348
342
  await getFlorydayAccessToken(context.supabase, data.environment, { forceRefresh: true });
349
- const { data: row } = await context.supabase
343
+ const { data: row } = await supabaseAdmin
350
344
  .from("floriday_connections")
351
345
  .select("token_expires_at")
352
346
  .eq("environment", data.environment)
@@ -366,12 +360,13 @@ export const upsertFlorydayConnection = createServerFn({ method: "POST" })
366
360
  return input;
367
361
  })
368
362
  .handler(async ({ data, context }) => {
363
+ const { supabaseAdmin } = await import("../integrations/supabase/client.server");
369
364
  // Update-in-place op (environment, is_active=true) — geen DELETE meer,
370
365
  // anders zou ON DELETE CASCADE alle cache-data voor deze connection wissen
371
366
  // bij een gewone credential-wijziging. SELECT-filter matcht exact de
372
367
  // partiële unieke index floriday_connections_env_active_uniq
373
368
  // (environment) WHERE is_active = true.
374
- const { data: existing, error: selectError } = await context.supabase
369
+ const { data: existing, error: selectError } = await supabaseAdmin
375
370
  .from("floriday_connections")
376
371
  .select("id")
377
372
  .eq("environment", data.environment)
@@ -392,7 +387,7 @@ export const upsertFlorydayConnection = createServerFn({ method: "POST" })
392
387
  };
393
388
  let inserted;
394
389
  if (existing?.id) {
395
- const { data: updated, error } = await context.supabase
390
+ const { data: updated, error } = await supabaseAdmin
396
391
  .from("floriday_connections")
397
392
  .update(payload)
398
393
  .eq("id", existing.id)
@@ -407,7 +402,7 @@ export const upsertFlorydayConnection = createServerFn({ method: "POST" })
407
402
  // de partiële unieke index vangt de tweede insert luid af met een
408
403
  // constraint-error. Credentials opslaan is een handmatige, zeldzame
409
404
  // actie — geen extra locking nodig.
410
- const { data: created, error } = await context.supabase
405
+ const { data: created, error } = await supabaseAdmin
411
406
  .from("floriday_connections")
412
407
  .insert({ environment: data.environment, ...payload })
413
408
  .select("*")
@@ -491,7 +486,8 @@ export const deleteFlorydayConnection = createServerFn({ method: "POST" })
491
486
  return input;
492
487
  })
493
488
  .handler(async ({ data, context }) => {
494
- const { error } = await context.supabase
489
+ const { supabaseAdmin } = await import("../integrations/supabase/client.server");
490
+ const { error } = await supabaseAdmin
495
491
  .from("floriday_connections")
496
492
  .delete()
497
493
  .eq("id", data.id);
@@ -693,10 +689,11 @@ export const updateFlorydayPublishingSettings = createServerFn({ method: "POST"
693
689
  return { ...input, gln_code: trimmed || null };
694
690
  })
695
691
  .handler(async ({ data, context }) => {
692
+ const { supabaseAdmin } = await import("../integrations/supabase/client.server");
696
693
  const row = await getActiveFlorydayCredentials(context.supabase, data.environment);
697
694
  if (!row)
698
695
  throw new Error(`Geen actieve Floriday-koppeling voor ${data.environment}`);
699
- const { error } = await context.supabase
696
+ const { error } = await supabaseAdmin
700
697
  .from("floriday_connections")
701
698
  .update({
702
699
  gln_code: data.gln_code?.trim() || null,
@@ -743,6 +740,7 @@ async function fetchBySequence(supabase, env, bySequenceEndpointBase, fromSequen
743
740
  }
744
741
  export async function syncFloridayEntityBySequence(supabase, env, connectionId, opts) {
745
742
  const t0 = Date.now();
743
+ const { supabaseAdmin } = await import("../integrations/supabase/client.server");
746
744
  const { data: stateRow } = await supabase
747
745
  .from("floriday_sync_state")
748
746
  .select("last_sequence_number")
@@ -754,7 +752,7 @@ export async function syncFloridayEntityBySequence(supabase, env, connectionId,
754
752
  // Debug-logging: helpt 401's onderscheid maken tussen scope-issue,
755
753
  // expired token en wrong env. Token zelf wordt NIET gelogd.
756
754
  try {
757
- const { data: connRow } = await supabase
755
+ const { data: connRow } = await supabaseAdmin
758
756
  .from("floriday_connections")
759
757
  .select("token_expires_at")
760
758
  .eq("id", connectionId)
@@ -0,0 +1,2 @@
1
+ export declare const CACHE_TABLES: Record<string, string>;
2
+ //# sourceMappingURL=cache-tables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-tables.d.ts","sourceRoot":"","sources":["../../../src/lib/gateway/cache-tables.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAyB/C,CAAC"}
@@ -0,0 +1,27 @@
1
+ // Letterlijke kopie uit src/routes/api/public/gateway/cached-list.ts (HEAD).
2
+ export const CACHE_TABLES = {
3
+ "sales-orders": "floriday_salesorders_cache",
4
+ "trade-items": "floriday_trade_items_cache",
5
+ "customer-organizations": "floriday_customers_cache",
6
+ "carriers": "floriday_carriers_cache",
7
+ "fulfillment-orders": "floriday_fulfillment_orders_cache",
8
+ "delivery-orders": "floriday_delivery_orders_cache",
9
+ "clock-supplies": "floriday_clock_supplies_cache",
10
+ "clock-presales": "floriday_clock_presales_cache",
11
+ "contracts": "floriday_contracts_cache",
12
+ "blanket-orders": "floriday_blanket_orders_cache",
13
+ "warehouses": "floriday_warehouses_cache",
14
+ "delivery-locations": "floriday_delivery_locations_cache",
15
+ "packings": "floriday_packings_cache",
16
+ "connections": "floriday_connections_cache",
17
+ "customer-stickers": "floriday_customer_stickers_cache",
18
+ "additional-services": "floriday_additional_services_cache",
19
+ "commercial-service-types": "floriday_commercial_service_types_cache",
20
+ "collections": "floriday_collections_cache",
21
+ "price-groups": "floriday_price_groups_cache",
22
+ "delivery-condition-sets": "floriday_delivery_condition_sets_cache",
23
+ "sales-strategies": "floriday_sales_strategies_cache",
24
+ "base-items": "floriday_base_items_cache",
25
+ "contract-trade-item-groups": "floriday_contract_trade_item_groups_cache",
26
+ "trade-item-classifications": "floriday_trade_item_classifications_cache",
27
+ };
@@ -0,0 +1,15 @@
1
+ import type { SupabaseClient } from "@supabase/supabase-js";
2
+ export interface CachedListInput {
3
+ environment: "staging" | "live";
4
+ entity: string;
5
+ limit?: number;
6
+ }
7
+ export type CachedListResult = {
8
+ ok: true;
9
+ rows: unknown[];
10
+ } | {
11
+ ok: false;
12
+ error: string;
13
+ };
14
+ export declare function runCachedList(supabase: SupabaseClient, parsed: CachedListInput): Promise<CachedListResult>;
15
+ //# sourceMappingURL=cached-list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cached-list.d.ts","sourceRoot":"","sources":["../../../src/lib/gateway/cached-list.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG5D,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,SAAS,GAAG,MAAM,CAAC;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,gBAAgB,GACxB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,OAAO,EAAE,CAAA;CAAE,GAC7B;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjC,wBAAsB,aAAa,CACjC,QAAQ,EAAE,cAAc,EACxB,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,gBAAgB,CAAC,CA8B3B"}
@@ -0,0 +1,35 @@
1
+ // Verplaatste business-logica voor de cached-list gateway-route.
2
+ // Behoud van gedrag: query, limit-clamp en ordering zijn letterlijk overgenomen
3
+ // uit src/routes/api/public/gateway/cached-list.ts (HEAD). Enige verschillen:
4
+ // (a) supabase is een parameter, (b) return data i.p.v. Response, (c) imports.
5
+ import { CACHE_TABLES } from "../../lib/gateway/cache-tables";
6
+ export async function runCachedList(supabase, parsed) {
7
+ if (parsed.environment !== "staging" && parsed.environment !== "live") {
8
+ return { ok: false, error: "Ongeldige environment" };
9
+ }
10
+ const table = CACHE_TABLES[parsed.entity];
11
+ if (!table) {
12
+ return { ok: false, error: `Onbekende entity: ${parsed.entity}` };
13
+ }
14
+ const limit = Math.min(Math.max(parsed.limit ?? 100, 1), 1000);
15
+ const { data: conn } = await supabase
16
+ .from("floriday_connections")
17
+ .select("id")
18
+ .eq("environment", parsed.environment)
19
+ .eq("is_active", true)
20
+ .order("updated_at", { ascending: false })
21
+ .limit(1)
22
+ .maybeSingle();
23
+ if (!conn) {
24
+ return { ok: false, error: `Geen actieve koppeling voor ${parsed.environment}` };
25
+ }
26
+ const { data: rows, error } = await supabase
27
+ .from(table)
28
+ .select("*")
29
+ .eq("connection_id", conn.id)
30
+ .order("updated_at", { ascending: false })
31
+ .limit(limit);
32
+ if (error)
33
+ return { ok: false, error: error.message };
34
+ return { ok: true, rows: rows ?? [] };
35
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./shared";
2
+ export * from "./cache-tables";
3
+ export * from "./cached-list";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/gateway/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./shared";
2
+ export * from "./cache-tables";
3
+ export * from "./cached-list";
@@ -0,0 +1,2 @@
1
+ export { verifyGatewayCaller, corsPreflight, withCors, GATEWAY_CORS_HEADERS, } from "../../lib/floriday-gateway-auth";
2
+ //# sourceMappingURL=shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/lib/gateway/shared.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,QAAQ,EACR,oBAAoB,GACrB,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,3 @@
1
+ // Gateway shared re-exports — subset used by cached-list (stap 1).
2
+ // Aanvullende exports (binary caller, types) volgen bij latere lifts.
3
+ export { verifyGatewayCaller, corsPreflight, withCors, GATEWAY_CORS_HEADERS, } from "../../lib/floriday-gateway-auth";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowselections/floriday-authenticatie-module",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "sideEffects": false,
5
5
  "type": "module",
6
6
  "main": "./dist-lib/index.js",
@@ -9,6 +9,10 @@
9
9
  ".": {
10
10
  "types": "./dist-lib/index.d.ts",
11
11
  "default": "./dist-lib/index.js"
12
+ },
13
+ "./gateway": {
14
+ "types": "./dist-lib/lib/gateway/index.d.ts",
15
+ "default": "./dist-lib/lib/gateway/index.js"
12
16
  }
13
17
  },
14
18
  "files": [
@@ -39,7 +43,7 @@
39
43
  "devDependencies": {
40
44
  "@flowselections/core": "1.0.16",
41
45
  "@eslint/js": "^9.32.0",
42
- "@lovable.dev/vite-tanstack-config": "2.7.1",
46
+ "@lovable.dev/vite-tanstack-config": "2.7.6",
43
47
  "@types/node": "^22.16.5",
44
48
  "@types/react": "^19.2.0",
45
49
  "@types/react-dom": "^19.2.0",