@kirby-tools/licensing 0.6.1 → 0.6.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/components/LicensingButtonGroup.vue +1 -6
- package/dist/components/LicensingDropdownItems.vue +1 -6
- package/dist/constants.js +13 -5
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/license.js +6 -11
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +16 -11
- package/package.json +2 -1
|
@@ -40,12 +40,7 @@ onMounted(() => {
|
|
|
40
40
|
})
|
|
41
41
|
|
|
42
42
|
async function handleRegistration() {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (isLicenseActive) {
|
|
46
|
-
// Force a reload to refresh the plugin's cached context
|
|
47
|
-
window.location.reload()
|
|
48
|
-
}
|
|
43
|
+
await openLicenseModal()
|
|
49
44
|
}
|
|
50
45
|
</script>
|
|
51
46
|
|
|
@@ -32,12 +32,7 @@ const { openLicenseModal } = useLicense({
|
|
|
32
32
|
const currentLicenseStatus = ref(props.licenseStatus)
|
|
33
33
|
|
|
34
34
|
async function handleRegistration() {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (isLicenseActive) {
|
|
38
|
-
// Force a reload to refresh the plugin's cached context
|
|
39
|
-
window.location.reload()
|
|
40
|
-
}
|
|
35
|
+
await openLicenseModal()
|
|
41
36
|
}
|
|
42
37
|
</script>
|
|
43
38
|
|
package/dist/constants.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
//#region src/constants.ts
|
|
2
|
-
const
|
|
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
|
|
51
|
-
"errors.license.versionMismatch": "Licentiesleutel ongeldig voor deze
|
|
52
|
-
"errors.license.needsUpgrade": "Licentiesleutel ongeldig voor deze
|
|
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 {
|
|
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 {
|
|
4
|
-
export { type License, type LicenseKey, LicenseModalResult, LicenseOptions, type LicenseStatus,
|
|
3
|
+
import { isLocalHost } from "./utils.js";
|
|
4
|
+
export { type License, type LicenseKey, LicenseModalResult, LicenseOptions, type LicenseStatus, isLocalHost, useLicense };
|
package/dist/index.js
CHANGED
package/dist/license.js
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
import {
|
|
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 =
|
|
9
|
+
const isLocalhost = isLocalHost();
|
|
17
10
|
const openLicenseModal = async () => {
|
|
18
11
|
const { label } = licenseOptions;
|
|
19
12
|
return { isLicenseActive: (await openFieldsDialog({
|
|
@@ -41,6 +34,8 @@ function useLicense(licenseOptions) {
|
|
|
41
34
|
const isLicenseActive = await activateLicense(value, licenseOptions);
|
|
42
35
|
if (!isLicenseActive) return false;
|
|
43
36
|
panel.notification.success(t("activated"));
|
|
37
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
38
|
+
window.location.reload();
|
|
44
39
|
return { isLicenseActive };
|
|
45
40
|
}
|
|
46
41
|
}))?.isLicenseActive ?? false };
|
|
@@ -75,7 +70,7 @@ async function activateLicense(event, licenseOptions) {
|
|
|
75
70
|
return true;
|
|
76
71
|
} catch (error) {
|
|
77
72
|
const message = error.message;
|
|
78
|
-
panel.notification.error(
|
|
73
|
+
panel.notification.error(ERROR_KEY_MAP[message] ? t(ERROR_KEY_MAP[message]) : message);
|
|
79
74
|
return false;
|
|
80
75
|
}
|
|
81
76
|
}
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
|
@@ -1,30 +1,35 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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
|
|
22
|
+
function t(key, data) {
|
|
18
23
|
const languageCode = window.panel.translation.code;
|
|
19
|
-
const translation =
|
|
24
|
+
const translation = I18N_MESSAGES?.[languageCode]?.[key] ?? key;
|
|
20
25
|
return data ? template(translation, data) : translation;
|
|
21
26
|
}
|
|
22
|
-
function
|
|
27
|
+
function isLocalHost() {
|
|
23
28
|
const { hostname } = window.location;
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
return
|
|
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 {
|
|
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.
|
|
4
|
+
"version": "0.6.3",
|
|
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": {
|