@7365admin1/core 3.46.1-staging.117 → 3.47.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 (29) hide show
  1. package/CHANGELOG.md +732 -0
  2. package/package.json +1 -1
  3. package/.changeset/camera-engagement-site-scope.md +0 -15
  4. package/.changeset/camera-entitlement-engagement.md +0 -45
  5. package/.changeset/camera-functions-for-patrol.md +0 -42
  6. package/.changeset/camera-integration-layer.md +0 -60
  7. package/.changeset/camera-list-site-scoping.md +0 -42
  8. package/.changeset/camera-monitoring-wall.md +0 -32
  9. package/.changeset/camera-probe-cache-and-substream-fallback.md +0 -46
  10. package/.changeset/camera-setup-from-recorder.md +0 -43
  11. package/.changeset/camera-write-authorization.md +0 -35
  12. package/.changeset/console-subscription-setup.md +0 -5
  13. package/.changeset/customer-site-property-details.md +0 -42
  14. package/.changeset/dahua-credential-logging.md +0 -19
  15. package/.changeset/dahua-spec-defects.md +0 -20
  16. package/.changeset/dashboard-truth-and-camera-health-claim.md +0 -104
  17. package/.changeset/default-staff-role-lookup.md +0 -5
  18. package/.changeset/hid-card-pin-authorization.md +0 -35
  19. package/.changeset/hid-physical-card-lifecycle.md +0 -8
  20. package/.changeset/marketplace-order-notification-categories.md +0 -39
  21. package/.changeset/notification-preferences.md +0 -20
  22. package/.changeset/notifications-session-scoping.md +0 -17
  23. package/.changeset/occurrence-and-patrol-defects.md +0 -24
  24. package/.changeset/promo-code-management.md +0 -5
  25. package/.changeset/service-provider-invite-approval.md +0 -31
  26. package/.changeset/service-provider-invite-pending-check.md +0 -17
  27. package/.changeset/site-name-similarity-check.md +0 -26
  28. package/.changeset/staff-console-authorization.md +0 -29
  29. package/.changeset/terms-acceptance-per-user.md +0 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,737 @@
1
1
  # @iservice365/core
2
2
 
