@7365admin1/core 3.99.1-staging.383 → 3.99.1-staging.384

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": minor
3
+ ---
4
+
5
+ Invitations record who sent them: the Seven365 console lists only its own (`GET /verifications?origin=seven365`), a client's invitation stays in that client's list, only Seven365 staff may send an invitation naming no organisation, and an organisation invitation must name a role.
package/dist/index.d.ts CHANGED
@@ -1058,6 +1058,8 @@ type TVerificationMetadata = {
1058
1058
  siteId?: string | ObjectId;
1059
1059
  siteName?: string;
1060
1060
  serviceProviderOrgId?: string | ObjectId;
1061
+ /** "seven365" when Seven365 sent it - see `invite-origin.util.ts`. */
1062
+ origin?: string;
1061
1063
  };
1062
1064
  type TVerification = {
1063
1065
  _id?: ObjectId;
@@ -1092,7 +1094,7 @@ declare function useVerificationRepo(): {
1092
1094
  createTextIndex: () => Promise<void>;
1093
1095
  add: (value: TVerification, session?: ClientSession) => Promise<ObjectId>;
1094
1096
  getById: (_id: string | ObjectId) => Promise<TVerification | null>;
1095
- getVerifications: ({ search, page, limit, sort, status, app, type, email, siteId, orgId, }: {
1097
+ getVerifications: ({ search, page, limit, sort, status, app, type, email, siteId, orgId, origin, }: {
1096
1098
  search?: string | undefined;
1097
1099
  page?: number | undefined;
1098
1100
  limit?: number | undefined;
@@ -1103,6 +1105,7 @@ declare function useVerificationRepo(): {
1103
1105
  email?: string | undefined;
1104
1106
  siteId?: string | undefined;
1105
1107
  orgId?: string | undefined;
1108
+ origin?: string | undefined;
1106
1109
  }) => Promise<{}>;
1107
1110
  getByIdByType: (type: string) => Promise<TVerification[]>;
1108
1111
  updateStatusById: (_id: string | ObjectId, status: string, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
@@ -15108,6 +15111,8 @@ type TVerificationMetadataV2 = {
15108
15111
  siteId?: string | ObjectId;
15109
15112
  siteName?: string;
15110
15113
  serviceProviderOrgId?: string | ObjectId;
15114
+ /** "seven365" when Seven365 sent it - see `invite-origin.util.ts`. */
15115
+ origin?: string;
15111
15116
  verificationCode?: string;
15112
15117
  /** Who sent the invitation. Taken from the session, never from the body. */
15113
15118
  invitedBy?: string | ObjectId;
package/dist/index.js CHANGED
@@ -5747,6 +5747,22 @@ var MVerification = class {
5747
5747
  // src/repositories/verification.repo.ts
5748
5748
  var import_node_server_utils19 = require("@7365admin1/node-server-utils");
5749
5749
  var import_mongodb17 = require("mongodb");
5750
+
5751
+ // src/utils/invite-origin.util.ts
5752
+ var SEVEN365_INVITE_ORIGIN = "seven365";
5753
+ function seven365InviteQuery() {
5754
+ return {
5755
+ $or: [
5756
+ { "metadata.origin": SEVEN365_INVITE_ORIGIN },
5757
+ {
5758
+ "metadata.origin": { $exists: false },
5759
+ "metadata.org": { $in: ["", null] }
5760
+ }
5761
+ ]
5762
+ };
5763
+ }
5764
+
5765
+ // src/repositories/verification.repo.ts
5750
5766
  function useVerificationRepo() {
5751
5767
  const db2 = import_node_server_utils19.useAtlas.getDb();
5752
5768
  if (!db2) {
@@ -5833,7 +5849,8 @@ function useVerificationRepo() {
5833
5849
  type = {},
5834
5850
  email = "",
5835
5851
  siteId = "",
5836
- orgId = ""
5852
+ orgId = "",
5853
+ origin = ""
5837
5854
  }) {
5838
5855
  page = page > 0 ? page - 1 : 0;
5839
5856
  const query2 = { status };
@@ -5878,6 +5895,10 @@ function useVerificationRepo() {
5878
5895
  query2["metadata.org"] = { $in: orgCandidates };
5879
5896
  cacheOptions.orgId = orgId;
5880
5897
  }
5898
+ if (origin === SEVEN365_INVITE_ORIGIN) {
5899
+ Object.assign(query2, seven365InviteQuery());
5900
+ cacheOptions.origin = origin;
5901
+ }
5881
5902
  const cacheKey = (0, import_node_server_utils19.makeCacheKey)(namespace_collection3, cacheOptions);
5882
5903
  const cachedData = await getCache(cacheKey);
5883
5904
  if (cachedData) {
@@ -14010,6 +14031,23 @@ async function requireRoleInvitable(role, org, apps, site) {
14010
14031
  if (refusal)
14011
14032
  throw new import_node_server_utils43.BadRequestError(refusal);
14012
14033
  }
14034
+ async function requireInviteOrigin(req, org, role, fromConsole = false) {
14035
+ if (!org) {
14036
+ await requirePlatformStaff(req);
14037
+ return { origin: SEVEN365_INVITE_ORIGIN };
14038
+ }
14039
+ if (!role)
14040
+ throw new import_node_server_utils43.BadRequestError("Choose a role for this invitation.");
14041
+ if (fromConsole) {
14042
+ const staff = await requirePlatformStaff(req).then(
14043
+ () => true,
14044
+ () => false
14045
+ );
14046
+ if (staff)
14047
+ return { origin: SEVEN365_INVITE_ORIGIN };
14048
+ }
14049
+ return {};
14050
+ }
14013
14051
  async function requireInviteReach(req, org, app, role, site) {
14014
14052
  const apps = Array.isArray(app) ? app : [app];
14015
14053
  if (apps.some((a) => a === PLATFORM_STAFF_MEMBER_TYPE)) {
@@ -27829,6 +27867,7 @@ function useVerificationController() {
27829
27867
  const siteName = req.body.siteName ?? "";
27830
27868
  try {
27831
27869
  await requireInviteReach(req, org, app, role, siteId);
27870
+ const origin = await requireInviteOrigin(req, org, role);
27832
27871
  await _createUserInvite({
27833
27872
  email,
27834
27873
  metadata: {
@@ -27837,7 +27876,8 @@ function useVerificationController() {
27837
27876
  name,
27838
27877
  org,
27839
27878
  siteId,
27840
- siteName
27879
+ siteName,
27880
+ ...origin
27841
27881
  }
27842
27882
  });
27843
27883
  res.status(201).json({ message: "Successfully invited user." });
@@ -27930,6 +27970,7 @@ function useVerificationController() {
27930
27970
  clientModules.residentAppModules = residentAppModules;
27931
27971
  }
27932
27972
  await requireInviteReach(req, org, app, role, siteId);
27973
+ const origin = await requireInviteOrigin(req, org, role, true);
27933
27974
  const verificationIds = await _createSimpleUserInvite({
27934
27975
  email,
27935
27976
  metadata: {
@@ -27939,7 +27980,8 @@ function useVerificationController() {
27939
27980
  org,
27940
27981
  siteId,
27941
27982
  siteName,
27942
- ...clientModules
27983
+ ...clientModules,
27984
+ ...origin
27943
27985
  }
27944
27986
  });
27945
27987
  const responseBody = {
@@ -27995,6 +28037,7 @@ function useVerificationController() {
27995
28037
  const siteName = req.body.siteName ?? "";
27996
28038
  try {
27997
28039
  await requireInviteReach(req, org, app, role, siteId);
28040
+ const origin = await requireInviteOrigin(req, org, role);
27998
28041
  await _createSimpleMemberInvite({
27999
28042
  email,
28000
28043
  metadata: {
@@ -28003,7 +28046,8 @@ function useVerificationController() {
28003
28046
  name,
28004
28047
  org,
28005
28048
  siteId,
28006
- siteName
28049
+ siteName,
28050
+ ...origin
28007
28051
  }
28008
28052
  });
28009
28053
  const responseBody = {
@@ -28173,6 +28217,8 @@ function useVerificationController() {
28173
28217
  email: import_joi29.default.string().optional().allow("", null),
28174
28218
  siteId: import_joi29.default.string().hex().optional().allow("", null),
28175
28219
  orgId: import_joi29.default.string().hex().optional().allow("", null),
28220
+ // "seven365": only the invitations Seven365 sent (the console's lists).
28221
+ origin: import_joi29.default.string().valid(SEVEN365_INVITE_ORIGIN).optional().allow("", null),
28176
28222
  limit: import_joi29.default.number().integer().min(1).allow("", null).default(10)
28177
28223
  });
28178
28224
  const query2 = { ...req.query };
@@ -28190,6 +28236,7 @@ function useVerificationController() {
28190
28236
  const siteId = req.query.siteId ?? "";
28191
28237
  const orgId = req.query.orgId ?? "";
28192
28238
  const limit = parseInt(req.query.limit ?? "10");
28239
+ const origin = req.query.origin ?? "";
28193
28240
  const type = req.query.type ? String(req.query.type).split(",") : "";
28194
28241
  const typeObj = {};
28195
28242
  if (type && Array.isArray(type) && type.length) {
@@ -28198,8 +28245,9 @@ function useVerificationController() {
28198
28245
  });
28199
28246
  }
28200
28247
  try {
28201
- await requireVerificationListReach(req, orgId);
28248
+ await requireVerificationListReach(req, origin ? null : orgId);
28202
28249
  const data = await _getVerifications({
28250
+ origin,
28203
28251
  search,
28204
28252
  page,
28205
28253
  status,
@@ -95722,6 +95770,7 @@ function useVerificationControllerV2() {
95722
95770
  const { email, app, role, name, org, siteId, siteName } = value;
95723
95771
  try {
95724
95772
  await requireInviteReach(req, org, app, role, siteId);
95773
+ const origin = await requireInviteOrigin(req, org, role);
95725
95774
  await _createUserInvite({
95726
95775
  email,
95727
95776
  metadata: {
@@ -95730,7 +95779,8 @@ function useVerificationControllerV2() {
95730
95779
  name,
95731
95780
  org,
95732
95781
  siteId,
95733
- siteName
95782
+ siteName,
95783
+ ...origin
95734
95784
  }
95735
95785
  });
95736
95786
  res.status(201).json({ message: "Successfully invited user." });