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