@supatype/cli 0.1.0-alpha.6 → 0.1.0-alpha.7

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.
Files changed (309) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-test.log +203 -1
  3. package/.turbo/turbo-typecheck.log +1 -1
  4. package/dist/app-config.d.ts +7 -0
  5. package/dist/app-config.d.ts.map +1 -0
  6. package/dist/app-config.js +113 -0
  7. package/dist/app-config.js.map +1 -0
  8. package/dist/augmentation-generator.d.ts +2 -0
  9. package/dist/augmentation-generator.d.ts.map +1 -0
  10. package/dist/augmentation-generator.js +111 -0
  11. package/dist/augmentation-generator.js.map +1 -0
  12. package/dist/binary-cache.d.ts +89 -0
  13. package/dist/binary-cache.d.ts.map +1 -0
  14. package/dist/binary-cache.js +656 -0
  15. package/dist/binary-cache.js.map +1 -0
  16. package/dist/cli.d.ts.map +1 -1
  17. package/dist/cli.js +13 -7
  18. package/dist/cli.js.map +1 -1
  19. package/dist/commands/admin.d.ts.map +1 -1
  20. package/dist/commands/admin.js +4 -3
  21. package/dist/commands/admin.js.map +1 -1
  22. package/dist/commands/app.d.ts.map +1 -1
  23. package/dist/commands/app.js +56 -209
  24. package/dist/commands/app.js.map +1 -1
  25. package/dist/commands/cache.d.ts +6 -0
  26. package/dist/commands/cache.d.ts.map +1 -0
  27. package/dist/commands/cache.js +105 -0
  28. package/dist/commands/cache.js.map +1 -0
  29. package/dist/commands/cloud.d.ts +12 -0
  30. package/dist/commands/cloud.d.ts.map +1 -1
  31. package/dist/commands/cloud.js +36 -46
  32. package/dist/commands/cloud.js.map +1 -1
  33. package/dist/commands/db.d.ts.map +1 -1
  34. package/dist/commands/db.js +47 -54
  35. package/dist/commands/db.js.map +1 -1
  36. package/dist/commands/deploy.d.ts +2 -1
  37. package/dist/commands/deploy.d.ts.map +1 -1
  38. package/dist/commands/deploy.js +92 -51
  39. package/dist/commands/deploy.js.map +1 -1
  40. package/dist/commands/dev.d.ts +11 -0
  41. package/dist/commands/dev.d.ts.map +1 -1
  42. package/dist/commands/dev.js +751 -384
  43. package/dist/commands/dev.js.map +1 -1
  44. package/dist/commands/diff.d.ts.map +1 -1
  45. package/dist/commands/diff.js +20 -15
  46. package/dist/commands/diff.js.map +1 -1
  47. package/dist/commands/engine.d.ts +1 -3
  48. package/dist/commands/engine.d.ts.map +1 -1
  49. package/dist/commands/engine.js +13 -85
  50. package/dist/commands/engine.js.map +1 -1
  51. package/dist/commands/functions.d.ts.map +1 -1
  52. package/dist/commands/functions.js +92 -105
  53. package/dist/commands/functions.js.map +1 -1
  54. package/dist/commands/generate.d.ts.map +1 -1
  55. package/dist/commands/generate.js +22 -12
  56. package/dist/commands/generate.js.map +1 -1
  57. package/dist/commands/init.d.ts +1 -1
  58. package/dist/commands/init.d.ts.map +1 -1
  59. package/dist/commands/init.js +124 -410
  60. package/dist/commands/init.js.map +1 -1
  61. package/dist/commands/migrate-from-v1.d.ts +5 -0
  62. package/dist/commands/migrate-from-v1.d.ts.map +1 -0
  63. package/dist/commands/migrate-from-v1.js +125 -0
  64. package/dist/commands/migrate-from-v1.js.map +1 -0
  65. package/dist/commands/migrate.d.ts.map +1 -1
  66. package/dist/commands/migrate.js +27 -23
  67. package/dist/commands/migrate.js.map +1 -1
  68. package/dist/commands/pg.d.ts +8 -0
  69. package/dist/commands/pg.d.ts.map +1 -0
  70. package/dist/commands/pg.js +102 -0
  71. package/dist/commands/pg.js.map +1 -0
  72. package/dist/commands/pull.d.ts.map +1 -1
  73. package/dist/commands/pull.js +5 -66
  74. package/dist/commands/pull.js.map +1 -1
  75. package/dist/commands/push.d.ts.map +1 -1
  76. package/dist/commands/push.js +99 -39
  77. package/dist/commands/push.js.map +1 -1
  78. package/dist/commands/seed.d.ts +2 -0
  79. package/dist/commands/seed.d.ts.map +1 -1
  80. package/dist/commands/seed.js +44 -11
  81. package/dist/commands/seed.js.map +1 -1
  82. package/dist/commands/self-host.d.ts +7 -1
  83. package/dist/commands/self-host.d.ts.map +1 -1
  84. package/dist/commands/self-host.js +272 -758
  85. package/dist/commands/self-host.js.map +1 -1
  86. package/dist/commands/self-update.d.ts +9 -0
  87. package/dist/commands/self-update.d.ts.map +1 -0
  88. package/dist/commands/self-update.js +33 -0
  89. package/dist/commands/self-update.js.map +1 -0
  90. package/dist/commands/status.d.ts.map +1 -1
  91. package/dist/commands/status.js +4 -3
  92. package/dist/commands/status.js.map +1 -1
  93. package/dist/commands/types.d.ts +3 -0
  94. package/dist/commands/types.d.ts.map +1 -0
  95. package/dist/commands/types.js +62 -0
  96. package/dist/commands/types.js.map +1 -0
  97. package/dist/commands/update.d.ts +7 -0
  98. package/dist/commands/update.d.ts.map +1 -0
  99. package/dist/commands/update.js +77 -0
  100. package/dist/commands/update.js.map +1 -0
  101. package/dist/components.d.ts +5 -0
  102. package/dist/components.d.ts.map +1 -0
  103. package/dist/components.js +3 -0
  104. package/dist/components.js.map +1 -0
  105. package/dist/config.d.ts +10 -51
  106. package/dist/config.d.ts.map +1 -1
  107. package/dist/config.js +101 -33
  108. package/dist/config.js.map +1 -1
  109. package/dist/docker-postgres.d.ts +39 -0
  110. package/dist/docker-postgres.d.ts.map +1 -0
  111. package/dist/docker-postgres.js +96 -0
  112. package/dist/docker-postgres.js.map +1 -0
  113. package/dist/engine-client.d.ts +67 -0
  114. package/dist/engine-client.d.ts.map +1 -0
  115. package/dist/engine-client.js +156 -0
  116. package/dist/engine-client.js.map +1 -0
  117. package/dist/ensure-binary.d.ts +7 -0
  118. package/dist/ensure-binary.d.ts.map +1 -0
  119. package/dist/ensure-binary.js +17 -0
  120. package/dist/ensure-binary.js.map +1 -0
  121. package/dist/functions-router-gen.d.ts +14 -0
  122. package/dist/functions-router-gen.d.ts.map +1 -0
  123. package/dist/functions-router-gen.js +199 -0
  124. package/dist/functions-router-gen.js.map +1 -0
  125. package/dist/index.d.ts +4 -5
  126. package/dist/index.d.ts.map +1 -1
  127. package/dist/index.js +2 -3
  128. package/dist/index.js.map +1 -1
  129. package/dist/kong-config.d.ts +21 -0
  130. package/dist/kong-config.d.ts.map +1 -0
  131. package/dist/kong-config.js +60 -0
  132. package/dist/kong-config.js.map +1 -0
  133. package/dist/local-gateway.d.ts +7 -0
  134. package/dist/local-gateway.d.ts.map +1 -0
  135. package/dist/local-gateway.js +9 -0
  136. package/dist/local-gateway.js.map +1 -0
  137. package/dist/local-storage.d.ts +8 -0
  138. package/dist/local-storage.d.ts.map +1 -0
  139. package/dist/local-storage.js +14 -0
  140. package/dist/local-storage.js.map +1 -0
  141. package/dist/pgbouncer-userlist.d.ts +5 -0
  142. package/dist/pgbouncer-userlist.d.ts.map +1 -0
  143. package/dist/pgbouncer-userlist.js +14 -0
  144. package/dist/pgbouncer-userlist.js.map +1 -0
  145. package/dist/postgres-ctl.d.ts +44 -0
  146. package/dist/postgres-ctl.d.ts.map +1 -0
  147. package/dist/postgres-ctl.js +137 -0
  148. package/dist/postgres-ctl.js.map +1 -0
  149. package/dist/process-manager.d.ts +41 -0
  150. package/dist/process-manager.d.ts.map +1 -0
  151. package/dist/process-manager.js +120 -0
  152. package/dist/process-manager.js.map +1 -0
  153. package/dist/project-config.d.ts +215 -0
  154. package/dist/project-config.d.ts.map +1 -0
  155. package/dist/project-config.js +145 -0
  156. package/dist/project-config.js.map +1 -0
  157. package/dist/pull-utils.d.ts +15 -0
  158. package/dist/pull-utils.d.ts.map +1 -1
  159. package/dist/pull-utils.js +12 -0
  160. package/dist/pull-utils.js.map +1 -1
  161. package/dist/release-pins.d.ts +7 -0
  162. package/dist/release-pins.d.ts.map +1 -0
  163. package/dist/release-pins.js +27 -0
  164. package/dist/release-pins.js.map +1 -0
  165. package/dist/release-public-key.d.ts +8 -0
  166. package/dist/release-public-key.d.ts.map +1 -0
  167. package/dist/release-public-key.js +13 -0
  168. package/dist/release-public-key.js.map +1 -0
  169. package/dist/runtime-routes.d.ts +25 -0
  170. package/dist/runtime-routes.d.ts.map +1 -0
  171. package/dist/runtime-routes.js +189 -0
  172. package/dist/runtime-routes.js.map +1 -0
  173. package/dist/scripts/postinstall.d.ts +5 -6
  174. package/dist/scripts/postinstall.d.ts.map +1 -1
  175. package/dist/scripts/postinstall.js +36 -20
  176. package/dist/scripts/postinstall.js.map +1 -1
  177. package/dist/self-host-compose.d.ts +14 -0
  178. package/dist/self-host-compose.d.ts.map +1 -0
  179. package/dist/self-host-compose.js +236 -0
  180. package/dist/self-host-compose.js.map +1 -0
  181. package/dist/storage-provision.d.ts +24 -0
  182. package/dist/storage-provision.d.ts.map +1 -0
  183. package/dist/storage-provision.js +44 -0
  184. package/dist/storage-provision.js.map +1 -0
  185. package/dist/systemd.d.ts +26 -0
  186. package/dist/systemd.d.ts.map +1 -0
  187. package/dist/systemd.js +102 -0
  188. package/dist/systemd.js.map +1 -0
  189. package/dist/tsx-runner.d.ts.map +1 -1
  190. package/dist/tsx-runner.js +9 -2
  191. package/dist/tsx-runner.js.map +1 -1
  192. package/dist/type-extractor.d.ts +31 -0
  193. package/dist/type-extractor.d.ts.map +1 -0
  194. package/dist/type-extractor.js +876 -0
  195. package/dist/type-extractor.js.map +1 -0
  196. package/package.json +4 -3
  197. package/releases/deno/VERSION +1 -0
  198. package/scripts/mirror-deno-release.sh +76 -0
  199. package/src/app-config.ts +128 -0
  200. package/src/augmentation-generator.ts +126 -0
  201. package/src/binary-cache.ts +802 -0
  202. package/src/cli.ts +13 -8
  203. package/src/commands/admin.ts +4 -3
  204. package/src/commands/app.ts +67 -231
  205. package/src/commands/cache.ts +117 -0
  206. package/src/commands/cloud.ts +46 -57
  207. package/src/commands/db.ts +54 -63
  208. package/src/commands/deploy.ts +110 -61
  209. package/src/commands/dev.ts +930 -405
  210. package/src/commands/diff.ts +21 -29
  211. package/src/commands/engine.ts +13 -116
  212. package/src/commands/functions.ts +97 -115
  213. package/src/commands/generate.ts +23 -10
  214. package/src/commands/init.ts +136 -414
  215. package/src/commands/migrate-from-v1.ts +131 -0
  216. package/src/commands/migrate.ts +27 -23
  217. package/src/commands/pg.ts +133 -0
  218. package/src/commands/pull.ts +6 -85
  219. package/src/commands/push.ts +128 -59
  220. package/src/commands/seed.ts +54 -12
  221. package/src/commands/self-host.ts +312 -880
  222. package/src/commands/self-update.ts +45 -0
  223. package/src/commands/status.ts +4 -3
  224. package/src/commands/types.ts +76 -0
  225. package/src/commands/update.ts +92 -0
  226. package/src/components.ts +6 -0
  227. package/src/config.ts +127 -94
  228. package/src/docker-postgres.ts +138 -0
  229. package/src/engine-client.ts +231 -0
  230. package/src/ensure-binary.ts +28 -0
  231. package/src/functions-router-gen.ts +224 -0
  232. package/src/index.ts +4 -12
  233. package/src/kong-config.ts +78 -0
  234. package/src/local-gateway.ts +9 -0
  235. package/src/local-storage.ts +14 -0
  236. package/src/pgbouncer-userlist.ts +15 -0
  237. package/src/postgres-ctl.ts +171 -0
  238. package/src/process-manager.ts +151 -0
  239. package/src/project-config.ts +353 -0
  240. package/src/pull-utils.ts +24 -0
  241. package/src/release-pins.ts +31 -0
  242. package/src/release-public-key.ts +12 -0
  243. package/src/runtime-routes.ts +216 -0
  244. package/src/scripts/postinstall.ts +36 -25
  245. package/src/self-host-compose.ts +257 -0
  246. package/src/storage-provision.ts +58 -0
  247. package/src/systemd.ts +137 -0
  248. package/src/tsx-runner.ts +11 -1
  249. package/src/type-extractor.ts +1016 -0
  250. package/tests/app-command.test.ts +54 -0
  251. package/tests/augmentation-generator.test.ts +59 -0
  252. package/tests/binary-cache-cloud-overrides.test.ts +123 -0
  253. package/tests/cached-artifact-format.test.ts +84 -0
  254. package/tests/cli-help.test.ts +40 -14
  255. package/tests/config.test.ts +140 -37
  256. package/tests/engine-distribution.test.ts +3 -3
  257. package/tests/ensure-binary.test.ts +59 -0
  258. package/tests/init.test.ts +28 -86
  259. package/tests/migrate-from-v1.test.ts +29 -0
  260. package/tests/pg-spawn-env.test.ts +18 -0
  261. package/tests/postgres-archive-tag.test.ts +9 -0
  262. package/tests/pull-utils.test.ts +36 -1
  263. package/tests/release-pins.test.ts +28 -0
  264. package/tests/runtime-contract.test.ts +236 -0
  265. package/tests/seed-discover.test.ts +31 -0
  266. package/tests/tsconfig.json +9 -0
  267. package/tests/type-extractor.test.ts +401 -0
  268. package/tsconfig.tsbuildinfo +1 -1
  269. package/vitest.config.ts +12 -0
  270. package/dist/engine/cache.d.ts +0 -37
  271. package/dist/engine/cache.d.ts.map +0 -1
  272. package/dist/engine/cache.js +0 -121
  273. package/dist/engine/cache.js.map +0 -1
  274. package/dist/engine/download.d.ts +0 -19
  275. package/dist/engine/download.d.ts.map +0 -1
  276. package/dist/engine/download.js +0 -108
  277. package/dist/engine/download.js.map +0 -1
  278. package/dist/engine/platform.d.ts +0 -24
  279. package/dist/engine/platform.d.ts.map +0 -1
  280. package/dist/engine/platform.js +0 -50
  281. package/dist/engine/platform.js.map +0 -1
  282. package/dist/engine/resolve.d.ts +0 -37
  283. package/dist/engine/resolve.d.ts.map +0 -1
  284. package/dist/engine/resolve.js +0 -133
  285. package/dist/engine/resolve.js.map +0 -1
  286. package/dist/engine/update-notify.d.ts +0 -11
  287. package/dist/engine/update-notify.d.ts.map +0 -1
  288. package/dist/engine/update-notify.js +0 -43
  289. package/dist/engine/update-notify.js.map +0 -1
  290. package/dist/engine/verify.d.ts +0 -50
  291. package/dist/engine/verify.d.ts.map +0 -1
  292. package/dist/engine/verify.js +0 -161
  293. package/dist/engine/verify.js.map +0 -1
  294. package/dist/engine-version.d.ts +0 -35
  295. package/dist/engine-version.d.ts.map +0 -1
  296. package/dist/engine-version.js +0 -35
  297. package/dist/engine-version.js.map +0 -1
  298. package/dist/engine.d.ts +0 -34
  299. package/dist/engine.d.ts.map +0 -1
  300. package/dist/engine.js +0 -76
  301. package/dist/engine.js.map +0 -1
  302. package/src/engine/cache.ts +0 -135
  303. package/src/engine/download.ts +0 -143
  304. package/src/engine/platform.ts +0 -66
  305. package/src/engine/resolve.ts +0 -197
  306. package/src/engine/update-notify.ts +0 -50
  307. package/src/engine/verify.ts +0 -206
  308. package/src/engine-version.ts +0 -39
  309. package/src/engine.ts +0 -99
