@zabaca/zbc 0.3.0 → 0.3.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.
package/package.json
CHANGED
package/src/commands/init.ts
CHANGED
|
@@ -111,13 +111,11 @@ export const initCommand = defineCommand({
|
|
|
111
111
|
console.warn(` warn: unknown --ci=${args.ci} (only "github" supported)`)
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
// 7. Claude Code scaffolding (
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
await copyTemplateDir(path.join(tplRoot, 'claude'), path.join(cwd, '.claude'))
|
|
120
|
-
}
|
|
114
|
+
// 7. Claude Code scaffolding (skip-if-exists, safe in either mode)
|
|
115
|
+
await copyTemplateFile(path.join(tplRoot, 'CLAUDE.md'), path.join(cwd, 'CLAUDE.md'), {
|
|
116
|
+
vars,
|
|
117
|
+
})
|
|
118
|
+
await copyTemplateDir(path.join(tplRoot, 'claude'), path.join(cwd, '.claude'))
|
|
121
119
|
|
|
122
120
|
console.log('')
|
|
123
121
|
console.log('✓ init done')
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { randomBytes } from 'node:crypto'
|
|
2
1
|
import { z } from 'zod'
|
|
2
|
+
import { createOperator, createAccount, fromSeed } from '@nats-io/nkeys'
|
|
3
|
+
import { encodeOperator, encodeAccount } from '@nats-io/jwt'
|
|
3
4
|
import { defineModule } from '../../src/define-module'
|
|
4
5
|
|
|
5
6
|
const FLY_API = 'https://api.machines.dev'
|
|
6
7
|
const FLY_GRAPHQL = 'https://api.fly.io/graphql'
|
|
7
|
-
const NATS_USER = 'app'
|
|
8
8
|
const MACHINE_TAG = { 'managed-by': 'zbc', instance: 'nats' } as const
|
|
9
9
|
|
|
10
10
|
interface FlyApp {
|
|
@@ -93,9 +93,15 @@ async function ensureIPs(appName: string, token: string): Promise<void> {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
function renderConf(): string {
|
|
96
|
+
function renderConf(operatorJWT: string, accountPub: string, accountJWT: string): string {
|
|
97
97
|
return `# Managed by zbc — do not edit by hand.
|
|
98
98
|
|
|
99
|
+
operator: ${operatorJWT}
|
|
100
|
+
resolver: MEMORY
|
|
101
|
+
resolver_preload: {
|
|
102
|
+
${accountPub}: ${accountJWT}
|
|
103
|
+
}
|
|
104
|
+
|
|
99
105
|
http_port: 8222
|
|
100
106
|
|
|
101
107
|
websocket {
|
|
@@ -103,11 +109,6 @@ websocket {
|
|
|
103
109
|
no_tls: true
|
|
104
110
|
}
|
|
105
111
|
|
|
106
|
-
authorization {
|
|
107
|
-
user: ${NATS_USER}
|
|
108
|
-
password: $NATS_PASSWORD
|
|
109
|
-
}
|
|
110
|
-
|
|
111
112
|
max_payload: 1MB
|
|
112
113
|
write_deadline: "10s"
|
|
113
114
|
`
|
|
@@ -130,23 +131,35 @@ export const natsServerModule = defineModule({
|
|
|
130
131
|
}),
|
|
131
132
|
outputs: z.object({
|
|
132
133
|
url: z.string(),
|
|
133
|
-
|
|
134
|
-
|
|
134
|
+
accountPublicKey: z.string(),
|
|
135
|
+
accountSigningKey: z.string(),
|
|
135
136
|
}),
|
|
136
137
|
async apply(config, ctx) {
|
|
137
138
|
const flyToken = ctx.secrets['FLY_API_TOKEN']
|
|
138
139
|
if (!flyToken) throw new Error('Missing secret: FLY_API_TOKEN')
|
|
139
140
|
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
const operatorSeed = ctx.secrets['NATS_OPERATOR_SEED']
|
|
142
|
+
const accountSeed = ctx.secrets['NATS_ACCOUNT_SEED']
|
|
143
|
+
if (!operatorSeed || !accountSeed) {
|
|
144
|
+
const op = createOperator()
|
|
145
|
+
const ac = createAccount()
|
|
146
|
+
const opSeed = new TextDecoder().decode(op.getSeed())
|
|
147
|
+
const acSeed = new TextDecoder().decode(ac.getSeed())
|
|
143
148
|
throw new Error(
|
|
144
|
-
`Missing secret:
|
|
145
|
-
` Generated
|
|
146
|
-
`
|
|
149
|
+
`Missing secret: NATS_OPERATOR_SEED and/or NATS_ACCOUNT_SEED\n` +
|
|
150
|
+
` Generated a pair for you — add both to your environment's secrets.yaml and re-run:\n\n` +
|
|
151
|
+
` NATS_OPERATOR_SEED: ${opSeed}\n` +
|
|
152
|
+
` NATS_ACCOUNT_SEED: ${acSeed}\n`,
|
|
147
153
|
)
|
|
148
154
|
}
|
|
149
155
|
|
|
156
|
+
const operatorKP = fromSeed(new TextEncoder().encode(operatorSeed))
|
|
157
|
+
const accountKP = fromSeed(new TextEncoder().encode(accountSeed))
|
|
158
|
+
const accountPub = accountKP.getPublicKey()
|
|
159
|
+
|
|
160
|
+
const operatorJWT = await encodeOperator('zbc-operator', operatorKP)
|
|
161
|
+
const accountJWT = await encodeAccount('zbc-account', accountKP, {}, { signer: operatorKP })
|
|
162
|
+
|
|
150
163
|
let app = await flyFetch<FlyApp>(`/v1/apps/${config.appName}`, flyToken)
|
|
151
164
|
if (app) {
|
|
152
165
|
console.log(` Fly app "${config.appName}" already exists`)
|
|
@@ -162,11 +175,12 @@ export const natsServerModule = defineModule({
|
|
|
162
175
|
|
|
163
176
|
const machineConfig = {
|
|
164
177
|
image: 'nats:latest',
|
|
165
|
-
env: { NATS_PASSWORD: password },
|
|
166
178
|
files: [
|
|
167
179
|
{
|
|
168
180
|
guest_path: '/etc/nats/nats-server.conf',
|
|
169
|
-
raw_value: Buffer.from(renderConf(), 'utf8').toString(
|
|
181
|
+
raw_value: Buffer.from(renderConf(operatorJWT, accountPub, accountJWT), 'utf8').toString(
|
|
182
|
+
'base64',
|
|
183
|
+
),
|
|
170
184
|
},
|
|
171
185
|
],
|
|
172
186
|
init: { cmd: ['-c', '/etc/nats/nats-server.conf'] },
|
|
@@ -247,8 +261,8 @@ export const natsServerModule = defineModule({
|
|
|
247
261
|
|
|
248
262
|
return {
|
|
249
263
|
url: `wss://${config.appName}.fly.dev`,
|
|
250
|
-
|
|
251
|
-
|
|
264
|
+
accountPublicKey: accountPub,
|
|
265
|
+
accountSigningKey: accountSeed,
|
|
252
266
|
}
|
|
253
267
|
},
|
|
254
268
|
async destroy(config, ctx) {
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nats-server",
|
|
3
|
-
"description": "Self-hosted NATS pub/sub server on Fly.io (WebSocket,
|
|
3
|
+
"description": "Self-hosted NATS pub/sub server on Fly.io (WebSocket, scoped JWT auth via @nats-io operator/account chain)",
|
|
4
4
|
"files": [{ "path": "index.ts" }],
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"zod": "^3.24.0"
|
|
6
|
+
"zod": "^3.24.0",
|
|
7
|
+
"@nats-io/jwt": "^0.0.11",
|
|
8
|
+
"@nats-io/nkeys": "^2.0.3"
|
|
7
9
|
},
|
|
8
|
-
"secrets": ["FLY_API_TOKEN", "
|
|
10
|
+
"secrets": ["FLY_API_TOKEN", "NATS_OPERATOR_SEED", "NATS_ACCOUNT_SEED"],
|
|
9
11
|
"signupUrl": "https://fly.io/app/sign-up",
|
|
10
12
|
"tokenUrl": "https://fly.io/user/personal_access_tokens",
|
|
11
|
-
"instructions": "Add FLY_API_TOKEN
|
|
13
|
+
"instructions": "Add FLY_API_TOKEN to packages/infra/environments/<env>/secrets.yaml. NATS_OPERATOR_SEED and NATS_ACCOUNT_SEED are the root of the NATS decentralized auth chain — if you don't have them yet, run apply once and the module will generate a pair and print them; paste both into secrets.yaml and re-run. The module creates a Fly Machine running nats:latest with WebSocket on wss://<appName>.fly.dev and verifies JWTs locally (no network callbacks)."
|
|
12
14
|
}
|
|
@@ -27,10 +27,39 @@ jobs:
|
|
|
27
27
|
|
|
28
28
|
- run: bun install
|
|
29
29
|
|
|
30
|
-
- name: Apply preview
|
|
30
|
+
- name: Apply preview + comment URLs
|
|
31
31
|
env:
|
|
32
32
|
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
|
|
33
|
-
|
|
33
|
+
GH_TOKEN: ${{ github.token }}
|
|
34
|
+
run: |
|
|
35
|
+
set -o pipefail
|
|
36
|
+
OUTPUT=$(bunx @zabaca/zbc apply preview 2>&1)
|
|
37
|
+
STATUS=$?
|
|
38
|
+
echo "$OUTPUT"
|
|
39
|
+
|
|
40
|
+
# Pair each "Deployed:" URL with the most recent "→ vercel:<name>" header
|
|
41
|
+
LIST=$(echo "$OUTPUT" | awk '
|
|
42
|
+
/^→ vercel:/{name=$2; sub(/vercel:/, "", name)}
|
|
43
|
+
/Deployed:/{print "- **" name "**: " $NF}
|
|
44
|
+
')
|
|
45
|
+
|
|
46
|
+
if [ -z "$LIST" ]; then
|
|
47
|
+
LIST="(no deployments captured — see logs)"
|
|
48
|
+
fi
|
|
49
|
+
|
|
50
|
+
BODY=$(printf '### Preview deployed :rocket:\n\n%s\n' "$LIST")
|
|
51
|
+
|
|
52
|
+
# Update existing comment if present, else create a new one
|
|
53
|
+
EXISTING=$(gh api "repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \
|
|
54
|
+
--jq '.[] | select(.body | startswith("### Preview deployed")) | .id' | head -1)
|
|
55
|
+
|
|
56
|
+
if [ -n "$EXISTING" ]; then
|
|
57
|
+
gh api -X PATCH "repos/${{ github.repository }}/issues/comments/$EXISTING" -f body="$BODY"
|
|
58
|
+
else
|
|
59
|
+
gh pr comment ${{ github.event.pull_request.number }} --body "$BODY"
|
|
60
|
+
fi
|
|
61
|
+
|
|
62
|
+
exit $STATUS
|
|
34
63
|
|
|
35
64
|
cleanup:
|
|
36
65
|
if: github.event.action == 'closed'
|