strapi-plugin-magic-sessionmanager 1.0.1 → 2.0.1

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/README.md CHANGED
@@ -53,7 +53,7 @@
53
53
  ### Non-Invasive Architecture
54
54
  ✅ **No Core Modifications** - Pure plugin, zero changes to Strapi core
55
55
  ✅ **Runtime Injection** - Middleware-based architecture
56
- ✅ **DB-Backed** - Uses `api::session.session` content type
56
+ ✅ **DB-Backed** - Uses `plugin::magic-sessionmanager.session` content type
57
57
  ✅ **License-Based** - Premium features via license key
58
58
 
59
59
  ---
@@ -185,7 +185,7 @@ Extract from response:
185
185
  Block? NO → Continue ✅
186
186
  Block? YES → Return 403 Forbidden ❌
187
187
 
188
- Create api::session.session record:
188
+ Create plugin::magic-sessionmanager.session record:
189
189
  {
190
190
  user: userId,
191
191
  token: jwt, // Access Token
@@ -936,7 +936,7 @@ curl http://localhost:1337/api/users \
936
936
  # Look for: [magic-sessionmanager] ✅ Login/Logout interceptor middleware mounted
937
937
  ```
938
938
 
939
- 3. Check `api::session.session` collection exists:
939
+ 3. Check `plugin::magic-sessionmanager.session` collection exists:
940
940
  - Go to Admin → Content Manager
941
941
  - Look for "Session" collection
942
942
 
@@ -92,7 +92,7 @@ var lastSeen = ({ strapi: strapi2, sessionService }) => {
92
92
  if (ctx.state.user && ctx.state.user.id) {
93
93
  try {
94
94
  const userId = ctx.state.user.id;
95
- const activeSessions = await strapi2.entityService.findMany("api::session.session", {
95
+ const activeSessions = await strapi2.entityService.findMany("plugin::magic-sessionmanager.session", {
96
96
  filters: {
97
97
  user: { id: userId },
98
98
  isActive: true
@@ -190,7 +190,7 @@ var bootstrap$1 = async ({ strapi: strapi2 }) => {
190
190
  ctx.body = { message: "Logged out successfully" };
191
191
  return;
192
192
  }
193
- const sessions = await strapi2.entityService.findMany("api::session.session", {
193
+ const sessions = await strapi2.entityService.findMany("plugin::magic-sessionmanager.session", {
194
194
  filters: {
195
195
  token,
196
196
  isActive: true
@@ -331,7 +331,7 @@ var bootstrap$1 = async ({ strapi: strapi2 }) => {
331
331
  );
332
332
  strapi2.log.info("[magic-sessionmanager] ✅ LastSeen middleware mounted");
333
333
  strapi2.log.info("[magic-sessionmanager] ✅ Bootstrap complete");
334
- strapi2.log.info("[magic-sessionmanager] 🎉 Session Manager ready! Sessions stored in api::session.session");
334
+ strapi2.log.info("[magic-sessionmanager] 🎉 Session Manager ready! Sessions stored in plugin::magic-sessionmanager.session");
335
335
  } catch (err) {
336
336
  strapi2.log.error("[magic-sessionmanager] ❌ Bootstrap error:", err);
337
337
  }
@@ -633,7 +633,7 @@ var session$3 = {
633
633
  return ctx.throw(401, "Unauthorized");
634
634
  }
635
635
  const sessionService = strapi.plugin("magic-sessionmanager").service("session");
636
- const sessions = await strapi.entityService.findMany("api::session.session", {
636
+ const sessions = await strapi.entityService.findMany("plugin::magic-sessionmanager.session", {
637
637
  filters: {
638
638
  user: { id: userId },
639
639
  token,
@@ -1150,7 +1150,7 @@ var session$1 = ({ strapi: strapi2 }) => ({
1150
1150
  async createSession({ userId, ip = "unknown", userAgent = "unknown", token }) {
1151
1151
  try {
1152
1152
  const now = /* @__PURE__ */ new Date();
1153
- const session2 = await strapi2.entityService.create("api::session.session", {
1153
+ const session2 = await strapi2.entityService.create("plugin::magic-sessionmanager.session", {
1154
1154
  data: {
1155
1155
  user: userId,
1156
1156
  ipAddress: ip.substring(0, 45),
@@ -1178,7 +1178,7 @@ var session$1 = ({ strapi: strapi2 }) => ({
1178
1178
  try {
1179
1179
  const now = /* @__PURE__ */ new Date();
1180
1180
  if (sessionId) {
1181
- await strapi2.entityService.update("api::session.session", sessionId, {
1181
+ await strapi2.entityService.update("plugin::magic-sessionmanager.session", sessionId, {
1182
1182
  data: {
1183
1183
  isActive: false,
1184
1184
  logoutTime: now
@@ -1186,14 +1186,14 @@ var session$1 = ({ strapi: strapi2 }) => ({
1186
1186
  });
1187
1187
  strapi2.log.info(`[magic-sessionmanager] Session ${sessionId} terminated`);
1188
1188
  } else if (userId) {
1189
- const activeSessions = await strapi2.entityService.findMany("api::session.session", {
1189
+ const activeSessions = await strapi2.entityService.findMany("plugin::magic-sessionmanager.session", {
1190
1190
  filters: {
1191
1191
  user: { id: userId },
1192
1192
  isActive: true
1193
1193
  }
1194
1194
  });
1195
1195
  for (const session2 of activeSessions) {
1196
- await strapi2.entityService.update("api::session.session", session2.id, {
1196
+ await strapi2.entityService.update("plugin::magic-sessionmanager.session", session2.id, {
1197
1197
  data: {
1198
1198
  isActive: false,
1199
1199
  logoutTime: now
@@ -1213,7 +1213,7 @@ var session$1 = ({ strapi: strapi2 }) => ({
1213
1213
  */
1214
1214
  async getAllSessions() {
1215
1215
  try {
1216
- const sessions = await strapi2.entityService.findMany("api::session.session", {
1216
+ const sessions = await strapi2.entityService.findMany("plugin::magic-sessionmanager.session", {
1217
1217
  populate: { user: { fields: ["id", "email", "username"] } },
1218
1218
  sort: { loginTime: "desc" },
1219
1219
  limit: 1e3
@@ -1245,7 +1245,7 @@ var session$1 = ({ strapi: strapi2 }) => ({
1245
1245
  */
1246
1246
  async getActiveSessions() {
1247
1247
  try {
1248
- const sessions = await strapi2.entityService.findMany("api::session.session", {
1248
+ const sessions = await strapi2.entityService.findMany("plugin::magic-sessionmanager.session", {
1249
1249
  filters: { isActive: true },
1250
1250
  populate: { user: { fields: ["id", "email", "username"] } },
1251
1251
  sort: { loginTime: "desc" }
@@ -1277,7 +1277,7 @@ var session$1 = ({ strapi: strapi2 }) => ({
1277
1277
  */
1278
1278
  async getUserSessions(userId) {
1279
1279
  try {
1280
- const sessions = await strapi2.entityService.findMany("api::session.session", {
1280
+ const sessions = await strapi2.entityService.findMany("plugin::magic-sessionmanager.session", {
1281
1281
  filters: { user: { id: userId } },
1282
1282
  sort: { loginTime: "desc" }
1283
1283
  });
@@ -1312,17 +1312,17 @@ var session$1 = ({ strapi: strapi2 }) => ({
1312
1312
  const config2 = strapi2.config.get("plugin::magic-sessionmanager") || {};
1313
1313
  const rateLimit = config2.lastSeenRateLimit || 3e4;
1314
1314
  if (sessionId) {
1315
- const session2 = await strapi2.entityService.findOne("api::session.session", sessionId);
1315
+ const session2 = await strapi2.entityService.findOne("plugin::magic-sessionmanager.session", sessionId);
1316
1316
  if (session2 && session2.lastActive) {
1317
1317
  const lastActiveTime = new Date(session2.lastActive).getTime();
1318
1318
  const currentTime = now.getTime();
1319
1319
  if (currentTime - lastActiveTime > rateLimit) {
1320
- await strapi2.entityService.update("api::session.session", sessionId, {
1320
+ await strapi2.entityService.update("plugin::magic-sessionmanager.session", sessionId, {
1321
1321
  data: { lastActive: now }
1322
1322
  });
1323
1323
  }
1324
1324
  } else if (session2) {
1325
- await strapi2.entityService.update("api::session.session", sessionId, {
1325
+ await strapi2.entityService.update("plugin::magic-sessionmanager.session", sessionId, {
1326
1326
  data: { lastActive: now }
1327
1327
  });
1328
1328
  }
@@ -1342,7 +1342,7 @@ var session$1 = ({ strapi: strapi2 }) => ({
1342
1342
  const now = /* @__PURE__ */ new Date();
1343
1343
  const cutoffTime = new Date(now.getTime() - inactivityTimeout);
1344
1344
  strapi2.log.info(`[magic-sessionmanager] 🧹 Cleaning up sessions inactive since before ${cutoffTime.toISOString()}`);
1345
- const activeSessions = await strapi2.entityService.findMany("api::session.session", {
1345
+ const activeSessions = await strapi2.entityService.findMany("plugin::magic-sessionmanager.session", {
1346
1346
  filters: { isActive: true },
1347
1347
  fields: ["id", "lastActive", "loginTime"]
1348
1348
  });
@@ -1350,7 +1350,7 @@ var session$1 = ({ strapi: strapi2 }) => ({
1350
1350
  for (const session2 of activeSessions) {
1351
1351
  const lastActiveTime = session2.lastActive ? new Date(session2.lastActive) : new Date(session2.loginTime);
1352
1352
  if (lastActiveTime < cutoffTime) {
1353
- await strapi2.entityService.update("api::session.session", session2.id, {
1353
+ await strapi2.entityService.update("plugin::magic-sessionmanager.session", session2.id, {
1354
1354
  data: { isActive: false }
1355
1355
  });
1356
1356
  deactivatedCount++;
@@ -1371,7 +1371,7 @@ var session$1 = ({ strapi: strapi2 }) => ({
1371
1371
  */
1372
1372
  async deleteSession(sessionId) {
1373
1373
  try {
1374
- await strapi2.entityService.delete("api::session.session", sessionId);
1374
+ await strapi2.entityService.delete("plugin::magic-sessionmanager.session", sessionId);
1375
1375
  strapi2.log.info(`[magic-sessionmanager] 🗑️ Session ${sessionId} permanently deleted`);
1376
1376
  return true;
1377
1377
  } catch (err) {
@@ -1387,13 +1387,13 @@ var session$1 = ({ strapi: strapi2 }) => ({
1387
1387
  async deleteInactiveSessions() {
1388
1388
  try {
1389
1389
  strapi2.log.info("[magic-sessionmanager] 🗑️ Deleting all inactive sessions...");
1390
- const inactiveSessions = await strapi2.entityService.findMany("api::session.session", {
1390
+ const inactiveSessions = await strapi2.entityService.findMany("plugin::magic-sessionmanager.session", {
1391
1391
  filters: { isActive: false },
1392
1392
  fields: ["id"]
1393
1393
  });
1394
1394
  let deletedCount = 0;
1395
1395
  for (const session2 of inactiveSessions) {
1396
- await strapi2.entityService.delete("api::session.session", session2.id);
1396
+ await strapi2.entityService.delete("plugin::magic-sessionmanager.session", session2.id);
1397
1397
  deletedCount++;
1398
1398
  }
1399
1399
  strapi2.log.info(`[magic-sessionmanager] ✅ Deleted ${deletedCount} inactive sessions`);
@@ -88,7 +88,7 @@ var lastSeen = ({ strapi: strapi2, sessionService }) => {
88
88
  if (ctx.state.user && ctx.state.user.id) {
89
89
  try {
90
90
  const userId = ctx.state.user.id;
91
- const activeSessions = await strapi2.entityService.findMany("api::session.session", {
91
+ const activeSessions = await strapi2.entityService.findMany("plugin::magic-sessionmanager.session", {
92
92
  filters: {
93
93
  user: { id: userId },
94
94
  isActive: true
@@ -186,7 +186,7 @@ var bootstrap$1 = async ({ strapi: strapi2 }) => {
186
186
  ctx.body = { message: "Logged out successfully" };
187
187
  return;
188
188
  }
189
- const sessions = await strapi2.entityService.findMany("api::session.session", {
189
+ const sessions = await strapi2.entityService.findMany("plugin::magic-sessionmanager.session", {
190
190
  filters: {
191
191
  token,
192
192
  isActive: true
@@ -327,7 +327,7 @@ var bootstrap$1 = async ({ strapi: strapi2 }) => {
327
327
  );
328
328
  strapi2.log.info("[magic-sessionmanager] ✅ LastSeen middleware mounted");
329
329
  strapi2.log.info("[magic-sessionmanager] ✅ Bootstrap complete");
330
- strapi2.log.info("[magic-sessionmanager] 🎉 Session Manager ready! Sessions stored in api::session.session");
330
+ strapi2.log.info("[magic-sessionmanager] 🎉 Session Manager ready! Sessions stored in plugin::magic-sessionmanager.session");
331
331
  } catch (err) {
332
332
  strapi2.log.error("[magic-sessionmanager] ❌ Bootstrap error:", err);
333
333
  }
@@ -629,7 +629,7 @@ var session$3 = {
629
629
  return ctx.throw(401, "Unauthorized");
630
630
  }
631
631
  const sessionService = strapi.plugin("magic-sessionmanager").service("session");
632
- const sessions = await strapi.entityService.findMany("api::session.session", {
632
+ const sessions = await strapi.entityService.findMany("plugin::magic-sessionmanager.session", {
633
633
  filters: {
634
634
  user: { id: userId },
635
635
  token,
@@ -1146,7 +1146,7 @@ var session$1 = ({ strapi: strapi2 }) => ({
1146
1146
  async createSession({ userId, ip = "unknown", userAgent = "unknown", token }) {
1147
1147
  try {
1148
1148
  const now = /* @__PURE__ */ new Date();
1149
- const session2 = await strapi2.entityService.create("api::session.session", {
1149
+ const session2 = await strapi2.entityService.create("plugin::magic-sessionmanager.session", {
1150
1150
  data: {
1151
1151
  user: userId,
1152
1152
  ipAddress: ip.substring(0, 45),
@@ -1174,7 +1174,7 @@ var session$1 = ({ strapi: strapi2 }) => ({
1174
1174
  try {
1175
1175
  const now = /* @__PURE__ */ new Date();
1176
1176
  if (sessionId) {
1177
- await strapi2.entityService.update("api::session.session", sessionId, {
1177
+ await strapi2.entityService.update("plugin::magic-sessionmanager.session", sessionId, {
1178
1178
  data: {
1179
1179
  isActive: false,
1180
1180
  logoutTime: now
@@ -1182,14 +1182,14 @@ var session$1 = ({ strapi: strapi2 }) => ({
1182
1182
  });
1183
1183
  strapi2.log.info(`[magic-sessionmanager] Session ${sessionId} terminated`);
1184
1184
  } else if (userId) {
1185
- const activeSessions = await strapi2.entityService.findMany("api::session.session", {
1185
+ const activeSessions = await strapi2.entityService.findMany("plugin::magic-sessionmanager.session", {
1186
1186
  filters: {
1187
1187
  user: { id: userId },
1188
1188
  isActive: true
1189
1189
  }
1190
1190
  });
1191
1191
  for (const session2 of activeSessions) {
1192
- await strapi2.entityService.update("api::session.session", session2.id, {
1192
+ await strapi2.entityService.update("plugin::magic-sessionmanager.session", session2.id, {
1193
1193
  data: {
1194
1194
  isActive: false,
1195
1195
  logoutTime: now
@@ -1209,7 +1209,7 @@ var session$1 = ({ strapi: strapi2 }) => ({
1209
1209
  */
1210
1210
  async getAllSessions() {
1211
1211
  try {
1212
- const sessions = await strapi2.entityService.findMany("api::session.session", {
1212
+ const sessions = await strapi2.entityService.findMany("plugin::magic-sessionmanager.session", {
1213
1213
  populate: { user: { fields: ["id", "email", "username"] } },
1214
1214
  sort: { loginTime: "desc" },
1215
1215
  limit: 1e3
@@ -1241,7 +1241,7 @@ var session$1 = ({ strapi: strapi2 }) => ({
1241
1241
  */
1242
1242
  async getActiveSessions() {
1243
1243
  try {
1244
- const sessions = await strapi2.entityService.findMany("api::session.session", {
1244
+ const sessions = await strapi2.entityService.findMany("plugin::magic-sessionmanager.session", {
1245
1245
  filters: { isActive: true },
1246
1246
  populate: { user: { fields: ["id", "email", "username"] } },
1247
1247
  sort: { loginTime: "desc" }
@@ -1273,7 +1273,7 @@ var session$1 = ({ strapi: strapi2 }) => ({
1273
1273
  */
1274
1274
  async getUserSessions(userId) {
1275
1275
  try {
1276
- const sessions = await strapi2.entityService.findMany("api::session.session", {
1276
+ const sessions = await strapi2.entityService.findMany("plugin::magic-sessionmanager.session", {
1277
1277
  filters: { user: { id: userId } },
1278
1278
  sort: { loginTime: "desc" }
1279
1279
  });
@@ -1308,17 +1308,17 @@ var session$1 = ({ strapi: strapi2 }) => ({
1308
1308
  const config2 = strapi2.config.get("plugin::magic-sessionmanager") || {};
1309
1309
  const rateLimit = config2.lastSeenRateLimit || 3e4;
1310
1310
  if (sessionId) {
1311
- const session2 = await strapi2.entityService.findOne("api::session.session", sessionId);
1311
+ const session2 = await strapi2.entityService.findOne("plugin::magic-sessionmanager.session", sessionId);
1312
1312
  if (session2 && session2.lastActive) {
1313
1313
  const lastActiveTime = new Date(session2.lastActive).getTime();
1314
1314
  const currentTime = now.getTime();
1315
1315
  if (currentTime - lastActiveTime > rateLimit) {
1316
- await strapi2.entityService.update("api::session.session", sessionId, {
1316
+ await strapi2.entityService.update("plugin::magic-sessionmanager.session", sessionId, {
1317
1317
  data: { lastActive: now }
1318
1318
  });
1319
1319
  }
1320
1320
  } else if (session2) {
1321
- await strapi2.entityService.update("api::session.session", sessionId, {
1321
+ await strapi2.entityService.update("plugin::magic-sessionmanager.session", sessionId, {
1322
1322
  data: { lastActive: now }
1323
1323
  });
1324
1324
  }
@@ -1338,7 +1338,7 @@ var session$1 = ({ strapi: strapi2 }) => ({
1338
1338
  const now = /* @__PURE__ */ new Date();
1339
1339
  const cutoffTime = new Date(now.getTime() - inactivityTimeout);
1340
1340
  strapi2.log.info(`[magic-sessionmanager] 🧹 Cleaning up sessions inactive since before ${cutoffTime.toISOString()}`);
1341
- const activeSessions = await strapi2.entityService.findMany("api::session.session", {
1341
+ const activeSessions = await strapi2.entityService.findMany("plugin::magic-sessionmanager.session", {
1342
1342
  filters: { isActive: true },
1343
1343
  fields: ["id", "lastActive", "loginTime"]
1344
1344
  });
@@ -1346,7 +1346,7 @@ var session$1 = ({ strapi: strapi2 }) => ({
1346
1346
  for (const session2 of activeSessions) {
1347
1347
  const lastActiveTime = session2.lastActive ? new Date(session2.lastActive) : new Date(session2.loginTime);
1348
1348
  if (lastActiveTime < cutoffTime) {
1349
- await strapi2.entityService.update("api::session.session", session2.id, {
1349
+ await strapi2.entityService.update("plugin::magic-sessionmanager.session", session2.id, {
1350
1350
  data: { isActive: false }
1351
1351
  });
1352
1352
  deactivatedCount++;
@@ -1367,7 +1367,7 @@ var session$1 = ({ strapi: strapi2 }) => ({
1367
1367
  */
1368
1368
  async deleteSession(sessionId) {
1369
1369
  try {
1370
- await strapi2.entityService.delete("api::session.session", sessionId);
1370
+ await strapi2.entityService.delete("plugin::magic-sessionmanager.session", sessionId);
1371
1371
  strapi2.log.info(`[magic-sessionmanager] 🗑️ Session ${sessionId} permanently deleted`);
1372
1372
  return true;
1373
1373
  } catch (err) {
@@ -1383,13 +1383,13 @@ var session$1 = ({ strapi: strapi2 }) => ({
1383
1383
  async deleteInactiveSessions() {
1384
1384
  try {
1385
1385
  strapi2.log.info("[magic-sessionmanager] 🗑️ Deleting all inactive sessions...");
1386
- const inactiveSessions = await strapi2.entityService.findMany("api::session.session", {
1386
+ const inactiveSessions = await strapi2.entityService.findMany("plugin::magic-sessionmanager.session", {
1387
1387
  filters: { isActive: false },
1388
1388
  fields: ["id"]
1389
1389
  });
1390
1390
  let deletedCount = 0;
1391
1391
  for (const session2 of inactiveSessions) {
1392
- await strapi2.entityService.delete("api::session.session", session2.id);
1392
+ await strapi2.entityService.delete("plugin::magic-sessionmanager.session", session2.id);
1393
1393
  deletedCount++;
1394
1394
  }
1395
1395
  strapi2.log.info(`[magic-sessionmanager] ✅ Deleted ${deletedCount} inactive sessions`);
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.1",
2
+ "version": "2.0.1",
3
3
  "keywords": [
4
4
  "strapi",
5
5
  "strapi-plugin",