strapi-plugin-magic-sessionmanager 4.10.0 → 4.11.0

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.
Files changed (31) hide show
  1. package/CHANGELOG.md +44 -6
  2. package/README.md +251 -69
  3. package/dist/admin/{Analytics-CdmRsigN.js → Analytics-CBHeWeGn.js} +1 -1
  4. package/dist/admin/{Analytics-PRqsLMEx.mjs → Analytics-D56O8Q6e.mjs} +1 -1
  5. package/dist/admin/{App-DUMCbuCr.js → App-D4cBPwB_.js} +2 -3
  6. package/dist/admin/{App-BSeYF7KA.mjs → App-EDIkLJdb.mjs} +2 -3
  7. package/dist/admin/{OnlineUsersWidget-CDZ19_PT.js → OnlineUsersWidget-BF2R2YIy.js} +1 -1
  8. package/dist/admin/{OnlineUsersWidget-B5pXzqM9.mjs → OnlineUsersWidget-MwUutkKQ.mjs} +1 -1
  9. package/dist/admin/{Settings-CrLzRXrA.js → Settings-CMzEF8EH.js} +9 -3
  10. package/dist/admin/{Settings-B-GRuWjT.mjs → Settings-bLMyi0BN.mjs} +8 -2
  11. package/dist/admin/{de-DwUCBY1b.mjs → de-CxfuTF6C.mjs} +0 -42
  12. package/dist/admin/{de-Dzo1tVoJ.js → de-DVNTHmSo.js} +0 -42
  13. package/dist/admin/{en-Dd0wXfgR.mjs → en-BcPIlQYL.mjs} +0 -42
  14. package/dist/admin/{en-CL5llI55.js → en-BuVXIcHA.js} +0 -42
  15. package/dist/admin/{es-CiNDwv_f.js → es-CEteHmBO.js} +0 -42
  16. package/dist/admin/{es-Cl5IwDA4.mjs → es-DxHpaNA1.mjs} +0 -42
  17. package/dist/admin/{fr-DBOQ-UDm.js → fr-BMd2-wW7.js} +0 -42
  18. package/dist/admin/{fr-DhADj8Zs.mjs → fr-Dw43lHg7.mjs} +0 -42
  19. package/dist/admin/{index-CaLVyCio.js → index-DvNfekoR.js} +9 -19
  20. package/dist/admin/{index-CHACmZsg.mjs → index-qa6Qnfkc.mjs} +9 -19
  21. package/dist/admin/index.js +1 -1
  22. package/dist/admin/index.mjs +1 -1
  23. package/dist/admin/{pt-CT6VpDMM.mjs → pt-7jnxDSX-.mjs} +0 -42
  24. package/dist/admin/{pt-m73K1nJ0.js → pt-BvO63p01.js} +0 -42
  25. package/dist/server/index.js +26 -592
  26. package/dist/server/index.mjs +26 -592
  27. package/package.json +29 -13
  28. package/dist/admin/License-BeD7Du6r.js +0 -443
  29. package/dist/admin/License-D5W_l35e.mjs +0 -443
  30. package/dist/admin/maskSensitiveValue-BWcSjow7.js +0 -9
  31. package/dist/admin/maskSensitiveValue-lLRhN_S7.mjs +0 -10
