@lunora/cli 1.0.0-alpha.22 → 1.0.0-alpha.24
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/dist/bin.mjs +1 -1
- package/dist/index.d.mts +33 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.mjs +2 -2
- package/dist/packem_chunks/handler.mjs +15 -5
- package/dist/packem_chunks/handler10.mjs +8 -14
- package/dist/packem_chunks/handler11.mjs +19 -189
- package/dist/packem_chunks/handler12.mjs +176 -115
- package/dist/packem_chunks/handler13.mjs +118 -52
- package/dist/packem_chunks/handler14.mjs +50 -43
- package/dist/packem_chunks/handler15.mjs +46 -67
- package/dist/packem_chunks/handler16.mjs +73 -37
- package/dist/packem_chunks/handler17.mjs +38 -100
- package/dist/packem_chunks/handler18.mjs +87 -152
- package/dist/packem_chunks/handler19.mjs +148 -67
- package/dist/packem_chunks/handler2.mjs +1 -1
- package/dist/packem_chunks/handler20.mjs +71 -76
- package/dist/packem_chunks/handler21.mjs +71 -288
- package/dist/packem_chunks/handler3.mjs +1 -1
- package/dist/packem_chunks/handler4.mjs +1 -1
- package/dist/packem_chunks/handler5.mjs +1 -1
- package/dist/packem_chunks/handler6.mjs +1 -1
- package/dist/packem_chunks/handler7.mjs +1 -1
- package/dist/packem_chunks/handler8.mjs +1 -1
- package/dist/packem_chunks/handler9.mjs +311 -12
- package/dist/packem_chunks/planDevCommand.mjs +2 -2
- package/dist/packem_chunks/runCodegenCommand.mjs +1 -1
- package/dist/packem_chunks/runDeployCommand.mjs +103 -13
- package/dist/packem_chunks/runInitCommand.mjs +44 -6
- package/dist/packem_chunks/runMigrateGenerateCommand.mjs +1 -1
- package/dist/packem_chunks/runResetCommand.mjs +2 -2
- package/dist/packem_chunks/runRpcCommand.mjs +1 -1
- package/dist/packem_shared/{COMMANDS-D3h9Iwvl.mjs → COMMANDS-B0ftFD_3.mjs} +20 -16
- package/dist/packem_shared/{command-BC30oSBW.mjs → command-D3lB_4Az.mjs} +5 -0
- package/dist/packem_shared/{commands-hl0mRqqg.mjs → commands-B-gR09Z_.mjs} +1 -1
- package/dist/packem_shared/prompt-cancelled-APzX1Im-.mjs +9 -0
- package/dist/packem_shared/{runAddCommand-vJdgiR5t.mjs → runAddCommand-bnY6-HKb.mjs} +1 -1
- package/dist/packem_shared/{storage-B7hHSTZP.mjs → storage-BIsph-Vk.mjs} +1 -1
- package/dist/packem_shared/{tui-prompts-M6OWsuyw.mjs → tui-prompts-BjEN8XgP.mjs} +2 -7
- package/dist/packem_shared/wrangler-secrets-P2_ZUR-k.mjs +47 -0
- package/package.json +3 -3
|
@@ -1,16 +1,315 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { writeFileSync, existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { DEV_VARS_FILE, DEV_VARS_KEY_PATTERN, generateSecretValue, DEV_VARS_EXAMPLE_FILE, parseDevVariableEntries, isPlaceholderValue, packageNamesFromBindings, inferLunoraBindings, requiredSecrets, isMintableSecretKey } from '@lunora/config';
|
|
4
|
+
import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
|
|
5
|
+
import { defaultSpawner } from '../packem_shared/createRecordingSpawner-DxI3mebw.mjs';
|
|
6
|
+
import { l as listRemoteSecrets } from '../packem_shared/wrangler-secrets-P2_ZUR-k.mjs';
|
|
4
7
|
|
|
5
|
-
const
|
|
6
|
-
|
|
8
|
+
const NEWLINE_PRESENT = /[\r\n]/u;
|
|
9
|
+
const UNREPRESENTABLE_PRESENT = /["\\]/u;
|
|
10
|
+
const parseDevVariables = (content) => {
|
|
11
|
+
const map = /* @__PURE__ */ new Map();
|
|
12
|
+
for (const entry of parseDevVariableEntries(content)) {
|
|
13
|
+
map.set(entry.key, entry);
|
|
14
|
+
}
|
|
15
|
+
return map;
|
|
16
|
+
};
|
|
17
|
+
const serializeDevVariables = (map) => {
|
|
18
|
+
const lines = [];
|
|
19
|
+
for (const entry of map.values()) {
|
|
20
|
+
lines.push(`${entry.key}="${entry.value}"`);
|
|
21
|
+
}
|
|
22
|
+
return `${lines.join("\n")}
|
|
23
|
+
`;
|
|
24
|
+
};
|
|
25
|
+
const redact = (value) => {
|
|
26
|
+
if (value.length <= 4) {
|
|
27
|
+
return "****";
|
|
28
|
+
}
|
|
29
|
+
return `${value.slice(0, 4)}${"*".repeat(Math.min(8, value.length - 4))}`;
|
|
30
|
+
};
|
|
31
|
+
const loadDevVariables = (devVariablesPath) => {
|
|
32
|
+
if (!existsSync(devVariablesPath)) {
|
|
33
|
+
return /* @__PURE__ */ new Map();
|
|
34
|
+
}
|
|
35
|
+
return parseDevVariables(readFileSync(devVariablesPath, "utf8"));
|
|
36
|
+
};
|
|
37
|
+
const runEnvList = (context) => {
|
|
38
|
+
const map = loadDevVariables(context.devVariablesPath);
|
|
39
|
+
if (map.size === 0) {
|
|
40
|
+
context.logger.info(`${DEV_VARS_FILE}: (empty)`);
|
|
41
|
+
return { code: 0, descriptors: [] };
|
|
42
|
+
}
|
|
43
|
+
for (const entry of map.values()) {
|
|
44
|
+
context.logger.info(`${entry.key}=${redact(entry.value)}`);
|
|
45
|
+
}
|
|
46
|
+
return { code: 0, descriptors: [] };
|
|
47
|
+
};
|
|
48
|
+
const runEnvGet = (context) => {
|
|
49
|
+
const { devVariablesPath, logger, options } = context;
|
|
50
|
+
if (!options.key) {
|
|
51
|
+
logger.error("env get requires a key. Usage: lunora env get <KEY>");
|
|
52
|
+
return { code: 1, descriptors: [] };
|
|
53
|
+
}
|
|
54
|
+
const entry = loadDevVariables(devVariablesPath).get(options.key);
|
|
55
|
+
if (!entry) {
|
|
56
|
+
logger.error(`env: ${options.key} is not set in ${DEV_VARS_FILE}`);
|
|
57
|
+
return { code: 1, descriptors: [] };
|
|
58
|
+
}
|
|
59
|
+
process.stdout.write(`${entry.value}
|
|
60
|
+
`);
|
|
61
|
+
return { code: 0, descriptors: [] };
|
|
62
|
+
};
|
|
63
|
+
const runEnvSet = (context) => {
|
|
64
|
+
const { devVariablesPath, logger, options } = context;
|
|
65
|
+
if (!options.key) {
|
|
66
|
+
logger.error("env set requires a key. Usage: lunora env set <KEY> <VALUE>");
|
|
67
|
+
return { code: 1, descriptors: [] };
|
|
68
|
+
}
|
|
69
|
+
if (!DEV_VARS_KEY_PATTERN.test(options.key)) {
|
|
70
|
+
logger.error(`env: invalid key "${options.key}" — must match [A-Za-z_][A-Za-z0-9_]*`);
|
|
71
|
+
return { code: 1, descriptors: [] };
|
|
72
|
+
}
|
|
73
|
+
if (options.value === void 0) {
|
|
74
|
+
logger.error("env set requires a value. Usage: lunora env set <KEY> <VALUE>");
|
|
75
|
+
return { code: 1, descriptors: [] };
|
|
76
|
+
}
|
|
77
|
+
if (NEWLINE_PRESENT.test(options.value)) {
|
|
78
|
+
logger.error(`env: value for "${options.key}" contains a newline, which .dev.vars cannot represent`);
|
|
79
|
+
return { code: 1, descriptors: [] };
|
|
80
|
+
}
|
|
81
|
+
if (UNREPRESENTABLE_PRESENT.test(options.value)) {
|
|
82
|
+
logger.error(`env: value for "${options.key}" contains a double-quote or backslash, which .dev.vars cannot round-trip`);
|
|
83
|
+
return { code: 1, descriptors: [] };
|
|
84
|
+
}
|
|
85
|
+
const map = loadDevVariables(devVariablesPath);
|
|
86
|
+
map.set(options.key, { key: options.key, value: options.value });
|
|
87
|
+
writeFileSync(devVariablesPath, serializeDevVariables(map), "utf8");
|
|
88
|
+
logger.success(`env: set ${options.key} (${redact(options.value)}) in ${DEV_VARS_FILE}`);
|
|
89
|
+
return { code: 0, descriptors: [] };
|
|
90
|
+
};
|
|
91
|
+
const runEnvUnset = (context) => {
|
|
92
|
+
const { devVariablesPath, logger, options } = context;
|
|
93
|
+
if (!options.key) {
|
|
94
|
+
logger.error("env unset requires a key. Usage: lunora env unset <KEY>");
|
|
95
|
+
return { code: 1, descriptors: [] };
|
|
96
|
+
}
|
|
97
|
+
const map = loadDevVariables(devVariablesPath);
|
|
98
|
+
if (!map.delete(options.key)) {
|
|
99
|
+
logger.warn(`env: ${options.key} was not set in ${DEV_VARS_FILE}`);
|
|
100
|
+
return { code: 0, descriptors: [] };
|
|
101
|
+
}
|
|
102
|
+
writeFileSync(devVariablesPath, serializeDevVariables(map), "utf8");
|
|
103
|
+
logger.success(`env: unset ${options.key} in ${DEV_VARS_FILE}`);
|
|
104
|
+
return { code: 0, descriptors: [] };
|
|
105
|
+
};
|
|
106
|
+
const runEnvPush = async (context) => {
|
|
107
|
+
const { devVariablesPath, logger, options } = context;
|
|
108
|
+
if (!options.yes) {
|
|
109
|
+
logger.error("env push uploads secrets to Cloudflare. Re-run with --yes to confirm.");
|
|
110
|
+
return { code: 1, descriptors: [] };
|
|
111
|
+
}
|
|
112
|
+
const map = loadDevVariables(devVariablesPath);
|
|
113
|
+
if (map.size === 0) {
|
|
114
|
+
logger.warn(`${DEV_VARS_FILE}: nothing to push (empty)`);
|
|
115
|
+
return { code: 0, descriptors: [] };
|
|
116
|
+
}
|
|
117
|
+
const spawner = options.spawner ?? defaultSpawner;
|
|
118
|
+
const descriptors = [];
|
|
119
|
+
for (const entry of map.values()) {
|
|
120
|
+
const args = ["exec", "wrangler", "secret", "put", entry.key];
|
|
121
|
+
if (options.prod) {
|
|
122
|
+
args.push("--env", "production");
|
|
123
|
+
}
|
|
124
|
+
if (options.temporary) {
|
|
125
|
+
args.push("--temporary");
|
|
126
|
+
}
|
|
127
|
+
const descriptor = {
|
|
128
|
+
args,
|
|
129
|
+
command: "pnpm",
|
|
130
|
+
cwd: options.cwd ?? process.cwd(),
|
|
131
|
+
// `wrangler secret put <name>` reads the value from stdin. We
|
|
132
|
+
// pipe it through the spawner's `input` channel so the secret
|
|
133
|
+
// never lands on the command line, in env, or in shell history.
|
|
134
|
+
input: entry.value
|
|
135
|
+
};
|
|
136
|
+
descriptors.push(descriptor);
|
|
137
|
+
logger.info(`pushing ${entry.key} -> wrangler secret${options.prod ? " (production)" : ""}`);
|
|
138
|
+
const result = await spawner(descriptor);
|
|
139
|
+
if (result.code !== 0) {
|
|
140
|
+
logger.error(`env push: failed at ${entry.key} (exit ${String(result.code)})`);
|
|
141
|
+
return { code: result.code, descriptors };
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
logger.success(`env: pushed ${String(map.size)} secret(s)`);
|
|
145
|
+
return { code: 0, descriptors };
|
|
146
|
+
};
|
|
147
|
+
const fetchRemoteSecretNames = (context) => {
|
|
148
|
+
const lister = context.options.secretLister ?? listRemoteSecrets;
|
|
149
|
+
return lister({
|
|
150
|
+
cwd: context.cwd,
|
|
151
|
+
env: context.options.prod ? "production" : void 0,
|
|
152
|
+
temporary: context.options.temporary
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
const runEnvDiff = async (context) => {
|
|
156
|
+
const { devVariablesPath, logger } = context;
|
|
157
|
+
const remote = await fetchRemoteSecretNames(context);
|
|
158
|
+
if (!remote.ok) {
|
|
159
|
+
logger.error(`env diff: ${remote.error ?? "failed to list remote secrets"}`);
|
|
160
|
+
return { code: 1, descriptors: [] };
|
|
161
|
+
}
|
|
162
|
+
const localKeys = new Set(loadDevVariables(devVariablesPath).keys());
|
|
163
|
+
const remoteKeys = new Set(remote.names);
|
|
164
|
+
const localOnly = [...localKeys].filter((key) => !remoteKeys.has(key)).toSorted((a, b) => a.localeCompare(b));
|
|
165
|
+
const remoteOnly = remote.names.filter((name) => !localKeys.has(name));
|
|
166
|
+
const both = [...localKeys].filter((key) => remoteKeys.has(key)).toSorted((a, b) => a.localeCompare(b));
|
|
167
|
+
for (const key of localOnly) {
|
|
168
|
+
logger.info(`local only (run \`lunora env push\`): ${key}`);
|
|
169
|
+
}
|
|
170
|
+
for (const key of remoteOnly) {
|
|
171
|
+
logger.info(`remote only (in Cloudflare, not ${DEV_VARS_FILE}): ${key}`);
|
|
172
|
+
}
|
|
173
|
+
logger.info(`in both: ${String(both.length)} secret(s)`);
|
|
174
|
+
if (localOnly.length === 0 && remoteOnly.length === 0) {
|
|
175
|
+
logger.success("env diff: local and remote secret names match");
|
|
176
|
+
}
|
|
177
|
+
return { code: 0, descriptors: [] };
|
|
178
|
+
};
|
|
179
|
+
const runEnvDoctor = (context) => {
|
|
180
|
+
const { cwd, devVariablesPath, logger } = context;
|
|
181
|
+
const examplePath = join(cwd, DEV_VARS_EXAMPLE_FILE);
|
|
182
|
+
if (!existsSync(examplePath)) {
|
|
183
|
+
logger.info(`env doctor: no ${DEV_VARS_EXAMPLE_FILE} to check against — nothing to validate.`);
|
|
184
|
+
return { code: 0, descriptors: [] };
|
|
185
|
+
}
|
|
186
|
+
const exampleKeys = parseDevVariableEntries(readFileSync(examplePath, "utf8")).map((entry) => entry.key);
|
|
187
|
+
const current = loadDevVariables(devVariablesPath);
|
|
188
|
+
if (!existsSync(devVariablesPath)) {
|
|
189
|
+
logger.error(`env doctor: ${DEV_VARS_FILE} is missing. Run \`lunora dev\` to scaffold it, or \`lunora env set <KEY> <VALUE>\`.`);
|
|
190
|
+
logger.info(`expected (from ${DEV_VARS_EXAMPLE_FILE}): ${exampleKeys.join(", ")}`);
|
|
191
|
+
return { code: 1, descriptors: [] };
|
|
192
|
+
}
|
|
193
|
+
const missing = exampleKeys.filter((key) => !current.has(key));
|
|
194
|
+
const placeholders = [...current.values()].filter((entry) => isPlaceholderValue(entry.value)).map((entry) => entry.key);
|
|
195
|
+
const exampleKeySet = new Set(exampleKeys);
|
|
196
|
+
const extra = [...current.keys()].filter((key) => !exampleKeySet.has(key));
|
|
197
|
+
for (const key of missing) {
|
|
198
|
+
logger.error(`missing: ${key} is in ${DEV_VARS_EXAMPLE_FILE} but not ${DEV_VARS_FILE}`);
|
|
199
|
+
}
|
|
200
|
+
for (const key of placeholders) {
|
|
201
|
+
logger.error(`unset: ${key} still has a placeholder value`);
|
|
202
|
+
}
|
|
203
|
+
for (const key of extra) {
|
|
204
|
+
logger.info(`extra: ${key} is set locally but not listed in ${DEV_VARS_EXAMPLE_FILE}`);
|
|
205
|
+
}
|
|
206
|
+
if (missing.length === 0 && placeholders.length === 0) {
|
|
207
|
+
logger.success(`env doctor: ${DEV_VARS_FILE} looks good (${String(current.size)} var(s)).`);
|
|
208
|
+
return { code: 0, descriptors: [] };
|
|
209
|
+
}
|
|
210
|
+
return { code: 1, descriptors: [] };
|
|
211
|
+
};
|
|
212
|
+
const resolveMintableKeys = async (context) => {
|
|
213
|
+
let packages = [];
|
|
214
|
+
try {
|
|
215
|
+
packages = packageNamesFromBindings(await inferLunoraBindings({ projectRoot: context.cwd }));
|
|
216
|
+
} catch {
|
|
217
|
+
}
|
|
218
|
+
const fromPackages = requiredSecrets(packages).map((entry) => entry.key).filter((key) => isMintableSecretKey(key));
|
|
219
|
+
const fromLocal = [...loadDevVariables(context.devVariablesPath).keys()].filter((key) => isMintableSecretKey(key));
|
|
220
|
+
return [.../* @__PURE__ */ new Set([...fromPackages, ...fromLocal])];
|
|
221
|
+
};
|
|
222
|
+
const runEnvGenerate = async (context) => {
|
|
223
|
+
const { devVariablesPath, logger, options } = context;
|
|
224
|
+
let keys;
|
|
225
|
+
if (options.key === void 0) {
|
|
226
|
+
keys = await resolveMintableKeys(context);
|
|
227
|
+
if (keys.length === 0) {
|
|
228
|
+
logger.info("env generate: no locally-generatable secrets for this project. Name one explicitly: lunora env generate <KEY>");
|
|
229
|
+
return { code: 0, descriptors: [] };
|
|
230
|
+
}
|
|
231
|
+
} else {
|
|
232
|
+
if (!DEV_VARS_KEY_PATTERN.test(options.key)) {
|
|
233
|
+
logger.error(`env: invalid key "${options.key}" — must match [A-Za-z_][A-Za-z0-9_]*`);
|
|
234
|
+
return { code: 1, descriptors: [] };
|
|
235
|
+
}
|
|
236
|
+
keys = [options.key];
|
|
237
|
+
}
|
|
238
|
+
const generated = keys.map((key) => {
|
|
239
|
+
return { key, value: generateSecretValue() };
|
|
240
|
+
});
|
|
241
|
+
if (options.set === true) {
|
|
242
|
+
const map = loadDevVariables(devVariablesPath);
|
|
243
|
+
for (const entry of generated) {
|
|
244
|
+
map.set(entry.key, entry);
|
|
245
|
+
}
|
|
246
|
+
writeFileSync(devVariablesPath, serializeDevVariables(map), "utf8");
|
|
247
|
+
logger.success(`env: generated ${String(generated.length)} secret(s) into ${DEV_VARS_FILE}: ${generated.map((entry) => entry.key).join(", ")}`);
|
|
248
|
+
return { code: 0, descriptors: [] };
|
|
249
|
+
}
|
|
250
|
+
for (const entry of generated) {
|
|
251
|
+
process.stdout.write(`${entry.key}=${entry.value}
|
|
252
|
+
`);
|
|
253
|
+
}
|
|
254
|
+
return { code: 0, descriptors: [] };
|
|
255
|
+
};
|
|
256
|
+
const runEnvCommand = async (options) => {
|
|
257
|
+
const cwd = options.cwd ?? process.cwd();
|
|
258
|
+
const context = {
|
|
259
|
+
cwd,
|
|
260
|
+
devVariablesPath: join(cwd, DEV_VARS_FILE),
|
|
261
|
+
logger: options.logger,
|
|
262
|
+
options
|
|
263
|
+
};
|
|
264
|
+
switch (options.subcommand) {
|
|
265
|
+
case "diff": {
|
|
266
|
+
return runEnvDiff(context);
|
|
267
|
+
}
|
|
268
|
+
case "doctor": {
|
|
269
|
+
return runEnvDoctor(context);
|
|
270
|
+
}
|
|
271
|
+
case "generate": {
|
|
272
|
+
return runEnvGenerate(context);
|
|
273
|
+
}
|
|
274
|
+
case "get": {
|
|
275
|
+
return runEnvGet(context);
|
|
276
|
+
}
|
|
277
|
+
case "list": {
|
|
278
|
+
return runEnvList(context);
|
|
279
|
+
}
|
|
280
|
+
case "push": {
|
|
281
|
+
return runEnvPush(context);
|
|
282
|
+
}
|
|
283
|
+
case "set": {
|
|
284
|
+
return runEnvSet(context);
|
|
285
|
+
}
|
|
286
|
+
case "unset": {
|
|
287
|
+
return runEnvUnset(context);
|
|
288
|
+
}
|
|
289
|
+
default: {
|
|
290
|
+
options.logger.error(`env: unknown subcommand "${options.subcommand}"`);
|
|
291
|
+
return { code: 1, descriptors: [] };
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
const isEnvSubcommand = (value) => value === "list" || value === "get" || value === "set" || value === "unset" || value === "push" || value === "diff" || value === "doctor" || value === "generate";
|
|
296
|
+
const execute = defineHandler(({ argument, cwd, logger, options }) => {
|
|
297
|
+
const sub = argument[0];
|
|
298
|
+
if (!isEnvSubcommand(sub)) {
|
|
299
|
+
logger.error(`env: unknown subcommand "${sub ?? ""}" — expected list | get | set | unset | push | diff | doctor | generate`);
|
|
300
|
+
return { code: 1 };
|
|
301
|
+
}
|
|
302
|
+
return runEnvCommand({
|
|
303
|
+
cwd,
|
|
304
|
+
key: argument[1],
|
|
7
305
|
logger,
|
|
8
|
-
out: argument[0] ?? options.out,
|
|
9
306
|
prod: options.prod === true,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
307
|
+
set: options.set === true,
|
|
308
|
+
subcommand: sub,
|
|
309
|
+
temporary: options.temporary === true,
|
|
310
|
+
value: argument[2],
|
|
311
|
+
yes: options.yes === true
|
|
312
|
+
});
|
|
313
|
+
});
|
|
15
314
|
|
|
16
|
-
export { execute };
|
|
315
|
+
export { execute, runEnvCommand };
|
|
@@ -4,12 +4,12 @@ import { p as parseApiSpec } from '../packem_shared/api-spec-CtA6ilu4.mjs';
|
|
|
4
4
|
import { existsSync, watch } from 'node:fs';
|
|
5
5
|
import { join } from 'node:path';
|
|
6
6
|
import { runCodegen } from '@lunora/codegen';
|
|
7
|
-
import { d as defineHandler } from '../packem_shared/command-
|
|
7
|
+
import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
|
|
8
8
|
import { d as detectPackageManager, e as execArgsFor } from '../packem_shared/detect-package-manager-DYp7n3mJ.mjs';
|
|
9
9
|
import { createServer, request } from 'node:http';
|
|
10
10
|
import { connect } from 'node:net';
|
|
11
11
|
import { loadStudioAssets, studioAssetsStamp, renderStudioHtml, resolveAdminToken, SCHEMA_EDIT_ENDPOINT, POLICY_SCAFFOLD_ENDPOINT, SEED_ENDPOINT, serveJsonHandler, handleSchemaEditRequest, handlePolicyScaffoldRequest, handleSeedRequest } from '@lunora/config/studio-host';
|
|
12
|
-
import { c as createTuiConfirm } from '../packem_shared/tui-prompts-
|
|
12
|
+
import { c as createTuiConfirm } from '../packem_shared/tui-prompts-BjEN8XgP.mjs';
|
|
13
13
|
|
|
14
14
|
const DEFAULT_DEBOUNCE_MS = 100;
|
|
15
15
|
const PATH_SEGMENT_SEPARATOR = /[/\\]/u;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { runCodegen } from '@lunora/codegen';
|
|
2
2
|
import { p as parseApiSpec } from '../packem_shared/api-spec-CtA6ilu4.mjs';
|
|
3
|
-
import { d as defineHandler } from '../packem_shared/command-
|
|
3
|
+
import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
|
|
4
4
|
import { v as validateOutputFormat, p as printJson, l as loggerForFormat, i as isJsonFormat } from '../packem_shared/output-format-wUvAN6AL.mjs';
|
|
5
5
|
|
|
6
6
|
const CRON_TRIGGER_LIMIT = 3;
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { runCodegen, discoverMigrations } from '@lunora/codegen';
|
|
3
|
-
import { readLinkedProject, writeLinkedProject, validateWranglerProject, inferLunoraBindings, reconcileWranglerBindings, DEV_VARS_FILE, parseDevVariableEntries, findWranglerFile, readWranglerJsonc, discoverContainerInfo } from '@lunora/config';
|
|
3
|
+
import { readLinkedProject, writeLinkedProject, validateWranglerProject, inferLunoraBindings, reconcileWranglerBindings, DEV_VARS_FILE, parseDevVariableEntries, isMintableSecretKey, findWranglerFile, readWranglerJsonc, discoverContainerInfo, packageNamesFromBindings, requiredSecrets, generateSecretValue } from '@lunora/config';
|
|
4
4
|
import { join } from '@visulima/path';
|
|
5
5
|
import { Spinner } from '@visulima/spinner';
|
|
6
6
|
import { Project } from 'ts-morph';
|
|
7
7
|
import { p as parseApiSpec } from '../packem_shared/api-spec-CtA6ilu4.mjs';
|
|
8
8
|
import { r as readWranglerName } from '../packem_shared/wrangler-name-cy4yhm9j.mjs';
|
|
9
|
-
import { d as defineHandler } from '../packem_shared/command-
|
|
9
|
+
import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
|
|
10
10
|
import { a as isRailpackAvailable, i as isDockerAvailable } from '../packem_shared/docker-hMQ97KSQ.mjs';
|
|
11
11
|
import { v as validateOutputFormat, i as isJsonFormat, p as printJson, l as loggerForFormat } from '../packem_shared/output-format-wUvAN6AL.mjs';
|
|
12
12
|
import { containerBuildTag } from '@lunora/container';
|
|
13
13
|
import { defaultSpawner } from '../packem_shared/createRecordingSpawner-DxI3mebw.mjs';
|
|
14
14
|
import { r as resolveWorkerUrl } from '../packem_shared/resolve-target-qbsJ_5sF.mjs';
|
|
15
15
|
import { r as runSchemaDriftGate } from '../packem_shared/schema-drift-gate-BtBt0as0.mjs';
|
|
16
|
+
import { c as createTuiConfirm } from '../packem_shared/tui-prompts-BjEN8XgP.mjs';
|
|
17
|
+
import { l as listRemoteSecrets } from '../packem_shared/wrangler-secrets-P2_ZUR-k.mjs';
|
|
16
18
|
import { runMigrateDataCommand } from './runMigrateGenerateCommand.mjs';
|
|
17
19
|
|
|
18
20
|
const WORKERS_DEV_URL = /https?:\/\/[^\s"'<>]+\.workers\.dev[^\s"'<>]*/u;
|
|
@@ -210,6 +212,88 @@ const warnDevVariablesNotPushed = (cwd, logger) => {
|
|
|
210
212
|
`Note: \`lunora deploy\` does not push secrets. ${DEV_VARS_FILE} has ${String(keyCount)} key(s); if you changed them, run \`lunora env push --yes\` to update the deployed secrets.`
|
|
211
213
|
);
|
|
212
214
|
};
|
|
215
|
+
const SECRET_LIKE_KEY = /(?:KEY|PASSWORD|SECRET|TOKEN)$/u;
|
|
216
|
+
const resolveRequiredSecretKeys = async (cwd) => {
|
|
217
|
+
let packages = [];
|
|
218
|
+
try {
|
|
219
|
+
packages = packageNamesFromBindings(await inferLunoraBindings({ projectRoot: cwd }));
|
|
220
|
+
} catch {
|
|
221
|
+
}
|
|
222
|
+
const fromPackages = requiredSecrets(packages).map((entry) => entry.key);
|
|
223
|
+
let fromLocal = [];
|
|
224
|
+
try {
|
|
225
|
+
const devVariablesPath = join(cwd, DEV_VARS_FILE);
|
|
226
|
+
if (existsSync(devVariablesPath)) {
|
|
227
|
+
fromLocal = parseDevVariableEntries(readFileSync(devVariablesPath, "utf8")).map((entry) => entry.key).filter((key) => SECRET_LIKE_KEY.test(key));
|
|
228
|
+
}
|
|
229
|
+
} catch {
|
|
230
|
+
}
|
|
231
|
+
return [.../* @__PURE__ */ new Set([...fromPackages, ...fromLocal])];
|
|
232
|
+
};
|
|
233
|
+
const pushMintableSecrets = async (cwd, options, keys) => {
|
|
234
|
+
const { logger } = options;
|
|
235
|
+
const spawner = options.spawner ?? defaultSpawner;
|
|
236
|
+
const environmentFlag = options.env === void 0 ? "" : ` --env ${options.env}`;
|
|
237
|
+
for (const key of keys) {
|
|
238
|
+
const args = ["exec", "wrangler", "secret", "put", key];
|
|
239
|
+
if (options.env !== void 0) {
|
|
240
|
+
args.push("--env", options.env);
|
|
241
|
+
}
|
|
242
|
+
if (options.temporary === true) {
|
|
243
|
+
args.push("--temporary");
|
|
244
|
+
}
|
|
245
|
+
const pushResult = await spawner({ args, command: "pnpm", cwd, input: generateSecretValue() });
|
|
246
|
+
if (pushResult.code !== 0) {
|
|
247
|
+
logger.error(
|
|
248
|
+
`failed to push secret ${key} (exit ${String(pushResult.code)}); set it manually with \`wrangler secret put ${key}${environmentFlag}\`.`
|
|
249
|
+
);
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
logger.success(`generated + pushed ${key}`);
|
|
253
|
+
}
|
|
254
|
+
return true;
|
|
255
|
+
};
|
|
256
|
+
const offerMissingSecrets = async (cwd, options, interactive) => {
|
|
257
|
+
if (options.dryRun === true || options.preview === true) {
|
|
258
|
+
return void 0;
|
|
259
|
+
}
|
|
260
|
+
const { logger } = options;
|
|
261
|
+
const environmentFlag = options.env === void 0 ? "" : ` --env ${options.env}`;
|
|
262
|
+
let remote;
|
|
263
|
+
try {
|
|
264
|
+
remote = await (options.secretLister ?? listRemoteSecrets)({ cwd, env: options.env, temporary: options.temporary });
|
|
265
|
+
} catch {
|
|
266
|
+
return void 0;
|
|
267
|
+
}
|
|
268
|
+
if (!remote.ok) {
|
|
269
|
+
return void 0;
|
|
270
|
+
}
|
|
271
|
+
const remoteNames = new Set(remote.names);
|
|
272
|
+
const required = await resolveRequiredSecretKeys(cwd);
|
|
273
|
+
const missing = required.filter((key) => !remoteNames.has(key));
|
|
274
|
+
if (missing.length === 0) {
|
|
275
|
+
return void 0;
|
|
276
|
+
}
|
|
277
|
+
if (!interactive) {
|
|
278
|
+
return `missing required secret(s) on the deploy target: ${missing.join(", ")}. Set them with \`wrangler secret put <KEY>${environmentFlag}\` (or \`lunora env generate --set\` then \`lunora env push --yes${options.env === void 0 ? "" : " --prod"}\`), then re-deploy.`;
|
|
279
|
+
}
|
|
280
|
+
for (const key of missing.filter((name) => !isMintableSecretKey(name))) {
|
|
281
|
+
logger.warn(`required secret ${key} is not set on the target — set it with: wrangler secret put ${key}${environmentFlag}`);
|
|
282
|
+
}
|
|
283
|
+
const mintable = missing.filter((key) => isMintableSecretKey(key));
|
|
284
|
+
if (mintable.length === 0) {
|
|
285
|
+
return void 0;
|
|
286
|
+
}
|
|
287
|
+
const confirm = options.secretConfirm ?? createTuiConfirm();
|
|
288
|
+
if (await confirm(`${String(mintable.length)} required secret(s) not set on the target (${mintable.join(", ")}). Generate strong values and push them now?`)) {
|
|
289
|
+
await pushMintableSecrets(cwd, options, mintable);
|
|
290
|
+
return void 0;
|
|
291
|
+
}
|
|
292
|
+
logger.warn(
|
|
293
|
+
`${String(mintable.length)} required secret(s) not set on the target: ${mintable.join(", ")}. Generate + push with \`lunora env generate --set\` then \`lunora env push --yes${options.env === void 0 ? "" : " --prod"}\`.`
|
|
294
|
+
);
|
|
295
|
+
return void 0;
|
|
296
|
+
};
|
|
213
297
|
const runPostDeployMigrations = async (options, cwd) => {
|
|
214
298
|
const project = new Project({ skipAddingFilesFromTsConfig: true });
|
|
215
299
|
const lunoraDirectory = join(cwd, "lunora");
|
|
@@ -375,6 +459,16 @@ const buildWranglerDeployArgs = (cwd, options) => {
|
|
|
375
459
|
}
|
|
376
460
|
return args;
|
|
377
461
|
};
|
|
462
|
+
const reportWranglerProblems = (validation, logger) => {
|
|
463
|
+
if (validation.problems.length === 0) {
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
logger.error("wrangler.jsonc validation failed:");
|
|
467
|
+
for (const problem of validation.problems) {
|
|
468
|
+
logger.error(` - ${problem}`);
|
|
469
|
+
}
|
|
470
|
+
return true;
|
|
471
|
+
};
|
|
378
472
|
const executeDeploy = async (options) => {
|
|
379
473
|
const cwd = options.cwd ?? process.cwd();
|
|
380
474
|
const interactive = isInteractive(options);
|
|
@@ -420,19 +514,15 @@ const executeDeploy = async (options) => {
|
|
|
420
514
|
return { code: 1, descriptor: void 0, error: preflightError, validation: { problems: [], wranglerPath: void 0 } };
|
|
421
515
|
}
|
|
422
516
|
const validation = validateWranglerProject({ projectRoot: cwd });
|
|
423
|
-
if (validation.
|
|
424
|
-
|
|
425
|
-
for (const problem of validation.problems) {
|
|
426
|
-
options.logger.error(` - ${problem}`);
|
|
427
|
-
}
|
|
428
|
-
return {
|
|
429
|
-
code: 1,
|
|
430
|
-
descriptor: void 0,
|
|
431
|
-
error: "wrangler validation failed",
|
|
432
|
-
validation
|
|
433
|
-
};
|
|
517
|
+
if (reportWranglerProblems(validation, options.logger)) {
|
|
518
|
+
return { code: 1, descriptor: void 0, error: "wrangler validation failed", validation };
|
|
434
519
|
}
|
|
435
520
|
warnDevVariablesNotPushed(cwd, options.logger);
|
|
521
|
+
const secretAbort = await offerMissingSecrets(cwd, options, interactive);
|
|
522
|
+
if (secretAbort !== void 0) {
|
|
523
|
+
options.logger.error(secretAbort);
|
|
524
|
+
return { code: 1, descriptor: void 0, error: secretAbort, validation };
|
|
525
|
+
}
|
|
436
526
|
const shouldAutoLink = !isJsonFormat(options.format) && options.dryRun !== true && options.preview !== true && readLinkedProject(cwd) === void 0;
|
|
437
527
|
const descriptor = {
|
|
438
528
|
args: buildWranglerDeployArgs(cwd, options),
|
|
@@ -6,15 +6,16 @@ import { join as join$1, dirname as dirname$1, basename, resolve, relative } fro
|
|
|
6
6
|
import { downloadTemplate } from 'giget';
|
|
7
7
|
import { modify, applyEdits } from 'jsonc-parser';
|
|
8
8
|
import { join, dirname } from 'node:path';
|
|
9
|
-
import { d as defineHandler } from '../packem_shared/command-
|
|
9
|
+
import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
|
|
10
10
|
import { a as detectInstalledManagers, i as installArgsFor } from '../packem_shared/detect-package-manager-DYp7n3mJ.mjs';
|
|
11
11
|
import MagicString from 'magic-string';
|
|
12
12
|
import { Project, SyntaxKind } from 'ts-morph';
|
|
13
|
-
import {
|
|
13
|
+
import { P as PromptCancelledError } from '../packem_shared/prompt-cancelled-APzX1Im-.mjs';
|
|
14
|
+
import { c as resolveTagVersions, d as resolveSourceRef, e as resolveDistTag, r as runAddCommand } from '../packem_shared/commands-B-gR09Z_.mjs';
|
|
14
15
|
import { defaultSpawner } from '../packem_shared/createRecordingSpawner-DxI3mebw.mjs';
|
|
15
|
-
import { d as tuiMascot, e as tuiStep,
|
|
16
|
+
import { d as tuiMascot, e as tuiStep, f as tuiMoonrise, t as tuiText, g as tuiHeadline, h as tuiInfo, a as tuiSelect, b as tuiConfirm, w as withTuiSpinner, i as tuiNextSteps, j as tuiTasks, k as tuiMultiSelect, l as withTuiBadgeProgress } from '../packem_shared/tui-prompts-BjEN8XgP.mjs';
|
|
16
17
|
import { logStep } from '../packem_shared/createLogger-B40gPzQo.mjs';
|
|
17
|
-
import { E as EMAIL_ITEM, p as promptBucketName, w as withStorageBucketName, M as MAIL_DESTINATION_PROMPT, r as resolveTypedDestination, f as withMailDestination, e as promptAuthProvider, c as promptDatabaseName, g as withAuthDatabaseName } from '../packem_shared/storage-
|
|
18
|
+
import { E as EMAIL_ITEM, p as promptBucketName, w as withStorageBucketName, M as MAIL_DESTINATION_PROMPT, r as resolveTypedDestination, f as withMailDestination, e as promptAuthProvider, c as promptDatabaseName, g as withAuthDatabaseName } from '../packem_shared/storage-BIsph-Vk.mjs';
|
|
18
19
|
import dns from 'node:dns/promises';
|
|
19
20
|
|
|
20
21
|
const GITHUB_CONTENT = `name: Deploy
|
|
@@ -287,6 +288,36 @@ const patchViteConfig = (source) => {
|
|
|
287
288
|
return { changed: true, code: ms.toString() };
|
|
288
289
|
};
|
|
289
290
|
|
|
291
|
+
const NETWORK_ERROR_PATTERN = /enotfound|eai_again|econnrefused|etimedout|network|fetch failed|getaddrinfo/u;
|
|
292
|
+
const NOT_FOUND_ERROR_PATTERN = /404|not found|could not find|no such/u;
|
|
293
|
+
const describeDownloadFailure = (error, context) => {
|
|
294
|
+
const raw = error instanceof Error ? error.message : String(error);
|
|
295
|
+
const lower = raw.toLowerCase();
|
|
296
|
+
const genericMessage = `failed to download template "${context.templateType}" from ${context.remote}: ${raw}`;
|
|
297
|
+
if (NOT_FOUND_ERROR_PATTERN.test(lower)) {
|
|
298
|
+
return {
|
|
299
|
+
hints: [
|
|
300
|
+
`Check the template name "${context.templateType}" and the ref "${context.ref}".`,
|
|
301
|
+
"List/inspect available templates, or target a branch/tag with `--ref <branch>`."
|
|
302
|
+
],
|
|
303
|
+
message: `template "${context.templateType}" not found at ${context.remote}: ${raw}`
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
if (NETWORK_ERROR_PATTERN.test(lower)) {
|
|
307
|
+
return {
|
|
308
|
+
hints: [
|
|
309
|
+
"You appear to be offline or unable to reach GitHub.",
|
|
310
|
+
"To scaffold without a network, point at a local template root: `lunora init --from <dir>`."
|
|
311
|
+
],
|
|
312
|
+
message: genericMessage
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
return {
|
|
316
|
+
hints: ["If this is a network/offline issue, scaffold from a local root with `lunora init --from <dir>`."],
|
|
317
|
+
message: genericMessage
|
|
318
|
+
};
|
|
319
|
+
};
|
|
320
|
+
|
|
290
321
|
const emitStep = async (type, message, answer) => {
|
|
291
322
|
if (isInteractive()) {
|
|
292
323
|
await tuiStep(BADGES[type], message, answer);
|
|
@@ -2036,8 +2067,15 @@ const scaffoldFromRemote = async (options) => {
|
|
|
2036
2067
|
if (error instanceof PromptCancelledError) {
|
|
2037
2068
|
throw error;
|
|
2038
2069
|
}
|
|
2039
|
-
const
|
|
2040
|
-
|
|
2070
|
+
const { hints, message } = describeDownloadFailure(error, {
|
|
2071
|
+
ref: resolveSourceRef(ref),
|
|
2072
|
+
remote: resolveTemplateSource(templateType, source, ref),
|
|
2073
|
+
templateType
|
|
2074
|
+
});
|
|
2075
|
+
logger.error(message);
|
|
2076
|
+
for (const hint of hints) {
|
|
2077
|
+
logger.warn(hint);
|
|
2078
|
+
}
|
|
2041
2079
|
return { code: 1, files: [], target };
|
|
2042
2080
|
} finally {
|
|
2043
2081
|
rmSync(stagingRoot, { force: true, recursive: true });
|
|
@@ -4,7 +4,7 @@ import { discoverSchema, discoverMigrations } from '@lunora/codegen';
|
|
|
4
4
|
import { join } from '@visulima/path';
|
|
5
5
|
import { Project } from 'ts-morph';
|
|
6
6
|
import { r as resolveAdminBaseUrl } from '../packem_shared/admin-url-4UzT-CI4.mjs';
|
|
7
|
-
import { d as defineHandler } from '../packem_shared/command-
|
|
7
|
+
import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
|
|
8
8
|
import { diffSnapshots, renderMigrationFile } from '../packem_shared/diffSnapshots-BeDvvNiF.mjs';
|
|
9
9
|
import { a as resolveProductionWorkerUrl } from '../packem_shared/resolve-target-qbsJ_5sF.mjs';
|
|
10
10
|
import schemaIrToSnapshot from '../packem_shared/schemaIrToSnapshot-DdsljJT-.mjs';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, rmSync } from 'node:fs';
|
|
2
2
|
import { join } from '@visulima/path';
|
|
3
|
-
import { d as defineHandler } from '../packem_shared/command-
|
|
4
|
-
import { b as tuiConfirm } from '../packem_shared/tui-prompts-
|
|
3
|
+
import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
|
|
4
|
+
import { b as tuiConfirm } from '../packem_shared/tui-prompts-BjEN8XgP.mjs';
|
|
5
5
|
|
|
6
6
|
const runResetCommand = async (options) => {
|
|
7
7
|
const cwd = options.cwd ?? process.cwd();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as defineHandler } from '../packem_shared/command-
|
|
1
|
+
import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
|
|
2
2
|
import { r as resolveWorkerUrl } from '../packem_shared/resolve-target-qbsJ_5sF.mjs';
|
|
3
3
|
|
|
4
4
|
const parseArgsJson = (raw) => {
|