@7365admin1/layer-common 4.97.1-staging.621 → 4.97.1-staging.622

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,189 @@
1
+ <!--
2
+ Zones & wrong-way. Draw areas on the camera's latest picture (click to add corners). Zones name an area
3
+ (for alerts and wrong-way rules); masks tell the engine to ignore an area (motion / objects).
4
+ Coordinates are saved as fractions of the picture (0..1), so they stay right at any screen size.
5
+ -->
6
+ <template>
7
+ <div>
8
+ <CctvEngineCameraPicker v-model:engine="engine" v-model:camera="camera" :site="site" />
9
+
10
+ <template v-if="engine && camera">
11
+ <v-progress-linear v-if="loading" indeterminate class="mt-3" />
12
+ <CctvEngineNotice v-else-if="error" class="mt-3" :error="error" retry @retry="load" />
13
+ <v-row v-else class="mt-1">
14
+ <v-col cols="12" md="8">
15
+ <div
16
+ ref="stage"
17
+ class="cctv-zn__stage"
18
+ :class="{ 'cctv-zn__stage--draw': canEdit }"
19
+ role="img"
20
+ :aria-label="`Latest picture from ${camera}. ${canEdit ? 'Click to add a corner.' : ''}`"
21
+ @click="addPoint"
22
+ >
23
+ <img v-if="image" :src="image" alt="" class="cctv-zn__img" draggable="false" />
24
+ <div v-else class="cctv-zn__none">No picture available yet - you can still draw, but placing is easier with a picture.</div>
25
+ <svg viewBox="0 0 1 1" preserveAspectRatio="none" class="cctv-zn__svg" aria-hidden="true">
26
+ <polygon v-for="(z, i) in zones" :key="`z${i}`" :points="svg(z.points)" :fill="color(i, 0.25)" :stroke="color(i, 1)" stroke-width="2" vector-effect="non-scaling-stroke" />
27
+ <polygon v-for="(m, i) in masks" :key="`m${i}`" :points="svg(m.points)" fill="rgba(0,0,0,0.45)" stroke="#fff" stroke-dasharray="6 4" stroke-width="2" vector-effect="non-scaling-stroke" />
28
+ <polyline v-if="draft.length" :points="svg(draft)" fill="rgba(255,255,255,0.2)" stroke="#fff" stroke-width="2" vector-effect="non-scaling-stroke" />
29
+ </svg>
30
+ <span v-for="(p, i) in draft" :key="`d${i}`" class="cctv-zn__dot" :style="{ left: p[0] * 100 + '%', top: p[1] * 100 + '%' }" />
31
+ </div>
32
+ <div class="hero-muted mt-1">
33
+ <template v-if="canEdit">Click on the picture to place corners (at least 3), then press "Finish shape".</template>
34
+ <template v-else>You can look at the zones but not change them. Ask a site admin for cctv-engine:manage-zones.</template>
35
+ </div>
36
+ </v-col>
37
+
38
+ <v-col cols="12" md="4">
39
+ <template v-if="canEdit">
40
+ <v-btn-toggle v-model="kind" mandatory density="comfortable" divided color="primary" class="mb-2">
41
+ <v-btn value="zone" size="small">Zone</v-btn>
42
+ <v-btn value="motion" size="small">Motion mask</v-btn>
43
+ <v-btn value="object" size="small">Object mask</v-btn>
44
+ </v-btn-toggle>
45
+ <p class="hero-muted">{{ KIND_HELP[kind] }}</p>
46
+ <v-text-field v-if="kind === 'zone'" v-model="zoneName" label="Zone name (e.g. entry, exit)" density="comfortable" hide-details class="mb-2" />
47
+ <div class="d-flex flex-wrap ga-2">
48
+ <v-btn size="small" color="primary" :disabled="!isValidPolygon(draft) || (kind === 'zone' && !zoneName.trim())" @click="finish">Finish shape</v-btn>
49
+ <v-btn size="small" variant="tonal" :disabled="!draft.length" @click="draft.pop()">Undo point</v-btn>
50
+ <v-btn size="small" variant="text" :disabled="!draft.length" @click="draft = []">Cancel</v-btn>
51
+ </div>
52
+ </template>
53
+
54
+ <h4 class="mt-4">Zones ({{ zones.length }})</h4>
55
+ <p v-if="!zones.length" class="hero-muted">None yet. Draw a zone to name an area, e.g. "entry" and "exit" for a wrong-way rule.</p>
56
+ <v-chip v-for="(z, i) in zones" :key="z.name + i" :color="color(i, 1)" class="mr-1 mb-1" :closable="canEdit" @click:close="zones.splice(i, 1)">{{ z.name }}</v-chip>
57
+ <h4 class="mt-3">Masks ({{ masks.length }})</h4>
58
+ <p v-if="!masks.length" class="hero-muted">None. Masks hide areas the engine should ignore (a road beyond the fence, a waving tree).</p>
59
+ <v-chip v-for="(m, i) in masks" :key="'m' + i" class="mr-1 mb-1" :closable="canEdit" @click:close="masks.splice(i, 1)">{{ m.kind === "motion" ? "Motion mask" : "Object mask" }} {{ i + 1 }}</v-chip>
60
+
61
+ <div v-if="canEdit" class="mt-4">
62
+ <v-btn color="primary" :loading="saving" :disabled="saving" @click="save">Save to the engine</v-btn>
63
+ <div v-if="saveMsg" class="mt-2" role="status">{{ saveMsg }}</div>
64
+ <CctvEngineNotice v-if="saveError" class="mt-2" :error="saveError" />
65
+ </div>
66
+ </v-col>
67
+ </v-row>
68
+ <CctvEngineNotice v-if="imageError && !error" class="mt-2" :error="imageError" title="The latest picture could not be loaded" body="The engine may be offline. You can still draw, then save when it is back." tone="info" />
69
+ </template>
70
+
71
+ <v-divider class="my-6" />
72
+ <CctvEngineWrongWayRules :site="site" :access="access" :engine="engine" :camera="camera" />
73
+ </div>
74
+ </template>
75
+
76
+ <script setup lang="ts">
77
+ import { computed, onBeforeUnmount, ref, watch } from "vue";
78
+ import {
79
+ buildZonesBody, CCTV_PERMISSIONS, isValidPolygon, pointFromClick, polygonToSvgPoints, readZonesReply,
80
+ type TMask, type TPoint, type TZone,
81
+ } from "../../utils/cctv-engine";
82
+
83
+ const props = defineProps<{ site: string; access?: { can: (p: any) => boolean } }>();
84
+ const { getZones, saveZones, latestImage } = useCctvEngine();
85
+
86
+ const engine = ref("");
87
+ const camera = ref("");
88
+ const canEdit = computed(() => props.access?.can(CCTV_PERMISSIONS.manageZones) ?? false);
89
+
90
+ const KIND_HELP = {
91
+ zone: "A named area. Used by alerts and wrong-way rules.",
92
+ motion: "The engine ignores movement inside this area (e.g. a waving tree, a TV).",
93
+ object: "The engine ignores objects found inside this area (e.g. a poster of a person).",
94
+ } as const;
95
+
96
+ const zones = ref<TZone[]>([]);
97
+ const masks = ref<TMask[]>([]);
98
+ const draft = ref<TPoint[]>([]);
99
+ const kind = ref<"zone" | "motion" | "object">("zone");
100
+ const zoneName = ref("");
101
+ const image = ref("");
102
+ const imageError = ref<unknown>(null);
103
+ const loading = ref(false);
104
+ const error = ref<unknown>(null);
105
+ const saving = ref(false);
106
+ const saveMsg = ref("");
107
+ const saveError = ref<unknown>(null);
108
+ const stage = ref<HTMLElement | null>(null);
109
+
110
+ const svg = (p: readonly TPoint[]) => polygonToSvgPoints(p);
111
+ const PALETTE = ["#1e88e5", "#43a047", "#fb8c00", "#8e24aa", "#e53935", "#00acc1"];
112
+ const color = (i: number, a: number) => {
113
+ const hex = PALETTE[i % PALETTE.length];
114
+ return a >= 1 ? hex : `${hex}${Math.round(a * 255).toString(16).padStart(2, "0")}`;
115
+ };
116
+
117
+ function addPoint(ev: MouseEvent) {
118
+ if (!canEdit.value || !stage.value) return;
119
+ const r = stage.value.getBoundingClientRect();
120
+ draft.value.push(pointFromClick(r, ev.clientX, ev.clientY));
121
+ }
122
+ function finish() {
123
+ if (!isValidPolygon(draft.value)) return;
124
+ if (kind.value === "zone") {
125
+ zones.value.push({ name: zoneName.value.trim().replace(/\s+/g, "_"), points: draft.value });
126
+ zoneName.value = "";
127
+ } else {
128
+ masks.value.push({ kind: kind.value, points: draft.value });
129
+ }
130
+ draft.value = [];
131
+ }
132
+
133
+ function readZones(res: any) {
134
+ ({ zones: zones.value, masks: masks.value } = readZonesReply(res));
135
+ }
136
+
137
+ function freeImage() {
138
+ if (image.value) URL.revokeObjectURL(image.value);
139
+ image.value = "";
140
+ }
141
+
142
+ async function load() {
143
+ zones.value = [];
144
+ masks.value = [];
145
+ draft.value = [];
146
+ saveMsg.value = "";
147
+ error.value = null;
148
+ imageError.value = null;
149
+ freeImage();
150
+ if (!engine.value || !camera.value) return;
151
+ loading.value = true;
152
+ const [z, img] = await Promise.allSettled([getZones(engine.value, camera.value), latestImage(engine.value, camera.value)]);
153
+ if (z.status === "fulfilled") readZones(z.value);
154
+ else error.value = z.reason;
155
+ if (img.status === "fulfilled") image.value = img.value;
156
+ else imageError.value = img.reason;
157
+ loading.value = false;
158
+ }
159
+
160
+ async function save() {
161
+ saving.value = true;
162
+ saveMsg.value = "";
163
+ saveError.value = null;
164
+ const { body, dropped } = buildZonesBody(zones.value, masks.value);
165
+ try {
166
+ await saveZones(engine.value, camera.value, body);
167
+ readZones(body);
168
+ saveMsg.value = dropped
169
+ ? `Saved. ${dropped} unfinished, unnamed or duplicate shape(s) were left out.`
170
+ : "Saved. The engine is using these zones now.";
171
+ } catch (e) {
172
+ saveError.value = e;
173
+ } finally {
174
+ saving.value = false;
175
+ }
176
+ }
177
+
178
+ watch([engine, camera], load);
179
+ onBeforeUnmount(freeImage);
180
+ </script>
181
+
182
+ <style scoped>
183
+ .cctv-zn__stage { position: relative; background: #111; border-radius: 10px; overflow: hidden; min-height: 180px; user-select: none; }
184
+ .cctv-zn__stage--draw { cursor: crosshair; }
185
+ .cctv-zn__img { width: 100%; display: block; }
186
+ .cctv-zn__none { color: #ddd; padding: 60px 16px; text-align: center; font-size: 13px; aspect-ratio: 16 / 9; }
187
+ .cctv-zn__svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
188
+ .cctv-zn__dot { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: #fff; border: 2px solid #1e88e5; pointer-events: none; }
189
+ </style>
@@ -0,0 +1,82 @@
1
+ <template>
2
+ <!-- Seven365 Super Admin only: everyone else never sees CCTV Engine set-up. -->
3
+ <v-expansion-panel v-if="isStaff" data-test="cctv-engine-site-switch">
4
+ <v-expansion-panel-title>
5
+ <v-icon class="mr-2">mdi-cctv</v-icon>
6
+ CCTV Engine (iSecure365)
7
+ </v-expansion-panel-title>
8
+ <v-expansion-panel-text>
9
+ <v-switch v-model="enabled" label="Switch CCTV Engine on at this site" color="primary" hide-details
10
+ data-test="cctv-engine-site-switch-toggle" />
11
+ <p class="text-caption text-medium-emphasis mt-1 mb-3">
12
+ The CCTV Engine is a small computer installed at the site that watches the cameras and tells us what it sees:
13
+ live pictures, recorded clips, people and vehicles, wrong-way driving, flagged number plates. When this is on,
14
+ people whose role allows it see a CCTV menu at this site. Off (the default) hides everything and nothing
15
+ changes for the site. Switching it off does not delete saved events.
16
+ </p>
17
+ <v-switch v-model="faceRecognition" :disabled="!enabled" label="Allow face recognition at this site"
18
+ color="primary" hide-details data-test="cctv-engine-face-toggle" />
19
+ <p class="text-caption text-medium-emphasis mt-1 mb-3">
20
+ Lets the engine learn faces from a library of photos and put a person's name on an event. It is a separate
21
+ switch because faces are personal data: leave it off unless the client has agreed. Off (the default) hides the
22
+ Face library and stores no names. It only works while the CCTV Engine above is on.
23
+ </p>
24
+ <p class="text-caption text-medium-emphasis mb-3">
25
+ Now: CCTV Engine <strong>{{ savedEnabled ? "On" : "Off" }}</strong>, face recognition
26
+ <strong>{{ savedFace ? "On" : "Off" }}</strong>. Only Seven365 can change these.
27
+ </p>
28
+ <v-btn class="screen-btn-primary" color="primary-button" variant="flat" text="Save"
29
+ :loading="saving" :disabled="!loaded" data-test="cctv-engine-site-switch-save" @click="save" />
30
+ <Snackbar v-model="toast.show" :text="toast.message" :color="toast.color" />
31
+ </v-expansion-panel-text>
32
+ </v-expansion-panel>
33
+ </template>
34
+
35
+ <script setup lang="ts">
36
+ import useSiteFeatureSettings from "../composables/useSiteFeatureSettings";
37
+ import useConsoleTier from "../composables/useConsoleTier";
38
+
39
+ /**
40
+ * Site setting `metadata.cctvEngine` `{ enabled, faceRecognition }` (core site-feature-settings). Both default OFF.
41
+ * The server refuses a change by anyone but the Seven365 Super Admin (403) and enforces the switches on every
42
+ * CCTV Engine route; this only draws them. Face recognition can only be on while the engine is on.
43
+ */
44
+ const props = defineProps({
45
+ siteId: { type: String, required: true },
46
+ saved: { type: Object as PropType<{ enabled?: boolean; faceRecognition?: boolean } | null>, default: null },
47
+ /** The site has been read; Save stays off until then. */
48
+ loaded: { type: Boolean, default: false },
49
+ });
50
+ const emit = defineEmits(["saved"]);
51
+
52
+ const { isStaff, load: loadTier } = useConsoleTier();
53
+ onMounted(() => loadTier());
54
+
55
+ const savedEnabled = computed(() => props.saved?.enabled === true);
56
+ const savedFace = computed(() => savedEnabled.value && props.saved?.faceRecognition === true);
57
+ const enabled = ref(false);
58
+ const faceRecognition = ref(false);
59
+ watch(savedEnabled, (v) => (enabled.value = v), { immediate: true });
60
+ watch(savedFace, (v) => (faceRecognition.value = v), { immediate: true });
61
+ watch(enabled, (on) => {
62
+ if (!on) faceRecognition.value = false;
63
+ });
64
+
65
+ const { saveSiteFeature } = useSiteFeatureSettings();
66
+ const saving = ref(false);
67
+ const toast = reactive({ show: false, message: "", color: "" });
68
+
69
+ async function save() {
70
+ if (!props.loaded || !isStaff.value) return;
71
+ saving.value = true;
72
+ try {
73
+ await saveSiteFeature(props.siteId, "cctvEngine", { enabled: enabled.value, faceRecognition: enabled.value && faceRecognition.value });
74
+ Object.assign(toast, { show: true, message: "Saved.", color: "success" });
75
+ emit("saved");
76
+ } catch (e: any) {
77
+ Object.assign(toast, { show: true, message: e?.data?.message || "Could not save.", color: "error" });
78
+ } finally {
79
+ saving.value = false;
80
+ }
81
+ }
82
+ </script>
@@ -272,6 +272,9 @@
272
272
  <ManpowerSiteSwitch v-if="showManpowerSwitch" :site-id="siteId"
273
273
  :saved="(siteData as any)?.metadata?.manpower" :loaded="!!siteData" @saved="refreshSiteData" />
274
274
 
275
+ <CctvEngineSiteSwitch v-if="showCctvEngineSwitch" :site-id="siteId"
276
+ :saved="(siteData as any)?.metadata?.cctvEngine" :loaded="!!siteData" @saved="refreshSiteData" />
277
+
275
278
  <slot
276
279
  name="panels"
277
280
  :can-manage="canManageSiteSettings"
@@ -303,6 +306,7 @@ const props = defineProps({
303
306
  showSiteSwitches: { type: Boolean, default: false },
304
307
  /** Manpower per-site switch (Seven365 Super Admin only): the Security host only. */
305
308
  showManpowerSwitch: { type: Boolean, default: false },
309
+ showCctvEngineSwitch: { type: Boolean, default: false },
306
310
  });
307
311
 
308
312
  const openPanels = ref([]); // default open first
@@ -0,0 +1,119 @@
1
+ /**
2
+ * iSecure365 CCTV Engine - every API call the CCTV Engine screens make.
3
+ * Contract: isecure365-cctv-engine/BACKEND_API_CONTRACT.md. Same style as useFile.ts.
4
+ *
5
+ * Pictures, clips and downloads need the signed-in session in a header, which an image or video tag
6
+ * cannot send, so those are read as a blob and shown through an object URL (`blobUrl`).
7
+ * Callers free it with `URL.revokeObjectURL`.
8
+ */
9
+ import { buildEventsQuery, type TEventFilters, type TZonesBody } from "../utils/cctv-engine";
10
+
11
+ export default function useCctvEngine() {
12
+ const api = <T = any>(url: string, opts: Record<string, any> = {}) =>
13
+ useNuxtApp().$api<T>(url, opts as any);
14
+
15
+ const enc = encodeURIComponent;
16
+ const cam = (engineId: string, camera: string) => `/api/cctv-engines/${engineId}/cameras/${enc(camera)}`;
17
+
18
+ // ---- engines & health
19
+ const listEngines = (site: string) => api("/api/cctv-engines", { method: "GET", query: { site } });
20
+ const createEngine = (body: { site: string; name: string; hardware?: Record<string, any> }) =>
21
+ api("/api/cctv-engines", { method: "POST", body });
22
+ const updateEngine = (id: string, body: Record<string, any>) =>
23
+ api(`/api/cctv-engines/${id}`, { method: "PATCH", body });
24
+ const rotateKey = (id: string) => api(`/api/cctv-engines/${id}/rotate-key`, { method: "POST" });
25
+ const deleteEngine = (id: string) => api(`/api/cctv-engines/${id}`, { method: "DELETE" });
26
+ const getHealth = (id: string) => api(`/api/cctv-engines/${id}/health`, { method: "GET" });
27
+ const listCameras = (id: string) => api(`/api/cctv-engines/${id}/cameras`, { method: "GET" });
28
+
29
+ // ---- live
30
+ const webrtcAnswer = (engineId: string, camera: string, sdp: string) =>
31
+ api<{ sdp: string }>(`${cam(engineId, camera)}/webrtc`, { method: "POST", body: { sdp } });
32
+
33
+ async function blobUrl(path: string, query?: Record<string, any>) {
34
+ try {
35
+ const blob = await api<Blob>(path, { method: "GET", query, responseType: "blob" });
36
+ return URL.createObjectURL(blob);
37
+ } catch (e: any) {
38
+ // An error body arrives as a Blob too; read its `{ message, code }` so the screen can say what happened.
39
+ const b = e?.data;
40
+ if (b instanceof Blob) {
41
+ try {
42
+ e.data = JSON.parse(await b.text());
43
+ } catch {
44
+ /* not JSON: keep the status only */
45
+ }
46
+ }
47
+ throw e;
48
+ }
49
+ }
50
+ const latestImage = (engineId: string, camera: string) =>
51
+ blobUrl(`${cam(engineId, camera)}/latest.jpg`, { t: Date.now() });
52
+
53
+ // ---- recordings, clips, exports
54
+ const listRecordings = (engineId: string, camera: string, from: string, to: string) =>
55
+ api(`${cam(engineId, camera)}/recordings`, { method: "GET", query: { from, to } });
56
+ const cameraClip = (engineId: string, camera: string, from: string, to: string) =>
57
+ blobUrl(`${cam(engineId, camera)}/clip.mp4`, { from, to });
58
+ const createExport = (engineId: string, body: { camera: string; from: string; to: string; name: string }) =>
59
+ api(`/api/cctv-engines/${engineId}/exports`, { method: "POST", body });
60
+ const listExports = (engineId: string) => api(`/api/cctv-engines/${engineId}/exports`, { method: "GET" });
61
+ const downloadExport = (engineId: string, exportId: string) =>
62
+ blobUrl(`/api/cctv-engines/${engineId}/exports/${exportId}/file`);
63
+
64
+ // ---- events
65
+ const listEvents = (site: string, filters: TEventFilters = {}) =>
66
+ api("/api/cctv-events", { method: "GET", query: buildEventsQuery(site, filters) });
67
+ const getEvent = (id: string) => api(`/api/cctv-events/${id}`, { method: "GET" });
68
+ const eventSnapshot = (id: string) => blobUrl(`/api/cctv-events/${id}/snapshot.jpg`);
69
+ const eventClip = (id: string) => blobUrl(`/api/cctv-events/${id}/clip.mp4`);
70
+
71
+ // ---- zones & wrong-way rules
72
+ const getZones = (engineId: string, camera: string) => api(`${cam(engineId, camera)}/zones`, { method: "GET" });
73
+ const saveZones = (engineId: string, camera: string, body: TZonesBody) =>
74
+ api(`${cam(engineId, camera)}/zones`, { method: "PUT", body });
75
+ const listWrongWayRules = (site: string) => api("/api/cctv-wrong-way-rules", { method: "GET", query: { site } });
76
+ const createWrongWayRule = (body: Record<string, any>) => api("/api/cctv-wrong-way-rules", { method: "POST", body });
77
+ // The server reads the site from `?site=` on every call by id and checks the caller against it.
78
+ const updateWrongWayRule = (site: string, id: string, body: Record<string, any>) =>
79
+ api(`/api/cctv-wrong-way-rules/${id}`, { method: "PATCH", query: { site }, body });
80
+ const deleteWrongWayRule = (site: string, id: string) =>
81
+ api(`/api/cctv-wrong-way-rules/${id}`, { method: "DELETE", query: { site } });
82
+
83
+ // ---- known plates (CCTV watch list only)
84
+ const listPlates = (site: string, query: Record<string, any> = {}) =>
85
+ api("/api/cctv-known-plates", { method: "GET", query: { site, ...query } });
86
+ const createPlate = (body: Record<string, any>) => api("/api/cctv-known-plates", { method: "POST", body });
87
+ const updatePlate = (site: string, id: string, body: Record<string, any>) =>
88
+ api(`/api/cctv-known-plates/${id}`, { method: "PATCH", query: { site }, body });
89
+ const deletePlate = (site: string, id: string) =>
90
+ api(`/api/cctv-known-plates/${id}`, { method: "DELETE", query: { site } });
91
+
92
+ // ---- faces
93
+ const listFaces = (engineId: string) => api(`/api/cctv-engines/${engineId}/faces`, { method: "GET" });
94
+ function enrolFace(engineId: string, image: File, faceName: string, consent: Record<string, any>) {
95
+ const body = new FormData();
96
+ body.append("file", image);
97
+ body.append("faceName", faceName);
98
+ body.append("consent", JSON.stringify(consent));
99
+ return api(`/api/cctv-engines/${engineId}/faces`, { method: "POST", body });
100
+ }
101
+ const deleteFace = (engineId: string, faceName: string) =>
102
+ api(`/api/cctv-engines/${engineId}/faces/${enc(faceName)}`, { method: "DELETE" });
103
+
104
+ // ---- alert settings
105
+ const getAlertSettings = (site: string) => api("/api/cctv-alert-settings", { method: "GET", query: { site } });
106
+ const saveAlertSettings = (site: string, body: Record<string, any>) =>
107
+ api("/api/cctv-alert-settings", { method: "PUT", query: { site }, body });
108
+
109
+ return {
110
+ listEngines, createEngine, updateEngine, rotateKey, deleteEngine, getHealth, listCameras,
111
+ webrtcAnswer, blobUrl, latestImage,
112
+ listRecordings, cameraClip, createExport, listExports, downloadExport,
113
+ listEvents, getEvent, eventSnapshot, eventClip,
114
+ getZones, saveZones, listWrongWayRules, createWrongWayRule, updateWrongWayRule, deleteWrongWayRule,
115
+ listPlates, createPlate, updatePlate, deletePlate,
116
+ listFaces, enrolFace, deleteFace,
117
+ getAlertSettings, saveAlertSettings,
118
+ };
119
+ }
@@ -0,0 +1,49 @@
1
+ import { cctvEngineAccess } from "../utils/cctv-engine";
2
+ import { grantsPermission } from "../utils/permission-spellings";
3
+ import { permissionsDenied } from "../utils/module-routes";
4
+
5
+ /**
6
+ * Who sees the CCTV Engine menu and screens. Mirrors the server: the site switch `cctvEngine.enabled` first,
7
+ * then the client's module list, then the role's `cctv-engine:*` permissions.
8
+ * The site is read once per site and shared, so the menu and the pages ask the same question.
9
+ * An unreadable site counts as switch OFF (the safe answer); the next navigation retries.
10
+ */
11
+ export default function useCctvEngineAccess(siteId: MaybeRefOrGetter<string>) {
12
+ const { userAppRole, userAppModulesDenied } = useLocalSetup();
13
+ const metadata = useState<Record<string, Record<string, any>>>("cctvEngineSiteMetadata", () => ({}));
14
+ const loading = ref(false);
15
+
16
+ async function refresh() {
17
+ const id = toValue(siteId);
18
+ if (!id || !/^[0-9a-f]{24}$/i.test(id) || loading.value) return;
19
+ loading.value = true;
20
+ try {
21
+ const site = await useSite().getSiteById(id);
22
+ metadata.value = { ...metadata.value, [id]: (site?.metadata as any) ?? {} };
23
+ } catch {
24
+ // leave unresolved
25
+ } finally {
26
+ loading.value = false;
27
+ }
28
+ }
29
+
30
+ // The menu is built before the site id is known, so ask again whenever it changes.
31
+ watch(
32
+ () => toValue(siteId),
33
+ (id) => {
34
+ if (id && !(id in metadata.value)) refresh();
35
+ },
36
+ { immediate: true },
37
+ );
38
+
39
+ const access = computed(() =>
40
+ cctvEngineAccess({
41
+ grants: (p) => !!userAppRole.value && grantsPermission(userAppRole.value.permissions, p),
42
+ moduleDenied: permissionsDenied(["cctv-engine:view-live"],userAppModulesDenied?.value),
43
+ siteMetadata: metadata.value[toValue(siteId)] ?? null,
44
+ }),
45
+ );
46
+ const resolved = computed(() => toValue(siteId) in metadata.value);
47
+
48
+ return { access, resolved, loading, refresh };
49
+ }
@@ -391,6 +391,22 @@ export function useCommonPermissions() {
391
391
  },
392
392
  };
393
393
 
394
+ /**
395
+ * iSecure365 CCTV Engine. The eight strings core `cctv-engine-permission.util.ts` enforces on every
396
+ * CCTV Engine route. Catalogue-only: offering an entry grants nobody anything until it is ticked.
397
+ * The site's `cctvEngine.enabled` switch (Seven365 Super Admin) must also be on.
398
+ */
399
+ const cctvEnginePermissions = {
400
+ "view-live": { check: true, description: "Allows the user to watch live pictures from the site's CCTV Engine cameras." },
401
+ "view-events": { check: true, description: "Allows the user to see what the CCTV Engine detected, play back recorded clips, and receive its alerts." },
402
+ export: { check: true, description: "Allows the user to export CCTV Engine recordings as video files." },
403
+ "manage-faces": { check: true, description: "Allows the user to add and remove people in the face library (only where face recognition is switched on)." },
404
+ "manage-plates": { check: true, description: "Allows the user to manage the CCTV known number plates list." },
405
+ "manage-zones": { check: true, description: "Allows the user to draw zones and masks on cameras and set wrong-way rules." },
406
+ "manage-alerts": { check: true, description: "Allows the user to choose which CCTV Engine events raise alerts, who is told and when." },
407
+ "manage-engine": { check: true, description: "Allows the user to add, rotate the key of, and remove the CCTV Engine boxes at the site." },
408
+ };
409
+
394
410
  // Trade catalogue v2 (owner 2026-10-21): Task Calendar per role. Grants
395
411
  // nothing alone; a role without `catalogue:trade-v2` keeps the calendar
396
412
  // (utils/trade-catalogue.ts).
@@ -405,6 +421,7 @@ export function useCommonPermissions() {
405
421
  return {
406
422
  taskCalendarPermissions,
407
423
  robotPermissions,
424
+ cctvEnginePermissions,
408
425
  inventoryPermissions,
409
426
  invitationPermissions,
410
427
  memberPermissions,
@@ -44,6 +44,7 @@ export default function usePropertyPermission() {
44
44
 
45
45
  inventoryPermissions,
46
46
  robotPermissions,
47
+ cctvEnginePermissions,
47
48
  } = useCommonPermissions();
48
49
 
49
50
 
@@ -644,6 +645,7 @@ export default function usePropertyPermission() {
644
645
  },
645
646
  },
646
647
  "robot-mgmt": robotPermissions,
648
+ "cctv-engine": cctvEnginePermissions,
647
649
  "site-settings": siteSettingsPermissions
648
650
  };
649
651
 
@@ -33,10 +33,12 @@ export default function useSecurityPermission() {
33
33
  bulletinBoardPermissions,
34
34
 
35
35
  inventoryPermissions,
36
+ cctvEnginePermissions,
36
37
  } = useCommonPermissions();
37
38
 
38
39
  const permissions: TPermissions = {
39
40
  inventory: inventoryPermissions,
41
+ "cctv-engine": cctvEnginePermissions,
40
42
  feedbacks: {
41
43
  "add-feedback": {
42
44
  check: true,
@@ -18,6 +18,7 @@ export const SITE_FEATURE_KEYS = [
18
18
  "visitorPassSms",
19
19
  "robotSharedSpace",
20
20
  "manpower",
21
+ "cctvEngine",
21
22
  ] as const;
22
23
 
23
24
  export type TSiteFeatureKey = (typeof SITE_FEATURE_KEYS)[number];
@@ -511,6 +511,17 @@ export const PERMISSIONS = {
511
511
  "see-robot-details",
512
512
  "delete-robot",
513
513
  ],
514
+ // iSecure365 CCTV Engine (core `cctv-engine-permission.util.ts` enforces exactly these eight strings).
515
+ "cctv-engine": [
516
+ "view-live",
517
+ "view-events",
518
+ "export",
519
+ "manage-faces",
520
+ "manage-plates",
521
+ "manage-zones",
522
+ "manage-alerts",
523
+ "manage-engine",
524
+ ],
514
525
 
515
526
  // ---- organisation console (`-org`) ----
516
527
  customers: [
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.97.1-staging.621",
5
+ "version": "4.97.1-staging.622",
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.",