@@ -1,50 +0,0 @@
1
- /**
2
- * Non-blocking update notification shown after CLI commands.
3
- * Checks once per 24 hours. Skips in CI environments.
4
- */
5
-
6
- import { ENGINE_VERSION } from "../engine-version.js"
7
- import {
8
- shouldCheckForUpdates,
9
- saveUpdateCheck,
10
- getLastKnownLatestVersion,
11
- } from "./cache.js"
12
- import { checkLatestVersion } from "./resolve.js"
13
-
14
- /**
15
- * Show an update notification if a newer engine version is available.
16
- * This runs after every CLI command, but only actually checks the network
17
- * once per 24 hours (throttled via ~/.supatype/update-check.json).
18
- */
19
- export async function showUpdateNotification(): Promise<void> {
20
- try {
21
- const shouldCheck = await shouldCheckForUpdates()
22
-
23
- if (shouldCheck) {
24
- // Perform network check
25
- const latest = await checkLatestVersion()
26
- if (latest) {
27
- await saveUpdateCheck(latest.version)
28
- if (latest.version !== ENGINE_VERSION) {
29
- printNotification(latest.version)
30
- }
31
- }
32
- } else {
33
- // Use cached info from last check
34
- const cachedLatest = await getLastKnownLatestVersion()
35
- if (cachedLatest && cachedLatest !== ENGINE_VERSION) {
36
- printNotification(cachedLatest)
37
- }
38
- }
39
- } catch {
40
- // Never fail the CLI command because of update check
41
- }
42
- }
43
-
44
- function printNotification(latestVersion: string): void {
45
- console.log()
46
- console.log(
47
- `Supatype engine v${latestVersion} is available. ` +
48
- `Run: npm update @supatype/cli`,
49
- )
50
- }
@@ -1,206 +0,0 @@
1
- /**
2
- * Checksum and signature verification for engine binaries.
3
- *
4
- * Two-step verification:
5
- * 1. Verify minisign signature on checksums.sha256 file
6
- * 2. Verify SHA256 hash of binary against signed checksum file
7
- *
8
- * Both steps MUST pass before the CLI executes the binary.
9
- */
10
-
11
- import { createHash } from "node:crypto"
12
- import { readFile, unlink } from "node:fs/promises"
13
-
14
- /**
15
- * Embedded minisign public key.
16
- *
17
- * This key is used to verify the signature on the checksum file.
18
- * It ensures the checksum file was produced by Supatype's CI,
19
- * not by an attacker who compromised the CDN.
20
- *
21
- * Generated with: minisign -G
22
- * The corresponding private key is stored as a GitHub Actions secret.
23
- *
24
- * TODO: Replace with actual public key once generated.
25
- */
26
- export const MINISIGN_PUBLIC_KEY = "RWS0000000000000000000000000000000000000000000000000"
27
-
28
- /**
29
- * Verify the minisign signature on a checksum file.
30
- *
31
- * Uses a pure-JS minisign verification (Ed25519).
32
- * Returns true if the signature is valid, false otherwise.
33
- */
34
- export async function verifySignature(
35
- checksumPath: string,
36
- signaturePath: string,
37
- publicKey: string = MINISIGN_PUBLIC_KEY,
38
- ): Promise<boolean> {
39
- // Minisign signature format:
40
- // Line 1: untrusted comment
41
- // Line 2: base64-encoded signature
42
- // Line 3 (optional): trusted comment
43
- // Line 4 (optional): base64-encoded global signature
44
-
45
- try {
46
- const sigContent = await readFile(signaturePath, "utf8")
47
- const checksumContent = await readFile(checksumPath)
48
-
49
- const sigLines = sigContent.trim().split("\n")
50
- if (sigLines.length < 2) return false
51
-
52
- // Parse the signature (line 2 is the base64-encoded signature)
53
- const sigBase64 = sigLines[1]!.trim()
54
- const sigBytes = Buffer.from(sigBase64, "base64")
55
-
56
- // Minisign signature: 2 bytes algorithm + 8 bytes key ID + 64 bytes Ed25519 sig
57
- if (sigBytes.length < 74) return false
58
-
59
- const algorithm = sigBytes.subarray(0, 2)
60
- const keyId = sigBytes.subarray(2, 10)
61
- const signature = sigBytes.subarray(10, 74)
62
-
63
- // Parse public key
64
- const pkBytes = Buffer.from(publicKey.slice(2), "base64") // Skip "RW" prefix
65
- if (pkBytes.length < 42) return false
66
-
67
- // Public key: 2 bytes algorithm + 8 bytes key ID + 32 bytes Ed25519 pubkey
68
- const pkKeyId = pkBytes.subarray(2, 10)
69
- const pk = pkBytes.subarray(10, 42)
70
-
71
- // Verify key IDs match
72
- if (!keyId.equals(pkKeyId)) return false
73
-
74
- // Verify Ed25519 signature using Node.js crypto
75
- const { verify, createPublicKey } = await import("node:crypto")
76
-
77
- const publicKeyObj = createPublicKey({
78
- key: Buffer.concat([
79
- // Ed25519 public key DER prefix
80
- Buffer.from("302a300506032b6570032100", "hex"),
81
- pk,
82
- ]),
83
- format: "der",
84
- type: "spki",
85
- })
86
-
87
- const isValid = verify(null, checksumContent, publicKeyObj, signature)
88
-
89
- // If there's a trusted comment (line 3-4), verify the global signature too
90
- if (sigLines.length >= 4 && isValid) {
91
- const trustedComment = sigLines[2]?.replace(/^trusted comment: ?/, "") || ""
92
- const globalSigBase64 = sigLines[3]!.trim()
93
- const globalSig = Buffer.from(globalSigBase64, "base64")
94
-
95
- const globalMessage = Buffer.concat([signature, Buffer.from(trustedComment)])
96
- const globalValid = verify(null, globalMessage, publicKeyObj, globalSig)
97
- return globalValid
98
- }
99
-
100
- return isValid
101
- } catch {
102
- return false
103
- }
104
- }
105
-
106
- /**
107
- * Verify the SHA256 checksum of a binary against a signed checksum file.
108
- *
109
- * The checksum file format follows sha256sum output:
110
- * <hash> <filename>
111
- */
112
- export async function verifyChecksum(
113
- binaryPath: string,
114
- checksumPath: string,
115
- expectedFilename: string,
116
- ): Promise<boolean> {
117
- const checksumContent = await readFile(checksumPath, "utf8")
118
-
119
- // Find the line matching our filename
120
- const lines = checksumContent.trim().split("\n")
121
- let expectedHash: string | undefined
122
-
123
- for (const line of lines) {
124
- // Format: "<hash> <filename>" (two spaces)
125
- const parts = line.trim().split(/\s+/)
126
- if (parts.length >= 2 && parts[1] === expectedFilename) {
127
- expectedHash = parts[0]!.toLowerCase()
128
- break
129
- }
130
- }
131
-
132
- if (!expectedHash) {
133
- throw new Error(
134
- `No checksum found for ${expectedFilename} in checksum file`,
135
- )
136
- }
137
-
138
- const binaryData = await readFile(binaryPath)
139
- const actualHash = createHash("sha256").update(binaryData).digest("hex")
140
-
141
- return actualHash === expectedHash
142
- }
143
-
144
- /**
145
- * Run the full two-step verification pipeline.
146
- * Deletes the binary if verification fails.
147
- *
148
- * Step 1: Verify minisign signature on checksums.sha256
149
- * Step 2: Verify SHA256 hash of binary against signed checksum
150
- */
151
- export async function verifyBinary(
152
- binaryPath: string,
153
- checksumPath: string,
154
- signaturePath: string,
155
- artifactName: string,
156
- ): Promise<void> {
157
- // Step 1: Verify signature
158
- const sigValid = await verifySignature(checksumPath, signaturePath)
159
- if (!sigValid) {
160
- await safeDelete(binaryPath)
161
- throw new Error(
162
- "Engine checksum signature verification failed.\n" +
163
- "The checksum file may have been tampered with.\n" +
164
- "If this persists, report at https://github.com/supatype/supatype/issues",
165
- )
166
- }
167
-
168
- // Step 2: Verify checksum
169
- const checksumValid = await verifyChecksum(binaryPath, checksumPath, artifactName)
170
- if (!checksumValid) {
171
- await safeDelete(binaryPath)
172
- throw new Error(
173
- "Engine binary checksum mismatch.\n" +
174
- "This could indicate a corrupt download or a tampered binary.\n" +
175
- "Try again or report at https://github.com/supatype/supatype/issues",
176
- )
177
- }
178
- }
179
-
180
- /**
181
- * Simple checksum-only verification (no signature).
182
- * Used as a fallback when signature files are not available.
183
- */
184
- export async function verifyChecksumOnly(
185
- binaryPath: string,
186
- checksumPath: string,
187
- artifactName: string,
188
- ): Promise<void> {
189
- const valid = await verifyChecksum(binaryPath, checksumPath, artifactName)
190
- if (!valid) {
191
- await safeDelete(binaryPath)
192
- throw new Error(
193
- "Engine binary checksum mismatch.\n" +
194
- "This could indicate a corrupt download or a tampered binary.\n" +
195
- "Try again or report at https://github.com/supatype/supatype/issues",
196
- )
197
- }
198
- }
199
-
200
- async function safeDelete(path: string): Promise<void> {
201
- try {
202
- await unlink(path)
203
- } catch {
204
- // Ignore deletion errors
205
- }
206
- }
@@ -1,39 +0,0 @@
1
- /**
2
- * The engine binary version this CLI package expects.
3
- * Update this whenever a new engine binary is released.
4
- *
5
- * The CLI always downloads and uses this exact version.
6
- * Upgrading the CLI (npm update) may bump the pinned engine version.
7
- * This ensures CLI and engine are always compatible.
8
- *
9
- * Versioning policy:
10
- * 0.x.y-alpha.N — alpha
11
- * 0.x.y-beta.N — beta
12
- * 0.x.y — stable pre-1.0
13
- * 1.0.0 — cloud launch
14
- * Major bumps (1.0 → 2.0) indicate breaking changes to the schema AST format.
15
- */
16
- export const ENGINE_VERSION = "0.1.0"
17
-
18
- /**
19
- * Primary CDN for engine binary distribution.
20
- * Hetzner Object Storage behind Cloudflare edge caching.
21
- */
22
- export const CDN_BASE_URL = "https://releases.supatype.io/engine"
23
-
24
- /**
25
- * Fallback: GitHub Releases on the public engine-releases repo.
26
- * Used when the primary CDN is unavailable.
27
- * Contains only binaries — no source code.
28
- */
29
- export const ENGINE_RELEASES_REPO = "supatype/engine-releases"
30
- export const GITHUB_RELEASES_FALLBACK_URL =
31
- `https://github.com/${ENGINE_RELEASES_REPO}/releases/download`
32
-
33
- /**
34
- * Legacy: GitHub repository for direct engine releases (before CDN).
35
- * Kept for backwards compatibility with existing downloads.
36
- */
37
- export const ENGINE_REPO = "supatype/schema-engine"
38
- export const ENGINE_DOWNLOAD_BASE =
39
- `https://github.com/${ENGINE_REPO}/releases/download/v${ENGINE_VERSION}`
package/src/engine.ts DELETED
@@ -1,99 +0,0 @@
1
- /**
2
- * Locates the engine binary (from cache) and provides a helper to invoke it.
3
- *
4
- * The engine binary is cached at ~/.supatype/engine/{version}/supatype-engine[.exe].
5
- * On first use, it's automatically downloaded, verified, and cached.
6
- */
7
-
8
- import { spawnSync, type SpawnSyncReturns } from "node:child_process"
9
- import { ENGINE_VERSION } from "./engine-version.js"
10
- import { detectPlatform } from "./engine/platform.js"
11
- import { getCachedBinaryPath, hasCachedBinary } from "./engine/cache.js"
12
- import { resolveEngine, checkVersionCompatibility } from "./engine/resolve.js"
13
-
14
- export interface EngineResult {
15
- stdout: string
16
- stderr: string
17
- exitCode: number
18
- }
19
-
20
- /**
21
- * Get the path to the engine binary, downloading if needed.
22
- * This is the async version — use when you can await.
23
- */
24
- export async function getEnginePathAsync(): Promise<string> {
25
- const platform = detectPlatform()
26
-
27
- // Fast path: binary already cached
28
- if (hasCachedBinary(ENGINE_VERSION, platform)) {
29
- return getCachedBinaryPath(ENGINE_VERSION, platform)
30
- }
31
-
32
- // Need to download
33
- const result = await resolveEngine(ENGINE_VERSION)
34
- return result.binaryPath
35
- }
36
-
37
- /**
38
- * Get the path to the engine binary (sync).
39
- * Throws if the binary is not cached — caller must ensure it's downloaded first.
40
- */
41
- export function getEnginePath(): string {
42
- const platform = detectPlatform()
43
- const path = getCachedBinaryPath(ENGINE_VERSION, platform)
44
-
45
- if (!hasCachedBinary(ENGINE_VERSION, platform)) {
46
- throw new Error(
47
- `Supatype engine binary not found in cache.\n` +
48
- `Expected: ${path}\n` +
49
- `Run any supatype command to trigger automatic download,\n` +
50
- `or run: npx supatype engine version`,
51
- )
52
- }
53
-
54
- return path
55
- }
56
-
57
- /**
58
- * Ensure the engine binary is available, downloading if necessary.
59
- * Call this before invokeEngine() in command handlers.
60
- */
61
- export async function ensureEngine(): Promise<string> {
62
- const result = await resolveEngine(ENGINE_VERSION)
63
-
64
- if (!result.fromCache) {
65
- // Just downloaded — version is correct
66
- return result.binaryPath
67
- }
68
-
69
- // Cached — check compatibility
70
- const compat = checkVersionCompatibility(ENGINE_VERSION, ENGINE_VERSION)
71
- if (!compat.compatible) {
72
- throw new Error(compat.message)
73
- }
74
-
75
- return result.binaryPath
76
- }
77
-
78
- /**
79
- * Invoke the engine binary with the given arguments.
80
- * Input JSON is passed via stdin.
81
- *
82
- * The caller must call ensureEngine() first to guarantee the binary exists.
83
- */
84
- export function invokeEngine(
85
- args: string[],
86
- input?: string,
87
- ): EngineResult {
88
- const enginePath = getEnginePath()
89
- const result: SpawnSyncReturns<Buffer> = spawnSync(enginePath, args, {
90
- input: input ? Buffer.from(input, "utf8") : undefined,
91
- maxBuffer: 50 * 1024 * 1024, // 50MB
92
- })
93
-
94
- return {
95
- stdout: result.stdout?.toString("utf8") ?? "",
96
- stderr: result.stderr?.toString("utf8") ?? "",
97
- exitCode: result.status ?? 1,
98
- }
99
- }