3
+ ## 3.47.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 35e1ba6: Camera functions for Virtual Patrol, proxied server-side.
8
+
9
+ Adds authenticated camera endpoints so the apps can use a site camera without ever
10
+ holding its credential. Dahua devices authenticate with digest and the cleartext
11
+ password on every request (HTTP API V3.37 §3.4) and the specification offers no
12
+ session or usable token, so the only safe shape is a server-side proxy.
13
+
14
+ - `useCameraViewController` — snapshot, snapshot-to-file for evidence, and
15
+ per-recorder health.
16
+ - A camera record does not hold a device address: `site.cameras.host` is the CCTV
17
+ relay's page URL and its numeric last path segment is the stream channel. A
18
+ camera is therefore resolved as **recorder (from `CAMERA_RTSP_DEVICES`, keyed by
19
+ relay authority) + channel (from the stored host)**. The address and credential
20
+ live in deployment configuration only — never in the database, never in a client.
21
+ - Pictures come off the video stream (one `ffmpeg` frame per snapshot, substream
22
+ for a tile, main stream for an evidence capture). The recorder in use exposes
23
+ RTSP only; its HTTP CGI ports are not reachable, so `snapshot.cgi`, firmware
24
+ (§4.6.14), device clock (§4.6.2) and PTZ (§8.1.5) cannot be used against it.
25
+ Firmware and clock are reported as unavailable with a reason, and PTZ refuses.
26
+ `GET /site-cameras/capabilities` reports `ptz: false` whatever
27
+ `CAMERA_PTZ_ENABLED` says, so a client hides the control rather than drawing a
28
+ pad whose every press fails.
29
+ - A camera whose relay has no configured recorder, or whose address carries no
30
+ channel, is refused up-front with a reason rather than failing as a blank picture.
31
+ - At most `CAMERA_MAX_CONCURRENT_GRABS` (4) pictures are taken at once across the
32
+ process, so the endpoint cannot fill the API host with ffmpeg or overpull the
33
+ recorder; over that, the caller is told the cameras are busy.
34
+ - Access is decided by the caller's site/org membership and their role's
35
+ permissions, never by the camera id in the URL.
36
+ - ANPR units are refused: ANPR belongs to visitor and vehicle management, not to
37
+ Virtual Patrol or CCTV.
38
+ - Camera host, username, password and the RTSP URL are never returned and never
39
+ logged; ffmpeg's stderr is discarded because it echoes the credential.
40
+ - No retry on a camera call: the device locks an account for 1800 s after 3
41
+ failures in 30 s (§4.7.x).
42
+
43
+ Requires `ffmpeg` on the API host (or `CAMERA_FFMPEG_PATH`); where it is absent the
44
+ snapshot endpoints answer with "Video tooling is not available on this server."
45
+
46
+ - a2bfbb1: Camera integration layer: a capability descriptor, a transport registry, and the
47
+ Dahua device HTTP adapter (written, tested, switched off).
48
+
49
+ Every camera in the wall and status responses now carries a `capabilities`
50
+ descriptor: `liveVideo`, `stillFrame`, `digitalZoom`, `ptz`, `presets`,
51
+ `playback`, `events`, `audio`, `deviceInfo`, each `supported` / `unsupported` /
52
+ `unknown` with a machine-readable reason code and one sentence. A client renders
53
+ itself from it without knowing anything about relays, recorders or networks.
54
+ `unknown` is distinct on purpose: "we have not been allowed to ask" is not the
55
+ same fact as "this camera cannot".
56
+
57
+ Capabilities resolve through a transport registry instead of the service picking
58
+ a path. `RELAY_PLAYER` is the stored player-page URL rendered in a WebView (the
59
+ live product's picture path, live video only, no control channel). `RTSP_FRAME`
60
+ is one ffmpeg still off the recorder. `DEVICE_HTTP` is the camera's own CGI API.
61
+ Registration order is preference order, so one camera serves live video over the
62
+ relay and evidence stills over RTSP at the same time, and adding a transport
63
+ later needs no service change.
64
+
65
+ `DEVICE_HTTP` covers device info/version, snapshot, PTZ (continuous, absolute,
66
+ stop), presets (list and recall), recorded-file query with playback URL
67
+ construction, and event subscription - digest auth only, values percent-encoded,
68
+ 403 treated as bad credentials and 401 as an ordinary challenge. It contacts
69
+ nothing today: the recorder in this estate answers on RTSP only. Enabling it is
70
+ configuration, not a code change.
71
+
72
+ A shared, persistent authentication failure budget is mandatory on that path. The
73
+ device locks an account for 1800 s after 3 failed logins in 30 s, so failures are
74
+ counted per device in the cache, the budget stops at 2, and once spent no request
75
+ leaves the process. Nothing retries anywhere.
76
+
77
+ Mutating operations are structurally unreachable while disabled: the adapter is
78
+ `null` without `CAMERA_DEVICE_HTTP_ENABLED`, and its `control` object is `null`
79
+ without `CAMERA_DEVICE_CONTROL_ENABLED`. Movement codes are an allow-list;
80
+ `SetPreset`, `ClearPreset`, tours, patterns, `configManager` writes and reboot are
81
+ absent.
82
+
83
+ Capability probing is read-only, cached, budget-aware, never throws, and happens
84
+ only on a deliberate single-camera status request - never as a side effect of a
85
+ list.
86
+
87
+ `host` is now returned for `type: "ip"` cameras on the wall response. It is the
88
+ video relay's player-page URL, not a device address and not a credential, and
89
+ `GET /site-cameras` already returns it to every authenticated caller. `anpr`
90
+ records, whose `host` is a real device endpoint, are excluded by the allow-list
91
+ itself.
92
+
93
+ New configuration, all optional and all off by default: `CAMERA_DEVICE_HTTP`
94
+ (JSON keyed by relay authority, credential referenced by environment variable
95
+ name), `CAMERA_DEVICE_HTTP_ENABLED`, `CAMERA_DEVICE_CONTROL_ENABLED`,
96
+ `CAMERA_DEVICE_HTTP_TIMEOUT_MS` (8000),
97
+ `CAMERA_DEVICE_HTTP_PROBE_TTL_SECONDS` (900). See
98
+ `docs/camera-integration-config.md`.
99
+
100
+ Existing responses keep every field they had, with the same wording, so current
101
+ consumers are unaffected.
102
+
103
+ - e11fbb5: CCTV monitoring wall: a site-scoped camera list and a batched health sweep.
104
+
105
+ Two additions to the camera proxy so a supervisor can watch a whole site rather
106
+ than one checkpoint at a time.
107
+
108
+ `getSiteWall` returns the cameras of one site from `site.cameras` - the
109
+ collection the real cameras are in - together with the polling intervals and
110
+ fan-out caps the client should use. No device is contacted, so opening a wall is
111
+ one database read. Entitlement is by site membership, not by the id in the URL,
112
+ and a caller outside the site gets the same answer as one asking for a site that
113
+ does not exist.
114
+
115
+ `getSiteHealth` probes the cameras currently on screen with at most
116
+ `CAMERA_WALL_MAX_CONCURRENT_PROBES` in flight. Reachability is a **per-recorder**
117
+ answer, cached per recorder: twelve of this estate's cameras are twelve channels
118
+ on one device, so a full wall is one connect rather than one per tile. It never
119
+ throws for a camera that is down; unreachable is the answer, and a camera whose
120
+ relay has no configured recorder is refused with a reason instead.
121
+
122
+ Firmware version and device clock are reported as unavailable with a reason: they
123
+ are HTTP CGI facts and the recorder in use exposes RTSP only.
124
+
125
+ Snapshots now record when a camera last returned a picture, so a tile can say
126
+ "last frame 40 minutes ago" instead of "never".
127
+
128
+ New, all optional and conservative by default: `CAMERA_WALL_POLL_MS` (5000),
129
+ `CAMERA_SINGLE_POLL_MS` (2000), `CAMERA_WALL_MAX_TILES` (9),
130
+ `CAMERA_WALL_MAX_CONCURRENT_PROBES` (4), `CAMERA_HEALTH_CACHE_SECONDS` (20).
131
+
132
+ - 2d6bc0e: CCTV reliability: cache the capability probe per channel, and stop reporting a
133
+ missing sub-stream as a dead camera.
134
+
135
+ Two defects in the camera proxy, both of which made one camera answer for
136
+ another.
137
+
138
+ **The capability probe was cached per recorder.** The key was `probe:<baseUrl>`,
139
+ so the first camera anyone opened decided `ptz` and `presets` for every channel
140
+ on that recorder until the TTL expired (default 900s). On this estate twelve
141
+ cameras are twelve channels on one device, and they are not all the same model.
142
+ The key is now `cameraProbeCacheKey(baseUrl, channel)` and every reader passes a
143
+ channel - `refreshProbe`, the health sweep, and the monitoring wall, whose own
144
+ de-duplication `Map` was keyed by recorder too and would have re-created the
145
+ same fault a layer above the cache. Cache lifetime and eviction are unchanged.
146
+
147
+ Only `ptz` and `presets` are channel-specific. `reachable`, `lockedOut`,
148
+ `softwareVersion` and `deviceType` are recorder facts that answer identically on
149
+ every channel, which is what `deviceInfo`, `playback` and `events` read, and a
150
+ test pins that so it stays true. The cost is at most one probe per channel per
151
+ TTL, and only on the deliberate single-camera status path - the wall and the
152
+ health sweep still never probe.
153
+
154
+ **A channel with no sub-stream failed exactly like a dead camera.** An
155
+ ONVIF-attached third-party camera frequently publishes no sub-stream, and the
156
+ recorder answers that channel with no picture, which surfaced as "The camera did
157
+ not return a picture." - indistinguishable from a camera that is off.
158
+ `getSnapshot` now goes through `grabWithSubStreamFallback`: the sub-stream
159
+ first, then exactly one main-stream attempt if and only if the failure is
160
+ `camera-no-picture`. The result carries `stream` and `fellBackToMain`, exposed
161
+ on the snapshot response as `X-Camera-Stream` and `X-Camera-Stream-Fallback`
162
+ alongside the existing `X-Camera-Snapshot-Cached`, so the fallback is explicit
163
+ rather than silent and a client can say "showing full resolution: this camera
164
+ has no low-bandwidth stream". A `nosub:<cameraId>` marker keeps the wasted
165
+ attempt to once per TTL, and a channel later given a sub-stream heals itself.
166
+
167
+ A refused credential, a timeout, a busy server, an oversized picture or a
168
+ missing ffmpeg never falls back - one attempt each, unchanged. Patrol evidence
169
+ (`hd: true`) already asks for the main stream and never enters the fallback.
170
+
171
+ Per-camera stream configuration is the better long-term answer but needs a
172
+ schema field, a form, an API surface and a migration for the existing cameras;
173
+ the automatic fallback needs no data change and is raised as a follow-up.
174
+
175
+ - 2b23b62: Camera setup from the recorder and channel, and a read-only test before saving.
176
+
177
+ A CCTV camera record stores a video-relay player-page URL. Nothing printed on a
178
+ camera or shown in a recorder's own screens tells anybody what that URL is, so
179
+ adding a camera meant asking whoever runs the video service for one address per
180
+ camera and pasting it in unverified.
181
+
182
+ `POST /site-cameras` and `PATCH /site-cameras/id/:id` now also accept
183
+ `recorderHost`, `recorderPort` and `channel`. The server reads the existing
184
+ `CAMERA_RTSP_DEVICES` map backwards - relay authority to recorder becomes
185
+ recorder to relay authority - and derives the same `https://<relay>/<channel>`
186
+ address it has always stored. There is deliberately no second map and no new
187
+ stored field: the recorder fields are consumed by the controller and never reach
188
+ the model, so `site.cameras` keeps exactly the shape it has today.
189
+
190
+ Additive and ordered so: a request that sends `host` behaves exactly as it
191
+ always has, so every camera configured that way and anyone holding a ready-made
192
+ address is unaffected. A recorder with no configured entry is refused with a
193
+ sentence a property manager can act on rather than a code.
194
+
195
+ New: `POST /site-cameras/site/:siteId/test` - does this address actually show a
196
+ picture? Site-scoped because the camera does not exist yet, and it requires
197
+ `site-settings:manage-cctv-camera`. The probe is read only: one TCP connect with
198
+ no credential, then at most one video frame off the stream. There is no mutating
199
+ call in the path.
200
+
201
+ It is rationed before it can reach a device - one test per camera per 15 s, four
202
+ per recorder per 5 minutes - and it consults the shared authentication failure
203
+ budget first, so pressing the button cannot walk a recorder into its own
204
+ 3-failures-in-30-seconds, 1800-second lockout. It answers with one of five plain
205
+ sentences and never an address, port, credential or device message.
206
+
207
+ `ffmpeg`'s stderr is now read for one fact - was the handshake rejected - and
208
+ discarded chunk by chunk without being accumulated, logged or returned, so "the
209
+ recorder refused the credential" can be told apart from "the channel is not
210
+ sending video". Snapshot failures gain that distinction too.
211
+
212
+ `authorizeSite` takes an optional permission list; existing callers are unchanged
213
+ and still require the camera view permissions.
214
+
215
+ - 62e4eb6: Authorize creating, editing and deleting a site camera.
216
+
217
+ `POST /site-cameras`, `PATCH /site-cameras/id/:id` and `DELETE
218
+ /site-cameras/id/:id` carried `requireAuth` and nothing else. There was no
219
+ permission check and no site scoping, so any signed-in account in any
220
+ organisation could add a camera to a site it has no relationship with, rewrite
221
+ another customer's camera address, or hard-delete one - the delete is a real
222
+ `deleteOne`, not a soft delete, and it reported success whether or not it matched
223
+ anything.
224
+
225
+ All three now go through `authorizeSite`, the same rule the read paths already
226
+ use: the caller must be a member of the camera's site, and their role must hold
227
+ the permission the Settings panel that draws the button is drawn on -
228
+ `site-settings:manage-cctv-camera` for a CCTV camera, `site-settings:manage-anpr-camera`
229
+ for an ANPR one. One endpoint serves both panels, so the permission follows the
230
+ camera's own `type` rather than being one string for both; asking only for the
231
+ CCTV string would have refused a role provisioned to manage ANPR alone.
232
+
233
+ For `PATCH` and `DELETE` the site and the type are read off the stored camera,
234
+ never off the request - `schemaUpdateSiteCamera` carries neither, and a caller
235
+ must not be able to supply either. A camera the caller may not reach is reported
236
+ exactly as a camera that does not exist, so the difference cannot be used to
237
+ enumerate camera ids.
238
+
239
+ Measured on staging before shipping: of the 107 users entitled to a site that has
240
+ a CCTV camera, 12 pass this gate and every one of them passes on the `*`
241
+ wildcard. No role that would now be refused holds any `site-settings:` string at
242
+ all, so no account that can open the CCTV or ANPR panel today is refused by this
243
+ change.
244
+
245
+ No response shape, status code or field changed for a permitted caller.
246
+
247
+ - 0af88b8: Add the staff console endpoints that set up, change and read back a client subscription, and the optional plan, start date, end date and billing mode fields they store.
248
+ - 348fde3: Stop the dashboards reporting figures nothing measured, and stop a recorder
249
+ socket being reported as camera health.
250
+
251
+ Five values were being returned in a shape that made "we measured this" and "we
252
+ never measured this" indistinguishable. Each is now either computed from real
253
+ data or returned as an explicit `null` with a reason a client can show.
254
+
255
+ **Patrol Compliance showed 100% on a site with no patrol data.**
256
+ `complianceRate` fell back to `100` when the checkpoint total was 0, so a site
257
+ with no patrol logs drew the same tile a perfect week draws - and a failed
258
+ request drew 0%. `calculateComplianceRate` now returns `null` when no checkpoint
259
+ was due, alongside `patrolCompliance.checkpointsDue` and an
260
+ `unavailableReason`. The Virtual Patrol process itself is untouched; this is
261
+ reporting only.
262
+
263
+ **"0 high severity" was a hard-coded literal**, at `openIncidents.highSeverity`
264
+ in both the security and property dashboards, on every site, on every day. It
265
+ read as "we checked your incidents and none of them are serious". Incident
266
+ reports record no severity at all - `TIncidentReport` has no severity, priority
267
+ or criticality field, and the only `highPriority` flags in this package are on
268
+ work orders and feedbacks - so there is nothing to count. It now returns `null`
269
+ with `highSeverityUnavailableReason`. `highSeverityIncidentCount` counts rather
270
+ than hard-returning `null`, so the tile starts telling the truth on its own the
271
+ day the incident form records a severity. Nothing is guessed in the meantime.
272
+
273
+ **The trend percentage compared the wrong period, in the wrong timezone.** The
274
+ `+/-%` beside every KPI tile was always today-vs-yesterday even on the Week and
275
+ Month views, so a month's count sat next to a yesterday comparison, unlabelled.
276
+ And the day boundary came from `new Date()` + `setHours(0,0,0,0)` - the HOST's
277
+ midnight - while `formatEndDate` and the period range beside it force
278
+ Asia/Singapore. On a UTC container the two halves disagree by eight hours:
279
+ "today" silently loses SGT 00:00-08:00 while "yesterday" keeps its full 24, so
280
+ the comparison was biased before any data was counted.
281
+
282
+ `getPeriodRange` / `getPreviousPeriodRange` (new,
283
+ `src/utils/dashboard-metrics.util.ts`) state Asia/Singapore explicitly and take
284
+ an injectable clock. Week now compares against the previous ISO week and month
285
+ against the previous month, in all three dashboards plus the facility-booking
286
+ tile. The boundary is correct whatever the host is set to; the host's own `TZ`
287
+ still wants reading by someone with DigitalOcean access, but only to size the
288
+ damage already done.
289
+
290
+ **A missing prior period now yields no percentage.**
291
+ `calculatePercentageChange` returned `100` when the prior period was empty and
292
+ `0` when both were empty, so a first-ever record read as growth and a site where
293
+ nothing has ever happened read as measured stability. Both now return `null`.
294
+
295
+ **"Supply Alert" is not an alert.** The query is `sort by qty ascending, limit
296
+ 3` with no threshold, because `site.supplies` records no stock level to compare
297
+ against - no `minQty`, no `reorderLevel`, no `threshold`, on any model in this
298
+ package. 900 gloves appeared under a heading that said "alert". No threshold is
299
+ invented: the payload now carries `basis: "lowest-quantity"` and
300
+ `thresholdUnavailableReason` so no client can present the list as a low-stock
301
+ warning. The client already relabels the tile "Lowest Stock".
302
+
303
+ **Camera health was a socket on the recorder, presented as the camera's.**
304
+ `probeDevice` is a bare TCP connect to the recorder's RTSP port, cached per
305
+ recorder. That caching is deliberate and worth keeping - twelve channels on one
306
+ device is one connect, not twelve - but it means one dead camera among twelve
307
+ stayed invisible (the recorder still answers, so every channel returned
308
+ `reachable: true`, `health: "ok"`, `reason: null`), and a relay outage read as
309
+ twelve healthy tiles because the relay is never probed.
310
+
311
+ A true per-camera liveness check is not available on this path: it would mean an
312
+ authenticated per-channel RTSP frame grab for every tile on every sweep, which
313
+ is device contact this change is in no position to make or to test and is enough
314
+ of it to reach the recorder's own lockout. So none is faked. Every health answer
315
+ now carries `cameraHealthClaim` - `verified` (`"recorder-video-port"` or
316
+ `"nothing"`), a `verifiedDescription` sentence, and `cameraVerified` /
317
+ `relayVerified` as explicit `null`s - so the response states exactly what was
318
+ checked and cannot be read as a stronger claim. `health` and `reachable` keep
319
+ their existing values and meanings, so the web wall (which already labels this
320
+ "Recorder responding") and the mobile monitoring screen are unaffected. A camera
321
+ that resolves to no recorder reports `"nothing"` rather than a check that
322
+ failed, because no request left the server.
323
+
324
+ Nothing else in the health descriptor overstates itself: `firmwareVersion`,
325
+ `deviceTime` and `driftSeconds` already return `null` with
326
+ `detailUnavailableReason`, and capabilities already carry an explicit
327
+ `"unknown"` state with a reason.
328
+
329
+ **Response contract:** `patrolCompliance.count`, `openIncidents.highSeverity`
330
+ and every tile's `percentage` may now be `null`. Checked against the current
331
+ published client rather than assumed: `DashboardMain.vue` coerces through
332
+ `toNumber(value ?? 0)`, so nothing crashes and nothing prints "null". A `null`
333
+ percentage is coerced to 0, which `v-if="card.percentage"` treats as falsy, so
334
+ the trend pill correctly disappears - the intended behaviour, for free. But a
335
+ `null` compliance rate still draws "0%" and a `null` high-severity count still
336
+ draws "0 high severity" until the layer renders the not-available. So on a site
337
+ with no patrol data the tile moves from a fabricated 100% to a fabricated 0%
338
+ until that lands; both are wrong, and the API is now the half that is right.
339
+ The client-side half is `layer-common` #1229 (open).
340
+
341
+ Dead code removed as a consequence: the local `formatEndDate` and
342
+ `getSiteDayRange` in `new-dashboard.repo.ts` have no remaining callers.
343
+
344
+ Deliberately not changed: the duplicate current-period aggregations (the trend's
345
+ current-side query now matches the tile's own count query and could be dropped,
346
+ but that is an optimisation, not a correctness fix); the Dahua URL convention;
347
+ and the disabled device-control capabilities, which stay off.
348
+
349
+ - f334ae3: Add dedicated physical HID card APIs for PACS and CSN credentials, including
350
+ manual assignment, reader enrollment, cancellation, verified removal, duplicate
351
+ protection, reader configuration checks, identity lookup metadata, and audited
352
+ device events.
353
+ - 907df46: Hold property-manager service-provider invitations for Seven365 approval, and give an invitation a life
354
+
355
+ A property management company inviting a service provider used to reach that
356
+ provider immediately. It now waits for the Seven365 super admin, and the
357
+ provider is told nothing at all until it is approved — no email, no in-app
358
+ message, and the invitation is not even readable to them. Approval is the one
359
+ place an invitation reaches the provider, so there is a single function that can
360
+ leak an unapproved one. An invitation Seven365 sends itself is not held.
361
+
362
+ An invitation now has seven states instead of two: waiting for Seven365, waiting
363
+ for the provider, accepted, not approved (with a reason the property manager
364
+ sees word for word), declined, cancelled and expired. Every change goes through
365
+ one conditional update that moves the row only from an expected state and
366
+ appends an immutable history line in the same write — so approving or accepting
367
+ twice writes nothing the second time, and no path can move an invitation
368
+ silently. Deleting is a soft delete: the row leaves the property manager's list,
369
+ the record and its history stay and remain visible to Seven365.
370
+
371
+ Authorization, which this endpoint did not have: the caller is resolved from the
372
+ session and must belong to the organisation the invitation is sent for — being
373
+ signed in used to be enough to invite a provider to any organisation's site.
374
+ Approving and rejecting require the Seven365 super-admin membership (an org-less
375
+ `members` row of type `admin` whose role is also of type `admin`), not an email
376
+ address, so it behaves the same in staging and production.
377
+
378
+ An already-onboarded provider still never sees sign-up or a one-time code, and
379
+ the sign-up path for a brand-new company is unchanged.
380
+
381
+ ### Patch Changes
382
+
383
+ - b5b41ea: Camera entitlement: an engagement grants a site only to an org-level membership, and permissions resolve against the granting role
384
+
385
+ Two follow-ups to the camera entitlement change:
386
+
387
+ - the engagement branch of `cameraGrant` ignored `members.siteId`, so a member
388
+ pinned to one site could reach every site their organisation is engaged at.
389
+ It now requires an org-level membership, matching the owning-org branch above
390
+ it: a membership pinned to a site never grants a different site.
391
+ - `getUserPermissions` accepts the granting membership's `role`, so a caller
392
+ holding several memberships in one organisation is no longer resolved by
393
+ whichever member document Mongo returns first.
394
+
395
+ - 91ba6e8: Let camera authorization understand engagements, and resolve it against the
396
+ right organisation.
397
+
398
+ Three defects in the same decision, fixed together because they are the same
399
+ question: "may this person reach this site, and on whose behalf?"
400
+
401
+ **1. An engagement was not an entitlement.** The product routes a service
402
+ provider - a security agency, a property management agency - to a customer's
403
+ site through an ACTIVE `customer.sites` record (`{org: provider, siteOrg: owner,
404
+ site}`). 227 of those are active on staging, 53 of them cross-organisation. It
405
+ is the same list the web apps' own site switcher is drawn from
406
+ (`useCustomerSite().getAll()`). No camera authorization code read it, so a guard
407
+ whose agency is contracted at a site was refused the cameras of the site the
408
+ switcher had just offered them. Measured on staging: **11 people reach a site
409
+ holding an active IP camera by this route and no other, 7 of them on wildcard
410
+ `owner` / `Super Admin` roles** - and across all 200 sites the figure is 125
411
+ people, 43 of them on wildcard roles. Nobody loses access; the change is
412
+ additive.
413
+
414
+ **2. `site.org` does not exist.** `authorizeSite` and `authorizeCamera`
415
+ projected `{org: 1}` and tested `site?.org`. All 200 site documents carry
416
+ `orgId`; not one carries `org`. So the org-level branch of the rule - the branch
417
+ for the 90 membership rows (56 people) that carry no `siteId` - could never
418
+ match. It reads `orgId` now, with `org` kept as a fallback. This WIDENS access,
419
+ so it was measured before it was enabled: on staging it admits **0** additional
420
+ people to a site holding a camera, and 14 across all 200 sites.
421
+
422
+ **3. Permissions resolved against an arbitrary organisation.**
423
+ `getUserPermissions({user, org: memberships[0]?.org})` took whichever membership
424
+ Mongo returned first, which for the 22 people who belong to more than one
425
+ organisation is a coin toss - it could read the permissions of an organisation
426
+ that has nothing to do with the site being asked about. It now resolves against
427
+ the membership that actually granted access.
428
+
429
+ Also splits `entitleSite` (may this person reach this site) out of
430
+ `authorizeSite` (that, plus the permission this particular use needs), so a
431
+ plain read of a site's own camera list can be scoped without also being gated on
432
+ a permission that would strand people who are legitimately at the site.
433
+
434
+ No response field changed. No route changed. No device is contacted by any of
435
+ this.
436
+
437
+ - 21d5d74: Scope `GET /site-cameras` to the caller's own site.
438
+
439
+ The site was an OPTIONAL query parameter and nothing on the handler looked at
440
+ the session beyond `requireAuth`. So any signed-in account, in any organisation,
441
+ could page the whole estate's cameras - on staging that is all 15 active IP
442
+ cameras across 3 owner organisations, each record carrying its `host` and its
443
+ `username`. It is the plainest cross-tenant read left in the camera module.
444
+
445
+ `site` is now required, and the caller is authorised against it with
446
+ `entitleSite`: membership of the site, of its owning organisation, or an ACTIVE
447
+ `customer.sites` engagement with it. "Not yours" and "does not exist" answer
448
+ identically, so site ids cannot be enumerated from the difference.
449
+
450
+ **Every caller in the estate already sends `site`** - checked across every
451
+ repository, not assumed:
452
+
453
+ | caller | sends |
454
+ | --------------------------------------------------------------- | ----------------------------- |
455
+ | `iservice365-mobile-app-security` `pages/cctv/index.vue` (live) | `site`, `type: ip`, `page` |
456
+ | `iservice365-mobile-app-security` `useAnprEnabled` (live) | `site`, `type: anpr` |
457
+ | `iservice365-layer-common` `CameraMain.vue` (Site Settings) | `site`, `type`, `page` |
458
+ | `iservice365-layer-common` `CameraWall.vue` | `site`, `type: ip`, `page` |
459
+ | `iservice365-web-app-security` `VirtualPatrolRoutesForm.vue` | `site`, `type: ip`, `page: 1` |
460
+ | `isecure365-mobile-app` `site.service.ts` `getAnprCameras` | `site`, `type: anpr` |
461
+
462
+ So no running client breaks.
463
+
464
+ Deliberately NOT gated on a camera permission. This is the same list the site's
465
+ own Settings panel and the guard's app have always read; on staging only 25 of
466
+ the 118 people entitled to a site with a camera hold a camera-view permission,
467
+ so a permission gate here would strand people who are legitimately at the site.
468
+ Restricting the read to the caller's own sites is the fix; who among them may
469
+ look is a separate decision that needs its own measurement.
470
+
471
+ The repository's 15-minute cache key already carries the site, so a cached page
472
+ can only be served to callers authorised for that same site. No caller id was
473
+ added to the key - it would make the cache per-person for an answer that is
474
+ identical per site.
475
+
476
+ - 8dea8b8: Give the Add / Edit Site form's property details somewhere to land.
477
+
478
+ The Organization app's Add Site form collects eight fields beyond the name,
479
+ category and address: MCST plan no., UEN, date of constitution, financial year
480
+ end, billing quarter, share capital, temporary occupation permit and
481
+ certificate of statutory. **None of them has ever been stored.** On create
482
+ `schemaCustomerSite` rejects any key it does not list, so sending them returns
483
+ 400 - which is why the form quietly leaves them out of the request. On update
484
+ `updateCusSiteById` builds a whitelist of `name`, `address` and `category` and
485
+ drops the rest. The Edit dialog reads them back from the customer-site
486
+ document, so they display as empty every time.
487
+
488
+ Eight optional string fields are added to `schemaCustomerSite`, to
489
+ `TCustomerSite`, to the `MCustomerSite` projection, and to the update
490
+ whitelist. One exported list (`customerSitePropertyFields`) drives both the
491
+ create projection and the update whitelist, so the two cannot drift apart.
492
+
493
+ **Additive and optional only.** No migration, no backfill, no index change,
494
+ nothing written to any existing record. A field the caller did not send stays
495
+ absent from the document rather than being written as an empty string, so a
496
+ customer-site written before this change is byte-identical afterwards and still
497
+ validates. An empty string IS kept, because clearing a field on the Edit form
498
+ has to clear it. Unknown keys are still rejected on create - this widens the
499
+ allow-list, it does not open it.
500
+
501
+ Blast radius, checked across every repository in the organisation rather than
502
+ assumed: `POST /api/customer-sites` has exactly **one** caller in the estate
503
+ (`iservice365-web-app-org` `components/SiteForm.vue`) and `PUT
504
+ /api/customer-sites/:id` has the same one. Every other consumer - all eleven
505
+ Nuxt apps via `layer-common`'s `useCustomerSite`, the resident app, the six
506
+ service-provider mobile apps, `iservice365-mobile-app-security` and
507
+ `isecure365-mobile-app` - only ever reads (`GET`), and reads name their fields
508
+ explicitly. `addViaInvite` sends none of the eight, so the invite-acceptance
509
+ path writes exactly the document it wrote before.
510
+
511
+ Covered by `test/customer-site-property-fields.test.mjs`, which asserts the
512
+ before-and-after shape both ways round: the details are accepted and survive
513
+ into the document, and a create without them still writes none of them.
514
+
515
+ - 78a3053: Stop logging camera and mailer credentials
516
+
517
+ Six places wrote a secret or a resident's details to stdout on an ordinary code
518
+ path. `getTrafficJunction` dumped the whole `TSiteCamera` object — including the
519
+ camera's `username` and plaintext `password` — on every reconnect, and
520
+ `addPlateNumber` logged its argument, which carries the same password plus a
521
+ resident's plate number and owner name. `checkOutBySiteAndPlate` logged the
522
+ matched visitor transaction. `siteCameraRepo.updateById` logged the re-read
523
+ camera document, and `vehicleService.add` logged the whole array of a site's
524
+ cameras, both with credentials in them. `sendEmail` printed `MAILER_PASSWORD`
525
+ itself on every message sent.
526
+
527
+ All now log identifiers, counts and outcomes only, through the module's logger
528
+ rather than `console.log`; the mailer line is removed outright because it
529
+ carried nothing but the secret.
530
+
531
+ - bbd97b4: Fix three Dahua HTTP API defects found by checking our integration against the
532
+ vendor specification (V3.37):
533
+
534
+ - The ANPR reconnect loop retried authentication ten times at one-second
535
+ intervals. The device locks the account for 1800 seconds after three failed
536
+ logins in thirty, so our own recovery could take ANPR down at a site for half
537
+ an hour. Authentication now backs off well past the device's counting window,
538
+ and a network fault is distinguished from an authentication failure.
539
+ - 401 and 403 were handled backwards. Per spec §3.4, 401 is the digest
540
+ challenge (retry) and 403 is a credentials rejection (stop). We treated 403 as
541
+ an account lock and killed the listener, and counted 401s toward a "wrong
542
+ password" warning.
543
+ - `updatePlateNumber`, `bulkInsertPlateNumber` and `removePlateNumber`
544
+ interpolated values into the CGI query string unencoded, against the spec's
545
+ stated RFC 3986 requirement. A plate or owner name containing a space or "&"
546
+ broke the request or appended extra parameters to it.
547
+
548
+ - ac0c6e1: Resolve the seeded platform staff role by type as well as name, so the default staff account cannot be bound to an ordinary organisation role that happens to share the name.
549
+ - ea2f1a3: HID Amico: authorise the card, PIN, discovery and visitor-QR endpoints
550
+
551
+ Ten HID Amico handlers required a session and nothing else. The reader id in
552
+ the URL was the only thing selecting the device, and `GET /readers` returns
553
+ every reader in the estate when no `site` is supplied, so any signed-in account
554
+ could act on any reader at any site of any organisation — assign or delete a
555
+ physical access card, set or clear a keypad PIN, put a reader into card
556
+ enrolment, list a user's stored card values, or revoke a visitor's QR pass.
557
+
558
+ Each of the ten now authorises before it does anything:
559
+
560
+ - `listUserCards`, `assignUserCard`, `enrollUserCard`, `cancelUserCardEnrollment`,
561
+ `deleteUserCard` and `revokeVisitorQr` require `site-settings:manage-entry-pass`
562
+ at the site of the **stored** reader.
563
+ - `getUserPinStatus`, `setUserPin` and `deleteUserPin` allow either that same
564
+ administrator, or the person whose own device user it is — entitlement to the
565
+ reader's site plus an ownership check on `hidUserId`, so the resident and MA
566
+ mobile apps' "Access PIN" screen keeps working while a neighbour's PIN cannot
567
+ be rewritten.
568
+ - `discoverReader` now takes the `site` the reader is being added to and
569
+ authorises it, and the address it may be pointed at is constrained: an
570
+ `http(s)` origin only, no credentials, no path, and never the API host itself
571
+ or the instance-metadata range. `HID_DISCOVERY_ALLOWED_HOSTS` optionally pins
572
+ it to named hosts; unset, nothing changes operationally.
573
+
574
+ A reader that is not yours answers exactly like a reader that does not exist, so
575
+ reader ids cannot be enumerated by watching the difference.
576
+
577
+ **Consumer change required:** `POST /access-management/hid/readers/discover` now
578
+ requires `site` in the body. `HidReaderForm.vue` in `@7365admin1/layer-common` is
579
+ the only caller and must be updated to send it.
580
+
581
+ - db402eb: Add the notification categories the marketplace order flow needs, and a way to
582
+ offer a switch to a vendor organization's staff.
583
+
584
+ Every send funnels through `filterRecipients`, which hands back nobody when the
585
+ category key is not in the catalogue. There was no key for buying or selling, so
586
+ a marketplace order notification would have reached no one; and the existing
587
+ `prelovedMarketplace` key is the resident neighbour noticeboard, so reusing it
588
+ would have meant somebody muting a neighbour's bookshelf silently losing their
589
+ own order updates.
590
+
591
+ Two new keys, deliberately separate from each other and from the noticeboard:
592
+
593
+ - `marketplaceOrder` — "My Marketplace Orders", offered to residents, for the
594
+ buyer's own sub-order changes and the seller's replies.
595
+ - `marketplaceVendorOrder` — "Marketplace Sales", offered to members of an
596
+ organization that sells, for a new sub-order and the buyer's replies.
597
+
598
+ Selling is not granted by a role permission anywhere in the estate — it is a
599
+ flag on the organization (`organizations.isMarketplaceVendor`) — so there is no
600
+ permission resource that could carry the sales switch. `categoriesForPermissions`
601
+ gains an optional `isMarketplaceVendor` ground, the exact twin of the existing
602
+ `isResident`/`residentDefault` pair, and `categoriesForUser` resolves it from the
603
+ organizations the caller is already a member of. No permission string is
604
+ introduced and no role data changes.
605
+
606
+ Additive throughout: both new parameters default to false, so a caller that does
607
+ not pass them is offered precisely what it was offered before. No existing
608
+ category changed its key, label, channels, defaults or offered-set.
609
+
610
+ Both keys are `rendered: true`, so the switches exist the moment this is
611
+ published. The senders live in `iservice365-API-core` and follow immediately —
612
+ the two must reach staging in the same cycle, or the screen shows a switch that
613
+ governs nothing. Setting them `rendered: false` is the alternative, but then
614
+ nothing offers the switch while the senders CAN already deliver, which is the
615
+ worse of the two.
616
+
617
+ - c99436e: Let a person choose which notifications they get, and enforce it where they are
618
+ sent.
619
+
620
+ Adds a `notification-preferences` collection (one row per user, storing only what
621
+ they switched OFF), a catalogue of what the product can notify about and on which
622
+ routes, and an authenticated pair of endpoints for reading and changing your own
623
+ settings — the user comes from the session, never from the request.
624
+
625
+ The guard runs inside `NotificationService.send`, so a switch actually stops the
626
+ message: the in-app copy and the phone alert are filtered independently. Somebody
627
+ with no saved row is never filtered, so behaviour is unchanged until they choose
628
+ to change it.
629
+
630
+ Two notice-board senders tag their messages `module: "feedback"`; they now pass
631
+ the honest category to the guard while leaving the stored tag alone, so switching
632
+ Feedback off does not silence the notice board.
633
+
634
+ - ce464b2: Scope the notification inbox to the signed-in person.
635
+
636
+ Every handler on `/notifications` read the user id out of the query string or
637
+ the URL and acted on it without comparing it to the session, so any signed-in
638
+ account could list another person's notifications, mark them read, and read
639
+ their unread count. Whose inbox is opened now comes from the session; a request
640
+ naming somebody else is refused rather than quietly served.
641
+
642
+ `POST /notifications` writes into up to 5000 inboxes at once and had no
643
+ authorisation beyond being signed in. It now requires a Seven365 super admin.
644
+
645
+ The `user` parameter is still accepted, so no app has to be released in step
646
+ with this: every caller in the organisation already sends its own id.
647
+
648
+ - 8266484: Fix defects in the occurrence-book and patrol modules, and move their day
649
+ windows to Singapore time
650
+
651
+ - Every day window in the occurrence-book and patrol queries is now
652
+ Asia/Singapore (UTC+8), midnight to midnight. Computed in UTC, a day ran
653
+ 08:00–08:00 SGT, so an entry or a patrol scan logged at 00:30 fell into the
654
+ previous day and the guard who made it could not find it under "today".
655
+ Stored data and response shapes are unchanged; only the window moves.
656
+ - Occurrence-book date filter returned the previous day for `DD/MM/YYYY`
657
+ callers, and rejected the ISO form its own validation accepts.
658
+ - Occurrence-book pagination was collapsed to page one whenever a date filter
659
+ was set, while the response still reported the full page count.
660
+ - Occurrence-entry search by book number could never match, because `$regex`
661
+ was applied to the numeric `bookEntryCount`.
662
+ - `PUT /api/patrol-logs/id/:id` and `PUT /api/patrol-routes/id/:id` answered
663
+ HTTP 200 when the update matched no document, so a failed incident-report
664
+ attach was reported to the user as a success.
665
+ - Amending an occurrence entry whose subject or signature had been deleted
666
+ answered HTTP 500; and deleting an already-deleted patrol route answered
667
+ HTTP 500 instead of succeeding.
668
+
669
+ - 6315a67: Promo codes: enforce expiry and disabled at redemption, and let staff edit, disable and remove a code
670
+ - b762baf: Make the "an invitation is already waiting" check actually find the invitation
671
+
672
+ The duplicate-invitation guard added with the existing-provider invite fix never
673
+ fired. Invitations are written with `metadata.siteId` as an ObjectId, but the
674
+ lookup searched for the site id as the plain string it arrived as on the request,
675
+ and MongoDB does not treat the two as equal. The query therefore always came back
676
+ empty: a property manager could send the same service provider a second, third
677
+ and fourth invitation for the same site while the first was still valid, and each
678
+ one produced another email and another pending row for them to chase.
679
+
680
+ The lookup now matches either form, so older records that hold the string are
681
+ still found. Nothing else changes: the refusal message and the status code are
682
+ the ones already shipped.
683
+
684
+ - d6c92d7: Stop rejecting site names that only differ by their building number
685
+
686
+ Adding a site refused any name within a Levenshtein distance of 2 of an
687
+ existing site in the same organisation, and told the user to contact support.
688
+ That is exactly one character, so "Winsland House II" could not be added next
689
+ to "Winsland House I". The same rule blocked "Tower A" beside "Tower B",
690
+ "Phase 2" beside "Phase 1" and "Block 15" beside "Block 5" — the standard way
691
+ buildings are named here.
692
+
693
+ The check now treats trailing numbers, Roman numerals and single letters as the
694
+ part that tells two buildings apart: if they differ, the names are different
695
+ sites and the distance is never measured. Real duplicates are still refused —
696
+ an exact repeat, a different capitalisation, stray or doubled whitespace,
697
+ punctuation-only differences, and a one or two character typo within the same
698
+ building. "House 1" and "House I" are still read as the same building.
699
+
700
+ The refusal now names the site it matched and says what to do about it instead
701
+ of pointing the user at support.
702
+
703
+ `site.repo.getByExactName` also built its case-insensitive regex from the raw
704
+ name; a name containing regex characters either threw or matched a site it is
705
+ not. It is escaped.
706
+
707
+ - b803f36: Staff console authorization: subscriptions, plans, promo codes, client status and platform Terms now require a Seven365 staff membership
708
+
709
+ The organisation, subscription, subscription-plan, promo-code and platform-terms
710
+ controllers checked only that a session existed, so every write behind the
711
+ Seven365 staff console was reachable by any signed-in account on the platform.
712
+
713
+ - `requirePlatformStaff` (new `src/utils/console-authz.util.ts`) gates the writes
714
+ that are ours to make: creating an organisation, suspending or reactivating a
715
+ client, the plan catalogue, minting a promo code, and publishing platform-wide
716
+ Terms. It reuses `isSuperAdmin` — a `members` row of type "admin" whose role is
717
+ also of type "admin" — the same check SP Approvals, Marketplace Vendors and the
718
+ notification broadcast already use. No role-name string takes part.
719
+ - `requireOrgAccess` gates the two writes a client legitimately makes on their
720
+ own account — editing their organisation during onboarding, and changing the
721
+ seat count on their own subscription. The organisation is read off the stored
722
+ subscription, never off the request.
723
+ - `POST /terms` took `createdBy` from the request body; it is now the session, so
724
+ published Terms can no longer be attributed to somebody else. The `user` field
725
+ is still accepted and ignored, so no application has to be released in step.
726
+ - The two `organizations/v2` reads page over every organisation on the platform
727
+ with its subscription and billing data; they are gated to staff for the same
728
+ reason.
729
+
730
+ The paid signup checkout and self-signup organisation creation are deliberately
731
+ left open — they are customer paths, and a test pins them that way.
732
+
733
+ - 2e0b41a: Terms acceptance: gate the per-user status and accept handlers to the person themselves
734
+
3
735
  ## 3.46.0
4
736
 
5
737
  ### Minor Changes