@ossmalaysia/keelson 0.0.0-stage → 0.0.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 +24 -2
- package/bin/keelson.js +21 -0
- package/lib.js +73 -0
- package/package.json +12 -4
- package/postinstall.js +7 -0
package/README.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ossmalaysia/keelson
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Contract-driven backend for business apps that AI can extend safely. One
|
|
4
|
+
contract file defines data, rules and workflow; one program serves a
|
|
5
|
+
grid/form UI, a REST API and an MCP endpoint. AI proposes changes, an admin
|
|
6
|
+
approves, the engine enforces.
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npx @ossmalaysia/keelson dev --template crm
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Opens a local backend at `http://localhost:8080` that reloads `contract.yaml`
|
|
13
|
+
on every edit. For a real server:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g @ossmalaysia/keelson
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
keelson serve
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
This package downloads the prebuilt Keelson program for your platform
|
|
24
|
+
(Linux x64, macOS, Windows x64) from the matching GitHub release and verifies
|
|
25
|
+
its checksum. Documentation: https://github.com/ossmalaysia/keelson
|
package/bin/keelson.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
const { spawn } = require("child_process");
|
|
4
|
+
const { ensure } = require("../lib.js");
|
|
5
|
+
|
|
6
|
+
ensure().then(
|
|
7
|
+
(bin) => {
|
|
8
|
+
const child = spawn(bin, process.argv.slice(2), { stdio: "inherit" });
|
|
9
|
+
for (const sig of ["SIGINT", "SIGTERM", "SIGHUP"]) process.on(sig, () => child.kill(sig));
|
|
10
|
+
child.on("error", (e) => {
|
|
11
|
+
console.error(`keelson: cannot start ${bin}: ${e.message}`);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
});
|
|
14
|
+
child.on("exit", (code, signal) => process.exit(signal ? 1 : code ?? 1));
|
|
15
|
+
},
|
|
16
|
+
(e) => {
|
|
17
|
+
console.error(`keelson: ${e.message}`);
|
|
18
|
+
console.error("keelson: could not get the Keelson program. Check your connection, or download it from https://github.com/ossmalaysia/keelson/releases");
|
|
19
|
+
process.exit(1);
|
|
20
|
+
},
|
|
21
|
+
);
|
package/lib.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Finds, and if needed downloads, the Keelson binary for this platform.
|
|
2
|
+
// The binary comes from the GitHub release matching this package's version
|
|
3
|
+
// and is checked against the SHA-256 published beside it.
|
|
4
|
+
"use strict";
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const os = require("os");
|
|
7
|
+
const path = require("path");
|
|
8
|
+
const crypto = require("crypto");
|
|
9
|
+
|
|
10
|
+
const VERSION = require("./package.json").version;
|
|
11
|
+
const BASE = (process.env.KEELSON_DOWNLOAD_BASE || `https://github.com/ossmalaysia/keelson/releases/download/v${VERSION}`).replace(/\/+$/, "");
|
|
12
|
+
|
|
13
|
+
const TARGETS = {
|
|
14
|
+
"linux-x64": "x86_64-unknown-linux-musl",
|
|
15
|
+
"darwin-arm64": "aarch64-apple-darwin",
|
|
16
|
+
"darwin-x64": "x86_64-apple-darwin",
|
|
17
|
+
"win32-x64": "x86_64-pc-windows-msvc",
|
|
18
|
+
"win32-arm64": "x86_64-pc-windows-msvc", // runs under Windows' x64 emulation
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function asset() {
|
|
22
|
+
const target = TARGETS[`${process.platform}-${process.arch}`];
|
|
23
|
+
if (!target) {
|
|
24
|
+
throw new Error(`Keelson has no prebuilt binary for ${process.platform}-${process.arch}. Build from source: https://github.com/ossmalaysia/keelson#build-from-source`);
|
|
25
|
+
}
|
|
26
|
+
return `keelson-${target}${process.platform === "win32" ? ".exe" : ""}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Prefer the package folder; fall back to the home folder when it is read-only
|
|
30
|
+
// (for example a global install done with sudo).
|
|
31
|
+
function candidates() {
|
|
32
|
+
const name = asset();
|
|
33
|
+
return [path.join(__dirname, "vendor", VERSION, name), path.join(os.homedir(), ".keelson", "bin", VERSION, name)];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function existing() {
|
|
37
|
+
return candidates().find((p) => fs.existsSync(p)) || null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function get(url) {
|
|
41
|
+
const res = await fetch(url, { redirect: "follow" });
|
|
42
|
+
if (!res.ok) throw new Error(`HTTP ${res.status} for ${url}`);
|
|
43
|
+
return Buffer.from(await res.arrayBuffer());
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function download() {
|
|
47
|
+
const name = asset();
|
|
48
|
+
const [bin, sum] = await Promise.all([get(`${BASE}/${name}`), get(`${BASE}/${name}.sha256`)]);
|
|
49
|
+
const expected = sum.toString("utf8").trim().split(/\s+/)[0].toLowerCase();
|
|
50
|
+
const actual = crypto.createHash("sha256").update(bin).digest("hex");
|
|
51
|
+
if (!/^[0-9a-f]{64}$/.test(expected) || expected !== actual) {
|
|
52
|
+
throw new Error(`checksum mismatch for ${name}: refusing to use the download`);
|
|
53
|
+
}
|
|
54
|
+
let lastError;
|
|
55
|
+
for (const dest of candidates()) {
|
|
56
|
+
try {
|
|
57
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
58
|
+
const tmp = `${dest}.${process.pid}.tmp`;
|
|
59
|
+
fs.writeFileSync(tmp, bin, { mode: 0o755 });
|
|
60
|
+
fs.renameSync(tmp, dest);
|
|
61
|
+
return dest;
|
|
62
|
+
} catch (e) {
|
|
63
|
+
lastError = e;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
throw lastError;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function ensure() {
|
|
70
|
+
return existing() || (await download());
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = { ensure, existing, VERSION, BASE };
|
package/package.json
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossmalaysia/keelson",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
}
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Contract-driven backend for business apps that AI can extend safely: REST, MCP and a grid/form UI from one contract file.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": { "type": "git", "url": "git+https://github.com/ossmalaysia/keelson.git", "directory": "npm" },
|
|
7
|
+
"homepage": "https://github.com/ossmalaysia/keelson#readme",
|
|
8
|
+
"bugs": "https://github.com/ossmalaysia/keelson/issues",
|
|
9
|
+
"keywords": ["backend", "mcp", "ai", "crm", "low-code", "sqlite", "nextjs"],
|
|
10
|
+
"bin": { "keelson": "bin/keelson.js" },
|
|
11
|
+
"files": ["bin/", "lib.js", "postinstall.js", "README.md"],
|
|
12
|
+
"scripts": { "postinstall": "node postinstall.js" },
|
|
13
|
+
"engines": { "node": ">=18" }
|
|
14
|
+
}
|
package/postinstall.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Fetch the binary at install time so the first run is instant. Never fails
|
|
2
|
+
// the install: the launcher downloads on first run if this did not work
|
|
3
|
+
// (offline install, --ignore-scripts, a proxy).
|
|
4
|
+
"use strict";
|
|
5
|
+
require("./lib.js")
|
|
6
|
+
.ensure()
|
|
7
|
+
.catch((e) => console.warn(`keelson: binary not downloaded yet (${e.message}); it will be fetched on first run.`));
|