@7365admin1/core 3.72.1-staging.323 → 3.72.1-staging.324

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ ---
2
+ "@7365admin1/core": patch
3
+ ---
4
+
5
+ Membership and role lookups by type match every stored spelling of an application: a Property Management lookup finds rows stored as `real_estate_developer` (written before 3.75.0) as well as `property_management_agency`, including the module deny list and the owner-grant cap.
package/dist/index.js CHANGED
@@ -3996,6 +3996,20 @@ function serviceAppType(type) {
3996
3996
  return type;
3997
3997
  return APP_TYPE_ALIASES[type] ?? type;
3998
3998
  }
3999
+ function storedAppTypes(type) {
4000
+ const app = serviceAppType(type);
4001
+ return [
4002
+ app,
4003
+ ...Object.keys(APP_TYPE_ALIASES).filter((alias) => APP_TYPE_ALIASES[alias] === app)
4004
+ ];
4005
+ }
4006
+ function appTypeQuery(type) {
4007
+ const types = storedAppTypes(type);
4008
+ return types.length === 1 ? types[0] : { $in: types };
4009
+ }
4010
+ function sameAppType(a, b) {
4011
+ return !!a && !!b && serviceAppType(a) === serviceAppType(b);
4012
+ }
3999
4013
 
4000
4014
  // src/repositories/member.repo.ts
4001
4015
  var import_node_server_utils14 = require("@7365admin1/node-server-utils");
@@ -4293,7 +4307,7 @@ function useMemberRepo() {
4293
4307
  return cachedData;
4294
4308
  }
