@better-update/cli 0.47.2 → 0.47.3

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/index.mjs CHANGED
@@ -9,7 +9,7 @@ import path from "node:path";
9
9
  import process$1 from "node:process";
10
10
  import AppleUtils from "@expo/apple-utils";
11
11
  import { autocomplete, cancel, confirm, isCancel, multiselect, password, select, text } from "@clack/prompts";
12
- import { open, readFile, writeFile } from "node:fs/promises";
12
+ import { mkdtemp, open, readFile, rm, writeFile } from "node:fs/promises";
13
13
  import { X509Certificate, createHash, createSign, createVerify, randomBytes, randomUUID } from "node:crypto";
14
14
  import { accessSync, chmodSync, constants, createReadStream, promises } from "node:fs";
15
15
  import { Entry } from "@napi-rs/keyring";
@@ -35,7 +35,7 @@ var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
35
35
 
36
36
  //#endregion
37
37
  //#region package.json
38
- var version = "0.47.2";
38
+ var version = "0.47.3";
39
39
 
40
40
  //#endregion
41
41
  //#region src/lib/interactive-mode.ts
@@ -21543,9 +21543,16 @@ const ExecErrorSchema = Schema.Struct({
21543
21543
  stdout: Schema.optional(Schema.String),
21544
21544
  stderr: Schema.optional(Schema.String)
21545
21545
  });
21546
- const runAltool = (args) => Effect.tryPromise({
21546
+ const runAltool = (args, extraEnv) => Effect.tryPromise({
21547
21547
  try: async () => {
21548
- const { stdout, stderr } = await execFileAsync("xcrun", ["altool", ...args]);
21548
+ const options = extraEnv ? {
21549
+ encoding: "utf8",
21550
+ env: {
21551
+ ...process.env,
21552
+ ...extraEnv
21553
+ }
21554
+ } : { encoding: "utf8" };
21555
+ const { stdout, stderr } = await execFileAsync("xcrun", ["altool", ...args], options);
21549
21556
  return {
21550
21557
  exitCode: 0,
21551
21558
  stdout,
@@ -21695,11 +21702,23 @@ const resolveAscUploadCredentials = (params) => Effect.gen(function* () {
21695
21702
  p8Pem: creds.p8Pem
21696
21703
  })), Effect.catchAll((error) => printHuman(`Could not prepare ASC API key ${credsKeyId} (${messageOf(error)}).`).pipe(Effect.as(null))));
21697
21704
  });
21698
- /** `altool` reads the API key from `--apiKeyDir`; write the decrypted `.p8` there. */
21699
- const writeP8ForAltool = (credentials) => Effect.gen(function* () {
21700
- const target = path.join(tmpdir(), `better-update-submit-AuthKey_${credentials.keyId}.p8`);
21701
- yield* Effect.promise(async () => writeFile(target, credentials.p8Pem, "utf8"));
21702
- return target;
21705
+ /**
21706
+ * `altool --apiKey <id>` searches for a file named *exactly* `AuthKey_<id>.p8` in
21707
+ * the standard `private_keys` dirs plus `$API_PRIVATE_KEYS_DIR`. Write the decrypted
21708
+ * `.p8` under that exact name into a fresh private temp dir and return the dir so the
21709
+ * caller can point `API_PRIVATE_KEYS_DIR` at it (and remove it afterward — it holds
21710
+ * the unencrypted signing key).
21711
+ */
21712
+ const writeP8KeyDir = (credentials) => Effect.promise(async () => {
21713
+ const dir = await mkdtemp(path.join(tmpdir(), "better-update-asc-"));
21714
+ await writeFile(path.join(dir, `AuthKey_${credentials.keyId}.p8`), credentials.p8Pem, "utf8");
21715
+ return dir;
21716
+ });
21717
+ const removeKeyDir = (dir) => Effect.promise(async () => {
21718
+ await rm(dir, {
21719
+ recursive: true,
21720
+ force: true
21721
+ });
21703
21722
  });
21704
21723
  const baseAltoolArgs = (ipaPath) => [
21705
21724
  "--upload-app",
@@ -21724,15 +21743,12 @@ const buildAltoolArgs = (params) => Effect.gen(function* () {
21724
21743
  code: "SUBMISSION_ASC_KEY_FETCH_FAILED",
21725
21744
  message: "ASC API key is required for an asc-api-key upload but was not resolved."
21726
21745
  });
21727
- const p8Path = yield* writeP8ForAltool(params.ascCredentials);
21728
21746
  return [
21729
21747
  ...baseAltoolArgs(params.ipaPath),
21730
21748
  "--apiKey",
21731
21749
  params.ascCredentials.keyId,
21732
21750
  "--apiIssuer",
21733
- params.ascCredentials.issuerId,
21734
- "--apiKeyDir",
21735
- path.dirname(p8Path)
21751
+ params.ascCredentials.issuerId
21736
21752
  ];
21737
21753
  });
21738
21754
  const runIosSubmit = (inputs) => Effect.gen(function* () {
@@ -21758,7 +21774,7 @@ const runIosSubmit = (inputs) => Effect.gen(function* () {
21758
21774
  ipaPath
21759
21775
  });
21760
21776
  yield* patchSubmissionStatus(inputs.api, inputs.submissionId, { status: "IN_PROGRESS" });
21761
- const result = yield* runAltool(altoolArgs);
21777
+ const result = inputs.auth.kind === "asc-api-key" && ascCredentials !== null ? yield* Effect.acquireUseRelease(writeP8KeyDir(ascCredentials), (keyDir) => runAltool(altoolArgs, { API_PRIVATE_KEYS_DIR: keyDir }), (keyDir) => removeKeyDir(keyDir)) : yield* runAltool(altoolArgs);
21762
21778
  if (result.exitCode !== 0) {
21763
21779
  yield* patchSubmissionStatus(inputs.api, inputs.submissionId, {
21764
21780
  status: "ERRORED",