@flowselections/floriday-klanten-module 1.0.14 → 1.0.15

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.
@@ -209,21 +209,69 @@ export const listFloridayNetwork = createServerFn({ method: "POST" })
209
209
  .middleware([requireSupabaseAuth])
210
210
  .inputValidator((input) => ({
211
211
  search: (input?.search ?? "").toString().trim().slice(0, 255),
212
+ types: Array.isArray(input?.types) && input.types.length > 0
213
+ ? input.types.slice(0, 10).map((t) => String(t).toUpperCase())
214
+ : ["CUSTOMER", "AGENT"],
215
+ includeExpired: !!input?.includeExpired,
216
+ limit: Math.min(Math.max(Number(input?.limit) || 500, 1), 2000),
212
217
  }))
213
218
  .handler(async ({ data, context }) => {
219
+ const nowIso = new Date().toISOString();
214
220
  let q = context.supabase
215
221
  .from("floriday_network_cache")
216
- .select("connection_id, organization_id, organization_name, gln, country, city, fetched_at")
217
- .order("organization_name")
218
- .limit(200);
222
+ .select("connection_id, organization_id, organization_name, gln, country, city, data, fetched_at", { count: "exact" })
223
+ .in("data->>organizationType", data.types)
224
+ .limit(data.limit);
225
+ if (!data.includeExpired) {
226
+ q = q.or(`data->>endDate.is.null,data->>endDate.gt.${nowIso}`);
227
+ }
219
228
  if (data.search) {
220
229
  const s = `%${data.search}%`;
221
- q = q.or(`organization_name.ilike.${s},gln.ilike.${s}`);
230
+ q = q.or(`organization_name.ilike.${s},gln.ilike.${s},data->>commercialName.ilike.${s},data->>name.ilike.${s}`);
222
231
  }
223
- const { data: rows, error } = await q;
232
+ const { data: rows, error, count } = await q;
224
233
  if (error)
225
234
  throw new Error(error.message);
226
- return { organizations: rows ?? [] };
235
+ const organizations = (rows ?? []).map((r) => {
236
+ const d = (r.data ?? {});
237
+ const physical = d.physicalAddress ?? {};
238
+ const mailing = d.mailingAddress ?? {};
239
+ const name = (r.organization_name && r.organization_name.trim()) ||
240
+ (typeof d.name === "string" && d.name.trim()) ||
241
+ (typeof d.commercialName === "string" && d.commercialName.trim()) ||
242
+ "";
243
+ const commercial = (typeof d.commercialName === "string" && d.commercialName.trim()) || "";
244
+ const endDate = d.endDate ?? null;
245
+ const isExpired = !!endDate && endDate < nowIso;
246
+ return {
247
+ connection_id: r.connection_id,
248
+ organization_id: r.organization_id,
249
+ organization_name: name,
250
+ commercial_name: commercial && commercial !== name ? commercial : null,
251
+ gln: r.gln ?? d.companyGln ?? null,
252
+ city: r.city ?? physical.city ?? mailing.city ?? null,
253
+ country: r.country ?? physical.countryCode ?? mailing.countryCode ?? null,
254
+ postal_code: physical.postalCode ?? mailing.postalCode ?? null,
255
+ address_line: physical.addressLine ?? mailing.addressLine ?? null,
256
+ organization_type: d.organizationType ?? null,
257
+ logo_url: d.logoUrl ?? null,
258
+ website: d.website ?? null,
259
+ end_date: endDate,
260
+ is_expired: isExpired,
261
+ fetched_at: r.fetched_at,
262
+ };
263
+ });
264
+ organizations.sort((a, b) => {
265
+ const an = a.organization_name || "\uffff";
266
+ const bn = b.organization_name || "\uffff";
267
+ return an.localeCompare(bn);
268
+ });
269
+ return {
270
+ organizations,
271
+ total: count ?? organizations.length,
272
+ limit: data.limit,
273
+ truncated: (count ?? 0) > organizations.length,
274
+ };
227
275
  });
228
276
  export const listCustomerClasses = createServerFn({ method: "POST" })
229
277
  .middleware([requireSupabaseAuth])
@@ -253,7 +301,7 @@ export const bulkImportCustomers = createServerFn({ method: "POST" })
253
301
  try {
254
302
  if (data.skipDuplicates) {
255
303
  const dupes = await findDuplicates(supabase, {
256
- email: row.email,
304
+ email: row.email ?? "",
257
305
  vat_number: row.vat_number || undefined,
258
306
  company_name: row.company_name,
259
307
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowselections/floriday-klanten-module",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "private": false,
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -46,7 +46,7 @@
46
46
  "devDependencies": {
47
47
  "@cloudflare/vite-plugin": "^1.25.5",
48
48
  "@eslint/js": "^9.32.0",
49
- "@flowselections/core": "^1.0.11",
49
+ "@flowselections/core": "1.0.12",
50
50
  "@lovable.dev/vite-tanstack-config": "2.6.4",
51
51
  "@rsbuild/core": "^1.0.0",
52
52
  "@tailwindcss/vite": "^4.2.1",