@7365admin1/core 3.52.2-staging.238 → 3.52.2

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,66 @@
1
1
  # @iservice365/core
2
2
 
3
+ ## 3.52.2
4
+
5
+ ### Patch Changes
6
+
7
+ - cfd7739: Fix the mailer transport defaults: an unset or unparseable port no longer resolves to `NaN`, and `MAILER_TRANSPORT_SECURE` now defaults to match the port instead of a fixed `false`. Same `Number(...) ?? n` fix applied to `PORT` and `REDIS_PORT`.
8
+ - eea5d0a: Self-service onboarding: email a contractor and every member their own pass link, and let them ask for it again (DV-0080).
9
+
10
+ Registration used to email `guest` submissions only. A contractor now gets the same mail — whether
11
+ the site auto-approved them or left them pending — and so does every member who supplied an email
12
+ address, each with their OWN pass link rather than the lead's. Members who arrive on a pending
13
+ group are emailed when staff approve it, through the same fan-out that creates their records.
14
+
15
+ The staff Approve/Reject notification was also `guest`-only and now covers a self-service
16
+ contractor group and its members, so nobody is left holding a link they do not know went live,
17
+ or one that no longer works. A group raised through the resident-app invite flow is deliberately
18
+ excluded — its members are already told by that flow's own invitation email, and they hold a
19
+ resident-app registration link rather than a self-service pass link.
20
+
21
+ `self-service-visitor.hbs` grew a contractor shape rather than a second template: Company and
22
+ Contractor Type on, passenger count, arrival time, duration and purpose off. Its context, its
23
+ subject line and the NRIC mask moved into `self-service-email.util.ts`, which all three senders
24
+ now share.
25
+
26
+ New public `resendSelfServicePass` controller, behind
27
+ `POST /api/visitor-transactions/self-service/resend/:id`. An address already on a record can never
28
+ be redirected — a supplied one is only accepted for a record whose `email` is blank, which is the
29
+ case the links card's inline field exists for — and a 60-second per-record cooldown sits on top of
30
+ the route's per-IP limiter. The route now only ever accepts self-service records: registration
31
+ stamps every lead and member row with `source: "self-service"`, and the resend lookup filters on
32
+ it, so a public caller can no longer read, re-address or resend a staff-created walk-in, delivery
33
+ or resident-app invite via a guessed or harvested id — a non-self-service id answers the same 404
34
+ as one that does not exist at all.
35
+
36
+ `schemaSelfServiceVisitor.members[]` accepts `email` and now requires it. Both the lead's and each
37
+ member's email in that schema deliberately validate with `tlds: { allow: false }` — the client-side
38
+ check and the resend route's own check both use a looser regex with no IANA TLD list, and a
39
+ mismatch would 400 an entire submission over a field the contractor can no longer see once the
40
+ members dialog has closed. The mail server stays the real judge of deliverability.
41
+
42
+ - b59a636: Vehicle management: make deleting and editing a vehicle safe against the ANPR cameras.
43
+
44
+ Deleting a vehicle no longer reports success when the plate is still on a camera. `bypass` now defaults to false, `removePlateNumber` returns an explicit per-camera outcome instead of swallowing its error, and a delete that cannot be confirmed on every camera holding the plate is refused with the record left intact so it can be retried. A site with no ANPR camera has nothing to revoke and now deletes successfully instead of failing with "No site cameras found."
45
+
46
+ Each camera is asked for its own record id before the removal, because a Dahua `recNo` is a per-device sequence number and the one stored on the vehicle only matches whichever camera was written last. Editing only the vehicle's name now removes the old whitelist record before inserting the new one, instead of leaving the previous entry on the camera for good.
47
+
48
+ Also: `pullVehicleByRecNo` is scoped to the person or site the plate belongs to (it matched on the record id alone, which is not unique across devices), the paginated camera lookups no longer skip their last page, and editing or deleting a vehicle now requires `vehicle-mgmt:update-vehicle` / `vehicle-mgmt:delete-vehicle` on the server, matching the gate the apps already apply in the browser.
49
+
50
+ - 643a92a: Vehicle ANPR: create now fails closed, an unregistered vehicle can be deleted, and camera errors are readable
51
+
52
+ - `add()` no longer reports "added to whitelist successfully" when nothing was written to a camera. Camera failures are collected per camera, any plate already written is taken back off, and the whole create is refused. A site with no active ANPR camera saves the vehicle but says plainly that the barrier does not know about it.
53
+ - Deleting a vehicle with a blank or missing `recno` is no longer rejected by request validation. The per-camera revoke guarantee is unchanged.
54
+ - Dahua's own reply (`Invalid Authority!`, `{"ErrorCode":...}`) is logged server-side and no longer put into the message the operator sees, on create, approve and edit.
55
+ - Editing a vehicle restores the previous plate on the camera if the re-insert fails, instead of leaving the resident locked out by a change the database then rolls back.
56
+
57
+ - d904033: Vehicle management: a deleted plate is gone from every list, a plate with no camera record can be deleted, and a camera blip no longer raises an alarm
58
+
59
+ - Deleting a vehicle is a soft delete, and no read path filtered on it — so the row never disappeared from the vehicle list, still sat on the blocklist (still stopping the car at the barrier), still filled the by-unit lookup, the season-pass options and the row counts, and still blocked re-creating that plate number. `getVehicles`, `getBlocklistedVehicles`, `getBlocklistedVehicleByPlateNumber`, `getAllVehiclesByUnitId` and `getSeasonPassTypes` now exclude deleted records, and `getVehicleById` drops deleted sibling plates. An explicit `status=deleted` is still honoured, which is the only way to look at them.
60
+ - Creating a vehicle no longer refuses a plate number that only exists on a deleted record. A live duplicate is still refused.
61
+ - The two database writes at the end of a delete ran together on one session inside one transaction; they now run in order. The person-side failure no longer reports itself as an NRIC problem and logs its real cause.
62
+ - An ANPR camera alert now waits for the third consecutive failed reconnect instead of the first. Writing a plate to a camera drops that camera's own event stream while the device services the write, so a successful "add vehicle" raised "the camera is not responding — ask your site technician" at the exact moment it succeeded.
63
+
3
64
  ## 3.52.1