4295
4309
  try {
4296
- const data = await collection.findOne({ user, type });
4310
+ const data = await collection.findOne({ user, type: appTypeQuery(type) });
4297
4311
  if (!data) {
4298
4312
  throw new import_node_server_utils14.NotFoundError("Member not found.");
4299
4313
  }
@@ -4437,7 +4451,7 @@ function useMemberRepo() {
4437
4451
  search = search || "";
4438
4452
  page = page > 0 ? page - 1 : 0;
4439
4453
  const query2 = {
4440
- type: serviceAppType(type),
4454
+ type: type ? appTypeQuery(type) : type,
4441
4455
  status
4442
4456
  };
4443
4457
  const cacheOptions = {
@@ -4566,7 +4580,7 @@ function useMemberRepo() {
4566
4580
  const query2 = {
4567
4581
  user,
4568
4582
  org: { $nin: [null, ""] },
4569
- type
4583
+ type: appTypeQuery(type)
4570
4584
  };
4571
4585
  const cacheOptions = {
4572
4586
  page,
@@ -4983,7 +4997,7 @@ function useMemberRepo() {
4983
4997
  try {
4984
4998
  const data = await collection.findOne({
4985
4999
  user,
4986
- type,
5000
+ type: appTypeQuery(type),
4987
5001
  org
4988
5002
  });
4989
5003
  if (!data) {
@@ -10584,7 +10598,7 @@ function pickSiteMembership(rows, type, site, org = "") {
10584
10598
  if (!site)
10585
10599
  return null;
10586
10600
  const live = rows.filter(
10587
- (m) => m.type === type && isLiveMembership(m) && (!org || idOf2(m.org) === org)
10601
+ (m) => sameAppType(m.type, type) && isLiveMembership(m) && (!org || idOf2(m.org) === org)
10588
10602
  );
10589
10603
  const atSite = live.find((m) => idOf2(m.siteId) === site);
10590
10604
  if (atSite)
@@ -10598,10 +10612,10 @@ function pickLookupMembership(rows, type, site = "", org = "") {
10598
10612
  const atSite = site ? pickSiteMembership(list, type, site, org) : null;
10599
10613
  if (atSite)
10600
10614
  return atSite;
10601
- const inOrg = org ? list.find((m) => m.type === type && idOf2(m.org) === org.toLowerCase()) : void 0;
10615
+ const inOrg = org ? list.find((m) => sameAppType(m.type, type) && idOf2(m.org) === org.toLowerCase()) : void 0;
10602
10616
  if (inOrg && isLiveMembership(inOrg))
10603
10617
  return inOrg;
10604
- return list.find((m) => m.type === type) ?? null;
10618
+ return list.find((m) => sameAppType(m.type, type)) ?? null;
10605
10619
  }
10606
10620
  function memberListSiteScope(memberships, org) {
10607
10621
  const inOrg = (memberships ?? []).filter((m) => idOf2(m.org) === idOf2(org));
@@ -12591,7 +12605,7 @@ function useRoleRepo() {
12591
12605
  return cachedData;
12592
12606
  }
12593
12607
  try {
12594
- const data = await collection.find({ org, permissions: "*", type, status: "active" }).toArray();
12608
+ const data = await collection.find({ org, permissions: "*", type: appTypeQuery(type), status: "active" }).toArray();
12595
12609
  setCache(cacheKey, data, 15 * 60).then(() => {
12596
12610
  import_node_server_utils42.logger.info(`Cache set for key: ${cacheKey}`);
12597
12611
  }).catch((err) => {
@@ -12631,7 +12645,7 @@ function useRoleRepo() {
12631
12645
  throw new import_node_server_utils42.BadRequestError("Role name is required.");
12632
12646
  }
12633
12647
  type = serviceAppType(type);
12634
- const query2 = type ? { name, type } : { name };
12648
+ const query2 = type ? { name, type: appTypeQuery(type) } : { name };
12635
12649
  try {
12636
12650
  const cacheKey = (0, import_node_server_utils42.makeCacheKey)(namespace_collection3, query2);
12637
12651
  const cachedData = await getCache(cacheKey);
@@ -12687,8 +12701,8 @@ function useRoleRepo() {
12687
12701
  cacheOptions.search = search;
12688
12702
  }
12689
12703
  if (type) {
12690
- query2.type = serviceAppType(type);
12691
- cacheOptions.type = query2.type;
12704
+ query2.type = appTypeQuery(type);
12705
+ cacheOptions.type = serviceAppType(type);
12692
12706
  }
12693
12707
  const cacheKey = (0, import_node_server_utils42.makeCacheKey)(namespace_collection3, cacheOptions);
12694
12708
  const cachedData = await getCache(cacheKey);
@@ -15580,12 +15594,11 @@ async function ownerGrantCeiling(org, type) {
15580
15594
  return null;
15581
15595
  try {
15582
15596
  const orgDoc = await useOrgRepo().getById(orgId).catch(() => null);
15583
- const appType = serviceAppType(orgDoc?.nature);
15584
- if (!orgDoc?.invitedRole || appType !== type)
15597
+ if (!orgDoc?.invitedRole || !sameAppType(orgDoc?.nature, type))
15585
15598
  return null;
15586
15599
  const role = await useRoleRepo().getRoleById(String(orgDoc.invitedRole)).catch(() => null);
15587
15600
  const permissions = role?.permissions;
15588
- const chosen = role && String(role.org ?? "") === orgId && role.default === true && role.type === appType && Array.isArray(permissions) && permissions.length > 0 && !permissions.includes("*");
15601
+ const chosen = role && String(role.org ?? "") === orgId && role.default === true && sameAppType(role.type, type) && Array.isArray(permissions) && permissions.length > 0 && !permissions.includes("*");
15589
15602
  return chosen ? permissions.map(String) : null;
15590
15603
  } catch {
15591
15604
  return null;
@@ -26537,7 +26550,7 @@ function useOrgController() {
26537
26550
  invitedModules?.permissions
26538
26551
  );
26539
26552
  const appOwnerRole = invitedModules?.permissions.length ? seededRoles.find(
26540
- (role) => role.type === serviceAppType(body.nature) && role.name === "owner"
26553
+ (role) => sameAppType(role.type, body.nature) && role.name === "owner"
26541
26554
  ) : void 0;
26542
26555
  if (appOwnerRole) {
26543
26556
  try {