@@ -785,10 +785,21 @@ var require_plugin_store = __commonJS({
785
785
  async function setPluginStoreValue(strapi2, key, value) {
786
786
  await withPluginStoreKey(strapi2, key, (store) => store.set({ key, value }));
787
787
  }
788
+ var LEGACY_LICENSE_STORE_KEYS = Object.freeze(["licenseKey", "lastValidated", "deviceId"]);
789
+ async function removeLegacyLicenseData(strapi2) {
790
+ const query = strapi2?.db?.query?.(CORE_STORE_UID);
791
+ if (!query || typeof query.deleteMany !== "function") return 0;
792
+ const result = await query.deleteMany({
793
+ where: { key: { $in: LEGACY_LICENSE_STORE_KEYS.map(coreStoreKey) } }
794
+ });
795
+ return Number(result?.count) || 0;
796
+ }
788
797
  module.exports = {
798
+ LEGACY_LICENSE_STORE_KEYS,
789
799
  PLUGIN_ID,
790
800
  collapseDuplicateStoreRows,
791
801
  coreStoreKey,
802
+ removeLegacyLicenseData,
792
803
  setPluginStoreValue,
793
804
  withPluginStoreKey
794
805
  };
@@ -5905,7 +5916,7 @@ var require_bootstrap = __commonJS({
5905
5916
  initCoordination,
5906
5917
  LockTimeoutError
5907
5918
  } = require_coordination();
5908
- var { withPluginStoreKey } = require_plugin_store();
5919
+ var { removeLegacyLicenseData, withPluginStoreKey } = require_plugin_store();
5909
5920
  var {
5910
5921
  classifyJwtIssuingRequest,
5911
5922
  isFailedLoginTrackedPath,
@@ -5939,6 +5950,16 @@ var require_bootstrap = __commonJS({
5939
5950
  }
5940
5951
  return settings;
5941
5952
  }
5953
+ async function removeLegacyLicenseRows(strapi2, log) {
5954
+ try {
5955
+ const removed = await removeLegacyLicenseData(strapi2);
5956
+ if (removed > 0) {
5957
+ log.info(`[CLEANUP] Removed ${removed} stored value(s) of the former license feature`);
5958
+ }
5959
+ } catch (err) {
5960
+ log.warn("[CLEANUP] Could not remove former license data:", err?.name || "Error");
5961
+ }
5962
+ }
5942
5963
  module.exports = async ({ strapi: strapi2 }) => {
5943
5964
  const log = createLogger(strapi2);
5944
5965
  log.info("[START] Bootstrap starting...");
@@ -5953,9 +5974,7 @@ var require_bootstrap = __commonJS({
5953
5974
  await checkEncryptionKeyConsistency(strapi2, log);
5954
5975
  await ensureSessionLookupIndexes(strapi2, log);
5955
5976
  await registerSessionAwareAuthStrategy(strapi2);
5956
- const licenseGuardService = strapi2.plugin("magic-sessionmanager").service("license-guard");
5957
- await licenseGuardService.initialize();
5958
- log.info("[SUCCESS] Session Manager active - all features are available without a license key");
5977
+ await removeLegacyLicenseRows(strapi2, log);
5959
5978
  const sessionService = strapi2.plugin("magic-sessionmanager").service("session");
5960
5979
  if (!strapi2.sessionManagerIntervals) {
5961
5980
  strapi2.sessionManagerIntervals = {};
@@ -6915,7 +6934,9 @@ var require_bootstrap = __commonJS({
6915
6934
  });
6916
6935
  const authenticatedRole = roles?.[0];
6917
6936
  if (!authenticatedRole) {
6918
- log.warn("Authenticated role not found - skipping permission setup");
6937
+ log.info(
6938
+ "Authenticated role does not exist yet; permission setup runs again on the first Session Manager API request"
6939
+ );
6919
6940
  return false;
6920
6941
  }
6921
6942
  const requiredActions = [
@@ -7886,52 +7907,6 @@ var require_admin = __commonJS({
7886
7907
  description: "Get aggregate end-user counts only (admin)"
7887
7908
  }
7888
7909
  },
7889
- // ============================ LICENSE ============================
7890
- {
7891
- method: "GET",
7892
- path: "/license/status",
7893
- handler: "license.getStatus",
7894
- config: {
7895
- policies: adminPolicy(),
7896
- description: "Get license status (admin)"
7897
- }
7898
- },
7899
- {
7900
- method: "POST",
7901
- path: "/license/auto-create",
7902
- handler: "license.autoCreate",
7903
- config: {
7904
- policies: adminPolicy(),
7905
- description: "Auto-create license for current admin (admin)"
7906
- }
7907
- },
7908
- {
7909
- method: "POST",
7910
- path: "/license/create",
7911
- handler: "license.createAndActivate",
7912
- config: {
7913
- policies: adminPolicy(),
7914
- description: "Create and activate a new license (admin)"
7915
- }
7916
- },
7917
- {
7918
- method: "POST",
7919
- path: "/license/ping",
7920
- handler: "license.ping",
7921
- config: {
7922
- policies: adminPolicy(),
7923
- description: "Ping the license server (admin)"
7924
- }
7925
- },
7926
- {
7927
- method: "POST",
7928
- path: "/license/store-key",
7929
- handler: "license.storeKey",
7930
- config: {
7931
- policies: adminPolicy(),
7932
- description: "Store a license key (admin)"
7933
- }
7934
- },
7935
7910
  // ============================ GEOLOCATION ============================
7936
7911
  {
7937
7912
  method: "GET",
@@ -9285,182 +9260,6 @@ var require_session = __commonJS({
9285
9260
  }
9286
9261
  });
9287
9262
 
9288
- // server/src/controllers/license.js
9289
- var require_license = __commonJS({
9290
- "server/src/controllers/license.js"(exports, module) {
9291
- "use strict";
9292
- var { sendServerError } = require_http_errors();
9293
- var PROVIDER_UNREACHABLE_MESSAGE = "License server unreachable. The plugin keeps working without a key.";
9294
- var EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
9295
- module.exports = ({ strapi: strapi2 }) => ({
9296
- async getStatus(ctx) {
9297
- try {
9298
- const licenseGuard = strapi2.plugin("magic-sessionmanager").service("license-guard");
9299
- const pluginStore = strapi2.store({ type: "plugin", name: "magic-sessionmanager" });
9300
- const licenseKey = await pluginStore.get({ key: "licenseKey" });
9301
- if (!licenseKey) {
9302
- return ctx.send({
9303
- success: true,
9304
- valid: true,
9305
- demo: false,
9306
- hasKey: false,
9307
- data: {
9308
- features: {
9309
- premium: true,
9310
- advanced: true,
9311
- enterprise: true,
9312
- custom: true
9313
- }
9314
- },
9315
- message: "Plugin is active. License key activation is optional."
9316
- });
9317
- }
9318
- const license = await licenseGuard.getLicenseByKey(licenseKey);
9319
- return ctx.send({
9320
- success: true,
9321
- valid: true,
9322
- demo: false,
9323
- hasKey: true,
9324
- data: {
9325
- licenseKey,
9326
- email: license?.email || null,
9327
- firstName: license?.firstName || null,
9328
- lastName: license?.lastName || null,
9329
- isActive: license?.isActive ?? true,
9330
- isExpired: license?.isExpired ?? false,
9331
- isOnline: license?.isOnline ?? false,
9332
- expiresAt: license?.expiresAt || null,
9333
- lastPingAt: license?.lastPingAt || null,
9334
- deviceName: license?.deviceName || null,
9335
- deviceId: license?.deviceId || null,
9336
- ipAddress: license?.ipAddress || null,
9337
- features: {
9338
- premium: true,
9339
- advanced: true,
9340
- enterprise: true,
9341
- custom: true
9342
- },
9343
- maxDevices: license?.maxDevices || 1,
9344
- currentDevices: license?.currentDevices || 0
9345
- }
9346
- });
9347
- } catch (error) {
9348
- strapi2.log.error(
9349
- "[magic-sessionmanager] Error getting license status:",
9350
- error?.name || "Error"
9351
- );
9352
- return sendServerError(ctx, 500, "Error getting license status");
9353
- }
9354
- },
9355
- async autoCreate(ctx) {
9356
- try {
9357
- const adminUser = ctx.state.user;
9358
- if (!adminUser) {
9359
- return ctx.unauthorized("No admin user logged in");
9360
- }
9361
- const licenseGuard = strapi2.plugin("magic-sessionmanager").service("license-guard");
9362
- const license = await licenseGuard.createLicense({
9363
- email: adminUser.email,
9364
- firstName: adminUser.firstname || "Admin",
9365
- lastName: adminUser.lastname || "User"
9366
- });
9367
- if (!license) {
9368
- return sendServerError(ctx, 503, PROVIDER_UNREACHABLE_MESSAGE);
9369
- }
9370
- await licenseGuard.storeLicenseKey(license.licenseKey);
9371
- return ctx.send({
9372
- success: true,
9373
- message: "License automatically created and stored",
9374
- data: license
9375
- });
9376
- } catch (error) {
9377
- strapi2.log.error(
9378
- "[magic-sessionmanager] Error auto-creating license:",
9379
- error?.name || "Error"
9380
- );
9381
- return sendServerError(ctx, 500, "Error creating license");
9382
- }
9383
- },
9384
- async createAndActivate(ctx) {
9385
- try {
9386
- const { email, firstName, lastName } = ctx.request.body || {};
9387
- if (![email, firstName, lastName].every((value) => typeof value === "string" && value.trim())) {
9388
- return ctx.badRequest("Email, firstName, and lastName are required");
9389
- }
9390
- const licenseGuard = strapi2.plugin("magic-sessionmanager").service("license-guard");
9391
- const license = await licenseGuard.createLicense({ email, firstName, lastName });
9392
- if (!license) {
9393
- return sendServerError(ctx, 503, PROVIDER_UNREACHABLE_MESSAGE);
9394
- }
9395
- await licenseGuard.storeLicenseKey(license.licenseKey);
9396
- return ctx.send({
9397
- success: true,
9398
- message: "License created and stored successfully",
9399
- data: license
9400
- });
9401
- } catch (error) {
9402
- strapi2.log.error("[magic-sessionmanager] Error creating license:", error?.name || "Error");
9403
- return sendServerError(ctx, 500, "Error creating license");
9404
- }
9405
- },
9406
- async ping(ctx) {
9407
- try {
9408
- const pluginStore = strapi2.store({ type: "plugin", name: "magic-sessionmanager" });
9409
- const licenseKey = await pluginStore.get({ key: "licenseKey" });
9410
- if (!licenseKey) {
9411
- return ctx.badRequest("No license key found");
9412
- }
9413
- const licenseGuard = strapi2.plugin("magic-sessionmanager").service("license-guard");
9414
- const verification = await licenseGuard.verifyLicense(licenseKey);
9415
- return ctx.send({
9416
- success: true,
9417
- message: verification.valid ? "License refreshed successfully" : "License key could not be verified, but the plugin keeps working.",
9418
- data: verification.data
9419
- });
9420
- } catch (error) {
9421
- strapi2.log.error("[magic-sessionmanager] Error refreshing license:", error?.name || "Error");
9422
- return sendServerError(ctx, 500, "Error refreshing license");
9423
- }
9424
- },
9425
- async storeKey(ctx) {
9426
- try {
9427
- const { licenseKey, email } = ctx.request.body || {};
9428
- if (typeof licenseKey !== "string" || !licenseKey.trim()) {
9429
- return ctx.badRequest("License key is required");
9430
- }
9431
- if (email !== void 0 && email !== null && email !== "") {
9432
- if (typeof email !== "string" || !EMAIL_PATTERN.test(email.trim())) {
9433
- return ctx.badRequest("Email must be a valid email address");
9434
- }
9435
- }
9436
- const trimmedKey = licenseKey.trim();
9437
- const trimmedEmail = typeof email === "string" && email.trim() ? email.trim().toLowerCase() : null;
9438
- const licenseGuard = strapi2.plugin("magic-sessionmanager").service("license-guard");
9439
- const verification = await licenseGuard.verifyLicense(trimmedKey);
9440
- if (!verification.valid && !verification.networkError) {
9441
- strapi2.log.warn("[magic-sessionmanager] Rejected an invalid license key");
9442
- return ctx.badRequest("Invalid or expired license key");
9443
- }
9444
- const license = verification.valid ? await licenseGuard.getLicenseByKey(trimmedKey) : null;
9445
- if (license?.email && trimmedEmail && license.email.toLowerCase() !== trimmedEmail) {
9446
- strapi2.log.warn("[magic-sessionmanager] Rejected a license holder email mismatch");
9447
- return ctx.badRequest("Email address does not match this license key");
9448
- }
9449
- await licenseGuard.storeLicenseKey(trimmedKey);
9450
- return ctx.send({
9451
- success: true,
9452
- message: verification.networkError ? "License key stored. The license server was unreachable, but the plugin keeps working." : "License key stored successfully",
9453
- data: verification.data || { licenseKey: trimmedKey, email: trimmedEmail }
9454
- });
9455
- } catch (error) {
9456
- strapi2.log.error("[magic-sessionmanager] Error storing license key:", error?.name || "Error");
9457
- return sendServerError(ctx, 500, "Error validating license key");
9458
- }
9459
- }
9460
- });
9461
- }
9462
- });
9463
-
9464
9263
  // scripts/geoip-updater.cjs
9465
9264
  var require_geoip_updater = __commonJS({
9466
9265
  "scripts/geoip-updater.cjs"(exports, module) {
@@ -10518,12 +10317,10 @@ var require_controllers = __commonJS({
10518
10317
  "server/src/controllers/index.js"(exports, module) {
10519
10318
  "use strict";
10520
10319
  var session = require_session();
10521
- var license = require_license();
10522
10320
  var settings = require_settings();
10523
10321
  var geoip = require_geoip();
10524
10322
  module.exports = {
10525
10323
  session,
10526
- license,
10527
10324
  settings,
10528
10325
  geoip
10529
10326
  };
@@ -11734,367 +11531,6 @@ var require_session2 = __commonJS({
11734
11531
  }
11735
11532
  });
11736
11533
 
11737
- // package.json
11738
- var require_package = __commonJS({
11739
- "package.json"(exports, module) {
11740
- module.exports = {
11741
- version: "4.10.0",
11742
- keywords: [
11743
- "strapi",
11744
- "plugin",
11745
- "strapi-plugin",
11746
- "strapi-v5",
11747
- "sessions",
11748
- "user-tracking",
11749
- "login-logout",
11750
- "activity-monitoring"
11751
- ],
11752
- type: "commonjs",
11753
- bin: {
11754
- "strapi-magic-sessionmanager-geoip": "./scripts/update-geoip-db.mjs"
11755
- },
11756
- exports: {
11757
- "./package.json": "./package.json",
11758
- "./strapi-admin": {
11759
- source: "./admin/src/index.js",
11760
- import: "./dist/admin/index.mjs",
11761
- require: "./dist/admin/index.js",
11762
- default: "./dist/admin/index.js"
11763
- },
11764
- "./strapi-server": {
11765
- source: "./server/src/index.js",
11766
- import: "./dist/server/index.mjs",
11767
- require: "./dist/server/index.js",
11768
- default: "./dist/server/index.js"
11769
- }
11770
- },
11771
- files: [
11772
- "dist",
11773
- "strapi-admin.js",
11774
- "strapi-server.js",
11775
- "scripts/geoip-updater.cjs",
11776
- "scripts/update-geoip-db.mjs",
11777
- "README.md",
11778
- "LICENSE",
11779
- "CHANGELOG.md",
11780
- "pics"
11781
- ],
11782
- engines: {
11783
- node: "^22.22.2 || >=24.15.0",
11784
- npm: ">=6.0.0"
11785
- },
11786
- scripts: {
11787
- clean: `node -e "require('fs').rmSync('dist', { recursive: true, force: true })"`,
11788
- test: "node --test tests/*.test.js tests/*.test.mjs",
11789
- "test:concurrency": "node scripts/concurrency/run.mjs",
11790
- "test:ts:front": "tsc --noEmit --allowJs --jsx react-jsx --moduleResolution bundler --module esnext -p admin/jsconfig.json",
11791
- "test:ts:back": "tsc --noEmit --allowJs --moduleResolution node --module commonjs -p server/jsconfig.json",
11792
- lint: "eslint .",
11793
- "lint:fix": "eslint . --fix",
11794
- format: "prettier --write .",
11795
- "format:check": "prettier --check .",
11796
- build: "npm run clean && strapi-plugin build && node scripts/build-server-bundle.mjs",
11797
- watch: "strapi-plugin watch",
11798
- "watch:link": "strapi-plugin watch:link",
11799
- "geoip:update": "node scripts/update-geoip-db.mjs",
11800
- verify: "strapi-plugin verify",
11801
- "verify:runtime": "node scripts/verify-server-bundle.mjs",
11802
- prepublishOnly: "npm test && npm run build && npm run verify && npm run verify:runtime"
11803
- },
11804
- dependencies: {
11805
- "@maxmind/geoip2-node": "^7.1.0",
11806
- "sanitize-html": "^2.18.0"
11807
- },
11808
- devDependencies: {
11809
- "@eslint/js": "^10.0.1",
11810
- "@semantic-release/changelog": "^7.0.0",
11811
- "@semantic-release/commit-analyzer": "^13.0.1",
11812
- "@semantic-release/git": "^11.0.1",
11813
- "@semantic-release/github": "^12.0.10",
11814
- "@semantic-release/npm": "^13.2.0",
11815
- "@semantic-release/release-notes-generator": "^14.1.1",
11816
- "@strapi/design-system": "^2.2.4",
11817
- "@strapi/icons": "^2.2.4",
11818
- "@strapi/sdk-plugin": "^6.1.1",
11819
- "@strapi/strapi": "5.61.0",
11820
- "better-sqlite3": "^13.0.3",
11821
- esbuild: "^0.28.2",
11822
- eslint: "^10.14.0",
11823
- "eslint-config-prettier": "^10.1.8",
11824
- "eslint-plugin-react-hooks": "^7.1.1",
11825
- globals: "^17.14.0",
11826
- pg: "^8.23.1",
11827
- prettier: "^3.9.10",
11828
- react: "^18.3.1",
11829
- "react-dom": "^18.3.1",
11830
- "react-intl": "^6.8.9",
11831
- "react-router-dom": "^6.30.6",
11832
- "semantic-release": "^25.0.9",
11833
- "styled-components": "^6.6.0"
11834
- },
11835
- peerDependencies: {
11836
- "@strapi/design-system": "^2.0.0",
11837
- "@strapi/icons": "^2.0.0",
11838
- "@strapi/strapi": "^5.0.0",
11839
- "@strapi/utils": "^5.0.0",
11840
- react: "^18.3.1",
11841
- "react-dom": "^18.3.1",
11842
- "react-intl": "^6.0.0",
11843
- "react-router-dom": "^6.0.0",
11844
- "styled-components": "^6.0.0"
11845
- },
11846
- publishConfig: {
11847
- access: "public"
11848
- },
11849
- strapi: {
11850
- kind: "plugin",
11851
- name: "magic-sessionmanager",
11852
- displayName: "Magic Sessionmanager",
11853
- description: "Advanced session management for Strapi v5 - Track user login/logout, session history, and online status"
11854
- },
11855
- name: "strapi-plugin-magic-sessionmanager",
11856
- description: "Advanced Session Management for Strapi v5 - Track user sessions with IP geolocation, security scoring, and real-time monitoring",
11857
- license: "MIT",
11858
- author: "Schero D.",
11859
- repository: {
11860
- type: "git",
11861
- url: "https://github.com/Schero94/Magic-Sessionmanager.git"
11862
- },
11863
- bugs: {
11864
- url: "https://github.com/Schero94/Magic-Sessionmanager/issues"
11865
- },
11866
- homepage: "https://github.com/Schero94/Magic-Sessionmanager#readme",
11867
- private: false
11868
- };
11869
- }
11870
- });
11871
-
11872
- // server/src/services/license-guard.js
11873
- var require_license_guard = __commonJS({
11874
- "server/src/services/license-guard.js"(exports, module) {
11875
- "use strict";
11876
- var crypto = __require("crypto");
11877
- var os = __require("os");
11878
- var pluginPkg = require_package();
11879
- var { createLogger } = require_logger();
11880
- var { setPluginStoreValue, withPluginStoreKey } = require_plugin_store();
11881
- var DEFAULT_LICENSE_SERVER_URL = "https://magicapi.fitlex.me";
11882
- var envTimeout = Number(process.env.MAGIC_LICENSE_TIMEOUT_MS);
11883
- var DEFAULT_FETCH_TIMEOUT_MS = Number.isFinite(envTimeout) && envTimeout > 0 ? envTimeout : 12e3;
11884
- var FETCH_RETRIES = 1;
11885
- var FETCH_RETRY_BACKOFF_MS = 750;
11886
- async function fetchWithTimeout(url, options = {}, timeoutMs = DEFAULT_FETCH_TIMEOUT_MS) {
11887
- let lastError;
11888
- for (let attempt = 0; attempt <= FETCH_RETRIES; attempt += 1) {
11889
- const controller = new AbortController();
11890
- const timer = setTimeout(() => controller.abort(), timeoutMs);
11891
- try {
11892
- return await fetch(url, { ...options, signal: controller.signal });
11893
- } catch (err) {
11894
- lastError = err;
11895
- if (attempt < FETCH_RETRIES) {
11896
- await new Promise((r) => setTimeout(r, FETCH_RETRY_BACKOFF_MS));
11897
- continue;
11898
- }
11899
- throw err;
11900
- } finally {
11901
- clearTimeout(timer);
11902
- }
11903
- }
11904
- throw lastError;
11905
- }
11906
- module.exports = ({ strapi: strapi2 }) => {
11907
- const log = createLogger(strapi2);
11908
- return {
11909
- getLicenseServerUrl() {
11910
- return process.env.MAGIC_LICENSE_SERVER_URL || DEFAULT_LICENSE_SERVER_URL;
11911
- },
11912
- async generateDeviceId() {
11913
- try {
11914
- return await withPluginStoreKey(strapi2, "deviceId", async (pluginStore) => {
11915
- const stored = await pluginStore.get({ key: "deviceId" });
11916
- if (stored && typeof stored === "string" && stored.length >= 16) {
11917
- return stored;
11918
- }
11919
- let identifier;
11920
- try {
11921
- const networkInterfaces = os.networkInterfaces();
11922
- const macAddresses = [];
11923
- Object.values(networkInterfaces).forEach((interfaces) => {
11924
- interfaces?.forEach((iface) => {
11925
- if (iface.mac && iface.mac !== "00:00:00:00:00:00") {
11926
- macAddresses.push(iface.mac);
11927
- }
11928
- });
11929
- });
11930
- identifier = `${macAddresses.join("-")}-${os.hostname()}`;
11931
- } catch {
11932
- identifier = `${Date.now()}-${crypto.randomBytes(16).toString("hex")}`;
11933
- }
11934
- const deviceId = crypto.createHash("sha256").update(identifier).digest("hex").substring(0, 32);
11935
- await pluginStore.set({ key: "deviceId", value: deviceId });
11936
- return deviceId;
11937
- });
11938
- } catch {
11939
- return crypto.randomBytes(16).toString("hex");
11940
- }
11941
- },
11942
- getDeviceName() {
11943
- try {
11944
- return os.hostname() || "Unknown Device";
11945
- } catch {
11946
- return "Unknown Device";
11947
- }
11948
- },
11949
- getIpAddress() {
11950
- try {
11951
- const networkInterfaces = os.networkInterfaces();
11952
- for (const name of Object.keys(networkInterfaces)) {
11953
- const interfaces = networkInterfaces[name];
11954
- if (!interfaces) continue;
11955
- for (const iface of interfaces) {
11956
- if (iface.family === "IPv4" && !iface.internal) {
11957
- return iface.address;
11958
- }
11959
- }
11960
- }
11961
- return "127.0.0.1";
11962
- } catch {
11963
- return "127.0.0.1";
11964
- }
11965
- },
11966
- getUserAgent() {
11967
- const pluginVersion = pluginPkg.version || "1.0.0";
11968
- const strapiVersion = strapi2.config.get("info.strapi") || "5.0.0";
11969
- return `MagicSessionManager/${pluginVersion} Strapi/${strapiVersion} Node/${process.version} ${os.platform()}/${os.release()}`;
11970
- },
11971
- async createLicense({ email, firstName, lastName }) {
11972
- try {
11973
- const response = await fetchWithTimeout(
11974
- `${this.getLicenseServerUrl()}/api/licenses/create`,
11975
- {
11976
- method: "POST",
11977
- headers: { "Content-Type": "application/json" },
11978
- body: JSON.stringify({
11979
- email,
11980
- firstName,
11981
- lastName,
11982
- deviceName: this.getDeviceName(),
11983
- deviceId: await this.generateDeviceId(),
11984
- ipAddress: this.getIpAddress(),
11985
- userAgent: this.getUserAgent(),
11986
- pluginName: "magic-sessionmanager",
11987
- productName: "Magic Session Manager"
11988
- })
11989
- }
11990
- );
11991
- const data = await response.json();
11992
- if (data.success) {
11993
- log.info("[SUCCESS] License created");
11994
- return data.data;
11995
- }
11996
- log.warn("[WARNING] License creation rejected by server");
11997
- return null;
11998
- } catch (error) {
11999
- log.warn("[WARNING] Error creating license:", error?.name || "Error");
12000
- return null;
12001
- }
12002
- },
12003
- async verifyLicense(licenseKey) {
12004
- try {
12005
- const response = await fetchWithTimeout(
12006
- `${this.getLicenseServerUrl()}/api/licenses/verify`,
12007
- {
12008
- method: "POST",
12009
- headers: { "Content-Type": "application/json" },
12010
- body: JSON.stringify({
12011
- licenseKey,
12012
- pluginName: "magic-sessionmanager",
12013
- productName: "Magic Session Manager"
12014
- })
12015
- }
12016
- );
12017
- const data = await response.json();
12018
- if (data.success && data.data) {
12019
- await setPluginStoreValue(strapi2, "lastValidated", (/* @__PURE__ */ new Date()).toISOString());
12020
- return { valid: true, data: data.data };
12021
- }
12022
- return { valid: false, data: null };
12023
- } catch (error) {
12024
- log.warn(
12025
- `[WARNING] License server unreachable during optional activation (${error?.name || "Error"}). This does not block the plugin.`
12026
- );
12027
- return { valid: false, data: null, networkError: true };
12028
- }
12029
- },
12030
- async getLicenseByKey(licenseKey) {
12031
- try {
12032
- const encodedKey = encodeURIComponent(licenseKey);
12033
- const response = await fetchWithTimeout(
12034
- `${this.getLicenseServerUrl()}/api/licenses/key/${encodedKey}`,
12035
- {
12036
- method: "GET",
12037
- headers: { "Content-Type": "application/json" }
12038
- }
12039
- );
12040
- const data = await response.json();
12041
- if (data.success && data.data) return data.data;
12042
- return null;
12043
- } catch (error) {
12044
- log.warn("[WARNING] Could not fetch license by key:", error?.name || "Error");
12045
- return null;
12046
- }
12047
- },
12048
- async pingLicense() {
12049
- return null;
12050
- },
12051
- async storeLicenseKey(licenseKey) {
12052
- await setPluginStoreValue(strapi2, "licenseKey", licenseKey);
12053
- await setPluginStoreValue(strapi2, "lastValidated", (/* @__PURE__ */ new Date()).toISOString());
12054
- log.info("[SUCCESS] License key stored");
12055
- return true;
12056
- },
12057
- startPinging() {
12058
- return null;
12059
- },
12060
- async initialize() {
12061
- return { valid: true, demo: false, data: null };
12062
- },
12063
- cleanup() {
12064
- },
12065
- async hasFeature() {
12066
- return true;
12067
- },
12068
- async getMaxSessions() {
12069
- return -1;
12070
- },
12071
- async getLicenseTierInfo() {
12072
- try {
12073
- const pluginStore = strapi2.store({ type: "plugin", name: "magic-sessionmanager" });
12074
- const licenseKey = await pluginStore.get({ key: "licenseKey" });
12075
- const hasKey = !!licenseKey;
12076
- return {
12077
- tier: hasKey ? "pro" : "free",
12078
- hasKey,
12079
- features: {
12080
- premium: true,
12081
- advanced: true,
12082
- enterprise: true
12083
- }
12084
- };
12085
- } catch {
12086
- return {
12087
- tier: "free",
12088
- hasKey: false,
12089
- features: { premium: true, advanced: true, enterprise: true }
12090
- };
12091
- }
12092
- }
12093
- };
12094
- };
12095
- }
12096
- });
12097
-
12098
11534
  // server/src/services/geolocation.js
12099
11535
  var require_geolocation = __commonJS({
12100
11536
  "server/src/services/geolocation.js"(exports, module) {
@@ -13247,12 +12683,10 @@ var require_services = __commonJS({
13247
12683
  "server/src/services/index.js"(exports, module) {
13248
12684
  "use strict";
13249
12685
  var session = require_session2();
13250
- var licenseGuard = require_license_guard();
13251
12686
  var geolocation = require_geolocation();
13252
12687
  var notifications = require_notifications();
13253
12688
  module.exports = {
13254
12689
  session,
13255
- "license-guard": licenseGuard,
13256
12690
  geolocation,
13257
12691
  notifications
13258
12692
  };