@dench.com/cli 3.12.30-staging.1461 → 3.12.31-staging.1469

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/environments.ts CHANGED
@@ -310,6 +310,41 @@ async function restoreState(
310
310
  );
311
311
  }
312
312
 
313
+ async function readStagedEnvironmentResolution(
314
+ resolutionFile: string,
315
+ parsed: { name?: string; revision?: string },
316
+ ): Promise<ResolvedEnvironment> {
317
+ try {
318
+ const info = await lstat(resolutionFile);
319
+ if (info.isSymbolicLink() || !info.isFile()) {
320
+ throw new Error(
321
+ "invalid_environment_resolution: Staged environment payload must be a regular file.",
322
+ );
323
+ }
324
+ const resolved = JSON.parse(
325
+ await readFile(resolutionFile, "utf8"),
326
+ ) as ResolvedEnvironment;
327
+ if (
328
+ !resolved ||
329
+ typeof resolved !== "object" ||
330
+ resolved.name !== parsed.name ||
331
+ (parsed.revision && resolved.revision !== parsed.revision) ||
332
+ !resolved.manifest ||
333
+ typeof resolved.credentialEnv !== "object" ||
334
+ resolved.credentialEnv === null ||
335
+ !Array.isArray(resolved.credentialFiles)
336
+ ) {
337
+ throw new Error(
338
+ "invalid_environment_resolution: Staged environment payload did not match the requested revision.",
339
+ );
340
+ }
341
+ return resolved;
342
+ } finally {
343
+ delete process.env.DENCH_ENVIRONMENT_RESOLUTION_FILE;
344
+ await rm(resolutionFile, { force: true }).catch(() => undefined);
345
+ }
346
+ }
347
+
313
348
  async function executeSavedEnvironment(
314
349
  opts: ClientOptions,
315
350
  parsed: Exclude<ReturnType<typeof validateEnvironmentArgs>, { verb: "help" }>,
@@ -320,12 +355,17 @@ async function executeSavedEnvironment(
320
355
  const stateKey =
321
356
  parsed.stateKey ??
322
357
  (job ? `job:${job}` : `local:${sha256(process.cwd()).slice(0, 32)}`);
323
- const environment = (await opts.convex.action(actionRef("resolve"), {
324
- ...token,
325
- name: parsed.name,
326
- ...(parsed.revision ? { revision: parsed.revision } : {}),
327
- stateKey,
328
- })) as ResolvedEnvironment;
358
+ const stagedResolutionFile =
359
+ process.env.DENCH_ENVIRONMENT_RESOLUTION_FILE?.trim();
360
+ const resolvedFromStagedFile = Boolean(stagedResolutionFile);
361
+ const environment = stagedResolutionFile
362
+ ? await readStagedEnvironmentResolution(stagedResolutionFile, parsed)
363
+ : ((await opts.convex.action(actionRef("resolveForAdmin"), {
364
+ ...token,
365
+ name: parsed.name,
366
+ ...(parsed.revision ? { revision: parsed.revision } : {}),
367
+ stateKey,
368
+ })) as ResolvedEnvironment);
329
369
  const suppliedWorkspace =
330
370
  opts.execution?.workspace ?? process.env.DENCH_ENVIRONMENT_WORKSPACE;
331
371
  const workspace =
@@ -377,12 +417,12 @@ async function executeSavedEnvironment(
377
417
  ? await acquireEnvironmentWorkspaceLock(workspace)
378
418
  : undefined;
379
419
  try {
380
- if (releaseExecution) {
420
+ if (releaseExecution && !resolvedFromStagedFile) {
381
421
  // Another command may have committed state or rotated credentials while
382
422
  // this process waited. Read again under the lock, retaining this revision.
383
423
  Object.assign(
384
424
  environment,
385
- await opts.convex.action(actionRef("resolve"), {
425
+ await opts.convex.action(actionRef("resolveForAdmin"), {
386
426
  ...token,
387
427
  name: environment.name,
388
428
  revision: environment.revision,
package/members.ts CHANGED
@@ -32,6 +32,7 @@
32
32
  * Both surfaces share this implementation so the CLI auth + payload
33
33
  * shape stays in lockstep.
34
34
  */
35
+ import { createHash } from "node:crypto";
35
36
  import { readFile } from "node:fs/promises";
36
37
  import { extname } from "node:path";
37
38
  import type { ConvexHttpClient } from "convex/browser";
@@ -380,11 +381,11 @@ async function uploadAvatar(
380
381
  if (bytes.byteLength > 2 * 1024 * 1024) {
381
382
  throw new MembersCliError("--avatar must be under 2 MB");
382
383
  }
383
- const uploadUrl = (await callMutation(
384
- ctx,
385
- api.profiles.avatarUploadUrl,
386
- {},
387
- )) as string;
384
+ const sha256 = createHash("sha256").update(bytes).digest("hex");
385
+ const uploadUrl = (await callMutation(ctx, api.profiles.avatarUploadUrl, {
386
+ sha256,
387
+ size: bytes.byteLength,
388
+ })) as string;
388
389
  const response = await fetch(uploadUrl, {
389
390
  method: "POST",
390
391
  headers: { "Content-Type": contentType },
@@ -394,7 +395,7 @@ async function uploadAvatar(
394
395
  throw new MembersCliError(`Avatar upload failed (${response.status})`);
395
396
  }
396
397
  const { storageId } = (await response.json()) as { storageId: string };
397
- await callMutation(ctx, api.profiles.setAvatar, { storageId });
398
+ await callMutation(ctx, api.profiles.setAvatar, { storageId, sha256 });
398
399
  }
399
400
 
400
401
  function shiftArg(ctx: MembersCliContext, expected: string): string {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dench.com/cli",
3
- "version": "3.12.30-staging.1461",
3
+ "version": "3.12.31-staging.1469",
4
4
  "description": "Dench agent workspace CLI.",
5
5
  "type": "module",
6
6
  "bin": {