@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.
Files changed (141) hide show
  1. package/README.md +16 -2
  2. package/dist/module.d.mts +278 -0
  3. package/dist/module.json +9 -0
  4. package/dist/module.mjs +134 -0
  5. package/dist/runtime/access.d.ts +1 -0
  6. package/dist/runtime/access.js +39 -0
  7. package/dist/runtime/app/components/TeamFormSlideover.d.vue.ts +13 -0
  8. package/dist/runtime/app/components/TeamFormSlideover.vue +126 -0
  9. package/dist/runtime/app/components/TeamFormSlideover.vue.d.ts +13 -0
  10. package/dist/runtime/app/components/TeamLadderSlideover.d.vue.ts +11 -0
  11. package/dist/runtime/app/components/TeamLadderSlideover.vue +125 -0
  12. package/dist/runtime/app/components/TeamLadderSlideover.vue.d.ts +11 -0
  13. package/dist/runtime/app/components/TeamMappingSlideover.d.vue.ts +15 -0
  14. package/dist/runtime/app/components/TeamMappingSlideover.vue +134 -0
  15. package/dist/runtime/app/components/TeamMappingSlideover.vue.d.ts +15 -0
  16. package/dist/runtime/app/components/TeamMemberSlideover.d.vue.ts +13 -0
  17. package/dist/runtime/app/components/TeamMemberSlideover.vue +79 -0
  18. package/dist/runtime/app/components/TeamMemberSlideover.vue.d.ts +13 -0
  19. package/dist/runtime/app/composables/index.d.ts +6 -0
  20. package/dist/runtime/app/composables/index.js +5 -0
  21. package/dist/runtime/app/composables/useTeamActions.d.ts +25 -0
  22. package/dist/runtime/app/composables/useTeamActions.js +56 -0
  23. package/dist/runtime/app/composables/useTeamLinks.d.ts +8 -0
  24. package/dist/runtime/app/composables/useTeamLinks.js +6 -0
  25. package/dist/runtime/app/composables/useTeamMappingActions.d.ts +20 -0
  26. package/dist/runtime/app/composables/useTeamMappingActions.js +46 -0
  27. package/dist/runtime/app/composables/useTeamMemberActions.d.ts +16 -0
  28. package/dist/runtime/app/composables/useTeamMemberActions.js +47 -0
  29. package/dist/runtime/app/composables/useTeamsTranslate.d.ts +7 -0
  30. package/dist/runtime/app/composables/useTeamsTranslate.js +15 -0
  31. package/dist/runtime/app/dashboard/MyTeams.d.vue.ts +3 -0
  32. package/dist/runtime/app/dashboard/MyTeams.vue +75 -0
  33. package/dist/runtime/app/dashboard/MyTeams.vue.d.ts +3 -0
  34. package/dist/runtime/app/grants/TeamGrantField.d.vue.ts +15 -0
  35. package/dist/runtime/app/grants/TeamGrantField.vue +120 -0
  36. package/dist/runtime/app/grants/TeamGrantField.vue.d.ts +15 -0
  37. package/dist/runtime/app/pages/admin-team.d.vue.ts +3 -0
  38. package/dist/runtime/app/pages/admin-team.vue +271 -0
  39. package/dist/runtime/app/pages/admin-team.vue.d.ts +3 -0
  40. package/dist/runtime/app/pages/admin.d.vue.ts +3 -0
  41. package/dist/runtime/app/pages/admin.vue +159 -0
  42. package/dist/runtime/app/pages/admin.vue.d.ts +3 -0
  43. package/dist/runtime/app/tabs/OwnerTeams.d.vue.ts +9 -0
  44. package/dist/runtime/app/tabs/OwnerTeams.vue +94 -0
  45. package/dist/runtime/app/tabs/OwnerTeams.vue.d.ts +9 -0
  46. package/dist/runtime/app/utils/admin-team.d.ts +27 -0
  47. package/dist/runtime/app/utils/admin-team.js +13 -0
  48. package/dist/runtime/dashboard.d.ts +8 -0
  49. package/dist/runtime/dashboard.js +14 -0
  50. package/dist/runtime/i18n/lang/da.json +174 -0
  51. package/dist/runtime/i18n/lang/en.json +174 -0
  52. package/dist/runtime/menus.d.ts +2 -0
  53. package/dist/runtime/menus.js +19 -0
  54. package/dist/runtime/server/candidates.d.ts +34 -0
  55. package/dist/runtime/server/candidates.js +16 -0
  56. package/dist/runtime/server/db/schema.postgresql.d.ts +628 -0
  57. package/dist/runtime/server/db/schema.postgresql.js +66 -0
  58. package/dist/runtime/server/db/schema.sqlite.d.ts +662 -0
  59. package/dist/runtime/server/db/schema.sqlite.js +66 -0
  60. package/dist/runtime/server/grants/team.d.ts +3 -0
  61. package/dist/runtime/server/grants/team.js +61 -0
  62. package/dist/runtime/server/plugins/ladders.d.ts +2 -0
  63. package/dist/runtime/server/plugins/ladders.js +7 -0
  64. package/dist/runtime/server/plugins/oauth-claims.d.ts +5 -0
  65. package/dist/runtime/server/plugins/oauth-claims.js +18 -0
  66. package/dist/runtime/server/plugins/owners.d.ts +2 -0
  67. package/dist/runtime/server/plugins/owners.js +19 -0
  68. package/dist/runtime/server/plugins/subscriptions.d.ts +2 -0
  69. package/dist/runtime/server/plugins/subscriptions.js +23 -0
  70. package/dist/runtime/server/policies.d.ts +2 -0
  71. package/dist/runtime/server/policies.js +14 -0
  72. package/dist/runtime/server/routes/admin/ladder.get.d.ts +2 -0
  73. package/dist/runtime/server/routes/admin/ladder.get.js +9 -0
  74. package/dist/runtime/server/routes/admin/ladder.put.d.ts +2 -0
  75. package/dist/runtime/server/routes/admin/ladder.put.js +27 -0
  76. package/dist/runtime/server/routes/admin/ladders.get.d.ts +2 -0
  77. package/dist/runtime/server/routes/admin/ladders.get.js +5 -0
  78. package/dist/runtime/server/routes/admin/mapping.delete.d.ts +2 -0
  79. package/dist/runtime/server/routes/admin/mapping.delete.js +11 -0
  80. package/dist/runtime/server/routes/admin/mapping.patch.d.ts +2 -0
  81. package/dist/runtime/server/routes/admin/mapping.patch.js +18 -0
  82. package/dist/runtime/server/routes/admin/mappings.get.d.ts +2 -0
  83. package/dist/runtime/server/routes/admin/mappings.get.js +22 -0
  84. package/dist/runtime/server/routes/admin/mappings.post.d.ts +2 -0
  85. package/dist/runtime/server/routes/admin/mappings.post.js +20 -0
  86. package/dist/runtime/server/routes/admin/member.delete.d.ts +2 -0
  87. package/dist/runtime/server/routes/admin/member.delete.js +18 -0
  88. package/dist/runtime/server/routes/admin/member.patch.d.ts +2 -0
  89. package/dist/runtime/server/routes/admin/member.patch.js +29 -0
  90. package/dist/runtime/server/routes/admin/member.post.d.ts +2 -0
  91. package/dist/runtime/server/routes/admin/member.post.js +18 -0
  92. package/dist/runtime/server/routes/admin/team.delete.d.ts +2 -0
  93. package/dist/runtime/server/routes/admin/team.delete.js +10 -0
  94. package/dist/runtime/server/routes/admin/team.get.d.ts +2 -0
  95. package/dist/runtime/server/routes/admin/team.get.js +9 -0
  96. package/dist/runtime/server/routes/admin/team.patch.d.ts +2 -0
  97. package/dist/runtime/server/routes/admin/team.patch.js +10 -0
  98. package/dist/runtime/server/routes/admin/teams.get.d.ts +2 -0
  99. package/dist/runtime/server/routes/admin/teams.get.js +26 -0
  100. package/dist/runtime/server/routes/admin/teams.post.d.ts +2 -0
  101. package/dist/runtime/server/routes/admin/teams.post.js +8 -0
  102. package/dist/runtime/server/routes/admin/users.get.d.ts +2 -0
  103. package/dist/runtime/server/routes/admin/users.get.js +13 -0
  104. package/dist/runtime/server/routes/me/teams.get.d.ts +2 -0
  105. package/dist/runtime/server/routes/me/teams.get.js +14 -0
  106. package/dist/runtime/server/routes/members.get.d.ts +2 -0
  107. package/dist/runtime/server/routes/members.get.js +14 -0
  108. package/dist/runtime/server/routes/team.get.d.ts +2 -0
  109. package/dist/runtime/server/routes/team.get.js +9 -0
  110. package/dist/runtime/server/search-index.d.ts +2 -0
  111. package/dist/runtime/server/search-index.js +7 -0
  112. package/dist/runtime/server/utils/teams-dto.d.ts +24 -0
  113. package/dist/runtime/server/utils/teams-dto.js +64 -0
  114. package/dist/runtime/server/utils/teams-ladders.d.ts +22 -0
  115. package/dist/runtime/server/utils/teams-ladders.js +53 -0
  116. package/dist/runtime/server/utils/teams-mappings.d.ts +16 -0
  117. package/dist/runtime/server/utils/teams-mappings.js +29 -0
  118. package/dist/runtime/server/utils/teams-roles.d.ts +63 -0
  119. package/dist/runtime/server/utils/teams-roles.js +242 -0
  120. package/dist/runtime/server/utils/teams-schemas.d.ts +127 -0
  121. package/dist/runtime/server/utils/teams-schemas.js +69 -0
  122. package/dist/runtime/server/utils/teams-search.d.ts +3 -0
  123. package/dist/runtime/server/utils/teams-search.js +2 -0
  124. package/dist/runtime/server/utils/teams.d.ts +65 -0
  125. package/dist/runtime/server/utils/teams.js +140 -0
  126. package/dist/runtime/utils/api.d.ts +30 -0
  127. package/dist/runtime/utils/api.js +33 -0
  128. package/dist/runtime/utils/claims.d.ts +7 -0
  129. package/dist/runtime/utils/claims.js +14 -0
  130. package/dist/runtime/utils/grants.d.ts +17 -0
  131. package/dist/runtime/utils/grants.js +9 -0
  132. package/dist/runtime/utils/index.d.ts +11 -0
  133. package/dist/runtime/utils/index.js +9 -0
  134. package/dist/runtime/utils/ladders.d.ts +22 -0
  135. package/dist/runtime/utils/ladders.js +43 -0
  136. package/dist/runtime/utils/links.d.ts +13 -0
  137. package/dist/runtime/utils/links.js +10 -0
  138. package/dist/runtime/utils/resolve.d.ts +29 -0
  139. package/dist/runtime/utils/resolve.js +57 -0
  140. package/dist/types.d.mts +5 -0
  141. package/package.json +121 -3
