@7365admin1/core 3.70.0 → 3.71.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.mjs CHANGED
@@ -3607,6 +3607,7 @@ function useMemberRepo() {
3607
3607
  user = "",
3608
3608
  org = "",
3609
3609
  siteId = "",
3610
+ siteIds,
3610
3611
  type = "",
3611
3612
  status = ""
3612
3613
  }) {
@@ -3640,6 +3641,12 @@ function useMemberRepo() {
3640
3641
  throw new BadRequestError13("Invalid site ID format.");
3641
3642
  }
3642
3643
  }
3644
+ if (siteIds) {
3645
+ query2.siteId = {
3646
+ $in: siteIds.filter((id) => ObjectId13.isValid(id)).map((id) => new ObjectId13(id))
3647
+ };
3648
+ cacheOptions.siteIds = [...siteIds].sort().join(",") || "no-site";
3649
+ }
3643
3650
  if (user) {
3644
3651
  try {
3645
3652
  query2.user = new ObjectId13(user);
@@ -9813,6 +9820,15 @@ function pickLookupMembership(rows, type, site = "", org = "") {
9813
9820
  return inOrg;
9814
9821
  return list.find((m) => m.type === type) ?? null;
9815
9822
  }
9823
+ function memberListSiteScope(memberships, org) {
9824
+ const inOrg = (memberships ?? []).filter((m) => idOf2(m.org) === idOf2(org));
9825
+ const here = inOrg.filter((m) => m.type !== "resident");
9826
+ if (!inOrg.length)
9827
+ return null;
9828
+ if (here.some((m) => !idOf2(m.siteId) || m.orgLevelRole))
9829
+ return null;
9830
+ return [...new Set(here.map((m) => idOf2(m.siteId)))];
9831
+ }
9816
9832
 
9817
9833
  // src/services/module-gate.service.ts
9818
9834
  var idOf3 = (v) => v == null ? "" : String(v?._id ?? v).toLowerCase();
@@ -14979,7 +14995,7 @@ function useRoleController() {
14979
14995
 
14980
14996
  // src/controllers/member.controller.ts
14981
14997
  import Joi27 from "joi";
14982
- import { BadRequestError as BadRequestError50, logger as logger37 } from "@7365admin1/node-server-utils";
14998
+ import { BadRequestError as BadRequestError50, logger as logger37, UnauthorizedError as UnauthorizedError9 } from "@7365admin1/node-server-utils";
14983
14999
 
14984
15000
  // src/services/member.service.ts
14985
15001
  import {
@@ -23083,6 +23099,18 @@ function useMemberController() {
23083
23099
  await requireConsolePermission(req, "members", "view-members");
23084
23100
  } else if (org) {
23085
23101
  await requireOrgAccess(req, org);
23102
+ }
23103
+ let siteIds;
23104
+ if (org && type !== "admin") {
23105
+ const actor = await resolveInviteActor(callerId(req));
23106
+ const scope = staffMayBypass(actor) ? null : memberListSiteScope(actor.memberships, org);
23107
+ if (scope) {
23108
+ if (siteId && !scope.includes(siteId.toLowerCase())) {
23109
+ throw new UnauthorizedError9("Not authorized.");
23110
+ }
23111
+ if (!siteId)
23112
+ siteIds = scope;
23113
+ }
23086
23114
  } else if (user && user !== callerId(req)) {
23087
23115
  await requireConsolePermission(req, "users", "see-all-users");
23088
23116
  }
@@ -23093,6 +23121,7 @@ function useMemberController() {
23093
23121
  user,
23094
23122
  org,
23095
23123
  siteId,
23124
+ siteIds,
23096
23125
  type,
23097
23126
  status
23098
23127
  });
@@ -23833,7 +23862,7 @@ function useVerificationController() {
23833
23862
  // src/controllers/file.controller.ts
23834
23863
  import {
23835
23864
  BadRequestError as BadRequestError52,
23836
- UnauthorizedError as UnauthorizedError9,
23865
+ UnauthorizedError as UnauthorizedError10,
23837
23866
  logger as logger39
23838
23867
  } from "@7365admin1/node-server-utils";
23839
23868
  import Joi29 from "joi";
@@ -23862,7 +23891,7 @@ async function requireFileDelete(req, file) {
23862
23891
  return;
23863
23892
  const caller = callerId(req);
23864
23893
  if (!caller)
23865
- throw new UnauthorizedError9("Not authorized.");
23894
+ throw new UnauthorizedError10("Not authorized.");
23866
23895
  if (caller === ownerId)
23867
23896
  return;
23868
23897
  const [me, owner] = await Promise.all([
@@ -23878,7 +23907,7 @@ async function requireFileDelete(req, file) {
23878
23907
  })) {
23879
23908
  return;
23880
23909
  }
23881
- throw new UnauthorizedError9("Not authorized.");
23910
+ throw new UnauthorizedError10("Not authorized.");
23882
23911
  }
23883
23912
  function useFileController() {
23884
23913
  const { createFile, deleteFile: _deleteFile } = useFileService();
@@ -23952,7 +23981,7 @@ import {
23952
23981
  BadRequestError as BadRequestError55,
23953
23982
  logger as logger41,
23954
23983
  NotFoundError as NotFoundError17,
23955
- UnauthorizedError as UnauthorizedError10
23984
+ UnauthorizedError as UnauthorizedError11
23956
23985
  } from "@7365admin1/node-server-utils";
23957
23986
  import Joi32 from "joi";
23958
23987
 
@@ -25257,7 +25286,7 @@ function useOrgController() {
25257
25286
  try {
25258
25287
  const createdBy = callerId(req);
25259
25288
  if (!createdBy)
25260
- throw new UnauthorizedError10("Not authorized.");
25289
+ throw new UnauthorizedError11("Not authorized.");
25261
25290
  const { inviteId, ...body } = req.body ?? {};
25262
25291
  let invitedFrom = null;
25263
25292
  let invitedRole = null;
@@ -27891,7 +27920,7 @@ function useSubscriptionService() {
27891
27920
  import Joi37 from "joi";
27892
27921
  import {
27893
27922
  BadRequestError as BadRequestError71,
27894
- UnauthorizedError as UnauthorizedError11,
27923
+ UnauthorizedError as UnauthorizedError12,
27895
27924
  logger as logger51
27896
27925
  } from "@7365admin1/node-server-utils";
27897
27926
 
@@ -28312,7 +28341,7 @@ function useSubscriptionController() {
28312
28341
  try {
28313
28342
  const subscription = await _getSubscriptionById(subscriptionId);
28314
28343
  if (!subscription) {
28315
- throw new UnauthorizedError11("Not authorized.");
28344
+ throw new UnauthorizedError12("Not authorized.");
28316
28345
  }
28317
28346
  await requireOrgAccess(req, subscription.org?.toString());
28318
28347
  const _res = await _updateSubscriptionSeats({
@@ -34016,7 +34045,7 @@ import {
34016
34045
  BadRequestError as BadRequestError92,
34017
34046
  logger as logger68,
34018
34047
  NotFoundError as NotFoundError26,
34019
- UnauthorizedError as UnauthorizedError12,
34048
+ UnauthorizedError as UnauthorizedError13,
34020
34049
  useAtlas as useAtlas56
34021
34050
  } from "@7365admin1/node-server-utils";
34022
34051
 
@@ -34122,7 +34151,7 @@ function siteModulesHandlers({
34122
34151
  return;
34123
34152
  }
34124
34153
  if (!await mayManage(actor, site)) {
34125
- throw new UnauthorizedError12("Not authorized.");
34154
+ throw new UnauthorizedError13("Not authorized.");
34126
34155
  }
34127
34156
  const org = site.orgId ? await _getOrgById(site.orgId.toString()) : null;
34128
34157
  const rejected = rejectedSiteModules(
@@ -34184,7 +34213,7 @@ function siteModulesHandlers({
34184
34213
  if (!site)
34185
34214
  throw new NotFoundError26("Site not found.");
34186
34215
  if (!await mayManage(actor, site))
34187
- throw new UnauthorizedError12("Not authorized.");
34216
+ throw new UnauthorizedError13("Not authorized.");
34188
34217
  const org = site?.orgId ? await _getOrgById(site.orgId.toString()) : null;
34189
34218
  res.json(
34190
34219
  await siteModulePreview(site, org, normaliseModules(req.body.modules), gateData)
@@ -39496,7 +39525,7 @@ function useCustomerSiteService() {
39496
39525
  import Joi60 from "joi";
39497
39526
  import {
39498
39527
  BadRequestError as BadRequestError107,
39499
- UnauthorizedError as UnauthorizedError13,
39528
+ UnauthorizedError as UnauthorizedError14,
39500
39529
  logger as logger81
39501
39530
  } from "@7365admin1/node-server-utils";
39502
39531
  async function requireEitherOrg(req, ...orgs) {
@@ -39505,7 +39534,7 @@ async function requireEitherOrg(req, ...orgs) {
39505
39534
  if (staffMayBypass(actor))
39506
39535
  return;
39507
39536
  if (wanted.length === 0 || !wanted.some((org) => actor.orgIds.includes(org))) {
39508
- throw new UnauthorizedError13("Not authorized.");
39537
+ throw new UnauthorizedError14("Not authorized.");
39509
39538
  }
39510
39539
  }
39511
39540
  function useCustomerSiteController() {
@@ -42717,7 +42746,7 @@ import {
42717
42746
  BadRequestError as BadRequestError121,
42718
42747
  InternalServerError as InternalServerError44,
42719
42748
  NotFoundError as NotFoundError37,
42720
- UnauthorizedError as UnauthorizedError14,
42749
+ UnauthorizedError as UnauthorizedError15,
42721
42750
  logger as logger93
42722
42751
  } from "@7365admin1/node-server-utils";
42723
42752
 
@@ -46251,8 +46280,8 @@ function useHidAmicoService() {
46251
46280
  await siteAccess.authorizeSite({ siteId, userId: value.userId, permissions });
46252
46281
  }
46253
46282
  } catch (error) {
46254
- if (error instanceof UnauthorizedError14) {
46255
- throw new UnauthorizedError14("You do not have permission to manage HID access at this site.");
46283
+ if (error instanceof UnauthorizedError15) {
46284
+ throw new UnauthorizedError15("You do not have permission to manage HID access at this site.");
46256
46285
  }
46257
46286
  throw error;
46258
46287
  }
@@ -46276,7 +46305,7 @@ function useHidAmicoService() {
46276
46305
  try {
46277
46306
  await authorizeSiteForCaller(String(reader.site || ""), userId);
46278
46307
  } catch (error) {
46279
- if (error instanceof UnauthorizedError14)
46308
+ if (error instanceof UnauthorizedError15)
46280
46309
  throw error;
46281
46310
  throw new NotFoundError37(HID_READER_NOT_FOUND);
46282
46311
  }
@@ -46328,10 +46357,10 @@ function useHidAmicoService() {
46328
46357
  async function assertUserReaderPermission(reader, userId, options = {}) {
46329
46358
  const permission = await getReaderPermissionForUser(reader, userId);
46330
46359
  if (!permission.granted) {
46331
- throw new UnauthorizedError14("You do not have HID access permission for this reader.");
46360
+ throw new UnauthorizedError15("You do not have HID access permission for this reader.");
46332
46361
  }
46333
46362
  if (options.intercom && !permission.intercom) {
46334
- throw new UnauthorizedError14("You do not have HID intercom permission for this reader.");
46363
+ throw new UnauthorizedError15("You do not have HID intercom permission for this reader.");
46335
46364
  }
46336
46365
  return permission;
46337
46366
  }
@@ -47669,10 +47698,10 @@ function useHidAmicoService() {
47669
47698
  const hasActiveMembership = memberships.some((membership) => membership.status !== "deleted" && membership.status !== "inactive");
47670
47699
  const resolvedIssuer = issuer || (hasResidentMembership ? "resident" : "property_management");
47671
47700
  if (resolvedIssuer === "resident" && !hasResidentMembership) {
47672
- throw new UnauthorizedError14("Only a Resident account can issue a Resident visitor QR code.");
47701
+ throw new UnauthorizedError15("Only a Resident account can issue a Resident visitor QR code.");
47673
47702
  }
47674
47703
  if (resolvedIssuer === "property_management" && !hasActiveMembership) {
47675
- throw new UnauthorizedError14("Only a site Property Management account can issue this visitor QR code.");
47704
+ throw new UnauthorizedError15("Only a site Property Management account can issue this visitor QR code.");
47676
47705
  }
47677
47706
  const configuredGateIds = site?.metadata?.hidQrCodePass?.qrGatePermissions?.[resolvedIssuer === "resident" ? "resident" : "propertyManagement"] || [];
47678
47707
  const gateReaderIds = configuredGateIds.filter((readerId) => typeof readerId === "string" && /^[a-f0-9]{24}$/i.test(readerId)).map(String);
@@ -50265,7 +50294,7 @@ function useVisitorTransactionService() {
50265
50294
  import Joi69 from "joi";
50266
50295
  import moment5 from "moment-timezone";
50267
50296
  import { ObjectId as ObjectId94 } from "mongodb";
50268
- import { BadRequestError as BadRequestError124, NotFoundError as NotFoundError39, InternalServerError as InternalServerError46, UnauthorizedError as UnauthorizedError15, logger as logger97 } from "@7365admin1/node-server-utils";
50297
+ import { BadRequestError as BadRequestError124, NotFoundError as NotFoundError39, InternalServerError as InternalServerError46, UnauthorizedError as UnauthorizedError16, logger as logger97 } from "@7365admin1/node-server-utils";
50269
50298
 
50270
50299
  // src/models/visitor-invite.model.ts
50271
50300
  import Joi67 from "joi";
@@ -55086,7 +55115,7 @@ function useVisitorTransactionController() {
55086
55115
  }
55087
55116
  const inviterUserId = callerId(req);
55088
55117
  if (!inviterUserId) {
55089
- next(new UnauthorizedError15("Not authorized."));
55118
+ next(new UnauthorizedError16("Not authorized."));
55090
55119
  return;
55091
55120
  }
55092
55121
  try {
@@ -55650,7 +55679,7 @@ function useGuestManagementController() {
55650
55679
  // src/controllers/person.controller.ts
55651
55680
  import Joi72 from "joi";
55652
55681
  import { BadRequestError as BadRequestError127, logger as logger100 } from "@7365admin1/node-server-utils";
55653
- import { NotFoundError as NotFoundError40, UnauthorizedError as UnauthorizedError16 } from "@7365admin1/node-server-utils";
55682
+ import { NotFoundError as NotFoundError40, UnauthorizedError as UnauthorizedError17 } from "@7365admin1/node-server-utils";
55654
55683
 
55655
55684
  // src/utils/people-create-gate.util.ts
55656
55685
  var PEOPLE_CREATE_REACH_MODE_DEFAULT = "log";
@@ -55717,7 +55746,7 @@ function usePersonController() {
55717
55746
  }
55718
55747
  const org = person.org?.toString() ?? "";
55719
55748
  if (!org || !actor.orgIds.includes(org)) {
55720
- throw new UnauthorizedError16("Not authorized.");
55749
+ throw new UnauthorizedError17("Not authorized.");
55721
55750
  }
55722
55751
  return actor;
55723
55752
  }
@@ -55800,7 +55829,7 @@ function usePersonController() {
55800
55829
  });
55801
55830
  }
55802
55831
  if (verdict.refuse) {
55803
- next(new UnauthorizedError16("Not authorized."));
55832
+ next(new UnauthorizedError17("Not authorized."));
55804
55833
  return;
55805
55834
  }
55806
55835
  }
@@ -55883,7 +55912,7 @@ function usePersonController() {
55883
55912
  });
55884
55913
  } else if (org) {
55885
55914
  if (!actor.orgIds.includes(org)) {
55886
- throw new UnauthorizedError16("Not authorized.");
55915
+ throw new UnauthorizedError17("Not authorized.");
55887
55916
  }
55888
55917
  } else {
55889
55918
  orgs = actor.orgIds;
@@ -60203,7 +60232,7 @@ function useSiteFacilityService() {
60203
60232
  import {
60204
60233
  BadRequestError as BadRequestError149,
60205
60234
  NotFoundError as NotFoundError46,
60206
- UnauthorizedError as UnauthorizedError17,
60235
+ UnauthorizedError as UnauthorizedError18,
60207
60236
  logger as logger119
60208
60237
  } from "@7365admin1/node-server-utils";
60209
60238
  import Joi84 from "joi";
@@ -60290,7 +60319,7 @@ function useSiteFacilityController() {
60290
60319
  } else {
60291
60320
  const { actor } = await siteReachOf(req);
60292
60321
  if (!actor.isSuperAdmin)
60293
- throw new UnauthorizedError17("Not authorized.");
60322
+ throw new UnauthorizedError18("Not authorized.");
60294
60323
  }
60295
60324
  const data = await _getAll({
60296
60325
  search,
@@ -63325,7 +63354,7 @@ function useBulletinBoardService() {
63325
63354
  import {
63326
63355
  BadRequestError as BadRequestError158,
63327
63356
  NotFoundError as NotFoundError54,
63328
- UnauthorizedError as UnauthorizedError18,
63357
+ UnauthorizedError as UnauthorizedError19,
63329
63358
  logger as logger128
63330
63359
  } from "@7365admin1/node-server-utils";
63331
63360
  import Joi92 from "joi";
@@ -63361,7 +63390,7 @@ function useBulletinBoardController() {
63361
63390
  } else {
63362
63391
  const { canReach } = await siteReachOf(req);
63363
63392
  if (!await canReach(scopeOf(value))) {
63364
- throw new UnauthorizedError18("Not authorized.");
63393
+ throw new UnauthorizedError19("Not authorized.");
63365
63394
  }
63366
63395
  }
63367
63396
  const data = await _add(value);
@@ -63918,7 +63947,7 @@ import { BadRequestError as BadRequestError164, logger as logger134 } from "@736
63918
63947
  import {
63919
63948
  BadRequestError as BadRequestError163,
63920
63949
  logger as logger133,
63921
- UnauthorizedError as UnauthorizedError19,
63950
+ UnauthorizedError as UnauthorizedError20,
63922
63951
  useAtlas as useAtlas93
63923
63952
  } from "@7365admin1/node-server-utils";
63924
63953
 
@@ -64302,7 +64331,7 @@ function useSiteBillingItemService() {
64302
64331
  function assertUnitAtSite(buildingUnit, site) {
64303
64332
  const siteId = site?.toString?.() ?? "";
64304
64333
  if (!siteId || (buildingUnit?.site?.toString() ?? "") !== siteId) {
64305
- throw new UnauthorizedError19("Not authorized.");
64334
+ throw new UnauthorizedError20("Not authorized.");
64306
64335
  }
64307
64336
  }
64308
64337
  async function add(value) {
@@ -64473,7 +64502,7 @@ function useSiteBillingItemService() {
64473
64502
  message: error.message
64474
64503
  });
64475
64504
  await session.abortTransaction();
64476
- if (error instanceof BadRequestError163 || error instanceof UnauthorizedError19) {
64505
+ if (error instanceof BadRequestError163 || error instanceof UnauthorizedError20) {
64477
64506
  throw error;
64478
64507
  }
64479
64508
  throw new BadRequestError163("Failed to update Site Billing Item.");
@@ -66442,7 +66471,7 @@ import Joi100 from "joi";
66442
66471
 
66443
66472
  // src/utils/resident-unit.util.ts
66444
66473
  import { ObjectId as ObjectId128 } from "mongodb";
66445
- import { UnauthorizedError as UnauthorizedError20, useAtlas as useAtlas99 } from "@7365admin1/node-server-utils";
66474
+ import { UnauthorizedError as UnauthorizedError21, useAtlas as useAtlas99 } from "@7365admin1/node-server-utils";
66446
66475
  async function requireOwnUnit(req, site, unitId) {
66447
66476
  const actor = await resolveInviteActor(callerId(req));
66448
66477
  if (staffMayBypass(actor))
@@ -66450,7 +66479,7 @@ async function requireOwnUnit(req, site, unitId) {
66450
66479
  const unit = unitId?.toString?.() ?? "";
66451
66480
  const siteId = site?.toString?.() ?? "";
66452
66481
  if (!ObjectId128.isValid(unit) || !ObjectId128.isValid(siteId) || !actor.id) {
66453
- throw new UnauthorizedError20("Not authorized.");
66482
+ throw new UnauthorizedError21("Not authorized.");
66454
66483
  }
66455
66484
  const db2 = useAtlas99.getDb();
66456
66485
  if (!db2)
@@ -66462,7 +66491,7 @@ async function requireOwnUnit(req, site, unitId) {
66462
66491
  status: { $ne: "deleted" }
66463
66492
  });
66464
66493
  if (!own)
66465
- throw new UnauthorizedError20("Not authorized.");
66494
+ throw new UnauthorizedError21("Not authorized.");
66466
66495
  }
66467
66496
 
66468
66497
  // src/controllers/site-unit-billing.controller.ts
@@ -75024,7 +75053,7 @@ function useOnlineFormRepo() {
75024
75053
  import {
75025
75054
  BadRequestError as BadRequestError204,
75026
75055
  NotFoundError as NotFoundError74,
75027
- UnauthorizedError as UnauthorizedError21,
75056
+ UnauthorizedError as UnauthorizedError22,
75028
75057
  logger as logger172
75029
75058
  } from "@7365admin1/node-server-utils";
75030
75059
  import Joi123 from "joi";
@@ -75096,10 +75125,10 @@ function useOnlineFormController() {
75096
75125
  if (site) {
75097
75126
  await requireSiteReach(req, site);
75098
75127
  } else if (!staffMayBypass(actor)) {
75099
- throw new UnauthorizedError21("Not authorized.");
75128
+ throw new UnauthorizedError22("Not authorized.");
75100
75129
  }
75101
75130
  if (org && !staffMayBypass(actor) && !actor.orgIds.includes(org)) {
75102
- throw new UnauthorizedError21("Not authorized.");
75131
+ throw new UnauthorizedError22("Not authorized.");
75103
75132
  }
75104
75133
  const data = await _getAll({ search, page, limit, status, org, site });
75105
75134
  res.json(data);
@@ -75164,7 +75193,7 @@ function useOnlineFormController() {
75164
75193
  if (payload.org) {
75165
75194
  const { actor } = await siteReachOf(req);
75166
75195
  if (!staffMayBypass(actor) && !actor.orgIds.includes(payload.org)) {
75167
- throw new UnauthorizedError21("Not authorized.");
75196
+ throw new UnauthorizedError22("Not authorized.");
75168
75197
  }
75169
75198
  }
75170
75199
  await _updateOnlineFormById(_id, payload);
@@ -82476,7 +82505,7 @@ import {
82476
82505
  BadRequestError as BadRequestError231,
82477
82506
  NotFoundError as NotFoundError83,
82478
82507
  InternalServerError as InternalServerError85,
82479
- UnauthorizedError as UnauthorizedError22,
82508
+ UnauthorizedError as UnauthorizedError23,
82480
82509
  useAtlas as useAtlas138,
82481
82510
  hashPassword as hashPassword4
82482
82511
  } from "@7365admin1/node-server-utils";
@@ -83399,10 +83428,10 @@ function useVerificationServiceV2() {
83399
83428
  const org = await getOrgById(orgId);
83400
83429
  const actor = await resolveInviteActor(invitedBy);
83401
83430
  if (!actor.id) {
83402
- throw new UnauthorizedError22("Sign in to continue.");
83431
+ throw new UnauthorizedError23("Sign in to continue.");
83403
83432
  }
83404
83433
  if (!staffMayBypass(actor) && !actor.orgIds.includes(orgId)) {
83405
- throw new UnauthorizedError22(
83434
+ throw new UnauthorizedError23(
83406
83435
  "You can only invite service providers to your own organisation's sites."
83407
83436
  );
83408
83437
  }
@@ -83715,7 +83744,7 @@ function useVerificationServiceV2() {
83715
83744
  const user = await _getUserById(userId).catch(() => null);
83716
83745
  const email = user?.email;
83717
83746
  if (!email) {
83718
- throw new UnauthorizedError22("Not authorized.");
83747
+ throw new UnauthorizedError23("Not authorized.");
83719
83748
  }
83720
83749
  return email;
83721
83750
  }
@@ -83753,7 +83782,7 @@ function useVerificationServiceV2() {
83753
83782
  throw new NotFoundError83("Invitation not found.");
83754
83783
  }
83755
83784
  if (invite.email.toLowerCase() !== email.toLowerCase()) {
83756
- throw new UnauthorizedError22("Not authorized.");
83785
+ throw new UnauthorizedError23("Not authorized.");
83757
83786
  }
83758
83787
  await _setOnboardingById({
83759
83788
  _id: inviteId,
@@ -87659,7 +87688,7 @@ import Joi159 from "joi";
87659
87688
  import { ObjectId as ObjectId183 } from "mongodb";
87660
87689
  import {
87661
87690
  InternalServerError as InternalServerError95,
87662
- UnauthorizedError as UnauthorizedError23,
87691
+ UnauthorizedError as UnauthorizedError24,
87663
87692
  useAtlas as useAtlas150
87664
87693
  } from "@7365admin1/node-server-utils";
87665
87694
  function db() {
@@ -87675,7 +87704,7 @@ function asObjectId(value) {
87675
87704
  function requireCaller(req) {
87676
87705
  const id = callerId(req);
87677
87706
  if (!id || !ObjectId183.isValid(id)) {
87678
- throw new UnauthorizedError23("Not authorized.");
87707
+ throw new UnauthorizedError24("Not authorized.");
87679
87708
  }
87680
87709
  return id;
87681
87710
  }
@@ -87683,7 +87712,7 @@ function requireSelfId(req, claimed) {
87683
87712
  const caller = requireCaller(req);
87684
87713
  const asked = claimed?.toString?.() ?? "";
87685
87714
  if (!asked || asked !== caller) {
87686
- throw new UnauthorizedError23("Not authorized.");
87715
+ throw new UnauthorizedError24("Not authorized.");
87687
87716
  }
87688
87717
  return caller;
87689
87718
  }
@@ -87691,11 +87720,11 @@ async function requireOwnChannel(req, channelId) {
87691
87720
  const caller = requireCaller(req);
87692
87721
  const _id = asObjectId(channelId);
87693
87722
  if (!_id)
87694
- throw new UnauthorizedError23("Not authorized.");
87723
+ throw new UnauthorizedError24("Not authorized.");
87695
87724
  const channel = await db().collection("channel-preloved").findOne({ _id }, { projection: { senderId: 1, receiverId: 1, postId: 1 } });
87696
87725
  const participants = [channel?.senderId, channel?.receiverId].map((id) => id?.toString?.() ?? "").filter(Boolean);
87697
87726
  if (!channel || !participants.includes(caller)) {
87698
- throw new UnauthorizedError23("Not authorized.");
87727
+ throw new UnauthorizedError24("Not authorized.");
87699
87728
  }
87700
87729
  return { caller, channel };
87701
87730
  }
@@ -87703,10 +87732,10 @@ async function requireOwnChatMessage(req, chatId) {
87703
87732
  const caller = requireCaller(req);
87704
87733
  const _id = asObjectId(chatId);
87705
87734
  if (!_id)
87706
- throw new UnauthorizedError23("Not authorized.");
87735
+ throw new UnauthorizedError24("Not authorized.");
87707
87736
  const message = await db().collection("chat-preloved").findOne({ _id }, { projection: { senderId: 1 } });
87708
87737
  if (!message || message.senderId?.toString?.() !== caller) {
87709
- throw new UnauthorizedError23("Not authorized.");
87738
+ throw new UnauthorizedError24("Not authorized.");
87710
87739
  }
87711
87740
  return caller;
87712
87741
  }
@@ -88132,7 +88161,7 @@ function useBidPrelovedService() {
88132
88161
  // src/controllers/bid-preloved.controller.ts
88133
88162
  import {
88134
88163
  BadRequestError as BadRequestError252,
88135
- UnauthorizedError as UnauthorizedError24,
88164
+ UnauthorizedError as UnauthorizedError25,
88136
88165
  logger as logger216
88137
88166
  } from "@7365admin1/node-server-utils";
88138
88167
  import Joi162 from "joi";
@@ -88184,7 +88213,7 @@ function useBidPrelovedController() {
88184
88213
  const bid = await _getById(params.id);
88185
88214
  const seller = await sellerOfPost(bid?.postId);
88186
88215
  if (!seller || seller !== caller) {
88187
- throw new UnauthorizedError24("Not authorized.");
88216
+ throw new UnauthorizedError25("Not authorized.");
88188
88217
  }
88189
88218
  const data = await _updateStatus(params.id, body.status);
88190
88219
  res.status(200).json(data);
@@ -88208,7 +88237,7 @@ function useBidPrelovedController() {
88208
88237
  const data = await _getById(params.id);
88209
88238
  const seller = await sellerOfPost(data?.postId);
88210
88239
  if (data?.buyerId?.toString?.() !== caller && seller !== caller) {
88211
- throw new UnauthorizedError24("Not authorized.");
88240
+ throw new UnauthorizedError25("Not authorized.");
88212
88241
  }
88213
88242
  res.status(200).json(data);
88214
88243
  } catch (error2) {
@@ -88606,7 +88635,7 @@ function useFormEntryRepo() {
88606
88635
  import {
88607
88636
  BadRequestError as BadRequestError254,
88608
88637
  NotFoundError as NotFoundError92,
88609
- UnauthorizedError as UnauthorizedError25,
88638
+ UnauthorizedError as UnauthorizedError26,
88610
88639
  logger as logger218
88611
88640
  } from "@7365admin1/node-server-utils";
88612
88641
  import Joi164 from "joi";
@@ -88716,7 +88745,7 @@ function useFormEntryController() {
88716
88745
  } else {
88717
88746
  const { actor } = await siteReachOf(req);
88718
88747
  if (!actor.isSuperAdmin)
88719
- throw new UnauthorizedError25("Not authorized.");
88748
+ throw new UnauthorizedError26("Not authorized.");
88720
88749
  }
88721
88750
  const data = await _getAll({ search, page, limit, status, org, site });
88722
88751
  res.json(data);
@@ -88767,7 +88796,7 @@ function useFormEntryController() {
88767
88796
  await requireSiteReach(req, rest.site);
88768
88797
  delete rest.userId;
88769
88798
  if (isOwner && rest.status && rest.status !== "pending") {
88770
- throw new UnauthorizedError25("Not authorized.");
88799
+ throw new UnauthorizedError26("Not authorized.");
88771
88800
  }
88772
88801
  await _updateFormEntryById(_id, rest);
88773
88802
  res.json({ message: "Successfully updated online form." });
@@ -88824,7 +88853,7 @@ function useFormEntryController() {
88824
88853
  async function residentFormSubmission(req, res, next) {
88825
88854
  const userId = callerId(req);
88826
88855
  if (!userId) {
88827
- next(new UnauthorizedError25("Not authorized."));
88856
+ next(new UnauthorizedError26("Not authorized."));
88828
88857
  return;
88829
88858
  }
88830
88859
  const payload = { ...req.body, userId };
@@ -90055,7 +90084,7 @@ function useHidAmicoController() {
90055
90084
  import {
90056
90085
  BadRequestError as BadRequestError257,
90057
90086
  logger as logger220,
90058
- UnauthorizedError as UnauthorizedError26
90087
+ UnauthorizedError as UnauthorizedError27
90059
90088
  } from "@7365admin1/node-server-utils";
90060
90089
  import Joi166 from "joi";
90061
90090
  function usePlatformTermsController() {
@@ -90071,7 +90100,7 @@ function usePlatformTermsController() {
90071
90100
  async function requireOwnRecord(req, user, { staffMayRead = false } = {}) {
90072
90101
  const id = callerId(req);
90073
90102
  if (!id) {
90074
- throw new UnauthorizedError26("Not authorized.");
90103
+ throw new UnauthorizedError27("Not authorized.");
90075
90104
  }
90076
90105
  if (id === user) {
90077
90106
  return id;
@@ -90079,7 +90108,7 @@ function usePlatformTermsController() {
90079
90108
  if (staffMayRead) {
90080
90109
  return await requireConsolePermission(req, "platform-terms", "see-platform-terms");
90081
90110
  }
90082
- throw new UnauthorizedError26("Not authorized.");
90111
+ throw new UnauthorizedError27("Not authorized.");
90083
90112
  }
90084
90113
  async function getLatest(_req, res, next) {
90085
90114
  try {
@@ -90288,7 +90317,7 @@ function useConsoleAuditController() {
90288
90317
  // src/controllers/notification.controller.ts
90289
90318
  import {
90290
90319
  BadRequestError as BadRequestError259,
90291
- UnauthorizedError as UnauthorizedError27,
90320
+ UnauthorizedError as UnauthorizedError28,
90292
90321
  logger as logger222
90293
90322
  } from "@7365admin1/node-server-utils";
90294
90323
  function useNotificationController() {
@@ -90306,10 +90335,10 @@ function useNotificationController() {
90306
90335
  function inboxOwner(req, claimed) {
90307
90336
  const caller = callerId5(req);
90308
90337
  if (!caller) {
90309
- throw new UnauthorizedError27("Not authorized.");
90338
+ throw new UnauthorizedError28("Not authorized.");
90310
90339
  }
90311
90340
  if (claimed && claimed !== caller) {
90312
- throw new UnauthorizedError27("Not authorized.");
90341
+ throw new UnauthorizedError28("Not authorized.");
90313
90342
  }
90314
90343
  return caller;
90315
90344
  }
@@ -90321,7 +90350,7 @@ function useNotificationController() {
90321
90350
  }
90322
90351
  try {
90323
90352
  if (!await isSuperAdmin(callerId5(req))) {
90324
- throw new UnauthorizedError27("Not authorized.");
90353
+ throw new UnauthorizedError28("Not authorized.");
90325
90354
  }
90326
90355
  const inserted = await _addMany(value.to, {
90327
90356
  title: value.title,