unoverse 0.1.35 → 0.1.36

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 (2) hide show
  1. package/lib/create.mjs +43 -13
  2. package/package.json +1 -1
package/lib/create.mjs CHANGED
@@ -104,6 +104,24 @@ function resolveTarget(nameArg) {
104
104
  /** Human name for the target, for messages that should not say "./.". */
105
105
  const label = (dir) => (dir === "." ? "this folder" : `./${dir}`);
106
106
 
107
+ function dockerUp() {
108
+ return spawnSync("docker", ["info"], { stdio: "ignore" }).status === 0;
109
+ }
110
+
111
+ /** The ONLY honest validation is the operation itself. create used to probe the auth
112
+ * realm with its own HTTP call and say "token accepted", then docker login failed on
113
+ * the same credential two minutes later — the tool approving a token with a weaker
114
+ * check than the one that counts. When Docker is up, validation IS docker login (and
115
+ * the credential lands in the keychain, so nothing downstream logs in again). */
116
+ function dockerLogin(token) {
117
+ const r = spawnSync("docker", ["login", REGISTRY_HOST, "-u", token, "--password-stdin"], {
118
+ input: token,
119
+ encoding: "utf8",
120
+ });
121
+ const err = (r.stderr || "").split("\n").filter((l) => l && !/^WARNING/i.test(l)).pop() || "";
122
+ return { ok: r.status === 0, err };
123
+ }
124
+
107
125
  function download(dir, stripComponents = 1, filter = "") {
108
126
  mkdirSync(dir, { recursive: true });
109
127
  const r = spawnSync(
@@ -248,20 +266,32 @@ export async function create(nameArg) {
248
266
 
249
267
  console.log(`\n ${cyan("A universe needs a registry access token.")}`);
250
268
  console.log(` ${dim("It authorizes the platform's images. Your Unoverse admin issues it.")}\n`);
251
- const token = await ask(rl, "Registry access token: ");
252
- if (!token) {
253
- fail("no token. The universe kit is available to licensed operators");
254
- process.exit(1);
255
- }
256
- process.stdout.write(" validating against the registry...");
257
- const valid = await validateRegistryToken(token);
258
- console.log("");
259
- if (!valid) {
260
- fail("that token was refused by the registry");
261
- console.log(` ${dim("Check it with your Unoverse admin, then try again.")}`);
262
- process.exit(1);
269
+ const useDocker = dockerUp();
270
+ let token;
271
+ // A refused token re-asks RIGHT HERE. Being thrown out of the wizard to run
272
+ // create again is its own bug.
273
+ for (;;) {
274
+ token = rawToken(await ask(rl, "Registry access token: "));
275
+ if (!token) {
276
+ fail("no token. The universe kit is available to licensed operators");
277
+ process.exit(1);
278
+ }
279
+ process.stdout.write(" validating against the registry...");
280
+ if (useDocker) {
281
+ const res = dockerLogin(token);
282
+ console.log("");
283
+ if (res.ok) { ok("token accepted"); break; }
284
+ fail("the registry refused it:");
285
+ console.log(` ${dim(res.err)}`);
286
+ console.log(` ${dim("Paste the registry token from your admin (dop_v1_…), or Ctrl-C to stop.")}\n`);
287
+ } else {
288
+ const valid = await validateRegistryToken(token);
289
+ console.log("");
290
+ if (valid) { ok("token accepted"); break; }
291
+ fail("that token was refused by the registry");
292
+ console.log(` ${dim("Check it with your Unoverse admin, or Ctrl-C to stop.")}\n`);
293
+ }
263
294
  }
264
- ok("token accepted");
265
295
 
266
296
  download(name);
267
297
  ok(`universe scaffolded in ${label(name)}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unoverse",
3
- "version": "0.1.35",
3
+ "version": "0.1.36",
4
4
  "description": "The Unoverse front door — create a Studio project, a universe, or a client app, and launch Studio.",
5
5
  "license": "SEE LICENSE IN README.md",
6
6
  "type": "module",