package/README.md CHANGED
@@ -1,3 +1,17 @@
1
- # Temporary Holding Version
1
+ # @frigear-nu/teams
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Teams for the frigear ecosystem: teams owned by an operation or the platform, members with a role from the ladder of
4
+ the team's kind, and role mapping rules that give people a team role from a global role or a subscription plan
5
+ without adding them by hand. The app defines its kinds and ladders in the `ladders` option; the module ships one
6
+ generic `default` ladder (`member`, `lead`). The option only seeds: a kind is stored once, and later changes to it in
7
+ `nuxt.config` are ignored; edit a stored ladder in the admin.
8
+
9
+ - Explicit memberships are rows; mapped ones are resolved at read time and never stored. An explicit membership always
10
+ wins over a mapped role on the same team.
11
+ - `resolveTeamRoles(event, userId, owner)` and `isTeamLead(event, userId, teamId)` for other modules (auto-imported).
12
+ - Registers the `team` grant kind of `@frigear-nu/auth` (a minimum role on one team), and owns owner references
13
+ (`ownerType` / `ownerId`, `OwnerRef`) and the `teams:owner:resolve` hook.
14
+ - Permissions `teams:read`, `teams:lead`, `teams:manage` and `teams:pii`; the `teams` scope and OAuth claim.
15
+ - Admin pages at `/admin/teams` (opt-in) and a "Teams" tab on the operation page.
16
+
17
+ Documentation: https://docs.frigear.dev/modules/organisation/teams
@@ -0,0 +1,278 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+ import { H3Event } from 'h3';
3
+ import { Translated } from '@frigear-nu/ui/translated';
4
+ export { Translated } from '@frigear-nu/ui/translated';
5
+
6
+ /**
7
+ * Who owns a team, or any record a module keeps per owner (a help-center category, a mailbox): `platform`, `operation`, `team`,
8
+ * or a type an app adds through `teams:owner:resolve`. Teams owns this type; other modules import it from
9
+ * `@frigear-nu/teams`. There is no global list of owner types.
10
+ */
11
+ type OwnerType = 'platform' | 'operation' | 'team' | (string & {});
12
+ /**
13
+ * A reference to a record's owner, stored as the `ownerType` / `ownerId` columns. `type` is never null: a record with
14
+ * no other owner is `{ type: 'platform', id: null }`. `id` is text, and `null` for `platform`.
15
+ */
16
+ type OwnerRef = {
17
+ type: OwnerType;
18
+ id: string | null;
19
+ };
20
+ /** A team role a user holds, on one team of one owner. */
21
+ type TeamRoleGrant = {
22
+ ownerType: OwnerType;
23
+ /** `null` for a team owned by the platform, as in {@link OwnerRef}. */
24
+ ownerId: string | null;
25
+ teamId: string;
26
+ kind: string;
27
+ role: string;
28
+ /** `explicit`: a stored membership. `mapped`: resolved at read time from a role mapping rule. */
29
+ source: 'explicit' | 'mapped';
30
+ };
31
+ /** A `team` grant on one team: the users holding `minRole` or a higher role on that team. */
32
+ type TeamIdGrant = {
33
+ kind: 'team';
34
+ teamId: string;
35
+ minRole: string;
36
+ };
37
+ /** A `team` grant on every team of a kind: the users holding `minRole` or a higher role on any team of `teamKind`. */
38
+ type TeamKindGrant = {
39
+ kind: 'team';
40
+ teamKind: string;
41
+ minRole: string;
42
+ };
43
+ /**
44
+ * The `team` grant of `@frigear-nu/auth`: one team (`teamId`) or every team of a kind (`teamKind`), at `minRole` or
45
+ * above on the kind's ladder.
46
+ */
47
+ type TeamGrant = TeamIdGrant | TeamKindGrant;
48
+ /**
49
+ * Context of `teams:owner:resolve`: the module that knows `owner.type` sets `label` and `exists`. Teams answers
50
+ * `platform`, `team` and `operation` (when `@frigear-nu/operations` is installed) itself; both stay `null` when nobody
51
+ * answers.
52
+ */
53
+ type TeamsOwnerResolveContext = {
54
+ event: H3Event | undefined;
55
+ owner: OwnerRef;
56
+ label: Translated | null;
57
+ exists: boolean | null;
58
+ };
59
+ /** One role of a ladder: a lower-case `key` (stored on members and mapping rules) and its label. */
60
+ type TeamLadderRole = {
61
+ key: string;
62
+ label: Translated;
63
+ };
64
+ /** The roles of a team kind, lowest first, and the lowest role that leads the team (`teams:lead`). */
65
+ type TeamLadder = {
66
+ roles: TeamLadderRole[];
67
+ /** The lowest role that counts as a lead of the team. Unset: nobody leads a team of this kind. */
68
+ leadFrom?: string | null;
69
+ };
70
+ /** What a mapping rule matches: a global role (with inheritance), or an active subscription to a plan. */
71
+ type TeamRoleMatch = {
72
+ role: string;
73
+ } | {
74
+ plan: string;
75
+ };
76
+ type ModuleOptions = {
77
+ /**
78
+ * The built-in ladders, by team kind. They are stored in `team_role_ladders` on the first request when the kind has
79
+ * no row yet, and admins may edit the row later. Merged over the one generic ladder the module ships, the `default`
80
+ * kind (`member`, `lead`; `lead` leads). The app defines its own kinds and roles here.
81
+ *
82
+ * Seed only: once a kind's row is stored, the stored row wins, whether or not an admin edited it. Changing a kind
83
+ * here later (a new role, another `leadFrom`) does not change the stored ladder: edit it in the admin
84
+ * (`PUT /api/admin/teams/ladders/:kind`). A new kind is still stored on the next start.
85
+ */
86
+ ladders?: Record<string, TeamLadder>;
87
+ settings?: {
88
+ pages?: {
89
+ /** Staff team list (needs `teams:manage`). `true` = `/admin/teams`. Off by default. */
90
+ admin?: string | boolean;
91
+ /** Staff team page (members, mapping rules, ladder); must contain an `:id` param. `true` = `/admin/teams/:id`. Off by default. */
92
+ adminTeam?: string | boolean;
93
+ };
94
+ /**
95
+ * Add a "Teams" tab to the `admin.operations` tab area (when `@frigear-nu/widget` is installed). Defaults to `true`;
96
+ * harmless when nothing renders the area.
97
+ */
98
+ operationsTab?: boolean;
99
+ };
100
+ };
101
+ type PublicModuleOptions = {
102
+ pages: {
103
+ admin?: string;
104
+ adminTeam?: string;
105
+ };
106
+ };
107
+ /** Where a team (or a mapping rule) belongs: `ownerId` is `null` for the platform. */
108
+ type TeamOwner = {
109
+ ownerType: OwnerType;
110
+ ownerId: string | null;
111
+ };
112
+ /** A team as anybody who may read it sees it (`GET /api/teams/:id`). */
113
+ type TeamDto = TeamOwner & {
114
+ id: string;
115
+ parentId: string | null;
116
+ kind: string;
117
+ name: Translated;
118
+ description: Translated | null;
119
+ capacity: number | null;
120
+ sort: number;
121
+ };
122
+ /** The staff view (`/api/admin/teams`): the same fields plus the audit dates, the owner's label and the member count. */
123
+ type AdminTeamDto = TeamDto & {
124
+ /** The owner's label from `teams:owner:resolve`, `null` for the platform or an owner nobody answers for. */
125
+ ownerLabel: Translated | null;
126
+ /** Explicit members only: mapped members are resolved on demand. */
127
+ memberCount: number;
128
+ createdAt: string;
129
+ updatedAt: string;
130
+ };
131
+ /** One member of a team: an explicit membership (a row) or a mapped one (resolved from a rule, never stored). */
132
+ type TeamMemberDto = {
133
+ /** The membership row's id (`tmm_...`); `null` for a mapped member. */
134
+ id: string | null;
135
+ teamId: string;
136
+ userId: number;
137
+ name: string | null;
138
+ avatar: string | null;
139
+ /** Only with `teams:pii`; otherwise left out. */
140
+ email?: string | null;
141
+ role: string;
142
+ /**
143
+ * Owned by consumers such as crew. Only `null` and `'active'` grant the role; any other value (`pending`,
144
+ * `inactive`, ...) keeps the member listed without a grant. Always `null` for a mapped member. Left out unless the
145
+ * caller manages (`teams:manage`) or leads (`teams:lead`) the team.
146
+ */
147
+ status?: string | null;
148
+ source: 'explicit' | 'mapped';
149
+ /** When the membership was added; `null` for a mapped member. */
150
+ addedAt: string | null;
151
+ };
152
+ /** My team roles (`GET /api/teams/me`): the grant plus the team's name. */
153
+ type MyTeamDto = TeamRoleGrant & {
154
+ name: Translated;
155
+ /** The role's label on the team kind's ladder; the role key when the ladder does not have it. */
156
+ roleLabel: Translated;
157
+ };
158
+ /** A role mapping rule (`/api/admin/teams/mappings`). */
159
+ type TeamRoleMappingDto = TeamOwner & {
160
+ id: string;
161
+ /** `null`: every team of the owner. */
162
+ teamId: string | null;
163
+ match: TeamRoleMatch;
164
+ teamRole: string;
165
+ priority: number;
166
+ createdAt: string;
167
+ updatedAt: string;
168
+ };
169
+ /** A ladder as the API answers it (`/api/admin/teams/ladders/:kind`). */
170
+ type TeamLadderDto = TeamLadder & {
171
+ kind: string;
172
+ leadFrom: string | null;
173
+ /** `stored`: a row of `team_role_ladders`. `default`: the module option, not stored yet. */
174
+ source: 'stored' | 'default';
175
+ };
176
+ /** A user found by the staff lookup (`GET /api/admin/teams/users?q=`). `email` only with `teams:pii`. */
177
+ type TeamUserLookupDto = {
178
+ id: number;
179
+ name: string | null;
180
+ avatar: string | null;
181
+ email?: string | null;
182
+ };
183
+ /** The `teams` claim of an id_token / userinfo with the `teams:read` scope: one entry per grant. */
184
+ type TeamsClaimEntry = {
185
+ id: string;
186
+ ownerType: OwnerType;
187
+ ownerId: string | null;
188
+ kind: string;
189
+ role: string;
190
+ source: 'explicit' | 'mapped';
191
+ };
192
+ /** A mapped grant while resolving: `priority` of the rule that produced it (default 0) decides between rules. */
193
+ type TeamsMappedGrant = TeamRoleGrant & {
194
+ priority?: number;
195
+ };
196
+ /** A team as the resolver sees it. */
197
+ type TeamsResolverTeam = TeamOwner & {
198
+ id: string;
199
+ kind: string;
200
+ };
201
+ /** Context of `teams:member:added` and `teams:member:removed`. */
202
+ type TeamMemberContext = {
203
+ event: H3Event;
204
+ team: AdminTeamDto;
205
+ member: TeamMemberDto;
206
+ };
207
+ /** Context of `teams:member:role-changed`. */
208
+ type TeamMemberRoleChangedContext = TeamMemberContext & {
209
+ from: string;
210
+ to: string;
211
+ };
212
+ /**
213
+ * Context of `teams:roles:resolve`. Listeners push mapped grants into `grants` (give them the `priority` of the rule
214
+ * they stand for; explicit memberships always win). `owner` is `null` when every owner is resolved at once (the
215
+ * team grant kind, the claim). `event` is `undefined` outside a request (the OAuth claim). When mapped members are
216
+ * listed (`teamMembers(..., { mapped: true })`), listeners are called once per candidate with `teams` holding that one
217
+ * team, its `owner`, and only the rules teams cannot answer in bulk itself (not `role` rules, nor `plan` rules when
218
+ * `@frigear-nu/subscriptions` is installed): a listener should not query per call there.
219
+ */
220
+ type TeamsRolesResolveContext = {
221
+ event: H3Event | undefined;
222
+ user: {
223
+ id: string | number;
224
+ };
225
+ owner: TeamOwner | null;
226
+ /** The user's global roles (closed over `inherit`). */
227
+ globalRoles: string[];
228
+ /** The mapping rules in play, every kind of `match`: listeners pick the ones they answer (teams answers `plan`). */
229
+ rules: TeamRoleMappingDto[];
230
+ /** The teams those rules can apply to. */
231
+ teams: TeamsResolverTeam[];
232
+ /** Kind to ordered role keys, lowest first. */
233
+ ladders: Record<string, string[]>;
234
+ grants: TeamsMappedGrant[];
235
+ };
236
+ /**
237
+ * Context of `teams:members:candidates`: listeners add the ids of users who may hold a mapped role on `team`, so
238
+ * `GET /api/teams/:id/members?include=mapped` can list them. Teams adds the users with an assigned role in
239
+ * `@frigear-nu/authorization` and the subscribers of mapped plans itself. Each candidate is checked with the resolver.
240
+ */
241
+ type TeamsMembersCandidatesContext = {
242
+ event: H3Event;
243
+ team: TeamsResolverTeam;
244
+ rules: TeamRoleMappingDto[];
245
+ userIds: Set<number>;
246
+ };
247
+
248
+ declare module '@nuxt/schema' {
249
+ interface NuxtConfig {
250
+ teams?: ModuleOptions;
251
+ }
252
+ interface PublicRuntimeConfig {
253
+ teams: PublicModuleOptions;
254
+ }
255
+ }
256
+ declare module 'nitropack' {
257
+ interface NitroRuntimeHooks {
258
+ /** A member was added to a team (an explicit membership). */
259
+ 'teams:member:added': (ctx: TeamMemberContext) => void | Promise<void>;
260
+ /** An explicit membership was removed. */
261
+ 'teams:member:removed': (ctx: TeamMemberContext) => void | Promise<void>;
262
+ /** A member's role changed (`from` and `to` are role keys of the team kind's ladder). */
263
+ 'teams:member:role-changed': (ctx: TeamMemberRoleChangedContext) => void | Promise<void>;
264
+ /** Push mapped grants for mapping sources teams does not know (teams answers `plan` rules itself with subscriptions). */
265
+ 'teams:roles:resolve': (ctx: TeamsRolesResolveContext) => void | Promise<void>;
266
+ /** Add users who may hold a mapped role on a team, for `GET /api/teams/:id/members?include=mapped`. */
267
+ 'teams:members:candidates': (ctx: TeamsMembersCandidatesContext) => void | Promise<void>;
268
+ /**
269
+ * Provider: label an owner and say whether it exists. Teams answers `team` and `operation`; an app adds its own
270
+ * owner types here. Other modules that store `ownerType` / `ownerId` validate their owners through it.
271
+ */
272
+ 'teams:owner:resolve': (ctx: TeamsOwnerResolveContext) => void | Promise<void>;
273
+ }
274
+ }
275
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
276
+
277
+ export { _default as default };
278
+ export type { AdminTeamDto, ModuleOptions, MyTeamDto, OwnerRef, OwnerType, PublicModuleOptions, TeamDto, TeamGrant, TeamIdGrant, TeamKindGrant, TeamLadder, TeamLadderDto, TeamLadderRole, TeamMemberContext, TeamMemberDto, TeamMemberRoleChangedContext, TeamOwner, TeamRoleGrant, TeamRoleMappingDto, TeamRoleMatch, TeamUserLookupDto, TeamsClaimEntry, TeamsMappedGrant, TeamsMembersCandidatesContext, TeamsOwnerResolveContext, TeamsResolverTeam, TeamsRolesResolveContext };
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "@frigear-nu/teams",
3
+ "configKey": "teams",
4
+ "version": "0.0.0",
5
+ "builder": {
6
+ "@nuxt/module-builder": "1.0.4",
7
+ "unbuild": "unknown"
8
+ }
9
+ }
@@ -0,0 +1,134 @@
1
+ import { defineNuxtModule, createResolver, hasNuxtModule, addServerImportsDir, addServerPlugin, addImports, addComponentsDir } from '@nuxt/kit';
2
+ import { registerModule, registerTailwindSource, registerLocales, resolvePagePath, registerDatabaseTable, registerSearchIndex, addModuleRoutes, inlineModuleRuntime, addModulePages, addOptionalMenuSource } from '@frigear-nu/module-kit/utils';
3
+ import { registerAccess, addPolicies, extendGrants } from '@frigear-nu/auth/utils';
4
+ import { teamsAccess } from '../dist/runtime/access.js';
5
+ import { mergeTeamLadders, teamLadderIssues } from '../dist/runtime/utils/ladders.js';
6
+ import { TEAMS_DASHBOARD, teamsDashboardItems } from '../dist/runtime/dashboard.js';
7
+
8
+ const MODULE_NAME = "@frigear-nu/teams";
9
+ const module$1 = defineNuxtModule({
10
+ meta: { name: MODULE_NAME, configKey: "teams" },
11
+ defaults: {
12
+ settings: { pages: {} }
13
+ },
14
+ moduleDependencies: {
15
+ "@nuxthub/core": { version: ">=0.10" },
16
+ "@frigear-nu/module-kit": { version: ">=0.0.1" },
17
+ "@frigear-nu/auth": { version: ">=0.0.1" },
18
+ // Members are users: the members list and the user lookup read the `users` table.
19
+ "@frigear-nu/users": { version: ">=0.0.1" },
20
+ "@frigear-nu/ui": { version: ">=0.0.1" },
21
+ "@frigear-nu/menu": { version: ">=0.0.1", optional: true },
22
+ "@frigear-nu/widget": { version: ">=0.0.0", optional: true },
23
+ // Items on the `crew.home` dashboard.
24
+ "@frigear-nu/dashboard": { version: ">=0.0.0", optional: true },
25
+ // Provides the admin route and shell the admin pages live in; the page components come from `@frigear-nu/ui`.
26
+ "@frigear-nu/admin": { version: ">=0.0.0", optional: true }
27
+ },
28
+ async setup(options, nuxt) {
29
+ registerModule(MODULE_NAME, nuxt);
30
+ const resolver = createResolver(import.meta.url);
31
+ registerAccess(nuxt, teamsAccess, { from: MODULE_NAME });
32
+ addPolicies(nuxt, { path: resolver.resolve("./runtime/server/policies") });
33
+ registerTailwindSource(nuxt, resolver.resolve("./runtime/app"));
34
+ registerLocales(nuxt, resolver.resolve("./runtime/i18n/lang"));
35
+ const settings = options.settings ?? {};
36
+ const ladders = mergeTeamLadders(options.ladders);
37
+ for (const [kind, ladder] of Object.entries(ladders)) {
38
+ const issues = teamLadderIssues(ladder);
39
+ if (issues.length) throw new Error(`[teams] the ladder "${kind}" is invalid: ${issues.join(" ")}`);
40
+ }
41
+ const runtime = nuxt.options.runtimeConfig;
42
+ runtime.teams = { ...runtime.teams, ladders };
43
+ let adminPath;
44
+ let adminTeamPath;
45
+ if (hasNuxtModule("@frigear-nu/admin")) {
46
+ const { adminRoute } = await import('@frigear-nu/admin/utils');
47
+ adminPath = resolvePagePath(settings.pages?.admin, adminRoute(nuxt, "teams"));
48
+ adminTeamPath = resolvePagePath(settings.pages?.adminTeam, adminRoute(nuxt, "teams", ":id"));
49
+ }
50
+ nuxt.options.runtimeConfig.public.teams = { pages: { admin: adminPath, adminTeam: adminTeamPath } };
51
+ registerDatabaseTable(nuxt, {
52
+ resolver,
53
+ schema: (dialect) => `./runtime/server/db/schema.${dialect}`
54
+ });
55
+ registerSearchIndex(nuxt, { name: "teams", handler: resolver.resolve("./runtime/server/search-index") });
56
+ addModuleRoutes(resolver, [
57
+ { method: "get", path: "me", file: "me/teams.get" },
58
+ { method: "get", path: ":id", file: "team.get" },
59
+ { method: "get", path: ":id/members", file: "members.get" }
60
+ ], { base: "/api/teams" });
61
+ addModuleRoutes(resolver, [
62
+ { method: "get", path: "", file: "admin/teams.get" },
63
+ { method: "post", path: "", file: "admin/teams.post" },
64
+ { method: "get", path: "mappings", file: "admin/mappings.get" },
65
+ { method: "post", path: "mappings", file: "admin/mappings.post" },
66
+ { method: "patch", path: "mappings/:id", file: "admin/mapping.patch" },
67
+ { method: "delete", path: "mappings/:id", file: "admin/mapping.delete" },
68
+ { method: "get", path: "ladders", file: "admin/ladders.get" },
69
+ { method: "get", path: "ladders/:kind", file: "admin/ladder.get" },
70
+ { method: "put", path: "ladders/:kind", file: "admin/ladder.put" },
71
+ { method: "get", path: "users", file: "admin/users.get" },
72
+ { method: "get", path: ":id", file: "admin/team.get" },
73
+ { method: "patch", path: ":id", file: "admin/team.patch" },
74
+ { method: "delete", path: ":id", file: "admin/team.delete" },
75
+ { method: "post", path: ":id/members", file: "admin/member.post" },
76
+ { method: "patch", path: ":id/members/:userId", file: "admin/member.patch" },
77
+ { method: "delete", path: ":id/members/:userId", file: "admin/member.delete" }
78
+ ], { base: "/api/admin/teams" });
79
+ addServerImportsDir(resolver.resolve("./runtime/server/utils"));
80
+ inlineModuleRuntime(nuxt, resolver);
81
+ addServerPlugin(resolver.resolve("./runtime/server/plugins/owners"));
82
+ extendGrants(nuxt, {
83
+ kind: "team",
84
+ label: "Team",
85
+ labelKey: "teams.grants.team",
86
+ icon: "i-lucide-users",
87
+ server: resolver.resolve("./runtime/server/grants/team"),
88
+ field: resolver.resolve("./runtime/app/grants/TeamGrantField.vue"),
89
+ defaults: { teamId: "", minRole: "" },
90
+ order: 20
91
+ });
92
+ addServerPlugin(resolver.resolve("./runtime/server/plugins/ladders"));
93
+ nuxt.hook("modules:done", () => {
94
+ if (hasNuxtModule("@frigear-nu/subscriptions", nuxt)) {
95
+ addServerPlugin(resolver.resolve("./runtime/server/plugins/subscriptions"));
96
+ }
97
+ if (hasNuxtModule("@frigear-nu/oauth-server", nuxt)) {
98
+ addServerPlugin(resolver.resolve("./runtime/server/plugins/oauth-claims"));
99
+ }
100
+ });
101
+ addImports([
102
+ { name: "useTeamLinks", from: resolver.resolve("./runtime/app/composables/useTeamLinks") },
103
+ { name: "useTeamActions", from: resolver.resolve("./runtime/app/composables/useTeamActions") },
104
+ { name: "useTeamMemberActions", from: resolver.resolve("./runtime/app/composables/useTeamMemberActions") },
105
+ { name: "useTeamMappingActions", from: resolver.resolve("./runtime/app/composables/useTeamMappingActions") },
106
+ { name: "useTeamsTranslate", from: resolver.resolve("./runtime/app/composables/useTeamsTranslate") }
107
+ ]);
108
+ addComponentsDir({ path: resolver.resolve("./runtime/app/components") });
109
+ addModulePages(MODULE_NAME, resolver, [
110
+ { name: "teams-admin", path: adminPath, file: "./runtime/app/pages/admin.vue" },
111
+ { name: "teams-admin-team", path: adminTeamPath, file: "./runtime/app/pages/admin-team.vue" }
112
+ ]);
113
+ if (adminTeamPath && settings.operationsTab !== false && hasNuxtModule("@frigear-nu/widget")) {
114
+ const { extendTabs } = await import('@frigear-nu/widget/utils');
115
+ extendTabs(nuxt, "admin.operations", {
116
+ id: "teams",
117
+ component: resolver.resolve("./runtime/app/tabs/OwnerTeams.vue"),
118
+ order: 20,
119
+ label: "Teams",
120
+ labelKey: "teams.admin.tabs.teams",
121
+ icon: "i-lucide-users-round",
122
+ props: { ownerType: "operation" },
123
+ permission: teamsAccess.permissions.manage
124
+ });
125
+ }
126
+ if (hasNuxtModule("@frigear-nu/dashboard")) {
127
+ const { extendDashboard } = await import('@frigear-nu/dashboard/utils');
128
+ extendDashboard(nuxt, TEAMS_DASHBOARD, teamsDashboardItems((path) => resolver.resolve(path)));
129
+ }
130
+ addOptionalMenuSource(nuxt, { file: resolver.resolve("./runtime/menus"), menu: "admin.nav" });
131
+ }
132
+ });
133
+
134
+ export { module$1 as default };
@@ -0,0 +1 @@
1
+ export declare const teamsAccess: import("@frigear-nu/auth/access").Access<"teams", "read" | "lead" | "manage" | "pii", "teams", never>;
@@ -0,0 +1,39 @@
1
+ import { defineAccess } from "@frigear-nu/auth/access";
2
+ export const teamsAccess = defineAccess("teams", {
3
+ permissions: {
4
+ // Self-service: every signed-in user holds it. Which teams it covers is the policy's business: the ones the user
5
+ // belongs to (explicit or mapped), and every team for `teams:manage`.
6
+ read: {
7
+ label: "Read your teams",
8
+ description: "See the teams you belong to, your role in them and who else is on them.",
9
+ implicit: true
10
+ },
11
+ // Held by everyone, narrowed by the policy to the teams where the user holds a lead role (the ladder's `leadFrom`
12
+ // and up). Other modules check it on a team record (`authorize(event, 'teams:lead', team)`).
13
+ lead: {
14
+ label: "Lead your teams",
15
+ description: "Lead the teams where you hold a lead role on the ladder.",
16
+ implicit: true
17
+ },
18
+ manage: {
19
+ label: "Manage teams",
20
+ description: "Create teams, add and remove members, change their roles, and edit role mapping rules and ladders.",
21
+ grantTo: ["admin"]
22
+ },
23
+ // Sensitive (`:pii`): never covered by `teams:*` or `*`, only granted by name.
24
+ pii: {
25
+ label: "See team members' contact details",
26
+ description: "See the email addresses of team members.",
27
+ grantTo: ["admin"]
28
+ }
29
+ },
30
+ scopes: {
31
+ // A named scope groups the permission for token consent; `teams:read` and `teams:pii` are usable as scopes as well.
32
+ teams: {
33
+ label: "Teams",
34
+ description: "See the teams you belong to and your role in them.",
35
+ icon: "i-lucide-users-round",
36
+ permissions: ["teams:read"]
37
+ }
38
+ }
39
+ });
@@ -0,0 +1,13 @@
1
+ import type { StaffTeam } from '../utils/admin-team.js';
2
+ import type { TeamOwner } from '../../../types.js';
3
+ type __VLS_Props = {
4
+ team?: StaffTeam;
5
+ owner?: TeamOwner;
6
+ };
7
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
8
+ close: (saved: false | import("../../utils/index.js").AdminTeamDto) => any;
9
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
10
+ onClose?: ((saved: false | import("../../utils/index.js").AdminTeamDto) => any) | undefined;
11
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
12
+ declare const _default: typeof __VLS_export;
13
+ export default _default;
@@ -0,0 +1,126 @@
1
+ <script setup>
2
+ import { z } from "zod";
3
+ import { TEAM_OWNER_TYPES } from "../utils/admin-team";
4
+ import { teamsApi } from "../../utils/api";
5
+ import { DEFAULT_TEAM_KIND } from "../../utils/ladders";
6
+ import { $fetch, computed, reactive, useAction, useLazyFetch, useModuleT, useTeamsTranslate } from "#imports";
7
+ defineOptions({ name: "TeamFormSlideover" });
8
+ const props = defineProps({
9
+ team: { type: Object, required: false },
10
+ owner: { type: Object, required: false }
11
+ });
12
+ const emit = defineEmits(["close"]);
13
+ const t = useModuleT("teams");
14
+ const tr = useTeamsTranslate();
15
+ const { busy, run } = useAction();
16
+ const { data: ladders } = useLazyFetch(teamsApi.admin.ladders, { default: () => [] });
17
+ const ownerFixed = computed(() => !!props.team || !!props.owner);
18
+ const kindOptions = computed(() => ladders.value.map((ladder) => ({ label: ladder.kind, value: ladder.kind })));
19
+ const ownerTypeOptions = computed(() => TEAM_OWNER_TYPES.map((value) => ({ label: t(`admin.ownerTypes.${value}`, value === "platform" ? "Platform" : "Operation"), value })));
20
+ const schema = z.object({
21
+ name: z.custom().refine((value) => !!tr(value).trim(), t("admin.nameRequired", "Enter a name.")),
22
+ description: z.custom().optional(),
23
+ kind: z.string().min(1, t("admin.kindRequired", "Choose a kind.")),
24
+ ownerType: z.string().min(1),
25
+ ownerId: z.string().trim().optional(),
26
+ capacity: z.number().int().min(0).optional(),
27
+ sort: z.number().int().optional()
28
+ }).refine((value) => value.ownerType === "platform" || !!value.ownerId, { message: t("admin.ownerIdRequired", "Enter the owner's id."), path: ["ownerId"] });
29
+ const state = reactive(props.team ? { name: props.team.name, description: props.team.description ?? void 0, kind: props.team.kind, ownerType: props.team.ownerType, ownerId: props.team.ownerId ?? "", capacity: props.team.capacity ?? void 0, sort: props.team.sort } : { name: void 0, description: void 0, kind: DEFAULT_TEAM_KIND, ownerType: props.owner?.ownerType ?? "platform", ownerId: props.owner?.ownerId ?? "", capacity: void 0, sort: 0 });
30
+ const isEmpty = (value) => value === void 0 || value === null || (typeof value === "string" ? !value.trim() : !Object.values(value).some((text) => text.trim()));
31
+ async function save(event) {
32
+ const data = event.data;
33
+ const fields = {
34
+ name: data.name,
35
+ description: isEmpty(data.description) ? null : data.description,
36
+ capacity: data.capacity ?? null,
37
+ sort: data.sort ?? 0
38
+ };
39
+ const saved = await run(
40
+ () => props.team ? $fetch(teamsApi.admin.team(props.team.id), { method: "PATCH", body: fields }) : $fetch(teamsApi.admin.teams, { method: "POST", body: { ...fields, kind: data.kind, ownerType: data.ownerType, ownerId: data.ownerType === "platform" ? null : data.ownerId } }),
41
+ { success: props.team ? t("admin.saved", "Saved {name}", { name: tr(data.name) }) : t("admin.created", "Created {name}", { name: tr(data.name) }) }
42
+ );
43
+ if (saved) emit("close", saved);
44
+ }
45
+ </script>
46
+
47
+ <template>
48
+ <FormSlideover
49
+ form-id="team-form"
50
+ :title="team ? t('admin.editTitle', 'Edit team') : t('admin.create', 'Add team')"
51
+ :submit-label="team ? t('admin.saveTeam', 'Save team') : t('admin.createAction', 'Create team')"
52
+ :loading="busy"
53
+ @close="emit('close', false)"
54
+ >
55
+ <UForm
56
+ id="team-form"
57
+ :schema="schema"
58
+ :state="state"
59
+ class="flex flex-col gap-4"
60
+ @submit="save"
61
+ >
62
+ <UFormField
63
+ name="name"
64
+ :label="t('admin.name', 'Name')"
65
+ required
66
+ >
67
+ <TranslatedInput v-model="state.name" />
68
+ </UFormField>
69
+ <UFormField
70
+ name="kind"
71
+ :label="t('admin.kind', 'Kind')"
72
+ :description="t('admin.kindHelp', 'The kind decides the role ladder of its members.')"
73
+ required
74
+ >
75
+ <USelect
76
+ v-model="state.kind"
77
+ :items="kindOptions"
78
+ :disabled="!!team"
79
+ class="w-full"
80
+ />
81
+ </UFormField>
82
+ <template v-if="!ownerFixed">
83
+ <UFormField
84
+ name="ownerType"
85
+ :label="t('admin.ownerType', 'Owner')"
86
+ required
87
+ >
88
+ <USelect
89
+ v-model="state.ownerType"
90
+ :items="ownerTypeOptions"
91
+ class="w-full"
92
+ />
93
+ </UFormField>
94
+ <UFormField
95
+ v-if="state.ownerType !== 'platform'"
96
+ name="ownerId"
97
+ :label="t('admin.ownerId', 'Owner id')"
98
+ :description="t('admin.ownerIdHelp', 'The id of the operation the team works at.')"
99
+ required
100
+ >
101
+ <UInput
102
+ v-model="state.ownerId"
103
+ class="w-full"
104
+ />
105
+ </UFormField>
106
+ </template>
107
+ <UFormField
108
+ name="capacity"
109
+ :label="t('admin.capacity', 'Capacity')"
110
+ :description="t('admin.capacityHelp', 'How many people the team needs.')"
111
+ >
112
+ <UInputNumber
113
+ v-model="state.capacity"
114
+ :min="0"
115
+ class="w-full"
116
+ />
117
+ </UFormField>
118
+ <UFormField
119
+ name="description"
120
+ :label="t('admin.description', 'Description')"
121
+ >
122
+ <TranslatedInput v-model="state.description" />
123
+ </UFormField>
124
+ </UForm>
125
+ </FormSlideover>
126
+ </template>
@@ -0,0 +1,13 @@
1
+ import type { StaffTeam } from '../utils/admin-team.js';
2
+ import type { TeamOwner } from '../../../types.js';
3
+ type __VLS_Props = {
4
+ team?: StaffTeam;
5
+ owner?: TeamOwner;
6
+ };
7
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
8
+ close: (saved: false | import("../../utils/index.js").AdminTeamDto) => any;
9
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
10
+ onClose?: ((saved: false | import("../../utils/index.js").AdminTeamDto) => any) | undefined;
11
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
12
+ declare const _default: typeof __VLS_export;
13
+ export default _default;
@@ -0,0 +1,11 @@
1
+ import type { StaffTeamLadder } from '../utils/admin-team.js';
2
+ type __VLS_Props = {
3
+ ladder: StaffTeamLadder;
4
+ };
5
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
6
+ close: (saved: false | import("../../utils/index.js").TeamLadderDto) => any;
7
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
8
+ onClose?: ((saved: false | import("../../utils/index.js").TeamLadderDto) => any) | undefined;
9
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
10
+ declare const _default: typeof __VLS_export;
11
+ export default _default;