@7365admin1/core 3.53.9 → 3.54.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -536,13 +536,13 @@ var require_logger = __commonJS({
536
536
  "use strict";
537
537
  exports.__esModule = true;
538
538
  var _utils = require_utils();
539
- var logger220 = {
539
+ var logger222 = {
540
540
  methodMap: ["debug", "info", "warn", "error"],
541
541
  level: "info",
542
542
  // Maps a given level value to the `methodMap` indexes above.
543
543
  lookupLevel: function lookupLevel(level) {
544
544
  if (typeof level === "string") {
545
- var levelMap = _utils.indexOf(logger220.methodMap, level.toLowerCase());
545
+ var levelMap = _utils.indexOf(logger222.methodMap, level.toLowerCase());
546
546
  if (levelMap >= 0) {
547
547
  level = levelMap;
548
548
  } else {
@@ -553,9 +553,9 @@ var require_logger = __commonJS({
553
553
  },
554
554
  // Can be overridden in the host environment
555
555
  log: function log(level) {
556
- level = logger220.lookupLevel(level);
557
- if (typeof console !== "undefined" && logger220.lookupLevel(logger220.level) <= level) {
558
- var method = logger220.methodMap[level];
556
+ level = logger222.lookupLevel(level);
557
+ if (typeof console !== "undefined" && logger222.lookupLevel(logger222.level) <= level) {
558
+ var method = logger222.methodMap[level];
559
559
  if (!console[method]) {
560
560
  method = "log";
561
561
  }
@@ -566,7 +566,7 @@ var require_logger = __commonJS({
566
566
  }
567
567
  }
568
568
  };
569
- exports["default"] = logger220;
569
+ exports["default"] = logger222;
570
570
  module2.exports = exports["default"];
571
571
  }
572
572
  });
@@ -5933,11 +5933,13 @@ __export(src_exports, {
5933
5933
  CameraType: () => CameraType,
5934
5934
  ConsoleAuditAction: () => ConsoleAuditAction,
5935
5935
  ConsoleAuditTarget: () => ConsoleAuditTarget,
5936
+ DEFAULT_RING_SECONDS: () => DEFAULT_RING_SECONDS,
5936
5937
  DEFAULT_SITE_TIMEZONE: () => DEFAULT_SITE_TIMEZONE,
5937
5938
  DEVICE_STATUS: () => DEVICE_STATUS,
5938
5939
  DOBStatus: () => DOBStatus,
5939
5940
  DUPLICATE_TERMS_VERSION_MESSAGE: () => DUPLICATE_TERMS_VERSION_MESSAGE,
5940
5941
  DayOfWeek: () => DayOfWeek,
5942
+ E164: () => E164,
5941
5943
  EAccessCardTypes: () => EAccessCardTypes,
5942
5944
  EAccessCardUserTypes: () => EAccessCardUserTypes,
5943
5945
  EmailSender: () => EmailSender,
@@ -5960,6 +5962,8 @@ __export(src_exports, {
5960
5962
  MAX_BULK_CAMERA_ROWS: () => MAX_BULK_CAMERA_ROWS,
5961
5963
  MAX_CAMERA_CHANNEL: () => MAX_CAMERA_CHANNEL,
5962
5964
  MAX_CAMERA_NAME_LENGTH: () => MAX_CAMERA_NAME_LENGTH,
5965
+ MAX_PERSONAL_EMERGENCY_CONTACTS: () => MAX_PERSONAL_EMERGENCY_CONTACTS,
5966
+ MAX_RING_SECONDS: () => MAX_RING_SECONDS,
5963
5967
  MAccessCard: () => MAccessCard,
5964
5968
  MAccessCardTransaction: () => MAccessCardTransaction,
5965
5969
  MAddress: () => MAddress,
@@ -5993,6 +5997,7 @@ __export(src_exports, {
5993
5997
  MHidAmicoReader: () => MHidAmicoReader,
5994
5998
  MHidSipAccount: () => MHidSipAccount,
5995
5999
  MHidSitePermissions: () => MHidSitePermissions,
6000
+ MIN_RING_SECONDS: () => MIN_RING_SECONDS,
5996
6001
  MIncidentReport: () => MIncidentReport,
5997
6002
  MManpowerDesignations: () => MManpowerDesignations,
5998
6003
  MManpowerMonitoring: () => MManpowerMonitoring,
@@ -6018,6 +6023,7 @@ __export(src_exports, {
6018
6023
  MPatrolQuestion: () => MPatrolQuestion,
6019
6024
  MPatrolRoute: () => MPatrolRoute,
6020
6025
  MPerson: () => MPerson,
6026
+ MPersonalEmergencyChain: () => MPersonalEmergencyChain,
6021
6027
  MPlatformTerms: () => MPlatformTerms,
6022
6028
  MPost: () => MPost,
6023
6029
  MPostFavorite: () => MPostFavorite,
@@ -6160,6 +6166,7 @@ __export(src_exports, {
6160
6166
  deviceHttpTimeoutMs: () => deviceHttpTimeoutMs,
6161
6167
  deviceProbeTtlSeconds: () => deviceProbeTtlSeconds,
6162
6168
  emitNotificationCreated: () => emitNotificationCreated,
6169
+ emptyPersonalEmergencyChain: () => emptyPersonalEmergencyChain,
6163
6170
  encodeHidPacsCard: () => encodeHidPacsCard,
6164
6171
  entitledSiteScope: () => entitledSiteScope,
6165
6172
  events_namespace_collection: () => events_namespace_collection,
@@ -6342,6 +6349,7 @@ __export(src_exports, {
6342
6349
  schemaPatrolQuestion: () => schemaPatrolQuestion,
6343
6350
  schemaPatrolRoute: () => schemaPatrolRoute,
6344
6351
  schemaPerson: () => schemaPerson,
6352
+ schemaPersonalEmergencyContact: () => schemaPersonalEmergencyContact,
6345
6353
  schemaPlate: () => schemaPlate,
6346
6354
  schemaPlatformTerms: () => schemaPlatformTerms,
6347
6355
  schemaPost: () => schemaPost,
@@ -6387,6 +6395,7 @@ __export(src_exports, {
6387
6395
  schemaUpdatePatrolQuestion: () => schemaUpdatePatrolQuestion,
6388
6396
  schemaUpdatePatrolRoute: () => schemaUpdatePatrolRoute,
6389
6397
  schemaUpdatePerson: () => schemaUpdatePerson,
6398
+ schemaUpdatePersonalEmergencyChain: () => schemaUpdatePersonalEmergencyChain,
6390
6399
  schemaUpdatePost: () => schemaUpdatePost,
6391
6400
  schemaUpdatePostFavorite: () => schemaUpdatePostFavorite,
6392
6401
  schemaUpdateServiceProviderBilling: () => schemaUpdateServiceProviderBilling,
@@ -6567,6 +6576,9 @@ __export(src_exports, {
6567
6576
  usePatrolRouteRepo: () => usePatrolRouteRepo,
6568
6577
  usePersonController: () => usePersonController,
6569
6578
  usePersonRepo: () => usePersonRepo,
6579
+ usePersonalEmergencyChainController: () => usePersonalEmergencyChainController,
6580
+ usePersonalEmergencyChainRepo: () => usePersonalEmergencyChainRepo,
6581
+ usePersonalEmergencyChainService: () => usePersonalEmergencyChainService,
6570
6582
  usePlatformTermsController: () => usePlatformTermsController,
6571
6583
  usePlatformTermsRepo: () => usePlatformTermsRepo,
6572
6584
  usePlatformTermsService: () => usePlatformTermsService,
@@ -14875,12 +14887,15 @@ var NOTIFICATION_CATEGORIES = [
14875
14887
  channelNote: { email: NO_EMAIL_RECIPIENT },
14876
14888
  permissionResources: ["emergency-contact"],
14877
14889
  safety: true,
14878
- // Nothing sends this. The sender below exists, but the only place emergency
14879
- // contacts are written is `iservice365-API-core`, and the change that would
14880
- // have called it from there (API-core #997) was closed, not merged. Until a
14881
- // caller exists this stays out of the screen rather than offering a switch
14882
- // over a message that never arrives.
14883
- rendered: false
14890
+ // A caller exists again. `iservice365-API-core` is still the only place a
14891
+ // site's emergency contacts are written, and its `emergency.service.ts`
14892
+ // now calls the sender below on each of the three writes. That caller
14893
+ // reads THIS flag before it sends (`notificationCategory("emergencyContact")
14894
+ // ?.rendered`), so the two halves cannot land out of order and leave a
14895
+ // safety alert arriving with no switch to turn it off: whichever repository
14896
+ // merges first, the alert only starts once a published core carrying this
14897
+ // line is installed there.
14898
+ rendered: true
14884
14899
  },
14885
14900
  {
14886
14901
  key: "virtualPatrol",
@@ -29898,7 +29913,7 @@ function usePromoCodeRepo() {
29898
29913
  }
29899
29914
  }
29900
29915
  async function updateById(_id, value) {
29901
- const objectId2 = toObjectId25(_id);
29916
+ const objectId2 = toObjectId26(_id);
29902
29917
  const changes = promoCodeUpdate(value);
29903
29918
  const res = await collection.updateOne(
29904
29919
  { _id: objectId2, deletedAt: null },
@@ -29911,7 +29926,7 @@ function usePromoCodeRepo() {
29911
29926
  return res;
29912
29927
  }
29913
29928
  async function updateStatusById(_id, status) {
29914
- const objectId2 = toObjectId25(_id);
29929
+ const objectId2 = toObjectId26(_id);
29915
29930
  const res = await collection.updateOne(
29916
29931
  { _id: objectId2, deletedAt: null },
29917
29932
  { $set: { status } }
@@ -29923,7 +29938,7 @@ function usePromoCodeRepo() {
29923
29938
  return res;
29924
29939
  }
29925
29940
  async function softDeleteById(_id, deletedBy) {
29926
- const objectId2 = toObjectId25(_id);
29941
+ const objectId2 = toObjectId26(_id);
29927
29942
  const res = await collection.updateOne(
29928
29943
  { _id: objectId2, deletedAt: null },
29929
29944
  {
@@ -29940,7 +29955,7 @@ function usePromoCodeRepo() {
29940
29955
  await invalidate(`delete ${objectId2}`);
29941
29956
  return res;
29942
29957
  }
29943
- function toObjectId25(_id) {
29958
+ function toObjectId26(_id) {
29944
29959
  const { error } = import_joi34.default.object({
29945
29960
  _id: import_joi34.default.string().hex().length(24).required()
29946
29961
  }).validate({ _id: String(_id) });
@@ -92070,6 +92085,222 @@ function useNotificationPreferenceController() {
92070
92085
  }
92071
92086
  return { get, update };
92072
92087
  }
92088
+
92089
+ // src/models/personal-emergency-chain.model.ts
92090
+ var import_node_server_utils303 = require("@7365admin1/node-server-utils");
92091
+ var import_mongodb184 = require("mongodb");
92092
+ var import_joi167 = __toESM(require("joi"));
92093
+ var MAX_PERSONAL_EMERGENCY_CONTACTS = 10;
92094
+ var MIN_RING_SECONDS = 5;
92095
+ var MAX_RING_SECONDS = 120;
92096
+ var DEFAULT_RING_SECONDS = 20;
92097
+ var E164 = /^\+[1-9]\d{1,14}$/;
92098
+ var schemaPersonalEmergencyContact = import_joi167.default.object({
92099
+ name: import_joi167.default.string().trim().min(1).max(120).required(),
92100
+ phone: import_joi167.default.string().trim().pattern(E164).required().messages({
92101
+ "string.pattern.base": "Phone number must be in international format, e.g. +6591234567."
92102
+ }),
92103
+ relationship: import_joi167.default.string().trim().max(60).allow("", null).default(""),
92104
+ order: import_joi167.default.number().integer().min(1).max(MAX_PERSONAL_EMERGENCY_CONTACTS).required(),
92105
+ active: import_joi167.default.boolean().default(true)
92106
+ });
92107
+ var schemaUpdatePersonalEmergencyChain = import_joi167.default.object({
92108
+ contacts: import_joi167.default.array().items(schemaPersonalEmergencyContact).unique("order").max(MAX_PERSONAL_EMERGENCY_CONTACTS).required().messages({
92109
+ "array.unique": "Two contacts cannot share the same position in the chain."
92110
+ }),
92111
+ ringSeconds: import_joi167.default.number().integer().min(MIN_RING_SECONDS).max(MAX_RING_SECONDS).default(DEFAULT_RING_SECONDS),
92112
+ siteDirectoryFallback: import_joi167.default.boolean().default(true),
92113
+ org: import_joi167.default.string().hex().length(24).allow("", null).default(null),
92114
+ site: import_joi167.default.string().hex().length(24).allow("", null).default(null)
92115
+ });
92116
+ var toObjectId25 = (value, what) => {
92117
+ if (value === null || value === void 0 || value === "")
92118
+ return null;
92119
+ const id = value.toString();
92120
+ if (!import_mongodb184.ObjectId.isValid(id))
92121
+ throw new import_node_server_utils303.BadRequestError(`Invalid ${what}.`);
92122
+ return new import_mongodb184.ObjectId(id);
92123
+ };
92124
+ function MPersonalEmergencyChain(value) {
92125
+ const user = toObjectId25(value.user, "user ID");
92126
+ if (!user)
92127
+ throw new import_node_server_utils303.BadRequestError("Invalid user ID.");
92128
+ const contacts = [...value.contacts ?? []].map((c) => ({
92129
+ name: c.name.trim(),
92130
+ phone: c.phone.trim(),
92131
+ relationship: (c.relationship ?? "").trim(),
92132
+ order: c.order,
92133
+ active: c.active ?? true
92134
+ })).sort((a, b) => a.order - b.order);
92135
+ const seen = /* @__PURE__ */ new Set();
92136
+ for (const contact of contacts) {
92137
+ if (seen.has(contact.order)) {
92138
+ throw new import_node_server_utils303.BadRequestError(
92139
+ "Two contacts cannot share the same position in the chain."
92140
+ );
92141
+ }
92142
+ seen.add(contact.order);
92143
+ }
92144
+ const now = /* @__PURE__ */ new Date();
92145
+ return {
92146
+ user,
92147
+ org: toObjectId25(value.org, "organization ID"),
92148
+ site: toObjectId25(value.site, "site ID"),
92149
+ contacts,
92150
+ ringSeconds: value.ringSeconds ?? DEFAULT_RING_SECONDS,
92151
+ siteDirectoryFallback: value.siteDirectoryFallback ?? true,
92152
+ createdAt: value.createdAt ?? now,
92153
+ updatedAt: now
92154
+ };
92155
+ }
92156
+ function emptyPersonalEmergencyChain(user) {
92157
+ return {
92158
+ user,
92159
+ org: null,
92160
+ site: null,
92161
+ contacts: [],
92162
+ ringSeconds: DEFAULT_RING_SECONDS,
92163
+ siteDirectoryFallback: true
92164
+ };
92165
+ }
92166
+
92167
+ // src/repositories/personal-emergency-chain.repo.ts
92168
+ var import_mongodb185 = require("mongodb");
92169
+ var import_node_server_utils304 = require("@7365admin1/node-server-utils");
92170
+ function usePersonalEmergencyChainRepo() {
92171
+ const namespace_collection = "personal-emergency-contacts";
92172
+ const getDB2 = () => {
92173
+ const db2 = import_node_server_utils304.useAtlas.getDb();
92174
+ if (!db2) {
92175
+ throw new import_node_server_utils304.InternalServerError("Unable to connect to server.");
92176
+ }
92177
+ return db2;
92178
+ };
92179
+ const collection = () => getDB2().collection(namespace_collection);
92180
+ async function createIndexes() {
92181
+ try {
92182
+ await collection().createIndexes([
92183
+ { key: { user: 1 }, name: "one_chain_per_user", unique: true }
92184
+ ]);
92185
+ return `Successfully created indexes for ${namespace_collection}.`;
92186
+ } catch (error) {
92187
+ import_node_server_utils304.logger.log({ level: "error", message: error.message });
92188
+ throw new import_node_server_utils304.InternalServerError(
92189
+ `Failed to create indexes for ${namespace_collection}.`
92190
+ );
92191
+ }
92192
+ }
92193
+ async function getByUser(user) {
92194
+ if (!import_mongodb185.ObjectId.isValid(user)) {
92195
+ throw new import_node_server_utils304.BadRequestError("Invalid user ID format.");
92196
+ }
92197
+ try {
92198
+ const doc = await collection().findOne({ user: new import_mongodb185.ObjectId(user) });
92199
+ return doc ?? emptyPersonalEmergencyChain(user);
92200
+ } catch (error) {
92201
+ if (error instanceof import_node_server_utils304.AppError)
92202
+ throw error;
92203
+ import_node_server_utils304.logger.log({ level: "error", message: error.message });
92204
+ throw new import_node_server_utils304.InternalServerError("Failed to retrieve emergency contacts.");
92205
+ }
92206
+ }
92207
+ async function replaceForUser(user, value) {
92208
+ const doc = MPersonalEmergencyChain({ ...value, user });
92209
+ try {
92210
+ await collection().updateOne(
92211
+ { user: doc.user },
92212
+ {
92213
+ $set: {
92214
+ contacts: doc.contacts,
92215
+ ringSeconds: doc.ringSeconds,
92216
+ siteDirectoryFallback: doc.siteDirectoryFallback,
92217
+ org: doc.org,
92218
+ site: doc.site,
92219
+ updatedAt: doc.updatedAt
92220
+ },
92221
+ $setOnInsert: { user: doc.user, createdAt: doc.createdAt }
92222
+ },
92223
+ { upsert: true }
92224
+ );
92225
+ return doc;
92226
+ } catch (error) {
92227
+ if (error instanceof import_node_server_utils304.AppError)
92228
+ throw error;
92229
+ import_node_server_utils304.logger.log({ level: "error", message: error.message });
92230
+ throw new import_node_server_utils304.InternalServerError("Failed to save emergency contacts.");
92231
+ }
92232
+ }
92233
+ return { createIndexes, getByUser, replaceForUser };
92234
+ }
92235
+
92236
+ // src/services/personal-emergency-chain.service.ts
92237
+ var import_node_server_utils305 = require("@7365admin1/node-server-utils");
92238
+ function usePersonalEmergencyChainService() {
92239
+ async function getForUser(user) {
92240
+ if (!user)
92241
+ throw new import_node_server_utils305.BadRequestError("No user in session.");
92242
+ return await usePersonalEmergencyChainRepo().getByUser(user);
92243
+ }
92244
+ async function updateForUser(user, value) {
92245
+ if (!user)
92246
+ throw new import_node_server_utils305.BadRequestError("No user in session.");
92247
+ return await usePersonalEmergencyChainRepo().replaceForUser(
92248
+ user,
92249
+ value
92250
+ );
92251
+ }
92252
+ return { getForUser, updateForUser };
92253
+ }
92254
+
92255
+ // src/controllers/personal-emergency-chain.controller.ts
92256
+ var import_node_server_utils306 = require("@7365admin1/node-server-utils");
92257
+ function usePersonalEmergencyChainController() {
92258
+ const { getForUser, updateForUser } = usePersonalEmergencyChainService();
92259
+ async function get(req, res, next) {
92260
+ const userId = req.params.userId;
92261
+ try {
92262
+ await requireSelfOrPlatformStaff(req, userId, {
92263
+ resource: "users",
92264
+ action: "see-user-details"
92265
+ });
92266
+ res.status(200).json({ data: await getForUser(userId) });
92267
+ } catch (error) {
92268
+ import_node_server_utils306.logger.log({ level: "error", message: error.message });
92269
+ next(error);
92270
+ }
92271
+ }
92272
+ async function update(req, res, next) {
92273
+ const userId = req.params.userId;
92274
+ try {
92275
+ await requireSelfOrPlatformStaff(req, userId, {
92276
+ resource: "users",
92277
+ action: "see-user-details"
92278
+ });
92279
+ } catch (error2) {
92280
+ import_node_server_utils306.logger.log({ level: "error", message: error2.message });
92281
+ next(error2);
92282
+ return;
92283
+ }
92284
+ const { error, value } = schemaUpdatePersonalEmergencyChain.validate(
92285
+ req.body,
92286
+ { convert: true }
92287
+ );
92288
+ if (error) {
92289
+ next(new import_node_server_utils306.BadRequestError(error.details[0].message));
92290
+ return;
92291
+ }
92292
+ try {
92293
+ res.status(200).json({
92294
+ message: "success",
92295
+ data: await updateForUser(userId, value)
92296
+ });
92297
+ } catch (err) {
92298
+ import_node_server_utils306.logger.log({ level: "error", message: err.message });
92299
+ next(err);
92300
+ }
92301
+ }
92302
+ return { get, update };
92303
+ }
92073
92304
  // Annotate the CommonJS export names for ESM import in node:
92074
92305
  0 && (module.exports = {
92075
92306
  ANPRMode,
@@ -92116,11 +92347,13 @@ function useNotificationPreferenceController() {
92116
92347
  CameraType,
92117
92348
  ConsoleAuditAction,
92118
92349
  ConsoleAuditTarget,
92350
+ DEFAULT_RING_SECONDS,
92119
92351
  DEFAULT_SITE_TIMEZONE,
92120
92352
  DEVICE_STATUS,
92121
92353
  DOBStatus,
92122
92354
  DUPLICATE_TERMS_VERSION_MESSAGE,
92123
92355
  DayOfWeek,
92356
+ E164,
92124
92357
  EAccessCardTypes,
92125
92358
  EAccessCardUserTypes,
92126
92359
  EmailSender,
@@ -92143,6 +92376,8 @@ function useNotificationPreferenceController() {
92143
92376
  MAX_BULK_CAMERA_ROWS,
92144
92377
  MAX_CAMERA_CHANNEL,
92145
92378
  MAX_CAMERA_NAME_LENGTH,
92379
+ MAX_PERSONAL_EMERGENCY_CONTACTS,
92380
+ MAX_RING_SECONDS,
92146
92381
  MAccessCard,
92147
92382
  MAccessCardTransaction,
92148
92383
  MAddress,
@@ -92176,6 +92411,7 @@ function useNotificationPreferenceController() {
92176
92411
  MHidAmicoReader,
92177
92412
  MHidSipAccount,
92178
92413
  MHidSitePermissions,
92414
+ MIN_RING_SECONDS,
92179
92415
  MIncidentReport,
92180
92416
  MManpowerDesignations,
92181
92417
  MManpowerMonitoring,
@@ -92201,6 +92437,7 @@ function useNotificationPreferenceController() {
92201
92437
  MPatrolQuestion,
92202
92438
  MPatrolRoute,
92203
92439
  MPerson,
92440
+ MPersonalEmergencyChain,
92204
92441
  MPlatformTerms,
92205
92442
  MPost,
92206
92443
  MPostFavorite,
@@ -92343,6 +92580,7 @@ function useNotificationPreferenceController() {
92343
92580
  deviceHttpTimeoutMs,
92344
92581
  deviceProbeTtlSeconds,
92345
92582
  emitNotificationCreated,
92583
+ emptyPersonalEmergencyChain,
92346
92584
  encodeHidPacsCard,
92347
92585
  entitledSiteScope,
92348
92586
  events_namespace_collection,
@@ -92525,6 +92763,7 @@ function useNotificationPreferenceController() {
92525
92763
  schemaPatrolQuestion,
92526
92764
  schemaPatrolRoute,
92527
92765
  schemaPerson,
92766
+ schemaPersonalEmergencyContact,
92528
92767
  schemaPlate,
92529
92768
  schemaPlatformTerms,
92530
92769
  schemaPost,
@@ -92570,6 +92809,7 @@ function useNotificationPreferenceController() {
92570
92809
  schemaUpdatePatrolQuestion,
92571
92810
  schemaUpdatePatrolRoute,
92572
92811
  schemaUpdatePerson,
92812
+ schemaUpdatePersonalEmergencyChain,
92573
92813
  schemaUpdatePost,
92574
92814
  schemaUpdatePostFavorite,
92575
92815
  schemaUpdateServiceProviderBilling,
@@ -92750,6 +92990,9 @@ function useNotificationPreferenceController() {
92750
92990
  usePatrolRouteRepo,
92751
92991
  usePersonController,
92752
92992
  usePersonRepo,
92993
+ usePersonalEmergencyChainController,
92994
+ usePersonalEmergencyChainRepo,
92995
+ usePersonalEmergencyChainService,
92753
92996
  usePlatformTermsController,
92754
92997
  usePlatformTermsRepo,
92755
92998
  usePlatformTermsService,