strapi-plugin-magic-link-v5 5.1.2 → 5.1.3
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 +31 -31
- package/dist/server/index.mjs +31 -31
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -222,35 +222,34 @@ Thanks.`,
|
|
|
222
222
|
}
|
|
223
223
|
return next();
|
|
224
224
|
});
|
|
225
|
-
|
|
226
|
-
setTimeout(() => {
|
|
225
|
+
setTimeout(async () => {
|
|
227
226
|
try {
|
|
228
|
-
rateLimiter2.
|
|
227
|
+
const rateLimiter2 = strapi2.plugin("magic-link").service("rate-limiter");
|
|
228
|
+
await rateLimiter2.cleanupExpired();
|
|
229
229
|
} catch (error2) {
|
|
230
|
-
strapi2.log.debug("Rate limit cleanup skipped - DB not ready");
|
|
230
|
+
strapi2.log.debug("[CLEANUP] Rate limit cleanup skipped - DB not ready");
|
|
231
231
|
}
|
|
232
232
|
}, 1e4);
|
|
233
|
-
setInterval(() => {
|
|
233
|
+
setInterval(async () => {
|
|
234
234
|
try {
|
|
235
|
-
rateLimiter2.
|
|
235
|
+
const rateLimiter2 = strapi2.plugin("magic-link").service("rate-limiter");
|
|
236
|
+
await rateLimiter2.cleanupExpired();
|
|
236
237
|
} catch (error2) {
|
|
237
|
-
strapi2.log.debug("Rate limit cleanup failed:", error2.message);
|
|
238
238
|
}
|
|
239
239
|
}, 30 * 60 * 1e3);
|
|
240
|
-
setTimeout(() => {
|
|
240
|
+
setTimeout(async () => {
|
|
241
241
|
try {
|
|
242
242
|
const otpService = strapi2.plugin("magic-link").service("otp");
|
|
243
|
-
otpService.cleanupExpiredCodes();
|
|
243
|
+
await otpService.cleanupExpiredCodes();
|
|
244
244
|
} catch (error2) {
|
|
245
|
-
strapi2.log.debug("OTP cleanup skipped - DB not ready");
|
|
245
|
+
strapi2.log.debug("[CLEANUP] OTP cleanup skipped - DB not ready");
|
|
246
246
|
}
|
|
247
247
|
}, 1e4);
|
|
248
|
-
setInterval(() => {
|
|
248
|
+
setInterval(async () => {
|
|
249
249
|
try {
|
|
250
250
|
const otpService = strapi2.plugin("magic-link").service("otp");
|
|
251
|
-
otpService.cleanupExpiredCodes();
|
|
251
|
+
await otpService.cleanupExpiredCodes();
|
|
252
252
|
} catch (error2) {
|
|
253
|
-
strapi2.log.error("OTP cleanup failed:", error2.message);
|
|
254
253
|
}
|
|
255
254
|
}, 5 * 60 * 1e3);
|
|
256
255
|
try {
|
|
@@ -27365,13 +27364,11 @@ var rateLimiter$1 = ({ strapi: strapi2 }) => ({
|
|
|
27365
27364
|
},
|
|
27366
27365
|
/**
|
|
27367
27366
|
* Clean up expired rate limit entries
|
|
27367
|
+
* Uses the strapi instance from module closure (not global.strapi)
|
|
27368
27368
|
*/
|
|
27369
27369
|
async cleanupExpired() {
|
|
27370
27370
|
try {
|
|
27371
|
-
|
|
27372
|
-
throw new Error("Strapi instance not available");
|
|
27373
|
-
}
|
|
27374
|
-
const pluginStore = commonjsGlobal.strapi.store({
|
|
27371
|
+
const pluginStore = strapi2.store({
|
|
27375
27372
|
type: "plugin",
|
|
27376
27373
|
name: "magic-link"
|
|
27377
27374
|
});
|
|
@@ -27391,14 +27388,12 @@ var rateLimiter$1 = ({ strapi: strapi2 }) => ({
|
|
|
27391
27388
|
});
|
|
27392
27389
|
if (cleaned > 0) {
|
|
27393
27390
|
await pluginStore.set({ key: "rate_limits", value: rateLimitData });
|
|
27394
|
-
|
|
27391
|
+
strapi2.log.info(`[CLEANUP] Cleaned up ${cleaned} expired rate limit entries`);
|
|
27395
27392
|
}
|
|
27396
27393
|
return { cleaned };
|
|
27397
27394
|
} catch (error2) {
|
|
27398
|
-
if (
|
|
27399
|
-
|
|
27400
|
-
} else {
|
|
27401
|
-
console.error("Error cleaning up rate limits:", error2);
|
|
27395
|
+
if (strapi2 && strapi2.log) {
|
|
27396
|
+
strapi2.log.debug("[CLEANUP] Rate limit cleanup skipped:", error2.message);
|
|
27402
27397
|
}
|
|
27403
27398
|
return { cleaned: 0 };
|
|
27404
27399
|
}
|
|
@@ -27448,14 +27443,14 @@ const QRCode = require$$2__default$3.default;
|
|
|
27448
27443
|
const emailHelpers = emailHelpers$3;
|
|
27449
27444
|
const cryptoUtils = crypto_1;
|
|
27450
27445
|
var otp$1 = ({ strapi: strapi2 }) => {
|
|
27451
|
-
|
|
27446
|
+
const strapiInstance = strapi2;
|
|
27452
27447
|
const getStrapi = () => {
|
|
27453
|
-
if (commonjsGlobal.strapi) {
|
|
27454
|
-
return commonjsGlobal.strapi;
|
|
27455
|
-
}
|
|
27456
27448
|
if (strapiInstance) {
|
|
27457
27449
|
return strapiInstance;
|
|
27458
27450
|
}
|
|
27451
|
+
if (commonjsGlobal.strapi) {
|
|
27452
|
+
return commonjsGlobal.strapi;
|
|
27453
|
+
}
|
|
27459
27454
|
throw new Error("Strapi instance not available");
|
|
27460
27455
|
};
|
|
27461
27456
|
const log = {
|
|
@@ -27740,26 +27735,31 @@ If you didn't request this code, you can safely ignore this email.
|
|
|
27740
27735
|
},
|
|
27741
27736
|
/**
|
|
27742
27737
|
* Clean up expired OTP codes
|
|
27738
|
+
* Uses strapiInstance from module closure for reliability in bundled plugins
|
|
27743
27739
|
*/
|
|
27744
27740
|
async cleanupExpiredCodes() {
|
|
27745
27741
|
try {
|
|
27746
|
-
|
|
27742
|
+
if (!strapiInstance) {
|
|
27743
|
+
return;
|
|
27744
|
+
}
|
|
27747
27745
|
const now = /* @__PURE__ */ new Date();
|
|
27748
|
-
const expiredCodes = await
|
|
27746
|
+
const expiredCodes = await strapiInstance.documents("plugin::magic-link.otp-code").findMany({
|
|
27749
27747
|
filters: {
|
|
27750
27748
|
expiresAt: { $lt: now }
|
|
27751
27749
|
}
|
|
27752
27750
|
});
|
|
27753
27751
|
for (const code of expiredCodes) {
|
|
27754
|
-
await
|
|
27752
|
+
await strapiInstance.documents("plugin::magic-link.otp-code").delete({
|
|
27755
27753
|
documentId: code.documentId
|
|
27756
27754
|
});
|
|
27757
27755
|
}
|
|
27758
27756
|
if (expiredCodes.length > 0) {
|
|
27759
|
-
|
|
27757
|
+
strapiInstance.log.info(`[CLEANUP] Cleaned up ${expiredCodes.length} expired OTP codes`);
|
|
27760
27758
|
}
|
|
27761
27759
|
} catch (error2) {
|
|
27762
|
-
|
|
27760
|
+
if (strapiInstance && strapiInstance.log) {
|
|
27761
|
+
strapiInstance.log.debug("[CLEANUP] OTP cleanup skipped:", error2.message);
|
|
27762
|
+
}
|
|
27763
27763
|
}
|
|
27764
27764
|
},
|
|
27765
27765
|
/**
|
package/dist/server/index.mjs
CHANGED
|
@@ -188,35 +188,34 @@ Thanks.`,
|
|
|
188
188
|
}
|
|
189
189
|
return next();
|
|
190
190
|
});
|
|
191
|
-
|
|
192
|
-
setTimeout(() => {
|
|
191
|
+
setTimeout(async () => {
|
|
193
192
|
try {
|
|
194
|
-
rateLimiter2.
|
|
193
|
+
const rateLimiter2 = strapi2.plugin("magic-link").service("rate-limiter");
|
|
194
|
+
await rateLimiter2.cleanupExpired();
|
|
195
195
|
} catch (error2) {
|
|
196
|
-
strapi2.log.debug("Rate limit cleanup skipped - DB not ready");
|
|
196
|
+
strapi2.log.debug("[CLEANUP] Rate limit cleanup skipped - DB not ready");
|
|
197
197
|
}
|
|
198
198
|
}, 1e4);
|
|
199
|
-
setInterval(() => {
|
|
199
|
+
setInterval(async () => {
|
|
200
200
|
try {
|
|
201
|
-
rateLimiter2.
|
|
201
|
+
const rateLimiter2 = strapi2.plugin("magic-link").service("rate-limiter");
|
|
202
|
+
await rateLimiter2.cleanupExpired();
|
|
202
203
|
} catch (error2) {
|
|
203
|
-
strapi2.log.debug("Rate limit cleanup failed:", error2.message);
|
|
204
204
|
}
|
|
205
205
|
}, 30 * 60 * 1e3);
|
|
206
|
-
setTimeout(() => {
|
|
206
|
+
setTimeout(async () => {
|
|
207
207
|
try {
|
|
208
208
|
const otpService = strapi2.plugin("magic-link").service("otp");
|
|
209
|
-
otpService.cleanupExpiredCodes();
|
|
209
|
+
await otpService.cleanupExpiredCodes();
|
|
210
210
|
} catch (error2) {
|
|
211
|
-
strapi2.log.debug("OTP cleanup skipped - DB not ready");
|
|
211
|
+
strapi2.log.debug("[CLEANUP] OTP cleanup skipped - DB not ready");
|
|
212
212
|
}
|
|
213
213
|
}, 1e4);
|
|
214
|
-
setInterval(() => {
|
|
214
|
+
setInterval(async () => {
|
|
215
215
|
try {
|
|
216
216
|
const otpService = strapi2.plugin("magic-link").service("otp");
|
|
217
|
-
otpService.cleanupExpiredCodes();
|
|
217
|
+
await otpService.cleanupExpiredCodes();
|
|
218
218
|
} catch (error2) {
|
|
219
|
-
strapi2.log.error("OTP cleanup failed:", error2.message);
|
|
220
219
|
}
|
|
221
220
|
}, 5 * 60 * 1e3);
|
|
222
221
|
try {
|
|
@@ -27331,13 +27330,11 @@ var rateLimiter$1 = ({ strapi: strapi2 }) => ({
|
|
|
27331
27330
|
},
|
|
27332
27331
|
/**
|
|
27333
27332
|
* Clean up expired rate limit entries
|
|
27333
|
+
* Uses the strapi instance from module closure (not global.strapi)
|
|
27334
27334
|
*/
|
|
27335
27335
|
async cleanupExpired() {
|
|
27336
27336
|
try {
|
|
27337
|
-
|
|
27338
|
-
throw new Error("Strapi instance not available");
|
|
27339
|
-
}
|
|
27340
|
-
const pluginStore = commonjsGlobal.strapi.store({
|
|
27337
|
+
const pluginStore = strapi2.store({
|
|
27341
27338
|
type: "plugin",
|
|
27342
27339
|
name: "magic-link"
|
|
27343
27340
|
});
|
|
@@ -27357,14 +27354,12 @@ var rateLimiter$1 = ({ strapi: strapi2 }) => ({
|
|
|
27357
27354
|
});
|
|
27358
27355
|
if (cleaned > 0) {
|
|
27359
27356
|
await pluginStore.set({ key: "rate_limits", value: rateLimitData });
|
|
27360
|
-
|
|
27357
|
+
strapi2.log.info(`[CLEANUP] Cleaned up ${cleaned} expired rate limit entries`);
|
|
27361
27358
|
}
|
|
27362
27359
|
return { cleaned };
|
|
27363
27360
|
} catch (error2) {
|
|
27364
|
-
if (
|
|
27365
|
-
|
|
27366
|
-
} else {
|
|
27367
|
-
console.error("Error cleaning up rate limits:", error2);
|
|
27361
|
+
if (strapi2 && strapi2.log) {
|
|
27362
|
+
strapi2.log.debug("[CLEANUP] Rate limit cleanup skipped:", error2.message);
|
|
27368
27363
|
}
|
|
27369
27364
|
return { cleaned: 0 };
|
|
27370
27365
|
}
|
|
@@ -27414,14 +27409,14 @@ const QRCode = require$$2$4;
|
|
|
27414
27409
|
const emailHelpers = emailHelpers$3;
|
|
27415
27410
|
const cryptoUtils = crypto_1;
|
|
27416
27411
|
var otp$1 = ({ strapi: strapi2 }) => {
|
|
27417
|
-
|
|
27412
|
+
const strapiInstance = strapi2;
|
|
27418
27413
|
const getStrapi = () => {
|
|
27419
|
-
if (commonjsGlobal.strapi) {
|
|
27420
|
-
return commonjsGlobal.strapi;
|
|
27421
|
-
}
|
|
27422
27414
|
if (strapiInstance) {
|
|
27423
27415
|
return strapiInstance;
|
|
27424
27416
|
}
|
|
27417
|
+
if (commonjsGlobal.strapi) {
|
|
27418
|
+
return commonjsGlobal.strapi;
|
|
27419
|
+
}
|
|
27425
27420
|
throw new Error("Strapi instance not available");
|
|
27426
27421
|
};
|
|
27427
27422
|
const log = {
|
|
@@ -27706,26 +27701,31 @@ If you didn't request this code, you can safely ignore this email.
|
|
|
27706
27701
|
},
|
|
27707
27702
|
/**
|
|
27708
27703
|
* Clean up expired OTP codes
|
|
27704
|
+
* Uses strapiInstance from module closure for reliability in bundled plugins
|
|
27709
27705
|
*/
|
|
27710
27706
|
async cleanupExpiredCodes() {
|
|
27711
27707
|
try {
|
|
27712
|
-
|
|
27708
|
+
if (!strapiInstance) {
|
|
27709
|
+
return;
|
|
27710
|
+
}
|
|
27713
27711
|
const now = /* @__PURE__ */ new Date();
|
|
27714
|
-
const expiredCodes = await
|
|
27712
|
+
const expiredCodes = await strapiInstance.documents("plugin::magic-link.otp-code").findMany({
|
|
27715
27713
|
filters: {
|
|
27716
27714
|
expiresAt: { $lt: now }
|
|
27717
27715
|
}
|
|
27718
27716
|
});
|
|
27719
27717
|
for (const code of expiredCodes) {
|
|
27720
|
-
await
|
|
27718
|
+
await strapiInstance.documents("plugin::magic-link.otp-code").delete({
|
|
27721
27719
|
documentId: code.documentId
|
|
27722
27720
|
});
|
|
27723
27721
|
}
|
|
27724
27722
|
if (expiredCodes.length > 0) {
|
|
27725
|
-
|
|
27723
|
+
strapiInstance.log.info(`[CLEANUP] Cleaned up ${expiredCodes.length} expired OTP codes`);
|
|
27726
27724
|
}
|
|
27727
27725
|
} catch (error2) {
|
|
27728
|
-
|
|
27726
|
+
if (strapiInstance && strapiInstance.log) {
|
|
27727
|
+
strapiInstance.log.debug("[CLEANUP] OTP cleanup skipped:", error2.message);
|
|
27728
|
+
}
|
|
27729
27729
|
}
|
|
27730
27730
|
},
|
|
27731
27731
|
/**
|
package/package.json
CHANGED