4
65
 
5
66
  ### Patch Changes
package/dist/index.js CHANGED
@@ -18228,7 +18228,13 @@ function usePersonRepo() {
18228
18228
  { session }
18229
18229
  );
18230
18230
  } catch (error) {
18231
- throw new import_node_server_utils41.InternalServerError("Failed to pull vehicle plates by nric.");
18231
+ import_node_server_utils41.logger.log({
18232
+ level: "error",
18233
+ message: `pullVehicleByRecNo failed on ${matchKey} for ${owner ? "person" : "site"} ${String(owner ?? site)}: ${error?.message ?? error}`
18234
+ });
18235
+ throw new import_node_server_utils41.InternalServerError(
18236
+ "Could not take the plate off the resident's record."
18237
+ );
18232
18238
  }
18233
18239
  }
18234
18240
  async function getByUserId(userId) {
@@ -21273,6 +21279,7 @@ function useVehicleRepo() {
21273
21279
  throw new import_node_server_utils50.InternalServerError("Unable to connect to server.");
21274
21280
  }
21275
21281
  const collection = db2.collection(vehicles_namespace_collection);
21282
+ const NOT_DELETED = { status: { $ne: "deleted" /* DELETED */ } };
21276
21283
  async function createIndex() {
21277
21284
  try {
21278
21285
  await collection.createIndexes([
@@ -21329,7 +21336,10 @@ function useVehicleRepo() {
21329
21336
  }) {
21330
21337
  page = page > 0 ? page - 1 : 0;
21331
21338
  const baseQuery = {
21332
- ...status && { status },
21339
+ // An explicit `status` is still honoured as it was - including
21340
+ // `status=deleted`, which is the only way to see deleted plates and is
21341
+ // what an audit view would ask for.
21342
+ ...status ? { status } : NOT_DELETED,
21333
21343
  ...type && { type },
21334
21344
  ...category && { category },
21335
21345
  ...site && { site: new import_mongodb42.ObjectId(site) }
@@ -21540,7 +21550,7 @@ function useVehicleRepo() {
21540
21550
  }
21541
21551
  try {
21542
21552
  const categories = await collection.aggregate([
21543
- { $match: { site } },
21553
+ { $match: { site, ...NOT_DELETED } },
21544
21554
  {
21545
21555
  $group: {
21546
21556
  _id: "$seasonPassType",
@@ -21715,7 +21725,19 @@ function useVehicleRepo() {
21715
21725
  cond: {
21716
21726
  $and: [
21717
21727
  { $ne: ["$$plate.plateNumber", null] },
21718
- { $ne: ["$$plate.plateNumber", ""] }
21728
+ { $ne: ["$$plate.plateNumber", ""] },
21729
+ // The plate that was ASKED for is always returned,
21730
+ // deleted or not - Restore, Approve and Blocklist
21731
+ // all read the record by its own id. Its deleted
21732
+ // SIBLINGS are dropped, so the Preview dialog of a
21733
+ // live resident stops offering actions on plates
21734
+ // that have been deleted.
21735
+ {
21736
+ $or: [
21737
+ { $eq: ["$$plate._id", "$$vehicleId"] },
21738
+ { $ne: ["$$plate.status", "deleted"] }
21739
+ ]
21740
+ }
21719
21741
  ]
21720
21742
  }
21721
21743
  }
@@ -21983,7 +22005,8 @@ function useVehicleRepo() {
21983
22005
  try {
21984
22006
  const unit = (0, import_node_server_utils50.toObjectId)(unitId);
21985
22007
  const query2 = {
21986
- unit
22008
+ unit,
22009
+ ...NOT_DELETED
21987
22010
  };
21988
22011
  const items = await collection.find(query2, {
21989
22012
  projection: {
@@ -22084,6 +22107,7 @@ function useVehicleRepo() {
22084
22107
  page = page > 0 ? page - 1 : 0;
22085
22108
  const baseQuery = {
22086
22109
  type: "blocklist" /* BLOCKLIST */,
22110
+ ...NOT_DELETED,
22087
22111
  ...site && {
22088
22112
  site: typeof site === "string" ? new import_mongodb42.ObjectId(site) : site
22089
22113
  }
@@ -22150,6 +22174,8 @@ function useVehicleRepo() {
22150
22174
  const baseQuery = {
22151
22175
  type: "blocklist" /* BLOCKLIST */,
22152
22176
  plateNumber,
22177
+ // A blocklist entry that was deleted must stop blocking the car.
22178
+ ...NOT_DELETED,
22153
22179
  ...site && {
22154
22180
  site: typeof site === "string" ? new import_mongodb42.ObjectId(site) : site
22155
22181
  }
@@ -22360,7 +22386,7 @@ function cameraCredentialsMessage(camera) {
22360
22386
  function cameraNotAuthorisedMessage(camera) {
22361
22387
  return `${describeCamera(camera)} rejected our connection, so it cannot read plates. This usually means its account is not allowed to use the plate-reading feed. Please ask your site technician or the security-system installer to check the camera's account permissions.`;
22362
22388
  }
22363
- var CAMERA_ALERT_AT_ATTEMPT = [1, 6, 30, 90];
22389
+ var CAMERA_ALERT_AT_ATTEMPT = [3, 6, 30, 90];
22364
22390
  var CAMERA_ALERT_EVERY_AFTER = 90;
22365
22391
  function shouldAlertOnFailure(consecutiveFailures) {
22366
22392
  if (!Number.isInteger(consecutiveFailures) || consecutiveFailures < 1)
@@ -35298,7 +35324,11 @@ function useVehicleService() {
35298
35324
  };
35299
35325
  if (vehicleValue.status && vehicleValue.status !== "pending" /* PENDING */) {
35300
35326
  const siteObjectId = new import_mongodb67.ObjectId(vehicleValue.site);
35301
- const existingPlateNumber = await findOne({ plateNumber, site: siteObjectId });
35327
+ const existingPlateNumber = await findOne({
35328
+ plateNumber,
35329
+ site: siteObjectId,
35330
+ status: { $ne: "deleted" /* DELETED */ }
35331
+ });
35302
35332
  if (existingPlateNumber) {
35303
35333
  throw new import_node_server_utils99.BadRequestError(`Vehicle plate number ${plateNumber} already exists.`);
35304
35334
  }
@@ -35472,17 +35502,12 @@ function useVehicleService() {
35472
35502
  throw new import_node_server_utils99.BadRequestError(message);
35473
35503
  import_node_server_utils99.logger.warn(`deleteVehicle bypassed a failed ANPR revoke: ${message}`);
35474
35504
  }
35475
- await Promise.all([
35476
- _deleteVehicle(_id, session),
35477
- // `plateNumber` is the fallback key. Pulling on an EMPTY `recNo` would
35478
- // match every other unregistered plate on the same person or site -
35479
- // five vehicles share the blank value on staging today.
35480
- _pullVehicleByRecNo(
35481
- recno,
35482
- { peopleId: vehicle?.peopleId, site, plateNumber },
35483
- session
35484
- )
35485
- ]);
35505
+ await _deleteVehicle(_id, session);
35506
+ await _pullVehicleByRecNo(
35507
+ recno,
35508
+ { peopleId: vehicle?.peopleId, site, plateNumber },
35509
+ session
35510
+ );
35486
35511
  await session.commitTransaction();
35487
35512
  return `Vehicle plate number deleted from ${type} record successfully.`;
35488
35513
  } catch (error) {