aaspai-authx 0.1.8 → 0.1.9

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/LICENSE CHANGED
@@ -1,3 +1,3 @@
1
- MIT License
2
-
1
+ MIT License
2
+
3
3
  (See standard MIT text)
@@ -252,6 +252,12 @@ var OrgUserSchema = new import_mongoose2.default.Schema(
252
252
  projectId: { type: String, required: true },
253
253
  roles: { type: [String], default: [] },
254
254
  emailVerified: { type: Boolean, default: false },
255
+ status: {
256
+ type: String,
257
+ enum: ["active", "inactive", "suspended", "banned", "pending"],
258
+ default: "active",
259
+ index: true
260
+ },
255
261
  lastEmailSent: { type: [Date], default: [] },
256
262
  lastPasswordReset: { type: Date },
257
263
  metadata: { type: [MetadataSchema], default: [] },
@@ -263,6 +269,7 @@ OrgUserSchema.index({ projectId: 1, createdAt: -1 });
263
269
  OrgUserSchema.index({ projectId: 1, updatedAt: -1 });
264
270
  OrgUserSchema.index({ projectId: 1, email: 1 });
265
271
  OrgUserSchema.index({ projectId: 1, emailVerified: 1, createdAt: -1 });
272
+ OrgUserSchema.index({ projectId: 1, status: 1, createdAt: -1 });
266
273
  OrgUserSchema.index({ projectId: 1, firstName: 1, lastName: 1 });
267
274
  var OrgUser = import_mongoose2.default.model("OrgUser", OrgUserSchema);
268
275
 
@@ -1695,7 +1702,8 @@ function createAuthRouter(options = {}) {
1695
1702
  "updatedAt",
1696
1703
  "email",
1697
1704
  "firstName",
1698
- "lastName"
1705
+ "lastName",
1706
+ "status"
1699
1707
  ];
1700
1708
  const sortBy = allowedSortFields.includes(String(req.query.sortBy || "")) ? String(req.query.sortBy) : "createdAt";
1701
1709
  const sortOrder = String(req.query.sortOrder || "desc").toLowerCase() === "asc" ? 1 : -1;
@@ -1733,6 +1741,30 @@ function createAuthRouter(options = {}) {
1733
1741
  const emailSearch = escapeRegex(String(req.query.email));
1734
1742
  baseQuery.email = { $regex: emailSearch, $options: "i" };
1735
1743
  }
1744
+ if (req.query.userId) {
1745
+ const userId = String(req.query.userId).trim();
1746
+ if (userId) {
1747
+ baseQuery.id = userId;
1748
+ }
1749
+ }
1750
+ if (req.query.status !== void 0) {
1751
+ const statusValue = String(req.query.status).toLowerCase().trim();
1752
+ if (statusValue === "true" || statusValue === "pending") {
1753
+ baseQuery.metadata = {
1754
+ $elemMatch: {
1755
+ key: "inWaitlist",
1756
+ value: true
1757
+ }
1758
+ };
1759
+ } else if (statusValue === "false" || statusValue === "active") {
1760
+ baseQuery.metadata = {
1761
+ $elemMatch: {
1762
+ key: "inWaitlist",
1763
+ value: false
1764
+ }
1765
+ };
1766
+ }
1767
+ }
1736
1768
  const projection = {
1737
1769
  id: 1,
1738
1770
  email: 1,
@@ -1742,6 +1774,7 @@ function createAuthRouter(options = {}) {
1742
1774
  projectId: 1,
1743
1775
  roles: 1,
1744
1776
  emailVerified: 1,
1777
+ status: 1,
1745
1778
  lastEmailSent: 1,
1746
1779
  lastPasswordReset: 1,
1747
1780
  metadata: 1,
@@ -1959,7 +1992,7 @@ function generateTokens(user) {
1959
1992
  expiresIn: "1d"
1960
1993
  });
1961
1994
  const refreshToken = import_jsonwebtoken4.default.sign(
1962
- { sub: user._id.toString() },
1995
+ { sub: user.id.toString() },
1963
1996
  process.env.JWT_SECRET,
1964
1997
  { expiresIn: "30d" }
1965
1998
  );