@melihmucuk/leash 1.0.4 → 1.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melihmucuk/leash",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "type": "module",
5
5
  "description": "Security guardrails for AI coding agents",
6
6
  "bin": {
@@ -9,7 +9,8 @@
9
9
  "files": [
10
10
  "dist/",
11
11
  "bin/",
12
- "!bin/test/"
12
+ "!bin/test/",
13
+ "packages/core/lib/version-checker.js"
13
14
  ],
14
15
  "author": "Melih Mucuk",
15
16
  "license": "MIT",
@@ -0,0 +1,44 @@
1
+ import { readFileSync, existsSync } from "fs";
2
+ import { dirname, join } from "path";
3
+ import { fileURLToPath } from "url";
4
+ function getVersion() {
5
+ const __dirname = dirname(fileURLToPath(import.meta.url));
6
+ const candidates = [
7
+ join(__dirname, "..", "..", "package.json"),
8
+ join(__dirname, "..", "..", "..", "package.json")
9
+ ];
10
+ for (const path of candidates) {
11
+ if (existsSync(path)) {
12
+ try {
13
+ const pkg = JSON.parse(readFileSync(path, "utf-8"));
14
+ if (pkg.name === "@melihmucuk/leash") {
15
+ return pkg.version;
16
+ }
17
+ } catch {
18
+ }
19
+ }
20
+ }
21
+ return "0.0.0";
22
+ }
23
+ const CURRENT_VERSION = getVersion();
24
+ const NPM_REGISTRY_URL = "https://registry.npmjs.org/@melihmucuk/leash/latest";
25
+ async function checkForUpdates() {
26
+ try {
27
+ const response = await fetch(NPM_REGISTRY_URL);
28
+ if (!response.ok) {
29
+ return { hasUpdate: false, currentVersion: CURRENT_VERSION };
30
+ }
31
+ const data = await response.json();
32
+ return {
33
+ hasUpdate: data.version !== CURRENT_VERSION,
34
+ latestVersion: data.version,
35
+ currentVersion: CURRENT_VERSION
36
+ };
37
+ } catch {
38
+ return { hasUpdate: false, currentVersion: CURRENT_VERSION };
39
+ }
40
+ }
41
+ export {
42
+ CURRENT_VERSION,
43
+ checkForUpdates
44
+ };