@flowselections/admin-installatietechniek 1.0.7 → 1.0.8
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.
- package/dist-lib/integrations/supabase/auth-middleware.d.ts +214 -1
- package/dist-lib/integrations/supabase/auth-middleware.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/client.d.ts +214 -1
- package/dist-lib/integrations/supabase/client.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/client.server.d.ts +214 -1
- package/dist-lib/integrations/supabase/client.server.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/types.d.ts +218 -1
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/lib/admin.functions.d.ts +4730 -44
- package/dist-lib/lib/admin.functions.d.ts.map +1 -1
- package/dist-lib/lib/admin.functions.js +23 -22
- package/dist-lib/lib/serverErrors.d.ts +7 -0
- package/dist-lib/lib/serverErrors.d.ts.map +1 -0
- package/dist-lib/lib/serverErrors.js +29 -0
- package/package.json +2 -2
|
@@ -2,6 +2,7 @@ import { createServerFn } from "@tanstack/react-start";
|
|
|
2
2
|
import { getRequestHost } from "@tanstack/react-start/server";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { requireSupabaseAuth } from "../integrations/supabase/auth-middleware";
|
|
5
|
+
import { normalizeServerErrors } from "../lib/serverErrors";
|
|
5
6
|
import { requireAdmin, requireUserAdmin } from "../lib/admin.server";
|
|
6
7
|
const featureSchema = z.object({
|
|
7
8
|
id: z.string().trim().min(1).max(200),
|
|
@@ -171,7 +172,7 @@ async function resolveEffectiveProfileId(admin, userId, requestedProfileId, isAd
|
|
|
171
172
|
return { profileId: undefined, locked: true };
|
|
172
173
|
}
|
|
173
174
|
export const getUsersWithRoles = createServerFn({ method: "POST" })
|
|
174
|
-
.middleware([requireSupabaseAuth])
|
|
175
|
+
.middleware([normalizeServerErrors, requireSupabaseAuth])
|
|
175
176
|
.inputValidator((data) => profileScopeInput.parse(data))
|
|
176
177
|
.handler(async ({ context, data }) => {
|
|
177
178
|
const { isAdmin } = await requireUserAdmin(context);
|
|
@@ -271,7 +272,7 @@ export const getUsersWithRoles = createServerFn({ method: "POST" })
|
|
|
271
272
|
};
|
|
272
273
|
});
|
|
273
274
|
export const assignRole = createServerFn({ method: "POST" })
|
|
274
|
-
.middleware([requireSupabaseAuth])
|
|
275
|
+
.middleware([normalizeServerErrors, requireSupabaseAuth])
|
|
275
276
|
.inputValidator((data) => assignRoleInput.parse(data))
|
|
276
277
|
.handler(async ({ context, data }) => {
|
|
277
278
|
const { isAdmin } = await requireUserAdmin(context);
|
|
@@ -307,7 +308,7 @@ export const assignRole = createServerFn({ method: "POST" })
|
|
|
307
308
|
return { ok: true };
|
|
308
309
|
});
|
|
309
310
|
export const removeRole = createServerFn({ method: "POST" })
|
|
310
|
-
.middleware([requireSupabaseAuth])
|
|
311
|
+
.middleware([normalizeServerErrors, requireSupabaseAuth])
|
|
311
312
|
.inputValidator((data) => assignRoleInput.parse(data))
|
|
312
313
|
.handler(async ({ context, data }) => {
|
|
313
314
|
const { isAdmin } = await requireUserAdmin(context);
|
|
@@ -326,7 +327,7 @@ export const removeRole = createServerFn({ method: "POST" })
|
|
|
326
327
|
});
|
|
327
328
|
/** Alle rollen met hun rechten, plus de geregistreerde modules en onderdelen. */
|
|
328
329
|
export const getRoles = createServerFn({ method: "POST" })
|
|
329
|
-
.middleware([requireSupabaseAuth])
|
|
330
|
+
.middleware([normalizeServerErrors, requireSupabaseAuth])
|
|
330
331
|
.inputValidator((data) => profileScopeInput.parse(data))
|
|
331
332
|
.handler(async ({ context, data }) => {
|
|
332
333
|
const { isAdmin } = await requireUserAdmin(context);
|
|
@@ -407,7 +408,7 @@ async function writeRolePermissions(supabase, roleId, permissions) {
|
|
|
407
408
|
throw error;
|
|
408
409
|
}
|
|
409
410
|
export const createRole = createServerFn({ method: "POST" })
|
|
410
|
-
.middleware([requireSupabaseAuth])
|
|
411
|
+
.middleware([normalizeServerErrors, requireSupabaseAuth])
|
|
411
412
|
.inputValidator((data) => createRoleInput.parse(data))
|
|
412
413
|
.handler(async ({ context, data }) => {
|
|
413
414
|
await requireAdmin(context);
|
|
@@ -436,7 +437,7 @@ export const createRole = createServerFn({ method: "POST" })
|
|
|
436
437
|
return { ok: true, roleId: created.id };
|
|
437
438
|
});
|
|
438
439
|
export const updateRole = createServerFn({ method: "POST" })
|
|
439
|
-
.middleware([requireSupabaseAuth])
|
|
440
|
+
.middleware([normalizeServerErrors, requireSupabaseAuth])
|
|
440
441
|
.inputValidator((data) => updateRoleInput.parse(data))
|
|
441
442
|
.handler(async ({ context, data }) => {
|
|
442
443
|
await requireAdmin(context);
|
|
@@ -450,7 +451,7 @@ export const updateRole = createServerFn({ method: "POST" })
|
|
|
450
451
|
return { ok: true };
|
|
451
452
|
});
|
|
452
453
|
export const duplicateRole = createServerFn({ method: "POST" })
|
|
453
|
-
.middleware([requireSupabaseAuth])
|
|
454
|
+
.middleware([normalizeServerErrors, requireSupabaseAuth])
|
|
454
455
|
.inputValidator((data) => roleIdInput.parse(data))
|
|
455
456
|
.handler(async ({ context, data }) => {
|
|
456
457
|
await requireAdmin(context);
|
|
@@ -487,7 +488,7 @@ export const duplicateRole = createServerFn({ method: "POST" })
|
|
|
487
488
|
return { ok: true, roleId: created.id };
|
|
488
489
|
});
|
|
489
490
|
export const deleteRole = createServerFn({ method: "POST" })
|
|
490
|
-
.middleware([requireSupabaseAuth])
|
|
491
|
+
.middleware([normalizeServerErrors, requireSupabaseAuth])
|
|
491
492
|
.inputValidator((data) => roleIdInput.parse(data))
|
|
492
493
|
.handler(async ({ context, data }) => {
|
|
493
494
|
await requireAdmin(context);
|
|
@@ -505,7 +506,7 @@ export const deleteRole = createServerFn({ method: "POST" })
|
|
|
505
506
|
* Wat niet meer voorkomt blijft bestaan maar wordt op inactief gezet.
|
|
506
507
|
*/
|
|
507
508
|
export const syncModuleRegistry = createServerFn({ method: "POST" })
|
|
508
|
-
.middleware([requireSupabaseAuth])
|
|
509
|
+
.middleware([normalizeServerErrors, requireSupabaseAuth])
|
|
509
510
|
.inputValidator((data) => syncModulesInput.parse(data))
|
|
510
511
|
.handler(async ({ context, data }) => {
|
|
511
512
|
await requireAdmin(context);
|
|
@@ -577,7 +578,7 @@ const setModuleEnforceInput = z.object({
|
|
|
577
578
|
enforce: z.boolean(),
|
|
578
579
|
});
|
|
579
580
|
export const setModuleEnforce = createServerFn({ method: "POST" })
|
|
580
|
-
.middleware([requireSupabaseAuth])
|
|
581
|
+
.middleware([normalizeServerErrors, requireSupabaseAuth])
|
|
581
582
|
.inputValidator((data) => setModuleEnforceInput.parse(data))
|
|
582
583
|
.handler(async ({ context, data }) => {
|
|
583
584
|
await requireAdmin(context);
|
|
@@ -590,7 +591,7 @@ export const setModuleEnforce = createServerFn({ method: "POST" })
|
|
|
590
591
|
return { ok: true };
|
|
591
592
|
});
|
|
592
593
|
export const getUserModulePermissions = createServerFn({ method: "POST" })
|
|
593
|
-
.middleware([requireSupabaseAuth])
|
|
594
|
+
.middleware([normalizeServerErrors, requireSupabaseAuth])
|
|
594
595
|
.inputValidator((data) => userPermissionsInput.parse(data))
|
|
595
596
|
.handler(async ({ context, data }) => {
|
|
596
597
|
await requireUserAdmin(context);
|
|
@@ -629,7 +630,7 @@ export const getUserModulePermissions = createServerFn({ method: "POST" })
|
|
|
629
630
|
};
|
|
630
631
|
});
|
|
631
632
|
export const setUserModulePermission = createServerFn({ method: "POST" })
|
|
632
|
-
.middleware([requireSupabaseAuth])
|
|
633
|
+
.middleware([normalizeServerErrors, requireSupabaseAuth])
|
|
633
634
|
.inputValidator((data) => setUserPermissionInput.parse(data))
|
|
634
635
|
.handler(async ({ context, data }) => {
|
|
635
636
|
await requireUserAdmin(context);
|
|
@@ -657,7 +658,7 @@ export const setUserModulePermission = createServerFn({ method: "POST" })
|
|
|
657
658
|
return { ok: true };
|
|
658
659
|
});
|
|
659
660
|
export const inviteUser = createServerFn({ method: "POST" })
|
|
660
|
-
.middleware([requireSupabaseAuth])
|
|
661
|
+
.middleware([normalizeServerErrors, requireSupabaseAuth])
|
|
661
662
|
.inputValidator((data) => inviteUserInput.parse(data))
|
|
662
663
|
.handler(async ({ context, data }) => {
|
|
663
664
|
const { isAdmin } = await requireUserAdmin(context);
|
|
@@ -697,7 +698,7 @@ export const inviteUser = createServerFn({ method: "POST" })
|
|
|
697
698
|
return { ok: true, userId };
|
|
698
699
|
});
|
|
699
700
|
export const deleteUser = createServerFn({ method: "POST" })
|
|
700
|
-
.middleware([requireSupabaseAuth])
|
|
701
|
+
.middleware([normalizeServerErrors, requireSupabaseAuth])
|
|
701
702
|
.inputValidator((data) => deleteUserInput.parse(data))
|
|
702
703
|
.handler(async ({ context, data }) => {
|
|
703
704
|
const { isAdmin } = await requireUserAdmin(context);
|
|
@@ -723,7 +724,7 @@ export const deleteUser = createServerFn({ method: "POST" })
|
|
|
723
724
|
return { ok: true };
|
|
724
725
|
});
|
|
725
726
|
export const updateUserName = createServerFn({ method: "POST" })
|
|
726
|
-
.middleware([requireSupabaseAuth])
|
|
727
|
+
.middleware([normalizeServerErrors, requireSupabaseAuth])
|
|
727
728
|
.inputValidator((data) => updateUserNameInput.parse(data))
|
|
728
729
|
.handler(async ({ context, data }) => {
|
|
729
730
|
const { isAdmin } = await requireUserAdmin(context);
|
|
@@ -763,7 +764,7 @@ function generatePassword(length = 16) {
|
|
|
763
764
|
return out;
|
|
764
765
|
}
|
|
765
766
|
export const createTestUser = createServerFn({ method: "POST" })
|
|
766
|
-
.middleware([requireSupabaseAuth])
|
|
767
|
+
.middleware([normalizeServerErrors, requireSupabaseAuth])
|
|
767
768
|
.inputValidator((data) => createTestUserInput.parse(data))
|
|
768
769
|
.handler(async ({ context, data }) => {
|
|
769
770
|
const { isAdmin } = await requireUserAdmin(context);
|
|
@@ -876,7 +877,7 @@ async function writeProfileLinks(supabase, profileId, roleIds, moduleIds) {
|
|
|
876
877
|
}
|
|
877
878
|
/** Alle bedrijfsprofielen met hun rollen, modules en tellingen. */
|
|
878
879
|
export const getProfiles = createServerFn({ method: "GET" })
|
|
879
|
-
.middleware([requireSupabaseAuth])
|
|
880
|
+
.middleware([normalizeServerErrors, requireSupabaseAuth])
|
|
880
881
|
.handler(async ({ context }) => {
|
|
881
882
|
const { isAdmin } = await requireUserAdmin(context);
|
|
882
883
|
const { supabaseAdmin } = await import("../integrations/supabase/client.server");
|
|
@@ -940,7 +941,7 @@ export const getProfiles = createServerFn({ method: "GET" })
|
|
|
940
941
|
};
|
|
941
942
|
});
|
|
942
943
|
export const createProfile = createServerFn({ method: "POST" })
|
|
943
|
-
.middleware([requireSupabaseAuth])
|
|
944
|
+
.middleware([normalizeServerErrors, requireSupabaseAuth])
|
|
944
945
|
.inputValidator((data) => createProfileInput.parse(data))
|
|
945
946
|
.handler(async ({ context, data }) => {
|
|
946
947
|
await requireAdmin(context);
|
|
@@ -959,7 +960,7 @@ export const createProfile = createServerFn({ method: "POST" })
|
|
|
959
960
|
return { ok: true, profileId: created.id };
|
|
960
961
|
});
|
|
961
962
|
export const updateProfile = createServerFn({ method: "POST" })
|
|
962
|
-
.middleware([requireSupabaseAuth])
|
|
963
|
+
.middleware([normalizeServerErrors, requireSupabaseAuth])
|
|
963
964
|
.inputValidator((data) => updateProfileInput.parse(data))
|
|
964
965
|
.handler(async ({ context, data }) => {
|
|
965
966
|
await requireAdmin(context);
|
|
@@ -975,7 +976,7 @@ export const updateProfile = createServerFn({ method: "POST" })
|
|
|
975
976
|
return { ok: true };
|
|
976
977
|
});
|
|
977
978
|
export const duplicateProfile = createServerFn({ method: "POST" })
|
|
978
|
-
.middleware([requireSupabaseAuth])
|
|
979
|
+
.middleware([normalizeServerErrors, requireSupabaseAuth])
|
|
979
980
|
.inputValidator((data) => profileIdInput.parse(data))
|
|
980
981
|
.handler(async ({ context, data }) => {
|
|
981
982
|
await requireAdmin(context);
|
|
@@ -1003,7 +1004,7 @@ export const duplicateProfile = createServerFn({ method: "POST" })
|
|
|
1003
1004
|
return { ok: true, profileId: created.id };
|
|
1004
1005
|
});
|
|
1005
1006
|
export const deleteProfile = createServerFn({ method: "POST" })
|
|
1006
|
-
.middleware([requireSupabaseAuth])
|
|
1007
|
+
.middleware([normalizeServerErrors, requireSupabaseAuth])
|
|
1007
1008
|
.inputValidator((data) => profileIdInput.parse(data))
|
|
1008
1009
|
.handler(async ({ context, data }) => {
|
|
1009
1010
|
await requireAdmin(context);
|
|
@@ -1037,7 +1038,7 @@ export const deleteProfile = createServerFn({ method: "POST" })
|
|
|
1037
1038
|
});
|
|
1038
1039
|
/** Zet precies één profiel als actief (is_default). */
|
|
1039
1040
|
export const setActiveProfile = createServerFn({ method: "POST" })
|
|
1040
|
-
.middleware([requireSupabaseAuth])
|
|
1041
|
+
.middleware([normalizeServerErrors, requireSupabaseAuth])
|
|
1041
1042
|
.inputValidator((data) => profileIdInput.parse(data))
|
|
1042
1043
|
.handler(async ({ context, data }) => {
|
|
1043
1044
|
await requireAdmin(context);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zet ruwe `Response`-throws (o.a. uit de auth-middleware) om naar gewone
|
|
3
|
+
* `Error`s. Anders komt er client-side alleen "Error: [object Response]" aan
|
|
4
|
+
* en klapt het scherm om zonder leesbare melding.
|
|
5
|
+
*/
|
|
6
|
+
export declare const normalizeServerErrors: import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, undefined, undefined, undefined, undefined>;
|
|
7
|
+
//# sourceMappingURL=serverErrors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverErrors.d.ts","sourceRoot":"","sources":["../../src/lib/serverErrors.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,yIAsBjC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createMiddleware } from "@tanstack/react-start";
|
|
2
|
+
/**
|
|
3
|
+
* Zet ruwe `Response`-throws (o.a. uit de auth-middleware) om naar gewone
|
|
4
|
+
* `Error`s. Anders komt er client-side alleen "Error: [object Response]" aan
|
|
5
|
+
* en klapt het scherm om zonder leesbare melding.
|
|
6
|
+
*/
|
|
7
|
+
export const normalizeServerErrors = createMiddleware({ type: "function" }).server(async ({ next }) => {
|
|
8
|
+
try {
|
|
9
|
+
return await next();
|
|
10
|
+
}
|
|
11
|
+
catch (err) {
|
|
12
|
+
if (err instanceof Response) {
|
|
13
|
+
let text = "";
|
|
14
|
+
try {
|
|
15
|
+
text = await err.clone().text();
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
/* body niet leesbaar */
|
|
19
|
+
}
|
|
20
|
+
const message = err.status === 401
|
|
21
|
+
? "Je sessie is verlopen. Log opnieuw in en probeer het nog eens."
|
|
22
|
+
: text || `Serverfout (${err.status})`;
|
|
23
|
+
throw new Error(message);
|
|
24
|
+
}
|
|
25
|
+
if (err instanceof Error)
|
|
26
|
+
throw err;
|
|
27
|
+
throw new Error(typeof err === "string" ? err : "Onbekende serverfout");
|
|
28
|
+
}
|
|
29
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowselections/admin-installatietechniek",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"flowselections": {
|
|
5
5
|
"moduleId": "admin-installatietechniek",
|
|
6
6
|
"pages": [
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"lint": "eslint ."
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@flowselections/core": "
|
|
43
|
+
"@flowselections/core": "1.0.18",
|
|
44
44
|
"@tanstack/react-query": "^5.0.0",
|
|
45
45
|
"@tanstack/react-router": "^1.0.0",
|
|
46
46
|
"@tanstack/react-start": "^1.0.0",
|