unoverse 0.1.34 → 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.
package/lib/create.mjs CHANGED
@@ -31,6 +31,17 @@ async function ask(rl, q) {
31
31
  * pre-encoded base64 `user:token` blob that docker config (and the starter's own
32
32
  * `docr` setting) uses. Wrapping the second shape in base64 AGAIN is how a valid
33
33
  * credential gets refused, so detect it and pass it through untouched. */
34
+ /** The raw dop_v1 token, whichever shape was pasted. docker login needs the raw form,
35
+ * so the base64 user:token blob is decoded before anything downstream sees it. */
36
+ function rawToken(token) {
37
+ if (/^[A-Za-z0-9+/]+=*$/.test(token) && !token.startsWith("dop_v1_")) {
38
+ const decoded = Buffer.from(token, "base64").toString("utf8");
39
+ const m = /^([\x20-\x7e]+):[\x20-\x7e]+$/.exec(decoded);
40
+ if (m) return m[1];
41
+ }
42
+ return token;
43
+ }
44
+
34
45
  function registryAuth(token) {
35
46
  if (/^[A-Za-z0-9+/]+=*$/.test(token)) {
36
47
  const decoded = Buffer.from(token, "base64").toString("utf8");
@@ -93,6 +104,24 @@ function resolveTarget(nameArg) {
93
104
  /** Human name for the target, for messages that should not say "./.". */
94
105
  const label = (dir) => (dir === "." ? "this folder" : `./${dir}`);
95
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
+
96
125
  function download(dir, stripComponents = 1, filter = "") {
97
126
  mkdirSync(dir, { recursive: true });
98
127
  const r = spawnSync(
@@ -237,20 +266,32 @@ export async function create(nameArg) {
237
266
 
238
267
  console.log(`\n ${cyan("A universe needs a registry access token.")}`);
239
268
  console.log(` ${dim("It authorizes the platform's images. Your Unoverse admin issues it.")}\n`);
240
- const token = await ask(rl, "Registry access token: ");
241
- if (!token) {
242
- fail("no token. The universe kit is available to licensed operators");
243
- process.exit(1);
244
- }
245
- process.stdout.write(" validating against the registry...");
246
- const valid = await validateRegistryToken(token);
247
- console.log("");
248
- if (!valid) {
249
- fail("that token was refused by the registry");
250
- console.log(` ${dim("Check it with your Unoverse admin, then try again.")}`);
251
- 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
+ }
252
294
  }
253
- ok("token accepted");
254
295
 
255
296
  download(name);
256
297
  ok(`universe scaffolded in ${label(name)}`);
@@ -280,7 +321,7 @@ export async function create(nameArg) {
280
321
  const r = spawnSync("bash", [operatorScript, "init"], {
281
322
  stdio: "inherit",
282
323
  cwd: name,
283
- env: { ...process.env, UNOVERSE_DOCR_TOKEN: token },
324
+ env: { ...process.env, UNOVERSE_DOCR_TOKEN: rawToken(token) },
284
325
  });
285
326
  if (r.status !== 0) {
286
327
  fail(`setup did not finish. Run 'unoverse start'${name === "." ? "" : ` in ./${name}`} to pick it back up`);
@@ -160,13 +160,17 @@ cmd_init() {
160
160
 
161
161
  # THE DOWNLOAD STARTS NOW (see the block at the top of this file).
162
162
  if [ "$DOCKER_OK" = "1" ]; then
163
- if echo "$DOCR_TOKEN" | docker login "$DOCR_REGISTRY" -u "$DOCR_TOKEN" --password-stdin >/dev/null 2>&1; then
163
+ local login_err
164
+ if login_err=$(echo "$DOCR_TOKEN" | docker login "$DOCR_REGISTRY" -u "$DOCR_TOKEN" --password-stdin 2>&1 >/dev/null); then
164
165
  start_background_pull
165
166
  echo ""
166
167
  echo -e " ${CYAN}⬇${NC} ${DIM}Platform images are downloading in the background while you configure${NC}"
167
168
  echo ""
168
169
  else
169
- warn "Registry login failed with this token. Images will not pull until it is fixed"
170
+ # The REASON, not just the fact: a swallowed docker error left "login failed"
171
+ # undiagnosable when create had just validated the same credential.
172
+ warn "Registry login failed. Images will not pull until it is fixed"
173
+ echo "$login_err" | grep -vi "warning" | head -3 | sed 's/^/ /'
170
174
  fi
171
175
  fi
172
176
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unoverse",
3
- "version": "0.1.34",
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",