strapi-plugin-magic-sessionmanager 4.3.1 → 4.3.2
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/server/index.js +68 -26
- package/dist/server/index.mjs +68 -26
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -516,9 +516,20 @@ var bootstrap$1 = async ({ strapi: strapi2 }) => {
|
|
|
516
516
|
}
|
|
517
517
|
let userDocId = user.documentId;
|
|
518
518
|
if (!userDocId && user.id) {
|
|
519
|
-
const fullUser = await strapi2.entityService.findOne(USER_UID$2, user.id
|
|
520
|
-
|
|
519
|
+
const fullUser = await strapi2.entityService.findOne(USER_UID$2, user.id, {
|
|
520
|
+
fields: ["documentId"]
|
|
521
|
+
});
|
|
522
|
+
userDocId = fullUser?.documentId;
|
|
523
|
+
if (!userDocId) {
|
|
524
|
+
log.error(`[ERROR] Could not get documentId for user ${user.id} - session NOT created!`);
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
521
527
|
}
|
|
528
|
+
if (!userDocId) {
|
|
529
|
+
log.error("[ERROR] No user documentId available - cannot create session");
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
log.debug(`[SESSION] Creating session for user documentId: ${userDocId}`);
|
|
522
533
|
const newSession = await sessionService.createSession({
|
|
523
534
|
userId: userDocId,
|
|
524
535
|
ip,
|
|
@@ -530,7 +541,11 @@ var bootstrap$1 = async ({ strapi: strapi2 }) => {
|
|
|
530
541
|
geoData
|
|
531
542
|
// Store geolocation data if available
|
|
532
543
|
});
|
|
533
|
-
|
|
544
|
+
if (newSession?.documentId) {
|
|
545
|
+
log.info(`[SUCCESS] Session ${newSession.documentId} created for user ${userDocId} (IP: ${ip})`);
|
|
546
|
+
} else {
|
|
547
|
+
log.error(`[ERROR] Session creation returned no documentId for user ${userDocId}`);
|
|
548
|
+
}
|
|
534
549
|
if (geoData && (config2.enableEmailAlerts || config2.enableWebhooks)) {
|
|
535
550
|
try {
|
|
536
551
|
const notificationService = strapi2.plugin("magic-sessionmanager").service("notifications");
|
|
@@ -771,16 +786,23 @@ async function registerSessionAwareAuthStrategy(strapi2, log) {
|
|
|
771
786
|
if (!userDocId) {
|
|
772
787
|
return decoded;
|
|
773
788
|
}
|
|
789
|
+
strapi2.log.debug(`[magic-sessionmanager] [JWT] Checking sessions for user: ${userDocId}`);
|
|
774
790
|
const activeSessions = await strapi2.documents(SESSION_UID$3).findMany({
|
|
775
791
|
filters: {
|
|
776
792
|
user: { documentId: userDocId },
|
|
777
793
|
isActive: true
|
|
778
794
|
},
|
|
779
|
-
limit: 1
|
|
795
|
+
limit: 1,
|
|
796
|
+
populate: { user: { fields: ["documentId"] } }
|
|
780
797
|
});
|
|
798
|
+
strapi2.log.debug(`[magic-sessionmanager] [JWT] Found ${activeSessions?.length || 0} active sessions`);
|
|
781
799
|
if (!activeSessions || activeSessions.length === 0) {
|
|
800
|
+
const allSessions = await strapi2.documents(SESSION_UID$3).findMany({
|
|
801
|
+
filters: { user: { documentId: userDocId } },
|
|
802
|
+
limit: 5
|
|
803
|
+
});
|
|
782
804
|
strapi2.log.info(
|
|
783
|
-
`[magic-sessionmanager] [JWT-BLOCKED] Valid JWT but no active session (user: ${userDocId.substring(0, 8)}
|
|
805
|
+
`[magic-sessionmanager] [JWT-BLOCKED] Valid JWT but no active session (user: ${userDocId.substring(0, 8)}..., total sessions: ${allSessions?.length || 0})`
|
|
784
806
|
);
|
|
785
807
|
return null;
|
|
786
808
|
}
|
|
@@ -2585,7 +2607,7 @@ var session$1 = ({ strapi: strapi2 }) => {
|
|
|
2585
2607
|
}
|
|
2586
2608
|
};
|
|
2587
2609
|
};
|
|
2588
|
-
const version$1 = "4.3.
|
|
2610
|
+
const version$1 = "4.3.1";
|
|
2589
2611
|
const require$$2 = {
|
|
2590
2612
|
version: version$1
|
|
2591
2613
|
};
|
|
@@ -17213,6 +17235,16 @@ const providerFactory = (options2 = {}) => {
|
|
|
17213
17235
|
}
|
|
17214
17236
|
};
|
|
17215
17237
|
};
|
|
17238
|
+
const parallelWithOrderedErrors = async (promises) => {
|
|
17239
|
+
const results = await Promise.allSettled(promises);
|
|
17240
|
+
for (let i2 = 0; i2 < results.length; i2 += 1) {
|
|
17241
|
+
const result = results[i2];
|
|
17242
|
+
if (result.status === "rejected") {
|
|
17243
|
+
throw result.reason;
|
|
17244
|
+
}
|
|
17245
|
+
}
|
|
17246
|
+
return results.map((r) => r.value);
|
|
17247
|
+
};
|
|
17216
17248
|
const traverseEntity = async (visitor2, options2, entity) => {
|
|
17217
17249
|
const { path: path2 = {
|
|
17218
17250
|
raw: null,
|
|
@@ -17313,15 +17345,13 @@ const traverseEntity = async (visitor2, options2, entity) => {
|
|
|
17313
17345
|
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
|
17314
17346
|
const method = isMorphRelation ? traverseMorphRelationTarget : traverseRelationTarget(getModel(attribute.target));
|
|
17315
17347
|
if (fp.isArray(value)) {
|
|
17316
|
-
|
|
17317
|
-
for (let i3 = 0; i3 < value.length; i3 += 1) {
|
|
17348
|
+
copy[key] = await parallelWithOrderedErrors(value.map((item, i3) => {
|
|
17318
17349
|
const arrayPath = {
|
|
17319
17350
|
...newPath,
|
|
17320
17351
|
rawWithIndices: fp.isNil(newPath.rawWithIndices) ? `${i3}` : `${newPath.rawWithIndices}.${i3}`
|
|
17321
17352
|
};
|
|
17322
|
-
|
|
17323
|
-
}
|
|
17324
|
-
copy[key] = res;
|
|
17353
|
+
return method(visitor2, arrayPath, item);
|
|
17354
|
+
}));
|
|
17325
17355
|
} else {
|
|
17326
17356
|
copy[key] = await method(visitor2, newPath, value);
|
|
17327
17357
|
}
|
|
@@ -17335,15 +17365,13 @@ const traverseEntity = async (visitor2, options2, entity) => {
|
|
|
17335
17365
|
path: newPath
|
|
17336
17366
|
};
|
|
17337
17367
|
if (fp.isArray(value)) {
|
|
17338
|
-
|
|
17339
|
-
for (let i3 = 0; i3 < value.length; i3 += 1) {
|
|
17368
|
+
copy[key] = await parallelWithOrderedErrors(value.map((item, i3) => {
|
|
17340
17369
|
const arrayPath = {
|
|
17341
17370
|
...newPath,
|
|
17342
17371
|
rawWithIndices: fp.isNil(newPath.rawWithIndices) ? `${i3}` : `${newPath.rawWithIndices}.${i3}`
|
|
17343
17372
|
};
|
|
17344
|
-
|
|
17345
|
-
}
|
|
17346
|
-
copy[key] = res;
|
|
17373
|
+
return traverseMediaTarget(visitor2, arrayPath, item);
|
|
17374
|
+
}));
|
|
17347
17375
|
} else {
|
|
17348
17376
|
copy[key] = await traverseMediaTarget(visitor2, newPath, value);
|
|
17349
17377
|
}
|
|
@@ -17358,15 +17386,13 @@ const traverseEntity = async (visitor2, options2, entity) => {
|
|
|
17358
17386
|
};
|
|
17359
17387
|
const targetSchema = getModel(attribute.component);
|
|
17360
17388
|
if (fp.isArray(value)) {
|
|
17361
|
-
|
|
17362
|
-
for (let i3 = 0; i3 < value.length; i3 += 1) {
|
|
17389
|
+
copy[key] = await parallelWithOrderedErrors(value.map((item, i3) => {
|
|
17363
17390
|
const arrayPath = {
|
|
17364
17391
|
...newPath,
|
|
17365
17392
|
rawWithIndices: fp.isNil(newPath.rawWithIndices) ? `${i3}` : `${newPath.rawWithIndices}.${i3}`
|
|
17366
17393
|
};
|
|
17367
|
-
|
|
17368
|
-
}
|
|
17369
|
-
copy[key] = res;
|
|
17394
|
+
return traverseComponent(visitor2, arrayPath, targetSchema, item);
|
|
17395
|
+
}));
|
|
17370
17396
|
} else {
|
|
17371
17397
|
copy[key] = await traverseComponent(visitor2, newPath, targetSchema, value);
|
|
17372
17398
|
}
|
|
@@ -17379,15 +17405,13 @@ const traverseEntity = async (visitor2, options2, entity) => {
|
|
|
17379
17405
|
attribute,
|
|
17380
17406
|
path: newPath
|
|
17381
17407
|
};
|
|
17382
|
-
|
|
17383
|
-
for (let i3 = 0; i3 < value.length; i3 += 1) {
|
|
17408
|
+
copy[key] = await parallelWithOrderedErrors(value.map((item, i3) => {
|
|
17384
17409
|
const arrayPath = {
|
|
17385
17410
|
...newPath,
|
|
17386
17411
|
rawWithIndices: fp.isNil(newPath.rawWithIndices) ? `${i3}` : `${newPath.rawWithIndices}.${i3}`
|
|
17387
17412
|
};
|
|
17388
|
-
|
|
17389
|
-
}
|
|
17390
|
-
copy[key] = res;
|
|
17413
|
+
return visitDynamicZoneEntry(visitor2, arrayPath, item);
|
|
17414
|
+
}));
|
|
17391
17415
|
continue;
|
|
17392
17416
|
}
|
|
17393
17417
|
}
|
|
@@ -18133,6 +18157,23 @@ const generateInstallId = (projectId, installId) => {
|
|
|
18133
18157
|
return require$$1__default.default.randomUUID();
|
|
18134
18158
|
}
|
|
18135
18159
|
};
|
|
18160
|
+
const createModelCache = (getModelFn) => {
|
|
18161
|
+
const cache = /* @__PURE__ */ new Map();
|
|
18162
|
+
return {
|
|
18163
|
+
getModel(uid) {
|
|
18164
|
+
const cached2 = cache.get(uid);
|
|
18165
|
+
if (cached2) {
|
|
18166
|
+
return cached2;
|
|
18167
|
+
}
|
|
18168
|
+
const model = getModelFn(uid);
|
|
18169
|
+
cache.set(uid, model);
|
|
18170
|
+
return model;
|
|
18171
|
+
},
|
|
18172
|
+
clear() {
|
|
18173
|
+
cache.clear();
|
|
18174
|
+
}
|
|
18175
|
+
};
|
|
18176
|
+
};
|
|
18136
18177
|
var map$2;
|
|
18137
18178
|
try {
|
|
18138
18179
|
map$2 = Map;
|
|
@@ -38821,6 +38862,7 @@ const dist = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty
|
|
|
38821
38862
|
augmentSchema,
|
|
38822
38863
|
contentTypes: contentTypes$1,
|
|
38823
38864
|
createContentApiRoutesFactory,
|
|
38865
|
+
createModelCache,
|
|
38824
38866
|
dates,
|
|
38825
38867
|
env,
|
|
38826
38868
|
errors: errors$1,
|
package/dist/server/index.mjs
CHANGED
|
@@ -503,9 +503,20 @@ var bootstrap$1 = async ({ strapi: strapi2 }) => {
|
|
|
503
503
|
}
|
|
504
504
|
let userDocId = user.documentId;
|
|
505
505
|
if (!userDocId && user.id) {
|
|
506
|
-
const fullUser = await strapi2.entityService.findOne(USER_UID$2, user.id
|
|
507
|
-
|
|
506
|
+
const fullUser = await strapi2.entityService.findOne(USER_UID$2, user.id, {
|
|
507
|
+
fields: ["documentId"]
|
|
508
|
+
});
|
|
509
|
+
userDocId = fullUser?.documentId;
|
|
510
|
+
if (!userDocId) {
|
|
511
|
+
log.error(`[ERROR] Could not get documentId for user ${user.id} - session NOT created!`);
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
508
514
|
}
|
|
515
|
+
if (!userDocId) {
|
|
516
|
+
log.error("[ERROR] No user documentId available - cannot create session");
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
log.debug(`[SESSION] Creating session for user documentId: ${userDocId}`);
|
|
509
520
|
const newSession = await sessionService.createSession({
|
|
510
521
|
userId: userDocId,
|
|
511
522
|
ip,
|
|
@@ -517,7 +528,11 @@ var bootstrap$1 = async ({ strapi: strapi2 }) => {
|
|
|
517
528
|
geoData
|
|
518
529
|
// Store geolocation data if available
|
|
519
530
|
});
|
|
520
|
-
|
|
531
|
+
if (newSession?.documentId) {
|
|
532
|
+
log.info(`[SUCCESS] Session ${newSession.documentId} created for user ${userDocId} (IP: ${ip})`);
|
|
533
|
+
} else {
|
|
534
|
+
log.error(`[ERROR] Session creation returned no documentId for user ${userDocId}`);
|
|
535
|
+
}
|
|
521
536
|
if (geoData && (config2.enableEmailAlerts || config2.enableWebhooks)) {
|
|
522
537
|
try {
|
|
523
538
|
const notificationService = strapi2.plugin("magic-sessionmanager").service("notifications");
|
|
@@ -758,16 +773,23 @@ async function registerSessionAwareAuthStrategy(strapi2, log) {
|
|
|
758
773
|
if (!userDocId) {
|
|
759
774
|
return decoded;
|
|
760
775
|
}
|
|
776
|
+
strapi2.log.debug(`[magic-sessionmanager] [JWT] Checking sessions for user: ${userDocId}`);
|
|
761
777
|
const activeSessions = await strapi2.documents(SESSION_UID$3).findMany({
|
|
762
778
|
filters: {
|
|
763
779
|
user: { documentId: userDocId },
|
|
764
780
|
isActive: true
|
|
765
781
|
},
|
|
766
|
-
limit: 1
|
|
782
|
+
limit: 1,
|
|
783
|
+
populate: { user: { fields: ["documentId"] } }
|
|
767
784
|
});
|
|
785
|
+
strapi2.log.debug(`[magic-sessionmanager] [JWT] Found ${activeSessions?.length || 0} active sessions`);
|
|
768
786
|
if (!activeSessions || activeSessions.length === 0) {
|
|
787
|
+
const allSessions = await strapi2.documents(SESSION_UID$3).findMany({
|
|
788
|
+
filters: { user: { documentId: userDocId } },
|
|
789
|
+
limit: 5
|
|
790
|
+
});
|
|
769
791
|
strapi2.log.info(
|
|
770
|
-
`[magic-sessionmanager] [JWT-BLOCKED] Valid JWT but no active session (user: ${userDocId.substring(0, 8)}
|
|
792
|
+
`[magic-sessionmanager] [JWT-BLOCKED] Valid JWT but no active session (user: ${userDocId.substring(0, 8)}..., total sessions: ${allSessions?.length || 0})`
|
|
771
793
|
);
|
|
772
794
|
return null;
|
|
773
795
|
}
|
|
@@ -2572,7 +2594,7 @@ var session$1 = ({ strapi: strapi2 }) => {
|
|
|
2572
2594
|
}
|
|
2573
2595
|
};
|
|
2574
2596
|
};
|
|
2575
|
-
const version$1 = "4.3.
|
|
2597
|
+
const version$1 = "4.3.1";
|
|
2576
2598
|
const require$$2 = {
|
|
2577
2599
|
version: version$1
|
|
2578
2600
|
};
|
|
@@ -17200,6 +17222,16 @@ const providerFactory = (options2 = {}) => {
|
|
|
17200
17222
|
}
|
|
17201
17223
|
};
|
|
17202
17224
|
};
|
|
17225
|
+
const parallelWithOrderedErrors = async (promises) => {
|
|
17226
|
+
const results = await Promise.allSettled(promises);
|
|
17227
|
+
for (let i2 = 0; i2 < results.length; i2 += 1) {
|
|
17228
|
+
const result = results[i2];
|
|
17229
|
+
if (result.status === "rejected") {
|
|
17230
|
+
throw result.reason;
|
|
17231
|
+
}
|
|
17232
|
+
}
|
|
17233
|
+
return results.map((r) => r.value);
|
|
17234
|
+
};
|
|
17203
17235
|
const traverseEntity = async (visitor2, options2, entity) => {
|
|
17204
17236
|
const { path: path2 = {
|
|
17205
17237
|
raw: null,
|
|
@@ -17300,15 +17332,13 @@ const traverseEntity = async (visitor2, options2, entity) => {
|
|
|
17300
17332
|
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
|
17301
17333
|
const method = isMorphRelation ? traverseMorphRelationTarget : traverseRelationTarget(getModel(attribute.target));
|
|
17302
17334
|
if (fp.isArray(value)) {
|
|
17303
|
-
|
|
17304
|
-
for (let i3 = 0; i3 < value.length; i3 += 1) {
|
|
17335
|
+
copy[key] = await parallelWithOrderedErrors(value.map((item, i3) => {
|
|
17305
17336
|
const arrayPath = {
|
|
17306
17337
|
...newPath,
|
|
17307
17338
|
rawWithIndices: fp.isNil(newPath.rawWithIndices) ? `${i3}` : `${newPath.rawWithIndices}.${i3}`
|
|
17308
17339
|
};
|
|
17309
|
-
|
|
17310
|
-
}
|
|
17311
|
-
copy[key] = res;
|
|
17340
|
+
return method(visitor2, arrayPath, item);
|
|
17341
|
+
}));
|
|
17312
17342
|
} else {
|
|
17313
17343
|
copy[key] = await method(visitor2, newPath, value);
|
|
17314
17344
|
}
|
|
@@ -17322,15 +17352,13 @@ const traverseEntity = async (visitor2, options2, entity) => {
|
|
|
17322
17352
|
path: newPath
|
|
17323
17353
|
};
|
|
17324
17354
|
if (fp.isArray(value)) {
|
|
17325
|
-
|
|
17326
|
-
for (let i3 = 0; i3 < value.length; i3 += 1) {
|
|
17355
|
+
copy[key] = await parallelWithOrderedErrors(value.map((item, i3) => {
|
|
17327
17356
|
const arrayPath = {
|
|
17328
17357
|
...newPath,
|
|
17329
17358
|
rawWithIndices: fp.isNil(newPath.rawWithIndices) ? `${i3}` : `${newPath.rawWithIndices}.${i3}`
|
|
17330
17359
|
};
|
|
17331
|
-
|
|
17332
|
-
}
|
|
17333
|
-
copy[key] = res;
|
|
17360
|
+
return traverseMediaTarget(visitor2, arrayPath, item);
|
|
17361
|
+
}));
|
|
17334
17362
|
} else {
|
|
17335
17363
|
copy[key] = await traverseMediaTarget(visitor2, newPath, value);
|
|
17336
17364
|
}
|
|
@@ -17345,15 +17373,13 @@ const traverseEntity = async (visitor2, options2, entity) => {
|
|
|
17345
17373
|
};
|
|
17346
17374
|
const targetSchema = getModel(attribute.component);
|
|
17347
17375
|
if (fp.isArray(value)) {
|
|
17348
|
-
|
|
17349
|
-
for (let i3 = 0; i3 < value.length; i3 += 1) {
|
|
17376
|
+
copy[key] = await parallelWithOrderedErrors(value.map((item, i3) => {
|
|
17350
17377
|
const arrayPath = {
|
|
17351
17378
|
...newPath,
|
|
17352
17379
|
rawWithIndices: fp.isNil(newPath.rawWithIndices) ? `${i3}` : `${newPath.rawWithIndices}.${i3}`
|
|
17353
17380
|
};
|
|
17354
|
-
|
|
17355
|
-
}
|
|
17356
|
-
copy[key] = res;
|
|
17381
|
+
return traverseComponent(visitor2, arrayPath, targetSchema, item);
|
|
17382
|
+
}));
|
|
17357
17383
|
} else {
|
|
17358
17384
|
copy[key] = await traverseComponent(visitor2, newPath, targetSchema, value);
|
|
17359
17385
|
}
|
|
@@ -17366,15 +17392,13 @@ const traverseEntity = async (visitor2, options2, entity) => {
|
|
|
17366
17392
|
attribute,
|
|
17367
17393
|
path: newPath
|
|
17368
17394
|
};
|
|
17369
|
-
|
|
17370
|
-
for (let i3 = 0; i3 < value.length; i3 += 1) {
|
|
17395
|
+
copy[key] = await parallelWithOrderedErrors(value.map((item, i3) => {
|
|
17371
17396
|
const arrayPath = {
|
|
17372
17397
|
...newPath,
|
|
17373
17398
|
rawWithIndices: fp.isNil(newPath.rawWithIndices) ? `${i3}` : `${newPath.rawWithIndices}.${i3}`
|
|
17374
17399
|
};
|
|
17375
|
-
|
|
17376
|
-
}
|
|
17377
|
-
copy[key] = res;
|
|
17400
|
+
return visitDynamicZoneEntry(visitor2, arrayPath, item);
|
|
17401
|
+
}));
|
|
17378
17402
|
continue;
|
|
17379
17403
|
}
|
|
17380
17404
|
}
|
|
@@ -18120,6 +18144,23 @@ const generateInstallId = (projectId, installId) => {
|
|
|
18120
18144
|
return require$$1.randomUUID();
|
|
18121
18145
|
}
|
|
18122
18146
|
};
|
|
18147
|
+
const createModelCache = (getModelFn) => {
|
|
18148
|
+
const cache = /* @__PURE__ */ new Map();
|
|
18149
|
+
return {
|
|
18150
|
+
getModel(uid) {
|
|
18151
|
+
const cached2 = cache.get(uid);
|
|
18152
|
+
if (cached2) {
|
|
18153
|
+
return cached2;
|
|
18154
|
+
}
|
|
18155
|
+
const model = getModelFn(uid);
|
|
18156
|
+
cache.set(uid, model);
|
|
18157
|
+
return model;
|
|
18158
|
+
},
|
|
18159
|
+
clear() {
|
|
18160
|
+
cache.clear();
|
|
18161
|
+
}
|
|
18162
|
+
};
|
|
18163
|
+
};
|
|
18123
18164
|
var map$2;
|
|
18124
18165
|
try {
|
|
18125
18166
|
map$2 = Map;
|
|
@@ -38808,6 +38849,7 @@ const dist = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty
|
|
|
38808
38849
|
augmentSchema,
|
|
38809
38850
|
contentTypes: contentTypes$1,
|
|
38810
38851
|
createContentApiRoutesFactory,
|
|
38852
|
+
createModelCache,
|
|
38811
38853
|
dates,
|
|
38812
38854
|
env,
|
|
38813
38855
|
errors: errors$1,
|
package/package.json
CHANGED