@7365admin1/layer-common 4.82.1-staging.475 → 4.82.1-staging.476

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.
@@ -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.82.1-staging.475",
5
+ "version": "4.82.1-staging.476",
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
+ }