@7365admin1/layer-common 4.87.0 → 4.88.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @iservice365/layer-common
2
2
 
3
+ ## 4.88.0
4
+
5
+ ### Minor Changes
6
+
7
+ - d635323: Add `useSiteActions(org)` and `utils/site-actions.ts`: whether the signed-in person may add or delete sites (and add organisations) in an organisation, as core answers it. Site-confined members are never offered these buttons.
8
+
3
9
  ## 4.87.0
4
10
 
5
11
  ### Minor Changes
@@ -1992,11 +1998,11 @@
1992
1998
  `utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
1993
1999
  own rule from two endpoints the console already calls, unprojected:
1994
2000
 
1995
- GET /api/members/user/:user/app/admin the Seven365 staff membership
1996
- GET /api/roles/id/:role that membership's role document
2001
+ GET /api/members/user/:user/app/admin the Seven365 staff membership
2002
+ GET /api/roles/id/:role that membership's role document
1997
2003
 
1998
- owner = member.type === "admin" && role.type === "admin" && role.default === true
1999
- staff = member.type === "admin" && role.type === "admin"
2004
+ owner = member.type === "admin" && role.type === "admin" && role.default === true
2005
+ staff = member.type === "admin" && role.type === "admin"
2000
2006
 
2001
2007
  `role.default` is the marker because it is the only property of a platform
2002
2008
  staff role no API caller can set - `role.controller.ts` validates create and
@@ -0,0 +1,29 @@
1
+ import { NO_SITE_ACTIONS, siteActionsOf, type TSiteActions } from "../utils/site-actions";
2
+
3
+ /**
4
+ * May the signed-in person add / delete sites (and add organisations) in this
5
+ * organisation? Re-asked whenever the organisation changes; hidden until core
6
+ * answers. See `utils/site-actions.ts`.
7
+ */
8
+ export default function useSiteActions(org: MaybeRefOrGetter<string>) {
9
+ const actions = ref<TSiteActions>({ ...NO_SITE_ACTIONS });
10
+
11
+ watch(
12
+ () => toValue(org),
13
+ async (id) => {
14
+ actions.value = { ...NO_SITE_ACTIONS };
15
+ if (!id) return;
16
+ try {
17
+ const res = await useNuxtApp().$api<Record<string, any>>("/api/customer-sites", {
18
+ query: { org: id, status: "active", limit: 1, withActions: true },
19
+ });
20
+ if (toValue(org) === id) actions.value = siteActionsOf(res);
21
+ } catch {
22
+ // stays hidden - the server refuses the action anyway
23
+ }
24
+ },
25
+ { immediate: true },
26
+ );
27
+
28
+ return actions;
29
+ }
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.87.0",
5
+ "version": "4.88.0",
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.",
@@ -0,0 +1,18 @@
1
+ /**
2
+ * What the signed-in person may do with an organisation's sites, as core
3
+ * answers it (`GET /api/customer-sites?withActions=true` -> `siteActions`).
4
+ *
5
+ * Owner rule 2026-10-01: creating, deleting or removing sites is for Seven365
6
+ * Super Admin, the organisation's owner and organisation-level members with the
7
+ * right; a member confined to sites never - whatever their role says. The
8
+ * server decides and refuses (403); the UI only hides what would be refused.
9
+ * Anything missing or unreadable reads as "no" (the button stays hidden).
10
+ */
11
+ export type TSiteActions = { create: boolean; delete: boolean; createCustomer: boolean };
12
+
13
+ export const NO_SITE_ACTIONS: TSiteActions = Object.freeze({ create: false, delete: false, createCustomer: false });
14
+
15
+ export function siteActionsOf(response: unknown): TSiteActions {
16
+ const a = (response as { siteActions?: Record<string, unknown> } | null)?.siteActions ?? {};
17
+ return { create: a.create === true, delete: a.delete === true, createCustomer: a.createCustomer === true };
18
+ }