@kirby-tools/licensing 0.6.1 → 0.6.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/constants.js CHANGED
@@ -1,5 +1,13 @@
1
1
  //#region src/constants.ts
2
- const TRANSLATIONS = {
2
+ const ERROR_KEY_MAP = {
3
+ "Unauthorized": "errors.validation.invalidCredentials",
4
+ "License key not valid for this plugin": "errors.license.invalidPlugin",
5
+ "License key not valid for this plugin version": "errors.license.versionMismatch",
6
+ "License key not valid for this plugin version, please upgrade your license": "errors.license.needsUpgrade",
7
+ "License key already activated": "errors.activation.alreadyUsed"
8
+ };
9
+ const INTEGRITY_ERROR = "The activation buttons appear to be hidden. Please purchase a license.";
10
+ const I18N_MESSAGES = {
3
11
  en: {
4
12
  "modal.fields.info": "Thanks for purchasing {label}! Please enter your email address and order ID to activate your license.",
5
13
  "modal.fields.orderId.help": "<a href=\"https://app.lemonsqueezy.com/my-orders\" target=\"_blank\">Find your order number</a> on Lemon Squeezy or <a href=\"mailto:hello@kirby.tools\">contact us</a> if you cannot find it.",
@@ -47,9 +55,9 @@ const TRANSLATIONS = {
47
55
  "modal.fields.orderId.help": "<a href=\"https://app.lemonsqueezy.com/my-orders\" target=\"_blank\">Vind je bestelnummer</a> op Lemon Squeezy of <a href=\"mailto:hello@kirby.tools\">neem contact met ons op</a> als je het niet kunt vinden.",
48
56
  "errors.validation.missingFields": "E-mailadres en bestelnummer zijn verplicht",
49
57
  "errors.validation.invalidCredentials": "E-mailadres of bestelnummer is onjuist",
50
- "errors.license.invalidPlugin": "Licentiesleutel ongeldig voor dit plug-in",
51
- "errors.license.versionMismatch": "Licentiesleutel ongeldig voor deze plug-inversie",
52
- "errors.license.needsUpgrade": "Licentiesleutel ongeldig voor deze plug-inversie. Upgrade nu op https://hub.kirby.tools.",
58
+ "errors.license.invalidPlugin": "Licentiesleutel ongeldig voor deze plugin",
59
+ "errors.license.versionMismatch": "Licentiesleutel ongeldig voor deze pluginversie",
60
+ "errors.license.needsUpgrade": "Licentiesleutel ongeldig voor deze pluginversie. Upgrade nu op https://hub.kirby.tools.",
53
61
  "errors.activation.alreadyUsed": "Licentiesleutel al geactiveerd",
54
62
  "activate": "Activeren",
55
63
  "activated": "Plugin geactiveerd",
@@ -59,4 +67,4 @@ const TRANSLATIONS = {
59
67
  };
60
68
 
61
69
  //#endregion
62
- export { TRANSLATIONS };
70
+ export { ERROR_KEY_MAP, I18N_MESSAGES, INTEGRITY_ERROR };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { License, LicenseKey, LicenseStatus } from "./types.js";
2
2
  import { LicenseModalResult, LicenseOptions, useLicense } from "./license.js";
3
- import { isLocal } from "./utils.js";
4
- export { type License, type LicenseKey, LicenseModalResult, LicenseOptions, type LicenseStatus, isLocal, useLicense };
3
+ import { isLocalHost } from "./utils.js";
4
+ export { type License, type LicenseKey, LicenseModalResult, LicenseOptions, type LicenseStatus, isLocalHost, useLicense };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { isLocal } from "./utils.js";
1
+ import { isLocalHost } from "./utils.js";
2
2
  import { useLicense } from "./license.js";
3
3
 
4
- export { isLocal, useLicense };
4
+ export { isLocalHost, useLicense };
package/dist/license.js CHANGED
@@ -1,19 +1,12 @@
1
- import { isLocal, t } from "./utils.js";
1
+ import { ERROR_KEY_MAP, INTEGRITY_ERROR } from "./constants.js";
2
+ import { isLocalHost, t } from "./utils.js";
2
3
  import { unref, useDialog, usePanel } from "kirbyuse";
3
4
 
4
5
  //#region src/license.ts
5
- const ERROR_MESSAGE_TRANSLATIONS = {
6
- "Unauthorized": "errors.validation.invalidCredentials",
7
- "License key not valid for this plugin": "errors.license.invalidPlugin",
8
- "License key not valid for this plugin version": "errors.license.versionMismatch",
9
- "License key not valid for this plugin version, please upgrade your license": "errors.license.needsUpgrade",
10
- "License key already activated": "errors.activation.alreadyUsed"
11
- };
12
- const INTEGRITY_ERROR = "The activation buttons appear to be hidden. Please purchase a license.";
13
6
  function useLicense(licenseOptions) {
14
7
  const panel = usePanel();
15
8
  const { openFieldsDialog } = useDialog();
16
- const isLocalhost = isLocal();
9
+ const isLocalhost = isLocalHost();
17
10
  const openLicenseModal = async () => {
18
11
  const { label } = licenseOptions;
19
12
  return { isLicenseActive: (await openFieldsDialog({
@@ -75,7 +68,7 @@ async function activateLicense(event, licenseOptions) {
75
68
  return true;
76
69
  } catch (error) {
77
70
  const message = error.message;
78
- panel.notification.error(ERROR_MESSAGE_TRANSLATIONS[message] ? t(ERROR_MESSAGE_TRANSLATIONS[message]) : message);
71
+ panel.notification.error(ERROR_KEY_MAP[message] ? t(ERROR_KEY_MAP[message]) : message);
79
72
  return false;
80
73
  }
81
74
  }
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region src/utils.d.ts
2
2
 
3
- declare function isLocal(): boolean;
3
+ declare function isLocalHost(): boolean;
4
4
  //#endregion
5
- export { isLocal };
5
+ export { isLocalHost };
package/dist/utils.js CHANGED
@@ -1,30 +1,35 @@
1
- import { TRANSLATIONS } from "./constants.js";
1
+ import { I18N_MESSAGES } from "./constants.js";
2
2
 
3
3
  //#region src/utils.ts
4
4
  const LOCALHOST_HOSTNAMES = [
5
5
  "localhost",
6
6
  "127.0.0.1",
7
- "[::1]"
7
+ "[::1]",
8
+ "0.0.0.0"
8
9
  ];
9
- const LOCAL_DOMAINS = [
10
+ const LOCAL_TLD_SUFFIXES = [
11
+ "localhost",
10
12
  "local",
11
13
  "test",
12
- "ddev.site"
14
+ "ddev.site",
15
+ "lndo.site",
16
+ "nitro",
17
+ "dev.cc"
13
18
  ];
14
19
  function template(input, values, fallback) {
15
20
  return input.replace(/\{(\w+)\}/g, (_, key) => values[key] || ((typeof fallback === "function" ? fallback(key) : fallback) ?? key));
16
21
  }
17
- function t(key = "", data) {
22
+ function t(key, data) {
18
23
  const languageCode = window.panel.translation.code;
19
- const translation = TRANSLATIONS?.[languageCode]?.[key] ?? key;
24
+ const translation = I18N_MESSAGES?.[languageCode]?.[key] ?? key;
20
25
  return data ? template(translation, data) : translation;
21
26
  }
22
- function isLocal() {
27
+ function isLocalHost() {
23
28
  const { hostname } = window.location;
24
- const isLocalhost = LOCALHOST_HOSTNAMES.includes(hostname);
25
- const isLocalDomain = LOCAL_DOMAINS.some((domain) => hostname.endsWith(`.${domain}`));
26
- return isLocalhost || isLocalDomain;
29
+ const isLocalHostname = LOCALHOST_HOSTNAMES.includes(hostname);
30
+ const isLocalTld = LOCAL_TLD_SUFFIXES.some((suffix) => hostname.endsWith(`.${suffix}`));
31
+ return isLocalHostname || isLocalTld;
27
32
  }
28
33
 
29
34
  //#endregion
30
- export { isLocal, t };
35
+ export { isLocalHost, t };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kirby-tools/licensing",
3
3
  "type": "module",
4
- "version": "0.6.1",
4
+ "version": "0.6.2",
5
5
  "packageManager": "pnpm@10.28.0",
6
6
  "description": "License system for Kirby Tools plugins within the Kirby Panel",
7
7
  "author": "Johann Schopplich <hello@johannschopplich.com>",
@@ -33,6 +33,7 @@
33
33
  "build": "tsdown",
34
34
  "lint": "eslint .",
35
35
  "lint:fix": "eslint . --fix",
36
+ "test:types": "tsc --noEmit",
36
37
  "release": "bumpp"
37
38
  },
38
39
  "peerDependencies": {