@frigear-nu/teams 0.0.0-stage → 0.0.0
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/README.md +16 -2
- package/dist/module.d.mts +278 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +134 -0
- package/dist/runtime/access.d.ts +1 -0
- package/dist/runtime/access.js +39 -0
- package/dist/runtime/app/components/TeamFormSlideover.d.vue.ts +13 -0
- package/dist/runtime/app/components/TeamFormSlideover.vue +126 -0
- package/dist/runtime/app/components/TeamFormSlideover.vue.d.ts +13 -0
- package/dist/runtime/app/components/TeamLadderSlideover.d.vue.ts +11 -0
- package/dist/runtime/app/components/TeamLadderSlideover.vue +125 -0
- package/dist/runtime/app/components/TeamLadderSlideover.vue.d.ts +11 -0
- package/dist/runtime/app/components/TeamMappingSlideover.d.vue.ts +15 -0
- package/dist/runtime/app/components/TeamMappingSlideover.vue +134 -0
- package/dist/runtime/app/components/TeamMappingSlideover.vue.d.ts +15 -0
- package/dist/runtime/app/components/TeamMemberSlideover.d.vue.ts +13 -0
- package/dist/runtime/app/components/TeamMemberSlideover.vue +79 -0
- package/dist/runtime/app/components/TeamMemberSlideover.vue.d.ts +13 -0
- package/dist/runtime/app/composables/index.d.ts +6 -0
- package/dist/runtime/app/composables/index.js +5 -0
- package/dist/runtime/app/composables/useTeamActions.d.ts +25 -0
- package/dist/runtime/app/composables/useTeamActions.js +56 -0
- package/dist/runtime/app/composables/useTeamLinks.d.ts +8 -0
- package/dist/runtime/app/composables/useTeamLinks.js +6 -0
- package/dist/runtime/app/composables/useTeamMappingActions.d.ts +20 -0
- package/dist/runtime/app/composables/useTeamMappingActions.js +46 -0
- package/dist/runtime/app/composables/useTeamMemberActions.d.ts +16 -0
- package/dist/runtime/app/composables/useTeamMemberActions.js +47 -0
- package/dist/runtime/app/composables/useTeamsTranslate.d.ts +7 -0
- package/dist/runtime/app/composables/useTeamsTranslate.js +15 -0
- package/dist/runtime/app/dashboard/MyTeams.d.vue.ts +3 -0
- package/dist/runtime/app/dashboard/MyTeams.vue +75 -0
- package/dist/runtime/app/dashboard/MyTeams.vue.d.ts +3 -0
- package/dist/runtime/app/grants/TeamGrantField.d.vue.ts +15 -0
- package/dist/runtime/app/grants/TeamGrantField.vue +120 -0
- package/dist/runtime/app/grants/TeamGrantField.vue.d.ts +15 -0
- package/dist/runtime/app/pages/admin-team.d.vue.ts +3 -0
- package/dist/runtime/app/pages/admin-team.vue +271 -0
- package/dist/runtime/app/pages/admin-team.vue.d.ts +3 -0
- package/dist/runtime/app/pages/admin.d.vue.ts +3 -0
- package/dist/runtime/app/pages/admin.vue +159 -0
- package/dist/runtime/app/pages/admin.vue.d.ts +3 -0
- package/dist/runtime/app/tabs/OwnerTeams.d.vue.ts +9 -0
- package/dist/runtime/app/tabs/OwnerTeams.vue +94 -0
- package/dist/runtime/app/tabs/OwnerTeams.vue.d.ts +9 -0
- package/dist/runtime/app/utils/admin-team.d.ts +27 -0
- package/dist/runtime/app/utils/admin-team.js +13 -0
- package/dist/runtime/dashboard.d.ts +8 -0
- package/dist/runtime/dashboard.js +14 -0
- package/dist/runtime/i18n/lang/da.json +174 -0
- package/dist/runtime/i18n/lang/en.json +174 -0
- package/dist/runtime/menus.d.ts +2 -0
- package/dist/runtime/menus.js +19 -0
- package/dist/runtime/server/candidates.d.ts +34 -0
- package/dist/runtime/server/candidates.js +16 -0
- package/dist/runtime/server/db/schema.postgresql.d.ts +628 -0
- package/dist/runtime/server/db/schema.postgresql.js +66 -0
- package/dist/runtime/server/db/schema.sqlite.d.ts +662 -0
- package/dist/runtime/server/db/schema.sqlite.js +66 -0
- package/dist/runtime/server/grants/team.d.ts +3 -0
- package/dist/runtime/server/grants/team.js +61 -0
- package/dist/runtime/server/plugins/ladders.d.ts +2 -0
- package/dist/runtime/server/plugins/ladders.js +7 -0
- package/dist/runtime/server/plugins/oauth-claims.d.ts +5 -0
- package/dist/runtime/server/plugins/oauth-claims.js +18 -0
- package/dist/runtime/server/plugins/owners.d.ts +2 -0
- package/dist/runtime/server/plugins/owners.js +19 -0
- package/dist/runtime/server/plugins/subscriptions.d.ts +2 -0
- package/dist/runtime/server/plugins/subscriptions.js +23 -0
- package/dist/runtime/server/policies.d.ts +2 -0
- package/dist/runtime/server/policies.js +14 -0
- package/dist/runtime/server/routes/admin/ladder.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/ladder.get.js +9 -0
- package/dist/runtime/server/routes/admin/ladder.put.d.ts +2 -0
- package/dist/runtime/server/routes/admin/ladder.put.js +27 -0
- package/dist/runtime/server/routes/admin/ladders.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/ladders.get.js +5 -0
- package/dist/runtime/server/routes/admin/mapping.delete.d.ts +2 -0
- package/dist/runtime/server/routes/admin/mapping.delete.js +11 -0
- package/dist/runtime/server/routes/admin/mapping.patch.d.ts +2 -0
- package/dist/runtime/server/routes/admin/mapping.patch.js +18 -0
- package/dist/runtime/server/routes/admin/mappings.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/mappings.get.js +22 -0
- package/dist/runtime/server/routes/admin/mappings.post.d.ts +2 -0
- package/dist/runtime/server/routes/admin/mappings.post.js +20 -0
- package/dist/runtime/server/routes/admin/member.delete.d.ts +2 -0
- package/dist/runtime/server/routes/admin/member.delete.js +18 -0
- package/dist/runtime/server/routes/admin/member.patch.d.ts +2 -0
- package/dist/runtime/server/routes/admin/member.patch.js +29 -0
- package/dist/runtime/server/routes/admin/member.post.d.ts +2 -0
- package/dist/runtime/server/routes/admin/member.post.js +18 -0
- package/dist/runtime/server/routes/admin/team.delete.d.ts +2 -0
- package/dist/runtime/server/routes/admin/team.delete.js +10 -0
- package/dist/runtime/server/routes/admin/team.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/team.get.js +9 -0
- package/dist/runtime/server/routes/admin/team.patch.d.ts +2 -0
- package/dist/runtime/server/routes/admin/team.patch.js +10 -0
- package/dist/runtime/server/routes/admin/teams.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/teams.get.js +26 -0
- package/dist/runtime/server/routes/admin/teams.post.d.ts +2 -0
- package/dist/runtime/server/routes/admin/teams.post.js +8 -0
- package/dist/runtime/server/routes/admin/users.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/users.get.js +13 -0
- package/dist/runtime/server/routes/me/teams.get.d.ts +2 -0
- package/dist/runtime/server/routes/me/teams.get.js +14 -0
- package/dist/runtime/server/routes/members.get.d.ts +2 -0
- package/dist/runtime/server/routes/members.get.js +14 -0
- package/dist/runtime/server/routes/team.get.d.ts +2 -0
- package/dist/runtime/server/routes/team.get.js +9 -0
- package/dist/runtime/server/search-index.d.ts +2 -0
- package/dist/runtime/server/search-index.js +7 -0
- package/dist/runtime/server/utils/teams-dto.d.ts +24 -0
- package/dist/runtime/server/utils/teams-dto.js +64 -0
- package/dist/runtime/server/utils/teams-ladders.d.ts +22 -0
- package/dist/runtime/server/utils/teams-ladders.js +53 -0
- package/dist/runtime/server/utils/teams-mappings.d.ts +16 -0
- package/dist/runtime/server/utils/teams-mappings.js +29 -0
- package/dist/runtime/server/utils/teams-roles.d.ts +63 -0
- package/dist/runtime/server/utils/teams-roles.js +242 -0
- package/dist/runtime/server/utils/teams-schemas.d.ts +127 -0
- package/dist/runtime/server/utils/teams-schemas.js +69 -0
- package/dist/runtime/server/utils/teams-search.d.ts +3 -0
- package/dist/runtime/server/utils/teams-search.js +2 -0
- package/dist/runtime/server/utils/teams.d.ts +65 -0
- package/dist/runtime/server/utils/teams.js +140 -0
- package/dist/runtime/utils/api.d.ts +30 -0
- package/dist/runtime/utils/api.js +33 -0
- package/dist/runtime/utils/claims.d.ts +7 -0
- package/dist/runtime/utils/claims.js +14 -0
- package/dist/runtime/utils/grants.d.ts +17 -0
- package/dist/runtime/utils/grants.js +9 -0
- package/dist/runtime/utils/index.d.ts +11 -0
- package/dist/runtime/utils/index.js +9 -0
- package/dist/runtime/utils/ladders.d.ts +22 -0
- package/dist/runtime/utils/ladders.js +43 -0
- package/dist/runtime/utils/links.d.ts +13 -0
- package/dist/runtime/utils/links.js +10 -0
- package/dist/runtime/utils/resolve.d.ts +29 -0
- package/dist/runtime/utils/resolve.js +57 -0
- package/dist/types.d.mts +5 -0
- package/package.json +121 -3
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const teamsTranslated: z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodString>, z.ZodTransform<{
|
|
3
|
+
[k: string]: string;
|
|
4
|
+
}, Record<string, string>>>]>;
|
|
5
|
+
/** A role key, a team kind or an owner type: lower case, as stored. */
|
|
6
|
+
export declare const teamsKey: z.ZodString;
|
|
7
|
+
/** The body of `POST /api/admin/teams`. The owner and kind are fixed once created. */
|
|
8
|
+
export declare const teamInput: z.ZodObject<{
|
|
9
|
+
kind: z.ZodString;
|
|
10
|
+
name: z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodString>, z.ZodTransform<{
|
|
11
|
+
[k: string]: string;
|
|
12
|
+
}, Record<string, string>>>]>;
|
|
13
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodString>, z.ZodTransform<{
|
|
14
|
+
[k: string]: string;
|
|
15
|
+
}, Record<string, string>>>]>>>;
|
|
16
|
+
parentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
17
|
+
capacity: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
18
|
+
sort: z.ZodOptional<z.ZodNumber>;
|
|
19
|
+
ownerType: z.ZodString;
|
|
20
|
+
ownerId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
/** The body of `PATCH /api/admin/teams/:id`: the texts, parent, capacity and sort. */
|
|
23
|
+
export declare const teamPatchSchema: z.ZodObject<{
|
|
24
|
+
sort: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
|
|
25
|
+
name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodString>, z.ZodTransform<{
|
|
26
|
+
[k: string]: string;
|
|
27
|
+
}, Record<string, string>>>]>>;
|
|
28
|
+
description: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodString>, z.ZodTransform<{
|
|
29
|
+
[k: string]: string;
|
|
30
|
+
}, Record<string, string>>>]>>>>;
|
|
31
|
+
parentId: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
32
|
+
capacity: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodNumber>>>;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
/** The body of `POST /api/admin/teams/:id/members`. */
|
|
35
|
+
export declare const teamMemberInput: z.ZodObject<{
|
|
36
|
+
userId: z.ZodNumber;
|
|
37
|
+
role: z.ZodString;
|
|
38
|
+
status: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
/** The body of `PATCH /api/admin/teams/:id/members/:userId`. */
|
|
41
|
+
export declare const teamMemberPatchSchema: z.ZodObject<{
|
|
42
|
+
role: z.ZodOptional<z.ZodString>;
|
|
43
|
+
status: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
44
|
+
}, z.core.$strip>;
|
|
45
|
+
/** What a rule matches: exactly one of `role` (a global role) or `plan` (a subscription plan key). Unknown keys fail. */
|
|
46
|
+
export declare const teamRoleMatchSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
47
|
+
role: z.ZodString;
|
|
48
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
49
|
+
plan: z.ZodString;
|
|
50
|
+
}, z.core.$strict>]>;
|
|
51
|
+
/** The body of `POST /api/admin/teams/mappings`. */
|
|
52
|
+
export declare const teamMappingInput: z.ZodObject<{
|
|
53
|
+
teamId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
54
|
+
match: z.ZodUnion<readonly [z.ZodObject<{
|
|
55
|
+
role: z.ZodString;
|
|
56
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
57
|
+
plan: z.ZodString;
|
|
58
|
+
}, z.core.$strict>]>;
|
|
59
|
+
teamRole: z.ZodString;
|
|
60
|
+
priority: z.ZodOptional<z.ZodNumber>;
|
|
61
|
+
ownerType: z.ZodString;
|
|
62
|
+
ownerId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
63
|
+
}, z.core.$strip>;
|
|
64
|
+
/** The body of `PATCH /api/admin/teams/mappings/:id`: the owner is fixed; the rest may change. */
|
|
65
|
+
export declare const teamMappingPatchSchema: z.ZodObject<{
|
|
66
|
+
priority: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
|
|
67
|
+
match: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
|
|
68
|
+
role: z.ZodString;
|
|
69
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
70
|
+
plan: z.ZodString;
|
|
71
|
+
}, z.core.$strict>]>>;
|
|
72
|
+
teamId: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
73
|
+
teamRole: z.ZodOptional<z.ZodString>;
|
|
74
|
+
}, z.core.$strip>;
|
|
75
|
+
/** The query of `GET /api/admin/teams/mappings`. */
|
|
76
|
+
export declare const teamMappingQuery: z.ZodObject<{
|
|
77
|
+
ownerType: z.ZodOptional<z.ZodString>;
|
|
78
|
+
ownerId: z.ZodOptional<z.ZodString>;
|
|
79
|
+
teamId: z.ZodOptional<z.ZodString>;
|
|
80
|
+
}, z.core.$strip>;
|
|
81
|
+
/** The body of `PUT /api/admin/teams/ladders/:kind`: every role, lowest first, and the lowest lead role. */
|
|
82
|
+
export declare const teamLadderInput: z.ZodObject<{
|
|
83
|
+
roles: z.ZodArray<z.ZodObject<{
|
|
84
|
+
key: z.ZodString;
|
|
85
|
+
label: z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodString>, z.ZodTransform<{
|
|
86
|
+
[k: string]: string;
|
|
87
|
+
}, Record<string, string>>>]>;
|
|
88
|
+
}, z.core.$strip>>;
|
|
89
|
+
leadFrom: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
90
|
+
}, z.core.$strip>;
|
|
91
|
+
/** The router params of the ladder routes. */
|
|
92
|
+
export declare const teamLadderParams: z.ZodObject<{
|
|
93
|
+
kind: z.ZodString;
|
|
94
|
+
}, z.core.$strip>;
|
|
95
|
+
/** The router params of the member routes. */
|
|
96
|
+
export declare const teamMemberParams: z.ZodObject<{
|
|
97
|
+
id: z.ZodString;
|
|
98
|
+
userId: z.ZodCoercedNumber<unknown>;
|
|
99
|
+
}, z.core.$strip>;
|
|
100
|
+
/** The query of `GET /api/teams/:id/members`. */
|
|
101
|
+
export declare const teamMembersQuery: z.ZodObject<{
|
|
102
|
+
include: z.ZodOptional<z.ZodEnum<{
|
|
103
|
+
mapped: "mapped";
|
|
104
|
+
}>>;
|
|
105
|
+
}, z.core.$strip>;
|
|
106
|
+
/** The query of the staff user lookup. */
|
|
107
|
+
export declare const teamUserLookupQuery: z.ZodObject<{
|
|
108
|
+
q: z.ZodString;
|
|
109
|
+
}, z.core.$strip>;
|
|
110
|
+
/** The query of `GET /api/admin/teams`. */
|
|
111
|
+
export declare const teamListQuery: z.ZodObject<{
|
|
112
|
+
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
113
|
+
pageSize: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
114
|
+
q: z.ZodOptional<z.ZodString>;
|
|
115
|
+
sort: z.ZodDefault<z.ZodEnum<{
|
|
116
|
+
sort: "sort";
|
|
117
|
+
kind: "kind";
|
|
118
|
+
createdAt: "createdAt";
|
|
119
|
+
}>>;
|
|
120
|
+
order: z.ZodDefault<z.ZodEnum<{
|
|
121
|
+
asc: "asc";
|
|
122
|
+
desc: "desc";
|
|
123
|
+
}>>;
|
|
124
|
+
ownerType: z.ZodOptional<z.ZodString>;
|
|
125
|
+
ownerId: z.ZodOptional<z.ZodString>;
|
|
126
|
+
kind: z.ZodOptional<z.ZodString>;
|
|
127
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { pageQuery } from "@frigear-nu/module-kit/server";
|
|
3
|
+
import { TEAM_KEY_PATTERN, teamLadderIssues } from "../../utils/ladders.js";
|
|
4
|
+
export const teamsTranslated = z.union([
|
|
5
|
+
z.string().trim().min(1).max(500),
|
|
6
|
+
z.record(z.string(), z.string().max(500)).transform((value) => Object.fromEntries(Object.entries(value).filter(([, text]) => text.trim()))).refine((value) => Object.keys(value).length > 0, "Add a text in at least one language.")
|
|
7
|
+
]);
|
|
8
|
+
export const teamsKey = z.string().trim().min(1).max(64).regex(TEAM_KEY_PATTERN, "Use lower case letters, digits, - and _.");
|
|
9
|
+
const ownerFields = {
|
|
10
|
+
ownerType: teamsKey,
|
|
11
|
+
/** `null` (or left out) for the platform; required for any other owner type. */
|
|
12
|
+
ownerId: z.string().trim().min(1).max(128).nullish()
|
|
13
|
+
};
|
|
14
|
+
export const teamInput = z.object({
|
|
15
|
+
...ownerFields,
|
|
16
|
+
kind: teamsKey,
|
|
17
|
+
name: teamsTranslated,
|
|
18
|
+
description: teamsTranslated.nullish(),
|
|
19
|
+
parentId: z.string().trim().min(1).max(64).nullish(),
|
|
20
|
+
capacity: z.number().int().min(0).max(1e5).nullish(),
|
|
21
|
+
sort: z.number().int().min(-1e5).max(1e5).optional()
|
|
22
|
+
});
|
|
23
|
+
export const teamPatchSchema = teamInput.pick({ name: true, description: true, parentId: true, capacity: true, sort: true }).partial();
|
|
24
|
+
export const teamMemberInput = z.object({
|
|
25
|
+
userId: z.number().int().positive(),
|
|
26
|
+
role: teamsKey,
|
|
27
|
+
status: z.string().trim().min(1).max(64).nullish()
|
|
28
|
+
});
|
|
29
|
+
export const teamMemberPatchSchema = teamMemberInput.pick({ role: true, status: true }).partial();
|
|
30
|
+
export const teamRoleMatchSchema = z.union([
|
|
31
|
+
z.strictObject({ role: z.string().trim().min(1).max(64) }),
|
|
32
|
+
z.strictObject({ plan: z.string().trim().min(1).max(128) })
|
|
33
|
+
]);
|
|
34
|
+
export const teamMappingInput = z.object({
|
|
35
|
+
...ownerFields,
|
|
36
|
+
teamId: z.string().trim().min(1).max(64).nullish(),
|
|
37
|
+
match: teamRoleMatchSchema,
|
|
38
|
+
teamRole: teamsKey,
|
|
39
|
+
priority: z.number().int().min(-1e3).max(1e3).optional()
|
|
40
|
+
});
|
|
41
|
+
export const teamMappingPatchSchema = teamMappingInput.pick({ teamId: true, match: true, teamRole: true, priority: true }).partial();
|
|
42
|
+
export const teamMappingQuery = z.object({
|
|
43
|
+
ownerType: teamsKey.optional(),
|
|
44
|
+
ownerId: z.string().trim().min(1).max(128).optional(),
|
|
45
|
+
teamId: z.string().trim().min(1).max(64).optional()
|
|
46
|
+
});
|
|
47
|
+
export const teamLadderInput = z.object({
|
|
48
|
+
roles: z.array(z.object({ key: teamsKey, label: teamsTranslated })).min(1).max(30),
|
|
49
|
+
leadFrom: teamsKey.nullish()
|
|
50
|
+
}).superRefine((value, ctx) => {
|
|
51
|
+
for (const message of teamLadderIssues(value)) ctx.addIssue({ code: "custom", message, path: ["roles"] });
|
|
52
|
+
});
|
|
53
|
+
export const teamLadderParams = z.object({ kind: teamsKey });
|
|
54
|
+
export const teamMemberParams = z.object({
|
|
55
|
+
id: z.string().trim().min(1),
|
|
56
|
+
userId: z.coerce.number().int().positive()
|
|
57
|
+
});
|
|
58
|
+
export const teamMembersQuery = z.object({ include: z.enum(["mapped"]).optional() });
|
|
59
|
+
export const teamUserLookupQuery = z.object({ q: z.string().trim().min(1).max(200) });
|
|
60
|
+
export const teamListQuery = pageQuery({
|
|
61
|
+
sort: ["sort", "createdAt", "kind"],
|
|
62
|
+
defaultSort: "sort",
|
|
63
|
+
defaultOrder: "asc",
|
|
64
|
+
filters: {
|
|
65
|
+
ownerType: teamsKey.optional(),
|
|
66
|
+
ownerId: z.string().trim().min(1).max(128).optional(),
|
|
67
|
+
kind: teamsKey.optional()
|
|
68
|
+
}
|
|
69
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { H3Event } from 'h3';
|
|
2
|
+
import { schema } from '@nuxthub/db';
|
|
3
|
+
import type { z } from 'zod';
|
|
4
|
+
import type { AdminTeamDto, OwnerRef, TeamMemberDto, TeamOwner, Translated } from '../../../types.js';
|
|
5
|
+
import type { teamInput, teamPatchSchema } from './teams-schemas.js';
|
|
6
|
+
export type TeamRow = typeof schema.teams.$inferSelect;
|
|
7
|
+
export type TeamMemberRow = typeof schema.teamMembers.$inferSelect;
|
|
8
|
+
type TeamInput = z.output<typeof teamInput>;
|
|
9
|
+
type TeamPatch = z.output<typeof teamPatchSchema>;
|
|
10
|
+
/** The row with this id, or `undefined`. */
|
|
11
|
+
export declare function findTeamById(id: string): Promise<TeamRow | undefined>;
|
|
12
|
+
/** The row with this id, or a 404. */
|
|
13
|
+
export declare function getTeamOr404(id: string): Promise<TeamRow>;
|
|
14
|
+
/** The membership of `userId` on `teamId`, or `undefined`. */
|
|
15
|
+
export declare function findTeamMember(teamId: string, userId: number): Promise<TeamMemberRow | undefined>;
|
|
16
|
+
/** The membership of `userId` on `teamId`, or a 404. */
|
|
17
|
+
export declare function getTeamMemberOr404(teamId: string, userId: number): Promise<TeamMemberRow>;
|
|
18
|
+
/**
|
|
19
|
+
* An owner's label and whether it exists, through `teams:owner:resolve` (teams answers `team` and `operation`). Both
|
|
20
|
+
* stay `null` for an owner type nobody answers. It answers nothing about access. Other modules that store
|
|
21
|
+
* `ownerType` / `ownerId` call it to validate their owners.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveTeamsOwner(event: H3Event | undefined, owner: OwnerRef): Promise<{
|
|
24
|
+
label: Translated | null;
|
|
25
|
+
exists: boolean | null;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Checks an owner and returns its label: the platform has no id (`ownerId: null`), every other owner must exist
|
|
29
|
+
* according to `teams:owner:resolve` (operations answers `operation`, teams answers `team`). An owner type nobody
|
|
30
|
+
* answers for, or an id that does not exist, is a 400.
|
|
31
|
+
*/
|
|
32
|
+
export declare function assertTeamsOwner(event: H3Event, owner: TeamOwner): Promise<Translated | null>;
|
|
33
|
+
/** The owners' labels, each owner resolved once (`null` for the platform and for owners nobody answers for). */
|
|
34
|
+
export declare function teamsOwnerLabels(event: H3Event, owners: TeamOwner[]): Promise<Map<string, Translated | null>>;
|
|
35
|
+
export declare const teamsOwnerKey: (owner: TeamOwner) => string;
|
|
36
|
+
/** The number of explicit members per team. */
|
|
37
|
+
export declare function teamMemberCounts(teamIds: string[]): Promise<Map<string, number>>;
|
|
38
|
+
/** The staff DTOs of rows, with their owners' labels and member counts. */
|
|
39
|
+
export declare function toAdminTeamDtos(event: H3Event, rows: TeamRow[]): Promise<AdminTeamDto[]>;
|
|
40
|
+
/** The staff DTO of one row. */
|
|
41
|
+
export declare function toAdminTeamDtoOf(event: H3Event, row: TeamRow): Promise<AdminTeamDto>;
|
|
42
|
+
/** Inserts a team after the owner, kind and parent checks. */
|
|
43
|
+
export declare function createTeamRow(event: H3Event, input: TeamInput): Promise<TeamRow>;
|
|
44
|
+
/** Applies a partial update; returns the updated row (the stored one when nothing changed). */
|
|
45
|
+
export declare function patchTeamRow(existing: TeamRow, patch: TeamPatch): Promise<TeamRow>;
|
|
46
|
+
/**
|
|
47
|
+
* Deletes a team: its memberships and its own rules go with it (`onDelete: 'cascade'` on both foreign keys), its
|
|
48
|
+
* sub-teams lose their parent (`parentId` has no foreign key).
|
|
49
|
+
*/
|
|
50
|
+
export declare function deleteTeamRow(id: string): Promise<void>;
|
|
51
|
+
/** Adds a membership; 409 when the user is a member already (the unique index decides between racing requests). */
|
|
52
|
+
export declare function insertTeamMemberRow(values: {
|
|
53
|
+
teamId: string;
|
|
54
|
+
userId: number;
|
|
55
|
+
role: string;
|
|
56
|
+
status: string | null;
|
|
57
|
+
addedBy: number | null;
|
|
58
|
+
}): Promise<TeamMemberRow>;
|
|
59
|
+
/** The DTO of one membership row, with the user's name and avatar (and email with `pii`). */
|
|
60
|
+
export declare function teamMemberDtoOf(row: TeamMemberRow, pii: boolean): Promise<TeamMemberDto>;
|
|
61
|
+
/** The member without the email, for a caller without `teams:pii`. */
|
|
62
|
+
export declare function withoutTeamsEmail(member: TeamMemberDto): TeamMemberDto;
|
|
63
|
+
/** 400 when no user has this id. */
|
|
64
|
+
export declare function assertTeamsUserExists(userId: number, field?: string): Promise<void>;
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { db, schema } from "@nuxthub/db";
|
|
2
|
+
import { and, count, eq, inArray } from "drizzle-orm";
|
|
3
|
+
import { conflict, isUniqueViolation, notFound, validationError } from "@frigear-nu/module-kit/server";
|
|
4
|
+
import { newId } from "../../utils/index.js";
|
|
5
|
+
import { sameTeamOwner } from "../../utils/resolve.js";
|
|
6
|
+
import { toAdminTeamDto, toTeamMemberDto } from "./teams-dto.js";
|
|
7
|
+
import { getTeamLadderOr400 } from "./teams-ladders.js";
|
|
8
|
+
import { teamSearchText } from "./teams-search.js";
|
|
9
|
+
export async function findTeamById(id) {
|
|
10
|
+
const [row] = await db.select().from(schema.teams).where(eq(schema.teams.id, id)).limit(1);
|
|
11
|
+
return row;
|
|
12
|
+
}
|
|
13
|
+
export async function getTeamOr404(id) {
|
|
14
|
+
const row = await findTeamById(id);
|
|
15
|
+
if (!row) throw notFound("Team not found.");
|
|
16
|
+
return row;
|
|
17
|
+
}
|
|
18
|
+
export async function findTeamMember(teamId, userId) {
|
|
19
|
+
const [row] = await db.select().from(schema.teamMembers).where(and(eq(schema.teamMembers.teamId, teamId), eq(schema.teamMembers.userId, userId))).limit(1);
|
|
20
|
+
return row;
|
|
21
|
+
}
|
|
22
|
+
export async function getTeamMemberOr404(teamId, userId) {
|
|
23
|
+
const row = await findTeamMember(teamId, userId);
|
|
24
|
+
if (!row) throw notFound("This user is not a member of the team.");
|
|
25
|
+
return row;
|
|
26
|
+
}
|
|
27
|
+
export async function resolveTeamsOwner(event, owner) {
|
|
28
|
+
const ctx = { event, owner: { ...owner }, label: null, exists: null };
|
|
29
|
+
await useNitroApp().hooks.callHook("teams:owner:resolve", ctx);
|
|
30
|
+
return { label: ctx.label, exists: ctx.exists };
|
|
31
|
+
}
|
|
32
|
+
export async function assertTeamsOwner(event, owner) {
|
|
33
|
+
if (owner.ownerType === "platform") {
|
|
34
|
+
if (owner.ownerId) throw validationError([{ path: ["ownerId"], message: "A platform-owned record has no owner id." }], "Unknown owner");
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
if (!owner.ownerId) throw validationError([{ path: ["ownerId"], message: "Choose the owner." }], "Unknown owner");
|
|
38
|
+
const resolved = await resolveTeamsOwner(event, { type: owner.ownerType, id: owner.ownerId });
|
|
39
|
+
if (resolved.exists !== true) {
|
|
40
|
+
throw validationError([{ path: ["ownerId"], message: resolved.exists === false ? "This owner does not exist." : `No installed module knows the owner type "${owner.ownerType}".` }], "Unknown owner");
|
|
41
|
+
}
|
|
42
|
+
return resolved.label;
|
|
43
|
+
}
|
|
44
|
+
export async function teamsOwnerLabels(event, owners) {
|
|
45
|
+
const labels = /* @__PURE__ */ new Map();
|
|
46
|
+
for (const owner of owners) {
|
|
47
|
+
const key = teamsOwnerKey(owner);
|
|
48
|
+
if (labels.has(key)) continue;
|
|
49
|
+
if (owner.ownerType === "platform" || !owner.ownerId) {
|
|
50
|
+
labels.set(key, null);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const resolved = await resolveTeamsOwner(event, { type: owner.ownerType, id: owner.ownerId });
|
|
54
|
+
labels.set(key, resolved.label);
|
|
55
|
+
}
|
|
56
|
+
return labels;
|
|
57
|
+
}
|
|
58
|
+
export const teamsOwnerKey = (owner) => `${owner.ownerType}\0${owner.ownerId ?? ""}`;
|
|
59
|
+
export async function teamMemberCounts(teamIds) {
|
|
60
|
+
if (!teamIds.length) return /* @__PURE__ */ new Map();
|
|
61
|
+
const rows = await db.select({ teamId: schema.teamMembers.teamId, total: count() }).from(schema.teamMembers).where(inArray(schema.teamMembers.teamId, teamIds)).groupBy(schema.teamMembers.teamId);
|
|
62
|
+
return new Map(rows.map((row) => [row.teamId, Number(row.total)]));
|
|
63
|
+
}
|
|
64
|
+
export async function toAdminTeamDtos(event, rows) {
|
|
65
|
+
const [labels, counts] = await Promise.all([
|
|
66
|
+
teamsOwnerLabels(event, rows.map((row) => ({ ownerType: row.ownerType, ownerId: row.ownerId ?? null }))),
|
|
67
|
+
teamMemberCounts(rows.map((row) => row.id))
|
|
68
|
+
]);
|
|
69
|
+
return rows.map((row) => toAdminTeamDto(row, {
|
|
70
|
+
ownerLabel: labels.get(teamsOwnerKey({ ownerType: row.ownerType, ownerId: row.ownerId ?? null })) ?? null,
|
|
71
|
+
memberCount: counts.get(row.id) ?? 0
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
export async function toAdminTeamDtoOf(event, row) {
|
|
75
|
+
return (await toAdminTeamDtos(event, [row]))[0];
|
|
76
|
+
}
|
|
77
|
+
async function assertTeamParent(parentId, owner, selfId) {
|
|
78
|
+
if (!parentId) return;
|
|
79
|
+
const parent = parentId === selfId ? void 0 : await findTeamById(parentId);
|
|
80
|
+
if (!parent || !sameTeamOwner({ ownerType: parent.ownerType, ownerId: parent.ownerId ?? null }, owner)) {
|
|
81
|
+
throw validationError([{ path: ["parentId"], message: "The parent must be another team of the same owner." }], "Unknown parent team");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export async function createTeamRow(event, input) {
|
|
85
|
+
const owner = { ownerType: input.ownerType, ownerId: input.ownerId ?? null };
|
|
86
|
+
await assertTeamsOwner(event, owner);
|
|
87
|
+
await getTeamLadderOr400(event, input.kind);
|
|
88
|
+
await assertTeamParent(input.parentId, owner);
|
|
89
|
+
const [row] = await db.insert(schema.teams).values({
|
|
90
|
+
id: newId("tem"),
|
|
91
|
+
ownerType: owner.ownerType,
|
|
92
|
+
ownerId: owner.ownerId,
|
|
93
|
+
parentId: input.parentId ?? null,
|
|
94
|
+
kind: input.kind,
|
|
95
|
+
name: input.name,
|
|
96
|
+
searchText: teamSearchText(input.name),
|
|
97
|
+
description: input.description ?? null,
|
|
98
|
+
capacity: input.capacity ?? null,
|
|
99
|
+
sort: input.sort ?? 0
|
|
100
|
+
}).returning();
|
|
101
|
+
return row;
|
|
102
|
+
}
|
|
103
|
+
export async function patchTeamRow(existing, patch) {
|
|
104
|
+
if (patch.parentId !== void 0) await assertTeamParent(patch.parentId, { ownerType: existing.ownerType, ownerId: existing.ownerId ?? null }, existing.id);
|
|
105
|
+
const values = {};
|
|
106
|
+
if (patch.name !== void 0) {
|
|
107
|
+
values.name = patch.name;
|
|
108
|
+
values.searchText = teamSearchText(patch.name);
|
|
109
|
+
}
|
|
110
|
+
if (patch.description !== void 0) values.description = patch.description;
|
|
111
|
+
if (patch.parentId !== void 0) values.parentId = patch.parentId;
|
|
112
|
+
if (patch.capacity !== void 0) values.capacity = patch.capacity;
|
|
113
|
+
if (patch.sort !== void 0) values.sort = patch.sort;
|
|
114
|
+
if (!Object.keys(values).length) return existing;
|
|
115
|
+
const [row] = await db.update(schema.teams).set(values).where(eq(schema.teams.id, existing.id)).returning();
|
|
116
|
+
return row;
|
|
117
|
+
}
|
|
118
|
+
export async function deleteTeamRow(id) {
|
|
119
|
+
await db.update(schema.teams).set({ parentId: null }).where(eq(schema.teams.parentId, id));
|
|
120
|
+
await db.delete(schema.teams).where(eq(schema.teams.id, id));
|
|
121
|
+
}
|
|
122
|
+
export async function insertTeamMemberRow(values) {
|
|
123
|
+
if (await findTeamMember(values.teamId, values.userId)) throw conflict("This user is a member of the team already.", { field: "userId" });
|
|
124
|
+
const [row] = await db.insert(schema.teamMembers).values({ id: newId("tmm"), ...values }).returning().catch((error) => {
|
|
125
|
+
if (isUniqueViolation(error)) throw conflict("This user is a member of the team already.", { field: "userId" });
|
|
126
|
+
throw error;
|
|
127
|
+
});
|
|
128
|
+
return row;
|
|
129
|
+
}
|
|
130
|
+
export async function teamMemberDtoOf(row, pii) {
|
|
131
|
+
const user = (await loadUserRefs([row.userId])).get(row.userId);
|
|
132
|
+
return toTeamMemberDto(row, user, pii);
|
|
133
|
+
}
|
|
134
|
+
export function withoutTeamsEmail(member) {
|
|
135
|
+
const { email: _email, ...rest } = member;
|
|
136
|
+
return rest;
|
|
137
|
+
}
|
|
138
|
+
export async function assertTeamsUserExists(userId, field = "userId") {
|
|
139
|
+
if (!(await loadUserRefs([userId])).has(userId)) throw validationError([{ path: [field], message: "This user does not exist." }], "Unknown user");
|
|
140
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export declare const teamsApi: {
|
|
2
|
+
readonly me: {
|
|
3
|
+
/** `GET` the caller's team roles on every owner, explicit and mapped (`source`). */
|
|
4
|
+
readonly teams: "/api/teams/me";
|
|
5
|
+
};
|
|
6
|
+
/** `GET` one team the caller belongs to (or manages). */
|
|
7
|
+
readonly team: (id: string) => string;
|
|
8
|
+
/** `GET` a team's members: names, emails only with `teams:pii`; `?include=mapped` adds the mapped members. */
|
|
9
|
+
readonly members: (id: string) => string;
|
|
10
|
+
readonly admin: {
|
|
11
|
+
/** `GET` (paginated, `?ownerType&ownerId&kind&q`) / `POST` teams. */
|
|
12
|
+
readonly teams: "/api/admin/teams";
|
|
13
|
+
/** `GET` / `PATCH` / `DELETE` one team. */
|
|
14
|
+
readonly team: (id: string) => string;
|
|
15
|
+
/** `POST` `{ userId, role, status? }` to add a member. */
|
|
16
|
+
readonly members: (id: string) => string;
|
|
17
|
+
/** `PATCH` `{ role?, status? }` / `DELETE` one member, by user id. */
|
|
18
|
+
readonly member: (id: string, userId: number | string) => string;
|
|
19
|
+
/** `GET` (`?ownerType&ownerId&teamId`) / `POST` role mapping rules. */
|
|
20
|
+
readonly mappings: "/api/admin/teams/mappings";
|
|
21
|
+
/** `PATCH` / `DELETE` one mapping rule. */
|
|
22
|
+
readonly mapping: (id: string) => string;
|
|
23
|
+
/** `GET` every ladder (stored and default). */
|
|
24
|
+
readonly ladders: "/api/admin/teams/ladders";
|
|
25
|
+
/** `GET` / `PUT` `{ roles, leadFrom }` the ladder of a team kind. */
|
|
26
|
+
readonly ladder: (kind: string) => string;
|
|
27
|
+
/** `GET` `?q=` users by name or email, to add as members (emails only with `teams:pii`). */
|
|
28
|
+
readonly users: "/api/admin/teams/users";
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const enc = encodeURIComponent;
|
|
2
|
+
const BASE = "/api/teams";
|
|
3
|
+
const ADMIN_BASE = "/api/admin/teams";
|
|
4
|
+
export const teamsApi = {
|
|
5
|
+
me: {
|
|
6
|
+
/** `GET` the caller's team roles on every owner, explicit and mapped (`source`). */
|
|
7
|
+
teams: `${BASE}/me`
|
|
8
|
+
},
|
|
9
|
+
/** `GET` one team the caller belongs to (or manages). */
|
|
10
|
+
team: (id) => `${BASE}/${enc(id)}`,
|
|
11
|
+
/** `GET` a team's members: names, emails only with `teams:pii`; `?include=mapped` adds the mapped members. */
|
|
12
|
+
members: (id) => `${BASE}/${enc(id)}/members`,
|
|
13
|
+
admin: {
|
|
14
|
+
/** `GET` (paginated, `?ownerType&ownerId&kind&q`) / `POST` teams. */
|
|
15
|
+
teams: ADMIN_BASE,
|
|
16
|
+
/** `GET` / `PATCH` / `DELETE` one team. */
|
|
17
|
+
team: (id) => `${ADMIN_BASE}/${enc(id)}`,
|
|
18
|
+
/** `POST` `{ userId, role, status? }` to add a member. */
|
|
19
|
+
members: (id) => `${ADMIN_BASE}/${enc(id)}/members`,
|
|
20
|
+
/** `PATCH` `{ role?, status? }` / `DELETE` one member, by user id. */
|
|
21
|
+
member: (id, userId) => `${ADMIN_BASE}/${enc(id)}/members/${enc(String(userId))}`,
|
|
22
|
+
/** `GET` (`?ownerType&ownerId&teamId`) / `POST` role mapping rules. */
|
|
23
|
+
mappings: `${ADMIN_BASE}/mappings`,
|
|
24
|
+
/** `PATCH` / `DELETE` one mapping rule. */
|
|
25
|
+
mapping: (id) => `${ADMIN_BASE}/mappings/${enc(id)}`,
|
|
26
|
+
/** `GET` every ladder (stored and default). */
|
|
27
|
+
ladders: `${ADMIN_BASE}/ladders`,
|
|
28
|
+
/** `GET` / `PUT` `{ roles, leadFrom }` the ladder of a team kind. */
|
|
29
|
+
ladder: (kind) => `${ADMIN_BASE}/ladders/${enc(kind)}`,
|
|
30
|
+
/** `GET` `?q=` users by name or email, to add as members (emails only with `teams:pii`). */
|
|
31
|
+
users: `${ADMIN_BASE}/users`
|
|
32
|
+
}
|
|
33
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TeamRoleGrant, TeamsClaimEntry } from '../../types.js';
|
|
2
|
+
/** The scopes that let an OAuth application see the `teams` claim: the named scope `teams`, or `teams:read` itself. */
|
|
3
|
+
export declare const TEAMS_CLAIM_SCOPES: readonly ["teams", "teams:read"];
|
|
4
|
+
/** Whether the granted scopes include one of {@link TEAMS_CLAIM_SCOPES}. */
|
|
5
|
+
export declare function scopeAllowsTeamsClaim(scope: readonly string[]): boolean;
|
|
6
|
+
/** The `teams` claim: one entry per grant, the team id as `id`. */
|
|
7
|
+
export declare function teamsClaim(grants: readonly TeamRoleGrant[]): TeamsClaimEntry[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const TEAMS_CLAIM_SCOPES = ["teams", "teams:read"];
|
|
2
|
+
export function scopeAllowsTeamsClaim(scope) {
|
|
3
|
+
return scope.some((item) => TEAMS_CLAIM_SCOPES.includes(item));
|
|
4
|
+
}
|
|
5
|
+
export function teamsClaim(grants) {
|
|
6
|
+
return grants.map((grant) => ({
|
|
7
|
+
id: grant.teamId,
|
|
8
|
+
ownerType: grant.ownerType,
|
|
9
|
+
ownerId: grant.ownerId ?? null,
|
|
10
|
+
kind: grant.kind,
|
|
11
|
+
role: grant.role,
|
|
12
|
+
source: grant.source
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { TeamGrant, TeamKindGrant } from '../../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* A `team` grant: `{ kind: 'team', teamId, minRole }` for one team, or `{ kind: 'team', teamKind, minRole }` for every
|
|
5
|
+
* team of a kind. Exactly one of `teamId` and `teamKind`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const teamGrantSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
8
|
+
kind: z.ZodLiteral<"team">;
|
|
9
|
+
teamId: z.ZodString;
|
|
10
|
+
minRole: z.ZodString;
|
|
11
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
12
|
+
kind: z.ZodLiteral<"team">;
|
|
13
|
+
teamKind: z.ZodString;
|
|
14
|
+
minRole: z.ZodString;
|
|
15
|
+
}, z.core.$strict>]>;
|
|
16
|
+
/** Whether the grant names every team of a kind rather than one team. */
|
|
17
|
+
export declare function isTeamKindGrant(grant: TeamGrant): grant is TeamKindGrant;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const teamRoleKey = z.string().trim().min(1).max(64);
|
|
3
|
+
export const teamGrantSchema = z.union([
|
|
4
|
+
z.strictObject({ kind: z.literal("team"), teamId: z.string().trim().min(1).max(64), minRole: teamRoleKey }),
|
|
5
|
+
z.strictObject({ kind: z.literal("team"), teamKind: z.string().trim().min(1).max(64), minRole: teamRoleKey })
|
|
6
|
+
]);
|
|
7
|
+
export function isTeamKindGrant(grant) {
|
|
8
|
+
return "teamKind" in grant;
|
|
9
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { translate } from '@frigear-nu/ui/translated';
|
|
2
|
+
export { translate };
|
|
3
|
+
export * from './api.js';
|
|
4
|
+
export * from './claims.js';
|
|
5
|
+
export * from './grants.js';
|
|
6
|
+
export * from './ladders.js';
|
|
7
|
+
export * from './links.js';
|
|
8
|
+
export * from './resolve.js';
|
|
9
|
+
export type { AdminTeamDto, ModuleOptions, MyTeamDto, OwnerRef, OwnerType, TeamDto, TeamGrant, TeamIdGrant, TeamKindGrant, TeamLadder, TeamLadderDto, TeamLadderRole, TeamMemberContext, TeamMemberDto, TeamMemberRoleChangedContext, TeamOwner, TeamRoleGrant, TeamRoleMappingDto, TeamRoleMatch, TeamsClaimEntry, TeamsMappedGrant, TeamsMembersCandidatesContext, TeamsOwnerResolveContext, TeamsResolverTeam, TeamsRolesResolveContext, TeamUserLookupDto, Translated, } from '../../types.js';
|
|
10
|
+
/** Random, prefixed id (`<prefix>_<32 hex>`): the one of `@frigear-nu/module-kit/id`. */
|
|
11
|
+
export { newId } from '@frigear-nu/module-kit/id';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { translate } from "@frigear-nu/ui/translated";
|
|
2
|
+
export { translate };
|
|
3
|
+
export * from "./api.js";
|
|
4
|
+
export * from "./claims.js";
|
|
5
|
+
export * from "./grants.js";
|
|
6
|
+
export * from "./ladders.js";
|
|
7
|
+
export * from "./links.js";
|
|
8
|
+
export * from "./resolve.js";
|
|
9
|
+
export { newId } from "@frigear-nu/module-kit/id";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TeamLadder } from '../../types.js';
|
|
2
|
+
/** Role keys and team kinds: lower case letters, digits, `-` and `_`, starting with a letter or digit. */
|
|
3
|
+
export declare const TEAM_KEY_PATTERN: RegExp;
|
|
4
|
+
/** The kind of the one ladder the module ships, and of a new team unless the app picks another. */
|
|
5
|
+
export declare const DEFAULT_TEAM_KIND = "default";
|
|
6
|
+
/**
|
|
7
|
+
* The ladder the module ships: one generic `default` kind, `member` then `lead`, led from `lead`. An app adds its own
|
|
8
|
+
* kinds and ladders with the module option `ladders`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const DEFAULT_TEAM_LADDERS: Readonly<Record<string, TeamLadder>>;
|
|
11
|
+
/** The ordered role keys of a ladder, lowest first. */
|
|
12
|
+
export declare function ladderKeys(ladder: TeamLadder | undefined): string[];
|
|
13
|
+
/** The position of `role` on the ladder (0 = lowest), or `-1` when it is not on it. */
|
|
14
|
+
export declare function teamRoleRank(keys: readonly string[] | undefined, role: string): number;
|
|
15
|
+
/** Whether `held` is at or above `min` on the ladder (role keys, lowest first). A role missing from it fails closed. */
|
|
16
|
+
export declare function roleAtLeast(keys: readonly string[] | undefined, held: string, min: string): boolean;
|
|
17
|
+
/** Whether `role` is at or above `leadFrom` on the ladder. `false` without a `leadFrom` or for an unknown role. */
|
|
18
|
+
export declare function isLeadRole(keys: readonly string[] | undefined, role: string, leadFrom: string | null | undefined): boolean;
|
|
19
|
+
/** The problems of a ladder definition (empty when it is valid): keys well formed and unique, `leadFrom` on it. */
|
|
20
|
+
export declare function teamLadderIssues(ladder: TeamLadder): string[];
|
|
21
|
+
/** The default ladders merged with the module option `ladders` (a kind in the option replaces the default one). */
|
|
22
|
+
export declare function mergeTeamLadders(option: Record<string, TeamLadder> | undefined): Record<string, TeamLadder>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export const TEAM_KEY_PATTERN = /^[a-z0-9][a-z0-9_-]*$/;
|
|
2
|
+
export const DEFAULT_TEAM_KIND = "default";
|
|
3
|
+
export const DEFAULT_TEAM_LADDERS = Object.freeze({
|
|
4
|
+
[DEFAULT_TEAM_KIND]: {
|
|
5
|
+
roles: [
|
|
6
|
+
{ key: "member", label: { en: "Member", da: "Medlem" } },
|
|
7
|
+
{ key: "lead", label: { en: "Lead", da: "Leder" } }
|
|
8
|
+
],
|
|
9
|
+
leadFrom: "lead"
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
export function ladderKeys(ladder) {
|
|
13
|
+
return ladder?.roles.map((role) => role.key) ?? [];
|
|
14
|
+
}
|
|
15
|
+
export function teamRoleRank(keys, role) {
|
|
16
|
+
return keys ? keys.indexOf(role) : -1;
|
|
17
|
+
}
|
|
18
|
+
export function roleAtLeast(keys, held, min) {
|
|
19
|
+
const heldRank = teamRoleRank(keys, held);
|
|
20
|
+
const minRank = teamRoleRank(keys, min);
|
|
21
|
+
return heldRank >= 0 && minRank >= 0 && heldRank >= minRank;
|
|
22
|
+
}
|
|
23
|
+
export function isLeadRole(keys, role, leadFrom) {
|
|
24
|
+
if (!leadFrom) return false;
|
|
25
|
+
const held = teamRoleRank(keys, role);
|
|
26
|
+
const min = teamRoleRank(keys, leadFrom);
|
|
27
|
+
return held >= 0 && min >= 0 && held >= min;
|
|
28
|
+
}
|
|
29
|
+
export function teamLadderIssues(ladder) {
|
|
30
|
+
const issues = [];
|
|
31
|
+
if (!ladder.roles.length) issues.push("A ladder needs at least one role.");
|
|
32
|
+
const seen = /* @__PURE__ */ new Set();
|
|
33
|
+
for (const role of ladder.roles) {
|
|
34
|
+
if (!TEAM_KEY_PATTERN.test(role.key)) issues.push(`"${role.key}" is not a valid role key: use lower case letters, digits, - and _.`);
|
|
35
|
+
if (seen.has(role.key)) issues.push(`"${role.key}" is on the ladder twice.`);
|
|
36
|
+
seen.add(role.key);
|
|
37
|
+
}
|
|
38
|
+
if (ladder.leadFrom && !seen.has(ladder.leadFrom)) issues.push(`The lead role "${ladder.leadFrom}" is not on the ladder.`);
|
|
39
|
+
return issues;
|
|
40
|
+
}
|
|
41
|
+
export function mergeTeamLadders(option) {
|
|
42
|
+
return { ...DEFAULT_TEAM_LADDERS, ...option };
|
|
43
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** The configured page paths (`public.teams.pages`), the team page with an `:id` param. */
|
|
2
|
+
export type TeamPages = {
|
|
3
|
+
admin?: string;
|
|
4
|
+
adminTeam?: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Builds every link to a teams page. All of them go through `localize` (the active locale's prefix, see `useLocaleLink`
|
|
8
|
+
* of `@frigear-nu/ui`). `query` is appended to the list link (an owner filter).
|
|
9
|
+
*/
|
|
10
|
+
export declare function createTeamLinks(pages: TeamPages | undefined, localize: (path: string) => string): {
|
|
11
|
+
admin: (query?: Record<string, string>) => string;
|
|
12
|
+
adminTeam: (id: string) => string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function createTeamLinks(pages, localize) {
|
|
2
|
+
return {
|
|
3
|
+
admin: (query) => {
|
|
4
|
+
const path = localize(pages?.admin || "/admin/teams");
|
|
5
|
+
const search = query ? new URLSearchParams(query).toString() : "";
|
|
6
|
+
return search ? `${path}?${search}` : path;
|
|
7
|
+
},
|
|
8
|
+
adminTeam: (id) => localize((pages?.adminTeam || "/admin/teams/:id").replace(":id", encodeURIComponent(id)))
|
|
9
|
+
};
|
|
10
|
+
}
|