@kirby-tools/licensing 0.4.0 → 0.4.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.
@@ -40,10 +40,15 @@ onMounted(() => {
40
40
  })
41
41
 
42
42
  async function handleRegistration() {
43
- const { isRegistered } = await openLicenseModal()
44
- if (isRegistered) {
45
- currentLicenseStatus.value = 'active'
46
- }
43
+ const { isLicenseActive } = await openLicenseModal()
44
+
45
+ if (!isLicenseActive)
46
+ return
47
+
48
+ // currentLicenseStatus.value = 'active'
49
+
50
+ // Force a reload to refresh the plugin's cached context
51
+ window.location.reload()
47
52
  }
48
53
  </script>
49
54
 
@@ -54,22 +59,12 @@ async function handleRegistration() {
54
59
  layout="collapsed"
55
60
  >
56
61
  <k-button
57
- v-if="currentLicenseStatus === 'upgradeable'"
58
- theme="notice"
59
- variant="filled"
60
- size="xs"
61
- link="https://hub.kirby.tools"
62
- target="_blank"
63
- :text="t('upgrade')"
64
- />
65
- <k-button
66
- v-else
67
62
  theme="love"
68
63
  variant="filled"
69
64
  size="xs"
70
- :link="pricingUrl"
65
+ :link="currentLicenseStatus === 'upgradeable' ? 'https://hub.kirby.tools' : pricingUrl"
71
66
  target="_blank"
72
- :text="t('buy')"
67
+ :text="currentLicenseStatus === 'upgradeable' ? t('upgrade') : t('buy')"
73
68
  />
74
69
  <k-button
75
70
  theme="love"
package/dist/license.d.ts CHANGED
@@ -5,7 +5,7 @@ export interface LicenseOptions {
5
5
  apiNamespace: string;
6
6
  }
7
7
  export interface LicenseModalResult {
8
- isRegistered: boolean;
8
+ isLicenseActive: boolean;
9
9
  }
10
10
  export declare function useLicense(licenseOptions: LicenseOptions): {
11
11
  isLocalhost: any;
package/dist/license.mjs CHANGED
@@ -1,7 +1,5 @@
1
1
  import { unref, usePanel } from "kirbyuse";
2
- import { t } from "./utils.mjs";
3
- const LOCALHOST_HOSTNAMES = ["localhost", "127.0.0.1", "[::1]"];
4
- const LOCAL_DOMAINS = ["local", "test", "ddev.site"];
2
+ import { isLocal, t } from "./utils.mjs";
5
3
  const ERROR_MESSAGE_TRANSLATIONS = {
6
4
  "Unauthorized": "modal.error.invalid.unauthorized",
7
5
  "License key not valid for this plugin": "modal.error.invalid.licenseKey",
@@ -13,7 +11,7 @@ export function useLicense(licenseOptions) {
13
11
  const panel = usePanel();
14
12
  const isLocalhost = isLocal();
15
13
  const openLicenseModal = () => {
16
- let isRegistered = false;
14
+ let isLicenseActive = false;
17
15
  const { label } = licenseOptions;
18
16
  const fields = {
19
17
  info: {
@@ -44,11 +42,11 @@ export function useLicense(licenseOptions) {
44
42
  on: {
45
43
  // Close event will always be triggered, even on submit
46
44
  close: () => {
47
- resolve({ isRegistered });
45
+ resolve({ isLicenseActive });
48
46
  },
49
47
  submit: async (event) => {
50
- isRegistered = await registerLicense(event, licenseOptions);
51
- if (isRegistered) {
48
+ isLicenseActive = await registerLicense(event, licenseOptions);
49
+ if (isLicenseActive) {
52
50
  panel.dialog.close();
53
51
  panel.notification.success(t("activated"));
54
52
  }
@@ -94,9 +92,3 @@ async function registerLicense(event, licenseOptions) {
94
92
  return false;
95
93
  }
96
94
  }
97
- function isLocal() {
98
- const { hostname } = window.location;
99
- const isLocalhost = LOCALHOST_HOSTNAMES.includes(hostname);
100
- const isLocalDomain = LOCAL_DOMAINS.some((domain) => hostname.endsWith(`.${domain}`));
101
- return isLocalhost || isLocalDomain;
102
- }
package/dist/utils.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export declare function t(key?: string, data?: Record<string, string>): string;
2
2
  export declare function template(input: string, values: Record<string, string>, fallback?: string | ((key: string) => string)): string;
3
+ export declare function isLocal(): any;
package/dist/utils.mjs CHANGED
@@ -1,4 +1,6 @@
1
1
  import { TRANSLATIONS } from "./constants.mjs";
2
+ const LOCALHOST_HOSTNAMES = ["localhost", "127.0.0.1", "[::1]"];
3
+ const LOCAL_DOMAINS = ["local", "test", "ddev.site"];
2
4
  export function t(key = "", data) {
3
5
  const languageCode = window.panel.translation.code;
4
6
  const translation = TRANSLATIONS?.[languageCode]?.[key] ?? key;
@@ -10,3 +12,9 @@ export function template(input, values, fallback) {
10
12
  (_, key) => values[key] || ((typeof fallback === "function" ? fallback(key) : fallback) ?? key)
11
13
  );
12
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
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kirby-tools/licensing",
3
3
  "type": "module",
4
- "version": "0.4.0",
4
+ "version": "0.4.2",
5
5
  "packageManager": "pnpm@9.15.0",
6
6
  "description": "Shared tooling for Kirby Tools licensing in the Kirby Panel",
7
7
  "author": "Johann Schopplich <hello@johannschopplich.com>",
@@ -42,11 +42,11 @@
42
42
  "vue": "^2.7.16"
43
43
  },
44
44
  "devDependencies": {
45
- "@antfu/eslint-config": "^3.11.2",
46
- "bumpp": "^9.9.0",
47
- "eslint": "^9.16.0",
48
- "kirbyuse": "^0.9.1",
45
+ "@antfu/eslint-config": "^3.12.0",
46
+ "bumpp": "^9.9.1",
47
+ "eslint": "^9.17.0",
48
+ "kirbyuse": "^0.9.2",
49
49
  "typescript": "^5.7.2",
50
- "unbuild": "^3.0.0-rc.11"
50
+ "unbuild": "3.0.0-rc.11"
51
51
  }
52
52
  }