@7365admin1/layer-common 4.2.20 → 4.2.21

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @iservice365/layer-common
2
2
 
3
+ ## 4.2.21
4
+
5
+ ### Patch Changes
6
+
7
+ - 58d9405: Add `useRole.getInvitableRoles` so an invite screen offers exactly the roles the invite endpoint accepts: the organisation's own roles plus the org-less template roles, never a `type: "admin"` console staff role, and optionally narrowed to one site.
8
+
3
9
  ## 4.2.20
4
10
 
5
11
  ### Patch Changes
@@ -726,11 +732,11 @@
726
732
  `utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
727
733
  own rule from two endpoints the console already calls, unprojected:
728
734
 
729
- GET /api/members/user/:user/app/admin the Seven365 staff membership
730
- GET /api/roles/id/:role that membership's role document
735
+ GET /api/members/user/:user/app/admin the Seven365 staff membership
736
+ GET /api/roles/id/:role that membership's role document
731
737
 
732
- owner = member.type === "admin" && role.type === "admin" && role.default === true
733
- staff = member.type === "admin" && role.type === "admin"
738
+ owner = member.type === "admin" && role.type === "admin" && role.default === true
739
+ staff = member.type === "admin" && role.type === "admin"
734
740
 
735
741
  `role.default` is the marker because it is the only property of a platform
736
742
  staff role no API caller can set - `role.controller.ts` validates create and
@@ -31,6 +31,60 @@ export default function useRole() {
31
31
  });
32
32
  }
33
33
 
34
+ /**
35
+ * The roles an INVITATION into `org` may actually hand out.
36
+ *
37
+ * The invite endpoints refuse a role the invitation is not entitled to
38
+ * (`core console-authz.util requireRoleInvitable` -> `invite-role-scope.util
39
+ * roleInvitable`), and that decision is a UNION that `GET /api/roles` cannot
40
+ * express in one call:
41
+ *
42
+ * - an ORG-LESS role is a template and is accepted for any organisation.
43
+ * Measured on staging: 341 of the 942 role-carrying invitations name one,
44
+ * so a picker that asks only for `org: <id>` locks every one of them out.
45
+ * - a role whose `org` IS the invited organisation.
46
+ * - never a `type: "admin"` role -- that is the Seven365 console's own staff
47
+ * type, and the server refuses it on any non-staff invitation.
48
+ *
49
+ * So: two reads, merged. `type: "organization"` on the org-less read is what
50
+ * excludes the staff roles there (the 12 org-less roles are 10 "organization"
51
+ * + 2 "admin"); the explicit filter covers the 1 org-SCOPED "admin" role,
52
+ * which the org read would otherwise return.
53
+ *
54
+ * `site` narrows the tenant half only, and only in the UI -- the server
55
+ * deliberately does not check a role's site, because a site is not a tenant
56
+ * boundary. A site-scoped screen still gets the organisation's site-less
57
+ * roles, because `getRoles` matches those too.
58
+ */
59
+ async function getInvitableRoles(
60
+ { search = "", org = "", site = "", limit = 50 } = {} as {
61
+ search?: string;
62
+ org?: string;
63
+ site?: string;
64
+ limit?: number;
65
+ }
66
+ ) {
67
+ const [tenant, templates] = await Promise.all([
68
+ org
69
+ ? getRoles({ search, org, site, limit })
70
+ : Promise.resolve({ items: [] } as Record<string, any>),
71
+ getRoles({ search, type: "organization", limit }),
72
+ ]);
73
+
74
+ const seen = new Set<string>();
75
+ const items = [...(tenant?.items ?? []), ...(templates?.items ?? [])].filter(
76
+ (role: Record<string, any>) => {
77
+ if (role?.type === "admin") return false;
78
+ const id = String(role?._id ?? "");
79
+ if (!id || seen.has(id)) return false;
80
+ seen.add(id);
81
+ return true;
82
+ }
83
+ );
84
+
85
+ return { items };
86
+ }
87
+
34
88
  function getRoleById(id: string) {
35
89
  return useNuxtApp().$api<TRole>(`/api/roles/id/${id}`, {
36
90
  method: "GET",
@@ -120,6 +174,7 @@ export default function useRole() {
120
174
  role,
121
175
  createRole,
122
176
  getRoles,
177
+ getInvitableRoles,
123
178
  getRoleById,
124
179
  updateRoleById,
125
180
  updateRoleFieldById,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@7365admin1/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "4.2.20",
5
+ "version": "4.2.21",
6
6
  "author": "7365admin1",
7
7
  "main": "./nuxt.config.ts",
8
8
  "//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",