@kirby-tools/licensing 0.5.2 → 0.6.1
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/README.md +22 -1
- package/dist/components/index.d.ts +2 -2
- package/dist/constants.js +62 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -0
- package/dist/license.d.ts +23 -14
- package/dist/license.js +84 -0
- package/dist/types.d.ts +12 -8
- package/dist/utils.d.ts +5 -3
- package/dist/utils.js +30 -0
- package/package.json +13 -12
- package/dist/constants.d.ts +0 -4
- package/dist/constants.mjs +0 -58
- package/dist/index.mjs +0 -1
- package/dist/license.mjs +0 -94
- package/dist/types.mjs +0 -0
- package/dist/utils.mjs +0 -20
- /package/dist/components/{index.mjs → index.js} +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
# @kirby-tools/licensing
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Internal shared library for managing licensing and activation of commercial Kirby Tools plugins within the Kirby Panel.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides a unified licensing system for all commercial Kirby Tools plugins, handling:
|
|
8
|
+
|
|
9
|
+
- **License activation**: Modal dialogs for entering email and order ID
|
|
10
|
+
- **License validation**: Checking license status (active, inactive, invalid, incompatible, upgradeable)
|
|
11
|
+
- **UI components**: Pre-built Vue components for license buttons and dropdown items
|
|
12
|
+
- **Multi-language support**: Translations for English, German, French, and Dutch
|
|
13
|
+
- **Local development**: Automatic detection of local environments to bypass licensing
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { useLicense } from '@kirby-tools/licensing'
|
|
19
|
+
|
|
20
|
+
const { openLicenseModal, assertActivationIntegrity } = useLicense({
|
|
21
|
+
label: 'Plugin Name',
|
|
22
|
+
apiNamespace: 'plugin-namespace'
|
|
23
|
+
})
|
|
24
|
+
```
|
|
4
25
|
|
|
5
26
|
## License
|
|
6
27
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default as LicensingButtonGroup } from
|
|
2
|
-
export { default as LicensingDropdownItems } from
|
|
1
|
+
export { default as LicensingButtonGroup } from "./LicensingButtonGroup.vue";
|
|
2
|
+
export { default as LicensingDropdownItems } from "./LicensingDropdownItems.vue";
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
//#region src/constants.ts
|
|
2
|
+
const TRANSLATIONS = {
|
|
3
|
+
en: {
|
|
4
|
+
"modal.fields.info": "Thanks for purchasing {label}! Please enter your email address and order ID to activate your license.",
|
|
5
|
+
"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.",
|
|
6
|
+
"errors.validation.missingFields": "Email address and order ID are required",
|
|
7
|
+
"errors.validation.invalidCredentials": "Email address or order ID is incorrect",
|
|
8
|
+
"errors.license.invalidPlugin": "License key invalid for this plugin",
|
|
9
|
+
"errors.license.versionMismatch": "License key invalid for this plugin version",
|
|
10
|
+
"errors.license.needsUpgrade": "License key invalid for this plugin version. Upgrade now on https://hub.kirby.tools.",
|
|
11
|
+
"errors.activation.alreadyUsed": "License key already activated",
|
|
12
|
+
"activate": "Activate",
|
|
13
|
+
"activated": "Plugin activated",
|
|
14
|
+
"buy": "Buy a license",
|
|
15
|
+
"upgrade": "Upgrade"
|
|
16
|
+
},
|
|
17
|
+
de: {
|
|
18
|
+
"modal.fields.info": "Dankeschön für den Kauf von {label}! Bitte gib deine E-Mail-Adresse und Bestellnummer ein, um deine Lizenz zu aktivieren.",
|
|
19
|
+
"modal.fields.orderId.help": "<a href=\"https://app.lemonsqueezy.com/my-orders\" target=\"_blank\">Finde deine Bestellnummer</a> bei Lemon Squeezy oder <a href=\"mailto:hello@kirby.tools\">kontaktiere uns</a>, wenn du sie nicht finden kannst.",
|
|
20
|
+
"errors.validation.missingFields": "E-Mail-Adresse und Bestellnummer sind notwendig",
|
|
21
|
+
"errors.validation.invalidCredentials": "E-Mail-Adresse oder Bestellnummer ist falsch",
|
|
22
|
+
"errors.license.invalidPlugin": "Lizenzschlüssel ungültig für dieses Plugin",
|
|
23
|
+
"errors.license.versionMismatch": "Lizenzschlüssel ungültig für diese Plugin-Version",
|
|
24
|
+
"errors.license.needsUpgrade": "Lizenzschlüssel ungültig für diese Plugin-Version. Aktualisiere jetzt auf https://hub.kirby.tools.",
|
|
25
|
+
"errors.activation.alreadyUsed": "Lizenzschlüssel bereits aktiviert",
|
|
26
|
+
"activate": "Aktivieren",
|
|
27
|
+
"activated": "Plugin aktiviert",
|
|
28
|
+
"buy": "Lizenz kaufen",
|
|
29
|
+
"upgrade": "Upgrade"
|
|
30
|
+
},
|
|
31
|
+
fr: {
|
|
32
|
+
"modal.fields.info": "Merci d'avoir acheté {label} ! Veuillez saisir votre adresse e-mail et votre numéro de commande pour activer votre licence.",
|
|
33
|
+
"modal.fields.orderId.help": "<a href=\"https://app.lemonsqueezy.com/my-orders\" target=\"_blank\">Trouvez votre numéro de commande</a> sur Lemon Squeezy ou <a href=\"mailto:hello@kirby.tools\">contactez-nous</a> si vous ne le trouvez pas.",
|
|
34
|
+
"errors.validation.missingFields": "Adresse e-mail et numéro de commande requis",
|
|
35
|
+
"errors.validation.invalidCredentials": "Adresse e-mail ou numéro de commande incorrect",
|
|
36
|
+
"errors.license.invalidPlugin": "Clé de licence invalide pour ce plugin",
|
|
37
|
+
"errors.license.versionMismatch": "Clé de licence invalide pour cette version du plugin",
|
|
38
|
+
"errors.license.needsUpgrade": "Clé de licence invalide pour cette version du plugin. Mettez à niveau maintenant sur https://hub.kirby.tools.",
|
|
39
|
+
"errors.activation.alreadyUsed": "Clé de licence déjà activée",
|
|
40
|
+
"activate": "Activer",
|
|
41
|
+
"activated": "Plugin activé",
|
|
42
|
+
"buy": "Acheter une licence",
|
|
43
|
+
"upgrade": "Upgrade"
|
|
44
|
+
},
|
|
45
|
+
nl: {
|
|
46
|
+
"modal.fields.info": "Bedankt voor het kopen van {label}! Voer je e-mailadres en bestelnummer in om je licentie te activeren.",
|
|
47
|
+
"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
|
+
"errors.validation.missingFields": "E-mailadres en bestelnummer zijn verplicht",
|
|
49
|
+
"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.",
|
|
53
|
+
"errors.activation.alreadyUsed": "Licentiesleutel al geactiveerd",
|
|
54
|
+
"activate": "Activeren",
|
|
55
|
+
"activated": "Plugin geactiveerd",
|
|
56
|
+
"buy": "Koop een licentie",
|
|
57
|
+
"upgrade": "Upgrade"
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
export { TRANSLATIONS };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { License, LicenseKey, LicenseStatus } from "./types.js";
|
|
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 };
|
package/dist/index.js
ADDED
package/dist/license.d.ts
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { LicenseStatus, MaybeRef } from "./types.js";
|
|
2
|
+
import { ComponentPublicInstance } from "vue";
|
|
3
|
+
|
|
4
|
+
//#region src/license.d.ts
|
|
5
|
+
interface LicenseOptions {
|
|
6
|
+
label: string;
|
|
7
|
+
apiNamespace: string;
|
|
6
8
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
interface LicenseModalResult {
|
|
10
|
+
isLicenseActive: boolean;
|
|
9
11
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
declare function useLicense(licenseOptions: LicenseOptions): {
|
|
13
|
+
isLocalhost: boolean;
|
|
14
|
+
assertActivationIntegrity: ({
|
|
15
|
+
component,
|
|
16
|
+
licenseStatus
|
|
17
|
+
}: {
|
|
18
|
+
component: MaybeRef<ComponentPublicInstance | null | undefined>;
|
|
19
|
+
licenseStatus: MaybeRef<LicenseStatus>;
|
|
20
|
+
}) => void;
|
|
21
|
+
openLicenseModal: () => Promise<{
|
|
22
|
+
isLicenseActive: boolean;
|
|
23
|
+
}>;
|
|
17
24
|
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { LicenseModalResult, LicenseOptions, useLicense };
|
package/dist/license.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { isLocal, t } from "./utils.js";
|
|
2
|
+
import { unref, useDialog, usePanel } from "kirbyuse";
|
|
3
|
+
|
|
4
|
+
//#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
|
+
function useLicense(licenseOptions) {
|
|
14
|
+
const panel = usePanel();
|
|
15
|
+
const { openFieldsDialog } = useDialog();
|
|
16
|
+
const isLocalhost = isLocal();
|
|
17
|
+
const openLicenseModal = async () => {
|
|
18
|
+
const { label } = licenseOptions;
|
|
19
|
+
return { isLicenseActive: (await openFieldsDialog({
|
|
20
|
+
submitButton: {
|
|
21
|
+
icon: "check",
|
|
22
|
+
theme: "love",
|
|
23
|
+
text: t("activate", { label })
|
|
24
|
+
},
|
|
25
|
+
fields: {
|
|
26
|
+
info: {
|
|
27
|
+
type: "info",
|
|
28
|
+
text: t("modal.fields.info", { label })
|
|
29
|
+
},
|
|
30
|
+
email: {
|
|
31
|
+
label: panel.t("email"),
|
|
32
|
+
type: "email"
|
|
33
|
+
},
|
|
34
|
+
orderId: {
|
|
35
|
+
label: "Order ID",
|
|
36
|
+
type: "text",
|
|
37
|
+
help: t("modal.fields.orderId.help", { label })
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
onSubmit: async (value) => {
|
|
41
|
+
const isLicenseActive = await activateLicense(value, licenseOptions);
|
|
42
|
+
if (!isLicenseActive) return false;
|
|
43
|
+
panel.notification.success(t("activated"));
|
|
44
|
+
return { isLicenseActive };
|
|
45
|
+
}
|
|
46
|
+
}))?.isLicenseActive ?? false };
|
|
47
|
+
};
|
|
48
|
+
const assertActivationIntegrity = ({ component, licenseStatus }) => {
|
|
49
|
+
if (unref(licenseStatus) === "active") return;
|
|
50
|
+
const element = unref(component)?.$el;
|
|
51
|
+
if (!element) throw new Error(INTEGRITY_ERROR);
|
|
52
|
+
const style = window.getComputedStyle(element);
|
|
53
|
+
if (style.display === "none" || style.visibility === "hidden" || style.opacity === "0" || style.clipPath === "inset(100%)" || style.transform.includes("scale(0")) throw new Error(INTEGRITY_ERROR);
|
|
54
|
+
const rect = element.getBoundingClientRect();
|
|
55
|
+
if (rect.width === 0 || rect.height === 0 || rect.right < 0 || rect.bottom < 0 || rect.left > window.innerWidth || rect.top > window.innerHeight) throw new Error(INTEGRITY_ERROR);
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
isLocalhost,
|
|
59
|
+
assertActivationIntegrity,
|
|
60
|
+
openLicenseModal
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
async function activateLicense(event, licenseOptions) {
|
|
64
|
+
const panel = usePanel();
|
|
65
|
+
const { email, orderId } = event;
|
|
66
|
+
if (!email || !orderId) {
|
|
67
|
+
panel.notification.error(t("errors.validation.missingFields"));
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
if ((await panel.api.post(`${licenseOptions.apiNamespace}/activate`, {
|
|
72
|
+
email,
|
|
73
|
+
orderId: Number(orderId)
|
|
74
|
+
}))?.status !== "ok") throw new Error("Failed to activate license key");
|
|
75
|
+
return true;
|
|
76
|
+
} catch (error) {
|
|
77
|
+
const message = error.message;
|
|
78
|
+
panel.notification.error(ERROR_MESSAGE_TRANSLATIONS[message] ? t(ERROR_MESSAGE_TRANSLATIONS[message]) : message);
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
//#endregion
|
|
84
|
+
export { useLicense };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { Ref } from "vue";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
type MaybeRef<T = any> = T | Ref<T>;
|
|
5
|
+
type LicenseKey = string;
|
|
6
|
+
type LicenseStatus = 'active' | 'inactive' | 'invalid' | 'incompatible' | 'upgradeable';
|
|
7
|
+
interface License {
|
|
8
|
+
key: LicenseKey;
|
|
9
|
+
version: number;
|
|
10
|
+
compatibility: string;
|
|
9
11
|
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { License, LicenseKey, LicenseStatus, MaybeRef };
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//#region src/utils.d.ts
|
|
2
|
+
|
|
3
|
+
declare function isLocal(): boolean;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { isLocal };
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { TRANSLATIONS } from "./constants.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils.ts
|
|
4
|
+
const LOCALHOST_HOSTNAMES = [
|
|
5
|
+
"localhost",
|
|
6
|
+
"127.0.0.1",
|
|
7
|
+
"[::1]"
|
|
8
|
+
];
|
|
9
|
+
const LOCAL_DOMAINS = [
|
|
10
|
+
"local",
|
|
11
|
+
"test",
|
|
12
|
+
"ddev.site"
|
|
13
|
+
];
|
|
14
|
+
function template(input, values, fallback) {
|
|
15
|
+
return input.replace(/\{(\w+)\}/g, (_, key) => values[key] || ((typeof fallback === "function" ? fallback(key) : fallback) ?? key));
|
|
16
|
+
}
|
|
17
|
+
function t(key = "", data) {
|
|
18
|
+
const languageCode = window.panel.translation.code;
|
|
19
|
+
const translation = TRANSLATIONS?.[languageCode]?.[key] ?? key;
|
|
20
|
+
return data ? template(translation, data) : translation;
|
|
21
|
+
}
|
|
22
|
+
function isLocal() {
|
|
23
|
+
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;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { isLocal, t };
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kirby-tools/licensing",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"packageManager": "pnpm@
|
|
6
|
-
"description": "
|
|
4
|
+
"version": "0.6.1",
|
|
5
|
+
"packageManager": "pnpm@10.28.0",
|
|
6
|
+
"description": "License system for Kirby Tools plugins within the Kirby Panel",
|
|
7
7
|
"author": "Johann Schopplich <hello@johannschopplich.com>",
|
|
8
8
|
"license": "AGPL-3.0-or-later",
|
|
9
9
|
"homepage": "https://github.com/kirby-tools/licensing-panel#readme",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
20
|
"types": "./dist/index.d.ts",
|
|
21
|
-
"default": "./dist/index.
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
22
|
},
|
|
23
23
|
"./components": {
|
|
24
24
|
"types": "./dist/components/index.d.ts",
|
|
25
|
-
"import": "./dist/components/index.
|
|
25
|
+
"import": "./dist/components/index.js"
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"types": "./dist/index.d.ts",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"scripts": {
|
|
33
|
-
"build": "
|
|
33
|
+
"build": "tsdown",
|
|
34
34
|
"lint": "eslint .",
|
|
35
35
|
"lint:fix": "eslint . --fix",
|
|
36
36
|
"release": "bumpp"
|
|
@@ -42,11 +42,12 @@
|
|
|
42
42
|
"vue": "^2.7.16"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@antfu/eslint-config": "^
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
45
|
+
"@antfu/eslint-config": "^7.0.1",
|
|
46
|
+
"@types/node": "^25.0.9",
|
|
47
|
+
"bumpp": "^10.4.0",
|
|
48
|
+
"eslint": "^9.39.2",
|
|
49
|
+
"kirbyuse": "^1.2.12",
|
|
50
|
+
"tsdown": "^0.19.0",
|
|
51
|
+
"typescript": "^5.9.3"
|
|
51
52
|
}
|
|
52
53
|
}
|
package/dist/constants.d.ts
DELETED
package/dist/constants.mjs
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
export const TRANSLATIONS = {
|
|
2
|
-
en: {
|
|
3
|
-
"modal.info": "Thanks for purchasing {label}! Please enter your email address and order ID to activate your license.",
|
|
4
|
-
"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.',
|
|
5
|
-
"modal.error.required.fields": "Email address and order ID are required",
|
|
6
|
-
"modal.error.invalid.unauthorized": "Email address or order ID is incorrect",
|
|
7
|
-
"modal.error.invalid.licenseKey": "License key invalid for this plugin",
|
|
8
|
-
"modal.error.incompatible": "License key invalid for this plugin version",
|
|
9
|
-
"modal.error.upgradeable": "License key invalid for this plugin version. Upgrade now on https://hub.kirby.tools.",
|
|
10
|
-
"modal.error.activated": "License key already activated",
|
|
11
|
-
"activate": "Activate",
|
|
12
|
-
"activated": "Plugin activated",
|
|
13
|
-
"buy": "Buy a license",
|
|
14
|
-
"upgrade": "Upgrade"
|
|
15
|
-
},
|
|
16
|
-
de: {
|
|
17
|
-
"modal.info": "Dankesch\xF6n f\xFCr den Kauf von {label}! Bitte gib deine E-Mail-Adresse und Bestellnummer ein, um deine Lizenz zu aktivieren.",
|
|
18
|
-
"modal.fields.orderId.help": '<a href="https://app.lemonsqueezy.com/my-orders" target="_blank">Finde deine Bestellnummer</a> bei Lemon Squeezy oder <a href="mailto:hello@kirby.tools">kontaktiere uns</a>, wenn du sie nicht finden kannst.',
|
|
19
|
-
"modal.error.required.fields": "E-Mail-Adresse und Bestellnummer sind notwendig",
|
|
20
|
-
"modal.error.invalid.unauthorized": "E-Mail-Adresse oder Bestellnummer ist falsch",
|
|
21
|
-
"modal.error.invalid.licenseKey": "Lizenzschl\xFCssel ung\xFCltig f\xFCr dieses Plugin",
|
|
22
|
-
"modal.error.incompatible": "Lizenzschl\xFCssel ung\xFCltig f\xFCr diese Plugin-Version",
|
|
23
|
-
"modal.error.upgradeable": "Lizenzschl\xFCssel ung\xFCltig f\xFCr diese Plugin-Version. Aktualisiere jetzt auf https://hub.kirby.tools.",
|
|
24
|
-
"modal.error.activated": "Lizenzschl\xFCssel bereits aktiviert",
|
|
25
|
-
"activate": "Aktivieren",
|
|
26
|
-
"activated": "Plugin aktiviert",
|
|
27
|
-
"buy": "Lizenz kaufen",
|
|
28
|
-
"upgrade": "Upgrade"
|
|
29
|
-
},
|
|
30
|
-
fr: {
|
|
31
|
-
"modal.info": "Merci d'avoir achet\xE9 {label} ! Veuillez saisir votre adresse e-mail et votre num\xE9ro de commande pour activer votre licence.",
|
|
32
|
-
"modal.fields.orderId.help": '<a href="https://app.lemonsqueezy.com/my-orders" target="_blank">Trouvez votre num\xE9ro de commande</a> sur Lemon Squeezy ou <a href="mailto:hello@kirby.tools">contactez-nous</a> si vous ne le trouvez pas.',
|
|
33
|
-
"modal.error.required.fields": "Adresse e-mail et num\xE9ro de commande requis",
|
|
34
|
-
"modal.error.invalid.unauthorized": "Adresse e-mail ou num\xE9ro de commande incorrect",
|
|
35
|
-
"modal.error.invalid.licenseKey": "Cl\xE9 de licence invalide pour ce plugin",
|
|
36
|
-
"modal.error.incompatible": "Cl\xE9 de licence invalide pour cette version du plugin",
|
|
37
|
-
"modal.error.upgradeable": "Cl\xE9 de licence invalide pour cette version du plugin. Mettez \xE0 niveau maintenant sur https://hub.kirby.tools.",
|
|
38
|
-
"modal.error.activated": "Cl\xE9 de licence d\xE9j\xE0 activ\xE9e",
|
|
39
|
-
"activate": "Activer",
|
|
40
|
-
"activated": "Plugin activ\xE9",
|
|
41
|
-
"buy": "Acheter une licence",
|
|
42
|
-
"upgrade": "Upgrade"
|
|
43
|
-
},
|
|
44
|
-
nl: {
|
|
45
|
-
"modal.info": "Bedankt voor het kopen van {label}! Voer je e-mailadres en bestelnummer in om je licentie te activeren.",
|
|
46
|
-
"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.',
|
|
47
|
-
"modal.error.required.fields": "E-mailadres en bestelnummer zijn verplicht",
|
|
48
|
-
"modal.error.invalid.unauthorized": "E-mailadres of bestelnummer is onjuist",
|
|
49
|
-
"modal.error.invalid.licenseKey": "Licentiesleutel ongeldig voor dit plug-in",
|
|
50
|
-
"modal.error.incompatible": "Licentiesleutel ongeldig voor deze plug-inversie",
|
|
51
|
-
"modal.error.upgradeable": "Licentiesleutel ongeldig voor deze plug-inversie. Upgrade nu op https://hub.kirby.tools.",
|
|
52
|
-
"modal.error.activated": "Licentiesleutel al geactiveerd",
|
|
53
|
-
"activate": "Activeren",
|
|
54
|
-
"activated": "Plugin geactiveerd",
|
|
55
|
-
"buy": "Koop een licentie",
|
|
56
|
-
"upgrade": "Upgrade"
|
|
57
|
-
}
|
|
58
|
-
};
|
package/dist/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./license.mjs";
|
package/dist/license.mjs
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { unref, usePanel } from "kirbyuse";
|
|
2
|
-
import { isLocal, t } from "./utils.mjs";
|
|
3
|
-
const ERROR_MESSAGE_TRANSLATIONS = {
|
|
4
|
-
"Unauthorized": "modal.error.invalid.unauthorized",
|
|
5
|
-
"License key not valid for this plugin": "modal.error.invalid.licenseKey",
|
|
6
|
-
"License key not valid for this plugin version": "modal.error.incompatible",
|
|
7
|
-
"License key not valid for this plugin version, please upgrade your license": "modal.error.upgradeable",
|
|
8
|
-
"License key already activated": "modal.error.activated"
|
|
9
|
-
};
|
|
10
|
-
export function useLicense(licenseOptions) {
|
|
11
|
-
const panel = usePanel();
|
|
12
|
-
const isLocalhost = isLocal();
|
|
13
|
-
const openLicenseModal = () => {
|
|
14
|
-
let isLicenseActive = false;
|
|
15
|
-
const { label } = licenseOptions;
|
|
16
|
-
const fields = {
|
|
17
|
-
info: {
|
|
18
|
-
type: "info",
|
|
19
|
-
text: t("modal.info", { label })
|
|
20
|
-
},
|
|
21
|
-
email: {
|
|
22
|
-
label: panel.t("email"),
|
|
23
|
-
type: "email"
|
|
24
|
-
},
|
|
25
|
-
orderId: {
|
|
26
|
-
label: "Order ID",
|
|
27
|
-
type: "text",
|
|
28
|
-
help: t("modal.fields.orderId.help", { label })
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
return new Promise((resolve) => {
|
|
32
|
-
panel.dialog.open({
|
|
33
|
-
component: "k-form-dialog",
|
|
34
|
-
props: {
|
|
35
|
-
submitButton: {
|
|
36
|
-
icon: "check",
|
|
37
|
-
theme: "love",
|
|
38
|
-
text: t("activate", { label })
|
|
39
|
-
},
|
|
40
|
-
fields
|
|
41
|
-
},
|
|
42
|
-
on: {
|
|
43
|
-
// Close event will always be triggered, even on submit
|
|
44
|
-
close: () => {
|
|
45
|
-
resolve({ isLicenseActive });
|
|
46
|
-
},
|
|
47
|
-
submit: async (event) => {
|
|
48
|
-
isLicenseActive = await activateLicense(event, licenseOptions);
|
|
49
|
-
if (isLicenseActive) {
|
|
50
|
-
panel.dialog.close();
|
|
51
|
-
panel.notification.success(t("activated"));
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
const assertActivationIntegrity = async ({ component, licenseStatus }) => {
|
|
59
|
-
if (unref(licenseStatus) === "active") {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const _component = unref(component);
|
|
63
|
-
if (!_component?.$el || window.getComputedStyle(_component.$el).display === "none" || window.getComputedStyle(_component.$el).visibility === "hidden" || window.getComputedStyle(_component.$el).opacity === "0") {
|
|
64
|
-
throw new Error("Are you trying to hide the activation buttons? Please buy a license.");
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
return {
|
|
68
|
-
isLocalhost,
|
|
69
|
-
assertActivationIntegrity,
|
|
70
|
-
openLicenseModal
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
async function activateLicense(event, licenseOptions) {
|
|
74
|
-
const panel = usePanel();
|
|
75
|
-
const { email, orderId } = event;
|
|
76
|
-
if (!email || !orderId) {
|
|
77
|
-
panel.notification.error(t("modal.error.required.fields"));
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
try {
|
|
81
|
-
const response = await panel.api.post(`${licenseOptions.apiNamespace}/activate`, {
|
|
82
|
-
email,
|
|
83
|
-
orderId: Number(orderId)
|
|
84
|
-
});
|
|
85
|
-
if (response?.status !== "ok") {
|
|
86
|
-
throw new Error("Failed to activate license key");
|
|
87
|
-
}
|
|
88
|
-
return true;
|
|
89
|
-
} catch (error) {
|
|
90
|
-
const message = error.message;
|
|
91
|
-
panel.notification.error(ERROR_MESSAGE_TRANSLATIONS[message] ? t(ERROR_MESSAGE_TRANSLATIONS[message]) : message);
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
}
|
package/dist/types.mjs
DELETED
|
File without changes
|
package/dist/utils.mjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { TRANSLATIONS } from "./constants.mjs";
|
|
2
|
-
const LOCALHOST_HOSTNAMES = ["localhost", "127.0.0.1", "[::1]"];
|
|
3
|
-
const LOCAL_DOMAINS = ["local", "test", "ddev.site"];
|
|
4
|
-
export function t(key = "", data) {
|
|
5
|
-
const languageCode = window.panel.translation.code;
|
|
6
|
-
const translation = TRANSLATIONS?.[languageCode]?.[key] ?? key;
|
|
7
|
-
return data ? template(translation, data) : translation;
|
|
8
|
-
}
|
|
9
|
-
export function template(input, values, fallback) {
|
|
10
|
-
return input.replace(
|
|
11
|
-
/\{(\w+)\}/g,
|
|
12
|
-
(_, key) => values[key] || ((typeof fallback === "function" ? fallback(key) : fallback) ?? key)
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
export function isLocal() {
|
|
16
|
-
const { hostname } = window.location;
|
|
17
|
-
const isLocalhost = LOCALHOST_HOSTNAMES.includes(hostname);
|
|
18
|
-
const isLocalDomain = LOCAL_DOMAINS.some((domain) => hostname.endsWith(`.${domain}`));
|
|
19
|
-
return isLocalhost || isLocalDomain;
|
|
20
|
-
}
|
|
File without changes
|